akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(int argc, char const *argv[]){
	ios::sync_with_stdio(0),cin.tie(0);
	ll n, q;
	cin >> n >> q;
	vector < pair <ll, pair <ll, ll> > > block;
	for(ll i = 0; i < n; i++){
		ll s, t, x;
		cin >> s >> t >> x;
		block.push_back(make_pair(x, make_pair(s, t)));
	}
	vector <pair <int, int> > points;
	for(int i = 0; i < n; i++){
		points.push_back(make_pair(block[i].second.first - block[i].first, i));
		points.push_back(make_pair(block[i].second.second - block[i].first, i));
	}
	for(int i = 0; i < q; i++){
		int foo; cin >> foo;
		points.push_back(make_pair(foo, -1));
	}
	sort(points.begin(), points.end());

	set <int> cur; bool active[n] = {0}; map <int, int> counter;
	int query; bool proc = 0;
	for(auto it: points){
		if(proc and query != it.first){
			if(cur.empty())
				cout << -1 << "\n";
			else
				cout << *cur.begin() << "\n";
			proc = 0;
		}
		if(it.second != -1){
			int loc = block[it.second].first;
			if(!active[it.second]){
				cur.insert(loc);
				counter[loc] = !counter.count(loc) ? 1 : counter[loc] + 1;
				active[it.second] = 1;
			}
			else if(active[it.second]){
				counter[loc]--;
				if(!counter[loc])
					cur.erase(loc);
				active[it.second] = 0; 
			}
		}
		else if(it.second == -1){
			proc = 1;
			query = it.first;
		}
	}
	if(proc)
		cout << -1 << "\n";
	return 0;
}

Measured memory_bytes: 31336
A, B, M = map(int, input().split())
x, y, c = [0] * M, [0] * M, [0] * M
a = list(map(int, input().split()))
b = list(map(int, input().split()))
for i in range(M):
    x[i], y[i], c[i] = map(int, input().split())
ans, sav = float("inf"), 0
for j in range(M):
    sav = a[x[j] - 1] + b[y[j] - 1] - c[j]
    if ans > sav:
        ans = sav

print(min(ans, min(a) + min(b)))


Measured memory_bytes: 24164
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<vector>
#include<cmath>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define scan(arg) cin>>arg
#define prin(arg) cout<<arg<<"\n"
#define prin2(arg1,arg2) cout<<arg1<<" "<<arg2<<"\n"
using namespace std;
typedef long long ll;
const int NMAX=1<<17;
string s;
int x,y;
vector<int> dx,dy;
bool dpx[4010][8010],dpy[4010][8010];
int main(){
  scan(s);scan(x);scan(y);
  int sx=0;
  while(s[sx]=='F') sx++;
  int c=-1,cnt=0;
  for(int i=sx+1;i<s.size();i++){
    if(s[i]=='F'){
      cnt++;
    }
    else{
      if(cnt>0&&c<0){
	dy.push_back(cnt);
      }
      else if(cnt>0&&c>0){
	dx.push_back(cnt);
      }
      c*=-1;
      cnt=0;
    }
  }
  if(cnt>0&&c<0){
    dy.push_back(cnt);
  }
  else if(cnt>0&&c>0){
    dx.push_back(cnt);
  }
  int xsum=0;
  rep(i,dx.size()){
    xsum+=dx[i];
  }
  int ysum=0;
  rep(i,dy.size()){
    ysum+=dy[i];
  }
  memset(dpx,0,sizeof(dpx));
  memset(dpy,0,sizeof(dpy));
  dpx[0][0]=1;
  dpy[0][0]=1;
  rep1(i,dx.size()){
    rep(j,xsum+1){
      if(dpx[i-1][abs(j-dx[i-1])]==1||dpx[i-1][j+dx[i-1]]==1){
	dpx[i][j]=1;
      }
    }
  }
  rep1(i,dy.size()){
    rep(j,ysum+1){
      if(dpy[i-1][abs(j-dy[i-1])]==1||dpy[i-1][j+dy[i-1]]==1){
	dpy[i][j]=1;
      }
    }
  }
  if(dpx[dx.size()][abs(x-sx)]==1&&dpy[dy.size()][abs(y)]==1){
    prin("Yes");
  }
  else prin("No");
  /* rep(i,dx.size()+1){
    rep(j,xsum+1){
      cout<<dpx[i][j]<<" ";
    }
    cout<<"\n";
    }*/

  
  
  
  return 0;
}


Measured memory_bytes: 62976
#include<bits/stdc++.h>
using namespace std;
const int C = 31, N = 521;
int d[C][C];
int g[3][C];
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n,c;
    cin >> n >> c;
    for (int i = 1; i <= c; ++i)
        for (int j = 1; j <= c; ++j)
            cin >> d[i][j];
    for (int i = 1; i <= n; ++i)
        for (int j = 1; j <= n; ++j) {
            int a;
            cin >> a;
            ++g[(i+j)%3][a];
        }
    int w[3];
    int ans = 2e9;
    for (w[0] = 1; w[0] <= c; ++w[0])
        for (w[1] = 1; w[1] <= c; ++w[1]) if (w[1] != w[0])
            for (w[2] = 1; w[2] <= c; ++w[2]) if (w[2] != w[0] && w[2] != w[1]) {
                int s = 0;
                for (int x = 0; x < 3; ++x)
                    for (int i = 1; i <= c; ++i)
                        s += d[i][w[x]] * g[x][i];
                ans = min(ans, s);
            }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <fstream>

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

template<class T> inline T abs(T X) {
    return X > 0 ? X : -X;
}

template<class T> inline T min(T X, T Y) {
    return X < Y ? X : Y;
}

void solve() {
    long n, k; cin >> n >> k;
    n %= k;
    long x = abs(n - k);
    cout << min(n, x) << endl;
}

int main() {

#ifdef DEV
    std::ifstream in("AtCoder/ABC161/Replacing Integer.input");
    cin.rdbuf(in.rdbuf());

    int t; cin >> t;
    for (int x = 1; x <= t; ++x) {
        solve();
    }
#else
    solve();
#endif

    return 0;
}


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

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

