akhauriyash/Code-Regression huggingface dataset:
fn main() {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    let mut iter = buf.split_whitespace();
    let n: usize = iter.next().unwrap().parse().unwrap();

    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    let s = buf.trim();

    let mut nr_wb = Vec::<(usize, usize)>::with_capacity(n);

    for c in s.chars() {
        let (w, b) = *nr_wb.last().unwrap_or(&(0usize, 0usize));
        if c == '.' {
            nr_wb.push((w+1, b));
        }
        else {
            nr_wb.push((w, b+1));
        }
    }

    let mut ans_wb: usize = n;
    let (all_w, _) = *nr_wb.last().unwrap();
    for i in 0..(n-1) {
        let (cur_w, cur_b) = nr_wb[i];
        let rem_w = all_w - cur_w;
        ans_wb = std::cmp::min(ans_wb, cur_b + rem_w);
    }

    let ans_w: usize = nr_wb.last().unwrap().1;
    let ans_b: usize = nr_wb.last().unwrap().0;

    println!("{}", std::cmp::min(std::cmp::min(ans_w, ans_b), ans_wb));
}


Measured memory_bytes: 8444
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() { 
  ios::sync_with_stdio(false); cin.tie(0);
  //b
  int n;
  long long d;
  cin >> n >> d;
  int ans = 0;
  for (int i = 0; i < n; i++) {
    long long x, y;
    cin >> x >> y;
    ans += (x * x + y * y <= d * d);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3608
#include<map>
#include<queue>
#include<time.h>
#include<limits.h>
#include<cmath>
#include<ostream>
#include<iterator>
#include<set>
#include<stack>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define rep_1(i,m,n) for(int i=m;i<=n;i++)
#define mem(st) memset(st,0,sizeof st)
inline int read()
{
	int num=0, w=0;
	char ch=0;
	while (!isdigit(ch))
	{
		w|=ch=='-';
		ch = getchar();
	}
	while (isdigit(ch))
	{
		num = (num<<3) + (num<<1) + (ch^48);
		ch = getchar();
	}
	return w? -num: num;
}
typedef long long ll;
typedef pair<int,int> pii;
typedef unsigned long long ull;
typedef pair<double,double> pdd;
const int inf = 0x3f3f3f3f;
const int N=2e6+10;
int a[N];
void solve()
{
	int n,x,t;
	cin>>n>>x>>t;
	int num=n/x;
	if(n%x)
		num++;
	cout<<num*t<<endl;
}
signed main()
{
	int t=1; 
	while(t--)
		solve();
	return 0;
}



Measured memory_bytes: 3620
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
#include<queue>
#include<stack>
#include<cmath>
using namespace std;
int main(){
    long long n,k;
    long long ans=0,tmp;
    cin>>n>>k;
	if(n*n<=1e8){
	  for(int i=1;i<=n;i++){
		  for(int j=1;j<=n;j++){
			 if(i%j>=k){
				ans++;
			 }
		 }
	  }
	} 
	else {
        for(long long i=k+1;i<=n;i++){
    	    tmp=n%i;
    	    ans+=(n/i)*(i-k);
    	    ans+=max(tmp-k+1,(long long)0);
	    }
	    if(k==0)ans=n*n; 
    } 
	cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>

signed main(){
  int n;
  std::cin>>n;
  int64_t ans = 0;
  for(ans=1;ans*(ans+1)/2<n;++ans);
  int except = (ans*(ans+1)/2)-n;
  for(int i=1;i<=ans;++i){
    if(i==except)continue;
    std::cout<< i <<std::endl;
  }
}


Measured memory_bytes: 3640
#include<iostream>
#include<fstream>
#include<string>
#include<cmath>
#include<queue>
#include<stack>
using namespace std;

int main(){
	 int n,fsize,bsize,a;
	 stack<int> f;
	 queue<int> b;
	 
     cin >> n;
     if (n%2==0){
     	for (int i=0;i<n;i++){
     		cin >> a;
     		if (i%2==1){
     			f.push(a);
     		}
     		else{
     			b.push(a);
     		}
     	}
	}
	else{
		for (int i=0;i<n;i++){
			cin >> a;
			if (i%2==1){
     			b.push(a);
	     	}
    	 	else{
     			f.push(a);
     		}
     	}
	}
	
	fsize = f.size();
	bsize = b.size();
	
    for (int i=0;i<fsize;i++){
    	cout << f.top() << " ";
    	f.pop();
    }
     for (int i=0;i<bsize;i++){
    	cout << b.front() << " ";
    	b.pop();
    }

	return 0;
};

Measured memory_bytes: 2944
Q, H, S, D = map(int, input().split())
prices = {0.25: Q, 0.5: H, 1: S, 2: D}
n = int(input())
costs = {0.25: Q * 8, 0.5: H * 4, 1: S * 2, 2: D}
costs_sorted = sorted(costs.items(), key=lambda x: x[1])
ans = 0
for cost in costs_sorted:
    quantity = cost[0]
    div, n = divmod(n, quantity)
    ans += int(prices[quantity] * div)
    if n == 0:
        break

print(ans)


Measured memory_bytes: 38512
#include <iostream>
#include <vector>

using namespace std;

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

    vector<vector<int>> neighbor(n, vector<int>(n));
    for (int i = 0; i < n; i++) {
        int u, k;
        cin >> u >> k;
        for (int j = 0; j < k; j++) {
            int x;
            cin >> x;
            neighbor[u - 1][x - 1] = 1;
        }
    }

    for (int i = 0; i < neighbor.size(); i++) {
        for (int j = 0; j < neighbor[i].size(); j++) {
            if (j > 0)
                cout << " ";
            cout << neighbor[i][j];
        }
        cout << endl;
    }

    return 0;
}



Measured memory_bytes: 3160
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define fi first
#define se second
#define pb push_back
#define rep(i, s, n) for (int i = s; i < n; i++)
#define rrep(i, s, n) for (int i = (n)-1; i >= (s); i--)
#define all(a) a.begin(),a.end()
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
const long long MOD = 1000000007, INF = 1e17;
 
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)
 
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;}



