akhauriyash/Code-Regression huggingface dataset:
n=int(input())
d=dict()
def get(n):
    if(n==1):return 1
    if(n==0):return 0
    if(n in d.keys()):return d[n]
    if(n%2==0):
        d[n]=2*get(n//2)+get(n//2-1)
    else:
        d[n]=2*get(n//2)+get(n//2+1)
    d[n]%=(10**9+7)
    return d[n]
def check(u,v,n):
    for a in range(n+1):
        b=u ^ a
        if(a+b==v):
            return 1
    return 0
#for e in range(1,n):
#    ans=0
#    for i in range(e+1):
##        for j in range(e+1):
#            ans+=check(i,j,e)
#    print(ans,get(e+1))
print(get(n+1))


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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << setprecision(20) << fixed;
  int N;
  cin >> N;
  vector<vector<int>> zahyo(N, vector<int>(3));
  for (int i = 0; i < N; i++) {
    int x, y, h;
    cin >> x >> y >> h;
    zahyo[i][0] = x;
    zahyo[i][1] = y;
    zahyo[i][2] = h;
  }
  for (int i = 0; i <= 100; i++) {
    for (int j = 0; j <= 100; j++) {
      int height = 0;
      for (int t = 0; t < N; t++) {
        if (height == 0 && zahyo[t][2] != 0) {
          height = zahyo[t][2] + abs(zahyo[t][0] - i) + abs(zahyo[t][1] - j);
          break;
        }
      }
      for (int t = 0; t < N; t++) {
        int takasa = zahyo[t][2] + abs(zahyo[t][0] - i) + abs(zahyo[t][1] - j);
        if (zahyo[t][2] != 0) {
          if (takasa != height) {
            // cout << i << " " << j <<  " " << t  <<endl;
            break;
          }
        } else {
          if (takasa < height) {
            break;
          }
        }
        if (t == N - 1) {
          cout << i << " " << j << " " << height << endl;
          return 0;
        }
      }
    }
  }
}


Measured memory_bytes: 3628
/*

                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                    prayer
*/

// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(long long i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) {rep(_,v.size())cout<<" "<<v[_];cout<<endl;}
#define show2d(v) {rep(__,v.size())show1d(v[__]);}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
#define yes cout<<"Yes\n"
#define no cout<<"No\n"

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

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

    int n;
    cin>>n;
    string s;
    cin>>s;
    int c=0;
    rep(i,s.size()-1)if(s[i]-s[i+1])c++;
    cout<<c+1<<endl;
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <iomanip>

using namespace std;

#define REP(i,n) for(ll (i) = (0); (i) < (n); ++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define ALL(v) v.begin(),v.end()
#define INF 1100000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007
#define Decimal fixed << setpresicion(20)


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

void prime_factor(int n, map<int, int>& res) {
  for (int i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      res[i]++;
      n /= i;
    }
  }
  if (n != 1) res[n]++;
}

