akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
const int maxn=100+5;
char a[maxn][maxn];
int n,m;
int cnt[27];
int g1=0,g2=0,g4=0;
int h1=0,h2=0,h4=0;
int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++) scanf("%s",a[i]+1);
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            cnt[a[i][j]-'a']++;
        }
    }
    for(int i=0;i<26;i++){
        if(cnt[i]&1) g1++;
        else if(cnt[i]%4==0) g4++;
        else g2++;
    }
    //printf("entr:\n");
    if(n%2==0 && m%2==1) swap(n,m);
    if(n&1 && m&1){
        h1=1;h2=n/2+m/2;
    }else{
        if(n&1){
            h1=0,h2=m/2;
        }else{
            h1=0;h2=0;
        }
    }
    if(g1>h1 || g2>h2) printf("No\n");
    else printf("Yes\n");
    return 0;
}


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

using namespace std;
//vector<long long> factors;
#define ll long long

#define pii pair<int,int>
#define pll pair<ll,ll>
#define _ <<'\n'
#define __ << ' '
#define all(x) (x).begin(), (x).end()
#define gcd __gcd
int IT_MAX = 1 << 17;
int MOD = 1000'000'007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x0f3f3f3f3f3f3f3f;
const double PI = acos(-1);
const double ERR = 1e-10;
#define szz(x) (int)(x).size()
#define IOS ios_base::sync_with_stdio(false); cout.tie(0);cin.tie(0);
#define flush fflush(stdout)

ll mod(ll a, ll m) { return (a + (abs(a) / m) * m + m) % m; }

//****************************don't use int!!!!!!!****************************//
//***************************code starts here!!!!!****************************//




int main() {
    IOS

    ll n;
    cin >> n;
    vector<pll > xy(n);
    for (int i = 0; i < n; ++i) {
        cin >> xy[i].first >> xy[i].second;
    }

    vector<vector<pll>> pq(n + 5, vector<pll >(n + 5));
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            pq[i][j].first = xy[i].first - xy[j].first;
            pq[i][j].second = xy[i].second - xy[j].second;
        }
    }

    map<pll, set<ll>> mp;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            if (i != j)
                mp[pq[i][j]].insert(i);
        }
    }

    ll mx = 0;
    for (auto i : mp) {
        if (i.second.size() > mx) {
            mx = i.second.size();
        }
    }

    if (mx == n) {
        cout << 1;
        return 0;
    } else {
        cout << n - mx;
        return 0;
    }

    return 0;
}

Measured memory_bytes: 640
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);    //scanner
        String s = sc.next();
        if(s.charAt(2)==s.charAt(3) && s.charAt(4)==s.charAt(5)){
            System.out.println("Yes");
        }
        else{
            System.out.println("No");
        }
    }
}


Measured memory_bytes: 35636
#include <iostream>
#include <string>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <utility>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
using namespace std;
#define INF 2147483647
#define LINF 9223372036854775807
#define MOD 1000000007
//#define int long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define repb(i, n) for (int i = n - 1; i >= 0; i--)
#define MODE 1
#ifdef MODE
#define DEB(X) cout << #X << ": " << X << " ";
#define ARDEB(i, X) cout << #X << "[" << i << "]: " << X[i] << " ";
#define END cout << endl;
#else
#define DEB(X) \
    {          \
    }
#define ARDEB(i, X) \
    {               \
    }
#define END \
    {       \
    }
#endif
typedef pair<int, int> P;
typedef long long ll;

signed main()
{
    int a,b;
    cin>>a>>b;
    if(a>=13)cout<<b<<endl;
    else if(6<=a && a<=12)cout<<b/2<<endl;
    else if(5>=a)cout<<0<<endl;

}


Measured memory_bytes: 256
N, M = map(int, input().split())
graph = [[] for i in range(N+1)]
for i in range(M):
  a, b = map(int, input().split())
  graph[a].append(b)
  graph[b].append(a)

is_visited = [False] * (N+1)
is_visited[1] = True
ans = [1]
def add_node(start):
  global is_visited
  global ans
  now = start
  go_next = True
  while go_next:
    go_next = False
    nodes = graph[now]
    for node in nodes:
      if not is_visited[node]:
        ans.append(node)
        is_visited[node] = True
        now = node
        go_next = True
        break

add_node(1)
ans = ans[::-1]
add_node(1)

print(len(ans))
print(*ans)

Measured memory_bytes: 25116
// -*- coding:utf-8-unix -*-

#[macro_use]
extern crate lazy_static;

// use proconio::derive_readable;
use proconio::fastout;
use proconio::input;
// use std::convert::TryInto;
use libm::*;
use std::cmp::*;
use std::collections::{BinaryHeap, HashSet};
use std::io::*;
use std::str::FromStr;
use superslice::*;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

//abc175-B
// #[fastout]
fn main() {
    input![n: usize, l: [u64; n]];
    // let set: HashSet<u64> = v.into_iter().collect();
    // let l: Vec<u64> = set.into_iter().collect();
    let size = l.len();

    let mut ans = 0;
    // eprintln!("{:?}", l);

    // let mut set = HashSet::new();

    for i in 0..size {
        let li = l[i];
        for j in (i + 1)..size {
            if i == j {
                continue;
            }
            let lj = l[j];

            for k in (j + 1)..size {
                if k == j || k == i {
                    continue;
                }
                let lk = l[k];

                // eprintln!("sum: {}, {}, {}", li + lj, lj + lk, lk + li);
                if li + lj > lk && lj + lk > li && lk + li > lj {
                    if li != lj && lj != lk && lk != li {
                        // eprintln!("{},{},{}", li, lj, lk);
                        // eprintln!("{},{},{}", i + 1, j + 1, k + 1);
                        ans += 1;
                        // let mut sorted = [li, lj, lk];
                        // sorted.sort();
                        // set.insert((sorted[0], sorted[1], sorted[2]));
                    }
                }
            }
        }
    }

    // println!("{:?}", set);
    // println!("{}", set.len());
    println!("{}", ans);
}

fn go(mid: usize, d: usize, use_num: usize, num753_cand: &mut Vec<usize>, n: usize) {}

