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

#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,x,n) for(int i=x; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)
#define all(X) (X).begin(),(X).end()
#define X first
#define Y second
#define pb push_back
#define eb emplace_back

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

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

template<class A, size_t N, class T> void Fill(A (&a)[N], const T &v){ fill( (T*)a, (T*)(a+N), v ); }

template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {os<<"{"; rep(i,t.size()) {os<<t[i]<<",";} os<<"}"; return os;}
template<class T,size_t n> ostream& operator<<(ostream &os, const array<T,n> &t) {os<<"{"; rep(i,n) {os<<t[i]<<",";} os<<"}"; return os;}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}

const ll INF = 1e9+7;


int main(){
	ios_base::sync_with_stdio(false);
	int N, ans=0;
	ll a[100005];

	cin >> N;
	rep(i,N) cin >> a[i];

	rep(i,N) ans += (a[i] % 2);

	cout << (ans > 0 ? "first" : "second") << endl;

	return 0;
}

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

typedef long long ll;

int main()
{
  int n, k;
  cin >> n >> k;
  vector<int>v(n);
  for(int i=0;i<n;i++)cin >> v[i];
  vector<int>dp(n,0);
  for(int i=1;i<n;i++)
  {
      dp[i]=INT_MAX;
      for(int j=1;j<=k && (i-j)>=0;j++)
      {
          dp[i] = min(abs(v[i-j]-v[i])+dp[i-j],dp[i]);
      }
  }
  cout << dp[n-1]<<endl;
    return 0;
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main()
{
	long long a,b,c,mx,mx2,mn;
	cin>>a>>b>>c;
	mx = max(a,max(b,c));
	mn = min(a,min(b,c));
	mx2 = (a + b + c) - (mx + mn);
	a = ((mx / 2) * mn * mx2);
	b = (((mx - (mx / 2))) * mn * mx2);
	cout<<abs(a- b);	
}

Measured memory_bytes: 256
x1, y1, x2, y2 = map(int, input().split())

sides = x2 - x1 + y2 - y1

x3 = x2 - (y2 - y1)
x4 = x1 - (y2 - y1)
y3 = y2 + (x2 - x1)
y4 = y1 + (x2 - x1)

print(x3, y3, x4, y4)

Measured memory_bytes: 3060
from networkx import*
N,*t=open(0)
G=Graph()
for s in t:a,b=s.split();G.add_edge(a,b)
s=shortest_path_length
x=s(G,'1')
y=s(G,N[:-1])
print('FSennunkeec'[sum(x[k]>y[k]for k in x)*2>=int(N)::2])

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

#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define EPS (1e-10)
#define equals(a,b) (fabs((a)-(b))<EPS)

using namespace std;

typedef long double ld;

const int MAX = 501,IINF = INT_MAX;
const ld LDINF = 1e100;
int H,W,sx,sy,gx,gy;
ld mincost[MAX][MAX][2]; // mincost[][][0] => from start, [1] = > from star
char c[MAX][MAX];
bool ban[MAX][MAX];
vector<int> star,plane;
int dx[] = {0,1,0,-1};
int dy[] = {1,0,-1,0};

inline bool isValid(int x,int y) { return 0 <= x && x < W && 0 <= y && y < H; }

inline void bfs(vector<int> sp,vector<int> Forbidden,int type){
  rep(i,H)rep(j,W) mincost[i][j][type] = LDINF, ban[i][j] = false;
  queue<int> que;
  rep(i,(int)sp.size()) que.push(sp[i]), mincost[sp[i]/W][sp[i]%W][type] = 0;
  rep(i,(int)Forbidden.size()) ban[Forbidden[i]/W][Forbidden[i]%W] = true;

  while(!que.empty()){
    int cur = que.front(); que.pop();
    rep(i,4){
      int nx = cur % W + dx[i], ny = cur / W + dy[i];
      if( c[ny][nx] == '#' ) continue;
      if( ban[ny][nx] ) continue;
      if( mincost[ny][nx][type] == LDINF ) {
        mincost[ny][nx][type] = mincost[cur/W][cur%W][type] + 1;
        que.push(nx+ny*W);
      }
    }
  }
}

bool check(ld E){
  ld T = 0;

  rep(i,(int)plane.size()){
    int x = plane[i] % W, y = plane[i] / W;
    T += min(mincost[y][x][0],mincost[y][x][1]+E);
  }

  ld len = plane.size();
  return len * E > T;
}

int main(){
  cin >> W >> H;
  rep(i,H)rep(j,W){
    cin >> c[i][j];
    if( c[i][j] == 's' ) sx = j, sy = i, c[i][j] = '.';
    if( c[i][j] == 'g' ) gx = j, gy = i;
    if( c[i][j] == '*' ) star.push_back(j+i*W);
    if( c[i][j] == '.' ) plane.push_back(j+i*W);
  }

  vector<int> sp,forbidden;
  sp.push_back(gx+gy*W);
  forbidden = star;
  forbidden.push_back(gx+gy*W);
  bfs(sp,forbidden,0);

  sp = star;
  forbidden.push_back(gx+gy*W);
  //forbidden.clear();
  bfs(sp,forbidden,1);

  ld L = 0, R = 1e50, M = 0;
  rep(i,220){
    M = ( L + R ) * (ld)0.5;
    if( check(M) ) R = M;
    else           L = M;
  }

  cout << setiosflags(ios::fixed) << setprecision(20) << min((ld)mincost[sy][sx][0],(ld)mincost[sy][sx][1]+L) << endl;

  return 0;
}

Measured memory_bytes: 10456
fun main(args: Array<String>) {
    val n = readInputLine().toInt()
    val aArr = readInputLine().split(" ").map{it.toInt()}
    
    var mult4 = 0
    var odd = 0
    
    for (a in aArr) {
        if (a % 4 == 0) {
            mult4++
            continue
        }
        
        if (a % 2 == 1) {
            odd++
        }
    }
    
    if (mult4 >= odd || (mult4 + odd == n && mult4 == odd - 1)) {
        println("Yes")
    } else {
        println("No")
    }
}

fun readInputLine(): String {
    return readLine()!!
}


Measured memory_bytes: 52172
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;

vi adj[100005];
int d1[100005];
int d2[100005];

void dfs(int x, int p, int* d)
{
    for (int y : adj[x])
    {
        if (y == p) continue;
        d[y] = d[x] + 1;
        dfs(y, x, d);
    }
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, u, v;
    cin >> n >> u >> v;
    for (int i = 1; i < n; ++i)
    {
        int u, v;
        cin >> u >> v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    dfs(u, 0, d1);
    dfs(v, 0, d2);
    int sol = 0;
    for (int i = 1; i <= n; ++i)
        if (d1[i] < d2[i])
            sol = max(sol, d2[i] - 1);
    cout << sol;
}


Measured memory_bytes: 11648
#include <vector>
#include <list>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>
#include <tuple>
#include <fstream>
#include<iostream>
#include <cmath>
#include <chrono>
#include <thread>
#include <stack>
#include <memory.h>
#include <numeric>
#include <iostream>
#include<climits>

//  vector<vector<int>> b(row_size, vector<int>(col_size,n));   //  n->initialized value

#define MOD 1000000007LL
#define ff first
#define fs second
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vll vector<long long>
#define vvi vector< vector <int> >
#define vpii vector< pair<int, int> >
#define pii pair<int,int>
#define mii map<int, int>
#define mp make_pair
#define tc                int T;cin>>T;while(T--)
#define fast_io            ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ll long long int

using namespace std;

vector<string> order;
map<string, bool> state;
map<string, vector<string>> path;


int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int n, W, totval = 0; cin >> n >> W;
    vector<pair<int, int>> items(n);
    for (auto& p : items)cin >> p.first >> p.second;
    for (auto& p : items)totval += p.second;
    vector<vector<int>> dp(n + 1, vector<int>(totval + 1));
    for (int i = 0; i <= totval; ++i)dp[1][i] = 1000000000+1;
    //for (int i = 0; i <= n; ++i)dp[i][0] = 0;
    dp[1][0] = 0;
    dp[1][items[0].second] = items[0].first;
    for (int i = 2; i <= n; ++i)
        for (int j = 0; j <= totval; ++j) {
            dp[i][j] = dp[i - 1][j];
            if (j>=items[i - 1].second) {
                dp[i][j] = min(dp[i][j], items[i - 1].first + dp[i - 1][j - items[i - 1].second]);
            }

        }
    for (int i = totval; i > -1; --i)if (dp[n][i] <= W) {
        cout << i << '\n'; break;
    }
    // printtable(dp);
    return 0;

}


Measured memory_bytes: 40192
import java.util.Arrays;
import java.util.Scanner;

public class Main {
  
  public static void main(String[] args) {
    
    Scanner sc = new Scanner(System.in);
    
    int N = Integer.parseInt(sc.next());
    int M = Integer.parseInt(sc.next());
    
    long xyz[][] = new long[4][N];
    int d[] = { -1, 1 };
    
    for (int i = 0; i < N; i++) {
      long x = Long.parseLong(sc.next());
      long y = Long.parseLong(sc.next());
      long z = Long.parseLong(sc.next());
      for (int j = 0; j < 2; j++) {
        for (int k = 0; k < 2; k++) {
          xyz[2 * j + k][i] = x + y * d[j] + z * d[k];
        }
      }
    }
    for (int i = 0; i < 4; i++) {
      Arrays.sort(xyz[i]);
    }
    
    long ans = 0, sum;
    for (int i = 0; i < 4; i++) {
      sum = 0;
      for (int j = 0; j < M; j++) {
        sum += -xyz[i][j];
      }
      ans = Math.max(ans, sum);
      sum = 0;
      for (int j = N - 1; j > N - 1 - M; j--) {
        sum += xyz[i][j];
      }
      ans = Math.max(ans, sum);
    }
    
    System.out.println(ans);
  }
}

Measured memory_bytes: 26068
h, w = [int(x) for x in input().split()]
masu = [input() for i in range(h)]
for i in range(h):
  for j in range(w):
    if all([masu[i][k] == '.' for k in range(w)]):
      break
    elif all([masu[k][j] == '.' for k in range(h)]):
      continue
    else:
      print(masu[i][j], sep='', end='')
  else:
    print('')
  

Measured memory_bytes: 4468
s = input()

s1 = int(s[0])*10 + int(s[1])
s2 = int(s[2])*10 + int(s[3])
#print(s1, s2)
if  (s1>12 or s1==0) and (s2>12 or s2==0):
  print('NA')
elif (s1>12 or s1==0) and 1<=s2<=12:
  print('YYMM')
elif (s2>12 or s2==0) and 1<=s1<=12:
  print('MMYY')
elif 1<=s1<=12 and 1<=s2<=12:
  print('AMBIGUOUS')

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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define FF first
#define SS second

#define DUMP(x) cout<<#x<<":"<<(x)<<endl
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class T>
istream& operator>>(istream& is, vector<T>& xs){
  for(auto& x: xs)
	is >> x;
  return is;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
ostream& operator<<(ostream& os, const vector<T>& xs){
  for(unsigned int i=0;i<xs.size();++i)
	os << (i?" ":"") << xs[i];
  return os;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

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

  VI xs(3);
  cin >> xs;
  int ans = 1e9;
  SORT(xs);
  do{
    mini(ans, abs(xs[0] - xs[1]) + abs(xs[1] - xs[2]));
  }while(next_permutation(ALL(xs)));

  cout << ans << endl;

  return 0;
}


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

int c[8] = {0, 1, 2, 3, 5, 7, 8, 9};
void solve(int n) {
  if(n >= 8) solve(n / 8);
  cout << c[n % 8];
}
int main() {
  int n;
  while(cin >> n, n) {
	solve(n);
	cout << "\n";
  }
  return 0;
}

Measured memory_bytes: 3024
#include<bits/stdc++.h>
#define fastio     ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define debug(x)   cerr<<#x<<": "<<x<<endl;
#define all(x)     (x).begin() , (x).end()
#define rep(i,a,b) for(int i=a;i<b;i++)
#define endl       '\n'
#define MAX        1000000
typedef long long int ll;
using namespace std;

const ll mod = 1e9+7;

int n , k;
vector<int>arr;
ll dp[MAX];


ll recur(int ind){
    if(ind == n)return 0;
    else if(ind > n)return INT_MAX;

    if(dp[ind]!=-1)return dp[ind];

    ll ans=INT_MAX;
    for(int i=1;i<=k;i++){
        ans = min(ans , abs(arr[ind] - arr[ind + i]) + recur(ind+i));
    }
    return dp[ind] = ans;
}
                



void solve(){
    cin>>n>>k;
    arr.resize(n+1);
    memset(dp , -1 , sizeof(dp));
    for(int i=1;i<=n;i++)cin>>arr[i];

    cout<<(recur(1))<<endl;
}





int main(){
    fastio
    int test=1;
    while(test--)
        solve();
    return 0;
}


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


void solve(long long N, long long A, long long B){
  long long combine = A + B;

  long long waru = N / combine;
  long long amari = N % combine;

  cout << ((waru * A) + min(A, amari)) << endl;

  return;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
  scanf("%lld",&N);
  long long A;
  scanf("%lld",&A);
  long long B;
  scanf("%lld",&B);
    solve(N, A, B);
    return 0;
}


Measured memory_bytes: 256
n = gets.to_i
pos = []
n.times do
  pos << gets.split.map(&:to_i)
end
pos.sort_by!{|x,y| Math.atan2(y,x)}

pos += pos

ans = 0
n.times do |i|
  cur = [0,0]
  n.times do |j|
    cur[0] += pos[i+j][0]
    cur[1] += pos[i+j][1]
    t = cur[0]**2 + cur[1]**2
    ans = t if t > ans
  end
end
p ans**0.5

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

using namespace std;
#define ll long long


int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll x[5];
    int index = 0;
    for(int i=0;i<5;i++)
        cin >>x[i];
    
    for(int i=0;i<5;i++)
    {
        if(x[i] == 0)
            cout<<(i + 1)<<endl;
    }
    
    return 0;
}


Measured memory_bytes: 3612
// Date: 2020-02-29

#include <bits/stdc++.h>
using namespace std;

typedef long long LL;
typedef long double LD;
typedef vector<int> VI;
typedef pair<LL, LL> pll;
typedef pair<int, int> pii;
#define FIO ios::sync_with_stdio(false);cin.tie(0)
#define rep(i, a, b) for(int i = int(a); i <= int(b); ++i)
#define per(i, b, a) for(int i = int(b); i >= int(a); --i)
#define mem(x, y) memset(x, y, sizeof(x))
#define all(x) (x).begin(),(x).end()
#define mk make_pair
#define pb push_back
#define fi first
#define se second
const LL INF = 1e18;
const LL mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const int N = 2e5 + 10;
template <typename T> void chkmax(T &x, T y) { x = max(x, y); }
template <typename T> void chkmin(T &x, T y) { x = min(x, y); }
LL qpow(LL x, LL y, LL MOD) {LL a=1; while(y){ if(y&1) a=a*x%MOD; x=x*x%MOD; y>>=1; } return a;}

int n, m, a, b;
LL fac[N], inv[N];

void add(LL& x, LL y) { x = (x + y) % mod; }

void init() {
    fac[0] = inv[0] = 1;
    rep(i, 1, N-1) fac[i] = fac[i-1] * i % mod, inv[i] = qpow(fac[i], mod-2, mod);
}

LL C(int x, int y) {
    return fac[x] * inv[y] % mod * inv[x-y] % mod;
}

LL cal(int x1, int y1, int x2, int y2) {
    //cout<<x1<<" "<<y1<<" "<<x2<<" "<<y2<<" "<< C(x2-x1+y2-y1, x2-x1) <<endl;
    return C(x2-x1+y2-y1, x2-x1);
}

int main() {
    init();
    scanf("%d%d%d%d", &n, &m, &a, &b);
    LL ans = 0;
    rep(i, 1, n-a) add(ans, cal(1, 1, i, b) * cal(i, b+1, n, m) % mod);
    printf("%lld\n", ans);

    return 0;
}

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

int main()
{
	int t, m, s;
	int rest;
	while (cin>>t>>m>>s) {
		if (t==-1 && m==-1 && s==-1) break;
		rest = 120*60 - t*60*60-m*60-s;
		s = rest%60;
		m = (rest/60)%60;
		t = (rest/60)/60;
		printf("%02d:%02d:%02d\n", t, m, s);
		rest *= 3;
		s = rest%60;
		m = (rest/60)%60;
		t = (rest/60)/60;
		printf("%02d:%02d:%02d\n", t, m, s);
	}
	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
#define p push_back
#define endl "\n"
#define l long long int
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    l n,d,ans=0;
    cin>>n>>d;
    for(int i=0;i<n;i++){
        int b,c;
        cin>>b>>c;
        if(ceil(sqrt(pow(b,2)+pow(c,2)))<=d)ans++;
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 3644
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;

bool A[110][110];

int main (){
	int n,a,b,c;
	cin>>n;
	for(int i=1;i<=n;i++){
			for(int j=1;j<=n;j++){
				A[i][j]=false;
		}
	}
	for(int i=1;i<=n;i++){
		cin>>a>>b;
		for(int j=1;j<=b;j++){
			cin>>c;
			A[a][c]=true;
		}
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			cout<<A[i][j]<<(j==n?"\n":" ");
		}
	}
	return 0;
}


Measured memory_bytes: 3108
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
int main()
{
  int D, N;
  cin >> D >> N;
  if (N == 100) {
    int v = pow(100, D)*(N+1);
    cout << v << endl;
  } else {
    cout << pow(100, D)*N << endl;
  }
  return 0;
}


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

int main() {
  int x;
  cin >> x;
  
  int a = x / 1000;
  int b = x % 1000 / 100;
  int c = x % 100 / 10;
  int d = x % 10;
  
  if (d == c && c == b) {
    cout << "Yes" << endl;
  }
  
  else if (a == b && b == c) {
    cout << "Yes" << endl;
  }
  
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, n) for(int i = 1; i < n; i++)
#define P pair<int, int>
typedef long long ll;
const ll mod = 1e9+7;

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;}

//繰り返し自乗法による累乗計算
//a**n
ll pow(ll a, ll n){
  if(n == 0) return 1;
  if(n%2 == 0){
    ll res = pow(a, n/2);
    return res * res;
  }
  return a * pow(a, n-1);
}
//繰り返し自乗法によるmod累乗計算
//a**n (mod)
ll modpow(ll a, ll n){
  if(n == 0) return 1;
  if(n%2 == 0){
    ll res = modpow(a, n/2);
    return res * res % mod;
  }
  return a * modpow(a, n-1) % mod;
}
//組み合わせ
//nCa
ll com(ll n, ll a){
  ll x = 1, y = 1;
  rep(i,a){
    x *= n-i;
    y *= i+1;
  }
  ll res = x / y;
  return res;
}
//組み合わせ(mod)
//nCa (mod)
ll modcom(ll n, ll a){
  ll x = 1, y = 1;
  rep(i, a){
    x = x * (n-i) % mod;
    y = y * (i+1) % mod;
  }
  ll ans = x * modpow(y, mod-2) % mod;
  return ans;
}
//gcd 最大公約数
ll gcd(ll x, ll y){
  if(x % y == 0) return y;
  return gcd(y, x%y);
}
//lcm 最小公倍数
ll lcm(ll x, ll y){
  return x * y / gcd(x, y);
}
//ngcd n個の最大公約数
ll ngcd(vector<ll> a){
  ll res;
  res = a[0];
  for(ll i = 1; i < a.size() && res != 1; i++) {
    res = gcd(a[i], res);
  }
  return res;
}
//nlcm n個の最小公倍数
ll nlcm(vector<ll> a) {
  ll res;
  res = a[0];
  for (ll i = 1; i < a.size(); i++) {
    res = lcm(res, a[i]);
  }
  return res;
}
// 素数判定
bool isprime(ll x){
  ll i;
  if(x < 2) return false;
  else if(x == 2) return true;
  if(x % 2 == 0) return false;
  for(i = 3; i*i <= x; i += 2){
    if(x % i == 0) return false;
  }
  return true;
}
// 桁和
ll digsum(ll x){
  ll res = 0;
  while(x > 0){
    res += x % 10;
    x /= 10;
  }
  return res;
}


int main(){
  string s;
  cin >> s;
  int top = 0;
  rep(i,3){
    if(s[i] == 'o') top++;
  }
  cout << 700 + top*100 << endl;
}






Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll ,P> P3;
typedef pair<P ,P> PP;
const ll MOD = ll(1e9+7);
const int IINF = INT_MAX;
const ll LLINF = LLONG_MAX;
const int MAX_N = int(1e5 + 5);
const double EPS = 1e-6;
const int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define ALL(v) (v).begin(), (v).end()


int main() {
    int a, b;
    cin >> a >> b;
    if(a==b) cout << a*2 << endl;
    else cout << max(a,b)*2-1 << endl;
    return 0;
}

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

using namespace std;
#define REP(i, n) for(ll i = 0;i < n;i++)
#define ll long long
#define MOD 1000000007
using vi = vector<ll>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける

ll n,k,y;


ll calcreq(vi &a,vi &f,vi &af,ll score){
  ll nns=0LL;
  REP(i,n){
    if (score<af[i]){
      nns+=(af[i]-score+f[i]-1)/f[i];
    }
  }
  return nns;
}



int main(){
  cin >> n>>k;
  vi a(n),f(n),af(n);
  ll asum=0LL;
  REP(i,n){
    cin>>a[i];
    asum+=a[i];
  }
  REP(i,n){
    cin>>f[i];
  }

  sort(a.begin(), a.end());
  sort(f.begin(), f.end(),greater<ll>());


  ll mx=0;
  REP(i,n){
    af[i]=a[i]*f[i];
    mx=max(mx,af[i]);
  }

  if (k==0){
    cout<<mx<<endl;
    return 0;
  }
  if (asum<=k){
    cout<<0<<endl;
    return 0;
  }


  //ニブタン
  //ll req;//必要な修行数

    ll mid=mx;
    ll end=mx;
    ll srt=0;
    ll mmid;
    ll res;
    
    for(int j=0;;j++){
      mmid=mid;
      res=calcreq(a,f,af,mid);
      if (res<=k){
        end=mid;
        mid=srt+(mid-srt)/2;
      }else{
        srt=mid;
        mid=mid+(end-mid)/2;
      }
      if (mmid==mid)break;
      if (mid==0)break;
    }



  if (calcreq(a,f,af,srt)<=k){
    cout<<srt<<endl;
    return 0;
  }


  if (calcreq(a,f,af,mid)<=k){
    cout<<mid<<endl;
    return 0;
  }
  
  if (calcreq(a,f,af,end)<=k){
    cout<<end<<endl;
    return 0;
  }
  
  

  return 0;
}

/*
11 1
3 1 4 1 5 9 2 6 5 3 5
8 9 7 9 3 2 3 8 4 6 2
*/

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

using namespace std;

int solve(vector<pair<int, int>> &foods, int t, vector<vector<int>> &memo,
          int offset = 0) {
  if (t <= 0 || offset == foods.size()) {
    return 0;
  }

  if (memo[t][offset] < 0) {
    memo[t][offset] =
        max(solve(foods, t, memo, offset + 1),
            solve(foods, t - foods[offset].first, memo, offset + 1) +
                foods[offset].second);
  }

  return memo[t][offset];
}

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

  vector<pair<int, int>> foods(n);
  for (auto &f : foods) {
    cin >> f.first >> f.second;
  }

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

  vector<vector<int>> memo(t + 1, vector<int>(n + 1, -1));
  cout << solve(foods, t, memo) << '\n';
  return 0;
}

