akhauriyash/Code-Regression huggingface dataset:
n,ma,mb=map(int,input().split())
abc=[list(map(int,input().split())) for _ in range(n)]

wmax=400
inf=10**10
dp=[[[inf]*(wmax+1) for _ in range(wmax+1)] for _ in range(n+1)]
dp[0][0][0]=0

for i in range(n):
    a,b,c=abc[i]
    for j in range(wmax+1):
        for k in range(wmax+1):
            dp[i+1][j][k]=dp[i][j][k]

            if j>=a and k>=b:
                dp[i+1][j][k]=min(dp[i+1][j][k],dp[i][j-a][k-b]+c)

ans=inf

for j in range(1,wmax+1):
    for k in range(1,wmax+1):
        if dp[n][j][k]>=inf:
            continue

        if ma*k==mb*j:
            ans=min(ans,dp[n][j][k])

if ans==inf:
    print(-1)
else:
    print(ans)


Measured memory_bytes: 126708
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <fstream>
#include <cmath>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)
using namespace std;
typedef vector<ll> vec;
typedef vector<vec> mat;

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

    ll X;
    cin >> X;
    vec dp(100010, 0);
    dp[0] = 1;
    Rep (i, 100001) {
        if (dp[i] == 1) {
            dp[i+100] = 1;
            dp[i+101] = 1;
            dp[i+102] = 1;
            dp[i+103] = 1;
            dp[i+104] = 1;
            dp[i+105] = 1;
        }
    }

    cout << dp[X] << endl;
}

Measured memory_bytes: 1024
N, A, B = map(int, input().split())
S = list(input())
cnt = 0
b_cnt = 0

for i in range(N):
    if S[i] == 'a':
        S[i] = 'Yes'
        cnt += 1
    elif S[i] == 'b':
        if b_cnt >= B:
            continue
        S[i] = 'Yes'
        cnt += 1
        b_cnt += 1

    if cnt == A + B:
        break

ans = ['No' if j != 'Yes' else j for j in S]

for k in range(N):
    print(ans[k])

Measured memory_bytes: 5472
//Dragon_warrior7(IITK)
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define pb push_back
#define nl cout << '\n'
#define sor(x) sort(x.begin(), x.end())
#define rev(v) reverse(v.begin(), v.end())
#define lb(v, temp) lower_bound(v.begin(), v.end(), temp)
#define ub(v, temp) upper_bound(v.begin(), v.end(), temp)
#define fi first
#define se second
#define llmax 1000000000000000000
#define deb(x) cout << #x << " " << x << "\n"
#define pll pair<ll, ll> 
#define vll vector<ll> 
#define rub cout << "\n------------------------------------\n"
typedef  tree < int ,  null_type ,  greater<int> ,  rb_tree_tag ,  tree_order_statistics_node_update > oset;
void read(vector<ll> &v)
{
	for (int i = 0; i < v.size(); i++)
		cin >> v[i];
}

void print(vector<ll> v)
{
	for (int i = 0; i < v.size(); i++)
		cout << v[i] << " ";
}
ll n,m,a,b,c,t,temp,x,y;
string str;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n;
	n*=2;
	vll v(n);
	read(v);
	sor(v);
	ll sum=0;
	for(int i=0;i<n;i+=2)
	{
	    sum+=v[i];
	}
	cout<<sum;
	
	
	
	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MM = 1000000000;
