akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1000000007;

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

int main(){
    ll N=0;
    cin >> N;
    ll ans=powmod(10, N)-powmod(9, N)-powmod(9, N)+powmod(8, N);
    ans%=mod;
    ans=(ans+mod)%mod;
    cout << ans << endl;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
#define INF 1000000007
#define MAX 200000
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rept(i,k,n) for(int i = (k); i < (int)(n); i++)

int main(){
    while(1){
        int n;cin>>n;
        if(!n) return 0;
        vector<int> w(n);
        rep(i,n) cin>>w[i];
        vector<vector<int> > dp(n,vector<int> (n,0));
        rept(d,1,n){
            rep(i,n-d){
                int j=i+d;
                if(dp[i+1][j-1] == d-1 && abs(w[i] - w[j]) <= 1) dp[i][j] = d+1;
                else rept(k,i,j) dp[i][j] = max(dp[i][j], dp[i][k] + dp[k+1][j]);
            }
        }
        cout << dp[0][n-1] << endl;
    }
    return 0;
}


Measured memory_bytes: 3128
s=STDIN.read
W=s.split[0].to_i
H=s.split[1].to_i
x=s.split[2].to_i
y=s.split[3].to_i
r=s.split[4].to_i

if (x-r>=0) && (x+r<=W) && (y-r>=0) && (y+r <=H)
  puts "Yes\n"
else
  puts "No\n"
end

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

using namespace std;

using ll = long long;

int const maxn = 101010;
ll const inf = 0x3f3f3f3;

template<typename Op = less<ll>>
struct LiChao {
private:
    struct Fc {
        ll a, b;

        ll eval(ll x) {
            return a*x + b;
        }
    };

    struct Node {
        Fc fn;
        unique_ptr<Node> l, r;

        Node(Fc fn) : fn(fn) {}
    };

    unique_ptr<Node> root;

    void upd(unique_ptr<Node> &t, ll l, ll r, Fc fn, Op op = Op{}) {
        ll m = (l+r)/2;
        
        bool bleft = op(fn.eval(l), t->fn.eval(l));
        bool bmid  = op(fn.eval(m), t->fn.eval(m));
        
        if (bmid) swap(t->fn, fn);
        if (l >= r) return;

        if (bleft != bmid) {
            if (!t->l) t->l = make_unique<Node>(fn);
            else upd(t->l, l, m, fn);
        }
        else {
            if (!t->r) t->r = make_unique<Node>(fn);
            else upd(t->r, m+1, r, fn);
        }
    }


    ll get(unique_ptr<Node> &t, ll x, ll l, ll r) {
        ll m = (l+r)/2;
        if (l == r and l == x) return t->fn.eval(x);

        if (x <= m and t->l)
            return min(t->fn.eval(x), get(t->l, x, l, m));
        else if (x > m and t->r)
            return min(t->fn.eval(x), get(t->r, x, m+1, r));

        return t->fn.eval(x);
    }
public:
    LiChao() : root(nullptr) {}

    void upd(ll a, ll b, ll l = 0, ll r = 1e6) {
        if (!root) {
            root = make_unique<Node>(Fc{a, b});
            return;
        }
        upd(root, l, r, {a, b});
    }

    ll get(ll x, ll l = 0, ll r = 1e6) {
        return get(root, x, l, r);
    }
};

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

    int n;
    cin >> n;

    ll c;
    cin >> c;

    vector<ll> h(n);
    for (auto& i : h) cin >> i;

    vector<ll> dp(n);
    LiChao<> cht;
    cht.upd(-2ll*h[n-1], h[n-1]*h[n-1] + c + dp[n-1]);

    for (int i = n-2; i >= 0; i--) {
        int x = h[i];
        dp[i] = cht.get(x) + h[i]*h[i];

        ll a = -2ll*h[i];
        ll b = h[i]*h[i] + c + dp[i];

        cht.upd(a, b);
    }

    cout << dp[0] << "\n";
}

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

int main () {
    int N , M ; cin >> N >> M ;
    vector <int> v (M , 0);
    for ( int i = 0; i < N ; ++i ) {
      int K; cin >> K ;
        for ( int j = 0; j < K ; ++j ) {
        int A; cin >> A ; --A ;
        ++v[A];
        }
    }
  int ans = 0;
  for ( int i = 0; i < M ; ++i ) {
    if ( v[i] == N ) {
    ++ans ;
    }
  }
  cout << ans << endl ;
}

Measured memory_bytes: 256
import java.io.*;

public class Main
{
	public static void main(String[] args)throws IOException
	{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb = new StringBuilder();
		StringBuilder sb2 = new StringBuilder();
		String str = "";
		while((str = br.readLine()) != null)		sb.append(str);
		sb2.append(sb.toString().toLowerCase());
		int[] cnt = new int[26];
		int n;
		for(int i=0;i<26;i++) cnt[i]=0;
		for(int i=0; i<sb2.length(); i++)
		{
			n = sb2.charAt(i)-'a';
			if(n>=0&&n<=26)	cnt[n]++;
		}
		char chr = 'a';
		for(int i=0; i<26; i++)	System.out.println(chr++ + " : " + cnt[i]);
	}
}

Measured memory_bytes: 24328
import java.util.Scanner;

public class Main {
  static String s;

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

    sc.next();
    s = sc.next();

    String ans = "A" + Character.toString(s.charAt(0)) + "C";

    System.out.println(ans);
  }
}


Measured memory_bytes: 9676
#include <iostream>
#include <vector>
#include <string>
#include <map>

using namespace std;

typedef map<string, int> item_price_map;
//typedef map<string, vector<string>> renkin_map;

item_price_map price_table;

bool get_input() {
    int n, m;

    string name;
    int price;
    cin >> n;
    if (n == 0) return false;
    for (int i = 0; i < n; i++) {
        cin >> name >> price;
        price_table[name] = price;
    }

    vector<string> items;
    int count;
    cin >> m;
    for (int i = 0; i < m; i++) {
        cin >> name >> count;
        items.resize(count);
        for (int j = 0; j < count; j++) {
            cin >> items[j];
        }
        int min_price = 0;
        for (int j = 0; j < count; j++) {
            min_price += price_table[items[j]];
        }
        price_table[name] = min_price < price_table[name] ? min_price : price_table[name];
    }

    return true;
}

void solve() {
    string name;
    cin >> name;
    cout << price_table[name] << endl;
}