#define vt          vector
#define sz(x)       (int)(x).size()
#define all(x)      (x).begin(), (x).end()
#define rall(x)     (x).rbegin(), (x).rend()
#define fi          first
#define se          second

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

    int n;
    cin >> n;
    vt<int> a(n);
    for (int &i : a) cin >> i;

    int cur = a[0];
    for (int i = 1; i < n; i++) {
        cur = __gcd(cur, a[i]);
    }

    if (cur != 1) return cout << "not coprime", 0;

    a.erase(remove(all(a), 1), a.end());
    n = sz(a);

    if (n > 8e4) return cout << "setwise coprime", 0;
    
    set<int> primes;
    for (int i : a) {
        for (int j = 2; j * j <= i; j++) {
            if (i % j == 0) {
                if (primes.count(j)) return cout << "setwise coprime", 0;
                primes.insert(j);
                i /= j;
                while (i % j == 0) i /= j;
            }
        }

        if (i != 1) {
            if (primes.count(i)) return cout << "setwise coprime", 0;
            primes.insert(i);
        }
    }

    cout << "pairwise coprime";
}


Measured memory_bytes: 7332
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> pip;
const ll INF = 1ll<<29;
const ll MOD = 1000000007;
const double EPS  = 1e-10;
const bool debug = 0;
//----------------------//

map<char, char> mm;

