akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MOD = pow(10, 9) + 7;
//const int MOD = 998244353;
//const int MOD = ;
int mod(int A, int M) {return (A % M + M) % M;}
const int INF = 1LL << 60;
const string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const string abc = "abcdefghijklmnopqrstuvwxyz";
template <class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template <class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
int divCeil(int A, int B) {return (A + (B - 1)) / B;}

int modpow(int a, int n, int m)
{
  int ret = 1;
  while (n > 0)
  {
    if (n % 2 == 1) ret = ret * a % m;
    a = a * a % m;
    n /= 2;
  }
  return ret;
}

int modinv(int a, int m)
{
  int b = m, x = 1, y = 0;
  while (b > 0)
  {
    int q = a / b, r = a - q * b, s = x - q * y;
    a = b; b = r;
    x = y; y = s;
  }
  return mod(x, m);
}

class combination
{
public:
  vector<int> fac, finv, inv;

  combination(int M)
  {
    fac = vector<int>(M, 1);
    finv = vector<int>(M, 1);
    inv = vector<int>(M, 1);

    for (int i = 2; i < M; i++)
    {
      fac.at(i) = fac.at(i - 1) * i % MOD;
      inv.at(i) = MOD - inv.at(MOD % i) * (MOD / i) % MOD;
      finv.at(i) = finv.at(i - 1) * inv.at(i) % MOD;
    }
  }

  int COM(int N, int K)
  {
    if (N < K) return 0;
    if (N < 0 || K < 0) return 0;
    return fac.at(N) * (finv.at(K) * finv.at(N - K) % MOD) % MOD;
  }
};

signed main()
{
  int N, A, B, C;
  cin >> N >> A >> B >> C;
  
  combination com(2 * N + 10);
  
  int ans = 0;
  for (int i = N; i < 2 * N; i++)
  {
    int P = com.COM(i - 1, N - 1);
    int p0 = modpow(A, N, MOD) * modpow(B, i - N, MOD) % MOD;
    int p1 = modpow(A, i - N, MOD) * modpow(B, N, MOD) % MOD;
    P *= (p0 + p1) % MOD;
    P %= MOD;
    P *= 100 * i;
    P %= MOD;

    int Q = modpow(100 - C, i, MOD) * (100 - C) % MOD;

    ans += modinv(Q, MOD) * P % MOD;
    ans %= MOD;
  }

  cout << ans << endl;
}

Measured memory_bytes: 4992
import java.util.*;
public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      int a = sc.nextInt();
      int b = sc.nextInt();
      int c = sc.nextInt();
      int k = sc.nextInt();
      int i = 1;
      while(i <= k){
        int max = Math.max(a,Math.max(b,c));
      	if(a==max)a = 2*a;
        else if(b==max)b = 2*b;
        else if(c==max)c = 2*c;
        i++;
      }
      System.out.println(a+b+c);
    }
}

Measured memory_bytes: 23124
#[allow(unused_imports)]
use std::char::*;
#[allow(unused_imports)]
use std::cmp::*;
use std::io::*;
use std::str::FromStr;
#[allow(unused_imports)]
use std::collections::*;

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

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")
}

#[derive(PartialEq, PartialOrd)]
pub struct Total<T>(pub T);

impl<T: PartialEq> Eq for Total<T> {}

impl<T: PartialOrd> Ord for Total<T> {
    fn cmp(&self, other: &Total<T>) -> std::cmp::Ordering {
        self.0.partial_cmp(&other.0).unwrap()
    }
}

//const MAX:usize = 100006;
//const INF:u64 = u64::max_value();

fn main() {
    let n:usize = read();
    let a:Vec<u32> = (0..n).map(|_| read()).collect();

    let avg:f64 = a.iter().sum::<u32>() as f64 / a.len() as f64;
    let mut ans:i32 = -1;
    let mut mn:f64 = 1000000.0;
    for (i,&e) in a.iter().enumerate() {
        if mn > (avg-e as f64).abs() {
            mn = (avg - e as f64).abs();
            ans = i as i32;
        }
    }

    println!("{}", ans);

}


Measured memory_bytes: 4352
#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet};

mod util {
    use std::io::stdin;
    use std::str::FromStr;
    use std::fmt::Debug;

    #[allow(dead_code)]
    pub fn line() -> String {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().to_string()
    }

    #[allow(dead_code)]
    pub fn get<T: FromStr>() -> T
    where
        <T as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().parse().unwrap()
    }

    #[allow(dead_code)]
    pub fn gets<T: FromStr>() -> Vec<T>
    where
        <T as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.split_whitespace()
            .map(|t| t.parse().unwrap())
            .collect()
    }

    #[allow(dead_code)]
    pub fn get2<T: FromStr, U: FromStr>() -> (T, U)
    where
        <T as FromStr>::Err: Debug,
        <U as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        let mut iter = line.split_whitespace();
        (
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap(),
        )
    }
}

fn dfs(v: usize, ve: &[HashSet<usize>], c: bool, color: &mut [Option<bool>]) -> bool {
    color[v] = Some(c);
    for &t in ve[v].iter() {
        if color[t].map(|b| b == c).unwrap_or(false) {
            return false;
        } else {
            if color[t].is_none() && !dfs(t, ve, !c, color) {
                return false;
            }
        }
    }
    true
}

