akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n; i++)

int main(){
  long long n, a;
  priority_queue<long long> nums,t;
  vector<long long> nums_v;
  vector<long long> nums_count(200000,0);
  long long sum=0,ans=0,b=0,now,count=0;;
  cin >> n;
  rep(i,n){
    cin >> a;
    nums_v.push_back(a);
    nums.push(a);
  }
  now = nums.top();
  rep(i,n){
    if(nums.top() == now){
      count++;
    }else{
      nums_count.at(now) = count;
      sum += count*(count-1)/2;
      now = nums.top();
      count = 1;
    }
    nums.pop();
  }
  
  nums_count.at(now) = count;
  sum += count*(count-1)/2;
  
  
  rep(i,n){
    b = nums_count.at(nums_v.at(i));
    if(b != 0){
      ans = sum - b + 1;
    }else{
      ans = sum;
    }
    cout << ans << endl;
  }
}

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

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

 
int main() {
  int N, M;
  cin >> N >> M;
  vector<LL> A(N+1,1);
  REP(i,M) {
    int b;
    cin >> b;
    A.at(b) = 0;
  }
  REP(i,N-1) {
    if (A.at(i+2) != 0) {
      A.at(i+2) = A.at(i) + A.at(i+1);
      A.at(i+2) %= 1000000007;
    }
  }
  cout << A.at(N) << endl;
  return 0;
}


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

const long long mod=1e9+7;

using namespace std;

int main(){
    int N,M;
    cin>>N>>M;
    vector<int> a(N+1,true);
    for(int i=0;i<M;i++){
        int tmp;
        cin>>tmp;
        a[tmp] = false;
    }

    vector<long long int> dp(N+1);
    dp[0]=1;

    for(int i=0;i<N;i++){
        for(int j=i+1;j<=min(i+2,N);j++){
            if(a[j]){
                dp[j]+=dp[i];
                dp[j]%=mod;
            }
        }
    }
    cout<<dp[N]<<endl;
    return 0;
}

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

int divCal(int x, int count){
  
  if(x % 2 == 1){
    return count;
  }
  if(x % 2 == 0 && x > 1){
    x = x / 2;
    count++;
    divCal(x, count);
  }
  
}


int main(){
  
  int N;
  cin >> N;
  
  vector<int> p(N);
  vector<int> count(N);
  int flag = 0;
  
  for(int i=0; i<N; i++){
    cin >> p.at(i);
    
    if(p.at(i) % 2 == 1){
      flag = 1;
      break;
    }
  }
  
  if(flag == 1){
    cout << 0 << endl;
  }else{
    for(int i=0; i<N; i++){
      int cnt = 0;
      count.at(i) = divCal(p.at(i), cnt);
    }
    sort(count.begin(), count.end());
    cout << count.at(0) << endl;
  }
  
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	int n, i;
	int data[10000];
	int min, max;
	long long int sum = 0;
	
	scanf("%d", &n);
	
	for(i = 0; i < n; i++) {
		scanf("%d", &data[i]);
	}
	
	min = data[0];
	max = data[0];
	
	for(i = 0; i < n; i++) {
		if(data[i] < min) {
			min = data[i];
		}
		
		if(data[i] > max) {
			max = data[i];
		}
	}
	
	for(i = 0; i < n; i++) {
		sum += data[i];
	}
	
	printf("%d %d %lld\n", min, max, sum);
	
	return 0;
}

Measured memory_bytes: 640
N = int(input())

num_list = list(map(int,input().split()))

cnt = 0

for i in range(N):
    minj = i
    for j in range(i,N):
        if num_list[j] < num_list[minj]:
            minj = j
    if i != minj:
        num_list[i],num_list[minj] = num_list[minj],num_list[i]
        cnt+=1
        
print(*num_list)
print(cnt)


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

using namespace std;

#define REPEAT(i, N) for (int i = 0; i < (N); i++)

typedef long long ll;

int main() {
  int N;
  
  cin >> N;
  
  vector<pair<ll, ll>> lists;
  
  REPEAT(i, N) {
    int in1, in2;
    
    cin >> in1 >> in2;
    
    lists.push_back(make_pair(in2, in1));
  }
  
  sort(lists.begin(), lists.end());
  
  ll sum = 0;
  
  REPEAT(i, N) {
    sum += lists[i].second;
    
    if (sum > lists[i].first) {
      cout << "No" << endl;
      
      return 0;
    }
  }
  
  cout << "Yes" << endl;
  
  return 0;
}

Measured memory_bytes: 6256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define LLINF 9223372036854775807
#define MOD ll(1e9+7)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr<<#x<<": "<<x<<endl

int main(){
    ll n;
    vector<ll> a(5,0);
    cin >> n;
    ll min = 1e18;
    ll min_index = 0;
    for(int i = 0; i < 5; i++){
        cin >> a[i];
        if(min > a[i]){
            min = a[i];
            min_index = i;
        }
    }
    ll t = n/min;
    if(n%min != 0){t++;}
    cout << 4+t << endl;
    return 0;
}


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

//	long long dp[2000][2000] = {};
int main(){
//	string t,b;
//	cin >> t >> b;
//	dp[0][0] = 1LL;
//
//	for(int i=0; i<t.size(); i++){
//		for(int j=0; j<b.size(); j++){
//			dp[i+1][j] += dp[i][j];
//			if(t[i] == b[j]){
//				dp[i+1][j+1] += dp[i][j];
//			}
//			dp[i+1][j] %= 1000000007;
//			dp[i+1][j+1] %= 1000000007;
//		}
//		dp[i+1][b.size()] += dp[i][b.size()];
//	}
//
//	cout << dp[t.size()][b.size()]%1000000007 << endl;
//
//	return 0;
/*	int p, m, c;
	cin >> p >> m >> c;

	cout << p + m + c << endl;*/
	/*int ha, hb, ka, kb, a, b, c, d, x, y;
	cin >> ha >> hb >> ka >> kb >> a >>b >>c >>d;

	x = ha*a+hb*b+(ha/10)*c+(hb/20)*d;
	y = ka*a+kb*b+(ka/10)*c+(kb/20)*d;

	if(x > y){
		cout << "hiroshi" << endl;
	}

	else if(y > x){
		cout << "kenjiro" << endl;
	}

	else{
		cout << "even" << endl;
	}*/

	int D, L;
	cin >> D >> L;

	cout << D/L+D%L << endl;
}