int main() {
	mm['b'] = 'd';
	mm['d'] = 'b';
	mm['p'] = 'q';
	mm['q'] = 'p';
	
	string s;
	cin >> s;
	
	string ans = "";
	REP(i, s.size()) ans += mm[s[i]];
	reverse(ALL(ans));
	
	puts(ans == s ? "Yes" : "No");
	return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<complex>
#include<algorithm>
using namespace std;
typedef long long int llint;
int main() {
	double n, t, a;
	cin >> n >> t >> a;
	double x;
	vector<double>h(n);
	for (int i = 0;i < n;i++) {
		cin >> x;
		h[i] = t - x * 0.006;
		h[i] = abs(a - h[i]);
	}
	double anss = 1000000;
	double ans;
	for (int i = 0;i < n;i++) {
		if (h[i] < anss) {
			anss = h[i];
			ans = i;
		}
	}
	cout << ans + 1 << endl;
	return 0;
}

Measured memory_bytes: 256
import java.io.*;

class Main{
 public static void main(String[] args)throws IOException{
  double r;
  String area,rect;
   BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
  
   String str = br.readLine(); 
   String[] strAry = str.split(" ");
   r = Double.parseDouble(strAry[0]);  
   area=String.format("%.5f", r*r*3.141592653589);    
   rect=String.format("%.5f", 2*r*3.141592653589);    
   
   System.out.println(area + " "+ rect); 
 }
}

Measured memory_bytes: 24716
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <cstring>
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <list>  
#include <cassert>
#include <ctime>
#include <climits>
using namespace std;  

#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }

const int MAXN=100000;
const int MAXLENSUM=100000;
const int MAXNODE=1+MAXLENSUM;
typedef struct Z { int c[2]; bool isleaf; } Z;

int n; ll dmx;
char s[MAXLENSUM+1];
Z z[MAXNODE]; int nz;
int addnode() { int ret=nz++; z[ret].c[0]=z[ret].c[1]=-1,z[ret].isleaf=false; return ret; }

ll dfs(int at,int d) {
	if(z[at].isleaf) return 0;
	ll ret=0;
	REP(x,2) {
		if(z[at].c[x]==-1) {
			ll rem=dmx-d;
			int idx=0; while((rem&(1<<idx))==0) ++idx; ret^=1LL<<idx;
		} else {
			ret^=dfs(z[at].c[x],d+1);
		}
	}
	return ret;
}

//const int DMX=(1<<6)-1;
//int dp[DMX+1];
//int mex[DMX+1];

void run() {
	scanf("%d%lld",&n,&dmx);
	nz=0; int rt=addnode();
	REP(i,n) { scanf("%s",s); int at=rt; for(int j=0;s[j]!='\0';++j) { int x=s[j]-'0'; if(z[at].c[x]==-1) z[at].c[x]=addnode(); at=z[at].c[x]; } z[at].isleaf=true; }
	ll ret=dfs(rt,0);
	printf("%s\n",ret==0?"Bob":"Alice");

	/*dp[0]=0; memset(mex,-1,sizeof(mex));
	FORE(i,1,DMX) {
		int cur=0;
		for(int j=i-1;j>=0;--j) { 
			//printf("%d %d: %d\n",i,j,cur);
			mex[cur]=i; cur^=dp[j];
		}
		dp[i]=0; while(dp[i]<DMX&&mex[dp[i]]==i) ++dp[i];
		printf("%d=%d\n",i,dp[i]);
	}*/
}

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


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

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

int main(){
    long long int n,ans=0,m=0;
    cin>>n;
    vector<long long int>t(10000);
    for(int i=0;i<n;i++){
        cin>>t[i];
    }
    sort(t.begin(),t.end(),greater<>());
    ans=t[0];
    for(int i=1;i<n;i++){
        m=gcd(ans,t[i]);
        ans=(ans/m)*t[i];
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 384
#include<cstdio>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<cstdlib>
#include<bitset>
#include<utility>
#include<sstream>
#include<iomanip>
using namespace std;

#define ll long long
#define MP make_pair

int main(void) {

	 int x,a;
	 cin>>x>>a;

	 if(x<a)cout<<"0\n";
	 else cout<<"10\n";

	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <limits.h>
#include <math.h>

typedef struct tuple_t {
    int b, c;
} tuple;

int qsort_int(const void *a, const void *b)
{
    return *(int *)a - *(int *)b;
}

int qsort_tuple_c_rev(const void *a, const void *b)
{
    return (*(tuple *)b).c - (*(tuple *)a).c;
}

int main(int argc, char *argv[])
{
    int n, m;
    int a[100000];
    tuple t[100000];
    int i, p;
    long long ans;

    scanf("%d %d", &n, &m);

    for (i = 0; i < n; i++) {
        scanf("%d", &a[i]);
    }
    for (i = 0; i < m; i++) {
        scanf("%d %d", &t[i].b, &t[i].c);
    }

    qsort(a, n, sizeof(int), qsort_int);
    qsort(t, m, sizeof(tuple), qsort_tuple_c_rev);

    p = 0;
    for (i = 0; i < m; i++) {
        if (p >= n) {break;}
        if (a[p] >= t[i].c) {break;}
        while(t[i].b) {
            if (a[p] >= t[i].c) {break;}

            a[p] = t[i].c;

            t[i].b--;
            p++;
        }
    }

    // sum
    ans = 0;

    for (i = 0; i < n; i++) {
        ans += a[i];
    }

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

    return 0;
}


Measured memory_bytes: 2164
import collections
N = int(input()) 
S = [0]*N
for i in range(N):
    S[i] = input()
c = collections.Counter(S)
values,counts = zip(*c.most_common())
m = 0
for j in range(1,len(values)):
    if len(values) == 1:
        break
    if counts[j-1] != counts[j]:
        break
    m+=1
common = []
for n in range(m+1):
    common.append(values[n])
new = sorted(common)
for u in range(m+1):
    print(new[u])

Measured memory_bytes: 59492
//A.cpp
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <math.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

void swap (int *x, int *y) {
  int temp;    // 値を一時保存する変数

  temp = *x;
  *x = *y;
  *y = temp;
}

/* pushdouwn操作 */
void pushdown (int array[], int first, int last) {
  int parent = first;   // 親
  int child = 2*parent;   // 左の子
  while (child <= last) {
    if ((child < last) && (array[child] < array[child+1])) {
       child++;   // 右の子の方が大きいとき、右の子を比較対象に設定
    }
    if (array[child] <= array[parent]) { break; }   // ヒープ済み
    swap(&array[child], &array[parent]);
    parent = child;
    child = 2* parent;
  }
}

/* ヒープソート */
void heap_sort (int array[], int array_size) {
  int i;

  for (i = array_size/2; i >= 1; i--) {
    pushdown(array, i, array_size);   // 全体をヒープ化
  }
  for (i = array_size; i >= 2; i--) {
    swap(&array[1], &array[i]);   // 最大のものを最後に
    pushdown(array, 1, i-1);   // ヒープ再構築
  }
}

int main(){
  int n,m;
  cin >> n >> m;
  int A[n+1];
  rep(i,n) cin >> A[i+1];
  for (int i = n/2; i >= 1; i--) {
    pushdown(A, i, n);   // 全体をヒープ化
  }
  // rep(i,n){
  //   printf("%d\n", A[i+1]);
  // }
  rep(i,m){
    A[1] /= 2;
    pushdown(A,1,n);
  }
  long long ans = 0;
  rep(i,n){
    ans += (long long) A[i+1];
    // printf("%d\n", A[i+1]);
  }
  printf("%lld\n", ans);
  return 0;

}


Measured memory_bytes: 640
X, Y, A, B, C = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))
p = sorted(p, reverse=True)
q = sorted(q, reverse=True)
new_arr = p[:X] + q[:Y] + r
new_arr = sorted(new_arr, reverse=True)
print(sum(new_arr[:X+Y]))

Measured memory_bytes: 109984
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define ll long long
#define ld long double
#define fastio ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define pb push_back
#define pf push_front
#define mp make_pair
#define mod 1000000007
#define vll vector<ll>
#define inf 1e12
#define pll pair<ll,ll>
#define ff first 
#define ss second 
#define PI acos(-1)
#define prm 998244353
#define endl '\n'
using namespace std;
using namespace __gnu_pbds; 
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
//cout << fixed << setprecision(0)
/*
ll power(ll x,ll y)
{
	ll res=1;
	while(y>0)
	{
		if(y%2==1)res=(res*x)%mod;
		y=y/2;
		x=(x*x)%mod;
	}
	return res;
}
ll inv(ll a) 
{
return power(a,mod-2);
}
 
ll fact[2000007];
ll inr[2000007];
void pre()
{
	fact[0]=1;
	for(ll i=1;i<=2000005;i++)fact[i]=(fact[i-1]*i)%mod;
	inr[0]=1;
	for(ll i=1;i<=2000005;i++)inr[i]=inv(fact[i]);
}
 
ll ncr(ll n,ll r)
{
	ll a=(fact[n]*inr[r])%mod;
	ll b=(a*inr[n-r])%mod;
	return b;
}
 
ll spf[10000050];
void sieve()
{
	for(ll i=2;i*i<=10000030;i++)
	{
		if(spf[i]==0)
		{
			for(ll j=i+i;j<=10000030;j+=i)
			{
				if(spf[j]==0)
				{
					spf[j]=i;
				}
			}
		}
	}
}
*/

int main()
{
    fastio; 
    //sieve();
    //pre();
    ll T=1;
    //cin>>T;  
    while(T--)
    {
    int n, k;
    cin >> n >> k;
  	vll p(n), c(n);
  	for(ll i=0;i<n;i++) 
	{
    cin >> p[i];
    p[i]--;
  	}
 
  	for(ll i=0;i<n;i++) cin >> c[i];
 
  	ll ans = -1e18;
  	ll vis[n];
  	for(ll i=0;i<n;i++)vis[i]=0;
  	for(ll si=0;si<n;si++)
	{
	//if(vis[si]==1)continue;
    ll x = si;
    vll s;
    ll total = 0;
    while (1) 
	{
      total += c[x];
      s.pb(c[x]);
      vis[x]=1;
      x = p[x];
      if (x == si) break;
    }
    
    ll cur = 0;
    int m = s.size();
    for(ll i=0;i<m;i++)
	{
      if (i + 1 > k) break;
      cur += s[i];
      ll t = cur;
      if (total > 0) 
	  t += ((k - (i + 1)) / m) * total;
      ans = max(ans, t);
    }
  	} 
  	cout << ans << endl;
	}
}

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

int main() {
  string str;
  cin >> str;
  string ans;
  for (unsigned int i=0; i<str.length(); i++) {
    if (str[i] == 'A') {
      for (unsigned int j=str.length()-1; i<j; j--) {
        if (str[j] == 'Z') {
          ans = str.substr(i, j-i+1);
          //cout << ans << endl;
          break;
        }
      }
      break;
    }
  }

  cout << ans.size() << endl;

  return 0;
}


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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
typedef long long ll;


int main() {
    int N; cin >> N;
    double T,A; cin >> T >> A;

    double dist = INF;
    int itr = 0;
    REP(i,N){
        double h; cin >> h;
        if(dist > abs(T-h*0.006 - A)){
            dist = abs(T-h*0.006 - A);
            itr = i+1;
        }
    }

    cout << itr << endl;
    return 0;
}

Measured memory_bytes: 3704
#include "bits/stdc++.h"
using namespace std;
int main(){
    int n,a,b,i;
    cin >> n >> a >> b;
    string s;
    cin >> s;
    char c;
    int pa=0,fo=0;
    for(i=0;i<n;i++){
        c = s.at(i);
        if(c == 'a'){
            if(pa<a+b){
                cout << "Yes" << endl;
                pa++;}
            else cout << "No" << endl;
        }else if(c == 'b'){
            if(pa<a+b && fo<b){
                cout << "Yes" << endl;
                pa++; fo++;
        }
            else cout << "No" << endl;
        }else{
            cout << "No" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 896
//i ll be the king
#include<bits/stdc++.h>
#define ll long long int
#define ld long double
#define sync ios_base::sync_with_stdio(false); cin.tie(NULL) 
#define input(arr,n) for(ll i1=0;i1<n;i1++ )cin>>arr[i1]
#define rep(n) for(ll i2=0;i2<n;i2++)
#define vmp(v,a,b) v.push_back(make_pair(a,b))
#define si(a) scanf("%lld",&a)
#define pi(a) printf("%lld",a)
#define aset(a,n,k) for(ll i3=0;i3<n;i3++)a[i3]=k; 	
#define mod 1000000007
#define mp(a,b) make_pair(a,b)
#define f first
#define s second 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type,greater_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>//s.order_of_key(val) *s.find_by_orde(ind)
using namespace std;
ll manhattan(ll n)
{
	ll ans=0;
	for(ll i=1;i<=n;i++)
	{
		ans+=(i*(i-1))/2;
		ans%=mod;
		
	}
 	return ans;
}
ll modexp(ll a,ll b)
{
	if(a==0)return 0;
	if(b==0)return 1;
	if(a==1)return 1;
	if(b%2==0)
	{
		ll val=modexp(a,b/2);
		return(val*val)%mod;
	}
	return (a*modexp(a,b-1))%mod;
}
int main()
{
	sync;
	ll n,m,k;
	cin>>n>>m>>k;
	ll dis=(manhattan(n)*(m*m)%mod+manhattan(m)*(n*n)%mod)%mod;
	ll invf[n*m],fact[n*m];
	invf[0]=invf[1]=fact[0]=fact[1]=1;
	for(ll i=2;i<=n*m;i++)
	invf[i]=(invf[i-1]*modexp(i,mod-2))%mod,
	fact[i]=(fact[i-1]*i)%mod;
	ll ncr=(invf[k-2]*invf[n*m-k])%mod;
	ncr=(ncr*fact[n*m-2])%mod;
	//cout<<dis<<" "<<ncr<<"  "<<manhattan(n)<<" "<<fact[n*m-2]<<" "<<invf[k-2]<<" "<<invf[n*m-k]<<endl;
	cout<<(ncr*dis)%mod;
}
	


Measured memory_bytes: 3328
import java.util.*;
public class Main
{
	public static void main(String arg[])
	{
		Scanner in=new Scanner(System.in);
		for(;;)
		{
			char ch[]=in.nextLine().toCharArray(); 
			if(ch[0]=='.')
				return;
			Stack<Character> st=new Stack<Character>();
			String ans="yes";
			for(int i=0;i<ch.length;i++)
			{
				if(ch[i]=='(')
					st.push(ch[i]);
				if(ch[i]=='[')
					st.push(ch[i]);
				if(ch[i]==')')
				{
					if(st.empty())
						ans="no";
					else if(st.get(st.size()-1)!='(')
						ans="no";
					else
						st.pop();
				}
				if(ch[i]==']')
				{
					if(st.empty())
						ans="no";
					else if(st.get(st.size()-1)!='[')
						ans="no";
					else
						st.pop();
				}
				if(ans.equals("no"))
					break;
			}
			if(!st.empty())
				ans="no";
			System.out.println(ans);
		}
	}
}

Measured memory_bytes: 12000
n = int(input())
b = list(map(int,input().split()))

a = [0 for _ in range(n)]
a[0] = b[0]
for i in range(1,n-1):
    a[i] = min(b[i-1], b[i])
a[n-1] = b[n-2]

print(sum(a))


Measured memory_bytes: 3060
A, B, C, D = map(int,input().split())
c = B//C-A//C + (A%C == 0)
d = B//D-A//D + (A%D == 0)
def gcd(a,b):
    if b == 0:
        return a
    return gcd(b,a%b)
def lcm(a,b):
    return a*b//gcd(a,b)
E = lcm(C,D)
e = B//E-A//E + (A%E == 0)
print(B-A+1-c-d+e)


Measured memory_bytes: 61964
#include<bits/stdc++.h>
#define ll long long int
#define pii pair<int,int >
#define F first
#define S second
#define mod 1000000000

/// cout <<"Case #"<<it<<": ";
using namespace std;
bool solve(string s,string t){
    for(int i=0;i<s.size();i++){
        if(s[i]!=t[i]) return false;
    }
    return true;
}
int main()
{   ios_base::sync_with_stdio(false);
    cin.tie(NULL);


    ll a ,b,c,k;
    cin>> a >> b >> c >>k;
    ll curr=a+b;ll sum=min(a,k);
    if(curr<k){
        sum=(ll)sum-k+curr;
    }
    cout << sum << endl;
    return 0;
}


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

using namespace std;
#define int long long
signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n, x, m;
	cin >> n >> x >> m;
	vector<int>r;
	map<int, int>ar;
	int cur = 0;
	for (int i = 0; i < min(n, 200000ll); i++) {
		r.push_back(x);
		if (ar.find(x) != ar.end()) {
			int j = ar[x];
			int d = i - ar[x];
			int vv = 0;
			for (int q = j; q < i; q++) {
				vv += r[q];
			}
			cur += vv * ((n - i) / d);
			for (int q = j; q < j + (n - i) % d; q++) {
				cur += r[q];
			}
			cout << cur;
			return 0;
		}
		cur += x;
		ar[x] = i;
		x = (x * x) % m;
	}
	int ans = 0;
	for (int i = 0; i < n; i++) {
		ans += r[i];
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 6588
#include <iostream>
#include <string>
#include <cstring>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
#include <fstream>
#include <unordered_set>

using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD 1000000007
#define P pair<ll, ll>

ll powmod(ll a, ll b) {
	a %= MOD;
	ll res = 1;
	while (b > 0) {
		if (b % 2 == 1)res = res * a % MOD;
		a = a * a % MOD;
		b /= 2;
	}
	return res;
}

ll f[3100000];
void cominit() {
	f[0] = 1;
	REP(i, 2100000)f[i + 1] = f[i] * (i + 1) % MOD;
}

ll com(ll n, ll r) {
	return f[n] * powmod(f[r] * f[n - r], MOD - 2) % MOD;
}

ll perm(ll n, ll r) {
	return f[n] * powmod(f[n - r], MOD - 2) % MOD;
}
ll t(ll a, ll b) {
	return (com(a + b + 2, a + 1) - 1 + MOD) % MOD;
}
int main() {
	cominit();
	ll a1, b1, a2, b2;
	cin >> a1 >> a2 >> b1 >> b2;
	cout << (t(b1, b2) - t(a1 - 1, b2) - t(b1, a2 - 1) + t(a1 - 1, a2 - 1) + MOD * 2) % MOD << endl;
}



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

//C++14 (GCC 5.4.1)

#define LLINF (1LL<<60)
typedef long long ll;
#define mod 1000000007

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define rrepd(i,a,b) for(int i=(a);i>=(b);i--)

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

template<typename T> inline T divrup(T a, T b) { if (a % b) return a/b+1; else return a/b;}
template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); }

#define dbg_v1(i,V) do{cout<<"-v1----\n";rep(i,V.size())cout<<" "<<i<<"\t:"<<V[i]<<endl;cout<<endl;}while(0)
#define dbg_v2(i,k,V) do{cout<<"-v2----\n";rep(i,V.size()){rep(k,V[0].size())cout<<" "<<V[i][k];cout<<endl;}}while(0)

int main() {
    ios::sync_with_stdio(false);//stdoutとcoutの同期解除
    cin.tie(nullptr);//cinとcoutの同期解除
    
    string s,t;
    cin >>s>>t;
    vector<vector<int>> dp(3001,vector<int>(3001,0));
    int ss=s.size(),ts=t.size();
    rep(i,ss)rep(k,ts){
        if(s[i]==t[k]) chmax(dp[i+1][k+1],dp[i][k]+1);
        chmax(dp[i+1][k+1],dp[i + 1][k]);
        chmax(dp[i+1][k+1],dp[i][k + 1]);
    }
    string ans="";
    int d = dp[ss][ts];
    while(true){
        if(d==0)break;
        if(dp[ss-1][ts]==d)ss--;
        else if(dp[ss][ts-1]==d)ts--;
        else {
            ans = s[ss-1] + ans;
            ss--,ts--,d--;
        }
    }

    cout << ans <<endl;
    return (0);
}

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

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String N = sc.next();
		boolean seven = false;
		for(int i = 0; i < N.length(); i++)
			if(N.charAt(i)=='7')
				seven = true;
		System.out.println(seven ? "Yes" : "No");
	}

}


Measured memory_bytes: 35624
#include "bits/stdc++.h"
#define rep(i,a,n) for(int i = a;i < n;i++)
#define INF 1e9
typedef unsigned long long ull;
typedef long long ll;
using namespace std;

int main(){
    
    ll h,w;
    cin >> h >> w;
    ll cells[h][w];
    ll dp[h][w][h*w];
    
    rep(i,0,h){
        rep(j,0,w){
            cin >> cells[i][j];
            rep(k,0,h*w) dp[i][j][k] = INF;
            
        }
    }
    
    dp[0][0][0] = 0;
    rep(k,0,h*w-1){
      rep(i,0,h){
          rep(j,0,w){
            
                if(i > 0)dp[i][j][k+1] = min(dp[i][j][k+1],dp[i-1][j][k]+cells[i][j]*(k*2+1));
                if(i < h-1)dp[i][j][k+1] = min(dp[i][j][k+1],dp[i+1][j][k]+cells[i][j]*(k*2+1));
                if(j > 0)dp[i][j][k+1] = min(dp[i][j][k+1],dp[i][j-1][k]+cells[i][j]*(k*2+1));
                if(j < w-1)dp[i][j][k+1] = min(dp[i][j][k+1],dp[i][j+1][k]+cells[i][j]*(k*2+1));
            }
        }
    }
    ll memo = INF;
    
    rep(i,0,h*w){
        memo = min(memo,dp[h-1][w-1][i]);
    }
    
    cout << memo << endl;
    return 0;
}



Measured memory_bytes: 9416
import java.awt.*;
import java.awt.geom.*;
import java.io.*;

import java.util.*;
class Main {
	

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String tar = sc.next().toLowerCase();
		int count = 0;
		while(true) {
			String tmp = sc.next();
			if(tmp.equals("END_OF_TEXT")) break;
			if(tar.equals(tmp.toLowerCase())) {
				count++;
			}
		}
		System.out.println(count);
	}
}

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

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

  int sum = 0;
  for (int i=0; i<100; i++){
    sum += A;
    if (sum % B == C){
      cout << "YES" << endl;
      return 0;
    }
    sum %= B;
  }
  cout << "NO" << endl;
}


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

