akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

const int MAXN = 200010;
typedef long long LL;
int n, K;
void reduce(int & x) { x += x >> 31 & K; }
int remod(LL x) { x %= K; return x + (x >> 63 & K); }
int A[MAXN], B[MAXN], L[MAXN], R[MAXN], li[MAXN], bak;
typedef std::pair<int, int> pi;
pi tree[MAXN << 2], tag[MAXN << 2];
void mkset(int u, pi t) { tree[u] = tag[u] = t; }
void pushdown(int u) {
	if (tag[u] != *tag) {
		mkset(u << 1, tag[u]);
		mkset(u << 1 | 1, tag[u]);
		tag[u] = *tag;
	}
}
pi qry(int u, int l, int r, int tar) {
	if (l == r) return tree[u];
	int mid = l + r >> 1;
	pushdown(u);
	if (tar <= mid) return qry(u << 1, l, mid, tar);
	return qry(u << 1 | 1, mid + 1, r, tar);
}
void mdf(int u, int l, int r, int L, int R, pi t) {
	if (L <= l && r <= R) return mkset(u, t);
	int mid = l + r >> 1;
	pushdown(u);
	if (L <= mid) mdf(u << 1, l, mid, L, R, t);
	if (mid < R) mdf(u << 1 | 1, mid + 1, r, L, R, t);
}
int main() {
	std::ios_base::sync_with_stdio(false), std::cin.tie(0);
	std::cin >> n >> K;
	LL pre = 0;
	for (int i = 1; i <= n; ++i) {
		std::cin >> A[i] >> B[i];
		if (B[i] == 1 && A[i] >= K) return std::cout << -1 << std::endl, 0;
		if (B[i] == 2) L[i] = 0, R[i] = K - 1;
		else L[i] = remod(-pre * 2), R[i] = remod(-(pre + A[i]) * 2);
		pre += A[i];
		li[++bak] = L[i], li[++bak] = R[i];
	}
	li[++bak] = 0;
	std::sort(li + 1, li + 1 + bak);
	bak = std::unique(li + 1, li + 1 + bak) - li - 1;
	for (int i = 1; i <= n; ++i) {
		L[i] = std::lower_bound(li + 1, li + 1 + bak, L[i]) - li;
		R[i] = std::lower_bound(li + 1, li + 1 + bak, R[i]) - li;
	}
	memset(tag, -1, sizeof tag);
	for (int i = 1; i <= bak; ++i)
		mdf(1, 1, bak, i, i, pi(i, 0));
	for (int i = n; i; --i) {
		pi v = qry(1, 1, bak, L[i]);
		if (L[i] <= R[i]) {
			if (L[i] > 1) mdf(1, 1, bak, 1, L[i] - 1, v);
			v.second += 1;
			if (R[i] < bak) mdf(1, 1, bak, R[i] + 1, bak, v);
		} else if (R[i] + 1 <= L[i] - 1)
			mdf(1, 1, bak, R[i] + 1, L[i] - 1, v);
	}
	LL ans = std::numeric_limits<LL>::max();
	for (int i = 1; i <= bak; ++i) {
		pi v = qry(1, 1, bak, i);
		ans = std::min(ans, pre * 2 + li[v.first] - li[i] + (LL) v.second * K);
	}
	std::cout << ans << std::endl;
	return 0;
}


Measured memory_bytes: 14592
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        MyScanner in = new MyScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        B solver = new B();
        solver.solve(1, in, out);
        out.close();
    }

    static class B {
        public void solve(int testNumber, MyScanner in, PrintWriter out) {
            int N = in.nextInt();
            int T = in.nextInt();
            int A = in.nextInt();
            int[] H = in.nextIntArray(N);

            int ans = 0;
            double min = 1e9;
            for (int i = 0; i < N; i++) {
                double temp = Math.abs(A - (T - H[i] * 0.006));
                if (temp < min) {
                    ans = i;
                    min = temp;
                }
            }
            out.println(ans + 1);
        }

    }

    static class MyScanner {
        private BufferedReader in;
        private StringTokenizer st;

        public MyScanner(InputStream stream) {
            in = new BufferedReader(new InputStreamReader(stream));
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    String rl = in.readLine();
                    if (rl == null) {
                        return null;
                    }
                    st = new StringTokenizer(rl);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }

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

        public int[] nextIntArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = nextInt();
            }
            return a;
        }

    }
}



Measured memory_bytes: 22868
#include <bits/stdc++.h>
template<class T> inline bool chmin(T&a, T b){if(a > b){a = b; return true;}else{return false;}}
template<class T> inline bool chmax(T&a, T b){if(a < b){a = b; return true;}else{return false;}}
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1.0)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

int main() {
    string a, b;
    cin >> a >> b;
    if(a == "H"){
        if(b == "H")cout << "H" << endl;
        else cout << "D" << endl;
    }else{
        if(b == "H")cout << "D" << endl;
        else cout << "H" << endl;
    }
}

Measured memory_bytes: 3576
let () =
  let n = read_int () in
  let min = ref 0 in
  let ans = ref (-1000000001) in
  let rec read i =
    if i > n then !ans
    else begin
      let r = read_int () in
      if i = 1 then min := r
      else begin
        if !ans < r - !min then ans := r - !min;
        if !min > r then min := r;
      end;
      read (i + 1)
    end
  in
  Printf.printf "%d\n" (read 1)

Measured memory_bytes: 4528
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=205,MAX_LOG=20;
const ll INF=1LL<<60;
struct edge{int to;ll cap;int rev;};

vector<edge> G[MAX];
int level[MAX];
int iter[MAX];

void add_edge(int from,int to,ll cap){
    G[from].push_back((edge){to,cap,int(G[to].size())});
    G[to].push_back((edge){from,0LL,int(G[from].size())-1});
}

