akhauriyash/Code-Regression huggingface dataset:
using System;

class C
{
	static void Main()
	{
		var words = new[] { "dream", "dreamer", "erase", "eraser" };
		var s = Console.ReadLine();
		Console.WriteLine(Dfs(0) ? "YES" : "NO");

		bool Dfs(int i)
		{
			foreach (var w in words)
			{
				if (!Contains(s, i, w)) continue;
				var ni = i + w.Length;
				if (ni == s.Length || Dfs(ni)) return true;
			}
			return false;
		}
	}

	static bool Contains(string s, int si, string w)
	{
		for (int j = 0; j < w.Length; j++)
			if (si + j >= s.Length || s[si + j] != w[j]) return false;
		return true;
	}
}


Measured memory_bytes: 27324
N = int(input())
A = list(map(int,input().split()))
d = {}
for a in A:
    if a in d:
        d[a] += 1
    else:
        d[a] = 1
ans = 0
for k in d:
    ans += k * d[k]
Q = int(input())
for i in range(Q):
    b, c = map(int, input().split())
    if b in d:
        Bn = d[b]
        if c in d:
            d[c] += d[b]
            d[b] = 0
        else:
            d[c] = d[b]
            d[b] = 0
        ans += (c-b)*Bn
    print(ans)


Measured memory_bytes: 20876
def match_m(x, y, N, M, A, B):
	for i in range(M):
		if x+i >= N: return False
		for j in range(M): 
			if y+j >= N: return False
			if A[x+i][y+j] != B[i][j]: return False
	return True

N, M = map(int, raw_input().split())
A, B = [], []
for i in range(N): A.append(raw_input())
for i in range(M): B.append(raw_input())
result = "No"
for x in range(N):
	for y in range(N):
		if(match_m(x,y,N,M,A,B)): 
			result = "Yes"
			break
print result

