akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <cstring>
#include <map>
using namespace std;

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

struct State {
    int x,y,turn,dis;
    State(int x,int y,int turn,int dis) : x(x), y(y), turn(turn) , dis(dis) {;}
};

int memo[1<<8][30][30];
int idx[26];

int bfs(vector<string> &mp) {
    const int h = mp.size();
    const int w = mp[0].length();

    int nx,ny,gx,gy;
    memset(memo, -1, sizeof(memo));

    for(int i=0; i<h; ++i) {
        for(int j=0; j<w; ++j) {
            if(mp[i][j] == '@') {
                nx = j; ny = i;
                mp[i][j] = '.';
            } else if(mp[i][j] == '<') {
                gx = j; gy = i;
                mp[i][j] = '.';
            }
        }
    }

    queue<State> Q;
    Q.push(State(nx,ny,0,0));

    while(!Q.empty()) {
        State st = Q.front(); Q.pop();
        int x = st.x, y = st.y;
        if(x == gx && y == gy) return st.turn;

        if(memo[st.dis][x][y] != -1) continue;
        memo[st.dis][x][y] = st.turn;

        for(int dir = 0; dir<4; ++dir) {
            int nx = x + dx[dir], ny = y + dy[dir];
            if(nx < 0 || nx >= w || ny < 0 || ny > h-1 || mp[ny][nx] == '#'
               || (isupper(mp[ny][nx]) && (st.dis>>(idx[mp[ny][nx]-'A']))%2 == 0))
                continue;

            State ns(nx,ny,st.turn+1,st.dis);

            if(islower(mp[ny][nx]))
                if(idx[mp[ny][nx]-'a'] != -1)
                    ns.dis ^= (1<<idx[mp[ny][nx]-'a']);

            Q.push(ns);
        }
    }

    return -1;
}

int main() {
    int W,H,nc;
    while(cin>>W>>H, W|H) {
        nc=0; memset(idx, -1, sizeof(idx));
        vector<string> mp(H);
        string s;
        for(int i=0; i<H; ++i)
            cin>>mp[i];

        for(int i=0; i<H; ++i)
            for(int j=0; j<W; ++j)
                if(isupper(mp[i][j]) && idx[mp[i][j]-'A'] == -1)
                    idx[mp[i][j]-'A'] = nc++;

        cout<<bfs(mp)<<endl;
    }
}

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

using namespace std;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int N, K;
    cin >> N >> K;
    vector<int> A(N);
    for (int i = 0; i<N; ++i) cin >> A[i];
    for (int i = K; i<N; ++i) {
        if (A[i-K]<A[i]) cout << "Yes\n";
        else cout << "No\n";
    }
}

Measured memory_bytes: 3912
def main():
  a = input()
  b = input()
  c = input()
  ab = [None]*20000
  ac = [None]*20000
  bc = [None]*20000
  def match(c1,c2):
    return (c1=='?')or(c2=='?')or(c1==c2)

  A = len(a)
  B = len(b)
  C = len(c)
  def solve(d1,d2,n,m,l):
    for i in range(n):
      for j in range(m):
        if not(match(d1[i],d2[j])):
          l[i-j+10000]=True
    return l
  ab = solve(a,b,A,B,ab)
  ac = solve(a,c,A,C,ac)
  bc = solve(b,c,B,C,bc)
  ans = 6000
  AB = A+B
  AC = A+C
  for i in range(-AC,AC,1):
    for j in range(-AB,AB,1):
      if (not(ab[i+10000]))and(not(ac[j+10000]))and(not(bc[j-i+10000])):
        L = min(0,min(i,j))
        R = max(A,max(B+i,C+j))
        ans = min(ans,R-L)
  print(ans)
  
main()

Measured memory_bytes: 47452
#include<iostream>
#include<math.h>
using namespace std;
int main()
{
  int N;
  cin>>N;
  int ans = 0;
  
  if (N < 3) {
    ans = 0;
  }
  else  {
    ans = N / 3;
  }
  cout<<ans<<endl;
  return 0;
}


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

using namespace std;

