akhauriyash/Code-Regression huggingface dataset:
#import sys
MOD = 10 ** 9 + 7
INFI = 10**10
#input = sys.stdin.readline
import math

import itertools

#import bisect

import copy
from functools import lru_cache

def sosuhante(n):
    for k in range(2, int(math.sqrt(n))+1):
        if n% k ==0:
            return False
    return True
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def kingaku(a,b,n):
    keta=len(str(n))
    return a*n+b*keta

def my_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default

#    h,w,a,b = map(int, input().split())
#    c = [[0 for j in range(n)] for i in range(n)]



def main():
    a=[-1 for i in range(9)]
    a[0],a[1],a[2]=map(int,input().split())
    a[3], a[4], a[5] = map(int, input().split())
    a[6], a[7], a[8] = map(int, input().split())
    n=int(input())
    b=[0 for i in range(9)]
    for i in range(n):
        temp=int(input())
        if temp in a:
            b[a.index(temp)]=1
    ans="No"
    if b[0]+b[1]+b[2]>=3:
        ans="Yes"
    elif b[3]+b[4]+b[5]>=3:
        ans="Yes"
    elif b[6]+b[7]+b[8]>=3:
        ans="Yes"
    elif b[0]+b[3]+b[6]>=3:
        ans="Yes"
    elif b[1]+b[4]+b[7]>=3:
        ans="Yes"
    elif b[2]+b[5]+b[8]>=3:
        ans="Yes"
    elif b[0]+b[4]+b[8]>=3:
        ans="Yes"
    elif b[2]+b[4]+b[6]>=3:
        ans="Yes"
    print(ans)
if __name__ == "__main__":
    main()

Measured memory_bytes: 38384
S = input()

#initialize
IsKaibun = 'No'

N = len(S)

def check_kaibun( mojiretu ):
    names = len(mojiretu)
    IsKaibunLocal = 'Yes'
    for name in range((names + 1) // 2):
        if mojiretu[name] != mojiretu[names - 1 - name]:
            IsKaibunLocal = 'No'

    return IsKaibunLocal

#pre check
if N%2 != 1 and N < 3 and N >  99 :
    PRE_CHECK = 1

#1st check
IsKaibun = check_kaibun(S)

#2nd check
if IsKaibun == 'Yes':
    IsKaibun =  check_kaibun(S[ 0 : int((N-1)/2) ])

#3rd check
if IsKaibun == 'Yes':
    IsKaibun = check_kaibun(S[ int((N+3)/2 - 1) : N ])

#output
print(IsKaibun)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N,M;
  cin>>N>>M;
  vector<int>record(2*M,0);
  vector<int>ans(N);
  for(int i=0;i<2*M;i++){
    cin>>record.at(i);
  }
  for(int i=0;i<2*M;i++){
    int n;
    n=record.at(i);
    ans.at(n-1)=ans.at(n-1)+1;
  }
  for(int i=0;i<N;i++){
    cout<<ans.at(i)<<endl;
  }
}

Measured memory_bytes: 256
from collections import deque
from itertools import chain
H, W = map(int, input().split())
G = chain.from_iterable([[s == '#' for s in input()] for _ in range(H)])
dist = [0]*(H*W)
B = deque([i for i, g in enumerate(G) if g])
visited = set(B)
while B:
    vij = B.pop()
    for dij in (W, -W, 1, -1):
        nij = vij + dij
        if (dij == 1 and not nij % W) or (dij == -1 and not (nij+1) % W) or not (0 <= nij < H*W) or nij in visited:
            continue
        visited.add(nij)
        dist[nij] = 1 + dist[vij]
        B.appendleft(nij)
print(max(dist))


Measured memory_bytes: 136508
#include <bits/stdc++.h>
#define SZ(x) ((int)(x).size())
typedef long long ll;
using namespace std;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cout.setf(ios::fixed); cout.precision(20);
    int n; cin >> n;
    vector<int> ans(n + 10, 0);
    vector<bool> vis(n + 10, false);
    vector<vector<pair<int, int>>> adj(n + 10);
    for (int i = 1; i < n; i++) {
        int u, v, w; cin >> u >> v >> w;
        adj[u].emplace_back(v, w);
        adj[v].emplace_back(u, w);
    }
    queue<int> q;
    q.push(1); vis[1] = true;
    while (!q.empty()) {
        int v = q.front(); q.pop();
        for (auto &edge : adj[v]) {
            int u = edge.first, w = edge.second;
            if (vis[u]) {
                continue;
            }
            if (w % 2 == 0) {
                ans[u] = ans[v];
            } else {
                ans[u] = !ans[v];
            }
            q.push(u);
            vis[u] = true;
        }
    }
    for (int i = 1; i <= n; i++) {
        cout << ans[i] << "\n";
    }
}

Measured memory_bytes: 6912
import java.util.*;

class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int counter = 0;
        for (int i=0; i<3; i++) {
            if (s.charAt(i) == '1') counter++;
        }
        System.out.println(counter);
    }
}


Measured memory_bytes: 21972
#include<stdio.h>

int main(void) {
	char b,s[4];
	scanf("%c", &b);
	s['A'] = 'T';
	s['T'] = 'A';
	s['C'] = 'G';
	s['G'] = 'C';
	printf("%c", s[b]);

	return 0;
}

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

using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

#define FOR(k,m,n) for(ll (k)=(m);(k)<(n);(k)++)
#define REP(i,n) FOR((i),0,(n))
#define WAITING(str) int str;std::cin>>str;
#define DEBUGING(str) cout<< #str << " " str<<endl

constexpr int INF = (1 << 30);
constexpr ll INFL = (1ll << 60);
constexpr ll MOD = 1000000007;// 10^9+7


int N;
vector<ll> a;
vector<vector<ll>> dp;

ll dfs(int l, int r)
{
    if(dp[l][r]!=INFL)return dp[l][r];
    ll res = INFL;
    FOR(k,l+1,r)
    {
       res = min(res, dfs(l,k) + dfs(k,r)); 
    }
    return dp[l][r] = res + a[r]-a[l];
}

