akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main() {
  string s;
  cin >> s;
  int n = (int)s.length() - 1;
  long res = 0;

  for (int bit = 0; bit < (1<<n); ++bit) {
    int i = 0;
    for (int j = 0; j < n; ++j) {
      if (bit & (1<<j)) {
        res += atol(s.substr(i, j - i + 1).c_str());
        i = j + 1;
      }
    }
    res += atol(s.substr(i, n - i + 1).c_str());
  }
  cout << res << endl;
}


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

typedef long long LL;

int n,h,w;
string fi[405];
bool vis[405][405];
int p[] ={1,0,-1,0};
int q[] ={0,1,0,-1};

LL bfs(int x, int y){
vis[x][y] = 1;
LL bl, wh;
bl=wh=0LL;
queue<int> qx,qy;
qx.push(x);
qy.push(y);
while(!qx.empty()){
int nx=qx.front(); qx.pop();
int ny=qy.front(); qy.pop();
if(fi[nx][ny] == '#') bl++;
else wh++;
for(int i=0;i<4;i++){
int cx = nx+p[i];
int cy = ny+q[i];
if(cx<0 || cx >=h || cy<0 || cy>= w || vis[cx][cy] || fi[cx][cy] == fi[nx][ny]) continue;
vis[cx][cy] = 1;
qx.push(cx);
qy.push(cy);
}
}
return bl*wh;
}

int main(){
cin>>h>>w;
for(int i=0;i<h;i++) cin >> fi[i];
LL ans = 0LL;
for(int i=0;i<h;i++)
for(int j=0;j<w;j++)
if(!vis[i][j]) ans+= bfs(i,j);
printf("%lld\n",ans);
return 0;
}


Measured memory_bytes: 640
n = int(input())
arr = list(map(int, input().split()))
dp = [0] * (n+1)
dp[0] = 0
dp[1] = abs(arr[1]-arr[0])
for i in range(2,n):
    dp[i] = min(dp[i-1]+abs(arr[i]-arr[i-1]), dp[i-2] + abs(arr[i]-arr[i-2]))
print(dp[n-1])

Measured memory_bytes: 13928
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;

#define REP(i,n) for(int (i)=0; (i)<(n); (i)++)
#define For(i,a,b) for(int (i)=(a); (i)<(b); (i)++)

class Dice {
    vector<int> v;
public:
    Dice(int a, int b, int c, int d, int e, int f);
    int getTop();
    void east();
    void south();
    void north();
    void west();
};

Dice::Dice(int a, int b, int c, int d, int e, int f) {
    v.push_back(a);
    v.push_back(b);
    v.push_back(c);
    v.push_back(d);
    v.push_back(e);
    v.push_back(f);
}

int Dice::getTop() {
    return v[0];
}

void Dice::east() {
    vector<int> e;
    e.push_back(v[3]);
    e.push_back(v[1]);
    e.push_back(v[0]);
    e.push_back(v[5]);
    e.push_back(v[4]);
    e.push_back(v[2]);
    REP(i,6) v[i] = e[i];
}

void Dice::south() {
    vector<int> e;
    e.push_back(v[4]);
    e.push_back(v[0]);
    e.push_back(v[2]);
    e.push_back(v[3]);
    e.push_back(v[5]);
    e.push_back(v[1]);
    REP(i,6) v[i] = e[i];
}

void Dice::north() {
    vector<int> e;
    e.push_back(v[1]);
    e.push_back(v[5]);
    e.push_back(v[2]);
    e.push_back(v[3]);
    e.push_back(v[0]);
    e.push_back(v[4]);
    REP(i,6) v[i] = e[i];
}

void Dice::west() {
    vector<int> e;
    e.push_back(v[2]);
    e.push_back(v[1]);
    e.push_back(v[5]);
    e.push_back(v[0]);
    e.push_back(v[4]);
    e.push_back(v[3]);
    REP(i,6) v[i] = e[i];
}

int main() {
    int a, b, c, d, e, f;
    cin >> a >> b >> c >> d >> e >> f;
    Dice dice(a,b,c,d,e,f);
    string o;
    cin >> o;
    REP(i,o.size()) {
        if (o[i] == 'S') dice.south();
        else if (o[i] == 'E') dice.east();
        else if (o[i] == 'W') dice.west();
        else dice.north();
    }
    cout << dice.getTop() << endl;
    return 0;
}

Measured memory_bytes: 1228
#include <iostream>
#include <stdio.h>
using namespace std;
 
 int main() {
  int pr[10001],i,j,n;
  for (i=0;i<10001;i++) pr[i]=1;
  for (i=2;i<5000;i++) if (pr[i]==1) for (j=i+i;j<10001;j+=i) pr[j]=0;
  while(cin >> n) {
	  if (n==0) break;
	  for (;n>4;n--) if (pr[n]==1 && pr[n-2]==1) { cout << n-2 << ' ' << n << endl; break; }
  }
  return 0;
 }

Measured memory_bytes: 1196
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define uint unsigned long long
#define double long double
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n) for (int i = 1; i <= (n); i++)
#define all(x) begin(x), end(x)
using vint = vector<int>;
using vvint = vector<vint>;
using vchar = vector<char>;
using vvchar = vector<vchar>;
constexpr double pi = 3.1415926535897932384626433832795028L;

int gcd(int a, int b) {
    while (b) { swap(a %= b, b); }
    return a;
}
int lcm(int a, int b) {
    return a / gcd(a, b) * b;
}
int sigma(int n){
    int sum=0;
    for (int i=1; i<=(n); i++){
        sum+=i;
    }
    return sum;
}
int sigma_2(int n) {
  if (n == 0) {
    return 0;
  }
  return n + sigma_2(n - 1);
}
int sum_range(int a, int b) {
  if (a == b) {
    return a;
  }
  return sum_range(a, b - 1) + b;
}
int distance(int yo,int xo,int yi,int xi){
    return (yo-yi)*(yo-yi)+(xo-xi)*(xo-xi);
}

int array_sum_from_i(vint &data, int i) {
  if (i == data.size()) {
    return 0;
  }
  int s = array_sum_from_i(data, i + 1);
  return data[i] + s;
}
int array_sum(vint &data) {
  return array_sum_from_i(data, 0);
}
bool has_divisor(int N, int i) {
  if (i == N) {
    return false;
  }
  if (N % i == 0) {
    return true;
  }
  return has_divisor(N, i + 1);
}