int main()
{
  int N; cin >> N;
  map<int, int> mp;
  for (int i = 2; i <= N; i++) prime_factor(i, mp);

  int n74=0, n24=0, n14=0, n4=0, n2=0;
  for (auto e : mp) {
    if (e.SE >= 74) n74++;
    if (e.SE >= 24) n24++;
    if (e.SE >= 14) n14++;
    if (e.SE >= 4) n4++;
    if (e.SE >= 2) n2++;
  }
  int ans = 0;
  ans += n74;
  ans += n24*(n2-1);
  ans += n14*(n4-1);
  ans += n4*(n4-1)/2 * (n2-2);
  cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
import collections
n=int(input())
c=list(map(int,input().split()))
c = collections.Counter(c)
count=0
for x in c:
    if x==c[x]:
        continue
    elif x>c[x]:
        count+=c[x]
    else:
        count=count+(c[x]-x)
print(count)

Measured memory_bytes: 68264
//============================================================================
// Name        : Hello.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include<algorithm>
#include <iostream>
#include<cstdio>
#include<cmath>
#include<iomanip>
#include<string>
using namespace std;
int main() {


	long long n;
	cin>>n;

	long long ans=1;
	for(long long i=0;i<n;i++){
		ans=(i+1)*ans%(1000000007);
	}

	cout<<ans<<endl;

	return 0;
}



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

//typedef
//------------------------------------------
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int MOD = 1000000007;

//MOD
//--------------------------------------------
#define MUL(a,b) (((a) % MOD) * ((b) % MOD)) % MOD

// grid
//--------------------------------------------
VL dx = {0, 1, 0, -1};
VL dy = {1, 0, -1, 0};
VL dx2 = {-1, 0, 1, -1, 1, -1, 0, 1};
VL dy2 = {-1, -1, -1, 0, 0, 1, 1, 1};

//debug
//--------------------------------------------
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//main code
LL calc(LL n){
	LL ret = 0;
	if (n % 2 == 0) {
		// n-1までの1の数数える -> n/2
		ret = ((n/2) % 2) xor n;
	}
	else {
		ret = ((n + 1) / 2) % 2;
	}

	return ret;
}

int main(int argc, char const* argv[])
{
	LL a,b;
	cin >> a >> b;
	cout << (calc(a-1) xor calc(b)) << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

struct card { char suit,value;};

void bubble(struct card a[],int n);
void selection(struct card a[],int n);
void print(struct card a[],int n);
bool isStable(struct card c1[],struct card c2[],int n);

void bubble(struct card a[],int n){
	for(int i=0;i<n;i++){
		for(int j=n-1;j>=i+1;j--){
			if(a[j].value<a[j-1].value){
				card t=a[j];
				a[j]=a[j-1];
				a[j-1]=t;
			}
		}
	}
	return;
}

void selection(struct card a[],int n){
	for(int i=0;i<n;i++){
		int minj=i;
		for(int j=i;j<n;j++){
			if(a[j].value<a[minj].value) minj=j;
		}
		card t=a[i];
		a[i]=a[minj];
		a[minj]=t;
	}
	return;
}

void print(struct card a[],int n){
	for(int i=0;i<n;i++){
		if(i>0)cout<<" ";
		cout<<a[i].suit<<a[i].value;
	}
	cout<<endl;

	return;
}

bool isStable(struct card c1[],struct card c2[],int n){
	for(int i=0;i<n;i++){
		if(c1[i].suit!=c2[i].suit)return false;
	}
	return true;
}

int main(void){
	card c1[100],c2[100];
	int n;

	cin>>n;
	for(int i=0;i<n;i++) cin>>c1[i].suit>>c1[i].value;

	for(int i=0;i<n;i++) c2[i]=c1[i];
	
	bubble(c1,n);
	selection(c2,n);

	print(c1,n);
	cout<<"Stable"<<endl;
	print(c2,n);
	if(isStable(c1,c2,n)) cout<<"Stable"<<endl;
	else cout<<"Not stable"<<endl;

	return 0;
}


Measured memory_bytes: 3100
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define N 666666
map<pair<int,int>,int> mp;
int x[N],y[N];
int dx[]={0,0,1,-1,1,1,-1,-1};
int dy[]={1,-1,0,0,1,-1,1,-1};
int ans[N];
signed main(){
	int h,w,n;
	scanf("%lld%lld%lld",&h,&w,&n);
	for(int i=1;i<=n;i++){
		scanf("%lld%lld",&x[i],&y[i]);
		mp[make_pair(x[i],y[i])]++;
		for(int j=0;j<8;j++){
			int tx=dx[j]+x[i];
			int ty=dy[j]+y[i];
			if(tx>=1&&ty>=1&&tx<=h&&ty<=w){
				mp[make_pair(tx,ty)]++;
			}
		}
	}
	int sum=0;
	ans[0]=(h-2)*(w-2);
	map<pair<int,int>,int> ::iterator it;
	for(it=mp.begin();it!=mp.end();it++){
		int tx=it->first.first;
		int ty=it->first.second;
		int num=it->second;
		if(tx>=2&&ty>=2&&tx<=h-1&&ty<=w-1){
			ans[mp[make_pair(tx,ty)]]++;
			sum++;
		}
	}
	ans[0]-=sum;
	for(int i=0;i<=9;i++) cout<<ans[i]<<'\n';
	return 0;
}

Measured memory_bytes: 60544
def solve():
    if N == 0:
        if A[0] == 1:
            return 1
        else:
            return -1

    if A[0] != 0:
        return -1

    tot = sum(A)
    cur = 1
    ans = 1
    for i in range(1, N + 1):
        cur *= 2
        if cur < A[i]:
            return -1
        tmp = min(cur, tot)
        ans += tmp
        cur = tmp - A[i]
        tot -= A[i]
    return ans


N, *A = map(int, open(0).read().split())
print(solve())


Measured memory_bytes: 19888
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define all(v) (v).begin(), (v).end()
#define sum(v) accumulate(all(v),0)
#define vi vector<int>

int main() {
  int n,m;
  cin >> n >> m;
  
  vi h(n);
  rep(i,n){
    cin >> h[i];
  }
  
  vi xs(n,1);

  rep(i,m){
    int a,b;
    cin >> a >> b;
    if(xs[a-1] == 1 and h[a-1] <= h[b-1]){
      xs[a-1] = 0;
    }
    if(xs[b-1] == 1 and h[b-1] <= h[a-1]){
      xs[b-1] = 0;
    }
  }
      
  cout << sum(xs)  << endl;
  
}


Measured memory_bytes: 4052
/*
 * hoge.cpp
 *
 *  Created on: 2014/09/30
 *      Author: eiichi
 */
#include<iostream>
#include<vector>
#include<cmath>
#include<string>
#include<map>
#include<list>
using namespace std;

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


	return 0;
}

Measured memory_bytes: 1192
import java.io.*;
import java.math.*;
import java.util.*;
public class Main {

	public static void main(String[] args) { 
		Scanner input = new Scanner(System.in);
		int N = input.nextInt();
		int P = input.nextInt();
		String S = input.next();
		long cnt = 0;
		if (P==2) {
			for (int i = S.length()-1; i >= 0; i--) {
				int D = Integer.parseInt(S.substring(i,i+1));
				if (D%2==0) cnt+=i+1;
			}
		}else if (P==5) {
			for (int i = S.length()-1; i >= 0; i--) {
				int D = Integer.parseInt(S.substring(i,i+1));
				if (D==0||D==5) cnt+=i+1;
			}
		}else {
			long[] mod = new long[P];
			mod[0]++;
			long pow_10 = 1;
			long curNum = 0;
			for (int i = S.length()-1; i >= 0; i--) {
				int D = Integer.parseInt(S.substring(i,i+1));
				curNum+=D*pow_10;
				curNum%=P;
				mod[(int) curNum]++;
				pow_10*=10;
				pow_10%=P;
			}
			for (int i = 0; i < P; i++) {
				cnt+=mod[i]*(mod[i]-1)/2;
			}
		}
		System.out.println(cnt);
	}
}

Measured memory_bytes: 37040
import java.util.*;

public class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    
    int n = sc.nextInt();
    boolean isPrime = false;
    
    for(int i = n; !isPrime; i++){
      boolean flg = true;
      
      for(int j = 2; flg && j <= Math.sqrt(n); j++){
        if(i % j == 0){
          flg = false;
        }
      }
      
      if(flg){
        System.out.println(i);
        isPrime = true;
      }
    }
  }
}

Measured memory_bytes: 35636
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <queue>
#include <stack>

using namespace std;

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

