akhauriyash/Code-Regression huggingface dataset:
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map;
import java.util.Queue;
import java.util.Scanner;

public class Main {
	
	static int x, y;
	static int[][] c;
	static class State{
		int color, minstep;
		int[][] field=new int[y][x];
		State(int color, int[][] field, int minstep){
			this.color=color;
			for(int i=0; i<y; i++) {
				for(int j=0; j<x; j++) {
					this.field[i][j]=field[i][j];
				}
			}
			this.minstep=minstep;
		}
	}
	
	static void Copy(int[][] b) {
		for(int i=0; i<y; i++) {
			for(int j=0; j<x; j++) {
				c[i][j]=b[i][j];
			}
		}
	}
	static void dfs(int w, int h, int pre, int now) {
		int[] dx= {1, 0, -1, 0};
		int[] dy= {0, 1, 0, -1};
		c[h][w]=now;
		for(int i=0; i<4; i++) {
			if(w+dx[i]<0 || w+dx[i]>=x || h+dy[i]<0 || h+dy[i]>=y) continue;
			if(c[h+dy[i]][w+dx[i]]!=pre) 	continue;
			dfs(w+dx[i], h+dy[i], pre, now);
		}
	}
	
	public static void main(String[] args) {
		try(Scanner sc = new Scanner(System.in)){
			while(sc.hasNext()) {
				x=sc.nextInt();
				y=sc.nextInt();
				if(x+y==0) break;
				c=new int[y][x];
				for(int i=0; i<y; i++) {
					for(int j=0; j<x; j++) {
						String s=sc.next();
						if(s.equals("R")) {
							c[i][j]=1;
						}else if(s.equals("G")) {
							c[i][j]=2;
						}else {
							c[i][j]=3;
						}
					}
				}
				Queue<State> q=new LinkedList<>();
				//int[][] copy=new int[y][x];
				
				q.add(new State(c[0][0], c, 0));
				int count=0;
				Map<String, Integer> map=new HashMap<>();
				while(!q.isEmpty()) {
					State s=q.poll();
					boolean tf=true;
					String str="";
					for(int i=0; i<y; i++) {
						for(int j=0; j<x; j++) {
							str+=String.valueOf(s.field[i][j]);
							if(s.field[0][0]!=s.field[i][j]) {
								tf=false; 
							}
						}
					}
					if(tf) {
						count=s.minstep;
						break;
					}
					if(map.containsKey(str)) continue;
					map.put(str, s.minstep);
					
					for(int i=1; i<=3; i++) {
						if(s.color==i) continue;
						Copy(s.field);
						dfs(0, 0, s.color,i);
						q.add(new State(i, c, s.minstep+1));
					}
				}
				System.out.println(count);
			}

		}
	}
}


Measured memory_bytes: 298436
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define EPS 1e-9
#define MOD 1000000007
#define int long long
using namespace __gnu_pbds;
using namespace std;
typedef pair<int, int> pii;
typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> ost;
#define INF 10000000000


int dp[100005];
int32_t main(){
	int n, k;
	cin >> n >> k;
	int a[n];
	for(int i = 0; i < n; i++)
		cin >> a[i];
	for(int i = 1; i < n; i++){
		dp[i] = INF;
		for(int j = 1; j <= k; j++)
			dp[i] = min(dp[i],(i-j >= 0 ? dp[i-j] + abs(a[i]-a[i-j]) : INF ) );
	}

	cout << dp[n-1];

	return 0;
}

Measured memory_bytes: 1792
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
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;
        FastReader in = new FastReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        DModSum solver = new DModSum();
        solver.solve(1, in, out);
        out.close();
    }

    static class DModSum {
        public void solve(int testNumber, FastReader s, PrintWriter out) {
            long n = s.nextLong();
            out.println((n * (n - 1)) / 2);
        }

    }

    static class FastReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private FastReader.SpaceCharFilter filter;

        public FastReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public long nextLong() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}



Measured memory_bytes: 21204
import sys
sys.setrecursionlimit(10**7) #再帰関数の上限,10**5以上の場合python
import math
from copy import copy, deepcopy
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque 
#deque(l), pop(), append(x), popleft(), appendleft(x)
##listでqueの代用をするとO(N)の計算量がかかってしまうので注意
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
#import fractions#古いatcoderコンテストの場合GCDなどはここからimportする
from functools import lru_cache#pypyでもうごく
#@lru_cache(maxsize = None)#maxsizeは保存するデータ数の最大値、2**nが最も高効率

def input(): return sys.stdin.readline()[:-1]
def printl(li): print(*li, sep="\n")
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def matmat(A,B):
    K,N,M=len(B),len(A),len(B[0])
    return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)]
def matvec(M,v):
    N,size=len(v),len(M)
    return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)]
def T(M):
    n,m=len(M),len(M[0])
    return [[M[j][i] for j in range(n)] for i in range(m)]
def main():
    mod = 10**9+7
    #w.sort(key=itemgetter(1),reversed=True)  #二個目の要素で降順並び替え

    #N = int(input())
    N, K = map(int, input().split())
    #A = tuple(map(int, input().split())) #1行ベクトル
    #L = tuple(int(input()) for i in range(N)) #改行ベクトル
    #S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列

    print(N*K)




if __name__ == "__main__":
    main()

Measured memory_bytes: 9772
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) (x).begin(),(x).end()
#define uniq(x) (x).erase(unique(ALL(x)),(x).end())
#define SORT(x) sort(ALL(x))
#define REV(x) reverse(ALL(x))
#define foreach(it,x) for(__typeof((x).begin()) it=(x).begin();it!=(x).end();it++)
#define debug(x) cerr<<#x<<"="<<(x)<<endl
#define gett() cerr<<"Time:"<<clock()<<"ms."<<endl
#define ri(x) scanf("%d",&x)
#define rl(x) scanf("%lld",&x)
#define rlcfpoj(x) scanf("%I64d",&x)
#define pi(x) printf("%d",x)
#define pl(x) printf("%lld",x)
#define plcfpoj(x) printf("%I64d",x)
#define lfd() printf("\n")
#define sp() printf(" ")
#define inrep(x) int x;scanf("%d",&x);while(x--)
#define testbit(mask,i) (((mask)>>(i))&1)
#define setbit(mask,i) ((mask)|(1<<i))
#define delbit(mask,i) ((mask)^(1<<i))
int a,b;
int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>a>>b;
	cout<<max(max(a+b,a-b),a*b)<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<numeric>