void BFS(int s){
    memset(level,-1,sizeof(level));
    queue<int> que;
    level[s] =0;
    que.push(s);
    while(!que.empty()){
        int v=que.front();que.pop();
        for(int i=0;i<G[v].size();i++){
            edge &e =G[v][i];
            if(e.cap>0&&level[e.to]<0){
                level[e.to]=level[v]+1;
                que.push(e.to);
            }
        }
    }
}

ll DFS(int v,int t,ll f){
    if(v==t) return f;
    for(int &i=iter[v];i<G[v].size();i++){
        edge &e =G[v][i];
        if(e.cap>0&&level[v]<level[e.to]){
            ll d= DFS(e.to,t,min(f,e.cap));
            if(d>0){
                e.cap-=d;
                G[e.to][e.rev].cap+=d;
                return d;
            }
        }
    }
    return 0;
}

ll max_flow(int s,int t){
    ll flow=0;
    for(;;){
        BFS(s);
        if(level[t]<0) return flow;
        memset(iter,0,sizeof(iter));
        ll f;
        while((f=DFS(s,t,INF))>0){
            flow+=f;
        }
    }
}


int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int H,W;cin>>H>>W;
    vector<string> S(H);
    for(int i=0;i<H;i++){
        cin>>S[i];
        for(int j=0;j<W;j++){
            if(S[i][j]=='o'){
                add_edge(i,100+j,1);
                add_edge(100+j,i,1);
            }else if(S[i][j]=='S'){
                add_edge(200,i,INF);
                add_edge(200,100+j,INF);
            }else if(S[i][j]=='T'){
                add_edge(i,201,INF);
                add_edge(100+j,201,INF);
            }
        }
    }
    
    ll k=max_flow(200,201);
    
    if(k<=H+W) cout<<k<<endl;
    else cout<<-1<<endl;
}



Measured memory_bytes: 1536
import sys
from collections import Counter
input = sys.stdin.readline
n = int(input())
s = list(input())

c  = Counter(s)  

num = c['R']*c['G']*c['B']

for j in range(n):
    for d in range(1,min(j,n-j-1)+1):
        i = j-d
        k = j+d
        if s[i] != s[j] and s[j] != s[k] and s[k] != s[i]:
            num -= 1
print(num)

Measured memory_bytes: 68636
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define RNG(i,from,to) for(int i=(from); i<(int)(to); i++)
#define gcd(i,j) __gcd((i), (j))
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<ll> vecll;
template<typename S, typename T> string to_string(pair<S, T> p) { return "("+to_string(p.first)+","+to_string(p.second)+")"; }
template<typename T> string to_string(T p[2]) { return "["+to_string(p[0])+","+to_string(p[1])+"]"; }
template<typename T> void println(T e){ cout << to_string(e) << endl; }
template<typename T> void println(const vector<T>& v){ cout << "[";for(const auto& e : v){ cout << to_string(e) << ","; }cout << "]";cout << endl; }
template<typename T> void println(const vector<vector<T>>& vv){ for(const auto& v : vv){ println(v); } }
template<typename Iter> void println(Iter first, Iter last){ for(auto it=first; it != last; it++){ cout << *it << " "; }; cout << endl; }
template<typename T> T mod_pow(T x, T n, const T &p) { T ret = 1; while(n > 0) { if(n & 1) (ret *= x) %= p; (x *= x) %= p; n >>= 1; } return ret; }
template<typename T> T mod_inv(T x, const T &p) { return mod_pow(x, p-2, p); }
const ll DVSR = 1e9+7;

bool ok(ll N, ll K) {
  if (N == 1) return true;
  if (N % K == 1) {
    return true;
  } else if (N % K == 0) {
    return ok(N/K, K);
  } else {
    return false;
  }
}

int main(int argc, char const *argv[])
{
  ll N; cin >> N;
  ll NN = N-1, cnt = 2;
  if (N == 2) {
    cout << 1 << endl;
    return 0;
  }
  ll upper = sqrt(NN)+1;
  for (ll i = 2; i < upper; i++) {
    if (NN%i == 0) {
      if (i*i != NN) cnt += 2;
      else cnt += 1;
    }
  }
  RNG(i, 2, sqrt(N)+1) if (N%i != 1 && ok(N, i)) cnt++;
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) FOR(i,0,n)
#define FOR(i,a,b) for(int i=(a),i##Len_=(b);i<i##Len_;i++)

