akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;
#define MOD 2019
int main(void)
{
	long long int L, R;
	long long int ans = MOD - 1;
	long long int i, j;

	cin >> L >> R;
	if ((R - L) >= MOD)ans = 0;
	else {
		for (i = L; i < R; i++) {
			for (j = i + 1; j <= R; j++) {
				long long int remain = (i * j) % MOD;
				if (remain < ans)ans = remain;
			}
		}
	}
	cout << ans << endl;

	return 0;
}

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

typedef long long ll;
const int INF = 1e9;
const ll LINF = 1e18;
const int mod = 1e9+7;

#define pi pair<int,int>
#define pl pair<lld,lld>

#define dump(x) cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define SANKOU(n,a,b) cout << ((n) ? (#a) : (#b) ) << endl

#define mem0(x) memset(x,0,sizeof(x))
#define fillnum(x,n) fill(begin(x),end(x),n)
#define asort(x) sort(x.begin(),x.end())
#define dsort(x,t) sort(x.begin(),x.end(),greater<t>())
#define vuniq(x) x.erase(unique(x.begin(), x.end()), x.end())

#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)

int main() {
    string S;
    cin >> S;
    if(S == "SUN") cout << 7 << endl;
    else if(S == "MON") cout << 6 << endl;
    else if(S == "TUE") cout << 5 << endl;
    else if(S == "WED") cout << 4 << endl;
    else if(S == "THU") cout << 3 << endl;
    else if(S == "FRI") cout << 2 << endl;
    else cout << 1 << endl;
}

Measured memory_bytes: 3624
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <sstream>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define F first
#define S second
#define pb push_back
#define pf push_front

using ll = long long;
using namespace std;
namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
ll M = 1000000007;
typedef pair<int, int> P;

typedef pair<ll, int> pli;

void solve()
{
    int n;
    cin >> n;
    vector<int> a(n);
    deque<int> pos;
    int now = 1;
    rep(i, n)
    {
        cin >> a[i];
        if (a[i] == now)
        {
            pos.pb(i + 1);
            now++;
        }
    }
    ll ans=0;
    if (now == 1)
    {
        ans=-1;
    }
    else
    {
        int prev = 0;
        rep(i, pos.size())
        {
            ans+=pos[i]-prev-1;
            prev=pos[i];
        }
        ans+=n-prev;
    }
    cout<<ans<<endl;
}
// DPテーブル
int main()
{
    solve();
}

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

using namespace std;


int main() {
	long long n, k;
	cin >> n >> k;

	vector<int> a(n);

	for (int i = 0; i < n; i++) {
		cin >> a[i];
		a[i]--;
	}

	int slow = 0;
	int fast = 0;

	do
	{
		slow = a[slow];
		fast = a[a[fast]];
	} while (fast != slow);


	int curr = 0;
	int len = 0;

	while (curr != fast) {
		curr = a[curr];
		len++;
	}
	
	if (k <= len) {
		int ans = 0;
		while (k > 0) {
			k--;
			ans = a[ans];
		}

		cout << ans + 1;
		return 0;
	}

	k -= len;

	int cycleLen = 0;

	do
	{
		fast = a[fast];
		cycleLen++;
	} while (curr != fast);

	k %= cycleLen;

	while (k > 0) {
		k--;
		fast = a[fast];
	}

	cout << fast + 1;
}

Measured memory_bytes: 4044
#include<bits/stdc++.h>
using namespace std;
int main(){
    long long x;
    cin >> x;
    for (int i = 0; i < 1000; i++){
        if (x < 0){
            for (int j = 0; i < 1000; i++){
                if (x == i*i*i*i*i -j*j*j*j*j){
                    cout << i << ' ' << j << endl;
                    return 0;
                }
            }
        }else{
            for (int j = 1000; j > -1000; j--){
                if (x == i*i*i*i*i -j*j*j*j*j){
                    cout << i <<' ' << j << endl;
                    return 0;
                }
            }
        }
    }
    cout << 1.0 * clock() / CLOCKS_PER_SEC;
    return 0;
}

Measured memory_bytes: 3636
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main
{

  public static void main(String[] args) throws IOException
  {
    BufferedReader r = new BufferedReader(new InputStreamReader(System.in), 1);

    String s;
    String sl[];

    s = r.readLine();
    sl = s.split(" ");

    System.out.println(Double.parseDouble(sl[0]) / Double.parseDouble(sl[1]));
  }

}

Measured memory_bytes: 21332
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, K;
    cin >> N >> K;
    int ans = 0;
    rep(i, N) {
        int tmp;
        cin >> tmp;
        ans += min(tmp*2, abs(K-tmp)*2);
    }
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 256
a,b,k = map(int,input().split())
if a+b <=k:
    a,b=0,0
elif a >=k :
    a = a-k
else:
    k = k -a 
    a = 0
    if b >= k:
        b = b-k
    else:
        b = k -b
print(a,b)

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

using namespace std;
 
typedef long long ll;
typedef unsigned long long u_ll;
typedef pair<int, int> pair_;

const long double PI = (acos(-1));
 
const int INF = 1001001001;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};

 
int gcd(int a, int b){
    if(b == 0) return a;
 
    return gcd(b, a%b);
}
 
int main(){
    
    string s, t;

    cin >> s >> t;

    int siz=s.size();

    int ans = 1;

    rep(i, siz){

        if(s[i]==t[i]) continue;
        else {
            ans = 0;
            break;
        }
    }

    if(ans) cout << "Yes";
    else cout << "No"; 

    return 0;
}

Measured memory_bytes: 3624
#include <cstdio>
#include <cmath>
#include <algorithm>
#define REP(val,times) for(int val = 0;val < times;val++)
int x[1001],y[1001];

int main(){
    int n;
    double p1 = 0.0,p2 = 0.0,p3 = 0.0,pinf = 0.0;
    scanf("%d",&n);
    REP(i,n)
        scanf("%d",&x[i]);
    REP(i,n)
        scanf("%d",&y[i]);
    REP(i,n){
        p1 += fabs(x[i] - y[i]);
        p2 += (x[i] - y[i]) * (x[i] - y[i]);
        p3 += fabs((x[i] - y[i]) * (x[i] - y[i]) * (x[i] - y[i]));
        pinf = fmax(pinf,fabs(x[i] - y[i]));
    }
    printf("%.6lf\n",p1);
    printf("%.6lf\n",sqrt(p2));
    printf("%.6lf\n",pow(p3,1.0 / 3.0));
    printf("%.6lf\n",pinf);

    return 0;
}


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