int main()
{
    cin>>N;
    a.resize(N+1,0);
    dp.resize(N+1,vector<ll>(N+1,INFL));
    REP(i,N)
    {
        cin>>a[i+1];
        dp[i][i+1]=a[i+1];
    }
    REP(i,N)a[i+1]+=a[i];

    cout << dfs(0,N) - a.back() << endl;
    return 0;
}


Measured memory_bytes: 1536
#include <cstdio>
#include <cstring>
#define M 5070721
#define NIL (-1)
#define L 14
typedef long long ll;
char H[M][L];

int getChar(char ch){
	if(ch=='A')return 1;
	else if(ch=='C')return 2;
	else if(ch=='G')return 3;
	else if(ch=='T')return 4;
	else return 0;
}

ll getKey(char str[]){
	ll sum=0,p=1,i;
	int len=strlen(str);
	for(i=0;i<len;i++){
		sum+=p*(getChar(str[i]));
		p*=5;
	}
	return sum;
}

int h1(int key){
	return key%M;
}

int h2(int key){
	return 1+(key%(M-1));
}

int find(char str[]){
	ll key,i,h;
	key=getKey(str);
	for(i=0;;i++){
		h=(h1(key)+i*h2(key))%M;
		if(strcmp(H[h],str)==0)return 1;
		else if(strlen(H[h])==0)return 0;
	}
	return 0;
}

int insert(char str[]){
	ll key,i,h;
	key=getKey(str);
	for(i=0;;i++){
		h=(h1(key)+i*h2(key))%M;
		if(strcmp(H[h],str)==0)return 1;
		else if(strlen(H[h])==0){
			strcpy(H[h],str);
			return 0;
		}
	}
	return 0;
}


int main(void){
	int n;
	char str[L],com[9];
	for(int i=0;i<M;i++){
		H[i][0]='\0';
	}
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%s %s",com,str);
		if(com[0]=='i'){
			insert(str);
		}else{
			if(find(str)){
				printf("yes\n");
			}else{
				printf("no\n");
			}
		}
	}
	return 0;
}

Measured memory_bytes: 72004
#include <bits/stdc++.h>
using namespace std;
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
typedef long long int ll;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int h, w, k, ans = 0;
    cin >> h >> w >> k;
    char c[h][w];
    rep(i, 0, h)
            rep(j, 0, w)
                cin >> c[i][j];
    rep(i, 0, (1 << h))
    {
        rep(j, 0, (1 << w))
        {
            int cs = 0;
            rep(l, 0, h)
                rep(p, 0, w)
                {
                    if ((i & (1 << l)) or (j & (1 << p)))
                        continue;
                    cs += (c[l][p] == '#');
                }
            if (cs == k)
                ans++;
        }
    }
    cout << ans;
    return 0;
}

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

int main (){
  int N,max = 0,min = INT_MAX,now;
  cin >> N;
  for (int i = 0;i < N;i++){
    cin >> now; 
    if(min > now) min = now;
    if(max < now) max = now;
  }
  cout << max - min << endl;
}

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

typedef long long ll;
using namespace std;

ll gcd(ll a, ll b) { //最大公約数
  if (b==0) return a;
  else return gcd(b, a%b);
}

ll lcm(ll a, ll b) { //最小公倍数
  return a * b / gcd(a, b);
}

ll digit_sum(ll a){ //10進桁和
  ll ans=0;
  while(a>0){
    ans+=a%10;
    a/=10;
  }
  return ans;
}



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

  if((abs(a-b)<=d&&abs(b-c)<=d)||abs(a-c)<=d){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
  return 0;
}


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


int main() {
    int n;
    cin >> n;
    int sum = 0;
    vector<int> a(n+1);
    for (int i = 1; i <= n; i++) {
        cin >> a.at(i);
    }
    for (int i = 1; i <= n; i++) {
        if (i % 2 == 1 && a.at(i) % 2 == 1) {
            sum++;
        }
    }
    cout << sum << endl;

    return 0;
}

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

int main() {
  int N, M;
  cin >> N >> M;
  
  int homework = 0;
  int kadai;
  
  for (int i = 0; i < M; i++) {
    cin >> kadai;
    homework += kadai;
  }
  
  if (homework > N) {
    cout << -1 << endl;
  } else {
    cout << N - homework << endl;
  }
}

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

int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  for (int i = 0;i<N;i++) {
    vec.at(i) += i+1;
  }
  vector<int> p(N);
  vector<int> q(N);
  
  for (int i = 0; i<N;i++) {
    cin >> p.at(i);
  }
  for (int i = 0; i < N;i++) {
    cin >> q.at(i);
  }
  
  int a,b;
  int cnt;
  do {
    cnt++;
    if (vec==p) a=cnt;
    if (vec==q) b=cnt;
  } while (next_permutation(vec.begin(),vec.end()));
  
  if (a>=b) cout << a-b << endl;
  else cout << b-a << endl;
}
  
 


Measured memory_bytes: 256
import java.util.Scanner;
     
public class Main{
    public static void main( String[] args ) throws Exception {
        Scanner in = new Scanner( System.in );
        long a = in.nextLong();
        long b = in.nextLong();
        long x = in.nextLong();
        System.out.println( ( b + x ) / x - ( a + x - 1 ) / x );
    }
}

Measured memory_bytes: 9808
#include <algorithm>
#include <bitset>
//#include <boost/multiprecision/cpp_int.hpp>
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstring>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <sstream>
#include <stdio.h>
#include <string>
#include <tuple>
#include <vector>
// namespace mp = boost::multiprecision;
using namespace std;
using ull = unsigned long long;
using ld = long double;
// using ll = boost::multiprecision::cpp_int;
using ll = long long;
#define FOR(i, N) for(ll i = 0; i < N; ++i)

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
// using int = ll;
ll gcd(ll m, ll n) {
    if(n == 0)
        return abs(m);
    return (gcd(n, m % n));
}
void putYN(bool b) {
    if(b) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}
