akhauriyash/Code-Regression huggingface dataset:
n, m = map(int, input().split())
N = [list(map(int, input().split())) for _ in range(n)]
M = [list(map(int, input().split())) for _ in range(m)]


for i in range(n):
    ans = 0
    d = 9999999999999999999999
    for j in range(m):
        tmp = abs(N[i][0]-M[j][0]) + abs(N[i][1]-M[j][1])
        if tmp < d:
            d = tmp
            ans = j
    print(ans+1)

Measured memory_bytes: 67432
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1e9
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; }
 
int main(void) {
    int a;
    string s;
    cin>>a>>s;
    if(a>=3200) cout<<s<<endl;
    else cout<<"red"<<endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

#ifdef _DEBUG
#define DMP(x) cerr << #x << ": " << x << "\n"
#else
#define DMP(x) ((void)0)
#endif

const int MOD = 1000000007, INF = 1111111111;
using namespace std;
typedef long long lint;

int main() {

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

	int N, K;
	cin >> N >> K;

	string S;
	cin >> S;

	S[K - 1] += 'a' - 'A';

	cout << S << "\n";

	return 0;
}


Measured memory_bytes: 256
//
//$$$$$$$$$$$$$$$$$$$$$$
//$$                  $$
//$$   gyoubu_oniwa   $$
//$$                  $$
//$$$$$$$$$$$$$$$$$$$$$$
//
#include<bits/stdc++.h>
using namespace std;
#define DBG(a) cout<<#a<<':'<<a<<endl;
#define PB push_back
#define EB emplace_back
#define btoe(v) (v).begin(),(v).end()
#define F first
#define S second
#define L length()
#define SZ size()
#define pow(a,b) (pow(a,b)+0.5)

typedef unsigned long long int ulli;
typedef long long int lli;
typedef long double ldbl;
#define f(i,a,b) for(int i=(a); i<(b); ++i)
#define fr(i,a,b) for(int i=(a); i>(b); --i)
#define fl(i,a,b) for(lli i=(a); i<(b); ++i)
#define flr(i,a,b) for(lli i=(a); i>(b); --i)
#define w(x) lli x; cin>>x; while(x--) 
#define inpn(n,v,T) T n; cin>>n; vector<T> v(n); fl(i,0,n) cin>>v[i];
#define inp(n,v,T) vector<T> v(n); fl(i,0,n) cin>>v[i];

typedef pair<int,int> pii;typedef vector<int> vi;typedef vector<vi> vvi;typedef vector<pii> vpii;typedef vector<vector<pii>> vvpii;typedef pair<lli,lli> plli;typedef vector<lli> vlli;typedef vector<vlli> vvlli;typedef vector<plli> vplli;typedef vector<vector<plli>> vvplli;typedef vector<bool> vb;typedef vector<string> vs;typedef vector<vector<string>> vvs;

#define unmp unordered_map

#define PRIME ((lli)(1e9+7ll))
#define PRIME2 (998244353ll)
const lli TEN_18 = 1e18;
const lli TEN_9 = 1e9;
const lli TEN_5 = 1e5;

inline void debugORfast(int a=1,int b=1){
    if(a){
        #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
        #endif
    }
    if(b){ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
}}

template<typename T>
void print(const T &v, int begin=-1, int end=-1, int w=2)
{
	if(begin==-1) fl(i,0,v.SZ) cout<<setw(w)<<v[i]<<' ';
	else if(end==-1) fl(i,begin,v.SZ) cout<<setw(w)<<v[i]<<' ';
	else fl(i,begin,end) cout<<setw(w)<<v[i]<<' ';
	cout<<endl;
}

template<typename T>
void printr(const T &v, int begin=-1, int end=-1, int w=2)
{
	if(begin==-1) flr(i,v.SZ-1,-1) cout<<setw(w)<<v[i]<<' ';
	else if(end==-1) flr(i,begin,-1) cout<<setw(w)<<v[i]<<' ';
	else flr(i,begin,end) cout<<setw(w)<<v[i]<<' ';
    cout<<endl;
}

void pans(char v){
	switch(v){
		case 'y' : cout<<"yes"<<endl; break;
		case 'n' : cout<<"no"<<endl; break;
		case 't' : cout<<"True"<<endl; break;
		case 'f' : cout<<"False"<<endl; break;
		case 'Y' : cout<<"YES"<<endl; break;
		case 'N' : cout<<"NO"<<endl; break;
	}
}


lli tmp1,tmp2;

int main()
{
	debugORfast(0,1);
	const int DBGDO=100;
	//w(ttt)
	{
		inp(5,v,lli);
		f(i,0,5) if(v[i]==0) cout<<i+1<<endl;
	}

	return 0;
}


Measured memory_bytes: 3656
//#include <GOD>

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

typedef long long ll;
#define si size()
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define E end()
#define B begin()
#define pi pair<int, int>
#define en cout << endl
#define cn const
#define fast_io ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

cn int maxn = 3 * 1e3 + 10;
int dp[maxn][maxn];
pi par[maxn][maxn];

int main(){
	fast_io;
	string s, t;
	cin >> s >> t;
	
	memset(dp, 0, sizeof(dp));
	if(s[0] == t[0]){
		dp[0][0] = 1;
	}
	par[0][0] = mp(-1, -1);
	for(int i = 1; i < s.si; i ++){
		if(s[i] == t[0]){
			dp[i][0] = 1;
			par[i][0] = mp(-1, -1);
		}else{
			dp[i][0] = dp[i - 1][0];
			par[i][0] = mp(i - 1, 0);
		}
	}
	for(int i = 1; i < t.si; i ++){
		if(s[0] == t[i]){
			dp[0][i] = 1;
			par[0][i] = mp(-1, -1);
		}else{
			dp[0][i] = dp[0][i - 1];
			par[0][i] = mp(0, i - 1);
		}
	}
		
	for(int i = 1; i < s.si; i ++){
		for(int j = 1; j < t.si; j ++){
			if(s[i] == t[j]){
				dp[i][j] = dp[i - 1][j - 1] + 1;
				par[i][j] = mp(i - 1, j - 1);	
			}else{
				if(dp[i - 1][j] > dp[i][j - 1]){
					par[i][j] = mp(i - 1, j);
				}else{
					par[i][j] = mp(i, j - 1);
				}
				dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
			}
		}
	}
	
//	cout << dp[s.si - 1][t.si - 1];
//	en;
	
	string ans;
	int x = s.si - 1, y = t.si - 1;
	while(par[x][y] != mp(-1, -1)){
		if(s[x] == t[y]){
			ans += s[x];
		}
		int i = par[x][y].F;
		int j = par[x][y].S;
		x = i;
		y = j;
	}
	if(s[x] == t[y]){
		ans += s[x];
	}
	
	reverse(ans.begin(), ans.end());
	cout << ans;
	
	return 0;
}


Measured memory_bytes: 106496
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>

#include <algorithm>
#include <numeric>
#include <cmath>

using namespace std;
typedef long long ll;
const long double PI = (acos(-1));
const long long MOD = 1000000007;
#define rep(i,n) REP(i,0,n)
#define REP(i,x,n) for(int i=x;i<n;++i)

///////////////////////////////////////////////////
// -------------------- I/O -------------------- //
///////////////////////////////////////////////////
// https://stackoverflow.com/questions/610245/where-and-why-do-i-have-to-put-the-template-and-typename-keywords
template<typename T> void outputVec(const std::vector<T>& vec, const int precision = 0) {
	if (precision > 0) std::cout << std::fixed << std::setprecision(precision);
	for (auto it = vec.begin(); it != vec.end() - 1; ++it) { std::cout << *it << " "; }
	std::cout << *(vec.end() - 1) << "\n";
}
template<typename T> void outputVal(const T& res, const int precision = 0) {
	if (precision > 0) std::cout << std::fixed << std::setprecision(precision);
	std::cout << res << "\n";
}
template<typename T> T inputVal() { T a; std::cin >> a; return a; }
template<typename T> std::vector<T> inputVec(T N) {
	std::vector<T> vec(N);
	for (auto it = vec.begin(); it != vec.end(); ++it) { std::cin >> *it; }
	return vec;
}
template<typename T> void inputVec(std::vector<T>& vec) {
	for (auto it = vec.begin(); it != vec.end(); ++it) { std::cin >> *it; }
}

///////////////////////////////////////////////////
// ------------------- utils ------------------- //
///////////////////////////////////////////////////
// change min/max
template<class T> inline bool chMin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chMax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

///////////////////////////////////////////////////
// ------------------- main -------------------- //
///////////////////////////////////////////////////
void Main() {
	const int K = inputVal<int>();
	const int X = inputVal<int>();

	int left  = -1000000;
	int right = 1000000;

	int start = std::max(X - (K - 1), left);
	int end   = std::min(X + (K - 1), right);

	for (int i = start; i < end; ++i) {
		std::cout << i << " ";
	}
	std::cout << end;

}

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	std::cout << std::fixed << std::setprecision(15);
	Main();

	return 0;
}


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