#include<set>
#include<algorithm>
#include<map>
#include<vector>
using namespace std;
typedef long long li;
#define minimize(a,b) (a>(b)?a=(b),1:0)
#define maximize(a,b) (a<(b)?a=(b),1:0)
#define ceil(a,b) (((a)+(b)-1)/(b))
#define yn(i) ((i)?"Yes":"No")
#define chmin(a,b) (a>(b)?a=(b),1:0)
#define abs(n) max((n),-(n))
#define dist(a,b) max((a)-(b),(b)-(a))
#define chmax(a,b) (a<(b)?a=(b),1:0)
#define repa(i,a,n) for(int i=(a);i<(n);i++)
#define MOD 1000000000
#define rep(i,n) for(int i=0;i<(n);i++)

#define df 0
template<class T> void print(const T& t){ cout << t << "\n"; }
template<class T, class... Ts> void print(const T& t, const Ts&... ts) { cout << t; if (sizeof...(ts)) cout << " "; print(ts...); }

// Container コンテナ型, map以外
template< template<class ...> class Ctn,class T>
std::ostream& operator<<(std::ostream& os,const Ctn<T>& v){
  auto itr=v.begin();
  while(itr!=v.end()){
    if(itr!=v.begin())cout << " ";
    cout << *(itr++);
  }
  return os;
}




string key="keyence";

void add(char m,string s,set<string> st){
  int n=s.size();
  rep(i,n){
    if(s[i]!=m) continue;
    string t;
    repa(j,i,n){
      t.push_back(s[j]);
      st.insert(t);
    }
  }
}

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

int main(){
  li k,n; cin >>k >>n;
  vector<li> a(n); rep(i,n) cin >>a[i];
  li s=a[0]-a[n-1]+k;
  rep(i,n-1){
    maximize(s,a[i+1]-a[i]);
  }
  print(k-s);
}





Measured memory_bytes: 4832
// time-limit: 2000
#include <bits/stdc++.h>
using namespace std;

const int mxN  = 2e5+10;
bool vis[mxN];
vector<int> adj[mxN];
int cnt;

void dfs(int i) {
    if (vis[i]) return;
    vis[i] = true;
    cnt++;
    for (auto& u: adj[i]) {
        dfs(u);
    }
}

void solve() {
    int n,m;
    cin >> n >> m;
    for (int i = 0; i < m; ++i) {
        int a,b;
        cin >> a >> b;
        adj[a].emplace_back(b);
        adj[b].emplace_back(a);
    }
    int ans = 0;
    for (int i = 0; i < n; ++i) {
        if (vis[i]) continue;
        cnt = 0;
        dfs(i);
        ans = max(ans, cnt);
    }
    cout << ans << "\n";
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int t = 1;
    //cin >> t;
    while (t--)
        solve();
    return 0;
}


Measured memory_bytes: 20916
from collections import deque

h, w = map(int, input().split())

d = deque()
op = [[-1] * w for i in range(h)]

for i in range(h):
    s = input().rstrip()
    for j in range(len(s)):
        if s[j] == '#':
            d.append((i, j, 0))
            op[i][j] = 0

while d:
    i, j, step = d.popleft()

    for i2, j2 in [(i-1, j), (i+1, j), (i, j-1), (i, j+1)]:
        if 0 <= i2 < h and 0 <= j2 < w:
            if op[i2][j2] == -1:
                d.append((i2, j2, step+1))
                op[i2][j2] = step + 1

print(max([max(op[i]) for i in range(h)]))


Measured memory_bytes: 130908
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    int N;
    string S;
    cin >> N >> S;
    if(S[0] == 'W'){
        cout << 0 << endl;
        return 0;
    }
    string str = "L";
    int cnt = 1;
    rep(i,1,N*2){
        if(str[i-1] == 'L'){
            if(S[i-1] != S[i]){
                str += "L";
                cnt++;
            }else{
                str += "R";
            }
        }else{
            if(S[i-1] != S[i]){
                str += "R";
            }else{
                str += "L";
                cnt++;
            }
        }
    }
    if(cnt != N){
        cout << 0 << endl;
        return 0;
    }
    //cout << str << endl;
    ll ans = 1, lcnt = 0;
    for(auto c:str){
        if(c == 'L')lcnt++;
        else {
            ans = (ans * lcnt) % MOD;
            lcnt--;
        }
    }
    rep(i,1,N+1)ans = ans * i % MOD;
    cout << ans << endl;
}

Measured memory_bytes: 776
#define _USE_MATH_DEFINES  

#include <algorithm>
#include <iostream>
#include <string>
#include <cmath>
#include <vector>

int main(){
    std::vector<std::vector<bool>> cards(4, std::vector<bool>(13, false));

    int n, val;
    std::cin >> n;
    char chr;    
    for(int i = 0; i < n; ++i){
        int j, k;
        std::cin >> chr >> k;
        switch(chr){
            case 'S':
                j = 0;
                break;
            case 'H':
                j = 1;
                break;
            case 'C':
                j = 2;
                break;
            case 'D':
                j = 3;
                break;
        }

        cards.at(j).at(k - 1) = true;
    }

//    std::cout << "hello!" << std::endl;

    for(int i = 0; i < 4; ++i){
        std::vector<bool>::iterator itr = std::find(cards.at(i).begin(), cards.at(i).end(), false); 
        while(cards.at(i).end() != itr){
            switch(i){
                case 0:
                    chr = 'S';
                    break;
                case 1:
                    chr = 'H';
                    break;
                case 2:
                    chr = 'C';
                    break;
                case 3:
                    chr = 'D';
                    break;
            }

            std::cout << chr << " " << std::distance(cards.at(i).begin(), itr) + 1 << std::endl;
            *itr = true;
            ++itr;
            itr = std::find(cards.at(i).begin(), cards.at(i).end(), false);
        }
    }

    return 0;
}


Measured memory_bytes: 3048
/**
    A	Darker and Darker    	C++14 (GCC 5.4.1)
    Accept
**/
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <algorithm>    // std::copy
#include <iterator>     // std::back_inserter
#include <set>
using namespace std;
 
