akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
typedef long long ll;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REP2(i, a, b) for(int i = a;i <= b;i++)
#define REPR(i, a, b) for(int i = a; i >= b; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 9223372036854775807
#define MOD 1000000007
#define PI 3.14159265358979323846
#define vi vector<int>
#define vll vector<ll>
#define vi2 vector<vector<int>>
#define eb emplace_back
#define fi first
#define se second
#define ALL(v) v.begin(), v.end()
#define sz(x) int(x.size())
using namespace std;
using P = pair<ll,ll>;
const int dx[]{0, 1, 0, -1, -1, -1, 1, 1}, dy[]{1, 0, -1, 0, -1, 1, -1, 1};
#define INT(name) int name;cin >> name;
#define VEC(type,name,n) vector<type> name(n);REP(i,n) cin >> name[i];

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()
{
  INT(N);
  INT(K);
  vector<P> A(N);
  REP(i,N) cin >> A[i].first >> A[i].second;
  
  ll MIN=INF;
  REP(i,N-1){
    REP2(j,i+1,N-1){
      REP(k,N-1){
        REP2(l,k+1,N-1){
          ll R=max(A[j].fi,A[i].fi);
          ll L=min(A[j].fi,A[i].fi);
          ll U=max(A[l].se,A[k].se);
          ll D=min(A[l].se,A[k].se);
          int cnt=0;
          REP(m,N){
            if(A[m].fi>=L&&A[m].fi<=R&&A[m].se<=U&&A[m].se>=D){
              cnt++;
            }
          }
          if(cnt>=K){
            MIN=min(MIN,(R-L)*(U-D));
            // cout << "R" << R << "L" << L << "U" << U << "D" << D << endl;
          }
        }
      }
    }
  }

  cout << MIN << endl;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define rep(a,n) for (ll a = 0; a < (n); ++a)
using namespace std;
using ll = long long;
typedef pair<ll,ll> P;
typedef pair<P,ll> PP;
//typedef vector<vector<ll> > Graph;
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; }
const ll INF = 1e9;

/*二次元累積和
    add(x,y,z)=(x,y)に値zを加える
    build()=累積和を構築する
    query(sx,sy,gx,gy)=左下が(sx,sy),右上が(gx,gy)の矩形和を求める
    (半開区間であり列gxと行gyは含まないこと)
*/

template<typename T>
struct  CumulativeSum2D{
    vector<vector< T > >data;

    CumulativeSum2D(int w,int h):data(w+1,vector< T >(h+1,0)){}

    void add(int x,int y,T z){
        ++x;++y;
        if(x >= data.size() || y >= data[0].size())return;
        data[x][y] += z;
    }

    void build(){
        for(int i=1;i<data.size();i++){
            for(int j=1;j<data[i].size();j++){
                data[i][j] += data[i][j-1] + data[i-1][j] - data[i-1][j-1];
            }
        }
    }

    T query(int sx, int sy, int gx, int gy){
        return data[gx][gy]-data[sx][gy]-data[gx][sy]+data[sx][sy];
    }
};

