akhauriyash/Code-Regression huggingface dataset:
N,K=map(int,input().split())

def genCombinationFunction(max_k,mod):
    modinv_table = [-1] * (max_k+1)
    modinv_table[1] = 1
    for i in range(2, max_k+1):
        modinv_table[i] = (-modinv_table[mod % i] * (mod // i)) % mod

    def binomial_coefficients(n, k):
        ans = 1
        for i in range(k):
            ans *= n-i
            ans *= modinv_table[i + 1]
            ans %= mod
        return ans
    return binomial_coefficients

mod=10**9+7
k=2000
f=genCombinationFunction(k,mod)
for i in range(1,K+1):
  redballs=N-K
  position=redballs+1

  order=f(position,i)
  order*=f(K-1,i-1)
  print(order%mod)
  

Measured memory_bytes: 9132
char s[2];m[21][21];main(n,x,y,c){for(;scanf("%d",&n),n;){for(memset(m,0,sizeof(m));n--;m[x][y]=1)scanf("%d%d",&x,&y);for(scanf("%d",&n),x=y=10;n--;)for(scanf("%s%d",s,&c),m[x][y]=0;c--;m[x][y]=0)*s=='W'?x--:*s=='E'?x++:*s=='S'?y--:y++;for(x=0;x<21;x++)for(y=0;y<21;y++)if(m[x][y])goto z;
z:puts(x==21?"Yes":"No");}exit(0);}

Measured memory_bytes: 584
import Control.Applicative
import Control.Monad
import Control.Monad.ST
import Data.Functor
import Data.Function
import Data.Monoid
import Data.Maybe
import Data.List
import qualified Data.Foldable as Foldable
import qualified Data.Set as Set
--import qualified Data.Sequence as Sequence
import Data.List.Split
import Data.Bits
import Data.Char
import Data.Ix
import Data.Ratio
import Data.Ord
import Data.Tuple
--import Data.Array
--import Data.Array.Unboxed
import Data.Array.IArray
import Data.Array.MArray
import Data.Array.IO
import Data.Array.ST
import Data.IORef
import Data.STRef
-- import System.IO.Unsafe

-- templete
readInt = read :: String -> Int
readInteger = read :: String -> Integer
readDouble = read :: String -> Double
getInt = readLn :: IO Int
getInts = map readInt . words <$> getLine
getInteger = readLn :: IO Integer
getIntegers = map readInteger . words <$> getLine
getDouble = readLn :: IO Double
sjoin :: (Show a) => [a] -> String
sjoin = unwords . map show
cond :: a -> a -> Bool -> a
cond t f c = if c then t else f
apply2 :: (a -> a -> b) -> [a] -> b
apply2 f [x,y] = f x y
apply3 :: (a -> a -> a -> b) -> [a] -> b
apply3 f [x,y,z] = f x y z
apply4 :: (a -> a -> a -> a -> b) -> [a] -> b
apply4 f [x,y,z,w] = f x y z w
fnTuple :: (a -> b, a -> c) -> a -> (b, c)
fnTuple (f,g) a = (f a, g a)
replace :: (Eq a) => a -> a -> [a] -> [a]
replace x y = map (\z -> if z==x then y else z)
binMap :: (a -> a -> b) -> [a] -> [b]
binMap f (x:xs@(y:_)) = f x y : binMap f xs
binMap _ _ = []
splitRec :: Int -> [a] -> [[a]]
splitRec _ [] = []
splitRec n xs = let (y,ys) = splitAt n xs in y : splitRec n ys
infixl 7 `divCeil`
divCeil :: Integral a => a -> a -> a
x `divCeil` y = (x+y-1) `div` y
-- templete



main = replicateM_ 9 $ do
    [n,a,b] <- words <$> getLine
    let x = readInt a
    let y = readInt b
    putStrLn $ unwords [n, show (x+y), show (200*x+300*y)]
    



Measured memory_bytes: 3784
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,i;
    cin>>a>>b;
    if(a==b){
        for(i=0;i<a;i++)
            cout<<a;
        cout<<endl;
    }
    else if(a>b){
        for(i=0;i<a;i++)
            cout<<b;
        cout<<endl;
    }
    else{
        for(i=0;i<b;i++)
            cout<<a;
        cout<<endl;
    }
}


Measured memory_bytes: 3564
import java.util.Scanner;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int y = sc.nextInt() / 1000;
        for (int i = 0; i <= n; i++) {
            for (int j = 0; i + j <= n; j++) {
                int k = n - i - j;
                int sum = i * 10 + j * 5 + k;
                if (sum == y) {
                    System.out.println(String.format("%d %d %d", i, j, k));
                    return ;
                }
            }
        }
        System.out.println("-1 -1 -1");
    }

}

Measured memory_bytes: 23764
import itertools
n=int(input())
data=[0,0,0,0,0]
for i in range(n):
    s=input()
    if(s[0]=='M'):
        data[0]+=1
    if(s[0]=='A'):
        data[1]+=1
    if(s[0]=='R'):
        data[2]+=1
    if(s[0]=='C'):
        data[3]+=1
    if(s[0]=='H'):
        data[4]+=1
ans=0
for x,y,z in itertools.combinations(range(5),3):
    ans+=data[x]*data[y]*data[z]
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <string>

using namespace std;

int f[1000];