int main() {
    while (get_input()) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 0
#include <stdio.h>

int main(int argc, char const *argv[])
{
	int H, W;
	while (1) {
		scanf("%d %d", &H, &W);
		if(H == 0 && W == 0) break;
		for(int i = 0; i < H; i++) {
			for(int j = 0; j <W; j++) {
				if( (i+j)%2 == 0)
					printf("#");
				else
					printf(".");
			}
			printf("\n");
		}
		printf("\n");
	}
	return 0;
}


Measured memory_bytes: 2140
#include<iostream>
#include<vector>
#include<string>
#include<utility>
#include<queue>

#define rep(i, n) for(int i = 0; i < (n); i++)
using ll = long long;
using P = std::pair<int, int>;
using PP = std::pair<ll, std::pair<int, int>>;
template<class T> inline void chmin(T& a, T b) { if(a > b) a = b; }
const ll INF = 1ll << 60;

ll dp[1010][1010];
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

int main(){
	int H, W, sh, sw, gh, gw;
	std::cin >> H >> W >> sh >> sw >> gh >> gw;
	sh--; sw--; gh--; gw--;
	std::vector<std::string> s(H);
	rep(i, H){
		std::cin >> s[i];
	}

	rep(i, H) rep(j, W){
		dp[i][j] = INF;
	}

	std::priority_queue<PP, std::vector<PP>, std::greater<PP>> q;
	q.push({0, {sh, sw}});
	dp[sh][sw] = 0;
	int cnt = 0;
	while(!q.empty()){
		ll now = q.top().first;
		int x = q.top().second.first;
		int y = q.top().second.second;
		q.pop();
		//std::cout << x << ", " << y << ": " << now << std::endl;

		rep(i, 4){
			int nx = x + dx[i];
			int ny = y + dy[i];
			if(nx < 0 || ny < 0 || nx >= H || ny >= W) continue;
			if(s[nx][ny] == '#') continue;
			if(dp[nx][ny] <= now) continue;
			dp[nx][ny] = dp[x][y];
			q.push({now, {nx, ny}});
			
		}
		for(int i=-2; i<=2; i++){
			for(int j=-2; j<=2; j++){
				if(i == 1 && j == 0) continue;
				if(i == -1 && j == 0) continue;
				if(i == 0 && j == 1) continue;
				if(i == 0 && j == -1) continue;
				if(i == 0 && j == 0) continue;
				int nx = x + i;
				int ny = y + j;
				if(nx < 0 || ny < 0 || nx >= H || ny >= W) continue;
				if(s[nx][ny] == '#') continue;
				if(dp[nx][ny] <= now + 1) continue;
				dp[nx][ny] = dp[x][y] + 1;
				q.push({now + 1, {nx, ny}});
			}
		}
	}

	if(dp[gh][gw] != INF){
		std::cout << dp[gh][gw] << std::endl;
	}else{
		std::cout << -1 << std::endl;
	}

	return 0;
}

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

// Contest: AtCoder Beginner Contest 143 (https://atcoder.jp/contests/abc143)
// Problem: C: Slimes (https://atcoder.jp/contests/abc143/tasks/abc143_c)

using namespace std;

using ll = int64_t;
using u64 = uint64_t;
using u32 = uint32_t;

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

    int a, b; cin >> a >> b;
    if (a >= 10 || b >= 10)
        cout << "-1\n";
    else
        cout << (a*b) << '\n';

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
 
int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int n;
	cin >> n;
  	if (n%1000 == 0) cout<<0;
	else cout << 1000 - n%1000;
	return 0;
}

Measured memory_bytes: 3184
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
	int seat[17] = {0};
	int X = 0;
	int stop[100] = {0};
	int time = 0;
	queue<int> Q;
	while(X < 100){
		int x;
		if(time%5 == 0 && time < 500){
			Q.push(time/5);
		}
		while(1){
			if(Q.size())x = Q.front();
			else x = -1;
			bool f = false;
			
			if(~x){
				int people = (x%5==1?5:2);
				int use = 19 + 3 * (x%3) + 17 * (x%2);
				rep(i,17-people+1){
					bool flag = true;
					rep(j,people){
						flag &= seat[i+j] == 0;
					}
					if(flag){
						rep(j,people){
							seat[i+j] = use;
						}
						f = true;
						break;
					}
				}
			}
			if(f){	
				stop[x] = time - x * 5;
				Q.pop();
				X++;
			}
			if(!f)break;
		}
		rep(i,17){
			seat[i] = max(0,seat[i]-1);
		}
		time++;
	}
	int n,c=0;
	
	while(cin >> n){
		if(n == 0)c++;
		cout << stop[n] << endl;
	}
	int a = 0;
	while(c>=1){cout << a/a << endl;};
	
}

Measured memory_bytes: 0
#include<iostream>
#include<set>

using namespace std;

bool c(char ch){

    return (ch=='a'||ch=='i'||ch=='u'||ch=='e'||ch=='o');
}

int main(){

    while(1){
        int n;
        cin>> n;
        if(!n) break;

        string s[n];
        int L=0;
        for(int i=0; i<n; i++){
            cin>> s[i];
            L=max<int>(L, s[i].size());
        }
        string t[n];
        for(int i=0; i<n; i++){
            for(int j=0; j<s[i].size(); j++){
                if(j==0){
                    t[i]+=s[i][j];
                }else{
                    if(c(s[i][j-1])) t[i]+=s[i][j];
                }
            }
        }
        for(int k=1; ; k++){
            if(k>L){
                cout<< -1<< endl;
                break;
            }
            set<string> S;
            for(int i=0; i<n; i++){
                if(t[i].size()<k) S.insert(t[i]);
                else S.insert(t[i].substr(0, k));
            }
            if(S.size()==n){
                cout<< k<< endl;
                break;
            }
        }
    }

    return 0;
}

