akhauriyash/Code-Regression huggingface dataset:
import java.io.*;
import java.util.*;

public class Main
{
    PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer tok;

    public void go() throws IOException
    {
        ntok();
        int a = ipar();
        int b = ipar();
        int c = ipar();
        int m1 = Math.min(c, b);
        long total = m1 * 2;
        c -= m1;
        b -= m1;
        int m2 = Math.min(c, a);
        total += m2;
        c -= m2;
        a -= m2;
        total += b;
        total += Math.min(1, c);
        out.println(total);

        out.flush();
        in.close();
    }

    public void ntok() throws IOException
    {
        tok = new StringTokenizer(in.readLine());
    }

    public int ipar()
    {
        return Integer.parseInt(tok.nextToken());
    }

    public long lpar()
    {
        return Long.parseLong(tok.nextToken());
    }

    public double dpar()
    {
        return Double.parseDouble(tok.nextToken());
    }

    public String spar()
    {
        return tok.nextToken();
    }

    public static void main(String[] args) throws IOException
    {
        new Main().go();
    }
}


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

int main() {
  int n;
  cin >> n;

  vector<string> a(n), b(n), c(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    b[i] = a[i];
    c[i] = a[i];
  }

  for (int i = 0; i < n; i++) {
    for (int j = n-1; j > i; j--) {
      if (b[j][1] < b[j-1][1]) {
        swap(b[j], b[j-1]);
      }
    }
  }

  for (int i = 0; i < n; i++) {
    int minj = i;
    for (int j = i; j < n; j++) {
      if (c[j][1] < c[minj][1]) {
        minj = j;
      }
    }
    swap(c[i], c[minj]);
  }

  for (int i = 0; i < n; i++) {
    if (i<n-1) cout << b[i] << " ";
    else cout << b[i] << endl;
  }

  cout << "Stable" << endl;

  for (int i = 0; i < n; i++) {
    if (i<n-1) cout << c[i] << " ";
    else cout << c[i] << endl;
  }

  bool flag = true;;
  for (int i = 0; i < n; i++) {
    if (b[i] != c[i]) {
      flag = false;
      break;
    }
  }

  if (flag) {
    cout << "Stable" << endl;
  }
  else {
    cout << "Not stable" << endl;
  }

}


Measured memory_bytes: 3216
/*|In The Name Of Allah|*/
//This Month Will Be Expert ISA
#include <bits/stdc++.h>

using namespace std;

const int N = 1e5+5;

const int mod = 1e9+7;

int main(){
    int n;
    string s;
    cin >> n >> s;
    int ans = 0;
    for(int i = 0; i+2 < n; i++){
        if(s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C'){
            ans ++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
n = int(input())
X = list(map(int, input().split()))
min_total = 100000000
for syukai in range(1, 100):
  total = 0
  for x in X:
    total += (x - syukai)**2
  else:
    min_total = min(total, min_total)
print(min_total)

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

int  main()
{
	string s , t;
	cin >> s >> t;
	int a,b;
	cin >> a >> b;
	string u; cin >> u;
	if (u == s) a--;
	else b--;
	cout << a  << " " << b << endl;
	return (0);
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
const int mod = 1e9+7;

int main(){
    int h, w;
    cin >> h >> w;

    char mat[h][w];
    static int dp[1000][1000] = {};

    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            cin >> mat[i][j];
        }
    }

    dp[0][0] = 1;
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            if(mat[i][j] == '#')    continue;
            if(i)   dp[i][j] += dp[i-1][j];
            if(j)   dp[i][j] += dp[i][j-1];
            dp[i][j] %= mod;
        }
    }

    cout << dp[h-1][w-1] << endl;

    return 0;
}

Measured memory_bytes: 5120
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b;
	cin>>a>>b;
	if(a>=6&&a<=12)
	{
		cout<<b/2<<endl;
	}
	else if(a<6)
	{
		cout<<0<<endl;
	}
	else
	{
		cout<<b<<endl;
	}
}

Measured memory_bytes: 384
# coding: utf-8


def array2d(d1, d2, init = None):
    return [[init for _ in range(d2)] for _ in range(d1)]


def main():
    n, a, b = map(int, input().split(" "))

    if a > b:
        print(0)
        return
    if n == 1 and a != b:
        print(0)
        return

    smin = (n - 1) * a + b
    smax = (n - 1) * b + a
    print(smax - smin + 1)

main()


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")

#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()

using ll = long long;
using ull = unsigned long long;
using namespace std;

