akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<bits/stdc++.h>
typedef long long int ll;
#define REP(i, n) for(int i = 0; i < (n); i++)
#define FOR_IN(i, a, b) for(int i = (a); i < (b); i++)
#define BETWEEN(x, a, b) ((x) >= (a) && (x) <= (b))
#define BIT(b, i) (((b) >> (i)) & 1)
#define LOG_F 1
#define LOG(...) if(LOG_F) fprintf(stderr, __VA_ARGS__)

using namespace std;

ll pow(int x, int n){
  return n == 0 ? 1 : x * pow(x, n - 1);
}


/*
n m
a1 ... am

n 10^4
m 9
ai 9

*** over 64 bit ***
 */


int match[] = {2,5,5,4,5,6,3,7,6};
int N,m;
string dp[10001];

string max(string s, string t){
  if(s[0]=='-' && t[0]=='-') return "-";
  if(s[0]=='-') return t;
  if(t[0]=='-') return s;

  if(s.size() < t.size()) return t;
  else if(s.size() > t.size()) return s;

  if(s < t) return t;
  else return s;
}

int main(){
  cin>>N>>m;
  int a[m];
  int b[m];
  REP(i,m){
    cin>>a[i];
  }

  sort(a, a+m, greater<int>());
  REP(i,m){
    b[i] = match[a[i]-1];    
  }

  REP(j,N+1){
    dp[j] = "-";
  }
  dp[0] = "";

  REP(i,m){
    REP(j,N+1){
      if(j>=b[i]){
        dp[j] = max(dp[j], dp[j-b[i]] + to_string(a[i]));
        //cerr << dp[j] << " ";
      }
    }
    //LOG("\n");
  }

  cout<<dp[N]<<endl;

  return 0;
}


Measured memory_bytes: 34432
import java.io.*;
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        String S = scan.next();
        String[] Sarray = new String[S.length()];
        for(int i=0;i<S.length();i++){
            String tmps = String.valueOf(S.charAt(i));
            Sarray[i] = tmps;
        }
        String tmps = Sarray[0];
        boolean f = false;
        int count = 0;
        for(int i=1;i<4;i++){
            if(String.valueOf(Sarray[i]).equals(tmps)){
                count++;
            }
        }
        if(count==3){
            f = true;
        }
        List<String> list = new ArrayList<String>();        
        for(int i=0;i<4;i++){
            list.add(Sarray[i]);
        }
        Collections.sort(list);
        String[] array = list.toArray(new String[list.size()]);
        if((f==false)&&String.valueOf(array[0]).equals(String.valueOf(array[1]))&&String.valueOf(array[2]).equals(String.valueOf(array[3]))){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 23636
#include<iostream>
using namespace std;
int main(){
	int ave = 0,meave = 0;
	while(true){
		int n;
		cin >> n;
		if(n == 0)break;
		for(int i = 0; i < n; i++){
			int pm, pe, pj;
			cin >> pm >> pe >> pj;
			ave = (pm + pe + pj) / 3;
			meave = (pm + pe) / 2;
			if(pm == 100 || pe == 100 || pj == 100){
				cout << "A" << endl;
			}
			else if(meave >= 90){
				cout << "A" << endl;
			}
			else if(ave >= 80){
				cout << "A" << endl;
			}
			else if(ave >= 70){
				cout << "B" << endl;
			}
			else if(ave >= 50 && pm >= 80 ||pe >= 80){
				cout << "B" << endl;
			}
			else{
				cout << "C" << endl;
			}
		}
	}
}

Measured memory_bytes: 1156
//Pye
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i = (a); i <= (b); i++)
#define FORR(i, a, b) for(int i = (a); i >= (b); i--)
#define pair pair <int, int>
#define maxn 400005
using namespace std;
int n, q, Next[maxn][26], cnt[maxn][26][26], str[maxn], sub[maxn], link[maxn], dem;
vector <int> id[maxn];
void Add(string s, int x){
    int u = 0;
    for(int i = 0; s[i]; i++){
        int v = s[i] - 'a';
        if(!Next[u][v]) Next[u][v] = ++dem;
        u = Next[u][v];
    }
    id[u].push_back(x);
    link[x] = u;
}
void Find(int u){
    FOR(p, 0, 25)
        if(Next[u][p]){
            int v = Next[u][p];
            Find(v);
            copy(id[v].begin(), id[v].end(), back_inserter(id[u]));
        }
}
void dfs(int u){
    FOR(p, 0, 25){
        FOR(q, 0, 25){
                if(p == q) continue;
                if(!Next[u][p] || !Next[u][q]) continue;
                for(auto x : id[Next[u][p]]) cnt[x][p][q] += id[Next[u][q]].size();
            }
        if(Next[u][p]) dfs(Next[u][p]);
    }

}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
//    ifstream cin("inp.txt");
    cin >> n;
    FOR(i, 1, n){
        string s;
        cin >> s;
        Add(s, i);
    }
    Find(0);
    dfs(0);
    cin >> q;
    while(q--){
        string s;
        int ans = n, k;
        cin >> k >> s;
        FOR(i, 0, 25)
            FOR(j, i+1, 25){
                int u = s[i] - 'a', v = s[j] - 'a';
                ans -= cnt[k][u][v];
            }
        cout << ans - id[link[k]].size() + 1 << '\n';
    }
}



Measured memory_bytes: 295160
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    int N,D,X;
    cin >> N >> D >> X;
    vector<int> days(N);
    int count=0;
    for(int i=0;i<N;i++){
        cin >> days.at(i);
        if(days.at(i)>D){
            count++;
        }else if(D%days.at(i)!=0){
            count+=D/days.at(i)+1;
        }else{
            count+=D/days.at(i);
        }
    }
    cout << count+X << endl;
}


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

public class Main {
  public static void main(String[] args) {
    @SuppressWarnings("resource")
    Scanner sc = new Scanner(System.in);
    Map<String, Integer> map = new HashMap<>();

    int N = sc.nextInt();
    for (int i = 0; i < N; i++) {
      String key = sc.next();
      map.computeIfPresent(key, (k, v) -> (v + 1));
      map.putIfAbsent(key, 1);
    }

    int M = sc.nextInt();
    for (int i = 0; i < M; i++) {
      String key = sc.next();
      map.computeIfPresent(key, (k, v) -> (v - 1));
      map.putIfAbsent(key, -1);
    }

    int ans = 0;
    for (Entry<String, Integer> e : map.entrySet()) {
      ans = Math.max(ans, e.getValue());
    }
    System.out.println(ans);
  }
}


Measured memory_bytes: 27220
#include <iostream>
#include <cmath>
#include <climits>

using namespace std;