using namespace std;

int main(){
    int Q,H,S,D,N;
    long long int ans=0;
    cin >> Q >> H >> S >> D;
    cin >> N;
    while(N != 0){
        if(1<N){
            ans += min({Q*8,H*4,S*2,D});
            N -= 2;
        }else{
            ans += min({Q*4,H*2,S});
            N -= 1;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
// A - Meal Delivery

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

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

	string ans;

	if (abs(x - a) < abs(x - b)) ans = "A";
	else ans = "B";

	cout << ans << endl;

	return 0;
}

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

int main() {
	int a, v, b, w; cin >> a >> v >> b >> w;
	int t; cin >> t;
	if (((long long)v - w) * t >= abs(a - b)) cout << "YES\n";
	else cout << "NO\n";
	return 0;
}


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

int main()
{
ll int m1,m2 ,d1,d2,l=0;
cin>>m1>>d1;
cin>>m2>>d2;
if(m1==1 || m1==3 || m1==5 ||m1==7 || m1==8 ||m1==10 || m1==12)
{
    if(d1==31)
    {
       l=-1;
    }
    else
    {
        l=-2;
    }
}
else
{
    if(d1==30)
    {
        l=-1;
    }
    else
    {
       l=-2;
    }
    if(m1==2)
    {
        if(d1==28)
        {
            l=-1;
        }
        else
        {
            l=-2;
        }
    }
}


if(l==-1)
{
     cout<<"1"<<endl;
}
else
{
     cout<<"0"<<endl;
}
return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int a[n+1];
	a[0]=0;
	int s=0;
	for(int i=1; i<=n; i++){
		cin>>a[i];
		if(a[i]>a[i-1])  s+=a[i]-a[i-1];
	}
	cout<<s;
}

Measured memory_bytes: 256
import sys
fin = sys.stdin.readline


class SegmentTree(object):
    INT_MAX = (1 << 31) - 1

    def __init__(self, n_):
        n = 1
        while n < n_:
            n *= 2
        self._tree = [self.INT_MAX] * (n * 2 - 1)
        self.num_elems = n


    def update(self, k, a):
        # accessing the index corresponding to the leaf
        k += self.num_elems - 1
        self._tree[k] = a

        # climbing up
        while k > 0:
            k = (k - 1) // 2
            self._tree[k] = min(self._tree[k * 2 + 1], self._tree[k * 2 + 2])
        # print(self._tree)

    def query(self, a, b, k, l, r):
        if r <= a or b <= l:
            return self.INT_MAX
        
        if (a <= l and r <= b):
            return self._tree[k]
        else:
            m = (l + r) // 2
            vl = self.query(a, b, 2 * k + 1, l, m)
            vr = self.query(a, b, 2 * k + 2, m, r)
            # print(vl, vr)
            return min(vl, vr)
    

n, q = [int(elem) for elem in fin().split()]
segtree = SegmentTree(n)

ceil_exp_2 = 1
while ceil_exp_2 < n:
    ceil_exp_2 *= 2

queries = tuple(tuple(int(elem) for elem in fin().split()) for _ in range(q))

for c, x, y in queries:
    if c == 0:
        segtree.update(x, y)
    else:
        print(segtree.query(x, y + 1, 0, 0, ceil_exp_2))



Measured memory_bytes: 22648
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
using namespace std;

int main()
{
	string s;
	cin >> s;

	auto left = -1;
	auto right = -1;
	for (auto c = 'a'; c <= 'z'; ++c)
	{
		for (auto i = 0; i < s.length(); ++i)
		{
			if (s[i] == c)
			{
				if (left < 0)
				{
					left = i;
				}
				else if (right < 0)
				{
					if (i - left <= 2)
					{
						right = i;
						break;
					}
					else
					{
						left = i;
					}
				}
			}
		}

		if (left >= 0 && right >= 0)
		{
			++left;
			++right;
			break;
		}
		else
		{
			left = -1;
			right = -1;
		}
	}

	cout << left << " " << right << endl;

	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int test[213456];
int main() {
	long long n, k, sum = 0, num = 1234567891230, a = 0; cin >> n;
	for(int h=0;h<n;h++){
      cin>>k;sum+=k;test[h]=k;
    }
    for(int h=0;h<n;h++){
       num = min(abs(a-(sum - a)), num);
       a+=test[h];
    }
    cout<<num<<endl;
	return 0;
}

Measured memory_bytes: 1024
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]
k=int(input())
print(l[k-1])


Measured memory_bytes: 38384
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define mp make_pair
#define pb(x) push_back(x)
#define vll vector<long long>
#define pll pair<long long, long long>
#define mll map<long long, long long>
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
#define gcd __gcd
#define clr(x) memset(x, 0, sizeof(x))
#define mod 1000000007LL
#define mod2 998244353LL
#define INF 1e18
 

typedef long long ll;
typedef long double ld;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> o_tree;

const int N = 2e5 + 6;
ll lo[4 * N + 1], hi[4 * N + 1], delta[4 * N + 1], mini[4 * N + 1];

// change update and rmq according to question

void buildSeg(ll node, ll l, ll r)
{
  lo[node]=l;
  hi[node]=r;
  if (l == r)
  {
    return;
  }
  ll mid = l+(r-l)/2;
  buildSeg(2*node+1,l,mid);
  buildSeg(2*node+2,mid+1,r);
}

void prop(ll i)
{
  delta[2*i+1]+=delta[i];
  delta[2*i+1]%=mod2;
  delta[2*i+2]+=delta[i];
  delta[2*i+2]%=mod2;
  delta[i]=0;
}


void update(ll i)
{
  mini[i]= mini[2*i+1]+delta[2*i+1]+mini[2*i+2]+delta[2*i+2];
  mini[i]%=mod2;
}

void increment(ll i,ll l,ll r,ll val)
{
   if(r<lo[i]||l>hi[i])
   {
      return;
   }
   if(l<=lo[i]&&r>=hi[i])
   {
     delta[i]+=val;
     delta[i]%=mod2;
     return;
   }
   prop(i);

   increment(2*i+1,l,r,val);
   increment(2*i+2,l,r,val);
   update(i);
}

ll rmq(ll i,ll l,ll r)
{
   if(r<lo[i]||l>hi[i])
   {
     return 0;
   }
   if(l<=lo[i]&&r>=hi[i])
   {
     return (mini[i]+delta[i])%mod2;
   }
   prop(i);
   ll lefmin=rmq(2*i+1,l,r);
   ll rigmin=rmq(2*i+2,l,r);
   update(i);
   return ((lefmin)+(rigmin))%mod2;
}


void solve()
{
    ll n,k;
    cin>>n>>k;
    ll i,j;
    ll a[k][2];
    for(i=0;i<k;i++)
    {
       ll l,r;
       cin>>l>>r;
       a[i][0]=l;
       a[i][1]=r;
    }

    buildSeg(1,1,n);
    increment(1,1,1,1);
    for(i=1;i<=n;i++)
    {
        for(j=0;j<k;j++)
        {
           ll val = rmq(1,i,i);
        //    cout<<val<<" "<<a[j][0]<<" "<<a[j][1]<<"\n";
           increment(1,i+a[j][0],i+a[j][1],val);
        }
    }
    ll ans = rmq(1,n,n);
    cout<<ans<<"\n";
}


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


if (fopen("input.txt","r" ))
  {
     freopen("input.txt", "r", stdin);
     freopen("output.txt", "w", stdout);
  }
cout<<setprecision(20);


ll t=1;


// cin>>t;


while(t--)
{
solve();
} 


return 0;
}

Measured memory_bytes: 18176
package main

import (
	"bufio"
	"os"
	"strconv"
	"strings"
	"fmt"
)

var scanner = bufio.NewScanner(os.Stdin)

func main() {
	scanner.Scan()
	n, _ := strconv.Atoi(scanner.Text())
	for i := 0; i < n; i++ {
		scanner.Scan()
		input := strings.Split(scanner.Text(), " ")
		buf := make([]float64, len(input))
		for j := range buf {
			buf[j], _ = strconv.ParseFloat(input[j], 64)
		}
		p1 := complex(buf[0], buf[1])
		p2 := complex(buf[2], buf[3])
		p3 := complex(buf[4], buf[5])
		pk := complex(buf[6], buf[7])
		ps := complex(buf[8], buf[9])
		kin := isAtSameSide(p3, pk, []complex128{p1, p2}) &&
			isAtSameSide(p1, pk, []complex128{p2, p3}) &&
			isAtSameSide(p2, pk, []complex128{p3, p1})
		sin := isAtSameSide(p3, ps, []complex128{p1, p2}) &&
			isAtSameSide(p1, ps, []complex128{p2, p3}) &&
			isAtSameSide(p2, ps, []complex128{p3, p1})
		if (kin || sin) && !(kin && sin) {
			fmt.Println("OK")
		} else {
			fmt.Println("NG")
		}
	}
}

func isAtSameSide(a, b complex128, line []complex128) bool {
	sa := (real(line[1]) - real(line[0]))*(imag(a)-imag(line[0]))+
		(imag(line[1])-imag(line[0]))*(real(line[0])-real(a))
	sb := (real(line[1]) - real(line[0]))*(imag(b)-imag(line[0]))+
		(imag(line[1])-imag(line[0]))*(real(line[0])-real(b))
	return (sa > 0 && sb > 0) || (sa < 0 && sb < 0)
}


Measured memory_bytes: 4056
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author tatsumack
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(12)

using namespace std;

typedef pair<int, int> P;

class EYutori {
public:
    void solve(std::istream& cin, std::ostream& cout) {
        int N, K, C;
        cin >> N >> K >> C;
        string s;
        cin >> s;

        vector<int> left(K), right(K);
        int cur = 0;
        REP(i, N) {
            if (cur == K) break;
            if (s[i] == 'x') continue;
            if (cur > 0 && i <= left[cur - 1] + C) continue;
            left[cur++] = i;
        }
        cur = K - 1;
        REV(i, N - 1, 0) {
            if (cur < 0) break;
            if (s[i] == 'x') continue;
            if (cur < K - 1 && i >= right[cur + 1] - C) continue;
            right[cur--] = i;
        }

        vector<int> res;
        REP(i, K) {
            if (left[i] == right[i]) res.push_back(left[i]);
        }

        for (auto d : res) cout << d + 1 << endl;
    }
};


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    std::istream& in(std::cin);
    std::ostream& out(std::cout);

    EYutori solver;
    solver.solve(in, out);
    return 0;
}


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

