akhauriyash/Code-Regression huggingface dataset:
import  java.util.*;

public class Main{
  public static void main(String[]args){
    Scanner sc = new Scanner(System.in);
    
    String[] s = sc.nextLine().split(" ");
    int H = Integer.parseInt(s[0]);
    int W = Integer.parseInt(s[1]);
    
    int[][] route = new int[H][W];
    int dots = 0;
    for(int i = 0; i < H; i++){
      String str = sc.nextLine();
      for(int j = 0; j < W; j++){
        char c = str.charAt(j);
        if(i == 0 && j == 0){
          route[i][j] = 1;
          dots++;
        }else if(c == '.'){
          route[i][j] = 0;
          dots++;
        }else{
          route[i][j] = -1;
        }
      } 
    }
    
    int[] ih = {+1, 0, -1, 0};
    int[] iw = {0, +1, 0, -1};
    
    Queue<Integer> qh = new ArrayDeque<>();
    Queue<Integer> qw = new ArrayDeque<>();
    qh.add(0);
    qw.add(0);
    boolean flag = false;
    
    while(qh.size() > 0){
      int nh = qh.poll();
      int nw = qw.poll();
      
      if(nh == H - 1 && nw == W - 1){
        flag = true;
        break;
      }
      
      for(int i = 0; i < 4; i++){
        int fh = nh + ih[i];
        int fw = nw + iw[i];
        
        if(fh >= 0 && fw >= 0 && fh < H && fw < W && route[fh][fw] == 0){
          qh.add(fh);
          qw.add(fw);
          route[fh][fw] = route[nh][nw] + 1;
        }
      }
    }
    
    if(flag){
      System.out.println(dots - route[H-1][W-1]);
    }else{
      System.out.println(-1);
    }
  }
}

Measured memory_bytes: 22996
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	max := 0
	ans := 0
	h := 0
	for i := 0; i < n; i++ {
		fmt.Scan(&h)
		if h >= max {
			max = h
			ans++
		}
	}
	fmt.Println(ans)
}


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

using namespace std;

int main(){
    int N;
    int dummy;
    int count=0;
    int A_sum=0, B_sum=0;
    priority_queue<int> a;
    
    cin >> N;
    for(int i=0;i<N;i++){
        cin >> dummy;
        a.push(dummy);
    }
    
    while(!a.empty()){
        if(count%2 == 0){
            A_sum += a.top();
            a.pop();
        }
        else if(count%2 == 1){
            B_sum += a.top();
            a.pop();
        }
        count++;
    }
    
    cout << A_sum-B_sum << endl;
    
    return 0;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt();
			int[] h = new int[n];
			IntStream.range(0, n).forEach(i -> h[i] = scanner.nextInt());
			System.out.println(getResult(h, 0, n - 1, 0));
		}
	}

	/**
	 * 条件を満たすような最小の「水やり」操作の回数を計算する
	 * 
	 * @param h       希望する高さの配列
	 * @param from    処理対象indexのfrom
	 * @param to      処理対象indexのfrom
	 * @param current 現在の高さ
	 * @return
	 */
	private static int getResult(final int[] h, int from, int to, int current) {
		if (from > to) {
			return 0;
		}
		if (from == to) {
			return h[from] - current;
		}
		List<Integer> minIndexes = new ArrayList<>();
		int min = Integer.MAX_VALUE;
		// 最小値とそのindexを計算する
		for (int i = from; i <= to; i++) {
			if (min > h[i]) {
				minIndexes.clear();
				min = h[i];
				minIndexes.add(i);
			}
		}
		int answer = 0;
		int prev = from - 1;
		for (int index : minIndexes) {
			answer += getResult(h, prev + 1, minIndexes.get(0) - 1, min);
			prev = index;
		}
		answer += getResult(h, prev + 1, to, min);
		return answer + min - current;
	}
}


Measured memory_bytes: 36292
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const long double EPS=1e-9;
const long double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
long double ABS(long double a){return max(a,-a);}
int G[510];
int K[510];
int main(){
	int a;scanf("%d",&a);
	if(a==1){
		printf("1\n1\n");return 0;
	}
	for(int i=2;i<=500;i+=2){
		if(i*2>=a){
			for(int j=0;j<a;j++){
				if(j<i)G[j]=K[j]=j;
				else K[j-i]=j;
			}
			printf("%d\n",i);
			for(int j=0;j<i;j++){
				for(int k=0;k<i;k++){
					if(k)printf(" ");
					if(j%2)printf("%d",K[(j+k)%i]+1);
					else printf("%d",G[(j+k)%i]+1);
				}
				printf("\n");
			}
			return 0;
		}
	}
}


Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
int a[114514];
signed main(){
	int n;cin>>n;
	rep(i,n)cin>>a[i];
	sort(a,a+n);
	int ans=0;
	int now=a[0],num=0;
	rep(i,n+1){
		if(a[i]==now){
			num++;
			}
		else{
			if(num>=now){
				ans+=num-now;
				}
			else{
				ans+=num;
				}
			num=1;now=a[i];	
			}	
		}
		cout<<ans<<endl;
	}


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

using ll = long long;

using namespace std;

int main() {
    int n;
    cin >> n;
    ll a = 0, b = 1;
    int q[n], x[n];
    for (int i=0; i<n; i++) cin >> q[i] >> x[i];
    reverse(q, q+n);
    reverse(x, x+n);
    for (int i=0; i<n; i++) {
        if (q[i] == 1) b *= x[i];
        else if (q[i] == 2) a -= b * x[i];
        else a += b * x[i];
    }
    cout << a << ' ' << b << '\n';
    return 0;
}


Measured memory_bytes: 3116
#include <stdio.h>

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


Measured memory_bytes: 2024
N = gets.chomp.to_i
cs, ss, fs = [], [], []
(N - 1).times do |i|
    cs[i], ss[i], fs[i] = gets.chomp.split.map(&:to_i)
end

N.times do |i|
    sum = 0
    (i..(N-2)).each do |j|
        if sum < ss[j]
            sum = ss[j]
        else
            sum += fs[j] - 1
            sum -= sum % fs[j]
        end
        sum += cs[j]
    end
    print sum, "\n"
end