Measured memory_bytes: 35840
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[n], b[n];
  int cnt1=0, cnt2=0;
  for(int i=0; i<n; i++) {
    cin >> a[i];
  }
  for(int i=0; i<n; i++) {
    cin >> b[i];
  }
  int ans=0;
  for(int i=0; i<n; i++) {
    cnt1=0;
    for(int j=0; j<=i; j++) {
      cnt1+=a[j];
    }
    for(int k=i; k<n; k++) {
      cnt1+=b[k];
    }
    if(cnt1>=cnt2) {
      cnt2=cnt1;
    }
  }
  cout << cnt2 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
int arr[2000000];
int arrSize = 0;
 
int toInt(string x) {
    int len = x.size();
    int res = 0;
    for (int i = 1; i < len; i++) {
        res = res*10 + (x[i] - '0');
    }
    return res;
}
 
void down(int pos) {
    int newPos = pos*2;
    if (newPos > arrSize) return;
    if (newPos + 1 <= arrSize) {
        if (arr[newPos + 1] > arr[newPos]) newPos++;
    }
    if (arr[newPos] > arr[pos]) {
        swap(arr[pos], arr[newPos]);
        return down(newPos);
    }
}
 
void up(int pos) {
    if (pos == 1) return;
    if (arr[pos] > arr[pos/2]) {
        swap(arr[pos], arr[pos/2]);
        return up(pos/2);
    }
}
 
