akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <climits>

using namespace std;
using ll=long long;
struct Edge{
    int a, b, c;
};
struct Node{
    Node* parent;
    //vector<int> children;
    int cost;
    ll sum;
    //Node() : parent(-1),  children(vector<int>()), cost(0) {children.reserve(10);}
    Node() : parent(nullptr), cost(0), sum(-1LL) {}
};
void func(Node *ptr, Node *toptr, int cost){
    if(ptr==nullptr)
        return;
    Node *parent = ptr->parent;
    ptr->parent = toptr;
    int c = ptr->cost;
    ptr->cost = cost;
    func(parent, ptr, c);
}
ll calcCost(Node *ptr){
    if(ptr==nullptr)
        return 0LL;
    if(ptr->sum==-1){
        ptr->sum = ptr->cost+calcCost(ptr->parent);
        return ptr->sum;
    }else{
        return ptr->sum;
    }
}
int main(){//TLE
    int n;
    cin >> n;
    vector<Edge> edge(n-1);
    for(int i=0;i<edge.size();++i){
        cin >> edge[i].a >> edge[i].b >> edge[i].c;
        --edge[i].a, --edge[i].b;
    }
    int q, k;
    cin >> q >> k;
    --k;
    vector<int> x(q);
    vector<int> y(q);
    for(int i=0;i<q;++i){
        cin >> x[i] >> y[i];
        --x[i], --y[i];
    }
    vector<Node> node(n);
    for(Edge& e : edge){
        node[e.b].parent = &(node[e.a]);
        node[e.b].cost = e.c;
    }
    func(&(node[k]), nullptr, 0);
    for(int i=0;i<q;++i){
        cout << (calcCost(&(node[x[i]]))+calcCost(&(node[y[i]]))) << endl;
    }
    return 0;
}

Measured memory_bytes: 9216
import queue
import sys
def input():
    return sys.stdin.readline().rstrip('\n')
    

def calc(N, A):
    A.sort(key=lambda x: -x)
    q = queue.Queue()
    q.put(A[0])
    ans = 0
    for a in A[1:]:
        ans += q.get()
        q.put(a)
        q.put(a)
    return ans


N = int(input())
A = [int(s) for s in input().split()]
print(calc(N, A))


Measured memory_bytes: 111572
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		while(true){
			int m = sc.nextInt();
			int f = sc.nextInt();
			int r = sc.nextInt();
			
			if((m + f + r) == -3) {
				break;
			}else if(m == -1 || f == -1){
				System.out.println("F");
			}else if((m + f) >= 80){
				System.out.println("A");
			}else if((m + f) >= 65 && (m + f) < 80){
				System.out.println("B");
			}else if((m + f) >= 50 && (m + f) < 65){
				System.out.println("C");
			}else if((m + f) >= 30 && (m + f) < 50){
				if(r >= 50){
					System.out.println("C");
				}
				else System.out.println("D");
			}
			else System.out.println("F");
		}
	}
}


Measured memory_bytes: 26188
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#include <vector>
#include <cstring>
#include <queue>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using uld = unsigned long long;
using P = pair<int,int>;
ll MAX(ll a,ll b,ll c){return max(a,max(b,c));}
ll MIN(ll a,ll b,ll c){return min(a,min(b,c));}
const ll mod = 1e9+7;
const ll INF = 1e10;
const int dx[4] = {0,1,0,-1};
const int dy[4] = {1,0,-1,0};
template<class T> inline bool chmax(T &a,T& b){if(a < b){a = b; return true;} else return false;}
template<class T> inline bool chmin(T &a,T& b){if(a > b){a = b; return true;} else return false;}
int main(){
    int n;
    cin >> n;
    int AC=0,WA=0,TLE=0,RE=0;
    rep(i,n){
        string s;
        cin >> s;
        if(s == "AC"){
            AC++;
        }
        else if(s == "WA"){
            WA++;
        }
        else if(s == "TLE"){
            TLE++;
        }
        else{
            RE++;
        }
    }
    cout << "AC x " << AC << endl;
    cout << "WA x " << WA << endl;
    cout << "TLE x " << TLE << endl;
    cout << "RE x " << RE << endl;
}

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

using namespace std;
typedef long long ll;
typedef pair<int,int> PI;
const double EPS=1e-6;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define F first
#define S second
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define SZ(a) (int)((a).size())
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) a.rbegin(),a.rend()
#define FLL(a,b) memset((a),b,sizeof(a))
#define CLR(a) FLL(a,0)
#define declare(a,it) __typeof(a) it=(a)
#define FOR(it,a) for(declare(a.begin(),it);it!=a.end();++it)
#define FORR(it,a) for(declare(a.rbegin(),it);it!=a.rend();++it)
template<class T,class U> ostream& operator<< (ostream& o, const pair<T,U>& v){return o << "(" << v.F << ", " << v.S << ")";}
template<class T> ostream& operator<< (ostream& o, const vector<T>& v){o << "{";rep(i,SZ(v)) o << (i?", ":"") << v[i];return o << "}";}
int dx[]={0,1,0,-1,1,1,-1,-1};
int dy[]={1,0,-1,0,-1,1,1,-1};
int s2i(string& a){stringstream ss(a);int r;ss>>r;return r;}
int geti(){int n;scanf("%d", &n);return n;}

int w[200];
ll dp[20000];
const ll mod = 1e9 + 7;

ll modpow(ll p, ll n, ll mod){
  ll ret = 1;
  while(n){
    if(n&1) ret = (ret*p)%mod;
    p = p*p % mod;
    n >>= 1;
  }
  return ret;
}


ll inv(ll p, ll mod){// mod is prime
  return modpow(p, mod-2, mod);
}

ll fact[1000];
ll invf[1000];

ll com(ll n, ll k){
  return fact[n] * invf[k] % mod * invf[n-k] % mod;
}