bool is_prime(int N) {
  if (N == 1) {
    return false;
  }
  else if (N == 2) {
    return true;
  }
  else {
    return !has_divisor(N, 2);
  }
}
bool is_even(int);
bool is_odd(int);

bool is_even(int n) {
  if (n == 0) {
    return true;
  }
  return is_odd(n - 1);
}

bool is_odd(int n) {
  if (n == 0) {
    return false;
  }
  return is_even(n - 1);
}








signed main() {
    string S ;
    cin >> S;
    int N = S.length();
    if(N%2!=0){
        cout << "No" << endl;
        return 0;
    }
    rep(i,N-1){
        if(S[i]=='h'&&S[i+1]=='i'){
            ;
        }
        else{
            cout << "No" << endl;
            return 0;
        }
        i++;
    }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N = 200010;
int n, a[N], g[N];
int gcd(int x, int y) {
	return !y ? x : gcd(y, x % y);
}
bool ok() {
	long long sum = 0;
	for (int i = 1; i <= n; i++) sum += a[i];
	if (n == 1 && a[1] == 1) return 0;
	if (n == 1) return 1;
	if (!(n & 1)) return sum & 1;
	if ((n & 1) && !(sum & 1)) return 1;
	
	for (int j = 0; ; j ^= 1) {
		g[n] = a[n];
		long long S = a[n] - 1; int G;
		for (int i = n - 1; i; i--) g[i] = gcd(g[i + 1], a[i]), S += a[i];
		bool flag = 0;
		if (a[1] > 1 && (1 & (S / (G = gcd(g[2], a[1] - 1))))) flag = 1, a[1]--;
		else 
			for (int i = 2, f = a[1]; i <= n; f = gcd(f, a[i]), i++)
				if (a[i] > 1) {
					int now = gcd(f, a[i] - 1);
					if (i < n) now = gcd(now, g[i + 1]);
					if (1 & (S / (G = now))) {
						flag = 1;
						a[i]--;
						break;
					}
				}
				else break;
		if (!flag) return j;
		for (int i = 1; i <= n; i++) a[i] /= G;
	}
}
 main() {
	scanf("%lld", &n);
	for (int i = 1; i <= n; i++) scanf("%lld", &a[i]);
	puts(ok() ? "First" : "Second");
	return 0;
}

Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		
		//変数//
		int SL;			//盤上の初期状態の長さ
		int group;		//同じ色ごとに分けた場合の数
		
		char s;			//Sから取り出した文字
		char bs;		//一回前の↑の文字
		
		String S;		//盤上の状態		
		
		Scanner scan = new Scanner(System.in);
		
		//入力//
		S = scan.nextLine();
		
		scan.close();
		
		//処理//
		//長さを取得
		SL = S.length();
		
		//初期処理
		group = 1;
		
		for(int i = 1; i < SL; i++){
			//指定位置の文字を取り出す
			s = S.charAt(i);
			
			//一つ前の文字を取得する
			bs = S.charAt(i - 1);
			
			//一つ前の状態と一致しなければgroupをインクリメント
			if( s != bs ){
				group++;
			}			
		}
		
		//結果//
		System.out.println(group - 1);

	}

}


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

using namespace std;

int main(int argc, char* argv[])
{
  int A, B; cin >> A >> B;

  if ((A+B)%2 != 0) {
    cout << "IMPOSSIBLE" << endl;
  } else {
    cout << (A+B)/2 << endl;
  }
  return 0;
}


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

using namespace std;


int main() {
    string s;
    cin >> s;
    int n = s.size();

    int ans = 0, l = 0, r = n - 1;
    for (int i = 0; i < 26; i++) if (i != 'x' - 'a') {
        int cnt = 0;
        for (int j = 0; j < n; j++) cnt += s[j] - 'a' == i;
        int sum = 0;
        for (int j = 0; j < n; j++) {
            if (s[j] - 'a' == i)  {
                sum++;
                if (cnt % 2) {
                    if (sum == cnt / 2 + 1) {
                        l = max(l, j);
                        r = min(r, j);
                    }
                } else if (sum == cnt / 2) {
                    l = max(l, j);
                } else if (sum == cnt / 2 + 1)
                    r = min(r, j);
            }
        }
    }

    //cout << l << ' ' << r << '\n';

    if (l > r) ans = -1;
    else {
        while (l >= 0 && r < n && ans != -1) {
            while (l >= 0 && r < n && s[l] == 'x' && s[r] == 'x')
                l--, r++;
            if (l >= 0 && r < n) {
                while (l >= 0 && s[l] == 'x') l--, ans++;
                while (r < n && s[r] == 'x') r++, ans++;
                if (l < 0 || r >= n || s[l] != s[r]) ans = -1;
                else {
                    l--;
                    r++;
                }
            }
        }
        if (ans != -1) ans += l + 1, ans += n - r;
    }

    cout << ans;

    return 0;
}


Measured memory_bytes: 512
import math

A, B, H, M = input().split()
# print(A, B, H, M)

def get_point(radians_theta, r):
    # 0° -> x:0, y=r とみなす
    # radians_theta 0 ~ 360
    # print(radians_theta, r)
    x = r * math.sin(math.radians(radians_theta))
    y = r * math.cos(math.radians(radians_theta))
    return x, y

def calc_rad_big_hand(H, M):
    # 長針
    return H * 30 + M / 2

def calc_rad_little_hand(M):
    # 短針
    return M * 6

def calc_result(A,B,H,M):
    H = int(H)
    M = int(M)
    A = int(A)
    B = int(B)
    big_hand_rad = calc_rad_big_hand(H, M)
    little_hand_rad = calc_rad_little_hand(M)
    big_x, big_y = get_point(big_hand_rad, A)
    little_x, little_y = get_point(little_hand_rad, B)
    return math.sqrt((big_x - little_x)**2 + (big_y-little_y)**2)

print(calc_result(A,B,H,M))


Measured memory_bytes: 9484
#!/usr/bin/env python

from collections import deque
import itertools as it
import sys

sys.setrecursionlimit(1000000)

