akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
#define ll  long long 
#define ull unsigned long long int
#define boost ios_base::sync_with_stdio(false);	cin.tie(NULL);	cout.tie(NULL)
#define vi vector<int>
#define P push_back
#define F first
#define S second
#define debug(x) cout<<x<<" "
#define pi vector<pair<int,int> >
#define all(a) a.begin(),a.end()
#define int ll
using namespace std;
using namespace __gnu_pbds;
typedef tree <int, null_type,less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
ll const mod=1e9+7;
int powi(int i,int b){
    int res=1;
    while(b){
        if(b&1)res*=i,res%=mod;
        b>>=1;
        i*=i;
        i%=mod;
    }
    return res;
}
// map<int,int> m;
// ll fact(int n){
// 	//if(n==0)return 0;
// 	if(n<=1)return 1;
// 	if(m[n]!=0)return m[n];
// 	return m[n]=(n*fact(n-1))%mod;
//}
// int ncr(int n,int r){
//     int h=fact(n);
//     int v=fact(r);
//     int j=fact(n-r);
//     v*=j;
//     v%=mod;
//     v=powi(v,mod-2);
//     return (h*v)%mod;
// }
// vi ar(2000000);
// vi sz(2000000);
// int root(int a){
//     if(ar[a]==a)return a;
//     return ar[a]=root(ar[a]);
// }
// int merge(int a,int b){
//     int h=root(a),j=root(b);
//     int ans=sz[h]*sz[j];
//     sz[j]+=sz[h];
//     if(h!=j){
//         ar[h]=j;
//     }
//     return ans;
// } 
void solve(){
    int n;
    cin>>n;
    vi a(1<<(n));
    vector<vi> g((1<<n),vi(2));
    for(int i=0;i<(1<<n);i++){
        cin>>a[i];g[i][0]=i;g[i][1]=-1;
    }
    vi b((1<<n));
    for(int i=0;i<n;i++){
        for(int j=0;j<(1<<n);j++){
            if((j&(1<<i))){
                if(a[g[j][0]]<a[g[j^(1<<i)][0]]){
                    g[j][1]=g[j][0];
                    g[j][0]=g[j^(1<<i)][0];
                }
                else{
                    if(g[j][0]!=g[j^(1<<i)][0]&&(g[j][1]==-1||(a[g[j][1]]<a[g[j^(1<<i)][0]]))){
                        g[j][1]=g[j^(1<<i)][0];
                    }
                    continue;
                }
                if(g[j^(1<<i)][1]!=-1&&(g[j][1]==-1||a[g[j][1]]<a[g[j^(1<<i)][1]])){
                    g[j][1]=g[j^(1<<i)][1];
                }
            }
        }
    }
    int mex=0;
    for(int i=1;i<(1<<n);i++){
        mex=max(mex,a[g[i][0]]+a[g[i][1]]);
        cout<<mex<<"\n";
    }
    
}   
signed main(){
    boost;
    int t=1;
    //cin>>t;
    for(int _=1;_<=t;_++){
        //cout<<"Case #"<<_<<": ";
        solve();
        cout<<"\n";
    }
    
    return 0;
}

Measured memory_bytes: 21504
#include <algorithm>
#include <array>
#include <bitset>
#include <cstdint>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <memory>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <vector>

// constexpr std::int64_t INF = 1ull << 50;
constexpr int INF = 1 << 20;

auto main() -> int {
  int N, T, A;
  std::cin >> N >> T >> A;

  std::vector<int> Hs(N);
  for (auto& Hi : Hs) {
    std::cin >> Hi;
  }

  double diff = INF;
  int idx = 0;
  for (auto i = 0; i < N; ++i) {
    const auto d = std::abs(0.006 * Hs[i] - T + A);
    if (d < diff) {
      diff = d;
      idx = i;
    }
  }

  std::cout << (idx + 1) << std::endl;
}


Measured memory_bytes: 888
#include<stdio.h>
main()
{
	int n,m,i,s=0,t;
	scanf("%d %d",&n,&m);
	for(i=0;i<m;i++)
	{
		scanf("%d",&t);
		s=s+t;
	}
	if(n>=s) printf("%d",n-s);
	else printf("-1");
 } 

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

void solve()
{
    int x, t;
    cin >> x >> t;
    int ans = max(x - t, 0);
    cout << ans << endl;
}

int main()
{
    solve();
    return 0;
}

