akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
using P = pair<int,int>;

/* 大文字を小文字に変換 */
char tolower(char c) {return (c + 0x20);}
/* 小文字を大文字に変換 */
char toupr(char c) {return (c - 0x20);}

// if('A'<=s[i] && s[i]<='Z') s[i] += 'a'-'A';

/*
string s = "abcdefg"
s.substr(4) "efg"
s.substr(0,3) "abc"
s.substr(2,4) "cdef"

// イテレータ要素のインデックス
distance(A.begin(), itr);
*/

int main()
{
    string s; cin >> s;
    int q; cin >> q;

    vector<tuple<int, char, int> > fc;

    int rev = 0;

    rep(_,q){
        int t; cin >> t;
        if(t == 1) rev++;
        else{
            int fi; char ci;
            cin >> fi >> ci;
            fc.push_back(make_tuple(fi, ci, rev));
        }
    }

    if(rev%2 == 1) reverse(s.begin(), s.end());

    string fronts = "";
    for(auto f: fc){
        int fi; char ci; int revi;
        tie(fi, ci, revi) = f;
        if((rev-revi)%2 == 1){
            if(fi == 1) fi = 2;
            else fi = 1;
        }
        if(fi == 1) fronts += ci;
        else s += ci;

        //cout << fi << " " << ci << " " << revi << endl;
    }
    reverse(fronts.begin(), fronts.end());
    // rep(i,fronts.size()) cout << fronts[i] << endl;

    rep(i,s.size()){
        fronts += s[i];
    }
    cout << fronts << endl;
}