int main(void) {
    int i, j, k;
    int n;
    string s;
    cin >> n;
    cin >> s;

    bool f1[10];
    for(i = 0; i < 10; i++) f1[i] = false;
    int fn1 = 0;
    for(i = 0; i < n - 2; ++i) {
        int d1 = s[i] - '0';
        if(f1[d1])
            continue;
        f1[d1] = true;
        fn1++;

        bool f2[10];
        for(j = 0; j < 10; ++j) f2[j] = false;
        int fn2 = 0;

        for(j = i + 1; j < n - 1; ++j) {
            int d2 = s[j] - '0';
            if(f2[d2])
                continue;
            f2[d2] = true;
            fn2++;

            for(k = j + 1; k < n; ++k) {
                int p = (s[i] - '0') * 100 + (s[j] - '0') * 10 + s[k] - '0';
                f[p] = 1;
            }

            if(fn2 == 10)
                break;
        }

        if(fn1 == 10)
            break;
    }
    int x = 0;
    for(i = 0; i < 1000; ++i) {
        x += f[i];
    }
    cout << x << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def II(): return int(sys.stdin.readline())


from collections import deque

from copy import copy
#debug = True
debug = False

def dprint(*objects):
    if debug == True:
        print(*objects)
def main():
    N = II()
    a_mat = []
    for i in range(N):
        a_mat.append(deque(LI()))

    cnt = 0
    first_list = [a_list.popleft() for a_list in a_mat]
    nend = 0
    previous_match_list = list(range(N))
    while True:
        # この日に試合できる可能性リスト
        # 試合する人リスト
        match_list = []
        for i in previous_match_list:
            a_no = first_list[i]
            a = a_no-1
            no = i+1
            # 試合をするペアの要素を入れていく
            if first_list[a] == no:
                match_list.append(i)

        dprint(first_list, match_list)

        if len(match_list) == 0:
            print(-1)
            return

        previous_match_list = copy(match_list)

        # 試合をしたことを反映
        for i in match_list:
            if len(a_mat[i]) == 0:
                first_list[i] = 0
                nend += 1 # 終わった人
            else:
                next_no = a_mat[i].popleft()
                next = next_no - 1
                first_list[i] = next_no
                previous_match_list.append(next)

        previous_match_list = list(set(previous_match_list))

        dprint(match_list, previous_match_list)
        dprint("")
        # 一日経過
        cnt += 1

        # 終了判定
        if nend == N:
            break


    print(cnt)


main()

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

int int_sort( const void * a , const void * b ) {
  if( *( int * )a < *( int * )b ) {
    return -1;
  }
  else
  if( *( int * )a == *( int * )b ) {
    return 0;
  }
  return 1;
}


int main(){
		int n,k;
		scanf("%d%d",&n,&k);
		int a[n],memo[200000]={0},count=0,i,j,ans=0,mm;
		for(i=0;i<n;i++){
				scanf("%d",&a[i]);
				memo[a[i]-1]++;
		}
		for(i=0;i<n;i++){
				if(memo[i]>0)count++;
		}
		/*for(i=0;i<n;i++){
				int small=memo[i];
				for(j=i;j<n;j++){
						if(small>=memo[j]){
								small=memo[j];
								mm=j;
						if(small==0)break;
						}
				}
				int tmp=memo[i];
				memo[i]=small;
				memo[mm]=tmp;
		}*/
		qsort(memo,200000,sizeof(int),int_sort);
		if(count<=k)puts("0");
		else {i=0;
				while(count>k){
						if(memo[i]!=0){
								ans+=memo[i];
								count--;
						}
						i++;
				}
				printf("%d\n",ans);
		}
		return 0;
}



Measured memory_bytes: 2556
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n",(x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define isYes(x) printf("%s\n",(x) ? "Yes" : "No")
#define isIn(x,y,h,w) (x >= 0 && x < h && y >= 0 && y < w)

#define int long long
//using ll = long long;
using P = pair<int,int>;

ostream &operator<<(ostream &os,const P &p){ return os << "(" << p.first << "," << p.second << ")"; }
template<class T>
ostream &operator<<(ostream &os,const vector<T> &v){
	for(int i = 0;i < v.size();i++) os << (i ? "," : "[") << v[i];
	os << "]";
	return os;
}

template<class T> T &chmin(T &a,const T &b){ return a = min(a,b); }
template<class T> T &chmax(T &a,const T &b){ return a = max(a,b); }

const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;

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

signed main(){
	int n,p = 2019,a[200010],pow10[200010] = {1};
	string s;
	cin >> s;
	n = s.length();
	for(int i = 0;i < n;i++) a[i] = s[i] - '0';
	for(int i = 1;i <= n;i++) pow10[i] = pow10[i - 1] * 10 % p;
	map<int,int> cnt;
	cnt[0]++;
	int ans = 0,sum = 0;
	for(int i = 0;i < n;i++){
		sum = (sum * 10 + a[i]) % p;
		int tmp = sum * pow10[n - i - 1] % p;
		if((p != 2 && p != 5) || a[i] % p == 0) ans += cnt[tmp];
		cnt[tmp]++;
	}
	cout << ans << endl;
}


Measured memory_bytes: 6888
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INFLL LLONG_MAX // 9223372036854775807
#define EPS 1e-9
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
template<class T>bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }
using namespace std;

struct Edge{
    // 始点, 終点, 重み, 最大量
    long long src, dst, weight, capacity;
    Edge(): src(0), dst(0), weight(0), capacity(0) {}
    Edge(long long s, long long d, long long w): src(s), dst(d), weight(w) {}
    Edge(long long s, long long d, long long w, long long c): src(s), dst(d), weight(w), capacity(c) {}
};

class Graph{
public:
    long long size;
    vector<vector<Edge>> node;
    Graph(long long n): size(n), node(n) {}
    // 無向辺の追加
    void addEdge(long long s, long long d, long long w = 1){
        node[s].emplace_back(s, d, w);
        node[d].emplace_back(d, s, w);
    }
    // 有向辺の追加
    void addArc(long long s, long long d, long long w = 1){
        node[s].emplace_back(s, d, w);
    }
    // ノードの追加
    void addNode(){
        size++;
        node.emplace_back();
    }
};

// Dijkstra(Heap); 単一始点最短路（優先度付きキューを利用したダイクストラ法）
// ：負辺がある場合はループにハマる可能性があるため、Bellman-Fordを使うこと。[O((E+V)logV)]
vector<long long> Dijkstra(const Graph &g, long long src){
    const long long WeightINF = numeric_limits<long long>::max()/2-1;
    using state = pair<long long, long long>;
    priority_queue<state> que;
    vector<long long> d(g.size, WeightINF);
    d[src] = 0;
    que.emplace(0, src);
    while(!que.empty()){
        auto p = que.top(); que.pop();
        long long w = -p.first;
        long long v = p.second;
        if(d[v] < w) continue;
        for(auto &edge: g.node[v]){
            if(d[edge.dst] > d[v] + edge.weight){
                d[edge.dst] = d[v] + edge.weight;
                que.emplace(-d[edge.dst], edge.dst);
            }
        }
    }
    return d;
}

int main(){
    Init();
    ll n, u, v;
    cin >> n >> u >> v;
    u--; v--;
    Graph g(n);

    rep(i, n-1){
        ll a, b;
        cin >> a >> b;
        a--; b--;
        g.addEdge(a, b);
    }

    auto dij_u = Dijkstra(g, u);
    auto dij_v = Dijkstra(g, v);

    // 高橋くんが逃げる側、青木くんが追う側
    // 高橋くんは、青木くんと重ならずにいける頂点の中で、
    // 青木くんが最も遠い頂点を目指せば良い
    ll node = 0, dist = 0;
    rep(i, n) if(dij_v[i] > dist && dij_u[i] < dij_v[i]) node = i, dist = dij_v[i];

    cout << dist - 1 << endl;
}