Measured memory_bytes: 3096
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define MOD1 1000000007
#define MOD2 998244353
#define LIMIT1 200002
#define LIMIT2 500002
typedef long long ll;
typedef long double ld;
typedef const void cv;
#define rep(i,n) for((i)=0;(i)<(n);(i)++)
#define per(i,n) for((i)=(n)-1;(i)>=0;(i)--)
#define max(a,b) ((a)>(b) ? (a) : (b))
#define min(a,b) ((a)<(b) ? (a) : (b))
#define zt(a,b) (max((a),(b))-min((a),(b)))
#define absl(v) labs((v))
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll nPr(int n,int r){ll i,result=1;rep(i,r){result*=(ll)(n-i);}return result;}
ll nCr(int n,int r){ll i,result=1;if(n<r) return 0;rep(i,min(r,n-r)){result*=(ll)(n-i);result/=(ll)(i+1);}return result;}
#define nHr(n,r) nCr((int)((n)+(r)+1),(int)(r))
#define sankaku(x) (((x)*((x)+1))/2)
int dx[8]={1,0,-1,0,1,-1,-1,1},dy[8]={0,1,0,-1,1,1,-1,-1};
int upint(cv *a, cv *b) { return *(int *)a < *(int *)b ? -1 : *(int *)a > *(int *)b ? 1 : 0; }
int downint(cv *a, cv *b) { return *(int *)a < *(int *)b ? 1 : *(int *)a > *(int *)b ? -1 : 0; }
int upchar(cv *left, cv *right) {return strcmp((char *)left,(char *)right);}
int downchar(cv *left, cv *right) {return strcmp((char *)right,(char *)left);}
int upll(cv *a, cv *b) { return *(ll *)a < *(ll *)b ? -1 : *(ll *)a > *(ll *)b ? 1 : 0; }
void tmpInit(int *c,ll m) {ll i;rep(i,m) c[i]=i;}
ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1){
      res *= a; if(mod>=1) res %= mod;
    }
    a *= a; if(mod>=1) a %= mod;
    n >>= 1;
  }
  return res;
}
void initialize(){
    
}
int main(void){
  initialize();
  ll n,m,i,j,k,result=1;
  ll a[LIMIT2];
  char s[LIMIT1];
  
  scanf("%lld",&n);
  rep(i,n){
    scanf("%lld",&a[i]);
  }
  qsort(a,n,sizeof(ll),upll);
  rep(i,n){
    if(a[i]==0){
      result=0;
      break;
    }else if((ld)powl(10,18)/result<a[i]){
      result = -1;
      break;
    }
    result *= a[i];
  }
  printf("%lld",result);
  
  return 0;
}



Measured memory_bytes: 3104
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int i,n;
	string s;
	cin>>n>>s;
	if(s.size()<=n)cout<<s;
	else 
	{
		for(i=0;i<n;i++)cout<<s[i];
		cout<<"...";
	}
	return 0;
}

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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
#define LINF 1e18
typedef long long ll;


