akhauriyash/Code-Regression huggingface dataset:
//#pragma GCC optimize("Os")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,fma,abm,mmx,avx,avx2,tune=native")
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#ifdef rd
#define trace(...) cout<<"Line:"<<__LINE__<<" "; __f(#__VA_ARGS__, __VA_ARGS__)
template<typename Arg1>
void __f(const char* name, Arg1&& arg1) {
	cout<<name<<" : "<<arg1<<endl;
}
template<typename Arg1, typename ... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
	const char* comma=strchr(names+1,',');
	cout.write(names,comma-names)<<" : "<<arg1<<" | ";
	__f(comma+1,args...);
}
#else
#define trace(...)
#define endl '\n'
#endif
#define pb push_back
#define fi first
#define se second
//#define int long long
typedef long long ll;
typedef float f80;
//#define double long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define sz(x) ((long long)x.size())
#define fr(a,b,c) for(int a=b; a<=c; a++)
#define rep(a,b,c) for(int a=b; a<c; a++)
#define trav(a,x) for(auto &a:x)
#define all(con) con.begin(),con.end()
const ll infl=0x3f3f3f3f3f3f3f3fLL;
const int infi=0x3f3f3f3f;
//const int mod=998244353;
int mod=1000000007;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> oset;
auto clk=clock();
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
int rng(int lim) {
	uniform_int_distribution<int> uid(0,lim-1);
	return uid(rang);
}
int powm(ll a, ll b) {
	int res=1;
	while(b) {
		if(b&1)
			res=(res*a)%mod;
		a=(a*a)%mod;
		b>>=1;
	}
	return res;
}

char g[805][805];
int dist[805][805];
void solve() {
	int n,m,k;
	cin>>n>>m>>k;
	memset(g,'#',sizeof(g));
	memset(dist,infi,sizeof(dist));
	fr(i,1,n)
		fr(j,1,m)
			cin>>g[i][j];
	int ans=infi;
	pii st;
	fr(i,1,n)
		fr(j,1,m)
			if(g[i][j]=='S') {
				st.fi=i;
				st.se=j;
			}
	queue<pii> bfs;
	bfs.push(st);
	vector<int> dx={1,0,-1,0},dy={0,1,0,-1};
	dist[st.fi][st.se]=0;
	while(!bfs.empty()) {
		pii at=bfs.front();
		bfs.pop();
		for(int i=0; i<4; i++) {
			if(g[at.fi+dx[i]][at.se+dy[i]]=='.'&&dist[at.fi+dx[i]][at.se+dy[i]]>dist[at.fi][at.se]+1) {
				dist[at.fi+dx[i]][at.se+dy[i]]=dist[at.fi][at.se]+1;
				bfs.push({at.fi+dx[i],at.se+dy[i]});
			}
		}
	}
	fr(i,1,n) {
		fr(j,1,m) {
			if(dist[i][j]<=k) {
				ans=min(ans,1+(i-1+k-1)/k);
				ans=min(ans,1+(j-1+k-1)/k);
				ans=min(ans,1+(n-i+k-1)/k);
				ans=min(ans,1+(m-j+k-1)/k);
			}
		}
	}
	cout<<ans<<endl;
}
signed main() {
	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	srand(chrono::high_resolution_clock::now().time_since_epoch().count());
	cout<<fixed<<setprecision(10);
	int t=1;
//	cin>>t;
	fr(i,1,t)
		solve();
#ifdef rd
	cout<<endl<<endl<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl;
#endif
	return 0;
}


Measured memory_bytes: 3456
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,n,s) for(int i = s; i < (n); ++i)
#define rsrep(i,n,s) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<x<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    if (a == b && b == c) {
        if (a%2 == 0 && b%2 == 0 && c%2 == 0) puts("-1");
        else puts("0");
        return 0;
    }

    int ans = 0;
    while (a%2 == 0 && b%2 == 0 && c%2 == 0) {
        ll ta = a, tb = b, tc = c;
        a = (tb+tc)/2;
        b = (ta+tc)/2;
        c = (ta+tb)/2;
        ans++;
    }

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

Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include<vector>
#include<iomanip>
#include<map>
#include <queue>
#include<cmath>
#include<cstdio>
#include<iomanip>
#include<set>
#include <bits/stdc++.h>
 
using namespace std;
using ll = long long int;
 
#define REP(i,n) for(ll i=0;i<(ll)(n);i++) //REP(i, 5) cout<<i;
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define MOD 1000000007 //10^9+7
//#define MOD 1
 
ll gcd(ll a, ll b) {
  ll tmp;
  if ( b > a) {
    tmp = a;
    a = b;
    b = tmp;
  }
  while (a % b !=0) {
    tmp = b;
    b = a % b;
    a = tmp;
  }
  return b;
}
 
const int MAX = 2000;

long long fac[MAX], finv[MAX], inv[MAX];
 
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


void sosuu(ll n, vector<ll> &v){

  vector<ll> num(n, 0);

  FOR(i, 1, sqrt(n)){
    if(num[i]==0){
      FOR(j, 0, n/i){
        num[i+(j*i)] = 1;
      }
    }
  }
  REP(i, n){
    if(num[i]==0) v.push_back(i+1);
  }
}

ll GetDigit(ll num){
    ll digit=0;
    while(num!=0){
        num /= 10;
        digit++;
    }
    return digit;
}


int main(void){
  ll h, w;
  cin>>h>>w;
  ll count = 0;

  ll M[h][w];
  REP(i, h){
    REP(j, w){
      char x;
      cin>>x;
      M[i][j] = x;
      if(x=='#') count++;
    }
  }

  queue<pair<ll, ll>> q;
  q.push(make_pair(0, 0));
  ll V[h][w];
  REP(i, h){
    REP(j,w){
      V[i][j] = 0;
    }
  }
  V[0][0] = 1;

  while(q.size()!=0){
    pair<ll, ll> now = q.front();
    q.pop();
    ll nx = now.first;
    ll ny = now.second;
    //cout<<nx<<","<<ny<<endl;
    if(nx==h-1 && ny==w-1){
      if(count==(h+w-1)) cout<<"Possible"<<endl;
      else cout<<"Impossible"<<endl;
      return 0;
    }

    ll x, y;
    x = nx + 1;
    y = ny;
    if(x<h && y<w && M[nx][ny]=='#'){
      q.push(make_pair(x, y));
      V[x][y] = 1;
    }
    x = nx;
    y = ny+1;
    if(x<h && y<w && M[nx][ny]=='#'){
      q.push(make_pair(x, y));
      V[x][y] = 1;
    }

  }
  cout<<"Impossible"<<endl;
  return 0;
}

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