signed main()
{
	IOS();
	int N,M;
	vector<pair<int,int>>ans;
	while(1){
		cin>>N>>M;
		if(N==0&&M==0)break;
		vector<int>a(N),b(M);
		int as = 0,bs = 0;
		rep(i,0,N){
			cin>>a[i];
			as += a[i];
		}
		rep(i,0,M){
			cin>>b[i];
			bs += b[i];
		}
		int mi = INF;
		pair<int,int> it = {-1,-1};
		rep(i,0,N){
			rep(j,0,M){
				if(as-a[i]+b[j]==bs-b[j]+a[i]){
					if(chmin(mi,a[i]+b[j])){
						it = {i,j};
					}
				}
			}
		}
		if(it.fi!=-1)ans.push_back({a[it.fi],b[it.se]});
		else ans.push_back(it);
	}
	for(auto e:ans){
		if(e.fi==-1){
			cout<<-1<<endl;
		}else{
			cout<<e.fi<<" "<<e.se<<endl;
		}
	}
}



Measured memory_bytes: 3208
from sys import stdin

input = stdin.readline

m = int(input())
dc = []
for _ in range(m):
    d, c = map(int,input().split())
    dc.append((d, c))

def cal(d, c):
    if c == 1:
        return [0, d]
    t = 1 + (d + d >= 10)
    a = (d + d >= 10) + (d + d) % 10

    ca = cal(a, c // 2)

    if c % 2:
        return [(c // 2) * t + ca[0] + 1 + (ca[1] + d >= 10), (ca[1] + d >= 10) + (ca[1] + d) % 10]
    else:
        return [(c // 2) * t + ca[0], ca[1]]


ans = 0
now = []
for d, c in dc:
    ca = cal(d, c)
    ans += ca[0]
    now.append(ca[1])

pre = 0
for i in now:
    pre = pre + i
    ans += 1
    if pre >= 10:
        ans += 1
        pre = pre % 10 + 1

print(ans - 1)


Measured memory_bytes: 120796
s_input = str(input())
 
s_1 = s_input[0:1]
s_2 = s_input[1:2]
s_3 = s_input[2:3]
 
count = 0
 
s_list = [s_1, s_2, s_3]
 
for s in s_list:
    if s == "1":
        count = count + 1
    else:
        None
      
print(count)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<bool,int> P;
#define rep(i,m,n) for(int i=m;i<n;i++)
ll mod=1e9+7;

int main(){
  int n,k;
  cin>>n>>k;
  string s;
  cin>>s;
  vector<P> a;
  int cur=1;
  rep(i,0,n-1){
    if(s[i]==s[i+1]){
      cur++;
    }
    else{
      if(s[i]=='1'){
        a.push_back(P(true,cur));
      }
      else{
        a.push_back(P(false,cur));
      }
      cur=1;
    }
  }
  if(s[n-1]=='1'){
    a.push_back(P(true,cur));
  }
  else{
    a.push_back(P(false,cur));
  }
  int tr=0;
  int fa=0;
  rep(i,0,a.size()){
    if(a[i].first) tr++;
    else fa++;
  }
  
  if(fa<=k) cout<<n<<endl;
  else{
    int b[tr+fa+1];
    b[0]=0;
    rep(i,0,tr+fa){
      b[i+1]=b[i]+a[i].second;
    }
    
    if(a[0].first && a[tr+fa-1].first){
      int ans=0;
      for(int i=0;i+2*k+1<=tr+fa;i+=2){
        ans=max(ans,b[i+2*k+1]-b[i]);
      }
      cout<<ans<<endl;
    }
    else if(!a[0].first && a[tr+fa-1].first){
      int ans=b[2*k]-b[0];
      for(int i=1;i+2*k+1<=tr+fa;i+=2){
        ans=max(ans,b[i+2*k+1]-b[i]);
      }
      cout<<ans<<endl;
    }
    else if(a[0].first && !a[tr+fa-1].first){
      int ans=b[tr+fa]-b[tr+fa-2*k];
      for(int i=0;i+2*k+1<=tr+fa;i+=2){
        ans=max(ans,b[i+2*k+1]-b[i]);
      }
      cout<<ans<<endl;
    }
    else{
      int ans=max(b[2*k]-b[0],b[tr+fa]-b[tr+fa-2*k]);
      for(int i=1;i+2*k+1<=tr+fa;i+=2){
        ans=max(ans,b[i+2*k+1]-b[i]);
      }
      cout<<ans<<endl;
    }
  }
}

Measured memory_bytes: 1652
N,*D=map(int,open(0).read().split())
def main():
    cnt=0
    for i in range(0,N*2,2):
        n1=D[i]
        n2=D[i+1]
        if n1==n2:
            cnt+=1
            if cnt>=3:
                return True
        else:
            cnt=0
    return False
if main():
    print("Yes")
else:
    print("No")

Measured memory_bytes: 61852
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include <numeric>
 
using namespace std;
using ll=long long;
#define rep(i,n) for(int i;i<n;i++)
#define ALL(a) (a).begin(),(a).end()

bool compare_by_b(pair<long, long> a, pair<long, long> b){
    return a.second < b.second;
}

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

    ll sum = 0;
    rep(i, n)sum += a[i];

    ll sunuke = a[0];
    ll arai = sum - a[0];
    ll res = abs(sunuke - arai);

    for(int i = 1; i < n-1; i++){
        sunuke += a[i];
        arai -= a[i];
        ll score = abs(sunuke - arai);
        if(score < res)res=score;
    }
    cout << res << endl;



}

Measured memory_bytes: 1792
import java.util.*
import kotlin.collections.ArrayList

fun main(args: Array<String>) {
    readLine()
    val values = readLine()!!.trim().split(' ').map(String::toInt)
    println(maxFactors(values).joinToString(" "){(it + 1).toString()})
}


class Flow(val to: Int, var hasFlow: Boolean) {
    private var mPair: Flow? = null
    var pair: Flow
        get() = mPair!!
        set(value) {
            mPair = value
        }
}
fun List<ArrayList<Flow>>.addEdge(a: Int, b: Int): Unit {
    this[a].add(Flow(b, true))
    this[b].add(Flow(a, false))
    this[a].last().pair = this[b].last()
    this[b].last().pair = this[a].last()
}
fun calMaxSize(values: List<Int>): Int {
    val nodes = List(values.size * 2 + 2){ArrayList<Flow>()}
    for (i in values.indices) {
        nodes.addEdge(values.size * 2, i)
        nodes.addEdge(i + values.size, values.size * 2 + 1)
    }
    for (i in values.indices) {
        for (j in 0 until i) {
            if (values[i] % values[j] == 0) {
                nodes.addEdge(j, i + values.size)
            }
            if (values[j] % values[i] == 0) {
                nodes.addEdge(i, j + values.size)
            }
        }
    }
    return values.size - calMaxFlow(nodes, values.size * 2, values.size * 2 + 1)
}
fun calMaxFlow(nodes: List<List<Flow>>, source: Int, sink: Int): Int {
    val searching = IntArray(nodes.size){0}
    val depth = IntArray(nodes.size){0}
    val queue: Queue<Int>  = ArrayDeque<Int>()
    fun bfs(): Unit {
        queue.add(source)
        depth.fill(-1)
        depth[source] = 0
        while (queue.isNotEmpty()) {
            val top = queue.poll()
            for (e in nodes[top]) if (e.hasFlow && depth[e.to] == -1) {
                depth[e.to] = depth[top] + 1
                queue.add(e.to)
            }
        }
    }
    fun dfs(current: Int): Boolean {
        if (current == sink) return true
        while (searching[current] < nodes[current].size) {
            val e = nodes[current][searching[current]]
            if (e.hasFlow && depth[current] < depth[e.to] && dfs(e.to)) {
                e.hasFlow = false
                e.pair.hasFlow = true
                return true
            }
            ++searching[current]
        }
        return false
    }
    var count = 0
    var hasFlow = true
    while (hasFlow) {
        searching.fill(0)
        bfs()
        hasFlow = false
        while (dfs(source)) {
            ++count
            hasFlow = true
        }
    }
    return count
}

fun maxFactors(values: List<Int>): List<Int> {
    val rest = values.indices.toMutableList()
    val confirmed = mutableListOf<Int>()
    var count = calMaxSize(values)
    while (count != 0) {
        val top = rest.first()
        val filtered = rest.filterNot { values[it] % values[top] == 0 || values[top] % values[it] == 0}
        if (calMaxSize(filtered.map(values::get)) == count - 1) {
            --count
            rest.removeIf { values[it] % values[top] == 0 || values[top] % values[it] == 0}
            confirmed.add(top)
        }else {
            rest.removeAt(0)
        }
    }
    return confirmed
}


Measured memory_bytes: 37168
#include<bits/stdc++.h>
using namespace std;
const int N=1205;
int n,sum,tot,num,id[N][N],dp[N*N],d[N*N],a[N][N],head[N*N],nex[N*N],to[N*N];
bool vis[N*N];
void add(int u,int v){to[++tot]=v;nex[tot]=head[u];head[u]=tot;}
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        for(int j=1;j<i;j++)
        id[i][j]=id[j][i]=++sum;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<n;j++)
        {
            int x;
            scanf("%d",&x);
            a[i][j]=id[i][x];
            vis[a[i][j]]=true;
        }
        for(int j=2;j<n;j++)
            add(a[i][j-1],a[i][j]),d[a[i][j]]++;
    }
    queue<int>q;
    for(int i=1;i<=sum;i++)
        if(!d[i]&&vis[sum]) q.push(i),dp[i]=1;
    if(q.empty()){printf("-1\n");return 0;}
    int ans=0;
    while(!q.empty())
    {
        int u=q.front();q.pop();
        num++;
        ans=max(ans,dp[u]);
        for(int i=head[u];i;i=nex[i])
        {
            int v=to[i];d[v]--;
            dp[v]=max(dp[v],dp[u]+1);
            if(!d[v]) q.push(v);
        }
    }
    if(num!=sum) printf("-1\n");
    else printf("%d\n",ans);
}


Measured memory_bytes: 34176
N = int(input())
A = [int(a) for a in input().split()]

ans = []
if abs(max(A)) > abs(min(A)):
    num = max(A)
    idx = A.index(num)
    for i in range(1, N):
        while A[i-1] > A[i]:
            A[i] += num
            ans.append([str(idx+1), str(i+1)])
            if A[i] > num:
                num = A[i]
                idx = i
else:
    num = min(A)
    idx = A.index(num)
    for i in range(N-2, -1, -1):
        while A[i] > A[i+1]:
            A[i] += num
            ans.append([str(idx+1), str(i+1)])
            if A[i] < num:
                num = A[i]
                idx = i
                
m = len(ans)
print(m)
for i in range(m):
    print(" ".join(ans[i]))

Measured memory_bytes: 38384
#include <stdio.h>

int main(){
    int s;
    int i, j, a[10000], min = 10000, ansj;

    scanf("%d", &s);

    a[0] = s;

    for(i=1; i<10000; i++){
        if(a[i-1] % 2 == 0)
            a[i] = a[i-1] / 2;
        else
            a[i] = 3 * a[i-1] + 1;
    }

    for(i=0; i<10000; i++){
        for(j=0; j<10000; j++){
            if(j > i && a[i] == a[j]){
                if((j-i) < min){
                    min = j - i;
                    ansj = j;
                }
            }
        }
    }

    printf("%d\n", ansj + 1);

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>

using namespace std;

int N,M;
vector<int>G[5100];

int main(){
  for(int i=0;i<5100;i++) G[i].resize(i+10, 0);
  scanf("%d%d",&N,&M);
  for(int i=0;i<M;i++){
    int a,b,x;scanf("%d%d%d", &a,&b,&x);
    G[a][b]++; G[a][b+1]--;
    G[a+x+1][b]--; G[a+x+1][b+x+2]++;
    G[a+x+2][b+1]++; G[a+x+2][b+x+2]--;
  }

  for(int i=0;i<=N+5;i++) for(int j=0;j<=i;j++) G[i][j+1] += G[i][j];
  for(int i=0;i<=N+5;i++) for(int j=i;j<=N+5;j++) G[j+1][i] += G[j][i];
  for(int i=0;i<=N+5;i++) for(int j=0;j<=i;j++) G[i+1][j+1] += G[i][j];
  int res = 0;
  for(int i=0;i<=N+5;i++) for(int j=0;j<=i;j++) if(G[i][j]) res++;
  printf("%d\n", res);
  return 0;
}

Measured memory_bytes: 52200
#include<cstdio>
#include<algorithm>
char s[101],t[101];
int main(){
    scanf("%s%s",s,t);
    int len=0;
    while(s[len]!='\0')len++;
    for(int i=0;i<len;i++){
        bool flag=true;
        for(int j=0;j<len;j++){
            if(s[j]!=t[(i+j)%len]){
                flag=false;
                break;
            }
        }
        if(flag){
            printf("Yes");
            return 0;
        }
    }
    printf("No");
    return 0;
}

Measured memory_bytes: 128
N = int(input())

H_ls = list(map(int,input().split(" ")))

h_left = H_ls[0]-1

ans = "Yes"
for h in H_ls:
    if h_left < h:
        h-=1
    elif h_left > h:
        ans = 'No'
        break
    h_left = h

print(ans)


Measured memory_bytes: 14252
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;
using namespace std;
#define lld long long int 
#define vll vector<long long int>
#define vs vector<string> 
#define vint vector<int> 
#define vp vector<pair<int,int>>
#define vpll vector<pair<long long int , long long int>>
#define forl(i,a,b) for(int i = a ; i <= b ; i++)
#define forln(i,a,b) for(int i = a; i < b ; i++)
#define forb(i,b,a) for(int i = b ; i >= a ; i--)
#define forbn(i,b,a) for(int i = b ; i > a ; i--)
lld mod = 1e9 + 7;
#define len(str) lld len = str.length();
#define ps push_back
#define B begin
#define E end
#define mk make_pair
#define F first 
#define S second 
#define FAST ios_base::sync_with_stdio(false),cin.tie(NULL)
#define test()                  lld t; cin>>t; while(t--)

typedef tree< pair<lld, lld>, null_type,less<pair<lld, lld>>,rb_tree_tag,
tree_order_statistics_node_update> ordered_set;

#define o_set tree<lld, null_type,greater_equal<lld>, rb_tree_tag,tree_order_statistics_node_update> 

/*
struct cmp
{
	bool operator()(const pair<int,int>& l , const pair<int,int>&r){
		if(l.F > r.F) return true;
		if(l.F == r.F){
			if(l.S < r.S) return true;
			else return false;
		}else return false;
	}
};

*/
lld power(lld x, lld y) 
{ lld temp; if( y == 0) return 1; temp = power((x%mod), (y%mod)/2); if (y%2 == 0) return ((temp%mod)*(temp%mod))%mod;else return (((x%mod)*(temp%mod))%mod*(temp%mod))%mod;} 


void solution( void );

int main()
{
	FAST;
	solution();
	return 0;
}
void solution()
{
		int a,b;
		cin>>a>>b;
		cout<<a*b<<endl;
}



Measured memory_bytes: 3612
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) {
			BufferedReader input = new BufferedReader(new InputStreamReader(System.in));


			  try{

				  String ab = input.readLine();
				  String[] strAry = ab.split(" ");
				  //????????????????????\??????????????°????????????????????§???????????????
				  int a = Integer.parseInt(strAry[0]);
				  //??????strAry??????????????????????????????????????????
				  int b = Integer.parseInt(strAry[1]);

				  if(a < b){
					  System.out.println("a < b");
				  }else if(a > b){
					  System.out.println("a > b");
				  }else if(a == b){
					  System.out.println("a == b");
				  }

			    }catch(IOException e) {   System.out.println("Exception : " + e);
			    }


		}


	}