while True:
    S_ = raw_input()
    if S_ == '.':
        break

    ans = 0
    for p, q, r in it.product([0, 1, 2], repeat = 3):
        S = S_
        S = S.replace("P", str(p)).replace("Q", str(q)).replace("R", str(r))

        while len(S) != 1:
            S = S.replace("-0", "2")
            S = S.replace("-1", "1")
            S = S.replace("-2", "0")
            for a, b in it.product([0, 1, 2], repeat = 2):
                S = S.replace("(%d*%d)" % (a, b), str(min(a, b)))
                S = S.replace("(%d+%d)" % (a, b), str(max(a, b)))
            
        if S == "2":
            ans += 1
    print ans


Measured memory_bytes: 4984
n = int(input())
s = str(input())
A = [0]
cum = 0
ans = ''
for i in range(n):
    if s[i] == '(':
        cum += 1
    else:
        cum -= 1
    if cum == -1:
        ans = '('+ans
        ans += s[i]
        cum = 0
    else:
        ans += s[i]
else:
    if cum > 0:
        ans += ')'*cum
print(ans)

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

string s;
bool check(int a,int b,int c)
{
   char ch[3];
   ch[0] = s[a] ;
   ch[1] = s[b] ;
   ch[2] = s[c] ;
   sort(ch,ch+3);
   if(ch[0] == 'B' && ch[1] == 'G' && ch[2] == 'R')
      return true ;
   return false;
}

int main()
{
   int n;

   cin >> n >> s;
   long long r = 0, g = 0, b = 0;
   for(int i =0; i < n; i++)
   {
      if(s[i] == 'R')
         r++;
      if(s[i] == 'G')
         g++;
      if(s[i] == 'B')
         b++;
   }
   int res = 0;
   for(int i = 0 ; i < n; i++)
   {
      for(int j = i+1; j < n; j++)
      {
         int k = (i+j)/2;
         if(k -i == j - k && check(i,j,k))
            res++;

      }
   }
   cout << b*r*g - res;
   return 0;
}


Measured memory_bytes: 3584
import java.util.*;
class Main
{
    public static void main (String[] args)
    {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        Map<Integer, Integer> map = new HashMap<>();
        for(int i = 0; i < n ; i++){
            a[i] = sc.nextInt();
            map.put(i, a[i]);
        }
        Arrays.sort(a);
        int med1 = a[n / 2 - 1];
        int med2 = a[n / 2];
        for(int i = 0; i < n; i++){
            if(map.get(i) <= med1) System.out.println(med2);
            else if(map.get(i) >= med2) System.out.println(med1);
        }
    }
}

Measured memory_bytes: 104164
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
    vector<vector<int>> data;
    int k = 0;
    vector<int> n;
    while(1){
        
        int ni;
        cin >> ni;
        if(ni == 0)break;
        n.push_back(ni);
        vector<int> v;
        for(int i = 0;i < n[k];i++){
            int v2;
            cin >> v2;
            v.push_back(v2);
        }
        data.push_back(v);
        k++;
    }
    for(int l = 0;l < k;l++){
        vector<int> d = data[l];
        sort(d.begin(),d.end());
        vector<int>a = d;
        vector<int>b;
        for(int i = 1;i < n[l] * 2 + 1;i++){
            if(d.front() == i){
                d.erase(d.begin());  
                //cout << i << "a" ;  
            }
            else{
                b.push_back(i);
                //cout << i << "b";
            }
            
        }
        int field = 0;
        while(!a.empty() && !b.empty()){
            for(int i = 0;i < a.size();i++){
                if(a[i] > field){
                    field = a[i];
                    //cout << "a" << a[i] <<" "<<field<<endl;
                    a.erase(a.begin() + i);
                    
                    break;
                }
                if(i == a.size() - 1)field = 0;
            }
            if(a.empty())break;
            for(int i = 0;i < b.size();i++){
                if(b[i] > field){
                    field = b[i];
                    //cout << "b" << b[i] <<" "<<field<<endl;
                    b.erase(b.begin() + i);
                    break;
                    
                }
                if(i == b.size() - 1)field = 0;
            }
        }
        cout << b.size() << endl <<a.size() << endl;
    }
    return 0;
}


Measured memory_bytes: 3152
#include "bits/stdc++.h"
// Custom Header {{{
#define ALL(x) x.begin(), x.end()
#define endl '\n'
using namespace std;
using i64 = long long;
using pii = pair<i64, i64>;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
// }}}

int K, N;
int d[300];
int START = 0, GOAL;
bool reach[300];
bool visited[300];
vector<vector<int>> G;

void addEdge(int s)
{
    for (int j = 1; j <= K; ++j) {
        int t = min(GOAL, s + j);
        G[s].push_back(max(0, min(GOAL, t + d[t])));
    }
}

void dfs(int u)
{
    if (!visited[u]) {
        visited[u] = true;
        for (int v : G[u]) dfs(v);
    }
}

bool canGoal(int u)
{
    if (u == GOAL) return true;

    if (visited[u]) return false;
    visited[u] = true;

    bool ret = false;
    for (int v : G[u]) {
        ret |= canGoal(v);
    }
    return ret;
}

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


    while(cin >> K, K) {
        cin >> N;
        memset(d, 0, sizeof(d));
        for (int i = 1; i <= N; ++i) cin >> d[i];
        GOAL = N+1;

        G = vector<vector<int>>(N+2);
        for (int i = 0; i <= N; ++i) {
            addEdge(i);
        }

        /*
        cout << "-------------------------------------" << endl;
        cout << ++__  << ' ' << N << ' ' << K << endl;
        for (int i = 1; i <= N; ++i) cout << d[i] << ' ';
        cout << endl;

        for (int i = 0; i <= GOAL; ++i) {
            printf("[%d] ", i);
            for (int u : G[i]) {
                printf(" %d", u);
            }
            printf("\n");
        }
        */

        memset(visited, false, sizeof(visited));
        dfs(0);

        int reachCount = 0;
        int canGoalCount = 0;

        memcpy(reach, visited, sizeof(reach));
        for (int i = 1; i <= GOAL; ++i) {
            if (reach[i]) {
                //printf("reach : %d\n", i);
                ++reachCount;
                memset(visited, false, sizeof(visited));
                if (canGoal(i)) {
                    ++canGoalCount;
                }
            }
        }

        cout << (canGoalCount > 0 && reachCount == canGoalCount ? "OK" : "NG") << endl;

    }

    return 0;
}



Measured memory_bytes: 3208
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int mod=1000000007;

