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

vector<int> to[100];
int ans[100];

int main() {
  int n;
  cin >> n;
  rep(i, n) {
    int u, k;
    cin >> u >> k;
    vector<int> v(k);
    rep(j, k) {
      int vj;
      cin >> vj;
      vj--;
      v[j] = vj;
    }
    to[i] = v;
    ans[i] = -1;
  }

  queue<int> q;
  q.push(0);
  ans[0] = 0;
  while (!q.empty()) {
    int now = q.front();
    q.pop();
    for (int next : to[now]) {
      if (ans[next] != -1) continue;
      ans[next] = ans[now] + 1;
      q.push(next);
    }
  }

  rep(i, n) printf("%d %d\n", i + 1, ans[i]);

  return 0;
}


Measured memory_bytes: 3260
N = int(input())
t, x, y = 0, 0, 0
for i in range(N):
    t_1, x_1, y_1 = map(int, input().split())
    distance = abs(x - x_1) + abs(y - y_1)
    if distance > t_1 - t or (t_1 - t - distance) % 2 != 0:
        print("No")
        exit()
print("Yes")


Measured memory_bytes: 3060
using System;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args)
    {
        var str = Console.ReadLine();
        string[] strer = str.Split(' ');
        var list = new List<int>();
        int count = 0;

        foreach (var s in strer)
        {
            list.Add(int.Parse(s));
        }

        for (int i = list[0]; i <= list[1]; i++)
        {
            if((list[2] % i) == 0)
            {
                count++;
            }
        }

        Console.WriteLine(count);
        
    }
}


Measured memory_bytes: 17996
import sys
N = int(input())
points = [list(map(int, input().split())) for _ in range(N)]

for a,b,c in points:
  if c>0:
    a,b,c
    break

f = lambda x, y: abs(a-x) + abs(b-y)

for i in range(101):
  for j in range(101):
    height = f(i, j) + c
    flg = True
    for x, y, h in points:
      if h != max(height - abs(x-i) - abs(y-j) , 0):
        flg = False
        break
    if flg:
      print(i, j, height)
      sys.exit()



Measured memory_bytes: 3064
#include<stdio.h>
#include<algorithm>
using namespace std;
int main(){
    int a;
    scanf("%d",&a);
    while(a--){
        int b,c,d;
        scanf("%d%d%d",&b,&c,&d);
        int ret=0;
int v=min(b,min(c,d));
        ret+=v;
        b-=v;c-=v;d-=v;
        ret+=v=min(b/2,c);
        b-=v*2;c-=v;
        ret+=b/3;
        printf("%d\n",ret);
    }
}

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

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

ll solve() {
    string S, T;
    cin >> S >> T;
    ll N = S.length(), M = T.length();
    vector<vector<ll>> dp(N + 1, vector<ll>(M + 1, 0));
    REP(i, N) {
        REP(j, M) {
            dp[i + 1][j + 1] = std::max(dp[i + 1][j], dp[i][j + 1]);
            if (S[i] == T[j])
                dp[i + 1][j + 1] = std::max(dp[i + 1][j + 1], dp[i][j] + 1);
        }
    }
    return dp[N][M];
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll Q;
    cin >> Q;
    REP(_, Q) {
        cout << solve() << endl;
    }
    return 0;
}


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

#define ipair pair<int,int>
#define rep(i,n) for(i=0;i<n;i++)
#define repj(i,j,n) for(i=j;i<n;i++)

#define PB(a,i) (a).push_back(i)
#define ALL(a) (a).begin(),(a).end()
#define SIZE(a,n) (a).resize(n)
#define SORT(a) sort(ALL(a))
#define VSORT(a, type) sort(ALL(a),greater<type>())
#define MAPIN(a,i,j) (a).insert(make_pair(i,j))

#define OK(i) cout<<"OK "<<i<<endl
#define Yes cout<<"Yes"<<endl
#define YES cout<<"YES"<<endl
#define No cout<<"No"<<endl
#define NO cout<<"NO"<<endl

using namespace std;

typedef unsigned long long lli;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector< vi > Matrix;

int main() {
    ll n,i,j,k;
    vi b;

    cin>>n;
    n--;
    SIZE(b,n);
    rep(i,n){
        cin>>b[i];
    }
    k=b[0];
    repj(i,1,n){
        k+=min(b[i-1],b[i]);
    }
    k+=b[n-1];

    cout<<k;
	
	return 0;
}


Measured memory_bytes: 256
n = int(input())
a = []
for i in range(n):
    a.append(int(input()))

sortedA = sorted(a)
max = sortedA[-1]
max2 = sortedA[-2]
x = 0
maxIndex = []
for i in range(n):
    if(max == a[i]):
        x += 1
        maxIndex.append(i)

if(x > 1):
    for i in range(n):
        print(max)
else:
    for i in range(n):
        if(a[i] == max):
            print(max2)
        else:
            print(max)


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

int main(){
    int n;
  	cin>>n;
    vector<double>a(n);
    double ans,y=0.0;
    for(int i=0;i<n;i++){
        cin>>a[i];
        //cout<<1/a[i]<<endl;
    }
    for(int i=0;i<n;i++){
        y+=1/a[i];
        //cout<<y<<endl;
    }
    ans=1/y;
    cout<<fixed<<setprecision(11)<<ans<<endl;
    return 0;
}



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

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[] d = new int[n];
		Arrays.fill(d, 0);
		for(int i=0;i<m;i++){
			int a = sc.nextInt();
			int b = sc.nextInt();
			d[Math.min(a, b)-1] ++;
			d[Math.max(a, b)-1] --;
		}
		sc.close();
		boolean success = true;
		for(int i=0;i<n;i++){
			if(d[i]%2!=0){
				success = false;
				break;
			}
		}
		if(success)System.out.println("YES");
		else System.out.println("NO");

	}

}

Measured memory_bytes: 65336
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<algorithm>
#include<map>
#include<cstdlib>
#include<cmath>
#include<numeric>
#include<iomanip>
#include<functional>
#include<cstdlib>
#include<queue>
#include<deque>
const double PI = acos(-1);
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
using ll =long long;
const int mod = 1000000007;
int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

ll gcd(ll a, ll b) {
	if (a % b == 0) {
		return b;
	}
	else {
		return gcd(b, a % b);
	}
}
ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
};
//fixed << setprecision(2)
bool  Array_check(ll y, ll x,ll d,ll w) {
	if (x < 0 || x >= w || y<0 || y>=d) {
		return false;
	}
	else {
		return true;
	}
	
}