int main() {
    string inp;
    int k;
    while (true) {
        cin >> inp;
        if (inp == "insert") {
            cin >> k;
            arr[++arrSize] = k;
            up(arrSize);
        }
        if (inp == "extract") {
            cout << arr[1] << endl;
            arr[1] = arr[arrSize];
            arr[arrSize--] = -1;
            down(1);
        }
        if (inp == "end") break;
    }
} 


Measured memory_bytes: 7080
package main

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

type sushi struct{ t, d int }
type sushis []sushi

func (s sushis) Len() int           { return len(s) }
func (s sushis) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }
func (s sushis) Less(i, j int) bool { return s[i].d > s[j].d }

func main() {
	var n, k int
	fmt.Scan(&n, &k)

	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	s := sushis(make([]sushi, n))
	for i := range s {
		sc.Scan()
		s[i].t, _ = strconv.Atoi(sc.Text())
		sc.Scan()
		s[i].d, _ = strconv.Atoi(sc.Text())
	}

	sort.Sort(s)
	sumD := 0
	mt := make(map[int]bool)
	src := make([]sushi, 0, k)
	for i := 0; i < k; i++ {
		sumD += s[i].d
		if mt[s[i].t] {
			src = append(src, s[i])
			continue
		}
		mt[s[i].t] = true
	}
	ts := len(mt)

	dst := make([]sushi, 0, n-k+1)
	for i := k; i < len(s); i++ {
		if !mt[s[i].t] {
			mt[s[i].t] = true
			dst = append(dst, s[i])
		}
	}

	ans := sumD + ts*ts
	for i := range src {
		if i >= len(dst) {
			break
		}
		sumD += -src[len(src)-i-1].d + dst[i].d
		ts++
		if v := sumD + ts*ts; v > ans {
			ans = v
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 7168
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define MAX_N 1000001
#define MAX_M 100010
const long long mod=1e9+7;
#define vec vector<int>
#define vecll vector<ll>
#define vecllvec vector<vector<ll>>
#define vecb vector<bool>
#define vecBvec vector<vector<bool>>
#define vecst vector<string>
#define veche vector<char>
#define vecd vector<double>
#define vecvec vector<vector<int>>
#define vecDvec vector<vector<double>>
#define vecHvec vector<vector<char>>
#define all(x) (x).begin(),(x).end()
#define ent cout<<endl
#define printvec(vec) for(int aqw=0;aqw<vec.size();aqw++){cout<<vec[aqw]<<" ";}ent;
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define REP(i,m,n) for(int i=m;i<(int)n;++i)
#define INF 1e+9
#define P pair<int, int>;
#define YES "Yes"
#define NO "No"
#define MAX_V 1000
#define PI 3.141592653589793
// cout << setprecision(15) << std::fixed;

// テレンス「もしかしてACですかーッ!?」　ジョセフ「Yse! Yse! Yse! Oh~MyGod」

int main(){
  int n,k;
  cin>>n>>k;
  int h[n];
  for(int i=0;i<n;i++){
    cin>>h[i];
  }
  vec dp(n+2,INF);
  dp[0]=0;
  for(int i=0;i<n;i++){
    for(int j=1;j<=k;j++){
      dp[i+j]=min(dp[i+j],dp[i]+abs(h[i]-h[i+j]));
    }
  }
  cout<<dp[n-1]<<endl;
}



Measured memory_bytes: 1024
A, B, C = map(int, input().split())

res = "No"
if B > A:
    for i in range(A, B+1):
        if i == C:
            res = 'Yes'
            break
else:
    for i in range(B, A+1):
        if i == C:
            res = 'Yes'
            break
print(res)
    

Measured memory_bytes: 2940
#include<iostream>
#include<string>
#include<cstring>
#include<cstdio>
#include<cctype>

using namespace std;

typedef unsigned long long ull;
const ull B = 100000007;

bool Rabin_Karp(string a, string b){

  int al = a.length(),bl = b.length();  
  if(al>bl)return false;

  ull t=1;
  for(int i=0; i<al; i++)t*=B;

  ull ah=0,bh=0;
  for(int i=0; i<al; i++)ah=ah*B+a[i];
  for(int i=0; i<al; i++)bh=bh*B+b[i];

  for(int i=0; i+al<=bl; i++){
    if(ah==bh)return true;
    if(i+al<bl)bh=bh*B+b[i+al]-b[i]*t;
  }
  return false;
}

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

char decode(char r, int a, int b)
{
    if ('a'<=r && r<='z') {
        int t = (r-'a') - b;
        while (t%a != 0) t += 26;
        return (t/a) % 26 + 'a';
    } 
    else return r;
}


int main(void){
  int n;
  string str;

  cin >> n;
  cin.ignore();

  while(n--){
    getline(cin,str);
    bool fg=false;
    for(int a=1;a<100;a++){
      if(gcd(a,26)==1){
	for(int b=1;b<100;b++){
	  string res="";
	  for(int k=0;k<str.size();k++)
	    res+=decode(str[k],a,b);
	  
	  if(Rabin_Karp("that",res)||Rabin_Karp("this",res)){
	    cout << res << endl;
	    fg=true;
	    break;
	  }
	}
      }
      if(fg)break;
    }
    
  }

  return 0;
}

Measured memory_bytes: 1220
N = int(input())
ac = 0
wa = 0
tle = 0
re = 0
for i in range(N):
    s = input()
    if s == 'AC':
        ac += 1
    if s == 'WA':
        wa += 1
    if s == 'TLE':
        tle += 1
    if s == 'RE':
        re += 1
print('AC x',ac)
print('WA x',wa)
print('TLE x',tle)
print('RE x' ,re)

Measured memory_bytes: 9084
from collections import defaultdict as d, deque

def bfs(adj, start, n):
	visited = [0] * (n + 1)
	tab = [0] * n
	q = deque([start])
	visited[start] = 1
	while q:
		s = q.popleft()
		for i in adj[s]:
			if visited[i] == 0:
				q.append(i)
				visited[i] = 1
				tab[i - 1] = s
	return tab

n, m = map(int, input().split())
adj = d(list)
for i in range(m):
	a, b = map(int, input().split())
	adj[a].append(b)
	adj[b].append(a)

t = bfs(adj, 1, n)
if 0 in t[1:]:
	print('No')
else:
	print('Yes')
	for i in range(1, n):
		print(t[i])


	

Measured memory_bytes: 39312
#include <bits/stdc++.h>
#include <string>
#include <cmath>
#include <sstream>
//#include <unordered_map>
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define FORD(i, a, b) for(int i = (a-1); i >= (b); i--)
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
typedef long long int ll;
using namespace std;
// ll mod=1000000007;
//ll mod=67280421310721;
ll mod=998244353;
ll INF=1e9;
ll t[1000005];
ll on[200005],te[200005],in[200005];
bool marked[1000005];
ll po(ll a,ll b)
{
	ll re=1;
	while(b)
	{
		if(b%2==1)
		{
			re=(re*a);
			re%=mod;
		}
		a=(a*a);
		a%=mod;
		b>>=1;
	}
	return re;
}
void push(int v,int tl,int tr) 
{
    if (marked[v]) 
    {
    	int tm=(tl+tr)/2;
    	t[v]=(t[v]*in[tr-tl+1])%mod;
    	t[2*v]=(t[v]*te[tm-tl+1])%mod;
    	t[2*v+1]=(t[v]*te[tr-tm])%mod;
    	t[v]=(t[v]*te[tr-tl+1])%mod;
        marked[v*2] = marked[v*2+1] = true;
        marked[v] = false;
    }
}

void update(int v, int tl, int tr, int l, int r, ll new_val) 
{
    if (l > r) 
        return;
    if (l == tl && tr == r) 
    {
        t[v] = (new_val*te[r-l+1])%mod;
        marked[v]=1;
        return;
    } 
    else 
    {
        push(v,tl,tr);
        int tm = (tl + tr) / 2;
        update(v*2, tl, tm, l, min(r, tm), new_val);
        update(v*2+1, tm+1, tr, max(l, tm+1), r, new_val);
   		t[v]=(t[2*v]*on[tr-tm+1]+t[2*v+1])%mod;
    }
    return;
}
ll sum(int v, int tl, int tr, int l, int r) {
    if (l > r) 
        return 0;
    if (l == tl && r == tr) 
    {
        return t[v];
    }
    push(v,tl,tr);
    int tm = (tl + tr)/2;
    return ((sum(v*2, tl, tm, l, min(r, tm))*on[tr-tm+1])+sum(v*2+1, tm+1, tr, max(l, tm+1), r))%mod;
}

int main()
{
	ios_base::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 test=1;
	// cin>>test;
	while(test--)
	{
		int n,q;
		cin>>n>>q;
		on[1]=1;
		te[1]=1;
		FOR(i,2,n+1)
		{
			on[i]=(10*on[i-1])%mod;
			te[i]=(te[i-1]+on[i])%mod;
			in[i]=po(te[i],mod-2);
			// cout<<in[i]<<" ";
		}	
		ll o=1;
		FOR(i,0,n)
		{
			update(1,0,n-1,i,i,1);
		}
		int l,r;
		FOR(i,0,q)
		{
			cin>>l>>r>>o;
			update(1,0,n-1,l-1,r-1,o);
			cout<<sum(1,0,n-1,0,n-1)<<'\n';
		}
	}
	return 0;
}

Measured memory_bytes: 12964
#include<cstdio>
#define int long long
inline int sqr(int a,int m){return a*a%m;}
int pow(int a,int n,int m)
{
	if(n<1)return 1;
	if(n&1)return sqr(pow(a,n>>1,m),m)*a%m;
	return sqr(pow(a,n>>1,m),m);
}
int gcd(int a,int b){return !b?a:gcd(b,a%b);}
void gcd(int x,int y,int &a,int &b)
{
	if(!y){a=1;b=0;return;}
	gcd(y,x%y,b,a);b-=x/y*a;
}
int solve(int a,int m)
{
	if(m==1)return 1;
	int phi=m,k=m;
	for(int i=2;i*i<=m;i++)
		if(k%i==0)
		{
			phi=phi/i*(i-1);
			while(k%i==0)k/=i;
		}
	if(k>1)phi=phi/k*(k-1);
	int g=gcd(m,phi),y=solve(a,g),o=((pow(a,y,m)-y)%m+m)%m,p,q;
	if(y==-1||o%g)return -1;
	gcd(phi,m,p,q);
	p=(p+m)%m*o/g%m;
	int res=(phi*p+y)%(m*phi);
	if(!res)res=m*phi;
	return res;
}
int q,a,m;
signed main()
{
	scanf("%lld",&q);
	while(q--)
	{
		scanf("%lld%lld",&a,&m);
		printf("%lld\n",solve(a,m));
	}
	return 0;
}

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

using namespace std;

long long int dp[100005][105];

pair<int,int>jinis[105];

void init(){
 memset(dp,-1,sizeof(dp));
}

long long solve(int vleft, int cur, int n){
 if(cur==n){
   if(vleft==0)return 0;
   return (long long)2000000000;
 }
 if(dp[vleft][cur]!=-1)return dp[vleft][cur];
 long long ret1 = 0, ret2 = 0;
  
 ret1 = (long long)jinis[cur].first + solve(max(0,vleft-jinis[cur].second),cur+1,n);
 
  ret2 = solve(vleft, cur+1, n);
  return dp[vleft][cur] = min(ret1,ret2);
}

int main(){
  int n,w;
  cin>>n>>w;
  int hi = 0;
  for(int i = 0; i<n; ++i){
   cin>>jinis[i].first>>jinis[i].second;
    hi = hi+jinis[i].second;
  }
  
  int lo = 0;
  init();
  while(lo+1<hi){
     int mid = (lo+hi)/2;
    //init();
     if(solve(mid,0,n)<=w)lo = mid;
    else hi = mid;
  }
  long long lw = solve(hi,0,n);
  if(lw<=w){
   cout<<hi<<"\n";
  }
  else{
  		cout<<lo<<"\n";
  }
  //cout<<solve(w,0,n)<<"\n";
  return 0;
}

Measured memory_bytes: 82304
#include<iostream>
#include<algorithm>
using lint=int64_t;
using namespace std;

constexpr int INF=1e9;

int N;
string S[210];

int col[210];
bool dfs(int cur=0,int ccol=1)
{
	col[cur]=ccol;
	for(int i=0;i<N;i++)
	{
		if(S[cur][i]=='0')continue;
		if(col[cur]==col[i])
			return false;
		if(col[i]==0 && !dfs(i,-ccol))
			return false;
	}

	return true;
}

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

	if(!dfs())
	{
		cout << -1 << endl;
		return 0;
	}

	int dist[210][210]={};
	for(int i=0;i<N;i++)
		for(int j=0;j<N;j++)
			if(i!=j)
				dist[i][j]=INF;
	for(int i=0;i<N;i++)
		for(int j=0;j<N;j++)
			if(S[i][j]=='1')
				dist[i][j]=1;
	
	for(int k=0;k<N;k++)
		for(int i=0;i<N;i++)
			for(int j=0;j<N;j++)
				dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j]);

	int ans=0;
	for(int i=0;i<N;i++)
		for(int j=0;j<N;j++)
			ans=max(ans,dist[i][j]);
	cout << ans+1 << endl;
	return 0;
}