int main(){
    int N, D;
    cin >> N >> D;
    int count = 0 ;
    vector<vector<int>> X ;
    X = vector<vector<int>>(N,vector<int>(D,0));
    for(int i = 0 ; i < N ; i++){
        for(int j = 0 ; j < D ; j++){
            cin >> X[i][j];
        }
    }
    for(int i = 0 ; i < N-1 ; i ++){
        for(int j = i + 1 ; j < N; j++){
            double m = 0;
            for(int k = 0; k < D ; k++){
                m +=pow(abs(X[j][k] - X[i][k]),2);
            }
            if(floor(sqrt(m) ) == ceil(sqrt(m))){
                count++;
            }
            // cout << i <<" "<< j << " "<< m << endl;
        }
    }

    cout << count << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<stdlib.h>
#include<iomanip>
#include<limits>
#include<queue>
#include<stack>
#include<math.h>
#include<array>
const int INF = 1e9;
const int MOD = 1e9 + 7;
using namespace std;
int num[101] = {0};
int main(){
    string S;
    cin >> S;
    int ans = 753;
    for(int i = 0; i < S.size() - 2 ; i++){
        string  subS = "";
        for(int k = 0; k <= 2; k++){
            subS+=S[i + k];
        }
        ans = min(ans, abs(753 - atoi(subS.c_str())));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> //gp_hash_table
#include <ext/pb_ds/tree_policy.hpp> // tree<int, null_type, less, rb_tree_tag, tree_order_statistics_node_update>

using namespace std;
using namespace __gnu_pbds;

#define hashmap gp_hash_table

typedef long long int ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; //find_by_order, order_of_key

const int N = (int) 3e3 + 10;
const int MOD = 998244353;

int n, S;
int a[N];
int memo[4][N][N];

int dp(int at, int S, int mask) {
    if(S < 0) return 0;
    if(at == n) return S == 0 && (mask == 0b11 || mask == 0b01);
    int& ans = memo[mask][at][S];
    if(ans != -1) return ans;
    ans = 0;
    if(mask == 0) {
        ans = (ans + dp(at, S, 0b01)) % MOD; //turn it on
        ans = (ans + dp(at + 1, S, mask)) % MOD; //keep it off
    } else if(mask == 0b01) { //can skip, take, or close it
        ans = (ans + dp(at + 1, S, mask)) % MOD; //skip
        ans = (ans + dp(at + 1, S - a[at], mask)) % MOD; //take
        ans = (ans + dp(at + 1, S, 0b11)) % MOD; //close
    } else { //closed, can only continue
        ans = (ans + dp(at + 1, S, mask)) % MOD;
    }
    return ans;
}

void solve() {
    cin >> n >> S;
    for(int i = 0; i < n; ++i) cin >> a[i];
    memset(memo, -1, sizeof(memo));
    cout << dp(0, S, 0) << '\n';
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(20);
    cout << fixed;
    solve();
    cout.flush();
    return 0;
}

Measured memory_bytes: 142080
#include <bits/stdc++.h>
#include <ctime>
#include <unordered_map>
#include <stdlib.h>
using namespace std;
#define ll  long long int
#define mod 1000000007
#define modd 998244353
#define com(a,n) for(ll i=0;i<n;i++) cin>>a[i];
#define pri(a,n) for(ll i=0;i<n;i++) cout<<a[i]<<endl;
#define speed ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
/*__builtin_clz();
__builtin_ctz();
__builtin_popcount();*/
int main()
{

    speed;
    ll n;
    cin>>n;
    string s1,s2,s;
    cin>>s1>>s2;
    for(ll i=0;i<n;i++)
    {
        s+=s1[i];
        s+=s2[i];
    }
    cout<<s<<"\n";
    cerr << "\nTime elapsed: " << 1000 * clock()/CLOCKS_PER_SEC << "ms\n";
}

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

int main() {
	std::int64_t n, m;
	std::vector<std::int64_t> in, pairSum;
	in.reserve(1000);
	pairSum.reserve(1000 * 1000);

	while (std::cin >> n >> m, n + m != 0) {
		in.push_back(0);
		for (int i = 0; i < n; ++i) {
			int p;
			std::cin >> p;
			in.push_back(p);
		}

		for (auto x : in)
			for (auto y : in)
				pairSum.push_back(x + y);

		std::sort(pairSum.begin(), pairSum.end());

		std::int64_t ans = 0;
		for (auto e : pairSum) {
			if (e > m)
				continue;

			auto it = std::upper_bound(pairSum.begin(), pairSum.end(), m - e);
			--it;
			ans = std::max(ans, e + *it);
		}

		std::cout << ans << std::endl;

		in.clear();
		pairSum.clear();
	}
}

Measured memory_bytes: 18396
#include <stdio.h> 
 
 
 long gcd_euclid(long m, long n) { 
     long temp; 
     while (n) { 
         temp = m % n; 
         m = n; 
         n = temp; 
     } 
     return m; 
 } 
 
 
 int main(){ 
     long a, b; 
     long temp; 
     long gcd, lcm; 
      
     while(scanf("%ld %ld", &a, &b)!=EOF){ 
         gcd = gcd_euclid(a, b); 
         temp = a / gcd; 
         lcm = temp * b; 
         printf("%ld %ld\n", gcd, lcm); 
     } 
 
 
     return 0; 
 } 


Measured memory_bytes: 2044
#include <stdio.h>
#include <string.h>
 
int main(void){
  char s[255];
  char t[255];
  char u[255];
  int a,b;
  scanf("%s %s",s,t);
  scanf("%d %d",&a,&b);
  scanf("%s",u);
  if(strcmp(s,u)==0){
    printf("%d %d",a-1,b);
  }else if(strcmp(t,u)==0){
    printf("%d %d",a,b-1);
  }else{
    printf("%d %d",a,b);
  }
}

Measured memory_bytes: 128
import copy

N, M = [ int(x) for x in input().split() ]

class Node:
    def __init__(self, id):
        self.id = id
        self.path = []
    def __str__(self):
        return "id: " + str(self.id) + " path: " + str(self.path)

nodes = []
for i in range(N):
    nodes.append(Node(i))

paths = []
for i in range(M):
    from_id, to_id = [ int(x) - 1 for x in input().split() ]
    paths.append([from_id, to_id])
    nodes[from_id].path.append(to_id)
    nodes[to_id].path.append(from_id)

def if_all_passed(passed_nodes):
    if len(passed_nodes) == N:
        return True
    else:
        return False

def go_child(id_new, passed_nodes):
    passed_nodes.append(id_new)
    if if_all_passed(passed_nodes):
        return True

    for i in nodes[id_new].path:
        if not i in passed_nodes:
            if go_child(i, passed_nodes):
                return True
    return False

count = 0
for ids in paths:
    nodes[ids[0]].path.remove(ids[1])
    nodes[ids[1]].path.remove(ids[0])
    if not go_child(0, []):
        count += 1
    nodes[ids[0]].path.append(ids[1])
    nodes[ids[1]].path.append(ids[0])

print(count)


Measured memory_bytes: 3540
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <climits>

using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

int main()
{
    int n, m;
    while (cin >> n >> m, n | m) {
        vector<int> taro(n);
        REP(i, n) {
            cin >> taro[i];
        }
        vector<int> hanako(m);
        REP(i, m) {
            cin >> hanako[i];
        }

        pair<int, int> ans(INT_MAX, INT_MAX);
        int taroSum = accumulate(ALL(taro), 0);
        int hanakoSum = accumulate(ALL(hanako), 0);
        REP(i, n) {
            REP(j, m) {
                if (taroSum - taro[i] + hanako[j] == hanakoSum - hanako[j] + taro[i]) {
                    ans = min(ans, pair<int, int>(taro[i], hanako[j]));
                }
            }
        }
        if (ans.first == INT_MAX) {
            cout << -1 << endl;
        } else {
            cout << ans.first << " " << ans.second << endl;
        }
    }
    return 0;
}

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

#define EPS (1e-10)
#define rep(i, a, b) for (int i = a; i < (int)(b); ++i)
#define rrep(i, a, b) for (int i = b - 1; i >= (int)(a); --i)

using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vd = vector<double>;
using vvi = vector<vi>;

constexpr int MOD = 1000000007;

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

    int x, y, a, b, c;
    cin >> x >> y >> a >> b >> c;

    vi p(a), q(b), vec(x + y + c);
    rep(i, 0, a) { cin >> p[i]; }
    rep(i, 0, b) { cin >> q[i]; }
    rep(i, 0, c) { cin >> vec[i]; }

    sort(p.begin(), p.end());
    sort(q.begin(), q.end());

    rep(i, 0, x) { vec[i + c] = p[a - x + i]; }
    rep(i, 0, y) { vec[i + c + x] = q[b - y + i]; }

    sort(vec.begin(), vec.end());

    ll ans = 0;
    rep(i, c, c + x + y) { ans += vec[i]; }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 2176
from bisect import *
N = int(input())
S = input()

swapleft = []
swapright = []

for i in range(N):
    if S[i] == "B":
        if (i+1) % 2 == 0:
            swapright.append(i+1)
    else:
        if (i+1) % 2 == 1:
            swapright.append(i+1)

for i in range(N, 2*N):
    if S[i] == "B":
        if (i+1) % 2 == 1:
            swapleft.append(i+1)
    else:
        if (i+1) % 2 == 0:
            swapleft.append(i+1)


swapleft = set(swapleft)
swapright = set(swapright)

if len(swapleft) > len(swapright):
    swapleft |= set([i for i in range(1, N+1)]) - swapright
    swapright = set([i for i in range(1, 2*N+1)]) - swapleft

else:
    swapright |= set([i for i in range(N+1, 2*N+1)]) - swapleft
    swapleft = set([i for i in range(1, 2*N+1)]) - swapright

if len(swapright) != len(swapleft):
    print(0)
else:

    swapleft = list(swapleft)

    swapleft.sort(reverse = True)
    swapright = list(swapright)
    swapright.sort()

    ans = 1

    for i in range(N):
        ans *= (N - bisect_left(swapright, swapleft[i]) - i)
        ans %= 1000000007


    for i in range(1, N+1):
        ans *= i
        ans %= 1000000007

    print(ans)


Measured memory_bytes: 90196
<?php
fscanf(STDIN, "%s", $n);

$sum = 0;
foreach (preg_split('//u', $n, -1, PREG_SPLIT_NO_EMPTY) as $i) {
	$sum += (int)$i;
}

echo (($sum % 9 === 0) ? 'Yes' : 'No') . "\n";

Measured memory_bytes: 23716
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define popCnt(x) (__builtin_popcountll(x))
typedef long long Long;

const int MOD = round(1e9 + 7);
const int N = 2e5 + 5;

struct Point {
  int x, y;
  Point(int x, int y) :
    x(x), y(y) {
  }
};

int fact[N];

int power(int b, int p) {
  if (p == 0) return 1;
  int res = power(b, p / 2);
  res = 1LL * res * res % MOD;
  if (p & 1) {
    res = 1LL * res * b % MOD;
  }
  return res;
}

int modInv(int x) {
  return power(x, MOD - 2);
}

void buildFact() {
  fact[0] = 1;
  for (int i = 1; i < N; ++i) {
    fact[i] = 1LL * fact[i - 1] * i % MOD;
  }
}

int getNoWays(const Point& p1, const Point& p2) {
  int dx = p2.x - p1.x;
  int dy = p2.y - p1.y;

  int res = 1LL * fact[dx + dy] * modInv(fact[dx]) % MOD;
  res = 1LL * res * modInv(fact[dy]) % MOD;

  return res;
}

int h, w, a, b;

int solve() {
  a = h - a + 1;
  int res = getNoWays(Point(1, 1), Point(h, w));

  int invalid = 0;
  for (int i = 1; i <= b; ++i) {
    int tmp = getNoWays(Point(1, 1), Point(a - 1, i));
    tmp = 1LL * tmp * getNoWays(Point(a, i), Point(h, w)) % MOD;
    invalid = (invalid + tmp) % MOD;
  }
  res = (res + MOD - invalid) % MOD;
  return res;
}

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#ifdef Local
  freopen("test.in", "r", stdin);
#else
#define endl '\n'
#endif

  buildFact();

  cin >> h >> w >> a >> b;

  cout << solve();

}



Measured memory_bytes: 1024
N = int(input())
d = {}
for _ in range(N):
  s = input()
  if not s in d:
    d[s] = 1
  else:
    d[s] += 1
x = sorted(list(d.items()), key=lambda x:x[1], reverse=True)
n = 0
l = []
for k, v in x:
  if v >= n:
    n = v
    l.append(k)
for y in sorted(l):
  print(y)


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

using namespace std;

typedef long long ll;

const int MOD = 1e9 + 7;

int add(int x, int y) {
	return x + y % MOD;
}

int sub(int x, int y) {
	return (x - y + MOD) % MOD;
}

int get_sum(int n) {
	return (1ll * n * (n + 1) / 2) % MOD;
}

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n, k;
	cin >> n >> k;
	int ans = 0;
	while (k <= n + 1) {
		int mn = get_sum(k - 1);
		int mx = sub(get_sum(n), get_sum(n - k));
		ans = add(add(1, sub(mx, mn)), ans);
		++k;
	}
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 3608
var
  n:string;
begin
  readln(n);
  if pos('111',n)>0 then begin writeln('Yes');exit;end;
  if pos('222',n)>0 then begin writeln('Yes');exit;end;
  if pos('333',n)>0 then begin writeln('Yes');exit;end;
  if pos('444',n)>0 then begin writeln('Yes');exit;end;
  if pos('555',n)>0 then begin writeln('Yes');exit;end;
  if pos('666',n)>0 then begin writeln('Yes');exit;end;
  if pos('777',n)>0 then begin writeln('Yes');exit;end;
  if pos('888',n)>0 then begin writeln('Yes');exit;end;
  if pos('999',n)>0 then begin writeln('Yes');exit;end;
  if pos('000',n)>0 then begin writeln('Yes');exit;end;
  writeln('No');
end.

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
//#define int long long
#define fo(a,b) for(int a=0;a<b;a++)
#define Sort(a) sort(a.begin(),a.end())
#define rev(a) reverse(a.begin(),a.end())
#define fi first
#define se second
#define co(a) cout<<a<<endl
#define sz size()
#define bgn begin()
#define en end()
#define pb(a) push_back(a)
#define pop pop_back
#define V vector
#define P pair
#define V2(a,b,c) V<V<int>> a(b,V<int>(c))
#define V2a(a,b,c,d) V<V<int>> a(b,V<int>(c,d))
#define incin(a) int a; cin>>a
//#define min min<int>
//#define max max<int>
template<class T>
 void cou(vector<vector<T>> a){
  int b=a.size();
  int c=a[0].size();
  fo(i,b){
    fo(j,c){
      cout<<a[i][j];
      if(j==c-1)
        cout<<endl;
      else
        cout<<' ';
    }
  }
}
/*template<>
 void cou(vector<vector<char>> a){
  int b=a.size();
  int c=a[0].size();
  fo(i,b){
    fo(j,c){
      cout<<a[i][j];
      if(j==c-1)
        cout<<endl;
      else
        cout<<' ';
    }
  }
}*/
 int wari(int a,int b) {
   if(a%b==0)
     return a/b;
   else
     return a/b+1;
 }
 int keta(int a){
  double b=a;
  b=log10(b);
  int c=b;
  return c+1;
 }
 int souwa(int a){
  return a*(a+1)/2;
 }
 int lcm(int a,int b){
  int d=a,e=b,f;
  if(a<b)
    swap(a,b);
  int c,m=1;
  while(m){
    c=a%b;
    if(c==0){
       f=b;
      m--;
    }
    else{
      a=b;
      b=c;
 }
  }
  return d*e/f;
    }
  int gcm(int a,int b){
      int d=a,e=b,f;
  if(a<b)
    swap(a,b);
  int c,m=1;
  while(m){
    c=a%b;
    if(c==0){
       f=b;
      m--;
    }
    else{
      a=b;
      b=c;
 }
  }
  return f;
  }
 bool prime(int a){
   if(a<2)
     return false;
   else if(a==2)
     return true;
   else if(a%2==0)
     return false;
   double b=sqrt(a);
    for(int i=3;i<=b;i+=2){
      if(a%i==0){
        return false;
      }
    }
   return true;
 }
struct Union{
  vector<int> par;
  Union(int n){
	par= vector<int>(n, -1);
  }
  int find(int x){
    if(par[x]<0)
      return x;
    else
      return par[x]=find(par[x]);
  }
  bool same(int a,int b){
    return find(a)==find(b);
  }
  int Size(int a){
    return -par[find(a)];
  }
  void unite(int a,int b){
    a=find(a);
    b=find(b);
    if(a==b)
      return;
    if(Size(b)>Size(a))
      swap<int>(a,b);
    par[a]+=par[b];
    par[b]=a;
  }
};
int ketas(int a){
  string b=to_string(a);
  int c=0;
  fo(i,keta(a)){
    c+=b[i]-'0';
  }
  return c;
}
/*struct aa{
	vector<int> gt;
  aa(int n){
	gt= vector<int>(n, 1);
  }
	void c(V<int> d,int b){
	if(d[b]==0){
		gt[d[b]-1]++;
		gt[gt.sz-1]++;
	}
	else{
		gt[d[b]-1]++;
		c(d,d[d[b]]-1);
	}
}
void cok(int a){
	cout<<gt[a-1]<<endl;
	fo(i,a-1)
	cout<<gt[i]<<endl;
}
};
*/
signed main(){
	int a;
	cin>>a;
	if(a==1)
		cout<<"Hello World"<<endl;
	else{
		int b,c;
		cin>>b>>c;
		cout<<b+c<<endl;
	}
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.*;
import java.util.*;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Collections;

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

        String s = sc.next();
        if(s.equals("ABC")){
            System.out.println("ARC");
        }else{
            System.out.println("ABC");
        }



    }
}

Measured memory_bytes: 35684
#include <bits/stdc++.h>
        using namespace std;
   #define int long long
const int MAX = 510000;
const int MOD =  998244353;
int h,w,s1,s2,g1,g2;
bool used1[100],used2[100];
int hen1[100][100],hen2[100][100];
int dfs2(int v,int f);
int dfs1(int v,int f){
   if(v==g1)return f;
   used1[v]=true;
   for(int i=0;i<w;i++){
if(hen1[v][i]>0&&!used2[i]){
   int d=dfs2(i,min(f,hen1[v][i]));
   if(d!=0){
   hen1[v][i]-=d;
   hen2[i][v]+=d;
   return d;
   }
}
   }
   return 0;
}
int dfs2(int v,int f){
   if(v==g2)return f;
   used2[v]=true;
   for(int i=0;i<h;i++){
if(hen2[v][i]>0&&!used1[i]){
   int d=dfs1(i,min(f,hen2[v][i]));
   if(d!=0){
   hen2[v][i]-=d;
   hen1[i][v]+=d;
   return d;
   }
   }
   }
   return 0;
}
     signed main(){
      cin>>h>>w;
      string a[h];
      for(int i=0;i<h;i++)cin>>a[i];
      for(int i=0;i<h;i++){
         for(int j=0;j<w;j++){
            if(a[i][j]=='o'){
               hen1[i][j]=1;
               hen2[j][i]=1;
            }
            if(a[i][j]=='S'){
               s1=i;s2=j;
            }
            if(a[i][j]=='T'){
               g1=i;g2=j;
        
            }
         }
      }

      if(s1==g1||s2==g2){
         cout<<-1;
         return 0;
      }
      int flow=0;
      while(true){
         fill(used1,used1+h,false);fill(used2,used2+w,false);
         int f=dfs1(s1,MOD)+dfs2(s2,MOD);
         if(f==0){
            cout<<flow;
            return 0;
         }
         
         flow+=f;
      }



      }

        


Measured memory_bytes: 384
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        int MAX = 1000000007;
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        String S_1 = sc.next();
        String S_2 = sc.next();
        sc.close();
        long result = 1;
        int i = 0;
        while(i < N){
            if(S_1.charAt(i) == S_2.charAt(i)){
                if(i == 0){
                    result *= 3;
                }else if(S_1.charAt(i - 1) == S_2.charAt(i - 1)){
                    result *= 2;
                }
                i++;
            }else{
                if(i == 0){
                    result *= 6;
                }else if(S_1.charAt(i - 1) == S_2.charAt(i - 1)){
                    result *= 2;
                }else{
                    result *= 3;
                }
                i += 2;
            }
            result %= MAX;
        }
        System.out.println(result);
    }

}