// use lazy_static::lazy_static;
// use std::sync::Mutex;

// lazy_static! {
//     static ref VALUES: Mutex<Vec<i32>> = Mutex::default();
// }

// let mut values = VALUES.lock().unwrap();
// values.extend_from_slice(&[1, 2, 3, 4]);
// assert_eq!(&*values, &[1, 2, 3, 4]);


Measured memory_bytes: 2180
package main

import (
	"fmt"
	"math"
)

func abs(a float64) float64 {
	if a >= 0 {
		return a
	}
	return -a
}

func min(a, b float64) float64 {
	if a >= b {
		return b
	}
	return a
}

func main() {
	var n, ans, sum int
	var avg, m float64
	fmt.Scan(&n)
	a := make([]int, n)
	for i := range a {
		fmt.Scan(&a[i])
		sum += a[i]
	}
	avg = float64(sum) / float64(n)
	var d float64
	m = math.MaxFloat64
	for i := 0; i < n; i++ {
		d = abs(avg - float64(a[i]))
		if m > d {
			m = d
			ans = i
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512
import sys
l = sys.stdin.readline().strip()
x = int(l)
cands = []
for i in range(-121, 121):
    cands.append(i**5)
for i, one in enumerate(cands):
    for j, two in enumerate(cands):
        if one - two == x:
            print(i-121,j-121)
            sys.exit()


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

int binSearch(int,int[],int);

int main(int argc, char** argv) {
    int size1;
    scanf("%d\n", &size1);
    int array1[size1];
    for(int i = 0; i < size1; i++)
        scanf("%d", &array1[i]);
    
    int size2;
    scanf("%d\n", &size2);
    int array2[size2];
    for(int i = 0; i < size2; i++)
        scanf("%d", &array2[i]);
    
    int searched[size1];
    for(int i = 0; i < size1; i++)
        searched[i] = 0;
    int count = 0;
    int temp;
    for(int i = 0; i < size2; i++){
        temp = binSearch(size1,array1,array2[i]);
        if(temp >= 0 && temp < size1)
            searched[temp]++;
    }
    
    for(int i = 0; i < size1; i++)
        if(searched[i])
            count++;
    
    printf("%d\n", count);
    return (EXIT_SUCCESS);
}

int binSearch(int size, int array[size], int searchVal){
    int left = 0;
    int right = size;
    int mid;
    while(left < right){
        mid = (left + right)/2;
        if(array[mid] == searchVal)
            return mid;
        if(searchVal > array[mid])
            left = mid + 1;
        else if(searchVal < array[mid])
            right = mid;
    }
    return -1;
}



Measured memory_bytes: 2704
/**
 *  Worg
 */
#include <vector>
#include <iostream>
#include <algorithm>
#include <iomanip>

const int MAX_N = 300 + 1;
int f[4];
double steps[MAX_N][MAX_N][MAX_N], p[MAX_N][MAX_N][MAX_N];
//  p[{state}] = the probability of making it to this state
//  steps[{state}] = expected number of steps to get to this state

int main() {
	//  dp[i][j][k] = expected number of operations to remain with i 1-pieces, j 2-pieces and k 3-pieces
	//  Cand avem n farfurii, din care k nu sunt goale, care e expected-ul de pasi pana cand vom nimeri o farfurie care nu e goala?
	//  p_waste * (1 + S) = S <=> p_waste + S * (p_waste - 1) = 0 <=> p_waste = S * (1 - p_waste) <=> S = p_waste / (1 - p_waste)

	int n; std::cin >> n;
	for (int i = 0; i < n; i++) {
		int x; std::cin >> x;
		f[x] += 1;
	}

	p[f[1]][f[2]][f[3]] = 1;
	for (int c = n; c >= 0; c--) {
		for (int b = n; b >= 0; b--) {
			for (int a = n; a >= 0; a--) {
				if (a + b + c == 0 || a + b + c > n) continue;

				double p_waste = (double)(n - (a + b + c)) / n;
				double step_waste = 1 + p_waste / (1 - p_waste);
				steps[a][b][c] += step_waste * p[a][b][c];

				//  remove 1
				if (a > 0) {
					double p_here = (double) a / (a + b + c);
					p[a - 1][b][c] += p[a][b][c] * p_here;
					steps[a - 1][b][c] += steps[a][b][c] * p_here;
				}

				// remove 2
				if (b > 0) {
					double p_here = (double) b / (a + b + c);
					p[a + 1][b - 1][c] += p[a][b][c] * p_here;
					steps[a + 1][b - 1][c] += steps[a][b][c] * p_here;
				}

				//  remove 3
				if (c > 0) {
					double p_here = (double) c / (a + b + c);
					p[a][b + 1][c - 1] += p[a][b][c] * p_here;
					steps[a][b + 1][c - 1] += steps[a][b][c] * p_here;
				}
			}
		}
	}

	std::cout << std::fixed << std::setprecision(10) << steps[0][0][0] << "\n";
	return 0;
}


Measured memory_bytes: 426240
import java.util.*;

public class Main {

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

        int n;
        n = in.nextInt();

        SortedMap<String,Integer> poll = new TreeMap<String, Integer>();

        int maxvote = 0;
        for(long i=0;i<n;i++)
        {
            String candidate = in.next();
            if(poll.containsKey(candidate))
            {
                poll.put(candidate,poll.get(candidate)+1);
            }
            else{
                poll.put(candidate,1);
            }
            maxvote = Math.max(maxvote,poll.get(candidate));
        }

        for(String candidate:poll.keySet())
        {
            if(poll.get(candidate)==maxvote)
                System.out.println(candidate);
        }

    }

}


Measured memory_bytes: 76008
/*
  	Coded by Apojacsleam
*/
#include<bits/stdc++.h>
using namespace std; 
int n;
double T,a,f[1001],cha=1000000000000000000,sum;
int ans;
int main()
{
	cin>>n>>T>>a;
	for(int i=1;i<=n;i++) cin>>f[i];
	for(int i=1;i<=n;i++)
	{
		sum=T-f[i]*0.006;
		if(abs(sum-a)<cha) cha=abs(sum-a),ans=i;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#define rep(i,n) for(int i=0; i<(n); ++i)
using namespace std;
typedef long long ll;

vector<int> clist; // 頂点ごとのカウンターリスト
vector<vector<int> > graph;
vector<int> ans;
vector<bool> seen;
int n, q;

void dfs(int X, int v){

  seen[v] = true;
  ans[v] = X + clist[v];

  rep(i,graph[v].size()){
    if(seen[graph[v][i]]) continue;
    int son = graph[v][i];
    ans[v] = X + clist[v];
    dfs(X + clist[v], son);
  }    

return;
}

int main(){

  cin >> n >> q;

  //generating graph
  graph = vector<vector<int> >(n);
  rep(i,n-1){
    int a, b;
    cin >> a >> b;
    --a; --b;
    graph[a].push_back(b);
    graph[b].push_back(a);
  }

  // generating counter list
  clist = vector<int>(n,0);
  rep(i,q){
    int p, x;
    cin >> p >> x;
    --p;
    clist[p] += x;
  }

  ans = vector<int>(n);
  seen = vector<bool>(n,false);
  dfs(0,0);

  rep(i,n) cout << ans[i] << " ";
  cout << endl;
  return 0;
}


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

#define ll long long 
#define pii pair<int, int>
#define ull unsigned ll
#define f first
#define s second
#define FOR(i,a,b) for (int i=(a); i<(b); i++)
#define REP(i,n) for (int i=0; i<(n); i++)
#define RREP(i,n) for (int i=(n-1); i>=0; i--)
#define ALL(x) x.begin(),x.end()
#define SZ(x) x.size()
#define MNTO(a,b) a = min(a,(__typeof__(a))(b))
#define MXTO(a,b) a = max(a,(__typeof__(a))(b))
#define pb push_back
#define debug(x) cerr<<#x<<" is "<<x<<endl

using namespace std;

const int maxn = 2e3+5;
const int intinf = 1<<29;
const ll inf = 1ll<<60;


void GG(){cout<<"No\n"; exit(0);}


vector<int> tree[maxn];
int nx = 0;
int k;
bool seen[maxn];

int dfs(int at, int left){
	if (left<0) return 0;
	seen[at]=1;
	int re = 1;
	for (int &v: tree[at]){
		if (!seen[v]) re+=dfs(v,left-1);
	}
	seen[at]=0;
	return re;
}

int solve(int x){
	int ex = 0, aa = 1;
	seen[x]=1;
	for (int &v: tree[x]){
		int a = dfs(v, k/2-1), b = dfs(v,k/2);
		aa += a; MXTO(ex, b-a);
		//debug(v); debug(a); debug(b);
	}
	seen[x]=0;
	return aa + ex;
}

int main(){
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
   	int n; cin>>n>>k;
   	REP(i,n-1) {
   		int a, b; cin>>a>>b; tree[a-1].pb(b-1); tree[b-1].pb(a-1);
   	}
   	int re = intinf;
   	REP(i,n){
   		fill(seen, seen+n, 0); 
   		//dfs(i,0);
   		if (k&1) nx = solve(i);
   		else{
   			nx = dfs(i,k/2); 
   		}
   		MNTO(re, n-nx);
   	}
   	cout<<re<<endl;
}

Measured memory_bytes: 384
/*Whose woods these are I think I know.
His house is in the village though;
He will not see me stopping here
To watch his woods fill up with snow.

My little horse must think it queer
To stop without a farmhouse near
Between the woods and frozen lake
The darkest evening of the year.

He gives his harness bells a shake
To ask if there is some mistake.
The only other sound’s the sweep
Of easy wind and downy flake.

The woods are lovely, dark and deep,
But I have promises to keep,
And miles to go before I sleep,
And miles to go before I sleep.*/

#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define pb push_back
#define fi first
#define se second
#define MOD 1000000007
const int maxn= 100010;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    cin>>s;
    int a=count(s.begin(),s.end(),'a');
    int b=count(s.begin(),s.end(),'b');
    int c=count(s.begin(),s.end(),'c');
    if((a==b&&abs(a-c)==1)||(a==c&&abs(a-b)==1)||(b==c&&abs(b-a)==1)||(a==b&&a==c))
        cout<<"YES";
    else
        cout<<"NO";
    cout<<endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int n,m;
vector<int>edge[100005];
int in[100005];
queue<int>que;
int ans[100005];
int main(){
	scanf("%d%d",&n,&m);
	m += n-1;
	rep(i,m){
		int a,b; scanf("%d%d",&a,&b);
		edge[a].pb(b);
		in[b]++;
	}
	repn(i,n) if(in[i]==0) que.push(i);
	while(!que.empty()){
		int q = que.front(); que.pop();
		for(int i=0;i<edge[q].size();i++){
			int to = edge[q][i];
			in[to]--;
			if(in[to] == 0) {ans[to] = q; que.push(to);}
		}
	}
	repn(i,n) printf("%d\n",ans[i]);
}


Measured memory_bytes: 7040
import std.algorithm;
import std.array;
import std.container;
import std.conv;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void scan(T...)(ref T a) {
    string[] ss = readln.split;
    foreach (i, t; T) a[i] = ss[i].to!t;
}
T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

int calc(int[] a) {
    int ans = 0;
    for (int i = 2; i < a.length; i++) {
        int mi = min(a[i-2], a[i]);
        int ma = max(a[i-2], a[i]);
        if (mi < a[i-1] && a[i-1] < ma) ans++;
    }
    return ans;
}

void main() {
    readint;
    auto a = readints;
    writeln(calc(a));
}


Measured memory_bytes: 256
#include <algorithm>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;

int main() {
  const string T = "AKIHABARA";
  string S;
  while (cin >> S) {
    int N = S.size(), M = T.size();
    int i = 0, j = 0;
    for (;;) {
      if (i < N && j < M && S[i] == T[j]) {
        ++i;
        ++j;
      } else if (j < M && T[j] == 'A') {
        ++j;
      } else {
        break;
      }
    }
    bool res = i == S.size() && j == T.size();
    cout << (res ? "YES" : "NO") << endl;
  }
  return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-

a,b,c,d = list(str(input()))

for i in range(2**3):
    op = []
    for j in range(3):
        if ((i>>j)&1):
            op.append("+")
        else:
            op.append("-")
    fml = a + op[0] + b + op[1] + c + op[2] + d
    if eval(fml) == 7:
        print(fml + "=7")
        break



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

int n;
long long a[3005];
long long dp[3005][3005];

long long f(int x, int y) {
    if(dp[x][y] != -1) return dp[x][y];
    if(x == y) return dp[x][y] = a[x];
    
    long long p = a[x] - f(x+1, y);
    long long q = a[y] - f(x, y-1);
    
    return dp[x][y] = max(p, q);
}

int main() {
	// your code goes here
	cin >> n;
	for(int i = 0; i < n; i++) {
	    cin >> a[i];
	}
	memset(dp, -1, sizeof dp);
	cout << f(0, n-1);
	return 0;
}


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

const ll INF = 1e18;
const ll MOD = 1000000007;
const ll MX = 0; //最大値

#define rep(i,n) for(ll i=0; i<(ll)(n); i++)
#define ALL(x) (x).begin(),(x).end()
#define MAX(x) *max_element(ALL(x))
#define PB push_back
#define F first
#define S second

int main(){
    ll n; cin >> n;
    ll res = 7 % n, cnt = 1;

    if(n%5 == 0 || n%2 == 0){
        cout << -1 << endl;
        return 0;
    }

    while(res != 0){
        cnt++;
        res = res * 10 + 7;
        res %= n;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 3612
#include"bits/stdc++.h"
#define int long long
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define itr(i,x) for(auto i=(x).begin();i!=(x).end();++i)
#define All(x) (x).begin(),(x).end()
#define rAll(x) (x).rbegin(),(x).rend()
using namespace std;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
const int mod=1000000007;
int gcd(int x,int y){return y?gcd(y,x%y):x;}
int lcm(int x,int y){return x*y/gcd(x,y);}
void YN(bool flg){cout<<(flg?"YES":"NO")<<endl;}
void Yn(bool flg){cout<<(flg?"Yes":"No")<<endl;}
void yn(bool flg){cout<<(flg?"yes":"no")<<endl;}
signed main(){
	int n;
	cin>>n;
	map<int,int> a;
	rep(i,n){
		int b;cin>>b;
		a[b]++;
	}
	int ans=0;
	itr(i,a){
		int f=i->first,s=i->second;
		if(f<s) ans+=s-f;
		else if(f>s) ans+=s;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 6272
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define IOS ios_base::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define PI acos(-1)
#define EPS 1e-5
#define sz(v) ((int)(v).size())
#define all(v) v.begin(),v.end()
#define forn(i, n) for(ll i=0;i<(ll)n;i++)
#define fi first
#define se second
 

int main() {
	vector<int> a(5);
	forn(i, 5) cin >> a[i];
	forn(i, 5) {
		if(a[i] == 0) {
			cout << i+1 << endl;
			break;
		}
	}
	return 0;
}



Measured memory_bytes: 3580
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(int i = 0; i < n; ++i)
#define rep2(i,start,end) for(ll i = start; i < end; ++i)
#define dwn(i,n) for(int i = n; i >= 0; --i)
#define dwn2(i,start,end) for(ll i = start; i >= end; --i)
#define pll pair<ll,ll>
#define mk(x,y) make_pair(x,y)
#define pdl pair<double, ll>
const ll N = 4e3 + 200;
const ll INF = 0x3f3f3f;
const ll mode = 1e9 + 7;
int v[N][N];
int main(){
	ll n;
	cin>>n;
	rep2(i,1,n+1){
		rep2(j,1,n){
			ll x;
			scanf("%lld",&v[i][j]);
			v[i][0] = 1;
		}
	}
	int flag = 0;
	ll sum = 0;
	ll mx = n*(n-1)/2;
	ll day = 0;
	while(1){
		day++;
		int mp2[N] = {0};
		int flag2 = 0;
		rep2(i,1,n+1){
			ll k = v[i][0];
			if(!mp2[i] && k != n){
				ll x = v[i][k];
				ll k2 = v[x][0];
				ll y = v[x][k2];
				if(y == i && !mp2[x]){
					sum++;
					flag2 = 1;
					mp2[i] = 1;
					mp2[x] = 1;
					v[i][0]++;
					v[x][0]++;
//					cout<<i<<" "<<x<<" "<<day<<endl;
				}		
			}
		}
		if(!flag2){
			flag = 1;
			break;
		}
		if(sum == mx){
			break;
		}
	}
	if(flag) cout<<"-1"<<endl;
	else cout<<day<<endl;
	return 0;
}








Measured memory_bytes: 17664
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System.Text.RegularExpressions;

class Program
{
    const string Yes = "Yes";
    const string No = "No";
    const char White = '.';
    const char Black = '#';
    const long Mod = 1000000007;

    static void Main(string[] args) {
        checked {
#if DEBUG
            MyDebugger.Test(process, "../TextFile1.txt");
            //TestCaseMaker.MakeTestCase1("../TextFile2.txt");
            //MyDebugger.Test(process, "../TextFile2.txt");
#else
            object ret = process(new StreamReader(Console.OpenStandardInput()));
            if(ret != null) Console.WriteLine(ret);
#endif
        }
    }

    static object process(TextReader input) {
        var s = input.ReadLine();

        if(s.Last() == 's') return s + "es";
        return s + "s";
    }

    static long[] ToIntArray(string strs, int n) {
        var ret = new long[n];
        var spl = strs.Split(' ');
        for (int i = 0; i < n; i++)
            ret[i] = long.Parse(spl[i]);
        return ret;
    }
}


Measured memory_bytes: 26072
def solve(i, m):
    if (i, m) in solved_dict:
        return solved_dict[(i, m)]
    if m == 0:
        return True
    if m < 0:
        return False
    if i >= n:
        return False
    solved_dict[(i, m)] = solve(i + 1, m - A[i]) or solve(i + 1, m)
    return solved_dict[(i, m)]

solved_dict = {}
n = int(input())
A = list(map(int, input().split()))
q = int(input())
for m in list(map(int, input().split())):
    print("yes" if solve(0, m) else "no")


Measured memory_bytes: 9228
#include<iostream>
#include<algorithm>


using namespace std;


int main()
{
	int n;
	int a[45] = { 1,1 };
	ios::sync_with_stdio(false);

	cin >> n;

	for (int i = 2; i < n+1; ++i)
	{
		a[i] = a[i - 1] + a[i - 2];
	}

	cout << a[n] << endl;

	return 0;

}


Measured memory_bytes: 3156
#include<iostream>
#include<cstdio>
#include<vector>
#define ll long long
using namespace std;

int main() {
	ll a;
	while (cin >> a) {
		for (ll b = 1, c = 0;; b *= 2, c++) {
			if (b > a) { cout << c << endl; break; }
		}
	}
}

Measured memory_bytes: 3084
#include<iostream>

using namespace std;

int main(void) {

	int x, y;

	cin >> x >> y;

	if (x == 2 && y == 2)
		cout << "Yes" << endl;

	else if (x == 4 || x == 6 || x == 9 || x == 11) {

		if (y == 4 || y == 6 || y == 9 || y == 11)
			cout << "Yes" << endl;
		else
			cout << "No" << endl;

	}

	else if (x == 1 || x == 3 || x == 5 || x == 7 || x == 8 || x == 10 || x == 12) {

		if(y == 1 || y == 3 || y == 5 || y == 7 || y == 8 || y == 10 || y == 12)
			cout << "Yes" << endl;
		else
			cout << "No" << endl;
	}

	else
		cout << "No" << endl;
		

}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <deque>
#include <string>
#include <cstring>
#include <iomanip>
#include <fstream>
#include <map>
#include <unordered_map>
#include <bitset>

#define _crt_secure_no_warnings
#define FREEELO ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back
#define mp make_pair
#define INF 0x3F3F3F3F
#define MAX 200001
#define MOD 1000000007
#define ALPHABET 128
#define loop(i, n) for (int i = 1; i <= (n); i++)
#define loop0(i, n) for (int i = 0; i < (n); i++)
#define sz(x) (int)x.size()
#define all(v) v.begin(), v.end()
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<ll, ll> llll;
typedef pair<int, int> ii;
typedef unordered_map<int, int> umii;
typedef unordered_map<ll, ll> umll;
int cnt = 0;
vector<vector<int> > g;
int used[MAX];
void dfs(int v){
    used[v] = 1;
    cnt++;
    for (int &to : g[v]){
        if (!used[to]) dfs(to);
    }
}

int main(){
    FREEELO
    int n, m; cin >> n >> m;
    g.resize(n + 1);
    loop(i, m){
        int u, v; cin >> u >> v;
        g[u].pb(v);
        g[v].pb(u);
    }
    int mx = -INF;
    loop(i, n){
        if (!used[i]) {
            cnt = 0;
            dfs(i);
            mx = max(mx, cnt);
        }
    }
    cout << mx << endl;
}

Measured memory_bytes: 20824
#include <bits/stdc++.h>
using namespace std;
int main() {
  int K;
  string S;
  cin>>K>>S;
  if(S.size()<=K){
    cout<<S<<endl;
  }else{
    for(int i=0;i<K;i++){
      cout<<S.at(i);
    }
    cout<<"..."<<endl;
  }
}



Measured memory_bytes: 3572
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        int x,y,z;
        Scanner sc = new Scanner(System.in);
        List<Integer> divisors = new ArrayList<Integer>();


        String temp = sc.nextLine();
        String[] tempArr = temp.split(" ");

        if (tempArr.length > 2) {
            x = Integer.parseInt(tempArr[0]);
            y = Integer.parseInt(tempArr[1]);
            z = Integer.parseInt(tempArr[2]);
        } else {
            x = 1;
            y = 1;
            z = 1;
        }

        int maxDivisor = 1;
        if (x > y) {
            maxDivisor = x;
        } else if (x < y){
            maxDivisor = y;
        } else {
            maxDivisor = x;
        }



        for (int i = 1; i <= maxDivisor; i++) {
            if ((x % i) == 0 && (y % i) == 0) {
                divisors.add(i);
            }
        }

        System.out.println(divisors.get(divisors.size() - z));

    }
}


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

void createPrimeTable(int* table, int size);

int main()
{
    int n;
    cin >> n;
    cout << n << ":";
    int sn = (int)sqrt(n);

    /* 素数表を作る */
    int prime_table[sn+1];
    createPrimeTable(prime_table, sn+1);

    vector<int> prime;
    for(int i=0; i<sn+1; i++) 
        if( prime_table[i] ) prime.push_back(i);

    vector<int>::iterator i;
    // for(i=prime.begin(); i!=prime.end(); i++) cout << *i << endl;

    /* ここから本番 */
    for(i=prime.begin(); i!=prime.end(); ){
        if( !(n%(*i)) ){
            if( n == *i ) break;
            cout << " " << *i;
            n /= *i;
            continue;
        }
        i++;
    }
    cout << " " << n << endl;


    return 0;
    
}

void createPrimeTable(int* table, int size)
{
    for(int i=0; i<size; i++) table[i] = 1;
    
    table[0] = table[1] = 0;

    for(int i=2; i<size; i++){
        if( table[i] ){
            for(int j=i+i;j<size; j+=i ){ table[j] = 0; }
        }
    }
}    

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

using namespace std;

using ll = long long;
using ull = unsigned long long;

#define REP(i,n) for(long long i = 0; i < (n); i++)
#define FOR(i, m, n) for(long long i = (m);i < (n); ++i)
#define ALL(obj) (obj).begin(),(obj).end()

template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;

const ll MOD = (ll)1e9 + 7;
const ll MOD2 = 998244353;
const ll LLINF = (ll)1e18;
const ll INTINF = (ll)1e9;
const long double PI = 3.1415926535897932384626433;

template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o;}
template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const multiset<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o;}
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) {o << "{" << obj.first << ", " << obj.second << "}"; return o;}
template <template <class tmp>  class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
void print(void) {cout << endl;}
template <class Head> void print(Head&& head) {cout << head;print();}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head << " ";print(forward<Tail>(tail)...);}
template <class T> void chmax(T& a, const T b){a=max<T>(a,b);}
template <class T> void chmin(T& a, const T b){a=min<T>(a,b);}
void YN(bool flg) {cout << ((flg) ? "YES" : "NO") << endl;}
void Yn(bool flg) {cout << ((flg) ? "Yes" : "No") << endl;}
void yn(bool flg) {cout << ((flg) ? "yes" : "no") << endl;}

int main() {
	int N,M;
	while(1){
		cin >> N;
		if(N==0) return 0;
		V<int> a(N),b(N);
		REP(i,N) cin >> a[i] >> b[i];
		cin >> M;
		V<int> c(M),d(M);
		REP(i,M) cin >> c[i] >> d[i];
		map<P<int,int>,int> mp;
		REP(i,M) mp[{c[i],d[i]}];
		for(int i = 0; i < M; ++i){
			int x = c[i] - a[0];
			int y = d[i] - b[0];
			int flg = 1;
			for(int j = 0; j < N; ++j){
				if( !mp.count({a[j]+x,b[j]+y}) ) flg = 0;
			}
			if(flg) {
				cout << x << " " << y << endl;
				break;
			}
		}
	}

	return 0;
}



Measured memory_bytes: 3076
import bisect

a,b,q = map(int,input().split())
shrine = [-10**12, 10**12]
for _ in range(a):
    s = int(input())
    shrine.append(s)
shrine.sort()

temple = [-10**12, 10**12]
for _ in range(b):
    t = int(input())
    temple.append(t)
temple.sort()

for _ in range(q):
    x = int(input())
    sx = bisect.bisect_right(shrine,x)
    tx = bisect.bisect_right(temple,x)
    ans = 10**12
    #最適な経路はスタート地点から前後のshrine、templeを訪れる経路
    for i in [shrine[sx-1], shrine[sx]]:
        for j in [temple[tx-1], temple[tx]]:
            #caas_1はスタート→shrine→temple
            case_1 = abs(i-x)+abs(i-j)
            #caas_2はスタート→temple→shrine
            case_2 = abs(j-x)+abs(i-j)
            ans = min(ans,case_1,case_2)
            
    print(ans)

Measured memory_bytes: 89056
#include <bits/stdc++.h>
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,ThxDem=b;i<ThxDem;++i)
#define pb push_back
#define ALL(s) s.begin(),s.end()
#define FIN ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define SZ(s) int(s.size())
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;

int main(){FIN;
	ll a,b,n; cin>>a>>b>>n;
	ll x=min(n,b-1);
	cout<<(a*x/b)-a*(x/b)<<"\n";
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
#include <atcoder/dsu>
using namespace std;
using namespace atcoder;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod= int(1e9)+7;
//const int mod=998244353;
using P = pair<int,int>;
using Pl= pair<ll,ll>;
using ld=long double;
using V=vector<int>;
using Vl=vector<ll>;
using VV=vector<vector<int>>;
using VVl=vector<vector<ll>>;

int main() {
    int n,q;cin >>n>>q;
    dsu d(n);
    for (int i = 0; i < q; ++i) {
        int a,b;cin >>a>>b;
        a--;b--;
        d.merge(a,b);
    }
    vector<bool>ch(n,true);
    ll ans=-1;
    for (int i = 0; i < n; ++i) {
        if(ch[d.leader(i)]){
            ans++;
            ch[d.leader(i)]=false;
        }
    }
    cout <<ans<<"\n";
}

Measured memory_bytes: 3788
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<cmath>

using namespace std;
int main(){
  string a,b;
  cin>>a>>b;
  if(a.size()>b.size()){
    cout<<"GREATER"<<endl;
  }
  else if(a.size()<b.size()){
    cout<<"LESS"<<endl;
  }
  else{
    if(a>b)cout<<"GREATER"<<endl;
    else if(a<b)cout<<"LESS"<<endl;
    else cout<<"EQUAL"<<endl;
  }
  
  
  return 0;
}



Measured memory_bytes: 256
# include <iostream>
# include <algorithm>
# define MAX 200002

using namespace std;

int N;
int A[MAX];
long long S[MAX];

int main(){
    cin >> N;
    for ( int i = 1; i <= N; i++) { cin >> A[i];}

    for ( int i = 0; i <= N; i++) {
        if ( i == 0 ) { S[0] = 0;}
        else { S[i] = S[i-1] + A[i];}
    }
    sort(S, S + N + 1);
    
    long long ans = 0;
    long long cnt = 1;
    for ( int i = 1; i <= N; i++) {
        if ( S[i] == S[i-1] ) { cnt++; }
        else {
            ans += (cnt * (cnt - 1)) / 2;
            cnt = 1;
        }
    }
    ans +=  (cnt * (cnt - 1)) / 2;

    cout << ans;
    
    return 0;
}

Measured memory_bytes: 2560
#include <stdio.h>

int main()
{
    int N;
    scanf("%d",& N);

   int last_number = N % 10;

   if (last_number == 2 || last_number == 4 || last_number == 5 || last_number == 7 || last_number == 9){
       printf("hon");
   }
   else if (last_number == 0 || last_number == 1 || last_number == 6 || last_number == 8) {
       printf("pon");
   }
   else if (last_number == 3) {
       printf("bon");
   }
return 0;
}

Measured memory_bytes: 2120
import math


def main():
    k = int(input())
    ans = 0
    for a in range(1, k + 1):
        for b in range(1, k + 1):
            n = math.gcd(a, b)
            for c in range(1, k + 1):
                ans += math.gcd(c, n)
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9180
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>

using namespace std;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define REPO(i, n) for(int i = 1;i <= n;i++)
#define ll long long
#define INF 1999999999
#define MINF -1999999999
#define INF64 1999999999999999999
#define ALL(n) n.begin(),n.end()
#define ABS(a,b) max(a,b) - min(a,b)

ll n, a, b, s[100], c, a2 = 1,ian = 0,ibn = 0;
double x = 0, y, a1;
bool o = true;
int main(){
	cin >> n >> a >> b;
	y = a;
	REP(i, n)cin >> s[i];
	sort(s, s + n, greater<ll>());
	c = s[0];
	REP(i, a) {
		x += s[i];
		if (c != s[i]) {
			o = false; 
			c = s[i];
			ian = 1;
		}
		else ian++;
	}
	a1 = x / y;
	FOR(i, a, n) {
		if (c != s[i])break;
		else ibn++;
	}
	if (o) {
		a2 = 0;
		FOR(i, a, min(b, ian + ibn) + 1) {
			ll z = 1;
			REP(j, i) {
				z *= ibn + ian - j;
				z /= j + 1;
			}
			a2 += z;
		}
	}
	else {
		REP(i, ian) {
			a2 *= ibn + ian - i;
			a2 /= i + 1;
		}
	}
	cout << fixed << a1 << endl;
	cout << a2 << endl;
}

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

int main(void){
  long long int a, b, x;
  long long int cnt = 0;
  cin >> a >> b >> x;
  cnt = b / x - (a - 1) / x;
  if(a == 0){cnt = b / x + 1;}
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    static final int MOD = 1000000007;
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int h = sc.nextInt();
		int w = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();
		Combination cmb = new Combination(h + w);
		long ans = 0;
		for (int i = 1; h - a - i >= 0 && b + i <= w; i++) {
		    int hh = h - a - i;
		    int ww = b + i - 1;
		    ans += (cmb.getComb(hh + ww, hh) * cmb.getComb(h - hh + w - ww - 2, h - hh - 1)) % MOD;
		    ans %= MOD;
		}
		System.out.println(ans);
   }

}

class Combination {
    static final int MOD = 1000000007;
    long[] fac;
    long[] finv;
    long[] inv;
    
    public Combination (int size) {
        fac = new long [size];
        finv = new long [size];
        inv = new long [size];
        fac[0] = 1;
        fac[1] = 1;
        finv[0] = 1;
        finv[1] = 1;
        inv[1] = 1;
        for (int i = 2; i < size; 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;
        }
    }
    
    
    public long getComb(int n, int k) {
        if (n < k || n < 0 || k < 0) {
            return 0;
        }
        return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
    }
    
}



Measured memory_bytes: 25556
#include<bits/stdc++.h>
#define ll long long 
using namespace std;
int main(){
    string N;
    cin>>N;
    int sum=0,count=N.size();
    for(int i=0;i<count;i++){
        sum=sum+N[count-i-1]-48;
    }   
    if(sum%9==0)cout<<"Yes"<<endl;
    else{
        cout<<"No"<<endl;
    }   
    return 0;
}


Measured memory_bytes: 3672
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
using namespace std;
const int MOD = 1000000007;
typedef long long ll;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
typedef unsigned int ui;
int main() {
	int n, X, x[200000],y[200000];
	cin >> n;
	int i;
	for (i = 0; i < n; i++) {
		cin >> X; x[i] = X; y[i] = X;
	}
	sort(x, x + n); int c = x[n / 2-1];
	for (i = 0; i < n; i++) {
		if (y[i] <= c)cout << x[n / 2] << endl;
		else cout << c << endl;
	}
	return 0;
}


Measured memory_bytes: 3712
N, K = list(map(int, input().split()))

ret = 0.0
for i in range(1, N + 1):
    # サイコロの点数がi, 確率が 1/N
    tmp = 1.0 / N
    # コインを振る
    now = i
    while now < K:
        # 点数以下ならばサイコロを振る
        now *= 2  # 点数は倍
        tmp /= 2  # 確率は1/2
    ret += tmp
    
print("{:.12f}".format(ret))

Measured memory_bytes: 39152
#include<iostream>
#include<math.h>
#include<algorithm>
#define ll long long int
#define FOR(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define REP(i,n) FOR(i,0,n)
#define REP1(i,n) FOR(i,1,n)
  
using namespace std;

int main() {
	int n, alice = 0, bob = 0;
	cin >> n;
	int a [ n ];
	REP(i,n) cin >> a [ i ];
	sort ( a, a+n );
	for ( int j = n - 1; j >= 0; j -= 2 ) {
		alice += a [ j ];
	}
	for ( int k = n - 2; k >= 0; k -= 2 ) {
		bob += a [ k ];
	}
	cout << alice - bob << endl;
	return 0;	
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define veci vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define vec2(a,b) vector<vec>(a,vec(b))
#define vec2ll(a,b) vector<vec>(a,vecll(b))
#define vec3(a,b,c) vector<vector<vec>>(a,vec2(b,c))
#define vec3ll(a,b,c) vector<vector<vecll>>(a,vec2ll(b,c))
#define fi first
#define se second
#define all(c) begin(c),end(c)
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))


using namespace std;
int in() {int x;cin>>x;return x;}
ll lin() {ll x;cin>>x;return x;}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T> inline void print(pair<T,T> p){cout<<"("<<p.first<<","<<p.second<<") ";}
//template<class T> inline void print(vector<pair<T,T>> v){for(auto e:v)print(e); cout<<endl;}
//template<class T> inline void print(T v){for(auto e:v)cout<<e<<" ";cout<<endl;}
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
    for(T& x:vec) is >> x;
    return is;
}
const ll INF=1e9+7;