Measured memory_bytes: 512
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>
 
#define int long long

#if DEBUG
    #include "debug.h"
#else
    #define debug(args...)
#endif    

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> ii;
typedef long long ll;


#define M 1000000 
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define fill(a,x) memset(a,x,sizeof(all))
#define F first
#define S second
#define FOR(i,a,b) for(int i = a; i<=b; ++i)
#define NFOR(i,a,b) for(int i = a; i>=b; --i)
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int INF = 1e9;
const int mod = 1e9+7;

const int N = 2e5 + 10;
inline int add(int x,int y){
  x += y;
  if(x >= mod) x -= mod;
  return x;
}
inline int mul(int x,int y){
  x = (1LL * x * y) % mod;
  return x;
}
clock_t time_p=clock();

int dist[500][500];
int mat[21][21];

int dx[4] = {0 , 0, 1, - 1};
int dy[4] = {1,-1,0,0};
int h,w;

bool is_valid(int i, int j) {
  if(i >= 1 and i <= h and j >= 1 and j <= w  and mat[i][j] == 1)return true;
  return false;
}

int32_t main(){
  fast;

  //freopen("in.txt","r",stdin);
  //freopen("out.txt","w",stdout);

  FOR(i,1,450)FOR(j,1,450)dist[i][j] = INF;
  FOR(i,1,450)dist[i][i] = 0;
  
  cin >> h >> w;
  FOR(i,1,h) {
    string s;
    cin >> s;
    FOR(j,0,w-1)if(s[j] == '.')mat[i][j + 1] = 1;else mat[i][j + 1] = 0;
  }

  FOR(i,1,h) {
    FOR(j,1,w) {
      if(is_valid(i,j)) {
        FOR(k,0,3) {
          int x = i + dx[k];
          int y = j + dy[k];
          if(is_valid(x,y)) {
            debug(i,j,x,y);
            dist[(i - 1)*w + j][(x - 1)*w + y] = 1;
          }
        }
      }
    }
  }
  int V = h*w;
  FOR(i,1,V)FOR(j,1,V)debug(i,j,dist[i][j]);
for (int k = 1; k <= V; k++)  
    {  
        // Pick all vertices as source one by one  
        for (int i = 1; i <= V; i++)  
        {  
            // Pick all vertices as destination for the  
            // above picked source  
            for (int j = 1; j <= V; j++)  
            {  
                // If vertex k is on the shortest path from  
                // i to j, then update the value of dist[i][j]  
                if (dist[i][k] + dist[k][j] < dist[i][j])  
                    dist[i][j] = dist[i][k] + dist[k][j];  
            }  
        }  
    }    
    int ans = 0;
  FOR(i,1,V) {
    FOR(j,1,V) {
      debug(i,j,dist[i][j]);
      if(dist[i][j] < INF)
        ans = max(ans,dist[i][j]);
    }
  }  
  cout << ans << "\n";
  time_p=clock()-time_p;
  cerr<<"\nTime Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";

  return 0;
}