mt19937 mt(time(nullptr));
// uniform_int_distribution< int > rand_int(0, 10) // rand[0, 10] inclusive

int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed;
  ll n, m;
  cin >> n >> m;
  ll nfact = 1, mfact = 1;
  ll mod = 1e9+7;
  for (ll i=1; i<=n; ++i) {
    nfact *= i;
    nfact %= mod;
  }
  for (ll i=1; i<=m; ++i) {
    mfact *= i;
    mfact %= mod;
  }
  if (n==m) cout << nfact * mfact * 2 % mod << endl;
  else if (abs(n-m) == 1) cout << nfact * mfact % mod << endl;
  else cout << 0 << endl;
  return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        //n は 3 以上 100　以下とします。
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        while(true) {
            String line = br.readLine();
            String[] line2 = line.split(" ");
            int i1=Integer.parseInt(line2[0]);
            int i2=Integer.parseInt(line2[1]);
            if(i1==0 && i2==0)break;
            System.out.println(combination(Integer.parseInt(line2[0]),Integer.parseInt(line2[1]) ) );
        }
    }
    static int combination(int a,int b) {
        int count=0;
        for(int i=a;i>=1;i--)
            for(int j=i-1;j>=1;j--)
                for(int k=j-1;k>=1;k--) 
                    if(i+j+k==b)count++;
        return count;
    }
}

Measured memory_bytes: 18608
#include <stdio.h>

int main(){

  int m,f,r,sum;
  for(;;){
    scanf("%d%d%d",&m,&f,&r);
  
    sum=m+f;
 
    if(m==-1&&f==-1&&r==-1){break;}
    else if(m==-1||f==-1)    {printf("F\n");}
    else if(sum<=100&&sum>=80) {printf("A\n");}
    else if(sum>=65&&sum<80) {printf("B\n");}
    else if(sum>=50&&sum<65) {printf("C\n");}
    else if(sum>=30&&sum<50) {                             
      if(r>=50)           {printf("C\n");}
      else  printf("D\n");}
    else {printf("F\n");}
  
  }

  return 0;
}

Measured memory_bytes: 584
from collections import deque

H, W = map(int, input().split())
grid = [input() for i in range(H)]

# 初期の黒('#')の位置からの距離
dist = [[-1]*W for _ in range(H)]

# '#'の位置をキューに追加（＝今回はこれが複数あるので、複数スタートとなる）
black_cells = deque()
for h in range(H):
    for w in range(W):
        if grid[h][w] == '#':
            black_cells.append((h, w))
            dist[h][w] = 0

def bfs(black_cells, dist):
    d = 0
    while black_cells:
        # キューとして使うのでpop()ではなくpopleft()
        h, w = black_cells.popleft()  # 黒いセルの座標
        d = dist[h][w]
        for dy, dx in ((1, 0), (0, 1), (-1, 0), (0, -1)):
            new_h = h + dy
            new_w = w + dx
            if new_h < 0 or H <= new_h or new_w < 0 or W <= new_w:
                continue
            if dist[new_h][new_w] == -1:  # セルが白('.')であるのと同義
                dist[new_h][new_w] = d+1
                black_cells.append((new_h, new_w))
    return d

d = bfs(black_cells, dist)
print(d)

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

int check(int A[],int N){
for(int i = 0;i<N-1;i++){
	if(A[i] > A[i+1]) return 0;
}
return 1;
}

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

for(int i=0;i<N-1;i++){
	if(H[i] > H[i+1]) H[i+1]++;
	}
	
	if(check(H,N)) printf("Yes");
	else printf("No");
	
	return 0;
}


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

//template
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll;
const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12;
void tostr(ll x,string& res){while(x)res+=('0'+(x%10)),x/=10; reverse(ALL(res)); return;}
template<class T> inline bool chmax(T& a,T b){ if(a<b){a=b;return 1;}return 0; }
template<class T> inline bool chmin(T& a,T b){ if(a>b){a=b;return 1;}return 0; }
//template end