fn main() {
    let (n, m): (usize, usize) = util::get2();
    let edges: Vec<(usize, usize)> = (0..m)
        .map(|_| {
            let (a, b) = util::get2::<usize, usize>();
            (a - 1, b - 1)
        })
        .collect();

    let mut ve = vec![HashSet::new(); n];
    let mut color = vec![None; n];

    for &(a, b) in &edges {
        ve[a].insert(b);
        ve[b].insert(a);
    }

    if dfs(0, &ve, true, &mut color) {
        // 二部グラフ
        let c1 = color.iter().filter(|c| c.unwrap()).count();
        println!("{}", c1 * (n - c1) - m);
    } else {
        println!("{}", n * (n - 1) / 2 - m);
    }
}


Measured memory_bytes: 61820
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;

  int A[N];
  for (int i = 0; i < N; i++) { 
    cin >> A[i];
  }
  
  int i = 0;
  while (i < N){ 
    if(A[i]%2 == 0){
      if(A[i]%3 != 0 && A[i]%5 != 0){
         cout << "DENIED" << endl;
         break;
      }else{
          i++;
      }
   }else{
      i++;
   }
  }
  
  if(i == N){
      cout << "APPROVED" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <math.h>
#define MOD 1000000007
typedef long long ll;
using namespace std;

int main(){
  int a,b;
  cin>>a>>b;
  if(a+b==15){
    cout<<'+'<<endl;
  }else if(a*b==15){
    cout<<'*'<<endl;
  }else{
    cout<<'x'<<endl;
  }
  return 0;
}


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

int main()
{
    int n;
    cin >> n;
    int cnt1 = 0;
    int cnt2 = 0;

    for(int i = 0, a; i < n; ++i){
        cin >> a;
        if(a % 2) cnt1++;
        if(a%4 == 0) cnt2++;
    }

    if(cnt2>cnt1-1 || (cnt2 >= cnt1-1 && cnt2+cnt1 == n)) cout << "Yes";
    else cout << "No";
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
using namespace std;
int table[105][105];
int check(int i, int j){
  for(int a=i-1; a<i+2; a++){
    for(int b=j-1; b<j+2; b++){
      if(table[a][b]==1){
        table[a][b]=0;
        check(a,b);
      }
    }
  }
  return 0;
}
int main(){
  int w,h;
  while(1){
    cin >> w >> h;
    if(w==0 && h==0) break;
    table[w+2][h+2]={};
    rep(i,h) rep(j,w) cin >> table[i+1][j+1];
    rep(i,h+1){
      rep(j,w+1){
        if(table[i][j]==1){
          table[i][j]=2;
          check(i,j);
        }
      }
    }
    int count=0;
    for(int i=1; i<h+1; i++) for(int j=1; j<w+1; j++) if(table[i][j]==2) count++;
    cout << count << endl;
  }
  return 0;
}




Measured memory_bytes: 3176
class BST:
  def __init__(self):
    self.root = None
  
  def insert(self, data):
    z = Node(data)
    y = None
    x = self.root

    while x:
      y = x
      if z.data < x.data:
        x = x.left
      else:
        x = x.right
    z.parent = y
    if y == None:
      self.root = z
    elif z.data < y.data:
      y.left = z
    else:
      y.right = z

  def find(self, data):
    x = self.root
    z = Node(data)
    while x and data != x.data:
      if z.data < x.data:
        x = x.left
      else:
        x = x.right
    if x is not None:
      return True
    else:
      return False


  def print(self):
    print('',' '.join(map(str, self.root.inorder())))
    print('',' '.join(map(str, self.root.preorder())))


class Node():
  def __init__(self, data):
    self.data = data
    self.left, self.right = None, None

  def inorder(self):
    in_list = []
    if self.left:
      in_list += self.left.inorder()
    in_list += [self.data]
    if self.right:
      in_list += self.right.inorder()
    return in_list
  
  def preorder(self):
    pre_list = []
    pre_list += [self.data]
    if self.left:
      pre_list += self.left.preorder()
    #pre_list += [self.data]
    if self.right:
      pre_list += self.right.preorder()
    return pre_list

tree = BST()
n = int(input())
for _ in range(n):
  inp = input().split()
  if len(inp) == 2:
    if inp[0] == "insert":
      tree.insert(int(inp[1]))
    else:
      x = tree.find(int(inp[1]))
      if tree.find(int(inp[1])):
        print("yes")
      else:
        print("no")
  else:
    tree.print()



Measured memory_bytes: 119560
#include <stdio.h>
#define ll long long
int main()
{
    ll a,b,c;
    scanf("%lld%lld%lld",&c,&a,&b);
    if (c==1)printf("%d",a==b);
    else if (a>b)puts("0");
    else printf("%lld",(b-a)*(c-2)+1);
}


Measured memory_bytes: 128
in_list = lambda: list(map(int,input().split()))

n = int(input())

lis_pnt = []

for _ in range(n):
	lis_pnt.append(in_list())

cost = []

for _ in range(n+1):
	cost.append([0,0,0])

for i in range(n):
	for bef in range(3):
		for aft in range(3):
			if bef != aft:
				cost[i+1][aft] = max(cost[i][bef]+lis_pnt[i][aft],cost[i+1][aft])
print(max(cost[n]))


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

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

  int a[n];
  rep (i, n) cin >> a[i];

  int ans = 0;
  int flag = -1; // 0:<, 1:=, 2:>
  for (int i = 0; i < n; i++) {
    if (i == n-1 && flag == -1) {
      ans++;
      break;
    } else if (i == n-1) break;
    if (flag == -1 || flag == 1) {
      if (flag == -1) ans++;
      if (a[i] < a[i+1]) flag = 0;
      else if (a[i] == a[i+1]) flag = 1;
      else flag = 2;
    }
    if (flag == 0) {
      if (a[i] > a[i+1]) flag = -1;
    } else if (flag == 2) {
      if (a[i] < a[i+1]) flag = -1;
    }
  }

  cout << ans << endl;

  return 0;
}


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

signed main(){
#ifdef _DEBUG
	//freopen("_in" , "r", stdin );
	//freopen("_out", "w", stdout);
#endif
	ios::sync_with_stdio(0); cin.tie(0);
	long n; cin >> n;
	long i = sqrt(n);
	for (; i; i--) if (n % i == 0) break;
	cout << i + n/i - 2 << '\n';
}


Measured memory_bytes: 256
#https://atcoder.jp/contests/abc164/tasks/abc164_b
# -*- coding: utf-8 -*-
A,B,C,D = map(int,input().split())
while C > 0 and B > 0:
  C = C - B
  if C <= 0:
    print("Yes")
    break
  A = A -D
  if A <= 0:
    print("No")
    break

Measured memory_bytes: 61552
// 解答不能.
// scott_wu氏.
// https://atcoder.jp/contests/abc155/submissions/10170836
#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;
#define repex(i, a, b, c) for(int i = a; i < b; i += c)
#define repx(i, a, b) repex(i, a, b, 1)
#define rep(i, n) repx(i, 0, n)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define pb push_back
#define a first
#define b second
#define all(x) x.begin(), x.end()
const int MAXN = 202020;

int N, M, blist[MAXN], cv[MAXN], par[MAXN], pnum[MAXN];
P bomb[MAXN];
vector<P> edge[MAXN];
bool seen[MAXN];
vector<int> vnode, ans;

void flood(int cloc){
    seen[cloc] = true;
    vnode.pb(cloc);
    for(P pp : edge[cloc]){
        int neigh = pp.a, nnum = pp.b;
        if(!seen[neigh]){
            par[neigh] = cloc;
            pnum[neigh] = nnum;
            flood(neigh);
        }
    }
}

int main(){
    scanf("%d %d", &N, &M);
    rep(i, N) scanf("%d %d", &bomb[i].a, &bomb[i].b);
    sort(bomb, bomb + N);
    rep(i, N) blist[i] = bomb[i].a;
    blist[N] = 1.1e9;
    rep(i, N + 1){
        cv[i] = 0;
        if(i < N) cv[i] ^= bomb[i].b;
        if(i > 0) cv[i] ^= bomb[i - 1].b;
        seen[i] = false;
    }
    N++;
    rep(i, M){
        int l, r;
        scanf("%d %d", &l, &r);
        r++;
        int a = lower_bound(blist, blist + N, l) - blist;
        int b = lower_bound(blist, blist + N, r) - blist;
        edge[a].pb({b, i + 1});
        edge[b].pb({a, i + 1});
    }
    bool bad = false;
    rep(i, N){
        if(!seen[i]){
            vnode.clear();
            flood(i);
            int cp = 0;
            for(int node : vnode) cp ^= cv[node];
            if(cp){
                bad = true;
            }else{
                reverse(all(vnode));
                for(int node : vnode){
                    if(cv[node]){
                        ans.pb(pnum[node]);
                        cv[node] ^= 1;
                        cv[par[node]] ^= 1;
                    }
                }
            }
        }
    }
    if(bad){
        puts("-1");
    }else{
        printf("%d\n", ans.size());
        sort(all(ans));
        rep(i, ans.size()){
            if(i) printf(" ");
            printf("%d", ans[i]);
        }
        puts("");
    }
    return 0;
}

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

char g[2001][2002];
int s1[2001][2001], s2[2001][2001], s3[2001][2001];

inline int gt(int s[][2001], int a, int b, int c, int d) { return s[c][d] - s[c][b] - s[a][d] + s[a][b]; }

int main(){
	int n, m, q;
	scanf("%d%d%d", &n, &m, &q);
	f(i, 1, n + 1){
		scanf("%s", g[i] + 1);
		f(j, 1, m + 1)if (g[i][j] == '1'){
			++s1[i][j];
			if (g[i - 1][j] == '1')++s2[i][j];
			if (g[i][j - 1] == '1')++s3[i][j];
		}
	}
	f(i, 1, n + 1)f(j, 1, m + 1)s1[i][j] += s1[i - 1][j] + s1[i][j - 1] - s1[i - 1][j - 1];
	f(i, 1, n + 1)f(j, 1, m + 1)s2[i][j] += s2[i - 1][j] + s2[i][j - 1] - s2[i - 1][j - 1];
	f(i, 1, n + 1)f(j, 1, m + 1)s3[i][j] += s3[i - 1][j] + s3[i][j - 1] - s3[i - 1][j - 1];
	while (q--){
		int a, b, c, d;
		scanf("%d%d%d%d", &a, &b, &c, &d);
		int an = gt(s1, a - 1, b - 1, c, d) - gt(s2, a, b - 1, c, d) - gt(s3, a - 1, b, c, d);
		printf("%d\n", an);
	}
}

Measured memory_bytes: 52608
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define is(a, b) a == b
#define len(v) ll(v.size())

class UnionFind {
public:
	vector<int> par;//親の番号
    vector<int> rank;//木の深さ
 
	UnionFind(int n){//全ての要素に対して自身が根となるように初期化, 木の深さは0になる
		rep(i,n){
            par.push_back(i);
            rank.push_back(0);
        }
	}
 
	int find(int x) {//木の根を求める
		if(par[x]==x){
            return x;
        }else{
            return par[x]=find(par[x]);
        }
	}
 
	void unite(int x,int y){//xとyの属する集合を併合
        x=find(x);
        y=find(y);
        if(x==y) return;
        if(rank[x]<rank[y]){//木の深さが小さい方を大きい方へ繋げる
            par[x]=y;
        }else{
            par[y]=x;
            if(rank[x]==rank[y]) rank[x]++;
        }
    }

    bool same(int x,int y){//xとyが同じ集合に属するか否か
        return find(x)==find(y);
    }
};
//x以下の要素への最小index, ソートしてから使ってね
template <class T> 
int former(const vector<T> &v, T x){
  return upper_bound(v.begin(), v.end(), x) - v.begin() - 1;
}
//x以上の要素への最小index
template <class T> 
int latter(const vector<T> &v, T x){
  return lower_bound(v.begin(), v.end(), x) - v.begin();
}
//vector書き出し
template <class T>
void cout_vec(const vector<T> &vec1){
  rep(i,len(vec1)){
    cout<<vec1[i]<<' ';
  }
  cout<<'\n';
}
//nCk
template <class T>
T comb(T n,T k){
    T ans=1;
    FOR(i,n-k+1,n+1){
        ans*=i;
    }
    FOR(i,1,k+1){
        ans/=i;
    }
    return ans;
}
//a,bの最大公約数
template <class T>
T gcd(T a,T b) {
	if (b == 0) return a;
	else return gcd(b, a % b);
}
//素因数分解
template <class T>
map<T,T> prime_factor(T x){
    map<T,T> ans;
    for(T i=2;i*i<=x;i++){
        while(x%i==0){
            x/=i;
            ans[i]++;
        }
    }
    if (x!=1){
        ans[x]=1;
    }
    return ans;
}
//約数列挙
template <class T>
vector<T> divisor(T x){
    vector<T> res;
    for(T i=1;i*i<=x;i++){
        if(x%i==0){
            res.push_back(i);
            if(i!=x/i){
                res.push_back(x/i);
            }
        }
    }
    return res;
}
//素数判定
template <class T>
bool is_prime(T x){
    for(T i=2;i*i<=x;i++){
        if(x%i==0){
            return false;
        }
    }
    return x!=1;
}

const ll inf=1e9+7;

ll mult(ll n,ll m){//n^m%infを求める
    if(m==1){
        return n%inf;
    }else if(m%2==0){//オーバーフロー防止のためにn^(m/2)*n^(m/2)を考える
        ll t=mult(n,m/2);
        return (t*t)%inf;
    }else{//奇数の時はn^(m-1)*nを考える
        ll t=mult(n,m-1);
        return (t*n)%inf;
    }
}

typedef pair<ll,ll> P;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m;
    map<string,int> s,t;
    cin>>n;
    rep(i,n){
        string x;
        cin>>x;
        s[x]++;
    }
    cin>>m;
    rep(i,m){
        string x;
        cin>>x;
        t[x]++;
    }
    int ans=0;
    for(auto itr:s){
        if(ans<s[itr.first]-t[itr.first]){
            ans=s[itr.first]-t[itr.first];
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
d = {}

def nCr(n, r):
    if n < r:
        return 0
    if n == r or r == 0:
        return 1
    if (n, r) in d:
        return d[(n, r)]
    d[(n, r)] = nCr(n - 1, r) + nCr(n - 1, r - 1)
    return d[(n, r)]

if __name__ == '__main__':
    n, a, b = map(int, input().split())
    v = sorted((int(s) for s in input().split()), reverse=True)
    print(sum(v[:a]) / a)
    x = v.count(v[a - 1])
    print(nCr(x, v[:a].count(v[a - 1])) if v[0] > v[a - 1] else sum(nCr(x, i) for i in range(a, b + 1)))


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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n;
  cin >> n;
  
  vector<int> a(n), b(n), count(n + 1);
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
    count.at(a.at(i))++;
  }
  for (int i = 0; i < n; i++) {
    cin >> b.at(i);
    count.at(b.at(i))++;
  }
  
  for (int i = 1; i <= n; i++) {
    if (count.at(i) > n) {
      cout << "No\n";
      return 0;
    }
  }
  
  reverse(b.begin(), b.end());
  
  int left = 1e9, right = -1, same;
  for (int i = 0; i < n; i++) {
    if (a.at(i) == b.at(i)) {
      left = i;
      same = a.at(i);
      break;
    }
  }
  for (int i = n - 1; i >= 0; i--) {
    if (a.at(i) == b.at(i)) {
      right = i;
      break;
    }
  }
  
  int it = 0;
  for (int i = left; i <= right; i++) {
    while (true) {
      if (a.at(it) != same && b.at(it) != same) {
        swap(b.at(it), b.at(i));
        it++;
        break;
      }
      else {
        it++;
      }
    }
  }
  
  cout << "Yes\n";
  for (int i = 0; i < n; i++) {
    if (i) cout << " ";
    cout << b.at(i);
  }
  cout << '\n';
}

Measured memory_bytes: 5576
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx,avx2,fma")

#include<bits/stdc++.h>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define ull unsigned long long
#define inf 2000000000
#define infLL 2000000000000000000
#define MAX 200005
#define sf(a) scanf("%d", &a)
#define sfl(a) scanf("%lld", &a)
#define pf(a) printf("%d\n", a)
#define pfl(a) printf("%lld\n", a)
#define Case(t) printf("Case %d: ", t)
#define pii pair<int, int>
#define MOD 1000000007
#define mod 998244353
#define PI acos(-1.0)
#define eps 1e-9
#define mem(a, b) memset(a, b, sizeof(a))
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

inline int Set(int N, int pos){return N=N | (1<<pos);}
inline int Reset(int N, int pos){return N=N & ~(1<<pos);}
inline bool Check(ll N, ll pos){return (bool)(N & (1LL<<pos));}

inline void normal(ll &a) { a %= mod; (a < 0) && (a += mod); }
inline ll modMul(ll a, ll b) { a %= mod, b %= mod; normal(a), normal(b); return (a * b) % mod; }
inline ll modAdd(ll a, ll b) { a %= mod, b %= mod; normal(a), normal(b); return (a + b) % mod; }
inline ll modSub(ll a, ll b) { a %= mod, b %= mod; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while (p) { if (p & 1LL) r = modMul(r, b); b = modMul(b, b); p >>= 1LL; } return r; }
inline ll modInverse(ll a) { return modPow(a, mod - 2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

ll fast_exp(ll x, ll n, ll m)
{
    ll res = 1;
    while(n>0)
    {
        if(n%2==1)
            res = (res * x) % m;
        x = (x * x) % m;
        n/=2;
    }
    return res%m;
}

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args)
{
    cerr << *it << " = " << a << endl;
    err(++it, args...);
}

clock_t t_Start;
void Start()
{
    t_Start = clock();
}
void End()
{
    double Time = (double)(clock()-t_Start)/CLOCKS_PER_SEC;
    error(Time);
}

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>orderedSet;
typedef tree<int,null_type,greater<int>,rb_tree_tag,tree_order_statistics_node_update>orderedSet1;

int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    //Start();

    FASTIO;
    int n;
    cin>>n;
    unordered_map<string, bool>mp;
    int ans = 0;
    for(int i = 0; i < n; i++)
    {
        string s;
        cin>>s;
        if(!mp[s])
            ans++;
        mp[s] = true;
    }
    cout<<ans<<endl;

    //End();
    return 0;
}


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

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define fi first
#define se second

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

    int r[100003]={0};
    rep(i,n)
    {
        int a,b;
        scanf(" %d %d", &a, &b);
        ++r[a];
        --r[b+1];
    }

    rep(i,100002) r[i+1]+=r[i];

    //number of people to invite
    int ans=0;

    for(int i=n; i>0; --i)
    {
        if(r[i+1]>=i)
        {
            ans=i;
            break;
        }
    }

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

Measured memory_bytes: 3600
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;

int main() {
  int N; scanf("%d", &N);
  vector<int> D(N);
  for(int i = 0; i < N; ++i) scanf("%d", &D[i]);
  sort(D.begin(), D.end());

  int M; scanf("%d", &M);
  vector<int> T(M);
  for(int i = 0; i < M; ++i) scanf("%d", &T[i]);
  sort(T.begin(), T.end());

  int j = 0;
  for(int i = 0; i < M; ++i) {
    while(j < N && D[j] < T[i]) ++j;
    if(j == N || D[j] > T[i]) {
      printf("NO\n");
      return 0;
    }
    ++j;
  }
  printf("YES\n");
  return 0;
}


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

using namespace std;

using ll = long long;
using ld = long double;
using vi = vector<ll>;
using vvi = vector<vi>;

#define all(a) a.begin(), a.end()
#define mp make_pair
#define pb push_back

void solve() {
    ll n; cin >> n;
    if (n % 1000 == 0) cout << "0";
    else cout << 1000 - n % 1000;

}

int main() {
    solve();
}

Measured memory_bytes: 3636
sub f{my$a=pop;
	for(grep$$a{$_},keys%$a){
		if(!$v[$_]){
			$v[$_]=1;
			++$c;
			f($_)
		}
	}
}
($N,$M)=glob<>;
/ /,${$`}{$'+0}=${$'+0}{$`}=1for@ab=<>;
for(@ab){
	/ /;
	${$`}{$'+0}=${$'+0}{$`}=0;
	@v=();
	$c=1;
	$v[1]=1;
	f 1;
	$x+=$c<$N;
	${$`}{$'+0}=${$'+0}{$`}=1
}
print$x


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

int main(){
    int N,M,X,Y; cin >> N >> M >> X >> Y;
    vector<int> x_(N);
    vector<int> y_(M);
    rep(i,N) cin >> x_[i];
    rep(i,M) cin >> y_[i];
    
    int x_max = -100, y_min = 100;
    rep(i,N){

        x_max = max(x_[i],x_max);
    }
    rep(i,M){

        y_min = min(y_[i],y_min);
    }
    if(x_max < y_min && x_max < Y && y_min > X){
       cout << "No War";
    }
    else{ cout << "War";
    }
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        while(true) {
            int n = Integer.parseInt(sc.nextLine());
            if (n == 0) break;
            for (int i = 0; i < n; i++) {
                String[] score = sc.nextLine().split(" ");
                int math = Integer.parseInt(score[0]);
                int english = Integer.parseInt(score[1]);
                int japanese = Integer.parseInt(score[2]);
                if (math == 100 || english == 100 || japanese == 100) {
                    System.out.println("A");
                } else if (math + english >= 180) {
                    System.out.println("A");
                } else if (math + english + japanese >= 240) {
                    System.out.println("A");
                } else if (math + english + japanese >= 210) {
                    System.out.println("B");
                } else if (math + english + japanese >= 150 && Math.max(math, english) >= 80) {
                    System.out.println("B");
                } else {
                    System.out.println("C");
                }
            }
        }
    }
}