Measured memory_bytes: 2048
import sys
sys.setrecursionlimit(10**6)

memo = {}

def solve(i, last_option):
	global a, b, c
	if (i, last_option) not in memo:
		if i == len(a):
			result = 0
		elif i == 0:
			result = max(a[i] + solve(i + 1, 1), b[i] + solve(i + 1, 2), c[i] + solve(i + 1, 3))
		else:
			if last_option == 1:
				result = max(b[i] + solve(i + 1, 2), c[i] + solve(i + 1, 3))
			elif last_option == 2:
				result = max(a[i] + solve(i + 1, 1), c[i] + solve(i + 1, 3))
			else:
				result = max(a[i] + solve(i + 1, 1), b[i] + solve(i + 1, 2))
		memo[(i, last_option)] = result
		return result
	else:
		return memo[(i, last_option)]

n = int(input())
a = [None for i in range(n)]
b = [None for i in range(n)]
c = [None for i in range(n)]
for i in range(n):
	a[i], b[i], c[i] = map(int, input().split())
print(solve(0, 4))


Measured memory_bytes: 119404
n=int(input())
l=list(map(int,input().split()))
xl=list(reversed(l))
g=[]
a=1
k=0
f=0
for i in xl:
  k+=i
  g.append(k)
g.reverse()
for i in range(len(g)):
  if g[i]>=a:
    g[i]=a
  a-=l[i]
  a*=2
  if a<=0 and i!=len(g)-1:
    f+=1
    break
  if a<0 and i==len(g)-1:
    f+=1
    break
