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

using namespace std;
#define ll long long
const int N = 1e5 + 5;
vector<int> g[N];
int dist[N][3];

int bfs(int source, int t) {
    for (int i = 0; i < N; i++) for (int j = 0; j < 3; j++) dist[i][j] = 1e8;
    queue<pair<int, int> > q;
    q.push({source, 0});
    dist[source][0] = 0;
    while (q.size()) {
        int node = q.front().first;
        int mod = q.front().second;
        q.pop();
        for (auto child:g[node]) {
            int nmod = (mod + 1) % 3;
            if (dist[child][nmod] == 1e8) {
                dist[child][nmod] = dist[node][mod] + 1;
                q.push({child, nmod});
            }
        }
    }
    if (dist[t][0] == 1e8) return -1;
    return dist[t][0] / 3;
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        int u, v;
        cin >> u >> v;
        g[u].push_back(v);
    }
    int s, t;
    cin >> s >> t;
    cout << bfs(s, t) << endl;
    return 0;
}

Measured memory_bytes: 6912
#include <iostream>
#include <algorithm>

#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;
using P = pair<int,int>;

int main()
{
    int N,M;
    cin>>N>>M;
    P r[100010];
    rep(i,M){
        int a,b;
        cin>>a>>b;
        r[i] = make_pair(b-1,a-1);
    }

    sort(r,r+M);

    int ans=1,min=0;
    for(int i=1;i<M;i++){
        if(r[min].first<=r[i].second){
            ans++;
            min=i;
        }
    }

    cout << ans << endl;

    return 0;
}

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

const int SIZE=100;
using F=bitset<SIZE>;

auto comp=[](const F& lhs,const F& rhs){
    return lhs.count()<rhs.count();
};

int dfs(int pos,vector<vector<F>> &bigSq,F state,unordered_map<F,int>& dp){
    if(pos==bigSq.size()){
        return 0;
    }
    if(dp.count(state)){
        return dp[state];
    }
    if(!state[pos]){
        auto ret=dfs(pos+1,bigSq,state,dp);
        dp[state]=ret;
        return ret;
    }
    
    vector<F> toS;
    for(int i=0;i<bigSq[pos].size();i++){
        toS.push_back(state & (~bigSq[pos][i]));
    }
    int res=1e6;
    sort(toS.begin(),toS.end(),comp);
    for(int i=0;i<toS.size();i++){
        bool isok=true;
        for(int j=0;j<i;j++){
            isok&=!((toS[i]&toS[j])==toS[j]);
        }
        if(isok){
            res=min(res,dfs(pos+1,bigSq,toS[i],dp)+1);
        }
    }
    return dp[state]=res;
}

int main(){
    int w,h;
    while(cin>>w>>h,w){
        vector<vector<int>> f(h,vector<int>(w,0));
        for(int i=0;i<h;i++){
            for(int j=0;j<w;j++){
                cin>>f[i][j];
            }
        }
        
        F state=0;
        vector<vector<F>> bigSq(h*w);
        for(int i=0;i<h;i++){
            for(int j=0;j<w;j++){
                if(!f[i][j]) continue;
                state.set(i*w+j);
                int s=0;
                for(int k=1;k<=10;k++){
                    bool isok=true;
                    for(int ii=0;ii<k;ii++){
                        for(int jj=0;jj<k;jj++){
                            isok&=(i+ii<h && j+jj<w && f[i+ii][j+jj]);
                        }
                    }
                    if(!isok) break;
                    s++;
                }
                F sq=0;
                for(int ii=0;ii<s;ii++){
                    for(int jj=0;jj<s;jj++){
                        sq.set((ii+i)*w+j+jj);
                    }
                }
                for(int ii=0;ii<s;ii++){
                    for(int jj=0;jj<s;jj++){
                        bigSq[(i+ii)*w+j+jj].push_back(sq);
                    }
                }
                sort(bigSq[i*w+j].begin(),bigSq[i*w+j].end(),comp);
            }
        }

        for(int i=0;i<h*w;i++){
            vector<F> newBigSq;
            for(int j=0;j<bigSq[i].size();j++){
                bool isok=true;
                for(int k=j+1;k<bigSq[i].size();k++){
                    isok&=((bigSq[i][j] & bigSq[i][k])!=bigSq[i][j]);
                }
                if(isok) newBigSq.push_back(bigSq[i][j]);
            }
            bigSq[i]=newBigSq;
        }
        
        unordered_map<F,int> dp;

        int res=dfs(0,bigSq,state,dp);
        cout<<res<<endl;
    }

    return 0;
}


Measured memory_bytes: 3192
// writer: w33z8kqrqk8zzzx33
#include <bits/stdc++.h>
using namespace std;
 
#define iter(i, a, b) for(int i=(a); i<(b); i++)
#define rep(i, a) iter(i, 0, a)
#define rep1(i, a) iter(i, 1, (a)+1)
#define log(a) cerr<<"\033[32m[DEBUG] "<<#a<<'='<<(a)<<" @ line "<<__LINE__<<"\033[0m"<<endl
#define all(a) a.begin(), a.end()
#define fi first
#define se second
#define pb push_back
#define mp make_pair
 
using ll=long long;
using pii=pair<int, int>;
//#define int ll
const int MOD = 1000000007;

ll swdp[101][10][2][4]; // swdp[cdig][digit val][eq to q][nonzero]

#define SWDP_COND(prevdig, nexdig) if(max(prevdig-nexdig, nexdig-prevdig) >= 2)

// assuming there are no preceding zeroes

int K;