const ll mod = 1000000007;

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

  int a, b;
  cin >> a >> b;

  int x = min(a, b);
  int y = max(a, b);

  for (int i = 0; i < y; i++) cout << x;
  cout << endl;

  return 0;
}


Measured memory_bytes: 256
def remove_lowest_step(flowers):
    flowers = [f-1 if f > 0 else 0 for f in flowers]
    return flowers


def count_lowest_step(flowers):
    binary_flowers = [1 if f > 0 else 0 for f in flowers]
    merge_flowers = binary_flowers[0:1]

    for b in binary_flowers[1:]:
        if merge_flowers[-1] == b:
            continue
        merge_flowers.append(b)

    return sum(merge_flowers)


def check_end(flowers):
    if sum(flowers) == 0:
        return True
    return False


def input_flowers():
    n = int(input())
    flowers = input().split()
    flowers = list(map(int, flowers))

    return n, flowers


n, flowers = input_flowers()
count = 0

while not check_end(flowers):
    count += count_lowest_step(flowers)
    flowers = remove_lowest_step(flowers)

print(count)

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

const int ALIVE = 1, DEAD = 2;
int h, w;
vector<vector<int>> field;
bool out_field(int i, int j) { return i < 0 || i >= h || j < 0 || j >= w; }

void dfs(int i, int j) {
    field[i][j] = DEAD;
    for (int di: {-1, 0, 1}) for (int dj: {-1, 0, 1}) {
        int ni = i + di, nj = j + dj;
        if (out_field(ni, nj) || field[ni][nj] != ALIVE) continue;
        dfs(ni, nj);
    }
}

int main() {
    while (cin >> w >> h, w) {
        field.assign(h, vector<int>(w));
        for (auto &row: field) for (auto &c: row) cin >> c;
        int cnt = 0;
        for (int si = 0; si < h; si++) for (int sj = 0; sj < w; sj++) {
            if (field[si][sj] != ALIVE) continue;
            cnt++;
            dfs(si, sj);
        }
        cout << cnt << endl;
    }
    return 0;
}


Measured memory_bytes: 3212
#include <stdio.h>
#include <stdbool.h>
#define n0 500000 //上限/2
#define n1 500    //sqrt(上限)/2

int prime(int *p){
  bool fp[n0]={};
  int i,j,np=1,s;
  for(i=0;i<n1;i++){
    if(fp[i]) continue;
    s=(i<<1)+3;
    for(j=(i+1)*3;j<n0;j+=s){
      fp[j]=1;
    }
  }
  p[0]=2;
  for(i=0;i<n0;i+=1){
    if(fp[i]^1){
      p[np]=(i<<1)+3;
      np++;
    }
  }
  return(np);
}

int main(){
  int i,j,p[200000],c,m=0,l[200000];
  long n;
  c=prime(&p);
  scanf("%ld",&n);
  for(i=0;i<c;i++){
    l[i]=0;
    while(n%p[i]==0){
      n/=p[i];
      l[i]++;
    }
  }
  if(n!=1){
    l[c]=1;
    c++;
  }
  for(i=0;i<c;i++){
    for(j=1;j<=l[i];j++){
      l[i]-=j;
      m++;
    }
  }
  printf("%d",m);
  return(0);
}


Measured memory_bytes: 2840
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using P = pair<int, int>;
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
const ll mod = 1000000007;
 
