akhauriyash/Code-Regression huggingface dataset:
a = 1
b = 2
c = 3
d = 4
e = 5
a,b,c,d,e = map(int,input().split())

if a != 1:
    print("1")

if b != 2:
    print("2")

if c != 3:
    print("3")

if d != 4:
    print("4")

if e != 5:
    print("5")

Measured memory_bytes: 61744
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,a,b) for(int i=(a);i<(b);++i)

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

//vector出力
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){
  o<<"{";
  for(int i=0;i<(int)v.size();i++) o << (i>0?", ":"") << v[i];
  o<<"}"<<endl;
  return o;
}


int main() {
  int a,b;
  cin >> a >> b;
  if (a+b==15) cout << '+';
  else if (a*b==15) cout << '*';
  else cout << 'x';
  cout << endl;
}


Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
P t[6];

bool solve(){
  if(t[0]!=t[1]||t[2]!=t[3]||t[4]!=t[5])return false;
  return (t[0].first==t[2].first&&t[0].second==t[4].first&&t[2].second==t[4].second);
}

int main(){
  for(int i=0;i<6;i++){
    int a,b;
    cin>>a>>b;
    if(a>b)swap(a,b);
    t[i]=P(a,b);
  }
  sort(t,t+6);
  cout<< (solve()?"yes":"no") <<endl;
  return 0;
}

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

typedef struct money{
  double value;
  string unit;
};

int main(){
  int N;
  cin>>N;
  vector <money> a(N);
  for(int i=0;i<N;i++){
    cin>>a[i].value>>a[i].unit;
  }

  double sum=0;

  for(int i=0;i<N;i++){
    if(a[i].unit=="JPY")
      sum+=a[i].value;
    else
      sum+=a[i].value*380000.0;
  }
  cout<<sum<<endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
// Custom Header {{{
#define ALL(x) x.begin(), x.end()
#define endl '\n'
using namespace std;
using i64 = long long;
using pii = pair<int, int>;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
// }}}

struct Edge { // {{{
    int src, to;
    i64 cost;
    Edge(int src,  int to, i64 cost) : src(src), to(to), cost(cost) {}
    Edge(int to, i64 cost = 0) : Edge(-1, to, cost) {}
    bool operator< (const Edge &o) const { return cost < o.cost; }
    bool operator> (const Edge &o) const { return cost > o.cost; }
};
using Edges = vector<Edge>;
using WGraph = vector<vector<Edge>>;
using Ugraph = vector<vector<int>>;
// }}}

vector<i64> dijkstra(const WGraph &G, vector<int> src) // {{{
{
    vector<i64> dist(G.size(), LINF);
    priority_queue<pii, vector<pii>, greater<pii>> pq;

    for (int s : src) {
        dist[s] = 0;
        pq.emplace(0, s);
    }

    while(!pq.empty()) {
        const i64 nowCost = pq.top().first;
        const int nowNode = pq.top().second;
        pq.pop();
        if (dist[nowNode] < nowCost) continue;

        for (const auto &e : G[nowNode]) {
            const i64 newCost = nowCost + e.cost;
            if (chmin(dist[e.to], newCost)) {
                pq.emplace(newCost, e.to);
            }
        }
    }

    return dist;
}
// }}}

signed main()
{
    cin.tie(nullptr); ios::sync_with_stdio(false);

    int H, W, D, Q;
    int a[303][303];
    pii pos[303 * 303];

    cin >> H >> W >> D;
    for (int i = 1; i <= H; ++i) {
        for (int j = 1; j <= W; ++j) {
            cin >> a[i][j];
            pos[a[i][j]] = pii(i, j);
        }
    }

    WGraph G(H*W + 1);

    for (int i = 1; i <= H*W; ++i) {
        if (i + D > H*W) continue;
        const int sy = pos[i].first;
        const int sx = pos[i].second;
        const int gy = pos[i+D].first;
        const int gx = pos[i+D].second;
        G[i].emplace_back(i+D, abs(gy - sy) + abs(gx - sx));
    }

    vector<int> src;
    for (int i = 1; i <= D; ++i) src.emplace_back(i);

    const auto dist = dijkstra(G, src);

    cin >> Q;
    while (Q--) {
        int L, R;
        cin >> L >> R;
        cout << dist[R] - dist[L] << endl;
    }


    return 0;
}


Measured memory_bytes: 7808
#include <iostream>
using namespace std;
int main(){
  int N;
  cin >> N;
  int a[100010];
  for(int i = 1; i <= N; ++i){
    cin >> a[i];
  }
  int i = 0;
  int light = 1;
  bool can = false;
  while(i < N){
    ++i;
    light = a[light];
    if(light == 2){
      can = true;
      break;
    }
  }
  if(can) cout << i << endl;
  else cout << -1 << endl;
}
 

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main() {
    int N;
    cin >> N;
    vector<int>L(N);
    for(int i = 0; i < N; i++) {
        cin >> L[i];
    }
    int cnt = 0;
    sort(L.begin(),L.end());
    for(int i = 1; i < N; i++) {
        for(int j = i+1; j < N; j++) {
            auto au = lower_bound(L.begin(),L.end(),L[j]-L[i]+1);
            if(au == L.end()) {
                continue;
            }
            if(au-L.begin() < i) {
                cnt+=i-(au-L.begin());
            }
        }
    }
    cout << cnt << endl;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

public class Solution
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine());
        int count = 0;
        int ba = 0;
        int xa = 0;
        int bx = 0;
        for (int i = 0; i < n; i++)
        {
            var s = Console.ReadLine();
            count += s.Replace("AB", "_").Count(c => c == '_');
            if (s.First() == 'B' && s.Last() == 'A')
            {
                ba++;
            }
            else if (s.Last() == 'A')
            {
                xa++;
            }
            else if (s.First() == 'B')
            {
                bx++;
            }
        }

        var max = count;
        if (xa > 0)
        {
            xa--;
        }
        else if (ba > 0)
        {
            ba--;
        }
        else
        {
            Console.WriteLine(max);
            return;
        }

        max += ba;
        ba = 0;
        if (bx > 0)
        {
            max++;
            bx--;
        }
        else
        {
            Console.WriteLine(max);
            return;
        }

        max += Math.Min(xa, bx);
        Console.WriteLine(max);
    }
}

