akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {

            int inputNum = int.Parse(Console.ReadLine());

            //?£???¨?????°??¨??¨?±????3?¬??????????(1?¬?????£????2?¬?????????°???3?¬??????¨?±???????)
            int[,,] roomNumber = new int[4, 3, 10];


            for (int d = 0; d < inputNum; d++)
            {
                string[] Input = Console.ReadLine().Split(' ');

                //??\????????????????????????????´?????????????
                for (int i = 0; i < 5; i++)
                {
                    if (i != int.Parse(Input[0]) - 1) continue;

                    for (int y = 0; y < 4; y++)
                    {
                        if (y != int.Parse(Input[1]) - 1) continue;

                        for (int j = 0; j < 11; j++)
                        {
                            if (j != int.Parse(Input[2]) - 1) continue;

                            roomNumber[i, y, j] += int.Parse(Input[3]);
                        }
                    }

                }
            }

            //????????????

            //?£??????\??£????????????????????????
            for (int a = 0; a < 4; a++)
            {

                string border = new string('#', 20);
                string output = string.Empty;

                for (int b = 0; b < 3; b++)
                {
                    for(int c = 0; c < 10; c++)
                    {
                        output += " "+roomNumber[a, b, c].ToString();
                    }

                    Console.WriteLine(output);
                    output = string.Empty;
                }


                if (a != 3) Console.WriteLine(border);
            
            }


        }


    }

    }

Measured memory_bytes: 9148
///Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>
using namespace std;
#define     int 	    long long
#define 	pb 	        push_back
#define 	mp 	        make_pair
#define 	pi 	        2*acos(0.0)
#define     scan(i)     scanf("%d",&i)
#define     loop(i,n) 	for(int i = 0 ; i <n ; i++)
#define 	vect 	    vector<int>
#define 	vec_it 	    vector<int>::iterator vi
#define     sorta(v)    sort(v.begin(),v.end())
#define     sortd(v)    sort(v.begin(),v.end(),greater<>())
#define 	mapp 	    map<int,int>
#define 	pairr 	    pair<int,int>
#define 	sett	    set<int>s
#define 	set_it 	    set<int>::iterator si
#define     map_it      map<int,int> :: iterator mi
#define 	yes 	    cout<<"Yes"<<endl
#define 	no 	        cout<<"No"<<endl
#define 	ff 	        first
#define 	ss 	        second
#define     mx          INT_MAX
#define     lmx         LLONG_MAX
#define     mn          INT_MIN
#define     lmn         LLONG_MIN
#define     GCD         __gcd(a,b)
#define     LCM         (a/GCD)*b
template <typename T> T gcd(T a,T b){return (b==0)?a:gcd(b,a%b);}
template <typename T> T lcm(T a,T b) {return a*(b/gcd(a,b));}
int modulo (int a, int b) { return a >= 0 ? a % b : ( b - abs ( a%b ) ) % b; }

void solve()
{
  // freopen ("(input).txt" , "r",  stdin) ;
  // string st,stt ;
  // int low=0,high=0;
  // int l,r;
    int n,k,t,b,c,x,y,z,d=0,temp=-1,cnt=mx,sum=0,f=0;
    cin>>n>>k  ; vect v(n) ,a  ; sett ; set_it ; mapp m,mp; pairr p; map_it;
    loop(i,n)
    {
        cin>>v[i];
        if(i>0&&v[i]+v[i-1]>=k)
        {
            temp=i;
            cnt=i-1;
        }
    }
    if(temp==-1)
        cout<<"Impossible"<<endl;
    else
    {
        cout<<"Possible"<<endl;
        for(int i=0;i<cnt;i++)
            cout<<i+1<<endl;
        for(int i=n-1;i>cnt;i--)
            cout<<i<<endl;
    }




}

main()
{
    int t;
  //  cin>>t;
  //  while(t--)
        solve();
}

Measured memory_bytes: 4060
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int count = 0;
        int min = 200005;
        for (int i = 0; i < n; i++) {
            int val = sc.nextInt();
            if (val < min) {
                ++count;
                min = val;
            }
        }
        System.out.println(count);
    }
}

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