Measured memory_bytes: 24200
#include<iostream>
using namespace std;
int main()
{
	int n,A[100],flag = 0;
	cin>>n;
	for(int i=0 ; i<n ; i++)
	{
		cin>>A[i];
	}
	for(int i=0 ; i<n-1  ;i++)
	{
		for(int j=n-1 ; j>i ; j--)
		{
			if(A[j]<A[j-1])
			{
				int temp = A[j];
				A[j] = A[j-1];
				A[j-1] = temp;
				flag++;
			}
		}
	}
	for(int i=0 ; i<n ; i++)
	{
		cout<<A[i];
		if(i != n-1)
		{
			cout<<" ";
		}
	}
	cout<<endl<<flag<<endl;
}


Measured memory_bytes: 3088
#include <bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	cin >> s;
	int t=0, i;
	for (i=0; i<s.size(); i++)
	{
		if (s[i]=='+') t++;
		else t--;
	}
	cout << t << endl;
	return 0;
}

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

using namespace std;

const int N = 1e5 + 5;
int ans[N] , k;
vector<pair<int , int> > adj[N];

void dfs (int node , int par , int col) {
    int nxt = 1;
    for (auto &c : adj[node]) {
        if (c.first == par) continue;
        nxt += nxt == col;
        k = max(k , nxt);
        ans[c.second] = nxt;
        dfs(c.first , node , nxt);
        nxt++;
    }
}

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

    int n;
    cin >> n;

    for (int i = 0 ;i < n - 1 ;i++) {
        int u , v;
        cin >> u >> v;
        adj[u].push_back({v , i});
        adj[v].push_back({u , i});
    }

    dfs(1 , 1 , -1);

    cout << k << '\n';
    for (int i = 0 ;i < n - 1 ;i++)
        cout << ans[i] << '\n';
}


