akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>

using namespace std;

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

	vector<int> X(M);
	for(int i = 0; i < M; i++){
		cin >> X.at(i);
	}
	
	if(N >= M){
		cout << 0 << endl;
		return 0;
	}
	
	
	sort(X.begin(), X.end());
	
	//dist.at(i)は、iとi+1の距離
	vector<int> dist(M-1);
	for(int i = 0; i < M-1; i++){
		dist.at(i) = abs(X.at(i+1) - X.at(i));
	}
	
	sort(dist.begin(), dist.end());
	
	//でかい区間から順に区切り線で消す
	for(int i = 0; i < N-1; i++){
		dist.at(M - (2+i)) = 0;
	}
	
	int ans = 0;
	for(int i = 0; i < M-1; i++){
		ans += dist.at(i);
	}
	
	cout << ans << endl;
	
}

Measured memory_bytes: 3960
#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <bitset>
using namespace std;

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



const int BIG_NUM = 1e9;
const ll INF = 1000000000000000000;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;

struct UnionFind
{
	vector<int> p;
	vector<int> s;
	UnionFind(int n) :p(n), s(n, 1) {
		for (int i = 0; i < n; i++) {
			p[i] = i;
		}
	}

	int root(int x) {
		int px = p[x];
		if (px == x) {
			return x;
		}

		p[x] = root(px);

		return p[x];
	}

	bool same(int x, int y) {
		return root(x) == root(y);
	}

	void unite(int x, int y) {
		int rx = root(x);
		int ry = root(y);

		if (rx == ry) {
			return;
		}

		p[rx] = ry;
		s[ry] += s[rx];

	}

	int size(int x) {
		return s[root(x)];
	}

};

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

	UnionFind uf(n);
	for (int i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		uf.unite(a, b);
	}

	int ans = 0;
	for (int i = 0; i < n; i++) {
		ans = max(ans, uf.size(i));
	}

	cout << ans << endl;

}

Measured memory_bytes: 10924
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pp pair<pair<ll, ll>,pair<ll, ll>>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define vii vector<int>
#define vll vector<ll>
#define mat vector<vector<ll>>
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define fi first
#define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define sz(x) (ll) (x).size()
#define pq priority_queue<ll>
#define pqg priority_queue<ll,vector<ll>,greater<ll>>
#define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
#define ERASE(v) sort(v.begin(),v.end());v.erase(unique(v.begin(),v.end()),v.end())
// #define int ll
using namespace std;
const ll INF = (1 << 30 ) - 1;
const ll LLINF = (1LL << 60LL);
const ll MOD = 1000000007;
const ll mod = 998244353;
const ll MAX = 1100000;
const double pi = acos(-1);
const double eps = 1e-10;
ll dx[4] ={1,0,-1,0} , dy[4] ={0,1,0,-1};
 
template<class T> 
inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> 
inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
 
struct Timer{
    chrono::system_clock::time_point start, end;
    Timer(){ start = chrono::system_clock::now(); }
    ~Timer(){
        end = chrono::system_clock::now();
        auto msec = chrono::duration_cast<chrono::milliseconds>(end - start).count();
        cerr<<"time : "<<msec<<" ms"<<endl;
    }
};
 


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

ll lcm(ll a,ll b){
    ll g =gcd(a,b);
    return a/g*b;
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Timer TM;

    ll n;
    cin>>n;
    if(n%2!=0){
        cout<<0<<endl;
    }
    else{
        ll ans=0;
        n/=2;
        while(n>0){
            ans+=n/5;
            n/=5;
        }
        cout<<ans<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include<vector>
#include<iomanip>
#include<map>
#include <queue>
#include<cmath>
#include<cstdio>
#include<iomanip>
#include<set>
#include <bits/stdc++.h>
 
using namespace std;
using ll = long long int;
 
#define REP(i,n) for(ll i=0;i<(ll)(n);i++) //REP(i, 5) cout<<i;
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define MOD 1000000007 //10^9+7
//#define MOD 1
 
ll gcd(ll a, ll b) {
  ll tmp;
  if ( b > a) {
    tmp = a;
    a = b;
    b = tmp;
  }
  while (a % b !=0) {
    tmp = b;
    b = a % b;
    a = tmp;
  }
  return b;
}
 
const int MAX = 1000;
 
ll table[MAX][MAX];
 
// テーブルを作る前処理
void COMinit() {
    table[0][0] = table[0][1] = 1;
    FOR(i, 1, MAX-1){
      FOR(j, 0, i+1){
        if(j==0) table[i][j] = 1;
        else if(j == i+1) table[i][j] = 1;
        else table[i][j] = table[i-1][j-1]+table[i-1][j];
      }
    }
}
 
// 二項係数計算
ll COM(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return table[n-1][k];
}

void sosuu(ll n, vector<ll> &v){

  vector<ll> num(n, 0);

  FOR(i, 1, sqrt(n)){
    if(num[i]==0){
      FOR(j, 0, n/i){
        num[i+(j*i)] = 1;
      }
    }
  }
  REP(i, n){
    if(num[i]==0) v.push_back(i+1);
  }
}


int main(void){
 
  ll x;
  cin>>x;

  ll A, B;

  REP(i, 1001){
    ll y = (i*i*i*i*i-x);
    ll z = ((-1)*i*i*i*i*i-x);
    //cout<<y<<" "<<z<<endl;

    REP(j, 1001){
      if(y==j*j*j*j*j){
        A=i;
        B=j;
        break;
      }
      if(y==(-1)*j*j*j*j*j){
        A=i;
        B=-j;
        break;
      }
      if(z==j*j*j*j*j){
        A=-i;
        B=j;
        break;
      }
      if(z==(-1)*j*j*j*j*j){
        A=-i;
        B=-j;
        break;
      }

    }
  }

  
    cout<<A<<" "<<B<<endl;

}

Measured memory_bytes: 3724
from functools import lru_cache
import sys
sys.setrecursionlimit(10**6)


n, x = map(int, input().split())

whole = [1]
putty = [1]
for _ in range(50):
    whole.append(whole[-1] * 2 + 3)
    putty.append(putty[-1] * 2 + 1)


@lru_cache(maxsize=None)
def rec(n, x):
    if n == 0:
        # n == 0のとき、x <= 1なら常にパティ
        return 0 if x < 1 else 1

    # 真ん中で条件分岐する
    med = (whole[n]+1) // 2

    # 真ん中より下なら、1つ前のレベルの結果を少し改造すればよい
    if x < med:
        return rec(n - 1, x - 1)
    # 真ん中なら、1つ前のレベルのパティ総数に1つ足せばよい
    elif x == med:
        return putty[n - 1] + 1
    # 真ん中より上なら、x == medの結果に1つ前のレベルの結果を改造したものを足せばよい
    elif x > med:
        return putty[n - 1] + 1 + rec(n - 1, x - med)


ans = rec(n, x)

print(ans)

Measured memory_bytes: 3572
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
  int r;
  cin>>r;
  if(r<1200){
    cout<<"ABC"<<endl;
  }else if(r<2800){
    cout<<"ARC"<<endl;
  }else{
    cout<<"AGC"<<endl;
  }
  return 0;
}

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

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

typedef pair<pair<string,int>, int> P;

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

  vector<P> v;
  REP(i, N) {
    string s; int x;
    cin >> s >> x;
    v.push_back({{s, -x}, i+1});
  }
  sort(ALL(v));
  REP(i, N) {
    cout << v[i].second << endl;
  }

  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}

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