int main() {
  string s;
  cin >> s;
  int ans = 0;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '1') {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <array>
#include <algorithm>
using namespace std;
int main() {
    string S;
    cin >> S;
    array<int, 3> cnt {};
    for (auto c : S) cnt[c - 'a']++;
    sort(cnt.begin(), cnt.end());
    cout << (cnt[2] -  cnt[0] <= 1 ? "YES" : "NO") << endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
  vector<string> v1;
  vector<string>::iterator itr;
  string buf, target;
  int cnt = 0;
  
  cin >> target;
  while(cin >> buf) {
	if(buf == "END_OF_TEXT") break;
	transform(buf.begin(), buf.end(), buf.begin(), ::tolower);
	v1.push_back(buf);
  }

  for(itr = v1.begin(); itr != v1.end(); ++itr) {
	if(*itr == target) cnt++;
  }
  cout << cnt << endl;

  return 0;
}

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

#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)

typedef pair<int, int> pint;

#define mp make_pair
#define mt make_tuple
#define pb push_back
#define pf push_front

#define MOD (1000 * 1000 * 1000 + 7)

signed main() {
    ll K;
    cin >> K;

    ll N = 50;
    cout << N << endl;

    vector<ll> a(N, N-1);

    REP(i, N) {
        a[i] += K / N;
    }

    int th = K%N;
    REP(i, N) {
        if (i < th) {
            a[i] += (N - th + 1);
        } else {
            a[i] -= th;
        }
    }

    REP(i, N) {
        cout << a[i] << " ";
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<stdbool.h>

//fast(?) Input
#define buf_sz 1<<24
char buf[buf_sz];
unsigned int nextint(){
	static int id = 0;
	if(id == 0)read(0, buf, buf_sz);
	unsigned int res = 0;
	while(id<buf_sz && buf[id]<'0' || '9'<buf[id])id++;
	while(id<buf_sz && '0'<=buf[id] && buf[id]<='9'){
		res *= 10;
		res += buf[id++] - '0';
	}if(id>=buf_sz)exit(1);
	return res;
}

int d[] = {[0 ... 1<<18] -1};
int find(int x){
	if(d[x] < 0) return x;
	return d[x] = find(d[x]);
}
bool unite(int x, int y){
	x = find(x); y = find(y);
	if(x == y)return false;
	if(d[x] > d[y]){
		int tmp = x;
		x = y;
		y = tmp;
	}
	d[x] += d[y];
	d[y] = x;
	return true;
}
bool same(int x, int y){return find(x) == find(y);}
int size(int x){return -d[find(x)];}

int main(){
	nextint();
	int Q = nextint();
	while(Q--){
		if(nextint() == 1){
			puts(same(nextint(), nextint())?"1":"0");
		}else {
			unite(nextint(), nextint());
		}
	}
	return 0;
}

Measured memory_bytes: 4452
import java.util.*;

public class Main{

    static int[][] dir4 = new int[][] { { 0, -1 }, { 1, 0 }, { 0, 1 }, { -1, 0 } };
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        StringBuilder sb = new StringBuilder();
        while(true){
            int w = sc.nextInt();
            int h = sc.nextInt();
            if(w == 0 && h == 0)break;
            int[][] g = new int[h][w];
            for (int i = 0; i < h; i++) {
                for (int j = 0; j < w-1; j++) {
                    int a = sc.nextInt();
                    if(a == 1){
                        g[i][j] |= 1<<1; g[i][j+1] |= 1<<3;
                    }
                }
                if(i == h-1)break;
                for (int j = 0; j < w; j++) {
                    int a = sc.nextInt();
                    if(a == 1){
                        g[i][j] |= 1<<2; g[i+1][j] |= 1;
                    }
                }
            }
            int[][] d = new int[h][w];
            for (int i = 0; i < h; i++) {
                Arrays.fill(d[i], -1);
            }
            d[0][0] = 1;
            ArrayDeque<Integer> q = new ArrayDeque<>();
            q.add(0);
            while(!q.isEmpty()){
                int nex = q.poll();
                int ch = nex/100; int cw = nex%100;
                for (int i = 0; i < 4; i++) {
                    if((g[ch][cw] >> i & 1) == 1)continue;
                    int nh = ch+dir4[i][1]; int nw = cw+dir4[i][0];
                    if(nh < 0 || h-1 < nh || nw < 0 || w-1 < nw) continue;
                    if(0 <= d[nh][nw])continue;
                    d[nh][nw] = d[ch][cw]+1;
                    q.add(nh*100 + nw);
                }
            }
            if(d[h-1][w-1] < 0) d[h-1][w-1] = 0;
            sb.append(d[h-1][w-1] + "\n");
        }
        System.out.print(sb.toString());
        sc.close();

    }

}



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

int main()
{
	string s;
	while (cin >> s, s != "0") {
		int n = s.size();
		vector<vector<vector<int>>> dp(n + 1, vector<vector<int>>(11, vector<int>(2)));
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < 11; j++) {
				dp[i + 1][j][0] = dp[i][j][0];
			}
			for (int j = 0; j < 11; j++) {
				dp[i + 1][(j * 10 + s[i] - '0') % 11][1] += dp[i][j][1];
				dp[i + 1][(j * 10 + s[i] - '0') % 11][0] += dp[i][j][1];
			}
			if (s[i] != '0') {
				dp[i + 1][s[i] - '0'][1]++;
			}
		}
		cout << dp[n][0][0] << endl;
	}
	return 0;
}

Measured memory_bytes: 53720
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repf(i, a, b) for(ll i = (a); i < (b) ; i++ )
const ll mo = 1000000007;
const ll INF = 1LL << 60; //MAX 9223372036854775807
ll ans = 0;

int main()
{
ll n,k;
cin >> n>>k;
if((n-1)*(n-2)/2<k){
    cout << -1<< endl;
    return 0;
}
ll cou=(n-1)*(n-2)/2-k;
cout << cou+n-1 << endl;
rep(i,n-1){
    cout << 1<<" "<<i+2 << endl;
}

rep(i,n-2)repf(j,i+1,n-1){
    if(cou==0)return 0;
    cout << i+2<<" "<<j+2 << endl;
    cou--;
}

return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int n,k,i,kari,kotae=1000000000;
  cin >>n>>k;
  int x[n];
  for(i=0;i<n;i++){
    cin>>x[i];
  }
  for(i=0;i<=n-k;i++){
    kari=x[i+k-1]-x[i]+min(abs(x[i+k-1]),abs(x[i]));
    if(kotae>kari){
      kotae=kari;
    }
  }
  cout<<kotae;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
const int maxn = 400001;
int n, a[maxn], b[maxn], ta[maxn], tb[maxn], l = 1, r = 1;
int main() {
	cin >> n;
	for(int i = 1; i <= n; ++ i) {
		cin >> a[i];
		ta[a[i]] ++;
	}
	for(int i = 1; i <= n; ++ i) {
		cin >> b[i];
		tb[b[i]]++;
	}
	for(int i = 1; i <= n; ++ i) {
		if(ta[i] + tb[i] > n) {
			puts("No");
			exit(0);
		}
	}
	memset(b, 0, sizeof(b));
	for(int i = 1;i <= n; ++ i) {
		for(int j = 1; j <= tb[i]; ++ j) {
			while(b[l]) ++ l;
			while(a[r] <= a[l] && r <= n) ++ r;
			while(b[r]) ++ r;
			if(a[l] != i) b[l ++] = i;
			else b[r ++] = i;
		}
	}
	l = 1;
	for(int i = n + 1; b[i]; ++ i) {
		while(b[l]) ++ l;
		if(a[l] != b[i]) a[l] = b[i];
		else {
			while(a[r = (rand() % n + 1)] == b[i] || b[r] == a[l]);
			b[l] = b[r];
			b[r] = b[i];
		}
	}
	puts("Yes");
	for(int i = 1; i <= n; ++ i) printf("%d ", b[i]);
	return 0;
}


Measured memory_bytes: 7668
//(・ω・)
#include <stdio.h>
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, atoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <iomanip> //setprecision
#include <limits>
#include <sstream> //istringstream
#include <stdlib.h>
#include <list>
#include <iterator>//std::advance()
using namespace std;

int main(){
   priority_queue<long long,vector<long long>,less<long long>> s;
   while(1){
       string meirei;
       cin >> meirei;
       if(meirei=="end") break;
       else if(meirei=="insert"){
           long long num;
           cin >> num;
           s.push(num);
       }
       else{
           cout << s.top() << endl;
           s.pop();
       }
   }
}


Measured memory_bytes: 11172
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for (ll i=0; i<n; ++i)
#define all(c) begin(c),end(c)
/*
1-2
3-4
5-6
*/
ll inf = 1e9;
vector<vector<ll>> G(51, vector<ll>(51,inf));
ll N,M,ans = 0;

void wf(){
  vector<vector<ll>> H(51, vector<ll>(51,inf));
  H = G;
  for(ll k=1; k<=N; k++) for(ll i=1; i<=N; i++) for(ll j=1; j<=N; j++)
    H[i][j] = min(H[i][j], H[i][k] + H[k][j]);
  for(ll i=1; i<=N; i++) for(ll j=1; j<=N; j++)
    if (H[i][j] == inf)
    {
      ans++;
      return;
    }
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  
  cin >>N >>M;
  vector<pair<ll,ll>> P;  
  rep(i,M){
    ll a,b; cin>>a>>b;
    P.push_back({a,b});
    G[a][b] = 1;
    G[b][a] = 1;
  }
  rep(i, N+1)
    G[i][i] = 0;
  ll sz = P.size();
  rep(i,sz)
  {
    ll p1=P[i].first;
    ll p2=P[i].second;
    G[p1][p2] = inf;
    G[p2][p1] = inf;
    wf();
    G[p1][p2] = 1;
    G[p2][p1] = 1;
  }
  cout <<ans <<endl;
}

Measured memory_bytes: 3716
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        abc165_a solver = new abc165_a();
        solver.solve(1, in, out);
        out.close();
    }

    static class abc165_a {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int K = in.nextInt();
            int A = in.nextInt();
            int B = in.nextInt();

            for (int i = K; i <= B; i += K) {
                if ((A <= i) && (i <= B)) {
                    out.println("OK");
                    return;
                }
            }
            out.println("NG");
        }

    }
}



