akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int n, q, pos, val, u, v, dp[300030], vis[300030];
vector<int> g[300030];
void dfs(int x, int csum) { //cout << x << "," << csum << endl;
    vis[x] = 1;
    for (auto nbr: g[x]) {
        if (vis[nbr] == 1) continue;
        int tmp = dp[nbr];
        dp[nbr] += csum;
        
        dfs(nbr, tmp+csum);
    }
}
int main() {ios::sync_with_stdio(false);cin.tie(0);
    cin >> n >> q; 
    for (int i = 0; i < n-1; i++) cin >> u >> v, g[u].push_back(v), g[v].push_back(u);
    for (int i = 0; i <= n + 1; i++) dp[i] = vis[i] = 0;
    while (q--) {
        cin >> pos >> val;
        dp[pos] += val;
    }
    //for (int i = 1; i <= n; i++) cout << dp[i] << " ";cout<<endl;
    dfs(1, dp[1]);
    for (int i = 1; i <= n; i++) cout << dp[i] << " ";
  return 0;
}

Measured memory_bytes: 23936
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,a,b,c,d,i,ans;
    cin>>n>>a>>b>>c>>d;
    if(n%a==0){
        if(n%c==0){
            if(n/a*b>n/c*d)ans=n/c*d;
            else ans=n/a*b;
        }else{
            if(n/a*b>(n/c+1)*d)ans=(n/c+1)*d;
            else ans=n/a*b;
        }
    }else{
        if(n%c==0){
            if((n/a+1)*b>n/c*d)ans=n/c*d;
            else ans=(n/a+1)*b;
        }else{
            if((n/a+1)*b>(n/c+1)*d)ans=(n/c+1)*d;
            else ans=(n/a+1)*b;
        }
    }
    cout<<ans<<endl;

}


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

int main(){

int X;
cin >> X;

int a,b=0;

if(X>=500){
a=X/500;
X=X%500;
}

if(X>=5){
b=X/5;
X=X%5;
}

cout << a*1000+b*5 << endl;
}

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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;

Node root, NIL;
int maxh;

Node treeSearch(Node u, int k){
  while( u != NIL && k != u->key ){
    if ( k < u->key ) u = u->left;
    else u = u->right;
  }
  return u;
}

void insert(int k);

void inorder(Node u);

void preorder(Node u);

int main(){
  
  int n, i, m;
  char com[20];
  
  scanf("%d", &n);
  maxh = 0;
  for( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &m);
      
      Node t = treeSearch(root, m);
      if ( t != NIL ){
	printf("yes\n");
      }else printf("no\n");
    }else if ( com[0] == 'i' ){
      scanf("%d", &m);
      insert(m);
    }else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }
  return 0;
}

void insert(int k){
  int H;
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while( x != NIL ){
    y = x;
    if ( z->key < x->key ){
      x = x->left;
    } else {
      x = x->right;
    }
  }

  z->parent = y;
  if ( y == NIL ){
    root = z;
  } else {
    if (z->key < y->key) {
      y->left = z;
    } else {
      y->right = z;
    }
  }
}

void inorder(Node u){
  if ( u == NIL ) return;
  inorder(u->left);
  printf(" %d", u->key);
  inorder(u->right);
}
void preorder(Node u){
  if ( u == NIL ) return;
  printf(" %d", u->key);
  preorder(u->left);
  preorder(u->right);
}



Measured memory_bytes: 20552
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) {rep(_,v.size())cout<<" "<<v[_];puts("");}
#define show2d(v) {rep(__,v.size())show1d(v[__]);}
using namespace std;
//kaewasuretyuui
typedef long long ll;
// #define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
// int dx[]={0,1,0,-1};
// int dy[]={1,0,-1,0};//RDLU
#define yes puts("YES")
#define no puts("NO")

//nCr mod m
#define MOD 1000000007
#define M 1000000
vector<ll> fact,ifact;
bool h=false;
// a^b mod MOD
ll powmod(ll a,ll b,ll m=MOD){
	ll out=1;
	ll p=a%m;
	while(b){
		if(b&1)out=out*p%m;
		p=p*p%m;
		b>>=1;
	}
	return out;
}
void init(){
	h=true;
	fact=ifact=vector<ll>(M);
	fact[0]=fact[1]=1;
	ifact[0]=ifact[1]=1;
	loop(i,2,M)fact[i]=fact[i-1]*i%MOD;
	loop(i,2,M)ifact[i]=powmod(fact[i],MOD-2,MOD);
}
//nCr
ll nCr(ll n,ll r,ll m=MOD){
	if(!h)init();
	if(n<0||r<0||n<r)return 1;//??????
	ll out=fact[n]*ifact[r]%MOD*ifact[n-r]%MOD;
	return out;
}

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

	int n,m,k;
	cin>>n>>m>>k;
	vvi in(k,vi(2));
	rep(i,k)cin>>in[i][0]>>in[i][1];
	in.pb({1,1});in.pb({n,m});
	sort(all(in));
	vi dp(in.size());
	dp[0]=-1;
	rep(i,in.size())loop(j,i+1,in.size()){
		int x=in[j][0]-in[i][0],y=in[j][1]-in[i][1];
		if(x>=0&&y>=0)
			(dp[j]+=MOD-dp[i]*nCr(x+y,x)%MOD)%=MOD;
	}
	cout<<dp[in.size()-1]<<endl;
}


Measured memory_bytes: 16128
#include <iostream>
using namespace std;
#include<string>
#define ll long long

#define fr(i,a,b) for(ll i=a;i<b;i++)
#define ffr(i,a,b) for(ll i=a;i>=b;i--)
#include<bits/stdc++.h>
#include<vector>
#define vl vector<ll>
#define pb push_back
//const ll N=1e5+5;




// int solve(){
    
// }


