akhauriyash/Code-Regression huggingface dataset:
#include <iostream> // cin, cout, cerr, clog
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota, accumulate, inner_product
#include <cstdio> // printf, scanf
#include <climits> // INT_MIN, LLONG_MIN
#include <cmath> // long, trig, pow
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <deque> // deque
#include <stack> // stack
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <unordered_map> // hashed by keys
#include <unordered_set> // hashed by keys
#include <iomanip> // cout<<setprecision(n)
#include <functional> // std::function<void(int)>

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

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

template <typename T>
std::vector<T> dijkstra(int s,std::vector<std::vector<std::pair<int, T> > > & G){
	using namespace std;
  const T INF = numeric_limits<T>::max();
  using P = pair<T, int>;
  int n=G.size();
  vector<T> d(n,INF);
  vector<int> b(n,-1);
  priority_queue<P,vector<P>,greater<P> > q;
  d[s] = 0;
  q.emplace(d[s],s);
  while(!q.empty()){
    P p=q.top();q.pop();
    int v=p.second;
    if(d[v]<p.first) continue;
    for(auto& e:G[v]){
      int u=e.first;
      T c=e.second;
      if(d[u]>d[v]+c){
        d[u]=d[v]+c;
        b[u]=v;
        q.emplace(d[u],u);
      }
    }
  }
  return d;
}

struct Barrier
{
	int x,y,r;
	Barrier(int x, int y, int r) : x(x), y(y), r(r) {}
};

signed main() {
	std::vector<Barrier> barriers;
	{
		//start
		int x,y;
		std::cin >> x >> y;
		barriers.emplace_back(x,y,0);
	}
	{
		//end
		int x,y;
		std::cin >> x >> y;
		barriers.emplace_back(x,y,0);
	}
	int n;
	std::cin >> n;
	rep(i,n) {
		int x,y,r;
		std::cin >> x >> y >> r;
		barriers.emplace_back(x,y,r);
	}
	std::vector<std::vector<std::pair<int, double> > > from(n+2,std::vector<std::pair<int,double> >());
	for(int i=0;i<n+2;i++) {
		for(int j=0;j<n+2;j++) {
			if(i==j) continue;
			Barrier& a = barriers[i];
			Barrier& b = barriers[j];
			double zero = 0;
			double len = std::max(zero,std::sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y))-a.r-b.r);
			from[i].emplace_back(j,len);
			from[j].emplace_back(i,len);
		}
	}
	std::vector<double> D = dijkstra<double>(0,from);
	print(D[1]);

	return 0;
}


Measured memory_bytes: 38256
#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 h, n;
  cin >> h >> n;
  vector<int> a(n), b(n);
  rep(i, n) { cin >> a[i] >> b[i]; }
  vector<int> dp(h + 1, INT_MAX);
  dp[0] = 0;
  for (int i = 1; i <= h; i++)
    rep(j, n) dp[i] = min(dp[i], dp[max(i - a[j], 0)] + b[j]);
  cout << dp[h] << endl;
}


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

const int N = 21;

int n, m;
int f[N][1 << N], len[1 << N];
int trans[1 << N][2];
// f[k][S|T]: 已经匹配 S，还需要添加的内容 T' 是 T 的子序列, |T| = k, |S| + '1' + |T| = N + 1, 状态数 O(n*2^n)
inline char nc()
{
	static char buf[1000000], *p1 = buf, *p2 = buf;
	return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin), p1 == p2)? EOF : *p1++;
}

inline int read()
{
	int neg = 1, res = 0;
	char ch;
	do 
	{
		ch = nc();
		if (ch == '-') neg = -1;
	} while (ch < 48 || ch > 57);
	do res = res * 10 + ch - 48, ch = nc(); while (ch >= 48 && ch <= 57);
	return res * neg;
}

inline int read_bit()
{
	char ch;
	do ch = nc(); while (ch != 48 && ch != 49);
	return ch - 48;
}

int main()
{
	n = read(), m = read();
	for (int i = 0; i <= n; ++i)
	{
		for (int j = 0; j < (1 << i); ++j)
		{
			f[i][1 << i | j] = read_bit();
		}
	}
	len[0] = -1;
	for (int i = 1; i <= 1 << (n + 1); ++i) len[i] = len[i >> 1] + 1;

	for (int S = 2; S <= 1 << (n + 1); ++S)
	{
		if (S >> (len[S] - 1) & 1)
		{
			trans[S][1] = S ^ (1 << len[S]); // 由于形如 1 + T，因此消掉前缀1即可
			trans[S][0] = trans[trans[S][1]][0];
		}
		else
		{
			trans[S][0] = S ^ (3 << (len[S] - 1)); // 消掉前缀 1 同时补一个前缀
			trans[S][1] = trans[trans[S][0]][1];
		}
	}

	for (int i = n; i >= 1; --i)
	{
		for (int S = 1 << i; S < (1 << (n + 1)); ++S)
		{	// S: [A|B]
			if (f[i][S])
			{
				int A = S >> i, B = (S & (1 << i) - 1) | 1 << i, T = 0;
				if (T = trans[B][0]) f[len[T]][(A << 1 | 1) << len[T] ^ T] += f[i][S];
				if (T = trans[B][1]) f[len[T]][(A << 1 | 0) << len[T] ^ T] += f[i][S];
				f[0][A] += f[i][S];
			}
		}
	}
	int ans = 1;
	for (int S = 2; S < 1 << (n + 1); ++S) if (f[0][S] >= m && len[S] > len[ans]) ans = S;
//	for (int i = 0; i <= n; ++i) for (int j = 0; j < 1 << n + 1; ++j) if (f[i][j]) printf("f[%d][%d] = %d\n", i, j, f[i][j]);
//	printf("ans = %d\n", ans);
	int j = n;
	while (~ans >> j & 1) --j;
	while (j--) printf("%d", ans >> j & 1);
	putchar('\n');
//	for (int i = 0; i <= n; ++i) for (int j = 0; j < (1 << N); ++j) if (f[i][j]) printf("state (%d, %d)\n", i, j);
	
	return 0;
}

Measured memory_bytes: 195964
#include<iostream>
#include<set>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i < (int)(n); i++)

#include <algorithm>
using namespace std;
#include <cmath>
#include <string>
#define elif else if
typedef long long ll;