if f==0 and n!=0:
  print(sum(g))
elif n==0:
  if l[0]==1:
    print(1)
  else:
    print(-1)
else:
  print(-1)

Measured memory_bytes: 20024
X, Y, Z, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)

sum = []
for x in range(X):
    for y in range(Y):
        for z in range(Z):
            if (x+1)*(y+1)*(z+1) <= K:
                sum.append(A[x] + B[y] + C[z])
            else:
                break

sum.sort(reverse=True)
for i in range(K):
    print(sum[i])

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

using namespace std;

typedef long long ll;

const ll MOD = 1000000007;
const ll INF = 1LL<<60;
//int INF = numeric_limits<int>::max();

int main(int, char**) {
	ll n, m, k; cin >> n >> m >> k;
	vector<ll> As, Bs;
	As.push_back(0);
	Bs.push_back(0);
	ll sm = 0;
	for (int i=0; i<n; i++) {
		ll a; cin >> a;
		sm += a;
		if (sm > k) {
			As.push_back(INF);
			sm = k + 1;
		} else As.push_back(sm);
	}
	sm = 0;
	for (int i=0; i<m; i++) {
		ll b; cin >> b;
		sm += b;
		if (sm > k) {
			Bs.push_back(INF);
			sm = k + 1;
		} else Bs.push_back(sm);
	}
	int ret = 0;
	for (int i=0; i<As.size(); i++) {
		if (As[i]>k) break;
		ll rem = k - As[i];
		auto itr = upper_bound(Bs.begin(), Bs.end(), rem);
		int b;
		b = itr - Bs.begin();
		b = max(0, b - 1);
		ret = max(ret, i+b);
		//cout << i << " " << b << " " << rem << " " << As[i] << endl;
	}
	cout << ret << endl;
	return 0;
}


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