int main(){
    ll n,k;
    cin >> n >> k;
    ll k2 = k*2;
    CumulativeSum2D<ll>black(k2,k2),white(k2,k2);
    rep(i,n){
        ll x,y;
        char c;
        cin >> x >> y >> c;
        if(c=='B'){
            black.add(x%k2,y%k2,1);
        }
        else{
            white.add(x%k2,y%k2,1);
        }
    }
    black.build();
    white.build();
    ll ans = 0;
    rep(i,k){
        rep(j,k){
            //Case1
            ll now = 0;
            //left
            now += black.query(0,0,i,j);
            now += white.query(i,0,i+k,j);
            now += black.query(i+k,0,k2,j);
            //middle
            now += white.query(0,j,i,j+k);
            now += black.query(i,j,i+k,j+k);
            now += white.query(i+k,j,k2,j+k);
            //right
            now += black.query(0,j+k,i,k2);
            now += white.query(i,j+k,i+k,k2);
            now += black.query(i+k,j+k,k2,k2);
            chmax(ans,now);

            //Case2
            now = 0;
            //left
            now += white.query(0,0,i,j);
            now += black.query(i,0,i+k,j);
            now += white.query(i+k,0,k2,j);
            //middle
            now += black.query(0,j,i,j+k);
            now += white.query(i,j,i+k,j+k);
            now += black.query(i+k,j,k2,j+k);
            //right
            now += white.query(0,j+k,i,k2);
            now += black.query(i,j+k,i+k,k2);
            now += white.query(i+k,j+k,k2,k2);
            chmax(ans,now);
        }
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 66004
import java.io.FileNotFoundException;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws FileNotFoundException {

        Scanner in = new Scanner(System.in);
//        Scanner in = new Scanner(new File("input.txt"));

        long a = in.nextLong();


        BigDecimal b = new BigDecimal(String.valueOf(in.nextDouble()));
        b = b.multiply(new BigDecimal(String.valueOf(a)));

        String s = b.toString();
        System.out.println(s.substring(0, s.indexOf(".")));
    }
}


Measured memory_bytes: 37848
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int MAX_N=100005;
int n,W;
int w[MAX_N],v[MAX_N];
LL dp[105][MAX_N];
int main()
{
	cin>>n>>W;
	for(int i=1;i<=n;i++)cin>>w[i]>>v[i];
	for(int i=1;i<=n;i++)
	{
		for(int j=0;j<=W;j++)
		{
			if(j>=w[i])dp[i][j]=max(dp[i][j],dp[i-1][j-w[i]]+v[i]);
			dp[i][j]=max(dp[i][j],dp[i-1][j]);
		}
	}
	LL ans=0;
	for(int i=0;i<=W;i++)
	{
		ans=max(ans,dp[n][i]);
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 79360
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
#define all(x) (x).begin(),(x).end()
#define rep(i,m,n) for(int i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(int i = m;i >= n;--i)
#define INF INT_MAX/2
using namespace std;
using ll = long long;
using R = double;
using Data = pair<ll, vector<int>>;
const ll MOD = 1e9 + 7;
const ll inf = 1LL << 50;
struct edge { ll from; ll to; ll cost; };
typedef tuple<ll, ll, ll>T;
typedef pair<ll, ll>pll;

int main(){
	ll n;
	cin >> n;
	vector<ll>a(n);
	vector<ll>sum(n+1);
	rep(i, 0, n)cin >> a[i];
	rep(i, 0, n)sum[i + 1] = sum[i] + a[i];
	map<ll, ll>mp;
	rep(i, 0, n+1)mp[sum[i]]++;

	ll ans = 0;
	fore(x, mp)ans += x.second*(x.second - 1) / 2;
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 15872
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()

from itertools import groupby
def resolve():
    S=input()
    X=[]; Y=[]
    dir=0
    for key,iter in groupby(S):
        h=len(list(iter))
        if(key=='T'): dir^=(h&1)
        else:
            if(dir&1==0): X.append(h)
            else: Y.append(h)

    # 最初が移動のときだけは自由度が無いため例外処理
    tx,ty=map(int,input().split())
    if(S[0]=='F'):
        tx-=X[0]
        del X[0]

    # あとはx,y独立に移動できるので、tx、tyが到達可能かを判定
    M=8100*2
    dpx=[0]*M; dpx[0]=1
    dpy=[0]*M; dpy[0]=1

    for x in X:
        ndpx=[0]*M
        for i in range(M):
            if(dpx[i]==0): continue
            ndpx[(i+x)%M]=1
            ndpx[(i-x)%M]=1
        dpx=ndpx

    for y in Y:
        ndpy=[0]*M
        for i in range(M):
            if(dpy[i]==0): continue
            ndpy[(i+y)%M]=1
            ndpy[(i-y)%M]=1
        dpy=ndpy

    print("Yes" if(dpx[tx%M] and dpy[ty%M]) else "No")
resolve()

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

int main(){

    int n; cin >> n;
    vector<int> s(n);
    vector<int> l(n);
    vector<int> p(n);
    for(int i = 0; i < n; i++){
        cin >> s[i] >> l[i] >> p[i];
    }

    int m; cin >> m;
    vector<int> w(m);
    for(int i = 0; i < m; i++){
        cin >> w[i];
    }

    vector<int> v(400, 0);

    for(int i = 0; i < n; i++){
        for(int j = s[i]; j <= l[i]; j++){
            v[j] = max(v[j], p[i]);
        }
    }

    int dp[410][410] = {};
    
    dp[0][0] = 0;

    for(int i = 0; i < 400; i++){
        for(int j = 0; j < 400; j++){
            if(j < i){
                dp[i + 1][j] = dp[i][j];
            }else{
                dp[i + 1][j] = max(dp[i][j], dp[i + 1][j - i] + v[i]);
            }
        }
    }

    vector<int> ans;
    for(int i = 0; i < m; i++){
        if(dp[399][w[i]] == 0){
            cout << -1 << endl;
            return 0;
        }

        ans.push_back(dp[399][w[i]]);
    }

    for(int i = 0; i < m; i++){
        cout << ans[i] << endl;
    }

    return 0;
}


Measured memory_bytes: 3816
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <cctype>
#include <stack>
#include <queue>
#include <vector>
#include <cstdlib>

using namespace std;

int main() {

	stack<int> B, C;
	int n,ball;

	cin >> n;

	for(int j=0;j<n;j++){
		for (int i = 0; i < 10; i++) {
			cin >> ball;

			if (i == 0)
				B.push(ball);

			else if (B.top() > ball)

				if (C.empty())
					C.push(ball);

				else if (C.top() < ball)
					C.push(ball);

				else {
					cout << "NO" << endl;
					break;
				}

			else {
				if (B.top() < ball)
					B.push(ball);
				else {
					cout << "NO" << endl;
					break;
				}
			}

			if (i == 9)
				cout << "YES" << endl;
		}
		while (1) {
			B.pop();
			if (B.empty())
				break;
		}
		while (1) {
			C.pop();
			if (C.empty())
				break;
		}
	}

	return 0;
}

Measured memory_bytes: 1192
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

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

int main(){
    int const INF = 100000000;
    int n, ma, mb;
    cin >> n >> ma >> mb;
    int a[n], b[n], c[n];
    rep(i, n) cin >> a[i] >> b[i] >> c[i];
    int dp[n+1][401][401];
    rep(i, n + 1)rep(j, 401)rep(k, 401) dp[i][j][k] = INF;
    rep(i, n + 1) dp[i][0][0] = 0;

    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= 400; j++){
            for(int k = 1; k <= 400; k++){
                if(j >= a[i-1] && k >= b[i-1]){
                    dp[i][j][k] = min(dp[i-1][j][k], dp[i-1][j-a[i-1]][k-b[i-1]] + c[i-1]);
                }else{
                    dp[i][j][k] = dp[i-1][j][k];
                }
            }
        }
    }
    int ans = INF;
    for(int i = 1; i * ma <= 400 && i * mb <= 400; i++){
        ans = min(ans, dp[n][i*ma][i*mb]);
    }
    // rep(i, 6){
    //     rep(j, 6){
    //         cout << dp[n][i][j] << " ";
    //     }
    //     cout << endl;
    // }
    if(ans == INF){
        cout << -1 << endl;
    }else{
        cout << ans << endl;
    }
}

Measured memory_bytes: 25984
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define maxn 100005
using namespace std;
typedef long long ll;
struct data{
	int num,val;
}a[maxn];
bool cmp(const data &x,const data &y){
	return x.num < y.num;
}
bool cmp2(const data &x,const data &y){
	return x.val < y.val;
}
int n;
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&a[i].num);
	sort(a+1,a+n+1,cmp);
	printf("%d ",a[n].num);
	for(int i=1;i<n;i++) a[i].val = min(a[i].num,a[n].num - a[i].num);
	sort(a+1,a+n,cmp2);
	printf("%d\n",a[n-1].num);
	return 0;
}


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