int main(){
	int n,a[100100]={};
	string s;
	cin>>n;
	cout<<0<<endl;
	cin>>s;
	if(s[0]=='V'){
		return 0;
	}else if(s[0]=='M')a[0]=1;
	else a[0]=2;
	cout<<n/2<<endl;
	cin>>s;
	if(s[0]=='V'){
		return 0;
	}else if(s[0]=='M')a[n/2]=1;
	else a[n/2]=2;
	cout<<n-1<<endl;
	cin>>s;
	if(s[0]=='V'){
		return 0;
	}else if(s[0]=='M')a[n-1]=1;
	else a[n-1]=2;
	int l=0,r=n/2;
	if((l^r)&1){
		if(a[l]!=a[r]){
			l=n/2;r=n-1;
		}
	}else{
		if(a[l]==a[r]){
			l=n/2;r=n-1;
		}
	}

	FOR(t,0,18){
		int m=(r+l)/2;
		cout<<m<<endl;
		cin>>s;
		if(s[0]=='V'){
			return 0;
		}else if(s[0]=='M'){
			a[m]=1;
		}else{
			a[m]=2;
		}
		if((l^m)&1){
			if(a[l]!=a[m]){
				l=m;
			}else r=m;
		}else{
			if(a[l]==a[m]){
				l=m;
			}else r=m;
		}
	}
    return 0;
}


Measured memory_bytes: 1236
#include<iostream>
using namespace std;
int main() {
    char w[3];
    int c = 0;
    for (int i = 0;i < 3;i++) {
        cin >> w[i];
    }


    if (w[0] == 'S' && w[1] == 'S' && w[2] == 'S')
        c = 0;
    if (w[0] == 'S' && w[1] == 'S' && w[2] == 'R')
        c = 1;
    if (w[0] == 'R' && w[1] == 'S' && w[2] == 'S')
        c = 1;
    if (w[0] == 'S' && w[1] == 'R' && w[2] == 'S')
        c = 1;
    if (w[0] == 'R' && w[1] == 'R' && w[2] == 'S')
        c = 2;
    if (w[0] == 'R' && w[1] == 'S' && w[2] == 'R')
        c = 1;
    if (w[0] == 'S' && w[1] == 'R' && w[2] == 'R')
        c = 2;
    if (w[0] == 'R' && w[1] == 'R' && w[2] == 'R')
        c = 3;

    cout << c;
    return 0;
}


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

//関数


int main() {
    
    
    //入力
    long sx,sy,tx,ty;
    cin>>sx>>sy>>tx>>ty;
    
    //計算
    long X=tx-sx,Y=ty-sy;
    
    for(int i=0;i<X;i++) cout<<'R';
    for(int i=0;i<Y;i++) cout<<'U';
    for(int i=0;i<X;i++) cout<<'L';
    for(int i=0;i<Y;i++) cout<<'D';
    
    cout<<'D';
    for(int i=0;i<=X;i++) cout<<'R';
    for(int i=0;i<=Y;i++) cout<<'U';
    cout<<'L';
    
    cout<<'U';
    for(int i=0;i<=X;i++) cout<<'L';
    for(int i=0;i<=Y;i++) cout<<'D';
    cout<<'R'<<endl;
}

Measured memory_bytes: 384
import heapq
N, C = list(map(int, input().split()))

ans = C
d = [list() for _ in range(C+1)]
for _ in range(N):
    s, t, c = map(int, input().split())
    d[c].append([s, t])

S = [0]*(10**5+1)
T = [0]*(10**5+1)

for i in range(C+1):
    if not d[i]:
        continue
    d[i].sort()
    s, t = d[i][0]
    for j in range(1, len(d[i])):
        if t == d[i][j][0]:
            t = d[i][j][1]
        else:
            S[s] += 1
            T[t] += 1
            s, t = d[i][j]
    S[s] += 1
    T[t] += 1

temp = 0
ans = 0
for i in range(1, 10**5+1):
    temp += S[i]-T[i-1]
    ans = max(ans, temp)
    
print(ans)


Measured memory_bytes: 26300
#include "stdio.h"


int main(void){

	int N;
	int N_digi[8];
	int i, bai=1;
	int sum = 0;

	scanf("%d", &N);

	for(i=0;i<8;i++)
	{
		bai*=10;
		N_digi[i] = ((N%bai)*10)/bai ;
		sum = sum + N_digi[i];
	}

	if(N%sum == 0)
	{
		printf("Yes\n");
	}
	else
	{
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

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

        int N = scan.nextInt();
        if (N % 1000 == 0) {
            System.out.println(0);
        }else {
            System.out.println(1000 - (N % 1000));
        }


    }
}


Measured memory_bytes: 35724
#include<iostream>
 #include<stdio.h>
 #include<string>
 #include<math.h>
 #include<iomanip>
 #include<algorithm>
 #include<string.h>
 #include<cctype>
 #include<map>
 #include<set>
 #include<vector>
 #include<sstream>
 #include<stack>
 #include<queue>
 
 using namespace std;
 
 int arr[4000+5]={0};
 
 int main()
 {
   int n;
   while(cin>>n&&n)
   {
     int count=0;
     map<int,long long int> mm;
     bool flag=false;
     for(int i=0;i<n;i++)
     {
       int id,p,q;
       cin>>id>>p>>q;
       mm[id]+=(p*q);
       if(i==0) arr[count++]=id;
       int j;
       for(j=0;j<count;j++)     
       {
         if(arr[j]==id) break;        
       }   
       if(j==count) arr[count++]=id;
     }           
     for(int i=0;i<count;i++)
     {
       int kk=arr[i];
       if(mm[kk]>=1000000)
       { 
         cout<<arr[i]<<endl;
         flag=true;
       }        
     }
     if(!flag) cout<<"NA"<<endl;
   }
   //while(1);
   return 0;
 }

Measured memory_bytes: 3152
//#pragma GCC optimize ("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("avx,avx2,fma")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
#define pb push_back
#define F first
#define S second
#define ins insert
#define mp make_pair
#define fo(i, n1, n, x) for(int i = n1; i <= n; i += x)
#define foo(i, n, n1, x) for(int i = n; i >= n1; i -= x)
#define bit __builtin_popcount
#define md (l + ((r - l) / 2))
#define all(x) x.begin(),x.end()
#define eb emplace_back
#define ub upper_bound
#define lb lower_bound
#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)

using namespace std;
//using namespace __gnu_pbds;
//using namespace __gnu_cxx;


using ll = long long;

//#define int ll

using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;



