akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

    private static Scanner sc;

    public static void main(String[] args) {
        Main instance = new Main();
        sc = instance.new Scanner();
        instance.solve();
    }

    private void solve() {
    	int[] time = new int[5];
    	int[] sabun = new int[5];
    	int[] jun = new int[5];
    	int result=0;
        try {
        	for (int i = 0; i<5;i++ ) {
        		time[i] = sc.nextInt();
        		sabun[i] = 10-time[i]%10==10? 0:10-time[i]%10;
        	}
        	int idx=0;
        	for(int check=0;check<10;check++) {
        		//System.out.println("check:"+check);
        		for (int i=0;i<5;i++) {
        			if (sabun[i]==check) {
        				//System.out.println("sabun["+i+"] : "+sabun[i]);
        				jun[idx]=i;
        				idx++;
        			}
        		}
        	}

        	int cnt=0;
        	for (int i : jun) {
        		//System.out.println("result : "+ result);
        		if (cnt != 4) result += time[i]+sabun[i];
        		else result += time[i];
        		cnt++;
        	}
        	/*
        	for(int i=0;i<5;i++) {
        		System.out.println(time[i]+" ,"+sabun[i]+" ,"+jun[i]);
        	}*/
        	System.out.println(result);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private class Scanner {
        String[] s;
        int i;
        BufferedReader br;
        String regex = " ";

        public Scanner() {
            s = new String[0];
            i = 0;
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        @Override
        protected void finalize() throws Throwable {
            try {
                super.finalize();
            } finally {
                destruction();
            }
        }

        private void destruction() throws IOException {
            if (br != null) br.close();
        }

        public String next() throws IOException {
            if (i < s.length) return s[i++];
            String st = br.readLine();
            while (st == "") st = br.readLine();
            s = st.split(regex, 0);
            i = 0;
            return s[i++];
        }

        public int nextInt() throws NumberFormatException, IOException {
            return Integer.parseInt(next());
        }

        public Long nextLong() throws NumberFormatException, IOException {
            return Long.parseLong(next());
        }

        public Double nextDouble() throws NumberFormatException, IOException {
            return Double.parseDouble(next());
        }
    }
}

Measured memory_bytes: 24660
n = int(input())
a = list(map(int,input().split()))
ans = a[0]
for i in range(n-1):
    ans *= a[i+1]
    if ans > 10**18:
        break
if 0 in a:
    print(0)
elif ans > 10**18:
    print(-1)
else:
    print(ans)


Measured memory_bytes: 21792
import std.stdio, std.conv, std.string;
import std.algorithm, std.array, std.container, std.typecons;
import std.numeric, std.math;
import core.bitop;

T RD(T = string)() { static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T)(in string str) { return str.split.to!(T[]); }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

long mod = pow(10, 9) + 7;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }

struct UnionFind
{
	void init(long n) { par = new long[](n); foreach (i; 0..n) par[i] = i; }
	long root(long i) { return par[i] == i ? i : (par[i] = root(par[i])); }
	bool same(long i, long j) { return root(i) == root(j); }
	void unite(long i, long j) { i = root(i); j = root(j); if (i == j) return; par[i] = j; }
	long[] par;
}

void main()
{
	auto H = RD!long;
	auto W = RD!long;
	auto D = RD!long;
	auto A = new long[2][](H*W);
	foreach (i; 0..H)
	{
		foreach (j; 0..W)
		{
			auto num = RD!long;
			A[num] = [i, j];
		}
	}
	auto Q = RD!long;
	auto L = new long[](Q);
	auto R = new long[](Q);
	foreach (i; 0..Q)
	{
		L[i] = RD!long;
		R[i] = RD!long;
	}

	auto dp = new long[](H*W+1);
	foreach (i; 0..H*W)
	{
		auto dist1 = abs(A[i+D][0] - A[i][0]);
		auto dist2 = abs(A[i+D][1] - A[i][1]);
		dp[i+D] = dp[i] + dist1 + dist2;
	}

	foreach (i; 0..Q)
	{
		writeln(dp[R[i]] - dp[L[i]]);
	}

	stdout.flush();
}

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

int main(){
  int a,rec=0;
  string s;
  cin>>a>>s;
  int count=0;
  for(int i=0;i<a;i++){
    if(s.at(i)=='I') count++;
    else count--;
    rec=max(rec,count);
  }
  cout<<rec<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <queue>
#include <set>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <complex>

using ll = long long int;
using namespace std;

int main(){
  ll X, Y, A, B, C, tmp;
  vector<ll> p, q, r;

  cin >> X >> Y >> A >> B >> C;
  for(ll i = 0; i < A; i++){
    cin >> tmp;
    p.push_back(tmp);
  }
  for(ll i = 0; i < B; i++){
    cin >> tmp;
    q.push_back(tmp);
  }
  for(ll i = 0; i < C; i++){
    cin >> tmp;
    r.push_back(tmp);
  }
  sort(p.begin(), p.end(), greater<ll>());
  sort(q.begin(), q.end(), greater<ll>());
  sort(r.begin(), r.end(), greater<ll>());

  vector<ll> pq;
  for(ll i = 0; i < X; i++){
    pq.push_back(p[i]);
  }
  for(ll j = 0; j < Y; j++){
    pq.push_back(q[j]);
  }
  sort(pq.begin(), pq.end());

  for(int i = 0; i < X+Y; i++){
    if(i >= C || pq[i] >= r[i]){
      break;
    }
    pq[i] = r[i];
  }
  
  ll ans = 0;
  for(ll i = 0; i < X+Y; i++){
    ans += pq[i];
  }

  cerr << "Answer:" << endl;
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 4724
#pragma GCC optimize "-O3"
#pragma GCC target ("avx")
#define _USE_MATH_DEFINES
#include<bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define inf (1ll<<60)
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v),greater<int>())
#define SPEED ios::sync_with_stdio(false);cin.tie(0);cout<<fixed<<setprecision(12)
signed gcd(int a, int b){return b?gcd(b,a%b):a;}
signed lcm(int a, int b){return a*b/gcd(a,b);}
//priority_queue<int, vi, greater<int> > que;//昇順

using namespace std;

const int mod=1e9+7;

signed main(){
    SPEED;
    int n;
    cin >> n;
    cout << 48-n << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 int N,M;
 cin >> N >> M;
  
  vector<vector<int>> data(N, vector<int>(M+1));
  for(int i = 0;i<N;i++){
    for(int j = 0;j<M+1;j++){
      cin >> data.at(i).at(j);
      if(j == data.at(i).at(0)) break;
    }
  }

  
  int ans = 0;
 for(int l =1;l<=M;l++){ 
   int count = 0;
  for(int i = 0;i<N;i++){
    for(int j = 1;j<M+1;j++){
      if(data.at(i).at(j) == l) count ++;
    }
  }
   if(count == N) ans ++;
 }
  cout << ans << endl;
  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n); i >= 0; i--)
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define ALL(obj) begin(obj), end(obj)
using namespace std;
using ll = long long;
using ull = unsigned long long;