int main(){
  int N;
  cin >>N;
  int h[110]={0};

  rep(i,N){
    cin>>h[i];
  }

  int ans = h[0];
  rep1(i,N){
    if(h[i]>h[i-1]){
      ans+=h[i]-h[i-1];
    }

  }

  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
int main(){
    int D,R,S;
    cin>>D>>R>>S;
    if(D<=R*S)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 3132
#include<iostream>
using namespace std;
 
int main(){
   int n,m;
    cin>>n>>m;
    int a[n][m];
    int sum[n];
    int sum2[m+1];
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            cin>>a[i][j];
        }
        sum[i]=0;
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            cout<<a[i][j]<<" ";
            sum[i]+=a[i][j];
        }
        cout<<sum[i]<<endl;
    }
    for(int j=0;j<=m;j++){
        sum2[j]=0;
    }
    for(int j=0;j<m;j++){
        for(int i=0;i<n;i++){
            sum2[j]+=a[i][j];
        }
        cout<<sum2[j]<<" ";
        sum2[m]+=sum2[j];
    }
    cout<<sum2[m]<<endl;
    return(0);
}

Measured memory_bytes: 3084
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
  public static void main(String[] args) throws IOException {
    Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
    int n = in.nextInt();
    int W = in.nextInt();
    int[] w = new int[n];
    int[] v = new int[n];
    for (int i = 0; i < n; i++) {
      w[i] = in.nextInt();
      v[i] = in.nextInt();
    }
    final Solver solve = new Solver();
    System.out.println(solve.solve(W, w, v));
  }
}


class Solver {
  public long solve(int W, int[] w, int[] v) {
    int n = w.length;
    int sum = 0;
    for (int i = 0; i < n; i++) {
      sum += v[i];
    }
    long[] dp = new long[sum+1];
    Arrays.fill(dp, 1000000000);
    dp[0] = (long)0;
    for (int item = 0; item < n; item++) {
      for (int val_already = sum - v[item]; val_already >= 0; val_already--) {
        dp[val_already + v[item]] = Math.min(dp[val_already + v[item]], dp[val_already]+w[item]);
      }
    }
    long answer = 0;
    for (int i = 0; i < dp.length; i++) {
      if (dp[i] <= W) {
        answer = Math.max(answer, i);
      }
    }
    return answer;
  }
}


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

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

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF INT_MAX/3

int n;
int a[111];

int main(){
	cin>>n;
  int res=0;
  rep(i,n)cin>>a[i];
  rep(i,n){
    int minj=i;
    repl(j,i,n){
      if(a[minj]>a[j])minj=j;
    }
    if(minj!=i){
      swap(a[minj],a[i]);
      res++;
    }
  }
  cout<<a[0];
  repl(i,1,n)cout<<" "<<a[i];
  cout<<endl;
  cout<<res<<endl;
	return 0;
}

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

#define rep(i, a, n)  for(ll i=a; i<n; i++)
#define per(i, a, n)  for(ll i=n-1; i>=a; i--)
#define fill0(n)  setfill('0') << right << setw(n)
#define all(x)  (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define LONGMAX 1e18
#define INTMAX 1000000000
using namespace std;
typedef long long ll;
typedef pair<ll,ll> p;

int n;

ll calc_sum(vector<ll> v){
  ll ret = 0;
  rep(i,0,v.size())ret+=v[i];
  return ret;
}

int main(){
  cin >> n;
  vector<ll> a(n+1,0);
  vector<ll> abs_a;
  ll cnt = 0;
  for(int i=1; i<n+1; i++){
    cin >> a[i];
    if(a[i] < 0)cnt++;
    abs_a.push_back(abs(a[i]));
  } 
  ll min = *min_element(all(abs_a));
  ll sum = calc_sum(abs_a);
  // cout << sum << endl;
  if(cnt%2==0)cout << sum << endl;
  else cout << sum-2*min << endl;

}

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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define range(a) a.begin(), a.end()

using namespace std;
using ll = long long;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int N; cin >> N;
  string S; cin >> S;
  // SA-IS O(n)
  vector<int> sa(N + 1); rep(i, N + 1) sa[i] = i;
  sort(range(sa), [&](int i, int j) {
    return S.substr(i) < S.substr(j);
  });
  // LCP O(n)
  vector<int> lcp(N + 1);
  rep(i, N) {
    int h = 0;
    while (sa[i] + h < N && sa[i + 1] + h < N && S[sa[i] + h] == S[sa[i + 1] + h]) h++;
    lcp[i] = h;
  }

  vector<int> ord(N);
  rep(i, N) ord[i] = i;
  // counting sort O(n)
  sort(range(ord), [&](int i, int j) { return lcp[i] > lcp[j]; });

  vector<int> l(N + 1);
  vector<int> r(N + 1);
  vector<int> mn(N + 1);
  vector<int> mx(N + 1);
  rep(i, N + 1) {
    l[i] = i;
    r[i] = i;
    mn[i] = sa[i];
    mx[i] = sa[i];
  }

  // O(n)
  int ans = 0;
  for (int i : ord) {
    int j = i + 1;
    int k = l[i];
    r[l[i]] = r[j];
    l[r[j]] = l[i];
    mn[k] = min(mn[k], mn[j]);
    mx[k] = max(mx[k], mx[j]);
    ans = max(ans, min(lcp[i], mx[k] - mn[k]));
  }
  cout << ans << endl;
}


Measured memory_bytes: 384
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();

		double[] money = new double[10];
		String[] dep = new String[10];

		for(int i = 0 ; i < N ; i++){
			money[i] = sc.nextDouble();
			dep[i] = sc.next();
		}

		sc.close();

		double ans=0.0;
		for(int i = 0 ; i < N ; i++){
			if(dep[i].equals("JPY")){
				ans += money[i];
			}
			else{
				ans += money[i] * 380000.0;
			}
		}

		System.out.println(ans);

	}
}

Measured memory_bytes: 22996
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <vector>
#include <string>
#include <iomanip>
#include <functional>
#include <cassert>
#include <cstdlib>
#include <cmath>
#include <cstring>
using namespace std;


typedef long long lint, ll;
typedef long double ldouble, ld;

#ifdef LOCAL
	#define dbg(expr) cerr << "[" << __LINE__ << "] " << #expr << " = " << (expr) << '\n';
#else
	#define dbg(expr) (void) 0;
#endif