const int N = 2e5 + 11, mod = 1e9 + 7, mod2 = 998244353;
const int MAX = 1e5 + 11;
const int INF1 = 2e9 + 11;
const ll INF2 = 6e18 + 11;
const double INF3 = 1e8 + 11;
const int base = 500;
const int P = 31;
const int dx[] = {1, -1, 0, 0, 1, 1, -1, -1};
const int dy[] = {0, 0, 1, -1, 1, -1, 1, -1};
const double EPS = 1e-4;
const double PI = acos(-1.0);


//template<typename T> using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }


mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int x, n, a[111], ans = -1;
bool us[111];
main() {
  file("threesum");
  ios;
  cin >> x >> n;
  fo(i, 1, n, 1) cin >> a[i], us[a[i]] = 1;
  fo(i, 0, 101, 1) {
    if (!us[i]) {
      if (ans == -1 || abs(i - x) < abs(ans - x)) ans = i;
    }
  }
  cout << ans;
  return 0;
}
/**

*/


Measured memory_bytes: 3676
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <queue>
#include <list>
#include <string>
using namespace std;

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

int main()
{
  int A,B,C;
  cin >> A >> B >> C;
  if(A >= C && C >= B){
    cout << "Yes";
  }else if(A <= C && C <= B){
    cout << "Yes";
  }else{
    cout << "No";
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <deque>
#include <queue>

using namespace std;
typedef long long ll;

ll A[100005];
ll L[100005], R[100005];
ll l,r;

int main(){
    int K;
    cin >> K;
    for(int i = 1; i <= K; i++) cin >> A[i];

    L[K] = 2; R[K] = 2;
    
    for(int i = K; i >= 1; i--){
        if(L[i]%A[i]==0||R[i]%A[i]==0||R[i]-L[i]+(L[i]%A[i])>=A[i]){
            if(L[i]%A[i] == 0) l = L[i]/A[i];
            else l = L[i]/A[i]+1;
            r = R[i]/A[i];
            L[i-1] = l*A[i];
            R[i-1] = r*A[i]+A[i]-1;
        } else {
            cout << -1 << endl;
            return 0;
        }
    }
    cout << L[0] << " " << R[0] << endl;
}



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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG2(x,y) cout<<#x<<": "<<x<<" "<<#y<<": "<<y<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

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

    //中間試験の点数 m、期末試験の点数 f、再試験の点数 r 
    REP(i,51){
        int m,f,r;
        cin>>m>>f>>r;

        if(m==-1 && f==-1 && r==-1) break;

        char ans;
        if(m==-1 || f==-1) ans='F';
        else if(m+f>=80) ans='A';
        else if(m+f<80 && m+f>=65) ans='B';
        else if(m+f<65 && m+f>=50) ans='C';
        else if(m+f<50 && m+f>=30) ans=(r>=50)?'C':'D';
        else if(m+f<30) ans='F';

        cout<<ans<<endl;
    }

    return 0;
}


Measured memory_bytes: 3124
#include <stdio.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))

ll gcd(ll p,ll q){for(ll t;q;)t=p%q,p=q,q=t;return p;}
ll lcm(ll p,ll q){return p/gcd(p,q)*q;}

ll n;
ll ans=1;
int main(){
	scanf("%lld",&n);
	rep(i,0,n){
		ll t;
		scanf("%lld",&t);
		ans=lcm(ans,t);
	}
	printf("%lld\n",ans);
}

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

#define fi                      first
#define se                      second
#define pb                      push_back
#define endl                    '\n'
#define all(x)                  x.begin(),x.end()
#define pii                     pair<int,int>
#define pll                     pair< long long int, long long int> 
#define fast                    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define SZ(x)                   ((int)x.size())

#define FOR(i,a,b)              for(int i = a; i < b; ++i)
#define REV(i,a,b)              for(int i = a; i >= b; --i)
#define FORE(i,a,b)             for(int i = a; i <= b; ++i)

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

void solve();

int32_t main()
{
        fast;
        int t = 1;
        // cin >> t;
        for(int i = 1; i <= t; ++i)
                solve();
        cerr << "Time taken: " << ((clock() * 1000) / CLOCKS_PER_SEC) << "ms\n";
}

void solve() {
        int a,b;
        cin >> a >> b;
        char p = (char)('0' + a);
        char q = (char)('0' + b);
        string x = "", y = "";
        FOR(i,0,a) {
        	x.pb(q);
        }
        FOR(j,0,b) {
        	y.pb(p);
        }
        if(x < y) {
        	cout << x << endl;
        }
        else {
        	cout << y << endl;
        }
}

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

ll gcd(ll a, ll b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}

ll gcd(vector<int> a) {
  sort(a.begin(), a.end());
  ll ret = a[0];
  for (int i = 1; i < a.size(); i++) {
    ret = gcd(a[i], ret);
  }
  return ret;
}

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  cout << gcd(a) << endl;
}

Measured memory_bytes: 1024
N=int(input())
for h in range(1,3501):
	for n in range(1,3501):
		if 4*h*n-N*(h+n)>0:
			if N*h*n%(4*h*n-N*(h+n))==0:
				w=N*h*n//(4*h*n-N*(h+n))
				print(h,n,w)
				exit()

Measured memory_bytes: 3064
#include <stdio.h>

int ans1(int a, int b, int x, int y){
    return a*x + b*y;
}

int ans2(int a, int b, int c, int x, int y){
    if (x >y)
        return 2*y*c + (x - y)*a;
    else
        return 2*x*c + (y - x)*b;
}

int ans3(int c, int x, int y){
    if (x >y)
        return 2*x*c;
    else
        return 2*y*c;
}