bool contain(std::vector<int> v, int x) {
  return std::find(v.begin(), v.end(), x) != v.end();
}

void reachable_vertexes(int v, int elen, int* edges, std::vector<int>& already_vertex, std::vector<int>& already_edge) {
  already_vertex.push_back(v);
 // std::cout << "v:" << v << " ";
  for(int i = 0; i < elen; i++) {
    if(contain(already_edge, i))
      continue;
    const int a = edges[i] / 100;
    const int b = edges[i] % 100;
    if(v != a && v != b)
      continue;
    already_edge.push_back(i);

    if(v == b && !contain(already_vertex, a)) {
      reachable_vertexes(a, elen, edges, already_vertex, already_edge);
    } else if(v == a && !contain(already_vertex, b)) {
      reachable_vertexes(b, elen, edges, already_vertex, already_edge);
    }
  }
}

bool is_linked_graph(int vlen, int elen, int* edges, int ignore_ind) {
  int i = ignore_ind == 0 ? 1 : 0;
  int a = edges[i] / 100;
  std::vector<int> already_vertex;
  std::vector<int> already_edge;
  already_edge.push_back(ignore_ind);
  reachable_vertexes(a, elen, edges, already_vertex, already_edge);
  //std::cout << already_vertex.size() << ", " <<  already_edge.size() <<"\n";
  return already_vertex.size() == vlen;
}

int bridge_count(int vlen, int elen, int* edges) {
  int b = 0;
  for(int i = 0; i < elen; i++) {
    b += !is_linked_graph(vlen, elen, edges, i);
  }
  return b;
}