bool check(int ind, const string & t, const string & s) {
    for (int i = 0; i < (int)t.length(); i++) {
        if (s[ind + i] == '?')
            continue;
        if (s[ind + i] != t[i])
            return false;
    }
    return true;
}

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

    string s, t;
    cin >> s;
    cin >> t;
    string ans = "";
    for (int i = 0; i < (int)s.length() - (int)t.length() + 1; i++) {
        if (check(i, t, s)) {
            auto cur = s;
            for (int j = 0; j < (int)t.length(); j++)
                cur[i + j] = t[j];
            for (char & c : cur) {
                if (c == '?')
                    c = 'a';
            }
            if (ans == "")
                ans = cur;
            ans = min(ans, cur);
        }
    }
    if (ans == "")
        cout << "UNRESTORABLE" << endl;
    else
        cout << ans << endl;
}

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

int gcd(int a, int b) {
	if (a == 0) {
		return b;
	} else if (b == 0) {
		return a;
	} else {
		return gcd(b, a % b);
	}
}

int a[100005];

int main() {

	int n, x;
	cin >> n >> x;
	
	int maxnum = 0;
	for (int i = 0; i < n; i++) {
		scanf("%d", &a[i]);

		maxnum = max(maxnum, a[i]);
	}

	if (x > maxnum) {
		printf("IMPOSSIBLE\n");
	} else {
		int gcdnum = a[0];
		for (int i = 1; i < n; i++) {
			gcdnum = gcd(gcdnum, a[i]);
		}

		if (x % gcdnum == 0) {
			printf("POSSIBLE\n");
		} else {
			printf("IMPOSSIBLE\n");
		}
	}

	return 0;
}

Measured memory_bytes: 640
import bisect
import sys
import collections
input = sys.stdin.readline
N = int(input())
A = [int(input()) for i in range(N)]
B = [A[0]]
B = collections.deque(B)
tmp = [0]*N
ans = 1
for i in range(1, N):
    id = bisect.bisect_left(B, A[i])
    if id == 0:
        B.appendleft(A[i])
    else:
        B[id-1] = A[i]
print(len(B))


Measured memory_bytes: 8832
n, q = map(int, input().split())
s = '*' + input().strip() + '*'
td = [tuple(input().strip().split()) for _ in range(q)]

def fall_d(i):
  now = i
  for t, d in td:
    if s[now] == t:
      if d == 'L':
        now -= 1
      else:
        now += 1
    if now == 0:
      return 'Left'
    elif now == n + 1:
      return 'Right'
  return 'Remain'

ll, lr = 0, n + 1
while ll != lr:
  mid = (ll + lr) // 2
  if fall_d(mid) == 'Left':
    ll = mid + 1
  else:
    lr = mid

rl, rr = 0, n + 1
while rl != rr:
  mid = (rl + rr) // 2
  if fall_d(mid) == 'Right':
    rr = mid
  else:
    rl = mid + 1

print(rr - ll)


Measured memory_bytes: 17968
/*
 * 	Just close your eyes
 * 		The sun is going down
 * 			You'll be alright...
 * 				No one can hurt you now
 * 					Come, morning light...
*/
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#ifndef rd
#define endl '\n'
#endif
#define deb cout<<"Line: "<<__LINE__<<" plz "
#define pb push_back
#define fi first
#define se second
//#define int long long
typedef long long ll;
#define pii pair<int,int>
#define sz(x) ((int)x.size())
#define fr(a,b,c) for(int a=b; a<=c; a++)
#define all(con) con.begin(),con.end()
const ll inf=1e18;
const int mod=1e9+7;
typedef vector<int> vi;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

void solve()
{
	int n,a,b;
	cin>>n>>a>>b;
	cout<<min(a,b)<<" "<<max(0,a+b-n)<<endl;
}
signed main() {
	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	srand(chrono::steady_clock::now().time_since_epoch().count());
	auto clk=clock();
	int t=1;
//	cin>>t;
	while(t--)
		solve();
#ifdef rd
	cout<<endl<<endl<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl;
#endif
	return 0;
}


Measured memory_bytes: 256
//ARC 095 C
#include <cstdio>
#include <algorithm>
using namespace std;
int x[200010],n,m1,m2,y[200010];
int main(){
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",&x[i]);
		y[i]=x[i];
	}
	sort(x,x+n);
	m1=x[n/2];
	m2=x[n/2-1];
	for(int i=0;i<n;i++)
		printf("%d\n",y[i]>m2?m2:m1);
}

Measured memory_bytes: 3712
#include <iostream>
#include <vector>
#include <math.h>
#include <string>
#define P 100003
#define N 100000
using namespace std;

int main(){
    int x,k;
    cin >> k >> x;
    if(k * 500 >= x){
        cout << "Yes" ;
    }else{
        cout << "No";
    }

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;   
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define ld long double
#define dd double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define sz(a) (ll)(a.size())
typedef long long ll;
typedef unsigned long long ull;
typedef pair <ll, ll> pll;
typedef pair <int, int> pii;
typedef vector<pll> vplll;
ll mod = 1e9+7;
const ld PI = 2 * acos(0.0);
const vector<ll> dx = {1, -1, 0, 0};
const vector<ll> dy = {0, 0, 1, -1};
#define round(x, y) ((x + y - 1) / y)
#define ce(x, y) ((x + y - 1) / y)
#define amax(x, y) \
    if (y > x)     \
        x = y;
#define amin(x, y) \
    if (y < x)     \
        x = y;
#define lcm(x, y) ((x) * (y) / __gcd(x, y))
#define len(x) (ll) x.length()
#define sq(x) ((x) * (x))
#define cb(x) ((x) * (x) * (x))
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll a,b,c,t,n,m,k,q; 
    t = 1;
    // cin>>t;
    while(t--)
    {
    	cin>>a>>b;
    	if(b>=a)
    	{
    		cout<<"unsafe"<<endl;
    	}
    	else
    		cout<<"safe"<<endl;
    }
    return 0;
}

Measured memory_bytes: 3652
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>
 
using namespace std;
using ll = long long;
 
void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); }
void _cout(){ cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); }
int gcd(int a, int b){ return (b == 0) ? a : gcd(b, a % b); }
 
