akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main()
{
    int t,i,j,k,n,x;
    cin>>n>>k;
    vector <int> arr(n);
    
    for(i=0;i<n;i++)
        cin>>arr[i];
    
    vector <vector <bool>> dp(n,vector <bool> (k+1));
    for(i=0;i<=k;i++)
    {
        int x=i/arr[0];
        if(x%2)
            dp[0][i]=true;
        else
            dp[0][i]=false;
    }
    for(i=0;i<n;i++)
    {
        for(j=0;j<=k;j++)
        {
            if(j==0)
                dp[i][j]=false;
            bool status=false;
            for(x=0;x<=i;x++)
            {
                if(j-arr[x]>=0&&!dp[i][j-arr[x]])
                {
                    status=true;
                    break;
                }
            }
            dp[i][j]=status;
        }
    }
    if(dp[n-1][k])
        cout<<"First"<<endl;
    else
        cout<<"Second"<<endl;
}

Measured memory_bytes: 4564
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define fi first
#define sc second
#define pb push_back
#define COUT(x) cout << (x) << endl
#define COUTF(x) cout << setprecision(15) << (x) << endl
#define ENDL cout << endl
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#define ANS cout << ans << endl
#define RETURN(x)    \
  cout << x << endl; \
  return 0
clock_t CLOCK;
#define START_TIMER CLOCK = clock()
#define SHOW_TIMER cerr << "time: " << (ld)(clock() - CLOCK) / 1000000 << endl
#define init() \
  cin.tie(0);  \
  ios::sync_with_stdio(false)
#define debug(x) cerr << "[debug] " << #x << ": " << x << endl;
#define debugV(v)                       \
  cerr << "[debugV] " << #v << ":";     \
  rep(i, v.size()) cerr << " " << v[i]; \
  cerr << endl;
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using mll = map<ll, ll>;
using qll = queue<ll>;
using P = pair<ll, ll>;

constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr ld PI = 3.141592653589793238462643383279;
ll get_digit(ll x) {
  return to_string(x).size();
}

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

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

vector<P> factorize(ll n) {
  vector<P> result;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      result.pb({i, 0});
      while (n % i == 0) {
        n /= i;
        result.back().second++;
      }
    }
  }
  if (n != 1) {
    result.pb({n, 1});
  }
  return result;
}

vll divisor(ll n) {
  vll ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) ret.push_back(n / i);
    }
  }
  SORT(ret);
  return (ret);
}

signed main() {
  init();
  ll N, T;
  cin >> N >> T;

  ll T_MAX = 6003;
  vll dp(T_MAX);

  vector<P> food(N);
  rep(i, N) cin >> food[i].first >> food[i].second;

  SORT(food);

  rep(i, N) {
    ll a = food[i].first;
    ll b = food[i].second;
    vll t = dp;
    rep(j, T) {
      ll nj = j + a;
      t[nj] = max(t[nj], dp[j] + b);
    }
    dp = t;
  }

  ll ans = 0;
  rep(j, T_MAX) {
    ans = max(ans, dp[j]);
  }
  COUT(ans);
  return 0;
}

Measured memory_bytes: 3800
import math
import itertools
import statistics
import collections

#n = int(input())
#n枚　y円

n, y = list(map(int, input().split()))

for i in range(0, n+1):
    money = 1000*i
   # print(money)
    for j in range(0, n+1-i):
        money = 1000*i
        money += (5000*j + 10000*(n-i-j))
        if money == y and n==i+j+(n-i-j):
           # print("Yes")
            print(str(n-i-j)+" "+str(j)+" "+str(i))
            exit()
        #print(money)

print("-1 -1 -1")




