akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<queue>
using namespace std;

struct Pos{int x,y,time;};

int park[10][10];

int px,py;
int n;
int sx,sy;

int dpx[12]={-1,0,1,2,2,2,1,0,-1,-2,-2,-2};
int dpy[12]={-2,-2,-2,-1,0,1,2,2,2,1,0,-1};
int pn=12;
int dsx[8]={-1,0,1,1,1,0,-1,-1};
int dsy[8]={-1,-1,-1,0,1,1,1,0};
int sn=8;

bool check(int x,int y){
  return 0<=x && x<10 && 0<=y && y<10;
}

string bfs(){
  queue<Pos>q;
  Pos now={px,py,0},next;
  q.push(now);
  while(!q.empty()){
    now=q.front();
    q.pop();
    if(now.time==n)return "OK";
    for(int i=0;i<pn;i++){
      next=now;
      next.x+=dpx[i];
      next.y+=dpy[i];
      next.time++;
      if(!check(next.x,next.y))continue;
      for(int j=0;j<sn;j++){
	int x=next.x+dsx[j];
	int y=next.y+dsy[j];
	if(!check(x,y))continue;
	if(park[x][y]==next.time)q.push(next);
      }
    }
  }

  return "NA";
}

int main()
{
  while(cin>>px>>py,px|py){
    for(int i=0;i<10;i++)for(int j=0;j<10;j++)park[i][j]=0;
    cin>>n;
    for(int i=1;i<=n;i++){
      cin>>sx>>sy;
      park[sx][sy]=i;
    }
    cout<<bfs()<<endl;
  }
}

Measured memory_bytes: 0
#include <stdio.h>

#define MAX 50000000

int parent(int i) {return i / 2;}
int left(int i) {return 2*i;}
int right(int i){return 2*i + 1;}
int H;
int A[MAX];

void maxHeap(int idx){
    int l = left(idx);
    int r = right(idx);
    int large;
    if(l <= H && A[idx] < A[l]){
        large = l;
    } else {
        large = idx;
    }

    if(r <= H && A[large] < A[r]){
        large = r;
    }

    if(large != idx){
        int tmp = A[idx];
        A[idx] = A[large];
        A[large] = tmp;
        maxHeap(large);
    }

}

void exec(){
    for(int i = H/2; i >= 1; i--) maxHeap(i);
}

int main(){
    int i;
    scanf("%d", &H);
    for(i = 1; i <= H; i++){
        scanf("%d", &A[i]);
    }

    exec();

    for(i = 1; i <= H; i++){
        printf(" %d", A[i]);
    }

    printf("\n");

    return 0;
}



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

const ll INF = 1001001001;

const double PI=3.141592653;

const ll sosu = 1000000007;//大きい素数

//提出のときに言語がc＋＋似合っていることを確認する

//絶対値の関数
int z(int a,int b){
  if(a>b) return a-b;
  else return b-a;
}

int main(){
  ll n;
  cin>>n;
  string ans;
  while(n){
    n--;
    ans+='a'+n%26;
    n/=26;
    
  }
  reverse(ans.begin(),ans.end());
  cout<<ans<<endl;

  

  return 0;
  
  
}


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

int main(){

	ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll n;
    cin >> n;
    vector<ll> v(n+1);
    for(ll i=1;i<=n;++i){

    	cin  >> v[i];
    }
    unordered_map<ll ,ll> m;

    for(ll i=1;i<=n;++i){
    	m[-v[i]+i]++;
    }
    ll ans = 0;

    for( ll i=1;i<=n;++i){
    	ll temp = i+v[i];
    	ans += m[temp];
    }

    cout << ans << "\n";


	return 0;
}

Measured memory_bytes: 20096
/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */

#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using Pair = pair<int64_t, int64_t>;

// std::cout << std::setprecision(20) << 1.1 << endl;

class UnionFind {
 public:
  explicit UnionFind(const int32_t n) : parents_(n, -1) {}
  UnionFind() = delete;

  bool IsRoot(const int32_t x) const {
    return (parents_[x] < 0);
  }

  int32_t FindRoot(const int32_t x) {
    if (IsRoot(x)) {
      return x;
    }
    parents_[x] = FindRoot(parents_[x]);
    return parents_[x];
  }

  bool Unite(const int32_t x, const int32_t y) {
    int32_t root_1 = FindRoot(x);
    int32_t root_2 = FindRoot(y);
    if (root_1 == root_2) {
      return false;
    }
    if (parents_[root_1] > parents_[root_2]) {
      std::swap(root_1, root_2);
    }
    parents_[root_1] += parents_[root_2];
    parents_[root_2] = root_1;
    return true;
  }

  bool IsSame(const int32_t x, const int32_t y) {
    return FindRoot(x) == FindRoot(y);
  }

  int32_t Size(const int32_t x) {
    return -1 * parents_[FindRoot(x)];
  }

