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

int row[300010], col[300010];
int X[300010], Y[300010];
int vr[300010], vc[300010];
vector <int> R, C;
int maxr = -1, maxc = -1;

int main () {
	int n, m, k; scanf("%d%d%d", &n, &m, &k);
	for (int i = 0; i < k; i++) {
		int x, y; scanf("%d%d", &x, &y);
		row[x]++, col[y]++;
		X[i] = x, Y[i] = y;
	}
	for (int i = 1; i <= n; i++) {
		if (row[i] > maxr) maxr = row[i], R.clear(), R.push_back(i);
		else if (row[i] == maxr) R.push_back(i);
	}
	for (int i = 1; i <= m; i++) {
		if (col[i] > maxc) maxc = col[i], C.clear(), C.push_back(i);
		else if (col[i] == maxc) C.push_back(i);
	}
	for (int i = 0; i < R.size(); i++) {
		vr[R[i]] = 1;
	}
	for (int i = 0; i < C.size(); i++) {
		vc[C[i]] = 1;
	}
	int cnt = 0;
	for (int i = 0; i < k; i++) {
		if (vr[X[i]] && vc[Y[i]]) cnt++;
	}
	if (cnt == R.size() * C.size()) printf("%d\n", maxr + maxc - 1);
	else printf("%d\n", maxr + maxc);
	return 0;
}


Measured memory_bytes: 12760
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
ans = sum(B)
for i in range(N-1):
    if A[i+1]-A[i] == 1:
        ans += C[A[i]-1]
print(ans)

Measured memory_bytes: 3064
#include<string>
#include<iostream>
#include <algorithm>
#include<vector>
#include<functional>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#define ll long long
using namespace std;



int main(){
  string S;
  cin>>S;
  sort(S.begin(),S.end());
  if(S[0]==S[1]&&S[1]!=S[2]&&S[2]==S[3]) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;

  return 0;
}



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

main() {
  int N,A,R,X=0;
  cin >> N;
  A=N;
  
  for (int i=8; i>0; i--) {
    int Y=1;
    for (int j=0; j<i; j++) {
      Y*=10;
    }
    X +=A/Y;
    A %= Y;
  }
  X += A;
  R = N%X;
  if (R==0)
    cout << "Yes" << endl;
  
  else 
    cout << "No" << endl;   
} 

Measured memory_bytes: 256
q,o,x,b;
main(a){
  for(scanf("%d");~scanf("%s",&a)&&(a%=9);o=o==3?b=x=!printf("%d\n",x):o){
    for(a-8?b=b*2+1,x+=b>>3&1,b&=7:o++;a<7&&b;b/=2)x+=b&1;
    //if(a%9==6)for(x++,b&=7;b;b/=2)x+=b&1;
  }
}

Measured memory_bytes: 0
using System;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                string ui = Console.ReadLine();
                if (ui == null) { break;
                }
                string[] a = ui.Split();
                Stack<double> stack = new Stack<double> { };
                for (int i = 0; i < a.Length; i++)
                {
                    if (a[i] == "+")
                    {
                        double a2 = stack.Pop();
                        double a1 = stack.Pop();
                        stack.Push(a1 + a2);
                    }
                  else  if (a[i] == "-")
                    {
                        double a2 = stack.Pop();
                        double a1 = stack.Pop();
                        stack.Push(a1 - a2);
                    }
                    else if (a[i] == "*")
                    {
                        double a2 = stack.Pop();
                        double a1 = stack.Pop();
                        stack.Push(a1 * a2);
                    }
                   else if (a[i] == "/")
                    {
                        double a2 = stack.Pop();
                        double a1 = stack.Pop();
                        stack.Push(a1 / (double)a2);
                    }
                    else { stack.Push(double.Parse(a[i])); }
                }
                Console.WriteLine(stack.Pop());

            }Console.ReadLine();
        }
    }
}

Measured memory_bytes: 10120
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repp(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define rrep(i, n, m) for (int i = n; i >= m; i--)

template <class T>
bool contain(const std::string &s, const T &v)
{
    return s.find(v) != std::string::npos;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,M,a,b;
    unordered_map<int, bool> mp1,mpN;
    cin >> N >> M;
    cout<<(N-1)*(M-1)<<endl;
}


Measured memory_bytes: 256
import java.lang.*;
import java.io.*;
import java.util.*;

class Main{
	public static void main(String args[]) throws FileNotFoundException{
		FScanner sc=new FScanner();
		//Scanner sc=new Scanner(System.in);
		int[] arg=sc.readIntL();
		int a=arg[0];
		int b=arg[1];
		int c=arg[2];
		int a2=a*10;
		int b2=b*10;
		int c2=c*10;
		
		int m=0;
		
		if(a2+b+c>m){
			m=a2+b+c;
		}
		if(b2+a+c>m){
			m=b2+a+c;
		}
		if(c2+a+b>m){
			m=c2+a+b;
		}
		
		System.out.println(m);
	}
	
	static void solve(int cur, int nx, int en, int hld){}

	static void disp(int[] data){
		for(int i=0; i<data.length; i++){
				System.out.printf("%d ",data[i]);
		}
			System.out.println();
	}
	
	static void disp(String[] data){
		for(int i=0; i<data.length; i++){
				System.out.printf("%s ",data[i]);
		}
			System.out.println();
	}
	
	static void disp(long[] data){
		for(int i=0; i<data.length; i++){
				System.out.printf("%d ",data[i]);
		}
			System.out.println();
	}
	
	static class FScanner{
		BufferedReader read=null;
		StringTokenizer tok=null;
		Scanner sc;
		FScanner() throws FileNotFoundException{
			sc=new Scanner(System.in);
		}
		boolean hasNextLine(){
			boolean has=true;
			if(!sc.hasNextLine()){
				has=false;
			}
			return has;
		}
		int readInt(){
			String buf=sc.nextLine();
			return Integer.parseInt(buf);
		}
		long readLong(){
			long i=Long.parseLong(sc.nextLine());
			return i;
		}
		int[] readIntL(){
			String[] buf=sc.nextLine().split(" ");
			int[] num=new int[buf.length];
			for(int i=0; i<buf.length; i++){
				num[i]=Integer.parseInt(buf[i]);
			}
			return num;
		}
		
		String readString(){
			return sc.nextLine();
		}
		String[] readStringL(String dlm){
			String[] s=sc.nextLine().split(dlm);
			return s;
		}
	}
}


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

using namespace std;

mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
typedef long long ll;
typedef long double ld;

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  ld a, b;
  cin >> a >> b;
  a *= b;
  cout << fixed << setprecision(0) << a << "\n";
  return 0;
}


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