Measured memory_bytes: 12536
#include <bits/stdc++.h>
#define pi 3.14159
using namespace std;
typedef long long LL;
const LL MOD = 1e9 + 7;
const int N = 1e5 + 7, M = 1e7, OO = 0x3f3f3f3f;
#define AC ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); cin.sync_with_stdio(0);
int main()
{
int n,x,y;
cin>>n;
    x=n/15;
    y=x*200;
    cout<<n*800-y;


    return 0;
}


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

int H, W;
char field[101][101];
int dh[4] = {1, 0, -1, 0}, dw[4] = {0, 1, 0, -1}; //上下左右の四方向のみ探索するため

//動的計画法
void dfs(int h, int w){
    char base = field[h][w];
    field[h][w] = '.'; //探索済みの印

    for(int i = 0; i < 4; i++){
        int nh = h + dh[i];
        int nw = w + dw[i];

        //場外アウトまたはbaseと同じ果物でなければ
        if(nh < 0 || nh > H || nw < 0 || nw > W) continue;
        if(field[nh][nw] != base) continue;
        dfs(nh, nw);
    }

    /*char u = field[h - 1][w];
    char d = field[h + 1][w];
    char l = field[h][w - 1];
    char r = field[h][w + 1];

    if(field[h - 1][w] == base) dfs(h - 1, w);
    if(field[h + 1][w] == base) dfs(h + 1, w);
    if(field[h][w - 1] == base) dfs(h, w - 1);   
    if(field[h][w + 1] == base) dfs(h, w + 1); */
}