Measured memory_bytes: 13268
// clang-format off
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using pii = pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
#define all(c) begin(c), end(c)
#define rall(c) rbegin(c), rend(c)
#define fore(x, c) for(auto &&x : c)
#define rep(i, a, n) for(int i = a, i##len = (int)(n); i < i##len; ++i)
#define rrep(i, a, n) for(int i = (int)(n - 1); i >= a; --i)
#define sz(c) ((int)c.size())
#define contains(c, x) (c.find(x) != end(c))
#define inseg(l, x, r) ((l) <= (x) && (x) < (r))
#define dump(...)
#define pb push_back
#define eb emplace_back
#define _ 0
const signed INF_ = 1001001001; const long long INF = 1001001001001001001LL;
const int DX[9] = {0,1,0,-1,1,1,-1,-1,0}, DY[9] = {-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os, const vector<T> &v) {
  for (auto i = begin(v); i != end(v); i++) os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is, vector<T> &v) {
  for (auto i = begin(v); i != end(v); i++) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
  is>>p.first>>p.second;return is;}
template<class T, class U> bool chmax(T &a, const U &b){return a<b?a=b,1:0;}
template<class T, class U> bool chmin(T &a, const U &b){return a>b?a=b,1:0;}
template <class T> void psum(T& c) {partial_sum(begin(c), end(c), begin(c));}
template<class T> using heap = priority_queue<T, deque<T>, greater<T>>;
struct before_main_function {
  before_main_function() {
      cin.tie(nullptr); ios::sync_with_stdio(0);
      cout << setprecision(15) << fixed;
  }
} before_main_function;
// clang-format on
//------------------8<------------------------------------8<--------------------

signed main() {
  int N;
  cin >> N;
  int A, B;
  cin >> A >> B;
  if ((B - A) % 2 == 0) {
    cout << (B - A) / 2 << endl;
  } else {
    int ans = INF;
    chmin(ans, A + ((B - A) - 1) / 2);
    B = N - B + 1;
    A = N - A + 1;
    swap(B, A);
    chmin(ans, A + ((B - A) - 1) / 2);
    cout << ans << endl;
  }
  return (0 ^ _ ^ 0);
}



Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner scan =new Scanner(System.in);
		int N=scan.nextInt();
		int a=(N%100)%10;
		int b=0;
		int[][] c= {{2,4,5,7,9},{0,1,6,8},{3}};
		String[] d= {"hon","pon","bon"};
		while(true) {
			for(int i=0;i<3;i++)
				for(int j=0;j<c[i].length;j++)
					if(a==c[i][j])
						b=i;
						break;
		}
		System.out.print(d[b]);
	}

}


Measured memory_bytes: 35708
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;

int main(){
  long long int t,tt,a,aa,b,bb;
  cin >> t >> tt;
  cin >> a >> aa;
  cin >> b >> bb;
  if((t*a+tt*aa) == (t*b+tt*bb)){
  	cout << "infinity" << endl; return 0;
  }
  if((t*a+tt*aa)<(t*b+tt*bb)){
  	swap(a,b); swap(aa,bb);
  }
  if(a>b){cout << 0 << endl; return 0;}
  long long int d = (t*a+tt*aa) - (t*b+tt*bb);
  cout << 2*((t*(b-a))/d) + 1 - ((t*(b-a))%d ==0 ? 1 : 0)<< endl;
  return 0;
}


Measured memory_bytes: 504
#include <bits/stdc++.h>
#define int long long

using namespace std;

signed main() {

    int n,k;
    cin>>n>>k;
    int a[n];
    int s=0;
    for (int i = 0; i < n; ++i) {
        cin>>a[i];
        s+=a[i];
    }

    vector<int>v;
    for (int i = 1; i*i <=s ; ++i) {
        if(s%i==0)
        {
            v.push_back(i);
            v.push_back(s/i);
        }
    }

    int mx=0;
    for(auto i:v)
    {
        vector<int>ss;
        for (int j = 0; j < n; ++j) {
            if(a[j]%i!=0)
                ss.push_back(a[j]%i);
        }

        sort(ss.begin(),ss.end());
        deque<int>d;
        for(auto j:ss)
            d.push_back(j);

        int count=0;
        while (d.size()>1)
        {
            int k1=d.front();
            int k2=d.back();
            d.pop_back();
            d.pop_front();
            if((k2+k1)>=i)
            {
                count+=i-k2;
                k1-=i-k2;
                d.push_front(k1);
            }
            else
            {
                count+=k1;
                k2+=k1;
                d.push_back(k2);
            }
        }

        if(count<=k)
        {
            mx=max(mx,i);
        }
    }

    cout<<mx;
}

Measured memory_bytes: 256
#pragma GCC optimize(3)
#include<bits/stdc++.h>
#define MAXN 405
#define INF 1000000000
#define MOD 1000000007
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
ll H,W,ans,cnt0,cnt1;
char str[MAXN][MAXN];
bool vis[MAXN][MAXN];
void dfs(ll x,ll y)
{
    if(str[x][y]=='#') cnt0++; else cnt1++;
    vis[x][y]=true;
    if(x>1&&!vis[x-1][y]&&str[x-1][y]!=str[x][y]) dfs(x-1,y);
    if(x<H&&!vis[x+1][y]&&str[x+1][y]!=str[x][y]) dfs(x+1,y);
    if(y>1&&!vis[x][y-1]&&str[x][y-1]!=str[x][y]) dfs(x,y-1);
    if(y<W&&!vis[x][y+1]&&str[x][y+1]!=str[x][y]) dfs(x,y+1);
}
int main()
{
    scanf("%lld%lld",&H,&W);
    for(ll i=1;i<=H;i++) scanf("%s",str[i]+1);
    memset(vis,false,sizeof(vis));
    ans=0;
    for(ll i=1;i<=H;i++)
    {
        for(ll j=1;j<=W;j++)
        {
            if(vis[i][j]) continue;
            cnt0=cnt1=0;dfs(i,j);
            ans+=cnt1*cnt0;
        }
    }
    printf("%lld\n",ans);
    return 0;
}



Measured memory_bytes: 13056
#include <iostream>
#include <cstdio>
#include <cstdlib>
using namespace std;

bool bad[20];

bool good(int n)
{
	while(n > 0)
	{
		int x = n % 10;
		if (bad[x]) return false;
		n /= 10;
	}
	return true;
}