class Cube{
 public:
 int f[6];
 Cube(){}
  void roll_z(){roll(1,2,4,3);} //
  void roll_y(){roll(0,2,5,3);} // to W
  void roll_x(){roll(0,1,5,4);} // to N
  void roll( int i, int j, int k, int l){
   int t = f[i]; f[i]=f[j]; f[j]=f[k]; f[k]=f[l]; f[l]=t;
  }
};

bool eq(Cube c1, Cube c2){
  for(int i = 0; i < 6; i++)
      if (c1.f[i] != c2.f[i]) return false;
  return true;
}

bool equal (  Cube c1, Cube c2 ){
    for (int i=0; i < 6; i++){
        for (int j=0; j < 4; j++){
          if ( eq( c1, c2) ) return true;
             c1.roll_z();
          }
          if (i % 2 == 0 ) c1. roll_y();
          else c1.roll_x();
    }
    return false;
}
Cube C[100]; int n;

bool check(){
     for  (int i = 0; i < n-1;i++)
            for (int j=i+1; j < n; j++) if (equal(C[i], C[j])) return false;
    return true;
}

int main(){
   cin >> n;

for (int j = 0; j <n; j++) 
for (int i = 0; i <6; i++) cin >> C[j]. f[i];

if  (check () ) cout << "Yes" << endl;
else cout << "No" << endl;

return 0;
}


Measured memory_bytes: 3096
import java.util.*;
 
public class Main {
    private static final Scanner scn = new Scanner(System.in);
     
    public static void main(String[] args) {
        int a = scn.nextInt(), b = scn.nextInt(), c = scn.nextInt(), x = 0;
        while(a <= b) {
            if(c % a == 0) {
                x++;
            }
            a++;
        }
        System.out.println(x);
    }
}

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

signed main() {
  int n, q; cin >> n >> q;
  string s; cin >> s;
  vector<int> sum(n+1, 0);

  // 累積和を用意
  //0 1 2 3 4 5 6 7 8
  // A C C A A A C A
  // 0 1 2 3 4 5 6 7
  for(int i = 1; i < n; i++) {
    sum[i+1] = sum[i];
    if(s[i-1]=='A' && s[i]=='C') sum[i+1]++;
  }
  for(int i = 0; i < q; i++) {
    int l, r; cin >> l >> r;
    cout << sum[r] - sum[l] << endl;
  }
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define sz(a) (a.size())
#define int long long
#define SYNC ios_base::sync_with_stdio(false), cin.tie(NULL);
#define all(c) c.begin(), c.end()
#define pb push_back
#define F first
#define S second
#define present(c, x) ((c).find(x) != (c).end())
#define cpresent(c, x) (find(all(c), x) != (c).end())
#define endl "\n"
#define bitcnt(n) __builtin_popcountll(n)
#define debug(x) cout << #x << " = " << x << endl;
#define debug2(x, y) cout << #x << " = " << x << " , " << #y << " = " << y << endl;
#define debug3(x, y, z) cout << #x << " = " << x << " , " << #y << " = " << y << " , " << #z << " = " << z << endl;
const int M = 1000000007;
const int N = 1e9 + 1;

signed main()
{
    int a, h;
    cin>>h>>a;
    if(h%a==0)
        cout<<h/a<<endl;
    else cout<<h/a + 1<<endl;


}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    static Scanner sc = new Scanner(System.in);


    public static void main(String[] args) {
        int n = sc.nextInt();
        int[] a = new int[n + 1];
        for (int i = 1; i < n + 1; i++) {
            a[i] = sc.nextInt();
        }
        int slow = a[1];
        boolean[] checked = new boolean[n + 1];
        int count = 1;
        while (!checked[slow]) {
            if (slow == 2) {
                System.out.println(count);
                return;
            }
            count++;
            checked[slow] = true;
            slow = a[slow];
        }
        System.out.println(-1);
    }
}


Measured memory_bytes: 51080
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = int64_t;
using P = pair<ll, ll>;
template <class T>
using V = vector<T>;