Measured memory_bytes: 1916
#include <iostream>
using namespace std;
int main(){
    int w,h;
    string c;
    cin>>w>>h>>c;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if((i==0 && j==0) || (i==0 && j==w-1) || (i==h-1 && j==0) || (i==h-1 && j==w-1)) cout<<"+";
            else if((i!=0 && i!=h-1 && j==0) || (i!=0 && i!=h-1 && j==w-1))cout<<"|";
            else if((i==0 && j!=0 && j!=w-1) || (i==h-1 && j!=0 && j!=w-1))cout<<"-";
            else if(i==h/2 && j==w/2)cout<<c;
            else cout<<".";
        }
    cout<<endl;
    }
    return 0;
}



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

int main() {
  int n,k,q;
  cin >> n >> k >> q;
  vector<int> win(n);

  for (int i=0; i<q; i++){
    int winner;
    cin >> winner;
    win.at(winner-1) += 1;
  }
  
  for (int i=0; i<n; i++){
    int point;
    point = k - (q - win.at(i));
    if (point >= 1){
      cout << "Yes";
    }
    else{
      cout << "No";
    }
      cout << endl;
    
  }
}


Measured memory_bytes: 1024
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using lpair = pair<ll, ll>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i=(m);i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i>=(n);i--)
#define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
void print() {}
template <class H,class... T>
void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll H,W;
    cin >> H >> W;
    string S[110];
    rep(i,0,H) cin >> S[i];
    ll dp[110][110] = {};
    rep(i,0,H+1){
        rep(j,0,W+1){
            dp[i][j] = INF;
        }
    }
    if(S[0][0] == '#'){
        dp[0][0] = 1;
    }else{
        dp[0][0] = 0;
    }

    rep(i,0,H){
        rep(j,0,W){
            if(i+1 < H){
                if(S[i][j] == '.' && S[i+1][j] == '#'){
                    dp[i+1][j] = min(dp[i+1][j], dp[i][j] + 1);
                }else{
                    dp[i+1][j] = min(dp[i+1][j], dp[i][j]);
                }
            }
            if(j+1 < W){
                if(S[i][j] == '.' && S[i][j+1] == '#'){
                    dp[i][j+1] = min(dp[i][j+1], dp[i][j] + 1);
                }else{
                    dp[i][j+1] = min(dp[i][j+1], dp[i][j]);
                }             
            }

        }
    }
    print(dp[H-1][W-1]);
    

}

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

const int RLEN=1<<18|1;
inline char nc() {
	static char ibuf[RLEN],*ib,*ob;
	(ib==ob) && (ob=(ib=ibuf)+fread(ibuf,1,RLEN,stdin));
	return (ib==ob) ? -1 : *ib++;
}
inline int rd() {
	char ch=nc(); int i=0,f=1;
	while(!isdigit(ch)) {if(ch=='-')f=-1; ch=nc();}
	while(isdigit(ch)) {i=(i<<1)+(i<<3)+ch-'0'; ch=nc();}
	return i*f;
}

const int N=17, mod=1e9+7;
inline int add(int x,int y) {return (x+y>=mod) ? (x+y-mod) : (x+y);}
inline int mul(int x,int y) {return (long long)x*y%mod;}
inline int pct(int x) {return __builtin_popcount(x);}
int n,m,g[N],bin[N],f[1<<N];
inline int valid(int s1,int al) {
	if((s1&1) && (s1&2)) return 0;
	int s2=(bin[n]-1)^al, sum=1;
	for(int j=0;j<n;j++) if(s2&bin[j]) {
		if(!(s1&g[j])) return 0;
		int c=pct(s1&g[j]);
		sum=mul(sum,bin[c]-1);
	} 
	for(int j=0;j<n;j++) if(s1&bin[j]) {
		int c=pct(s2&g[j]);
		sum=mul(sum,bin[c]);
	}
	return sum;
}
int main() {
	n=rd(), m=rd();
	for(int i=0;i<=n;i++) bin[i]=1<<i;
	for(int i=1;i<=m;i++) {
		int x=rd()-1, y=rd()-1;
		g[x]|=bin[y];
	}
	f[0]=1;
	for(int s=1;s<bin[n];++s) {
		for(int s2=s;s2;s2=(s2-1)&s) {
			int t=valid(s2,s);
			if(t) f[s]=add(f[s],mul(f[s^s2],t));
		}
	}
	cout<<f[bin[n]-1]<<'\n';
}

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

#define fi first
#define se second
#define mp make_pair
#define pb push_back

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

const int maxn = 1e5 + 5;

int N, M;
int par[maxn], deg[maxn];
vector<int> adj[maxn];

signed main(void)
{
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  if (fopen("A.INP", "r")){
    freopen("A.INP", "r", stdin);
    freopen("A.OUT", "w", stdout);
  }
  cin >> N >> M;
  for (int i = 1; i <= N + M - 1; ++i){
    int u, v; cin >> u >> v;
    adj[u].pb(v); ++deg[v];
  }
  vector<int> topo;
  for (int i = 1; i <= N; ++i){
    if (deg[i] == 0){
      topo.pb(i);
    }
  }
  int cur = 0;
  while (cur < topo.size()){
    int u = topo[cur++];
    for (int v : adj[u]){
      --deg[v];
      if (deg[v] == 0){
        par[v] = u;
        topo.pb(v);
      }
    }
  }
  for (int i = 1; i <= N; ++i) cout << par[i] << '\n';
}


Measured memory_bytes: 7672
#include <iostream>
#include <string>
#include <stddef.h>
#include <stack>
#include <queue>

using namespace std;

int main() {
	int w, h, x, y, r;
	cin >> w >> h >> x >> y >> r;
	if (x >= r&&y >= r&&x <= w - r&&y <= h - r) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 1160
#include<iostream>
#include<string.h>
using namespace std;
int main()
{
	char x1[20],x2[20],x3[20];
	int x,y;
	cin>>x1;
	cin>>x2;
	//getline(cin,x2);
	cin>>x>>y;
	cin>>x3;
	if(strcmp(x3,x1)==0)
	x--;
	else 
	y--;
	cout<<x<<" "<<y;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<vector>
#define Inf 1000000007
using namespace std;
int  fun(int i,int j,vector<vector<int>>&v,int dp[100000][3])
{
    ///base case
    if(i==-1)
    return 0;

    if(dp[i][j]!=0)
    return dp[i][j];

    ///rec case

        for(int k=0;k<3;k++)
        {
            if(j==k)
            continue;
            dp[i][j]=max(v[i][j]+fun(i-1,k,v,dp),dp[i][j]);
        }
        return dp[i][j];
}
 
int main()
{
    int n;
    cin>>n;
    vector<vector<int>>v;
    v.resize(n);
    for(int i=0;i<n;i++)
    v[i].resize(3);
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<3;j++)
        {
            cin>>v[i][j];
        }
    }
    int dp[100000][3];
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<3;j++)
        {
            dp[i][j]=0;
        }
    }
    cout<<max(fun(n-1,0,v,dp),max(fun(n-1,1,v,dp),fun(n-1,2,v,dp)))<<endl;
    return 0;
}

