akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int n;
vector<char>c(100);
int main() {
	while (1) {
		int ba = 0;
		cin >> n;
		if (n == 0) return 0;
		vector<int>v(n);
		for (int i = 0; i < 100; i++) {
			cin >> c[i];
		}
		for (int i = 0; i < 100; i++) {
			if (c[i] == 'M') {
				v[i%n]++;
			}
			if (c[i] == 'S') {
				ba += 1 + v[i%n];
				v[i%n] = 0;
			}
			if (c[i] == 'L') {
				v[i%n] += 1 + ba;
				ba = 0;
			}
		}
		sort(v.begin(), v.end());
		for (int i = 0; i < n; i++) {
			cout << v[i] << " ";
		}
		cout << ba << endl;
	}
	return 0;
}

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

#define rep(i,a,b) for(int i=a;i<b;i++)
#define int long long
const int inf = 100100100100100009;
const int mod = 1000000007;

int mod_pow(int x, int n, int m){
    if(n== 0) return 1;
    int res = mod_pow(x*x%m,n/2,m);
    if(n&1) res = res*x%m;
    return res;
}

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


    int n, m; cin >> n >> m;
    cout << mod_pow(m,n,mod) << endl;



}


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

int main() {
    string N; cin >> N;
    long long sum = 0;
    for (int i = 0; i < N.size(); i++) {
        sum += N.at(i) - '0';
    }
    if (sum % 9 == 0) {
        cout << "Yes" << endl;
    } else cout << "No" << endl;
}

Measured memory_bytes: 3748
#include<stdio.h>

int main(){
  int m,f,b;
  scanf("%d %d %d", &m, &f, &b);
  if(m >= b){
    printf("%d\n", 0);
  }
  else if(m+f >= b){
    printf("%d\n", b-m);
  }
  else{
    printf("NA\n");
  }
  return(0);
}



Measured memory_bytes: 2088
#include<cstdio>
int main(){
	int a,b,c,d,i,j,k,l;
	double g;
	while(~scanf("%d",&a))
	{
		l=0;
		if(a<100)
		printf("0\n");
		else
		{
			b=a%100;
			c=a/100;
//			printf("%d %d\n",b,c);
			if(b==0)
			{
			printf("1\n");
			continue;	
			}
			if(b%2==0)
			{
				d=b/2;
				if(c>=d)
			l=1;
				else
			l=0;
			}
			if(l==1)
			{
			printf("1\n");
			continue;	
			}
				if(b%4==0)
			{
				d=b/4;
				if(c>=d)
			l=1;
				else
			l=0;
			}
			if(l==1)
			{
			printf("1\n");
			continue;	
			}
			 if(b%3==0)
			{
				d=b/3;
				if(c>=d)
				l=1;
				else
				l=0;
			}
			if(l==1)
			{
			printf("1\n");
			continue;	
			}
			if(b%5==0)
			{
				d=b/5;
				if(c>=d)
			l=1;
				else
				l=0;
			}
			if(l==1)
			{
			printf("1\n");
			continue;	
			}
			if(b%2&&b%3&&b%5)
			{
				d=b;
				if(c>=d)
				l=1;
				else
				l=0;
			}
			if(l==1)
			printf("1\n");
			else
			printf("0\n");
			
		}
	}
}

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

typedef long long ll;
typedef pair<int, int> pii;
#define FOR(i, n) for(int (i)=0; (i)<(n); (i)++)
#define FOR1(i, n) for(int (i)=1; (i)<=(n); (i)++)
#define FORI(i, n) for(int (i)=n-1; (i)>=0; (i)--)

int main(int argc, char** argv) {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout << setprecision(15);
    if (argc == 2 && atoi(argv[1]) == 123456789) {
        freopen("d:\\code\\cpp\\contests\\stdin", "r", stdin);
        //freopen("d:\\code\\cpp\\contests\\stdout", "w", stdout);
    }

    int n, t;
    cin >> n >> t;
    vector<pii> v(n+1);
    FOR1(i, n)
        cin >> v[i].first >> v[i].second;
    sort(v.begin()+1, v.end(), less<pii>());

    const int M = 3000;
    vector<vector<ll>> dp(n+1, vector<ll>(2*M+1, 0));

    ll sol = 0;
    FOR1(i, n){
        for(int j=0; j<v[i].first; j++) {
            dp[i][j] = dp[i - 1][j];
        }
        for(int j=v[i].first; j<=t+v[i].first-1; j++){ //time when finished
            dp[i][j] = max( dp[i-1][j], v[i].second + dp[i-1][j-v[i].first]);
            sol = max(sol, dp[i][j]);
        }
    }
    cout << sol << endl;

    if (argc == 2 && atoi(argv[1]) == 123456789)        cerr << clock()*1.0/CLOCKS_PER_SEC << " sec\n";
    return 0;
}

Measured memory_bytes: 141184
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> P; //終点、始点