void swap(ll &a, ll &b) {
    ll tmp = a;
    a = b;
    b = tmp;
}
ll combi(ll n, ll k) {
    ll r = 1, rr = 1;
    for(ll i = 0; i < k; ++i) {
        r *= (n - i);
        rr *= (i + 1);
        // r %= 1000000007;
        // rr %= 1000000007;
    }
    r /= rr;
    // r %= 1000000007;
    return r;
}

int main() {
    ll a;
    string s;
    cin >> a >> s;
    if(a>=3200){
        cout << s << endl;
    }else{
        cout << "red" << endl;
    }
    return 0;
}


Measured memory_bytes: 888
#!python3.8
# -*- coding: utf-8 -*-
# aising2020/aising2020_b
import sys

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [i2s() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

def main():
    N = i2n()
    a = i2nn()
    ans = 0
    for i in range(N):
        ans += bool((i + 1) % 2 and a[i] % 2)
    print(ans)
    return

main()


Measured memory_bytes: 9208
import java.util.*;

public class Main {
	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		LinkedList<Integer> ll = new LinkedList<>();
		
		int H = 999;
		int W = 999;
		
		int cnt = 0;
		
		//?????????????´?
		while(H != 0 || W != 0) {
			H = sc.nextInt();
			W = sc.nextInt();
			if(H == 0 && W == 0) {
				break;
			} else {
				ll.add(H);
				ll.add(W);
				cnt+=2;
			}
		}
		
		int k = 0;
		while(k < cnt) {
			int j = 0;
			while(j < ll.get(k)) {
				int i = 0;
				while(i < ll.get(k+1)) {
					System.out.print("#");
					i++;
				}
				System.out.println();
				j++;
			}
			System.out.println();
			k+=2;
		}
		
	}
}

Measured memory_bytes: 35916
#include <stdio.h>

int main(void){
  
  int A;
  int B;
  int C;
  
  scanf("%d %d %d",&A,&B,&C);
  
  if(A >= B && A >= C){
    printf("%d",A * 10 + B + C);
  }
  else if(B >= A && B >= C){
    printf("%d",B * 10 + A + C);
  }
  else{
    printf("%d",C * 10 + A + B);
  }
  
  return 0;
  
}


Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<queue>
#include<set>
#include<map>
#include<stack>
#include<bitset>
using namespace std;
typedef long long LL;
const int N=4010;
int gi() {
	int w=0;bool q=1;char c=getchar();
	while ((c<'0'||c>'9') && c!='-') c=getchar();
	if (c=='-') q=0,c=getchar();
	while (c>='0'&&c <= '9') w=w*10+c-'0',c=getchar();
	return q? w:-w;
}
int f[N][N];
int main()
{
	const int mod=1e9+7;
	int n=gi(),m=gi(),k=gi(),i,j,ans=0,s;
	f[0][0]=1;
	for (i=1;i<=(n+m)/(k-1);i++) {
		for (j=s=0;j<=m;j++) {
			(s+=f[i-1][j])%=mod;
			if (j>=k) (s-=f[i-1][j-k])%=mod;
			f[i][j]=s;
			if (!((j-m)%(k-1))&&!(((j+n-1)%(k-1)))&&(i-1)*(k-1)+k-j<=n)
				(ans+=(f[i][j]-f[i-1][j])%mod)%=mod;
		}
	}
	printf("%d\n",(ans+mod)%mod);
	return 0;
}


Measured memory_bytes: 61568
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll mod4=998244853;
ll inf=1000000000000000000;
double pi=2*acos(0);
#define rep(i,m,n) for(ll i=m;i<n;i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
ll lmax(ll a,ll b){
    if(a<b)return b;
    else return a;
}
ll lmin(ll a,ll b){
    if(a<b)return a;
    else return b;
}
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(b==0)return a;
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll Pow(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}
int main(){
  int n;cin>>n;
  int a[n];
  vector<int> v;
  rep(i,0,n){
    cin>>a[i];
    v.push_back(a[i]);
  }
  if(n==2){
    cout<<"Possible"<<endl;
    return 0;
  }
  sort(v.begin(),v.end());
  int ma=v.back();
  if(ma==1){
    cout<<"Impossible"<<endl;
    return 0;
  }
  if(v[0]<(ma+1)/2){
    cout<<"Impossible"<<endl;
    return 0;
  }
  int cnt[ma+1];
  fill(cnt,cnt+ma+1,0);
  rep(i,0,n)cnt[a[i]]++;
  int t=ma/2+1;
  rep(i,t+1,ma+1){
    if(cnt[i]<=1){
      cout<<"Impossible"<<endl;
      return 0;
    }
  }
  if(ma%2==0){
    if(cnt[t-1]!=1){
      cout<<"Impossible"<<endl;
      return 0;
    }
  }
  else{
    if(cnt[t]!=2){
      cout<<"Impossible"<<endl;
      return 0;
    }
  }
  cout<<"Possible"<<endl;
}



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

int main(){
    int n;
    cin >> n;
    int ans = 0;
    vector<int> p(n);
    rep(i,n){
        cin >> p[i];
        p[i]--;
    }
    rep(i,n){
        if(i == p[i]){
            ans++;
            if(i < n - 1) swap(p[i],p[i+1]);
            else swap(p[i],p[i-1]);
        }
    }
    cout << ans << endl;
}

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

#define SZ(x) (((int)x.size()))
#define all(x) (x).begin(), (x).end()

typedef long long ll;
typedef long double ld;

using namespace std;

ll n, ans, tmp, i;