ll _solve_swdp(string s) {
    memset(swdp, 0, sizeof swdp);
    swdp[0][s[0]-'0'][1][s[0] != '0'] = 1;
    // change to 0 if can have preceding zeroes
    iter(d, 0, s[0]-'0') swdp[0][d][0][d != 0] = 1;
    rep1(dig, s.size()-1) {
        rep(pdval, 10) rep(dval, 10)
            rep(d, 4) if(d || !dval) swdp[dig][dval][0][d] += swdp[dig-1][pdval][0][d - (dval != 0)];
        rep(dval, s[dig]-'0')
            rep(d, 4) if(d || !dval) swdp[dig][dval][0][d] += swdp[dig-1][s[dig-1]-'0'][1][d - (dval != 0)];
        rep(d, 4) if(d || s[dig] == '0') swdp[dig][s[dig]-'0'][1][d] += swdp[dig-1][s[dig-1]-'0'][1][d - (s[dig] != '0')];
    }
    ll ans = 0; rep(dval, 10) ans += swdp[s.size()-1][dval][0][K] + swdp[s.size()-1][dval][1][K];
    return ans;
}

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    string s; cin >> s >> K;
    cout << _solve_swdp(s) << endl;
}



Measured memory_bytes: 384
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c=sc.nextInt();
        if (b-a==c-b) {
            System.out.println("YES");  
        }else{
            System.out.println("NO");
        }
       
    }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#ifdef ENABLE_DEBUG
#define dump(a) cerr<<#a<<"="<<a<<endl
#define dumparr(a,n) cerr<<#a<<"["<<n<<"]="<<a[n]<<endl
#else
#define dump(a) 
#define dumparr(a,n) 
#endif
#define FOR(i, a, b) for(ll i = a;i < b;i++)
#define For(i, a) FOR(i, 0, a)
#define REV(i, a, b) for(ll i = b-1;i >= a;i--)
#define Rev(i, a) REV(i, 0, a)
#define REP(a) For(i, a)

typedef long long int ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<ll, ll> pll;
typedef pair<ll,pll> ppll;
typedef vector<ll> vll;

const ll INF=(1LL<<50);

template<class S,class T>
std::ostream& operator<<(std::ostream& os,pair<S,T> a){
  os << "(" << a.first << "," << a.second << ")";
  return os;
}
template<class T>
std::ostream& operator<<(std::ostream& os,vector<T> a){
  os << "[ ";
  REP(a.size()){
    os<< a[i] << " ";
  }
  os<< " ]";
  return os;
}


void solve(long long N, long long K, std::vector<long long> h){
  cout<<count_if(h.begin(),h.end(),[&K](ll x){return x>=K;})<<endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long K;
    scanf("%lld",&K);
    std::vector<long long> h(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&h[i]);
    }
    solve(N, K, std::move(h));
    return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>
int main()
{
int a,b;
scanf("%d\n%d",&a,&b);
if(a==1&&b==2||a==2&&b==1)
{
printf("3\n");}
else if(a==2&&b==3||a==3&&b==2)
    {
printf("1\n");
}
else
{
    printf("2\n");}
return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;

public class Main {

    public static void main(String[] args){

        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int x = sc.nextInt();
        int res = 0;

        for(int i=0; i<=a; i++) {
            for(int j=0; j<=b; j++) {
                for(int k=0; k<=c; k++) {
                    if(500*i + 100*j + 50*k == x) res++;
                }
            }
        }
        System.out.println(res);
    }

}


Measured memory_bytes: 23764
#include<iostream>
#include<vector>
#include<map>
#include<cmath>
#include<string>
#include<bitset>
#include <sstream>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
typedef long long ll;

int main()
{
    int a,b;
    cin>>a>>b;
    if(a>=b)
    {
        cout<<string(a,'0'+b)<<endl;
    }
    else
    {
        cout<<string(b,'0'+a)<<endl;
    }
    
    
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
  int K, N, i, save, con;
  int tmp=0;
  int a[200000];
  
  if(scanf("%d%d",&K,&N)==1);
  for(i=0;i<N;i++)
    if(scanf("%d",&a[i])==1);
  
  for(i=0;i<N-1;i++){
    save=a[i+1]-a[i];
    if(save>tmp)
      tmp=save;}
  
  save=K-a[N-1]+a[0];
  if(save>tmp)
    tmp=save;
  
  con=K-tmp;
  printf("%d",con);
  
  return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
#define forn(x, n)              for (int x = 0; x < n; x++)
#define forr(x, n)              for (int x = n; x >= 0; x--)
#define fore(x, a, b, c)        for (int x = a; x <= b; x += c)
#define forre(x, a, b, c)       for (int x = a; x >= b; x -= c)
#define clr                     cin.ignore(numeric_limits<streamsize>::max(), '\n')
#define all(container)          (container).begin(), (container).end()
#define rall(container)         (container).rbegin(), (container).rend()
#define FILL(x, val)            memset(x, val, sizeof(x))
#define pb                      push_back
#define eb                      emplace_back
#define fi                      first
#define se                      second
#define mod                     (int)1000000007
#define INF                     (int)0x3f3f3f3f

using namespace std;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }  

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

int main(void) {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int arr[]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int k;cin>>k;
    cout<<arr[k-1]<<'\n';
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include <bits/stdc++.h>
#include<string>
#include<algorithm>
using namespace std;
typedef pair<int,int> P;


int main(){
    long X;
    cin >>X;
    for(long i=-120;i<120;++i){
        for(long j =-120;j<120;++j){
            if(i*i*i*i*i-j*j*j*j*j == X){
                cout << i << " " << j << endl;
                return 0;
            }
        }
    }

    return 0;
}

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

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;

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

#define rep(i, j) for (int i = 0; i < j; i++)
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
#define debug(x) cerr << #x << ": " << x << endl;
#define int ll

const ll mod = 1e9 + 7;
const ll inf = (1LL << 50);

void solve(long long N, long long M, long long V, long long P, std::vector<long long> A){

    sort(rall(A));

    ll ap = A[P - 1];
    int lo = 0, hi = N;
    while(hi - lo > 1) {
        int mid = lo + (hi - lo) / 2;
        if (mid < P) lo = mid;
        else if (A[mid] + M < ap) hi = mid;
        else {
            ll tmp = 0;
            rep(i, P - 1) tmp += M;
            for(int i = P - 1; i <= mid; i++) {
                tmp += max(0LL, A[mid] + M - A[i]);
            }
            for (int i = mid + 1; i < N; i++) tmp += M;
            if (tmp < M * V) hi = mid;
            else lo = mid;
        }
    }
    cout << lo + 1 << endl;
}

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

    long long N;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);
    long long V;
    scanf("%lld",&V);
    long long P;
    scanf("%lld",&P);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    solve(N, M, V, P, std::move(A));
    return 0;
}


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

