akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  string s;
  cin >> s;
  vector<pair<char, int>> vp;
  vp.push_back({s.front(), 1});
  rep2(i, 1, s.size()){
    if(s.at(i) == s.at(i-1)) vp.back().second++;
    else vp.push_back({s.at(i), 1});
  }

  int k;
  cin >> k;
  ll ans = 0;
  rep2(i, 1, vp.size()-1) ans += (ll)vp.at(i).second/2*k;
  if(vp.size() == 1){
    ans += (ll)s.size()*k/2;
  }else if(vp.front().first == vp.back().first){
    ans += (ll)(vp.front().second+vp.back().second)/2*(k-1);
    ans += vp.front().second/2;
    ans += vp.back().second/2;
  }else{
    ans += (ll)vp.front().second/2*k;
    ans += (ll)vp.back().second/2*k;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3628
import java.util.Scanner;

public class Main {


    public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
    	int a = sc.nextInt();
    	int b = sc.nextInt();
    	int c = sc.nextInt();
        if(a < b && b < c)
        {
            System.out.println("Yes");
        }
        else
        {
            System.out.println("No");
        }
        sc.close();
    }

}

Measured memory_bytes: 26188
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#define MAX_V 100005

int main(void){
 	int n;
 	cin>>n;
 	vector<int> v1,v2;
 	int inp;
 	rep(i,112345){
 		v1.push_back(0);
 		v2.push_back(0);
 	}
 	rep(i,n){
 		cin>>inp;
 		if(i%2 == 0){
 			v1[inp]++;
 		}else{
 			v2[inp]++;
 		}
 		
 	}
 	int max1 = 0, max2 = 0, next1 = 0, next2 = 0, memo1, memo2;
 	rep(i,112345){
 		if(v1[i] > next1){
 			if(v1[i] > max1){
 				next1 = max1;
 				max1 = v1[i];
 				memo1 = i;
 			}else{
 				next1 = v1[i];
 			}
 		}
 		if(v2[i] > next2){
 			if(v2[i] > max2){
 				next2 = max2;
 				max2 = v2[i];
 				memo2 = i;
 			}else{
 				next2 = v2[i];
 			}
 		}

 	}
 	if(memo1 != memo2){
 		cout<<n-max1-max2<<endl;
 		return 0;
 	}else{
 		cout<<n-max(max1 + next2, max2 + next1)<<endl;
 		return 0;
 	}

	return 0;
}

Measured memory_bytes: 1396
#include <stdio.h>

int main(int argc, const char * argv[]) {
    // insert code here...
    int W, H, x, y, r;
    scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);
    if (x>0&&y>0) {
        if (x+r<=W&&y+r<=H) {
            printf("Yes\n");
        }else{
            printf("No\n");
        }
    }else{
        printf("No\n");
    }
    return 0;
}



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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

vector<int> h,l,s;
vector<int> g[300];
vector<ll> dp[301];
vector<ll> update;

void knapsackDP(ll v,ll lim,ll clim,const vector<ll>& pre,vector<ll>& ret){
  deque<ll> deq,deqv;
  rep(i,clim+1){
    ll val=pre[i]-i*v;
    while(deq.size()&&deqv.back()<=val){
      deq.pop_back(); deqv.pop_back();
    }
    deq.push_back(i);
    deqv.push_back(val);
    ret[i]=deqv.front()+i*v;
    if(deq.front()==i-lim){
      deq.pop_front();
      deqv.pop_front();
    }
  }
}

void dfs(int v,int clim,vector<ll>& ret){
  knapsackDP(s[v],h[v],clim,ret,dp[v]);
  for(int nv : g[v]){
    dfs(nv,clim-l[nv],ret);
    ret=dp[nv];
    knapsackDP(s[v],h[v]-l[nv],clim,ret,update);
    rep(i,clim+1-l[nv])maxch(dp[v][i+l[nv]],update[i]+(ll)l[nv]*s[v]);
  }
}

int main(){
  while(1){
    int N,C;
    scanf("%d%d",&N,&C);
    if(N==0)break;
    rep(i,N){
      g[i].clear();
      dp[i].resize(C+1,0);
    }
    h.resize(N,0); l.resize(N,0); s.resize(N,0); update.resize(C+1,0);
    rep(i,N)scanf("%d",&h[i]);
    rep(i,N)scanf("%d",&s[i]);
    rep(i,N-1){
      int p;
      scanf("%d",&p); p--;
      g[p].push_back(i+1);
    }
    rep(i,N-1)scanf("%d",&l[i+1]);
    rep(i,N){
      sort(all(g[i]),[&](const int& a,const int& b){ return l[a] < l[b]; });
    }
    vector<ll> ret(C+1,0);
    dfs(0,C,ret);
    cout<<dp[0][C]<<endl;
  }

  return 0;
}



Measured memory_bytes: 84368
#include <iostream>
#include <sstream>
#include <stack>
#include <iomanip>
#include <numeric>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>

#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type >
#define endl '\n'

#define FOR(i, A, B) for(auto i = (A);i != (B); i++)
#define FORD(i, A, B) for(auto i = (A);i != (B); i--)

#define READRANGE(begin, end) FOR(it, begin, end) cin >> *it
#define READVEC(V) READRANGE(BEGIN(V), END(V))

using namespace std;

typedef long long lint;
typedef pair<int, int> Pii;
typedef pair<int, lint> Pil;
typedef pair<lint, lint> Pll;
typedef pair<lint, int> Pli;

template<class U, class V>
istream& operator >>(istream& in, pair<U, V>& pr) {
    return in >> pr.first >> pr.second;
}

template<class U, class V>
ostream& operator <<(ostream& out, pair<U, V>& p) {
    return out << p.first << " " << p.second;
}

template<class T>
ostream& operator <<(ostream& out, vector<T> vec) {
    for (T& e : vec)
        out << e << " ";
    return out << endl;
}

// ---- BEGIN LIBRARY CODE ----
// ---- END LIBRARY CODE ----
void io_init()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
};

int main(int argc, char **argv)
{
    io_init();

    // Actual program code starts here.
    char d1, d2;
    cin >> d1 >> d2;
    int r1 = d1 - '0', r2 = d2 - '0';
    cout << min(string(r1, d2), string(r2, d1)) << endl;
    return 0;
};

