akhauriyash/Code-Regression huggingface dataset:
#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 N, M = 0;
    cin >> N;
    vector<int> a(N - 1), b(N - 1), c(N), ans(N);
    vector<vector<int>> edge(N);
    rep(i, N - 1) {
        cin >> a[i] >> b[i];
        a[i]--;
        b[i]--;
        edge[a[i]].push_back(b[i]);
        edge[b[i]].push_back(a[i]);
    }
    rep(i, N) {
        cin >> c[i];
        M += c[i];
    }
    sort(c.begin(), c.end());
    M -= c[N - 1];
    vector<bool> done(N, false);
    queue<int> q;
    q.push(0);
    done[0] = true;
    int j = N - 1;
    while (!q.empty()) {
        int p = q.front();
        q.pop();
        done[p] = true;
        ans[p] = c[j];
        //cout << "ans[" << p << "]=" << ans[p] << "\n";
        j--;
        rep(i, edge[p].size()) {
            if (done[edge[p][i]]) continue;
            q.push(edge[p][i]);
        }
    }
    cout << M << "\n";
    rep(i, N) {
        cout << ans[i];
        if (i == N - 1) cout << "\n";
        else cout << " ";
    }
}

Measured memory_bytes: 1152
#include <cstdio>
#include <cstring>
#include <iostream>
#define debug(...) fprintf(stderr,__VA_ARGS__)
using namespace std;
typedef long long ll;
const int mod=998244353;
const int maxn=300+5;
int n; char S[maxn];
int mx[maxn][maxn];
int f[maxn][maxn][maxn];
int C[maxn][maxn];
int sx[maxn],sy[maxn];
bool g[maxn][maxn][maxn];
inline int add(int x) {return x>=mod?x-mod:x;}
void init() {
	for(int i=0;i<=n;++i) {
		C[i][0]=C[i][i]=1;
		for(int j=1;j<i;++j) C[i][j]=add(C[i-1][j-1]+C[i-1][j]);
	}
}
int main() {
	scanf("%s",S+1),n=strlen(S+1);
	init();
	f[n+1][0][0]=1;
	for(int i=n;i>=1;--i) {
		for(int a=0;a<=n;++a) for(int b=0;b<=n;++b) {
			f[i][a][b]=f[i+1][a][b];
			if(S[i]=='0'&&b) f[i][a][b]=add(f[i][a][b]+f[i][a][b-1]);
			if(S[i]=='1'&&a) f[i][a][b]=add(f[i][a][b]+f[i][a-1][b]);
		}
	}
	g[0][0][0]=1;
	for(int i=0;i<=n;++i) {
		for(int a=n;a>=0;--a) for(int b=n;b>=0;--b) if(g[i][a][b]) {
			if(a+b>=2) {
				if(a) g[i][a-1][b]=1;
				if(b) g[i][a][b-1]=1;
			}
			if(i+2<=n) {
				if(S[i+1]=='0'||S[i+2]=='0') g[i+2][a+1][b]=1;
				if(S[i+1]=='1'||S[i+2]=='1') g[i+2][a][b+1]=1;
			}
			if(i+1<=n&&(a||b)) {
				g[i+1][a][b]=1;
				if(S[i+1]=='0'&&b) g[i+1][a+1][b-1]=1;
				if(S[i+1]=='1'&&a) g[i+1][a-1][b+1]=1; 
			}
		}
	}
	memset(mx,-1,sizeof(mx));
	for(int i=n;i>=0;--i) {
		for(int a=0;a<=n;++a) for(int b=0;b<=n;++b) if(g[i][a][b]) {
			if(mx[a+sx[i]][b+sy[i]]==-1) mx[a+sx[i]][b+sy[i]]=i;
		}
		sx[i-1]=sx[i],sy[i-1]=sy[i];
		if(S[i]=='0') ++sx[i-1]; else ++sy[i-1];
	}
	int an=0;
	for(int x=0;x<=n;++x) for(int y=0;y<=n;++y) if(mx[x][y]!=-1) {
		int t=mx[x][y]+1,xx=x-sx[t-1],yy=y-sy[t-1];
		int r=an;
		for(int a=0;a<=xx;++a) for(int b=0;b<=yy;++b) if(f[t][a][b]) {
			an=(an+(ll)f[t][a][b]*C[xx+yy-a-b][xx-a])%mod;
		}
//		debug("%d %d %d %d\n",xx,yy,t-1,an-r);
	}
	printf("%d\n",an);
	return 0;
}

Measured memory_bytes: 121016
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(ll i = 0; i < (ll) n; i++)
#define xrep(i,x,n) for(ll i = (ll) x; i < (ll) n; i++)
#define vl vector<long long>
#define vs vector<string>
#define vvl vector<vector<long long>>
#define all(A) A.begin(), A.end()

int main() {
    ll n, k;
    cin >> n >> k;
    vl h(n);
    rep(i, n) cin >> h[i];

    vl dp(n);

    xrep(i,1,n){
        dp[i] = dp[i-1] + abs(h[i]-h[i-1]);
        xrep(j,1,min(i,k) + 1){
            dp[i]=min(dp[i-j] + abs(h[i]-h[i-j]),dp[i]);
        }
    }

    cout << dp[n-1] << endl;
}

Measured memory_bytes: 4748
import sys

N = int(input())
digit = len(str(N))
# 1-99
if digit < 3:
    print(min((N), 9))
# 100-999
elif digit == 3:
    print(N-99+9)
# 1000-9999
elif digit == 4:
    print(999-99+9)
# 10000-99999
elif digit == 5:
    print(N-9999-99+999+9)
# 100000
else:
    print(99999-9999-99+999+9)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <string>
#include <cctype>
#include <map>

using namespace std;

const int mod = 1000000007;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
#define ll long long