Measured memory_bytes: 2692
#include<cstdio>
using namespace std;
int main()
{
	int n,i,cnt;
	char s[100000];
	scanf("%d",&n);
	scanf("%s",s);
	cnt=0;
	for(i=0;i<n-1;i++){
		if(s[i]==s[i+1])	cnt++;
		// printf("cnt=%d s=%c\n",cnt,s[i]);
	}
	printf("%d\n",n-cnt);
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<numeric>
#include<map>
#include<queue>
#include<set>
#include<cstdio>
using namespace std;
typedef vector<vector<int>> mat;
typedef vector<int> vec;

int main(){
    int N,M,Q;cin>>N>>M>>Q;
    mat x(510,vec(510,0)),S(510,vec(510,0));
    
    int L,R;
    for(int i=0;i<M;i++){
        cin>>L>>R;
        x[L][R]++;
    }

    for(int i=1;i<=N;i++){
        for(int j=1;j<=N;j++){
            S[i][j]=S[i][j-1]+S[i-1][j]-S[i-1][j-1]+x[i][j];
        }
    }

    int p,q;
    for(int i=0;i<Q;i++){
        cin>>p>>q;
        cout<<S[q][q]-S[p-1][q]-S[q][p-1]+S[p-1][p-1]<<endl;
    }
    return 0;
    
}

Measured memory_bytes: 2944
#include<bits/stdc++.h>
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int, int>P;

char s[60][30], buf[2];
int d[60][30][60][30][2];
struct st {
	int lx, ly, rx, ry, c;
	bool b;
};
bool operator<(const st&a, const st&b) {
	return a.c > b.c;
}
int C(char c) {
	if (isdigit(c))return c - '0';
	return 0;
}
int w, h;
inline void update(st p, priority_queue<st>&que) {
	for (int k = -2; k <= 2; k++) {
		for (int t = 1; t <= 3 - abs(k); t++) {
			if (p.b) {
				int nx = p.lx + k, ny = p.ly + t;
				if (0 <= nx&&nx < h && 0 <= ny&&ny < w&&s[nx][ny] != 'X') {
					int&u = d[p.lx][p.ly][nx][ny][!p.b];
					int c = p.c + C(s[nx][ny]);
					if (u > c) {
						u = c; que.push({ p.lx,p.ly,nx,ny,u,!p.b });
					}
				}
			}
			else {
				int nx = p.rx + k, ny = p.ry - t;
				if (0 <= nx&&nx < h && 0 <= ny&&ny < w&&s[nx][ny] != 'X') {
					int&u = d[nx][ny][p.rx][p.ry][!p.b];
					int c = p.c + C(s[nx][ny]);
					if (u > c) {
						u = c; que.push({ nx,ny,p.rx,p.ry,u,!p.b });
					}
				}
			}
		}
	}
}
int main() {
	while (scanf("%d%d", &w, &h), w) {
		memset(d, 0x3f, sizeof(d));
		priority_queue<st>que;
		rep(i, h)rep(j, w) {
			scanf("%s", buf); s[i][j] = buf[0];
		}
		rep(j, w) {
			int i = h - 1;
			if (s[i][j] == 'S') {
				update({ i,j,0,0,0,1 }, que); update({ 0,0,i,j,0,0 }, que);
			}
		}
		while (!que.empty()) {
			st p = que.top(); que.pop();
			if (d[p.lx][p.ly][p.rx][p.ry][p.b] != p.c)continue;
			update(p, que);
		}
		int Min = INF;
		rep(i, h)rep(j, w)rep(k, h)rep(t, w)rep(y, 2) {
			if (s[i][j] == 'T' || s[k][t] == 'T')Min = min(Min, d[i][j][k][t][y]);
		}
		if (Min == INF)puts("-1");
		else printf("%d\n", Min);
	}
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define int long long

signed main(){
    int n; string s, t;
    cin >> n >> s >> t;
    rep(i, n) cout << s[i] << t[i];
    cout << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int N = in.nextInt();
		if(N==3||N==5||N==7) {
			System.out.println("YES");
			
		}else{
			System.out.println("NO");
			
		}
	}
}


Measured memory_bytes: 21972
#include <bits/stdc++.h>
#include <stdio.h>
 
using namespace std;
 
#define int long long
 
bool codejam = 0;
 
typedef long long li;
typedef long double ld;
 
void solve();

int32_t main () {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout << fixed << setprecision(20);
	#ifdef LOCAL
		freopen("input.txt", "r", stdin);
	#endif
	int t = 1; 
	// cin >> t;
	int tt = t;
	while (t--) { 
		if (codejam) cout << "Case #" << tt - t << ": ";
		solve();
	}
	return 0;
}
const int N = 2e5 + 55;
multiset<int> a;
int arr[N];
int n;
void solve() {
	cin >> n;
	for (int i = 1; i <= n; ++i) {
		cin >> arr[i];
		a.insert(arr[i]);
	}
	for (int i = 1; i <= n; ++i) {
		a.erase(a.find(arr[i]));
		cout << *a.rbegin() << endl;
		a.insert(arr[i]);
	}
}	

Measured memory_bytes: 13696
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<typename T> bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<typename T> bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef tuple<ll,ll,ll> tlll;
typedef tuple<int,int,int> tiii;
const ll mod=998244353;
const int inf=1<<30;

ll dp[3010][3010];

int main(){
  int n,s; cin >> n >> s;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  ll ans=0;
  rep(i,n+1) dp[i][0]=1;
  rep(i,n)rep(j,s){
    if(j+a[i]<=3009) dp[i+1][j+a[i]]+=dp[i][j];
    dp[i+1][j]+=dp[i][j];
    dp[i+1][j+a[i]]%=mod;
    dp[i+1][j]%=mod;
  }
  rep(i,n+1){
    ans+=dp[i][s]*(n-i+1)%mod;
    ans%=mod;
  }
  /*
  rep(i,n+1){
    rep(j,s+1){
      cout << dp[i][j];
    }cout << endl;
  }*/
  cout << ans << endl;
}

Measured memory_bytes: 74168
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

int main(){
  string s, t;
  cin >> s >> t;
  int N = s.size();
  int M = t.size();

  vector<int> pos[26];
  //アルファベットから位置を検索

  int cnts[26], cntt[26];
  fill(cnts, cnts + 26, 0);
  fill(cntt, cntt + 26, 0);

  for(int i = 0; i < N; i++){
    int ind = (int)(s[i] - 'a');
    cnts[ind]++;
    pos[ind].push_back(i);
  }
  for(int i = 0; i < M; i++){
    cntt[(int)(t[i] - 'a')]++;
  }

  for(int i = 0; i < 26; i++){
    if(cnts[i] == 0 && cntt[i] != 0){
      cout << -1 << endl;
      return 0;
    }
  }

  //debug
  /*for(int i = 0; i < 26; i++){
    cout << (char)('a' + i) << " ";
    for(int j = 0; j < pos[i].size(); j++){
      cout << pos[i][j] << " ";
    }
    cout << endl;
  }*/

  //tのはしから検索
  ll ans = 0;
  int pv = -1;
  for(int i = 0; i < M; i++){
    int ind = (int)(t[i] - 'a');
    auto tmp = upper_bound(pos[ind].begin(), pos[ind].end(), pv);
    //cout << ind << " " << it << endl;

    if(tmp == pos[ind].end()){
      ans += N;
      pv = pos[ind][0];
    } else {
      //cout << "hoge" << endl;
      pv = *tmp;
    }
  }

  ans += pv + 1;
  cout << ans << endl;
  return 0;

}

Measured memory_bytes: 1216
#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 <cstring>
#include <sstream>
#include <cassert>
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;
typedef pair<int,int> PI;
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define MP make_pair
#define PB push_back

ll q1,b,c1,c2,q2;

bool can(ll ai){
  ll zan=b-ai*c1;
  ll ji=zan/c2;
  if(ai>q2 || ai<1)return false;
  if(ai+ji<q1)return false;
  if(zan<0)return false;
  return true;
}

main(){
  while(cin>>q1,q1){
    cin>>b>>c1>>c2>>q2;

    ll l=0,r=1000000;
    while(l+1<r){
      ll mid=(l+r)/2;
      //cout<<l<<" "<<mid<<" "<<r<<endl;
      if(can(mid))l=mid;
      else r=mid;
    }
    if(can(l)){
      cout<<l<<" "<<(b-l*c1)/c2<<endl;
    }else puts("NA");
  }
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define ri register int
using namespace std;
typedef long long ll;
#define pb push_back
const int rlen=1<<18|1;
char buf[rlen],*ib=buf,*ob=buf;
#define gc() (((ib==ob)&&(ob=(ib=buf)+fread(buf,1,rlen,stdin)),ib==ob)?-1:*ib++)
inline int read() {
  int ans=0;
  bool f=1;
  char ch=gc();
  while(!isdigit(ch)) f^=ch=='-',ch=gc();
  while(isdigit(ch)) ans=((ans<<2)+ans<<1)+(ch^48),ch=gc();
  return f?ans:-ans;
}
namespace modular {
  const int mod=1e9+7;
  inline int add(int a,int b) { return a+b<mod?a+b:a+b-mod; }
  inline int dec(int a,int b) { return a<b?a-b+mod:a-b; }
  inline int mul(int a,int b) { return (ll)a*b%mod; }
  inline void Add(int&a,int b) { a=a+b<mod?a+b:a+b-mod; }
  inline void Dec(int&a,int b) { a=a<b?a-b+mod:a-b; }
  inline void Mul(int&a,int b) { a=(ll)a*b%mod; }
  inline int ksm(int a,int p) { int ret=1;for(;p;p>>=1,Mul(a,a)) (p&1)&&(Mul(ret,a),1);return ret; }
  inline int Inv(int a) { return ksm(a,mod-2); }
}
using namespace modular;
const int N=2e5+5;
int n,a[N],fac[N],ifac[N],pw[N];
inline void init() {
  pw[0]=ifac[0]=ifac[1]=fac[0]=fac[1]=1,pw[1]=2;
  for(ri i=2;i<=n;++i) {
    fac[i]=mul(fac[i-1],i);
    ifac[i]=mul(ifac[mod-mod/i*i],mod-mod/i);
    pw[i]=add(pw[i-1],pw[i-1]);
  }
  for(ri i=2;i<=n;++i) Mul(ifac[i],ifac[i-1]);
}
inline int C(int n,int m) { return n<m||m<0?0:mul(fac[n],mul(ifac[m],ifac[n-m])); }
int main() {
  #ifdef ldxcaicai
  freopen("lx.in","r",stdin);
  #endif
  n=read();
  init();
  for(ri i=1;i<=n;++i) a[i]=read();
  sort(a+1,a+n+1);
  int res=0;
  for(ri i=1;i<=n;++i) Add(res,mul(pw[i-1],mul(a[i],add(pw[n-i],i==n?0:mul(pw[n-i-1],n-i)))));
  cout<<mul(res,pw[n]);
  return 0;
}

Measured memory_bytes: 3584
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int a= sc.nextInt();
		int b = sc.nextInt();
		int c = 0;
		
		if(b%a==0) {
			System.out.println(a+b);
		}else {
			System.out.println(b-a);
		}
	}
}



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