ll d[105][105];
char p[105][105];
ll h,w;

int main()
{
    
    cin >> h >> w;
    rep(i,h){
        rep(j,w){
            cin >> p[i][j];
            d[i][j]=INF;
        }
    }
    rep(i,h){
        rep(j,w){
            if(i){
                if(j){
                    if(p[i][j]!=p[i][j-1]){
                        d[i][j]=min(d[i][j],d[i][j-1]+1);
                    }
                    else{
                        d[i][j]=min(d[i][j],d[i][j-1]);
                    }
                    if(p[i][j]!=p[i-1][j]){
                        d[i][j]=min(d[i][j],d[i-1][j]+1);
                    }
                    else{
                        d[i][j]=min(d[i][j],d[i-1][j]);
                    }
                }
                else{
                    if(p[i][j]!=p[i-1][j]){
                        d[i][j]=min(d[i][j],d[i-1][j]+1);
                    }
                    else{
                        d[i][j]=min(d[i][j],d[i-1][j]);
                    }
                }
            }
            else{
                if(j){
                    if(p[i][j]!=p[i][j-1]){
                        d[i][j]=d[i][j-1]+1;
                    }
                    else{
                        d[i][j]=d[i][j-1];
                    }
                }
                else{
                    if(p[i][j]=='#'){
                        d[i][j]=1;
                    }
                    else{
                        d[i][j]=0;
                    }
                }
            }
        }
    }
    cout << (d[h-1][w-1]+1)/2 << endl;
    return 0;
} 


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