int main(){
  fact[0] = 1;
  for(int i = 1; i < 1000; ++i){
    fact[i] = i*fact[i-1] % mod;
    invf[i-1] = inv(fact[i-1], mod);
  }
  
  
  int n,W;
  cin >> n >> W;
  for(int i = 0; i < n; ++i)
    cin >> w[i];
  ll ans = 0;
  sort(w, w+n);
  //ans += w[0] > W;
  reverse(w, w+n);
  
  dp[0] = 1;
  
  ll su = accumulate(w, w+n, 0);
  ans += su <= W;
  
  for(int i = 0; i < n;){
    int j = 0;
    while(i+j < n && w[i] == w[i+j]) ++j;
    su -= w[i] * j;

    for(int k = 1; k <= j; ++k){
      for(int tw = 0; tw <= W; ++tw){
        if(tw + (k-1)*w[i] + su <= W &&
           tw + (k)*w[i] + su > W)
          ans += dp[tw] * com(j,k-1) % mod;
      }
    }
    
    for(int tw = W; tw >= 0; --tw){
      for(int k = 1; k <= j; ++k){
        if(tw - k*w[i] >= 0)
          dp[tw] = (dp[tw] + dp[tw-k*w[i]] * com(j,k) % mod) %mod;
      }
    }
    
    
    ans %= mod;
    
    i += j;
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 1260
n = int(input())
#a,b=map(int,input().split()) #横並び
#x=[int(input()) for i in range(3)] #縦に並んだのを配列に
y=list(map(int,input().split())) #横に並んだのを配列に
#print("{:.9f}".format(a/b))
print('YNeos'[2*max(y)>=sum(y)::2])


Measured memory_bytes: 3068
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <tuple>
#include <queue>
#include <bitset>
#include <set>
#include <map>
#include <list>

using ll = long long;
using ld = long double;
using namespace std;
const int INF = 1e9+100;
const ll INF64 = 7e18l;
const int mod = 1000000007;
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(a) (a).begin(), (a).end()
#define FIN ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);


int main(){
    FIN;
    ll n;
    cin >> n;
    vector<ll> ans(4,0);
    for(ll i=0;i<n;i++){
        string s;
        cin >> s;
        if(s == "AC") ans[0]++;
        if(s == "WA") ans[1]++;
        if(s == "TLE") ans[2]++;
        if(s == "RE") ans[3]++;
    }

    cout << "AC x " << ans[0] << endl;
    cout << "WA x " << ans[1] << endl;
    cout << "TLE x " << ans[2] << endl;
    cout << "RE x " << ans[3] << endl;


    return 0;
}


Measured memory_bytes: 3668
#include <bits/stdc++.h>
typedef long long ll;
#define MOD 1000000007
#define INF -99999999 
using namespace std;
 
int main()
{
    int a,b; cin >> a >> b;
    int ab;
    if(b<=9) ab = 10*a + b;
    else if (b <= 99) ab = 100*a + b;
    else ab = 1000*a + b;
    for (int i = 0; i < 1000; i++)
    {
        if(ab == i*i){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 256
def main():
    import sys
    import math
    sys.setrecursionlimit(10**6)
    input = sys.stdin.readline
    A, B, H, M = [int(x) for x in input().strip().split()]
    hours = 2 * math.pi * (60 * H + M) / (60 * 12)
    minites = 2 * math.pi * M / 60
    Ax, Ay = A * math.sin(hours), A * math.cos(hours)
    Bx, By = B * math.sin(minites), B * math.cos(minites)
    print(((Ax-Bx)**2+(Ay-By)**2)**.5)
    
if __name__ == '__main__':
    main()

Measured memory_bytes: 9592
#include<iostream>
#include<cstdio>
#include<cmath>
#include<vector>
#include<list>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<string>
#include<utility>
#include<algorithm>
#include<functional>
#include<deque>
#include<string.h>
#include<ctype.h>
using namespace std;

int main(){
  char c[9];
  for (int i = 0; i < 9; i++){
    cin >> c[i];
  }
  printf("%c%c%c\n", c[0], c[4], c[8]);
  return 0;
}



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

int main() {
    int x, a, b;
    cin >> x >> a >> b;
    int A = abs(x - a);
    int B = abs(x - b);
    if (A < B) cout << 'A' << endl;
    else cout << 'B' << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<utility>
#include<string>
#include<stack>
#include<queue>
#include<set>
#include<math.h>
#include <map>
using namespace std;
typedef long long int ll;
#define repi(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,a) repi(i,0,a)
#define all(u) u.begin(),u.end()
#define pl pair<ll,ll>
#define f first
#define s second
#define mod 1000000007
#define inf 1<<30
#define mp(a,b) make_pair(a,b)
#define len(u,N) u.begin(),u.begin()+N

ll N;
vector<ll> p(100010);
vector<ll> data;

int main() {
    cin >> N;
    rep(i,N) cin >> p[i];
    ll temp = 0;
    rep(i,N){
        if (p[i] == i+1){
            temp++;
            if (i == N-1){
                data.push_back(temp);
            }
        }
        else {
            data.push_back(temp);
            temp = 0;
        }
    }
    ll res = 0;
    rep(i,data.size()){
        // cout << data[i] << " ";
        res += (data[i]+1)/2;
    }
    // cout << endl;
    cout << res << endl;
    
    return 0;
}


Measured memory_bytes: 2168
import java.util.Scanner;
public class Main
{
	public static void main(String arg[])
	{
		Scanner in=new Scanner(System.in);
		int m=in.nextInt();
		while(m-->0)
		{
			double f=in.nextInt();
			int y=in.nextInt();
			int n=in.nextInt();
			double ans=0;
			double res=0;
			for(int i=0;i<n;i++)
			{
				int ma=in.nextInt();
				double r=in.nextDouble();
				double de=in.nextDouble();
				double A=f;
				int B;
				
				if(ma==0)
				{
					double risi=0;
					for(int j=0;j<y;j++)
					{
						B=(int)(A*r);
						risi+=B;
						A-=de;
					}
					 res=A+risi;
				}
				else if(ma==1)
				{
					for(int j=0;j<y;j++)
					{
						B=(int)(A*r);
						A+=B-de;
					}
					 res=A;
				}
				ans=Math.max(ans, res);
			}
			System.out.println((int)ans);
		}
	}
}

Measured memory_bytes: 13000
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll>
#define cvector vector<char>
#define svector vector<string>
#define lque queue<ll>
#define lpque priority_queue<ll>
#define dlpque priority_queue<ll,lvector,greater<ll>>
#define P pair<ll,ll>
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define rep(i,n) for(ll i=0; i<n; ++i)
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n,ans=1000,val=0,pos=0;cin>>n;
  lvector A(n);rep(i,n) cin>>A[i];
  while(pos<n) {
    if(pos+1<n) {
      if(A[pos]>A[pos+1]) {
        ll pos_=pos+1;
        while(pos_+1<n&&A[pos_]>=A[pos_+1]) pos_++;
        if(pos_<n-1) {
          val=ans/A[pos_];
          ans-=A[pos_]*val;
        }
        pos=pos_;
      }
      else if(A[pos]<A[pos+1]){
        if(val==0) {
          val=ans/A[pos];
          ans-=A[pos]*val;
        }
        ll pos_=pos+1;
        while(pos_+1<n&&A[pos_]<=A[pos_+1]) pos_++;
        ans+=A[pos_]*val;
        pos=pos_;
      }
      else pos++;
    }
    else pos++;
  }
  print(ans);
  return 0;
}

Measured memory_bytes: 3656
import java.util.Scanner;

class Main {

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

        int a = sc.nextInt();
        int b = sc.nextInt();

        String[] s = new String[a];
        for (int i = 0; i < a; i++) {
            s[i] = sc.next();
        }
        String n = "#";
        for (int i = 0; i <= b + 1; i++) {
            System.out.print(n);
        }
        System.out.println("");
        for (int i = 0; i < a; i++) {
            System.out.print(n);
            System.out.print(s[i]);
            System.out.println(n);
        }
        for (int i = 0; i <= b + 1; i++) {
            System.out.print(n);
        }
        System.out.println("");

    }
}

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

using namespace std;

int n, t, e;
int x[111111];
long long f[111111], g[111111];

int main(){
//	freopen("input.inp", "r", stdin);
	scanf("%d%d%d",&n,&e,&t);
	for(int i = 1; i <= n; ++i) scanf("%d",&x[i]);
	int p = 0;
	g[0] = - 2 * x[1];
	for(int i = 1; i <= n; ++i){
		while (2ll * (x[i] - x[p + 1]) > t) ++p;
		f[i] = f[p] + t;
		if (p) f[i] = min(f[i], g[p - 1] + 2 * x[i]);
		g[i] = min(f[i] - 2 * x[i + 1], g[i - 1]);
	}
	printf("%lld",f[n] + e);
	return 0;
}

Measured memory_bytes: 2176
import java.util.*;

public class Main {
    static int n, m;
    static int[] l, r, d;
    static String s;
    static int modP = 1000000007;
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        n = in.nextInt();
        m = in.nextInt();
        l = new int[m];
        r = new int[m];
        d = new int[m];

        Map<Integer, List<E>> map = new HashMap<>();

        for(int i = 0; i < m; i++) {
            l[i] = in.nextInt();
            r[i] = in.nextInt();
            d[i] = in.nextInt();
            E e = new E(l[i], r[i], d[i]);
            List<E> leftList = map.containsKey(l[i]) ? map.get(l[i]) : new LinkedList<E>();
            leftList.add(e);
            map.put(l[i], leftList);

            List<E> rightList = map.containsKey(r[i]) ? map.get(r[i]) : new LinkedList<E>();
            rightList.add(e);
            map.put(r[i], rightList);
        }

        int[] line = new int[n+1];
        boolean[] visited = new boolean[n+1];

        List<E> init = new LinkedList<E>();
        E e = new E(0, 1, 0);
        init.add(e);
        map.put(0, init);
        visited[0] = true;

        for(int i = 0; i < n + 1; i++) {
            if(!visited[i]) {
                if(!checkAndPadding(i, line[i], visited, line, map)) {
                    System.out.println("No");
                    return;
                }
            }
        }

        System.out.println("Yes");
    }

    static boolean checkAndPadding(int id, int position, boolean[] visited, int[] line, Map<Integer, List<E>> map) {
        if(visited[id]) return line[id] == position;

        line[id] = position;
        visited[id] = true;

        if(!map.containsKey(id)) return true;

        List<E> list = map.get(id);
        for(E e : list) {
            int targetId, targetPos;
            if(e.l == id) {
                targetId = e.r;
                targetPos = line[id] + e.d;
            }else{
                targetId = e.l;
                targetPos = line[id] - e.d;
            }

            if(visited[targetId]) {
                if (line[targetId] != targetPos){
                    return false;
                }
            }else{
                if(!checkAndPadding(targetId, targetPos, visited, line, map)) {
                    return false;
                }
            }
        }

        return true;
    }
}

class P {
    int x, y;
    P(int x, int y) {
        this.x = x;
        this.y = y;
    }
}

class E {
    int l, r, d;
    E(int l, int r, int d) {
        this.l = l;
        this.r = r;
        this.d = d;
    }
}

Measured memory_bytes: 190028
a, b, c, d = [int(e) for e in input().split()]

def gcd(a, b):
  while True:
    t = b % a
    if t == 0:
      return a
    b, a = a, t

def f(a, b, n):
  x = (a // n) * n
  if x < a:
    x += n
  if x > b:
    return 0
  result = 0
  if a <= x <= b:
    result += 1
  result += (b - x) // n
  return result

acc = 0
acc += f(a, b, c)
acc += f(a, b, d)
acc -= f(a, b, c * d // gcd(c, d))
print(b - a + 1 - acc)


Measured memory_bytes: 3064
#include"bits/stdc++.h"
using namespace std;
using ll = int64_t;

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

    vector<vector<char>> table(10, vector<char>());
    table[1].push_back('.');
    table[1].push_back(',');
    table[1].push_back('!');
    table[1].push_back('?');
    table[1].push_back(' ');
    for (int i = 2; i <= 7; i++) {
        for (int j = 0; j < 3; j++) {
            table[i].push_back('a' + (i - 2) * 3 + j);
        }
    }
    table[7].push_back('s');
    table[8].push_back('t');
    table[8].push_back('u');
    table[8].push_back('v');
    table[9].push_back('w');
    table[9].push_back('x');
    table[9].push_back('y');
    table[9].push_back('z');


    for (int i = 0; i < L; i++) {
        string s;
        cin >> s;

        int kind = -1, num = -1;
        for (char c : s) {
            if (c == '0') {
                if (kind != -1) {
                    printf("%c", table[kind][num % table[kind].size()]);
                }
                kind = -1;
                num = -1;
            } else {
                kind = c - '0';
                num++;
            }
        }
        cout << endl;
    }
}


Measured memory_bytes: 3120
// A.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <set>
#include <map>
#include <vector>

using namespace std;

int main(int argc, char* argv[]) {
	int n;
	cin >> n;
	vector<int> a(n);
	map<int, int> m;
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
		m[a[i]] += 1;
	}
	set<int> s(a.begin(), a.end());
	vector<int> v(n);
	for (int t = 0; t < 500; ++t) {
		int ar = rand() % n, br = rand() % n;
		if (ar == br) continue;
		int p = a[ar];
		int q = a[br];
		int x = p ^ q;
		if (s.find(x) != s.end()) {
			map<int, int> r = m;
			r[p] -= 1;
			r[q] -= 1;
			r[x] -= 1;
			if (r[x] >= 0) {
				v[0] = p;
				v[1] = q;
				v[2] = x;
				int i;
				for (i = 3; i < n; ++i) {
					x = v[i - 2] ^ v[i - 1];
					v[i] = x;
					r[x] -= 1;
					if (r[x] < 0) {
						break;
					}
				}
				if (i >= n && (v[0] == (v[1] ^ v[n - 1]))) {
					cout << "Yes" << endl;
					return 0;
				}
			}
		}
	}
	cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 8064
import java.util.Scanner;
 
public class Main {
 
    public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();// 人数
      	int[] height =new int[n];//身長
      	int max=0;//自分より前の最大身長
      	long sum=0;
      
      	for(int i=0;i<n;i++){
          height[i] = sc.nextInt();
        }
      
      	max=height[0];
      	for(int i=0;i<n;i++){
          if(max<=height[i]){
            max=height[i];
          }
          sum+=max-height[i];
        }
      	System.out.println(sum);
    } 
}























Measured memory_bytes: 60456
#include <iostream> // cin, cout, cerr, clog
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota, accumulate, inner_product
#include <cstdio> // printf, scanf
#include <climits> // INT_MIN, LLONG_MIN
#include <cmath> // long, trig, pow
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <stack> // stack
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <unordered_map> // hashed by keys
#include <unordered_set> // hashed by keys
#include <iomanip> // cout<<setprecision(n)

#define rep(i,n) for(int i = 0; i < n; i++)
#define ENDL "\n"
#define print(i) std::cout << (i) << "\n"

#define int long long // at least int64 > 9*10^18
#define all(v) v.begin(), v.end()

#define MOD 1000000007

signed main() {
	int h,w;
	std::cin >> h >> w;
	std::vector<std::string> grid(h);
	rep(i,h) std::cin >> grid[i];
	std::vector<std::vector<int> > dp(h+1,std::vector<int>(w+1,0));
	dp[1][1]=1;
	rep(i,h) rep(j,w) {
		if(i==0&&j==0) continue;
		if(grid[i][j]=='#') continue;
		dp[i+1][j+1] = (dp[i][j+1]+dp[i+1][j])%MOD;
	}
	print(dp[h][w]);
	return 0;
}


Measured memory_bytes: 9216
#include <iostream>
#include <string>
#include <vector>
#include <cctype>
#include <algorithm>
#include <functional>
#include <cmath>
#include <string>
#include <cstring>
#include <vector>
#include <numeric>
#include <iomanip>
#include <limits>
#include <sstream>
#include <bitset>
#include <set>
	
#define roop(i, n) for(int i=0;i<n;i++)
#define DIV 1000000007
#define MOD ((int)1e9+7)
//static const long double pi = 3.1415926535897932;
	
using namespace std;
using ll = long long int;
using ull = unsigned long long;
	
char toSmall(char c) { // 大文字を小文字へ
	return (c + 0x20);
}
	
char toLarge(char c) { // 小文字を大文字へ
	return (c - 0x20);
}
	
float myPower(int a, int n) { // aのn乗の計算
	float x = 1;
	while (n > 0) { // 全てのbitが捨てられるまで
		if ( n & 1) { // 一番右のbitが１のとき
			x *= a;
		}
		a *= a;
		n >>= 1; // bit全体を右に1つシフトして一番右を捨てる
	}
	return x;
}
	
struct Combination {
	const int num=51e4;			//要素数
	const int mod=1e9+7;
	vector<ll> fact,inv,finv; //階乗,逆元,逆元の階乗.
	
	Combination():fact(num),inv(num),finv(num){
		fact[0]=fact[1]=1;
		inv[1]=1;
		finv[0]=finv[1]=1;
		for(int i=2;i<num;++i){
			fact[i]=fact[i-1]*i%mod;
			inv[i]=mod-inv[mod%i]*(mod/i)%mod;
			finv[i]=finv[i-1]*inv[i]%mod;
		}
	}
	
	int nCk(int n,int k){
		if(n<k) return 0;
		if(n<0 or k<0) return 0;
		return fact[n]*(finv[k]*finv[n-k]%mod)%mod;
	}
	int big_nCk(int n,int k){ //nが大きいとき
		ll res=1LL;
		for (int i = 0; i < k; i++) {
			res=res*(n-i)%mod;
		}
		res = res*finv[k]%mod;
		return res;
	}
	int nHk(int n,int k){return nCk(n+k-1,n-1);}//重複組み合わせ.
};
	
vector<string> split(const string& src, const char* delim = ",") { //カンマ区切り
	vector<string> vec;
	string::size_type len = src.length();
	
	for (string::size_type i = 0, n; i < len; i = n + 1) {
		n = src.find_first_of(delim, i);
		if (n == string::npos) {
			n = len;
		}
		vec.push_back(src.substr(i, n - i));
	}
	
	return vec;
}
	
bool check_int(string str)
{
	if (all_of(str.cbegin(), str.cend(), [](char ch) { return isdigit(ch);}))
	{
		return true;
	}
	return false;
}
	
struct rest {
	string s;
	int p;
	int num;
	
	/* -------------------------------------
	sort関数を使用したときのソートの定義をする。
	まずは文字列sでソートする。
	文字列sが同じだった場合、pでソートする。
	この条件を参考演算子で表現(ifでもOK)
	-------------------------------------*/
	bool operator<(const rest& right) const {
		return s == right.s ? p > right.p : s < right.s;
	}
};
	
ll pow_mod(ll n, ll k, ll p) { // n^k(mod p)
	if (k == 0) {
		return 1;
	}
	ll res = pow_mod(n * n % p, k / 2, p);
	if (k & 1) {
		res = res * n % p;
	}
	return res;
}
	
bool vector_finder(std::vector<int> vec, int number) { // vector 内にnumberがあるかどうか
	auto itr = std::find(vec.begin(), vec.end(), number);
	size_t index = std::distance( vec.begin(), itr );
	if (index != vec.size()) { // 発見できたとき
		return true;
	}
	else { // 発見できなかったとき
		return false;
	}
}

int main() {
	int n;
	cin >> n;
	set<int> st;
	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		st.insert(a);
	}
	cout << st.size() << endl;
	return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include<iomanip>
#include<algorithm>
using namespace std;
int main(){
  int N;
  cin>>N;
  double a[100];
  for(int j=0; j<N; j++){
      cin>>a[j];
  }
  double sum=0.0;
  sort(a,a+N);
  
  for(int i=0; i<N; i++){
     sum=sum+a[N-1]/a[i];
  }
  cout<<fixed<<setprecision(7)<<(1/sum)*a[N-1];
  return 0;
}  
  
  

Measured memory_bytes: 256
//teja349
#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip> 
//setbase - cout << setbase (16); cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 << endl; prints xxx77
//setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx
//cout.precision(x)  cout<<fixed<<val;  // prints x digits after decimal in val

using namespace std;
#define f(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define vl vector< ll >
#define ss second
#define ff first
#define ll long long
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod (1000*1000*1000+7)
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >

//std::ios::sync_with_stdio(false);   
vi vec;
set<int> set2;
vector<vi> adj(123456);
int p[123456],visit[123456];
int dfs(int cur){
	visit[cur]=1;
	vec.pb(cur);
	set2.insert(p[cur]);
	int i;
	rep(i,adj[cur].size()){
		if(!visit[adj[cur][i]]){
			dfs(adj[cur][i]);
		}
	}
	return 0;
}
int cnt(){
	int i;
	int haha=0;
	rep(i,vec.size()){
		if(set2.find(vec[i])!=set2.end()){
			haha++;
		}
	}
	return haha;
}
int main(){
    std::ios::sync_with_stdio(false);
    int n,m;
    cin>>n>>m;
    int i,u,v,ans=0;
    rep(i,n){
    	cin>>p[i];
    	p[i]--;
    }
    rep(i,m){
    	cin>>u>>v;
    	u--;
    	v--;
    	adj[u].pb(v);
    	adj[v].pb(u);
    }
    rep(i,n){
    	if(!visit[i]){
    		vec.clear();
    		set2.clear();
    		dfs(i);
    		ans+=cnt();
    	}
    }
    cout<<ans<<endl;
    return 0;  
    
}



Measured memory_bytes: 14200
package main

import (
	"fmt"
)

func main() {
	var N, H, W int
	fmt.Scanf("%d%d%d", &N, &H, &W)
	ans := 0
	for i := 0; i < N; i++ {
		var A, B int
		fmt.Scanf("%d%d", &A, &B)
		if H <= A && W <= B {
			ans++
		}
	}
	fmt.Printf("%d\n", ans)
}


Measured memory_bytes: 640
object Main extends App {
    val input = readLine
    val a = input.split(" ")(0)
    val b = input.split(" ")(1)
    val num = (a + b).toInt
    val sqrt_double = Math.sqrt(num)
    val sqrt_int = sqrt_double.toInt
    val res = if(sqrt_int * sqrt_int - num == 0){"Yes"}else{"No"}
    println(res)
}


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

int main() {
  string s;
  cin >> s;
  int n = s.size();
  int a = 0,b = 0,c = 0;
  rep(i,n){
    if(s[i] == 'a') a++;
    if(s[i] == 'b') b++;
    if(s[i] == 'c') c++;
  }
  if(n%3 != 0){
    if(a <= n/3+1 && b <= n/3+1 && c <= n/3+1) cout << "YES" << endl;
    else cout << "NO" << endl;
  }
  else{
    if(a <= n/3 && b <= n/3 && c <= n/3) cout << "YES" << endl;
    else cout << "NO" << endl;
  }
}

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

int main() {
  int n; cin >> n;
  string s; cin >> s;

  int c[2] = {};
  for (int i = 0; i < n; i++) {
    if (s[i] == '(') c[0]++;
    else {
      if (c[0] > 0) c[0]--;
      else c[1]++;
    }
  }

  for (int i = 0; i < c[1]; i++) cout << '(';
  cout << s;
  for (int i = 0; i < c[0]; i++) cout << ')';
  cout << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <cmath>
#include <queue>
#include <numeric>
#include <climits>
#include <iterator>
#include <iomanip>
#include <stack>
#include <set>
#include <cstdio>
#include <bitset>
#include <functional>
#include <tuple>
#include <list>
#include <deque>
using namespace std;
typedef pair<int, int> P;

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

typedef long long ll;
typedef vector<int> VI;

ll a[1010];
int main() {
    cin.tie(0);
   	ios::sync_with_stdio(false);
    
    int n; cin >> n;
    REP(i, n) cin >> a[i];
    int q; cin >> q;
    
    REP(i, q){
        int b, e, k; cin >> b >> e >> k;
        int cnt=0;
        for(int j=b; j<e; ++j) if(a[j]==k) cnt++;
        cout << cnt << endl;
    }
	return 0;
}


Measured memory_bytes: 3224
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/detail/standard_policies.hpp>

using namespace std;
using namespace __gnu_pbds;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define long long long 

typedef trie<string,null_type,trie_string_access_traits<>,pat_trie_tag,trie_prefix_search_node_update> pref_trie;
typedef tree<long int,null_type,less<long int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef cc_hash_table<long int,long int, hash<long int>, equal_to<long int>, direct_mask_range_hashing<long int>, 
hash_standard_resize_policy<hash_exponential_size_policy<>, hash_load_check_resize_trigger<true>, true>> ht;


void DFS(long int idx,long int par, vector<vector<long int>> &g, unordered_set<long int> &visited, ht &distance){
	visited.insert(idx);
	distance[idx] = distance[par] + 1;
	for(auto ele : g[idx]){
		if(visited.find(ele) == visited.end()){
			DFS(ele,idx,g,visited,distance);
		}
	}
}

int main(){
   IOS;
 //    #ifndef ONLINE_JUDGE
 //        freopen("in.txt",  "r",  stdin);
 //        freopen("out.txt", "w", stdout);
 //    #endif
 
   long int n,u,v;
   cin>>n>>u>>v;

   vector<vector<long int>> g(n);
   for(long int i = 1; i < n; i++){
   	long int x,y;
   	cin>>x>>y;
   	g[x-1].push_back(y-1);
   	g[y-1].push_back(x-1);
   }

   ht distance1,distance2;
   unordered_set<long int> visited;
   distance1[-1] = distance2[-1] = -1;

   DFS(u-1,-1,g,visited,distance1);

   visited.clear();
   	
   DFS(v-1,-1,g,visited,distance2);

   long int ans = 0;

   // for(auto ele : distance2)
   // 	cout<<ele<<" ";
   // cout<<endl;

   for(long int i = 0; i < n; i++){
   	if(distance1[i] < distance2[i]){
   		ans = max(ans,distance2[i] - 1);
   	}
   }

   cout<<ans;

   return 0;
}

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

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int a,b; cin >> a >> b;
	if (a>9||b>9) cout << -1 << endl;
		else cout << (a*b) << endl;
	return 0;
}


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

#define MAX 1000000

int main(void) {
  long long int n;
  scanf("%lld", &n);

  long long int factors[MAX];
  long long int pointer = 0;
  for (long long int i = 2; i * i <= n; i++) {
    if (pointer > MAX) {
      printf("over\n");
      break;
    } else {
      factors[pointer] = 0;
    }
    while (!(n % i)) {
      factors[pointer]++;
      n /= i;
      if (n % i) pointer++;
    }
  }

  // printf("%lld\n", pointer);
  long long int result = 0;
  for (long long int i = 0; i < pointer; i++) {
    long long int count = factors[i];
    // printf("count: %lld\n", count);
    for (long long int j = 1; j <= count; j++) {
      result++;
      count -= j;
    }
  }
  if (n != 1) result++;

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

  return 0;
}


Measured memory_bytes: 1736
import numpy as np
a,b,x=map(int,input().split())

c=2*x/(a*b)
if c<=a:
    print(np.arctan(b/c)*180/np.pi)
else:
    b1=2*b-2*x/a**2
    print(np.arctan(b1/a)*180/np.pi)

Measured memory_bytes: 18588
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    A, B = LI()

    if (A - B) % 2 == 0:
        print((A + B) // 2)
    else:
        print('IMPOSSIBLE')

if __name__ == '__main__':
    resolve()


Measured memory_bytes: 9940
#include<iostream>
#include<algorithm>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
static const int MAX = 100;

int main(){
    int A[MAX], n;

    cin >> n;
    rep(i, n) cin >> A[i];
  
  	rep(k, n){
        if(k > 0) printf(" ");
    	printf("%d", A[k]);
    }
    printf("\n");

    int j , v;
    
    rep2(i, 1, n){
        v = A[i];
        j = i - 1;

        while(j >= 0 && A[j] > v){
            A[j+1] = A[j];
            j--;
        }

        A[j+1] = v;
        
        rep(k, n){
            if(k > 0) printf(" ");
          	printf("%d", A[k]);
        }
      	printf("\n");
    }
}


Measured memory_bytes: 3208
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
#define tll tuple<ll, ll, ll>
#define all(c) c.begin(),c.end()

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
 
const ll inf = 1000000001;
const ll INF = 1e18;
const ll MOD = 1000000007;

char albt[26] = {'a','b','c','d','e','f','g','h','i','j','k','l',
                 'm','n','o','p','q','r','s','t','u','v','w','x',
                 'y','z'};

//vector<ll> g[202020];
//fill(score, score+202020, 0);
//vector<ll> v[505];

int main(){
  string s, t;
  cin >> s >> t;
  ll ans = 0;
  for (int i=0;i<3;i++){
    if (s[i] == t[i]) ans += 1;
  }
  
  
  cout << ans << endl;
}

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

using namespace std;

#define DUMP(x) std::cerr << (#x) << " = " << (x) << "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP(i, k, n) for (int i = (k); i < (int)(n); ++i)
#define ALL(r) r.begin(), r.end()
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define IMP cout << "IMPOSSIBLE" << endl
#define Imp cout << "Impossible" << endl
#define imp cout << "impossible" << endl
#define M1 cout << "-1" << endl
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

template <typename T>
ostream &operator<<(ostream &os, vector<T> &v)
{
    os << "{";
    rep(i, v.size()) os << v[i] << (i == (int)v.size() - 1 ? "" : ", ");
    os << "}";
    return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, pair<T, U> &p)
{
    os << "(" << p.first << ", " << p.second << ")";
    return os;
}
template <typename T>
T dup(T x, T y)
{
    return (x + y - 1) / y;
};
template <typename A, size_t N, typename T>
inline void arrayFill(A (&array)[N], const T &val) { std::fill((T *)array, (T *)(array + N), val); }
struct in
{
    const size_t n = 0;
    in() = default;
    in(size_t n) : n(n){};
    template <typename T>
    operator T()
    {
        T ret;
        cin >> ret;
        return ret;
    }
    template <typename T>
    operator vector<T>()
    {
        assert(n != 0);
        vector<T> ret(n);
        for (auto &x : ret)
            cin >> x;
        return ret;
    }
};

using ll = int64_t;
using vint = vector<int32_t>;
using vvint = vector<vint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pint = pair<int32_t, int32_t>;
using vpint = vector<pint>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
using setint = set<int32_t>;
using setstr = set<string>;
using qint = queue<int32_t>;
using qpint = queue<pint>;

constexpr std::int32_t INF = 1001001001;
constexpr std::int64_t LINF = 1001001001001001001;

void Main()
{
    string s;
    cin >> s;
    cout << string(s.size(), 'x') << endl;
}

signed main()
{
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 764
// use std::ops::{Index, IndexMut};
// use std::cmp::{Ordering, min, max};
// use std::collections::{BinaryHeap, BTreeMap};
// use std::collections::btree_map::Entry::{Occupied, Vacant};
// use std::clone::Clone;

fn getline() -> String {
    let mut res = String::new();
    std::io::stdin().read_line(&mut res).ok();
    res
}

macro_rules! readl {
    ($t: ty) => {
        {
            let s = getline();
            s.trim().parse::<$t>().unwrap()
        }
    };
    ($( $t: ty),+ ) => {
        {
            let s = getline();
            let mut iter = s.trim().split(' ');
            ($(iter.next().unwrap().parse::<$t>().unwrap(),)*)
        }
    };
}

macro_rules! readlvec {
    ($t: ty) => {
        {
            let s = getline();
            let iter = s.trim().split(' ');
            iter.map(|x| x.parse().unwrap()).collect::<Vec<$t>>()
        }
    }
}

macro_rules! debug {
    ($x: expr) => {
        println!("{}: {:?}", stringify!($x), $x)
    }
}

fn printiter<'a, T>(v: &'a T)
where
    &'a T: std::iter::IntoIterator,
    <&'a T as std::iter::IntoIterator>::Item: std::fmt::Display,
{
    for (i, e) in v.into_iter().enumerate() {
        if i != 0 {
            print!(" ");
        }
        print!("{}", e);
    }
    println!("");
}

struct ContestPrinter {
    s: String,
}

impl ContestPrinter {
    fn new() -> ContestPrinter {
        ContestPrinter { s: String::new() }
    }

    fn print<T>(&mut self, x: T)
    where
        T: std::fmt::Display,
    {
        self.s.push_str(format!("{}", x).as_str());
    }

    fn println<T>(&mut self, x: T)
    where
        T: std::fmt::Display,
    {
        self.s.push_str(format!("{}\n", x).as_str());
    }
}

impl std::ops::Drop for ContestPrinter {
    fn drop(&mut self) {
        print!("{}", self.s);
    }
}

fn main() {
    let mut printer = ContestPrinter::new();
    let n = readl!(usize);
    let mut a = readlvec!(i32);
    a.sort();
    a.reverse();
    let mut sum = [0, 0];
    for i in 0..n {
        sum[i%2] += a[i];
    }
    printer.println(sum[0]-sum[1]);
}


Measured memory_bytes: 4352
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.bigint, std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen)  return _RDA!T(_f, fix); else return _RDA!T(fix); }

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; }

void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }

long mod = 10^^9 + 7;
//long mod = 998_244_353;
//long mod = 1_000_003;
void moda(T)(ref T x, T y) { x = (x + y) % mod; }
void mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(T)(ref T x, T y) { x = (x * y) % mod; }
void modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }
void modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }

void main()
{
	auto X = RD;

	long ans;
	if (X < 600)
		ans = 8;
	else if (X < 800)
		ans = 7;
	else if (X < 1000)
		ans = 6;
	else if (X < 1200)
		ans = 5;
	else if (X < 1400)
		ans = 4;
	else if (X < 1600)
		ans = 3;
	else if (X < 1800)
		ans = 2;
	else
		ans = 1;

	writeln(ans);
	stdout.flush;
	debug readln;
}


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

int n, a[100];
signed main() {
 cin.tie(0);
 ios::sync_with_stdio(false);

  while (1) {
		cin >> n;
		if (n == 0) break;

		int ans = 0;
		for (int i = 0; i < n; i++) 
			cin >> a[i];
		for (int i = 0; i < n-1; i++) {
			for (int j = 0; j < n-1-i; j++) {
				if (a[j] > a[j+1]) {
					swap(a[j], a[j+1]);
					ans++;
				}
			}
		}
		cout << ans << endl;
	}
  return 0;
}