int main(int argc, char const *argv[])
{
    long long N;
    cin >> N;

    double sq = sqrt((double)N);
    long long sum;
    long long min = LLONG_MAX;
    long long min_i, min_j;
    for (int i = 1; i <= (int)sq; i++)
    {
        if (N % i == 0)
        {
            sum = i + (N / i);
            if (sum < min)
            {
                min = sum;
                min_i = i;
                min_j = (N / i);
            }

        }
        
    }
    
    cout << (min_i - 1 + min_j - 1) << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <ios> 
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

using namespace std;
typedef long long int lli;
typedef vector<int> vi;
const int MAX=1e5+5;

int main(){
	int N,M;
	cin>>N>>M;
	if(N>=M){
		cout<<0;
		return 0;
	}
	int X[MAX];
	rep(i,M)cin>>X[i];
	sort(X,X+M);

	int d[MAX];
	rep(i,M-1)d[i]=X[i+1]-X[i];
	sort(d,d+(M-1));
  
	int ans=0;
	rep(i,M-N)ans+=d[i];
	cout<<ans;
}

Measured memory_bytes: 1024
def calc(d)
  loop.with_index do |_, i|
    next if i == 0
    n = (i * Math::PI).to_i
    n += 1 if Math::PI > (n + 0.5) / i
    if (Math::PI - 1.0 * n / i).abs < d
      return "#{n}/#{i}"
    end
  end
end
loop do
  d = gets.to_f
  break if d == 0.0
  puts calc(d)
end

Measured memory_bytes: 8572
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int w = in.nextInt();
		Obj[] object = new Obj[n+1];
		for (int i = 1; i < object.length; i++) {
			object[i] = new Obj(in.nextInt(), in.nextInt());
		}
		int[][] dp = new int[n+1][w+1];

		for (int i = 1; i <= n; i++) {
			for (int j = 0; j <= w; j++) {
				if (j < object[i].weight) {
					dp[i][j] = dp[i-1][j];
				} else {
					dp[i][j] = Math.max(dp[i-1][j], dp[i-1][j-object[i].weight] + object[i].value);
				}
			}
		}

		System.out.println(dp[n][w]);

	}
	static class Obj {
		int value;
		int weight;

		public Obj(int v, int w) {
			value = v;
			weight = w;
		}
	}

}



Measured memory_bytes: 30944
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) (v).begin(),(v).end()
#define out(a) cout << (a) << endl
using namespace std;
using ll = long long;
int main(){
    int n;
    string s;
    cin >> n >> s;
    int cnt=0, ans=0;
    for (int i=0; i<n; i++){
        if (s[i] == 'I') cnt++;
        else cnt--;
        ans = max(ans, cnt);
    }
    out(ans);
}

Measured memory_bytes: 256
import copy
n,k = map(int,input().split())
ai = [int(i) for i in input().split()]

#old_ai = ai
cnt = 0
old_tmp = sum(ai)

while 1 == 1:
    #old_ai = copy.deepcopy(ai)
    li = [0]*(n+1)
    for i in range(n):
        li[max(0,i-ai[i])] += 1
        li[min(n,i+1+ai[i])] -= 1
        #print(li)
    #print(li)
    tmp = 0
    for i in range(n):
        if i == 0:
            ai[i] = li[i]
            tmp += ai[i]
        else:
            ai[i] = li[i] + ai[i-1]
            tmp += ai[i]
    #print(rui)
    if old_tmp == tmp:
        print(*ai)
        exit()
        break
    cnt += 1
    if cnt == k:
        print(*ai)
        exit()
    old_tmp = tmp

Measured memory_bytes: 155944
s = input()

n = len(s)

def is_palindrome(start, end):
    while start <= end:
        if s[start] == s[end]:
            start += 1
            end -= 1
        else:
            return False
    return True

if is_palindrome(0, n - 1) and is_palindrome(0, (n - 1) // 2 - 1) and is_palindrome((n + 3 // 2), n-1):
    print("Yes")
else:
    print("No")


Measured memory_bytes: 2940
import java.util.Scanner;

public class Main {
    static StringBuilder sb = new StringBuilder();

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        recursive(0, 0, 100, 0.0, n);
        sb.append("100.00000000 0.00000000");
        System.out.println(sb.toString());
    }

    private static void recursive(double st1, double st2, double en1, double en2, int n) {
        if (n == 0) {
            sb.append(st1 + " ").append(st2 + "\n");
            return;
        }
        double h = Math.hypot(en1 - st1, en2 - st2);//+ (en2 - st2) / 2
        double k = Math.sqrt(3) / 2 * (h / 3);
        double v = k * (en1 - st1) / h;
        double a = Math.pow(k, 2);
        double b = Math.pow(v, 2);
        Double p = Math.sqrt(a -b);
        if (p.isNaN()) {
            p = 0.0;
        }
        if (st2>en2){
            p=0-p;
        }
        double point = (en1 + st1) / 2 - p;

        recursive(st1, st2, st1 + (en1 - st1) / 3, st2 + (en2 - st2) / 3, n - 1);
        recursive(st1 + (en1 - st1) / 3, st2 + (en2 - st2) / 3,point, v + (en2 + st2) / 2, n - 1);
        recursive(point, v + (en2 + st2) / 2, st1 + ((en1 - st1) / 3 * 2), st2 + ((en2 - st2) / 3 * 2), n - 1);
        recursive(st1 + ((en1 - st1) / 3 * 2), st2 + ((en2 - st2) / 3 * 2), en1, en2, n - 1);
    }
}


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

typedef long long ll;
typedef unsigned long long ull;

int len[100000];
vector<int> edge[100000];

int getlen(int v){
    if(len[v]>0) return len[v];
    int l = 0;
    for(int to:edge[v]){
        l = max(l, getlen(to)+1);
    }
    len[v] = l;
    return l;
}

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

    int ans = 0;
    for(int i=0;i<N;i++) ans = max(ans, getlen(i));

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

Measured memory_bytes: 8192
#include<iostream>
#include<string.h>
#include<stdio.h>
#include<cmath>
#include<algorithm>
using namespace std;

int n;
int a[100011],b[100011],c[100011];
long long sb[100011];
long long ans;

int main()
{
    int i,j,k;
    long long tmp;
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
    }
    for(i=1;i<=n;i++)
    {
        scanf("%d",&b[i]);
    }
    
    b[n+1]=0x3f3f3f3f;
    
    for(i=1;i<=n;i++)
    {
        scanf("%d",&c[i]);
    }
    
    sort(a+1,a+n+1);
    sort(b+1,b+n+1);
    sort(c+1,c+n+1);
    
    
    int xx,yy;
    xx=1;
    ans=0;
    for(i=1;i<=n;i++)
    {
        while(xx<=n && c[xx]<=b[i])
        {
            xx++;
        }
        
        sb[i]=n+1-xx;
    }
    
    
    for(i=n-1;i>=1;i--)
    {
        sb[i]+=sb[i+1];
        
        
    }
    /*
    for(i=1;i<=n;i++)
    {
        cout<<sb[i]<<' ';
    }
    cout<<"***"<<endl;
    */
    
    sb[n+1]=0;
    xx=1;
    for(i=1;i<=n;i++)
    {
        while(xx<=n && b[xx]<=a[i])
        {
            xx++;
        }
        
        tmp=sb[xx];
        ans+=tmp;
    }
    
    cout<<ans<<endl;
    
    return 0;
}