Measured memory_bytes: 23764
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;

namespace C
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split(' ');
            long x = long.Parse(s[0]);
            long k = long.Parse(s[1]);
            long d = long.Parse(s[2]);

            long ans = 0;
            #region 自作（失敗）
            /*long temp_x = x;
            if(k*d < Math.Abs(x))
            {
                if (x > 0) ans = x - k * d;
                else ans = k * d - x;
                Console.WriteLine(ans);
                return;
            }
            else
            {
                for (int i = 0; i < k; i++)
                {
                    temp_x = Math.Abs(temp_x) - d;
                    if (temp_x <= 0)
                    {
                        if (k == i+1)
                        {
                            if (Math.Abs(temp_x) > temp_x + d)
                            {
                                Console.WriteLine(temp_x + d);
                            }
                            else
                            {
                                Console.WriteLine(Math.Abs(temp_x));
                            }
                            return;
                        }
                        else if (k - i % 2 == 0)
                        {
                            ans = temp_x;
                            Console.WriteLine(ans);
                            return;
                        }
                        else 
                        { 
                            ans = temp_x + d;
                            Console.WriteLine(ans);
                            return;
                        }
                    }
                }
            }

            Console.WriteLine(ans);
            return;*/
            #endregion

            x = Math.Abs(x);

            long a = Math.Min(x/d, k);
            k -= a;
            x -= a * d;

            if(k % 2 == 0)
            {
                Console.WriteLine(x);
            }
            else
            {
                Console.WriteLine(d-x);
            }

        }
    }
}


