akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define rep2(i,n) for (int i = 1; i <= (n); i++)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
using ll = long long;
template <class T>
using Grid = vector<vector<T>>;
const int mod = 1000000007;
struct mint {
    ll x;
    mint(ll x = 0)
        : x((x % mod + mod) % mod) {}
    mint operator-() const {
        return mint(-x);
    }
    mint &operator+=(const mint a) {
        if ((x += a.x) >= mod)
            x -= mod;
        return *this;
    }
    mint &operator-=(const mint a) {
        if ((x += mod - a.x) >= mod)
            x -= mod;
        return *this;
    }
    mint &operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const {
        return mint(*this) += a;
    }
    mint operator-(const mint a) const {
        return mint(*this) -= a;
    }
    mint operator*(const mint a) const {
        return mint(*this) *= a;
    }
    mint pow(ll t) const {
        if (!t)
            return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1)
            a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const {
        return pow(mod - 2);
    }
    mint &operator/=(const mint a) {
        return *this *= a.inv();
    }
    mint operator/(const mint a) const {
        return mint(*this) /= a;
    }
};
istream &operator>>(istream &is, const mint &a) {
    return is >> a.x;
}
ostream &operator<<(ostream &os, const mint &a) {
    return os << a.x;
}
struct combination {
    vector<mint> fact, ifact;
    combination(int n):fact(n+1), ifact(n+1) {
        assert(n < mod);
        fact[0] = 1;
        for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
    }
    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n]*ifact[k]*ifact[n-k];
    }
    mint P(int n, int k){
        return fact[n] * ifact[n-k];
    }
};
int main(){
    int n, k;
    cin >> n >> k;
    combination c(n);
    rep2(i, k) {
        mint ans = c(n - k + 1, i);
        if (i >= 1)
            ans *= c(k - 1, i - 1);
        printf("%d\n", ans);
    }
}


Measured memory_bytes: 3768
#define _USE_MAT_DEFINES
#include<iostream>
#include <iomanip>
#include<stdio.h>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include <queue>
#include <utility>
#include <map>
#include <set>
#include <stack>
#include <deque>
#include <numeric>
#include <functional>
using namespace std;