Measured memory_bytes: 6612
#include<bits/stdc++.h>  
int a[10001];
using namespace std;
int main()
{
	int b,c,d;
	cin>>a[1]>>a[2]>>a[3];
	sort(a+1,a+3+1);
    if(a[2]-a[1]==a[3]-a[2])	
      cout<<"YES"<<endl;
	else
	  cout<<"NO"<<endl;  		 
   return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(int argc, char *argv[]){
  int n,l,s,r;
  scanf("%d %d", &n,&l);
  s = n*(l-1) + n*(n+1)/2;
  if(l>=1) s -= l;
  if(l<1-n) s -= l+n-1;
  printf("%d",s);
  return 0;
}

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

using namespace std;

using ll =  long long;
using Pll = pair<ll, ll>;
using Pii = pair<int, int>;

constexpr ll MOD = 1000000007;
constexpr long double EPS = 1e-10;
constexpr int dyx[4][2] = {
    { 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};
constexpr int V = 100000;
constexpr int INF = 1<<30;

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int N, W;
    cin >> N >> W;
    vector<ll> v(N), w(N);
    for(int i=0;i<N;++i) {
        cin >> w[i] >> v[i];
    }

    vector<vector<ll>> dp(N+1, vector<ll>(V+1, INF));
    dp[0][0] = 0;
    for(int i=1;i<=N;++i) {
        for(int j=0;j<=V;++j) {
            dp[i][j] = dp[i-1][j];
            if(j >= v[i-1]) dp[i][j] = min(dp[i][j], dp[i-1][j-v[i-1]] + w[i-1]);
        }
    }

    ll ans = 0;
    for(int j=V;j>=0;--j) {
        if(dp[N][j] <= W) {
            ans = j;
            break;
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 80256
mod = 10**9+7
n,a,b = [int(i) for i in input().split()]
k = min(n,2*(10**5))
import sys
sys.setrecursionlimit(100000000)
def pow_k(a,n,mod):
    if n == 0:
        return 1
    if n % 2 ==0:
        return pow_k(a*a % mod,n//2,mod)
    else:
        return a * pow_k(a,n-1,mod) % mod
def modinv(a, mod):
    return pow(a, mod-2, mod)
def combination_list(n, mod):
    lst = [1]
    for i in range(1, k+1):
        lst.append(lst[-1] * (n+1-i) % mod * modinv(i, mod) % mod)
    return lst
ans = pow_k(2,n,mod)
cmb = combination_list(n,mod)
ans -=1
ans -= cmb[a]
if ans < 0:
    ans += mod
ans -= cmb[b]
if ans <0:
    ans += mod
print(ans)

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

int main()
{
    string w, t;
    int cnt = 0;
    cin >> w;
    cin >> t;
    while(t != "END_OF_TEXT")
    {
        transform(t.begin(), t.end(), t.begin(), ::tolower);
        if (t == w) cnt++;
        cin >> t;
    }
    cout << cnt << endl;
    return 0;
}



Measured memory_bytes: 3156
import itertools
n,k=map(int,input().split())
l=list(map(int,input().split()))
if k>42:
    l=[n]*n
    print(*l)
else:
    for _ in range(k):
        countl=[0]*(n+1)
        for i in range(n):
            countl[max(1,i+1-l[i])]+=1
            if i+2+l[i]<=n:
                countl[i+2+l[i]]-=1
            
        l=list(itertools.accumulate(countl))
        l.remove(l[0])
    print(*l)

Measured memory_bytes: 180024
#include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <tuple>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
//cin.sync_with_stdio(false);
//streambuf
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
int mincost[5001];
vector<pii> tx(5001);
vector<vector<int>> way(5001);
int main() {
	int h, w;
	while (cin >> h >> w,h) {
		int m = h*h+w*w;
		int m1, h1;
		for (m1 = m;; m1++) {
			for (h1 = (m1 == m ? h + 1 : 1); h1*h1*2<m1; h1++) {
				if ((int)sqrt(m1 - h1*h1)*(int)sqrt(m1 - h1*h1)==m1-h1*h1)goto a;
			}
		}
	a:
		cout << h1 <<" "<< (int)sqrt(m1 - h1*h1) << endl;
	}
}

Measured memory_bytes: 3192
#include<stdio.h>
  int main(void)
{
  int x,y;

  while(1)
    {
        scanf("%d %d",&x,&y);
        if(x==0 && y==0)break;
        if(x<y)printf("%d %d\n",x,y);
        if(x>y)printf("%d %d\n",y,x);
        if(x==y)printf("%d %d\n",x,y);
    }
    return 0;
}

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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;

#define INF INT_MAX/2

#define MAX_N 1000

struct state{
	int lw,lh,rw,rh;
};

int w,h;
string bl[55],br[55];
int slw,slh,srw,srh;
int glw,glh,grw,grh;

bool vis[55][55][55][55];

int dl[4][2]={{0,1},{1,0},{-1,0},{0,-1}};
int dr[4][2]={{0,1},{-1,0},{1,0},{0,-1}};

int main(){
	cin.sync_with_stdio(false);
	while(1){
		cin>>w>>h;
		if(w==0)break;
		rep(i,h)cin>>bl[i]>>br[i];
		rep(i,h)rep(j,w){
			if(bl[i][j]=='L'){
				slw=j; slh=i;
			}
			if(br[i][j]=='R'){
				srw=j; srh=i;
			}
			if(bl[i][j]=='%'){
				glw=j; glh=i;
			}
			if(br[i][j]=='%'){
				grw=j; grh=i;
			}
		}
		bool ok=false;
		queue<state> que;
		que.push((state){slw,slh,srw,srh});
		memset(vis,0,sizeof(vis));
		while(!que.empty()){
			state ns=que.front(); que.pop();
			int w1=ns.lw,h1=ns.lh,w2=ns.rw,h2=ns.rh;
			if(vis[w1][h1][w2][h2])continue;
			vis[w1][h1][w2][h2]=true;
			if(w1==glw&&h1==glh&&w2==grw&&h2==grh){
				ok=true;
				break;
			}
			if((w1==glw&&h1==glh)||(w2==grw&&h2==grh))continue;
			rep(di,4){
				int nw1=w1+dl[di][0],nh1=h1+dl[di][1];
				if(nw1<0||nw1>=w||nh1<0||nh1>=h||bl[nh1][nw1]=='#'){
					nw1=w1;nh1=h1;
				}
				int nw2=w2+dr[di][0],nh2=h2+dr[di][1];
				if(nw2<0||nw2>=w||nh2<0||nh2>=h||br[nh2][nw2]=='#'){
					nw2=w2; nh2=h2;
				}
				que.push((state){nw1,nh1,nw2,nh2});
			}
		}
		if(ok)cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
	}
	return 0;
}

Measured memory_bytes: 15476
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int n;
const int N=1e5+7;
int a[N];
int main()
{	
 memset(a,0,sizeof(a));
 cin>>n;
 for (int i=2;i<=n;i++)
 {
 	int x=i;
 	for (int j=2;j<=x;j++)
 	{
 	while(x%j==0)
 		{
 		a[j]++;
		 x/=j;
		 }
	 }
	 a[x]++;
	 }	
    ll  ans=1;
	for (int i=2;i<=n;i++)
	ans=((ll)(ans*(a[i]+1)))%1000000007;
	cout<<ans;
	return  0;
}

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

int main(){
    ll N;
    cin >> N;
    ll a[N];
    ll x[N];
    ll sum = 0;
    rep(i, N){
        cin >> a[i];
        sum += a[i];
        x[i] = sum;
    }
    ll x_ymin = LONG_LONG_MAX;

    rep(i,N-1){
        ll x_y = llabs(x[i] - (sum - x[i]));
        if(x_ymin >= x_y){
            x_ymin = x_y;
        }
    }

    cout << x_ymin << endl;

    return 0;
}

Measured memory_bytes: 3328
# https://atcoder.jp/contests/code-festival-2017-quala/tasks/code_festival_2017_quala_c
from collections import defaultdict

H,W = map(int,input().split())
C = defaultdict(int)
for _ in range(H):
    row = list(input())
    for i in range(W):
        C[row[i]] += 1
if H%2==0 and W%2==0:
    flag = 0
    for a in C:
        if C[a]%4!=0:
            flag = 1
            break
    if flag==0:
        print("Yes")
    else:
        print("No")
elif (H%2==0 and W%2==1) or (H%2==1 and W%2==0):
    n = (H//2)*(W//2)
    for a in C:
        if C[a]>=4:
            n -= C[a]//4
            C[a] = C[a]%4
    if n>0:
        print("No")
    else:
        flag = 0
        for a in C:
            if C[a]%2==1:
                flag=1
                break
        if flag==0:
            print("Yes")
        else:
            print("No")
else:
    n = (H//2)*(W//2)
    for a in C:
        if C[a]>=4:
            n -= C[a]//4
            C[a] = C[a]%4
    if n>0:
        print("No")
    else:
        cnt = 0
        for a in C:
            cnt += C[a]%2
        if cnt==1:
            print("Yes")
        else:
            print("No")


# 1つの行において列数が偶数の場合、例えば左端にaを置いた場合は、
# その列がpalindromeになる関係上必然的に右端にもaを置くことになる。
# さらに、列方向に見た場合は、今置いた2つのaに対して、一番下の行で
# それぞれを置く必要がある。したがって、1つのaを置くと、芋づる式に
# 合計４つのaを置くことになる。
# 行・列のどちらかが奇数の場合は、その真ん中のところにおいては
# 2個でよかったり、3個でよかったり、1個で良かったりするので、場合分けする。


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

#define REPU(i, a, b) for (int i = (a); i < (b); ++i)
#define REPD(i, a, b) for (int i = (a); i > (b); --i)
#define MEM(a, x) memset(a, x, sizeof(a))
#define ALL(a) a.begin(), a.end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())
#define DEBUG(x) cerr << #x << " = " << x << endl

typedef long long ll;
const int MOD = 1000000007;

template<class T, class U> inline T tmin(T a, U b) { return (a < b) ? a : b; }
template<class T, class U> inline T tmax(T a, U b) { return (a > b) ? a : b; }
template<class T, class U> inline void amax(T &a, U b) { if (b > a) a = b; }
template<class T, class U> inline void amin(T &a, U b) { if (b < a) a = b; }
template<class T> inline T tabs(T a) { return (a > 0) ? a : -a; }
template<class T> T gcd(T a, T b) { while (b != 0) { T c = a; a = b; b = c % b; } return a; }


int main(int argc, char *argv[]) {
	ios_base::sync_with_stdio(false);
	
	int n;

	cin >> n;
	vector<int> a(n), b(n);
	REPU(i, 0, n) {
		cin >> a[i];
		b[i] = a[i];
	}
	sort(ALL(b));
	int ans = 0;
	REPU(i, 0, n) {
		a[i] = lower_bound(ALL(b), a[i]) - b.begin();
		if (a[i] % 2 != i % 2) ans++;
	}
	cout << ans / 2<< endl;
	
	return 0;
}

Measured memory_bytes: 1024
using System;
using System.Collections;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Collections.Generic;
using System.Threading.Tasks;

class Program
{
	//Main
	static void Main(string[] args)
	{
		//読み込む
		string[] line = Console.ReadLine().Split(' ');
		ulong A = ulong.Parse(line[0]);
		ulong B = ulong.Parse(line[1]);
		ulong N = ulong.Parse(line[2]);

		//n-Ai = (Aj-m)/B が最大になれば良い
		//jの最大値について
		ulong maxJ = 0;
		if(N<B){
				maxJ = N;
		}else{
				maxJ = B-1;
		}

		//mの最小値は0

		ulong ans = (A*maxJ)/B;


		Console.WriteLine(ans);

	}
}



Measured memory_bytes: 17820
var
	i:Longint;
	s:String;
begin
	readln(s);
	for i:=2 to length(s)do begin
		if s[i]=s[i-1]then begin
			writeln(i-1,' ',i);
			exit;
		end;
		if(i>2)and(s[i]=s[i-2])then begin
			writeln(i-2,' ',i);
			exit;
		end;
	end;
	writeln('-1 -1');
end.


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#define MAX 101
void isEmpty(void);
void isFull(void);
void push(int);
int pop(void);
int top=0;
int op[MAX];
int main(){
  int x,n,m,flag=0;
  char s[100];

  while( scanf("%s", s) != EOF ){
    if ( s[0] == '+' ){
      n=pop();
      m=pop();
      top++;
      x=m+n;
      op[top]=x;
    } else if ( s[0] == '-' ){
      n=pop();
      m=pop();
      x=m-n;
      top++;
      op[top]=x;
    } else if ( s[0] == '*' ){
      n=pop();
      m=pop();
      top++;
      op[top]=m*n;
    } else {
      x = atoi(s);
      push(x);
    }
  }

  printf("%d\n",op[top]);

  return 0;
}

void push(int x){
  top++;
  isFull();
  op[top]=x;
}

int pop(){
  top--;
  isEmpty();
  return op[top+1];
}

void isFull(){
  if(top>=MAX){
    printf("Stack is full\n");
    exit(1);
  }
}

void isEmpty(){
  if(top<0){
    printf("Stack is empty\n");
    exit(1);
  }
}



Measured memory_bytes: 2108
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repk(i, k, n) for (int i = k; i < n; i++)
#define MOD 1000000007
#define INF 1e9
#define PIE 3.14159265358979323

template <class T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
T GCD(T a, T b) {
    if (b == 0)
        return a;
    else
        return GCD(b, a % b);
}
template <class T>
inline T LCM(T a, T b) {
    return (a * b) / GCD(a, b);
}

using namespace std;
//#inculude <bits/stdc++.h>
#define int long long

signed main() {
    int a, b, x;
    cin >> a >> b >> x;
    if (a == 0) {
        cout << b / x + 1 << endl;
        return 0;
    }
    cout << b / x - (a - 1) / x << endl;
}

Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
#include<iomanip>
#include<cmath>
#include<vector>
using namespace std;

const int MAX_N = 101;
const double PI = 3.14159265358979323846264338327950288;

struct P {
    double x, y;
    int idx;
    P() {}
    P(double x, double y) : x(x), y(y) {
    }
    P operator+ (P p) {
        return P(x + p.x, y + p.y);
    }
    P operator- (P p) {
        return P(x - p.x, y - p.y);
    }
    P operator* (double d) {
        return P(x * d, y * d);
    }
    double dot(P p) {
        return x * p.x + y * p.y;
    }
    double det(P p) {
        return x * p.y - y * p.x;
    }
};

bool cmp_x(const P& p, const P& q) {
    if (p.x != q.x) return p.x < q.x;
    return p.y < q.y;
}

vector<P> convex_hull(vector<P> ps, int n) {
    sort(ps.begin(), ps.end(), cmp_x);
    int k = 0;
    vector<P> qs(n * 2);
    // 下側
    for (int i = 0; i < n; i++) {
        while (k > 1 && (qs[k - 1] - qs[k - 2]).det(ps[i] - qs[k - 1]) <= 0) k--;
        qs[k++] = ps[i];
    }
    // 上側
    for (int i = n - 2, t = k; i >= 0; i--) {
        while (k > t && (qs[k - 1] - qs[k - 2]).det(ps[i] - qs[k - 1]) <= 0) k--;
        qs[k++] = ps[i];
    }
    qs.resize(k - 1);
    return qs;
}

int main() {
    int N;
    double x, y;
    cin >> N;
    vector<P> ps(N);
    for (int i = 0; i < N; i++) {
        cin >> x >> y;
        ps[i].x = x, ps[i].y = y, ps[i].idx = i;
    }
    if (N == 2) {
        // N = 2の時は凸包ができないため
        cout << fixed << setprecision(7);
        cout << 0.5 << endl;
        cout << 0.5 << endl;
        return 0;
    }
    vector<P> qs = convex_hull(ps, N);
    qs.push_back(qs[0]);
    qs.push_back(qs[1]);
    vector<double> ans(N, 0.0);
    for (int i = 0; i < qs.size() - 2; i++) {
        P pr = qs[i] - qs[i + 1], pq = qs[i + 2] - qs[i + 1];  // i+1番目の座標を基準とした座標を作成
        double len_pr = pr.x * pr.x + pr.y * pr.y, len_pq = pq.x * pq.x + pq.y * pq.y;
        ans[qs[i + 1].idx] = (PI - acos(pr.dot(pq) / sqrt(len_pr * len_pq))) / (2 * PI);
    }
    cout << fixed << setprecision(7);
    for (int i = 0; i < N; i++) {
        cout << ans[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 256
//----->|try=0; while(!success) try++;|<------
//----->|Belief Yourself,Respect Yourself|<----
//----->|Be Proud Of Yourself,You're Doing Your best|<-----
#include<bits/stdc++.h>
using namespace std;
#define uniq(x)  x.erase(unique(x.begin(),x.end()), x.end()) //Unique value find from vector
#define upper(arr,n,fixed) upper_bound(arr,arr+n,fixed)-arr  //Upper value search;
#define lower(arr,n,fixed) upper_bound(arr,arr+n,fixed)-arr  //Lower value search;
#define max3(a,b,c) max(max(a,b),c)//maximum value find three value;
#define min3(a,b,c) min(min(a,b),c)//minimum value find three value;
#define rep(i,intial,n) for(int i=intial; i<(n) ; i++)
#define REP(i,intial,n) for(int i=intial; i<=(n) ; i++)
#define PI acos(-1.0)//PI Calculation
#define LL long long
#define AND(a,b) ((a) & (b))
#define OR(a,b) ((a)|(b))
#define XOR(a,b) ((a) ^ (b))
#define MP make_pair
#define sqr(x) ((x)*(x))
#define sqrt(x) sqrt(1.0*(x))
#define INF_MAX 2147483647
#define INF_MIN -2147483647
#define MX 1000005
#define MOD 1000000007
template<typename T> T POW(T b,T p)          //Pow calculation
{
    T r=1;
    while(p)
    {
        if(p&1)r=(r*b);
        b=(b*b);
        p>>=1;
    }
    return r;
}

template<typename T> T BigMod(T b,T p,T m) //BigMod Calculation
{
    T r=1;
    while(p)
    {
        if(p&1)r=(r*b)%m;
        b=(b*b)%m;
        p>>=1;
    }
    return r;
}

//||--------------------------->||Main_Code_Start_From_Here||<---------------------------------||
int main()
{
    //freopen("a.in", "r", stdin);
    //freopen("a.out", "w", stdout);
    string s;
    while(cin>>s)
    {
        vector<string>v;
        string ss="";
        rep(i,0,s.size())
        {
            if(s[i]==',')
            {
                v.push_back(ss);
                ss="";
            }
            else
            {
                ss+=s[i];
            }
        }
        if(ss.size()!=0) v.push_back(ss);
        rep(i,0,v.size()-1) cout<<v[i]<<" ";
        cout<<v[v.size()-1]<<endl;
        v.clear();
    }


}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for (int i = a; i <b; i++)
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef pair<int,int> pi;
#define trace(x) cout<<#x<<"="<<x<<"\n";
#define print(x) cout<<#x<<" is "; for(int i=0;i<x.size();i++){cout<<x[i]<<" ";}cout<<"\n"
#define llp 1000000007
#define mod 1000000007


ll power(ll x, ll y) 
{
	ll temp;
	if( y == 0)
		return 1;
	temp = power(x, y/2);
	if (y%2 == 0)
		return (temp*temp)%mod;
	else
		return (((x*temp)%mod)*temp)%mod; 
}

int main()
{   ios::sync_with_stdio(false);
    //freopen("a.in", "r", stdin);
    //freopen("b.in", "r", stdin);
    //freopen("c.in", "r", stdin);
    //freopen("d.in", "int r", stdin);
    int n,a,b;
    cin>>n>>a>>b;
    if(a<b)swap(a,b);
    int bb=0;
    if((a+b)>n){
    	bb=(a+b)-n;
    }
    int aa=b;
    cout<<aa<<" "<<bb<<"\n";
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;

namespace paizaTest
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            var count = int.Parse(Console.ReadLine());
            var oneLine = Console.ReadLine().Split(' ').Select(int.Parse).ToList();

            BubbleSort(count, oneLine);
        }

        public static void BubbleSort(int count, List<int> A)
        {
            var flag = true;
            var sortCount = 0;
            while (flag)
            {
                flag = false;
                for (int i = A.Count - 1; i > 0; i--)
                {
                    if (A[i] < A[i - 1])
                    {
                        var tmp = A[i];
                        A[i] = A[i - 1];
                        A[i - 1] = tmp;
                        flag = true;
                        sortCount += 1;
                    }
                }
            }

            Console.WriteLine(string.Join(" ", A.Select(x => x.ToString()).ToArray()));
            Console.WriteLine(sortCount.ToString());
        }
    }
}

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

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

    if(M == 0)
    {
        cout << 0 << ' ' << 0 << endl;
        return 0;
    }

    vector<ll> p(M);
    vector<string> S(M);

    for(ll i = 0; i < M; i++)
    {
        cin >> p.at(i) >> S.at(i);
    }
    
    vector<bool> ACorWA(N+1,false);
    vector<ll> WAcnt(N+1,0);
    ll ACcnt = 0;
    ll WAsum = 0;

    for(ll i = 0; i < M; i++)
    {
       if(S.at(i) == "WA")
       {
           if(ACorWA.at(p.at(i)) == false)
           {
               WAcnt.at(p.at(i))++;
           }
       }
       else
       {
           if(ACorWA.at(p.at(i)) == false)
           {
               ACcnt++;
               WAsum += WAcnt.at(p.at(i));
               ACorWA.at(p.at(i)) = true;
           }
       }
       
            
        
    }

    cout << ACcnt << ' ' << WAsum << endl;
    return 0;
}

Measured memory_bytes: 7296
import sys
from collections import Counter

# sys.stdin = open("c1.in")


def is_not_zero(x):
    if x != 0:
        return True
    else:
        return False


n = int(input())
a = list(map(int, input().split()))
c = Counter()

for x in a:
    for l in range(0, 3600, 400):
        if x < l:
            c[l] += 1

g = []
for l in range(400, 3600, 400):
    g.append(c[l] - c[l - 400])
r = n - sum(g)

# print('g:', g, '\nr:', r)

res = [0, 0]
# non_zero = list(filter(lambda x: x != 0, g))
non_zero = list(filter(is_not_zero, g))
if len(non_zero) == 0:
    res[0] = 1
    res[1] = r
if len(non_zero) > 0:
    res[0] = len(non_zero)
    res[1] = len(non_zero) + r
print(res[0], res[1])


Measured memory_bytes: 3316
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"

using namespace std;

const long long int MOD = 1000000007;


long long int N, M, K, H, W, L, R;

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

	cin >> N >> M >> K;
	cin >> L;
	if (abs(N - M) <= L && abs(M - K) <= L) {
		cout << "Yes\n";
		return 0;
	}
	if (abs(N - K) <= L) {
		cout << "Yes\n";
		return 0;
	}
	cout << "No\n";
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn=200050;
typedef long long ll;
string s;
int cnt[26][maxn];
int main() {
	cin>>s;
	for(int i=0;i<s.length();i++) {
		for(int j=0;j<26;j++)
			cnt[j][i+1]=cnt[j][i];
		cnt[s[i]-'a'][i+1]++;
	}
	ll sum=1;
	for(int i=0;i<s.length();i++)
		sum+=(i+1)-cnt[s[i]-'a'][i+1];
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 20868
#include <cstdio>
#include <algorithm>

using namespace std;

int H, N, A[1005], B[1005];
int dp[10005];

int main() {
  scanf("%d %d", &H, &N);
  for (int i = 0; i < N; i++) scanf("%d %d", &A[i], &B[i]);
  for (int h = 1; h <= H; h++) {
    dp[h] = 1000000000;
    for (int i = 0; i < N; i++) {
      if (h - A[i] <= 0) dp[h] = min(dp[h], B[i]);
      else dp[h] = min(dp[h], dp[h - A[i]] + B[i]);
    }
  }
  printf("%d\n", dp[H]);
}


Measured memory_bytes: 256
#pragma comment(linker, "/STACK:102400000,102400000")
#include <bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define SZ(x) (int)(x.size())
#define rep(i,a,b) for(int i=a;i<b;i++)
#define per(i,a,b) for(int i=b-1;i>=a;i--)
#define inf 1000000007
#define mod 1000000007
#define x first
#define y second
#define pi acos(-1.0)
#define DBG(x) cerr<<(#x)<<"="<<x<<"\n";
//#define dprintf(...) 
#define hash _hash
#define next _next
//#define dprintf(...) fprintf(outFile,__VA_ARGS__)
 
#define FOREACH(it,x) for(__typeof(x.begin()) it=x.begin();it!=x.end();it++)
#define ull unsigned long long
#define ll long long
#define N 200010
 
template <class T,class U>inline void Max(T &a,U b){if(a<b)a=b;}
template <class T,class U>inline void Min(T &a,U b){if(a>b)a=b;}
 
//FILE* outFile;
inline void add(int &a,int b){a+=b;while(a>=mod)a-=mod;}


int pow(int a,int b){
    int ans=1;
    while(b){
        if(b&1)ans=ans*(ll)a%mod;
        a=(ll)a*a%mod;b>>=1;
    }
    return ans;
}


char s[N];
int main(){
	int i,j,k,ca=0,n=0,m;
	int a,b;
	scanf("%d%d%d%s",&n,&a,&b,s);
	int x=0,y=0;
	rep(i,0,n){
		if(s[i]=='c')puts("No");
		else if(s[i]=='a'){
			if(x+y<a+b){puts("Yes");x++;}
			else puts("No");
		}
		else{
			if(x+y<a+b&&y<b){puts("Yes");y++;}
			else puts("No");
		}
	}
    return 0;
}




Measured memory_bytes: 768
#include<cstdio>
#include<cstdlib>
#include<ctime>
int last[500];
long long s[500][30];
long long c[30];
int tt[500];
int out[500];
int vis[30];

long long getD(int d){
    for(int i = 1; i <= 26; i++) last[i] = 0;
    long long cur = 0;
    for(int i = 1; i <= d; i++){
        int t = tt[i];
        cur += s[i][t];
        last[t] = i;
        for(int j = 1; j <= 26; j++) cur -= c[j]*(i-last[j]);
    }
    return  cur;
}

int main(){
    srand(time(NULL));
    int d;
    scanf("%d",&d);
    for(int i = 1; i <= 26; i++) scanf("%lld",&c[i]);
    for(int i = 1; i <= d; i++){
        for(int j = 1; j <= 26; j++) scanf("%lld",&s[i][j]);
    }
    for(int i = 1; i <= d; i++){
        int find = 1;
        for(int j = 2; j <= 26; j++) if(s[i][j]>s[i][find]) find = j;
        tt[i] = find;
    }
    long long ans = getD(d);
    for(int i = 0; i < 5000; i++){
        int a = rand()%365+1;
        int keep = tt[a];
        for(int j = 1; j <= 26; j++) vis[j] = 0;
        for(int j = 1; j <= 10; j++){
            int u = rand()%26+1;
            tt[a] = u;
            long long res = getD(d);
            if(res>ans){
                keep = u;
                ans = res;
            }
        }
        tt[a] = keep;
    }
    for(int i = 1; i <= d; i++) printf("%d\n",tt[i]);
    
    return 0;
}


Measured memory_bytes: 1824
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a[] = new int[5];
		for(int i = 0; i < 5; ++i)
			a[i] = sc.nextInt();
		int k = sc.nextInt();
		sc.close();
		String ans[] = {":(", "Yay!"};
		int an = 1;
		if(a[4] - a[0] > k)an = 0;
		System.out.println(ans[an]);
	}

}


Measured memory_bytes: 20820
#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 int long long
typedef long double ld;
typedef unsigned long long ull;
#define X first
#define Y second
#define mp make_pair
template<class T> using indexed_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<class T, class X> using indexed_map = tree<T, X, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
const long long M = 1e9+7;
const double PI = acos(-1.0);
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

long long modpow(long long n, long long k, long long MOD);

/**************** code starts here ****************/

void poppingfever() {
	int n, k; cin >> n >> k;
	if (n == 1) {
		if (k == 0) {
			cout << "0 0 1 1";
		} else {
			cout << -1;
		}
		exit(0);
	}
	if (k >= (1 << n)) cout << -1;
	else if (k == 0) {
		for (int i = 0; i < (1 << n); i++) {
			cout << i << ' ' << i << ' ';
		}
	} else {
		for (int i = (1 << n) - 1; i >= 0; i--) {
			if (i == k) {
				continue;
			}
			cout << i << ' ';
		}
		cout << k << ' ';
		for (int i = 0; i < (1 << n); i++) {
			if (i == k) {
				continue;
			}
			cout << i << ' ';
		}
		cout << k << ' ';
	}
}

/**************************************************/

signed main() {
	#ifdef fastfurioustransform
	freopen("inp.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
	#endif

	ios::sync_with_stdio(0); cin.tie(0);
	//cout << fixed << setprecision(12);

	poppingfever();

	return 0;
}

long long modpow(long long n, long long k, long long MOD) {
	long long ans = 1; n %= MOD;
	while (k > 0) {
		if (k & 1) ans = (ans*n) % MOD;
		k >>= 1; n = (n*n) % MOD;
	}
	return ans; 
}

Measured memory_bytes: 1792
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <queue>
#include <set>
#include <map>
using namespace std;
 
int N;
int color[100005];
vector<pair<int, int>> G[100005];
void hukasa(int i){
    for (int j=0;j<G[i].size();j++){
        if(color[G[i][j].first]==0){
            color[G[i][j].first] = color[i]+G[i][j].second;
            hukasa(G[i][j].first);
        }
    }
}
 
int main() {
    cin >> N;
    for(int i=0;i<N-1;i++){
        int s,t,w;
        cin >> s >> t >> w;
        G[s-1].push_back(pair<int, int> (t-1,w));
        G[t-1].push_back(pair<int, int> (s-1,w));
    }
    for(int i=0;i<N;i++){
        if(color[i] == 0){
            color[i] = 1;
            hukasa(i);
        }
    }
    
    for(int i=0;i<N;i++){
        if(color[i]%2==0){
            cout << 1<< endl;
        } else {
            cout << 0 << endl;
        }
        
    }
    
}


Measured memory_bytes: 8320
#include <iostream>                                                                    
using namespace std;                                                                   
int main(){                                                                              string s,t;
  cin >> s >> t;
  int cnt = 0;
  for(int i=0;i<s.size();i++){
    if(s[i] != t[i]) cnt++;
  }
  cout << cnt << endl;
} 

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


struct Lowmath {
    ll Sline;
    vector<ll> S;
    
    Lowmath(ll a){
        Sline = a;
        S=vector<ll>(a+1,0);
    }
    void addset(ll a,ll b){
        a+=1;
            do{
                S[a]+=b;
                
            }while((a+=a&(-a))<=Sline);
    }
        
    ll sumset0(ll i){
        ll sum=0;
        do{
        sum+=S[i];
        }while(i-=i&(-i));
        return sum;
    }
    
    ll sumset(ll l,ll r){
        return sumset0(r) - sumset0(l);
        
    }
    
    
};

string BN(ll a){
    string S="";
    S.push_back((a&1) + '0');
    while (a >>=1) {
        S.push_back((a&1) + '0');
    }
    reverse(S.begin(), S.end());
    return S;
}

int main() {
    ll N,Q;
    cin >> N >> Q;
    Lowmath A(N);
    for(ll i=0;i<A.Sline;i++){
        ll s1;
        cin >> s1;
        A.addset(i, s1);
    }
    
    while(Q){
        ll s1,s2,s3;
        cin >> s1 >> s2 >> s3;
        if(s1==0)A.addset(s2, s3);
        else{
            cout << A.sumset(s2, s3) << endl;
        }
        
        
        Q--;
    }
    
    
}


Measured memory_bytes: 8220
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll>PLL;
#define rep(i,n) for (int i = 0; i < (n); ++i)
ll MOD = 1e4+7;
int main() {
    int n, m;
    cin >> n >> m;
    map<int, int> mp;
    rep(i, n) mp[i] = 0;
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        --a, --b;
        ++mp[a], ++mp[b];
    }
    for ( auto tmp_mp : mp ) {
        cout << tmp_mp.second << endl;
    }
    return 0;
}



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

using namespace std;

typedef long long ll;

int main() {
	int n;
	string s;
	cin >> n >> s;
	string cpy = s;
	sort(cpy.begin(), cpy.end());

	int ans = 0;
	for (int i = 0; i < n; i++) {
		if (s[i] == 'W')ans++;
	}
	ans = min(ans, n - ans);
	int tmp = 0;
	for (int i = 0; i < n; i++) {
		if (s[i] != cpy[i]) {
			tmp++;
		}
	}
	ans = min(ans, tmp / 2);
	cout << ans << endl;

	return 0;
}

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

int main(void) {
    double r;
    double pi = 3.14159265359;
    cin >> r;
    
    printf("%.6lf %.6lf", r * r * pi, 2 * r * pi);
    cout << endl;
    return 0;
}



Measured memory_bytes: 3276
sx,sy,tx,ty= map(int, input().split())
ux, uy = tx - sx, ty - sy
ans = ""
ans += 'R' * ux + 'U' * uy
ans += 'L' * ux + 'D' * uy
ans += 'D'
ans += 'R' * (ux + 1) + 'U' * (uy + 1)
ans += 'LU'
ans += 'L' * (ux + 1) + 'D' * (uy + 1)
ans += 'R'
print(ans)

Measured memory_bytes: 3064
n = int(input())
l = list(map(int,input().split()))
l.sort()
count = 0
for i in range(n-2):
    for j in range(i+1,n-1):
        for k in range(j+1,n):
            if l[i]!=l[j] and l[j]!=l[k] and l[k]!=l[i]:
                if l[i]+l[j]>l[k]:
                    count+=1
print(count)


Measured memory_bytes: 9080
#include <cstdio>
#include <algorithm>

using namespace std;

const int MAXN=2e5+10;
int N;
int arr[MAXN];

typedef long long int ll;

int main(){
    scanf("%d",&N);
    for(int i=1;i<=N;i++) scanf("%d",arr+i);

    ll ans=0;

    if (N%2){
        ll sum=0;
        for(int i=1;i<=N-2;i+=2) sum+=arr[i];
        ans=sum;

        ll tailDiff=0,tailDiffMax=0;
        for(int i=N-2;i>=0;i-=2){
            sum-=arr[i];
            sum+=arr[i+1];
            tailDiff+=arr[i+2];
            tailDiff-=arr[i+1];
            tailDiffMax=max(tailDiffMax,tailDiff);
            ans=max(ans,sum+tailDiffMax);
        }

    }else{
        ll sum=0ll;
        for(int i=1;i<N;i+=2) sum+=arr[i];

        ans=sum;
        for(int i=N-1;i>=0;i-=2){
            sum+=arr[i+1];
            sum-=arr[i];
            ans=max(ans,sum);
        }
    }


    printf("%lld\n",ans);

    return 0;
}

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

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

#define mp make_pair
typedef pair<int,int> pii;

const int M_MAX = 1000010;
const int N = 4000;

// 4000*4000*4 = 16000000*4 = 16MB*4=64MB
// 1MB
pii fill(vector<vector<int>> &maze, int x, int y, int dir, int k, int s) {
  for (int i = 0; i < k; i++) {
    maze[y + i * dy[dir]][x + i * dx[dir]] = s++;
  }
  return mp(x + k * dx[dir], y + k * dy[dir]);
}

void make(vector<vector<int>> &maze) {
  pii now = mp(N / 2, N / 2);
  int k = 1;
  int num = 1;
  while(num <= M_MAX) {
    now = fill(maze, now.first, now.second, 0, k, num); num += k;
    now = fill(maze, now.first, now.second, 1, k, num); num += k;
    k++;
    now = fill(maze, now.first, now.second, 2, k, num); num += k;
    now = fill(maze, now.first, now.second, 3, k, num); num += k;
    k++;
  }
}

char isprime[M_MAX];

void era() {
  for (int i = 0; i < M_MAX; i++) {
    isprime[i] = 1;
  }
  isprime[0] = isprime[1] = 0;
  for (int i = 2; i < M_MAX; i++) {
    if (isprime[i]) {
      for (int j = i + i; j < M_MAX; j += i) {
        isprime[j] = 0;
      }
    }
  }
}

void solve(vector<vector<int>> &maze, int m, int n) {
  int sx, sy;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      if (maze[i][j] == n) {
        sx = j, sy = i;
      }
    }
  }
  vector<vector<int16_t>> dp(N, vector<int16_t>(N, -1));
  dp[sy][sx] = isprime[maze[sy][sx]];
  for (int i = 0; i < N - 1; i++) {
    for (int j = 0; j < N; j++) {
      if (maze[i][j] > m) continue;
      if (dp[i][j] == -1) continue;
      if (j >= 1) dp[i + 1][j - 1] = max(dp[i + 1][j - 1], (int16_t)(dp[i][j] + isprime[maze[i + 1][j - 1]]));
      dp[i + 1][j] = max(dp[i + 1][j], (int16_t)(dp[i][j] + isprime[maze[i + 1][j]]));
      if (j < N - 1) dp[i + 1][j + 1] = max(dp[i + 1][j + 1], (int16_t)(dp[i][j] + isprime[maze[i + 1][j + 1]]));
    }
  }
  int ma = 0;
  int ma_ind = 0;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      if (maze[i][j] > m) continue;
      if (ma <= dp[i][j] && isprime[maze[i][j]]) {
        if (ma < dp[i][j]) {
          ma = dp[i][j];
          ma_ind = maze[i][j];
        } else {
          if (ma_ind < maze[i][j]) ma_ind = maze[i][j];
        }
      }
    }
  }
  if (ma == 0) {
    cout << "0 0" << endl;
  } else {
    cout << ma << " " << ma_ind << endl;
  }
}

int main() {
  vector<vector<int>> maze(N, vector<int>(N, 0));
  make(maze);
  era();

  int n, m;
  while(cin >> m >> n, m != 0) {
    solve(maze, m, n);
  }
  
  return 0;
}



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

const long long MOD = 1000000007;
const long long MAX = 2000000;

template<typename T>
T gcd(T a, T b) {
    return b != 0 ? gcd(b, a % b) : a;
}

template<typename T>
T lcm(T a, T b) {
    return a * b / gcd(a, b);
}

int main()
{
    long long H, N;
    cin >> H >> N;
    long long A[N];
    long long sum = 0;
    for (int i = 0; i < N;i++){
        cin >> A[i];
        sum += A[i];
    }
    if(sum>=H){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}


Measured memory_bytes: 1024
import sys


class BinaryIndexedTree():
    '''
    1-indexed
    '''
    def __init__(self, A):
        self.__n = len(A)
        self.__node = [0] * (self.__n + 1)
        self.__data = [0] * (self.__n + 1)

        S = [0] * (self.__n + 1)
        for i in range(1, self.__n + 1):
            S[i] = S[i - 1] + A[i - 1]
            self.__data[i] = A[i - 1]
            self.__node[i] = S[i] - S[i - (i & -i)]

    def add(self, i, v):
        self.__data[i] += v
        while i <= self.__n:
            self.__node[i] += v
            i += i & -i

    def sum(self, i):
        ''' [1, i]の和
        '''
        rst = 0
        while i > 0:
            rst += self.__node[i]
            i -= i & -i
        return rst
    
    def get(self, i, j):
        '''[i, j]の和
        '''
        if i == j:
            return self.__data[i]
        else:
            return self.sum(j) - self.sum(i - 1)


def main():
    N, Q = map(int, input().split())
    C = list(map(int, input().split()))

    P = [[] for _ in range(N)]
    for i, c in enumerate(C):
        P[c - 1].append(i)

    right = [0] * N
    for p in P:
        if len(p):
            right[p.pop()] = 1
    BIT = BinaryIndexedTree(right)

    query = [[] for _ in range(N)]
    for i, s in enumerate(sys.stdin.readlines()):
        l, r = map(int, s.split())
        query[r - 1].append((l - 1, i))

    ans = [None] * Q

    cur = N - 1
    for r, q in enumerate(reversed(query)):
        r = (N - 1) - r
        while q:
            l, i = q.pop()
            while r < cur:
                c = C[cur] - 1
                p = P[c]
                if len(p):
                    BIT.add(p.pop() + 1, 1)
                cur -= 1
            tmp = BIT.get(l + 1, r + 1)
            ans[i] = tmp

    print(*ans, sep='\n')


if __name__ == '__main__':
    main()


Measured memory_bytes: 281560
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>
#include<set>
#include<deque>
#include<queue>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;
const Int MOD = 1000000000 + 7;

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	Int H, W;
	cin >> H >> W;

	vector<vector<Int>> a(H, vector<Int>(W, 0));

	for (Int i = 0; i < H; i++) {
		for (Int j = 0; j < W; j++) {
			cin >> a[i][j];
		}
	}

	vector<vector<Int>> ans;
	//ans.push_back(vector<Int>

	/*for (Int i = 0; i < H; i++) {
		for (Int j = 0; j < W; j++) {
			if (a[i][j] % 2) {
				a[i][j]--;

				if (j == W - 1) {
					if (i == H - 1) {
						continue;
					}
					else {
						a[i + 1][0]++;
						vector<Int> temp = { i + 1,j + 1,i + 2,1 };
					}
				}
				else {
					a[i][j + 1]++;
					vector<Int> temp = { i + 1,j + 1,i + 1,j + 2 };
					ans.push_back(temp);
				}
			}
		}
	}*/

	Int j = 0;
	for (Int i = 0; i < H; i++) {
		if (j == 0) {//→
			while (j < W) {
				if (a[i][j] % 2) {
					a[i][j]--;

					if (j == W - 1) {
						if (i == H - 1) {
							continue;
						}
						else {
							a[i + 1][W-1]++;
							vector<Int> temp = { i + 1,j + 1,i + 2,W };
							ans.push_back(temp);
						}
					}
					else {
						a[i][j + 1]++;
						vector<Int> temp = { i + 1,j + 1,i + 1,j + 2 };
						ans.push_back(temp);
					}
				}
				j++;
			}
		}
		else {//←
			j = W - 1;
			while (j >= 0) {
				if (a[i][j] % 2) {
					a[i][j]--;

					if (j == 0) {
						if (i == H - 1) {
							continue;
						}
						else {
							a[i + 1][0]++;
							vector<Int> temp = { i + 1,1,i + 2,1 };
							ans.push_back(temp);
						}
					}
					else {
						a[i][j - 1]++;
						vector<Int> temp = { i + 1,j + 1,i + 1,j };
						ans.push_back(temp);
					}
				}
				j--;
			}
			j = 0;
		}
	}

	Int len = ans.size();
	printf("%lld\n", len);
	for (Int i = 0; i < len; i++) {
		printf("%lld %lld %lld %lld\n", ans[i][0], ans[i][1], ans[i][2], ans[i][3]);
	}

}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using pi = pair<int, int>;
const ll INF = 1LL << 60;

int main() {
	int n;
	cin >> n;
	if (n % 2 == 0) {
		cout << 1 << endl;
	}
	else {
		cout << 0 << endl;
	}
	return 0;
}



Measured memory_bytes: 3668
using System;
using System.Collections.Generic;
using System.Linq;

namespace ABC073_C_Write_and_Erase
{
	internal class Program
	{
		public static void Main(string[] args)
		{
			int n = int.Parse(Console.ReadLine());
			List<int> aList = new List<int>();
			for (int i = 0; i < n; i++)
				aList.Add(int.Parse(Console.ReadLine()));
			
			aList.Sort();
			
			//解説スライドを見て書いたコード
			int count = 1;
			int result = 0;
			for (int i = 0; i < n - 1; i++)
			{
				if (aList[i] == aList[i + 1])
				{
					count++;
				}
				else
				{
					if (count % 2 == 1) result++;
					count = 1;
				}
				
				if (i == n - 2 && count % 2 == 1) result++;
			}
			
			Console.WriteLine(result);

			//自分で書いたコード
			/*int count = aList.Count;
			for (int i = 0; i < n;)
			{
				int countNumbers = aList.Count(x => x == aList[i]);
				if (countNumbers % 2 == 1)
					count -= countNumbers - 1;
				else
					count -= countNumbers;

				i += countNumbers;
			}

			Console.WriteLine(count);*/
		}
	}
}

Measured memory_bytes: 16092
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int a, b, c; cin >> a >> b >> c;
  cout << set<int>({a, b, c}).size() << '\n';
}


Measured memory_bytes: 256
/*
Cerberus97
Hanit Banga
*/

#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>

using namespace std;

#define pb push_back
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)

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