Measured memory_bytes: 19360
#include <bits/stdc++.h>
using namespace std;
// for(long long i = 0;i < num; i++){}
int main() {
    //
    long long num;
    long long cnt = 0;

    cin >> num;

    vector<long long> A(num);
    vector<long long> B(num);
    vector<long long> over;
    vector<long long> nEnough;

    for (int i = 0; i < num; i++) cin >> A.at(i);

    for (int i = 0; i < num; i++) {
        long long tmp;
        cin >> tmp;
        B.at(i) = tmp;

        if (A.at(i) > B.at(i))
            over.push_back(A.at(i) - B.at(i));
        else if (A.at(i) < B.at(i))
            nEnough.push_back(B.at(i) - A.at(i));
    }

    sort(over.rbegin(), over.rend());

    long long tmp2;
    long long lastIndex = -1;
    for (int i = 0; i < nEnough.size(); i++) {
        tmp2 = nEnough.at(i);
        cnt++;
        for (int j = 0; j < over.size(); j++) {
            if (over.at(j) == 0) continue;
            
            if (tmp2 <= over.at(j)) {
                over.at(j) -= tmp2;
                tmp2 = 0;
                if (lastIndex == -1) {
                    lastIndex = j;
                    cnt++;
                } else {
                    if (lastIndex != j) {
                        cnt++;
                        lastIndex = j;
                    }
                }
                break;
            } else {
                tmp2 -= over.at(j);
                over.at(j) = 0;
                if (lastIndex == -1) {
                    lastIndex = j;
                    cnt++;
                } else {
                    if (lastIndex != j) {
                        cnt++;
                        lastIndex = j;
                    }
                }
            }
        }

        if (tmp2 > 0) {
            cout << -1;
            return 0;
        }
    }

    cout << cnt;
    //
}


Measured memory_bytes: 5888
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPLL(i, n) for (ll i = 0; i < (ll)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;

// 必ず働く日にちを全列挙する問題
// K日働くことができるかどうか → 貪欲法(左端から選んでいく。それでK日選べなかったら絶対に無理)
// 1, 2, 3, …, Kと書けるかどうか。書けるなら可能、書けないなら不可能。
// 元々K日働くことが可能なケースで、働ける特定のある日を働けない日としたとき不可能となったのなら、その日は必ず働く日になる
// 左端から貪欲で詰めていった場合、右端から貪欲で詰めていった場合をそれぞれ計算する。
// 左端から詰めていって書いた番号と、右端から詰めていって書いた番号が一致する場合、その日は必ず働く日になる。
// 左からの貪欲と右からの貪欲で解ける。

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, K, C; cin >> N >> K >> C;
  string S; cin >> S;
  vector<int> L(N, 0);
  vector<int> R(N, -1);
  int l = -1, r = N;
  int cntL = 1, cntR = K;
  REP(i, N){
    if(S[i] == 'o' && i > l){
      L[i] = cntL;
      l = i + C;
      cntL++;
    }
    if(S[N-1-i] == 'o' && N-1-i < r){
      R[N-1-i] = cntR;
      r = (N-1-i) - C;
      cntR--;
      if(cntR ==  0) cntR--;
    }
  }
  vector<int> ans;
  REP(i, N){
    if(L[i] == R[i]){
      ans.push_back(i+1);
    }
  }
  for(auto &i : ans){
    cout << i << endl;
  }
}

Measured memory_bytes: 5980
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define REP(i, b, n) for (Int i = b; i < Int(n); i++)
#define rep(i, n) REP(i, 0, n)
using namespace std;
using Int = long long;
Int inf = 1000000000000000001LL;
using vi = vector<Int>;
using vvi = vector<vi>;
using mapis = unordered_map<Int,string>;
using mapii = unordered_map<Int,Int>;
using pii = pair<Int,Int>;

Int GCD(Int a, Int b){
    if(b==0) return a;
    if(a < b) return GCD(b, a);
    unsigned r;
    while ((r=a%b)) {
        a = b;
        b = r;
    }
    return b;
}
Int printX(Int r, Int D, Int X, int count){
    if(count == 10){
        return 0;
    }
    Int nextX = r*X - D;
    cout<< nextX <<endl;
    printX(r,D,nextX,count+1);

}

int myPow(int x, int p) {
    if (p == 0) return 1;
    if (p == 1) return x;
    return x * myPow(x, p-1);
}

int main() {
    Int N,K;
    cin >> N >>K;
    Int ans = 0;
    vi h = vi(N);
    rep(i,N){
        int tmp;
        cin >> tmp;
        if(tmp>=K){
            ans++;
        }
    }




    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
#define MAXN 100000 
#define LL long long
int n,m,ans;
LL w[MAXN+5];
int fa[MAXN+5],cnt[MAXN+5];
struct edge{
	int u,v,w;
}a[MAXN+5];
bool cmp(edge s1,edge s2){return s1.w<s2.w;}
int xfind(int x){return (fa[x]==x)?x:fa[x]=xfind(fa[x]);}
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
	{scanf("%lld",&w[i]);fa[i]=i;}
	for(int i=1;i<=m;i++)
		scanf("%d%d%d",&a[i].u,&a[i].v,&a[i].w);
	sort(a+1,a+m+1,cmp);
	for(int i=1;i<=m;i++)
	{
		int x=xfind(a[i].u),y=xfind(a[i].v);
		if(x!=y)
		{
			w[x]+=w[y];
			cnt[x]+=cnt[y];
			w[y]=0,cnt[y]=0;
			fa[y]=x;
		}
		cnt[x]++;
		if(w[x]>=a[i].w)
		{
			ans+=cnt[x];
			cnt[x]=0;
		}
	}
	printf("%d",m-ans);
}