int main(){
   int n; scanf("%d",&n);
   vector<int> lb(n+1,0),rb(n+1,0);
   rep(i,0,n)scanf("%d%d",&lb[i],&rb[i]);
   sort(ALL(lb)); sort(ALL(rb)); reverse(ALL(lb));
   ll ans=0;
   rep(i,0,n+1)ans+=2*max(0,lb[i]-rb[i]);
   printf("%lld\n",ans);
   return 0;
}

Measured memory_bytes: 1024
n = gets.to_i

minv = gets.to_i
r = gets.to_i
maxv = r - minv
minv = r if minv > r

(n - 2).times do
	r = gets.to_i
	maxv = r - minv if maxv < r - minv
	minv = r if minv > r
end

puts maxv

Measured memory_bytes: 8800
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()   //reverse
#define strall(v) (v).cbegin(),(v).cend() //const_itterator
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}
const int INF = 1e8;
int MOD = 1e9+7;
int main() {
  long long N, K;
    cin >> N >> K;
    long long res = 0;
    for (long long k = K; k <= N+1; ++k) {
        long long first = k * (k-1) / 2;
        long long final = (N*2-k+1) * k / 2;
        long long add = final - first + 1;
        res = (res + add) % MOD;
    }
    cout << res << endl;
}

Measured memory_bytes: 3672
#include<math.h>
#include<limits.h>
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<sstream>
#include<list>
#include<queue>
#include <algorithm>
#include<initializer_list>
#include<map>
#include<set>
using namespace std;

int main() {
	int h, w;
	cin >> h >> w;
	vector<string> s(h);
	for (int i = 0; i < h; i++) {
		cin >> s[i];
		for (int j = 0; j < w; j++) {
			if (s[i][j] == '.') {
				s[i][j] = '0';
			}
		}
	}
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if (s[i][j] == '#') {
				for (int r = max(0, i - 1); r < min(h, i + 2); r++) {
					for (int c = max(0, j - 1); c < min(w, j + 2); c++) {
						if (r != i || c != j) {
							if (s[r][c] != '#') s[r][c] = (char)((int)s[r][c] + 1);
						}
					}
				}
			}
		}
	}
	for (int i = 0; i < h; i++)cout << s[i] << endl;
	return 0;
}





Measured memory_bytes: 256
#include <stdio.h>

int partition(int *, int, int);

int main(){
  int A[100000];
  int n, i, x;

  scanf("%d", &n);

  for(i = 0; i < n; i++){
    scanf("%d", &A[i]);
  }

  x = partition(A, 0, n - 1);

  for(i = 0; i < n; i++){
    if(i != x)      printf("%d", A[i]);
    else if(i == x) printf("[%d]", A[i]);

    if(i < n - 1) printf(" ");
    else printf("\n");
  }

  return 0;
}


int partition(int *A, int p, int r){
  int x;
  int i, j, k;
  int temp;

  x = A[r];
  i = p - 1;

  for(j = p; j < r; j++){
    if(A[j] <= x){
      i++;
      
      temp = A[i];
      A[i] = A[j];
      A[j] = temp;
    }
  }

  temp = A[i + 1];
  A[i + 1] = A[r];
  A[r] = temp;


  return i+1;
  
}



Measured memory_bytes: 2108
N = int(input())
for i in range(N):
    S = str(input())
    bit = bin(int(S, 16))[2:].zfill(32)

    bit = bit[::-1]
    # print(bit)
    pos = (-1)**int(bit[31])
    up = int(bit[7:31][::-1], 2)
# print(bit[7:31],len(bit[7:31]), int(bit[7:31], 2))
    # print(bit[:7],len(bit[:7]))

    # print(up)
    low = 0
    pow = 0.5
    for b in bit[:7][::-1]:
        # print(pow*int(b))
        low = low + pow*int(b)
        # print(int(b))
        pow *= 0.5
    # print(low)

    print(pos*(up+low))



Measured memory_bytes: 5632
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();
		int[] monsters = new int[n];
		for (int i = 0; i < n; i++) {
			monsters[i] = sc.nextInt();
		}
		Arrays.sort(monsters);
		
		long left = 0;
		long right = 1000000000;
		
		long m = 0;
		while(right-left > 1) {
			m = (right + left) / 2;
			if(check(monsters, a, b, m)) {
				right = m;
			} else {
				left = m;
			}
		}
		System.out.println(right);
	}
	
	private static boolean check(int[] mon, long max, long ave, long m) {
		
		long num = m;
		long add = max-ave;
		for(int i = 0; i<mon.length && num >= 0;i++) {
			long hp = mon[i] - ave*m;
			if(hp > 0) {
				long minus = (hp+add-1)/add;
				num -= minus;
			}
		}
		
		return num >= 0;
	}
}

Measured memory_bytes: 50884
import java.io.*;
import java.util.*;

public class Main {

	public static void main(String[] args) {
        FastScanner in = new FastScanner();
        PrintWriter out = new PrintWriter(System.out);
        long a = in.nextInt() , b = in.nextInt() , c = in.nextInt() , d = in.nextInt();
        out.println(Math.max(Math.max(a*c, a*d), Math.max(b*c, b*d)));
        out.flush();
	}
	
	static class FastScanner {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer("");
		