Measured memory_bytes: 3572
#include<bits/stdc++.h>
using namespace std;
int a[100001],n,t,s,maxn1,maxn2,f,i; 
int main()
{
	cin>>n>>t;
	for(i=1;i<=n;i++)	cin>>a[i];
	for(i=n;i>=1;i--)	
	{
		maxn1=max(a[i],maxn1);
		s=max(maxn1-a[i],s);
	 } 
	 for(i=n;i>=1;i--)
	 {
	 	maxn2=max(a[i],maxn2);
	 	if(maxn2-a[i]==s)	f++;
	 }
	 cout<<f;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
int main()
{
    ll n; cin>>n;
    ll ans=1;
    while(1)
    {
        if(ans==n)
        {
            cout<<ans;
            break;
        }
        else if(ans>n)
        {
            cout<<ans/2;
            break;
        }
        ans=ans*2;
    }
}




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

using namespace std;

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

    int minl=1, maxr=n;
    int l, r;
    for(int i=0; i<m; i++)
    {
        cin>>l>>r;
        minl=max(l, minl);
        maxr=min(r, maxr);
    }

    int ans=maxr-minl+1;
    if(ans<0)   ans=0;

    cout<<ans;

    return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
from sys import stdin

s_in = lambda: stdin.readline()[:-1]  # s = s_in()
d_in = lambda: int(stdin.readline())  # N = d_in()
ds_in = lambda: list(map(int, stdin.readline().split()))  # List = ds_in()


X, Y = ds_in()
print(X + Y//2)


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

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

    vector<int> A(m);
    for(int i=0; i<m; i++){
        cin >> A.at(i);
    }


    int count = 0;
    for(int i=0; i<m; i++){
        count += A.at(i);
    }

    if(m>n) cout << -1 << endl;
    
    else if(n >= m && n-count < 0){
        cout << -1 << endl;
    }

    else cout << n-count << endl;


    
}

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

int N, Q;
vector<vector<int>> tree(200001);
vector<bool> used(200001);
vector<long long> q(200001);
vector<long long> ans(200001);

void make_tree(int i, long long sum){
  used.at(i) = true;
  sum += q.at(i);
  ans.at(i) = sum;
  for(int j = 0; j < tree.at(i).size(); ++j){
    if(!used.at(tree.at(i).at(j))){
      make_tree(tree.at(i).at(j), sum);
    }
  }
  return;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << setprecision(20) << fixed;


  cin >> N >> Q;
  for (int i = 0; i < N - 1; ++i) {
    int a, b;
    cin >> a >> b;
    tree.at(a).push_back(b);
    tree.at(b).push_back(a);
  }


  for(int i = 0; i < Q; ++i){
    int a, b;
    cin >> a >> b;
    q.at(a) += b;
  }

  make_tree(1, 0);
  
  /*表示用
  for(int i = 1; i < N + 1; ++i){
    cout << "i:" << i;
    for(auto x: treeS.at(i)){
      cout << " " << x;
    }
    cout <<endl;
  }*/



  for(int i = 1; i < N + 1; ++i){
    cout << ans.at(i) << " ";
  }
}


Measured memory_bytes: 32128
#define _USE_MATH_DEFINES
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

const int MOD = 1000000007; 
const int INF = 1000000000; //1e9
const int NIL = -1;
const long long LINF = 1000000000000000000; // 1e18
const long double EPS = 1E-10;

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






int main(){
    std::string S; std::cin >> S;
    int N(S.size());
    long long ans(0);
    //m[i] = i文字目から最後まで
    std::vector<int> m(N+1); m[N] = 0;
    int keta(1);
    //m[i]: U_i % 2019 = i
    std::vector<int> cnt(2019, 0);
    cnt[0] = 1;
    for(int i(N-1); i >= 0; --i){
        m[i] = (keta*(S[i]-'0') + m[i+1]) % 2019;
        if(m[i] < 0) m[i] += 2019;
        ans += cnt[m[i]];
        ++cnt[m[i]];
        keta = 10 * keta % 2019;
        if(keta < 0) keta += 2019;
    }
    std::cout << ans << std::endl;
    return 0;
}


Measured memory_bytes: 4396
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;cin>>n;
    struct rest {
        string name;  // 名前
        int    price; // 価格
        int    index;
    };

    vector<rest> sp(n);

    for (int i = 0; i < n; i++) {
        cin>>sp[i].name>>sp[i].price;
        sp[i].index=i;
    }
    // priceをキーに降順でソート
    stable_sort(sp.begin(), sp.end(),
     [](const rest& x, const rest& y) { return x.price > y.price;});
    // nameをキーに昇順でソート
    stable_sort(sp.begin(), sp.end(),
     [](const rest& x, const rest& y) { return x.name < y.name;});
     for (int i = 0; i < n; i++) {
         cout<<sp[i].index+1<<endl;
     }
}


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

// #undef DEBUG  // Uncomment this line to forcefully disable debug print.
#if DEBUG
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define DBG(...)                              \
  do {                                        \
    cerr << #__VA_ARGS__ << ": ";             \
    debug(__VA_ARGS__);                       \
    cerr << " (L" << __LINE__ << ")" << endl; \
  } while (0)
#else
#define DBG(...)
#endif

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, n) for (auto i : (n))
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)

using ll = long long;

using namespace std;

int main() {
  int A, B, C;
  cin >> A >> B >> C;
  if (A == B && B != C ||
      B == C && C != A ||
      C == A && A != B) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


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

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        String S = scan.next();
        String T = scan.next();
        char[] d_s = S.toCharArray();
        char[] d_t = T.toCharArray();
        int answer = 0;
        for (int i = 0; i < 3; i++) {
            if (d_s[i] == d_t[i]) {
                answer += 1;
            }
        }

        System.out.println(answer);
    }
}


Measured memory_bytes: 23124
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define GCD(m,n) __gcd(m,n)
#define LCM(m,n) (m*n)/GCD(m,n)
# define mod 1000000007



int main()
{
   ll i,j,n,w;
   cin >> n >> w;
   ll weight[n];
   ll price [n];
   for(i=0;i<n;i++)
   {
       cin >> weight[i];
       cin >> price[i];
   }
   ll dp[n+1][w+1];
   for(i=0;i<=n;i++)
   {
       for(j=0;j<=w;j++)
       {
           if(i==0 || j==0)
            dp[i][j]=0;
       }
   }
   for(i=1;i<=n;i++)
   {
       for(j=1;j<=w;j++)
       {
           if(weight[i-1]<=j)
             dp[i][j]=max(dp[i-1][j],price[i-1]+dp[i-1][j-weight[i-1]]);
           else
           dp[i][j]=dp[i-1][j];
       }
   }
   cout << dp[n][w];
}


Measured memory_bytes: 82464
#include <bits/stdc++.h>
using namespace std;
vector <vector<int>> vv;
int checkRank(){
    int ret = 0;
    for(int i = 0; i < vv.size(); i++){
        for(int j = 0; j < vv[0].size(); j++){
            ret = max(ret,vv[i][j]);
        }
    }
    return ret;
}
void checkpath(int x, int y, int rank){
    if( (x >= 0) && 
        (x < vv.size()) &&
        (y >= 0) &&
        (y < vv[0].size())){

        if(vv[x][y]==-1){
            return;
        }else{
            if( (vv[x][y]==-2) ||
                (vv[x][y]>rank)  ){
                vv[x][y]=rank;
                checkpath(x+1,y,rank+1);
                checkpath(x,y+1,rank+1);
                checkpath(x-1,y,rank+1);
                checkpath(x,y-1,rank+1);
            }
        }

    }
}
void clearpath(){
    for(int i = 0; i < vv.size(); i++){
        for(int j = 0; j < vv[0].size(); j++){
            if(vv[i][j]!=-1){
                vv[i][j]=-2;
            }
        }
    }
}
int main(){
    int h,w;
    cin >> h >> w;
    vv = vector<vector<int>>(h);
    //vector <vector<int>> vv(h);
    for(int i = 0; i < h; i++){
        vv[i]=vector<int>(w,0);
    }
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            char c;
            cin >> c;
            if(c=='.'){
                vv[i][j]=-2;
            }else if(c=='#'){
                vv[i][j]=-1;
            }else{

            }
        }
    }
    int ans = 0;
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            checkpath(i,j,0);
            ans = max(ans,checkRank());
            clearpath();
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
#include<math.h>
#include<queue>
#include<cstdio>
#include<set>
#include<map>
using namespace std;
using ll = long long;