Measured memory_bytes: 5268
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main() {
  int n;
  while (cin >> n) {
    if (n == 0) break;
    int a[n];
    REP(i, n) cin >> a[i];
    int sum[n + 1];
    sum[0] = 0;
    REP(i, n) sum[i + 1] = sum[i] + a[i];
    int ans = -1e9;
    REP1(i, n) REP(j, i) ans = max(ans, sum[i] - sum[j]);
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 3108
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;

public class Main {

	public static void main(String[] args) {
		while (true) {
			int N = nextInt();
			if (N == -1) {
				break;
			}

			ArrayList<Integer> primes = new ArrayList<Integer>();
			if (N < 2) {
				primes.add(2);
				N = 3;
			} else if (N % 2 == 0) {
				N++;
			} else {
				N += 2;
			}
			while (primes.size() <= 30) {
				boolean is_prime = true;
				for (int i = 2; i < Math.sqrt(N) + 1; i++) {
					if (N % i == 0) {
						is_prime = false;
						break;
					}
				}
				if (is_prime) {
					primes.add(N);
				}
				N += 2;
			}

			ArrayList<Integer> matsuzaki = new ArrayList<Integer>();
			for (int i = 0; i < primes.size(); i++) {
				for (int j = i; j < primes.size(); j++) {
					matsuzaki.add(primes.get(i) + primes.get(j));
				}
			}

			Collections.sort(matsuzaki);

			int P = nextInt();
			System.out.println(matsuzaki.get(P - 1));

		}

	}

	static int nextInt() {
		int c;
		try {
			c = System.in.read();
			while (c != '-' && (c < '0' || c > '9'))
				c = System.in.read();
			if (c == '-')
				return -nextInt();
			int res = 0;
			while (c >= '0' && c <= '9') {
				res = res * 10 + c - '0';
				c = System.in.read();
			}
			return res;
		} catch (IOException e) {
			e.printStackTrace();
		}
		return -1;
	}

}

Measured memory_bytes: 63376
a = input()
b = input()
c = input()
d = input()
e = input()
k = input()
a = int(a)
b = int(b)
c = int(c)
d = int(d)
e = int(e)
k = int(k)
if e - a > k:
    print(':(') 
else:
    print('Yay!')

Measured memory_bytes: 3060
#include <stdio.h>

int main() {
    char S[100000];
    char A[100000];
    char B[100000];
    int countA = 0,countB = 0;
    int i = 0,m = 0;
    int len;


    scanf("%s ",S);

    while (S[i] != '\0') {
        i++;
    }
    len = i;
    for (int j = 0; j < len; j = j + 2) {
        A[j] = '1';
        A[j+1] = '0';
        B[j] = '0';
        B[j+1] = '1';
    }


    for (int k =0 ; k < len; ++k) {
        if (S[k] != A[k]) {
            countA++;
        }
        if (S[k] != B[k]) {
            countB++;
        }
    }

    printf("%d",(countA > countB) ? countB : countA);

    return 0;
}

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

int N;
vector<int> A;

int main() {
    cin >> N;
    A.resize(N);
    for (int i=0; i<N; i++) cin >> A[i];
    int res = 0;
    for (int i=0; i<A.size(); i++) {
        for (int j=i+1; j<A.size(); j++) {
            res = res + A[i] * A[j];
        }
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 3592
n,T = map(int,input().split())
c = [0]*n
t = [0]*n

for i in range(n):
    c[i],t[i] = map(int,input().split())

cost= 10000
for i in range(n):
    if t[i] <= T and c[i] <= cost:
        cost = c[i]
        
if cost == 10000:
    print("TLE")
else:
    print(cost)

Measured memory_bytes: 38256
#include<bits/stdc++.h>
using namespace std;
const int Maxn=1e2+10,Maxk=1e5+10;
int N,K; 
int A[Maxn];
int Dp[Maxk];
int main()
{
	cin>>N>>K;
	int Mn=1e9;
	for(int i=0;i<N;i++)
	{
		cin>>A[i];
		Mn=min(Mn,A[i]);
	}
	for(int i=Mn;i<=K;i++)
	{
		bool flag=false;
		for(int j=0;j<N;j++)
		{
			if(i>=A[j]&&!Dp[i-A[j]])
			{	
				flag=true;
				break;
			}
		}
		Dp[i]=flag;
	}
	puts(Dp[K]?"First":"Second");
	return 0;
} 

Measured memory_bytes: 640
#include <bits/stdc++.h>
 
#define ff first
#define ss second
#define mp make_pair
 
using namespace std;

typedef long long ll;

int cnt[200005], m[200005];

int main(){
	int n,p;
	char s[200005];

	scanf("%d%d %s", &n, &p, s);

	ll ans = 0;

	if(p == 2 or p == 5) {
		for(int i = 0; s[i]; i++)
			if((s[i]-'0')%p == 0) ans += i+1;
		
		printf("%lld\n", ans);
		return 0;
	}

	int b = 1;
	for(int i = (int)strlen(s)-1; i >= 0; i--) {
		int x = s[i] - '0';
		m[i] = (x*b)%p;
		b = (b*10)%p;
	}

	cnt[0] = 1;

	for(int i = 0; s[i]; i++) {
		if(i) m[i] = (m[i] + m[i-1])%p;
		cnt[m[i]]++;
	}

	for(int i = 0; i < p; i++)
		ans += (ll)cnt[i]*(cnt[i]-1)/2;

	printf("%lld\n", ans);

	return 0;
}

Measured memory_bytes: 1280
import scala.math._

object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val a, b, c, d = sc.nextLong

  val lc = lcm(c, d)
  val total = b / c + b / d - b / lc
  val part = a / c + a / d - a / lc
  val ans = b - a - (total - part) + (if (a % c != 0 && a % d != 0) 1 else 0)

  println(ans)

  ///////////////////////////////////////////

  def bigIterator(start: BigInt, end: BigInt, step: BigInt = 1) =
    Iterator.iterate(start)(_ + step).takeWhile(_ <= end)

  def gcd(a: Int, b: Int): Int =
    if (b == 0) a else gcd(b, a % b)

  def gcd(a: Long, b: Long): Long =
    if (b == 0) a else gcd(b, a % b)

  def lcm(a :Int, b :Int): Int =
    a / gcd(a, b) * b

  def lcm(a :Long, b :Long): Long =
    a / gcd(a, b) * b
}

Measured memory_bytes: 25796
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
int ans;
int d[4];
int n;

// 1+2+4+8=15
void rec(int use) {
  if(use == 15) {
    if(d[0]+d[1]+d[2]+d[3]==n) ans++;
  }
  for(int i=0;i<4;i++) {
    if(use & (1<<i)) return;
    for(int j=0;j<10;j++) {
      d[i]=j;
      rec(use|(1<<i));
    }
  }
}

main() {
  while(cin>>n) {
    ans=0; rec(0);
    cout <<ans<<endl;
  }
}

Measured memory_bytes: 0
#include <bits/stdc++.h>

#define optimizar_io ios_base::sync_with_stdio(0);cin.tie(0);

using namespace std;

int main(){
	optimizar_io;
	int N;
	cin >> N;
	int data[N];
	for (int i = 0; i < N; i++){
		cin >> data[i];
	}
	int sol = 0;
	for (int i = 0; i < N; i++){
		for (int j = i + 1; j < N; j++){
			sol += data[i] * data[j];
		}
	}
	cout << sol << endl;
	return 0;
}


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

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

  ll N; cin >> N;
  ll K; cin >> K;
  ll ans;
  ll MAX = K - 1;
  for (ll i = 1; i < N + K; i++) {
    if (N <= MAX) {
      ans = i;
      break;
    } else {
      MAX = MAX * K + K - 1;
    }
  }
  cout << ans << '\n';
  return 0;
}

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

int main(){
  string s; cin>>s;
  
  vector<char> sv(4);
  for (int i=0; i<4; i++) sv[i]=s[i];
  sort(sv.begin(), sv.end());
  if (sv[0]==sv[1] && sv[1]!=sv[2] && sv[2]==sv[3]){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <algorithm>

#define MOD 1000000007

inline int getnum()
{
	char c=getchar();
	while(!(c>='0' && c<='9'))
		c=getchar();
	int num=0;
	while(c>='0' && c<='9')
	{
		num*=10;num+=c-'0';
		c=getchar();
	}
	return num;
}

int m[505050];

int _factor(int num)
{
	int ans=1;
	for(register int i=2;i<=num;i++)
		ans=(long long)ans*i%MOD;
	return ans;
}

int inv[505050];
void initinv(int num)
{
	inv[1]=1;
	for(register int i=2;i<=num;i++)
		inv[i]=(long long)(MOD-MOD/i)*inv[MOD%i]%MOD;
}

unsigned s[505050];
int main()
{
	int N;scanf("%d",&N);
	for(register int i=1;i<=N;i++)
		m[i]=getnum();
	initinv(N);
	
	for(register int i=1;i<=N;i++)
		s[i]=(s[i-1]+inv[i])%MOD;
	unsigned ans=0;
	for(register int i=1;i<=N;i++)
		ans=(ans+(long long)(s[N-i+1]+s[i]-1)*m[i])%MOD;
	ans=(long long)ans*_factor(N)%MOD;
	printf("%u\n",ans);
	
	return 0;
}

Measured memory_bytes: 2944
#include <bits/stdc++.h>
#define ll long long
using namespace std;

int main() {
    ll x,n,d,y;
    cin>>n;
    if(n%2==0||n%5==0){
        cout<<"-1";
        return 0;
    }
    ll rem=7;
    ll prev_add=1;
    ll cnt=1;
    int flag=0;
    while(1){
       if(rem%n==0){
           cout<<cnt;
           break;
       }
       prev_add=(prev_add*10)%n;
       rem+=(prev_add*7)%n;
       cnt++;
    }
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define rep(i,s,n) for (int i = s; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
using graph = map<int, vector<int>>;
 
int dfs(graph &G, vector<bool> &seen, int v, int cnt, vector<int> &ans, vector<int> &px) {
  seen[v] = true;
  cnt += px[v];
  ans[v] = cnt;
  for (auto nv : G[v]) {
    if (seen[nv]) continue;
    dfs(G,seen,nv,cnt,ans,px);
  }
  cnt -= px[v];
  return 0;
}
 
int main() {
  int n,q;
  cin >> n >> q;
  graph G;
  rep(i,0,n-1) {
    int a,b;
    cin >> a >> b;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  vector<int> px(n+1,0);
  rep(i,0,q) {
    int p,x;
    cin >> p >> x;
    px[p] += x;
  }
  vector<bool> seen(n+1,false);
  vector<int> ans(n+1,0);
  
  dfs(G,seen,1,0,ans,px);
 
  rep(i,1,n) cout << ans[i] << " ";
  cout << ans[n] << endl;
 
  return 0;
}

Measured memory_bytes: 48568
#from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
import copy
N = int(input())

A = []
for _ in range(N):
  A.append(list(map(int, input().split())))
  
D = copy.deepcopy(A)
for i in range(N):
  D[i][i] = 0
  
for k in range(N):
  for i in range(N):
    for j in range(N):
      D[i][j] = min(D[i][j], D[i][k] + D[k][j])
      
#G = csgraph_from_dense(A)
#D = floyd_warshall(G)

ans = 0
for i in range(N):
  for j in range(i+1,N):
    if D[i][j] < A[i][j]:
      print(-1)
      exit(0)
      
for i in range(N):
  for j in range(i+1,N):
    flg = True
    for k in range(N):
      if i == k or j == k:
        continue
      if D[i][j] == D[i][k] + D[k][j]:
        flg = False
    if flg:
      ans += D[i][j]
      
print(int(ans))

Measured memory_bytes: 76860
#input
n = int(input())
H = []
for _ in range(n):
    a, b = map(int, input().split())
    H.append([a + b, a, b])

H = sorted(H, reverse = True)
sum_c = 0
sum_a = 0

for i in range(n):
    if i % 2 == 0:
        sum_c += H[i][1]
    else:
        sum_a += H[i][2]

ans = sum_c - sum_a
print(ans)

Measured memory_bytes: 24028
N, M = map(int, input().split())
L = [list(map(int, input().split())) for _ in range(N)]
L.sort(key=lambda x: x[0])
S = 0
for l in L:
  if l[1]>=M:
    S += l[0]*M
    break
  else:
    S += l[0]*l[1]
    M -= l[1]
print(S)

Measured memory_bytes: 28560
### constant

R = 6378.1

### main

while true
  a, b, c, d = gets.strip.split(' ').map{|s| s.to_f}
  break if a < 0 && b < 0 && c < 0 && d < 0

  th0 = a * Math::PI / 180
  ph0 = b * Math::PI / 180
  th1 = c * Math::PI / 180
  ph1 = d * Math::PI / 180

  x0 = Math.cos(ph0) * Math.cos(th0)
  y0 = Math.sin(ph0) * Math.cos(th0)
  z0 = Math.sin(th0)

  x1 = Math.cos(ph1) * Math.cos(th1)
  y1 = Math.sin(ph1) * Math.cos(th1)
  z1 = Math.sin(th1)

  dd = (x0 - x1) ** 2 + (y0 - y1) ** 2 + (z0 - z1) ** 2

  th = Math.acos(1 - dd / 2)

  r = (R * th).round

  puts r
end

Measured memory_bytes: 6256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main(){
	ll a, b, n;
	cin >> a >> b >> n;
	ll x = min(b-1, n);
	printf("%lld\n", ((a*x)/b) - (a * (x/b)));
	return 0;
}

Measured memory_bytes: 3748
#include <bits/stdc++.h>
#include <numeric>
#define ll long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

#define pr pair<int, int>

using namespace std;

const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;


//#define DEBUG

#ifdef DEBUG
#define PRINT(A) std::cout << (#A) << ":" << (A) << std::endl;
#else
#define PRINT(A)
#endif

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 a[10010][10010], b[1000];
int dp[10010][3];
 

int main()
{

    //int N, M; cin >> N >> M;
    string S; cin >> S;
    int len = S.length();
    bool b = true;
    for(int i = 0; i < len/2; i++){
        if(S[i] != S[len-i-1]){
            b = false;
        }
        
        if(i < len/2/2){
            if(S[i] != S[len/2 -i -1]){
                b = false;
            }
        }
    }

    cout << (b?"Yes":"No") << endl;

    

    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <cstring>
#define min(a,b) (((a)<(b))?((a)):((b)))
#define MAX 100000
int altura[MAX];
int custo(int n)
{
    int menorCustoAte[MAX];
    for(int i = 0; i < n; i++)
        menorCustoAte[i] = INT_MAX;
    menorCustoAte[0] = 0;
    for(int i = 0; i < n; i++)
    {
        if(i < n - 1)
            menorCustoAte[i + 1] = min(menorCustoAte[i + 1],
                    menorCustoAte[i] + abs(altura[i] - altura[i + 1]));
        if(i < n - 2)
            menorCustoAte[i + 2] = min(menorCustoAte[i + 2],
                    menorCustoAte[i] + abs(altura[i] - altura[i + 2]));
    }
    return menorCustoAte[n - 1];
}
int main()
{
    int n;
    scanf("%d", &n);
    for(int i = 0; i < n; i++)
        scanf("%d", &altura[i]);
    printf("%d\n", custo(n));
}

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

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int h, w, k;
    string s[10];
    int sum[11][1001];

    cin >> h >> w >> k;
    for(int i=0;i<h;++i) cin >> s[i];

    for(int i=0;i<=h;++i) sum[i][0] = 0;
    for(int j=0;j<=w;++j) sum[0][j] = 0;
    for(int i=1;i<=h;++i){
        for(int j=1;j<=w;++j){
            sum[i][j] = sum[i-1][j] + sum[i][j-1] - sum[i-1][j-1] + (s[i-1][j-1] - '0');
        }
    }

    int ans = h + w - 2;
    for(int ptn=0;ptn<(1<<h-1);++ptn){
        vector<int> sep;
        sep.emplace_back(0);
        for(int i=0;i<h-1;++i){
            if((ptn>>i) & 1) sep.emplace_back(i+1);
        }
        sep.emplace_back(h);

        int cand = sep.size() - 2;
        int left = 0;
        for(int pos=1;pos<=w;++pos){
            vector<int> cur;
            for(size_t i=1;i<sep.size();++i){
                cur.emplace_back(sum[sep[i]][pos] - sum[sep[i]][left ] - sum[sep[i-1]][pos] + sum[sep[i-1]][left ]);
            }
            if(*max_element(cur.begin(), cur.end()) > k){
                if(left == pos-1){
                    cand = h * w;
                    break;
                }else{
                    ++cand;
                    left = pos - 1;
                }
            }
        }
        ans = min(ans, cand);
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
n = gets.to_i
line =gets.split(' ').map(&:to_i)

kotae = 100
for t in 0..n-1
  ss = 0
  so = 0
  for j in 0..t do
   ss += line[j]
  end
  so = line.inject(:+)-ss
  sa = (ss-so).abs
  if sa<= kotae
    kotae = sa
  end
end
puts kotae


Measured memory_bytes: 1788
a = int(input())
A = a%500
b = a//500
c = a-(b*500)
d = c//5

X = (a/500)*1000
Y = b*1000 + d*5
Z = (a//5)*5

if a == 0:
    print(0)
elif a < 5:
    print(0)
elif A == 0:
    print(int(X))
elif b>0 and d > 0:
    print(int(Y))
elif b>0 and d < 0:
    print(int(b*1000))
elif b == 0 and d > 0:
    print(int(Z))
elif b == 0 and d < 0:
    print(0)

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

typedef long long ll;

bool comp(pair<ll,ll> a, pair<ll,ll> b){
    if(a.first != b.first){
        return a.first < b.first;
    } else {
        return a.second < b.second;
    }
}

int main() {
    ll N; cin >> N;
    vector<ll> A(N), B(N);
    vector<pair<ll,ll> > d(N);
    for(ll i=0; i<N; i++) cin >> A[i] >> B[i];
    for(ll i=0; i<N; i++) {
        d[i].first = A[i]+B[i];
        d[i].second = i;
    }
    sort(d.begin(), d.end(), comp);
    reverse(d.begin(), d.end());
    
    ll a=0,t=0;
    for(ll i=0; i<N; i++){
        //cout << d[i].first <<" "<< d[i].second << endl;
        if(i%2==0) t+=A[d[i].second];
        else a+=B[d[i].second];
    }
    
    //cout << t <<" "<< a << endl;
    cout << t - a << endl;
}


Measured memory_bytes: 3328
n, x, y = map(int, input().split())
x -= 1
y -= 1

dists = [0] * (n - 1)
for i in range(n - 1):
    for j in range(i + 1, n):
        dists[min(j - i, abs(x - i) + abs(y - j) + 1) - 1] += 1
[print(dist) for dist in dists]


Measured memory_bytes: 3444
#include<cstdio>
#include<algorithm>
#include<iostream>
using namespace std;
int n,m;
int a[120][120];
int dp[120][120];
int main()
{
	cin>>m;
  	n=2;
  	for(int i=1;i<=n;i++)
    {
      	for(int j=1;j<=m;j++)
        {
          	cin>>a[i][j];
        }
    }
  	dp[1][1]=a[1][1];
	for(int i=2;i<=n;i++)
    {
      	dp[i][1]=dp[i-1][1]+a[i][1];
    }
  	for(int j=2;j<=m;j++)
    {
      	dp[1][j]=dp[1][j-1]+a[1][j];
    }
  	for(int i=2;i<=n;i++)
    {
      	for(int j=2;j<=m;j++)
        {
          	dp[i][j]=max(dp[i-1][j],dp[i][j-1])+a[i][j];
        }
    }
  	cout<<dp[n][m]<<endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		int n = in.nextInt();
		int[] l = new int[n];
		for (int i = 0; i < n; i++)
			l[i] = in.nextInt();
		int r = solve(l);
		System.out.println(r);
		in.close();
	}

	private static int solve(int[] l) {
		Arrays.sort(l);
		int r = 0;
		for (int i = l.length - 1; i >= 0; i--)
			for (int j = i - 1; j >= 0; j--) {
				if (l[j] * 2 < l[i])
					break;
				for (int k = j - 1; k >= 0; k--)
					if (l[j] + l[k] <= l[i])
						break;
					else
						r++;
			}
		return r;
	}
}

Measured memory_bytes: 26652
#
# File    : B.rb
# Author  : Kazune Takahashi
# Created : 2019-5-25 21:02:10
# Powered by Visual Studio Code
#

r, d, x = gets.chomp.split(" ").map{|i| i.to_i}
for i in 0...10
  x = r * x - d
  puts x
end


Measured memory_bytes: 1788
#include<stdio.h>

int main(void){
	long d,i,y,x,ans;
	
	while(scanf("%ld",&d)!=EOF){
		ans=0;
		for(i=0;i*d<600;i++){
			ans+=d*(i*d)*(i*d);
		}
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <queue>
#include <algorithm>
#include <vector>
#include <climits>
#define int long long
using namespace std;
typedef pair <int,int> P;
#define to first
#define co second
#define fi first
#define se second
const int INF=INT_MAX;
const int MAX_V=100000;
vector <P> G[MAX_V];
int v,d[MAX_V];
void dijk(int s){
  priority_queue <P,vector<P>,greater<P> > que;
  fill(d,d+v,INF);
  d[s]=0;
  que.push(P(0,s));
  for(;!que.empty();){
    P p=que.top(); que.pop();
    int v=p.se;
    if (d[v]<p.fi) continue;
    for(int i=0;i<(int)G[v].size();i++){
      P e=G[v][i];
      if(d[e.to]>d[v]+e.co){
	d[e.to]=d[v]+e.co;
	que.push(P(d[e.to],e.to));
      }
    }
  }
}
signed main(){

  cin>>v;
  for(int i=0,u,k;i<v&&cin>>u>>k;i++) for(int j=0,a,b;j<k&&cin>>a>>b;j++) G[u].push_back(P(a,b));
  dijk(0);
  for(int i=0;i<v;i++) cout<<i<<" "<<d[i]<<endl;
  return 0;

}

Measured memory_bytes: 14144
#include <iostream>
#include <queue>

using namespace std;
int main(void){
    queue<string> lq;
    queue<int> tq;
    int n,qlim;
    cin >> n >> qlim;
    for(int i=0;i<n;i++){
        string l;
        int t;
        cin >> l >> t;
        lq.push(l);
        tq.push(t);
    }

    int c=0;
    int q=0;
    while(!lq.empty()){
      c++;
      q++;
      if(q==tq.front()){
            cout << lq.front() << " " << c << endl;
            lq.pop();
            tq.pop();
            q=0;
      }else if(q==qlim){
            lq.push(lq.front());
            tq.push(tq.front()-qlim);
            lq.pop();
            tq.pop();
            q=0;
      }
    }
}



Measured memory_bytes: 5792
#include <bits/stdc++.h>
/*#include <iostream>
#include <set>
#include <vector>
#include <cstring>
#include <algorithm>
#include <climits>
#include <iomanip>
*/
using namespace std;

#define FAST       			ios_base :: sync_with_stdio(false); cin.tie(NULL); 
#define endl "\n"

typedef long long int  ll;
typedef unsigned long long int ull;

int ans = 0;

bool isgood(string str)
{
    bool count[10] = {0};
    memset(count , 0 , sizeof(count));
    
    for(int i=0 ; i<str.size() ; i++)
        count[str[i]-'0'] = 1;
        
    return (count[3] == 1 && count[5] == 1 && count[7] == 1);
}

void produce(int i , int n , string str , string a)
{
	if(i == n)
	{
	    if(isgood(str) && str <= a)
	        ans++;
    	return;
	}
	
	if(isgood(str))
        ans++;
	
	produce(i+1 , n , str+'3' , a);
	produce(i+1 , n , str+'5' , a);
	produce(i+1 , n , str+'7' , a);
}

int main()
{
	FAST;
	string str;
	cin >> str;

    produce(0 , str.size() , "" , str);
    
	cout << ans;

	return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    int n = Integer.parseInt(in.readLine());
    System.out.println(n%2==0?n:2*n);
  }
}

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

int main(void) {
    int N; cin >> N;
    
    vector<int> d(N);
    for (int i=0; i<N; i++) {
        cin >> d[i];
    }
    
    sort(d.begin(), d.end());

    int K_min = d[0];
    int range_min = 0;
    for (K_min=d[0], range_min=0; range_min < N;) {
        while (d[range_min]==K_min) range_min++;
        if (range_min < N/2) {
            K_min = d[range_min];
            range_min++;
        } else if (range_min == N/2) {
            cout << d[range_min] - K_min;
            break;
        } else {
            cout << "0";
            break;
        }
    }

    return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define SIZMAX int(2e5+10)
#define mod int(1e9+7)
#define inf int(1e9+5)

int main()
{
  ll n; cin>>n;
  vector<ll> arr(n);
  for(ll i=0;i<n;i++) cin>>arr[i];
  vector<ll> dp(n,inf);
  dp[0]=0;
  for(ll i=0;i<n;i++){
    for(int j:{i+1,i+2}){
      if(j<n){
        dp[j]=min(dp[j],dp[i]+abs(arr[i]-arr[j]));
        //cout<<dp[j]<<endl;
      }
    }
  }
  cout<<dp[n-1];
  return 0;
}

Measured memory_bytes: 1792
import java.io.*; 
import java.util.*; 
public class Main {
    static ArrayList<Integer> adj_lst[];
    static boolean vis[];
    static int dp[];
    public static void main(String args[]){
        Scanner input=new Scanner(System.in);
        int n=input.nextInt();
        int m=input.nextInt();
        adj_lst=new ArrayList[n];
        vis=new boolean[n];
        dp=new int[n];
        for(int i=0;i<adj_lst.length;i++) {
            adj_lst[i]=new ArrayList<Integer>();
            dp[i]=-1;
        }
        for(int i=0;i<m;i++) {
            int u=input.nextInt()-1;
            int v=input.nextInt()-1;
            adj_lst[u].add(v);
        }
//        for(int i=0;i<adj_lst.length;i++) {
//            System.out.print(i+"->");
//            for(int j=0;j<adj_lst[i].size();j++) {
//                System.out.print(adj_lst[i].get(j)+" ");
//            }
//            System.out.println();
//        }
        for(int i=0;i<n;i++) {
            if(!vis[i]) {
                solve(i);
            }
        }
        int max=Integer.MIN_VALUE;
        for(int i=0;i<n;i++) {
            max=Math.max(max,dp[i]);
        }
        System.out.println(max);
    }
    public static void solve(int root) {
        vis[root]=true;
        if(adj_lst[root].size()==0) {
            dp[root]=0;
            return;
        }
        dp[root]=Integer.MIN_VALUE;
        for(int i=0;i<adj_lst[root].size();i++) {
            if(dp[adj_lst[root].get(i)]==-1) {
                solve(adj_lst[root].get(i));
            }
            dp[root]=Math.max(dp[root],1+dp[adj_lst[root].get(i)]);
        }
    }
}


Measured memory_bytes: 107252
// A.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <map>
#include <set>

using namespace std;

typedef long long LL;

// 掃き出し法
bool possible(LL t, vector<LL> a) {
	if (a.empty()) return t == 0;
	LL x = 0;
	int st = 0;
	int sz = (int)a.size();
	sort(a.rbegin(), a.rend());
	vector<int> bp(64, -1);
	for (LL b = 60; b >= 0; --b) {
		LL f = 1LL << b;
		if (!(a[st] & f)) continue;
		for (int i = 0; i < sz; ++i) {
			if (i != st && (a[i] & f) != 0) a[i] ^= a[st];
		}
		bp[b] = st++;
		if (st >= sz) break;
		sort(a.rbegin(), a.rbegin() + sz - st);
	}
	for (LL b = 60; b >= 0; --b) {
		LL f = 1LL << b;
		if ((f & t) != 0 && (f & x) == 0 && bp[b] >= 0) {
			x ^= a[bp[b]];
		}
	}
	return t == x;
}

int main(int argc, char* argv[]) {
	LL t, n;
	cin >> t;
	for (LL tt = 0; tt < t; ++tt) {
		cin >> n;
		vector<LL> a(n);
		for (LL i = 0; i < n; ++i) {
			cin >> a[i];
		}
		string s;
		cin >> s;
		int ans = 0;
		vector<LL> x;
		for (LL i = n - 1; i >= 0; --i) {
			if (s[i] != '0') {
				if (!possible(a[i], x)) {
					ans = 1;
					break;
				}
			} else {
				x.emplace_back(a[i]);
			}
		}
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 3592
def spaceinput():
    return list(map(int,input().split(" ")))
N=int(input())
aa=spaceinput()


suml=aa[0]
sumr=sum(aa[1:])
minv=10**10
for i in range(1,len(aa)+1):
    #print(suml,sumr)
    v=abs(suml-sumr)
    if minv>v:
        minv=v

    if i==len(aa)-1:
        break
    suml+=aa[i]
    sumr-=aa[i]


print(minv)


Measured memory_bytes: 24800
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<sstream>
#include<complex>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()

using namespace std;

typedef unsigned int uint;
typedef long long ll;
typedef complex<double> P;

const int mask = (1<<10)-1;

int main(){
  int n;
  scanf("%d",&n);
  while(n --> 0){
    int data[10] = { 0 };
    REP(i,10) REP(j,10){
      int tmp; scanf("%d",&tmp);
      if(tmp == 1) data[i] |= (1 << j);
    }

    REP(k,(1<<10)){
      int d[10]; REP(i,10) d[i] = data[i];
      d[0] ^= k; d[0] ^= (k<<1); d[0] ^= (k>>1);
      d[1] ^= k;

      int ans[10] = { k };
      for(int i=0; i<9; i++){
        int tmp = 0;
        REP(j,10){
          if(d[i] & (1<<j)){
            tmp |= (1<<j);
          }
        }
        d[i] ^= tmp;
        d[i+1] ^= tmp; d[i+1] ^= (tmp<<1); d[i+1] ^= (tmp>>1);
        if(i!=8) d[i+2] ^= tmp;
        ans[i+1] = tmp;
      }
      if((d[9] & mask) == 0){
        REP(i,10) REP(j,10)
          printf("%d%c",((ans[i]&(1<<j))==0?0:1),(j==9?'\n':' '));
        break;
      }
    }
  }

  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef pair<int, int> P;

const long double EPS = 1e-10;
const long long INF = 1e18;
const int MOD = (int)1e9 + 7;
const long double PI = acos(-1.0L);

int main() {
  int a, b, h, m;
  cin >> a >> b >> h >> m;

  double th = 2 * PI * ((60 * h) + m) / 720;
  double tm = 2 * PI * m / 60;

  double xh = a * cosl(th);
  double yh = a * sin(th);
  double xm = b * cosl(tm);
  double ym = b * sin(tm);
  double dx = xh - xm;
  double dy = yh - ym;
  double ans = sqrt(dx * dx + dy * dy);
  cout << fixed << setprecision(15) << ans << endl;

  return 0;
}

Measured memory_bytes: 4164
#include <bits/stdc++.h>
#ifdef BUG
    #include "debug.hpp"
#else
    #define DEBUG(var)
#endif

using namespace std;
template< class T1, class T2 > inline istream &
operator>>( istream & fin, pair< T1, T2 > & pr )
{ fin >> pr.first >> pr.second; return fin; }
template< class T0, class T1, class T2 > inline istream &
operator>>( istream & fin, tuple< T0, T1, T2 > & t )
{ fin >> get<0>(t) >> get<1>(t) >> get<2>(t); return fin; }
template< class T > inline istream &
operator>>( istream & fin, vector< T > & a ) {
for(auto & u: a) fin >> u; return fin; }
template<class T, size_t n> inline istream &
operator>>( istream & fin, array<T, n> & a ) {
for(auto & u: a) fin >> u; return fin; }
template<class FwdIter> inline auto
dump(FwdIter first, FwdIter last, const char * dlm = " ") -> void {
typedef typename iterator_traits<FwdIter>::value_type value_type;
copy(first, last, ostream_iterator<value_type>(cout, dlm)); }
template<typename T> vector<T> & operator--(vector<T> & a)
{ for(auto & i: a) --i; return a; }
/* @@@ ----------------------------------- */

int64_t b005()
{
    size_t n;
    cin >> n;

    vector<int> a(n);
    cin >> a;

    a.push_back(0);
    vector<size_t> d;
    int64_t out = 0;

    for(size_t k = 0; k < a.size(); ++k)
    {
        while(!d.empty() && a[k] < a[d.back()])
        {
            const auto i = d.size() == 1 ? (size_t) -1 : d[d.size() - 2];
            const auto j = d.back();
            out += ((int64_t)(j - i)) * ((int64_t)(k - j)) * a[j];
            d.pop_back();
        }

        d.push_back(k);
    }

    return out;
}


int main(const int argc, char * argv [])
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cout << b005();

    return EXIT_SUCCESS;
}


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

int main() {
  int N;
  cin >> N;
  char s;
  for(int i=0;i<N;i++){
    cin >> s;
    if (s=='Y'){
      cout << "Four" << endl;
      break;
    }
    else if (i==N-1){
      cout << "Three" << endl;
    }
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vp = vector<P>;
using vvp = vector<vp>;
using vint = vector<int>;
using vvint = vector<vint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vchar = vector<char>;
using vvchar = vector<vchar>;

#define rep(i, n) for (int i = 0; i < n; ++i)
#pragma region Debug
istream &operator>>(istream &is, P &a)
{
    return is >> a.first >> a.second;
}
ostream &operator<<(ostream &os, const P &a) { return os << "(" << a.first << "," << a.second << ")"; }

template <typename T>
void view(const std::vector<T> &v)
{
    for (const auto &e : v)
    {
        std::cout << e << " ";
    }
    std::cout << std::endl;
}
template <typename T>
void view(const std::vector<std::vector<T>> &vv)
{
    for (const auto &v : vv)
    {
        view(v);
    }
}
#pragma endregion
#pragma region chminmax
template <typename T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}
template <typename T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
#pragma endregion

int main()
{
    int v, e, r;
    cin >> v >> e >> r;
    vvp g(v, vp());
    rep(i, e)
    {
        int f, t, c;
        cin >> f >> t >> c;
        g[f].emplace_back(P(c, t));
    }

    priority_queue<int, vector<int>, greater<int>> q;
    q.push(r);

    ll INF = 1LL << 60;
    vll d(v, INF);
    d[r] = 0;

    while (q.size())
    {
        int nv = q.top();
        q.pop();
        for (P t : g[nv])
        {
            bool update = chmin(d[t.second], d[nv] + t.first);
            if (update)
                q.push(t.second);
        }
    }

    rep(i, v)
    {
        if (d[i] == INF)
        {
            cout << "INF" << endl;
            continue;
        }
        cout << d[i] << endl;
    }

    return 0;
}


Measured memory_bytes: 16516
#include<iostream>
#include<string.h>
#include<string>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<math.h>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
typedef long double db;
const int N=10000;
const db pi=acos(-1.0);
#define lowbit(x) (x)&(-x)
#define sqr(x) (x)*(x)
#define rep(i,a,b) for (register int i=a;i<=b;i++)
#define per(i,a,b) for (register int i=a;i>=b;i--)
#define fir first
#define sec second
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define maxd 998244353
#define eps 1e-8
int n,a[100100];

int read()
{
    int x=0,f=1;char ch=getchar();
    while ((ch<'0') || (ch>'9')) {if (ch=='-') f=-1;ch=getchar();}
    while ((ch>='0') && (ch<='9')) {x=x*10+(ch-'0');ch=getchar();}
    return x*f;
}

int main()
{
    n=read();
    rep(i,1,n) a[i]=read();
    sort(a+1,a+1+n);
    int l=a[n/2],r=a[n/2+1];
    printf("%d",r-l);
    return 0;
}

Measured memory_bytes: 640
/*
  mail: mleautomaton@foxmail.com
  author: MLEAutoMaton
  This Code is made by MLEAutoMaton
*/
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define ll long long
#define REP(a,b,c) for(int a=b;a<=c;a++)
#define re register
#define file(a) freopen(a".in","r",stdin);freopen(a".out","w",stdout)
inline int gi(){
	int f=1,sum=0;char ch=getchar();
	while(ch>'9' || ch<'0'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0' && ch<='9'){sum=(sum<<3)+(sum<<1)+ch-'0';ch=getchar();}
	return f*sum;
}
const int N=1000010;
char s[N];
int n,nxt[N],pre[N];
void init(){
	int j=0;nxt[1]=0;
	for(int i=2;i<=n;i++){
		while(j && s[j+1]!=s[i])j=nxt[j];
		if(s[j+1]==s[i])j++;
		nxt[i]=j;
	}
	j=n+1;pre[n]=n+1;
	for(int i=n-1;i;i--){
		while(j<=n && s[j-1]!=s[i])j=pre[j];
		if(s[i]==s[j-1])j--;
		pre[i]=j;
	}
}
bool check(int id){
	int flag1=(!nxt[id] || id%(id-nxt[id]));
	int flag2=(pre[id+1]==n+1 || (n-id)%(n-id-(n-pre[id+1]+1)));
	return (flag1&flag2);
}
int main(){
	scanf("%s",s+1);n=strlen(s+1);
	init();
	if(!nxt[n] || n%(n-nxt[n]))return printf("1\n1\n"),0;
	if(nxt[n]==n-1)return printf("%d\n1\n",n),0;
	int sum=0;
	for(int i=1;i<n;i++)if(check(i))sum++;
	printf("2\n%d\n",sum);
	return 0;
}

Measured memory_bytes: 8448
#include <bits/stdc++.h>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
using namespace std;

int main() {
    string s;
    cin >> s;
    if (s[s.length() - 1] == 's') {
        string ans = s + "es";
        cout << ans << endl;
    }else{
        string ans = s + "s";
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 3632
x, k, d = gets.split.map &:to_i

if k*d <= x.abs
  p x.abs - k*d
else
  n = x / d
  if n < 0 and x != d
    n += 1
  end
  y = x - n * d
  if (k - n.abs).odd?
    if x >= 0
      y -= d
    else
      y += d
    end
  end
  p y.abs
end


Measured memory_bytes: 14280
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>

static const int INF = 1000000007;
using ll = long long;
using u32 = unsigned;
using namespace std;
ll pow_ (ll x, ll n, ll M){
    ll u = 1;
    if(n > 0){
        u = pow_(x, n/2, M);
        if (n % 2 == 0) u = (u*u) % M;
        else u = (((u * u)% M) * x) % M;
    }
    return u;
};

int main() {
    int n, m;
    cin >> n >> m;
    ll ans = ((1900*m)+(100*(n-m)))* pow_(2, m, INF);
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 256
import math
import itertools

N = int(input())

P = [int(i) for i in input().split()]
Q = [int(i) for i in input().split()]

tP = tuple(P)
tQ = tuple(Q)
ord_P = 0 
ord_Q = 0 
cnt = 1
Num = []


for i in itertools.permutations(range(1,N+1)): 
    if i == tP:
        ord_P = cnt
    if i == tQ:
        ord_Q = cnt
    cnt += 1
    
print(abs(ord_P - ord_Q))


Measured memory_bytes: 3064
def f(n):
    if n % 2 == 0:
        return n//2
    return 3*n + 1

s = int(input())

nums = [s]
n = 1
while s not in nums[0:n-1:]:
    s = f(s)
    nums.append(s)
    n += 1

print(n)

Measured memory_bytes: 2940
#include <iostream>
#include <queue>

using namespace std;

constexpr int MAX = 30;
constexpr int INF = 1000000;

struct State {
    State(int x, int y, int d) 
        : x(x), y(y), depth(d) {}

    int x;
    int y;
    int depth;
};

int w, h;
int wall[MAX*MAX][MAX*MAX];
int visited[MAX][MAX];

int bfs() {
    int dx[4] = {1, 0, -1, 0};
    int dy[4] = {0, 1, 0, -1};

    queue<State> que;
    que.push(State(0,0,1));
    visited[0][0] = 1;

    while (!que.empty()) {
        State s = que.front();
        que.pop();

        if (s.x == w - 1 && s.y == h - 1) return s.depth;

        for (int i = 0; i < 4; i++) {
            int nx = s.x + dx[i];
            int ny = s.y + dy[i];
            int from = s.x + s.y * w;
            int to = nx + ny * w;
            if (0 <= nx && nx < w && 0 <= ny && ny < h && visited[ny][nx] < 0 && !wall[from][to]) {
                que.push(State(nx, ny, s.depth+1));
                visited[ny][nx] = s.depth + 1;
            }
        }
    }

    return 0;
}

int main(int argc, char const *argv[]) {
    
    while (cin>>w>>h, w||h) {
        for (int i = 0; i < MAX; i++) {
            for (int j = 0; j < MAX; j++) {
                visited[i][j] = -1;

            }
        }

        for (int i = 0; i < 2 * h - 1; i++) {
            if (i % 2 == 0) {
                for (int j = 0; j < w - 1; j++) {
                    int from = i / 2 * w + j;
                    int to = from + 1;
                    int exist_wall = 0;
                    cin>>exist_wall;
                    wall[from][to] = exist_wall;
                    wall[to][from] = exist_wall;
                }
            }else {
                for (int k = 0; k < w; k++) {
                    int from = (i - 1) / 2 * w + k;
                    int to  = from + w;
                    int exist_wall = 0;
                    cin>>exist_wall;
                    wall[from][to] = exist_wall;
                    wall[to][from] = exist_wall;
                }

            }
        }

        cout<<bfs()<<endl;
    }
    return 0;
}

Measured memory_bytes: 6152
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
fn main() {
    use std::cmp::max;
    use std::cmp::min;
    use std::collections::HashMap;

    input!{
        n: usize,
        a: [i32; n],
    }

    let mut mp = HashMap::new();
    for i in 0..n {
        let count = mp.entry(a[i]).or_insert(0);
        *count += 1;
    }
    let mut ans = 0;
    for (k, v) in mp {
        ans += if k > v {
            v
        } else {
            v-k
        };
    }
    println!("{}", ans);
}


Measured memory_bytes: 10492
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try(Scanner sc = new Scanner(System.in)){
                int a=sc.nextInt();
                int b=sc.nextInt();
                if(a<=8 && b<=8) {
                	System.out.println("Yay!");
                }
                else {
                	System.out.println(":(");
                }
        }
    }
}

Measured memory_bytes: 21716
#include <stdio.h>
#include <iostream>

using namespace std;

int main(){

    int k;

    cin >> k;

    int a, b;
    cin >> a >> b;

    string res = "NG";

    if(a % k == 0 || b % k == 0){
        res = "OK";
        cout << res << endl;
        return 0;
    }
  
  	while(a < b){
      if(a % k == 0){
        res = "OK";
        break;
      }
      a++;
    }

  	cout << res << endl;
    return 0;
}

Measured memory_bytes: 3612
import java.io.*;
import java.util.*;

public class Main {

	final static long MOD = 1000000007;
	public static String[] Ws = null;
	public static int wsIndx = 0;
	public static BufferedReader in = null;
	public static void main(String[] args) throws Exception {
		solution(args);
		if(in!=null){
			in.close();
		}
	}

	public static void solution(String[] args) throws Exception{

		String s = nextString();


		System.out.println(700+s.replaceAll("x", "").length()*100);

	}
	public static String[] toStringArray(String s) {
		String[] tmp = new String[s.length()];
		char[] c = s.toCharArray();
		for (int i = 0; i < tmp.length; i++) {
			tmp[i] = String.valueOf(c[i]);
		}
		return tmp;
	}

	public static void check() throws Exception{
		if(in == null){
			in = new BufferedReader(new InputStreamReader(System.in));
		}
		if(Ws==null || Ws.length<=wsIndx){
			Ws = in.readLine().split(" ");
			wsIndx=0;
		}
	}
	public static int nextInt()throws Exception{
		check();
		return Integer.parseInt(Ws[wsIndx++]);
	}

	public static long nextLong()throws Exception{
		check();
		return Long.parseLong(Ws[wsIndx++]);
	}

	public static String nextString()throws Exception{
		check();
		return Ws[wsIndx++];
	}

	public static int[] nextInts()throws Exception{
		check();
		int[] tmp = new int[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Integer.parseInt(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static long[] nextLongs()throws Exception{
		check();
		long[] tmp = new long[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Long.parseLong(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static String[] nextStrings()throws Exception{
		check();
		wsIndx=Ws.length;
		return Ws;
	}


}


Measured memory_bytes: 21332
N = input()
max_digit = N[0]

min_tmp = ''
max_tmp = ''
for i in range(len(N)):
    min_tmp += max_digit
    max_tmp += str(int(max_digit) + 1)
    
if  int(min_tmp) >= int(N):
    print(min_tmp)
else:
    print(max_tmp)

Measured memory_bytes: 8928
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, A):
    ans = 0
    for a in A:
        while a % 2 == 0:
            a //= 2
            ans += 1

    return ans


def main():
    N = read_int()
    A = read_int_n()
    print(slv(N, A))


if __name__ == '__main__':
    main()


Measured memory_bytes: 8388