int main()
{
    int k ,s,count=0;
    cin>>k>>s;
    if (s != 3*k)
    {
            for(int i=k;i>=0;i--)
        {
            for(int j =k;j>=0;j--)
            {
                   // cout <<i<<j<<l<<endl;
                    if (s-i-j >=0 && s-i-j <= k)
                    {
                        count++;
                    }
                
            }
        }
    }
    else
        count++;
    cout<<count;
}

Measured memory_bytes: 256
#pragma comment(linker, "/STACK:102400000,102400000")
#include<algorithm>
#include<iostream>
#include<cstring>
#include<fstream>
#include<bitset>
#include<cstdio>
#include<string>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<set>
#define INF 0X3F3F3F3F
#define N 200010
#define M 2000100
#define LL long long
#define FF(i,a,b) for(int i=a;i<=b;++i)
#define RR(i,a,b) for(int i=a;i>=b;--i)
#define FJ(i,a,b) for(int i=a;i<b;++i)
#define SC(x) scanf("%d",&x)
#define SCC(x,y) scanf("%d%d",&x,&y)
#define SCCC(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define SS(x) scanf("%s",x)
#define PR(x) printf("%d\n",x)
#define CL(a,b) memset(a,b,sizeof(a))
#define FD T&q=fd[rt],&ql=fd[rt<<1],&qr=fd[rt<<1|1]
#define MID int mid=((l+r)>>1)
#define lson rt<<1,l,mid
#define rson rt<<1|1,mid+1,r
#define zero(x) (((x)>0?(x):-(x))<EPS)
#define PB push_back
#define SZ size
#define PII pair<int,int>
#define PLL pair<long long,long long>
#define MP make_pair
#define IN freopen("in.txt","r",stdin)
#define OUT freopen("out.txt","w",stdout)
using namespace std;
const int MOD=1000000007;
const double PI=acos(-1.0);
const double EPS=1e-8;
inline int II(){int n=0,ch=getchar();bool t=0;if(ch==-1)return 0;
for(;ch<'0'||ch>'9';ch=getchar())if(ch=='-')t=1;
for(;ch>='0'&&ch<='9';n=n*10+ch-'0',ch=getchar());if(t)return -n;return n;}
inline void OO(int a){if(a<0){putchar('-');a=-a;}
if(a>=10)OO(a/10);putchar(a%10+'0');}
inline int sgn(double x){return(x>EPS)-(x<-EPS);}
struct edge{int v,nx;}E[M*2+N*2];int head[N],EN;
void init_edge(){EN=0;CL(head,-1);}
void add_edge(int u,int v){
    E[EN]=(edge){v,head[u]};head[u]=EN++;
  //  E[EN]=(edge){u,head[v]};head[v]=EN++;
}
int n,b[N];
LL a[N];
int main(){
 //   IN;
    SC(n);
    FF(i,1,n)SC(b[i]);
    LL tot=0;
    FF(i,1,n)tot+=b[i];
    LL tmp=1LL*(1+n)*n/2;
    if(tot%tmp){
        puts("NO");
        return 0;
    }
    LL k=tot/tmp;
    LL mm=0;
    FF(i,2,n)a[i]=b[i]-b[i-1];
    a[1]=b[1]-b[n];
    FF(i,1,n){
        if((k<a[i])||(k-a[i])%n){
            puts("NO");
            return 0;
        }
    }
    puts("YES");
    return 0;
}


Measured memory_bytes: 1408
n = int(input())
a=1
b=1
c=1
d=1
mod = 1000000007
for _ in range(n):
    a=a*10%mod
    b = b*9%mod
    c = c*9%mod
    d = d*8%mod
print((a-b+mod - c+mod+d)%mod)

