akhauriyash/Code-Regression huggingface dataset:
def Price_combination():
    combination = []
    for i, x in enumerate(a):
        j = i + 1
        for y in a[j:]:
            if x + y <= m:
                combination.append(x+y)

    return combination

while True:
    n, m = map(int, input().split())
    if n == m == 0:
        break

    a = [int(i) for i in input().split()]

    ######## 許容範囲で金額を組み合わせる ########
    combination = Price_combination()
    ############################################

    if len(combination):
        print(max(combination))
    else:
        print("NONE")



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

int main(){
  int n,k;
  cin >>  n >> k;
  double possibility=0;
  for(int i=1;i<=n;i++){
    int a = i;
    double p=1;
    while(a<k){
      p*=1/(double)2;
      a*=2;
      //cout << p << endl;
    }
    //cout << possibility << endl;
    possibility += p;
  }
  possibility /= n;
  printf("%.15f\n",possibility);
  return 0;
}


Measured memory_bytes: 256
k = int(input())
if k <= 9:
    print(k)
else:
    a = [[1,2,3,4,5,6,7,8,9]]
    cnt = 0
    anscnt = 9
    flag = 0
    while flag == 0:
        b = []
        for i in a[cnt]:
            stri = str(i)
            if stri[-1] == "0":
                now = int(stri + "0")
                b.append(now)
                anscnt += 1
                if anscnt == k:
                    print(now)
                    flag = 1
                now = int(stri + "1")
                b.append(now)
                anscnt += 1
                if anscnt == k:
                    print(now)
                    flag = 1
            elif stri[-1] == "9":
                now = int(stri + "8")
                b.append(now)
                anscnt += 1
                if anscnt == k:
                    print(now)
                    flag = 1
                now = int(stri + "9")
                b.append(now)
                anscnt += 1
                if anscnt == k:
                    print(now)
                    flag = 1
            else:
                s = int(stri[-1])-1
                now = int(stri + str(s))
                b.append(now)
                anscnt += 1
                if anscnt == k:
                    print(now)
                    flag = 1
                s += 1
                now = int(stri + str(s))
                b.append(now)
                anscnt += 1
                if anscnt == k:
                    print(now)
                    flag = 1
                s += 1
                now = int(stri + str(s))
                b.append(now)
                anscnt += 1
                if anscnt == k:
                    print(now)
                    flag = 1
            a.append(b)
            cnt += 1