int main() {
  int n, k;
  cin >> n >> k;
  set<char> d;
  for (int c = '0'; c <= '9'; c++) d.insert(c);
  rep(i, k) {
    char tmp;
    cin >> tmp;
    d.erase(tmp);
  }

  auto is_ok = [&](int n) {
    string s = to_string(n);
    int l = s.length();
    bool ret = true;
    rep(i, l) {
      if (d.count(s[i]) == 0) ret = false;
    }
    return ret;
  };

  int ans = n;
  while (true) {
    if (is_ok(ans)) break;
    ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 3668
#include <stdio.h>

int main() {
	int fib[45], i, n;

	fib[0] = 1;
	fib[1] = 1;

	scanf("%d", &n);

	for (i = 2;i <= n;i++)
		fib[i] = fib[i - 1] + fib[i - 2];

	printf("%d\n", fib[n]);

	return 0;
}


Measured memory_bytes: 2120
#include <limits.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <math.h>

#define もし if(
#define そうでなくてもし }else if(
#define ならば ){
#define そうでないならば }else{
#define を実行する }

#define 文字列を読み込む(s) scanf("%s", s)
#define 整数を読み込む(x) int x; scanf("%d", &x)
#define 文字を読み込む(c) char c; scanf(" %c", &c)

#define 文字列を書き出す(s) printf("%s", (s))
#define 文字を書き出す(c) printf("%c", (c))
#define 改行する putchar(10)

#define 文字列の長さ(s) (strlen(s))

typedef int 整数;
typedef char 文字;

int main(void){
	文字 s[500001];
	文字列を読み込む(s+200000);
	整数 l=200000, r=200000+文字列の長さ(s+200000);
	整数 f=1;

	整数 i;
	整数を読み込む(q);
	for(i=0; i<q; i++){
		整数 Q;
		scanf("%d", &Q);
		もし Q==1 ならば
			f=(f==1?2:1);
		そうでないならば
			整数を読み込む(F);
			文字を読み込む(c);
			もし F==f ならば
				s[--l]=c;
			そうでないならば
				s[r++]=c;
			を実行する
		を実行する
	}
	もし f==1 ならば
		s[r]=0;
		文字列を書き出す(s+l);
		改行する;
	そうでないならば
		for(i=r-1; i>=l; i--){
			文字を書き出す(s[i]);
		}
		改行する;
	を実行する
}



Measured memory_bytes: 768
import java.util.*;

class Main{
	
	public static void main(String args[]){

		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();

		int num = 55555;
		ArrayList<Integer> prime = new ArrayList<>();
		prime.add(2);

		boolean isPrime = false;
		for (int i = 5; i <= num; i += 2) {

            for (int j = 2; j * j <= i; j++) {
                if (i % j == 0) {
                    isPrime = false;
                    break;
                }
                isPrime = true;
            }
            if (isPrime) {
            	if(i%5 == 1)
                prime.add(i);
            }
        }

        int ans[] = new int[N];

        for(int n=0;n<N;n++){
        	ans[n] = prime.get(n);
        }


        for(int a : ans){
        	System.out.print(a +" ");
        }
        System.out.println();
	}
}

Measured memory_bytes: 21716
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<string>
#include<cmath>
#define ll long long
#define INF 0x3f3f3f3f
#define N 100005
using namespace std;

struct node{
	int t,x,y;
	bool operator<(node a){
		return t<a.t;
	}
}a[N];

int main()
{
	ll n,t,x,y;
	bool flag=true;
	cin>>n;
	a[0].t=a[0].x=a[0].y=0;
	for(int i=1;i<=n;i++){
		cin>>a[i].t>>a[i].x>>a[i].y;
	}
//	sort(a+1,a+n+1);
	for(int i=1;i<=n;i++){
		int lenx=a[i].x-a[i-1].x;
		if(lenx<0) lenx=-lenx;
		int leny=a[i].y-a[i-1].y;
		if(leny<0) leny=-leny;
		int len=lenx+leny;
		int dt=a[i].t-a[i-1].t;
		if(dt<len){
			flag=false;
			break;
		}
		if(len&1){
			if(dt%2==0){
				flag=false;
				break;
			}
		}else{
			if(dt&1){
				flag=false;
				break;
			}
		}
	}
	if(flag)
	puts("Yes");
	else puts("No");
	return 0;
}

Measured memory_bytes: 1408
#[allow(unused_imports)]
use itertools::Itertools;
#[allow(unused_imports)]
use num::*;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
#[allow(unused_imports)]
use std::collections::*;

pub fn bsearch<F>(ok: i64, ng: i64, pred: F) -> Option<i64>
where
    F: Fn(i64) -> bool,
{
    let orig_ok = ok;
    let mut ok = ok;
    let mut ng = ng;
    while (ok - ng).abs() > 1 {
        let mid = (ok + ng) / 2;
        if pred(mid) {
            ok = mid;
        } else {
            ng = mid;
        }
    }
    if ok == orig_ok {
        None
    } else {
        Some(ok)
    }
}

fn solve() {
    input! {
        h: usize, w: usize, k: usize,
        grid: [Chars; h]
    };

    let mut cusum = vec![vec![0; w + 1]; h + 1];
    for i in 0..h {
        for j in 0..w {
            let c = if grid[i][j] == '1' { 1 } else { 0 } + cusum[i + 1][j] + cusum[i][j + 1]
                - cusum[i][j];
            cusum[i + 1][j + 1] = c;
        }
    }

    let mut res = std::usize::MAX;
    for h_bits in 0..1 << (h - 1) {
        let mut range = Vec::new();
        let mut s = 0;
        for i in 0..(h - 1) {
            if (h_bits >> i) & 1 == 1 {
                range.push((s, i));
                s = i + 1;
            }
        }
        range.push((s, h - 1));
        let mut count = range.len() - 1;
        let mut l = 0;
        while l < w {
            let j = bsearch(l as i64 - 1, w as i64, |x| {
                let j = x as usize;
                range.iter().all(|&(s, e)| {
                    let c = cusum[e + 1][j + 1] + cusum[s][l] - cusum[e + 1][l] - cusum[s][j + 1];
                    c <= k
                })
            });
            if let Some(j) = j {
                l = j as usize + 1;
                if l < w {
                    count += 1;
                }
            } else {
                count = std::usize::MAX;
                break;
            }
        }
        if count < res {
            res = count;
        }
    }
    println!("{}", res);
}

fn main() {
    std::thread::Builder::new()
        .name("big stack size".into())
        .stack_size(256 * 1024 * 1024)
        .spawn(|| {
            solve();
        })
        .unwrap()
        .join()
        .unwrap();
}


Measured memory_bytes: 2396
import sys
input = sys.stdin.buffer.readline

def main():
    N = int(input())
    a = list(map(int,input().split()))
    
    bit = 0
    r = 0
    ans = 0
    for l in range(N):
        while r < N:
            num = a[r]
            if num & bit == 0:
                bit += num
                r += 1
            else:
                num = a[l]
                bit -= num
                break
            ans += r-l
    
    print(ans)
    
if __name__ == "__main__":
    main()


Measured memory_bytes: 20400
import java.util.*;
import java.io.*;
import java.math.*;
 
 
import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
 
public class Main{
    static final long mod=1000000007;
    
    public  static void main(String[] args)   throws Exception, IOException{
        Reader sc = new Reader(System.in);
        PrintWriter out=new PrintWriter(System.out);
        // int n=sc.nextInt();
        // char c[][] = new char[h][w];
        // char c[]=sc.nextString().toCharArray();
        // for(int i=0; i<n; i++) {d[i]=sc.nextInt();}
        int n=sc.nextInt();

        int a[] = new int[n];
        int b[] = new int[n];
        
        for(int i=0; i<n; i++) {
            a[i] = sc.nextInt();
        }
        for(int i=0; i<n; i++) {
            b[i] = sc.nextInt();
        }
   
        int c[] = new int[n];
        int ans=0;
        for(int i=0; i<29; i++) {

            int md = (1<<(i+1));
            for(int t=0; t<n; t++) {
                c[t] = b[t]&(md-1);
            }

            sort(c);
            int bit=0;

            for(int t=0; t<n; t++){ 
                int  at=a[t]%md, l = -at + (1<<i), r = -at + (1<<(i+1));

                l=lb(c,l);
                r=lb(c,r)-1;
                if(l<n)bit^=(r-l+1)%2;

                l = -at + (3<<(i)); r = -at + (1<<(i+2));
                l=lb(c,l);
                r=lb(c,r)-1;

                if(l<n)bit^=(r-l+1)%2;
            }
            ans^=bit<<i;
        }

        out.println(ans);
        out.flush();
    }

    static int lb(int[] a, int x) {
        int l = -1, r = a.length;
        while (r-l > 1) {
            int md = (l+r)/2;
            if (a[md] < x) {
                l = md;
            } else {
                r = md;
            }
        }
        return r;
    }

    static void db(Object... os){
        System.err.println(Arrays.deepToString(os));
    }
     
    static boolean validpos(int x,int y,int r, int c){
        return x<r && 0<=x && y<c && 0<=y;
    }
    
    static boolean bit(long x,int k){
        // weather k-th bit (from right) be one or zero
        return  ( 0 < ( (x>>k) & 1 )  )  ? true:false;
    }    
}

class P implements Comparable<P>{
        int id, d;
        P(int  id, int d) {
            this.id=id;
            this.d=d;
        } 
          
        public int compareTo(P p){
            return d-p.d; //descend
        }
    }

class Reader
{ 
    private BufferedReader x;
    private StringTokenizer st;
    
    public Reader(InputStream in)
    {
        x = new BufferedReader(new InputStreamReader(in));
        st = null;
    }
    public String nextString() throws IOException
    {
        while( st==null || !st.hasMoreTokens() )
            st = new StringTokenizer(x.readLine());
        return st.nextToken();
    }
    public int nextInt() throws IOException
    {
        return Integer.parseInt(nextString());
    }
    public long nextLong() throws IOException
    {
        return Long.parseLong(nextString());
    }
    public double nextDouble() throws IOException
    {
        return Double.parseDouble(nextString());
    }
}

Measured memory_bytes: 55776
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <algorithm>

using namespace std;

class inverse {
    public:
    inverse(int n, int mod);
    ~inverse();
    long long get_inv(int x);
    long long get_fact(int x);
    long long get_invfact(int x);
    long long get_comb(int x, int y);
    
    private:
    int mod;
    long long* inv;
    long long* fact;
    long long* invfact;
};

inverse::inverse(int n, int mod) : mod(mod) {
    inv = (long long *)malloc(sizeof(long long) * (n + 1));
    fact = (long long *)malloc(sizeof(long long) * (n + 1));
    invfact = (long long *)malloc(sizeof(long long) * (n + 1));
    inv[1] = 1;
    for (int i = 2; i <= n; i++) inv[i] = inv[mod % i] * (mod - mod / i) % mod;
    fact[0] = invfact[0] = 1;
    for (int i = 1; i <= n; i++) fact[i] = fact[i - 1] * i % mod;
    for (int i = 1; i <= n; i++) invfact[i] = invfact[i - 1] * inv[i] % mod;
}

inverse::~inverse() {
    free(inv);
    free(fact);
    free(invfact);
}

long long inverse::get_inv(int x) {
    return inv[x];
}

long long inverse::get_fact(int x) {
    return fact[x];
}

long long inverse::get_invfact(int x) {
    return invfact[x];
}

long long inverse::get_comb(int x, int y) {
    return fact[x] * invfact[y] % mod * invfact[x - y] % mod;
}

const int mod = 1000000007;
vector <int> v[3002];
long long dp[3002][2];

int main() {
    int h, w, n, i, j;
    long long ans;
    vector <pair<int, int>> z;
    
    scanf("%d %d %d", &h, &w, &n);
    
    for (i = 0; i < n; i++) {
        int r, c;
        
        scanf("%d %d", &r, &c);
        
        z.push_back(make_pair(r - 1, c - 1));
    }
    
    z.push_back(make_pair(0, 0));
    z.push_back(make_pair(h - 1, w - 1));
    
    sort(z.begin(), z.end());
    
    for (i = 0; i < z.size(); i++) {
        for (j = i + 1; j < z.size(); j++) {
            if (z[i].second <= z[j].second) v[j].push_back(i);
        }
    }
    
    inverse inv(h + w, mod);
    
    dp[0][1] = 1;
    
    for (i = 0; i < z.size(); i++) {
        int r1 = z[i].first;
        int c1 = z[i].second;
        
        for (j = 0; j < v[i].size(); j++) {
            int r2 = z[v[i][j]].first;
            int c2 = z[v[i][j]].second;
            long long x = inv.get_comb(r1 + c1 - r2 - c2, r1 - r2);
            
            dp[i][0] = (dp[i][0] + dp[v[i][j]][1] * x) % mod;
            dp[i][1] = (dp[i][1] + dp[v[i][j]][0] * x) % mod;
        }
    }
    
    ans = dp[n + 1][0] - dp[n + 1][1];
    while (ans < 0) ans += mod;
    while (ans >= mod) ans -= mod;
    
    printf("%lld\n", ans);
    
    return 0;
}


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

int main(){
    int a, b;
    cin >> a >> b;
    int c = 0;
    rep(i,1e8) c++;
    cout << max(a+b,max(a-b,a*b));
    return 0;
}

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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
	long long n,k;
	cin>>n>>k;
	long double temp=log(n)/log(k);
	//cout<<temp<<endl;
	long long ans=floor(temp)+1;
	cout<<ans<<"\n";
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define inf 1e9
int main()
{
    int n;cin>>n;vector<int>h(n+1);for(int i=1;i<=n;i++)cin>>h[i];
    vector<int>dp(n+1,inf);dp[1]=0;
    for(int i=2;i<=n;i++)
    {
        if(i==2)dp[i]=dp[i-1]+abs(h[i]-h[i-1]);
        else 
        dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
        
    }
    cout<<dp[n];
}

Measured memory_bytes: 1024
import std.stdio, std.conv, std.string, std.bigint;
import std.math, std.random, std.datetime;
import std.array, std.range, std.algorithm, std.container, std.format;
string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }

/*

ナップサック問題（価値の上限が小さい）

xs[i][v]: i番目まで(index <= i)で、価値vを達成するのに必要な容量

xs[0][0] = 0
xs[0][v] = infinity
xs[i][v] = min(
		ws[i], // i個目を取る前提 v - vs[i] < 0 の場合
		xs[i - 1][v - vs[i]] + ws[i], // i個目を取る前提 v - vs[i] >= 0 
		xs[i - 1][v] // i個目を取らない前提
	)

求めるものは

xs[n - 1][v] <= npw であるような最大のv

*/

void main(){
	long n = read.to!long;
	long npw = read.to!long;
	
	long[] ws, vs;
	foreach(i; 0 .. n){
		ws ~= read.to!long;
		vs ~= read.to!long;
	}
	
	long infty = npw * 100;
	
	long vmax;
	foreach(v; vs) vmax += v;
	
	long[][] xs = [[0]];
	foreach(v; 1 .. vmax + 1) xs[0] ~= infty;
	
	foreach(i; 0 .. n){
		long[] q = [];
		foreach(v; 0 .. vmax + 1){
			q ~= min(
				xs[$ - 1][v],
				(v - vs[i] < 0)? ws[i]: xs[$ - 1][v - vs[i]] + ws[i]
			);
		}
		debug writeln("q:", q, " i:", i);
		xs ~= q;
	}
	
	long ans;
	foreach(v; 0 .. vmax + 1) if(xs[n][v] <= npw) ans = v;
	
	ans.writeln;
}


Measured memory_bytes: 114044
#include<iostream>
typedef long long ll;
using namespace std;

const int MOD = 1e9 + 7, MAX = 2000001;

int comb(int n, int k){
    // Calculate factorial and inverse element
    ll fac[MAX], finv[MAX], inv[MAX];
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }

    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
    int X, Y, ans = 0;
    cin >> X >> Y;
    int n = (2 * Y - X) / 3;
    int m = (2 * X - Y) / 3;
    if ((X + Y) % 3 == 0 && n >= 0 && m >= 0) {
        ans = comb(n + m, n);
    }
    cout << ans << endl;
}