//小文字=大文字+32
int dx[4] = { 1,-1,0,0 };
int dy[4] = { 0,0,1,-1 };
int main() {
	queue<int>q_x;
	queue<int>q_y;
	queue<int>wap_x;
	queue<int>wap_y;
	int d, w;
	int sx, sy;
	int gx, gy;
	char c[1000][1000];
	cin >> d >> w;
	cin >> sy >> sx;
	cin >> gy >> gx;
	sy--;
	sx--;
	gx--;
	gy--;
	ll x;
	ll y;
	ll tmpx;
	ll tmpy;
	ll wap = 0;
	ll precontain = 0;
	ll wapcount = 0;
	rep(i, d) {
		rep(j, w) { 
			cin >> c[i][j]; 
		}
	}
	q_x.push(sx);
	q_y.push(sy);
	wap_x.push(sx);
	wap_y.push(sy);
	precontain = q_x.size();
	c[sy][sx] = 'X';
	wapcount = 1;
	while (1) {
		for (ll ct = 0; ct < precontain; ct++) {
			x = q_x.front();
			q_x.pop();
			y = q_y.front();
			q_y.pop();
			
			rep(i, 4) {
				tmpx = x + dx[i];
				tmpy = y + dy[i];
				if (Array_check(tmpy, tmpx, d, w) && c[tmpy][tmpx] == '.') {
					c[tmpy][tmpx] = 'X';
					if (tmpx == gx && tmpy == gy) {
						cout << wap<<endl;
						
						return 0;
					}
					wap_x.push(tmpx);
					wap_y.push(tmpy);
					q_x.push(tmpx);
					q_y.push(tmpy);
					wapcount++;
					
				}
			}
			
		}
		
		int save = wapcount;
		if (q_x.empty()) {
			wapcount = 0;
			wap++;
			for (ll k = 0; k <save ; k++) {
				x = wap_x.front();
				wap_x.pop();
				y = wap_y.front();
				wap_y.pop();
				for (int i = -2; i < 3; i++) {
					for (int j = -2; j < 3; j++) {
						tmpy = y + i;
						tmpx = x + j;
						if (Array_check(tmpy, tmpx, d, w) &&  c[tmpy][tmpx] == '.') {
							c[tmpy][tmpx] = 'X';
							if (tmpx == gx && tmpy == gy) {
								cout << wap << endl;
					
								return 0;
							}
							q_x.push(tmpx);
							q_y.push(tmpy);
							wap_x.push(tmpx);
							wap_y.push(tmpy);
							wapcount++;
						
						}
					}
				}
			}			
		}
		if (q_x.empty()) {
			cout << -1;

			return 0;
		}
		precontain = q_x.size();
		
		
	}
}
	



Measured memory_bytes: 4588
#include <bits/stdc++.h>
 
using namespace std;
 
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define sz(x) ((int)(x).size())
#define whole(x) (x).begin(), (x).end()
 
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair < int, int > pii;
typedef pair < ll, ll > pll;
 
const int N = int(2e5) + 2;
const int LG = 20;
const ll mod = (int)1e9 + 7;
const int INF = (int)1e9 + 7;
const ll linf = 1e18; 
const ld pi = acos(-1);
const int base = 10;
const ld EPS = 1e-9;

int n, a[N], suffmn[N];
int main (){
    scanf ("%d", &n);
    for (int i = 1; i <= n; ++i) scanf ("%d", a + i);
    for (int i = n; i >= 1; --i){
        if (i == n) suffmn[i] = a[i];
        else suffmn[i] = min(suffmn[i + 1], a[i]);
    }
    for (int i = 1; i < n; ++i){
        if (suffmn[i + 1] < (a[i] - 1)) return !printf ("No\n");
    }
    return !printf ("Yes\n");
}

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

int N, K;
vector<bool> hastrick;
int d, a;
int ans;

void initFalse(){
    for (int i=0; i < N; i++){
        hastrick.at(i) = false;
    }
}

void input(){
    cin >> N >> K;
    hastrick.resize(N);
    initFalse();
    for (int k=0; k< K; k++){
        cin >> d;
        for(int i = 0; i < d; i++){
            cin >> a;
            if (!hastrick.at(a-1)){
                hastrick.at(a-1) = true;
            }
        }
    }
}

void printAns(){
    ans = 0;
    for (int i=0; i < N; i++){
        if (!hastrick.at(i)){
            ans++;
        }
    }
    cout << ans << endl; 
}

int main(){
    input();
    printAns();
}

Measured memory_bytes: 3596
#include <stdio.h>

int main() {
    int n;
    scanf("%d", &n);
    
    long long sum = 0;
    
    for (int i = 1; i < n+1; ++i){
        if (i%3 == 0 || i%5 == 0)
            continue;
        else
            sum += i;
        
    }
    
    printf("%lld", sum);
    return 0;
}


Measured memory_bytes: 1736
object Main extends App {
  scala.io.Source.stdin.getLines.toList.map(_.split(" ")).takeWhile(_(1) != "?").map(x => (x(0).toInt, x(1), x(2).toInt)).map({
    case (a, "+", b) => a + b
    case (a, "-", b) => a - b
    case (a, "*", b) => a * b
    case (a, "/", b) => a / b
    case _ => -100100100
  }).map(println)
}

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

int main() {
    string s;
    cin >> s;
    int counter = 700;
    if (s[0] == 'o') counter += 100;
    if (s[1] == 'o') counter += 100;
    if (s[2] == 'o') counter += 100;
    cout << counter << endl;
}


Measured memory_bytes: 256
import os
import sys
from collections import defaultdict, Counter, deque
from itertools import product, permutations,combinations, accumulate
from operator import itemgetter
from bisect import bisect_left,bisect
from heapq import heappop,heappush,heapify
from math import ceil, floor, sqrt
from copy import deepcopy


def main():
    n = int(input())
    vectoer = []
    flag = True
    for i in range(n):
        s = input()
        vectoer.append(s)

    if len(vectoer) != len(set(vectoer)):
        flag = False
        
    for i in range(n-1):
        if vectoer[i][-1] !=  vectoer[i+1][0]:
            flag = False
            break

    if flag:
        print("Yes")
    else:
        print("No")
    

if __name__ == '__main__':
	main()


Measured memory_bytes: 9476
#include <bits/stdc++.h>
#include <iostream>
#define ll long long
#define mem(f, x) memset(f, x, sizeof(f))
#define INF 0x3f3f3f3f
using namespace std;
const int M = 2*1e5 + 50;
const int N = 2*1e5 + 50;
ll m, n;
int nxt[N];
int hd[N], cir[N];

struct eg{
    int to, pre;
    eg( ):to(0),pre(0){}
    eg( int tt, int pp ):to(tt),pre(pp){}
}e[M];