Measured memory_bytes: 3108
import java.util.Scanner;
import java.util.TreeMap;

public class Main{

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
	    int N = sc.nextInt();
	 
	    TreeMap <Integer, Integer> store = new TreeMap <Integer, Integer>();
	    
	    for (int i=0; i<N; i++){
	    	int A =sc.nextInt();
	    	int B =sc.nextInt();
	    	
	    	if (store.containsKey(B)) 
				store.put(B, store.get(B) + A);
			 else 
				store.put(B, A);
	    	
	    }
	    int time = 0;
	    
	   
	    //System.out.println(store.entrySet());
	    
	    
	    while (store.isEmpty()!=true){
	    	int lim = store.firstKey();
	    	int task = store.get(lim);
	    	
	    	//System.out.println(lim);
	    	//System.out.println(task);
	    	
	    	if (time+task<=lim){
	    		time+=task;
	    		store.remove(lim, task);
	    	}
	    	
	    	else {
	    		time = -1;
	    		break;
	    	}
	    }
	    if (time == -1)
	    	System.out.println("No");
	    
	    else
	    	System.out.println("Yes");
	    
	    

	}

}


Measured memory_bytes: 129988
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

#define int long long


const int INF = 1e18 + 239;

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

	int n;
	cin >> n;
	int c = 1;
	while (n--) {
		int x;
		cin >> x;
		if (x == 0) {
			cout << 0 << endl;
			return 0;
		}
		if (c > INF / x) {
			c = INF;
		} else {
			c = min(INF, c * x);
		}
	}
	if (c > (int)1e18) {
		cout << -1 << endl;
	} else {
		cout << c << endl;
	}
}

Measured memory_bytes: 3184
#include <stdio.h>
int main(void)
{
	int n, i, t, s1, s2, s, ans;
	int w[100];
	ans = 1000000000;
	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf("%d", &w[i]);
	}
	for (t = 0; t < n - 1; t++) {
		s1 = 0;
		s2 = 0;
		s = 0;
		for (i = 0; i < n; i++) {
			if (t >= i) {
				s1 = s1 + w[i];
			}
			else {
				s2 = s2 + w[i];
			}
		}
		if (s1 >= s2) {
			s = s1 - s2;
		}
		else {
			s = s2 - s1;
		}
		if (ans > s) {
			ans = s;
		}
	}
	printf("%d", ans);

	return 0;
}

Measured memory_bytes: 128
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
    
		// 文字列の入力
		String s = sc.next();
        String[] list = s.split("");
        int[] constList = new int[3];
        int a = Integer.parseInt(list[0]);
        for (int i = 0; i < 3; i++) {
          constList[i] = Integer.parseInt(list[i + 1]);
        }
        
        String ans = list[0];
        
        for (int i = 0; i < 8; i++) {
          String bin = "";
          if (i < 2) {
            bin += "00";
          } else if (i < 4) {
            bin += "0";
          }
          bin += Integer.toBinaryString(i);
          String[] oprList = bin.split("");
          int sum = a;
          
          for (int index = 0; index < 3; index++) {
            if (oprList[index].equals("0")) {
              sum += constList[index];
            } else {
              sum -= constList[index];
            }
          }
          
          if (sum == 7) {
            for (int index = 0; index < 3; index++) {
              if (oprList[index].equals("0")) {
                ans += "+" + list[index + 1];
              } else {
                ans += "-" + list[index + 1];
              }
            }
            ans += "=7";
            break;
          }
        }
    
		// 出力
		System.out.println(ans);
	}
}

Measured memory_bytes: 22612
#include <iostream>
#include <cmath>

using namespace std;