Measured memory_bytes: 3072
def e(x,y):
 A[y][x]='0'
 for d in range(-3,4):
  s,t=x+d,y+d
  0<=s<8and A[y][s]=='1'and e(s,y)
  0<=t<8and A[t][x]=='1'and e(x,t)
for i in range(int(input())):
 print(f'Data {i+1}:')
 input()
 A=[list(input())for _ in[0]*8]
 e(int(input())-1,int(input())-1)
 for r in A:print(*r,sep='')


Measured memory_bytes: 5632
#include <iostream>
#include <ccomplex>
#include <vector>
#include <cassert>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <numeric>
#include <list>
#include <assert.h>
#include <math.h>
#include <valarray>
#include <stdio.h>
#include <algorithm>
#include <set>
#include <complex>
#include <list>
#include <time.h>
#include <stack>
#include <locale>
#include <clocale>
#include <ctype.h>
#include <wchar.h>
#include <random>
#include <vector>
#include <unordered_map>
#include <bitset>

using namespace std;
typedef long long int LL;
typedef long long int ll;
typedef pair<long long int, long long int> pii;
typedef pair<double, double> pdd;

#define SORT(c) sort((c).begin(),(c).end())
#define BACKSORT(c) sort((c).begin(),(c).end(),std::greater<LL>())
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SP << " " <<