int main(void){
    while(cin >> H >> W){
        if(H + W == 0) break;

        //果樹園の地図を作成する
        for(int i = 0; i < H; i++){
            for(int j = 0; j < W; j++){
                cin >> field[i][j];
            }
        }

        //探索開始
        int c = 0; //分配後の区画数
        for(int i = 0; i < H; i++){
            for(int j = 0; j < W; j++){
                //場外アウトならば、それ以降は実行せずスルー
                if(field[i][j] == '.') continue;
                dfs(i, j);
                c++;
            }
        }
        cout << c << endl;
    }
}



Measured memory_bytes: 3528
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N =2000+10;
const int mod=1e9+7;
#define P pair<int, int>

int main()
{
    int x,y;
    cin>>x>>y;
    if(x>=1&&x<=9&&y>=1&&y<=9)
        cout<<x*y<<"\n";
    else
        cout<<"-1\n";
    return 0;
}


Measured memory_bytes: 256
X, Y = map(int, input().split())

ans = 0

if X == 1:
    ans += 300000
elif X == 2:
    ans += 200000
elif X == 3:
    ans += 100000

if Y == 1:
    ans += 300000
elif Y == 2:
    ans += 200000
elif Y == 3:
    ans += 100000

if X == 1 and Y == 1:
    ans += 400000

print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <queue>
#include <iomanip>
using namespace std;
typedef long long ll;

int main() {
    int a, b, ans = 0, l = 1;
    cin >> a >> b;
    while (l < b) {
        l += a - 1;
        ans++;
    }
    cout << ans << endl;

}

/* 
g++ -std=c++14 main.cpp
*/

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  string a,b,c;
  cin >> a >> b >> c;
  int d,e,f;
  d = a.size();
  e = b.size();
  f = c.size();
  if(a.at(d-1) == b.at(0) && b.at(e-1) == c.at(0))
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int[] a=new int[4];
		int[] b=new int[4];
		int a_p=0,b_p=0;
		for(int i=0; i<4; i++) {
			a[i]=sc.nextInt();
			a_p+=a[i];
		}

		for(int i=0; i<4; i++) {
			b[i]=sc.nextInt();
			b_p+=b[i];
		}

		System.out.println(Math.max(a_p, b_p));
	}
}



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

int main(){
  int N;
  cin >> N;
  map<string,int> A;
  for(int i=0;i<N;i++){
    string S;
    cin >> S;
    A[S]++;
  }
  int maxcount=0;
  for(auto it=A.begin();it!=A.end();it++){
    maxcount=max(maxcount,(*it).second);
  }
  for(auto it=A.begin();it!=A.end();it++){
    if(maxcount==(*it).second){
      cout << (*it).first << endl;
    }
  }
}

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


using namespace std;



const int MAXN = 500 * 1000 + 23, INF = 1000 * 1000 * 1000 + 23;










int n, k, p[MAXN], inv[MAXN];

vector<int> kmrg(vector<int> u, vector<int> v) {
	vector<int> m, res;
	reverse(u.begin(), u.end());
	m.push_back(u[0]);
	for (int i = 1; i < (int)u.size(); i++) {
		int tmp = m.back();
		m.push_back(min(u[i], tmp));
	}
	reverse(v.begin(), v.end());
	while (!u.empty() && !v.empty())
		if (v.back() <= m.back() - k) res.push_back(v.back()), v.pop_back();
		else res.push_back(u.back()), m.pop_back(), u.pop_back();
	while (!u.empty()) res.push_back(u.back()), u.pop_back();
	while (!v.empty()) res.push_back(v.back()), v.pop_back();
	return res;
}


vector<int> msrt(int l, int r) {
	if (r - l == 1) return {inv[l]};
	int mid = (l + r) >> 1;
	vector<int> u = msrt(l, mid), v = msrt(mid, r);
	return kmrg(u, v);
}




int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr), cout.tie(nullptr);
	cin >> n >> k;
	for (int i = 0; i < n; i++) {
		cin >> p[i];
		inv[--p[i]] = i;
	}
	vector<int> vec = msrt(0, n);
	for (int i = 0; i < n; i++) p[vec[i]] = i;
	for (int i = 0; i < n; i++) cout << p[i] + 1 << '\n';
	return 0;
}

Measured memory_bytes: 11192
import java.util.*;

public class Main {
    public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
    int A = sc.nextInt();
    String op = sc.next();
    int B = sc.nextInt();

    if(op.charAt(0)== '+'){
    System.out.println(A+B);
    }else{
    System.out.println(A-B);    
    }
    }
}

Measured memory_bytes: 35612
n = int(input())
s = [input() for _ in range(n)]
import collections
c = collections.Counter(s)
d = c.most_common()
e = [d[0][0]]
for i in range(len(d)-1): #nじゃない　dの長さ
   if d[0][1] == d[i+1][1]:
      e.append(d[i+1][0])       #辞書順にする
e.sort()
print('\n'.join(e))   #print(repr(e))でもいける？

Measured memory_bytes: 50312
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<list>
#include<map>
#include<numeric>
#include<iomanip>
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define ll long long

using namespace std;

//最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) {
		return a;
	}
	return gcd(b, a % b);
}

//最小公倍数
ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
}