Measured memory_bytes: 35964
#include <iostream>

#define MAX_SET (1000)

using namespace std;

void draw_frame(int H, int W);

int main()
{  
    int  i;
    int* H = new int[MAX_SET + 1];
    int* W = new int[MAX_SET + 1];
    int  size;

    for (int i = 0; i < MAX_SET + 1; i++) {
         do {
             cin >> H[i] >> W[i];
         } while (H[i] > 300 || W[i] > 300);

         if (H[i] == 0 && W[i] == 0) {	    
             size = i;
	     break;
         }
    }
   
    for (int i = 0; i < size; i++) {
         draw_frame(H[i], W[i]);         
         cout << endl;
    }

    delete[] H;
    delete[] W;
 
    return (0);
} 

void draw_frame(int H, int W)
{    
     for (int i = 1; i <= H; i++) {
          if (i == 1 || i == H) {
              for (int j = 1; j <= W; j++) {
	  	   cout << "#";
              }
          } else {
	      for (int j = 1; j <= W; j++) {
		   if (j == 1 || j == W) {
		       cout << "#";
                   } else {
		       cout << ".";
                   }
	      }
          }

          cout << endl;
     }
}

Measured memory_bytes: 1192
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using vec=vector<ll>;
using mat=vector<vec>;
#define For(i,a,b) for(i=a;i<b;i++)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define all(v) (v).begin(),(v).end()
#define vsort(v) sort(all(v))
#define mod 1000000007
using data=pair<ll,ll>;

long mmid(long a,long b,long c){return a<b?(b<c?b:max(a,c)):(b>c?b:min(a,c));}

ll modinv(ll a) {
  ll b=mod,u=1,v=0,t;
  while(b){
    t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  return (u+mod)%mod;
}

ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}

ll modncr(ll n,ll r){
  ll i,plus=1;
  rep(i,r){
    plus=(plus*(n-i))%mod;
    plus=moddevide(plus,i+1);
  }
  return plus;
}

ll euclidean_gcd(ll a, ll b) {
  if(a<b) return euclidean_gcd(b, a);
  ll r;
  while ((r=a%b)){a=b;b=r;}
  return b;
}

ll countdigits(ll n){
  ll ans=0;
  while(n){n/=10;ans++;}
  return ans;
}

ll sumdigits(ll n){
  ll ans=0;
  while(n){ans+=n%10;n/=10;}
  return ans;
}

void printmap(vector<ll>& a,ll H,ll W){
  ll i,j;
  For(i,0,H+2){
    For(j,0,W+2){cout<<a[i*(W+2)+j];}
    cout<<endl;
  }
}
void inputmap(vector<ll>& a,ll H,ll W){
  ll i,j;
  string ss;
  For(i,1,H+1){
    cin>>ss;
    For(j,1,W+1){
      if(ss[j-1]=='#'){
        a[i*(W+2)+j]=1;
      }else{
        a[i*(W+2)+j]=0;
      }
    }
  }
}


int main(){
  ll i,j,N,K,M=0;
  cin>>N;
  vector<ll> a(N+1,0),v(N+1,0),ans;
  rep1(i,N+1){
    cin>>a[i];
  }
  for(i=N;i>0;i--){
    if(a[i]!=v[i]){
      ans.push_back(i);
      for(j=1;j*j<=i;j++){
        if(i%j==0){
          v[j]=1-v[j];
          if(j*j!=i)v[i/j]=1-v[i/j];
        }
      }
    }
  }
  cout<<ans.size()<<endl;
  rep(i,ans.size()){
    cout<<ans[i]<<" ";
  }
  return 0;
}

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

