akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[][] counts = new int[10][10];
        for (int i = 1; i < N+1; i++) {
            int btm = i % 10;
            int top = -1, x = i;
            while(-0 < x){
                top = x % 10;
                x /= 10;
            }
            counts[top][btm]++;
        }

        int ans = 0;
        for (int i = 0; i < 10 ; i++) {
            for (int j = 0; j < 10; j++) {
                ans += counts[i][j] * counts[j][i];
            }
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 22996
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long N = Long.parseLong(sc.next());
		List<Long> aList = new ArrayList();
		List<Long> bList = new ArrayList();
		
		for(long i=0; i <= N;i++){
			aList.add(Long.parseLong(sc.next()));
		}
		long totalDamage = 0;
		for(long i=0; i < N;i++){
			long a = Long.parseLong(sc.next());
			bList.add(a);
			totalDamage += a;
		}
		
		long amari = -1;
		long more = 0;
		for(int i=0;i<N;i++){
			long a1 = aList.get(i);
			long a2 = aList.get(i+1);
			long b1 = bList.get(i);
			if(amari!=-1){
				a1 = amari;
			}
			if(a1+a2 >b1){
				amari = b1 > a1? a2-(b1-a1): a2;
			}else if(a1 + a2 < b1){
				amari = 0;
				more += b1 - (a1+a2);
			} else {
				amari = 0;
			}
		}
		System.out.println(totalDamage-more);
	}
}


Measured memory_bytes: 53928
import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    
    int a = sc.nextInt();
    String s = sc.next();
    int b = sc.nextInt();
    
    if (s.equals("+")) {
      System.out.println(a + b);
    } else if (s.equals("-")) {
      System.out.println(a - b);
    }
  }
}

Measured memory_bytes: 21332
#include <iostream>
#include <vector>
using namespace std;

int main() {
  int H, W, K;
  cin >> H >> W >> K;
  char d[H][W];
  string s;
  for (int i=0; i<H; i++){
    cin >> s;
    for (int j=0; j<W; j++){
      d[i][j]=s.at(j);
    }
  }
  int ans = 0;
  for (int bitt = 0; bitt < (1<<H); bitt++) {
    for (int bity = 0; bity < (1<<W); bity++) {
      int count=0;
      for (int i = 0; i < H; i++) {
        for (int j=0; j < W; j++) {
          if ((bitt & (1<<i)) && (bity & (1<<j)) && (d[i][j]=='#')) {
              count++;
          }
        }
      }
      if (count==K)
        ans++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
#include <math.h>
#include <stdio.h>

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define rep(i, n) repd(i, 0, n)

using namespace std;

namespace mp = boost::multiprecision;
using Bint = mp::cpp_int;

using ll = long long;
ll mod = pow(10, 9) + 7;

template <typename T> void output(T, ll);
ll gcd(ll, ll);
ll lcm(ll, ll);
Bint comb(Bint, Bint);
void prime_map(map<ll, ll> &, ll);

int main() {
    // source
    double a, b, x;
    cin >> a >> b >> x;
    double ans = 0;
    if (x <= a * a * b / 2) {
        ans = atan2(a * b * b, 2 * x) * 180 / M_PI;
    } else {
        x -= a * a * b / 2;
        ans = atan2(2 * x - a * a * b, a * a * a) * 180 / M_PI;
    }
    printf("%2.20f\n", abs(ans));
    return 0;
}

Bint comb(Bint a, Bint b) {
    Bint ans = 1;

    if (a < b) {
        return 0;
    }

    rep(i, b) {
        ans *= a - i;
        ans /= i + 1;
    }

    return ans;
}

template <typename T> void output(T a, int precision) {
    if (precision > 0) {
        cout << setprecision(precision) << a << "\n";
    } else {
        cout << a << "\n";
    }
}

template <typename T> T min(T a, T b) {

    if (a < b) {
        return a;
    } else {
        return b;
    }
}

ll gcd(ll a, ll b) {
    if (b == 0) {
        return a;
    }
    return gcd(b, a % b);
}

ll lcm(ll a, ll b) { return a * b / gcd(a, b); }

void prime_map(map<ll, ll> &m, ll num) {

    if (num == 1) {
        return;
    }
    ll cache = num;
    repd(i, 2, sqrt(num) + 2) {
        if (num % i == 0) {
            if (m[i] == 0) {
                m[i] = 1;
            } else {
                m[i]++;
            }

            num /= i;
            break;
        }
    }
    if (cache == num) {
        if (m[num] == 0) {
            m[num] = 1;
        } else {
            m[num]++;
        }

        return;
    }
    prime_map(m, num);
    return;
}


Measured memory_bytes: 256
N=int(input())
p=[]
for i in range(N):
    x,y=map(int,input().split())
    p.append([x,y])

L=0
for i in range(N-1):
    for j in range(i+1,N):
        L += ((p[i][0]-p[j][0])**2 + (p[i][1]-p[j][1])**2 )**0.5
print(2*L/N)

Measured memory_bytes: 3064
import Control.Applicative
import Control.Monad
import Control.Monad.ST
-- import qualified Data.ByteString as BS
import Data.Functor
import Data.Function
import Data.Monoid
import Data.Maybe
import Data.List
import qualified Data.Foldable as Foldable
--import qualified Data.Set as Set
--import qualified Data.Sequence as Sequence
import Data.List.Split
import Data.Bits
import Data.Char
import Data.Ix
import Data.Ratio
import Data.Ord
import Data.Fixed
import Data.Tuple
import Data.Array
--import Data.Array.Unboxed
--import Data.Array.IArray
import Data.Array.MArray
import Data.Array.IO
import Data.Array.ST
import Data.IORef
import Data.STRef
import Text.Printf
import System.IO
-- import System.IO.Unsafe
 
-- templete
readInt = read :: String -> Int
readInteger = read :: String -> Integer
readDouble = read :: String -> Double
getInt = readLn :: IO Int
getInts = map readInt . words <$> getLine
getInteger = readLn :: IO Integer
getIntegers = map readInteger . words <$> getLine
getDouble = readLn :: IO Double
getDoubles = map readDouble . words <$> getLine
sjoin :: (Show a) => [a] -> String
sjoin = unwords . map show
tjoin :: (Show a, Show b) => (a, b) -> String
tjoin (x, y) = show x ++ (' ' : show y)
cond :: a -> a -> Bool -> a
cond t f c = if c then t else f
apply2 :: (a -> a -> b) -> [a] -> b
apply2 f [x,y] = f x y
apply3 :: (a -> a -> a -> b) -> [a] -> b
apply3 f [x,y,z] = f x y z
apply4 :: (a -> a -> a -> a -> b) -> [a] -> b
apply4 f [x,y,z,w] = f x y z w
fnTuple :: (a -> b, a -> c) -> a -> (b, c)
fnTuple (f,g) a = (f a, g a)
replace :: (Eq a) => a -> a -> [a] -> [a]
replace x y = map (\z -> if z==x then y else z)
binMap :: (a -> a -> b) -> [a] -> [b]
binMap f (x:xs@(y:_)) = f x y : binMap f xs
binMap _ _ = []
splitRec :: Int -> [a] -> [[a]]
splitRec _ [] = []
splitRec n xs = let (y,ys) = splitAt n xs in y : splitRec n ys
infixl 7 `divCeil`
divCeil :: Integral a => a -> a -> a
x `divCeil` y = (x+y-1) `div` y
coverC :: Ord a => (a, a) -> a -> Bool
coverC (l,r) x = l<=x && x<=r
coverH :: Ord a => (a, a) -> a -> Bool
coverH (l,r) x = l<=x && x<r
ibsearch :: (Int -> Bool) -> (Int,Int) -> Int
ibsearch f (ok,ng) = if abs (ok-ng) <= 1 then ok else let mid = (ok + ng) `div` 2 in ibsearch f (if f mid then (mid,ng) else (ok,mid))
whenM :: Monad m => m Bool -> m () -> m ()
whenM c a = c >>= flip when a
unconsU :: [a] -> (a, [a])
unconsU (x:xs) = (x, xs)
-- templete


main = do
    n <- (`div`4) <$> getInt
    when (n/=0) $ do
        replicateM n getInt >>= print . sum >> main
        


Measured memory_bytes: 4112
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int,int>;
using pib = pair<int,bool>;
using ll = long long;
using ld = long double;
#define all(x) (x).begin(),(x).end()
#ifdef fread_unlocked
#define fread fread_unlocked
#define fwrite fwrite_unlocked
#endif
#define mp make_pair
#define lc ind<<1
#define rc ind<<1|1
const int MN = 1e3+5, MOD = 1e9+7, BASE = 31, MASK = (1 << 10) - 1;
int main () {
	int x,n;
	scanf ("%d %d",&x,&n);
	set<int> p;
	while (n--) {
		int a; scanf ("%d",&a); p.insert(a);
	}
	set<int> nt;
	for (int i = -100; i <= 200; i++) if (!p.count(i)) nt.insert(i);
	auto it = nt.lower_bound(x);
	int best = *it;
	if (abs(x-(*prev(it))) <= abs(x-best)) best = *(--it);
	printf ("%d\n",best); 
	return 0;
}


Measured memory_bytes: 3808
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Math;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            A();
        }

        static void A()
        {
            var S = Read().ToArray();
            var red = S.Count(x => x == '0');
            var blue = S.Count(x => x == '1');
            Println(red > blue ? S.Length - (red - blue) : S.Length - (blue - red));
        }

        static IEnumerable<int> Range(int start, int stop)
        {
            if (start < 0 || stop < 0 || start > stop || (start <= 0 && stop <= 0))
                return new List<int>();

            return Enumerable.Range(start, stop - start);
        }

        static bool IsDigit(string str)
        {
            var i = 0;
            return int.TryParse(str, out i);
        }

        static int DigitsSum(long num)
        {
            return num.ToString().Select(x => x.ToString()).Sum(int.Parse);
        }

        static int[] ToIntArray(string str)
        {
            return str.Select(x => x.ToString()).Select(int.Parse).ToArray();
        }

        static int Gcd(int a, int b) => b == 0 ? a : Gcd(b, a % b);

        static bool IsPrime(int x)
        {
            if (x <= 1 || (x != 2 && x % 2 == 0)) return false;
            if (x == 2) return true;

            for (int i = 3; i < x; i += 2)
                if (x % i == 0) return false;

            return true;
        }

        static string Read() => Console.ReadLine();
        static int ReadInt() => int.Parse(Read());
        static long ReadLong() => long.Parse(Read());

        static List<string> ReadSplit() => Read().Split().ToList();
        static List<int> ReadSplitInt() => Read().Split().Select(int.Parse).ToList();
        static List<long> ReadSplitLong() => Read().Split().Select(long.Parse).ToList();

        static void Print(object value) => Console.Write(value.ToString());
        static void Println(object value) => Console.WriteLine(value.ToString());

        static string Join<T>(IEnumerable<T> list) => string.Join("", list);
    }

    public static class MyExtensions
    {
        public static string Slice(this string str, int start = 0, int stop = 0)
        {
            if (start > str.Length || stop > str.Length || start < 0 || stop < 0)
                return "";

            if (stop == 0) stop = str.Length;
            return str.Substring(start, stop - start);
        }
    }
}