int main(void){
    int a, b, c, x, y;
    int anser1, anser2, anser3, true_ans;
    
    /* input */
    scanf("%d", &a);
    scanf("%d", &b);
    scanf("%d", &c);
    scanf("%d", &x);
    scanf("%d", &y);
    
    anser1 = ans1(a, b, x, y);
    anser2 = ans2(a, b, c, x, y);
    anser3 = ans3(c, x, y);
    
    if (anser1 < anser2 && anser1 < anser3){
        true_ans = anser1;
    }
    else if (anser2 < anser3 && anser2 < anser1){
        true_ans = anser2;
    }
    else {
        true_ans = anser3;
    }
    
    /* output */
    printf("%d \n", true_ans);
        
    return 0;
    }


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(r) r.begin(),r.end()
typedef int64_t ll;
typedef std::vector<ll> vll;
using namespace std;
struct Solution {
    void solve(std::istream& in, std::ostream& out) {
        
        ll N;
        in >> N;
        vll a(N);
        rep(i, N) {
            in >> a[i];
        }
        sort(all(a));
        reverse(all(a));
        ll l = 0;
        ll r = 0;
        rep(i, N - 1) {
            if (a[i + 1] == a[i]) {
                if (l == 0) {
                    l = a[i];
                }
                else {
                    r = a[i];
                    break;
                }
                i++;
            }
        }
        out << l*r << '\n';
    }
};
void solve(std::istream& in, std::ostream& out) {
    out << std::setprecision(12);
    Solution solution;
    solution.solve(in, out);
}
#include <fstream>
#include <iostream>
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    istream& in = cin;
    ostream& out = cout;
    solve(in, out);
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int x, n, y;
    string s;
    cin >> n >> x >> y;
//    map<int, int> cnt;
    int cnt[2000] = {};
    for (int i = 1; i < n; i++) {
        int dis = 0;
        for (int j = i + 1; j <= n; j++) {
            dis = min(j - i, abs(x - i) + 1 + abs(y - j));
            cnt[dis]++;
            //cout << i << " " << dis << " " << j << endl;
        }
    }
    for (int i = 1; i < n; i++) {
        cout << cnt[i] << endl;
    }
}


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

using namespace std;

int n;
int d[190], c[401];
int t[20][20];
set< vector<int> > S;

int abs(int t){ return t>0?t:-t; }

void search(int L, int R){
	if(L+1==R){
		vector<int> v;
		for(int i=0;i+1<n;i++)
			v.push_back(t[i][i+1]);
		S.insert(v);
		return ;
	}
	int idx = 0;
	while(c[d[idx]]==0) idx++;
	c[d[idx]]--;
	
	bool check = true;
	t[0][R-1] = t[R-1][0] = d[idx];
	for(int i=1;i<n;i++){
		if(L<i&&i<R) continue;
		if(c[t[i][R-1] = t[R-1][i] = abs(t[0][R-1]-t[0][i])]==0) check = false;
		c[t[i][R-1]]--;
	}
	if(check) search(L, R-1);
	for(int i=1;i<n;i++)
		if(i<=L||R<=i) c[t[i][R-1]]++;

	check = true;
	t[L+1][n-1] = t[n-1][L+1] = d[idx];
	for(int i=0;i+1<n;i++){
		if(L<i&&i<R) continue;
		if(c[t[i][L+1] = t[L+1][i] = abs(t[i][n-1]-t[L+1][n-1])]==0) check = false;
		c[t[i][L+1]]--;
	}
	if(check) search(L+1, R);
	for(int i=0;i+1<n;i++)
		if(i<=L||R<=i) c[t[i][L+1]]++;

	c[d[idx]]++;
}

int main(){
	while(cin >> n, n){
		S.clear();
		memset(c, 0, sizeof(c));
		for(int i=0;i<n*(n-1)/2;i++){
			cin >> d[i];
			if(i!=0) c[d[i]]++;
		}
		t[0][n-1] = t[n-1][0] = d[0];
		search(0, n-1);
		for(set< vector<int> >::iterator it=S.begin();it!=S.end();it++){
			for(int i=0;i+1<it->size();i++)
				cout << (*it)[i] << " ";
			cout << it->back() << endl;
		}
		cout << "-----" << endl;
	}
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#include<string.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
const ll INF=1<<29;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};

int main() {

	ll n,k,q;
	ll a[100001];
	ll t[100001]={};

	cin>>n>>k>>q;

	rep(i,q){
		cin>>a[i];
		t[a[i]]++;
	}

	for(int i=1; i<n+1; i++){
		if(t[i]+k<=q)cout<<"No"<<endl;
		else cout<<"Yes"<<endl;
	}

	return 0;
}


Measured memory_bytes: 2176
// 以下と同じ内容を提出.
// https://atcoder.jp/contests/caddi2018b/submissions/9393358
#include <bits/stdc++.h>
using namespace std;
#define repex(i, a, b, c) for(int i = a; i < b; i += c)
#define repx(i, a, b) repex(i, a, b, 1)
#define rep(i, n) repx(i, 0, n)
#define repr(i, a, b) for(int i = a; i >= b; i--)

int main(){
    
    // 1. 入力情報.
    int N;
    scanf("%d", &N);
    
    // 2. 勝者は？
    // 奇数がある場合
    // -> 奇数部分を first が 食べてから, 後は, second と 同じ内容のりんごを
    // first が 食べることで, first が 勝者.
    // 
    // すべて偶数の場合
    // -> first と 同じ内容のりんごを second が 食べることで, second が 勝者.
    bool ans = false;
    rep(i, N){
        int a;
        scanf("%d", &a);
        if(a & 1) ans = true;
    }
    
    // 3. 出力.
    printf("%s\n", ans ? "first" : "second");
    return 0;
    
}

Measured memory_bytes: 256
n, m, c = map(int, input().split())
b = list(map(int, input().split()))
a = [list(map(int, input().split())) for _ in range(n)]

ans = 0
for i in range(n):
    cond = c
    for j in range(m):
        cond += a[i][j]*b[j]
    if cond > 0:
        ans += 1

print(ans)

Measured memory_bytes: 3060
module.exports=function(e){var r={};function t(n){if(r[n])return r[n].exports;var o=r[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,t),o.l=!0,o.exports}return t.m=e,t.c=r,t.d=function(e,r,n){t.o(e,r)||Object.defineProperty(e,r,{enumerable:!0,get:n})},t.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},t.t=function(e,r){if(1&r&&(e=t(e)),8&r)return e;if(4&r&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(t.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&r&&"string"!=typeof e)for(var o in e)t.d(n,o,function(r){return e[r]}.bind(null,o));return n},t.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(r,"a",r),r},t.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},t.p="",t(t.s=0)}([function(e,r,t){t(1)(t(2).readFileSync("/dev/stdin","UTF-8").split("\n"))},function(e,r,t){"use strict";function n(e,r){return function(e){if(Array.isArray(e))return e}(e)||function(e,r){var t=[],n=!0,o=!1,u=void 0;try{for(var i,f=e[Symbol.iterator]();!(n=(i=f.next()).done)&&(t.push(i.value),!r||t.length!==r);n=!0);}catch(e){o=!0,u=e}finally{try{n||null==f.return||f.return()}finally{if(o)throw u}}return t}(e,r)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}e.exports=function(e){for(var r=n(e[0].split(" ").map(function(e){return Number(e)}),3),t=r[0],o=r[1],u=r[2],i=0;i<=t;i++)for(var f=0;f<=o;f++)if((t-i)*f+(o-f)*i==u)return void console.log("Yes");console.log("No")}},function(e,r){e.exports=require("fs")}]);