int main() 
{
    int N,K;
    double res = 0;

    cin >> N >> K;

    double tmp;

    for(int i = 1; i <= N; i++)
    {
        //1から順にやっていく?
        //何分の1の何をキープしておく

        tmp = 1.0/N;

        int now = i;

        while(now < K)
        {
            now *= 2;
            tmp /= 2;
        }

        res += tmp;

    }
    //cout    << res << endl; 
    printf("%.12f\n",res);

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _CRT_SECURE_NO_WARNINGS
#define ll long long
#define BUF 1e5
#define INF 1<<30
using namespace std;
ll MOD = 1e9 + 7;
ll A, B, C, D, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S;
ll ans = 0;

int main() {
	cin >> N >> M >> C;
	vector<int>a(M), b(M);
	for (int i = 0; i < M; i++)cin >> b[i];
	for (int i = 0; i < N; i++) {
		int tmp = 0;
		for (int i = 0; i < M; i++) {
			cin >> a[i];
			tmp += a[i] * b[i];
		}
		tmp += C;
		if (tmp > 0)ans++;
	}
	cout << ans << endl;
}

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

using namespace std;

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;

const ll mod=1e9+7;
const ll inf=1e16; 

#define rep(i,m,n) for(ll i=m;i<n;i++)
#define repr(i,m,n) for(ll i=m;i>=n;i--)

int main(){
   cin.tie(nullptr);
  ios::sync_with_stdio(false);
  
 ll n,p;
  cin >> n >> p;
 string s;
  cin >> s;
 
  ll res=0;
 if(p==2||p==5){
   rep(i,0,n) if(ll(s[i]-'0')%p==0) res+=i+1;  
 } 
 else {
  map<ll,ll> mp;
  mp[0]++;
  ll x=0,pow=1;
  repr(i,n-1,0) {
    x+=(ll(s[i]-'0')*pow),x%=p;
    mp[x]++;
    pow*=10,pow%=p;
  }
  for(auto p: mp) res+=p.second*(p.second-1)/2;
 }
  cout << res << endl;
 
}

Measured memory_bytes: 1044
#include <bits/stdc++.h>
#define ll long long  int
#define N 200000
#define f(i, a, b) for (ll i = (ll)a; i <= (ll)b; i++)
#define rf(i, a, b) for (ll i = (ll)a; i >= (ll)b; i--)
#define po pop_back
#define pb push_back
#define lb lower_bound
#define fi first
#define se second
#define debug(x) cout << #x << " = " << x << endl
#define ub upper_bound
#define ibs ios_base::sync_with_stdio(false)
#define cti cin.tie(0)
#define all(x) x.begin(), x.end()
#define PI 3.14159265
#define cot cout.tie(0)
using namespace std;


ll n,d,a;
ll x[N+1],h[N+1],c[N+1];  

vector <pair <ll,ll>  > vp;

 
int main()
{
    //freopen("input.txt","r",stdin);
    
    cin >> n >> d >> a;

    f(i,1,n)
    {
        cin >> x[i] >> h[i];

        vp.pb({x[i],h[i]});


    }

    ll ans=0;
    sort(all(vp));

    for(int i=0,j=0;i<n;++i)
    {
              while(j<n&&vp[j].first<=vp[i].first+2*d)
              ++j;
              ll need=max((vp[i].second-c[i]*a+a-1)/a,0LL);
              ans+=need;
              c[i]+=need;
              c[j]-=need;
              c[i+1]+=c[i]; 
    }
    cout << ans ;
}

Measured memory_bytes: 8816
import java.util.*;

public class Main{
    public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	int H = sc.nextInt();
	int W = sc.nextInt();
	for ( int i = 0; i < H; i++ ) {
	    for ( int j = 0; j < W; j++ ) {
		String S = sc.next();
		if ( S.equals("snuke") ) {
		    System.out.print((char)('A' + j));
		    System.out.println(i + 1);
		}
	    }	    
	}

    }
}


Measured memory_bytes: 22868
#include <stdio.h>
#define L 100010
int arr[L];
int res[L] = {0};
int main()
{
        for(int i = 0;i<L;i++){
                arr[i] = 1;
        }
        arr[0] = 0;
        arr[1] = 0;
        for(int i = 2;i<=L;i++){
                if(arr[i] == 1){
                        for(int j=i*2;j<=L;j+=i){
                                arr[j] = 0;
                        }
                }
        }
        for(int i = 3; i<L; i++){
                if(arr[i] == 1&&arr[(i+1)/2] == 1)
                        res[i] = 1;
                res[i] += res[i-1];
        }
        int T;
        scanf("%d",&T);
        while(T--){
                int a,b;
                scanf("%d %d",&a,&b);
                printf("%d\n",res[b] - res[a-1]);
        }
        return 0;
}



Measured memory_bytes: 1408
n=int(input())
a=[]
b=[]
for i in range(n):
  k=list(map(int,input().split()))
  a.append(k)
a.sort()
a.reverse()
for i in range(n):
  k=list(map(int,input().split()))
  b.append(k)
b.sort()
ans=0
for i in range(n):
  c=[]
  for j in range(len(b)):
    if a[i][0]<b[j][0] and a[i][1]<b[j][1]:
      c.append(b[j][1])
    else:
      c.append(10**18)
  if c.count(10**18)!=len(c):
    b.pop(c.index(min(c)))
    ans+=1
print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<string>
using namespace std;
int main() {
    int K, S;
    cin >> K >> S;
    int c = 0;
    for(int i = 0; i <= K; i++){
        for(int j = 0; j <= K; j++){
            if(0<= S - i - j && S - i - j <= K) c++;
        }
    }
    cout << c << endl;
    return 0;
}

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

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	 
	int n;
	string s;
	cin >> n >> s;
	if(n & 1) {
		cout << "No\n";
	}
	else {
		bool flag = true;
		for(int i = 0; i < n/2; i++) {
			if(s[i] != s[i+n/2]) {
				flag = false;
				break;
			}
		}
		if(flag) cout << "Yes\n";
		else cout << "No\n";
	}

	return 0;
}

Measured memory_bytes: 256
def examA():
    S = SI()
    T = SI()
    if S==T[:len(S)]:
        if len(S)+1==len(T):
            print("Yes")
            return
    print("No")
    return

def examB():
    ans = 0
    print(ans)
    return

def examC():
    ans = 0
    print(ans)
    return

def examD():
    ans = 0
    print(ans)
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def I(): return int(input())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

sys.setrecursionlimit(10**7)

if __name__ == '__main__':
    examA()

"""
142
12 9 1445 0 1
asd dfg hj o o
aidn
"""

Measured memory_bytes: 76720
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n,m = map(int, input().split())
if n==m:
    ans = "Yes"
else:
    ans = "No"
print(ans)

Measured memory_bytes: 61860
import math
food = [int(input()) for i in range(5)]

minute = 9
z = 0
for i in range(4):
    if minute > food[i] % 10 and food[i] % 10 != 0:
        minute = food[i] % 10
        z = i

ans = 0
for i in range(5):
    if z != i:
        ans += math.ceil(food[i] / 10) * 10
ans += food[z]

print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
char c[200];
int vis;
unsigned int lenth;
int main()
{
    cin>>c;
    lenth=strlen(c);
    for(unsigned int i=0;i<lenth;i++)
    {
        if(c[i]=='C') vis=1;
        if(c[i]=='F'&&vis==1) vis=2;
        if(vis==2) break; 
    }
    if(vis==2) cout<<"Yes";
    else cout<<"No";
}

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