int main( ){
    while( scanf( "%lld %lld", &n, &m ) != EOF ){
        for( int i = 1; i <= n; i++ )
            scanf( "%d", nxt+i );
        int lw = 1, fa = 1;
        lw = nxt[lw], fa = nxt[fa];
        fa = nxt[fa];
        int cnt = 1;
        while( lw != fa ){
            lw = nxt[lw];
            fa = nxt[fa], fa = nxt[fa];
            cnt++;
        }
        fa = 1;
        while( lw != fa )
            lw = nxt[lw], fa = nxt[fa];
        fa = 1;
        int ct = 0;
        bool flag = 0;
        while( fa != lw ){
            fa = nxt[fa];
            ct++;
            if( ct == m ){
                flag = 1;
                printf( "%d\n", fa );
                break;
            }
        }
        if( flag ) continue;
        m -= ct;
        m %= cnt;
        fa = lw;
        while( m ){
            fa = nxt[fa];
            m--;
        }
        printf( "%d\n", fa );
    }
    return 0;
}


Measured memory_bytes: 6044
#include<bits/stdc++.h>
using namespace std;
int main(){
  int count = 0;
  string s; cin >> s;
  int ans=0;
  for(int i=0;i<s.length();i++){
    if(s[i]=='A' || s[i]=='G' || s[i]=='C' || s[i]=='T') ++count;
    else count=0;
    ans=max(ans,count);
  }
	cout << ans << endl;
  	return 0;
}

Measured memory_bytes: 256
program contests
  implicit none
  integer              :: n, a, b
  integer, allocatable :: p(:)
  integer              :: m(3), i
  read(*,*) n
  read(*,*) a, b
  allocate(p(n))
  read(*,*) p(:)
  m = 0
  do i = 1, n
     if (p(i) .le. a) then
        m(1) = m(1) + 1
     else if (p(i) .le. b) then
        m(2) = m(2) + 1
     else
        m(3) = m(3) + 1
     end if
  end do
  deallocate(p)
  write(*,'(i0)') minval(m)
  stop
end program contests

Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pi 2*acos(0.0)
#define f first
#define s second
#define pb push_back
#define gap ' '
#define fastio {ios_base::sync_with_stdio(false);cin.tie(NULL);}
#define mod 998244353
#define N 100005
priority_queue< int,vector<int>,greater<int> > red,green;
priority_queue<int>no;

int main()
{
    int x,y,a,b,c;
    cin>>x>>y>>a>>b>>c;
    for(int i=0;i<a;i++)
    {
        ll x;
        cin>>x;
        red.push(x);
    }
    for(int i=0;i<b;i++)
    {
        ll x;
        cin>>x;
        green.push(x);
    }
    for(int i=0;i<c;i++)
    {
        ll x;
        cin>>x;
        no.push(x);
    }

    while(red.size()>x)
    {
        red.pop();
    }
    while(green.size()>y)
    {
        green.pop();
    }

    while(no.size() && (no.top()>green.top() || no.top()> red.top()))
    {
        ll x=no.top();
        no.pop();

        if(green.top()>red.top())
        {
            red.pop();
            red.push(x);
        }
        else{
            green.pop();
            green.push(x);
        }

    }

    ll ans=0;
    while(red.size()){
        ans+=red.top();
        red.pop();
    }
    while(green.size()){
        ans+=green.top();
        green.pop();
    }
    cout<<ans<<endl;

}


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

using namespace std;

int main() {
    string a,b;
    int ai,bi;
    string u;
    cin >> a >> b >> ai >> bi >> u;
    if (a == u)
        --ai;
    else if (b == u)
        --bi;
    cout << ai << " " << bi;
}


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

#define LL long long
#define pa pair<int,int>
using namespace std;
const int N = 5001;
const int inf = 2147483647;

int _max(int x, int y) {return x > y ? x : y;}
LL _min(LL x, LL y) {return x < y ? x : y;}
inline int read() {
    int x = 0, f = 1; char ch = getchar();
    while(ch < '0' || ch > '9') {if(ch == '-') f = -1; ch = getchar();}
    while(ch >= '0' && ch <= '9') x = (x << 3) + (x << 1) + (ch ^ 48), ch = getchar();
    return x * f;
}
void put(int x) {
	if(x < 0) putchar('-'), x = -x;
	if(x >= 10) put(x / 10);
	putchar(x % 10 + '0');
}

int a[N]; LL f[N][N];

int main() {
	int n = read(), A = read(), B = read();
	for(int i = 1; i <= n; i++) a[i] = read();
	memset(f, 63, sizeof(f)); f[0][0] = 0;
	for(int i = 1; i <= n; i++) {
		for(int j = 0; j <= n; j++) {
			if(a[i] > j) {
				f[i][j] = _min(f[i][j], f[i - 1][j] + A);
				f[i][a[i]] = _min(f[i][a[i]], f[i - 1][j]);
			} else f[i][j] = _min(f[i][a[i]], f[i - 1][j] + B);
		}
	} LL ans = f[0][1];
	for(int i = 0; i <= n; i++) ans = _min(ans, f[n][i]);
	printf("%lld\n", ans);
	return 0;
}



Measured memory_bytes: 195712
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using Map = map<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
ll INF=1LL<<60;
ll MOD=998244353;

int main(){
    ll A;
    cin >> A;
    ll B;
    cin >> B;
    ll C;
    cin >> C;
    ll D;
    cin >> D;
    ll E;
    cin >> E;
    ll F;
    cin >> F;

    double Max=0;
    ll ans1=INF,ans2=INF;

    for(ll x=0;x<=30;x++){
        for(ll y=30;y>=0&&x+y>0;y--){
            for(ll z=0;z<=1500;z++){
                if(E*(A*x+B*y)-C*z>=0&&F-C*z-100*(A*x+B*y)>=0){
                ll w=min((E*(A*x+B*y)-C*z)/D,(F-C*z-100*(A*x+B*y))/D);
                if(Max<=(double)(C*z+D*w)/(A*x+B*y)){
                    Max=(double)(C*z+D*w)/(A*x+B*y);
                    ans1=100*(A*x+B*y)+C*z+D*w;
                    ans2=C*z+D*w;
                }
                }
            ;}
        ;}
    ;}
    cout<<ans1<<" "<<ans2<<endl;
    return 0;
}


Measured memory_bytes: 256
N = int(input())
S=[]
for i in range(N):
    s =list(input())
    S.append(s)
num=0
for a in range(N):
    t =1
    #flag = True
    for i in range(N):
        #if not flag:
           # break
        for j in range(N):
            if i==j:
                continue
            #x = (i+a)%N
            #y=j
            if S[(j+a)%N][i]!=S[(i+a)%N][j]:
                t=0
                #flag=False
                #break
    if t:
        num+=1
print(N*num)



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

int N, A[3000];

int64_t dp[3001][3001][2];
const int64_t INF = 1e18;

int64_t rec(int i, int j, int k){
    if(i > j) return 0;
    if(dp[i][j][k] != INF) return dp[i][j][k];

    int64_t result;
    if(k == 0){
        result = max(rec(i+1, j, 1-k) + A[i], rec(i, j-1, 1-k) + A[j]);
    }else{
        result = min(rec(i+1, j, 1-k) - A[i], rec(i, j-1, 1-k) - A[j]);
    }
    dp[i][j][k] = result;
    return result;
}