Measured memory_bytes: 11832
#include <bits/stdc++.h>
using namespace std;
#define nl cout<<'\n'
#define nll <<'\n'
#define fio ios_base::sync_with_stdio(false); cin.tie(NULL)
int main()
{
    int a,b;
    cin>>a>>b;
    int s=0;
    if(a>1) s+=(a*(a-1))/2;
    if(b>1) s+=(b*(b-1))/2;
    cout<<s;
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
using namespace std;
int main(){
    double pi = 3.141592;
    int x1,y1,x3,y3,x2,y2,x4,y4;;
    cin>>x1>>y1>>x2>>y2;
    x3=round(((x2-x1)*cos(pi/4)-(y2-y1)*sin(pi/4)  )*sqrt(2)+ x1);
    y3=round(((x2-x1)*sin(pi/4)+(y2-y1)*cos(pi/4)  )*sqrt(2)+ y1);
    x4=round((x2-x1)*cos(pi/2)-(y2-y1)*sin(pi/2)  + x1);
    y4=round((x2-x1)*sin(pi/2)+(y2-y1)*cos(pi/2)  + y1);
    cout<<x3<<" "<<y3<<" "<<x4<<" "<<y4<<endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <map>
#include <set>
#include <cstdio>
#include <cmath>
#define rep(i,l,n) for(lint i=l;i<n;i++)
#define rer(i,l,n) for(lint i=l;i<=n;i++)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define pb(a) push_back(a)
#define mk(a,b) make_pair(a,b)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef vector<int> vi;
typedef vector<lint> vli;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

lint gcd(lint a,lint b){
	if(b==0) return a;
	return gcd(b,a%b);
}
lint mini(lint a,lint b){
	lint g=gcd(a,b);
	return a*b/g;
}
lint solve(lint a,lint m){
	lint now=1,res=0;
	for(res=1;;res++){
		now=(a*now)%m;
		if(now==1) return res;
	}
}
int main(){
	lint a,b,c,l,m,n;
	while(cin>>a>>l>>b>>m>>c>>n){
		if(a==0 && b==0 && c==0 && l==0 && m==0 && n==0) break;
		lint ans=0,A,B,C;
		A=solve(a,l);
		B=solve(b,m);
		C=solve(c,n);
		ans=mini(mini(A,B),C);
		o(ans);
	}		
}

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

#define COUNTOF(a) (sizeof(a)/sizeof(a[0]))
#define SP << " " <<
typedef long long ll;
template<class T> istream& operator >> (istream& s, vector<T>& v) {
  for (T& x: v) s >> v;
  return s;
}
inline void Yes(bool f){cout<<(f?"Yes":"No")<<endl;}
inline void YES(bool f){cout<<(f?"YES":"NO")<<endl;}

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

    const int N = 3;
    string s; cin >> s;

    int ans=0;
    for (int i = 0; i < N; i++)
        if (s[i] == '1') ans++;
    cout << ans << endl;
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG //エラーを出すためのおまじない
#include <bits/stdc++.h>
//#include <cstdlib>  // abs() for integer
#include <cmath>    // abs() for float, and fabs()
#include <math.h>
using namespace std;
#define coYES cout << "YES" << endl
#define coNO cout << "NO" << endl
#define coYes cout << "Yes" << endl
#define coNo cout << "No" << endl
#define coyes cout << "yes" << endl
#define cono cout << "no" << endl
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  int n, c, k;
  cin >> n >> c >> k;
  vector<int> t(n);
  rep(i, n) {
    int num;
    cin >> num;
    t.at(i) = num;
  }
  sort(t.begin(), t.end());
  int passenger = 0;
  int now_time = 0;
  int bus = 0;
  int first_pass_timelimit = 0;
  int first_pass_time = 0;
  rep(i, n) {
    passenger++;
    now_time = t.at(i);
    if (passenger == 1) {
      first_pass_time = t.at(i);
    }
    if (passenger > 1) {
      first_pass_timelimit = t.at(i) - first_pass_time;
    }
    //timelimit = t.at(i) - now_time_before;
    if (passenger >= c) {
      if (first_pass_timelimit <= k) {
        bus++;
        passenger = 0;
        first_pass_time = 0;
        first_pass_timelimit = 0;
        //cout << 123 << endl;
      }
    }
    if (first_pass_timelimit > k) {
      bus++;
      passenger = 1;
      first_pass_time = t.at(i);
      first_pass_timelimit = t.at(i) - first_pass_time;
      //cout << 456 << endl;
    }
  }
  if (passenger) {
    bus++;
    //cout << 789 << endl;
  }
  cout << bus << endl;
}
      


Measured memory_bytes: 3728
n = int(input())
H = list(map(int,input().split()))

h_max = 0
for i in range(len(H)):
    if i == 0:
        h_max = H[i]
    else:
        if h_max <= H[i]+1:
            if h_max < H[i]:
                h_max = H[i]
        else:
            print ("No")
            exit ()

print ("Yes")


Measured memory_bytes: 20592
x, y = map(int, input().split())

prize_x = 0
prize_y = 0
prize_z = 0

if x == 3:
    prize_x = 100000
elif x == 2:
    prize_x = 200000
elif x == 1:
    prize_x = 300000

if y == 3:
    prize_y = 100000
elif y == 2:
    prize_y = 200000
elif y == 1:
    prize_y = 300000
    
if x == 1 and y == 1:
    prize_z = 400000

print(prize_x + prize_y + prize_z)

Measured memory_bytes: 3064
#include <stdio.h>

int main(void){

        int a,b,c,k;
        scanf("%d%d%d%d",&a,&b,&c,&k);
        int ans = 0;

        for(int i=1;i<=k;i++){
                if(a>0){
                        a = a-1;
                        ans = ans+1;
                }else if(a==0 && b>0){
                        b = b-1;
                }else{
                        c = c-1;
                        ans = ans-1;
                }   
        }   

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


Measured memory_bytes: 1732
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		final Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		long s = sc.nextInt();
		long cash = 0;
		long ans = 0;
		for(int i = 0; i < N; i++) {
			int time = sc.nextInt();
			if(time >= cash) {
				ans += s;
				cash = time + s;
			} else {
				ans += (time + s - cash);
				cash = time + s;
			}
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 64848
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <cstdlib>
#include <cmath>
#include <functional>

#define INF 1000000000000000000
using namespace std;
typedef long long ll;


int main(){
	int a, b;
	cin >> a >> b;
	if (a == 1)a += 13;
	if (b == 1)b += 13;
	if (a == b)cout << "Draw" << endl;
	else if (a > b)cout << "Alice" << endl;
	else cout << "Bob" << endl;

	return 0;
}


Measured memory_bytes: 256
s = input()

ans = 0
for i in range(2 ** (len(s) - 1)):
    s_start = 0
    for j in range(len(s)):
        if i >> j & 1:
            ans += int(s[s_start:j+1])
            s_start = j+1
#            print(ans)
    ans += int(s[s_start:])
print(ans)

Measured memory_bytes: 3060
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	static int[] S ;
	public static void main(String[] args) throws Exception {
		// TODO 自動生成されたメソッド・スタブ
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String W = in.readLine();

		int L = Integer.parseInt(W);

		double a = (double)L/(double)3;
		double ans = a * a * a;

		System.out.printf("%.12f",ans);
	}


}


Measured memory_bytes: 23252
import statistics
N = int(input())
 
a = []
b = []
 
for i in range(N):
    m, n = map(int, input().split())
    a.append(m)
    b.append(n)
 
if N % 2 == 1:
    print(int(statistics.median(b)-statistics.median(a)+1))
else:
    print(int(statistics.median(b)*2-statistics.median(a)*2+1))

Measured memory_bytes: 28860
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

/* typedef */

/* global variables */

int nis[9];
int ccds[3][9], csums[3];

/* subroutines */

bool rec(int k, int *cds) {
  if (k == 0) return true;

  for (int i = 0; i < 9; i++)
    if (cds[i] >= 3) {
      cds[i] -= 3;
      bool ok = rec(k - 3, cds);
      cds[i] += 3;
      if (ok) return true;
    }

  for (int i = 0; i < 7; i++)
    if (cds[i] && cds[i + 1] && cds[i + 2]) {
      cds[i]--, cds[i + 1]--, cds[i + 2]--;
      bool ok = rec(k - 3, cds);
      cds[i]++, cds[i + 1]++, cds[i + 2]++;
      if (ok) return true;
    }

  return false;
}

/* main */

int main() {
  int tn;
  cin >> tn;
  while (tn--) {
    memset(ccds, 0, sizeof(ccds));
    memset(csums, 0, sizeof(csums));

    for (int i = 0; i < 9; i++) cin >> nis[i];
    for (int i = 0; i < 9; i++) {
      char c;
      cin >> c;
      int ci = (c == 'R') ? 0 : (c == 'G') ? 1 : 2;

      ccds[ci][nis[i] - 1]++;
      csums[ci]++;
    }

    if (false)
      for (int i = 0; i < 3; i++) {
	for (int j = 0; j < 9; j++) cout << ccds[i][j] << ' ';
	cout << "= " << csums[i] << endl;
      }

    bool ok = true;
    for (int i = 0; ok && i < 3; i++)
      ok = (csums[i] % 3 == 0) && rec(csums[i], ccds[i]);

    cout << ok << endl;
  }

  return 0;
}

Measured memory_bytes: 1160
import java.util.*;
public class Main { 
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		long n = stdIn.nextInt();
		int counter = 0;
		while(n > 1) {
			if(n % 3 == 2) n++;
			if(n % 3 == 1) n+=2;
			n /= 3;
			
			counter++;
		}
		System.out.println(counter);
	}
}

Measured memory_bytes: 17360
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }

/*
 <url:http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2400&lang=jp>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */
int T,P,R;
struct Team{
    int id;
    int correct;
    int penalty;
    vector<int> accept;
    vector<int> wrong;
    Team(){};
    Team(int id,int P):id(id),accept(P),wrong(P),correct(0),penalty(0){}
    void AC(int P,int time){
        if(accept[P]) return;
        accept[P] = 1;
        penalty += wrong[P]*1200 + time;
        correct++;
        return;
    }
    void WA(int P){
        wrong[P]++;
    }
    bool operator < (const Team& o)const {
        return correct!=o.correct?correct>o.correct:penalty!=o.penalty?penalty<o.penalty:id<o.id;
    }
};
void solve(){
    vector<Team> info(T);
    for(int i = 0; i < T;i++) info[i] = Team(i,P);
    for(int i = 0; i < R;i++){
        int tid,pid,time; string msg;
        cin >> tid >> pid >> time >> msg;
        tid--; pid--;
        if(msg == "CORRECT"){
            info[tid].AC(pid,time);
        }else{
            info[tid].WA(pid);
        }
    }
    sort(info.begin(),info.end());
    for(Team& team:info){
        cout << team.id+1 << " " << team.correct << " " << team.penalty << endl;
    }
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    while(cin >> T >> P >> R,T){
        solve();
    }
    return 0;
}



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

int main() {
  int N;
  cin >> N;
  vector<int> x(N), y(N), h(N);
  for(int i = 0; i < N; i++) {
    cin >> x.at(i) >> y.at(i) >> h.at(i);
  }

  int MAX = 100;

  for(int posY = 0; posY <= MAX; posY++) {
    for(int posX = 0; posX <= MAX; posX++) {
      int needH = -1;
      for(int i = 0; i < N; i++) {
        if(h.at(i) > 0) {
          int tmp = h.at(i) + abs(posY - y.at(i)) + abs(posX - x.at(i));
          if (needH == -1) {
            needH = tmp;
          } else {
            if (needH != tmp) {
              needH = -2;
              break;
            }
          }
        }
      }
      if (needH == -2) continue;
      for (int i = 0; i < N; i++) {
        if (h.at(i) == 0) {
          int dist = abs(posY - y.at(i)) + abs(posX - x.at(i));
          if (needH > dist) {
            needH = -2;
            break;
          }
        }
      }
      if (needH == -2) continue;
      cout << posX << " " << posY << " " << needH << endl;
      return 0;
    }
  }
}


Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! input {
    ( $($t:ty),* ) => {{
        let mut s = String::new();
        std::io::stdin().read_line(&mut s);
        let mut splits = s.trim().split_whitespace();
        ($( { splits.next().unwrap().parse::<$t>().unwrap() },)*)
    }}
}

#[allow(unused_must_use)]
#[allow(unused_variables)]
fn solve() {
    let (n, ) = input!(usize);
    let mut a = Vec::with_capacity(n);
    
    for _ in 0..n {
        let (an, ) = input!(u32);
        a.push(an);
    }

    let mut sorted = a.clone();
    sorted.sort();

    let max = sorted[sorted.len() - 1];
    let max2 = sorted[sorted.len() - 2];

    for val in a {
        if max == val {
            println!("{}", max2);
        } else {
            println!("{}", max);
        }
    }
}

fn main() {
    solve();
}


Measured memory_bytes: 7676
import java.util.*;
import java.io.PrintWriter;
import static java.lang.Integer.*;
import static java.lang.Long.*;
import static java.lang.Math.*;
import static java.lang.System.*;

public class Main {
	public static final int MOD = 1000000007;
	public static final int M = 3;
	public static void main(String[] args) {
		int i,j;
		Scanner sc = new Scanner(in);
		boolean[][] card = new boolean[M][];
		int[][] a = new int[M][M];
		HashMap<Integer, Pair> map = new HashMap<>();
		for (i = 0; i < M; i++) {
			card[i] = new boolean[M];
			for (j = 0; j < M; j++) {
				map.put(parseInt(sc.next()), new Pair(i, j));
			}
		}
		int n = parseInt(sc.next());
		int[] b = new int[n];
		for (i = 0; i < n; i++) {
			Pair p = map.get(parseInt(sc.next()));
			if(p!=null) {
//				out.println(p);
				card[p.i][p.j]= true; 
			}
		}
		sc.close();
		boolean f = false;
		for (i = 0; i < M; i++) {
			if(card[i][0]&&card[i][1]&&card[i][2]) f = true;
			if(card[0][i]&&card[1][i]&&card[2][i]) f = true;
		}
		if(card[0][0]&&card[1][1]&&card[2][2]) f = true;
		if(card[0][2]&&card[1][1]&&card[2][0]) f = true;
		out.println(f?"Yes":"No");
	}
}
class Pair {
	int i;
	int j;
	Pair(int i, int j) {
		this.i = i;
		this.j = j;
	}
	@Override
	public String toString() {
		return "i=" + String.valueOf(i) + ":j=" + String.valueOf(j);
	}
}


Measured memory_bytes: 23252
N = int(input())
A = list(map(int,input().split()))

calc1 = 0
calc2 = 0

L = A

if L[0] > 0 :
    su = L[0]
else :
    su = 1
    calc1 += 1 + abs(L[0])

for i in range(1,N) :
    su += L[i]
    if i % 2 :
        if su >= 0 :
            calc1 += 1 + abs(su)
            su = -1
    else :
        if su <= 0 :
            calc1 += 1 + abs(su)
            su = 1

L = A

if L[0] < 0 :
    su = L[0]
else :
    su = -1
    calc2 += 1 + abs(L[0])

for i in range(1,N) :
    su += L[i]
    if not i % 2 :
        if su >= 0 :
            calc2 += 1 + abs(su)
            su = -1
    else :
        if su <= 0 :
            calc2 += 1 + abs(su)
            su = 1
print(min(calc1,calc2))


Measured memory_bytes: 14468
def main():
    N = int(input())
    S = [0]*N
    count=[1]*N
    for i in range(N):
        S[i] = input()
    ss=sorted(S)
    ss.append("zettainai")
    flag=0
    for i in range(N):
        if ss[i]==ss[i+1]:
            flag= flag+1
        else:
            count[i]=count[i]+flag
            flag=0
    maxx=max(count)
    for i in range(N):
        if count[i]==maxx:
            print(ss[i])