Measured memory_bytes: 16344
k,n = map(int,input().split())
a = list(map(int,input().split()))
a.insert(0,0)
a.append(k)
tosa = []
for i in range(len(a)-1):
    tosa.append(a[i+1] - a[i])
tmp = tosa[0] + tosa[-1]
tosa[0] = tmp
del tosa[-1]
tosa.sort()
result = sum(tosa[:n-1])
print(result)

Measured memory_bytes: 26444
// https://atcoder.jp/contests/abc122/tasks/abc122_b
#include <bits/stdc++.h>

using namespace std;

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

#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<(b);i++)
#define repr(i,b,a) for(int i=int(b);i>=(a);i--)
#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool valid(int lx,int ux,int ly,int uy,int x,int y){
	return lx<=x&&x<ux&&ly<=y&&y<uy; 
}
ll power(ll x,ll p){
	if(p==0)return 1;
	ll res=power(x*x%mod,p/2);
	if(p%2==1)res=res*x%mod;
	return res;
}


int main()
{
	string s;
	cin>>s;
	int n=s.length();
	int ans=0;
	rep(i,n)repi(j,i,n){
		string t=s.substr(i, j-i+1);
		int res=t.length();
		for(auto c:t)if(c!='A'&&c!='C'&&c!='G'&&c!='T') res=0;
		ans = max(ans, res);
	}
	cout<<ans<<endl;
	return 0;
}

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

int LinearSearch(int x,int s[],int n){
	s[n] = x;
	for(int i=0;;i++){
		if(s[i]==x){
			if(i<n){
				return i;
			}else{
				return -1;
			}
		}
	}
}

int main(){
	int data1;
	cin >> data1;
	int* list1 = new int[data1+1];
	for(int i=0;i<data1;i++){
		cin >> list1[i];
	}

	int data2;
	cin >> data2;
	int* list2 = new int[data2];
	for(int i=0;i<data2;i++){
		cin >> list2[i];
	}

	int count=0;
	for(int i=0;i<data2;i++){
		if(LinearSearch(list2[i],list1,data1)!=-1)
			count++;
	}
	
	cout << count << endl;
	delete[] list1,list2;
	return 0; 
}

Measured memory_bytes: 3116
import java.util.*;

public class Main {
    static long steps[];

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String L = sc.next();
        long ari = 1L;
        long nasi = 2L;
        for(int i=1; i<L.length(); i++) {
            ari = (ari * 3) % 1000000007L;
            switch(L.charAt(i)) {
                case '0':
                    break;
                case '1':
                    ari = (ari + nasi) % 1000000007L;
                    nasi = (nasi * 2) % 1000000007L;
                    break;
            }
        }
        System.out.println((ari + nasi) % 1000000007L);
    }
}

Measured memory_bytes: 27152
#include<bits/stdc++.h>
using namespace std;
int r,c,k;
string s[10];
vector<pair<int,bool>> v;
vector<pair<int,bool>> paint;
bool check()
{
	int ct = 0;
	set<int> row,col;
	for(pair<int,bool> p:paint)
	{
		if(p.second)
			row.insert(p.first);
		else
			col.insert(p.first);
	}
	for(int i=0;i<r;++i)
	{
		for(int j=0;j<c;++j)
		{
			if(row.find(i)!=row.end()||col.find(j)!=col.end())
				continue;
			if(s[i][j]=='#')
				ct++;
		}
	}
	return (ct==k);
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin>>r>>c>>k;
	for(int i=0;i<r;++i)
	{
		cin>>s[i];
		v.push_back({i,true});
	}
	for(int i=0;i<c;++i)	
		v.push_back({i,false});
	int limit = 1<<(r+c);
	int ans = 0;
	for(int i=0;i<limit;++i)
	{
		paint.clear();
		for(int j=0;j<r+c;++j)
			if(i&(1<<j))
				paint.push_back(v[j]);
		if(check())
			ans++;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3648
l, r = map(int, input().split())

if (r-l)>=2019:
    print(0)
else:
    l %= 2019
    r %= 2019

    min = 2020
    for i in range(l, r):
        for j in range(i+1, r+1):
            if (i*j)%2019 < min:
                min = (i*j)%2019
    if l>=r:
        min = 0
    print(min)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=1000000007,MAX=100005,INF=1<<30;

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N;cin>>N;
    vector<ll> x(N),y(N);
    
    for(int i=0;i<N;i++){
        int a,b;cin>>a>>b;
        x[i]=a-b;
        y[i]=a+b;
    }
    
    sort(all(x));
    sort(all(y));
    
    cout<<max(x.back()-x[0],y.back()-y[0])<<endl;
    
}


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

public class Main {
	
	private static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	
	
	public static void main(String[] args) throws NumberFormatException, IOException {
		int n = Integer.parseInt(br.readLine());
		
		int maxv = Integer.MIN_VALUE;
		int min = Integer.MAX_VALUE;
		
		for(int i = 0; i < n; i++){
			int r = Integer.parseInt(br.readLine());
			maxv = Math.max(maxv, r - min);
			min = Math.min(min, r);
		}
		
		System.out.println(maxv);
		
	}
}


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

using namespace std;

int main(){
	int k,t;
	cin >> k >> t;
	int ma = 0;
	for(int i=0;i<t;i++){
		int a;cin >> a;
		ma = max(ma,a);
	}
	cout << max(2*ma-k-1,0) << endl;
	
	return 0;
}

Measured memory_bytes: 256
N,A,B,C,D=map(int,input().split())
S=input()

if "##" in S[A:C-1] or "##" in S[B:D-1]:
    print("No")
    exit()
elif C > D and "..." not in S[B-2:D+1]:
    print("No")
else:
    print("Yes")


Measured memory_bytes: 3572
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
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;
}
const int N = 45;
int n;
int A[N][N];
ll f[N][N][N] , g[N][N][N];
int main()
{
	n = read() << 1; ll ans = 0;
	for(int i = 1;i <= n;i ++) for(int j = 1;j <= n;j ++) scanf("%1d",&A[i][j]);
	for(int i = 1;i <= n;i ++)
	{
		f[i][i][i] = 1;
		for(int j = i + 1;j < n;j ++) g[i][i][j] = A[j][i];
	}
	for(int len = 3;len <= n;len ++) for(int i = 1 , j;i <= n - len;i ++)
	{
		j = i + len - 1;
		for(int p = i;p < j;p ++) for(int q = j;q > p;q --)
		{
			ll sum = 0;
			for(int k = q;k <= j;k ++) sum += f[q][j][k] * g[i][p][k];
			for(int k = p + 1;k < q;k ++) f[i][j][k] += sum * f[p + 1][q - 1][k];
		}
		for(int w = i;w <= j;w ++) for(int k = j + 1;k < n;k ++) g[i][j][k] += f[i][j][w] * A[w][k];
	}
	for(int i = 1;i < n;i ++) ans += f[1][n - 1][i] * A[n][i];
	printf("%lld\n",ans);
	return 0;
}

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