int main(){
	ll N,ans=0;
	cin >> N;
	stack< pair<ll,ll> > st;
	st.push({0,0});
	while(not st.empty()){
		auto x = st.top();
		st.pop();
		if(x.second==7)ans++;
		if(x.first*10+3<=N)st.push({x.first*10+3,x.second|1});
		if(x.first*10+5<=N)st.push({x.first*10+5,x.second|2});
		if(x.first*10+7<=N)st.push({x.first*10+7,x.second|4});
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>          // printf(), scanf()
#include <stdbool.h>

int
main(int argc, char **argv)
{
	int d, w, h;
	double a, b;
	int r;
	int n;

	while (true)
	{
		scanf("%d %d %d", &d, &w, &h);
		if (d == 0 && w == 0 && h == 0)
			break;

		if (d < w)
		{
			if (d < h) /* d < w ? h */
			{
				a = d;
				b = (w < h) ? w : h;
			}
			else /* h <= d < w ? */
			{
				a = h;
				b = d;
			}
		}
		else /* w <= d ? */
		{
			if (w < h) /* w <= d ? h */
			{
				a = w;
				b = (d < h) ? d : h;
			}
			else /* h <= w <= d ? */
			{
				a = h;
				b = w;
			}
		}

		a /= 2;
		b /= 2;
		scanf("%d", &n);
		while (n--)
		{
			scanf("%d", &r);
			if (a * a + b * b < r * r)
				printf("OK\n");
			else
				printf("NA\n");
		}
	}

	return 0;
}

Measured memory_bytes: 584
#include <stdio.h>
#include <string.h>
#include <math.h>
#pragma warning(disable : 4996)

int fab(long long a, long long b) {

    int ta = 0, tb = 0;
    long long tmp;

    tmp = a;
    while (tmp > 0) {
        tmp /= 10;
        ta++;
    }

    tmp = b;
    while (tmp > 0) {
        tmp /= 10;
        tb++;
    }

    return (ta>=tb) ? ta : tb;
}

int main()
{
    long long N;
    int min = 11;

    scanf("%lld", &N);

    for (long long A = 1; A <= sqrt(N); A++) {
        long long B = N / A;
        if (B * A == N) {
            int p = fab(A, B);
            if (p < min)
                min = p;
        }

    }

    printf("%d", min);

    return 0;

}

Measured memory_bytes: 2108
#include <iostream>
#include <vector>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define FI first
#define SE second
#define PB push_back
#define MP make_pair

using namespace std;
typedef long long ll;

class UnionFind {
public:
  UnionFind(int n): par(n, -1) { }
  int root(int x) {
    if (par[x] < 0) return x;
    else return par[x] = root(par[x]);
  }
  void unite(int x, int y) {
    x = root(x), y = root(y);
    if (x == y) return;
    if (par[y] < par[x]) swap(x, y);
    par[x] += par[y];
    par[y] = x;
  }
  bool same(int x, int y) {
    return root(x) == root(y);
  }
  int size(int x) {
    return -par[root(x)];
  }

private:
  vector<int> par;
};

int main()
{
  ll N, M;
  cin >> N >> M;
  vector<pair<int, int>> edge;
  REP(i, M) {
    int A, B; cin >> A >> B;
    A--, B--;
    edge.PB(MP(A, B));
  }

  vector<ll> v(M);
  v[M - 1] = N * (N - 1) / 2;
  UnionFind uf(N);
  for (int i = M - 1; i > 0; i--) {
    int A = edge[i].FI, B = edge[i].SE;
    v[i - 1] = v[i];
    cerr<<"["<<uf.size(A)<<", "<<uf.size(B)<<"]"<<endl;
    if (!uf.same(A, B)) v[i - 1] -= (long long)uf.size(A) * uf.size(B);
    uf.unite(A, B);
  }
  REP(i, M) cout << v[i] << endl;
  return 0;
}

Measured memory_bytes: 3316
s = input()
even = {'0': 0, '1': 0}
odd = {'0': 0, '1': 0}
for i in range(len(s)):
    if i % 2 == 0:
        even[s[i]] += 1
    else:
        odd[s[i]] += 1
print(min(even['0'] + odd['1'], even['1'] + odd['0']))


Measured memory_bytes: 3188
n, m = map(int, input().split())
g = [[] for _ in range(n)]
for i in range(m):
    a, b = map(int, input().split())
    g[a - 1].append(b - 1)
    g[b - 1].append(a - 1)
s = [0, g[0][0]]
d = [1] * n
d[0], d[g[0][0]] = 0, 0
edges = [(0, g[0][0])]
inv = [0] * n
inv[0], inv[g[0][0]] = 1, 1
path = [[] for _ in range(n)]
path[0].append(g[0][0])
path[g[0][0]].append(0)
while s:
    p = s.pop()
    for node in g[p]:
        if d[node]:
            s.append(node)
            d[node] = 0
            path[p].append(node)
            path[node].append(p)
            inv[p] += 1
            inv[node] += 1
            break
d = [1] * n
for i in range(n):
    if inv[i] == 1:
        s = [i]
        d[i] = 0
        break
l = [i + 1]
while s:
    p = s.pop()
    for node in path[p]:
        if d[node]:
            s.append(node)
            d[node] = 0
            l.append(node + 1)
print(len(l))
print(' '.join(map(str, l)))


Measured memory_bytes: 45404
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    long a = Long.parseLong(sc.next());
    char[] b = sc.next().toCharArray();
    int c = 100*(b[0]-'0')+10*(b[2]-'0')+b[3]-'0';
    System.out.println(a*c/100);
  }
}

Measured memory_bytes: 35740
#include<stdio.h>
int main(void)
{
    int A,B;
   
    scanf("%d%d",&A,&B);
    if(A>B){
      if(A-1>B) printf("%d\n",2*A-1);
      else printf("%d\n",A+B);
    }
    else if(A<B){
      if(B-1>A) printf("%d\n",2*B-1);
      else printf("%d\n",A+B);
    }
    else printf("%d\n",A+B);
  
    return 0;
}

Measured memory_bytes: 1728
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll MOD = 1000000007;
const ll INF = 9999999999;
const int INFI=2147483647;
template<class T> inline bool chmin(T& a, T b){if (a>b){a = b; return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if (a<b){a = b; return true;}return false;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
  T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }


int n;
vector<int> color;

struct Edge {
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w) {}
};

void dfs(vector<vector<Edge>> &G, int v){
  for (auto ne : G[v]){
    int nv = ne.to;
    int nw = ne.weight;
    if (color[nv] != -1) continue;
    color[nv] = nw % 2 == 0 ? color[v] : 1 - color[v];
    dfs(G, nv);
  }
}

int main() {
  cin >>n;
  vector<vector<Edge>> G(n);
  rep(i, n-1){
    int a,b,c; cin >>a >>b >>c;
    a--; b--;
    G[a].push_back(Edge(b, c));
    G[b].push_back(Edge(a, c));
  }
  color.assign(n, -1);
  color[0] = 0;
  dfs(G, 0);

  rep(i, n) cout <<color.at(i) <<endl;
}

Measured memory_bytes: 8192
#include <bits/stdc++.h>
using namespace std;
int main() {
	int A, B, C, X;
	cin >> A >> B >> C >> X;
	int count = 0;
	for (int i = 0; i < A + 1; i++) {
		for (int j = 0; j < B + 1; j++) {
			for (int k = 0; k < C + 1; k++) {
				if (500 * i + 100 * j + 50 * k == X) count++;
			}
		}
	}
	cout << count << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
int a,b;
int main()
{
	scanf("%d%d",&a,&b);
	if(a<=0&&b>=0)
		puts("Zero");
	else if(a>0)
		puts("Positive");
	else
		((a-b+1)&1)?puts("Negative"):puts("Positive");
	return 0;
}

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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;A++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////
#define MOD (ll)(1e9+7)

ll N,x[101010];
ll i, j, k,ans;
int main(){
    scanf("%lld", &N);
    fornum(i,0,N){
        scanf("%lld", &x[i]);
    }
    //printf("%lld\n", MOD);
    k = 0;
    ans = 1;
    fornum(i,0,N){
        //printf("%lld:%lld\n",(i-k*2)*2, x[i]);
        if((i-k)*2<x[i])
            continue;
        ans = ans * (i+1-k) % MOD;
        k++;
        
    }
    //printf("%lld:%lld\n",k, i);
    fornum(k,k,N){
        ans = ans * (N - k) % MOD;
    }
    printf("%lld",ans);

    return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {

	static Scanner scanner;
	public static void main(String[] args) {
	    scanner = new Scanner(System.in);

	    int n=gi();
	    int[] A= new int[n];
	    int f=0;
	    for(int i=0; i<A.length;i++) {
    		A[i]=gi();
    	}
	    while(true) {
	    	boolean flg=true;
	    	for(int i=0; i<A.length;i++) {
	    		if(A[i]%2!=0) {
	    			flg=false;
	    			break;
	    		}else {
	    			A[i]=A[i]/2;
	    		}
	    	}
	    	if(!flg) {
	    		break;
	    	}
	    	f++;
	    }
	    System.out.print(f);
//	    if (n%f==0) {
//	    	System.out.print("Yes");
//	    }else {
//	    	System.out.print("No");
//	    }



	}

	public static long d(long n) {
		String a=String.valueOf(n);
		return (long)a.length();
	}

	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}

	// doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	}
}

Measured memory_bytes: 35632
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) x.begin(),x.end()
#define chmin(a,b) a=min(a,b)
#define chmax(a,b) a=max(a,b)
ll D;
ll c[26];
ll s[366][26];
ll t[366];