int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int a, b; cin >> a >> b;
    if (a <= 9 && b <= 9) {
        cout << (a*b) << '\n';
    }
    else {
        cout << -1 << '\n';
    }
}



Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
#define len(n) (int)n.length()
#define pb push_back
#define ll long long
#define make_pair mkp
#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(v) (v).begin(), (v).end()
#ifdef DBGPRT
#define dbg(n) cerr << "//" << #n << ":" << n <<endl
#else
#define dbg(n) ;
#endif
typedef pair<ll, ll> LLARR;
#define INF 999999999
const double PI = 3.1415926535897932384626433832795;

int main()
{
	ios::sync_with_stdio(false);

	ll s, c;
	cin >> s >> c;
	
	ll ans = 0;
	
	if(s>=1)
		if(c>=2)
		{
			ll tmp = min(c/2, s);
			ans += tmp;
			s -= tmp;
			c -= tmp * 2;
		}
	ans += c/4;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
/* B */

#include <iostream>
using namespace std;

int main(){
    int n;
    cin >> n;
    int* line = new int[n];

    int max = 0, sum = 0;

    for(int i = 0; i < n; i++){
    	cin >> line[i];
    	sum += line[i];
    	if(line[i] > max){
    		max = line[i];
    	}
    }

    if(sum - max > max){
    	cout << "Yes" << endl;
    }else{
    	cout << "No" << endl;
    }


}

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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  
  int L=A + B;
  int R=C + D;
  
  if (L < R) {
    cout << "Right" << endl;
  }
  
  else if (L > R) {
    cout << "Left" << endl;
  }
  
  else {
    cout << "Balanced" << endl;
  }
}

Measured memory_bytes: 256
#include<iostream> 
#include<vector> 
#include<algorithm> 
#include<iomanip> 
#include<stack> 
#include<unordered_map>
#include<climits>
#include<set> 
#include<string> 
//#include<bits/stdc++.h> 
using namespace std; 
#define lld long long int 
#define eb emplace_back
//to insert pair use eb
#define mp make_pair
#define fi first
#define se second
#define pb push_back

#define X 1000000007
#define Y 998244353
#define E4 1000
#define E5 10000 
#define E6 1000000
#define inf 1001001001
#define longinf 2001001001001001001
#define pi 3.1415926535

# define rec2(i,a,b) for(lld i=a;i<b;i++) 
#define rec(i,n) for(lld i=0;i<n;i++)
#define rev(i,a,b) for(lld i=b-1;i>=a;i--)
#define all(v) (v).begin(), (v).end()
#define large(v)  *max_element(all(v))
#define small(v)  *min_element(all(v)) 
#define v vector
const double EPS = 1e-6;
/*  //prime sieve if needed 
//prime factors of number
int prime[E6+1]; 
void sieve(lld n) 
{ rec(i,n+1) 
    prime[i]=1; 
   for(lld i=2;i*i<=n;i++) 
     { if(prime[i]!=1) 
          continue; 
         for(lld j=i*i;j<=n;j=j+i) 
          if(prime[i]==1)
           prime[j]=i; 
      }
}
*/
lld gcd(lld a,lld b)
{
    if(a==0)
     return b; 
    return gcd(b%a,a); 
}
//fermat a^(m-2)%mod
lld binarymul(lld a,lld n,lld m)
{  lld res=1; 
 while(n) 
  { if(n%2) 
      { res=(res*a)%m; 
         n--; 
      } 
     a=(a*a)%m; 
     n/=2; 
  }
  return res; 
}
int main()
{
   ios_base::sync_with_stdio(false); 
   cin.tie(0);
     #ifdef PUNEET_GOEL
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    #endif
   //sieve(E6); 
    lld n; 
    cin>>n; 
    lld f[4]={0}; 
     rec(i,n) 
     { string a; 
     cin>>a; 
      if(a=="RE") 
        f[3]++; 
      else if(a=="WA") 
        f[1]++; 
       else if(a=="TLE") 
        f[2]++; 
        else 
         f[0]++; 
     } 
     cout<<"AC x "<<f[0]<<endl; 
     cout<<"WA x "<<f[1]<<endl; 
     cout<<"TLE x "<<f[2]<<endl; 
     cout<<"RE x "<<f[3]<<endl; 
	return 0;
}

Measured memory_bytes: 3660
#include <iostream>

using namespace std;