int main()
{
	cin >> n;
	for (i = 2; i * i <= n; i++)
	{
		tmp = n;
		while (tmp % i == 0)
			tmp /= i;
		if (tmp % i == 1)
			ans++;
	}
	n--;
	for (ll j = 1; j * j <= n; j++)
	{
		if (n % j == 0)
		{
			if (j >= i)
				ans++;
			if (n / j != j && n / j >= i)
				ans++;
		}
	}
	cout << ans + 1;
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int n;
    int a,b;
    scanf("%d",&n);

    a = n / 500;
    n = n % 500;

    b = n / 5;
    n = n % 5;

    printf("%d\n", (a * 1000) + (b * 5));

    return 0;
}


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

int main(){
  ll K,A,B;
  cin >> K >> A >> B;
  if(B-A<=2||A>=K){
    cout << K+1 << endl;
  }else{
    ll m = (K-(A-1))/2;
    cout << B+(B-A)*(m-1)+(K-A-1)%2 << endl;
  }
}


Measured memory_bytes: 256
N,Q = map(int, input().split())
S = input()
List = [0]
p = 0
for i in range(N-1):
  if S[i] == "A":
    if S[i+1] == "C":
      p = p + 1
      List.append(p)
    else:
      List.append(p)
  else:
    List.append(p)

List.append(0)   
for i in range(Q):
  l, r = map(int, input().split())
  if List[l-2] == List[l-1]:
    print(List[r-1] - List[l-2])
  else:
    print(List[r-1] - List[l-1])

Measured memory_bytes: 6200
n,Y=map(int,input().split())

for x in range(n+1):
  for y in range(n+1):
    z = 0 if n-x-y <= 0 else n-x-y
    if 10000*x + 5000*y + 1000*(z) == Y and x+y+z == n:
      print(x,y,z)
      exit()
print(-1,-1,-1)

Measured memory_bytes: 9192
#include <stdio.h>
# include <string.h>

int main() {
    char s[101], ns[101];
    scanf("%s", s);
    int a =3;
    
    int tam = strlen(s);
    
    for (int i = 0; i < tam; ++i)
        ns[i] = s[tam-(i+1)];
        
    ns[tam] = '\0';
    
    for (int i = 0; i < tam; ++i){
        if (ns[i] != s[i]){
            a -= 1;
           // printf("11111 \n");
            break;
            
        }
    }
    // 2 cond
    int cs2 = (tam-1)/2;
    for (int i = 0; i < cs2; ++i){
        if (ns[cs2-(i+1)] != s[i]){
            a -= 1;
            //printf("22222 \n");
            break;
            
        }
    }
    
    // 3 cond
    
    int cs3 = ((tam+3)/2)-1;
    //printf("__%d\n", cs3);
    int rr = 1;
    for (int i = cs3; i < tam; ++i){
        //printf("%d %d\n", ns[cs3-(i+1)], s[rr]);
        if (ns[i] != s[tam - rr]){
            a -= 1;
            //printf("33333 \n");
            break;
            
        }
        rr += 1;
    }
    
    if (a ==3)
        printf("Yes\n");
    else
        printf("No\n");
    
    

    return 0;
}


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

const int N = 1e4 + 4;
int a[N] , b[N];


int main() {

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

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

	long long operation = 0;
	for(int i = 0 ; i < n ; i++){
		if(a[i] < b[i]){
			operation += (b[i] - a[i]) / 2;
		}else if(a[i] > b[i]){
			operation -= (a[i] - b[i]);
		}
	}

	if(operation >= 0)puts("Yes");
	else puts("No");

}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <unordered_map>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
#include <unordered_map>
#include <fstream>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef pair<int,int> pii;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(int i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {1,-1,0,0,1,-1,1,-1};
ll dx[8] = {0,0,1,-1,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T> inline void print(T &a){
    rep(i,a.size()) cout << a[i] << " ";
    cout << "\n";
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
const int mod = 1e9 + 7;
//const int mod = 998244353;



int main(){
	ll n,m,s; cin >> n >> m >> s;
	vector<vpl> G(n);
	rep(i,m){
		ll u,v,d; cin >> u >> v >> d;
		G[u].emplace_back(v,d);
	}
	ll cnt = 0;
	vl d(n,linf);
	d[s] = 0;
	while(1){
		if(cnt >= n){
			puts("NEGATIVE CYCLE");
			return 0;
		}
		bool upd = false;
		rep(u,n){
			if(d[u] == linf) continue;
			for(auto v : G[u]){
				if(d[v.first] > d[u] + v.second){
					d[v.first] = d[u] + v.second;
					upd = true;
				}
			}
		}
		cnt++;
		if(!upd) break;
	}
	rep(i,n){
		if(d[i] == linf) puts("INF");
		else cout << d[i] << "\n";
	}
}


Measured memory_bytes: 3176
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <bitset>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define fin(ans) cout<<(ans)<<endl
#define P 1000000007
#define STI(s) atoi(s.c_str())//string to int
#define mp(p,q) make_pair(p,q)
#define pb(n) push_back(n)
#define Sort(a) sort(a.begin(),a.end())
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const int INF = INT_MAX;
const long long LLINF = 1LL<<60;
//g++ -std=c++1z temp.cpp
//./a.out

string lcs(string s, string t) {
    vvi dp(s.size() + 1, vi(t.size() + 1));

    for(int i = 0; i < s.size(); i++) {//LCS
        for(int j = 0; j < t.size(); j++) {
            if(s[i] == t[j]) {
                dp[i + 1][j + 1] = dp[i][j] + 1;
            }
            else{
                dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j]);
            }
        }
    }
    string ans = "";
    int i = (int)s.size(), j = (int)t.size();
    while (i > 0 && j > 0){
        // (i-1, j) -> (i, j) と更新されていた場合
        if (dp[i][j] == dp[i-1][j]) {
            --i; // DP の遷移を遡る
        }
        // (i, j-1) -> (i, j) と更新されていた場合
        else if (dp[i][j] == dp[i][j-1]) {
            --j; // DP の遷移を遡る
        }
        // (i-1, j-1) -> (i, j) と更新されていた場合
        else {
            ans = s[i-1] + ans; // このとき s[i-1] == t[j-1] なので、t[j-1] + res でも OK
            --i, --j; // DP の遷移を遡る
        }
    }
    return ans;
}