int main() {
	ll a, b, n;
	cin >> a >> b >> n;
	ll i = min(n, b - 1);

	ll ans = (a * i) / b - a * (i / b);

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



Measured memory_bytes: 3632
N, M = gets.split.map(&:to_i)
if M > 0
  inf = 10000000000 * M
  arr = Array.new(8){Array.new(M){-inf}}
  N.times do
    x, y, z = gets.split.map(&:to_i)
    for j in 0..7 do
      num = x * (-1) ** j + y * (-1) ** (j / 2) + z * (-1) ** (j / 4)
      if num > arr[j][M-1]
        arr[j].pop
        k = M - 2
        while k > 0 && num > arr[j][k-1]
          k -= 1
        end
        arr[j].insert(k, num)
      end
    end
  end
  ans = []
  arr.each {|nums| ans += [nums.inject(&:+)]}
  puts ans.max
else
  N.times{gets}
  puts 0
end

Measured memory_bytes: 1916
#include <stdio.h>
#include <string.h>

int main(void){
	char str[1000];
	int len;
	int i;

	scanf("%[^\n]%*c", str);
	len = strlen(str);

	for(i=0; i < len; i++){
		if('a' <= str[i] && str[i] <= 'z'){
			str[i] -= ('a' - 'A');
		}
	}

	printf("%s\n", str);

	return 0;
}

Measured memory_bytes: 0
import math
n,d = map(int,input().split())
list1 = []
for i in range(n):
	list1.append(list(map(int,input().split())))

def func(i,j):
	global list1
	global d
	cout = 0
	for k in range(d):
		cout += (list1[i][k] - list1[j][k])**2
	return math.sqrt(cout)

count = 0

for i in range(0,n-1):
	for j in range(i+1,n):
		judge = func(i,j)
		if judge.is_integer():
			count += 1
print(count)


Measured memory_bytes: 3064
n = int(input())
d_list = [int(i) for i in input().split()]
R_max = max(d_list)+1
R = [0] * R_max
ans = 1
if d_list[0] != 0:
  print(0)
  exit()
  
for di in d_list:
  R[di] += 1
  
if R[0] != 1:
  print(0)
  exit()
  
for i in range(1, R_max):
  ans *= R[i-1]**R[i]%998244353
print(ans%998244353)

Measured memory_bytes: 52824
#include<bits/stdc++.h>
using namespace std;
template <typename T> using vec = vector<T>;

int main()
{
	long a;
	string b;
	cin >> a >> b;
	int c = (int)(b.at(0)-'0')*100 + (int)(b.at(2)-'0')*10 + (int)(b.at(3)-'0');
	cout << a*c/100 << endl;
}

Measured memory_bytes: 3548
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
using namespace std;
int main() {
  
  int N;
  cin>>N;
  
  vector<char> vec(N);
  for(int i=0;i<N;i++){
    cin>>vec[i];
  }

  int ans=1;
  
  
  for(int i=0;i<N-1;i++){
    if(vec[i+1]!=vec[i]){
      ans++;
    }
  }
  
  cout<<ans<<endl;
}

Measured memory_bytes: 3696
#include <iostream>
#include <cstring>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <math.h>
#include <string>
#include <map>
#include <cstdlib>
#include <sstream>
#include <bitset>
using namespace std;

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

int main()
{
    int N;
    cin >> N;
    vector<P> A(N);
    for(int i=0; i<N; i++){
        int tmp;
        cin >> tmp;
        A[i]=P(tmp, i+1);
    }
    sort(A.begin(), A.end());
    for(int i=0; i<N-1; i++){
        cout << A[i].second << ' ';
    }
    cout << A[N-1].second << endl;

    

    return 0;
}

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

using namespace std;
typedef long long ll;
//typedef unsigned long long ll;

//#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define sz(x) ll(x.size())
//typedef pair<ll, int> P;
//typedef pair<ll, ll> P;
//const double INF = 1e10;
const ll INF = LONG_LONG_MAX / 100;
//const ll INF = 1e15;
const ll MINF = LONG_LONG_MIN;
//const int INF = INT_MAX / 10;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)

bool contain(set<char> &s, int a) { return s.find(a) != s.end(); }

//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);

void print_line(vector<ll> &line) {
    if (line.size() == 0ll) {
        cout << endl;
        return;
    }
    for (ll i = 0; i < line.size(); i++) {
        cout << line[i];
        if (i == line.size() - 1) cout << endl;
        else cout << ' ';
    }
}


typedef priority_queue<long long, vector<long long>, greater<long long> > PQ_ASK;
const int mod = 1000000007;

typedef pair<ll, ll> P;

int main() {
    int n;
    cin >> n;
    vector<ll> s(n);
    rep(i, n)cin >> s[i];

    int q;
    cin >> q;
    int count = 0;
    rep(i, q) {

        int t;
        cin >> t;

        for (int j = 0; j < n; j++) {
            ll k = s[j];
            if (k == t) {
                count++;
                break;
            }
        }
    }
    cout << count << endl;
}



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

//============================================================================
// Name        : a.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================
#include <iostream>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;

int main() {
	int n;cin>>n;
	vector<int> d(n);
	for(int i=0;i<n;i++){
		cin>>d[i];
	}
	ll def=998244353;
	if(d[0]!=0){
		cout<<0<<endl;
		return 0;
	}
	vector<int> count(n,0);
	for(int i=0;i<n;i++){
		count[d[i]]++;
	}
	if(count[0]!=1){
		cout<<0<<endl;
		return 0;
	}
	ll ans=1;
	int end=0;
	for(int i=1;i<n;i++){
		for(int j=0;j<count[i];j++){
			ans*=count[i-1];
			ans%=def;
		}
	}
	cout<<ans<<endl;
	return 0;
}

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

int main(){
    int n,max=0;
    cin>>n;
    vector<int> v(n),c(n);
    for(int i=0;i<n;i++) cin>>v[i];
    for(int i=0;i<n;i++){
        cin>>c[i];
        if(v[i]>c[i]) max+=v[i]-c[i];
    }
    cout<<max<<endl;
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

int main(void){
	ll n,ans=0ll;
	cin >> n;
	if(n%2){
		cout << 0 << endl;
	}else{
		n /= 2;
		while(n){
			n /= 5;
			ans += n;
		}
		cout << ans << endl;
	}
	return 0;
}


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

int main()
{
    vector<int> n(4);

    for (int i = 0; i < 4; i++)
    {
        cin >> n[i];
    }
    sort(n.begin(), n.end());

    if (n[0] = 1 && n[1] == 4 && n[2] == 7 && n[3] == 9)
    {
        cout << "YES" << endl;
    }
    else
    {
        cout << "NO" << endl;
    }
    
    
    
    
    
}

Measured memory_bytes: 256
#include "bits/stdc++.h" // 提出時こちらで問題なし
using namespace std;

int main() {
	int num_N = 0;
	int ans = 0;
	cin >> num_N;

	vector<int> v(num_N);
	for (int i = 0; i < num_N;  i++) {
		cin >> v.at(i);
	}

	int tmp = 0;
	for (int i = 0; i < num_N; i++) {
		if (i % 2 == 0) {
			tmp = v.at(i);
			if (tmp % 2 == 1) {
				ans++;
			}
			else {
				// pass;
			}
		}
		else {
			//pass;
		}
	}
	cout << ans;
	//system("pause");
}

Measured memory_bytes: 3596
import java.util.*;

class Main{
    public static void main(String[] args) {
        Scanner stdIn = new Scanner(System.in);
        int a = stdIn.nextInt();
        int b = stdIn.nextInt();
        int c = stdIn.nextInt();

        if(a == b){
          if(a != c) System.out.println("Yes");
          else System.out.println("No");
          return;
        } if(b == c){
          if(b != a) System.out.println("Yes");
          else System.out.println("No");
          return;
        } if(c == a){
          if(c != b) System.out.println("Yes");
          else System.out.println("No");
          return;
        }else{
          System.out.println("No");
          return;
        }

    }
}



Measured memory_bytes: 23124
#include <bits/stdc++.h>
using namespace std;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout << fixed << setprecision(12);

    int l;
    cin >> l;

    double len = (double)l/3;

    cout << len*len*len << '\n';
    return 0;
}




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

#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, n, m) for (int i = n; i < m; i++)
#define ll long long int

using namespace std;

int main() {
  int n, ruiseki[200005] = {};
  string s;
  cin >> n;
  cin >> s;

  REP(i,n) {
    if (s[i] == '#') {
      ruiseki[i+1] += ruiseki[i] + 1;
    } else {
      ruiseki[i+1] = ruiseki[i];
    }
  }

  int result = 10000000;
  REP(i,n+1) {
    int tmp = (n - i) - (ruiseki[n] - ruiseki[i]) + ruiseki[i];
    result = min(tmp, result);
  }

  cout << result << endl;

}


Measured memory_bytes: 1412
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, a, n) for(ll i = a; i < (ll)(n); i++)
#define memi cout << endl
#define kono(n) cout << fixed << setprecision(n)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define hina cout << ' '
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define in3(n, m, l) cin >> n >> m >> l
#define out(n) cout << n
const ll mei = (ll)1e9 + 7;