using namespace std;
int main(){
  int x=0;
  int n;
  string s;
  cin>>n>>s;
  vector<int> v;
  v.push_back(0);
  for(int i=0;i<n;i++){
    if(s[i]=='I'){
      x++;
      v.push_back(x);
    }
    else{
      x--;
      v.push_back(x);
    }
  }
  sort(v.begin(),v.end());
  cout<<v[n]<<endl;
    
  
  
  return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	void run(){
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int s,g;
		while(n--!=0){
			s=sc.nextInt();
			g=sc.nextInt();
			//s<gだったら数え上げ　s>g数え下げ
			if(0<=s && s<=5){
				if(s<g){
					boolean f=true;
					for(int i=s;i<=g;i++){
						if(f){
							System.out.print(i);
							f=false;
						}
						else{
							System.out.print(" "+i);
						}
					}
					System.out.println();
				}
				else{
					boolean f=true;
					for(int i=s;g<=i;i--){
						if(f){
							System.out.print(i);
							f=false;
						}
						else{
							System.out.print(" "+i);
						}
					}
					System.out.println();
				}
			}//

			if(6<=s && s<=9){
				if(s<g){
					boolean f=true;
					for(int i=s;i<=g;i++){
						if(f){
							System.out.print(i);
							f=false;;
						}
						else{
							System.out.print(" "+i);
						}
					}
					System.out.println();
				}
				else{
					boolean f=true;
					for(int i=s;i<=9;i++){
						if(f){
							System.out.print(i);
							f=false;;
						}
						else{
							System.out.print(" "+i);
						}
					}
					for(int i=5;0<=i;i--){
						if(f){
							System.out.print(i);
							f=false;;
						}
						else{
							System.out.print(" "+i);
						}
						if(i==g) break;
					}
					if(5<g){
						for(int i=1;i<=g;i++){
							if(f){
								System.out.print(i);
								f=false;;
							}
							else{
								System.out.print(" "+i);							}
						}
					}
					System.out.println();
				}//else
			}
		}
	}
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 11000
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul, add
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()

if N%10 == 0:
	print(10)
else:
	print(reduce(add, map(int, list(str(N)))))


Measured memory_bytes: 5384
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <cstdio>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
using namespace std;
#define MOD 1000000007
#define rep(i,n) for(int i = 0; i < (n); ++i)
typedef long long ll;


int main(void) {
  int a, b;
  cin >> a >> b;
  if(a <= 8 && b <= 8) cout << "Yay!" << endl;
  else cout << ":(" << endl;

  return 0;
}


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

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


int main() {
    ll N,K; cin >> N >> K;
    vector<int> P(N);
    vector<ll> C(N);
    REP(i,N){
        cin >> P[i];
        P[i]--;
    }
    REP(i,N) cin >> C[i];


    
    ll ans = -LINF;

    REP(i,N){//全ての点を始点として考える
        ll loop_sum = 0;
        int pos = i;
        ll cnt = 0;

        REP(j,N){//ループの周期を求める cnt
            pos = P[pos];
            loop_sum += C[pos];
            if(i==pos){
                cnt = j+1;
                break;
            }
        }

        ll tmp = -LINF;
        ll sum = 0;
        pos = i;//1周して戻ってきてるけど一応

        if(K <= cnt){//Kが1周にみたないなら
            REP(j,K){
                pos = P[pos];
                sum += C[pos];
                tmp = max(tmp,sum);
            }

            ans = max(ans,tmp);

        }else{//1周以上できるなら

            if(loop_sum <= 0){//1周しても得がない場合は最初の1周だけかんがえればよい
                REP(j,cnt){
                    pos = P[pos];
                    sum += C[pos];
                    tmp = max(tmp,sum);
                }
                ans = max(ans, tmp);
            }else{//得する場合はガンガン回す →これは嘘で1とあまりを考える

                ll K2 = K%cnt+cnt;//周回後のあまり
                ll k = K/cnt-1;//何周できるか

                tmp = 0;//k周したあとは1回も動かなくても良いので
                REP(j,K2){
                    pos = P[pos];
                    sum += C[pos];
                    tmp = max(tmp,sum);
                }
                tmp += loop_sum*k;

                ans = max(ans, tmp);
            }
        }


    }
    cout << ans << endl;


    return 0;
}

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

#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define RFOR(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define LL long long
#define INF INT_MAX/3

const double EPS = 1e-14;
const double PI  = acos(-1.0);


int main(){
  int a, b, c;

  scanf("%d %d %d", &a, &b, &c);

  printf("%s\n", a + b >= c ? "Yes" : "No");
}


Measured memory_bytes: 256
//2019.7.22 by ljz
//email 573902690@qq.com
//if you find any bug in my code
//please tell me
#include<bits/stdc++.h>
using namespace std;
#define res register int
#define LL long long
#define inf 0x3f3f3f3f
#define INF 1e18+1e9
#define eps 1e-10
#define RG register
#define db double
#define lb long db
#define pc(x) __builtin_popcount(x)
typedef pair<int,int> Pair;
#define mp make_pair
#define fi first
#define se second
#define pi acos(-1.0)
#define pb push_back
#define gc getchar
#define Pi 2.0*acos(-1.0)
//inline char gc() {
//    static char buf[100000],*p1,*p2;
//    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
//}
inline int read() {
    res s=0,ch=gc();
    while(ch<'0'||ch>'9')ch=gc();
    while(ch>='0'&&ch<='9')s=s*10+ch-'0',ch=gc();
    return s;
}
//inline int read() {
//    res s=0,ch=gc(),w=1;
//    while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=gc();}
//    while(ch>='0'&&ch<='9')s=s*10+ch-'0',ch=gc();
//    return s*w;
//}
//inline LL Read() {
//    RG LL s=0;
//    res ch=gc();
//    while(ch<'0'||ch>'9')ch=gc();
//    while(ch>='0'&&ch<='9')s=s*10+ch-'0',ch=gc();
//    return s;
//}
//inline LL Read() {
//    RG LL s=0;
//    res ch=gc(),w=1;
//    while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=gc();}
//    while(ch>='0'&&ch<='9')s=s*10+ch-'0',ch=gc();
//    return s*w;
//}
//inline void write(RG __int128 x){
//    if(x>10)write(x/10);
//    putchar(x%10+'0');
//}
inline void swap(res &x,res &y) {
    x^=y^=x^=y;
}
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int kcz=998244353;
const int N=5e5+10;
namespace MAIN{
    inline void add(res &x,const res &y){
        x+=y,x>=kcz?x-=kcz:1;
    }
    inline int Add(const res &x,const res &y){
        return x+y>=kcz?x+y-kcz:x+y;
    }
    inline int mul(const res &x,const res &y){
        return int(1LL*x*y%kcz);
    }
    int n,m;
    int fac[N],inv[N];
    inline int C(const res &x,const res &y){
        return mul(fac[x],mul(inv[y],inv[x-y]));
    }
    inline int A(const res &x,const res &y){
        return mul(fac[x],inv[x-y]);
    }
    int pwn[N],pwm[N];
    int ans;
    inline void MAIN(){
        n=read(),m=read(),fac[0]=fac[1]=inv[0]=inv[1]=pwn[0]=pwm[0]=1;
        if(n>m)swap(n,m);
        for(res i=1;i<=m;i++)pwn[i]=mul(pwn[i-1],n+1),pwm[i]=mul(pwm[i-1],m+1);
        for(res i=2;i<=m;i++)fac[i]=mul(fac[i-1],i),inv[i]=mul(inv[kcz%i],kcz-kcz/i);
        for(res i=2;i<=m;i++)inv[i]=mul(inv[i-1],inv[i]);
        for(res i=0;i<=n;i++)add(ans,i&1?kcz-mul(mul(C(n,i),A(m,i)),mul(pwn[m-i],pwm[n-i])):mul(mul(C(n,i),A(m,i)),mul(pwn[m-i],pwm[n-i])));
        printf("%d\n",ans);
    }
}
int main(){
    MAIN::MAIN();
    return 0;
}

Measured memory_bytes: 8064
#include <iostream>
#include <sstream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>

#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type >

#define FOR(i, A, B) for(auto i = (A);i != (B); i++)
#define FORD(i, A, B) for(auto i = (A);i != (B); i--)

#define READRANGE(begin, end) FOR(it, begin, end) cin >> *it
#define READVEC(V) READRANGE(BEGIN(V), END(V))

using namespace std;

typedef long long lint;
typedef pair<int, int> Pii;
typedef pair<int, lint> Pil;
typedef pair<lint, lint> Pll;
typedef pair<lint, int> Pli;

void io_init()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
};