int main()
{
    int k, x;
    cin >> k >> x;

    cout << (500 * k >= x ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 256
N, W = map(int, input().split())

items = [list(map(int, input().split())) for i in range(N)]
values = []
weights = []
for item in items:
    key = 1
    while item[2] > 0:
        values.append(item[0] * key)
        weights.append(item[1] * key)
        item[2] -= key
        key = min(key * 2, item[2])
#あとはvalues, weightsに対してknapsack DPするだけ
num = len(values)
dp = [0 for w in range(W+1)]
for i in range(num):
    wi = weights[i]
    vi = values[i]
    for w in range(W, wi -1 , -1):
        if dp[w] < dp[w - wi] + vi:
            dp[w] = dp[w - wi] + vi

print(dp[W])


Measured memory_bytes: 6072
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=105;
inline int read()
{
	int s=0,w=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){s=s*10+ch-'0';ch=getchar();}
	return s*w;
}
int n,m;
int d[15][15],f[N][N];
int main()
{
	n=read();m=read();
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			d[i][j]=read();
	for(int i=0;i<=100;i++)
		for(int j=0;j<=100;j++)
			for(int x=1;x<=n;x++)
				for(int y=1;y<=m;y++)
					f[i][j]=max(f[i][j],d[x][y]-i*x-y*j);
	for(int x=1;x<=n;x++)
		for(int y=1;y<=m;y++)
		{
			int now=100000;
			for(int i=0;i<=100;i++)
				for(int j=0;j<=100;j++)
					now=min(now,f[i][j]+i*x+y*j);
			if(now!=d[x][y]){
				puts("Impossible");
				return 0;
			}
		}
	puts("Possible");
	puts("202 10401");
	for(int i=1;i<101;i++)printf("%d %d X\n",i,i+1);
	for(int i=102;i<202;i++)printf("%d %d Y\n",i,i+1);
	for(int i=0;i<=100;i++)
		for(int j=0;j<=100;j++)
			printf("%d %d %d\n",i+1,202-j,f[i][j]);
	puts("1 202");
	return 0;
}

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

int main(void){
    int L, R, d;
    cin >> L >> R >> d;

    int cnt = 0;
    for (int i = L; i <= R; i++) {
        if (i%d == 0) cnt++;
    }
    cout << cnt << endl;
}


Measured memory_bytes: 3588
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define REP(i,a,b) for(int i=int(a);i<(int)b;++i)
#define Graph vector<vecctor<ll>>
#define pairs vector<pair<ll,ll>>
#define pb push_back



using namespace std;
using ll = long long;
const ll INF = 1e18;
const double PI = acos(-1);

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}



int main(void)
{
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int>a(n);
    rep(i,n){
        cin >> a[i];
    }
    vector<pair<int,int>>pred;
    int max,min = 0;
    for(int i=1;i < n;i++){
        if(a[i] < a[i-1]){
            max = i-1;
            pred.pb(make_pair(min,max));
            min = i;
        }
    }
    pred.pb(make_pair(min,n-1));
    ll wal = 1000;
    for(auto x :pred){
        ll buy = wal/a[x.first];
        wal %= a[x.first];
        wal += a[x.second]*buy;
    }

    cout << wal << endl;
    return 0;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define ve vector
#define chmin(x,y) x = min(x,y)

int main(){
    int n,k;
    cin >> n >> k;
    ve<int> x(n),y(n);
    rep(i,n) cin >> x[i];
    rep(i,n) y[i] = -x[n-1-i];
    int ans = 2e9;
    rep(i,n-k+1){
        int memo = abs(x[i]) + (x[i+k-1]-x[i]);
        ans = min(ans,memo);
        memo = abs(y[i]) + y[i+k-1]-y[i];
        ans = min(ans,memo);
    }
    cout << ans << endl;
    return 0;
}


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

int main(){
	int n;
	cin>>n;
	int a[n];
	int ma[n]={};
	int maxval=10000000;
	int count=0;
	rep(i,n){
		cin>>a[i];
		maxval=min(maxval,a[i]);
		ma[i]=maxval;
		if(ma[i]==a[i])count++;
	}
	cout << count << endl;
}


Measured memory_bytes: 1792
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AtCoder
{
    class Program
    {
        private const int MODULO = 1000000007;
        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }

        static int Solve(string S)
        {
            int count = 0;
            for (int i = 1; i < S.Length; ++i)
            {
                if (S[i - 1] != S[i]) { ++count; }
            }
            return count;
        }
        static void Main(string[] args)
        {
            Console.WriteLine(Solve(Read()));
        }
    }
}


Measured memory_bytes: 13140
import sys
def main():
    input = sys.stdin.readline
    H,W=map(int, input().split())
    S=[list(input()) for _ in range(H)]

    #dp[i][j]=[i,j]にたどり着くまでの黒のかたまりの数の最小値
    INF = 10**9
    dp = [[INF] * W for _ in range(H)]
    dp[0][0] = 1 if S[0][0] == '#' else 0
    for i in range(H):
        for j in range(W):
            if i > 0: #上から来た
                if S[i-1][j] != '#' and S[i][j] == '#': #白→黒
                    dp[i][j] = min(dp[i][j], dp[i-1][j] + 1)
                else: #白→白、黒→白、黒→黒
                    dp[i][j] = min(dp[i][j], dp[i-1][j])
            if j > 0: #左から来た
                if S[i][j-1] != '#' and S[i][j] == '#': #白→黒
                    dp[i][j] = min(dp[i][j], dp[i][j-1] + 1)
                else: #白→白、黒→白、黒→黒
                    dp[i][j] = min(dp[i][j], dp[i][j-1])
    print(dp[H-1][W-1])

if __name__ == '__main__':
    main()

Measured memory_bytes: 43120
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>

using namespace std;

const int nmax = 1e9 + 7;
typedef long long ll;

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

  vector < pair<int, int> > XY(N);
  for (int i = 0; i < N; i++){
    int X, Y; cin >> X >> Y;
    XY[i].first = X;
    XY[i].second = Y;
  }
  sort(XY.begin(), XY.end());

  vector < pair<int, int> > PQ;
  for (int i = 0; i < N - 1; i++){
    for (int j = i + 1; j < N; j++){
      int P = XY[i].first - XY[j].first;
      int Q = XY[i].second - XY[j].second;
      PQ.push_back(make_pair(P, Q));
    }
  }

  int ans = N;
  for (int i = 0; i < PQ.size(); i++){
    int P = PQ[i].first, Q = PQ[i].second;
    int cnt = N;

    vector <bool> visited(N);
    visited[0] = true;

    queue <int> que; que.push(0);

    while (!que.empty()){
      int now = que.front(); que.pop();
      int X = XY[now].first, Y = XY[now].second;

      pair <int, int> next = make_pair(X - P, Y - Q);

      for (int j = 0; j < N; j++){
        if (XY[j] == next && visited[j] == false){
          visited[j] = true;
          que.push(j);
          cnt--;
          break;
        }
      }
      
      if (que.empty()){
        for (int j = 0; j < N; j++){
          if (visited[j] == false){
            que.push(j);
            visited[j] = true;
            break;
          }
        }
      }
    }

    if (ans > cnt) ans = cnt;
  }
  
  cout << ans << endl;


  return 0;
}