int main(){
    string S,T;
    cin >> S >> T;

    if(S.substr(0, S.size()) == T.substr(0, S.size())){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 3632
#include <stdio.h>

int main(void) {
    int S, h, m, s;
    scanf("%d", &S);
    h = S / 3600;
    m = (S % 3600) / 60;
    s = (S % 3600) % 60;
    printf("%d:%d:%d\n", h, m, s);
    return 0;
}


Measured memory_bytes: 2148
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <queue>
#define LL long long
#define inf 0x3f3f3f3f
#define lson rt<<1
#define rson rt<<1|1
#define PII pair<int,int>
#define test freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
using namespace std;
const int maxn=2e5+5;
int main()
{
    int t;
    string s;
    cin>>t>>s;
    for(int i=0;i<s.size();++i)
    {
        s[i]+=t;
        if(s[i]>'Z') s[i]-=26;
    }
    cout<<s;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;
typedef long long INT;

static const INT MOD = 998244353;

INT modPow(INT a, INT b, int mod) {
    INT x = 1;
    
    while(b > 0) {
        if (b & 1) {
	    x = (x*a)%mod;
	}

        a = (a*a)%mod;
        b /= 2;
    }

    return x;
}

INT getModInv(INT a) {
    return modPow(a, MOD-2, MOD);
}


INT f(INT N, INT M, INT K) {
    INT s = 0;
    INT c = 1;
    INT c1 = N-1;
    INT c2 = 1;
    INT d = modPow(M-1, N, MOD);
    INT d1 = getModInv(M-1);

    for(INT k=0; k<K+1; ++k) {
        d = d*d1%MOD;
        s = (s + c*d)%MOD;
	
        c = c*c1%MOD*getModInv(c2)%MOD;
        c1 -= 1;
        c2 += 1;
    }

    return (s*M)%MOD;
}


int main(void) {
    INT N, M, K;

    cin >> N >> M >> K;

    if (M == 1 and N == K+1) {
	cout << 1 << std::endl;
    } else {
	cout <<  f(N,M,K) << std::endl;
    }
}


Measured memory_bytes: 3648
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi std::vector<std::vector<int> >
#define vvl std::vector<std::vector<ll> >
#define MODs 1000000007;
typedef long long int ll;
using namespace std;

set<ll> las{-1};
const ll INF = 1000000007;
vvl cost = vv(51, 51, -1, ll);
ll calc(ll a, ll b){
  ll ret = INF;
  if(a==b) return cost[a][b] = 0;
  if(a<b) return cost[a][b] = INF;
  if(cost[a][b]!=-1) return cost[a][b];
  for(ll i=1;i<=a;i++) {
    if(las.find(i)!=las.end()) ret = min(ret, calc(a%i, b));
    else ret = min(ret, max(i, calc(a%i, b)));
  }
  return cost[a][b] = ret;
}
int main(int argc, char const *argv[]) {
  ll N, ans = 0;
  std::cin >> N;
  std::vector<ll> A(N), B(N), t(60, 1);
  for(int i=1;i<60;i++) t[i] = t[i-1] * 2;
  t[0] = 0;
  for(int i=0;i<N;i++) std::cin >> A[i];
  for(int i=0;i<N;i++) std::cin >> B[i];
  for(int i=0;i<=50;i++) for(int j=0;j<=50;j++) calc(j, i);
  for(int i=0;i<N;i++){
    if(cost[A[i]][B[i]]==INF){
      std::cout << -1 << '\n';
      return 0;
    }
  }
  while(true){
    int idx=-1, cos=0;
    for(int k=0;k<N;k++)if(cost[A[k]][B[k]]>cos) cos = cost[A[k]][B[k]], idx = k;
    if(cos==0) break;
    ll tmp = cost[A[idx]][B[idx]];
    //std::cout << tmp << '\n';
    if(las.find(tmp)==las.end()) las.insert(tmp), ans += t[tmp];
    if(cost[A[idx]][B[idx]] >= cost[A[idx]%tmp][B[idx]]) A[idx]%=tmp;
    for(int i=0;i<=50;i++) for(int j=0;j<=50;j++) cost[j][i] = -1;
    for(int i=0;i<=50;i++) for(int j=0;j<=50;j++) calc(j, i);
  }
  std::cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 504
#include <stdio.h>
static void ABC113A_DiscountFare();

#if 1
int main()
{
	//ABC111D_RobotArms();
	ABC113A_DiscountFare();
	fflush(stdout);
	return 0;
}
#endif

static void ABC113A_DiscountFare()
{
	int X, Y;
	scanf(" %d %d", &X, &Y);
	printf("%d\n", X + Y / 2);
}


Measured memory_bytes: 128
N, M = map(int, input().split())
S = list(input())
S.reverse()

ans = []
C = -1
lastZero = 0
lastStop = 0
flag = True
for i, v in enumerate(S):
    C += 1
    if v == '0':
        lastZero = i
    elif i - lastZero >= M:
        flag = False
        break
    if C == M:
        ans.append(lastZero - lastStop)
        lastStop = lastZero
        C = i - lastStop
    elif i == N:
        ans.append(C)

if flag:
    for i in range(len(ans)-1, -1, -1):
        print(ans[i],end='')
        if i > 0:
            print(' ',end='')
        else:
            print()
else:
    print(-1)

Measured memory_bytes: 6180
#include<bits/stdc++.h>
#define mem(dp,a) memset(dp,a,sizeof(dp))
#define pb(x) push_back(x)
#define m_p(x,y) make_pair(x,y)
#define f(n) for(ll i=0;i<n;i++)
#define r(n) for(ll j=0;j<n;j++)
#define all(v) (v).begin(),(v).end()
#define ff first
#define ss second
#define pi 3.14159265359
#define hs ios_base::sync_with_stdio(false);cin.tie(NULL);
using namespace std;
typedef long long int ll;
typedef long double ld;
ll ESP=1e18;
ll INF=1e9+7;

int main()
{
 hs;
 ll n;
 cin>>n;
 unordered_map<ll,ll>mp;
 f(n-1)
 {
  ll x;
  cin>>x;
  mp[x]++;
 }
 for(ll i=1;i<=n;i++)
    cout<<mp[i]<<"\n";
 return 0;

}


Measured memory_bytes: 11496
#include <iostream>

int main()
{

    int a,b,c;
    std::cin >> a >> b >> c;
    if(a<b && a<c && b<c){
        std::cout << "Yes" << std::endl;
    }else{
        std::cout << "No" << std::endl;
    }

    return 0;
}

Measured memory_bytes: 2996
import java.util.*;
import java.io.*;

public class Main {
	public static void main (String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		String[] line = br.readLine().split(" ", n);
		ArrayList<Integer> list = new ArrayList<>();
		for (int i = 0; i < n; i++) {
		    list.add(Integer.parseInt(line[i]));
		}
		ArrayList<Integer> ans = new ArrayList<>();
		while (list.size() > 0) {
		    for (int i = list.size() - 1; i >= 0; i--) {
		        if (list.get(i) > i + 1) {
		            System.out.println(-1);
		            return;
		        }
		        if (list.get(i) == i + 1) {
		            list.remove(i);
		            ans.add(i + 1);
		            break;
		        }
		    }
		}
		StringBuilder sb = new StringBuilder();
		for (int i = ans.size() - 1; i >= 0; i--) {
		    sb.append(ans.get(i)).append("\n");
		}
		System.out.print(sb);
    }
}



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

using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;
typedef vector < vector<ll> > Mat;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int N;
ll K, A[int(1e5+5)], cnt[60];

int main(){
  cin >> N >> K;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    for (int j = 0; j < 60; j++){
      if ((A[i] & ((ll)1<<j)) != 0) cnt[j]++;
    }
  }

  ll now = 0, ans = 0;
  for (int j = 59; j >= 0; j--){
    if (N - cnt[j] <= cnt[j]){
      ans += ((ll) 1 << j) * cnt[j];
    }else{
      if (now + ((ll)1 << j) <= K){
        ans += ((ll)1 << j) * (N - cnt[j]);
        now += (ll) 1 << j;
      }else{
        ans += ((ll)1<<j) * cnt[j];
      }
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 4388
n=int(input())
a=[int(input())for i in range(n)]
vis=[0]*n
i=0
cnt=0
while True:
    next=a[i]
    cnt+=1
    if vis[next-1]==1:#一度来たことがある点であればbreak
        print(-1)
        exit()
    vis[next-1]=1#一度光った点は記録
    if next==2:
        break
    i=next-1
print(cnt)


Measured memory_bytes: 7888
// 参考
// https://techracho.bpsinc.jp/jhonda/2019_08_05/78537

// Input macro
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! stdin {
    () => {{
        use std::io::Read;
        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        s
    }};
}

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

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

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

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

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

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

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

// Test Code
macro_rules! test {
    ($($input:expr => $output:expr),* $(,)*) => {
        #[test]
        fn solve_test() {
            $(
                assert_eq!(solve($input), $output);
            )*
        }
    };
}

test! {
r"21
" => r"27",

r"12
" => r"36"
}

use std::cmp;
use std::collections::HashSet;
use std::f32::MAX;

fn main() {
    println!("{}", solve(&stdin!()));
}

fn solve(src: &str) -> String {
    input! {
        source = src,
        m: i32
    }

    (48 - m).to_string()
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
int main(){
    int n;
    while(cin >> n){
        if(n == 0) break;
        vector<pair<double,string> > vec;
        rep(j,n){
            string name;
            int price,A,B,C,to_flower,E,num,sell,flag;
            cin >> name >> price >> A >> B >> C >> to_flower >> E >> num >> sell >> flag;
            double sum_time = A+B+C+(to_flower+E)*flag;
            double income = num*sell*flag - price;
            double efficiency = income/sum_time;
            vec.push_back(make_pair(-efficiency,name));
        }
        sort(vec.begin(),vec.end());
        rep(i,vec.size()){
            cout << vec[i].second << endl;
        }
        cout << '#' << endl;
    }
    return 0;
}



Measured memory_bytes: 3224
N, M = map(int, raw_input().split())
ks_s = []
for i in range(M):
    ks_s.append(map(int, raw_input().split()))

ps = map(int, raw_input().split())

ans = 0
for i in range(2**N):
    flag = True
    for j in range(M):
        p = ps[j]
        k = ks_s[j][0]
        num_on = 0
        for l in range(1, k+1):
            s = ks_s[j][l]
#            print i, j, l, s, bin(i), bin(1<<s)                                                       
            if 1 << s-1 & i:
                num_on = num_on + 1
        if num_on % 2 != p:
            flag = False
#            break                                                                                     

    if flag:
        ans = ans + 1

print ans


Measured memory_bytes: 2692
N,K = map(int,input().split())
dict = {}
for i in range(N):
  a,b = map(int,input().split())
  if(a in dict): dict[a] += b
  else: dict[a] = b

count = 0
ans = 0
for k, v in sorted(dict.items()):
   count += v
   if(count >= K): 
    ans = k
    break
print(ans)

Measured memory_bytes: 14560
#include<iostream>
#include<cmath>

using namespace std;

int main() {
    long a;
    string str;
    cin >> a >> str;
    int index;
    for (index=0; index<str.size(); ++index) {
        if (str[index] == '.') break;
    }
    string str1 = str.substr(0, index);
    string str2 = str.substr(index+1);
    int b = stoi(str1+str2);
    string ans = to_string(a*b);
    if (ans.size() <= 2) {
        cout << 0 << endl;
        return 0;
    }
    ans = ans.substr(0, ans.size()-2);
    cout << ans << endl;
}


Measured memory_bytes: 3172
#include<bits/stdc++.h>
 
using namespace std;
using S = set<long long>;
using D = deque<long long>;
using L = vector<long long>;
using M = map<int,long long>;
using A = vector<vector<long long>>;
using Q = priority_queue<long long>;
using U = unordered_map<int,long long>; //mapとの違いはkeyの順番を保持していない

#define sorted(vector) sort(vector.begin(),vector.end()) //O(nlongn)
#define vmin(vector) *min_element(vector.begin(),vector.end()) //O(N)
#define vmax(vector) *max_element(vector.begin(),vector.end()) //O(N)
#define vsum(vector) accumulate(vector.begin(),vector.end(),0) //O(N)
#define vcount(vector,a) count(vector.begin(), vector.end(),a) //O(N)
#define bisect_left(vector,a) (lower_bound(vector.begin(),vector.end(),a)-vector.begin())
#define bisect_right(vector,a) (upper_bound(vector.begin(),vector.end(),a)-vector.begin())
#define vfind(vector,a) find(vector.begin(), vector.end(), a) != vector.end() //遅いからあんまり使うな
//存在確認はmap!!!!!!!!!!!!!か配列に埋め込んでcontinueで回避
//__gcd(a,b)はコンパイラがGCC時のみ

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    long long n,m,l,r,ll,rr;
    cin>>n>>m;
    ll=0;
    rr=1e18;

    for(int i=0  ;i<m  ;i++){
        cin>>l>>r;
        ll=max(l,ll);
        rr=min(r,rr);
    }
    long long z=0;
    cout<<max(z,rr-ll+1)<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <stdio.h>
#include <cmath>
#include <cfloat>
#include <algorithm>
#include <numeric>
#include <vector>
#include <iterator>
#include <set>
#include <map>
using namespace std;

const double PI=acos(-1);

int main(){
    long n, cnt = 0;
    cin >> n;
    vector<long long> l(n);
    for(int i = 0; i < n; i ++){
        int t = 0;
        cin >> l[i];
        while(l[i]%2 == 0){
            l[i] /= 2;
            t++;
        }
        cnt += t;
    }
    cout << cnt << endl;
    return 0;
}

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

int main()
{
	int i, Q, l[100001], r[100001];
	scanf("%d", &Q);
	for (i = 1; i <= Q; i++) scanf("%d %d", &(l[i]), &(r[i]));
	
	int j, p, count[100001] = {};
	for (i = 3; i <= 100000; i++) {
		count[i] = count[i-1];
		
		for (p = 2; p * p <= i; p++) if (i / p * p == i) break;
		if (p * p <= i) continue;
		
		j = (i + 1) / 2;
		for (p = 2; p * p <= j; p++) if (j / p * p == j) break;
		if (p * p <= j) continue;
		
		count[i]++;
	}
	
	for (i = 1; i <= Q; i++) printf("%d\n", count[r[i]] - count[l[i]-1]);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/

const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

ll modpow(ll x, ll n){
    if(n == 0) return 1;

    ll res = modpow(x, n/2);
    if(n%2 == 0) return res*res%mod;
    else return res*res%mod*x%mod;
}

ll power(ll x, ll n){
    if(n == 0) return 1;

    ll res = power(x, n/2);
    if(n%2 == 0) return res*res;
    else return res*res*x;
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };

/* <--------------------------------------------> */

struct s{
    int h1, w1, h2, w2;
};

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

    int h, w; cin >> h >> w;
    vector< vector<int> > a(h+5, vector<int>(w+5, 0));
    for(int i=1; i<=h; ++i) for(int j=1; j<=w; ++j) cin >> a[i][j];

    vector
 ans;

    for(int i=1; i<=h; ++i){
        if(i%2 == 1){
            for(int j=1; j<=w; ++j) if(a[i][j]%2 == 1) {
                if(i==h && j==w) continue;
                else if(j == w) { ans.push_back({i, j, i+1, j}); ++a[i+1][j]; }
                else { ans.push_back({i, j, i, j+1}); ++a[i][j+1]; }
            }
        }
        else{
            for(int j=w; j>0; --j) if(a[i][j]%2 == 1) {
                if(i==h && j==1) continue;
                else if(j == 1) { ans.push_back({i, j, i+1, j}); ++a[i+1][j]; }
                else { ans.push_back({i, j, i, j-1}); ++a[i][j-1]; }
            }
        }
    }

    cout << ans.size() << endl;
    for(auto s:ans) printf("%d %d %d %d\n", s.h1, s.w1, s.h2, s.w2);

	return 0;
}


Measured memory_bytes: 5232
import java.util.*

class Edge(a: Int, b: Int, num: Int) {
    var a = a
    var b = b
    var num = num

}

class Connection(node: Int, num: Int) {
    val node = node
    val num = num
}

fun tra(node: Int, save: Array<Int>, children: Array<MutableList<Int>>): Int {
    for (i in children[node]) {
        save[node] += tra(i, save, children)
    }
    return save[node]
}

fun main(args: Array<String>){
	val cin = Scanner(System.`in`)
    val n = cin.nextInt()
    val m = cin.nextInt()

    val connect = Array<MutableList<Int>>(n, {mutableListOf()})
    val edges = Array<Edge>(m, { i -> Edge(cin.nextInt() - 1, cin.nextInt() - 1, i)})

    if (m % 2 == 1) {
        println(-1)
        return
    }

    for (i in 0..m-1) {
        val a = edges[i].a
        val b = edges[i].b
        connect[a].add(b)
        connect[b].add(a)
    }

    val queue: MutableList<Int> = mutableListOf(0)
    val parent = Array<Int>(n, { -1 })
    val save = Array<Int>(n, { 0 })
    val exist = Array<Boolean>(n, { false })
    val children = Array<MutableList<Int>>(n, { mutableListOf()})
    exist[0] = true

    while (queue.size != 0) {
        val now = queue.removeAt(0)
        for (c in connect[now]) {
            if (c != parent[now] && (c > now || exist[c] == false)) {
                save[now] += 1
                if (exist[c] == false) {
                    parent[c] = now
                    children[now].add(c)
                    exist[c] = true
                    queue.add(c)
                }
            }
        }
    }

    tra(0, save, children)

    for (e in edges) {
        if (parent[e.a] == e.b) {
            if (save[e.a] % 2 == 0) {
                print(e.b+1)
                print(" ")
                println(e.a+1)
            } else {
                print(e.a+1)
                print(" ")
                println(e.b+1)
            }
        } else if (parent[e.b] == e.a) {
            if (save[e.b] % 2 == 0) {
                print(e.a+1)
                print(" ")
                println(e.b+1)
            } else {
                print(e.b+1)
                print(" ")
                println(e.a+1)
            }
        } else {
            if (e.a > e.b) {
                print(e.b+1)
                print(" ")
                println(e.a+1)
            } else {
                print(e.a+1)
                print(" ")
                println(e.b+1)
            }
        }
    }
}

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

const string YES = "Yes";
const string NO = "No";

void solve(std::string S, std::string T) {
	for(int i   = 0;i<S.size();i++){
      if(S.substr(i)+S.substr(0,i) == T){cout<<YES;return;}}
  cout<<NO;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You
// use the default template now. You can remove this line by using your custom
// template)
int main() {
  std::string S;
  std::cin >> S;
  std::string T;
  std::cin >> T;
  solve(S, T);
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	static Scanner sc = new Scanner(System.in);
	static String st = sc.nextLine();
	static char[] str = st.toCharArray();
	public static void main(String[] args) {

		String order = null;
		int q = Integer.parseInt(sc.nextLine());

		for (int i = 0; i < q; i++) {
			order = sc.nextLine();

			String[] od = order.split(" ");

			switch(od[0]) {
				case("replace"):
					replace(od);
				continue;
				case("reverse"):
					reverse(od);
				continue;
				case("print"):
					print(od);
				continue;
				default:
				continue;
			}
		}


	}
	private static void print(String[] od) {
		int n = Integer.parseInt(od[1]);
		int m = Integer.parseInt(od[2]);

		for (int i = n; i <= m; i++) {
			System.out.print(str[i]);
		}
		System.out.println();

	}
	private static void reverse(String[] od) {
		int n = Integer.parseInt(od[1]);
		int m = Integer.parseInt(od[2]);
		char[] st_tmp = new char[m - n + 1];
		int j = 0;

		for (int i = n; i <= m; i++) {
			st_tmp[j] = str[i];
			j++;
		}

		j--;
		for (int i = n; i <= m; i++) {
			str[i] = st_tmp[j];
			j--;
		}

	}
	private static void replace(String[] od) {
		int n = Integer.parseInt(od[1]);
		int m = Integer.parseInt(od[2]);
		char[] st_rep = od[3].toCharArray();
		int j = 0;

		for (int i = n; i <= m; i++) {
			str[i] = st_rep[j];
			j++;
		}

	}

}



Measured memory_bytes: 31336
using System;
using System.Linq;
using System.Collections;

namespace B
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            bool answer = false;

            for (int i = 1; i < 10; i++)
            {
                if(n % i == 0)
                {
                    for (int j = i; j < 10; j++)
                    {
                        if(n == i*j)
                        {
                            answer = true;
                            break;
                        }
                    }
                }
            }

            Console.WriteLine(answer? "Yes" : "No");
        }
    }
}


Measured memory_bytes: 13140
import itertools
import math
n = int(input())
points = []
for i in range(n):
    point = list(map(int,input().split()))
    points.append(point)
length = 0
for root in itertools.permutations(points):
    # print(root)
    for i in range(n-1):
        lengthi = math.sqrt((root[i][0]-root[i+1][0])**2+(root[i][1]-root[i+1][1])**2)
        # print(lengthi)
        length += lengthi
    # print(length)



print(length/(math.factorial(n)))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define itn int
#define nibu(K,x) binary_search(K.begin(),K.end(),x)
#define rep**(i,n) for(int i=0;i<n;i++)
#define all(x) x.begin(),x.end()
#define sz(x) x.size()
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define out(x) cout<<x<<endl
#define put(x) out(x)
#define in(x) cin>>x
#define maxx(a,b,c) max(a,max(b,c))
#define minn(a,b,c) min(a,min(b,c))
using ll = long long;
using vl = vector<ll>;
using vs = vector<string>;
const double pi = 3.14159265358979;
const ll mod = 1000000007;

int main() {
itn a,b;
  in(a>>b);
  if(b%a==0) out(a+b);
  else out(b-a);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll mod=1e9+7;
int main()
{
    ll n;
    cin>>n;
    vector<ll> dp(n+2,0);
    dp[0]=1;
    for(int i=0;i<n+1;i++)
    {
        for(int j=0;j<i-2;j++)
        {
            dp[i]+=dp[j];
            dp[i]%=mod;
        }
    }
    cout<<dp[n]<<endl;
    return 0;
}


Measured memory_bytes: 3632
S = input()
k = 0
if S[0] == 'A' and S[2:-1].count('C') == 1:
    for i in range(len(S)):
        if S[i].isupper():
            if k == 2:
                print('WA')
                exit()
            k += 1
    print('AC')
else:
    print('WA')

Measured memory_bytes: 3060
// 物极必反

#include <bits/stdc++.h>

#define append push_back

using namespace std;
using ll = long long;

const int N = 5e5 + 3;
const int M = 1e6 + 7;
const long long MOD = 1e9 + 7;
const long long INF = 1e18 + 9;
const int SM = 1e3 + 5;
const int logN = 22, BL = 400;
const long double EPS = 1e-14;
const int dx[] = {1, 0, 0, -1, -1, 1, -1, 1};
const int dy[] = {0, 1, -1, 0, -1, 1, 1, -1};

void debug(){
	cerr << "\n";
}
template<typename Type1, typename... Type2>
void debug(Type1 a, Type2... b) {
    cerr << a << " ";
    debug(b...);
}

int main(){
    // freopen(".in", "r", stdin);
    // freopen(".out", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    long double a, b, c; cin >> a >> b >> c;

    if(sqrt(a) + sqrt(b) + EPS < sqrt(c)) cout << "Yes";
    else cout << "No";

    return 0;
}


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

int facctorialMethod(int k){
    int sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}



int main() {
  int N;
  cin >> N ;
  vector<int> p(N); 
  vector<int> q(N); 
  rep(i, N) cin>>p[i];
  rep(i, N) cin>>q[i];
  vector<int> a(N);
  
  rep(i, N){
  	a[i] = i + 1;
  }
  map<vector<int>, int> mp;
  
  //vector<int> p(N); 
  
  do{
  	mp[a] = mp.size();
  }while(next_permutation(a.begin(), a.end()));
  
    
  cout<<(abs(mp[q]- mp[p]))<<endl;
}

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

using namespace std;

int main(){

	int sz;
	long long int tmp, ans = 0;
	string s;
	vector<int> v, d;

	cin>> s;
	sz = s.size();
	d.resize(sz, 0);
	v.resize(2040, 0);

	tmp = 1;
	for (int i = 0;i < sz;i++) {
		d[i] = tmp % 2019;
		tmp = 10 * d[i];
		//cout << d[i] << endl;
	}

	v[0] = 1;

	tmp = 0;
	for (int i = 0;i < sz;i++) {
		/*for (int j = 0;j < 2040;j++) {
			if (v[j] > 0) cout << j << " ";
		}
		cout << " #" << endl;*/

		tmp += (int)(s[sz - i - 1]-'0')*d[i];
		tmp = tmp % 2019;
		//cout << tmp << endl;
		ans += v[tmp];
		//if (v[tmp] > 0) cout << i << " " << v[tmp] << endl;
		v[tmp]++;
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 4384
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const int INF = 100000000;
ll i,j,k;
int main(){
    ll n,k;cin>>n>>k;//n:candle総本数 k:灯したいcandle数
    vector<ll> x(n+1);
    for(i=0;i<n;i++){cin>>x[i];}
    x[n]=0;
    sort(x.begin(),x.end());
    
    ll num;
    for(num=0;x[num]!=0;num++);//0の場所
    
    ll mini=100000000000000,ans=100000000000000;
    for(i=0;i<=num;i++){
        if(i+k>n){break;}//はみでてる
        if(num-i>k){continue;}//0を含むような幅kの区間を探索
        mini=min(-2*x[i]+x[i+k],2*x[i+k]-x[i]);
        ans=min(ans,mini);
    }

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

Measured memory_bytes: 1024
#include "bits/stdc++.h"
#define rep(i, n) for (int (i) = 0; i < (n); ++i)

int n, k, cnt;
int main() {
    scanf("%d %d", &n, &k);
	cnt = (n - 1) * (n - 2) / 2;
	if (cnt < k) printf("-1\n");
	else {
		printf("%d\n", n - 1 + cnt - k);
		cnt -= k;
		rep(i, n - 1) printf("1 %d\n", i + 2);
		rep(i, n - 2) {
			for (int j = i + 1; j < n - 1; ++j) {
				if (cnt == 0) return 0;
                printf("%d %d\n", i + 2, j + 2);
				cnt--;
			}
		}
	}
}

Measured memory_bytes: 256
n=int(input())
fxy=[[] for _ in range(n)]
for i in range(n):
    x,y=map(int, input().split())
    fxy[i].append(x-y)
    fxy[i].append(x+y)
fxy.sort()
ans=fxy[-1][0]-fxy[0][0]
fxy.sort(key=lambda x: x[1])
ans=max(ans,fxy[-1][1]-fxy[0][1])
print(ans)

Measured memory_bytes: 46164
#include "bits/stdc++.h"
using namespace std;

/* macro */
#define rep(i,a,b) for(int i=a;i<b;i++)
#define revrep(i,a,b) for(int i = a; i > b; i--)
#define int long long
#define exist(s,e) ((s).find(e)!=(s).end())
#define all(v) (v).begin(), (v).end()
#define each(s,itr) for(auto (itr) = s.begin(); (itr) != s.end(); (itr)++)
#define sum(v) accumulate(all(v), (0LL))
#define isin(a, b, c) (b <= a && a <= c)
#define println cout << "\n";
#define sz(v) (int)v.size()
#define bin(x) static_cast<bitset<16> >(x)


/* alias */
template<class T> using vec = vector<T>;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef tuple<int, int, int> ti;
typedef map<int, int> mi;
typedef set<int> si;


/* constant */
const int inf = 1LL << 62;
const int mod = 1e9 + 7;
const int dx[8]={1,0,-1,0,-1,1,-1,1};
const int dy[8]={0,1,0,-1,-1,-1,1,1};
const string alphabet = "abcdefghijklmnopqrstuvwxyz";

/* io_method */
int input(){int tmp;cin >> tmp;return tmp;}
string raw_input(){string tmp;cin >> tmp;return tmp;}
template<class T> void printx(T n){cout << n;}
template<class T, class U> void printx(pair<T, U> p){cout << "(" << p.first << "," << p.second << ")";}
template<class T, class U, class V> void printx(tuple<T, U, V> t){cout << "{" << get<0>(t) << "," << get<1>(t) <<"," << get<2>(t) << "}" << endl;}
template<class T> void printx(vector<T> v){cout << "{";rep(i,0,v.size()){printx(v[i]);if(i != v.size()-1)printx(",");}cout << "}";}
template<class T> void print(T n){printx(n);cout << endl;}
template<class T> void print(set<T> s){cout << "{";each(s, e){if(e != s.begin()) printx(",");printx(*e);}cout << "}" << endl;}
template<class T, class U> void print(map<T, U> mp){cout << "{";each(mp, e){cout << "(" << e -> first << "," << e -> second << ")";}cout << "}" << endl;}
template<class T> void printans(vec<T> v){rep(i,0,sz(v)){cout << v[i] << (i == sz(v) - 1 ? "" : " ");}cout << endl;}


/* general_method */
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<class T>T cut(T &a, int l, int r){return T(a.begin()+l, a.begin()+r);}


/* math_method */
int ceil(int a, int b){return a / b + (a % b > 0);}


/* main */

int n;
vi arr;
void in(){
    cin >> n;
    rep(i,0,n) arr.push_back(input());
}

int dp[101010][2];
int dfs(int i, bool flag){

    if(i == n - 1) return (flag ? -arr[i] : arr[i]);
    if(dp[i][flag] > -1) return dp[i][flag];
    int ans = 0;
    chmax(ans, (flag ? arr[i] : -arr[i]) + dfs(i + 1, true)); //do
    chmax(ans, (flag ? -arr[i] : arr[i]) + dfs(i + 1, false)); // not do

    return dp[i][flag] = ans;

}

void solve(){
    memset(dp, -1, sizeof(dp));
    print(dfs(0, false));

}

signed main(){

    cin.tie(0);
    ios::sync_with_stdio(false);
    in();
    solve();
    
}

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

int main() {

	char s[10];
	scanf("%s", s);

	int n = strlen(s);
	if(!(n%2)) {
        n--;
        int ans = 0;
        for(int i = 1; i <= n; i += 2)
            ans = ans*100 + 9;
        printf("%d", ans);
	}
	else {
        int a = 0, t = 1;
        for(int i = 0; i < n; i++) {
            a = a*10 + s[i]-'0';
            t *= 10;
        }
        t /= 10;
        int ans = 0;
        for(int i = 1; i <= n-2; i += 2)
            ans = ans*100 + 9;
        ans += a - t + 1;
        printf("%d", ans);
	}

    return 0;
}

Measured memory_bytes: 256
<?php

$lines = array_map("trim", file("php://stdin"));
list($height, $width) = explode(" ", array_shift($lines));
$height = intval($height);
$width = intval($width);
$map = array_map("str_split", $lines);
$canDraw = true;
foreach($map as $y => $row) {
  foreach($row as $x => $char) {
    if ($char !== "#") {
      continue;
    }

    $neighboars = getNeighborsChar($map, $x, $y);
    $notBlackValues = array_filter($neighboars, function($v) {
      return $v !== "#";
    });
    if (count($notBlackValues) === count($neighboars)) {
      $canDraw = false;
      break;
    }
  }

  if (!$canDraw) {
    break;
  }
}

echo $canDraw ? "Yes" : "No";

function getCharOn($map, $x, $y) {
  if (count($map) <= $y || $y < 0) {
    return null;
  }
  
  $row = $map[$y];
  if (count($row) <= $x || $x < 0) {
    return null;
  }

  return $row[$x];
}

function getNeighborsChar($map, $x, $y) {
  return [
    'right' => getCharOn($map, $x + 1, $y),
    'left' => getCharOn($map, $x - 1, $y),
    'up' => getCharOn($map, $x, $y - 1),
    'down' => getCharOn($map, $x, $y + 1)
  ];
}

Measured memory_bytes: 4728
#include <bits/stdc++.h>
#define uint unsigned long long
#define ll long long
#define db double
#define ls rt << 1
#define rs rt << 1 | 1
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define X first
#define Y second
#define pcc pair<char, char>
#define vi vector<int>
#define vl vector<ll>
#define rep(i, x, y) for(int i = x; i <= y; i ++)
#define rrep(i, x, y) for(int i = x; i >= y; i --)
#define ept 1e-9
#define INF 0x3f3f3f3f
#define sz(x) (x).size()
using namespace std;
inline 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;
}
inline ll read1()
{
	ll 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;
}
ll A, B, C, K;
int main() 
{
    cin >> A >> B >> C >> K;
    if (K & 1) cout << B - A;
    else cout << A - B;
    return 0;
}


Measured memory_bytes: 256