int main(){
    int R;
    cin >> R;
    double p=3.1415926535;
    cout << 2*R*p << endl;
    return 0;

}

Measured memory_bytes: 3772
using System;
using System.Linq;

namespace ABC048B
{
    class Program
    {
        static void Main(string[] args)
        {
            Solver sol = new Solver();
            sol.Solve();
        }
    }

    class Solver
    {
        long a;
        long b;
        long x;

        public void Solve()
        {
            Func<long, long> f = n => n >= 0 ? n / x + 1 : 0;
            Console.WriteLine(f(b) - f(a - 1));
        }

        public Solver()
        {
            long[] abx = ReadLongArray();
            a = abx[0];
            b = abx[1];
            x = abx[2];
        }

        static String ReadString() { return Console.ReadLine(); }
        static int ReadInt() { return int.Parse(Console.ReadLine()); }
        static long ReadLong() { return long.Parse(Console.ReadLine()); }
        static double ReadDouble() { return double.Parse(Console.ReadLine()); }
        static String[] ReadStringArray() { return Console.ReadLine().Split(' '); }
        static int[] ReadIntArray() { return Console.ReadLine().Split(' ').Select(e => int.Parse(e)).ToArray(); }
        static long[] ReadLongArray() { return Console.ReadLine().Split(' ').Select(e => long.Parse(e)).ToArray(); }
        static double[] ReadDoubleArray() { return Console.ReadLine().Split(' ').Select(e => double.Parse(e)).ToArray(); }
    }

}


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

int main() {
    int n;
    while (cin >> n, n) {
        int f1, t;
        vector<vector<int>> meet(31); // meet[x] := x日目に会える人
        for (int i=0; i<n; ++i) {
            cin >> f1;
            for (int j=0; j<f1; ++j) {
                cin >> t;
                meet[t].push_back(i);
            }
        }

        vector<set<int>> pieces(n); // pieces[x] := 人xが持っている断片
        for (int i=0; i<n; ++i) {
            pieces[i].insert(i);
        }
        int ans = -1;
        for (int i=1; i<=30; ++i) {
            set<int> t;
            for (int j: meet[i]) {
                t.insert(pieces[j].begin(), pieces[j].end());
            }
            for (int j: meet[i]) {
                pieces[j] = t;
            }
            if ((int)t.size() == n) {
                ans = i;
                break;
            }
        }
        cout << ans << endl;
    }
    return 0;
}


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

using namespace std;
#define next _next
#define y1 _y1
#define y2 _y2
#define lowbit(x) (x&(-x))
#define lc ((rt)<<1)
#define rc ((rt)<<1|1)
#define mid  ((l+r)>>1)
#define clr(a, b) memset(a,b,sizeof(a))

#ifdef __LOCAL_DEBUG__
# define _debug(fmt, ...) fprintf(stderr, "\033[94m%s: " fmt "\n\033[0m", \
    __func__, ##__VA_ARGS__)
#define dg(a) cout <<"\033[94m" <<#a << "\033[0m = "<< a << endl;
#else
#define _debug(...) ((void)0)
#define dg(a)((void)0)
#endif

typedef long long ll;
typedef long double ld;
const ld pi = acos(-1);
const int inf = 0x3f3f3f3f;
const ll llinf = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + 7;
const int maxn = static_cast<int>(1e6 + 7);

int main() {
    ios::sync_with_stdio(false), cin.tie(nullptr);
    string s;
    ll k;
    cin >> s >> k;
    int idx = -1;
    for (char i : s) if (i == '1') idx++; else break;
    if (idx == -1) {
        cout << s[0] << endl;
    } else {
        idx++;
        if (k <= idx) cout << "1" << endl;
        else cout << s[idx] << endl;
    }

}

Measured memory_bytes: 256
# ARC067D - Walk and Teleport (ABC052D)
def main():
    # choose A * dist(i, j) or B greedily
    N, A, B = tuple(map(int, input().split()))
    X = tuple(map(int, input().split()))
    ans = sum(min(A * (j - i), B) for i, j in zip(X, X[1:]))
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 14352
#include <iostream>
#include <fstream>
#include <cmath>
#include <algorithm>
#include <vector>
#define f cin
#define NMAX 3010
using namespace std;

//ifstream f("date.in");

long long int v[NMAX], dp[NMAX][NMAX][2];
long long int dist_arr[NMAX], n;

long long int calc_dist(long long int x, long long int y) {
    return (dist_arr[y] - dist_arr[x] + v[x]);
}

int main() {

    f >> n;
    for (int i = 0; i < n; ++i) {
        f >> v[i];
        if (i == 0) {
            dist_arr[i] = v[0];
        } else {
            dist_arr[i] = dist_arr[i - 1] + v[i];
        }
    }

    for (int l = 0; l < n; ++l) {
        for (int i = 0; i + l < n; ++i) {
            if (l == 0) {
                dp[i][i + l][0] = v[i];
                dp[i][i + l][1] = v[i];
            } else {
                dp[i][i + l][0] = max(v[i] + calc_dist(i + 1, i + l) - dp[i + 1][i + l][1],
                                      v[i + l] + calc_dist(i, i + l - 1) - dp[i][i + l - 1][1]);
                dp[i][i + l][1] = max(v[i] + calc_dist(i + 1, i + l) - dp[i + 1][i + l][0],
                                      v[i + l] + calc_dist(i, i + l - 1) - dp[i][i + l - 1][0]);
            }
        }
    }

    cout << 2 * dp[0][n - 1][0] - dist_arr[n - 1];

    return 0;
}


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

int getNum(vector<int> v)
{
    int num = 0;
    for(int n : v)
    {
        num *= 10;
        num += n;
    }
    return num;
}

int main()
{
    int n;
    cin >> n;
    vector<int> v;
    vector<int> p(n);
    int numP = 0;
    vector<int> q(n);
    int numQ = 0;
    for(int i = 1; i <= n; ++i)
    {
        v.push_back(i);
    }
    for(int i = 0; i < n; ++i)
    {
        cin >> p[i];
        numP = getNum(p);
    }
    for(int i = 0; i < n; ++i)
    {
        cin >> q[i];
        numQ = getNum(q);
    }

    int a,b,i = 1;
    do
    {
        int t = getNum(v);
        if(numP == t)
        {
            a = i;
        }
        if(numQ == t)
        {
            b = i;
        }
        ++i;
    }
    while(next_permutation(v.begin(),v.end()));

    cout << abs(a-b) << endl;
}

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