int main(){
    cin >> N;
    for(int i=0; i<N; i++) cin >> A[i];
    for(int i=0; i<=3000; i++) for(int j=0; j<=3000; j++) for(int k=0; k<2; k++) dp[i][j][k] = INF;
    cout << rec(0, N-1, 0) << endl;
    return 0;
}

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

#define rep(i,s,n) for (int i = (int)s; i < (int)n; i++)
#define ll long long

int main() {
  int N, L;
  cin >> N >> L;
  vector<int> ord(N);
  iota(ord.begin(), ord.end(), 0);
  vector<int> apple(N);
  vector<int> absapple(N);
  rep(i, 0, N) {
    apple[i] = L + i;
    absapple[i] = abs(L + i);
  }
  sort(ord.begin(), ord.end(), [&](int a, int b) {
    return absapple[a] < absapple[b];
  });

  int ans = 0;
  rep(i, 1, N) {
    ans += apple[ord[i]];
  }
  cout << ans << endl;
};


Measured memory_bytes: 256
import numpy as np
n,k = map(int,input().split())
h = list(map(int,input().split()))

h = np.array(h)

dp = [0 for i in range(n)]

dp = np.array(dp)

for i in range(1,n):
    s = max(0,i-k)
    dp[i] = np.min(dp[s:i] + abs(h[s:i] - h[i]))

print(dp[-1])

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

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef tuple<ll, ll, ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define REP(i,n) for (ll i = 0; i < n; ++i)
#define REPR(i,n) for (ll i = n-1; i >= 0; --i)
#define FOR(i,m,n) for (ll i = m; i < n; ++i)
#define FORR(i,m,n) for (ll i = n-1; i >= m; --i)
#define FORE(x,xs) for (const auto& x : xs)
#define ALL(v) v.begin(), v.end()

const int MOD = 1000000007;
const int MAX = 2e5+10;

ll pow_(ll n, ll k) {
    ll res = 1;
    while (k) {
        if (k&1) res = (res * n) % MOD;
        n = n * n % MOD;
        k >>= 1;
    }
    return res;
}

ll inv(ll n) {
    return pow_(n, MOD-2);
}

ll nCk (int n, int k) {
    ll res = 1;
    REP (i, k) res = res * (n-i) % MOD;
    FOR (i, 1, k+1) res = res * inv(i) % MOD;
    return res;
}

int N, A, B;

ll solve() {
    ll all = pow_(2, N) + MOD - 1;
    all += MOD - nCk(N, A);
    all += MOD - nCk(N, B);
    return all % MOD;
}

int main() {
    cin >> N >> A >> B;
    cout << solve() << endl;
}

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

using namespace std;

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

  cout << (long long)n*(n-1)/2 << endl;
}

/*
1 2 3 4 5 6 7 8 9 10 11 12 13
*/

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Q2
{
    class Program
    {
        static void Main(string[] args)
        {
            string line = Console.ReadLine();
            string[] strs = line.Split(' ');

            int N = int.Parse(strs[0]);
            int X = int.Parse(strs[1]);

            line = Console.ReadLine();
            strs = line.Split(' ');
            int sum = 0;
            int count = 1;
            for(int i = 0; i < N; i++)
            {
                sum += int.Parse(strs[i]);
                if (sum <= X) count++;
            }
            Console.WriteLine(count);
        }
    }
}


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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vii; //2次元配列
typedef vector<ll> vll;
typedef vector<string> vs;

struct point{
    ll x, y;
};

/*FUNCs=================================================*/



/*MAIN==================================================*/
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化

    int a, b, c, count; cin >> a>> b >> c;
    while(count <= c && b >= a){
        count++;
        b -= a;
    }
    if(count > c) count = c;
    cout << count <<'\n';
}


Measured memory_bytes: 256
x1, y1, x2, y2 = map(int, input().split())
dx, dy = x2 - x1, y2 - y1

dx, dy = -dy, dx
x3, y3 = x2 + dx, y2 + dy
dx, dy = -dy, dx
x4, y4 = x3 + dx, y3 + dy

print(x3, y3, x4, y4)

Measured memory_bytes: 3060
from itertools import accumulate

n, m = map(int, input().split())
a = list(map(int, input().split()))

a.sort(reverse=True)
a_acm = list(accumulate(a))

a_cnt = [0] * (10 ** 6 + 1)
for e in a:
    a_cnt[e] += 1

acm = list(accumulate(a_cnt))


def count_handshake(x):
    ret = 0
    for e in a:
        if x - e - 1 >= 0:
            cnt = acm[-1] - acm[x-e-1]
        else:
            cnt = n

        ret += cnt

    return ret


left = 0
right = 10 ** 6

while right - left > 1:
    mid = (left + right) // 2
    if count_handshake(mid) >= m:
        left = mid
    else:
        right = mid

ans = 0
handshake_cnt = 0
for e in a:
    if left - e - 1 >= 0:
        cnt = n - acm[left-e-1]
    else:
        cnt = n

    if cnt > 0:
        ans += e * cnt + a_acm[cnt-1]
        handshake_cnt += cnt

if handshake_cnt > m:
    ans -= left * (handshake_cnt - m)

print(ans)


Measured memory_bytes: 60580
#include<bits/stdc++.h>
#define ii pair<int,int>
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define INF 100000000000000000
#define int long long int
#define modulo 1000000007
using namespace std;

int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    vector<int> arr;
    for(int i=0;i<n;i++){
        int x;
        cin>>x;
        arr.pb(x);
    }
    int ans=0;
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            ans+=arr[i]*arr[j];
        }
    }
    cout<<ans;
}


Measured memory_bytes: 256
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_nl = lambda: list(map(int, readline().split()))
in_na = lambda: map(int, read().split())
in_s = lambda: readline().rstrip().decode('utf-8')


def comb(n, k):

    k = min(k, n - k)

    m = 1
    for i in range(n, n - k, -1):
        m *= i

    n = 1
    for i in range(1, k + 1):
        n *= i

    return m // n


def main():
    N, P = in_nn()
    A = in_nl()

    odd = 0
    even = 0
    for a in A:
        if a % 2 == 0:
            odd += 1
        else:
            even += 1

    #print(odd, even)

    ans = 0
    if P == 0:
        for k in range(0, even + 1, 2):
            ans += comb(even, k) * 2**odd
    else:
        for k in range(1, even + 1, 2):
            ans += comb(even, k) * 2**odd

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9104
#include<bits/stdc++.h>
using namespace std;
int main(){
 
  int k;
  cin>>k;
  string s;
  cin>>s;
  string ans="";
  string f="...";
  if(s.size()<=k)
    cout<<s.substr(0,k);
  else
  {
    cout<<s.substr(0,k);
    cout<<f;
  }
}