Measured memory_bytes: 2304
#define _GLIBCXX_DEBUG
#include <iostream>
#include <bits/stdc++.h>
    
    
using namespace std;
#define ll long long
#define ld long double
#define  P pair<ll,ll>
#define FOR(i,n,m) for(ll i=n; i<(ll)m;i++)
#define FORr(i,m,n) for(ll i=n; i>=(ll)m; i--)
#define FORm(i,m) for(auto i=m.begin();i!=m.end();i++)
#define REV(v) reverse(v.begin(),v.end())
#define sortAl(v) sort(v.begin(),v.end())
#define sortAlr(v) sort(v.begin(),v.end()); reverse(v.begin(),v.end())
#define cout(n) cout<<fixed<<setprecision(n)
#define dout(n) cout<<# n<<" = "<<n<<endl;
#define v1out(v) FOR(j,0,v.size()){cout<<v[j]; if(j!=(ll)v.size()-1)cout<<" ";else cout<<endl; }
#define v2out(v) FOR(i,0,v.size())v1out(v[i]);

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    vector<P> v(n);
    FOR(i,0,n){
        cin>>v[i].first;
        v[i].second=i;
    }
    sortAlr(v);
    vector<vector<ll>> dp(n+1,vector<ll>(n+1));
    FOR(i,1,n+1){
        ll a = v[i-1].first;
        ll p = v[i-1].second;
//        cout<<"i = "<<i<<endl;
        FOR(j,0,i+1){
            ll l = i-j-1;
            ll r = n-j;
            //cout<<" j = "<<j<<" "<<l<<" "<<r<<endl;
            if(j>0)dp[i][j] = max(dp[i-1][j-1] + a*abs(r-p),dp[i][j]);
            if(j<i)dp[i][j] = max(dp[i-1][j] + a*abs(l-p), dp[i][j]);            
        }
    }
    ll ans = 0;
    FOR(i,0,n+1){
        ans = max(ans,dp[n][i]);
    }
    cout<<ans<<endl;

}

Measured memory_bytes: 34692
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long  ll;
#define rep(i,s,n)for(ll i=s;i<n;i++)
#define repe(i,s,n)for(ll i=s;i<=n;i++)

char c[50][50] = {};
int d[50][50] = {};

void maze(ll R, ll C, ll sy, ll sx, ll gy, ll gx) {
	sy--, sx--, gy--, gx--;
	bool v[50][50] = {};
	ll x[4] = { 1,0,0,-1 };
	ll y[4] = { 0,1,-1,0 };

	ll ps = 0;
	ll pe = 0;
	ll qy[10000] = {};
	ll qx[10000] = {};

	qy[pe] = sy;
	qx[pe] = sx;
	d[sy][sx] = 0;
	v[sy][sx] = true;
	pe++;

	while (ps != pe) {
		ll cy = qy[ps];
		ll cx = qx[ps];
		ps++;
		if (cy == gy && cx == gx) {
			break;
		}

		rep(i, 0, 4) {
			ll ny = cy + y[i];
			ll nx = cx + x[i];

			if (ny >= 0 && ny < R && nx >= 0 && nx < C && c[ny][nx] != '#' && !v[ny][nx]) {
				qy[pe] = ny;
				qx[pe] = nx;
				pe++;
				v[ny][nx] = true;
				d[ny][nx] = d[cy][cx] + 1;
			}
		}
	}
}

int main() {
	ll h, w; cin >> h >> w;
	ll white = 0;
	rep(i, 0, h) {
		rep(j, 0, w) {
			cin >> c[i][j];
			if (c[i][j] == '.')white++;
		}
	}
	maze(h, w, 1, 1, h, w);

	ll cost = d[h - 1][w - 1];
	if (cost == 0)cout << -1 << endl;
	else {
		cout << white - (cost + 1) << endl;
	}

	return 0;
}

Measured memory_bytes: 384
#include<stdio.h>

int main(void)
{
  char str[100001],ans='a';
  int i=0;
  scanf("%s",str);
  while(str[i] != '\0')
    {
      if(ans == str[i])
	{
	  ans++;
	  i=0;
	  continue;
	}
      if((int)ans == 123)
	{
	  printf("None\n");
	  return 0;
	}
      i++;
    }

  printf("%c\n",ans);
  return 0;
}
		   


Measured memory_bytes: 256
#include<stdio.h>

int main(){
    int a,b,c;
    scanf("%d %d %d",&a,&b,&c);
    int h1=a+b,h2=b+c,h3=a+c;
    if (h1<h2 && h1<h3) printf("%d\n",h1);
    else if(h2<h1 && h2<h3) printf("%d\n",h2);
    else printf("%d\n",h3);

    return 0;
}


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

using namespace std;

#define FOR(i,a,b) for(int i = (a); i <= (b); ++i)
#define FORD(i,a,b) for(int i = (a); i >= (b); --i)
#define RI(i,n) FOR(i,1,(n))
#define REP(i,n) FOR(i,0,(n)-1)
#define mini(a,b) a=min(a,b)
#define maxi(a,b) a=max(a,b)
#define mp make_pair
#define pb push_back
#define st first
#define nd second
#define sz(w) (int) w.size()
typedef vector<int> vi;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;

typedef pair<ll, pll> para;
const ll inf = 1e18 + 7;
const int maxN = 1e5 + 5;

#define LOGN 18
int n, k;
string s;
pii dp[maxN];
set<pii> odl;


int main() {
	ios_base::sync_with_stdio(0);
	cin >> n >> k;
	cin >> s;
	dp[n] = {0, 0};
	odl.insert({0, n});
	FORD(i, n - 1, 0) {
		if (i + k + 1 <= n) {
			odl.erase({dp[i + k + 1].st, i + k + 1});
		}
		if (s[i] == '1') dp[i] = {-1, -1};
		else {
			if (odl.empty()) {
				cout << "-1";
				return 0;
			} else {
				auto it = odl.begin();
				dp[i].st = it->st + 1;
				dp[i].nd = it->nd;
				odl.insert({dp[i].st, i});
			}
		}
	}
	int x = 0;
	while (x != n) {
		cout << dp[x].nd - x << " ";
		x = dp[x].nd;
	}
	return 0;
}


Measured memory_bytes: 3712
_,_,X,Y = map(int,input().split())
x = list(map(int,input().split()))
y = list(map(int,input().split()))

x_max = max(x)
y_min = min(y)
flag = False
for z in range(X+1,Y+1):
  if x_max < z <= y_min:
    flag = True