const int INF = 1 << 30;
int n;
int grid[2][110];
int dis[2][110];

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  while (cin >> n, n) {
    for (int i = 0; i < 2; i++) {
      for (int j = 0; j < n; j++) {
        cin >> grid[i][j];
      }
    }
    fill_n((int*)dis, 2 * 110, INF);
    queue<pii> que;
    dis[0][0] = dis[1][0] = 0;
    que.emplace(0, 0);
    que.emplace(1, 0);
    while (!que.empty()) {
      pii p = que.front(); que.pop();
      int a = p.first, b = p.second;
      if (grid[a][b] == 0) {
        for (int i = 0; i < 3 && b + i < n; i++) {
          if (dis[!a][b + i] > dis[a][b] + 1) {
            dis[!a][b + i] = dis[a][b] + 1;
            que.emplace(!a, b + i);
          }
        }
      } else if (grid[a][b] == 1) {
        if (b + 1 == n || grid[a][b + 1] != 1) {
          for (int i = 0; i < 3 && b + i < n; i++) {
            if (dis[!a][b + i] > dis[a][b] + 1) {
              dis[!a][b + i] = dis[a][b] + 1;
              que.emplace(!a, b + i);
            }
          }
        } else if (dis[a][b + 1] > dis[a][b]) {
          dis[a][b + 1] = dis[a][b];
          que.emplace(a, b + 1);
        }
      } else {
        if (b - 1 >= 0 && dis[a][b - 1] > dis[a][b]) {
          dis[a][b - 1] = dis[a][b];
          que.emplace(a, b - 1);
        }
      }
    }
    if (grid[0][n - 1] == 2 && grid[1][n - 1] == 2) cout << "NA" << endl;
    else if (dis[0][n - 1] == INF && dis[1][n - 1] == INF) cout << "NA" << endl;
    else cout << min(dis[0][n - 1], dis[1][n - 1]) << endl;
  }

  return 0;
}


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