Measured memory_bytes: 3628
#include <stdio.h>
#include <math.h>
#include <stdlib.h>

int main(void){
	int i,n,a,b,c;
	
	if(scanf("%d%d", &a, &b)<2){
		fprintf(stderr, "error: ill-formed fraction.\n");
		exit(1);
	}
	
	if(b%a==0){
		c = a + b;
		printf("%d", c);
	}else{
		c = b - a;
		printf("%d", c);

	}

	return 0;

}

Measured memory_bytes: 128
N=int(input())
a=list(map(int,input().split()))

S=[0]
s = 0
for i in range(N):
    s+=a[i]
    S.append(s)
ans=10**28
for i in range(1,N):
    ans=min(abs(S[N]-2*S[i]),ans)
print(ans)

Measured memory_bytes: 24832
#include <iostream>
#include <string>
using namespace std;
int main() {
	string S;
	int ans = 0;

	cin >> S;

	for (int i = 0; i < (int)S.size(); i++)
	{
		if (S[i] == '+')
			ans++;
		if (S[i] == '-')
			ans--;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
use std::io::Read;
use std::collections::VecDeque;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let n: usize = iterator.next().unwrap().parse().unwrap();
    let m: usize = iterator.next().unwrap().parse().unwrap();

    let mut graph: Vec<Vec<usize>> = vec![Vec::new(); n];
    for _ in 0..m {
        let a: usize = iterator.next().unwrap().parse().unwrap();
        let b: usize = iterator.next().unwrap().parse().unwrap();
        graph[a - 1].push(b - 1);
        graph[b - 1].push(a - 1);
    }

    const INF: usize = std::usize::MAX;

    let mut from: Vec<usize> = vec![INF; n];
    from[0] = 0;

    let mut q: VecDeque<usize> = VecDeque::new();
    q.push_back(0);
    while !q.is_empty() {
        let u: usize = q.pop_front().unwrap();
        for &v in graph[u].iter() {
            if from[v] == INF {
                from[v] = u;
                q.push_back(v);
            }
        }
    }

    let mut result = String::from("Yes\n");
    for i in 1..n {
        result.push_str(&format!("{}\n", from[i] + 1));
    }
    return result.trim().to_string();
}


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

int a[100001];
vector<int> f[100001];
vector<int> b[100001];

void dfs(int start, int group) {
  if (a[start] >= 0) return;
  a[start] = group;
  for (auto friendId: f[start]) {
    dfs(friendId, group);
  }
}

void Main() {
  int n, m, k;
  cin >> n >> m >> k;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    f[a].push_back(b);
    f[b].push_back(a);
  }
  for (int i = 0; i < k; i++) {
    int c, d;
    cin >> c >> d;
    b[c].push_back(d);
    b[d].push_back(c);
  }

  memset(a, -1, sizeof(a));
  int group = 0;
  for (int i = 1; i <= n; i++) {
    dfs(i, group);
    group++;
  }

  /*
  for (int i = 1; i <= n; i++) {
    cout << a[i] << endl;
  }
  return;
  */

  int groupNum[n];
  memset(groupNum, 0, sizeof(groupNum));
  for (int i = 1; i <= n; i++) {
    groupNum[a[i]]++;
  }
  /*
  cout << groupNum[0] << endl;
  return;
  */
  for (int i = 1; i <= n; i++) {
    int groupId = a[i];
    int ans = groupNum[groupId] - 1;
    /*
    cout << "########" << endl;
    cout << groupId << endl;
    cout << ans << endl;
    */
    for (auto fId: f[i]) {
      /*
      cout << "fId = " << fId << endl;
      */
      if (a[fId] == groupId) ans--;
    }
    for (auto bId: b[i]) {
      /*
      cout << "bId = " << bId << endl;
      */
      if (a[bId] == groupId) ans--;
    }
    cout << ans << endl;
  }
}

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


Measured memory_bytes: 12664
import java.util.Scanner;

//On or Off
public class Main{

	int h, w, M, INF = 1<<29;
	int[][] cost, on, off, nh, nw, v, dp;
	char[][] map;
	int[][] move = {{-1,0},{0,1},{1,0},{0,-1}};
	boolean[][] u;
	
	boolean dfs(int i, int j, int ti, int tj){
		if(i==ti&&j==tj)return true;
		u[i][j] = true;
		for(int k=0;k<4;k++){
			int ni = i+move[k][0], nj = j+move[k][1];
			if(0<=ni&&ni<h&&0<=nj&&nj<w&&!u[ni][nj]&&map[ni][nj]=='.'){
				if(dfs(ni, nj, ti, tj)){
					nh[i][j] = ni; nw[i][j] = nj; return true;
				}
			}
		}
		nh[i][j] = nw[i][j] = -1;
		return false;
	}
	