		String next() {
			while(!st.hasMoreTokens())
				try {
					st = new StringTokenizer(br.readLine());
				}catch(IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		
		int nextInt() {
			return Integer.parseInt(next());
		}
		
		long nextLong() {
			return Long.parseLong(next());
		}
		
		int[] readArray(int n) {
			int a[] = new int[n];
			for(int i=0;i<n;i++) a[i] = nextInt();
			return a;
		}
		
		Integer[] readArray(long n) {
		    Integer a[] = new Integer[(int)n];
			for(int i=0;i<n;i++) a[i] = nextInt();
			return a;
		}
		
		long[] readArray(int n,long x) {
			long a[] = new long[n];
			for(int i=0;i<n;i++) a[i] = nextLong();
			return a;
		}
		
	}
	
	static class Pair implements Comparable<Pair> {
		int x, y;
		Pair(int a, int b){ x = a; y = b; }
		int getKey() { return x; }
		int getVal() { return y; }
		@Override
		public int compareTo(Pair o) {
			if(o.getVal() - this.getVal()>0)
				return -1;
			else if(o.getVal() - this.getVal()<0)
				return 1;
			else 
				return 0;
		}
		
	}
	
	static boolean arrayEquals(char a[], char b[]) {
		int n = a.length;
		boolean verdict = true;
		for(int i=0;i<n;i++) {
			if(a[i]!=b[i]) {
				verdict = false;break;
			}
		}
		return verdict;
	}
	
	static long lcm(long a, long b) {
		return (a*b)/gcd(a,b);
	}
	
	static long gcd(long a, long b) {
		if(b==0) return a;
		else return gcd(b,a%b);
	}
	
	static long hashInt(int x,int y) {
		return x*(1_000_000_000L)+y;
	}
}



Measured memory_bytes: 32964
a,b,c,d,e,f = gets.chomp.split(" ").map(&:to_i)
ans = []
tmp = 0
for i in 0..f/(100*a)
  for j in 0..(f-100*a)/(100*b)
    for k in 0..((a*i+b*j)*e)/c
      if f < (a*i+b*j)*100+c*k
        next
      end
      for l in 0..((a*i+b*j)*e-c*k)/d
        if f >= (a*i+b*j)*100+(c*k+d*l) && tmp <= (c*k+d*l).to_f/((a*i+b*j)*100+(c*k+d*l))
          ans = [i,j,k,l]
          tmp = (c*k+d*l).to_f/((a*i+b*j)*100+(c*k+d*l))
        end
      end
    end
  end
end
puts "#{(a*ans[0]+b*ans[1])*100+(c*ans[2]+d*ans[3])} #{(c*ans[2]+d*ans[3])}"

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

const int N = 85;

int n, m;

int a[N][N];

bool dp[N][N][N * N * 2];

inline bool inbound(int i, int j) {
	return i >= 1 && i <= n && j >= 1 && j <= m;
}

int main(int argc, char const *argv[])
{
	// memset(dp, -1, sizeof dp);
	scanf("%d%d", &n, &m);
	for (int i=1; i<=n; ++i)
		for (int j=1; j<=m; ++j) {
			scanf("%d", &a[i][j]);
		}
	for (int i=1; i<=n; ++i)
		for (int j=1; j<=m; ++j) {
			int x; scanf("%d", &x);
			a[i][j] -= x;
			if (a[i][j] < 0) a[i][j] = -a[i][j];
		}

	dp[1][1][a[1][1]] = 1;
	int lim = N * N * 2;
	for (int i=1; i<=n; ++i) {
		for (int j=1; j<=m; ++j) {
			for (int k=0; k<lim; ++k) {
				if (!dp[i][j][k]) continue;
				// printf("%d %d\n", i, j);
				if (inbound(i+1, j)) {
					dp[i+1][j][k+a[i+1][j]] = dp[i+1][j][abs(k-a[i+1][j])] = 1;
				}
				if (inbound(i, j+1)) {
					dp[i][j+1][k+a[i][j+1]] = dp[i][j+1][abs(k-a[i][j+1])] = 1;
				}
			}
		}
	}

	int ans = lim + 1;
	for (int i=0; i<lim; ++i) if (dp[n][m][i]) {ans = i; break;}
    printf("%d\n", ans);
    return 0;
}



Measured memory_bytes: 96896
K,S = input().strip().split()
K,S = int(K),int(S)

count = 0

for x in range(S+1):
  for y in range(S+1-x):
    z = S - x- y
    #print( x,y,z)
    if x <= K and y <= K and z <= K:
      count += 1
print(count)

Measured memory_bytes: 41068
from itertools import product

N = int(input())
xy = [[] for i in range(N)]

for i in range(N):
    for j in range(int(input())):
        xy[i].append(list(map(int, input().split())))
        
ans = 0
for bit in product([0,1], repeat=N):
    f = 0
    for i, j in enumerate(bit):
        if j == 1:
            for x, y in xy[i]:
                if bit[x-1] != y:
                    f = 1
                    break
    if f == 0:
        ans = max(ans, sum(bit))
print(ans)

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

#define Q int t; scanf("%d", &t); for(int q=1; q<=t; q++)
typedef long long int lli;
typedef pair<lli, lli> pi;

vector<pair<pi, lli> > edges;



int main()
{
    int n;
    cin >> n;
    int a[n+1];

    for(int i=1; i<=n; i++){
        cin >> a[i];
    }
    int gl[n+2], gr[n+2];
    gl[0] = gr[n+1] = 0;
    for(int i=1; i<=n; i++){
        gl[i] = __gcd(a[i], gl[i-1]);
    }
    for(int i=n; i>0; i--){
        gr[i] = __gcd(a[i], gr[i+1]);
    }
    int mx = 0;
    for(int i=1; i<=n; i++){
        mx = max(mx, __gcd(gr[i+1], gl[i-1]));
    }
    cout << mx << "\n";

    return 0;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

#define INF 1<<30
#define LINF 1ll<<60ll
#define MOD 1000000007
#define pb(a) push_back(a)

#define _overload3(_1,_2,_3,_4,name,...) name
#define _rep(i,n) _repi(i,0,n)
#define _repi(i,a,b) for(int i=a, i##_len=(b); i<i##_len; ++i)
#define _repis(i,a,b,s) for(int i=a, i##_len(b); i<i##_len; i+=s)
#define REP(...) _overload3(__VA_ARGS__,_repis,_repi,_rep,)(__VA_ARGS__)

#define REPR(i, n) for(int i = n;i >= 0;--i)
#define REPARR(i, v) for(int i = 0;i < sz(v);++i)

#define all(vec) (vec.begin()),(vec.end())
#define sz(x) ((int)(x).size())
#define bit(n) (1ll<<(n))

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(a>b){a=b;return true;}return false;}

#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define yes(n) cout<<((n)?"yes":"no")<<endl
#define poss(n) cout<<((n)?"possible":"impossible")<<endl
#define Poss(n) cout<<((n)?"Possible":"Impossible")<<endl


int main(){
    int n;
    cin>>n;
    vi a(n);
    REP(i,n){
        cin>>a[i];
    }
    int cnt=0;
    REP(i,n){
        int j=i+1;
        int l_u=0,l_d=0;
        while(a[j-1]<=a[j])j++,l_u++;
        j=i+1;
        while(a[j-1]>=a[j])j++,l_d++;
        //cout<<i<<"-"<<i+l_u<<endl;
        //cout<<i<<"-"<<i+l_d<<endl<<endl;

        i+=max(l_u,l_d);
        cnt++;
    }
    cout<<cnt<<endl;
    return 0;
}


Measured memory_bytes: 640
import java.util.Scanner;
public class Main {
	public static void main(String[]args) {
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int m=sc.nextInt();
		System.out.println(gcd(n,m));
	}
	static int gcd(int a, int b) {
		if(b>0) {
			return gcd(b,a%b);
		}else {
			return a;
		}
		}
}


Measured memory_bytes: 26428
import math

n = int(input())
x = list(map(int, input().split()))

mean1 = math.floor(sum(x)/n)
mean2 = math.ceil(sum(x)/n)

ans1 = 0
ans2 = 0
for i in range(n):
    ans1 += (x[i] - mean1)**2
    ans2 += (x[i] - mean2)**2

print(min(ans1, ans2))

Measured memory_bytes: 3064
def getN():
    return int(input())

def getMN():
    a = input().split()
    b = [int(i) for i in a]
    return b[0],b[1]

def getlist():
    a = input().split()
    b = [int(i) for i in a]
    return b

n,k = getMN()
if n  >= k*2 -1:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 3060
#include<stdio.h>
int main(void)
{
	int a,b,c;
	scanf("%d %d %d",&a,&b,&c);
	if(a < b){
		if(b < c){
			printf("Yes\n");
		}else{
			printf("No\n");
		}
	}else{
			printf("No\n");
	}
	return 0;
}



Measured memory_bytes: 2128
#include<iostream>
#include <cstdio>
#include<algorithm>
using namespace std;

int Print(int a[], int p){
    for(int i=0;i<p;i++){
        if(i>0)printf(" ");
        printf("%d",a[i]);
    }
	printf("\n");
}

int main(){
    int n;
    int a[100];
    cin >> n ;
    for(int i=0;i<n;i++)cin >> a[i] ;
    int count = 0 ;
    
    int flag= 1;
    while(flag){
        flag = 0;
        for(int j=n-1;j>0;j--){
            if(a[j]<a[j-1]){
                int tmp = a[j-1];
                a[j-1] = a[j];
                a[j] = tmp ;
                count++;
                flag = 1;
            }
        }
    }
    
    Print(a,n) ;
    cout << count << endl;

    return 0 ;
}



Measured memory_bytes: 3244
#include <iostream>
#include <string.h>

using namespace std;
int main() {
	int h=1, w=1;
	while (h != 0 && w != 0) {
		cin >> h;
		cin >> w;
		if (h == 0 && w == 0) continue;
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				if (i % 2 == 0 ) {
					if (j % 2 == 0) cout << "#";
					if (j % 2 == 1)cout << ".";
				}
				else {
					if (j % 2 == 0) cout << ".";
					if (j % 2 == 1)cout << "#";
				}
				
			}
			cout << endl;
		}
		cout << endl;
	}
	return 0;
}

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