int main(int argc, char **argv)
{
    io_init();

    // Actual program code starts here.
    int a, b, h;
    cin >> a >> b >> h;
    cout << h / 2 * (a + b) << endl;
    return 0;
};


Measured memory_bytes: 256
//! 尺卂乃卂.卂ﾌ乇乇ㄒ
#include<bits/stdc++.h>
//#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
//Using namespace __gnu_pbds;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> Ordered_set;

#define ll              long long
#define int             long long
#define ld             long double
#define pb              push_back
#define pii             pair<int,int>
#define vi              vector<int>
#define vii             vector<vi>
#define vip            vector<pii>
#define mii             map<int,int>
#define mip             map<pair<int,int>,int>
#define mic             map<char,int> 
#define all(v)          v.begin(),v.end()  
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define lb(x)           (x&(-x))
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define w(x)            int x; cin>>x; while(x--)
#define itr(it,v)          for(auto it:v)
#define show(arr,n)     for(int i=0;i<n;i++) cout<<arr[i]<<" "; cout<<"\n";
#define fi(i,n)         for(int i=0;i<n;i++)
#define fir(i,k,n)       for(int i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ff               first 
#define ss               second
#define deb(x) cout << #x << "=" << x << endl
#define FIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define check(x) (x && cout<<"Yes\n")||(cout<<"No\n");
#define fin(s)          freopen(s,"r",stdin);  
#define fout(s)         freopen(s,"w",stdout);

const ld pi = 3.141592653589793238462643383279502884;
const int xd[]={-1,0,1,0};
const int yd[]={0,-1,0,1};
int XX[] = { -1, -1, -1, 0, 0, 1, 1, 1 };
int YY[] = { -1, 0,  1, -1, 1, -1, 0, 1 };

int expo(int a,int b,int m);
int mmi(int a,int m);
void ipgraph(int m);

const int N=5*(1e5)+10;
vii adj(N);
int a[N];

void  solve(){

}
int32_t main()
{
    FIO
    int n; cin>>n;
    int sum=0;
    fi(i,n) {
        cin>>a[i];  
        sum=(sum+a[i])%mod;
    }
    int res=0;
    fi(i,n){
        sum=(sum-a[i]+mod)%mod;
        res=(res+(a[i]*sum)%mod)%mod;
    }
    cout<<res<<"\n";
    return 0;

}

void ipgraph(int m){
    int i, u, v;
    while(m--){
          cin>>u>>v;
         u--, v--;
    adj[u].pb(v);
    adj[v].pb(u);
    }
}
int expo(int a,int b,int m){
    if(b==0) return 1;
    if(b==1) return a;
    int val=(expo(a,b/2,m)*expo(a,b/2,m))%m;
    if(b & 1) return (val*a)%m;
    else return val;
}
int mmi(int a,int m){
    return expo(a,m-2,m);
}

Measured memory_bytes: 16396
from math import factorial
N = int(input())
K = int(input())
S = list(map(int,str(N))) #桁数
ans = 0
digit = len(S)
k = K