Measured memory_bytes: 256
from collections import defaultdict
N = int(input())
cnt = defaultdict(int)
for c in input():
    cnt[c] += 1
for _ in range(N-1):
    tmp_cnt = defaultdict(int)
    for c in input():
        tmp_cnt[c] += 1

    for k, v in cnt.items():
        cnt[k] = min(cnt[k], tmp_cnt[k])
ans = ''
for k, v in cnt.items():
    ans += k*v
print(''.join(sorted(ans)))


Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
int n,k,t;
int main()
{
	scanf("%d%d",&n,&k);
	if(k>(n-1)*(n-2)/2)
	{
		printf("-1");
		return 0;
	}
	int s=(n-1)*(n-2)/2;
	printf("%d\n",n-1+s-k);
	for(int i=2;i<=n;i++)
		printf("1 %d\n",i);
	for(int i=2;i<=n,t<s-k;i++)
	{
		for(int j=i+1;j<=n;j++)
		{
			t++;
			if(t<=s-k)
				printf("%d %d\n",i,j);
		}
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <map>
#include <queue>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
using P = pair<ll, int>;
const ll INF = 1e+18;

struct edge{
  int to, cost;
  edge(int To, int Cost): to(To), cost(Cost){}
};

void dijkstra(vector<vector<edge>> &graph, vector<ll> &dist, int start) {
  int V = graph.size();
  dist.resize(V, INF);
  dist[start] = 0;
  priority_queue<P, vector<P>, greater<P>> pq;
  pq.emplace(dist[start], start);
  while(!pq.empty()) {
    P p = pq.top();
    pq.pop();
    int v = p.second;
    if(dist[v] < p.first) {
      continue;
    }
    for(auto node: graph[v]) {
      if(node.to >= V) {
        cout << node.to << endl;
      }
      if(dist[node.to] > dist[v] + node.cost) {
        dist[node.to] = dist[v] + node.cost;
        pq.emplace(dist[node.to], node.to);
      }
    }
  }
  
}

int main() {
  int v, e, start;
  cin >> v >> e >> start;
  vector<vector<edge>> graph(v);
  rep(i, e) {
    int s, t, d;
    cin >> s >> t >> d;
    graph[s].push_back(edge(t, d));
  }
  vector<ll> dist;
  dijkstra(graph, dist, start);
  rep(i, v) {
    if(dist[i] == INF) {
      cout << "INF" << endl;
    }
    else {
    cout << dist[i] << endl;
    }
  }
  return 0;
}


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

int main(){
  int N,M;
  cin>>N>>M;
  vector<int> x(M);
  for(int i=0;i<M;i++){
    cin>>x[i];
  }
  sort(x.begin(), x.end());
  //Mが1のときの例外処理をいれるよう
  if (M==1){cout<<"0"<<endl;return 0;}
  
  vector<int> x_(M-1);
  for(int i=0;i<M-1;i++){//これで差分が代入される
    x_[i]=x[i+1]-x[i];
  }
  //差分をソート、小さい順
  sort(x_.begin(), x_.end());
  //大きいほうの差分N-1個は無視できる
  //このときN>Mなら
  if (N>M){
    cout<<"0"<<endl;return 0;
  }
  int sum = accumulate(x_.begin(),x_.end() - (N-1), 0);
  cout<<sum;
  return 0;
}

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

int main(){
    ll A,B;
    cin >> A >> B;

    ll c=1;
    ll i=0;
    ll tp=0;

    while(c<B){
        if(i==0){
            c += A - 1;
            tp+=1;
        }else{
            for(ll j=0;j<=c;j++){
                c += A - 1;
                tp++;
                if(c>=B) break;
            }
        }
        i++;
    }

    cout << tp << endl;
    return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/stack:256000000")
#include<utility>
#include<iostream>
#include<vector>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<functional>
#include<random>
#include<climits>
#include<queue>
#include<stack>
#include<deque>
#include<bitset>
#include<map>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<cassert>
#include<ccomplex>

//4Head
#define all(x) x.begin(), x.end()
#define mp make_pair
#define X first
#define Y second

using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
mt19937_64 gen(time(NULL));

// belik's shit
ll const mod = 1e9 + 7;
namespace {
	ll mult(ll& a, ll& b) {
		ll val = a * b - (ll)((ld)a * b / mod) * mod;
		if (val < 0) {
			val += mod;
		}
		if (val >= mod) {
			val -= mod;
		}
		return val;
	}
	ll poww(ll a, ll b)
	{
		ll val = 1;
		a %= mod;
		while (b > 0){
			if (b % 2) val = mult(a, val);
			a = mult(a, a);
			b >>= 1;
		}
		return val % mod;
	}
	ll inv(ll a) {
		return poww(a, mod - 2);
	}
}

ll const maxn = 3e5 + 5;

signed main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	ll n; cin >> n; vector<ll>a(n); for (ll i = 0; i < n; i++) cin >> a[i];
	for (ll i = 0; i < n; i++) a[i] = -a[i];
	vector<ll>d(n + 1, mod);
	d[0] = -mod;
	for (ll i = 0; i < n; i++) {
		ll pos = upper_bound(all(d), a[i]) - begin(d);
		d[pos] = a[i];
	}
	for (ll i = n; i >= 1; i--) {
		if (d[i] != mod) {
			cout << i << endl;
			return 0;
		}
	}

	return 0;
}
/*

*/

Measured memory_bytes: 1792
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] a = new int[N];
        int[] b = new int[N];
        for(int i = 0;i < N;i++){
            a[i] = sc.nextInt();
            b[i] = sc.nextInt();
        }
        int number = 0;
        for(int i = 0;i < N;i++){
            for(int j = 0;j < b[i]-a[i]+1;j++){
                number++;
            }
        }
        System.out.println(number);
    }
}

Measured memory_bytes: 25576
#include<iostream>
#include<vector>
#include<string>
#include<map>
#include<utility>
#include<algorithm>
#include<queue>
#include<cmath>
#include<iomanip>
#define REP(i, n) for(ll i = 0; i < n; i++)
#define REPR(i, n) for(ll i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(ll i = m; i <= n; i++)
#define FORR(i, m, n) for(ll i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n)
#define MAX 100000
#define inf 1000000007
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