typedef int ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-12;
static const double PI = acos(-1.0);
static const ll MOD = 1000000007;

#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(a) (a).begin(), (a).end()
#define DEBUG(x) cout << #x << ": " << x << endl

ll calc_score(ll D, const vector<ll> &c, const vector<vector<ll>> &s, const vector<ll> &t) {
  vector<ll> last(26, 0);
  ll score = 0;
  REP(d, D) {
    ll i = t[d] - 1;
    score += s[d][i];
    last[i] = d + 1;
    REP(j, 26) {
      score -= c[j] * (d + 1 - last[j]);
    }
  }
  return score;
}

ll calc_diff(ll D, ll pre, ll next, const vector<ll> &c, const vector<vector<ll>> &s, ll d, const vector<ll> &t) {
  ll diff = s[d - 1][next] - s[d - 1][pre];
  {
    ll l = 0;
    for (int i = d - 1; i >= 1; i--) {
      if (t[i - 1] - 1 == next) {
        l = i;
        break;
      }
    }
    ll r = D + 1;
    FOR(i, d + 1, D + 1) {
      if (t[i - 1] - 1 == next) {
        r = i;
        break;
      }
    }
    ll x = r - d;
    ll y = d - l;
    diff += c[next] * x * y;
  }
  {
    ll l = 0;
    for (int i = d - 1; i >= 1; i--) {
      if (t[i - 1] - 1 == pre) {
        l = i;
        break;
      }
    }
    ll r = D + 1;
    FOR(i, d + 1, D + 1) {
      if (t[i - 1] - 1 == pre) {
        r = i;
        break;
      }
    }
    ll x = r - d;
    ll y = d - l;
    diff -= c[pre] * x * y;
  }
  return diff;
}

void solve(ll D, vector<ll> c, vector<vector<ll>> s, vector<ll> t) {
  ll score = calc_score(D, c, s, t);
  ll M;
  scanf("%d", &M);
  REP(i, M) {
    ll d;
    scanf("%d", &d);
    ll q;
    scanf("%d", &q);
    ll pre = t[d - 1] - 1;
    ll next = q - 1;
    t[d - 1] = next + 1;

    score += calc_diff(D, pre, next, c, s, d, t);
    printf("%d\n", score);
  }
}

int main() {
  ll D;
  scanf("%d", &D);
  vector<ll> c(26);
  for (int i = 0; i < 26; i++) {
    scanf("%d", &c[i]);
  }
  vector<vector<ll>> s(D, vector<ll>(26));
  for (int i = 0; i < D; i++) {
    for (int j = 0; j < 26; j++) {
      scanf("%d", &s[i][j]);
    }
  }
  vector<ll> t(D);
  for (int i = 0; i < D; i++) {
    scanf("%d", &t[i]);
  }
  solve(D, move(c), move(s), move(t));
  return 0;
}


Measured memory_bytes: 3808
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

struct node{
  unsigned int key;
  struct node *next;
  struct node *prev;
};

typedef struct node * NodePointer;

NodePointer nil;

NodePointer listSearch(int key){
  /* your code */
  NodePointer x;
  x = nil->next;
  while((x != nil)&&(x->key != key))
    x = x->next;
  return x;
}

void init(){
  nil = malloc(sizeof(struct node));
  nil->next = nil;
  nil->prev = nil;
}

void printList(){
  NodePointer cur = nil->next;
  int isf = 1;
  while(1){
    if ( cur == nil ) break;
    if ( isf == 0)  printf(" ");
    printf("%d", cur->key);
    cur = cur->next;
    isf = 0;
  }
  printf("\n");
}

void deleteNode(NodePointer t){
  /* your code */
  
  if ((t->next->prev == nil) || (t->prev->next == nil)) return;
  t->prev->next = t->next;
  t->next->prev = t->prev;
  
  
}

void deleteFirst(){
  NodePointer t = nil->next;
  if ( t == nil ) return;
  deleteNode(t);
}

void deleteLast(){
  /* your code */
  NodePointer t = nil->prev;
  if(t == nil) return;
  deleteNode(t);
}

void delete(int key){
  /* your code */
  deleteNode(listSearch(key));
  
}


void insert(int key){
  NodePointer x;
  x = malloc(sizeof(struct node));
  x->key = key;

  /* your code */
  x->next = nil->next;
  nil->next->prev = x;
  nil->next = x;
  x->prev = nil;
  
  
}

int main(){
  int key, n, i;
  int size = 0;
  char com[20];
  int np = 0, nd = 0;
  scanf("%d", &n);
  init();
  for ( i = 0; i < n; i++ ){
    scanf("%s%d", com, &key);
    if ( com[0] == 'i' ) {insert(key); np++; size++;}
    else if ( com[0] == 'd' ) {
      if (strlen(com) > 6){
	if ( com[6] == 'F' ) deleteFirst();
	else if ( com[6] == 'L' ) deleteLast();
      } else {
	delete(key); nd++; 
      }
      size--;
    }
  }

  printList();
  return 0;
}



Measured memory_bytes: 36104
#include<bits/stdc++.h>
#define int long long
#define rep(i,a,b) for(int i=a;i<b;i+=1)
#define reps(i,a,b) for(int i=a;i>=b;i-=1)
#define vi vector<int>
#define pb push_back
#define in(x) int x; cin>>x;
#define inn(x, y) int x, y; cin>>x>>y;
#define mi unordered_map<int,int>
#define mem(x) memset(x, 0, sizeof(x))
#define IOS ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
using namespace std;

//bool primes[1000001];
//vi prime;
//void seive(){
//	memset(primes, true, sizeof(primes));
//	primes[0] = primes[1] = false;
//	for(int i = 2; i*i<=1000000;i += 1)
//	{
//		if(primes[i])
//		{
//			for(int j = i*i; j <= 1000000;j += i) primes[j] = false;
//		}
//	}
//	rep(i, 2, 1000001)
//	{
//		if(primes[i]) prime.pb(i);
//	}
//}


//int gcd(int a, int b){
//	return b==0 ? a : gcd(b, a%b);
//}