int dp[3001][3001];
/// dp[i][j] 考慮 S 的前 i 個字元和 T 的前 j 個字元的 LCS 長度

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

    string s, t;
    cin >> s >> t;

    for (int i = 1; i <= s.size(); i++)
        for (int j = 1; j <= t.size(); j++)
            if (s[i - 1] == t[j - 1])
                dp[i][j] = dp[i - 1][j - 1] + 1;
            else
                dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);

    int n = s.size(), m = t.size(), tmp = dp[n][m];
    string ans;
    while (tmp)
    {
        while (dp[n - 1][m] == tmp)
            n--;
        while (dp[n][m - 1] == tmp)
            m--;
        ans += s[n - 1];
        tmp--, n--, m--;
    }
    reverse(ans.begin(), ans.end());
    cout << ans << '\n';

    return 0;
}


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

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = ReadArrayInt();
            var X = input[0];
            var Y = input[1];
            var Z = input[2];
            var K = input[3];
            var A = ReadArrayLong();
            var B = ReadArrayLong();
            var C = ReadArrayLong();
            var AB = new List<long>();
            for (int i = 0; i < X; i++)
            {
                var max = false;
                for (int j = 0; j < Y; j++)
                {
                    AB.Add(A[i] + B[j]);
                }
            }
            AB.Sort();
            AB.Reverse();
            var ans = new List<long>();
            Array.Sort(C);
            Array.Reverse(C);
            for (int i = 0; i < Math.Min(AB.Count(), K); i++)
            {
                for (int j = 0; j < Z; j++)
                {
                    ans.Add(AB[i] + C[j]);
                }
            }
            ans.Sort();
            ans.Reverse();
            for (int i = 0; i < K; i++)
            {
                Console.WriteLine(ans[i]);
            }

            Console.WriteLine();
            Console.ReadLine();
        }

        static string Read() { return Console.ReadLine(); }
        static int ReadInt() { return int.Parse(Read()); }
        static long ReadLong() { return long.Parse(Read()); }
        static int[] ReadArrayInt() { return Read().Split(' ').Select(s => int.Parse(s)).ToArray(); }
        static long[] ReadArrayLong() { return Read().Split(' ').Select(s => long.Parse(s)).ToArray(); }
    }
}

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