//スコア計算
ll score(ll days){
	ll ans=0;
	ll last[26];
	rep(i,26)last[i]=0;
	for(ll d=1;d<=days;d++){
		ans+=s[d][t[d]];
		last[t[d]]=d;
		rep(i,26){
			ans-=c[i]*(d-last[i]);
		}
	}
	return ans;
}

ll whole_score;
ll score_typ[26];
void recalc(ll i){
	ll ans=0;
	ll last=0;
	for(ll d=1;d<=D;d++){
		if(t[d]==i){
			ans+=s[d][i];
			last=d;
		}
		ans-=c[i]*(d-last);
	}
	whole_score-=score_typ[i];
	score_typ[i]=ans;
	whole_score+=score_typ[i];
}
void change(ll d,ll q){
	ll b=t[d];
	t[d]=q;
	recalc(b);
	recalc(q);
}
void init_score(){
	whole_score=0;
	rep(i,26){
		score_typ[i]=0;
		recalc(i);
	}
}

//貪欲法
void greedy(){
	for(ll d=1;d<=D;d++){
		ll ma=-1e17,pt=0;
		rep(i,26){
			t[d]=i;
			ll res=score(d);
			if(ma<res){
				ma=res;
				pt=i;
			}
		}
		t[d]=pt;
	}
}

//局所探索_改
void local_search(){
	rep(u,50000){
		ll d=rand()%D+1;
		ll max_score=whole_score;
		ll pt=-1;
		rep(i,26){//日付に対して、変更先26文字の中で最大のものを選ぶ
			change(d,i);
			ll aft_score=whole_score;
			if(aft_score>=max_score){
				max_score=aft_score;
				pt=i;
			}
		}
		change(d,pt);
	}
}


int main(){
	cin>>D;
	rep(i,26)cin>>c[i];
	for(ll d=1;d<=D;d++)rep(j,26)cin>>s[d][j];
	greedy();
	init_score();
	local_search();
	for(ll d=1;d<=D;d++){
		cout<<t[d]+1<<"\n";
	}
}


Measured memory_bytes: 3700
#include<cstdio>

using namespace std;

int main(void){
	int h1,h2,tai;
	int data,tyou=0,hisi=0;

	while((scanf("%d,%d,%d",&h1,&h2,&tai))!=EOF){
		if(h1==h2)	hisi++;
		data=h1*h1+h2*h2;
		if(data==tai*tai)	tyou++;
	}
	printf("%d\n%d\n",tyou,hisi);

	return 0;
}

Measured memory_bytes: 0
use std::collections::BinaryHeap;
use std::cmp;

fn main(){
    let mut sc = Scanner::new();
    let h = sc.next();
    let w = sc.next();
    let mut g = vec![vec![] ; h];
    for i in 0..h {
        g[i] = sc.next::<String>().chars().collect();
    }
    for i in 0..h {
        for j in 0..w {
            print!("{}", if i == 0 || (i != h-1 && j%2 == 0) { '#' } else { g[i][j] });
        }
        println!("");
    }
    println!("");
    for i in 0..h {
        for j in 0..w {
            print!("{}", if i == h-1 || (i != 0 && j%2 == 1) { '#' } else { g[i][j] });
        }
        println!("");
    }
}

// Scanner

#[allow(dead_code)]
struct Scanner {
    token_buffer : Vec<String>,
    index : usize,
}

#[allow(dead_code)]
impl Scanner {
    fn new() -> Scanner{
        Scanner { token_buffer: vec![], index: 0 }
    }

    fn wrapped<T>(& mut self) -> Result<T,&str> where T: std::str::FromStr {
        let s = try!(self.fetch_token());
        let t = try!(s.parse::<T>().map_err(|_| "Parse error"));
        Ok(t)
    }
    fn next<T>(& mut self) -> T where T: std::str::FromStr {
        self.wrapped::<T>().unwrap()
    }

    fn fetch_token(&mut self) -> Result<&String,&str> {
        while self.index >= self.token_buffer.len() {
            let mut st = String::new();
            while st.trim() == "" {
                match std::io::stdin().read_line(&mut st) {
                    Ok(l) if l > 0 => continue,
                    Ok(_)  => return Err("End of file"),
                    Err(_) => return Err("Failed to read line"),
                }
            }
            self.token_buffer = st.split_whitespace()
                .map(|x| x.to_string())
                .collect();
            self.index = 0;
        }

        self.index += 1;
        Ok(&self.token_buffer[self.index - 1])
    }
}


Measured memory_bytes: 2044
n,c,k=map(int,input().split())
t=[]
for i in range(n):
    t.append(int(input()))
t.sort()
cnt=1
s=0
for i in range(1,n):
    if i==s+c or  t[i]>t[s]+k:
        s=i
        cnt+=1
print(cnt)



Measured memory_bytes: 50648
/***
* When I wrote this
* only God & I understood
* what I was doing
* Now, God only knows
/***/
#include<iostream>
#include<cmath>
#include<cstring>
#include<string>
#include<algorithm>
#include <iomanip>
#include<map>
typedef long long ll;
const int mod = 1e9 + 7;
using namespace std;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
//fixed<< setprecision(2)
int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    ll n;
    while (cin >> n)
    {
        ll* p = new ll[n + 5];
        for (int i = 0; i < n; i++)cin >> p[i];
        ll a = 1000 % p[0], b = 1000 / p[0], c = p[0];
        for (int i = 1; i < n; i++)
        {
            if (p[i] > c)
            {
                a = a + b * p[i];

                b = a / p[i];
                a = a % p[i];
                c = p[i];
            }
            else if (p[i] < c)
            {
                a = a + b * c;
                b = a / p[i];
                a = a % p[i];
                c = p[i];
            }
        }
        cout << a + b * c << '\n';
    }
}