int main(){
    int N; int M;
    cin >> N >> M;
    P A[100100];
    for(int i=0; i<M; i++){
        int a,b;
        cin >> a >> b;
        P p;
        p.first =b; p.second =a;
        A[i]=p;
    }
    sort(A,A+M);
    int cnt=0;
    int before=1;
    for(int i=0; i<M; i++){
        P q=A[i];
        int a = q.first; int b=q.second;
        if(q.second < before) continue;
        cnt++;
        before =q.first;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 1024
K, N = map(int, input().split())
A = list(map(int, input().split()))

total = [0]*N
for i in range(N-1):
  total[i] = A[i+1] - A[i]
total[N-1] = K - A[N-1] + A[0]

print(sum(total)-max(total))

Measured memory_bytes: 26420
import sys
input = lambda: sys.stdin.readline().rstrip()
input_nums = lambda: list(map(int, input().split()))

def main():
    S = input()
    isMM = lambda s: int(s) > 0 and int(s) <= 12
    isOnlyYY = lambda s: int(s)>12 or int(s) == 0
    if   isMM(S[:2]) and isOnlyYY(S[2:]): print('MMYY')
    elif isOnlyYY(S[:2]) and isMM(S[2:]): print('YYMM')
    elif isMM(S[:2]) and isMM(S[2:]): print('AMBIGUOUS')
    else: print('NA')

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
/*
AuThOr Gwj
*/
#include<bits/stdc++.h>
#define rb(a,b,c) for(int a=b;a<=c;++a)
#define rl(a,b,c) for(int a=b;a>=c;--a)
#define LL long long
#define IT iterator
#define PB push_back
#define II(a,b) make_pair(a,b)
#define FIR first
#define SEC second
#define FREO freopen("check.out","w",stdout)
#define rep(a,b) for(int a=0;a<b;++a)
#define KEEP while(1)
#define SRAND mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define random(a) rng()%a
#define ALL(a) a.begin(),a.end()
#define POB pop_back
#define ff fflush(stdout)
#define fastio ios::sync_with_stdio(false)
#define debug_pair(A) cerr<<A.FIR<<" "<<A.SEC<<endl;
using namespace std;
const int INF=0x3f3f3f3f;
typedef pair<int,int> mp;
typedef pair<mp,mp> superpair;
int main(){
	fastio;
	LL a,b,n;
	cin>>a>>b>>n;
	LL x=min(n,b-1);
	cout<<((a*x)/b-a*(x/b))<<endl;
	return 0;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
#define int long long int
#define INF 1000000005
#define MOD 1000000007
#define FF first
#define SS second
#define double long double
#define int long long int

using namespace std;
typedef long long ll;

ll gcd(ll loc, ll b)
{
    if(loc == 0LL)
        return b;
    if(b == 0LL)
        return loc;
    return gcd(b, loc%b);
}

typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll modx(ll Base, ll exponent)
{
  ll ans = 1;
  if(Base == 1)
    return Base;
  while(exponent)
  {
    if(exponent & 1)
      ans = (ans * Base)%MOD;
    Base = (Base * Base)%MOD;
    exponent = exponent >> 1;
  }
  return ans;
}

ll inmodx(ll num)
{
  return (modx(num, MOD-2LL));
}

bool cmp(pii loc, pii b)//true for loc before b
{
  if(loc.SS < b.SS)
    return 1;
  if(loc.SS > b.SS)
    return 0;
  if(loc.FF <= b.FF)
    return 1;
  return 0;
}
int n;
double p[5005];
double dp[5005][5005];
signed main()
{   
    
  
 //  freopen("input.txt", "r", stdin);
  //freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(0); 
    cin.tie(0);
    cout.tie(0);

    cin>>n;
    for(int i=0;i<n;i++)
      cin>>p[i];
  dp[1][n]=1.0000;
  for(int i=0;i<=n+1;i++)
  {
    for(int j=n-1;j>=0;j--)
    {
      dp[i+1][j]=p[j]*dp[i][j+1]+(1.0000-p[j])*dp[i+1][j+1];
    }
  }
/* for(int i=0;i<=n+1;i++)
 {
   for(int j=0;j<=n;j++)
   {
    cout<<dp[i][j]<<" ";
   }
   cout<<endl;
 } 
 */
 double sum=0.00000000;
 for(int i=(n/2)+2;i<=n+1;i++)
 {
  sum+=dp[i][0];
 }
 cout<<fixed<<setprecision(10)<<sum<<endl;


  
  return 0;
}

Measured memory_bytes: 235264
#include <iostream>
using namespace std;
int a[3],m[3];
int ans = 0;

int freq(int a1, int m1, int x) {
  x = (a1*x)%m1;
  if(x == 1) return 1;
  else return freq(a1,m1,x)+1;
}

int gcd(int x,int y) {
  if(y == 0) return x;
  else return gcd(y ,x % y);
}

int main() {
  while(cin >> a[0] >> m[0] >> a[1] >> m[1] >> a[2] >> m[2]) {
    if(a[0] == 0 && m[0] == 0 && a[1] == 0 && m[1] == 0 && a[2] == 0 && m[2] == 0) break;
    int fa = freq(a[0],m[0],1);
    int fb = freq(a[1],m[1],1);
    int fc = freq(a[2],m[2],1);
    int LCMab = fa*fb/gcd(fa,fb);
    int LCMbc = fb*fc/gcd(fb,fc);
    long long int LCMabc = (long long int)LCMab*(long long int)LCMbc/(long long int)gcd(LCMab,LCMbc);
    cout << LCMabc << endl;
  }
}

Measured memory_bytes: 0
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) {

		 BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		 try{

			 int x = Integer.parseInt(br.readLine());

			 System.out.printf("%d\n", x*x*x);

		 }catch(IOException e){
			 e.printStackTrace();
		 }
	}
}





Measured memory_bytes: 24420
#include<stdio.h>

int n,A[50];

//入力値のMから選んだ要素を引いていく再帰関数
int solve (int i,int m){
	if( m==0 ) return 1;
	if( i>=n ) return 0;
	int res = solve(i + 1, m) || solve(i+1,m-A[i]);
	return res;
}

int main(){
	int q,M,i;
	
	scanf("%d",&n);
	for(i=0; i<n; i++) scanf("%d",&A[i]);
	scanf("%d",&q);
	for(i=0; i<q; i++){
		scanf("%d",&M);
		if(solve(0,M))printf("yes\n");
		else printf("no\n");
	}
	
	return 0;
}


Measured memory_bytes: 2128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define FORL(i,x) for(int i=head[x];i;i=nxt[i])
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define PB push_back
#define MP make_pair
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }



int main() {
  ll N,K;
  scanf("%lld%lld", &N,&K);
  vector<ll> v;
  FOR(i,0,N-1){
    ll input;
    cin >> input;
    v.PB(input);
  }

  ll ans = 0;
  const ll MOD = pow(10,9) + 7;

  FOR(i,0,N-1){
    ll all_lower = 0;
    ll remain_lower = 0;

    FOR(j,0,N-1){
      if(v[j]<v[i]) ++all_lower;
    }

    FOR(j,i+1,N-1){
      if(v[j]<v[i]) ++remain_lower;
    }

    // cout << all_lower << " " << remain_lower << endl;

    if(K%2!=0) ans += all_lower * K % MOD * ((K-1) / 2) % MOD;
    else ans += all_lower * (K / 2) % MOD * (K-1) % MOD;
    ans %= MOD;
    ans += remain_lower * K % MOD;
  }

  cout << ans << endl;

}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
//using namespace __gnu_pbds;
//typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> set_t;
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define pf push_front
#define SUM(v) accumulate(v.begin(),v.end(),lli(0))
#define rev(n,d) for(int i=n;i>=d;i--)
#define FOR0(n) for(lli i=0;i<n;i++)
#define FOR(a,n) for(int i=a;i<n;i++)
#define FORQ(a,n) for(lli i=a;i<=n;i++)
#define inf 1000000009
#define inff 0x3f3f3f3f
#define sz(a) int((a).size())
#define all(c) c.begin(), c.end()
#define ff first
#define ss second
#define endl "\n"
#define mod 1000000007
#define mem(ar,x) memset(ar,x,sizeof ar)
#define present(container, element) (container.find(element) != container.end())
#define max3(a,b,c) return (lli(a)>lli(b)?(lli(a)>lli(c)?a:c):(lli(b)>lli(c)?b:c))
#define max4(a,b,c,d) return (max3(a,b,c)>lli(d)?(max3(a,b,c)):d)
#define min3(a,b,c) return (lli(a)<lli(b)?(lli(a)<lli(c)?a:c):(lli(b)<lli(c)?b:c))
#define min4(a,b,c,d) return (max3(a,b,c)<lli(d)?(max3(a,b,c)):d)
typedef long long int lli;
typedef pair<int,int> pii;
typedef pair<int,pii>ppii;
typedef vector<int>vi;
typedef vector<vi>vvi;
typedef vector<pii>vpii;
const int N=100005;
int dr8[]={0,0,1,-1,1,1,-1,-1};
int dc8[]={1,-1,0,0,-1,1,-1,1};
int dr4[]={0,1,-1,0};
int dc4[]={1,0,0,-1};
lli n;
int check(lli x,lli y){
	if(x>n||x<1||y<1||y>n) return 0;return 1;
}
int main(){
	fast
	cin>>n;
	lli pos[n+1][n+1];
	pair<lli,lli>rc[n*n+1];
	lli in=1;
	lli dis[n+1][n+1];
	int done[n+1][n+1];
	mem(done,0);
	FORQ(1,n){
		for(lli j=1;j<=n;j++){
			pos[i][j]=in++;
			rc[in-1]={i,j};
			dis[i][j]=1+min(i-1,min(j-1,min(n-i,n-j)));
		}
	}
	lli an=0,p;
	lli t=n*n;
	while(t--){
		cin>>p;
		lli x=rc[p].ff,y=rc[p].ss;
		an+=--dis[x][y];
		done[x][y]=1;
		queue<pair<lli,lli> >q;
		q.push({x,y});
		while(!q.empty()){
			pair<lli,lli>f=q.front();
			q.pop();
			lli d=dis[f.ff][f.ss];
			lli r=f.ff,c=f.ss;
			for(int i=0;i<4;i++){
				lli cs=d;
				lli xx=dr4[i]+r,yy=dc4[i]+c;
				if(check(xx,yy)){
					if(!done[xx][yy]) cs++;
					if(cs<dis[xx][yy]){
						dis[xx][yy]=cs;
						q.push({xx,yy});
					}
				}
			}
		}
	}
	cout<<an;
}



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

using namespace std;

using ll = long long;
const ll mxs = 1e18 + 10;

ll n, c;
vector<ll> arr;

// ll power(ll a, int p){
//     ll res = 1;
//     while(p){
//         if(p & 1) res = res * a;
//         a = a * a;
//         p /= 2;
//     }
//     return res;
// }

// ll cost(int i, int j){
//     ll res = pow(ll(arr[i] - arr[j]), (ll) 2) + (ll) c;
//     return res;
// }

// ll solve(int idx){
//     // cout<<idx<<endl;
//     if(idx == n - 1) return 0;
//     ll res = mxs;
//     for(int i = idx + 1; i < n; i++){
//         // cout<<i<<endl;
//         res = min(res, cost(idx, i) + solve(i));
//     }
//     return res;
// }

struct line {
    ll k, b;
    pair<ll, ll> intsect(const line& l){
        ll num = l.b - b;
        ll den = k - l.k;
        if(den < 0){
            num = -num;
            den = -den;
        }
        assert(den > 0);
        return {num, den};
    }
};

int main(){
    // assert(power(5, 2) == 25);
    // assert(power(17, 2) == 289);
    cin>>n>>c;
    arr.resize(n);
    for(int i = 0; i < n; i++){
        cin>>arr[i];
    }
    vector<ll> dp(n);
    // dp[i] -> min cost to reach i from zero -> ans is dp[n-1]
    // dp[0] = 0;
    // for(int i = 1; i < n; i++){
    //     for(int j = 0; j < i; j++){
    //         dp[i] = min(dp[i], dp[j] + cost(j, i));
    //     }
    // }
    // ll res = dp[n-1];
    // ll res = solve(0);

    vector<line> lines;
    vector<pair<ll, ll>> sx;
    dp[0] = 0;
    int ptr = 0;
    for(int i = 0; i < n - 1; i++){
        line cur = {-2 * arr[i], dp[i] + arr[i] * arr[i]  + c};
        if(lines.empty()){
            lines.push_back(cur);
        }else{
            auto pr1 = cur.intsect(lines.back());
            pair<ll, ll> pr2;
            while(lines.size() >= 2){
                pr2 = sx.back();
                bool ok = (__int128) pr1.first * pr2.second <= (__int128) pr1.second * pr2.first; 
                if(ok){
                    lines.pop_back();
                    sx.pop_back();
                }else{
                    break;
                }
                pr1 = cur.intsect(lines.back());
            }
            lines.push_back(cur);
            sx.push_back(pr1);
        }
        ptr = min(ptr, (int) lines.size() - 1);
        while(ptr < (int) lines.size() - 1 && (__int128) arr[i+1] * sx[ptr].second >= (__int128) sx[ptr].first){
            ptr++;
        }
        dp[i + 1] = arr[i + 1] * arr[i + 1] + lines[ptr].k * arr[i + 1] + lines[ptr].b;
    }
    ll res = dp.back();
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 13536
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define all(v) v.begin(),v.end()
#define mp make_pair
#define ff first
#define ss second
#define MAXN  1000005
#define endl "\n"
using namespace std;
vector<string>v;
ll dp[1001][1001];
ll h,w;
ll mo=1000000007;
ll rec(int i, int j){
    if(i==h-1&&j==w-1)
        return 1;
    if(i>=h||j>=w)
        return 0;
    if(dp[i][j]!=-1)
        return dp[i][j];
    if(v[i][j]=='#')
        return 0;
    ll ans=rec(i+1,j)+rec(i,j+1);
    return dp[i][j]=ans%mo;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin>>h>>w;
    memset(dp,-1,sizeof(dp));
    for(ll i=0;i<h;i++){
        cin>>s;
        v.pb(s);
    }
    ll ans=rec(0,0);
    cout<<ans<<endl;



    return 0;
}



Measured memory_bytes: 9216
N=int(input())
S=input()

mapping=['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z']

converted_list=[]
for s in list(S):
    index=mapping.index(s)
    converted_list.append(mapping[(index+N)%26])

print(''.join(converted_list))

Measured memory_bytes: 3188
#include <bits/stdc++.h>
typedef long long ll;

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

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int d[5] = {0, 1, 0, -1, 0};

using namespace std;

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

    cin >> N;
    rep(i, N) { cout << "ACL"; }
    cout << endl;
}


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