int main() {
    //cin高速化
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,ans,tmp;
    cin >> n;
    ans = 0;
    vll a(n+1,0);//初期化忘れない
    vll b(n+1,0);
    vll dp(n, 0);
    FOR(i,1,n){
        cin >> tmp;
        a[i] = i+tmp;
        b[i] = i-tmp;
        if(b[i] > 0)dp[b[i]] += 1;
    }

    FOR(i, 1, n){
        if(a[i] < n) ans += dp[a[i]];
    }
    cout << ans <<"\n";
	return 0;
}

Measured memory_bytes: 7920
#include <iostream>
using namespace std;
int main () {

	int a, b, c, d;
    int count1, count2;
    float t1, t2;
    count1 = 0;
    count2 = 0;


	cin>>a>>b>>c>>d;

	t1 = c;
    t2 = a;
    while (t1 > 0) {
          t1 -= b;
          count1 += 1;
    }

    while (t2 > 0) {
    	t2 -= d;
    	count2 += 1;
    }

    if (count1 <= count2) {
    	cout << "Yes" << endl;
    }
    else {
    	cout << "No" << endl; 
    }


	return 0;
}

Measured memory_bytes: 3676
n=int(input())
alist = list(map(int, input().split()))
alist=sorted(alist)
answer=1
ng=0
for i in range(n):
    if ng==0:
        answer*=alist[i]
        if answer>10**18:
            ng=1

if ng==1:
    print(-1)
else:
    print(answer)

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

int main(){
	int N,M,in,out,s,ans=0;
	cin>>N>>M;
	s=ans=M;
	for(int i=0;i<N;i++){
		cin>>in>>out;
		s+=in-out;
		if(s<0){
			puts("0");
			return 0;
		}
		ans=max(ans,s);
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 1144
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

int main(){
	int A,B,C,N;
	int tmp;
	cin >> A >> B >> C >> N;
	while(N > 0){
		if (A > B && A > C){
			A *= 2;

		}
		else if(B > C && B > A){
			B *= 2;
		}
		else{
			C *= 2;

		}
		N--;
	}
	cout << A + B + C <<endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()
#define LL long long

using namespace std;

int main(){

    string A;cin>>A;
    vector<string> s;

    int pt=A.size();
    int step[pt+1][26];
    REP(i,26)step[pt][i]=-1;

    while(pt>0){
        pt--;
        REP(i,26)step[pt][i]=step[pt+1][i];
        step[pt][A[pt]-'a']++;

        bool all=true;
        REP(i,26)all=all&& (step[pt][i]>=0);
        if(all)REP(i,26)step[pt][i]=-1;
    }

    char alpha[26];
    REP(i,26)alpha[i]='a'+i;
    string ans="";

    int pointer=0;

    while(pointer<=A.size()){
        REP(i,26)if(step[pointer][i]==-1){
                ans+=alpha[i];
                while(pointer<=A.size()&&A[pointer]!=alpha[i])pointer++;
                pointer++;
                break;
            }
    }



    cout<<ans<<endl;


    return 0;
}

Measured memory_bytes: 20868
#include <iostream>
#include <algorithm>

using namespace std;

int main() {
    int n;
    long c;
    cin >> n >> c;
    long x[n], v[n], l[n+1], r[n+1], lb[n+1], rb[n+1];
    l[0] = 0; r[n] = 0; lb[0] = 0; rb[n] = 0;
    for (int i=0; i<n; i++)
        cin >> x[i] >> v[i];
    long suml=0, sumr=0;
    for (int i=0; i<n; i++) {
        suml += v[i];
        sumr += v[n-1-i];
        l[i+1]    = max(l[i],    suml - x[i]);
        lb[i+1]   = max(lb[i],   suml - x[i]*2);
        r[n-1-i]  = max(r[n-i],  sumr - (c - x[n-1-i]));
        rb[n-1-i] = max(rb[n-i], sumr - (c - x[n-1-i])*2);
    }
    long best=0;
    for (int i=0; i<=n; i++)
        best = max({best, l[i] + rb[i], r[i] + lb[i]});
    cout << best << '\n';
    return 0;
}

Measured memory_bytes: 4992
#include <iostream>
#include <vector>
#include <string>
#include <cctype>
#include <cmath>
#include <iomanip>
#include <climits>
#include <cfloat>
#include <algorithm>
#define PB push_back
#define ll long long
#define ull unsigned long long
#define uint unsigned
#define PIE (3.14159265358979323846)
#define MOD 1000000007;
using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    size_t a {}, b {}, m {};
    cin >> a >> b >> m;
    vector<int> arr1 (a);
    vector<int> arr2 (b);
    int mn1 {INT_MAX}, mn2 {INT_MAX};
    for (auto &val: arr1) {
        cin >> val;
        mn1 = min(mn1, val);
    }
    for (auto &val: arr2) {
        cin >> val;
        mn2 = min(val, mn2);
    }

    int ans {INT_MAX};
    while (m--) {
        int x {}, y {}, c {};
        cin >> x >> y >> c;

        ans = min(arr1.at(x-1) + arr2.at(y-1) - c, ans);
    }
    cout<<min(ans, mn2+mn1)<<endl;
    return 0;
}


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

#define f first
#define s second
#define ins insert
#define eb emplace_back
#define endl '\n'
#define ll long long
#define ld long double
#define vl vector<ll>
#define no cout << "NO" << endl
#define yes cout << "YES" << endl
#define tc ll t; cin >> t; while (t--)
#define sz(c) (ll) (c).size()
#define trav(x,c) for(auto &x : c)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define _for(i,a,n) for(ll i = a ; i < n; ++i)
#define _rfor(i,a,n) for(ll i = n-1 ; i >= a; --i)
#define db(x) cout << #x << ": " << x << endl;
#define _db(c) trav(x,c) cout << x << " "; cout << endl;
#define godspeed ios::sync_with_stdio(0); cin.tie(0);
template<typename... T> void read(T&... x) {((cin >> x),...);}

int main() {
    godspeed;
    int n; cin >> n;
    if(n%1000 == 0) cout << 0;
    else cout << 1000 - n%1000;
}

Measured memory_bytes: 3648
fn main() {
	let line = read_vec::<usize>();
	let mut n = Vec::new();
	let mut m = Vec::new();
	for i in 0..line[0] {
		n.push(read_vec::<i32>());
	}
	for i in 0..line[1] {
		m.push(readLine::<i32>());
	}

	for xs in &n {
		println!("{}", xs.iter().zip(&m)
			.map(|(x, y)| x * y)
			.sum::<i32>());
	}
}

fn readLine<T: std::str::FromStr>() -> T {
    let mut line = String::new();
    std::io::stdin().read_line(&mut line).ok();
    line.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}


Measured memory_bytes: 5048
//#include"pch.h"
//#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<algorithm>
#include<iostream>

using namespace std;
int main() {

	string s;


	cin >> s;
	for (int i = 0; i < s.size(); i++) {
		if (i % 2 == 0) {
			cout<<s[i];
		}
	}
	cout << endl;




	return(0);
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<30
#define pb push_back
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

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

	vector<string> s(h);
	rep(i, h) cin >> s[i];

	vector<int> v[h];
	rep(i, h) {
		rep(j, w) {
			if(s[i][j] == 'c') v[i].push_back(j);
		}
	}

	rep(i, h) {
		rep(j, w) {
			int id = upper_bound(v[i].begin(), v[i].end(), j) - v[i].begin();
			if(id > 0) {
				cout << j - v[i][id-1];
			} else {
				cout << -1;
			}
			if(j == w-1) cout << endl;
			else cout << " ";
		}
	}

	return 0;
}

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

const int N = 310;

int n;
char a[N][N], b[N][N];

int shift(int x) {
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < n; ++j)
      b[i][j] = a[i][(j + x) % n];
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < n; ++j)
      if (b[i][j] != b[j][i])
        return 0;
  return 1;
}