const int INF = 200000000;
const int MOD = 1e9 + 7;

// 多次元 vector 生成
template <class T> vector<T> make_vec(size_t a) { return vector<T>(a); }
template <class T, class... Ts> auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
const int MAX_DIGIT = 60;
long long dp[100][2];

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

    ll N, K;
    cin >> N >> K;
    auto A = make_vec<ll>(N);
    REP(i, N) { cin >> A.at(i); }
    memset(dp, -1, sizeof(dp));
    dp[0][0] = 0;
    for (int k = 0; k < MAX_DIGIT; k++) {
        ll mask = 1LL << (MAX_DIGIT - k - 1);
        ll oc = 0;
        REP(i, N) {
            if (A[i] & mask) {
                oc++;
            }
        }
        ll zc = N - oc;

        // 1 is smaller, 0 is exact
        if (dp[k][1] != -1) {
            dp[k + 1][1] = max(dp[k + 1][1], dp[k][1] + (max(oc, zc) * mask));
        }

        if (dp[k][0] != -1) {
            if (K & mask) {
                dp[k + 1][1] = max(dp[k + 1][1], dp[k][0] + oc * mask);
                dp[k + 1][0] = max(dp[k + 1][0], dp[k][0] + zc * mask);
            } else {
                dp[k + 1][0] = max(dp[k + 1][0], dp[k][0] + oc * mask);
            }
        }
    }

    cout << max(dp[MAX_DIGIT][0], dp[MAX_DIGIT][1]) << endl;

    return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>

int main(void)
{
   char s[4];

   scanf("%s",s);

   if((s[0]!=s[1]) && (s[1]!=s[2]) && (s[0]!=s[2]))
      printf("Yes\n");
   else
      printf("No\n");

   return 0;
}



Measured memory_bytes: 128
#include <cassert>
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <map>
using namespace std;


typedef long long ll;
pair<int, int> calc(ll b, pair<int, int>& d) {
  pair<int, int> ret{-d.first, -d.second};
  int d2 = 0, d5 = 0;
  while(b % 2 == 0) { ++d2; b /= 2;}
  while(b % 5 == 0) { ++d5; b /= 5;}
  ret.first += d2;
  ret.second += d5;
  return ret;

}

int main() {
  int n; cin >> n;
  map<pair<int, int>, int> cnt;
  ll ans = 0;
  for (int i = 0; i < n; ++i) {
    string a; cin >> a;
    int m = 0;
    string c = "";
    for (int j = 0; j < a.size(); ++j) {
      if (a[j] == '.') {
        m = a.size()-j-1;
        continue;
      }
      c += a[j];
    }
    ll b = stol(c);
    pair<int, int> d25 = {m, m};
    auto ret = calc(b, d25);
    for (auto e: cnt) {
      if (e.first.first + ret.first >= 0 && e.first.second + ret.second >= 0) {
        ans += e.second;

      }

    }
    // cout << a << " " << b << " " << m << " " << ret.first << " " << ret.second << endl;
    cnt[ret] += 1;

  }
  cout << ans << endl;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define ft first
#define sc second
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) {if(a<b) a=b;}
#define chmin(a, b) {if(a>b) a=b;}
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
static const ll INF=1e18;
static const ll MAX=1e5+7;
static const ll MOD=1e9+7;
ll max(ll a, ll b) {return a>b?a:b;}
ll min(ll a, ll b) {return a<b?a:b;}




int main(void) {
  ll N, M;
  cin >> N >> M;
  ll a[MAX];
  ll dp[MAX]={};
  ll i;
  
  for(i=0; i<M; i++) {
    cin >> a[i];
    dp[a[i]]=-1;
  }
  
  dp[0]=1;
  for(i=0; i<N; i++) {
    if(dp[i]==-1) continue;
    
    if(dp[i+1]!=-1) {
      moC(dp[i+1], +, dp[i]);
    }
    if(dp[i+2]!=-1) {
      moC(dp[i+2], +, dp[i]);
    }
  
  }
  
  pt(dp[N]);
  
}
  
  


Measured memory_bytes: 1792
#include <stdio.h>

int judge(int a, int b, int c){
  if(a+b > c && b+c > a && c+a > b){
    if(a*a+b*b==c*c || b*b+c*c==a*a || c*c+a*a==b*b)
      return 1;
    else
      return 0;
  } else {
    return 0;
  }
}

int main(){
  int a,b,c;
  int num,i;
  scanf("%d", &num);

  for(i=0;i<num;i++){
    scanf("%d %d %d", &a, &b, &c);
    if(judge(a,b,c))
      printf("YES\n");
    else
      printf("NO\n");
  }

  return 0;
}

Measured memory_bytes: 580
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <deque>
 
using namespace std;
 
#define rep(i,n) for(int i=0; i<(n); i++)
#define repc(i,s,e) for(int i=(s); i<(e); i++)
#define pb(n) push_back((n))
#define mp(n,m) make_pair((n),(m))
#define all(r) r.begin(),r.end()
#define fi first
#define se second
 
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;


const int INF=1e9;


const int MAX_V = 1e6+10;

struct edge{
	int to, cost;
	edge(){}
	edge(int to, int cost):to(to),cost(cost){}
};
int V;
vector<edge> G[MAX_V];
int d[MAX_V];

void dijkstra(int s){
	priority_queue<pii, vector<pii>, greater<pii> > q;
	fill(d, d+V, INF);
	d[s] = 0;
	q.push(pii(0, s));

	while(!q.empty()){
		pii p = q.top();
		q.pop();

		int v = p.se;
		if(d[v] < p.first) continue;
		for(int i = 0; i < G[v].size(); i++){
			edge e = G[v][i];
			if(d[e.to] > d[v]+e.cost){
				d[e.to] = d[v]+e.cost;
				q.push(pii(d[e.to],e.to));
			}
		} 
	}
}