int main(){
  int i,N,P;
  cin >> N >> P;
  vector<int> S(N);
  for(i=0; i<N; i++){
    scanf("%1d",&S[i]);
  }
  long long ans=0;
  if(P == 2 || P == 5){
    for(i=0; i<N; i++){
      if(S[i]%P == 0) ans += i+1;
    }
    cout << ans;
  }
  else{
    vector<long long> ret(P,0);
    vector<int> digit_ret(N);
    long long tmp=1;
    for(i=0; i<N; i++){
      digit_ret[i] = tmp;
      tmp = (tmp*10)%P;
    }
    tmp = 0;
    for(i=N-1; i>=0; i--){
      tmp = (tmp + S[i]*digit_ret[N-i-1])%P;
      ret[tmp]++;
    }
    for(i=0; i<P; i++){
      tmp = ret[i];
      ans += tmp*(tmp-1)/2;
    }
    cout << ans+ret[0];
  }
  return 0;
}

Measured memory_bytes: 1920
#include <algorithm>
#include <cmath>
#include <iostream>
#include <numeric>
#include <utility>
#include <string>
#include <vector>

using namespace std;

int MAX = 1e9;
int d, g;
vector<int> p;
vector<int> c;

int solve(int next, int remain, vector<pair<int, int>> &problems) {
    if (next == d) {
        for (int i = problems.size()-1; i >= 0; i--) {
            int point = problems[i].first;
            int numprob = problems[i].second;
            if (point * numprob >= remain) {
                return ceil(1.0 * remain / point);
            }
        }
        return MAX;
    } else {
        int point = next + 1;
        int avail_p = p[next] * point + c[next];
        int when_complete = MAX;
        if (remain > avail_p) {
            when_complete = p[next] + solve(next + 1, remain - avail_p, problems);
        } else if (remain <= avail_p) {
            when_complete = p[next];
        }
        problems.emplace_back(point, p[next] - 1);
        int when_incomplete = solve(next + 1, remain, problems);
        problems.pop_back();
        return min(when_complete, when_incomplete);
    }
}

int main() {
    cin >> d >> g;
    g /= 100;
    for (int i = 0; i < d; i++) {
        int pp, cc;
        cin >> pp >> cc;
        cc /= 100;
        p.push_back(pp);
        c.push_back(cc);
    }

    vector<pair<int, int >> problems;
    int result = solve(0, g, problems);
    cout << result << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <array>
#include <algorithm>

std::vector<unsigned long long> split(std::string str, char del) {
    int first = 0;
    int last = str.find_first_of(del);

    std::vector<unsigned long long> result;

    while (first < str.size()) {
        std::string subStr(str, first, last - first);

        result.push_back(std::stoi(subStr));

        first = last + 1;
        last = str.find_first_of(del, first);

        if (last == std::string::npos) {
            last = str.size();
        }
    }

    return result;
}

int main()
{
    std::string str;
    std::getline(std::cin, str);
    unsigned long long n = std::stoi(str);
    
    std::getline(std::cin, str);
    if (n < 3)
    {
        std::cout << 0 << std::endl;
    }
    else
    {
        auto vec = split(str, '  ');

        std::array<int, 3> edge;
        int count = 0;
        for (int i = 0; i < n - 2; i++)
        {
            for (int j = i + 1; j < n - 1; j++)
            {
                for (int k = j + 1; k < n; k++)
                {
                    edge[0] = vec[i];
                    edge[1] = vec[j];
                    edge[2] = vec[k];

                    if (edge[0] != edge[1] && edge[1] != edge[2] && edge[2] != edge[0])
                    {
                        std::sort(edge.begin(), edge.end());
                        if (edge[2] < edge[1] + edge[0])
                        {
                            count++;
                        }

                    }
                }
            }
        }

        std::cout << count << std::endl;
    }

    
}

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

using ull = unsigned long long;
using ll = long long;

const int mod = 1e9 + 7;
const int inf = INT_MAX;
const int N = 5000 + 5;

ll n, k, p[N], c[N];

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

    cin >> n >> k;
    for (int i = 1; i <= n; i++) cin >> p[i];
    for (int i = 1; i <= n; i++) cin >> c[i];

    ll ans = LLONG_MIN;
    for (int i = 1; i <= n; i++) {
        int ptr = p[i];
        ll sum = c[p[i]];

        vector<ll> val = {sum};
        while (ptr != i) {
            ptr = p[ptr];
            sum += c[ptr];
            val.push_back(sum);
        }

        ans = max(ans, (k / (ll)val.size()) * sum + (k % val.size() != 0 ? val[k % val.size() - 1] : 0));
        for (int j = 0; j < k % (ll)val.size(); j++) {
            ans = max(ans, (k / (ll)val.size()) * sum + val[j]);
        }

        if (k >= (ll)val.size()) {
            for (int j = 0; j < val.size(); j++) {
                ans = max(ans, (k / (ll)val.size() - 1) * sum + val[j]);
                ans = max(ans, val[j]);
            }
        }
    }

    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 3788
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
# define ll int64_t
# define str string
# define rep(i,n) for(ll i=0;i<n;i++)
# define rrep(i,n) for(ll i=1;i<=n;i++)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define mod 1000000007
# define PI 3.141592653589793
# define vec vector
#define dump(x) cerr<<#x<<"="<<x<<endl
using namespace std;

#define INF 2000000000
#define MAX_V 10



bool compare_by_b(pair<string,ll> a,pair<string,ll> b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}

bool my_compare(pair<string,ll> a,pair<string,ll> b){
    if(a.first != b.first) return a.first<b.first;
    if(a.second != b.second) return a.second>b.second;
    else return true;
}

ll modpow(ll a,ll n,ll mod1) {
    ll res=1;
    while(n>0){
        if(n&1) res=res*a%mod1;
        a = a*a%mod1;
        n >>= 1;
    }
    return res;
}

ll factorial(ll n){
    ll x=1;
    rrep(i,n) (x*=i)%=mod;
    return x;
}

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

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

using graph = vector<vector<ll>>;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll n;
    cin>>n;
    ll lc;
    rep(i,n){
        ll a;
        cin>>a;
        if(i==0) lc=a;
        else lc=lcm(lc,a);
    }
    cout<<lc<<endl;
    return 0;
}



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