signed main(){
  int n; cin >> n;
	string s; cin >> s;
	bool ok = true;
	vector<string> t(4);
	t[0] = "SS"; t[1] = "SW"; t[2] = "WS"; t[3] = "WW";
	for(int i = 0; i < 4; i++){
  	for(int j = 2; j < n; j++){
		  if(t[i][j - 1] == 'S'){
				if(s[j - 1] == 'o') t[i].push_back(t[i][j - 2]);
				if(s[j - 1] == 'x'){
					if(t[i][j - 2] == 'W') t[i].push_back('S');
					if(t[i][j - 2] == 'S') t[i].push_back('W');
				}
			}
			if(t[i][j - 1] == 'W'){
				if(s[j - 1] == 'x') t[i].push_back(t[i][j - 2]);
				if(s[j - 1] == 'o'){
					if(t[i][j - 2] == 'W') t[i].push_back('S');
					if(t[i][j - 2] == 'S') t[i].push_back('W');
				} 
			}
		} 
	}
	for(int i = 0; i < 4; i++){
		ok = true;
		if(s.back() == 'o'){
			if(t[i][n - 1] == 'S' && t[i][n - 2] != t[i][0]) ok = false;
			if(t[i][n - 1] == 'W' && t[i][n - 2] == t[i][0]) ok = false;
		}
		if(s.back() == 'x'){
			if(t[i][n - 1] == 'S' && t[i][n - 2] == t[i][0]) ok = false;
			if(t[i][n - 1] == 'W' && t[i][n - 2] != t[i][0]) ok = false;
		}
		if(s[0] == 'o'){
			if(t[i][0] == 'S' && t[i][1] != t[i][n - 1]) ok = false;
			if(t[i][0] == 'W' && t[i][1] == t[i][n - 1]) ok = false;
		}
		if(s[0] == 'x'){
			if(t[i][0] == 'S' && t[i][1] == t[i][n - 1]) ok = false;
			if(t[i][0] == 'W' && t[i][1] != t[i][n - 1]) ok = false;
		}
		if(ok){
			cout << t[i] << endl;
			return 0;
		}
	}
	cout << -1 << endl;
}


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

using namespace std;

int main(){
    int N;
    cin >> N;
    set<string> s;
    string temp;
    for(int i=0; i!=N; i++){
        cin >> temp;
        s.insert(temp);
    }
    cout << s.size() << endl;

    return 0;   
}

Measured memory_bytes: 19220
#include<bits/stdc++.h>
using namespace std;
typedef		vector<int>				 vi;
typedef 	vector<vi>				vii;
typedef		pair<int,int>			pii;
typedef		unsigned long long		ull;
typedef		long long				ll ;
#define MOD (int)(1e9+7)
#define INF (int)(1<<29) 
#define fori(i,a,b)		for(int i=a ; i <= b ; i++) 			
#define ford(i,a,b)  	for(int i=a ; i >= b ; i-- ) 
#define rep(i,n)   		for(int i=0; i < n ; i++ ) 
#define DEBUG(x)		cout << '>' << #x << ':' << x << endl;


int main()
{
	ios_base::sync_with_stdio(0);	
	int x , a , b ;
	cin >> x >> a >> b ;
	int d1 = abs(x-a) ;
	int d2 = abs(x-b) ; 
	if ( d1 > d2 ) 
	{
		cout << "B\n";
	}
	else
		cout << "A\n";

	return 0 ;
}



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

int main()
{
	ll n;
	cin >> n;
	ll ans = 0;
	ans += n/500*1000;
	n -= ans/2;
	ans += n/5*5;
	cout<<ans<<endl;
}


Measured memory_bytes: 3492
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>
using namespace std;
int n,cnt1[111],cnt2[111],a,b;
string s;
int main()
{
	cin>>n>>s;
	for(int i=0;i<n;i++)
	{
		if(s[i]=='(')
		{
			a++;
		}
		else
		{
			if(a)
			{
				a--;
			}
			else
			{
				b++;
			}
		}
	}
	for(int i=0;i<b;i++)
	{
		cout<<'(';
	}
	cout<<s;
	for(int i=0;i<a;i++)
	{
		cout<<')';
	}
	cout<<endl;
	return 0;
}

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

typedef long long ll;


ll N;
ll A[100010],B[100010];
int main(){
  cin>>N;
  for(int i=0;i<N;i++){
    cin>>A[i]>>B[i];
  }
  ll ans=0,t;
  //逆から
  for(int i=N-1;i>=0;i--){
    bool flag=true;
    if((A[i]+ans)%B[i]==0){
      flag=false;
    }
    if(flag){
      t=(A[i]+ans)/B[i];
      t++;
      ans+=B[i]*t-(A[i]+ans);
    }


  }

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


Measured memory_bytes: 1792
#include<iostream>
    using namespace std;
    int main(){
    int n,a,b=0,c;
    cin>>n>>a;
    while(n-c>0){
    b++;
    c=(a*2+1)*b;
    if(n-c==0)
    break;
    }
    cout<<b<<'\n';
    } 

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String str = scan.nextLine();
		int count = 0;
		for(int i = 0; i < 3; ++i) {
			if(str.charAt(i) == '1') {
				count++;
			}
		}
		System.out.println(count);
		scan.close();
	}
}


Measured memory_bytes: 21844
#include<stdio.h>

int main(void)
{
  long n , ans = 1 , t = 1000000007;
  scanf("%ld",&n);
  
  for(int i = 1;i <=n;i++){
    ans=ans*i;
    if(t<ans){
      ans=ans%t;
  }}
  
  printf("%ld",ans%t);
  
  return 0;
}

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