int main(){
	int E, r;
	cin>>V>>E>>r;
	int s, t, c;
	for(int i = 0; i < E; i++){
		cin>>s>>t>>c;
		G[s].pb(edge(t,c));
	}
	dijkstra(r);
	for(int i = 0; i < V; i++){
		if(d[i]==INF){
			cout<<"INF"<<endl;
		}
		else{
			cout<<d[i]<<endl;
		}
	}
}

Measured memory_bytes: 34240
from collections import*
n,*a=map(int,open(0).read().split())
dp=[defaultdict(lambda:-10**18)for _ in range(n)]
for i in range(n):dp[i][0]=0
for i,a in enumerate(a):
    for j in range(n//2-(n-i)//2,i//2+2):
        dp[i][j]=max(dp[i-2][j],dp[i-2][j-1]+a,dp[i-1][j])
print(dp[-1][n//2])

Measured memory_bytes: 188504
#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>

auto& in = std::cin;
auto& out = std::cout;

int32_t N, def_max, def_min;
int32_t V[2000];

int32_t func_max(int32_t i);
int32_t dp_min[2000];
int32_t func_min(int32_t i)
{
	if (dp_min[i] != -1) { return dp_min[i]; }
	int32_t res = std::abs(V[N - 1] - (i == 0 ? def_max : V[i - 1]));
	for (int32_t k = i+1; k < N; k++)
	{
		res = std::min(res, func_max(k));
	}
	return dp_min[i] = res;
}
int32_t dp_max[2000];
int32_t func_max(int32_t i)
{
	if (dp_max[i] != -1) { return dp_max[i]; }
	int32_t res = std::abs(V[N-1] - (i == 0 ? def_min : V[i - 1]));
	for (int32_t k = i + 1; k < N; k++)
	{
		res = std::max(res, func_min(k));
	}
	return dp_max[i] = res;
}

template<typename T, typename U>
std::enable_if_t<std::rank<T>::value == 0> fill_all(T& arr, const U& v) {
	arr = v;
}
template<typename ARR, typename U>
std::enable_if_t<std::rank<ARR>::value != 0> fill_all(ARR& arr, const U& v) {
	for (auto& i : arr) {
		fill_all(i, v);
	}
}

int main()
{
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);
	in.tie(nullptr);
	out.tie(nullptr);

	in >> N >> def_max >> def_min;
	for (int32_t i = 0; i < N; i++)
	{
		in >> V[i];
	}

	fill_all(dp_max, -1);
	fill_all(dp_min, -1);

	out << func_max(0) << endl;

	return 0;
}
#endif


Measured memory_bytes: 384
import java.util.Scanner;

public class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        if(n % 2 == 0) {
            System.out.println(n / 2);
        } else {
            System.out.println(n /2 + 1);
        }
        sc.close();
    }
}


Measured memory_bytes: 22612
#include<iostream>
#include<cstdio>
#define mod 1000000007
using namespace std;
long long ans,x,y,n,q,a[3001],t[3001][3001],T[3001][3001],sum[3001][3001],Sum[3001][3001];
int read()
{
  char c=0;
  int sum=0;
  while (c<'0'||c>'9')
    c=getchar();
  while ('0'<=c&&c<='9')
    {
      sum=sum*10+c-'0';
      c=getchar();
    }
  return sum;
}
long long fast_pow(long long a,int b)
{
  if (b==0)
    return 1;
  if (b&1)
    return fast_pow(a*a%mod,b/2)*a%mod;
  else
    return fast_pow(a*a%mod,b/2);
}
int main()
{
  n=read(),q=read();
  for (int i=1;i<=n;++i)
    a[i]=read();
  for (int i=1;i<=n;++i)
    for (int j=i+1;j<=n;++j)
      {
	if (a[i]>a[j])
	  t[i][j]=1;
	if (a[i]<a[j])
	  T[i][j]=1;
      }
  int a,b,c,d;
  for (int i=1;i<=q;++i)
    {
      x=read(),y=read();
      if (x>y)
	swap(x,y);
      for (int j=x+1;j<=y-1;++j)
	{
	   a=t[x][j],b=T[x][j],c=t[j][y],d=T[j][y];
	   t[x][j]=T[j][y]=(a+d)%mod*fast_pow(2,mod-2)%mod;
	   T[x][j]=t[j][y]=(b+c)%mod*fast_pow(2,mod-2)%mod;
	 }
      for (int j=1;j<=x-1;++j)
	 {
	   a=t[j][x],b=T[j][x],c=t[j][y],d=T[j][y];
	   t[j][x]=t[j][y]=(a+c)%mod*fast_pow(2,mod-2)%mod;
	   T[j][x]=T[j][y]=(b+d)%mod*fast_pow(2,mod-2)%mod;
	 }
      for (int j=y+1;j<=n;++j)
	{
	  a=t[x][j],b=T[x][j],c=t[y][j],d=T[y][j];
	  t[x][j]=t[y][j]=(a+c)%mod*fast_pow(2,mod-2)%mod;
	  T[x][j]=T[y][j]=(b+d)%mod*fast_pow(2,mod-2)%mod;
	}
      a=t[x][y],b=T[x][y];
      t[x][y]=T[x][y]=(a+b)%mod*fast_pow(2,mod-2)%mod;
    }
  for (int i=1;i<=n;++i)
    for (int j=i+1;j<=n;++j)
      ans=(ans+t[i][j]*fast_pow(2,q)%mod)%mod;
  printf("%lld\n",ans);
  return 0;
}

Measured memory_bytes: 141696
#include<cstdio>
#include<iostream>
#include<map>
#include<set>
#include<vector>
#include<cstring>
#include<cassert>
#include<sstream>
#include<cmath>
#include<algorithm>
#include<queue>
#include<limits>
#include<ctime>
#include<stack>
#include<bits/stdc++.h>
#include<string>
#include<stdlib.h>
#include<stdio.h>
typedef long long ll;

using namespace std;

int main(){
	int n,ans=0,maks=0;
	string s;
	cin>>n>>s;
	for(int i=0;i<n;i++){
		if(s[i]=='I'){
			ans++;
		}
		if(s[i]=='D'){
			ans--;
		}
		maks=max(ans,maks);
	}
	cout<<maks;
}

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