Measured memory_bytes: 256
#include<cstdio>
#define N 400001
using namespace std;
int x[N],y[N],p[N],xwei[N],f[N],next[N],head[N],edge[N],wei[N];
int total1,n,stotal=0;
void insert(int x,int y)
{
	total1++;
	next[total1]=head[x];
	head[x]=total1;
	edge[total1]=y;
}
void swap(int &x,int &y)
{
	int t=x;x=y;y=t;
}
int max(int x,int y)
{
	if (x<y) return y;
	return x;
}
void qsort(int l,int r)
{
	int i=l,j=r;
	int mid=p[(i+j)/2];
	while (i<=j)
	{
		while (p[i]<mid) i++;
		while (p[j]>mid) j--;
		if (i<=j)
		{
			swap(p[i],p[j]);
			swap(xwei[i],xwei[j]);
			swap(wei[i],wei[j]);
			i++;j--;
		}
	}
	if (i<r) qsort(i,r);
	if (l<j) qsort(l,j);
}
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
	{
		int xx,yy;
		scanf("%d%d",&xx,&yy);
		stotal++;p[stotal]=xx-yy;xwei[stotal]=1;wei[stotal]=i;
		stotal++;p[stotal]=yy+xx;xwei[stotal]=2;wei[stotal]=i;
	}
	qsort(1,stotal);
	p[0]=-1e9-1;
	int num=0;
	for (int i=1;i<=stotal;i++)
	{
		if (p[i]!=p[i-1]) 
			num++;
		if (xwei[i]==1) x[wei[i]]=num;
		else	y[wei[i]]=num;
	}
	for (int i=1;i<=n;i++) insert(y[i],i);
	for (int i=1;i<=num;i++)
	{
		for (int j=head[i];j;j=next[j])
		{
			int y=edge[j];
			f[i]=max(f[x[y]]+1,f[i]);
		}
		f[i]=max(f[i],f[i-1]);
	}
	printf("%d\n",f[num]);
}

Measured memory_bytes: 12032
#![allow(unused_imports)]
    #![allow(dead_code)]
    use std::io::prelude::*;
    use std::cmp::{max, min};
    use std::collections::BinaryHeap;

    const MOD: i64 = 1e9 as i64 + 7; 

    fn main(){
        let h: usize = read();
        let w: usize = read();
        let a: usize = read();
        let b: usize = read();
        let c = w - a;
        let d = h - b;
        for _ in 0..b{
            for _ in 0..a{
                print!("0");
            }
            for _ in 0..c{
                print!("1");
            }
            println!();
        }
        for _ in 0..d{
            for _ in 0..a{
                print!("1");
            }
            for _ in 0..c{
                print!("0");
            }
            println!();
        }
    }

    fn read<T>() -> T
    where
        T: std::str::FromStr,
    {
        let stdin = std::io::stdin();
        let token: String = stdin
            .lock()
            .bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect();
        token.parse().ok().unwrap()
    }


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

using namespace std;

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

    int N;
    string S;
    cin >> N >> S;
    int res = 1;
    for (int i = 1; i < N; ++i) {
        res += S[i] != S[i - 1];
    }
    cout << res << "\n";
    
    return 0;
}

Measured memory_bytes: 512
import java.io.*;
import java.util.*;

public class Main {
    static MyReader in = new MyReader();

    public static void main(String[] args) {
        int N = in.i();
        long K = in.l();
        long[] A = in.ll(N);

        long X = 0;
        for (int d = 39; d >= 0; d--) {
            int c = 0;
            for (int i = 0; i < N; i++) {
                c += (A[i] >> d) & 1;
            }
            X |= c < N - c ? (1L << d) : 0;
        }

        for (int d = 39; d >= 0; d--) {
            long k = (K >> d) & 1;
            long b = (X >> d) & 1;
            if (k == 1 && b == 0) {
                break;
            } else if (k == 0 && b == 1) {
                X ^= 1L << d;
            }
        }

        long ans = 0;
        for (int i = 0; i < N; i++) {
            ans += A[i] ^ X;
        }

        System.out.println(ans);
    }
}

class MyReader extends BufferedReader {
    char[] cbuf = new char[1024];
    int head = 0;
    int tail = 0;

    MyReader() {
        super(new InputStreamReader(System.in));
    }

    char next() {
        if (head == tail) {
            try {
                tail = super.read(cbuf, 0, cbuf.length);
            } catch (IOException e) {
                e.printStackTrace();
            }
            head = 0;
        }
        return cbuf[head++];
    }

    int i() {
        int k = next() - '0';
        boolean minus = k == -3;
        int n = minus ? 0 : k;
        while (0 <= (k = next() - '0') && k <= 9) n = 10 * n + k;
        return minus ? -n : n;
    }

    long[] ll(final int N) {
        long[] a = new long[N];
        for (int j = 0; j < a.length; j++) a[j] = l();
        return a;
    }

    long l() {
        int k = next() - '0';
        boolean minus = k == -3;
        long n = minus ? 0 : k;
        while (0 <= (k = next() - '0') && k <= 9) n = 10 * n + k;
        return minus ? -n : n;
    }

    char[] s(final int N) {
        char[] s = new char[N];
        for (int i = 0; i < N; i++) {
            s[i] = next();
        }
        next();
        return s;
    }

    public int read(char[] cbuf) {
        int i;
        char c;
        for (i = 0; (c = next()) != ' ' && c != '\n'; i++) cbuf[i] = c;
        return i;
    }

    public String readLine() {
        try {
            return super.readLine();
        } catch (IOException e) {
            return null;
        }
    }
}


Measured memory_bytes: 36308
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
//long long a[200005]={0};
long long vv[4][200005];
int a = -mod*2,b = -mod*2,c = -mod*2,d = -mod*2;
int main()
{
    int n;
    cin >> n;
    int x,y;
    for(int i=0;i<n;i++){
        cin >> x >> y;
        a=max(a,x+y);
        b=max(b,-x-y);
        c=max(c,x-y);
        d=max(d,y-x);
    }
    //long long dis = 0 ;
    cout << max(a+b,c+d) <<endl;
    //dis = max(dis,*max_element(vv[0],vv[0]+n)+*max_element(vv[1],vv[1]+n));
    //dis = max(dis,*max_element(vv[2],vv[2]+n)+*max_element(vv[3],vv[3]+n));
    //cout << dis << endl;
    return 0;
}