Measured memory_bytes: 63364
z = [0 for _ in range(8)]
z[:4] = list(map(int, input().split()))
for i in range(2):
    z[2*i + 4] = z[2*i + 2] - z[2*i + 3] + z[2*i + 1]
    z[2*i + 5] = z[2*i + 3] + z[2*i + 2] - z[2*i]
print(z[4], z[5], z[6], z[7])

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

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

int main()
{
  int n;
  cin >> n;
  int an, bn;
  vector<int> num(n);
  vector<int> a(n);
  vector<int> b(n);
  rep(i, n)
  {
    num[i] = i + 1;
  }
  rep(i, n)
  {
    int in;
    cin >> in;
    a[i] = in;
  }
  rep(i, n)
  {
    int in;
    cin >> in;
    b[i] = in;
  }
  int count = 1;
  do
  {
    if (num == a)
    {
      an = count;
    }
    if (num == b)
    {
      bn = count;
    }
    count++;
  } while (next_permutation(num.begin(), num.end()));
  cout << abs(an - bn) << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using ld = long double;
const int INF = (1<<30)-1;
const long long LINF = (1LL<<62)-1;
const long double PI = acos(-1.0L);
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  vector<int> num(n);
  rep(i, n) {
    int a;
    cin >> a;
    num[--a]++;
  }
  sort(num.rbegin(), num.rend());
  int ans = n;
  rep(i, k)
    ans -= num[i];
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#include <string>

using namespace std;

int main() {
	long long t;
	int n;
	cin >> n;
	for(int i = 0;i < n;i++) {
		int e;
		cin >> e;
		t += e;
	}
	t -= n;
	cout << t;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,sum=0;
  cin>>n;
  int k;
  string s;
  cin>>k>>s;
  int c=0;
  char last;
  int ans=0;
  for(int i=0;i<n;i++)
  {
    if(s[i]!=last)
    {
      last=s[i];
      c++;
    }
    if(s[i]=='L' && i>0 && s[i-1]=='L')ans++;
    if(s[i]=='R' && i<n-1 && s[i+1]=='R')ans++;
  }
  int half=(c-1)/2;
  if(k>half){
    ans=n-1;
  }
  else{
    ans+=2*k;}
  
  cout<<ans<<endl;
  return 0;
}
    
    

Measured memory_bytes: 512
using System;

public class hello
{
    public static int[] dx, dy, dy2;
    public static int h, w;
    public static void Main()
    {
        dx = new int[] { 0, 1, 1, 1, 0, -1, -1, -1 };
        dy = new int[] { 1, 1, 0, -1, -1, -1, 0, 1 };
        dy2 = new int[] { 1, -1 };
        string[] line = Console.ReadLine().Trim().Split(' ');
        h = int.Parse(line[0]);
        w = int.Parse(line[1]);
        var map = new bool[h, w];
        for (int i = 0; i < w; i++) map[0, i] = true;
        for (int i = 0; i < h; i++)
        {
            var s = Console.ReadLine().Trim();
            for (int j = 0; j < w; j++)
            {
                if (s[j] == 'o') putMap2(map, i, j);
                else if (s[j] == 'x') putMap8(map, i, j);
            }
        }
        var ans = 0;
        foreach (var x in map) if (!x) ans++;
        Console.WriteLine(ans);

    }
    static void putMap8(bool[,] map, int x, int y)
    {
        map[x, y] = true;
        for (int i = 0; i < 8; i++)
        {
            var nx = x + dx[i];
            var ny = y + dy[i];
            if (nx >= 0 && nx < h && ny >= 0 && ny < w) map[nx, ny] = true;
        }
    }
    static void putMap2(bool[,] map, int x, int y)
    {
        map[x, y] = true;
        for (int i = 0; i < 2; i++)
        {
            var ny = y + dy2[i];
            if (ny >= 0 && ny < w) map[x, ny] = true;
        }
    }
}



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

int main() {
  int A , B;
  cin >> A >> B;
  
  if ( A + B < 24){
    cout << A + B << endl;
  }
  else if ( A + B >-24){
    cout << A + B - 24 << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <map>
#include <set>
#include <bitset>
#include <sstream>
#include <cstdlib>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <climits>
#include <ctype.h>
using namespace std;

#define PI acos(-1.0)
#define EPS 1e-8
#define MOD 1000000007
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define fi first
#define se second

typedef long double ld;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;

struct Matrix {
    vvi data;
    int r, c;
    Matrix(int row, int col, bool identity = false) : r(row), c(col) {
        data.assign(row, vector<int>(col, 0));
        if (identity) {
            for (int i = 0; i < r; ++i) {
                data[i][i] = 1;
            }
        }
    }
    Matrix operator * (Matrix& other) {
        int m = r, n = c, p = other.c;
        Matrix res(m, p);
        for (int i = 0; i < m; ++i) {
            for (int j = 0; j < p; ++j) {
                for (int k = 0; k < n; ++k) {
                    res.data[i][j] += data[i][k] * other.data[k][j];
                }
            }
        }
        return res;
    }
};

// 扩展欧几里得算法 res[1] * a + res[2] * b = res[0] = gcd(a, b)
vector<int> extendGcd(int a, int b) {
    if (b == 0) {
        return {a, 1, 0};
    } else {
        vector<int> tmp = extendGcd(b, a % b);
        return {tmp[0], tmp[2], tmp[1] - (a / b) * tmp[2]};
    }
}

// 矩阵快速幂
Matrix matrix_power(Matrix base, ll exp) {
    int n = base.r;
    Matrix res(n, n, true);
    while (exp) {
        if (exp & 1) {
            res = res * base;
        }
        base = base * base;
        exp >>= 1;
    }
    return res;
}

// 带模快速幂
template <typename T>
T power_mod(T base, int exp, int mod = MOD) {
    T res = 1;
    while (exp) {
        if (exp & 1) res = res * base % mod;
        base = base * base % mod;
        exp >>= 1;
    }
    return res;
}

// 快速幂
template <typename T>
T power(T base, int exp) {
    T res = 1;
    while (exp) {
        if (exp & 1) res *= base;
        base *= base;
        exp >>= 1;
    }
    return res;
}

// 求逆元
ll inv(ll a) {
    return power_mod(a, MOD - 2);
}

/******************************** template ********************************/
#define N 5050
int n;
vector<pll> foo;

bool cmp(pll a, pll b) {
    ll aa = a.fi + a.se;
    ll bb = b.fi + b.se;
    return aa < bb;
}

int main() {
    cin >> n;
    ll h, p;
    for (int i = 0; i < n; ++i) {
        cin >> h >> p;
        foo.pb({h, p});
    }
    sort(all(foo), cmp);
    ll tot = 0;
    priority_queue<ll> pq;
    for (int i = 0; i < n; ++i) {
        if (tot <= foo[i].fi) {
            tot += foo[i].se;
            pq.push(foo[i].se);
        } else if (pq.top() > foo[i].se) {
            tot -= pq.top() - foo[i].se;
            pq.pop();
            pq.push(foo[i].se);
        }
    }
    cout << pq.size();

    return 0;
}

Measured memory_bytes: 512
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Main main = new Main();
		main.solve();
	}

	void solve() throws Exception {
		try (Scanner cin = new Scanner(System.in)) {
			int count = cin.nextInt();
			List<Integer> list = new ArrayList<>(count);
			list.add(cin.nextInt());

			boolean even;
			if (count % 2 == 0) {
				even = true;
			} else {
				even = false;
			}

			while (cin.hasNext()) {
				list.add(cin.nextInt());
			}

			int index = 0;

			if (even) {
				index = list.size() - 1;
				System.out.print(list.get(index));
				index -= 2;
				while (index >= 0) {
					System.out.print(" " + list.get(index));
					index -= 2;
				}
				index = 0;
				while (index < list.size()) {
					System.out.print(" " + list.get(index));
					index += 2;
				}
			} else {
				index = list.size() - 1;
				System.out.print(list.get(index));
				index -= 2;
				while (index >= 0) {
					System.out.print(" " + list.get(index));
					index -= 2;
				}
				index = 1;
				while (index < list.size()) {
					System.out.print(" " + list.get(index));
					index += 2;
				}
			}

		} finally {
		}
	}

}


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

#define FOR(i, a, b) for(long long int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000 //2000000000
#define LLINF 1000000000000000000 //9000000000000000000
#define PI 3.14159265358979

using namespace std;
typedef long long int ll;
typedef pair< long long int, long long  int> P;



int main(void) {
	string str;
	int q;
	int a, b;
	string jud;
	string repl;
	string t, r;

	cin >> str;
	cin >> q;
	FOR(i, 1, q) {
		cin >> jud;
		cin >> a >> b;
		if (jud == "print") {
			t = str.substr(a, b-a+1);
			cout << t << endl;
		}
		else if (jud == "reverse") {
			t = str.substr(a, b-a+1);
			r = t;
			RFOR(u,t.size() - 1,0) {
				t[u] = r[t.size() - 1 - u];
			}
			str.replace(a, b-a+1, t);
		}
		else if (jud == "replace") {
			cin >> repl;
			str.replace(a, b-a+1, repl);
		}
	}

	
	
	return 0;
}



Measured memory_bytes: 3180
#include<iostream>
#include<vector>
#include <cstdlib>

using namespace std;

int main(){
  int a,b,c;
  cin >> a >> b >> c;
  if(a==b) cout <<c;
  else if(a==c) cout <<b;
  else if(b==c) cout<<a;
  
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		String str = sc.next();
		int tmp = 'a' - 'A';
		char[] array = str.toCharArray();
		array[k - 1] += tmp;
		System.out.println(array);
	}
}