void bubbleSort(char arr[], int n)
{
    int i, j;
    for (i = 0; i < n - 1; i++)
        for (j = 0; j < n - i - 1; j++)
            if (arr[j] > arr[j + 1]) {
                char temp = arr[j];
                arr[j] = arr[j + 1];
                arr[j + 1] = temp;
            }

}

void bubbleSortR(char arr[], int n)
{
    int i, j;
    for (i = 0; i < n - 1; i++)
        for (j = 0; j < n - i - 1; j++)
            if (arr[j] < arr[j + 1]) {
                char temp = arr[j];
                arr[j] = arr[j + 1];
                arr[j + 1] = temp;
            }

}

int main(void)
{
    char s[101], t[101];
    scanf("%s%s", s, t);

    int sl = strlen(s), tl = strlen(t);
    bubbleSort(s, sl);
    bubbleSortR(t, tl);

    int i;
    int f = 1;

    if (sl < tl) {
        for (i = 0; i < sl; i++) {
            if (s[i] != t[i]) {
                f = 0;
                break;
            }
        }
        if (f) {
            puts("Yes");
            return 0;
        }
    }
    int ll = sl < tl ? sl : tl;
    for (i = 0; i < ll; i++) {
        if (s[i] == t[i])
            continue;
        else if (s[i] < t[i]) {
            puts("Yes");
            return 0;
        }
        else {
            puts("No");
            return 0;
        }
    }
    puts("No");
    return 0;
}

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

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>
#include<unordered_set>
#include<bitset>
#include<complex>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

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

	string S, T;
	cin >> S >> T;
	T += S;
	cout << T << endl;

	return 0;
}

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

#define rep(i,n) for(int i=0;i< (n);++i)
#define REP(i,n) for(int i=1;i<=(n);++i)
#define ALL(a) (a).begin(),(a).end()
using LLI = long long int;
LLI GCD(LLI a,LLI b){ if(a<b) return GCD(b,a); else if(a%b==0) return b; else return GCD(b,a%b); }
LLI LCM(LLI a,LLI b){ return (a/GCD(a,b))*b; }

int main() {
    std::ios::sync_with_stdio(false);
    //
    LLI N;
    std::cin >> N;
    //
    std::vector<LLI> a(N-1),b(N-1),c(N-1);
    rep(i,N-1) {
        std::cin >> a[i] >> b[i] >> c[i];
        --a[i]; // 0-indexed
        --b[i]; // 0-indexed
    }
    //
    LLI Q,K;
    std::cin >> Q >> K;
    --K; // 0-indexed
    //
    std::vector<LLI> x(Q),y(Q);
    rep(i,Q) {
        std::cin >> x[i] >> y[i];
        --x[i];
        --y[i];
    }
    // init graph
    using edge = std::pair<LLI,LLI> ; // to, weight
    std::vector<std::vector<edge>> graph(N);
    rep(i,N-1) {
        graph[a[i]].push_back(std::make_pair(b[i],c[i]));
        graph[b[i]].push_back(std::make_pair(a[i],c[i]));
    }

    //
    std::vector<LLI> dist(N,-1);
    dist[K] = 0;
    //
    std::queue<LLI> queue;
    queue.push(K);
    while(!queue.empty()) {
        auto pos = queue.front();
        queue.pop();
        //
        auto edges = graph[pos];
        rep(i,edges.size()){
            auto e = edges[i];
            auto to = e.first;
            auto weight = e.second;
            if(dist[to]<0) {
                dist[to] = dist[pos] + weight;
                queue.push(to);
            }
        }
    }

    rep(i,Q) {
        std::cout << dist[x[i]] + dist[y[i]] << std::endl;
    }
    return 0;
}

Measured memory_bytes: 14448
#include <bits/stdc++.h>
#include <cstdlib>  //abs()で絶対値を取得する（整数）
#include <cmath>    //abs()かfabs()で絶対値を取得する（少数）
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
int main(){
    int s;
    int w;
    cin >> s >> w;
    if (s <= w){
        cout << "unsafe";
    }else{
        cout << "safe";
    }
    return 0;
}

Measured memory_bytes: 3600
/* Code by pedroslrey *
 *     march 7        *
 *    Starurday       */

#include <bits/stdc++.h>

using namespace std;

using lli = long long int;

const int INF = 1000000007;
const lli LLINF = 9223372036854775800;

#define debug(args...) fprintf(stderr, args)
#define show(x) fprintf(stderr, "[DEBUG] -> %d\n", x)