LL mod = 998244353;

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

  LL a, b, c;
  cin >> a >> b >> c;
  if (a+b==c||a+c==b||c+b==a){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
'''
.append(要素) リストに要素を追加
.extend(リスト) リストを連結する
.insert(場所,要素) 指定した場所に要素追加
del 配列名[場所]
-1で末尾で末尾から一つ前
sort()
sorted(reverse=true)
配列の初期化
配列名=[a]*n+[b]*m
Decimal()
'''

from sys import stdin
from itertools import accumulate, dropwhile, takewhile, groupby
import bisect
import copy
import math
from functools import reduce
from operator import mul
from collections import Counter
import itertools
import fractions
import sys
num = int(stdin.readline().rstrip())
a = int(num/1000)+1
res = (a*1000-num) % 1000
print(res)


Measured memory_bytes: 72760
#include<iostream>
using namespace std;
int main(){
    int dp[10001]={0};
    int N,W;
    cin>>N>>W;
    int v,w;
    for(int i=0;i<N;i++){
        cin>>v>>w;
        for(int j=0;j<=W;j++){
            if(j>=w){
                dp[j] = max(dp[j-w]+v,dp[j]);
            }
        }
    }
    cout<<dp[W]<<endl;
    return 0;
}


Measured memory_bytes: 3140
N = int(input())
T = list(map(int, input().split()))
M = int(input())
P = [0] * M
X = [0] * M
for i in range(M):
	P[i], X[i] = map(int, input().split())
for j in range(M):
	tmp = T[P[j] - 1] - X[j]
	print(sum(T) - tmp)


Measured memory_bytes: 3060
n=int(input())
ans={}
for i in range(n):
    s=input()
    ans[s]=ans.get(s,0)+1
m=int(input())
for i in range(m):
    t=input()
    ans[t]=ans.get(t,0)-1
print(max(ans.values()) if max(ans.values())>0 else 0)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define ll long long
#define MIN INT_MIN
#define MAX INT_MAX
#define PB push_back
#define MP make_pair
#define rep(j,n,jj) for(int i=j;i<n;i+=jj)
#define modd 1000000007
using namespace std;
void solve();
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    time_t start,end;
    time(&start);
    solve();
    time(&end);
    double t= double(end - start); 
/*    cout << fixed */
/*         << t<< setprecision(5)<<endl;*/
    return 0; 
}