int main()
{
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);

	int n, k;
	scanf("%d%d", &n, &k);
	while(k--)
	{
		int x;
		scanf("%d", &x);
		bad[x] = 1;
	}
	while(!good(n)) n++;
	printf("%d\n", n);

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string>
#include <complex>
using namespace std;
int main(void) {
  long a=0,b=0,c=0,x=0,count=0;
  cin >> a;
  cin >> b;
  cin >> c;
  cin >> x;
  for(int i = 0; i <= a; i++) {
    for(int j = 0; j <= b; j++) {
      for(int z = 0; z <= c; z++) {
        if((500*i + 100*j + 50*z) == x) {
          count++;
        }
      }
    }
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 256
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args) {
#if DEBUG
        MyDebugger.Test(process, "../TextFile1.txt");
        //MyDebugger.Test(process, "../TextFile2.txt");
        //MyDebugger.MakeTestCase("../TextFile2.txt");
#else
        object ret = process(new StreamReader(Console.OpenStandardInput()));
        Console.WriteLine(ret);
#endif
    }

    static object process(TextReader input) {
        var n = int.Parse(input.ReadLine());

        if (n == 1) {
            return "Hello World";
        } else {
        var a = int.Parse(input.ReadLine());
        var b = int.Parse(input.ReadLine());

            return a + b;
        }
    }
}


Measured memory_bytes: 11092
def main():
    n, *a = map(int, open(0).read().split())

    b = [sum([cur_a * (-1) ** in_i for in_i, cur_a in enumerate(a)])]

    for cur_a in a[:-1]:
        b.append((cur_a - b[-1] // 2) * 2)

    ans = b
    print(*ans)
    return()

if __name__ == '__main__':
    main()


Measured memory_bytes: 14092
#include <iostream>

using namespace std;

int main()
{
    int x;
    cin>>x;
    
    if(x<600) cout<<8<<'\n';
    else if(x<800) cout<<7<<'\n';
    else if(x<1000) cout<<6<<'\n';
    else if(x<1200) cout<<5<<'\n';
    else if(x<1400) cout<<4<<'\n';
    else if(x<1600) cout<<3<<'\n';
    else if(x<1800) cout<<2<<'\n';
    else cout<<1<<'\n';
    

    return 0;
}

Measured memory_bytes: 3672
N, K = map(int, input().split())

a = []

for i in range(K):
    d = int(input())
    A = list(map(int, input().split()))
    for j in A:
        if j not in a:
            a.append(j)

ans = 0

for i in range(1,N+1):
    if i not in a:
        ans += 1

print(ans)


Measured memory_bytes: 9068
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

using std::string;
using std::vector;
using std::set;
using std::multiset;
using std::unordered_set;
using std::map;
using std::multimap;
using std::unordered_map;
using std::pair;
using std::cin;
using std::cout;

using boost::multiprecision::cpp_int;
using cpp_dec_float_1000 = boost::multiprecision::number<boost::multiprecision::cpp_dec_float<1000, boost::int128_type>>;

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

constexpr char CRLF  = '\n';
constexpr char SPACE = ' ';
constexpr char VECTOR_COUT_SEPARATOR = SPACE;
constexpr ll INF = 1000'000'007;
constexpr int MOD = 1000'000'007;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> std::ostream& operator<< (std::ostream& os, const std::vector<T>& vc) { for(auto it = vc.begin(); it != vc.end(); ++it) { if (std::next(it) == vc.end()) os << *it; else os << *it << VECTOR_COUT_SEPARATOR; } return os; }
template<class T1, class T2> inline std::ostream & operator<< (std::ostream & os, const std::pair<T1, T2> & p) { return os << p.first << ' ' << p.second; }
template<class T> T modinv(T a, T m) { T b = m, u = 1, v = 0; while (b) { T t = a / b; a -= t * b; boost::swap(a, b); u -= t * v; boost::swap(u, v); } u %= m; if (u < 0) u += m; return u; }
template<class T> inline bool isSosuu(const T& n) { if (n == T(1)) { return false; } for (T i = 2; i*i <= n; ++i) { if (n % i == 0) { return false; } } return true; }
template<class T> vector<vector<T>> split (const vector<T>& S, T delim) { vector<vector<T>> ret{}; vector<T> buff{}; for (auto c : S) { if (c == delim) { if (!buff.empty()) ret.push_back(buff); buff.clear(); } else { buff.push_back(c); } } if (!buff.empty()) ret.push_back(buff); return ret; }
template<class T> inline void printYesNo(const T& t) { cout << (t ? "Yes" : "No") << CRLF; }
template<class T = int64_t> T modpow(T N, T P, T M) { T ret{1}; N %= M; while (P) { if (P & 0x01) { ret *= N; ret %= M; } P >>= 1; N *= N; N %= M; } return ret; }

/** code for assert debug begin */
int gErr = 0;
#define ASSERT(p) if(!(p)){ gErr = 1; }else{ ; }
/** code for assert debug end */

struct Tmp
{
public:
  int N;
  Tmp(int N)
  : N(N)
  {}
};

void solve(void)
{
  int N; cin >> N;
  vector<ll> A(N);
  for (auto& a : A) { cin >> a; }
  vector<ll> B(N);
  boost::partial_sum(A, B.begin());
  ll sum = boost::accumulate(A, 0L);
  ll res = std::numeric_limits<ll>::max();

  for (int i = 0; i < N-1; ++i) {
    auto a = B[i];
    auto b = sum - B[i];
    auto cost = std::abs(a - b);

    chmin(res, cost);
  }
  cout << res << CRLF;
  return;
}

int main(void)
{
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(0);

  solve();

  return 0;
}


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

int main(){
	int N;
	cin >> N;
	int  count =0;
  int a= N;
	while(N>0){
		N /=10;
		count++;
	}
	switch(count){
		case 6:
		cout << 90909;
		break;
		case 5:
		cout << a-10000+1+909;
		break;
		case 4:
		cout << 909;
		break;
		case 3:
		cout << a-100+1+9;
		break;
		case 2:
		cout << 9;
		break;
		case 1:
		cout <<a <<endl;
		break;
	}
}

Measured memory_bytes: 256
import java.util.Scanner

/**
  * Created by goryudyuma on 2017/07/16.
  */


object Main {
  def main(args: Array[String]): Unit = {
    val sc = new Scanner(System.in)
    val N = sc.nextInt()
    val K = sc.nextInt()
    val arr: Array[Int] = new Array[Int](N)

    for (i <- 0 until N) {
      arr(i) = sc.nextInt()
    }

    println(arr.sorted.reverse.splitAt(K)._1.sum)
  }
}


Measured memory_bytes: 25896
#include<bits/stdc++.h>
using namespace std;
long long ans,a[200010];
int main(){
    int n;
    cin>>n;
    for(int i=1;i<=n;i++) cin>>a[i];
    for(int i=2;i<=n;i++) {
    	ans+=max(0ll,a[i-1]-a[i]);
    	a[i]+=max(0ll,a[i-1]-a[i]);
	}
	cout<<ans;
	return 0;
}

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

signed main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

    //int t=1; cin>>t; while(t--)
    {
        int a, b; 
        cin >> a >> b;
    
        cout << (a < 10 && b < 10 ? a*b : -1) << '\n';
    
    }

    cerr << "Time elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n";
    return 0;
}


Measured memory_bytes: 256
n,m,x = map(int, input().split())
ca = [list(map(int, input().split())) for _ in range(n)]


def hantei(list):
    for i in range(m):
        if list[i] < x:
            return False
    return True


ans = 100000000

for i in range(2 ** n):
    kin = 0
    rikai = [0] * m
    for j in range(n):
        if ((i >> j) & 1):
            kin += ca[j][0]
            for k in range(m):
                rikai[k] += ca[j][k+1]
        if hantei(rikai):
            if kin < ans:
                ans = kin

if ans == 100000000:
    ans = -1

print(ans)

Measured memory_bytes: 69004
N, M = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(N)]
K = []
for i in range(N):
    K.append(A[i][0])
    del A[i][0]
    