int main(){
  int k,s; cin>>k >>s;
  int count=0;
  for(int h=0;h<=k;h++){
    for(int i=0;i<=k;i++){
      int z=s-h-i;
      if(z>=0&&z<=k)count++;
    }
  }
  cout<<count<<endl;
}

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

#define rep(i,a) for(int i = 0 ; i < a ; i ++)
#define loop(i,a,b) for(int i = a ; i < b ; i ++)
#define vi vector<int>
#define vs vector<string>
#define pb push_back
using namespace std;

int main(void){
  int x,a,b;
  cin>>x>>a>>b;
  if(b<=a){
    cout<<"delicious"<<endl;
  }else if(b <= a + x){
    cout<<"safe"<<endl;
  }else {
    cout<<"dangerous"<<endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#define mod 1000000007
using namespace std;

long int dp[1000][1000];

void num_paths(int H,int W){
	
	dp[0][0] = 1;
	for(int row = 0 ; row < H ; row++){
		for(int col = 0 ; col < W ; col++){
			if(dp[row][col] >= 0){
				if(row > 0 && dp[row-1][col] > 0)
					dp[row][col] += (dp[row-1][col]%mod) ;
				if(col > 0 && dp[row][col-1] > 0)
					dp[row][col] +=  (dp[row][col-1]%mod);
			}
		}
	}
	return;
}


int main(){
	int H,W;
	cin >> H >> W;
	
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			char c;
			cin >> c; 
			if(c == '.') dp[i][j] = 0;
			else dp[i][j] = -1;
			
		}
	}

	num_paths(H,W);
	long int k = 1e9+7;
	long int count = dp[H-1][W-1] % k;

	cout << count << '\n';
	
	// for(int i=0;i<H;i++){
	// 	for(int j=0;j<W;j++){
	// 		cout << dp[i][j]<<' ';
	// 	}
	// 	cout << '\n';
	// }
	return 0;
}

Measured memory_bytes: 11368
#include<iostream>
#include<map>
#include<vector>
#include<cmath>
#include<string>
#include<algorithm> 
using namespace std;
 
# define p(s) std::cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
 
int main()
{
    long long int n,k;cin >> n >> k ;

    map<int,long long int> mp;
    for(int i=0;i<n;i++){
        long long int a,b;cin >> a >> b;
        mp[a]+=b;
    }

    vector<pair<int,long long int>> v;
    for(auto m:mp){
        pair<int,long long int> p;
        p.first = m.first;
        p.second = m.second;
        v.push_back(p);
    }   
    sort(v.begin(),v.end());

    int i=0;
    int ans;
    while(1){
        k -= v[i].second;
        if(k<=0) {
            ans = v[i].first;
            break;
        }
        i++;
    }
    p(ans)
}

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

int main() {
  string S;
  cin>>S;
  long int ans=0;
  int N;
  for(int tmp=0;tmp<(1<<S.size()-1);tmp++){
    bitset<10> sub(tmp);
    long int s=stol(S);
    int i=0;
    ans+=s%10;
    N=1;s/=10;
    while(s){
      if(sub.test(i))N*=10;
      else N=1;
      ans+=(s%10)*N;
      s/=10;
      i++;
    }
  }
  cout <<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using pii = pair<int, int>;

//const ll INF = 1e18L + 5;
//const int INF = 1e9 + 5;
//const double pi = 3.14159265358979323846;

void	string_tolower(string &s)
{
	int n = s.size();
	rep(i, n) {
		s[i] = tolower(s[i]);
	}
}

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

	string w, s;
	int ans = 0;
	cin >> w;
	while (getline(cin , s)) {
		if (s == "END_OF_TEXT")
			break;
		string_tolower(s);
		istringstream iss(s);
		while (iss) {
			string word;
			iss >> word;
			if (word == w)
				ans++;
		}
	}
	cout << ans << endl;
}