def D(i,j): 
    if i >= j:
        return (9**j) * (factorial(i) // (factorial(i - j) * factorial(j)))
    else:
        return 0

if K > len(S):
    print(0)
    exit()

for i in range(digit):
    digit -= 1
    if int(S[i]) == 0:
        if K == len(S):
            print(0)
            exit()
        continue
    ans += D(digit,k)
    k -= 1
    if k == 0:
        ans += S[i]
        break
    ans += (int(S[i]-1))*D(digit,k)
print(ans)


Measured memory_bytes: 3064
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.ListIterator;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.TreeSet;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while(true){
			final String input = sc.next();
			
			if("0.0".equals(input)){
				break;
			}
			
			final double error = Double.parseDouble(input);
			
			final double upper_bound = Math.PI + error;
			final double lower_bound = Math.PI - error;
			
			for(int denom = 1; ; denom++){
				int lower = (int)(Math.ceil(lower_bound * denom));
				int upper = (int) (upper_bound * denom);
				
				final double denom_d = (double) denom;
				
				final double low_d = lower / denom_d;
				final double high_d = upper / denom_d;
				
				//System.out.println(denom + " " + low_d + " " + high_d);
				
				if(upper_bound >= low_d && low_d >= lower_bound){
					System.out.println(lower + "/" + denom);
					break;
				}else if(upper_bound >= high_d && high_d >= upper_bound){
					System.out.println(upper + "/" + denom);
					break;
				}
			}
			
		}
		
		sc.close();
	}

}

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

using namespace std;

typedef long long ll;

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

    for (int i = 0; i < K; i++) {
        if (B <= A) { B *= 2; }
        else if (C <= B) { C *= 2; }

        if (A < B && B < C) { 
            cout << "Yes" << endl;
            return 0;
        }
    }

    cout << "No" << endl;
}

Measured memory_bytes: 3628
def is_palindrome(string):
    for i in xrange(len(string) / 2):
        if string[i] != string[-1 - i]:
            return False
    return True


ret = 0
while 1:
    try:
        if is_palindrome(raw_input()):
            ret += 1
    except EOFError:
        break
print ret

Measured memory_bytes: 4204
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;

const int MAX = 1e5+5;
int n, d;

int main(int argc, char const **argv) {
	cin >> n;
	int x = 0;

	for (int i = 0 ; i < n ; i++) {
		cin >> d;
		x = x ^ d;
	}

	if (x == 0)
      cout << "Yes";
  	else
      cout << "No";

	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define INF 1e12

#define PB push_back
#define PF push_front
#define fi first
#define se second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vpi vector<pii>
#define vll vector<ll>
#define vpl vector<pll>
#define vvi vector<vector<int>>
#define vvl vector<vector<ll>>
#define mii map<int, int>
#define mci map<char, int>
#define MX(x) *max_element(all(x))
#define MN(x) *min_element(all(x))
#define ios ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define pr_d(x) cout << fixed << setprecision(15) << x << endl
#define ud(c, x) distance(c.begin(), upper_bound(all(c), x))
#define ld(c, x) distance(c.begin(), lower_bound(all(c), x))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define rep3(i, n) for (int i = (n - 1); i >= 0; --i)
#define rep4(i, a, b) for (int i = (a); i > (b); --i)
#define pb push_back
#define out(x) cout << x << "\n"
bool odd(int i) { return i % 2; }

#define all(v) v.begin(), v.end()
#define size(x) int(x.size())

int gcd(int a, int b) { return __gcd(a, b); }
int lcm(int a, int b) { return a * (b / gcd(a, b)); }
void Yes_No(bool f) {
  if (f)
    printf("Yes\n");
  else
    printf("No\n");
}
void YES_NO(bool f) {
  if (f)
    printf("YES\n");
  else
    printf("NO\n");
}

template <typename T>
void deb1(T x) {
  cout << "debug: " << x << "\n";
}

template <typename T>
bool chmax(T& a, const T& b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
bool chmin(T& a, const T& b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
//-------------------ここから回答する-----------------------

void solve(void) {
  int n;
  cin >> n;
  vi a(n);
  rep(i, n) cin >> a[i];
  ll l = 0, r = accumulate(all(a), 0), ans = INF;
  vll cusum(n + 1);
  cusum[0] = 0;
  rep(i, n) cusum[i + 1] += cusum[i] + a[i];
  rep2(i, 1, n) chmin(ans, abs(cusum[i] - (cusum[n] - cusum[i])));
  out(ans);
}
int main(void) { solve(); }

Measured memory_bytes: 5592
use std::io::*;
use std::str::FromStr;

fn main() {
    let n: usize = read();
    let a: usize = read();
    let b: usize = read();

    println!("{}", std::cmp::min(n*a, b));
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


Measured memory_bytes: 4352
h, w = map(int, input().split())
s = [list(input()) for i in range(h)]

delta = [[0, -1], [-1, 0], [1, 0], [0, 1]]
ans = 'Yes'
for y in range(h):
  for x in range(w):
    if s[y][x] == '#':
      for xd, yd in delta:
        if 0 <= x + xd < w and 0 <= y + yd < h and s[y + yd][x + xd] == '#':
          break
      else:
        ans = 'No'
        break

print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<string.h>
#include<map>
#include<set>
#define maxn 1000005
#define lson (now<<1)
#define rson ((now<<1)|1)
#define mid ((nl+nr)>>1)
using namespace std;
typedef long long ll;
int n;
int a[maxn];
int cnt[maxn];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]),cnt[a[i]]++;
	int ans=0;
	for(int i=1;i<=n;i++)
	{
		if(cnt[a[i]]>1) continue;
		int flag=1;
		if(a[i]==1)
		{
			ans++;
			continue;
		}
		for(int j=1;j*j<=a[i];j++)
		{
			if(a[i]%j==0)
			{
				if(cnt[j])
				{
					flag=0;
					break;
				}
				if(j!=1 && cnt[a[i]/j])
				{
					flag=0;
					break;
				}
			}
		}
		ans+=flag;
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 8376
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] A = new int[N+2];
		A[0] = 0;
		A[N+1] = 0;
		int max = 0;

		for(int i=1; i<N+1; i++) {
			A[i] = sc.nextInt();
			max += Math.abs(A[i] - A[i-1]);
		}
		max += Math.abs(A[N]);
		//System.out.println(max);
		for(int k=1; k<N+1; k++) {
			System.out.println(max-Math.abs(A[k]-A[k-1])
					-Math.abs(A[k+1]-A[k])
					+Math.abs(A[k+1]-A[k-1]));
		}

	}

}