int main(void){ios::sync_with_stdio(false);cin.tie(0);
//////////////////////////////////////////////////////
    
    string s, t;
    cin >> s >> t;
    
    cout<<lcs(s,t)<<endl;

//////////////////////////////////////////////////////
return 0;}

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

using namespace std;
typedef long long ll;

int main() {
    int n, m; cin >> n >> m;
    vector<int> pcnt(n);
    vector<int> ac(n);
    for (int i = 0; i < m; i++) {
        int p; cin >> p;
        string s; cin >> s;
        if (ac[p-1] == 0 && s == "WA") pcnt[p-1]++;
        else if (ac[p-1] == 0 && s == "AC") ac[p-1] = 1;
    }

    int ans_c = 0;
    int ans_p = 0;
    for (int i = 0; i < n; i++) {
        ans_c += ac[i];
        if (ac[i] == 1)
            ans_p += pcnt[i];
    }
    cout << ans_c << " " << ans_p << endl;
}



Measured memory_bytes: 1024
import numpy as np,sys
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
N,M = LI()
ab = np.array([LI() for _ in range(N)])
cd = np.array([LI() for _ in range(M)])
for x in ab:
    print(np.abs(cd-x).sum(axis=1).argmin()+1)


Measured memory_bytes: 12432
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ok() puts(ok?"Yes":"No");
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef set<int> si;
typedef map<string, int> msi;
typedef greater<int> gt;
typedef priority_queue<int, vector<int>, gt> minq;
typedef long long ll;
typedef pair<ll,ll> pll;
const ll LINF = 1e18L + 1;
const int INF = 1e9 + 1;
//clang++ -std=c++11 -stdlib=libc++ 


// BFS but find dist st we can get to V in mod 3 moves.

vi to[100005];

int main() {
  int N, M; cin >>N>>M;
  rep(i,M) {
    int u, v; cin >> u>> v;
    u--; v--;
    to[u].push_back(v);
  }
  int S, T; cin >> S>>T;
  S--;T--;
  vvi dist(N, vi(3, INF));
  dist[S][0] = 0;
  queue<ii> q;
  q.push({S, 0});
  while (q.size()) {
    int v = q.front().first; 
    int l = q.front().second; q.pop();
    int nl = (l+1)%3;
    for (int u: to[v]) {
      if (dist[u][nl] != INF) continue;
      dist[u][nl] = dist[v][l] + 1;
      q.push({u, nl});
    }
  }
  int ans = dist[T][0];
  if (ans == INF) ans = -1;
  else  ans /= 3; 
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 11136
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Math;
using static System.Console;
using static exMath;
using static exReadLine;


class Program
{
    static void Main(string[] args)
    {
        string[] input = ReadLine().Split();
        int A, B;
        intReadLine(out A, out B);
        string U = ReadLine();
        if(input[0] == U)
        {
            WriteLine(A - 1 + " " + B);
        }
        else
        {
            WriteLine(A + " " + (B - 1));
        }
    }
}

static class exReadLine
{
    public static void intReadLine(out int a)
    {
        a = int.Parse(ReadLine());
    }
    public static void intReadLine(out int a, out int b)
    {
        int[] input = ReadLine().Split().Select(int.Parse).ToArray();
        a = input[0];
        b = input[1];
    }
    public static void intReadLine(out int a, out int b, out int c)
    {
        int[] input = ReadLine().Split().Select(int.Parse).ToArray();
        a = input[0];
        b = input[1];
        c = input[2];
    }
    public static void intReadLine(out int a, out int b, out int c, out int d)
    {
        int[] input = ReadLine().Split().Select(int.Parse).ToArray();
        a = input[0];
        b = input[1];
        c = input[2];
        d = input[3];
    }

    public static void longReadLine(out long a)
    {
        a = long.Parse(ReadLine());
    }
    public static void longReadLine(out long a, out long b)
    {
        long[] input = ReadLine().Split().Select(long.Parse).ToArray();
        a = input[0];
        b = input[1];
    }
    public static void longReadLine(out long a, out long b, out long c)
    {
        long[] input = ReadLine().Split().Select(long.Parse).ToArray();
        a = input[0];
        b = input[1];
        c = input[2];
    }
    public static void longReadLine(out long a, out long b, out long c, out long d)
    {
        long[] input = ReadLine().Split().Select(long.Parse).ToArray();
        a = input[0];
        b = input[1];
        c = input[2];
        d = input[3];
    }
}

static class exMath
{
    // 最大公約数
    public static int Gcd(int a, int b)
    {
        if (a < b) return Gcd(b, a);
        while (b != 0)
        {
            var r = a % b;
            a = b;
            b = r;
        }
        return a;
    }
    public static long Gcd(long a, long b)
    {
        if (a < b) return Gcd(b, a);
        while (b != 0)
        {
            var r = a % b;
            a = b;
            b = r;
        }
        return a;
    }

    // 最小公倍数
    public static long Lcm(int a, int b)
    {
        return BigMul(a, b) / Gcd(a, b);
    }
    public static long Lcm(long a, long b)
    {
        return a * b / Gcd(a, b);
    }
}

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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define UB upper_bound
#define LB lower_bound
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

// G13E_5.cpp

void mat_prod(LL a[3][3], LL b[3][3], LL c[3][3], LL MOD) { // a = b * c;
	LL d[3][3];
	inc(i, 3) {
	inc(j, 3) {
		d[i][j] = 0;
	}
	}
	
	inc(i, 3) {
	inc(j, 3) {
	inc(k, 3) {
		(d[i][j] += b[i][k] * c[k][j]) %= MOD;
	}
	}
	}
	
	inc(i, 3) {
	inc(j, 3) {
		a[i][j] = d[i][j];
	}
	}
	
	return;
}

void mat_exp(LL a[3][3], LL b[3][3], LL c, LL MOD) { // a = b ^ c;
	LL t[60][3][3];
	if(true) {
		inc(i, 3) {
		inc(j, 3) {
			t[0][i][j] = b[i][j];
		}
		}
		inc(i, 60 - 1) {
			mat_prod(t[i + 1], t[i], t[i], MOD);
		}
	}
	
	inc(i, 3) {
	inc(j, 3) {
		a[i][j] = 0;
	}
	}
	inc(i, 3) { a[i][i] = 1; }
	inc(i, 60) {
		if((c >> i) & 1) {
			mat_prod(a, a, t[i], MOD);
		}
	}
	
	return;
}



LL n, m, x[100002];
const LL MOD = 1000000007;

int main() {
	cin >> n >> m;
	inc1(i, m) { cin >> x[i]; }
	x[0] = 0;
	x[m + 1] = n + 1;
	
	LL a[3][3] = { { 2, 1, 1 }, { 2, 1, 0 }, { 1, 1, 1 } };
	LL b[3][3] = { { 1, 0, 0 }, { 2, 1, 0 }, { 1, 1, 1 } };
	LL c[3][3] = { { 1, 0, 0 }, { 0, 1, 0 }, { 0, 0, 1 } };
	LL d[3][3];
	
	inc(i, m + 1) {
		if(i != 0) { mat_prod(c, b, c, MOD); }
		mat_exp(d, a, x[i + 1] - x[i] - 1, MOD);
		mat_prod(c, d, c, MOD);
	}
	
	cout << c[2][0] << endl;
	
	return 0;
}


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

using namespace std;

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)