	void run(){
		Scanner sc = new Scanner(System.in);
		h = sc.nextInt(); w = sc.nextInt(); M = sc.nextInt();
		cost = new int[h][w];
		on = new int[h][w]; off = new int[h][w];
		nh = new int[h][w]; nw = new int[h][w];
		map = new char[h][w];
		for(int i=0;i<h;i++)map[i]=sc.next().toCharArray();
		v = new int[h][w];
		for(int i=0;i<h;i++)for(int j=0;j<w;j++)v[i][j] = -1;
		for(int i=0;i<h;i++)for(int j=0;j<w;j++)cost[i][j]=sc.nextInt();
		for(int i=0;i<h;i++)for(int j=0;j<w;j++)on[i][j]=sc.nextInt();
		for(int i=0;i<h;i++)for(int j=0;j<w;j++)off[i][j]=sc.nextInt();
		int t = 0, pi = sc.nextInt(), pj = sc.nextInt();
		dp = new int[h][w];
		v[pi][pj] = 0;
		dp[pi][pj] = on[pi][pj];
		while(--M!=0){
			int ti = sc.nextInt(), tj = sc.nextInt();
			u = new boolean[h][w];
			dfs(pi, pj, ti, tj);
			for(;;){
				int ni = nh[pi][pj], nj = nw[pi][pj];
				t++;
				if(v[ni][nj]==-1)dp[ni][nj] = on[ni][nj];
				else{
					dp[ni][nj] = Math.min(dp[ni][nj]+off[ni][nj]+on[ni][nj], dp[ni][nj]+(t-v[ni][nj])*cost[ni][nj]);
				}
				v[ni][nj] = t;
				pi = ni; pj = nj;
				if(pi==ti&&pj==tj)break;
			}
		}
		int res = 0;
		for(int i=0;i<h;i++)for(int j=0;j<w;j++)if(v[i][j]!=-1)res+=dp[i][j]+off[i][j];
		System.out.println(res);
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 13000
def main():
    h, n = map(int, input().split())
    INF = 10 ** 9
    dp = [INF for _ in range(2*10**4)]
    AB = [tuple(map(int, input().split())) for _ in range(n)]
    dp[0] = 0
    for a, b in AB:
        for i in range(h):
            dp[i + a] = min(dp[i + a], dp[i] + b)
    print(min(dp[h:]))
if __name__ == "__main__":
    main()

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

int main(){
    int r,c;
    cin >> r >> c;
    int cell[r+1][c+1] = {};
    for(int i=0;i<r;++i){
        for(int j=0;j<c;++j){
            int tmp;
            cin >> tmp;
            cell[i][j] = tmp;
            cell[i][c] += tmp;
            cell[r][j] += tmp;
            cell[r][c] += tmp;
        }
    }

    for(int i=0;i<=r;++i){
        for(int j=0;j<=c;++j){
            cout << cell[i][j];
            if(j != c) cout << " ";
        }
        cout << endl;
    }
    return 0;
}



Measured memory_bytes: 3092
#include <bits/stdc++.h>
using namespace std;
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; }
using ll = long long;
using P = pair<ll, ll>;
const long double PI = acos(-1.0L);
ll GCD(ll a, ll b) { return b?GCD(b, a%b):a; }
ll LCM(ll a, ll b) { return a/GCD(a, b)*b; }


int main() {
    int n, m; cin >> n >> m;
    int Ea = (1<<m);
    int Eb = 0;
    long double time = 100.0*(long double)n + 1800.0*(long double)m;
    cout << setprecision(14) << time*(long double)(Ea+Eb) << endl;
}

Measured memory_bytes: 3792
#include <bits/stdc++.h>
#define fi first
using namespace std;
#define se second
long long n,m, ans,kcl;
pair<long long , long long > arr[100005];
int main(){
	cin>>n>>m;
	kcl = 1e9;
	for(int i =1;i<=m;i++){
		cin>>arr[i].fi>>arr[i].se;
		kcl = min(kcl,arr[i].se);
	}
	sort(arr+1,arr+m+1);
	for(int i = kcl;i>=1;i--){
		if(arr[m].fi<=i)ans++;
		else break;
	}
	cout<<ans<<endl;

}

Measured memory_bytes: 1792
#include <stdio.h>
 
#define MAX 2000001
 
void insert(int);
void heapIncreaseKey(int, int);
int extract(void);
void maxHeapify(int);
 
int H=0, A[MAX];
 
int main()
{
  int key, Out[MAX], i, j;
  char input[10];
 
  while( 1 ){
    scanf("%s", input);
    if( input[0] == 'e' && input[1] == 'n' ) break;
    if( input[0] == 'i' ){
      scanf("%d", &key);
      insert(key);
    }
    else {
      Out[j] = extract();
      j++;
    }
  }
 
  for( i = 0 ; i < j ; i++ ) printf("%d\n", Out[i]);
   
  return 0;
}
 
void insert(int key)
{
  H++;
  A[H] = -1000000000;
  heapIncreaseKey(H, key);
}
 
void heapIncreaseKey(int i, int key)
{
  int tmp;
   
  if( key < A[i] ) return;
  A[i] = key;
  while( i > 1 && A[i/2] < A[i] ){
    tmp = A[i];
    A[i] = A[i/2];
    A[i/2] = tmp;
    i = i / 2;
  }
}
 
int extract()
{
  int max;
 
  if( H < 1 ) return -1000000000;
  max = A[1];
  A[1] = A[H--];
  maxHeapify(1);
  return max;
}
 
void maxHeapify(int i)
{
  int l, r, largest, tmp;
   
  l = 2 * i;
  r = 2 * i + 1;
   
  if( l <= H && A[l] > A[i] ) largest = l;
  else largest = i;
  if( r <= H && A[r] > A[largest] ) largest = r;
   
  if( largest != i ){
    tmp = A[i];
    A[i] = A[largest];
    A[largest] = tmp;
    maxHeapify(largest);
  }
}

Measured memory_bytes: 8072
#include <bits/stdc++.h>
#define FOR(I,X,Y) for(int I=X;I<Y;I++)
#define REP(I,X,Y) for(int I=Y-1;I>=X;I--)
#define INF 1000000007
using namespace std;

bool can1[200010],canN[200010];

int main(){
  int N,M,a,b;
  cin >> N >> M;
  FOR(i,0,M){
    cin >> a >> b;
    if(a == 1)can1[b] = 1;
    if(b == N)canN[a] = 1;
  }
  FOR(i,2,N){
    if(can1[i] && canN[i]){
      cout << "POSSIBLE" << endl;
      return 0;
    }
  }
  cout << "IMPOSSIBLE" << endl;
}


Measured memory_bytes: 640
import java.awt.*;
import java.awt.geom.*;
import java.io.*;

import java.util.*;
class Main {

	static char[] xx = new char[] {'S','H','C','D'};
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		boolean[][] l = new boolean[4][13];
		for(int i = 0; i < n; i++) {
			char k = sc.next().charAt(0);
			int r = sc.nextInt();
			if(k == 'S') {
				l[0][r-1] = true;
			}
			if(k == 'H') {
				l[1][r-1] = true;
			}
			if(k == 'C') {
				l[2][r-1] = true;
			}
			if(k == 'D') {
				l[3][r-1] = true;
			}
		}
		for(int i = 0 ; i< 4; i++) {
			for(int j = 0; j < 13; j++) {
				if(!l[i][j]) {
					System.out.println(xx[i] + " " + (j+1));
				}
			}
		}
	}
}



Measured memory_bytes: 26272
import sys
input = sys.stdin.readline

N = int(input())
ABs = []
for _ in range(N):
    A, B = map(int, input().split())
    ABs.append((B, A))

ABs.sort()

t = 0
for tTo, tm in ABs:
    t += tm
    if tTo < t:
        print('No')
        break
else:
    print('Yes')


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

#define ll long long

int main()
{
	ll n;
	cin >> n;
	ll all = n*(n+1)/2;
	ll three = (n/3)*(3+n-n%3)/2;
	ll five = (n/5)*(5+n-n%5)/2;
	ll fif = (n/15)*(15+n-n%15)/2;
	cout << all-(three+five)+fif << '\n';
}

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

# define line cout << "\n" ;

int main()
{
  	ios_base :: sync_with_stdio ( false ) ; cin.tie ( 0 ) ; cout.tie ( 0 ) ; 
  
    int n , W ;
    cin >> n >> W ;

    const int N = 1e5 + 10 ;

    vector < long long > dp ( N , -1e11 - 100 ) ;
    dp[0] = 0 ;

    for ( int i=0 ; i < n ; i ++ )
    {
        int w , val ;
        cin >> w >> val ;

        for ( int j = N - 1 ; j > -1 ; j -- )
        {
            int indx = j + w ;
            if ( indx >= N ) continue ;

            dp[indx] = max ( dp[indx] , dp[j] + val ) ;
        }
    }

    long long ans = 0 ;
    for ( int i=0 ; i <= W ; i ++ )
        ans = max ( ans , dp[i] ) ;

    cout << ans << "\n" ;
    return 0 ;

}