Measured memory_bytes: 38376
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define endl "\n"
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);

    int n;
    cin >> n;
    int arr[n];
    for (int i=0;i<=n-1;i++)
    {
        cin >> arr[i];
    }    

    int count=1;
    for (int i=0;i<=n-1;i++)
    {
        if (arr[i]==count)
        {
            count++;
        }
    }

    if (count==1)
    {
        cout << "-1" << endl;
    }
    else
    {
        cout << n-count+1 << endl;
    }
    
    return 0;
}


Measured memory_bytes: 1024
function Main(input) {
  input=input.split("\n");
  if(input[input.length-1]===''){
    input.pop();
  }
  const N=input[0]-0;
  var A=input[1].split(' ').map(e=>{
    return e-0;
  });
  A.unshift(0);
  var ret=new Array(N+1);
  var temp=0;
  var pointer;
  for(var i=N;i>=1;i--){
    pointer=i*2;
    temp=0;
    while(pointer<=N){
      temp=(ret[pointer]+temp)%2;
      pointer+=i;
    }
    ret[i]=(temp+A[i])%2;
  }
  ret.shift();
  var ans=ret.reduce((acc,cur)=>{
    return acc+cur;
  });
  console.log(ans);
  ret.forEach((e,i)=>{
    if(e===1){
      console.log(i+1);
    }
  });

}