main()

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

int main() {
    using namespace std;
    constexpr unsigned long MOD = 1000000007;
    unsigned long N;
    cin >> N;
    deque<bool> A(2 * N);
    {
        deque<bool> B(2 * N);
        string S;
        cin >> S;
        for(unsigned long i = 0; i < 2 * N; ++i)B[i] = S[i] & 1;
        A[0] = B[0];
        bool s = true;
        for(unsigned long i = 1; i < 2 * N; ++i){
            A[i] = B[i] ^ s;
            s ^= 1;
        }
    }
    if(accumulate(A.begin(), A.end(), 0UL) != N)return 0 & puts("0");
    unsigned long ans{1}, amari{0};
    for(unsigned long i = 1; i <= N; ++i)(ans *= i) %= MOD;
    for(const auto& i : A){
        if(i){
            (ans *= amari) %= MOD;
            if(amari)--amari;
            else return 0 & puts("0");
        }else ++amari;
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
    int N;
    cin >> N;
    int a[N], c[9];
    rep(i, N) {
        cin >> a[i];
    }
    rep(i, 9) {
        c[i] = 0;
    }

    rep(i, N) {
        if(a[i] < 400) {
            c[0]++;
        }
        else if(a[i] < 800) {
            c[1]++;
        }
        else if(a[i] < 1200) {
            c[2]++;
        }
        else if(a[i] < 1600) {
            c[3]++;
        }
        else if(a[i] < 2000) {
            c[4]++;
        }
        else if(a[i] < 2400) {
            c[5]++;
        }
        else if(a[i] < 2800) {
            c[6]++;
        }
        else if(a[i] < 3200) {
            c[7]++;
        }
        else {
            c[8]++;
        }
    }

    int t = 0;
    int min = 0;
    int max = 0;
    rep(i, 8) {
        if(0 < c[i]) {
            t++;
        }
    }

    max = t + c[8];
    if(t == 0) {
        min = 1;
    }
    else {
        min = t;
    }

    cout << min << " " << max;
    
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
n, x, m = list(map(int, input().split()))

s = [0, x]
d = {x: 1}
su = x
ans = x
for i in range(2, n+1):
    x = (x * x) % m
    su += x
    if x in d:
        a = su - s[d[x]]
        ans = s[d[x]] - x
        le = i - d[x]
        rep = (n - d[x] + 1) // le
        ans += a * rep
        amari = (n - d[x] + 1) % le
        for j in range(amari):
            ans += x
            x = (x * x) % m
        break
    else:
        s.append(su)
        d[x] = i
        ans = su
print(ans)

Measured memory_bytes: 17456
N, T = gets.split.map(&:to_i)
cs = []
N.times.each do
  temp = []
  temp = gets.split.map(&:to_i)
  if temp[1] <= T
    cs << temp[0]
  end
end
if cs.empty?
  puts "TLE"
else
  puts cs.min
end


Measured memory_bytes: 1788
#include <cstdio>

using namespace std;

const int N = 109;

char ans[N][N];

int main() {
  int a, b;
  scanf("%d %d", &a, &b);
  for (int i = 0; i < 50; ++i) {
    for (int j = 0; j < 100; ++j) {
      ans[i][j] = '.';
    }
  }
  for (int i = 50; i < 100; ++i) {
    for (int j = 0; j < 100; ++j) {
      ans[i][j] = '#';
    }
  }
  for (int i = 0; i < 50; i += 2) {
    for (int j = 0; j < 100; j += 2) {
      if (b > 1) {
        ans[i][j] = '#';
        --b;
      }
    }
  }
  for (int i = 51; i < 100; i += 2) {
    for (int j = 0; j < 100; j += 2) {
      if (a > 1) {
        ans[i][j] = '.';
        --a;
      }
    }
  }
  puts("100 100");
  for (int i = 0; i < 100; ++i) {
    for (int j = 0; j < 100; ++j) {
      putchar(ans[i][j]);
    }
    putchar('\n');
  }
}


Measured memory_bytes: 128
MOD=10**9+7
cnt=0; sum=0; prev=nil; can=true; h=Hash.new(0)
def gs() gets.chomp end
def gi() gets.to_i end
def gsmi() gets.chomp.split.map(&:to_i) end

def desc(ar) ar.sort!{|x,y|y<=>x} end
def min(a,b) a<=b ? a : b end
def max(a,b) a>=b ? a : b end
def sum(ar) ar.inject(:+) end

def C(a,b) b==0||a==b ? 1 : (b=a-b if a/2<b;(a-b+1..a).inject(:*)/(1..b).inject(:*)) end

def puts_yesno(can) puts(can ? 'Yes' : 'No') end
def putsend(s) puts s; exit end
def debug(k,v) puts "#{k}:#{v}" end
########### ( ˘ω˘ )ｽﾔｧ… ###########
n=gi
a=gsmi

putsend -1 if a.count(1).zero?

num=1
j=0
n.times do |i|
  if num==a[i]
    num+=1
  end
end
puts n-num+1


Measured memory_bytes: 20624
#include <bits/stdc++.h> // Tomasz Nowak
using namespace std;     // XIII LO Szczecin
using L = long long;

#define FOR(i, l, r) for(int i = l; i <= r; ++i)
#define REP(i, n) FOR(i, 0, n - 1)

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

	int n;
	cin >> n;
	vector<int> h(n);
	for(int &hi : h)
		cin >> hi;

	vector<int> dp(n);
	FOR(i, 1, n - 1) {
		dp[i] = dp[i - 1] + abs(h[i] - h[i - 1]);
		if(i != 1)
			dp[i] = min(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]));
	}
	cout << dp.back() << '\n';
}

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