int main() {
    int N; cin >> N;
    vector<int> A(N);
    REP(i,N) cin >> A[i];

    ll ans = 0;
    REP(i,N-1){
        if(A[i] > A[i+1]){
            ans += A[i]- A[i+1];
            A[i+1] = A[i];
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4044
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int s[]=new int[n];
        for(int i=0;i<n;i++) s[i]=sc.nextInt();
        int q=sc.nextInt();
        int cnt=0;
        for(int i=0;i<q;i++){
            int t=sc.nextInt();
            for(int j=0;j<n;j++){
                if(t==s[j]){
                    cnt++;
                    break;
                }
            }
        }
        System.out.println(cnt);
    }
}


Measured memory_bytes: 40708
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial#, gcd
from bisect import bisect_left #bisect_left(list, value)
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
pl = lambda x: print(*x, sep='\n')

S = input()
T = input()

for dif in range(len(S)):
    ok = True
    for i, t in zip(range(dif, dif+len(S)), T):
        ri = i%len(S)
        if S[ri] != t:
            ok = False
        if not(ok):
            break
    else:
        if ok:
            print('Yes')
            exit()
else:
    print('No')

Measured memory_bytes: 65664
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define ALL(v) (v).begin(), (v).end()
#define LENGTHOF(x) (sizeof(x) / sizeof(*(x)))
#define AFILL(a, b) fill((int*)a, (int*)(a + LENGTHOF(a)), b)
#define SQ(x) ((x)*(x))
#define Mod(x, mod) (((x)+(mod)%(mod))
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define INF 1 << 30
#define EPS 1e-10
#define MOD 1000000007
#define MAX_N 64

typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;

vector<int>X1,X2,Y1,Y2,Z1,Z2,xunzip,yunzip,zunzip;
map<int,int>xzip,yzip,zzip;
int X,Y,Z, N, K;
int sea[128][128][128];

int compress(vector<int> &x1, vector<int>&x2, map<int,int> &zip, vector<int> &unzip){
  vector<int>xs;
  /*  for(int i=0;i<N;i++){
    for(int d=-1;d<=1;d++){
      int tx1 = x1[i]+d, tx2 = x2[i]+d;
      if(0<=tx1 && tx1 <= 1000000) xs.push_back(tx1);
      if(0<=tx2 && tx2 <= 1000000) xs.push_back(tx2);
    }
    }*/
  rep(i, N) xs.push_back(x1[i]), xs.push_back(x2[i]);


  sort(xs.begin(), xs.end());
  xs.erase(unique(xs.begin(), xs.end()), xs.end());
  for(int i=0;i<xs.size();i++){
    zip[xs[i]] = i;
    unzip[i] = xs[i];
  }
  return xs.size();
}

int main(){
  scanf("%d%d", &N, &K);
  X1.resize(N); X2.resize(N); Y1.resize(N); Y2.resize(N); Z1.resize(N); Z2.resize(N);
  xunzip.resize(128); yunzip.resize(128), zunzip.resize(128);
  rep(i, N){
    scanf("%d%d%d%d%d%d", &X1[i], &Y1[i], &Z1[i], &X2[i], &Y2[i], &Z2[i]);
  }

  X = compress(X1, X2, xzip, xunzip);
  Y = compress(Y1, Y2, yzip, yunzip);
  Z = compress(Z1, Z2, zzip, zunzip);



  memset(sea, 0, sizeof(sea));
  int x,y,z;
  rep(i, N){
    REP(x, xzip[X1[i]], xzip[X2[i]]){
      REP(y, yzip[Y1[i]], yzip[Y2[i]]){
	REP(z, zzip[Z1[i]], zzip[Z2[i]]){
	  sea[z][y][x]++;
	}
      }
    }
  }

  /*  rep(z, Z-1){
    rep(y, Y-1){
      rep(x, X-1) printf("%d", sea[z][y][x]);
      puts("");
    }
    puts("");
    }*/

  ll res = 0;
  rep(z, Z-1) rep(y, Y-1) rep(x, X-1){
    if(sea[z][y][x]<K) continue;
    res += (ll)(zunzip[z+1]-zunzip[z]) * (ll)(yunzip[y+1]-yunzip[y]) * (ll)(xunzip[x+1]-xunzip[x]);
  }
  printf("%lld\n", res);
  return 0;
}

Measured memory_bytes: 9428
N = int(input())
T, A = map(int, input().split())
H = list(map(int, input().split()))
minv = abs(A - H[0] * 0.006)
ans = 1
for i in range(N):
    a = abs(A-(T-H[i]*0.006))
    if minv > a:
        minv = a
        ans = i+1
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using LL = long long int;
#define incID(i, l, r) for(int i = (l)    ; i <  (r); ++i)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); --i)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); ++i)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define dec(i, n)  decID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec1(i, n) decII(i, 1, n)
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define FI first
#define SE second
#define FR front()
#define BA back()
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
auto setmin   = [](auto & a, auto b) { return (b <  a ? a = b, true : false); };
auto setmax   = [](auto & a, auto b) { return (b >  a ? a = b, true : false); };
auto setmineq = [](auto & a, auto b) { return (b <= a ? a = b, true : false); };
auto setmaxeq = [](auto & a, auto b) { return (b >= a ? a = b, true : false); };
#define SI(v) static_cast<int>(v.size())
#define RF(e, v) for(auto & e: v)
#define until(e) while(! (e))
#define if_not(e) if(! (e))
#define ef else if
#define UR assert(false)
#define IN(T, ...) T __VA_ARGS__; IN_(__VA_ARGS__);
void IN_() { };
template<typename T, typename ... U> void IN_(T &  a, U &  ... b) { cin >> a; IN_(b ...); };
template<typename T                > void OUT(T && a            ) { cout << a << endl; }
template<typename T, typename ... U> void OUT(T && a, U && ... b) { cout << a << " "; OUT(b ...); }

// ---- ----

int main() {
	IN(int, x, n);
	set<int> se;
	inc(i, n) {
		IN(int, p);
		se.insert(p);
	}
	
	inc(i, 10000) {
		if(se.count(x - i) == 0) { OUT(x - i); break; }
		if(se.count(x + i) == 0) { OUT(x + i); break; }
	}
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repm(i, m, n) for (int i = m; i < (n); i++)
#define eps (1e-7)
#define inf (1e9)
#define pi (acos(-1))
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

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

    bool iseven = true;
    int count = 0;
    while (iseven)
    {
        rep(i, n)
        {
            if (a[i] % 2 == 1)
            {
                iseven = false;
                break;
            }
            a[i] /= 2;
        }
        if (iseven)
            count++;
    }

    cout << count << endl;

    return 0;
}

Measured memory_bytes: 256
import bisect

N = int(input())
Ali = [int(input()) for _ in range(N)]
dp = [10**10]*N
dp[0] = Ali[0]

for i in range(1,N):
  a = Ali[i]
  if a > dp[i-1]:
    dp[i] = a
  else:
    dp[bisect.bisect_left(dp, a)] = a
    
print(bisect.bisect_left(dp, 10**10))


Measured memory_bytes: 10468
#include "bits/stdc++.h"
#include "math.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef vector<pair<ll,ll> > vp;
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define drep(i,a,b) for(ll i=(a);i>(b);--i)
const int MOD = 1000000007;
const int MAX = 510000;

int main(){
  ll w,h,n,wr,wl=0,hu=0,hd;cin>>w>>h>>n;
  wr=w;hd=h;
  rep(i,0,n){
    ll x,y,a;cin>>x>>y>>a;
    if(a==1){wl=max(wl,x);}
    if(a==2){wr=min(wr,x);}  
    if(a==4){hd=min(hd,y);}
    if(a==3){hu=max(hu,y);}
  }
  if(wl<wr&&hu<hd){cout<<(wr-wl)*(hd-hu)<<endl;}
  else{cout<<0<<endl;}
}




Measured memory_bytes: 256
/* by Natsu Kinmoe */
#include <bits/stdc++.h>
using namespace std;
#define SZ(x)               ((int)(x).size())
#define all(x)              (x).begin(), (x).end()
#define loop(i, n)          for(int i = 0; i < (n); i++)
#define cont(i, n)          for(int i = 1; i <= (n); i++)
#define circ(i, a, b)       for(int i = (a); i <= (b); i++)
#define range(i, a, b, c)   for(int i = (a); ((c) > 0 ? i <= (b) : i >= (b)); i += (c))
#define foreach(it, v)      for(__typeof((v).begin()) it = (v).begin(); it != (v).end(); it++)
#define y0          y0O0OO00OO0OO0OO0OOO00OO0OO0O0O000OO0
#define y1          y1II11II11III11I1III11II111IIII1II1I1
#define pub         push_back
#define pob         pop_back
#define mak         make_pair
typedef long long   ll;
typedef long double lf;
const int   Inf = 0x3f3f3f3f;
const ll    INF = 0x3f3f3f3f3f3f3f3fll;
/* Source code starts here */

int main() {
	int k; cin >> k;
	loop(i, k) cout << "ACL";
	return 0;
}


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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

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

	int r;
	cin>>r;
	cout<<r*r;
					                                				
	cerr<<"\nTime elapsed: " << 1000.0 * clock() / CLOCKS_PER_SEC << " ms\n";
	
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000000;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}


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



int main() {

	ll N;
	ll P[MAX];
	cin >> N;
	repn(i, N) cin >> P[i];

	ll ans = 0;
	ll m = N + 1;

	repn(i, N) {
		if (P[i] < m) { ans++; m = P[i]; }
	}

	cout << ans;
	
	system("PAUSE");

}


Measured memory_bytes: 3840
#include "bits/stdc++.h"
using namespace std;

#define FOR(i,a,b) for(int (i)=(a);i<(int)(b);i++)
#define rep(i,n) FOR(i,0,n)
#define mset(a,x) memset(a,x,sizeof(a))

struct Circle {
    int x, y, r;
};
Circle read() {
    int x, y, r;
    scanf("%d%d%d", &x, &y, &r);
    return Circle{x, y, r};
}
const double INF = 1145141919810893;
int n;
double cost[1010][1010];
double d[1010];
bool used[1010];

void dijkstra(int s) {
    mset(used, 0);
    fill(d, d + 1010, INF);
    d[s] = 0;
    const int N = n + 2;
    while (1) {
        int v = -1;
        rep(to, N) {
            if (!used[to] && (v == -1 || d[to] < d[v])) v = to;
        }
        if (v == -1) break;
        used[v] = true;
        rep(to, N) d[to] = min(d[to], d[v] + cost[v][to]);
    }
}

int main() {
    vector<Circle> cs;
    rep(i, 1010) rep(j, 1010) cost[i][j] = INF;
    rep(i, 2) {
        int x, y; cin >> x >> y;
        cs.push_back(Circle{x,y,0});
    }
    cin >> n;
    rep(i, n) cs.push_back(read());
    rep(i, n + 2) rep(j, n + 2) {
        double d = hypot(cs[i].x - cs[j].x, cs[i].y - cs[j].y) - cs[i].r - cs[j].r;
        if (d < 0) d = 0.;
        cost[i][j] = d;
    }

    dijkstra(0);
    printf("%.10f\n", d[1]);
    return 0;
}