Measured memory_bytes: 3600
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <cstring>
#include <map>
#include <set>
#include <algorithm>

using namespace std;

int main()
{
  int a,b,c;
  cin >> a >> b >> c;
  cout << min(b/a, c);
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
//#define N 10000
int main(){
	int n,j,cnt = 0;
	int a;
	scanf("%d",&n);
	while(n--){
		scanf("%d",&a);
		if(a < 2) continue;
		if(a == 2 || a == 3){ cnt++; continue;}
		else if(a % 2 == 0) continue;
		for(j = 3;j*j <= a; j+=2)
			if(a % j == 0) break;
		if(a % j == 0) continue;
		cnt++;
	}
	printf("%d\n",cnt);

	return 0;
}



Measured memory_bytes: 2100
///Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>
#define        u64             uint64_t
#define        ll              long long
#define        endl            "\n"
#define        PI              acos(-1)
#define        fi              first
#define        si              second
#define        mkp             make_pair
#define        pb              push_back
#define        set0(arr)       memset(arr, 0, sizeof(arr))
#define        setinf(arr)     memset(arr, 126, sizeof(arr))
#define        all(x)          (x).begin(),(x).end()
#define        sz(v)           ((int)(v).size())
#define        IOS             ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
using          pll        =      pair<ll, ll> ;
using          vl         =      vector<ll> ;
using          vpll       =      vector<pll> ;
using          mll        =      map<ll, ll> ;
using          mcl        =      map<char, ll> ;
using          msl        =      map<string,ll> ;
using          sl         =      set<ll> ;
using          sc         =      set<char> ;
using          dl         =      deque<ll> ;
const int N = 1e6+5 ;

ll      mod = 1e9+7 ;
vl      adj[N] ;
vpll    adjc[N] ;
ll      vis[N] ;
ll      arr[N] ;


ll fun(ll n)
{

    ll div[n + 1];
    memset(div, 0, sizeof div);

    // For every number from 1 to n
    for (ll i = 1; i <= n; i++) {

        // Increase divisors count for
        // every number divisible by i
        for (ll j = 1; j * i <= n; j++)
            div[i * j]++;
    }

    // Print the divisors
    ll sum=0;
    for (ll i = 1; i <= n; i++)
        sum+=div[i];
        return sum;
}

int main()
{
    IOS;
    ll a, b, c, d, n, m, p, x, y, z, i, j, k, f = 0, tc, cnt = 0, sum = 0, mul = 1, mi = 1e18, ma = -1e18, cs;
    string   str ;
    char     ch ;
    double   db ;
    ll       l, r ;
    //code

     cin>>n;
     cout<<fun(n-1)<<endl;


    //code
    return 0;
}




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

int main(){
  int h,w;
  cin>>h>>w;
  vector<string> s(h);
  for (int i=0;i<h;i++){
    cin>>s.at(i);
  }
  for (int i=0;i<h;i++){
    for (int j=0;j<w;j++){
      if (s.at(i).at(j)=='#'){
        cout<<'#';
      }else{
        int c=0;
        for (int k=max(0,i-1);k<=min(h-1,i+1);k++){
          for (int l=max(0,j-1);l<=min(w-1,j+1);l++){
            if (s.at(k).at(l)=='#'){
              c++;
            }
          }
        }
        cout<<c;
      }
    }
    cout<<endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")

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

int main(){
  int n; cin >> n;
  int a[n];
  rep(i, n) cin >> a[i];
  int tmpMax[n] = {};
  int tmp = -1*MOD;
  for(int i = n-1; i>=1; i--){
    tmp = max(a[i], tmp);
    tmpMax[i] = tmp;
  }
  int ans = -1 * MOD;
  for(int i = 0; i<n-1; i++){
    ans = max(ans, tmpMax[i+1] - a[i]);
  }
  cout << ans << "\n";
}



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

int main() {
    int N;
    cin >> N;
    string ans = "APPROVED";
    for(int i=0; i<N; i++) {
        int A;
        cin >> A;
        if(A%2==0 && A%3!=0 && A%5!=0) ans = "DENIED";
    }
    cout << ans << endl;
}


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

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

 int main(){
  int n, m;

  cin >> n >> m;
  int a[51],b[51];

  rep(i,m+1) cin >> a[i] >> b[i];

 int ansA[n],ansB[n];

  rep(i,n+1){

   ansA[i]= 0;
   rep(k,m+1){
    if(a[k] != i) continue;
    else ansA[i]++;
    }

    ansB[i]= 0;
    rep(k,m+1){
     if(b[k] != i) continue;
    else ansB[i]++;
    }
   }

   rep(i,n+1){ 
    cout << (ansA[i]) + (ansB[i]) << endl;
   }


 return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	
	int n; cin >> n;
	vector<vi> e(n, vi(n, -1));
	rep(i, n){
		int a; cin >> a;
		rep(j, a){
			int x, y; cin >> x >> y;
			e[i][x - 1] = y;
		}
	}
	int ans = 0;
	rep(b, 1 << n){
		bool ok = 1;
		rep(i, n) if(b >> i & 1) rep(j, n) if(e[i][j] >= 0 && (b >> j & 1) != e[i][j]){
			ok = 0;
			i = n; break;
		}
		if(ok) ans = max(ans, __builtin_popcount(b));
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner

object Main extends App{
  val sc = new Scanner(System.in)

  val n  = sc.nextInt
  val al = List.fill(n)(sc.nextInt)

  val res = al.map{a =>
    def loop(n: Int, cnt: Int): Int ={
      if(n % 2 == 0 ) loop(n / 2, cnt + 1)
      else cnt
    }
    loop(a, 0)
  }.min

  println(res)
}

Measured memory_bytes: 25544
N = int(input())
A = list(map(int, input().split()))
B = [A[i] - (i+1) for i in range(len(A))]
B.sort()

if N % 2 != 0:
    b = B[(N+1)//2 - 1]
    ans = 0
    for i in range(len(B)):
        ans += abs(B[i] - b)
else:
    b1 = B[N//2 - 1]
    ans1 = 0
    for i in range(len(B)):
        ans1 += abs(B[i] - b1)
    b2 = B[N//2]
    ans2 = 0
    for i in range(len(B)):
        ans2 += abs(B[i] - b2)
    ans = min(ans1, ans2)
print(ans)


Measured memory_bytes: 25744
#include <bits/stdc++.h>
//----***やべーやつら***----
using namespace std;
#define int long long

//----***型定義***----
using ll = long long;
using pll = pair<ll, ll>;
using pdd = pair<double, double>;
typedef long double ld;
typedef pair<int,int> P;

//----***Like a Pythonista***----
#define REP(ii,jj,nn) for (ll ii=jj;ii<(nn);ii++)
#define RREP(ii,nn,jj) for (ll ii = nn; jj<ii;ii--)
#define each(i,...) for (auto&& i:__VA_ARGS__)
#define ALL(vec) (vec).begin(),(vec).end()
#define sum(...) accumulate(ALL(__VA_ARGS__),0LL)
#define dsum(...) accumulate(ALL(__VA_ARGS__),0.0L)
#define vec(type,name,...) vector<type> name(__VA_ARGS__)
template<class T> inline auto max(const T& a){ return *max_element(ALL(a)); }
template<class T> inline auto min(const T& a){ return *min_element(ALL(a)); }
inline ll gcd(ll a,ll b){if(b == 0) return a;return  gcd(b,a%b);}
inline ll lcm(ll a,ll b){ll g = gcd(a,b);return a / g * b;}

//----***定数***----
#define MOD 1e9+7;
#define INF 1e9;
#define EPS 1e-9;

//----***入出力***---
#define print(out) cout<< out  << "\n";
#define debug(var)  do{std::cerr << #var << " ↓ "<<"\n";view(var);}while(0);
#define dbg cerr<<"🥺🥺🥺🥺🥺🥺"<<endl;
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }

//----***初期時読み込み***----
struct initial{initial(){cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};}initial_;

signed main(){
  int N;
  string S;
  cin>>N>>S;
  vector<int> R_num(2*N,0),G_num(2*N,0),B_num(2*N,0);
  if(S.at(N-1)=='R')R_num[N-1]=1;
  if(S.at(N-1)=='G')G_num[N-1]=1;
  if(S.at(N-1)=='B')B_num[N-1]=1;
  for(int i=N-1;0<=i;i--){
    if(S.at(i)=='R'){
      R_num[i]=R_num[i+1]+1;
    }
    else{
      R_num[i]=R_num[i+1];
    }
    if(S.at(i)=='G'){
      G_num[i]=G_num[i+1]+1;
    }
    else{
      G_num[i]=G_num[i+1];
    }
    if(S.at(i)=='B'){
      B_num[i]=B_num[i+1]+1;
    }
    else{
      B_num[i]=B_num[i+1];
    }
  }
  int ans=0;
  char target;
  for(int i=0;i<N-2;i++)for(int j=i+1;j<N-1;j++){
    if(S.at(i)==S.at(j))continue;
    if (S.at(i)=='R'&&S.at(j)=='B'){target='G';}
    else if(S.at(i)=='B'&&S.at(j)=='R'){target='G';}
    else if(S.at(i)=='R'&&S.at(j)=='G'){target='B';}
    else if(S.at(i)=='G'&&S.at(j)=='R'){target='B';}
    else if(S.at(i)=='G'&&S.at(j)=='B'){target='R';}
    else if(S.at(i)=='B'&&S.at(j)=='G'){target='R';}

    if(target=='R'){
      ans+=R_num[j+1];
    }
    if(target=='B'){
      ans+=B_num[j+1];
    }
    if(target=='G'){
      ans+=G_num[j+1];
    }
    if(2*j-i<N&&S.at(2*j-i)==target){
      ans--;
    }
  }

  cout<<ans<<"\n";

}


Measured memory_bytes: 3784
#include <iostream>
#include <stdio.h>
#include <set>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <limits>

typedef long long int lli;
#define rep(i,s,N) for(int i=s;i<N;i++)
#define MOD 1000000007
using namespace std;

int main(void)
{
	int H, W; cin >> H >> W;
	vector<string> a(H + 2);
	rep(j, 0, W + 2) {
		a[0].push_back('#');
		a[H + 1].push_back('#');
	}
	rep(i, 1, H + 1) {
		cin >> a[i];
		a[i].insert(0, "#");
		a[i].push_back('#');
	}
	rep(i, 0, H + 2)cout << a[i] << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, l, r, sum = 0;
  cin >> N;
 
  for (int i = 0; i < N; i++) {
    cin >> l >> r;
    sum += r - l + 1;
  }
  
  cout << sum;
}

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

typedef long long ll;
const int MAXN = 3e5 + 10;
const int Mod = 1e9 + 7;
int N;
char S[MAXN];
ll f[MAXN][2][2][3], s[MAXN];
ll ans;

int main() {
	register int i, j, k, l;
	scanf("%s", S + 1); N = strlen(S + 1);
	for(s[N + 1] = 1, i = N; i; --i) s[i] = s[i + 1] * (S[i] == '?' ? 2 : 1) % Mod;
	f[1][0][0][0] = 1;
	for(i = 1; i <= N; ++i) {
		if(S[i] != '1')
			for(j = 0; j < 2; ++j)
				for(k = 0; k < 2; ++k)
					for(l = 0; l < 3; ++l)
						(f[i + 1][j][k][(l & 1) + 1] += f[i][j][k][l]) %= Mod;
		if(S[i] != '0')
			for(j = 0; j < 2; ++j)
				for(k = 0; k < 2; ++k) {
					if(!j && !k) (f[i + 1][1][1][0] += f[i][j][k][0]) %= Mod;
					else if(j && k) (ans += 1ll * f[i][j][k][0] * s[i + 1]) %= Mod;
					else (f[i + 1][!j][k][0] += f[i][j][k][0]) %= Mod;
					(f[i + 1][j][k][0] += f[i][j][k][1]) %= Mod;
					(f[i + 1][!j][k][0] += f[i][j][k][2]) %= Mod;
				}
	}
	printf("%lld\n", (ans + f[N + 1][1][1][0]) % Mod);
	return 0;
}

Measured memory_bytes: 30976
# -*- coding: utf-8 -*-
"""
Created on Tue Jan  1 15:49:46 2019

@author: Yamazaki Kenichi
"""

D = int(input())

if D == 22:
    print('Christmas Eve Eve Eve')
elif D == 23:
    print('Christmas Eve Eve')
elif D == 24:
    print('Christmas Eve')
else:
    print('Christmas')


Measured memory_bytes: 2940
import sys
input=sys.stdin.readline

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

class UnionFind:
    def __init__(self, n):
        self.par = [-1]*(n+1)
        self.sizes=[1]*(n+1)

    # 検索
    def find(self, x):
        if self.par[x]<0:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    # 併合
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x==y:
            return
        d1=self.par[x]
        d2=self.par[y]
        if d1<=d2:
            self.par[y]=x
            self.sizes[x]=self.sizes[x]+self.sizes[y]
            if d1==d2:
                self.par[x]=self.par[x]-1
        else:
            self.par[x]=y
            self.sizes[y]=self.sizes[x]+self.sizes[y]

    # 同じ集合に属するか判定
    def same_check(self, x, y):
        return self.find(x) == self.find(y)

    #サイズ
    def size(self,x):
        return self.sizes[self.find(x)]

    #木の数
    def number(self):
        count=0
        for i in self.par[1:]:
            if i<0:
                count=count+1
        return count

U=UnionFind(n)
for _ in range(m):
    a,b=map(int,input().split())
    a-=1
    b-=1
    if not U.same_check(a,b):
        U.union(a,b)

ans=0
for i in range(n):
    ans=max(ans,U.size(i))
print(ans)


Measured memory_bytes: 83028
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
//const int INF = 1e8;
using namespace std;

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

	map<int,int> input;
	rep(i,n){
		int a;
		cin >> a;
		input[a]++;
	}
	//for(auto i : input){ cout << i.first << ' ' << i.second << endl; }

	vector<int> odd(100001,0), even(100001,0); //同値でマッチングできる:even
	for(auto i : input){
		if(i.second % 2){
			odd[i.first % m]++;
			i.second--;
		}
		even[i.first % m] += i.second;
	}


	int ans = odd[0] / 2 + even[0] / 2; //mod 0のカードのマッチング
	range(i,1,m){
		int j = m - i;
		if(i == j){
			ans += (odd[i] + even[i]) / 2; // mod m / 2のカードのマッチング
		}else if(i < j){
			if(odd[i] > odd[j]){
				swap(odd[i], odd[j]);
				swap(even[i], even[j]);
			}

			ans += odd[i];
			odd[j] -= odd[i]; //自分自身にマッチングできないカードを別カードにマッチング
			int p = min(odd[j], even[i]); //余ったカードをさらにマッチング
			ans += p;
			even[i] -= p;

			ans += even[i] / 2 + even[j] / 2; //自分とマッチング
		}
	}

	cout << ans << endl;
}


Measured memory_bytes: 5760
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <cassert>
#include <string.h>
//#include <unordered_set>
//#include <unordered_map>
//#include <bits/stdc++.h>

#define MP(A,B) make_pair(A,B)
#define PB(A) push_back(A)
#define SIZE(A) ((int)A.size())
#define LEN(A) ((int)A.length())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define fi first
#define se second

using namespace std;

template<typename T>inline bool upmin(T &x,T y) { return y<x?x=y,1:0; }
template<typename T>inline bool upmax(T &x,T y) { return x<y?x=y,1:0; }

typedef long long ll;
typedef unsigned long long ull;
typedef long double lod;
typedef pair<int,int> PR;
typedef vector<int> VI;

const lod eps=1e-11;
const lod pi=acos(-1);
const int oo=1<<30;
const ll loo=1ll<<62;
const int mods=1e9+7;
const int inv2=(mods+1)>>1;
const int MAXN=3005;
const int INF=0x3f3f3f3f;//1061109567
/*--------------------------------------------------------------------*/
inline int read()
{
	int f=1,x=0; char c=getchar();
	while (c<'0'||c>'9') { if (c=='-') f=-1; c=getchar(); }
	while (c>='0'&&c<='9') { x=(x<<3)+(x<<1)+(c^48); c=getchar(); }
	return x*f;
}
int f[MAXN][MAXN],a[MAXN];
inline int upd(int x,int y){ return x+y>=mods?x+y-mods:x+y; }
int main()
{
	int n=read(),q=read();
	for (int i=1;i<=n;i++) a[i]=read();
	for (int i=1;i<=n;i++) 
		for (int j=1;j<=n;j++)
			if (a[i]>a[j]) f[i][j]=1;
	for (int i=1;i<=q;i++)
	{
		int x=read(),y=read();
		f[x][y]=f[y][x]=1ll*upd(f[x][y],f[y][x])*inv2%mods;
		for (int j=1;j<=n;j++)
		if (x!=j&&y!=j)
			f[x][j]=f[y][j]=1ll*upd(f[x][j],f[y][j])*inv2%mods,
			f[j][x]=f[j][y]=1ll*upd(f[j][x],f[j][y])*inv2%mods;
	}
	int ans=0;
	for (int i=1;i<=n;i++) 
		for (int j=i+1;j<=n;j++) ans=upd(ans,f[i][j]);
	for (int i=1;i<=q;i++) ans=upd(ans,ans);
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 35584
// author:  Harsh Nema
#include <bits/stdc++.h>
#define ll long long int
#define F first
#define S second
const ll mod = 1e9 + 7;
const ll INF = 10000000000000;
#define pb push_back
#define deb(x) cout << '>' << #x << ':' << x << endl;
#define fastio ios_base::sync_with_stdio(0); cin.tie(0);
using namespace std;
void solve(){
    ll n=0;
    cin>>n;
    ll sum=0;
    for(ll i=1;i<=n;++i){
        if(i%3!=0 and i%5!=0)
            sum+=i;
    }
    cout<<sum;
}
int main()
{
    fastio;
//    ll t=0;
//    cin>>t;
//    while(t--)
        solve();
    return 0;
}


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

l = "abcdefghijklmnopqrstuvwxyz"

taroscore = 0
hanakoscore = 0


for i in range(n):
  card = input().split()
  taro = card[0]
  hanako = card[1]
  tn = len(taro)
  hn = len(hanako)

  if tn > hn :
    tryn = hn

  else:
    tryn = tn

  for o in range(tryn):


    for j in range(26):
      if taro[o] == l[j]:
        taros = j

    for k in range(26):
      if hanako[o] == l[k]:
        hanakos = k

    if taros > hanakos:
      result = "taro"
      break
    elif taros < hanakos:
      result = "hanako"
      break
    else:
      result = "even"

  if result == "taro":
    taroscore += 3

  elif result == "hanako":
    hanakoscore += 3

  else:
    if tn == hn:
      taroscore += 1
      hanakoscore += 1
    elif tn < hn:
      hanakoscore += 3
    else:
      taroscore += 3

print(taroscore, hanakoscore)
 


Measured memory_bytes: 5600
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>

using namespace std;

#define all(a) (a).begin(),(a).end()
#define rep(i,n) for(int i=0;i<(n);++i)
#define iter(it,v) for(auto it=v.begin();it!=v.end();++it)
#define in(v) cin>>v;
#define out(v) cout<<v<<"\n"
const int MOD = 1e9+7;
const int INF = numeric_limits<int>::max();

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

  vector<int> L[N];
  rep(i, N) {
    int k; in(k);
    rep(j, k) {
      int l; in(l);
      L[i].push_back(l);
    }
    sort(all(L[i]));
  }

  set<int> s;
  iter(it, L[0]) {
    s.insert(*it);
  }
  bool is_friend[N]; // コミュニティーに属している=0番の人としゃべれる
  fill(is_friend, is_friend+N, false);
  is_friend[0] = true;

  while (true) {
    bool changed = false;
    rep(i, N) {
      if (is_friend[i])
        continue;
      bool has_common = false;
      iter(it, L[i]) {
        if (s.find(*it) != s.end()) {
          has_common = true;
          break;
        }
      }
      if (has_common) {
        is_friend[i] = true;
        changed = true;
        iter(it, L[i]) s.insert(*it);
      }
    }
    if (!changed)
      break;
  }
  rep(i, N) {
    if (!is_friend[i]) {
      out("NO");
      return 0;
    }
  }
  out("YES");

  return 0;
}


Measured memory_bytes: 5888
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cmath>
#include <iomanip>
#include <algorithm>
using namespace std;

int main(){
    int n;
    cin >> n;
    vector<string> startM;
    vector<string> startA;
    vector<string> startR;
    vector<string> startC;
    vector<string> startH;
    for(int i = 0; i < n; i++){
        string str;
        cin >> str;
        if(str[0] == 'M'){
            startM.push_back(str);
        }
        if(str[0] == 'A'){
            startA.push_back(str);
        }
        if(str[0] == 'R'){
            startR.push_back(str);
        }
        if(str[0] == 'C'){
            startC.push_back(str);
        }
        if(str[0] == 'H'){
            startH.push_back(str);
        }
    }
    // M - A - R,C,H
    // M - R - C,H
    // M - C - H
    // A - R - C,H
    // A - C - H
    // R - C - H
    if(startM.size() + startA.size()+ startR.size()+ startC.size()+ startH.size() < 3){
        cout << 0 << endl;
    } else {
        long long ans = 0;
        ans += startM.size() * startA.size() * startR.size();
        ans += startM.size() * startA.size() * startC.size();
        ans += startM.size() * startA.size() * startH.size();
        ans += startM.size() * startR.size() * startC.size();
        ans += startM.size() * startR.size() * startH.size();
        ans += startM.size() * startC.size() * startH.size();
        ans += startA.size() * startR.size() * startC.size();
        ans += startA.size() * startR.size() * startH.size();
        ans += startA.size() * startC.size() * startH.size();
        ans += startR.size() * startC.size() * startH.size();
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 5748
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <queue>
#include <cmath>
#include <stdio.h>
#include <sstream>
#define int_inf 1000000000 //1e9
#define ll_inf  1000000000000000000 //1e18
using namespace std;
template <typename T> std::string to_string(const T& t){
	std::ostringstream os; os<<t; return os.str();
}

struct S{
	int a, b;
};
bool operator< (S &p, S &q){
	if(p.a!=q.a) return p.a<q.a;
	else return p.b<q.b;
}

int main(){
	int n, h;
	cin >> n >> h;
	vector<S> sw;
	sw.resize(n);
	for(int i=0; i<n; i++) cin >> sw[i].a >> sw[i].b;
	sort(sw.begin(), sw.end());
	int maxa=sw[n-1].a;
//cout<<"#"<<endl;
//cout<<maxa<<endl;
	vector<int> blist;
	
	for(int i=0; i<n; i++){
		if(sw[i].b >= maxa){
			blist.push_back(sw[i].b);
//cout<<sw[i].b<<endl;
	}}
	sort(blist.begin(), blist.end(),greater<int>());
//cout<<"#"<<endl;	
	int ans=0;
	while(blist.size()>=1 && h>0){
		h-=blist[0];
		blist.erase(blist.begin());
		ans+=1;
	}
	
	if(h>0){
		ans += (h+maxa-1)/maxa;
	}
	
	cout << ans << endl;
	return 0;
}
	


Measured memory_bytes: 1660
/*
 * AOJ 0118: Property Distribution
 * ?¢???????m???n??????????????±3?§???????????????????????§??????????????????¶???????????¶?????±????°?????????????
 * ?±???????DFS?????°??????????´¢??????BFS?????¶??\??????
 * ??????????????????????????????????????????4???????????\??¢?????\???????§????????????§????????????????????????????????°?????????
 */

#include <cstdio>
#include <iostream>

using namespace std;

char mat[102][102];
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
int m, n;
int ans;

void dfs(int x, int y) {
  char t = mat[x][y];
  mat[x][y] = '.';
  for (int i = 0; i < 4; ++i) {
    int xx = x + dx[i];
    int yy = y + dy[i];
    if (xx >= 0 && xx < m && yy >= 0 && yy < n && mat[xx][yy] == t) {
      dfs(xx, yy);
    }
  }
}

void solve() {
  ans = 0;
  for (int i = 0; i < m; ++i) {
    cin >> mat[i];
  }
  for (int i = 0; i < m; ++i) {
    for (int j = 0; j < n; ++j) {
      if (mat[i][j] != '.') {
        ++ans;
        dfs(i, j);
      }
    }
  }
}

int main() {
  while (cin >> m >> n && n > 0 && m > 0) {
    solve();
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 3544
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
#define endl "\n"
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();
// freopen("input.txt", "r", stdin);

int main() {
    int r, g;
    cin >> r >> g;
    cout << g*2 - r << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define dhoom ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);  
typedef long long ll;
typedef long double ld;
const ll inf = 1e18;
const int nax = 2e6 + 7;
const ll mod = 1e9 + 7;
//ll tree[4 * nax];
//9uS-22RSwk7gQqh
int count(ll x){
	int cnt = 0;
	while(x != 0){
		cnt++;
		x /= 10;
	}
	return cnt;
}
int main()
{
	int a , b , w;
	cin >> w >> a >> b;
	if(a + w <= b)
		cout << abs(b - a - w) << endl;
	else if(b + w <= a)
		cout << abs(a - b - w) << endl;
	else 
		cout << 0 << endl;
	
	return 0;
	
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef pair<int, int>P;
#define PI 3.14159265359
#define MOD 1000000007
const int MAX =510000;
int main(){
  	ll a,b,n;
  	cin >>a>>b>>n;
  	ll ans=0;
  	if(b<=n){
    	ans=(a*(b-1))/b;	
    }
  	else{
    	ans=(a*n)/b;
    }
  	cout<<ans<<endl;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int i,x;
    string p;
 map<string,int>mp;
 string a[2];
 for(i=0;i<2;i++)
 {
     cin>>a[i];
 }
  for(i=0;i<2;i++)
  {
      cin>>x;
      mp[a[i]]=x;
  }
  cin>>p;
  mp[p]--;
  for(i=0;i<2;i++)
  {
      cout<<mp[a[i]]<<" ";
  }

return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include <cmath>
#include <tuple>
#include <bitset>
#include <utility>
#include <climits>
#include <iomanip>

#define push emplace_back
#define each(i, x) for (auto i=0; i < x; i++)
using ull = unsigned long long;
constexpr auto mod = 1000000007;
constexpr auto INF = ULLONG_MAX;

using namespace std;
template <typename T> inline void dump(const T& x) { cout << "[" << x << "]" << endl; }
template <typename T> inline void dump(const vector<T>& x) { for (const auto v : x) { cout << v << " "; } cout << endl; }
template <typename T> inline void sort_asc(vector<T>& x) { std::sort(x.begin(), x.end()); }
template <typename T> inline void sort_desc(vector<T>& x) { std::sort(x.begin(), x.end(), greater<T>()); }
template <typename T> inline T max_value(vector<T>& x) { return *max_element(x.begin(), x.end()); }
template <typename T> inline T min_value(vector<T>& x) { return *min_element(x.begin(), x.end()); }
template <typename T> inline T sum_value(vector<T>& x) { return accumulate(x.begin(), x.end(), 0ULL); }

int main() {
  ull m1, d1, m2, d2;
  cin >> m1 >> d1 >> m2 >> d2;

  if (m1 == 1 || m1 == 3 || m1 == 5 || m1 == 7 || m1 == 8 || m1 == 10 || m1 == 12) {
    if (d1 == 31) {
      cout << 1 << endl;
    } else {
      cout << 0 << endl;
    }
  } else if (m1 == 4 || m1 == 6 || m1 == 9 || m1 == 11) {
    if (d1 == 30) {
      cout << 1 << endl;
    } else {
      cout << 0 << endl;
    }
  } else {
    if (d1 == 28) {
      cout << 1 << endl;
    } else {
      cout << 0 << endl;
    }
  }


  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#define H 12
#define W 12

void Move(int i,int j,int movex[],int movey[],char data[H][W]){
  int k;
  if (0<=j && j<W && 0<=i && i<H){
    if (data[i][j]=='0')
      return ;
    else
      data[i][j]='0';
  }else
    return ;

  for (k=0;k<4;k++)
    Move(i+movey[k],j+movex[k],movex,movey,data);
}

int main(){
  int i,j;
  int movex[]={0,0,1,-1},movey[]={-1,1,0,0};
  char data[H][W];
  while (1){
    for (i=0;i<H;i++)
      if (scanf("%s",&data[i])==EOF) return 0;
    int cnt=0;
    for (i=0;i<H;i++)
      for (j=0;j<W;j++)
        if (data[i][j]=='1'){
          cnt++;
          Move(i,j,movex,movey,data);
        }
  printf("%d\n",cnt);
  }
}

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

int main() {
    int N;
    cin >>N;
    vector<pair<pair<string,int>,int>> p(N);
    for (int i=0;i<N;i++){
        string s;
        int t;
        cin >>s>>t;
        p[i]=make_pair(make_pair(s,-t),i+1);
    }
    sort(p.begin(),p.end());
    for(auto a:p)cout<<a.second<<endl;
}

Measured memory_bytes: 256
#include<string>
#include<iostream>
#include<algorithm>
#include<set>
#include<math.h>
#include<vector>
#include<sstream>
#include<queue>
#include<functional>
#include<bitset>
#include<cstdio>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include <string.h>
using ll = long long;

#define rep(i, n) for(ll i = 0; i < (int)(n); i++)
#define reps(i,x) for(ll i=1;i<=(int)(x);i++)
#define rrep(i,x) for(ll i=((int)(x)-1);i>=0;i--)
#define rreps(i,x) for(ll i=(int)(x);i>0;i--)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define vll vector<ll>
#define vi vector<int>
#define mp make_pair
#define vpll vector<pair<ll,ll>>
#define vpi vector<pair<int,int>>
#define mod 1000000007 
using namespace std;
ll n, m;
int main() {
	string s;
	cin >> s;
	ll ans = 0;
	rep(i, 1 << (s.size() - 1)) {
		string t = "";
			t = s[0];
			rep(k, s.size()-1) {
				if ((i >> k)&1) {
					ans += stoll(t);
					t = s[k+1];
				}
				else {
					t += s[k+1];
				}
			}
			ans += stoll(t);
	}
	cout << ans << endl;
	return 0;
}

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

using namespace std;

inline void Boost() {
	ios::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
}
typedef long long int ll;
typedef long double ld;

int main() {
	Boost();

	int n;
	cin >> n;

	int v[4] = {0};
	for(int i = 3; i >= 0; --i, n /= 10) v[i] = n % 10;

	if((v[0] == v[1] && v[1] == v[2]) || (v[1] == v[2] && v[2] == v[3])) {
		cout << "Yes";
	} else {
		cout << "No";
	}
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using lli = long long int;

int main(){
	int n, W, V = 0;
	cin >> n >> W;
	vector<int> w(n), v(n);
	for(int i = 0; i < n; ++i){
		cin >> w[i] >> v[i];
		V += v[i];
	}

	vector<vector<int>> mem(n+1, vector<int>(V+1, -1));
	function<int(int, int)> dp = [&](int pos, int rem){
		if(rem <= 0) return 0;
		if(pos == n) return 1<<30;
		if(mem[pos][rem] != -1) return mem[pos][rem];
		int ans = min(dp(pos + 1, rem), w[pos] + dp(pos + 1, rem - v[pos]));
		return mem[pos][rem] = ans;
	};

	for(int i = V; i >= 0; --i){
		if(dp(0, i) <= W){
			cout << i << "\n";
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 40192
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/range/adaptor/reversed.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
typedef long long int ll;

#define PI (acos(-1))
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define dumparr(x) cerr << #x ; for(auto elem: x){cerr << " " << elem;} cerr << endl;
#define dumppairs(x) cerr << #x ; for(auto elem: x){cerr << "(" << elem.first << " " << elem.second << ") ";} cerr << endl;
#define dumpline cerr << "**********************" << endl;
#define dumpwline(x) cerr << "******** " << #x << "=" << (x) << " ********" << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

vector <ll> next_runrun(vector<ll> runrun){
    REP(i, runrun.size()){
        if ((runrun[i] <= runrun[i+1]) && (runrun[i] < 9)){
            runrun[i] += 1;
            for(int j=i-1; j>=0; j--){
                runrun[j] = max(ll(0), runrun[j+1] - 1);
            }
            return runrun;
        }
    }
    if (runrun[runrun.size()-1] == 9){
        vector <ll> ret;
        REP(i, runrun.size()){
            ret.push_back(0);
        }
        ret.push_back(1);
        return ret;
    } else {
        runrun[runrun.size()-1] += 1;
        for(int j=runrun.size()-2; j>=0; j--){
            runrun[j] = max(ll(0), runrun[j+1] - 1);
        }
        return runrun;
    }
}

int main(void){
    ll n; cin >> n;
    vector <ll> first = {1};
    REP(i, n-1){
        first = next_runrun(first);
    }
    REP(i, first.size()){
        cout << first[first.size()-1-i];
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
# C

import sys
from collections import defaultdict, deque
from heapq import heappush, heappop
import math
import bisect
input = sys.stdin.readline

# 再起回数上限変更
# sys.setrecursionlimit(1000000)

n = int(input())
p = list(map(int, input().split()))

prev = p[0]
ans = 0
for p in p[1:]:
    diff = max(prev - p, 0)
    # print(diff)
    ans += diff
    prev = p + diff

print(ans)


Measured memory_bytes: 91816
#include<iostream>
#include <math.h>
#include <string>
#include <iomanip>
using namespace std;

int main(){
	string a;
	string b;
	string c;
	//string winner;
	int ia, ib, ic,n;
	cin >> a >> b >> c;
	ia = 0; ib = 0;; ic = 0; n = 0;
	while (1){
		
		if (n == 0){
			if (a[ia] == 'a'){
				n = 0;
			}
			else if (a[ia] == 'b'){
				n = 1;
			}
			else if (a[ia] == 'c'){
				n = 2;
			}
			else if (a[ia] == '\0'){
				cout << "A" << endl;
				break;
			}
			ia++;
		}
		else if (n == 1){
			if (b[ib] == 'a'){
				n = 0;
			}
			else if (b[ib] == 'b'){
				n = 1;
			}
			else if (b[ib] == 'c'){
				n = 2;
			}
			else if (b[ib] == '\0'){
				cout << "B" << endl;
				break;
			}
			ib++;
		}else if(n == 2){
			if (c[ic] == 'a'){
				n = 0;
			}
			else if (c[ic] == 'b'){
				n = 1;
			}
			else if (c[ic] == 'c'){
				n = 2;
			}
			else if (c[ic] == '\0'){
				cout << "C" << endl;
				break;
			}
			ic++;
		}


	}

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main { 
  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    int N = in.nextInt();
    int[] numbers = new int[N];
    for (int i = 0; i < N; i++) {
      numbers[i] = in.nextInt();
    }
    int count = bubbleSort(numbers);
    trace(numbers);
    System.out.println(count);
  }
  
  public static int bubbleSort(int[] array) {
    int count = 0;
    for (int i = 0; i < array.length; i++) {
      for (int j = array.length - 1; j >= i + 1; j--) {
        if (array[j] < array[j - 1]) {
          swap(array, j, j - 1);
          count++;
        }
      }
    }
    return count;
  }
  
  public static void swap(int[] array, int p, int q) {
    int temp = array[p];
    array[p] = array[q];
    array[q] = temp;
  }
  
  public static void trace(int[] array) {
    StringBuilder output = new StringBuilder();
    for (int i = 0; i < array.length; i++) {
      output.append(array[i]);
      if (i != array.length -1) output.append(" ");
    }
    System.out.println(output.toString());
  }
}

Measured memory_bytes: 18148
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define N 100000
typedef long long ll;
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) int(x.size())
#define OUT(a) cout<<(a)<<endl
typedef pair<int,int> P;
#define INF 1000000
const int MAX = 1000000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
// 二項係数計算 COMinit()を先に使用すること
long long COM(int n, int k){
	if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int main(){
	int x,y;
    cin>>x>>y;
    ll ans=0;
    if((2*x-y)%3==0&&(2*x-y)>=0&&(2*y-x)>=0){
        int s=(2*x-y)/3;
        int t=(2*y-x)/3;
        COMinit();
        ans=COM(s+t,s);
    }
    OUT(ans);
	return 0;
}

Measured memory_bytes: 23680