Measured memory_bytes: 7500
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pb push_back
#define ll long long
#define pi pair<int,int>
#define pii pair<pi,int>
#define go ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
int n,x;
bool ok=1;
int main()
{
    go;
    cin>>n;
    while(n--)
    {
        cin>>x;
        if(x&1) continue;
        if(x%3==0) continue;
        if(x%5==0) continue;
        ok=0;
    }
    if(!ok)
        cout<<"DENIED";
    else
    cout<<"APPROVED";
    return 0;
}


Measured memory_bytes: 256
d=[[],[],[],[]]
for t in[*open(0)][1:]:*z,u=t.split();d[ord(u)%5]+=[*map(int,z)],
I=N=9**9
P,M='x+y,','x-y,'
for*A,S in(3,0,'x,y,'),(1,2,'y,x,'),(0,2,P+M),(1,3,P+M),(1,0,M+P),(3,2,M+P):
 n=p=-I
 for x,y,r in eval('sorted((%sQ)for Q,P in enumerate(A)for x,y in d[P])'%S):
  if r:n,p=x,y
  elif x==n:N=min(N,y-p)
print(N%I*5or'SAFE')

Measured memory_bytes: 71640
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll n,k;
    cin>>n;
    ll arr[n];
    map<ll,ll> q1;
    for(ll i=0;i<n;i++)
    {
      ll x;
      cin>>x;
      q1.insert({x,i+1});
    }
     for (auto itr = q1.begin(); itr != q1.end(); ++itr)
     {
         cout<<itr->second<<" ";
     }
    return 0;
}