int main(){
    char al;
    cin>>al;
    if(al>='A'&&al<='Z')
    cout<<'A';
    if(al>='a'&&al<='z')
    cout<<'a';
	return 0;
}

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

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            var l = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int a = l [0], b = l [1], c = l [2];
            var ans = false;
            if ((c >a && c < b) || (c > b && c < a)) ans = true;
            Console.WriteLine(ans ? "Yes" : "No");
        }
    }
}


Measured memory_bytes: 13268
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream> 
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
using namespace std;
#define eps 0.000000001
#define LONG_INF 10000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define REP(i,n) for(long long i = 0;i < n;++i)
int grid[1000][1000] = {};
int main() {
	int n;
	cin >> n;
	vector<int> a;
	REP(i, n) {
		int hoge;
		cin >> hoge;
		a.push_back(hoge);
	}
	sort(a.begin(), a.end());
	if (a[a.size() - 1] - a[0] >= 2) {
		cout << "No" << endl;
		return 0;
	}
	int color = a[a.size()-1];
	for (int i = 1;i < a.size();++i) {
		if (a[i] != a[i - 1]) {
			color -= i;
			if (color >= 1 && (a.size() - i) / 2 >= color) {
				cout << "Yes" << endl;
				return 0;
			}
			else {
				cout << "No" << endl;
				return 0;
			}
		}
	}
	if (a.size()-1 == color||a.size() / 2 >= color) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 892
#!/usr/bin/env python3
import sys
from bisect import bisect_left


## 約数の列挙O(N)
def divisor(n): #nの約数を全て求める
    i = 1
    table = []
    while i * i <= n:
        if n%i == 0:
            table.append(i)
            table.append(n//i)
        i += 1
    table = list(set(table))
    return table

def solve(N: int, M: int):
    if M%N == 0:
        print(M//N)
        return

    max_answer = M//N
    divisors = divisor(M)
    divisors.sort()

    index = bisect_left(divisors,max_answer)
    if index == 0:
        print(1)
        return 
    print(divisors[index-1])


    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    solve(N, M)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		int A = scan.nextInt();
		int B = scan.nextInt();
		int count = 1;
		int sum = 0;

		while(count < B) {
			count--;
			count += A;
			sum++;
		}

		System.out.println(sum);
	}

}

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

int rec(int n, int count) {
    if (n < 10) return count;
    int mx = 0;
    for (int i=10; i<=1000000; i*=10) {
        mx = max(mx, (n / i) * (n % i));
    }
    return rec(mx, count + 1);
}

int main() {
    int q, n;
    cin >> q;
    for (int i=0; i<q; ++i) {
        cin >> n;
        cout << rec(n, 0) << endl;
    }
    return 0;
}

Measured memory_bytes: 1164
#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
#include<utility>
#include<string>
#include<utility>
#include<iomanip>
#include<bitset>
#include<math.h>
using namespace std;

int main(){

	int n,k;
	cin >> n >> k;
	vector<int> v (n);

	int ans = 0;
	for (int i = 0; i < n; i++)
	{
		cin >> v[i];
	}
	
	for (int i = 0; i < n; i++)
	{
		if(v[i] >= k){
			ans ++;
		}
	}
	
	cout << ans << endl;

}


Measured memory_bytes: 640
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cmath>
#include<vector>
typedef long long ll;
using namespace std;
const int MOD=1e9+7;
int N;
ll ans=0;

int main(void) {
	cin >> N;
	cout << 1110 - N << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A,B,C,D,E;
  cin >> A;
  B=A/1000;//1000
  C=A%1000/100;//100
  D=(A%1000)%100/10;//10
  E=((A%1000)%100)%10;//1
  
   if (B!=C && D!=E) {
    cout << "No" << endl;
  }
  else if (C!=D){
    cout << "No" << endl;
  }
  else {
  	cout << "Yes" << endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<functional>
#include <string>
#include<iomanip>
#include<cstdio>
#include<math.h>
#include<stack>
#include<queue>
#include<cstring>
#include<vector>
typedef long long int ll;
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define EREP(i,n) for(int i=(n-1);i>=0;--i)
#define D(n,retu) REP(i,n){cin>>retu[i];}
#define mod 1000000007
#define MIN -93193111451418101
#define INF 931931114518101
#define double long double
using namespace std;
typedef pair<ll, ll>P;
template<typename T>
void fill_all(T& arr, const T& v) {
	arr = v;
}
template<typename T, typename ARR>
void fill_all(ARR& arr, const T& v) {
	for (auto& i : arr) { fill_all(i, v); }
}
#define MAX_NUM 50
long long comb[MAX_NUM + 1][MAX_NUM + 1];

ll par[100000], depth[100000];
static void calc_comb()
{
	for (uint32_t i = 0; i <= MAX_NUM; i++) {
		for (uint32_t j = 0; j <= i; j++) {
			if ((j == 0) || (i == j)) {
				comb[i][j] = 1;
			}
			else {
				comb[i][j] = comb[i - 1][j - 1] + comb[i - 1][j];
			}
		}
	}
}
#define yo 100001
//------------------変数-----------------------//

//-------------------関数----------------------//

ll gcd(ll a, ll b)
{
	ll c;
	while (a != 0) {
		c = a; a = b%a;  b = c;
	}
	return b;
}
ll lcm(ll m, ll n)
{
	// 引数に０がある場合は０を返す
	if ((0 == m) || (0 == n))
		return 0;

	return ((m / gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}//lcm
int main() {
	ll a, b, c, d, e, f, aa, bb, cc, dd;
	cin >> a >> b >> c >> d >> e >> f;
	a *= 100; b *= 100;
	ll hoge = lcm(a, lcm(b, (lcm(c, d))));
	//cout << hoge << endl;
	aa = hoge / a; bb = hoge / b;
	cc = hoge / c; dd = hoge / d;
	double maxa = 0;
	ll maxmizu = 0, maxsato = 0;
	REP(i, aa + 1) {
		if (i*a > f) { break; }
		REP(j, bb + 1) {
			if (i*a + j*b > f) { break; }
			REP(k, cc + 1) {
				double st = k*c;
				double aaaaa = e;
				if (aaaaa / 100 * i*a + j*b < st) { break; }
				REP(l, dd + 1) {
					double mizu = i*a + j*b;
					double sato = k*c + l*d;
					/*	cout << mizu << " " << sato << endl;
					cout << i << " " << j << " " << k << " " << l << endl;*/
					if ((l == 0 && k == 0)) { continue; }
					if (j == 0 && i == 0) { continue; }
					if (mizu + sato > f) { break; }
					double ee = e,keidaroo=100;
					if (ee / keidaroo * mizu < sato) { break; }
					if (maxa < sato / (sato + mizu)) {
						maxa = sato / (sato + mizu);
						maxmizu =mizu+sato; maxsato = sato;
					}
				}
			}
		}
	}
	if (maxmizu == 0) { cout << a << " " << maxsato << endl; return 0; }
	cout << maxmizu << " " << maxsato << endl;
}



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

int main() {
  int n; cin >> n;
  vector<int> a(n);
  for(int i = 0; i < n; i++) cin >> a[i];
  sort(a.begin(), a.end());
  cout << a.at(n-1) - a.at(0);
}


Measured memory_bytes: 3596
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=105;
int n,m,ans,a[N];
int main()
{
	scanf("%d%d",&n,&m);
	for (int i=1;i<=n;i++) scanf("%d",&a[i]);
	sort(a+1,a+n+1);
	for (int i=1;i<=n;i++)
	{
		if (m>=a[i])
		{
			if (i==n)
			{
				if (m==a[i]) ++ans; break;
			}
			m-=a[i]; ++ans;
		}
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
//using System.Text;
//using System.Text.RegularExpressions;
//using System.Globalization;
//using System.Diagnostics;
using static System.Console;
//using System.Numerics;
//using static System.Math;
//using pair = Pair<int, int>;

class Program
{
    static void Main()
    {
        //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
        new Program().solve();
        Out.Flush();
    }
    Scanner cin = new Scanner();
    readonly int[] dd = { 0, 1, 0, -1, 0 }; //→↓←↑
    readonly int mod = 1000000007;
    void chmax<T>(ref T a, T b) where T : IComparable<T> { a = a.CompareTo(b) < 0 ? b : a; }
    void chmin<T>(ref T a, T b) where T : IComparable<T> { a = a.CompareTo(b) < 0 ? a : b; }

    void solve()
    {
        int N = cin.nextint;
        if (N == 1)
        {
            WriteLine(0);
            return;
        }
        var A = cin.scanint;
        for (int i = 0; i < N; i++)
        {
            A[i] -= i - 1;
        }
        Array.Sort(A);
        long ans = 0;
        for (int i = 0; i < N; i++)
        {
            ans += Math.Abs(A[i] - A[N / 2]);
        }
  
        long tmp = 0;
        for (int i = 0; i < N; i++)
        {
            tmp += Math.Abs(A[i] - A[N / 2 - 1]);
        }

        WriteLine(Math.Min(ans, tmp));
    }

}

class Scanner
{
    string[] s; int i;
    char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] scan { get { return ReadLine().Split(); } }
    public int[] scanint { get { return Array.ConvertAll(scan, int.Parse); } }
    public long[] scanlong { get { return Array.ConvertAll(scan, long.Parse); } }
    public double[] scandouble { get { return Array.ConvertAll(scan, double.Parse); } }
    public string next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = ReadLine();
            while (st == "") st = ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return next;
        }
    }
    public int nextint { get { return int.Parse(next); } }
    public long nextlong { get { return long.Parse(next); } }
    public double nextdouble { get { return double.Parse(next); } }
}

Measured memory_bytes: 30812
n,m,q=map(int,input().split())
a=[[0]*(n+1) for _ in range(n+1)]
for _ in range(m):
  l,r=map(int,input().split())
  a[l][r]+=1
for i in range(n+1):
  for j in range(n):
    a[i][j+1]+=a[i][j]
for i in range(n):
  for j in range(n+1):
    a[i+1][j]+=a[i][j]
for _ in range(q):
  q,p=map(int,input().split())
  print(a[p][p]-a[p][q-1]-a[q-1][p]+a[q-1][q-1])

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

int n,m,k;

char a[6][6];
char b[6][6];
void same()
{
    for(int i= 0 ;i<n ;i++)
    {
        for(int j =0 ; j<m ;j++)
         b[i][j] = a[i][j];
    }
}
void set2(int i , int j)
{
    for(int x = 0 ; x < n ; x++)
    {
        if(i & (1<<x))
        {
            for(int y = 0 ; y<m ; y++)
             b[x][y] =  '$';
        }
    }

    for(int p =0 ; p<m ;p++)
    {
        if(j & (1 << p))
        {
            for(int q =0 ; q<n ;q++)
            b[q][p] = '$';
        }
    }
}
bool check()
{
    int p =0 ;
    for(int i =0 ;i<n ;i++)
    {
        for(int j =0 ; j<m ;j++)
        {
            if(b[i][j] == '#')
             p++;
        }
    }
    return p == k ;
}
int main()
{
    
    cin>>n>>m>>k;
    

    for(int i = 0 ; i<n ; i++)
    {
        for(int j = 0 ; j<m ;j++)
        {
            cin>>a[i][j];
        }
    }
    int count =0;
    for(int i = 0 ; i < (1 << n) ; i++)
    {
        for(int j = 0 ; j< (1 << m); j++)
        {
            same();
            set2(i , j);

            if(check())
            {
                count++;
            }
        }
    }
    cout<<count<<endl;
}

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

int Data[4][3][10] = { 0 };

int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; ++i) {
		int b, f, r, v;
		cin >> b >> f >> r >> v;

		Data[b - 1][f - 1][r - 1] += v;
	}

	for (int i = 0; i < 4; ++i) {
		for (int i2 = 0; i2 < 3; ++i2) {
			for (int i3 = 0; i3 < 10; ++i3) {
				cout << " " << Data[i][i2][i3];
			}
			cout << endl;
		}
		if (i < 4 - 1) {
			for (int j = 0; j < 20; ++j) {
				cout << "#";
			}
			cout << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 3088
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int a,b,c,d,e;
    while(~scanf("%d",&a))
    {
    b=a/100;
    c=a/10%10;
    d=a%10;
    e=d*100+c*10+b;
    if(e==a)printf("Yes\n");
    else printf("No\n");
}
    return 0;
}

Measured memory_bytes: 128
/*
 ~ author - Sayan Bose
 ~ Do Good Die Great
*/
#include<bits/stdc++.h>
#define ll long long
#define amaterasu ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
using namespace std;

void solve()
{
	int n;
	cin >> n;
	cout << 2*n*3.14 << '\n';
}

int main()
{
	amaterasu
	solve();
	return 0;
}


Measured memory_bytes: 3816
#include <bits/stdc++.h>
#define Phuong_ ios_base::sync_with_stdio(0); cin.tie(0);
#define pb push_back
#define mp make_pair

/// easy access -------------
using namespace std;
using ll = long long;
using ld = long double;
typedef pair<int,int> pii;
///-------------------------

/// problem's variable---------------


///--------------------------

bool check(string x)
{
    int head=0;
    int tail =x.size()-1;
    while (head<=tail)
    {
        if (x[head]!=x[tail]) return false;
        head++;
        tail--;
    }
    return true;
}

int main()
{
    Phuong_;
    string s;
    cin >> s;
    int n = s.size();
    string u="";
    bool f1=false;
    for(int i=0; i<n; ++i)
    {
        if (i==(n-1)/2)
        {
            f1=check(u);
            u="";
            continue;
        }
        u+=s[i];
    }
    if (check(u)&& f1 && check(s)) cout << "Yes"; else cout << "No";
    return 0;
}



Measured memory_bytes: 256
//Created Time:2019年12月18日 星期三 18时32分15秒
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>

using namespace std;

long long n;
int a[2002];
int cnt;

int main(){
	cin >> n; ++n;
	int l = 0, r = 50; bool flag = false;
	for(int i = 39, pos = 1; ~i; --i){
		long long p = 1ll << i;
		if(p > n) continue;
		if(p & n){
			if(flag)
				++cnt, a[++l] = pos++;
			else flag = true;
		}
		if(i) a[++r] = pos++, ++cnt;
	}
	cout << cnt + 100 << endl;
	for(int i = l; i; --i) cout << a[i] << ' ';
	for(int i = 51; i <= r; ++i) cout << a[i] << ' ';
	for(int i = 1; i <= 100; ++i) cout << i << ' ';
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1000003 ;

int main(){
  int a,b,k;
  cin >> a >> b >> k;
  int cnt=0;
  for(int i=a;i>=0;i--){
    if(a%i==0 && b%i==0)cnt++;
    if(cnt==k){
      cout << i << endl;
      return 0;
    }
  }
return 0;}

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

const int N = 1e5 + 100, inF = N;

int n, k, ans, out[N], dis[N];
bool mark[N];
vector<int> in[N];

void dfs(int v, bool change = false) {
	mark[v] = change;
	for (int u: in[v]) 
		if(mark[u] == false) {
			dis[u] = dis[v] + 1;
			dfs(u, change);
		}
}

int main() {
	ios::sync_with_stdio(false), cin.tie(0);
	cin >> n >> k;
	cin >> out[0];
	ans += (out[0] != 1);
	
	for (int i = 1; i < n; i++) {
		cin >> out[i];
		in[--out[i]].push_back(i);
	}
	dfs(0);
	vector<int> vec(n);
	iota(vec.begin(), vec.end(), 0);
	sort(vec.begin(), vec.end(), [](int a, int b) {
		return dis[a] > dis[b];
	});
        //////////////////////////////////////////////////////////////////////////////////
	for (int u: vec) {
		if(mark[u] || dis[u] <= k)
			continue;
		for (int i = 0; i < k - 1; i++)
			u = out[u];
		ans++;
		dfs(u, true);
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 11648
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0; i<(int)(n); ++i)

using namespace std;
typedef vector<int> Node;
typedef vector<Node> Graph;
Graph G, RG;

void dfs(int u, vector<bool>& used, vector<int>& order) {
    if(used[u]) return;
    used[u] = true;
    for(int v : G[u]) {
        dfs(v, used, order);
    }
    order.push_back(u);
}

void rdfs(int u, int k, vector<bool>& used, vector<int>& node) {
    if(used[u]) return;
    used[u] = true;
    node[u] = k;
    for(int v : RG[u]) {
        rdfs(v, k, used, node);
    }
}

int main(){
    int N, M, T;
    while(cin >> N >> M >> T && N > 0) {
        vector<int> p(N);
        vector<int> t(N);
        vector<int> r(N);
        REP(i, N) cin >> p[i] >> t[i] >> r[i];

        G.assign(N, Node());
        RG.assign(N, Node());
        bool d[100][100] = {};
        REP(i, M) {
            int a, b;
            cin >> a >> b;
            a--; b--;
            G[a].push_back(b);
            RG[b].push_back(a);
            d[a][b] = true;
        }

        REP(k, N) REP(i, N) REP(j, N) if(d[i][k] && d[k][j]) d[i][j] = true;


        vector<int> order;
        vector<bool> used(N);
        REP(i, N) dfs(i, used, order);
        reverse(order.begin(), order.end());

        vector<int> node(N);
        used.assign(N, false);
        int V = 0;
        for(int v : order) if(!used[v]) rdfs(v, V++, used, node);

        vector<set<int>> SG(V);
        REP(i, N) for(int j : G[i]) if(node[i] != node[j]) {
            SG[node[i]].insert(node[j]);
        }

        int dp[100][10001] = {};
        REP(i, V) {
            REP(v, N) if(node[v] == i) {
                int b = 1;
                int rest = (d[v][v] ? r[v] : 1);
                while(rest > 0) {
                    int use = min(rest, b);
                    rest -= use;
                    b *= 2;
                    
                    int get = p[v] * use;
                    int cost = t[v] * use;

                    for(int j = T - cost; j >= 0; j--) {
                        dp[i][j + cost] = max(dp[i][j + cost], dp[i][j] + get);
                    }
                }
            }

            for(int j : SG[i]) {
                for(int k = 0; k <= T; k++) {
                    dp[j][k] = max(dp[j][k], dp[i][k]);
                }
            }
        }

        int ans = 0;
        REP(i, V) REP(j, T + 1) ans = max(ans, dp[i][j]);
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 5240
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

from collections import deque

n, q = map(int, readline().split())
graph = [[] for _ in range(n + 1)]
for i in range(n - 1):
    a, b = map(int, readline().split())
    graph[a].append(b)
    graph[b].append(a)
cnt = [0] * (n + 1)
for i in range(q):
    p, x = map(int, readline().split())
    cnt[p] += x


def dfs(s):
    check = [False] * (n + 1)
    stack = deque([s])
    while stack:
        now = stack.pop()
        check[now] = True
        for nxt in graph[now]:
            if check[nxt]:
                continue
            stack.appendleft(nxt)
            cnt[nxt] += cnt[now]


dfs(1)
print(*cnt[1:])


Measured memory_bytes: 56024
#include <iostream>
#include <tuple>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;

typedef tuple<int, int, int> TP;

int main()
{
	int N, M, t, s, d;
	while (cin >> N >> M, N || M) {
		vector< TP > vec;
		vec.reserve(M);
		for (int i = 0; i < M; i++) {
			cin >> t >> s >> d;
			vec.push_back(TP(t,s,d));
		}
		sort(vec.begin(), vec.end());
		set<int> cmp;
		cmp.insert(1);
		for (int i = 0; i < vec.size(); i++) {
			if (cmp.count(get<1>(vec[i]))) {
				cmp.insert(get<2>(vec[i]));
			}
		}
		cout << cmp.size() << endl;
	}
	return 0;
}

Measured memory_bytes: 3836
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cstring>
using namespace std;
#define ll long long
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define FORL(i,x) for(int i=head[x];i;i=nxt[i])
#define clr(x,y) memset(x,y,sizeof(x))
#define in(a) a=read()
#define out(a) printf("%d\n",a)
inline ll read(){
	char c=getchar();ll f=1,x=0;
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9')x=x*10+(c-'0'),c=getchar();
	return x*f;
}
#define mod 1000000007
#define maxn 1010
#define inf (1<<30)
ll a[maxn*maxn],b[maxn*maxn],v[maxn];
int main(){
	int n,m;
	in(n);in(m);
	FOR(i,1,n)in(v[i]);
	int num=0;
	FOR(i,1,n){
		ll s=0;
		FOR(j,i,n){
			s+=v[j];
			a[++num]=s;
		}
	}
	ll ans=0;
	FORD(i,50,0){
		int c=0;
		FOR(j,1,num)if(a[j]&(1ll<<i))b[++c]=a[j];
		if(c>=m){
			FOR(j,1,c)a[j]=b[j];
			num=c;
			ans+=(1ll<<i);
		}
	}
	printf("%lld\n",ans);
}

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

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

const ll MOD = 1e9 + 7;
const ll inf = 1LL<<60;
const int int_inf = 100000000;
const double eps = 1e-9;

const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
 
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

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

    int tmp = int(s.size())-1;
    bool ok = true;

    for (int i = 0; i < tmp/2;  i++) {
        if (s[i] != s[tmp-i]) ok = false;
    }
    for (int i = 0; i < tmp/2/2; i++) {
        if (s[i] != s[tmp/2-1-i]) ok = false;
    }
    for (int i = 0; i < tmp/2/2; i++) {
        if (s[tmp/2+1+i] != s[tmp-i]) ok = false;
    }
    if (ok) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}



Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::{Write, BufWriter};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

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

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

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

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

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

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

fn dfs(v: usize, g: &[Vec<usize>], memo: &mut [Option<usize>]) -> usize {
    if let Some(ans) = memo[v] { return ans; }
    let mut ma = 0;
    for &w in g[v].iter() {
        let sub = dfs(w, g, memo);
        ma = max(ma, sub + 1);
    }
    memo[v] = Some(ma);
    ma
}

fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }
    input! {
        n: usize,
        xy: [(usize1, usize1)],
    }
    let mut g = vec![Vec::new(); n];
    for (x, y) in xy {
        g[x].push(y);
    }
    let mut memo = vec![None; n];
    for i in 0 .. n { dfs(i, &g, &mut memo); }
    puts!("{}\n", memo.iter().max().unwrap().unwrap());
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


Measured memory_bytes: 20732
grid = [list(map(int, input().split())) for _ in range(3)]
ans = 'Yes'

b1 = 0
a1 = grid[0][0]
a2 = grid[1][0]
a3 = grid[2][0]

b2 = grid[0][1] - a1
b3 = grid[0][2] - a1

if b2 + a2 != grid[1][1]:
    ans = 'No'

if b2 + a3 != grid[2][1]:
    ans = 'No'

if b3 + a2 != grid[1][2]:
    ans = 'No'

if b3 + a3 != grid[2][2]:
    ans = 'No'

print(ans)

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

#define GYOU_MAX 256
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define PRINT(str) printf(#str "\n")
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define pi acos(-1.0)
#define v_pri(val) printf("%d\n",val);
#define s_pri(str) printf("%s\n",str);
#define v_sca(x) scanf("%d",&x);
#define s_sca(x) scanf("%s",x);

typedef long long int ll;


/*
puts("コメント");
//*/

int main(void) {
	int N, M;
	v_sca(N);
	v_sca(M);
	int p[100000];
	char S[100000][3];


	int pena[100001] = { 0 };
	int ac[100001] = { 0 };
	int x;
	int max = 0;
	rep(i, M) {
		v_sca(p[i]);
		s_sca(S[i]);

		if (p[i] > max) {
			max = p[i];
		}

		x = p[i];
		if (ac[x] != 1 && strcmp(S[i], "WA") == 0) {
			pena[x] ++;
		}

		if (ac[x] != 1 && strcmp(S[i], "AC") == 0) {
			ac[x]++;
		}
	}

	int sum1 = 0, sum2 = 0;
	rep(i, max + 1) {
		if (ac[i] == 0) {
			continue;
		}
		sum1 += ac[i];
		sum2 += pena[i];
	}
	printf("%d %d\n", sum1, sum2);


	return 0;
}

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

XY = [tuple(map(int,input().split())) for i in range(N)]


dots = XY[:]

import sys
INT_MAX = sys.maxsize


def sub_f(x, ans_list):
    right_x, left_x = x[0], x[1]
    ans = INT_MAX
    for ((_, under_y), (_, top_y)) in itertools.combinations(dots, 2):
        if under_y > top_y:
            under_y, top_y = top_y, under_y
        counter = 0
        for d_x, d_y in dots:
            if  (left_x <= d_x) and (d_x <= right_x) and (under_y <= d_y) and (d_y <= top_y):
                counter += 1

        if counter >= K:
            area = (top_y-under_y) * (right_x-left_x)
            ans = min(ans, area)
    #return ans
    ans_list.append(ans)

import itertools
multiprocessing_inputs = []
for ((left_x, _), (right_x, _)) in itertools.combinations(dots, 2):
    if left_x > right_x:
        left_x, right_x = right_x, left_x
    
    multiprocessing_inputs.append((right_x, left_x))
    #ans_list.append(sub_f(right_x, left_x))


import threading
ans_list = []
threadlist = []
for x in multiprocessing_inputs:
    #ans_list = p.map(sub_f, multiprocessing_inputs)
    th = threading.Thread(target=sub_f, args=(x, ans_list))
    threadlist.append(th)
for th in threadlist:
    th.start()
for th in threadlist:
    th.join()

ans = min(ans_list)
print(ans)

Measured memory_bytes: 53108
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
#include<cmath>

using namespace std;
string st;
long long ans;
char ch[20]={'C','O','D','E','F','E','S','T','I','V','A','L','2','0','1','6'};
int main()
{
 cin>>st;
 for(int i=0;i<16;i++)
 {
  if(st[i]!=ch[i]) ans++;
 }
 cout<<ans;
 return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 1; i <= (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
int main() {
  int N;
  cin >> N;
  int A = 0;
  int ans = 0;
  rep(i, N - 1) {
    A = N / i;
    if(A * i == N) {
      A--;
    }
    ans += A;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3636
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

const (
	initialBufSize = 10000
	maxBufSize     = 10000000
)

var (
	sc = func() *bufio.Scanner {
		sc := bufio.NewScanner(os.Stdin)
		buf := make([]byte, initialBufSize)
		sc.Buffer(buf, maxBufSize)
		sc.Split(bufio.ScanWords)
		return sc
	}()
)

func nextString() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func nextFloat() float64 {
	sc.Scan()
	f, e := strconv.ParseFloat(sc.Text(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func main() {
	n := nextInt()
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = nextInt()
	}

	sort.Ints(a)
	flags := make(map[int]bool)
	dup := make(map[int]bool)
	ok := make(map[int]bool)
	for _, v := range a {
		flag := true
		for i := 1; i*i <= v; i++ {
			if v%i == 0 {
				if flags[i] {
					flag = false
				}
				if i*i != v {
					if flags[v/i] {
						flag = false
					}
				}
			}
		}
		if ok[v] {
			dup[v] = true
		}
		if flag && !flags[v] {
			ok[v] = true
		}
		flags[v] = true
	}
	fmt.Println(len(ok) - len(dup))
}


Measured memory_bytes: 17312
n = int(input())
s = str(input())
c = 0
from collections import deque
res = deque([])
for i in range(n):
    if s[i] =='(':
        c += 1
    else:
        c -= 1
    if c < 0:
        res.appendleft('(')
        c = 0
    res.append(s[i])
if c > 0:
    res.append(')'*c)
print(''.join(list(res)))


Measured memory_bytes: 64720
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/adaptor/indexed.hpp>

using namespace std;
using namespace boost::adaptors;
using namespace std::string_literals;
using ll = int64_t;
using vecint = vector<int>;
using vecll = vector<ll>;
using boost::irange;

int main()
{
  char ch;
  cin>>ch;
  ++ch;
  cout<<ch<<endl;
  return 0;
}


Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int n;
string a,b;
vector<int>va,vb;
int main(){
	cin>>n;
	cin>>a>>b;
	char ch; int len;
	for(int i=0;i<a.size();i++){
		if(i == 0){
			ch = a[i];
			len = 1;
		}
		else if(ch == a[i]) len++;
		else{
			va.pb(len);
			ch = a[i];
			len = 1;
		}
	}
	va.pb(len);
	
	for(int i=0;i<b.size();i++){
		if(i == 0){
			ch = b[i];
			len = 1;
		}
		else if(ch == b[i]) len++;
		else{
			vb.pb(len);
			ch = b[i];
			len = 1;
		}
	}
	vb.pb(len);
	//cout<<va.size()<<" "<<vb.size()<<endl;
	int ans = INF;
	int sz = va.size();
	int sz2 = vb.size();
	for(int i=-sz;i<=sz2;i++){
		int fl = (i%2+2)%2;
		if((a[0]!=b[0])+fl == 1) continue;
		//cout<<i<<endl;
		//0..0(i個) va
		//vb
		vector<int>posa,posb;
		for(int ii=0;ii<va.size();ii++){
			rep(j,va[ii]) posa.pb(i+ii);
		}
		for(int ii=0;ii<vb.size();ii++){
			rep(j,vb[ii]) posb.pb(ii);
		}
		int x = 0;
		for(int i=0;i<posa.size();i++) x += abs(posa[i]-posb[i]);
		ans = min(ans,x);
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 384
#D
import math
a,b,x=map(int,input().split())
cap=a**2*b
ans=0
if x<=cap/2:
    n=2*x/(a*b)
    ans=math.atan(b/n)*180/math.pi
else:
    n=2*(cap-x)/(a**2)
    ans=math.atan(n/a)*180/math.pi
print(ans)

Measured memory_bytes: 3060
import java.util.Scanner;


public class Main{

	public static void main(String args[]){

		Scanner sc = new Scanner(System.in);

		int n=sc.nextInt();
		long a[]=new long[n];
		long total=0;
		long min=1000000000L;
		int count=0;
		for(int i=0;i<n;++i){
			a[i]=sc.nextLong();
			if(Math.abs(a[i])<min)min=Math.abs(a[i]);
			total=total+Math.abs(a[i]);

			if(a[i]<0)++count;
		}

		if (count%2==0)System.out.println(total);
		else System.out.println(total-2*min);
	}
}

Measured memory_bytes: 61148
H, W = map(int, input().split())
N = int(input())
a = list(map(int, input().split()))

b = []
for i in range(N):
    b.extend([i + 1] * a[i])

for i in range(H):
    row = b[i * W:(i + 1) * W]
    if i % 2 == 1:
        row.reverse()
    print(' '.join([str(c) for c in row]))


Measured memory_bytes: 3572
#include<cstdio>
#include<cstring>
using namespace std;
char s[111];
int main()
{
	bool bk=false;
	scanf("%s",s+1);
	for(int i=1;i<=strlen(s+1);i++)
	{
		if(s[i]=='C')bk=true;
		if(bk==true&&s[i]=='F')
		{
			printf("Yes\n");
			return 0;
		}
	}
	printf("No\n");
	return 0;
}

Measured memory_bytes: 128
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout
	cnt := 0

	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
		cnt = 2
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)
	solve(scanner, writer)
	for i := 0; i < cnt; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}

	writer.Flush()
}

func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	a := getNextInt(scanner)
	b := getNextInt(scanner)
	c := getNextInt(scanner)
	k := getNextInt(scanner)

	ans := minint(a, k)
	k -= minint(a, k)
	k -= minint(b, k)
	ans -= minint(c, k)
	fmt.Fprintln(writer, ans)
}

func minint(a, b int) int {
	if a < b {
		return a
	}
	return b
}


Measured memory_bytes: 1800
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define SPEED ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
typedef vector<int>vi;
typedef pair<int,int>pi;
typedef vector<pi>vpi;
typedef vector<vi>vvi;
#define double long double
#define pow powl
#define sqrt sqrtl
#define cbrt cbrtl
#define floor floorl
#define ceil ceill
#define pb push_back
#define ep emplace_back
#define PB pop_back
#define pf push_front
#define ef emplace_front
#define PF pop_front
#define mp make_pair
#define ub(a,b) upper_bound(all(a),b)-a.begin()
#define lb(a,b) lower_bound(all(a),b)-a.begin()
#define bs(a,b) binary_search(all(a),b)
#define mem(a,b) memset(a,b,sizeof(a))
#define in(a,n) FOR(i,0,n-1) cin>>a[i]
#define in1(a,n) FOR(i,1,n) cin>>a[i]
#define ff first
#define ss second
#define out(a,n) FOR(i,0,n-1) cout<<a[i]<<" ";cout<<endl;
#define out1(a,n) FOR(i,1,n) cout<<a[i]<<" ";cout<<endl;
#define clr(a) a.clear()
#define pow2(a) (1LL<<a)
#define all(a) a.begin(),a.end()
#define all1(a) a.begin()+1,a.end()
#define rall(a) a.rbegin(),a.rend()
#define rall1(a) a.rbegin(),a.rend()
#define sz(a) ((int)a.size())
#define FOR(i,a,b) for(auto i=a;i<=b;i++)
#define NFOR(i,a,b) for(auto i=a;i>=b;i--)
const int mod=1e9+7;

inline int add(int a,int b){return (a%mod + b%mod)%mod;}
inline int sub(int a ,int b){return (a%mod - b%mod + mod)%mod;}
inline int mul(int a,int b){return (a%mod * b%mod)%mod;}
inline int power(int a,int b,int MOD){int res=1;while(b){if(b&1){res*=a;res%=MOD;}a=a*a;a%=MOD;b>>=1;}return res;}

#define trace(x) cout<<#x<<" :: "<<x<<endl;
#define trace2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<endl;
#define trace3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<endl;
#define trace4(x,y,z,w) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\t"<<#w<<" :: "<<w<<endl;
clock_t time_p = clock();
void time()
{
  time_p = clock() - time_p;
  cerr << "Time elapsed : " << (double)(time_p)/CLOCKS_PER_SEC <<endl;
}
signed main()
{
	 ios_base::sync_with_stdio(false);
	 cin.tie(NULL);
	 cout.tie(NULL);
	 int n;
	 cin>>n;
	 map<int,int>m;
	 for(int i=0;i<n;i++)
	 {
	 	  int x;
	 	  cin>>x;
	 	  m[x]++;
	 }
	 for(auto &x:m)
	 {
	 	    if(x.second>2)
	 	    {
	 	    	   if(x.second&1)
	 	    	   {
	 	    	   	 m[x.first]=1;
	 	    	   }
	 	    	   else
	 	    	   {
	 	    	   	 m[x.first]=2;
	 	    	   	}
	 	    }
	 }
	 int res=0;
	 int count=0;
	 for(auto &x:m)
	 	if(x.second==1)
	 		res++;
	 	else
	 		count++;
	  res+=count;
	  if(count&1)
	  	res--;
	  cout<<res<<endl;
	  time();
	  return 0;
}

Measured memory_bytes: 4992
N=int(input())
H=list(map(int,input().split()))
dp=[0]*N
dp[0]=0
dp[1]=abs(H[1]-H[0])

for i in range(2,N):
    dp[i]=min(dp[i-2]+abs(H[i]-H[i-2]),dp[i-1]+abs(H[i]-H[i-1]))

print(dp[N-1])

Measured memory_bytes: 20656
#include<iostream>
#include<string>
#include <algorithm>

using namespace std;
int main()
{

    int n;
    cin >> n;

    int a[100];

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

    sort(a, a + n);

    int alice, bob;
    alice = 0;
    bob = 0;

    bool g = true;

    for (int i=n-1;i>=0;i--){
        if(g) {
            alice += a[i];
            g = false;
        }
        else{
            bob += a[i];
            g = true;
        }
    }

    cout << alice-bob;

    return 0;

}

Measured memory_bytes: 256
#include <iostream>

int main()
{

	int N;
	std::cin >> N;

	int h[101];
	int h_max=0;
	for (int i = 1; i < N + 1; i++) {
		std::cin >> h[i];
		if (h_max < h[i]) {
			h_max = h[i];
		}
	}

	int count = 0;
	int l_flag = 0;



	for(int num =1;num<h_max+1;num++){
		for (int i = 1; i < N + 1; i++) {//始端処理
			if (i==0 && h[i] != 0) {
				h[i]--;
				l_flag = 1;
			}
			else if (i == 0 && h[i] == 0) {//始端処理
			}
			else if (h[i] != 0) {
				h[i]--;
				l_flag = 1;
			}
			else {
				if (l_flag == 1) {
					count++;
					l_flag = 0;
				}
			}

			if (i == N && l_flag == 1) {//終端処理
				count++;
				l_flag = 0;
			}
		}
	}

	std::cout << count;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;

ll wrong[50][10];
ll pnum[50];
ll penalty[50];

struct P  {
    ll num;
    ll penalty;
    int id;
    P(ll num, ll p, int id) : num(num),penalty(p),id(id) {}
};

bool operator<(const P &a, const P&b ) {
    return a.num!=b.num?a.num>b.num:a.penalty!=b.penalty?a.penalty<b.penalty:
        a.id<b.id;
}
int main() {
    int T,PP,R;
    while(cin>>T>>PP>>R,T||PP||R) {
        memset(wrong,0,sizeof(wrong));
        memset(pnum,0,sizeof(pnum));
        memset(penalty,0,sizeof(penalty));
        for (int i=0; i<R; ++i) {
            int t, p, time;
            string s;
            cin >> t >> p >> time >> s;
            t--;p--;
            if (s == "WRONG") {
                wrong[t][p]++;
            } else {
                penalty[t] += wrong[t][p]*1200 + time;
                pnum[t]++;
            }
        }
        vector<P> v;
        for (int i=0; i<T; ++i) {
            v.push_back(P(pnum[i], penalty[i], i));
        }
        sort(v.begin(), v.end());
        for (int i=0; i<T; ++i) {
            cout << v[i].id+1 << " " << v[i].num << " " << v[i].penalty << endl;
        }
    }
}

Measured memory_bytes: 940
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())

using namespace std;
typedef long long ll;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const int INF = 1001001001;
const long long INFL = (1LL<<60);
const double eps = (1e-9);

int main(int argc, char* argv[])
{
  int n;
  cin >> n;
  map<int, int> m;

  rep(i, n) {
    int a;
    cin >> a;
    m[a]++;
    if (m[a] == 3) m[a] = 1;
    if (m[a] == 4) m[a] = 2;
  }

  int nums = m.size();
  int num_even = 0;
  for (auto itr = m.begin(); itr != m.end(); itr++) {
    if (itr->second == 2) {
      num_even++;
      if (num_even == 2) num_even = 0;
    }
  }

  if (num_even != 0) {
    cout << nums - 1 << endl;
  } else {
    cout << nums << endl;
  }

  return 0;
}


Measured memory_bytes: 4992
#include <cstdio>
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <cmath>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#define rep(i,n) for (int i=0;i<n;i++)
using ll = long long;
using namespace std;

void solve(){

}
int main (){
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll n;
    cin >> n;
    ll ans = 1000000000000000;
    rep(i,5){
        ll m;
        cin >> m;
        ans = min(ans,m);
    }
    cout << (n+ans-1)/ans + 4 << endl;

    return 0;
}

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

int main()
{
    ll N,M;
    cin >> N >> M;
    ll H[N];
    ll A[M],B[M];
    ll num[N];
    for(ll i=0;i<N;i++)cin >> H[i];
    for(ll i=0;i<M;i++)cin >> A[i] >> B[i];
    for(ll i=0;i<N;i++)num[i]=1;
    for(ll i=0;i<M;i++){
        if(H[A[i]-1]>H[B[i]-1]){
            num[B[i]-1]=0;
        }else if(H[A[i]-1]<H[B[i]-1]){
            num[A[i]-1]=0;
        }else if(H[A[i]-1]==H[B[i]-1]){
            num[A[i]-1]=num[B[i]-1]=0;
        }
    }
    ll count=0;
    for(ll i=0;i<N;i++){
        if(num[i]==1){
            count++;
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 6760