Measured memory_bytes: 8192
#include <stdio.h>

int main(void){
  int i,n;
  unsigned long long money = 100000,
                     money_;
  scanf("%d\n",&n);
  for(i = 0;i < n;i++){
    money += (unsigned long long)(money * 0.05);
    money_ = money / 1000;
    if(money_ * 1000 != money){
      money = (money_ + 1) * 1000;
    }
  }
  printf("%lu\n",money);
  return 0;
}

Measured memory_bytes: 600
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int n = sc.nextInt();
        int count = 0;
        int ans = 0;
		for(int i = 1;i <= n; i++){
          for(int j = 1;j <= i;j++){
            if(i % j == 0){
              count += 1;
            }
          }
          if(count == 8){
            ans += 1;
          }
          count = 0;
          i++;
          
        }
      
      System.out.println(ans);
      
    }
}

Measured memory_bytes: 35608
import java.util.Scanner;

public class Main {
	final int INF = Integer.MAX_VALUE;

	int mergeCount = 0;
	void run() {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int[] s = new int[n];
		for (int i = 0; i < n; i++)
			s[i] = scan.nextInt();
		mergeSort(s, 0, n);
		for (int i = 0; i < n; i++)
			System.out.print(s[i] + (i == n - 1 ? "\n" : " "));
		System.out.println(mergeCount);
	}
	
	void mergeSort(int[] a, int left, int right) {
		if (left + 1 < right) {
			int mid = (left + right) / 2;
			mergeSort(a, left, mid);
			mergeSort(a, mid, right);
			merge(a, left, mid, right);
		}
	}
	
	void merge(int[] a, int left, int mid, int right) {
		int n1 = mid - left;
		int n2 = right - mid;

		int[] l = new int[n1 + 1];
		int[] r = new int[n2 + 1];
		for (int i = 0; i < n1; i++)
			l[i] = a[left + i];
		for (int i = 0; i < n2; i++)
			r[i] = a[mid + i];
		l[n1] = r[n2] = INF;
		
		int i = 0, j = 0;
		for (int k = left; k < right; k++) {
			mergeCount++;
			if (l[i] <= r[j])
				a[k] = l[i++];
			else
				a[k] = r[j++];
		}
	}
	public static void main(String[] args) {
		new Main().run();
	}
}



Measured memory_bytes: 170340
#include<bits/stdc++.h>
using namespace std;
double a,b,amin,bmin,bmax,amax;
int ans,flag;
int work(double a)
{
	int k=0;
	while(k*1.0000000<=a)
	{
		k++;
		if(k*1.0000000>a)
		{
			return k-1;
		}
	}
}
int main()
{
	scanf("%lf%lf",&a,&b);
	amin=a/0.08;
	amax=(a+1)/0.08;
	bmin=b/0.1;
	bmax=(b+1)/0.1;
	if(amin>=bmin&&amin<bmax)
	{
		ans=work(amin);
		while(ans<amax&&ans<bmax)
		{
			if(ans*0.1>=b&&ans*0.1<b+1&&ans*0.08>=a&&ans*0.08<a+1)
		    {
			    printf("%d",ans);
			    return 0;
		    }
		    ans++;
		}
	}
	if(bmin>=amin&&bmin<amax)
	{
		ans=work(bmin);
		while(ans<amax&&ans<bmax)
		{
			if(ans*0.1>=b&&ans*0.1<b+1&&ans*0.08>=a&&ans*0.08<a+1)
		    {
			    printf("%d",ans);
			    return 0;
		    }
		    ans++;
		}
	}
	printf("-1");
	return 0;
}
/*
1 2
*/

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

int main() {
    int H, W;
    cin >> H >> W;
    vector<string> G(H);
    rep(i, H) cin >> G[i];
    queue<pair<int, int>> Q;
    vector<vector<int>> dist(H, vector<int>(W));
    rep(i, H) rep(j, W) {
        if(G[i][j] == '#') {
            Q.emplace(i, j);
            dist[i][j] = 1;
        }
    }

    const int dx[4] = {1, 0, -1, 0};
    const int dy[4] = {0, 1, 0, -1};

    int ans = 1;
    while(!Q.empty()) {
        pair<int, int> cur = Q.front(); Q.pop();
        int y = cur.first, x = cur.second;
        for(int i = 0; i < 4; ++i) {
            int ny = y + dy[i], nx = x + dx[i];
            if(ny < 0 || nx < 0 || ny >= H || nx >= W) continue;
            if(dist[ny][nx]) continue;
            if(G[ny][nx] == '.') {
                Q.push(make_pair(ny, nx));
                dist[ny][nx] = dist[y][x] + 1;
                ans = max(ans, dist[ny][nx]);
            }
        }
    }
    cout << ans - 1 << '\n';
    return 0;
}


Measured memory_bytes: 13456
#include "bits/stdc++.h"
using namespace std;
const int N = 1e5 + 5;
int n , m;
int sz[N];
int red[N];
int x , y;
int main(){
    scanf("%d %d" , &n , &m);
    for(int i = 1 ; i <= n ; ++i){
        sz[i] = 1;
        red[i] = 0;
    }
    red[1] = 1;
    for(int i = 1 ; i <= m ; ++i){
        scanf("%d %d" , &x , &y);
        if(red[x]){
            red[y] = 1;
        }
        --sz[x];
        ++sz[y];
        if(!sz[x]){
            red[x] = 0;
        }
    }
    int ans = 0;
    for(int i = 1 ; i <= n ; ++i){
        ans += red[i];
    }
    printf("%d\n" , ans);
}

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

bool isin(int n, int x[]){
	for (int i=0; i<4; i++)
		if (n==x[i]) return true;
	return false;
}

int main(void){
	
	while (true){
		int a[4],b[4];
		for (int i=0; i<4; i++)
			cin>>a[i];
		if (cin.eof()) break;
		for (int i=0; i<4; i++)
			cin>>b[i];

		int c1=0, c2=0;
		for (int i=0; i<4; i++)
			if (isin(a[i], b))
				if (a[i]==b[i]) c1++;
				else c2++;
		cout<<c1<<" "<<c2<<endl;
	}
	return 0;
}

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

typedef pair<int, int> P;