int main() {
	lli n;
	scanf("%lld", &n);
	lli a, b;
	scanf("%lld%lld", &a, &b);
	if (a + b == 0) {
		printf("0\n");
		return 0;
	}
	lli q = n/(a+b);
	lli r = n%(a + b);
	lli total = q*a;
	if (r >= a) total += a;
	else total += r;
	printf("%lld\n", total);
}

Measured memory_bytes: 256
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=(b-1);i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;

#define MOD 1000000007

int main() {
	ll n,t;
	cin>>n>>t;
	ll a = 0;
	ll b = 0;
	ll ans = 0;
	rep(i,0,n){
		ll c;
		cin>>c;
		if(b<=c){
			ans += t;
		}
		else{
			ans += t-(b-c);
		}
		a = c;
		b = c+t;
	}
	cout << ans << endl;
	return 0;
}

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

using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
typedef long long ll;

int main(){
  int a,b,c;
  cin >> a >> b >> c;
  if(a<b && b<c)cout << "Yes" << endl;
  else cout << "No" << endl;
}



Measured memory_bytes: 3092
#include <iostream>
#include <vector>
#include <math.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define REP2(i,s,e) for(int i=s;i<e;i++)
using namespace std;
 
int main() {
	int H,W;
    cin >> H;
    cin >> W;
    string A[H];
    REP(i,H){
        cin >> A[i];
    }

    if(H==1 && W==1){
        cout << 0 << endl;
        return 0;
    }
 
    int MAX = 1000000;
    int L[H+2][W+2]={0};
    vector<pair<int,int> > toCheck;
  	REP(i,H+2){
        REP(j,W+2){
          	if(i==0||i==W+2||j==0||j==H+2)
              	L[i][j] = MAX;
        }
    }
    REP(i,H){
        REP(j,W){
            if(A[i][j] == '#'){
                L[i+1][j+1] = 0;
                toCheck.push_back(make_pair(i+1,j+1));
            }else{
                L[i+1][j+1] = MAX;
            }
        }
    }
 
    while(true){
        vector<pair<int,int> > toCheck_new;
        if(toCheck.size()==0) break;
        for(int ind = 0; ind != toCheck.size(); ++ind) {
            int i = toCheck[ind].first;
            int j = toCheck[ind].second;
            if(L[i-1][j]>L[i][j]+1){
                L[i-1][j] = L[i][j]+1;
                if(i-1!=0) toCheck_new.push_back(make_pair(i-1,j));
            }
            if(L[i][j-1]>L[i][j]+1){
                L[i][j-1] = L[i][j]+1;
                if(j-1!=0) toCheck_new.push_back(make_pair(i,j-1));}
            if(L[i][j+1]>L[i][j]+1){
                L[i][j+1] = L[i][j]+1;
                if(j+1!=W+1) toCheck_new.push_back(make_pair(i,j+1));}
            if(L[i+1][j]>L[i][j]+1){
                L[i+1][j] = L[i][j]+1;
                if(i+1!=H+1) toCheck_new.push_back(make_pair(i+1,j));}
        }
        if(toCheck_new.size()==0) break;
        toCheck = toCheck_new;
    }
 
    int maximum = 0;
    for(int i=1;i<H+1;i++){
        for(int j=1;j<W+1;j++){
            if(L[i][j] > maximum) maximum=L[i][j];
        }
    }
	cout << maximum<< endl;
    return 0;
}

Measured memory_bytes: 17896
ab = [list(map(int, input().split())) for _ in range(3)]
ichi = 0
ni = 0
san = 0
yon = 0
flag = 0
for l in ab:
    for n in l:
        if n == 1:
            ichi += 1
        elif n == 2:
            ni += 1
        elif n == 3:
            san += 1
        elif n == 4:
            yon += 1
if ichi == 2:
    flag += 1
if ni == 2:
    flag += 1
if san == 2:
    flag += 1
if yon == 2:
    flag += 1
if flag == 2:
    print("YES")
else:
    print("NO")


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#include<algorithm>
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	ll n;
	cin>>n;
	string s;
	cin>>s;
	ll ans=0;
	for(ll i=0;i<n-2;i++){
		if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C'){
			ans++;
		}
	}
	cout <<ans;
	// your code goes here
	return 0;
}

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

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

fn parent(node_id: usize) -> usize {
    return node_id / 2;
}

fn left(node_id: usize) -> usize {
    return node_id * 2;
}

fn right(node_id: usize) -> usize {
    return node_id * 2 + 1;
}

fn main() {
    let h: usize = read();
    let mut a: Vec<i64> = vec![0];
    for _ in 0..h {
        let number: i64 = read();
        a.push(number);
    }
    for (index, node_key) in a.iter().enumerate() {
        if index == 0 {
            continue;
        }
        print!("node {}: key = {}, ", index, node_key);
        if parent(index) >= 1 {
            print!("parent key = {}, ", a[parent(index)]);
        }
        if left(index) <= h {
            print!("left key = {}, ", a[left(index)]);
        }
        if right(index) <= h {
            print!("right key = {}, ", a[right(index)]);
        }
        println!();
    }
}



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

int main(){
  while(true){
    int a,b,kekka;
    string op;
    cin >> a >> op >> b;
    if(op == "?") break;
    if(op == "+"){
      kekka = a + b;
    }else if(op == "-"){
      kekka = a - b;
    }else if(op == "*"){
      kekka = a * b;
    }else if(op == "/"){
      kekka = a / b;
    }
    cout << kekka << endl;
  }
  return 0;
}