Measured memory_bytes: 3232
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define abdelrahman010 ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long long ll;
using namespace std;
const int N = 1e5 + 5;
int n , q , a[N] , f[N];
ll sum = 0;
int main() {
    abdelrahman010
    cin >> n;
    for(int i = 0;i < n;i++) {
        cin >> a[i];
        f[a[i]]++;
        sum += a[i];
    }
    cin >> q;
    while(q--) {
        int x , y;
        cin >> x >> y;
        sum -= 1ll * f[x] * x;
        sum += 1ll * f[x] * y;
        f[y] += f[x] , f[x] = 0;
        cout << sum << '\n';
    }
    return 0;
}

Measured memory_bytes: 4432
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  for(int roop = 0; roop < n; roop++){
    int m;
    cin >> m;
    int fence[m];
    for(int i = 0; i < m; i++){
      cin >> fence[i];
    }
    int a = 0, b = 0;
    for(int i = 0; i < m - 1; i++){
      a = max(a, fence[i + 1] - fence[i]);
      b = min(b, fence[i + 1] - fence[i]);
    }
    cout << a << " " << -b << endl;
  }
  return 0;
}

Measured memory_bytes: 1160
#!/usr/bin/env python

def main():
    N, M = map(int, input().split(" "))

    all_pass_time = (N - M) * 100 + M * 1900
    needed_try_cnt_for_all_pass = 2 ** M
    print(all_pass_time * needed_try_cnt_for_all_pass)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define gc getchar_unlocked()
#define pc(x) putchar_unlocked(x)
template<typename T> void scan(T &x){x = 0;bool _=0;T c=gc;_=c==45;c=_?gc:c;while(c<48||c>57)c=gc;for(;c<48||c>57;c=gc);for(;c>47&&c<58;c=gc)x=(x<<3)+(x<<1)+(c&15);x=_?-x:x;}
template<typename T> void printn(T n){bool _=0;_=n<0;n=_?-n:n;char snum[65];int i=0;do{snum[i++]=n%10+48;n/= 10;}while(n);--i;if (_)pc(45);while(i>=0)pc(snum[i--]);}
template<typename First, typename ... Ints> void scan(First &arg, Ints&... rest){scan(arg);scan(rest...);}
template<typename T> void print(T n){printn(n);pc(10);}
template<typename First, typename ... Ints> void print(First arg, Ints... rest){printn(arg);pc(32);print(rest...);}

using namespace std;
const int MM = 2e5+2;

int n, t[3], ans[MM];
vector<int> adj[MM], va, vb;

void dfs(int cur, int pre, int v){
    if(v)
        vb.push_back(cur);
    else
        va.push_back(cur);
    for(int u: adj[cur]){
        if(u != pre)
            dfs(u, cur, v^1);
    }
}
int cnt[3];

int main(){
    scan(n);
    for(int i = 0,a,b; i < n-1; i++){
        scan(a, b);
        adj[a].emplace_back(b);
        adj[b].emplace_back(a);
    }
    for(int i = 1; i <= n; i++)
        cnt[i%3]++;
    
    dfs(1, 0, 0);
    if(va.size() < vb.size())
        swap(va, vb);
    
    t[0] = 3, t[1] = 1, t[2] = 2;
    if(vb.size() < cnt[1]){
        //need to use va to fill both, vb is third
        for(int i: va){
            if(t[1] <= n){
                ans[i] = t[1];
                t[1] += 3;
            }
            else if(t[2] <= n){
                ans[i] = t[2];
                t[2] += 3;
            }
            else{
                ans[i] = t[0];
                t[0] += 3;
            }
        }
        for(int i: vb){
            ans[i] = t[0];
            t[0] += 3;
        }
    }
    else{
        for(int i: va){
            if(t[1] <= n){
                ans[i] = t[1];
                t[1] += 3;
            }
            else{
                ans[i] = t[0];
                t[0] += 3;
            }
        }
        for(int i: vb){
            if(t[2] <= n){
                ans[i] = t[2];
                t[2] += 3;
            }
            else{
                ans[i] = t[0];
                t[0] += 3;
            }
        }
    }
    assert(*max_element(t, t+3)-3 <= n);
    
    for(int i = 1; i <= n; i++)
        printf("%d ", ans[i]);
    
    return 0;
}
/*
10
1 2
2 3
3 4
2 5
1 6
6 7
6 8
8 9
8 10
 */

Measured memory_bytes: 21620
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
#define N 200010
char s1[N],s2[N];
int a[30],b[30];
int main()
{
    int i,j,k;
    scanf("%s%s",s1,s2);
    k=strlen(s1);
    for(i=0;i<k;i++)
    {
        j=s1[i]-'a';
        a[j]++;
    }
    k=strlen(s2);
    for(i=0;i<k;i++)
    {
        j=s2[i]-'a';
        b[j]++;
    }
    sort(a,a+30);
    sort(b,b+30);
    for(i=0;i<30;i++)
    if(a[i]!=b[i])
    {
        printf("No\n");
        return 0;
    }
    printf("Yes\n");
    return 0;
}

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

inline int toInt(string s) {
    int v;
    istringstream sin(s);
    sin >> v;
    return v;
}
template <class T>
inline string toString(T x) {
    ostringstream sout;
    sout << x;
    return sout.str();
}

#define reps(i, k, n) for (ll(i) = (k); (i) < (n); ++(i))
#define rep(i, n) reps(i, 0, n)
#define debug(x) cerr << x << " (L:" << __LINE__ << ")" << '\n';

#define pb push_back
#define mp make_pair
#define ALL(o) (o).begin(), (o).end()
#define sz(a) (int)((a).size())

#define ll long long
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vs = vector<string>;

const ll MAX = (ll)0x3f0000003f000000;
const int MOD = 1000000007;
const double EPS = 1e-9;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1},
          dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

void solve();
ll ans = 0;

void setup() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
}

int main() {
    setup();
    solve();
}

void solve() {
    string s;
    cin >> s;
    rep(i, 3) {
        if (s[i] == '1') ans++;
    }
    cout << ans;
}