int main()
{
    int n;
    cin>>n;
    int ld=n%10;
    //cout<<ld;
    if(ld==2 || ld==4||ld==5|| ld==7 || ld==9)
        cout<<"hon"<<endl;
    if(ld==0 ||ld==1||ld==6||ld==8)
        cout<<"pon"<<endl;
    if(ld==3)
        cout<<"bon"<<endl;
}


Measured memory_bytes: 3664
N = int(input())
a = [int(i) for i in input().split()]

MOD2 = 0
MOD4 = 0

for i in a:
    if i % 4 == 0:
        MOD4 += 1
    elif i % 2 == 0:
        MOD2 += 1

if MOD4 == 0:
    if N == MOD2:
        print('Yes')
    else:
        print('No')
else:
    if MOD2 >= 1:
        MOD2 -= 1
    if (N-MOD2) // 2 <= MOD4:
        print('Yes')
    else:
        print('No')




Measured memory_bytes: 14252
#include <bits/stdc++.h>
using namespace std;
#define ull unsigned long long
#define MOD (int)(1e9+7)
#define ceil(x, y) (x%y==0? (x/y) : (x/y+1))
#define FOR(i, N) for(int i = 0; i < N; ++i)
#define FOR1(i, N) for(int i = 1; i <= N; ++i)
#define vi vector <int>
#define pii pair <int, int>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mset(a, v) memset(a, v, sizeof(a))
#define all(v) (v).begin(), (v).end()
#define INF 2e9
#define EPS 1e-9
#define MAX 200009
#define int long long
/*#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef cc_hash_table<int, int, hash<int>> ht; // while using, comment #define int long long  */