int main()
{
 string s;
  cin>>s;
  ll max=0;
  for(ll i=0;i<s.size();i++)
  {
   ll count=0;
    while(s[i]=='R')
    {
     count++; 
      i++;
    }
    if(count>0)
    {
     i--; 
      if(count>max)
      {
       max=count; 
      }
    }
  }
  cout<<max<<endl;
  
}

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

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

int main() {
	int n, X, ans;

	scanf("%d%d", &n, &X);
	ans = 0;
	while (n--) {
		int x;

		scanf("%d", &x);
		ans = gcd(ans, abs(X - x));
	}
	printf("%d\n", ans);
	return 0;
}


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

int main()
{
  int num1, num2, agg;
  agg = 0;

  cin >> num1 >> num2;
  agg = num1 + num2;

  if(agg >= 10)
  cout << "error" << endl;
  else
  cout << agg << endl;
}


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

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

  string S; cin >> S;
  string T; cin >> T;
  int N = S.size();
  string ans = "Yes";
  for (ll i = 0; i < N; i++) {
    if (S[i] != T[i]) ans = "No";
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 3652
#include <iostream>
#include <vector>

using namespace std;

int parent[100001];

int root(int v) {
	if (parent[v] == v) return v;
	return (parent[v] = root(parent[v]));
}

void unite(int u, int v) {
	int ru = root(u), rv = root(v);
	if (ru != rv) parent[ru] = rv;
}

int main(int argc, char *argv[]) {
	int N, M;
	cin >> N >> M;

	for (int i = 0; i < N; i++)
		parent[i] = i;

	vector<int> p(N);
	for (int i = 0; i < N; i++) {
		cin >> p[i];
		p[i]--;
	}

	for (int i = 0; i < M; i++) {
		int x, y;
		cin >> x >> y;
		x--, y--;
		unite(x, y);
	}

	int ans = 0;
	for (int i = 0; i < N; i++)
		if (root(i) == root(p[i]))
			ans++;

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1024
//ITP1_7_B_19140837_小島優希也
//学習番号 19140837    氏名　小島優希也
#include <iostream>
#include <vector>
using namespace std;

int main(void) {
    vector<int> count;
    while (true) {
        int n, x;
        cin >> n >> x;
        int i = 0;
        if (n == 0 && x == 0) break;
        else {
            for (int a = 1; a <= n - 2; a++) {
                for (int b = a + 1; b <= n - 1; b++) {
                    for (int c = b + 1; c <= n; c++) {
                        if (a + b + c == x) i++;
                    }
                }
            }
            count.push_back(i);
        }
    }
    for (int i = 0; i < count.size(); i++) {
        cout << count.at(i) << endl;
    }
    return 0;
}




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

int main() {
  int n,m;
  cin>>n>>m;
  vector<int> k(n);
  int a[n][30];
  vector<vector<bool>> b(n, vector<bool>(30, false));
  for (size_t i = 0; i < n; i++) {
    cin>>k[i];
    for (size_t j = 0; j < k[i]; j++) {
      cin>>a[i][j];
      b[i][a[i][j]-1] = true;
    }
  }
  for (size_t i = 0; i < n; i++) {
    for (size_t j = 0; j < 30; j++) {
      b[0][j] = b[0][j] && b[i][j];
    }
  }
  int p = 0;
  for (size_t j = 0; j < 30; j++) {
    if (b[0][j]==true) {
      p++;
    }
  }
  cout<<p<<endl;
}

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

int main() {
    int n, l;
    cin >> n >> l;
    string s[n];
    for (int i = 0; i < n; i++) cin >> s[i];

    sort(s, s+n);
    string ret = "";
    for (int i = 0; i < n; i++) {
        ret += s[i];
    }

    cout << ret << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;
class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        for(int i = 1 ; ; i++ ){
            int x = sc.nextInt();
            if(x == 0){
                break;
            }
            System.out.println("Case " + i + ": " + x);
        }
    }
}


Measured memory_bytes: 42488
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<utility>
#include<algorithm>
#include<cstdio>
#include<iomanip>
#include<queue>
#include<stack>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)

using namespace std;

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

    string S;
    cin >> S;
    ll n = S.size();

    bool ans = true;
    Rep (i, n) {
        if (i % 2 == 0 && S[i] == 'L' || i % 2 == 1 && S[i] == 'R') {
            ans = false;
            break;
        } 
    }

    if (ans) cout << "Yes\n";
    else cout << "No\n";
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast","inline","-ffast-math")
#pragma GCC target("avx,sse2,sse3,sse4,mmx")
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
//#define int long long
using namespace __gnu_pbds;
using namespace std;

int val[10]; 

signed main()
{
	ios::sync_with_stdio(false);
	int n,m;
	cin>>n>>m;
	memset(val,-1,sizeof(val));
	for(int i=1;i<=m;i++){
		int x,y;
		cin>>x>>y;
		if(val[x]==-1) val[x]=y;
		else if(val[x]!=y){
			cout<<-1<<endl;
			return 0;
		}
	}
	for(int i=1;i<=n;i++){
		if(i==1&&n>1&&val[i]==0){
			cout<<-1<<endl;
			return 0;
		}
		if(val[i]!=-1) continue;
		if(i==1&&n>1) val[i]=1;
		else val[i]=0;
	}
	for(int i=1;i<=n;i++) cout<<val[i];
	cout<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string s1,s2,s3; cin >> s1 >> s2 >> s3;
  int dif = 'A' - 'a';
  s1[0]-=32;
  s2[0]-=32;
  s3[0]-=32;
  
  cout << s1[0] << s2[0] << s3[0] << endl;
}

Measured memory_bytes: 3616
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <cassert>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
const ll mod=1000000007;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
// head

const int N=501000;
char s[N];
int n,nxt[N],acyc[N];
int main() {
	scanf("%s",s);
	n=strlen(s);
	nxt[0]=-1;
	int k=-1;
	rep(i,1,n) {
		while (k>=0&&s[k+1]!=s[i]) k=nxt[k];
		if (s[k+1]==s[i]) ++k;
		nxt[i]=k;
	}
	int prd=n-nxt[n-1]-1;
	if (prd==1) {
		printf("%d\n",n);
		puts("1");
	} else if (prd==n||n%prd!=0) printf("1\n1\n");
	else {
		rep(i,0,n-1) {
			acyc[i]=(nxt[i]==-1)||((i+1)%(i-nxt[i])!=0);
		}
		rep(i,0,n) nxt[i]=0; reverse(s,s+n);
		nxt[0]=-1;
		int k=-1;
		rep(i,1,n) {
			while (k>=0&&s[k+1]!=s[i]) k=nxt[k];
			if (s[k+1]==s[i]) ++k;
			nxt[i]=k;
		}
		int ret=0;
		rep(i,0,n-1) if ((nxt[i]==-1||(i+1)%(i-nxt[i])!=0)&&acyc[n-i-2]) ++ret;
		printf("2\n%d\n",ret);
	}
}


Measured memory_bytes: 4608
#include <bits/stdc++.h>
#define ll long long 
using namespace std;
 
int main(){

  ios::sync_with_stdio(false);
  cin.tie(0);
  /*#ifndef ONLINE_JUDGE
  freopen ("input.txt", "r", stdin);
  freopen ("output.txt", "w", stdout);
    #endif 
*/
ll a,b,k;
cin>>a>>b>>k;

if(k>=a)
{
  k-=a;
  a=0;
  if(k>=b)
  {
    k-=b;
    b=0;
  }
  else b-=k;

}
else if(k<a)
{
  a=a-k;
}

cout<<a<<" "<<b<<endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define l long
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ff first
#define ss second
#define pii pair <int,int>
#define pll pair <ll,ll>
#define testcase() int t; cin>>t; while(t--)

ll M = 1e9 + 7;
ll powerm(ll x,ll y){ ll res=1; while(y){ if(y&1) res=(res*x)%M; y=y>>1; x=(x*x)%M;} return res%M; }
ll power(ll x,ll y){ ll res=1; while(y){ if(y&1) res=(res*x); y=y>>1; x=(x*x);} return res; }
ll max3(ll a,ll b,ll c){ return max( max(a,b),c ); }
ll gcd(ll a,ll b){if(b>a)return gcd(b,a); if(b==0)return a; return gcd(b,a%b);}

const int N = 100;
int ans[N],a[N],b[N],c[N],d[N];
int m,n,q; int jj;

void solve(int sz,int val)
{
    if(sz==n+1)
    {
        int tt = 0;
        for(int i=0;i<q;i++)
        {
            if( ans[b[i]] - ans[a[i]] == c[i] )
                tt += d[i];
        }
        jj = max(jj,tt);
        return;
    }
    for(int i=val;i<=m;i++)
    {
        ans[sz] = i;
        solve(sz+1,i);
    }
}

int main() {
	
	//ifstream cin("input.txt");
	//ofstream cout("output.txt");
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 
	
	cin>>n>>m>>q;
	for(int i=0;i<q;i++)
	{
	    cin>>a[i]>>b[i]>>c[i]>>d[i];
	    //a[i]--; b[i]--;
	}
	solve(1,1);
	cout<<jj;
	
	return 0;
}


Measured memory_bytes: 3672
def Judge_the_color(P):
    if P <= 399:
        return 'gray'
    elif P<=799:
        return 'brown'
    elif P<=1199:
        return 'green'
    elif P<=1599:
        return 'lightblue'
    elif P<=1999:
        return 'blue'
    elif P<=2399:
        return 'yellow'
    elif P<=2799:
        return 'orange'
    elif P<=3199:
        return 'red'
    else:
        return 'WC'

N=int(input())
aaa=list(map(int,input().split()))
l=[]

for a in aaa:
    l.append(Judge_the_color(a))

WCs=l.count('WC')

MIN=len(set(l))
MAX=len(set(l))

if MIN==1 and l[0]=='WC':
    MIN=1
elif WCs>=1:
    MIN=MIN-1
else:
    pass

if WCs>=1:
    MAX=MAX-1+WCs
else:
    pass

print(MIN,MAX)

Measured memory_bytes: 9224
n=int(input())
w=list(map(int,input().split()))
wa=[0]*(n+1)
for i in range(n):
	wa[i+1] = wa[i]+w[i]

ans = 1234567890
for i in range(1,n+1):
	ans = min(ans,abs(wa[n]-2*wa[i]))
print(ans)

Measured memory_bytes: 3064
n, k = map(int, input().split())
mod = 10 ** 9 + 7

ans = 0
for t in range(k, n+2):
    mini = t * (t-1) // 2 % mod
    residue = n - t + 1
    maxim = mini + t * residue
    maxim %= mod
    count = maxim - mini + 1
    count %= mod
    ans += count
    ans %= mod

print(ans)


Measured memory_bytes: 9188
#include <iostream>
#include <string>
#include <vector>
#include <bits/stdc++.h>

using namespace std;

long long calc_med(vector<long long> &vec){ 
    int size = vec.size(); 
    std::sort(vec.begin(), vec.end()); 
    if (size%2 == 0){ 
        return (vec[size/2-1] + vec[size/2 + 1-1]); 
    } 
    else{ 
        return vec[(size+1)/2-1]; 
    }
}

int main(){ 
    long long N; 
    cin >> N ; 
    vector<long long> A(N), B(N); 
    //vector<int> vec(N); 
    for (int i = 0; i < N; ++i){ 
        cin >> A[i] >> B[i];
    }


    if(N%2 ==1){
        cout << calc_med(B) - calc_med(A) + 1 << endl;;
    }
    else{
        //cout << "aaa" << endl;
        //cout << "calcB" <<calc_med(B) << endl;
        cout << calc_med(B) - calc_med(A)+ 1 << endl;;
    }
    return 0;
}

Measured memory_bytes: 6380
/**
 * 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;

struct BIT {
    int n;
    vector<int> bit; // 1-indexd

    BIT(int sz) {
        bit.resize(sz + 1);
        n = sz;
    }

    int sum(int i) {
        int s = 0;
        while (i > 0) {
            s += bit[i];
            i -= i & -i;
        }
        return s;
    }

    void add(int i, int x) {
        while (i <= n) {
            bit[i] += x;
            i += i & -i;
        }
    }
};

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

        vector<BIT> v;
        REP(i, 26) {
            v.emplace_back(N + 1);
        }
        REP(i, N) {
            int idx = s[i] - 'a';
            v[idx].add(i + 1, 1);
        }

        while (q--) {
            int t;
            cin >> t;
            if (t == 1) {
                int i;
                char c;
                cin >> i >> c;
                int idx = s[i - 1] - 'a';
                v[idx].add(i, -1);
                s[i - 1] = c;
                v[c - 'a'].add(i, 1);
            } else {
                int l, r;
                cin >> l >> r;
                int res = 0;
                REP(i, 26) {
                    int num = v[i].sum(r) - v[i].sum(l - 1);
                    if (num > 0) res++;
                }
                cout << res << endl;
            }
        }
    }
};


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

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


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

const int64_t MOD = 1e9+7;
string S = "TAGC";

// dp[i][a][b][c] : i文字まで決めていて直近三文字がabc
int64_t dp[105][4][4][4];

int main(){
  int N; cin >> N;
  
  dp[0][0][0][0] = 1;

  for(int i=0; i<=N; i++){
    for(int a=0; a<4; a++){
      for(int b=0; b<4; b++){
        for(int c=0; c<4; c++){
          for(int d=0; d<4; d++){
            dp[i+1][a][b][c];

            // 次の状態を含めた3文字が AGC, GAC, CAG
            if(S[a] == 'A' && S[b] == 'G' && S[c] == 'C') continue;
            if(S[a] == 'G' && S[b] == 'A' && S[c] == 'C') continue;
            if(S[a] == 'A' && S[b] == 'C' && S[c] == 'G') continue;

            // 次の状態を含めた4文字が A()GC, AG()c
            if(S[a] == 'A' && S[c] == 'G' && S[d] == 'C') continue;
            if(S[a] == 'A' && S[b] == 'G' && S[d] == 'C') continue;

            dp[i+1][a][b][c] = (dp[i+1][a][b][c] + dp[i][b][c][d]) % MOD;
          }
        }
      }
    }
  }

  int64_t ans = 0;
  for(int a=0; a<4; a++){
    for(int b=0; b<4; b++){
      for(int c=0; c<4; c++){
        ans = (ans + dp[N][a][b][c]) % MOD;
      }
    }
  }
  
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  map<int,int> mp;
  for(int i=0;i<n;i++){
    int a;
    cin>>a;
    mp[a]++;
  }
  int c=0;
  for(auto a:mp){
    if(a.second%2==1) c++;
  }
  cout<<c;
}

Measured memory_bytes: 4864
n = int(input())
nl = [str(i) for i in range(1, n+1)]
def perm(nl):

    if len(nl) == 0:
        return []

    if len(nl) == 1:
        return [nl]

    l = []

    for i in range(len(nl)):

        m = nl[i]

        rest = nl[:i] + nl[i+1:]

        for p in perm(rest):
            l.append([m] + p)


    return l



for i in perm(nl):
    print(" ".join(i))


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

const int maxn = 2e5+5;
int n,k,a[maxn],maxl=0;

int query(int l,int r){
	if (r<=l) return l;
	int mid = (l+r)>>1;
	int ans = 0;
	for (int i=1;i<=n;i++){
		ans += ((a[i]-1)/mid); 
	}
	if (ans <= k) return query(l,mid);
	else return query(mid+1,r);
}

int main(){
	cin >> n >> k;
	for (int i=1;i<=n;i++){
		cin >> a[i];	
		maxl = max (maxl,a[i]);
	}
	cout << query(1,maxl);
	return 0;
}	

Measured memory_bytes: 4244
#include<bits/stdc++.h>
#define F first
#define S second
#define endl '\n'
#define MP make_pair
#define pb push_back

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

static const int INF = INT_MAX;
static const LL L_INF = LLONG_MAX;
static const int MOD = (1000000000 + 7);

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

    int w, h;
    int x, y, r;
    cin >> w >> h >> x >> y >> r;
    if( x - r < 0 || y - r < 0 || x + r > w || y + r > h ) cout << "No" << endl;
    else cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 3156
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
using namespace std;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 3000000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define MOD 998244353
#define REP(i,n) for(long long i = 0;i < n;++i)    
#define seg_size 524288
double dot(complex<double> a, complex<double> b) {
	return a.real() * b.real() + a.imag() * b.imag();
}
double gyaku_dot(complex<double> a, complex<double> b) {
	return a.real() * b.imag() - a.imag() * b.real();
}
double leng(complex<double> a) {
	return sqrt(a.real() * a.real() + a.imag() * a.imag());
}
double angles(complex<double> a, complex<double> b) {
	double cosine = dot(a, b) / (leng(a) * leng(b));
	double sine = gyaku_dot(a, b) / (leng(a) * leng(b));
	double kaku = acos(cosine);
	if (sine <= 0) {
		kaku = 2 * Ma_PI - kaku;
	}
	return kaku;
}
vector<int> convex_hull(vector<complex<double>> a) {
	vector<int> ans;
	double now_minnest = a[0].real();
	int now_itr = 0;
	REP(i, a.size()) {
		if (now_minnest > a[i].real()) {
			now_minnest = a[i].real();
			now_itr = i;
		}
	}
	ans.push_back(now_itr);
	complex<double> ba(0, 1);
	while (true) {
		int now_go = 0;
		double now_min = 0;
		int starter = ans[ans.size() - 1];
		for (int i = 0; i < a.size(); ++i) {
			if (i != starter) {
				double goa = angles(ba, a[i] - a[starter]);
				if (goa > now_min) {
					now_min = goa;
					now_go = i;
				}
			}
		}
		if (now_go == ans[0]) break;
		ans.push_back(now_go);
		ba = complex<double>(a[now_go] - a[starter]);
	}
	return ans;
}
long long gcd(long long a, long long b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
int main(){
	int a, b, c;
	cin >> a >> b >> c;
	cout << a + b + c - max({ a,b,c }) << endl;
}


Measured memory_bytes: 256
N,K = map(int,input().split())
R,S,P = map(int,input().split())
T = [_ for _ in input()]
cnt = 0
for i in range(N):
    if i < K or T[i] != T[i-K]:
        if T[i] == "r":
            cnt += P
        elif T[i] == "s":
            cnt += R
        else:
            cnt += S
    else:
        T[i] = "z"
print(cnt)

Measured memory_bytes: 82424
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
const int MAXN = (1 << 20) + 5, MAXM = 2e5 + 5, BOUND = 2e5, MOD = 45989, INF = 0x3f3f3f3f;
const ll INFL = 0x3f3f3f3f3f3f3f3f;
const double PI = acos(-1.0), eps = 1e-3;
#define mid l + ((r-l)>>1)
#define lson o<<1,l,mid
#define rson o<<1|1,mid+1,r
#define lc(x) c[x][0]
#define rc(x) c[x][1]
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
char gdffsaw;
#define G gdffsaw=getchar()
#define GO G;while(gdffsaw<'-')G
#define in(z) GO;z=gdffsaw&15;G;while(gdffsaw>'-')z*=10,z+=gdffsaw&15,G
int read() {
	int x = 0, f = 1; char ch = getchar();
	while (ch<'0' || ch>'9') { if (ch == '-')f = -1; ch = getchar(); }
	while (ch >= '0'&&ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); }
	return x * f;
}

int a, b, c;
int main() {
	ios::sync_with_stdio(false);
	in(a); in(b); in(c);
	int ans = 0, cnt = 0;
	for (int i = min(a, b); i >= 1; i--) {
		if (a%i == 0 && b%i == 0)cnt++;
		if (cnt == c) {
			ans = i;
			break;
		}
	}
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define in(x) cin >> x
#define out(str) cout << str << endl

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

const int N=100002 /*値*/;
bool prime[N];
int li[N];
// int imosu[N]={};
void eratosthenes(bool *prime){
    rep(i,N) prime[i] = 1;
    prime[0] = prime[1] = 0;
    rep(i,N){
        if(prime[i]){
            for(int j = i + i; j < N; j+=i){
                prime[j] = 0;
            }
        }
    }
}

void likely(int *li){
    rep(i,N){
        if(prime[i]&&prime[(i+1)/2])li[i]=1;
        else li[i]=0;
    }
    rep(i,N-1){
        li[i+1]+=li[i];
    }
}

int Q,ans=0;

int main(){
    eratosthenes(prime);
    // rep(i,10){
    //     out(prime[i]);
    // }
    likely(li);
    // rep(i,10){
    //     printf("%d : %d\n",i,li[i]);
    // }
    cin>>Q;
    int left,right;
    rep(i,Q){
        ans=0;
        cin>>left>>right;
        out(li[right]-li[left-1]);
        // imosu[left]++;
        // imosu[right+1]--;
    }
    // rep(i,N-1){
    //     imosu[i+1]+=imosu[i];
    // }
    // rep(i,10){
    //     printf("%d : %d\n",i,imosu[i]);
    // }
    // rep(i,N-1){
    //     ans+=imosu[i]*li[i];
    // }
    // out(ans);
}


Measured memory_bytes: 1152
#include<iostream>
#include<vector>
#include <algorithm>
#include <string>
#include <utility>
#include <set>
#include <map>
#include<cmath>
#include <queue>

using lli = long long int;
int inf = 1000000007;
using namespace std;
#define sort(X) sort(X.begin(),X.end())

int N, M;

int main()
{
	cin >> N >> M;
	vector<vector<int>> data(M);
	for (int i = 0; i < M; i++) {
		int k;
		cin >> k;
		for (int j = 0; j < k; j++) {
			int s;
			cin >> s;
			data[i].push_back(s);
		}
	}
	vector<int> p(M);
	for (int i = 0; i < M; i++) {
		int pi;
		cin >> pi;
		p[i] = pi;
	}

	//bit
	int ans = 0;
	for (int bit = 0; bit < (1 << N); bit++) {
		vector<int> c(M);
		for (int j = 0; j < M; j++)c[j] = 0;
		for (int k = 0; k < N; k++) {
			if ((1 & bit >> k)) {
				//k番目のボタン押す
				for (int j = 0; j < M; j++) {
					if (count(data[j].begin(), data[j].end(), k + 1) == 1) {
						c[j] += 1;
					}
				}
			}
		}
		bool flag = true;
		for (int j = 0; j < M; j++) {
			if ((c[j] % 2) != p[j])flag = false;
		}
		if (flag)ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
def isCLKWISE(ph):
    return not ((ph[-1][0] - ph[-3][0])*(- ph[-3][1] + ph[-2][1]) - (ph[-2][0] - ph[-3][0])*(- ph[-3][1] + ph[-1][1] ) < 0)
      
def ConvexHullScan(P):
    P.sort()
    phU = [P[0],P[1]]
    for p in P[2:]:
        phU.append(p)
        while(True):
            if isCLKWISE(phU) : break
            else :
                del phU[-2]
                if len(phU) == 2 : break
    phL = [P[-1],P[-2]]
    for p in P[-3::-1]:
        phL.append(p)
        while(True):
            if isCLKWISE(phL) : break
            else :
                del phL[-2]
                if len(phL) == 2 : break
    ph = phU + phL[1:-1]
    return ph
  
n = range(int(input()))
P = []
for i in n:
    P.append([int(x) for x in input().split()])
      
Q = ConvexHullScan(P)
Q.reverse()
print(len(Q))
idx = min([[x[1][1],x[1][0],x[0]] for x in enumerate(Q)])[2]
R = Q[idx:] + Q[:idx]
for r in R : print(r[0],r[1])

Measured memory_bytes: 33752
#include <stdio.h>

int main()
{
	int N;
	//N=111;
	int count=0;
	scanf("%d",&N);
	for (int i = 0; i < 3; i++){
		int check = N % 10;
		
		if (check == 7){
			
			count++;
			//break;
		}
		N=N/10;
		// printf("%d\n",N);
		// printf("%d\n\n",check);
	}
	if (count==0){
		printf("No\n");
	}else{
		printf("Yes\n");
	}
 
 
	return 0;
}

Measured memory_bytes: 1636
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (b); i++)
#define rrep(i, a, b) for (int i = a; i >= (b); i--)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <class T>
inline bool chmin(T& a, T b) {
   if (a > b) {
      a = b;
      return true;
   }
   return false;
}
template <class T>
inline bool chmax(T& a, T b) {
   if (a < b) {
      a = b;
      return true;
   }
   return false;
}
void hr() {
   cerr << "--------------" << endl;
}
const int INF = 1001001001;
const int MOD = 1000000007;

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

   int x;
   cin >> x;
   if (x >= 30)
      cout << "Yes" << endl;
   else
      cout << "No" << endl;
   return 0;
}

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

int main() {
  string s,t;
  cin >> s >> t;
  sort(s.begin(),s.end());
  sort(t.rbegin(),t.rend());
  
  if (s < t) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

int main()
{
	int N;
	int p[30];
	cin >> N;
	for (int i = 0; i < N; i++) cin >> p[i];
	int ans = 0;
	for (int i = 1; i < N - 1; i++) {
		if ((p[i - 1] < p[i] && p[i] < p[i + 1]) || (p[i - 1] > p[i] && p[i] > p[i + 1])) ans++;
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std ;
#define ll long long int 
#define pb push_back 
#define mp make_pair 
#define pii pair <int , int > 
#define pll pair < ll , ll >
int main(){
	ios_base::sync_with_stdio(false) ;
	cin.tie(NULL) ;
	ll l , r ;
	cin >> l >> r ;
	if(r - l >= 2019){
		cout << 0 ;
		return 0 ;
	}
	ll mn = (ll)1e18 ;
	for(ll i = l ; i <= r ; i++){
		for(ll j = i + 1 ; j <= r ; j++){
			mn = min(mn , (i*j)%(ll)2019) ;
		}
	}
	cout << mn ;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MAX 100010
#define pb push_back
#define ll long long
using namespace std;

ll val[1000003];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t=1;
    //cin>>t;
    
    while(t--)
    {

        ll a;
        long double b;
        cin>>a>>b;
        ll ans=a*b;
        cout<<ans;
    }


    return 0;
}

Measured memory_bytes: 3740
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
#define endl "\n"
#define pb push_back
#define mp make_pair
#define ff first
#define pi pair<ll,ll>
#define ss second
#define ll long long
#define MAXN 100005
using namespace std;
using namespace __gnu_pbds;  

int n;

void solve()
{
	cin>>n;
	while(n>0)
	{
		int p=n%10;
		if(p==7)
		{
			cout<<"Yes"<<endl;
			return;
		}
		n/=10;
	}
	cout<<"No"<<endl;
}

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


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

using namespace std;

const char en = '\n';
using  ll =          long long;
using ull = unsigned long long;

#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,s,g) for(int i=s;i<g;i++)

int main(){
	ios::sync_with_stdio(false);cin.tie();
	
	while(true){
		int in,result=0,c[]{500,100,50,10,5,1};
		cin>>in;

		if(in==0) break;

		in*=-1;
		in+=1000;

		REP(i, 6){
			result+=in/c[i];
			in%=c[i];
		}

		cout<<result<<en;
	}


	return 0;
}

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

#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define dbgB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

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

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

template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

// ------------------------------------------------------------------------------------------

int main() {
   int N, M, Q;
   cin >> N >> M >> Q;
   vec<int> ev[501];
   rep (i, M) {
      int x, y;
      cin >> x >> y;
      ev[x].emplace_back(y);
   }
   for (int i = 0; i <= N; i++) {
      sort(begin(ev[i]), end(ev[i]));
   }

   while (Q--) {
      int p, q;
      cin >> p >> q;
      int ret = 0;
      for (int i = p; i <= q; i++) {
         ret += upper_bound(begin(ev[i]), end(ev[i]), q) - begin(ev[i]);
      }
      cout << ret << endl;
   }

   return 0;
}

Measured memory_bytes: 2176
use std::io;

fn main() {
    let n = get_num();
    let mut points: Vec<Vec<i32>> = Vec::new();
    for _i in 0..n {
        let point = read_line();
        points.push(point);
    }

    let mut t = 0;
    let mut x = 0;
    let mut y = 0;
    let mut possibility = true;

    for i in 0..points.len() {
        if possible(points[i][0] - t, x, y, points[i][1], points[i][2]) {
            t = points[i][0];
            x = points[i][1];
            y = points[i][2];
        } else {
            possibility = false;
            break;
        }
    }

    if possibility {
        println!("Yes");
    } else {
        println!("No");
    }
}

fn possible(time: i32, from_x:i32, from_y:i32, to_x:i32, to_y:i32) -> bool {
    let need_time = (from_x - to_x).abs() + (from_y - to_y).abs();
    if need_time <= time && need_time % 2 == time % 2 {
        true
    } else {
        false
    }
}

fn read_line() -> Vec<i32> {

    let input_str = get_input();
    let vec: Vec<&str> = input_str.trim().split_whitespace().collect();

    let mut int_vec: Vec<i32> = Vec::new();
    for v in vec {
        int_vec.push(to_i(v));
    }

    int_vec
}

fn get_num() -> i32 {
    to_i(&get_input())
}

fn to_i(s: &str) -> i32 {
    let input_num: i32 = match s.trim().parse() {
        Ok(num) => num ,
        Err(_)  => panic!("input wrong number."),
    };
    input_num
}

fn get_input() -> String {
    let mut input_str = String::new();
    io::stdin().read_line(&mut input_str)
        .expect("Failed to read line")
        ;
    input_str
}


Measured memory_bytes: 9720
package main

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

////////////////////////////////////////
///        templates                 ///
////////////////////////////////////////

var sc = bufio.NewScanner(os.Stdin)

func nextLine() string {
        sc.Scan()
        return sc.Text()
}

var rdr = bufio.NewReaderSize(os.Stdin, 1000000)

func readBigLine() string {
        buf := make([]byte, 0, 1000000)
        for {
                l, p, e := rdr.ReadLine()
                if e != nil {
                        panic(e)
                }
                buf = append(buf, l...)
                if !p {
                        break
                }
        }
        return string(buf)
}

func strSprit(str string) []string {
        cols := strings.Split(str, " ")
        return cols
}

func parseInt(str string) int {
        n, _ := strconv.Atoi(str)
        return n
}

type SortSlice []int

func (s SortSlice) Len() int {
        return len(s)
}

func (s SortSlice) Swap(i, j int) {
        s[i], s[j] = s[j], s[i]
}

func (s SortSlice) Less(i, j int) bool {
        return s[i] < s[j]
}

func reverseString(str string) string {
        buf := []rune(str)
        for i, j := 0, len(buf)-1; i < j; i, j = i+1, j-1 {
                buf[i], buf[j] = buf[j], buf[i]
        }
        return string(buf)
}

////////////////////////////////////////
///        end templates             ///
////////////////////////////////////////

func main() {
        line := nextLine()
        spl := strSprit(line)

        a := parseInt(spl[0])
        b := parseInt(spl[1])
        c := parseInt(spl[2])
        d := parseInt(spl[3])

        start := int(math.Max(float64(a), float64(c)))
        end := int(math.Min(float64(b), float64(d)))

        if start > end {
                fmt.Println(0)
        } else {
                fmt.Println(end - start)
        }
}


Measured memory_bytes: 640
#include <cstdio>
#include <iostream>
#include <vector>
#include <set>
#include <string>
#include <algorithm>
#include <cmath>

using namespace std;

const int CMax = 200002;

int n, A[CMax], m, B[CMax], ats;

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

    for (int i = 0; i < n; i++) {
        scanf("%d", &A[i]);
    }

    sort(A, A+n);

    scanf("%d", &m);

    for (int i = 0; i < m; i++) {
        scanf("%d", &B[i]);
    }

    sort(B, B+m);

    int indA = 0;
    int indB = 0;
    while (indA < n && indB < m){
        if (A[indA] == B[indB]) {
            indA++;
            indB++;
        } else {
            indA++;
        }
    }

    if (indB == m) {
        printf("YES\n");
    } else {
        printf("NO\n");
    }
}


Measured memory_bytes: 1792
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <map>
#include <queue>
#include <set>
#define rep(i,n) for (ll i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
//#define repitr(itr, st) for(auto itr = st.begin(); itr != st.end(); ++itr)
#define P_B push_back
#define PO_B pop_back
#define E_B emplace_back
#define M_P make_pair
#define fi first
#define se second
#define debug(x) cout << #x << ": " << x << endl
//#define print(x) printf("%d\n", x)

using namespace std;
using ll = long long;
using Pii = pair<int,int>;
using Pll = pair<ll,ll>;
using VI = vector<int>;
using VL = vector<ll>;
using VVI = vector<vector<int> >;
using VVL = vector<vector<ll> >;
//int dx[4] = {1, 0, -1, 0};
//int dy[4] = {0, 1, 0, -1};
//const ll LINF = (ll)1e18 - 1;
//const int INF = 1e9 - 1;
//int:±2*10^9くらい　ll:±9*10^18くらい



void Main(){
	int N, M, np = 2, ans = 1;
	cin >> N >> M;
	vector<queue<int> > P(N+1, queue<int> ());
	vector<bool> T(N+1, false);

	rep(i, M){
		int x, y, z;
		cin >> x >> y >> z;
		P[x].push(y);
		P[y].push(x);
	}

	queue<int> Q;
	Q.push(1);
	T[1] = true;

	while(!Q.empty()){
		int q;
		q = Q.front();
		Q.pop();

		while(!P[q].empty()){
			if(!T[P[q].front()]){
				Q.push(P[q].front());
				T[P[q].front()] = true;
			}
			P[q].pop();
		}

		if(Q.empty()){
			while(true){
				if(np == N+1) break;
				if(T[np]) np++;
				else{
					Q.push(np);
					T[np] = true;
					ans++;
					break;
				}
			}
		}
	}

	cout << ans << endl;



}

int main()
{
	cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();

  return 0;
}


Measured memory_bytes: 68224
#include <stdio.h>

void cut(int *card, int n, int k)
{
	int card2[200];
	int i, j;
	
	for (i = k, j = 0; i < n; i++, j++){
		card2[j] = card[i];
	}
	for (i = 0; i < k; i++, j++){
		card2[j] = card[i];
	}
	
	for (i = 0; i < n; i++){
		card[i] = card2[i];
	}
}

void riffle(int *card, int n)
{
	int card2[200];
	int i, j;
	
	for (i = 0, j = 0; i < n / 2; i++){
		card2[j++] = card[i];
		card2[j++] = card[n / 2 + i];
	}
	
	for (i = 0; i < n; i++){
		card[i] = card2[i];
	}
}

int main (void)
{
	int n, m, k, i, card[200] = {0};
		
	scanf("%d %d", &n, &m);
	
	n *= 2;
	
	for (i = 0; i < n; i++){
		card[i] = i + 1;
	}
	
	for (i = 0; i < m; i++){
		scanf("%d", &k);
		
		if (k == 0){
			riffle(card, n);
		}
		else {
			cut(card, n, k);
		}
	}
	
	for (i = 0; i < n; i++){
		printf("%d\n", card[i]);
	}
	
	return (0);
}

Measured memory_bytes: 600
while True:
    try:
        n=int(input())
    except:
        break
    if n==0:
        break
    data={}
    staff=[]
    for i in range(n):
        spam=list(map(int,input().split()))
        if spam[0] in data.keys():
            data[spam[0]]+=spam[1]*spam[2]
        else:
            data[spam[0]]=spam[1]*spam[2]
            staff.append(spam[0])
    if max(data.values())<1000000:
        print('NA')
    else:
        for i in staff:
            if data[i] >= 1000000:
                print(i)

Measured memory_bytes: 6748
#include <stdio.h>
int main()
{
  int A,B;
  scanf("%d %d",&A,&B);

  if (A >= 6 && A <= 12){
    printf("%d\n",B/2);
  }


  if (A <= 5){
    printf("0\n");
  }

  if (A > 12){
    printf("%d",B);
  }
}


Measured memory_bytes: 128
n = int(input())
l = [input().split() for _ in range(n)]
ot = ox = oy = 0
can = True
for (t, x, y) in l:
    dt = int(t) - ot
    dist = abs(int(x) - ox) + abs(int(y) - oy)
    if dt < dist:
        can = False
    if (dist % 2 != dt % 2):
        can = False
    ox = int(x)
    oy = int(y)
    ot = int(t)

print("Yes" if can else "No")

Measured memory_bytes: 32148
package main

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

func main() {
	n := getInt()
	a := getInt()

	fmt.Println(n*n - a)
}

// -----------------------------------------

var scanner = wordScanner()

func wordScanner() *bufio.Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	return sc
}

func getInt() int {
	scanner.Scan()
	i, err := strconv.Atoi(scanner.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func getString() string {
	scanner.Scan()
	s := scanner.Text()
	return s
}


Measured memory_bytes: 640
n=int(input())
num = [int(input()) for _ in range(n)]
cnt=0
for i in num:
    if i==2:
        cnt+=1
    if i<2 or i%2==0:
        continue
    j=3
   
    while j*j<=i:
        if i%j==0:
            break
        j+=2
    else:
        cnt+=1

print(cnt)
    



Measured memory_bytes: 5988
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <algorithm>
#include <queue>
using namespace std;
int h,w;
char mp[55][55];///标记地图
int a[55][55];///标记数组
int fx[4][2]={1,0,0,1,-1,0,0,-1};///方向
struct node
{
    int i,j,step;
};
int bfs(int pi,int pj)
{
    queue<node>q;
    node now,next,kai;
    kai.i=pi;
    kai.j=pj;
    kai.step=1;
    a[kai.i][kai.j]=true;
    q.push(kai);
    while(!q.empty())
    {
        now=q.front();
        q.pop();
        if(now.i==(h-1)&&now.j==(w-1))
            return now.step;
        for(int k=0;k<4;k++)
        {
            next.i=now.i+fx[k][0];///更新方向
            next.j=now.j+fx[k][1];
            if(next.i<0||next.j<0||next.i>=h||next.j>=w||a[next.i][next.j]||mp[next.i][next.j]=='#')
                continue;
            next.step=now.step+1;///更新部署
            a[next.i][next.j]=true;
            q.push(next);
        }
    }
    return -1;
}
int main()
{
  memset(a,0,sizeof(a));
  scanf("%d %d",&h,&w);
  int sum=0;
  for(int i=0;i<h;i++)
  {
      scanf("%s",&mp[i]);
      for(int j=0;j<w;j++)
      {
          if(mp[i][j]=='.')
            sum++;
      }
  }
  int b;
  b=bfs(0,0);
  if(b==-1)
    printf("-1\n");
  else
    printf("%d\n",sum-b);

}


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

int top,S[1000];

void push(int);
int pop();

int main() {
  int a;
  top=0;
  char s[100];

  while(scanf("%s",s)!=EOF){
    if(s[0]=='+'){
      push(pop()+pop());
  }
    else if(s[0]=='-'){
      a=pop();
      push(pop()-a);
    }
    else if(s[0]=='*'){
      push(pop()*pop());
    }
    else{
      push(atoi(s));
    }
  }

  printf("%d\n",pop());

  return 0;
}

void push(int x){
  S[++top]=x;
}

int pop(){
  top--;

  return S[top+1];

}



Measured memory_bytes: 2128
#include <bits/stdc++.h>
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
using Int = long long;
const char newl = '\n';

//INSERT ABOVE HERE
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(0);

  int n,k,c;
  cin>>n>>k>>c;

  string s;
  cin>>s;

  int cnt=0,lst=-c-1;
  vector<int> vs(n,0);
  for(int i=0;i<n;i++){
    if(lst+c>=i) continue;
    if(s[i]=='x') continue;
    cnt++;
    lst=i;
    vs[i]++;
  }
  if(cnt>k) return 0;

  cnt=0;lst=n+c+1;
  for(int i=n-1;i>=0;i--){
    if(lst-c<=i) continue;
    if(s[i]=='x') continue;
    cnt++;
    lst=i;
    vs[i]++;
  }

  for(int i=0;i<n;i++)
    if(vs[i]==2) cout<<i+1<<newl;
  return 0;
}


Measured memory_bytes: 2580
#include <stdio.h>

int main(void)
{
	int t;
	int n[] = {6000, 4000, 3000, 2000};
	int ans;
	int i;
	
	for (i = 0; i < 4; i++){
		scanf("%d %d", &t, &ans);
		
		printf("%d\n", ans * n[t - 1]);
	}
	
	return (0);
}

Measured memory_bytes: 600