print("No War" if flag else "War")

Measured memory_bytes: 9192
al = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
n = int(input())
wli = list(input())
ali = []

for i in range(len(wli)):
    a = al.index(wli[i])
    ali.append(al[(n+a)%26])


for i in ali:
    print(i, end = "")

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int nextInt() { int x; scanf("%d", &x); return x;}

int main2() {
  int N = nextInt();
  int A = nextInt();
  cout << (N % 500 <= A ? "Yes":"No") << endl;
  return 0;
}

int main() {
  for (;!cin.eof();cin>>ws)
    main2();
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define FOR(i,a,b) for(int i=(a); i<=(b); i++)
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define chmin(a,b) if((a)>(b)) (a)=(b);
#define chmax(a,b) if((a)<(b)) (a)=(b);
#define vi vector<int>
#define pii pair<int,int>
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define pb push_back
#define pf push_front
int gcd(int a,int b){/*a>=0,b>=0,￢(a=b=0)*/
  while(min(a,b)>0){if(a<b)swap(a,b);a%=b;}return max(a,b);
}
int dx[]={1,0,-1,0,1,-1,-1,1};
int dy[]={0,1,0,-1,1,1,-1,-1};
const int MOD = 1e9+7;
const long long INF = 1e18+10;

/*--------------------------------------------------------------------*/

signed main(){
	int n;
	cin>>n;
	vi p(n);
	rep(i,n)cin>>p[i];
	sort(all(p));
	int ans=0;
	rep(i,n-1)ans+=p[i];
	ans+=p[n-1]/2;
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3556
//
// Created by munaiyi on 2020/3/8.
//

#include <bits/stdc++.h>

using namespace std;
const int maxn = 2e5 + 5;
const int mod = 998244353;
pair<int, int> d[maxn];
int dp[maxn], Next[maxn];



int main() {
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%d%d", &d[i].first, &d[i].second);
    }
    sort(d, d + n);
    memset(dp, 0, sizeof(dp));
    dp[n] = 1;
    Next[n] = n;
    for (int i = n - 1; i >= 0; i--) {
        dp[i] = dp[i + 1];
        Next[i] = i+1;
        int v = d[i].first + d[i].second;
        while(Next[i]!=n&&d[Next[i]].first<v){
            Next[i] = Next[Next[i]];
        }
        dp[i] = dp[i] + dp[Next[i]];
        if (dp[i] >= mod) dp[i] -= mod;
        //printf("%d %d %d\n", i, dp[i], Next[i]);
    }
    printf("%d\n", dp[0]);
    return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define last last2

using namespace std;

char str[5005],ans[5005];

void outputmin(int n) {
  char minn=str[1];
  for(int i=1;i<=n;i++) minn=min(minn,str[i]);
  for(int i=1;i<=n;i++) putchar(minn);
}

void solve1(int n) {
  static char cur[5005];
  memcpy(ans,str,sizeof(ans));
  for(int i=1;i<=n;i++) {
    int cnt=0;
    for(int j=i;j<=n;j++) cur[++cnt]=str[j];
    for(int j=1;j<i;j++) cur[++cnt]=str[n-j+1];
    bool ok=0;
    for(int j=1;j<=n;j++)
      if (cur[j]!=ans[j]) {
      	if (cur[j]<ans[j]) ok=1;
      	break;
	  }
	if (ok) memcpy(ans,cur,sizeof(ans));
  }
  puts(ans+1);
}

int trans[5005];

void pre(int n,int m,int k) {
  static int cur[5005];
  for(int i=1;i<=n;i++) trans[i]=i;
  for(int i=1;i<k;i++) {
  	int cnt=0;
  	for(int j=m+1;j<=n;j++) cur[++cnt]=trans[j];
  	for(int j=1;j<=m;j++) cur[++cnt]=trans[n-j+1];
  	m*=2;
  	memcpy(trans,cur,sizeof(trans));
  }
  int cnt=0;
  for(int j=n-m+1;j<=n;j++) cur[++cnt]=trans[j];
  for(int j=1;j<=n-m;j++) cur[++cnt]=trans[n-j+1];
  memcpy(trans,cur,sizeof(trans));
}

void solve(int n,int k) {
  static char cur[5005],cur2[5005];
  char minn=str[1];
  for(int i=1;i<=n;i++) minn=min(minn,str[i]);
  int last=1,pow2=1;
  for(int i=1;i<k;i++) pow2*=2;
  int len=0;
  for(int i=1;i<=n;i++)
    if (str[i]!=minn) {
    	if (pow2*(i-last)>=n) {
    		outputmin(n);
    		return;
		}
		len=max(len,i-last);
		last=i+1;
	}
  if (pow2*2*(n-last+1)>=n) {
  	outputmin(n);
  	return;
  }
  len=max(len,2*(n-last+1));
  pre(n,len,k-1);
  memcpy(ans,str,sizeof(ans));
  last=1;  
  for(int i=1;i<=n;i++)
    if (str[i]!=minn) {
    	if (i-last==len) {
    		int cnt=0;
    		for(int j=n-last+2;j<=n;j++) cur[++cnt]=str[j];
    		for(int j=1;j<=n-last+1;j++) cur[++cnt]=str[n-j+1];
    		for(int j=1;j<=n;j++) cur2[j]=cur[trans[j]];
    		bool ok=0;
    		for(int j=1;j<=n;j++)
    		  if (cur2[j]!=ans[j]) {
    		  	if (cur2[j]<ans[j]) ok=1;
    		  	break;
			  }
			if (ok) memcpy(ans,cur2,sizeof(ans));
		}
		last=i+1;
	}
  if (2*(n-last+1)==len) {
  	int cnt=0;
  	for(int i=n-last+2;i<=n;i++) cur[++cnt]=str[i];
  	for(int i=1;i<=n-last+1;i++) cur[++cnt]=str[n-i+1];
  	for(int i=1;i<=n;i++) cur2[i]=cur[trans[i]];
  	bool ok=0;
  	for(int i=1;i<=n;i++)
  	  if (cur2[i]!=ans[i]) {
  	  	  if (cur2[i]<ans[i]) ok=1;
  	  	  break;
		}
	if (ok) memcpy(ans,cur2,sizeof(ans));
  }
  puts(ans+1);
}

int main() {
  int n,k;
  scanf("%d%d%s",&n,&k,str+1);
  if (k>14) {
  	outputmin(n);
  	return 0;
  }
  if (k==1) {
  	solve1(n);
  	return 0;
  }
  solve(n,k);
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <iomanip>
#include <climits>
#include <map>
using namespace std;
string s;
int main()
{
	string A,B;
	cin >> A >> s >> B;
	cout << A[0] << s[0] << B[0] << endl;
	return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define INF 1e+9
typedef long long ll;
void chmin(ll &a, ll b) { if (a > b) a = b; }
    ll n,A,B,C;
    vector<ll> l;
    
ll dfs(int cnt,ll a,ll b, ll c){
    if(n==cnt){
        if(!a||!b||!c)return INF;
        return abs(a-A)+abs(b-B)+abs(c-C);
    }
    ll ret0 = dfs(cnt+1,a,b,c);
    ll ret1 = dfs(cnt+1,a+l[cnt],b,c)+(a?10:0);
    ll ret2 = dfs(cnt+1,a,b+l[cnt],c)+(b?10:0);
    ll ret3 = dfs(cnt+1,a,b,c+l[cnt])+(c?10:0);
    ll res = min(ret0,ret1);
    res = min(res,ret2);
    res = min(res,ret3);
   /* ll res = dfs(cnt+1,a,b,c);
    chmin(res,dfs(cnt+1,a+l[cnt],b,c)+(a?10:0));
    chmin(res,dfs(cnt+1,a,b+l[cnt],c)+(b?10:0));
    chmin(res,dfs(cnt+1,a,b,c+l[cnt])+(c?10:0));*/
    //cout<<res<<endl;
    return res;
}

int main(){
    cin>>n>>A>>B>>C;
    l.resize(n);
    for(int i=0;i<n;i++){
        cin>>l[i];
    }
    cout<<dfs(0,0,0,0)<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long 
#define hell 1000000007
#define F first
#define re 15000000
#define S second
#define pb push_back
#define all(a)  (a).begin(),(a).end()
#define rep(i,a,b) for(ll int i = a;i<b;i++)
#define pi 3.1415926536
#define Mod 998244353
//char a[2000][2000];
using namespace std;
struct Node
{
	int data;
	Node *left;
	Node *right;
};
void inorder(Node *ptr){
	if(ptr == NULL)
		 return ;
	inorder(ptr->left);
	cout<<ptr->data<<" ";
	inorder(ptr->right);
}
int main()
{   
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);            
    //std::setprecision(20);    
    int tests=1;
      //freopen("input.txt", "r", stdin);	
    //cin>>tests;
  while(tests--)
    {
    	ll n,k;
    	cin>>n>>k;
    	if(k == 1){
    		cout<<0;
    	}
    	else{
    		cout<<n-k;
    	}
    }
}


Measured memory_bytes: 256
//
//  main.cpp
//  AC
//
//  Created by makinofuya on 2019/07/08.
//  Copyright © 2019 makinofuya. All rights reserved.
//
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stack>
typedef long long ll;
using namespace std;
#define mod 1000000007
#define rep(i,n) for(int i=1;i<n;i++)
#define out(s) cout << s << endl

int main(){
    int n,k;cin >> n >> k;
    int c;
    double ans=0,p;
    rep(i,n+1){
        p=1.0/n;
        c=i;
        while(c<k){
            c*=2;
            p/=2;
        }
        ans+=p;
    }
    printf("%.12f\n",ans);
    return 0;
}



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

typedef long long int ll;
typedef long double ld;

//****************************************************                
#define lp(var,start,end) for (ll var = start; var <end ; ++var)
#define rlp(var,start,end) for(ll var = start; var>=end ; var--)
#define pb push_back
#define mp make_pair
#define pf push_front
#define ff first
#define ss second
#define vll vector<ll>
#define pll pair<ll,ll> 
#define vpll vector<pll>
#define all(X) X.begin(),X.end()
#define endl "\n" //comment it for interactive questions
#define trace1(a) cerr << #a << ": " << a << endl;
#define trace2(a,b) cerr << #a << ": " << a << " " << #b << ": " << b << endl;
#define trace3(a,b,c) cerr << #a << ": " << a << " " << #b << ": " << b << " " << #c << ": " << c << endl;
#define trace4(a,b,c,d) cerr << #a << ": " << a << " " << #b << ": " << b << " " << #c << ": " << c << #d << ": " << d << endl;
#define OC freopen("input.txt" , "r", stdin); freopen("output.txt" , "w", stdout)
#define MOD (ll)1e9+7; //change it for other mods
#define FAST_IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
        //*******************************************************
//Some Functions

ll powmod(ll a,ll b)
{
   ll res = 1;
   while(b > 0) {
      if(b & 1) res = (res * a) % MOD;
      a = (a*a)%MOD;
      b = b >> 1; 
  }
  return res % MOD;
}

void solve()
{
    ll n;
    cin >> n;
    ll sum = 0;
    vll a(n+1), b(n+1), c(n+1);
    for(ll i=1;i<=n;i++) {
    	cin >> a[i];
    }
    for(ll i=1;i<=n;i++){
    	cin >> b[i];
    }
    for(ll i=1;i<=n;i++){
    	cin >> c[i];
    }
    for(ll i=1;i<=n;i++){
    	sum += b[a[i]];
    	if(i!=1){
    		if(a[i] == a[i-1] + 1) {
    			sum += c[a[i-1]];
    		}
    	}
    }
    cout << sum <<"\n";
}

int main()
{
    FAST_IO;
    // #ifndef ONLINE_JUDGE 
   	// 	OC;
    // #endif
    ll t = 1;
    // cin >> t;
    while(t--){
        solve();
    }
}

Measured memory_bytes: 256
import sys

sys.setrecursionlimit(200000)


def input():
    return sys.stdin.readline()[:-1]


def ii(t: type = int):
    return t(input())


def il(t: type = int):
    return list(map(t, input().split()))


def imi(N: int, t: type = int):
    return [ii(t) for _ in range(N)]


def iml(N: int, t: type = int):
    return [il(t) for _ in range(N)]


def solve():
    a, b, c = il()
    for i in range(1, 100):
        if i*a % b == c:
            return 'YES'
    return 'NO'


if __name__ == "__main__":
    print(solve())


Measured memory_bytes: 3064
"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    const N = ~~arg[0];
    const S = arg.slice(1, N + 1).map(n=>~~n);
    
    let now = 1;
    let cnt = 0;
    
    while(now !== 2) {
        now = S[now - 1];
        cnt++;
        
        if(cnt > N) {
            console.log(-1);
            return;
        }
    }
    
    console.log(cnt);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

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

//ライブラリ始まり

//定数

//円周率
const double PI = 3.1415926535897932384;

//天井
const int INF = 1000000000; // = 10^9
const ll LINF = 1000000000000000; // = 10^15

//ABC文字列
const string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZABC";
const string abc = "abcdefghijklmnopqrstuvwxyzabc";

//よくあるmodくん
const ll MOD = 1000000007; // = 10^9 + 7

//データ構造

//Union_Find木
struct UnionFind {
  vector<int> UF; // UF.at(i) : iの親の番号
  vector<int> SIZE; // SIZE.at(root(i)) : iと連結されてる要素の数
  UnionFind(int N) : UF(N), SIZE(N, 1) { // 最初は全てが根であるとして初期化
    for(int i = 0; i < N; i++) {
      UF.at(i) = i;
    }
  }
  int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
    if (UF.at(x) == x) {
      return x;
    }
    return UF.at(x) = root(UF.at(x));
  }
  void unite(int x, int y) { // xとyの木を併合
    int rx = root(x); // xの根をrx
    int ry = root(y); // yの根をry
    if (rx == ry) {
      return; // xとyの根が同じ(=同じ木にある)時はそのまま
    }
    // xとyの根が同じでない(=同じ木にない)時：小さい方の根を大きい方の根につける
    if (SIZE.at(rx) < SIZE.at(ry)) {
      UF.at(rx) = ry;
      SIZE.at(ry) += SIZE.at(rx);
      SIZE.at(rx) = 0;
    }
    else {
      UF.at(ry) = rx;
      SIZE.at(rx) += SIZE.at(ry);
      SIZE.at(ry) = 0;
    }
  }
  bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
  }
  int size(int x) { // xと連結されてる要素の数を返す
    return SIZE.at(root(x));
  }
};

//関数

//ctoi
int ctoi(char c){
  if (c == '0') {
    return 0;
  }
  if (c == '1') {
    return 1;
  } 
  if (c == '2') {
    return 2;
  } 
  if (c == '3') {
    return 3;
  }
  if (c == '4') {
    return 4;
  } 
  if (c == '5') {
    return 5;
  } 
  if (c == '6') {
    return 6;
  }
  if (c == '7') {
    return 7;
  } 
  if (c == '8') {
    return 8;
  } 
  if (c == '9') {
    return 9;
  }
  return -1;  
}

//素数判定
bool PN(int x) {
  if (x <= 1) {
    return false; // 1や0,-1は素数ではない
  }
  if (x == 2) {
    return true; // √2 + 1 > 2 なので下でやると 2 ％ 2 = 0 となり判定できない
  }
  for (int i = 2; i < sqrt(x) + 1; i++) {
    if (x % i == 0) {
      return false; // 割れたら素数じゃない
    }
  }
  return true;
}

//ライブラリ終わり

int main() {
  int N;
  cin >> N;
  int X = 0;
  string S;
  cin >> S;
  int ans =  X;
  for (int i = 0; i < N; i++) {
    if (S.at(i) == 'I') {
      X++;
    }
    else {
      X--;
    }
    ans = max(ans, X);
  }
  cout << ans << endl;
}

Measured memory_bytes: 3592
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<iomanip>
#include<set>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int main(){
	int N;
	scan(N);
	int H[200];
	int ans=0,highest=0;
	rep(i,N){
		scan(H[i]);
		if(H[i]>=highest) ans++;
		highest=max(highest,H[i]);
	}
	prin(ans);
	return 0;
}


Measured memory_bytes: 256
a1=list(map(int,input().split()))
a2=list(map(int,input().split()))
a3=list(map(int,input().split()))
a=[a1,a2,a3]
n=int(input())
b=[0 for _ in range(n)]
for i in range(n):
  b[i]=int(input())
bingo=[[0,0,0],[0,0,0],[0,0,0]]
for i in range(3):
  for j in range(3):
    if a[i][j] in b:
      bingo[i][j]=1
for i in range(3):
  if bingo[i]==[1,1,1]:
    print('Yes')
    exit()
for j in range(3):
  if bingo[0][j]==1 and bingo[1][j]==1 and bingo[2][j]==1:
    print('Yes')
    exit()
if bingo[0][0]==1 and bingo[1][1]==1 and bingo[2][2]==1:
  print('Yes')
  exit()
if bingo[0][2]==1 and bingo[1][1]==1 and bingo[2][0]==1:
  print('Yes')
  exit()


print('No')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, N) for (int i = 0; i < (int)N; ++i)
#define all(a) (a).begin(), (a).end()