const int MOD = MM + 7;
const int MAX = 510000;
#define rep(i, n) for(ll i=0; i<n; i++)
#define Rep(i, j, n) for(ll i=j; i<n; i++)
#define all(vec) vec.begin(), vec.end()
template<class T> inline bool chmin(T& a, T b) {if(a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if(a < b) {a = b; return true;} return false;}
const ll INF = 1LL << 60;
const double pi = acos(-1.0);

int main() {
    ll n; cin >> n;
    map<ll, ll> d;
    rep(i, n) {
        ll a; cin >> a;
        d[a]++;
    }
    ll m; cin >> m;
    rep(i, m) {
        ll a; cin >> a;
        if(!d.count(a) || d[a] <= 0) {
            cout << "NO" << endl;
            return 0;
        }
        d[a]--;
    }
    cout << "YES" << endl;
}

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

// 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)
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  vector<vector<P> > vec(n);
  rep(i, n) {
    cin >> a[i];
    int x, y;
    rep(_, a[i]) {
      cin >> x >> y;
      vec[i].push_back(make_pair(x - 1, y));
    }
  }
  int ans = 0;
  for (int i = 0; i < (1 << n); i++) {
    bitset<15> s(i);
    bool contradiction = false;
    rep(j, n) {
      if (s.test(j)) {
        rep(k, a[j]) {
          P p = vec[j][k];
          if ((p.second ^ s[p.first]) == 1) {
            contradiction = true;
            break;
          }
        }
      }
      if (contradiction) break;
    }
    if (!contradiction) {
      ans = max((int)s.count(), ans);
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3620
import java.util.*;
public class Main {
	public static void main(String[] args)
	{
		//変数
		int count=0;
		boolean sw=false;
		int answer=0;
		int sum=0;
		List<Integer> h=new ArrayList<Integer>();
		//int t[]=new int[(int)Math.pow(10,5)];
		int max=Integer.MIN_VALUE;
		int min=Integer.MAX_VALUE;
		//入力
		Scanner sc = new Scanner(System.in);
		int N=sc.nextInt();
		int M=sc.nextInt();
		int C=sc.nextInt();
		int A[][]=new int[N][M];
		List<Integer> B=new ArrayList<Integer>();
		for(int i=0;i<M;i++)
		{
			B.add(sc.nextInt());
		}
		for(int i=0;i<N;i++)
		{
			for(int j=0;j<M;j++)
			{
				A[i][j]=sc.nextInt();
			}
		}
		
		//処理
		while(sw==false)
		{
			for(int i=0;i<M;i++)
			{
				h.add(A[count][i]);
			}
			for(int i=0;i<M;i++)
			{
				int x=B.get(i);
				int y=h.get(i);
				sum+=x*y;
			}
			sum+=C;
			if(sum>0)
			{
				answer++;
			}
			h.clear();
			sum=0;
			count++;
			if(count==N)
			{
				sw=true;
			}
		}
		// 出力
		//System.out.println(Arrays.toString(X));
		//System.out.println(Arrays.deepToString(a));
		//System.out.println(Arrays.toString(A.toArray()));
		//System.out.println("-------------------");
		System.out.println(answer);
	}
}

Measured memory_bytes: 23252
using System;
using System.Collections.Generic;
using System.Text;

namespace AtCoder
{
  class Program
  {
    static void Main(string[] args)
    {
      int A = int.Parse(Console.ReadLine());
      int B = int.Parse(Console.ReadLine());
      int C = int.Parse(Console.ReadLine());
      int X = int.Parse(Console.ReadLine());
      int amount = 0;
      int c = 0;
      NewMethod(X, amount, A, B, C, ref c);
      Console.WriteLine(c);
      //Console.ReadLine();
    }

    private static void NewMethod(int X, int amount, int A, int B, int C, ref int c)
    {
      if(amount == X)
        c++;

      if(amount >= X)
        return;

      if(A > 0 && amount + 500 <= X)
      {
        NewMethod(X, amount + 500, A - 1, B, C, ref c);
      }
      if(B > 0 && amount + 100 <= X)
      {
        NewMethod2(X, amount + 100, A, B - 1, C, ref c);
      }
      if(C > 0 && amount + 50 <= X)
      {
        NewMethod3(X, amount + 50, A, B, C - 1, ref c);
      }
    }
    private static void NewMethod2(int X, int amount, int A, int B, int C, ref int c)
    {
      if(amount == X)
        c++;

      if(amount >= X)
        return;

      if(B > 0 && amount + 100 <= X)
      {
        NewMethod2(X, amount + 100, A, B - 1, C, ref c);
      }
      if(C > 0 && amount + 50 <= X)
      {
        NewMethod3(X, amount + 50, A, B, C - 1, ref c);
      }
    }
    private static void NewMethod3(int X, int amount, int A, int B, int C, ref int c)
    {
      if(amount == X)
        c++;

      if(amount >= X)
        return;

      if(C > 0 && amount + 50 <= X)
      {
        NewMethod3(X, amount + 50, A, B, C - 1, ref c);
      }
    }
  }
}

Measured memory_bytes: 27500
y,x=map(int,input().split())
s=[]
ans='Yes'
for i in range(y):
    s.append(list(input()))
for j in range(y):
    for k in range(x):
        if s[j][k]=='#':
            if j==y-1:
                if k==x-1:
                    if s[j][k]!=s[j-1][k] and s[j][k]!=s[j][k-1]:
                        ans='No'
                        break
                elif k==0:
                    if s[j][k]!=s[j-1][k] and s[j][k]!=s[j][k+1]:
                        ans='No'
                        break
                else:
                    if s[j][k]!=s[j-1][k] and s[j][k]!=s[j][k+1] and s[j][k]!=s[j][k-1]:
                        ans='No'
                        break
            elif j==0:
                if k==x-1:
                    if s[j][k]!=s[j+1][k] and s[j][k]!=s[j][k-1]:
                        ans='No'
                        break
                elif k==0:
                    if s[j][k]!=s[j+1][k] and s[j][k]!=s[j][k+1]:
                        ans='No'
                        break
                else:
                    if s[j][k]!=s[j+1][k] and s[j][k]!=s[j][k+1] and s[j][k]!=s[j][k-1]:
                        ans='No'
                        break
            else:
                if k==x-1:
                    if s[j][k]!=s[j+1][k] and s[j][k]!=s[j][k-1] and s[j][k]!=s[j-1][k]:
                        ans='No'
                        break
                elif k==0:
                    if s[j][k]!=s[j+1][k] and s[j][k]!=s[j][k+1] and s[j][k]!=s[j-1][k]:
                        ans='No'
                        break
                else:
                    if s[j][k]!=s[j+1][k] and s[j][k]!=s[j][k+1] and s[j][k]!=s[j][k-1] and s[j][k]!=s[j-1][k]:
                        ans='No'
                        break
print(ans)


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


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
	int N, M;
	cin >> N >> M;

	int ball[3][N + 1];
	rep(i, 3) rep(j, N + 1) ball[i][j] = 0;
	ball[0][1] = 1;
	REP(i, 2, N) ball[1][i] = 1;
	REP(i, 1, N) ball[2][i] = ball[1][i] + ball[0][i];
	rep(i, M) {
		int x, y;
		cin >> x >> y;
		ball[2][x]--;
		ball[2][y]++;
		if (ball[1][x] == 0) {
			ball[0][y] = 1;
			ball[0][x] = 0;
		}
		else if (ball[0][x] == 0) {
			ball[1][y]++;
			ball[1][x]--;
		}
		else {
			ball[1][y]++;
			ball[0][y] = 1;
		}
		if (ball[2][x] == 0) {
			ball[1][x] = 0;
			ball[0][x] = 0;
		}
		/*
		rep(i, N) {
			cout << ball[2][i + 1] << ": red:" << ball[0][i + 1] << endl;
		}
		cout << endl;
		//*/
	}
	int ans = 0;
	REP(i, 1, N) {
		// if (ball[0][i]) cout << i << endl;
		ans += ball[0][i];
	}

	cout << ans << endl;



    return 0;
}


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

int N, K;
int x[114514];

int main(void) {
	int i;
	int mizuhasu = 1111111111;
	if (scanf("%d%d", &N, &K) != 2) return 1;
	for (i = 0; i < N; i++) {
		if (scanf("%d", &x[i]) != 1) return 1;
	}
	for (i = K - 1; i < N; i++) {
		int l = i - (K - 1), r = i;
		int satorina;
		satorina = abs(x[l]);
		if (abs(x[r]) < satorina) satorina = abs(x[r]);
		satorina += x[r] - x[l];
		if (satorina < mizuhasu) mizuhasu = satorina;
	}
	printf("%d\n", mizuhasu);
	return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;
int main(){
    int n,m,c,ans; cin >> n>>m>>c;
    ans=0;
    vector<int> b(m);
    for(int i=0;i < m;i++){
        cin >> b[i];
    }
    for(int i=0; i < n;i++){
        int sum=0;
        for(int j=0;j<m;j++){
            int t; cin>>t;
            sum += t*b[j];
        }
        if ((sum + c) > 0 ){
            ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}

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

int n,p;
map <int,int> mp;  

int myPow (int x,int y) {
    int res = 1;
    for (int i = 0;i < y;i++) {
        res*= x;
    }
    return res;
}

void primeFactors(int n)  
{  
    while (n % 2 == 0)  
    {  
        mp[2]++;
        n = n/2;  
    }  
    for (int i = 3; i <= sqrt(n); i = i + 2)  
    {  
        while (n % i == 0)  
        {  
            mp[i]++;
            n = n/i;  
        }  
    }  
    if (n > 2)  
        mp[n]++; 
}  

signed main(){
    // freopen("NAME.INP", "r" , stdin);
    // freopen("NAME.OUT", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cin >> n >> p;
    primeFactors(p);
    int res = 1;
    for (auto i: mp) {
        int x = i.second / n;
        if (x > 0) {
            res*= myPow(i.first,x);
        }
    }
    cout << res << endl;

    return 0;
}

Measured memory_bytes: 3660
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#define rep(i, n) for(int i = 0; i < n; i++)
#define pii pair<int, int>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const int INF = (1 << 29);

int n, m, R, a, b, c, ans;
vector<vector<int>> d(201, vector<int>(201));
vector<int> r(9), used(9);

void dfs(int depth, int last, int dist) {

    if(depth == R) {
        if(ans > dist) {
            ans = dist;
            return;
        }
    }

    rep(i, R) {
        if(!used[i]) {
            used[i] = 1;
            if(last == -1) {
                dfs(depth+1, i, 0);
            }
            else {
                dfs(depth+1, i, dist + d[r[last]][r[i]]);
            }
            used[i] = 0;
        }
    }
}

int main() {
    ans = INF;
    cin >> n >> m >> R;

    rep(i, n) {
        rep(j, n) {
            if(i != j) {
                d[i][j] = INF;
            }
        }
    }

    rep(i, R) {
        cin >> r[i];
        r[i]--;
    }

    rep(i, m) {
        cin >> a >> b >> c;
        a--;  b--;
        if(d[a][b] > c) {
            d[a][b] = d[b][a] = c;
        }
    }

    rep(k, n) {
        rep(i, n) {
            rep(j, n) {
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }

    dfs(0, -1, 0);

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

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

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

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

// @author: pashka

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

    int a, b, c;
    cin >> a >> b >> c;
    cout << (((a + b + c) >= 22) ? "bust" : "win");

    return 0;
}

Measured memory_bytes: 256
h,w = map(int,input().split())
k = []
h_remove = []
w_remove = []
for i in range(h):
    ls = input()
    if ls.count(".") == w:
        h_remove.append(i)
    k.append(ls)
for i in range(w):
    now = ""
    for j in range(h):
        now += k[j][i]
    if now.count(".") == h:
        w_remove.append(i)
h_remove = set(h_remove)
w_remove = set(w_remove)
for i in range(h):
    ans = ""
    if i in  h_remove:
        continue
    else:
        for j in range(w):
            if j in w_remove:
                continue
            else:
                ans += k[i][j]
        print(ans)

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

struct Benri {
    Benri() {
        std::cin.tie(0); ios::sync_with_stdio(false);
        cout << fixed << setprecision(12);
    }
} benri;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vll = vector<long long>;
using pll = pair<ll, ll>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define MOD 1000000007
#define MOD2 998244353

typedef complex<long double> P;
namespace std {
bool operator < (const P& a, const P& b) {
    return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
}
}

int main() {
    int N; cin >> N;
    vector<pair<long double, pll>> AP(N); // arg, point
    rep(i, N) {
        ll x, y; cin >> x >> y;
        AP[i].S = pll(x, y);
        AP[i].F = arg(P((long double)x, (long double)y));
    }

    sort(all(AP));

    ll ans = 0;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            pll tmp(0, 0);
            for (int k = i ; k <= i + j; k++ ) {
                int l = k % N;
                tmp.F += AP[l].S.F;
                tmp.S += AP[l].S.S;
            }
            //cout << i << " " << j << " " << abs(tmp) << endl;
            ans = (ans > tmp.F * tmp.F + tmp.S* tmp.S ? ans : tmp.F * tmp.F + tmp.S* tmp.S) ;
        }
    }

    long double num = sqrt((long double)ans);

    cout << num << endl;

}





Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
  int N;
  cin >> N;
  int A[N], T[N];
  for(int i = 0; i < N; ++i){
    cin >> T[i];
  }
  for(int i = 0; i < N; ++i){
    cin >> A[i];
  }
  if(N == 1){
    if(A[0] == T[0]) cout << 1 << endl;
    else cout << 0 << endl;
    return 0;
  }
  int H[N][2];
  for(int i = 0; i < N; ++i){
    H[i][1] = min(T[i],A[i]);
    H[i][0] = 1;
  }
  H[0][0] = T[0];
  H[N-1][0] = A[N-1];
  long long int ans = 1LL, mod = 1000000007LL;
  for(int i = 1; i < N-1; ++i){
    bool f = false;
    if(T[i-1] != T[i]){
      H[i][0] = T[i];
      f = true;
    }
    if(A[i] != A[i+1]){
      H[i][0] = A[i];
    }
  }
  
  for(int i = 0; i < N; ++i){
    ans *= max(0LL,(long long int)(H[i][1]-H[i][0]+1));
    ans %= mod;
  }
  
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1792
// <head>
    #include <bits/stdc++.h>
    using namespace std;
    using ll = long long;
    using vi = vector<int>;
    using vll = vector<ll>;
    using pi = pair<int, int>;
    using pll = pair<ll,ll>;
    template <class T> using vv = vector<vector<T>>;
    #define rep(i,n) for(int i = 0; i < (int)(n); i++)
    #define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
    #define rrep(i,n) for(int i = (int)(n)-1; i >= 0; i--)
    #define rrepi(i,a,b) for(int i = (int)(b)-1; i >= (int)(a); i--)
    const int INF = 1002003004;
    const ll LINF = 1002003004005006007ll;
    struct preprocess{preprocess()
    {cin.tie(nullptr);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}}____;
// </head>

// <library>
    template<typename T>
    struct BIT {
    int n;
    vector<T> d;
    BIT(int n=0):n(n),d(n+1) {}
    void add(int i, T x=1) {
        for (i++; i <= n; i += i&-i) {
        d[i] += x;
        }
    }
    T sum(int i) {
        T x = 0;
        for (i++; i; i -= i&-i) {
        x += d[i];
        }
        return x;
    }
    T sum(int l, int r) {
        return sum(r-1) - sum(l-1);
    }
    };
// </library>
const int MX = 200005;
int in[MX], out[MX], k;
vector<int> to[MX];
void dfs(int v, int p=-1){
    in[v] = k++;
    for (int u: to[v]){
        if (u==p) continue;
        dfs(u,v);
    }
    out[v] = k;
}
    vector<ll> vs[MX];
ll f(ll n){
    return n*(n+1)/2;
}
int main(){
    int n; cin >> n;
    vector<ll> c(n);

    for (int i = 0; i < n; i++){
        cin >> c[i];
        vs[c[i]-1].emplace_back(i);
        
    }
    for (int i = 0; i < n-1; i++){
        int a,b;
        cin >> a >> b;
        a--; b--;
        to[a].emplace_back(b);
        to[b].emplace_back(a);
    }
    dfs(0);
    ll tot=f(n);
    BIT<int> d(n);
    for (int i = 0; i < n; i++){
        d.add(i,1);
    }
    for (int i = 0; i < n; i++){
        ll ans = tot;
        vector<ll> nvs = vs[i];
        sort(nvs.begin(), nvs.end(), [&](int a, int b){
            return in[a] > in[b];
        });
        vector<pair<ll, ll>> history;
        for (auto j: nvs){
            ll cnt = 1;      
            for(auto k: to[j]){
                if(in[j]>in[k])continue;
                ll num = d.sum(in[k],out[k]);
                ans -= f(num);
                cnt += num;
            }
            d.add(in[j],-cnt);
            history.emplace_back(make_pair(in[j],cnt));
        }
        ans -= f(d.sum(0,n));
        cout << ans << '\n';
        for (auto p:history){
            d.add(p.first,p.second);
        }
    }
    
}


Measured memory_bytes: 37456
//#include<bits/stdc++.h>	// 全てのヘッダーファイルをinclude
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<set>
#define REP(i,n) for(int i=0;i<n;i++)
#define REPR (i,n) for(int i=n;i>0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
const int MOD{ int(1e9 + 7) };	// int 1000000007
const int inf{ int(1e9) };	// inf = 1000000000 // 1e9 はdouble型
using namespace std;
typedef long long ll;


int main(void) {
	int n;
	string s;
	cin >> n >> s;
	int x = 0, max_x = 0;
	REP(i, n) {
		x = (s[i] == 'I' ? x + 1 : x - 1);
		max_x = max(max_x, x);
	}
	cout << max_x << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <array>
#include <vector>
#include <map>
#include <utility>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <string>
#include <limits.h>
#include <algorithm>

using namespace std;

int main(){
    
    int n;
    cin >> n;
    vector<int> a;
    int counter[100000] = {0};
    set<int> s;
    for (int i =0 ; i < n; i++) {
        int aa;
        cin >>aa;
        a.push_back(aa);
        counter[aa] ++;
        s.insert(aa);
    }
    
    size_t res = s.size();
    
    int guusuu = 0;
    for (int x : s) {
        if (counter[x] % 2 == 0) {
            guusuu ++;
        }
    }
    res -= guusuu%2 == 1 ? 1 : 0;
    cout << res << endl;
    
    return 0;
}


Measured memory_bytes: 5752
/*input
39
RBRBGRBGGBBRRGBBRRRBGGBRBGBRBGBRBBBGBBB
*/
/*

**************************
*						 *
* AUTHOR :: knight_coder *
*						 *
**************************

*/
#include<bits/stdc++.h>
#define lld          long long int
#define pb          push_back
#define ppb         pop_back
#define	endl		'\n'
#define mii         map<lld,lld>
#define msi         map<string,lld>
#define mis         map<lld, string>
#define mpi         map<pair<lld ,lld >,lld >
#define pii         pair<lld,lld>
#define vi          vector<lld>
#define vpi 		vector<pii>
#define vs          vector<string>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (lld)x.size()
#define hell        1000000007
#define rrep(i,m,n)	for(lld i=m;i>=n;i--)
#define rep(i,m,n)	for(lld i=m;i<n;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define what_is(x)  cerr << #x << " is " << x << endl;
#define pr(x) 		cout<< x << " ";
#define pre(x)		cout<< x << endl ;
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
std::mt19937_64 rng(std::chrono::steady_clock::now().time_since_epoch().count());
template<typename T>
using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>; 
//change null_type to get ordered_map
#define N  100005
#define DEC(N)	cout << std::fixed; cout << setprecision(N);
void solve()
{
	lld n;
	cin >> n;
	string s;
	cin >> s;
	rep(i,0,s.size()){
		if(s[i]=='R'){
			s[i]='0';
		}
		else if(s[i]=='G'){
			s[i]='1';
		}
		else{
			s[i]='2';
		}
	}
	lld cnt[n+1][3];
	rep(i,0,n+1){
		rep(j,0,3){
			cnt[i][j]=0;
		}
	}
	rep(j,0,3){
		rrep(i,n-1,0){
			cnt[i][j]=((s[i]-'0')==j)+cnt[i+1][j];
		}
	}
	lld ans=0;
	rep(i,0,n){
		rep(j,i+1,n){
			if(s[i]==s[j]){
				continue;
			}
			lld diff=(j-i);			
			lld notposs=j+diff;
			lld t=3-(s[i]-'0')-(s[j]-'0');
			lld cn=cnt[j+1][t];
			if(notposs<n && (s[notposs]-'0')==t){
				cn--;
			}
			ans+=cn;
		}
	} 
	cout << ans << endl;
}
signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int tests=1;
	//cin>>tests;
	while(tests--)
	{
		solve();
	}
}

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

#define g(a,b,c) for(int a=b;a<c;a++)
#define ff(a,b,c) for(int a=c;a>b;a--)
#define ffk(a,b,c) for(int a=b;a<=c;a++)
#define fff(a,b,c) for(int a=c;a>=b;a--)
int main (){
double  t,x;
cin>>t>>x;
cout<<fixed<<setprecision(10)<<t/x;
}


Measured memory_bytes: 256
N=map(int,input().split())
A=sorted(list(map(int,input().split())))
B=list(map(int,input().split()))
C=sorted(list(map(int,input().split())))

def countA(target,L):
  ok=-1
  ng=len(L)
  while abs(ok-ng)>1:
    mid=(ok+ng)//2
    if L[mid]<target:
      ok=mid
    else:
      ng=mid
  return (ok+1)

def countC(target,L):
  ok=len(L)
  ng=-1
  while abs(ok-ng)>1:
    mid=(ok+ng)//2
    if L[mid]>target:
      ok=mid
    else:
      ng=mid
  return len(L)-ok

ans=0
for i in range(len(B)):
  data=B[i]
  ans+=(countA(data,A)*countC(data,C))
  
print(ans)


Measured memory_bytes: 24008
#include<stdio.h>
int main(){
int a, b,c;
  scanf("%d %d %d",&a,&b,&c);
  if (a==b && b==c){
  printf("No");
  }else if(a-b==0 || b-c==0 || c-a==0){
  printf("Yes");
  }else{
   printf("No");
  }
  return 0;
}

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

int main(){
  string s;
  cin >> s;
  int a_place = 0, z_place = 0;
  for(int i = 0; i < s.length(); i++){
    if(s[i] == 'A'){
      a_place = i;
      break;
    }
  }
  for(int i = s.length(); i >= 0; i--){
    if(s[i] == 'Z'){
      z_place = i;
      break;
    }
  }
  cout << z_place - a_place + 1 << endl;
  return 0;
}

Measured memory_bytes: 3776
from itertools import accumulate
from collections import Counter
n=int(input())
a=[int(i) for i in input().split()]
#0~1,0~2,…と総和を求めていく
b=list(accumulate([0]+a))
#総和の種類ごとにカウント
count=Counter(b)
#総和を多い順に並べる 形式:[(総和,個数)]
count_most=count.most_common()
ans=0
for i in count_most:
    if i[1]>1:
        ans+=i[1]*(i[1]-1)//2
print(ans)

Measured memory_bytes: 48144
#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
constexpr long long int mod = 1000000007;


//M*X+R=Y

int main() {
	int A, B;
	cin >> A >> B;
	if (A > B)cout << "safe";
	else cout << "unsafe";
}

Measured memory_bytes: 3616
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define mt make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;

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

    int N;
    while(cin >> N) {
        vll a(N), b(N);
        rep(i, N) {
            cin >> a[i] >> b[i];
        }
        ll ad = 0;
        for(int i = N - 1; i >= 0; --i) {
            ad += (b[i]-(a[i] + ad) % b[i])%b[i];
        }
        cout << ad << endl;
    }
}


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

using namespace std;

int main(int argc, const char *argv[]) {
  string S;
  cin >> S;
  if (S.compare("BBB") == 0 || S.compare("AAA") == 0) {
    cout << "No" << endl;
  }else{
    cout << "Yes" << endl;
  }
  return 0;
}


Measured memory_bytes: 888
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=1e5+5;
int main()
{
    map<ll,bool>vis;
    bool valid=0;
    ll n,m;
    cin>>n>>m;
    while(m--)
    {
        ll a,b;
        cin>>a>>b;
        if(a==1)
        {
            if(vis[b])
                valid=1;
            vis[b]=1;
        }
        else if(b==n)
        {
            if(vis[a])
            {
                valid=1;
            }
            vis[a]=1;
        }
    }
    if(valid)
        cout<<"POSSIBLE"<<endl;
    else
        cout<<"IMPOSSIBLE"<<endl;
    return 0;
}


Measured memory_bytes: 16072
#include <stdio.h>

int main() {
	int n;
	int a[1000000] = {};
	int min;
	int max = -1000000000;

	scanf("%d", &n);
	for(int i = 0; i < n; i++)
		scanf("%d", &a[i]);

	min = a[0];

	for(int j = 1; j < n; j++) {
		if(max < a[j] - min) {
			max = a[j] - min;
		}
		if(min > a[j]) {
			min = a[j];
		}
	}

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


Measured memory_bytes: 6664
/*
    Problem 20
    https://atcoder.jp/contests/abc077/tasks/arc084_a
*/
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <list>
#include <set>
#include <stack>
#include <cctype>
#include <cmath>
#include <bitset>

using namespace std;
/* typedef */
typedef long long ll;
/* constant */
/* global variables */
/* function */
/* main */
int main(){
    int N;
    cin >> N;
    vector<int> A(N), B(N), C(N);
    for (int i = 0; i < N; i++) scanf("%d", &A[i]);
    for (int i = 0; i < N; i++) scanf("%d", &B[i]);
    for (int i = 0; i < N; i++) scanf("%d", &C[i]);
    sort(A.begin(), A.end());
    sort(C.begin(), C.end());
    ll ans = 0;
    for (int i = 0; i < N; i++) {
        ll candidateA = lower_bound(A.begin(), A.end(), B[i]) - A.begin();
        ll candidateC = upper_bound(C.begin(), C.end(), B[i]) - C.begin();
        candidateC = N - candidateC;
        ans += candidateA * candidateC;
    }
    cout << ans << '\n';
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
char s[100005];
int sum[26];
bool check(int x)
{
    for (int i = 0; i < 26; ++i) if (sum[i] > x) return 1;
    return 0;
}
int main()
{
    bool exist = 0;
    scanf("%s", s);
    int ls = strlen(s), ansl = -1, ansr = -1;
    for (int i = 0; i < 26; ++i){
        int sum = 0, sumo = 0, l = -1;
        for (int j = 0; j < ls; ++j){
            if (s[j] - 'a' == i) ++sum;
            else ++sumo;
            if (sumo > sum){
                sum = sumo = 0;
                l = j;
            }
            if (j - l < 2) continue;
            else{
                if (sum > (j - l) / 2){
                    ansl = l + 2, ansr = j + 1;
                    exist = 1;
                    break;
                }
            }
        }
        if (exist) break;
    }
    printf("%d %d\n", ansl, ansr);
    return 0;
}


Measured memory_bytes: 384
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <cmath>
using namespace std;

#define FOR(i,s,e) for (int i = int(s); i != int(e); i++)
#define FORIT(i,c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define ISEQ(c) (c).begin(), (c).end()

int main(){
	string s;
	cin >> s;
	int c[100] = {0};

	FOR(i,0,s.length()){
		c[s[i]-'a']++;
	}

	bool check = true;
	FOR(i,0,100){
		if (c[i] % 2 != 0) check = false;
	}

	string ans = "Yes";
	if (!check) ans = "No";

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


Measured memory_bytes: 256
#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());

    cout << vec.at(N/2)-vec.at(N/2 -1);
    
 
 }

Measured memory_bytes: 640
s = input()
nums = [int(s[0]+s[1]), int(s[2]+s[3])]
if nums[0] >= 1 and nums[0] <= 12:
  month = True
else:
  month = False
if nums[1] >= 1 and nums[1] <= 12:
  if month:
    print("AMBIGUOUS")
  else:
    print("YYMM")
else:
  if month:
    print("MMYY")
  else:
    print("NA")

Measured memory_bytes: 3060
s=list(map(int,input().split()))
a=s[2]%s[1]
d=s[2]//s[1]
if a==s[1]-1:
  b=int((s[0]*a)//s[1])
  c=int(a//s[1])*s[0]
  print(b-c)
else:
  if d==0:
    b=int((s[0]*a)//s[1])
    c=int(a//s[1])*s[0]
    print(b-c)
  else:
    a=s[2]-a-1
    b=int((s[0]*a)//s[1])
    c=int(a//s[1])*s[0]
    print(b-c)

Measured memory_bytes: 9176
from collections import deque
import sys
input = sys.stdin.readline

N, Q = [int(i) for i in input().split()]

E = [[] for _ in range(N)]
for a, b in (map(int, input().split()) for _ in range(N - 1)):
    E[a - 1].append(b - 1)
    E[b - 1].append(a - 1)

ans = [0] * N
for p, x in (map(int, input().split()) for _ in range(Q)):
    ans[p - 1] += x

visited = [False] * N
Q = deque([0])
while Q:
    a = Q.popleft()
    visited[a] = True
    for e in E[a]:
        if visited[e]:
            continue
        ans[e] += ans[a]
        Q.append(e)

print(*ans)


Measured memory_bytes: 56168
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
using namespace std;
#define debug(x) std::cerr << #x << " = " << (x) << std::endl
typedef long long LL;
const int MAXN = 2e5+17;
char mp[100][100];
int main(int argc ,char const *argv[])
{
	#ifdef noob
	freopen("Input.txt","r",stdin);freopen("Output.txt","w",stdout);
	#endif	
	int n,m;
	cin>>n>>m;
	int dap = 0;
	int k1 = ceil(1.0*n/50),k2;
	if(n>1) m-=1;
	k2 = k2=ceil(1.0*m/50);
	if(m>0) n--;
	k1 = ceil(1.0*n/50);
	while(k1--) 
	{
		n-=50;
		for (int i = 0; i < 100; ++i)
		{
			for (int j = 0; j < 3; ++j)
			{
				int tj= j+dap*3;
				if(((tj-1)%3==0)&&i&1) mp[i][tj]='.';
				else mp[i][tj]='#';
			}
		}
		if(n<0)
		{
			int tms = -1*n;
			for (int i = 0; i < 100; ++i)
			{
				for (int j = 0; j < 3; ++j)
				{
					int tj=j+dap*3;
					if(mp[i][tj]=='.'&&tms>0) 
					{
						mp[i][tj] = '#'; 
						tms--;
					}
				}
			}
			dap++;
			break;
		}
		dap++;
	}
	while(k2--) 
	{
		m-=50;
		for (int i = 0; i < 100; ++i)
		{
			for (int j = 0; j < 3; ++j)
			{
				int tj= j+dap*3;
				if(((tj-1)%3==0)&&i&1) mp[i][tj]='#';
				else mp[i][tj]='.';
			}
		}
		if(m<0)
		{
			int tms = -1*m;
			for (int i = 0; i < 100; ++i)
			{
				for (int j = 0; j < 3; ++j)
				{
					int tj=j+dap*3;
					if(mp[i][tj]=='#'&&tms>0) 
					{
						mp[i][tj] = '.'; 
						tms--;
					}
				}
			}
			dap++;
			break;
		}
		dap++;
	}
	cout<<100<<" "<<dap*3<<endl;
	for (int i = 0; i < 100; ++i)
		cout<<mp[i]<<endl;
	return 0;	
}

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

int countDivisor(int n){
  int cnt = 2;
  for(int i=2; i<= n/2; i++){
    if( n%i == 0) cnt++;
  }
  return cnt;
}

int main(){

  int N,ans;
  cin >> N;
  ans = 0;
  for(int i = 1; i<=N; i++){
    if(i%2 == 0)continue;
    if(countDivisor(i) == 8) ans++;
  }
  cout << ans << endl;

  return 0;
}

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

using namespace std;

int main()
{
//    freopen("in.txt","r",stdin);
//    freopen("out.txt","w",stdout);

    vector<int> v;
    v.clear();

    int q;
    cin>>q;
    while(q--)
    {
        int m;
        cin>>m;

        switch(m)
        {
            case 0:
                int x;
                cin>>x;
                v.push_back(x);
                break;
            case 1:
                int p;
                cin>>p;
                cout<<v[p]<<endl;
                break;
            case 2:
                v.pop_back();
                break;
        }
    }
}



Measured memory_bytes: 3936
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}

type Animal struct {
	color int
	size  int
}

type Animals []*Animal

func (as Animals) Len() int {
	return len(as)
}

func (as Animals) Less(i, j int) bool {
	return as[i].size < as[j].size
}

func (as Animals) Swap(i, j int) {
	as[i], as[j] = as[j], as[i]
}

func main() {
	sc.Split(bufio.ScanWords)
	n := nextInt()
	animals := make(Animals, n)
	for i := range animals {
		animals[i] = &Animal{i + 1, nextInt()}
	}
	// 大きさの昇順にソート
	sort.Sort(animals)

	sums := make([]int64, n+1)
	for i := 1; i <= n; i++ {
		sums[i] = sums[i-1] + int64(animals[i-1].size)
	}

	ans := n
	for i := n - 2; i >= 0; i-- {
		if sums[i+1]*2 < int64(animals[i+1].size) {
			ans -= i + 1
			break
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 5504
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;

int main() {
  int n, l;
  cin >> n >> l;
  vector<string> s(n);
  for (int i = 0; i < n; i++) {
    cin >> s[i];
  }
  sort(all(s));
  for (int i = 0; i < n; i++) {
    cout << s[i] << flush;
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;
 
const ll nmax = 1e9 + 7;
const ll Mod = 998244353;
const double PI = 2 * asin(1);

int N, A, X[51];
ll DP[51][51][2501];

int main(){
  cin >> N >> A;
  for (int i = 1; i <= N; i++) cin >> X[i];
  DP[0][0][0] = 1;

  for (int i = 1; i <= N; i++){

    for (int j = 0; j <= N; j++){
      for (int k = 0; k <= A * N; k++){
        DP[i][j][k] = DP[i-1][j][k];
      }
    }

    for (int j = 0; j < N; j++){
      for (int k = 0; k <= A * N; k++){
        DP[i][j + 1][k + X[i]] += DP[i - 1][j][k];
      }
    }
  }
  
  ll ans = 0;
  for (int j = 1; j <= N; j++){
    ans += DP[N][j][j * A];
  }
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 50048
#include<stdio.h>
char change(int s)
{
    char t;
    if(s==0)t='0';
    if(s==1)t='1';
    if(s==2)t='2';
    if(s==3)t='3';
    if(s==4)t='4';
    if(s==5)t='5';
    if(s==6)t='6';
    if(s==7)t='7';
    if(s==8)t='8';
    return t;
}
struct lei
{
    char a[55];
}lei[55];
int main()
{
    int m,n,i,j,s;
    scanf("%d%d",&m,&n);
    for(i=0;i<m;i++)
    {
       scanf("%s",lei[i].a);
    }
    for(i=0;i<m;i++)
    {
        for(j=0;j<n;j++)
        {
            s=0;
            if(lei[i].a[j]=='.')
            {
                if(lei[i-1].a[j-1]=='#')s++;
                if(lei[i-1].a[j+1]=='#')s++;
                if(lei[i-1].a[j]=='#')s++;
                if(lei[i].a[j-1]=='#')s++;
                if(lei[i].a[j+1]=='#')s++;
                if(lei[i+1].a[j-1]=='#')s++;
                if(lei[i+1].a[j]=='#')s++;
                if(lei[i+1].a[j+1]=='#')s++;
                lei[i].a[j]=change(s);
            }
        }
    }
    for(i=0;i<m;i++)
    {
        printf("%s",lei[i].a);
        printf("\n");
    }
    return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		int n=scan.nextInt();
		int max=0;
		int min=2147483647;
		int a=0;
		for(int i=0;i<n;i++) {
			a=scan.nextInt();
			if(max<=a) {
				max=a;
			}
			if(min>=a){
				min=a;
			}
		}
		int result=max-min;

		System.out.println(result);
		scan.close();		

	}
}

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

int main() {
  int N;
  bool p,w,g,y=false;
  string c;
  
  cin >> N;
  
  for (int i = 0; i < N; i++){
    cin >> c;  
    if (c == "P"){
      p=true;
    }else if (c == "W"){
      w=true;
    }else if (c == "G"){
      g=true;
    }else if (c == "Y"){
      y=true;
    }
  }
  if ( p && w && g && y ){
    cout << "Four" << endl;
  }else if (p && w && g){
    cout << "Three" << endl;
  }else if (w && g && y){
    cout << "Three" << endl;
  }else if (g && y && p){
    cout << "Three" << endl;
  }else if (y && p && w){
    cout << "Three" << endl;
  }
}

Measured memory_bytes: 256
#include <string>
#include <set>
#include <cstdio>
#include <algorithm>
using namespace std;
const int M=4;
int m[10][10];
char s0[M+2];
int chk(const string &s){
	int d=0;
	for(int i=0;i<4;i++)d=m[d][s[i]-'0'];
	return d;
}
bool correct(const string &s){
	return m[chk(s)][s[M]-'0']==0;
}
int main(){
	set<string>se;
	for(int i=0;i<10;i++)for(int j=0;j<10;j++)scanf("%d",m[i]+j);
	for(int i=0;i<10000;i++){
		sprintf(s0,"%04d",i);
		string s=s0;
		s+=chk(s)+'0';
		se.insert(s);
	}
	printf("%d\n",count_if(se.begin(),se.end(),[&](string s)->bool{
		for(int i=0;i<M;i++)if(s[i]!=s[i+1]){
			swap(s[i],s[i+1]);
			if(correct(s))return true;
			swap(s[i],s[i+1]);
		}
		for(int i=0;i<=M;i++)for(char j='0';j<='9';j++)if(s[i]!=j){
			swap(s[i],j);
			if(correct(s))return true;
			swap(s[i],j);
		}
		return false;
	}));
}

Measured memory_bytes: 3872
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

template<typename It>
bool is_palindrome( It const& b, It const& e )
{
    if ( *b != *e )
        return false;
    if ( distance( b, e ) <= 1 )
        return true;
    return is_palindrome( b+1, e-1 );
}

int main()
{
    string s;
    size_t sum = 0;
    while( cin >> s ) {
        if ( is_palindrome( s.begin(), s.end() - 1 ) )
            ++sum;
    }
    cout << sum << endl;
}

Measured memory_bytes: 1180
#include<iostream>
#include<cstdio>
#define M 100010
using namespace std;
int n,m,ans,vis[M],sum[M];
int main() {
	scanf("%d%d",&n,&m);
	vis[1]=true;
	for(int i=1;i<=n;i++) sum[i]=1;
	for(int i=1;i<=m;i++) {
		int x,y;scanf("%d%d",&x,&y);
		vis[y]|=vis[x];
		if(sum[x]==1) vis[x]=false;
		sum[x]--;sum[y]++;
	}
	for(int i=1;i<=n;i++) ans+=vis[i];
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 1024
package main

import (
	"fmt"
)

func main() {
	var n int64
	fmt.Scan(&n)
	var S []int64
	for n > 0 {
		n -= 1
		S = append(S, n%26)
		n /= 26
	}
	for i := range S {
		fmt.Print(string("a"[0] + byte(S[len(S)-i-1])))
	}
	fmt.Println()
}

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

#define ll long long
#define mod 1000000007

using namespace std;



int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s,t;
    cin>>s>>t;
    vector<ll>ser(26,-1),ter(26,-1);
    for(int i=0;i<s.size();i++){
        ll x=s[i]-'a';
        ll y=t[i]-'a';
        if(ser[x]!=-1&&ser[x]!=y){
            cout<<"No\n";return 0;
        }
        if(ter[y]!=-1&&ter[y]!=x){
            cout<<"No\n";return 0;
        }
        ser[x]=y;
        ter[y]=x;
    }
    cout<<"Yes\n";
}


Measured memory_bytes: 3764
#include<stdio.h>
int isprime(int m){
	int k;
	for(k=2;k*k <= m;k++){
		if(m%k==0)return 0;
	}
	return 1;
}	
int main(){
	const int max=1000000;
	int sum[max];
	int i, n;
	for(i=2;i<=max;i++){
		if(isprime(i)){
			sum[i+1]=sum[i]+1;
		}else{
			sum[i+1]=sum[i];
		}
	}	
	while(scanf("%d",&n) != EOF){
		printf("%d\n",sum[n+1]);
	}
	return 0;
}

Measured memory_bytes: 4500
#include <stdio.h>

int main() {
    int faces[6];
    int i, c, t;
    for (i=0; i<6; i++) {
        if (scanf("%d ", &faces[i]) != 1) return -1;
    }
    while ((c=getchar()) != '\n') {
        switch (c) {
            case 'N':
                t = faces[0];
                faces[0] = faces[1];
                faces[1] = faces[5];
                faces[5] = faces[4];
                faces[4] = t;
                break;
            case 'S':
                t = faces[0];
                faces[0] = faces[4];
                faces[4] = faces[5];
                faces[5] = faces[1];
                faces[1] = t;
                break;
            case 'E':
                t = faces[0];
                faces[0] = faces[3];
                faces[3] = faces[5];
                faces[5] = faces[2];
                faces[2] = t;
                break;
            case 'W':
                t = faces[0];
                faces[0] = faces[2];
                faces[2] = faces[5];
                faces[5] = faces[3];
                faces[3] = t;
                break;
            default:
                continue;
        }
    }
    printf("%d\n", faces[0]);
    return 0;
}



Measured memory_bytes: 2052
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;

struct mint {
  ll x;
  mint(ll x=0):x(x%mod){}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

struct combination {
    vector<mint> fact, ifact;
    combination(int n):fact(n+1),ifact(n+1) {

        fact[0] = 1;
        for(int i = 1; i <= n; i++) {
            fact[i] = fact[i-1] * i;
        }

        ifact[n] = fact[n].inv();
        for(int i = n; i >= 1; i--) {
            ifact[i-1] = ifact[i] * i;
        }
    }

    mint operator()(int n, int k) {
        if (k < 0 || k > n)  {
            return 0;
        }
        return fact[n]*ifact[k]*ifact[n-k];
    }
} comb(100005); 

mint f(int n, int k) {

    if(n < 0) {
        return 0;
    }

    mint res = comb(n, k);
    res *= comb.fact[k];
    return res;
}

int k;
mint ans;
vector<int> to[100005];

void dfs(int v, int p = -1) {

    for(int u : to[v]) {
        if(u == p) {
            continue;
        }
        dfs(u, v);
    }

    int nk = (p == -1) ? k : k-2;
    int c = (p == -1) ? to[v].size() + 1 : to[v].size() - 1;

    ans *= f(nk, c);
}

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

    rep(i, n-1) {
        int a, b;
        cin >> a >> b;
        a--;  b--;
        to[a].push_back(b);
        to[b].push_back(a);
    }

    ans = 1;

    dfs(0);

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

Measured memory_bytes: 10752
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <complex>
#include <algorithm>
#include <numeric>
#include <utility>
#include <tuple>
#include <bitset>
#include <cstdint>
#include <cassert>
#include <random>
#include <iterator>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;

int main() {
    int n;
    cin >> n;
    vector<int> a(n), k(n);
    for (int i = 0; i < n; ++i) cin >> a[i] >> k[i];
    
    int g = 0;
    for (int i = 0; i < n; ++i) {
        int h = 0;
        while (a[i] >= k[i] && a[i] % k[i] != 0) {
            a[i] = a[i] / k[i] * k[i] + (a[i] % k[i]) % (a[i] / k[i] + 1);
            if (a[i] >= k[i] && a[i] % k[i] != 0) {
                a[i] -= a[i] / k[i] + 1;
            }
        }
        g ^= a[i] / k[i];
    }
    if (g != 0) {
        cout << "Takahashi\n";
    } else {
        cout << "Aoki\n";
    }

    return 0;
}

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

int main () {
  vector<vector<char>> data(3,vector<char>(3));
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      cin >> data.at(i).at(j);
    }
  }
  for (int i = 0; i < 3; i++) {
    cout << data.at(i).at(i);
  }
}

Measured memory_bytes: 256
n,m,x,y=input().split()
n,m,x,y=int(n),int(m),int(x),int(y)
x1=input().split()
x2=[]
for i in range(n):
    x2.append(int(x1[i]))
y1=input().split()
y2=[]
for i in range(m):
    y2.append(int(y1[i]))

s="War"
if y>x:
    for i in range(y-x):
        if x+i+1>max(x2) and min(y2)>=x+i+1:
            s="No War"

print(s)


Measured memory_bytes: 3064