int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i)
    scanf("%s", a[i]);
  int ans = 0;
  for (int j = 0; j < n; ++j)
    ans += shift(j);
  printf("%d\n", ans * n);
  return 0;
}

Measured memory_bytes: 384
#include<cstdio>
#include<queue>
#include<cstring>
#include<vector>
#include<algorithm>
using namespace std;
char a[4005],b[4005];
int l[4005],r[4005],top,wt[4005][4005],c[4005];
bool check[4005];
int n,last,ans=2147483647;
struct sd{int w,num;bool operator < (const sd &fu) const {return w<fu.w;};}st[4005];
int main() {
	scanf("%s%s",a+1,b+1);n=strlen(a+1);
	for(int i=1;i<=n;++i) a[i+n]=a[i],b[i+n]=b[i];
	for(int i=1;i<=n;++i) if(b[i]=='1') goto loop;
	for(int i=1;i<=n;++i) if(a[i]=='1') goto lp2;
	goto loop;
	lp2:;
	printf("-1");return 0;
	loop:;
	for(int i=n;i;--i) if(b[i]=='1') {last=i-n;break;}
	for(int i=1;i<=n;++i) {if(b[i]=='1') last=i;l[i]=i-last;}
	for(int i=1;i<=n;++i) if(b[i]=='1') {last=i+n;break;}
	for(int i=n;i;--i) {if(b[i]=='1') last=i;r[i]=last-i;}
	for(int i=0;i<n;++i) {//aÊý×éÕûÌåÓÒÒÆ
		memset(check,false,sizeof(check));int su=0;
		memset(c,0,sizeof(c));top=0;
		for(int j=1;j<=n;++j) if(b[j]!=a[j-i+n]) {st[++top]=(sd){l[(j-i+n)>n?(j-i):(j-i+n)],(j-i+n)>n?(j-i):(j-i+n)};wt[r[(j-i+n)>n?(j-i):(j-i+n)]][++c[r[(j-i+n)>n?(j-i):(j-i+n)]]]=(j-i+n)>n?(j-i):(j-i+n);su++;}
		sort(st+1,st+1+top);
		for(int j=0;j<n;++j) {
			for(int p=1;p<=c[j];++p) check[wt[j][p]]=true;
			while(check[st[top].num]) --top;
			ans=min(ans,st[top].w+j+j+st[top].w+i+su);
			ans=min(ans,j+j+st[top].w+abs(n-i-st[top].w)+su);
		}
	}
	for(int i=0;i<n;++i) {
		memset(check,false,sizeof(check));int su=0;
		memset(c,0,sizeof(c));top=0;
		for(int j=1;j<=n;++j) if(b[j]!=a[j+i]) {++su;st[++top]=(sd){r[(j+i)>n?(j+i-n):(j+i)],(j+i)>n?(j+i-n):(j+i)};wt[l[(j+i)>n?(j+i-n):(j+i)]][++c[l[(j+i)>n?(j+i-n):(j+i)]]]=(j+i)>n?(j+i-n):(j+i);}
		sort(st+1,st+1+top);
		for(int j=0;j<n;++j) {
			for(int p=1;p<=c[j];++p) check[wt[j][p]]=true;
			while(check[st[top].num]) --top;
			ans=min(ans,j+j+st[top].w+st[top].w+i+su);
			ans=min(ans,j+j+st[top].w+abs(n-i-st[top].w)+su);
		}
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 31488
#include <cstdio>
#include <cstring>
#include <iostream>

using namespace std;
#define N 100010
bool check(int x){
	int ans=0;
	for(int i=1;i<=x;i++){
		if(!(x%i))ans++;
	}
	if(ans==8)return 1;
	return 0;
}
int main(){
	int n;
	cin>>n;
	int ans=0;
	for(int i=1;i<=n;i+=2){
		if(check(i))ans++;
	}
	printf("%d\n",ans);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main () {
  int N;
  cin >> N;
  string S;
  cin >> S;
  bool ok = true;
  if (N % 2 == 1) {
    ok = false;
  }
  else {
    for (int i = 0; i < N / 2; i++) {
      if (S.at(i) != S.at(N / 2 + i)) {
        ok = false;
        break;
      }
    }
  }
  if (ok) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }

}

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

int main(void){
    int n,b,f,r,v;
    int count[4][3][10];
    
    for (int h=0; h<4; h++) {
        for (int i=0; i<3; i++) {
            for (int j=0; j<10; j++) {
                count[h][i][j]=0;
            }
        }
    }
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> b >> f >> r >> v;
        count[b-1][f-1][r-1] += v;
    }
    
    for (int h=0; h<4; h++) {
        if(h!=0)cout<<"####################\n";
        for (int i=0; i<3; i++) {
            for (int j=0; j<10; j++) {
                cout <<" "<< count[h][i][j];
            }cout << endl;
            
        }
    }
}

Measured memory_bytes: 1168
#include "bits/stdc++.h"

using namespace std;
using std::vector;

#define ll long long
#define vi vector<int>
#define vl vector<long long>
#define vvi vector<vi>
#define pi  pair<int,int>
#define mp  make_pair
#define pb  push_back
#define MOD int(1e9) + 7
#define PAI  3.1415926535
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define chmax(x, y) x = max(x,y)
#define chmin(x, y) x = min(x,y)
#define pr(x) cout << x << endl
#define Endl endl
#define rep(i, n) for(int i = 0 ; i < n; i++)

const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
const int ddx[8] = {-1,0,1,-1,1,-1,0,1};
const int ddy[8] = {-1,-1,-1,0,0,1,1,1};
const int inf = 99999999;
const ll linf = 1LL << 62;

ll gcd(ll a,ll b){
  if(a < b)swap(a , b);
  if(a % b != 0) return(gcd(b, a%b));
  return b;
}

ll lcm(ll a,ll b){
  if(a < b)swap(a , b);
  return (a / gcd(a , b)) * b;
}

int main(){

  int n; cin >> n;
  vi c(n), v(n);
  
  rep(i, n) cin >> c[i];
  rep(i, n) cin >> v[i];

  int ans = 0;
  rep(i, n){
    if(c[i] > v[i]){
      ans += c[i] - v[i];
    }
  }

  pr(ans);
  
  return 0;
}


Measured memory_bytes: 256
/*
*          Name : chaitanya
*
*     Institute : ANITS,Visakhapatnam
*
*/
#include<cstdio>
#include<iostream>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<complex>
#include<cstring>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<numeric>
#include<limits>
#include<climits>
#include<cfloat>
#include<functional>
#include<iterator>
#include <random>
#define infy  1000000000
#define all(x) begin(x),end(x)
#define ll long long int
#define ff first
#define ss second
#define pb push_back
const ll mod = 1000000007;
#pragma GCC optimization ("O3")
const int N = 1000010;
using namespace std;
int main()
{
 
  // freopen("input.txt","r",stdin);
  // freopen("output.txt","w",stdout);
  //ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  ll a,b;
  cin >> a >> b;
  ll k = (a*b)/__gcd(a,b);
  cout << k;
  return 0;
} 


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <limits.h>
#include <math.h>
#include <functional>
#include <bitset>
#include <iomanip>

#define repeat(i,n) for (long long i = 0; (i) < (n); ++ (i))
#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i] << '\n'
#define debugArrayP(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i].first<< " " << x[i].second << '\n'

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef vector<int> vint;
typedef vector<ll> vll;
const ll INF = INT_MAX;
const ll MOD = 1e9+7;


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll X,Y;cin>>X>>Y;
  cout <<(X%Y==0? -1:X*(Y-1))<<endl;
  return 0;
}


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

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define COUT(x) cout<<(x)<<"\n"