int N, T;
vector<int> t;
int main() {
  cin >> N >> T;
  t.resize(N);
  rep(i, N) cin >> t[i];

  ll ans = T;
  for (int i = 1; i < N; ++i) {
    int dt = t[i] - t[i - 1];
    ans += (dt < T ? dt : T);
  }

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


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

int main() {
  int x;
  double ans=0;
  cin >> x;

  if (x!=1) {
    for (int i=2; i<=x; i++) {
      for (int j=2; pow(i, j)<=x; j++) {
        if (ans<pow(i, j)) ans=pow(i, j);
      }
    }
  } else {
    ans=1;
  }

  cout << ans << endl;
}

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

using namespace std;
using L = vector<long long>;
using A = vector<vector<long long>>;
#define sorted(vector) sort(vector.begin(),vector.end())
#define vmin(vector) *min_element(vector.begin(),vector.end())
#define vmax(vector) *max_element(vector.begin(),vector.end())
#define vsum(vector) accumulate(vector.begin(),vector.end(),0)
#define append(a) push_back(a)
#define int(a) stoi(a)
#define str(a) to_string(a)
#define bisect_left(vector,a) (lower_bound(vector.begin(),vector.end(),a)-vector.begin())
#define bisect_right(vector,a) (upper_bound(vector.begin(),vector.end(),a)-vector.begin())
#define defA(a,b,c) A(a,L(b,c));


int main(void) {
    int n;
    cin>>n;
    A a = defA(n,2,0);
    for(int i=0  ;i<n  ;i++){
        cin>>a[i][0];
        a[i][1]=i;
    }
    sorted(a);
    for(int i=0  ;i<n  ;i++){
        cout<<a[i][1]+1<<" ";
    }

}


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

int main() {
  int n; cin >> n;
  vector<ll> a(n), c(n);
  rep(i,n) {
    cin >> a[i];
    if (i==0) {c[i] = a[i]; continue;}
    c[i] = c[i-1] + a[i];
  }
  ll ans = 1e15+5;
  rep(i,n-1) {
    ll snk = c[i], ara = c[n-1] - c[i];
    ans = min(abs(snk - ara), ans);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 6428
#include <iostream>
#include <vector>
#include <algorithm>
  
int main()
{
    static const int kCountMax = 3;
    std::vector<int> v(kCountMax);
    for (int i = 0; i < kCountMax; ++i) {
        std::cin >> v[i];
    }
    sort(v.begin(), v.end());
    for (int i = 0; i < kCountMax; ++i) {
        std::cout << (i ? " " : "") << v[i];
    }
    std::cout << std::endl;
    return 0;
}

Measured memory_bytes: 1208
#include<bits/stdc++.h>
//#include <iostream>
//#include <iomanip>
//#include <vector>
//#include <cmath>
//#include <algorithm>
using namespace std;


#define F first
#define PB push_back
#define MP make_pair

typedef long long ll;

ll p = pow(10, 9) + 7;




int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    vector<int> al(26);
    string s;
    cin >> s;
    for(int i = 0; i < s.length(); i++)
    {
        al[s[i] - 97]++;
    }
    bool yap = true;
    for(int i = 0; i < 26; i++)
    {
        if(al[i] % 2 != 0) yap = false;
    }
    if(yap)
    {
        cout << "Yes" << endl;
    }else{cout << "No" << endl;}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int x,ans=0; cin >> x;
  for(int i=1;i<=x;i+=2) {
        int count=0;
        for(int j=1;j<=i;j++)  if(i%j==0) count++;
        if(count==8) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define N 200005
#define p 1000000007
using namespace std;

int n,m,ct,tmp_ct,x[N],y[N],a[N];
pair <int,int>P[N];
long long sum[N];
vector<int>Ve[N];

inline int lowbit(int x){return x&-x;}

inline void add(int x,int y){for(int i=x;i<=tmp_ct+1;i+=lowbit(i))(sum[i]+=y)%=p;}

inline long long ask(int x){long long tmp=0;for(int i=x;i;i-=lowbit(i))(tmp+=sum[i])%=p;return tmp;}

int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
		scanf("%d",&x[i]);
	for(int i=1;i<=m;i++)
		scanf("%d",&y[i]);
	for(int i=1;i<=n;i++)
	{
		if(x[i]<y[1]||x[i]>y[m])continue;
		int pos=upper_bound(y+1,y+1+m,x[i])-y;
		P[++ct]=make_pair(y[pos]-x[i],x[i]-y[pos-1]);
	}
	sort(P+1,P+1+ct);
	for(int i=1;i<=ct;i++)
		a[2*i-1]=P[i].first,a[2*i]=P[i].second;
	sort(a+1,a+1+2*ct);
	tmp_ct=unique(a+1,a+1+2*ct)-a-1;
	for(int i=1;i<=ct;i++)
	{
		P[i].first=lower_bound(a+1,a+1+tmp_ct,P[i].first)-a;
		P[i].second=lower_bound(a+1,a+1+tmp_ct,P[i].second)-a;
		Ve[P[i].first].push_back(P[i].second);
	}
	add(1,1);
	for(int i=1;i<=tmp_ct;i++)
	{
		int las=0;
		for(vector<int>::reverse_iterator it=Ve[i].rbegin();it!=Ve[i].rend();it++)
			if(*it!=las)add(*it+1,ask(*it)),las=*it;
	}
	printf("%lld",ask(tmp_ct+1));
}


Measured memory_bytes: 12288
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair<int, int> pi;
typedef vector<int> vi;
template<class Key, class Compare = less<Key>>
using Tree = tree<Key, null_type, Compare, rb_tree_tag, tree_order_statistics_node_update>;






void Main() {
  int n;
  string a, b, c;
  cin >> n >> a >> b >> c;
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    int cnt[26] = {};
    ++cnt[a[i]-'a'];
    ++cnt[b[i]-'a'];
    ++cnt[c[i]-'a'];
    int res = 2;
    for (int j = 0; j < 26; ++j) {
      if (cnt[j] == 3) {
        res = min(res, 0);
      }
    }
    for (int j = 0; j < 26; ++j) {
      if (cnt[j] == 2) {
        res = min(res, 1);
      }
    }
    ans += res;
  }
  cout << ans << '\n';
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  #ifdef _DEBUG
//  freopen("in.txt", "r", stdin);
//  freopen("out.txt", "w", stdout);
  #endif
  Main();
  return 0;
}


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

using namespace std;

int main(){
	long long a , b , c , k , ans = 0;
	cin>>a>>b>>c>>k;
	if(k >= a) ans += a , k -= a;
	else ans += k , k = 0;
	if(k > 0){
		if(k >= b) k -= b;
		else k = 0;
		if(k > 0){
			if(k > c) ans -= c;
			else ans -= k;
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 3632
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    char a,b,c,d,e,f;
    cin>>a>>b>>c>>d>>e>>f;
    if(a==f && b==e && c==d){cout<<"YES"<<endl;return 0;}
    else{cout<<"NO"<<endl;return 0;}
}


Measured memory_bytes: 256
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;

class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line;

        while (!(line = br.readLine()).equals("0")) {
            int n = Integer.parseInt(line);
            int[] before = new int[n];
            int[] after = new int[n];
            String[] input = br.readLine().split(" ");
            for (int i = 0; i < n; i++) {
                before[i] = Integer.parseInt(input[i]);
            }

            int phase = 0;
            while (true) {
                for (int i = 0; i < n; i++) {
                    int now = before[i];
                    int count = 0;
                    for (int j = 0; j < n; j++) {
                        if (now == before[j])
                            count++;
                    }
                    after[i] = count;
                }

                if (Arrays.equals(before, after)) {
                    break;
                } else {
                    before = after.clone();
                }

                phase++;
            }

            System.out.println(phase);
            for (int i = 0; i < n; i++) {
                if (i == 0)
                    System.out.print(after[i]);
                else
                    System.out.print(" " + after[i]);
            }
            System.out.println();
        }
    }
}


Measured memory_bytes: 25508
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b;
  cin>>a>>b;
  if(a%3==0||b%3==0||(a+b)%3==0){
    cout<<"Possible"<<endl;
  }
  else{
    cout<<"Impossible"<<endl;
  }
}


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

int main(int argc, const char * argv[]) {
    int N,K;
    cin >> N >> K;
    long long answer;
    answer = K;
    for(int i=0;i<N-1;i++){
        answer *= (K-1);
    }
    cout << answer << endl;
    
    return 0;
}


Measured memory_bytes: 256
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
    static final Scanner     sc = new Scanner(System.in);
    static final PrintStream so = System.out;
    public static void main(String[] args) {
        int N = nint();
        int M = nint();
        int K = nint();
        
        for (int r = 0; r <= N; r++) {
            for (int c = 0; c <= M; c++) {
                int numBlack = (N-r)*c + (M-c)*r;
                if (numBlack == K) {
                    so.println("Yes");
                    return;
                }
            }
        }
        so.println("No");
    }
    private static int nint() {
        return sc.nextInt();
    }
}