Measured memory_bytes: 27564
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
#define rep2(i,a,n) for(int i=a;i<n;i++)
#define been(ix) (ix).begin(),(ix).end()
using namespace std;
typedef long long ll; 
typedef vector<int> vi;
typedef vector<long long> vl;
const ll INFL = 1e18;
const int INF = 1001001001; 
typedef pair<int,int> P;
#define foreach(ix,i) for(auto& (ix) : (i))
typedef long double ld;
int mod =1000000007;
const double PI = acos(-1);

int main(){
    int a,b,c,k;cin>>a>>b>>c>>k;
    bool f =false;
    rep(i,k+1){
        rep(j,k+1){
            rep(l,k+1){
                if(i+j+l>k)continue;
                int A = a*pow(2,i),B=b*pow(2,j),C=c*pow(2,l);
                if(A<B&&B<C)f=true;
            }
        }
    }
    if(f)cout<<"Yes"<<endl;
    else
    {
         cout<<"No"<<endl;
    }
    
    
}

Measured memory_bytes: 4096
list = []
r,c=map(int,input().split())
all_ttl = 0
for i in range(r):
    s = input()
    ttl = 0
    cnt = 0
    for a in map(int, s.split()):
        if i==0:
            list.append(a)
        else:
            list[cnt] += a
        ttl += a
        cnt += 1
    s = s + " " + str(ttl)
    all_ttl += ttl
    print(s)