signed main(){

	lli n,m;
	cin>>n>>m;

	if(n==m)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stdio.h>
#include <cstring>
#include <queue>
#include <stack>
#include <functional>
using namespace std;
#define Would
#define you


int main() {
	int n;
	cin >> n;
	cout << (n - 30) / 2 << endl;
}



Measured memory_bytes: 3104
def BinarySearch(n, S, t):
    """ ????????????????????? """
    left = 0
    right = n - 1

    while left <= right:
        center = (left + right) // 2

        if t > S[center]:
            left = center + 1
        elif t < S[center]:
            right = center - 1
        else:
            return center

    return -1

n = int(input())
S = [int(s) for s in input().split()]

q = int(input())
T = [int(t) for t in input().split()]

cnt = 0

for t in T:
    if BinarySearch(n, S, t) != -1:
        cnt += 1

print(cnt)

Measured memory_bytes: 18900
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define mp make_pair
#define pb push_back
#define vll vector<ll>
#define endl "\n"
#define pll pair<ll,ll>
#define all(x) (x).begin() , (x).end()
#define f first
#define s second
#define pr(x) cout<<x<<endl;
#define pr2(x,y) cout<<x<<" "<<y<<endl;
#define pr3(x,y,z) cout<<x<<" "<<y<<endl;
#define prv(v) for(auto x:v) cout<<x<<" ";
#define ffs fflush(stdout);
using namespace std;
 
const ll N =(2e5+5);
const ll MOD = 998244353;
const ll INF = LLONG_MAX;
const ll LOG = 29;
 
long long binpow(long long a, long long b) {
    // a%=MOD;    
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = (res * a);
        a = (a * a) ;
 
        
        b >>= 1;
    }
    //res;
    return res;
} 

void solve(){
    
    ll n,a,b;
    cin>>n>>a>>b;
    if((b-a)&1)cout<<"Borys\n";
    else cout<<"Alice\n";
 }
 
 