Measured memory_bytes: 2944
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
//#include<boost/multiprecision/cpp_int.hpp>
//#include<boost/multiprecision/cpp_dec_float.hpp>
//namespace mp=boost::multiprecision;
//#define mulint mp::cpp_int
//#define mulfloat mp::cpp_dec_float_100
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
constexpr int MOD=1000000007;
//constexpr int MOD=998244353;
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcountll(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
#define fi first
#define se second
typedef long long lint;
int dx[8]={1,1,0,-1,-1,-1,0,1};
int dy[8]={0,1,1,1,0,-1,-1,-1};
const int MAX_N=2e5+5;
//struct edge{lint to,num;};

vector<int> edge[MAX_N];
bool reach[MAX_N];
int ans[MAX_N];

int main(void){
    int N,X,Y;
    cin >> N >> X >> Y;
    X--,Y--;
    for(int i=0;i<N;i++) for(int j=i+1;j<N;j++){
        int dis=j-i;
        int cmp=abs(i-X)+1+abs(Y-j);
        cmp=min(cmp,abs(i-Y)+1+abs(X-j));
        dis=min(dis,cmp);
        ans[dis]++;
    }
    for(int i=1;i<N;i++) cout << ans[i] << endl;
}

Measured memory_bytes: 8304
#include<bits/stdc++.h>
#define mem0(a) memset(a,0,sizeof(a))  
#define meminf(a) memset(a,0x3f,sizeof(a))  
using namespace std;  
typedef long long ll;  
typedef long double ld;  
typedef double db;  
const int maxn=200005,inf=0x3f3f3f3f;    
const ll llinf=0x3f3f3f3f3f3f3f3f;     
const ld pi=acos(-1.0L);  
vector<int> v[maxn]; 
int main() {  
    int n,m,i,j,l,r;  
    scanf("%d%d",&n,&m);  
    priority_queue<int,vector<int>,greater<int> > pq;  
    for (i=1;i<=n;i++) {  
        scanf("%d%d",&l,&r);  
        if (l==0) pq.push(r); else v[l].push_back(r);  
    }  
    for (i=1;i<=m+1;i++) {  
        sort(v[i].begin(),v[i].end());  
    }  
    int pos=-1;  
    for (i=1;i<=m;i++) {
        if (v[i].size()>1) {
            for (j=0;j<v[i].size()-1;j++) pq.push(v[i][j]);  
        } else if (v[i].size()==0) {
            if (!pq.empty()) {
                if (pq.top()<=i) pq.pop(); else {  
                    pos=max(pos,i);  
                    while (!v[pos].size()&&pos<=m) pos++;  
                    if (v[pos].size()) v[pos].pop_back();  
                }    
            } else {
                pos=max(pos,i);
                while (!v[pos].size()&&pos<=m) pos++;
                if (v[pos].size()) v[pos].pop_back();
            }
        }
    }
    int ans=pq.size();
    printf("%d\n",ans); 
    return 0;
}

Measured memory_bytes: 8960
#include <stdlib.h>
#include <iostream>
#include <climits>
using namespace std;

struct weight{
	int val;
	int id;
	weight(){
		val = 0;
		id  = 0;
	}
	weight(weight *w){
		val = w->val;
		id  = w->id;
	}
	void set(weight *w){
		val = w->val;
		id  = w->id;
	}
};

void merge_sort(weight *array, int left, int right);
void merge(weight *array, int left, int mid, int right);
void swap(weight *a, weight *b);
int cal_min_swap(weight *original, weight *sorted, int num);
int linear_search(weight *array, int size, int num);

int main(){
	int n;

	cin >> n;

	weight* original = (weight*)malloc(n * sizeof(weight));
	weight* sorted   = (weight*)malloc(n * sizeof(weight));
	int result = 0;

	if(n < 1){
		return 0;
	}

	for(int i = 0; i < n; i++){
		cin >> original[i].val;
		original[i].id = i;
		sorted[i].set(&original[i]);
	}

	merge_sort(sorted, 0, n);
	cout << cal_min_swap(original, sorted, n) << endl;
	return 0;
}

void merge_sort(weight *array, int left, int right){
	if(left+1 < right){
		int mid = (left + right) >> 1;
		merge_sort(array, mid, right);
		merge_sort(array, left, mid);
		merge(array, left, mid, right);
	}

}

void merge(weight *array, int left, int mid, int right){
	int n1 = mid - left;
	int n2 = right - mid;

	weight* L = (weight*)malloc((n1+1) * sizeof(weight));
	weight* R = (weight*)malloc((n2+1) * sizeof(weight));

	for(int i = 0; i < n1; ++i){
		L[i].set(&array[left+i]);
	}
	L[n1].val = INT_MAX;
	for(int i = 0; i < n2; ++i){
		R[i].set(&array[mid+i]);
	}
	R[n2].val = INT_MAX;

	int i = 0;
	int j = 0;
	for(int k = left; k < right; ++k){
		if(L[i].val <= R[j].val){
			array[k].set(&L[i]);
			++i;
		}else{
			array[k].set(&R[j]);
			++j;
		}
	}
}

void swap(weight *a, weight *b){
	weight *temp = new weight(b);
	b->set(a);
	a->set(temp);
	free(temp);
}

int cal_min_swap(weight *original, weight *sorted, int num){
	int total_swap_w = 0;
	int temp_i = 0;
	bool is_swap = false;
	int swap_num = 0;
	int min = sorted[0].val;
	int this_min = 0;
	int this_total_swap_num = 0;
	string test;
	for(int i = 0; i < num; ++i){
		if(original[i].id != sorted[i].id){
			if(!is_swap){
				temp_i = i;
				swap_num = 0;
				this_min = sorted[i].val;
				this_total_swap_num = 0;
			}
			this_total_swap_num += original[i].val;
			int swap_i = linear_search(sorted, num, original[i].val);
			swap(&sorted[i], &sorted[swap_i]);
			i = swap_i - 1;
			is_swap = true;
			swap_num++;
		}else{
			if(is_swap){
				if(swap_num != 1){
					if(min*swap_num + 2*(min + this_min) < this_min*swap_num){
						this_total_swap_num += min*swap_num + 2*(min + this_min);
					}else{
						this_total_swap_num += this_min*swap_num;
					}
				}else{
					this_total_swap_num += this_min;
				}
				total_swap_w += this_total_swap_num;
				this_total_swap_num = 0;
				i = temp_i;
				is_swap = false;
			}
		}
	}
	return total_swap_w;
}
int linear_search(weight *array, int size, int num){
	for(int i = 0; i < size; ++i){
		if(array[i].val == num){
			return i;
		}
	}
	return -1;
}

Measured memory_bytes: 1328
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
using ll = long long;
typedef pair<int, int> P;
ll Mod = 1000000007;
int main() {
  int H,W;
  cin >> H >> W;
  ll p[H];
  ll q[W];
  ll ans = 0;
  for (int i = 0; i < H; i++) {
    cin >> p[i];
    ans += p[i];
  }
  for (int j = 0; j < W; j++) {
    cin >> q[j];
    ans += q[j];
  }

  sort(q,q+W);

  ll sum[W+1];
  sum[0] = 0;
  for (int i = 0; i < W; i++) {
    sum[i+1] = sum[i] + q[i];
  }
  
  for (int i = 0; i < H; i++) {
    int s = lower_bound(q,q+W,p[i]) - q;
    ans += sum[s];
    ans += p[i] * ((ll)W - s);
  }

  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 5932
import java.util.Scanner;
//import java.util.TreeSet;

public class Main {
	
	private static long cnt;

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		// Scanner sc = new Scanner(System.in);
		// int n = sc.nextInt();

		// TreeSet<Integer> all = new TreeSet<Integer>();
		// int cnt = 0;

		// while (n > 0) {
		// int k = sc.nextInt();
		// cnt += (all.tailSet(k)).size();
		// all.add(k);
		// n--;
		// }

		// System.out.println(cnt);

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();

		int[] A = new int[n];

		for (int i = 0; i < n; i++) {
			A[i] = sc.nextInt();
		}

		mergeSort(A, 0, n);

		System.out.println(cnt);

	}

	public static void marge(int[] A, int left, int mid, int right) {
		int n1 = mid - left;
		int n2 = right - mid;

		int[] L = new int[n1 + 1];
		int[] R = new int[n2 + 1];

		for (int i = 0; i < n1; i++) {
			L[i] = A[left + i];
		}
		for (int i = 0; i < n2; i++) {
			R[i] = A[mid + i];
		}

		L[n1] = Integer.MAX_VALUE;
		R[n2] = Integer.MAX_VALUE;

		int i = 0;
		int j = 0;
		for (int k = left; k < right; k++) {
			if (L[i] <= R[j]) {
				A[k] = L[i];
				i++;
			} else {
				A[k] = R[j];
				j++;
				cnt += (n1 - i);
				
				// L[i] > R[i] ?????¨??? R[i]???L???????´?????????????L???????´???°-1-i????????????????°???????
			}

		}
	}

	public static void mergeSort(int[] A, int left, int right) {
		if (left + 1 < right) {
			int mid = (left + right) / 2;
			mergeSort(A, left, mid);
			mergeSort(A, mid, right);
			marge(A, left, mid, right);
		}
	}

}

Measured memory_bytes: 101928
#include<stdio.h>

#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2

void dfs_visit(int);
void dfs(void);

int n,M[N][N];
int color[N],d[N],f[N],tt;

int main(){
  int u,v,k,i,j;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      M[i][j]=0;
    }
  }
  for(i=0;i<n;i++){
    scanf("%d%d",&u,&k);
    u--;
    for(j=0;j<k;j++){
      scanf("%d",&v);
      v--;
      M[u][v]=1;
    }
  }
  dfs();
  return 0;
}