int main() {
    vector<int>A(3);
    cin >> A[0] >> A[1] >> A[2];
    sort(A.begin(), A.end());
    
    int x = A[2] - A[1];
    if (A[0] % 2 == A[1] % 2)cout << x + (A[2] - A[0] - x) / 2;
    else cout << x + (A[2] - A[0] - x) / 2 + 2;



    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

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



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

int main() {
	int h, w;
	cin >> h >> w;

	string c[h];
	for (int i = 0; i < h; i++) {
		cin >> c[i];
		cout << c[i] << endl;
		cout << c[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 256
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
 
using namespace std;
 
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
 
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
 
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
 
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
 
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
 

int main(void){
  int n,k;
  int ans =0;
  scanf("%d %d",&n,&k);

  
  ans = k * pow(k-1,n-1);
    printf("%d\n",ans);
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <list>
#include <set>
#include <stack>
#include <cctype>
#include <cmath>
#include <bitset>

using namespace std;

/* typedef */
typedef long long ll;

/* constant */
const int INF = 1 << 30;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;

/* global variables */

/* function */

/* main */
int main(){
    string T, P;

    cin >> T >> P;
    int len_T = T.size();
    int len_P = P.size();
    bool same;
    for (int i = 0; i < len_T - len_P + 1; i++) {
        same = true;
        for (int j = 0; j < len_P; j++) {
            if (T[i + j] != P[j]) {
                same = false;
                break;
            }
        }
        if (same) cout << i << '\n';
    }

}



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

int main(){
    ll H,W; cin >> H >> W;
    if (H==1 || W==1) cout << 1 << endl;
    else if (H%2!=0 && W%2!=0) cout << H*W/2+1 << endl;
    else cout << H*W/2 << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String s = sc.nextLine();
        String x_k_d [] = s.split(" ", -1);
        long x = Long.parseLong(x_k_d[0]);
        long k = Long.parseLong(x_k_d[1]);
        long d = Long.parseLong(x_k_d[2]);
        
        //移動した後の位置pos、残り移動回数a
        long pos = x;
        long a = k;
        long b = 0;
        long c = 0;

        //出力は絶対値なのでposを正にして計算する
        if(x < 0){
            pos *= -1;
        }
        //0に近づけるように移動させる
        if(pos / d < k){
            a -= pos / d;
            pos = pos % d;
            
        }else{
            a = 0;
            pos -= d * k;
        }
        
        if(a == 0){
            System.out.println(pos);
        }else{
            b = pos;
            c = (pos - d) * -1;
            if(a % 2 == 0){
                System.out.println(b);
            }else if(a % 2 == 1){
                System.out.println(c);
            }
        }
    }
}

Measured memory_bytes: 35604
import math
N,X= map(int,input().split())
x=list(map(int, input().split()))
x.append(X)
x.sort()
d=[]
if N==1:
  print(x[1]-x[0])
  exit()
for i in range(N):
  d.append(x[i+1]-x[i])
gc=math.gcd(d[0],d[1])
for i in range(N):
  gc=math.gcd(d[i],gc)
print(gc)

Measured memory_bytes: 20376
/*
 * 0605.cc: Modern Mansion
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 100000;
const int MAX_K = 200000;
const int MAX_GN = MAX_K + 2;

typedef long long ll;
const ll LINF = 1LL << 60;

/* typedef */

typedef vector<int> vi;

struct Stat {
  ll d;
  int i, j;
  bool s;
  Stat() {}
  Stat(ll _d, int _i, int _j, bool _s): d(_d), i(_i), j(_j), s(_s) {}
  bool operator<(const Stat &s) const { return d > s.d; }
};

/* global variables */

int xys[MAX_GN][2];
vi nbrs[2][MAX_N];
bool sws[MAX_GN];
ll dists[MAX_GN][2];

/* subroutines */

/* main */

int main() {
  int m, n, k;
  cin >> m >> n >> k;

  xys[0][0] = xys[0][1] = 0;
  nbrs[0][0].push_back(0);
  nbrs[1][0].push_back(0);

  xys[1][0] = m - 1, xys[1][1] = n - 1;
  nbrs[0][m - 1].push_back(1);
  nbrs[1][n - 1].push_back(1);
  
  int gn = 2;
  
  for (int i = 0; i < k; i++) {
    int xi, yi;
    cin >> xi >> yi;
    xi--, yi--;

    if (xi == 0 && yi == 0) sws[0] = true;
    else if (xi != m - 1 || yi != n - 1) {
      xys[gn][0] = xi;
      xys[gn][1] = yi;
      nbrs[0][xi].push_back(gn);
      nbrs[1][yi].push_back(gn);
      sws[gn] = true;
      gn++;
    }
  }
  //printf("gn=%d\n", gn);

  for (int i = 0; i < gn; i++)
    dists[i][0] = dists[i][1] = LINF;
  dists[0][0] = 0;

  priority_queue<Stat> q;
  q.push(Stat(0, 0, 0, true));

  while (! q.empty()) {
    Stat u = q.top(); q.pop();
    if (dists[u.i][u.j] != u.d) continue;
    if (u.i == 1) break;

    if (sws[u.i]) {
      int vj = u.j ^ 1;
      ll vd = u.d + 1;
      if (dists[u.i][vj] > vd) {
	dists[u.i][vj] = vd;
	q.push(Stat(vd, u.i, vj, true));
      }
    }

    if (u.s) {
      vi &nbru = nbrs[u.j][xys[u.i][u.j]];
      for (vi::iterator vit = nbru.begin(); vit != nbru.end(); vit++) {
	int &vi = *vit;
	if (vi != u.i) {
	  ll vd = u.d + abs(xys[vi][u.j ^ 1] - xys[u.i][u.j ^ 1]);
	  if (dists[vi][u.j] > vd) {
	    dists[vi][u.j] = vd;
	    q.push(Stat(vd, vi, u.j, false));
	  }
	}
      }
    }
  }

  ll mind = (dists[1][0] < dists[1][1]) ? dists[1][0] : dists[1][1];
  printf("%lld\n", (mind >= LINF) ? -1LL : mind);
  return 0;
}

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

int main()
{
    int a[100000];
    int n;
    int max = 0;

    cin >> n;
    for(int i = 0; i < n; i++) {
        cin >> a[i];
        if( a[i] > max) {
            max = a[i];
        }
    }

    double target = (double)(max / 2.0);
    int Nearest;
    double NearDiff = max;
    for(int i = 0; i < n; i++) {
        if(a[i] == max) {
            continue;
        }

        if(a[i] < target) {
            if((target - a[i]) < NearDiff) {
                Nearest = a[i];
                NearDiff = target - Nearest;
            }
        }
        else {
            if((a[i] - target) < NearDiff) {
                Nearest = a[i];
                NearDiff = Nearest - target;
            }
        }
    }

    cout << max << " " << Nearest << endl;
    return 0;
}


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

int main(){
  int h,n;
  cin>>h>>n;
  int a[10005],b[10005];
  rep(i,n) cin>>a[i]>>b[i];
  int dp[20005];
  for(int i=0;i<=h+10000;i++) dp[i]=1e9;
  dp[0]=0;
  for(int i=1;i<=h+10000;i++){
    rep(j,n){
      if(i-a[j]>=0){
	dp[i]=min(dp[i],dp[i-a[j]]+b[j]);
      }
    }
  }
  int ans=1e9;
  for(int i=h;i<=h+10000;i++){
    ans=min(dp[i],ans);
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 384
/** 
 * Dont raise your voice, improve your argument.
 * --Desmond Tutu
 */

#include <bits/stdc++.h>
using namespace std;

#define DEBUG
#ifndef DEBUG
#define endl "\n"
#endif

const double PI=3.1415926535897932384626433;
typedef long long ll;
#define fori(n) for(ll i=0; i<(n); i++)

#define cins(s) string s; cin>>s;
#define cini(i) int i; cin>>i;
#define cinll(l) ll l; cin>>l;
#define cind(d) double d; cin>>d;
#define cinai(a, n) vi a(n); fori(n) { cin>>a[i]; }
#define cinall(a, n) vll a(n); fori(n) { cin>>a[i]; }
#define cinas(s, n) vs s(n); fori(n) { cin>>s[i]; }

typedef pair<int, int> pii;
typedef pair<double,double> pdd;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<string> vs;
typedef vector<ll> vll;

ll atol(string &s) {
    istringstream iss(s);
    ll i;
    iss>>i;
    return i;
}

void atoli(string &s, vll &a) {
    istringstream iss(s);
    int i=0;
    while(iss.good())
        cin>>a[i++];
}

void solve() {
    cins(s);
    int sz=(int)s.size();
    int l,r;
    if(sz&1) {
        l=r=((sz+1)/2)-1;
    } else {
        l=(sz/2)-1;
        r=l+1;
    }

    int ans=0;
    for(; l>=0; l--, r++) {
        if(s[l]!=s[r])
            ans++;
    }
    cout<<ans<<endl;
}

int main() {
cin.tie(nullptr);
std::ios::sync_with_stdio(false);
        solve();
}



Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#define N 100001
#define NIL -1
using namespace std;

struct Node {
	int parent, left, right;
};

Node **T;
int *depth,*degree;

Node* newNode(int parent, int left, int right){
	Node* p = new Node;
	p->parent=parent; p->left=left; p->right=right;
	return p;
}
void df(int id, int dp){
	depth[id] = dp;
	if(T[id]->left != NIL) df(T[id]->left, dp+1);
	if(T[id]->right != NIL) df(T[id]->right, dp+1);
}

void calDepth(int n){
	int rt=NIL;
	for(int i=0;i<n;i++){
		if(T[i]->parent == NIL) rt = i;
	}
	df(rt, 0);
}

int height(int id){
	if(id==NIL) return -1;
	return 1+max( height(T[id]->left), height(T[id]->right) );
}

int sib(int id){
	int par = T[id]->parent;
	if(par == -1) return -1;
	if(T[par]->left == id){
		if(T[par]->right == NIL) return -1;
		else return T[par]->right; 
	} else {
		if(T[par]->left == NIL) return -1;
		else return T[par]->left;
	}
}

int main(){
	int n;
	cin >> n;
	T = new Node*[N];
	depth = new int[N];
	degree = new int[N];
	for(int i=0;i<n;i++){
		T[i] = newNode(NIL, NIL, NIL);
		degree[i] = 0;
	}
	for(int i=0;i<n;i++){
		int id, left, right;
		cin >> id >> left >> right;
		T[id]->left = left;
		T[id]->right = right;
		if(left != NIL){
			T[left]->parent = id;
			degree[id]++;
		}
		if(right != NIL){
			T[right]->parent = id;
			degree[id]++;
		}
	}
	calDepth(n);
	for(int i=0;i<n;i++){
		cout << "node " << i << ": parent = "<<T[i]->parent;
		cout << ", sibling = " << sib(i) << ", degree = " << degree[i];
		cout << ", depth = " << depth[i] <<", height = " << height(i)<<", ";		
		if(T[i]->parent == NIL){
			cout << "root";
		} else if(degree[i]==0){
			cout << "leaf";
		} else {
			cout << "internal node";
		}
		cout << endl;
	}
	for(int i=0;i<N;i++) delete T[i];
	delete[] T;
	return 0;
}

Measured memory_bytes: 1212
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for( int i = 0 ; i < n ; i++ )
 
int main(){
  int A , B, K ;
  cin >> A >> B ;
  if ( ( A+ B )%2 == 1 )cout << "IMPOSSIBLE" << endl;
  else  cout << ( A + B )/2 << endl;
}

Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
af=[]
al=[]
for i in range(n):
    if i%2==0:
        af.append(a[i])
    else:
        al.append(a[i])

if n%2==0:
    al=al[::-1]
    for a in al:
        print(a,end=" ")
    for a in af:
        print(a,end=" ")
else:
    af=af[::-1]
    for a in af:
        print(a,end=" ")
    for a in al:
        print(a,end=" ")

Measured memory_bytes: 26180
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;

int dp[100005][3], a[100005][3], n;

int main(){
    int n;
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> a[i][0] >> a[i][1] >> a[i][2];
    }
    //dp[i][j] = max(dp[i][j], dp[i+1][k] + a[i][k]) where k != j
    for(int i = 1; i <= n; i++){
        for(int j = 0; j < 3; j++){
            dp[i][j] = 0;
            for(int k = 0; k < 3; k++){
                if(j != k){
                    dp[i][j] = max(dp[i][j], dp[i-1][k] + a[i-1][k]);
                }
            }
        }
    }
    int mmax = 0;
    for(int i = 0; i < 3; i++)mmax = max(mmax, dp[n][i]);
    cout << mmax << endl;
    return 0;
}

Measured memory_bytes: 2560
import math
import collections
import bisect
from collections import deque
from copy import copy, deepcopy


def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    for i in range(N - K):
        if(A[i] < A[i + K]):
            print("Yes")
        else:
            print("No")


if __name__ == '__main__':
    main()


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

vector<ll> ret;
void divisor(long long n)
{

    for (long long i = 1; i * i <= n; i++)
    {
        if (n % i == 0)
        {
            ret.push_back(i);
            if (i * i != n)
                ret.push_back(n / i);
        }
    }
    //sort(ret.begin(), ret.end()); // 昇順に並べる
}

int main()
{
    //最大公約数を求める。
    ll n, m;
    cin >> n >> m;
    divisor(m);
   sort(ret.begin(), ret.end());
    ll k = 0;

    k = ret[lower_bound(ret.begin(), ret.end(), n) - ret.begin()];
    cout << m / k << endl;
    //公約数のうち、N以上となるもののうち最小値になるものを選択すれば良い。
    //Mが大きすぎるのでfor分で回すと死ぬ。
    //公約数と成り得る数をqueに格納していけば絶対にできる。(どうやる？)
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {

	while(1){

		int a;

    		scanf("%d",&a);

    		if(a==0) break;


		int sa,e500,a500,e100,a100,e50,a50,e10,a10,e5,e1,k;
		sa=1000-a;
		e500=sa/500;
		a500=sa%500;
		e100=a500/100;
		a100=a500%100;
		e50=a100/50;
		a50=a100%50;
		e10=a50/10;
		a10=a50%10;
		e5=a10/5;
		e1=a10%5;
		k=e500+e100+e50+e10+e5+e1;
		printf("%d\n",k);	
	}

	return 0;

}



Measured memory_bytes: 2064
import sys
from collections import deque

def solve():
    input = sys.stdin.readline
    N = int(input())
    Edge = [[] for _ in range(N)]
    for _ in range(N-1):
        a, b, c = map(int, input().split())
        Edge[a-1].append((b-1, c))
        Edge[b-1].append((a-1, c))
    Q, K = map(int, input().split())
    Ans = [0] * Q
    Dist = [-1] * N
    q = deque()
    q.append((K-1, K-1, 0))
    while q:
        nowN, pre, dist = q.popleft()
        if Dist[nowN] == -1:
            Dist[nowN] = dist
            for nextN, cost in Edge[nowN]:
                if nextN != pre: q.append((nextN, nowN, dist + cost))
    for i in range(Q):
        x, y = map(int, input().split())
        Ans[i] = Dist[x-1] + Dist[y-1]

    print(*Ans, sep="\n")
    return 0

if __name__ == "__main__":
    solve()

Measured memory_bytes: 50268
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <stdlib.h>
using namespace std;

#define INF 1e9
#define PI 3.141592653589793238
typedef long long ll;

int main() {
    ll x,money=100;cin>>x;
    int ans=0;

    while(money<x){
        money += money/100;
        ans++;
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  set<string> words;
  cin >> N;
  vector<string> s(N);
  for(int i=0;i<N;i++) { cin >> s[i]; words.insert(s[i]); }
  cin >> M;
  vector<string> t(M);
  for(int j=0;j<M;j++) { cin >> t[j]; words.insert(t[j]); }
  int sum=0;
  
  for(const string& word : words) {
    int v=0;
    for(const string& w : s) {
      if (word==w) v += 1;
    }
    for(const string& w : t) {
      if (word==w) v -= 1;
    }
    if (v>sum) sum = v;
  }
  
  cout << sum << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
    public static void main (String[] args){
        try (Scanner sc = new Scanner (System.in)){
            String line = sc.nextLine();
            String answer = "";
            int length = line.length();
            for(int i = 0; i<length; i++){
                char ch = line.charAt(i);
                if(Character.isLowerCase(ch)) {
                    System.out.print(Character.toUpperCase(ch));
                }else{
                    System.out.print(Character.toLowerCase(ch));
                }
            }
            System.out.println(answer);
        }
    }
}



Measured memory_bytes: 26668
#include <ctime>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <map>
using namespace std;

typedef long long ll;
typedef double lf;
typedef long double Lf;
typedef pair <int,int> pii;
typedef pair <ll, ll> pll;

#define TRACE(x) cerr << #x << "  " << x << endl
#define FOR(i, a, b) for (int i = (a); i < int(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define _ << " " <<

#define fi first
#define sec second
#define mp make_pair

const int MAXN = 100100;
const ll INF = 1e18;
const lf EPS = 1e-8;

inline bool lt(const lf &a, const lf &b) {return a + EPS < b;}
inline bool eq(const lf &a, const lf &b) {return max(a - b, b - a) < EPS;}

int X, Y, Z;
ll a[MAXN], b[MAXN], c[MAXN];
int n;

ll dp[MAXN];

inline void update(int i, int i1, ll t) {
		if (dp[i1] < t) dp[i1] = t;
}

int retA, retB;

pair <ll, int> checkA(lf x, ll y) {
	REP(i, n + 1) dp[i] = -INF;
	dp[0] = 0;
	REP(i, n) {
		update(i, i + 1, dp[i] + c[i]);
		update(i, i + 1, dp[i] + a[i] + y);
		update(i, i + 1, dp[i] + b[i] + x);
	}

	retA = retB = 0;
	for (int i = n; i; i--) {
		if (dp[i] == dp[i - 1] + c[i - 1]) continue;
		if (dp[i - 1] + b[i - 1] + x == dp[i]) retB++;
		else retA++;
	}

	return mp(dp[n], retA);
}

pair <ll, int> checkB(lf x) {
	ll lo = -(1LL << 30), hi = (1LL << 30), mid;
	REP(i, 40) {
		mid = (lo + hi) / 2;
		pair <ll, int> t = checkA(x, mid);
		if (t.sec == X) {
			lo = mid;
			break;
		}
		if (t.sec < X) lo = mid;
		else hi = mid;
	}

	ll Ret = checkA(x, lo).fi - lo * X;
	return mp(Ret, retB);
}

int perm[MAXN];
ll a1[MAXN], b1[MAXN], c1[MAXN];

int main() {
	scanf("%d %d %d",&Y,&X,&Z);
	n = X + Y + Z;
	REP(i, n) scanf("%lld %lld %lld",&b[i],&a[i],&c[i]);
       
	srand(time(NULL));
	REP(i, n) perm[i] = i;
	REP(i, 100) random_shuffle(perm, perm + n);
	
	REP(i, n) {
		a1[i] = a[perm[i]];
		b1[i] = b[perm[i]];
		c1[i] = c[perm[i]];
	}
	REP(i, n) {
		a[i] = a1[i];
		b[i] = b1[i];
		c[i] = c1[i];
	}

	ll lo = -(1LL << 30), hi = (1LL << 30), mid;

	REP(i, 40) {
		mid = (lo + hi) / 2;
		pair <ll, int> t = checkB(mid);
		if (t.sec < Y) lo = mid;
		if (t.sec == Y) {
			lo = mid;
			break;
		}
		if (t.sec > Y) hi = mid;
	}

	pair <ll, int> t = checkB(lo);
	printf("%lld\n",t.fi - lo * Y);
	return 0;
}


Measured memory_bytes: 6144
#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() {
  bool a= false,b = false,c = false;
  string s;
  cin >> s;
  rep(i,3){
    if(s[i] == 'a') a = true;
    if(s[i] == 'b') b = true;
    if(s[i] == 'c') c = true;
  }
  if(a&&b&&c) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<deque>
#include<iomanip>
#include<tuple>
using namespace std;
typedef long long int LL;
typedef pair<int,int> P;
typedef pair<LL,int> LP;
const int INF=1<<30;
const LL MAX=1e9+7;

void array_show(int *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%d%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(LL *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%lld%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(vector<int> &vec_s,int vec_n=-1,char middle=' '){
	if(vec_n==-1)vec_n=vec_s.size();
	for(int i=0;i<vec_n;i++)printf("%d%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}
void array_show(vector<LL> &vec_s,int vec_n=-1,char middle=' '){
	if(vec_n==-1)vec_n=vec_s.size();
	for(int i=0;i<vec_n;i++)printf("%lld%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}

int t[100005][2];
vector<int> v1,v2;
map<int,int> m1;
vector<int> path[100005];
bool used[100005];

void check(int a){
	if(used[a])return;
	used[a]=true;
	for(auto to:path[a])check(to);
}

int main(){
	int n,m;
	int i,j,k;
	int a,b,c;
	int p,q;
	int s=0;
	cin>>n;
	p=0,q=0;
	for(i=0;i<n;i++){
		cin>>a;
		t[i][0]=a;
		v1.push_back(a);
		p^=a;
	}
	for(i=0;i<n;i++){
		cin>>a;
		t[i][1]=a;
		v2.push_back(a);
		q^=a;
	}
	v1.push_back(p),v2.push_back(q);
	sort(v1.begin(),v1.end());
	sort(v2.begin(),v2.end());
	for(i=0;i<v1.size();i++){
		if(v1[i]!=v2[i]){
			cout<<-1<<endl;
			return 0;
		}
	}
	if(b==c)s=n;
	else s=n-1;

	for(c=0,i=0;i<n;i++){
		a=t[i][0],b=t[i][1];
		if(a==b){
			s--;
			continue;
		}
		if(m1.find(a)==m1.end())m1[a]=c++;
		if(m1.find(b)==m1.end())m1[b]=c++;
		a=m1[a],b=m1[b];
		path[a].push_back(b);
		path[b].push_back(a);
	}
	for(i=0;i<c;i++){
		if(used[i])continue;
		check(i);
		s++;
	}
	if(m1.find(p)!=m1.end())s--;
	cout<<s<<endl;
}

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

typedef long long ll;

int main(){
    int N,W;
    cin >> N >> W;
    ll w[N];
    ll v[N];
    for(int i=0;i<N;i++){
        cin >> w[i] >> v[i];
    }
    vector<ll> w1,w2,w3,w4;
    for(int i=0;i<N;i++){
        if(w[i]==w[0]){
            w1.push_back(v[i]);
        }else if(w[i]==w[0]+1){
            w2.push_back(v[i]);
        }else if(w[i]==w[0]+2){
            w3.push_back(v[i]);
        }else{
            w4.push_back(v[i]);
        }
    }
    sort(w1.begin(),w1.end(),greater<ll>());
    sort(w2.begin(),w2.end(),greater<ll>());
    sort(w3.begin(),w3.end(),greater<ll>());
    sort(w4.begin(),w4.end(),greater<ll>());
    w1.insert(w1.begin(),0);
    w2.insert(w2.begin(),0);
    w3.insert(w3.begin(),0);
    w4.insert(w4.begin(),0);
    //for(int i=0;i<w1.size();i++){
        //cout << w1[i] << endl;
    //}
    for(int i=1;i<w1.size();i++){
        w1[i]+=w1[i-1];
    }
    for(int i=1;i<w2.size();i++){
        w2[i]+=w2[i-1];
    }
    for(int i=1;i<w3.size();i++){
        w3[i]+=w3[i-1];
    }
    for(int i=1;i<w4.size();i++){
        w4[i]+=w4[i-1];
    }
    ll ans=0;
    for(int i=0;i<w1.size();i++){
        for(int j=0;j<w2.size();j++){
            for(int k=0;k<w3.size();k++){
                for(int l=0;l<w4.size();l++){
                    ll weight=i*w[0]+j*(w[0]+1)+k*(w[0]+2)+l*(w[0]+3);
                    if(weight<=W){
                        ll sum=w1[i]+w2[j]+w3[k]+w4[l];
                        ans=max(ans,sum);
                    }
                }
            }
        }
    }
    std::cout << ans << endl;
}

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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

// 最小公倍数
ll lcm(ll a, ll b){
    return a*b/gcd(a, b);
}

int main()
{
    cout << fixed << setprecision(15);

    ll N;
    cin >> N;

    vector<ll> A(N+1, 0);

    for(ll i=1; i<=N; i++){
        ll t = i;
        for(ll j=2; j<=t; j++){
            while(t%j ==0){
                t = t/j;
                A[j]++;
            }
        }
    }
    ll a=0;
    ll b=0;
    ll c=0;
    ll d=0;
    ll e=0;

    for(ll i=2; i<=N; i++){
        // cout << A[i] << endl;
        if(A[i] >= 2) a++;
        if(A[i] >= 4) b++;
        if(A[i] >= 14) c++;
        if(A[i] >= 24) d++;
        if(A[i] >= 74) e++;
    }

    // cout << a << endl;
    // cout << b << endl;
    // cout << c << endl;
    // cout << d << endl;
    // cout << e << endl;

    ll ans = 0;

    ans += b*(b-1)/2 * (a-2);
    ans += d * (a-1);
    ans += c * (b-1);
    ans += e;

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

Measured memory_bytes: 256
// G++ MACRO.CPP -STD=C++17
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
using namespace std;
 
#define dump(x)  cout << #x << " = " << (x) << endl;
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl
#define possible(n) cout << ((n) ? "possible" : "impossible"  ) << endl
 
#define SANKOU(n,a,b) cout << ((n) ? (#a) : (#b) ) << endl
 
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
 
#define FOREACH(x,a) for(auto& (x) : (a) )
 
#define WFA(d,v) REP(k,v)REP(i,v)REP(j,v)d[i][j]=min(d[i][j],d[i][k]+d[k][j])
 
#define SCOUT(x) cout<<(x)<<" "
#define ENDL cout<<endl
 
#define VECCIN(x) for(auto&youso_: (x) )cin>>youso_
#define VECIN2(x,y) REP(i,x.size())cin>>x[i]>>y[i]
#define VECCOUT(x) if(1){for(auto tt=x.begin();tt!=x.end();tt++){if(tt!=x.begin())cout<<" ";cout<<(*tt);}cout<<endl;}
 
#define ALL(obj) (obj).begin(),(obj).end()
 
#define EXIST(n,x) (find(ALL(n),x)!=n.end())
#define UNIQUE(obj) sort(ALL( obj )); obj.erase(unique(ALL(obj)),obj.end())
#define EN(x) if(1){cout<<#x<<endl;return 0;}
#define COUT(x) cout<<(x)<<endl
void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail){
    cin>>head;
    CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)
 
template <class T = ll>
T IN(){T x;cin>>x;return (x);}
 
template <class Head>
void VT(Head head){}
template <class Head,class Seco,class... Tail>
void VT(Head&& head,Seco&& seco,Tail&&... tail){
    seco.resize(head);
    VT(head,move(tail)...);
}
void VT2(){}
template <class Head,class... Tail>
void VT2(Head&& head,Tail&&... tail){
  VECCIN(head);
  VT2(move(tail)...);
}
 
template <class Head>
void VT3(Head&& head){}
template <class Head,class Seco,class... Tail>
void VT3(Head&& head,Seco&& seco,Tail&&... tail){
  seco[head]=IN();
  VT3(head,move(tail)...);
}
 
#define VC1(n,...) V __VA_ARGS__;VT(n,__VA_ARGS__);VT2(__VA_ARGS__); //aaabbbccc
#define VC2(n,...) V __VA_ARGS__;VT(n,__VA_ARGS__);REP(i,n)VT3(i,__VA_ARGS__); //abcabcabc
 
// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision; // cpp_int
 
#define P pair<ll,ll>
#define V vector<ll>
#define M map<ll,ll>
#define S set<ll>
 
#define pb(a) push_back(a)
#define mp make_pair
 
 
int main(){
  CIN(n);VC1(n,v);
  // 各値に対して差を3e4程度余裕を持つ
  // 0,3e4,6e4… 最終的には6*10^8で済む
  V x(n);V y(n);
  REP(i,n){
    x[i]= 30000 * i;
    y[n-1-i]= 30000 * i;
  }
  REP(i,n)
    x[v[i]-1]+=i;
  REP(i,n){
    x[i]++;y[i]++;
  }
  VECCOUT(x);VECCOUT(y);
 
  return 0;
}

Measured memory_bytes: 1152
#include<iostream>
#include<stdio.h>
using namespace std;
int main()
{
	long long int a[101][21];
	int n, i, i2, b[101];
	cin >> n;

	for (i = 0; i < n; i++){
		cin >> b[i];
	}
	for (i = 0; i < n + 1; i++){
		for (i2 = 0; i2 <= 20; i2++){
			a[i][i2] = 0;
		}
	}
	a[0][b[0]] = 1;
	for (i = 0; i < n - 2; i++){
		for (i2 = 0; i2 <= 20; i2++){
			if (a[i][i2] != 0){
				if (b[i + 1] + i2 <= 20){
					a[i + 1][b[i + 1] + i2] += a[i][i2];
				}
				if (i2 - b[i + 1] >= 0){
					a[i + 1][i2 - b[i + 1]] += a[i][i2];
				}
			}
		}


	}
	/*for (i = n - 2; i >= 0; i--){
		for (i2 = 0; i2 <= 20; i2++){
			printf("%3d", a[i][i2]);
		}
		printf("\n");
	}
	printf("\n");*/
	printf("%lld\n", a[n - 2][b[n - 1]]);
	return 0;
}

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

int64_t mod = 1000000007;
int64_t large = 9223372036854775807;
double PI = 3.141592653589793;

int main()
{
    int N;
    cin >> N;
    vector<int> V(N), C(N);
    for (int i = 0; i < N; i++)
        cin >> V[i];
    for (int i = 0; i < N; i++)
        cin >> C[i];
    vector<int> list(N);
    for (int i = 0; i < N; i++)
        list[i] = V[i] - C[i];
    sort(list.begin(), list.end());
    reverse(list.begin(), list.end());
    int ans = 0;
    int i = 0;
    while (list[i] > 0)
    {
        ans += list[i];
        i++;
    }
    cout << ans;
}

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

int main()
{
	int a;
	
	while(true)
	{
		int h=0;
	cin>>a;
	a=1000-a;
	if(a==1000)return 0;
	while(a>=500)
	{
		a=a-500;
		h=h+1;
		
	}
	while(a>=100)
	{
	a=a-100;
	h=h+1;
	}
	while(a>=50)
	{
	a=a-50;
	h=h+1;
	}
	while(a>=10)
	{
	a=a-10;
	h=h+1;
	}
	while(a>=5)
	{
	a=a-5;
	h=h+1;
	}
	while(a>=1)
	{
	a=a-1;
	h=h+1;
	}
	cout<<h<<endl;
}

		return 0;

}

Measured memory_bytes: 1160
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <cstdio>
#include <string>
#include <cmath>
#include <queue>
//#include <bits/stdc++.h>
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i,i0,n) for(int (i)=(i0);(i)<(n);(i)++)
#define FORR(i,i0,n) for(int (i)=(n)-1; (i)>=(i0);(i)--)
#define rn return
#define fi first
#define se second
typedef std::pair<int,int> P;
using namespace std;
using ll = long long;

int main(){
    int N,M; cin >> N >> M;
    int l,r;
    int maxl = -101010,minr= 101010;
    rep(i,M){
        cin >> l >> r;
        if (maxl<l) maxl = l;
        if (minr>r) minr = r;
    }
    cout << (maxl>minr? 0: minr-maxl+1);
    rn 0;
}

Measured memory_bytes: 256
ints = input().split(' ')
r, D, x_0 = int(ints[0]), int(ints[1]), int(ints[2])

def calc(i):
	if i==2000:
		return x_0
	else:
		return r*calc(i-1)-D
for i in range(2001, 2011):
	print(calc(i))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define PI 3.141592653589793
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, a, n) for (int i = a; i < (n); i++)
#define rrep(i, n, k) for (int i = (n); i >= (k); i--);
#define all(x) (x).begin(), (x).end()
#define vi vector<int>
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;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>vector<T> make_vector(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto make_vector(size_t a, Ts... ts){return vector<decltype(make_vector<T>(ts...))>(a, make_vector<T>(ts...));}
const int MOD = 1e9 + 7;
const int INF = 2e18;

signed main() {
    int N, M;
    cin >> N >> M;
    vector<set<int>> G(N + 1);
    for (int i = 0; i < M; i++) {
        int A, B;
        cin >> A >> B;
        G[A].insert(B);
        G[B].insert(A);
    }
    if (M % 2 == 1) {
        cout << -1 << endl;
        return 0;
    }
    vector<int> tree(N + 1, -1), treeCount(N + 1, 0);
    {
        // generate tree
        queue<int> explore;
        explore.push(1);
        while (!explore.empty()) {
            int now = explore.front();
            explore.pop();
            for (auto next : G[now]) {
                if (tree[next] != -1 || next == 1) continue;
                tree[next] = now;
                treeCount[now]++;
                explore.push(next);
            }
        }
    }
    vector<int> count(N + 1, 0);
    vector<pair<int, int>> ans;
    auto update = [&](int from, int to) {
        ans.emplace_back(from, to);
        count[from]++;
        G[from].erase(to);
        G[to].erase(from);
    };
    queue<int> explore;
    vector<bool> check(N + 1, true);
    for (int i = 2; i <= N; i++) if (treeCount[i] == 0) {
            explore.push(i);
            check[i] = false;
    }
    while (!explore.empty()) {
        int now = explore.front();
        explore.pop();

        if (treeCount[now] != 0) {
            explore.push(now);
            continue;
        }
        {
            int next = tree[now];
            if (next == -1) continue;
            if (count[now] % 2 == 0) update(next, now);
            else update(now, next);
            if (check[next]) explore.push(next);
            check[next] = false;
            treeCount[next]--;
        }
        auto temp = G[now];
        for (auto next : temp) update(next, now);
    }
    for (auto temp : ans) {
        cout << temp.first << " " << temp.second << endl;
    }
}


Measured memory_bytes: 19824
B = []
for i in range(3):
    B.append(list(map(str, input().split())))

N = int(input())

num_list = []
for i in range(N):
    num_list.append(input())

for n in num_list:
    for i in range(3):
        for j in range(3):
            if B[i][j] == n:
                B[i][j] = "N"

ans = "No"
for i in range(3):
    if B[i][0] is B[i][1] is B[i][2]: ans = "Yes"
    if B[0][i] is B[1][i] is B[2][i]: ans = "Yes"

if B[0][0] is B[1][1] is B[2][2]: ans = "Yes"
if B[0][2] is B[1][1] is B[0][2]: ans = "Yes"

print(ans)


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

const int INF = 1001001001;

int main() {
  ll n, k, amari, ans;
  cin>>n>>k;

  amari = n % k;

  ans = min(amari, abs(k - amari));

  cout<<ans<<endl;

  return 0;
}

Measured memory_bytes: 256
while True:
    h,w = map(int, input().split())
    
    if h == 0 and w == 0:           
        break
        
    for i in range(h):
        if i == 0 or i == h-1:
            print('#' * w)
        else:
            print('#'+'.'*(w-2)+'#')
    print()


Measured memory_bytes: 5608
/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Main
{
     public static int minCost(int [][]h , int curr_ind , int n , int [][]dp , int k){
	        if(curr_ind > n  )
	        return 0;
	        
	        if(dp[curr_ind][k]!=-1) return dp[curr_ind][k];
	        
	        int a = Integer.MIN_VALUE;
	        
	        if(k==0){
	            a = Math.max((h[curr_ind][1] + minCost(h,curr_ind+ 1,n,dp,1 )),Math.max((h[curr_ind][2] + minCost(h,curr_ind+ 1,n,dp,2 )),(h[curr_ind][3] + minCost(h,curr_ind+ 1,n,dp,3 ))));
	        }else if(k == 1){
	            a = Math.max((h[curr_ind][2] + minCost(h,curr_ind+ 1,n,dp,2 )),(h[curr_ind][3] + minCost(h,curr_ind+ 1,n,dp,3 )));
	        }else if(k == 2){
	             a = Math.max((h[curr_ind][1] + minCost(h,curr_ind+ 1,n,dp,1 )),(h[curr_ind][3] + minCost(h,curr_ind+ 1,n,dp,3 )));
	        }else{
	             a = Math.max((h[curr_ind][2] + minCost(h,curr_ind+ 1,n,dp,2 )),(h[curr_ind][1] + minCost(h,curr_ind+ 1,n,dp,1 )));
	        }
	        
	        
	        
	       
	        
	        return dp[curr_ind][k] = a;
	        
	        
	    }
    
	public static void main (String[] args) throws java.lang.Exception
	{
	    
	   
	    
	    
		// your code goes here
		 Scanner sc = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		int n = sc.nextInt();
		
		
		int h[][] = new int[n+1][4];
		for(int i = 1 ;i<=n;i++){
		    for(int j=1;j<=3;j++){
		    h[i][j] = sc.nextInt();
			}}
			
			int dp[][]=new int[n+1][4];
			for(int i=0;i<n+1;i++){
			for(int j =0;j<4;j++){
			dp[i][j] = -1;
			}}
			
			System.out.println(minCost(h , 1 , n , dp , 0));
	}
}


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

int main(){
int n;
cin >> n;
int m;
m=n*(n-1)/2;
int a[m];
int b[m];
int c[m];
int d[m];
int e;
int f;
int g[n];
int h[n];
e=0;
while(e<m){
cin >> a[e];
cin >> b[e];
cin >> c[e];
cin >> d[e];
e=e+1;}
e=0;
while(e<n){
g[e]=0;
h[e]=1;
e=e+1;}
e=0;
while(e<n){
f=0;
while(f<m){
if(a[f]==e+1){if(c[f]>d[f]){g[e]=g[e]+3;}
              if(c[f]==d[f]){g[e]=g[e]+1;}}
if(b[f]==e+1){if(c[f]<d[f]){g[e]=g[e]+3;}
              if(c[f]==d[f]){g[e]=g[e]+1;}}
f=f+1;}
e=e+1;}
e=0;
while(e<n){
f=0;
while(f<n){
if(g[e]<g[f]){h[e]=h[e]+1;}
f=f+1;}
e=e+1;}
e=0;
while(e<n){
cout << h[e] <<endl;
e=e+1;}
}

Measured memory_bytes: 1236
/*
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_11_C&lang=ja
*/

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

int main(){
    int n;
    cin >> n;
    vector<vector<int>> to(n);
    rep(i,n){
        int u,k;
        cin >> u >> k;
        rep(j,k){
            int v;
            cin >> v;
            v--;
            to[i].push_back(v);
        }
    }

    vector<int> dist(n,-1);
    queue<int> q;
    dist[0]=0;
    q.push(0);

    while(!q.empty()){
        int p;
        p = q.front();
        q.pop();
        //cout << "p" << p << endl;
        rep(i,to[p].size()){
            if(dist[to[p][i]]==-1){
                dist[to[p][i]]=dist[p]+1;
                q.push(to[p][i]);
            }
        }
    }

    rep(i,dist.size()){
        cout << i+1 <<" " <<dist[i] << endl;
    }
}


Measured memory_bytes: 3160
#include <iostream>

int main(){
    int d, n, aw;
    std::cin >> d >> n;
    aw = n;
    if(n==100) ++aw;
    for(int i=0; i<d; ++i){
        aw *= 100;
    }
    std::cout << aw << std::endl;
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> vec;
typedef vector<vec> mat;
int main(){
    string s,t;
    cin>>s>>t;
    cout<<t<<s<<"\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
const ll MOD = 1000000007;
const ll INF = 2147483647;
const ll LINF = 9223372036854775807;
#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

int main() {
	string s; cin >> s;
	if(s[0]==s[1]&&s[1]==s[2]){
		cout << "No" << endl;
	}
	else{
		cout << "Yes" << endl;
	}
	return 0;
}

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


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

Measured memory_bytes: 512
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>

using namespace std;

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

long long int INF = 1e18;
long long int MOD = 1e9 + 7;

int main(){
	
	int N, M;
	cin >> N >> M;
	
	int cnt[100] = {};
	
	for(int i = 0; i < N; i++){
		int K;
		cin >> K;
		for(int j = 0; j < K; j++){
			int A;
			cin >> A;
			cnt[A] += 1;
		}
	}
	
	int ans = 0;
	for(int i = 1; i <= M; i++){
		if(cnt[i] == N){
			ans += 1;
		}
	}
	
	cout << ans << endl;
	
	return 0;
}


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

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

int main(){
    int n;
    cin>>n;
    int x,y,z;
    cin>>x>>y>>z;
    
    int l[10];
    rep(i,n) cin>>l[i];
    int ans=10000000;
    
    for (int bit = 0; bit < (1<<n); ++bit)
    {
        for (int bit2 = 0; bit2 < (1<<n); ++bit2)
        {
            //cout<<bitset<10>(bit)<<" "<<bitset<10>(bit2)<<endl;
            int tmpans=0;
            int A=0,B=0,C=0,D=0;
            for(int i=0;i<n;i++){
                if((bit & (1<<i))&&(bit2 & (1<<i))){
                    if(A>0) tmpans+=10;
                    A+=l[i];
                    
                }else if((bit & (1<<i)) && (!(bit2 & (1<<i)))){
                    if(B>0) tmpans+=10;
                    B+=l[i];
                    //if(B>0) tmpans+=10;
                }else if((!(bit & (1<<i))) && (bit2 & (1<<i))){
                    if(C>0) tmpans+=10;
                    C+=l[i];
                    //if(C>0) tmpans+=10;
                }else{
                    D+=l[i];
                }
                //cout<<A<<" "<<B<<" "<<C<<" "<<D<<endl;
            }
            
            if(A*B*C>0){
                //cout<<A<<" "<<B<<" "<<C<<" "<<D<<endl;
                //cout<<abs(A-x)<<" "<<abs(B-y)<<" "<<abs(C-z)<<" "<<D<<endl;
                tmpans+=abs(A-x);
                tmpans+=abs(B-y);
                tmpans+=abs(C-z);
                ans=min(ans,tmpans);
               // cout<<"tmp is"<<tmpans<<endl;
            }
        }
    }
    
    
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input())


def max_pos_number(n):
    val = 0
    for i in range(n):
        if i % 2 == 0:
            val += 2**i
    return val


def min_pos_number(n):
    val = 0
    for i in range(n):
        if i % 2 == 1:
            val -= 2**i

    return val


n = 1
while True:
    if min_pos_number(n) <= N <= max_pos_number(n):
        break
    n += 1

result = []
for i in range(n-1, -1, -1):
    if i % 2 == 0:
        if N > max_pos_number(i):
            result.append(1)
            N -= (-2) ** i
        else:
            result.append(0)
    else:
        if N < min_pos_number(i):
            result.append(1)
            N -= (-2) ** i
        else:
            result.append(0)
print(''.join([str(x) for x in result]))


Measured memory_bytes: 9148
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<ctime>
#include<map>
#include<bitset>
#include<set>
#define LL long long
#define mp(x,y) make_pair(x,y)
#define pll pair<long long,long long>
#define pii pair<int,int>
using namespace std;
inline int read()
{
	int f=1,x=0;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int stack[20];
template<typename T>inline void write(T x)
{
	if(x<0){putchar('-');x=-x;}
    if(!x){putchar('0');return;}
    int top=0;
    while(x)stack[++top]=x%10,x/=10;
    while(top)putchar(stack[top--]+'0');
}
template<typename T>inline void pr1(T x){write(x);putchar(' ');}
template<typename T>inline void pr2(T x){write(x);putchar('\n');}
const int MAXN=132005;
struct edge{int x,y,c,next;}a[2*MAXN];int len,last[MAXN];
void ins(int x,int y,int c){len++;a[len].x=x;a[len].y=y;a[len].c=c;a[len].next=last[x];last[x]=len;}

int up[MAXN],n;LL mxsum,mnsum,lim;
set<pll> se[MAXN];
set<pll>::iterator it,it1;
pll sta[2*MAXN];int tp;
void dp(int x)
{
	se[x].clear();
	if(!last[x]){se[x].insert(mp(up[x],up[x]));return ;}
	int fx=0,fy=0;for(int k=last[x];k;k=a[k].next)fx?fy=a[k].y:fx=a[k].y;
	dp(fx);dp(fy);if(se[fx].size()>se[fy].size())swap(se[fx],se[fy]);
	for(it=se[fx].begin();it!=se[fx].end();++it)
	{
		pll temp=*it;if(temp.second>lim)continue;
		it1=se[fy].lower_bound(mp(lim-temp.second+1,0));if(it1==se[fy].begin())continue;
		--it1;pll num=*it1;temp.second=num.second;
		se[x].insert(mp(temp.first+up[x],temp.second+up[x]));
	}tp=0;
	for(it=se[x].begin();it!=se[x].end();++it)
	{
		pll temp=*it;
		if(temp.first!=temp.second)swap(temp.first,temp.second),sta[++tp]=temp;
	}
	while(tp)se[x].insert(sta[tp--]);LL pre=-1;
	for(it=se[x].begin();it!=se[x].end();++it)
	{
		pll temp=*it;
		if(temp.first==pre)continue;pre=temp.first;
		if(!tp||temp.second<sta[tp].second)sta[++tp]=temp;
	}se[x].clear();
	while(tp)se[x].insert(sta[tp--]);
}
bool check(LL limit)
{
	lim=limit;dp(1);
	if(se[1].size())return true;
	return false;
}
int main()
{
//	freopen("a.in","r",stdin);
	n=read();mnsum=999999999;
	for(int i=2;i<=n;i++)
	{
		int x=read();up[i]=read();
		ins(x,i,up[i]);mxsum+=up[i];mnsum=min(mnsum,1LL*up[i]);
	}
//	pr2(check(16));
	LL l=mnsum,r=mxsum,ans;
	while(l<=r)
	{
		LL mid=(l+r)>>1;
		if(check(mid))ans=mid,r=mid-1;
		else l=mid+1;
	}pr2(ans);
	return 0;
}


Measured memory_bytes: 81152
while True:
    m, f, r = map(int, input().split())
    if m == -1 and f == -1:
        break
    if m == -1 or f == -1:
        print("F")
    elif m + f >= 80:
        print("A")
    elif 65 <= (m+f) < 80:
        print("B")
    elif 50 <= (m+f) < 65 or r >= 50:
        print("C")
    elif 30 <= (m+f) < 50:
        print("D")
    elif m+f < 30:
        print("F")


Measured memory_bytes: 5596