akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define TRACE(x) x
#define WATCH(x) TRACE(cout << #x" = " << x << endl)
#define WATCHR(a, b) TRACE(for (auto it=a; it!=b;) cout << *(it++) << " "; cout << endl)
#define WATCHC(V) TRACE({cout << #V" = "; WATCHR(V.begin(), V.end());})

#define all(x) (x).begin(), (x).end()

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    int A, B, C;
    cin >> A >> B >> C;

    cout << B + min(C, A + B + 1) << "\n";

    return 0;
}



Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

namespace ALDS1_6_D {
    public static class Problem {
        public static int GetMinCost(this int[] source) {
            int n = source.Length;
            int minCost = 0;
            
            Dictionary<int, int> valueToIndex = Enumerable.Range(0, n)
                .ToDictionary(i => source[i], i => i);
            
            Array.Sort(source);

            int minValue = source[0];
            bool[] used = new bool[n];
            
            for(int i = 0; i < n; i++) {
                if (used[i])
                    continue;

                int minValueInGroup = source[i];
                int curPosition = valueToIndex[minValueInGroup];
                int sumOriginal = 0;
                int sumReplace = (minValue + minValueInGroup) * 2;

                while (curPosition != i) {
                    used[curPosition] = true;
                    int nextValue = source[curPosition];
                    sumOriginal += nextValue + minValueInGroup;
                    sumReplace += nextValue + minValue;
                    curPosition = valueToIndex[nextValue];
                }
                minCost += Math.Min(sumOriginal, sumReplace);
            }
            return minCost;
        }
    }

    class Program {
        static void Main(string[] args) {
            Console.ReadLine();
            int[] input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            Console.WriteLine(input.GetMinCost());
        }
    }
}

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

int main() {
    int N;
    
    cin >> N;
    vector<int> vec(N);

    for(int i=0; i<N; i++){
        cin >> vec.at(i);
    }
    
    sort(vec.begin(), vec.end());
    
    int S=0;
    
    for(int i=0; i<N-1; i++){
        if(vec.at(i)-vec.at(i+1)==0){
            S++;
        }
    }
    
    if(S==0){
        cout << "YES" << endl;
    }
    else{
        cout << "NO" << endl;
    }
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define ll long long
using namespace std;
signed main() {
  ll a, b, c, n;
  cin >> a >> b >> c >> n;

  for (int i = 0; i < n; i++) {
    if (c <= b) {
      c *= 2;
    }else if (b <= a) {
      if (b*2 >= c) {
        c *= 2;
      }else {
        b *= 2; 
      }
    }
  }

  if (a < b && c > b) {
    cout << "Yes\n";
  }else {
    cout << "No\n";
  }

  return 0;
}


Measured memory_bytes: 3604
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <algorithm>
#include <random>
#include <chrono>
#include <iomanip>
#define lint long long int
#define FOR(x, to) for(int x=0; x<(int)(to); x++) // for簡略表記
#define DUMP(ar) for(int loop=0; loop<(int)ar.size(); loop++) cout << "[" << loop << "]:" << ar[loop] << endl // 配列一覧表示
#define DUMPL(ar) for(int loop=0; loop<(int)ar.size(); loop++) { cout << ar[loop]; if(loop<(int)ar.size()-1) cout << ' '; } cout << endl; // 配列一行一覧表示
#define COUT(x) cout << x << endl // 単要素出力
#define ALL(ar) ar.begin(), ar.end() // コンテナの全要素
#define LOOPD(i) cout << "ループ[" << i << "]回目---------------" << endl // ループ回数デバグ
using namespace std;
// cout << fixed << setprecision(4) で小数点以下4桁の桁そろえ
// cout << setw(5) << ... で表示形式を5桁に設定 5桁未満なら頭に空白がつく 5桁越なら先頭から5桁まで
// cout << setw(5) << setfill('0') << ... で空白部分の埋め文字に5を使う
// getline(cin, [変数]); で空白などを含む入力の受け取り(行ごとの受け取り)
// cin >> ws; でそこまでにストリームに残されたホワイトスペースを取り除く(=以降のgetlineの有効化)

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

    string s;
    cin >> s;
    int cnt = 0;
    for(int i=0; i<(int)s.size()/2; i++){
        if(s[i] != s[s.size()-i-1]) cnt++;
    }

    COUT(cnt);

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
//typedef vector<unsigned int>vec;
typedef vector<ll>vec;
typedef vector<vec> mat;
typedef vector<vector<int>> Graph;

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
//const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
//const ll  MOD = 1000000007;
const ll MOD = 998244353;
const double PI = acos(-1.0);
const double EPS = 1e-10;

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; }
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

class UnionFind{
public:
    //親の番号，親の場合-(その集合のサイズ)
    vector<int> Parent;
    
    UnionFind(int N){
        Parent = vector<int>(N,-1);
    }
    
    //Aがどのグループに属しているか調べる
    int root(int A){
        if(Parent[A]<0) return A;
        return Parent[A] = root(Parent[A]);
    }

    //自分のいるグループの頂点数を調べる
    int size(int A){
        return -Parent[root(A)];
    }