#define each(i, c) for (auto& i : c)
#define mkp(a, b) make_pair(a, b)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> Pll;
const ll MOD = 1e9+7;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << ": " << p.second << ")"; return os; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ", "; os << ")"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; each (i, m) os << i << ", "; os << "}"; return os; }

int main() {
  ll a, b;
  cin >> a >> b;

  ll ans = 0;
  if (a%2 != 0) {
    ans = a;
  }
  
  if (b%2 == 0) {
    if ((b-a)/2 % 2 != 0) ans ^= 1;
    ans ^= b;
  } else {
    if ((b+1-a)/2 % 2 != 0) ans ^= 1;
  }

  cout << ans << endl;

  return 0;
}


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

int main(){
    int n;
    long long m;
    cin>>n>>m;
    vector<long long> a(n);
    for(int i=0;i<n;i++) cin>>a[i];
    long long ans=0;
    map<long long,int> mp;
    mp[0]=1;
    long long tmp=0;
    for(int i=0;i<n;i++){
        tmp+=a[i];
        tmp%=m;
        ans+=mp[tmp];
        mp[tmp]+=1;
    }

    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 7772
s = input()
t = input()
S = "UNRESTORABLE"
for i in range(len(s)-len(t), -1, -1):
    flag = all([s[i+j] == t[j] or s[i+j] == "?" for j in range(len(t))])
    if flag:
        S = s[:i]+t+s[i+len(t):]
        S = S.replace("?", "a")
        break
print(S)

Measured memory_bytes: 3060
n=int(input())
a = [0] + [int(i) for i in input().split()] + [0]
all = sum(abs(a[i]-a[i+1]) for i in range(n+1))
ans = []
for i in range(1,n+1):
  if (a[i-1] <= a[i] <= a[i+1]) or (a[i-1] >= a[i] >= a[i+1]):
    ans.append(all)
  else:
    ans.append(all - (abs(a[i-1]-a[i])+abs(a[i]-a[i+1])-abs(a[i-1]-a[i+1])))
for i in range(n):
  print(ans[i])

Measured memory_bytes: 14172
#include <stdio.h>

int max(int a, int b){
	if(a>b){
		return a;
	}
	return b;
}

int main(){
	int H;
	int W;
	char S[2000][2000];
	scanf("%d",&H);
	scanf("%d",&W);
	int i;
	int j;
	char dummy;
	scanf("%c",&dummy);
	for(i=0;i<H;i++){
		for(j=0;j<W;j++){
			scanf("%c",&S[i][j]);
		}
		scanf("%c",&dummy);
	}
	int f[2000][2000];//front
	int b[2000][2000];//back
	int l[2000][2000];//left
	int r[2000][2000];//right
	for(i=0;i<H;i++){
		for(j=0;j<W;j++){
			if(i==0){
				if(S[i][j]=='#'){
					f[i][j]=0;
				}else{
					f[i][j]=1;
				}
			}else{
				if(S[i][j]=='#'){
					f[i][j]=0;
				}else{
					f[i][j]=f[i-1][j]+1;
				}
			}
		}
	}
	for(i=H-1;i>=0;i--){
		for(j=0;j<W;j++){
			if(i==H-1){
				if(S[i][j]=='#'){
					b[i][j]=0;
				}else{
					b[i][j]=1;
				}
			}else{
				if(S[i][j]=='#'){
					b[i][j]=0;
				}else{
					b[i][j]=b[i+1][j]+1;
				}
			}
		}
	}
	for(i=0;i<H;i++){
		for(j=0;j<W;j++){
			if(j==0){
				if(S[i][j]=='#'){
					l[i][j]=0;
				}else{
					l[i][j]=1;
				}
			}else{
				if(S[i][j]=='#'){
					l[i][j]=0;
				}else{
					l[i][j]=l[i][j-1]+1;
				}
			}
		}
	}
	for(i=0;i<H;i++){
		for(j=W-1;j>=0;j--){
			if(j==W-1){
				if(S[i][j]=='#'){
					r[i][j]=0;
				}else{
					r[i][j]=1;
				}
			}else{
				if(S[i][j]=='#'){
					r[i][j]=0;
				}else{
					r[i][j]=r[i][j+1]+1;
				}
			}
		}
	}
	int ans;
	ans=0;
	for(i=0;i<H;i++){
		for(j=0;j<W;j++){
			ans=max(ans,f[i][j]+b[i][j]+l[i][j]+r[i][j]);
		}
	}
	ans=ans-3;
	printf("%d",ans);
}

Measured memory_bytes: 66560
program prob3
    implicit none
    integer :: a, b, c
    integer :: i
    read(*,*) a, b, c
    do i = 1, 100
        if(mod(a*i, b) == c)then
            write(*,'(a)') 'YES'
            stop
        end if
    end do

    write(*,'(a)') 'NO'
    stop
contains
end program prob3

Measured memory_bytes: 2904
import java.util.*;
import static java.lang.Integer.*;
//import static java.lang.Long.*;
import static java.lang.Math.*;
import static java.lang.System.*;

public class Main {
	public static void main(String[] args) {
		int i,j;
		Scanner sc = new Scanner(in);
		int n = parseInt(sc.next());
		int k = parseInt(sc.next());
		int[] a = new int[n];
		for(i=0;i<n;i++) {
			a[i] = parseInt(sc.next());
		}
		sc.close();
		int ans=1;
		n-=k;
		out.println(ans+(int)ceil((double)n/(k-1)));
	}
}

Measured memory_bytes: 47444
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] A = new int[N+1];
        int[] B = new int[N];
        for(int i = 0; i < N+1; i++) A[i] = sc.nextInt();
        for(int i = 0; i < N; i++) B[i] = sc.nextInt();

        long res = 0;
        for(int i = 0; i < N; i++) {
            int d = Math.min(A[i], B[i]);
            res += d;
            A[i] -= d;
            B[i] -= d;

            d = Math.min(B[i], A[i+1]);
            res += d;
            A[i+1] -= d;
            

        }
        System.out.println(res);
    }
}