int main() {
  vector<int> num(3);
  int tmp = 0;
  REP(i, 3) cin >> num[i];
  sort(ALL(num));
  REP(i, 2) {
    if (num[i] == num[i+1]) {
      tmp++;
    }
  }
  if (tmp == 1) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

struct SegTree{
    int n; vector<int> dat;
    //初期化
    SegTree(int _n){
        n=1;
        while(n<_n) n*=2;
        dat=vector<int>(2*n-1,0);
    }

    void add(int k, int a){
        k+=n-1;
        dat[k] += a;
        //更新
        while(k>0){
            k=(k-1)/2;
            dat[k]=dat[2*k+1]+dat[2*k+2];
        }
    }
    //内部的に投げられるクエリ
    int _query(int a, int b, int k, int l, int r){
        if(r<=a || b<=l) return 0;

        if(a<=l && r<=b) return dat[k];

        int vl=_query(a,b,2*k+1,l,(l+r)/2);
        int vr=_query(a,b,2*k+2,(l+r)/2,r);
        return vl+vr;
    }
    //[a,b)
    int query(int a, int b){
        return _query(a,b,0,0,n);
    }
};

const int N = 100000;
const ll INF = LLONG_MAX/3;

struct edge{ int to,cost; };
vector<edge> G[N];

int main(){
    int n,m;
    scanf(" %d %d", &n, &m);
    rep(i,m){
        int a,b,c;
        scanf(" %d %d %d", &a, &b, &c);
        G[a].pb({b,c});
        G[b].pb({a,c});
    }

    auto dijkstra = [&](int start){
        using P = pair<ll,int>;
        vector<ll> d(n,INF);
        priority_queue<P, vector<P>, greater<P>>pq;
        d[start] = 0;
        pq.push({0,start});
        while(!pq.empty()){
            P now = pq.top();
            pq.pop();
            int v = now.se;
            if(now.fi > d[v]) continue;
            for(const auto &e:G[v]){
                if(d[e.to] > d[v]+e.cost){
                    d[e.to] = d[v]+e.cost;
                    pq.push({d[e.to], e.to});
                }
            }
        }
        return d;
    };

    vector<ll> s = dijkstra(0), g = dijkstra(n-1);

    using pl = pair<ll,ll>;
    using query = pair<pl,int>;

    vector<ll> ug;

    int Q;
    scanf(" %d", &Q);
    vector<query> q(Q);
    rep(i,Q){
        ll fs,fg;
        scanf(" %lld %lld", &fs, &fg);
        q[i] = {{fs,fg}, i};
        ug.pb(fg);
    }
    sort(all(q));

    vector<pl> v(n);
    rep(i,n){
        v[i] = {s[i],g[i]};
        ug.pb(g[i]);
    }
    sort(all(v));

    sort(all(ug));
    ug.erase(unique(all(ug)), ug.end());
    int UG = ug.size();

    SegTree st(UG);

    int idx = 0;
    vector<int> ans(Q);
    rep(i,Q){
        int ID = q[i].se;
        ll fs = q[i].fi.fi, fg = q[i].fi.se;

        while(idx<n && v[idx].fi<=fs){
            int a_idx = lower_bound(all(ug), v[idx].se)-ug.begin();
            st.add(a_idx, 1);
            ++idx;
        }

        int gidx = lower_bound(all(ug), fg)-ug.begin();
        ans[ID] = st.query(gidx, UG);
    }

    rep(i,Q) printf("%d\n", ans[i]);
    return 0;
}



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

#define MOD 1000000007
 
using namespace std;

int N, K;
bool f[1000000];
vector<int> e[1000000];

long dfs(int p, int k){
    long ret = 1;
    f[p] = true;

    int t;
    if(k == K) t = K-1;
    else t = K-2;

    for(int i=0; i<e[p].size(); i++){
        if(!f[e[p][i]]){
            ret = (ret % MOD) * dfs(e[p][i], t) % MOD;
            t--;
        }
    }

    return (ret * k) % MOD;
}

int main(){
    cin >> N >> K;

    for(int i=0; i<N-1; i++){
        int a, b;
        cin >> a >> b;
        e[a-1].push_back(b-1);
        e[b-1].push_back(a-1);
    }

    fill(f, f+N, false);

    long ans = dfs(0, K) % MOD;

    cout << ans;

    return 0;
}


Measured memory_bytes: 31616
#include <bits/stdc++.h>
using namespace std;
int main()
{
  string s;
  cin >> s;

  int t = 0;
  for (int i = 0; i < 3; i++) {
    if (s[i] == '1') {
      t++;
    }
  }

  cout << t << endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int A = sc.nextInt();
    int B = sc.nextInt();
    int answer =0;
    for(int i=1;i<=N;i++){
      if(isRange(i,A,B)){
        answer = answer+i;
      }
    }
    System.out.println(answer);
  }
  
  public static boolean isRange(int n ,int min ,int max){
    int cnt1=n%10;
    int cnt10=(n/10)%10;
    int cnt100 =(n/100)%10;
    int cnt1000 =(n/1000)%10;
    int cnt10000=n/10000;
    int sums = cnt1+cnt10+cnt100+cnt1000+cnt10000;
    if(min<=sums&&sums<=max){
      return true;
    }
    return false;
  }
  

  
}

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


int selectionSort(int arr[], int n){
	int min_i;
	int swapCount = 0;
	for(int i = 0; i < n; i++){
		min_i = i;
		for(int j = i; j < n; j++){
			if( arr[j] < arr[min_i] ){
				min_i = j;
			}
		}
		if(i != min_i){
			swap(arr[i], arr[min_i]);
			swapCount++;
		}
	}
	return swapCount;
}

void printArr(int arr[], int n){
	for(int i = 0; i < n; i++){
		cout << arr[i];
		if(i != n - 1){
			cout << ' ';
		}
	}
	cout << endl;
}

int main(){
	int n;
	int arr[100];
	int swapCount;
	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> arr[i];
	}

	swapCount = selectionSort(arr, n);
	printArr(arr, n);
	cout << swapCount << endl;

	return 0;
}


Measured memory_bytes: 3108
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define REP(i,n) for(int i = 0; i < n; i++)
#define FOR(i,j,n) for(int i = j; i < n; i++)
#define RFOR(i,j,n) for(int i = j-1; i >= n; i--)
#define PREC(n) fixed << setprecision(n)
#define print_array(v) REP(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
#define YesorNo(a) printf(a?"Yes\n":"No\n")
#define _LIBCPP_DEBUG 0
using namespace std;
int64_t MOD = 1000000007;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a, b;
  cin >> a >> b;
  if(a < b) swap(a,b);
  if(a > b + 1) cout << a + a - 1 << endl;
  else cout << a + b << endl;
  return 0;
}
//templete by private_yusuke

Measured memory_bytes: 256
#include<iostream>
#include<stack>
#include<map>
#include<vector>
using namespace std;
stack<int>a;
stack<pair<int,int> >a1;
int sum;//统计总共有多少洪水
int part;

int main()
{
	int i = 0;
	char c;
	while (cin >> c) {
		if (c == '\\'){
			a.push(i);
		}
		else if (c == '/'&&!a.empty()) {
			sum+= i - a.top();
			part = i - a.top();
			while (!a1.empty() && a1.top().first > a.top()) {
				part += a1.top().second;
				a1.pop();
			}
			a1.push(make_pair(a.top(), part));
			a.pop();
		}
		i++;
	}
	vector<int>ans;
	while (!a1.empty()) {
		ans.push_back(a1.top().second);
		a1.pop();
	}
	cout << sum << endl;
	cout << ans.size();
	for (int i = ans.size() - 1; i >= 0; i--) {
		cout << " " << ans[i];
	}
	cout << endl;
    return 0;
}