//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 52620
#include<bits/stdc++.h>
using namespace std;
int n,m,p=0;
 vector<int>v[10];

void dfssecond(bool vis[],int s)
{
  /*cout<<"s  "<<s<<endl;
for(int i=1;i<=n;i++)
{
  cout<<vis[i]<<" ";
}
cout<<endl<<endl;*/
vis[s]=1;
for(int i=0;i<v[s].size();i++)
{
  if(!vis[v[s][i]])
  {
    dfssecond(vis,v[s][i]);
    //cout<<"t "<<s<<endl;
   /* for(int i=1;i<=n;i++)
{
  cout<<vis[i]<<" ";
}
cout<<endl;*/
  }
}
for(int i=1;i<=n;i++)
{
  if(!vis[i])
  {
    
    vis[s]=0;
  }
  
}
if(vis[s]!=0)
{
p++;
//cout<<"p "<<p<<"  "<<"s "<<s<<endl;
vis[s]=0;
}
//return;
}

/*int  dfs(bool visited[],int s)
{int count=0;
    visited[s]=1;
    for(int i=0;i<v[s].size();i++)
    {
         if(!visited[v[s][i]])
         {
          if( !(dfssecond(visited,v[s][i],count)))
          {
              //count++; 
          }
         }
    }
    return count;
}*/