const int N = 1e2 + 10;

int a[N];

int main() {
	int n; cin >> n;
	for (int i = 1; i <= n; ++i) {
		cin >> a[i];
	}
	int ans = 0;
	for (int i = 2; i <= n; ++i) {
		if (a[i] == a[i - 1]) {
			++ans;
			++i;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
    int n,array[15]={};
    scanf("%d",&n);
    for(int i=0;i<n;i++) scanf("%d",&array[i]);
    int max=0,max_i=0;
    for(int i=0;i<n;i++){
        if(array[i]>max){
            max=array[i];
            max_i=i;
        }
    }
    int sum=0;
    for(int i=0;i<n;i++){
        if(i==max_i) continue;
        sum+=array[i];
    }
    if(max<sum) printf("Yes\n");
    else printf("No\n");
    return 0;
}

Measured memory_bytes: 128
import java.util.*;
import java.io.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        FastScanner sc = new FastScanner(System.in);
        int n = sc.nextInt();
        int[] li = sc.nextIntArray(n);
        System.out.println(solve(li));
    }
    
    public static int solve(int[] arr){
        int max = arr.length;
        int ret = 0;
        for(int i = 0; i < max-2; i++){
            int[] chk = {arr[i],arr[i+1],arr[i+2]};
            Arrays.sort(chk);
            if(arr[i+1] == chk[1]){
                ret++;
            }
        }
        return ret;
    }
}