int main(){
  ll k, a, b;
  in3(k, a, b);
  string s = "NG";
  rep2(i, a, b + 1){
    if(i % k == 0)
      s = "OK";
  }
  out(s);
  memi;
}

Measured memory_bytes: 3628
using System;
using System.Collections.Generic;
using System.Linq;
using static Input;
using NX = System.Int64;


public class Prog
{
    public static void Solve()
    {
        int X = NextInt(), Y = NextInt();
        if (X > Y) { int temp = X; X = Y; Y = temp; }
        //1:2になるまで3で割る
        NX count = 0;
        while (Y != X * 2)
        {
            Y -= 3;
            X -= 3;
            count += 2;
            if (X < 0 || Y < 0) { Console.WriteLine(0); return; }
        }
        NX C = count + X;
        NX ans = PCH.nCr(count + X, count / 2 + X);
        Console.WriteLine(ans);

    }
    public static void Main()
    {
        var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
        Console.SetOut(sw);
        Solve();
        Console.Out.Flush();
        return;
    }

}
public static class PCH
{
    public static long nPr(long n, long r, long m = 1000000007)
    {
        for (long i = 0; i < r; r++) { n *= (n - i); n %= m; }
        return n;
    }
    public static long nCr(long n, long r, long m = 1000000007)
    {
        if (r == 0) return 0;
        long a = 1;
        for (long i = 0; i < r; i++) { a *= (n - i); a %= m; }
        long b = 1;
        for (long x = 2; x <= r; x++) { b *= x; b %= m; }
        b = RepPow(b, m - 2) % m;
        return (a * b) % m;
    }
    public static long nHr(long n, long r, long m = 1000000007)
    {
        return nCr(n + r - 1, r, m);
    }
    public static long RepPow(long x, long p, long m = 1000000007)
    {
        if (p == 0) return 1;
        if (p == 1) return x % m;
        long b = RepPow(x, p / 2, m) % m;
        if (p % 2 == 0) { return (b * b) % m; }
        else { return (x * ((b * b) % m)) % m; }
    }
}
public class Input
{
    public const long MOD = 1000000007;
    public const int INF = 1000000007;
    private static Queue<string> q = new Queue<string>();
    private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); }
    public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); }
    public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); }
    public static string NextString() { Confirm(); return q.Dequeue(); }
    public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); }
    public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
    public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
    public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); }
    public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
    public long Abs(long a, long b) => Math.Abs(a - b);
}


Measured memory_bytes: 13268
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))
#l = [list(map(int,input().split())) for i in range(n)]
#a = [list(input()) for _ in range(n)]
#a = [input() for _ in range(n)]


n,m,x,y = map(int, input().split())
xl = list(map(int, input().split()))
yl = list(map(int, input().split()))

xmax = max(xl)
ymin = min(yl)

isWar = True
for i in range(x+1, y+1):
    if (xmax < i and ymin >= i):
        isWar = False
        break
if (isWar):
    print("War")
else:
    print("No War")



Measured memory_bytes: 9080
#include <iostream>
#include <string>
#include <vector>

int main() {
  	std::cin.tie(nullptr);
  
    int N, Q;
    std::string S;
    std::cin >> N >> Q >> S;

    std::vector<int> cnt(N + 1, 0);
    for (int i = 2; i <= N; ++i) {
        cnt[i] = cnt[i - 1];
        if (S.substr(i - 2, 2) == "AC") ++cnt[i];
    }

    for (int q = 0; q < Q; ++q) {
        int l, r;
        std::cin >> l >> r;
        std::cout << cnt[r] - cnt[l] << std::endl;
    }
    return 0;
}


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

int memo[101][101][3][3];

//k=0(曲がってない),k=1(w-1方向に曲がった),k=2(h-1方向に曲がった)
int solve(int w, int h, int k, int p){

  if(!w && !h) return 1;
  if(w < 0 || h < 0) return 0;
  if(memo[w][h][k][p]) return memo[w][h][k][p];

  int ans = 0;
  if(!k || k == p) ans += solve(w-1, h, p, 1) + solve(w, h-1, p, 2);
  else if(p == 1) ans += solve(w-1, h, p, 1);
  else if(p == 2) ans += solve(w, h-1, p, 2);

  return memo[w][h][k][p] = ans%100000;
}