Measured memory_bytes: 23892
import sys
from collections import deque

H, W = map(int, sys.stdin.readline().strip().split())
grid = [[]] * H
movable = 0
for i in range(H):
    grid[i] = list(sys.stdin.readline().strip())
    for j in grid[i]:
        if j == ".":
            movable += 1
# print(movable)

q = deque()
q.append((0, 0, 0))
visited = set()
goal = False
# BFS
while q:
    x, y, c = q.popleft()
    for dx, dy in ((-1, 0), (0, 1), (1, 0), (0, -1)):
        if 0 <= x+dx < W and 0 <= y+dy < H:
            if x+dx == W-1 and y+dy == H-1:
                goal = True
                c += 1
                break
            elif grid[y+dy][x+dx] == "." and (x+dx, y+dy) not in visited:
                q.append((x+dx, y+dy, c+1))
                visited.add((x+dx, y+dy))

    if goal:
        break

if goal:
    print(movable - (c + 1))
else:
    print(-1)

Measured memory_bytes: 3700
#include <iostream>
using namespace std;
int main(void){
    int a,b,c,k;
    cin>>a>>b>>c>>k;
    if(a>=k){
        cout<<k<<endl;
    }
    else if(k<=a+b)cout<<a<<endl;
    else cout<<a-(k-a-b)<<endl;
}