s = ""
for a in list:
    if s == "":
        s = str(a)
    else:
        s = s + " " + str(a)
print(s + " " + str(all_ttl))


Measured memory_bytes: 5612
#include <iostream>
using namespace std;
long long max(long long a, long long b) {
  if(a >= b) {
    return a;
  }
  return b;
}

int main(void) {
  long long a, b, k;
  cin >> a >> b >> k;
  cout << max(a - k, 0) << ' ' << max(b - max(k - a, 0), 0)
       << 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 COUT(x) cout<<(x)<<endl
#define dump(x)  cout << #x << " = " << (x) << endl;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
using M = map<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int, vector<int>, greater<int>>;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main() {
  ll n; cin >> n;
  ll x, t;
  REP(i,n) {
    cin >> t;
    x = i == 0 ? t : lcm(x,t);
  }
  cout << x << endl;
  return 0;
}

Measured memory_bytes: 256
def maxValue(a,b,v):
	v2 = v
	for i in range(v2,-1,-1):
		for j in range(v2//a+1): #j:aの個数
			k = i-a*j
			if k%b==0:
				return i
	return -1

a,b,c,d,e,f = list(map(int, input().split()))

waVa = maxValue(a*100,b*100,f)
suVa = maxValue(c,d,min(f-waVa,waVa*e//100))
maxR = 0

anw = waVa
ans = suVa

while 1:
	waVa = maxValue(a*100,b*100,waVa-1)
	suVa = maxValue(c,d,min(f-waVa,waVa*e//100))
	if waVa == 0:
		break
	if maxR<100*suVa/(suVa+waVa):
		maxR = 100*suVa/(suVa+waVa)
		anw = waVa
		ans = suVa

print(anw+ans,ans)

Measured memory_bytes: 3064
n,k=map(int,input().split())
l=list(map(int,input().split()))
sc=0
ans=n-k+1
INF=n+1
No=2
while No<n:
    No*=2
tree=[[0,0]]*(2*No)
for i in range(No-1,No-1+n):
    tree[i]=[l[i-No+1],l[i-No+1]]
for i in range(No-2,-1,-1):
    a,b=tree[i*2+1]
    c,d=tree[i*2+2]
    tree[i]=[max(a,c),min(b,d)]
def query(l,r):
    L=l+No-1
    R=r+No-1
    s=[-INF,INF]
    while L<=R:
        if R&1:
            a,b=tree[R]
            c,d=s
            s=[max(a,c),min(b,d)]
            R-=2
        else:
            R-=1
        if L&1:
            L-=1
        else:
            a,b=tree[L]
            c,d=s
            s=[max(a,c),min(b,d)]
        L>>=1;R>>=1
    return s
class unionfind:
    def __init__(self, n):
        self.n = n
        self.root = [-1]*(n+1)
        self.rnk = [0]*(n+1)
    def find(self, x):
        if(self.root[x] < 0):
            return x
        else:
            self.root[x] = self.find(self.root[x])
            return self.root[x]
    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if(x == y):
            return 
        elif(self.rnk[x] > self.rnk[y]):
            self.root[x] += self.root[y]
            self.root[y] = x
        else:
            self.root[y] += self.root[x]
            self.root[x] = y
            if(self.rnk[x] == self.rnk[y]):
                self.rnk[y] += 1
    def same(self, x, y):
        return self.find(x) == self.find(y)
    def count(self, x):
        return -self.root[self.find(x)]
uf=unionfind(n)
s=set()
t=1
for i in range(n-1):
    if l[i]<l[i+1]:
        t+=1
    else:
        t=1
    if t>=k:
        s.add(i-k+2)
if len(s)>1:
    a=s.pop()
    while s:
        uf.unite(a,s.pop())
for i in range(n-k):
    b,a=query(i,i+k)
    if l[i]==a and l[i+k]==b:
        uf.unite(i,i+1)
s=set()
for i in range(n-k+1):
    s.add(uf.find(i))
print(len(s))

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

#define ASC(vec) vec.begin(), vec.end()		// 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend()	// 降順ソート 例:sort(DESC(vec));
#define rep(i, n) for(int i = 0; i < n; i++)
#define Rep(i, n) for(int i = 1; i < n; i++)
#define Ans(s) cout << s << endl

const int mod = 1000000007;
const int inf = (int)1e9 + 7;
const long long INF = 1LL << 60;

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

int GCD(int a, int b) { return b ? GCD(b, a % b) : a; }
int round_int(int a, int b) { return (a + (b - 1)) / b; }

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

// 4,8方向に探索する際に用いる配列
//int dx[4] = { 0,  0, 1, -1 };
//int dy[4] = { 1, -1, 0,  0 };
//int dx[8] = { 1, 0, -1,  0, 1, -1, -1,  1 };
//int dy[8] = { 0, 1,  0, -1, 1,  1, -1, -1 };

constexpr auto MAX = 100010;

// ────────────────────────────────────────────────────

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

	vector<int> l(n);
	rep(i, n) cin >> l[i];

	int ans = 1;
	int pos = 0;
	rep(i, n)
	{
		pos += l[i];
		if (pos > x) break;
		ans++;
	}
	Ans(ans);
}

Measured memory_bytes: 256
def main():
    from math import sqrt
    from fractions import gcd
    from collections import defaultdict
    from copy import deepcopy

    N = int(input())
    A = list(map(int, input().split()))
    mod = 10 ** 9 + 7

    p = [1] * (1001)
    P = []  # 1000までの素数表
    p[0] = p[1] = 0
    for x in range(2, int(sqrt(1000000)) + 1):
        if p[x]:
            P.append(x)
            for y in range(x * x, 1001, x):
                p[y] = 0

    B = [defaultdict(int) for i in range(N)]  # N個の数を素因数分解したもの
    lcm = defaultdict(int)  # N個の数のlcmを素因数分解したもの

    for i in range(N):
        for j in P:
            if A[i] % j == 0:
                while A[i] % j == 0:
                    A[i] //= j
                    B[i][j] += 1
            lcm[j] = max(lcm[j], B[i][j])
        if A[i] != 1:
            B[i][A[i]] = 1
            lcm[A[i]] = 1

    l = 1  # N個の数のlcm
    for i in lcm.keys():
        l = (l * pow(i, lcm[i], mod)) % mod

    ans = 0
    # l/A[i]の和を求めていく
    for i in range(N):
        r = l
        for j in list(B[i].keys()):
            r = (r * pow(j, mod - B[i][j] - 1, mod)) % mod
        ans = (ans + r) % mod

    print(ans)

if __name__ == '__main__':
    main()

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

int main() {
 int a,b;
 cin>>a>>b;
 vector<vector<int>>dp(a+1,vector<int>(b+1));
 for(int c=0;c<a;c++){
 	int d,e;
 	cin>>d>>e;
 	for(int f=0;f<b+1;f++){
 		if(f<e)dp[c+1][f]=dp[c][f];
 		else dp[c+1][f]=max(dp[c][f],dp[c][f-e]+d);
 	}
 }
 cout<<dp[a][b]<<endl;
}

Measured memory_bytes: 6788
N=int(input())

if N==1:
    print(1)
    exit()

P=[]
for i in range(N):
    P.append(list(map(int,input().split())))

c={}
for i in range(N):
    for j in range(N):
        if i!=j:
            p=P[j][0]-P[i][0]
            q=P[j][1]-P[i][1]
            temp=str(p)+"_"+str(q)
            if temp in c:
                c[temp]+=1
            else:
                c[temp]=1
c_num=[]
for j in c:
    c_num.append(c[j])

print(N-max(c_num))



Measured memory_bytes: 3316
n = int(input())
s = list(map(int,input().split()))
flag = -1
for i in range(n):
    if s[i] == 1:
        flag = 2
    if s[i] == flag:
        flag += 1
if flag == -1:
    print(-1)
else:
    print(n - flag + 1)

Measured memory_bytes: 24744
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define eb emplace_back
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}


int const INF = 1001001001;


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

int n,m;
cin >> n >> m;
if(n == m) cout << "Yes" << endl;
else cout << "No" << endl;


return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define endl "\n" 
#define pi acos(-1)
#define ll long long 
using namespace std;
ll power(ll a,ll b){
	ll k=1;
	for(int i=0;i<b;i++)
		k*=a;
	return k;
}
void solve();
int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
	#ifndef ONLINE_JUDGE
    	freopen("input.txt", "r", stdin);
    	freopen("output.txt", "w", stdout);
	#endif
	int q=1;//cin>>q;
	while(q--){
		solve();
	}
}
void solve(){
	int n,k,x,l,m;cin>>k>>n;int arr[101]={0};
	for(int i=0;i<n;i++){
		cin>>x;
		arr[x]=1;
	}
	l=m=k;
	while(true){
		if(arr[l]==0){
			break;
		}
		else
			l++;
		if(l==101)
			break;
	}
	while(true){
		if(arr[m]==0)
			break;
		else
			m--;
		if(m==-1)
			break;
	}
	(k-m<=l-k)?cout<<m:cout<<l;
	
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
const long long INF = 1e14;
const int MAXV = 112345;
const int MAXN = 112;
long long dp[MAXV];
int v[MAXN], w[MAXN], n, W, som;

int main(){
	scanf("%d %d", &n, &W);
	for(int i = 1; i <= n; i++ ){
		scanf("%d %d", &w[i], &v[i]);
		som += v[i];


	}
	for(int i = 1; i <= som; i++)dp[i] = INF;
	dp[0] = 0;
	for(int id = 1; id <= n; id++){
		int wi = w[id], vi = v[id];
		for(int i = som; i >= vi; i--){
			dp[i] = min(dp[i], dp[i - vi] + wi);


		}

	}
	for(int i = som; i >= 0; i-- ){
		if(dp[i] <= W){
			printf("%d\n", i);
			break;
		}


	}




}



Measured memory_bytes: 1024
#include <iostream>
#include <bitset>
#include <fstream>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <functional>
#include <cctype>
#include <list>
#include <limits>
//#include <boost/multiprecision/cpp_int.hpp>

const double EPS = (1e-10);


using namespace std;
using Int = long long;
//using namespace boost::multiprecision;

const Int MOD = 1000000007;

Int mod_pow(Int x, Int n) {
    Int res = 1;
    while(n > 0) {
        if(n & 1) res = (res * x) % MOD; //ビット演算(最下位ビットが1のとき)
        x = (x * x) % MOD;
        n >>= 1; //右シフト(n = n >> 1)
    }
    return res;
}

//最大公約数
template<typename T>
T gcd(T a, T b) {
    return b != 0 ? gcd(b, a % b) : a;
}

//最小公倍数
template<typename T>
T lcm(T a, T b) {
    return a * b / gcd(a, b);
}

bool my_cmp(const int &a, const int &b) {
    if (a % 10 == 0) return true;
    else if (b % 10 == 0) return false;
    else return a%10 > b%10;
}

int main(){
    long long food[5];
    for (int i = 0; i < 5; i++) {
        cin >> food[i];
    }
    sort(food, food+5, my_cmp);
    long long ans = 0;
    for (int i = 0; i < 4; i++) {
        ans += (food[i] + 9) / 10 * 10;
    }
    ans += food[4];
    cout << ans << endl;
    return 0;
}



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

using namespace std;
using llong = long long;
using ldbl = long double;
using lpair = pair<llong, llong>;

#define ALL(x) x.begin(), x.end()

template<typename T>
constexpr T inf = static_cast<T>(pow(10, static_cast<int>(log10(numeric_limits<T>::max())))) + 7;
constexpr llong mod = 1e9+7;

int main() {
  llong N;
  cin >> N;

  vector<vector<llong>> res(10, vector<llong>(10, 0));
  for (int i = 1; i <= N; ++i) {
    llong right = i%10;
    llong cp = i;
    llong left;
    while (cp) {
      left = cp%10;
      cp /= 10;
    }

    res[left][right]++;
  }

  llong ans = 0;
  for (int i = 1; i <= 9; ++i) {
    for (int j = 1; j <= 9; ++j) {
      ans += res[i][j] * res[j][i];
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
  int i,j=0,c=0,n1,n2,retu1[10000],retu2[500];
  scanf("%d",&n1);
  for(i=0;i<n1;i++){
    scanf("%d",&retu1[i]);
  }
  scanf("%d",&n2);
  for(i=0;i<n2;i++){
    scanf("%d",&retu2[i]);
  }
  for(i=0;i<n2;i++){
    j=0;
    while(j<n1){
      if(retu1[j]==retu2[i]){
	c++;
	break;
      }
      else j++;
    }
  }
  printf("%d\n",c);
  return 0;
}

Measured memory_bytes: 640
#include <cstdio>
#include <algorithm>
using namespace std;

const int MAX = 1 << 15;

bool isPrime[MAX + 1];

int main() {
	fill(isPrime, isPrime + MAX + 1, true);
	isPrime[0] = isPrime[1] = false;

	for(int i = 2; i * i <= MAX; i++)
		if(isPrime[i])
			for(int j = 2 * i; j <= MAX; j += i)
				isPrime[j] = false;



	for(int N; scanf("%d", &N), N;) {
		int cnt = 0;
		for(int i = 2; i <= N / 2; i++) {
			if(isPrime[i] && isPrime[N - i])
				cnt++;
		}
		printf("%d\n", cnt);
	}

	return 0;
}

Measured memory_bytes: 0