Measured memory_bytes: 47104
li=list(map(int,input().split()))

a=li[0]
b=li[1]

ans=0

if(a>=b):
    ans+=a
    a-=1
else:
    ans+=b
    b-=1

if(a>=b):
    ans+=a
    a-=1
else:
    ans+=b
    b-=1


print(ans)

Measured memory_bytes: 3060
def main():
    s = input()
    k = int(input())
    n = len(s)

    if s == s[0]*n:
        print( n*k//2 )
        return 0

    cnt, t = 0, 1
    for key, value in enumerate(s):
        if key == 0: continue
        if value == s[key-1]:
            t += 1
        else:
            cnt += t // 2
            t = 1
    cnt += t//2
    left, right = 0, len(s)-1
    a, b = 0, 0
    while s[left] == s[0]:
        left += 1
        a += 1
    while s[right] == s[-1]:
        right -= 1
        b += 1

    ans = (cnt*k)
    if s[0] != s[-1]:
        print(ans)
    else:
        ans -= (a//2 + b//2)*(k-1)
        ans += (a+b)//2 * (k-1)
        print(ans)

main()


Measured memory_bytes: 3064
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x) cout << #x << ' ' << '=' << ' ' << (x) << endl;
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
typedef vector<ll> vec;
typedef vector<P> pvec;
typedef vector<vector<ll>> vvec;
typedef vector<vector<P>> pvvec;
typedef priority_queue<ll> PQI;
typedef priority_queue<P> PQP;
typedef priority_queue<ll,vector<ll>,greater<ll>> PQIG;
typedef priority_queue<P,vector<P>,greater<P>> PQPG;
const vector<int> dx = {0, -1, 0, 1, 1, 1, -1, -1};
const vector<int> dy = {1, 0, -1, 0, 1, -1, 1, -1};
const int MOD = (1000000007);
// const int MOD = (998244353);
// const int INF = (1 << 30);
const int INF = (1LL << 60);
const double EPS = (1 >> 30);
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;}
template< typename T1, typename T2 > istream &operator>>(istream &is, pair< T1, T2 > &p) { is >> p.first >> p.second; return is; }
template< typename T > istream &operator>>(istream &is, vector< T > &v) { for(T &in : v) is >> in; return is; }