Measured memory_bytes: 1204
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <iterator>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <regex>
using namespace std;
using pii  = pair<int,int>;
using ll=long long;
using ld=long double;
#define pb push_back
#define mp make_pair
#define sc second
#define fr first
#define stpr setprecision
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<(n);++i)
#define Rep(i,a,b) for(ll i=(a);i<(b);++i)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define rRep(i,a,b) for(int i=a;i>=b;i--)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
ll gcd(ll a,ll b){return (b == 0 ? a : gcd(b, a%b));}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll MOD=1000000007;
constexpr ll INF=1000000011;
constexpr ll MOD2=998244353;
constexpr ll LINF = 1001002003004005006ll;
constexpr ld EPS=10e-8;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}
template<class T> ostream& operator<<(ostream& os, vector<T>& v){
  for(auto i=begin(v); i != end(v); ++i){
    if(i !=begin(v)) os << ' ';
    os << *i;
  }
  return os;
}

ll N,P,A[507],sum=0;

vector< ll > divisor(ll n) {
  vector< ll > ret;
  for(ll i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

bool check(ll X){
  ll mas = 0;
  pair<ll,ll> C[507];
  ll D[507],E[507];
  rep(i,N){
    C[i].fr=A[i]%X;
    C[i].sc=(C[i].fr == 0LL ? 0LL :X-C[i].fr);
  }
  sort(C,C+N);
  D[0]=0;
  E[N]=0;
  ll K=0;
  rep(i,N){
    K+=C[i].fr;
    D[i+1]=K;
  }
  K=0;
  rRep(i,N-1,0){
    K+=C[i].sc;
    E[i]=K;
  }
  rep(i,N+1){
    if(D[i]==E[i]){
      mas = D[i];
      break;
    }
  }
  return mas<=P;
}

int main(){
  cin >> N >> P;
  ll T = 1;
  rep(i,N){
    cin >> A[i];
    sum += A[i];
  }
  auto B = divisor(sum);
  rep(i,B.size()){
    if(check(B[i])){
      T = max(B[i],T);
    }
  }
  cout << T << endl;
}

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

using namespace std;

int main()
{
  int a = 0, b = 0;
  cin >> a >> b;
  if(a > 9){
    cout << -1 << endl;
  }else if(b > 9){
    cout << -1 << endl;
  }else{
    cout << a * b << endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
         
typedef long long ll;
using namespace std;
        
#define F first
#define S second
#define sqr(x) x*x
#define pb push_back
#define mp make_pair
#define sz(x) ((int) (x).size())
#define all(x) (x).begin(), (x).end()
#define allr(x) (x).rbegin(), (x).rend()
#define repit(i, n) for(auto it = n.begin(); it != n.end(); ++it)
       
const ll mod=1000000007;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0);for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b){if(b==0)return a;else return gcd(b,a%b);}
int lcm(int a,int b){return abs(a*b)/gcd(a,b);}
     
int main(){ios_base::sync_with_stdio(0);cin.tie(0);
    int a;
    cin >> a;
    int sum = 0;
    for(int i = 1; i <= a; ++i){
        sum = sum + i;
    }
    cout << sum;

}

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

int main(){
  int a[3][3];
  int b[3][3]={};
  for(int i=0;i<3;i++){
    for(int r=0;r<3;r++){
      cin >> a[i][r];
    }
  }
  int n;
  cin >> n;
  for(int i=0;i<n;i++){
    int w;
    cin >> w;
      for(int i=0;i<3;i++){
    for(int r=0;r<3;r++){
      if(a[i][r]==w){b[i][r]=1;}
    }
  }
  }
  for(int i=0;i<3;i++){
  if(b[i][0]==1 && b[i][1]==1 && b[i][2]==1){cout << "Yes" << endl;
                                            return 0;}
  }
   for(int i=0;i<3;i++){
  if(b[0][i]==1 && b[1][i]==1 && b[2][i]==1){cout << "Yes" << endl;
                                            return 0;}
  }
   if(b[0][0]==1 && b[1][1]==1 && b[2][2]==1){cout << "Yes" << endl;
                                            return 0;} 
    if(b[2][0]==1 && b[1][1]==1 && b[0][2]==1){cout << "Yes" << endl;
                                            return 0;}
  cout << "No" << endl;
}

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

int main() {
    int N, K; cin >> N >> K;
    vector<int> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A.at(i);
    }
    int e = 0;
    if (N == K) cout << 1 << endl;
    else {
        if ((N-1) % (K-1) != 0) e = 1;
        cout << (N-1) / (K-1) + e << endl;
    }
}

Measured memory_bytes: 3792
// #define _CRT_SECURE_NO_WARNINGS
// #define _USE_MATH_DEFINES	// M_PI=3.1415...
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <locale>
#include <cctype>
#include <sstream>
#include <iomanip>	// 20桁出力 cout << setprecision(20) << double;
#include <queue>
#include <bitset>	// bitset<8> bs1(131uL); // 10000011 bs1[0]は1 01stringからビット集合生成可
using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<LL> VL;
typedef map<int, int> MAPII;
typedef multimap<int, char, greater<int> > MuMAPIC;
typedef vector<pair<int, int> > VPII;
typedef multimap<int, string, greater<int> > MuMIS;
typedef pair<int, int> P;
typedef pair<int, pair<P, P> > PP;

#define INF 999999999999999997;
#define MP make_pair
#define FAST_IO  cin.tie(0); ios::sync_with_stdio(false);
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORL(i,a,b) for(LL i=(a);i<(b);i++)
#define FOR_REV(i,a,b) for(int i=(a);i>=(b);i--)
//for gcc (未test)
// #define FOREACH_IT(it,c) for(typeof(c)::iterator it=(c).begin(); it!=(c).end(); ++it)
//for Visual Studio
#define foreach_it(type,it,c) for(type::iterator it=c.begin(),c_end=c.end();it!=c_end;++it)
#define FOR_ITR(d) for(auto itr=d.begin(),d_end=d.end();itr!=d_end;++itr)	// C++11
// for Debug.
#define DUMP_VVI(b) FOR(i,0,b.size()){FOR(j,0,b[i].size())printf("%d ",b[i][j]);puts("");}
#define D_OUT(str,value) if(dbgF){cout<<str<<" : "<<value<<endl;}
// 入力をpush_back(d)やarray[d]に使う時に1行で書ける
// int INPUT_INT() {int d;cin>>d;return d;}
template<class T>T IN() { T d; cin >> d; return d; }
// 最大公約数（Greatest Common Divisor）
LL gcd(LL a, LL b) { return (b > 0) ? gcd(b, a%b) : a; }
// 最小公倍数（Least Common Multiple）
LL lcm(LL a, LL b) { return a / gcd(a, b) * b; }
// Y年はうるう年か否か
bool uruu(LL Y) { return (((Y % 4 == 0 && Y % 100 != 0) || Y % 400 == 0) ? true : false); }

int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };
int dxx[8] = { 0,1,1,1,0,-1,-1,-1 };
int dyy[8] = { 1,1,0,-1,-1,-1,0,1 };