int main(){
    while(1){
        int n; cin>>n;
        if(n == 0) return 0;

        vector<int> ans;
        vector<vector<P>> base(4);
        for(int i=0; i<=n; i++){
            int m; cin>>m;
            
            vector<int> x(m), y(m);
            for(int j=0; j<m; j++) cin>>x[j]>>y[j];

            if(i == 0){
                for(int j=0; j<m-1; j++){
                    int dx = x[j+1] - x[j];
                    int dy = y[j+1] - y[j];

                    base[0].emplace_back(dx, dy);
                }

                for(int j=1; j<4; j++){
                    for(int k=0; k<m-1; k++){
                        int pdx = base[j-1][k].first;
                        int pdy = base[j-1][k].second;
                        if(pdx == 0){
                            base[j].emplace_back(pdy, pdx);
                        }
                        else{
                            base[j].emplace_back(pdy, -pdx);
                        }
                    }
                }
            }
            else{
                if(m != base[0].size() + 1){
                    continue;
                }

                for(int j=0; j<4; j++){
                    bool same = true;
                    for(int k=0; k<m-1; k++){
                        int dx = x[k+1] - x[k];
                        int dy = y[k+1] - y[k];

                        if(!(base[j][k].first == dx && base[j][k].second == dy)){
                            same = false;
                        }
                    }

                    if(same){
                        ans.emplace_back(i);
                        break;
                    }

                    same = true;
                    for(int k=m-2; k>=0; k--){
                        int dx = x[k] - x[k+1];
                        int dy = y[k] - y[k+1];

                        if(!(base[j][m-2-k].first == dx && base[j][m-2-k].second == dy)){
                            same = false;
                        }
                    }

                    if(same){
                        ans.emplace_back(i);
                        break;
                    }
                }
            }
        }

        for(auto i:ans) cout << i << endl;
        cout << "+++++" << endl;
    }
}


Measured memory_bytes: 3024
#include <bits/stdc++.h>
#define pb push_back
#define wrln cout<<'\n';
using namespace std;
 
 
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0) ;
    int d=0;
    int f[100];
    for (int i='0'; i<='9' ; i++)
    {
        f[i]=d++;
    }
    char a; string s;
    cin>>s;
    int sum=0;
    for (auto a:s)
    {
        sum+=f[a];
    }
    if (0 == sum%9) cout<<"Yes"; else cout<<"No";
}
 

Measured memory_bytes: 3720
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
#define pb push_back
#define ld long double
#define f first
#define s second
#define in insert
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int INF = 1e18 + 5;
const int mod = 1e9 + 7;
const int  N = 2e5 + 314;
const long double pi = 3.1415926535897932384626433832795;
void solve(){
    int a, b;
    cin>>a>>b;
    cout<<a*b;
}
signed main(){
    speed;
    int t=1;
    //cin>>t;
    while(t--)solve();
}