void solve(){
	int n,m;
	cin>>n>>m;
	int ans=0;
	rep(0,m,1){
		int x;
		cin>>x;
		ans+=x;
	}
	if(ans<=n){
		cout<<n-ans<<"\n";
	}
	else{
		cout<<-1<<"\n";
	}
	
}

Measured memory_bytes: 3632
#include <stdio.h>

int main(){
    int x,y;
    int tmp;
    
    while (1){
        scanf("%d %d",&x,&y);
        if (x == 0 && y ==0){
            break;
        }
        
        if ( x > y){
            tmp = y;
            y = x;
            x = tmp;
        }
        
        printf("%d %d\n",x,y);
    }
    return 0;
}

Measured memory_bytes: 600
package main

import "fmt"
import "sort"

func main(){
	var N int64
	var x int64
	var a [100]float64
	var count int

	fmt.Scan(&N, &x)
	b := make([]float64, int(N), 1000)
	for i := 0 ; i < int(N) ; i++{
		fmt.Scan(&a[i])
	}

	for i := 0 ; i < int(N) ; i++ {
		b[i] = a[i]
	}
	sort.Float64s(b)

	for i := 0 ; i < int(N) ; i++{
		if int64(b[i]) <= x{
			count++
		}
		x = x - int64(b[i])
	}
	if count > 0 && x > 0 {
		count--
	}
	// fmt.Println(b)
	fmt.Println(count)
}

