akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define prtd(var, i) cout << fixed << setprecision(i) << var << endl;
#define ll long long
using namespace std;
#define INF 1e18LL

const ll MAX = 1000000000000000000; //1e18

int main(){
    ll ans = 0;
    int n;
    cin >> n;
    vector<int> an(n, 100010);
    rep(i, n-1){
        int tmp;
        cin >> tmp;
        an[i] = min(an[i], tmp);
        an[i+1] = min(an[i+1], tmp);
        if(i + 1 == n - 1) an[i+1] = tmp;
    }
    rep(i, n) ans += an[i];
    cout << ans << endl;
}

// - - - - - -
// 0 0 10 10 10 23
// 2 2 5    

// - - - - - -

Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <cassert>
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
const double EPS = 1e-9;
const double PI  = acos(-1.0);

typedef pair<double,string> pds;
namespace std{
	bool operator<(const pds &l,const pds &r){
		if(abs(l.first-r.first)<EPS){
			return l.second<r.second;
		}else{
			return l.first>r.first;
		}
	}
}

int main(){
	int n;
	while(cin>>n,n){
		vector<pds> eff;
		REP(i,n){
			string l;
			int p,a,b,c,d,e,f,s,m;
			cin>>l>>p>>a>>b>>c>>d>>e>>f>>s>>m;
			int t=a+b+c+(d+e)*m;
			int v=f*s*m;
			eff.push_back(make_pair((double)(v-p)/t,l));
		}
		sort(ALL(eff));
		REP(i,n){
			cout<<eff[i].second<<endl;
		}
		cout<<"#"<<endl;
	}
}

Measured memory_bytes: 1220
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cmath>
#include <algorithm>
#include <climits>
#include <iomanip>
#define endl "\n"
#define debug(x) cout << #x << " : " << x << endl;
#define debug2(x, y) cout << #x << " : " << x  << ", " << #y << " : " << y << endl;
#define FASTIO ios_base::sync_with_stdio(false),cin.tie(0);
typedef long long ll;
using namespace std;

int main()
{
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif

	FASTIO
	
	ll n;
	cin >> n;

	ll x = 1, y = 1, z = 1;
	ll f[n + 1] = {0};

	ll val = 0;
	for(x = 1; x <= n; x ++)
	{
		y = x;
		val = x * x + y * y + z * z + x * y + y * z + z * x;
		if(val > n)
			break;		
		for(y = x; y <= n; y ++)
		{
			z = y;
			val = x * x + y * y + z * z + x * y + y * z + z * x;
			if(val > n)
				break;

			for(z = y; z <= n; z ++)
			{
				val = x * x + y * y + z * z + x * y + y * z + z * x;
				if(val > n)
					break;
				if(x == y && y == z && z == x)
					f[val] += 1;
				else if(x != y && y != z && z != x)
					f[val] += 6;
				else
					f[val] += 3;				
			}
		}
	}

	for(ll i = 1; i <= n; i ++)
		cout << f[i] << endl;

}

Measured memory_bytes: 3660
from __future__ import print_function

import sys

import re
import array
import copy
import functools
import operator

import math
import string
import fractions
from fractions import Fraction
from fractions import gcd
# fractions.gcd() を用いること
# math.log2()はatcoderでは対応していない．留意せよ．

import collections
import itertools
import bisect

import random
import time

import heapq
from heapq import heappush
from heapq import heappop
from heapq import heappushpop
from heapq import heapify
from heapq import heapreplace
from queue import PriorityQueue as pq
from queue import Queue

from itertools import accumulate

from collections import deque
from collections import Counter

from operator import mul
from functools import reduce

input = sys.stdin.readline


def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)
    return


def lcm(n, m):
    return int(n * m / gcd(n, m))


def coprimize(p, q):
    common = fractions.gcd(p, q)
    return (p // common, q // common)


def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom


def main():
    S = input().strip()
    C=Counter()

    for i in range(len(S)):
        if C[S[i]]==0:
            C[S[i]]+=1
        else:
            print("no")
            return
    print("yes")
    return

if __name__ == '__main__':
    main()

Measured memory_bytes: 60780
import java.util.*;
class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] a = new int[N+1];

        for(int i = 1; i<N+1; i++) {
            a[i] = sc.nextInt();
        }
        int[] dp = new int[N+1];
        dp[1] = 0;
        dp[2] = (int)Math.abs(a[2] - a[1]);
        for(int i = 3; i<=N; i++) {
            dp[i] = Math.min(dp[i-1] + (int)Math.abs(a[i]-a[i-1]), dp[i-2] + (int)Math.abs(a[i]-a[i-2]));
        }
        System.out.println(dp[N]);
    }

}

Measured memory_bytes: 50552
l = [int(input()) for _ in range(5)]
k = int(input())
 
flag = False
for i in range(5):
  for j in range(i +1, 5):
    if l[j] - l[i] > k:
      flag = True
      break
 
if flag:
  print(":(")
else:
  print("Yay!")

Measured memory_bytes: 3060
import java.util.Scanner;
   