int main(){
    int n;
    cin>>n;
    vector<ll> a(n);
    REP(i,n){
        cin >> a[i];
    }
    ll max1 = a[0];
    ll ans = 0;
    for(int i=1;i<n;i++){
        ans += max(max1-a[i],(ll)0);
        max1 = max(max1,a[i]);
    }
    COUT(ans);
}

Measured memory_bytes: 4752
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
##############################

import math


N, M = map(int, input().split())

nm = abs(N-M)
remain = 10**9 + 7
if nm >= 2:
    print(0)
elif nm == 1:
    print(math.factorial(N) % remain * math.factorial(M)% remain )
else:
    print(2 * math.factorial(N)% remain  * math.factorial(M)% remain )


Measured memory_bytes: 4096
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;


int main(int argc, const char * argv[]) {
    string s;
    cin >> s;
    for(int i = 0; i < s.size(); i++){
        if(s.at(i) == ','){
            cout << ' ';
        }else{
            cout << s.at(i);
        }
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define reps(i,a,b) for(int i=a;i<b;++i)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template<typename T> inline bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T &a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U &u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U &u,const V... v){for(auto &e:u)fill_v<T>(e,v...);}

const int mod = 1000000007;

struct mint {
    long long x;
    mint(long long x=0) : x((x % mod + mod) % mod) {}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
    mint operator+(const mint a) const { return mint(*this) += a;}
    mint operator-(const mint a) const { return mint(*this) -= a;}
    mint operator*(const mint a) const { return mint(*this) *= a;}
    mint pow(long long t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    mint inv() const { return pow(mod-2);}
    mint& operator/=(const mint a) { return *this *= a.inv();}
    mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
bool operator==(const mint& a, const mint& b) { return a.x == b.x;}

struct combination {
    vector<mint> fact, ifact;
    combination(int n) : fact(n+1), ifact(n+1) {
        assert(n < mod);
        fact[0] = 1;
        for (int i = 1; i <= n; ++i) fact[i] = fact[i-1] * i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i] * i;
    }
    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n] * ifact[k] * ifact[n-k];
    }
};
// combination c(max);
// mint c(n, k)

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

    int k;
    cin >> k;
    string s;
    cin >> s;
    int n = sz(s);
    mint ans = 0;
    combination c(n+k);
    for (int i = n; i <= n+k; ++i) {
        ans += c(i-1, n-1) * mint(25).pow(i-n) * mint(26).pow(n+k-i);
    }
    cout << ans << endl;
}


Measured memory_bytes: 35680
#include <bits/stdc++.h>
using namespace std;
char s[300][300];
bool chk[300][300];
int main()
{
    int h,w; cin>>h>>w;
    for(int i=0;i<h;i++) scanf("%s",s[i]);
    for(int i=0;i<h;i++)
    {
        bool flag=false;
        for(int j=0;j<w;j++) if(s[i][j]=='#') flag=true;
        if(!flag) for(int j=0;j<w;j++) chk[i][j]=true;
    }
    for(int i=0;i<w;i++)
    {
        bool flag=false;
        for(int j=0;j<h;j++) if(s[j][i]=='#') flag=true;
        if(!flag) for(int j=0;j<h;j++) chk[j][i]=true;
    }
    for(int i=0;i<h;i++)
    {
        bool flag=false;
        for(int j=0;j<w;j++) if(!chk[i][j]) flag=true,printf("%c",s[i][j]);
        if(flag) puts("");
    }
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    int n,a,mx=0,mn=1000000000;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a;
        mx=max(a,mx);
        mn=min(a,mn);
    }
    cout<<mx-mn<<endl;
    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<vector>