int main()
{
	int a, b;
	cin >> a >> b;
	int ans;
	if (a <= 5)
		ans = 0;
	else if (6 <= a && a <= 12)
		ans = b / 2;
	else
		ans = b;
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstring>
#include <sstream>
#include <map>
#include <queue>
#include <vector>
#include <deque>
#include <climits>
#define scanf scanf_s
#define mk make_pair
#define pb push_back
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> pos;
const ll MOD = 1000000007, N = 100010;

ll min2(ll v1, ll v2) { if (v1 == -1)return v2; if (v2 == -1)return v1; return min(v1, v2); }
ll pw(ll v1, ll v2, ll mod = 1000000007) {
	ll v3 = 1;
	for (; v2 != 0; v1 = (v1 * v1) % mod, v2 = (v2 >> 1))
		if (v2 & 1)v3 = (v3 * v1) % mod;
	return v3;
}

ll fc[N], rv[N], n,t1,t2;
int v1[N];
void ip() {
	memset(v1, -1, sizeof(v1));
	for (int i = 0; i <= n; i++) {
		int v2; cin >> v2;
		if (v1[v2] != -1) {
			t1 = v1[v2]; t2 = i;
		}
		else v1[v2] = i;
	}
}

ll cmb(ll v1, ll v2) { if (v1 < v2)return 0; ll v3 = (fc[v1] * rv[v2]) % MOD; v3 = (v3 * rv[v1 - v2]) % MOD; return v3; }

int main() {
	fc[0] = rv[0] = 1;
	for (int i = 1; i < N; i++) { fc[i] = (fc[i - 1] * i) % MOD; rv[i] = pw(fc[i], MOD - 2); }
	cin >> n;
	ip();
	for (int i = 1; i <= n; i++) {
		ll v1 = cmb(n, i), v2 = cmb(n, i - 1), v3 = cmb(t1 + n - t2, i - 1);
		v1 = (v1 + v2) % MOD; v1 = (v1 - v3 + MOD) % MOD;
		cout << v1 << endl;
	}
	cout << 1 << endl;
	return 0;
}



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

using namespace std;
using ll = long long;

#define rep(i, a) for (int (i) = 0; (i) < (int) (a); (i)++)
#define reps(i, a, b) for (int (i) = (int) (a); (i) < (int) (b); (i)++)
#define rrep(i, a) for (int (i) = (int) a-1; (i) >= 0; (i)--)
#define rreps(i, a, b) for (int (i) = (int) (a)-1; (i) >= (int) (b); (i)--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
#define PRINT(f) if((f)){cout << (TRUE__) << endl;}else{cout << FALSE__ << endl;}
#define TRUE__ "Yes"
#define FALSE__ "No"
#define PERM(v) next_permutation(all(v))
#define UNIQUE(v) sort(all(v));(v).erase(unique(all(v)), v.end())
#define CIN(type, x) type x;cin >> x

#ifdef LOCAL
	#define lcout(a) cout << a;
	#define lcoutln(a) cout << a << endl;
	#define lcerr(a) cerr << a;
	#define lcerrln(a) cerr << a << endl;
#else
	#define lcout(a) 
	#define lcoutln(a) 
	#define lcerr(a) 
	#define lcerrln(a) 
#endif

#define INF 1e9;

int ch[1000001];

int culc(int pos, int r)
{
	if (r < 10) return 0;
	if (ch[r] == pos) return -INF;
	ch[r] = pos;
	int ma = 0;
	for (int i = 10; r / i > 0; i *= 10) {
		ma = max((r / i) * (r % i), ma);
	}
	return culc(pos, ma) + 1;
}

int main()
{
	CIN(int, q);
	reps(i, 1, q+1) {
		CIN(int, r);
		cout << max(culc(i, r), -1) << endl;
	}
}



Measured memory_bytes: 4880
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  int X;
  for (int i = 0; i < N; i++) {
    int l;
    cin >> l;
    int r;
    cin >> r;
    X = X + r - l + 1;
  }
  cout << X << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <cmath>
#define rep(i, N) for(int (i) = 0; (i) < (N); (i) ++)
typedef long long ll;
using namespace std;

vector<bool> visited(8, false);
vector<vector<int>> edges;

int main(){
    ll N;
    cin >> N;
    int sqrN = sqrt(N);

    for(int i = sqrN; i >= 1; i --){
        if(N % i == 0){
            ll big = N / i;
            int ans = 0;
            while(big >= 1){
                big /= 10;
                ans ++;
            }
            cout << ans << endl;
            return 0;
        }
    }

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <list>
#include <algorithm>
#include <set>
#include <queue>

using namespace std;
#define ll long long

int main()
{
    //freopen("aa_input.txt", "r", stdin);
    int n, l;
    cin>>n>>l;
    int curr, min = 100000, ans = 1;
    for(int i=1; i<=n; i++){
        curr = l+i-1;
        if(curr<=0){
            min = curr;
            ans = i;
        }
        else if(curr<min){
            min = curr;
            ans = i;
        }
    }
    int sum = 0;
    for(int i=1; i<=n; i++){
        curr = l+i-1;
        if(ans != i){
            sum += curr;
        }
    }
    cout<<sum<<endl;
    return 0;
}
/*

riaadmorshed@gmail.com

*/

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

#define itn int
#define all(x) (x).begin(), (x).end()
#define make_unique(x) sort(all((x))); (x).resize(unique(all((x))) - (x).begin())

#define random_shuffle(...) shuffle(__VA_ARGS__, rng)
#define rand() rng()

using namespace std;

inline int nxt() {
	int x;
	scanf("%d", &x);
	return x;
}

vector<int> solve(int n, int a, int b) {
	if (n == 1) {
		return {a, b};
	}
	assert(__builtin_parity(a) != __builtin_parity(b));
	int bit = 1 << (n - 1);
	if ((a & bit) != (b & bit)) {
		auto res1 = solve(n - 1, a, a ^ 1);
		auto res2 = solve(n - 1, (a ^ 1) ^ bit, b);
		res1.insert(res1.end(), all(res2));
		return res1;
	} else {
		auto res1 = solve(n - 1, a, b);
		auto res2 = solve(n - 1, a ^ bit, res1[1] ^ bit);
		res1.insert(res1.begin() + 1, all(res2));
		return res1;
	}
}

int main() {
	mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

	int n = nxt(), a = nxt(), b = nxt();
	if (__builtin_parity(a) == __builtin_parity(b)) {
		cout << "NO\n";
		return 0;
	}

	printf("YES\n");
	auto res = solve(n, a, b);
	for (int x : res) {
		printf("%d ", x);
	}
	printf("\n");

	return 0;
}

Measured memory_bytes: 1648
use proconio::{input, fastout};

#[fastout]
fn main() {
    input! {
        n: usize,
        a: [usize; n],
        q: usize,
        bc: [(usize, usize); q]
    }

    let mut mp = vec![0; 100001];
    let mut sum = 0;
    for i in a {
        sum += i;
        mp[i] += 1;
    }

    for (b, c) in bc {
        let tmp = mp[b];
        sum = sum - b * tmp + c * tmp;
        println!("{}", sum);
        mp[b] = 0;
        mp[c] += tmp;
    }

}


Measured memory_bytes: 6848
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rep3(i, l, n) for (int i = l; i < n; ++i)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define out(a) cout << a << endl
#define outa(a, n) rep(_, n) cout << a[_] << " "; cout << endl
#define SZ(v) (int)v.size()
#define inf (int)(1e9+7)

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    int c = 0;
    rep(i, n) {
        int a;
        cin >> a;
        while (a % 2 == 0) { a /= 2; c++; }
    }
    out(c);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll      	long long int
#define PI      	acos(-1)
#define read    	freopen("in.txt","r",stdin)
#define uu      	first
#define vv      	second
#define write   	freopen("out.txt","w",stdout)
#define pii     	pair<int,int>
#define pll         pair<ll,ll>
#define INF     	1e9
#define EPS     	1e-8
#define MAX     	1000006
#define MOD     	1000000007
#define fastRead 	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
int n , m  , ara[2000][2000];
string str;
ll dp[2000][2000];

ll solve(int x , int y) {

    if( ara[x][y] == -1) return 0;
    if( x == 0 && y ==0) return 1;

    ll &ret = dp[x][y];
    if( ret != - 1) return ret;

    ret = 0;

    if( x==0 ) ret  = solve(x , y-1);
    else if( y== 0 ) ret = solve(x-1 , y);
    else {

        ret = (solve(x-1 , y)%MOD + solve(x ,y-1) %MOD )%MOD;
    }
    return ret;
}

int main()
{
    fastRead;
    cin>>n>>m;
    for(int i =0 ; i  <n ; i++ ) {
        cin>>str;
        for(int j =0 ; j < m ; j++ ) {
            if( str[j] == '#') ara[i][j] = -1;
        }
    }
    memset(dp , -1 , sizeof dp);
    cout<<solve(n-1 , m-1)<<endl;
    return 0;
}


Measured memory_bytes: 41344
import sys
input=sys.stdin.readline
sys.setrecursionlimit(100000000)
MOD = 10**9+7
INF = 10 ** 20
from functools  import lru_cache

MAXN = 405
a = [0] * MAXN
dp = [[-1] * MAXN for _ in range(MAXN)]
def dfs(l,r):
    if dp[l][r] != -1:
        return dp[l][r]
    if r - l == 1:
        dp[l][r] = 0
        return 0
    ans = INF
    for i in range(l + 1,r):
        ans = min(ans,dfs(l,i) + dfs(i,r)) 
    if l == 0:
        ans += a[r - 1]
    else:
        ans += a[r - 1] - a[l - 1]
    dp[l][r] = ans
    return ans

def main():
    n = int(input())
    b = list(map(int,input().split()))
    a[:n] = b

    for i in range(1,n):
        a[i] += a[i - 1]
    
    ans = dfs(0,n)
    print(ans)
if __name__=='__main__':
    main()

Measured memory_bytes: 43356
#include <algorithm>
#include <bitset>
#include <boost/dynamic_bitset.hpp>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <typeindex>
#include <typeinfo>
#include <vector>

#define DEBUG(x) cout << #x << ": " << x << endl
#define INFILE() freopen("input.txt", "r", stdin)

using namespace std;

using ll = long long;
using ull = unsigned long long;
using i_i = pair<int, int>;
using ll_i = pair<ll, int>;
using i_ll = pair<int, ll>;
using d_i = pair<double, int>;
using ll_ll = pair<ll, ll>;
using d_d = pair<double, double>;

static constexpr ll LL_MOD = 1000000007;
static constexpr int I_MOD = 1000000007;
static constexpr double EPS = numeric_limits<double>::epsilon();
static constexpr double PI = 3.14159265358979323846264338327950288;

template <class T> static void scan(vector<T> &v);
static void scan(vector<string> &v, bool isWord = true);
static boost::dynamic_bitset<> scan(char trueValue = 'o');

int main(int argc, char *argv[]) {
	// INFILE();
  int n, m;
  cin >> n >> m;
  vector<ll> ns(n);
  vector<ll> ms(m);
  scan(ns);
  scan(ms);

	ll totalX = 0, totalY = 0;

	for (int i = 0; i < n; i++) {
		totalX += i * ns[i];
		totalX -= (n - i - 1) * ns[i];
		totalX %= LL_MOD;
	}

	for (int i = 0; i < m; i++) {
		totalY += i * ms[i];
		totalY -= (m - i - 1) * ms[i];
		totalY %= LL_MOD;
	}


	cout << (totalX * totalY) % LL_MOD << "\n";
  return 0;
}

template <class T> static void scan(vector<T> &v) {
  map<type_index, const char *const> m = {{typeid(int), "%d"},
                                          {typeid(ll), "%lld"},
                                          {typeid(double), "%lf"},
                                          {typeid(char), "%c"}};

  auto tFormat = m[typeid(T)];

  for (T &n : v) {
    scanf(tFormat, &n);
  }
}

static void scan(vector<string> &v, bool isWord) {
  if (isWord) {
    for (auto &n : v) {
      cin >> n;
    }
    return;
  }

  int i = 0, size = v.size();
  string s;
  getline(cin, s);

  if (s.size() != 0) {
    i++;
    v[0] = s;
  }

  for (; i < size; ++i) {
    getline(cin, v[i]);
  }
}

static boost::dynamic_bitset<> scan(char trueValue) {
  string s;
  getline(cin, s);

  if (s.size() == 0) {
    getline(cin, s);
  }

  for_each(begin(s), end(s),
           [trueValue](char &c) { c = (c == trueValue) ? '1' : '0'; });
  return boost::dynamic_bitset<>(string(rbegin(s), rend(s)));
}


Measured memory_bytes: 1792
N, C = map(int, input().split())
D = []
for i in range(C):
    D.append(list(map(int, input().split())))
c = []
for i in range(N):
    c.append(list(map(int, input().split())))
ij = [[(i + j) % 3 for i in range(1, N + 1)] for j in range(1, N + 1)]
#print(ij)
color = [[0 for i in range(C)] for j in range(3)]
for i in range(1, N + 1):
    for j in range(1, N + 1):
        color[(i + j) % 3][c[i - 1][j - 1] - 1] += 1
#print(color)

cost = [[0 for i in range(C)] for j in range(3)]
for i in range(C): #(i + j) % 2 == 0
    cost[0][i] = 0
    for j in range(C):
        cost[0][i] += D[j][i] * color[0][j]
            
for i in range(C): #(i + j) % 2 == 1
    for j in range(C):
        cost[1][i] += D[j][i] * color[1][j]
                
for i in range(C): #(i + j) % 2 == 2
    for j in range(C):
        cost[2][i] += D[j][i] * color[2][j]

#print(cost)
minicost = 10000 * 500 * 500
for i in range(C):
    for j in range(C):
        if i != j:
            for k in range(C):
                if j != k and k != i:
                    if minicost > cost[0][i] + cost[1][j] + cost[2][k]:
                        minicost = cost[0][i] + cost[1][j] + cost[2][k]
print(minicost)

Measured memory_bytes: 7668
import scala.io.StdIn.readLine

class Dice(var d:List[Int]) {
  val fs = (x:List[Int]) => x match {case List(x1,x2,x3,x4,x5,x6) => List(x5,x1,x3,x4,x6,x2) }
  val fw = (x:List[Int]) => x match {case List(x1,x2,x3,x4,x5,x6) => List(x3,x2,x6,x1,x5,x4) }

  def roll(dir:Char)  =
    dir match {
      case 'S' => fs
      case 'N' => fs compose fs  compose fs
      case 'W' => fw
      case 'E' => fw compose fw compose fw
    }

  def apply(f:(List[Int])=>List[Int]) = this.d = f(this.d)
  def getTopFace() = d(0).toString
}

object Main extends App {
  val faces = readLine.split(" ").map(_.toInt).toList
  val dice = new Dice(faces)
  var rolls:(List[Int])=>List[Int] = x=>x

  dice.apply(readLine.foldLeft(rolls) { (x,y) => dice.roll(y) compose x })
  println(dice.getTopFace)
}

Measured memory_bytes: 44144
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INFLL LLONG_MAX // 9223372036854775807
#define EPS 1e-9
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
template<class T>bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }
using namespace std;

bool f(ll obj, ll &k, vi &a, ll &n){
    bool ret = true;
    ll cnt = 0;
    rep(i, n){
        cnt += (ceil(1.0*a[i]/obj)-1);
        if(cnt > k){
            ret = false;
            break;
        }
    }
    return ret;
}

int main(){
    Init();
    ll n, k; cin >> n >> k;
    vi a(n);
    rep(i, n) cin >> a[i];

    ll l=0, r=1000000000;
    while(r-l > 1){
        ll mid = (r+l)/2;
        (f(mid, k, a, n) ? r : l ) = mid;
    }
    cout << r << endl;
}

Measured memory_bytes: 4768
#include <iostream>

using namespace std;
const int maxn=1e6+10;
int main()
{
    //int up=111111;
    int k;cin>>k;
    int tmp=0;
    int ans=-1;
    for(int i=1; i<=maxn; i++){
        tmp=((tmp%k)*(10%k)%k+7%k)%k;
        if(tmp%k==0){
            ans=i;
            break;
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3172
#include <iostream>
using namespace std;
int main() {
    long long int n,i,sum=0;
    cin>>n;
    for(i=1;i<=n;i++)
    {
        if(i%3!=0 && i%5!=0)
            sum=sum+i;
    }
    cout<<sum;
    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
#define pb push_back
#define pii pair < ll , ll >
#define F first
#define S second
#define endl '\n'
#define int long long
#define sync ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#define kill(x) return cout<<x<<'\n', 0;
using namespace std;
const int N=5010,mod=1e9+7;
ll dp[N][N];
ll fac[N];
vector <int> g[N];
ll t=0;
ll vis[N];
void dfs(ll v){
    vis[v]=1;
    t++;
    for (auto u : g[v]){
        if (vis[u]) continue;
        dfs(u);
    }
}
ll a[N];
ll mol[N];
int32_t main(){
    fac[0]=1;
    for (int i=1;i<N;i++){
        fac[i]=fac[i-1]*i%mod;
    }
    ll power=1;
    ll n;
    cin >> n;
    for (int i=1;i<=n;i++){
        cin >> a[i];
        if (a[i]!=-1){
            g[i].pb(a[i]);
            g[a[i]].pb(i);
        }
    }
    ll p2=1;
    for (int i=1;i<=n;i++){
        if (a[i]!=-1) continue;
        t=0;
        dfs(i);
        mol[p2++]=t;
    }
    p2--;
    for (int i=1;i<=p2;i++) {
       // cout << mol[i] << endl;
        power*=n-1;
        power%=mod;
    }
    ll ans=0;
    for (int i=1;i<=n;i++){
        if (vis[i]==0){
            t=0;
            dfs(i);
            ans+=power;
        }
    }
   // cout << ans << " " << mol[1] << endl;
    dp[0][0]=1;
    for (int i=1;i<=p2;i++){
        for (int j=1;j<=i;j++){
            dp[i][j]=dp[i-1][j]*(n-1)%mod+dp[i-1][j-1]*(mol[i])%mod;
            dp[i][j]%=mod;
        }
        dp[i][0]=dp[i-1][0]*(n-1);
        dp[i][0]%=mod;
    }
    for (int i=2;i<=p2;i++){
        ans+=dp[p2][i]*fac[i-1]%mod;
      //  cout << i << " " << dp[p2][i]*fac[i-1]%mod << endl;
        ans%=mod;
    }
    ll powe=1;
    for (int i=1;i<p2;i++){
        powe*=n-1;
        powe%=mod;
    }
    for (int i=1;i<=p2;i++){
        if (mol[i]>1){
            ans+=powe*(mol[i]-1);
            ans%=mod;
        }
    }
    ll z=power*(n);
    z%=mod;
    z-=ans;
    z+=mod;
    cout << z%mod << endl;

}


Measured memory_bytes: 120512
#include<bits/stdc++.h>
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define ll long long
#define pb push_back 
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)

using namespace std;

int main()
{
    IOS;
    int n,m;
    cin >> n >> m;
    if(n == m)
        cout << "Yes";
    else
        cout << "No";
}

Measured memory_bytes: 256
class Dice:
    def __init__(self,pips):
        self.top = pips[0]
        self.south = pips[1]
        self.east = pips[2]
        self.west = pips[3]
        self.north =pips[4]
        self.bottom=pips[5]
    def n(self):
        self.top,self.south,self.bottom,self.north = \
        self.south,self.bottom,self.north,self.top
    def s(self):
        self.top,self.north,self.bottom,self.south = \
        self.north,self.bottom,self.south,self.top
    def e(self):
        self.top,self.west,self.bottom,self.east = \
        self.west,self.bottom,self.east,self.top
    def w(self):
        self.top,self.east,self.bottom,self.west = \
        self.east,self.bottom,self.west,self.top
    def r(self):
        self.north,self.east,self.south,self.west = \
        self.east,self.south,self.west,self.north
    def set_ts(self,t,s):
        for i in range(4):
            if self.top != t:
                if self.east == t or self.west == t:
                    self.e()
                else:
                    self.n()
            else:
                break
        for i in range(4):
            if self.south != s:
                self.r()
            else:
                break
        if(self.top == t and self.south == s):
            return True
        else:
            return False

pips = [int(x) for x in input().split()]
a = Dice(pips)
pips = [int(x) for x in input().split()]
b = Dice(pips)
b_pat = []
for i in range(6):
    if i < 4:
        b.n()
    elif i == 4:
        b.e()
    elif i == 5:
        b.e()
        b.e()
    for j in range(4):
        b.r()
        b_pat.append([b.top,b.north,b.south,b.east,b.west,b.bottom])

if ([a.top,a.north,a.south,a.east,a.west,a.bottom]) in b_pat:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 7852
#include<iostream>
#include<cstdio>
using namespace std;
int MIN=0x7fffffff;
int compute(int x,int y)
{
	int c=0;
	int c2=0;
	while(x!=0)
	{
		c+=x%10;
		x/=10;
	}
	while(y!=0)
	{
		c2+=y%10;
		y/=10;
	}
	return c+c2;
}
int main()
{
	int n;
	cin>>n;
	int n2=n/2;
	int b;
	for(int i=1;i<=n2;i++)
	{
		b=compute(i,n-i);
		if(b<MIN)
			MIN=b;
	}
	cout<<MIN;
	return 0;
}

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

int dp[1002][1002];

int lcs(string s1,string s2) {
    int m = s1.length();
    int n = s2.length();
    s1 = " " + s1;
    s2 = " " + s2;
    for(int i=1;i<=m;i++) dp[i][0] = 0;
    for(int i=1;i<=n;i++) dp[0][i] = 0;
    int rec = 0;
    for(int i=1;i<=m;i++) {
        for(int j=1;j<=n;j++) {
            if(s1[i] == s2[j]) {
                dp[i][j] = dp[i-1][j-1] + 1;
            } else {
                dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
            }
            rec = max(rec,dp[i][j]);
        }
    }
    return rec;
}

int main() {
    int n; cin >> n;
    while(n--) {
        string s1,s2; cin >> s1 >> s2;
        cout << lcs(s1,s2) << endl;
    }
    return 0;
}



Measured memory_bytes: 7100
program Build_Stairs
    implicit none
    integer(4):: n,i,nmax
    integer(4),allocatable:: h(:)

    read*, n
    allocate(h(n))
    read*, h(:)
    nmax=h(1)
    do i=2,n
        if (h(i) < nmax-1) then
            print*, 'No'
            stop
        end if
        nmax =max(nmax, h(i))
    end do
    print*, 'Yes'


end program Build_Stairs

Measured memory_bytes: 1152
#include<stdio.h>
#include<math.h>
int main(){
int n,i;
double a,b,c,d,e,f,l;
scanf("%d\n",&n);
for(i=0;i<n;i++){
scanf("%lf %lf %lf %lf %lf %lf\n",&a,&b,&c,&d,&e,&f);
l=(a-d)*(a-d)+(b-e)*(b-e);
l=sqrt(l);
if(c+f<l){
printf("0\n");
}
else if(c-f>l){
printf("2\n");
}
else if(f-c>l){
printf("-2\n");
}
else{
printf("1\n");
}
}
return 0;
}


Measured memory_bytes: 2048
import java.util.Iterator;
import java.util.PrimitiveIterator;
import java.util.Scanner;
import java.util.function.Supplier;
import java.util.stream.IntStream;
import java.util.stream.Stream;

public class Main{
	static Scanner s=new Scanner(System.in);

	void solve(){
		long a=gInt(),b=gInt(),ab=gInt(),x=gInt(),y=gInt();
		long r=Long.MAX_VALUE;

		for(long i=Math.max(x,y)*2;i>=0;--i) {
			r=Math.min(r,ab*i+Math.max(0,x-i/2)*a+Math.max(0,y-i/2)*b);
		}
		System.out.println(r);
	}

	public static void main(String[] $){
		new Main().solve();
	}

	static int gInt(){
		return Integer.parseInt(s.next());
	}
	static long gLong(){
		return Long.parseLong(s.next());
	}
	static double gDouble(){
		return Double.parseDouble(s.next());
	}

	SupplyingIterator<Integer> ints(int n){
		return new SupplyingIterator<>(n,Main::gInt);
	}
	SupplyingIterator<Long> longs(int n){
		return new SupplyingIterator<>(n,Main::gLong);
	}
	SupplyingIterator<Double> doubles(int n){
		return new SupplyingIterator<>(n,Main::gDouble);
	}
	SupplyingIterator<String> strs(int n){
		return new SupplyingIterator<>(n,s::next);
	}

	Range rep(int i){
		return Range.rep(i);
	}
	Range rep(int f,int t,int d){
		return Range.rep(f,t,d);
	}
	Range rep(int f,int t){
		return rep(f,t,1);
	}
	Range rrep(int f,int t){
		return rep(t,f,-1);
	}

	IntStream REP(int v){
		return IntStream.range(0,v);
	}
	IntStream REP(int l,int r){
		return IntStream.rangeClosed(l,r);
	}

	IntStream INTS(int n){
		return IntStream.generate(Main::gInt).limit(n);
	}
	Stream<String> STRS(int n){
		return Stream.generate(s::next).limit(n);
	}

}
class SupplyingIterator<T> implements Iterable<T>,Iterator<T>{
	int			t;
	Supplier<T>	supplier;

	SupplyingIterator(int t,Supplier<T> supplier){
		this.t=t;
		this.supplier=supplier;
	}

	@Override
	public Iterator<T> iterator(){
		return this;
	}

	@Override
	public boolean hasNext(){
		return t>0;
	}

	@Override
	public T next(){
		--t;
		return supplier.get();
	}

}
class Range implements Iterable<Integer>,PrimitiveIterator.OfInt{
	int to,cur,d;

	Range(int from,int to,int d){
		this.cur=from-d;
		this.to=to;
		this.d=d;
	}

	Range(int n){
		this(0,n-1,1);
	}

	@Override
	public Iterator<Integer> iterator(){
		return this;
	}

	@Override
	public boolean hasNext(){
		return cur+d==to||(cur!=to&&(cur<to==cur+d<to));
	}

	@Override
	public int nextInt(){
		return cur+=d;
	}

	static Range rep(int i){
		return new Range(i);
	}
	static Range rep(int f,int t,int d){
		return new Range(f,t,d);
	}
	static Range rep(int f,int t){
		return rep(f,t,1);
	}
	static Range rrep(int f,int t){
		return rep(f,t,-1);
	}

}


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

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

    pair<pair<string, int>, int> s[100];
    string str;
    int num;
    for (int i = 0; i < n; i++) {
        cin >> str >> num;
        s[i] = make_pair(make_pair(str,-num) ,i);
    }
    sort(s, s+n);
    for (int i = 0; i < n; i++) {
        cout << s[i].second+1 << endl;
    }

    return 0;
}


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

constexpr int inf = 0x3f3f3f3f;
constexpr ll linf = 0x3f3f3f3f3f3f3f3fLL;

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

    int n, m; cin >> n >> m;
    vector<vector<int>> g(n);
    for (int i = 0; i < m; i++) {
        int a, b; cin >> a >> b;
        a--, b--;
        g[a].emplace_back(b);
        g[b].emplace_back(a);
    }

    vector<int> ans(n);
    vector<bool> visited(n);
    queue<int> q;
    q.emplace(0); visited[0] = true;
    while (!q.empty()) {
        int now = q.front(); q.pop();
        for (auto &nxt: g[now]) {
            if (visited[nxt]) continue;
            visited[nxt] = true;
            ans[nxt] = now;
            q.emplace(nxt);
        }
    }
    cout << "Yes" << endl;
    for (int i = 1; i < n; i++) {
        cout << ans[i] + 1 << endl;
    }
    return 0;
}


Measured memory_bytes: 10328
N, Z, W = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]

if N == 1:
    print(abs(W - a[0]))
elif N == 2:
    print(max(abs(a[1] - a[0]), abs(a[1] - W)))
elif N>=3:
    print(max(abs(a[-1] - W), abs(a[-1] - a[-2])))

Measured memory_bytes: 38640
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskX solver = new TaskX();
		solver.solve(1, in, out);
		out.close();
	}

	static int INF = 1 << 30;
	static long LINF = 1L << 55;
	static int MOD = 1000000007;
	static int[] mh4 = { 0, -1, 1, 0 };
	static int[] mw4 = { -1, 0, 0, 1 };
	static int[] mh8 = { -1, -1, -1, 0, 0, 1, 1, 1 };
	static int[] mw8 = { -1, 0, 1, -1, 1, -1, 0, 1 };

	static class TaskX {

		public void solve(int testNumber, InputReader in, PrintWriter out) {

			String a = in.nextString();
			String b = in.nextString();
			String c = in.nextString();

			out.printf("%s%s%s\n", a.charAt(0), b.charAt(0), c.charAt(0));

		}
	}

	static class InputReader {
		BufferedReader in;
		StringTokenizer tok;

		public String nextString() {
			while (!tok.hasMoreTokens()) {
				try {
					tok = new StringTokenizer(in.readLine(), " ");
				} catch (IOException e) {
					throw new InputMismatchException();
				}
			}
			return tok.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(nextString());
		}

		public long nextLong() {
			return Long.parseLong(nextString());
		}

		public double nextDouble() {
			return Double.parseDouble(nextString());
		}

		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt();
			}
			return res;
		}

		public int[] nextIntArrayDec(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt() - 1;
			}
			return res;
		}

		public long[] nextLongArray(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong();
			}
			return res;
		}

		public long[] nextLongArrayDec(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong() - 1;
			}
			return res;
		}

		public InputReader(InputStream inputStream) {
			in = new BufferedReader(new InputStreamReader(inputStream));
			tok = new StringTokenizer("");
		}
	}

}