void dfs_visit(int u){
  int v;
  color[u]=GRAY;
  d[u]=++tt;
  for(v=0;v<n;v++){
    if(M[u][v]==0)continue;
    if(color[v]==WHITE){
      dfs_visit(v);
    }
  }color[u]=BLACK;
  f[u]=++tt;
}

void dfs(){
  int u;
  for(u=0;u<n;u++)color[u]=WHITE;
  tt=0;
  for(u=0;u<n;u++){
    if(color[u]==WHITE)dfs_visit(u);
  }
  for(u=0;u<n;u++){
    printf("%d %d %d\n",u+1,d[u],f[u]);
  }
}



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

#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << "\t|";
  __f(comma + 1, args...);
}
 

#define print(x) for(auto it : x) cout<< it << " "; cout << endl;
typedef long long ll;
typedef unsigned long long ull;

vector<vector<int>> subsets(vector<int>& nums) {
    int n = nums.size(), p = 1 << n;
    vector<vector<int>> subs(p);
    for (int i = 0; i < p; i++) {
        for (int j = 0; j < n; j++) {
            if ((i >> j) & 1) {
                subs[i].push_back(nums[j]);
            }
        }
    }
    return subs;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int m, n, k; cin >> m >> n >> k;
    vector<string> v(m);
    for (int i = 0; i < m; i++) {
        cin >> v[i];
    }
    vector<int> row, col;
    for (int i = 0; i < m; i++) {
        row.push_back(i);
    }
    for (int i = 0; i < n; i++) {
        col.push_back(i);
    }
    vector<vector<int>> rows = subsets(row);
    vector<vector<int>> cols = subsets(col);
    int ans = 0;
    for (auto row : rows) {
        for (auto col : cols) {
            int cnt = 0;
            for (int i = 0; i < m; i++) {
                for (int j = 0; j < n; j++) {
                    if (find(row.begin(), row.end(), i) == row.end() && find(col.begin(), col.end(), j) == col.end()) {
                        if (v[i][j] == '#') {
                            cnt++;
                        }
                    }
                }
            }
            if (cnt == k) ans++;
        }
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 3628
#pragma region kyomukyomupurin

/**
 *    author  : 𝒌𝒚𝒐𝒎𝒖𝒌𝒚𝒐𝒎𝒖𝒑𝒖𝒓𝒊𝒏
 *    created : 2020-05-03 20:18:17
 **/

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#include <cmath>
#include <complex>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

using int64 = long long;

template <class T>
using binary_heap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template <class T, class U>
std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) {
  return os << '(' << p.first << ", " << p.second << ')';
}

template <class T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) {
  int flag = 0;
  for (auto e : vec) os << (flag++ ? ", " : "{") << e;
  return os << (vec.empty() ? "{}" : "}");
}

template <class T>
std::ostream& operator<<(std::ostream& os, const std::set<T>& st) {
  int flag = 0;
  for (auto e : st) os << (flag++ ? ", " : "{") << e;
  return os << (st.empty() ? "{}" : "}");
}