int main()
{
  int n, l;
  cin >> n >> l;
  int sum = 0;
  int m = 1000000;
  rep(i, n) {
    sum += l+i;
    if (abs(l+i)<abs(m)) m = l + i;
  }
  sum -= m;
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <tuple>
using namespace std; using ll = long long; using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vpll = vector<pll>;
//**デバッグ準備**//
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
void debug_out() { cerr << endl; }
template<typename Head, typename... Tail>
void debug_out(Head h, Tail... t) {
	cerr << " " << h;
	if (sizeof...(t) > 0) cerr << " :";
	debug_out(t...);
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> vec) {
	for (size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
	return os;
}
ll ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
bool pairCompare(const pll firstElof, pll secondElof)
{
	return firstElof.first > secondElof.first;
}
//**Snippetリスト**//
//rep, vin, all, iteLoop//
//bitSearch, bitList, gcdlcm, isPrime, primeFactorize, Npow, divisor, modinv, dfs, bfs, eratos//
//dijkstra, WarshallFloyd, BellmanFord, UnionFind, COM, digitDP ,RMQ//
ll i, j, k, l; ll N, M, K, H, W, L, X, Y, Z, R;
ll MOD = 1000000007; ll INF = 1LL << 62; ll ans = 0; ll z = 0, o = 1;
vl flag, color, D; vll path;
int main() {
	cin >> N;
	vl A(N);
	for (i = 0; i < N; i++) cin >> A[i];
	sort(A.begin(), A.end());
	ll left = 0;
	ll right = N - 1;
	vl L, R;
	//最初にA[0]を真ん中に
	left = 1;
	ll count = 0;
	while (count < N-1) {
		if (count % 4 == 0) {
			L.push_back(A[right]);
			right--;
		}
		if (count % 4 == 1) {
			R.push_back(A[right]);
			right--;
		}
		if (count % 4 == 2) {
			L.push_back(A[left]);
			left++;
		}
		if (count % 4 == 3) {
			R.push_back(A[left]);
			left++;
		}
		count++;
	}
	reverse(L.begin(), L.end());
	debug(L,A[0],R);
	ll mini = INF;
	if (L.size() > 0) {
		for (i = 0; i < L.size() - 1; i++) {
			ans += abs(L[i] - L[i + 1]);
			mini = min(mini, abs(L[i] - L[i + 1]));
		}
		ans += abs(L[L.size() - 1] - A[0]);
		mini = min(mini, abs(L[L.size()-1] - A[0]));
	}
	if (R.size() > 0) {
		ans += abs(R[0] - A[0]);
		mini = min(mini, abs(R[0] - A[0]));
		for (i = 0; i < R.size() - 1; i++) {
			ans += abs(R[i] - R[i + 1]);
			mini = min(mini, abs(R[i] - R[i + 1]));
		}
	}
	ll p, q;
	if (L.size() > 0) {
		p = L[0];
	}
	else {
		p = A[0];
	}
	if (R.size() > 0) {
		q = R[R.size() - 1];
	}
	else {
		q = A[0];
	}
	ans += abs(p - q);
	mini = min(mini, abs(p - q));
	debug(ans, mini);
	ans -= mini;
	cout << ans;
}

Measured memory_bytes: 3820
#include <bits/stdc++.h>
#include <map>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int, int> T;
 
const ll MOD=1e9+7;
//const ll INF=1e18;
int INF = 1000000;

int ban[35][35],w,h,c[4],dp[35][35][4];
int dj[4][4] = {{0,1,0,-1},
              {1,0,-1,0},
              {0,-1,0,1},
              {-1,0,1,0} };
int di[4][4] = {{-1,0,1,0},
              {0,1,0,-1},
              {1,0,-1,0},
              {0,-1,0,1}};

int next_direction(int i,int j,int ni,int nj){
    if(i == ni){
        if(j > nj){
            return 3;
        }else{
            return 1;
        }
    }else{
        if(i > ni){
            return 0;
        }else{
            return 2;
        }
    }
}

int main(){
    while(true){
        cin >> w >> h;
        if(w + h == 0)break;
        for(int i = 1;i <= h;i++){
            for(int j = 1;j <= w;j++){
                cin >> ban[i][j];
                for(int k = 0;k < 4;k++) dp[i][j][k] = INF;
            }
        }
        for(int i = 0;i < 4;i++){
            cin >> c[i];
        }
        queue<T> que;
        dp[1][1][1] = 0;
        que.push(make_tuple(1,1,1,0));
        while(!que.empty()){
            T t = que.front(); que.pop();
            int i = get<0>(t),j = get<1>(t),d = get<2>(t),cost = get<3>(t);
     //       cout << "i:" << i << ", j:" << j << ", d:" << d << ", cost:" << cost <<endl;
            if(dp[i][j][d] != cost || (i == h && j == w)) continue;
            for(int k = 0;k < 4;k++){
                int ni = i + di[d][k],nj = j + dj[d][k];
                int nd = next_direction(i,j,ni,nj);
                if(ni <= 0 || ni > h || nj <= 0 || nj > w)continue;
                int same_d = 0;
                if(k == ban[i][j]) same_d = c[k];
                if(dp[ni][nj][nd] > cost + c[k] - same_d){
                    dp[ni][nj][nd] = cost + c[k] - same_d;
                    que.push(make_tuple(ni,nj,nd,dp[ni][nj][nd]));
                }
            }
        }
        int ans = INF;
        for(int k = 0;k < 4;k++){
            ans = min(ans,dp[h][w][k]);
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 3056
#include <bits/stdc++.h>
#define ll long long
#define N 100010
#define M 1010

using namespace std;
int n; double m;

int read() {
	int s = 0, f = 0; char ch = getchar();
	while (!isdigit(ch)) f |= (ch == '-'), ch = getchar();
	while (isdigit(ch)) s = s * 10 + (ch ^ 48), ch = getchar();
	return f ? -s : s;
}

int main() {
	int ans = 0;
	n = read(), m = read();
	for (int i = 1; i <= n; i++) {
		double x = read(), y = read();
		double sy = sqrt(x * x * 1ll+ y * y * 1ll);
		if (sy <= m) ans++;
	}
	cout << ans;
}

Measured memory_bytes: 3644
INF = 1 << 30

n = int(input())

g = [[] for i in range(n)]
num = [[] for i in range(n)]
for i in range(n-1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    g[a].append(b)
    g[b].append(a)
    num[a].append(i)
    num[b].append(i)

m = int(input())

u = [0 for i in range(m)]
v = [0 for i in range(m)]
ls = [0 for i in range(m)]
for i in range(m):
    u[i], v[i] = map(int, input().split())
    u[i] -= 1
    v[i] -= 1

    cost = [INF for j in range(n)]
    cost[u[i]] = 0
    st = [u[i]]
    pre = [-1 for j in range(n)]
    pre[u[i]] = -2

    while len(st) > 0:
        now = st.pop()
        for to in g[now]:
            if pre[to] == -1:
                pre[to] = now
                st.append(to)
    
    pos = v[i]
    while pos != u[i]:
        for j in range(len(g[pos])):
            to = g[pos][j]
            if to == pre[pos]:
                ls[i] |= 1<<num[pos][j]
                pos = to
                break

ans = 0

for bit in range(1<<m):
    cnt = 0
    val = 0
    for i in range(m):
        if ((bit>>i)&1) == 1:
            cnt += 1
            val |= ls[i]
    
    pcnt = 0
    for i in range(n):
        if ((val>>i)&1) == 1:
            pcnt += 1
    
    nokori = n-1-pcnt

    if cnt%2 == 0:
        ans += 2**nokori+1
    else:
        ans -= 2**nokori+1

print(ans)

Measured memory_bytes: 44204
#include <cstdio>
#include <iostream>
#include <vector>
#include <string>
#include <utility>
using namespace std;

int main(){
	char num=0,oldNum=0;
	for(int i=0;i<4;i++){
		cin>>num;
		if(num==oldNum){
			cout<<"Bad"<<endl;
			return 0;
		}else{
			oldNum=num;
		}
	}
	cout<<"Good"<<endl;
	return 0;
}

Measured memory_bytes: 256
n = int(input())
s = input()
s1 = ""
s2 = ""
if n%2 != 0:
    print("No")
    exit()
for i in range(len(s)//2):
    s1 = s1 + s[i]
    s2 = s2 + s[(len(s)//2)+i]
if s1 == s2:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<deque>
#include<iomanip>
#include<tuple>
#include<cassert>
#include<set>
#include<atcoder/all>
using namespace std;
using namespace atcoder;
typedef long long int LL;
typedef pair<int,int> P;
typedef pair<LL,int> LP;
const int INF=1<<30;
const LL MAX=1e9+7;

void array_show(int *array,int array_n,char middle=' '){
    for(int i=0;i<array_n;i++)printf("%d%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(LL *array,int array_n,char middle=' '){
    for(int i=0;i<array_n;i++)printf("%lld%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(vector<int> &vec_s,int vec_n=-1,char middle=' '){
    if(vec_n==-1)vec_n=vec_s.size();
    for(int i=0;i<vec_n;i++)printf("%d%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}
void array_show(vector<LL> &vec_s,int vec_n=-1,char middle=' '){
    if(vec_n==-1)vec_n=vec_s.size();
    for(int i=0;i<vec_n;i++)printf("%lld%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}

int main(){
    int n,m;
    int i,j,k;
    int a,b,c;
    cin>>n>>m;
    dsu seg(n);
    for(i=0;i<m;i++){
        cin>>c>>a>>b;
        if(c==0)seg.merge(a,b);
        else if(seg.same(a,b))cout<<1<<endl;
        else cout<<0<<endl;
    }
}

Measured memory_bytes: 3988
from collections import defaultdict
from collections import deque
import itertools
import math

def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()

n = readInt()
d = {"2":0,"4":0,"other":0}
for i in readInts():
	if i%4==0:
		d["4"]+=1
	elif i%2==0:
		d["2"]+=1
	else:
		d["other"]+=1

if d["4"]>=d["other"]+min(0,d["2"]-1):
	print("Yes")
else:
	print("No")

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

int main(){
  int n,m;
  cin>>n>>m;
  int a,b;
  vector<int> v(n,0),tmpa(m),tmpb(m);
  for(int i=0;i<m;i++){
    cin>>tmpa[i]>>tmpb[i];
  }
  for(int i=0;i<m;i++){
    v[tmpa[i]-1]++;
    v[tmpb[i]-1]++;
  }
  for(int i=0;i<n;i++)
    cout<<v[i]<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
 
using namespace std;
 
typedef long long int ll;
#define pb push_back
#define mp make_pair
 
int main(){
	int n,k,s,i;
	scanf("%d%d%d",&n,&k,&s);

	int a[n+1];
	for(i=1;i<=k;i++){
		a[i]=s;
	}
	int p=0;
	if(s==1e9)
		p=s-1;
	else
		p=s+1;
	for(i=k+1;i<=n;i++){
		a[i]=p;
	}

	for(i=1;i<=n;i++)
		printf("%d ",a[i] );
	printf("\n");
 
	return 0;
}

Measured memory_bytes: 1664
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
	string s; cin>>s;
	int n=s.size();
	if(n==1){
		cout<<1<<endl;
		return 0;
	}
	if(n==2){
		if(s[0]==s[1]) cout<<1<<endl;
		else cout<<2<<endl;
		return 0;
	}
	int dp[2][200020];
	fill(dp[0], dp[0]+n+1, -1);
	fill(dp[1], dp[1]+n+1, -1);
	dp[0][0]=1;
	dp[1][1]=1;
	for(int i=1; i<n; i++){
		if(dp[1][i-1]!=-1){
			dp[0][i]=max(dp[0][i], dp[1][i-1]+1);
		}
		if(dp[0][i-1]!=-1 && s[i]!=s[i-1]){
			dp[0][i]=max(dp[0][i], dp[0][i-1]+1);
		}
		if(i==1) continue;
		if(dp[0][i-2]!=-1){
			dp[1][i]=max(dp[1][i], dp[0][i-2]+1);
		}
		if(dp[1][i-2]!=-1 && (s[i]!=s[i-2] || s[i-1]!=s[i-3])){
			dp[1][i]=max(dp[1][i], dp[1][i-2]+1);
		}
	}
	cout<<max(dp[0][n-1], dp[1][n-1])<<endl;
	return 0;
}

Measured memory_bytes: 2180
X, Y = map(int,input().split())
# https://qiita.com/derodero24/items/
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

if (X+Y)%3!=0:
    print(0)
else:
    itr=(X+Y)//3
    x_mx=itr*2
    if itr<=X and X<=x_mx and itr<=Y and Y<=x_mx and X+Y==itr+x_mx:
        c=X-itr
        f=cmb(itr, c)
        f=f%(10**9+7)
        print(f)
    else:
        print(0)


Measured memory_bytes: 44148
#include<bits/stdc++.h>
using namespace std;
int finddigits(int a)
{
int ans=0;
while(a>0)
{
ans+=(a%10);
a/=10;
}
return ans;
}
int main()
{
int n,a,b;
cin >> n >> a >> b;
long long ans=0;
for(int i=1;i<=n;i++)
{
int u=finddigits(i);
if(u>=a&&u<=b)
ans+=i;
}
cout << ans;
return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <functional>
#include <math.h>
#include <stdlib.h>
#include <map>
#include <deque>
#include <sys/timeb.h>
#include <fstream>

using namespace std;

#define repr(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repr(i,0,n)
#define reprrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) reprrev(i,0,n)
#define repi(itr,ds) for(auto itr=ds.begin();itr!=ds.end();itr++)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define mp make_pair
#define mt make_tuple
#define INF 1050000000
#define INFL 1100000000000000000LL
#define EPS (1e-10)
#define MOD 1000000007
#define PI 3.1415926536
#define RMAX 4294967295

typedef long long ll;
typedef pair<int, int> Pi;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<Pi> vPi;
typedef vector<vector<int> > vvi;
typedef vector<vector<bool> > vvb;
typedef vector<vector<ll> > vvll;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<double> > vvd;
typedef vector<vector<Pi> > vvPi;
typedef priority_queue<int, vector<int>, greater<int> > pqli;
typedef priority_queue<ll, vector<ll>, greater<ll> > pqlll;
typedef priority_queue<Pi, vector<Pi>, greater<Pi> > pqlP;
struct Edge {
	int from, to, cost;
	bool operator<(Edge e) {
		return cost < e.cost;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
template <class T>
using vec = vector<T>;
template<class T>
using pql = priority_queue<T, vector<T>, greater<T>>;
string debug_show(Pi a) {
	return "(" + to_string(a.first) + "," + to_string(a.second) + ")";
}

template<class T>
struct augEdge {
	T from, to;
	int cost;
	bool operator<(augEdge e) { return cost < e.cost; }
	bool operator>(augEdge e) { return cost > e.cost; }
};
template<class T>
using augGraph = vector<augEdge<T>>;



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

	int h, w;
	cin >> h >> w;
	vs s(h);
	rep(i, h)cin >> s[i];
	rep(i, h) {
		cout << s[i] << endl << s[i] << endl;
	}

	return 0;
}


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

namespace ABC136
{
    class Program3
    {
        static void Main()
        {
            var N = int.Parse(Console.ReadLine());
            var H = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            var now = H[0] > 0 ? H[0] - 1 : H[0];

            for (int i = 1; i < N; i++)
            {
                if (H[i] < now)
                {
                    Console.WriteLine("No");
                    return;
                }
                now = Math.Max(H[i] - 1, now);
            }

            Console.WriteLine("Yes");
        }
    }
}


Measured memory_bytes: 30300
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,K;
  cin >> N >> K;
  vector<int> A(N);
  int sum = 0;
  for(int i=0; i<N; i++) {
    cin >> A.at(i);
    if(A.at(i) > K / 2) {sum += 2 * ( K - A.at(i));}
    else {sum += 2 * A.at(i);}
  }
  cout << sum << endl;
}

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

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

    ll x;
    cin >> x;
    ll a,b;
    rep(i,400){
        rep(j,400){
            ll ans,ansb;
            ans = i*i*i*i*i;
            ansb = j*j*j*j*j;
 
            if(ans + ansb == x){
                a = i;
                b = -j;
                goto OUT;
            }
            if(ans - ansb == x){
                a = i;
                b = j;
                goto OUT;
            }
        }
    }
    OUT:
    cout << a << " " << b << endl;
    cout << endl;
    return 0;
}


Measured memory_bytes: 3600
#include<stdio.h>

int main(){
  int n,tmp;
  int v[100];
  double ans=0;
  
  scanf("%d",&n);
  for(int i=0;i<n;i++){
    scanf("%d",&v[i]);
  }
  
  for(int i=0;i<n;i++){
    for(int j=i+1;j<n;j++){
      if(v[i]>v[j]){
        tmp=v[i];
        v[i]=v[j];
        v[j]=tmp;
      }
    }
  }
  
  for(int i=0;i<n;i++){
    if(i==0){
      ans=v[i];
    }else{
      ans=(ans+v[i])/2;
    }
  }
  
  printf("%lf",ans);
  return 0;
}
        

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

namespace atcoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            var S = Console.ReadLine();

            var r = S.IndexOf("R");
            if (r == -1)
            {
                Console.WriteLine(0);
                return;
            }

            var ans = 1;
            for (int i = r + 1; i < 3; i++)
            {
                if (S[i] == 'R')
                    ans++;
                else
                    break;
            }

            Console.WriteLine(ans);
        }
    }
}


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


int n;
vector<vector<int> > tree;
int* changedDpIndex;
int* changedValue;
vector<int> dpValue;
int* ans;
int* value;
void dfs(
         int currentIndex,
         int father
) {
    auto binarySearchIndex = lower_bound(dpValue.begin(), dpValue.end(), value[currentIndex]);
    int length;
 //   cout << "currentIndex: " << currentIndex << endl;
    if (*binarySearchIndex == value[currentIndex]) {
        // nodes[currentIndex] = new Node(currentIndex, -1, -1);
        length = ans[father];
    } else {
        int insertPos = binarySearchIndex - dpValue.begin();
     //   cout << "insertPos: " << insertPos << endl;
        changedDpIndex[currentIndex] = insertPos;
        changedValue[currentIndex] = dpValue[insertPos];
        if (dpValue[insertPos] == INT_MAX) {
            length = insertPos + 1;
        } else {
            length = ans[father];
        }
        dpValue[insertPos] = value[currentIndex];
    }
    //  length = -Arrays.binarySearch(dpValue, Integer.MAX_VALUE - 1) - 1;
    ans[currentIndex] = length;
    
    // visit sons
    for (int son: tree[currentIndex]) {
        if (son == father) {
            continue;
        }
        dfs(son, currentIndex);
    }
    
    if (changedDpIndex[currentIndex] != -1) {
        // this node replaced some node before, recover it
        dpValue[changedDpIndex[currentIndex]] = changedValue[currentIndex];
        //    nodes[currentIndex] = new Node(currentIndex, -1, -1);
    }
    
}
int main() {
    
    cin >> n;
    tree = vector<vector<int> >(n + 1);
    value = new int[n + 1];
    changedDpIndex = new int[n + 1];
    changedValue = new int[n + 1];
    ans = new int[n + 1];
    for (int i = 1; i <= n; ++i) {
        cin >> value[i];
    }
    for (int i = 1; i < n; ++i) {
        int u, v;
        cin >> u;
        cin >> v;
        tree[u].push_back(v);
        tree[v].push_back(u);
    }
    ans = new int[n + 1];
    ans[1] = 1;
    dpValue = vector<int>(n);
    for (int i = 0; i < n; ++i) {
        dpValue[i] = INT_MAX;
    }
    changedDpIndex = new int[n + 1];
    changedValue = new int[n + 1];
    for (int i = 1; i <= n; ++i) {
        changedDpIndex[i] = -1;
        changedValue[i] = INT_MAX;
    }
    dfs(1, -1);
    for (int k = 1; k <= n; ++k) {
        cout << ans[k] << endl;
    }
}



Measured memory_bytes: 26256
#include <stdio.h>
int main(void)
{
	int n, b, i[2], p=0;
	scanf("%d",&n);
	
	for(b = 1; b <= 9; b++){
		i[0] = n % b;
		i[1] = n / b;
		if(i[0] == 0 && i[1] <= 9 && p == 0){
			printf("Yes");
			p++;
		}
	}
	
	if(p == 0){
		printf("No");
	}
	
	return 0;
}

Measured memory_bytes: 128
import java.util.Scanner

fun main() {
	val scn = Scanner(System.`in`)
	val s = scn.next()
	var max = 0
	var cnt = 0
	for (c in s){
		when(c) {
			'S' -> cnt = 0
			'R' -> {
				cnt++
				max = kotlin.math.max(max, cnt)
			}
		}
	}
	println(max)
}


Measured memory_bytes: 36032
use std::io::*;

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let n: usize = itr.next().unwrap().parse().unwrap();
    let k: usize = itr.next().unwrap().parse().unwrap();

    let mut sushi = vec![Vec::new(); 100010];
    let mut other = Vec::new();
    let mut top_sushi = std::collections::BinaryHeap::new();
    for _ in 0..n {
        let t: usize = itr.next().unwrap().parse().unwrap();
        let d: usize = itr.next().unwrap().parse().unwrap();
        sushi[t - 1].push(d);
    }

    for i in 0..100005 {
        sushi[i].sort_by(|a, b| b.cmp(&a));
        for j in 0..sushi[i].len() {
            if j == 0 {
                top_sushi.push(sushi[i][j]);
            } else {
                other.push(sushi[i][j]);
            }
        }
    }
    other.sort_by(|a, b| b.cmp(&a));
    let mut sum = vec![0; 100010];
    for i in 0..other.len() {
        sum[i + 1] = sum[i] + other[i];
    }

    let mut ans = 0;
    let mut top_score = 0;
    let mut top_count = 0;
    for i in 1..k + 1 {
        if let Some(top) = top_sushi.pop() {
            top_score += top;
            top_count += 1;
        }
        ans = std::cmp::max(ans, top_score + sum[k - i] + top_count * top_count);
    }
    println!("{}", ans);
}


Measured memory_bytes: 16636
#include<bits/stdc++.h>
using namespace std;
char S[5];
char T[5];
int main() {
	scanf("%s",S);
	scanf("%s",T);
	int ans=0;
	for(int i=0;i<3;i++){
		if(S[i]==T[i])
			ans++;
	}
	printf("%d",ans);
	return 0;
}


Measured memory_bytes: 256
import sys
 
n = int(input())
a = list(map(int, input().split()))
aa = [0]
for i in range(n):
    aa.append(aa[i] + a[i])
 
ans = sys.maxsize
 
def getdiff(left, center, right):
    return abs((aa[center] - aa[left]) - (aa[right] - aa[center]))
 
L = 1
R = 3
 
for C in range(2, n):
    while L + 1 < C and getdiff(0, L, C) > getdiff(0, L + 1, C):
        L += 1
    while R + 1 < n and getdiff(C, R, n) > getdiff(C, R + 1, n):
        R += 1
    pqrs = [aa[L], aa[C] - aa[L], aa[R] - aa[C], aa[n] - aa[R]]
    pqrs.sort()
    ans = min(ans, pqrs[3] - pqrs[0])
 
print(ans)

Measured memory_bytes: 24672
#import pysnooper
#import os,re,sys,operator,math,heapq,string
from collections import Counter,deque
#from operator import itemgetter
#from itertools import accumulate,combinations,groupby,combinations_with_replacement,permutations
from sys import stdin,setrecursionlimit
#from copy import deepcopy

setrecursionlimit(10**6)
input=stdin.readline

n=int(input().rstrip())
hanako,taro=0,0
for _ in range(n):
    t,h=input().split()
    if t==h:
        hanako+=1
        taro+=1
    elif t>h:
        taro+=3
    else:
        hanako+=3
print(taro,hanako)


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

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


Measured memory_bytes: 3080
import sys
sys.setrecursionlimit(10**9)

N = int(input())

G = [[] for i in range(N)]
for i in range(N-1):
    a, b = map(int, input().split())
    G[a-1].append([b-1,i])

ans = [None]*(N-1)

# 引数：今回の基準頂点、前回の基準頂点と今回の頂点を結ぶ辺の色番号
def func(ver, color):
    # 色番号。まずは最低の番号から始める。もし今回と前回の基準頂点の色番号1の場合は後で色番号変更
    cnt = 1
    # for (基準頂点と繋がっている頂点, 辺の番号) in 基準頂点
    for (to, i) in G[ver]:
        # 既使用（前回の基準頂点と今回の頂点を結ぶ辺の色）と今回使う色番号が同じなら+1で色番号変更
        if cnt==color:
            cnt += 1
        # i番目の辺における色番号
        ans[i] = cnt
        # 今回の頂点と、今回の頂点と基準頂点の辺の色番号を入力し、今回の頂点を次の基準頂点にする
        func(to, cnt)
        # 今回の基準頂点と繋がる次の頂点の処理をするために色番号変更
        cnt += 1

func(0, 0)

print(max(ans))

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

Measured memory_bytes: 70992
#include <stdio.h>
#include <bitset>
using namespace std;
const int N=8;
char c[N][N];
bitset<N*10> u,d,l,r;
bool dfs(int now){
    if(now>=N)return true;
    if(d[now])return dfs(now+1);
    for(int i=0;i<N;i++)if(!u[i]&&!l[i+now]&&!r[i-now+10]){
        c[now][i]='Q';
        u[i]=l[i+now]=r[i-now+10]=true;
        if(dfs(now+1))return true;
        u[i]=l[i+now]=r[i-now+10]=false;
        c[now][i]='.';
    }
    return false;
}
int main(){
    int n,x,y;
    scanf("%d",&n);
    for(int i=0;i<N;i++)for(int j=0;j<N;j++)c[i][j]='.';
    u.reset();
    r.reset();
    d.reset();
    l.reset();
    while(n--){
        scanf("%d%d",&x,&y);
        c[x][y]='Q';
        d[x]=u[y]=l[x+y]=r[y-x+10]=true;
    }
    dfs(0);
    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++)printf("%c",c[i][j]);
        printf("\n");
    }
}


Measured memory_bytes: 2684
import java.util.*;

public class Main {

    static final int MOD = 1000000007;

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt(),a=sc.nextInt(),b=sc.nextInt();
        x-=a;
        x=x%b;
        System.out.println(x);
    }
}


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

namespace ConsoleApp5
{
    class Program
    {

        static void Main(string[] args)
        {
            String S = Console.ReadLine();
            String[] line = S.Split(' ');
            long N = long.Parse(line[0]);
            long M = long.Parse(line[1]);
            long[] A = new long[N];
            long count = 0;

            S = Console.ReadLine();
            line = S.Split(' ');

            for (long i = 0; i < N; i++)
            {
                A[i] = long.Parse(line[i]);
            }

            long sum = A.Sum();

            for (long i = 0; i < N; i++)
            {
                if (A[i] >= sum / (4.0 * M))
                {
                    count++;
                }
            }

            if (count >= M)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }

        }
    }
}

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

struct S{
	string s;
	int p;
	int city;
};

int cmp(S x,S y){
	if(x.s==y.s) return x.p>y.p;
	return x.s<y.s;
}

int main(int argc , char* argv[]){
	int n; cin >> n;
	S __r[n+1];
	for(int i=1;i<=n;++i){
		cin >> __r[i].s >> __r[i].p;
		__r[i].city=i;
	}
	sort(__r+1,__r+n+1,cmp);
	for(int i=1;i<=n;++i) cout <<__r[i].city << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define rep(i,n) for(ll i = 0; i < (ll)(n); i++)
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; }
const ll INF = 1LL << 60;
int main(){
    string s;
    int k;
    cin >> s >> k;
    int tot = 0;
    int se = 1;
    int n = s.size();
    int a=0,b=0;
    bool start = true;
    rep(i,n){
        if(!i) continue;
        if(s[i]==s[i-1])se++;
        else {
            if(tot==0 && start) {
                a = se;
                start = false;
            }
            tot += se/2;
            se=1;
        }
    }
    b = se;
    tot += b/2;
    ll ans = (ll)tot*k;
    if(s[0]==s[n-1]){
        if(a+b!=n){
            ans -= (a/2 + b/2)*(k-1);
            ans += ((a+b)/2)*(k-1);
        }else{
            ans = (ll)n*k/2;
        }
        
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define INF 1e9
#define MOD 1e9+7
#define fastio ios_base::sync_with_stdio(0),cin.tie(0)
#define debug(x) cout << x << endl

int main(){
	int in[4];
	cin >> in[0] >> in[1] >> in[2];
	sort(in,in+3);
	int k;
	cin >> k;
	long long kali=1;
	for (int i=0;i<k;i++){
		kali*=2;
	}
	long long ans=in[0]+in[1]+(in[2]*kali);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstring>
#include <iterator>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <fstream>
#include <iomanip>
#include <cassert>
//#include <utility>
//#include <memory>
//#include <functional>
//#include <deque>
//#include <cctype>
//#include <ctime>
//#include <numeric>
//#include <list>
//#include <iomanip>
 
//#if __cplusplus >= 201103L
//#include <array>
//#include <tuple>
//#include <initializer_list>
//#include <forward_list>
//
//#define cauto const auto&
//#else
 
//#endif
 
using namespace std;
 
 
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
 
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
 
#define VV(T) vector<vector< T > >
 
template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}
 
template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}
 
#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define F first
#define S second
#define mkp make_pair
#define RALL(v) (v).rbegin(),(v).rend()
#define DEBUG
#ifdef DEBUG
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#else
#define dump(x) 
#define debug(x) 
#endif
 
#define MOD 1000000007LL
#define EPS 1e-8
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)
 
void mainmain(){
    string s;
    cin>>s;
    int n = s.size();
    int a = 0;
    int ans = n;
    rep(i,n){
        if(s[i] == 'S'){
            a++;
        }
        else{
            if(a){
                a--;
                ans-=2;
            }
        }
    }
    cout<<ans<<endl;
}
 
 
signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(20);
    mainmain();
}

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

using namespace std;

int64_t f(int64_t n){
    int64_t ans=0;
    
ans = (1+n)*n/2;

    return ans;
}

int main(){
    int64_t n,ans=0;
    cin >>n;
    ans=f(n) - f(n/3) *3 - f(n/5)*5 + f(n/15)*15; 
    cout << ans <<endl;

}


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

mod = 10**9+7
s = 0
nizyo = 0

for i in range(n):
    s += a[i]
    #s %= mod

for i in range(n):
    nizyo += a[i]**2
    #nizyo %= mod

print(((s**2 - nizyo)//2)%mod)

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


int main(){
    string s="ACL";
    int n;
    cin>>n;
    rep(i,n) cout<<s;
    return 0;
}


Measured memory_bytes: 3628