Measured memory_bytes: 8192
import sys
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
DVSR = 1000000007
def POW(x, y): return pow(x, y, DVSR)
def INV(x, d=DVSR): return pow(x, d - 2, d)
def DIV(x, y, d=DVSR): return (x * INV(y, d)) % d
def LI(): return [int(x) for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()
def II(): return int(input())

A,B,X=LI()
print("YES" if X <= A+B and A <= X else "NO")


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

int main(){
    int p, q;
    while( cin >> p >> q ){ 
	int rem = p % q;
	map<int, bool> V;
	map<int, int> P;
	V[p] = true;
	V[rem] = true;
	P[p] = 0;
	P[rem] = 1;
	int cur = 1;
	while( rem > 0 ){
	    rem *= 10;
	    cout << rem/q;
	    rem = rem%q;
	    if ( V[rem] ) {
	      int s= P[rem];
	      cout << endl;
	      for ( int i = 0; i < s-1; i++ ) cout << " ";
	      for ( int i = s; i <= cur; i++ ) cout << "^";
	      break;
	    }
	    V[rem] = true;
	    P[rem] = ++cur;
	}
    	cout << endl;
    }
    return 0;
}

Measured memory_bytes: 1200
import sys
n=int(input())
a=list(map(int,input().split()))
a.sort()
maxlen=a[-1]
thing={}
for i in range(n):
  if a[i] in thing:
    thing[a[i]]+=1
  else:
    thing[a[i]]=1
    
if maxlen%2==1:
  if not (maxlen+1)//2 in thing:
    print('Impossible')
    sys.exit()
  if thing[(maxlen+1)//2]!=2:
    print('Impossible')
    sys.exit()
if maxlen%2==0:
  if not (maxlen+1)//2 in thing:
    print('Impossible')
    sys.exit()
  if thing[(maxlen+1)//2]!=1:
    print('Impossible')
    sys.exit()
for i in thing:
  if i==(maxlen+1)//2:
    continue
  if i<(maxlen+1)//2:
    print('Impossible')
    sys.exit()
  if thing[i]<2:
    print('Impossible')
    sys.exit()
for i in range((maxlen+1)//2,maxlen):
  if not i in thing:
    print('Impossible')
    sys.exit()
print('Possible')

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

using namespace std;

int cankill(int h, int n, vector <long long> a){
  if (accumulate(a.begin(), a.end(), 0L) >= h)
    return 1;
  return 0;  
}

int main() {
  ios_base::sync_with_stdio(false);
  long long h, n;
  cin >> h >> n;
  vector <long long> a(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];
  string res[2] = {"No", "Yes"};
  cout << res[cankill(h,n,a)] << endl;
}

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

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

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()

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

  int N;
  string S;
  cin>>N>>S;
  bool ans=true;
  for(int i=0;i<N/2;i++){
    if(S[i]!=S[i+N/2])ans=false;
  }
  if(N%2==1)ans=false;
  if(ans)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<queue>
#include<stack>
#include<map>

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

template<typename A, typename B> bool chmin(A &a, const B &b){ return b < a && (a = b, true); }
template<typename A, typename B> bool chmax(A &a, const B &b){ return a < b && (a = b, true); }

int main() {
  int a;
  cin >> a;
  cout << a+a*a+a*a*a << '\n';
  return 0;
}

Measured memory_bytes: 3616
# coding: utf-8
# Your code here!
import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
read = sys.stdin.read

#n = int(input())
#k,x = [int(i) for i in readline().split()]
n,*c = [int(i) for i in read().split()]
c.sort(reverse=True)


MOD = 10**9+7

ans = 0
for i,ci in enumerate(c):
    ans += (i+2)*ci%MOD
    ans %= MOD

print(ans*pow(2,2*n-2,MOD)%MOD)







Measured memory_bytes: 25124
/// Code By t_bone_289 (Tushar Singh)
/// An Immature Programmer.... I'm still developing !!
#include<bits/stdc++.h>
using namespace std;
#define pll pair<ll,ll>
#define fi first
#define se second
#define mp make_pair
#define pb emplace_back
#define endl '\n'
#define M 1000000007
#define error(x) cout << #x << " = " << x << endl;
typedef long long ll;
typedef double d;
typedef long double ld;
ll powmod(ll base,ll exp,ll MOD){ll res=1;while(exp>0){if(exp%2==1) res=(res*base)%MOD;base=(base*base)%MOD;exp/=2;}return (res%MOD);}
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll n;
    cin>>n;
    vector<ll> v(n);
    for(auto &x:v)
    {
        cin>>x;
    }
    sort(v.begin(),v.end());
    map<ll,ll> m;
    for(ll i=0;i<n;i++)
    {
        m[v[i]]++;
    }
    vector<ll> pow2;
    ll val=2;
    while(val<=INT_MAX)
    {
        pow2.pb(val);
        val*=2;
    }
    ll p=0;
    sort(v.begin(),v.end());
    reverse(v.begin(),v.end());
    for(ll i=0;i<n;i++)
    {
        for(auto x:pow2)
        {
            if(x<=v[i])
            {
                continue;
            }
            if((m[x-v[i]])>0 && m[v[i]]>0)
            {
                if(2*v[i]==x)
                {
                    if(m[v[i]]>1)
                    {
                        m[v[i]]-=2;
                        p++;
                    }
                }
                else
                {
                    m[x-v[i]]--;
                    m[v[i]]--;
                    p++;
                }
            }
        }
    }
    cout<<p<<endl;
    return 0;
}




Measured memory_bytes: 45312
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop;

void main() {
    immutable int M = 51;
    auto N = readln.chomp.to!int;
    auto A = readln.split.map!(to!int);
    auto B = readln.split.map!(to!int);
    auto S = iota(1, M).array;

    bool ok() {
        auto D = new int[][](M, M);
        foreach (i; 0..M) foreach (j; 0..M) D[i][j] = i == j ? 1 : 1 << 29;
        foreach (i; 0..M) foreach (j; S) D[i][i%j] = 1;
        foreach (i; 0..M) foreach (j; 0..M) foreach (k; 0..M) D[j][k] = min(D[j][k], D[j][i] + D[i][k]);
        return N.iota.map!(i => D[A[i]][B[i]] < 1 << 29).all;
    }

    if (!ok) {
        writeln(-1);
        return;
    }
    
    ulong ans = 0;
    foreach (i; iota(50, 0, -1)) {
        S = S.remove!(a => a == i);
        if (!ok) {
            S ~= i;
            ans += 1UL << i;
        }
    }

    ans.writeln;
}


Measured memory_bytes: 1020
#!/usr/bin/env python3
import sys
import math
args = sys.argv
if len(args) == 2:
  from IPython import embed
  em = True
else:
  em = False
input = sys.stdin.readline
N = float(input())
Nc = math.ceil(N / 1.08)
Nf = math.floor(N / 1.08)
if int(Nc * 1.08) == N:
  print(Nc)
elif int(Nf * 1.08) == N:
  print(Nf)
else:
  print(":(")


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (auto& x : A) cin >> x;
  int th = 0;
  int ans = 0;
  for (int i = 0; i < N; i++) {
    th = max(th, A[i]);
    ans += max(0LL, th - A[i]);
  }
  cout << ans << endl;
}


Measured memory_bytes: 4780
#include<stdio.h>
int main(){
  int n,cnt = 0;
  scanf("%d",&n);
  char s[n][20];
  for(int i = 0;i < n;i++){
    scanf("%s",&s[i]);
    for(int j = 0;j < i;j++){
      int c = 0;
      if(strlen(s[i]) == strlen(s[j])){\
        for(int k = 0;k < strlen(s[j]);k++){\
          if(s[i][k] != s[j][k]){
            c = 1;\
            break;
          }
        }
      }else{
        c = 1;
      }
      if(c == 0){
        cnt = 1;
      }
    }
    if(i > 0 && s[i - 1][strlen(s[i - 1]) - 1] != s[i][0] || cnt == 1){
      printf("No\n");
      return 0;
    }
  }
  printf("Yes\n");
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define REP(i,n) for (int i=0;i<(n);i++)
#define ALL(a) (a).begin(),(a).end()
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define ll long long
#define ull unsigned long long
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

using namespace std;

int main(){

  int n,w;

  cin >> n >> w;
  vector<vector<int>> dp(n+1,vector<int>(w+1,0));
  vector<pair<int,int>> nap(n);
  REP(i,n)cin >> nap[i].first >> nap[i].second;
  
  for(int i=1;i<n+1;i++)
    REP(j,w+1){
      if(j-nap[i-1].second>=0){
	dp[i][j] = max(dp[i-1][j-nap[i-1].second]+nap[i-1].first,dp[i-1][j]);
      }else{
	dp[i][j] = dp[i-1][j];
      }
    }
  /*    REP(i,n+1){
    REP(j,w+1)
      cout << dp[i][j] << " ";
    cout << endl;
    }*/
  cout << dp[n][w] << endl;
		 
  return 0;
}

Measured memory_bytes: 6812
#include <bits/stdc++.h>
#define F first
#define S second
#define all(a) a.begin(),a.end()
#define setDP(arr) memset(arr,-1,sizeof arr)
#define Clear(arr) memset(arr,0,sizeof arr)
#define oo 2000000000
#define inf 1000000000000000000
#define P1 31
#define P2 37
#define M  1000000007
#define M2 1000000009
#define pii pair<ll,ll>
typedef long long ll;
using namespace std;
const int N = 355001;
const int SQRTN = 320;
const int LOGN = 20;
const long double PI = acos(-1);
const long double TAU = 2*PI;


ll sum , n , a[N],x;

signed main(){
    cin >> n >> x;
    for(int i = 0 ; i < n ; i++){
        scanf("%d",a+i);
        sum+=a[i];
    }
    if(sum==x)return cout << n << endl,0;
    if(sum<x)return cout << n-1 << endl,0;
    sort(a,a+n);
    int ans =0;
    sum=0;
    for(int i = 0 ; i < n ; i++){
        sum+=a[i];
        if(sum<=x)ans++;
        else break;
    }
    cout << ans << endl;





}


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

int main(){
  int A, B, C;
  cin >> A >> B >> C;

  if (A + B >= C){
    cout << "Yes" << endl;
  }
  else
  {
    cout << "No" << endl;
  }
  
}

Measured memory_bytes: 3576
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N = INT()
A = LIST()

s = A[0]
a = sum(A)-A[0]
ans = abs(s-a)

for i in range(1, N-1):
    s += A[i]
    a -= A[i]
    ans = min(ans, abs(s-a))
print(ans)


Measured memory_bytes: 25700