Measured memory_bytes: 21460
while True:
    n, p = [int(s) for s in input().strip().split()]

    if n == 0 and p == 0:
        break

    wan = p
    cands = [0] * n

    is_decided = False
    while not is_decided:
        for i in range(n):
            if wan == 1 and (cands[i] + 1) == p:
                print(i)
                is_decided = True
                break

            if wan == 0:
                wan += cands[i]
                cands[i] = 0
            else:
                wan -= 1
                cands[i] += 1




Measured memory_bytes: 5600
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;scanf("%d",&n);
    int a;scanf("%d",&a);
    for(int i=0;i<n-1;i++){
        int b;scanf("%d",&b);
        a=__gcd(a,b);
    }
    printf("%d\n",a);
}

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

#define int long long
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rep1(i,n) for(int i=1;i<=(int)(n);++i)
#define rep11(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end())
#define vdelete(v) (v).erase(unique(all(v)), (v).end())
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1000000007
#define INF LONG_LONG_MAX

int n,a,r1,r2=INF,cnt1=1,cnt2;
bool f=true;

signed main() {
    cin >> n >> r1;
    rep(i,n-1) {
        cin >> a;
        if (r1 == a) cnt1++;
        else if (abs(r1-a)==1) {
            if (f) r2 = a, cnt2++, f=false;
            else if (r2 == a) cnt2++;
            else {
                cout << "No" << endl;
                return 0;
            }
        }
        else {
            cout << "No" << endl;
            return 0;
        }
    }
    if (r1 > r2) {
        swap(r1,r2);
        swap(cnt1, cnt2);
    }
    if (!cnt2) {
        if (n-1 == r1 || r1*2 <= n) cout << "Yes" << endl;
        else cout << "No" << endl;
    } else {
        n -= cnt1;
        r2 -= cnt1;
        if (r2 < 1) cout << "No" << endl;
        else if (r2*2 <= n) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
}





Measured memory_bytes: 256
# 解説通りに組んでみた

H, W = gets.split.map(&:to_i)

# ＃で埋めた配列を作る
b = []
(H + 2).times do
    b << Array.new((W + 2), "#")
end

# 入力された文字列を挿入する
H.times do |i|
    a = gets.chomp.split("")
    W.times do |j|
       b[i + 1][j + 1]=a[j]
    end
end

# 配列を展開して表示
b.each do |s|
    puts s.join
end


Measured memory_bytes: 2300
#include <set>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define N 400005
#define ll long long
int n, l, tot;
int A[N], now[N], nnow[N], pre[N];
int val[N], vl[N], vr[N], suml[N], sumr[N];
ll ans;
struct cmp
{
	bool operator ()(const int &a,const int &b)
	{
		if (val[a] != val[b])
			return val[a] < val[b];
		return vl[a] < vl[b];
	}
};
set<int, cmp>s;
int main()
{
	scanf("%d%d", &n, &l);
	for (int i = 1; i <= n; i++)
	{
		scanf("%d", &A[i]);
		++tot;
		vl[tot] = vr[tot] = i;
		val[tot] = A[i];
		suml[tot] = sumr[tot] = 1;
		s.insert(tot);
	}
	while (!s.empty())
	{
		int len = 0;
		now[++len] = *s.begin();
		s.erase(s.begin());
		while (!s.empty() && val[*s.begin()] == val[now[1]] && vl[*s.begin()] == vr[now[len]] + 1)
		{
			now[++len] = *s.begin();
			s.erase(s.begin());
		}
		pre[0] = 0;
		for (int i = 1; i <= len; i++)
			pre[i] = pre[i - 1] + suml[now[i]];
		for (int i = 1; i <= len; i++)
		{
			ans += (ll)suml[now[i]] * sumr[now[i]]; 
			if (i - l + 1 >= 1)
				ans += (ll)sumr[now[i]] * pre[i - l + 1];
		}
		int nlen = 0, last = 0;
		for (int i = 1; i <= len / l; i++)
		{
			int tmpl = (i - 1) * l + 1, tmpr = i * l;
			if (i == len / l)
				tmpr = len;
			tot++;
			vl[tot] = vl[now[tmpl]];
			vr[tot] = vr[now[tmpr]];
			val[tot] = val[now[1]] + 1;
			for (int j = i * l; j <= (i + 1) * l - 1 && j <= len; j++)
				sumr[tot] += sumr[now[j]];
			suml[tot] = pre[len % l + 1 + (i - 1) * l] - pre[last];
			last = len % l + 1 + (i - 1) * l;
			s.insert(tot);
			nnow[++nlen] = tot;
		}
		pre[0] = 0;
		for (int i = 1; i <= nlen; i++)
			pre[i] = pre[i - 1] + suml[nnow[i]];
		for (int i = 1; i <= nlen; i++)
		{
			ans -= (ll)suml[nnow[i]]*sumr[nnow[i]];
			if (i - l + 1 >= 1)
				ans -= (ll)sumr[nnow[i]] * pre[i - l + 1];
		}
	}
	printf("%lld\n", ans);
}


Measured memory_bytes: 22400
N = int(input())
p_array = []
for _ in range(N):
  price = int(input())
  p_array.append(price)

#合計
price_sum = sum(p_array)
#最大値の半分の値（/ではなく//を使用しているのはint型にするため）
discount = max(p_array)//2

print(price_sum - discount)

Measured memory_bytes: 2940
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define all(c) begin(c), end(c)
const int INF =
    sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = 1e9 + 7;
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, K;
    cin >> N >> K;
    cout << (N % K != 0) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin >> n;
  
  vector<int> height(n);
  for(int i=n-1; i>=0; i--) {
    cin >> height[i];
  }
  
  bool judge = true;
  for (int i=0; i<n; i++) {
    if (i == 0) {
      continue;
    }
    if (height[i] > height[i-1] + 1) {
      judge = false;
      break;
    }
    else if (height[i] == height[i-1] + 1) {
      height[i]--;
    }
  }
  
  cout << (judge ? "Yes" : "No") << endl;
}

Measured memory_bytes: 768
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <deque>
#include <stack>
#include <map>
const int MOD = 1e9+7;
#define PI 3.14159265359
typedef long long ll;
using namespace std;

ll llmax(ll x, ll y){
	if (x > y) return x;
	return y;
}


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

	if (n == 1 && m == 1){
		cout << 1 << endl;
	}else if (n == 1 || m == 1){
		cout << llmax(n, m) - 2 << endl;
	}else{
		cout << (n-2)*(m-2) << endl;
	}
	return 0;
}

Measured memory_bytes: 3620