Measured memory_bytes: 3624
<?php
$target = trim(fgets(STDIN));
list($min, $max) = explode(' ', trim(fgets(STDIN)));

$result = '';
for($i=$min; $i<=$max; $i++){
    if($i % $target == 0){
        $result = 'OK';
        break;
    }
}

if($result == 'OK'){
    echo $result;
} else {
    echo 'NG';
}


Measured memory_bytes: 16188
#include <iostream>
#include <string>

using namespace std;

int main(void) {
  string s; 
  int w;

  cin >> s;
  cin >> w;

  int i = 0;

  while (i * w < s.size()) {
    cout << s[i * w];
    i++;
  }

  cout << endl;

  return 0;
}

Measured memory_bytes: 256
//84104971101048411497 - Can you guess what does this mean?
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef complex<double> point;
#define mapii map<int, int>
#define debug(a) cout << #a << ": " << a << endl
#define debuga1(a, l, r) fto(i, l, r) cout << a[i] << " "; cout << endl
#define fdto(i, r, l) for(int i = (r); i >= (l); --i)
#define fto(i, l, r) for(int i = (l); i <= (r); ++i)
#define forit(it, var) for(__typeof(var.begin()) it = var.begin(); it != var.end(); it++)
#define forrit(rit, var) for(__typeof(var.rbegin()) rit = var.rbegin(); rit != var.rend(); rit++)
#define ii pair<int, int>
#define iii pair<int, ii>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define maxN 205
#define oo 1000000000000000007LL
#define sz(a) (int)a.size()