Measured memory_bytes: 60312
import java.io.*;
import java.math.*;
import java.util.*;
public class Main { 
 
	public static void main(String[] args) { 
		Scanner input = new Scanner(System.in);
		long N = input.nextLong();
		long A = input.nextLong();
		long B = input.nextLong();
		long C = input.nextLong();
		long D = input.nextLong();
		long E = input.nextLong();
		long ans = 0;
		
		long S1 = ceil(N,A);
		ans+=S1;
		long sum = S1;
		
		long S2 = ceil(N,B);
		S2-=(sum-1);
		if (S2>0) {
			ans+=S2;
			sum+=S2;
		}else {
			ans++;
			sum++;
		}
		
		long S3 = ceil(N,C);
		S3-=(sum-2);
		if (S3>0) {
			ans+=S3;
			sum+=S3;
		}else {
			ans++;
			sum++;
		}
		long S4 = ceil(N,D);
		S4-=(sum-3);
		if (S4>0) {
			ans+=S4;
			sum+=S4;
		}else {
			ans++;
			sum++;
		}
		
		long S5 = ceil(N,E);
		S5-=(sum-4);
		if (S5>0) {
			ans+=S5;
			sum+=S5;
		}else {
			ans++;
			sum++; //Sum = sum of times per slot of getting all people out of city i
		}
		System.out.println(ans);
	}
	public static long ceil(long num, long den) {
		long ans = num/den;
		if (num%den!=0) ans++;
		return ans;
	}
}

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

using namespace std;

using int64 = long long;
const int mod = 1e9 + 7;

const int64 infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;


template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 > &p) {
  os << p.first << " " << p.second;
  return os;
}

template< typename T1, typename T2 >
istream &operator>>(istream &is, pair< T1, T2 > &p) {
  is >> p.first >> p.second;
  return is;
}

template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
  for(int i = 0; i < (int) v.size(); i++) {
    os << v[i] << (i + 1 != v.size() ? " " : "");
  }
  return os;
}

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

template< typename T = int64 >
vector< T > make_v(size_t a) {
  return vector< T >(a);
}

template< typename T, typename... Ts >
auto make_v(size_t a, Ts... ts) {
  return vector< decltype(make_v< T >(ts...)) >(a, make_v< T >(ts...));
}

template< typename T, typename V >
typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) {
  t = v;
}

template< typename T, typename V >
typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) {
  for(auto &e : t) fill_v(e, v);
}

template< typename F >
struct FixPoint : F {
  FixPoint(F &&f) : F(forward< F >(f)) {}

  template< typename... Args >
  decltype(auto) operator()(Args &&... args) const {
    return F::operator()(*this, forward< Args >(args)...);
  }
};

template< typename F >
inline decltype(auto) MFP(F &&f) {
  return FixPoint< F >{forward< F >(f)};
}

int main() {
  int N;
  cin >> N;
  vector< int > B(N - 1);
  cin >> B;

  int ret = 0;
  for(int i = 0; i < N; i++) {
    int v = inf;
    if(i < N - 1) v = min(v, B[i]);
    if(i - 1 >= 0) v = min(v, B[i - 1]);
    ret += v;
  }
  cout << ret << endl;
}



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