void firstdfs()
{
  
  int count=0;
     bool visited[n+1];
     memset(visited,0,sizeof(visited));
     visited[1]=1;
     dfssecond(visited,1);
     cout<<p<<endl;
  
}
int main()
{
  //int n,m;
  cin>>n>>m;
  //vector<int>v[n+1];
  for(int i=1;i<=m;i++)
  {
    int a,b;
    cin>>a>>b;
    v[a].push_back(b);
    v[b].push_back(a);

  }
  //cout<<endl<<endl;
firstdfs();
}

Measured memory_bytes: 256
#include <iostream>
#include <string>

using namespace std;

int main() {

	int people,count = 0;
	string hat;

	cin >> people;
	cin >> hat;

	for (int i = 0; i < people; i++){

		if (hat[i] == 'R'){

			count++;
		}
	}

	hat = (count > people / 2) ? "Yes" : "No";
	cout << hat;

	return 0;
}

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

using namespace std;

int main(int argc, char *argv[]) {
    int N, M;
    cin >> N >> M;
    map<int, int> hm;
    map<int, multiset<int>> pm;
    for (int i = 0; i < N; i++) {
        int cur;
        cin >> cur;
        hm[i + 1] = cur;
    }
    for (int j = 0; j < M; j++) {
        int a, b;
        cin >> a >> b;
        pm[a].insert(hm[b]);
        pm[b].insert(hm[a]);
    }

    int ans = 0; 
    for (int k = 0; k < N; k++) {
        int cur = k + 1;
        int myheight = hm[cur];
        if (pm.count(cur) == 0) {
            ans++;
        } else {
            int hmx = *pm[cur].rbegin();
            if (myheight > hmx) {
                ans++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 25800
/***********************************************************************************
*           Falling down is an accident, Staying down is a choice.                 *
***********************************************************************************/
#include <bits/stdc++.h>
using namespace std;
#define ios std::ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) //Fast IO
#define _USE_MATH_DEFINES
#define PI acos(-1.0) //3.14159265358
#define EPS 1e-9 //epsilon, 10^-9, checking for equality 
#define pb push_back
#define fi first
#define se second
#define isort(x) sort(x.begin(),x.end())
#define dsort(x) sort(x.rbegin(),x.rend())
const int inf=1e9+7; //10^9 +7
const int modc=998244353;
typedef long long int ll;
void solve();int main(){ios;solve();return 0;}
/***********************************************************************************/
void solve()
{
	int n;cin>>n;
	vector<ll> a(n,inf),b(n-1);
	for(int i=0;i<n-1;i++)
	{
		cin>>b[i];
	}	
	for(int i=n-2;i>=0;i--)
	{
		if(a[i+1]>b[i]) a[i+1] = b[i];
		a[i] = b[i];
	}
	ll ans=0;
	for(int i=0;i<n;i++) ans+=a[i];
	cout<<ans<<endl;	
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
        int n, wa;

        scanf("%d", &n);

        wa=n;

        while(wa>=10){
                wa=wa%10;
        }

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

        return 0;
}


Measured memory_bytes: 2156
def BSort(A,n):
    flag=1
    while flag:
        flag=0
        for i in range(n-1,0,-1):
            if A[i][1]<A[i-1][1]:
                A[i],A[i-1]=A[i-1],A[i]
                flag=1

def SSort(A,n):
    for i in range(n):
        minj=i
        for j in range(i,n):
            if A[j][1]<A[minj][1]:
                minj=j
        A[i],A[minj]=A[minj],A[i]

n = int(input())

A = list(input().split())
B=A[:]

BSort(A,n)
print(' '.join(A))
print('Stable')
SSort(B,n)
print(' '.join(B))

if A==B:
    print('Stable')
else:
    print('Not stable')



Measured memory_bytes: 5608
#![allow(unused_imports)]

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

use std::{i32, i64, u32, u64, usize, f64};
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::io::{stdout, Write, BufWriter};
use std::mem::{swap};

fn main() {
    input! {
        n: usize,
        hs: [usize; n],
    }
    let mut ans = 0usize;
    solve(&mut ans, &hs);
    println!("{}", ans);
}

fn solve(ans: &mut usize, hs: &[usize]) {
    if let Some(&m) = hs.iter().min() {
        *ans += m;
        let hss: Vec<_> = hs.iter().map(|h| h - m).collect();
        for hs in hss.split(|h| *h == 0) {
            solve(ans, hs);
        }
    }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define rep(i,n) for(int i=(0);i<(n);i++)

using namespace std;

typedef long long ll;

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

	int n, a, b;
	cin >> n >> a >> b;

	cout << min(n * a, b) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define ld long double
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using P=pair<long long,long long>;
#define rep(i,n) for(long long i=0; i<(long long)n; i++)
#define FOR(i,a,b) for(long long i=a; i<b; i++)
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((long long)(x).size())
#define COUT(x) cout << x << endl
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstr vector<string>
#define vp vector<pair<int,int>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define SUM(x) accumulate(x.begin(),x.end(),0)
#define MAX(x) *max_element(x.begin(),x.end())
#define MIN(x) *min_element(x.begin(),x.end())
#define couty cout<<"Yes"<<endl
#define coutn cout<<"No"<<endl
#define coutY cout<<"YES"<<endl
#define coutN cout<<"NO"<<endl
#define yn(x) cout<<(x?"Yes":"No")<<endl
#define YN(x) cout<<(x?"YES":"NO")<<endl
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcm(long long a, long long b){return a*b/gcd(a,b);}
const long long dx[4]={1,0,-1,0};
const long long dy[4]={0,1,0,-1};
const long long INF = 1e12;
const long long MOD = 1e9+7;

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(15);

    string s; cin >> s;
    int n=s.size();
    int k; cin >> k;
    set<string> set;
    
    //size
    FOR(i,1,k+1){
        //begin
        for(int j=0; j+i<=n; j++){
            set.insert(s.substr(j,i)); 
        }
    }
    
    //for(auto s:set) cout<<s<<endl;
    cout<<*(next(set.begin(),k-1))<<endl;
}

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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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; }

const ll INF = 1e9+10;
const ll MOD = 1e9+7;
const ll LINF = 1e18;



signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  
  string s; cin>>s;
  cout<<s[0]<<(s.size()-2)<<s[s.size()-1]<<endl;
  
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define PI 3.14159265359
#define NIL (-1)
#define LL long long
using namespace std;
const int64_t MOD = 1e9 + 7;
const int INF = INT_MAX;

int main() {
	int64_t N, M;
	cin >> N >> M;

	priority_queue<int64_t> pq;
	for (int i = 0; i < N; i++) {
		int64_t n;
		cin >> n;
		pq.push(n);
	}

	for (int i = 0; i < M; i++) {
		int64_t n = pq.top();
		pq.pop();
		pq.push(n / 2);
	}

	int64_t sum = 0;
	for (int i = 0; i < N; i++) {
		int64_t n = pq.top();
		pq.pop();
		sum += n;
	}

	cout << sum << endl;
}

Measured memory_bytes: 4300
#include <stdio.h>
#include <iostream>
using namespace std;

int main(void){
  int i, n;
  i = 1;
  while(1){
    cin >> n;
    if(n!=0){
      printf("Case %d: %d\n", i, n);
      i++;
    }else{
      break;
    }
  }
  return 0;
}



Measured memory_bytes: 3116
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
ll time10[11];
ll ketanum[11];
void init() {
	time10[0] = 1;
	rep1(i, 10) {
		time10[i] = time10[i - 1] * 10;
	}
	ketanum[0] = 0;
	rep1(i, 10) {
		ketanum[i] = ketanum[i - 1] + 9 * time10[i - 1] * i;
	}
}
int main(){
	init();
	ll n; int k; 
	while (cin >> n >> k, n || k) {
		n--;
		int chk = 1;
		rep(i, 11) {
			if (ketanum[i] < n) {
				chk = i + 1;
			}
		}
		n -= ketanum[chk - 1];
		ll d = n / chk; ll r = n % chk;
		LP now = { time10[chk - 1] + d,r };
		rep(i, k) {
			string u = to_string(now.first);
			cout << u[now.second];
			int len = u.length();
			if (now.second < len - 1) {
				now.second++;
			}
			else {
				now.first++; now.second = 0;
			}
		}
		cout << endl;
	}
	return 0;
}


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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ll << (b))

using namespace std;

using i32 = int;
using i64 = long long;
using u64 = unsigned long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vu64 = vector<u64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
inline u64 xorshift() { static u64 x = 88172645463325252ull; x = x ^ (x << 7); return x = x ^ (x >> 9); }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template <typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template <typename T> inline T power(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
template <typename T, typename S> istream& operator>>(istream &is, pair<T, S> &p) { is >> p.first >> p.second; return is; }
template <typename T, typename S> ostream& operator<<(ostream &os, pair<T, S> &p) { os << p.first << ' ' << p.second; return os; }

void solve() {
  while (true) {
    int x, y, s; cin >> x >> y >> s;
    if (x == 0) return;

    int ans = 0;
    reps(i, s - 1) {
      int T = s - i * (100 + x) / 100;
      int j = -1;
      rreps(k, s - 1) {
        if (k * (100 + x) / 100 == T) {
          j = k;
          break;
        }
      }
      if (j == -1) continue;
      amax(ans, i * (100 + y) / 100 + j * (100 + y) / 100);
    }
    cout << ans << '\n';
  }
}



Measured memory_bytes: 3160
import java.io.InputStream;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	int N, M;
	List<List<Integer>> g;
	boolean[] visited;

	boolean isEndNode(int n) { // いきどまり
		boolean result = true;
		for (int x : g.get(n)) {
			if (visited[x] == false) {
				result = false;
				break;
			}
		}
		return result;
	}

	boolean allVisited() {
		for (int i = 1; i < visited.length; i++) {
			if (visited[i] == false) {
				return false;
			}
		}
		return true;
	}

	//
	int bfs(int n) {
		if (isEndNode(n)) {
			visited[n] = true;
			try {
				if (allVisited()) {
					return 1;
				} else {
					return 0;
				}
			} finally {
				visited[n] = false;
			}
		}

		visited[n] = true;

		int ans = 0;
		for (int x : g.get(n)) {
			if (!visited[x]) {
				ans += bfs(x);
			}
		}

		visited[n] = false;

		return ans;

	}

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		N = sc.nextInt();
		M = sc.nextInt();

		g = new ArrayList<>();
		for (int i = 0; i <= N; i++) {
			g.add(new ArrayList<>());
		}

		for (int i = 0; i < M; i++) {
			int a = sc.nextInt();
			int b = sc.nextInt();

			g.get(a).add(b);
			g.get(b).add(a);
		}

		sc.close();

		visited = new boolean[N + 1];

		out.println(bfs(1));

	}

	public static void main(String[] args) {
		new Main()._main(args);
	}
}


Measured memory_bytes: 24276
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <tuple>

using namespace std;

template< typename T >
struct edge {
  int src, to;
  T cost;

  edge(int to, T cost) : src(-1), to(to), cost(cost) {}

  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}

  edge &operator=(const int &x) {
    to = x;
    return *this;
  }

  operator int() const { return to; }
};