Measured memory_bytes: 62164
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
bool dp[100001];
int A[101];
int main()
{
//  freopen("in.txt", "r", stdin);
//  freopen("out.txt", "w", stdout);
  int n, k;
  cin >> n >> k;
  for(int i = 0;i < n;i++){
    cin >> A[i];
  }

  for(int i = A[0];i <= k;i++){
    for(int j = 0;j < n;j++){
      if(i - A[j] < 0)break;
      dp[i] |= !dp[i - A[j]];
    }
  }
  cout << (dp[k] ? "First" : "Second");
  return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#include<random>
using namespace std;
using ll=long long;
using ld=long double;
using P=pair<ll,ll>;
#define MOD 1000000007LL
#define INF 1000000000ll
#define EPS 1e-10
#define FOR(i,n,m) for(ll i=n;i<(ll)m;i++)
#define REP(i,n) FOR(i,0,n)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define ALL(v) v.begin(),v.end()
#define UNIQUE(v) sort(ALL(v));v.erase(unique(ALL(v)),v.end());
#define pb push_back

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll N, Q;
	cin >> N >> Q;
	vector<ll> a(N);
	REP(i,N) cin >> a[i];
	REP(i,N) a[i]--;
	vector<P> list(N);
	REP(i,N) {
		if(i == 0) list[a[i]].first = a[N - 1];
		else list[a[i]].first = a[i - 1];
		if(i == N - 1) list[a[i]].second = a[0];
		else list[a[i]].second = a[i + 1];
	}
	ll last = a[N - 1];
	REP(i,Q) {
		ll q;
		cin >> q;
		q--;
		if(q == last) {
			last = list[q].first;
		} else if(q == list[last].second) {
			last = q;
		} else {
			ll nlast = list[q].first;
			ll tmps = list[q].second;
			list[q].first = last;
			list[q].second = list[last].second;
			list[list[last].second].first = q;
			list[last].second = q;
			list[nlast].second = tmps;
			list[tmps].first = nlast;
			last = nlast;
		}

	}
	vector<ll> b(N);
	ll pos = list[last].second;
	REP(i,N) {
		b[i] = pos + 1;
		pos = list[pos].second;
	}
	DUMP(b);
	return 0;
}




Measured memory_bytes: 6012
#include <iostream>
#include <fstream>
#include <typeinfo>
#include <vector>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-6;
const ll mod=1e9+7;
const vi emp;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,-0};
const int DX[8]={-1,-1,-1,0,0,1,1,1},DY[8]={1,0,-1,1,-1,1,0,-1};

ll f(ll b,ll n){
	if(n<b) return n;
	return f(b,floor((double)n/b))+n%b;
}

ll n,s;

int main(){
	cout<<syosu(15);
	cin>>n>>s;
	ll ans=-1;
	for(int i=1e6;i>1;i--) if(f(i,n)==s) ans=i;
	if(ans!=-1){
		cout<<ans<<endl;
		return 0;
	}
	ll I=n;
	double dn=n;
	for(int i=1;i<1e6;i++){
		ll bs=ceil(dn/i+0.01),bt=I+1;
		I=bs-1;
		if(bs<=1) break;
		while(bt-bs>1){
			ll m=(bs+bt)/2,fm=f(m,n);
			if(fm<s) bt=m;
			else bs=m;
		}
		if(f(bs,n)==s) ans=bs;
	}
	if(ans==-1&&n==s) ans=n+1;
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair <int, int>
#define pll pair <ll, ll>
#define pci pair <char, int>
#define pld pair <ld, ld>
#define ppld pair <pld, pld>
#define ppll pair <pll, pll>
#define pldl pair <ld, ll>
#define vll vector <ll>
#define vvll vector <vll>
#define vpll vector <pll>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define mll map <ll, ll>
#define fastmap gp_hash_table
#define cd complex <double>
#define vcd vector <cd>
#define PI 3.14159265358979
#define ordered_set tree <ll, null_type, less <ll>, rb_tree_tag, tree_order_statistics_node_update>
#pragma 03
using namespace std;
using namespace __gnu_pbds;
ll a[1000005];
int main(){
	fastio;
	ll n, m; cin >> n >> m;
	for (ll i = 0; i < m; i++){
		ll ip; cin >> ip; n -= ip;
	}
	if (n < 0) cout << -1 << endl;
	else cout << n << endl;
}

Measured memory_bytes: 3640
#include <stdio.h>

int binarySearch(int);

int n;
int count=0;
int S[100000], T[50000];

int main(){
  int i;
  int q;
  
  //Sのデータの入力
  scanf("%d", &n);
  for( i=0 ; i<n ; i++){
    scanf("%d", &S[i]);
  }
  
  //Tのデータの入力&探索
  scanf("%d", &q);
  for( i=0 ; i<q ; i++){
    scanf("%d", &T[i]);
    if(binarySearch(T[i]) == 1){
      count++;
    }
  }
  printf("%d\n",count);
  return 0;
}

int binarySearch(int key){
  int left, right, mid;
  
  left = 0;
  right = n;
  
  while(left < right){
    mid = (left + right) / 2;
    if(S[mid] == key){
      return 1;
    }else if(key < S[mid]){
      right = mid;
    }else{
      left = mid + 1;
    }
  }
  return 0;
}



Measured memory_bytes: 2384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int Inf = 1000000001;
constexpr ll INF= 1e18;
constexpr ll MOD = 998244353;
const double PI = 3.1415926535897;
typedef pair<ll,ll> P;

int main() {
    int N,A;
    cin >> N >> A;
    if(N % 500 <= A) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}

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

#define out(t) cout << (t) << "\n"

using namespace std;

typedef long long ll;
typedef unsigned int uint;

void swap(int &a, int &b) {
    a ^= b;
    b ^= a;
    a ^= b;
}

uint tzcnt(uint x) {
    x = ~x & (x - 1);
    x -= x >> 1 & 0x55555555;
    x = (x & 0x33333333) + (x >> 2 & 0x33333333);
    x = x + (x >> 4) & 0x0F0F0F0F;
    return x * 0x01010101 >> 24;
}

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

    int n;
    cin >> n;

    int res = 100000000;
    for (int i = 0; i < n; i++) {
        uint x;
        cin >> x;

        res = min((int)tzcnt(x), res);
    }

    out(res);

    int ttttttt;
    cin >> ttttttt;
}

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

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