int main() {
    string s;
    cin >> s;
    if(s[0] == s[1]){
        cout << 1 << ' ' << 2 << endl;
        return 0;
    }
    for(int i=2; i<s.size(); i++){
        if(s[i] == s[i-1]){
            cout << i  << ' ' << i+1 << endl;
            return 0;
        }
        if(s[i] == s[i-2]){
            cout << i-1 << ' ' << i+1 << endl;
            return 0;
        }
    }

    cout << -1 << ' ' << -1 << endl;
 
    return 0;
}

Measured memory_bytes: 512
//
#include<iostream>

using namespace std;

#define PB push_back
#define f first
#define s second

int ord[1000005];

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n, m;
    cin >> n >> m;
    int f, s;
    if(n%4 == 1)
    {
        f = (n-1)/2;
        s = (n+1)/2;
    }
    else if(n%4 == 3)
    {
        f = (n+1)/2;
        s = (n-1)/2;
    }
    else
    {
        f = n/2-1;
        s = n/2;
    }
    for(int i=0; i<n; i++)
    {
        ord[i] = -1;
    }
    for(int i=0; i<f; i++)
    {
        if(i >= f-1-i)
            break;
        ord[i] = f-1-i;
    }
    for(int i=f; i<f+s; i++)
    {
        if(i >= 2*f+s-i-1)
            break;
        ord[i] = 2*f + s - i - 1;

    }

//    for(int i=0; i<n; i++)
//    {
//        cout << i << " " << ord[i] << "\n";
//    }
    for(int i=0; i<n; i++)
    {
        if(i < f && i >= f-1-i)
            continue;
        if(i < n && i >= 2*f + s-i-1)
            continue;
        cout << i+1 << " " << ord[i] + 1;
        if(m > 1)
            cout << "\n";
        m--;
        if(m == 0)
            break;
    }

    return 0;
}


Measured memory_bytes: 4288
#include<map>
using i=int64_t;i k,t=1,n,p;i S(i x){return x?x%10+S(x/10):0;}main(){scanf("%d",&k);while(printf("%ld\n",n+=t),--k)t+=t*9*(S(p=n+t+t)*(n+t)>S(n+t)*p);}

Measured memory_bytes: 128
#include <stdio.h>
#include <iostream>
using namespace std;

int main() {
    int a, b;
    cin >> a >> b;
    int d = b - a;
    int e = 0;
    for (int i = 1; i <= d; i++){
        e += i;
    }
    cout << e - b;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdint>
#include<cstdlib>
template<typename T>
void fin(T const& t){ std::cout << t << std::endl; exit(0); }

int const MAXN = 1e5;
int A[MAXN+1];

int main() {
  int N; std::cin >> N;
  for(int i = 0; i <= N; ++i) std::cin >> A[i];
  int64_t ans = 0;
  for(int i = 0; i < N; ++i) {
    int B; std::cin >> B;
    int k = std::min(A[i], B);
    ans += (int64_t)k;
    B -= k;
    k = std::min(A[i+1], B);
    ans += (int64_t)k;
    A[i+1] -= k;
  }
  fin(ans);
  return 0;
}


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

#define rep(i,n) for(int i=0;i<n;i++)
//#define long long ll;

int main(){

 long long n,k;
  cin>>n>>k;

 long long r = n%k;

 if(r)
    cout<<min(abs(r-k),r)<<endl;
 else
    cout<<0<<endl;


return 0;
}

Measured memory_bytes: 3564
//g++ -std=gnu++14 a.cpp
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
#include <random>
#include <math.h>

using namespace std;

#define ll long long
#define rep(i, n) for(ll i = 0; i < (n); i++)
ll MOD = 1e9 + 7;
int INF = 1 << 30;
ll INFL = 1LL << 60;

int main() {
  ll N,K,R,S,P;
  cin >> N >> K >> R >> S >> P;
  string T;
  cin >> T;
  vector<int> hantei(N,1);
  ll sum = 0;
  /*
  rep(i,N){
    if(T.at(i)=='r') sum += P;
    else if(T.at(i)=='s') sum += R;
    else sum += S;
  }
  */
  for(int i = 0;i < N-K;i++){
    if(hantei.at(i)==1 && T.at(i)==T.at(i+K)){

        hantei.at(i+K) = 0;

    }
  }
  /*
  rep(i,N){
    cout << hantei.at(i) << " ";
  }
  cout << endl;
  */
  rep(i,N){
    if(hantei.at(i)){
      if(T.at(i)=='r') sum += P;
      else if(T.at(i)=='s') sum += R;
      else sum += S;
    }
  }
  cout << sum << endl;
}


Measured memory_bytes: 896
#include <iostream>
#include <vector>
#include <tuple>
#include <deque>
#include <set>
#include <map>
#include <cmath>
#include <string>
#include <algorithm>
#include <unordered_map>
#define int long long
#define all(x) (x).begin(), (x).end()
#define allr(x) (x).rbegin(), (x).rend()

using namespace std;

void fast()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}

const int MOD = 1e9 + 7;
const int INF = 1e9;

signed main()
{
	int n;
	cin >> n;
	vector <int> a(n);
	for (int & e : a)
        cin >> e;
    int xr = 0;
    for (int e : a)
        xr ^= e;
    for (int e : a)
        cout << (e ^ xr) << " ";
    cout << '\n';
	return 0;
}


Measured memory_bytes: 4824
#include<iostream>
#include<set>
#include<vector>
#include<cmath>
#include<complex>
#include<string>
#include<algorithm>

using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define pb push_back

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vvi;


int main(void)
{
  int n,a;
	int sum = 0,max = 0;

  cin >> n;

  rep(i,n){
    cin >> a;
		max = std::max(a,max);
		sum += a;
  }

	if((sum-max) <= max){
		cout << "No" << endl;
	  return 0;
	}

  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1000000007;
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

ll n;
vector<ll> v;

void dfs(string s){
    ll x=stoll(s);
    if(x<=n){
        bool o7=false,o5=false,o3=false;
        rep(i,s.size()){
            if(s[i]=='7') o7=true;
            else if(s[i]=='5') o5=true;
            else if(s[i]=='3') o3=true;
        }
        if(o7 && o5 && o3) v.push_back(x);
        dfs(s+'7');
        dfs(s+'5');
        dfs(s+'3');
    }
}


int main(){
    cin>>n;
    dfs("7");
    dfs("5");
    dfs("3");

    cout<<v.size()<<endl;
} 


Measured memory_bytes: 3716
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
	int n;
	cin>>n;
 string s;
    cin>>s;
    ll start=0,end=n-1;
    ll cnt=0;
    while(start<=end){
        if(s[start]=='W' and s[end]=='R'){
            s[start]='R';
            s[end]='W';
            cnt++;
        }
        if(s[start]=='R'){
            start++;
        }
        if(s[end]=='W'){
            end--;
        }
    }
    cout<<cnt<<endl;
}

 
 