template< typename T >
using Edges = vector< edge< T > >;
template< typename T >
using WeightedGraph = vector< Edges< T > >;

template< typename T >
vector< T > dijkstra(WeightedGraph< T > &g, int s) {
  const auto INF = numeric_limits< T >::max();
  vector< T > dist(g.size(), INF);

  using Pi = pair< T, int >;
  priority_queue< Pi, vector< Pi >, greater< Pi > > que;
  dist[s] = 0;
  que.emplace(dist[s], s);
  while(!que.empty()) {
    T cost;
    int idx;
    tie(cost, idx) = que.top();
    que.pop();
    if(dist[idx] < cost) continue;
    for(auto &e : g[idx]) {
      auto next_cost = cost + e.cost;
      if(dist[e.to] <= next_cost) continue;
      dist[e.to] = next_cost;
      que.emplace(dist[e.to], e.to);
    }
  }
  return dist;
}

int main(void) {
    int N, X, Y;
    cin >> N >> X >> Y;
    --X; --Y;

    WeightedGraph<int> g(N);
    for(int i=0; i<N-1; i++) {
        g[i].emplace_back(i+1, 1);
        g[i+1].emplace_back(i, 1);
    }
    g[X].emplace_back(Y, 1);
    g[Y].emplace_back(X, 1);

    vector<int64_t> ans(N);
    for(int i=0; i<N; i++) {
        auto dist = dijkstra(g, i);
        for(auto e: dist) {
            ans[e]++;
        }
    }

    for(int k=1; k<N; k++) {
        cout << ans[k]/2 << endl;
    }
    return 0;
}