using namespace std;

typedef pair<double,double> P;
double EPS = 1e-10;

double add(double a, double b){
  if(abs(a+b) < EPS * (abs(a)+abs(b)))return 0;
  return a+b;
}

struct point{
  double x, y;
  point(){}
  point(double x,double y) : x(x) , y(y){}

  point operator + (point p){
    return point(add(x,p.x), add(y,p.y));
  }

  point operator - (point p){
    return point(add(x,-p.x), add(y,-p.y));
  }

  point operator * (double d){
    return point(x*d,y*d);
  }

  point operator / (double d){
    return point(x/d,y/d);
  }
};


struct circle{
  point p;
  double r;
};

vector<point> circles_cross(circle a, circle b){
    vector<point> ret;
     
    double x = a.p.x - b.p.x , y = a.p.y - b.p.y;
    double L = x * x + y * y;
    if(L > pow(a.r+b.r,2))return ret;
     
    L = sqrt(L);
    double C = atan2(b.p.y-a.p.y,b.p.x-a.p.x);
    double alpha = acos((L*L+a.r*a.r-b.r*b.r)/(2*L*a.r));
     
    point r1,r2;
    r1.x = a.p.x + cos(C+alpha) , r1.y = a.p.y + sin(C+alpha);
    r2.x = a.p.x + cos(C-alpha) , r2.y = a.p.y + sin(C-alpha);
     
    ret.push_back(r1) , ret.push_back(r2);
     
    return ret;
}