// vector注意
// vec[i][j]の形に入力を入れるとき、vecは初期化してある必要がある.

// ------------------- include, typedef, define END. -------------------


int main() {
	FAST_IO;
	// for D_OUT(str, value)  ... cout<< str <<" : "<< value <<endl;
	bool dbgF = true;

	//コードはここから書く.
	char X, Y;
	cin >> X >> Y;
	cout << (X > Y ? ">" : X < Y ? "<" : "=") << endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    //g h ; " string
    string st;
    cin>>st;
    bool b=false;
    for(int i=0;i<st.size();i++)
    {
        if(st[i]-'0'==7)
        {
            b=true;
        }
    }
    if(b)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;


     //Alhamdulilla..

}



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

using namespace std;

#define FAST() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

int main()
{
    FAST();
    int a,b,c,n,ans;
    cin >> a >> b >> c >> n;
    ans=min(a,n),n-=ans;
    n-=min(b,n);
    ans-=min(c,n);
    cout << ans;
    return 0;
}


Measured memory_bytes: 3628
#include<stdio.h>

int main(){
  int i, j, a[3], c;
  
  for (i = 0; i < 3; i++){
    scanf("%d", &a[i]);
  }
  
  for (i = 0; i < 3; i++){
    for (j = i; j < 3; j++){
      if(a[i] > a[j]){
        c = a[i];
        a[i] = a[j];
        a[j] = c;
      }
    }
  }
  
  printf("%d\n", a[0] + a[1]);
  
  return 0;
}

Measured memory_bytes: 128
n,m = map(int, input().split())

ans = [" "]*n
flag = 0

#print(ans)

for i in range(m):
    s, c = map(int, input().split())
    if (ans[s - 1] == " " or ans[s - 1] == c):
        ans[s - 1] = c
    else:
        flag = 1
        break


if (flag == 1 or (ans[0] == 0 and n!=1)):
    print(-1)
else:
    for i in range(n):
        if (ans[i] != " "):
            print(ans[i],end="")
        elif (i == 0 and n != 1):
            print(1,end="")
        else:
            print(0, end="")

    print()

Measured memory_bytes: 3188
#include <stdio.h>

int main(void)
{
	int S,h,m,s;
	scanf("%d",&S);
	h = S / 3600;
	m = S % 3600 / 60;
	s = S % 60;

	printf("%d:%d:%d\n",h,m,s);

	return 0;
}

Measured memory_bytes: 592
#!/usr/bin/env python3
import sys
import numpy as np


def solve(x: "List[int]"):
    print(np.argmin(x)+1)
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    x = [int(next(tokens)) for _ in range(5)]  # type: "List[int]"
    solve(x)

if __name__ == '__main__':
    main()


Measured memory_bytes: 26868
#include <iostream>
#include <fstream>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <iomanip>
using namespace std;
typedef long long ll;
const ll MOD = ll(1e9 + 7);

int A[500], B[500];
ll p[500][500]; // pow(x, y)
ll table[410][500];
ll dp[410][500];

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

	for(int i = 0; i < 500; i++) {
		p[i][0] = 1;
		for(int j = 1; j < 500; j++) {
			p[i][j] = (p[i][j - 1] * i) % MOD;
		}
	}

	int N, C;
	cin >> N >> C;
	for(int i = 0; i < N; i++) {
		cin >> A[i];
	}
	for(int i = 0; i < N; i++) {
		cin >> B[i];
	}

	dp[0][0] = 1;
	for(int i = 0; i < N; i++) {
		for(int c = 0; c <= C; c++) {
			ll sum = 0;
			for(int x = A[i]; x <= B[i]; x++) {
				sum = (sum + p[x][c]) % MOD;
			}
			table[i][c] = sum;
		}
		for(int j = 0; j <= C; j++) {
			for(int c = 0; j + c <= C; c++) {
				dp[i + 1][j + c] = (dp[i + 1][j + c] + dp[i][j] * table[i][c] % MOD) % MOD;
			}
		}
	}
	cout << dp[N][C] << endl;
}

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

int main()
{
    int n;
    cin >> n;
    long long L[87];
    L[0] = 2LL, L[1] = 1LL;
    for (int i = 2; i <= n; i++)
        L[i] = L[i - 2] + L[i - 1];
    cout << L[n] << endl;
}