Measured memory_bytes: 1024
s = input()
t = input()
n = len(s)
m = len(t)
dp = [[0]*(m+1) for _ in range(n+1)]
for i in range(n):
  for j in range(m):
    if s[i] == t[j]:
      dp[i+1][j+1] = dp[i][j] + 1
    else:
      dp[i+1][j+1] = max(dp[i][j+1],dp[i+1][j])
i,j = n,m
ans = ""
while i and j:
  if dp[i][j] == dp[i-1][j]:
    i -= 1
  elif dp[i][j] == dp[i][j-1]:
    j -= 1
  else:
    i -= 1
    j -= 1
    ans += s[i]
print(ans[::-1])

Measured memory_bytes: 112220
#include <stdio.h>
int member[10000];
unsigned int money[4000];
int in(int n, int c) {
	int i;
	for(i = 0; i < c; ++ i) if(member[i] == n) return 1;
	return 0;
}
int main() {
	while(1) {
		int N;
		scanf("%d", &N);
		if(N == 0) break;
		int i, num;
		num = 0;
		for(i = 0; i < N; ++ i) {
			int n, k;
			unsigned int a, b;
			scanf("%d %u %u", &n, &a, &b);
			if(in(n, num)) {
				money[n] += a * b;
			} else {
				member[num++] = n;
				money[n] = a * b;
			}
		}
		int count = 0;
		for(i = 0; i < num; ++ i) {
			if(money[member[i]] >= 1000000) {
				printf("%d\n", member[i]);
				count ++;
			}
		}
		if(count == 0) printf("NA\n");
	}
	return 0;
}

Measured memory_bytes: 636
#include <stdio.h>

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

char grid[8][9];

void dfs(int x, int y)
{
	int dir;
	int len;
	
	if (x < 0 || 8 <= x) return;
	if (y < 0 || 8 <= y) return;
	if (grid[y][x] == '0') return;
	
	grid[y][x] = '0';
	
	for (dir = 0; dir < 4; dir++){
		for (len = 1; len <= 3; len++){
			dfs(x + dx[dir] * len, y + dy[dir] * len);
		}
	}
}

int main(void)
{
	int n;
	int x, y;
	int data_i;
	int i, j;
	
	scanf("%d", &n);
	for (data_i = 0; data_i < n; data_i++){
		for (i = 0; i < 8; i++){
			scanf("%s", grid[i]);
		}
		
		scanf("%d %d", &x, &y);
		dfs(x - 1, y - 1);
		
		printf("Data %d:\n", data_i + 1);
		for (i = 0; i < 8; i++){
			printf("%s\n", grid[i]);
		}
	}
	
	return (0);
}

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

int n;
int a[100005];

int main()
{
    while(cin >> n)
    {
        for(int i = 1; i <= n; ++i)
            cin >> a[i];
        int sum = 0;
        for(int i = 1; i < n; ++i)
        {
            if(a[i] == i)
            {
                swap(a[i], a[i + 1]);
                sum++;
            }
        }
        if(a[n] == n) sum++;
        cout << sum << endl;
    }
}


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

#define rep(i,a,n) for(int i=a; i<n; i++)
#define repr(i,a,n) for(int i=a;i >= n;i--)
#define INF 999999999
#define pb(a) push_back(a)

int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
using namespace std;

typedef pair<int, int> pii;
typedef long long int ll;
typedef vector<pii> VP;

int n, k;
int c[11];
int d[10];
vector<int> e;

int main(void) {
    cin >> n >> k;
    int m = n;
    rep(i,0,k) cin >> d[i];

    rep(i,0,10) {
        bool a = true;
        rep(j,0,k) {
            if(d[j] == i) a = false;
        }
        if(a) e.pb(i);
    }

    //rep(i,0,e.size()) cout << e[i] << endl;

    int ret = 0;
    int digit = 0;
    while(m != 0) {
        c[digit] = m % 10;
        digit++;
        m /= 10;
    }
    c[digit] = 0;

    rep(i,0,digit+1) {
        if(ret >= n) continue;
        bool a = true;
        rep(j,0,e.size()) {
            if(e[j] >= c[i]) {
                a = false;
                ret += e[j] * (int)pow(10,i);
                break;
            }
        }
        if(a) {
            ret += e[0] * (int)pow(10,i);
            c[i+1]++;
        }
    }
    if(c[digit-1] < (ret / (int)pow(10,digit-1)) % (int)pow(10,digit)) {
        ret = (ret / (int)pow(10,digit-1)) % (int)pow(10,digit) * pow(10,digit-1);
        rep(i,0,digit-1) ret += e[0] * (int)pow(10,i);
    }
    cout << ret << endl;
    return 0;
}

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

int main(void) {

	// TODO: submit前にprintf-debugの削除確認！
	int N, T, A;
	cin >> N;
	cin >> T >> A;

	int H[N];
	int ans = 0;
	for(int i=0; i<N; i++) {
		int h;
		cin >> h;
		H[i] = h;
		
		double t = (double)T - h*0.006;
		double ansT = (double)T - H[ans]*0.006;
		if(abs(A-t) < abs(A-ansT))
			ans = i;
	}
	
	cout << ans+1;

	return 0;
}



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

int main()
{
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);
  
  constexpr int64_t mod=1e9+7;
  
  int N;
  std::cin>>N;
  
  std::vector<int64_t> A(N);
  for(int i=0;i!=N;i++)
  {
    std::cin>>A[i];
  }
  
  int64_t sum=0;
  for(int i=0;i!=N;i++)
  {
    sum=(sum+A[i])%mod;
  }
  
  int64_t result=0;
  for(int i=0;i!=N;i++)
  {
    sum-=A[i];
    if(sum<0)sum+=mod;
    result=(result+(A[i]*sum)%mod)%mod;
  }
  
  std::cout<<result<<std::endl;
  
  return 0;
}

Measured memory_bytes: 4756
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		int a = in.nextInt();
		int b = in.nextInt();
		int c = in.nextInt();
		int d = in.nextInt();
		int e = in.nextInt();
		int k = in.nextInt();
		System.out.println(solve(a, e, k));
		in.close();
	}

	private static String solve(int a, int e, int k) {
		if (e - a > k)
			return ":(";
		else
			return "Yay!";
	}

}

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

int a[101],b[101];
int main()
{
    int n; cin>>n;
    for(int i=0;i<n-1;i++) cin>>b[i];

    a[0]=b[0];
    for(int i=1;i<n-1;i++)
    {
        if(b[i]<b[i-1]) a[i]=b[i];
        else a[i]=b[i-1];
    }
    a[n-1]=b[n-2];

    int sum=0;
    for(int i=0;i<n;i++) sum+=a[i];
    cout<<sum;
}