int n;
vvec G;
vec c;

void dfs(int pre,int now,int iro){
    c[now]=iro;
    for(auto &next : G[now]){
        if(pre==next) continue;
        dfs(now,next,(iro+1)%2);
    }
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);
    //---------------------------------------------
    
    cin>>n;
    G.resize(n);
    c.resize(n,-1);
    rep(i,n-1){
        int a,b;cin>>a>>b;a--;b--;
        G[a].pb(b);G[b].pb(a);
    }
    dfs(-1,0,0);
    int cnt=0;
    int cn=0;
    rep(i,n){
        if(c[i]==0) cnt++;
        else cn++;
    }
    vec ans(n);
    vec g;
    if(cnt>n/3 && cn>n/3){
    rep(i,n){
        if((i+1)%3==1) g.pb(i+1);
    }
    rep(i,n){
        if((i+1)%3==0) g.pb(i+1);
    }
    rep(i,n){
        if((i+1)%3==2) g.pb(i+1);
    }
    int f=0;
    rep(i,n){
        if(c[i]==0) ans[i]=g[f],f++;
    }
    rep(i,n){
        if(c[i]==1) ans[i]=g[f],f++;
    }
    rep(i,n) cout<<ans[i]<<endl;
    }
    else{
    rep(i,n){
        if((i+1)%3==0) g.pb(i+1);
    }
    rep(i,n){
        if((i+1)%3==1) g.pb(i+1);
    }
    rep(i,n){
        if((i+1)%3==2) g.pb(i+1);
    }
    int f=0;
    if(cn<=n/3){
        rep(i,n){
            if(c[i]==1) ans[i]=g[f],f++;
        }
        rep(i,n){
            if(c[i]==0) ans[i]=g[f],f++;
        }
        rep(i,n) cout<<ans[i]<<endl;
    }
    if(cnt<=n/3){
        rep(i,n){
            if(c[i]==0) ans[i]=g[f],f++;
        }
        rep(i,n){
            if(c[i]==1) ans[i]=g[f],f++;
        }
        rep(i,n) cout<<ans[i]<<endl;
    }
    }
}

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

using namespace std;

int main()
{
	int X;

	cin >> X;

	int count;

	while (1)
	{
		count = 0;

		for (int i = 1; i <= X; i++)
		{
			if (X % i == 0)
				count++;
		}

		if (count == 2)
			break;

		X++;
	}

	cout << X << endl;
}

