akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cout<<*i<<" "; cout<<endl; }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int N;
bool ok[301][101];
string input;
string words[101];
string words_row[101];
int s_cnt;
int s_map[301];
void print(){
  REP(i, s_cnt){
    cout<<words_row[s_map[i]];
    if(i == s_cnt - 1) cout<<"."<<endl;
    else cout<<" ";
  }
}
void dfs(int idx){
  assert(input.size() >= idx);
  if(input.size() == idx){
    print();
  }else{
    REP(i, N){
      if(ok[idx][i]){
        s_map[s_cnt++] = i;
        dfs(idx + words[i].size());
        s_cnt--;
      }
    }
  }
}
int main(){
  while(cin>>N && N){
    s_cnt = 0;
    memset(ok, 0, sizeof(ok));
    REP(i, N){
      cin>>words[i];
      words_row[i] = words[i];
      REP(j, words[i].size()){
        string check = "cfilosvz";
        REP(k, check.size()){
          if(check[k] >= words[i][j]){
            words[i][j] = '2' + k;
            break;
          }
        }
      }
    }
    cin>>input;
    REP(i, input.size()){
      REP(j, N){
        if(input.size() - i >= words[j].size() && input.substr(i, words[j].size()) == words[j]){
          ok[i][j] = true;
        }
      }
    }
    dfs(0);
    cout<<"--"<<endl;
  }
  return 0;
}

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

