akhauriyash/Code-Regression huggingface dataset:
import sys
input = sys.stdin.buffer.readline


# mod=10**9+7
# rstrip().decode('utf-8')
# map(int,input().split())
# import numpy as np


from collections import deque
from collections import defaultdict


def main():
	N=int(input())
	M=N-1
	G = defaultdict(set)

	color = [0 for i in range(N + 1)]

	for _ in range(M):
		A, B = map(int, input().split())
		G[A].add(B)
		G[B].add(A)

	color[1] = 1
	que = deque([1])  # 始点を追加

	while len(que):
		p = que.popleft()  # 直近で追加したグラフの頂点を取得
		for q in list(G[p]):  # 結合しているグラフの頂点を参照
			if color[q] == 0:  # 塗られていないなら別の色で塗る
				color[q] = -color[p]
				que.append(q)


	b=[]
	w=[]
	for i in range(1,N+1):
		if color[i]==1:
			b.append(i)
		else:
			w.append(i)

	ans=[0]*(N+1)
	lim = ((N - 1) // 3)
	i=0
	if len(b)<len(w):
		for val in w:
			if i<=lim:
				ans[val]=3*i+1
				i+=1
			else:
				break
		w=w[i:]
	else:
		for val in b:
			if i<=lim:
				ans[val]=3*i+1
				i+=1
			else:
				break
		b=b[i:]


	lim = ((N - 2) // 3)
	i=0
	if len(b)<len(w):
		for val in w:
			if i<=lim:
				ans[val]=3*i+2
				i+=1
			else:
				break
		w=w[i:]
	else:
		for val in b:
			if i<=lim:
				ans[val]=3*i+2
				i+=1
			else:
				break
		b=b[i:]


	i=0
	for val in b:
		ans[val]=3*i+3
		i+=1
	for val in w:
		ans[val]=3*i+3
		i+=1




	print(*ans[1:])




if __name__ == "__main__":
	main()


Measured memory_bytes: 122316
#include"bits/stdc++.h"

#define rep(i, N) for(int i = 0;i < N;i++)

typedef long long ll;

const int mod = 1e9 + 7;

using namespace std;



int main(void) {
	string S; cin >> S;
	int ans = 0;

	for (int i = 0; i + 1 < S.length(); i++) {
		if (S[i] != S[i + 1])ans++;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3760
#include <iostream>
using namespace std;
int main(){
    string s;
    cin >> s;
    int x = 0;
    for (int i = 0 ; i <  s.size(); i++) {
        if (s[i] == 'o' ) {
            x++;
        }
    }
    cout << 700+x*100;
    
    
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	int w, h,x,y,r;
	scanf("%d", &w);
	h = 1;
	while (w != 0) {
		printf("Case %d: %d\n", h, w);
		scanf("%d", &w);
		h++;
	}

	return 0;
}

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

int main()
{
  int N;
  int a[128];
  cin >> N;
  for (int i = 0; i < N; i++) cin >> a[i];
  // end input

  int cost_min = 1000000000;
  for (int i = -100; i <= 100; i++) {
    int sum = 0;
    for (int j = 0; j < N; j++) {
      sum += (a[j]-i)*(a[j]-i);
    }
    if (sum < cost_min) cost_min = sum;
  }
  cout << cost_min << endl;
}

Measured memory_bytes: 256
def f(n):
    if n%2 == 0:
        return n //2
    return 3*n+1

s = int(input())
ans = 1
used = set()
# 同じものがでるまで処理を繰り返す
while True:
    if s in used:
        break
    used.add(s)
    ans += 1
    s = f(s)
print(ans)

Measured memory_bytes: 3060
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  
#include <chrono>
#include <random>
#include <time.h>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define endl "\n"
#define all(c) begin(c),end(c)
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}

#define INF 1e9+7
#define LLINF 1e18+7
#define N 500000
ll MOD=1e9+7;
ll dp[2000000];
int a[N];
ll n;
vec mem(20,-1);
main(){
    string s;
    cin>>s;
    int k=s.size();
    int a=0;
    rep(i,k){
        if(s[i]=='o')a++;
    }
    a+=(15-k);
    if(a>=8)cout<<"YES";
    else cout<<"NO";
}



Measured memory_bytes: 256
let readInt _ = stdin.ReadLine() |> int

let d =
    new System.Collections.Generic.Dictionary<int, int>()

let rec solve (d: System.Collections.Generic.Dictionary<int, int>) (arr: int []) current =
    let c = current - 1
    let next = arr.[c]
    if next = 2 then
        d.Count + 1
    elif d.ContainsKey(next) then
        -1
    else
        d.Add(next, next)
        solve d arr next


()
|> readInt
|> fun x -> [| 1 .. x |]
|> Array.map readInt
|> solve d
<| 1
|> printfn "%d"


Measured memory_bytes: 39492
import math
mod = 10**9 + 7
n, m = map(int, input().split())
#mの素因数分解
#(prime, power)を要素としてもつ配列を返す関数を作る
def factorize(n):
    fct = []
    b, e = 2, 0
    while b*b <= n:
        while n%b == 0:
            n //= b
            e += 1
        if e > 0:
            fct.append((b, e))
        b += 1
        e = 0
    if n > 1:
        fct.append((n, 1))
    return fct

num = factorize(m)
ans = 1

for p in num:
    for i in range(p[1]):
        ans *= n+i
    for i in range(p[1]):
        ans //= i+1
print(ans%mod)


Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define pie 3.141592653589793238462643383279
#define mod 998244353
#define inf 10000000000000007
#define all(vec) vec.begin(),vec.end()
#define ggr getchar(); getchar();return 0;
#define int long long
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
bool prime(int x) {
	for (int i = 2; i <= sqrt(x); i++) {
		if (x%i == 0)return false;
	}
	return true;
}

int kai(int x) {
	if (x == 1)return 1;
	return kai(x - 1)*x;
}

int mod_pow(int x, int y, int moder) {
	int res = 1;
	while (y > 0) {
		if (y & 1)res = res * x%moder;
		x = x * x%moder;
		y >>= 1;
	}
	return res;
}

int h, w, n, a[11451];
int mu[114][114];

signed main() {
	cin >> h >> w >> n;
	rep(i, n)cin >> a[i];
	int ta = 0;
	rep(i, h) {
		rep(j, w) {
			if (i % 2 == 0)mu[i][j] = ta + 1;
			else mu[i][w - j - 1] = ta + 1;
			a[ta]--;
			if (a[ta] == 0)ta++;
		}
	}
	rep(i, h) {
		rep(j, w) {
			if (j == w - 1)cout << mu[i][j] << endl;
			else cout << mu[i][j] << " ";
		}
	}
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
bool isPowerOfTwo (int x) 
{ 
  return x && (!(x&(x-1))); 
} 
int main(){
    int n;
    cin>>n;
    int swim[n],bugs[n],homework[n];
    for (int i = 0; i < n; i++)
    {
        cin>>swim[i]>>bugs[i]>>homework[i];
    }
    int happiness[n][3];
    happiness[0][0]=swim[0];
    happiness[0][1]=bugs[0];
     happiness[0][2]=homework[0];
    for (int i = 1; i < n; i++)
    {
        happiness[i][0]= swim[i]+ max(happiness[i-1][1],happiness[i-1][2]);
        happiness[i][1]= bugs[i]+ max(happiness[i-1][0],happiness[i-1][2]);
        happiness[i][2]= homework[i]+ max(happiness[i-1][1],happiness[i-1][0]); 
    }
    cout<<max(max(happiness[n-1][0],happiness[n-1][1]),happiness[n-1][2])<<endl;
    
    
}

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

int main() {
  int N;
  cin >> N;
  
  vector<int> vec(9);
  vec = { 111, 222, 333, 444, 555, 666, 777, 888, 999 };
  
  for( int i = 0; i < 9; i++ ){
    if( vec.at(i) >= N ){
      cout << vec.at(i) << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 256
N = int(input())
a = list(map(int, input().strip().split(' ')))
sorted_a = sorted(a, reverse=True)

Alice = 0
Bob = 0
while not sorted_a == []:
  Alice += sorted_a[0]
  sorted_a.pop(0)
  if sorted_a == []:
    break
  Bob += sorted_a[0]
  sorted_a.pop(0)

print(Alice - Bob)

Measured memory_bytes: 38256
N = int(input())
S = []
for i in range(N):
	S.append(list(input())[0])

count = [0] * 5
for i in range(N):
	if S[i] == "M":
		count[0] += 1
	elif S[i] == "A":
		count[1] += 1
	elif S[i] == "R":
		count[2] += 1
	elif S[i] == "C":
		count[3] += 1
	elif S[i] == "H":
		count[4] += 1
		
sum = 0
for i in range(3):
	sum += count[i] * count[i+1] * count[i+2]

for i in range(2):
	sum += count[i] * count[i+1] * count[i+3]
	sum += count[i] * count[i+2] * count[i+3]

for i in range(3):
		sum += count[0] * count[i+1] * count[4]
print(sum)

Measured memory_bytes: 4012
//インクルード(アルファベット順)
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
//#include<unordered_map>//イテレータあるけど順序保持しないmap
//#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列
#include<valarray>//なんとなく追加
//メモ：表示桁数を大きくする　　cout << fixed << setprecision(20) << cm << endl;
using namespace std;
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
#define PI acos(-1.0)
#define answer(ans) cout<<ans<<endl;




signed main() {
 int N , M , ans=0;
 cin >> N >> M;
 vector<long> H(N);
 vector<int> frag(N,1);
 REP(i,N){
     cin >> H[i];
 }
int A,B;
REP(i,M){
    cin >> A >> B;
    if(H[A-1] > H[B-1]){
        frag[B-1]=0;
    }
    if(H[A-1] == H[B-1]){
        frag[A-1]=0;
        frag[B-1]=0;
    }
    if(H[A-1] < H[B-1]){
        frag[A-1]=0;
    }
}
REP(i,N){
    ans += frag[i];
}
answer(ans);

}

Measured memory_bytes: 4580
#include<bits/stdc++.h>
#define Add(x,y) x=mymax(0,mymin(X,x+y))
using namespace std;

namespace IO
{
	const int S=(1<<20)+5;
	//Input Correlation
	char buf[S],*H,*T;
	inline char Get()
	{
		if(H==T) T=(H=buf)+fread(buf,1,S,stdin);
		if(H==T) return -1;return *H++;
	}
	inline int read()
	{
		int x=0;char c=Get();
		while(!isdigit(c)) c=Get();
		while(isdigit(c)) x=x*10+c-'0',c=Get();
		return x;
	}
	//Output Correlation
	char obuf[S],*oS=obuf,*oT=oS+S-1,c,qu[55];int qr;
	inline void flush(){fwrite(obuf,1,oS-obuf,stdout);oS=obuf;}
	inline void putc(char x){*oS++ =x;if(oS==oT) flush();}
	template <class I>inline void print(I x)
	{
		if(!x) putc('0');
		if(x<0) putc('-'),x=-x;
		while(x) qu[++qr]=x%10+'0',x/=10;
		while(qr) putc(qu[qr--]);
	}
}

inline int mymax(const int &x,const int &y){return x>y?x:y;}
inline int mymin(const int &x,const int &y){return x<y?x:y;}

using namespace IO;
const int N=100010;
int t[N],a[N],r[N];
int X,n,Q;

int main()
{
	X=read();n=read();
	for(int i=1;i<=n;i++) r[i]=read();
	Q=read();
	for(int i=1;i<=Q;i++) t[i]=read(),a[i]=read();
	int down=0,c=0,up=X,fg=-1,p1=0,p2=1,ad=0;
	while(p2<=Q)
	{
		if(t[p2]>r[p1+1]&&p1<n)
		{
			p1++;
			ad=fg*(r[p1]-r[p1-1]);
			Add(down,ad);Add(up,ad);
			c+=ad;fg=-fg;
		}
		else
		{
			int len=t[p2]-r[p1];
			int ans=mymax(down,mymin(up,a[p2]+c));
			Add(ans,fg*len);
			print(ans);putc('\n');
			p2++;
		}
	}
	flush();
	return 0;
}

Measured memory_bytes: 4352
#include<iostream>
#include<string>
using namespace std;
typedef int64_t ll;
const ll mod=1e9+7;
ll const MA=5000;
ll d[MA+1];
void p(){
    ll t[MA+1]={};
    t[0]=(d[0]+d[1])%mod;
    for(int i=1;i<MA;i++){
        t[i]=(d[i-1]*2+d[i+1])%mod;
    }
    t[MA]=d[MA-1]*2%mod;
    for(int i=0;i<=MA;i++){
        d[i]=t[i];
    }
}
int main(){
    ll N;
    string s;
    cin>>N;
    cin>>s;
    d[s.size()]=1;
    for(int i=0;i<N;i++){
        p();
    }
    cout<<d[0]<<endl;
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <unordered_map>
#include <map>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using lint = long long;
using namespace std;

const int MOD = 1000000007;

int main() {
    char c;
    cin >> c;
    c += 1;
    cout << c << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
 
 int  x, y;
 cin >> x >> y;
 
 
 for (int i=0; i<=x; i++) {
     if ((i*2 + (x-i)*4) == y) {
         cout << "Yes" << endl;
         return 0;
     }
 }
 
 cout << "No" << endl;
}


Measured memory_bytes: 3096
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi std::vector<std::vector<int> >
#define vvl std::vector<std::vector<ll> >
#define MODs 1000000007;
typedef unsigned long long int ll;
using namespace std;

int main(int argc, char const *argv[]) {
  ll N, S=0, ans = 0;
  std::cin >> N;
  bool flag = false;
  std::vector<ll> A(N);
  for(int i=0;i<N;i++){
    std::cin >> A[i];
    if(A[i]>10000) {
      flag = true;
      ll tmp = A[i];
      if(A[i]>=51*(N+1))A[i] = (A[i]%(51*(N+1))==0?(51*(N+1)):A[i]%(51*(N+1)));
      S+=tmp-A[i];
    }
  }
  if(flag){
    while(true){
      ll ma=N-1, mai=-1;
      for(int i=0;i<N;i++) if(ma<A[i]) ma=A[i], mai=i;
      if(mai==-1) break;
      ans++;
      for(ll i=0;i<N;i++) {
        if(i==mai) A[i]-=N;
        else A[i]++;
      }
    }
    std::cout << S + ans << '\n';
  }else{
    while(true){
      ll ma=N-1, mai=-1;
      for(ll i=0;i<N;i++) if(ma<A[i]) ma=A[i], mai=i;
      if(mai==-1) break;
      ans++;
      for(ll i=0;i<N;i++) {
        if(i==mai) A[i]-=N;
        else A[i]++;
      }
    }
    std::cout << ans << '\n';
  }
  return 0;
}


Measured memory_bytes: 888
use std::io::Read;

fn solve(s: &str, t: &str) -> String {
    let sn = s.len();
    let tn = t.len();
    let sch: Vec<char> = s.chars().collect();
    let tch: Vec<char> = t.chars().collect();

    let mut dp: Vec<Vec<i16>> = vec![vec![0; tn+1]; sn+1];
    for (i,si) in sch.iter().enumerate() {
        for (j,tj) in tch.iter().enumerate() {
            dp[i+1][j+1] = if si == tj {
                dp[i][j] + 1
            } else {
                std::cmp::max(dp[i+1][j], dp[i][j+1])
            };
        }
    }

    let mut i = sn;
    let mut j = tn;
    let mut acc = String::new();
    while i > 0 && j > 0 {
        if sch[i-1] == tch[j-1] {
            acc.push(sch[i-1]);
            i -= 1;
            j -= 1;
        } else if dp[i-1][j] < dp[i][j-1] {
            j -= 1;
        } else {
            i -= 1;
        }
    }

    acc.chars().rev().collect()
}

fn main () {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut iter = buf.split_whitespace();

    let s = iter.next().unwrap();
    let t = iter.next().unwrap();

    println!("{}", solve(s,t));
}



Measured memory_bytes: 22780
#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>;
int keta(int x) {
    int ans = 0;
    while(x>0) {
        x /= 10;
        ans++;
    }
    return ans;
}
int main() {
    int a, b; cin >> a >> b;
    int x = keta(b);
    rep(i, x) a*=10;
    int c = a + b;
    bool ok = false;
    for(int i=2;i*i<=c;i++) {
        if(i*i == c) ok = true;
    }
    if(ok) cout << "Yes";
    else cout << "No";
}


Measured memory_bytes: 256
while(1):
	n=int(input())
	if n==0:
		break	
	a=[int(i) for i in input().split()]

	total=0
	for i in a:
		total+=i
	
	hei=total/n
	count=0
	for i in a:
		if i <=hei:
			count+=1
	print(count)



Measured memory_bytes: 6612
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val n = sc.nextInt()
  val xy = List.fill(n)((sc.nextInt(), sc.nextInt()))
  val a = xy.map{case (x, y) => y - x}
  val b = xy.map{case (x, y) => y + x}
  println((a.max - a.min).max(b.max - b.min))
}


Measured memory_bytes: 84908
local n, k = io.read("*n", "*n")
local t = {}
for i = 1, k do
  local z = io.read("*n")
  t[z] = true
end
while true do
  local len = #(tostring(n))
  local valid = true
  local v = n
  for i = 1, len do
    local tmp = v % 10
    if t[tmp] then valid = false break end
    v = v // 10
  end
  if valid then print(n) break end
  n = n + 1
end


Measured memory_bytes: 2848
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
vector<int> a(14),b(14);
bool five();
bool tempy(int x, int y);
int main(){
  for(;;){
    vector<int> ans;
    if(scanf("%1d",&a[0]) == EOF) break;
    for(int i=1; i<13; i++) scanf("%1d",&a[i]);
    for(int i=1; i<=9; i++){
      a[13] = i;
      for(int j=0; j<14; j++) b[j] = a[j];
      sort(b.begin(),b.end());
      if(five()) continue;
      if(tempy(1,4)) ans.push_back(i); 
    }
    if(ans.empty()) ans.push_back(0);
    for(int i=0; i<ans.size(); i++){
      if(i != 0) cout <<" ";
      cout <<ans[i];
    }
    cout <<endl;
  }
  return 0;
}
bool five(){
  for(int i=0,j=0,k=0; i<14; i++){
    if(b[i] != j){j=b[i];k = 1;}
    else k++;
    if(k == 5) return true;
  }
  return false;
}
bool tempy(int x, int y){
  if(x == 0 && y == 0) return true;
  for(int i=0; i<14; i++){
    if(b[i] == 0) continue;
    if(x != 0){
      for(int j=i+1; j<14; j++){
	if(b[i] != b[j]) continue;
	int q = b[i];
	b[i] = b[j] = 0;
	if(tempy(0,y)) return true;
	b[i] = b[j] = q;
	break;
      }
    }
    if(y != 0){
      for(int j=i+1; j<14; j++){
	if(b[i] != b[j]) continue;
	for(int k=j+1; k<14; k++){
	  if(b[i] != b[k]) continue;
	  int q = b[i];
	  b[i] = b[j] = b[k] = 0;
	  if(tempy(x,y-1)) return true;
	  b[i] = b[j] = b[k] = q;
	  goto flag_pon;
	}
      }
    flag_pon:;
      for(int j=i+1; j<14; j++){
	if(b[i]+1 != b[j]) continue;
	for(int k=j+1; k<14; k++){
	  if(b[i]+2 != b[k]) continue;
	  int q = b[i];
	  b[i] = b[j] = b[k] = 0;
	  if(tempy(x,y-1)) return true;
	  b[i] = q;b[j] = q+1;b[k] = q+2;
	  goto flag_chi;
	}
      }
    flag_chi:;
    }
  }
  return false;
}

Measured memory_bytes: 1232
def main():
    S = input()
    lst = list()
    ans = 0
    for i in range(1 << len(S) - 1):
        lst.clear()
        pre = 0
        for j in range(len(S) - 1):
            if i >> j & 1:
                lst.append(int(S[pre:j + 1]))
                pre = j + 1
        lst.append(int(S[pre:]))
        ans += sum(lst)
    print(ans)
    return


main()


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

int main() {
  int H, W, k = 0;
  while(1){
    if(k > 0)
      cout << endl;
    cin >> H >> W;
    if(H == 0 && W == 0)
      break;
    for (int i = 0; i < H; i++){
      for(int j = 0; j < W; j++){
        cout << "#";
        if(j == W - 1){
          cout << endl;
          break;
        }  
      }
    }
    k++;
  }
}



Measured memory_bytes: 3112
#include<stdio.h>

int main(){
  int A[100], tmp, N, i, j, minj, cnt=0;
  
  scanf("%d", &N);
  for (i=0; i<N; i++) {
    scanf("%d", &A[i]);
  }
  
  for (i=0; i<N; i++) {
    minj = i;
    for (j=i; j<N; j++) {
      if (A[j] < A[minj]) {
        minj = j;
      }
    }
    if (minj != i) {
      tmp = A[i];
      A[i] = A[minj];
      A[minj] = tmp;
      cnt++;
    }
  }

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

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
int main() {
  int64_t answer;
  int N;
  bool big=false;
  cin >> N;
  answer=1;
  
  for(int i=0;i<N;i++){
    int64_t a;
    cin >> a;
    if(a==0){
      answer=0;
      big = false;
      break;
    }
    if(1000000000000000000/a<answer){
      big =true;
    }
    answer*=a;
  }
  
  if(big){
    answer=-1;
  }
  
  cout << answer << endl;
}


Measured memory_bytes: 3540
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn main() {
    let _line0 = read_vec::<i32>();
    let mountains = read_vec::<i32>();
    let mut max = 0;
    let mut count = 0;
    for x in mountains {
        if max <= x {
            max = x;
            count += 1;
        }
    }

    println!("{}", count);
}


Measured memory_bytes: 4352
// by Balloons
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define mpr make_pair
#define debug() puts("okkkkkkkk")
#define rep(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)

using namespace std;

typedef long long LL;

const int inf = 1e9;

int n;
int h[505][505], occ[505][505];
const int dx[]={0,0,1,-1};
const int dy[]={1,-1,0,0};

void dfs(int x,int y){
	int curupd = h[x][y] + occ[x][y];
	for(int i=0;i<4;i++){
		int tx = x+dx[i], ty = y+dy[i];
		if(h[tx][ty] > curupd){
			h[tx][ty] = curupd;
			dfs(tx,ty);
		}
	}
}

signed main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			h[i][j] = min(min(i-1,n-i),min(j-1,n-j)),
			occ[i][j] = 1;
	int res=0;
	for(int i=1;i<=n*n;i++){
		int id;scanf("%d",&id);
		int x=(id-1)/n+1,y=id%n == 0?n:id%n;
		res += h[x][y];
		occ[x][y] = 0;
		dfs(x,y);
	}
	printf("%d\n",res);

	return 0;
}



Measured memory_bytes: 16648
#include<stdio.h>

int main (void)
{
    int a,b,c,d;

    scanf("%d %d %d %d",&a,&b,&c,&d);

    while(1){
        c-=b;
        a-=d;

        if(c<=0){
            //win taka
            printf("Yes");
            break;

        }else if(a<=0){
            printf("No");
            break;
        }
    }



    return 0 ;
}

Measured memory_bytes: 1736
using System;

public class a {
 static void Main(){
   string[] week = new string[7]{"SUN","MON","TUE","WED","THU","FRI","SAT"};
   string day = Console.ReadLine();
   for(int i = 0; i<week.Length;i++){
     if(week[i]==day){
       Console.WriteLine(7-i);
     }
   }
 
 }
}

Measured memory_bytes: 25648
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

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

    static class TaskA {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            String str = in.next();
            out.println(str.substring(0, str.lastIndexOf("FESTIVAL")));
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

    }
}



Measured memory_bytes: 21460
using System;
using System.Collections.Generic;
//using System.Linq;
//using System.Numerics;

class Program {
    static void Main (string[] args) {
        var input = INP();
        int L = TOI(input[0]);
        int R = TOI(input[1]);
        int d = TOI(input[2]);

        int cnt = 0;
        for(int i = L;i < R + 1;i++) {
            if(i % d == 0) {
                cnt++;
            }
        }

        CWL(cnt);
    }


    public static List<int> PrimeFactors (int n) {
        var tmpList = new List<int>();
        int i = 2;
        int tmp = n;

        while(i * i <= n) {
            if(tmp % i == 0) {
                tmp /= i;
                tmpList.Add(i);
            } else {
                i++;
            }
        }

        if(tmp != 1) tmpList.Add(tmp);

        return tmpList;
    }

    static string[] INP () {
        return Console.ReadLine().Split(' ');
    }

    static void CWL (string value) {
        Console.WriteLine(value);
    }

    static void CWL (int value) {
        Console.WriteLine(value);
    }

    static void CWL (long value) {
        Console.WriteLine(value);
    }

    static void CWL (float value) {
        Console.WriteLine(value);
    }

    static void CWL (double value) {
        Console.WriteLine(value);
    }

    static int TOI (string str) {
        return int.Parse(str);
    }

    static long TOL (string str) {
        return long.Parse(str);
    }

    static float TOF (string str) {
        return float.Parse(str);
    }

    static double TOD (string str) {
        return double.Parse(str);
    }

    /*static void Main (string[] args) {
        var input = INP();
        var input2 = INP();
        var input3 = INP();

        CWL("dummy");
    }*/
}


Measured memory_bytes: 27472
n,k=map(int,input().split())
s=list(input())*3
p=['A' if s[i]=='B' else 'B' for i in range(n)]*3
head,tail=0,n
for i in range(2*n):
	if s[head]=='A':
		s[head],p[head]='B','A'
	else:
		s,p=p,s
		head+=1
		s[tail],p[tail]='A','B'		
		tail+=1
	if i==k-1:
		print(''.join(s[head:tail]))
		break
else:
	if n%2==1 and k%2==1:
		if s[head]=='A':
			s[head],p[head]='B','A'
		else:
			s,p=p,s
			head+=1
			s[tail],p[tail]='A','B'		
			tail+=1
	print(''.join(s[head:tail]))

Measured memory_bytes: 69932
import Control.Applicative ((<$>), (<*>))
import Control.Monad (replicateM, unless)

main :: IO ()
main = do
  n <- readLn
  unless (n == 0) $ do
    solve n <$> replicateM n (read <$> getLine) <*> readLn >>= print
    main
    
solve :: Int -> [Int] -> Int -> Int
solve n xs k = bsearch xs n k

bsearch :: [Int] -> Int -> Int -> Int
bsearch xs n k = f 0 0 (n-1)
  where f ct l r | l > r = ct
                 | v == k = ct + 1
                 | v > k = f (ct + 1) l (m - 1)
                 | otherwise = f (ct + 1) (m + 1) r
          where m = (l + r) `div` 2
                v = xs !! m



Measured memory_bytes: 3852
#124C
import sys
s = sys.stdin.readline().rstrip()
n = len(s)

cnt = 0
for i in range(n):
    if i % 2==0: #偶数
        if s[i] != '0':
            cnt +=1
    else:
        if s[i] != '1':
            cnt +=1

print(min(cnt, n-cnt))

Measured memory_bytes: 3188
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cctype>
#include <cstdlib>
#include <utility>
#include<cmath>
#include <string>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <vector>
#include <deque>
#include <list>
#include <functional>
#include <tuple>
using namespace std;
typedef long long ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef double db;
#define ls(x) x<<1
#define rs(x) x<<1|1
#define low(x) (x&-x)
#define all(x) x.begin(),x.end()
#define mp make_pair
#define X first
#define Y second
#ifdef _DEBUG
    const int N=1e3+10;
#else
    const int N=1e6+10;
#endif
const ll mod=1e9+7;
template<typename T> inline T gcd(T a,T b){return !b?a:gcd(b,a%b);}
template<typename T> inline T q_pow(T a,T x){T ans=1,tmp=a;while(x){if(x&1)(ans*=tmp)%=mod;(tmp*=tmp)%=mod;x>>=1;}return ans;}
template<typename T> inline void re(T &N){int f=1;char c;while((c=getchar())< '0'||c> '9')if(c=='-')f=-1;N=c-'0';while((c=getchar())>='0'&&c<='9')N=N*10+c-'0';N*=f;}
ll m,n,t=1,st,en;
ll d[100][20],g[50],sg[50];
int ans[50];

int main()
{
    // freopen("data.txt","r",stdin);
    re(n);
    for(int i=0;i<=9;i++)d[1][i]=1;
    g[1]=sg[1]=9;
    for(int i=2;i<=20;i++)
    {
        for(int j=0;j<=9;j++)
        {
            if(j> 0)d[i][j]+=d[i-1][j-1];
            d[i][j]+=d[i-1][j];
            if(j< 9)d[i][j]+=d[i-1][j+1];
        }
        for(int j=1;j<=9;j++)g[i]+=d[i][j];
        sg[i]=sg[i-1]+g[i];
    }
    m=0;
    while(sg[m]< n)m++;
    n-=sg[m-1];
    for(int i=m;i>=1;i--)
    {
        int l,r,j;
        if(i==m)l=1,r=9;
        else l=ans[i+1]-1,r=ans[i+1]+1;
        l=max(0,l),r=min(r,9);
        for(j=l;j<=r;j++)
        {
            if(d[i][j]< n)n-=d[i][j];
            else break;
        }
        ans[i]=j;
    }
    for(int i=m;i>=1;i--)printf("%d",ans[i]);
    return puts(""),0;
}


Measured memory_bytes: 256
program r20926a
 
implicit none
character(len=15) :: a
integer :: n

read *, n

if(n==1) then
 print *, 'ACL'
else if(n==2) then
 print *, 'ACLACL'
else if(n==3) then
 print *, 'ACLACLACL'
else if(n==4) then
 print *, 'ACLACLACLACL'
else if(n==5) then
 print *, 'ACLACLACLACLACL'
end if

end program r20926a

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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repr(i, n) for(int i = (int)(n); i >= 0; i--)
#define repm(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define repmr(i, m, n) for(int i = (int)(n); i >= (int)(m); i--)
#define all(x) (x).begin(),(x).end()
#define inf 2e9
#define MOD 1000000007

using namespace std;
typedef long long int lli;
typedef long long ll;

int main(){
  int h,w; cin >> h >> w;
  vector<vector<char>> a(h, vector<char>(w));
  rep(i,h) rep(j,w){
    cin >> a[i][j];
  }

  vector<bool> white_h(h,false), white_w(w,false);
  rep(i,h){
    bool isWhite = true;
    rep(j,w){
      if(a[i][j] == '#'){
        isWhite = false;
        break;
      }
    }
    if(isWhite) white_h[i] = true;
  }

  rep(i,w){
    bool isWhite = true;
    rep(j,h){
      if(a[j][i] == '#'){
        isWhite = false;
        break;
      }
    }
    if(isWhite) white_w[i] = true;
  }

  rep(i,h){
    if(white_h[i]) continue;
    rep(j,w){
      if(white_w[j]) continue;
      cout << a[i][j];
    }
    cout << endl;
  }
}


Measured memory_bytes: 256
def main():
 
    N,K = map(int,input().split())
    P = list(map(int,input().split()))
    C = list(map(int,input().split()))
 
    # グルーピング
    import copy
    P2 = set(P)
    Group = []
    while len(P2)>0:
        temp = list(P2)[0]
        tempGroup = []
        while temp in P2:
            tempGroup.append(temp)
            P2.remove(temp)
            temp = P[temp-1]
        Group.append(tempGroup)
    Point = []
    for x in Group:
        tempPoint = []
        for p in x:
            tempPoint.append(C[p-1])
        Point.append(tempPoint)
 
    #print(Group)
    #print(Point)
 
    max00 = -10**9
    for x in Point:
        sumx = sum(x)
        tempx = copy.copy(x)
        tempx.extend(x)
        lenx = len(x)
        max0 = -10**9
        dp = [0]*lenx
        if sumx <= 0 or K < lenx:
            for i in range(min(lenx-1,K)):
                for j in range(lenx):
                    dp[j] = dp[j] + tempx[j+i]
                max0 = max(max0,max(dp))
                #print(dp)
        else:
            K2 = K % lenx
            SN = int(K/lenx)
            for i in range(lenx):
                for j in range(lenx):
                    dp[j] = dp[j] + tempx[j+i]
                #print(dp)
                if i < K2:
                    max0 = max(max0,max(dp) + sumx*SN)
                    #print(max0)
                else:
                    max0 = max(max0,max(dp) + sumx*(SN-1))
        max00 = max(max00,max0)
    print(max00)
 
if __name__ == "__main__":
    main()

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

int main() {
  int N;
  scanf("%d", &N);
  char a[N];
  for (int i = 0; i < N; ++i) {
    cin >> a[i];
  }

  int count = 0;
  int maxcount = 3*100000;

  for (int i = 1; i < N; ++i){
    if(a[i]=='E') ++count;
  }

  maxcount = count;

  for (int i = 0; i < N-1; ++i){
    if(a[i+1]=='E') --count;
    if(a[i]=='W') ++count;
    if(maxcount>count) maxcount = count;
  }

  cout << maxcount << endl;

}

Measured memory_bytes: 512
/* Dsingh_24 */

#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define	endl		'\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define ios	    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
#define N  200005
ll n,h[N],a[N];
vi BIT(N);
void update(ll x,ll val)
{
	for(;x<=N;x+=(x&-x))
		BIT[x]=max(BIT[x],val);
}
ll query(ll x)
{
	ll res=0;
	for(;x>0;x-=(x&-x))
		res=max(res,BIT[x]);
	return res;
}
int main()
{
	ios
	ll n,i,j;
	cin>>n;
	for(i=0;i<n;i++)
		cin>>h[i];
	for(i=0;i<n;i++)
		cin>>a[i];
	ll ans=0;
	for(i=0;i<n;i++){
		ll cur=query(h[i])+a[i];
		ans=max(ans,cur);
		update(h[i],cur);
	}
	cout<<ans;
	return 0;
}

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


int main()
{
    string a,b;
    cin >> a >> b ;
    int n = a.size();
    int m = b.size();
    int dp[n + 1][m + 1];
    for(int i = 0; i <= n; i++)
        dp[i][0] = 0;
    for(int i = 0; i <= m; i++)
        dp[0][i] = 0;

    string ans;
    for(int i = 1; i <= n; i++)
    {
        for(int j = 1; j <= m; j++)
        {
            dp[i][j] = max(dp[i - 1][j],dp[i][j - 1]);
            if(a[i - 1] == b[j - 1]){
                dp[i][j] = dp[i - 1][j - 1] + 1;
            }
        }
    }
    string mxstr;
    for(int i = n; i >= 1; i--)
    {
        int temp = i;
        ans.clear();    
        for(int j = m; j >= 1 && i >= 0; j--)
        {
            while(i >= 1 && dp[i - 1][j] == dp[i][j]){
                i--;
            }
            if(dp[i][j] == dp[i - 1][j - 1] + 1 && a[i - 1] == b[j - 1])
            {
                ans += b[j - 1];
                //cout << b[j - 1] << " " << i << " " << j << '\n' ;
                i--;
            }
        }
        if(ans.size() > mxstr.size())
            mxstr = ans;
        i = temp;
    }
    ans = mxstr;
    reverse(ans.begin(),ans.end());
    cout << ans << '\n' ; 
    return 0;
}

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

using namespace std;

using ll = long long;

constexpr char newl = '\n';

int n, m, q;
vector<int> a, b, c, d;
int ans = 0;

int calc(const vector<int>& v){
    int res = 0;
    for (int i = 0; i < q; i++) {
        if (v[b[i]] - v[a[i]] == c[i]) res += d[i];
    }
    return res;
};

void dfs(int i, vector<int>& v) {
    if (i == n) {
        ans = max(ans, calc(v));
        return;
    }

    for (int j = (i == 0 ? 1 : v.back()); j <= m; j++) {
        v.push_back(j);
        dfs(i + 1, v);
        v.pop_back();
    }
};

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

    cin >> n >> m >> q;

    a.resize(q);
    b.resize(q);
    c.resize(q);
    d.resize(q);
    for (int i = 0; i < q; i++) {
        cin >> a[i] >> b[i] >> c[i] >> d[i];
        --a[i]; --b[i];
    }

    vector<int> v;
    dfs(0, v);
    cout << ans << newl;
    return 0;
}

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

using namespace std;

const int INF = 1 << 24;

struct Node {
    int dist, time;
    Node(int d, int t) : dist(d), time(t) {}
};

int main() {

    int n, m, a, b, d, t;
    int k, p, q, r;


    while(cin >> n >> m, n | m) {

        vector<vector<Node> > node(100, vector<Node>(100, Node(INF, INF)));

        for(int i = 0; i < m; ++i) {
            node[i][i].dist = 0;
            node[i][i].time = 0;
        }

        for(int i = 0; i < n; ++i) {
            cin >> a >> b >> d >> t;
            --a;
            --b;
            node[a][b].dist = d;
            node[a][b].time = t;
            node[b][a].dist = d;
            node[b][a].time = t;
        }

        for(int i = 0; i < m; ++i) {
            for(int j = 0; j < m; ++j) {
                for(int k = 0; k < m; ++k) {
                    node[j][k].dist = min(node[j][k].dist, node[j][i].dist + node[i][k].dist);
                    node[j][k].time = min(node[j][k].time, node[j][i].time + node[i][k].time);
                }
            }
        }

        cin >> k;

        for(int i = 0; i < k; ++i) {
            cin >> p >> q >> r;
            --p;
            --q;
            if(r == 0) {
                cout << node[p][q].dist << endl;
            } else {
                cout << node[p][q].time << endl;
            }
        }

    }

}

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

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

    int d,n;
    cin>>d>>n;
    if(n==100)n++;
    long long m=1;
    for(int i=0;i<d;i++)m*=100;
    cout<<n*m<<endl;

}

Measured memory_bytes: 256
/*
 _____ _             _              _           _ 
|_   _| |__   ___   / \   _ __  ___| |__  _   _| |
  | | | '_ \ / _ \ / _ \ | '_ \/ __| '_ \| | | | |
  | | | | | |  __// ___ \| | | \__ \ | | | |_| | |
  |_| |_| |_|\___/_/   \_\_| |_|___/_| |_|\__,_|_|                                                

*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
#define ll          long long
#define pb          push_back
#define ppb         pop_back
#define	endl		'\n'
#define mii         map<ll,ll>
#define msi         map<string,ll>
#define mis         map<ll, string>
#define rep(i,a,b)    for(ll i=a;i<b;i++)
#define repr(i,a,b) for(ll i=b-1;i>=a;i--)
#define trav(a, x) 	for(auto& a : x)
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define vii         vector<pair<ll, ll>>
#define vs          vector<string>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll)x.size()
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define max(a,b)	(a>b?a:b)
#define min(a,b)	(a<b?a:b)

/*	For Debugging	*/
#define DEBUG 		cerr<<"\n>>>I'm Here<<<\n"<<endl;
#define display(x) trav(a,x) cout<<a<<" ";cout<<endl;
#define what_is(x)  cerr << #x << " is " << x << endl;

std::mt19937_64 rng(std::chrono::steady_clock::now().time_since_epoch().count());
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define TIME        cerr << "\nTime elapsed: " << setprecision(5) <<1000.0 * clock() / CLOCKS_PER_SEC << "ms\n";
#define DECIMAL(n)  cout << fixed ; cout << setprecision(n);
#define FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace __gnu_pbds;
using namespace std;
#define PI 3.141592653589793
#define N  100005

void solve()
{
	ll n;
	cin>>n;
	while(n>0)
	{
		if(n%10==7)
		{
			cout<<"Yes\n";
			return;
		}
		n/=10;
	}
	cout<<"No\n";
	return;
}
int main()
{
	FAST
	int TESTS=1;
//	cin>>TESTS;
	while(TESTS--)
	{
		solve();
	}
	TIME
	return 0;
}


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

int main(){
  int D; cin >> D;
  vector<int> c(26);
  for(int i=0; i<26; i++) cin >> c[i];
  vector<vector<int>> s(D,vector<int>(26));
  for(int i=0; i<D; i++){
    for(int j=0; j<26; j++){
      cin >> s[i][j];
    }
  }
  vector<vector<int>> lastc(D+1,vector<int>(26,0));
  vector<int> t(D);
  
    srand(std::time(nullptr));
  
  for(int i=1; i<=D; i++){
    
    int cont; /*cin >> cont;
    cont--;*/ cont=rand()%26;
    t[i-1]=cont;
    
    //lastcの更新
    for(int j=0; j<26; j++){
      if(j==cont) lastc[i][j]=i;
      else lastc[i][j]=lastc[i-1][j];
    }
  }
  
  int M=10000000;//調整
  for(int i=0; i<M; i++){
    int d,q; /*cin >> d >> q; q--;
    */
    d=rand()%D+1; 
    q=rand()%26;
    int qold=t[d-1];
    
    int sat=0;
    
    sat = sat - s[d-1][qold];
    sat = sat + s[d-1][q];
    
    int lastcold = lastc[d-1][qold];
    for(int j=d; j<=D; j++){
      if(j==d){
        sat-=c[qold]*(j-lastcold);
      }
      else if(lastc[j][qold]==j){
        break;
      }
      else{
        sat-=c[qold]*(lastc[j][qold]-lastcold);
      }
    }
    
    for(int j=d; j<=D; j++){
      if(lastc[j][q]==j){
        break;
      }
      else{
        sat+=c[q]*(d-lastc[j][q]);
      }
    }
    
    if(sat>0||rand()%100==0){
      for(int j=d; j<=D; j++){
        if(j==d){
          lastc[j][qold]=lastc[j-1][qold];
        }
        else if(lastc[j][qold]==j){
          break;
        }
        else{
          lastc[j][qold]=lastc[j-1][qold];
        }
      }
      
      for(int j=d; j<=D; j++){
        if(j==d){
          lastc[j][q]=d;
        }
        else if(lastc[j][q]==j){
          break;
        }
        else{
          lastc[j][q]=lastc[j-1][q];
        }
      }
      
      t[d-1]=q;
    }
  }
  
  for(int i=0; i<D; i++){
    cout << t[i]+1 << endl;
  }
}

Measured memory_bytes: 3704
from collections import deque
def main():
  _map, _input, _int = map, input, int
  n, q = _map(_int, _input().split())
  values = [0] * n
  links = [[] for _ in range(n)]
  for _ in range(n - 1):
    a, b = _map(_int, _input().split())
    if a >= b:
      return
    links[a - 1].append(b - 1)
    links[b - 1].append(a - 1)
  for _ in range(q):
    p, x = _map(_int, _input().split())
    values[p - 1] += x
  d = deque()
  d.append((0, -1))
  while len(d) != 0:
    i, p = d.popleft()
    for j in links[i]:
      if j == p:
        continue
      values[j] += values[i]
      d.append((j, i))
  print(*values)
main()


Measured memory_bytes: 62132
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>
#include <tuple>


using namespace std;

int main(){

	float T, X;

	cin >> T >> X;

	cout << T/X << endl;

	return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.lang.StringBuilder;
public class Main {
	public static void main(String[] args) throws Exception{
		Scanner sc = new Scanner(System.in);
		StringBuilder bu = new StringBuilder();
		int h,w;
		while((h=sc.nextInt())!=0&&(w=sc.nextInt())!=0){
			for(int i=1;i<=h;i++){
				for(int o=1;o<=w;o++){
					if(i==1||o==1||i==h||o==w){
						bu.append("#");
					}else{
						bu.append(".");
					}
				}
				bu.append("\n");
			}
			bu.append("\n");
		}
		System.out.print(bu);
	}
}

Measured memory_bytes: 27320
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <queue>
using namespace std;

int n,a,b; 

int read(){
	int t=1,s=0;
	char c=getchar();
	while((c>'9'||c<'0')&&c!='-')c=getchar();
	if(c=='-')t=-1,c=getchar();
	while(c>='0'&&c<='9')
	s=s*10+c-'0',c=getchar();
	return s*t;
}

int main(void){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	scanf("%d %d %d",&n,&a,&b);
	int ans=min(n*a,b);
	printf("%d",ans);
}


Measured memory_bytes: 128
MOD = 1000000007
n, a, b = list(map(int, input().split()))

res = pow(2, n, MOD) - 1

dpa = {}
dpb = {}
factriala = 1
factrialb = n
for i in range(1, max(a, b)+1):
  if i in [a, b]:
    dpb[i] = factrialb
  factriala *= i
  factriala %= MOD
  factrialb *= n-i
  factrialb %= MOD
  if i in [a, b]:
    dpa[i] = factriala

def ncr_count(r):
  return dpb[r] * pow(dpa[r], MOD-2, MOD)

res = res - ncr_count(a) - ncr_count(b)

print(res%MOD)

Measured memory_bytes: 40848
import fractions

N = int(input())
 
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i:
        divisors.append(n//i)
  # divisors.sort()
  return divisors
 
divisors = make_divisors(N)
sum = 0
#print(len(divisors))

for i in range(len(divisors)):
  if divisors[i] < 10 and N/divisors[i] < 10:
    sum += 1
    
if sum >= 1:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 5688
#include<iostream>
#include<cstdio>
#include<cstring>
 
using namespace std;
static const int M = 1046527;
static const int NIL = -1;
static const int L = 14;
char H[M][L];
 
// ???????????????°????????????
int getChar(char ch){
    if(ch == 'A') return 1;
    else if(ch == 'C') return 2;
    else if(ch == 'G') return 3;
    else if(ch == 'T') return 4;
    else return 0;
}
 
long long getKey(char str[]){
    long long sum = 0, p=1, i;
    for(i=0; i<strlen(str); i++){
        sum += p*(getChar(str[i]));
        p *= 5;
    }
    return sum;
}
 
int h1(int key){ return key % M; }
int h2(int key){ return 1 +(key % (M-1)); }
 
int find(char str[]){
    long long key, i, h;
    key = getKey(str);
    for (int i = 0; ; ++i)
    {
        h = (h1(key) + i * h2(key)) % M;
        if( strcmp(H[h],str) == 0) return 1;
        else if( strlen(H[h]) == 0) return 0; //???????????????£???????????????
    }
    return 0;
}
 
int insert(char str[]){
    long long key, i, h;
    key = getKey(str);
    for (int i = 0; ; ++i)
    {
        h = (h1(key) + i * h2(key)) % M;
        if( strcmp(H[h],str) == 0) return 1;
        else if( strlen(H[h]) == 0){
            strcpy(H[h], str);
            return 0;
        }
    }
    return 0;
}
 
int main(int argc, char const *argv[])
{
    int i,n,h;
    char str[L], com[9];
    for (int i = 0; i < M; ++i) H[i][0] = '\0';
    scanf("%d", &n);
    for(i=0; i<n; i++){
        scanf("%s %s", com,str);
        if (com[0] == 'i')
        {
            insert(str);
        }
        else{
            if(find(str)){
                printf("yes\n");
            }
            else{
                printf("no\n");
            }
        }
    }
    return 0;
}

Measured memory_bytes: 17440
import java.util.Scanner;

public class Main{
  public static void main(String[] args){

    Scanner sc = new Scanner(System.in);
    int w = sc.nextInt();
    int n = sc.nextInt();
    int[] values = new int[w];
    for(int i = 0;i < values.length; i++){
      values[i] = i + 1;
    }
    for(int i = 0; i < n; i++){
       String str = sc.next();
       String[]ab = str.split(",");
       int a = Integer.parseInt(ab[0]) - 1;
       int b = Integer.parseInt(ab[1]) - 1;
       int c = 0;
       c = values[a];
       values[a]=values[b];
       values[b]=c;
     }
     for(int i = 0; i < n; i ++){
       System.out.println(values[i]);
     }
   }
  }

Measured memory_bytes: 26148
#include <bits/stdc++.h>
typedef long long lint;
using namespace std;

// 累積和
struct cumulative_sum {
    using lint = long long int;
    int sz;
    // data[i]:元の数列
    vector<lint> data;
    // cum[i]:[0,i)の和
    vector<lint> sum;
    // 要素数を指定して初期化
    cumulative_sum(const int _sz) : sz(_sz) {
        data.assign(sz, 0);
        sum.assign(sz + 1, 0);
    }
    lint& operator[](const int k) {
        return data[k];
    }
    // dataに基づいてsumを構築
    void build() {
        for (int i = 0; i < sz; i++) sum[i + 1] = sum[i] + data[i];
    }
    // [a,b)の和を求める
    lint query(const int a, const int b) {
        return sum[b] - sum[a];
    }
};

lint n, m;
vector<lint> a;

//幸福度k以上の握手が何個あるか
lint count(lint k) {
    lint res = 0;
    for (int i = 0; i < n; i++) {
        res += a.end() - lower_bound(a.begin(), a.end(), k - a[i]);
    }
    return res;
}

bool check(lint k) {
    return count(k) < m;
}

// めぐる式二分探索
long long meguru_BinarySearch(long long ok, long long no,
                              function<bool(long long)> isValid) {
    while (abs(ok - no) > 1) {
        long long mid = (ok >> 1) + (no >> 1) + (1 & ok & no);
        (isValid(mid) ? ok : no) = mid;
    }
    return ok;
}

int main() {
    cin >> n >> m;
    a.resize(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    lint ok = meguru_BinarySearch(1e+6, 0, check);
    lint ans = 0;
    ans += (ok - 1) * (m - count(ok));
    cumulative_sum cum(n);
    for (int i = 0; i < n; i++) {
        cum[i] = a[i];
    }
    cum.build();
    for (int i = 0; i < n; i++) {
        int b = lower_bound(a.begin(), a.end(), ok - a[i]) - a.begin();
        ans += a[i] * (n - b) + cum.query(b, n);
    }
    cout << ans << endl;
}

Measured memory_bytes: 2560