int main (){
	int n, a, b, lugaresOcupados=0;

	scanf("%d", &n);

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

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

	return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.util.Map.Entry;

 class Main {
	 static int mod =  (int) (Math.pow(10,9)+7);
    public static void main(String[] args) {
    	
        Scanner sc = new Scanner(System.in);
        int anser=0;
        int H = sc.nextInt();
        int W = sc.nextInt();
        int[][] s = new int[H][W];
        int[][] ans = new int[H][W];
		for(int i=0;i<H;i++) {
			String ss = sc.next();
			for(int j=0;j<W;j++) {
//				System.out.println(ss.substring(j,j+1));
				if ("#".equals(ss.substring(j,j+1))) {
					s[i][j]=0;
				} else {
					s[i][j]=1;
				}
			}
        }
        
		for(int i=0;i<H;i++) {
			for(int j=0;j<W;j++) {
				if(s[i][j]==1) {
					int count=0;
					for(int k=j+1;k<W&&s[i][k]==1;k++) {
						count++;
					}
					for(int k=0;k<=count;k++) {
						ans[i][j]=count;
						j++;
					}
				}
			}
		}
		for(int j=0;j<W;j++) {
			for(int i=0;i<H;i++) {
				if(s[i][j]==1) {
					int count=0;
					for(int k=i+1;k<H&&s[k][j]==1;k++) {
						count++;
					}
					for(int k=0;k<=count;k++) {
						ans[i][j]=ans[i][j]+count;
						if(anser<ans[i][j]) {
							anser=ans[i][j];
						}
						i++;
					}
				}
			}
		}
		
		
        System.out.println(anser+1);			
    }
}

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

int main(){
  
  int n, x, y;
  
  cin >> n;
  pair<int, int> p[n];
  for(int i = 0;i < n;i++){
    cin >> x >> y;
    p[i] = make_pair(x, y);
  }
  
  sort(p, p + n);
  
  for(int i = 0;i < n;i++) cout << p[i].first << " " << p[i].second << endl;
  
  return 0;
}


Measured memory_bytes: 3876
#include<stdio.h>
 
int main(void)
{
    while (1) {
        char str_num[1001];
 
        scanf("%s", str_num);
 
        if (str_num[0] == '0') break;
 
        int i = 0;
        int sum = 0;
 
        do {
            sum += (str_num[i] - '0');
            i++;
        } while (str_num[i] != '\0');
 
        printf("%d\n", sum);
    }
 
    return 0;
}


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

using namespace std;

int main() {
	ios::sync_with_stdio(false);
	long long n;
	cin>>n;
	long long res = 0;
	long long curr = 1;
	while (n > 0) {
		res += curr;
		n /= 2;
		curr *= 2;
	}
	cout<<res<<endl;
}


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

typedef long long int ll;
typedef long double ld;

#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
#define pll pair<ll,ll>
#define mp make_pair
#define ff first
#define ss second
#define pb push_back
#define mod 1000000007
#define lp(start,end) for(ll i=start;i<=end;i++) 
#define deb1(a) cout<<#a<<" = "<<(a)<<endl;
#define deb2(a,b) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<endl;
#define deb3(a,b,c) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<", "<<#c<<" = "<<(c)<<endl;


ll modu(ll a, ll b)
{
	ll ans =1;
	while(b>0)
	{
		if(b&1)
		ans = (ans*a)%mod;
		b/=2;
		a = (a*a)%mod;
	}
	return ans;
}

int main()
{
	fastio
	ll n,x,t;
	cin >> n >> x >> t;
	if(n%x==0)
	{
		cout << (n*t)/x << endl;
	}
	else
	{
		cout << (n/x + 1)*t << endl; 
	}
	return 0;	
}


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

using namespace std;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define BIT(X, i) ((X>>i)&1)
#define REP(i, a, b) for(int i = (a); i < (b); ++i)
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(a) (a).begin(), (a).end()
#define r_all(a) (a).rbegin(), (a).rend()
#define in(x) cin>>x
#define ina(x, n) rep(x_i,n) cin>>x[x_i]
#define outa(x, n) rep(x_i,n) cout<<x[x_i]<<" \n"[x_i==n-1]

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> pll;
typedef vector<pll> vll;
typedef priority_queue<ll> pq;

const int MOD = 1e9+7;
const int INF = (1<<30);
const ll INFL = (1L<<62);

int main() {
  string s; cin >> s;
  int n = s.length();
  vvl alps(26, vl(n,0));
  for (int i = n-1; i > 0; i--) {
    alps[s[i]-'a'][i]++;
    rep(j,26) {
      alps[j][i-1] += alps[j][i];
    }
  }
  ll ans = 1;
  for (int i = 0; i < n-1; i++) {
    rep(j,26) {
      if (s[i]-'a' == j) continue;
      ans += alps[j][i+1];
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 42756
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>

using namespace std;

int main() {
	int n;
	cin >> n;
	string abc = "abcdefghijklmnopqrstuvwxyz";
	vector< vector<int> > dd(n, vector<int>(26, 0));
	string a;
	for (int i = 0; i < n; i++) {
		cin >> a;
		for (int j = 0; j < a.size(); j++) {
			dd[i][a[j] - 'a']++;
		}
	}
	string s = "";
	for (int i = 0; i < 26; i++) {
		int aa = dd[0][i];
		for (int j = 0; j < n; j++) {
			aa = min(aa, dd[j][i]);
		}
		for (int j = 0; j < aa; j++) {
			s += abc[i];
		}
	}
	cout << s << endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
using namespace std;

int main() {
    int n;
    vector<int> v = {};
    vector<int> cnt = {};
    int po = 0;
    scanf("%d", &n);
    v.resize(n);
    cnt.resize(n);
    for (int i = 0; i < n; i++) {
        scanf("%d", &v[i]);
    }
    int tmp = v[0];
    while (true) {
        po++;
        if ((tmp-1) == 1) {
            printf("%d\n", po);
            break;
        }
        cnt[tmp - 1]++;
        if (cnt[tmp - 1] == 2) {
            printf("%d\n", -1);
            break;
        }
        tmp = v[tmp - 1];
    }
}

Measured memory_bytes: 1024
H,W,K = map(int,input().split())
Cake = []
for i in range(H):
  temp = str(input())
  temp = list(temp)
  Cake.append(temp)
#print(Cake)

n = 0 #ケーキの番号
ans = [[0]*W for _ in range(H)]
rem = set([])
for i in range(H):
  row = set(Cake[i])
  if "#" not in row: #この列にイチゴがない。
    if i == 0 or i-1 in rem:
      rem.add(i) #上もない。
    else:
      ans[i] = ans[i-1]
  else:
    n += 1
    Flag = True #Trueの間は一個目のイチゴ
    for j in range(W):
      if Flag and Cake[i][j] == "#":
        ans[i][j] = str(n)
        Flag = False
      elif Cake[i][j] == "#":
        n += 1
        ans[i][j] = str(n)
      else:
        ans[i][j] = str(n)
    if rem:
      for t in rem:
        ans[t] = ans[i]
      rem = set([])
#print(ans)
for t in range(H):
  temp = " ".join(ans[t])
  print(temp)
#print(" ".join(ans[i]) for i in range(H))  

Measured memory_bytes: 10100
$mod = 10**9+7

def pow(a,b)
  if b == 1
    a
  elsif b%2 == 0
    (pow(a,b/2)**2)%$mod
  else
    (a*pow(a,b/2)**2)%$mod
  end
end

def create_fact(n)
  for i in 2..n
    $fact[i] = ($fact[i-1]*i)%$mod
  end
end

def create_fact_inv(n)
  $fact_inv[n] = pow($fact[n],$mod-2)
  n.downto(1) do |i|
    $fact_inv[i-1] = ($fact_inv[i]*i)%$mod
  end
end

def create_inv(n)
  for i in 1..n
    $inv[i] = ($fact[i-1]*$fact_inv[i])%$mod
  end
end

def init(n)
  $fact = Array.new(n+1,1)
  $fact_inv = Array.new(n+1,1)
  $inv = Array.new(n+1,0)
  create_fact(n)
  create_fact_inv(n)
  create_inv(n)
end

def combi(a,b)
  (($fact[a]*$fact_inv[b])%$mod)*$fact_inv[a-b]%$mod
end

init(1000010)
n = gets.to_i
a = gets.split.map(&:to_i)
ans = 1
a.each do |i|
    ans = ans.lcm(i)
end
ans %= $mod
c = 0
a.each do |i|
    c += $inv[i]
    c -= $mod if c > $mod
end
puts ans*c%$mod

Measured memory_bytes: 77840
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define de(c) cout << #c << " = " << c << endl
#define dd(c) cout << #c << " = " << c << " "
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
mt19937 mrand(random_device{}());
const ll mod=100000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

const int maxn = 200023;
int T;
int n;
string str;
string a;
string b;

int main(int argc, char const *argv[])
{
#ifdef indiewar
    freopen("in.txt","r",stdin);
//    freopen("out.txt","w",stdout);
#endif
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
//    cin >> T;
    T =1;
    while(T--)
    {
        cin >> str;
        cin >> n;
        int f = 0;
        rep(i,0,n) {
            int x, y;
            cin >> x;
            if (x == 1) {
                f++;
            } else {
                char c;
                cin >> y >> c;
                if (y == 1) {
                    if (f % 2 == 0) a += c;
                    else b += c;
                } else {
                    if (f % 2 == 1) a += c;
                    else b += c;
                }
            }
        }
            if(f % 2 == 0)
            {
                reverse(a.begin(),a.end());
                cout << a << str << b << endl;
            }
            else {
                reverse(b.begin(), b.end());
                reverse(str.begin(), str.end());
                cout << b << str << a << endl;
            }

    }
    return 0;
}

Measured memory_bytes: 1104
N, M = [int(a) for a in input().split()]
adj = [[False] * N for _ in range(N)]
edgelist = []
for i in range(M):
    a, b = [int(a) for a in input().split()]
    a-=1
    b-=1
    adj[a][b] = True
    adj[b][a] = True
    edgelist.append((a,b))

bridges = 0
for a,b in edgelist:
    adj[a][b] = False
    adj[b][a] = False

    marked = [False] * N
    stk = [a]
    while stk:
        x = stk.pop()
        marked[x] = True
        for i in range(N):
            if adj[x][i] and not marked[i]:
                stk.append(i)
    if not marked[b]:
        bridges += 1

    adj[a][b] = True
    adj[b][a] = True

print(bridges)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int A[200001];
bool K[200001];
queue<int>Q;
int main() {
	int a,i,j,w;
	cin>>a;
	for(i=1; i<=a; i++)cin>>A[i];
	for(i=a; i>=1; i--) {
		w=0;
		for(j=i+i; j<=a; j+=i)w+=K[j];
		w%=2;
		if(w!=A[i])K[i]=1,Q.push(i);
	}
	cout<<Q.size()<<endl;
	while(!Q.empty())cout<<Q.front()<<" ",Q.pop();
}

Measured memory_bytes: 2432
# _*_ coding:utf-8 _*_
#  Atcoder_Beginners_Contest087-B
#  https://beta.atcoder.jp/contests/abc087/tasks/abc087_B

def  selectPattern(a500yen,b100yen,c50yen,total):
	a500yenRange = range(0,a500yen+1)
	b100yenRange = range(0,b100yen+1)
	c50yenRange = range(0,c50yen+1)
	nowPattern = 0
	for a in a500yenRange:
		thisTotal = 0
		for b in b100yenRange:
			for c in c50yenRange:
				thisTotal = a*500+b*100+c*50
				if thisTotal == total :
					nowPattern = nowPattern+1

	answer = nowPattern
	return answer


if __name__ == '__main__':
	a500yen = int(input())
	b100yen = int(input())
	c50yen = int(input())
	total = int(input())
	solution=selectPattern(a500yen,b100yen,c50yen,total)
	print(solution)

Measured memory_bytes: 3064
N = int(input())
C = [100+i for i in range(6)]
T = [float('inf')]*(N+1)
T[0] = 0

for i in range(6):
    for j in range(C[i], N+1):
        T[j] = min(T[j], T[j - C[i]] + 1)

if T[N] != float('inf'):
    print(1)
else:
    print(0)

Measured memory_bytes: 11848
#include<stdio.h>

int main(void)
{
	int a, b, x = 0;
	char op = 0;
	
	while(1) {
		
		scanf("%d %c %d", &a, &op, &b);
		
		if(op == '+'){
			x = a + b;
		} else if (op == '-'){
			x = a - b;
		} else if (op == '*'){
			x = a * b;
		} else if (op == '/'){
			x = a / b;
		} else if (op == '?') break;
		
		printf("%d\n", x);
		
	}
	
	return 0;
	
}




Measured memory_bytes: 2120
H, W, A, B = map(int, input().split())

if W//2 < A or H//2 < B:
    print("No")
    exit(0)

ans = [[0 for _ in range(W)] for __ in range(H)]
for i in range(H):
    for j in range(W):
        if i >= B and j < A:
            ans[i][j] = 1
        elif i < B and j >= A:
            ans[i][j] = 1

for j in range(H):
    print("".join(str(x) for x in ans[j]))


Measured memory_bytes: 83420
#include<bits/stdc++.h>
#define ll long long 
#define int ll
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;

int32_t main(){
    fast;
    int N{},x{},c{};    cin>>N>>x;
    int A[N+1]{}; for(int i=0;i<N;i++)    cin>>A[i];
    for(int i=1;i<N+1;i++){
        if(A[i]+A[i-1] > x){
        c += A[i]+A[i-1]-x;
        A[i] -= A[i]+A[i-1]-x;
    }
        
    }
    cout<<c<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <queue>
#include <list>
#include <stack>
#include <math.h>
#include <map>
#include <unordered_map>
using namespace std;

#define ll long long
#define ull unsigned long long

#define	max	1000000007

class mod
{
public:
	ll val;

	mod(ll v)
	{
		val = v % max;
	}

	mod()
	{
		val = 0;
	}

	void operator -=(const mod &v)
	{
		val -= v.val;

		if (val < 0)
			val += max;		
	}

	void operator +=(const mod &v)
	{
		if (val + v.val >= max)
			val -= max;
		val += v.val;
	}

	void operator +=(ll &v)
	{
		if (val + v >= max)
			val -= max;
		val += v;
	}

	void operator *=(const mod &v)
	{
		val *= v.val;
		val %= max;
	}

	void operator *=(ll &v)
	{
		val *= v;
		val %= max;
	}

	ll modinv(ll a)
	{
		ll b = max, u = 1, v = 0;
		while (b) 
		{
			ll t = a / b;
			a -= t * b; swap(a, b);
			u -= t * v; swap(u, v);
		}
		u %= max;
		if (u < 0)
			u += max;
		return u;
	}

	void operator /=(const mod &v)
	{
		val *= modinv(v.val);
		val %= max;
	}

	void operator /=(ll &v)
	{
		val *= modinv(v);
		val %= max;
	}
};

int main()
{
	int n, k;
	cin >> n >> k;
	
	mod combi1(1), combi2(n - k + 1);
	ll p1 = k, q1 = 0, p2 = n - k + 1, q2 = 1;

	for (int i = 0; i < k; i++)
	{
		//	do
		mod r(combi1);
		r *= combi2;

		printf("%lld\n", r.val);

		combi1 *= --p1;
		combi1 /= ++q1;
		combi2 *= --p2;
		combi2 /= ++q2;
	}
	return 0;
}


Measured memory_bytes: 256
h,w = map(int, input().split())
maze = [list(input()) for _ in range(h)]
max_step = 0

for h_i in range(h):
  for w_i in range(w):
    grid = [[-1]*w for _ in range(h)]
    
    if maze[h_i][w_i] == '.':
      grid[h_i][w_i] = 0
      loc = [[h_i,w_i]]
      
      for k in range(1, h*w):
        next_loc = []
        for y,x in loc:
          for i,j in ([1,0], [-1,0], [0,1], [0,-1]):
            next_h = y+i
            next_w = x+j
            
            if 0 <= next_h < h and 0 <= next_w < w and maze[next_h][next_w] == '.' and grid[next_h][next_w]==-1: 
              grid[next_h][next_w] = k
              next_loc.append([next_h, next_w])
        loc=next_loc
      # print(grid)
      temp_max_step = max(max(grid_w) for grid_w in grid)
      max_step = max(max_step, temp_max_step)
      
print(max_step)

Measured memory_bytes: 3064
#include<cstdio>
using namespace std;
int a,b;
int main()
{
  scanf("%d%d",&a,&b);
  if(a==0||b==0)  printf("Zero");
  else if(a>0&&b>0)  printf("Positive");
  else if((a<0&&b>0)||(a>0&&b<0))  printf("Zero");
  else 
  {
  	int k=a-b;
  	if(k<0)  k=-k;
  	if(k%2)  printf("Positive");
  	else  printf("Negative");
  }
  return 0;
} 

Measured memory_bytes: 128
N,K=map(int,input().split())
cnt=0
if K==0:
    print(N*N)
else:
    for i in range(K+1,N+1):    #bの数について
        fin=N%i
        if (fin>=K):
            cnt=cnt+(fin-K)+1
        clus=(N-fin)//i
        cnt=cnt+clus*(i-K)
        #print(cnt)
    print(cnt)

Measured memory_bytes: 39280
#include<iostream>
#include<cmath>
#include<cstdio>
using namespace std;
typedef long long LL;

int main(){
    LL x , y , flag = 1;
    cin>>x>>y;
    while(2 * x <= y){
    	flag += 1;
    	x = 2 * x;
    	}
    cout<<flag<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <vector>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <ctype.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)


int main(){
	int a,b,k;
	cin>>k >> a >> b;
	
	int i=0;
	while(true){
		i += k;
		
		if(i>= a && i<=b) {
			cout << "OK\n";
			return 0;
		} else if(i>b){
			break;
		}
	}
	cout << "NG\n";
	
	
	return 0;
}

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

int main() {
  int a, b, c;
  long long k;
  cin>>a>>b>>c>>k;
  long long ans;
  if (k % 2 == 0) {
    ans = a - b;
  } else {
    ans = b -a ;
  }
  if (abs(ans) > 1e18) {
    cout<<"unfair"<<endl;
  } else {
    cout<<ans<<endl;
  }

}

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

int main(void){
    string s;
    bool flug = false;
    char ans;
    char c;
    int i;
    
    cin >> s;
    
    for(c = 'a'; c <= 'z'; c++){
        for(i = 0; i < s.length(); i++){
            if(c == s[i])       break;
        }
        if(i == s.length()){
            flug = true;
            ans = c;
            break;
        }
    }
    
    if(flug)        cout << ans << endl;
    else            cout << "None\n";
    
    return 0;
}

Measured memory_bytes: 512
#include <algorithm>
#include <bitset>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

int main() {
    vector<int> alphas(26, 0);
    char ch;
    while (cin >> ch) {
        if (isupper(ch)) {
            ch = tolower(ch);
        }
        if (isalpha(ch)) {
            alphas[ch - 'a']++;
        }
    }
    for (int i = 0; i < alphas.size(); i++) {
        printf("%c : %d\n", 'a' + i, alphas[i]);
    }
}

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

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

  vector<int> p(n);
  for (int i = 0; i < n; i++) {
    cin >> p.at(i);
  }

  vector<int> q(n);
  for (int i = 0; i < n; i++) {
    q.at(i) = p.at(i);
  }
  sort(q.begin(),q.end());

  int count = 0;
  for (int i = 0; i < n; i++) {
    if (q.at(i) != p.at(i)) {
      count++;
    }
    if (count > 2) {
      break;
    }
  }

  if(count < 3){
    cout << "YES" << endl;
  }
  else{
    cout << "NO" << endl;
  }

}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<time.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
const int inf=1e8;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
int main(){
	int n;
	while(cin>>n,n){
		vector<string>s(n);
		vector<double>ko(n);
		rep(i,n){
			int p,a,b,c,d,e,f,ss,m;
			cin>>s[i]>>p>>a>>b>>c>>d>>e>>f>>ss>>m;
			double syu=f*ss*m-p;
			double t=a+b+c+(d+e)*m;
			ko[i]=syu/t;
		}
		map<double,vector<string> >out;
		rep(i,n)out[ko[i]].pb(s[i]);
		map<double,vector<string> >::iterator it=out.end();
		for(it--;;it--){
			double d=it->first;
			sort(all(out[d]));
			rep(i,out[d].size())cout<<out[d][i]<<endl;
			if(it==out.begin())break;
		}
		cout<<"#"<<endl;
	}
}

Measured memory_bytes: 1228
#include <iostream>
#include <vector>
#include <numeric>
using i64 = long long;

class UF {
    std::vector<int> par, rank;

    public:
    UF(int size) : par(size), rank(size) {
        std::iota(par.begin(), par.end(), 0);
    }

    int root(int x) {
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    bool same(int x, int y) {
        return root(x) == root(y);
    }

    void unite(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y) return;

        if (rank[x] < rank[y]) par[x] = y;
        else {
            par[y] = x;
            if (rank[x] == rank[y]) rank[x]++;
        }
    }
};

int main() {
    int n, q;
    std::cin >> n >> q;

    UF uft(n + 1);
    while (q--) {
        int t, u, v;
        std::cin >> t >> u >> v;
        if (t) std::cout << uft.same(u, v) << '\n';
        else uft.unite(u, v);
    }

    return 0;
}


Measured memory_bytes: 4724
#include <stdio.h>
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <string>
#include <utility>
#include <queue>
#include <unordered_set>
#include <set>
#include <unordered_map>
#include <cmath>
#include <iomanip>
using namespace std;
#define sL(i) i << 1
#define sR(i) i << 1 | 1
#define mp make_pair
#define pb push_back
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pair<int,int>, int> ppi;
const int MOD = 1e9 + 7;
const int INF = 2e9 + 5;


int main(){
    cin.sync_with_stdio(0);
    cin.tie(0);
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    if(a < b) swap(a, b);
    if(a < c) swap(a, c);
    cout << (a<<k) + b + c;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
namespace io{
	const int l=1<<20;
	char buf[l],*s,*t;
	inline char gc(){
		if(s==t){
			t=(s=buf)+fread(buf,1,l,stdin);
			return s==t?EOF:*s++;
		}
		return *s++;
	}
	char c;
	template<class IT>inline void gi(IT &x){
		x=0;c=gc();while(c<'0'||c>'9')c=gc();
		while('0'<=c&&c<='9'){x=(x<<1)+(x<<3)+(c^48);c=gc();}
	}
};
using io::gi;
template<class IT>inline void _int(      IT &a,      IT &b  ){if(a>b)swap(a,b);}
template<class IT>inline void cmin(      IT &a,const IT &b=0){if(a>b)a=b;}
template<class IT>inline void cmax(      IT &a,const IT &b=0){if(a<b)a=b;}
template<class IT>inline IT   _min(const IT &a,const IT &b=0){return a>b? b:a;}
template<class IT>inline IT   _max(const IT &a,const IT &b=0){return a<b? b:a;}
template<class IT>inline IT   _abs(const IT &a              ){return a<0?-a:a;}

const int N=105;
char s[N];
int main(){
//	freopen("a.in","r",stdin);
//	freopen("a.out","w",stdout);
	int n,k,i,j,ans=0,ant=0,anu=0;
	scanf("%s%d",s+1,&k);n=strlen(s+1);
	if(s[1]==s[n]){
		for(i=2;i<n;++i)if(s[1]!=s[i])break;
		if(i>=n){printf("%lld",(n*((ll)k))>>1);return 0;}
//		printf("START\n");
		for(i=j=1;i<=n;i=j){
			while(s[i]==s[j])++j;//printf("%d %d\n",i,j);
			if(i==1||j>n){ant+=((j-i)>>1);anu+=j-i;}
			else ans+=((j-i)>>1);
		}
//		printf("%d %d %d\n",ans,ant,anu);
		printf("%lld",ans*((ll)k)+ant+(anu>>1)*((ll)(k-1)));
	}else{
		for(i=j=1;i<=n;i=j){
			while(s[i]==s[j])++j;
			ans+=((j-i)>>1);
		}
		printf("%lld",ans*((ll)k));
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;
const ll oo = 0x3f3f3f3f3f3f3f3fLL;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c),end(c)
#define mp make_pair
#define pb push_back
#define xx first
#define yy second
#define FOR(i,a,b) for (ll i=(a); i<(b); i++)
#define FORD(i,a,b) for (ll i=ll(b)-1; i>=(a); i--)

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

	ll n; cin >> n;
	multiset<double> blob;
	FOR(i,0,n) {
		ll a; cin >> a;
		blob.insert(a);
	}

	while(blob.size() > 1) {
		double firs = *blob.begin();
		blob.erase(blob.begin());
		double secon = *blob.begin();
		blob.erase(blob.begin());
		blob.insert((firs + secon) / 2.0 );
	}

	cout << *blob.begin() << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<queue>
#include<cstring>

#define visited(p) visited[p.first][p.second]
#define maze(p) maze[p.first][p.second]
#define dist(p) dist[p.first][p.second]

using namespace std;

int h, w;
char maze[21][21];
bool visited[21][21];
int dist[21][21];

bool validCell(pair<int, int> p){
	return (p.first >= 0 && p.first < h && p.second >= 0 && p.second < w);
}

int bfs(pair<int, int> start)
{
	int ret = 0;
	queue<pair<int, int>> q;
	visited(start) = true;
	q.push(start);
	int size;
	while(!q.empty())
	{
		size = q.size();
		while(size--)
		{
			pair<int, int> cur = q.front();
			q.pop();
			for(int j = 0 ; j < 2 ; j++){
				pair<int, int> cand = cur;
				for(int i = -1 ; i <= 1 ; i += 2)
				{
					if(j) 
						cand.second = cur.second + i;
					else 
						cand.first = cur.first + i;
					
					if(validCell(cand) && maze(cand) == '.' && !visited(cand))
					{
						visited(cand) = true;
						dist(cand) = dist(cur) + 1;
						ret = max(ret, dist(cand));
						q.push(cand);
					}
				}
			}
		}
	}
	return ret;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	
	cin >> h >> w;
	for(int i = 0 ; i < h ; i++)
		for(int j = 0 ; j < w ; j++)
			cin >> maze[i][j];
	int ans = 0;
	for(int i = 0 ; i < h ; i++){
		for(int j = 0 ; j < w ; j++){
			if(maze[i][j] == '.'){
				memset(visited, false, sizeof(visited));
				memset(dist, 0, sizeof(dist));
				ans = max(ans, bfs(make_pair(i, j)));
			}
		}
	}
	cout << ans << '\n';
	
	return 0;
}

Measured memory_bytes: 256
"use strict";

const input = require("fs").readFileSync("/dev/stdin", "utf8").trim();

const inputs = input.split("\n").map(i => +i);

const exec = (inputs) => {
  const k = inputs.pop();

  const yay = (inputs[inputs.length-1] - inputs[0]) <= k;

  console.log(yay ? "Yay!" : ":(");
}

exec(inputs);


Measured memory_bytes: 21064
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define all(v) v.begin(),v.end()
#define P pair<int,int>
#define len(s) (int)s.size()

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>inline int cmp(vector<T>&v,T &a){
	return lower_bound(all(v),a)-v.begin();
}
constexpr int mod = 1e9+7;
constexpr int inf = 3e18;

signed main(){
	int N;
	cin>>N;
	int ans=0;
	rep(i,N){
		int a;cin>>a;
		if(i%2==0&&a%2)ans++;
	}
	cout<<ans<<endl;
}


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

int main(void)
{
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  if (a + b > c + d)
  {
    cout << "Left" << endl;
  }
  else if (a + b < c + d)
  {
    cout << "Right" << endl;
  }
  else
  {
    cout << "Balanced" << endl;
  }
}

Measured memory_bytes: 256
n = int(input())
s = [0] * n
for i in range(n):
    s[i] = list(input())

char = list(set(s[0]))
for i in range(n):
    char = set(char) & set(s[i])

char = sorted(list(char))
cnt = [[0] * len(char) for _ in range(n)]
for i in range(n):
    for j in range(len(s[i])):
        for k in range(len(char)):
            if s[i][j] == char[k]:
                cnt[i][k] += 1

min_cnt = [50] * len(char)
for i in range(n):
    for j in range(len(char)):
        min_cnt[j] = min(min_cnt[j], cnt[i][j])

ans = ''
for i in range(len(char)):
    ans += char[i] * min_cnt[i]
print(ans)

Measured memory_bytes: 3064
#include <iostream>
using namespace std;
int main(void){
    int H,W;
    
    while(1){
    cin >> H;
    cin >> W;
    
     if(H==0 && W==0)break;
    
    for(int i=0;i<H;i++){
     for(int j=0;j<W;j++){
     
     cout << '#';
     }
     
     cout << endl;
    }
    cout << endl;
    

    }
    }

    


Measured memory_bytes: 3088
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define N 100000
#define pi M_PI

int main(){
  int n,q,k=0;
  int left,right,mid=0;
  int a[N],b[N];
  scanf("%d",&n);
  for(int i=0;i<n;i++){
      scanf("%d",&a[i]);
  }
  scanf("%d",&q);
  for(int j=0;j<q;j++){
      scanf("%d",&b[j]);
  }
  for(int j=0;j<q;j++){
      left=0;
  right=n;
      while(left<right){
          mid=(left+right)/2;
          if(a[mid]==b[j]){
              k++;
              break;
          }
            if(b[j]<a[mid]){
              right=mid;
          }else{
              left=mid+1;
          }
      }
  }
  printf("%d\n",k);
  return 0;
}



Measured memory_bytes: 2356
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		FastScanner in = new FastScanner(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		ProblemA solver = new ProblemA();
		solver.solve(1, in, out);
		out.close();
	}

	static class ProblemA {
		public void solve(int testNumber, FastScanner in, PrintWriter out) {
			int n = in.nextInt();
			int ans = Integer.MAX_VALUE;
			for (int a = 1; a < n; a++) {
				ans = Math.min(ans, f(a) + f(n - a));
			}
			out.println(ans);
		}

		private int f(int n) {
			int res = 0;
			while (n > 0) {
				res += n % 10;
				n /= 10;
			}
			return res;
		}

	}

	static class FastScanner {
		private BufferedReader in;
		private StringTokenizer st;

		public FastScanner(InputStream stream) {
			in = new BufferedReader(new InputStreamReader(stream));
		}

		public String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					String rl = in.readLine();
					if (rl == null) {
						return null;
					}
					st = new StringTokenizer(rl);
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return st.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}

	}
}



Measured memory_bytes: 21456
#include <iostream>
#include <vector>
using namespace std;
#define MAXQ 100000

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

  auto f = [](int n) {
    if (n == 1) return false;
    for (int i = 2; i * i <= n; i++) {
      if (n % i == 0) return false;
    }
    return true;
  };

  vector<int> cs(MAXQ+1);
  for (int n = 1; n < MAXQ; n += 2) {
    cs[n] = cs[n-1];
    if (f(n) && f((n + 1) / 2)) cs[n]++;
    cs[n+1] = cs[n];
  }

  int Q; cin >> Q;
  for (int i = 0; i < Q; i++) {
    int l, r; cin >> l >> r;
    cout << cs[r] - cs[l-1] << endl;
  }
}

Measured memory_bytes: 1024
#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#include<cmath>
#include<climits>
#include<ctime>
#include<cstring>
#include<numeric>
using namespace std;


int main()
{
	int x, y, z, m, E;
	while (cin >> E &&E > 0) {
		m = E;
		for (z = 0; z*z*z <= E; z++) {
			for (y = 0; y*y + z*z*z <= E; y++) {
				x = E - y*y - z*z*z;
				if (m > x + y + z)m = x + y + z;
			}
		}
		cout << m << endl;
	}
}

Measured memory_bytes: 3020
#include <bits/stdc++.h>
#define cout16 cout << setprecision(16) 
#define rep(i,n) for(int i=0;i<n;i++ )
#define rep2(i,f,n) for(int i=f;i<n;i++ )
#define SORT(A) sort(A.begin(),A.end())
#define REV(A) reverse(A.begin(),A.end())
typedef long long int ll;
using vi = std::vector<int>;
using vvi = std::vector<std::vector<int>>;
using vll = std::vector<ll>;
using vvll = std::vector<std::vector<ll>>;
using P = std::pair<int,int>;
using vp = std::vector<P>;
using namespace std;
#define INF 1001001001
#define LL_INF 1001001001001001001
#define fi first
#define se second

int main(void) {
	int n; cin >> n;
	vi c(n);
	ll ans = 0;
	rep(i,n){
		int a,b; cin >> a >> b;
		c[i] = a+b;
		ans -= b;
	}
	SORT(c);REV(c);
	rep(i,(n+1)/2){
		ans += c[i*2];
	}
	cout << ans << endl;
}


Measured memory_bytes: 640
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("Failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();

    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: String = read();

    if n.contains("7") {
        println!("Yes");
    } else {
        println!("No");
    }
}

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

int main() {
	string s;
	cin >> s;
	if (s == "zyxwvutsrqponmlkjihgfedcba") {
		cout << -1 << endl;
	} else {
		vector<bool> u(int(26));
		for (auto e : s) {
			u[e - 'a'] = true;
		}
		if (s.size() == 26) {
			for (bool b = true; b;) {
				for (int i = s.back() - 'a'; i < 26; i++) {
					if (!u[i]) {
						s.pop_back();
						s.push_back('a' + i);
						b = false;
						break;
					}
				}
				if (b) {
					u[s.back() - 'a'] = false;
					s.pop_back();
				}
			}
		} else {
			for (int i = 0; i < 26; i++) {
				if (!u[i]) {
					s.push_back('a' + i);
					break;
				}
			}
		}
		cout << s << endl;
	}
	return 0;
}


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

int main(void) {
    string b;
    char base[2][2] = {{'A','T'},{'C','G'}};
    cin >> b;

    for(int i=0;i<2;i++) {
        for (int j=0;j<2;j++) {
            if(b[0] == base[i][j]) {
                cout << base[i][(j+1)%2]  << endl;
                break;
            }
        }
    }
    return 0;
}


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

//#include <ext/pb_ds/assoc_container.hpp> // Common file
//#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update

#define rep(i,n) for(i=1;i<=n;i++)
#define Rep(i,n) for(i=0;i<n;i++)
#define For(i,a,b) for(i=a;i<=b;i++)

#define pb(x) push_back(x)
#define sz(x) (int)x.size()

#define mem(ara,val) memset(ara,val,sizeof(ara))
#define eps 1e-19

#define si(x) scanf("%d",&x)
#define sii(x,y) scanf("%d %d",&x,&y)
#define siii(x,y,z) scanf("%d %d %d",&x,&y,&z)
#define sl(x) scanf("%lld",&x)
#define sll(x,y) scanf("%lld %lld",&x,&y)
#define slll(x,y,z) scanf("%lld %lld %lld",&x,&y,&z)
#define ss(str) scanf("%s",str)
#define pi(x) printf("%d",x)
//#define pii(x,y) printf("%d %d",x,y)
#define piii(x,y,z) printf("%d %d %d",x,y,z)
#define pl(x) printf("%lld",x)
#define pll(x,y) printf("%lld %lld",x,y)
#define plll(x,y,z) printf("%lld %lld %lld",x,y,z)
#define NL printf("\n")
#define Max 200005
#define INF 1e9
#define un(x) x.erase(unique( x.begin() , x.end() ), x.end())
#define mod 1000000007

#define FI freopen("z.txt","r",stdin)

#define D(x) cout << #x << " = " << x << endl
#define DD(x,y) cout << #x << " = " << x << "   " << #y << " = " << y << endl
#define DDD(x,y,z) cout << #x << " = " << x << "   " << #y << " = " << y << "   " << #z << " = " << z << endl
#define all(x) x.begin(),x.end()
#define prntvctr(x) for(int i = 0; i < x.size(); i++) printf("%d%c", x[i], i + 1 == x.size() ? '\n' : ' ' );
#define pc(x) __builtin_popcount(x)

typedef long long LL;
typedef unsigned long long ULL;

const double PI = acos(-1.0);

using namespace std;

int setb(int n,int pos)
{
    return n=n | (1 << pos);
}
int resb(int n,int pos)
{
    return n=n & ~(1 << pos);
}
bool checkb(int n, int pos)
{
    return (bool)(n & (1 << pos));
}

inline LL bigmod(LL b, LL p, LL m)
{
    LL ret = 1, cur = b % m;
    while( p )
    {
        if(p & 1) ret = ( ret * cur ) % m;
        cur = ( cur * cur ) % m;
        p = p >> 1;
    }
    return ret;
}

LL n, m, ara[100005];

int main()
{
    //FI;
    LL i;
    sll(n, m);
    LL tot = 0;
    rep(i, n) sl( ara[i] ), tot += ara[i];
    if( m > tot )
    {
        printf("%lld\n", n - 1);
        exit(0);
    }
    sort(ara+1,ara+n+1);
    LL ret = 0;
    rep(i, n)
    {
        if( ara[i] <= m )
        {
            ret++;
            m -= ara[i];
        }
    }
    pl( ret ); NL;
    return 0;
}


Measured memory_bytes: 256
//选择排序
#include <iostream>

using namespace std;

int main(){
    int n;
    int a[100];

    cin>>n;
    for(int i=0; i<n;++i)
        cin>>a[i];

    int count=0;
    for(int i=0;i<n;++i)
    {
        int minIndex=i;
        for(int j=i;j<n;++j)
        {
            if(a[minIndex]>a[j])
            {
                minIndex=j;
            }
        }
        if(minIndex!=i)
        {
            int temp=a[i];
            a[i]=a[minIndex];
            a[minIndex]=temp;
            count++;
        }
    }

    for(int i=0;i<n;++i)
    {
        if(i)
            cout<<" ";
        cout<<a[i];
    }
    cout<<endl<<count<<endl;
    return 0;
}



Measured memory_bytes: 3096
#include<iostream>
#include<string>
using namespace std;
int main(){
	string s;
	getline(cin, s);
	int n = s.size();
	for (int i = 0; i < n; i++){
		if ((s[i] >= 'A' && s[i] <= 'Z') || (s[i] >= 'a'&&s[i] <= 'z'))
			cout << (char)(s[i] ^ 32);
		else
			cout << s[i];
	}
cout <<endl;
	return 0;
}

Measured memory_bytes: 3184
#include <bits/stdc++.h>
 
using namespace std;
#define sz(x) (int)(x).size()
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define ll long long
const int N=3e5+5,MOD=1e9+7;
 
int n,m;

ll dp[3005][3005];
string a,b;
int main()
{	
	cin>>a>>b;

	a='#'+a;
	b='#'+b;

	n=sz(a),m=sz(b);

	for(int i=1;i<n;i++){
		for(int j=1;j<m;j++){
			if(a[i]==b[j]){
				dp[i][j]=1+dp[i-1][j-1];
			}
			else dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
		}
	}

	int i = n-1 , j = m-1;
	string ans;
	while(i && j){

		if(a[i]==b[j]){
			ans.pb(a[i]);
			i--;
			j--;	
		}
		else{
			if(dp[i][j-1]>dp[i-1][j])j--;
			else i--;
		}
	}

	reverse(all(ans));
	

	cout<<ans<<"\n";
}
 

Measured memory_bytes: 70656