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

#define FOR(i,a,b) for(int i= (a); i<((int)b); ++i)
#define RFOR(i,a) for(int i=(a); i >= 0; --i)
#define FOE(i,a) for(auto i : a)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v,x) (std::find(v.begin(), v.end(), x) != v.end())
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());

typedef long long LL;
template<typename T> using V = std::vector<T>;
template<typename T> using VV = std::vector<std::vector<T>>;
template<typename T> using VVV = std::vector<std::vector<std::vector<T>>>;

template<class T> inline T ceil(T a, T b) { return (a + b - 1) / b; }
template<class T> inline void print(T x) { std::cout << x << std::endl; }
template<class T> inline void print_vec(const std::vector<T> &v) { for (int i = 0; i < v.size(); ++i) {  if (i != 0) {std::cout << " ";} std::cout << v[i];} std::cout << "\n"; }
template<class T> inline bool inside(T y, T x, T H, T W) {return 0 <= y and y < H and 0 <= x and x < W; }
template<class T> inline double euclidean_distance(T y1, T x1, T y2, T x2) { return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)); }
template<class T> inline double manhattan_distance(T y1, T x1, T y2, T x2) { return abs(x1 - x2) + abs(y1 - y2); }

const int INF = 1L << 30;
const double EPS = 1e-9;
const std::string YES = "YES", Yes = "Yes", NO = "NO", No = "No";
const std::vector<int> dy4 = { 0, 1, 0, -1 }, dx4 = { 1, 0, -1, 0 };    // 4近傍（右, 下, 左, 上）
const std::vector<int> dy8 = { 0, -1, 0, 1, 1, -1, -1, 1 }, dx8 = { 1, 0, -1, 0, 1, 1, -1, -1 };

using namespace std;

bool ok(int y1, int y2, int x1, int x2, int k, vector<int> &ys, vector<int> &xs) {
    int count = 0;
    FOR(i, 0, ys.size()) {
        int y = ys[i];
        int x = xs[i];
        if (y1 <= y and y <= y2 and x1 <= x and x <= x2) {
            count++;
        }
    }
    return count >= k;
}

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

	int N, K;
	cin >> N >> K;
	vector<int> xx, yy;
	vector<int> xs(N), ys(N);
	FOR(i, 0, N) {
	    cin >> xs[i] >> ys[i];
	    xx.emplace_back(xs[i]);
	    yy.emplace_back(ys[i]);
	}

    sort(ALL(yy));
    sort(ALL(xx));

    LL ans = LONG_LONG_MAX;
	FOR(i, 0, yy.size()) {
	    FOR(j, i + 1, yy.size()) {
            FOR(k, 0, xx.size()) {
                FOR(l, k + 1, xx.size()) {
                    if (ok(yy[i], yy[j], xx[k], xx[l], K, ys, xs)) {
                        ans = min(ans, (LL)abs(yy[i] - yy[j]) * (LL)abs(xx[k] - xx[l]));
                    }
                }
            }
	    }
	}
    print(ans);

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <numeric>
#include <stdio.h>
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)






int main() {
	int N;
	
	cin >>N;
	string s = "ARC";
	if (N < 1200) {
		s = "ABC";
	}
	cout <<s<< endl;
}


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

#define REP(i,n) for(int i = 0; i < n; i++)
#define ll long long
#define PI M_PI
#define bf printf("\n");

using namespace std;

int main(void){
    int N;  cin >> N;
    int d[N];
    REP(i,N) cin >> d[i];

    sort(d,d+N);
    
    cout << d[N/2]-d[N/2-1] << endl;
    return 0;
}

Measured memory_bytes: 640
x = int(input())
dp = [0]*(x + 105 + 1)
dp[100] = 1 
dp[101] = 1
dp[102] = 1
dp[103] = 1
dp[104] = 1
dp[105] = 1

for i in range(100,x-105+6):
    for j in range(100,106):
        dp[i+j] = max(dp[i] , dp[i+j])

print(dp[x])

Measured memory_bytes: 9524
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
//using namespace __gnu_pbds;

#define ll long long int
#define endl "\n"
#define db(x) cout<<#x<<" ->"<<x<<endl
#define db2(x,y) cout<<#x<<"->"<<x<<", "<<#y<<" -> "<<y<<endl
#define db3(x,y,z) cout<<#x<<" -> "<<x<<" , "<<#y<<" -> "<<y<<" , "<<#z<<" -> "<<z<<endl
#define db4(w,x,y,z) cout<<#w <<" -> " << w << " , " << #x<<" -> "<<x<<" , "<<#y<<" -> "<<y<<" , "<<#z<<" -> "<<z<<endl
#define prt(x) for(auto it = x.begin(); it!=x.end(); it++) { cout<<*it<<" "; } cout<< endl
#define IN freopen("input.txt","r",stdin)

//template<typename T>
//using ordered_set =
//tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
const int N = (int)501;
vector< int > V[N + 5];

int32_t main(){
    ios_base::sync_with_stdio(false); cin.tie(0);
//    IN;
    int n , m , q;
    vector< int > L , R;
    cin >> n >> m >> q;
    while(m--){
        int l , r;
        cin >> l >> r;
        V[l].push_back(r);
    }
    for(int i = 0; i <= N; i++){
        sort(V[i].begin(),V[i].end());
    }
    while(q--){
        int l , r;
        cin >> l >> r;
        int sam = 0;
        for(int i = l; i <= r; i++){
            int res = upper_bound(V[i].begin(),V[i].end(),r) - V[i].begin();
            sam+=res;
        }
        cout << sam << endl;
    }
    return 0;
}


Measured memory_bytes: 2176
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+5;
int n,m,ans=0,father[N],sum[N];
int Findfather(int x){
    return father[x]==x?x:father[x]=Findfather(father[x]);
}
void Union(int x,int y){
    x=Findfather(x);
	y=Findfather(y);
    if(x!=y){
    	father[y]=x;
		sum[x]+=sum[y];
	}
}
void init(){
    for(int i=0;i<=n;i++){
    	father[i]=i,sum[i]=1;
	}
}
int main(){
    cin>>n>>m;
    init();
    while(m--){
        int u,v;
        cin>>u>>v;
        Union(u,v);
    }
    for(int i=1;i<=n;i++){
    	if(Findfather(i)==i){
    		ans=max(ans,sum[i]);
		}
	}
    cout<<ans;
    return 0;
}