int main(void){
  int n;
  circle a[100];

  while(cin >> n,n){
    vector<P>d;

    for(int i=0;i<n;i++){
      scanf("%lf,%lf",&a[i].p.x,&a[i].p.y);
      a[i].r=1;
    }
    /*
      for(int i=0;i<n;i++){
      for(int j=i+1;j<n;j++){
      double L=sqrt(pow(x[i]-x[j],2)+pow(y[i]-y[j],2));
      if(L>2.0000)continue;
      double theta=atan2(y[j]-y[i],x[j]-x[i]);
      double a=acos(L/2);
      d.push_back(make_pair(x[i]+cos(theta+a),y[i]+sin(theta+a)));
      d.push_back(make_pair(x[i]+cos(theta-a),y[i]+sin(theta-a)));
      }
      }
    */
    for(int i=0;i<n;i++){
      for(int j=i+1;j<n;j++){
	vector<point> p=circles_cross(a[i],a[j]);
	for(int k=0;k<p.size();k++){
	  d.push_back(make_pair(p[k].x,p[k].y));
	}
      }
    }
    /*
    for(int i=0;i<d.size();i++){
      cout << d[i].first << " " <<d[i].second << endl;
    }
    */
    int count,ans=1;
    for(int i=0;i<d.size();i++){
      count=0;
      
      for(int j=0;j<n;j++){
	if(pow(d[i].first-a[j].p.x,2)+pow(d[i].second-a[j].p.y,2)<=1+EPS)count++;
      }
	ans=max(ans,count);
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define dunk(n) cout << n << endl
#define all(a) (a).begin(),(a).end()
int gcd(int a,int b){
    if(b > a) swap(a,b);
    int r = a%b;
    while(r != 0){
        a = b;
        b = r;
        r = a%b;
    }
    return b;
}

int main() {
    int k,ans = 0;
    cin >> k;
    for(int a = 1; a <= k; a++){
        for(int b = 1; b <= k; b++){
            for(int c = 1; c <= k; c++){
                ans += gcd(gcd(c,b),a);
            }
        }
    }
    dunk(ans);
}

Measured memory_bytes: 3632
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <unordered_map>
#include <map>
#include <unordered_set>
#include <set>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <array>
#include <deque>
#include <bitset>
typedef long long ll;
using namespace std;
#define trace(x) cerr << #x << " is " << x << endl;

const ll INF = 1e18L + 5;

int main() {
    int n, w;
    scanf("%d", &n);
    scanf("%d", &w);
    int weight[n + 1];
    int value[n + 1];
    int value_sum = 0;
    for (int i = 1; i <= n; i++) {
        scanf("%d", &weight[i]);
        scanf("%d", &value[i]);
        value_sum += value[i];
    }
    vector<ll> dp(value_sum + 1, INF);
    dp[0] = 0;
    for (int i = 1; i <= n; i++) {
        for (int j = value_sum; j >= 0; j--) {
            if (j >= value[i]) {
                dp[j] = min(dp[j - value[i]] + weight[i], dp[j]);
            }
        }
    }
    ll res = 0L;
    for (int i = 1; i <= value_sum; i++) {
        if (dp[i] <= w) {
            res = max((ll)i, res);
        }
    }
    cout << res <<endl;
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstdlib>
#include <stack>
#include <vector>
#include <algorithm>
using namespace std;


int main(int argc, char const *argv[])
{
	stack<int> S1;
	stack<pair<int, int> > S2;
	char ch;
	int sum = 0;
	for (int i = 0; cin >> ch; i++) {
		if (ch == '\\') S1.push(i); 
		else if (ch == '/' && S1.size() > 0) {
			int j = S1.top(); S1.pop();
			sum += i - j;
			int a = i -j;
			while (S2.size() > 0 && S2.top().first > j) {
				a += S2.top().second; S2.pop();
			}
			S2.push(make_pair(j, a));
		}
	}

	vector<int> ans;
	int t = 0;
	while (S2.size() > 0) {
		ans.push_back(S2.top().second);
		S2.pop();
	}
	reverse(ans.begin(), ans.end());
	cout << sum << endl;
	cout << ans.size();
	for (int i = 0; i < ans.size(); i++) {
		cout << " ";
		t += ans[i];
		cout << ans[i];
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 1284
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int K, X;
    cin >> K >> X;

    int start = X - (K-1);
    int tmp = start;
    int N = (K-1) * 2 + 1;
    vector <int> data(N);

    for(int i = 0; i < N; i++){
        data[i] = tmp;
        tmp = tmp + 1;
    }

    for(int i = 0; i < N; i++){
            cout << data[i] << " " ;
    }

    return 0;
}

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

#define ran 101101

int n, k, ans;
vector<int> e[ran];

struct modular_arithmetic{
	int mod;

	modular_arithmetic(){
		mod = 1000000007;
	}
	//No specific settings.
	int mul(int x,int y){return (int)((long long int)x*y%mod);}
};
modular_arithmetic ma;

void dfs(int cur, int par) {
	if (cur==1) {
		for(int i=0;i<=e[cur].size();i++)
			ans = ma.mul(ans, k-i);
	} else {
		int t = 1;
		for(int i=0;i<=(int)e[cur].size()-2;i++)
			t = ma.mul(t, k-2-i);
		ans = ma.mul(ans, t);
	}
	
	for(int i=0;i<(int)e[cur].size();i++) {
		int nxt = e[cur][i];
		if (nxt==par) continue;
		
		dfs(nxt, cur);
	}
}

int main() {
	scanf("%d%d", &n, &k);
	for(int i=1;i<n;i++) {
		int x, y;
		scanf("%d%d", &x, &y);
		e[x].push_back(y); e[y].push_back(x);
	}
	
	int ma = 0;
	for(int i=1;i<=n;i++)
		ans = max(ans, (int)e[i].size());
	if(ma>k) {
		puts("0");
		return 0;
	}
	
	ans = 1;
	dfs(1, -1);
	printf("%d\n", ans);
	
	return 0;
}

Measured memory_bytes: 10368
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <numeric>
#include <queue>
#include <vector>
#include <cmath>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <set>
#include <map>
#include <stack>

using namespace std;

template<class T> inline bool chmin(T& a, T b) {if (a > b) { a=b; return true; } return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) { a=b; return true; } return false;}

typedef long long LL;
typedef pair<int, int> PII;

#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repl(i, n) for(LL i = 0; i < (LL)(n); i++)

int main(void){
  string s, t;
  cin >> s >> t;

  for (int i = 0; i <s.length(); i++) {
    if (s[i] != t[i]) {
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;

  return 0;
}

Measured memory_bytes: 3624
#include<stdio.h>
#define MAX 100005
#define NIL -1
struct Node_struct{int p, l, r ,s,h;}; /*p: 親(parent), l: 一番左の子(left child), r:右の兄弟(right sibling),s(兄弟)*/
typedef struct Node_struct Node;
Node T[MAX];
int D[MAX];

void print(int u){
  int i, d=0;
  printf("node %d: parent = %d, sibling = %d,", u, T[u].p,T[u].s);
  
  if(T[u].r!=NIL)d++;
  if(T[u].l!=NIL)d++;
  printf(" degree = %d, depth = %d, height = %d, ",d, D[u],T[u].h);

  
  if(T[u].p==NIL) printf("root\n");
  else if(T[u].l==NIL && T[u].r==NIL) printf("leaf\n");
  else printf("internal node\n");
  
  
}

int calcDepth(int u, int p){
  int h1=0,h2=0; /* 再帰しない時の為の初期化 */
  D[u] = p;
  if(T[u].l!=NIL) h1=calcDepth(T[u].l,p+1);
  if(T[u].r!=NIL) h2=calcDepth(T[u].r,p+1);

  if(T[u].l==NIL && T[u].r==NIL){
    T[u].h=0;
    return 1;
  }

  T[u].h=h1<h2 ? h2 : h1;
  return T[u].h+1;
}

int main(){
  int i, j, k;
  int n;
  int id, l,r, child;
  int root = NIL;
  scanf("%d", &n);
  for(i=0; i<n; i++) T[i].p = T[i].l = T[i].r =T[i].s= NIL;
  
  for(i=0; i<n; i++){
    scanf("%d%d%d", &id,&l,&r);
     //子を入力する (input children)
      
      T[l].p = id;
      T[r].p = id;
      T[l].s = r;
      T[r].s = l;
      T[id].r=r;
      T[id].l=l;
      
    
  }

  //根を求める (find the root)
  for(i=0; i<n; i++){
    if(T[i].p == -1) root = i;
  }
  
  //それぞれのノードの深さを求める (find depth of each node)
  calcDepth(root, 0);

  //出力 (output)
  for(i=0; i<n; i++) print(i);
  
  return 0;
}



Measured memory_bytes: 2052
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;
 
 
public class Main {

	static long MOD = 1_000_000_007;
	static int[][] map;
	static long[][] dp;
	static int[] dx = {1,-1,0,0};
	static int[] dy = {0,0,1,-1};
	public static void main(String[] args) throws Exception {
		// TODO Auto-generated method stub
		//int N = Integer.parseInt(sc.next());
		//long L = Long.parseLong(sc.next());
		//char[] c = sc.next().toCharArray();
		int INF = Integer.MAX_VALUE;
		int ans = 0;
		
		Scanner sc = new Scanner(System.in);
		int X = Integer.parseInt(sc.next());
		int A = Integer.parseInt(sc.next());
		
		if (X<A){
			ans=0;
		}else{
			ans=10;
		}

		
		System.out.println(ans);
		
	}
}



Measured memory_bytes: 22228
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin >> n;
  vector<int> data(n);
  for (int i = 0; i < n; i++) {
    cin >> data.at(i);
  }
  
  int count = 0;
  
  for(int i = 0; i < 30; i++) {
    for (int j = 0; j < n; j++) {
    if (data.at(j) % 2 != 0) {
      break;
    }
    else {
      data.at(j) = data.at(j) / 2;
      count++;
    }
      
  }
    }
  cout << count / n << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>

using namespace std;

int main() {
    long n, a, b;
    cin >> n >> a >> b;
    if (n + 1 < a + b || n > a * b) {
        cout << -1 << '\n';
        return 0;
    }
    long start = n + 1, 
        sets  = (b == 1 ? 0 : (n - a) / (b - 1)), 
        r     = (b == 1 ? 0 : (n - a) % (b - 1));
    for (long i=0; i<b; i++) {
        long end = start;
        if (i == b-1)
            start = 1;
        else
            start -= sets + (i < r);
        for (long j=start ; j<end; j++) 
            cout << j << (j < end-1 || i < b-1 ? ' ' : '\n');
    }
    return 0;
}

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

using ll = long long int;

bool solve(){
    ll n;
    cin >> n;
    ll ans = 0, m = 1;
    while(m < n){
        m *= 3;
        ans++;
    }
    cout << ans << endl;
    return false;
}

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


Measured memory_bytes: 3112