akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <set>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <string>
#include <cstring>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
#include <tuple>
#include <numeric>
#include <assert.h>
#include <functional>
#include <unordered_map>

using namespace std;

/*-----------------------------------------------------------------------------
　定義
 -------------------------------------------------------------------------------*/
#define REP(i, n)				for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n)			for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define INF						2e9
#define MOD						(1000 * 1000 * 1000 + 7)
#define Ceil(x, n)				(((((x))+((n)-1))/n))		/* Nの倍数に切り上げ割り算 */
#define CeilN(x, n)				(((((x))+((n)-1))/n)*n)		/* Nの倍数に切り上げ */
#define FloorN(x, n)			((x)-(x)%(n))				/* Nの倍数に切り下げ */
#define IsOdd(x)				(((x)&0x01UL) == 0x01UL)			
#define IsEven(x)				(!IsOdd((x)))						
#define ArrayLength(x)			(sizeof( x ) / sizeof( x[ 0 ]))
#define	MAX_QWORD				((QWORD)0xFFFFFFFFFFFFFFFF)
#define M_PI					3.14159265358979323846
typedef long long				ll;
typedef unsigned long long int	QWORD;
typedef pair<ll, ll>			P;

/*-----------------------------------------------------------------------------
　処理
 -------------------------------------------------------------------------------*/
int main()
{
	string S;
	cin >> S;

	int asn = 700;
	REP(i, 3) if (S[i] == 'o') asn += 100;
	cout << asn << endl;
	return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#define PI 3.141592653589793
#define MOD 1000000007


int main(){
	int n, tim[60];
	char str[60][120], x[120];
	scanf("%d", &n);
	for(int i=1; i<=n; i++){
		scanf("%s%d", &str[i], &tim[i]);
	}
	scanf("%s", &x);
	int i;
	for(i=1; i<=n; i++){
		if(strcmp(str[i], x) == 0) break;
	}
	i++;
	int ans = 0;
	for(; i<=n; i++){
		ans += tim[i];
	}
	
	printf("%d\n", ans);

	return 0;
}

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

typedef long long LL;

template<typename T>
void printmatrix(vector<vector<T> > ar){
    for (int i = 0; i < (int)ar.size(); i++) {
        for (int j = 0; j < (int)ar.size(); j++) {
            cout << ar[i][j];
        }
        cout << endl;
    }
}

template<typename T>
void printvector(vector<T> vec){
    for (int i = 0; i < (int)vec.size(); i++) {
        cout << vec[i] << endl;
    }
}

template<typename T>
void unique(vector<T>& vec){
    sort(vec.begin(), vec.end());
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
}

template<typename T>
vector<T> cumsum(vector<T> vec){
    vector<T> newvec((T)vec.size());
    int tmp = 0;
    for (int i = 0; i < (int)vec.size(); i++) {
        tmp += vec[i];
        newvec[i] = tmp;
    }

    return newvec;
}


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

    vector<int> m(n);
    for (int i = 0; i < n; i++) {
        cin >> m[i];
        x -= m[i];
    }
    sort(m.begin(), m.end());

    cout << (x / m[0]) + n << endl;

    return 0;
}

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

using namespace std;

int s[5001];

int main()
{
	int n;

	while (scanf("%d", &n), n) {
		for (int i = 1; i <= n; ++i) {
			int a; scanf("%d", &a);
			s[i] = a + s[i - 1];
		}

        int ma = -100000;

		for (int i = 1; i <= n; ++i) for (int j = 1; j <= i; ++j) {
			ma = max(ma, s[i] - s[j - 1]);
		}

		printf("%d\n", ma);
	}
}

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

int main(){
    int N,M;
    cin >> N >> M;
    vector<vector<int> > food_like(N, vector<int> (0));
    for (int i = 0; i < N; i++){
        int K;
        cin >> K;
        vector<int> food_liki(K);
        for (int j = 0; j < K; j++){
            cin >> food_liki.at(j);
        }
        food_like.at(i) = food_liki;
    }
    vector<int> food_survey(M);
    for (int i = 0; i < M; i++){
        food_survey.at(i) = 0;
    }
    for (int i = 1; i <= M; i++){
        for (int j = 0; j < N; j++){
            for (int k = 0; k < food_like.at(j).size(); k++){
                if (food_like.at(j).at(k) == i){
                    food_survey.at(i - 1)++;
                }
            }
        }
    }
    int count = 0;
    for (int i = 0; i < M; i++){
        if (food_survey.at(i) == N){
            count++;
        }
    }
    cout << count << endl;
}


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

using namespace std;

int main(){
  int n; 
  cin >> n;
  string s;
  cin >> s;
  int same[26] = {0};
  int count = 0;
  int ans = 0;
  
  for(int k = 0; k < n; k++){  
    for(int i = 0; i <= k; i++){
      for(int j = n - 1; j > k; j--){
        if(same[s[i] - 'a'] == 0 && s[i] == s[j]){ 
          count++;
          same[s[i] - 'a']++;
        }
      }
    }
    if(ans < count) ans = count;
    count = 0;
    for(int x = 0; x < 26; x++){
      same[x] = 0;
    }
  }
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256
# # Make IO faster
# import sys
# input = sys.stdin.readline

# # get single (or) multiple str
# X = input()

# # get single int
# N = int(input())
# # get multiple int (e.g., 2)
# X, Y = map(int, input().split())
# # get multiple int (e.g., 2) for N lines
# XY = [list(map(int, input().split())) for _ in range(N)]

# from IPython import embed; embed(); exit();

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

A, B, C, D = MAP()
print(max([A * B, C * D]))


Measured memory_bytes: 27208
N, M = map(int, input().split())
cleared = [0 for i in range(N)]
wrong = [0 for i in range(N)]
penalty = 0
for i in range(M):
  p, s = map(str, input().split())
  p = int(p) - 1
  if cleared[p] == 1:
    continue
  if s == "AC":
    cleared[p] = 1
    penalty += wrong[p]
  else:
    wrong[p] += 1
print(sum(cleared), penalty)

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

using namespace std;
typedef long long ll;
typedef long double lb;
#define rep(i,j,n) for (ll i = j; i < (n); i++)
#define repr(i,j,n) for(ll i = j; i >= (n); i--)
#define each(i,mp) for(auto& i:mp)
#define all(x) (x).begin(),(x).end()
#define CLR(mat,f) memset(mat, f, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<b)
#define out(ans) cout << ans << endl
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; }
typedef pair<ll,ll>P;
const ll mod=1e9+7;
const ll INF = 1LL<<60;
const ll m=1LL<<32;