int main(int argc, char* argv[]) {
  int N, M;
  cin >> N >> M;

  long double ret = 0;

  // all passed
  ret = (M * 1900 + (N - M) * 100) * pow(2, M);

  cout << ret << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
    //#define ll long long
    using namespace std;
    #define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
    #define fileio freopen("http://in.in", "r", stdin),freopen("out.out", "w", stdout);
    #define ll long long
    #define pb push_back
    #define pll pair<ll,ll>
    #define ff first
    #define ss second
    #define mp make_pair
    #define N 2000001
    #define M 998244353
    #define INF 1000000000000000
  ll gcd(ll a,ll b)
  {
    if(b==0)return a;
    else return(gcd(b,a%b));
  }
  vector<pll> adj[100001];
  vector<ll> tim[100001];

int main()
{
  SPEED;
 string s;
 cin>>s;
 if(s=="ABC")cout<<"ARC";
 else cout<<"ABC";
 

}



Measured memory_bytes: 8352
from collections import deque

N,M = map(int,input().split())

connect = [[] for _ in range(3*N)]

for _ in range(M):
    u,v = map(int,input().split())
    u -= 1
    v -= 1
    connect[u].append(v+N)
    connect[u+N].append(v+2*N)
    connect[u+2*N].append(v)

S,T = map(int,input().split())
S -= 1
T -= 1

def bfs(s):
    q = deque()
    q.append(s)
    d = [-1 for _ in range(3*N)]
    d[s] = 0
    
    while q:
        v = q.popleft()
        if v == T:
            return d[v]
    
        for u in connect[v]:
            if d[u] == -1:
                q.append(u)
                d[u] = d[v]+1
                
    return -1

ans =  bfs(S)

if ans == -1:
    print(-1)
else:
    print(ans//3)

Measured memory_bytes: 60208
def affine(word, alpha, beta):
    word = list(word)
    for i in range(len(word)):
        word[i] = albs[(albs.index(word[i]) * alpha + beta) % 26]
    return ''.join(word)
albs = 'abcdefghijklmnopqrstuvwxyz'
alphas = [1, 3, 5, 7, 9, 11, 15, 17, 19, 21, 23, 25]
betas = list(range(26))
for _ in range(int(input())):
    words = input().split(' ')
    for alpha in range(26):
        for beta in range(26):
            test = list(map(lambda x: affine(x, alpha, beta), words))
            if 'that' in test or 'this' in test:
                print(*test)
                break
        else:
            continue
        break

Measured memory_bytes: 7752
require 'pp'

a, b, k = gets.split.map(&:to_i)

turn = :a
k.times do |i|
    if turn == :a
        if a % 2 == 1
            a -= 1
        end
        b += a / 2
        a = a / 2

        turn = :b
    else
        if b % 2 == 1
            b -= 1
        end
        a += b / 2
        b = b / 2

        turn = :a
    end
end

puts "#{a} #{b}"


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

int main(){
  string s;cin >> s;
  
  for(int i=0; i<(int)s.size(); i++){
    if(i%2==0 && s[i]=='L'){
      cout << "No" << endl;
        return 0;
    }
    if(i%2==1 && s[i]=='R'){
      cout << "No" << endl;
        return 0;
    }
  }
  cout << "Yes" << endl;
  
  return 0;
}

Measured memory_bytes: 256
def main():
    R,G,B,N=map(int,input().split())
    cnt=0
    for r in range(0,N//R+1):
        for g in range(0,(N-r*R)//G+1):
            bunshi=N-r*R-g*G
            q,m=divmod(bunshi,B)
            # if q<0:continue
            if m==0:cnt+=1
    print(cnt)
main()

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

#define ll long long
#define endl "\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

const int MAX = 1e5 + 5;
ll cost = (ll)1e18;

int main()
{
	IOS
	int t = 1;
	//cin >> t;
	while(t--)
	{
		int n, m, x;   // n = rows and m = columns
		cin >> n >> m >> x;

		int mat[n][m + 1];

		for(int i = 0; i < n; i++)
		{
			for(int j = 0; j <= m; j++)
			{
				cin >> mat[i][j];
			}
		}
		for(int i = 1; i <= (1 << n); i++)
		{
			ll total = 0;
			vector<ll> val(m);
			for(int j = 0; j < n; j++)
			{
				if(i & (1 << j))
				{
					total += mat[j][0];
					for(int k = 0; k < m; k++)
					{
						val[k] += mat[j][k + 1];
					}
				}
			}
			bool chck = 1;
			for(int j = 0; j < m; j++)
			{
				if(val[j] < x)
				{
					chck = 0;
					break;
				}
			}
			if(chck)
				cost = min(cost, total);
		}
		if(cost == 1e18) cout << -1 << endl;
		else cout << cost << endl;
	}
	return 0;
}


Measured memory_bytes: 3632
N = int(input())
X = list(map(int,input().split()))
s_X = sorted(X)
c = s_X[-(N//2)]
c2 = s_X[-(N//2)-1]

for i in range(N):
    if X[i] < c:
        print(c)
    else:
        print(c2)

Measured memory_bytes: 26180
h, w = map(int,input().split())
row = [0]*h
ans = []
for i in range(h):
    prev = 0
    for j, a in enumerate(map(lambda x:int(x)%2,input().split())):
        if a:
            if prev:
                prev = 0
                continue
            else:
                prev = 1
        if prev:
            if j == w-1:
                row[i] = 1
            else:
                ans.append((i+1,j+1,i+1,j+2))
prev = 0
for i, a in enumerate(row):
    if a:
        if prev:
            prev = 0
            continue
        else:
            prev = 1
    if prev:
        if i == h-1:
                break
        else:
            ans.append((i+1,w,i+2,w))

print(len(ans))
for i in ans:
    print(*i)

Measured memory_bytes: 24216
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
int main() {
  int n;
  cin>>n;
  int a[n];
  int sum=0;
  rep(i,n){
    cin>>a[i];
    sum+=a[i];
  }
  int sum2=0;
  int sum3;
  rep(i,n){
    sum2+=a[i];
    if(sum2>sum/2){
      sum3=sum2-a[i];
      break;
    }
  }
  int ans=min(abs(sum-sum2*2),abs(sum-sum3*2));
  cout<<ans<<endl;
}

Measured memory_bytes: 256
from collections import deque
s = input()
n = len(s)
s = int(s)
if n<3:
    print(0)
    exit()
nums = deque(['7','5','3'])
kouho= deque()
while nums:
    num = nums.popleft()
    num3 = num+'3'
    num5 = num+'5'
    num7 = num+'7'
    if (3<= len(num3) <= n):
        kouho.append(num3)
        kouho.append(num5)
        kouho.append(num7)
    if len(num3)<n:
        nums.append(num3)
        nums.append(num5)
        nums.append(num7)

ans = 0
while kouho:
    number = kouho.pop()
    if ("3" in number)and("5" in number)and("7" in number):
        if int(number)<=s:
            ans +=1
print(ans)
    




Measured memory_bytes: 5364
#include <iostream>
#include <cstdlib>
#include <stack>
using namespace std;
int main(void){
    
    stack<int> S;
    int a, b;
    string str;
    
    while(cin >> str){
        
        if(str[0] == '+'){
            a = S.top(); S.pop();
            b = S.top(); S.pop();
            S.push(a + b);
        }
        else if(str[0] == '-'){
            a = S.top(); S.pop();
            b = S.top(); S.pop();
            S.push(b - a);           
        }
        else if(str[0] == '*'){
            a = S.top(); S.pop();
            b = S.top(); S.pop();
            S.push(a * b);               
        }
        else{
            S.push(atoi(str.c_str()));
        }
    }
    
    cout << S.top() << endl;
    
    
}



Measured memory_bytes: 3180
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define rep1(i, n) for(int i=1; i<=n; i++)
#define repr(i, n) for(int i=n-1; i>=0; i--)
#define repr1(i, n) for(int i=n; i>=1; i--)
#define all(v) v.begin(),v.end()
using ll = long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
const double EPS = 1e-10;
const double PI = acos(-1);
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() {
    int h, w; cin >> h >> w;
    int k; cin >> k;
    vector<string> c(h);
    rep(i, h) cin >> c[i];

    int ans = 0;
    for (int bity = 0; bity < (1 << h); bity++) {
        for (int bitx = 0; bitx < (1 << w); bitx++) {
            vector<string> s = c;
            rep(i, h) {
                if (bity & (1 << i)) {
                    rep(j, w) s[i][j] = '@';
                }
            }
            rep(j, w) {
                if (bitx & (1 << j)) {
                    rep(i, h) s[i][j] = '@';
                }
            }

            int cnt = 0;
            rep(i, h) rep(j, w) {
                if (s[i][j] == '#') cnt++;
            }
            if (cnt == k) ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3636
/* ****devACE**** */

#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define	endl		'\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
using namespace std;

#define N  100005
vector<int>adj[N];
int mx[N],vis[N];
void dfs(int node)
{
	vis[node]=1;
	for(auto i:adj[node])
	{
		if(!vis[i])
		dfs(i);
		mx[node]=max(mx[node],mx[i]+1);
	}
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
//	cin>>TESTS;
	while(TESTS--)
	{
		int n,m,i,j,k;
		cin>>n>>m;
		for(i=0;i<m;i++)
		{
			int x,y;
			cin>>x>>y;
			adj[x].pb(y);
		}
		for(i=1;i<=n;i++)if(!vis[i])dfs(i);
		int ans=mx[1];
		for(i=2;i<=n;i++)ans=max(ans,mx[i]);
		cout<<ans;
	}
	return 0;
}

Measured memory_bytes: 8576
#include <bits/stdc++.h>
#define FOR(i,bg,ed) for(ll i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007
//#define int long long
using namespace std;
typedef long long ll;
const int INF = 1e9;


signed main()
{
    int X, A, B;

    cin >> X >> A >> B;
    A *= -1;
    if (A + B <= 0) {
        cout << "delicious" << endl;
    } else if (A + B <= X) {
        cout << "safe" << endl;
    } else {
        cout << "dangerous" << endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <cmath>
#include <complex>
#include <map>
#include <climits>
#include <sstream>
using namespace std;

#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define EPS 1e-8
#define F first
#define S second
#define mkp make_pair

static const double PI=6*asin(0.5);
typedef long long ll;
typedef complex<double> CP;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vint;
static const int INF=1<<24;

template <class T>
void initvv(vector<vector<T> > &v,int a,int b, const T  &t = T()){
	v.assign(a,vector<T>(b,t));
}

//v.erase(unique(v.begin(),v.end()),v.end());

bool prime[10100];
int a[10100];
int main(){
	rep(i,10100){
		prime[i]=true;
	}
	prime[0]=prime[1]=false;
	for(int i=2;i*i<10100;i++){
		if(prime[i]){
			for(int j=i*i;j<10100;j+=i){
				prime[j]=false;
			}
		}
	}
	int M=5;
	reep(i,5,10100){
		if(prime[i]&&prime[i-2]){
			M=i;
		}
		a[i]=M;
	}
	int n;
	while(cin>>n,n){
		cout<<a[n]-2<<" "<<a[n]<<endl;
	}
}

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

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

const ll MOD = 1e9 + 7;
const ll inf = 1LL<<60;
const double eps = 1e-9;

const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
 
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()
{
    int n, m;
    cin >> n >> m;
    vector <int> s(m), c(m);

    for (int i = 0; i < m; i++) {
        cin >> s[i] >> c[i];
        s[i]--;
    }

    int first, end;
    if (n == 1) {
        first = 0;
        end = 9;
    }
    if (n == 2) {
        first = 10;
        end = 99;
    }
    if (n == 3) {
        first = 100;
        end = 999;
    }
    int x[n], tmp;
    for (int i = first; i <= end; i++) {
        tmp = i;
        for (int j = n-1; j >= 0; j--) {
            x[j] = tmp % 10;
            tmp /= 10;
        }
        //for (int j = 0; j < n; j++) cout << x[j];
        //cout << endl;
        bool ok = true;
        for (int j = 0; j < m; j++) {
            //cout << x[s[j]] <<  " " << c[j] << endl;
            if (x[s[j]] != c[j]) ok = false;
        }
        if (ok) {
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	ll n;
	cin>>n;
	string ans="";
	while(n){
		n--;
		ll x=n%26;
		char c=('a'+x);
		ans=c+ans;
		n/=26;
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 3652
#include <iostream>

using namespace std;

int main(){
    while(true){
        int n;
        cin >> n;
        if(n==0)break;
        string str;
        bool st[2]={false,false};
        int c=0;
        bool flag=false;
        for(int i=0;i<n;i++){
            cin >> str;
            if(str=="lu")st[0]=true;
            else if(str=="ru")st[1]=true;
            else if(str=="ld")st[0]=false;
            else if(str=="rd")st[1]=false;
            if(!flag && st[0] && st[1]){
                flag=true;
                c++;
            }
            else if(flag && !st[0] && !st[1]){
                flag=false;
                c++;
            }
        }
        cout << c << endl;
    }
    return 0;
}

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

using namespace std;

int main(){
  int n,i;
  cin >> n;
  long long x=1,y=1,t,a;
  for(i=0;i<n;i++){
    cin >> t >> a;
    x=t*max((x+t-1)/t,(y+a-1)/a);
    y=a*max((x+t-1)/t,(y+a-1)/a);
  }
  cout << x+y << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18,MOD = 1e9 + 7;
const int INT_INF = 1e9,INT_MOD=1e9+7;
#define rep(i, N) for(int i = 0; i < N; i++)
typedef pair<int, int> Pi;
typedef pair<double, double> P;
signed main(){
    int k,n;cin>>k>>n;
    int a[n];
    rep(i,n) cin>>a[i];
    int ln[n];
    rep(i,n-1) ln[i]=a[i+1]-a[i];
    ln[n-1]=k+a[0]-a[n-1];
    int ans=INT_INF;
    rep(i,n) ans=min(ans,k-ln[i]);
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define N 3000+10
using namespace std;

char path[N][N];	

int main(){
	int n, m;
	string str1, str2, answ = "";
	int lcs[2][N], current, last;

	//input
	cin >> str1 >> str2;
	n = str1.size();
	m = str2.size();

	//initial conditions
	for(int i=0;i<=m;i++){
		lcs[0][i] = 0;
		lcs[1][i] = 0;
	}

	//alg
	for(int i=n-1;i>=0;i--){
		current = i%2;
		last = (i+1)%2;
		for(int j=m-1;j>=0;j--){
			if(str1[i]==str2[j]){
				lcs[current][j] = lcs[last][j+1]+1;
				path[i][j] = '=';
			}
			else{
				if(lcs[current][j+1]>lcs[last][j]){
					path[i][j] = '>';
				}
				else{
					path[i][j] = '<';	
				}
				lcs[current][j] = max(lcs[current][j+1],lcs[last][j]);
			}
		}
	}

	for(int i=0,j=0;i<n&&j<m;){
		if(path[i][j]=='='){
			answ+=str1[i];
			i++;
			j++;
		}
		else if(path[i][j]=='>'){
			j++;
		}
		else{
			i++;
		}
	}

	cout << answ << '\n';

	return 0;
}

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

#define INIT_CAP 10
#define INF 1000000000

#define min(a, b) (((a) < (b)) ? (a) : (b))

const int di[4] = {-1, 0, 1, 0};
const int dj[4] = {0, 1, 0, -1};

typedef struct {
	int to, w;
} Edge;

typedef struct {
	Edge *elem;
	int cap, size;
} VecEdge;

typedef struct {
	int num;
	int d;
} PNumDis;

VecEdge adj[30 * 30 * 4];
PNumDis heap[30 * 30 * 4];
int hsize;
int d[30 * 30 * 4], idx[30 * 30 * 4];

int w, h;
int field[30][30];

void init(int n) {
	while (n--)
		adj[n] = (VecEdge){malloc(sizeof(Edge) * INIT_CAP), INIT_CAP, 0};
}

inline void add(int from, int to, int w) {
	if (adj[from].size == adj[from].cap) {
		adj[from].cap <<= 1;
		adj[from].elem = realloc(adj[from].elem, sizeof(Edge) * adj[from].cap);
	}
	adj[from].elem[adj[from].size++] = (Edge){to, w};
}

void freeAll(int n) {
	while (n--)
		free(adj[n].elem);
}

inline int calcNextIdx(int i) {
	return i * 2 + 1 + (i * 2 + 2 < hsize && heap[i * 2 + 1].d > heap[i * 2 + 2].d);
}

inline PNumDis delete(void) {
	int i;
	int nextIdx;
	const PNumDis root = heap[0], last = heap[--hsize];

	for (i = 0; i * 2 + 1 < hsize && last.d > heap[nextIdx = calcNextIdx(i)].d; i = nextIdx) {
		heap[i] = heap[nextIdx];
		idx[heap[i].num] = i;
	}
	heap[i] = last;
	idx[last.num] = i;

	return root;
}

inline void decreaseKey(int num, int d) {
	int i;

	for (i = idx[num]; i > 0 && d < heap[i - 1 >> 1].d; i = i - 1 >> 1) {
		heap[i] = heap[i - 1 >> 1];
		idx[heap[i].num] = i;
	}
	heap[i] = (PNumDis){num, d};
	idx[num] = i;
}

void dijkstra(int n, int s) {
	int i;

	for (i = 0; i < n; i++) {
		heap[i] = (PNumDis){i, INF};
		d[i] = INF;
		idx[i] = i;
	}
	hsize = n;

	d[s] = 0;
	decreaseKey(s, 0);
	while (hsize > 0) {
		const PNumDis fromP = delete();
		for (i = 0; i < adj[fromP.num].size; i++) {
			const Edge e = adj[fromP.num].elem[i];
			if (fromP.d + e.w < d[e.to]) {
				d[e.to] = fromP.d + e.w;
				decreaseKey(e.to, d[e.to]);
			}
		}
	}
}

int main(void) {
	int i, j, k, l;

	while (scanf("%d %d", &w, &h), w) {
		int c[4];

		for (i = 0; i < h; i++)
			for (j = 0; j < w; j++)
				scanf("%d", field[i] + j);

		for (i = 0; i < 4; i++)
			scanf("%d", c + i);

		init(h * w * 4);

		for (i = 0; i < h; i++)
			for (j = 0; j < w; j++)
				for (k = 0; k < 4; k++)
					for (l = 0; l < 4; l++) {
						int nd = k + l & 3;
						int ni = i + di[nd], nj = j + dj[nd];
						if (ni >= 0 && ni < h && nj >= 0 && nj < w)
							add(i * w * 4 + j * 4 + k, ni * w * 4 + nj * 4 + nd, l == field[i][j] ? 0 : c[l]);
					}

		dijkstra(h * w * 4, 1);

		printf("%d\n", min(d[(h - 1) * w * 4 + (w - 1) * 4 + 1], d[(h - 1) * w * 4 + (w - 1) * 4 + 2]));

		freeAll(h * w * 4);
	}

	return 0;
}

Measured memory_bytes: 1052
#include<bits/stdc++.h>
#define fr(i,c,b) for(int i=c;i<b;i++)
#define frl(i,c,b) for(ll i=c;i<b;i++)
#define si(x) int x; scanf("%d", &x)
#define sll(x) ll x; scanf("%lld", &x)
#define pi(x) printf("%d", x)
#define pll(x) printf("%lld", x)
#define nl printf("\n")
#define watch(x) cout << (#x) << " is " << (x) << endl
#define MAX 100001
#define M 1000000007
#define pb push_back

typedef long long int ll;

using namespace std;

int main()
{
    sll(n);
    ll a[n]; fr(i,0,n)  cin>>a[i];
    ll sum[n];
    sum[n-2]=a[n-1];
    for(int i=n-3;i>=0;i--)
    {
        sum[i]=(sum[i+1]%M+a[i+1]%M)%M;
    }
    
    ll ans=0;
   // ll j=n-2;
    for(int i=0;i<n-1;i++)
    {
        ans=(ans%M+a[i]%M*sum[i]%M)%M;
    }
    
    cout<<ans%M;
    
    
    
}


Measured memory_bytes: 6764
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
const ll MAX = 1001001;
const ll MOD = 1000000007;
int main()
{
    ll h, w;
    cin >> h >> w;
    ll cx, cy, gx, gy;
    cin >> cx >> cy >> gx >> gy;
    cx--;
    cy--;
    gx--;
    gy--;

    vector<vector<char>> s(h, vector<char>(w));
    rep(i, h)
    {
        rep(j, w)
        {
            cin >> s[i][j];
        }
    }
    vector<vector<int>> d(h, vector<int>(w));
    ll INF = 1001001001;

    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            d[i][j] = INF;
        }
    }
    ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
    deque<P> q;
    q.push_front(P(cx, cy));
    d[cx][cy] = 0;
    while (q.size())
    {
        P p = q.front();
        q.pop_front();
        if (p.first == gx && p.second == gy)
        {
            break;
        }
        for (int i = 0; i < 4; i++)
        {
            int nx = p.first + dx[i], ny = p.second + dy[i];

            if (0 <= nx && nx < h && 0 <= ny && ny < w && s[nx][ny] != '#')
            {
                if (d[nx][ny] > d[p.first][p.second])
                {
                    q.push_front(P(nx, ny));
                    d[nx][ny] = d[p.first][p.second];
                }
            }
        }
        rep2(i, -2, 3)
        {
            rep2(j, -2, 3)
            {
                if (abs(i) + abs(j) >= 2)
                {
                    int nx = p.first + i, ny = p.second + j;

                    if (0 <= nx && nx < h && 0 <= ny && ny < w && s[nx][ny] != '#')
                    {
                        if (d[nx][ny] > 1 + d[p.first][p.second])
                        {
                            q.push_back(P(nx, ny));
                            d[nx][ny] = d[p.first][p.second] + 1;
                        }
                    }
                }
            }
        }
    }
    if (d[gx][gy] == INF)
    {
        cout << -1 << endl;
    }
    else
    {
        cout << d[gx][gy] << endl;
    }
}

Measured memory_bytes: 8740
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<queue>
#include<numeric>
#define all(x) (x).begin(),(x).end()
typedef long long ll;
 
using namespace std;

int main()
{
    int N;  cin >> N;
    vector<int> c(N), s(N), f(N);
    for(int i=0; i<N-1; i++)  cin >> c[i] >> s[i] >> f[i];
    for(int i=0; i<N; i++){
        int t = 0;
        for(int j=i; j<N-1; j++){
            if(j == i)  t += c[j] + s[j];
            else{
                if(t <= s[j])    t = c[j] + s[j];
                else if(t%f[j] == 0)   t += c[j];
                else    t += c[j] + f[j] - t%f[j];
            }
        }
        cout << t << endl;
    }
    return 0;
}

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

int main() {
	int n;
	cin>>n;
	int dp[MAX][3];
	int A[n],B[n],C[n];
	for(int i=0 ; i<n ; i++)
	{
		cin>>A[i]>>B[i]>>C[i];
	}
	for(int i=0 ; i<n ; i++)
	{
		for(int j=0 ; j<3 ; j++)
		{
			if(i==0)
			{
				if(j==0)
					dp[i][j]=A[i];
				else if(j==1)
					dp[i][j]=B[i];
				else
					dp[i][j]=C[i];
			}
			else
			{
				for(int k=0 ; k<3 ; k++)
				{
					if(j==k)
						continue;
					if(j==0)
						dp[i][j]=max(dp[i][j],dp[i-1][k]+A[i]);
					else if(j==1)
						dp[i][j]=max(dp[i][j],dp[i-1][k]+B[i]);
					else	
						dp[i][j]=max(dp[i][j],dp[i-1][k]+C[i]);
				}
			}
		}
	}
	int ret=0;
	ret=max(ret,dp[n-1][0]);
	ret=max(ret,dp[n-1][1]);
	ret=max(ret,dp[n-1][2]);
	
	cout<<ret<<"\n";
	
	return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
#include <fstream>
#include <unordered_map>
#include <unordered_set>
#include <assert.h>
using namespace std;


#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD 1000000007
#define P pair<ll, ll>

ll n, m;
vector<ll> g[110000];

int main() {
	ll n, m;
	cin >> n >> m;
	vector<ll> v(n);
	REP(i, n)cin >> v[i];
	REP(i, m) {
		ll a, b;
		cin >> a >> b;
		a--;
		b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	ll ans = 0;
	REP(i, n) {
		bool ok = true;
		REP(j, g[i].size()) {
			if (v[i] <= v[g[i][j]])ok = false;
		}
		if (ok)ans++;
	}
	cout << ans << endl;
}



Measured memory_bytes: 10124
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  int t[100009],x[100009],y[100009];
  cin>>n;
  t[0]=0;
  x[0]=0;
  y[0]=0;
  for(int i=1;i<=n;i++){
    cin>>t[i]>>x[i]>>y[i];
  }
  for(int i=0;i<n;i++){
    int dt=t[i+1]-t[i];
    int dx=x[i+1]-x[i];
    int dy=y[i+1]-y[i];
    int d=abs(dx)+abs(dy);
    if(dt<d||d%2!=dt%2){
      cout<<"No"<<endl;
      return(0);
    }
  }
  cout<<"Yes"<<endl;   
  return(0);
}


Measured memory_bytes: 1408
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Main {

    public static  void main(String args[]) {
        Scanner scanner = new Scanner(System.in);
        int h = scanner.nextInt();
        int w = scanner.nextInt();
        String x[][] = new String[h + 2][w + 2];
        for(int i = 0; i < x.length; i++){
            Arrays.fill(x[i], ".");
        }
        for (int i = 1; i < h + 1; i++) {
            String str = scanner.next();
            for (int j = 1; j < w + 1; j++) {
                x[i][j] = str.substring(j - 1, j);
                //System.out.print(x[i][j]);
            }
            //System.out.println();
        }

        boolean ans = true;
        for (int i = 1; i < h + 1; i++) {
            for (int j = 1; j < w + 1; j++) {
                if (x[i][j].equals("#") && !(x[i-1][j].equals("#")) && !(x[i+1][j].equals("#")) && !(x[i][j-1].equals("#")) && !(x[i][j+1].equals("#"))) {
                    System.out.println("No");
                    ans = false;
                    return;
                }
            }
        }
        if(ans){
            System.out.println("Yes");
        }
    }
}


Measured memory_bytes: 21844
n = int(input())

d,x = [int(i) for i in input().split()]
li = []
t = x

def cou(ele,d): #ele=5 d=7
    e = 1
    c = 1
    
    while (e<d):
        
        e += ele   #e = 1+5=6
        if d>=e:
            c +=1
        
   
    #print(c)
    return c

for i in range(n):

    ele = int(input())
    
    c = cou(ele,d)
    t += c

    li.append(ele)


print(t)



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

ll dat[800000],lazy[800000],N;
void init(int n){
	N=1;while(N<n)N<<=1;
	rep(i,2*N-1)dat[i]=0;
}
inline void push(int k){
	dat[k]+=lazy[k];
	if(k<N-1){
		lazy[k*2+1]+=lazy[k];
		lazy[k*2+2]+=lazy[k];
	}
	lazy[k]=0;
}
inline void upnode(int k){
	dat[k]=max(dat[k*2+1],dat[k*2+2]);
}
inline void update(int a,int b,ll x,int k=0,int l=0,int r=N){
	push(k);
	if(b<=l||r<=a)return;
	if(a<=l&&r<=b){
		lazy[k]+=x;
		push(k);
		return;
	}
	push(k);
	update(a,b,x,k*2+1,l,(l+r)/2);
	update(a,b,x,k*2+2,(l+r)/2,r);
	upnode(k);
}
inline ll query(int a,int b,int k=0,int l=0,int r=N){
	if(b<=l||r<=a)return -INF;
	if(a<=l&&r<=b){
		push(k);
		return dat[k];
	}
	push(k);
	ll lb=query(a,b,k*2+1,l,(l+r)/2);
	ll rb=query(a,b,k*2+2,(l+r)/2,r);
	upnode(k);
	return max(lb,rb);
}

vector<P>v[300000];
int main(){
	int n,m;scanf("%d%d",&n,&m);
	rep(i,m){
		int l,r,a;scanf("%d%d%d",&l,&r,&a);l--;r--;
		v[r].push_back(P(l,a));
	}
	init(n);
	rep(i,n){
		if(i){
			update(i,i+1,max(0LL,query(0,i)));
		}
		for(auto p:v[i]){
			update(p.first,i+1,p.second);
		}
	}
	cout<<max(0LL,query(0,n))<<endl;
}

Measured memory_bytes: 24960
import bisect
import sys
input = sys.stdin.readline

def main():
    a,b,q = map(int, input().split())

    sl = [int(input()) for _ in range(a)]
    tl = [int(input()) for _ in range(b)]
    xl = [int(input()) for _ in range(q)]

    for x in xl:
        ans = 10**11

        curr_dist = 0
        ind_s = bisect.bisect_left(sl, x)
        ind_t = bisect.bisect_left(tl, x)
        
        for next_s in [ind_s, ind_s-1]:
            if 0 <= next_s < a:
                curr_dist = abs(x-sl[next_s])
                curr_pos = sl[next_s]
                ind_t2 = bisect.bisect_left(tl, curr_pos)
                if ind_t2 == 0:
                    curr_dist += abs(tl[0] - curr_pos)
                elif ind_t2 == b:
                    curr_dist += abs(tl[b-1] - curr_pos)
                else:
                    curr_dist += min( abs( tl[ind_t2-1] - curr_pos), abs(tl[ind_t2]-curr_pos))
                ans = min(curr_dist, ans)


        for next_t in [ind_t, ind_t-1]:
            if 0 <= next_t < b:
                curr_dist = abs(x-tl[next_t])
                curr_pos = tl[next_t]
                ind_s2 = bisect.bisect_left(sl, curr_pos)
                if ind_s2 == 0:
                    curr_dist += abs(sl[0] - curr_pos)
                elif ind_s2 == a:
                    curr_dist += abs(sl[a-1] - curr_pos)
                else:
                    curr_dist += min( abs( sl[ind_s2-1] - curr_pos), abs(sl[ind_s2]-curr_pos))
                ans = min(curr_dist, ans)

        print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 73308
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;
import java.lang.Math;

public class Main {
	public static void main(String[] args) {
		FS reader = new FS();
		// write reader
		int x = reader.nextInt();
		solver(x);
	}
	
	public static void solver(int x) {
		// write logic
        if (x < 1200) System.out.println("ABC");
        else System.out.println("ARC");
	}
	
	// Read Class
	static class FS {
		private final InputStream in = System.in;
		private final byte[] buffer = new byte[1024];
		private int ptr = 0;
		private int buflen = 0;
		private boolean hasNextByte() {
			if (ptr < buflen) {
				return true;
			} else {
				ptr = 0;
				try {
					buflen = in.read(buffer);
				} catch (IOException e) {
					e.printStackTrace();
				}
				if (buflen <= 0) {
					return false;
				}
			}
			return true;
		}
	
		private int readByte() { return hasNextByte() ? buffer[ptr++] : -1;}
		private boolean isPrintableChar(int c) {return 33 <= c && c <= 126;}
		private void skipUnprintable() {while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
	
		public boolean hasNext() { skipUnprintable(); return hasNextByte();}
		public String next() {
			if (!hasNext()) throw new NoSuchElementException();
			StringBuilder sb = new StringBuilder();
			int b = readByte();
			while(isPrintableChar(b)) {
				sb.appendCodePoint(b);
				b = readByte();
			}
			return sb.toString();
		}
		public int nextInt() {
			return (int)nextLong();
		}
		public long nextLong() {
			if (!hasNext()) throw new NoSuchElementException();
			long n = 0;
			boolean minus = false;
			int b = readByte();
			if (b == '-') {
				minus = true;
				b = readByte();
			}
			if (b < '0' || '9' < b) {
				throw new NumberFormatException();
			}
			while(true) {
				if ('0' <= b && b <= '9') {
					n *= 10;
					n += b - '0';
				} else if(b == -1 || !isPrintableChar(b)) {
					return minus ? -n : n;
				} else {
					throw new NumberFormatException();
				}
				b = readByte();
			}
		}
	}
}



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

bool chk(vector<long long> calc, long long score){
    bool bol = true;
    for(int i=0; i<calc.size(); i++){
        if(calc.at(i) < score){
            bol = false;
        }
    }
    return bol;
}
 
int main(){
    long long  N, M, X; cin >> N >> M >> X;
    vector<long long> calc(M);

    vector<vector<long long>> CA(N,vector<long long>(M+1));
    for(int i=0; i<N; i++){
        for(int j=0; j<M+1; j++){
            cin >> CA.at(i).at(j);
        }
    }

    long long ans = 1e9;
    for(int i=0; i<pow(2,N); i++){
        
        long long cnt = i;
        long long C_calc = 0;
        vector<long long> A_calc(M,0);
        
        for(int j=0; j<N; j++){
            if((cnt>>j)&1){
                //bit立ってる
                C_calc += CA.at(j).at(0); 
                for(int k=0; k<M; k++){
                    A_calc.at(k) += CA.at(j).at(k+1);
                }
            }
            cnt >> 1;
        }

        if(chk(A_calc,X)){
            ans = min(ans,C_calc);
        }

    }

    if(ans == 1e9){
        cout << -1 << endl;
    }else{
        cout << ans << endl;
    }
   

}

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


using namespace std;

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

    vector<int> A(N);
    vector<int> B(N);
    vector<int> C(N-1);

    A.clear();
    B.clear();
    C.clear();

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

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

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

    int sum = 0;
    for(int i=0;i<N;i++){
        sum += B[A[i]-1];
    
        if(A[i+1]-A[i] == 1){
            sum += C[A[i]-1];
        }
    }

    cout << sum << endl;

    return 0;
        
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <numeric>

using namespace std;

typedef long long ll;

long long GCD(long long a, long long b){if(b==0)return a;return GCD(b,a%b);}

ll MOD = 1000000007;

int main() {
    int N, M;  cin >> N >> M;
    set<int> A; for (int i = 0; i < M; ++i) {
        int a; cin >> a;
        A.insert(a);
    }
    vector<int> dp(N+100);
    for (int i = 0; i < N+1; ++i) dp[i] = 0;

    dp[1] = 1;
    dp[2] = 1;
    for (int i = 0; i < N; ++i) {
        if (A.count(i) > 0) continue;
        if (A.count(i+1) == 0) dp[i+1] = (dp[i+1] + dp[i]) % MOD;
        if (A.count(i+2) == 0) dp[i+2] = (dp[i+2] + dp[i]) % MOD;
    }
    cout << dp[N] << endl;
}


Measured memory_bytes: 5376
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
	// AtCoder Beginner Contest 136
	// https://atcoder.jp/contests/abc136/tasks
	public static void main(String[] args) {
		FastReader sc = new FastReader();
		int h = sc.nextInt();
		int w = sc.nextInt();
		char[][] room = new char[h][w];
		int[][] down = new int[h][w];
		int[][] up = new int[h][w];
		int[][] left = new int[h][w];
		int[][] right = new int[h][w];
		int res = 0;
		
		for (int i = 0; i < h; i++) {
			String s = sc.next();
			for (int j = 0; j < w; j++) {
				room[i][j] = s.charAt(j);
			}
		}
		
		// Down
		for (int j = 0; j < w; j++) {
			int light = 0;
			for(int i = 0; i < h; i++) {
				if (room[i][j] == '#') {
					light = 0;
				} else {
					light++;
					down[i][j] = light;
				}
			}
		}
		
		// Up
		for (int j = 0; j < w; j++) {
			int light = 0;
			for(int i = h - 1; i >= 0; i--) {
				if (room[i][j] == '#') {
					light = 0;
				} else {
					light++;
					up[i][j] = light;
				}
			}
		}
		
		// Left
		for (int i = 0; i < h; i++) {
			int light = 0;
			for(int j = 0; j < w; j++) {
				if (room[i][j] == '#') {
					light = 0;
				} else {
					light++;
					left[i][j] = light;
				}
			}
		}
		
		// Right
		for (int i = 0; i < h; i++) {
			int light = 0;
			for(int j = w - 1; j >= 0; j--) {
				if (room[i][j] == '#') {
					light = 0;
				} else {
					light++;
					right[i][j] = light;
				}
			}
		}
		
		// for (int i = 0; i < h; i++) {
		//	System.out.println(Arrays.toString(right[i]));
		// }
		
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				if (room[i][j] != '#') {
					int currLight = left[i][j]+right[i][j]+up[i][j]+down[i][j] - 3;
					res = Math.max(res, currLight);
				}
			}
		}
		System.out.println(res);
	}
	

	static class FastReader { 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastReader() { 
            br = new BufferedReader(new InputStreamReader(System.in)); 
        } 
  
        String next() { 
            while (st == null || !st.hasMoreElements()) { 
                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()); 
        } 
  
        double nextDouble() { 
            return Double.parseDouble(next()); 
        } 
  
        String nextLine() { 
            String str = ""; 
            try{ 
                str = br.readLine(); 
            } catch (IOException e) { 
                e.printStackTrace(); 
            } 
            return str; 
        } 
    } 
}


Measured memory_bytes: 129092
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		try(Scanner sc = new Scanner(System.in)) {

			int x = sc.nextInt();
			int y = sc.nextInt();

			if ( y % 2 == 0 && x * 2 <= y && y <= x * 4 ) {
				System.out.println("Yes");
			}
			else {
				System.out.println("No");
			}
		}
	}

}

Measured memory_bytes: 35740
#include <algorithm>
#include <iostream>
#include <utility>
#include <vector>

using namespace std;

int main(void) {
  int N;
  cin >> N;
  vector<pair<int, int>> p(N);
  for (int i = 0; i < N; ++i) {
    int A;
    cin >> A;
    p[i] = pair<int, int>(A, i + 1);
  }
  sort(p.begin(), p.end());

  for (const auto &v : p) {
    cout << v.second << " ";
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 3964
import java.util.*;

public class Main {
public static void main(String[] args) {
		
		Scanner keyboard = new Scanner(System.in); 
		
		long N  = keyboard.nextLong();
		
		String S = "abcdefghijklmnopqrstuvwxyz";
		String[] s = S.split("");
		
		StringBuffer ans = new StringBuffer("");
		
		while(N > 0) {
			int j = (int)((N-1)%26);
			N = (N-1)/26;
			ans.append(s[j]);
		}
		
		System.out.print(ans.reverse());
		keyboard.close();	
	}
}


Measured memory_bytes: 35712
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <iomanip>
using namespace std;
typedef long long int ll;

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

#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define drep(i, n) for(int i = n - 1; i >= 0; i--)

const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;

int main() {
  long h, w;
  cin >> h >> w;
  long ans;
  if (h == 1 || w == 1) {
    ans = 1;
  } else {
    ans = (h * w + 1) / 2;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256