Measured memory_bytes: 3740
#include<iostream>
using namespace std;
int main()
{
	int a,b;
	cin>>a;
	cin>>b;
	
	if(a+b==3)
	cout<<"3"<<endl;
	if(a+b==4)
	cout<<"2"<<endl;
	if(a+b==5)
	cout<<"1"<<endl;
	
	return 0;
}

Measured memory_bytes: 256
import numpy as np
nums = np.array(list(map(int, input().split())))



count = 0
while(True):
    min_num = nums.min()
    nums_count = (nums == min_num).sum()
    if nums_count == 3:
        break
    indx = np.where(nums == min_num)[0]
    count += 1
    if nums_count == 2:
        nums[indx] += 1
    if nums_count == 1:
        nums[indx] += 2

print(count)

Measured memory_bytes: 21128
import sys
read = lambda: sys.stdin.readline().rstrip()

class Solution(object):
    def counting_tree(self, N, D):
        #import collections
        tot = 1

        #cnt = collections.Counter(D)

        cnt = [0]*N
        for i in D:
            cnt[i]+=1

        for i in D[1:]:
            tot = tot * cnt[i-1]%998244353

        return tot if D[0]==0 else 0

def main():
    
    N0 = int(read())
    D0 = tuple(map(int, read().split()))

    res = Solution().counting_tree(N0, D0)

    print(res)

if __name__ == "__main__":
    main()

Measured memory_bytes: 14260
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef  unsigned long long int ull;
typedef pair<ll,ll> P;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
//ios_base::sync_with_stdio(false);
//cin.tie(NULL);
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int main(){
map<string,int> mp;
string s,t;
cin>>s>>t;
int a,b;
cin>>a>>b;
mp[s]=a;mp[t]=b;
string h;
cin>>h;
mp[h]--;
cout<<mp[s]<<" "<<mp[t]<<endl;
}

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