int main(void)
{
    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: 256
#include<bits/stdc++.h>
using namespace std;

int main()
{
    int i,n,cf=0,cs=0;
    char s[4];
    char a,b,c,d;
    cin>>s;
    for(i=0;i<4;i++)
    {
        if(s[0]==s[i])
        {
            cf++;
            a=s[i];

        }
        else
        {
            b=s[i];
        }

    }
     for(i=0;i<4;i++)
    {
       if(s[i]==b)
        {
            cs++;


        }
    }
    if(cs==2 && cf==2)
    {
        cout<<"Yes"<<endl;
    }
    else
        cout<<"No"<<endl;


    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
string a;
int x,y;
int main()
{
    cin>>a;
    for(int i=0;i<=a.size();i++)
    {
        if(a[i]=='C') x=1;
        if(a[i]=='F'&&x==1) y=1;
    }
    if(x==1&&y==1) cout<<"Yes";
    else cout<<"No";
    return 0;
}

Measured memory_bytes: 256
/**
  * http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_8_B&lang=jp
  * Character - Sum of Numbers
  */
object Main {
  def main(args: Array[String]): Unit = {
    Iterator.continually(io.StdIn.readLine()).takeWhile(_ != null).takeWhile(_ != "0")
      .map(_.map(_.toString.toInt).sum)
      .foreach(println)
  }
}

Measured memory_bytes: 44080
#include <bits/stdc++.h>
#define ri register
#define int long long
using namespace std; const int N=200010;
inline int read()
{
    int s=0, w=1; ri char ch=getchar();
    while(ch<'0'||ch>'9') { if(ch=='-') w=-1; ch=getchar(); }
    while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+(ch^48), ch=getchar();
    return s*w;
}
int A,B;
char mp[110][110];
signed main()
{
    A=read(), B=read();
    puts("100 100");
    for(ri int i=1;i<=50;i++)for(ri int j=1;j<=100;j++)mp[i][j]='.';
    for(ri int i=51;i<=100;i++)for(ri int j=1;j<=100;j++)mp[i][j]='#';
    for(ri int i=1;i<=50;i++, i++)
    for(ri int j=1;j<=100&&B>1;j++, j++)
    mp[i][j]='#', B--;
    for(ri int i=100;i>50;i--, i--)
    for(ri int j=100;j&&A>1; j--, j--)
    mp[i][j]='.', A--;
    for(ri int i=1;i<=100;i++,puts(""))
    for(ri int j=1;j<=100;j++) printf("%c",mp[i][j]);
    return 0;
}

Measured memory_bytes: 3684
#include<bits/stdc++.h>
using namespace std;
int main(){
	long long a,b,x,n=0;
	scanf("%lld%lld%lld",&a,&b,&x);
	if(a>0){
		a-=1;
		n=(b/x)-(a/x);
	}else{
	n=(b/x);
	n++;
}
	printf("%lld",n);
}

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

#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define size_t unsigned long long
#define ll long long
#define rep(i,a) for(int i=0;i<(a);i++)
#define repr(i,a) for(int i=(int)(a)-1;i>=0;i--)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b) for(int i=(int)(b)-1;i>=a;i--)
#define ALL(a) a.begin(), a.end()
using namespace std;
int si() { int x; scanf("%d", &x); return x; }
long long sl() { long long x; scanf("%lld", &x); return x; }
string ss() { string x; cin >> x; return x; }
void pi(int x) { printf("%d ", x); }
void pl(long long x) { printf("%lld ", x); }
void pd(double x) { printf("%.15f ", x); }
void ps(const string &s) { printf("%s ", s.c_str()); }
void br() { putchar('\n'); }

const ll MOD = 1e9 + 7;
const ll INF = 1e9 + 5;

struct mint {
    int n;
    mint(int n_ = 0) : n(n_) {}
};

mint operator+(mint a, mint b) { a.n += b.n; if (a.n >= MOD) a.n -= MOD; return a; }
mint operator-(mint a, mint b) { a.n -= b.n; if (a.n < 0) a.n += MOD; return a; }
mint operator*(mint a, mint b) { return (long long)a.n * b.n % MOD; }
mint &operator+=(mint &a, mint b) { return a = a + b; }
mint &operator-=(mint &a, mint b) { return a = a - b; }
mint &operator*=(mint &a, mint b) { return a = a * b; }

typedef pair<int, int> P;

const ll N = 1e5+5;
string s;
vector<ll> v[N];
ll n,m;
ll a[N];
ll dp[N];

ll mod(ll a, ll m) {
    return (a % m + m) % m;
}

// a*b/m
ll mul(ll a, ll b, ll m) {
    a = mod(a, m); b = mod(b, m);
    if (b == 0) return 0;
    ll res = mul(mod(a + a, m), b>>1, m);
    if (b & 1) res = mod(res + a, m);
    return res;
}


int main () {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> n >> m;
  rep(i,m) {
    cin >> a[i];
    dp[a[i]] = -1;
  }
  rep(i,m-1) {
    if(a[i+1] - a[i] == 1) {
      cout << 0 << endl;
      return 0;
    }
  }
  dp[0] = 1;
  dp[1] = dp[1] == -1 ? -1 : 1;
  for(int i = 2; i<=n; i++) {
    if(dp[i] == -1) continue;
    else if(dp[i-2] == -1) {
      dp[i] = dp[i-1];
    } else if(dp[i-1] == -1) {
      dp[i] = dp[i-2];
    } else {
      dp[i] = (dp[i-2] + dp[i-1]) % MOD;
    }
  }
  // rep(i,n+1) cout << dp[i] << endl;
  cout << dp[n] << endl;
}


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

int main(){
    string s;
    cin >> s;
    if (s.at(0)==s.at(1) && s.at(1)==s.at(2)){
        cout << "No" << endl;
    }

    else {
        cout << "Yes" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import sys

def warshall(n, matrix):
  for i in xrange(n):
    matrix[i][i] = 0
  for i in xrange(n):
    for j in xrange(n):
      for k in xrange(n):
        matrix[j][k] = min(matrix[j][k], matrix[j][i]+matrix[i][k])
  return matrix

while True:
  n,m,s,g1,g2 = map(int, raw_input().split())
  if n==m==s==g1==g2==0:
    break
  matrix = [[10**10] * n for i in xrange(n)]
  for i in xrange(m):
    b1,b2,c = map(int, raw_input().split())
    matrix[b1-1][b2-1] = c
  costs = warshall(n, matrix)
  mincost = 10**10
  for i in xrange(n):
    mincost = min(mincost, costs[s-1][i]+costs[i][g1-1]+costs[i][g2-1])
  print mincost

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

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define LL long long
#define INF INT_MAX/3

const double EPS = 1e-14;
const double PI  = acos(-1.0);


int main(){
  int n;
  int p;

  scanf("%d %d",&n, &p);

  int a;
  int odd = 0;
  int even = 0;
  REP (i, n) {
    scanf("%d", &a);
    if (a % 2) odd++;
    else even++;
  }

  LL ans;
  if (p % 2 == 0 && odd == 0) {
    ans = pow(2, n);
  } else if (p % 2 == 1 && odd == 0) {
    ans = 0;
  } else {
    ans = pow(2, n - 1);
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
// Problem Code: abc174_c

#include <iostream>

using namespace std;

int repsept(int K) {
	int num = 0;
	for (int i = 1; i <= K; i++) {
		num = (10 * num + 7) % K;
		if (num == 0)
			return i;
	}
	return -1;
}

int main() {
	int K;
	cin >> K;
	cout << repsept(K);
	return 0;
}

Measured memory_bytes: 3584
#include <iostream>
using namespace std;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	string n;
	cin >> n;
	REP(i,n.size()){
		if(n[i] == '9'){
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>

int main(void){
    double A,B;
    scanf("%lf %lf",&A,&B);
    double AMin=A/8*100,AMax=(A+1)/8*100;
    double BMin=B*10,BMax=(B+1)*10;
    if(AMin>BMax-1 || ceil(AMax-1)<BMin) printf("-1\n");
    else if(BMin<=ceil(AMin-1)) printf("%d\n",(int)ceil(AMin));
        else printf("%d\n",(int)BMin);
    return 0;
}

Measured memory_bytes: 128
#include <stdio.h>

int main(int argc,char *argv[]){
 	int N,i,j=0;
  	int a[50];
  scanf("%d",&N);
  if(N<2||N>50){ return -1;}
  i=N;
  while(i>0){
    scanf("%d",&a[j]);
    j++;
    i--;
  }
  j=0;
  int k=0;
  int max=0;
  for(k=0;k<N;k++){
    for(j=k+1;j<N;j++){
    	max += a[k]*a[j];
    }
  }
  
  printf("%d",max);
  
  return 0;
}

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

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

string S[10] = {"pon", "pon", "hon", "bon", "hon", "hon", "pon", "hon", "pon", "hon"};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string N;
    cin >> N;
    ll s = N[N.length() - 1] - '0';
    cout << S[s] << endl;

    return 0;
}

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

using namespace std;

int main() {
    int n;  cin >> n;
    vector<int> v;
    for (int i = 0; i < n; i++) {
        int a;  cin >> a;
        v.push_back(a);
    }

    sort(v.begin(), v.end(), greater<int>());

    int ret = 0;
    for (int i = 0; i < n; i++) {
        if (i % 2 == 0) ret += v[i];
        else            ret -= v[i];
    }

    cout << ret << endl;

    return 0;
}

Measured memory_bytes: 256
loop do
	h, w = gets.split.map(&:to_i)
	if h == 0 && w == 0 then
		break
	end
	
	h.times do |i|
		w.times do |j|
			if (i + j) % 2 == 0 then
				print("#")
			else
				print(".")
			end
		end
		puts
	end
	puts
end



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

public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int A = sc.nextInt();
        int B = sc.nextInt();
        
        System.out.println( ( N * A < B ) ? N * A : B );
    }
}


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

int main(){
    int n;
    cin >> n;
    ll a[n];
    ll sum = 0, p = 0;
    ll ans = 1000000000000000000;
    for(int i = 0; i < n; i++){
        cin >> a[i];
        sum += a[i];
    }
    for(int i = 0; i < n-1; i++){
        p += a[i];
        ans = min(ans,abs(sum-2*p));
    }
    cout << ans << endl;

    return 0;
}

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

int main()
{
    int n;
    cin >> n;
    int f[n][10];
    long long p[n][11];
    long long rieki = -10000000000;
    for (auto i = 0; i < n; i++)
    {
        for (auto j = 0; j < 10; j++)
        {
            cin >> f[i][j];
        }
    }
    for (auto i = 0; i < n; i++)
    {
        for (auto j = 0; j < 11; j++)
        {
            cin >> p[i][j];
        }
    }

    for (auto i = 1; i < 1 << 10; i++)
    {
        long long tmp_rieki = 0;
        for (auto j = 0; j < n; j++)
        {
            int num = 0;
            for (auto k = 0; k < 10; k++)
            {
                if ((1 & i >> k) == 1 && f[j][9 - k] == 1)
                {
                    num++;
                }
            }
            tmp_rieki += p[j][num];
        }

        if (tmp_rieki > rieki)
        {
            rieki = tmp_rieki;
        }
    }

    cout << rieki << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>

int main()
{
	long long N, M;
	std::cin >> N >> M;

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

	// 累積和を計算する
	std::vector<long long> B( N + 1 );
	B[0] = 0;
	for ( long i = 1; i <= N; i++ )
	{
		B[i] = A[i - 1] + B[i - 1];
	}

	// 各Bi(i>0)をMで割った余りが0 to M-1である個数をカウントする
	// --> 余りが等しければ、Br - Bl は Mの倍数になる
	//  exp) Mx + 1 と My + 1はそれぞれMで割ると余りが1になるため、
	//      (Mx + 1) - (My + 1) = M(x - y) と変形でき、これはMの倍数である
	long long ans = 0;
	std::map<long long, long long> counter;
	for ( long i = 0; i <= N; i++ )
	{
		ans += counter[B[i] % M];
		counter[B[i] % M]++;	//	カウントアップ（次に余りが一致するBiが見つかれば、組み合わせはその分増える）
	}

	std::cout << ans << std::endl;

	return ( 0 );
}


Measured memory_bytes: 5760
s = input()
t = input()

pos = 0
itr = 0

S = set(s)
T = set(t)

if S>=T:
    for i in t:
        pos = s.find(i,pos) 
        if pos < 0:
            itr += 1
            pos = s.find(i) + 1
        else:
            pos += 1
    print(itr*len(s)+pos)

else:
    print(-1)

Measured memory_bytes: 3444
function Main(s) {
  var s = s.split("\n");
  var hw = s[0].split(" ").map(e => e*1);
  var head = ["_".repeat(hw[1] + 2)];
  var tail = ["_".repeat(hw[1] + 2)];
  for (var i = 1; i <= hw[0]; i++) {
    s[i] = "_" + s[i] + "_";
  }
  var x = head.concat(s.slice(1, hw[0] + 1));
  var y = x.concat(tail);
  var ans = new Array(hw[0]).fill("");
  var cnt;
  for (var i = 1; i < hw[0] + 1; i++) {
    for (var j = 1; j < hw[1] + 1; j++) {
      cnt = 0;
      if (y[i][j] === ".") {
        if (y[i - 1][j - 1] === "#") cnt++;
        if (y[i][j - 1] === "#") cnt++;
        if (y[i + 1][j - 1] === "#") cnt++;
        if (y[i - 1][j] === "#") cnt++;
        if (y[i + 1][j] === "#") cnt++;
        if (y[i - 1][j + 1] === "#") cnt++;
        if (y[i][j + 1] === "#") cnt++;
        if (y[i + 1][j + 1] === "#") cnt++;
        ans[i - 1] += String(cnt);
      } else {
        ans[i - 1] += "#";
      }
    }
  }
  for (var i of ans) console.log(i);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

#define         pb         push_back
#define         sf(x)      scanf("%d",&x)
#define         sfl(x)     scanf("%lld",&x)
#define         pf(x)      printf("%d\n",x)
#define         pfl(x)     printf("%lld\n",x)
#define         endl       '\n'
#define         pii        pair<int,int>
#define         mapii      map<int,int>
#define         mapll      map<ll,ll>
#define         mapci      map<char,int>
#define         mapcl      map<char,ll>
#define         mapsi      map<string,int>
#define         mapsl      map<string,ll>
#define         pll        pair<ll,ll>
#define         vi         vector<int>
#define         vl         vector<ll>
#define         vd         vector<double,double>
#define         all(c)     c.begin(),c.end()
#define         F          first
#define         S          second
#define         mp         make_pair
#define        ftc(x)      cerr << #x << ": " << x << " " << endl;
#define         PI         acos(-1)
#define         lcm(a,b)   ((a*b)/__gcd(a,b))
//   cout<<std::setprecision(12)<<

int main()
{
    int i,j,k,l,m,n,mx,mn;
    cin >> k >> n;
   int ar[n+10];
    for(i=0;i<n;i++)
    {
        cin >> ar[i];
    }
    mn = 1e6;
    for(i=0;i<n;i++)
    {
        if(i == (n-1))
        {

            m = k-ar[i];
            m += ar[0];
          //  cout<<m<<endl;
            mn = min(mn,k-m);
        }
        else{
          m = ar[i+1]-ar[i];
            mn = min(mn,k-m);
        }
    }
    cout<<mn<<endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
long long dp[41][401][401] = {};
class mix{
public:
    int a;
    int b;
    int p;
};
bool cmp(mix a,mix b)
{
    return (a.p < b.p);
}
int min_cost(int n,mix c[],int i,int a,int b,int r1,int r2)
{
    if(i == n)
        return INT_MAX;
    int gcd = __gcd(r1,r2);
    if(gcd != 0 && (r1/gcd) == a && (r2/gcd) == b)
        return 0;
    if(dp[i][r1][r2])
        return dp[i][r1][r2];
    long long c1 = (long long)c[i].p + (long long)min_cost(n,c,i + 1,a,b,r1 + c[i].a,r2 + c[i].b);
    long long c2 = (long long)min_cost(n,c,i + 1,a,b,r1,r2);
    dp[i][r1][r2] = min(c1,c2);
    return min(c1,c2);
}
int main()
{
    int n,a,b,i;
    cin>>n>>a>>b;
    mix c[n];
    for(i = 0; i < n; i++)
    {
        int f,s,t;
        cin>>f>>s>>t;
        c[i].a = f;
        c[i].b = s;
        c[i].p = t;  
    }
    sort(c,c + n,cmp);
    if(min_cost(n,c,0,a,b,0,0) != INT_MAX)
        cout<<min_cost(n,c,0,a,b,0,0)<<endl;
    else
        cout<<"-1"<<endl;
    return 0;
}

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

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

    for (int i = 1; i <= n; i++) {
        int x = i;
        if (i % 3 == 0) {
            cout << " " << i;
            continue;
        }
        while (x) {
            if (x % 10 == 3) {
                cout << " " << i; 
                break;
            }
            x /= 10;
        }
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 3020
use std::io::stdin;

fn main() {
    let mut s = String::new();
    stdin().read_line(&mut s).ok();
    let n: i64 = s.trim().parse().unwrap();

    println!(
        "{}",
        (1..=n)
            .filter(|&e| !(e % 5 == 0 || e % 3 == 0))
            .sum::<i64>()
    );
}


Measured memory_bytes: 2104
import "dart:io";

main(){
  List nab = stdin.readLineSync().split(" ").map((x) => int.parse(x)).toList();

  int n = nab[0];
  int a = nab[1];
  int b = nab[2];

  int ans = 0;
  for (int i = 1; i <= n; i++){
    int sum = 0;
    int tmp = i;
    while (tmp > 0){
      sum += tmp % 10;
      tmp ~/= 10;
    }
    if (a <= sum && sum <= b) ans += i;
  }
  print(ans);
}


Measured memory_bytes: 13140
#include<stdio.h>
int main(void) {
	char S[100000];
	int N;
	int k = 1;
	scanf("%d", &N);
	scanf("%s", S);
	for (int i = 0; i < N-1; i++) {
		if (S[i] != S[i + 1]) {
			k++;
		}
	}
	printf("%d\n", k);
}

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

const long long INF = 1LL << 60;

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

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

long long h[1000000];
long long dp[1000000];

int main() {
	int n;
	cin >> n;
	int k;
	cin >> k;
	for (int i = 0;i < n;i++)cin >> h[i];
	for (int i = 0;i < n;i++) dp[i] = INF;

	dp[0] = 0;

	for (int i = 0;i < n;i++) {
		for (int j = 1;j <= k;j++) {
			chmin(dp[i + j], dp[i] + abs(h[i + j] - h[i]));
		}
	}
	cout << dp[n - 1] << endl;
}



Measured memory_bytes: 5248
#include <bits/stdc++.h>
#include <cstdlib>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
using ll = long long;
const int MOD = 1000000007;

long long mod(long long val, long long m) {
  long long res = val % m;
  if (res < 0) res += m;
  return res;
}

bool is_prime(long long N) {
    if (N == 1) return false;
    for (long long i = 2; i * i <= N; ++i) {
        if (N % i == 0) return false;
    }
    return true;
}

vector<pair<long long, long long> > prime_factorize(long long N) {
    vector<pair<long long, long long> > res;
    for (long long a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        long long ex = 0;
        while (N % a == 0) {
            ++ex;
            N /= a;
        }
        res.push_back({a, ex});
    }
    if (N != 1) res.push_back({N, 1});
    return res;
}

int main() {
  int K,T,max=0,ans=0,sum=0;
  cin >> K >> T;
  vector<int> a(T);
  rep(i,T) {
    cin >> a[i];
    sum+=a[i];
    if(a[i]>max) max=a[i];
  }
  sum-=max;
  //sort(T.begin(),T.end(),greater<int>());
  if(sum>max-2) ans=0;
  else ans=max-sum-1;
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 3528
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>
#include <tuple>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e12;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1
#define MAX_N 100100 * 3

string s;

int main() {
	cin >> s;
	if (s.size() >= 4 && s.substr(0, 4) == "YAKI")cout << "Yes" << endl;
	else cout << "No" << endl;
}

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

int main(){
	int answer = 0;
	string S;
	cin >> S;
	for(int i = 0; i < S.size() / 2; i++){
		string left = S.substr(i, 1);
		string right = S.substr(S.size() - i - 1, 1);
		if(left != right) answer++;
	}
	cout << answer << endl;
	return 0;
}

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



int main(){
	int h,w;
	cin>>h>>w;
	int c[15][15];
	for(int i=0;i<10;++i){
		for(int j=0;j<10;++j){
		cin>>c[i][j];
		}
	}
	int a[h+5][w+5];
	for(int i=0;i<h;++i){
		for(int j=0;j<w;++j){
			cin>>a[i][j];
		}
	}
	/*cout<<endl;
	for(int i=0;i<10;++i){
		for(int j=0;j<10;++j){
			cout<<c[i][j]<<" ";
			if(j==9)cout<<endl;
		}
	}
	cout<<"-------------------"<<endl;:*/
	long long int dp[15][15];//long long int d[15][15];

	/*cout<<"-------------------"<<endl;


	for(int i=0;i<10;++i){
		for(int j=0;j<10;++j){
			cout<<dp[i][j]<<" ";
			d[i][j]=dp[i][j];
			if(j==9)cout<<endl;
		}
	}
	cout<<"-------------------"<<endl;*/
	for(int k=0;k<10;++k){
  	for(int i=0;i<10;++i){
    	for(int j=0;j<10;++j){
    		/*if((i==2&&j==1)||(i==1&&j==2)){
    			cout<<"dp"<<i<<k<<"="<<dp[i][k]<<" + "<<"dp"<<k<<j<<"="<<dp[k][j]<<" = "<<dp[i][k]+dp[k][j]<<endl;
    		}	*/
      	if(c[i][j]>c[i][k]+c[k][j])c[i][j]=c[i][k]+c[k][j];
    	}
  	}
	}
	/*cout<<"-------------------"<<endl;
	for(int i=0;i<10;++i){
		for(int j=0;j<10;++j){
			cout<<dp[i][j]<<" ";

			if(j==9)cout<<endl;
		}
	}
	
	cout<<"-------------------"<<endl;
	for(int i=0;i<10;++i){
		for(int j=0;j<10;++j){
			cout<<d[i][j]-dp[i][j]<<" ";
			if(j==9)cout<<endl;
		}
	}
	cout<<"-------------------"<<endl;*/
	int ans=0;
	for(int i=0;i<h;++i){
		for(int j=0;j<w;++j){
			if(a[i][j]==-1)continue;
			/*cout<<"a"<<"["<<i<<"]"<<"["<<j<<"]"<<":"<<a[i][j]<<endl;*/
			/*cout<<"c["<<a[i][j]<<"]"<<"[1]"<<":"<<c[a[i][j]][1]<<endl;*/
			ans+=c[a[i][j]][1];
			/*cout<<"ans"<<":"<<ans<<endl;*/
		}
	}
	/*cout<<"-------------------"<<endl;*/
	cout<<ans<<endl;
}

Measured memory_bytes: 892
/**
 ____ ____ ____ ____ ____
||a |||t |||o |||d |||o ||
||__|||__|||__|||__|||__||
|/__\|/__\|/__\|/__\|/__\|

**/

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int n;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    int cnt[2];
    cnt[0] = cnt[1] = 0;
    for(int i = 1; i <= n; i++)
    {
        int a;
        cin >> a;
        cnt[(a & 1)]++;
    }
    if(cnt[1] & 1)
        cout << "NO\n";
    else
        cout << "YES\n";
    return 0;
}


Measured memory_bytes: 3652
import static java.lang.System.*;

import java.io.*;

class Main {

    public static void main(String[] args) {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        
        try {
            while (true) {
                String[] line = reader.readLine().split(" ");
                int a = Integer.parseInt(line[0]);
                String op = line[1];
                int b = Integer.parseInt(line[2]);
                
                if (op.equals("?")) {
                    break;
                }

                switch (op) {
                case "+":
                    out.println(a + b);
                    break;

                case "-":
                    out.println(a - b);
                    break;

                case "*":
                    out.println(a * b);
                    break;

                case "/":
                    out.println(a / b);
                    break;

                default:
                    break;
                }
            } 
        } catch (NumberFormatException e) {
            out.println(e);
        } catch (IOException e) {
            out.println(e);
        }

    }

}

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

using namespace std;

#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
#define Eunique(v) v.erace(unique(all(v)),v.end())
#define pvec(v)　rep(i,v.size()){cout << v[i] << " ";}
#define INF 0x3f3f3f3f
#define mset(m,v) memset(m,v,sezeof(m))
#define mod (ll)(1e9 +7);

const double pi = acos(-1.0);

typedef vector<int> vi;
typedef string ss;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef deque<ll> dll;
typedef pair<ll,ll> P;
ll dx[4] = {1,0,-1,0},dy[4] = {0,1,0,-1};

ll gcd(ll x,ll y)
{
    ll r;
    while((r = x % y) != 0)
    {
        x = y;
        y = r;
    }
    return y;
}

ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b; // Be careful not to overflow
}

ll digsum(ll n){
    ll sum = 0;
    while(n > 0){
        sum += n % 10;
        n /= 10;
    }

    return sum;
}

int main()
{
    ll n;
    cin >> n;
    vll h(n);
    rep(i,n)cin >> h[i];
    
    repr(i,n-1){
        ll tmp = 0;
        if(h[i] > h[i+1])tmp = h[i] - h[i+1];
        if(tmp > 1){
            puts("No");
            return 0;
        }

        else if(tmp > 0)h[i]--;
    }

    puts("Yes");

    /*rep(i,n)cout << h[i] << " ";
    cout << endl;
    */
    
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define mins(a,b) a=min(a,b)
#define maxs(a,b) a=max(a,b)
template < typename T > std::string to_string( const T& n )
  {
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
  }
using namespace std;

const long long INF=9000000000000000;
int main(){
int n,k,a;
string s,x,y;
cin>>n;
k=n/100;
a=n%100;
if(0<k and k<13 and 0<a and 13>a){
cout<<"AMBIGUOUS"<<endl;
}
if(0<k and k<13 and 0>=a ){
cout<<"MMYY"<<endl;
}
if(0<k and k<13 and 13<=a){
cout<<"MMYY"<<endl;
}
if(0>=k and 0<a and 13>a)
cout<<"YYMM"<<endl;
if(k>=13 and 0<a and 13>a)
cout<<"YYMM"<<endl;
if(k>=13 and  13<=a)
cout<<"NA"<<endl;
if(k>=13 and 0>=a)
cout<<"NA"<<endl;
if(0>=k and  13<=a)
cout<<"NA"<<endl;
if(0>=k and 0>=a )
cout<<"NA"<<endl;
}


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

ll modpow(ll a, ll b, ll p = 1e9+7){
    if(b == 0)  return 1;
    if(b % 2 == 0){
        ll d = modpow(a, b/2, p);
        return (d*d) % p;
    }else{
        return (a%p * modpow(a, b-1, p)) % p;
    }
}

struct ModComb{
    vector<ll> po, inv;
    ll N;

    ModComb(ll n) : N(n), po(n), inv(n) {
        po[0] = 1;
        for(int i = 1; i < N; i++)  po[i] = (po[i-1] * i) % mod;
        inv[N-1] = modpow(po[N-1], mod-2, mod);
        for(int i = N-2; i >= 0; i--)   inv[i] = (inv[i+1] * (i+1)) % mod;
    }
    
    ll nCk(ll n, ll k){
        if(n < k)   return 0;
        return (((po[n]*inv[n-k])%mod)*inv[k])%mod;
    }

    ll nPk(ll n, ll k){
        if(n < k)   return 0;
        return (po[n]*inv[n-k])%mod;
    }

    ll nHk(ll n, ll k){
        if(n == 0 && k == 0)    return 1;
        return nCk(n+k-1, k);
    }
};

int main(){
    ModComb mc(100005);
    int n;
    cin >> n;
    vector<int> a(n+1), cnt(n+1, 0);
    int p;
    for(int i = 0; i <= n; i++){
        cin >> a[i];
        cnt[a[i]]++;
        if(cnt[a[i]] == 2)  p = a[i];
    }
    int l = n+1, r = -1;
    for(int i = 0; i <= n; i++){
        if(a[i] == p)   l = min(l, i), r = max(r, i);
    }
    for(int k = 1; k <= n+1; k++){
        cout << (mc.nCk(n+1, k)-mc.nCk(n+1-(r-l+1), k-1)+mod)%mod << endl;
        // ll ans = 0;
        // if(n+1-2 >= k)  ans += mc.nCk(n-1, k);
        // ans %= mod;
        // ans += 2*mc.nCk(n-1, k-1);
        // if(n+1-(r-l+1) >= k-1)  ans -= mc.nCk(n+1-(r-l+1), k-1);
        // if(ans < 0) ans += (-ans/mod+1)*mod;
        // ans %= mod;
        // if(k >= 2)  ans += mc.nCk(n+1-2, k-2);
        // ans %= mod;
        // cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 3584
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Math;

class Program{
    static int n;
    static string s;

    static void Main(){
        n = int.Parse(Console.ReadLine());
        s = Console.ReadLine();

        int[] countb = new int[n + 1];
        for (int i = 1;i <= n;i++){
            countb[i] = countb[i - 1];
            if (s[i - 1] == '#') countb[i]++;
        }

        int ans = int.MaxValue;
        for (int i = 1;i <= n;i++){
            int temp = countb[i - 1];
            temp += (n - i + 1) - (countb[n] - countb[i - 1]);
            ans = Min(ans,temp);
        }

        ans = Min(ans,countb[n]);
        
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 14012
#include<bits/stdc++.h>
using namespace std;
#define N 250
#define ll long long
#define int ll
#define pb push_back
#define pi pair<ll , ll>
#define mp make_pair
#define mod 1000000007
int32_t main(){
int n;
cin>>n;
int arr[n];
for(int i = 0 ; i < n ;i++){
    cin>>arr[i];
}
int prev[n+1] = {0};
int dp[n+1] ;
for(int i = 0 ; i <= n ; i++){
    dp[i] = -1;
}
int freq[n+1] = {0};
int zero = 3;
int ans = 1;
for(int i = 0 ; i < n ;i++){
       freq[arr[i]]++;
      if(arr[i] == 0){
          if(zero == 0){
              cout<<0<<endl;
              return 0;
          }
            ans = ((ans%mod)*(zero%mod) + mod)%mod;
            zero--;
      }
      else{
              int between = freq[arr[i]-1]-prev[arr[i]-1];
              if(dp[arr[i]] == -1){
                    if(between == 0){
                        cout<<"0"<<endl;
                        return 0;
                    }
                   ans = ((ans%mod)*(between%mod) + mod)%mod;
                  dp[arr[i]] = freq[arr[i]-1]-1;
              }
              else{
                   if(between + dp[arr[i]] <= 0){
                       cout<<"0"<<endl;
                       return 0;
                   }
                 ans = ((ans%mod)*((between + dp[arr[i]])%mod) +mod)%mod;
                 dp[arr[i]] = dp[arr[i]] + between-1;
              }
             prev[arr[i]-1] = freq[arr[i]-1];
      }
}
cout<<(ans+mod)%mod<<endl;
    
}


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

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

    ll n,w;
    cin >> n >> w;
    ll weight[n], value[n];
    rep(i,n) cin >> weight[i] >> value[i];
    
    ll dp[n+1][w+1];
    rep(i,n+1){
        rep(j,w+1){
            dp[i][j] = 0;
        }
    }
    
    rep(i,n){
        for(int sum_w=0; sum_w<w+1; sum_w++){
            if(sum_w >= weight[i]){
                dp[i+1][sum_w] = max(dp[i+1][sum_w], dp[i][sum_w - weight[i]] + value[i]);
            }
            
            dp[i+1][sum_w] = max(dp[i+1][sum_w], dp[i][sum_w]);
        }
    }
    
    cout << dp[n][w] << endl;

    return 0;
}

Measured memory_bytes: 79232
#include <stdio.h>

int main(void){
    char data1[3],data2[3],data3[3];
    scanf("%s",data1);
    scanf("%s",data2);
    scanf("%s",data3);
    printf("%c%c%c\n",data1[0],data2[1],data3[2]);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <iomanip>
#include <math.h>
//#include <unistd.h>
//#include <stdio.h>
#define rep(i,x) for(ll i = 0;i<x;i++)
#define all(a) (a).begin(),(a).end()
using ll = long long;
using ld = long double;
using namespace std;
using dou = double;
const ll INF = 1LL << 60;
const ll mod = 1000000007;
typedef pair<ll,ll> P;
using graph = vector<vector<ll>>;
template<class T> inline bool chmax(T& a, T b){if(a < b){a = b; return true;}return false;}
template<class T> inline bool chmin(T& a, T b){if(a > b){a = b; return true;}return false;}
ll gcd(ll a,ll b){
    if(a < b)swap(a,b);
    if(a % b == 0)return b;
    else return gcd(b,a%b);
}
//素数判定O(sqrt(N))
bool isp(ll n){
    bool res = true;
    if(n == 1)return false;
    else{
        for(ll i = 2;i * i <= n;i++){
            if(n % i == 0){
                res = false;
                break;
            }
        }
        return res;
    }
}

ll fac[510000], finv[510000], inv[510000];

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

// 二項係数計算
ll COM(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
//nのm乗をMODで割ったあまりO(logN)
ll modpow(ll n,ll m,ll MOD){
    ll res = 1;
    while(m){
        if(m & 1)res = (res * n) % MOD;
        m >>= 1;
        n *= n;
        n %= MOD;
    }
    return res;
}

//printf("%.10f\n", N);
/*  vector<ll> vec = {1,2,5,6,8,9,10};
    cout << binary_search(all(vec),5) << endl; -> true*/
/*
    vector<ll> vec = {1,2,5,6,8,9,10};
    auto n = upper_bound(all(vec),4);
    cout << *n << endl; -> 5*/
/*
    cout << fixed << setprecision(15);
*/
int main(){
    ll N;
    cin >> N;
    vector<ll> num(N);
    rep(i,N)cin >> num[i];
    vector<bool> visit(N);
    ll cnt = 0;
    ll now = 0;
    rep(i,N + 1){
        //cout << now << "\n";
        now = num[now] - 1;
        cnt++;
        if(visit[now]){
            cout << -1 << endl;
            return 0;
        }
        if(now == 1){
            cout << cnt << endl;
            return 0;
        }
        visit[now] = true;
    }
}
/*3
3
1
2*/

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

static const int MAX = 200000;

int main() {
  ll a,b,k;
  cin >> a >> b >> k;
  if (a >= k) {
    a -= k;
  } else {
    k -= a;
    a = 0;
    if (b >= k) {
      b -= k;
    } else {
      k -= b;
      b = 0;
    }
  }
  cout << a << " " << b << endl;
}


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

void solve(long long H, long long W, long long h, long long w){
	cout << H*W-h*W-H*w+h*w << "\n";
}

int main(){
	long long W;
	long long H;
	long long h;
	long long w;
	scanf("%lld",&H);
	scanf("%lld",&W);
	scanf("%lld",&h);
	scanf("%lld",&w);
	solve(H, W, h, w);
	return 0;
}


Measured memory_bytes: 764
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<vector>
using namespace std;
typedef long long LL;
LL n,p; 
int main()
{
	scanf("%lld%lld",&n,&p);
	LL ans=1;
	for (LL u=2;u*u<=p;u++)
	if (p%u==0)
	{
		//printf("%lld\n",u);
		LL cnt=0;
		while (p%u==0) 
		{
			p/=u;cnt++;
			if (cnt>=n) ans*=u,cnt=0;
		}
	}
	if (p!=1&&n==1) ans*=p;
	printf("%lld\n",ans);
	return 0;
}


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

/*alias*/
#define REP(i,n) for (int i = 0; i < (n); i++)
#define ALL(obj) (obj).begin(), (obj).end()
using ll=long long;

using namespace std;

/*input*/
int n,k;

/*funcs*/


/*main*/
int main(){
    cin>>n>>k;
    cout<<n-k+1;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import java.math.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int d = sc.nextInt();
        ArrayList<ArrayList<Double>> li = new ArrayList<ArrayList<Double>>();
        for(int i = 0; i < n; i++){
            ArrayList<Double> tmp = new ArrayList<Double>();
            for(int j = 0; j < d; j++){
                double x = sc.nextDouble();
                tmp.add(x);
            }
            li.add(tmp);
        }
        int ans = 0;
        for(int i = 0; i < n; i++){
            for(int j = i+1; j < n; j++){
                double tmp = 0;
                for(int k = 0; k < d; k++){
                    tmp += Math.pow(li.get(i).get(k)-li.get(j).get(k),2);
                }
                if(Math.pow(tmp,0.5) % 1 == 0){
                    ans++;
                }
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 25044
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
    ll t,a,b,i,j,k,n,x;
    cin>>n>>x;
    vector<ll>v;
    for(i=0;i<n;i++)
    {
        cin>>k;
        v.push_back(k);
    }
    ll c=0;
    for(i=0;i<n-1;i++)
    {
        ll p=v[i]+v[i+1];
        if(p>x)
        {
            ll q=p-x;
            if(v[i+1]>=q)
            {
                v[i+1]=v[i+1]-q;
                c+=q;
            }
            else
            {
                v[i+1]=0;
                q-=v[i+1];
                v[i]=v[i]-q;
                c+=q;
            }
        }

    }
    cout<<c<<endl;
    return 0;
}


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

int w,h;
int mp[50][50];

void rec(int y,int x){
	if(mp[y][x]==0)return;
	mp[y][x]=0;
	if(x+1<w)rec(y,x+1);
	if(y+1<h)rec(y+1,x);
	if(x-1>=0)rec(y,x-1);
	if(y-1>=0)rec(y-1,x);
	if(x+1<w&&y-1>=0)rec(y-1,x+1);
	if(x+1<w&&y+1<h)rec(y+1,x+1);
	if(x-1>=0&&y+1<h)rec(y+1,x-1);
	if(y-1>=0&&x-1>=0)rec(y-1,x-1);
}

int main(){
	int x,y,ret;
	while(cin >> w >> h && w && h){
		ret = 0;
		for(int i=0;i<h;i++){
			for(int j=0;j<w;j++){
				cin >> mp[i][j];
			}
		}
		for(int i=0;i<h;i++){
			for(int j=0;j<w;j++){
				if(mp[i][j]){
					rec(i,j);
					ret++;
				}
			}
		}
		cout << ret << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
int main() {
  
  int s,answer;
  cin >>s;
  
  vector<int>a(1000000);
  a[0]=s;
  
  for(int i=1;i<=1000000;i++){
    if(a[i-1]%2==0){
      a[i]=a[i-1]/2;
    }
    else{
      a[i]=a[i-1]*3+1;
    }
  }
  
  for(int i=0; i<1000000; i++){
    if(a[i]==1||a[i]==2||a[i]==4){
      answer=i+4;
      break;
    }
  }
  cout <<answer <<endl;
}

Measured memory_bytes: 4096
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long int N,R=0,G=0,B=0,NG=0;string S;cin>>N>>S;
  for(int i=0;i<N;i++){
    if(S[i]=='R')R++;
    if(S[i]=='G')G++;
    if(S[i]=='B')B++;
  }
  for(int i=1;i<=N/2;i++)
    for(int j=0;j<N-2*i;j++)
      if(S[j]!=S[j+i]&&S[j+i]!=S[j+2*i]&&S[j+2*i]!=S[j])NG++;
  cout<<R*G*B-NG<<endl;
}

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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using P = pair<int, int>;

const int INF = 1001001001;

vvi to;
vi a;
vi ans;
vi lis;

void dfs(int v, int p, int change, int value){
    auto it = lower_bound(all(lis), a[v]);
    change = int(it - lis.begin());
    value = *it;
    // cout << v << " " << p << ": " << change << " " << value << endl;
    
    *it = a[v];
    int l = lower_bound(all(lis), INF) - lis.begin();
    ans[v] = l - 1;
    
    for(auto u : to[v]){
        if(u == p) continue;
        dfs(u, v, change, value);
    }
    if(change != -1) lis[change] = value;
    return;
}

void Main() {
    int n; cin >> n;

    a.resize(n);
    rep(i, n) {
        cin >> a[i];
        a[i]--;
    }
    
    to.resize(n);
    rep(i, n-1){
        int u, v; cin >> u >> v;
        u--; v--;
        to[u].pb(v);
        to[v].pb(u);
    }

    ans.resize(n);

    lis.resize(n+1, INF);
    lis[0] = -INF;
    dfs(0, -1, -1, -1);
    
    rep(i, n) cout << ans[i] << endl;
    return;
}

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

Measured memory_bytes: 30760
import collections

n = int(input())
s = [list(input()) for i in range(n)]

for i in range(n):
    s[i] = collections.Counter(s[i])

ans=[100] *28
for i in range(28):
    for j in range(n):
        if s[j][chr(i+97)]<=ans[i]:
            ans[i]=s[j][chr(i+97)]
x=''

for i in range(28):
    if ans[i]!=0:
        for j in range(ans[i]):
            x+=chr(i+97)

print(x)

Measured memory_bytes: 39408
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <string>
#include <stack>
#include <cmath>
#define ll long long
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
using namespace std;
//
const int inf=1e9+7;
const int mod=1e9+7;
//
struct poi{
	int X;int Y;int Z;
	bool operator<(const poi&R)const{
		return X==R.X ? Y==R.Y ? Z<R.Z : Y<R.Y : X<R.X;
	}
};
//
ll GCD(ll a,ll b){
	return (b==0)?(a):(GCD(b,a%b));
}
ll LCM(ll a,ll b){
	return a/GCD(a,b)*b;
}
//
int main(){
	int X,Y;
	cin>>X>>Y;
	int N=GCD(X,Y);
	int x=X/N,y=Y/N;
	cout<<(x+y-1)*N+1<<endl;
	return 0;
}


Measured memory_bytes: 3104
#include<iostream>
using namespace std;
long long a[200000],b[200000],p[200000],n,T,k;
int main(){
	cin>>n>>T>>k;
	for(int i=1;i<=n;i++)cin>>a[i]>>b[i];
	long long L=1LL<<62,M=0;
	for(int i=n;i>=1;i--){
		if(b[i]==2){L=a[i];M=0;}
		if(b[i]==1 && M==0){L=(a[i]+L)/2;p[i]=L;M++;}
		if(b[i]==1 && M==1){p[i]=L;}
	}
	L=-1LL<<62;
	for(int i=1;i<=n;i++){
		if(b[i]==1)L=p[i];
		if(b[i]==2)p[i]=L;
	}
	for(int i=0;i<k;i++){
		int r;cin>>r;
		if(b[r]==1){
			if((p[r]-a[r])>=T)cout<<a[r]+T<<endl;
			else cout<<p[r]<<endl;
		}
		if(b[r]==2){
			if((a[r]-p[r])>=T)cout<<a[r]-T<<endl;
			else cout<<p[r]<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 5436
#include <algorithm>
#include <iostream>
#include <math.h>
#include <cstdio>
#include <string.h>
#include <vector>
#include <functional>
#include <stack>
#include <queue>
#include <string>
#include <list>
using namespace std;
typedef long long ll;
/* prototype */
vector<int> SOE(int,int);//素数 (Min,Max)
int MinCM(int,int);//最小公倍数(num1,num2)
int MaxCD(int,int);//最大公約数(num1,num2)
vector<int> igets(int);//cin * N
ll nPr(ll,ll); //(n,r)
ll nE(ll); //(n)
ll nCr(ll,ll); //(n,r)

void solve(){
    ll N,K,ans=1;
    cin >> N >> K;
    N-=K;
    while(N>0){
        N-=K-1;
        ans++;
    }
    cout << ans << endl;
}

int main(void){cin.tie(0);ios::sync_with_stdio(false);solve();}
/*FUNC*/
//エラトステネスのふるい(素数発見アルゴリズム)
vector<int> SOE(int min, int max)
{
    //0,1は含まれない
    if (min < 2) min = 2;
    //探索リスト作成
    vector<int> int_array;
    for (int i = min; i <= max; i++) int_array.push_back(i);
    //素数リスト
    vector<int> sosu;
    //√max
    double stop = sqrt(max);
    //計算
    while (true)
    {
        //素数リストに追加
        sosu.push_back(int_array.front());
        int_array.erase(int_array.begin());
        //停止
        if (stop < (double)(sosu.back())) break;
        //ふるい
        for (int i = 0; i < (int)int_array.size(); i++)
        {
            if (int_array[i] % sosu.back() == 0)
                int_array.erase(int_array.begin() + i);
        }
    }
    sosu.insert(sosu.end(), int_array.begin(), int_array.end());
    return sosu;
}

//最小公倍数
int MinCM(int a, int b)
{
    int c = a * b;
//入れ替え
    if (a < b)
        swap(a, b);
    int r = a % b;
    while (r != 0)
    {
        a = b;
        b = r;
        r = a % b;
    }
    return c / b;
}

//最大公約数
int MaxCD(int a, int b)
{
//入れ替え
    if (a < b)
        swap(a, b);
    int r = a % b;
    while (r != 0)
    {
        a = b;
        b = r;
        r = a % b;
    }
    return b;
}
//iget cin int 2 vector
vector<int> igets(int N){
    vector<int> A;
    int temp;
    for (int i = 0; i < N; ++i) {
        cin >> temp;
        A.push_back(temp);
    }
    return A;
}

ll nPr(ll n,ll r) {
    ll ans=1;
    r=n-r;
    while(n!=r) {
        ans*=n;
        --n;
    }
    return ans;
}

ll nE(ll n) {
    return nPr(n,n);
}

ll nCr(ll n,ll r) {
    if(r==0)return -1;
    else{
        if(0!=n-r&&n-r<r)r=n-r;
        return nPr(n,r)/nE(r);
    }
}

Measured memory_bytes: 256
class Main{

public static void main (String[] args) {

	java.util.Scanner sc = new java.util.Scanner(System.in);

	int N = sc.nextInt();

	int kosuu [] = new int [4];

	for (int i=0; i<N; i++) {
		String temp = sc.next();
		if (temp.equals("AC")) {
			kosuu[0]++;
		} else if (temp.equals("WA")) {
			kosuu[1]++;
		} else if (temp.equals("TLE")) {
			kosuu[2]++;
		} else {
			kosuu[3]++;
		}
	}

	System.out.print("AC x ");
	System.out.println(kosuu[0]);
	System.out.print("WA x ");
	System.out.println(kosuu[1]);
	System.out.print("TLE x ");
	System.out.println(kosuu[2]);
	System.out.print("RE x ");
	System.out.println(kosuu[3]);

	sc.close();;

}


}



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

int main() {
  int n;
  cin >> n;
  queue<int> r;
  for(int i=0;i<n;i++) {
    int q;
    cin >> q;
    r.push(q);
  }
  int j=0;
  while(true){
    if(r.size()==0){
      if(j==0){
        cout << -1;
      }else{
        cout << n-j;
      }
      return 0;
    }
    if(r.front()==j+1){
      j++;
      r.pop();
    }
    else r.pop();
  }
}


Measured memory_bytes: 1024
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <math.h>

int main(void)
{
    int x, a, b;
    int dist1, dist2;
    scanf("%d %d %d", &x, &a, &b);

    dist1 = abs(x-a);
    dist2 = abs(x-b);

    if (dist1<dist2) printf("A");
    else printf("B");


    return 0;
}


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

int main(){
  string s; cin >> s;

  int cnt=0;
  int n=0;
  for(int i=0; i<s.length(); i++){
    if(s[i] == 'S'){
      n++;
    }
    else if(s[i] == 'T'){
      if(n>0){
        n--;
        cnt++;
      }
    }
  }

  cout << s.length() - 2*cnt << endl;

  return 0;
}


Measured memory_bytes: 640
#include <algorithm>
#include <iostream>
#include <queue>
#include <cmath>
#include <string>
#include <iterator>
#include <map>
#include <set>
#include <iomanip>
#include <vector>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using Graph = vector<vector<int>>;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
#define INF 100000000
#define MAX 200001
#define MOD 1000000007
ll fac[MAX], finv[MAX], inv[MAX];
const int MX = 1000005;

int main(){
    int ans=0;
    for(int i=1;i<=5;i++){
        int a;cin>>a;
        if(a==0) ans=i;
    }
    cout<<ans<<endl;
    
}

Measured memory_bytes: 3580
def f(x,n):
  if n==0:
    return ((x+1)//2)%2
  a=x%(2**(n+1))
  if a<2**n:
    return 0
  return (a-1)%2
A,B=map(int,input().split())
ans=0
for i in range(100):
  ans|=((f(B,i)-f(A-1,i))%2)<<i
print(ans)

Measured memory_bytes: 38256
#include <stdio.h>
#include <string.h>
int n, r[128]; bool used[22370000]; char com[7], s[13];
int main() {
	scanf("%d", &n); r[65] = 1, r[67] = 2, r[71] = 3;
	for(int i = 0; i < n; i++) {
		scanf("%s %s", com, s);
		int h = 0, l = strlen(s);
		for(int j = 0; j < l; j++) h = h * 4 + r[s[j]];
		h += 1 << (2 * l);
		if(com[0] == 105) used[h] = true;
		else puts(used[h] ? "yes" : "no");
	}
}

Measured memory_bytes: 3984