namespace abc085_b
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            List<int> mochis = new List<int> {};
            for (int i = 0; i < n; i++)
            {
                mochis.Add(int.Parse(Console.ReadLine()));
            }
            IEnumerable<IGrouping<int, int>> mochiGroups = mochis.GroupBy(m => m);
            Console.WriteLine(mochiGroups.Count());
        }
    }
}


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

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

  ll n, a, b;
  cin >> n >> a >> b;

  if (n == 1) {
    if (a == b) {
      cout << 1 << endl;
    } else {
      cout << 0 << endl;
    }
  } else if (a > b) {
    cout << 0 << endl;
  } else {
    cout << (a+b*(n-1))-(a*(n-1)+b)+1 << endl;
  }
}


Measured memory_bytes: 256
using System;
 
class Program
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        decimal dx1, dy1, dx2, dy2;
 
        for (int i = 0; i < n; i++)
        {
            string[] input = Console.ReadLine().Split(' ');
            decimal[] p = Array.ConvertAll(input, decimal.Parse);
 
            dx1 = p[2] - p[0];
            dy1 = p[3] - p[1];
            dx2 = p[6] - p[4];
            dy2 = p[7] - p[5];
 
            Console.WriteLine(dx2 * dy1 == dx1 * dy2 ? "YES" : "NO");
        }
    }
}