int main(){
	long long a, temp=0, i, now, tot=0, max=0;
	cin>>a;
	for(i=0;i<a;i++){
		cin>>now;
		if(now>temp){
			if(tot>max){
				max=tot;
			}
			tot=0;
		}
		else{
			tot++;
			if(tot>max){
				max=tot;
			}
		}
		temp=now;
	}
	cout<<max<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
string s;
int main()
{
	cin>>s;
	if(s[0]!=s[2]||s[0]!=s[1]&&s[1]!=s[2])
	cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <queue>
#include <tuple>
#include <cstring>
#include <cctype>
#include <ctype.h>

#define INF 200000000
#define MOD 1000000007

using namespace std;

int main()
{
    long long int n;
    cin >> n;
    long long int ans = 1;
    for (long long int i = 1; i <= n; i++)
    {
        ans *= i;
        ans %= MOD;
    }
    cout << ans << endl;
    return 0;
}


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

#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define ll long long int

using namespace std;

int main()
{
  int n;
  int a[100000];
  cin >> n;
  REP(i, n)
  {
    cin >> a[i];
  }
  sort(a, a + n);

  int result = a[0];
  while (result != 1)
  {
    int tmp = result;
    REP(i, n)
    {
      if (a[i] % result != 0 && a[i] % result < tmp)
      {
        tmp = a[i] % result;
      }
    }
    if (tmp == result)
    {
      result = tmp;
      break;
    }
    result = tmp;
  }

  cout << result << endl;
}


Measured memory_bytes: 640
n, q = map(int, input().split())
s = input()
lis=[]
for i in range(q):
    lis.append(list(map(int, input().split())))
idx=0
acs=[0]*n
for _ in s:
    if s[idx]=="A" and s[idx+1]=="C":
        acs[idx+1] = 1
        idx+=1
    idx+=1
    if idx>=(len(s)-1):
        break
cnt=0
#print(acs)
for i,el in enumerate(acs):
    if el!=0:
        cnt+=el
        acs[i]=cnt
    else:
        acs[i]=cnt
#print(acs)
for i in lis:
    print(acs[i[1]-1]-acs[i[0]-1])


Measured memory_bytes: 30704
open Printf
open Scanf

let id x = x

let rec seq s t f =
  if s > t then []
  else
    let x = f s in
    x :: seq (s + 1) t f
             
module Pqueue = struct
  type 'a t = {mutable cnt : int; hp : 'a array; cmp : 'a -> 'a -> int}

  let create n v f = {cnt = 0; hp = Array.make n v; cmp = f}

  let push k pq =
    let swap i j =
      let t = pq.hp.(i) in
      pq.hp.(i) <- pq.hp.(j);
      pq.hp.(j) <- t in
    let rec iter i =
      let p = i / 2 in
      if p = 0 || pq.cmp pq.hp.(p) pq.hp.(i) >= 0 then ()
      else (swap p i; iter p)
    in
    pq.cnt <- pq.cnt + 1;
    pq.hp.(pq.cnt) <- k;
    iter (pq.cnt)

  let max_heapify pq n =
    let swap i j =
      let t = pq.hp.(i) in
      pq.hp.(i) <- pq.hp.(j);
      pq.hp.(j) <- t in
    let rec iter i =
      let l = 2 * i in
      let r = 2 * i + 1 in
      let mi =
        let ti = if l <= pq.cnt && pq.cmp pq.hp.(l) pq.hp.(i) > 0 then l else i in
        if r <= pq.cnt && pq.cmp pq.hp.(r) pq.hp.(ti) > 0 then r else ti in
      if mi <> i then
        begin
          swap mi i;
          iter mi
        end
    in
    iter n

  let pop pq =
    let ret = pq.hp.(1) in
    pq.hp.(1) <- pq.hp.(pq.cnt);
    pq.cnt <- pq.cnt - 1;
    max_heapify pq 1;
    ret

  let top pq = pq.hp.(1)

  let is_empty pq = pq.cnt = 0

  let length pq = pq.cnt
end

let () = 
  let rec loop () = 
    let c, n, m, s, d = scanf "%d %d %d %d %d " @@ fun c n m s d -> (c, n, m, s, d) in
    if c = 0 && n = 0 && m = 0 && s == 0 && d = 0 then ()
    else
      begin
        let adj = Array.make (n + 1) [] in
        for i = 1 to m do
          let a, b, f = scanf "%d %d %d " @@ fun a b f -> (a, b, f) in
          adj.(a) <- (b, f) :: adj.(a);
          adj.(b) <- (a, f) :: adj.(b)
        done;
        let cost = Array.make_matrix (n + 1) (c + 1) 2000000 in
        let pq = Pqueue.create (n * n * c * 4) (0, 0, 0) (fun (_, _, x0) (_, _, x1) -> compare x1 x0) in
        Pqueue.push (s, c, 0) pq;
        let rec iter () =
          if Pqueue.is_empty pq then ()
          else begin
              let (i, j, k) = Pqueue.pop pq in
              if cost.(i).(j) > k then begin
                  cost.(i).(j) <- k;
                  List.iter (fun (e, f) -> Pqueue.push (e, j, k + f) pq;
                                           if j > 0 then Pqueue.push (e, (j-1), k + f / 2) pq else ()
                            ) adj.(i);
                end else ();
              iter ()
            end
        in iter ();
           printf "%d\n" @@ List.fold_left (fun x i -> min x cost.(d).(i)) 2000000 (seq 0 c id) ;
        loop ()
      end
  in loop ()



Measured memory_bytes: 27052
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <stdlib.h>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <map>
#include <set>
using namespace std;
#define ms(x, n) memset(x,n,sizeof(x));
typedef  long long LL;
const int inf = 1<<30;
const LL maxn = 15;
const double eps = 1e-9;

int n, d, x[maxn][maxn];
bool judge(int i, int j){
    double tmp = 0;
    for(int l = 1; l <= d; ++l)
        tmp += (double)(x[i][l]-x[j][l])*(x[i][l]-x[j][l]);
    tmp = sqrt(tmp);
    //printf("%.6lf\n",tmp);
    if(tmp-(int)tmp <= eps) return true;
    else return false;
}
int main()
{
    cin >> n >> d;
    for(int i = 1; i <= n; ++i)
        for(int j = 1; j <= d; ++j)
            cin >> x[i][j];
    int cnt = 0;
    for(int i = 1; i <= n; ++i)
        for(int j = 1; j < i; ++j)
            if(judge(j, i))
                ++cnt;
    cout << cnt << endl;

	return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
 
int selectionSort(int A[], int N){
  int minj;
  int sw = 0;
  int i, j, v;
  for ( i = 0; i < N; i++) {
    minj = i;
    for ( j = i; j < N; j++) {
      if (A[j] < A[minj]) {
        minj = j;
      }
    }
    v = A[i]; A[i] = A[minj]; A[minj] = v;
    if( i != minj) sw++;
  }
  return sw;
}
 
int main(){
  int A[100], N, i, sw;
 
  scanf("%d", &N);
  for ( i = 0; i < N; i++) scanf("%d", &A[i]);
 
  sw = selectionSort(A, N);
 
  for ( i = 0; i < N; i++ ){
    if ( i > 0 ) printf(" ");
    printf("%d", A[i]);
  }
  printf("\n");
  printf("%d\n", sw);
 
  return 0;
}


Measured memory_bytes: 2736
s=gets

s=s.split

x=s[0].to_i
a=s[1].to_i
b=s[2].to_i
n_a =(x-a).abs
n_b =(x-b).abs
if n_a < n_b
  puts "A"
elsif n_a > n_b
  puts "B"
else
  puts ""
end
  

Measured memory_bytes: 1788
def main():
    N = int(input())
    A = list(map(int, input().split()))

    if 0 in A: 
        print(0)
        return

    prod = 1 
    for a in A:
        prod *= a
        if prod > 1000000000000000000:
            print(-1) 
            return

    print(prod)

main()

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

int main() {
  int N, K;
  cin >> N >> K;
  int sum = 0;
  
  vector<int> fruits(N);
  for (int i = 0; i < N; i++) {
    cin >> fruits.at(i);
  }
  sort(fruits.begin(), fruits.end());
  
  for (int i = 0; i < K; i++) {
    sum = sum + fruits[i];
  }
  
  cout << sum << endl;
}

Measured memory_bytes: 3580
#include<cstdio>
#include<algorithm>
using namespace std;
const int MAXN = 100007;
int a[MAXN];
int partition(int a[], int l, int r){
	int tmp = a[r];
	int i = l-1;
	for(int j = 0; j < r; j++){
		if(a[j]<=tmp){
			i++;
			swap(a[i], a[j]);
		}
	}
	swap(a[i+1], a[r]);
	return i+1;
}
int main(){
	int n;
	scanf("%d", &n);
	for(int i = 0; i < n; i++){
		scanf("%d", &a[i]);
	}
	int y = partition(a, 0, n-1);
	for(int i = 0; i < n; i++){
		if(i != 0){
			printf(" ");
		}
		if(i == y){
			printf("[%d]", a[i]);
		}else{
			printf("%d", a[i]);
		}
	}
	printf("\n");
	return 0;
}


Measured memory_bytes: 3128
#include <iostream>
#include <vector>
//#include <string>
//#include <algorithm>
//#include <math.h>
//#include <queue>
//#include <stack>
//#include <iomanip>

// sometimes used
//#include <set>
//#include <map>
//#include <numeric>
//#include <list>
//#include <deque>
//#include <unordered_map>

//typedef long long LL;
//typedef long double LD;
using namespace std;
 
//#define MOD 1000000007
//#define MAX 100100
#define NIL -1

int main() {
    int a;
    int b;
    int c;
    int d;
    int e;
    int f;
    vector<int> g(31, NIL);
    cin >> a >> b >> c >> d >> e >> f;

    int tmp;

    for(int i=0; 100*a*i<=f; i++){
        for(int j=0; 100*b*j<=f; j++){
            if(100*(a*i+b*j)<f){
                g[a*i+b*j]=1;
                tmp=a*i+b*j;
            }
        }
    }

    int max_num=0;
    double max_val=0.0;
    int max_idx=NIL;
    for(int i=1; i<=30; i++){
        if(g[i]!=NIL){
            for(int j=0; c*j<=f; j++){
                for(int k=0; d*k<=f; k++){
                    if(c*j+d*k<=e*i && 100*i+c*j+d*k<=f){
                        if((double)(c*j+d*k)/(((double)i*100.0+(double)(c*j+d*k)))>max_val){
                            max_val=(double)(c*j+d*k)/(((double)i*100.0+(double)(c*j+d*k)));
                            max_num=c*j+d*k;
                            max_idx=i;
                            //cout << max_val << endl;
                        }
                    }
                }
            }
        }
    }

    if(max_num==0){
        max_idx=tmp;
    }

    cout << max_idx*100+max_num << " " << max_num << endl;

    return 0;
}

Measured memory_bytes: 256
/*
 * Created by KeigoOgawa
 */


#include <cstdio>
#include <iostream>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <cassert>
#include <cmath>

#define INF (int)1e8
#define EPS 1e-10
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define RFOR(i, a, b) for (ll i = (b)-1; i >= (a); i--)
#define REP(i, n) for (ll i = 0; i < (n); i++)
#define RREP(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define MIN(a, b) (a > b ? b : a)
#define MAX(a, b) (a > b ? a : b)
#define debug(x) cout << #x << ": " << x << endl
#define all(a) (a).begin(), (a).end()

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> PII;

// vector
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
    int len = v.size();
    for (int i = 0; i < len; ++i) {
        s << v[i]; if (i < len - 1) s << "\t";
    }
    return s;
}

int N;
string s;
vector<vector<int> > dp;

int main(void) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N;
    cin >> s;
    dp.resize(N+1);
    REP(i, N+1) {
        dp[i].resize(3);
    }

    REP(i, N+1) {
        dp[i][0] = dp[i][1] = dp[i][2] = -N;
    }
    dp[0][0] = 0;

    // dp[n][0]: s[n]=0
    // dp[n][1]: s[n]=1, 10
    // dp[n][2]: s[n]=1, 01
    // 連続する1によって個数が増える
    REP(i, N) {
        // 前までの引き継ぎ
        dp[i][0] = max(dp[i][0], dp[i][1]);
        dp[i + 1][0] = max(dp[i + 1][0], dp[i][0]);

        if (s[i] == '1') {
            dp[i + 1][1] = max(dp[i + 1][1], dp[i][1] + 1);
            dp[i + 1][2] = max(dp[i + 1][2], max(dp[i][0], dp[i][2]) + 1);
        }

        if (i == N - 1) continue;
        if (s[i] == '1' && s[i + 1] == '0') {
            dp[i + 2][1] = max(dp[i + 2][1], dp[i][0]);
        }
        if (s[i] == '0' && s[i + 1] == '1') {
            dp[i + 2][0] = max(dp[i + 2][0], dp[i][2]);
        }
    }

    cout << max(dp[N][0], dp[N][1]) << endl;


    return 0;
}