Measured memory_bytes: 512
using System;
using System.Collections.Generic;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            List<string> inputStling = new List<string>();

            string[] input = Console.ReadLine().Split(' ');
            int inputNumber = int.Parse(input[0]);
            int inputLength = int.Parse(input[1]);

            for(int i = 0; i <= inputNumber - 1; i++)
            {
                inputStling.Add(Console.ReadLine());
            }

            inputStling.Sort();

            string[] inputStringSorted = inputStling.ToArray();
            string outputString = string.Empty;
            for (int i = 0; i <= inputNumber - 1; i++)
            {
                outputString = outputString + inputStringSorted[i];
            }

            Console.WriteLine(outputString);
        }
    }
}


Measured memory_bytes: 13408
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
using namespace std;
#define MAX 300000
typedef long long ll;



int main(){
  ll N,data,a,ans;
  cin>>N;
  for(int i=0;i<5;i++){
    cin>>data;
    if(i==0) a=data;
    a=min(a,data);
  }
  ans=(N+a-1)/a+4;
  cout<<ans<<endl;
  
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define _repargs(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _repargs(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p = 0) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template


int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    int D;
    cin >> D;
    vector<ll> C(26);
    rep(i, 26) cin >> C[i];
    vector<vector<ll>> S(D, vector<ll>(26));
    rep(i, D) rep(j, 26) cin >> S[i][j];
    vector<int> T(D);
    rep(i, D) {
        cin >> T[i];
        T[i]--;
    }
    
    int M;
    cin >> M;
    vector<pair<int, int>> DQ(M);
    rep(i, M) {
        cin >> DQ[i].first >> DQ[i].second;
        DQ[i].first--;
        DQ[i].second--;
    }
    
    ll ans = 0;
    vector<ll> pen(26);
    vector<ll> cpen(26);
    rep(i, D) {
        ans += S[i][T[i]];
        rep(j, 26) pen[j] += C[j];
        pen[T[i]] = 0;
        rep(j, 26) {
            cpen[j] += pen[j];
            ans -= pen[j];
        }
//        output(ans);
    }
    
    for(auto m: DQ) {
        int prev = T[m.first];
        int cur = m.second;
//        cout << prev << "->" << cur << endl;
        ans += cpen[prev] + cpen[cur];
        ans -= S[m.first][prev];
        ans += S[m.first][cur];
        pen[prev] = 0;
        pen[cur] = 0;
        cpen[prev] = 0;
        cpen[cur] = 0;
        T[m.first] = m.second;
        rep(i, D) {
            pen[prev] += C[prev];
            pen[cur] += C[cur];
            if(T[i] == prev) pen[prev] = 0;
            if(T[i] == cur) pen[cur] = 0;
            cpen[prev] += pen[prev];
            cpen[cur] += pen[cur];
        }
        ans -= cpen[prev] + cpen[cur];
        output(ans);
    }
    
    
    
    
    
    
    return 0;
}


Measured memory_bytes: 3800