Measured memory_bytes: 5408
#include <bits/stdc++.h>
using namespace std;
string s;
int temp;
bool valid;
int main() {
cin>>s;
for(int i=1;i<s.length();i++) {
	for(int j=0;j<s.length()-i;j++) {
		if(s[j]>s[j+1]) {
			temp=s[j];
			s[j]=s[j+1];
			s[j+1]=temp;
		}
	}
}
valid=true;
for(int i=0;i<s.length()-1;i++) {
	if(s[i]==s[i+1]) {
		valid=false;
	}
}
if(valid) {
	cout<<"yes"<<endl;
} else {
	cout<<"no"<<endl;
}
}


Measured memory_bytes: 3652
from math import ceil, floor
N,K=map(int, input().split())
if K % 2 == 1:
    ans = (floor(N/K) - ceil(1/K) + 1)**3
    print(ans)
else:
    ans = (floor(N/K - 1/2) - ceil(1/K - 1/2) + 1)**3
    ans += (floor(N/K) - ceil(1/K) + 1)**3
    print(ans)

Measured memory_bytes: 62244
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <list>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <iterator> 
#include <limits>

#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for (int i=(a); i<(b); i++)
#define ALL(a) (a).begin(),(a).end()
#define RALL(A) (a).rbegin(),(a).rend()
#define PB push_back
#define MP make_pair

#define dump(x) cerr << #x << " = " << (x) << endl;

using namespace std;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = numeric_limits<int>::max() / 2;
const int NEG_INF = numeric_limits<int>::min() / 2;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

int N;
LL x;
const int MAX_N = 2000;
int A[MAX_N];
int b[MAX_N];

void solve() {
    LL ans;
    REP(k, N) {
        LL tmp = k * x;
        REP(i, N) {
            if (k == 0) {
                b[i] = A[i];
            } else {
                int j = i - k;
                if (j < 0) j += N;
                b[i] = min(b[i], A[j]);
            }
            tmp += b[i];
        }
        //cout << k << " " << tmp << endl;
        if (k == 0) {
            ans = tmp;
        } else {
            ans = min(ans, tmp);
        }
    }
    cout << ans << endl;
}