int main()
{
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  int ans = min(B, D) - max(A, C);
  ans = max(ans, 0);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
S = input()
mae = 1
ato = 1
ls = len(S)

temp = S[0]
ans = 1
while True:
    ato += 1
    if ato > ls:
        break
    if temp != S[mae:ato]:
        ans += 1
        temp = S[mae:ato]
        mae = ato
print(ans)

Measured memory_bytes: 3500
#include<iostream>
#include<vector>
#include<map>
using namespace std;

using P = pair<int, int>;

#define N 100004

vector<int> g[N], g0[N];

vector<int> vs;
int lab[N], prv[N];

void dfs(int v, int p) {
  prv[v] = p;
  vs.push_back(v);
  lab[v] = vs.size();
  for(int w : g[v]) {
    if(w == p) {
      continue;
    }
    if(lab[w]) {
      if(lab[v] < lab[w]) {
        g0[v].push_back(w);
      }
      continue;
    }
    dfs(w, v);
  }
}

int used[N], ap[N];
vector<P> bs;
vector<int> aps;
void construct(int n) {
  dfs(0, -1);

  used[0] = 1;
  bool first = true;
  for(int u : vs) {
    if(!used[u]) {
      // (u, p) is a bridge
      int p = prv[u];
      bs.push_back(u < p ? P(u, p) : P(p, u));
      if(g[u].size() > 1) ap[u] = 1;
      if(g[p].size() > 1) ap[p] = 1;
    }
    bool cycle = false;
    for(int v : g0[u]) {
      int w = v;
      while(w != u && !used[w]) {
        used[w] = 1;
        w = prv[w];
      }
      if(w == u) {
        cycle = true;
      }
    }
    if(cycle) {
      if(!first) ap[u] = 1;
      first = false;
    }
  }
  for(int i=0; i<n; ++i) {
    if(ap[i]) aps.push_back(i);
  }
}

int main() {
  int n, m;
  cin >> n >> m;
  for(int i=0; i<m; ++i) {
    int a, b; cin >> a >> b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  construct(n);
  for(int v : aps) {
    cout << v << endl;
  }
  return 0;
}


Measured memory_bytes: 9520
#include"bits/stdc++.h"
using namespace std;
#define ll long long
#define LL long long
#define MOD 1000000007
#define INF 2000000000
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };
ll N, M, K,H,W,L,R,l,r,mi1,mi2,sum,Q;
LL ans;
LL no;
bool b,bb[100001];
string s,t;

int main() {
	cin >> N;
	vector<pair<LL,LL>> a(N);
	for (int i = 0; i < N; i++) {
		cin >> a[i].first;
		a[i].second = i+1;
	}
	sort(a.begin(), a.end());
	for (int i = 0; i < N; i++) {
		cout << a[i].second << " ";
	}
		cout << endl;

	return 0;
}



Measured memory_bytes: 2432
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
  // 入力
  int N, R;
  cin >> N >> R;

  int naibu;

  if (N >= 10) {
    naibu = R;
  } else {
    naibu = R + 100*(10-N);
  }
  
  cout << naibu << endl;

  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
	char ch[2][3];
	for(int i=0;i<2;i++)
	{
		for(int j=0;j<3;j++)
		{
			cin>>ch[i][j];
		}
	}
	int flag=1;
	if(ch[0][1]!=ch[1][1])flag=0;
	if(ch[0][0]!=ch[1][2])flag=0;
	if(ch[0][2]!=ch[1][0])flag=0;
	if(flag)printf("YES\n");
	else printf("NO\n");
	return 0;
}

Measured memory_bytes: 256
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#include<bits/stdc++.h>
using namespace std;
//using namespace __gnu_pbds;
#define ll long long
#define M 1000000007LL
#define rep(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define sep(i,a,b) for(ll i=(ll)a;i>=(ll)b;i--)
#define mll map<ll,ll>
#define vl vector<ll>
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define sz(v) ((ll)v.size())
#define all(a) a.begin(),a.end()
#define F first
#define S second
#define pii pair<ll,ll> 
#define mod 1000000007
#define MAXN 300002
ll arr[100002];
ll ans=0;
vector<ll>v;
void f(ll i,ll k,ll ind,ll an,ll su)
{

if(k==0 and i<v.size()) return;
  if(i==v.size() and k) return;
  if(i==v.size()and k==0) {ans=max(ans,an);
    return;}
  ll btti=(an >> (ind - 1)) & 1;
  if(btti==0) return;

  f(i+1,k-1,ind,(an&(su+v[i])),0);
  
  f(i+1,k,ind,an,su+v[i]);
}
int main() {
       ll t;
       ios::sync_with_stdio(0);
       cin.tie(0);
       cout.tie(0);
       ll a,b;
       cin>>a>>b;
       cout<<max(a+b,max(2*a-1,2*b-1));
       return 0;
}

Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    m, n = map(int, input().split())
    print(pow(m, n, mod))


if __name__ == '__main__':
    resolve()



Measured memory_bytes: 5612
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<numeric>
#include<map>
#include<queue>
#include<deque>
#include<set>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
typedef long long ll;
typedef vector<int> vec;
typedef vector<vector<int>> mat;