int main()
{
	int a, b, c;
	int k;
	int n;

	scanf("%d%d%d", &a, &b, &c);
	n = 0;
	for (k = a; k <= b; k++) {
		if (c % k == 0) n++;
	}
	printf("%d\n", n);
	return 0;
}



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

int main(){
  int n,m;
  cin >> n >> m;
  vector<int>a(m);
  vector<int>b(m);
  for(int i=0;i<m;i++)
    cin >> a.at(i) >> b.at(i);
  sort(a.begin(),a.end(),greater());
  sort(b.begin(),b.end());
  cout << max(0,b.at(0)-a.at(0)+1) << endl;
  return 0;
}

Measured memory_bytes: 3996
#include<stdio.h>

int main(){
	long a,b,k,i;
	scanf("%ld%ld%ld",&a,&b,&k);
	for(i=0;i<k;i++){
		if(i>=b-a+1)return 0;
		printf("%ld\n",a+i);
	}
	//for(i=k-1;i>=0;i--)printf("%ld\n",b-i);
	if(b-a+1>=k*2){
		for(i=k-1;i>=0;i--)printf("%ld\n",b-i);
	}
	else {
		for(i=k-1-(k*2-b+a-1);i>=0;i--)printf("%ld\n",b-i);
	}
	return 0;
}


Measured memory_bytes: 128
#include <unordered_map>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <cmath>
#include <map>
using namespace std;

string input;
string s;
int ptr = 0;

int eval()
{
	char c = s[ptr];
	ptr ++;
	if('0' <= c && c <= '9')
	{
		if(c == '0') return 0;
		if('0' <= s[ptr] && s[ptr] <= '9')
		{
			char c2 = s[ptr];
			ptr ++;
			return (c-'0') * 10 + (c2-'0');
		}
		else
			return (c-'0');
	}
	else
	{
		char op = c;
		ptr ++;
		int v1 = eval();
		ptr ++;
		int v2 = eval();
		ptr ++;
		if(op == '_')
			return min(v1, v2);
		if(op == '^')
			return max(v1, v2);
	}
	return -1;
}

int evalMin()
{
	
	
	char c = s[ptr];
	
	if(c == '*') return 0;
	ptr ++;
	

	if('0' <= c && c <= '9')
	{
		if(c == '0') return 0;
		if(s[ptr] == '*') return (c-'0');

		if('0' <= s[ptr] && s[ptr] <= '9')
		{
			char c2 = s[ptr];
			ptr ++;
			return (c-'0') * 10 + (c2-'0');
		}
		else
			return (c-'0');
	}
	else
	{

		char op = c;
		ptr ++;
		int v1 = evalMin();
		ptr ++;
		int v2 = evalMin();
		ptr ++;
		if(op == '_')
			return min(v1, v2);
		if(op == '^')
			return max(v1, v2);
	}
	return -1;
}


int evalMax()
{
	char c = s[ptr];
	if(c == '*') return 99;
	ptr ++;
	

	if('0' <= c && c <= '9')
	{
		if(c == '0') return 0;
		if(s[ptr] == '*') return (c-'0') * 10 + 9;
		if('0' <= s[ptr] && s[ptr] <= '9')
		{
			char c2 = s[ptr];
			ptr ++;
			return (c-'0') * 10 + (c2-'0');
		}
		else
			return (c-'0');
	}
	else
	{
		char op = c;
		ptr ++;
		int v1 = evalMax();
		ptr ++;
		int v2 = evalMax();
		ptr ++;
		if(op == '_')
			return min(v1, v2);
		if(op == '^')
			return max(v1, v2);
	}
	return -1;
}

bool verify(int fstLength)
{
	s = input;
	for(int i = fstLength; i < s.length(); i++)
		s[i] = '*';
	ptr = 0;
	int vMin = evalMin();

	
	s = input;
	for(int i = fstLength; i < s.length(); i++)
		s[i] = '*';
	ptr = 0;
	int vMax = evalMax();
	return vMin == vMax;
}

int minLen()
{
	int L = 0, R = input.length(), M;
	while(R - L > 1)
	{
		M = (L + R) / 2;
		if(verify(M))
			R = M;
		else
			L = M;
	}
	return R;
}

int MAIN()
{
	int T;
	cin >> T;
	while(T--)
	{
		cin >> input;
		s = input;
		ptr = 0;
		cout << eval() << " ";
		cout << minLen();
		cout << endl;
	}
	return 0;
}