int main()
{
	int n;
	cin >> n;
	int s[n+1];
	
	for (int i=1; i<=n; i++)  cin >> s[i];
	int min=-1,f=0;
	
	for (int i=1; i<=100; i++){
		f=0;
		for (int j=1; j<=n; j++){
			f+=fabs(s[j]-i)*fabs(s[j]-i);
		}
		if (f<min || min==-1) min=f;
	}
	cout << min << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
class Main{
  public static void main(String[] args){
    Scanner stdIn = new Scanner(System.in);
    int N = stdIn.nextInt();
    double M = stdIn.nextDouble();
    Double X = 4*M;
    Double Y = 1/X;
    int[] s = new int[N];
    for (int i = 0; i<N; i++){
      s[i] = stdIn.nextInt();
    }
    int G = 0;
    for(int i = 0; i<N; i++){
      G += s[i];
    }
    int Sum = 0;
    for(int i = 0; i<N; i++){
      if(s[i]>=G*Y){
        Sum += 1;
      }
    }
    if(Sum >= M){
      System.out.println("Yes");
    }
    if(Sum < M){
      System.out.println("No");
    }
  }
}

Measured memory_bytes: 23124
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include <vector>
#include <map>
using namespace std;
long long Z(long long n) {
	if(n==0) return 0;
	return Z(n/5)+n/5;
}
long long Read() {
	long long x=0,f=1;
	char c=getchar();
	while(c<'0'||c>'9') {
		if(c=='-')f=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9')x=x*10+c-'0',c=getchar();
	return x*f;
}
int main() {
	int n,b;
	n=Read(),b=Read();
	n=n%500;
	if(n>b) cout<<"No"<<endl;
	else cout<<"Yes"<<endl;
	return 0;
}

Measured memory_bytes: 256
n=int(input())
l=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(l[n-1])

Measured memory_bytes: 3060
n = int(input())
names = {}
for x in 'MARCH':
    names[x] = 0

for _ in range(n):
    s = input()
    if s[0] in 'MARCH' :
        names[s[0]] += 1

ans = 0
for x in 'MARCH' :
    for y in 'MARCH' :
        if x == y:
            continue
        for z in 'MARCH':
            if x == z or y == z :
                continue
            ans += names[x]*names[y]*names[z]

print(ans//6)


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

using ll = int64_t;
#define int ll

#define FOR(i, a, b) for (int i = int(a); i < int(b); i++)
#define REP(i, b) FOR(i, 0, b)
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(x) x.begin(), x.end()

using pi = pair<int, int>;
using vi = vector<int>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  REP(i, (int)v.size()) {
    if (i) os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

ll read() {
  ll i;
  scanf("%" SCNd64, &i);
  return i;
}

void printSpace() { printf(" "); }

void printEoln() { printf("\n"); }

void print(ll x, int suc = 1) {
  printf("%" PRId64, x);
  if (suc == 1) printEoln();
  if (suc == 2) printSpace();
}

string readString() {
  static char buf[3341000];
  scanf("%s", buf);
  return string(buf);
}

char *readCharArray() {
  static char buf[3341000];
  static int bufUsed = 0;
  char *ret = buf + bufUsed;
  scanf("%s", ret);
  bufUsed += strlen(ret) + 1;
  return ret;
}

template <class T, class U>
void chmax(T &a, U b) {
  if (a < b) a = b;
}

template <class T, class U>
void chmin(T &a, U b) {
  if (b < a) a = b;
}

template <class T>
T Sq(const T &t) {
  return t * t;
}

const int mod = 1e9 + 7;

signed main() {
  int n, d;
  cin >> n >> d;
  vector<vi> x(n);
  REP(i, n) {
    REP(j, d) { x[i].PB(read()); }
  }
  auto isInt = [&d](vi &a, vi &b) {
    double sol = 0, tmp;
    REP(i, d) { sol += pow(a[i] - b[i], 2); }
    sol = sqrt(sol);
    if (modf(sol, &tmp) == 0.0)
      return true;
    else
      return false;
  };
  int ans = 0;
  REP(i, n) {
    REP(j, n) {
      if (i >= j) continue;
      if (isInt(x[i], x[j])) ans++;
    }
  }
  print(ans);
}


Measured memory_bytes: 256
#include<stdio.h>

int main()
{
    int A,B;
    scanf("%d %d",&A,&B);

    if((A==1&&B==2)||(A==2&&B==1))
        printf("3");
    else if((A==2&&B==3)||(A==3&&B==2))
        printf("1");
    else
        printf("2");
    return 0;
}


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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define LCM(a, b) (a) / __gcd((a), (b)) * (b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define ln '\n'

using namespace std;
using LL = long long;
using ldouble = long double;
using P = pair<int, int>;
using LP = pair<LL, LL>;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1e9 + 7;
static const int SIZE = 200005;

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

vector<LL> Div(LL n) {
    vector<LL> ret;
    for(LL i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);
            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

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

    int H, W;
    cin >> H >> W;
    int mp[505][505];
    for(int i = 1; i <= H; ++i) {
        for(int j = 1; j <= W; ++j) {
            cin >> mp[i][j];
        }
    }

    vector<pair<P, P>> res;
    for(int i = 1; i <= H; ++i) {
        for(int j = 1; j <= W; ++j) {
            if(mp[i][j] % 2 == 0) continue;
            if(i == H && j == W) continue;
            if(i == H) {
                res.pb(MP(MP(i, j), MP(i, j + 1)));
                mp[i][j + 1]++;
            } else if(j == W) {
                res.pb(MP(MP(i, j), MP(i + 1, j)));
                mp[i + 1][j]++;
            } else {
                if(mp[i][j + 1] % 2 == 1) {
                    res.pb(MP(MP(i, j), MP(i, j + 1)));
                    mp[i][j + 1]++;
                } else {
                    res.pb(MP(MP(i, j), MP(i + 1, j)));
                    mp[i + 1][j]++;
                }
            }
        }
    }

    cout << res.size() << endl;
    for(int i = 0; i < res.size(); ++i) {
        cout << res[i].F.F << " " << res[i].F.S << " " << res[i].S.F << " " << res[i].S.S << endl;
    }

    return 0;
}



Measured memory_bytes: 5232
MOD = 10**9+7
d = dict()
s = int(input())
d[0], d[1], d[2], d[3], d[4], d[5] = 1, 0, 0, 1, 1, 1
def mod(x):
    return (x%MOD + MOD)%MOD

def add(a, b):
    return mod(mod(a) + mod(b))

def ans(n):
    if n in d:
        return d[n]
    else:
        total = 0
        for i in range(3, n+1):
            if n-i>=0:
                # print(i, n-i)
                total = add(total, ans(n-i))
                # print(total)
        d[n] = total
        return d[n]

print(ans(s))




Measured memory_bytes: 9532
# -*- coding: utf-8 -*-
"""
Created on Sun Mar 24 20:45:14 2019

@author: screamLab
"""

n,m = input().split()
s = input()
ans = 0
table = [0]
for i in range(len(s)-1):
    if s[i:i+2] == 'AC':
        ans += 1
    table.append(ans)
        
for i in range(int(m)):
    a,b = input().split()
    a = int(a)
    b = int(b)
    print(table[b-1] - table[a-1])

Measured memory_bytes: 6100
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

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

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

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

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

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

fn gcd(a: usize, b: usize) -> usize {
    if b > a {
        gcd(b, a)
    } else if b == 0 {
        a
    } else if a % b == 0 {
        b
    } else {
        gcd(b, a % b)
    }
}

fn main() {
    input! {
        n: usize,
        a: [usize; n],
    }
    let mut l = Vec::new();
    l.resize(n + 2, 1);
    let mut r = Vec::new();
    r.resize(n + 2, 1);

    l[0] = 0;
    r[n + 1] = 0;
    for i in 1..n + 1 {
        l[i] = gcd(a[i - 1], l[i - 1]);
    }
    for i in (1..n + 1).rev() {
        r[i] = gcd(a[i - 1], r[i + 1]);
    }
    let g = (1..n + 1).map(|i| gcd(l[i - 1], r[i + 1])).max().unwrap();
    println!("{}", g);
}


Measured memory_bytes: 6396
# include <stdio.h>
# include <bits/stdc++.h>
using namespace std;
# define fi cin
# define fo cout
# define x first
# define y second
# define ll long long
# define IOS ios_base :: sync_with_stdio(0);cin.tie(0)
# define p(v) cerr << #v << " = " << v << '\n'
# define p2(v) cerr << #v << " = " << (complex < int > (v.x,v.y)) << '\n'
# define vi vector < int >
# define vll vector < ll >
# define pii pair < int , int >
# define mp make_pair
# define int ll
int32_t main(void)
{
    #ifdef CF
    freopen("input","r",stdin);
    #endif // CF
    srand(time(0));
    fo << fixed << setprecision(7);
    cerr << fixed << setprecision(7);
    static int p[1 << 20];
    int n,m;
    fi>>n>>m;
    static char s[55][55];
    for (int i = 1;i <= n;++i)
        fi>>(s[i] + 1);
    int A = -1,B = -1;
    for (int i = 1;A == -1 && i <= n;++i)
        for (int j = 1;A == -1 && j <= m;++j)
            if (s[i][j] == '#')
            {
                A = i;B = j;
            }
    if (A == -1)
        return puts("Impossible") * 0;
    while (A != n || B != m)
    {
        s[A][B] = '.';
        if (s[A + 1][B] != '#' && s[A][B + 1] != '#')
            return puts("Impossible") * 0;
        if (s[A + 1][B] == '#')
            ++A;
        else
            ++B;
    }
    s[A][B] = '.';
    for (int i = 1;i <= n;++i)
        for (int j = 1;j <= m;++j)
            if (s[i][j] == '#')
                return puts("Impossible") * 0;
    return puts("Possible") * 0;
    cerr << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';
    return 0;
}

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

int main(){
    int n,k,q;
    cin >> n >> k >> q;
    vector<int> A(n,0);
    rep(i,q){
        int a;
        cin >> a;
        a--;
        A.at(a)++;
    }
    rep(i,n){
        if(k-q+A.at(i)>0) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 3772
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cstdlib>
#include <vector>
using namespace std;

#define max(a, b) ((a) > (b) ? (a) : (b))

const int MAX_N = 1010;
int dp[MAX_N][MAX_N];

int solve(char str1[], char str2[]) {
    memset(dp, 0, sizeof(dp));
    int sz1 = strlen(str1);
    int sz2 = strlen(str2);
    for(int i = 1; i <= sz1; ++i) {
        for(int j = 1; j <= sz2; ++j) {
            if(str1[i - 1] == str2[j - 1])
                dp[i][j] = dp[i - 1][j - 1] + 1;
            else
                dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
        }
    }
    return dp[sz1][sz2];
}

int main() {
    int t;
    char str1[MAX_N];
    char str2[MAX_N];
    scanf("%d\n", &t);
    while(t--) {
        gets(str1);
        gets(str2);
        printf("%d\n", solve(str1, str2));  
    }
    return 0;
}

Measured memory_bytes: 5028
import * as fs from 'fs';

//in
//
//out
//
const main = (inp: string) => {
    const a: number = parseInt(inp.split('\n')[0]);
    const s: string = inp.split('\n')[1];

    if (a >= 3200) {
        console.log(s);
    } else {
        console.log('red');
    }

};

main(fs.readFileSync('/dev/stdin', 'utf8').trim());

Measured memory_bytes: 7372
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll MOD=1000000007;
ll n,m,R;
ll r[10];
ll a[20000],b[20000],c[20000];
ll d[205][205];
ll ans=1000000000000000000;
ll p[8];
int main(void){
    cin>>n>>m>>R;
    for(int i=0;i<R;i++){
        cin>>r[i];
    }
    sort(r,r+R);
    for(int i=0;i<205;i++){
        for(int j=0;j<205;j++){
            d[i][j]=1000000000000000000;
            if(i==j){
                d[i][j]=0;
            }
        }
    }
    for(int i=0;i<m;i++){
        cin>>a[i]>>b[i]>>c[i];
        d[a[i]-1][b[i]-1]=c[i];
        d[b[i]-1][a[i]-1]=c[i];
    }
    for(int k=0;k<n;k++){
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
            }
        }
    }
    for(int i=0;i<R;i++){
        p[i]=i;
    }
    do{
        ll C=0;
        for(int i=1;i<R;i++){
            C+=d[r[p[i-1]]-1][r[p[i]]-1];
        }
        /*for(int i=0;i<R;i++){
            cout<<r[p[i]]<<" ";
        }
        cout<<C<<endl;*/
        ans=min(ans,C);
    } while(next_permutation(p,p+R));
    cout<<ans<<endl;
    
}


Measured memory_bytes: 4420
N = int(input())
l = ["AC","WA","TLE","RE"]
ans = [0,0,0,0]
for i in range(N):
    S = input()
    if(S == "AC"):
        ans[0] += 1
    if(S == "WA"):
        ans[1] += 1
    if(S == "TLE"):
        ans[2] += 1
    if(S == "RE"):
        ans[3] += 1

for i in range(4):
    print(l[i], " x ",ans[i])

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


int main() {
    int p[1000], n, m, i, total;

    while (cin) {
        cin >> n >> m;
        if (!n && !m) break;

        for (i = 0; i < n; i++) {
            cin >> p[i];
        }
        sort(p, p+n);

        for (i = 0, total = 0; i < n%m; i++) {
            total += p[i];
        }
        for (; i < n; i++) {
            if (i%m != n%m) {
                total += p[i];
            }
        }
        cout << total << endl;
    }
    return 0;
}

Measured memory_bytes: 1176
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;


public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();

    List<String> list = new LinkedList<>();
    boolean last = true;

    while(sc.hasNext()){
      if(last) {
        list.add(sc.next());
        last = false;
      }else{
        list.add(0,sc.next());
        last = true;

      }

    }

    if (n % 2 == 1){
      Collections.reverse(list);
    }
    System.out.println(String.join(" ", list));

  }
}


Measured memory_bytes: 82000
#define max(a,b)(a=a<b?b:a)
long c,x[1<<17],v[1<<17],ans,L,R,Rmax,Lmax;i;
main(n)
{
	for(scanf("%d%ld",&n,&c);~scanf("%ld%d",x+i,v+i);)L+=v[i++];
	for(;i--;)
	{
		L-=v[i];
		R+=v[i];
		max(ans,L-(i?x[i-1]*2:0)+max(Rmax,R-(c-x[i])));
	}
	for(;i<n;i++)
	{
		L+=v[i];
		R-=v[i];
		max(ans,R-(i!=n-1)*(c-x[i+1])*2+max(Lmax,L-x[i]));
	}
	printf("%ld",ans);
}

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

int N = 1e5 + 1;

int32_t main() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> graph[N];
  for (int i = 2; i <= n; i++) {
    graph[i].emplace_back(i-1, 0);
  }
  for (int i = 0; i < m; i++) {
    int l, r, c;
    cin >> l >> r >> c;
    graph[l].emplace_back(r, c);
  }

  int d[N];
  for (int i = 1; i <= n; i++) d[i] = INT_MAX;

  priority_queue<pair<int, int>> pq;
  pq.emplace(0, 1);

  while (!pq.empty()) {
    int w = -pq.top().first;
    int v = pq.top().second;
    pq.pop();
    if (d[v] == INT_MAX) {
      d[v] = w;
      for (auto child : graph[v]) {
        if (d[child.first] == INT_MAX) {
          pq.emplace(-w - child.second, child.first);
        }
      }
    }
  }

  if (d[n] == INT_MAX) cout << -1;
  else cout << d[n];
}

Measured memory_bytes: 10872