int main(){
    int N,M;cin>>N>>M;
    priority_queue<int> pque;
    int a;
    for(int i=0;i<N;i++){
        cin>>a;
        pque.push(a);
    }
    for(int i=1;i<=M;i++){
        int m=pque.top();pque.pop();
        m/=2;
        pque.push(m);
    }
    ll ans=0;
    while(!pque.empty()){
        int M=pque.top();pque.pop();
        ans+=(ll)M;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 892
l, r = map(int, input().split())
if r-l >=2020:
    print(0)
    exit()
ans = 2018
for i in range(l, r+1):
    for j in range(l, r+1):
        if i != j:
            a = i*j%2019
            ans = min(ans, a)
print(ans)

Measured memory_bytes: 9184
import java.util.Scanner;
import java.util.Arrays;
public class Main {
	static int j=0;
	
	static int[] field_make(String str){
		j=0;
		int[] field=new int[str.length()];
		Arrays.fill(field, -1);
		 while( j< str.length()){
			 if(str.indexOf('c',j) != -1){
				 field[str.indexOf('c',j)]=0;
				 j=str.indexOf('c',j);
			 }
			 j++;
		 }
		 return field;
	}
	
	
	static void doit(){
		Scanner sc = new Scanner(System.in);
		int H=sc.nextInt();
		int W=sc.nextInt();
		int[][] field=new int[H][W];
		String[] str=new String[H];
		for(int i=0;i<H;i++){
			str[i]=sc.next();
			field[i]=field_make(str[i]);
		}
		
	sc.close();
	for(int i=0;i<H;i++){
		 for(int k=0;k<W-1;k++){
			 if(field[i][k]!=-1 && field[i][k+1]!=0){
				 field[i][k+1]=field[i][k]+1;
			 }
		 }
		 for (int k=0;k<W-1;k++){
				System.out.printf("%d ", field[i][k]);
			}
				System.out.printf("%d\n",field[i][W-1]);
	}
		
	}
	
	
	public static void main(String[] args) {
		new Main();
		doit();
	}

}

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

using namespace std;
typedef long long LL;
int _max(int x, int y) {return x > y ? x : y;}
int _min(int x, int y) {return x < y ? x : y;}
const int N = 10001;
int read() {
	int s = 0, f = 1; char ch = getchar();
	while(ch < '0' || ch > '9') {if(ch == '-') f = -1; ch = getchar();}
	while(ch >= '0' && ch <= '9') s = s * 10 + ch - '0', ch = getchar();
	return s * f;
}
void put(int x) {
	if(x >= 10) put(x / 10);
	putchar(x % 10 + '0');
}

int n, a[N];
int plen, p[N];
int tp, ans[N * 2], sum[N];
bool v[N];

int gcd(int a, int b) {return b == 0 ? a : gcd(b, a % b);}

void get_p(int n) {
	for(int i = 2; i <= n; i++) {
		if(!v[i]) p[++plen] = i;
		for(int j = 1; j <= plen && (LL)i * p[j] <= n; j++) {
			v[i * p[j]] = 1;
			if(i % p[j] == 0) break;
		}
	}
}

int add(int x, int y, int mod) {
	x += y;
	return x >= mod ? x - mod : x;
}

bool check(int mod) {
	for(int i = 0; i < mod - 1; i++) sum[i] = 0;
	for(int i = 0; i <= n; i++) sum[i % (mod - 1)] = add(sum[i % (mod - 1)], (a[i] % mod + mod) % mod, mod);
	for(int i = 0; i < mod - 1; i++) if(sum[i]) return 0;
	return 1;
}

int main() {
	n = read();
	get_p(n);
	for(int i = n; i >= 0; i--) a[i] = read();
	int cc = abs(a[n]); for(int i = n - 1; i >= 0; i--) if(a[i]) cc = gcd(cc, abs(a[i]));
	for(int i = 2; i * i <= cc; i++) if(cc % i == 0){
		while(cc % i == 0) cc /= i;
		ans[++tp] = i;
	} if(cc > 1) ans[++tp] = cc;
	for(int i = 1; i <= plen; i++) if(a[0] % p[i] == 0 && check(p[i])) ans[++tp] = p[i];
	sort(ans + 1, ans + tp + 1);
	tp = unique(ans + 1, ans + tp + 1) - (ans + 1);
	for(int i = 1; i <= tp; i++) put(ans[i]), puts("");
	return 0;
}


Measured memory_bytes: 384
# 2020/07/05
# AtCoder Beginner Contest 173 - C

import copy

def dfs(hi, wi, wc, wh, ww, wk, d):
    if d == 0 and wi >= ww:
        d = 1
    elif d == 1 and hi >= wh:
        d = 2

    if d == 0:
        newc = copy.deepcopy(wc)
        for i in range(wh):
            newc[i][wi] = '.'
        rval = dfs(hi, wi+1, wc, wh, ww, wk, d)
        rval += dfs(hi, wi+1, newc, wh, ww, wk, d)
        return rval
    elif d == 1:
        newc = copy.deepcopy(wc)
        for i in range(ww):
            newc[hi][i] = '.'
        rval = dfs(hi+1, wi, wc, wh, ww, wk, d)
        rval += dfs(hi+1, wi, newc, wh, ww, wk, d)
        return rval
    else:
        cnt = 0
        for i in range(wh):
            for j in range(ww):
                if wc[i][j] == '#':
                    cnt = cnt + 1
        if cnt == wk:
            return 1
        else:
            return 0

# Input
h, w, k = map(int,input().split())

c = list()
for i in range(h):
    cl = list(input())
    c.append(cl)

ans = dfs(0, 0, c, h, w, k, 0)

# Output
print(ans)


Measured memory_bytes: 9368
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <deque>

using namespace std;

#define mod 1000000007
#define pi atan(1) * 4

int main()
{
	int a, b, c, d, e, f;
	cin >> a >> b >> c >> d >> e >> f;
	double node = 0.0;
	int s = 0, w = 100 * a;
	for(int i = 0; i < 30; i++){
		for(int j = 0; j < 30; j++){
			int canputsugar = min(f - 100 * a * i - 100 * b * j, (a * i + b * j) * e);
			int maxsugar = 0;
			for(int k = 0; k < 3000; k++){
				if(c * k > canputsugar) break;
				int nowsugar = c * k + d * ((canputsugar - c * k) / d);
				double nownode = (double)nowsugar / (a * i + b * j);
				if(nownode > node){
					node = nownode;
					w = 100 * (a * i + b * j);
					s = nowsugar;
				}
			}
		}
	}
	cout << s + w << " " << s << endl;
	return 0;
}

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


using namespace std;

using ll   = long long;
using ii   = pair < int , int >;
using i3   = pair < int , ii >;
using li   = pair < ll , int >;
using lii  = pair <  ll,  ii >;
using vi   = vector < int >;
using vl   = vector < ll >;
using vli  = vector < li >;
using vii  = vector < ii >;
using vi3  = vector < i3 >;
using vlii = vector < lii >;

const int N = 2e5 + 5;
const ll INF = 1e17;
const double eps = 1e-12 , PI = acos(-1);

int n , k , q;

int ans[N];

void solve(int cs){
    scanf("%d %d %d" , &n , &k , &q);

    for(int i = 0 ; i < q ; i ++){
        int x;
        scanf("%d" , &x);
        ans[x] ++;
    }

    for(int i = 1 ; i <= n ; i ++){
        if(k - q + ans[i] > 0){
            printf("Yes\n");
        }
        else {
            printf("No\n");
        }
    }

}

main(){
    int t = 1;
    //8scanf("%d" , &t);

    for(int cs = 1 ; t -- ; cs ++){
        solve(cs);
    }

    return 0;
}



Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <math.h>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <functional>
#include <assert.h>
#define int long
#define ll long long
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define SZ(x) x.size()
#define fi first
#define se second
const int INF = 1e9;
using namespace std;

template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;

using pi=pair<int,int>;
using vi=vc<int>;

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(20);

    int A; cin >> A;
    if(A%2==1) cout << 0 << endl;
    else {
        int N=A;
        int cnt=0;
        while(N>0){
            cnt+=N/5/2;
            N/=5;
        }
        cout << cnt << endl;
    }
}

Measured memory_bytes: 256
//includes
#include<iostream>
#include<vector>
#include<set>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<string>
#include<stack>
#include<map>
#include<queue>
#include<iomanip>
#include<numeric>
#include<assert.h>
#include<cstring>
#include<unordered_map>
#include<bitset>

//macros and consts
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define all(a) (a).begin(),(a).end()
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define FORE(i,a) for(auto &i : a)
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define accm accumulate
#define Fi first
#define Se second
#define INF 1e9
#define llINF (1LL<<60)
#define mINF -1e9
#define mllINF -(1LL<<60)
#define endl "\n"
#define CONT continue
#define BRK break
#define modulo(n, m) (((n)%(m)+(m))%m)

//shorter types
using namespace std;
using ll = long long;
using vi = std::vector<int>;
using vc = std::vector<char>;
using vll = std::vector<long long>;
using vs = std::vector<string>;
using Mi = map<int,int>;
using Mll = map<ll,ll>;
using UMi = unordered_map<int,int>;
using UMll = unordered_map<ll,ll>;
using Pi = pair<int,int>;
using Pll = pair<ll,ll>;
using vPi = vector<Pi>;
using vPll = vector<Pll>;
using vvi = vector<vector<int>>;
using vvll = vector<vector<ll>>;
using vvc = vector<vector<char>>;
using vvs = vector<vector<string>>;
using pqgi = priority_queue<int,vector<int>,greater<int>>;
using pqsi = priority_queue<int,vector<int>,less<int>>;
using pqgll = priority_queue<int,vector<int>,greater<int>>;
using pssll = priority_queue<int,vector<int>,less<int>>;
template<class T>
using vec = vector<T>;

//here begins your code
signed main(){
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  int X;
  cin >> X;

  int mod = X % 100;
  int remainder0 = X / 100;

  int needed = mod / 5;
  int remainder1 = mod % 5;

  if(remainder1 == 0){
  	if(remainder0 >= needed){
  		cout << 1 << endl;
  	}
  	else{
  		cout << 0 << endl;
  	}
  }
  else{
  	if(remainder0 >= needed + 1){
  		cout << 1 << endl;
  	}
  	else{
  		cout << 0 << endl;
  	}
  }

  //check types
  //do not eb if you resize
  //resize before you access by idx
  return 0;
} 

Measured memory_bytes: 888
#include<stdio.h>

main(){
  int H,W;
  int i,j;
  for(;;){
    scanf("%d %d",&H,&W);
    if(H==0 && W==0) break;
    for(i=0;i<H;i++){
      for(j=0;j<W;j++){
        if((i+j)%2!=0){
          printf(".");
        }else{
          printf("#");
        }
      }
      printf("\n");
    }
    printf("\n");
  }
}



Measured memory_bytes: 2120
#include <cstdio>
#define ll long long
using namespace std;

ll f[55], p[55];

ll F(ll n, ll x) {
	if (n == 0) return 1;
	if (x == 1) return 0;
	if (x > 1 && x <= f[n-1] + 1) return F(n - 1, x - 1);
	if (x == 2 + f[n-1]) return p[n-1] + 1;
	if (2 + f[n-1] < x && x <= 2 + 2 * f[n-1]) return p[n-1] + 1 + F(n - 1, x - 2 - f[n-1]);
	if (x == f[n-1] * 2 + 3) return 2 * p[n-1] + 1;
}

int main() {
	f[0] = p[0] = 1;
	for (int i = 1; i <= 50; i++) {
		f[i] = 2 * f[i-1] + 3;
		p[i] = 2 * p[i-1] + 1;
	}
	ll n; ll x;
	scanf("%lld%lld", &n, &x);
	printf("%lld\n", F(n, x));
	return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <cstring>
#include <utility>
#include <iostream>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#define rep(i, s, g) for ((i) = (s); (i) < (g); ++(i))
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = (1e18) + 1;

int main(void)
{
    int a, b;

    cin >> a >> b;

    if (a > 9 || b > 9)
    {
        cout << -1 << endl;
    }
    else
    {
        cout << a * b << endl;
    }
}

Measured memory_bytes: 256
H,W = list(map(int,input().split()))
def atoi(a):
    alphabet = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o',
                'p','q','r','s','t','u','v','w','x','y','z']
    return alphabet.index(a)
a_list = [0 for i in range(26)]

for i in range(H):
    S=input()
    for a in range(len(S)):
        a_list[atoi(S[a])]+=1

if H%2==0 and W%2==0:
    flg=True
    for a in a_list:
        if a%4!=0:
            flg=False
            break
    if flg:
        print("Yes")
    else:
        print("No")
elif H%2==1 and W%2==0:
    w=W//2
    count=0
    flg=True
    for a in a_list:
        if a%4==1 or a%4==3:
            flg=False
            break
        elif a%4==2:
            count+=1
        if count>w:
            flg=False
            break
    if flg:
        print("Yes")
    else:
        print("No")
elif H%2==0 and W%2==1:
    h=H//2
    count=0
    flg=True
    for a in a_list:
        if a%4==1 or a%4==3:
            flg=False
            break
        elif a%4==2:
            count+=1
        if count>h:
            flg=False
            break
    if flg:
        print("Yes")
    else:
        print("No")
else:
    h=H//2
    w=W//2
    count1=0
    count2=0
    flg=True
    for a in a_list:
        if a%4==1 or a%4==3:
            count1+=1
        elif a%4==2:
            count2+=1
        if count2>h+w or count1>1:
            flg=False
            break
    if flg:
        print("Yes")
    else:
        print("No")
    

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
#define drep(i,n) for(int i = (n)-1; i >= 0; i--)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
const long long mod = 1e9 + 7;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int a, b, h; cin >> a >> b >> h;
    cout << (a + b) * h / 2 << endl;

    return 0;
}