Measured memory_bytes: 3220
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Comparator<int[]> comparator = new Comparator<int[]>() {
            @Override
            public int compare(int[] o1, int[] o2) {
                return Double.compare((double)o1[0]/o1[1], (double)o2[0]/o2[1]);
            }
        };
        Scanner sc = new Scanner(System.in);
        int INF = Integer.MAX_VALUE-500000;
        int N = Integer.parseInt(sc.next());
        int Ma = Integer.parseInt(sc.next());
        int Mb = Integer.parseInt(sc.next());
        int[][] dp = new int[401][401];
        for (int i=0;i<dp.length;i++) {
            for (int j=0;j<dp.length;j++) {
                dp[i][j] = INF;
            }
        }
        dp[0][0]=0;
        for (int k=0;k<N;k++) {
            int a = Integer.parseInt(sc.next());
            int b = Integer.parseInt(sc.next());
            int c = Integer.parseInt(sc.next());
            for (int i=400;i>=0;i--) {
                for (int j=400;j>=0;j--) {
                    if (dp[i][j]!=INF) {
                        dp[i+a][j+b]=Math.min(dp[i+a][j+b], dp[i][j]+c);
                    }
                }
            }
        }
        // System.out.println(Arrays.deepToString(dp));
        // System.out.println(Arrays.toString(dp[1]));
        int x = Ma;
        int y = Mb;
        int ans = INF;
        while(x<400 && y<400) {
            ans = Math.min(ans, dp[x][y]);
            x+=Ma;
            y+=Mb;
        }
        if(ans!=INF) System.out.println(ans);
        else System.out.println(-1);
    }
}

Measured memory_bytes: 24836
#!/usr/bin python3
# -*- coding: utf-8 -*-

# 双方向グラフで幅優先探索

from collections import deque

N = int(input())
graph = [[] for _ in range(N)]
#隣接リストの作成
for i in range(N-1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    graph[a].append(b)
    graph[b].append(a)
mx = 0
st = -1
for i, g in enumerate(graph):
    if len(g)>mx:
        st = i
        mx = len(g)
#    print(graph)
c = list(map(int,input().split()))
c.sort(reverse = True)

#幅優先探索
q = deque()
seen = [False]*N
q.append(st)
seen[st] = c[0]
idx = 1
while len(q)>0:
    cur = q.popleft()
    for i in graph[cur]:
        if seen[i]==False:
            seen[i] = c[idx]
            idx += 1
            q.append(i)
print(sum(c[1:]))
print(' '.join(map(str,seen)))

Measured memory_bytes: 12248
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int (i)=0;(i)<(n);i++)
#define INF 1001001001
#define LLINF 1001001001001001001
#define MOD 1000000007
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define ALL(v) v.begin(), v.end()
typedef long long ll;
const ll mod=1000000007;

ll powmod(ll x,ll y){
    ll res=1;
    for(ll i=0;i<y;i++){
        res=res*x%mod;
    }
    return res;
}

int main(){
    int a,b;
    cin >> a >> b;
    if(b%a==0)cout << a + b<< endl;
    else cout << b-a << endl;

    return 0;

}


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

using namespace std;

#define long long long


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

    string s;
    cin >> s;

    for (char ss : s) {
        cout << (char)(((ss - 'A' + n) % 26) + 'A');
    }
    return 0;
}


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);
        Main m = new Main(sc);
        m.show(m.solve());
        sc.close();
    }
    
	//フィールド
    Scanner sc;
    String C1;
    String C2;
    
    //入力
    Main(Scanner sc) {
        this.sc = sc;
        C1 = sc.nextLine();
        C2 = sc.nextLine();
    }
    
    //解答処理
    private String solve() {
        String answer = "NO";
        String c2 = new StringBuilder(C2).reverse().toString();
        
        if (C1.equals(c2)) {
        	answer = "YES";
        }
        
        return answer;
    }
    
    //出力
    public void show(String answer) {
        System.out.println(answer);
    }

}


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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll n,a,b; cin >> n >> a >> b;
  if ((b-a)%2==0) cout << (b-a)/2 << endl;
  else {
    ll ans = min(a-1, n-b) + 1 + (b-a-1)/2;
    cout << ans << endl;
  }
  return 0;
}


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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
long long INF = 1e18;
const int MOD = 1e9 + 7;

using namespace std;

#define MAX_N 40
pair<int,int> Y[MAX_N],ps[1<<(MAX_N/2)];

int inline bs(int begin, int end, int x){
  int left=begin,right=end-1,mid;
  if(x<ps[left].first || x>ps[right].first) return -1;
  while(left<=right){
    mid = (left+right)/2;
    if(x<ps[mid].first) right = mid-1;
    else left = mid+1;
  }
  if(x==ps[right].first) return right;
  else return -1;
}

int main(){
    int ans=MOD,n,ma,mb;

    scanf("%d %d %d",&n,&ma,&mb);
    REP(i,n){
        int a,b;
        scanf("%d %d %d",&a,&b,&Y[i].second);
        Y[i].first = ma*b - mb*a;
    }

    int n2 = n / 2;
    REP(i,1<<n2){
        int s=0,v=0;
        REP(j,n2){
            if(i>>j&1){
                s += Y[j].first;
                v += Y[j].second;
            }
        }
        ps[i] = make_pair(s,v);
    }

    ps[0] = ps[1];
    sort(ps,ps+(1<<n2));
    int m=1;
    FOR(i,1,1<<n2) if(ps[m-1].first != ps[i].first) ps[m++] = ps[i];

    REP(i,1<<(n-n2)){
        int s=0,v=0;
        REP(j,n-n2){
            if(i>>j&1){
                s += Y[n2+j].first;
                v += Y[n2+j].second;
            }
        }
        if(s!=0||v==0){
            if(bs(0,m,-s)!=-1) ans = min(ans,v+ps[bs(0,m,-s)].second);
        }else ans = min(ans,v);
    }

    if(ans!=MOD&&ans!=0) printf("%d\n",ans);
    else printf("-1\n");
    return 0;
}


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