Measured memory_bytes: 28152
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args){
    	try {
    		InputStreamReader isr = new InputStreamReader(System.in);
    		BufferedReader br = new BufferedReader(isr);
    		String buf = br.readLine();
    		StringTokenizer st=new StringTokenizer(buf," ");
    		int a = Integer.parseInt(st.nextToken());
    		int b = Integer.parseInt(st.nextToken());
    		System.out.println( a*b + " " +(a+b)*2);

    	} catch(IOException e) {
		    System.err.println(e);
		}
    }
}

Measured memory_bytes: 16856
#include <bits/stdc++.h>
using namespace std;
int v[110];
int c[110];
int main(){
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",&v[i]);
	}
	for(int i=0;i<n;i++){
		scanf("%d",&c[i]);
	}
	int ma=0;
	for(int i=0;i<n;i++){
		ma+=max(0,v[i]-c[i]);
	}
	printf("%d\n",ma);
	return 0;
}


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

int64_t gcd(int64_t a, int64_t b) {
    return b ? gcd(b, a % b) : a;
}

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (auto& e : a) cin >> e;
    vector<int64_t> gcdl(n), gcdr(n);
    gcdl[0] = a[0], gcdr[n-1] = a[n-1];
    for (int i=1; i<n; i++) gcdl[i] = gcd(a[i], gcdl[i-1]);
    for (int i=n-1; i>0; i--) gcdr[i-1] = gcd(a[i-1], gcdr[i]);

    vector<int64_t> can(n);
    can[0] = gcdr[1], can[n-1] = gcdl[n-2];
    for (int i=1; i<n-1; i++) can[i] = gcd(gcdl[i-1], gcdr[i+1]);

    cout << *max_element(can.begin(), can.end()) << endl;

    return 0;
}

Measured memory_bytes: 2944
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<long double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }
#define INF 1LL<<60

int main() {
    int N;
    cin >> N;

    set<ll> numbers; 
    map<ll, ll> map_numbers;
    REP(i, N) {
        ll tmp;
        cin >> tmp;
        numbers.insert(tmp);
        map_numbers[tmp]++;
    }

    ll ans = 0;
    FORR(t, 37, 1) {
        ll x = pow(2, t-1);
        ll y = pow(2, t);

        if(numbers.size() == 0) break;
        ll max = *numbers.rbegin();
        if(max < x) continue;
        
        set<ll> to_remove;
        for(auto a = numbers.rbegin(); a != numbers.rend(); ++a) {
            if(map_numbers[*a]==0) continue;
            if(*a < x) break;
            if(map_numbers[y - *a]>0 && *a != y - *a) {
                ll num_pair = min(map_numbers[*a], map_numbers[y-*a]);
                ans+=num_pair;
                map_numbers[y-*a]-=num_pair;
                map_numbers[*a]-=num_pair;
                if(map_numbers[*a] == 0) 
                    to_remove.insert(*a);
                if(map_numbers[y-*a] == 0)
                    to_remove.insert(y-*a);
            } else if(map_numbers[y - *a]>=2 && *a == y - *a) {
                ll num_pair = map_numbers[*a] / 2;
                ans+=num_pair;
                map_numbers[*a]-=num_pair;
                if(map_numbers[*a] == 0) 
                    to_remove.insert(*a);
            } else {
                map_numbers[*a] = 0;
                to_remove.insert(*a);
            }
        }

        for(ll r: to_remove) {
            numbers.erase(numbers.find(r));
        }
    }

    cout << ans << endl;

    return 0;
}


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

typedef long long ll;
#define rep(i,x) for(int i=0;i<x;i++)
#define put(ans)    cout << ans << endl;