Measured memory_bytes: 256
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")
    };
}

fn main() {
    input! {
        a:[[i32;3];3],
        n:usize,
        b:[i32;n],
    }
    let mut a = a;
    for x in b {
        for i in 0..3 {
            for j in 0..3 {
                if a[i][j] == x {
                    a[i][j] = 0;
                }
            }
        }
    }
    for l in &a {
        if l.iter().fold(0, |s, x| s + x) == 0 {
            println!("Yes");
            return;
        }
    }
    for i in 0..3 {
        let mut s = 0;
        for j in 0..3 {
            s += a[j][i];
        }
        if s == 0 {
            println!("Yes");
            return;
        }
    }
    if a[0][0] + a[1][1] + a[2][2] == 0 || a[0][2] + a[1][1] + a[2][0] == 0 {
        println!("Yes");
        return;
    }
    println!("No");
}

// fn read<T: std::str::FromStr>() -> T {
//     let mut s = String::new();
//     std::io::stdin().read_line(&mut s).unwrap();
//     s.trim().parse().ok().unwrap()
// }

// fn read_vec<T: std::str::FromStr>(n: usize) -> Vec<T> {
//     (0..n).map(|_| read()).collect::<Vec<_>>()
// }


Measured memory_bytes: 4352
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<cstring>
#include<map>
#include<vector>
#include<queue>
#include<climits>
#include<set>
#include<utility>
using namespace std;
typedef long long int ll;
const ll MOD=1e9+7;