class Main{
 public static void main(String[] arge){
     
Scanner sc=new Scanner(System.in);


while (true){ 

int a=sc.nextInt();
int b=sc.nextInt();

if(a==0 && b==0)
{break;}
else{
for ( int i = 0; i < a; i++ ){
for ( int j = 0; j < b; j++ ){
System.out.print("#");		       
}
System.out.println("");

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




Measured memory_bytes: 34540
#include <iostream>
#include <map>
#include <vector>
using namespace std;
 
struct UnionFind {
    vector<int> par;
    
    UnionFind(int n) : par(n, -1) { }
    void init(int n) { par.assign(n, -1); }
    
    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    
    bool issame(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    
    int size(int x) {
        return -par[root(x)];
    }
};
 
int main() {
    int N, K, L; cin >> N >> K >> L;
    UnionFind uf1(N), uf2(N);
    for (int i = 0; i < K; ++i) {
        int a, b; cin >> a >> b; --a, --b;
        uf1.merge(a, b);
    }
    for (int i = 0; i < L; ++i) {
        int a, b; cin >> a >> b; --a, --b;
        uf2.merge(a, b);
    }
 
    using pint = pair<int,int>;
    map<pint, int> ma;
    for (int v = 0; v < N; ++v) {
        pint p(uf1.root(v), uf2.root(v));
        ma[p]++;
    }
 
    for (int v = 0; v < N; ++v) {
        pint p(uf1.root(v), uf2.root(v));
        cout << ma[p] << " ";
    }
}

Measured memory_bytes: 13568
function Main(input) {
  input = input.split("\n");
  var N = parseInt(input[0].split(" ")[0]);
  var M = parseInt(input[0].split(" ")[1]);
  input.shift();
  input.splice(M,input.length);
  var p = input.map(i => i.split(" "));
  var x = new Array(N+1);
  for(var i=0;i<N+1;i++){
    var xsub=new Array(2).fill(0);
    x[i]=xsub;
  }
  var ac=0;
  var wa=0;
  for(var i=0;i<M;i++){
    var a = parseInt(p[i][0]);
    var b = p[i][1];
    if(b=="WA"){
      x[a][1]++;
    }
    if(b=="AC"&&x[a][0]==0){
      ac++;
      wa+=x[a][1];
      x[a][0]++;
    }
  }
  var ans = ac + " " + wa;
  console.log('%s', ans);
  return ans;
}

function debug(n){
  var input = document.getElementById("input"+n).value;
  var ans=Main(input);
  var result="WA";
  if(ans==document.getElementById("output"+n).value.split("\n")[0]){
    result="AC";
  }
  document.getElementById("result"+n).innerHTML=result;
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 52664
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] cd = new int[N+1];
		long ans = 1;
		for(int i = 1; i <= N; i++) {
			int a = i;
			for(int j = 2; j <= i; j++) {
				while(a % j == 0 && a > 0) {
					cd[j]++;
					a /= j;
				}
			}
		}
		for(int i = 0; i <= N; i++)
			ans = ans * (cd[i] + 1) % 1000000007;
		System.out.println(ans);
	}

}

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

int main()
{
    int n,m,s,c,i;
    scanf("%d%d",&n,&m);
    int num[n];
    int ans=0;

    for(i=0;i<n;i++)
        num[i] = -1;

    for(i=0;i<m;i++){
        scanf("%d%d",&s,&c);
        if(num[s-1] == -1 || num[s-1] == c)
            num[s-1] = c;
        else ans = -1;
    }

    if(n==1){
        if(num[0]==-1)
            num[0] = 0;
        if(ans == -1)
            printf("-1");
        else 
            printf("%d",num[0]);
    }
    
    if(n==2){
        if(num[0]==0)
            ans=-1;
        if(num[0]==-1)
            num[0]=1;
        if(ans == -1)
            printf("-1");
        else{
            for(i=0;i<n;i++){
                if(num[i] == -1)
                    printf("0");
                else
                    printf("%d",num[i]);
            }
        }
    }

    if(n==3){

        if(num[0] == 0)
            ans = -1;
        if(num[0] == -1)
            num[0] = 1;

        if(ans == -1)
            printf("-1");
    
        else{
            for(i=0;i<n;i++){
                if(num[i] == -1)
                    printf("0");
                else
                    printf("%d",num[i]);
            }
        }   
    }
    return 0;

}


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

using namespace std;

int main() {
    int a, b;
    string s;
    cin >> a;
    cin >> b;
    cin >> s;
    
    for (int i = 0; i < a + b + 1; ++i)
    {
        if (i < a && s[i] == '-')
        {
            cout << "No" << endl;
            break;
        }
        
        if (i == a && s[i] != '-')
        {
            cout << "No" << endl;
            break;
        }
        
        if (i > a && s[i] == '-')
        {
            cout << "No" <<endl;
            break;
        }
        
        if (i == a + b)
        {
            cout << "Yes" << endl;
        }
        
    }
    return 0;
}


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int D,G;
int P[11],C[11];

int dp[1111];

signed main(){
    cin>>D>>G;
    rep(i,D)cin>>P[i]>>C[i];
    rep(i,D){
        for(int j=1111-1;j>=0;j--){
            for(int k=0;k<=P[i];k++){
                if(j+k>=1111)break;
                chmax(dp[j+k],dp[j]+100*(i+1)*k+(k==P[i])*C[i]);
            }
        }
    }
    cout<<lower_bound(dp,dp+1111,G)-dp<<endl;
    return 0;
}


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

int count(ll n){
    int ans = 0;
    while(n > 0){
        n /= 10;
        ans++;
    }
    
    return ans;
}

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

    ll n;
    cin >> n;
    
    long double base = sqrt(n);
    ll i = floor(base);
    ll a = 0;
    
    while(i > 0){
        if(n % i == 0){
            a = n / i;
            break;
        }
        
        i--;
    }
    
    cout << max(count(a), count(i)) << endl;
    
    return 0;
}

Measured memory_bytes: 256
a=int(input())

for i in range(a):
    x,y,z=map(int,input().split())
    
    if x>y:
        x,y=y,x
    if y>z:
        y,z=z,y
    if x>y:
        x,y=y,x
    
    if z**2==x**2+y**2:
        print("YES")
    else:
        print("NO")
    


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

int main() {
    string s;
    cin >> s;

    if(s[2] == s[3] && s[4] == s[5]){
        puts("Yes");
    }else{
        puts("No");
    }
    return 0;
}

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

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <climits>
#include <bitset>
#include <array>
#include <deque>
#include <queue>
#include <map>
#include <set>
#define all(x) (x).begin(),(x).end()

const int MOD = 1e9 + 7;

void solve(){

}
int main(){
    string S;
    cin >> S;
    vector<char> b;
    b.push_back(S[0]);
    char t = S[0];
    int ans = 0;
    bool em = true;
    for (int i = 1; i < S.size(); ++i) {
        if (t != S[i] && !b.empty()) {
            b.pop_back();
            ans += 2;
        } else {
            b.push_back(S[i]);
        }
        if (!b.empty()) {
            t = b.back();
        } else {
        }
    }
    cout << ans << endl;






    return 0;
}


Measured memory_bytes: 576
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
using namespace std;
int n, ok, cnt, b;
int a[100][30];
char ans[55];
int Min = 1000;
char s[55][55];
int main()
{
	scanf("%d", &n);
	for(int i = 1; i <= n; i++)
	{
		scanf("%s", s[i]);
		b = strlen(s[i]);
		for(int j = 0; j < b; j++)
		a[i][s[i][j] - 'a']++;
	}
		for(int j = 0; j <= 26; j++)
		{
			Min = 100;
			for(int i = 1; i <= n; i++)
			{
				Min = min(Min, a[i][j]);
			}
			if(Min != 100)for(int k = 1; k <= Min; k++)ans[cnt++] = 'a' + j;
		}
	printf("%s\n", ans);
}

Measured memory_bytes: 128
use proconio::input;
use proconio::marker::Usize1;

macro_rules! chmax {
    ($max_v: expr, $v: expr) => {
        if $v > $max_v {
            $max_v = $v;
            true
        } else {
            false
        }
    };
}

fn main() {
    input! {
        _: usize,
        _: usize,
        m: usize,
        hw: [(Usize1, Usize1); m],
    };

    let mut map_h = std::collections::BTreeMap::new();
    let mut map_w = std::collections::BTreeMap::new();
    for (i, &(h_i, w_i)) in hw.iter().enumerate() {
        map_h.entry(h_i).or_insert(vec![]).push(i);
        map_w.entry(w_i).or_insert(vec![]).push(i);
    }

    let ans1 = {
        let mut max_h = 0;
        let mut max_h_i = 0;
        for (h_i, is) in map_h.iter() {
            if chmax!(max_h, is.len()) {
                max_h_i = *h_i;
            }
        }
        let mut max_w = 0;
        for (_, is) in map_w.iter() {
            let len = is.iter().filter(|&&i| hw[i].0 != max_h_i).count();
            chmax!(max_w, len);
        }
        max_h + max_w
    };
    let ans2 = {
        let mut max_w = 0;
        let mut max_w_i = 0;
        for (w_i, is) in map_w.iter() {
            if chmax!(max_w, is.len()) {
                max_w_i = *w_i;
            }
        }
        let mut max_h = 0;
        for (_, is) in map_h.iter() {
            let len = is.iter().filter(|&&i| hw[i].1 != max_w_i).count();
            chmax!(max_h, len);
        }
        max_h + max_w
    };

    let ans = std::cmp::max(ans1, ans2);
    println!("{}", ans);
}


Measured memory_bytes: 60996
import heapq
from collections import defaultdict, deque
from math import ceil, factorial, gcd
from itertools import accumulate, permutations
import sys
import bisect

sys.setrecursionlimit(10 ** 7)
INF = float("inf")
MOD = 10 ** 9 + 7

si = lambda: input().strip()
ii = lambda: int(input())
mii = lambda: map(int, input().split())
msi = lambda: map(str, input().split())
lmii = lambda: list(map(int, input().split()))
lmsi = lambda: list(map(str, input().split()))
smii = lambda: sorted(map(int, input().split()))

# ----------

k = ii()
a, b = mii()

for i in range(a, b + 1):
    if i % k == 0:
        print('OK')
        exit()

print('NG')

Measured memory_bytes: 9480
// "header" {{{
#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <string>
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cstring>
#include <iomanip>
#include <tuple>

using namespace std;

#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define pii pair<int,int> 
#define int int64_t
#define Fixed fixed << setprecision(10)
#define moke_pair make_pair
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const long long mod = 1000000007;

template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

template <class T> using min_heap = priority_queue<T,vector<T>,greater<T> >;
template <class T> using max_heap = priority_queue<T>;
template <class T,class U> using umap = unordered_map<T,U>;

inline int64_t updiv(int64_t n,int64_t d){
    return ((n + d -1) / d);
}
/*
inline double Sqrt( const double &x) 
{
	double         xHalf = 0.5 * x;
	int64_t  tmp   = 0x5FE6EB50C7B537AAl - ( *(int64_t*)&x >> 1);
	double         xRes  = * (double*)&tmp;

	xRes *= ( 1.5 - ( xHalf * xRes * xRes ) );
	xRes *= ( 1.5 - ( xHalf * xRes * xRes ) );
	xRes *= ( 1.5 - ( xHalf * xRes * xRes ) );
	xRes *= ( 1.5 - ( xHalf * xRes * xRes ) );
	return xRes * x;
}
*/
// }}}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int pos = INF;
    rep(i,s.size()){
        if(s[i] == 'A'){
            pos = i;
            break;
        }
    }
    int lpos = INF;
    for(int i = s.size()-1;i >= pos;--i){
        if(s[i] == 'Z'){
            lpos = i;
            break;
        }
    }
    cout << lpos - pos + 1 << '\n';
    return 0;
}


Measured memory_bytes: 764
x = list(map(int, input().split()))
y = list(map(int, input().split()))
z = [0, 1, 2]
for i in range(6):
    order = [0, 0, 0]
    for j in range(3):
        if {x[j], x[-j-1]} != {y[z[j]], y[-z[j]-1]}:
            break
        if x[j] == y[z[j]]:
            order[j] = 1 
            if x[j] == x[-j-1]:
                order[j] = 2 
    else:
        if 2 in order or (i < 3) == sum(order) % 2:
            print('Yes')
            break
    z = z[-1:] + z[:-1]
    if i == 2:
        z = [z[0], z[2], z[1]]
else:
    print('No')

Measured memory_bytes: 7720
N, K = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))