void __print(int x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define dbg(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define dbg(x...)
#endif
using namespace std;
bool tri(int a, int b, int c){
    if(a+b>c and b+c>a and c+a>b) return true;
    else return false;
}
int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
    	freopen("in.txt", "r", stdin);
    	freopen("out.txt", "w", stdout);
    #endif
    int T=1;
    // cin >> T;
    FOR1(tt, T){
    	// cout << "Case #" << tt << ": ";
        int x, k, d;
        cin >> x >> k >> d;

        if(k < abs(x)/d){
            cout << abs(x) - k*d;
        }
        else{
            k -= abs(x)/d;
            int rem = abs(x) % d;
            if(k % 2 == 0) cout << rem;
            else cout << abs(rem-d);
        }
        
    	cout << '\n';
    }
	return 0;
}


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

// Macros
#define PRAGMA(x) _Pragma(#x)
//
#define F  first
#define S  second
#define PB push_back
#define MP make_pair
//
#define ALL(container)   container.begin(),container.end()
#define MAKE_UNIQUE(vec) do { PRAGMA(message "DO NOT FORGET TO SORT THE VECTOR !!!"); vec.erase(unique(ALL(vec)),vec.end()); } while(0)
// vec.resize() sucks, use vec.assign()
// comparator -> return <

// Rename Datatypes
using ll  = long long;
using ld  = long double;
using pii = std::pair <int,int>;

// Output, Common Containers
template <typename T> ostream& operator << (ostream &os, const vector<T> &v) { for (T i : v) os << i << ' '; return os; }
template <typename T> ostream& operator << (ostream &os, const set<T> &v)    { for (T i : v) os << i << ' '; return os; }
template <typename T> ostream& operator << (ostream &os, const deque<T> &v)  { for (T i : v) os << i << ' '; return os; }
template <typename T, typename S> ostream& operator << (ostream &os, const pair<T,S> &v) { os << "(" << v.F << "=>" << v.S << ") "; return os; }
template <typename T, typename S> ostream& operator << (ostream &os, const map<T,S> &v)  { for (auto i : v) os << i << ' '; return os; }

// Debugging
#ifdef LOCAL
	#define trace(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); d__f(_it, args); }
	void d__f(__attribute__((unused)) istream_iterator<string> it) {}
	template<typename Head, typename... Tail> void d__f(istream_iterator<string> it, Head H, Tail... T) { cerr << *it << " <=> [" << H << "]\n"; d__f(++it, T...); }
#else
	#define trace(args...)
#endif


// CODE STARTS HERE

signed main() {
	std::ios::sync_with_stdio(false); //Warning: Do NOT use C I/O now.
	std::cin.tie(nullptr); //Note: Comment out this line for interactive questions.
	// std::cout.setf(std::ios::fixed); std::cout.precision(20); //Note: To output decimals correctly.

	// int tt; cin >> tt;
	// for(int test_no = 1; test_no <= tt; ++test_no){}

	int k;
	cin >> k;

	string s;
	cin >> s;

	for(int i = 0; i < min(k, (int)s.size()); ++i)
		cout << s[i];

	if(k < s.size()) cout << "...";
	cout << "\n";
}


Measured memory_bytes: 3648
///Ug02-47-18-017
#include<stdio.h>
int main()
{
    int A_1, A_2, A_3, ans;

    scanf("%d %d %d",&A_1, &A_2, &A_3);

    ans = A_1 + A_2 + A_3;

    if(ans >= 22){
        printf("bust\n");
    }else{
        printf("win\n");
    }


    return 0;
}


Measured memory_bytes: 128
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <iomanip>

#define REP(i,n) for(i=0; i < (n); i++)
#define REPONE(i, n) for(i=1; i <= (n); i++)
#define LOOP(n) for(int loopCount=1; loopCount <= (n); loopCount++)
#define ITER(c) __typeof((c).begin())
#define EACH(c,it) for(ITER(c) it =(c).begin(); it!=(c).end(); it++)
#define SZ(c) ((int) (c).size())
#define ALL(c) c.begin(), c.end()
#define SUM(c) accumulate(ALL(c), 0)
#define EXIST(c,v) (find(ALL(c), (v)) != (c).end())
#define PB push_back
#define MP make_pair

using namespace std;
static const double EPS = 1e-9;
static const double PI = 3.141592653589793238462643383279;
typedef long long ll;

int main(){
    int i, j;
    REPONE(i,9)REPONE(j,9) printf("%dx%d=%d\n", i, j, i*j);
    return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    istream& in(cin);
    ostream& out(cout);
    int n,k,s;
    in>>n>>k>>s;
    fr(i,k) cout<<s<<" ";
    fr(i,n-k){
        if(s==1e9) cout<<s-1<<" ";
        else cout<<s+1<<" ";
    }
    cout<<endl;
}

Measured memory_bytes: 1280
import numpy as np


def num_even_odd(num):
    num_odd = np.ceil(num/2)
    num_even = num//2
    return num_odd, num_even


def main(num):
    odds, evens = num_even_odd(num)
    print(int(odds * evens))


if __name__ == "__main__":
    main(int(input()))

Measured memory_bytes: 12404
parseInt(x::String) = parse(Int, x)
parseInt(x::SubString{String}) = parse(Int, x)
parseInt(x::Char) = parse(Int, x)
parseInt(x::Float64) = trunc(Int, x)
parseFloat(x::String) = parse(Float64, x)
parseFloat(x::Int) = trunc(Float64, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function getcod(cod,lim)
    if cod==0 || cod==lim+1
        return false
    else
        return true
    end
end

function main()
    h,w=parseMap(split(readline()))
    s=[chomp(readline()) for i in 1:h]
    ans="Yes"
    for i in 1:h
        for j in 1:w
            flg=false
            if s[i][j]=='.'
                continue
            end
            for (x,y) in [(-1,0),(1,0),(0,-1),(0,1)]
                if !getcod(j+x,w) || !getcod(i+y,h)
                    continue
                end
                if s[i+y][j+x]=='#'
                    flg=true
                    break
                end
            end
            if !flg
                ans="No"
            end
        end
    end
    println(ans)
end
main()

Measured memory_bytes: 170272
from collections import Counter

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

a_even = [0] * (n//2); a_odd = [0] * (n//2)

for i in range(n):
    if i % 2 == 0:
        a_even[i//2] = a[i]
    else:
        a_odd[i//2] = a[i]

dic_even = Counter(a_even); dic_odd = Counter(a_odd)

first_even_key, first_even_num = max(dic_even.items(), key=lambda x: x[1])
dic_even.pop(first_even_key)
if len(dic_even) > 0:
    second_even_key, second_even_num = max(dic_even.items(), key=lambda x: x[1])
else:
    second_even_key = -1; second_even_num = 0

first_odd_key, first_odd_num = max(dic_odd.items(), key=lambda x: x[1])
dic_odd.pop(first_odd_key)
if len(dic_odd) > 0:
    second_odd_key, second_odd_num = max(dic_odd.items(), key=lambda x: x[1])
else:
    second_odd_key = -1; second_odd_num = 0

if first_even_key == first_odd_key:
    print(n - max(first_even_num + second_odd_num, second_even_num + first_odd_num))
else:
    print(n - first_even_num - first_odd_num)

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

int main() {
  string S;
cin >> S;
for(int i=0;i<S.size();i++){
  if(i%2==0){
    if(S[i]=='L'){
      cout<<"No"<<endl;
      return 0;
    }
  }
  if(i%2==1){
    if(S[i]=='R'){
      cout<<"No"<<endl;
      return 0;
    }
  }
}
cout<<"Yes"<<endl;
return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static final int MAX = 1_000_000;

    public static void main(String[] args) {
        boolean[] prime = createPrimeTable(MAX);
        try(Scanner scn = new Scanner(System.in)) {
            int a;
            int b;
            int n;
            while((a = scn.nextInt()) > 0 | (b = scn.nextInt()) > 0 | (n = scn.nextInt()) > 0) {
                for(int cnt = 0; cnt < n; a += b) {
                    if(prime[a]) {
                        cnt++;
                    }
                }
                System.out.println(a - b);
            }
        }
    }

    public static boolean[] createPrimeTable(int num) {
        boolean[] rslt = new boolean[-~num];
        int lmt = (int)Math.ceil(Math.sqrt(num));
        Arrays.fill(rslt, 2, rslt.length, true);
        for(int i = 4; i <= num; i += 2) {
            rslt[i] = false;
        }
        for(int i = 3; i <= lmt; i += 2) {
            for(int j = i * 2; j <= num; j += i) {
                rslt[j] = false;
            }
        }
        return rslt;
    }
}

Measured memory_bytes: 30048