 private:
  std::vector<int32_t> parents_;
};

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

  int64_t N, M, K;
  cin >> N >> M >> K;
  UnionFind uf(N + 1);
  // const int64_t L = static_cast<int64_t>(T.length());
  vector<int32_t> number_of_friends(N + 1, 0);
  vector<set<int32_t>> block_list(N + 1);
  for (int64_t i = 0; i < M; ++i) {
    int32_t a, b;
    cin >> a >> b;
    uf.Unite(a, b);
    ++number_of_friends[a];
    ++number_of_friends[b];
  }
  for (int64_t i = 0; i < K; ++i) {
    int32_t c, d;
    cin >> c >> d;
    block_list[c].insert(d);
    block_list[d].insert(c);
  }
  for (int64_t i = 1; i <= N; ++i) {
    int32_t potential = uf.Size(i) - number_of_friends[i] - 1;
    for (const int32_t block : block_list[i]) {
      if (uf.IsSame(i, block)) {
        --potential;
      }
    }
    if (i != 1) {
      cout << " ";
    }
    // cerr << N << ", " << uf.Size(i) << ", " << static_cast<int32_t>(block_list[i].size()) << endl;
    cout << potential;
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 15744
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;

int main()
{
	int n,a;
	string s;
	vector<pair<pair<string,int>,int>>v;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>s>>a;
		v.push_back(make_pair(make_pair(s,a*-1),i));
	}
	sort(v.begin(),v.end());
	for(int i=0;i<n;i++)
	{
		cout<<v[i].second<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
n=int(input())
MOD=10**9+7
cnt=[0 for _ in range(1000)]
for i in range(2,n+1):
    e=i
    for j in range(2,i+1):
        while(e%j==0):
            e//=j
            cnt[j]+=1
ans=1
for i in range(1000):
    ans=(ans*(cnt[i]+1))%MOD
print(ans)


Measured memory_bytes: 9044
#include<bits/stdc++.h>
#define fr(a,b,c) for(int a=b;a<c;a++)
using namespace std;
typedef long long ll;

map<ll,ll> cnt;

int main(){
	ll ans=0,sum=0;
	int n=0;
	cin>>n;
	cnt[0]=1;
	fr(i,0,n){
		int a;
		cin>>a;
		sum+=a;
		ans+=cnt[sum];
		cnt[sum]++;
	}
	cout<<ans<<endl;
}

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

using namespace std;

vector<int> v2;

#define pb push_back


int main() {
    int n,m;
    cin>>n>>m;
    vector<int> v1(11,-1);
    int r=0;
    int br=0;

    for(int i=0;i<m;i++){
        int x,y;
        cin>>x>>y;
        if(v1[x]==-1 || v1[x]==y){
            v1[x]=y;    
        }else{
            br=1;
        }
        
        
    }
    
    if(br==1){
        cout<<"-1";
        return 0;
    }
    
    if(n==1){
        if(v1[1]==-1){
            v1[1]=0;
        }
        cout<<v1[1];
        return 0;
    }
    
    if(v1[1]==0){
        br=1;
    }
    
    
    if(br==1){
        cout<<"-1";
        return 0;
    }
    if(v1[1]==-1){
        v1[1]=1;
    }
    
    for(int i=1;i<=n;i++){
        if(v1[i]==-1){
            v1[i]=0;
        }
        cout<<v1[i];
    }
    

}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{   
    string str;
    cin>>str;
    for(int i=0;str[i]!='\0';i++)
    {
        if(str[i]=='A'&&str[i+1]=='C')
        {
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n;
vector<int> inp;
vector<vector<int>> dp;

int stoney (int c,int k)
{
    if(k==0) return !c;
    if(k<0) return c;
    if(dp[k][c] != -1) return dp[k][c];

    int ans;
    for(int i=0;i<n;i++)
    {
            ans = stoney(!c,k-inp[i]);
            if(ans == c) return dp[k][c]=ans;
    }
    return dp[k][c]=!c;
}

int main()
{
    ios_base::sync_with_stdio(0); 
    cin.tie(0); cout.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    int k;
    cin>>n>>k;
    inp.resize(n);
    dp.assign(k+1,vector<int> (2,-1));

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

    int ans = stoney(1,k);
    if(ans == 1) cout<<"First"<<'\n';
    if(ans == 0) cout<<"Second"<<'\n';

}


Measured memory_bytes: 16308
import sys

n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

diff = [a[i] - b[i] for i in range(n)]
sumdiff = 0
for i in range(n):
    sumdiff = sumdiff + diff[i]

if sumdiff < 0:
    print(-1)
    sys.exit


else:
    diff.sort()

    ans = 0
    i = 0
    while diff[i] < 0: 
        ans = ans + 1
        i = i + 1

    cost = 0
    for i in range(ans):
       cost = cost + diff[i]
    cost = -1 * cost


    j = n-1
    while cost > 0:
        cost = cost - diff[j]
        j = j - 1
        ans = ans + 1

    print(ans)

Measured memory_bytes: 19068
/*
 * 1_2.c
 *
 *  Created on: 2018/11/20
 *      Author: masato
 */

#include <stdio.h>

int main(void){
	int n,i,j,x,v,m;
	scanf("%d", &n);
	int value[n];

	for(i=0;i<n;i++){
		scanf("%d", &x);
		value[i] = x;

		printf("%d", x);
		if(i==n-1){
			printf("\n");
		} else{
			printf(" ");
		}
	}

	for(i=1;i<n;i++){
		v = value[i];
		j = i-1;
		while(j >=0 && value[j] > v){
			value[j+1] = value[j];
			j--;
		}
		value[j+1] = v;
		for(m=0;m<n;m++){
			printf("%d", value[m]);
			if(m==n-1){
				printf("\n");
			} else{
				printf(" ");
			}
		}
	}
}



Measured memory_bytes: 1928
#include <iostream>
#include <string>
#include <algorithm>
#include <map>

using namespace std;

int main()
{
    int A, B, C, D;
    cin >> A;
    cin >> B;
    cin >> C;
    cin >> D;
    int d1 = min(A, B);
    int d2 = min(C, D);
    cout << d1 + d2 << endl;

    return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	as := scanNums(n)

	x := 1
	cnt := 0
	for i := 0; i < n; i++ {
		if as[i] == x {
			x++
			continue
		}
		cnt++
	}
	if cnt == n {
		fmt.Println(-1)
		return
	}
	fmt.Println(cnt)
}

func scanNums(len int) (nums []int) {
	var num int
	for i := 0; i < len; i++ {
		fmt.Scan(&num)
		nums = append(nums, num)
	}
	return
}



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

typedef long long ll;

#define rep(a,b,c) for(int a=b,a##end=c;a<=a##end;++a)
#define drep(a,b,c) for(int a=b,a##end=c;a>=a##end;--a)


char IO;
int rd(){
	int s=0,f=0;
	while(IO=getchar(),IO<'0'||IO>'9')if(IO=='-')f=1;
	do s=(s<<1)+(s<<3)+(IO^'0');
	while(IO=getchar(),IO>='0'&&IO<='9');
	return f?-s:s;
}

const int N=1e5+10,P=1e9+7;

int n,m;
int a[N];
int cnt;
int dp[110][N];
int main(){
	n=rd(),m=rd();
	int now=n;
	a[cnt=1]=n;
	while(now>1){
		now--;
		int l=1,r=n,res=-1;
		while(l<=r){
			int mid=(l+r)>>1;
			if(n/mid<=now) r=mid-1,res=mid;
			else l=mid+1;
		}
		a[++cnt]=now=n/res;
	}
	sort(a+1,a+cnt+1);
	rep(i,1,cnt) dp[1][i]=a[i]-a[i-1];
	rep(i,2,m){
		int s=0;
		rep(j,1,cnt){
			(s+=dp[i-1][j])%=P;
			dp[i][cnt-j+1]=1ll*(a[cnt-j+1]-a[cnt-j])*s%P;
		}
		//rep(j,1,cnt) cout<<dp[i][j]<<endl;
	}
	ll ans=0;
	rep(i,1,cnt) (ans+=dp[m][i])%=P;
	printf("%lld\n",ans);
}








Measured memory_bytes: 42496
import collections
n = int(input())
vs = list(map(int, input().split()))
veven = vs[0:n:2]
vodd = vs[1:n:2]
mins = []
flag = False
if veven == vodd and len(set(vodd)) == 1:
    print(n //2)
else:
    ce = collections.Counter(veven)
    co = collections.Counter(vodd)
    cem = ce.most_common()
    com = co.most_common()
    for i, j in cem:
        for k, h in com:
            if i != k:
                mins.append(n-j-h)
                flag = True
                break
        if flag:
            break
    flag = False
    for i, j in com:
        for k, h in cem:
            if i != k:
                mins.append(n-j-h)
                flag = True
                break
        if flag:
            break
    print(min(mins))
        



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

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

  bool ok = false;
  if (n % 3 != 0) {
    if (mp.size() == 1 && mp[0] > 0) {
      ok = true;  // 000000000...
    }
  } else {
    if (mp.size() == 3) {
      auto itr = mp.begin();
      auto itr2 = itr;
      if ((*itr).second == n / 3 && (*(++itr)).second == n / 3 &&
          (*(++itr)).second == n / 3) {
        if (((*itr2).first ^ (*(++itr2)).first ^ (*(++itr2)).first) == 0) {
          ok = true;  // xyz xyz xyz xyz
        }
      }
    } else if (mp.size() == 2) {
      if (mp[0] == n / 3) {
        ok = true;  // 0xx 0xx 0xx 0xx
      }
    } else if (mp.size() == 1) {
      if (mp[0] > 0) {
        ok = true;  // 000000000
      }
    }
  }

  if (ok) {
    puts("Yes");
  } else {
    puts("No");
  }

  return 0;
}


Measured memory_bytes: 7092
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>

#define FOR(i, a, b) for(int (i)=(a); (i)<(b); (i)++)
#define IFOR(i, a, b) for(int (i)=(a);(i)<=(b);(i)++)
#define RFOR(i, a, b) for(int (i)=(a);(i)>=(b);(i)--)

using namespace std;

long long power(long long n, long long p) {
	if (p == 0)
		return 1;
	long long res = 1;
	long long add = n;
	while (p > 0) {
		if (p & 1)
			res = (res * add);
		p >>= 1;
		add = add*add;
	}
	return res;
}

bool check(long long T, long long N, long long a) {
	// division
	long long div;
	if (a == 0)
		div = T;
	else
		// ここが違いそう
		div = T / a;

	if (div == 0)
		div = 1;

	IFOR(k, 1, div + 1) {
		// mはT未満
		// rはk未満（T未満）
		long long m = (T - (k - 1)*a) / k;
		long long r = (T - (k - 1)*a) % k;
		if (m <= 0)
			continue;
		// (m+1)をr回、mをk-r回かける
		// でかすぎ注意
		double exper = pow(m, k - r) * pow(m + 1, r);
		if (exper > N) {
			return true;
		}
		// 最大限作れるクッキーの数
		long long res = power(m, k - r) * power(m + 1, r);
		if (res >= N)
			return true;
	}
	return false;

}


int main() {
	long long n, a;
	cin >> n >> a;

	long long lb = 0, ub = n;
	while (ub - lb > 1) {
		long long half = (lb + ub) / 2;
		if (check(half, n, a)) {
			ub = half;
		}
		else {
			lb = half;
		}
	}
	cout << ub << endl;
	return 0;
}

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

int main(){
    int x;
    cin >> x;
    for(int i = 1; i <= 360; i++){
        if(i*x % 360 == 0){
            cout << i << endl;
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 3584
#include<cstdio>
#include<string>
#include<queue>
using namespace std;

int main() {
  char com[20];
  priority_queue<int> PQ;

  while ( 1 ) {
    scanf("%s", com);
    if ( com[0] == 'i' ) {
      int key ; scanf("%d", &key);
      PQ.push(key);
    } else if ( com[1] == 'x' ) {
      printf("%d\n", PQ.top());
      PQ.pop();
    } else if ( com[0] == 'e' ) {
      break;
    }
  }

  return 0;
}


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

int main(){
  int n;
  int l[105];
  cin >> n;
  int ans = 0;
  rep(i, n)cin >> l[i];
  for(int i=0;i<n;i++){
    for(int j=i+1;j<n;j++){
      for(int k=j+1;k<n;k++){
        if(l[i]==l[j]||l[i]==l[k]||l[j]==l[k])continue;
        if(l[i]+l[j]>l[k]&&l[i]+l[k]>l[j]&&l[k]+l[j]>l[i])ans++;
      }
    }
  }
  cout << ans;
  return 0;
}


Measured memory_bytes: 3620
#include<bits/stdc++.h>
#define next Next
#define inf (0x3f3f3f3f)
using namespace std;

const int maxn=100000+10;
struct node{
	int x,y;
}a[maxn],b[maxn];
int vis[maxn];
int head[maxn],next[maxn],v[maxn],e=1,to[maxn];
int dis[maxn],w[maxn];
int s=201,t=202,n;
inline void add(int x,int y,int z){
	to[++e]=y;
	next[e]=head[x];
	head[x]=e;
	w[e]=z;
}
bool bfs(){
    queue<int> q;
    for(int i=0;i<=n+n;++i)
        dis[i]=0;
    dis[t]=0;dis[s]=1,q.push(s);
    while(!q.empty()){
        int k=q.front();
        for(int i=head[k];i;i=next[i])
            if(!dis[to[i]]&&w[i]>0){
                dis[to[i]]=dis[k]+1;
                q.push(to[i]);
            }
        q.pop();
    }
    return dis[t];
}

int dfs(int u,int flow){
    if(u==t||!flow)
        return flow;
    for(int i=head[u];i;i=next[i])
        if(dis[to[i]]==dis[u]+1&&w[i]>0){
            int di=dfs(to[i],min(flow,w[i]));
            if(di){
                w[i]-=di;
                w[i^1]+=di;
                return di;
            }
        }
    return 0;
}
int dinic(){
    int ans=0;
    while(bfs()){
        while(true){
            int a=dfs(s,inf);
            ans+=a;
            if(!a)
                break;
        }
    }
    return ans;
}
int main(){
//	freopen("aa.in","r",stdin);
//	freopen("aa.out","w",stdout);
	scanf("%d",&n);
	for(int i=1;i<=n;++i){
		scanf("%d%d",&a[i].x,&a[i].y);
		add(s,i,1);
		add(i,s,0);
	}
	for(int i=1;i<=n;++i){
		scanf("%d%d",&b[i].x,&b[i].y);
		add(i+n,t,1);
		add(t,i+n,0);
	}
	for(int i=1;i<=n;++i)
		for(int j=1;j<=n;++j)
			if(a[i].x<=b[j].x&&a[i].y<=b[j].y){
				add(i,j+n,1);
				add(j+n,i,0);
			}
	printf("%d\n",dinic());
	return 0;
}


Measured memory_bytes: 2432
package main

import "fmt"

func main() {
	var N, A, B int
	fmt.Scan(&N, &A, &B)
	if A+B-1 > N || A*B < N {
		fmt.Println(-1)
		return
	}
	r := 1
	remaining := N - A
	for r <= N {
		l := r + remaining
		if remaining > B-1 {
			l = r + B - 1
		}
		for i := l; i >= r; i-- {
			fmt.Printf("%d ", i)
		}
		remaining -= l - r
		r = l + 1
	}
}


Measured memory_bytes: 5136
#include<bits/stdc++.h>
using namespace std;
int main(){
        int x,a,n; cin>>x>>n; unordered_map<int,int>  vis; for(int i=0;i<n;i++) {cin>>a; vis[a]=1;}
        if(!vis[x]) {cout<<x<<endl; return 0;}
        int low=x-1,high=x+1;
        while(1){
                if(!vis[low]) { cout<<low<<endl; return 0;}
                if(!vis[high]) { cout<<high<<endl; return 0; }
                low--,high++;
        }
}
 

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

using namespace std;

typedef long long int ll;

void solve()
{
	ll n1, n;
	cin >> n1 >> n;
	ll sum = 0;
	for(int i = 0, x; i <n; i++) cin >> x, sum += x;
	if(sum > n1) cout << "-1";
	else cout << n1 - sum << "\n";
}

int main()
{
	int t = 1;
	//cin >> t;
	for(int i = 0; i < t; i++)
	{
		//cout << "Case #" << i + 1 << ": ";
		solve();
	}
	return 0;
}



Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;


int main() {
  int n,d,x;
  cin >> n >> d >> x;
  vector<int> a(n),b(n);
  rep(i,n) cin >> b[i];
  rep(i,d-1){
    int u=0;
    a=b;
    rep(i,n) cin >> b[i];
    vector<int> d(x+1,-1);
    d[0]=0;
    rep(j,n){
      rep(k,x){
        if (d[k]!=-1){
          if (k+a[j]<=x){
            d[k+a[j]]=max(d[k+a[j]],d[k]+b[j]);
          }
        }
      }
    }
    rep(j,x+1){
      u=max(u,d[j]+x-j);
    }
    x=max(x,u);
  }
  cout << x << endl;

}



Measured memory_bytes: 3228
#include <iostream>
#include <cstring>
using namespace std;
int W,H;

int memo[100][100];
char mp[100][100];

int dfs(int x,int y){
	if(y >= H || x >= W) return 99999;
	else if(y == H-1 && x == W-1) return 0;
	if(~memo[y][x]) return memo[y][x];
	return memo[y][x] = min(dfs(x+1,y),dfs(x,y+1))+mp[y][x];
}
int main(){
	cin >> H >> W;
	for(int i = 0 ; i < H ; i++)
		for(int j = 0 ; j < W ; j++){
			char c; cin >> c; c -= '0';
			mp[i][j] = c;
		}
	memset(memo,-1,sizeof(memo));
	cout << dfs(0,0) << endl;
}

Measured memory_bytes: 0
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        while(true){
            int sum=0;
            double m=0.0,a2=0.0,a1=0.0;
            int n = sc.nextInt();
            int s[] = new int[n];

            if(n==0){
                break;
            }else{
                for(int i=0;i<n;i++){
                    s[i] = sc.nextInt();
                    sum += s[i];
                }

                m = (double)sum/n;
                
                for(int i=0;i<n;i++){
                    a1 += (double)(s[i]-m)*(s[i]-m);
                }
                a2 = a1/n;

                System.out.println(Math.sqrt(a2));
            }
        }

        sc.close();
    }
}


Measured memory_bytes: 30824
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include<math.h>
using namespace std;
#define INF 10000000
#define MOD 1000000007
typedef long long ll;
typedef pair<int,int> P;


int main(){
    int N;
    cin>>N;
    ll A[110000],a[110000],b[110000],sum=0,x,ans=1000000000,ansa,ansb;

    for(int i=0;i<N;i++){
        cin>>A[i];
    }
    sort(A,A+N);

    for(int i=0;i<N;i++){
        if(i%2==0){
            a[i]=A[i/2];
            b[i]=A[N-1-i/2];
        }else{
            b[i]=A[i/2];
            a[i]=A[N-1-i/2];
        }
    }
    
    for(int i=0;i<N;i++){
        x=abs(a[(i+1)%N]-a[i]);
        ans=min(ans,x);
        sum+=x;
    }

    ansa=sum-ans;
    sum=0;
    ans=1000000000;

    for(int i=0;i<N;i++){
        x=abs(b[(i+1)%N]-b[i]);
        ans=min(ans,x);
        sum+=x;
    }
    ansb=sum-ans;
    cout<<max(ansb,ansa)<<endl;
}


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

using namespace std;
using ll = long long;


int main()
{
    string s; cin >> s;
    int n = s.size();
    for(int i = 0; i < n - 1; i++) {
        if(s.substr(i, 2) == "AC") {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main () {

	int a, b, c;
	cin >> a >> b >> c;
	if (a >= b && a >= c) cout << a*10+b+c;
	else if (b >= a && b >= c) cout << b*10+a+c;
	else cout << c*10+a+b;

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main()
{
	int w,h,x,y,r;
	
	scanf("%d %d %d %d %d",&w,&h,&x,&y,&r);
	
	if(x==w || y==h || x<0 || y<0 || r>x || r>y || x>w || y>h)
	{
		printf("No\n");
	}
	else
	{
		printf("Yes\n");
	}
}


Measured memory_bytes: 2140
#include"bits/stdc++.h"
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPS(i,n) for(int i=1, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
using namespace std;
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; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { std::fill( (T*)array, (T*)(array+N), val ); }
#define INF 1e9
#define PI (acos(-1))
#define mod (int)1e9+7
int main() {
    int h, w, k;
    cin >> h >> w >> k;
    vector<vector<char>> c(h, vector<char>(w));
    REP(i, h) REP(j, w)cin >> c[i][j];
    int sum=0,ans=0;
    REP(i, pow(2, h)) {
        REP(j, pow(2, w)) {
            sum = 0;
            REP(k, h) {
                REP(l, w) {
                    if ((c[k][l] == '#' && !(i & (1 << k)) && !(j & (1 << l))))sum++;
                }
            }
            if (sum == k)ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4072
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    int num = in.nextInt();
    int timelimit = in.nextInt();
    int costmin = 0;
    for (int i = 0; i < num; i++) {
      int cost = in.nextInt();
      int time = in.nextInt();
      if (timelimit < time) {
        continue;
      }
      if (costmin == 0 || costmin > cost) {
        costmin = cost;
      }
    }
    if (costmin == 0) {
      System.out.println("TLE");
    } else {
      System.out.println(costmin);
    }
  }
}

Measured memory_bytes: 23764
#include<stdio.h>

int main(){
    int N;
    int A, B, i;
    int min=100000000, ans=0;

    scanf("%d", &N);
    for(i=1; i<N; i++){
        A=i;
        B=N-i;
        ans=0;
        while(A>0){
            ans+=A%10;
            A = A/10;
        }
        while(B>0){
            ans+= B%10;
            B=B/10;
        }
        
        if(ans<min){
            min = ans;
        }
    }

    printf("%d", min);

    return 0;
}

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

int sumChoco(int c, int d){
  int days = 1;
  int h = 0;
  // 日にちを求める
  for(int i = 1; i < d; i++){
  h = i * c + 1;
  if (h <= d)
    days++;
  }

  return days;

}

int main() {

  int n, d, x;
  int a[100] = {};
  int choco = 0;

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

  for(int i = 0; i < n; i++){
    choco += sumChoco(a[i], d);
  }

  cout << choco + x << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using vvi = vector<vector<int>>;
#define repex(i, a, b, c) for(int i = a; i < b; i += c)
#define repx(i, a, b) repex(i, a, b, 1)
#define rep(i, n) repx(i, 0, n)
#define pb push_back
int du[101010], dv[101010], duv[101010]; // 距離を保存

// グラフを幅優先探索する.
// https://ja.wikipedia.org/wiki/幅優先探索
// ※bfsの動作確認用.
// @param G: グラフ.
// @param s: グラフの探索開始頂点.
// @param d: 探索開始地点からの距離.
// @return: 特に無し.
void bfs(vvi &G, int s, int* d){
    
    // 1. 空のキュー.
    queue<int> q;
    
    // 2. 訪問済みフラグ設定.
    // ※スタート地点は, 距離ゼロを指定.
    d[s] = 0;
    
    // 3. 探索地点 s をキュー q に追加.
    q.push(s);
    while(!q.empty()){
        
        // 4. キューから取り出す.
        int u = q.front();
        q.pop();
        
        // 5. 取り出した要素を処理.
        for(auto &e : G[u]){
            
            // 6. 訪問済であれば, 処理をスキップ.
            if(d[e] > 0)            continue;
            if(d[e] == 0 && e != s) d[e] = d[u] + 1, q.push(e);
        }
    }
    return;
}

int main(){
    
    // 1. 入力情報.
    int N, u, v;
    scanf("%d %d %d", &N, &u, &v);
    u--, v--;
    vvi G(N);
    rep(i, N - 1){
        int a, b;
        scanf("%d %d", &a, &b);
        a--, b--;
        G[a].pb(b);
        G[b].pb(a);
    }
    
    // 2. 頂点 u, v から 各頂点までの距離を計算.
    bfs(G, u, du);
    bfs(G, v, dv);
    // rep(i, N) printf("%d ", du[i]);
    // puts("");
    // rep(i, N) printf("%d ", dv[i]);
    // puts("");
    
    // 3. 頂点 u, v の 中間地点 m を 取得.
    int m = -1, dm = du[v] / 2;
    rep(i, N){
        if(du[v] % 2 == 0){
            if(du[i] == dm && dv[i] == dm){
                m = i;
                break;
            }
        }else{
            if(du[i] == dm && dv[i] == dm + 1){
                m = i;
                break;
            }
        }
    }
    
    // 4. 頂点 m から 各頂点までの距離を計算.
    bfs(G, m, duv);
    // rep(i, N) printf("%d ", duv[i]);
    // printf("\nm=%d\n", m);
    
    // 5. 頂点 m から 最も遠い頂点 f を 取得.
    // ※ 但し, 頂点 v よりも 頂点 u に近いものに限定.
    int f = -1, df = 0;
    rep(i, N){
        if(df < duv[i] && du[i] < dv[i]) f = i, df = max(df, duv[i]);
    }
    
    // 6. 出力.
    printf("%d\n", duv[v] + duv[f] - 1);
    return 0;
    
}

Measured memory_bytes: 7040
#include<iostream>
#include <stdio.h>

using namespace std;

int getgcd(int n, int m)
{
    int r;
    if (n > m) {
        int t = m;
        m = n;
        n = t;
    }
    while ((r = m % n) != 0) {
    m = n;
    n = r;
    }
    return n;
}

int main(void){
    int a,b,c,K;
    int sum=0;

    cin>>K;

    for(a=1;a<=K;a++){
        for(b=1;b<=K;b++){
            for(c=1;c<=K;c++){
                sum+=getgcd(getgcd(a, b), c);
            }
        }
    }
    cout<<sum<<endl;

    return 0;
}


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

#define int long long
#define fast_io(); ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define loop(i,a,b) for(int i=a;i<b;i++)
#define all(x) x.begin(),x.end()
#define pb push_back
#define ins insert
#define fi first
#define se second
#define _max max_element
#define _min min_element
#define tc(T) int T; cin>>T; while(T--)
#define q(q) int q; cin>>q; while(q--)
#define pi 3.1415926535897932384626433832
const int pinf=((int)9e18);
const int ninf=((int)-9e18);
const int mod=1000000007;

using namespace std;

int32_t main()
{
    fast_io();

    //FILE *fptr1=freopen("in.txt","r",stdin);
    //FILE *fptr2=freopen("out.txt","w",stdout);


    int n;
    cin>>n;

    vector <int> a(n);
    loop(i,0,n) cin>>a[i];


    if(is_sorted(all(a)))
    {
        cout<< "YES";
        return 0;
    }
    else
    {
        loop(i,0,n)
        {
            loop(j,i+1,n)
            {
                vector <int> b=a;
                swap(b[i],b[j]);
                if(is_sorted(all(b)))
                {
                    cout<< "YES";
                    return 0;
                }
            }
        }
    }

    cout<< "NO";


    return 0;
}


Measured memory_bytes: 3664
/*
 * 17-08-06_ARC080_E.cpp
 *
 *  Created on: 2017/08/06
 *      Author: ryoma
 */

#include<iostream>
#include<algorithm>
#include<queue>
#include<vector>

using namespace std;


inline int get_min2pow(int n) {
	int res = 1;
	while (res < n)
		res *= 2;
	return res;
}

///Segment Tree////////

template<typename T,T dval>
struct segtree {
	int N;
	vector<T> node;
	//例外値　ex)INF,0
	T default_value = dval;
	static inline T merge(const T& l, const T& r) {
		//RMQ
		return min(l,r);
		//RSQ
		//return l+r;
	}
	segtree(){}
	segtree(int n) {
		N = get_min2pow(n);
		node.resize(2 * N, default_value);
	}
	segtree(vector<int> v) {
		int sz = v.size();
		N = get_min2pow(sz);
		node.resize(2 * N, default_value);
		for (int i = 0; i < sz; i++)
			node[i + N - 1] = v[i];
		for (int i = N - 2; i >= 0; i--)
			node[i] = merge(node[2 * i + 1], node[2 * i + 2]);
	}
	void init(int n){
		N = get_min2pow(n);
		node.resize(2 * N, default_value);
	}
	// update k th element
	void update(int k, T val) {
		k += N - 1; // leaf
		node[k] = val;
		while (k > 0) {
			k = (k - 1) / 2;
			node[k] = merge(node[k * 2 + 1], node[k * 2 + 2]);
		}
	}
	// add k th element
	void add(int k, T val) {
		k += N - 1; // leaf
		node[k] += val;
		while (k > 0) {
			k = (k - 1) / 2;
			node[k] = merge(node[k * 2 + 1], node[k * 2 + 2]);
		}
	}
	// [a, b)
	T query(int a, int b) {
		return query(a, b, 0, 0, N);
	}
	T query(int a, int b, int k, int l, int r) {
		if (r <= a or b <= l)
			return default_value;
		if (a <= l and r <= b)
			return node[k];
		int m = (l + r) / 2;
		T vl = query(a, b, k * 2 + 1, l, m);
		T vr = query(a, b, k * 2 + 2, m, r);
		return merge(vl, vr);
	}
};

struct area{
	int l,r;
	int min;
	int mod2;
	area(int l_,int r_,int min_,int e):l(l_),r(r_),min(min_),mod2(e){}
};

bool operator<(const area& l,const area& r){
	return l.min > r.min;
}

int N;
int map[2*100010];

int q[2*100010];
int main(){
	cin >> N;
	segtree<int,2*100010> pmin[2];
	pmin[0].init(N/2);
	pmin[1].init(N/2);
	for(int i=0;i<N;i++){
		int p;
		cin >> p;
		pmin[i&1].update(i/2,p);
		map[p] = i/2;
	}
	priority_queue<area> pq;
	pq.push(area(0,N/2,pmin[0].query(0,N/2),0));
	for(int i=0;i<N/2;i++){
		area a = pq.top();
		pq.pop();
		int x = a.min;
		int y = pmin[!a.mod2].query(map[x]+a.mod2,a.r+a.mod2);
		q[2*i] = x;
		q[2*i+1] = y;
		pq.push(area(a.l,map[x],pmin[a.mod2].query(a.l,map[x]),a.mod2));
		pq.push(area(map[x]+a.mod2,map[y],pmin[!a.mod2].query(map[x]+a.mod2,map[y]),!a.mod2));
		pq.push(area(map[y]+!a.mod2,a.r,pmin[a.mod2].query(map[y]+!a.mod2,a.r),a.mod2));
	}
	for(int i=0;i<N;i++){
		cout << q[i] <<( i+1<N? " ":"\n");
	}
	return 0;
}




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

using namespace std;
using ll = long long;

template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_V(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl;
#define DEBUG_M(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}

int main() {
    int k, x;
    cin>>k>>x;
    int left = x-k+1, right=x+k-1;
    for (int i = max(-1000000, left); i <= min(1000000, right); ++i) {
        cout<<i<<" ";
    }
    cout<<endl;

    return 0;
}

Measured memory_bytes: 256
//#define _USE_MATH_DEFINES
#include <iostream>
#include <stdio.h>
//#include <iomanip>
#include <vector>
//#include <string>
//#include <algorithm>
//#include <functional>
#include <cmath>

using namespace std;

int main(){

	int n,buf;
	double ave, a;
	vector <int> s;



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

		ave = 0;
		a = 0;
		s.clear();
		for(int i = 0; i < n; i++) {
			cin >> buf;
			s.push_back(buf);
			ave += buf;
		}
		ave /= n;

		for (int i = 0; i < n; i++){
			a += pow((s[i] - ave), 2);
		}
		a = sqrt((a / n));

		printf("%.6f\n", a);
	}


	return 0;
}

Measured memory_bytes: 1248
#include <iostream>

using namespace std;

int main(void) {
  int A, B, K;
  int tmp;
  cin >> A >> B >> K;
  if (K >= B-A+1) {
    for(int i=A;i <= B;i++) {
      cout << i << endl;
    }
  } else {
    tmp = A+K;
    for (int i=A;i < tmp;i++) {
      cout << i << endl;
    }
    if (2*K-1 < B-A) {
      // cout << "condition 1" << endl;
      tmp = B-K+1;
      for (int i=tmp;i <=B;i++) {
        cout << i << endl;
      }
    } else {
      // cout << "condition 2" << endl;
      tmp;
      for(int i=tmp;i <= B;i++) {
        cout << i << endl;
      }
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define f(i,a,b) for(int i(a);i<b;i++)
#define rep(i,n) for(int i(0);i<n;i++)
#define fast  ios_base::sync_with_stdio(0); cin.tie(0);
#define pres(x) cout<<fixed; cout<<setprecision(x);
#define open freopen("input.txt","r",stdin) ; freopen("output.txt","w",stdout);
#define watch(x) cout<<(#x)<<" is "<<x<<"\n";
#define out(x) cout<<x<<"\n";
#define mod 1000000007

bool sq(int x){
	int t = sqrt(x);
	if(t*t==x)return true;
	else return false;
}

int32_t main(){
	
	fast;
	//open;

	int n, d , ans=0;
	cin>>n>>d;
	int array[n][d];
	rep(i,n){
		rep(j,d)cin>>array[i][j];
	}
	rep(i,n){
		f(j,i+1,n){
			int temp=0;
			rep(k,d){
				temp += (array[i][k] - array[j][k])*(array[i][k] - array[j][k]);
			}
			if(sq(temp))ans++;

		}

	}
	cout<<ans;


	return 0;
}

Measured memory_bytes: 256
n = int(raw_input())
his = map(int, raw_input().split(' '))
j = 0
pv = float('inf')
count = 0
m = 0
while(j < len(his)):
	if pv >= his[j]: count +=1
	else: count = 1
	m = max(count-1,m)
	pv = his[j]
	j +=1
print m


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

signed main() {
  int N, K;
  cin >> N >> K;
  
  vector<pair<int, int>> P(N);
  int A, B;
  for( int i = 0; i < N; i++ ){
    cin >> A >> B;
    P.at(i) = make_pair(A, B);
  }
  sort(P.begin(), P.end());
  
  for( int i = 0; i < N; i++ ){
    if( K <= P.at(i).second ){
      cout << P.at(i).first << endl;
      return 0;
    }else{
      K -= P.at(i).second;
    }
  }
}

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

int main(){
  int a,b,c,d,e;
  cin >> a >> b >>c  >> d >> e;
  if(a == 0)cout << 1;
  else if(b == 0) cout << 2;
  else if(c == 0) cout << 3;
  else if(d == 0) cout << 4;
  else cout << 5 << endl;
  return 0;
}


Measured memory_bytes: 3596
#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (int64_t)(n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

#define chmax(a, b) (a) = max(a, b)
#define chmin(a, b) (a) = min(a, b)

int64_t dpow(int64_t a, int64_t b, int64_t MOD) {
  if (b == 0) {
    return 1;
  }
  if (b % 2 == 0) {
    return dpow(a * a % MOD, b / 2, MOD);
  } else {
    return dpow(a, b - 1, MOD) * a % MOD;
  }
}

/**
 *  lookup table of stirling number s(i,j) for i in {1, ..., n} and j in {1,
 *  ..., m}
 * s(i, j) == the number of partition of n items into m nonempty groups
 * */
vector<vector<int64_t>> stirling2(size_t n, size_t m, size_t MOD) {
  vector<vector<int64_t>> result(n + 1, vector<int64_t>(m + 1, 0));
  result[0][0] = 1;
  for (size_t i = 1; i <= n; i++)
    for (size_t j = 1; j <= i; j++) {
      result[i][j] = result[i - 1][j - 1] + j * result[i - 1][j] % MOD;
      result[i][j] %= MOD;
    }
  return result;
}

/// lookup table of k! for k in {1, ..., n}
vector<int64_t> factorials(size_t n, size_t MOD) {
  vector<int64_t> result(n + 1, 1);
  for (size_t i = 1; i <= n; i++) {
    result[i] = result[i - 1] * i % MOD;
  }
  return result;
}

int main() {
  int64_t N, M;
  cin >> N >> M;

  auto stirling = stirling2(N + 1, N + 1, M);
  auto fact = factorials(N + 1, M);

  int64_t result = 0;
  irep(i, N) {
    int64_t comb = fact[N] * dpow(fact[i] * fact[N - i] % M, M - 2, M) % M;
    int64_t f = 0;

    int64_t p2 = dpow(2, N - i, M);
    int64_t t = 1;
    for (int j = 0; j <= i; j++) {
      f += stirling[i + 1][j + 1] * t % M;
      f %= M;

      t *= p2;
      t %= M;
    }
    f *= dpow(2, dpow(2, N - i, M - 1), M);
    f %= M;

    int64_t term = dpow(-1, i, M) * comb % M * f % M;
    result += term;
    result %= M;
  }
  result = (result + M) % M;
  cout << result << endl;

  return 0;
}

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

using namespace std;

#define endl '\n'
#define ll long long

const ll mod = 1e9 + 7;
const ll maxn = 2e5 + 5;
const double pi = 3.1415926535897932384626433832795028841971693993751058209749445923078;
//iostream::sync_with_stdio(false);

int main()
{
    ll n, a, b;
    cin >> n >> a >> b;
    ll h = n;
    if(n < a + b)
    {
        if(a > n)
        {
            cout << n << endl;
        }
        else
        {
            cout << a << endl;
        }
    }
    else
    {
        n = n / (a + b) * a;
        if(h % (a + b) >= a)
        {
            cout << n + a << endl;
        }
        else
        {
            cout << n + (h % (a + b)) << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <climits>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <string>
#include <list>
#include <ctime>
#include <complex>
#include <bitset>
#include <tuple>

#define ff first
#define ss second

using namespace std;
using pii=pair<int,int>;
using ll=long long;

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

    int n,w;
    cin>>n>>w;
    vector<vector<ll>> dp(2,vector<ll>(100001,999999999999LL));
    vector<pii> v(n);
    for(int i=0; i<n; i++){
        cin>>v[i].ff>>v[i].ss;
    }
    dp[0][v[0].ss]=v[0].ff;
    dp[0][0]=0;
    int answer=v[0].ss;
    for(int i=1; i<n; i++){
        for(int j=0; j<=100000; j++){
            dp[i%2][j]=min(dp[i%2][j],dp[1-(i%2)][j]);
            if(j-v[i].ss<0) continue;
            dp[i%2][j]=min(dp[i%2][j],dp[1-(i%2)][j-v[i].ss]+v[i].ff);
            if(dp[i%2][j]<=w) answer=max(answer,j);
        }
    }
    cout<<answer;

    return 0;
}


Measured memory_bytes: 5576
#include<iostream>
#include<string>
#include<vector>
using namespace std;
#define int long long
#define rep(i,n) for(int i = 0; i < n; i++)
#define YN(f) (f?"YES":"NO")
#define yn(f) (f?"Yes":"No")	
#define INF 123456789123456
#define MOD (int)(1e9+7)
#define MAX_N 10
#define MAX_V 60

vector<int> G[MAX_V];
int N, M;

bool foo(int n, int m, int used[], int count){//cout<<n<<" "<<m<<" "<<count<<endl;
	
	if(used[m])return false;
	used[m] = true;
	for(int y : G[m]){
		if(count == 0 && y == n)continue;
		if(y == n)return true;
		if(foo(n,y, used, count+1)) return true;
	}
	return false;
}

signed main(){
	int count = 0,a , b;
	cin>>N>>M;
	
	rep(i, M){
		cin>>a>>b;a--,b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	
	rep(i, N){
		for(int y : G[i]){
			int used[60] = {};
			if(foo(i,y,used, 0) == false){
				count++;
			}
		}
	}
	
	cout<<count/2<<endl;
	
	return 0;
}

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

int main(){
  int N;
  cin >> N;
  vector<char> c(N);
  int red = 0;
  for(int i=0; i<N; i++){
    cin >> c.at(i);
    if(c.at(i)=='R') red++;
  }
  int white = N - red;
  vector<int> p(N+1);
  int leftW = 0, rightR = red;
  p.at(0) = rightR;
  p.at(N) = N - rightR;
  for(int i=1; i<N; i++){
    if(c.at(i-1)=='R') rightR--;
    if(c.at(i-1)=='W') leftW++;
    p.at(i) = max(leftW, rightR);
  }
  sort(p.begin(), p.end());
  cout << p.front();
  return 0;
}

Measured memory_bytes: 4308
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i ++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i ++)
#define MP make_pair

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const int MOD = 998244353;

int n;
int c[10005], cnt;
vector<int> G[10005];
int ret[10005];

void dfs(int v, int par)
{
	ret[v] = c[cnt ++];
	rep(i, G[v].size()) {
		int u = G[v][i];
		if(u == par) continue;
		dfs(u, v);
	}
}

int main()
{
	scanf("%d", &n);
	rep(i, n - 1) {
		int u, v;
		scanf("%d%d", &u, &v);
		G[u].push_back(v);
		G[v].push_back(u);
	}
	rep(i, n) scanf("%d", &c[i]);
	sort(c, c + n);
	reverse(c, c + n);
	
	dfs(1, -1);
	LL sum = 0;
	rep(i, n) if(i > 0) sum += c[i];
	printf("%lld\n", sum);
	rep1(i, n) printf("%d ", ret[i]);
	return 0;
}

Measured memory_bytes: 1536
ac=0
wa=0
tle=0
re=0
for _ in range(int(input())):
  s=input()
  if(s=="AC"):
    ac+=1
  if s=="WA":
    wa+=1
  if s=="TLE":
    tle+=1
  if s=="RE":
    re+=1
print("AC x",ac)
print("WA x",wa)
print("TLE x",tle)
print("RE x",re)

Measured memory_bytes: 9148
// C++ 14
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(ll __x = __start; __x < __end; __x++)

int main() {
  ll n, k; cin >> n >> k;
  if (k == 0) {
    cout << n*n << endl;
    return 0;
  }
  
  ll ans = 0;
  loop(b,k+1,n+1) {
    ans += max(b-k, 0LL) * (n/b);
    int r = n%b;
    ans += max(r-k+1, 0LL);
  }
  cout << ans << endl;
  return 0;
}


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

#define ll long long
#define INF_LL 1LL << 60
#define INF 99999999
#define MOD (ll)1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, a, n) for(int i = a; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

void put_double(double obj){printf("%.12f\n",obj);};

template < typename T > std::string to_string( const T& n )
{
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
}

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }


int main()
{
    string s1, s2, s3;
    cin >> s1 >> s2 >> s3;
    cout << "A" << s2[0] << "C" << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
// Begin Header {{{
#define all(x) (x).begin(), (x).end()
#define lli long long int
#define rep(i,n) for(lli i=0; i<n; i++)
#define loop(i, j, n) for(lli i=j; i<n; i++)
#define Max(a, b) ((a) > (b) ? (a) : (b))
#define Min(a, b) ((a) < (b) ? (a) : (b))
constexpr int INF  = 0x3f3f3f3f;
const long long mod=1e9+7;
//Function
lli combi(lli n, lli r)
{
	if(r==0 || r==n) return 1;
	else return combi(n-1,r) + combi(n-1,r-1);
}
lli sigma1(lli n){return n*(n+1)/2;}
lli sigma2(lli s, lli n){return sigma1(n) - sigma1(s -1);}
using namespace std;
// }}} End Header

int main()
{
	ios::sync_with_stdio(false); cin.tie(nullptr);
	lli n, m;
	cin >> n >> m;
	vector<lli> h(n+1);
	vector<lli> ans(n+1, 1);

	loop(i, 1, n+1){
		cin >> h[i];
	}
	rep(i,m){
		lli a, b, c;
		cin >> a >> b;
		c = Min(h[a], h[b]);
		if(h[a] == h[b]){
			ans[a]--;
			ans[b]--;
		}else if(c == h[a]){
			ans[a]--;
		}else{
			ans[b]--;
		}
	}
	lli sum = 0;
	loop(i, 1, n+1){
		if(ans[i] > 0) sum++;
	}
	cout << sum << endl;
	return 0;
}

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

int main() {
int N ;
cin>>N;
int x=N;
int sum=0;
while(x>0){
sum+=x%10;
x=x/10;
}
if(N%sum==0){
cout<<"Yes"<<endl;
}
else{
cout<<"No"<<endl;
}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v).begin(), (v).end()
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define DEBUG
#define int long long
#define INF 1e18
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; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<"\n";}
typedef long long ll;

signed main()
{
    int n, k;
    cin >> n >> k;
    vector<int> h(n);
    REP(i, n)
    cin >> h[i];

    sort(h.begin(), h.end());
    int cnt = 0;
    if(n<=k){
        cout << 0 << endl;
        return 0;
    }
    for (int i = 0; i < n - k; i++)
    {
        cnt += h[i];
    }
    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <iomanip>
#include <fstream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>

#define _GLIBCXX_DEBUG
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
using namespace std;
using vi = vector<int64_t>;
using vvi = vector<vi>;

int main(int argc, const char * argv[]) {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    string s;
    cin >> s;
    int res = 1000;
    rep(i,s.size()-2){
        int tmp = stoi(string{s.at(i)} + string{s.at(i+1)} + string{s.at(i+2)});
        res = min(res, abs(tmp - 753));
    }
    cout << res << endl;
}


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

int main() {
  string ans = "";
  int x1, y1, x2, y2;
  cin >> x1 >> y1 >> x2 >> y2;
  for (int i = 0; i < x2 - x1; i++)
    ans = ans + "R";
  for (int i = 0; i < y2 - y1; i++)
    ans = ans + "U";
  for (int i = 0; i < x2 - x1; i++)
    ans = ans + "L";
  for (int i = 0; i < y2 - y1; i++)
    ans = ans + "D";
  ans = ans + "D";
  for (int i = 0; i < x2 - x1 + 1; i++)
    ans = ans + "R";
  for (int i = 0; i < y2 - y1 + 1; i++)
    ans = ans + "U";
  ans = ans + "L";
  ans = ans + "U";
  for (int i = 0; i < x2 - x1 + 1; i++)
    ans = ans + "L";
  for (int i = 0; i < y2 - y1 + 1; i++)
    ans = ans + "D";
  ans = ans + "R";
  cout << ans << endl;
}

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

constexpr long long mod{1000000007};

struct Node {
	std::list<int> edges;
	int depth{-1};
	long long color[2]{-1, -1};
};
std::vector<Node> tree;
void init_root(int, int);
long long dfs(int, int);

int main()
{
	int n;
	scanf("%d", &n);
	tree.resize(n + 1);
	for (int i{}; i < n - 1; i++)
	{
		int x, y;
		scanf("%d%d", &x, &y);
		x--; y--;
		tree[x].edges.push_back(y);
		tree[y].edges.push_back(x);
	}
	tree[n].edges.push_back(0);
	tree[0].edges.push_back(n);
	init_root(n, 0);
	printf("%lld\n", dfs(n, 0));

	return 0;
}

void init_root(int index, int depth)
{
	if (tree[index].depth >= 0) return;
	tree[index].depth = depth;
	for (auto& e: tree[index].edges)
		if (tree[e].depth < 0)
			init_root(e, depth + 1);
	return;
}

long long dfs(int index, int black)
{
	long long& color{tree[index].color[black]};
	if (color >= 0) return color;
	color = 1;
	for (auto& e: tree[index].edges)
	{
		if (tree[e].depth < tree[index].depth) continue;
		long long sum{dfs(e, 0)};
		if (!black)
		{
			sum += dfs(e, 1);
			sum %= mod;
		}
		color *= sum;
		color %= mod;
	}
	return color;
}

Measured memory_bytes: 16000