Measured memory_bytes: 15316
#include <stdio.h>

int main( void ) {
	int i, n, sum, min, max, tmp;

	for ( ; scanf( "%d", &n ), n; printf( "%d\n", ( sum - min - max ) / ( n - 2 ) ) ) {
		scanf( "%d", &tmp );

		sum = min = max = tmp;
		for ( i = 0; i < n - 1; i++ ) {
			scanf( "%d", &tmp );

			sum += tmp;
			if ( tmp < min )
				min = tmp;
			if ( max < tmp )
				max = tmp;
		}
	}

	return 0;
}

Measured memory_bytes: 600
n, l = map(int, input().split())
apple = []
for i in range(1, n + 1):
    apple.append(i+l-1)
for i in range(400):
    if i in apple:
        apple.remove(i)
        print(sum(apple))
        break
    elif -i in apple:
        apple.remove(-i)
        print(sum(apple))
        break
    else:
        pass

Measured memory_bytes: 9104
#include<bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp> 
//using namespace boost::multiprecision; 
using namespace std;
#define ll long long int
#define ld long long double
#define vi vector<int>
#define vl vector<ll>
#define pi pair<int, int>
#define pl pair<ll, ll>
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define nl '\n'
#define mp make_pair
#define debug1(x) cout <<#x<<" "<<x<<'\n';
#define debug2(x,y) cout <<#x<<" "<<x <<" "<<#y<<" "<<y <<'\n';
#define debug3(x,y,z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<'\n';
#define fi first
#define se second
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define inf 1e18
const int mod = (int)1e9+7;
pair<ll,ll>s4[4]={{-1,0},{1,0},{0,-1},{0,1}};
pair<ll,ll>s8[8]={{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,1},{1,0},{1,-1}};