int main(){

  int w,h;

  while(true){
    cin >> w >> h;
    if(!w && !h) break;
    memset(memo, 0, sizeof(memo));
    cout << solve(w-1, h-1, 0, 0) << endl;
  }
}

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

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

	vector<long long> num( K );
	for( int i = 1; i <= N; i++ ) num[ i % K ]++;
	long long ans = 0;
	for( int a = 0; a < K; a++ ) {
		int b = (K - a) % K;
		int c = (K - a) % K;
		if( (b + c) % K == 0 ) ans += num[a] * num[b] * num[c];
	}

	cout << ans << endl;
}


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

int main(void){
	int h, w, k, i, j, num = 1, cur = -1, fr = 500;
    cin >> h >> w >> k;
    
    vector<vector<int>> ans(h, vector<int>(w, -1));
    vector<int> cp(h, -2);
    for (i = 0; i < h; i++){
    	string s; bool ok = false, first = true;
        cin >> s;
        for (j = 0; j < w; j++) if (s[j] == '#') {ok = true; break;}
        if (!ok) {cp[i] = cur; continue;}

        cur = i; fr = min(fr, i);
        for (j = 0; j < w; j++){
        	if (s[j] == '#'){
            	if (first) ans[i][j] = num, first = false;
                else ans[i][j] = ++num;
            }else{
            	ans[i][j] = num;
            }
        }
      	++num;
    }
    
    for (i = 0; i < h; i++){
		if (cp[i] == -2) for (j = 0; j < w; j++) cout << ans[i][j] << " ";
        else if (cp[i] == -1) for (j = 0; j < w; j++) cout << ans[fr][j] << " ";
        else for (j = 0; j < w; j++) cout << ans[cp[i]][j] << " ";
        cout << "" << endl;
    }
    
	return 0;
}

Measured memory_bytes: 3984
# ABC_081_B_Shift_only.py
N = int(input())
a = list(map(int, input().split()))
count = 0
while True:
	flag = 0
	for i in range(0, N):
		Ai = a[i]
		if Ai % 2 == 1:
			flag = 1
	if flag == 1:
		break
	for i in range(0, N):
		a[i] = a[i]//2
	count += 1
print(count)

Measured memory_bytes: 64124
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef vector<pii> vp;

int gcd(int a, int b){
    if(b==0) return a;
    return gcd(b,a%b);
}
int lcm(int a, int b){
    return a/gcd(a,b)*b;
}

vector<pii> primefactor(int n){
    vector<pii> ret;
    for(int i = 2; i*i <= n; i++)if(n % i == 0){
        int cnt = 0;
        while(n%i == 0)n /= i, cnt++;
        ret.push_back(pii(i,cnt));
    }
    if(n != 1)ret.push_back(pii(n,1));

    return ret;
}

#define MAX 200000

long long fac[MAX], finv[MAX], inv[MAX];

void init() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; 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;
    }
}

long long ncr(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


signed main(void) {
    init();
    int n,m;
    cin >> n >> m;
    vp a = primefactor(m);
    int ans = 1;
    rep(i,a.size()){
        //cout << a[i].first << " " << a[i].second << endl;
        ans *= ncr(a[i].second+n-1, a[i].second);
        ans %= MOD;
    }
    cout << ans << endl;
}


Measured memory_bytes: 4992
unittest
{
	assert( [ "4", "3 8 5 1" ].parse.expand.solve == "Yes" );
	assert( [ "4", "3 8 4 1" ].parse.expand.solve == "No" );
	assert( [ "10", "1 8 10 5 8 12 34 100 11 3" ].parse.expand.solve == "No" );
}



import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto n = input.front.to!( long );
	input.popFront;
	auto ls = input.front.split.to!( long[] );
	return tuple( ls );
}

auto solve( long[] ls )
{
	auto m = ls.reduce!max;
	auto s = ls.sum - m;
	return ( m < s ) ? "Yes" : "No";
}


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

int main() {
string S,T;
  int result = 1;
  cin >> S >> T;
  for(int a = 0;a < S.length();a++){
    if(S[a] != T[a])result = 0;
  }
  if(result == 0)cout << "No" << endl;
  if(result == 1)cout << "Yes" << endl;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define FIN         ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ii          pair<int,int>
#define F           first
#define S           second
#define pb          push_back
#define all(x)      (x).begin(),(x).end()
#define rall(x)     (x).rbegin(),(x).rend()
#define fore(i,a,b) for(int i = a;i < b; i+= 1)
#define forr(i,a)   for(int i = a; i >= 0; i--)
#define fori(i,m)   for(auto i = m.begin(); i != m.end(); i++) 
#define w(t)        while(t--)
#define sz(s)       int(s.size())
#define cls(a,car)  memset(a,car,sizeof (a))
#define db(x)       cerr << #x << " is " << x << '\n'
#define FL          freopen("input.txt", "r", stdin),freopen("output.txt", "w", stdout);
#define EjecuteTime cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"
#define angle(x)    double(x * acos(-1) / 180.0)
using namespace std;
typedef long long   ll;
typedef vector<int> vi;
typedef vector<ii>  vii;
const int N = 2 * 1e5 + 5;
const ll mod = 1e9 + 7;
const double E = 1e-9;
//int dx[] = {1, 0}, dy[] = {0, 1};
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
//int dx[] = {2, 1, -1, -2, -2, -1, 1, 2}, dy[] = {1, 2, 2, 1, -1, -2, -2, -1};
// fflush(stdout)
// cout << flush
// a + b = a ^ b + 2 * (a & b)
int add(int a, int b){return  a + b > mod ? a + b - mod : a + b;}
int mul(int a, int b){return a * b >= mod ? a * b % mod : a * b;} 
int v[N];
int main(){
    //FL;
    FIN;
    int n;
    cin >> n;
    for(int i = 0; i < n; i++)cin >> v[i];
    sort(v, v + n);
    reverse(v, v + n);
    ll ans = 0;
    for(int i = 0; i < (n - 1) / 2; i++){
        ans += 1ll * v[i];
    }
    //db(ans);
    for(int i = 1; i <= (n - 1) / 2; i++)
        ans += 1ll * v[i];
    if(!(n & 1))
        ans += 1ll * v[(n - 1) / 2];

    //db(ans);
    cout << ans << '\n';
    EjecuteTime;
    return 0;
}       

Measured memory_bytes: 4588