Measured memory_bytes: 3632
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n;
		while ((n = in.nextInt()) > 0) {
			int m = in.nextInt();
			String s = in.next();
			int count = 0;
			while (s.startsWith("O")) {
				s = s.substring(1);
			}
			while (s.endsWith("0")) {
				s = s.substring(0, s.length() - 1);
			}
			while (s.contains("II")) {
				s = s.replaceAll("I{2,}", "I,I");
			}
			while (s.contains("OO")) {
				s = s.replaceAll("O{2,}", ",");
			}
			String[] split = s.split(",");
			for (String p : split) {
				int l = p.length() - (n * 2 + 1);
				if (l >= 0)
					count += (l / 2 + 1);
			}

			System.out.println(count);
		}
	}
}

Measured memory_bytes: 53016
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll, ll> Pll;
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
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; }

const int MOD = 1000000007;
const int INF = 1e9;

const int mod = 1000000007;
const int inf = 1e9;
#define PI acos(-1);
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};


int main(){
    int n;
    cin >> n;
    vector<pair<ld, ld>> a(n);
    for(int i = 0; i < n; i++) cin >> a[i].first >> a[i].second;
    sort(a.begin(), a.end());
    ld ans = 0;
    do{
        for(int i = 0; i < n-1; i++) {
            ans += sqrt((a[i].first-a[i+1].first)*(a[i].first-a[i+1].first) + (a[i].second-a[i+1].second)*(a[i].second-a[i+1].second));
        }
    }while(next_permutation(a.begin(), a.end()));

    ld t = 1;
    for(int i = n; i >= 1; i--) {
        t *= i;
    }
    ans /= t;

    cout << fixed << setprecision(15) <<  ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<cstdio>
using namespace std;

int main( ){
  double x1,y1,x2,y2;
  cin>>x1>>y1>>x2>>y2;
  printf("%f",sqrt(pow(x1-x2,2)+pow(y1-y2,2)));
  return 0;
}

Measured memory_bytes: 3272
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i < (ll)(n); i++)
const ll mo = 1000000007;
const ll INF = 	9223372036854775807;
ll ans = INF;