int main(){

  ll x;cin>>x;

  rep(i,-120,120){
    ll num=pow(i,5)-x;
    rep(j,-120,120){
      if(num==pow(j,5)){
        out(i<<" "<<j);
        return 0;
      }
    }
  }


  
  return 0;
}


Measured memory_bytes: 4060
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <string>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
using namespace std;
#define loop(i,N) for(ll (i)=0; (i)<(N);++(i))
struct _OMAZINAI_ { _OMAZINAI_() { std::ios::sync_with_stdio(false); std::cin.tie(0); } } __omazinai_instance__;
#define INF ((1LL<<61) + (1<<29))
#define YesNo(x) {std::cout << ((x)?"Yes":"No") << std::endl;}
#define YESNO(x) {std::cout << ((x)?"YES":"NO") << std::endl;}
#define OddEven(x) {std::cout << ((x)%2?"Odd":"Even") << std::endl;}
#define ODDEVEN(x) {std::cout << ((x)%2?"ODD":"EVEN") << std::endl;}
typedef long long int ll;
ll my_gcd(ll a, ll b) { return b ? my_gcd(b, a%b) : a; };
void _INPUT_IMPL_() {};
template <class T, class... Args> void _INPUT_IMPL_(T& dest, Args&... args) { cin >> dest; _INPUT_IMPL_(args...); }
void _OUTPUT_IMPL_() {};
template <class T, class... Args> void _OUTPUT_IMPL_(T dest, Args... args) { cout << dest << (sizeof...(Args) ? " " : ""); _OUTPUT_IMPL_(args...); }
#define in(type, ...) type __VA_ARGS__; _INPUT_IMPL_(__VA_ARGS__)
#define in_v(type, name, cnt) vector<type> name(cnt); loop(i, cnt) cin >> name[i];
#define sort_v(v) std::sort(v.begin(), v.end())
#define out(...) (_OUTPUT_IMPL_(__VA_ARGS__), std::cout<<std::endl)
#define set_fix(x) ((std::cerr<<std::fixed<<std::setprecision(x)),(std::cout<<std::fixed<<std::setprecision(x)))
//小さい方に寄る
#define space_op(x, y, a, b, c) ([](auto x_, auto y_, auto a_, auto b_, auto c_){if(x_<y_)return a_;if(x_>y_)return c_;return b_;}(x,y,a,b,c))
#define space_out(x, y, a, b, c) out(space_op(x, y, a, b, c))

// ^^^ Template ^^^ //

int main() {
	in(int, age);
	if (age == 1) {
		out("Hello World");
	} else {
		in(int, A, B);
		out(A + B);
	}
}


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