int main()
{
	int start = clock();
	#ifdef LOCAL_TEST
		freopen("in.txt", "r", stdin);
		freopen("out.txt", "w", stdout);
	#endif
	ios :: sync_with_stdio(false);
	cout << fixed << setprecision(16);
	int ret = MAIN();
	#ifdef LOCAL_TEST
		cout << "[Finished in " << clock() - start << " ms]" << endl;
	#endif
	return ret;
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <tuple>
#include <queue>
#include <cmath>
#include <cfloat>
#include <set>
#include <map>

// statics
using namespace std;
using int64 = int_fast64_t;
using PAIR = pair<int64, int64>;
constexpr int INF = 1 << 30;
constexpr int64 LINF = 1LL << 60;
constexpr int MOD = 1e9 + 7;
constexpr int MAX_N = 3e5 + 1;

// init/input
#define int int64
#define INIT ios::sync_with_stdio(false);cin.tie(0);
#define VAR(type, ...) type __VA_ARGS__;MACRO_VAR_Scan(__VA_ARGS__);
template<typename T> void MACRO_VAR_Scan(T &t) {cin>>t;}
template<typename First, typename...Rest> void MACRO_VAR_Scan(First &first, Rest&...rest) {cin>>first;MACRO_VAR_Scan(rest...);}
#define VEC(type, c, n) vector<type> c(n);for(auto &&i:c)cin>>i;

// out
#define OUT(dist) cout<<(dist);
#define FOUT(n, dist) cout<<fixed<<setprecision(n)<<(dist);
#define SP cout<<" ";
#define BR cout<<endl;
#define zero(n) cout<<setfill('0')<<right<<setw(n)
#define debug(x) cerr<<#x<<":"<< (x);BR;

// utility
#define ALL(a) (a).begin(), (a).end()
#define EACH(i, a) for(auto &&i:(a))
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RFOR(i, a, b) for(int i=(b)-1;i>=0;--i)
#define REP(i, n) for(int i=0;i<(n);++i)
#define RREP(i, n) for(int i=(n)-1;i>=0;--i)

signed main() {
  INIT;
	VAR(int, n);
	VEC(int, a, n);
	REP(i, n) {
		a[i] -= 1 + i;
	}
	sort(ALL(a));
	int c = a[n/2];
	int ans = 0;
	REP(i, n) {
		ans += abs(a[i] - c);
	}
	OUT(ans)BR;
		
  return 0;
}


Measured memory_bytes: 1792
//ABC111B
#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <math.h>
#include<stdio.h>
#include<climits>
#include<cfloat>
using namespace std;

int main(){
	int n;
	cin >> n;
	cout << n*n*n << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <math.h>
#include <cstdio>
#include <string.h>
#include <vector>
using namespace std;
int main(void) {
	int N, i ,t = 0, ans;
	string S;
	cin >> N >> S;
	ans = N;
	int d1[N] = { 0 }, d2[N] = { 0 };
	for (i = 0; i<N; i++) {
		if (S[i] == 'W')t++;
		d1[i] = t;
	}
	t = 0;
	for (i = N - 1; i >= 0; i--) {
		if (S[i] == 'E')t++;
		d2[i] = t;
	}
	for (i = 0; i<N; i++) ans = min(ans, d1[i] + d2[i]);
	cout << ans - 1 << endl;
}

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

int main() {

	for (int x, t = 1; ; t++) {
		cin >> x;
		if (x == 0) {
			break;
		}
		cout << "Case " << t << ": " << x << endl;
	}
	return 0;
}

Measured memory_bytes: 3016
n = input()
op_cnt = len(n) - 1
for i in range(2 ** op_cnt):
    op = ['-'] * op_cnt
    for j in range(op_cnt):
        if ((i >> j) & 1):
            op[op_cnt - 1 - j] = '+'
    
    formula = ''
    for p_n, p_o in zip(n, op + ['']):
        formula += p_n + p_o
    result = eval(formula)
    if result == 7:
        print(formula + '=7')
        break

Measured memory_bytes: 3064
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  int n;
  cin >> n;
  int mx = 0;
  int ans = 0;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    if (x >= mx) ans++;
    mx = max(x, mx);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
//------------------------------>> tsukasa_diary's template <<------------------------------//
#include <bits/stdc++.h>
using namespace std;

#define for_(i,a,b) for (int i=(a);i<(b);++i)

using lint = long long;
using pii = pair< int, int >;

template< typename T > using Vec = vector< T >;

template< typename T > bool inRange(T x, T lb, T ub) { return lb <= x && x < ub; }
template< typename T > bool inRange(T x, T y, T lb, T ub) { return in_range(x, lb, ub) && in_range(y, lb, ub); }

template< typename T > void modAdd(T& a, T b, T mod) { a = (a + b + mod) % mod; }
template< typename T > void modMul(T& a, T b, T mod) { a = (a * b) % mod; }
template< typename T > void minUpdate(T& a, T b) { a = min(a, b); }
template< typename T > void maxUpdate(T& a, T b) { a = max(a, b); }

int bitCount(int x) { return __builtin_popcount(x); }
int bitCount(lint x) { return __builtin_popcountll(x); }

const int dx[4] = {0,1,0,-1}, dy[4] = {-1,0,1,0};
const int Dx[8] = {0,1,1,1,0,-1,-1,-1}, Dy[8] = {-1,-1,0,1,1,1,0,-1};
const double EPS = 1e-9;
const double PI = acos(-1);

//--------------8---------------->> coding space <<-----------------8-------------//

int N, A[100005];
lint dp[100005][2];

int main() {
	cin >> N;
	for_(i,0,N) cin >> A[i];

	for_(i,0,N+1) for_(f,0,2) dp[i][f] = -(1LL << 60);
	
	dp[0][0] = 0;
	for_(i,0,N) {
		maxUpdate(dp[i+1][0], dp[i][0] + A[i]);
		maxUpdate(dp[i+1][0], dp[i][1] - A[i]);
		
		if (i < N-1) {
			maxUpdate(dp[i+1][1], dp[i][0] - A[i]);
			maxUpdate(dp[i+1][1], dp[i][1] + A[i]);
		}
	}
	cout << dp[N][0] << endl;
}
//--------------8---------------->> coding space <<-----------------8-------------//

Measured memory_bytes: 2176
#include <bits/stdc++.h>
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll N; cin >> N;
  vector<ll> A(N, 0);
  REP(i, N){
    cin >> A[i];
  }
  vector<int> c(3, 0);
  ll ans = 1;
  ll MOD = 1e9 + 7;
  for(ll i = 0; i < N; i++){
    ll cnt = 0;
    ll k;
    REP(j, 3){
      if(A[i] == c[j]){
        cnt++;
        k = j;
      }
    }
    c[k]++;
    ans = ans * cnt % MOD;
  }
  cout << ans % MOD << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0; i<n; i++)
typedef long long ll;
typedef long long unsigned int llu;
ll MOD = 1000000007;
ll INF = 1000000009;


ll gcd(ll a,ll b)
{
	if (a%b==0)
	{
		return(b);
    }
	else
	{
		return(gcd(b,a%b));
    }
}

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 IsPrime(ll num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    long double sqrtNum = sqrt(num);
    for (ll i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}

void solve(){
  ll a,b;
  cin >> a >> b;
  ll g = gcd(a,b);
  //cout << g << endl;////
  vector<ll> v = divisor(g);
  //cout << v[0] << " " << v[1] << " " << v[2] << endl;////
  //vはgの約数
  //vの要素それぞれについて、それより前のvのどれかで割れるかを調べる

  ll count = 1;
  for(int i=1; i<v.size(); i++){
    bool b=true;
    for(int j=1; j<i; j++){
      if(v[i]%v[j]==0){
        b=false;
        break;
      }
    }
    if(b) count++;
    //if(b) cout << v[i] << endl;
  }
  cout << count << endl;

}

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

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
const int maxn =1e5+10;
const int mod=1e9+7;
int a[maxn];
int f[maxn];


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    ll sum=0;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        f[a[i]]++;
        sum+=a[i];
    }
    int q;
    cin>>q;
    while(q--)
    {
        int b,c;
        cin>>b>>c;
        int x=f[b];
        f[c]+=x;
        f[b]=0;
        sum+=1ll*(c-b)*x;
        cout<<sum<<'\n';
    }










}