Measured memory_bytes: 3232
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc =new Scanner(System.in);
    int X =sc.nextInt();
    int j=0;
    for(int i=1;;i++){
      j=360*i;
      if(j%X==0){System.out.println(j/X);System.exit(0);}}
  }
}

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

int main(void)
{
	char s[11]={},t[11]={},u[11]={};
	int a,b;
	scanf("%s%s",s,t);
	scanf("%d%d",&a,&b);
	scanf("%s",u);
	if(strcmp(s,u)==0) printf("%d %d\n",a-1,b);
	else if(strcmp(t,u)==0) printf("%d %d\n",a,b-1);
	return 0;
}



Measured memory_bytes: 128
#include <bits/stdc++.h>
    using namespace std;
    
    int main(){
        long  n;
        cin >> n;
        long w;
        vector<long>  v , vt;
        long t = 0;
        for(int i = 0 ; i < n ; i++){
            cin >> w;
            t += w;
            v.push_back(w);
            vt.push_back(t);
        }
        
        long ans = 10000;
        long s ;
        for(int i = 0 ; i < n ; i++){
            s = abs(vt[i] - (t - vt[i]));
            ans = min(s , ans);
        }
        cout << ans << endl;
        
        return 0;
    }

Measured memory_bytes: 256
#pragma comment(linker, "/STACK:102400000,102400000")
#include <bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define SZ(x) (int)(x.size())
#define rep(i,a,b) for(int i=a;i<b;i++)
#define per(i,a,b) for(int i=b-1;i>=a;i--)
#define inf 1000000007
#define mod 1000000007
#define x first
#define y second
#define pi acos(-1.0)
#define DBG(x) cerr<<(#x)<<"="<<x<<"\n";
//#define dprintf(...) 
#define hash _hash
//#define dprintf(...) fprintf(outFile,__VA_ARGS__)
 
#define FOREACH(it,x) for(__typeof(x.begin()) it=x.begin();it!=x.end();it++)
#define ull unsigned long long
#define ll long long
#define N 100001
 
template <class T,class U>inline void Max(T &a,U b){if(a<b)a=b;}
template <class T,class U>inline void Min(T &a,U b){if(a>b)a=b;}
 
//FILE* outFile;

inline void add(int &a,int b){a+=b;while(a>=mod)a-=mod;}
 
int pow(int a,int b){
    int ans=1;
    while(b){
        if(b&1)ans=ans*(ll)a%mod;
        a=(ll)a*a%mod;b>>=1;
    }
    return ans;
}


int p[N],q[N];
pii v[N];
int main(){
    int n,i,j,k,K,T,m=0;
    int t=0;
    ll INF=1e10;
    ll M=1;
    while(M*M*M<=INF)M++;
    rep(i,2,M){
        if(!p[i])q[t++]=i;
        rep(j,0,t){
            if(1LL*i*q[j]>=N)break;
            p[i*q[j]]=1;
            if(i%q[j]==0)break;
        }
    }
    scanf("%d",&n);
    int all=0,ans=0;
    ll x,y;
    map<ll,int>g;
    map<ll,ll>f;
    rep(i,0,n){
        scanf("%lld",&x);y=x;
        int sz=0;
        rep(j,0,t){
            if(1LL*q[j]*q[j]>x)break;
            if(x%q[j]==0){
                k=0;
                while(x%q[j]==0)x/=q[j],k++;
                k%=3;
                if(k)v[sz++]={q[j],k};
            }
        }
        if(x>1&&x<M){
            v[sz++]={x,1};
        }
        else if(x>1){
            y=sqrt(x);
            while(y*y<=x)y++;
            while(y*y>x)y--;
            if(y*y==x){
                v[sz++]={y,2};
            }
            else if(x>=N){ans++;continue;}
            else v[sz++]={x,1};
        }
        if(sz==0){all=1;continue;}
        x=1;
        rep(j,0,sz){
            rep(k,0,v[j].y)x=x*v[j].x;
        }
        //cerr<<y<<" "<<x<<"\n";
        if(!g.count(x)){
            ll y=1;
            rep(j,0,sz)rep(k,0,3-v[j].y)y=y*v[j].x;
            f[x]=y;
        }
        g[x]++;
    }
    while(!g.empty()){
        x=g.begin()->x;
        y=f[x];
        if(g.count(y)){
            //cerr<<g[x]<<" "<<g[y]<<"\n";
            ans+=max(g[x],g[y]);
            g.erase(y);
        }
        else ans+=g[x];
        g.erase(x);
    }
    ans+=all;
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 11008
#include<stdio.h>

int main(void)
{
	int a,b,c;

	scanf("%d %d %d",&a ,&b ,&c);

		if(a<b){
            if(b<c){
                printf("Yes\n");
            }
        else{
		printf("No\n");
		}
	}
		else{
		printf("No\n");
	}
	return 0;
}


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

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

	sort(A.begin(), A.end());

	bool ans = true;
	for(int i = 1; i < N; i++){
		if(A[i - 1] == A[i]){
			ans = false;
			break;
		}
	}

	if(ans) cout << "YES" << endl;
	else cout << "NO" << endl;

	return 0;
}

Measured memory_bytes: 1792
#17:11
n,m = map(int,input().split())
pre = [i for i in range(n)]
ans = n
for _ in range(m):
  x,y,z = map(int,input().split())
  x -= 1
  y -= 1
  X = [x]
  Y = [y]
  while pre[x] != x:
    X.append(x)
    x = pre[x]
  while pre[y] != y:
    Y.append(y)
    y = pre[y]
  if x != y:
    ans -= 1
    for xx in X:
      pre[xx] = y
    for yy in Y:
      pre[yy] = y
    pre[x] = y
#print(pre)
print(ans)

Measured memory_bytes: 73120
using System;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
using Debug = System.Diagnostics.Debug;