template <class T, class U>
std::ostream& operator<<(std::ostream& os, const std::map<T, U>& mp) {
  int flag = 0;
  for (auto e : mp) os << (flag++ ? ", " : "{") << e;
  return os << (mp.empty() ? "{}" : "}");
}

template <class T>
std::istream& operator>>(std::istream& is, std::vector<T>& vec) {
  for (T& e : vec) is >> e;
  return is;
}

#define all(_) begin(_), end(_)
#define rall(_) rbegin(_), rend(_)

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

void debug_out() { std::cerr << '\n'; }

template <class Head, class... Tail>
void debug_out(Head&& head, Tail&&... tail) {
  std::cerr << head;
  if (sizeof...(Tail) != 0) std::cerr << ", ";
  debug_out(std::forward<Tail>(tail)...);
}

#pragma endregion kyomukyomupurin

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

  int n; cin >> n;
  int k; cin >> k;

  map<int, int> mp;

  for (int i = 0; i < k; ++i) {
    int d; cin >> d;
    for (int j = 0; j < d; ++j) {
      int a; cin >> a; --a; ++mp[a];
    }
  }

  cout << n - (int)mp.size() << endl;

  return 0;
}

Measured memory_bytes: 3648
T,A,S = map(int, input().split(' '))

persons = [T, A, S]

def check_even(persons):
    for person in persons:
        if person % 2 != 0:
            return False
    return True

# 1 1 1 の判定を先にするため

# 0回目
if not check_even(persons):
    print(0)
    exit()

# 全数同値 -> 無限
if T == A and A == S:
    print(-1)
    exit()

count = 1

while True:
    for person in persons:
        tmp_0 = persons[0]
        tmp_1 = persons[1]
        tmp_2 = persons[2]

        persons[0] = 0 + tmp_1 / 2 + tmp_2 / 2
        persons[1] = tmp_0 / 2 + 0 + tmp_2 / 2
        persons[2] = tmp_0 / 2 + tmp_1 / 2 + 0

        if check_even(persons):
            count += 1
        else:
            print(count)
            exit()


Measured memory_bytes: 9264
#include <algorithm>
#include <climits>
#include <iostream>
using namespace std;

int main() {
	int N, A, B, ans = INT_MAX, tmp1, tmp2;
	cin >> N;
	for (int i = 1; i <= N / 2; ++i) {
		A = i;
		B = N - i;
		tmp1 = 0;
		tmp2 = 0;
		do {
			tmp1 += A % 10;
		} while (A /= 10);
		do {
			tmp2 += B % 10;
		} while (B /= 10);
		ans = min(ans, tmp1 + tmp2);
	}
	cout << ans;
}

Measured memory_bytes: 256
#include<cstdio>