int main()
{
ll n,k;
cin >> n>>k;
pair<ll, ll> p[n];
pair<ll, ll> y[n];
rep(i, n)
{
    cin >> p[i].first>>p[i].second;
    y[i].first=p[i].second;
    y[i].second=p[i].first;
}
sort(p,p+n);
sort(y,y+n);
rep(i,n-1)for (ll j = i+1; j < (ll)(n); j++){
    ll left=p[i].first,right=p[j].first;
    rep(l,n){
        if(y[l].second>=left&&y[l].second<=right){
            ll count=1;
            for (ll m = l+1; m < (ll)(n); m++){
                if(y[m].second>=left&&y[m].second<=right)count++;
                if(count>=k){
                    ans=min(ans,(-left+right)*(y[m].first-y[l].first));
                    break;
                }
            }
        }
    }
}

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

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

using namespace std;

const int MAX_N = 1e6+10;

int main(int argc, char const *argv[])
{
	int s, f[MAX_N];
	cin >> s;
	f[0] = 0;
	f[1] = s;
	int m=2;
	vector<int> vec;
	vec.emplace_back(s);
	while(1){
		if (f[m-1]%2) f[m] = 3*f[m-1]+1;
		else f[m] = f[m-1]/2;
		auto itr = find(vec.begin(), vec.end(), f[m]);
	    if( itr != vec.end() ) break;
		vec.emplace_back(f[m]);
		vec.erase(std::unique(vec.begin(), vec.end()), vec.end());
		m++;
	}
	cout << m << endl;
	return 0;
}

Measured memory_bytes: 384
n = int(input())
an = list(map(int, input().split()))

def multi(n):
    i = 2
    while True:
        yield n * i
        i += 1

d = {}
for a in an:
    if a not in d:
        d[a] = 1
    else:
        d[a] += 1

anmax = 10**6
# 小さい順に倍数要素を消しこんでいく.
for n in sorted(d):
    if n not in d:
        continue

    for m in multi(n):
        if m > anmax:
            break

        if m in d:
            del d[m]

    # 同じ値が複数ある場合は自分自身も消す.
    if d[n] > 1:
        del d[n]

#print(d)
print(len(d))


Measured memory_bytes: 35788
#include <iostream>

using namespace std;

int main(void) {
    int n, d, x;
    cin >> n >> d >> x;
    int a[n];
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }

    int sum = x;
    for (int i = 0; i < n; ++i) {
        if (d % a[i] == 0) {
            sum += d / a[i];
        } else {
            sum += (d / a[i]) + 1;
        }
    }

    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
import math
from collections import deque
from collections import defaultdict
from copy import deepcopy
from itertools import accumulate #リストを与えると累積和を返す
def input(): return sys.stdin.readline().rstrip()
from functools import lru_cache #メモ化

def main():
    a, v = list(map(int,sys.stdin.readline().split()))
    b, w = list(map(int,sys.stdin.readline().split()))
    t = int(sys.stdin.readline())
    dist = abs(a - b)
    if v <= w:
        print('NO')
        return 0

    vw = v - w
    if vw * t >= dist:
        print('YES')
    else: print('NO')


    return 0

if __name__ == "__main__":
    main()

Measured memory_bytes: 9736
#include <iostream>
#include<vector>
#include<climits>
#include<algorithm>
#include<bitset>
#include<cmath>
#include<functional>
#include <numeric>
#define FORi(N) for(int i=0;i<N;++i)
using namespace std;
using ll = long long;
ll gcd(ll m,ll n){
  if(n==0)return abs(m);
  return(gcd(n,m%n));
}
int main(){
  ll N;
  cin>>N;
  vector<ll> A(N);
  FORi(N){
    cin>>A[i];
    A[i]-=1+i;
  }
  sort(A.begin(),A.end());
  ll ans = 0;
  ll num = A[N/2];
  FORi(N){ans+=abs(A[i]-num);}
  ll ans_=0;
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 1792
// avvinci -  summers 18    
// #include"prettyprint.hpp"
#include<bits/stdc++.h>
using namespace std;

typedef pair<long long,long long > P;

#define mod 1000000007 
#define pb emplace_back
#define fs first
#define sc second
#define ll long long 
#define fr(it,st,en) for(it=st;it<en;it++)
#define all(container) container.begin(),container.end()
#define INP ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ws(x) cout << #x << " = " << x << endl;
#define N 1000004

const long long infl = 1e18+5;

ll n,m,k,q,x,y,f,val,t,i,j;
ll ind,cnt,sz,sm,ans,mx,mn;
ll a[N] ;


int main(){
INP
if (fopen("inp.txt", "r")) {
    freopen("myfile.txt","w",stdout);
    freopen("inp.txt", "r", stdin);
}

cin>>n;
set <P> s1,s2,sc1,sc2; 
map<ll , P > mp ; 
fr(i,0,n){
	cin>>x>>y;
	mp[i] = {x,y} ;
	s1.insert({y,i}) ;
	s2.insert({x,i}) ; 
}
sc1 = s1;
sc2 = s2 ; 
x = 0 ;
P p ; 
while(!s1.empty()){
	if( (cnt%2 ==0) ){
		p = *s1.begin() ;
	}
	if( (cnt%2 == 1) ){
		p = *s2.rbegin() ; 
	}
	cnt++ ;
	ind = p.sc ;
	// ws(ind);
	s1.erase({mp[ind].sc,ind});
	s2.erase({mp[ind].fs,ind});
	if(x > mp[ind].sc ) {
		val += x - mp[ind].sc ; 
		x = mp[ind].sc; 
	}
	else if( x < mp[ind].fs ) {
		val += mp[ind].fs - x ; 
		x = mp[ind].fs ; 
	}
}

ans = val + abs(x) ;
// ws(ans);
val = 0 ; 
s1 = sc1; 
s2 = sc2 ; 
x = 0 ; 
cnt = 0 ; 
while( !s2.empty()){
	if( (cnt%2 ==1) ){
		p = *s1.begin() ;
	}
	if( (cnt%2 == 0) ){
		p = *s2.rbegin() ; 
	}
	cnt++;

	ind = p.sc ;
	// ws(ind); 
	s1.erase({mp[ind].sc,ind});
	s2.erase({mp[ind].fs,ind});
	// ws(s1) ; 
	if(x > mp[ind].sc ) {
		val += x - mp[ind].sc ; 
		x = mp[ind].sc; 
	}
	else if( x < mp[ind].fs ) {
		val += mp[ind].fs - x ; 
		x = mp[ind].fs ; 
	}
	// ws(val);
}

ans = max(ans ,val + abs(x) ) ;

cout<<ans; 




return 0 ;
}

Measured memory_bytes: 31488
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define rrep(i, n) for(int i=n-1; i>=0; i--)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define ALL(v) v.begin(),v.end()
#define pb push_back
#define eb emplace_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
const double EPS = 1e-10;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const int MAX = 200010;
int n;
ll k, a[MAX], f[MAX];

int main() {
    cin >> n >> k;
    rep(i, n) cin >> a[i];
    rep(i, n) cin >> f[i];

    sort(a, a+n, greater<ll>());
    sort(f, f+n);

    ll left = -1, right = LLINF;
    while (right - left > 1) {
        ll mid = (left + right) / 2;
        ll tmp = 0;
        rep(i, n) {
            if (a[i] * f[i] >= mid) {
                tmp += (a[i] - mid / f[i]);
            }
        }
        if (tmp <= k) right = mid;
        else left = mid;
    }
    cout << right << endl;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = long long;
using std::cout;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

int main() {
	i64 n, m; scanf("%lld%lld", &n, &m);
	std::vector<i64> x(n), y(m);
	for(int i = 0; i < n; i++) scanf("%lld", &x[i]);
	for(int i = 0; i < m; i++) scanf("%lld", &y[i]);

	i64 A = 0, B = 0;
	const int MOD = 1e9 + 7;
	for(i64 i = 0; i < n; i++) (A += x[i] * i - x[i] * (n - i - 1)) %= MOD;
	for(i64 i = 0; i < m; i++) (B += y[i] * i - y[i] * (m - i - 1)) %= MOD;
	printf("%lld\n", A * B % MOD);
	return 0;
}


Measured memory_bytes: 1920
#include <bits/stdc++.h>
#define db(x) cerr << __LINE__ << ": " << #x << " = " << (x) << endl;
#define ll long long
#define ld long double
#define pll pair<ll, ll>
#define MOD 1000000007
#define FOR(i, n) for(ll i = 0; i < n; i++)
using namespace std;
const long long INF = 3*1e18;

int main() {
    ios::sync_with_stdio(0);    
    cin.tie(0);
    ll N;
    cin >> N;
    ll A[N][3];
    for(ll i = 0; i < N; i++)
        cin >> A[i][0] >> A[i][1] >> A[i][2];
    ll a = A[0][0], b = A[0][1], c = A[0][2];
    if(N == 1) cout << max(a, max(b, c)) << "\n";
    else{
        for(ll i = 1; i < N; i++){
            ll x = A[i][0] + max(b, c), y = A[i][1] + max(a, c), z = A[i][2] + max(a, b);
            a = x, b = y, c = z;
        }
        cout << max(a, max(b, c)) << "\n";
    }
}

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

using namespace std;

int main(){
    int n,x,tmp_max = 0,sum = 0;
    cin >> n;

    vector<int>v(n);

    for(int i = 0;i < n;i++){
        cin >> v[i];
        if(tmp_max < v[i]){
            tmp_max = v[i];
            x = i;
        }
    }

    for(int i = 0;i < n;i++){
        if(i == x)continue;
        else sum += v[i];
    }

    if(tmp_max < sum)cout << "Yes" << endl;
    else cout << "No" << endl;
    

    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <vector>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <ctype.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long lint;

int main(){
   lint n,m;
   cin >> n >> m;
   lint hw = 0;
   lint a;
   REP(i,m){
      cin >> a;
      hw += a;
   }
   
   if(hw > n) cout << "-1\n";
   else cout << n-hw << endl;
   
   return 0;
}

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

using namespace std;
typedef long long ll;

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

int main() {
  int N;
  ll C;
  cin >> N >> C;

  vector<ll> x(N + 1, 0), v(N + 1, 0), rwv(N + 1, 0);
  for (int i = 1; i <= N; i++) {
    cin >> x[i] >> v[i];
  }

  // 累積和
  for (int i = 0; i < N; i++) {
    rwv[i + 1] = rwv[i] + v[i + 1];
  }

  vector<ll> r(N + 1, 0);
  for (int i = 0; i < N; i++) {
    r[i + 1] = max(r[i], rwv[i + 1] - x[i + 1]);
  }

  vector<ll> l(N + 1, 0);
  l[N] = rwv[N] - rwv[N - 1] - (C - x[N]);
  for (int i = N - 1; i >= 1; i--) {
    l[i] = max(l[i + 1], rwv[N] - rwv[i - 1] - (C - x[i]));
  }

  ll ans = 0;
  for (int i = 1; i <= N; i++) {
    ans = max(ans, rwv[i] - x[i]);
    if (i < N) {
      ans = max(ans, rwv[i] - 2 * x[i] + l[i + 1]);
    }
  }

  for (int i = N - 1; i >= 0; i--) {
    ans = max(ans, rwv[N] - rwv[i] - (C - x[i + 1]));
    if (i > 0) {
      ans = max(ans, rwv[N] - rwv[i] - 2 * (C - x[i + 1]) + r[i]);
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 4224
import java.util.*;
import java.io.*;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int A = sc.nextInt();
        int B = sc.nextInt();
        
        System.out.println((A-B)%2==0 ? "Alice" : "Borys");
    }
}

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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int keta(int n) {
    int ans = 0;
    while (n) {
        n /= 10;
        ++ans;
    }
    return ans;
}

int main(){
    ll n, a, b;
    cin >> n;
    a = sqrtl(n);
    while (n%a!=0) a--;
    b = n/a;
    cout << max(keta(a), keta(b)) << endl;
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define VFOR(x,a,b) for(int x=(a);x<((a)+(b));x++)
ll LLtable[110][5];
ll F(string N, int K);
int main(){
  VFOR(i,0,110){VFOR(j,0,5){LLtable[i][j]=-100;}}
  string N; int K;
  cin >> N >> K;
  cout << F(N,K);
  return 0;
}
ll F(string N, int K){
  if(K==0) return 1;
  if(N.size()<K) return 0;
  if(N.size()==0) return 0;
  if(N.size()==1) return (N[0]-'0');
  {
    int tmpflg = 1;
    VFOR(i,0,N.size()){
      if(N[i]!='9'){
        tmpflg = 0;
        i = -10;
      }
    }
    if(tmpflg && LLtable[N.size()][K]!=-100){
      return LLtable[N.size()][K];
    }
  }
  string s9,sl;
  VFOR(i,0,N.size()-1) {
    s9 += '9';
  }
  VFOR(i,1,N.size()-1){
    if(N[i]!= '0'){
      while(i<N.size()){
        sl += N[i];
        i++;
      }
      i = -10;
    }
  }
  ll anstmpk = F(s9,K),anstmpk2=F(s9,K-1);
  if(LLtable[s9.size()][K]==-100) LLtable[s9.size()][K] = anstmpk;
  if(LLtable[s9.size()][K-1]==-100) LLtable[s9.size()][K-1] = anstmpk2;
  ll ans=( anstmpk+(N[0]-'0'-1)*anstmpk2+F(sl,K-1) );
  //cout << "F( " << N << ", " << K << ") = " << ans << endl;
  return ( ans );
}

Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <cassert>
#include <iostream>
#include <map>
#include <sstream>
#include <string>
#include <tuple>
#include <vector>
// #include <queue>

using namespace std;

namespace atcoder {
namespace {

////////////////////////////////////////////////////////////////
using UUU = unsigned long;
[[gnu::unused]] constexpr auto modP{1000 * 1000 * 1000 + 7};
[[gnu::unused]] UUU pow0(const UUU a, const UUU n, const UUU acc)
{
  if (a >= modP)
    return pow0(a % modP, n, acc);
  if (acc >= modP)
    return pow0(a, n, acc % modP);
  if (n == 0)
    return acc;
  if ((n & 1) == 0)
    return pow0(a * a, n / 2, acc);
  return pow0(a, n - 1, (acc * a) % modP);
}
[[gnu::unused]] UUU pow(const UUU a, const UUU n)
{
  return pow0(a, n, 1);
}
////////////////////////////////////////////////////////////////
// XXX
[[gnu::unused]] long choose(const long n, const long k)
{
  if (k == 0) return 1;
  long numer = 1;
  long denom = 1;
  for (long p = n, q = 1; q <= k; --p, ++q) {
    numer *= p;
    numer %= modP;
    denom *= q;
    denom %= modP;
  }
  const auto denomInv = pow(denom, modP - 2);
  return numer * denomInv % modP;
}

long solve1(const long N, const long K, const long i)
{
  const auto p1 = choose(K - 1, i - 1);
  const auto p2 = choose(N - K - i + 1 + i, i);
  return (p1 * p2) % modP;
}

[[gnu::unused]] vector<unsigned long> solveV(istream& in)
{
  unsigned long N, K;
  in >> N >> K;
  // assert(1 <= K && K <= N && N <= 2000);

  vector<unsigned long> ans(K);
  for (auto i = 0u; i < K; ++i) {
    ans[i] = solve1(N, K, i + 1);
  }
  return ans;
}

} // namespace
} // namespace atcoder

////////////////////////////////////////////////////////////////
int main()
{
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  using namespace atcoder;
  const auto ans = solveV(cin);
  for (const auto& x : ans)
    cout << x << '\n';
}


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

int flg[11];

int main(){
  int N, c[3];
  cin>>N;
  string s;
  cin>>s;
  int len = s.size(), ans = 0;

  rep(i, 10){
    rep(j, 10){
      rep(k, 10){
        c[0]=i, c[1]=j, c[2]=k;
        int cnt = 0;
        rep(m, len){
          if((int)s[m]-48 == c[cnt] && cnt<3) cnt++;
        }
        if(cnt == 3) ans++;
      }
    }
  }

  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <unordered_map>
#include <stdio.h>
#include <list>
#include <vector>
#include <algorithm>
#include <stack>
#include <climits>
#include <cmath>
#include <map>
#include <queue>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

int main()
{
	int k,a,b;cin >> k >> a >> b;
	if(b-a<3)
	{
		cout<<k+1<<endl;
		return 0;
	}
	ll ans = 1;
	if(k<a)
	{
		cout << k+1 << endl;
		return 0;
	}
	ans = a;
	k -= a-1;
	if(k%2==1)
	{
		ans +=1;
		k--;
	}
	ans += (1LL)*(k/2)*(b-a);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256