Measured memory_bytes: 764
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstring>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#define MAX_N 50000
#define INF (long)1e9
const int MOD = 1e9 + 7;
const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, 1, -1};
using namespace std;
typedef long long ll;
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a, b, d;
	while(cin >> a >> b >> d, a | b | d)
	{
		int ans_x, ans_y;
		int sum1 = INF, sum2 = INF;
		for(int i = 0; i < MAX_N; i++)
		{
			int j = (a * i - d) / b;
			if(j < 0) continue;
			int num = abs(a * i - b * j);
			if(num == d)
			{
				if(i + j <= sum1 && a * i + b * j <= sum2)
				{
					sum1 = i + j;
					sum2 = a * i + b * j;
					ans_x = i; ans_y = j;
				}
			}
		}
		for(int j = 0; j < MAX_N; j++)
		{
			int i = (b * j - d) / a;
			if(i < 0) continue;
			int num = abs(b * j - a * i);
			if(num == d)
			{
				if(i + j <= sum1 && a * i + b * j <= sum2)
				{
					sum1 = i + j;
					sum2 = a * i + b * j;
					ans_x = i; ans_y = j;
				}
			}
		}
		for(int i = 0; i < MAX_N; i++)
		{
			int j = (d - a * i) / b;
			if(j < 0) continue;
			if(a * i + b * j == d)
			{
				if(i + j <= sum1 && a * i + b * j <= sum2)
				{
					sum1 = i + j;
					sum2 = a * i + b * j;
					ans_x = i; ans_y = j;
				}
			}
		}
		cout << ans_x << " " << ans_y << endl;
	}
	return 0;
}




Measured memory_bytes: 3104
#include <cmath>
#include <cstdio>
using namespace std;
int N, sum, o[1000010];
char a[1000010];
int main() {
    scanf("%d%s", &N, a + 1);
    for (int i = 1; i < N; ++i) a[i] = abs(a[i + 1] - a[i]);
    --N;
    if (N == 1) {
        printf("%d\n", (int)a[1]);
        return 0;
    }
    o[1] = 0;
    for (int i = 2; i <= N; ++i) {
        int mul = N - i + 1, div = i - 1;
        o[i] = o[i - 1];
        while (!(mul & 1)) {
            mul >>= 1;
            ++o[i];
        }
        while (!(div & 1)) {
            div >>= 1;
            --o[i];
        }
    }
    for (int i = 1; i <= N; ++i) o[i] = !o[i];
    for (int i = 1; i <= N; ++i) {
        sum += o[i] * a[i];
    }
    if (sum & 1) {
        puts("1");
        return 0;
    }
    sum = 0;
    for (int i = 1; i <= N; ++i) {
        if (a[i] == 1) {
            sum = 1;
            break;
        }
    }
    if (sum) {
        puts("0");
        return 0;
    }
    for (int i = 1; i <= N; ++i) sum += o[i] * (a[i] == 2);
    puts(sum & 1 ? "2" : "0");
    return 0;
}


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

int main() {
    string x;
    cin >> x;
    if (x[5] == '0' && (x[6] == '1' || x[6] == '2' || x[6] == '3' || x[6] == '4')){
        cout << "Heisei" << endl;
    } else cout << "TBD" << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;

const long double pi = 3.141592653589793;

#define debug(x) cout << #x << " = " << (x) << endl;
#define rep(i, n) for(int i = 0;i < n;i++)
#define pb push_back
#define mp make_pair
#define mod 1000000007

vector<int> g[1<<20];

int main() {
	ios::sync_with_stdio(false);
    //freopen("input.in","r",stdin);
 	//freopen("output.out","w",stdout);
	int n, m, x, y;

	cin>>n>>m;

	rep(i, m) {
		cin>>x>>y;
		g[x].pb(y);
		g[y].pb(x);
	}

	bool possible = false;

	for(auto &x: g[1]) {
		for(auto &y:g[x]) {
			if(y == n) {
				possible = true;break;
			}
		}
		if(possible) break;
	}

	if(possible) cout<<"POSSIBLE"<<endl;
	else cout<<"IMPOSSIBLE"<<endl;

	return 0;
}


Measured memory_bytes: 31856
import itertools
import sys

def hantei(s):
  hantei = s.isupper()
  
  if hantei:
    i = 0
    for s1, s2 in itertools.combinations(s, 2):
      if s1 == s2:
        i += 1
    hantei = 'Yes' if i == 2 else 'No'
  else:
    hantei = 'No'
    
  return hantei


if __name__ == '__main__':
  args = sys.stdin
  
  for arg in args:
    print(hantei(str(arg)))


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

void trace(int A[], int N){
  for(int i = 0; i < N; i++){
    if(i < N - 1) {
      cout << A[i] << " ";
    } else {
      cout << A[i] << endl;
    }
  }
}

// int insertionSort(vector<int> A, int N) {
void insertionSort(int A[], int N){
    for (int i = 1; i < N; i++) {
      // int v = A.at(i);
      int v = A[i];
      int j = i - 1;
      // while(j >= 0 && A.at(j) > v) {
      while(j >= 0 && A[j] > v) {
        // A.at(j+1) = A.at(j);
        A[j+1] = A[j];
        j--;
      }
      // A.at(j+1) = v; // 最後はj=-1となる
      A[j+1] = v;
      trace(A, N);
    }
}


int main() {
  int N;
  cin >> N;
  // vector<int> A(N);
  int A[N];
  // for (int i = 0; i < N; i++) cin >> A.at(i);
  for (int i = 0; i < N; i++) cin >> A[i];
  trace(A, N);
  insertionSort(A, N);

}



Measured memory_bytes: 3068
/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Main
{
     public static int minCost(int []h , int curr_ind , int n , int []dp , int k){
	        if(curr_ind > n-1  )
	        return 0;
	        
	        if(dp[curr_ind]!=-1) return dp[curr_ind];
	        
	        int a = Integer.MAX_VALUE;
	        for(int i = curr_ind + 1;i<=Math.min(n,curr_ind+k);i++){
	            
	         a  = Math.min(a ,    (Math.abs(h[curr_ind] - h[i]) + minCost(h , i , n ,dp , k))) ;
	        }
	        
	        
	       
	        
	        return dp[curr_ind] = a;
	        
	        
	    }
    
	public static void main (String[] args) throws java.lang.Exception
	{
	    
	   
	    
	    
		// your code goes here
		 Scanner sc = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		int n = sc.nextInt();
			int k = sc.nextInt();
		
		
		int h[] = new int[n+1];
		for(int i =1;i<=n;i++){
		    h[i] = sc.nextInt();
			}
			
			int dp[]=new int[n+1];
			for(int j =0;j<n+1;j++)
			dp[j] = -1;
			
			System.out.println(minCost(h , 1 , n , dp , k));
	}
}


Measured memory_bytes: 64512
#include<iostream>
using namespace std;
int main(){
  int N, a[10000];
  cin >> N;
  int ans = 0;
  for(int i = 0; i < 2*N; i++){
    cin >> a[i];
  }
  for(int i = 0; i < N; i++){
    ans += a[(2*i + 1)] - a[2*i] + 1;
  }
  cout << ans << endl;
}

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

int dp[101][4][4][4];

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

    dp[0][3][3][3] = 1;

    rep(i, N){
        rep(c1, 4){
            rep(c2, 4){
                rep(c3, 4){
                    if(dp[i][c1][c2][c3] == 0) continue;

                    rep(a, 4){
                        if(a == 2 && c1 == 1 && c2 == 0) continue;
                        if(a == 2 && c1 == 0 && c2 == 1) continue;
                        if(a == 1 && c1 == 2 && c2 == 0) continue;
                        if(a == 2 && c1 == 1 && c3 == 0) continue;
                        if(a == 2 && c2 == 1 && c3 == 0) continue;

                        dp[i+1][a][c1][c2] += dp[i][c1][c2][c3];
                        dp[i+1][a][c1][c2] %= MOD;
                    }
                }
            }
        }
    }
    int ans = 0;
    rep(c1, 4){
        rep(c2, 4){
            rep(c3, 4){
                ans += dp[N][c1][c2][c3];
                ans %= MOD;
            }
        }
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
#include<sstream>
#include<complex>
#include<functional>
#include<vector>
#include<map>
#include<queue>
#include<deque>
#include<stack>
#include<set>

using namespace std;
#define endl '\n'

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;

template<typename T = long long>
T gcd(T a, T b) { return b ? gcd(b, a%b) : a; }

// value
int N;
ll A[100010];
ll B[100010];

void solve() {

	cin >> N;
	for (int i = 0; i <= N; i++) {
		cin >> A[i];
	}
	for (int i = 0; i < N; i++) {
		cin >> B[i];
	}
	ll ans = 0;
	for (int i = 0; i < N; i++) {
		ll tmp = max(0LL, B[i] - A[i]);
		ans += B[i] - tmp; B[i] = tmp;
		tmp = max(0LL, B[i] - A[i + 1]);
		ans += B[i] - tmp; A[i + 1] -= B[i] - tmp;
	}

	cout << ans << endl;

	return;

}

int main() {

	cin.tie(0);
	ios::sync_with_stdio(false);

	solve();

	return 0;

}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v).begin(), (v).end()
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define DEBUG
#define int long long
#define INF 1e18
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<"\n";}
typedef long long ll;