Measured memory_bytes: 256
/*---------------------------------

 @Author:   Dicer
 @DateTime: 2019-05-15 19:53:54

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

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
inline ll qpow(ll a,ll b,ll mod){ll res=1;while(b){if(b&1)res = (res*a)%mod;a=(a*a)%mod;b>>=1;}return res;}
const double eps = 1e-8;
const int INF = 0x3f3f3f3f;
const int mod = 1e9+7;
const int MAXN = 2e5 + 7;

int main(int argc, char const *argv[])
{
	int a, b, c;
	cin >> a >> b >> c;
	cout << min(c, b/a) << endl;
	return 0;
}

Measured memory_bytes: 256
a,b,m = map(int,input().split())
ai = list(map(int,input().split()))
bi = list(map(int,input().split()))
ans = min(ai) + min(bi)
for i in range(m):
    x, y, c = map(int,input().split())
    cost = ai[x-1] + bi[y-1] - c
    ans = min(ans, cost)
print(ans)


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

#define ll long long
#define Fi first
#define Se second
#define Pb push_back
#define vi vector<int>
#define vp vector<pair<int,int>>
#define vvi vector<vector<int>>
#define vvp vector<vector<pair<int,int>>>

const int INF = 1e9;
const int MOD = 1e9+7;
using Graph = vector<vector<ll>>; //Caution!! Segmentation Fault!! Don't forget to add +1!

#define all(v) v.begin(),v.end()
#define output_s(a) printf("%s\n",(a).c_str())

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define Rep(i,n,m) for(int i=(int)(n);i<(int)(m);i++)
#define RepS(i,n,m) for(int i=(int)(n);i<=(int)(m);i++)
#define RRepS(i,n,m) for(int i=(int)(n);i>=(int)(m);i--)
#define RepA(x) for(auto &item:(x))

void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail){
    cin>>head;
    CINT(move(tail)...);
}    
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

template<typename TypeInt> //最大公約数
TypeInt GCD(TypeInt a,TypeInt b){
    if(a%b==0) return b;
    else return GCD(b,a%b);
}
template<typename TypeInt> //最小公倍数
TypeInt LCM(TypeInt a,TypeInt b){
    return a*b/GCD(a,b);
}

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

//----------------------library------------------------//

//const int dx[4]={1,0,-1,0};
//const int dy[4]={0,1,0,-1};
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 NMAX = 200;
bool flag;

bool comp(int x,int y){
    return abs(0-x)<abs(0-y);
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    CIN(X);
    int x,ans=1;
    for(int i=2;i*i<=X;i++){
        for(x=i*i;x<=X;x*=i) ans=max(ans,x);
    }
    printf("%d\n",ans);

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i <(n) ; ++i)
#define PI 3.14159265
using namespace std;
using ll = long long;
void self_max(int &a,int b){
	a = max(a,b);
}
void self_min(ll &a,ll b){
	a = min(a,b);
}

int main(){
	int n;
	ll k;
	cin >> n >> k;
	vector<int> a(n);
	vector<int> f(n);
	rep(i,n) cin >> a[i];
	rep(i,n) cin >> f[i];

	sort(a.begin(),a.end());
	sort(f.rbegin(),f.rend());

	ll l = -1, r = 1e12;
	while(l+1 < r){
		ll c = (l+r)/2;
		bool ok = [&]{
			ll s = 0;
			rep(i,n){
				s += max(0ll,a[i] - c/f[i]);
			}
			return s <= k;
		}();
		if(ok) r = c; else l=c;
	}

	cout << r << endl;
	
	return 0;
}




Measured memory_bytes: 1792
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <set>
#include <sstream>
#include <string>
#include <queue>
#include <vector>
using namespace std;

#define rep(i,n) for(int i=0; i<(n); ++i)
#define rrep(i,n) for(int i=1; i<=(n); ++i)
#define drep(i,n) for(int i=(n)-1; i>=0; --i)
#define foreach(it, v) for(typeof(v.begin()) it=v.begin(); it!=v.end(); ++it)
#define pb push_back
#define sz(x) (int)(x).size()
#define fi first
#define se second

typedef unsigned int uint;
typedef long long int ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii> vpii;
typedef set<int> si;

//MOD//
const ll MOD = 1000000007;
struct big;
big ex(big a, ll tms);
typedef struct big{
  ll val;
  big():val(0){}
  big(ll val):val((val%MOD+MOD)%MOD){}
  big& operator += (const big& obj){ (val+=obj.val)%=MOD; return *this;}
  big& operator -= (const big& obj){ (val+=MOD-obj.val)%=MOD; return *this;}
  big& operator *= (const big& obj){ (val*=obj.val)%=MOD; return *this;}
  big& operator /= (const big& obj){ (val*=ex(obj,MOD-2).val)%=MOD; return *this;}
  big operator + (const big& obj)const{ return big(*this) += obj;}
  big operator - (const big& obj)const{ return big(*this) -= obj;}
  big operator * (const big& obj)const{ return big(*this) *= obj;}
  big operator / (const big& obj)const{ return big(*this) /= obj;}
  bool operator < (const big& obj)const{ return val < obj.val;}
  bool operator == (const big& obj)const{ return val == obj.val;}
} big;
istream& operator >> (istream& i, big& obj){ i>>obj.val; return i;}
ostream& operator << (ostream& o, const big& obj){ o<<obj.val; return o;}
big ex(big obj, ll tms){
  if(!tms) return 1;
  big ret = ex(obj, tms/2);
  ret *= ret;
  return (tms&1) ? ret*obj : ret;
}
//MOD//

ll pow(ll n, int m){
  if(!m) return 1;
  ll ret = pow(n, m/2);
  ret *= ret;
  return (m&1) ? ret*n : ret;
}

template <class F, class T>
void convert(const F &f, T &t){
  stringstream ss;
  ss << f;
  ss >> t;
}


int main(){
  string s;
  cin >> s;
  int gc = 0;
  int pc = 0;
  rep(i,s.length()){
    if(s[i] == 'g')
      ++gc;
    else
      ++pc;
  }
  int ans = (gc - pc)/2;
  cout << ans << endl;
  return 0;
}


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

ll n, k;
ll v[100000];
ll DP[100000];

ll backtrack(ll pos) {

	// cout<<pos<<" ";
	if(pos >= n-1) return 0LL;

	if(DP[pos] != -1) return DP[pos];

	ll answer = INT_MAX;

	for (ll i = 1; i <= k; i++) {

		ll tmp = INT_MAX;
		if(pos+i < n) tmp = abs(v[pos] - v[pos+i]) + backtrack(pos+i);
		if(tmp != INT_MAX) answer = min(answer, tmp);
	}

	return DP[pos] = answer;
}

int main() {
		
	cin>>n>>k;
	for (ll i = 0; i < n; i++) cin>>v[i];
	memset(DP, -1, sizeof(DP));

	cout<<backtrack(0);

	return 0;
}

Measured memory_bytes: 6528
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int dx[] = { -1, 0, 1, 0 }; const int dy[] = { 0, 1, 0, -1 };

int main() {
	int n;
	cin >> n;
	vector<int> mass(n);
	REP(i, n)
		cin >> mass[i];
	vector<int> memo(n, 999999);
	memo[0] = 0;
	queue<int> Q;
	Q.push(0);
	set<int> se;
	while (!Q.empty()){
		int q = Q.front(); Q.pop();
		for (int i = 1; i < 7; i++){
			if (q + i >= n)break;
			int q2 = q;
			
			se.insert(q2);
			q2 += i;
			while (1){
				if (!EXIST(se, q2)){
					se.insert(q2);
					if (mass[q2] == 0 && memo[q2]>memo[q] + 1){
						memo[q2] = memo[q] + 1;
						Q.push(q2);
						break;
					}
					else
						q2 += mass[q2];
				}
				else
					break;
			}
		}
	}
	cout << memo[n - 1] << endl;
}

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

int main(void){

    string S;
    cin >> S;

    int n = S.length();

    int ans1=0,ans2=0;

    for (int i = 0; i < n; ++i) {
        if(S[i]-'0' == (i%2)){
            ans1++;
        } else{
            ans2++;
        }
    }

    cout<<min(ans1,ans2)<<endl;
    return 0;
}

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


void solve(std::string S, std::string T){
    cout<<T+S<<endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    std::string S;
    std::cin >> S;
    std::string T;
    std::cin >> T;
    solve(S, T);
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String args[]){
	Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      String s = sc.next();
      char[] c = s.toCharArray();
      int a = 0;
      for(int i=0; i<n-2; i++){
        if(c[i]=='A' && c[i+1]=='B' && c[i+2]=='C'){
          a++;
        }
      }
       System.out.println(a);
    }
}

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

int main(){
  int n,s=0;
  cin >> n;
  vector<int> p(n);
  int i;
  for(i=0;i<n;i++){
    cin >> p.at(i);
    if(p.at(i)==i+1){
      s++;
    }
  }
  
  if(s>=n-2){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }
}

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

const int m=1000000007;

int main(){
  int n;
  cin >> n;
  vi a(n);
  rep(i,n) cin >> a[i];
  sort(a.begin(),a.end());
  int f=n%2;
  ll ans=1;
  if(f==1){
    if(a[0]!=0){cout << 0;return 0;}
    for(int i=1;i<n;i++){
      if(a[i]!=(i+1)/2*2){cout << 0;return 0;}
    }
    rep(i,(n-1)/2){ans*=2;ans%=m;}
    cout << ans;
  }else{
    for(int i=0;i<n;i++){
      if(a[i]!=i/2*2+1){cout << 0;return 0;}
    }
    rep(i,n/2){ans*=2;ans%=m;}
    cout << ans;
  }
  
  return 0;
}

Measured memory_bytes: 3696
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x-I .)
#define show(obj) {for(auto x:obj)cout<<x<<' ';cout<<endl;}
#define line "----------"
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> LP;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

int main(){
    string s;
    cin >> s;
    for(int bit = 0; bit < (1<<4); ++bit){
        bool exi[4] = {false};
        rep(i,4){
            if(bit & (1 << i))exi[i] = true;
        }
        string now;
        if(exi[0])now += 'A';
        now += "KIH";
        if(exi[1])now += 'A';
        now += "B";
        if(exi[2])now += 'A';
        now += "R";
        if(exi[3])now += 'A';
        if(s == now){
            cout << "YES" << endl;
            return 0;
        }
    }
    cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 3604
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		String aa=sc.next();
		int mojisu=aa.length();
		String crib=sc.next();
		int c_moji=crib.length();
		int point=-1;

		for(int i=0; i<=mojisu-c_moji; i++) {
			boolean mj=true;
			String a=aa.substring(i,i+c_moji);

			for(int j=0; j<c_moji; j++) {
				if(a.charAt(j)==crib.charAt(j) || a.charAt(j)=='?') {
					//
				}
				else {
					mj=false;
				}
			}
			if(mj==true) {
				point=i;
			}
		}

		if(point==-1) {
			System.out.println("UNRESTORABLE");
		}

		else {
			char[] bb=new char[mojisu];

			for(int i=0; i<mojisu; i++) {
				bb[i]=aa.charAt(i);

				if(i>=point && i<point+c_moji) {
					bb[i]=crib.charAt(i-point);
				}

				if(bb[i]=='?') {
					bb[i]='a';
				}
			}

			String moto="";
			for(int i=0; i<mojisu; i++) {
				moto=moto+""+bb[i];
			}
			System.out.println(moto);
		}
	}
}

Measured memory_bytes: 21844