Measured memory_bytes: 21844
#include <iostream>
 
using namespace std;
 
#define rep(i, n) for (int i = 0; i < n; i++)
 
int main(void) {
    string s;
    cin >> s;
    int ans = 0; // 数を数えるための変数。これが答えになる
    
    for (int i = 0; i < 3; i++){
      if (s[i] == '1') {
        ans++;
      }
    }
  
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import sys

S = input()
T = input()

if len(S) == len(T):
    changeCounter = 0
    for j in range(len(S)):
        if not S[j] == T[j]:
            changeCounter += 1
    print(changeCounter)
    sys.exit()

minChangeCounter = 1000000
for i in range(len(S) - len(T)):
    substr = S[i:i + len(T)]
    changeCounter = 0
    for j in range(len(T)):
        if not substr[j] == T[j]:
            changeCounter += 1
    if changeCounter < minChangeCounter: minChangeCounter = changeCounter
print(minChangeCounter)


Measured memory_bytes: 72540
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
int n,m,k;
int main(){
    scanf("%d%d%d",&n,&m,&k);
    for(int i = 0; i <= n ; i++){
		for(int j = 0; j <= m ; j++){
            if( (i*m+j*n-2*i*j) == k){
                printf("Yes\n");
                return 0;
            }
		}
    }
    printf("No\n");
}


Measured memory_bytes: 256
N,K=[int(c) for c in input().split()]
S=input()
K-=1
if(S[K]=="A"):
	print(S[:K]+"a"+S[K+1:])
if(S[K]=="B"):
	print(S[:K]+"b"+S[K+1:])
if(S[K]=="C"):
	print(S[:K]+"c"+S[K+1:])

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

int main() {
    int y,m,d;
    char g[10];
    
    while(1){
        scanf("%s%d%d%d",g,&y,&m,&d);
        if(strcmp(g, "#")==0) break;
        if((y==31 && m>4) || y>31)
            printf("? %d %d %d\n",y-30,m,d);
        else
            printf("%s %d %d %d\n",g,y,m,d);
    }
    return 0;
}


Measured memory_bytes: 2060
s = input().split();
n = int(s[0])
k = int(s[1])

A= [0 for i in range(n)]
ans = n
for i in range(k):
	d = input() 
	d = int(d)
	a =  list(map(int, input().split()))
	
	for j in range(d):
		if A[a[j]-1]== 0:
			A[a[j]-1]=1
			ans = ans -1
		else:
			continue

print(ans)

Measured memory_bytes: 67692
#include<bits/stdc++.h>
#include<string>
#define chal ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
int main()
{
    string s,t;
    long ans=0;
    cin>>s>>t;
    for(long i=0;i<s.size();i++)
    {
        if(s[i]!=t[i])
            ans++;
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 3916
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        n:usize
    }
    let mut ans = 0;
    for i in 1..n+1{
        ans += i;
    }
    println!("{}",ans);
}


Measured memory_bytes: 4476
#include <iostream>
using namespace std;
char mark[102][102];
char tmp[102][102];

int main() {
	int H, W;cin >> H >> W;
	for (int i = 0;i < H;i++) {
		for (int k = 0;k < W;k++) {
			cin >> mark[i][k];
			tmp[i][k] = mark[i][k];
		}
	}

	for (int i = 0;i < H;i++) {
		bool Hflag = 1;
		for (int k = 0;k < W;k++) {
			if (mark[i][k] == '#') {
				Hflag = 0;
			}
		}

		if (Hflag) {
			for (int k = 0;k < W;k++) {
				tmp[i][k] = '0';
			}
		}
	}


	
	for (int k = 0;k < W;k++) {
		bool Kflag = 1;
		for (int i = 0;i < H;i++) {
			if (mark[i][k] == '#') {
				Kflag = 0;
			}
		}
		if (Kflag) {
			for (int i = 0;i < H;i++) {
				tmp[i][k] = '0';
			}
		}
	}

	for (int i = 0;i < H;i++) {
		bool enter = 0;
		for (int k = 0;k < W;k++) {
			if (tmp[i][k] != '0') {
				cout << mark[i][k];
				enter = 1;
			}
		}

		if (enter)cout << "\n";
	}

	return 0;
}


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

int main(){
  string s, o;
  cin >> s;
  o = "";
  for(auto c : s){
    if(c =='B'){o=o.substr(0,o.length()-1);continue;}
    o += c;
  }
  cout << o;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <math.h>
#include <map>
using namespace std;

const int MAXN = 2e5 + 10;
int N;
map<long long, int> cnt;
long long ans;

int main() {
    register int i; long long x = 0, y;
    scanf( "%d", &N ); ++cnt[0];
    for( i = 1; i <= N; ++i )
        scanf( "%lld", &y ), x += y, ans += cnt[x], ++cnt[x];
    printf( "%lld\n", ans );
    return 0;
}

Measured memory_bytes: 12800
/*
ID: Aman Raj
LANG: C++
TASK: milk3
*/
#include<iostream>
#include <stdio.h>
//#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
#include<math.h>
typedef long long ll;
 #include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
//setbase - cout << setbase (16); cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 << endl; prints xxx77
//setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx
//cout.precision(x)  cout<<fixed<<val;  // prints x digits after decimal in val

using namespace std;
using namespace __gnu_pbds;

#define f(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define vl vector< ll >
#define ss second
#define ff first
//#define ll long long
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod (1000*1000*1000+7)
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >
//#define flush fflush(stdout)
#define primeDEN 727999983
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#include <fstream>
// find_by_order()  // order_of_key
typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;


int main()
{    ifstream fin ("milk3.in");
     ofstream fout ("milk3.out");
     ll n,k;cin>>n>>k;
     cout<<setprecision(12);
     double ans=0.000000000;
      for(ll i=1;i<=n;i++)
      {   double p=1;
          ll j=i;if(j<k){while(j<k){p*=(1.000000000000/2);j*=2;}}
          ans+=(1.000000000000/n)*p;
      }
      cout<<ans;

    return 0;

}


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

using namespace std;

#define FOR(i, j, k) for(int i = j; i < k; ++i)
#define rep(i, j) FOR(i, 0, j)
#define INF (1 << 30)

int main() {
	int map[100][100];
	int W, H, N;
	int x, y, a;
	cin >> W >> H >> N;
	memset(map, 0, sizeof(map));
	rep(i, N) {
		cin >> x >> y >> a;
		if(a == 1) rep(i, H) rep(j, x) map[i][j] = 1;
		else if(a == 2) rep(i, H) for(int j = x; j < W; ++j) map[i][j] = 1;
		else if(a == 3) rep(i, y) rep(j, W) map[i][j] = 1;
		else if(a == 4) for(int j = y; j < H; ++j) rep(i, W) map[j][i] = 1;
	}
	int ans = 0;
	rep(i, H) rep(j, W) if(map[i][j] == 0) ++ans;
	cout << ans << endl; 
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define L long long
using namespace std;
int n,p;
char s[310][310],t[310][310];
int main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	int i,j,k,l;
	scanf("%d",&n);
	for(i=1;i<=n;i++)
	  scanf("%s",s[i]+1);
	for(k=0;k<n;k++)
	  {
       for(i=1;i<=n;i++)
         for(j=1;j<=n;j++)
           t[i][(j+k-1)%n+1]=s[i][j];
       for(i=1,l=0;i<=n;i++)
         for(j=1;j<=n;j++)
           if(t[i][j]!=t[j][i])
             l=1;
       if(!l)
         p++;
      }
    printf("%d\n",p*n);
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define db3(x, y, z) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define dbv(v) cerr << #v << "="; for (auto _x : v) cerr << _x << ", "; cerr << endl
#define dba(a, n) cerr << #a << "="; for (int _i = 0; _i < (n); ++_i) cerr << a[_i] << ", "; cerr << endl
typedef long long ll;
typedef long double ld;
int A[1005], B[1005], cnt[1000005];
bool appear[1000005], used[1000005];
void no() {
	printf("0\n");
	exit(0);
}
const ll MOD = 1000000007;
int main() {
	int n, m;
	scanf("%d%d", &n, &m);
	for (int i = 0; i < n; ++i) scanf("%d", &A[i]);
	for (int i = 0; i < m; ++i) scanf("%d", &B[i]);
	for (int i = 0; i < m; ++i) {
		if (appear[B[i]]) no();
		appear[B[i]] = true;
	}
	memset(appear, 0, sizeof(appear));
	for (int i = 0; i < n; ++i) {
		if (appear[A[i]]) no();
		appear[A[i]] = true;
	}
	for (int i = 0; i < m; ++i) {
		if (appear[B[i]]) {
			used[B[i]] = true;
		}
	}
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < m; ++j) {
			++cnt[min(B[j], A[i])];
		}
	}
	ll ans = 1;
	for (int i = 0; i < m; ++i) {
		if (!cnt[B[i]]) no();
		if (!used[B[i]]) {
			ans = ans * cnt[B[i]] % MOD;
			used[B[i]] = true;
		}
		--cnt[B[i]];
	}
	for (int i = 0; i < n; ++i) {
		if (!used[A[i]]) {
			if (!cnt[A[i]]) no();
			ans = ans * cnt[A[i]] % MOD;
			used[A[i]] = true;
			--cnt[A[i]];
		}
	}
	int avail = 0;
	for (int i = n * m; i >= 1; --i) {
		avail += cnt[i];
		if (!used[i]) {
			ans = ans * avail % MOD;
			--avail;
		}
	}
	printf("%lld\n", ans);
}


Measured memory_bytes: 1280
import java.util.concurrent.LinkedBlockingDeque
import kotlin.math.min

fun main() {
    val n = readLine()?.toInt() ?: return
    val r = n
    var c = Int.MAX_VALUE

    fun sub(v: Int): Pair<Int, Int> {
        var six = 6
        if (six > v) {
            six = -1
        } else {
            while (true) {
                if (six == v) {
                    break
                }
                val newSix = six * 6
                if (newSix > v) {
                    break
                }
                six = newSix
            }
        }
        var nine = 9
        if (nine > v) {
            nine = -1
        } else {
            while (true) {
                if (nine == v) {
                    break
                }
                val newNine = nine * 9
                if (newNine > v) {
                    break
                }
                nine = newNine
            }
        }
        return Pair(six, nine)
    }

    val f = sub(r)
    val queue = LinkedBlockingDeque<List<Int>>()
    if (f.first != -1) {
        queue.offer(listOf(f.first))
    } else {
        c = min(c, r)
    }
    if (f.second != -1) {
        queue.offer(listOf(f.second))
    } else {
        c = min(c, r)
    }

    while (queue.isNotEmpty()) {
        val q = queue.poll()
        val s = q.sum()
        val next = sub(r - s)
        if (next.first == -1) {
            c = min(
                c, q.size + if (s == r) 0 else {
                    r - s
                }
            )
        } else {
            queue.offer(q + listOf(next.first))
        }
        if (next.second == -1) {
            c = min(
                c, q.size + if (s == r) 0 else {
                    r - s
                }
            )
        } else {
            queue.offer(q + listOf(next.second))
        }
    }
    println(c.toString())
}

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

using namespace std;

int main()
{
  int N;
  cin >> N;
  int ok = 1;
  while(ok * (ok + 1) / 2 < N) ++ok;
  string S = string(ok, ')') + string(ok, '(');
  swap(S[ok], S[ok - (ok * (ok + 1) / 2) + N]);
  cout << S << endl;
}

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

int main (){
    int Alice, Bob;
    cin>>Alice>>Bob;
    if(Alice==1){
        Alice+=13;
    }
    if(Bob==1){
        Bob+=13;
    }
    if(Alice>Bob){
        cout<<"Alice"<<endl;
    }
    else if(Alice<Bob){
        cout<<"Bob"<<endl;
    }
    else{
        cout<<"Draw"<<endl;
    }


}

Measured memory_bytes: 256
s = gets.chomp.split("")
if  (s[0] == "A")&& (s[2..-2].count{|t|t == "C"} == 1)
  s.delete_at(0)
  s.delete("C")
  require 'set'
  al = ("a".."z").to_a
  if  Set.new(al).superset?(Set.new(s))
    puts "AC"
  else
    puts "WA"
  end
else
    puts "WA"
end


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

int main() {
	string s, t;
	cin >> s >> t;
	int a, b;
	cin >> a >> b;
	string x;
	cin >> x;
	if (x == s)
		--a;
	if (x == t)
		--b;
	cout << a << ' ' << b << '\n';
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
using namespace std;
const int MAXW = 1e4 + 7;
int v[107], w[107], dp[2][MAXW];
int main() {
    int n, W;
	scanf("%d%d", &n, &W);
	for (int i = 1; i <= n; i++) {
		scanf("%d%d", &v[i], &w[i]);
	}
	for (int i = 1; i <= n; i++) {
		for (int j = 0; j <= W; j++) {
			if (j >= w[i]) dp[i % 2][j] = max(dp[(i - 1) % 2][j], dp[(i - 1) % 2][j - w[i]] + v[i]);
			else dp[i % 2][j] = dp[(i - 1) % 2][j];
		}
	}
	printf("%d\n", dp[n % 2][W]);
	return 0;
}


Measured memory_bytes: 2840
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
#define erep(i,n) for(int i = 0;i<=n;i++)
#define rep1(i,n) for(int i = 1;i<n;i++)
#define erep1(i,n) for(int i = 1;i<=n;i++)
typedef long long ll;
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstring vector<string>
#define vdouble vector<double>
#define vll vector<ll>:
#define vbool vector<bool>
#define INF 1101010101010101010
#define MOD 1000000007
#define int long long
using P = pair<int,int>;
signed main(){
  int h,w;
  cin >> h >> w;
  int n;
  cin >> n;
  vint A(n);
  rep(i,n) cin >> A[i];
  vvint ans(h,vint(w));
  int xcount = 0;
  int ycount = 0;
  int nowcolor = 1;
  int colorcount = 0;
  bool flag = true;
  int sum = h*w;
  while(sum--){
    ans[xcount][ycount] = nowcolor;
    colorcount++;
    if(flag){
      if(ycount == w-1){
        xcount++;
        flag = false;
      }
      else{
        ycount++;
      }
    }
    else{
      if(ycount == 0){
        xcount++;
        flag = true;
      }
      else{
        ycount--;
      }
    }
    if(colorcount == A[nowcolor-1]){
      colorcount = 0;
      nowcolor++;
    }
  }
  rep(i,h){
    rep(j,w){
      cout << ans[i][j] << " ";
    }
    cout << endl;
  }
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#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++)
#define fi first
#define se second
#define mp make_pair
#define itrfor(itr,A) for(auto itr = A.begin(); itr !=A.end();itr++)
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;
typedef long long llong;
char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define print(a) cout << a << endl;
#define MOD llong(1e9+7)
#define MAX int(2 * 1e5 +5)
#define debug(x)  cout << #x << " = " << (x) << endl;
#define pi acos(-1.0)
#define int llong
#define INF llong(1e17)
template<class T> bool chmax(T &a,  T b) {if(a<b){a=b; return 1;} return 0;}
template<class T> bool chmin(T &a,  T b) {if(a>b){a=b; return 1;} return 0;}
bool Add(int &a,int b){a = (a + b) % MOD;}
void myprint(int* A,int A_num){
   REP(i,A_num) cout << A[i] << " ";
   cout << endl;
}

signed main(){
    int n,l;
    cin >> n >> l;
    vector<int> ans;
    int bef = -INF;
    int now;
    int id = -1;
    REP(i,n){
        cin >> now;
        if(now + bef >= l){
            id = i;
            bef = now;
        } 
        else{
            bef = now;
        }
    }


    if(id == -1){
        cout << "Impossible" << endl;
        return 0;
    }
    cout << "Possible" << endl;
    ans.push_back(id);
    FOR(i,id + 1,n) ans.push_back(i);
    REPR(i,id-1){
        if(i == 0) break;
        ans.push_back(i);
    }

    Reverse(ans);
    itrfor(itr,ans) cout << *itr << endl;

}

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

int main() {
	// your code goes here
	int n, k;
	cin >> n;
	vector<int> a(n, 0), b(n, 0), c(n, 0);
	vector<vector<int> >dp(n, vector<int>(3, 0));
	for(int i = 0; i < n; ++i) cin >> a[i] >> b[i] >> c[i];
	dp[0][0] = a[0], dp[0][1] = b[0], dp[0][2] = c[0];
	for(int i = 1; i < n; ++i){
		dp[i][0] = max(dp[i-1][1], dp[i-1][2]) + a[i];
		dp[i][1] = max(dp[i-1][0], dp[i-1][2]) + b[i];
		dp[i][2] = max(dp[i-1][0], dp[i-1][1]) + c[i];
	}
	cout << max(dp[n-1][0], max(dp[n-1][1], dp[n-1][2])) << endl;
	return 0;
}

Measured memory_bytes: 6912
x, y = map(int,input().split())

if x*y < 0: #異符号→反転可能性あり
    print(abs(abs(x)-abs(y))+1)

elif x*y == 0:
    if x <= y:
        print(y-x)
    else:
        print(x-y+1)

else: #同符号→反転可能性なし
    if x <= y:
        print(y-x)
    else:
        print(x-y+2)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
bool pal(string st)
{
    string ts=st;
	reverse(st.begin(),st.end());
    return ts==st;
}
int main()
{
    ios::sync_with_stdio(0);
    char ss[102];
	string s;
    string st1;
    st1="";
    cin>>s; 
    for(int i=0;i<(s.size()+1)/2-1;i++)
    st1+=s[i];
    bool f=true;
    if(!(pal(s))) f=false;
    if(!(pal(st1))) f=false;
    if(f) cout<<"Yes\n";
    else cout<<"No\n";
    return 0;
}


Measured memory_bytes: 256
// abc066_b
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) rep(i,v.size())cout<<" "<<v[i];cout<<endl<<endl;
#define show2d(v) rep(i,v.size()){rep(j,v[i].size())cout<<" "<<v[i][j];cout<<endl;}cout<<endl;
using namespace std;
typedef long long ll;
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1};
int dy[] = {1, 0, -1, 0};
int main(int argc, char *argv[])
{
  string s, a, b;
  cin >> s;
  int size = (int)s.size();
  for (int i=0;i<size;++i) {
    if ((size-i)%2!=0||i==0) continue;

    a = s.substr(0,(size-i)/2);
    b = s.substr((size-i)/2,(size-i)/2);
    if (a == b) {
      cout << (int)a.size()+(int)b.size() << endl;
      break;
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define forn(i, n) for(ll i = 0; i < (ll)(n); i++)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef unsigned int ui32;
const long long INFLL = 1e18;
using namespace std;

const ll MAXN = 102 + 10;
const ll INF = 1000 * 1000 * 1000;

struct edge {
    ll a, b, cap, flow;
};

ll n, s, t, d[MAXN], ptr[MAXN], q[MAXN], a[MAXN];
vector<edge> e;
vector<ll> g[MAXN];

void add_edge (ll a, ll b, ll cap) {
    edge e1 = { a, b, cap, 0 };
    edge e2 = { b, a, 0, 0 };
    g[a].push_back ((ll) e.size());
    e.push_back (e1);
    g[b].push_back ((ll) e.size());
    e.push_back (e2);
}

bool bfs() {
    ll qh=0, qt=0;
    q[qt++] = s;
    memset (d, -1, n * sizeof d[0]);
    d[s] = 0;
    while (qh < qt && d[t] == -1) {
        ll v = q[qh++];
        for (size_t i=0; i<g[v].size(); ++i) {
            ll id = g[v][i],
                    to = e[id].b;
            if (d[to] == -1 && e[id].flow < e[id].cap) {
                q[qt++] = to;
                d[to] = d[v] + 1;
            }
        }
    }
    return d[t] != -1;
}

ll dfs (ll v, ll flow) {
    if (!flow)  return 0;
    if (v == t)  return flow;
    for (; ptr[v]<(ll)g[v].size(); ++ptr[v]) {
        ll id = g[v][ptr[v]],
                to = e[id].b;
        if (d[to] != d[v] + 1)  continue;
        ll pushed = dfs (to, min (flow, e[id].cap - e[id].flow));
        if (pushed) {
            e[id].flow += pushed;
            e[id^1].flow -= pushed;
            return pushed;
        }
    }
    return 0;
}

ll dinic() {
    ll flow = 0;
    for (;;) {
        if (!bfs())  break;
        memset (ptr, 0, n * sizeof ptr[0]);
        while (ll pushed = dfs (s, INFLL))
            flow += pushed;
    }
    return flow;
}

int main() {
    //ios_base::sync_with_stdio(false);
    //cin.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout

    cin >> n;
    s = 0, t = n + 1;
    ll sum = 0;
    for (ll i = 1; i <= n; i++) {
        scanf("%lld", &a[i]);
        if (a[i] < 0) {
            add_edge(s, i, -a[i]);
        } else {
            sum += a[i];
            add_edge(i, t, a[i]);
        }
        for (int j = i + i; j <= n; j += i) {
            add_edge(i, j, INF * MAXN);
        }
    }
    n += 2;
    cout << max(0LL, sum - dinic()) << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <cctype>
#include <cfloat>
#include <climits>
#include <cmath>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <ios>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <forward_list>
#include <random>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <unordered_map>
#include <unordered_set>
#endif

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define lcm( a, b ) (a)/__gcd((a),(b))*(b)
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;
typedef pair< int, P > iP;
typedef pair< P, P > PP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 200005;

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

vector< int > Div( int n ) {
    vector< int > ret;
    for( int i = 1; i * i <= n; ++i ) {
        if( n % i == 0 ) {
            ret.pb( i );

            if( i * i != n ) ret.pb( n / i );
        }
    }
    sort( all( ret ) );
    return ret;
}

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

    int a, b, c;
    cin >> a >> b >> c;
    if( a + b + c >= 22 ) cout << "bust";
    else cout << "win";
    cout << endl;
    return 0;
}



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

int main() {
	int n, x, sum;

	while (1) {
		cin >> n >> x;
		if (n == 0 && x == 0)
			break;

		sum = 0;

		for (int i = 1; i <= n - 2; i++) {
			for (int j = i + 1; j <= n - 1; j++) {
				for (int k = j + 1; k <= n; k++) {
					if (i + j + k == x)
						sum++;
				}
			}
		}
		cout << sum << endl;
	}

	return 0;
}

Measured memory_bytes: 1160
import java.util.*;

class Main {
	public static void main(String[] args){
		
		Scanner sc = new Scanner(System.in);
		
		final String[] len = sc.nextLine().split(" ");
		final int r = Integer.parseInt(len[0]);
		final int c = Integer.parseInt(len[1]);
		StringBuilder sb = new StringBuilder();
		final String lb = System.getProperty("line.separator");
		int[][] mat = new int[r + 1][c + 1];
		
		for(int i = 0; i < r; i++){
			final String[] col = sc.nextLine().split(" ");
			for(int j = 0; j < c; j++){
				mat[i][j] = Integer.parseInt(col[j]);
				mat[i][c] += mat[i][j];
				mat[r][j] += mat[i][j];
				sb.append(col[j]).append(" ");
			}
			sb.append(mat[i][c]).append(lb);
		}
		for(int i = 0; i < c; i++){
			sb.append(mat[r][i]).append(" ");
			mat[r][c] += mat[r][i];
		}
		sb.append(mat[r][c]).append(lb);
		System.out.print(sb.toString());
	}
}

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

int main() {
  int N, M;
  cin >> N >> M;
  
  int total = 0;
  for (int i = 0; i < M; i++ ) {
    int a;
    cin >> a;
    total = total + a;
  }
  
  int result = -1;
  if (total <= N) {
    result = N - total;
  }
  
  cout << result << endl;;
  
}


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

int main() {
  int n;
  string s;
  cin >> n >> s;
  int ans = 0;
  rep(i, n) ans += s.substr(i, 3) == "ABC";
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256