using Edge = pair<long long, long long>;
using Graph = vector<vector<Edge>>;

Graph G;
int N, d[200010];

// <最短距離, 頂点の番号>
using P = pair<int, int>;

void dijkstra(int s)
{
    priority_queue<P, vector<P>, greater<P>> que;
    fill(d, d + N, INF);
    d[s] = 0;
    que.push(P(0, s));

    while (!que.empty())
    {
        P p = que.top();
        que.pop();
        int v = p.second;
        if (d[v] < p.first)
            continue;

        for (int i = 0; i < G[v].size(); ++i)
        {
            Edge e = G[v][i];
            if (d[e.first] > d[v] + e.second)
            {
                d[e.first] = d[v] + e.second;
                que.push(P(d[e.first], e.first));
            }
        }
    }
}


signed main()
{
    int x,y;
    cin>>N>>x>>y;
    x--,y--;
    G.assign(N,vector<Edge>());
    vector<int>v(N,0);
    for (int i = 0; i < N-1; i++)
    {
        G[i].push_back(Edge(i+1,1));
        G[i+1].push_back(Edge(i,1));
    }
    G[x].push_back(Edge(y,1));
    G[y].push_back(Edge(x,1));
    for (int i = 0; i < N-1; i++)
    {
        dijkstra(i);
        int cnt=0;
       
        for (int j = i; j < N; j++)
        {
            v[d[j]]++;
        }
               
    }
    for (int i = 1; i <= N-1; i++)
    {
        cout<<v[i]<<endl;
    }
    
    
    return 0;
}

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

int main() {
	
	string s; int n=0;
	cin>>s;
	for(int i=0;i<s.size()/2;i++) {
		if(s[i]!=s[(s.size())-1-i]) {
			n++;
		}
	}
	cout<<n;
	return 0;
}

Measured memory_bytes: 256
/**
 *      ABC 109 C
 *      author  : kyomukyomupurin
 *      created : 2018-09-08 21:10:40
**/

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

int gcd(int x, int y){
	if (x % y ==0){
		return y;
    }
	else {
		return gcd(y ,x % y);
    }
}


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int N, X; cin >> N >> X;
    int x[N] = {};
    for (int i = 0; i < N; ++i) {
        cin >> x[i];
    }

    int diff[N] = {};
    for (int i = 0; i < N; ++i) {
        diff[i] = abs(x[i] - X);
    }

    int answer = diff[0];
    for (int i = 1; i < N; ++i) {
        answer = gcd(answer, diff[i]);
    }

    cout << answer << endl;

    return 0;
}

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

int main()
{
    int h, w;

    while(1) {
        cin >> h >> w;
    
        if((h==0)&&(w==0)) break;

        for(int i = 0; i < h; i++) {
            for(int j = 0; j < w; j++) {
                cout << '#';
            }
            cout << endl;
        }
        cout << endl;
    }
    
    return 0;
    
}


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

using namespace std;

#define ll long long
#define fix cout << fixed; cout << setprecision(10)





void solve() {

	int n, k;
	cin >> n >> k;
	if(n * 500 >= k) {
		cout << "Yes";
	}
	else {
		cout << "No";
	}




	
}

int main() {

	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	
	solve();

	return 0;
}

Measured memory_bytes: 3584
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using System.Runtime.CompilerServices;
using static MyUtil;

class MyUtil
{
    public static double[] ReadDoubleArray()
    {
        return ReadLine().Split().Select(x => double.Parse(x)).ToArray();
    }
}