int main(){

  int x, ans=1;
  cin >> x;
  for(int i=1; i<=1000; i++){
    for(int j=2; j<16; j++){
      if(pow(i, j)<=x && ans<=pow(i, j)){
        ans=pow(i, j);
      }
    }
  }
  cout << ans << endl;

	return 0;
}


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

int main()
{
	int N, M, A[100];

	cin >> N >> M;
	int total = 0;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
		total += A[i];
	}

	int nselect = 0;
	double threshold = total / (4.0 * M);
	for (int i = 0; i < N; i++) {
		if (A[i] >= threshold)
			nselect++;
	}
	if (nselect >= M)
		printf("Yes\n");
	else
		printf("No\n");
}


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


using namespace std;


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


  vector< vector<int> > a;
  for(int i=0;i<n;i++){
    int u;
    int k;
    cin >> u >> k;
    vector<int> tmpa;
    for(int j=0;j<k;j++){
      int tmp;
      cin >> tmp;
      tmpa.push_back(tmp);
    }

    a.push_back(tmpa);
  }

  
  
  int a2[n][n];

  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      a2[i][j]=0;
    }
  }
  
  for(int i=0;i<n;i++){
    for(int j=0;j<(int)a[i].size();j++){
      a2[i][a[i][j]-1] = 1;
    }
  }

  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      if(j!=0)cout << " ";
      cout << a2[i][j];
    }
    cout << endl;
  }
      
  
}

Measured memory_bytes: 1260
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

using Weight = int;
using Flow = int;
struct Edge {
	int s, d; Weight w; Flow c;
	Edge() {};
	Edge(int s, int d, Weight w = 1) : s(s), d(d), w(w), c(w) {};
};
bool operator<(const Edge &e1, const Edge &e2) { return e1.w < e2.w; }
bool operator>(const Edge &e1, const Edge &e2) { return e2 < e1; }
inline ostream &operator<<(ostream &os, const Edge &e) { return (os << '(' << e.s << ", " << e.d << ", " << e.w << ')'); }

using Edges = vector<Edge>;
using Graph = vector<Edges>;
using Array = vector<Weight>;
using Matrix = vector<Array>;

void addArc(Graph &g, int s, int d, Weight w = 1) {
	g[s].emplace_back(s, d, w);
}
void addEdge(Graph &g, int a, int b, Weight w = 1) {
	addArc(g, a, b, w);
	addArc(g, b, a, w);
}

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

	auto dijkstra = [&](const Graph &g, int s, Array &dist) {
		int n = g.size();
		vector<bool> vis(n);
		vector<int> prev(n, -1);
		dist.assign(n, INF);
		dist[s] = 0;
		using State = tuple<Weight, int, int>; // (???????????¢, ???, ???)
		priority_queue<State, vector<State>, greater<State>> pq;
		pq.emplace(0, s, -1);
		while (pq.size()) {
			Weight d; int v, p; tie(d, v, p) = pq.top(); pq.pop();
			if (dist[v] < d)continue;
			vis[v] = true;
			prev[v] = p;
			for (auto &e : g[v]) {
				if (vis[e.d])continue;
				if (dist[e.d] > dist[v] + e.w) {
					dist[e.d] = dist[v] + e.w;
					pq.emplace(dist[e.d], e.d, v);
				}
			}
		}
		return prev;
	};

	int V, E, r; cin >> V >> E >> r;
	Graph g(V);
	rep(i, 0, E) {
		int s, t, d; cin >> s >> t >> d;
		addArc(g, s, t, d);
	}
	Array dist;
	dijkstra(g, r, dist);
	rep(i, 0, V) {
		if (dist[i] == INF)
			cout << "INF" << endl;
		else
			cout << dist[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 18956
#include <bits/stdc++.h>
#define X first
#define Y second
using namespace std;

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

int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("cowland.out", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n;
    cin >> n;
    cout << (1000 - n % 1000) % 1000;

    return 0;
}


Measured memory_bytes: 3676
#include <stdio.h>
int main(void){
    int n,i,j,min,x;
    int data[1000];
    for(;;){
        scanf("%d",&n);
        if(n==0) break;
        for(i=0;i<n;i++) scanf("%d",&data[i]);
        min=abs(data[0]-data[1]);
        for(i=0;i<n-1;i++){
            for(j=i;j<n;j++){
                if(i!=j){
                    x=abs(data[i]-data[j]);
                    if(x<min) min=x;
                }
            }
        }
        printf("%d\n",min);
    }
    return 0;
}



Measured memory_bytes: 2028