Measured memory_bytes: 4404
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <time.h>
#define int long long
#define endl '\n'
#define INF 1000000000000000000
#define all(a) a.begin(),a.end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define fi first
#define se second
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
template<class T, class S> bool chmax(T &a, const S &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T, class S> bool chmin(T &a, const S &b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll n, ll m) { return (m ? gcd(m, n%m) : n); }
ll lcm(ll n, ll m) { return n / gcd(n, m)*m; }

vector<vector<int>> tree(100010, vector<int>());

int ans(int n, int p) {
	vector<int> vec;
	for (int i : tree[n]) {
		if (i == p) continue;
		vec.push_back(ans(i, n));
	}
	sort(all(vec));
	int res = 0;
	for (int i : vec) {
		res = max(i, res) + 1;
	}
	return res;
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);
	//modcalc();

	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 1; i < n; i++) {
		cin >> a[i];
		a[i]--;
		tree[a[i]].pb(i);
	}
	cout << ans(0, -1) << endl;
}

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

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

int main() {

    string s; cin >> s;
    int k; cin >> k;

    vector<string> v;

    int n = s.size();

    for (int i = 1; i <= min(k, n); ++i) { //何文字か。最大でもk文字以下になる
        for (int j = 0; j <= s.size()-i; ++j) { //何文字目からか
            string st = "";
            for (int l = 0; l < i; ++l) {
                if (j + l > s.size() - 1) {
                    break;
                } else {
                    st += s[j+l];
                }
            }

            auto itr = find(v.begin(), v.end(), st);
            if (itr == v.end()) {
                v.push_back(st);
            }
        }
    }

    sort(v.begin(), v.end());

    cout << v[k - 1] << endl;
}

Measured memory_bytes: 1024
class UnionFind
  attr :union_count

  def initialize()
    @table = Hash.new { |_hash, key| key }
    @rank = Hash.new { 0 }
    @union_count = 0
  end

  def find(elt)
    if @table[elt].eql? elt
      elt
    else
      @table[elt] = find(@table[elt])
    end
  end
 
  def union(node1, node2)
    root1 = find(node1)
    root2 = find(node2)

    if @rank[root1] < @rank[root2]
      @table[root1] = root2
      @union_count += 1
    elsif @rank[root1] > @rank[root2]
      @table[root2] = root1
      @union_count += 1
    elsif root1 != root2
      @table[root2] = root1
      @rank[root1] += 1
      @union_count += 1
    end
  end

end

n, m = gets.split.map(&:to_i)

uf = UnionFind.new

m.times do
  x, y, z = gets.split.map(&:to_i)
  uf.union(x, y)
end

puts n - uf.union_count


Measured memory_bytes: 10364
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <cstring>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;

#define sz size()
#define pb push_back
#define clr(a,b) memset(a,b,sizeof(a))
#define rep(i,a,n) for(int i = (a);i < (n);i++)
#define lep(i,a,n) for(int i = (a);i <= (n);i++)
#define per(i,a,n) for(int i = (a);i > (n);i--)
#define pel(i,a,n) for(int i = (a);i >= (n);i--)
#define endl "\n"
#define print(X) cout << X << endl;
#define INF 1e+9
#define INFL 1e+18

#define W 400
#define H 400

ll n,m,l;
int field[W][H];
ll dp[300][300],d[2100010];

typedef struct point{
    int x,y;
}point;

// vector<point> vec;
int point_num;

void init(){
    clr(field,-1);
    // vec.clear();
    point_num = 1;
    field[W/2][H/2] = 0;
    // vec.pb(point{100,100});
}

void put(point &p){
    point ins;
    bool f = false;
    rep(i,0,W){
        rep(j,0,H){
            if(field[i][j] == p.x){
                ins.x = i;
                ins.y = j;
                f = 1;
                break;
            }
        }
        if(f)break;
    }

    // if(!f)print("NO");
    if(p.y == 0)field[ins.x-1][ins.y] = point_num;
    if(p.y == 1)field[ins.x][ins.y-1] = point_num;
    if(p.y == 2)field[ins.x+1][ins.y] = point_num;
    if(p.y == 3)field[ins.x][ins.y+1] = point_num;
    point_num++;
}

void func(point &ans){
    

    int mina,minb,maxa,maxb;
    mina = minb = maxa = maxb = -1;

    int a[W],b[W];
    clr(a,0);
    clr(b,0);

    rep(i,0,W){
        rep(j,0,W){
            if(field[i][j] != -1){
                a[i]++;
                b[j]++;
            }
        }
    }
    rep(i,0,W){
        if(a[i] != 0){
            if(mina == -1)mina = i;
            maxa = i;
        }
        if(b[i] != 0){
            if(minb == -1)minb = i;
            maxb = i;
        }
    }

    ans.x = maxa - mina +1;
    ans.y = maxb - minb + 1;
}

void deb(){
    rep(i,0,400){
        rep(j,0,400){
            cout << field[i][j] << "";
        }
        puts("");
    }
}

int main(){
    int n;
    while(cin >> n,n != 0){
        point ans;
        init();
        point p;
        rep(i,0,n-1){
            cin >> p.x >> p.y;
            put(p);
        }
        func(ans);
        // deb();
        cout << ans.x << " " << ans.y << endl;
    }
    return 0;
}


Measured memory_bytes: 3624
#include<iostream>

using namespace std;

