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

public class Main{

	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		int ABCD = scn.nextInt();
		int A = ABCD/1000;
		int B = (ABCD%1000)/100;
		int C = (ABCD%100)/10;
		int D = ABCD%10;
		
		
		if(A+B+C+D==7) {
			System.out.println(A+"+" + B + "+" + C + "+" + D + "=" + 7);
			return;
		}
		if(A+B+C-D==7) {
			System.out.println(A+"+" + B + "+" + C + "-" + D + "=" + 7);
			return;
		}
		if(A+B-C+D==7) {
			System.out.println(A+"+" + B + "-" + C + "+" + D + "=" + 7);
			return;
		}
		if(A+B-C-D==7) {
			System.out.println(A+"+" + B + "-" + C + "-" + D + "=" + 7);
			return;
		}
		if(A-B+C+D==7) {
			System.out.println(A+"-" + B + "+" + C + "+" + D + "=" + 7);
			return;
		}
		if(A-B+C-D==7) {
			System.out.println(A+"-" + B + "+" + C + "-" + D + "=" + 7);
			return;
		}
		if(A-B-C+D==7) {
			System.out.println(A+"-" + B + "-" + C + "+" + D + "=" + 7);
			return;
		}
		if(A-B-C-D==7) {
			System.out.println(A+"-" + B + "-" + C + "-" + D + "=" + 7);
			return;
		}
	}

}


Measured memory_bytes: 23252
ord_a = ord('a')

ss = input()
K = int(input())

As = [ord(s) - ord_a for s in ss]

anss = []
for A in As[:-1]:
    num = 26 - A
    if A == 0 or K < num:
        anss.append(A)
    else:
        anss.append(0)
        K -= num

anss.append((As[-1] + K) % 26)

print(''.join([chr(ans + ord_a) for ans in anss]))


Measured memory_bytes: 6284
def div(n, d):
    cnt = 0
    while n % d == 0 and cnt < 18:
        n //= d
        cnt += 1
    return cnt


n = int(input())
dp = [[0]*19 for _ in range(19)]
#dp[i][j] -> 2の素因数がi以上,5の素因数がj以上の数字の数

ans = 0
for _ in range(n):
    x = round(float(input()) * pow(10, 9))
    two = div(x, 2)
    five = div(x, 5)
    ans += dp[18 - two][18 - five]
    for i in range(two + 1):
        for j in range(five + 1):
            dp[i][j] += 1

print(ans)


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

int main() {
  int a, b;
  cin >> a >> b;
  int n = 1;
  int ans = 0;
  while(true) {
    if(n >= b) {
      cout << ans << endl;
      break;
    }
    n += a-1;
    ans ++;
  }
  return 0;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
syoji = 1000
kabu = 0
kai = 0
uri = 0
if N ==1:
  print(syoji)
  exit()
sw = 0
for i in range(N):
  if i<N-1 and kabu == 0 and A[i] < A [i+1]:
    for j in range(i+1,N):
      if sw ==1 and uri >= A[j]:
        break
 
      elif  A[i] < A[j]:
        uri = A[j]
        sw = 1
    if sw ==1:
      kabu = syoji // A[i]
      syoji = syoji - kabu*A[i]
      kai = A[i]
      sw = 0
  elif kabu > 0 and A[i]==uri:
    syoji = syoji + kabu*A[i]
    kabu = 0
    uri = 0
 
        
print(syoji)

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

#define MAX_VERTEX 100
#define INF 1000000

int vertex_num; // ???????????°
int d[MAX_VERTEX][MAX_VERTEX];  // ???????????¢???d[?§????][??????]??§?§??????????????????????????????¢?????¨???

void Input() {
  cin >> vertex_num;

  // (a1) ??\???????????¶??§?????????
  // d?????¨???INF?????????????§??????¨????????????????????´???0
  for (int i = 0; i < vertex_num; i++) {
    for (int j = 0; j < vertex_num; j++) {
      d[i][j] = i == j ? 0 : INF;
    }
  }

  for (int i = 0; i < vertex_num; i++) {
    int vertex, out;
    cin >> vertex >> out;
    for(int j = 0; j < out; j++) {
      int to, c;
      cin >> to >> c;
      d[vertex][to] = c;
    }
  }
}

void WarshallFloyd() {
  for (int k = 0; k < vertex_num; k++) {
    for (int i = 0; i < vertex_num; i++) {
      for (int j = 0; j < vertex_num; j++) {
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
      }
    }
  }
}

void Output() {
  for(int i = 0; i < vertex_num; i++) {
    cout << i << " " << d[0][i] << endl;
  }
}

int main() {

  Input();
  WarshallFloyd();
  Output();

  return 0;
}

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

int main(){
    int k; cin>>k;
    string s; cin>>s;
    if(s.size()<=k) cout<<s<<endl;
    else{
        rep(i,k) cout<<s[i];
        cout<<"..."<<endl;
    }
    return 0;
}


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

using namespace std;

int main() {
  int N;
  cin >> N;

  int result = 0;
  for (int a = 1; a <= N; a *= 100) {
    int b = a * 10 - 1;
    result += min(N, b) - a + 1;
  }
  cout << result << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int f(int a){
  int k=0;
  while(a>0)k+=a%10,a/=10;
  return k;
}
main(){
  int n,a=1,m=99;
  cin>>n;
  for(;a<n;a++)m=min(m,f(a)+f(n-a));
  cout<<m;
}

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

int main() {
	int n; cin >> n;
	vector<int>h(n); for (auto&& x : h)cin >> x;

	for (int i = n - 1; i > 0; i--) {
		if (h[i - 1] <= h[i]);
		else {
			if (h[i - 1] - 1 <= h[i])h[i - 1]--;
			else { cout << "No" << endl; return 0; }
		}
	}
	cout << "Yes" << endl;

	return 0;
}

Measured memory_bytes: 640
object Main {
  def main(args:Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)
    val W = sc.nextInt
    val H = sc.nextInt
    val x = sc.nextInt
    val y = sc.nextInt
    val r = sc.nextInt
    println(if(x-r >= 0 && y-r >= 0 && x+r <= W && y+r <= H)"Yes" else "No")
  }
}

Measured memory_bytes: 44800
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vi2 = vector<vector<int>>;
using vb = vector<bool>;
using vb2 = vector<vector<bool>>;
using vc = vector<char>;
using vc2 = vector<vector<char>>;
using vs = vector<string>;
using si = set<int>;
using vs2 = vector<vector<string>>;
using pii = pair<int, int>;
using mii = map<int, int>;
const int INF = 1e9;
const ll LINF = 1e18;
#define MP(a,b) make_pair((a),(b))
#define MT(...) make_tuple(__VA_ARGS__)
#define sz(x) (int)(x).size()

#define FOR(i,a,b) for(int i=(a);i<(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 ALL(x) (x).begin(),(x).end()
#define IN(type,a) type a;cin >> a
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define COUT(x) cout << (x) << endl
#define DCOUT(x,n) cout << fixed << setprecision(n) << (x) << endl
template<typename T>inline istream& operator>>(istream&i,vector<T>&v)
{REP(j,sz(v))i>>v[j];return i;}
template<typename T>
T gcd(T x, T y){
    if ((x==1)||(y==1)) return 1;
    if (x>y) {
        if (x%y==0) {
            return y;
        }else{
            return gcd(y, x%y);
        }
    }else{
        if (y%x==0) {
            return x;
        }else{
            return gcd(x, y%x);
        }
    }
}

int main() {
    IN(string, s);
    if (s=="ABC") {
        COUT("ARC");
    }else {
        COUT("ABC");
    }
}


Measured memory_bytes: 3620
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;

double dist(double x1,double y1,double z1,double x2,double y2,double z2){
    return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)+(z1-z2)*(z1-z2));
}