class Program
{
    public static void Main()
    {
        int n = int.Parse(ReadLine());
        double[] p = ReadDoubleArray();

        double[,] dp = new double[n+1,n+1];
        dp[0,0] = 1.0;

        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j < n; j++)
            {
                dp[i+1, j] += dp[i, j] * (1.0 - p[i]);
                dp[i+1, j+1] += dp[i, j] * p[i];
            }
        }

        double ans = 0.0;
        for (int i = n/2 + 1; i <= n; i++)
            ans += dp[n, i];

        WriteLine(ans);
    }
}

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

int main() {

  int N;
  cin >> N ;
  
  int ans;
  ans = 0;
  
  for (int i = 0; i < N; i++) {
    int li , ri;
      cin >> li >> ri;
    
    
    ans += ri - li;
  }
  
  ans += N; 
  cout << ans << endl;
}


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

int main(){
  int A, B, C;
  cin >> A >> B >> C;
  if((A==B && B!=C) || (B==C && C!=A) || (C==A && A!=B)){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll N;
  cin >> N;
  vector<int> a(N);
  REP(i, N) cin >> a[i];
  ll wa = accumulate(a.begin(), a.end(), 0);
  ll k1 = wa / N;
  ll k2 = wa / N + 1;
  ll ans1 = 0;
  ll ans2 = 0;
  for(ll i = 0; i < N; i++) {
    ans1 += (a[i] - k1) * (a[i] - k1);
  }
  for(ll i = 0; i < N; i++) {
    ans2 += (a[i] - k2) * (a[i] - k2);
  }

  ll ans = min(ans1, ans2);
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
    long long int h,w,ans=0;
    cin>>h>>w; //h竖着，w横着
    long long int diyihang,dierhang;
    if(w==1||h==1)
    {ans=1;
        cout<<ans<<endl;
        return 0;
    }
    if(w%2==1)
        diyihang=(w/2)+1;
    else
        diyihang=w/2;
    if(w%2==1)
        dierhang=w/2;
    else
        dierhang=w/2;
        
        for(long long int i = 1;i<=h;i++)
        {
            if(i%2==1)
                ans+=diyihang;
            else
                ans+=dierhang;
            
        }
    cout<<ans<<endl;
    
    return 0;
}


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

using namespace std;

#define FOR(i, j, k) for(int i = j; i < k; ++i)
#define rep(i, j) FOR(i, 0, j)
#define repr(i, j) for(int i = j; i >= 0; -i)
#define INF (1 << 30)
#define MOD 1000000007

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

int N, M, K;
int a, b, Cost, Time;
int tTime[101][101];
int tCost[101][101];

int main() {
	while(scanf("%d %d", &N, &M), N||M) {
		memset(tTime, 0x3, sizeof(tTime));
		memset(tCost, 0x3, sizeof(tCost));
		rep(i, N) {
			scanf("%d %d %d %d", &a, &b, &Cost, &Time);
			tTime[a][b] = tTime[b][a] = Time;
			tCost[a][b] = tCost[b][a] = Cost;
		}
		FOR(i, 1, M + 1) FOR(j, 1, M + 1) FOR(k, 1, M + 1) {
			tTime[j][k] = min(tTime[j][k], tTime[j][i] + tTime[i][k]);
			tCost[j][k] = min(tCost[j][k], tCost[j][i] + tCost[i][k]);
		}
		scanf("%d", &K);
		rep(i, K) {
			int p, q, r;
			scanf("%d %d %d", &p, &q, &r);
			printf("%d\n", (r) ? tTime[p][q] : tCost[p][q]);
		}
	}
	return 0;
}

Measured memory_bytes: 3176
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

vector<pair<int64_t,int64_t>>prime_factorize(int64_t x){
  vector<pair<int64_t,int64_t>>p;
  for(int64_t i=2;i*i<=x;i++){
    int cnt=0;
    if(x%i==0){
    while(x%i==0){cnt++;x/=i;}
    p.push_back(make_pair(i,cnt));
    }
  }
  if(x!=1){p.push_back(make_pair(x,1));}
  return p; 
}

int main() {
  int N,M;
  cin>>N>>M;
  int a=M/N;
  for(int i=a;i>=1;i--){
    if(M%i==0){cout<<i<<endl;return 0;}
  }
  
  return 0;
}

Measured memory_bytes: 3608
#include <stdio.h>
int main(){
  char s[4];
  scanf("%s",s);
  int j=0;
  for(int i=0;i<3;i++){
    if(s[i]=='7'){  //'7'としないといけない。文字列と数字の見分けが大事
      j=1;
      break;
    }
  }
  if (j==0){
    puts("No");
  }else{
    puts("Yes");
  }
  
  return 0;
}

Measured memory_bytes: 1644
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define inf (1ll<<60)
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl

using namespace std;

const int mod=1e9+7;

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

class DisjointSet{
    public:
    vi rank, p;
    
    DisjointSet(){}
    DisjointSet(int size){
        rank.resize(size,0);
        p.resize(size,0);
        rep(i,size)makeSet(i);
    }
    
    void makeSet(int x){
        p[x]=x;
        rank[x]=0;
    }
    
    bool same(int x,int y){
        return findSet(x)==findSet(y);
    }
    
    void unite(int x,int y){
        link(findSet(x),findSet(y));
    }
    
    void link(int x,int y){
        if(rank[x]>rank[y]){
            p[y]=x;
        }
        else{
            p[x]=y;
            if(rank[x]==rank[y]){
                rank[y]++;
            }
        }
    }
    
    int findSet(int x){
        if(x!=p[x]){
            p[x]=findSet(p[x]);
        }
        return p[x];
    }
};

void run(){
    int n,m,x,y;
    cin>>n>>m>>x>>y;
    vi a(n),b(m);
    rep(i,n)cin>>a[i];
    rep(i,m)cin>>b[i];
    bool f;
    REP(i,x+1,y){
        f=true;
        rep(j,n){
            if(a[j]>=i)f=false;
        }
        rep(j,m){
            if(b[j]<i)f=false;
        }
        if(f){
            cout<<"No War"<<endl;
            return;
        }
        
    }
    cout<<"War"<<endl;
}

Measured memory_bytes: 256
#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 main(){
  int n;
  cin >> n;
  vector<ll> l(n);
  rep(i, n) cin >> l[i];
  int cnt = 0;
  rep(i, n){
    for(int j=i+1; j<n; j++){
      for(int k=j+1; k<n; k++){
        if (l[i] == l[j] || l[j] == l[k] || l[i] == l[k]) continue;
        if (l[i] + l[j] <= l[k] || l[j] + l[k] <= l[i] || l[i] + l[k] <= l[j]) continue;
        cnt += 1;
      }
    }
  }
  cout << cnt << endl;
  return 0;
}


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