bool is_integer(double x) {
    return std::floor(x)==x;
}

int main(){
    int x;  cin >> x;
    if(x==0){
        puts("1");
    }else{
        puts("0");
    }
    
    return 0;
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PII;
mt19937 mrand(random_device{}()); 
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head

const int N=2010;
int dx[]={1,0,-1,0},dy[]={0,1,0,-1};
int n,m,t,ans;
char s[N][N];
int dis[N][N];
PII q[N*N];
int main() {
	scanf("%d%d",&n,&m);
	rep(i,0,n) scanf("%s",s[i]);
	memset(dis,0x20,sizeof(dis));
	rep(i,0,n) rep(j,0,m) if (s[i][j]=='#') {
		q[t++]=mp(i,j);
		dis[i][j]=0;
	}
	rep(i,0,t) {
		int x=q[i].fi,y=q[i].se;
		ans=dis[x][y];
		rep(k,0,4) {
			int px=x+dx[k],py=y+dy[k];
			if (px>=0&&px<n&&py>=0&&py<m&&dis[px][py]>10000) {
				dis[px][py]=dis[x][y]+1;
				q[t++]=mp(px,py);
			}
		}
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 28928
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

class Alchemy {

	public static void input_data(int n) {

		for (int i = 0; i < n; i++) {

			String[] name_cost = Main.sc.nextLine().split(" ");
			String name = name_cost[0];
			int cost = Integer.parseInt( name_cost[1] );
			Main.item_data.put(name, cost);
		}

	}

	public static void input_recipe(int m) {
		for (int i = 0; i < m; i++) {
			String[] recipe = Main.sc.nextLine().split(" ");

			String output = recipe[0];
			int prod_fee = 0;

			int k = Integer.parseInt(recipe[1]);

				for (int j = 0; j < k; j++) {
					prod_fee += Main.item_data.get( recipe[2 + j] );
				}
			Main.item_data.put(output, Math.min( prod_fee, Main.item_data.get(output) ) );
		}

	}
}

public class Main {

	static Scanner sc = new Scanner(System.in);
	static Map<String, Integer> item_data = new HashMap<String, Integer>();
	public static void main(String[] args) {

			while (sc.hasNext()) {
				int n = Integer.parseInt(sc.nextLine());
					if (n == 0) {
						break;
					}
				Alchemy.input_data(n);

				int m = Integer.parseInt(sc.nextLine());
				Alchemy.input_recipe(m);

				System.out.println(item_data.get( sc.nextLine() ));

				item_data.clear();
			}

		sc.close();
	}
}


Measured memory_bytes: 31912
// Copyright 2020 yaito3014
#include <bits/stdc++.h>

int main() {
  using namespace std;
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int D;
  cin >> D;
  array<int, 26> c;
  for (auto& e : c) cin >> e;
  vector<array<int, 26>> d(D);
  for (auto& r : d)
    for (auto& e : r) cin >> e;
  for (int i = 0; i < D; ++i) cout << (i % 26) + 1 << '\n';
}

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

#define rp(i, k, n) for (ll i = k; i < n; i++)
#define ll  long long

ll mod = 1e9 + 7;


int main() {
    int n, l;
    cin >> n >> l;
    int ans = 1000;
    int sum = 0;
    rp(i, 1, n + 1) {
        sum += l+i-1;
        if (abs(ans) > abs(l+i-1)) {
            ans = l+i-1;
        }
    }
    printf("%d", sum - ans);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long int
int32_t main(){
	string s;int k;
	cin>>s>>k;
	for(int i=0;i<min(k,(int)s.length());i++){
		if(s[i]!='1'){
			cout<<s[i];return 0;
		}
	}
	cout<<1;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <algorithm>
#include <numeric>
#include <utility>
#include <random>
#include <chrono>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>

using namespace std;

using LL = long long;
using ULL = unsigned long long;
using PII = pair<int, int>;
using PIL = pair<int, LL>;
using PLL = pair<LL, LL>;
const int mod = 1e9 + 7;
// const int mod = 998244353;

inline void quickread() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
}

int a[1010][1010], f[1010][1010];
string st;
int h, w;

inline void work() {
    cin >> h >> w;
    for (int i = 1; i <= h; ++i) {
        cin >> st;
        for (int j = 1; j <= w; ++j) {
            a[i][j] = (st[j - 1] == '.');
        }
    }
    for (int i = 2; i <= h; ++i) {
        if (!a[i][1]) {
            break;
        }
        f[i][1] = 1;
    }
    for (int j = 2; j <= w; ++j) {
        if (!a[1][j]) {
            break;
        }
        f[1][j] = 1;
    }
    for (int i = 2; i <= h; ++i) {
        for (int j = 2; j <= w; ++j) {
            if (a[i][j]) {
                f[i][j] = (f[i][j - 1] + f[i - 1][j]) % mod;
            }
        }
    }
    cout << f[h][w] << "\n";
}

int main() {
    // freopen("input.txt", "r", stdin);
    quickread();
    work();
    return 0;
}

Measured memory_bytes: 8192
#include<iostream>
#include<queue>
using namespace std;
int main () {
  int MOD = 1e9 + 7;
  int dp[1003][1003];
  char map[1003][1003];
  int H, W;
  cin >> H >> W;
  for (int i = 0; i < H; i ++) {
    for (int j = 0; j < W; j ++) {
      cin >> map[i][j];
    }
  }
  for (int i = 0; i <= H; i ++) {
    for (int j = 0; j <= W; j ++) {
      dp[i][j] = 0;
    }
  }
 dp[0][1] = 1;
  for (int i = 1; i <= H; i ++) {
    for (int j = 1; j <= W; j ++) {
      if (map[i - 1][j - 1] != '#') dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % MOD;
    }
  }
  /*for (int i = 0; i <= H; i ++) {
    for (int j = 0; j <= W; j++) {
      cout << dp[i][j] << ' ';
    }
    cout << endl;
  }*/
  cout << dp[H][W] << endl;
}

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

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

    vector<string> S(3);
    for(int i = 0; i < 3; i++){
        cin >> S[i];
    }

    int now = 0;
    vector<int> Idx(3, 0);
    while(true){
        int past = now;
        if(Idx[now] == S[now].size()){
            cout << char('A' + now) << endl;
            return 0;
        }
        now = int(S[now][Idx[now]] - 'a');
        Idx[past]++;
    }

    return 0;
}

Measured memory_bytes: 256