int main() {
  int i,j,n,q,count=0,left,right;
  int *S;
  int *T;
  scanf("%d",&n);
  if(n>100000) exit(8);
  S=(int *)malloc(n*sizeof(int));
  for(i=0;i<n;i++)
    {
      scanf("%d",&S[i]);
      if(S[i]<0 || S[i]>1000000000) exit(8);
    }
  scanf("%d",&q);
  if(q>50000) exit(8);
  T=(int *)malloc(q*sizeof(int));
  for(i=0;i<q;i++)
    {
      scanf("%d",&T[i]);
      if(T[i]<0 || T[i]>1000000000) exit(8);
    }
  
  for(j=0;j<q;j++)
    {
      left = 0;
      right = n;
      while(left<right)
	{
	  if(S[(left+right)/2]==T[j])
	    {
	      count++;
	      break;
	    }
	  else if(S[(left+right)/2]<T[j])
	    {
	      left = ((left+right)/2)+1;
	    }
	  else if(S[(left+right)/2]>T[j])
	    {
	      right = (left+right)/2;
	    }
	}
    }
  
  printf("%d\n",count);
  return 0;
}




Measured memory_bytes: 2316
from collections import deque
def main():
    n, m = list(map(int, input().split()))
    G = [[] for _ in range(n)]
    L = []
    for _ in range(m):
        a, b = list(map(lambda x: int(x) - 1, input().split()))
        G[a].append(b)
        G[b].append(a)
        L.append(set([a, b]))
    ans = 0
    for l in L:
        stack = deque([0, ])
        visited = [False] * n
        while stack:
            x = stack.popleft()
            if visited[x]:
                continue
            visited[x] = True
            for dx in G[x]:
                if set([x, dx]) == l:
                    continue
                if not visited[dx]:
                    stack.append(dx)
        if not all(visited):
            ans += 1
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
int main(){
  int m,n,cnt;
  vector<int> num(7368795);
  while(1){
    cin>>m>>n;
    if(m==0 && n==0) break;
    for(int i=0;i<7368795;i++){
      num[i]=0;
    }
    cnt=0;
    for(int i=m;i<7368795;i++){
      if(num[i]==0){
	if(cnt==n){
	  cout<<i<<endl;
	  break;
	}
	for(int j=i;j<7368795;j+=i){
	  num[j]=1;
	}
	cnt++;
      }
    }
  }
  return 0;
}



Measured memory_bytes: 31344
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;

int main(void){
  string a,b;
  cin >> a >> b;
  sort(a.begin(), a.end());
  sort(b.begin(), b.end(), greater<char>());

  int lna = a.size();
  int lnb = b.size();
  int ln = min(lna, lnb);

  for(int i = 0; i < ln; i++){
    if(a[i] < b[i]){
      cout << "Yes" << endl; return 0;
    } else if(a[i] == b[i]){

    } else {
      cout << "No" << endl; return 0;
    }
  }
  if(lna >= lnb){
    cout << "No" << endl; 
  } else {
    cout << "Yes" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int n,p,a,c;
long long ans=1;
main(){
    cin>>n>>p;
    for(int i=0;i<n;i++){
        cin>>a;
        if(!(a%2))c++;
        ans*=2;
    }
    if(n==c && p==1)cout<<0<<endl;
    else if(c==n)cout<<ans<<endl;
    else cout<<ans/2<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<complex>
#include<vector>
#include<algorithm>
#include<functional>
#include<array>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define INF 1e+9


int main() {
	int n;
	cin >> n;
	if (n % 2 == 0) cout << n << endl;
	else cout << n * 2 << endl;


	return 0;
}

Measured memory_bytes: 256