int main()
{
	int map[20][20];
	int x,y,i,j,n;
	
	for(;;)
	{
		cin >> x >> y ;
		if(x==0 && y==0)
			break;
		
		cin >> n ;
		for(i=0;i<n;i++)
		{
			int a,b;
			cin >> a >> b ;
			map[a-1][b-1]=-1;
		}
		int flag=0;
		for(i=0;i<x;i++)
		{
			if(map[i][0]==-1)
				flag=1;
			if(flag==1)
				map[i][0]=0;
			else
				map[i][0]=1;
		}
		flag=0;
		for(j=0;j<y;j++)
		{
			if(map[0][j]==-1)
				flag=1;
			if(flag==1)
				map[0][j]=0;
			else
				map[0][j]=1;
		}
		for(i=1;i<x;i++)
		{
			for(j=1;j<y;j++)
			{
				if(map[i][j]==-1)
					map[i][j]=0;
				else
					map[i][j]=map[i-1][j]+map[i][j-1];
			}
		}
		
		cout << map[x-1][y-1] << endl;
	}
	
}

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

int main(){
  int n; cin>>n;
  vector<int> a(n),b(n);
  for(int i=0; i<n; ++i)cin>>a[i]>>b[i];

  long long ans=0LL;
  for(int i=n-1; i>=0; --i){
    if((a[i]+ans)%b[i]!=0)ans+=b[i]-(a[i]+ans)%b[i];
  }

  cout<<ans<<endl;
}


Measured memory_bytes: 1024
/* ITP1_8_A:Toggling Cases */
/* 20181123 AOJ */
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <string.h>

int main(void) {
	char str1[1200], str2[1200];
	int i, cnt;

	i = 0;
	while(1) {
		scanf("%c", &str1[i]);
		if(str1[i] == '\n') break;

		if(str1[i] >= 'a' && str1[i] <= 'z') {
			str2[i] = str1[i] - 32;
		} else if(str1[i] >= 'A' && str1[i] <= 'Z') {
			str2[i] = str1[i] + 32;
		} else {
			str2[i] = str1[i];
		}
		i++;
	}

	str2[i] = '\0';
	printf("%s", str2);
	printf("\n");
 
	return 0;
}