void solve() {
    ll a,b,c;
    cin >> a>>b>>c;
    ll hash[1000]={0};
    hash[a]++;
    hash[b]++;
    hash[c]++;
    int x=0,y=0;
    
    for(int i=0;i<999;i++) {
        if(hash[i]==2) {
            x=2;
        }
        if(hash[i]==1) {
            y=1;
        }
    }
    if(x==2&&y==1) {
        cout << "Yes\n";
    }
    else{
        cout << "No\n";
    }
    
}

signed main() {
	boost;
	solve();
}

Measured memory_bytes: 256
/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */

#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using Pair = pair<int64_t, int64_t>;

// std::cout << std::setprecision(20) << 1.1 << endl;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int64_t X;
  cin >> X;
  for (int64_t A = -1000; A < 1000; ++A) {
    for (int64_t B = -1000; B < 1000; ++B) {
      if (A * A * A * A * A - B * B * B * B * B == X) {
        cout << A << " " << B << endl;
        return 0;
      }
    }
  }

  return 0;
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1ll << 62;
const int MOD = 1000000007;

template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int main() {
  int N, K;
  cin >> N >> K;
  vector<ll> x(N), y(N);
  rep(i, N) cin >> x[i] >> y[i];

  vector<ll> xx = x;
  vector<ll> yy = y;
  sort(all(xx));
  sort(all(yy));

  ll ans = LINF;
  repp(xi, 0, N - 2) {
    repp(xj, xi + 1, N - 1) {
      repp(yi, 0, N - 2) {
        repp(yj, yi + 1, N - 1) {
          ll l = xx[xi];
          ll r = xx[xj];
          ll d = yy[yi];
          ll u = yy[yj];
          int cnt = 0;
          rep(k, N) {
            if (l <= x[k] && x[k] <= r && d <= y[k] && y[k] <= u)
              cnt++;
          }
          if (cnt >= K)
            chmin(ans, (r - l) * (u - d));
        }
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef pair<int, int> P;
typedef long long ll;
ll dp[110][100100];
ll mod = 1e9+7;
int main(){
    int n,k;
    cin >> n >> k;
    vector<int> v(n);
    rep(i,n){
        cin >> v[i];
    }
    dp[0][k]=1;
    rep(i,n){
        rep(j,k+1){
            //O(1)で更新する必要がある→imos
            dp[i+1][j+1]-=dp[i][j];
            dp[i+1][max(0,j-v[i])]+=dp[i][j];
        }
        rep(j, k + 1)
        {
            dp[i+1][j+1]+=dp[i+1][j];
        }
        rep(j,k+1){
            dp[i+1][j]%=mod;
        }
    }
    cout << dp[n][0] << endl;
    return 0;
}

Measured memory_bytes: 79360
import heapq
INF = 10**10


def dijkstra(s, G):
    d = [INF] * len(G)
    d[s] = 0
    q = []
    heapq.heapify(q)
    heapq.heappush(q, (0, s))
    while len(q) > 0:
        shortest, v = heapq.heappop(q)
        if d[v] < shortest:
            continue
        for e in G[v]:
            to, cost = e
            if d[to] > d[v] + cost:
                d[to] = d[v] + cost
                heapq.heappush(q, (d[to], to))
    return d


H, W = map(int, input().split())
G = [[] for _ in range(10)]
for i in range(10):
    adj = list(map(int, input().split()))
    for j, cost in enumerate(adj):
        # 1からの距離を計算したいから逆向きのグラフを考える
        G[j].append((i, cost))
shortest_d = dijkstra(1, G)
ans = 0
for _ in range(H):
    for x in list(map(int, input().split())):
        if x == -1:
            continue
        ans += shortest_d[x]
print(ans)


Measured memory_bytes: 9284
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

void calc(char s[],char out[],int n,int h){

	for(int i=h;i<n;i++){
		out[i]=s[i];
		printf("%c",out[i]);
	}
	for(int i=0;i<h;i++){
		out[i]=s[i];
		printf("%c",out[i]);
	}
	printf("\n");
}

int main(void){
	char s[200],out[200]={};
	int m;
	int h,h2,s_len;

	while(scanf("%s",s)){
		if(strcmp(s,"-")==0){
			break;
		}

		strcpy(out,"");

		s_len = strlen(s);		

		scanf("%d",&m);
		h2=0;
		for(int i=0;i<m;i++){
			scanf("%d",&h);
			h2+=h;
		}

		calc(s,out,s_len,(h2%s_len));
	}

}


Measured memory_bytes: 2056
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;

ll niz[200005];
int levo[200005];
int desno[200005];

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout << fixed;

    int n;
    cin >> n;
    for(int i=1; i<=n; i++){
        cin >> niz[i];
    }
    stack <int> stek;
    stek.push(0);
    for(int i=1; i<=n; i++){
        while(niz[stek.top()] > niz[i]) stek.pop();
        levo[i] = stek.top();
        stek.push(i);
    }
    while(!stek.empty()) stek.pop();
    stek.push(n+1);
    for(int i=n; i>=1; i--){
        while(niz[stek.top()] > niz[i]) stek.pop();
        desno[i] = stek.top();
        stek.push(i);
    }
    ll res = 0;
    for(int i=1; i<=n; i++){
        res += niz[i]*(i-levo[i])*(desno[i]-i);
    }
    cout << res;
    return 0;
}


Measured memory_bytes: 4224
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

n,a,b = map(int,input().split())
X = list(map(int,input().split()))
dis = [0]*(n-1)
for i in range(1,n):
  dis[i-1]= X[i]-X[i-1]
for di in dis:
  if di*a <= b:
    ans += di*a
  else:
    ans += b
print(ans)

Measured memory_bytes: 69488
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <tuple>
#include <algorithm>
#include <map>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <sstream> // std::stringstream
#include <bitset>  // std::bitset<N>
using namespace std;
long long int MOD = 1000000000 + 7;
using ll = long long;
ll LARGE = 1000000;


void print(vector<char>& v) {
	for (int i = 0; i < v.size(); ++i) {
		cout << v[i] << " ";
	}
	cout << endl;
}

int ncr(int n, int r) {
	int k1 = 1;
	int k2 = 1;
	for (int i = 0; i < r; ++i) {
		k1 *= (i + 1);
		k2 *= (n - i);
	}
	return k2 / k1;
}

int main() {
	ll k, n;
	cin >> k >> n;
	vector<ll> a(n);
	for (ll i = 0; i < n; ++i) {
		cin >> a[i];
	}
	ll max_dist = 0;
	for (ll i = 1; i < n; ++i) {
		ll dist = abs(a[i - 1] - a[i]);
		if (max_dist < dist) {
			max_dist = dist;
		}
	}
	ll dist = abs(k - a[n - 1]) + a[0];
	if (max_dist < dist) {
		max_dist = dist;
	}

	cout << k - max_dist << endl;
	return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define each(a, b) for(auto (a): (b))
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define pb push_back
#define show(x) cout <<#x<<" = "<<(x)<<endl
#define spair(p) cout <<#p<<": "<<p.fi<<" "<<p.se<<endl
#define svec(v) cout<<#v<<":";rep(kbrni,v.size())cout<<" "<<v[kbrni];cout<<endl
#define sset(s) cout<<#s<<":";each(kbrni,s)cout <<" "<<kbrni;cout<<endl

using namespace std;

typedef pair<int,int>P;

const int MAX_N = 100005;

ll comb[51][51];

int main()
{
    int n,P;
    cin >> n >> P;
    vector<int> a(n);
    int v1=0,v2=0;
    rep(i,n){
        cin >> a[i];
        if(a[i] % 2 == 0){
            v1++;
        }else{
            v2++;
        }
    }
    rep(i,n+1){
        comb[i][0] = 1;
    }
    for(int i=1;i<=n;i++){
        for(int j=1;j<=i;j++){
            comb[i][j] = comb[i-1][j] + comb[i-1][j-1];
        }
    }
    ll sm1 = 0;
    ll sm2 = 0;
    rep(i,v1+1){
        sm1 += comb[v1][i];
    }
    if(P == 0){
        for(int i=0;2*i<=v2;i++){
            sm2 += comb[v2][2*i];
        }
    }else{
        for(int i=0;2*i+1<=v2;i++){
            sm2 += comb[v2][2*i+1];
        }
    }
    cout << sm1*sm2 << "\n";
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i, n) for (int i = 0; i < ((int)(n)); i++) // 0-indexed昇順

int main()
{
  string s;
  cin >> s;
  int res = 0;
  rep(i, s.size())
  {
    if (s.at(i) == '1')
      res++;
  }
  cout << res << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

int main()
{
    string S;
    cin >> S;

    vector<int> cnt(2, 0);
    for(int i = 0; i < S.length(); i++)
    {
        cnt[S[i] - '0']++;
    }

    int ans = min(cnt[0], cnt[1]) * 2;

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 512
#include<stdio.h>
#include<string.h>
int a[4];
void abcd(int l,int r)
{
    int i=l,j=r,t;
    int p=a[(l+r)/2];
    while(i<=j)
    {while(a[i]<p)
    {i++;}
    while(a[j]>p)
    {j--;}
    if(i<=j)
    {t=a[i]; 
    a[i]=a[j]; 
    a[j]=t;
    i++; 
    j--;}}
    if(l<j)
    abcd(l,j);
    if(i<r)
    abcd(i,r); 
    }
int main()
{
    scanf("%d%d%d",&a[1],&a[2],&a[3]);
    abcd(1,3);
    if(a[2]-a[1]==a[3]-a[2])
    printf("YES\n");
    else
    printf("NO\n");
    return 0;
}

Measured memory_bytes: 128
N, A, B, K = map(int, input().split())

MOD = 998244353

# inv[k]: kの逆元
inv = [0] * (N + 1)
inv[1] = 1
for k in range(2, N + 1):
    inv[k] = (-(MOD // k) * inv[MOD % k]) % MOD

# nCr[r]: C(N, r) % MOD
nCr = [0] * (N + 1)
nCr[0] = 1
for r in range(1, N + 1):
    nCr[r] = (nCr[r - 1] * (N - r + 1) * inv[r]) % MOD

ans = 0
for a in range(N + 1):
    b = (K - A * a) // B
    if A * a + B * b == K and 0 <= b <= N:
        ans += (nCr[a] * nCr[b]) % MOD
        ans %= MOD

print(ans)


Measured memory_bytes: 26720
//A - Tenki
//2019/09/09

#include <stdio.h>

int main(void) {
    int ans=0,i;
    char forecast[4],real[4];
    scanf("%s",forecast);
    scanf("%s",real);
    for (i=0;i<3;i++) {
        if (forecast[i]==real[i]) {
            ans++;
        }
    }
    printf("%d",ans);
    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include <algorithm> // sort
#include <map> // pair
using namespace std;
using ll = long long;
const ll mod = 1e9+7;

int main(){
  string s;
  bool ym,my;
  cin >> s;
  if((s[0] == '0' && s[1] != '0') || (s[0] == '1' && s[1] <= '2')){
    my = true;
  }else{
    my = false;
  }
  if((s[2] == '0' && s[3] !='0') || (s[2] == '1' && s[3] <= '2')){
    ym = true;
  }else{
    ym = false;
  }
  if(ym && my){
    cout << "AMBIGUOUS";
  }else if(ym && !my){
    cout << "YYMM";
  }else if(!ym && my){
    cout << "MMYY";
  }else{
    cout << "NA";
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+5,M=1e6+5,inf=0x3f3f3f3f,mod=1e9+7;
#define mst(a) memset(a,0,sizeof a)
#define lx x<<1
#define rx x<<1|1
#define reg register
#define PII pair<int,int>
#define fi first 
#define se second
int main()	{
	string a,b;
	cin>>a>>b;
	int ans=0;
	for(int i=0;i<a.size();i++)
		if(a[i]!=b[i]) ans++;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3836
program abc167b
      implicit none
      integer(8)::a,b,c
      integer(8)::k,ans=0

         read *, a,b,c,k

         if (a>=k) then
            print *, k
            stop
         else
            ans=ans+a
            k=k-a
            if (b>=k) then
               print *, ans
               stop
            else
               k=k-b
               ans=ans-k
               print *, ans
               stop
            end if
         end if

   end program abc167b

Measured memory_bytes: 2796
a = int(input())
b = int(input())
c = int(input())
x = int(input())
ans = 0

for i in range(0, a+1):
    for j in range(0, b+1):
        for k in range(0, c+1):
            if i * 500 + j * 100 + k * 50 == x:
                ans += 1
print(ans)


Measured memory_bytes: 39536
H,W,A,B = map(int,input().split())
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

N = 10**6     #出力の制限
mod = 10**9+7 
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル
for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )
def path(a,b):
  h=b[0]-a[0]
  w=b[1]-a[1]
  return cmb(h+w,h,mod)
st,gl = [0,0],[H-1,W-1]
ans = path(st,gl)
for i in range(A):
  ans-=(path(st,[H-i-1,B-1])*path([H-i-1,B],gl))%mod
print(ans%mod)

Measured memory_bytes: 122000
#include<bits/stdc++.h>
using namespace std;


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    long long int n;
    cin >> n;
    vector<pair<long long int, long long int>> a;
    for(long long int i = 0; i < n; i++) {
        long long int x;
        cin >> x;
        int flag = 1;
        for(long long int j = 0; j < i; j++) {
            if(x == a[j].first) {
                a[j].second++;
                flag = 0;
                break;
            }
        }
        if(flag) {
            a.push_back(pair<long long int, long long int>(x, 1));
        }
    }
    sort(a.begin(), a.end());
    long long int ans = 0;
    for(int i = 0; i < a.size(); i++) {
        for(int j = i + 1; j < a.size(); j++) {
            for(int k = j + 1; k < a.size(); k++) {
                if(a[i].first + a[j].first > a[k].first) {
                    ans += a[i].second * a[j].second * a[k].second;
                }
            }
        }
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 3656
#include <iostream>
#include <algorithm>

using namespace std;

typedef long long ll;

ll x, y, z, k;
ll a[1000], b[1000], c[1000];
ll K;
ll h[60000000];
int sz;

int main()
{
  cin >> x >> y >> z >> k;
  K = k;
  for (int i = 0; i < x; i++) cin >> a[i];
  for (int i = 0; i < y; i++) cin >> b[i];
  for (int i = 0; i < z; i++) cin >> c[i];
  sort(a, a + x);
  sort(b, b + y);
  sort(c, c + z);
  for (int i = x - 1; i >= 0; i--)
  {
    for (int j = y - 1; j >= 0; j--)
    {
      for (int k = z - 1; k >= 0 && (x - i - 1) * (y - j - 1) * (z - k - 1) < K; k--)
      {
        h[sz] = a[i] + b[j] + c[k];
        sz++;
      }
    }
  }
  sort(h, h + sz);
  for (int i = sz - 1; i >= sz - k; i--)
  {
    //cout << i << endl;
    cout << h[i] << "\n";
  }
}


Measured memory_bytes: 24960
using System;
public class Program
{
    public static void Main(string[] args)
    {
        var inputN = Console.ReadLine();
        var input = Console.ReadLine();
        if (input.Length % 2 != 0)
        {
            Console.WriteLine("No");
            return;
        }
        for (var i = 0; i < input.Length/2;i++)
        {
            if (input[i] != input[i + input.Length / 2])
            {
                Console.WriteLine("No");
                return;
            }
        }
        Console.WriteLine("Yes");
    }
}

Measured memory_bytes: 11092
#include <stdio.h>
 
int main(void) {
  int A, B, C, X;
  int ans = 0;
  int a, b;
  
  scanf("%d %d %d %d", &A, &B, &C, &X);
  for(a = 0; a <= A; a++) {
    for(b = 0; b <= B; b++) {
      int c = (X - 500 * a - 100 * b) / 50;
      if(0 <= c && c <= C) ans++;
    }
  }
  printf("%d\n", ans);
  
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
using namespace std;
int main(){
    int a, b;
    cin >> a >> b;
    if(a <= 5){
        cout << 0 << endl;
    }else if(a <= 12){
        cout << b/2 << endl;
    }else{
        cout << b << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Deque;
import java.util.Queue;
import java.util.Scanner;
 


public class Main {
	private static Scanner sc = new Scanner(System.in);
	//StringBuffer S = new StringBuffer(sc.next());
	//String hoge2 = str.reverse().toString();
	//map.containsKey(A)
	//Map<Integer, Integer> map = new HashMap<Integer, Integer>(N);
	/*for ( キーのデータ型 key : マップの名前.keySet() ) {
		データのデータ型 data = マップの名前.get( key );
		
		// keyやdataを使った処理;
	}*/
	//int i = Integer.parseInt(s);
	//Queue<String> qq=new ArrayDeque<>(); //add,poll,peek
	//Deque<String> dd=new ArrayDeque<>();//push後ろに入れる,poll(pop)後ろからとる,peek addは先頭に入るからバグ注意
	//ArrayList<Integer> cc = new ArrayList<>(N);
	//cc.contains(tmp)
	//Arrays.asList(c).contains("a")
	//list.set(1,"walk");//1 1 2 3 5
	static long mod =1000000007;
	static long longINF=1000000000000000007L;
	static int INF=1000000007;

	
	public static void main(String[] args) {
		//StringBuffer str = new StringBuffer(sc.nextInt());
		//for(int i=0;i<N;i++) {}
		p(sc.nextInt()*sc.nextInt());
			
		
		
		
		//int N=sc.nextInt();
		//int a[]=new int[N];for(int i=0;i<N;i++) {a[i]=sc.nextInt();}
		//String S=sc.next();
		
		
		
		
		
		
		
		
	}
		
		
		
		
		
	
	
	
	static long bi(int i) {
		long t=1;
		for(int a=1;a<=i;a++) {
			t*=a;
			t%=mod;
		}
		return t;
	}
	public static long modPow(long g,long N) {
		long T=1;
		for(int i=0;i<N;i++) {
			T*=g;
			T%=mod;
		}
		return T;
	}
	static void bit() {
		int n=3;
		String[] ar = {"a","b","c"};
		for(int i =0;i<(1<<n);i++) {
			String S="";
			for(int j=0;j<n;j++) {
				if((1&i>>j)==1) {
					S+=ar[j];
				}
			}
			p("S="+S);
		}
	}
	public static long lcm(long a, long b) {
        return a / gcd(a, b) * b;
	}
	
	public static long gcd(long a, long b) {
        return b == 0 ? a: gcd(b, a % b);
	}
	static String nextPermutation(String s) {
		ArrayList<Character> list=new ArrayList<>();
		for(int i=0;i<s.length();i++) {
			list.add(s.charAt(i));
		}
		int pivotPos=-1;
		char pivot=0;
		for(int i=list.size()-2;i>=0;i--) {
			if(list.get(i)<list.get(i+1)) {
				pivotPos=i;
				pivot=list.get(i);
				break;
			}
		}
		if(pivotPos==-1&&pivot==0) {
			return "Final";
		}
		int L=pivotPos+1,R=list.size()-1;
		
		
		
		int minPos=-1;
		char min =Character.MAX_VALUE;
		
		for(int i=R;i>=L;i--) {
			if(pivot<list.get(i)) {
				if(list.get(i)<min) {
					min=list.get(i);
					minPos=i;
				}
			}
		}
		
		Collections.swap(list, pivotPos, minPos);
		Collections.sort(list.subList(L, R+1));
		
		
		StringBuilder sb=new StringBuilder();
		for(int i=0;i<list.size();i++) {
			sb.append(list.get(i));
		}
		return sb.toString();
	}
	


	
	static void p(String ans) {System.out.println(ans);};
	static void p(int ans) {System.out.println(ans);};
	static void p() {System.out.println();};
	static void p(long ans) {System.out.println(ans);};
	static void p(double ans) {System.out.println(ans);};
	
}
	


Measured memory_bytes: 36024
#include <iostream>
using namespace std;
#include<bits/stdc++.h>
#define ll long long
#define mp make_pair
#define pb push_back
void solve(){
	
}
int main() {
	int h1,s1,h2,s2;
	cin>>h1>>s1>>h2>>s2;
	int l=h2/s1+(h2%s1>0);
	int r=h1/s2+(h1%s2>0);
	if(l-r<=0){
		cout<<"Yes";
	}
	else
	cout<<"No";
	return 0;
}

Measured memory_bytes: 3656
#include <iostream>

using namespace std;

class Mat
{
public:
    Mat(int sr,int sc)
    {
        r = sr;
        c = sc;
        n = new int*[r];
        for(int i = 0;i < r;i++)
        {
            n[i] = new int[c];
        }
    }
    int calcR(int r);
    int calcC(int c);
    int** n;
    int r;
    int c;
};

int Mat::calcR(int sr)
{
    int s = 0;
    for(int i = 0;i < c;i++)
    {
        s += n[sr][i];
    }
    return s;
}

int Mat::calcC(int sc)
{
    int s = 0;
    for(int i = 0;i < r;i++)
    {
        s += n[i][sc];
    }
    return s;
}

int main()
{
    int r,c;
    cin >> r >> c;
    Mat mat(r,c);
    for(int i = 0;i < r;i++)
    {
        for(int j = 0;j < c;j++)
        {
            int n;
            cin >> n;
            mat.n[i][j] = n;
        }
    }
   for(int i = 0;i < r;i++)
    {
        for(int j = 0;j < c;j++)
        {
            cout << mat.n[i][j] << " ";
        }
        cout << mat.calcR(i) << endl;
    }
    int s = 0;
    for(int i = 0;i < c;i++)
    {
        int cs;
        cs = mat.calcC(i);
        s += cs;
        cout << cs << " ";
    }
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 1228
#![allow(non_snake_case)]
#![allow(dead_code)]
#![allow(unused_macros)]
#![allow(unused_imports)]

use std::str::FromStr;
use std::io::*;
use std::collections::*;
use std::cmp::*;

struct Scanner<I: Iterator<Item = char>> {
    iter: std::iter::Peekable<I>,
}

macro_rules! exit {
    () => {{
        exit!(0)
    }};
    ($code:expr) => {{
        if cfg!(local) {
            writeln!(std::io::stderr(), "===== Terminated =====")
                .expect("failed printing to stderr");
        }
        std::process::exit($code);
    }}
}

impl<I: Iterator<Item = char>> Scanner<I> {
    pub fn new(iter: I) -> Scanner<I> {
        Scanner {
            iter: iter.peekable(),
        }
    }

    pub fn safe_get_token(&mut self) -> Option<String> {
        let token = self.iter
            .by_ref()
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        if token.is_empty() {
            None
        } else {
            Some(token)
        }
    }

    pub fn token(&mut self) -> String {
        self.safe_get_token().unwrap_or_else(|| exit!())
    }

    pub fn get<T: FromStr>(&mut self) -> T {
        self.token().parse::<T>().unwrap_or_else(|_| exit!())
    }

    pub fn vec<T: FromStr>(&mut self, len: usize) -> Vec<T> {
        (0..len).map(|_| self.get()).collect()
    }

    pub fn mat<T: FromStr>(&mut self, row: usize, col: usize) -> Vec<Vec<T>> {
        (0..row).map(|_| self.vec(col)).collect()
    }

    pub fn char(&mut self) -> char {
        self.iter.next().unwrap_or_else(|| exit!())
    }

    pub fn chars(&mut self) -> Vec<char> {
        self.get::<String>().chars().collect()
    }

    pub fn mat_chars(&mut self, row: usize) -> Vec<Vec<char>> {
        (0..row).map(|_| self.chars()).collect()
    }

    pub fn line(&mut self) -> String {
        if self.peek().is_some() {
            self.iter
                .by_ref()
                .take_while(|&c| !(c == '\n' || c == '\r'))
                .collect::<String>()
        } else {
            exit!();
        }
    }

    pub fn peek(&mut self) -> Option<&char> {
        self.iter.peek()
    }
}

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin.bytes().map(|c| c.unwrap() as char));
    let N: usize = sc.get();
    let mut s = HashSet::new();
    for _ in 0..N {
        let S: String = sc.get();
        s.insert(S);
    }
    println!("{}", s.len());
}


Measured memory_bytes: 15236
import heapq
N, M = map(int,input().split())
reward = [[] for _ in range(M)]
for i in range(N):
  A,B = map(int,input().split())
  if A <= M:
    reward[A-1].append(B)
q = []
ans = 0
for day in range(M):
  for r in reward[day]:
    heapq.heappush(q,-r)
  if len(q) >0:
    ans += -heapq.heappop(q)
print(ans)

Measured memory_bytes: 18468
from operator import itemgetter

N, T = map(int, input().split()) # 横に2個
ct = [list(map(int, input().split())) for _ in range(N)]

ans = -1
ct.sort(key=itemgetter(1))
for i, c in enumerate(ct):
    if c[1] > T:
        break
    if i == 0:
        ans = c[0]
        continue
    ans = min(ans, c[0])

if ans == -1:
    print('TLE')
else:
    print(ans)

Measured memory_bytes: 3064
n,m=map(int,input().split())
s=set()
t=set()
for _ in range (m):
  a,b=(map(int,input().split())) 
  if a==1:
    s.add(b)
  if b==n:
    t.add(a)

res=s&t
if res:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Measured memory_bytes: 58328
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout
	cnt := 0

	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
		cnt = 6
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)
	solve(scanner, writer)
	for i := 0; i < cnt; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
	writer.Flush()
}

func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner)
	aa := make([]int, n)

	for i := 0; i < n; i++ {
		aa[i] = getNextInt(scanner)
	}

	sort.Ints(aa)
	if aa[n-1]-aa[0] > 1 {
		fmt.Fprintln(writer, "No")
		return
	}

	if aa[n-1] == aa[0] {
		if n >= aa[0]*2 || n == aa[0]+1 {
			fmt.Fprintln(writer, "Yes")
			return
		}
		fmt.Fprintln(writer, "No")

		return
	}

	l := -1
	r := n
	for l+1 < r {
		m := (l + r) >> 1
		if aa[m] == aa[0] {
			l = m
			continue
		}
		r = m
	}
	if aa[n-1]-r > 0 && (n-r)%(aa[n-1]-r) == 0 {
		fmt.Fprintln(writer, "Yes")
		return
	}
	fmt.Fprintln(writer, "No")
}


Measured memory_bytes: 2432
def paint(f_inp, x, y):
    if f_inp[y][x]:
        f_inp[y][x] = False
        if f_inp[y][x - 1]:
            f_inp = paint(f_inp, x - 1, y)
        if f_inp[y][x - 2]:
            f_inp = paint(f_inp, x - 2, y)
        if f_inp[y][x - 3]:
            f_inp = paint(f_inp, x - 3, y)
        if f_inp[y][x + 1]:
            f_inp = paint(f_inp, x + 1, y)
        if f_inp[y][x + 2]:
            f_inp = paint(f_inp, x + 2, y)
        if f_inp[y][x + 3]:
            f_inp = paint(f_inp, x + 3, y)
        if f_inp[y - 1][x]:
            f_inp = paint(f_inp, x, y - 1)
        if f_inp[y - 2][x]:
            f_inp = paint(f_inp, x, y - 2)
        if f_inp[y - 3][x]:
            f_inp = paint(f_inp, x, y - 3)
        if f_inp[y + 1][x]:
            f_inp = paint(f_inp, x, y + 1)
        if f_inp[y + 2][x]:
            f_inp = paint(f_inp, x, y + 2)
        if f_inp[y + 3][x]:
            f_inp = paint(f_inp, x, y + 3)
    return f_inp

i_data = 1
n = int(input())
for i in range(n):
    _ = input()
    print("Data " + str(i_data) + ":")
    f = [[False for i in range(14)] for j in range(14)]
    for i in range(8):
        inp = input()
        for j in range(8):
            if inp[j] == "1":
                f[i + 3][j + 3] = True
    x = int(input())
    y = int(input())
    f = paint(f, x + 2, y + 2)
    for i in range(8):
        s = ""
        for j in range(8):
            if f[i + 3][j + 3]:
                s = s + "1"
            else:
                s = s + "0"
        print(s)
    i_data += 1



Measured memory_bytes: 5628
/*input
11
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
#define pb push_back 

int main() {
  
int n;
cin>>n;
int odd,even;

if(n%2==0)
	{odd=n/2;even=n/2;}
else
{
	odd=n/2+1;even=n/2;
}
cout<<odd*even;

return 0;
} 

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){
    int n;
    int f=0,g=0,h=0,i=0;
    string kase[100000];
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> kase[i];
    }
    for(int u=0;u<n;u++){
        if(kase[u]=="AC"){
            f=f+1;
        }else if(kase[u]=="WA"){
            g=g+1;
        }else if(kase[u]=="TLE"){
            h=h+1;
        }else if(kase[u]=="RE"){
            i=i+1;
        }
    }
    cout << "AC x" " "<< f << endl;
    cout << "WA x" " "<< g << endl;
    cout << "TLE x" " "<< h << endl;
    cout << "RE x" " "<< i << endl;

    return 0;
}


Measured memory_bytes: 6748
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(200002)

def dfs(s):
    for t, d in G[s]:
        if x[t] is None:
            x[t] = x[s] + d
            if not dfs(t):
                return False
        else:
            if x[t] - x[s] != d:
                return False
    return True

N, M = map(int, input().split())
x = [None] * N
G = [[] for _ in range(N)]
for i in range(M):
    L, R, D = map(int, input().split())
    L -= 1
    R -= 1
    G[L].append([R, D])
    G[R].append([L, -D])
ans = True
for i in range(N):
    if x[i] is None:
        x[i] = 0
        if not dfs(i):
            ans = False
print(('No', 'Yes')[ans])


Measured memory_bytes: 135144
"use strict";
const Main = (input) =>{
   let xs = input.trim().split('\n')
   let K = Number(xs[0]);
   let A = Number(xs[1].split(' ')[0]);
   let B = Number(xs[1].split(' ')[1]);
   let ans = 'NG';
   for(let i=A; A<=B; A++)
   if(A%K<=0){
   ans ='OK';
   break;
   }
   console.log(ans);
}
Main(require('fs').readFileSync('/dev/stdin','utf8'));

Measured memory_bytes: 29624
#include <bits/stdc++.h>
int main()
{
    int N,M;
    std::cin >> N >> M;
    std::vector<std::vector<int>> s(M);
    for(int i = 0, k; i < M; i++){
        std::cin >> k, s[i].resize(k);        
        for(int j =0;j < k; j++){std::cin >> s[i][j], s[i][j]--;}
    }
    std::vector<int> p(M);
    for(int i = 0; i < M; i++){std::cin >> p[i];}
    const int MASK = 1<<N;
    int ans = 0;
    for(int mask = 0; mask < MASK; mask++){
        int ok = 0;
        for(int i = 0; i < M; i++){
            int num = 0;
            for(const int sw: s[i]){
                if(mask&(1<<sw)){num++;}
            }
            if(num%2==p[i]){ok++;}
        }
        if(ok==M){ans++;}
    }
    std::cout << ans << std::endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;

int main() {
  int n; cin >> n;
  int x[n];
  int sum =0;
  for(int i = 0; i < n; i++){
    cin >> x[i];
  }
  int ans = 100000000;
  for(int i = 1; i <= 100; i++){
    int cnt = 0;
    for(int j = 0; j < n; j++){
      cnt += (x[j]-i)*(x[j]-i);
    }
    ans = min(ans,cnt);
  }
  cout << ans << endl;
}


Measured memory_bytes: 3556
use v5.18;
use warnings;
sub read_line { chomp(my $s = <>); $s }
sub splited_read_line { split / /, read_line }

# 5, 2, 9
my ($a, $b, $c) = splited_read_line;
say solve();

sub solve {
  if ( $a + $b == 0 ) {
    $c > 0 ? 1 : 0
  }
  elsif ( $c <= $a + $b + 1 ) {
    $b + $c;
  }
  else {
    $b + ($a + $b + 1);
  }
}


Measured memory_bytes: 640
N = int(input())
S = list(input())

r = []
g = []
b = []

for i, s in enumerate(S):
    if s == 'R':
        r.append(i)
    elif s == 'G':
        g.append(i)
    else:
        b.append(i)
        
b = set(b)

ans = 0        

for ri in r:
    for gi in g:
        add = len(b)
        if ri - abs(gi-ri) in b:
            add -= 1
        if ri + abs(gi-ri) in b:
            add -= 1
        if gi - abs(gi-ri) in b:
            add -= 1
        if gi + abs(gi-ri) in b:
            add -= 1
        if abs(gi-ri) % 2 == 0:
            if min(ri,gi) + abs(gi-ri)//2 in b:
                add -= 1
        
        ans += max(0, add)
        
print(ans)


Measured memory_bytes: 69452
#include<iostream>
#include<cstring>
#include<queue>
using namespace std;

struct tb{
	int f,t;
	tb(int f,int t): f(f),t(t) {}
};


int n,m,pr,q,r;
int chx[5001][3];

int main(void){
	while(1){
		scanf("%d",&n);
		if(n==0)break;
		queue<tb> c;
		queue<tb> d[4];
		c.push(tb(1,n));
		scanf("%d",&m);
		scanf("%d%d%d",&pr,&q,&r);
		for(int i=0;i<m;i++){
			scanf("%d%d",&chx[i][1],&chx[i][2]);
		}
		for(int i=0;i<m;i++){
			int sh=1,size=0;
			while(c.size()){
				tb p=c.front();c.pop();
				size+=p.t-p.f+1;
				if(sh!=3){
					if(size<=chx[i][sh]){
						d[sh].push(tb(p.f,p.t));
						if(size==chx[i][sh])sh++;
					}else if(sh==2){
						int x=size-p.t+p.f-1;
						int xx=chx[i][2]-x;
						d[2].push(tb(p.f,p.f+xx-1));
						d[3].push(tb(p.f+xx,p.t));
						sh++;

					}else if(sh==1 && size<=chx[i][2]){
						int x=size-p.t+p.f-1;
						int xx=chx[i][1]-x;
						d[1].push(tb(p.f,p.f+xx-1));
						d[2].push(tb(p.f+xx,p.t));
						if(size==chx[i][2])sh++;
						sh++;
					}else{
						int x=size-p.t+p.f-1;
						int xx=chx[i][1]-x;
						int x2=chx[i][2]-chx[i][1];
						d[1].push(tb(p.f,p.f+xx-1));
						d[2].push(tb(p.f+xx,p.f+xx+x2-1));
						d[3].push(tb(p.f+xx+x2,p.t));
						sh=3;
					}
				}else d[sh].push(tb(p.f,p.t));
			}
			for(int j=3;j>=1;j--){
				while(d[j].size()){
					tb p=d[j].front();d[j].pop();
					int pf=p.f,pt=p.t;
					c.push(tb(pf,pt));
				}
			}
		}
		int size=1;
		int ans=0;
		while(c.size()){
			tb p=c.front();c.pop();
			int x=p.f,y=p.t;
			int s=y-x+1;
			if(size<pr)x+=pr-size;
			if(size+s>q)y-=size+s-q-1;
			if(y>r)y=r;
			if(y>=x)ans+=y-x+1;
			//printf("%d %d %d %d\n",p.f,p.t,x,y);
			size+=s;
		}
		printf("%d\n",ans);
	}
    return 0;
}

Measured memory_bytes: 1036
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i = 0; i < (N); i++)
#define repo(i,N) for(int i = 1; i < (N); i++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
//#define num 1000000007
#define pi acos(-1.0)
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//#define int long long

int main() {
  int a,b;
  cin >>a>>b;
  
  cout << a+b/2 << endl;
  
}

Measured memory_bytes: 256
#include<stdio.h>

typedef struct TMP{
  int shi;
  int p;
  int y;
  int ans;
}TEST;

int asc(const void *a, const void *b) {
  TEST test1 = *(TEST *)a;
  TEST test2 = *(TEST *)b;

  int tmp1 = test1.y;
  int tmp2 = test2.y;
  return tmp1 - tmp2;
}

int asc1(const void *a, const void *b) {
  TEST test1 = *(TEST *)a;
  TEST test2 = *(TEST *)b;

  int tmp1 = test1.shi;
  int tmp2 = test2.shi;
  return tmp1 -tmp2;
}

int main(){
  int i,n,m,k;
  scanf("%d%d",&n,&m);
  TEST hoge[100001];
  int answer[100001];
  for(i=0;i<m;i++){
    hoge[i].shi=i;
    scanf("%d%d",&hoge[i].p,&hoge[i].y);
  }
  qsort(hoge,m,sizeof(TEST),asc);
  for(i=0;i<m;i++){
    answer[hoge[i].p]++;
    hoge[i].ans=answer[hoge[i].p];
  }
  qsort(hoge,m,sizeof(TEST),asc1);
  for(i=0;i<m;i++){
    printf("%06d%06d\n",hoge[i].p,hoge[i].ans);
  }
  return 0;
}

Measured memory_bytes: 4964
#include<bits/stdc++.h>
#define    ll   long long int
#define    sz   200010

using namespace std;


ll num[sz];


int main()
{

     ll n,i,j,k,a,c,b,x;
     cin>>n;

     for(i=1;i<=n;i++)
     {
         cin>>num[i];
     }
     sort(num+1,num+n+1);

     a=n/2;
     b=a+1;

     a=num[a];
     b=num[b];

     cout<<b-a<<endl;




    return 0;
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;

ll ans=0;

ll arr[10];
int n,m,q;
vector<int> A(60),B(60),C(60),D(60);

void dfs(int p, int v){
  arr[p]=v;
  if(p==9){
    ll pnt=0;
    for(int i=0;i<q;i++){
      if(arr[B[i]-1]-arr[A[i]-1]==C[i]){
        pnt+=D[i];
      }
    }
    ans=max(pnt, ans);
    return;
  }
  for(int i=v;i<=m;i++){
    dfs(p+1, i);
  }
}

int main(int argc, char *argv[]) { ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
  cin>>n>>m>>q;
  for(int i=0;i<q;i++){
    cin>>A[i]>>B[i]>>C[i]>>D[i];
  }
  dfs(0, 1);
  cout<<ans<<endl;
  
  return 0;
}


Measured memory_bytes: 3660
//線型探索

#include<stdio.h>
#include<stdlib.h>

int main(void){
  int n,q,cnt=0,work;
  int *S;
  int i,j;

  scanf("%d",&n);

  S=(int *)malloc(sizeof(int)*n);

  for(i=0;i<n;i++)scanf("%d",&S[i]);

  scanf("%d",&q);

  for(i=0;i<q;i++){
    scanf("%d",&work);
    for(j=0;j<n;j++){
      if(S[j]==work){
	cnt++;
	break;
      }
    }
  }

  printf("%d\n",cnt);

  free(S);
}

Measured memory_bytes: 636
import collections
counter = collections.Counter()
N, M = map(int, input().split())
a = list(map(int, input().split()))
counter.update(a)
for i in range(M):
  b,c = map(int, input().split())
  counter[c] += b
#print(counter)
ans = 0
maisuu = 0
for c, b in sorted(counter.items(), reverse = True):
  if N-maisuu >= b:
    ans += c*b
    maisuu += b
  else:
    ans += c*(N-maisuu)
    maisuu = N
  if maisuu == N:
    break
print(ans)
  




Measured memory_bytes: 40992