int main()
{
    int a, b, k;
    cin >> a >> b >> k;

    int rank = 0;
    int ans = 0;

    for (auto i = 100; i > 0; i--)
    {
        if (a % i == 0 && b % i == 0)
        {
            rank += 1;
            if (rank == k)
            {
                ans = i;
                break;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <string>
#include <functional>
#include <set>
#define DB cerr<<"D"<<endl
#define pb push_back
using namespace std; using ll=long long; using ld=long double; const int INF=1e9; const ll LINF=1e18; const double dINF = 1e18; const ld ldINF = 1e18; const double EPS = 1e-6;
template<typename T, typename U, typename O> void caut(T a, U b, O c){cout<<"("<<a<<","<<b<<","<<c<<") ";} template<typename T, typename U> void caut(T a, U b){cout<<"("<<a<<","<<b<<") ";} template<typename T> void caut(T a){cout<<"("<<a<<") ";}
using P=pair<double,int>;
const ll M = 998244353;
void add(ll& x, ll y) {x+=y; x%=M;}
void chmax(ll& x, ll y) {if (x<y) x=y;}

int main() {
  ll n; cin>>n;
  ll an=n%10;
  for(ll i=9,j=10,k=9;i<=n;i+=j,k++) {
    an=k;
    if (i+j > j*10) j*=10;
  }
  cout<<an<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    rep(i, n)cin >> a[i];
    vector<bool> dp(k+1, false);
    for(int i = 1; i <= k; i++){
        bool win = false;
        rep(j, n){
            if(i < a[j])break;
            if(!dp[i-a[j]])win = true;
        }
        dp[i] = win;
    }
    if(dp[k])cout << "First" << endl;
    else cout << "Second" << endl;
}

Measured memory_bytes: 3604
#!/usr/bin/env python3
# -*- coding: utf-8 -*-


def main():
    A, B, C = map(int, input().split())
    if A == B and B != C:
        print('Yes')
    elif A == C and B != C:
        print('Yes')
    elif B == C and A != B:
        print('Yes')
    else:
        print('No')


if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#define rep(i, n) for(int i = 0; i < (n); ++i)
typedef long long ll;
using namespace std;
const ll mod = 1000000007;
ll pow(ll b, ll e) {
  if(e == 0)
    return 1LL;
  if(e % 2 == 1)
    return pow(b, e - 1) * b % mod;
  ll m = pow(b, e >> 1);
  return m * m % mod;
}
ll inv(ll a) {
  return pow(a, mod - 2);
}
ll mcomb(ll n, ll k) {
  ll res = 1LL;
  k = min(k, n - k);
  rep(i, k) res = res * (n - i) % mod;
  rep(i, k) res = res * inv(i + 1) % mod;
  return res;
}
const int MAX = 1000000;
int main(void) {
  ll x, y;
  cin >> x >> y;
  if((x + y) % 3 != 0) {
    cout << 0 << endl;
    return 0;
  }
  ll n = (2 * y - x) / 3;
  ll m = (2 * x - y) / 3;
  if(n < 0 || m < 0) {
    cout << 0 << endl;
    return 0;
  }
  cout << mcomb(n + m, n) << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long int
#define pb push_back
typedef pair<ll,ll> ipair;
#define F first
#define S second
 
/*
//functions from gfg
 
long long int power(long long int x,long long int y,long long  int p)
{
    long long int res = 1;     // Initialize result
 
    x = x % p;  // Update x if it is more than or 
                // equal to p
 
    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            {//d=(long double)x/p;
            res = (res*x) % p;
            }
 
        // y must be even now
        y = y>>1; // y = y/2
        x=(x*x)%p;
        
    }
    return res%p;
}
 
long long int gcd(long long int a,long long int b) 
{ 
    if (a == 0) 
        return b; 
    return gcd(b % a, a); 
}
 
long long int binomialCoeff(long long int n, ll k) 
{ 
    ll res = 1; 
  
    // Since C(n, k) = C(n, n-k) 
    if (k > n - k) 
        k = n - k; 
  
    // Calculate value of [n*(n-1)*---*(n-k+1)] / [k*(k-1)*---*1] 
    for (ll i = 0; i < k; ++i) 
    { 
        res *= (n - i); 
        res /= (i + 1); 
    } 
  
    return res; 
} 
 

void sieve(int n, vector<ll> &primes) 
{ 
    vector<int> prime(n,1);
    ll p;
    for ( p=2; p*p<=n; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == 1) 
        { 
            
            for (int i=p*p; i<=n; i += p) 
                prime[i] = 0; 
        } 
    } 
  
    for(p=2;p<=n;p++)
    {
        if(prime[p])
        primes.pb(p);
    }
   
} 


void dfs(vector<ll> adj[] ,ll src,vector<ll> &vis)
{
    vis[src]=1;
    for(ll i=0;i<adj[src].size();i++)
    {
        if(vis[adj[src][i]]==0)
        dfs(adj,adj[src][i],vis)
    }
}
 
*/

int main() {
	ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);
    std::cout.tie(NULL);
    
    
	ll n,i,j,p,k,m,t,ans=0;
    cin>>n>>t;
    ll dp[3005][3005];
    memset(dp, 0, sizeof(dp)); 
    vector<ll> a(n),b(n);
    vector<pair<ll,ll> > val(n);
    for(i=0;i<n;i++)
    {
        cin>>a[i]>>b[i];
        val[i].F=a[i];
        val[i].S=b[i];
    }
    sort(val.begin(),val.end());
    for(i=0;i<n;i++)
    {
        a[i]=val[i].F;
        b[i]=val[i].S;
    }
    for(i=0;i<t;i++)
    {
        for(j=0;j<n;j++)
        {
            if(i+a[j]<t)
            {
                dp[j+1][i+a[j]] = max(dp[j][i]+b[j],dp[j+1][i+a[j]]);
            }
            
            dp[j+1][i] = max(dp[j][i],dp[j+1][i]);
            
        }
    }
    for(i=0;i<n;i++)
    {
        ans=max(ans,dp[i][t-1]+b[i]);
    }
    cout<<ans<<endl;
    
    // for(i=0;i<n;i++)
    // {
    //     cout<<a[i]<<" ";
    // }
    // cout<<endl;
    
	return 0;
}

Measured memory_bytes: 74264
import java.io.BufferedInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/**
 * Created by Harry on 5/10/20.
 */
public class Main {
    public static void main(String[] args) throws IOException {
        Scanner scanner = new Scanner(new BufferedInputStream(System.in));
        String s = scanner.next();
        String t = scanner.next();
        boolean res = t.length() == s.length()+1 && t.substring(0, t.length()-1).equals(s);
        System.out.print(res ? "Yes" : "No");
    }
}


Measured memory_bytes: 35676
// ABC153C.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

//#include "pch.h"
#include <iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
	int N;
	cin >> N;
	int K;
	cin >> K;
	vector<int>H(N);
	for (int i = 0; i < N; i++)
	{
		cin >> H.at(i);
	}
	sort(H.begin(), H.end(), greater<int>()); // 降順ソート
	long long ans = 0;
	for (int i = K; i < N; i++)
	{
		ans += H.at(i);
	}
	cout << ans << endl;
}


Measured memory_bytes: 1024
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <functional>
#include <cmath>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define MOD (ll)1000000007

ll p[10001], c[10001];
ll t[10001];

int main(void)
{
	ll n, kk, answer = -1e9;
	scanf("%lld %lld", &n, &kk);
	for (ll i = 1; i <= n; i++)
		scanf("%lld", &p[i]);
	for (ll i = 1; i <= n; i++)
		scanf("%lld", &c[i]);

	for (ll i = 1; i <= n; i++)
	{
		ll k = kk;
		//printf("\nstart : %lld\n", i);
		ll temp = c[p[i]], how = 1;
		t[how] = temp;
		ll start = i, cur = p[i];
		
		while (cur != start)
		{
			cur = p[cur];
			how++;
			temp += c[cur];
			t[how] = temp;
		}
		
		//for (ll j = 1; j <= how; j++)
		//	printf("%lld ", t[j]);
		//printf("\n");

		ll ans = -1e9, cycle = (k - 1LL) / how;
		k -= cycle * how;

		//printf("cycle : %lld, k = %lld\n", cycle, k);

		for (ll j = 1; j <= k; j++)
			ans = max(ans, t[j]);
		if (t[how] > 0)
			ans += cycle * t[how];
		else if (cycle > 0)
		{
			for (ll j = 1; j <= how; j++)
				ans = max(ans, t[j]);
		}
		//printf("ans : %lld\n", ans);
		answer = max(ans, answer);
	}
	printf("%lld", answer);
	return 0;
}

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

public class Main {
	
	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int N = Integer.parseInt(br.readLine());
		String str = br.readLine();
		
		int res = 1;
		for(int i=1;i<N;i++){
			char ch = str.charAt(i);
			char prev = str.charAt(i-1);
			
			if (ch != prev){
				res++;
			}
		}
		System.out.println(res);
	}
}

Measured memory_bytes: 23124
#include <iostream>
    #include <algorithm>
        
    int main(void) {
      int n;
      std::cin >> n;
      
      int sum = 0;
      int tmpn = n;
      while(tmpn) {
        sum += tmpn % 10;
        tmpn /= 10;
      }
      
      std::cout << ((n % sum == 0) ? "Yes" : "No") << std::endl;
      
      return 0;
    }

Measured memory_bytes: 256
function Main(input) {
  input = input.split('\n');
  const ans = input[0].split('S').map(str => str.length).reduce((a,b) => a > b ? a : b);
  console.log(ans);
}

//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 30364
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i,n,k) for(int i=(n);i<(k);i++)
#define ALL(a)  (a).begin(),(a).end()
ll ans=0;
const int INF = 2e9 + 1;
int x[4] = {-1, 0, 1, 0};
int y[4] = {0, 1, 0, -1};
int dp[1010][1010];
struct node{
    int d;
    int nx;
    int ny;
};
bool operator< (const node &l, const node &r){
    return l.d > r.d;
};
void Main(){
    int h, w;
    cin >> h >> w;
    h += 2;
    w += 2;
    int sh, sw, gh, gw;
    cin >> sh >> sw >> gh >> gw;
    vector<string> s(h);
    string str = "";
    For(i,0,w) str += '#';
    s[0] = str;
    s[h-1] = str;
    For(i,1,h-1){
        cin >> s[i];
        s[i] = '#' + s[i] + '#';
    }
    For(i,0,h) For(j,0,w) dp[i][j] = INF;
    dp[sh][sw] = 0;
    priority_queue<node> que;
    node init;
    init.d = 0;
    init.nx = sh;
    init.ny = sw;
    que.push(init);
    while(!que.empty()){
        auto now = que.top();
        node to;
        que.pop();
        if(now.nx == gh && now.ny == gw) break;
        bool flag = false;
        For(i,0,4){
            if(s[now.nx + x[i]][now.ny + y[i]] == '#'){
                flag = true;
                continue;
            }
            if(dp[now.nx + x[i]][now.ny + y[i]] > now.d){
                dp[now.nx + x[i]][now.ny + y[i]] = now.d;
                to.d = now.d;
                to.nx =  now.nx + x[i];
                to.ny = now.ny + y[i];
                que.push(to);
            }
        }
        if(flag){
            For(i, -2, 3){
                if(clamp(now.nx + i, 0, h-1) != now.nx + i) continue;
                For(j, -2, 3){
                    if(clamp(now.ny + j, 0, w-1) != now.ny + j) continue;
                    if(s[now.nx + i][now.ny + j] == '#') continue;
                    if(dp[now.nx + i][now.ny + j] > now.d + 1){
                        dp[now.nx + i][now.ny + j] = now.d + 1;
                        to.d = now.d + 1;
                        to.nx =  now.nx + i;
                        to.ny = now.ny + j;
                        que.push(to);
                    }               
                }
            }
        }
    }
    /*For(i,0,h){
        For(j,0,w){
            cout << dp[i][j] << " \n"[j==w-1];
        }
    }*/
    if(dp[gh][gw] == INF) cout << -1 << endl;
    else cout << dp[gh][gw] << endl;
}
int main(){
    Main();
    /*
    東方風神録は神が出てくるので当然神ゲー
    */
    return 0;
}

Measured memory_bytes: 9624
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>

using namespace std;

typedef long long int ll;

const ll MOD = 1000000007;

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

  int A, B, C;
  cin >> A >> B >> C;

  cout << max(0, B + C - A) << endl;

  return 0;
}


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