Measured memory_bytes: 9300
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
const ll MOD=ll(1e9)+7;
const int MAXN=int(1e5);
ll Pow3[MAXN+5];
char S[MAXN+5];
ll a[MAXN+5],c[MAXN+5],kn_fro[MAXN+5],kn_beh[MAXN+5];
int main()
{
    ll f=1;
    for(int i=0;i<=1e5+2;i++) Pow3[i]=f,f*=3ll,f%=MOD; //预处理3的次方
    scanf("%s",S);int len=strlen(S);
    for(int i=0,totA=0,totkn=0;i<len;i++) //统计a[i],kn_fro[i]，均不包含第i个字符本身
    {
        a[i]=totA;kn_fro[i]=totkn;
        if(S[i]=='A') totA++;
        if(S[i]=='?') totkn++;
    }
    for(int i=len-1,totC=0,totkn=0;i>=0;i--) //统计c[i],kn_beh[i]，均不包含第i个字符本身
    {
        c[i]=totC;kn_beh[i]=totkn;
        if(S[i]=='C') totC++;
        if(S[i]=='?') totkn++;
    }
    ll ans=0;
    for(int i=0;i<len;i++)
        if(S[i]=='?' || S[i]=='B')
        { //这里一些玄学错误……如果大家发现只在第11组数据WA了，肯定是long long 炸了，把MOD的顺序换一下再交吧……
            ll O1=a[i]*((c[i]*Pow3[kn_beh[i]+kn_fro[i]])%MOD)%MOD, //A->C
               O2=kn_beh[i]? (a[i]*(kn_beh[i]*Pow3[kn_beh[i]+kn_fro[i]-1]%MOD)%MOD):0ll, //A->?
               O3=kn_fro[i]? (c[i]*(kn_fro[i]*Pow3[kn_fro[i]+kn_beh[i]-1]%MOD)%MOD):0ll, //?->C
               O4=(kn_beh[i] && kn_fro[i])? (kn_fro[i]*(kn_beh[i]*Pow3[kn_fro[i]+kn_beh[i]-2]%MOD)%MOD):0ll; //?->?
            ll Sum=((O1+O2)%MOD+(O3+O4)%MOD)%MOD;
            ans+=Sum;
            ans%=MOD;
        }
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 4224
N = int(input())
A = list(map(int, input().split()))

ans = [0 for _ in range(N)]

sign = 1
for a in A:
    ans[0] += sign * a
    sign *= -1


for i in range(1, N):
    ans[i] = 2 * A[i-1] - ans[i - 1]

print(*ans)

"""
ダム1: 2( a1 - a2 + a3 )
ダム2: 2( a2 - a3 + a1 )
ダム3: 2( a3 - a1 + a2 )
"""


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


if __name__ == '__main__':
    n, m = map(int, input().split())
    shops = []
    ans = 0
    for i in range(n):
        shops.append(list(map(int, input().split())))
    shops.sort(key=lambda x:x[0])

    for shop in shops:
        price = shop[0]
        available = shop[1]
        if m - available > 0:
            ans += price * available
            m -= available
        else:
            ans += price * m
            break

    print(ans)

Measured memory_bytes: 28960
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#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>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const double PI2 = 8.0 * atan(1.0);

#define REP(i,n)	for(int i=0;i<(int)n;++i)
#define ALL(c)		(c).begin(),(c).end()
#define CLEAR(v)	memset(v,0,sizeof(v))
#define MP(a,b)		make_pair((a),(b))
#define ABS(a)		((a)>0?(a):-(a))
#define FOR(i,s,n)	for(int i=s;i<(int)n;++i)

int n, m;
int a[50], b[50], c[50], d[50];

int main(int argc, char **argv) {
	cin >> n >> m;
	REP(i, n) cin >> a[i] >> b[i];
	REP(i, m) cin >> c[i] >> d[i];
	REP(i, n) {
		int mi = 400000000, res = 0;
		REP(j, m) {
			int v = abs(a[i] - c[j]) + abs(b[i] - d[j]);
			if (v < mi) {
				mi = v;
				res = j;
			}
		}
		cout << (res + 1) << endl;
	}
	return 0;
}


Measured memory_bytes: 256
function search_nums(left, right){// left < right
  nums = [];
  for( var i=0 ; i<left ; i++ ){
    num = left-i;
    if((left%num==0) && (right%num==0)){
      nums.push(num);
    }
  }
  return nums;
}

function main(input) {
  const formatted_input = input.split(' ').map( x => parseInt(x, 10) );
  const A = formatted_input[0];
  const B = formatted_input[1];
  const K = formatted_input[2];



  if(A <= B){
    console.log(search_nums(A, B)[K-1]);
  }else{
    console.log(search_nums(B, A)[K-1]);
  }
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 7372
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <cassert>
#include <cstdint>

using namespace std;

using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<long long>;
using VVL = vector<VL>;

const long long INF = 1e18;
const int N_CONTEST = 26;

int D;
VI c;
VVI s;

long long calc_sat_constest_day(int contest, int day, const VI &lastdays) {
	long long ret = s[day][contest];
	for (int i = 1; i <= N_CONTEST; i++) {
		if (i != contest) {
			ret -= (long long) c[i] * (day - lastdays[i]);
		}
	}
	return ret;
}

VL calc_sats(const VL &t, bool shows=false) {
	long long sat = 0;
	VL sats(D+1, 0);
	VI lastdays(N_CONTEST+1, 0);

	for (int i = 1; i <= D; i++) {
		int contest = t[i];

		lastdays[contest] = i;
		long long sat_day = calc_sat_constest_day(contest, i, lastdays);
		sat += sat_day;
		sats[i] = sat;
	}

	if (shows) {
		for (int i = 0; i <= D; i++) {
			printf("%3d: %15lld\n", i, sats[i]);
		}
	}

	return sats;
}

VL solve_greedy() {
	VL t(D+1, -1);

	VI lastdays(N_CONTEST+1, 0);
	for (int i = 1; i <= D; i++) {
		long long maxi = -INF;
		int cand = -1;
		for (int j = 1; j <= N_CONTEST; j++) {
			long long sc = calc_sat_constest_day(j, i, lastdays);
			if (sc > maxi) {
				maxi = sc;
				cand = j;
			}
		}

		t[i] = cand;
		lastdays[cand] = i;
	}

	return t;
}

int main() {
	cin >> D;

	c.assign(N_CONTEST+1, 0);
	for (int i = 1; i <= N_CONTEST; i++) {
		cin >> c[i];
	}
	s.assign(D + 1, VI(N_CONTEST+1, 0));
	for (int i = 1; i <= D; i++) {
		for (int j = 1; j <= N_CONTEST+1; j++) {
			cin >> s[i][j];
		}
	}

	VL t = solve_greedy();
	for (int i = 1; i <= D; i++) {
		cout << t[i] << endl;
	}
	auto sats = calc_sats(t);
	auto sat = sats.back();
	auto score = max<long long>(0, sat + 1000000);
	// cout << sats.back() << endl;
	// cout << score << endl;

	return 0;
}


Measured memory_bytes: 3236
#include <bits/stdc++.h>
using namespace std;
int main() {
    int64_t n,y;
    cin >> n >> y;
    for(int i = 0;i <= n;i++) {
        for(int j = 0;i + j <= n;j++) {
            if(i * 10000 + j * 5000 > y) {
                break;
            }
            if((y - i * 10000 - j * 5000) % 1000 == 0 && i + j + (y - i * 10000 - j * 5000) / 1000 == n) {
                cout << i << " " << j << " " << (y - i * 10000 - j * 5000) / 1000 << endl;
                return 0;
            }
        }
    }
    cout << -1 << " " << -1 << " " << -1 << endl;
}


Measured memory_bytes: 256
//自称高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

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

#define INF 1999999999
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007 

int main() {
    int ans = 0;
    int tmp;
    int n, m , k;
    int s[10] = {};
    cin >> n >> m;
    REP(i, m){
        cin >> k;
        REP(j , k){
            cin >> tmp;
            s[tmp-1] += 1 << i; 
        }
    }
    //REP(i, n) cout << bitset<10>(s[i]) << endl;
    //cout << endl;

    int p= 0;
    REP(i, m){
        cin >> tmp;
        if(tmp == 1) p += 1 << i;
    } 
    //cout << bitset<10>(p) << endl << endl;
    REP(i, pow(2, n)){
        int now = 0;
        REP(j, n){
            if(i & (1 << j)) now ^= s[j];
        }
        //cout << bitset<10>(now) << endl;
        if(p == now) ans ++;
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
using namespace std;

#define rep(i,a,n) for(int i=a; i<n; i++)
#define repq(i,a,n) for(int i=a; i<=n; i++)
#define repr(i,a,n) for(int i=a; i>=n; i--)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 2000000000
#define int long long int

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define LEQ(n, m) ((n) <= (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
#define GEQ(n, m) ((n) + EPS >= (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

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

namespace std {
    bool operator<(const P& a, const P& b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

signed main() {
    int a[3]; rep(i,0,3) cin >> a[i];
    sort(a, a+3);
    rep(i,0,3) {
        if(a[i] % 2 == 0) {
            cout << 0 << endl;
            return 0;
        }
    }
    cout << a[0] * a[1] << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dump(...)
#endif
#define endl "\n"
#define ll long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define INF (1 << 30 - 1)
#define LLINF (1LL << 60)
#define vi vector<int>
#define vvi vector<vector<int>>
#define pi pair<int, int>
#define ALL(a) (a).begin(), (a).end()
#define BIT(n) (1LL << (n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてからつかうこと
constexpr ll MOD = 1e9 + 7;
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec)
        is >> x;
    return is;
}

signed main() {
    cin >> N;
    vector<string> v(N);
    REP(i, N) {
        cin >> v[i];
    }
    list<pair<int, int>> x;
    list<pair<int, int>> y;
    int plus = 0;
    int minus = 0;
    REP(i, N) {
        int cnt = 0;
        string s = v[i];
        int mn = INF;
        REP(j, s.size()) {
            if (s[j] == '(') {
                cnt++;
            } else {
                cnt--;
            }
            mn = min(cnt, mn);
        }
        if (cnt >= 0) {
            if (mn >= 0) {
                plus += cnt;
            } else {
                pair<int, int> tmp = {mn, cnt};
                x.push_back(tmp);
            }
        } else {
            mn -= cnt;
            cnt *= -1;
            if (mn >= 0) {
                minus += cnt;
            } else {
                pair<int, int> tmp = {mn, cnt};
                y.push_back(tmp);
            }
        }
    }
    while (x.size() > 0) {
        bool flag = false;
        for (auto it = x.begin(); it != x.end(); it++) {
            auto p = *it;
            if (plus + p.first >= 0) {
                plus += p.second;
                auto cp = it;
                it++;
                x.erase(cp);
                flag = true;
            }
        }
        if (!flag) {
            break;
        }
    }
    while (y.size() > 0) {
        bool flag = false;
        for (auto it = y.begin(); it != y.end(); it++) {
            auto p = *it;
            if (minus + p.first >= 0) {
                minus += p.second;
                auto cp = it;
                it++;
                y.erase(cp);
                flag = true;
            }
        }
        if (!flag) {
            break;
        }
    }
    if (x.size() > 0 || y.size() > 0) {
        cout << "No" << endl;
    } else {
        if (plus == minus) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    }
}


Measured memory_bytes: 34284
// Aizu Vol-2 0220: Binary Digit A Doctor Loved
// 2017.8.6

#include <stdio.h>
#include <ctype.h>

char *gets(char *);
char buf[50], *p;

int getInt(void)
{
	int n = 0;
	while (isspace(*p) || *p == ',') p++;
	if (*p == '-') return -1;
	while (isdigit(*p)) n = 10 * n + (*p++ - '0');
	return n;
}

#define P 10
char ans[20], *px, *py;

int main()
{
	int x, y, k;

	while (1) {
		gets(p = buf);
		if ((x = getInt()) < 0) break;
		if (x > 255) { puts("NA"); continue; }
		px = ans + P;
		k = 8; while (k--) *--px = (x & 1) + '0', x >>= 1;
		py = ans + P; *py++ = '.';
		y = 0;
		if (*p == '.') {
			k = 0, p++;
			while (k < 4 && isdigit(*p)) y = 10 * y + (*p++ - '0'), k++;
			while (k++ < 4) y *= 10;
		}
		k = 4; while (k--) y <<= 1, *py++ = (y/10000) + '0', y %= 10000;
		if (y) puts("NA");
		else *py = 0, puts(px);
	}
	return 0;
}

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

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
template<typename T> void view(T cont) {std::cout << cont << std::endl;}
template<typename T> void view(T* cont, ll sz) {rep(i, sz) std::cout << cont[i] << " "; std::cout << std::endl;}
template<typename T> void view(const std::vector<T>& v) {for (const auto& f: v) std::cout << f << " "; std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv) { for (const auto& v: vv) {view(v);}}
const long long INF = 1LL<<60;
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

int main(){
    int N; cin >> N;
    vector<int> W;
    rep(i, N) {
        int temp; cin >> temp;
        W.push_back(temp);
    }
    int ans = 10000000;
    for (int i = 0; i < N - 1; i++) {
        int sum1 = 0, sum2 = 0;
        for (int j = i; j >= 0; j--) {
            sum1 += W[j];
        }
        for (int j = i + 1; j < N; j++) {
            sum2 += W[j];
        }
        int diff = abs(sum1 - sum2);
        if (diff < ans) ans = diff;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#define llong long long
#define INF (__INT32_MAX__ / 2)
#define EPS 10e-8

using namespace std;
typedef pair<llong, llong> ipair;
llong modulo(llong left, llong right) { return (left % right + right) % right; }

int N;
double res;
int main(int argc, char **argv) {
    cin >> N;

    if(N % 2 == 0)
        res = 0.5;
    else
        res = 1.0 - (double)(N / 2) / N;

    printf("%.10f\n", res);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define INF 9223372036854775807LL
#define inf 1000000007
#define lol long long
#define abs(x,y) (max(x,y)-min(x,y))
#define mp make_pair
#define fi first
#define se second
using namespace std;
lol a,b,c;
int x[100001],y[100001];
bool an[10];
bool o[10][10];
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  lol d=0,e=0,f=0;
  string s;
  cin >>a;
  cin >>s;
  x[a-1]=1,an[s[a-1]-'0']=true;
  for(int n=a-2;n>=0;n--){
    if(!an[s[n]-'0']) an[s[n]-'0']=true,x[n]=x[n+1]+1;
    else x[n]=x[n+1];
  }
  for(int n=0;n<a-2;n++){
    int t=s[n]-'0';
    for(int m=n+1;m<a-1;m++){
      int r=s[m]-'0';
      if(!o[t][r]) o[t][r]=true,d+=x[m+1];
    }
  }
  cout <<d<<'\n';
  return 0;
}


Measured memory_bytes: 640
N,M = list(map(int,input().split()))

if N==1:
    print(M)
else:
    ans = 1
    for i in range(1,10**5):
        if i*i>M:
            break
        if M%i==0:
            j=0
            k=0
            if M//i>=N:
                j=i
            if i>=N:
                k=M//i
            ans = max(j,k,ans)

    print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <numeric>
#include <map>
#include <iomanip>
#include <cmath>
#include <queue>
#include <limits.h>

using namespace std;    
typedef long long ll;
typedef pair<ll, ll> pll;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
const bool DEBUG = true;

int main(){

    ll ans = 0;

    ll money = 100;
    ll X;
    cin >> X;
    while ( money < X )
    {
        money *= 1.01;
        ans ++;
    }
    
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3620
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = 0
for i in range(n):
    if a[i] >= b[i]:
        ans += b[i]
    else:
        ans += a[i]
        b[i] -= a[i]
        if a[i+1] >= b[i]:
            ans += b[i]
            a[i+1] -= b[i]
        else:
            ans += a[i+1]
            a[i+1] = 0
print(ans)

Measured memory_bytes: 23940
#include <cstdio>
#include <cmath>
#include <iostream>
#include <complex>
#include <vector>
using namespace std;

typedef complex<double> point;
double cross(const point& a, const point& b) {
	return imag(conj(a)*b);
}

typedef vector<point> polygon;
double convex_diameter(const polygon &P) {
	const int n = P.size();
	auto diff = [&P,n](int i) {return P[(i+1)%n] - P[i];};
	int is = 0, js = 0;
	for (int i = 1; i < n; ++i) {
		if (imag(P[i]) > imag(P[is])) is = i;
		if (imag(P[i]) < imag(P[js])) js = i;
	}
	double maxd = norm(P[is]-P[js]);

	int i, maxi, j, maxj;
	i = maxi = is;
	j = maxj = js;
	do {
		if (cross(diff(i), diff(j)) >= 0) j = (j+1) % n;
		else i = (i+1) % n;
		if (norm(P[i]-P[j]) > maxd) {
			maxd = norm(P[i]-P[j]);
			maxi = i; maxj = j;
		}
	} while (i != is || j != js);
	return maxd; /* farthest pair is (maxi, maxj). */
}

int main() {
	int n;
	while (cin >> n) {
		polygon pol(n);
		for (auto& p : pol) {
			double x, y;
			cin >> x >> y;
			p = point(x, y);
		}
		printf("%.10lf\n", sqrt(convex_diameter(pol)));
	}
	return 0;
}

Measured memory_bytes: 2312
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}

template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

// -------------------------------------------------------

int A, B, M;
int a[101010], b[101010], c[101010], x[101010], y[101010];

int main()
{
    cin >> A >> B >> M;
    int ans = inf;
    repe(i, 1, A)
    {
        cin >> a[i];
    }
    repe(i, 1, B)
    {
        cin >> b[i];
    }
    repe(i, 1, M)
    {
        cin >> x[i] >> y[i] >> c[i];
        ans = min(ans, a[x[i]] + b[y[i]] - c[i]);
    }
    sort(a + 1, a + A + 1);
    sort(b + 1, b + B + 1);
    ans = min(ans, a[1] + b[1]);
    cout << ans << endl;
}


Measured memory_bytes: 2176
s = input()

a = [[] for i in range(26)]

l = len(s)

for i in range(l):
    a[ord(s[i]) - 97].append(i)
ans = 1000

for i in range(26):
    a[i].append(l)
    t = a[i][0]
    for j in range(1, len(a[i])):
        t = max(t, a[i][j] - a[i][j-1] - 1)
    ans = min(ans, t)

print(ans)

Measured memory_bytes: 9092
s = int(input())

a = [s]
while True:
  if a[-1] % 2 == 0:
    output = int(a[-1] / 2)
  else:
    output = int(3 * a[-1] + 1)
  a.append(output)
  if a.count(output) >= 2:
    break
    
print(len(a))

Measured memory_bytes: 38384
//my import
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<stack>
#include<list>
#include<unordered_map>
using namespace std;
#define ll long long
#define dd cout<<endl
#define lll __int128
const int mod=1e9+7;
const int inf=1e9+7; 

//const int maxn=

int pre[2005];

int main()
{
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	
	int x;
	
	cin>>x;
	
	if(x>=2000)
		return cout<<1<<endl,0;
	
	memset(pre,0,sizeof(pre));
	
	for(int i=1;i<=19;i++)
	{
		for(int j=100*i;j<=(105*i);j++)
			pre[j]=1;
	}
	
	cout<<pre[x]<<endl;
	
	return 0;
}

Measured memory_bytes: 256
H,W = list(map(int,input().split()))

field = [["."]*(W+2)]
for i in range(H):
    field.append(["."])
    field[-1].extend(list(input()))
    field[-1].append(".")
field.append(["."]*(W+2))

for i in range(1,H+1):
    for j in range(1,W+1):
        if field[i][j] == "#":
            print("#",end="")
        else:
            cnt = 0
            for x in [-1,0,1]:
                for y in [-1,0,1]:
                    if field[i+y][j+x] == "#":
                        cnt += 1
            print(cnt,end="")
    print("")

Measured memory_bytes: 3444
#include <bits/stdc++.h>
using namespace std;
char s[100100];
int res[100100],lp[100100],rp[100100];
int main(){
	scanf("%s",s);
	memset(res,0,sizeof(res));
	int l=strlen(s);
	int pt;
	for(int i=0;i<l;i++) if(s[i]=='L') {pt=i;break;}
	for(int i=0;i<l;i++){
		if(s[i]=='R'){
			if(i>pt)
			for(int j=pt+1;j<l;j++){
				if(s[j]=='L' && j>i){
					pt=j;
					break;
				}
			}
			int cnt=pt-i;
			res[pt-(cnt%2)]+=1;
		}
	}
	for(int i=l-1;i>=0;i--) if(s[i]=='R') {pt=i;break;}
	for(int i=l-1;i>=0;i--){
		if(s[i]=='L'){
			if(i<pt){
				for(int j=pt-1;j>=0;j--){
					if(s[j]=='R' && j<i){
						pt=j;
						break;
					}
				}
			}
			int cnt=i-pt;
			res[pt+(cnt%2)]++;
		}
	}
	for(int i=0;i<l;i++){
		if(i) printf(" ");
		printf("%d",res[i]);
	}
	printf("\n");
	return 0;
}


Measured memory_bytes: 896
def m():
    N, M = map(int, input().split())
    H = list(map(int, input().split()))
    graph = [[] for _ in range(N + 1)]
    for _ in range(M):
        a, b = map(int, input().split())
        graph[a].append(b)
        graph[b].append(a)
    ans = 0
    for i in range(1, N+1):
        current = H[i-1]
        p = 1
        for x in graph[i]:
            if current <= H[x-1]:
                p = 0
                break
        ans += p
    return ans


print(m())


Measured memory_bytes: 29360
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = ll(1e9) + 1;

#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 scn(n) scanf("%d", &n)
#define scns(s) scanf("%s", &s)
#define pri(n) printf("%d", n)
#define priln(n) printf("%d\n", n)
#define pris(s) printf("%s", s)
#define prisln(s) printf("%s\n", s)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main()
{
  int n, m;
  scn(n);
  scn(m);
  int s[m];
  int c[m];

  for (int i; i < m; ++i) {
    cin >> s[i] >> c[i];
  }

  int d[n];
  rep(i, n) d[i] = -1;

  int check = 0;
  rep(i, m) {
    int pos = s[i] - 1;
    if (d[pos] >= 0 && d[pos] != c[i]) {
      check = 1;
      break;
    }

    d[pos] = c[i];
  }

  if (n > 1 && d[0] < 0) d[0] = 1;
  rep(i, n) {
    if (d[i] < 0) d[i] = 0;
  }
  if (n > 1 && d[0] == 0) check = 1;

  if (check == 1) {
    cout << -1 << endl;
  } else {
    int ans = 0;
    rep(i, n) ans += d[i]*pow(10, n - i - 1);
    cout << ans << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
const int mod = 1e9 + 7;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<int> vi;
map<string, int> mp;
int main(){
    int a, b;
    cin >> a >> b;
    cout << ((a <= b)?"unsafe":"safe") << endl;
    return 0;
}  

Measured memory_bytes: 3636
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
string s;
int n;
vector<pair<int,string> >ans;
void f(int i,int sum,string t)
{
	if(sum>n)return;
	else if(i==s.size())
	{
		ans.push_back(make_pair(sum,t));
		return;
	}
	for(int j=1;i+j<=s.size();j++)
	{
		f(i+j,sum+stoi(s.substr(i,j)),t+(i==0?"":" ")+s.substr(i,j));
	}
}
main()
{
	while(cin>>n>>s,n||s!="0")
	{
		ans.clear();
		f(0,0,"");
		if(ans.size()==0)cout<<"error"<<endl;
		else
		{
			sort(ans.begin(),ans.end());
			if(ans.size()>1&&ans[ans.size()-1].first==ans[ans.size()-2].first)cout<<"rejected"<<endl;
			else cout<<ans[ans.size()-1].first<<" "<<ans[ans.size()-1].second<<endl;
		}
	}
}




Measured memory_bytes: 3128
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s1, s2 ;
    cin >> s1 >> s2 ;
    int flag = 0;
    for( int i=0 ; i < s1.size(); i++ )
    {
        if(  s1[i] != s2[i] )flag=1;
    }
    if(flag == 1)cout<<"No\n";
    else cout<<"Yes\n";

    return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include <cstdio>
#include <bits/stdc++.h>


using namespace std;
int main(){
  long long INF =  1000000007;
  long long N, i, ans = 1;
  cin >> N;
  for (i = 1; i <= N; i++){
    ans *= i;
    ans %= INF;
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std;

#define ll long long
#define ld long double
#define P pair<ll, ll>

#define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++)

#define all(v) v.begin(), v.end()

#define sortAl(v) sort(all(v))
#define sortAlr(v)                                                             \
  sort(v.begin(), v.end());                                                    \
  reverse(v.begin(), v.end())

#define cout(n) cout << fixed << setprecision(n)

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

template <class T> inline void chmax(T &a, T b) { a = std::max(a, b); }
template <class T> inline void chmin(T &a, T b) { a = std::min(a, b); }

#define mod (int)(1e9 + 7)
#define INF LLONG_MAX

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

  ll n, m;
  cin >> n >> m;

  vector<ll> a(n);
  rep(i, n) { cin >> a[i]; }

  vector<ll> dp(n);
  unordered_map<ll, ll> rem_map;

  dp[0] = a[0] % m;
  rem_map[dp[0]]++;

  REP(i, n) {
    dp[i] = dp[i - 1] + a[i];
    dp[i] %= m;
    rem_map[dp[i]]++;
  }

  ll sum = 0;
  ll ans = 0;
  rep(i, n) {
#if 0
    for (ll k = i; k < n; k++) {
      if (dp[k] == sum) {
        ans++;
      }
    }
#else
    // keyが存在する場合
    auto itr = rem_map.find(sum);
    if (itr != rem_map.end()) {
      ans += itr->second;
    }
#endif
    rem_map[dp[i]]--;
    sum += a[i];
    sum %= m;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 5260
#include<stdio.h>
int main ()
{
    int A,B,C;
    scanf("%d%d%d",&A,&B,&C);
    if(A==B){
        printf("%d",C);
    }
    else if(B==C){
        printf("%d",A);
    }
    else if(C==A){
        printf("%d",B);
    }
    return 0;
}


Measured memory_bytes: 128
def f(s):
    c = 0
    for i in range(len(s)):
        if i == 0:
            c = 1
        elif s[i - 1] == s[i]:
            pass
        else:
            c += 1
    return c

assert f("aabbbbaaca") == 5
assert f("aaaaa") == 1
assert f("xxzaffeeeeddfkkkkllq") == 10

_n = input()
s = input()
ans = f(s)
print(ans)


Measured memory_bytes: 39664
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();
		int t = 0;

		/*
		 * 
		 * [0 << 50 >> 50] 40 [90 << 50 >> 140] 50 [190 << 5 >> 95] 40 [135 <<5>> 140] 40 [180 <<5>> 185]
		 *                 51        111

		 * [0 << 5 >> 5] 40 [45 << 5 >> 50] 40 [90 << 5 >> 95] 40 [135 <<5>> 140] 40 [180 <<5>> 185]
		 *               29                 89                                    149
		 */
		while (t < Integer.MAX_VALUE - 120) {
			int w1 = t;
			int w2 = t + a;
			int r = t / 60;
			int arrive = 60 * r + c;
//			System.out.printf("%d <--> %d, r = %d, arrive = %d\n", new Object[] { new Integer(w1), new Integer(w2), new Integer(r), new Integer(arrive) });

			if (w1 <= arrive && arrive <= w2) {
				System.out.println(arrive);
				return;
			}

			t += a + b;
		}
		
		System.out.println(-1);
	}
}

Measured memory_bytes: 26480
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <string>
#include <bitset>
#include <deque>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define print(x) cout<<(x)<<endl
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n)-1; i >= 0; --i)
#define INF10 1001001001 
#define INF5 100000
#define EPS 1e-10

set<int> p;


int main() {
	int A, B, K; cin >> A >> B >> K;
	for (int i = A; i < A + K; i++) {
		if (i > B)break;
		p.insert(i);
	}
	for (int i = B; i > B - K; i--) {
		if (i < A)break;
		p.insert(i);
	}
	vector<int>out;
	for (auto a : p) {
		out.push_back(a);
	}
	sort(out.begin(), out.end());
	for (auto a : out) {
		print(a);
	}



	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long N,M,ans=-1; cin>>N>>M;
  string s,t; cin>>s>>t;
  long long L, a=N, b=M, c=a%b;
  while(c!=0){
    a=b, b=c, c=a%b;
  }
  L=N*M/b;
  int x=L/N, y=L/M, z=N/y;
  for(int i=0; i<z; i++){
    if(s[i*y]!=t[i*x]) break;
    if(i==z-1) ans=L;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 512