    bool unite(int A, int B){
        //root(A)にroot(B)をくっつける
        A = root(A);
        B = root(B);
        if(A==B) return false;//すでにくっついてる

        //大きい方に小さい方をくっつける
        if(size(A) < size(B)) swap(A, B);

        Parent[A] += Parent[B];
        Parent[B] = A;

        return true;
    }
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<pair<int,int>> A(N), B(N);
    REP(i,N){
        cin >> A[i].first;
        A[i].second = i;
    }
    REP(i,N){
        cin >> B[i].first;
        B[i].second = i;
    }
    sort(A.begin(), A.end());
    sort(B.begin(), B.end());
    UnionFind uf(N);
    REP(i,N){
        if(A[i].first > B[i].first){
            cout << "No" << endl;
            return 0;
        }
        uf.unite(A[i].second, B[i].second);
    }
    set<int> st;
    REP(i,N) st.insert(uf.root(i));
    if(st.size() >= 2){
        cout << "Yes" << endl;
        return 0;
    }
    REP(i,N-1){
        if(B[i].first >= A[i+1].first){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 2176
/*

*/
#include<bits/stdc++.h>
using namespace std;


#define all(v)           ((v).begin()), ((v).end())
#define sz size()
#define clr(v,d)         memset(v,d,sizeof(v))
#define lp(i, n)         for(int i=0;i<(int)(n);++i)
#define lpi(i, j, n)     for(int i=(j);i<(int)(n);++i)
#define lpd(i, j, n)     for(int i=(j);i>=(int)(n);--i)
#define sci(a)	scanf("%d",&a)
#define scii(a, b)	scanf("%d%d",&a, &b)
#define pri(a)	printf("%d\n",a)



typedef long long ll;

const int maxn = 500500;

bool ad[1005][1005];

vector<int> adj[maxn];

int cnt[1005][2];
int col[1005];
int comps;

bool dfs(int u, int cl){
	col[u] = cl;
	++cnt[comps][cl-1];
	for (int v : adj[u]) {
		if (col[v] == cl)	return 0;
		if (!col[v]){
			if(!dfs(v, 3 - cl)) return 0;
		}
	}
	return 1;
}

int dp[1005][1005];

int main(){
	ios::sync_with_stdio(0);
	int n, m, u, v;
	cin >> n >> m;
	lp(i, m){
		cin >> u >> v;
		--u; --v;
		ad[u][v] = ad[v][u] = 1;
	}
	lp(i, n) lp(j, n) if (i != j && !ad[i][j])
		adj[i].push_back(j);
	lp(i, n)if(!col[i]){
		if (!dfs(i, 1)) {
			cout << "-1";
			return 0;
		}
		comps++;
	}
	dp[0][0] = 1;
	lp(i, comps) lp(j, n) if (dp[i][j]){
		dp[i + 1][j + cnt[i][0]] = dp[i + 1][j + cnt[i][1]] = 1;
	}
	int ret = n*n;
	lp(i, n + 1) if (dp[comps][i])
		ret = min(ret, i*(i - 1) / 2 + (n - i)*(n - i - 1) / 2);
	cout << ret;
}

Measured memory_bytes: 17408
import java.util.*;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long n = sc.nextLong();
    String res = func(n);
    System.out.println(res);
  }
  
  public static String func(long n) {
    n--;
    if(n <= 25 && 0 <= n)
      return Character.toString((char)(97 + n));
    String res = func(n/26) + ((char)(97 + (n%26)));
    
    return res;
  }
}


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

int main() {
  int n;
  cin >> n;
  vector<long>a(n);
  vector<long>mp(n,0);
  vector<long>pm(n,0);
  cin >> a[0];
  pm[0] += a[0];
  mp[0] -= a[0];
  for(int i = 1;i < n;i++){
    cin >> a[i];
    if(i%2 == 0){
      pm[i] = pm[i-1]+a[i];
      mp[i] = mp[i-1]-a[i];
    }
    else{
      pm[i] = pm[i-1]-a[i];
      mp[i] = mp[i-1]+a[i];
    }
  }
  cout << pm[n-1] << " ";
  for(int i = 1;i < n;i++){
    if(i%2 == 0){
      cout << mp[i-1]+pm[n-1]-pm[i-1];
    }
    else{
      cout << pm[i-1]+mp[n-1]-mp[i-1];
    }
    if(i != n-1) cout << " ";
  }
  cout << "" << endl;
}


Measured memory_bytes: 3712
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

zan = a[0]
kill = 0
for i in range(n):
    kill_first_town = min(zan, b[i])
    if kill_first_town == zan:
        kill_second_town = min(b[i]-zan, a[i+1])
    else:
        kill_second_town = 0
    zan = a[i+1] - kill_second_town    
    kill += kill_first_town + kill_second_town
print(kill)

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

int main(){
int X, Y, Z; cin >> X >> Y >> Z;

int ans = 0;
int room = X - Z;
while (room >= 0) {
    if (room >= Y + Z) {
        ans++;
    }
    room -= Y + Z;
}

cout << ans << endl;

}


Measured memory_bytes: 256
// g++ -std=c++11 temp.cpp
#include <bits/stdc++.h>
using namespace std;

#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) FOR(i,0,n)
#define EACH(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;

#define INF INT_MAX/3

#define MAX_N 1000

int n;
int d[10][10];

int main(){
	while(1){
		cin>>n;
		if(n==0) break;
		REP(i,10)REP(j,10)d[i][j]=INF;
		REP(i,10)d[i][i]=0;
		int v = 0;
		REP(i,n){
			int a,b,c;
			cin>>a>>b>>c;
			v = max(v,max(a,b));
			d[a][b]=c; d[b][a]=c;
		}
		v++;

		REP(k,v)REP(i,v)REP(j,v) d[i][j]=min(d[i][j], d[i][k]+d[k][j]);
		int resa = 0, resb = INF;
		REP(i,v){
			int sum = 0;
			REP(j,v) sum+=d[i][j];
			if(resb>sum){
				resa=i; resb=sum;
			}
		}
		cout<<resa<<" "<<resb<<endl;
	}

	return 0;
}

Measured memory_bytes: 3108
#include <algorithm>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <utility>
#include <vector>

using namespace std;

int main()
{
    int r, D, x_2000;
    cin >> r >> D >> x_2000;
    int x = x_2000;
    for (int i = 0; i < 11; i++)
    {
        if (i > 0)
            cout << x << endl;
        x = r * x - D;
    }
    return 0;
}

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

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

  int a[101], b[101], c[101], d[101];
  for (int i = 0; i < N; i++) cin >> a[i] >> b[i];
  for (int i = 0; i < N; i++) cin >> c[i] >> d[i];

  pair<int, int> red[101];
  pair<int, int> blue[101];

  for (int i = 0; i < N; i++) {
    red[i].first = b[i];
    red[i].second = a[i];
    blue[i].first = c[i];
    blue[i].second = d[i];
  }
  sort(red, red + N);
  sort(blue, blue + N);

  int ans = 0;
  int redcount[101] = {0};