ans = A[0]
for i in range(N-1):
    ans = set(ans) & set(A[i+1])

print(len(ans))


Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <map>
#include <string>
#include <vector>

using namespace std;

long long dp[1000][1000] = {};

int main(){
	int N, K;
	long long ans=0;
	long long tmp1 = 0, tmp2 = 0;
	cin >> N >> K;
	for (int i = 0; i < N; i++){
		for (int j = 0; j < K; j++){
			if (i == 0){
				dp[i][j] = 1;
			}
			else{
				dp[i][j] =tmp1-dp[i-1][j];
			}
			tmp2 += dp[i][j];

			if (j == K - 1){
				tmp1 = tmp2;
				tmp2 = 0;
			}

		}
	}

		for (int j = 0; j < K; j++){
			ans+= dp[N-1][j];
		}

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

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

int main(){
	vector<int> v(10);
	for(int i = 0 ; i < 10 ; i++) cin >> v[i];
	sort(v.begin(),v.end());
	for(int i = 0 ; i < 3 ; i++)
		cout << v[v.size()-1-i] << endl;
}

Measured memory_bytes: 1212
#include<cstdio>
 
#define ran 555
 
int n, m;
int a[ran][ran];
int s, v[ran*ran][4];
 
void o(int a, int b, int c, int d) {
	v[s][0] = a; v[s][1] = b; v[s][2] = c; v[s][3] = d;
	s++;
}
 
int main() {
	scanf("%d%d", &n, &m);
	for(int i=1;i<=n;i++)
	for(int j=1;j<=m;j++) 
		scanf("%d", &a[i][j]);
	
	s = 0;
	for(int i=1;i<n;i++) 
	for(int j=1;j<=m;j++)
		if (a[i][j]%2) {
			a[i][j]--; a[i+1][j]++;
			o(i, j, i+1, j);
		}
	for(int j=1;j<m;j++)
		if (a[n][j]%2) {
			a[n][j]--; a[n][j+1]++;
			o(n, j, n, j+1);
		}
	printf("%d\n", s);
	for(int i=0;i<s;i++) 
		printf("%d %d %d %d\n", v[i][0], v[i][1], v[i][2], v[i][3]);
	
	return 0;
}

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

int main(){
    int H,W;
    while(1){
        cin >> H >> W;
        if (H == 0 && W == 0)break;
        for ( int i = 0; i < H; i++)
        {
            for (int i = 0; i < W; i++)
            {
                cout << "#";
            }
        cout << endl;
        }
    cout << endl;
    }
return 0;
}
    


Measured memory_bytes: 3112
// Aizu Vol-10 1017: Riffle Shuffle
// 2017.8.24 bal4u@uu

#include <stdio.h>

int a[55], b[55], c[55];
int ca, cb, ia, ib, ic;

int main()
{
	int n, r, m, k;

	while (scanf("%d%d", &n, &r) == 2) {
		for (k = 0; k < n; k++) c[k] = k;
		cb = n >> 1, ca = n - cb;
		while (r-- > 0) {
			k = 0;
			for (ib = 0; ib < cb; ib++) b[ib] = c[k++];
			for (ia = 0; ia < ca; ia++) a[ia] = c[k++];
			scanf("%d", &m);
			for (ia = ib = ic = 0; ia < ca || ib < cb; ) {
				for (k = 0; k < m && ia < ca; k++) c[ic++] = a[ia++];
				for (k = 0; k < m && ib < cb; k++) c[ic++] = b[ib++];
			}
		}
		printf("%d\n", c[ic-1]);
	}
	return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
#define FOR(i,a,n) for(ll i=(ll)a;i<(ll)n;i++)
#define RFOR(i,a,n) for(ll i=(ll)n-1;i >= (ll)a;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,0,n)
#define ALL(v) v.begin(), v.end()
#define bra(first,second) '(' << first << ',' << second << ')'
//constexpr ll MOD = 1000000007;
constexpr ll MOD = 998244353;
ll INF = 1001001001001001001;
long double EPS = 1e-11;
long double PI = 3.141592653589793238;
template<typename T>
void remove(std::vector<T>& vector, unsigned int index){
    vector.erase(vector.begin() + index);
}

using Graph = vector<vector<ll>>;

ll tableF[200010];
ll tableI[200010];

ll modfact(ll a,ll m){
   if(tableF[a] != -1){
      return tableF[a];
   }
   if(a == 1){
      tableF[a] = 1;
      return tableF[a];
   }
   ll res = 1;
   res = a * modfact(a-1,m);
   res %= m;
   tableF[a] = res;
   return res;
}

ll modpow(ll a,ll n,ll m){//modpow(a,n,m) := a ^ n (mod m)
  ll res = 1;
  while(n > 0){
    if(n & 1)res = res * a % m;
    a = a * a % m;
    n >>= 1;
  }
  return res;
}

ll modinv(ll a,ll p){//modinv(a,p) := pを法とするaの逆元(※pは素数でなければならない)
    ll res = modpow(a,p-2,p);
    return res;
}

ll modCON(ll n,ll r,ll m){
   if(n < 200010){
   ll res = 1;
   if(n < 0 || r < 0 || n < r){
      return 0;
   }
   res *= tableF[n];
   res %= m;
   res *= tableI[r];
   res %= m;
   res *= tableI[n-r];
   res %= m;
   return res;
   }else{
   ll res = 1;//tableを持ってないときよう
   for(int i = 1;i <= n;i++){
      res *= i;
      res %= m;
   }
   for(int i = 1;i <= r;i++){
      res *= modinv(i,m);
      res %= m;
   }
   for(int i = 1;i <= n-r;i++){
      res *= modinv(i,m);
      res %= m;
   }
   return res;
   }
}

void modfill(ll m){//忘れない　約200ms
   fill(tableF,tableF+200010,-1);
   fill(tableI,tableI+200010,-1);
   tableF[0] = 1;
   tableI[0] = 1;
   for(int i = 1;i < 200010;i++){
      tableF[i] = modfact(i,m);
      tableI[i] = modinv(tableF[i],m);
   }
}

ll modtable[5010][5010];

int main(){
   modfill(MOD);
   rep(i,5010) rep(j,5010){
      modtable[i][j] = modCON(i,j,MOD);
   }
   ll K,N;
   cin >> K >> N;
   ll all = modtable[N+K-1][N];
   FOR(i,2,2*K+1){
      ll res = all;
      ll cnt = 0;
      FOR(j,1,K+1){
         if(j <= K && i - j <= K && j <= i - j)cnt++;
      }
      FOR(j,1,cnt+1){
         if(j * 2 > N) break;
         if(j % 2 == 1){
            res -= modtable[cnt][j] * modtable[N+K-1-j*2][K-1];
         }else{
            res += modtable[cnt][j] * modtable[N+K-1-j*2][K-1];
         }
         while(res < 0) res += MOD * (ll)1000000000;
         res %= MOD;
      }
      cout << res % MOD << endl;
   }
}


Measured memory_bytes: 199552
package main

import "fmt"

func main() {
	var s string
	fmt.Scan(&s)
	m := make(map[rune]int, 26)
	for _, r := range s {
		m[r]++
	}
	var r = 'a'
	for {
		if m[r] == 0 {
			fmt.Println(string(r))
			break
		}
		if r != 'z' {
			r++
		} else {
			fmt.Println("None")
			break
		}
	}
}


Measured memory_bytes: 1280
use std::io;

fn main() {
  let mut buf = String::new();
  io::stdin().read_line(&mut buf).unwrap();
  let s: Vec<&str> = buf.split_whitespace().collect();
  let n: f32 = s[0].parse().unwrap();
  let m: f32 = s[1].parse().unwrap();
  println!("{}", 2_f32.powf(m) * (1900_f32 * m + 100_f32 * (n - m)));
}


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

int linearSearch(int A[], int n, int key) {
  int i = 0;
  A[n] = key;
  for (; A[i] != key; i++);
  if (i == n) return -1;
  return i;
}

int main() {
  int n; cin >> n;
  int A[100001];
  for (int i = 0; i < n; i++) {
    cin >> A[i];
  }
  int q; cin >> q;
  int ans = 0;
  for (int i = 0; i < q; i++) {
    int t; cin >> t;
    if (linearSearch(A, n, t) != -1) ans++;
  }
  cout << ans << endl;
}


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

using namespace std;

//int maxstixks[10]={0,0,1,7,4,5,9,8,0,0};
bool comaprestr(const string &str1,const string &str2){
	if (str1.size()<str2.size())
	{
		return true;
	}else if (str1.size()==str2.size() && str1.size()>0)
	{
		return str1<str2;
	}else{
		return false;
	}
}
int main(int argc, char const *argv[])
{
	int reqsticks[10]={0,2,5,5,4,5,6,3,7,6};
	int n,m,tmp;
	cin >> n >> m;
	string dp[n+1];
	dp[0]="";
	dp[1]="";
	vector<int> arr(m,0);
	int minreq=10000;
	//cout << "numberusable\n";
	//cout << m << '\n';
	for (int i = 0; i <m ; ++i)
	{
		cin >> arr[i];
	}
	//cout << '\n';
	//cout << "satring dp\n";
	for (int i = 2; i <=n; ++i)
	{
		//cout << "i: " << i << '\n';
		string maxstr="";
		for (int j = 0; j <m ; ++j)
		{
			string tmpstr="";
			if (i-reqsticks[arr[j]]>0 || i-reqsticks[arr[j]]==0)
			{
				if (i-reqsticks[arr[j]]==0)
				{
					auto s=to_string(arr[j]);
					tmpstr+=s;
					sort(tmpstr.rbegin(),tmpstr.rend());
				}else{
					if(dp[i-reqsticks[arr[j]]]!=""){
						tmpstr+=dp[i-reqsticks[arr[j]]];
						auto s=to_string(arr[j]);
						tmpstr+=s;
						sort(tmpstr.rbegin(),tmpstr.rend());
					}
				}

			}
			if (comaprestr(maxstr,tmpstr))
			{
				maxstr=tmpstr;
			}

		}
		dp[i]=maxstr;
		//cout <<maxstr << '\n';
	}
	cout << dp[n] << '\n';
	return 0;
}

Measured memory_bytes: 25472
//============================================================================
// Name        : ITP_1_11_A.cpp
// Author      : 
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
using namespace std;

// [0]が上面にある時のサイコロの状態を作成。
// 時計回り。インデックスの意味は薄いです。
int STATE[6][4] =
{
		{2,4,5,3},
		{6,4,1,3},
		{6,2,1,5},
		{6,5,1,2},
		{6,3,1,4},
		{5,4,2,3}
};

class Dice
{
public:
	int nums[6];
	int joumen;
	int north_num;

public:
	Dice();

	void Command(char cmd);
	int GetNorhIndex();
	int NumToDiceIndex(int num);
};

Dice::Dice()
{
	// サイコロの初期状態
	joumen = 1;
	north_num = 5;
}

void Dice::Command(char cmd)
{
	int idx = GetNorhIndex();
	int tmp_joumen = 0;
	int tmp_north = 0;

	if(cmd == 'N'){
		tmp_north = joumen;
		tmp_joumen = STATE[joumen-1][(idx + 2)%4];
	}
	else if(cmd == 'E'){
		tmp_north = north_num;
		tmp_joumen = STATE[joumen-1][(idx + 3)%4];
	}
	else if(cmd == 'S'){
		tmp_north = 7 - joumen;
		tmp_joumen = north_num;
	}
	else if(cmd == 'W'){
		tmp_north = north_num;
		tmp_joumen = STATE[joumen-1][(idx + 1)%4];
	}

	joumen = tmp_joumen;
	north_num = tmp_north;
}

int Dice::GetNorhIndex()
{
	int res = 0;
	for(int i=0;i<4;i++){
		if(STATE[joumen-1][i] == north_num){
			res = i;
			break;
		}
	}

	return res;
}

int Dice::NumToDiceIndex(int num){
	for(int i=0;i<6;i++){
		if(nums[i] == num){
			return i + 1;
		}
	}
	return 0;
}

int main()
{
	Dice dice;

	// サイコロ面の数字入力
	for(int i=0;i<6;i++){
		cin >> dice.nums[i];
	}

	// 質問数
	int qes = 0;
	cin >> qes;

	for(int q=0;q<qes;q++){
		// 回転したていで設定
		int joumen_num = 0;
		int south_num  = 0;
		cin >> joumen_num >> south_num;
		dice.joumen = dice.NumToDiceIndex(joumen_num);
		dice.north_num = 7 - dice.NumToDiceIndex(south_num);

		int ans = dice.nums[STATE[dice.joumen-1][(dice.GetNorhIndex() + 1)%4]-1];
		cout << ans << endl;
	}
	return 0;
}



Measured memory_bytes: 3084
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int h = in.nextInt();
            int w = in.nextInt();

            String a[] = new String[h];

            for (int i = 0; i < h; i++) {
                a[i] = in.readString();
            }

            for (int i = 0; i < w + 2; i++) {
                out.print("#");
            }
            out.println();
            for (int i = 0; i < h; i++) {
                out.print("#");
                out.print(a[i]);
                out.print("#");
                out.println();
            }

            for (int i = 0; i < w + 2; i++) {
                out.print("#");
            }
        }

    }

    static class InputReader {
        private final InputStream stream;
        private final byte[] buf = new byte[8192];
        private int curChar;
        private int snumChars;

        public InputReader(InputStream st) {
            this.stream = st;
        }

        public int read() {
            if (snumChars == -1)
                throw new InputMismatchException();
            if (curChar >= snumChars) {
                curChar = 0;
                try {
                    snumChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (snumChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public String readString() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        public boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

    }
}



Measured memory_bytes: 21460
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
#include <cstdlib>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
#define dump(val) cerr << __LINE__ << ":\t" << #val << " = " << (val) << endl

using namespace std;

typedef long long int lli;

template<typename T>
vector<T> make_v(size_t a, T b) {
    return vector<T>(a, b);
}

template<typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v(ts...))>(a, make_v(ts...));
}

struct Edge {
    int x, y, foot, cost;
    Edge(int _x, int _y, int f, int c)
        : x(_x), y(_y), foot(f), cost(c) {}
    Edge() {}
    bool operator<(const Edge &e) const {
        return cost > e.cost;
    }
};

int main() {
    int w, h;
    while (cin >> w >> h, w + h) {
        auto mp = make_v(h, w, ' ');
        REP(i, 0, h) {
            REP(j, 0, w) {
                cin >> mp[i][j];
            }
        }
        priority_queue<Edge, vector<Edge>> pq;
        REP(i, 0, h) {
            REP(j, 0, w) {
                if (mp[i][j] == 'S') {
                    REP(x, -3, 4) {
                        if (x == 0) continue;
                        REP(y, -3, 4) {
                            if (abs(x) + abs(y) > 3) continue;
                            int nx = j + x;
                            int ny = i + y;
                            if (nx < 0 || ny < 0 || nx >= w || ny >= h || mp[ny][nx] == 'X') continue;
                            pq.emplace(nx, ny, x < 0, mp[ny][nx] - '0');
                        }
                    }
                }
            }
        }
        const int inf = 1 << 29;
        auto Cost = make_v(w, h, 2, inf);
        auto used = make_v(w, h, 2, false);
        int ans = -1;
        while (pq.size()) {
            Edge e = pq.top();
            pq.pop();
            if (used[e.x][e.y][e.foot]) continue;
            used[e.x][e.y][e.foot] = true;
            if (mp[e.y][e.x] == 'T') {
                ans = e.cost;
                break;
            }
            REP(x, 1, 4) {
                REP(y, -3, 4) {
                    if (x + abs(y) > 3) continue;
                    int nx = e.x + (2 * e.foot - 1) * x;
                    int ny = e.y + y;
                    if (nx < 0 || ny < 0 || nx >= w || ny >= h || mp[ny][nx] == 'X') continue;
                    int nc = mp[ny][nx] - '0';
                    if (mp[ny][nx] == 'T') {
                        nc = 0;
                    }
                    if (Cost[nx][ny][!e.foot] > e.cost + nc) {
                        Cost[nx][ny][!e.foot] = e.cost + nc;
                        pq.emplace(nx, ny, !e.foot, Cost[nx][ny][!e.foot]);
                    }
                }
            }
        }
        cout << ans << endl;
    }
    return 0;
}



Measured memory_bytes: 3152
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
#define fi first
#define se second
#define pb push_back
#define forn(i,n) for(int i=0;i<(n);i++)
#define for1(i,n) for(int i=1;i<=n;i++)
#define forr(i,n) for(int i=n;i>=0;i--)
#define all(x) x.begin(), x.end()
#define ar array
const int MAXN = 1e5 +5;

void fio(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}

vector<ar<int,4> > Q;
int n,m,q;
int an = 0;
vector <int> v;

void dfs(int u){
	if(v.size()==n){
		int ma = 0;
		for(auto z:Q)
			if(v[z[1]] - v[z[0]] == z[2])
					ma += z[3];
		an = max(an, ma);
		return;
	}
	for(int i = u; i<=m ;i++){
		v.pb(i);
		dfs(i);
		v.pop_back();
	}
}

int main(){
  fio();
  cin>>n>>m>>q;
  Q.resize(q);
  forn(i,q){
  	int a,b,c,d; cin>>a>>b>>c>>d;
  	a--,b--;
  	Q.pb({a,b,c,d});
  }
  dfs(1);
  cout<<an<<endl;
  return 0;
}

Measured memory_bytes: 3608
from fractions import gcd 
n,k = map(int,input().split())
a=k*(n//k)
if n >= k and n%k == 0:
    print(0)
elif n < k:
    print(min(abs(n-k),n))
else:
    print(min(abs(abs(n-a)-k),abs(n-a)))

Measured memory_bytes: 5600
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> P;
typedef vector<vector<int>> Matrix;
static const int INF = 2000000000;

int main(){
  int a, b, x;
  cin >> a >> b >> x;
  if (x >= a  && a + b >= x) cout << "YES\n";
  else cout << "NO\n";
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define maxn 100010
#define ll long long
int l[maxn],r[maxn];
main()
{
    int n;scanf("%d",&n);
    for(int i=1;i<=n;i++)scanf("%d%d",&l[i],&r[i]);
    sort(l,l+n+1,greater<int>());
    sort(r,r+n+1);
    ll ans=0;
    for(int i=0;i<=n;i++)ans+=2*max(0,l[i]-r[i]);
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		string[] str = Console.ReadLine().Split();
		long D = long.Parse(str[0]);
		long T = long.Parse(str[1]);
		long S = long.Parse(str[2]);
		string ans = "No";
		if(T*S>=D){
			ans = "Yes";
		}
		Console.WriteLine(ans);
	}
}

Measured memory_bytes: 17848
<?php
while (True) {  
  fscanf(STDIN, "%d %d", $h, $w);
  if ($h === 0 && $w === 0) {
    break;
  }
  if ($w % 2 === 0) {
    for ($i = 1; $i <= $h; $i++) {
      if ($i % 2 === 1) {
        echo str_repeat("#.", floor($w / 2))."\n";
      } else {
        echo str_repeat(".#", floor($w / 2))."\n";
      }
    }
  }
  if ($w % 2 === 1) {
    for ($i = 1; $i <= $h; $i++) {
      if ($i % 2 === 1) {
        echo str_repeat("#.", floor($w / 2))."#\n";
      } else {
        echo str_repeat(".#", floor($w / 2)).".\n";
      }
    }
  }
  echo "\n";
  unset($h);
  unset($w);
}


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

int main(){
  int i,j,cnt;
  int n;
  cin>>n;
  int s[n];
  for(i=0;i<n;i++)cin>>s[i];
  int sum=0;
  for(i=0;i<n;i++)sum+=s[i];
  if(sum%10!=0){
    cout<<sum;
    return 0;
  }
  int mi=INT_MAX;
  for(i=0;i<n;i++){
    if(s[i]%10!=0){
      mi=min(mi,s[i]);
    }
  }
  if(mi==INT_MAX)cout<<0;
  else cout<<sum-mi;
}

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

const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };

int bfs(const vector<string> &v,int H, int W, int x, int y) {
    vector<vector<int>> dist(H, vector<int>(W, -1));
    queue<pair<int,int>> que;

    int res = 0;
    que.push({x, y});
    dist[x][y] = 0;
    while (!que.empty()) {
        int x = que.front().first, y = que.front().second;
        res = max(res, dist[x][y]);
        que.pop();
        for (int dir = 0; dir < 4; ++dir) {
            int nx = x+ dx[dir], ny = y + dy[dir];
            if (nx < 0 || nx >= H || ny < 0 || ny >= W) continue;
            if (v[nx][ny] == '#') continue;
            if (dist[nx][ny] == -1) {
                dist[nx][ny] = dist[x][y] + 1;
                que.push({nx, ny});
            }
        }
    }
    return res;
}

int main(){

  int H,W;
  cin >> H >> W;

  vector<string> field(H);
  for (int h = 0; h < H; ++h) cin >> field[h];

  vector<vector<int> > dist(H, vector<int>(W, -1));
  int ans=0;

  rep(i,H)rep(j,W){
    if(field[i][j]=='#')continue;
    int d=bfs(field,H,W,i,j);
    ans=max(d,ans);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>

int main()
{
  int A, B, C, K;
  std::cin >> A >> B >> C >> K;
  int res;
  if (A >= K) res = K;
  else if (A + B >= K) res = A;
  else res = 2*A + B - K;
  std::cout << res << std::endl;
  return 0;
}

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

#define int long long

#define override_rep(i, l, r, mes, ...) mes
#define rep1(i, n) for (int i = 0; i < n; i++)
#define rep2(i, l, r) for (int i = l; i < r; i++)
#define rep(...) override_rep(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)

using namespace std;
using P = pair<int, int>;

template<typename T, typename U>
istream& operator>>(istream& in, pair<T, U>& p) {
    in >> p.first >> p.second;
    return in;
}

// https://twitter.com/vane11ope ←フォローしましょう
// (ノ)>◡<(ヾ)ﾓﾁﾓﾁ
signed main(signed argc, char* argv[]) {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    const int MOD = 1e9 + 7;

    int n, max_a = 0, pow2 = 1, ans = 0;
    cin >> n;

    map<int, int> mp;
    rep(i, n) {
        int a;
        cin >> a;
        max_a = max(max_a, a);
        mp[a]++;
    }

    while (max_a >= pow2) pow2 *= 2;

    for (auto now = mp.rbegin(); now != mp.rend(); now++) {
        while (now->first * 2 < pow2) pow2 /= 2;
        if(mp.count(pow2-now->first)==0)continue;
        if(pow2-now->first!=now->first) {
            int b = min(mp[now->first],mp[pow2 - now->first]);
            mp[pow2 - now->first] -= b;
            mp[now->first] -= b;
            ans += b;
        }
        else{
            int b=(int)(now->second)/2;
            mp[now->first]-=b*2;
            ans+=b;
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 12800
def main():
     from operator import mul
     from functools import reduce
 
     def cmb(n,r):
          r = min(n-r,r)
          if r == 0: return 1
          over = reduce(mul, range(n, n - r, -1))
          under = reduce(mul, range(1,r + 1))
          return over // under
     
     n,k=map(int,input().split())
     MOD=10**9+7
     for ks in range(1,k+1):
          if ks-1<=n-k:
               print((cmb(n-k+1,ks)%MOD)*(cmb(k-1,k-ks)%MOD)%MOD)
               
          else:
               print(0)
          
if __name__=='__main__':
     main()

Measured memory_bytes: 3944
import java.util.*;
public class Main{
	static Scanner s = new Scanner(System.in);
	public static void main(String[] args) {
		int sx=s.nextInt(),sy=s.nextInt(),tx=s.nextInt(),ty=s.nextInt(),
		x=sx,y=sy;
		ArrayDeque<Character> deque = new ArrayDeque<>(5000);
		//start
		for(;y<ty  ;y++) deque.add('U');
		for(;x<tx  ;x++) deque.add('R');
		//t1
		for(;y>sy  ;y--) deque.add('D');
		for(;x>sx  ;x--) deque.add('L');
		//s1
		x--;deque.add('L');
		for(;y<ty  ;y++) deque.add('U');
		y++;deque.add('U');
		for(;x<tx  ;x++) deque.add('R');
		y--;deque.add('D');
		//t2
		x++;deque.add('R');
		for(;y>sy  ;y--) deque.add('D');
		y--;deque.add('D');
		for(;x>sx  ;x--) deque.add('L');
		y++;deque.add('U');
		//s2
		System.out.println(deque.toString().replaceAll("[^DLRU]", ""));
	}
}

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
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 N, M, Q;
vector<int> a, b, c, d;
ll ans = 0;

void dfs(vector<int> &A, int flag) {
  // 終了条件
  if(A.size() == N) {
    ll tmp = 0;
    REP(i, Q) {
      if(A[b[i] - 1] - A[a[i] - 1] == c[i]) tmp += d[i]; 
    }
    if(ans < tmp) {
      ans = tmp;
    }
    return;
  }

  // 再帰
  int first;
  if(flag != 0) {
    first = flag;
  } else {
    first = 1;
  }
  for(int i = first; i <= M; ++i) {
    A.push_back(i);
    dfs(A, i);
    A.pop_back();
  }
}

int main() {
  cin >> N >> M >> Q;
  a.resize(Q); b.resize(Q); c.resize(Q); d.resize(Q);
  REP(i, Q) cin >> a[i] >> b[i] >> c[i] >> d[i];
  vector<int> A;
  dfs(A, 0);
  cout << ans << endl;
}


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

int main() {
  int a, b;
  cin >> a >> b;
  if (a % 2 != 0 && b % 2 != 0) {
    cout << "Odd" << endl;
  }
  else {
    cout << "Even" << endl;
  }
}

Measured memory_bytes: 256
#include <stdio.h>

int f[100];

int main(){
  int n, i;
  f[0] = f[1] = 1;
  scanf("%d", &n);
  for(i = 2; i <= n; ++i) f[i] = f[i - 1] + f[i - 2];
  printf("%d\n", f[n]);
  return 0;
}

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

int main() {
	ll ans=1<<30,a[109],sum=0;
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	for(int i=-100;i<=100;i++){
		sum=0;
		for(int j=0;j<n;j++){
			sum+=(a[j]-i)*(a[j]-i);
		}
		ans=min(ans,sum);
	}
	cout <<ans;
	return 0;
}

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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)
#define vvl(v,w,h,init) vector<vector<ll>> v(w,vector<ll>(h,init))
#define mp(a,b) make_pair(a,b)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using pii = pair<int,int> ;
using pll = pair<ll,ll> ;

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll q;
  string s = "000";
  cin >> q;
  rep(i,q){
    bool f = true;
    ll n = 0;
    cin >> s;
    set<ll> st;
    while(s.size() != 1){
      ll ans = -1;
      REP(k,1,s.size()){
        string l = s,r = s;
        l.resize(k);
        r = r.substr(k);
        ll n2 = ston(l,1) * ston(r,1);
        ans = max(ans,n2);
      }
      if(!st.insert(ans).se ){
        cout << -1 << endl;
        f = false;
        break;
      }
      else{
        s = to_string(ans);
      }
      ++n;
    }
    if(f)
    cout << n << endl;
  }
  return 0;
}

Measured memory_bytes: 3316
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        final Scanner sc = new Scanner(System.in);

        final int n = sc.nextInt();
        final int t = sc.nextInt();
        final int a = sc.nextInt();
        final int[] h = new int[n];
        for (int i = 0; i < n; i++) {
            h[i] = sc.nextInt();
        }

        int index = -1;
        double min = Integer.MAX_VALUE;
        for (int i = 0; i < n; i++) {
            final double x = t - h[i] * 0.006;
            final double near = Math.abs(a-x);
            if (near < min) {
                index = i;
                min = near;
            }
        }

        System.out.println(index+1);
    }
}


Measured memory_bytes: 22996
//Heaplax
#include<bits/stdc++.h>
#define LL long long
#define LOG(x) cerr<<#x<<" = "<<x<<endl
#define add_edge(u,v) nxt[++cnt]=head[u],head[u]=cnt,to[cnt]=v
#define open(x) freopen(#x".in","r",stdin),freopen(#x".out","w",stdout)
char ch;bool fs;void re(int& x)
{
	while(ch=getchar(),ch<33);
	if(ch=='-')fs=1,x=0;else fs=0,x=ch-48;
	while(ch=getchar(),ch>33)x=x*10+ch-48;
	if(fs)x=-x;
}
using namespace std;
bitset<2005> l[2005],r[2005],a[2005];//r[i]表示i作为右端点时那些左端点可行
int n;
char s[2005];
int main()
{
	re(n);
	for(int i=2;i<=n;++i)
	{
		scanf("%s",s+1);
		for(int j=1;j<i;++j)
		{
			if(s[j]=='1')a[i][j]=1;
			else a[j][i]=1;
		}
	}
	for(int i=1;i<=n;++i)l[i][i]=r[i][i]=1;
	for(int len=1;len<n;++len)
		for(int i=1;i<=n;++i)
		{
			if(i+len<=n && (r[i+len]&l[i+1]&a[i]).any())r[i+len][i]=1;
			if(i-len>=1 && (l[i-len]&r[i-1]&a[i]).any())l[i-len][i]=1;
		}
	printf("%d\n",(l[1]&r[n]).count());
}


Measured memory_bytes: 1920