Measured memory_bytes: 256
h,w=map(int,input().split())
s=[]
import heapq
INF=10**9
def Dijkstra(graph, start):
  dist=[INF]*len(graph)
  parent=[INF]*len(graph)
  queue=[(0, start)]
  while queue:
    path_len, v=heapq.heappop(queue)
    if dist[v]==INF: 
      dist[v]=path_len
      for w in graph[v]:
        if dist[w[0]]==INF:
          parent[w[0]]=v
          heapq.heappush(queue, (dist[v]+w[1], w[0]))         
  return (dist,parent)
for i in range(h):
  a=input()
  s.append(a)
graph=[]
ans=0
for i in range(h):
  for j in range(w):
    graph.append([])
for i in range(h):
  for j in range(w):
    if s[i][j]=='.':
      if i>0 and s[i-1][j]=='.':
        graph[i*w+j].append([(i-1)*w+j,1])
      if i<h-1 and s[i+1][j]=='.':
        graph[i*w+j].append([(i+1)*w+j,1])
      if j>0 and s[i][j-1]=='.':
        graph[i*w+j].append([i*w+j-1,1])
      if j<w-1 and s[i][j+1]=='.':
        graph[i*w+j].append([i*w+j+1,1])
for i in range(h):
  for j in range(w):
    if s[i][j]=='.':
      a,b=Dijkstra(graph,i*w+j)
      for k in range(h):
        for l in range(w):
          if a[k*w+l]!=INF:
            ans=max(ans,a[k*w+l])
print(ans)

Measured memory_bytes: 76080
#include<bits/stdc++.h>
using namespace std;
int N,M,a,b;
int G[500][500];
int from[3000],to[3000];
bool visited[500];

bool dfs(int pos,int ti){
  if(pos==ti)return true;
  visited[pos]=true;
  for(int i=1;i<=N;i++){
    if(visited[i])continue;
    if(G[pos][i]==0)continue;
    if(dfs(i,ti)){
      G[pos][i]--;
      G[i][pos]++;
      return true;
    }
  }
  return false;
}

int max_flow(int si,int ti){
  int res=0;
  while(1){
    for(int i=1;i<=N;i++)visited[i]=false;
    if(dfs(si,ti))res++;
    else break;
  }
  return res;
}

int main(){
  cin>>N>>M;
  for(int i=1;i<=M;i++){
    cin>>a>>b;
    G[a][b]++;
    G[b][a]++;
    from[i]=a;
    to[i]=b;
  }
  cin>>a>>b;
  cout<<max_flow(a,b)<<endl;
  vector<int> ans;
  for(int i=1;i<=M;i++){
    a=from[i],b=to[i];
    if(G[b][a]==0)ans.push_back(i);
  }
  cout<<ans.size()<<endl;
  for(int i=0;i<(int)ans.size();i++)cout<<ans[i]<<endl;
  return 0;
}

Measured memory_bytes: 1832
#include<stdio.h>

void bubbleSort(int dt[],int n)
{
    int i,j,temp;

    for(i=0;i<n-1;i++){
        for(j=n-1;j>i;j--){
            if(dt[j-1]>dt[j]){
               
                temp=dt[j];
                dt[j]=dt[j-1];
                dt[j-1]=temp;
                
            }
        }
   
    }
}



int main(){

int h;
int m;


int a[200];


int an,bn;

int i;



scanf("%d",&an);

for(i=0;i<an;i++){
scanf("%d",&h);
scanf("%d",&m);
a[i]=h*60+m;
	}

scanf("%d",&bn);

for(i=an;i<an+bn;i++){
scanf("%d",&h);
scanf("%d",&m);
a[i]=h*60+m;
	}

bubbleSort(a,an+bn);

printf("%d:%02d",(a[0]-(a[0]%60))/60,a[0]%60);

for(i=1;i<an+bn;i++){
	if(a[i-1]!=a[i]){
printf(" %d:%02d",(a[i]-(a[i]%60))/60,a[i]%60);
}
	}
	

printf("\n");


return 0;
	}

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

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<=(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define Eback(s) s.erase(s.end()-1,s.end())
#define rev(v) reverse(all(v))
#define minvec(v) *min_element(all(v))
#define maxvec(v) *max_element(all(v))
#define sumvec(v) accumulate(all(v),0LL)
#define mapmin(v) v.rbegin()->first
#define mapmax(v) v.begin()->first
#define pb push_back
#define pf push_front
#define m_p make_pair
#define DOUBLE fixed << setprecision(15)
#define OK cerr<<"OK\n"
#define OK1 cerr<<"OK1\n"
#define OK2 cerr<<"OK2\n"
#define SIZE(s) (int)s.size()
#define INF ((1LL<<62)-(1LL<<31))
#define zero(x,n) setw(x) << setfill('0') << n

typedef long long ll;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long long> vll;
typedef vector<vll> vvll;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<string> vs;

typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
typedef vector<pair<ll,ll>> vpll;

const double pi = acos(-1.0);
const int mod=1000000007;
const int mod2=998244353;

template<class A, class B>
ostream& operator<<(ostream& ost, const pair<A, B>&p) {
	ost << "{" << p.first << ", " << p.second << "} ";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost, const vector<T>&v) {
	ost << "{";
	for (int i = 0; i<(int)v.size(); i++) {
		if (i)ost << " ";
		ost << v[i];
	}
	ost << "} \n";
	return ost;
}

template<class A, class B>
ostream& operator<<(ostream& ost, const map<A, B>&v) {
	ost << "{";
	for (auto p:v) {
		ost << "{" << p.first << ", " << p.second << "} ";
	}
	ost << "} ";
	return ost;
}

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

void YES(bool b) {cout << ((b)?"YES\n":"NO\n");}
void Yes(bool b) {cout << ((b)?"Yes\n":"No\n");}
void yes(bool b) {cout << ((b)?"yes\n":"no\n");}
void Yay(bool b) {cout << ((b)?"Yay!\n":":(\n");}

ll powmod(ll a,ll b){ll c=1; while(b>0){ if(b&1){ c=a*c%mod; } a=a*a%mod; b>>=1; } return c;}
ll gcd(ll x, ll y) {return __gcd(x,y);}
ll lcm(ll x, ll y) {return x/__gcd(x,y)*y;}

int main()
{
	ll n,ans=0;
	cin >> n;
	vll a(n);
	rep(i,n) cin >> a[i];
	rep(i,n){
		ans+=a[i]/2;
		a[i]%=2;
		if(a[i] && a[i+1]>0 && i!=n-1){
			ans++;
			a[i+1]--;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>
int main()
{
	char s[5];
	int i,p=0;
	for ( i = 0; i <4; i++)
	{
		scanf("%c",&s[i]);
		if(s[i]=='+')p++;
		if(s[i]=='-')p--;
	}
	printf("%d\n",p);
	return 0;
}

Measured memory_bytes: 128