const double INF=(double)(1<<30);
double G[100][100];
double mindist[100];
bool used[100];
double x[100],y[100],z[100],r[100];

int main(){
    int n, i, j;
    while(cin>>n,n){
        for(i=0;i<n;i++) cin>>x[i]>>y[i]>>z[i]>>r[i];
        for(i=0;i<n;i++){
            for(j=0;j<n;j++){
                double d=dist(x[i],y[i],z[i],x[j],y[j],z[j]);
                G[i][j]=d-r[i]-r[j]>=0?d-r[i]-r[j]:0.0;
            }
        }
        double ans=0.0;
        for(i=0;i<n;i++){
            mindist[i]=G[0][i];
            used[i]=false;
        }
        used[0]=true;
        for(i=0;i<n;i++){
            int id=-1;
            double m=INF;
            for(j=0;j<n;j++){
                if(used[j]) continue;
                if(mindist[j]<m){
                    m=mindist[j];id=j;
                }
            }
            if(id==-1)break;
            used[id]=true;
            ans+=m;
            for(j=0;j<n;j++)
                mindist[j]=min(mindist[j],G[id][j]);
        }
        printf("%.3lf\n",ans);
    }
    return 0;
}

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

int main() {
	ll n, k;
	cin >> n >> k;
	vector<ll> a(n);
	rep(i, n) {
		cin >> a[i];
		a[i]--;
	}
	set<ll> st;
	vector<ll> r;
	ll now = 0;
	ll last;
	while(1) {
		if(st.count(now)) {
			last = now;
			break;
		} else {
			st.insert(now);
			r.push_back(now);
			now = a[now];
		}
	}
	ll roop = st.size();
	ll pre = 0;
	rep(i, n) {
		if ( r[i] == last) break;
		
		pre++;
	}
	vector<ll> ro;
	rep(i, r.size()) {
		if(pre > i) continue;
		ro.push_back(r[i]);
	}
	if(k < pre) {
		cout << r[k]+1 << endl;
		return 0;
	}
	k -= pre;
	
	cout << ro[k%ro.size()] + 1 << endl;
	// for(int t: ro) cout << t << endl;
	return 0;
}

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

int main(){
    int n,k;

    cin >> n >> k;
    vector<int> data(n);
    for (int i = 0; i < n; i++) {
        cin >> data.at(i);
    }
    int ans=0;
    sort(data.begin(), data.end());
    for(int j=n-1;j>(n-k-1);j--){
        ans += data.at(j);
    }

    cout << ans << endl;

    return 0;
}

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

int main() {
  int N;
  cin >> N;

  vector<int> p(N+1);  
  for (int i = 2; i <= N; i++) {
    cin >> p.at(i);
  }

  // 組織の関係から2次元配列を作る
  vector<vector<int>> children(N+1);  // ある組織の子組織の番号一覧
  for (int i = 2; i <= N; i++) {
    int parent = p.at(i);  // i番の親組織の番号
    children.at(parent).push_back(i);  // parentの子組織一覧にi番を追加
  }

  for (int i = 1; i <= N; i++) {
     cout << children.at(i).size() << endl;
  }
}


Measured memory_bytes: 14780
from math import factorial
n,a,b = map(int,input().split())
mod = 10**9 + 7

def func(a,n,p):
  bi=str(format(n,"b"))
  res=1
  for i in range(len(bi)):
    res=(res*res) %p
    if bi[i]=="1":
      res=(res*a) %p
  return res