A.sort()
F.sort(reverse=True)

T = []
for i in range(N):
    T.append(A[i]*F[i])

s = -1
l = 10**12
while(l-s > 1):
    mid = (l-s)//2 + s
    c = 0
    for i in range(N):
        if T[i] > mid:
            if (T[i] - mid) % F[i] == 0:
                c += (T[i] - mid) // F[i]
            else:
                c += (T[i] - mid) // F[i] + 1
    if c > K:
        s = mid
    else:
        l = mid
print(l)

Measured memory_bytes: 121292
N,T = map(int,input().split())
item=sorted([list(map(int,input().split())) for _ in range(N)],key=lambda x:x[0])

dp=[0]*(T+1)

for a,b in item:
    for t in reversed(range(T)):
        dist=min(T,t+a)
        dp[dist] = max(dp[t]+b,dp[dist])
print(max(dp))


Measured memory_bytes: 47832
using System;
using System.Linq;

class Program
{
    static void Main(string[] args) {
        int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray();
        Console.WriteLine(solve(a[0],a[1]));
    }
    static int solve(int k, int s) {
        int count = 0;
        for(int x = 0; x <= k; x ++) {
            for(int y = 0; y <= k; y ++) {
                int z = s-x-y;
                if(z>=0 && z<=k) count ++;
            }
        }
        return count;
    }
}

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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()