int32_t main(void){
	IOS;
	
	in(n);
	bool res = true;
	while(n)
	{
		if(n%10==7)
		{
			cout<<"Yes"<<endl;
			res = false;
			break;
		}
		n/=10;
	}
	if(res) cout<<"No"<<endl;
	
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
 
using namespace std;
 
int main(){
    long long n;
    cin >> n;
    long long ans = 0, arr[n];
    for(long long i = 0; i < n - 1; ++i){
        cin >> arr[i];
        ans += arr[i];
    }
    long long last, rans; cin >> last;
    rans = abs(ans - last);
    for(long long i = n - 2; i > 0; --i){
        rans = min(rans, abs(ans - arr[i] - (last + arr[i])));
        last += arr[i];
        ans -= arr[i];
    }
    cout << rans;
    return 0;
}


Measured memory_bytes: 1792
fun main(args: Array<String>) {
    val s = readLine()!!
    val dp = Array(s.length + 1) { arrayOfNulls<Long>(4) }
    val mod = 1000000007

    dp[s.length][0] = 0
    dp[s.length][1] = 0
    dp[s.length][2] = 0
    dp[s.length][3] = 1

    for (i in (s.length - 1) downTo 0) {
        val m1 = if (s[i] == '?') 3 else 1
        dp[i][3] = ((dp[i + 1][3]!!) % mod * m1) % mod

        for (j in 2 downTo 0) {
            val m2 = if (s[i] == '?' || s[i] == "ABC"[j]) 1 else 0
            dp[i][j] = (((dp[i + 1][j]!!) % mod * m1) % mod + dp[i + 1][j + 1]!! * m2) % mod
        }
    }
    println(dp[0][0])
}

Measured memory_bytes: 52428
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define f(i, x, n) for(int i = x; i < (int)(n); ++i)

int const N = 200000, md = 1e9 + 7;
vector<int> tr[N + 1];
pair<int, int> dp[N + 1];
int n, an[N + 1][2], pw2[N + 1], mxdp[N + 1], es[N + 1][3];

inline void ad(int &x, int y) { if ((x += y) >= md)x -= md; }

int pl(int v = 0, int l = 0, int r = 0){
	if (v && (int)tr[v].size() == 1)return pl(tr[v][0], l, r + 1);
	dp[v] = make_pair(l, r);
	mxdp[v] = r;
	f(i, 0, tr[v].size())tr[v][i] = pl(tr[v][i], r + 1, r + 1), mxdp[v] = max(mxdp[v], mxdp[tr[v][i]]);
	return v;
}

inline pair<int, int> rm(vector<pair<int, int> > &v){
	es[0][0] = 1;
	f(i, 0, v.size()){
		es[i + 1][0] = (ll)es[i][0] * v[i].first % md;
		es[i + 1][1] = (ll)es[i][0] * v[i].second % md;
		ad(es[i + 1][1], (ll)es[i][1] * v[i].first % md);
		es[i + 1][2] = (ll)es[i][1] * v[i].second % md;
		ad(es[i + 1][2], (ll)es[i][2] * (v[i].first + v[i].second) % md);
	}
	ad(es[v.size()][0], es[v.size()][2]);
	return make_pair(es[v.size()][0], es[v.size()][1]);
}

int D, sz;
void go(int v = 0){
	if (D >= dp[v].first && D <= dp[v].second) { an[v][0] = an[v][1] = 1; ++sz; return; }
	vector<pair<int, int> > x;
	f(i, 0, tr[v].size()){
		int u = tr[v][i];
		if (mxdp[u] < D)continue;
		go(u);
		x.push_back(make_pair(an[u][0], an[u][1]));
	}
	pair<int, int> t = rm(x);
	an[v][0] = t.first;
	an[v][1] = t.second;
}

int main(){
	scanf("%d", &n);
	pw2[0] = 1;
	f(i, 1, n + 1)if ((pw2[i] = pw2[i - 1] << 1) >= md)pw2[i] -= md;
	f(i, 1, n + 1){
		int t;
		scanf("%d", &t);
		tr[t].push_back(i);
	}
	pl();
	int a = 0;
	f(i, 0, mxdp[0] + 1){
		D = i;
		sz = 0;
		go();
		ad(a, (ll)an[0][1] * pw2[n + 1 - sz] % md);
	}
	printf("%d\n", a);
}

Measured memory_bytes: 16128
import java.io.*;
import java.util.Random;
import java.util.StringTokenizer;

public class Main {
    //Solution by Sathvik Kuthuru
    public static void main(String[] args) {
        FastReader scan = new FastReader();
        PrintWriter out = new PrintWriter(System.out);
        Task solver = new Task();
        int t = 1;
        for(int tt = 1; tt <= t; tt++) solver.solve(tt, scan, out);
        out.close();
    }

    static class Task {

        public void solve(int testNumber, FastReader scan, PrintWriter out) {
            long x = scan.nextLong();
            long curr = 100;
            long step = 0;
            while(curr < x) {
                curr = (long) (1.01 * curr);
                step++;
            }
            out.println(step);
        }
    }

    static void shuffle(int[] a) {
        Random get = new Random();
        for (int i = 0; i < a.length; i++) {
            int r = get.nextInt(a.length);
            int temp = a[i];
            a[i] = a[r];
            a[r] = temp;
        }
    }

    static void shuffle(long[] a) {
        Random get = new Random();
        for (int i = 0; i < a.length; i++) {
            int r = get.nextInt(a.length);
            long temp = a[i];
            a[i] = a[r];
            a[r] = temp;
        }
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        public FastReader(String s) throws FileNotFoundException {
            br = new BufferedReader(new FileReader(new File(s)));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }

}

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

using namespace std;
#define ll long long
#define ld long double
#define PI 3.141592653L
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const ll INF = (ll)1e18;
const int N = 2e5 + 5;
const ll MOD = 1e9+7;

int parent[N];

int gcd(int a, int b) { 
    if (a == 0) 
        return b;  
    return gcd(b%a, a);  
} 
   
int lcm(int a, int b) {  
    return (a*b)/gcd(a,b);  
} 

ll pow(ll x, ll y, ll p) {
    if(y == 0) return 1;
    ll res = 1;
    x %= p;
    if(x == 0) return 0LL;
    while(y > 0) {
        if(y & 1) res = (res*x) % p;
        y >>= 1;
        x = (x*x) % p;
    }
    return res;
}

int find(int x) {
    return x == parent[x] ? x : parent[x] = find(parent[x]);
}

void Union(int x, int y) {
    int xPar = find(x), yPar = find(y);
    if(xPar != yPar) parent[xPar] = yPar;
}

ll nCr(ll n, ll r) {
    ll res = 1;
    for(ll i=1;i<=r;i++) {
        res = res * (n - r + i) / i;
        // is different from
        // res *= (n -r + i) / i;
    }
    return res;
}

void solve() {
    int l, r, d;
    cin >> l >> r >> d;
    int temp = d;
    int res = 0;
    while(d <= r) {
        if(l <= d && d <= r) res++;
        d += temp;
    }
    cout << res << endl;
    return;
} 

int main()
{
    IOS
    //int t;
    //cin >> t;
    //while(t--) 
    solve();
    return 0; 
}


Measured memory_bytes: 3644
#define DIN freopen("input.txt","r",stdin);
#define DOUT freopen("output.txt","w",stdout);
#include <bits/stdc++.h>
#define mem(a,b) memset(a,b,sizeof(a))
#define REP(i,a,b) for(int i=(a);i<=(int)(b);i++)
#define REP_(i,a,b) for(int i=(a);i>=(b);i--)
#define pb push_back
using namespace std;
typedef long long LL;
typedef vector<int> VI;
typedef pair<int,int> P;
int read()
{
    int x=0,flag=1; char c=getchar();
    while((c>'9' || c<'0') && c!='-') c=getchar();
    if(c=='-') flag=0,c=getchar();
    while(c<='9' && c>='0') {x=(x<<3)+(x<<1)+c-'0';c=getchar();}
    return flag?x:-x;
}

const int maxn=2e5+5;
struct node
{
    int L,R,K;
    bool operator < (const node x) const {return K<x.K;}
}a[maxn];

int main()
{
    int T=read();
    while(T--)
    {
        int n=read();
        REP(i,1,n) a[i].K=read(),a[i].L=read(),a[i].R=read();
        vector<node> x,y;
        REP(i,1,n)
            if(a[i].L>=a[i].R) x.pb(a[i]);
            else y.pb(a[i]);
        sort(x.begin(),x.end()); sort(y.begin(),y.end());
        LL ans=0;
        REP(i,1,n) ans+=min(a[i].L,a[i].R);

        priority_queue<int,VI,greater<int> > Q;
        REP(i,1,x.size())
        {
            int add=abs(x[i-1].L-x[i-1].R),k=x[i-1].K;
            if(k>Q.size()) Q.push(add);
            else if(!Q.empty() && add>Q.top()) Q.pop(),Q.push(add);
        }
        while(!Q.empty()) ans+=Q.top(),Q.pop();
        REP(i,1,y.size())
        {
            int add=abs(y[y.size()-i].L-y[y.size()-i].R),k=n-y[y.size()-i].K;
            if(k>Q.size()) Q.push(add);
            else if(!Q.empty() && add>Q.top()) Q.pop(),Q.push(add);
        }
        while(!Q.empty()) ans+=Q.top(),Q.pop();
        printf("%lld\n",ans);
    }

    return 0;
}


Measured memory_bytes: 8808
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
typedef long long ll;
int memo[6][10];
const ll MOD = 1000000007;
ll dp[100001][13]; //iは桁、jは剰余
int main(){

    //計算結果メモ用
    //周期性を利用して、10のi乗*s[j]%13を予め求めておく
    rep(i,10) memo[0][i] = i;
    rep(i,6) memo[i][0] = 0;
    rep(i,5){
        for(int j = 1; j < 10; j++){
        memo[i+1][j] = 10*memo[i][j]%13;
        }
    }

    string s; cin >> s;

    int range = s.size(); //s.size()を何回も呼び出すのはダメ、先に記録しておく
    
    rep(i,range) rep(j,13) dp[i][j] = 0;

    if(s[range-1] == '?') rep(j,10) dp[range-1][j] = 1;
    else dp[range-1][(s[range-1]-'0')] = 1;

    for(int i = range-2; i >= 0; i--){ //10のi乗*s[i]%13について考える
        if(s[i] == '?'){
            rep(j,10){ //?に何を入れるかで全探索
                rep(k,13){ //各剰余について計算
                    dp[i][(memo[(range-1-i)%6][j]+k)%13] = (dp[i][(memo[(range-1-i)%6][j]+k)%13] + dp[i+1][k]) % MOD;
                }
            }
        }else{
            rep(j,13){ //普通に各剰余から次への推移を考える
                dp[i][(memo[(range-1-i)%6][(s[i]-'0')] + j) % 13] = (dp[i][(memo[(range-1-i)%6][(s[i]-'0')] + j) % 13] + dp[i+1][j]) % MOD;
            }
        }
    }

    cout << dp[0][5] % MOD << endl;
}

Measured memory_bytes: 10624
fn solve() {
    let n: usize = {
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).unwrap();
        buf.trim_end().parse().unwrap()
    };

    let spf = smaller_prime_factors(n);
    let factor = move |x: usize| {
        let mut x = x;
        let mut ret = std::collections::HashMap::new();
        while x != 1 {
            *ret.entry(spf[x]).or_insert(0) += 1;
            x /= spf[x];
        }
        ret
    };

    let mut ans = 1;
    for i in 2..n {
        let m = factor(i);
        let mut t: i64 = 1;
        for &v in m.values() {
            t *= v + 1;
        }
        ans += t;
    }

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

fn smaller_prime_factors(n: usize) -> Vec<usize> {
    let mut spf: Vec<usize> = (0..(n + 1)).collect();

    for i in 2 as usize..(n + 1) {
        if spf[i] == i {
            for j in ((i * i)..(n + 1)).step_by(i as usize) {
                if spf[j] == j {
                    spf[j] = i;
                }
            }
        }
    }
    spf
}

fn main() {
    solve();
}


Measured memory_bytes: 9988
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#define rep(i,l,r) for(int i=(l);i<=(r);++i)
#define per(i,r,l) for(int i=(r);i>=(l);--i)
using namespace std;
const int maxn=1e5+10;
int a[maxn],n;
int main(){
    scanf("%d",&n);
    rep(i,1,n) scanf("%d",&a[i]);
    sort(a+1,a+n+1,greater<int>());
    rep(i,1,n) if(a[i+1]<i+1){
        int ans=(a[i]-i)&1,j=i;
        while(j<n&&a[j+1]==i) ++j;
        ans|=(j-i)&1;puts(ans?"First":"Second");break;
    }
    return 0;
}

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

using i64 = long long;
using P = pair<i64, i64>;

#define overload3(_1, _2, _3, name, ...) name
#define rep1(i, n) for(i64 i = 0LL; i < (n); ++i)
#define rep2(i, a, b) for(i64 i = (a); i < (b); ++i)
#define rep(...) overload3(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)
#define all(v) v.begin(), v.end()


void solve(long long N){
  cout << (N + 1) / 2 << endl;
}

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;

int main(){
    long long N;
    scanf("%lld",&N);
    solve(N);
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#include <chrono>
#include <random>
#include <cstdio>
#define ll long long int
#define endl '\n'
#define pb push_back
#define mp make_pair
#define rep(i,n) for(ll i=0;i<n;i++)
#define vi vector <int>
#define vs vector <string>
#define vc vector <char>
#define vl vector <ll>
#define pll pair<ll, ll>
#define pint pair<int, int>
#define S second
#define F first
#define all(c) (c).begin(),(c).end()
using namespace std;
const int N=500001;
ll gcd(ll a, ll b) { if (a == 0) return b; return gcd(b % a, a); } 
ll lcm(ll a, ll b){return a*b/gcd(a, b);}
#define pi 3.14159265358979323846264338
using namespace std; 
ll max(ll a, ll b){ if(a>b)return a;return b;}
ll min(ll a, ll b){ if(a < b) return a;return b;}
ll inf = 100000000000000000;

void solve() 
{
    ll k;
    cin>>k;

    int r = 7%k;

    // cout<<r<<endl;
    // cout<<101%77<<endl;


    for(int i = 1; i <= 1e6; i++)
    {
        if(r == 0)
        {
            cout<<i<<endl;
            return;
        }

        // cout<<r<<endl;
        r = (10*r + 7)%k;
    }

    cout<<-1<<endl;
}



int main()
{
    #ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int T=1;
    // cin>>T;
    int t=0;
    while(t++<T)

    {
        // cout<<"Case #"<<t<<":"<<' ';
        solve();
        // cout<<'\n';
    }

    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}


Measured memory_bytes: 3800
#include <iostream>
#include <algorithm>
#include <string>
#include <functional>
#include <math.h>
#include <map>
#include <vector>
using namespace std;

int main() {
	int n, m, x;
	int a[100];
	cin >> n >> m >> x;
	for (int i = 0; i < m; i++) {
		cin >> a[i];
	}
	int ans0 = 0;
	for (int i = x; i > 0; i--) {
		for (int j = 0; j < m; j++) {
			if (i == a[j]) {
				ans0++;
			}
		}
	}
	int ansn = 0;
	for (int i = x; i < n; i++) {
		for (int j = 0; j < m; j++) {
			if (i == a[j]) {
				ansn++;
			}
		}
	}
	cout << min(ans0, ansn) << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int a,b;
    char op;
    cin >> a >> op >> b;
    while (op!='?') {
        if(op == '+'){
            cout << a+b<<"\n";
        }else if (op=='-'){
            cout<< a-b<<"\n";
        }else if (op=='*'){
            cout<< a*b<<"\n";
        }else if (op == '/'){
            cout<<a/b<<"\n";
        }
        cin>>a>>op>>b;
    }
}

Measured memory_bytes: 1160
#include <stdio.h>
int main(){
  int W,H,x,y,r;
  scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
  if((x+r)<=W&&(x-r)>=0&&(y+r)<=H&&(y-r)>=0)
    printf("Yes\n");
  else printf("No\n");
  return 0;
}

Measured memory_bytes: 1012
#include <cstdio>
#include <cctype>

using namespace std;

int main(void) {
	char c;
	while (1) {
		scanf("%c", &c);
		if (isalpha(c)) {
			if (islower(c)) {
				c = toupper(c);
			}
			else if (isupper(c)) {
				c = tolower(c);
			}
		}
		printf("%c", c);
		if (c == '\n') break;
	}

	return 0;
}

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

#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define eb push_back
#define endl '\n'
#define all(x) (x).begin(), (x).end()
#define output(x) cout<<x<<endl;
#define fre(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define frd(i, a, b) for (int i = (int)(a); i >= b; --i)

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<pair<int,int> > vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;
const ll mod=1e9+7;
const int maxn = 310000;

bool possible[maxn];
int ans[maxn];

int main(){
	cin.tie(0);ios_base::sync_with_stdio(0);	
	int n,k;
	cin>>n>>k;
	ll a[n];
	for (int i = 0; i < n; ++i)
	{
		cin>>a[i];
	}
	for (int i = 0; i < n; ++i)
	{
		possible[a[i]]=1;
		vector<int>v;
		for (int j = 0; j < maxn; ++j)
		{
			if(possible[j]){
				v.pb(j);
				if(j+a[i]<=k) v.pb(j+a[i]);
			}
		}
		for(auto it:v){
			possible[it]=1;
		}
	}
	fre(i,1,k){
			for (int j = 0; j < n; ++j)
			{
				if(i-a[j]>=0){
					if(ans[i-a[j]] == 0) ans[i]=1;
				}
			}
	}
	if(ans[k]){
		output("First");
	}
	else {
		output("Second");
	}
	return 0;
}

Measured memory_bytes: 2220
from scipy.sparse import*
n,*t=map(int,open(0).read().split())
c=sorted(t[-n:])
f=[0]*n
for i in csgraph.depth_first_order(csr_matrix(([1]*~-n,(t[:-n:2],t[1:-n:2])),[n+1]*2),1,0)[0]:n-=1;f[i-1]=c[n]
print(sum(c[:-1]),*f)

Measured memory_bytes: 19340
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
  
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
  
using namespace std;
  
typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;
  
const int INF=1<<29;
const double EPS=1e-9;
  
const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};


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

  vector<int> X_ = X;
  sort(all(X_));

  int ans1 = X_[N / 2 - 1];
  int ans2 = X_[N / 2];

  for (int i = 0; i < N; i++) {
    if (X[i] > ans1) {
      cout << ans1 << endl;
    } else {
      cout << ans2 << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
#define ull unsigned long long
#define MOD (int)(998244353)
#define ceil(x, y) (x%y==0? (x/y) : (x/y+1))
#define FOR(i, N) for(int i = 0; i < N; ++i)
#define FOR1(i, N) for(int i = 1; i <= N; ++i)
#define vi vector <int>
#define pii pair <int, int>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mset(a, v) memset(a, v, sizeof(a))
#define all(v) (v).begin(), (v).end()
#define INF (int)2e18
#define EPS 1e-9
#define int long long
#define MAX 100009
int fun(int arr[], int n, int k){
	/*if(n == 1) return 0LL;
	if(n == 2) return abs(arr[n]-arr[n-1]);
    return min(abs(arr[n]-arr[n-1]) + fun(arr, n-1), abs(arr[n]-arr[n-2]) + fun(arr, n-2));*/
	/*dp[i] = min cost to reach ith stone*/
	int dp[n+1];
	for(int i = 1; i <= n; i++) dp[i] = INF;
	dp[1] = 0;
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= k; j++){
			dp[i] = min(dp[i], ((i-j >= 1)? abs(arr[i]-arr[i-j]) + dp[i-j] : INF));
		}
	}
	return dp[n];
}
int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
	int T=1;
	//cin >> T;
	FOR1(i, T)
	{
		//cout << "Case #" << i << ": \n";
		int n, k; cin >> n >> k;
        int a[n+1];
        FOR1(i, n) cin >> a[i];
        cout << fun(a, n, k);
		cout<<'\n';
	}
	return 0;
}


Measured memory_bytes: 1792
import sys
from collections import Counter
N,M,K = map(int,input().split())
f = [[] for _ in range(N+1)]
b = [[] for _ in range(N+1)]
for i in range(M):
    x,y = map(int,input().split())
    f[x].append(y)
    f[y].append(x)

d = [None]*(N+1)
sys.setrecursionlimit(10**9)
def dfs(f,s,id):
    if(d[s] is None):
        d[s] = id
    for i in f[s]:
        if(d[i] is not None):
            continue
        dfs(f,i,id)
         
cnt = -1
for j in range(1,N+1):
    if(d[j] == None):
        cnt += 1
        dfs(f,j,cnt)
    
for i in range(K):
    x,y = map(int,input().split())
    if(d[x] == d[y]):
        b[x].append(y)
        b[y].append(x)

c = Counter(d)
for i in range(1,N+1):
    print(c[d[i]] - len(f[i]) - len(b[i])-1)

Measured memory_bytes: 52416
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e18;
int mod = 1e9+7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
signed main() {
    double n,m,d;
    cin >> n >> m >> d;
    if(d == 0) {
        cout << fixed << setprecision(20) << (m-1)*((n-d)/(n*n)) << endl;
    }
    else {
        cout << fixed << setprecision(20) << (m-1)*((n-d)*2/(n*n)) << endl;
    }
}


Measured memory_bytes: 3780
#include <math.h>
#include <utility>
#include <string>
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;

int m;
int n;
int map[10][10] = {0};
int cnt = 0;
int churchx;
int churchy;
int dx[4] = {-1,1,0,0};
int dy[4] = {0,0,-1,1};

int saiki( int xinput, int yinput, int nokori ) {
	for ( int i = 0; i < 4; i++ ) {
		int x = xinput;
		int y = yinput;
		if ( nokori == 0 ) {
			if ( y == churchy && x > churchx && i != 0 ) continue;
			if ( y == churchy && x < churchx && i != 1 ) continue;
			if ( x == churchx && y > churchy && i != 2 ) continue;
			if ( x == churchx && y < churchy && i != 3 ) continue;
		}
		while(true) {
			x += dx[i];
			y += dy[i];
			if ( x < 0 || x >= m || y < 0 || y >= n ) break;
			if ( map[x][y] == 1 ) {
				map[x][y] = 0;
				saiki( x, y, nokori-1 );
				map[x][y] = 1;
				break;
			}else if ( map[x][y] == 2 ) {
				if ( nokori == 0 ) {
					cnt++;
					return 0;
				}
			}else if ( map[x][y] == 3 ) {
				break;
			}
		}
	}
	return 0;
}

int main(){
	while(true) {
		cin >> m;
		cin >> n;
		if ( m == 0 ) break;
		int nokori = 0;
		for ( int i = 0; i < n; i++ ) {
			for ( int j = 0; j < m; j++ ) {
				cin >> map[j][i];
				if ( map[j][i] == 1 ) {
					nokori++;
				}else if ( map[j][i] == 2 ) {
					churchx = j;
					churchy = i;
				}
			}
		}
		if ( nokori == 0 ) {
			cout << "1" << endl;
		}else {
			cnt = 0;
			saiki( churchx, churchy, nokori );
			cout << cnt << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1160
#https://atcoder.jp/contests/abc167/tasks/abc167_b
# -*- coding: utf-8 -*-
A,B,C,K = map(int,input().split())
point = 0
if A >= K:
  print(K)
elif A+B >= K:
  print(A*1)
else:
  print(A*1 + (K-A-B)*-1)

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

#define rep(i, n)  for (int i = 0; i < (int) (n); i++)
#define Rrep(i, n) for (int i = ((int) n - 1); i >= 0; i--)
#define all(x)     (x).begin(), (x).end()
#define SZ(x)      ((int) (x).size())
#define INF 2e15
#define MOD 10e9 + 7

typedef vector <int> vint;
typedef long long    ll;



int main()
{
    ll n;
    ll count = 0;
    ll buf   = 2;
    cin >> n;
    if (n == 0 || n % 2 == 1) { cout << 0; return 0; }

    for (int i = 1;; i++) {
        buf = buf * 5;
        if (buf > n) { break; }
        count = count + (ll) (n / buf);
        // cout << "count=" << count << "," << "i=" << i << endl;
    }

    cout << count;

    return 0;
}


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

using namespace std ;

int main(void){
    int N;
    // std::vector<int> a(100);
    int a[100];

    cin >> N;
    
    for(int i=0; i<N; i++)
        cin >> a[i];

    // int min = *std::min_element(a.begin(), a.end());
    // int max = *std::max_element(a.begin(), a.end());
    
    int max=0, min=999999999;
    for(int i=0; i<N; i++) {
        if(max < a[i]) max=a[i];
        if(min > a[i]) min=a[i];
    }
    cout << max - min << endl;

    return 0;
}


Measured memory_bytes: 256
H, W, K = map(int, input().split())
C = []
for i in range(H):
    c = input()
    c = list(c)
    C.append(c)

ans = 0
for i in range(2 ** H):
    gyou = [False]*H
    for j in range(H):
        if ((i >> j) & 1):
            gyou[H - 1 - j] = True
    #print(gyou)
    for k in range(2 ** W):
        retu = [False]*W
        for l in range(W):
            if ((k >> l) & 1):
                retu[W - 1 - l] = True
        #print(retu)
        count = 0
        for m in range(H):
            for n in range(W):
                if C[m][n] == "#" and gyou[m] == True and retu[n] == True:
                    count += 1
        if count == K:
            ans += 1

print(ans)

Measured memory_bytes: 9236
#include<iostream>
#include<string>

using namespace std;

int main(void){

    int a,b,k;
    cin >> a >> b >> k;
    for(int i = a;i<=b;i++){
        if(i==a||i==b){
            cout << i << endl;
            continue;
        }
        if(i<=a+k-1){cout << i << endl;continue;}
        if(i>=b-k+1){cout << i << endl;continue;}
    }

    return 0;
}


Measured memory_bytes: 256