using namespace std;

template <class T> inline bool chmin(T &a, T b) { /* {{{ */
  if (a > b) {
    a = b;
    return true;
  }
  return false;
} /* }}} */

int main() {
  int N;
  cin >> N;
  vector<int> V;
  V.push_back(1);
  {
    int i = 6;
    while (i <= N) {
      V.push_back(i);
      i *= 6;
    }
  }
  {
    int i = 9;
    while (i <= N) {
      V.push_back(i);
      i *= 9;
    }
  }
  const int inf = 1e9;
  vector<int> dp(N + 10, inf);
  dp[0] = 0;
  for (auto v : V) {
    for (int i = 0; i <= N; i++) {
      if (dp[i] == inf) continue;
      if (i + v <= N) chmin(dp[i + v], dp[i] + 1);
    }
  }
  cout << dp[N] << endl;

  return 0;
}
/* vim:set fdm=marker: */


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

using namespace std;

const int N = 256;
const int MOD = 1e9 + 7;

int n, k, a[N], f[N][N][N], fac[N];

int main() {
  fac[0] = 1;
  for (int i = 1; i < N; ++i) {
    fac[i] = (long long) i * fac[i - 1] % MOD;
  }
  cin >> n >> k;
  for (int i = 1; i <= n; ++i) {
    scanf("%d", a + i);
  }
  f[0][0][0] = 1;
  for (int i = 1; i <= n; ++i) {
    for (int j = 0; j <= i; ++j) {
      for (int x = 0; x < N; ++x) {
        f[i][j][x] = f[i - 1][j][x];
        if (j) f[i][j][x] += f[i - 1][j - 1][x ^ a[i]];
        if (f[i][j][x] >= MOD) f[i][j][x] -= MOD;
      }
    }
  }
  int ans = 0;
  for (int i = 1; i <= n; ++i) {
    int cur = (long long) fac[i] * f[n][i][k] % MOD;
    ans += cur; if (ans >= MOD) ans -= MOD; 
  }
  cout << ans << '\n';
  return 0;
}



Measured memory_bytes: 9132
import numpy as np

n, m = map(int, input().split())

lr_mat = np.zeros((m, 2))

for i in range(m):
    lr_mat[i, :] = list(map(int, input().split()))

left_max = max(lr_mat[:, 0])
right_min = min(lr_mat[:, 1])

cnt = 0
for i in range(1, n+1):
    if(left_max <= i) and (i <= right_min):
        cnt += 1

print(cnt)


Measured memory_bytes: 21388
PROGRAM-ID.                      ABC_107_B.
DATA                             DIVISION.
WORKING-STORAGE                  SECTION.
    01 INP     PIC X(7).
    01 INP2    PIC X(100).

    01 H       PIC 9(3).
    01 W       PIC 9(3).

    01 i       PIC 9(3) BINARY.
    01 j       PIC 9(3) BINARY.

    01 a1.
        03 a PIC X(100) OCCURS 100 INDEXED AX.

    01 cntH1.
        03 cntH PIC 9(1) OCCURS 100 INDEXED HX VALUE ZERO.

    01 cntW1.
        03 cntW PIC 9(1) OCCURS 100 INDEXED WX VALUE ZERO.

    01 cnt     PIC 9(3) VALUE ZERO.

    01 c       PIC 9(3) VALUE ZERO.

    01 flgH    PIC 9(1).
    01 flgW    PIC 9(1).

    01 st      PIC X(100).

PROCEDURE                        DIVISION.
    ACCEPT INP.

    UNSTRING INP
    DELIMITED BY SPACE
    INTO H W.

    PERFORM VARYING i FROM 1 BY 1 UNTIL H < i
        SET AX TO i
        ACCEPT a(AX)
    END-PERFORM

    MOVE 1 TO flgH

    PERFORM VARYING i FROM 1 BY 1 UNTIL H < i
        MOVE 1 TO flgH
        PERFORM VARYING j FROM 1 BY 1 UNTIL W < j
            SET AX TO i
            IF a(AX)(j:1) = '#'
                MOVE ZERO TO flgH
                EXIT PERFORM
            END-IF
        END-PERFORM
        IF 1 = flgH
            SET HX TO i
            MOVE 1 TO cntH(HX)
        END-IF
    END-PERFORM.

    PERFORM VARYING i FROM 1 BY 1 UNTIL W < i
        MOVE 1 TO flgW
        PERFORM VARYING j FROM 1 BY 1 UNTIL H < j
            SET AX TO j
            IF a(AX)(i:1) = '#'
                MOVE ZERO TO flgW
                EXIT PERFORM
            END-IF
        END-PERFORM
        IF 1 = flgW
            SET WX TO i
            MOVE 1 TO cntW(WX)
            ADD 1 TO cnt
        END-IF
    END-PERFORM.

    PERFORM VARYING i FROM 1 BY 1 UNTIL H < i
        SET HX TO i
        SET AX TO i
        IF ZERO = cntH(HX)

            MOVE ZERO TO c
            PERFORM VARYING j FROM 1 BY 1 UNTIL W < j
                SET WX TO j
                IF ZERO = cntW(WX)
                    MOVE a(AX)(j:1) TO st(j - c:1)
                ELSE
                    ADD 1 TO c
                END-IF
            END-PERFORM

            DISPLAY st(1:FUNCTION STORED-CHAR-LENGTH(st))

        END-IF

    END-PERFORM.

    STOP RUN.


Measured memory_bytes: 636
#include<bits/stdc++.h>
using namespace std ; 
# define pb push_back
# define ll long long 
# define mp make_pair
# define endl "\n" 
#define pii pair<int,int> 
# define vi vector<int>
# define pll pair<ll,ll> 
# define vl vector<long>

int main() {
	ios_base::sync_with_stdio(false);
    cin.tie(NULL) ; 
    ll h , w ; 
    cin >> h >> w ; 
    if(h==1 || w==1) {
    	cout << 1   ; 
    } else {
    	cout << (h*w+1)/2  ;
    }
    return 0; 
}







Measured memory_bytes: 3456