  for (int i = 0; i < N; i++) {
    for (int j = N-1; j >= 0; j--) {
      if (red[j].second < blue[i].first and red[j].first < blue[i].second and redcount[j] == 0) {
        ans++;
        redcount[j]++;
        break;
      }
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#coding:utf-8
#!/usr/bin/python

X=[]
N=int(raw_input())
X=map(int,raw_input().split())

kotae=0
for p in range(min(X),max(X)+1):
    karioki=0
    for i in range(N):
        karioki+=pow(X[i]-p,2)
    if(p==min(X)):
       kotae=karioki
    elif(kotae>karioki):
         kotae=karioki
print kotae

Measured memory_bytes: 2568
#pragma region
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <list>
#include <iomanip>
#include <cstdint>
#include <cstdlib>

using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define rrep(i, s) for (int(i) = (s) - 1; (i) >= 0; --(i))
#define all(x) x.begin(),x.end()
#pragma endregion


int main()
{
	ll n; cin >> n;
	for (ll i = 1; i <= 3500; ++i)
	{
		for (ll j = 1; j <= 3500; ++j)
		{
			ll k = 4 * i*j - j * n - i * n;
			if (k <= 0)continue;
			if ((i*j*n) % k == 0)
			{
				cout << i << " " << j << " " << (i*j*n) / k << endl;
				return 0;
			}
		}
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int vis[100002]={0};
vector<int> topo;
vector<int> adj[100002];

void dfs(int node,int par)
{
	for(int u:adj[node])
	{
		if(!vis[u])
		dfs(u,node),vis[u]=true;
	}
	
	topo.push_back(node);
}

int main() {
	int n,m;
	cin >> n >> m;
	
	int in[n+1];
	
	memset(in,0,sizeof in);
	
	for(int i=0;i<m;i++)
	{
		int u,v;
		cin >> u >> v;
		adj[u].push_back(v);
		in[v]++;
	}
	
	for(int i=1;i<=n;i++)
	{
		if(in[i]==0)
		{
			vis[i]=true;
			dfs(i,-1);
		}
	}
	int dp[n+1]={0};
	memset(dp,0,sizeof dp);
	
	int ans=0;
	
	reverse(topo.begin(),topo.end());
	
	for(int i=0;i<topo.size();i++)
	{
		//cout << topo[i] << endl; 
		for(int u:adj[topo[i]])
		{
			dp[u]=max(dp[u],dp[topo[i]]+1);
			ans=max(ans,dp[u]);
		}
	}

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

Measured memory_bytes: 11772
#include<bits/stdc++.h>
using namespace std;
//#include<ext/rope>
//using namespace __gnu_cxx
//#include<ext/pb_ds/priority_queue.hpp>
//using namespace __gnu_pbds;
#define lowbit(x) (x&-x)
#define pb push_back
#define empb emplace_back
#define all(x) (x).begin(),(x).end()
#define clr(a,b) memset(a,b,sizeof(a))
#define caze(T) for(cin>>T;T;T--)
#define inf (1<<29)
#define Endl ('\n')
#define fi first
#define se second
#define db double
#define ldb long double
#define ll long long
#define pii pair<int,int>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define pll pair<ll,ll>
#define ull unsigned long long
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
inline char nc() {
	#define SZ 1000000
	static char buf[SZ], *p1, *p2;
	return p1==p2&&(p2=(p1=buf)+fread(buf,1,SZ,stdin),p1==p2)?EOF:*p1++;
}
template<typename T>
inline int scan(T &x) {
	char c, sign=1; 
	while(!isdigit(c=nc())&&c!=EOF)if(c=='-')sign*=-1;
	if(c==EOF) return EOF;
	for(x = 0; isdigit(c); c = nc())
		x = (x<<1) + (x<<3) + (c&15);
	return x *= sign, 1;
}
template<typename T, typename...Args>
inline int scan(T &x, Args&...args) {
	return scan(x), scan(args...);
}
int main()
{IOS;
	int n,mx=0,m=0;cin>>n;
	vector<int>x(n),y(n);
	vector<int>ans;
	for(int i=0;i<n;++i)
		cin>>x[i]>>y[i],mx=max(mx,abs(x[i])+abs(y[i]));
	for(int i=1;i<n;++i)
		if(((x[0]+y[0])^(x[i]+y[i]))&1)
			return cout<<-1<<Endl,0;
	if(!((x[0]^y[0])&1)) ans.pb(1);
	while((1LL<<m)<=mx) ans.pb(1<<m++);
	reverse(all(ans));
	cout<<(m=ans.size())<<Endl;
	for(int i=0;i<m;++i)
		cout<<ans[i]<<" \n"[i==m-1];
	string ch="LRDU";
	function<void(int,int)>go=[&](int x,int y)
	{
		string s(m,'a');
		int a[2]={x,y};
		for(int i=0;i<m;++i)
		{
			int c=0,d=0,t;
			if(abs(a[1])>abs(a[0])) c=1;
			if(a[c]>0) d=1;
			s[i]=ch[c<<1|d];
			a[c]=d?a[c]-ans[i]:a[c]+ans[i];
		}
		cout<<s<<Endl;
	};
	for(int i=0;i<n;++i)
		go(x[i],y[i]);
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<math.h>
#include<cstdio>
#include<ctype.h>
#include<stdio.h>
#include<set>
#include<vector>
#include<map>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<numeric>
#include<string>
typedef long long ll;
using namespace std;

ll gcd(ll a, ll b){
if(a<b){return gcd(b,a);}
else if(a%b){return gcd(b,a%b);}
else{return b;}
}
int main(){
  ll N,X;
  cin>>N>>X;
  ll m[N];
  ll sum=0;
  for(ll i=0; i<N; ++i){
    cin>>m[i];
    }
  for(ll i=0; i<N; ++i){
  sum+=m[i];
  }
  sort(m,m+N);
  cout<<N+(X-sum)/m[0]<<endl;
  }
  
  
  

  
  

 


Measured memory_bytes: 256
n, k = list(map(int, input().split()))
h_li = []
for i in range(n):
    h = int(input())
    h_li.append(h)
h_li.sort()
d = 10 ** 10
m = k - 1
while m < n:
    if d > (h_li[m] - h_li[m - k + 1]):
        d = h_li[m] - h_li[m - k + 1]
    m += 1
print(d)


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


int main(){
    string s;
    cin >> s;
    int n = s.size();
    for(int bit = 0; bit < (1 << n-1); bit++){
        int sum = (s[0] - '0');
        string op = "";
        for(int i = 0; i < n-1; i++){
            if(bit & (1<<i)){
                sum += (s[i+1] - '0');
                op += "+";
            }else{
                sum -= (s[i+1] - '0');
                op += "-";
            }
        }
        if(sum == 7){
            for(int i = 0; i < n-1; i++){
                cout << s[i] << op[i];
            }
            cout << s[n-1] << "=7\n";
            return 0;
        }
    }
    return 0;


}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
int main(){
  int i,c=0,a,v=0,b;
  char s[4];
   scanf("%s",&s);
  
  if((s[0]==s[1]&&s[2]==s[3]&&s[0]!=s[2])
     ||(s[0]==s[2]&&s[1]==s[3]&&s[0]!=s[1])
     ||(s[0]==s[3]&&s[1]==s[2]&&s[0]!=s[1]))
    printf("Yes");
  /*else if(s[0]==s[1]==s[2]==s[3])
    printf("No");*/
  else
    printf("No");
}

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

/* 大文字を小文字に変換 */
char tolower(char c) {return (c + 0x20);}
/* 小文字を大文字に変換 */
char toupr(char c) {return (c - 0x20);}

// if('A'<=s[i] && s[i]<='Z') s[i] += 'a'-'A';

/*
string s = "abcdefg"
s.substr(4) "efg"
s.substr(0,3) "abc"
s.substr(2,4) "cdef"

// イテレータ要素のインデックス
distance(A.begin(), itr);
*/

const int INF = pow(10,9);
const int MAX_N = 12;

int main()
{
    int N, M, X; cin >> N >> M >> X;
    // bitset<N> S(0);
    vector<int> A[N];
    rep(i,N){
        int c; cin >> c; A[i].push_back(c);
        rep(_,M){
            int Ai; cin >> Ai; A[i].push_back(Ai);
        }
    }
    /*
    rep(i,N){
        rep(j,M+1){
            cout << A[i][j] << " ";
        }
        cout << endl;
    }
    */
    int mincost = INF;
    for(int i=0; i<pow(2,N); i++){
        int cost = 0;
        bitset<MAX_N> S(i); // 使用する参考書
        int Skill[M];
        rep(j,M) Skill[j] = 0;    // 初期化
        rep(j,N){
            if(S.test(j)){
                cost += A[j][0];
                rep(k,M){
                    Skill[k] += A[j][k+1];
                }
            }
        }
        bool isComp = true;
        rep(j,M){
            if(Skill[j] < X) isComp = false;
        }
        // cout << cost << endl;
        if(isComp){
            if(mincost > cost) mincost = cost;
        }
    }
    if(mincost == INF) cout << -1 << endl;
    else cout << mincost << endl;
}

Measured memory_bytes: 4108
n = int(input())
ans = 0
for i in range(1,int(n**0.5) + 1):
    if n % i == 0:
        a = n//i - 1
        b = i - 1
        #print("{} {}".format(b,a))
        if a != 0 and (n // a) == n % a:
            ans += a
        if b != 0 and (n // b) == n % b:
            ans += b
print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int h1,m1,h2,m2,k,t1,t2;
int main(){
	#ifndef DavidLaptop
		#ifdef FILIN
			freopen(FILIN,"r",stdin);
			freopen(FILOUT,"w",stdout);
		#endif
	#endif
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>h1>>m1>>h2>>m2>>k;
	t1=h1*60+m1;
	t2=h2*60+m2;
	cout<<max(t2-t1-k,0)<<endl;
	return 0;
}



Measured memory_bytes: 3692
n = int(input())
 
x0, y0, t0 = 0, 0, 0
 
for _ in range(n):
  t, x, y = map(int, input().split())
  if abs(x-x0) + abs(y-y0) > t-t0 or (x+y)%2 != t%2:
    status = "No"
    break
  else:
    status = "Yes"
    t0, x0, y0 = t, x, y
    
print(status)

Measured memory_bytes: 3064
//ahmat
#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(),x.end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<" = "<<(x)<<endl
#define debug_arr(x) {cout<<#x<<":";for(auto a:x) cout<<a<<" ";cout<<endl;}
using vi=vector<int>;
using pii=pair<int,int>;
using ll=long long;
using ull=unsigned long long;
const int inf=0x3f3f3f3f;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    //
    string s;
    cin>>s;
    long k=count_if(all(s),[](char c){return c=='o';});
    cout<<((k+(15-s.size()))>=8? "YES":"NO")<<endl;
}

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

constexpr int inf = 0x3f3f3f3f;
constexpr ll linf = 0x3f3f3f3f3f3f3f3fLL;

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

    int x; cin >> x;
    cout << (x < 1200 ? "ABC" : "ARC") << endl;
    return 0;
}


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



int main(){
	int N,i,R,B;
  	cin>>N;
  	string s;
  	R = 0;
  	B = 0;
  		cin>>s;
  for(i = 0; i < N; i++){
  	      	if(s[i]=='R'){
        	R++;
        }else if(s[i]=='B'){
        	B++;
        }
  }
  	if(R>B){
    	printf("Yes");
    }else{
    	printf("No");
    }
  	
  
    
    
  	return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#define ll long long
#define rep(i,l,r) for(ll i=(l);i<(r);i++)
#define max(p,q) ((p)>(q)?(p):(q))
#define min(p,q) ((p)<(q)?(p):(q))
#define chmax(a,b) ((a)=(a)>(b)?(a):(b))
#define chmin(a,b) ((a)=(a)<(b)?(a):(b))
#define abs(p) ((p)>=(0)?(p):(-(p)))
int cmp(const void *a, const void *b);
//your code here!

int main(void){
    ll N, A, B;
    scanf("%lld %lld %lld", &N, &A, &B);
    printf("%lld\n", min(N*A, B));
    return 0;
}

int cmp(const void *a, const void *b){
    ll A=*(ll *)a, B=*(ll *)b;
    if(A==B)return 0;
    else return A>B ? 1:-1;//昇順ソート
}


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

int n;
double p[3300], dp[3300];

int main() {
  cin >> n;
  for (int i = 0; i < n; i++) cin >> p[i];

  dp[0] = 1;
  for (double prob : p) {
    for (int j = n; 0 <= j; j--) {
      dp[j] = dp[j] * (1 - prob) + dp[j - 1] * prob;
    }
  }
  double ans = 0;
  for (int i = (n + 1) / 2; i <= n; i++) {
    ans += dp[i];
  }

  printf("%.10f\n", ans);
  return 0;
}

Measured memory_bytes: 3832
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
	int n,m,sum=0;
	cin >> n;
	vector<int> t(n, 0);
	for (int i = 0; i < n; i++) {
		cin >> t[i];
		sum += t[i];
	}
	cin >> m;
	vector<int> p(m, 0);
	vector<int> x(m, 0);
	for (int i = 0; i < m; i++) {
		cin >> p[i];
		cin>> x[i];
	}
	for (int i = 0; i < m; i++) {
		cout << sum - (t[p[i] - 1]-x[i]) << endl;
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int WSH(int A)
{
	int Sum=0;
	while(A>0)
	{
		Sum+=A%10;
		A/=10;
	}
	return Sum;
}
int main()
{
	int Sum=0;
	int N,A,B;
	cin>>N>>A>>B;
	for(int I=1;I<=N;I++)
	{
		if(WSH(I)>=A&&WSH(I)<=B)
		Sum+=I;
	}
	cout<<Sum;
	return 0;
}

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

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

    ll factor = n/(a+b);
    ll rem = n%(a+b);

    ll resp = a*factor;
    rem = rem < a ? rem : a;
    resp += rem;
    cout << resp << endl;
    
    return 0;
}

Measured memory_bytes: 256
/*
❤️❤️❤️I_love_QMsh❤️❤️❤️
*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define x first
#define y second

using namespace std;
using namespace __gnu_pbds; // gp_hash_table<int, int> table;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; // <int> .find_by_order(int) .order_of_key(int)

template<typename T> bool smin(T &a, const T &b) { bool ret = b < a; return a = (ret ? b : a), ret; }
template<typename T> bool smax(T &a, const T &b) { bool ret = a < b; return a = (ret ? b : a), ret; }

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;

mt19937 rnd;

signed main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int N, m;
  cin >> N >> m;
  struct E {
    int u, v, c;
  };

  vector<E> es(m);
  vector<pair<int, int>> crds;

  for (int i = 1; i <= N; i++) {
    crds.emplace_back(i, 0);
  }


  for (E &e : es) {
    cin >> e.u >> e.v >> e.c;
    crds.emplace_back(e.u, e.c);
    crds.emplace_back(e.v, e.c);
  }
  sort(all(crds));
  crds.resize(unique(all(crds)) - crds.begin());



  int n = crds.size();

  vector<vector<pair<int, int>>> g(n);

  for (E &e : es) {
    int u = lower_bound(all(crds), make_pair(e.u, e.c)) - crds.begin();
    int v = lower_bound(all(crds), make_pair(e.v, e.c)) - crds.begin();
    g[u].emplace_back(v, 0);
    g[v].emplace_back(u, 0);
  }


  for (int i = 1; i <= N; i++) {
    auto it = lower_bound(all(crds), make_pair(i, 0)) - crds.begin();
    int u = it;
    it++;
    while (it < n && crds[it].x == i) {
      g[u].emplace_back(it, 1);
      g[it].emplace_back(u, 1);
      it++;
    }
  }


  vector<int> d(n, n);
  d[0] = 0;
  set<pair<int, int>> st;
  st.insert({0, 0});
  while (!st.empty()) {
    int u = st.begin()->y;
    st.erase(st.begin());
    for (auto [v, w] : g[u]) {
      int nd = d[u] + w;
      if (d[v] > nd) {
        st.erase({d[v], v});
        d[v] = nd;
        st.insert({d[v], v});
      }
    }
  }

  int it = lower_bound(all(crds), make_pair(N, 0)) - crds.begin();
  cout << (d[it] == n ? -1 : d[it] / 2);

  return 0;
}

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

int main() {
  int N;
  cin >> N;
  string S;
  cin >> S;
  int ans = 0;
  int now = 0;
  for (auto c : S) {
    if (c == 'I') now++;
    else now--;
    ans = max(ans, now);
  }
  cout << ans << "\n";
}

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

int change(int x)
{
	int ans=0;
	while(x)
	{
		ans+=x%10;
		x=x/10;
	}
	return ans;
}
int main()
{
	cin>>n;
	int result=INT_MAX;
	if(n>=2&&n<=10) result=n;
	if(n>10&&n<100) result=(n/10+n%10);
	if(n>=100)
	{
		for(int i=1;i<=n/2;++i)
		{
			int j,temp1,temp2;
			j=n-i;
			temp1=change(i);
			temp2=change(j);
			result=min(temp1+temp2,result);
		}
	}
	cout<<result;
	return 0;
}

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

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

  ll d = a / b;
  ll r = a % b;
  double f = (1.0 * a) / b;

  printf("%lld %lld %.5lf\n", d, r, f);
  return 0;
}


Measured memory_bytes: 3204
#include<cstdio>
#include<cstring>
#include<algorithm>
#define rep(i,a,b) for(i=a;i<=b;i++)
using namespace std;
const int N=1010;
char ans[N][N];
int main(){
	//freopen("a.in","r",stdin);
	//freopen("a.out","w",stdout);
	int n,m,a,b;
	int i,j,cnt1,cnt2,x,flag,nowi,nowj;
	scanf("%d%d%d%d",&n,&m,&a,&b);
	rep(i,1,n)	rep(j,1,m)	ans[i][j]='.';
	if(n&1){
		x=1;
		rep(i,1,min(m/2,a)){
			ans[n][x]='<';x++;
			ans[n][x]='>';x++;
		}
		a-=min(m/2,a);
	}
	if(m&1){
		x=1;
		rep(i,1,min(n/2,b)){
			ans[x][m]='^';x++;
			ans[x][m]='v';x++;
		}
		b-=min(n/2,b);
	}
	if((n>>1)*(m>>1)<(a+1>>1)+(b+1>>1)-(n&m&a&b&1))	{printf("NO\n");return 0;}
	if(n&m&a&b&1){
		ans[n][m]=ans[n-1][m];
		ans[n-1][m]=ans[n-2][m];
		ans[n-2][m-2]='^';ans[n-1][m-2]='v';
		ans[n-2][m-1]='<';ans[n-2][m]='>';
		nowi=nowj=1;
	}
	else{		
		cnt1=a&1;cnt2=b&1;flag=1;
		for(i=1;i<n&&flag;i+=2) for(j=1;j<m&&flag;j+=2){
			if(cnt1){ans[i][j]='<';ans[i][j+1]='>';cnt1--;}
			else if(cnt2){ans[i][j]='^';ans[i+1][j]='v';cnt2--;}
			else flag=0,nowi=i,nowj=j;
		}
	}
	cnt1=a>>1;cnt2=b>>1;flag=1;
	for(i=nowi;i<n&&flag;i+=2) for(j=nowj;j<m&&flag;j+=2){
		nowi=1;nowj=1;
		if(cnt1){ans[i][j]='<';ans[i][j+1]='>';ans[i+1][j]='<';ans[i+1][j+1]='>';cnt1--;}
		else if(cnt2){ans[i][j]='^';ans[i+1][j]='v';ans[i][j+1]='^';ans[i+1][j+1]='v';cnt2--;}
		else flag=0;
	}	
	printf("YES\n");
	rep(i,1,n){
		rep(j,1,m)	printf("%c",ans[i][j]);
		printf("\n");
	}
}
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
			
	

Measured memory_bytes: 2176
#include<iostream>
#include<cstdio>
#include<queue>
#include<map>
#include<algorithm>
using namespace std;
const int N=1e5+10,INF=0x3f3f3f3f;
long long a[N];
struct P{
    long long a;
    int b;
    friend bool operator <(P p1,P p2){
        return p1.a<p2.a;
    }
};
int main()
{
    //freopen("out.txt","w",stdout);
    int n;
    while(~scanf("%d",&n)&&n>=4){
        long long sum=0;
        map<long long ,int>m;
        m.clear();
        priority_queue<P>q;
        for(int i=0;i<n;i++){
            scanf("%lld",&a[i]);
            m[a[i]]++;
        }
        for(map<long long ,int>::iterator it=m.begin();it!=m.end();it++)
            if((*it).second>=2){
                P p;
                p.a=(*it).first;
                p.b=(*it).second;
                q.push(p);
            }

        while(!q.empty()){
            P p1=q.top();
            q.pop();
            if(p1.b>=4) {sum=p1.a*p1.a;break;}
            else {
                P p2=q.top();
                q.pop();
                sum=p1.a*p2.a;
                break;
            }
        }

        printf("%lld\n",sum);
    }
    return 0;
}


Measured memory_bytes: 7296
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
	ll r, D, x, last;
	cin >> r >> D >> x;
	last = x;
	for (ll i = 1; i <= 10; i ++)
	{
		x = last * r - D;
		cout << x << endl;
		last = x;
	}
}

Measured memory_bytes: 256
import sys

stdin = sys.stdin

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

n = ni()
l = list(map(lambda x:int(x) - 1, list(ns())))
f = 1
if 1 not in l:
    l = [x//2 for x in l]
    f += 1

def Cmod2(n, r):
    return n&r == r

s = sum(Cmod2(n-1,i)*l[i] for i in range(n)) % 2
print(f*s)


Measured memory_bytes: 21092
#include <stdio.h>

int main(void)
{
	int square[3] = {0};
	int circle[9999] = {0};
	int n, a, b, c, i;

	while (scanf("%d %d %d", &a, &b, &c) != EOF)
	{
		if (a != 0)
		{
			if (a >= b && a >= c)
			{
				square[0] = b;
				square[1] = c;
				square[2] = a;
			}
			else if (b >= a && b >= c)
			{
				square[0] = a;
				square[1] = c;
				square[2] = b;
			}
			else if (c >= a && c >= b)
			{
				square[0] = a;
				square[1] = b;
				square[2] = c;
			}
		}
		else
			break;

		scanf("%d", &n);

		for (i = 0; i < n; i++)
		{
			scanf("%d", &circle[i]);
		}
		for (i = 0; i < n; i++)
			if (((square[0] * square[0]) + (square[1] * square[1])) < (circle[i] * 2) * (circle[i] * 2))
				printf("OK\n");
			else
				printf("NA\n");
	}

	return 0;
}

Measured memory_bytes: 632
#include<stdio.h>
#include<string.h>
int main(void)
{
	int n,a,min=1000,i,j;
	char s[11];
	char k[9]={'1','2','3','4','5','6','7','8','9'};
	scanf("%s", s);
	n=strlen(s);
	for(i=0; i<n-2; i++)
	{
		for(j=0; j<9; j++)
		{
			if(s[i]==k[j])
			a=(j+1)*100;
		}
		for(j=0; j<9; j++)
		{
			if(s[i+1]==k[j])
			a+=(j+1)*10;
		}
		for(j=0; j<9; j++)
		{
			if(s[i+2]==k[j])
			a+=j+1;
		}
		if(abs(a-753)<min)
		min=abs(a-753);
	}
	printf("%d\n", min);
	
	return 0;
}

Measured memory_bytes: 128
# -*- coding: utf-8 -*-

def main(N, A):
    ans = float("INF")
    for i in range(2):
        sm = 0
        cnt = 0
        for j in range(N):
            sm += A[j]
            #smを正にしたい
            if(j%2==i and sm<=0):
                cnt += 1 - sm
                sm = 1
            #smを負にしたい
            elif(j%2==1-i and sm>=0):
                cnt += 1 + sm
                sm = -1
        ans = min(ans, cnt)
    print(ans)
    
if __name__ == '__main__':
    N = int(input())
    A = [int(i) for i in input().split()]
    
    main(N, A)

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

using namespace std;

long long x;
long long int y=0;
long long  m = 100;

int main() {

  cin >> x;
  while(m < x){
    y++;
    m = (long long) (m*1.01);
  }
  


  cout << y << endl;


  
  
  return 0;
}



Measured memory_bytes: 3624
#include <algorithm>
#include <cstdio>
#include <unordered_map>
#include <vector>

using namespace std;

constexpr int INF = 99999999;
struct V {
    bool exist = false;
    int d = INF;
    V() = default;
    V(bool e, int dd)
        : exist{e}
        , d{dd}
    {
    }
};

int main()
{
    while (true) {
        size_t w;
        size_t h;
        scanf("%ld %ld", &w, &h);

        if (w == 0 && h == 0) {
            break;
        }

        const auto size = w * h;

        vector<vector<V>> am{size};
        for (auto&& r : am) {
            r.resize(size);
        }

        for (size_t i = 0; i < 2 * h - 1; ++i) {
            // ?£????????????£??????????????????
            if (i % 2 == 0) {
                for (size_t j = 0; j < w - 1; ++j) {
                    int t;
                    scanf("%d", &t);
                    if (t == 0) {
                        auto id = j + (i / 2) * w;
                        am[id][id + 1] = V(true, INF);
                        am[id + 1][id] = V(true, INF);
                    }
                }
            }
            else {
                for (size_t j = 0; j < w; ++j) {
                    int t;
                    scanf("%d", &t);
                    if (t == 0) {
                        auto id = j + (i / 2) * w;
                        am[id][id + w] = V(true, INF);
                        am[id + w][id] = V(true, INF);
                    }
                }
            }
        }

        am[0][0].d = 1;
        am[0][0].exist = true;

        unordered_map<size_t, V> q;
        for (size_t i = 0; i < am.size(); ++i) {
            for (size_t j = 0; j < am.size(); ++j) {
                if (am[i][j].exist) {
                    q[i] = am[i][j];
                    break;
                }
            }
        }
        using TT = decltype(q)::value_type;
        // ??????????????????
        while (!q.empty()) {
            auto it =
                min_element(begin(q), end(q), [](const TT& l, const TT& r) {
                    return l.second.d < r.second.d;
                });
            auto u = *it;
            q.erase(it);
            for (size_t i = 0; i < am.size(); ++i) {
                auto&& v = am[u.first][i];
                if (v.exist) {
                    auto alt = u.second.d + 1;
                    if (v.d > alt) {
                        v.d = alt;
                        q[i].d = alt;
                    }
                }
                am[i][u.first] = v;
            }
        }

        int min = 0;
        auto&& goal = am[size - 1];
        auto it = min_element(begin(goal), end(goal),
                              [](const V& l, const V& r) { return l.d < r.d; });
        if (it->d != INF) {
            min = it->d;
        }

        printf("%d\n", min);
    }
}

Measured memory_bytes: 8696
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#define SIZE 305
#define MOD 1000000007

using namespace std;

int nm[SIZE][SIZE];
int dp[SIZE][SIZE][SIZE];

int main()
{
	int n,m;
	scanf("%d %d",&n,&m);
	memset(nm,-1,sizeof(nm));
	for(int i=0;i<m;i++)
	{
		int l,r,x;
		scanf("%d %d %d",&l,&r,&x);
		if(nm[l][r]!=-1&&nm[l][r]!=x)
		{
			puts("0");
			return 0;
		}
		nm[l][r]=x;
	}
	memset(dp,0,sizeof(dp));
	//1-indexed にします
	dp[1][0][0]=3;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=i;j++)
		{
			for(int k=j+1;k<=i;k++)
			{
				if(nm[j][i]!=-1&&nm[k][i]!=-1&&nm[j][i]<nm[k][i])
				{
					puts("0");
					return 0;
				}
			}
		}
		int a1=0,a2=n+1,b1=0,b2=n+1,c1=0,c2=n+1;
		for(int j=1;j<=i;j++)
		{
			if(nm[j][i]==1)
			{
				a1=max(a1,j);
				a2=min(a2,j);
			}
			if(nm[j][i]==2)
			{
				b1=max(b1,j);
				b2=min(b2,j);
			}
			else if(nm[j][i]==3)
			{
				c1=max(c1,j);
				c2=min(c2,j);
			}
		}
		for(int j=0;j<=i;j++)
		{
			for(int k=0;k<=j;k++)
			{
				if(j>=a2||j<b1||k>=b2||k<c1) dp[i][j][k]=0;
			}
		}
		if(i==n) break;
		for(int j=0;j<=i;j++)
		{
			for(int k=0;k<=j;k++)
			{
				if(dp[i][j][k]==0) continue;
				//a[i+1]=a[i]のとき
				dp[i+1][j][k]+=dp[i][j][k];
				if(dp[i+1][j][k]>=MOD) dp[i+1][j][k]-=MOD;
				//a[i+1]!=a[i],a[i+1]=a[j] のとき
				dp[i+1][i][k]+=dp[i][j][k]*(j==0?2:1)%MOD;
				if(dp[i+1][i][k]>=MOD) dp[i+1][i][k]-=MOD;
				if(j!=0)
				{
					dp[i+1][i][j]+=dp[i][j][k];
					if(dp[i+1][i][j]>=MOD) dp[i+1][i][j]-=MOD;
				}
			}
		}
	}
	int ret=0;
	for(int i=0;i<=n;i++)
	{
		for(int j=0;j<=i;j++)
		{
			ret+=dp[n][i][j];
			if(ret>=MOD) ret-=MOD;
		}
	}
	printf("%d\n",ret);
	return 0;
}


Measured memory_bytes: 111488
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <tuple>
#include <stdio.h>
#include <bitset>
#include <limits.h>
#include <complex>
#include <deque>
#include <iomanip>
#include <list>
using namespace std;
#define pi pair<int32,int32>
#define pl pair<int64,int64>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define en cout << endl //セミコロンつけろ
//#define MM 1000000000
//#define MOD MM+7
const int MM = 1e9;
const int MOD = MM+7;
const long double PI = acos(-1);
const long long INF = 1e15;
int dx[8] = {-1,0,1,0,-1,-1,1,1};
int dy[8] = {0,-1,0,1,-1,1,1,-1};
// 'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122
template<typename T>
T GCD(T u,T v){
    return v ? GCD(v,u%v) : u;
}
template<typename T>
T LCM(T x,T y){
    T gc = GCD(x,y);
    return x*y/gc;
}


int main(){
    int N,Q; cin >> N >> Q;
    string s; cin >> s;
    int num[100010]; fill(num,num+100010,0);
    for(int i = 1; i < N; i++){
        if (s[i-1] == 'A' && s[i] == 'C'){
            num[i] = num[i-1] + 1;
        } else {
            num[i] = num[i-1];
        }
    }
    for(int i = 0; i < Q; i++){
        int l,r; cin >> l >> r;
        l--, r--;
        int ans = num[r]-num[l];
        cout << ans << endl;
    }
}

Measured memory_bytes: 1408
import copy
h, w = map(int, input().split())
grid = []
scoresInit = [[500 for i in range(w)] for j in range(h)]

for i in range(h):
  grid.append(list(input()))
  for j in range(w):
    if grid[i][j] == "#":
      scoresInit[i][j] = -1

ans = 0
for i in range(h):
  for j in range(w):
    scores = copy.deepcopy(scoresInit)
    if grid[i][j] == "#":
      continue
    scores[i][j] = 0
    queue = [(i,j)]
    while queue != []:
      (x, y) = queue.pop(0)
      if x-1 >= 0 and grid[x-1][y] != "#" and scores[x-1][y] > scores[x][y]+1:
        scores[x-1][y] = scores[x][y]+1
        queue.append((x-1, y))
      if x+1 < h and grid[x+1][y] != "#" and scores[x+1][y] > scores[x][y]+1:
        scores[x+1][y] = scores[x][y]+1
        queue.append((x+1, y))
      if y-1 >= 0 and grid[x][y-1] != "#" and scores[x][y-1] > scores[x][y]+1:
        scores[x][y-1] = scores[x][y]+1
        queue.append((x, y-1))
      if y+1 < w and grid[x][y+1] != "#" and scores[x][y+1] > scores[x][y]+1:
        scores[x][y+1] = scores[x][y]+1
        queue.append((x, y+1))
    ansTmp = 0
    for k in range(len(scores)):
      ansTmp = max(ansTmp, max(scores[k]))
    ans = max(ans, ansTmp)
print(ans)

Measured memory_bytes: 3444
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define ll long long
#define dd double
#define MOD1 1000000007
#define MOD2 998244353
#define nl cout<<endl
#define rt ll Q[100005]={0}
#define mp make_pair
#define test() ll t;cin>>t;while(t--)
#define pb push_back
#define ff first    
#define ss second
#define all(v) v.begin(),v.end()
#define s(ar,n) sort(ar,ar+n)
#define rs(ar,n) sort(ar, ar+n, greater<ll>()) 
#define oa(a,n) for(ll i=0;i<n;i++)cout<<a[i]<<" ";nl
#define cn(a,n) for(ll i=0;i<n;i++)cin>>a[i];
#define ov(a,n) for(ll i=n-1;i>=0;i--)cout<<a[i]<<" ";nl
#define ovp(a,n) for(ll i=0;i<n;i++)cout<<a[i].ff<<" "<<a[i].ss<<endl;
#define maxa(ar,N) *max_element(ar,ar+N)
#define mina(ar,N) *min_element(ar,ar+N)
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
typedef pair<ll,ll> pii;
ll powe(ll n,ll m){if(m==0)return 1;if(m<0) return 0;ll t=powe(n,m/2);if(m%2==0)return (t*t);return (((t*t))*n);}
ll mpowe(ll n,ll m,ll MOD){if(m==0)return 1;ll t=mpowe(n,m/2,MOD);t%=MOD;if(m%2==0)return (t*t)%MOD;return (((t*t)%MOD)*n)%MOD;}
ll logtwo(ll n){if(n==1)return 0;if(n==0) return -1;return logtwo(n/2)+1;}
int main()
{
   
    ll a,b,c,k,ans=0;
    cin>>a>>b>>c>>k;
    ans = min(a,k);
    k = k-min(a,k);
    k = k-min(b,k);
    ans = ans- min(c,k);
    cout<<ans<<endl;
}

Measured memory_bytes: 3632
// https://atcoder.jp/contests/abc177/tasks/abc177_c
#include <bits/stdc++.h>
// #include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
// using cpp_dec = boost::multiprecision::cpp_dec_float_50;
// using cpp_int = boost::multiprecision::cpp_int;
using int128_t = boost::multiprecision::int128_t;

using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define CEIL(a, b) ((a - 1) / b + 1)
const int MOD = 1e9 + 7;

// 参考
// https://atcoder.jp/contests/abc177/submissions/16384020
void solve() {
    int N;
    cin >> N;
    int128_t x = 0, y = 0;
    REP(i, N) {
        int128_t t;
        cin >> t;
        x += t;
        y += t * t;
    }
    // (A + B + C)^2 = A^2 + B^2 + C^2 + 2*AB + 2*AC + 2*BC
    // 2*AB + 2*AC + 2*BC = (A + B + C)^2 - (A^2 + B^2 + C^2)

    // AB + AC + BC
    // = ((A + B + C)^2 - (A^2 + B^2 + C^2)) / 2
    // = (x^2 - y) / 2
    cout << (x * x - y) / 2 % MOD << endl;
}

signed main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    solve();
}


Measured memory_bytes: 3656
import java.io.IOException;
import java.io.InputStream;
import java.util.*;

public class Main {
    public static void main(String[] args){
        FastScanner sc = new FastScanner();
        int A = sc.nextInt();
        int B = sc.nextInt();
        int result = 0;
        int x = (A + B) / 24;
        result = A + B - x * 24;
        System.out.println(result);

    }

    static class FastScanner {
        private final InputStream in = System.in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int buflen = 0;
        private boolean hasNextByte() {
            if (ptr < buflen) {
                return true;
            }else{
                ptr = 0;
                try {
                    buflen = in.read(buffer);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (buflen <= 0) {
                    return false;
                }
            }
            return true;
        }
        private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
        private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
        public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
        public String next() {
            if (!hasNext()) throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while(isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }
        public long nextLong() {
            if (!hasNext()) throw new NoSuchElementException();
            long n = 0;
            boolean minus = false;
            int b = readByte();
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            if (b < '0' || '9' < b) {
                throw new NumberFormatException();
            }
            while(true){
                if ('0' <= b && b <= '9') {
                    n *= 10;
                    n += b - '0';
                }else if(b == -1 || !isPrintableChar(b)){
                    return minus ? -n : n;
                }else{
                    throw new NumberFormatException();
                }
                b = readByte();
            }
        }
        public int nextInt() {
            long nl = nextLong();
            if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
            return (int) nl;
        }
        public double nextDouble() { return Double.parseDouble(next());}
    }
}

Measured memory_bytes: 20564
//by Top1
#include <bits/stdc++.h>
          
#define f first
#define s second
#define int long long
#define ld long double
#define ull unsigned long long
#define pii pair <int, int>
#define pll pair <long, long>
#define mp make_pair
#define pb push_back
#define pf push_front
#define pp pop_back
#define cerr cout
#define rev reverse
#define all(s) s.begin(), s.end()
#define sz(s) (int)s.size()
#define forn(i, a, b) for (int i = a; i <= b; i++)
#define boost ios_base::sync_with_stdio(false); cin.tie(0),cout.tie(0);
#define nxtp next_permutation
#define pvtp prev_permutation
#define KZ return 
#define x1 x21212121
#define y1 y21212121
#define sqr(x) x * x 
      
const int inf = (1e9) + 1;
const int mod = 479001599;
const int maxn = 1e6 + 111;
        
using namespace std;          

int n, k, ans, kk;

void solve(){             
	vector <int> v;

	int k = 1;

	cin >> kk;

	for (int i = 1; i <= 10; i++){
		for (int j = 0; j <= 9; j++){
			if (i == 1 && j == 0)
				continue;
			if (i == 1){
				v.pb(j);
				continue;
			}
			if (v.empty())
				break;
			for (int h = 0; h < sz(v); h++){
				int y = v[h];
				int g = y % 10;
				bool ch = true;
				int cnt = 0;
				while (y > 0){
					y /= 10;
					cnt++;
				}
				if (cnt != i - 1)
					continue;
				y = v[h];
				while (y > 0){
					y /= 10;
					if (y == 0)
						break;
					if (abs(y % 10 - g) > 1){
						ch = false;
						break;
					}
					g = y % 10;
				}
				if (abs(v[h] % 10 - j) <= 1){
					v.pb(v[h] * 10 + j);
					//cout << y * 10 + j << endl;;
				}
			}
		}
		k *= 10;
	}        

	sort(all(v));

	cout << v[kk - 1];
}                              
      
main(){
    boost;
    
    int q = 1;
 
    //cin >> q;
    
    while (q--){
        solve();
    }
}

Measured memory_bytes: 2420
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from collections import defaultdict


N = int(read())
counter = defaultdict(int)
for x in map(str,range(1,N+1)):
    head = x[0]
    tail = x[-1]
    counter[(head, tail)] += 1
ans = 0
items = list(counter.items())
for (head, tail), cnt in items:
    ans += cnt * counter[(tail, head)]
print(ans)


Measured memory_bytes: 3316
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    int n = scan.nextInt();
    int m = scan.nextInt();
    int count = 0;
    while (n>0){
      n -= m;
      count++;
    }

    System.out.println(count);
  }
}


Measured memory_bytes: 35716
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
int main(void){
    string s;
    cin>>s;
    if(s.size()%2!=0){
        cout<<"No"<<endl;
        return 0;
    }else{
        for(int i=0;i<s.size();i++){
            if(i%2==0){
                if(s[i]!='h'){
                    cout<<"No"<<endl;
                    return 0;
                }
            }else{
                if(s[i]!='i'){
                    cout<<"No"<<endl;
                    return 0;
                }
            }
        }
    }
    cout<<"Yes"<<endl;
    
}


Measured memory_bytes: 3624