int main() {
    string S;
    cin >> S;

    bool alp[26] = {false};
    for(int i = 0; i < S.size(); ++i) {
        alp[S.at(i)-'a'] = true;
    }
    for(int i = 0; i < 26; ++i) {
        if(!alp[i]) {
           cout << (char)(i + 'a') << endl;
           return 0;
        }
    }
    cout << "None" << endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
typedef long long ll;

int main() {
    const ll MAXX = 1000000000000001;
    ll N;
    cin >> N;
    vector<ll> v;
    v.push_back(26);
    while(v.back() <= MAXX)v.push_back(v.back() * 26);
    rep(i,v.size()-1)v[i+1] += v[i];
    ll len = 0;
    rep(i,v.size()){
        if(N<=v[i]){
            len = i+1;
            if(i >= 1)N -= v[i-1];
            break;
        }
    }
    string ans = "";
    N--;
    for(int i = 1; i <= len; i++){
        ans.push_back(char('a' + N%26));
        N /= 26;
    }
    reverse(all(ans));
    cout << ans << endl;
}

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

using namespace std;

int N;
vector<int> A;
vector<vector<int>> edges;
vector<bool> visited;
vector<int> ans;
vector<int> dp;
const int inf = 1e9 + 10;

void dfs(int v) {
  visited[v] = true;
  int idx = lower_bound(dp.begin(), dp.end(), A[v]) - dp.begin();
  int last = dp[idx];
  dp[idx] = A[v];
  ans[v] = lower_bound(dp.begin(), dp.end(), inf) - dp.begin();
  for (int e : edges[v]) {
    if (visited[e]) continue;
    dfs(e);
  }
  dp[idx] = last;
}

int main() {
  cin >> N;
  A.resize(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  edges.assign(N, vector<int>());
  for (int i = 0; i < N - 1; i++) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    edges[u].push_back(v);
    edges[v].push_back(u);
  }
  visited.resize(N);
  ans.resize(N);
  dp.assign(N, inf);
  dfs(0);
  for (int i = 0; i < N; i++) {
    cout << ans[i] << endl;
  }

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


Measured memory_bytes: 24956
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c=0;
	cin>>a>>b;
	if(a>0&&b>0)//如果相乘得数都为正，则直接输出Positive
   {
	cout<<"Positive";
	return 0;
	}
	else if(a<0&&b<0)/*如果都为负，分相乘的数是积数，则输出Negative，否则输出Positive*/
	{
		c=b-a+1;
		if(c%2!=0)cout<<"Negative";
		else cout<<"Positive";
        return 0;
	}
	else if(a<0||b>0)cout<<"Zero";//如果相乘的数包括零，则输出Zero
	return 0;
}

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

using namespace std;

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

int main() {
    ios_base::sync_with_stdio(0);
    int n;
    cin >> n;
    int k;
    cin >> k;
    int max_cnt = 0;
    for (int i = 0; i < k; i++) {
        int a;
        cin >> a;
        max_cnt = max(max_cnt, a);
    }
    int other = n - max_cnt;
    cout << max(0, max_cnt - other - 1) << endl;
    return 0;
}


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

#define int long long
#define ll long long
#define vll vector<int>
#define mset(a) memset(a,0,sizeof(a))
#define pb push_back
#define range(c) c.begin() , c.end()
#define forn(i,n) for(ll i=0; i<(int)n; ++i)
#define for1(i,n) for(ll i=1; i<(int)n; ++i)
#define endl '\n'
#define MOD 1000000007
#define pii pair<int,int>
#define test ll t;cin>>t;while(t--)
using namespace std;

vector<bool> sieve(ll n){
    vector<bool>prime(n+1,true);
    prime[0]=prime[1]=false;
    for(ll i=2; i<=n; ++i){
        if(prime[i]&&(i*i)<=n)
        for(ll j=i*i; j<=n; j+=i)prime[j]=false;
    }
    return prime;
}

ll power(ll a, ll b, ll m = MOD) {
    a %= m;
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}

//////////////////////////////////////////////////////////////

int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    

    int n;cin>>n;
    int a[n][3];
    forn(i,n) cin>>a[i][0]>>a[i][1]>>a[i][2];

    int dp[n][3];
    mset(dp);
    dp[0][0]=a[0][0];
    dp[0][1]=a[0][1];
    dp[0][2]=a[0][2];

    for1(i,n) {
        dp[i][0] = a[i][0] + max(dp[i-1][1], dp[i-1][2]);
        dp[i][1] = a[i][1] + max(dp[i-1][0], dp[i-1][2]);
        dp[i][2] = a[i][2] + max(dp[i-1][0], dp[i-1][1]);
    }    

    cout<<max({dp[n-1][0], dp[n-1][1], dp[n-1][2]});

    return 0;
}


Measured memory_bytes: 4992
#include<iostream>
#include<string>
using namespace std;
int main(){
	string a;
	int n;
	cin>>n;
	while(n){
		int b[4]={0};
		int ten=0;
		int cint=0;
		while(cint!=3){
			cin>>a;
			if(a=="HIT"){
				for(int i=2;i>=0;i--){
						b[i+1]=b[i];
					}
					b[0]=1;
					if(b[3]==1){
						b[3]=0;
						ten++;
					}
			}
			if(a=="HOMERUN"){
				ten++;
				for(int i=0;i<3;i++){
					if(b[i]==1){
						ten++;
					}
					b[i]=0;
				}
			}
			if(a=="OUT"){
				cint++;
			}
		}
		cout<<ten<<endl;
		n--;
	}
}

Measured memory_bytes: 1208
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
def main(): 
	week = int(input())
	base = 100000
	x = base
	for i in range(week):
		x = round(x * 1.05)
		if x % 1000 > 0:
			x = (x // 1000) *1000 +1000
	print(x)
if __name__ == '__main__':
  main()

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

void trace(int A[], int n)
{
    for(int i = 0; i < n; i++){
        if(i > 0) cout << " ";
        cout << A[i];
    }
    cout << '\n';
}

void insertionSort(int A[], int n)
{
    int key, j;
    for(int i = 1; i < n; i++){
        key = A[i];
        j = i - 1;
        while(j >= 0 && A[j] > key){
            A[j + 1] = A[j];
            j--;
        }
        A[j + 1] = key;
        trace(A, n);
    }
}

int main()
{
    int n;
    int A[100];

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

    trace(A, n);
    insertionSort(A, n);

    return 0;
}

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

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

  vector<int> d(K);
  vector<vector<int>> A(K, vector<int>(N));
  for (int i = 0; i < K; i++) {
    cin >> d.at(i);
    int Z;
    Z = d.at(i);
    for (int j = 0; j < Z; j++) {
      cin >> A.at(i).at(j);
    }
  }
  
  vector<int> vec(N);
  for (int i = 0; i < K; i++) {
    int Z;
    Z = d.at(i);
    for (int j = 0; j < Z; j++) {
      int ZZ;
      ZZ = A.at(i).at(j);
      ZZ=ZZ-1;
      vec.at(ZZ)+=1;
    }
  }
 
  int res=0;
  for (int i = 0; i < N; i++) {
    if (vec.at(i)==0) res+=1;
  }

  cout << res << endl;
  return 0;
  
}

Measured memory_bytes: 3672
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mod = 1e9 + 7;
const int inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;

ll gcd(ll a, ll b) { return (b ? gcd(b, a % b) : a); }
ll lcm(ll a, ll b) { return a / (gcd(a, b)) * b; }

int main()
{
    int a, b;
    cin >> a >> b;
    cout << gcd(a, b) << endl;
}


Measured memory_bytes: 3088
def gcd (a, b)
  s = a < b ? a : b
  l = a < b ? b : a
  if l % s == 0 then
    s
  else
    gcd(s, (l % s))
  end
end

def lcm (a, b)
  a * b / gcd(a, b)