#define For(i, n) for(int i = 0; i < (n); i ++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Search(rb, re, x) distance(rb, find(rb, re, x))
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Reverse(c) reverse(Range(c))
#define Vec2(T, n, m, xs) vector<vector<T>> xs(n, vector<T>(m))
#define Sum(a) accumulate(Range(a), 0)
#define Cusum(T, n, xs, sxs) vector<T> sxs(n+1); For(i, n) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) Vec2(T, n, m, xs); For(i, n) For(j, m) cin >> xs[i][j]
#define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) for(const auto &e : xs) cout << e << " "; cout << "\n"
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")

int main(void){
    Cin(string, s, t);
    for(int i = (int)s.size() - (int)t.size(); i >= 0; i --){
        bool f = true;
        For(j, (int)t.size()){
            if(s[i+j] != t[j] && s[i+j] != '?'){
                f = false;
                break;
            }
        }
        if(f){
            For(j, (int)s.size()) if(s[j] == '?') s[j] = 'a';
            For(j, (int)t.size()) s[i+j] = t[j];
            Cout(s);
            return 0;
        }
    }
    Cout("UNRESTORABLE");
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int H,A,hit;
    scanf("%d %d",&H,&A);
    if(H%A==0)
    {
        hit=(H/A);
        printf("%d",hit);
    }
    else
    {
        hit=(H/A)+1;
        printf("%d",hit);
    }
return 0;
}


Measured memory_bytes: 128
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.PrintStream;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Spandan
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CSumOfGcdOfTuplesEasy solver = new CSumOfGcdOfTuplesEasy();
        solver.solve(1, in, out);
        out.close();
    }

    static class CSumOfGcdOfTuplesEasy {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.readInt();
            int gcdRes = 1;
            int sum = 0;
            for (int i = 1; i <= n; i++) {
                for (int j = 1; j <= n; j++) {
                    gcdRes = gcd(i, j);
//                System.out.println("gcdRes ="+gcdRes);
                    for (int k = 1; k <= n; k++) {
                        int gcd = gcd(gcdRes, k);
                        sum += gcd;
//                    System.out.println("sum = "+sum+" i="+i +" j="+j +" k = "+k+" gcd ="+gcdRes);
                    }
                }
            }
            System.out.println(sum);
        }

        int gcd(int a, int b) {
            if (b == 0)
                return a;
            return gcd(b, a % b);
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1)
                throw new RuntimeException();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new RuntimeException();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public int readInt() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

    }
}



Measured memory_bytes: 32676
import java.util.*;
public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner reader=new Scanner(System.in);
		int A=reader.nextInt();
		String op=reader.next();
		int  B=reader.nextInt();
		if(op.equals ("+")){
			System.out.print(A+B);
		}
		else {
			System.out.print(A-B);

		}
		}
}


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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)
#define rrep(i, n) for(int i = ((int)n - 1); i >= 0; --i)

typedef long long ll;
typedef long double ld;

const ll Inf = 1e18;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
    string s, t, u;
    int a, b;
    cin >> s >> t >> a >> b >> u;
    if (s == u) --a;
    else --b;
    cout << a << " " << b << endl;
    
    return 0;
}



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

typedef long long ll;
typedef long double Double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

// chmax, chmin
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;
}

void solve(long long a, long long b, long long c, long long d) {
    cout << max({a * c, a * d, b * c, b * d}) << endl;
}

int main() {
  long long a;
  scanf("%lld", &a);
  long long b;
  scanf("%lld", &b);
  long long c;
  scanf("%lld", &c);
  long long d;
  scanf("%lld", &d);
  solve(a, b, c, d);
  return 0;
}


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

int main(){
    int n;
    cin >> n;
    vector<int> a(n),b(n),c(n);
    rep(i,n) cin >> a[i];
  	rep(i,n) cin >> b[i];
  	rep(i,n) cin >> c[i];
    int sum = 0;
    rep(i,n){
      	sum += b[a[i]-1];
        if((a[i-1]+1) == a[i]) sum += c[a[i-1]-1];
    }
    cout << sum << endl;
}


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

int main()
{
    int N;
    cin >> N;
    string s;
    cin >> s;
    int ans = 0;
    int maxx = 0;
    for (int i = 0; i < N; i++)
    {
        if(s[i] == 'I'){
            ans++;
            if(ans > maxx){
                maxx = ans;
            }
        }
        else{
            ans--;
        }
    }
    cout << maxx << endl;
}


Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include<iostream>
#include<vector>
#include<map>
#include<math.h>

#define irep(i,n) for(int i = 0; i < (int)(n); i++)
#define irep2(i,a,n) for(int i = (int)(a); i <= (int)(n); i++)
#define irrep(i,n) for(int i = (int)(n-1); i > -1; i--)
#define irrep2(i,n,a) for(int i = (int)(n); i >= (int)(a); i--)

#define fi first
#define se second

using namespace std;

using ll = long long;
using v_int = vector<int>;
using v2_int = vector<v_int>;
using v_ll = vector<ll>;
using v2_ll = vector<v_ll>;
using v_string = vector<string>;
using v_bool = vector<bool>;
using v2_bool = vector<v_bool>;
using pii = pair<int, int>;
using mii = map<int, int>;

const double PI = 3.1415926535897932;
const int INF = (int)2e9;
const ll LINF = (ll)2e18;
const ll MOD = 1000000007;
const int dc[8] = {1, -1, 0,  0, 1, -1,  1, -1};
const int dr[8] = {0,  0, 1, -1, 1,  1, -1, -1};

template<typename T, typename U> inline
ostream& operator<<(ostream &o, pair<T,U> &p) {
    return o << "{" << p.first << "," << p.second << "}";
}
template<typename T> inline
istream& operator>>(istream &is, vector<T> &vec) {
    for(auto &v : vec) { is >> v; }
    return is;
}
template<typename T> inline
ostream& operator<<(ostream &os, vector<T> &vec) {
    for(auto &v : vec) { os << v << ",";}
    return os;
}
template<typename T> inline
ostream& operator<<(ostream &os, vector<vector<T> > &mat) {
    for(auto &row : mat) { os << row << endl; }
    return os;
}
template<typename T> inline
void chmin(T &a, T b) { a = min(a, b); }
template<typename T> inline
void chmax(T &a, T b) { a = max(a, b); }