def egcd(a, b):
    if a == 0:
        return b, 0, 1
    else:
        g, y, x = egcd(b % a, a)
        return g, x - (b // a) * y, y
def modinv(a, m):
    g, x, y = egcd(a, m)
    if g != 1:
        raise Exception('modular inverse does not exist')
    else:
        return x % m
def cmb(n, r, mod):
    r = min(r, n-r)
    res = 1
    for i in range(r):
        res = res * (n - i) * modinv(i+1, mod) % mod
    return res
  
print((func(2,n,mod)-cmb(n,a,mod)-cmb(n,b,mod)-1)%mod)

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

int main() {
    int A, B;
    cin >> A >> B;
    int ans = 0;
    if (A >= 13){
    	ans = B;
    }else if (A > 5){
    	ans = B / 2;
    }else{
    	ans = 0;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string>
#include <algorithm>
#include <string.h>
using namespace std;
 
int main(){
    
    int H,W,N=0;
    char S[55][55]={};

    cin >> H >> W;

    for(int i=1;i<=H;i++){
        for(int j=1;j<=W;j++){
            cin >> S[i][j];
        }
    }

    for(int i=1;i<=H;i++){
        for(int j=1;j<=W;j++){

            if(S[i][j]=='#'){

                if(S[i-1][j]!='#'&&S[i+1][j]!='#'&&S[i][j-1]!='#'&&S[i][j+1]!='#')N=1;

            }

        }
    }

    if(N==1){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;
int n;
int a;
int m = 0x7fffffff;
int d = 0x80000000;

int main()
{
	cin >> n;
	cin >> m;
	
	for(int i =1; i<n; i++)
	{
		cin >> a;
		int dd = a - m;
		if (dd > d) d = dd;
		if (a < m) m = a;
	}
	
	cout << d << endl;
	
	return 0;
}

Measured memory_bytes: 1160
r, g, b = map(int, input().split())
k = int(input())

flag = False

count = 0
while count < k:
    count += 1
    if r < g * (2 ** (k - count)) < b * (2 ** count):
        #print("A", r, g * (2 ** (k - count)), b * (2 ** count))
        flag = True
        break

count = 0
while count < k:
    count += 1
    if r * (2 ** (k - count)) < g < b * (2 ** count):
        #print("B", r * (2 ** (k - count)), g, b * (2 ** count), count)
        flag = True
        break

count = 0
while count < k:
    count += 1
    if r * (2 ** (k - count)) < g * (2 ** count) < b:
        #print("C", r * (2 ** (k - count)), g * (2 ** count), b)
        flag = True
        break

if flag == True:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 9200
#include <bits/stdc++.h>
using namespace std;
using namespace std::chrono;
#define idfc ios_base::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)
//#define ll long long
#define pb emplace_back
#define mp make_pair
#define nt _ll128
#define ld long double
long double PI =3.14159265358979323846;
using ll = long long;



const ll modo=1e9+7;
const ll inf=LONG_LONG_MAX;
const ll ms=(1e7)+5;


int cost[20];
int ar[20][20];
int br[20];

int main() {
    idfc;

    int n, m, x;
    cin >> n >> m >> x;
    int i, j;
    for (i = 0; i < n; i++) {
        cin >> cost[i];
        for (j = 0; j < m; j++) {
            cin >> ar[i][j];
        }
    }

    int c;
    int lim = 1 << n;
    int ans=INT_MAX; int k; int fl;
    for (i = 0; i < lim; i++)
    {
        c=0;fl=1;
        for(j=0;j<m;j++)br[j]=0;
        for(j=0;j<n;j++)
        {
            if((i&(1<<j)))
            {
                c+=cost[j];
                for(k=0;k<m;k++)
                {
                    br[k]+=ar[j][k];
                }
            }
        }
        for(j=0;j<m;j++)
        {
            if(x>br[j])fl=0;
        }
        if(fl)ans=min(ans,c);
    }
    if(ans==INT_MAX)cout<<-1;
    else cout<<ans;

    return 0;
}

Measured memory_bytes: 3652
import java.util.*;
public class Main{
  static Scanner sc = new Scanner(System.in);
  public static void main(String [] args){
    int e;
    while(true){
      e = sc.nextInt();
      if(e == 0)break;
      System.out.println(solve(e));
    }
  }
  static int solve(int e){
    double x,y,z,res;
    int ans = e;
    double m;
    double Cz;
    for(z = 0; Math.pow(z, 3) <= e ;z++){
      Cz = Math.pow(z,3);
      for(y = 0; Math.pow(y, 2) <= e - Cz; y++){
        x = e - (Cz + Math.pow(y, 2));
        m = x + y + z;
        if(ans > m) ans = (int)m;
      }
    }
    return ans;
  }
}

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

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

    int n;
    long long sol = 1;
    string a, b;
    cin >> n >> a >> b;

    for (int i = 0; i < n; ++i)
    {
        if (a[i] == b[i])
        {
            if (i == 0)
                sol *= 3;
            else if (a[i - 1] == b[i - 1])
                sol *= 2;
            sol %= 1000000007;
        }
        else
        {
            if (i == 0)
                sol *= 6;
            else if (a[i - 1] == b[i - 1])
                sol *= 2;
            else
                sol *= 3;
            sol %= 1000000007;
            ++i;
        }
    }

    cout << sol << '\n';
}

Measured memory_bytes: 256
def merge_sort(arr, left, right)
  return 0 unless left + 1 < right

  count = 0

  mid = (left + right) / 2

  count += merge_sort(arr, left, mid)
  count += merge_sort(arr, mid, right)
  count += merge(arr, left, mid, right)

  count
end

def merge(arr, left, mid, right)
  n1 = mid - left
  n2 = right - mid

  left_arr = arr[left, n1]
  right_arr = arr[mid, n2]

  left_arr << Float::INFINITY
  right_arr << Float::INFINITY

  i = j = 0
  k = left
  count = 0

  while k < right
    if left_arr[i] <= right_arr[j]
      arr[k] = left_arr[i]
      i += 1
    else
      arr[k] = right_arr[j]
      j += 1
    end

    count += 1
    k += 1
  end

  count
end

if $PROGRAM_NAME == __FILE__
  n = gets.to_i

  arr = gets.chomp.split.map(&:to_i)

  count = merge_sort(arr, 0, n)

  puts arr.join(' ')
  puts count
end

Measured memory_bytes: 68488
#include <stdio.h>
#include <stdlib.h>

typedef long value_type; /* ソートするキーの型 */

value_type med3(value_type x, value_type y, value_type z)
/* x, y, z の中間値を返す */
{
    if (x < y)
        if (y < z) return y; else if (z < x) return x; else return z; else
        if (z < y) return y; else if (x < z) return x; else return z;
}

//aの値を基準にしてquicksort
void quicksort(value_type a[], value_type b[], int left, int right){
    if (left < right) {
        int i = left, j = right;
        value_type tmp, pivot = med3(a[i], a[i + (j - i) / 2], a[j]); /* (i+j)/2ではオーバーフローしてしまう */
        while (1) { /* a[] を pivot 以上と以下の集まりに分割する */
            while (a[i] < pivot) i++; /* a[i] >= pivot となる位置を検索 */
            while (pivot < a[j]) j--; /* a[j] <= pivot となる位置を検索 */
            if (i >= j) break;
            tmp = a[i]; a[i] = a[j]; a[j] = tmp; /* a[i],a[j] を交換 */
            tmp = b[i]; b[i] = b[j]; b[j] = tmp;
            i++; j--;
        }
        quicksort(a, b, left, i - 1);  /* 分割した左を再帰的にソート */
        quicksort(a, b, j + 1, right); /* 分割した右を再帰的にソート */
    }
}

int main(void){
    int N;
    scanf("%d", &N);
    long a[N];
    long b[N];
    int flag = 1;
    for(int i = 0; i < N; i++){
        scanf("%ld%ld", &a[i], &b[i]);
    }
    quicksort(b, a, 0, N-1);
    long time_now = 0;
    for(int i = 0; i < N ; i++){
        time_now += a[i];
        if(b[i] < time_now){
            flag = 0; break;
        }
    }
    printf("%s\n", (flag == 1) ? "Yes" : "No");
    return 0; 
}


Measured memory_bytes: 3328
/*
    Author - Param Kothari
    Ah shit, here we go again
*/

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

#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back
#define mk make_pair

typedef long long ll;
typedef long double ld;

void solve(){
    string s;
    cin >> s;
    int res = 0, curr = 0;
    for(int i = 0; i < 3; i++){
        if(s[i] == 'R'){
            curr++;
        }
        else{
            res = max(res, curr);
            curr = 0;
        }
    }
    res = max(res, curr);
    cout << res << "\n";
    return;
}

int main(){
    IOS;
    int t = 1;
    // cin >> t;
    for(int i = 1; i <= t; i++){
        solve();
    }
    return 0;
}

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

int main(){
    int x;
    cin >> x;
    if (x) cout << 0 << endl;
    else cout << 1 << endl;
}

Measured memory_bytes: 3632
#include<stdio.h>
#include<iostream>
#include<string.h>
using namespace std;
//int n,num[15],r,count;
int n,r,count=0;

void change( int n,int r )
{
     if( n )
     {
         change( n / r, r );
         count++;
     }
 }
int main( )
{
    scanf( "%d%d",&n,&r );
    {
           if( n < 0 )
               printf( "-" ),n = -n;
           change(n,r);
           cout<<count<<endl;
           }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,start,end) for(int i=start;i<=end;i++)
const int INF = 1001001001;
typedef long long ll;
const ll MOD=1000000007;
using namespace std;
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; }
template<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>U COUNT(const T& a, const U& v) { return count(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }

int main(void){
    // Your code here!
    int n; cin >> n;
    ll ans = 1;
    rep(i,n){
        ans*=i+1;
        ans%=MOD;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }


using namespace std;

int main(){

    int N, C;
    cin >> N >> C;
    int D[C+1][C+1];
    int color[N+1][N+1];
    rep(i, C) {
        rep(j, C) {
            cin >> D[i][j];
        }
    }

    rep(i, N){
        rep(j, N){
            cin >> color[i][j];
            color[i][j]--;
        }
    }

    ll ans = 1000000000000000;

    ll cost[3][C];

    rep(i, 3) {
        rep(j, C) {
            cost[i][j] = 0;
        }
    }

    rep(i, C) {
        rep(a, N) {
            rep(b, N) {
                if (color[a][b] != i ) {
                    cost[(a+b)%3][i] += D[color[a][b]][i];
                }
            }
        }
    }
    rep(i, C) {
        rep(j, C) {
            rep(k, C) {
                if (i == j || j == k || k == i) {
                    continue;
                }


                chmin(ans, cost[0][i] + cost[1][j] + cost[2][k]);
            }
        }
    }



    cout << ans << endl;

}

Measured memory_bytes: 1280
//------------------------------>> tsukasa_diary's template <<------------------------------//
#include <bits/stdc++.h>
using namespace std;

using lint = long long;
using pii = pair< int, int >;

template< typename T > using Vec = vector< T >;

template< typename T > bool inRange(T x, T lb, T ub) { return lb <= x && x < ub; }
template< typename T > bool inRange(T x, T y, T lb, T ub) { return in_range(x, lb, ub) && in_range(y, lb, ub); }

template< typename T > void modAdd(T& a, T b, T mod) { a = (a + b + mod) % mod; }
template< typename T > void modMul(T& a, T b, T mod) { a = (a * b) % mod; }
template< typename T > void minUpdate(T& a, T b) { a = min(a, b); }
template< typename T > void maxUpdate(T& a, T b) { a = max(a, b); }

int bitCount(int x) { return __builtin_popcount(x); }
int bitCount(lint x) { return __builtin_popcountll(x); }

const int dx[4] = {0,1,0,-1}, dy[4] = {-1,0,1,0};
const int Dx[8] = {0,1,1,1,0,-1,-1,-1}, Dy[8] = {-1,-1,0,1,1,1,0,-1};
const double EPS = 1e-9;
const double PI = acos(-1);

//--------------8---------------->> coding space <<-----------------8-------------//



int main() {
	int N;
	cin >> N;
	using psi = pair< string, pii >;
	set< psi > store;
	for (int i=0; i<N; ++i) {
		string S;
		int P;
		cin >> S >> P;
		store.insert(psi(S, pii(-P, i)));
	}
	for (psi p : store) cout << p.second.second + 1 << endl;
}
//--------------8---------------->> coding space <<-----------------8-------------//

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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define ANS(n) cout << (n) << endl
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)
#define mp make_pair

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int32 n;
    cin >> n;
    vector<int32> dist(n, -1);
    vector<vector<pii>> es(n);
    REP(i,n-1){
        int32 u,v,w;
        cin >> u >> v >> w;
        u--;v--;w %= 2;
        es[u].pb(mp(v,w));
        es[v].pb(mp(u,w));
    }
    stack<int32> st;
    st.push(0);
    dist[0] = 0;
    while(!st.empty()){
        int32 cur = st.top();st.pop();
        REP(i,es[cur].size()){
            int32 next, w;
            tie(next, w) = es[cur][i];
            if(dist[next] != -1)continue;
            dist[next] = dist[cur] + w;
            st.push(next);
        }
    }
    REP(i,n){
        ANS((dist[i] + dist[0]) % 2);
    }
    return 0;
}

Measured memory_bytes: 8704
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
typedef pair<int,int> Pint;
typedef pair<ll, ll> P;
//typedef pair<int, pair<int, int>> P;
//typedef tuple<int,int,int> T;
ll INFL = 1000000000000000010;//10^18 = 2^60
int INF = 2147483600;//10^9
ll MOD  = 1000000007;
vector<int> dy = {0,0,1,-1};
vector<int> dx = {1,-1,0,0};

//コンビネーション
const int MAXcomb = 200010;
ll fac[MAXcomb], finv[MAXcomb], inv[MAXcomb];
//facはn!,finvは1/n!
//invは逆元
void COMinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < MAXcomb; i++){
        fac[i] = fac[i-1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
        finv[i] = finv[i-1] * inv[i] % MOD;
    }
}
ll comb(int n, int k){
    if(n < k) return 0;
    if(n < 0 || k < 0) return 0;
    return fac[n] * finv[k] % MOD * finv[n-k] % MOD;
}

ll gcd(ll a, ll b){//計算量はO(log(max(a,b))
    if(b == 0) return a;
    return gcd(b, a % b);
}

int main(void){
    int N;
    cin >> N;
    vector<ll> A(N);
    for(int i = 0; i < N; i++ )cin >> A[i];
    
    vector<ll> fromLeft(N);
    vector<ll> fromRight(N);
    
    fromLeft[0] = A[0];
    for(int i = 1; i < N; i++){
        fromLeft[i] = gcd(fromLeft[i-1], A[i]);
    }
    fromRight[0] = A[N-1];
    for(int i = 1; i < N; i++){
        fromRight[i] = gcd(fromRight[i-1], A[N-1-i]);
    }
    
    ll ans = 1;
    for(int i = 0; i < N-2; i++){
        ans = max(ans, gcd(fromLeft[i], fromRight[N-3-i]));
    }
    ans = max(ans, max(fromLeft[N-2], fromRight[N-2]));
    cout << ans << endl;
}

Measured memory_bytes: 2560
from itertools import permutations

D, G = map(int, input().split())
PC = []
for _ in range(D):
    p, c = map(int, input().split())
    PC.append((p, c))

ans = sum(p for p, _ in PC)
for ids in permutations(range(D)):
    score = 0
    num = 0
    for i in ids:
        p, c = PC[i]
        if score + (i + 1) * 100 * p + c < G:
            score += (i + 1) * 100 * p + c
            num += p
        else:
            for j in range(p):
                score += (i + 1) * 100
                num += 1
                if G <= score:
                    ans = min(ans, num)
                    break
            else:
                score += c
                if G <= score:
                    ans = min(ans, num)
        if G <= score:
            break
print(ans)

Measured memory_bytes: 73600
/****Author: Barish Namazov****/
#include <bits/stdc++.h>

using namespace std;

/***TEMPLATE***/
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()

#define F first
#define S second
#define pb push_back

#define endl '\n'

const int max4 = 10004;
const int maxx = 100005;
const int max6 = 1000006;
const int lg5 = 17;

const int INF = 2 * 1000000007;
const long long INFLL = 4LL * 1000000000 * 1000000000;

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

int powmod (int a, int b, int mod) {
    int res = 1; a %= mod;
    for (; b; b >>= 1) {
        if (b & 1) {
            res = 1LL * res * a % mod;
        }
        a = 1LL * a * a % mod;
    }
    return res;
}
#define ll long long
ll gcd (ll a, ll b) {
    while (b > 0) {
        ll t = a % b;
        a = b, b = t;
    }
    return a;
}

int lcm (int a, int b) {
    return (a / gcd (a, b)) * b;
}

int is_prime (int n) {
    if (n <= 1 || n > 3 && (n % 2 == 0 || n % 3 == 0))
        return 0;
    for (int i = 5, t = 2; i * i <= n; i += t, t = 6 - t)
        if (n % i == 0)
            return 0;
    return 1;
}

/******Don't forget to use long long when needed!!******/

int main() {
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    ios_base :: sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    int n, a, b;
    cin >> n >> a >> b;
    long long x = 1LL * (n - 1) * a + b;
    long long y = 1LL * (n - 1) * b + a;
    cout << max(0LL, y - x + 1) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define BIT(n) (1LL << (n))
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPB(i, n) for (int i = 0; i < BIT(n); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORA(i, n) for (auto &&i : n)
#define FORS(i, m, n) for (int i = m; i <= n; i++)
#define DEBUG(x) cerr << #x << ": " << x << "\n"
#define PRINTALL(V)    \
  for (auto v : (V)) { \
    cerr << v << " ";  \
  }                    \
  cerr << "\n";
#define ALL(v) v.begin(), v.end()
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define epb emplace_back
#define int long long
using namespace std;
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 (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> using vec = std::vector<T>;
template <class T> void print(const T &x) { cout << x << "\n"; }
const int MOD = 1000000007, INF = 1061109567;
const double EPS = 1e-10, PI = acos(-1.0);
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
signed main() {
  cin.tie(0), ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  if ((A + B) > (C + D)) {
    print("Left");
  } else if ((A + B) < (C + D)) {
    print("Right");
  } else {
    print("Balanced");
  }
}

Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<map>
#include<string>
#include<vector>
#include<iostream>
#pragma GCC optimize(2)
using namespace std;
typedef long long ll;
const ll INF=1000000000000005;
const ll maxn=1e6+5;
const int mod=998244353;
ll n,m,p;
ll x,y;
ll in[maxn/100];
int work()
{
    for(int i=1;i<=n;i++) if(in[i]>4||in[i]<=1) return 0;
    int a=0,b=0,c=0;//2 3 4
    for(int i=1;i<=n;i++)
    {
        if(in[i]==4) c++;
        else if(in[i]==3) b++;
        else a++;
    }
    if(a!=4) return 0;
    for(int i=1;i*i<=c;i++)
    {
        if(c%i==0)
        {
            int temp=c/i;
            if((temp+i)*2==b) return 1;
        }
    }
    return 0;
}
char s[1005],t[1005];
int main()
{
    scanf("%lld%lld",&n,&m);
    for(int i=1;i<=m;i++)
        s[i]=n+'0';
    for(int i=1;i<=n;i++)
        t[i]=m+'0';
    if(strcmp(s+1,t+1)>0) printf("%s\n",t+1);
    else printf("%s\n",s+1);
    return 0;
}
/***
***/


Measured memory_bytes: 256
/*
for (int i = 0; i < N; ++i){}

// 各桁の和を計算する関数
int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) { // n が 0 になるまで
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

sort(a, a + N, greater<int>());  // a[0:N] を大きい順にソート

int num[110] = {0};  // バケット
for (int i = 0; i < N; ++i) {
    num[d[i]]++;  // d[i] が 1 個増える
}

map<string, int> mp; // 連想配列 map<キー型, 値型> オブジェクト名
for (int i = 0; i < N; ++i) {
    auto itr = mp.find(s[i]);        // s[i] が設定されているか？
    if(itr != mp.end() ) {
         mp[s[i]] += 1;
    }
    else {
         mp[s[i]] += 1 ;
    }
}
stack<int> s;	//intをデータとするスタックを用意
s.push(1);		//{} -> {1}
printf("%d\n", s.top());	// 3
s.pop();

queue<int> que;	//intをデータとするキューを用意
que.push(1);		//{} -> {1}
printf("%d\n", que.front());	// 1
que.pop();
*/
#include <iostream>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>

using namespace std;

// #define for(i,a,b) for (int i=(a);i<(b);++i)
typedef long long ll;
typedef pair<int,int> point;
#define rep(i,n) for(i,0,n)
 
int main() {
	// 入力
	int H, W;
	cin >> H >> W;
	char a[H+1][W+1];
	for (int i = 0; i < H; ++i){
		for (int j = 0; j < W; ++j){
			cin >> a[i][j];
		}
	}	
	
	// 解法


	// for (int i = 0; i < H; ++i){
	// 	for (int j = 0; j < W; ++j){
	// 		cout << a[i][j];
	// 	}
	// 	cout << endl;
	// }
	
	char b[H+1][W+1];
	for (int j = 0; j < W; ++j){
		bool onlyW = true;
		for (int i = 0; i < H; ++i){
			if (a[i][j]=='#'){
				onlyW = false;
				break;
			}
		}
		if (onlyW){
			for (int i = 0; i < H; ++i) b[i][j] = '+';
		}
		else{
			for (int i = 0; i < H; ++i) b[i][j] = a[i][j];
		}
	}
	
	for (int i = 0; i < H; ++i){
		bool onlyW = true;
		for (int j = 0; j < W; ++j){
			if (a[i][j]=='#'){
				onlyW = false;
				break;
			}
		}
		if (onlyW){
			for (int j = 0; j < W; ++j) b[i][j] = '-';
		}
		else{
			for (int j = 0; j < W; ++j) b[i][j] = b[i][j];
		}
	}
	

	for (int i = 0; i < H; ++i){
		if (b[i][0]!='-'){
			for (int j = 0; j < W; ++j){
				if (b[i][j]!='+') cout << b[i][j];
			}
			cout << endl;
		}
	}
}
 


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vl;
#define INF __INT32_MAX__
#define LINF __LONG_LONG_MAX__

int main() {
    ll X;
    cin >> X;

    ll cnt = (X / 11) * 2;
    ll mod = X % 11;
    if (mod != 0) {
        if (mod <= 6) {
            cnt++;
        } else {
            cnt += 2;
        }
    }

    cout << cnt << endl;
}

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


int main()
{
   int w, h, x, y ;
   cin >> w >> h >> x >> y ;
   double ans = (double)w*h/2 ;
   int num = (w==x*2 && h==y*2) ? 1 : 0 ;
   printf("%.10f %d\n",ans, num) ;
    return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
#define MAX_N 100000

int main()
{
	int N;
	char S[MAX_N];
	int ans = 0;

	scanf("%d", &N);
	scanf("%s", S);

	char c = '0';

	for (int i = 0; i < N; ++i)
	{
		if (c == S[i])
		{
			continue;
		}

		else if (i == N-1)
		{
			ans++;
		}

		else
		{
			c = '0';
			ans++;
			if (S[i] == S[i+1])
			{
				c = S[i];
			}
		}
	}

	printf("%d\n", ans);
	return 0;
}




Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		
		Scanner scanner = new Scanner(System.in);
		String s = scanner.nextLine();
		int len = Integer.parseInt(s);
		
		int[] numbers = new int[len];
		for (int i = 0; i < numbers.length; i++) {
			numbers[i] = scanner.nextInt();
		}
		
		Main solution = new Main();
		int ans = 0;
		while (solution.checkEven(numbers)) {
			ans++;
			for (int i = 0; i < numbers.length; i++) {
				numbers[i] = numbers[i]/2;
			}
		}
		
		System.out.println(ans);
		
		scanner.close();
	}

	public int forwardCount(int[] numbers) {
		int res = 0;
		for (int i : numbers) {
			if (i % 2 == 0) {
				res++;
			}else{
				break;
			}
		}
		return res;
	}

	public boolean checkEven(int[] numbers) {
		boolean b = true;
		for (int i : numbers) {
			if (i % 2 != 0) {
				b = false;
			}
		}
		return b;
	}

}

Measured memory_bytes: 22100
def has_black_around(table, y, x):
    dxs = [0, 1, 0, -1]
    dys = [1, 0, -1, 0]

    for dx, dy in zip(dxs, dys):
        ny = y + dy
        nx = x + dx
        if table[ny][nx] == "#":
            return True
    return False


def solve(table, H, W):

    for y in range(1, H + 1):
        for x in range(1, W + 1):
            if table[y][x] == '#' and not has_black_around(table, y, x):
                return False
    return True


if __name__ == '__main__':
    H, W = map(int, input().split())

    table = [["@" for j in range(W + 2)] for i in range(H + 2)]

    for i in range(1, H + 1):
        table[i][1:W+1] = [ch for ch in input().strip()]

    answer = "Yes" if solve(table, H, W) else "No"

    print(answer)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
	int H, W;
	cin >> H >> W;
	int c[11][11];
	int a[H + 1][W + 1];
	for (int i = 0; i < 10; i++) {
		for (int j = 0; j < 10; j++) {
			cin >> c[i][j];
		}
	}
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			cin >> a[i][j];
		}
	}
	for (int k = 0; k < 10; k++) {
		for (int j = 0; j < 10; j++) {
			for (int i = 0; i < 10; i++) {
				c[i][j] = min(c[i][j], c[i][k] + c[k][j]);
			}
		}
	}
	ll ans = 0;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			if (a[i][j] != -1)ans += c[a[i][j]][1];
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 384
N, Q = map(int, input().split())
S = list(input())

countlist = [0 for i in range(N)]
for i in range(1, N):
    #print(S[i - 1:i + 1])
    countlist[i] = countlist[i - 1]
    if S[i - 1:i + 1] == ["A", "C"]:
        countlist[i] += 1

#print(countlist)
for i in range(Q):
    #print(i)
    l, r = map(int, input().split())
    l -= 1
    r -= 1
    ans = countlist[r] - countlist[l - 1]
    if S[l] == "C" and S[l - 1] == "A":
        #print(S[r], r)
        #print(100)
        ans -= 1
    if l == 0:
        ans = countlist[r]
    print(ans)
#print(countlist)

Measured memory_bytes: 6832
countMondai = gets.to_i;
aryBill = Array.new(4){Array.new(3){Array.new(10,0)}};

for num in 0..countMondai-1 do
	
	aryMondai = gets.split.map(&:to_i);
	
	aryBill[aryMondai[0]-1][aryMondai[1]-1][aryMondai[2]-1] += aryMondai[3];
	
end

for tou in 0..3 do
	for kai in 0..2 do
		for heya in 0..9 do
			
			print " " + aryBill[tou][kai][heya].to_s;
			
		end
		
		print "\r\n";
	end
	
	if tou != 3 then
		puts "####################";
	end
end

Measured memory_bytes: 8824
#include<stdio.h>
#include<stdlib.h>

int main(void){
  int x, y, a, b;
  scanf("%d",&x);
  scanf("%d",&y);
  for(a=0;a<=x;a++){
  	b=x-a;
    if(y==2*a+4*b){
      printf("Yes");
      return 0;
    }
  }
  printf("No");
 return 0;
}

Measured memory_bytes: 1700
#include<iostream>
#include<stack>
using namespace std;

typedef long long ll;

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

    ll h[n];
    for(int i = 0; i < n; i++)  cin >> h[i];

    stack<pair<int,ll>> s;

    ll ans = 0;
    for(int i = 0; i < n; i++){
        if(s.empty()){
            s.push({i, h[i]});
        }else if(s.top().second > h[i]){
            pair<int,ll> tmp;
            do{
                if(s.top().second <= h[i])  break;
                tmp = s.top();
                ans = max(ans, (i-tmp.first)*tmp.second );
                s.pop();
            }while(!s.empty());
            s.push({tmp.first, h[i]});
        }else if(s.top().second < h[i]){
            s.push({i, h[i]});
        }
    }

    while(!s.empty()){
        auto x = s.top(); s.pop();
        ans = max(ans, (n-x.first)*x.second);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 5272
#include "bits/stdc++.h"
using namespace std;

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

	int a = 0;
	cin >> a;

	string s;
	cin >> s;

	if (a >= 3200)
		cout << s;
	else
		cout << "red";

	return 0;
}

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

main(){
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif

    ios_base::sync_with_stdio(false);cin.tie(NULL);
    int x;cin>>x;
    cout<<1-x<<"\n";
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define repr(i, a, b) for(ll i = (a); i < (b); i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
const ll MOD = 1000000007;
const ll INF = 100000000000000000LL;
inline ll GCD(ll a, ll b){ return b?GCD(b, a % b):a; }
inline ll LCM(ll a, ll b){ return a/GCD(a, b)*b; }
inline ll powint(ll x, ll y){ ll r=1; while(y){ if(y&1) r*=x; x*=x; y>>=1; } return r; }
inline ll powmod(ll x, ll y, ll m = MOD){ ll r=1; while(y){ if(y&1) r*=x; x*=x; r%=m; x%=m; y>>=1; } return r; }
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; }
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll n;
    cin >> n;
    string s;
    cin >> s;
    vll wc(n);
    vll ec(n);
    wc[0] = 0;
    repr(i, 1, n){
        wc[i] = wc[i-1] + (s[i-1] == 'W');
    }
    ec[n-1] = 0;
    for(int i = n-2; i >= 0; i--){
        ec[i] = ec[i+1] + (s[i+1] == 'E');
    }
    dump(wc, ec);
    ll ans = INF;
    rep(i, n){
        chmin(ans, wc[i]+ec[i]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5396
# ARC062C - AtCoDeerくんと選挙速報 / AtCoDeer and Election Report (ABC046C)
def main():
    n = int(input())
    arr = tuple(tuple(map(int, input().rstrip().split())) for _ in range(n))
    t, a = 1, 1
    for i, j in arr:
        r = max((t - 1) // i + 1, (a - 1) // j + 1)
        t, a = i * r, j * r
    print(t + a)


if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std;
#define debug(x) cerr << #x << "=" << x << endl;
#define lgx cerr << "----------" << endl;
typedef long long LL;
const int MaxN = 1e5 + 10;

LL f[90];

void Sl() {
    memset(f, 0, sizeof(f));
    f[0] = 2, f[1] = 1;
    for (int i = 2; i <= 86; i++) {
        f[i] = f[i-1] + f[i-2];
    }
}

int main() {
    int n;
    Sl();
    while(cin >> n) {
        cout << f[n] << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
    int dom[4][3][10]={{{0}}}, n,i,j,k,b,f,r,v;

    scanf("%d",&n);

    for(i=0;i<n;i++) {
        scanf("%d%d%d%d",&b,&f,&r,&v);
        dom[b-1][f-1][r-1] += v;
    }

    for(i=0;i<4;i++) {
        for(j=0;j<3;j++) {
            for(k=0;k<10;k++)
                printf(" %d", dom[i][j][k]);
            printf("\n");
        }
        if (i!=3)
            printf("####################\n");
    }

    return 0;
}

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

#define int long long
//base:[Convex-Hull Trick - sataniC++](http://satanic0258.hatenablog.com/entry/2016/08/16/181331#fn-534591c8)
//追加する直線の傾きは単調（最小値なら傾きは単調減少、最大値なら傾きは単調増加）
template<typename T>
struct ConvecHullTrick {
  typedef pair<T,T> Line;
  vector<Line> lines; //直線（傾き，切片）
	bool isMonotonicX; //最小値(最大値)を求めるxが単調であるか
	function<bool(T l, T r)> comp; //最小/最大を判断する関数

	//flag:クエリは単調？　compFunc:求めるのは最大値？
	ConvecHullTrick(bool flagX=0,bool compFunc=0):isMonotonicX(flagX){
    if(compFunc)comp=[](T l,T r){return l<=r;};
    else comp=[](T l,T r){return l>=r;};
	};

	//直線l1,l2,l3のうちl2が不必要であるかどうか
	bool check(Line l1,Line l2,Line l3){
		if(l1<l3)swap(l1,l3);
    T a1=l1.first,a2=l2.first,a3=l3.first,b1=l1.second,b2=l2.second,b3=l3.second;
		return (b3-b2)*(a2-a1)>=(b2-b1)*(a3-a2);
	}

	//直線y=ax+bを追加する　単調性から付け足すのは一番後ろで、不必要なやつが消えるまで一番後ろを消したら付け足す
	void add(T a, T b) {
		Line line(a,b);
		while(lines.size()>=2&&check(*(lines.end()-2),lines.back(),line))lines.pop_back();
		lines.emplace_back(line);
	}

	//linesのi番目の直線のxでの値
	T f(int i,T x) {
		return lines[i].first*x+lines[i].second;
	}

	//特定のlineのxでの値
	T f(Line line,T x) {
		return line.first*x+line.second;
	}

	//直線群の中でxの時に最小(最大)となる値を返す
	T get(T x){
    assert(lines.size());
		if(isMonotonicX){//最小値(最大値)クエリにおけるxが単調（昇順）
			static int head=0;
			while(lines.size()-head>=2&&comp(f(head,x),f(head+1,x)))head++;
			return f(head,x);
		}
		else{
			int low=-1,high=lines.size()-1;
			while(high-low>1){
				int mid=(high+low)>>1;
				if(comp(f(mid,x),f(mid+1,x)))low=mid;
        else high=mid;
			}
			return f(high,x);
		}
	}
};
int dp[223456];

signed main(){
  int n,c;cin>>n>>c;
  ConvecHullTrick<int> CHT(1,0);
  for(int i=0;i<n;i++){
    int h;cin>>h;
    int res=0;
    if(i)res=CHT.get(h)+h*h+c;
    if(i==n-1)cout<<res<<endl;
    else CHT.add(-2*h,res+h*h);
  }
}


Measured memory_bytes: 6512
#include <bits/stdc++.h>
using namespace std;
#define int long long
using ll=long long;
using vi=vector<int>;
using pii=pair<int,int>;
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define SZ(c) ((int)c.size())
#define CONTAIN(c,x) (c.find(x)!=end(c))
#define OUTOFRANGE(y,x,h,w) (y<0||x<0||y>=h||x>=w)
#define dump(...)
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
#define INF (1001001001)
#define INFLL (1001001001001001001ll)
template<class T> ostream& operator << (ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v)) os << *i << (i==end(v)-1 ? "" : "\n"); return os; }
template<class T> istream& operator >> (istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is >> *i; return is; }
template<class T> istream& operator >> (istream &is, pair<T,T> &p) {
        is >> p.first >> p.second; return is; }
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;}
//------------------------------------------------------------------------------
struct before_main_function {
    before_main_function() {
        #ifdef int
            #undef INF
            #define INF INFLL
            #define stoi stoll
        #endif
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(15)<<fixed;
        // #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

signed main() {
    int n;
    cin>>n;
    vector<int> p(n);
    cin>>p;
    int ans=0;
    REP(i,n) {
        if(i==n-1) {
            if(p[i]==n) {
                ans++;
                break;
            }
        }
        if(p[i]==i+1 && p[i+1]==i+2) {
            ans++;
            i++;
        } else if(p[i]==i+1 && p[i+1]!=i+2) {
            ans++;
            i++;
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1024
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<cstring>
#include<string>
#define inf 0x3f3f3f3f
using namespace std;
int n,m,l,a,b,c,q,s,t,dist[310][310],dis[310][310];
int main(){
	scanf("%d%d%d",&n,&m,&l);
	memset(dis,inf,sizeof(dis));
	memset(dist,inf,sizeof(dist));
	for(int i=1;i<=m;i++) scanf("%d%d%d",&a,&b,&c),dist[a][b]=dist[b][a]=c;
	for(int k=1;k<=n;k++)
	    for(int j=1;j<=n;j++)
	        for(int i=1;i<=n;i++)
	            dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j]);
	for(int i=1;i<=n;i++)
	    for(int j=1;j<=n;j++)
	        if(dist[i][j]<=l) dis[i][j]=dis[j][i]=1;
	for(int k=1;k<=n;k++)
	    for(int j=1;j<=n;j++)
	        for(int i=1;i<=n;i++)
	            dis[i][j]=min(dis[i][j],dis[i][k]+dis[k][j]);
	scanf("%d",&q);
	for(int i=1;i<=q;i++){
	    scanf("%d%d",&s,&t);
		if(dis[s][t]!=1061109567) printf("%d\n",dis[s][t]-1);
		else printf("-1\n");
	}
}

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    ll N;
    cin >> N;
    vector<ll> A(N);
    rep(i, N) cin >> A[i];
    ll ans = 0;
    map<ll, ll> cnt;
    rep(i, N) {
        ll a = A[i];
        rep(j, 61) {
            if ((a & (1LL << j))) {
                cnt[j]++;
            }
        }
    }
    rep(j, 61) {
        ll tmp = 1LL << j;
        tmp %= MOD;
        ans += (((cnt[j] * (N - cnt[j])) % MOD) * tmp) % MOD;
        ans %= MOD;
    }

    cout << ans % MOD << '\n';
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 2560