Measured memory_bytes: 3652
def main():
    N = int(input())

    primes = sieve(N+1)
    res = 1
    for p in primes:
        f = 0
        i = 1
        while p ** i <= N:
            f += (N//(p**i))
            i += 1
        res *= f + 1
        res = res % (10**9 + 7)

    print(res)

def sieve(n):
    s = [True] * n
    for x in range(2, int(n**0.5) + 1):
        if s[x]: mark(s, x)
    return [i for i in range(0,n) if s[i] and i > 1]

def mark(s, x):
    for i in range(x + x, len(s), x):
        s[i] = False

if __name__ == "__main__":
    main()


Measured memory_bytes: 3192
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <cctype>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <complex>
#include <fstream>
#include <iomanip>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T> T RoundOff(T a){ return int(a+.5-(a<0)); }
template<class T, class C> void chmax(T& a, C b){ if(a < b) a = b; }
template<class T, class C> void chmin(T& a, C b){ if(b < a) a = b; }
template<class T, class C> pair<T, C> mp(T a, C b){ return make_pair(a, b); }


int tanri(int year, int money, double c, double b)
{
	int pool = 0;
	rep(i, year)
	{
		pool += money * c;
		money -= b;
	}

	return money + pool;
}

int hukuri(int year, int money, double c, double b)
{
	rep(i, year)
	{
		money *= 1.0 + c;
		money -= b;
	}

	return money;
}

int main()
{
	int m;
	cin >> m;
	while(m--)
	{
		double money, year, n;
		cin >> money >> year >> n;

		int res = 0;
		rep(i, n)
		{
			double f, c, b;

			cin >> f >> c >> b;
			

			if(!f) chmax(res, tanri(year, money, c, b));
			else  chmax(res, hukuri(year, money, c, b));
		}

		cout << res << endl;
	}
}

Measured memory_bytes: 0
#include<stdio.h>
#define MAX_SIZE 256

int count(int num);

int main(){
	int num[2];
	
	while(scanf("%d %d", num, num+1) != EOF)
	{
		printf("%d\n", count(num[0] + num[1]));
	}
	
	return 0;
}

int count(int num)
{
	int ans = 0;
	
	while(num > 0)
	{
		ans++;
		num /= 10;
	}
	
	return ans;
}

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

int main()
{
    long n,c=0;
    cin>>n;
    long long a[n+1];
    for(int i=1;i<=n;i++)
    { 
         cin>>a[i];
         if(i%2==1 && a[i]%2==1)
         c++;
    }
    cout<<c<<endl;
    return 0;
}

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

int main(void){
    int n;

    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    cout << fixed << setprecision(10) << (n % 2 == 0? n / 2 / (double) n : (n + 1) / 2 / (double) n) << "\n";
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<climits>
#include<iostream>
#include<sstream>
#include<utility>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
#include<stack>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
int V,E,r,C[100000];
vector<P> G[100000];

void dij(int s)
{
	C[s]=0;
	priority_queue<P> Q;
	Q.push(make_pair(s,0));
	for(;!Q.empty();)
	{
		P t=Q.top();Q.pop();
		for(int i=0;i<G[t.first].size();i++)
		{
			if(C[G[t.first][i].first]>t.second+G[t.first][i].second)
			{
				C[G[t.first][i].first]=t.second+G[t.first][i].second;
				Q.push(make_pair(G[t.first][i].first,C[G[t.first][i].first]));
			}
		}
	}
}

int main()
{
	memset(C,0x7f,sizeof(C));
	scanf("%d%d%d",&V,&E,&r);
	for(int i=0;i<E;i++)
	{
		int s,t,d;
		scanf("%d%d%d",&s,&t,&d);
		G[s].push_back(make_pair(t,d));
		//G[t].push_back(make_pair(s,d));
	}
	dij(r);
	for(int i=0;i<V;i++)
	{
		if(C[i]==2139062143)puts("INF");
		else printf("%d\n",C[i]);
	}
	return 0;
}

Measured memory_bytes: 20516
//08
#include<iostream>
#include<string>
#include<algorithm>

using namespace std;

int main(){
  for(int n,m;cin>>n>>m,n|m;){
    string c(n,'#');
    for(int i=0;i<m;i++){
      char p;
      cin>>p;
      switch(p){
      case 'B':
	int j;
	for(j=c.size()-1;j>=0;j--){
	  if(c[j]=='#'&&(j==0||c[j-1]!='A')&&(j==c.size()-1||c[j+1]!='A')){
	    c[j]=p;
	    break;
	  }
	}
	if(j>=0)break;
      case 'A':
	for(int j=0;j<c.size();j++){
	  if(c[j]=='#'){
	    c[j]=p;
	    break;
	  }
	}
	break;
      case 'C':
	if(i==0){
	  c[n/2]=p;
	}else{
	  for(int j=0;j<c.size();j++){
	    if(c[j]!='#'){
	      if(j!=c.size()-1&&c[j+1]=='#'){
		c[j+1]=p;
		break;
	      }else if(j!=0&&c[j-1]=='#'){
		c[j-1]=p;
		break;
	      }
	    }
	  }
	}
	break;
      case 'D':
	if(i==0){
	  c[0]=p;
	}else{
	  int b;
	  int d=-1;
	  for(int j=0;j<c.size();j++){
	    if(c[j]=='#'){
	      int cd;
	      int l;
	      for(l=j;l>=0&&c[l]=='#';l--);
	      cd=(l<0)?1000:j-l;
	      int r;
	      for(r=j;r<n&&c[r]=='#';r++);
	      cd=min(cd,(r==n)?1000:r-j);
	      if(d<cd){
		d=cd;
		b=j;
	      }
	    }
	  }
	  c[b]=p;
	}
	break;
      }
    }
    cout<<c<<endl;
  }
  return 0;
}

Measured memory_bytes: 1208
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;

#define INF 1LL << 61
#define MAX (1LL << 31) -1
#define MOD 1000000007

typedef long long ll;
typedef pair<int,int> pi;
//typedef pair<pair<int,int>,ll> p;
#define bit(n, k) ((n >> k) & 1) /*nのk bit目*/
#define rad_to_deg(rad) (((rad) / 2 / M_PI) * 360)
template<class T,class U>bool inline chmin(T&a,const U&b){if(a<=b)return false;a=b;return true;}
template<class T,class U>bool inline chmax(T&a,const U&b){if(a>=b)return false;a=b;return true;}
//__builtin_popcount(S);
//C.erase(unique(C.begin(),C.end()),C.end());
//#define int ll
int dx[]={1,-1,0,0},dy[]={0,0,-1,1};

signed main(){
    while(true){
        int N,M;
        cin>>N>>M;
        if(N==0 && M==0) return 0;

        vector<int> C(M);
        for(int i=0;i<M;i++) cin>>C[i];
        vector<int> x(N);
        for(int i=0;i<N;i++) cin>>x[i];
        vector<vector<ll>> dp(N+1,vector<ll>(256,INF));
        dp[0][128]=0;
        for(int i=0;i<N;i++){
            for(int j=0;j<256;j++){
                if(dp[i][j]==INF) continue;
                for(int k=0;k<M;k++){
                    int jj=j+C[k];
                    if(jj<0) jj=0;
                    else if(jj>255) jj=255;
                    chmin(dp[i+1][jj],dp[i][j]+(ll)(x[i]-jj)*(x[i]-jj));
                }
            }
        }
        ll ans=INF;
        for(int i=0;i<256;i++){
            chmin(ans,dp[N][i]);
        }
        cout<<ans<<endl;
    }
}


Measured memory_bytes: 43884
#include <bits/stdc++.h>
#define R register
#define MN 105
#define eps 5e-10
const double pi = acos(-1);
typedef long long ll;
inline int read(){
	R int x; R bool f; R char c;
	for (f=0; (c=getchar())<'0'||c>'9'; f=c=='-');
	for (x=c^'0'; (c=getchar())>='0'&&c<='9'; x=(x<<1)+(x<<3)+(c^'0'));
	return f?-x:x;
}
struct P{
	int x,y,no;
	inline P operator - (const P &b)const{return (P){x-b.x,y-b.y};}
	inline ll operator * (const P &b)const{return (ll)x*b.x+(ll)y*b.y;}
	inline ll operator / (const P &b)const{return (ll)x*b.y-(ll)y*b.x;}
	inline bool operator <(const P &b)const{return b.x==x?y<b.y:x<b.x;}
	inline double mod(){return sqrt((ll)x*x+(ll)y*y)+eps;}
	inline ll mod2(){return (ll)x*x+(ll)y*y;}
}pt[MN];int n,tp,que[MN];double ans[MN];
inline bool cmp(P a,P b){return (a-pt[1])/(b-pt[1])?(a-pt[1])/(b-pt[1])>0:(a-pt[1]).mod2()<(b-pt[1]).mod2();}
inline double angle(P a,P b,P c){return acos((b-a)*(c-a)/(b-a).mod()/(c-a).mod());}
int main(){
	n=read();for (R int i=1; i<=n; ++i) pt[i]=(P){read(),read(),i},pt[i]<pt[1]?std::swap(pt[i],pt[1]),0:0;
	std::sort(pt+2,pt+n+1,cmp);for (R int i=1; i<=n; que[++tp]=i++)
		while(tp>1&&(pt[que[tp]]-pt[que[tp-1]])/(pt[i]-pt[que[tp-1]])<=0) --tp;
	ans[pt[que[1]].no]=(pi-angle(pt[que[1]],pt[que[2]],pt[que[tp]]))/(pi*2);
	ans[pt[que[tp]].no]=(pi-angle(pt[que[tp]],pt[que[tp-1]],pt[que[1]]))/(pi*2);
	for (R int i=2; i<tp; ++i)
		ans[pt[que[i]].no]=(pi-angle(pt[que[i]],pt[que[i-1]],pt[que[i+1]]))/(pi*2);
	for (R int i=1; i<=n; ++i) printf("%.10lf\n",(ans[i]));
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main()
{
  int n;
  ll k;
  cin >> n >> k;
  vector<pair<int, int>> v(n);
  for (auto &e : v)
    cin >> e.first >> e.second;

  sort(v.begin(), v.end());

  ll itr = 0;
  int ans = 0;
  for (int i = 0; i < n; ++i)
  {
    itr += v[i].second;
    if (itr >= k)
    {
      ans = v[i].first;
      break;
    }
  }

  cout << ans << endl;

  return 0;
}


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

int main(){
    long long INF = 1LL << 60;
    int n;
    cin >> n;
    vector<int> dp(n);
    vector<int> h(n);
    for(int i = 0;i < n;i++) cin >> h[i];
    dp[0] = 0;
    for(int i = 1;i < n;i++) dp[i] = INF;

    for(int i = 1;i< n;i++){
        if(i == 1) dp[i] = dp[i] + abs(h[i-1] - h[i]);
        else{
            dp[i] = min(dp[i-1] + abs(h[i-1] - h[i]),dp[i-2] + abs(h[i-2] - h[i]));
        }
    } 
    cout << dp[n-1] << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
template<class T> inline bool chmin(T& a, T b){if(a > b){a = b; return true;} return false;}

typedef long long ll;

int main(){
  ll n, k;
  cin >> n >> k;
  
  while(1){
    if (k > n*2){
      cout << n << endl;
      return 0;
    }
    else if (k >= n){
      cout << abs(k-n);
      return 0;
    }
    else {
      n = n % k;
    }
  }
  
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long n,a,b,c,d;
int main()
{
	cin>>n;
	a=n/1000%10;
	b=n/100%10;
	c=n/10%10;
	d=n%10;
	if((a==b && b==c) || (b==c && c==d))
	{
		cout<<"Yes"<<endl;
		return 0;
	}
	else cout<<"No"<<endl;

	return 0;
}

Measured memory_bytes: 256
# include <bits/stdc++.h>
# define rep(i, n) for(ll i = 0; i < (n); ++i)
# define reps(i, n) for(ll i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(ll i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(ll i=((int)(n)); i>0; --i)
# define ll long long
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define optimize_cin() cin.tie(0); ios::sync_with_stdio(false)
# define P pair<int, int>
# define mp make_pair
# define x first
# define y second
using namespace std;
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; }

ll gcd (ll x, ll y) {
  if(x==0) return y;
  return gcd(y%x,x);
}

int main() {
  ll a, b, c, d; cin >> a >> b >> c >> d;

  ll lcm = c / gcd(c, d) * d;
  ll ans = b - a + 1 - (b/c - (a-1)/c + b/d - (a-1)/d - b/lcm + (a-1)/lcm);
  cout << ans << endl;
}


Measured memory_bytes: 3580
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
typedef long long ll;
typedef pair<int, int> pi;
typedef vector<int> vi;
template <class Key, class Compare = less<Key>>
using Tree = __gnu_pbds::tree<Key, __gnu_pbds::null_type, Compare, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>;



int N, K;
int a[101];
bool dp[100001];

void Main() {
  cin >> N >> K;
  for (int i = 0; i < N; ++i) {
    cin >> a[i];
  }
  fill(dp, dp+K+1, 0);
  for (int i = 0; i < N; ++i) {
    dp[a[i]] = 1;
  }
  for (int k = 1; k <= K; ++k) {
    for (int i = 0; i < N; ++i) {
      if (a[i] > k || dp[k]) break;
      dp[k] = !dp[k - a[i]];
    }
  }
  cout << (dp[K] ? "First\n" : "Second\n");
}

int main() {
  ios::sync_with_stdio(false);
//  cin.tie(nullptr);
  #ifdef _DEBUG
//  freopen("in.txt", "r", stdin);
//  freopen("out.txt", "w", stdout);
  #endif
  Main();
  return 0;
}


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

/***********************************************/
/* Dear online judge:
 * I've read the problem, and tried to solve it.
 * Even if you don't accept my solution, you should respect my effort.
 * I hope my code compiles and gets accepted.
 *  ___  __     _______    _______
 * |\  \|\  \  |\  ___ \  |\  ___ \
 * \ \  \/  /|_\ \   __/| \ \   __/|
 *  \ \   ___  \\ \  \_|/__\ \  \_|/__
 *   \ \  \\ \  \\ \  \_|\ \\ \  \_|\ \
 *    \ \__\\ \__\\ \_______\\ \_______\
 *     \|__| \|__| \|_______| \|_______|
 */
const long long mod = 1000000007;

struct DSU{
	vector<int> p,sz;
	DSU(int N){
		p.resize(N);
		sz.resize(N,1);
		for(int i = 0;i < N;i++)p[i] = i;
	}
	int par(int x){
		if(x == p[x])
			return x;
		return p[x] = par(p[x]);
	}
	bool mrg(int x,int y){
		x = par(x),y = par(y);
		if(x == y)
			return false;
		if(sz[x] < sz[y]){
			swap(x,y);
		}
		p[y] = p[x];
		sz[x] += sz[y];
		return true;
	}
};

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

	int N,M,x,y;
	cin>>N>>M;
	vector<int> at(N+1);
	DSU d(N+1);
	for(int i = 1;i <= N;i++) cin>>at[i];
	for(int i = 0;i < M;i++) {
		cin>>x>>y;
		d.mrg(x,y);
	}
	int res = 0;
	for(int i = 1;i <= N;i++) {
		res += d.par(i) == d.par(at[i]);
	}
	cout<<res<<'\n';
	return 0;
}


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

#define for_(i,a,b) for(int i=(a);i<(b);++i)

void safe() { puts("SAFE"); }
void susp() { puts("SUSPICIOUS"); }

int NUM_CASES, H, W;
string img[55];

int lft[26], top[26], rgt[26], bot[26];
char c_img[55][55];

void solve() {
	for_(i,0,26) {
		lft[i] = top[i] = 55;
		rgt[i] = bot[i] = -1;
	}
	
	for_(y,0,H) for_(x,0,W) {
		if (img[y][x] != '.') {
			int c = img[y][x] - 'A';
			lft[c] = min(lft[c], x);
			top[c] = min(top[c], y);
			rgt[c] = max(rgt[c], x);
			bot[c] = max(bot[c], y);
		}
	}
	
	vector< int > obj;
	for_(i,0,26) if (rgt[i] != -1) obj.push_back(i);
	
	if (obj.size() == 0) {
		safe();
		return;
	}
	
	do {
		for_(y,0,H) for_(x,0,W) c_img[y][x] = '.';
		for (int o : obj) for_(y,top[o],bot[o]+1) for_(x,lft[o],rgt[o]+1) c_img[y][x] = char('A' + o);
		bool isok = true;
		for_(y,0,H) for_(x,0,W) isok &= (img[y][x] == c_img[y][x]);
		
		if (isok) {
			safe();
			return;
		}
	} while (next_permutation(obj.begin(), obj.end()));
	
	susp();
}

int main() {
	cin >> NUM_CASES;
	for_(t,0,NUM_CASES) {
		cin >> H >> W;
		for_(i,0,H) cin >> img[i];
		solve();
	}
}

Measured memory_bytes: 3072