static class P
{
    static void Main()
    {
        var nm = Console.ReadLine().Split().Select(int.Parse).ToArray();
        var switches = new int[nm[0]];
        for (int i = 0; i < nm[1]; i++)
        {
            foreach (var s in Console.ReadLine().Split().Select(int.Parse).Skip(1))
            {
                switches[s - 1] |= 1 << i;
            }
        }
        int valid = 0;
        var p = Console.ReadLine().Split().Select(int.Parse).ToArray();
        for (int i = 0; i < nm[1]; i++)
        {
            valid |= p[i] << i;
        }
        int count = 0;
        for (int i = 0; i < (1 << switches.Length); i++)
        {
            int res = 0;
            for (int j = 0; j < switches.Length; j++)
            {
                if (((i >> j) & 1) == 1)
                {
                    res ^= switches[j];
                }
            }
            if (res == valid) count++;
        }
        Console.WriteLine(count);
    }
}


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

using namespace std;
using ll = long long;


int main()
{
    string s;
    cin >> s;
    map<char,int> mp;
    for(auto i : s)mp[i]++;

    for(char i = 'a'; i <= 'z'; i++){
        if(!mp[i]){cout << i << endl;return 0;}
    }
    cout << "None" << endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
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<bool> vb;
typedef vector<double> vd;
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 irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;


int main(void) {
    
    int n;
    cin>>n;
    string s,t;
    cin>>s>>t;
    for(int i=0;i<n;i++){
        if(s.substr(i) == t.substr(0,n-i)){
            fin(i+n);
            return 0;
        }
    }
    fin(2*n);
}

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

//#define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
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<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<bool> > vvb;
typedef vector<vector<double> > vvd;
typedef vector<vector<string> > vvs;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

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;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

signed main()
{   
    gearup;
    char s; cin >> s;
    map<char,char>mp;
    mp['A'] = 'T';
    mp['T'] = 'A';
    mp['G'] = 'C';
    mp['C'] = 'G';
    out(mp[s]);
}


Measured memory_bytes: 256
import math
def solve(n, h, a_arr, b_arr):
    max_a = max(a_arr)
    max_b = max(b_arr)

    # max_a_i = a_arr.index(max_a)
    # max_b_i = b_arr.index(max_b)

    # 投げて得するmax
    throw_sum = 0
    throw_i = 0
    for b in sorted(b_arr, reverse=True):
        if b > max_a:
            throw_sum += b
            throw_i += 1
        if throw_sum >= h:
            # print(throw_sum)
            break



    attack_i = 0
    if h > throw_sum:
        attack_i = math.ceil((h - throw_sum) / max_a)

    # print(attack_i, throw_i)
    return throw_i + attack_i



n, h = map(int, input().split())
a_arr = [0] * n
b_arr = [0] * n
for i in range(n):
    a, b = map(int, input().split())
    a_arr[i] = a
    b_arr[i] = b

print(solve(n, h, a_arr, b_arr))


Measured memory_bytes: 12080
n = int(input())
a = list(map(int,input().split()))
INF = n*10**10
dp = [[-INF]*2 for i  in range(n+1)]
#i番目まで見たとき、i番目でー１を書けたかがｊのときのmax
dp[0][0] = 0
for i in range(n):
    dp[i+1][0] = max(dp[i][0]+a[i],dp[i][1]-a[i])
    dp[i+1][1] = max(dp[i][0]- a[i],dp[i][1]+a[i])
ans = dp[n][0]
print(ans)


Measured memory_bytes: 72608
n, m = gets.split.map(&:to_i)
to = Array.new(n + 1){[]}
prev = Array.new(n + 1, nil)
prev[0] = 1
m.times{
	a, b = gets.split.map(&:to_i)
	to[a] << b
	to[b] << a
}
q = [1]
until q.size.zero?
	now = q.shift
	to[now].each{|t|
		unless prev[t]
			q.push t
			prev[t] = now
		end
	}
end
if prev.all?
	puts "Yes"
	prev.shift(2)
	puts prev
else
	puts "No"
end

Measured memory_bytes: 32800
#include<bits/stdc++.h>
using namespace std;
string a;
int main()
{
	int m=0,n=0;
	cin>>a;
	for(int i=0;i<a.size();i++)
	if(a[i]=='p')m++;			//对方出布的次数 
	else
	n++;						//对方出石头的次数 
	int x=(m+n)/2;				//自己出布的次数				
	if(x<m)
	cout<<m+n-2*x;
	else
	cout<<x-m;
	return 0; 
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define endl '\n'
#define all(x) (x).begin(),(x).end()
const int INF=2e5+5;
const int N=1e6+5;
const ll oo=1e18+5;
const ll mod=1e9+7;

struct BIT{
	int n;
	vector<int> fen;
	BIT(int n){
		this->n=n;
		this->fen.resize(n);
	}
	void update(int pos,int val){
		for(int i=pos;i;i-=i&-i){
			this->fen[i]=min(this->fen[i],val);
		}
	}
	int query(int pos){
		int ans=n;
		for(int i=pos;i<this->n;i+=i&-i){
			ans=min(ans,this->fen[i]);
		}
		return ans;
	}
};

int main(){
	ios::sync_with_stdio(0); cin.tie(0);
	int n,q;
	cin>>n>>q;
	vector<bool> row(n),col(n);
	BIT mRow(n),mCol(n);
	for(int i=0;i<n;++i) mRow.fen[i]=mCol.fen[i]=n;
	ll ans=1ll*(n-2)*(n-2);
	while(q--){
		int opt,val;
		cin>>opt>>val;
		if(opt==1){
			if(row[val]) continue;
			row[val]=1;
			int y=mRow.query(val);
			ans-=y-2;
			mCol.update(y-1,val);
		}
		else{
			if(col[val]) continue;
			col[val]=1;
			int x=mCol.query(val);
			ans-=x-2;
			mRow.update(x-1,val);
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 4780
#include <stdio.h>

int main(){

	int X,A,B;

	scanf("%d %d %d",&X,&A,&B);

	if(A>=B){
	printf("delicious\n");
	}
	else{
		if(B-A<=X){printf("safe\n");}
		else{printf("dangerous\n");}
	}

	return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>

using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,a,n) for(int i=a;i<n;i++)
#define mp(i,j) make_pair(i,j)
#define debug_v(v,N) for(int i=0;i<N;i++) { cout << v[i] << " "; } cout << endl;
#define debug_vv(v,H,W) for(int i=0;i<H;i++) { for(int j=0;j<W;j++) { cout << v[i][j] << " "; } cout << endl; }

typedef long long ll;
typedef pair<int, int> P;

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; }

int H[100010];
int dp[100010];

void Main()
{
	int N; cin >> N;
	rep(i,N) cin >> H[i];
	dp[N - 1] = H[N - 1];
	for (int i = N - 2; i > 0; --i) {
		if (H[i] > dp[i + 1]) {
			dp[i] = H[i] - 1;
			if (dp[i] > dp[i + 1]) {
				cout << "No" << endl;
				return;
			}
		} else {
			dp[i] = H[i];
		}
	}
	cout << "Yes" << endl;
}

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


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
 
int n,a[200],k,mi,dp[3][100005];
 
bool f(int p,int rem)
{  
 //cout<<"Start "<<p<<" "<<rem<<endl;
   if(dp[p][rem]!=-1)
      { //cout<<"already "<<p<<" "<<rem<<endl;
	  return dp[p][rem];
}
      
      if(rem==0 or rem<mi)
      {
      	dp[p][rem]=0;
      	//	cout<<"Base "<<p<<" "<<rem<<" "<<dp[p][rem]<<endl;
      	return false;
	  }
      bool val=true;
	for(int i=1;i<=n;i++)
	{ 
	if(rem-a[i]>=0)
	{
	 /* if(rem==k)
	  cout<<(p+1)%2<<" "<<rem-a[i]<<endl;
	  
	  if(p==0 and rem-a[i]==1)
	  cout<<"here "<<dp[(p+1)%2][rem-a[i]]<<endl;*/
	  f((p+1)%2,rem-a[i]);
	val = val and dp[(p+1)%2][rem-a[i]];
/*	if(rem==k)
	cout<<"val is "<<val<<endl;*/
}
}
	
	if(val==false)
	 dp[p][rem]=1;
	else
	dp[p][rem]=0;
//	cout<<p<<" "<<rem<<" "<<dp[p][rem]<<endl;
 
    return dp[p][rem];
	
}
main()
{
	cin>>n>>k;
	mi=1000000;
	
	for(int i=1;i<=n;i++)
{
		cin>>a[i];
		 mi = min(mi,a[i]);
	}
	
	for(int i=0;i<3;i++)
	for(int j=0;j<100004;j++)
	dp[i][j]=-1;	
	
	if(f(0,k))
	cout<<"First";
	else
	cout<<"Second";
}

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

int main(){
    double n;
    vector<double>v;
    while(cin>>n){
        v.push_back(n);
    }   
    double a=v[0];
    double b=v[0];
    for(int i=0; i<v.size();i++){
        a=max(a,v[i]);
        b=min(b,v[i]);
    }   
    cout<<(a-b)<<endl;
    return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<iomanip>
#include<math.h>
#include<algorithm>
#include<utility>
#include<functional>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<vector>
using namespace std;
typedef long long LL;
typedef pair<int, int> P;

LL N,M,a,b,c,d;
string s;
map<char,int> mp;
int main(){
    cin>>N;
    int A[100010];
    for(int i=0;i<N;i++){
        cin>>A[i];
    }
    sort(A,A+N);
    LL ans=1;
    int s=0;
    for(int i=N-1;i>=1;i--){
        if(A[i]==A[i-1]){
            i--;
            ans*=A[i];
            s++;
            if(s>=2)break;
        }
    }
    if(s<=1){
        cout<<"0";
        return 0;
    }
    cout<<ans;

    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
using namespace std;
typedef long long ll;
ll mod = 1000000007;

int main() {
    int m,d,ans = 0;
    cin >> m >> d;
    for(int i = 1;i <= m;i++){
        for (int j = 1; j <= d; ++j) {
            int d1,d10,tmp;
            tmp = j;
            d1 = (tmp%10);
            tmp /= 10;
            d10 = (tmp%10);
            if(d1 >= 2 && d10 >= 2 && d1*d10 == i) ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
out=0
k=0
for i in range(1,N+1):
    k=0
    if i % 2==1:
        for j in range(1,i+1):
            if i % j==0:
                k = k+1
        if k==8:
            out = out+1
    
print(out) 

Measured memory_bytes: 9044
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>   
using namespace std;
 
int main(){
int a,i = 0;
cin >> a;
int b[a],c[a],ans[a];
while(a > i){
    cin >> b[i] >> c[i];
    ans[i] =  b[i] % c[i];
    if(ans[i] == 0) ans[i] = c[i];
    i++;
}
i = 0;
while(a > i){
cout << ans[i] << endl;
i++;
}
}

Measured memory_bytes: 1160
L,R = [int(i) for i in input().split()]

tmp = 2019
ans = 2019

for i in range(L,R):
  for j in range(i+1,R+1):
    tmp = (i*j)%2019
    ans = min(tmp,ans)
    if ans == 0:
      break
  else:
    continue
  break

print(ans)

Measured memory_bytes: 3060
n=int(input())
s=list(input())

ans=0
for i in range(10):
    for j in range(10):
        for k in range(10):
            for p in range(len(s)):
                if s[p]==str(i):
                    for q in range(p+1,len(s)):
                        if s[q]==str(j):
                            for r in range(q+1,len(s)):
                                if s[r]==str(k):
                                    ans+=1
                                    break
                            break
                    break

print(ans)


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

using namespace std;
int n;
long long k,mid;
int a[300000],f[300000];

bool check()
{
    long long tk = k;
    for(int i=0;i<n;++i){
        if(1LL*a[i]*f[i]>mid){
        long long ts = mid/f[i];
        tk -= a[i] - ts;
        }
        if(tk<0) return false;
    }
    return true;
}

int main()
{
    scanf("%d%lld",&n,&k);
    for(int i=0;i<n;++i)scanf("%d",a+i);
    for(int i=0;i<n;++i)scanf("%d",f+i);
    sort(f,f+n);
    sort(a,a+n);reverse(a,a+n);
    long long l=0,r = 1000000;
    r*=r;
    while(l<r){
        mid = (l+r)/2;
        if(check())r=mid;
        else l = mid + 1;
    }
    printf("%lld\n",l);
    return 0;
}


Measured memory_bytes: 5372
#include<stdio.h>
int main()

{

    int X,A,B,i,z,t,f;
    scanf("%d",&X);
    scanf("%d",&A);
    scanf("%d",&B);
    i=X-A;
    z=i/B;
    t=B*z;
    f=i-t;
    printf("%d",f);








    return 0;
}





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

int dx8[8] = {1, 1, 0, -1, -1, -1, 0, 1};
int dy8[8] = {0, 1, 1, 1, 0, -1, -1, -1};

int w, h;

int field[51][51];
bool seem[51][51];

void dfs(int x, int y)
{
	field[y][x] = 0;
	for (int i = 0; i < 8; ++i)
	{
		int xx = x + dx8[i];
		int yy = y + dy8[i];

		if (xx < 0 || xx >= w || yy < 0 || yy >= h) continue;
		
		if (field[yy][xx] == 0) continue;

		dfs(xx, yy);
	}
}

int main(int argc, char **argv)
{
	while (true)
	{
		cin >> w >> h;
		if (w == 0 && h == 0) break;
		memset(field, 0, sizeof(field));
		for (int y = 0; y < h; ++y)
			for (int x = 0; x < w; ++x)
				cin >> field[y][x];

		int c{0};
		memset(seem, 0, sizeof(seem));
		for (int y = 0; y < h; ++y)
		{
			for (int x = 0; x < w; ++x)
			{
				if (field[y][x] == 0) continue;
				dfs(x, y);
				++c;
			}
		}
		std::cout << c << std::endl;
	}
}



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

using namespace std;

int main() {
  string s;
  cin >> s;
  if (s[0] == '7' || s[1] == '7' || s[2] == '7') {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}

Measured memory_bytes: 3640
/// 標準入力を行で読み込んでStringにする
#[allow(dead_code)]
fn rd() -> String {
    let mut input = String::new();
    std::io::stdin().read_line(&mut input).unwrap();
    input.trim().to_string()
}

/// 1行の文字を空白で分割してVec<T>にする。
#[allow(dead_code)]
fn rd_vec<T : std::str::FromStr>() -> Vec<T> {
    rd().split_whitespace().map(|x| x.parse().ok().unwrap()).collect()
}

/// 1つの要素を入力で受け取る
#[allow(dead_code)]
fn rd_one<T : std::str::FromStr>() -> T {
    let mut input = String::new();
    std::io::stdin().read_line(&mut input).unwrap();
    input.trim().parse().ok().unwrap()
}

/// 複数回read_splitを行う
#[allow(dead_code)]
fn rd_vec_mul<T : std::str::FromStr>(count : i32) -> Vec<Vec<T>> {
    (0..count).map(|_| rd_vec()).collect()
}

/// Vecを1列で出力する
#[allow(dead_code)]
fn op_vec<T : std::fmt::Display>(item : Vec<T>, splitter : char) {
    let cnt = item.len();
    let mut c = 0;
    for i in item.iter() {
        c+=1;
        if cnt > c {print!("{}{}", i, splitter);} else {println!("{}", i);}
    }
}

fn main() {
    let input : i32 = rd_one();
    let mut answer : String = rd_one();
    if input < 3200 { answer = "red".to_string(); }
    println!("{}", answer);
}


Measured memory_bytes: 4352
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <map>
#include <set>
#include <queue>
#include <list>
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,a,b) for(int i=int(a);i<int(b);++i)
#define crep(i) for(char i='a';i<='z';i++)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define psortfirst(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.first<b.first;});
#define ALL(x) (x).begin(),(x).end()
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
using namespace std;
using pii  = pair<int,int>;
long long gcd(long long a, long long b){return (b == 0 ? a : gcd(b, a%b));}
long long lcm(long long a, long long b){return a*b/gcd(a,b);}
typedef long long ll;
#define MOD 1000000007
#define EPS 10e-8

ll B[100007];

int main(){
    ll N,K,Q,A[100007],C=0;cin >> N >> K >> Q;
    rep(i,Q){
        cin >> A[i];
        B[A[i]]++;
    }
    rep(i,N){
        if(Q-B[i+1]>=K){
            cout << "No" <<endl;
        }
        else{
            cout << "Yes" <<endl;
        }
    }
}

Measured memory_bytes: 2176
from itertools import combinations
from math import sqrt

n, d = map(int, input().split())
ps = [tuple(map(int, input().split())) for _ in range(n)]

cnt = 0
for x, y in combinations(ps, 2):
  if sqrt(sum((x[i]-y[i])**2 for i in range(d))).is_integer():
    cnt += 1
    
print(cnt)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int n,t;
  string s;
  cin>>n>>t;
  vector<int>a(n);
  cin>>s;
  for(int i=0;i<n-1;i++)
  {
      if(i!=0)a[i]=a[i-1];
      if(s[i]=='A' && s[i+1]=='C')
      {
        if(i==0)a[i]=1;
      	else a[i]=a[i-1]+1;
      }
  }
  a[n-1]=a[n-2];
  while(t--)
  {
    int l,r;
    cin>>l>>r;
    l--;
    r--;
    long long ans=a[r]-a[l];
    if(s[l]=='A'&& s[l+1]=='C')ans++;
    if(s[r]=='A' && ans!=0 && s[r+1]=='C' && r!=n-1)ans--;   
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
int n,m;
int a[1100];

bool cmp(int x,int y)
{
	return x>=y;
}

int main()
{
	int sum=0;
	scanf("%d%d",&n,&m);
	for(int i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
		sum+=a[i];
	}
	sort(a,a+n,cmp);
	if(a[m-1]>=sum*1.0/(4*m))
		printf("Yes\n");
	else
		printf("No\n");
}

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

signed main(){
  
  int a, b, h, m;
  
  cin >> a >> b >> h >> m;

  double hz = M_PI * ( 360.0 * ( h * 60 + m ) / 720 ) / 180.0;
  
  double hx = cos( hz ) * a;
  double hy = sin( hz ) * a;
  
  double mz = M_PI * ( 360.0 * m / 60 ) / 180.0;

  double mx = cos( mz ) * b;
  double my = sin( mz ) * b;
  
  double X = hx - mx;
  double Y = hy - my;
  
  printf("%.10f\n", sqrt( X * X + Y * Y ) );
  
  return 0;
}


Measured memory_bytes: 4056
#include<stdio.h>
int main(){
  char s[258];
  int n,i,j,l,k,x,y,max;
  int X[]={1,1,0,-1};
  int Y[]={0,1,1, 1};
  while(1){
    scanf("%d",&n);
    if(n==0)break;
    scanf("\n");
    int m[257][257]={0};
    max=0;
    for(i=0;i<n;i++){
      fgets(s,257,stdin);
      for(j=0;j<n;j++){
	m[i+1][j+1]=s[j]-'0';
      }
    }
    for(i=0;i<n;i++){
      for(j=0;j<n;j++){
	if(m[i+1][j+1]==1){
	  for(k=0;k<4;k++){
	    x=j+1;
	    y=i+1;
	    l=0;
	    while(m[y][x]==1){
	      x+=X[k];
	      y+=Y[k];
	      l++;
	    }
	    if(max<l)max=l;
	  }
	}
      }
    }
    printf("%d\n",max);
  }
  return 0;
}

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

#define M 1000000/* your task*/
#define L 14

char H[M][L]; /* Hash Table */

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;
}

/* convert a string into an integer value */
long long getKey(char str[]){
  long long sum = 0, p = 1, i;
  for ( i = 0; i < strlen(str); i++ ){
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}

int h1(int key){ return key%M/* your task */; }
int h2(int key){ return 1+(key%(M-1))/* your task */; }

int find(char str[]){
    /* your task */
  long long 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[]){
    /* your task */
  long long 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(){
    int i, n, h;
    char str[L], com[9];
    for ( i = 0; i < M; i++ ) H[i][0] = '\0';
    
    scanf("%d", &n);
    
    for ( 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: 15460
//https://atcoder.jp/contests/agc021/tasks/agc021_a
#include <bits/stdc++.h>
using namespace std;
using ll=int64_t;
#define FOR(i,a,b) for(int64_t i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
//[決めた桁][未満フラグ,未満のとき1]
ll dp[17][2]={};
int main() {
#if LOCAL&01
    std::ifstream in("./test/sample-1.in"); //input.txt
    std::cin.rdbuf(in.rdbuf());
#endif
    string N; cin>>N;
    ll ans=0;
    REP(i,N.size()){
        if (N[i]=='0') continue;
        ll sum=0;
        REP(k,N.size()){
            ll digit = N[k]-'0';
            if(i==k){
                if (k==N.size()-1) sum+=digit;
                else sum+=digit-1;
            } else if(i<k){
                sum+=9;
            } else {
                sum+=digit;
            }
        }
        ans=max(ans,sum);
    }
    cout<<ans<<endl;
    return 0;
#if 0
    dp[0][0]=1;
    for(ll k=0;k<N.size();++k){ //桁
        ll digit = N[k]-'0';
        for(ll d=0;d<=9;++d){ //未満フラグ1
            //ll has49=f|(d==4||d==9);
            dp[k+1][1] = max(dp[k][1]+d,dp[k+1][1]);
        }
        for(ll d=0;d<=digit;++d){ //未満フラグ0
            //ll has49=f|(d==4||d==9);
            dp[k+1][(d<digit)] = max(dp[k][0]+d,dp[k+1][(d<digit)]); //未満フラグ0は桁数があっているとき
        }
    }
    ll ans=max(dp[N.size()][0],dp[N.size()][1]);
    cout<<ans<<endl;
    return 0;
#endif
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
  int n, m;
  if (scanf("%d %d", &n, &m) == -1) return -1;
  int lr[2][m];
  int i = 0;
  for(i = 0;i < m;i++) {
    if (scanf("%d %d", &lr[0][i], &lr[1][i]) == -1) return -1;
  }
  int left = 1;
  int right = 1000000;
  for(i=0;i<m;i++) {
    if (left < lr[0][i]) left = lr[0][i];
    if (right > lr[1][i]) right = lr[1][i];
  }
  int ans = right - left + 1;
  printf("%d\n", ans < 0 ? 0 : ans);
  return 0;
}

Measured memory_bytes: 896
import sys
from collections import Counter
def main():
    a, b, c, k = map(int, input().split())
    r = 0
    if a >= k:
        print(k)
        sys.exit()
    else:
        r += a
        k -= a
    if b >= k:
        print(r)
        sys.exit()
    else:
        k -= b
    r -= min(k, c)
    print(r)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9460
#pragma GCC optimize("O3")

#include "bits/stdc++.h"

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) for(int i = 0; i < (a); ++i)
#define pb push_back
#define sz(x) (int)x.size()
#define f first
#define s second

vector<int> ans;
vector<bool> vis;

void dfs(int v,vector<vector<int>> &graph)
{
    vis[v]=true;
    F0R(i,sz(graph[v]))
    {
        if(!vis[graph[v][i]])
            dfs(graph[v][i],graph);
    }
    ans.pb(v);
}

void top_sort(vector<vector<int>> &graph)
{
    vis.assign(sz(graph),false);
    ans.clear();
    F0R(i,sz(graph))
    {
        if(!vis[i])
            dfs(i,graph);
    }
    reverse(ans.begin(),ans.end());
}

int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n,m;
    cin >> n >> m;
    vector<vector<int>> graph(n,vector<int>(0));
    int first,second;
    F0R(i,m)
    {
        cin >> first >> second;
        graph[first-1].pb(second-1);
    }
    top_sort(graph);
    reverse(ans.begin(),ans.end());
    map<int,int> mi;
    F0R(i,n)
    {
        // cout << ans[i] << " ";
        mi.insert({ans[i],i});
    }
    // cout << endl;
    vector<int> dp(n,0);
    FOR(i,1,n)
    {
        F0R(j,sz(graph[ans[i]]))
        {
            // if(i==0) cout << "IN HERE" << endl;
            dp[i]=max(dp[i],dp[mi[graph[ans[i]][j]]]+1);
        }
    }
    int res=-1;
    // cout << "dp: " << endl;
    F0R(i,n)
    {
        // cout << dp[i] << " ";
        res=max(res,dp[i]);
    }
    cout << res << endl;

    return 0;
}


Measured memory_bytes: 13304
#include <bits/stdc++.h>
#define int long long
#pragma GCC optimize("O3")

#define fi first
#define se second
#define em emplace
#define eb emplace_back
#define mp make_pair
#define pi pair<int,int>
#define vi vector<int>
#define vpi vector<pair<int,int>>
#define vll vector<ll>
#define vpll vector<pair<ll,ll>>
#define endl '\n'

#define si(v) int((v).size())
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i) 
#define rep2(i, n, m) for (ll i = n; i <= (ll)(m); ++i)
#define rep3(i, n, m) for (ll i = n; i >= (ll)(m); --i)

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

using ll = long long;
using ld = long double;
using namespace std;

constexpr ll MOD = 1000000007;

signed main()
{
  cout << fixed << setprecision(20);
  ios::sync_with_stdio(false);
  cin.tie(0);

  int n; cin >> n;
  map<int,int> m;
  int sum = 0;

  rep(i, n) {
    int a; cin >> a;
    sum += a;
    ++m[a];
  }

  int q; cin >> q;
  rep(i, q) {
    int b, c; cin >> b >> c;
    int s = b * m[b];
    sum -= s;
    sum += c * m[b];
    m[c] += m[b];
    m[b] = 0;

    cout << sum << endl;
  }

  return (0);
}


Measured memory_bytes: 9556
A, B = map(int, input().split())

def calc(n):
    mod = n % 4
    if mod == 0:
        return n
    elif mod == 1:
        return n ^ (n-1) 
    elif mod == 2:
        return n ^ 1
    elif mod == 3:
        return 0
a = calc(A - 1)
b = calc(B)

print(a ^ b)


Measured memory_bytes: 2940
/** @Date    : 2017-07-24 14:47:53
  * @FileName: B 贪心.cpp
  * @Platform: Windows
  * @Author  : Lweleth (SoungEarlf@gmail.com)
  * @Link    : https://github.com/
  * @Version : $Id$
  */
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <algorithm>
#include <utility>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <stack>
#include <queue>
#include <math.h>
//#include <bits/stdc++.h>
#define LL long long
#define PII pair<int ,int>
#define MP(x, y) make_pair((x),(y))
#define fi first
#define se second
#define PB(x) push_back((x))
#define MMG(x) memset((x), -1,sizeof(x))
#define MMF(x) memset((x),0,sizeof(x))
#define MMI(x) memset((x), INF, sizeof(x))
using namespace std;

const int INF = 0x3f3f3f3f;
const int N = 1e5+20;
const double eps = 1e-8;


int vis[400];
int cnt[400];

int main()
{
	int n, m;
	while(cin >> n >> m)
	{
		MMF(vis);
		queue<int>q[400];
		for(int i = 0; i < n; i++)
		{
			for(int j = 0; j < m; j++)
			{
				int x;
				scanf("%d", &x);
				q[i].push(x);
			}
		}
		int ans = INF;
		for(int j = 0; j < m; j++)
		{
			int ma = 0;
			int pos = -1;
			MMF(cnt);
			for(int i = 0; i < n; i++)
			{
				while(vis[q[i].front()])
					q[i].pop();
				int nw = q[i].front();
				cnt[nw]++;
				if(cnt[nw] > ma)
				{
					ma = cnt[nw];
					pos = nw;
				}
			}
			vis[pos] = 1;
			ans = min(ans, ma);
		}
		printf("%d\n", ans);
	}
    return 0;
}

Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
bool sosu[1000005]={0};
bool check[1000005];
main(){
  int n,k;
  int shop;
  sosu[1]=1;
  for(int i=2;i<(int)sqrt(1000005);i++){
    if(sosu[i]==0){
      for(int j=i;j<1000005;j+=i){
	sosu[j]=true;
      }
    }
  }
  while(1){
    bool a=true;
    cin>>n>>k;
    if(n==0&&k==0)break;
    memset(check,false,sizeof(check));
    for(int i=1;i<=n;i++){
      scanf("%d",&shop);
      check[shop]=true;
      for(int j=shop;j<=k;j++){
	if(check[j-shop]==true){
	  check[j]=true;
	}
      }  
    }
    for(int i=k;i>0;i--){
      if(sosu[i]==false&&check[i]==true){
	cout<<i<<endl;
	i=0;
	a=false;
      } 
    }
    if(a){
      cout<<"NA"<<endl;
    }
  }
}

Measured memory_bytes: 3200
#14:35
s = input()
n = len(s)
scr = 0
for i in range(n):
  a = int(s[i])
  if i == 0:
    b = 0
  else:
    b = 1 - b
  if a != b:
    scr += 1
#print(scr)
print(min(scr,n-scr))

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

typedef long long ll;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define print(n) cout << n << endl
const ll INF = 1e18;

int main(){
    ll N;
    cin >> N;

    vector<ll> a(N);
    rep(n,N) cin >> a[n];
    
    vector<vector<ll>> dp(2,vector<ll>(3, -INF));
    dp[0][0] = 0; dp[1][0] = 0;
    bool n;
    ll temp;
    const bool even = N & 1;
    rep(i,N){
        n = i&1;
        if(even && i >= 6 && !n){
            if(i == 6) dp[0][2] = a[0] + a[3] + a[6];
            else dp[0][2] = max(dp[0][2], temp) + a[i];
        }
        if(i >= 2){
            if(i <= 3) dp[n][1] = a[i] + n * a[0];
            else{
                if(n) temp = dp[n][1];
                dp[n][1] = max(dp[n][1], dp[1-n][0] - a[i-1]) + a[i];
            }
        }
        dp[n][0] += a[i];
    }
    if(even) dp[0][0] -= a[N-1];

    ll ans;
    if(N<=3) ans = max({dp[0][0],dp[0][1],dp[1][0]});
    else ans = max({dp[1-even][0],dp[1-even][1],dp[1-even][2]});
    
    print(ans);
    return 0;
}

Measured memory_bytes: 4856