Measured memory_bytes: 2052
#include<iostream>
#include<cmath>
using namespace std;
long long A(long long n,long long m){
	long long ans=1,k=n;
	for(long long i=m;i>=1;i--){
		if(k){
		ans*=i;
		ans%=1000000007;
		k--;
	}
	}
	return ans;
}
int main(){
long long n,m,answer=1,s;
cin>>n>>m;
if(n==m){
	for(long long i=m;i>=1;i--){
		answer*=i;
		answer%=1000000007;
	}
	answer*=A(m,m);
	answer%=1000000007;
	answer*=2;
	answer%=1000000007;
	cout<<answer;
}
else if(abs(n-m)==1){
	long long k=min(n,m);
		for(long long i=k;i>=1;i--){
		answer*=i;
		answer%=1000000007;
	}
	answer*=A(k,k);
	answer%=1000000007;
	answer*=(k+1);
	answer%=1000000007;
	cout<<answer;
}
else cout<<0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <cstring>
#include <map>

#define ll long long
const ll MOD = 1e9 + 7;
const ll INF = 1 << 29;

int main()
{
    std::string S, T;
    std::cin >> S >> T;

    for (auto i=0; i<S.size(); ++i)
    {
        if (S[i] != T[i])
        {
            std::cout << "No" << std::endl;
            return 0;
        }
    }

    if (S.size() + 1 == T.size())
        std::cout << "Yes" << std::endl;
    else
        std::cout << "No" << std::endl;
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
#define rgt register
#define rint rgt int
#define LL long long
#define rll rgt LL
#define inf 0x7f7f7f7f
#define N 100007
using namespace std;
const int T=1<<15;
template<class K>inline bool cmax(K&a,const K&b){return(a<b)?a=b,1:0;}
template<class K>inline bool cmin(K&a,const K&b){return(a>b)?a=b,1:0;}
inline int read() {
	rint s=0;
	rgt char c=getchar();
	while(!isdigit(c)) c=getchar();
	while(isdigit(c)) s=(s<<1)+(s<<3)+c-'0',c=getchar();
	return s;
}
int n,t,d[N],sum[19],f[T+3],st,ans,p[T+3];
int main()
{
	rint i,j,x,y,val;n=read();
	for(i=1;i<n;i++)
		x=read(),y=read(),val=read(),d[x]^=val,d[y]^=val;
	for(i=0;i<n;i++) ++sum[d[i]];
	for(i=1;i<16;i++) ans+=sum[i]>>1,st|=(sum[i]&1)<<(i-1);
	for(i=1;i<T;i++) f[i]=f[i>>1]+(i&1);
	for(i=1;i<T;i++) --f[i];
	for(i=0;i<T;i++)
		for(j=0;j<15;j++)
			if((i>>j)&1) p[i]^=(j+1);
	for(i=0;i<T;i++) {
		if(p[i]) continue;
		for(j=(i-1)&i;j;j=(j-1)&i)
			if(!p[j]) f[i]=min(f[i],f[j]+f[i^j]);
	}printf("%d",ans+f[st]);
	return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,n) for(ll i = 0; i < (n); ++i )
#define rep_rev(n,i) for(ll i = n; i >= 0; --i )
using namespace std;
using P = pair<int, int>;
const long long INF = 1LL << 60;

int main(){
  int N; cin >> N;
  int x = 0,ans = 0;
  string S; cin >> S;
  rep(i,N){
    if(S[i] == 'I') x++;
    else x--;
    if(x>ans) ans = x;
  }
  cout << ans << endl;
 return 0; 
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>
#include <queue>

using namespace std;
constexpr int INF = 1000000;

bool adj[700][700], pwede[701][701];

int choose2(int i) {
	return (i)*(i-1)/2;
}

int main() {
	int n, m; scanf("%d %d", &n, &m);
	for (int i = 0; i < m; ++i) {
		int u, v; scanf("%d %d", &u, &v);
		adj[--u][--v] = true;
		adj[v][u] = true;
	}
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < n; ++j) {
			if (i != j) adj[i][j] = not adj[i][j];
		}
	}
	int cbc = 0;
	vector<int> bdivc(n, -1);
	for (int i = 0; i < n; ++i) {
		if (bdivc[i] == -1) {
			bdivc[i] = cbc;
			queue<int> q; q.push(i);
			while (not q.empty()) {
				int cur = q.front(); q.pop();
				// printf("color %d %d\n", cur, bdivc[cur]);
				for (int next = 0; next < n; ++next) {
					if (adj[cur][next] and bdivc[next] == -1) {
						bdivc[next] = bdivc[cur] ^ 1;
						q.push(next);
					}
				}
			}
			cbc += 2;
		}
	}
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < n; ++j) {
			if (i != j and adj[i][j] and bdivc[i] == bdivc[j]) {printf("-1\n"); return 0;}
		}
	}
	vector<int> compCount(cbc);
	for (int i = 0; i < n; ++i) ++compCount[bdivc[i]];
	vector<int> a, b;
	for (int i = 0; i < cbc; ++i) {
		// printf("comp %d %d\n", i, compCount[i]);
		if (i % 2 == 0) a.push_back(compCount[i]);
		else b.push_back(compCount[i]);
	}
	pwede[0][0] = true;
	for (int i = 1; i <= a.size(); ++i) {
		// printf("pair %d %d\n", a[i-1] , b[i-1]);
		for (int fas = 0; fas <= n; ++fas) {
			if (fas >= a[i-1]) pwede[i][fas] = pwede[i][fas] || pwede[i-1][fas - a[i-1]];
			if (fas >= b[i-1]) pwede[i][fas] = pwede[i][fas] || pwede[i-1][fas - b[i-1]];
		}
	}
	int ans = 1000000000;
	for (int as = 0; as <= n; ++as) {
		if (pwede[a.size()][as]) {
			ans = min(choose2(as) + choose2(n - as), ans);
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n); for(int i = 0;i < (int)(n);i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
int main(){
    string s;
    cin >> s;
    for(int i = s.size()/2-1;i > 0;i--){
        string t = s.substr(0,i);
        string u = s.substr(i,i);
        if(t == u){
            cout << i*2 << endl;
            return 0;
        }
    }
    return 0;
}

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

int main() {

  string in;

  while( cin >> in ) {

    long long int ans0 = 0;
    long long int ans1 = 0;

    for ( long long int i = 0; i < in.size() - 2; i++ ) {
      string k = in.substr( i, 3 );
      if ( k == "JOI" ) ans0++;
      if ( k == "IOI" ) ans1++;
    }

    cout << ans0 << endl << ans1 << endl;

  }

  return 0;

}

Measured memory_bytes: 1212
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AOJ2
{
    class Program
    {
        static void Main()
        {
            var check = int.Parse(Console.ReadLine());
            var result = new List<string>();
            while (check != 0)
            {
                var point0=0;
                var point1=0;
                var data = Enumerable.Range(0, check)
                    .Select(x => Console.ReadLine().Split(' ').Select(y=>int.Parse(y)).ToArray());
                foreach (var item in data)
                {
                    if (item[0] == item[1])
                    {
                        point0 += item[0];
                        point1 += item[0];
                    }
                    else if (item[0] > item[1])
                    {
                        point0 += item[0];
                        point0 += item[1];
                    }
                    else
                    {
                        point1 += item[0];
                        point1 += item[1];
                    }
                }
                check = int.Parse(Console.ReadLine());
                result.Add(point0 + " " + point1);
            }
            result.ForEach(x => Console.WriteLine(x));
        }
    }
}

Measured memory_bytes: 6104
#include <array>
#include <cmath>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
int GCD(int a, int b)
{
    if (a < b)
    {
        int tmp = a;
        a = b;
        b = tmp;
    }
    int r = 1;

    while (r != 0)
    {
        r = a % b;
        a = b;
        b = r;
    }

    return a;
}
int main()
{
    long long int n, k;
    std::cin >> n >> k;
    if (n == k)
    {
        std::cout << 0;
    }
    else if (k > n)
    {
        std::cout << std::min(n, k - n);
    }
    else
    {
        long long int a, b, r, m;
        m = GCD(n, k);
        a = n / m;
        b = k / m;
        r = a % b;
        std::cout << std::min(r * m, (b - r) * m);
    }
    std::cout << std::endl;
    //     long long int x = n;

    // printf("GCD=%d\n", GCD(n, k));

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
#include <numeric>
#include <array>
#include <queue>
using namespace std;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define pow(x) x*x
#define ll long long
static const int MAX = 100010;
static const ll INFTY = 1e12;
static const int NUMMAX = 300;


int main(){

  ll N;
  ll x, y;
  ll ans = INFTY;

  cin >> N;

  for( int i = 1; i <= sqrt(N); i++ ){
    if( N % i == 0 ){
      x = N / i;
      y = N / x;
      ans = min( ans, x+y-2 );
    }
  }

  cout << ans << endl;


  return 0;
}
/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         pass System Test!
*/

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
enum Personality{HONEST,UNKIND};
struct Person
{
    Person():mem(0),hp(0){}
    Person(int x):mem(1,x),hp(1){}
    vector<int> mem;
    int hp;
    Personality judge(Person p)
    {
        printf("? %d %d\n",mem[0],p.mem[0]);
        fflush(stdout);
        char in[5];scanf("%s",in);
        return in[0]=='Y'?HONEST:UNKIND;
    }
    void answer(int n)
    {
        string s(n,'0');
        for(int i:mem) s[i]='1';
        printf("! %s\n",s.c_str());
        fflush(stdout);
    }
};
Person merge(Person a,Person b)
{
    a.mem.insert(a.mem.end(),b.mem.begin(),b.mem.end());
    a.hp+=b.hp;
    return a;
}
vector<Person> jail;
Person fight(Person big,Person small)
{
    if(big.hp<small.hp) swap(big,small);
    big.hp-=small.hp;small.hp=0;
    jail.push_back(small);
    return big;
}
int main()
{
    int a,b;scanf("%d%d",&a,&b);
    if(a<=b){puts("Impossible");return 0;}
    
    int n=a+b;
    Person jury(0);
    for(int i=1;i<n;i++)
    {
        Person defendant(i);
        if(jury.judge(defendant)==HONEST)
        {
            if(defendant.judge(jury)==HONEST) jury=merge(jury,defendant);  
            else jury=defendant;
        }
        else jury=fight(jury,defendant);
    }
    for(const auto &defendant:jail) if(jury.judge(defendant)==HONEST)
        jury=merge(jury,defendant);
    jury.answer(n);
    return 0;
}


Measured memory_bytes: 976
#include <stdio.h>          // printf(), scanf()

#define MAX_N 100

int
main(int argc, char** argv)
{
	int a[MAX_N];
	int i;

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

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

	for (i = n - 1; i >= 0; --i)
		printf("%d%c", a[i], i != 0 ? ' ' : '\n');

	return 0;
}

Measured memory_bytes: 596