int main(int argc, char const* argv[])
{
    cin >> N >> x;
    REP(i, N) cin >> A[i];
    solve();
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
struct block{
  bool right;
  bool down;
  bool left;
  bool up;
  block():right(false),down(false),left(false),up(false){}
};
void ud(block* b,string& s,int row){
  for(int i=0;i<4;i++){
    if(s[i]=='1'){
      b[row*6+i+1].down=true;
      b[(row+1)*6+i+1].up=true;
    }
  }
}
void lr(block* b,string& s,int row){
  for(int i=0;i<5;i++){
    if(s[i]=='1'){
      b[row*6+i].right=true;
      b[row*6+i+1].left=true;
    }
  }
}
enum direction{UP,RIGHT,DOWN,LEFT};

int main(){
  block b[36]{};
  int p=1;
  direction d=direction::RIGHT;
  string s;
  cin>>s; ud(b,s,0);
  cin>>s; lr(b,s,1);
  cin>>s; ud(b,s,1);
  cin>>s; lr(b,s,2);
  cin>>s; ud(b,s,2);
  cin>>s; lr(b,s,3);
  cin>>s; ud(b,s,3);
  cin>>s; lr(b,s,4);
  cin>>s; ud(b,s,4);
  do{
    switch(d){
    case direction::UP:
      cout<<"U";
      if(b[p].up){
	d=direction::LEFT;
      }else{
	p-=6;
	if(!b[p].right){
	  p+=1;
	  d=direction::RIGHT;
	  if(!b[p].down){
	    p+=6;
	    d=direction::DOWN;
	  }
	}
      }
      break;
    case direction::RIGHT:
      cout<<"R";
      if(b[p].right){
	d=direction::UP;
      }else{
	p+=1;
	if(!b[p].down){
	  p+=6;
	  d=direction::DOWN;
	  if(!b[p].left){
	    p-=1;
	    d=direction::LEFT;
	  }
	}
      }
      break;
    case direction::DOWN:
      cout<<"D";
      if(b[p].down){
	d=direction::RIGHT;
      }else{
	p+=6;
	if(!b[p].left){
	  p-=1;
	  d=direction::LEFT;
	  if(!b[p].up){
	    p-=6;
	    d=direction::UP;
	  }
	}
      }
      break;
    case direction::LEFT:
      cout<<"L";
      if(b[p].left){
	d=direction::DOWN;
      }else{
	p-=1;
	if(!b[p].up){
	  p-=6;
	  d=direction::UP;
	  if(!b[p].right){
	    p+=1;
	    d=direction::RIGHT;
	  }
	}
      }
      break;
    }
  }while(p!=1);
  cout<<"\n";
}

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

int main() {
  int n, d;
  cin >> n >> d;
  int A[n][d];
  for(int i = 0; i < n; i++){
    for(int j = 0; j < d; j++){
      cin >> A[i][j];
    }
  }
  int ans = 0;
  for(int i = 0; i < n; i++){
    for(int j = i+1; j < n; j++){
      int tmp = 0;
      for(int k = 0; k < d; k++){
        int b = abs(A[i][k] - A[j][k]);
        tmp += b*b;
      }
      bool judge = false;
      for(int k = 0; k <= tmp; k++){
        if(k*k == tmp) ans++;
      }
    }
  }
  cout << ans << endl;
        
        
        
  
}


Measured memory_bytes: 3632
n,k = map(int,input().split())
itazura = list(range(1,n+1))
for i in range(k):
    di = input()
    Ai = list(map(int,input().split()))
    for one in Ai:
        if one in itazura:
            itazura.remove(one)
print(len(itazura))

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

int main(){
  int d;
  int c[27];
  int s[400][27];
  int t[400];
  static int last[27];//最後の開催日

  cin >> d;
  rep(i, 26)cin >> c[i+1];
  rep(i, d){
    rep(j, 26){
      cin >> s[i+1][j+1];
    }
  }

  for(int i=1;i<=d;i++){
    int mx = -INF;
    int mxi;
    for(int j=1;j<=26;j++){
      int tmp=0;
      tmp += s[i][j];
      for(int k=1;k<=26;k++){
        if(j!=k)tmp-=(i-last[k])*c[k];
      }
      if(tmp>mx){
        mx = tmp;
        mxi = j; 
      }
    }
    t[i]=mxi;
    last[t[i]]=i;
  }

  //
  int target = 0;
  rep(i, 26)last[i+1]=0;
  for(int i=1;i<=d;i++){
    target += s[i][t[i]];
    last[t[i]]=i;
    for(int j=1;j<=26;j++)target-=(i-last[j])*c[j];
  }

  int mx1=-INF;
  int mx1i;
  rep(i, 26){
    int tmp = c[i+1];
    if(tmp>mx1){
      mx1=tmp;
      mx1i=i+1;
    }
  }
  //ここから焼きなまし法
  for(int k=1;k<=d;k++){
    //k日目をmx1iに変更する
    int tmp = 0;
    rep(i, 26)last[i+1]=0;
    for(int i=1;i<=d;i++){
      if(i==k){
        tmp += s[i][mx1i];
        last[mx1i]=i;
        for(int j=1;j<=26;j++)tmp-=(i-last[j])*c[j];
        continue;
      }
      tmp += s[i][t[i]];
      last[t[i]]=i;
      for(int j=1;j<=26;j++)tmp-=(i-last[j])*c[j];
    }
    // cout << target << ":" << tmp << endl;
    if(tmp>target){
      t[k]=mx1i;
    }
  }
  
  rep(i, d)cout << t[i+1] << endl;
  return 0;
}


Measured memory_bytes: 3544
n=int(input())

s=[True]*13
h=[True]*13
c=[True]*13
d=[True]*13

for i in range(n):
  mark,num=list(map(str,input().split()))

  if mark=='S':
    s[int(num)-1]=False
  if mark=='H':
    h[int(num)-1]=False
  if mark=='C':
    c[int(num)-1]=False
  if mark=='D':
    d[int(num)-1]=False

for i in range(0,13):
  if s[i]==True:
    print("S",i+1)
for i in range(0,13):
  if h[i]==True:
    print("H",i+1)
for i in range(0,13):
  if c[i]==True:
    print("C",i+1)
for i in range(0,13):
  if d[i]==True:
    print("D",i+1)

  



Measured memory_bytes: 5616
/**
                 MD.Faysal Hasan
                Comilla Univesity               **/

#include<bits/stdc++.h>
#include<algorithm>
#include<utility>
#include <stdlib.h>
using namespace std;
#define         rep(i,n)       for (int i = 0;i<(int)(n);i++)
#define         rep1(i,n)      for (int i = 1;i<=(int)(n);i++)
#define         sajo(str)      sort(str.begin(),str.end())
#define         rsajo(str)     reverse(str.begin(),str.end())
#define         pi             3.14159265359
#define         neli            printf("\n")
#define         gcd(a,b)       __gcd(a,b)
#define         lcm(a,b)       (a/gcd(a,b))*b
#define         yes            cout<<"Yes"<<"\n"
#define         no             cout<<"No"<<"\n"
#define         pf             printf
#define         sf             scanf
#define         pb             push_back
#define         pbk            pop_back
#define         Faysal         ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int N = 2e5+5;
typedef long long int         lli;
typedef long long             ll;
typedef unsigned long long    ull;
typedef double                db;
typedef long double           ldb;

int pos(int arr[], int n, int x)
{
    for (int i = 0; i < n; i++)
        if (arr[i] == x)
            return i+1;
}

int fact(int n)
{
   if(n==0)
      return(1);

   return(n*fact(n-1));
}

int main()
{
    Faysal;
    ll ans,cnt,mx,sum,n,q,x,y,mn;
    string s,t;

    cin>>x>>y;
    if(x==y)
        yes;
    else
        no;

    return 0;
}


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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define POSSIBLE cout << ((n) ? "POSSIBLE\n" : "IMPOSSIBLE\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)

const int32 MAX_N = 1002;

int64 dp[MAX_N+1][MAX_N+1][2][2][2];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int32 n,m;
    cin >> n >> m;
    REP(i,n+1)REP(j,m+1)REP(a,2)REP(b,2)REP(c,2){
        if(j == 0)continue;
        dp[i][j][a][b][c] = -LLINF;
    }
    REP(i,n){
        int64 x,y,z;
        cin >> x >> y >> z;
        REP(j,m){
            for(int32 mask = 0; mask < (1 << 3); mask++){
                dp[i+1][j+1][mask>>0&1][mask>>1&1][mask>>2&1]
                 = max(dp[i][j+1][mask>>0&1][mask>>1&1][mask>>2&1],
                        dp[i][j][mask>>0&1][mask>>1&1][mask>>2&1]
                        + x * ((mask>>0&1)?1:-1)
                        + y * ((mask>>1&1)?1:-1)
                        + z * ((mask>>2&1)?1:-1));
            }
        }
    }
    // REP(i,n+1){
    //     REP(j,m+1){
    //         cout << dp[i][j][0][0][0] << " ";
    //     }
    //     cout << endl;
    // }
    int64 ans = 0;
    for(int32 mask = 0; mask < (1 << 3); mask++){
        ans = max(ans, dp[n][m][mask>>0&1][mask>>1&1][mask>>2&1]);
    }
    ANS(ans);
    return 0;
}

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

int main() {
  int n;
  cin >> n;
  
  vector<int> a(n);
  for (int i = 0; i < n; i++) cin >> a.at(i);
  
  int biggest = 0, alice = 0, bob = 0;
  for (int j = 0; j < n; j++) {
    for (int i = 0; i < n; i++) if (biggest < a.at(i)) biggest = a.at(i);
    for (int i = 0; i < n; i++) {
      if (a.at(i) == biggest) {
        a.at(i) = 0;
        break;
      }
    }
    if (j%2 == 0) {
      alice += biggest;
    } else bob += biggest;
    biggest = 0;
  }
  
  cout << alice - bob << endl;
}


Measured memory_bytes: 256
#include<cstdio>
using namespace std;
#define N 233333
int a[N],b[N],n;
bool check(int s)
{
	for(int i=1;i<2*n;i++)b[i]=(a[i]>=s);
	for(int i=n;i>1;i--)
	{
		if(b[i]==b[i-1])return b[i];
		if(b[n*2-i]==b[n*2-i+1])return b[n*2-i];
	}
	return b[1];
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<n*2;i++)
	scanf("%d",&a[i]);
	int lb=0,rb=233333,ans=0;
	while(lb<=rb)
	{
		int mid=(lb+rb)>>1;
		if(check(mid))ans=mid,lb=mid+1;
		else rb=mid-1;
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 1792
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 

typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
using namespace std;


int main(int argc, char* argv[])
{
    int n, m;
    scanf("%d%d", &n, &m);

    vector<ll> a((n+1)*(m+1));
    int i,j;
    for(i=0; i<n; i++) {
        for(j=0; j<m; j++) {
            scanf("%lld", &a[i*(m+1)+j]);
        }
    }

    for(j=0; j<m; j++) {
        ll sum=0;
        for(i=0; i<n; i++) {
            sum+=a[i*(m+1)+j];
        }
        a[n*(m+1)+j]=sum;
    }
    for(i=0; i<=n; i++) {
        ll sum=0;
        for(j=0; j<m; j++) {
            sum+=a[i*(m+1)+j];
        }
        a[i*(m+1)+m]=sum;
    }

    for(i=0; i<=n; i++) {
        for(j=0; j<=m; j++) {
            printf("%d", a[i*(m+1)+j]);
            if(j<m) printf(" ");
        }
        printf("\n");
    }

    return 0;
}



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

int main()
{
   string s;
   int i = 0, x = 0, y = 0, a = 0, sub = 0;
   cin >> s;
   for(i = 0; i < s.size(); i++)
   {
       if(s[i] == 'A')
       {
           x++;
       }
       if(x != 0)
       {
           y++;
       }
       if(s[i] == 'Z' && x != 0)
       {
           a++;
           sub = y;
       }
   }
   cout << sub;
    return 0;
}

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

using namespace std;

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

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

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

const int MAX_LIFE = 100;
const int INF = 1e9;

struct Edge{
    int town, cost;
};

struct P{
    int town, cost, life;

    bool operator >(const P& p) const{
        return cost > p.cost;
    }
};

int main() {
    int town_n, life, rtown_n, road_n, start, goal;
    while(cin >> town_n >> life >> rtown_n >> road_n >> start >> goal,
          town_n|life|rtown_n|road_n|start|goal){

        vector<vector<Edge>> E(town_n + 1);
        vb rtowns(town_n + 1, false);
        REP(i, rtown_n){
            int n;
            cin >> n;
            rtowns[n] = true;
        }
        rtowns[start] = true;
        rtowns[goal] = true;

        REP(i, road_n){
            int from, to, cost;
            cin >> from >> to >> cost;
            E[from].push_back({to, cost});
            E[to].push_back({from, cost});
        }

        vvi G(town_n + 1, vi(MAX_LIFE + 1, INF));
        G[start][life] = 0;

        priority_queue<P, vector<P>, greater<P>> que;
        que.push({start, 0, life});

        int res = INF;
        while(!que.empty()){
            P p = que.top(); que.pop();
            if(p.town == goal){
                res = p.cost;
                break;
            }
            if(rtowns[p.town] && p.life < life){
                int next_cost = p.cost + 1;
                int next_life = p.life + 1;
                if (G[p.town][next_life] > next_cost){
                    G[p.town][next_life] = next_cost;
                    que.push({p.town, next_cost, next_life});
                }
            }

            for(Edge e:E[p.town]){
                int next_life = p.life - e.cost;
                if(next_life < 0) continue;
                int next_cost = p.cost + e.cost;
                if (G[e.town][next_life] > next_cost){
                    G[e.town][next_life] = next_cost;
                    que.push({e.town, next_cost, next_life});
                }
            }
        }

        if(res == INF)
            cout << "Help!" << endl;
        else
            cout << res << endl;
    }
}

Measured memory_bytes: 1488
#include <bits/stdc++.h>
#define ll long long
#define Whitebeard ios::sync_with_stdio(0),ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
using namespace std;
vector<int>v(100009,0);
vector<int>v2(100009,0);
int main()
{
    Whitebeard;
    int a,b,c,ac=0,wr=0;
    string s;
    cin>>a>>b;
    if(b==0)
    {
        cout<<"0 0";return 0;
    }
    else
    {
        while(b--)
        {
            cin>>c>>s;
            if(v[c]!=1 && s=="AC")
            {
                v[c]=1;
                ac+=1;wr+=v2[c];
            }
            else if(v[c]!=1 && s=="WA")
            {
                v2[c]+=1;
            }
        }

    }
cout<<ac<<" "<<wr;
    return 0;
}


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

#define endl '\n'

using namespace std;

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

  string a, b;
  cin >> a >> b;
  int count = 0;
  count += a[0] == b[0];
  count += a[1] == b[1];
  count += a[2] == b[2];
  cout << count << endl;

  return 0;
}


Measured memory_bytes: 256
import sys

input = sys.stdin.readline


def func(x):
    count = 0
    while(x % 2 == 0):
        x = int(x / 2)
        count += 1
    return (count)


n = int(input())

a = list(map(int, input().rstrip().split()))


a_even = [x for x in a if x % 2 == 0]

lis = [func(x) for x in a]

# print(lis)

print(sum(lis))


Measured memory_bytes: 4148
#include<iostream>
#include<string>
using namespace std;
int main()
{
	string a;
	while (cin >> a)
	{
		int count = 0;
		for (int i = 0; i < a.size(); i++)
			if (a[i] == 'o') count++;
		cout << 700 + count * 100 << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b)  for(int i=(a),i##formax=(b);i< i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formin=(b);i>=i##formin;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max((x),(y))
#define mins(x,y) x=min((x),(y))
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define all(a) ((a).begin()),((a).end())
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define bit(n) (1LL<<(n))
typedef long long ll;
typedef __int128_t lll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>using P=pair<T,Y>;
template<class T,class Y>ostream& operator<<(ostream&o,P<T,Y>&p){return o<<"("<<p.fi<<","<<p.se<<")";}
template<class T>ostream& operator<<(ostream&o,V<T>&v){for(T&t:v)o<<t<<",";return o<<endl;}
template<class T>void uniq(V<T>&v){sort(all(v));v.erase(unique(all(v)), v.end());}

lll gcd(lll a,lll b,lll&x,lll&y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll modInv(ll a,ll m){lll x,y;gcd(a,m,x,y);return(x%m+m)%m;}
ll modPow(lll a,lll n,ll m){lll p=1;for(;n;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return p;}
//V<ll>F,R;void setF(int n,int mod){F=R=V<ll>(++n);F[0]=1;FOR(i,1,n)F[i]=F[i-1]*i%mod;R[n-1]=modInv(F[n-1],mod);FORR(i,n-1,1)R[i-1]=R[i]*i%mod;}
//ll comb(int a,int b,int m){return a<b||b<0?0:F[a]*R[b]%m*R[a-b]%m;}

const int IINF = 1e9+6;
const ll LINF = 1e18;
const int MOD = 1e9+7; //998244353;
const int N = 1e5;
int n, m;
string s;
V<int> v;
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> m >> s;
  int i=n;
  while((i-=m) > 0){
    for(int j=0; j<m; i++, j++) if(s[i] == '0'){
      v.pb(i);
      goto ok;
    }
    cout << -1 << endl;
    return 0;
    ok:;
  }
  v.pb(0);
  reverse(all(v));
  v.pb(n);
  FOR(i, 1, sz(v)) cout << v[i] - v[i-1] << " ";
  cout << endl;
}

Measured memory_bytes: 1096
// DFSを用いたトポロジカルソート
// 計算量 O(V + E) 
// reference Programming Contest Challenge Book Second Edition
// verify https://onlinejudge.u-aizu.ac.jp/courses/library/5/GRL/1/GRL_4_B

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

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

template<typename T> struct edge {
  int to;
  edge(int to_) : to(to_) {}
};

template<typename T,template <typename ELEM> class C> struct AdListGraph {
  vector<vector<C<T>>> G;
  vector<bool> used;
  vector<bool> is_ancetor;
  int V;//0,...,|V|-1

  AdListGraph (int V_) {
    init(V_);
  }

  void init(int V_) {
    V = V_;

    G.clear();
    G.resize(V);
  }

  // https://faithandbrave.hateblo.jp/entry/20080310/1205149207
  template <typename FROM, class... Args>
  void add_edge(FROM from, Args&&... arg) {
    G[from].emplace_back(arg...);
  }

  bool DFSWithTopologicalSort (int i, vector<int>& sorted) {
    if (is_ancetor[i]) return false;
    if (used[i]) return true;

    used[i] = true;
    is_ancetor[i] = true;

    for(const auto& v : G[i]) {
      if(!DFSWithTopologicalSort(v.to, sorted)) return false;
    }

    is_ancetor[i] = false;
    sorted.emplace_back(i);//dfsの帰りがけの順

    return true;
  }

  template<typename ID_TYPE>
  bool TopologicalSort (vector<ID_TYPE>& sorted) { // 成功ならtrue 失敗(DAG出ない)ならfalseを返す
    used.clear();
    used.resize(V,false);
    is_ancetor.clear();
    is_ancetor.resize(V, false);

    sorted.clear();

    rep (i,V) {
      if(!DFSWithTopologicalSort(i, sorted)) {
        return false;
      }
    }

    reverse(sorted.begin(),sorted.end());

    return true;
  }

};

using ll = long long;

int main() {
  ll V,E;
  cin >> V >> E;
  AdListGraph<ll,edge> G(V);
  rep(i,E) {
    ll s,t;
    cin >> s >> t;
    G.add_edge(s,t);
  }

  vector<int> ans;

  cout << !G.TopologicalSort(ans) << endl;

  return 0;
}



Measured memory_bytes: 3172
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define M 1000000007
#define INF ((1LL<<62LL) - 1)

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n,q; cin >> n >> q;

    int ans = (n-2)*(n-2);

    map<int,int> deep, right;
    deep[n] = n;
    right[n] = n;

    while(q--){
        int type; cin >> type;
        int x; cin >> x;

        if(type == 1){
            // deep wali
            if(right.find(x) != right.end()){
                continue;
            }

            auto it = right.upper_bound(x);
            pair<int,int> p = *it;

            //cout << "deep wali " << p.first << " " << p.second << "\n";

            ans -= (p.second - 2);

            if(deep.find(p.second) != deep.end()){
                deep[p.second] = min(deep[p.second], x);
            } else {
                deep[p.second] = x;
            }
        } else {
            // right wali
            if(deep.find(x) != deep.end()){
                continue;
            }

            auto it = deep.upper_bound(x);
            pair<int,int> p = *it;

            //cout << "right wali " << p.first << " " << p.second << "\n";

            ans -= (p.second - 2);

            if(right.find(p.second) != right.end()){
                right[p.second] = min(right[p.second], x);
            } else {
                right[p.second] = x;
            }
        }
    }

    cout << ans << "\n";



}


Measured memory_bytes: 9892
#include<bits/stdc++.h>
using namespace std;
 
#define fastio ios::sync_with_stdio(); cin.tie(0); cout.tie(0);
#define pb push_back
#define ll long long
#define fi first
#define se second
#define maxn 2001
 
const int mod = 1e9+7 ;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pii> vii;
 
bool dp[maxn][100001];
int pre[maxn];
 
signed main()
{
//	freopen(".inp","r",stdin);
//	freopen(".out","w",stdout);
	fastio;
	int n;	cin >> n;
	int a[n+1], sum = 0;
	for (int i = 1; i <= n; i++)
	{
		cin >> a[i];
		pre[i] = pre[i-1] + a[i];
	}
	dp[0][0] = true;
	for (int i = 1; i <= n; i++)
	{
		for (int j = 0; j <= 100000; j++)
		{
			if (!dp[i][j])
			{
				if (j >= a[i])
				{
					if (j + a[i] <= 100000)
					dp[i][j] = max(dp[i-1][j-a[i]], dp[i-1][j+a[i]]);
					else dp[i][j] = dp[i-1][j-a[i]];
				}
				else
				{
					if (j + a[i] <= 100000)
					dp[i][j] = max(dp[i-1][a[i]-j], dp[i-1][a[i]+j]);
					else dp[i][j] = dp[i-1][j-a[i]];
				}
			}
			if (j + a[i] <= 100000 && !dp[i][j+a[i]])	dp[i][j+a[i]] = dp[i-1][j];
		}
	}
	for (int j = 0; j <= 100000; j++)
	{
		if (dp[n][j])
		{
			cout << (pre[n] + j) / 2;
			return 0;
		}
	}
}


Measured memory_bytes: 198956
/*
title:

url:
*/

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <functional>
#include <queue>
#include <limits>
#include <string>
#include <utility>
#include <cstring>
#include <map>
#include <cmath>
#include <iterator>

using namespace std;

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

typedef pair<int, int> pint;
typedef long long ll;

int N;

void make_f(vector<int> &f)
{
    f[0] = 1;
    for (int i = 1; i < f.size(); i++)
    {
        f[i] = f[i - 1] * i;
        f[i] %= INF;
    }
}

int get_pow(int x, int n)
{
    int res = 1;
    while (n != 0)
    {
        if (n & 1)
            res = res * x % INF;
        x = x * x % INF;
        n = n >> 1;
    }
    return res;
}

signed main()
{
    cin >> N;
    int data[N];
    int has_n[N + 1];
    fill(has_n, has_n + N + 1, -1);
    int l, r;
    l = r = 0;
    rep(i, N + 1)
    {
        cin >> data[i];
        if (has_n[data[i]] >= 0)
        {
            l = has_n[data[i]];
            r = N - i;
        }
        has_n[data[i]] = i;
    }

    vector<int> f(N + 2, 1);
    make_f(f);

    vector<int> pow_f;
    rep(i, f.size())
    {
        pow_f.push_back(get_pow(f[i], INF - 2));
    }

    rep(i, N + 1)
    {
        int tmp_a, tmp_b;
        tmp_a = f[N + 1] * pow_f[i + 1] % INF;
        tmp_a = tmp_a * pow_f[N - i] % INF;
        if (i > l + r)
        {
            tmp_b = 0;
        }
        else
        {
            tmp_b = f[l + r] * pow_f[i] % INF;
            tmp_b = tmp_b * pow_f[l + r - i] % INF;
        }
        if (tmp_a - tmp_b > 0)
        {
            cout << tmp_a - tmp_b << endl;
        }
        else
        {
            cout << tmp_a - tmp_b + INF << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 4468
export class Main {
  static main(input: string): string {
    const [n, k] = input.split("\n")[0].split(" ").map(Number);
    return k <= Math.ceil(n/2) ? "YES" : "NO";
  }
}
console.log(Main.main(require("fs").readFileSync("/dev/stdin", "utf8")));

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


int main()
{
    int n, m;
    string s;
    cin >> n >> m;
    cin >> s;
    
    vector<int> ma;
    int cnt = 0;
    for(int i=1; i<s.length(); ++i){
        ++cnt;
        if(s[i]=='0'){
            ma.push_back(cnt);
            cnt = 0;
        }
    }
    if(ma.size()==0 || m < *max_element(ma.begin(), ma.end())){
        cout << -1 << endl;
        return 0;
    }

    vector<int> ans;
    cnt = 0;
    for(int i=ma.size()-1; i>=0; --i){
        int tmp = cnt + ma[i];
        if( tmp > m ) {
            ans.push_back(cnt);
            cnt = 0;
        }
        cnt += ma[i];
    }
    ans.push_back(cnt);

    for(int i=ans.size()-1; i>=0; --i){
        cout << ans[i] << " ";
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 1592
mo=10**9+7
n=int(input())+1
s=input()+' '

S=[]
p=s[0]
i=0
while i<n-1:
    c=s[i+1]
    if c==p:
        S+=[2]
        i+=2
    else:
        S+=[1]
        i+=1
    if i<n:
        p=s[i]

p=S.pop()
if p==1:
    ans=3
else:
    ans=6
while S:
    c=S.pop()
    if (p,c)==(1,1):
        ans*=2
    elif (p,c)==(1,2):
        ans*=2
    elif (p,c)==(2,2):
        ans*=3
    elif (p,c)==(2,1):
        ans*=1
    ans%=mo
    p=c
print(ans)


Measured memory_bytes: 38256
#include <cmath>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <iomanip>
#include <map>
#include <stack>
#include <queue>

using namespace std;

typedef long long ll;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n,x,s[210];
    int d=1e9+7;
    cin>>n>>x;
    for(int i=0;i<n;i++) cin>>s[i];
    vector<vector<ll>> dp(n+1,vector<ll>(x+1,0));
    
    sort(s,s+n);
    for(int h=0;h<=x;h++){
        dp[0][h]=h;
        for(int i=0;i<n;i++){
            dp[i+1][h]=dp[i][h%s[i]]+i*dp[i][h];
            dp[i+1][h]%=d;
        }
    }
    
    cout<<dp[n][x]<<endl;
}

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

using ll = long long;
vector<ll> mask;

int dfs(int l, int N, int b, vector<vector<int>>& g, vector<int>& str, vector<int>& dp) {
    int& res = dp[b];
    if(res != -1) {
        return res;
    }
    res = 0;
    for(int i=0; i<N; ++i) {
        if((b >> i) & 1) {
            int nb = b & ~(1 << i);
            nb &= ~(int)(mask[l+i] >> l);
            res = max(res, dfs(l, N, nb, g, str, dp) + str[l+i]);
        }
    }
    return res;
}

int main() {
    int N;
    while(cin >> N, N) {
        map<string, int> id;
        vector<vector<int>> g(N, vector<int>(N));
        mask.resize(N);
        vector<int> str(N);
        for(int i=0; i<N; ++i) {
            string A;
            int B, C;
            cin >> A >> B >> C;
            if(id.count(A) == 0) {
                id[A] = id.size() - 1;
            }
            str[id[A]] = B;
            for(int j=0; j<C; ++j) {
                string D;
                cin >> D;
                if(id.count(D) == 0) {
                    id[D] = id.size() - 1;
                }
                g[id[A]][id[D]] = g[id[D]][id[A]] = 1;
            }
        }
        if(N == 1) {
            cout << str[0] << endl;
            continue;
        }
        int N1 = N/2, N2 = N - N1;
        for(int i=0; i<N; ++i) {
            ll m = 0;
            for(int j=0; j<N; ++j) {
                if(g[i][j]) {
                    m |= (1LL << j);
                }
            }
            mask[i] = m;
        }
        vector<int> dp1(1 << N1, -1), dp2(1 << N2, -1);
        int res = 0;
        for(int b=0; b<1<<N1; b+=2) {
            bool ignore = false;
            for(int i=0; i<N1; ++i) {
                if(g[0][i] && (b >> i) & 1) {
                    ignore = true;
                }
            }
            if(ignore) {
                continue;
            }
            int b2 = (1 << N2) - 1;
            for(int i=0; i<N1; ++i) {
                if(b & (1 << i)) {
                    b2 &= ~(int)(mask[i] >> N1);
                }
            }
            b2 &= ~(int)(mask[0] >> N1);
            res = max(res, dfs(0, N1, b, g, str, dp1) + dfs(N1, N2, b2, g, str, dp2) + str[0]);
        }
        cout << res << endl;
    }
}

Measured memory_bytes: 11212
#include<iostream>
using namespace std;
int main(){
    int n,l=0,r=0;
    string s;
    cin>>n>>s;
    for(int i=0;i<n;i++){
        switch (s[i]){
            case '(':r++;break;
            case ')':(r?r--:l++);break;
        }
    }
    cout<<string(l,'(')<<s<<string(r,')')<<endl;
    return 0;
}

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

killed = 0

for i in range(n):
    now_kill = min(a[i], b[i])
    killed += now_kill
    a[i] -= now_kill
    b[i] -= now_kill
    if b[i] == 0:continue
    now_kill = min(a[i+1], b[i])
    killed += now_kill
    a[i+1] -= now_kill
    b[i] -= now_kill

print(killed)

Measured memory_bytes: 19116
N,Q = map(int,input().split())
S = "_"+ input() +"_"
td = [input().split() for _ in range(Q)]

l = 0
r = N+1
for i in range(Q-1,-1,-1): 
    t,d = td[i]
    if t == S[l] and d == "R":
        l -= 1
    elif t == S[l+1] and d == "L":
        l += 1
    if t == S[r] and d == "L":
        r += 1
    elif t == S[r-1] and d == "R":
        r -= 1
print(max(0,r-l-1))


Measured memory_bytes: 39356
// eddy1021
#include <bits/stdc++.h>
using namespace std;
typedef double D;
typedef long double LD;
typedef long long ll;
typedef long long LL;
typedef pair<int,int> PII;
typedef pair<LL,LL> PLL;
typedef pair<LD,LD> Pt;
typedef tuple<int,int,int> tiii;
typedef tuple<LL,LL,LL> tlll;
#define mod9 1000000009ll
#define mod7 1000000007ll
#define INF  1023456789ll
#define INF16 10000000000000000ll
#define FI first
#define SE second
#define X FI
#define Y SE
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define eps 1e-9
#define SZ(x) (int)(x).size()
#define ALL(x) (x).begin(), (x).end()
#ifndef ONLINE_JUDGE
#define debug(...) printf(__VA_ARGS__)
#else 
#define debug(...)
#endif
inline LL getint(){
  LL _x=0,_tmp=1; char _tc=getchar();    
  while( (_tc<'0'||_tc>'9')&&_tc!='-' ) _tc=getchar();
  if( _tc == '-' ) _tc=getchar() , _tmp = -1;
  while(_tc>='0'&&_tc<='9') _x*=10,_x+=(_tc-'0'),_tc=getchar();
  return _x*_tmp;
}
inline LL add( LL _x , LL _y , LL _mod = mod7 ){
  _x += _y;
  return _x >= _mod ? _x - _mod : _x;
}
inline LL sub( LL _x , LL _y , LL _mod = mod7 ){
  _x -= _y;
  return _x < 0 ? _x + _mod : _x;
}
inline LL mul( LL _x , LL _y , LL _mod = mod7 ){
  _x *= _y;
  return _x >= _mod ? _x % _mod : _x;
}
LL mypow( LL _a , LL _x , LL _mod ){
  if( _x == 0 ) return 1LL;
  LL _ret = mypow( mul( _a , _a , _mod ) , _x >> 1 , _mod );
  if( _x & 1 ) _ret = mul( _ret , _a , _mod );
  return _ret;
}
LL mymul( LL _a , LL _x , LL _mod ){
  if( _x == 0 ) return 0LL;
  LL _ret = mymul( add( _a , _a , _mod ) , _x >> 1 , _mod );
  if( _x & 1 ) _ret = add( _ret , _a , _mod );
  return _ret;
}
inline bool equal( D _x ,  D _y ){
  return _x > _y - eps && _x < _y + eps;
}
int __ = 1 , _cs;
/*********default*********/
#define N 101010
void build(){

}
char s[ N ];
int cg , cp , len;
void init(){
  scanf( "%s" , s );
  len = strlen( s );
}
void solve(){
  int win = 0;
  for( int i = 0 ; i < len ; i ++ )
    if( s[ i ] == 'g' ){
      if( cp + 1 <= cg ){
        cp ++; win ++;
      }else{
        cg ++;
      }
    }else{
      if( cp + 1 <= cg ){
        cp ++;
      }else{
        cg ++; win --;
      }
    }
  printf( "%d\n" , win );
}
int main(){
  build();
  //__ = getint();
  while( __ -- ){
    init();
    solve();
  }
}


Measured memory_bytes: 384
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()

from collections import defaultdict, deque, Counter
from sys import exit
import heapq
import math
import copy
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

# O(n)までOK a, b, cどれかを固定（ループ）させる
N, K = getNM()
# Kで割ってi余る数リスト
lista = [0] * K
ans = 0
for i in range(1, N + 1):
    lista[i % K] += 1
# 例えばN = 5, K = 3のとき1と４、2と5は同じものとして扱う
for a in range(K):
    # a（あまりがaであるもののどれか）に対応するb, cは
    # b == k - a(mod K)
    b = (K - a) % K
    c = (K - a) % K
    if (b + c) % K == 0:
        ans += lista[a] * lista[b] * lista[c]
print(ans)

Measured memory_bytes: 40560
using System;

namespace ABC125_a
{
    class Program
    {
        static void Main(string[] args)
        {
            double m = 0;
            double n = 0;
            string[] array = Console.ReadLine().Split(' ');
            int a = int.Parse(array[0]);
            int b = int.Parse(array[1]);
            int t = int.Parse(array[2]);
            if (( a <= 20) && ( b <= 20) && ( t <= 20) && (a >= 1) && (b >= 1) && (t >= 1))
            {
                m = Math.Floor((t + 0.5) / a);
                n = b * m;
                Console.WriteLine(n);
            }


        }
    }
}


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

ll inf=1ll<<60;

int main()
{
	//freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
	ios_base::sync_with_stdio(false); cin.tie(0);
	string a,b,c;
	cin>>a>>b>>c;
	if (a[a.size()-1]==b[0]&&b[b.size()-1]==c[0]){
		cout<<"YES";
	}
	else {
		cout<<"NO";
	}
	return 0;
}

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

bool isdraw(int used)
{
	if(used == (1<<3)-1) return true;
	for(int i=0; i<3; i++)
		if(used == (1<<i)) return true;
		
	return false;
}

int main()
{
	int t;
	while(scanf("%d", &t), t)
	{
		int ar[5], used=0;
		ar[0]=t;
		used|=(1<<(ar[0]-1));
		for(int i=1; i<5; i++)
		{
			scanf("%d", &ar[i]);
			used|=(1<<(ar[i]-1));
		}
		
		for(int i=0; i<5; i++)
		{
			if(isdraw(used)) puts("3");
			else
			{
				if(used&(1<<(ar[i])%3)) puts("1");
				else puts("2");
			}
		}
	}
}

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

int main(void){
    char S[101];
    ll Yes = 1;
    scanf("%s", S);
    rep(i, strlen(S)){
        if(i%2==1){//偶数の時
            if(S[i]=='R') Yes = 0;
        }
        else {//奇数
            if(S[i]=='L') Yes = 0;
        }
    }
    printf(Yes?"Yes":"No");
    return 0;
}

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


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

using namespace std;

#define INF (1 << 30)
#define INFL (1LL << 62)
#define MOD7 1000000007
#define MOD9 1000000009
#define EPS 1e-10

using ll = long long;
using ull = unsigned long long;

ll pow(ll a, ll b) {
    if (b == 0) return 1;
    if (b % 2) return a * pow(a, b - 1);
    return pow(a * a, b / 2);
}
//a^(-1)≡a^(p-2) (mod p) (but p is prime)
ll powMod(ll a, ll b, ll p) {
    if (b == 0) return 1;
    if (b % 2) return (a * powMod(a, b - 1, p)) % p;
    return powMod(a * a % p, b / 2, p);
}

int main() {
    ll n, k, ans = 1, c1 = 1, c2 = 1;
    cin >> n >> k;
    ll cnt = (n < k ? n - 1 : k);
    for (int i = 1; i <= cnt; ++i) {
        (c1 *= (n - i + 1)) %= MOD7;
        (c1 *= powMod(i, MOD7 - 2, MOD7)) %= MOD7;
        (c2 *= (n - i)) %= MOD7;
        (c2 *= powMod(i, MOD7 - 2, MOD7)) %= MOD7;
        (ans += (c1 * c2) % MOD7) %= MOD7;
    }
    cout << ans << endl;

    return 0;
}

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

typedef long double     lf;

using namespace std;

const lf EPS = 1e-9;

struct pt {
  lf x, y;
  pt( ) { }
  pt( lf x, lf y ) : x( x ), y ( y ) { }
};

inline lf x( pt P ) { return P.x; }
inline lf y( pt P ) { return P.y; }

istream& operator >> ( istream& in, pt& p ) {
  lf x,y; in >> x >> y;
  p = pt(x,y); return in;
}

ostream& operator << ( ostream& out, const pt& p ) {
  out << double(p.x) << " " << double(p.y);
  return out;
}

pt operator + ( const pt& A, const pt& B ) {
  return pt( x(A)+x(B), y(A)+y(B) );
}

pt operator - ( const pt& A, const pt& B ) {
  return pt( x(A)-x(B), y(A)-y(B) );
}


pt operator * ( const lf& B, const pt& A ) {
  return pt( x(A)*B, y(A)*B );
}

pt operator * ( const pt& A, const lf& B ) {
  return pt( x(A)*B, y(A)*B  );
}

inline lf dot( pt A, pt B ) {
  return x(A)*x(B) + y(A)*y(B);
}

inline lf norm( pt A ) {
  return x(A)*x(A) + y(A)*y(A);
}

pt projection (pt p, pt A, pt B) {
  lf u = dot( p-A , B-A ) / norm( B-A );
  return A + ( B-A )*u;
}

pt p1,p2,p;
int n;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(10);

  cin >> p1 >> p2 >> n;
  for( int i = 0; i < n; ++i ) {
    cin >> p;
    cout << projection( p, p1, p2 ) << '\n';
  }
}

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

using namespace std;

int main(void) {

    int N;
    cin >> N;

    int a[N];
    for(int i = 0; i < N; i++)
        cin >> a[i];

    sort(a, a + N, greater<int>());

    int Alice = 0, Bob = 0;

    for(int i = 0; i < N; i++){
        if(i % 2 == 0)
            Alice += a[i];
        else
            Bob += a[i];
    }

    cout << Alice - Bob << endl;

    return 0;
}

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

int main() {

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

  int count = 0;

  for (int i = A; i <= B; i++) {
    string s = to_string(i);
    if (s[0] == s[4] && s[1] == s[3]) {
      count++;
    }
  }

  cout << count << endl;

}

Measured memory_bytes: 256
from collections import defaultdict

N,M = map(int,input().split())
edges = [list(map(int,input().split())) for _ in range(M)]
G = defaultdict(list)

is_visited1 = [False] * N

for frm,to in edges:
    G[frm].append(to)
    G[to].append(frm)

def hamilton(node,is_visited,ans):
    #print(is_visited)
    #print(node) 
    is_visited[node-1] =True
    if not False in is_visited:
        ans += 1
        return ans
    for no in G[node]:
        if is_visited[no-1]:
            continue
        ans = hamilton(no,is_visited,ans)
        is_visited[no-1] =False
    #is_visited[node-1] =False        
    return ans
print(hamilton(1,is_visited1,0))


Measured memory_bytes: 3316
N = int(input())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
C = [int(x) for x in input().split()]
res = 0
last_order = -100
for n in A:
  res += B[n-1]
  if n-1 == last_order+1:
    res += C[n-2]
  last_order = n-1
print(res)

Measured memory_bytes: 3064
(N, K) = gets.split.map(&:to_i)

h = []
N.times do
  h << gets.to_i
end

h.sort!

sD = 999_999_999_999

(N - K + 1).times do |i|
  dr = h[i..i+K-1]
  d = dr.last - dr.first
  if d < sD
    sD = d
  end
end

puts sD

Measured memory_bytes: 4016