Measured memory_bytes: 384
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		while (true) {
			int m = sc.nextInt();
			int f = sc.nextInt();
			int r = sc.nextInt();
			if (m == -1 && f == -1 && r == -1) {
				break;
			}
			if ((m == -1 || f == -1) || m + f < 30) {
				System.out.println("F");
			} else if (m + f >= 80) {
				System.out.println("A");
			} else if (m + f >= 65 && m + f <80) {
				System.out.println("B");
			} else if ((m + f >= 50 && m + f < 65) || r >= 50) {
				System.out.println("C");
			} else if (m + f >= 30 && m + f < 50) {
				System.out.println("D");
			}
			
		}
		sc.close();
	}

}


Measured memory_bytes: 26300
n = gets.chomp.to_i
a = gets.chomp.split(" ").map(&:to_i)

b = [a[0]]
(1..(n - 1)).each do |i|
  b << b[i-1] + a[i]
end

a_sum = b[n-1]
ans = (b.shift * 2 - a_sum).abs
b.pop
b.each do |x|
  ans = [ans, (2 * x - a_sum).abs].min
end

puts ans

Measured memory_bytes: 22788
n=int(input())
s=input()
a=[str(c) for c in s]
if n%2==1:
  print("No")
else:
  l=n//2
  a1=a[:l]
  a2=a[l:]
  a1="".join(a1)
  a2="".join(a2)
  if a1==a2:
    print("Yes")
  else:
    print("No")

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

int main(void) {
  string s;cin >> s;
  
  for (int i=0;i<3;i++) {
    if (s[i] == '1') {
      s[i] = '9';
    } else {
      s[i] = '1';
    }
  }
  
  cout << s << endl;
    
  return 0;
}

Measured memory_bytes: 256