int main(void)
{
    string s, t;
    cin >> s >> t;
    
    int n = s.size();
    int m = t.size();
    int ans = INF;
    irep(i, n - m + 1) {
        //cout << s.substr(i, m) << endl;
        string u = s.substr(i,m);
        int cnt = 0;
        irep(i, m) {
            if(u[i] != t[i]) { cnt++; }    
        }
        chmin(ans, cnt);
    }
    cout << ans << endl;

    return 0;
} /*atcoder*/


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
#define P pair<int,int>
#define all(vec) vec.begin(),vec.end()
#define F first
#define S second
using namespace std;


int n,m,a[214514],b[214514];
bool s[214514],t[214514];
signed main(){
	cin>>n>>m;
	rep(i,m){
		int a,b;cin>>a>>b;
		if(a>b)swap(a,b);
		if(a==1)s[b]=1;
		if(b==n)t[a]=1;
	}
	rep(i,n){
		if(s[i]&&t[i]){
			cout<<"POSSIBLE"<<endl;
			return 0;
		}
	}
	cout<<"IMPOSSIBLE"<<endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>

using namespace std;
#define rep(i,N) for(int (i)=0;(i)<(N);(i)++)


int main() {
	int X, Y; cin >> X >> Y;
	cout << X + Y / 2 << endl;

}

Measured memory_bytes: 256
import java.util.*;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int point[] = new int[n];
		for (int i = 0; i < n; i++) {
			point[i] = sc.nextInt();
		}

		// ソート（ただし昇順になることに注意）
		Arrays.sort(point);

		// 総投票数
		int sum = 0;
		for (int i = 0; i < n; i++) {
			sum += point[i];
		}

		// 人気 m 位のアイテムの票数によって分岐
		if (point[point.length - m] * m * 4 < sum) {
			System.out.println("No");
		} else {
			System.out.println("Yes");
		}

	}

}


Measured memory_bytes: 35884
n = int(input())
l = input()
a = l.split(' ')

tmp = 0
total2 = 0

for i in range(n):
    tmp += int(a[i])

for i in range(n):
    total2 += int(a[i])*(tmp-int(a[i]))
    tmp -= int(a[i])

print(total2%1000000007)