int main(){
    int q;
    long long a[100],b[100];
    cin >> q;
    for(int i=0; i<q; i++)
    cin >> a[i] >> b[i];

    for(int i=0; i<q; i++){
        long long ans=0;
        if(a[i]==b[i] || a[i]+1==b[i])
        ans=(a[i]-1)*2;
        else if(a[i]==b[i]+1)
        ans=(b[i]-1)*2;
        else{
            ans=sqrt(a[i]*b[i]);
            if(a[i]*b[i]<=ans*ans)
            ans--;
            if(ans*(ans+1)>=a[i]*b[i])
            ans=ans*2-2;
            else
            ans=ans*2-1;
        }
        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 256
# include <iostream>
# include <sstream>
# include <cstdio>
# include <cstdlib>
# include <algorithm>
# include <string>
# include <cstring>
# include <cmath>
# include <stack>
# include <queue>
# include <vector>
# include <list>
# include <map>
# include <set>
# include <deque>
# include <iterator>
# include <functional>
# include <bitset>
# include <climits>
# include <ctime>
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define odd(x) (x&1)
typedef long long ll;
typedef long double ld;
const ll oo = 2 * 1000 * 1000 * 1000;
const int _cnt = 1000 * 1000;
const int _p = 1000 * 1000 * 1000 + 7;
ll o(ll x) { return x%_p; }
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }
int lcm(int a, int b) { return a / gcd(a, b)*b; }
using namespace std;

void file_put() {
	freopen("filename.in", "r", stdin);
	freopen("filename.out", "w", stdout);
}

int w, a, b, c, d, ans = 0;

int main() {
	//file_put();

	scanf("%d%d%d", &w, &a, &b);
	c = a + w;
	d = b + w;
	if (b >= c) ans = b - c;
	if (a >= d) ans = a - d;
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cstring>
using namespace std;
int main()
{
	long long n, a, b;
	cin >> n>>a>>b;
	long long ans = 0, sum = 0;
	ans = n / (a + b);
	sum += ans * a;
	ans = n % (a + b);
	if (ans >= a)
		sum+=a;
	else
		sum += ans;

	cout << sum << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdio>

using namespace std;

#define loop(i, n) for (int i = 0; i < n; i++) 

int main()
{
    int a, b, c;
    while (cin >> a >> b >> c) {
        int era = 0;
        if (a < 1868) {
            era = 1;
        } else if (a == 1868) {
            if (b < 9) {
                era = 1;
            } else if (b == 9) {
                if (c < 8) {
                    era = 1;
                } else {
                    era = 2;
                }
            } else {
                era = 2;
            }
        } else if (a < 1912) {
            era = 2;
        } else if (a == 1912) {
            if (b < 7) {
                era = 2;
            } else if (b == 7) {
                if (c < 30) {
                    era = 2;
                } else {
                    era = 3;
                }
            } else {
                era = 3;
            }
        } else if (a < 1926) {
            era = 3;
        } else if (a == 1926) {
            if (b < 12) {
                era = 3;
            } else if (b == 12) {
                if (c < 25) {
                    era = 3;
                } else {
                    era = 4;
                }
            } else {
                era = 4;
            }
        } else if (a < 1989) {
            era = 4;
        } else if (a == 1989) {
            if (b < 1) {
                era = 4;
            } else if (b == 1) {
                if (c < 8) {
                    era = 4;
                } else {
                    era = 5;
                }
            } else {
                era = 5;
            }
        } else {
            era = 5;
        }
        if (era == 1) {
            cout << "pre-meiji" << endl;
        } else {
            if (era == 2) {
                cout << "meiji " << a - 1867 << " ";
            } else if (era == 3) {
                cout << "taisho " << a - 1911 << " ";
            } else if (era == 4) {
                cout << "showa " << a - 1925 << " ";
            } else if (era == 5) {
                cout << "heisei " << a - 1988 << " ";
            }
            cout << b << " " << c << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3076
#include<bits/stdc++.h>
#define ll long long int
#define endl '\n'
#define M 1000000007
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
#define f first
#define s second
#define b begin
#define e end
#define pb push_back
#define mp make_pair
#define FOR(i,a,b) for(i=a;i<b;i++)
#define RFOR(i,a,b) for(i=a;i>=b;i--)
#define all(x) x.begin(),x.end()
#define itfr(it,x) for(it=x.begin();it!=x.end();it++)
#define flash ios_base::sync_with_stdio(false); cin.tie(NULL)
using namespace std;

int main()
{
    flash;
    //sieve();
    ll T=1,t,n,i,j;
    // cin>>T;
    while(T--)
    {
        cin>>n>>j;
        vector<string> vs(n);
        FOR(i,0,n)
            cin>>vs[i];
        sort(all(vs));
        for(auto it:vs)
            cout<<it;
        cout<<endl;
    }
}

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

int n,a,b;
long long ans;
int main()
{
	scanf("%d%d%d",&n,&a,&b);
	if (b-a<=2) ans=n+1; else {
		ans=1;
		ans+=min(n,a-1); n-=min(n,a-1);
		ans+=1ll*(b-a)*(n/2); n&=1;
		if (n) ans++;
	}
	printf("%lld\n",ans);
	return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<int>a(n+1);
  vector<int>b(n+1,0);
  vector<int>ans(0);
  for(int i = 1;i <= n;i++){
    cin >> a[i];
  }
  for(int i = n;i >= 1;i--){
    int sum = 0;
    for(int j = i+i;j <= n;j += i){
      sum += b[j];
    }
    if(sum%2 != a[i]){
      b[i]++;
      ans.push_back(i);
    }
  }
  cout << ans.size() << endl;
  for(int i = 0;i < ans.size();i++){
    cout << ans[i];
    if(i != ans.size()-1) cout << " ";
  }
  cout << "" << endl;
}


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) { cout << #v << "=" << endl; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << endl; }
#define mdebug(m) { cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;} }
#define pb push_back
#define fi first
#define se second
#define int long long
#define INF 1000000000000000000
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); i++) { cout << v[i]; if(i != v.size() - 1) cout << endl; }; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p){ cout << '(' << p.first << ',' << p.second << ')'; return os; }
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void chOut(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }

using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using v_bool = vector<bool>;
using v_Pii = vector<Pii>;

//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//char d[4] = {'D','R','U','L'};

const int mod = 1000000007;
//const int mod = 998244353;



signed main(){

    int N, K; cin >> N >> K;
    vec A(N); cin >> A;

    int x0 = 0, x1 = 10000000000;
    while(x1 - x0 > 1){
        int x = (x0 + x1) / 2;
        int cnt = 0;
        REP(i, N){
            cnt += (A[i] - 1) / x;
        }
        if(cnt <= K) x1 = x;
        else x0 = x;
    }
    Out(x1);

    return 0;
}


Measured memory_bytes: 4776
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
using namespace std;
const int MAXN = 1e5 + 10;

struct vec {
    double x, y;
    double p;
    vec() {}
    vec(double a, double b)
    {
        x = a, y = b;
    }
    bool operator>(const vec a) const
    {
        return x == a.x ? y > a.y : x > a.x;
    }
    vec operator-(const vec a) const
    {
        return vec(x - a.x, y - a.y);
    }
    vec operator+(const vec a) const
    {
        return vec(x + a.x, y + a.y);
    }
    bool operator<(const vec a) const
    {
        return y == a.y ? x < a.x : y < a.y;
    }
    friend ostream& operator<<(ostream& out, vec& a)
    {
        cout << a.x << ' ' << a.y;
        return out;
    }
    friend istream& operator>>(istream& in, vec& a)
    {
        in >> a.x >> a.y;
        return in;
    }
} p[MAXN];
int n;
double chaji(vec A, vec B)
{
    return A.x * B.y - A.y * B.x;
}
double xuanzhuan(vec a, vec b, vec c)
{
    return chaji(b - a, c - a);
}
double changdu(vec a) //长度
{
    return sqrt(a.x * a.x + a.y * a.y);
}
vec q[MAXN];
double tubao_zhijing(int tail) //求出直径
{
    double re = 0;
    if (tail == 1) //仅有两个点
        return changdu(q[1] - q[0]);
    q[0] = q[n]; //把第一个点放到最后
    //q[tail+1]=q[1];
    for (int i = 0, j = 2; i < tail; i++) //枚举边
    {
        while (xuanzhuan(q[i], q[i + 1], q[j]) < xuanzhuan(q[i], q[i + 1], q[j + 1]))
            j = (j + 1) % tail;
        re = max(re, max(changdu(q[j] - q[i]), changdu(q[j] - q[i + 1])));
    }
    return re;
}

int main()
{
   // freopen("txt.txt", "w", stdout);
    cin >> n;
    for (int i = 1; i <= n; i++)
        cin >> q[i];
    int tail = n;
    printf("%.6f\n", tubao_zhijing(tail));
    return 0;
}


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

int pm(int y, int m) {
    int sum = 0;
    int s[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
    for (int i = 0; i < m - 1; i++) {
        sum += s[i];
        if (i == 1 && y % 4 == 0 && (y % 100 != 0 || y % 400 == 0)) sum += 1;
    }
    return sum;
}

int main() {
    int y1,y2,m1,m2,d1,d2;
    while (cin >> y1 >> m1 >> d1 >> y2 >> m2 >> d2,
           y1 > -1 && y2 > -1 && m1 > -1 && m2 > -1 && d1 > -1 && d2 > -1) {
        y1--;
        int t1 = y1 * 365 + (y1 / 400) - (y1 / 100) + (y1 / 4);
        y1++;
        t1 += d1;
        t1 += pm(y1, m1);

        y2--;
        int t2 = y2 * 365 + (y2 / 400) - (y2 / 100) + (y2 / 4);
        y2++;
        t2 += d2;
        t2 += pm(y2, m2);

        cout << t2 - t1 << endl;
    }

    return 0;
}

Measured memory_bytes: 3024
#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<cctype>
#include<vector>
#include<stack>
#include<queue>
#include<ctime>
#include<map>
#define ll long long
#define ld long double
#define ull unsigned long long
using namespace std;
const ll mod = 998244353;
const int maxn = 101001;
ll a[maxn];
ll mul(ll x,ll y,ll z)
{
    ll sm = (ld)x/z*y;
    return ((ull)x*y-(ull)sm*z+z)%z;
}
ll qpow(ll x,ll y,ll z)
{
    ll ans = 1;
    x %= z;
    for(ll i=y;i;i>>=1){
        if(i&1) ans = mul(ans,x,z);
        x = mul(x,x,z);
    }
    return ans%z;
}
int main(void)
{
    int n,x;
    scanf("%d",&n);
    cin>>x;
    if(x!=0){
        printf("0\n");
        return 0;
    }
    a[x]++;
    for(int i=1;i<n;i++){
        scanf("%d",&x);
        a[x]++;
    }
    if(a[0]>1){
        printf("0\n");
        return 0;
    }
    int ret = 0;
    ll ans = 1,pr = 1;
    for(int i=0;i<n;i++){
        if(a[i]==0){
            if(ret!=n)  ans = 0;
            break;
        }
        ans = mul(ans,qpow(pr,a[i],mod),mod);
        pr = a[i];
        ret += (int)a[i];
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 1024
n = int(input())
full_set=set([1,2,3,4,5,6,7,8,9,10,11,12,13])
S=[]
H=[]
C=[]
D=[]
for i in range(n):
    suit,num = input().split()
    if   suit=="S": S.append(int(num))
    elif suit=="H": H.append(int(num))
    elif suit=="C": C.append(int(num))
    elif suit=="D": D.append(int(num))
S_set=set(S)
H_set=set(H)
C_set=set(C)
D_set=set(D)
for (suit,suit_set) in zip(["S","H","C","D"],[S_set,H_set,C_set,D_set]):
    for num in sorted(list(full_set - suit_set)): print(suit,num)

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

int main(void) {
    int N, a, i;
    char S[10];
    int c0 = 0, c1 = 0, c2 = 0, c3 = 0;

    a = scanf("%d",&N);

    for(i = 0; i <= N; i++){
        fgets(S, 10, stdin);
        S[strlen(S)-1] = '\0';

        if(strcmp(S, "AC") == 0) c0++;
        else if(strcmp(S, "WA") == 0) c1++;
        else if(strcmp(S, "TLE") == 0) c2++;
        else if(strcmp(S, "RE") == 0) c3++;
    }

    printf("AC x %d\n", c0);
    printf("WA x %d\n", c1);
    printf("TLE x %d\n", c2);
    printf("RE x %d\n", c3);

    return 0;
}

Measured memory_bytes: 1708
#include <stdio.h>
#include <string.h>

int main(void)
{
    char s[101];
    int k;
    scanf("%d\n%s\n", &k, s); //整数入れるときは&をつける

    if (strlen(s) > k) {
        s[k] = 0;
        printf("%s...\n", s);
    }
    else {
        printf("%s\n", s);
    }
    return 0;
}


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

int main() {
  string s, t, r;
  cin >> s >> t >> r;
  string ans = "NO";
  if (s.at(s.size()-1) == t.at(0)) {
    if (t.at(t.size()-1) == r.at(0)) {
      ans = "YES";
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	scanInit()

	n := nextInt()
	t := nextInt()
	tl := make([]int, n)

	sum := 0
	tl[0] = nextInt()
	for i := 1; i < n; i++ {
		tl[i] = nextInt()
		if tl[i] > tl[i-1]+t {
			sum += t
		} else {
			sum += tl[i] - tl[i-1]
		}
	}
	sum += t
	fmt.Println(sum)
}

// ---- readfunc
var sc = bufio.NewScanner(os.Stdin)

func scanInit() {
	const cap = 200 * 1024 // default=64*1024
	var buf = make([]byte, cap)
	sc.Buffer(buf, cap)
	sc.Split(bufio.ScanWords)
	return
}
func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 6148
#include <bits/stdc++.h>
using namespace std;
 
#define pb push_back
typedef long long int ll;
typedef vector<ll> vl;
typedef map<ll,ll> ii;
typedef vector<vl> vvl;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    ll t;cin>>t;
    map<ll,vl> d;
    ll p=0;
    ll w;
    vector<pair<ll,ll>> lol;
    t--;
    while(t--){
        ll a,b;cin>>a>>b;
        d[a].pb(b);
        d[b].pb(a);
        lol.pb({a,b});
        ll x=d[a].size();
        ll y=d[b].size();
        ll c=max(x,y);
        if(c>p){
            if(x>y) w=a;
            else w=b;
            p=c;    
        }
    }
    queue<ll> q;q.push(w);
    ii vis;
    vis[w]=1;
    map<pair<ll,ll>,ll> m;
    queue<ll> v;v.push(0);
    while(!q.empty()){
        ll a=q.front();q.pop();
        ll b=v.front();v.pop();
        for(ll i:d[a]){
            if(!vis[i]){
                q.push(i);
                m[{a,i}]=b;
                m[{i,a}]=b;
                b++;
                b%=p;
                v.push(b);
                vis[i]=1;
            }
        }
    }
    cout<<p<<"\n";
    
    for(pair<ll,ll> i:lol){
        cout<<(m[{i.first,i.second}]+1)<<"\n";
    }
    return 0;
}

Measured memory_bytes: 32368
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int) n; i++)
using ll = long long;
template <class T>
using vt = vector<T>;
using vvi = vector<vector<int>>;

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

  //solve
  int ans = 1;
  while(n>1){
    n /= 2;
    ans *= 2;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
a,b = map(int, input().split())
x = list(map(int, input().split()))
#dp = [0]+[10**10]*(a-1)
dp = [0]+[float("inf")]*(a-1)
dp[1] = abs(x[1]-x[0])
for i,h in enumerate(x):
    for j in range(max(0,i-b),i):
        dp[i] = min(dp[i],dp[j]+abs(h-x[j]))
        #print(dp)
#print(dp)
print(dp[a-1])

Measured memory_bytes: 55136
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#define pii pair<int,int>
#define F first
#define S second
#define ericxiao ios_base::sync_with_stdio(0);cin.tie(0);
#define endl '\n'
using namespace std;

const int maxN = 2e5 + 10;

int N, u, v;
vector<int> adj[maxN];
vector<int> ans, dia;

pii getFar(int p, int u){
    pii pp = {0, u};
    for(int v : adj[u]){
        if(v == p) continue;
        pp = max(getFar(u, v), pp);
    }
    pp.F++;
    //cout << "Res for u = " << u << ": " << pp.F << ", " << pp.S << endl;
    return pp;
}

inline void getDia(int a){
    int current = a, prev = a;
    dia.push_back(a);
    current = adj[current][0];
    bool hasFound;
    while(true){
        //cout << "Current = " << current << endl;
        dia.push_back(current);
        hasFound = false;
        if(adj[current].size() == 1) break;
        else{
            for(int u : adj[current]){
                if(u == prev) continue;
                if(adj[u].size() > 1){
                    prev = current;
                    current = u;
                    hasFound = true;
                    break;
                }
            }
            if(!hasFound){
                for(int u : adj[current]){
                    if(adj[u].size() == 1){
                        current = u;
                        break;
                    }
                }
            }
        }
    }
}

vector<int> getPer(vector<int> dia){
    bool isRoot = true;
    vector<int> res = vector<int>(N);
    int currentId = 0, cnt = 1, sz, lim;
    for(int u : dia){
        //cout << "Checking u = " << u << endl;
        if(adj[u].size() == 1){
            sz = adj[u].size() - 1;
        } else {
            sz = adj[u].size() - 2;
        }
        //cout << "sz = " << sz << endl;
        res[currentId + sz] = cnt++;
        lim = currentId + sz;
        for(; currentId < lim; currentId++) res[currentId] = cnt++;
        currentId++;
        //for(int u : res) cout << u << " "; cout << endl;
    }
    return res;
}

bool isLess(vector<int> a, vector<int> b){
    for(int i = 0; i < N; i++){
        if(a[i] < b[i]) return true;
        else if(a[i] > b[i]) return false;
    }
}

int main(){
    ericxiao;
    cin >> N;
    for(int i = 0; i < N - 1; i++){
        cin >> u >> v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    pii p1 = getFar(1, 1), p2;
    int a = p1.S;
    p2 = getFar(a, a);
    int b = p2.S;
    // cout << a << " " << b << endl;
    getDia(a);
    int sum = 0;
    for(int u : dia){
        if(adj[u].size() == 1) sum++;
        else sum += adj[u].size() - 1;
    }
    if(sum != N){
        cout << -1 << endl;
        return 0;
    }
    //cout << "DIA: " << endl;
    //for(int u : dia) cout << u << " "; cout << endl;
    vector<int> res1 = getPer(dia);

    for(int u : res1){
        if(!u){
            cout << -1 << endl;
            return 0;
        }
    }
    reverse(dia.begin(), dia.end());
    vector<int> res2 = getPer(dia);
    if(isLess(res1, res2)){
        for(int u : res1) cout << u << " ";
    } else {
        for(int u : res2) cout << u << " ";
    }
    cout << endl;

}


Measured memory_bytes: 18416
#include <cstdio>
#include <algorithm>
#include <vector>
#include <utility>
#include <functional>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <cstring>
#include <string>
#include <cmath>
#include <iostream>

using namespace std;
typedef long long lli;
typedef pair<int,int> pii;
typedef pair<lli,int> pli;
typedef pair<lli,lli> pll;

int n,a[50],b[50];

bool check(lli state) {
	for(int i=0;i<n;i++) {
		int vis[51] = {0,};
		vis[a[i]] = 1;
		for(int j=50;j;j--) {
			if(state & (1ll<<j)) {
				for(int k=0;k<=50;k++) if(vis[k]) {
					vis[k % j] |= 1;
				}
			}
		}
		if(!vis[b[i]]) return false;
	}
	return true;
}
int main() {
	scanf("%d",&n);
	for(int i=0;i<n;i++) scanf("%d",a+i);
	for(int i=0;i<n;i++) scanf("%d",b+i);

	lli ans=0;
	for(int i=50;i;i--) {
		if(!check(ans | ((1ll<<i)-1))) ans |= 1ll<<i;
	}
	printf("%lld\n",check(ans) ? ans : -1ll);
	
	return 0;
}


Measured memory_bytes: 256
def main():
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    if sum(A) > sum(B):
        print('No')
        exit()
    
    cnt = 0
    for i in range(N):
        if B[i] > A[i]:
            cnt += (B[i] - A[i]) // 2
        else:
            cnt -= (A[i] - B[i])

    if cnt >= 0:
        print('Yes')
    else:
        print('No')
    


if __name__ == "__main__":
    main()

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

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

int main(){

  int n, k;
  cin >> n >> k;
  
  int g = 0, m = 0;
  for(int i=0; i<n; i++){
    int x;
    cin >> x;
    g = gcd(x, g);
    m = max(x, m);
  }

  if(k <= m && k % g == 0) cout << "POSSIBLE";
  else cout << "IMPOSSIBLE";
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;
#define MOD 1000000000 + 7
int main(){
  int N;
  cin >> N;
  long long A[N];
  long long sum(0);
  long long sum_A(0);
  for(int i = 0 ; i < N ; ++i)
  {
    cin >> A[i];
    sum += (A[i] * sum_A) % (MOD);
    sum %= (MOD);
    sum_A += A[i];
    sum_A %= (MOD);
  }
  cout << sum << endl;
  return 0;
}

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

using namespace std;

#define fastio cin.tie(NULL);cout.tie(NULL);ios_base::sync_with_stdio(0);
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define MAXN 200005
#define INF 0x3f3f3f3f
#define LINF 0x3f3f3f3f3f3f3f3f
#define MOD 1000000007
#define pb push_back
#define endl '\n'
#define int long long

typedef long long ll;
typedef pair <int, int> pii;
typedef vector <int> vi;
typedef vector <pii> vii;
typedef vector <vi> matriz;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// auto timer_start = chrono::steady_clock::now().time_since_epoch().count();

int a, b, c, n, m, k;
string s, t, u;

int32_t main(){
    fastio
    cin >> s;
    bool ver = true;
    for(int i = 0; i < sz(s); i++){
        if(!(i & 1)){
            ver = ver and (s[i] == 'R' or s[i] == 'U' or s[i] == 'D');
        } else ver = ver and (s[i] == 'L' or s[i] == 'U' or s[i] == 'D');
    }
    cout << (ver ? "Yes" : "No") << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll n, k, p;
int main(){
	cin>>n>>k;
	p=n/k;
	if(k%2==1){
		cout<<p*p*p;
		return 0;
	}
	else {
		ll q=(n+k/2)/k, x=0;
		cout<<p*p*p+q*q*q;
		return 0;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <array>
#include <algorithm>
#include <cmath>
#include <vector>
using namespace std;

int H, W;
array<array<int, 10>, 10> c;

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

    cin >> H >> W;

    for(auto& c1 : c) for(auto& c2 : c1){
        cin >> c2;
    }

    for(int k = 0; k < 10; ++k) for(int i = 0; i < 10; ++i) for(int j = 0; j < 10; ++j){
        c[i][j] = min(c[i][j], c[i][k] + c[k][j]);
    }

    int ans = 0;
    for(int i = 0; i < H; ++i) for(int j = 0; j < W; ++j){
        int A;
        cin >> A;
        if(A != -1 && A != 1){
            ans += c[A][1];
        }
    }
    cout << ans << endl;

    return 0;
}

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

int main()
{
	long long n,ans=0;
	string s;
	cin>>n>>s;
	long long r[n+10]={0},g[n+10]={0},b[n+10]={0},sr=0,sg=0,sb=0;
	for(int i=n-1;i>=0;i--)
	{
		r[i]=sr;
		g[i]=sg;
		b[i]=sb;
		if(s[i]=='R'){sr++;r[i]++;}else
		if(s[i]=='G'){sg++;g[i]++;}else
		{sb++;b[i]++;}
	}
	for(int i=0;i<n;i++)
	{
		for(int j=i+1;j<n;j++)
			{
				if(s[j]!=s[i])
				{
					if(s[i]!='B' && s[j]!='B')
					{
						ans+=b[j+1];
						if((j+(j-i))<n && s[j+(j-i)]=='B')ans--;
						// else if(j+1<n)ans+=b[j+1];
					}
					else if(s[i]!='R' && s[j]!='R')
					{
						ans+=r[j+1];
						if((j+(j-i))<n && s[j+(j-i)]=='R')ans--;
						// else if(j+1<n)ans+=r[j+1];
					}
					else
					{
						ans+=g[j+1];
						if((j+(j-i))<n && s[j+(j-i)]=='G')ans--;
						// else if(j+1<n)ans+=g[j+1];
					}
					// cout<<ans<<"\n";
				}
			}
		}
	cout<<ans;
}


Measured memory_bytes: 3688
#include <iostream>
#include <queue>
#include <string>
#include <algorithm>

using namespace std;

void a(){
    int A, P; cin >> A >> P;

    int p = A*3 + P;
    cout << p/2;

}

void b(){
    int N; cin >> N;
    vector<pair<string,int>> vec(N);
    for(int i = 0; i < N; i++){
        string s; cin >> s;
        int p; cin >> p;

        vec[i] = make_pair(s,-p);
    }
    vector<int> idx(N);
    for(int i = 0; i < N; i++){
        idx[i] = i;
    }

    sort(idx.begin(),
         idx.end(),
         [&vec](int idx1, int idx2){return (vec[idx1] < vec[idx2]);}
    );


    for(int i = 0; i < N; i++){

        cout << idx[i] + 1 << endl;
    }

}

bool is_mem(int bit, int i){

    return bit & (1 <<i);
}

bool is_lamp_on(int bit, const vector<int> &connected, int p){
    int on_switch = 0;
    for(int n: connected){
        if (is_mem(bit, n)) on_switch++;
    }

    return (on_switch%2 == p);

}
void c(){
    int N, M; cin >> N >> M;

    vector<vector<int>> connect(M);
    for(int i = 0; i < M; i++){

        int k; cin >> k;
        for(int j = 0;j<k; j++ ){
            int s_ij; cin >> s_ij; s_ij--;
            connect[i].push_back(s_ij);
        }
    }
    vector<int> p_vec(M);
    for(int i = 0; i < M; i++){
        cin >> p_vec[i];
    }

    int count = 0;
    for(int bit = 0; bit < (1<<N); ++bit){
        bool all_on = true;
        for(int m = 0; m < M; m++){// 全てonになるか？
            if (!is_lamp_on(bit, connect[m], p_vec[m])) {
                all_on = false;
                break;
            }
        }
        if (all_on) count++;
    }

    cout << count;

}

int calc_value(vector<int> & vec, int l, int r, int k){
    int N = vec.size();
    priority_queue<int, vector<int>, greater<int> > minus_value;
    int sum = 0;
    for(int i = 0; i < l; i++){
        sum += vec[i];
        if (vec[i] < 0) minus_value.push(vec[i]);
    }
    for(int i = N-1; N - r <= i; i--){
        sum += vec[i];
        if (vec[i] < 0) minus_value.push(vec[i]);
    }

    int remain = k - (l+r);
    while(remain >0 && !minus_value.empty()){
        remain--;
        int top = minus_value.top();
        sum += -top;
        minus_value.pop();
    }

    return sum;

}
void d(){
    int N; int K; cin >> N >> K;

    vector<int> vec(N);
    for(int i = 0; i < N; i++){
        cin >> vec[i];
    }
    int max_value = 0;
    for(int l = 0; l <=K; l++)
        for(int r = 0; l + r <= K && l + r <= N;r++){
            int value = calc_value(vec, l,r,K);
            max_value = max(max_value, value);
        }

    cout << max_value;

}
int main(){
    d();
}

Measured memory_bytes: 256