akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cassert>
#include <chrono>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<double, int> pdi;
typedef pair<int, pii> pipii;
typedef vector<vector<ll>> matrix;

ll l[51];
int n;
void solve() {
  cin >> n;
  int maxIdx = 0;
  ll maxVal = -1e9;
  int minIdx = 0;
  ll minVal = 1e9;
  for(int i = 1; i <= n; i++) {
    cin >> l[i];
    if(l[i] > maxVal) {
      maxVal = l[i];
      maxIdx = i;
    }
    if(l[i] < minVal) {
      minVal = l[i];
      minIdx = i;
    }
  }
  cout << 2*n-2 << "\n";
  if(maxVal + minVal >= 0) {
    for(int i = 1; i <= n; i++) {
      if(i != maxIdx) {
        cout << maxIdx << " " << i << "\n";
        l[i] += l[maxIdx];
      }
    }
    for(int i = 2; i <= n; i++) {
      cout << i-1 << " " << i << "\n";
      l[i] += l[i-1];
    }
  }
  else {
    for(int i = 1; i <= n; i++) {
      if(i != minIdx) {
        cout << minIdx << " " << i << "\n";
        l[i] += l[minIdx];
      }
    }
    for(int i = n; i > 1; i--) {
      cout << i << " " << i-1 << "\n";
      l[i-1] += l[i];
    }
  }
  for(int i = 1; i < n; i++) assert(l[i] <= l[i+1]);
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  solve();
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#define ll long long
#define maxn 200010
inline ll read()
{
	ll x=0; char c=getchar(),f=1;
	for(;c<'0'||'9'<c;c=getchar())if(c=='-')f=-1;
	for(;'0'<=c&&c<='9';c=getchar())x=x*10+c-'0';
	return x*f;
}
inline void write(ll x)
{
	static int buf[20],len; len=0;
	if(x<0)x=-x,putchar('-');
	for(;x;x/=10)buf[len++]=x%10;
	if(!len)putchar('0');
	else while(len)putchar(buf[--len]+'0');
}
inline void writeln(ll x){write(x); putchar('\n');}
inline void writesp(ll x){write(x); putchar(' ');}
int a[maxn];
int n,k,s;
int main()
{
	n=read(); k=read(); s=read();
	for(int i=1;i<=n;i++)
		if(i<=k)a[i]=s;
		else if(s==1000000000)a[i]=1;
		else a[i]=s+1;
	for(int i=1;i<=n;i++)
		writesp(a[i]);
	putchar('\n');
	return 0;
}

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

typedef long long ll;
#define fori(n) for(int i=0;i<n;i++)
#define pb push_back


ll power(ll base,ll e)
{
    ll answer=1;
    //ll e=1000000005;
    while(e)
    {
        if(e%2==1)
        {
            answer*=base;
        }
        base*=base;
       // base%=mod;
        e/=2;
       // answer%=mod;
    }
    return answer;
}


void sieveprimes(ll n)
{
    bool prime[n+1];
    memset(prime,true,sizeof(prime));

    for(ll i=2;i*i<=n;i++)
    {
        if(prime[i]==true)
        {
            for(ll j=i*i;j<=n;j+=i)
            {
                prime[j]=false;
            }

        }

    }

    /*for (int p=2; p<=n; p++)
       if (prime[p])
          cout << p << " ";*/
    /*for(ll i=2;i<=n;i++)
    {
        if(prime[i])    ans.insert(i*i);
    }*/
}


int main()
{

   string s;
   cin>>s;
   int flag=0;
   for(int i=0;i<s.length();i++)
   {
       if(s[i]=='7')
       {
           flag  = 1;
           break;
       }

   }
   if(flag==1) cout<<"Yes"<<endl;
   else cout<<"No"<<endl;

}


Measured memory_bytes: 3632
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
using namespace std;

#define FOR(i,n) for(int (i)=0;(i)<(n);(i)++)
#define eFOR(i,n) for(int (i)=0;(i)<=(n);(i)++)
#define SORT(i) sort((i).begin(),(i).end())
#define INF 1000000000

int main() {

	int k, s, ans = 0;
	cin >> k >> s;

	eFOR(x, k) {
		eFOR(y, k) {
			if (s - x - y >= 0 && s - x - y <= k)ans++;
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		int x;
		int y;
		BufferedReader br = new BufferedReader (new InputStreamReader(System.in));
		
		while (true) {
			String str = br.readLine();
			String[] result = str.split(" ");
			x = Integer.parseInt(result[0]);
			y = Integer.parseInt(result[1]);
		
			if (x == 0 && y == 0) {
				break;
			}
			if (y > x) {
				System.out.println(x + " " + y);
			} else {
				System.out.println(y + " " + x);
			}
		}
	}
}

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

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define fst first
#define snd second
#define pb push_back
#define ALL(x) x.begin(),x.end()
#define EPS (1e-9)
#define equals(a,b) (fabs((a)-(b))<EPS)

using namespace std;

bool LT(double a,double b) { return !equals(a,b) && a < b; }
bool LTE(double a,double b) { return equals(a,b) || a < b; }

const string YES = "";
const string NO  = "";

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

void solve() {

}

int main() {
  ll a;
  string b;
  cin >> a >> b;
  ll v1 = a;
  rep(i,(int)b.size()) {
    if( b[i] == '.' ) {
      b[i] = ' ';
    }
  }
  stringstream ss;
  ss << b;
  string tmp;
  string fuck = "";
  while( ss >> tmp ) {
    fuck += tmp;
  }
  ll v2 = atoll(fuck.c_str());
  //cout << v1 << " " << v2 << endl;
  ll v3 = v1 * v2;
  //cout << "v3 = " << v3 << endl;
  string s = to_string(v3);
  if( s.size() <= 2 ) {
    puts("0");
    return 0;
  }
  
  rep(i,(int)s.size()-2) {
    cout << s[i];
  } puts("");
  
  //v3 /= 100LL;
  //cout << "v4 = " << v3 <<endl;

  return 0;
}


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

string mymax(string a, string b){
    vector<pair<int, string> > ans;
    int t = 0;
    while(t<a.size() && a[t]=='0') t++;
    a = a.substr(t);
    t = 0;
    while(t<b.size() && b[t]=='0') t++;
    b = b.substr(t);
    if(a=="")a="0";
    if(b=="")b="0";
    ans.emplace_back(a.size(), a);
    ans.emplace_back(b.size(), b);
    sort(ans.rbegin(), ans.rend());
    return ans[0].second;
}

int main(){
    int w, h;
    while(cin >> w >> h, w+h){
        vector<vector<int> > c(h+2, vector<int>(w+2, -1));
        for(int i = 1; i <= h; ++i){
            if(i==0||i==h+1)continue;
            for(int j = 1; j <= w; ++j){
                char tmp;
                cin >> tmp;
                if(0 <= tmp - '0' && tmp - '0' <= 9){
                    c[i][j] = tmp - '0';
                }
            }
        }
        vector<vector <string>> dp(h+2, vector<string>(w+2, ""));
        for(int i = 1; i <= h; ++i){
            for(int j = 1; j <= w; ++j){
                if(c[i][j] == -1) continue;
                // if(c[i][j] == 0){
                //     if(dp[i-1][j] != "")
                //         dp[i][j] = mymax(dp[i-1][j], dp[i][j]);
                //     if(dp[i][j-1] != "")
                //         dp[i][j] = mymax(dp[i][j-1], dp[i][j]);
                //     if(dp[i][j] != "")
                //         dp[i][j] += (char)(c[i][j] + '0');
                //     continue;
                // }
                dp[i][j] = mymax(dp[i-1][j], dp[i][j-1]) + (char)(c[i][j] + '0');
            }
        }

        string ans = "";
        for(int i = 1; i <= h; ++i){
            for(int j = 1; j <= w; ++j){
                ans = mymax(ans, dp[i][j]);
            }
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 3284
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 1e6+100;
typedef long long ll;
struct node{
	ll a,b;
	ll id;
}s1[MAXN];
bool cmp(node a,node b){
	return a.a+a.b>b.a+b.b;
}
int main(){
	ll n;
	cin>>n;
	for(ll i=1;i<=n;i++){
		cin>>s1[i].a>>s1[i].b;
	}
	sort(s1+1,s1+n+1,cmp);
	ll ans=0;
	for(ll i=1;i<=n-1;i+=2){
		ans+=max(s1[i].a-s1[i+1].b,s1[i+1].a-s1[i].b);
	}
	if(n&1) ans+=s1[n].a;
	cout<<ans<<endl;
	return 0;
}

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

int main() {
  string a;
  cin >> a;
  
  if(a.at(0) == a.at(1) && a.at(1) == a.at(2)){
    cout << "Yes" << endl;
  }
  else if(a.at(1) == a.at(2)&&a.at(2) == a.at(3)){
    cout << "Yes" << endl;
  }
  else if(a.at(0) == a.at(1) == a.at(2) == a.at(3)){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
  
}

Measured memory_bytes: 256
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int a = Integer.parseInt(scanner.next());
        int b = Integer.parseInt(scanner.next());
        int c = Integer.parseInt(scanner.next());
        scanner.close();

        Set<Integer> set = new HashSet<>();
        set.add(a);
        set.add(b);
        set.add(c);

        System.out.println(set.size());
    }
}


Measured memory_bytes: 21972
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
typedef vector<ll> vel;
typedef vector<str> ves;
#define REP(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define rep(i, b) REP(i, 0, b)
const ll mod = 1000000007;
const double pi = 3.14159265358979;

int main() {
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    ll L = a + b, R = c + d;
    if (L < R) {
        cout << "Right" << endl;
    }
    else if (L == R) {
        cout << "Balanced" << endl;
    }
    else {
        cout << "Left" << endl;
    }
}


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

string _itoa(int num) {
    string res = "";
    while (num) {
        int mod = num % 10;
        char n = '0' + mod;
        res = n + res;
        num /= 10;
    }

    return res;
}

int main() {
    int n;
    while (cin >> n, n) {
        string str;
        cin >> str;

        for (int c = 0; c < n; c++) {
            char num = str[0];
            int count = 0;
            string tmp = "";
            for (int i = 0; i < str.size(); i++) {
                if (str[i] == num) count++;
                else {
                    string s = _itoa(count);
                    tmp += (s + num);
                    num = str[i];
                    count = 1;
                }
            }
            str = tmp;
            if (count > 0) {
                string s = _itoa(count);
                str += (s + num);
            }
        }
        cout << str << endl;
    }

    return 0;
}

Measured memory_bytes: 3260
N, M = map(int, input().split())
a = [int(input()) for _ in range(M)]
aset = set(a)
memo = [0 for _ in range(N + 10)]
memo[0] = 1
DIV = 10**9 + 7
for idx in range(N):
	if(memo[idx]):
		if(idx + 1 not in aset):
			memo[idx + 1] += memo[idx]
			memo[idx + 1] %= DIV
		if(idx + 2 not in aset):
			memo[idx + 2] += memo[idx]
			memo[idx + 2] %= DIV
print(memo[N])

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

using namespace std;

#define MOD 1000000007
typedef long long int ll;

int main(){

	ios_base::sync_with_stdio(false);
	cin.tie(0);

	string s;
	cin>>s;
	int n=s.size();
	int dpr[n+1]={0};
	int dpl[n+1]={0};

	int rec=0;
	for(int i=1;i<=n;i++){
		dpr[i]=rec;
		if(s[i-1]=='R'){
			rec=i;
		}
	}
	rec=0;
	for(int i=n;i>=1;i--){
		dpl[i]=rec;
		if(s[i-1]=='L'){
			rec=i;
		}
	}

	int ans[n+1]={0};
	for(int i=1;i<=n;i++){
		if(s[i-1]=='L'){
			int tr=dpr[i];
			if(tr==0){
				continue;
			}
			if((i-tr)%2==1){
				ans[tr+1]++;
			}
			else{
				ans[tr]++;
			}
		}
		else{
			int tl=dpl[i];
			if(tl==0){
				continue;
			}
			if((tl-i)%2==1){
				ans[tl-1]++;
			}
			else{
				ans[tl]++;
			}
		}
	}	
	for(int  i=1;i<=n;i++){
		cout<<ans[i]<<" ";
	}
	cout<<endl;

        
	

	return 0;
}

Measured memory_bytes: 4960
N = int(input())
S = input()

res = 0

Rn = S.count('R')
Gn = S.count('G')
Bn = S.count('B')

res = Rn * Gn * Bn

for p in range(1, N - 1):
  for q in range(1, min(p, N - p - 1) + 1):
    i, j, k = p - q, p, p + q
    if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
      res -= 1

print(res)


Measured memory_bytes: 9168
r, c = gets.split.map(&:to_i)
table = []
result_table = []

r.times do
  row = gets.split.map(&:to_i)
  table.push(row)
  result_table.push(row.push(row.sum))
end

column_sumed_row = []
table.transpose.each do |t|
  column_sumed_row.push(t.sum)
end
result_table.push(column_sumed_row)
puts result_table.map{|r|r*' '}


Measured memory_bytes: 7124
import java.util.Scanner;
import java.util.Arrays;

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

    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();

    int x = 0 ;

      for(;a<=b; a++){

        if(c%a == 0){
          x++;
        }
      }

    System.out.println(x);

    } 
}


Measured memory_bytes: 26340
import copy

N, Ma, Mb = map(int, input().split())
ABC = [tuple(map(int, input().split())) for _ in range(N)]

INF, W = 10000, 10 * max(Ma, Mb) * N
dp = [[INF] * (2 * W + 1)]

for a, b, c in ABC:
    dp.append(copy.deepcopy(dp[-1]))
    df = a * Mb - b * Ma
    dp[-1][df] = min(dp[-1][df], c)
    for d in range(-W, W + 1):
        dp[-1][df + d] = min(dp[-1][df + d], c + dp[-2][d])

print("-1" if dp[N][0] == INF else dp[N][0])


Measured memory_bytes: 6260
#include<cstdio>
#include<iostream>
#include<map>
using namespace std;

map<int,int> a;
int f[100005];

int main(){
	int n,i,s=0,t;
	
	cin>>n;
	
	for(i=1;i<=n;i++){
		cin>>f[i];
		a[f[i]]=a[f[i]]+1;
	}
	
	for(i=1;i<=n;i++){
		if(a[f[i]]<f[i])s+=a[f[i]];
		if(a[f[i]]>f[i])s+=a[f[i]]-f[i];
		a[f[i]]=0;
	}
	
	cout<<s<<endl;
	return 0;
}

Measured memory_bytes: 5120
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <deque>
#include <cctype>
#include <cstdio>
#include <math.h>
#include <set>
using namespace std;
int main(void){
    int n,k,x,y;
    cin >> n >> k >> x >> y;
    long long ans =0;
    for(int i=1;i<=n;i++){
        if(i<=k){
            ans+=x;
        }else{
            ans+=y;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/* 
 * File:   main.c
 * Author: kundaikwangwari
 *
 * Created on July 26, 2019, 1:57 PM
 */

#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#define NIL -1
#define N 100000
/*
 * 
 */
typedef struct{
   int a;
   int b;
   int cost;
}Inf;

int parent[N];

void GenerateSet(int n){
 
    for(int i = 0; i <= n; i++){
        parent[i] = i;
        //printf("%d ",parent[i]);
        }
}

int FindParent(int a){
    
    //printf("finding parent\n");
    if(parent[a] == a)return a;
    return parent[a] = FindParent(parent[a]);
}

void CombineSets(int a, int b){
 
   // printf("Combining sets...");
    //printf("findparent(%d) is %d, findparent(%d) is %d\n",a,FindParent(a),b,FindParent(b));
    parent[FindParent(a)] = FindParent(b);
    //printf("findparent(%d) is %d, findparent(%d) is %d\n",a,FindParent(a),b,FindParent(b));
    return;
}

int SameSet(int a, int b){

    //printf("in samesetfunction...%d %d %d %d %d\n",a,b,FindParent(a),FindParent(b),(FindParent(a) == FindParent(b)));
    return (FindParent(a) == FindParent(b));
    
}
/*
void MinimumSpanningTree(A,w){
    
}
*/
int main(int argc, char** argv) {

    
    int n,MST=0;
    scanf("%d",&n);
    int table[n+1][n+1];
    Inf data[N], temp;
    
    int  Nodes = n, Edges;
    for(int a = 0; a < n; a++){
        for(int b = 0; b < n; b++){
        scanf("%d",&table[a][b]);
        if(table[a][b] != NIL){
        data[Edges].a = a;
        data[Edges].b = b;
        data[Edges].cost = table[a][b];
        Edges++;
        }
        }
    }
        GenerateSet(Nodes);
        
        
        for(int i = Edges - 1; i >= 0; i--){
            for(int k = 0; k < i; k++){
                if(data[k].cost > data[k+1].cost){
                    temp = data[k+1];
                    data[k+1] = data[k];
                    data[k] = temp;
                }
            }
        }
        
        //for(int i = 0; i < Edges; i++)printf("(%d,%d) %d\n",data[i].a,data[i].b,data[i].cost);
        for(int i = 0; i < Edges; i++){
            //printf("%d).I am here\n",i);
            if(SameSet(data[i].a, data[i].b))continue;
            MST +=data[i].cost;
            //printf("hello\n");
            CombineSets(data[i].a,data[i].b);
        }
 
        printf("%d\n",MST);
    return (0);
}


Measured memory_bytes: 2108
# coding=utf-8

A, B, C, D = 4, 9, 2, 3
A, B, C, D = 10, 40, 6, 8
A, B, C, D = 314159265358979323, 846264338327950288, 419716939, 937510582
A, B, C, D = map(int, raw_input().split())


def f(d):
    return B / d - (A - 1) / d


def gcd(a, b):
    while b != 0:
        a, b = b, a % b
    return a

E = C / gcd(C, D) * D

good = f(C) + f(D) - f(E)
print B - A + 1 - good


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

int main() {
  long long int n,ans;
  cin>>n;
  vector<int> a(n);
  for(int i=0;i<n;i++)cin>>a.at(i);
  sort(a.begin(),a.end());
  ans=1;
  
  if(n%2==1){
    for(int i=0;i<n;i++){
      if(i==0){
        if(a.at(i)!=0){
          cout<<0<<endl;
          return 0;
        }
      }
      else if(a.at(i)!=((i+1)/2)*2){
        cout<<0<<endl;
        return 0;
      }
    }
  }
  else{
    for(int i=0;i<n;i++){
      if(a.at(i)!=(i/2)*2+1){
        cout<<0<<endl;
        return 0;
      }
    }
  }
    
    
    
  for(int i=0;i<n/2;i++){
    ans*=2;
    if(ans>=1000000007)ans%=1000000007;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 640
#include <string>
#include <iostream>
using namespace std;
int N, D; string X, Y;
int main() {
	cin >> N >> X >> D; Y = X;
	for (int i = 0; i < N; i++) {
		if (D == 0) break;
		if (X[i] == '0') {
			Y[i] = '1'; D--;
		}
	}
	for (int i = N - 1; i >= 0; i--) {
		if (D == 0) break;
		if (X[i] == '1') {
			Y[i] = '0'; D--;
		}
	}
	cout << Y << endl;
	return 0;
}

Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
int bai,hei;
vector<int >g[200005];
int vis[200005];
int uss[200005];
int daan[200005];
void dfs(int p)
{
    for(int i=0;i<g[p].size();i++)
    {
        if(vis[g[p][i]]==0)
        {
            if(vis[p]==1)
            {
                vis[g[p][i]]=2;
                hei++;
                dfs(g[p][i]);
            }
            else
            {
                vis[g[p][i]]=1;
                bai++;
                dfs(g[p][i]);
            }
        }
    }
}
int main()
{
    //freopen("t5.in","r",stdin);
   //freopen("t5.out","w",stdout);
    int i,j,n,m,q;
    hei=0;bai=0;
    cin>>n;
    int m3=n/3;
    int m2=(n+1)/3;
    int m1=(n+2)/3;
    for(i=1;i<n;i++)
    {
        int u,v;
        scanf("%d%d",&u,&v);
        g[u].push_back(v);
        g[v].push_back(u);
    }
    vis[1]=1;
    bai=1;
    hei=0;
    dfs(1);
    if(bai>hei)
    {
        swap(hei,bai);
        for(i=1;i<=n;i++)
        {
            if(vis[i]==1)vis[i]=2;
            else vis[i]=1;
        }
    }
    memset(uss,0,sizeof(uss));
    memset(daan,0,sizeof(daan));
    int cs;
    if(bai<m2)
    {
        cs=3;
        for(i=1;i<=n;i++)
        {
            if(vis[i]==1)
            {
                uss[cs]=1;
                daan[i]=cs;
                cs+=3;
            }
        }
        cs=1;
        for(i=1;i<=n;i++)
        {
            if(vis[i]==2)
            {
                if(!uss[cs])
                {
                    daan[i]=cs;cs++;
                }
                else
                {
                    cs++;i--;
                }
            }
        }
    }
    else
    {
        cs=2;
        for(i=1;i<=n;i++)
        {
            if(vis[i]==1)
            {
                uss[cs]=1;
                daan[i]=cs;
                cs+=3;
            }
            if(cs>n)break;
        }
        cs=3;
        for(i=1;i<=n;i++)
        {
            if(vis[i]==1&&daan[i]==0)
            {
                uss[cs]=1;
                daan[i]=cs;
                cs+=3;
            }
        }
        cs=1;
         for(i=1;i<=n;i++)
        {
            if(vis[i]==2)
            {
                if(!uss[cs])
                {
                    daan[i]=cs;cs++;
                }
                else
                {
                    cs++;i--;
                }
            }
        }
    }
    for(i=1;i<n;i++)printf("%d ",daan[i]);
    cout<<daan[n]<<endl;
    return 0;
}


Measured memory_bytes: 20096
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <vector>
#include <sstream>
#include <set>
#include <queue>
#include <stack>
#include <cctype>
#include <map>
#include <climits>
#include <bitset>
using namespace std;
#define MATH_PI 3.14159265358979323846
int main(){
	ios::sync_with_stdio(false);
	int iSum = 0, iMax = 0, i ,iInput;
	for (i = 1; i <= 3; ++i){
		cin >> iInput;
		iSum += iInput;
		iMax = max(iMax, iInput);
	}
	cout << iSum - iMax << endl;
endapp:
	//system("pause > nul");
	return 0;
}

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

typedef unsigned long uint;

int main(void)
{
	uint n;
	uint t;
	uint i;
	uint time;
	uint t_i;
	uint t_prev;

	scanf("%ld %ld", &n, &t);

	scanf("%ld", &t_i);
	time = 0;
	t_i = 0;
	t_prev = 0;
	for(i=0; i<n-1; i++){
		scanf("%ld", &t_i);
		if((t_i - t_prev) > t){
			time += t;
		} else {
			time += t_i - t_prev;
		}
		t_prev = t_i;
	}
	time += t;
	printf("%d\n", time);
    
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <vector>
#include <string>
#define mod 1000000007
#define INF LLONG_MAX
#define loop(i,x,n) for(int i = x; i < n; i++)
#define pb push_back
#define mp make_pair
#define ll long long 
#define vpl vector< pair<ll,ll> >
#define vpi vector< pair<int,int> >
#define vi vector<int>
#define vl vector<ll>
#define vch vector<char>
#define se second
#define fi first
using namespace std;

ll solve(int wts[],ll pro[],int N,int W){
		ll dp[N+1][W+1] = {0};
		
		for(int n=0;n<=N;n++){
			for(int w=0;w<=W;w++){
				if(n == 0 || w == 0){
					dp[n][w] = 0;
 				}else{
 					ll inc = 0,ex = 0;
 					if(wts[n-1] <= w){
 						inc = pro[n-1] + dp[n-1][w-wts[n-1]];
 					}
 					ex = dp[n-1][w];
 					
 					dp[n][w] = max(inc,ex);
 				}
			}
		}
		
		return dp[N][W];
}


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

	
	int n,w;
	cin >> n >> w;
	
	int wts[n];
	ll pro[n];
	
	for(int i=0;i<n;i++){
		cin >> wts[i] >> pro[i];
	}
	
	cout << solve(wts,pro,n,w) << "\n";
	
	
	
	return 0;
}



Measured memory_bytes: 79232
# -*- coding: utf-8 -*-
"""
B - 仲良しうさぎ / Friendly Rabbits
https://atcoder.jp/contests/code-festival-2016-quala/tasks/codefestival_2016_qualA_b

"""
import sys


def solve(N, rabbits):
    ans = 0
    for i, r in enumerate(rabbits[1:], start=1):
        if rabbits[r] == i:
            ans += 1
    return ans // 2


def main(args):
    N = int(input())
    rabbits = [-1] + [int(a) for a in input().split()]
    ans = solve(N, rabbits)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])


Measured memory_bytes: 13880
#include <iostream>
#include <string>
using namespace std;
int main(){
  int k;
  cin >> k;
  string str;
  cin >> str;
  if(str.length() > k)
    cout << str.substr(0,k) << "...\n";
  else 
    cout << str << '\n';
  return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
	int n,date[500];
	long long ans=1;
	cin>>n;
	for(int i=0;i<n;i++)cin>>date[i];
	sort(date, date + n, greater<int>());
	for(int i=0;i<n;i++)ans+=max(0,date[i]-i/4);
	cout<<ans<<endl;
	
	return 0;
}


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

#define select(_1, _2, x, ...) x

#define repn(i, n) for (int i = 0; i < (n); i++)
#define repr(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, ...) select(__VA_ARGS__, repr, repn)(i, __VA_ARGS__)

#define rrepn(i, n) for (int i = (n - 1); i >= 0; i--)
#define rrepr(i, a, b) for (int i = (b - 1); i >= (a); i--)
#define rrep(i, ...) select(__VA_ARGS__, rrepr, rrepn)(i, __VA_ARGS__)

#define umax(m, x) (m = max(m, x));
#define umin(m, x) (m = min(m, x));

#define rng(v) v.begin(), v.end()
#define rrng(v) v.rbegin(), v.rend()

#define debug(x) cerr << #x << " = " << x << endl

using namespace std;

using ll = long long int;

using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using vc = vector<char>;
using vs = vector<string>;

using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using vvs = vector<vector<string>>;

const int INF = 1e9;
const ll LINF = 1e18;

inline void yn(bool f) { cout << (f ? "Yes" : "No") << endl; }


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

    while (true) {
        c -= b;
        if (c <= 0) {
            cout << "Yes" << endl;
            break;
        }
        a -= d;
        if (a <= 0) {
            cout << "No" << endl;
            break;
        }
    }

    return 0;
}


Measured memory_bytes: 3624
#include <iostream>
#include <string>
#include <cmath>
#include <iomanip>

using namespace std;

using ll = long long;
using ld = long double;

#define PI 3.14159265358979323846264338327950L

int main(){
  int A, B;
  
  cin >> A >> B;
 
  cout << A*B << endl;
  
  return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1000000007;
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

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

    if(n%2==1){
        cout<<0<<endl;
        return 0;
    }

    n/=2;
    ll ans=0;
    for(ll i=5;i<=n;i*=5){
        ans+=n/i;
    }

    cout<<ans<<endl;
}


Measured memory_bytes: 3616
x, k, d = map(int, input().split())

ans = 0
if k * d < abs(x):
    if x >= 0:
        ans = x - k*d
    else:
        ans = x + k*d
    print(abs(ans))
    exit()
    
xd = x // (2*d)
if k % 2:
    tmp = x - 2*d*xd
    l = [abs(tmp-d), abs(tmp+d), abs(tmp+3*d)]
    ans = min(l)
else:
    tmp = x - 2*d*xd
    l = [abs(tmp-2*d), abs(tmp), abs(tmp+2*d)]
    ans = min(l)
print(ans)

Measured memory_bytes: 9216
input1 = int(input())
input2 = str(input())

result_string = []
for i in range(input1):
    if i > 0 and input2[i] != input2[i-1]:
        result_string.append(input2[i])
    elif i == 0:
        result_string.append(input2[i])
#print(''.join(result_string))
print(len(result_string))

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


// M A F I A - M A F I A - M A F I A - M A F I A - M A F I A - M A F I A //

#define int               long long
#define endl              '\n'
#define ff                first
#define ss                second
#define mp                make_pair
#define pb                push_back
#define vii               vector<int> 
#define mii                          map< int, int >
#define msi                          map< string, int > 
#define mib                          map< int, bool > 
#define pii               pair<int,int>
#define vpii              vector< pii >
#define all(v)            v.begin(),v.end()
#define loop(i,s,e)       for(int i=s;i<e;i++)
#define rloop(i,e,s)      for(int i=e;i>=s;i--)
#define mset(a,f)              memset(a,f,sizeof(a))
#define M                 1000000007
#define fastio            ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define prvec(v)          loop(i_u_j,0,v.size())cout << v[i_u_j] <<" "; cout << endl;
#define prarr(arr,n)      loop(i_u_j,0,n)cout << arr[i_u_j] << " "; cout << endl;
#define bug(...)        __f (#__VA_ARGS__, __VA_ARGS__)


template <typename Arg1>
void __f (const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << endl; }
template <typename Arg1, typename... Args>
void __f (const char* names, Arg1&& arg1, Args&&... args)
{
     const char* comma = strchr (names + 1, ',');
     cout.write (names, comma - names) << " : " << arg1 << " | "; __f (comma + 1, args...);
}

// M A F I A - M A F I A - M A F I A - M A F I A - M A F I A - M A F I A //
const int N = 3e5 + 7;
int n, k;
int arr[N];


void solve()
{
      cin >> n >> k;
      int mn = 1e8;
      loop(i,0,n) cin >> arr[i], mn = min(mn, arr[i]);
      bool dp[k+1];
      mset(dp,false);
      loop(i,0,mn) if( i <= k ) dp[i] = 0;

      loop(i,mn, k+1)
      {
            loop(j,0,n)
            {
                   if( i >= arr[j] ) dp[i] = ( dp[i] || !dp[ i - arr[j] ] );
            }
      }

      if( dp[k] ) cout << "First";
      else cout << "Second";
}

int32_t main() {
    fastio;

  
  int t = 1; 
  //cin>>t;
  
  while(t--) solve();
  
  


}


// M A F I A - M A F I A - M A F I A - M A F I A - M A F I A - M A F I A //















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

void main_()
{
    ll N;
    cin >> N;

    vector<vector<ll>> dp(3);
    for (auto&& i : dp) {
        i.reserve(N);
        ll n;
        cin >> n;
        i.push_back(n);
    }
    for (ll i = 1; i < N; ++i) {
        ll a, b, c;
        cin >> a >> b >> c;
        dp[0].push_back(max(dp[1][i - 1], dp[2][i - 1]) + a);
        dp[1].push_back(max(dp[0][i - 1], dp[2][i - 1]) + b);
        dp[2].push_back(max(dp[0][i - 1], dp[1][i - 1]) + c);
    }

    cout << max({ dp[0][N - 1], dp[1][N - 1], dp[2][N - 1] }) << endl;
}
int main()
{
    cin.tie(nullptr);
    cout.tie(nullptr);
    ios_base::sync_with_stdio(false);
    main_();
    return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int b, N;
  cin >> N;
  b = 100;
  for (int i = 0; i < N; i++) {
    int A, a;
    cin >> A;
    a = 0;
    while (A%2 == 0) {
      A /= 2;
      a++;
    }
    if (b > a) b = a;
  }
  cout << b <<endl;
}
   


Measured memory_bytes: 256
import java.util.Scanner;

class Main{
public static void main(String args[]){
String c;
Scanner scan = new Scanner(System.in);
c = scan.next();
if(c.equals("a") || c.equals("e") || c.equals("i") || c.equals("o") || c.equals("u")){
System.out.println("vowel");
}else{
System.out.println("consonant");
}
}
}

Measured memory_bytes: 9680
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
  
int main() {
  int N;
  cin >> N;
  int ans = 0;
  for(int i = 1;i < N-i;i++) {
    ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <vector>
using namespace std;
int main(){
    int N; cin >> N;
    
    map <int, int> cnt;
    for (int i = 1; i <= N; i++){
        int num = i;
        for (int j = 2; j <= i; j++){
            while (num % j == 0){
                cnt[j]++;
                num = num / j;
            }
        }
    }

    vector <int> A(100);
    for (int i = 0; i < 100; i++){
        if (cnt[i] >= 2){
            A[3]++;
        }
        if (cnt[i] >= 4){
            A[5]++;
        }
        if (cnt[i] >= 14){
            A[15]++;
        }
        if (cnt[i] >= 24){
            A[25]++;
        }
        if (cnt[i] >= 74){
            A[75]++;
        }
    }

    int ans = 0;
    ans += A[75];
    ans += A[25] * (A[3] - 1);
    ans += A[15] * (A[5] - 1);
    ans += A[5] * (A[5] - 1) / 2 * (A[3] - 2);

    cout << ans << endl;
    
    return 0;    
}

Measured memory_bytes: 256
#include<iostream>
#include <stdlib.h>
#include<stdio.h>
using namespace std;

int sort(const void *a, const void *b){
    return *(int*)a - *(int*)b;
}

int main(){
    int num;
    int a[100];
    int cost = 1000000;
    int sum = 0;

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

    qsort(a, num, sizeof(int), sort);

    for(int i = a[0]; i <= a[num - 1]; i++){
        for(int j = 0; j < num; j++){
            sum += (i - a[j]) * (i - a[j]);
        }
        if(sum < cost){
            cost = sum;
        }
        sum = 0;
    }

    cout << cost << '\n';

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb(x) push_back(x)
#define all(x) x.begin(), x.end()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = 1e9;
const ll INF = 1e18;
const ld EPS = 1e-10;

int main(){
    string S;
    cin >> S;
    int N = S.size();
    int pw[N];
    pw[0] = 1;
    rep2(i, 1, N) pw[i] = (pw[i-1]*10)%2019;
    //下i桁を2019で割ったあまり
    int sum[N+1];
    map<int, ll> mp;
    sum[0] = 0;
    rep(i, N){
        sum[i+1] = (sum[i]+pw[i]*(S[N-1-i]-'0')) % 2019;
    }
    rep2(i, 0, N){
        mp[sum[i]]++;
    }
    ll ans = 0;
    for(auto &e: mp){
        ans += e.second*(e.second-1)/2;
    }
    cout << ans << endl;
}

Measured memory_bytes: 5320
#include<iostream>
using namespace std;
int main()
{
    bool water[31];
    bool sugar[3001];
    for(int i = 0; i < 31; i++){
        water[i] = false;
    }
    for(int i = 0; i < 3001; i++){
        sugar[i] = false;
    }
    int a, b, c, d, e, f;
    cin >> a >> b >> c >> d >> e >> f;
    int ans_sum = a * 100;
    int ans_sugar = 0;
    for(int i = 0; i <= (f / (100 *a)); i++){
        for(int j = 0; j <= (f / (100 * b)); j++){
            if(100 * a  * i + 100 * b * j > f){
                break;
            }
            if(i == 0 && b == 0){
                continue;
            }
            water[a * i + b * j] = true;
        }
    }
    for(int i = 0; i * c <= e * 30; i++){
        for(int j = 0; i * c + j * d <= e * 30; j++){
            sugar[i * c + j * d] = true;
        }
    }
    for(int i = 1; i <= (f / 100); i++){
        for(int j = 0; j <= i * e; j++){
            if((water[i] == false) || (sugar[j] == false)){
                continue;
            }
            if(i * 100 + j > f){
                break;
            }
            if(((1.0 * (double)j) / ((double)i * 100.0 + (double)j)) - ((double)ans_sugar / (double)ans_sum * 1.0) > 0.0){
                //cout << ans_sugar / (ans_sum * 1.0) << " " << (1.0 * j) / (i * 100 + j) << endl;
                //cout << ((1.0 * j) / (i * 100 + j)) - (ans_sugar / ans_sum * 1.0) << endl;
                ans_sum = i * 100 + j;
                ans_sugar = j;
            }
            //cout << ans_sum << " " << ans_sugar << endl;
        }
    }
    cout << ans_sum << " " << ans_sugar << endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
p = list(map(int, input().split()))

up = list(range(1, N+1))
count = 0
for i in range(N):
    if(p[i] != up[i]):
        count += 1

if(count == 2 or count == 0):
    print('YES')
else:
    print('NO')


Measured memory_bytes: 2940
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define REP(i, n) for(int i = 1; i < (int)(n); ++i)
using namespace std;

int main() {
    int N, H, W;
    cin >> N >> H >> W;
    cout << (N - W + 1) * (N - H + 1) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl
#define debug cout << "hi" << endl

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

const ll MOD = 1e9 + 7;
const int INF32 = 1<<30;
const ll INF64 = 1LL<<60;
const ld pi = 3.141592653589793;

void solve(){
     ll a,b;
     cin >> a >> b;
     map<ll,ll>mp;
     ll aa = a;ll bb = b;
     for(int i = 2;i<=max(sqrt(a),sqrt(b));i++){
        if(aa%i==0){
            mp[i]++;
            while(aa%i==0) aa /= i;
        }
        if(bb%i==0){
            mp[i]++;
            while(bb%i==0) bb /= i;
        }
     }
     ll ans = 0;
     if(aa==bb&&aa!=1) ans++;
     for(auto it : mp){
        if(it.second == 2)
            ans++;
     }
     cout << ans+1;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    return 0;
}

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

#define   M             1005
#define   ll            long long
#define   PI            atan(1.0)*4
#define   mst(x,v)      memset(x,v,sizeof(x))
#define   inf           (int)1e9
#define   rush()        int T;scanf("%d",&T);while(T--)

typedef   pair<int,int> P;

int n,m,ans;
int a[M],b[M];


int main() {
	
	scanf("%d",&n);
	
	int t,ans=0;
	
	for(int i=0,sum=0;i<n;i++) {
		scanf("%d",&t);
		sum+=t;
		a[i]=sum;
	}
	
	for(int i=0;i<n;i++) scanf("%d",&b[i]);
		
	for(int i=n-1;i>=0;i--) {
		b[i]=b[i+1]+b[i];
		ans=max(ans,b[i]+a[i]);
	}
		
	
//	for(int i=1;i<=n;i++) printf(i==n?"%2d\n":"%2d ",i);
//	for(int i=0;i<n;i++) printf(i==n-1?"%2d\n":"%2d ",a[i]);
//	for(int i=0;i<n;i++) printf(i==n-1?"%2d\n":"%2d ",a[i]+b[i]);

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



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

bc = [list(map(int, input().split())) for i in range(m)]
bc = sorted(bc, key=lambda x: x[1], reverse=True)
count = 0

for i in range(m):
  b, c = bc[i][0], bc[i][1]
  l += [c]*b
  count += b
  if count >= n:
    break

l.sort(reverse=True)
print(sum(l[:n]))

Measured memory_bytes: 35648
using System;

class Atcoder51
{
    public static void Main()
    {
        string[] input = Console.ReadLine().Split(' ');
        int a = int.Parse(input[0]);
        int b = int.Parse(input[1]);

        if (a + b >= 10)
            Console.WriteLine("error");
        else
            Console.WriteLine(a + b);
    }
}

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

#define PI 3.14159265358979323846264338327950L
#define ll long long

using namespace std;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int a, b;
    cin >> a >> b;
    cout << a * b << "\n";

    return 0;

}


/*int t;
    cin >> t;
    while (t--) {
        int n;
        cin >> n;
        set<int> sets;
        for (int i = 0; i < n; i++) {
            int temp;
            cin >> temp;
            if (temp % 2 == 0) {
                sets.insert(temp);
            }
        }
        ll answer = 0;
        for (auto i = sets.end() - 1; i != sets.begin() - 1; --i) {
            int number = *i;
            while (number % 2 == 0) {
                if (sets.find(number) != sets.end()) {
                    sets.erase(number);
                }f
                answer++;
                number = number / 2;
            }
        }
    }*/


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

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

    int r, c;
    cin >> r >> c;

    int sh[101][101] = {};
    for (int i=0; i<r; ++i) {
        for (int j=0; j<c; ++j) {
            cin >> sh[i][j];
            sh[r][j] += sh[i][j];
            sh[i][c] += sh[i][j];
            sh[r][c] += sh[i][j];
        }
    }

    for (int i=0; i<r+1; ++i) {
        for (int j=0; j<c+1; ++j) {
            cout << (j == 0 ? "" : " ") << sh[i][j];
        }
        cout << endl;
    }

    return 0;
}


Measured memory_bytes: 3184
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include <iostream>
using namespace std;

class abc076a {
public:
	void solve(std::istream& in, std::ostream& out) {
	    int r, g;
	    in >> r >> g;

	    int ans = 2 * g - r;
	    out << ans << endl;

	}
};


int main() {
	abc076a solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define INF (1e9)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
const long double PI = acos(-1.0L);
const long long MOD = 1000000007LL;
//const long long MOD = 998244353LL;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
template<class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true;} return false; }
template<class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true;} return false; }
///////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    string S,T; cin >> S >> T;
    int N = S.size();
    int M = T.size();

    reverse(all(S)); reverse(all(T));
    rep(i,N-M+1) {
        bool ok = true;
        rep(j,M) {
            if (T[j] != S[j+i] && S[j+i] != '?') ok = false;
        }
        if (ok) {
            rep(j,M) S[j+i] = T[j];
            rep(j,N) {
                if (S[j] == '?') S[j] = 'a';
            }
            reverse(all(S));
            cout << S << endl;
            return 0;
        }
    }

    cout << "UNRESTORABLE" << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<deque>
#include<vector>
#include<cmath>
#include<algorithm>
#include<string>
int main(void)
{
	int x;
	std::cin >> x;
	if(x >= 30)
	{
		std::cout << "Yes" << std::endl;
	}
	else
	{
		std::cout << "No" << std::endl;
	}
    return 0;
}


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

//解説
int main() {
    int n;
    cin >> n;
    vector<int> a(n,0);
    ll sum = 0;
    rep(i,n){
        cin >> a.at(i);
        sum += a.at(i)-1;
    }
    cout << sum << endl;
    return 0;
}

/*
やっほい！
　　　　　　　やほほい！
　　　　+　　 　*
　　　 ∧∧　　. ∧∞∧　*
*　ヽ(=´ω｀)人(´ω｀*)ﾉ
　.～（ O x.） （ 　 O)～　+
。*　 　∪　　　　∪
*/

Measured memory_bytes: 256
n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
x,ans = [],0
def f(m):
	q = [i+1 for i in range(m)]+x
	c = [[True]*51 for i in range(51)]
	for i in range(51): c[i][i] = False
	for i in q:
		for j in range(i,51): c[j][j%i] = False
	for k in range(51):
		for i in range(51):
			for j in range(51): c[i][j]*=bool(c[i][k]+c[k][j])
	return any(c[a[i]][b[i]] for i in range(n))
if f(50): print(-1)
else:
	for i in range(49,-1,-1):
		if f(i): x.append(i+1)
	for i in x: ans+=2**i
	print(ans)

Measured memory_bytes: 3064
#include<stdio.h>
     
    int main(){
    	int n,m,b=0;
    	int a[1000];
       int t=0;
     
    	scanf("%d %d",&n,&m);
     
    	for(int i=0;i<n;i++){
    		scanf("%d",&a[i]);
    		t=t+a[i];
    	}
    	for(int i=0;i<n;i++){
    		if(a[i]*4*m>=t){
             b++;
          }
       }
     
    	if(b>=m){
          printf("Yes");
       }else{
          printf("No");
       }
       
       return 0;
    }

Measured memory_bytes: 1712
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<map>
#include<list>
#include<cctype>
#include<climits>
#include<bitset>
#include<stack>

using namespace std;

typedef long long ll;

const int dx[4] = { 1, 0, -1, 0 }, dy[4] = { 0, 1, 0, -1 };
const int MAX = 19;
int W, H, fld[10][10];
int P, sx, sy;
map<pair<pair<int, int>, int>, int> memo;

inline int CountBit(int s)
{
	int res = 0;
	for (int i = 0; i < P; i++) res += (s >> i) & 1;
	return res;
}

inline bool IsInside(int x, int y)
{
	return 0 <= x && x < W && 0 <= y && y < H;
}

inline bool CanDown(int x, int y, int s, int noBits)
{
	if (x == sx && y == sy && noBits == P) return true;
	if (fld[y][x] == -1) return false;
	return ((s >> fld[y][x]) & 1) == 0;
}

int DFS(int x, int y, int s)
{
	int cnt = CountBit(s);
	if (x == sx && y == sy && cnt == P) return 1;
	pair<pair<int, int>, int> state = make_pair(make_pair(x, y), s);
	if (cnt < MAX)
	{
		map<pair<pair<int, int>, int>, int>::iterator itr = memo.find(state);
		if (itr != memo.end()) return itr->second;
	}
	int sum = 0;
	for (int i = 0; i < 4; i++)
	{
		int nx = x + dx[i], ny = y + dy[i];
		while (IsInside(nx, ny) && !CanDown(nx, ny, s, cnt))
			nx += dx[i], ny += dy[i];
		if (!IsInside(nx, ny)) continue;
		sum += DFS(nx, ny, s | (1 << fld[ny][nx]));
	}
	if (cnt < MAX && !(cnt >= 16 && sum == 0)) memo[state] = sum;
	return sum;
}

signed main()
{
	while (cin >> W >> H, W || H)
	{
		memo.clear();
		P = 0;
		for (int i = 0; i < H; i++)
		{
			for (int j = 0; j < W; j++)
			{
				cin >> fld[i][j];
				if (fld[i][j] == 0) fld[i][j] = -1;
				else if (fld[i][j] == 1) fld[i][j] = P++;
				else sx = j, sy = i, fld[i][j] = -1;
			}
		}
		printf("%d\n", DFS(sx, sy, 0));
	}
	return 0;
}

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

int main() {
  int N, K, sum = 0;
  cin >> N >> K;
  vector<int> h;
  for (int i = 0; i < N; ++i) {
    int x;
    cin >> x;
    h.push_back(x);
    if (x >= K)
      ++sum;
  }
  cout << sum << endl;
}


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

typedef long long ll;

int main(){
    int n;
    cin >> n;
    int ans = 0;
    vector<int> a(n), b(n);
    for(int i=0; i<n; i++) cin >> a[i];
    for(int i=0; i<n; i++) cin >> b[i];
    vector<int> c(n);
    ll re = 0;
    for(int i=0; i<n; i++){
        c[i] = a[i] - b[i];
        if(c[i] < 0){
            re += abs(c[i]);
            ans++;
        } 
    }
    sort(c.rbegin(), c.rend());
    for(int i=0; i<n; i++){
        if(c[i] > 0 && re > 0){
            re -= c[i];
            ans++;
        }
        else{
            break;
        }
    }
    if(re > 0) cout << -1 << endl;
    else cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1408
s = input()
k = int(input())

# 1種類の文字の連続の場合
if len(set(s)) == 1:
    print(len(s) * k // 2)

else:
    count_l = []
    before_mozi = ''

    for mozi in s:
        if before_mozi == mozi:
            count_l[-1] += 1
        else:
            count_l.append(1)
        before_mozi = mozi

    # 先頭と末端の文字が同じ場合
    if s[0] == s[-1]:
        result = sum([x//2 for x in count_l[1:-1]]) * k + count_l[0]//2 + count_l[-1]//2 + (count_l[0] + count_l[-1])//2 * (k-1)

    else:
        result = sum([x//2 for x in count_l]) * k

    print(result)

Measured memory_bytes: 3064
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil,pi,factorial
    from operator import itemgetter
    def I(): return int(input())
    def MI(): return map(int, input().split())
    def LI(): return list(map(int, input().split()))
    def LI2(): return [int(input()) for i in range(n)]
    def MXI(): return [[LI()]for i in range(n)]
    def SI(): return input().rstrip()
    def printns(x): print('\n'.join(x))
    def printni(x): print('\n'.join(list(map(str,x))))
    inf = 10**17
    mod = 10**9 + 7
#main code here!
    n=I()
    ans=pow(10,n,mod)-2*pow(9,n,mod)+pow(8,n,mod)
    print(ans%mod)
    

        
        
        
        
    
if __name__=="__main__":
    main()



Measured memory_bytes: 67164