int main() {
  int n, m;
  std::cin >> n;
  std::cin >> m;
  int edges[m];
  int a, b;
  for(int i = 0; i < m; i++) {
    std::cin >> a;
    std::cin >> b;
    edges[i] = (a - 1) * 100 + (b - 1);
  }

  int c = bridge_count(n, m, edges);
  std::cout << c << "\n";
  return 0;
}

Measured memory_bytes: 256
N,K = map(int,input().split())
D = list(map(int,input().split()))
U = []
for i in range(10):
    if not i in D:
        U.append(i)
ans = float("inf")
import itertools

for i in range(6):
    for v in itertools.product(U,repeat=i):
        tmp = ""
        for s in v:
            tmp += str(s)
        if tmp != "":
            tmp = int(tmp)
            if tmp>=N and tmp<ans:
                ans = tmp
print(ans)

Measured memory_bytes: 42732
import java.io.PrintWriter

val pw = PrintWriter(System.out)

fun main(args: Array<String>) {
    var (n,t) = listOfInt()
    var g = mutableListOf<MutableList<Int>>()
    repeat(n) { g.add(mutableListOf<Int>())}
    repeat(n-1){
        var (a,b)=listOfInt()
        --a; --b;
        g[a].add(b)
        g[b].add(a)
    }
    var re=t.toLong()
    repeat(n){ v ->
        var sz=g[v].size
        var nrt=if(v==0) 0 else 1
        for(i in (1..(sz-nrt))){
            re*=t-i-(if(v==0) 0 else 1)
            re%=1000000007
        }
    }
    pw.println(re)
    pw.flush()
}

fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map { it.toInt() }
fun listOfLong() = listOfString().map { it.toLong() }
fun listOfDouble() = listOfString().map { it.toDouble() }


Measured memory_bytes: 72652
#include<cstdio>
#include<cstring>
#include<cctype>
#include<algorithm>
#define reg register
using namespace std;
const int N=2e5+5;
int n,a[N];
inline int read()
{
	int x=0,w=1;
	char c=getchar();
	while (!isdigit(c)&&c!='-') c=getchar();
	if (c=='-') c=getchar(),w=-1;
	while (isdigit(c))
	{
		x=(x<<1)+(x<<3)+c-'0';
		c=getchar();
	}
	return x*w;
}
inline bool check(int k)
{
	for (reg int i=1;i<n;i++)
	{
		if ((a[n-i+1]>k)==(a[n-i]>k)) return a[n-i]<=k;
		if ((a[n+i-1]>k)==(a[n+i]>k)) return a[n+i]<=k;
	}
	return a[1]<=k;
}
int main()
{
	n=read();
	for (reg int i=1;i<(n<<1);a[i++]=read());
	int l=1,r=(n<<1)-1,ans=0;
	while (l<=r)
	{
		int mid=(l+r)>>1;
		if (check(mid)) ans=mid,r=mid-1;
		else l=mid+1;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 896
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;

int main() {        
    int n, c;
    cin >> n >> c;
    vector<vector<int>> v1(c + 1, vector<int>(0)), v2(c + 1, vector<int>(0));
    for (int i = 0; i < n; i++) {
        int s, t, cc;
        cin >> s >> t >> cc;
        v1[cc].push_back(s);
        v1[cc].push_back(t);
    }
    vector<int> begin(100001, 0), end(100001, 0);
    for (int i = 1; i <= c; i++) {
        sort(v1[i].begin(), v1[i].end());
        for (auto num : v1[i]) {
            if (v2[i].size() > 0 && v2[i].back() == num) {
                v2[i].pop_back();
            } else {
                v2[i].push_back(num);
            }
        }
        for (int j = 0; j < v2[i].size(); j += 2) {
            begin[v2[i][j]]++;
            end[v2[i][j + 1]]++;
        }
    }

    int res = 0;
    int r = 0;
    for (int i = 1; i <= 100000; i++) {
        r += begin[i];
        res = max(r, res);
        r -= end[i];
    }
    cout << res << endl;
}


Measured memory_bytes: 6156
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        // write your code here

        Scanner in = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);

        String n = in.nextLine();

        if(n.charAt(0) == '7' || n.charAt(1) == '7'  || n.charAt(2)== '7')
            out.println("Yes");
        else out.println("No");
        out.close();
    }
}


Measured memory_bytes: 35924
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <algorithm>
#include <cmath>
#include <iostream>

using namespace std;

const int MAX_N = 100;

int A[MAX_N];

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

    int N;
    cin >> N;

    int sum = 0;

    for (int i = 0; i < N; i++) {
        cin >> A[i];
        sum += A[i];
    }

    double minf = double(sum) / N;

    int y;
    if (minf - floor(minf) <= floor(minf) + 1 - minf) {
        y = int(floor(minf));
    } else {
        y = int(floor(minf)) + 1;
    }

    int cost = 0;
    for (int i = 0; i < N; i++) {
        cost += (A[i] - y) * (A[i] - y);
    }

    cout << cost << "\n";

    return 0;
}

Measured memory_bytes: 3704
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
fn main(){
    let s : String = read();
    let ans = s.rfind('Z').unwrap() - s.find('A').unwrap() + 1;
    println!("{}",ans );
}

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

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

fn main() {
    let a: u32 = read();
    let b: u32 = read();
    let c: u32 = read();
    let mut ans = "NO";

    for i in 1..(100+1) {
        if (i * a) % b == c {
            ans = "YES";
            break;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#pragma region GNUC
//以下を参考にした
//https://yukicoder.me/wiki/auto_vectorization
#ifdef __GNUC__
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#endif
#pragma endregion

#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <cmath>

#include <string>
#include <cstring>
#include <vector>
#include <valarray>
//#include <array>//x C++ (G++ 4.6.4)

#include <queue>
#include <complex>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <cassert>//assert();
#include <fstream>
#include <random>
/////////
#define REP(i, x, n) for(int i = x; i < n; ++i)
#define rep(i,n) REP(i,0,n)

/////////
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
#define PII pair<int,int>
/////////
using namespace::std;

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

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

void solve(){
	int N;
	cin >> N;
	vector<int> T(N);
	int sum = 0;
	for(int i=0;i<N;++i){
		cin >> T[i];
		sum += T[i];
	}
	int M;
	cin >> M;
	for(int i=0;i<M;++i){
		int P,X;
		cin >> P >> X;
		--P;
		X -= T[P];
		cout << sum + X << endl;
	}
}

signed main(void){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	//std::cout << std::fixed;//小数を10進数表示
	//cout << setprecision(16);//小数点以下の桁数を指定
	
	solve();
}


Measured memory_bytes: 256