Measured memory_bytes: 25120
from collections import deque
def solve():
    N, X, Y = map(int, input().split())
    X -= 1
    Y -= 1
    ans = [0] * N

    for start_vertex in range(N):
        q = deque()
        distance_list = [float('inf')] * N

        def push(vertex, distance):
            if distance_list[vertex] != float('inf'):
                return
            q.append(vertex)
            distance_list[vertex] = distance
        
        push(start_vertex, 0)

        while len(q) > 0:
            vertex = q.popleft()
            distance = distance_list[vertex]

            if vertex - 1 >= 0:
                push(vertex-1, distance+1)
            if vertex + 1 < N:
                push(vertex+1, distance+1)
            if vertex == X:
                push(Y, distance+1)
            if vertex == Y:
                push(X, distance+1)
        
        for i in distance_list:
            ans[i] += 1
    
    ans = list(map(lambda x: x // 2, ans))
    print(*ans[1:], sep='\n')

if __name__ == '__main__':
    solve()

Measured memory_bytes: 62812
using System;
// using System.Collections.Generic;
// using System.Linq;
// using System.Text;

class Program
{
    static void Main()
    {
        int a = int.Parse(Console.ReadLine());
        Console.WriteLine(a + Math.Pow(a, 2) + Math.Pow(a, 3));
        return;
    }
}

Measured memory_bytes: 27932
import sys
from collections import Counter
input = sys.stdin.buffer.readline

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

counter = Counter(Xs)
same_number_pairs = [0] * M #classify the number by (% M)
not_paired_numbers = [0] * M

for value, count in counter.items():
    same_number_pairs[value % M] += count // 2
    not_paired_numbers[value % M] += count % 2

sum_pairs = not_paired_numbers[0] // 2
not_paired_numbers[0] %= 2
if M % 2 == 0:
    sum_pairs += not_paired_numbers[M//2] // 2
    not_paired_numbers[M//2] %= 2
for i in range(1, (M+1)//2):
    pair = min(not_paired_numbers[i], not_paired_numbers[-i])
    sum_pairs += pair
    not_paired_numbers[i] -= pair
    not_paired_numbers[-i] -= pair

for mod, count in enumerate(not_paired_numbers):
    while same_number_pairs[(-mod)%M] >= 1 and count >= 2:
        same_number_pairs[(-mod)%M] -= 1
        count -= 2
        sum_pairs += 2

print(sum(same_number_pairs) + sum_pairs)

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

const int N=2e3+5,K=1e4+5,S=1e6+5;

bitset<K>f[N];

int n,len[N],k,l;
char s[N][K],ans[K];

namespace Z{
  int ext[K],nxt[K];
  int n,m;
  char s[K],t[K];

  inline void build(char ss[K],char tt[K],int nn,int mm){
    n=nn;m=mm;
    for(int i=0;i<n;i++)s[i]=ss[i];
    for(int i=0;i<m;i++)t[i]=tt[i];
    int mid=0;
    nxt[0]=0;
    for(int i=1;i<n;i++){
      if(nxt[mid]+mid>=i+nxt[i-mid])nxt[i]=nxt[i-mid];
      else nxt[i]=max(0,mid+nxt[mid]-i);
      while(i+nxt[i]<n&&s[nxt[i]]==s[i+nxt[i]])nxt[i]++;
      if(i+nxt[i]>mid+nxt[mid])mid=i;
    }

    mid=0;
    ext[0]=0;
    //!!! ext<= min(n,m)
    while(t[ext[0]]==s[ext[0]]&&ext[0]<min(n,m))ext[0]++;
    for(int i=1;i<m;i++){
      if(ext[mid]+mid>=i+nxt[i-mid])ext[i]=nxt[i-mid];
      else ext[i]=max(0,mid+ext[mid]-i);
      while(ext[i]<n&&i+ext[i]<m&&s[ext[i]]==t[i+ext[i]])ext[i]++;
      if(i+ext[i]>mid+ext[mid])mid=i;
    }
    nxt[0]=n;
  }

}

#define pii pair<int,bool>
#define xx first
#define yy second

bitset<K> ok,vis;

pii a[K];

int st[K],t;

inline int cmpc(char a,char b){return a<b?-1:1;}

inline int cmp(pii x,pii y){
  if(x==y)return 0;
  if(!x.yy&&!y.yy)return 0;
  if(!x.yy){
    if(x.xx<=y.xx)return 0;
    const int lcp=min(Z::ext[y.xx],x.xx-y.xx);
    if(lcp==x.xx-y.xx)return 0;
    return cmpc(Z::t[y.xx+lcp],Z::s[lcp]);
  }else{
    if(!y.yy){
      if(x.xx>=y.xx)return 0;
      int lcp=Z::ext[x.xx];
      //!!! not t[x] but ext[x]!!!
      if(lcp==Z::n)return 0;
      return cmpc(Z::s[lcp],Z::t[x.xx+lcp]);
    }
    int lcp=min(Z::ext[x.xx],min(y.xx-x.xx,Z::n));
    if(lcp==Z::n)return 0;
    if(lcp<y.xx-x.xx)return cmpc(Z::s[lcp],Z::t[x.xx+lcp]);
    lcp=min(Z::n-y.xx+x.xx,Z::nxt[y.xx-x.xx]);
    if(lcp==Z::n-y.xx+x.xx)return 0;
    return cmpc(Z::s[y.xx-x.xx+lcp],Z::s[lcp]);
  }

}

inline int cmp(int x,int y){
  return cmp(a[x],a[y]);
}

inline void ins(int id,int n){
  Z::build(s[id],ans,n,l);
  vis.reset();
  for(int j=0;j<=k;j++)if(f[id+1][k-j]){
    if(ok[j]){vis[j]=1;a[j]=pii(j,0);}
    if(j>=n&&ok[j-n]){
      if(vis[j])
        a[j]=cmp(a[j],pii(j-n,1))<=0?a[j]:pii(j-n,1);
      else vis[j]=1,a[j]=pii(j-n,1);
    }
  }

  t=0;
  for(int j=0;j<=k;j++)if(vis[j]){
    while(t&&cmp(st[t],j)>0)t--;
    if(!t||!cmp(st[t],j))st[++t]=j;
  }

  l=st[t];
  if(a[l].yy)for(int j=0;j<n;j++)ans[a[l].xx+j]=s[id][j];

  ok.reset();
  while(t)ok[st[t--]]=1;

}

int main(){
  scanf("%d%d",&n,&k);
  for(int i=1;i<=n;i++){
    scanf("%s",s[i]);
    len[i]=strlen(s[i]);
  }

  ok[0]=f[n+1][0]=1;
  for(int i=n;i;i--)f[i]=f[i+1]|f[i+1]<<len[i];

  for(int i=1;i<=n;i++)ins(i,len[i]);

  printf("%s\n",ans);

  return 0;
}


Measured memory_bytes: 21504
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define all(v) v.begin(),v.end()
#define P pair<int,int>
#define len(s) (int)s.size()
 
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;
}
constexpr int mod = 1e9+7;
constexpr long long inf = 3e18;

int N;
string S[55];
int C[55];
using pst=pair<string,bool>;
using T=pair<int,pst>;
map<pst,int>dp;
pst func(string l,string r){
	if(len(l)>len(r)){
		rep(i,len(r)){
			if(r[i]!=l[len(l)-i-1])return {"うしたぷにきあくん笑",0};
		}
		return {l.substr(0,len(l)-len(r)),0};
	}
	rev(i,len(l)){
		if(l[i]!=r[len(l)-i-1])return {"うしたぷにきあくん笑",0};
	}
	return {r.substr(len(l)),1};
}
signed main(){
	cin>>N;
	priority_queue<T,vector<T>,greater<T>>que;
	rep(i,N){
		cin>>S[i]>>C[i];
		rep(j,len(S[i])+1){
			rep(k,2){
				pst t=func(S[i].substr(0,j),(j+k<len(S[i])?S[i].substr(j+k):""));
				if(t.first!="うしたぷにきあくん笑"){
					if(dp.find(t)==dp.end()||dp[t]>C[i]){
						dp[t]=C[i];
						que.push({C[i],t});
					}
				}
			}
		}
	}
	while(!que.empty()){
		T p=que.top();que.pop();
		if(dp[p.second]<p.first)continue;
		rep(i,N){
			pst t;
			if(!p.second.second){
				t=func(p.second.first,S[i]);
			}else {
				t=func(S[i],p.second.first);
			}
			if(t.first!="うしたぷにきあくん笑"){
				if(dp.find(t)==dp.end()||dp[t]>p.first+C[i]){
					dp[t]=p.first+C[i];
					que.push({p.first+C[i],t});
				}
			}
		}
	}
	int ans=inf;
	if(dp.find({"",0})!=dp.end())ans=dp[{"",0}];
	if(dp.find({"",1})!=dp.end())ans=dp[{"",1}];
	cout<<(ans==inf?-1:ans)<<endl;
}

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

int main() {
  int H, W;
  cin >> H >> W;
  int h, w;
  h = H + 2;
  w = W + 2;
  vector<char> s(h * w);
  for(int i = 0; i < (h * w); i++){
    if(i % w == 0 || (i + 1) % w == 0 || i < w || i > ((h - 1) * w))
      continue;
    cin >> s.at(i);
  }
  for(int i = 0; i < (h * w); i++){
    if(i % w == 0 || (i + 1) % w == 0 || i < w || i > ((h - 1) * w))
      continue;
    int sum = 0;
    if(s.at(i) == '.'){
      s.at(i) = '0';
      if(s.at(i - w - 1) == '#')
        sum++;
      if(s.at(i - w) == '#')
        sum++;
      if(s.at(i - w + 1) == '#')
        sum++;
      if(s.at(i - 1) == '#')
        sum++;
      if(s.at(i + 1) == '#')
        sum++;
      if(s.at(i + w - 1) == '#')
        sum++;
      if(s.at(i + w) == '#')
        sum++;
      if(s.at(i + w + 1) == '#')
        sum++;
      if(sum == 1)
        s.at(i) = '1';
      if(sum == 2)
        s.at(i) = '2';
      if(sum == 3)
        s.at(i) = '3';
      if(sum == 4)
        s.at(i) = '4';
      if(sum == 5)
        s.at(i) = '5';
      if(sum == 6)
        s.at(i) = '6';
      if(sum == 7)
        s.at(i) = '7';
      if(sum == 8)
        s.at(i) = '8';
    }
  }
  for(int i = 0; i < (h * w); i++){
    if(i % w == 0 || (i + 1) % w == 0 || i < w || i > ((h - 1) * w))
      continue;
    cout << s.at(i);
    if((i + 2) % w == 0)
    cout << endl;
  }
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
    int H,W,s[100][100]={0},p[20000],N,i,j,m=0,n=0;
    scanf("%d %d",&H,&W);
    scanf("%d",&N);
    for(i=1;i<=N;i++)
        scanf("%d",&p[i]);
    for(i=1;i<=N;i++)
    {
        for(j=1;j<=p[i];j++)
        {
            if(n<W-1&&n>=0&&s[m][n+1]==0) {s[m][n]=i;n++;}
            else if(n==W-1&&s[m][n-1]!=0) {s[m][n]=i;m++;}
            else if(n<=W-1&&n>0&&s[m][n-1]==0) {s[m][n]=i;n--;}
            else if(n==0&&s[m][n+1]!=0) {s[m][n]=i;m++;}
            else if(W==1) {s[m][n]=i;m++;}
        }
    }
    for(m=0;m<H;m++)
    {
        for(n=0;n<W;n++)
            if(n==W-1) printf("%d\n",s[m][n]);
            else printf("%d ",s[m][n]);
    }
    return 0;

}

Measured memory_bytes: 256
s=input()
a=int(s[0]+s[1]+s[2]+s[3])
b=int(s[5]+s[6])
c=int(s[8]+s[9])
if a>2019:
    print("TBD")
elif a==2019 and b>=5:
    print("TBD")
else:
    print("Heisei")


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

int main()
{
  int n;
  int flag = 1;
  int i;
  int tmp;
  int count = 0;
  
  scanf("%d",&n);

  if(n < 1 || 100 < n)
    exit(0);
  
  int a[n];

  for(i = 0; i<n; i++){
    scanf("%d",&a[i]);
    if(a[i] < 0 || 100 < a[i])
      exit(1);
  }

  while(flag){
    flag = 0;
    for(i = n-1; i>0; i--){
      if(a[i] < a[i-1]){
	tmp = a[i];
	a[i] = a[i-1];
	a[i-1] = tmp;
	flag = 1;
	count++;
      }
    }
  }
  
  for(i=0; i<n-1; i++){
    printf("%d ",a[i]);
  }
  
  printf("%d\n%d\n",a[i],count);
  return 0;
}

  



Measured memory_bytes: 2712
import java.util.Scanner;

class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    String n = scanner.nextLine();
    String[] h = scanner.nextLine().split(" ");
    
    int total = 1;
    int max = Integer.parseInt(h[0]);
    for (int i = 1; i < Integer.parseInt(n); i++) {
      if (max <= Integer.parseInt(h[i])) {
        max = Integer.parseInt(h[i]);
        total++;
      }
    }
    System.out.println(total);
  }
}

Measured memory_bytes: 21844
#include <iostream>

using std::cin;
using std::cout;
using std::endl;

int main(void){
	int n,p;
	int a[51];

	cin >> n; 
	cin >> p; 

	while (n != 0 || p != 0) {
		int fin = 0;
		int winner = 0;

		for (int i = 0; i < 51; i++) {
			if (i == 50) {
				a[i] = p;
			}else{
				a[i] = 0;
			}
		}
		while (!fin) {
			for (int i = 0; i < n && !fin; i++) {
				if (a[50] != 0) {
					a[i] += 1;
					a[50] -= 1;
				}else{
					a[50] += a[i];
					a[i] = 0;
					if (a[50] == p) {
						fin = 1;
						winner = i;
					}
				}
			}
		}
		cout << winner << endl;
		fin = 0;
		
		cin >> n;
		cin >> p;
	}

	return 0;
}

Measured memory_bytes: 3024
#include<iostream>
using namespace std;
int main(){
	int x1,y1,x2,y2;
	cin>>x1>>y1>>x2>>y2;
	int a = x2-x1;
	int b = y2-y1;
	cout<<x2 - b<<" "<<y2 + a <<" "<<x1 - b<<" "<<y1 + a;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define range(i,a,n) for(int i=(a);i<(n);i++)

#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};

template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S acm(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
void YN(bool b){cout<<(b?"YES":"NO")<<"\n";}
void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";}
void yn(bool b){cout<<(b?"yes":"no")<<"\n";}

ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll x,y,z,k;
	cin>>x>>y>>z>>k;
	vl a(x),b(y),c(z);
	rep(i,x)cin>>a[i];
	rep(i,y)cin>>b[i];
	rep(i,z)cin>>c[i];
	vl ab,abc;
	rep(i,x)rep(j,y)ab.push_back(a[i]+b[j]);
	sort(all(ab),greater<ll>());
	rep(i,min(k,x*y))rep(j,z)abc.push_back(ab[i]+c[j]);
	sort(all(abc),greater<ll>());
	rep(i,k)cout<<abc[i]<<endl;
}


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

using namespace std;
using llong = long long;
using ldbl = long double;
using P = pair<llong, llong>;

#define BE(x) x.begin(), x.end()

const llong inf = llong(1e18)+7;
const llong mod = 1e9+7;

int main(){
	llong H, W;
	cin >> H >> W;
	llong ans = min((H%3>0)*W, (W%3>0)*H);
	for(int i = 1; i < H; i++){
		vector<llong> S(3);
		S[0] = W*i;
		S[1] = (H-i)*(W/2);
		S[2] = (H-i)*(W/2 + (W&1));
		sort(BE(S));
		ans = min(ans, S[2] - S[0]);
	}
	for(int i = 1; i < W; i++){
		vector<llong> S(3);
		S[0] = H*i;
		S[1] = (W-i)*(H/2);
		S[2] = (W-i)*(H/2 + (H&1));
		sort(BE(S));
		ans = min(ans, S[2] - S[0]);
	}
	cout << ans << endl;


	return 0;
}

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

int main()
{
    int n;
    int a,b,c,d;
    cin>>n;
    int floor[4][3][10];
    for(int i=0;i<4;i++){
        for(int s=0;s<3;s++){
            for(int t=0;t<10;t++){
                floor[i][s][t]=0;
            }
        }
    }

    for(int i=0; i<n; i++) {
        cin>>a>>b>>c>>d;
        floor[a-1][b-1][c-1]+=d;
    }
    for(int i=0;i<4;i++){
        for(int s=0;s<3;s++){
            for(int t=0;t<10;t++){
                cout<<" "<<floor[i][s][t];
            }
            cout<<endl;
        }
        if(i!=3)
        cout<<"####################"<<endl;
    }
}

Measured memory_bytes: 3092
import sys
 
stdin = sys.stdin
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()

s = input()
ans1 = 0
ans = 0
for a in s:
    if a == "A":
        # print("T")
        ans+=1
    elif a == "T":
        # print("A")
        ans += 1

    elif a == "C":
        ans += 1
    elif a == "G":
        ans+=1
    else:
        ans = 0
    if ans > ans1:
        ans1 = ans
print(ans1)

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

typedef long long ll;
ll INF = 1LL << 60;
ll MAX = 100010;


int
main() 
{
  ll n;
  cin >> n;
  ll min = INF;
  rep(i, 0, 5){
    ll tmp; cin >> tmp;  
    if(min > tmp) min = tmp;
  }

  if(n <= min){
    cout << 5 << endl;
  } else if(n % min == 0){
    cout << 4 + (n / min) << endl;
  } else {
    cout << 5 + (n / min) << endl;
  }

}



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

using namespace std;
#define ll long long
const int N = 1e6 + 1, MOD = 998244353;
int cnt[N], S[N], _S[N];
vector <int> Div[N];

int sum(int a, int b) {return a + b - (a + b >= MOD ? MOD : 0);}
int mul(ll a, ll b) {return a * b % MOD;}

int main() {
    for (int i = N - 1; i >= 1; i--) for (int j = i; j < N; j += i) Div[j].push_back(i);
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int n; cin >> n;
    for (int i = 0, x; i < n; i++) cin >> x, cnt[x]++;
    int ans = 0;
    for (int i = 1; i < N; i++) if (cnt[i]) {
        ans = sum(ans, mul(i, 1ll * cnt[i] * (cnt[i] - 1) / 2));
        int res = 0;
        for (int d : Div[i]) _S[d] = S[d];
        for (int d : Div[i]) {
            res = sum(res, mul(S[d], i / d));
            for (int _d : Div[d]) if (_d != d) S[_d] = sum(S[_d], MOD - S[d]);
        }
        ans = sum(ans, mul(res, cnt[i]));
        for (int d : Div[i]) S[d] = sum(_S[d], mul(i, cnt[i]));
    }
    cout << ans << "\n";

    return 0;
}


Measured memory_bytes: 128716
import java.awt.geom.Line2D;
import java.awt.geom.Point2D;
import java.util.*;

public class Main {
	
	private void doit(){
		Scanner sc = new Scanner(System.in);
		while(true){
			int n = sc.nextInt();
			if(n== 0) break;
			int [] xlist = new int[n];
			int [] ylist = new int[n];
			boolean [] visited = new boolean[n];
			for(int i=0; i < n; i++){
				xlist[i] = sc.nextInt();
				ylist[i] = sc.nextInt();
			}
			int nowx = 0, nowy = 0;
			double dis = 0, nowdeg = 0.0;
			for(int i=0; i < n; i++){
				double degmin = 720.0;
				int ind = -1;
				for(int j = 0; j < n; j++){
					if(! visited[j]){
						if(! isinLine(nowx, nowy, xlist[j], ylist[j], xlist,ylist)){
							//calc deg
							double res = getDeg(nowx, nowy, xlist[j], ylist[j]);
							//System.out.println("j=" + j +" degmin= " + degmin + " " + res + "ind= " + ind);
							if(res < nowdeg){
								res+= 360;
							}
							if(degmin > res){
								degmin = res;
								ind = j;
							}
						}
						else{
							//System.out.println("intersect!");
						}
					}
				}
				visited[ind] = true;
				dis += Point2D.Double.distance(nowx, nowy, xlist[ind], ylist[ind]);
				nowx = xlist[ind];
				nowy = ylist[ind];
				nowdeg =degmin % 360;
				//System.out.printf("ind= %d nowdeg= %.3f degmin= %.3f \n",ind+1, nowdeg, degmin);
				//System.out.println(dis + " " + (ind + 1) );
			}
			System.out.printf("%1.1f\n",dis);
			//debug
//			System.out.println("debug=");
//			Line2D.Double line =new Line2D.Double(0,0,20,0);
//			int temp = line.relativeCCW(10, 0);
//			System.out.println(temp);
		}
	}

	private boolean isinLine(int nowx, int nowy, int nextx, int nexty, int[] xlist,int[] ylist) {
		Line2D.Double line =new Line2D.Double(nowx,nowy,nextx,nexty);
		for(int i=0; i < xlist.length; i++){
			if((nowx == xlist[i] && nowy == ylist[i]) || (nextx == xlist[i] && nexty == ylist[i]) ) continue;
			if(line.relativeCCW(xlist[i],ylist[i]) == 0){
				return true;
			}
		}
		return false;
	}

	private double getDeg(int nowx, int nowy, int nextx, int nexty) {
		double dis = Point2D.Double.distance(nowx, nowy, nextx, nexty);
		double sin = (double)(nextx - nowx) / dis;
		double asin = Math.asin(sin);
		double deg = Math.toDegrees(asin);
		double degRevision = revision(nowx,nowy,nextx,nexty,deg);
		return degRevision;
	}
	
	private double revision(int nowx, int nowy, int nextx, int nexty,double deg){
		if(nowx <= nextx && nowy <= nexty){
			return deg;
		}
		if(nowx <= nextx && nowy >= nexty){
			return ((double)180 - deg);
		}
		if(nowx >= nextx && nowy <= nexty){
			return ((double)360+deg);
		}
		if(nowx >= nextx && nowy >= nexty){
			return ((double)180-deg);
		}
		else{
			return deg;
		}
	}

	public static void main(String[] args) {
		Main obj = new Main();
		obj.doit();
	}
}

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

#define REP(type, i, a, b) for( type i = a; i < b; i++ )
typedef long long ll;

using namespace std;

int main (void) {
    ll N, ans;
    ans = 0;
    scanf("%lld",&N);
    ll b[N-1];
    REP(int,i,0,N-1) scanf("%lld", &b[i]);
    ans += b[N-2];
    ans += b[0];
    for ( int i = N - 2; i > 0; i-- ){
        ans += min( b[i], b[i-1]);
    }
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 256