int main(void)
{
	int a, b;

	while(scanf("%d%d", &a, &b)==2)
	{
		if(a<=8 && b<=8)
		{
			printf("Yay!\n");
		}
		else
		{
			printf(":(\n");
		}
	}

	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int n,k,r,s,p;
string t;
long long res =0;
long long dp[3][100001];
long long cal(string tmp){
    //memset(dp,0,sizeof dp);
    dp[0][0]=0;
    dp[1][0]=0;
    dp[2][0]=0;
    for (int i=1;i<=tmp.size();i++){
        //tmp[i-1]
        // 0,1,2-> R,S,P
        dp[0][i] = max(dp[1][i-1],dp[2][i-1]) + (tmp[i-1]=='s')*r;
        dp[1][i] = max(dp[0][i-1],dp[2][i-1]) + (tmp[i-1]=='p')*s;
        dp[2][i] = max(dp[0][i-1],dp[1][i-1]) + (tmp[i-1]=='r')*p;
    }
    return max(dp[0][tmp.size()],max(dp[1][tmp.size()],dp[2][tmp.size()]));
}
int main(){
    cin>>n>>k>>r>>s>>p;
    cin>>t;
    //cout<<t;

    string tmp;
    int j =0;
    for (int i=0;i<k;i++){
        tmp ="";
         j=0;
         while (i+j*k<n){
            tmp+=t[i+j*k];
            //cout<<i+j*k<<" ";
            j++;
         }
         res+=cal(tmp);
         //cout<<tmp<<" "<<res<<" "<<cal(tmp)<<endl;
    }

    cout<<res<<endl;

}


Measured memory_bytes: 2944
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define range(i,a,n) for(ll i=(a);i<(n);i++)

#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

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

template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S acm(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
void YN(bool b){cout<<(b?"YES":"NO")<<"\n";}
void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";}
void yn(bool b){cout<<(b?"yes":"no")<<"\n";}
int sgn(const double&r){return (r>EPS)-(r<-EPS);} // a>0  : sgn(a)>0
int sgn(const double&a,const double&b){return sgn(a-b);} // b<=c : sgn(b,c)<=0

ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n,k;
	cin>>n>>k;
	vl v(n);
	rep(i,n)cin>>v[i];
	sort(all(v));
	ll ans=0;
	rep(i,n-k)ans+=v[i];
	puta(ans);
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int main(){
  string S; cin >> S;
  int N = S.length();
  bool strong = true;
  for(int i = 0; i < (N - 1) / 2; i++){
    if(S[i] != S[N - 1 - i]){
      strong = false;
      break;
    }
  }
  for(int i = 0; i < (N - 1) / 4; i++){
    if(S[i] != S[(N - 3) / 2 - i]){
      strong = false;
      break;
    }
  }
  if(strong) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

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


int main(){
  int n, y;
  cin >> n >> y;
  y /= 1000;
  int m = y - n;

  if(y==1 || y==2){
    if(y==n) cout << "0 0 " << n << endl;
    else cout << "-1 -1 -1" << endl;
  }
  else{
    int l = ceil(2.0/9.0*m);
    int a = m - 4*l;
    int b = -2*m + 9*l;
    int c = n + m - 5*l;
    if(a>=0 && b>=0 && c>=0) cout << a << " " << b << " " << c << endl;
    else cout << "-1 -1 -1" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>


int r,c;
int n;
int x,y,z;
int total,ans;
int cnt;
int hoge[256][256];
int sita[256];
int i=1;
int cnt2;

main(){
	
	scanf("%d%d",&r,&c);
	for(x=0;x<r;x++){
		for(y=0;y<c;y++){
			scanf("%d",&hoge[x][y]);
			sita[y]+=hoge[x][y];
		}
	}
	
	for(x=0;x<r;x++){
		for(y=0;y<c;y++){
			printf("%d ",hoge[x][y]);
			cnt+=hoge[x][y];
		}
	printf("%d\n",cnt);
	cnt2+=cnt;
	cnt=0;
	}
	
	for(x=0;x<c;x++){
		printf("%d ",sita[x]);
		
		}
	printf("%d\n",cnt2);
	
	
	
	
	return 0;
}

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

#define F first
#define S second
#define pb push_back
#define ll long long
#define all(v) (v).begin(),(v).end()
#define endl '\n'

using namespace std;

const int N = 100005;
const int MOD = 1e9 + 7;
const int INF = 2000000000;
const ll INFLL = 1LL * INF * INF;

int p2[N], p3[N];
int main() {
    ios_base :: sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    p2[0] = p3[0] = 1;
    for (int i = 1; i < N; i++) {
        p2[i] = 2LL * p2[i - 1] % MOD;
        p3[i] = 3LL * p3[i - 1] % MOD;
    }
    string s;
    cin >> s;
    int cnt = 0, res = 0;
    for (int i = 0; i < s.size(); i++) {
        if (s[i] == '0') continue;
        res += 1LL * p3[s.size() - i - 1] * p2[cnt++] % MOD;
        res %= MOD;
    }
    res = (res + p2[cnt]) % MOD;
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 1280
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 + c >= 22) {
      System.out.println("bust");
    } else {
      System.out.println("win");
    }
  }
}


Measured memory_bytes: 21972
from collections import deque

K=int(input())

def bfs(k):
    queue = deque()
    for i in range(1, 10):#1~9までをqueueに追加しておく
        queue.append(i)
    cnt = 1
    
    while queue:
        x = queue.popleft()#左から取り出すと、自動的に小さい順から取り出せる
        if cnt == k:
            return x
        cnt += 1 #これまでのルンルン数の数
        last = x%10 #末尾の数字
        if last > 0:
            queue.append(x*10+last-1)#x-1⇒x⇒x+1の順にを末尾に追加すると順番になる。0と9に注意
        queue.append(x*10+last)
        if last < 9:
            queue.append(x*10+last+1)
            
print(bfs(K))

Measured memory_bytes: 44528
/* 	* In the name of GOD 
 	* Thanks God */
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
#define F first
#define S second

int32_t main(){
	char c;
	cin >> c;
	if (islower(c))
		cout << 'a';
	else
		cout << 'A';
}


Measured memory_bytes: 3644
#include<stdio.h>
#include<string.h>
int main()
{
    int i,j,len,lastIndexValue,flag = 0;
    char string1[101];
    char string2[101];
    scanf("%s%s",&string1,&string2);
    len = strlen(string1);
    for(i=0;i<len;i++)
    {
        if(strcmp(string1,string2)==0)
        {
            flag = 1;                       /// flag is the indicator .
            break;
        }
        lastIndexValue = string2[len-1];
        for(j=len-1;j>0;j--)
        {
            string2[j] = string2[j-1];
        }
        string2[j] = lastIndexValue;
        //string2[len] = '\0';
    }
    if(flag == 1 ) printf("Yes\n");
    else printf("No\n");
    return 0;
}

Measured memory_bytes: 1644
#include <iostream>

using namespace std;

int main() {
  int n,x,l,i;
  cin >> n;
  cin >> x;

  int d = 0;
  for (i = 1; i <= n; i++) {
    cin >> l;
    d += l;
    
    if (d > x) {
      break;
    }
  }
  
  cout << i << endl;
  
  
  return 0;
}

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

int main(){
	int n, m;
	string id;

	cin >> n >> id >> m;

	vector<int> v(m);
	for(int i=0;i<m;i++)cin >> v[i];

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

	int checksum = 0;
	vector<int> star;

	for(int i=0;i<id.size();i++){
		if(id[i] == '*'){
			star.push_back(i);
		} else {
			int n = id[i] - '0';
			if(i % 2 == 0){
				checksum += n;
			} else {
				n *= 2;
				checksum += n / 10;
				checksum += n % 10;
			}
		}
	}

	int all = 1;
	for(int i=0;i<star.size();i++)all *= m;

	int res = 0;

	for(int mask=0;mask<all;mask++){
		int tmp = mask;
		int sum = checksum;

		for(int i=0;i<star.size();i++){
			int d = v[tmp % m];
			
			if(star[i] % 2 == 0){
				sum += d;
			} else {
				d *= 2;
				sum += d / 10;
				sum += d % 10;
			}

			tmp /= m;
		}

		if(sum % 10 == 0)++res;
	}

	cout << res << endl;

	return 0;
}

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


public class Test
{	
    public static void Main()
	{
	    double [] n = Console.ReadLine().Split(' ').Select(s=>double.Parse(s)).ToArray();
	    Console.WriteLine(  Math.Ceiling((n[0]+n[1])/2));
	} 
}

Measured memory_bytes: 11220
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <iomanip>
#include <bitset>
#include <set>
#include <map>
#include <stdio.h>
#include <numeric>
#include <cstring>

#define rep(i,n) for (int i = 0; i < (n); i++)
#define rep1(i,n) for (int i = 1; i < (n); i++)
#define FOR(i,a,b) for (int i=(a); i < (b); i++)
#define MOD 1000000007 //10^9+7
using namespace std;
using ll = long long;
using PII = pair<int, int>;
using PLL = pair<ll, ll>;
const int INF = numeric_limits<int>::max();
const ll INFL = numeric_limits<ll>::max();


// 負の数にも対応した % 演算
long long mod(long long val, long long m) {
    long long res = val % m;
    if (res < 0) res += m;
    return res;
}

//greatest common divisor
long long gcd(ll a, ll b) 
{
    if (a % b == 0) {
        return b;
    } else {
        return gcd(b, a % b);
    }
}

//least common multiple
long long lcm(ll a, ll b)
{
    return a / gcd(a, b) * b ;
}

ll factorial(ll n) {
    ll res = 1;
    for (ll i = 1; i <= n; i++) {
        res *= i;
    }
    return res;
}

int main()
{
    ll l, r; cin >> l >> r;
    r = min(r, l + 4038);
    ll ans = 2018;
    for (ll i = l; i <= r; i++) {
        for (ll j = i+1; j <= r; j++) {
            ans = min(ans, (i*j)%2019);
        }
    }
    cout<< ans << endl;
    return 0;
}


Measured memory_bytes: 3536
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = Integer.parseInt(sc.next());
		int b = Integer.parseInt(sc.next());
		if (a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0)
			System.out.println("Possible");
		else
			System.out.println("Impossible");
	}
}

Measured memory_bytes: 21844
#include <iostream>
#include <string>
#include <vector>
#include <unordered_map>

using namespace std;

string makeString(long long x, long long y) {
    return to_string(x) + " " + to_string(y);
}

int main() {
    long long h,w,n;
    cin >> h >> w >> n;
    long long x,y;
    unordered_map<string, long long> m;
    for(long long i=0; i<n;i++){
        cin >> x >> y;
        for(int j=0; j<3; j++){
            if(x-j < 1 || x-j > h-2)
                continue;
            for(int k=0;k<3;k++){
                if(y-k < 1 || y-k > w-2)
                    continue;
                string s = makeString(x-j,y-k);
                if(m.find(s) == m.end()) {
                    m[s] = 1;
                }else {
                    m[s]++;
                }
            }
        }
    }
    vector<long long> v;
    for(int i=0;i<9;i++){
        v.push_back(0);
    }
    for(auto it = m.begin(); it != m.end(); it++){
        // cout << it->first << endl;
        v[it->second-1]++;
    }
    long long sum = (h-2)*(w-2);
    for(int i=0;i<9;i++){
        sum -= v[i];
    }
    cout << sum << endl;
    for(int i=0;i<9;i++){
        cout << v[i] << endl;
    }

}


Measured memory_bytes: 119056
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>
using namespace std;

map<string, set<string> > memo;

set<string> solve(const pair<string, vector<string> >& base, const vector<pair<string, vector<string> > >& g)
{
  set<string> ans;
  for (int i = 0; i < base.second.size(); ++i) {
		bool found = false;
		for (int j = 0; j < g.size() && !found; ++j) {
		  if (base.second[i] == g[j].first) {
		    found = true;
		    map<string, set<string> >::iterator it = memo.find(base.second[i]);
		    if (it != memo.end()) {
		      ans.insert(it->second.begin(), it->second.end());
				} else {
		      set<string> s = solve(g[j], g);
		      memo.insert(pair<string, set<string> >(base.second[i], s));
		      ans.insert(s.begin(), s.end());
		    }
		  }
		}
		if (!found)
		  ans.insert(base.second[i]);
  }
  return ans;
}

pair<string, vector<string> > split(const string str)
{
  int s = 0, t;
  t = str.find_first_of(":", s);
  string key = str.substr(0, t);
  s = t+1;
  
  vector<string> value;
  do {
    t = str.find_first_of(",", s);
	  value.push_back(str.substr(s, t-s));
	  s = t+1;
  } while (t != string::npos);
  
  return pair<string, vector<string> >(key, value);
}

int main()
{
  int n;
  while (cin >> n) {
    if (n == 0)
      break;
    
    memo.clear();
    
    string s;
    cin >> s;
    s.erase(s.end()-1);
    
    pair<string, vector<string> > base = split(s);
    vector<pair<string, vector<string> > > other;
    for (int i = 1; i < n; ++i) {
      cin >> s;
      s.erase(s.end()-1);
      other.push_back(split(s));
    }
    set<string> ans = solve(base, other);
    cout << ans.size() << endl;
  }
  return 0;
}

Measured memory_bytes: 1032
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <string>
#include <set>
#include <bitset>
#include <unordered_map>
#include <cmath>
#include <functional>

using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
template <class T>
using Vvec = vector<vector<T> >;

template <class T>
void debug(T& v)
{
    for(auto& x: v) cout << x << " ";
    cout << endl;
}

int main()
{
    int N;
    cin >> N;
    vector<ll> A(N);
    for(auto& x: A) cin >> x;

    ll p = 2;
    ll ans = A[0]-1;
    for(int i=1; i<N; i++){
        if(p == A[i]) p++;
        else ans += (A[i]-1)/p;
    }

    cout << ans << endl;
}

Measured memory_bytes: 1024
import Control.Monad
import Control.Applicative

solve :: String -> Int
solve str = do
	let [n, m] = map read $ words str :: [Int]
	if n `mod` m == 0 then m else n `mod` m

main = do
	n <- readLn :: IO Int
	s <- replicateM n getLine
	mapM_ print $ map solve s

Measured memory_bytes: 4144
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
using namespace std;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
	#define eprintf(...) 42
#endif

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

const int N = 200200;
ll fenv[N];
void addFenv(int p) {
	for(; p < N; p |= p + 1)
		fenv[p]++;
}
ll getFenv(int r) {
	ll res = 0;
	for(; r >= 0; r = (r & (r + 1)) - 1)
		res += fenv[r];
	return res;
}
ll getSum(int l, int r) {
	return getFenv(r - 1) - getFenv(l - 1);
}

const int A = 26;
vector<int> a[A];
pii b[N];
int m;
char s[N];
int n;

int main()
{
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);

	scanf("%s", s);
	n = strlen(s);
	for (int i = 0; i < n; i++) {
		int x = (int)(s[i] - 'a');
		a[x].push_back(i);
	}
	int id = -1;
	for (int i = 0; i < A; i++) {
		if ((int)a[i].size() & 1) {
			if (id != -1) {
				printf("-1\n");
				return 0;
			}
			id = i;
		}
	}

	ll ans = 0;
	if (id != -1) {
		int pos = a[id][(int)a[id].size() / 2];
		for (int c = 0; c < A; c++) {
			for (int i = 0; i < (int)a[c].size() / 2; i++) {
				if (a[c][i] > pos) ans++;
				if (a[c][(int)a[c].size() - 1 - i] < pos) ans++;
			}
		}
	}
	for (int c = 0; c < A; c++) {
		for (int i = 0; i < (int)a[c].size() / 2; i++)
			b[m++] = mp(a[c][i], a[c][(int)a[c].size() - 1 - i]);
	}
	sort(b, b + m);
	for (int i = 0; i < m; i++) {
		ans += 2 * getSum(0, b[i].first) + getSum(b[i].first, b[i].second);
		addFenv(b[i].second);
	}
	printf("%lld\n", ans);

	return 0;
}


Measured memory_bytes: 3064