class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;
    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }
    
    public void close() throws Exception{
        this.reader.close();
        return;
    }

    public String next() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken("\n");
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public double nextDouble() {
         return Double.parseDouble(next());
    }

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }

    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nextLong();
        return a;
    } 
}

Measured memory_bytes: 25384
import java.util.Scanner

import scala.collection.mutable.ArrayBuffer

object Main {

  class UnionFind(val n: Int) {

    sealed trait Node

    final case class Root(count: Int, rank: Int) extends Node

    final case class NonRoot(parentIndex: Int) extends Node

    // TODO ArrayBufferではなくArrayでいいはず
    private val nodes: ArrayBuffer[Node] = ArrayBuffer.fill(n)(Root(count = 1, rank = 0))

    private def rootNode(index: Int): (Int, Root) = {
      nodes(index) match {
        case root: Root => (index, root) // nodes(index) == root
        case nonRoot: NonRoot =>
          val (rootIndex, root) = rootNode(nonRoot.parentIndex)
          nodes(index) = NonRoot(parentIndex = rootIndex) // 経路圧縮
          (rootIndex, root)
      }
    }

    def numComponents(): Int = nodes.count(p = node => node.isInstanceOf[Root])

    private def root(index: Int): Int = rootNode(index)._1

    def sameCount(x: Int): Int = rootNode(x)._2.count