int n;

void dfs(string str, char c_max)
{
    if (str.size() == n)
    {
        cout << str << '\n';
        return;
    }

    for (char c = 'a'; c <= c_max + 1; c++)
    {
        dfs(str + c, max(c, c_max));
    }
}

int main()
{
    cin >> n;

    dfs("a", 'a');
    // cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 3640
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;

const ll LLINF = 1LL << 60;
vector<vector<int>> G;

int dfs(int v, vector<int> &dp) {
    // 一度書き換えたノードは連結した最終ノードまで見て計算済み
    if(dp[v] != -1) return dp[v];

    int res = 0;
    for(auto nv : G[v]) {
        res = max(res, dfs(nv, dp) + 1);
    }
    return dp[v] = res;
}

int main() {
    int N, M;
    cin >> N >> M;
    G.assign(N, vector<int>());
    for(int i = 0; i < M; ++i) {
        int a, b;
        cin >> a >> b;
        --a, --b;
        G[a].push_back(b);
    }

    vector<int> dp(N, -1);
    int res = 0;
    // 連結していない場合もあるので、全部試す
    // dpを書き換える回数は高々N回
    for(int i = 0; i < N; ++i) res = max(res, dfs(i, dp));

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 8192
use proconio::input;
use std::cmp::min;

fn main() {
    input! {s: String}
    let mut ans = s.len()-1;
    for c in b'a'..=b'z' {
        ans = min(ans, s.split(c as char).map(|s| s.len()).max().unwrap());
    }
    println!("{}", ans);
}

Measured memory_bytes: 2144
s = gets(&:chomp)
sa = s.split(//)
slen=s.length-2
i=0
str = String.new
ans = 2
while i<slen/2
    str=str+sa[i]
    str2 = String.new
    #puts str
    j=i+1
    num=i+1
    num.times do |k|
        str2+=sa[j]
        j=j+1
    end
    #puts "str2 "+str2
    if str.eql?(str2)
        ans = str.length+str2.length
    end
    i=i+1
end
puts ans

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

int p( int x )
{
  int sum = 0;
  
  while( x ) {
    sum += x % 10;
    x /= 10;
  }
  return sum;
}

int main( void )
{
  int N;
  cin >> N;
  int sum;
  int min = INT_MAX;

  int A, B;

  for( int i = 1; i < N; i++ ) {
    A = i;
    B = N - i;
    sum = p( A ) + p( B );
    if( sum < min )
      min = sum;
  }

  cout << min << endl;
}

Measured memory_bytes: 3612
#include <iostream>
using namespace std;
int main(){
    int n, m, ans;
    cin >> n >> m;
    int A[n][m], B[m][1];
    for (int i=0; i<n; i++){
        for (int j=0; j<m; j++){
            cin >> A[i][j];
        }
    }for (int i=0; i<m; i++){
        cin >> B[i][0];
    }for (int i=0; i<n; i++){
        ans = 0;
        for (int k=0; k<m; k++){
            ans += A[i][k]*B[k][0];
        }cout << ans << endl;
    }return 0;
}


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

int main(){
	int N,M;
	cin >> N >> M;
	int sum=0;
	for(int i=0;i<M;i++){
		int A;
		cin >> A;
		sum+=A;
	}
	cout << ((N>=sum)?(N-sum):(-1)) << endl;
	return 0;
}

Measured memory_bytes: 3644
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　 |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/












int N, M;
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N >> M;

    vector<pair<int, int>> v;
    rep(i, 0, N) {
        int a, b; cin >> a >> b;
        v.push_back({ a,b });
    }
    sort(all(v));

    ll ans = 0;
    fore(p, v) {
        int d = min(M, p.second);

        ans += 1LL * p.first * d;
        M -= d;
    }
    cout << ans << endl;
}




Measured memory_bytes: 1400
#include <bits/stdc++.h>
#define int int64_t
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i))
#define REP3(i, m, n) for (int i = (m); (i) < (int)(n); ++ (i))
#define REP_R(i, n) for (int i = (int)(n) - 1; (i) >= 0; -- (i))
#define REP3R(i, m, n) for (int i = (int)(n) - 1; (i) >= (int)(m); -- (i))
#define REPP(i, n) for (int i = 1; (i) < (int)(n+1); ++ (i))
#define REPR(i, n) for (int i = (int)(n) - 1; (i) >= 0; -- (i))
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i, m, n) for(int i=(m)-1; i>=(n); i--)
#define ALL(v) v.begin(), v.end()
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())
#define SORTR(c) sort((c).begin(),(c).end(),greater<int>());
#define BIT(n) (1LL<<(n))
#define PCNT(x) __builtin_popcountll(x)
#define GCD(x,y) __gcd(x,y)
#define LCM(x,y) x/__gcd(x,y)*y
#define PB push_back
#define MP make_pair
#define endl "\n"
#define pa cout << ans << endl
#define p(x) cout << x << endl
#define pall(x) for(auto iter : x) p(iter)
#define yes cout << "Yes" << endl
#define no cout << "No" << endl
#define yn(x) cout << (x ? "Yes" : "No") << endl
using namespace std;
using Graph = vector<vector<int> >;
using WeightedGraph = vector<vector<pair<int, int> > >;
typedef long double LD;
typedef vector<int> VI;
typedef vector<vector<int> > VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
const int INF = 2000000000;
const long double PI = acosl(-1);
const int MOD = 1000000007;
void print() {cout << endl;}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head; if (sizeof...(tail) != 0) cout << " ";print(forward<Tail>(tail)...);}
template <class T> void print(vector<T> &vec) {for (auto& a : vec) {cout << a; if (&a != &vec.back()) cout << " ";} cout << endl;}
template <class T> void print(vector<vector<T>> &df) { for (auto& vec : df) { print(vec);}}