typedef unsigned int uint;

int getInt(){
  int ret = 0,c;
  c = getchar();
  while(!isdigit(c)) c = getchar();
  while(isdigit(c)){
    ret *= 10;
    ret += c - '0';
    c = getchar();
  }
  return ret;
}

#define MOD 100000

int n,m,s;

int memo[50][3001];

int main(){
  int i,j,k,x,y;
  while(1){
    n = getInt();
    m = getInt();
    s = getInt();

    if(n+m+s == 0) break;

    REP(i,n*n) REP(j,s+1) memo[i][j] = 0;

    rep(i,1,m+1){
      for(j=n*n-2; j>=0; j--){
	for(k=1; k<s; k++){
	  if(!memo[j][k]) continue;
	  if(k+i > s) break;
	  memo[j+1][i+k] = (memo[j+1][i+k] + memo[j][k]) % MOD;
	}
      }
      memo[0][i] = 1;
    }

    printf("%d\n",memo[n*n-1][s]);
  }
  return 0;
}

Measured memory_bytes: 936
import java.io.{BufferedOutputStream, BufferedReader, InputStreamReader, PrintWriter}

import scala.annotation.tailrec

object Main {
  def main(args: Array[String]): Unit = {
    val in = new BufferedReader(new InputStreamReader(System.in))
    val out = new PrintWriter(new BufferedOutputStream(System.out))
    val (n, k) = in.readLine().split("\\s+") match {
      case Array(n, k) => (n.toInt, k.toLong)
    }

    val abs = List.fill(n)(
      in.readLine().split("\\s+").map(_.toInt) match {
        case Array(a, b) => (a, b)
      }
    ).sortBy(_._1)

    @tailrec
    def find(k: Long, abs: List[(Int, Int)]): Int = {
      val (a, b) = abs.head
      if (k <= b) {
        a
      } else {
        find(k - b, abs.tail)
      }
    }

    out.println(find(k, abs))

    out.flush()
  }
}


Measured memory_bytes: 86208
import math

n = int(input())


def ts(x):
    return x * (x + 1)


m = n
for i in range(math.ceil(math.sqrt(2 * n) - 2), math.floor(math.sqrt(2 * n)) + 1, 1):
    if ts(i) < 2 * n <= ts(i + 1):
        m = i + 1
        break



if m % 2 == 0:
    a = n % (m + 1)
    b = n // (m + 1)
    if a != 0:
        print(a)
    i = 1
    c = 0
    while c != b:
        if i != a and m + 1 - i != a:
            print(i)
            print(m + 1 - i)
            c += 1
        i += 1
else:
    """
  check=[]
  if a!=0:
      check.append(a)
  i = 1
  c = 0
  while c!=b and i<(m+1)//2:
      if i!=a and m+1-i!=a:
          check.append(i)
          check.append(m+1-i)
          c+=1
      i+=1
  if c==b:
      for i in check:
          print(i)
  else:

      n-=(m+1)//2
      a = n % (m + 1)
      b = n // (m + 1)
      if m % 2 == 0:
          if a != 0:
              print(a)
          i = 1
          c = 0
          while c != b:
              if i != a and m + 1 - i != a:
                  print(i)
                  print(m + 1 - i)
                  c += 1
      """
    print(m)
    n -= m
    m -= 1

    a = n % (m + 1)
    b = n // (m + 1)
    if a != 0:
        print(a)
    i = 1
    c = 0
    while c != b:
        if i != a and m + 1 - i != a:
            print(i)
            print(m + 1 - i)
            c += 1
        i += 1

Measured memory_bytes: 9248
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
//'A' = 65, 'a' = 97

int main()
{
    int n, m, l;
    cin >> n >> m >> l;
    int A[n][m], B[m][l];
    rep(i, 0, n) {
        rep(j, 0, m) {
            cin >> A[i][j];
        }
    }
    rep(i, 0, m) {
        rep(j, 0, l) {
            cin >> B[i][j];
        }
    }

    ll C[n][l] = {};
    rep(i, 0, l) {
        rep(j, 0, n) {
            rep(k, 0, m) {
                C[j][i] += A[j][k] * B[k][i];
            }
        }
    }

    rep(i, 0, n) {
        rep(j, 0, l) {
            if (j == l - 1) cout << C[i][j];
            else cout << C[i][j] << " ";
        }
        cout << endl;
    }

    return 0;

}



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

int main() {
	int n, m, x, y;
	cin >> n >> m >> x >> y;
	for(int i = 0; i < n; i++) {
		int x_t;
		cin >> x_t;
		if(x < x_t) {
			x = x_t;
		}
	}
	for(int i = 0; i < m; i++) {
		int y_t;
		cin >> y_t;
		if(y > y_t) {
			y = y_t;
		}
	}
	if(x < y) {
		cout << "No War" << endl;
	} else {
		cout << "War" << endl;
	}
	return 0;
}


Measured memory_bytes: 256