    def same(x: Int, y: Int): Boolean = root(x) == root(y)


    def unite(x: Int, y: Int): Unit = {
      if (same(x, y)) return

      val (xRootIndex, xRoot) = rootNode(x)
      val (yRootIndex, yRoot) = rootNode(y)

      if (xRoot.rank < yRoot.rank) {
        // xRootの親をyRootとする
        nodes(xRootIndex) = NonRoot(parentIndex = yRootIndex)
        nodes(yRootIndex) = yRoot.copy(count = xRoot.count + yRoot.count)
      } else {
        // yRootの親をxRootとする
        nodes(yRootIndex) = NonRoot(parentIndex = xRootIndex)
        val nextXRootRank = xRoot.rank + (if (xRoot.rank == yRoot.rank) 1 else 0)
        nodes(xRootIndex) = Root(count = xRoot.count + yRoot.count, rank = nextXRootRank)
      }
    }

  }

  case class Magic(x: Int, y: Int, z: Long)

  case class NextInfo(v: Int, w: Long)

  def read() = {
    val sc = new Scanner(System.in)
    val n, m = sc.nextInt()
    // 0-index化
    val magics = IndexedSeq.fill(m)(
      Magic(sc.nextInt() - 1, sc.nextInt() - 1, sc.nextLong()))
    (n, m, magics)
  }


  def solve(n: Int, m: Int, magics: IndexedSeq[Magic]): Int = {
    val uf = new UnionFind(n)
    for (magic <- magics) {
      uf.unite(magic.x, magic.y)
    }
    uf.numComponents()
  }

  def main(args: Array[String]): Unit = {
    val (n, m, magics) = read()
    val result = solve(n, m, magics)
    println(result)
  }
}

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

using namespace std;

int main() {
  string s;
  cin >> s;
  int l = s.size();
  vector<int> cnt(2, 0);
  for (int i = 0; i < l; i++) {
    cnt[i % 2] += s[i] == '1';
  }
  cout << min(l / 2 - cnt[1] + cnt[0], (l + 1) / 2 - cnt[0] + cnt[1]) << '\n';
  return 0;
}

Measured memory_bytes: 512