const double PI = acos(-1.0);

double fRand(double fMin, double fMax)
{
    double f = (double)rand() / RAND_MAX;
    return fMin + f * (fMax - fMin);
}

template <class T>
T min(T a, T b, T c) {
    return min(a, min(b, c));
}

template <class T>
T max(T a, T b, T c) {
    return max(a, max(b, c));
}

int n, r[maxN], b[maxN];

int main () {
    scanf("%d", &n);
    fto(i, 0, 2*n-1) r[i] = b[i] = -1;
    fto(i, 1, n) {
        int x, y; scanf("%d%d", &x, &y);
        r[x] = y;
    }
    fto(i, 1, n) {
        int x, y; scanf("%d%d", &x, &y);
        b[x] = y;
    }

    int ans = 0;
    fdto(i, 2*n-1, 0) {
        if (r[i] != -1) {
            int minB = -1, posB = 0;
            fto(j, i+1, 2*n-1) {
                if (b[j] > r[i] && (minB == -1 || b[j] < minB)) {
                    minB = b[j];
                    posB = j;
                }
            }
            if (minB != -1) {
                ++ans;
                b[posB] = -1;
            }
        }
    }

    cout << ans;

    return 0;
}


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

int main(){
  int a[3], min=1000000;
  cin >> a[0] >> a[1] >> a[2];
  
  for(int i=0; i<3; i++){
    for(int j=0; j<3; j++){
      if (a[i] + a[j] <= min && i != j){
        min = a[i] + a[j];
      }
    }
  }
  
  cout << min << endl;
  
  
  
}

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

int main() {
	int N, M; 
	scanf("%d %d", &N, &M);
	fflush(stdout);
	int ans = 0;
	for (int i = 0; i < N; ++i) {
		int a;
		printf("lst %d\n", i);
		fflush(stdout);
		scanf("%d", &a);
		ans += (a*(a - 1));
		for (int j = 0; j < a; ++j) {
			int b;
			scanf("%d", &b);
		}
	}
	printf("ans %d\n", ans);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 3208
use proconio::{fastout, input};

#[fastout]
fn main() {
    input!(n: [isize; 5], k: usize);

    let mut is_ = false;
    for v in &n {
        for v2 in &n {
            if (v - v2).abs() as usize > k {
                is_ = true;
            }
        }
    }

    println!("{}", if is_ { ":(" } else { "Yay!" });
}


Measured memory_bytes: 2172
#include <bit>
#include <bitset>
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <iomanip>

typedef long double ld;
typedef long long ll;

using namespace std;

ll MOD = ((ll)1e9 + 7);

/* TEMPLATE ENDS HERE */

#define MAXN (1 << 10)

int a[MAXN][MAXN];

void solve(int l, int r, int color) {
	if (l >= r) {
		return;
	}
	int m = (l + r) / 2;
	for (int i1 = l; i1 <= m; i1++) {
		for (int i2 = m + 1; i2 <= r; i2++) {
			a[i1][i2] = color;
			a[i2][i1] = color;
		}
	}
	solve(l, m, color + 1);
	solve(m + 1, r, color + 1);
}

int main() {
	cout << fixed << setprecision(12);	
	int n;
	cin >> n;
	solve(0, n - 1, 1);
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
	return 0;
}


struct mod {
	ll x;

	mod(ll tx = 0) {
		x = tx;
	}
	
	mod& operator=(const ll & tx) {
		x = tx;
		return *this;
	}
	
	mod& operator=(const mod & m2) {
		x = m2.x;
		return *this;
	}

	mod operator+(const mod& m2) const {
		return mod((x + m2.x) % MOD);
	}

	mod& operator+=(const mod& m2) {
		x += m2.x;
		x %= MOD;
		return *this;
	}

	mod operator-(const mod & m2) const {
		return mod((x - m2.x + MOD) % MOD);
	}

	mod& operator-=(const mod & m2) {
		x -= m2.x;
		x = (x + MOD) % MOD;
		return *this;
	}

	mod operator*(const mod & m2) const {
		return mod((x * m2.x) % MOD);
	}

	mod& operator*=(const mod & m2) {
		x *= m2.x;
		x %= MOD;
		return *this;
	}

	mod mypow(ll k) const {
		mod ret = 1;
		mod cur = x;
		while (k) {
			if (k & 1) {
				ret *= cur;
			}
			cur *= cur;
			k >>= 1;
		}
		return ret;
	}

	mod inv() const {
		return mypow(MOD - 2);
	}

	mod operator/(const mod & m2) const {
		return (*this) * m2.inv();
	}

	mod& operator/=(const mod & m2) {
		x *= m2.inv().x;
		x %= MOD;
		return *this;
	}

	bool operator<(const mod & m2) const {
		return x < m2.x;
	}
};

ostream &operator<<(ostream & os, const mod & m) {
	return os << m.x;
}


Measured memory_bytes: 5620