signed main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    cout << fixed << setprecision(10);
    int ans = 0;
    
    string S, T;
    cin >> S >> T;

    int N = S.length();
    REP(i,N) {
        if (S[i] != T[i]) ans++;
    }
    cout << ans << endl;
    
    
    
    return 0;
}

/*
cd ~/Desktop/Programming/AtCoder/contest/abc172/abc172_b && sh shellscripts/test_cpp.sh
cd ~/Desktop/Programming/AtCoder/contest/abc172/abc172_b && sh shellscripts/etest_cpp.sh
cd ~/Desktop/Programming/AtCoder/contest/abc172/abc172_b && sh shellscripts/submit_cpp.sh
*/


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

int main(){
  double n;cin>>n;
  double k;cin>>k;
  double chance=0;
  
  for(int i=1;i<=n;i++){
    if(k/double(i)<1){
      chance+=1/n;
    }else{
    chance+=(1/n)*pow(0.5,ceil(log2(k/double(i))));
    }
  }
  cout<<setprecision(13)<<chance<<endl;
  return 0;
}

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

int main() {
    string s;
    cin >> s;
    int ans=1000;
    int dis;
    for(int i=0;i<s.size()-2;i++){
        int a = (s.at(i)-'0')*100+(s.at(i+1)-'0')*10+(s.at(i+2)-'0');
        dis = abs(a-753);
        ans = min(ans,dis);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
PENALTY = 3000


def func(n, a, b, c):
    if n == N:
        return (abs(a - A) if a > 0 else PENALTY) +\
               (abs(b - B) if b > 0 else PENALTY) +\
               (abs(c - C) if c > 0 else PENALTY)
    else:
        r0 = func(n + 1, a, b, c)
        r1 = func(n + 1, a + l[n], b, c) + 10
        r2 = func(n + 1, a, b + l[n], c) + 10
        r3 = func(n + 1, a, b, c + l[n]) + 10
        return min(r0, r1, r2, r3)


N, A, B, C = map(int, input().split())
l = [int(input()) for _ in range(N)]
ans = func(0, 0, 0, 0)
print(ans - 30)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
const long long INF=1e18,MOD=1e9+7;
int main(){
  int n,ans=0;
  string s;
  map<string,int>card;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>s;
    card[s]++;
  }
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>s;
    card[s]--;
  }
  for(auto itr:card){
    ans=max(ans,itr.second);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll dp[105][100005];
ll fun(ll v[],ll w[], ll i, ll Wt)
{
    if(Wt<=0 || i<0)
    return 0;
    if(dp[i][Wt]!=-1)
    return dp[i][Wt];
    if(Wt>=w[i])
      return dp[i][Wt]= max(v[i]+fun(v,w,i-1,Wt-w[i]),fun(v,w,i-1,Wt));
    return dp[i][Wt]=fun(v,w,i-1,Wt);
    
}
 
int main() {
   
   ll i,n,k,j,W;
   cin>>n>>W;
   ll v[n+1];
   ll w[n+1];
   for(i=0;i<n;i++)
   {
       cin>>w[i];
       cin>>v[i];
   }
   memset(dp,-1,sizeof(dp));
   cout<<fun(v,w,n-1,W);
    
}

Measured memory_bytes: 85596
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
typedef long long ll;

int main()
{
    string s;
    cin>>s;
    int p = (s[0]-'0')*10+(s[1]-'0');
    int q = (s[2]-'0')*10+(s[3]-'0');

    if(p<=12 && (q>12||q==0) && p>0)
    {
        cout<<"MMYY"<<endl;
    }
    else if((p>12||p==0) && q<=12 && q>0)
    {
        cout<<"YYMM"<<endl;
    }
    else if((p>12 && q>12) || (p==0 && q==0) || (p==0 && q>12) || (q==0 && p>12))
    {
        cout<<"NA"<<endl;
    }
    else{
        cout<<"AMBIGUOUS";
    }
}



Measured memory_bytes: 256
fun main(args: Array<String>) {
    val (X, Y, x, y, r) = readLine()!!.split(" ").map { it.toInt() }
    val hoge = listOf(x + r, x - r, y + r, y - r)

    var result = "Yes"
    hoge.forEach {
        if (it > X || it > Y) result = "No"
        if (it < 0) result = "No"
    }
    println(result)
}


Measured memory_bytes: 31996
'use strict'

const main = (INPUT) => {
  const input = INPUT.split('\n')
  const N = input[0]
  const V = input[1].split(' ').map(n => Number(n))
  const C = input[2].split(' ').map(n => Number(n))
  let ans = 0
  for (let i = 0; i < N; i++) {
    if (V[i] > C[i]) {
      ans += V[i] - C[i]
    }
  }
  console.log(ans)
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'))


Measured memory_bytes: 7372
import java.util.LinkedList;
import java.util.Scanner;
import java.util.Iterator;

class Graph {
	private int totalVertex;
	//adjMatrix[u][v] = 1 if there is an edge from u to v, otherwise 0
	private int[][] adjMatrix;
	//adjWeight[u][v] -- the weight of the edge from u to v if there is one
	private int[][] adjWeight;
	//if a node is settled (e.g., processed in the Dijkstra's algorithm)
	private Boolean[] ifSettled;
	public Graph() { totalVertex = 0; }
	public int getTotalVertex() { return totalVertex; }
	//load graph from standard input
	public void loadAdjMatrix() {
		Scanner in = new Scanner(System.in);
		totalVertex = in.nextInt();
		adjMatrix = new int[totalVertex][totalVertex];
		adjWeight = new int[totalVertex][totalVertex];
		ifSettled = new Boolean[totalVertex];
		int i, j;
		for(i = 0; i < totalVertex; i ++) {
			ifSettled[i] = false;
			for(j = 0; j < totalVertex; j ++) {
				adjMatrix[i][j] = adjWeight[i][j] = 0;
			}
		}
		int u, v;
		for(i = 0; i < totalVertex; i ++) {
			u = in.nextInt();
			int degree = in.nextInt();
			for(j = 0; j < degree; j ++) {
				v = in.nextInt(); 
				adjMatrix[u][v] = 1;
				adjWeight[u][v] = in.nextInt();
			}	
		}
		in.close();
	}
	
	
	
	
	
	//return weight of the edge from u to v if there is one
	public int getWeight(int u, int v) {
		return adjWeight[u][v];
	}
	
	//return neighbors of u as a LinkedList
	public LinkedList<Integer> getNeighbors(int u) {
		LinkedList<Integer> tmp = new LinkedList<Integer>();
		for(int v = 0; v < totalVertex; v ++) {
			if(adjMatrix[u][v] == 1) tmp.add(v);
		}
		return tmp;
	}
	
	//return unsettled neighbors of u as a LinkedList
	public LinkedList<Integer> getUnsettledNeighbors(int u) {
		LinkedList<Integer> tmp = new LinkedList<Integer>();
		for(int v = 0; v < totalVertex; v ++) {
			if((adjMatrix[u][v] == 1) && (ifSettled[v] == false)) tmp.add(v);
		}
		return tmp;
	}
	
	//return the unsettled node that has the smallest dist
	public int getUnsettledNearest(int[] dist) {
		int md = Integer.MAX_VALUE;
		int mv = -1;
		int v;
		for(v = 0; v < totalVertex; v ++) {
			if((ifSettled[v] == false) && (dist[v] < md)) {
				md = dist[v];
				mv = v;
			}
		}
		return mv;
	}
	//implement the following	
	public int[] Dijkstra(int s) {
	int[] path = new int[totalVertex];
	LinkedList<Integer> sss = new LinkedList<Integer>();
	path[s] = 0;
	for(int i = 0; i < totalVertex; i++) {
		if(i != s) {
			path[i] = Integer.MAX_VALUE;
		}
	}
	while(sss.size() < totalVertex) {
		int V = getUnsettledNearest(path);
		LinkedList<Integer> X = getUnsettledNeighbors(V);
		Iterator<Integer> it = X.iterator();
		sss.add(V);
		ifSettled[V] = true;
		while(it.hasNext()) {
			int x = it.next();
			if(path[V] + getWeight(V, x) < path[x]) {
				path[x] = path[V] + getWeight(V, x);
			}
		}
	}
	return path;
	}
}

public class Main {
	public static void main(String[] argv) {
		Graph g = new Graph();
		g.loadAdjMatrix();
		int[] dist = g.Dijkstra(0);
		for(int i = 0; i < g.getTotalVertex(); i ++) {
			System.out.println(i + " " + dist[i]);
		}
	}
}


Measured memory_bytes: 39956
#include <bits/stdc++.h>
#include <stdio.h>      /* printf */
#include <math.h>
using namespace std;
#define PI 3.141592653589793238462643
//3.14159265359
int main()
{
    double a,b,h,m;
    cin>>a>>b>>h>>m;
    double angle=abs((60*h-11*m)/2);
    double param, result;
    param = angle;
    result = cos ( param * PI / 180.00);
    //printf ("The cosine of %f degrees is %f.\n", param, result );
    double rez;
    double kolku=a*a+b*b-2*a*b*result;
    rez=sqrt(kolku);
    //cout<<rez<<endl;
    std::cout << std::fixed;
    std::cout << std::setprecision(20)<<rez<<endl;;
    return 0;
}


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

typedef long long ll;

char dx[] = {0,1,2,0,2,0,1,2};
char dy[] = {0,0,0,1,1,2,2,2};
int main () {

    int h,w;
    cin >> h >> w;
    vector<string> s(h);
    char m[100][100] = {};

    for(int i=0; i<h; i++) {
	cin >> s[i];
    }

    for(int i=0; i<h; i++) {
	for(int j=0; j<w; j++) {
	    if(s[i][j] == '#') {
		for(int k=0; k<8; k++) {
		    m[i+dy[k]][j+dx[k]] ++;
		}
	    }
	}
    }
    for(int i=0; i<h; i++) {
	for(int j=0; j<w; j++) {
	    if(s[i][j] == '#') 
		m[i+1][j+1] = '#';
	}
    }
		

    
    for(int i=0; i<h; i++) {
	for(int j=0; j<w; j++) {
	    if( m[i+1][j+1] == '#' )
		cout << "#";
	    else
		printf("%d",m[i+1][j+1]);
	}
	cout << endl;
    }
    
    
    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		int n = in.nextInt();
		int x = in.nextInt();
		int[] l = new int[n];
		for (int i = 0; i < n; i++)
			l[i] = in.nextInt();
		System.out.println(solve(n, x, l));
		in.close();
	}

	private static int solve(int n, int x, int[] l) {
		int d = 0;
		for (int i = 0; i < n; i++) {
			d += l[i];
			if (d > x)
				return i + 1;
		}
		return n + 1;
	}
}


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


int main() {
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  bool ans = false;
  if(abs(a-c) <= d) ans = true;
  else if(abs(a-b) <= d && abs(c-b) <= d) ans = true;

  puts(ans?"Yes":"No");
}


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

#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define repn(i, n) for(int (i) = 1; (i) <= (n); (i)++)
#define repr(i, n) for(int (i) = (n-1); (i) >= 0; (i)--)
#define all(x) (x).begin(), (x).end()
#define lint long long
#define ulint unsigned long long
#define fi first
#define se second
#define setpre(x) cout << fixed << setprecision(x)
#define ii(x) int x; cin >> (x)
#define ii2(x, y) int x, y; cin >> (x) >> (y)
#define ii3(x, y, z) int x, y, z; cin >> (x) >> (y) >> (z)
#define out(x) cout << (x) << endl
#define outs(x) cout << (x) << " "
#define yn(x) cout << ((x)?("Yes"):("No")) << endl
#define YN(x) cout << ((x)?("YES"):("NO")) << endl
#define bit_c(x) __builtin_popcountll(x)

inline void logger(){ cout << " [LOGGER] " << endl; }
template<typename A, typename... B>
void logger(const A& a, const B&... b){
    cout << a << " , ";
    logger(b...);
}

typedef pair<lint, lint> P;
const lint MOD = 1000000007;
const lint MOD9 = 998244353;
const lint INF = MOD * MOD;
const int MAX = 1005;

/* ...o(^-^)o... */

int dist[MAX][MAX];
bool seen[MAX][MAX];

int main(){
    int h, w; cin >> h >> w;
    vector<string> vs(h);
    rep(i, h) cin >> vs[i];

    queue<P> que;
    rep(i,h) rep(j, w){
        if(vs[i][j] == '#'){
            que.push(P(i, j));
            dist[i][j] = 0; seen[i][j] = true;
        }
    }

    vector<P> d = {P(-1, 0), P(1, 0), P(0, -1), P(0, 1)};

    while(!que.empty()){
        P p = que.front(); que.pop();
        rep(k, 4){
            int s = p.fi+d[k].fi, t = p.se+d[k].se;
            if(s < 0 || s >= h || t < 0 || t >= w) continue;
            if(seen[s][t]) continue;
            seen[s][t] = true;
            dist[s][t] = dist[p.fi][p.se] + 1;
            que.push(P(s, t));
        }
    }

    int ans = 0;
    rep(i, h) rep(j, w) ans = max(ans, dist[i][j]);
    out(ans);
}

Measured memory_bytes: 22580
a=int(input())
b=int(input())
c=int(input())
x=int(input())/50
ans=0
for i in range(0,a+1):
  for j in range(0,b+1):
    for k in range(0,c+1):
      if x==10*i+2*j+k:
        ans+=1
        
print(ans)

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

int main(){
    int k; //湖の１周の長さ
    int n; //家の個数
    cin >> k >> n;

    vector<int> dist(n); //隣の家の距離
    for(int i=0; i<n; i++) cin >> dist[i];

    int max1 = 0; //隣の家との距離の最大値
    
    /* 隣の家との距離の最大値を求める */
    for(int i=0; i<n-1; i++){
        max1 = max(dist[i+1]-dist[i],max1);
    }

    //最初の家と最後の家との距離を求めて、比べる
    max1 = max(max1,dist[0]+(k-dist[n-1]));

    cout << k-max1 << endl;
}

Measured memory_bytes: 1024
#include <iostream>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
int main() {
    char s[4] ;
    int x;
    cin >>  s;
    if ((s[0]==s[1] &&s[1] ==s[2]) || (s[3]==s[1]&&s[1]==s[2])){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include <atcoder/dsu>

//QCFium法
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

//浮動小数点処理高速化
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace std;
using namespace atcoder;
using i64 = int64_t;
using f80 = __float80;
using u64 = uint_fast64_t;

constexpr i64 INF = 1010000000000000017LL;
constexpr u64 MOD = 1000000007LL;
constexpr f80 PI = 3.14159265358979323846;

#define _overload3(_1,_2,_3,name,...) name
#define repi(i,start,end) for(int i=(int)(start);i<(int)(end);++i)
#define _rep(i,n) repi(i,0,n)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(i,start,end) for(int i=(int)(start);i>(int)(end);--i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()

#define v(T) vector<T>
#define vv(T) v(v(T))
#define vvv(T) v(v(v(T)))
typedef v(int) vi;

#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >

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

template<typename T> ostream &operator<<(ostream &os, const vector< T > &v){
  rep(i,v.size()) os << v[i] << (i + 1 != v.size() ? " " : "");
  return os;
}
template<typename T> istream &operator>>(istream &is, vector< T > &v){
  for(T &in : v) is >> in;
  return is;
}

//sort(rng(P),[](const vi &a, const vi &b){return a[1]<b[1];});

void Main()
{
  int N, Q;
  cin >> N >> Q;
  dsu d(N);

  int t, u, v;
  rep(i, Q) {
    cin >> t >> u >> v;
    if(t==0) {
      d.merge(u, v);
    } else {
      if(d.same(u, v)) {
        cout << "1\n";
      } else {
        cout << "0\n";
      }
    }
  }
}

int main()
{
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
//  cout << fixed << setprecision(15);
  Main();
}


Measured memory_bytes: 3928
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define MP make_pair
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define PLI pair<ll, int>
#define PIL pair<int, ll>
#define STR string
#define Fst first
#define Snd second
#define SHN 1e9
#define LSHN 1e18
using namespace std;
int n;
vector<int> vx,vy;
int main()
{
	cin >>n;
	for (int i=0;i<n;i++)
	{
		int x,y;
		cin >>x>>y;
		vx.push_back(x),vy.push_back(y);
	} 
	sort(vx.begin(),vx.end());
	sort(vy.begin(),vy.end());
	if (n%2)
	{
		int x=vx[n/2],y=vy[n/2];
		cout <<y-x+1;
	}
	else
	{
		int x=vx[n/2-1]+vx[n/2],y=vy[n/2-1]+vy[n/2];
		cout <<y-x+1;
	}
	return 0;
}

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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define PI 3.14159265358979
#define MOD 1000000007 // = 10^9 + 7

using namespace std;
using ll = long long;

void solve()
{
	ll n;
	cin >> n;
	vector<ll> a(n + 1);
	vector<ll> b(n);
	for(int i = 0; i < n + 1; ++i)
	{
		cin >> a[i];
	}
	for(int i = 0; i < n; ++i)
	{
		cin >> b[i];
	}

	ll ans = 0;
	for(int i = 0; i < n; ++i)
	{
		if (a[i] <= b[i])
		{
			ans += min(b[i], a[i] + a[i + 1]);
			a[i + 1] = max(0LL, a[i + 1] + a[i] - b[i]);
		}
		else
		{
			ans += b[i];
		}	
	}
	cout << ans;
}

int main()
{
	fastio;
	solve();

	return 0;
}

Measured memory_bytes: 4760
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int k = sc.nextInt();

    if(b - a + 1 <= k * 2){
      for(int i = a; i <= b; i++){System.out.println(i);}
    }else{
      for(int i = a; i <= a+k-1; i++){
        System.out.println(i);
      }
      for(int j = b-k+1; j <= b; j++){
        System.out.println(j);
      }
    }
    
  }
}

/*
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
String blank = sc.nextLine();
String s = sc.nextLine();
System.out.println();
System.exit(0)
*/


Measured memory_bytes: 22996
from collections import Counter,defaultdict,deque
import sys
from itertools import permutations, combinations
from heapq import heappop, heappush
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
    
def inp(): # n=1
    return int(input())
def inpm(): # x=1,y=2
    return map(int,input().split())
def inpl(): # a=[1,2,3,4,5,...,n]
    return list(map(int, input().split()))
def inpls(): # a=['1','2','3',...,'n']
    return list(input().split())
def inplm(n): # x=[] 複数行
    return list(int(input()) for _ in range(n))
def inpll(n): # [[1,1,1,1],[2,2,2,2],[3,3,3,3]]
    return sorted([list(map(int, input().split())) for _ in range(n)])

def main():
    n=inp()
    t=[[] for _ in range(n)]
    s=[[] for _ in range(n)]
    for i in range(n):
        a=inp()
        for _ in range(a):
            x,y=inpm()
            if y==1:
                t[i].append(x-1)
            else:
                s[i].append(x-1)
    res=0
    for k in range(pow(2,n),-1,-1):
        flag = True
        cnt = 0
        for i in range(n):
            if (k>>i)&1 == 1:
                for e in t[i]:
                    if (k>>e)&1 == 0:
                        flag = False
                for e in s[i]:
                    if (k>>e)&1 == 1:
                        flag = False
                cnt+=1
        if flag:
            res = max(res,cnt)
    print(res)


if __name__ == "__main__":
    main()

Measured memory_bytes: 44636
import java.io.*;

public class Main{
    public static void main(String[] args){
        double n = 0;
        String line;
        int i = 0, j = 0;
        double[] number;
        double average = 0;
        int sum = 0;
        double sigma = 0;
        double[] deviation;
        deviation = new double[1000];

        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        try {
            while(true){
                line = reader.readLine();
                n = Integer.parseInt(line);
                if(n == 0){
                    break;
                }
                number = new double[(int)n];
                line = reader.readLine();
                String[] data = line.split(" ",(int)n);
                for(i = 0; i < n; i++){
                    number[i] = Integer.parseInt(data[i]);
                    sum += number[i];
                }
                average = sum/n;
                for(i = 0; i < n; i++){
                    sigma += Math.pow(number[i] - average, 2.0);
                }
                deviation[j] = Math.sqrt(sigma/(double)n);
                j++;
                sum = 0;
                average = 0;
                sigma = 0;
            }
            
            for(i = 0; i < j; i++){
                System.out.printf("%.8f\n",deviation[i]);
            }         
            
        } catch (NumberFormatException e) {
            System.out.println(e);
        } catch (IOException e) {
            System.out.println(e);
        }
    }
}


Measured memory_bytes: 25368
#include<bits/stdc++.h>
#define f(i,a,b) for(long long i=a;i<b;i++)
#define pb(i) push_back(i)
#define mk(x,y) make_pair(x,y)
#define F first
#define S second
#define accu(i) fixed<<setprecision(i)
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
typedef long long ll;
using namespace std;

class A{
	public:
		ll val,idx;
};

bool comp(A a,A b){
	return a.val<b.val;
}

int main(){
    FIO;
	ll n,p;cin>>n;
	A *a = new A[n];
	f(i,0,n){
		cin>>p;
		a[i].val=p;
		a[i].idx=i;
	}
	sort(a,a+n,comp);
	f(j,0,n) cout<<a[j].idx+1<<" ";
	return 0;
}

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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

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

  ll n;
  cin >> n;
  string s;
  cin >> s;

  ll ans = 0;
  REP(i, n-1){
    vll aCount(26, 0), bCount(26, 0);
    for(int j = 0; j <= i; j++)
      aCount[s[j]-'a']++;
    for(int k = i+1; k < n; k++)
      bCount[s[k]-'a']++;

    ll num = 0;
    REP(k, 26){
      if(aCount[k] >= 1 && bCount[k] >= 1)
        num++;
    }
    ans = max(ans, num);
  }

  cout << ans << endl;
}


Measured memory_bytes: 256