int main(){
    ios_base::sync_with_stdio(0);
     cin.tie(NULL);
     
    ll t=1;
    while(t--){
        solve();
    }
     
 
 
    return 0;     
    
        
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ull unsigned long long
#define ll int64_t 
#define f(i,s,e) for(i=s;i<e;++i)
#define endl << "\n"
#define sp << " "
#define INF INFINITY
#define mset(a,b) memset(a,b,sizeof(a))
#define mod 1000000007
#define mp(a,b) make_pair(a,b)
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define PI acos(-1) 
#define pb(a) push_back(a)
#define pf(a) push_front(a)
#define eb(a) emplace_back(a)
#define print(x) for(auto it:x) cout<<it<<' '; cout<<"\n";

#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
using namespace std;

int main()
{
	FAST_IO ;
	string s,t;
	cin >> s >> t;
	ll i,j,k,ans,n;
	ans = t.size() ;
	for(i=0;i<s.size();++i)
	{
		ll cnt = 0;
		bool f = true ;
		for(j=0;j<t.size();++j)
		{
			if(i+j>=s.size())
			{
				f = false;
				break ;
			}
			if(s[i+j]!=t[j])
				cnt++ ;
		}
		if(f)
			ans = min(ans,cnt) ;
	}
	cout << ans endl ;
	return 0;
}

/*
If u haven't come up with an approach yet ,skip this one
  Try this when feeling stuck -
  1. Int overflow, array bounds
  2. Special cases (n=1?)
  3. Prove your approach to yourself(mathematical induction,counter-intuitive or stronger test cases)
  4. Calm down and don't look at standings and stop thinking about rating and think about the question
  5. Just do it! 
*/ 

//Benq's advice - 
/* 
	And following advices are must for me -
	* do something instead of nothing and stay organized
	* WRITE STUFF DOWN 
*/

//#define _GLIBCXX_DEBUG 
// It will convert WA verdict to runtime error if that error is caused due to out of bound excess , declare it at the top
//#pragma GCC optimize "trapv" 
// It will convert WA to runtime error if WA was caused due to int overflow error,declare it anywhere

Measured memory_bytes: 3612
#include <stdio.h>
#include <ctype.h>

int main(int argc, char *args[])
{
	int alpha[26];
	int i;
	char ch;

	for( i=0; i<26; i++ ) {
		alpha[i] = 0;
	}

	while( scanf("%c", &ch) != EOF ) {
		if( (0x41 <= ch && ch <= 0x5a) |
			(0x61 <= ch && ch <= 0x7a) ) {
			alpha[tolower(ch) - 'a']++;
		}
	}


	for( i=0; i<26; i++ ) {
		printf("%c : %d\n", i+'a', alpha[i]);
	}


	return 0;

}

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

#define ll long long
using namespace std;


ll solve(int idx , vector<vector<int>>& data , int w , int n ,vector<vector<ll>>&dp)
{
    if(idx >= n || w == 0)
     return 0;

    if(dp[idx][w] != -1)
     return dp[idx][w];

    ll op1 = -1e7;
    ll op2 = -1e7;
   

    if(w - data[idx][0] >= 0)
     op1 = solve(idx + 1 , data , w - data[idx][0] , n ,dp) + data[idx][1];
    
    op2 = solve(idx +1 , data , w ,n ,dp);

    dp[idx][w] = max(op1 , op2);

    return dp[idx][w];
}
int main()
{
     

    int n,w;
    cin>>n>>w;
    

    vector<vector<int>>data( n , vector<int>(2));
    for(int i = 0 ; i<n ;i++)
    {
        cin>>data[i][0];
        cin>>data[i][1];
    }
    
    
    vector<vector<ll>>dp(n+1 , vector<ll>(w+1 , -1));

    ll ans = solve( 0 , data ,w , n ,dp);
    

    
    cout<<ans<<endl;
    return 0;

}

Measured memory_bytes: 83120
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0; i<(n); i++)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
int main(){
    ll n,k; cin>>n>>k;
    vector<ll> a(n);
    ll sum=0;
    rep(i,n){
        cin>>a[i];
        sum+=a[i];
    }
    ll res=1;
    for(ll ii=1; ii*ii<=sum; ii++){
        if(sum%ii!=0) continue;
        for(ll i: {ii, sum/ii}){
            vector<ll> amari(n);
            ll wa=0;
            rep(j,n){
                amari[j]=a[j]%i;
                wa+=amari[j];
            }
            sort(amari.begin(), amari.end(), greater<ll>());
            wa/=i;
            ll tmp=0;
            rep(j,wa){
                tmp+=i-amari[j];
            }
            if(tmp<=k){
                chmax(res,i);
                if(i==sum/ii){
                    cout<<res<<endl;
                    return 0;
                }
            }
        }
    }
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//#define DEBUG_MODE
#define endl '\n'
#ifdef DEBUG_MODE
#define DEBUG(X) debug_func(X, #X)
#define DEBUG_ENDL endl
#define DEBUG_SEPARATOR_LINE cout<<"=================\n"
#else
#define DEBUG(X) 0
#define DEBUG_ENDL 0
#define DEBUG_SEPARATOR_LINE 0
#endif
#define ALL(V) (V).begin(), (V).end()
#define ALLR(V) (V).rbegin(), (V).rend()
#define DEBUG_ENDL_S(S) ((S).size() ? "\n" : "")
template <typename T> using V = vector<T>;
template <typename T> using VV = V<V<T>>;
template <typename T, typename U> using P = pair<T, U>;
using ll = __int128;
using PLL = P<ll, ll>;
template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename Head, typename... Tail> const Head& var_min(const Head &head, const Tail&... tail) { return min(head, var_min(tail...)); }
template <typename Head, typename... Tail> const Head& var_max(const Head &head, const Tail&... tail) { return max(head, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }
istream& operator >>(istream &is, __int128 &a) { int64_t i; is >> i; a = (__int128)i; return is; }
ostream& operator <<(ostream &os, const __int128 &a) { os << (int64_t)a; return os; }
string to_string(__int128 i) { return to_string((int64_t)i); }
void debug_func_preffix(const string &s) { if(s.size()) cout << s << " = "; }
template <typename T>
void debug_func(const T &t, const string &s = "") {
    debug_func_preffix(s);
    cout << t << DEBUG_ENDL_S(s);
}
template <typename T, typename U>
void debug_func(const P<T, U> &p, const string &s = "") {
    debug_func_preffix(s);
    cout << "(";
    debug_func(p.first);
    cout << ", ";
    debug_func(p.second);
    cout << ")" << DEBUG_ENDL_S(s);
}
template <typename T>
void debug_func(const V<T> &v, const string &s = "") {
    for(ll i = 0; i < v.size(); i++) {
        string t = s + "[" + to_string(i) + "]";
        debug_func(v[i], t);
    }
}

ll max_score(ll sum, ll A, ll B) {
    ll ret = 0;
    for(ll e : {2 * A, 2 * B, sum}) {
        for(ll i = -10; i <= 10; i++) {
            ll a = e / 2 + i;
            if(a <= 0 || sum < a) continue;
            ll b = sum - a;
            if(b <= 0 || sum < b) continue;
            if(a >= A) a++;
            if(b >= B) b++;
            chmax(ret, a * b);
        }
    }
    return ret;
}

int main() {
    ll Q;
    cin >> Q;
    for(ll QQ = 0; QQ < Q; QQ++) {
        ll A, B;
        cin >> A >> B;
        if(A > B) swap(A, B);
        ll score = A * B;
        ll ok = 0, ng = 1e18 + 10;
        while(abs(ok - ng) > 1) {
            ll mid = (ok + ng) / 2;
            if(max_score(mid + 1, A, B) < score) ok = mid;
            else ng = mid;
        }
        cout << ok << endl;
    }
    return 0;
}


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

using namespace std;

typedef long long LL;

struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
#define fin "\n"


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

template <typename T>
inline void chmin(T &l,T r){l=min(l,r);}

template <typename T>
inline void chmax(T &l,T r){l=max(l,r);}

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

string s;
int N;
bool check(string t,int id){
    int m=t.size();
    if(id+m>N)return false;
    REP(i,m)if(s[id+i]!=t[i])return false;
    return true;
}
int main(){
    cin>>s;
    N=s.size();
    vector<int> dp(N+1,0);
    dp[0]=1;
    REP(i,N)if(dp[i]){
        if(check("dream",i))dp[i+5]=1;
        if(check("dreamer",i))dp[i+7]=1;
        if(check("erase",i))dp[i+5]=1;
        if(check("eraser",i))dp[i+6]=1;
    }
    if(dp[N])cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    return 0;
}


Measured memory_bytes: 848
fun main(args:Array<String>) = readLine()!!.let { N ->
    val n = N.toLong()
    val sn = N.map{(it-'0').toLong()}.fold(0L) {sum,ele -> sum + ele}
    if(n % sn == 0L) {"Yes"} else {"No"}
}.run(::println)

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

int main() {
	long long Q, H, L, D, N;
	cin >> Q >> H >> L >> D >> N;
	H = min(H, Q * 2);
	L = min(L, H * 2);
	D = min(D, L * 2);
	cout << N / 2 * D + (N % 2) * L;
}

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

using namespace std;

int INF = 1'000'000;

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

    bool ans = true;
    unordered_map< char, vector<int> > tIndex, sIndex;
    for(int i=0;i<S.size();i++){
        sIndex[S[i]].push_back(i);
        tIndex[T[i]].push_back(i);
    }

    /***
    for(auto itr=tIndex.begin();itr!=tIndex.end();itr++){
        cout << itr->first << endl;
        for(int j=0;j<itr->second.size();j++){
            cout << itr->second[j] << ", ";
        }
        cout << endl << endl;
    }
    ***/

    for(auto itr=tIndex.begin();itr!=tIndex.end();itr++){
        char c = S[ itr->second[0] ];
        for(int i=1;i<itr->second.size();i++){
            if( c != S[ itr->second[i] ] ){
                cout << "No";
                return 0;
            }
        }
    }

    for(auto itr=sIndex.begin();itr!=sIndex.end();itr++){
        char c = T[ itr->second[0] ];
        for(int i=1;i<itr->second.size();i++){
            if( c != T[ itr->second[i] ] ){
                cout << "No";
                return 0;
            }
        }
    }

    cout << "Yes" << endl;
}

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

long long choose(long long n) {
    return n * (n - 1) / 2;
}

int main() {
    int N;
    cin >> N;
    vector<int> A(N), count(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    for (int i = 0; i < N; i++) {
        A[i]--;
    }
    for (int i = 0; i < N; i++) {
        count[A[i]]++;
    }
    long long all = 0;
    for (int i = 0; i < N; i++) {
        all += choose(count[i]);
    }
    for (int i = 0; i < N; i++) {
        long long answer = all;
        answer -= choose(count[A[i]]);
        answer += choose(count[A[i]] - 1);
        cout << answer << endl;
    }
    return 0;
}

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

int main(){
    string s;
    cin >> s;
    map<char,int> m;
    rep(i,4) m[s[i]]++;
    int cnt = 0;
    for(auto p : m) if(p.second == 2) cnt++;
    if(cnt == 2) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3620
import copy
import sys
import math

def main():
	a,b,c,k = map(int,input().split())
	if(abs(a-b)>=10**18):
		print('Unfair')
		sys.exit()
	if(k%2==0):
		print(a-b)
	else:
		print(b-a)


def listtodict(a):
	b = {}
	for i in a:
		try:
			b[i] += 1
		except:
			b[i] = 1
	return b

def base_10_to_n(X, n):
	X_dumy = X
	out = ''
	while X_dumy>0:
		out = str(X_dumy%n)+out
		X_dumy = int(X_dumy/n)
	if(out == ''): return '0'
	return out

main()

Measured memory_bytes: 38512
#include<bits/stdc++.h>
using namespace std;
#define I INT32_MAX
#define IM INT_MIN
#define MOD 1000000007
#define ll long long
#define lli long long int
#define rep(i,n) for (int i = 0; i < n; i++)
#define repk(i,k,n) for (int i = k; i <= n; i++)
#define repr(i,k,n) for (int i = k; i >= n; i--)
#define all(v) (v).begin(),(v).end()
typedef vector<int> vi;
typedef set<int> si;


void solve() {
	ll n;
	cin >> n;
	std::vector<ll> arr(n + 1);
	for (ll i = 0; i < n; ++i)
	{
		cin >> arr[i];
	}
	std::vector<ll> dp(n + 1);
	dp[0] = 0;
	dp[1] = abs(arr[1] - arr[0]);
	for (ll i = 2; i < n; ++i)
	{
		ll onejump = dp[i - 1] + abs(arr[i] - arr[i - 1]);
		ll twojump  = dp[i - 2] + abs(arr[i] - arr[i - 2]);
		dp[i] = min(onejump, twojump);
	}
	cout << dp[n - 1] << endl;

}

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

	int t = 1;
	// cin >> t;
	while (t--)
		solve();

}






Measured memory_bytes: 4748
///Bismillahir Rahmanir Rahim
#include "bits/stdc++.h"

#define                           ll                          long long
#define                           int                         ll
#define                           fi                          first
#define                           si                          second
#define                           mp                          make_pair
#define                           pb                          push_back
#define                           pi                          pair<ll,ll>
#define                           clr(x)                      memset(x,0,sizeof(x));
#define                           f(i,l,r)                    for(int i=l;i<=r;i++)
#define                           rf(i,r,l)                   for(int i=r;i>=l;i--)
#define                           done(i)                     cout<<"done = "<<i<<endl;
#define                           show(x,y)                   cout<<x<<" : ";for(auto z:y)cout<<z<<" ";cout<<endl;
#define                           fast                        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

using namespace std;

const ll inf=1e18;
const int mod=1e9+7;
const int M=100005;

 main()

{
    fast
    int a,b,k;
    cin>>a>>b>>k;
    int sa,sb;
    if(a>=k)
    {
        sa=a-k;
        k=0;
    }
    else
    {
        sa=0;
        k=k-a;
    }
    if(b>=k)
    {
        sb=b-k;
        k=0;
    }
    else sb=0;
    cout<<sa<<" "<<sb<<endl;
    return 0;

}





































Measured memory_bytes: 3600