end

A, B, C, D = STDIN.gets.chomp.split(" ").map(&:to_i)

all = ((B / C) + (B / D)) - (B / lcm(C, D))
part = (((A - 1) / C) + ((A - 1) / D)) - ((A - 1) / lcm(C, D))
puts  (B - A + 1) - (all - part)


Measured memory_bytes: 1788
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<cmath>
using namespace std;
 
#define REP(i,n) for(int i=0;(i)<(n);(i)++)
 
int main() {
	int A, B, C, D;
	cin >> A >> B >> C >> D;
	
	int ans;
 
	ans =  min(B, D) - max(A, C);
 
	if (ans < 0) ans = 0;
 
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<vector>
#include<set>
#include<map>
#include<string>

using namespace std;

	pair < long long , long long > dp[3009][3009];
	long long val[3009];
	#define inf 1000000000990
	
int main(){

	long long sum = 0;
	
	int n; cin >> n;
	for(int i = 1; i <= n; i++){
		cin >> val[i];
		sum += val[i];
	}
	
	for(int i = 0; i < 3009; i++){
		for(int j = 0; j < 3009; j++){
			dp[i][j] = make_pair(0,0);
		}
	}
	
	for(int i = 1; i <= n; i++) dp[i][i] = make_pair(((n%2==0)?0:val[i]),((n%2==0)?val[i]:0));
	
	int igrac = ((n%2==0)?0:1);
	for(int d = 1; d <= n; d++){
		
		for(int i = 1, j = d; i<=n && j<=n; j++,i++){
			
			if(j + 1 <= n){
				if(igrac == 0){
					if(dp[i][j].first + val[j+1] > dp[i][j+1].first) dp[i][j+1] = make_pair(dp[i][j].first + val[j+1],dp[i][j].second);
				}	
				else{
					if(dp[i][j].second + val[j+1] > dp[i][j+1].second) dp[i][j+1] = make_pair(dp[i][j].first,dp[i][j].second + val[j+1]);
				}
			} 
			if(i - 1 > 0){
				if(igrac == 0){
					if(dp[i][j].first + val[i-1] > dp[i-1][j].first) dp[i-1][j] = make_pair(dp[i][j].first + val[i-1],dp[i][j].second);
				}	
				else{
					if(dp[i][j].second + val[i-1] > dp[i-1][j].second) dp[i-1][j] = make_pair(dp[i][j].first,dp[i][j].second + val[i-1]);
				}
			}
			
		}
		
		igrac++; igrac%=2;
		
	}
	
	cout << dp[1][n].first - dp[1][n].second << endl;
	
	

	return 0;
}

Measured memory_bytes: 141696
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

typedef long long            ll;
typedef unsigned long long   ull;
typedef vector<int>          vi;
typedef vector<ll>           vl;
typedef pair<int, int>       pi;
typedef pair<ll, ll>         pl;
typedef vector<pi>           vpi;
typedef vector<pl>           vpl;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

#define read        freopen("in.c", "r", stdin)
#define write       freopen("out.c", "w", stdout)
#define all(a)      a.begin(), a.end()
#define bye         exit(0)
#define mp          make_pair
#define ff          first
#define ss          second
#define L(x)        ((x) << 1)
#define R(x)        ((x) << 1 | 1)
#define SZ(a)       (ll)(a).size()
#define pb          push_back
#define eb          emplace_back
#define eps         1e-9
#define inf         (1000000000)
#define infl        (1000000000000000000LL)
#define cs(p)       printf("Case %d:", (p)++)
#define ptc(c)      putchar(c)
#define gtc()       getchar()
#define nl          puts("")
#define sp          printf(" ")
#define out(a)      printf("%lld", (ll)(a))
#define SET(a, x)   memset((a), x, sizeof(a))
#define dbg(x)      cout << "--- " << #x << " = " << (x) << '\n'

ll bgm(ll a, ll b, ll m) {
    b = (b == -1) ? (m - 2) : b;
    a %= m;
    ll rem = 1;
    while(b != 0) {
        if(b&1)
            rem = (rem * a) % m;
        a = (a * a) % m;
        b >>= 1;
    }
    return rem;
}

inline ll in() {
    ll a;
    assert(scanf("%lld", &a) != EOF);
    return a;
}

const int MAX = 1000000 + 5;
const int LEN = 50;
const ll MOD = 1000000007;

int ara[5][4][11];
int b,f,r,v;


int main() {
    //read,write;
    int num;
    cin >> num;
    while(num--){
        cin >> b >> f >> r >> v;
        ara[b][f][r]=max(0,ara[b][f][r]+v);
    }
    for(int i=1;i<=4;i++){
        for(int j=1;j<=3;j++){
            for(int k=1;k<=10;k++){
                cout << " " << ara[i][j][k];
            }
            cout << endl;
            //cout << ara[i][j][10] << endl;
        }
        if(i!=4) cout << "####################" << endl;
    }

    return 0;
}



Measured memory_bytes: 3072
# coding: utf-8
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

S = sr()
K = ir()
S = S[:K]
if len(set(S)) == 1 and S[0] == '1':
    answer = 1
else:
    for s in S:
        if s != '1':
            answer = s
            break

print(answer)


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

struct Block{
    int w, s, v;
    Block(int w, int s, int v) : w(w), s(s), v(v) {}
};

bool operator<(const Block &a, const Block &b){
    return a.w+a.s < b.w+b.s;
}

int main(){
    int N;
    cin >> N;
    vector<Block> B;
    for(int i = 0; i < N; ++i){
        int w, s, v;
        cin >> w >> s >> v;
        B.emplace_back(w,s,v);
    }
    sort(B.begin(),B.end());
    vector<long long> dp(2e4+1,-1);
    dp[0] = 0;
    for(int i = 0; i < N; ++i){
        for(int j = B[i].s; j >= 0; --j){
            if(j + B[i].w > 2e4) continue;
            dp[j+B[i].w] = max(dp[j+B[i].w],dp[j]+B[i].v);
        }
        for(int j = 1; j <= 2e4; ++j)
            dp[j] = max(dp[j],dp[j-1]);
    }
    cout << dp.back() << endl;
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
    int K,T;
    vector<int> a;

    cin >> K >> T;
    for(int i=0;i<T;i++){
        int in;
        cin >> in;
        a.push_back(in);
    }

    sort(a.begin(),a.end());
    reverse(a.begin(),a.end());

    int ans=a.at(0)*2-K-1;

    if(ans<0){
        cout << "0" << endl;
    }else{
        cout << ans << endl;
    }

    return 0;

}

Measured memory_bytes: 256