akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1000000007;
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

// ダイクストラ法
// 参照：蟻本　p97
// O(mlogn)
struct edge{int to;ll cost;};
typedef pair<ll,int> P; // firstは最短距離、secondは頂点の番号

int n; // 頂点の数
vector<edge> G[100010];
ll d[100010];

void dijkstra(int s){
    priority_queue<P,vector<P>, greater<P>> que;
    fill(d,d+n,1LL<<60);
    d[s]=0;
    que.push(P(0,s));

    while(!que.empty()){
        P p=que.top(); que.pop();
        int v=p.second;
        if(d[v]<p.first) continue;
        rep(i,G[v].size()){
            edge e=G[v][i];
            if(d[e.to]>d[v]+e.cost){
                d[e.to]=d[v]+e.cost;
                que.push(P(d[e.to],e.to));
            }
        }
    }
}

int main(){
    cin >> n;
    for (int i=0; i<n-1; ++i) {
        int a, b;
        ll c;
        cin >> a >> b >> c;
        a--,b--;
        edge e = {b, c};
        G[a].push_back(e);
        e={a,c};
        G[b].push_back(e);
    }
    
    int q,k;
    cin>>q>>k;
    k--;
    dijkstra(k); // 頂点0からの距離を求める
    //rep(i,n) cout<<d[i]<<endl;
    ll ans[q];
    rep(i,q){
        int x,y;
        cin>>x>>y;
        x--,y--;
        ans[i]=d[x]+d[y];
    }

    rep(i,q) cout<<ans[i]<<endl;
}




Measured memory_bytes: 11120
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,k;
  cin >> n >> k;
  string s;
  cin >> s;
  for(int i=0;s[i];i++){
    if(i+1==k){
      s[i]+=32;
    }
  }
  cout << s << endl;
  return 0;
}

Measured memory_bytes: 3596
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce


INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


n, m = LI()
s = LI()
t = LI()
dp = [[1] * (m + 1) for _ in range(n + 1)]


for i in range(n):
    for j in range(m):
        if s[i] == t[j]:
            dp[i + 1][j + 1] = (dp[i + 1][j] + dp[i][j + 1]) % mod
        else:
            dp[i + 1][j + 1] = (dp[i][j + 1] + dp[i + 1][j] - dp[i][j]) % mod



print(dp[n][m])

Measured memory_bytes: 73436
#include<bits/stdc++.h>
using namespace std;
int n,h,w;
map<long long,int>mp;
long long cnt[10];
int fx[9]={0,0,0,1,1,1,-1,-1,-1};
int fy[9]={0,-1,1,0,-1,1,0,-1,1};
bool in(int x,int y)
{
	if(x-1>=1 && x+1<=h && y-1>=1 && y+1<=w)return 1;
	return 0;
}
int main()
{
	scanf("%d%d%d",&h,&w,&n);
	cnt[0]=1ll*(h-2)*(w-2);
	int x,y;
	for(int i=1;i<=n;i++)
	{
		scanf("%d%d",&x,&y);
		for(int j=0;j<9;j++)
		{
			int xx=x+fx[j],yy=y+fy[j];
			if(!in(xx,yy))continue;
			long long p=1ll*xx*1000000000+yy;
			if(mp.find(p)!=mp.end())
			{
				cnt[mp[p]]--; cnt[++mp[p]]++;
			}
			else
				cnt[0]--,cnt[mp[p]=1]++;
		}
	}
	for(int i=0;i<=9;i++)
		printf("%lld\n",cnt[i]);
	return 0;
}


Measured memory_bytes: 56448
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n;
	while(cin>>n&&n!=-1){
		string ans;
		for(;n>0;n/=4)ans+=n%4+'0';
		if(ans.size()==0)cout<<0;
		else for(int i=ans.size()-1;i>=0;i--)cout<<ans[i];
		cout<<endl;
	}
}

Measured memory_bytes: 1200
#include<bits/stdc++.h>
#define INF 100000000000000
#define ll long long
using namespace std;
ll a,b,c,d,e,n,k;
ll arr[100001];
ll foo[100001];
ll trump(ll x){
    if(x==n)return 0;
    if(x>n)return INF;
    if(foo[x]!=INF)return foo[x];
    ll a=INF;
    for(int i=1;i<=k;i++){
        a=min(a,abs(arr[x]-arr[x+i])+trump(x+i));
    }
    return foo[x]=a;
}
int main(){
    for(int i=0;i<=100001;i++)foo[i]=INF;
    ios::sync_with_stdio(false);
    cin>>n>>k;
    for(int i=1;i<=n;i++){
        cin>>c;
        arr[i]=c;
    }
    cout<<trump(1)<<endl;
    return 0;
}


Measured memory_bytes: 6528
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <cmath>
#include <map>

int main(void) {

	int k, i;

	std::cin >> k >> i;


	std::cout << k - i + 1 << std::endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(n); ++i)
#define repr(i, a, b) for (int i=a; i<(b); ++i)
#define reprev(i, n) for (int i=n-1; i>=0; --i)
#define reprrev(i, a, b) for (int i=b-1; i>=(a); --i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int main() {
    cout << fixed << setprecision(10);
    
    int N; cin >> N;
    vector<int> A(N);
    // vector<bool> ped(N, false);
    rep(i, N) cin >> A[i];
    // int csum = 0;

    vector<int> sts;
    sts.emplace_back(A[0]);

    // A[i]未満の値があれば、それに上塗り、
    // A[i]未満の値がなければ、新たな色で追加する
    // stsにて降順で管理する
    repr(i, 1, N) {
        if (A[i] <= sts[sts.size()-1]) {
            // stsの最小の値 以下の場合
            sts.emplace_back(A[i]);
        } else {
            // stsの最小の値より大きい場合
            // なるべくA[i]に近くて、A[i]より小さい数を見つける
            int l = -1, r = sts.size();
            while (l + 1 < r) {
                int c = (l+r) / 2;
                if (sts[c] < A[i]) {
                    r = c;
                } else {
                    l = c;
                }
            }
            sts[r] = A[i];
        }
    }
    cout << sts.size() << endl;
    return 0;
}

Measured memory_bytes: 1276
#include<iostream>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int pow(int a,int b){
	if(b==0)return 1;
	if(b%2!=0)return a*pow(a,b-1);
	else return pow(a*a,b/2);
}

int main(){
	int d,n;
	cin>>d>>n;
	if(n==100)cout<<(n+1)*pow(100,d)<<endl;
	else cout<<n*pow(100,d)<<endl;
	return 0;
}

Measured memory_bytes: 256
N = gets.split.map(&:to_i)
ar = gets.split.map(&:to_i)

ans = 1000000000
for moke in ar do
  s = 0
  while moke%2==0 do
    moke /= 2
    s += 1
  end
  ans = (ans<s ? ans : s)
end
puts ans

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

typedef pair<int, int> pii;
typedef long long ll;
template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()
#define dump(x) cout << #x << " = " << (x) << endl
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

template<class T, class U> void chmin(T& t, const U& u) { if (t > u) t = u; }
template<class T, class U> void chmax(T& t, const U& u) { if (t < u) t = u; }

template<class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
    os<<"("<<p.first<<","<<p.second<<")";
    return os;
}

template<class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    os<<"{";
    rep(i, v.size()) {
        if (i) os<<",";
        os<<v[i];
    }
    os<<"}";
    return os;
}

int main() {
    int N; cin >> N;
    cout << N * N * N << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <climits>
#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <vector>
#include <sstream>
#include <typeinfo>
#include <fstream>

#define DIV 1000000007

using namespace std;

long long N, L;
long long a[100005];

int main(){
	cin >> N >> L;
	long long maxcomb = -1;
	long long maxidx = -1;

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

	for(int i = 0; i < N-1; i++){
		if(maxcomb < a[i] + a[i+1]){
			maxidx = i;
			maxcomb = a[i] + a[i+1];
		}
	}
	if(maxcomb < L){
		cout << "Impossible" << endl;
		return 0;
	}

	cout << "Possible" << endl;
	for(int i = 0; i < maxidx; i++){
			cout << i+1 << endl;
	}
	for(int i = N-2; i > maxidx; i--){
			cout << i+1 << endl;
	}
	cout << maxidx+1 << endl;




}

Measured memory_bytes: 1536
import fractions
a,b,c,d=map(int,input().split())
before=(a-1)//c+(a-1)//d-(a-1)//(c*d//fractions.gcd(c,d))
after=b//c+b//d-b//(c*d//fractions.gcd(c,d))
print(before-after-a+b+1)

Measured memory_bytes: 5048
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define all(a) a.begin(),a.end()
#define SORT(a) sort(all(a))
#define int long long
#define FOR(i, m, n) for(int i = m;i < n;i++)
typedef vector<int> VI;
typedef vector<VI> VVI;
const int MOD=1000000007;
const long long INF = 1LL << 60;
//----------------------------------------------
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n,ans = 0;
    cin >> n;
    rep(i,n-1)ans += i + 1;
    cout << ans <<endl;
    
    return 0;
}

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

using namespace std;

#define x first
#define y second
#define mp make_pair
#define pb push_back

typedef long long ll;

const ll MOD = 1e9+7;
const ll INF = 1e9+5;
const int MAXN = 500005;

int n, m, k;
int a, b, c, d, e, f;
string s, t, r;
char c1, c2, c3;

int A[MAXN];
int B[MAXN];

set <int> S;

int main() {
	cin >>n;
  	for (int i=0 ; i<n ; i++) {
      cin >>a;
      S.insert(a);
    }
  	if (S.size() == n) cout <<"YES\n";
	else cout <<"NO\n"<<endl;
	return 0;
}

Measured memory_bytes: 9600
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,b) FOR(i,0,b)
#define PB push_back
typedef long long LL;
const LL INF = 1LL<<60;
using namespace std;
LL solve2(LL A,LL B,LL x,LL y){
	if(B%y) return INF;
	return abs(A*y-B*x)/y;
}
LL solve(LL A,LL B,LL x,LL y){
	LL ans = INF;
	ans=min(ans,A%x+B%y+solve2(A-A%x,B-B%y,x,y));
	ans=min(ans,-A%x+x+B%y+solve2(A-A%x+x,B-B%y,x,y));
	ans=min(ans,A%x-B%y+y+solve2(A-A%x,B-B%y+y,x,y));
	ans=min(ans,-A%x+x-B%y+y+solve2(A-A%x+x,B-B%y+y,x,y));
	return ans;
}
int main(){
	LL A,B,N,ans;
	cin >> A >> B >> N;
	ans=INF;

	FOR(i,1,N+1){
		FOR(j,1,N+1){
			ans=min(ans,solve2(A,B,i,j));		
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 3088
// ABC 042 B : Iroha Loves Strings (ABC Edition)
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

int main(){
  int N,L;
  string str;
  vector<string> slst;
  cin >> N >> L;
  for(int i=0; i<N; i++){
    cin >> str;
    slst.push_back(str);
  }
  sort(slst.begin(),slst.end());
  for(int i=0; i<N; i++){
    cout << slst[i] ;
  }
  cout << endl;
  return 0;
}


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

char pic[1010][1010];
int dp[1010][1010];

main()
{
	int n,m;
	scanf("%d %d",&n,&m);
	for(int i=1;i<=n;i++)
	{
		scanf("%s",&pic[i][1]);
	}
	dp[1][1]=1;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			if(pic[i][j]=='.')
			{
				int pls=0;
				if(i)
				{
					pls+=dp[i-1][j];
				}
				if(j)
				{
					pls+=dp[i][j-1];
				}
				dp[i][j]+=pls;
				dp[i][j]%=md;
			}
		//	printf("%d ",dp[i][j]);
		}
		//printf("\n");
	}
	printf("%d",dp[n][m]);
}

Measured memory_bytes: 5248
#include <iostream>
using namespace std;
int main(void){
    int a,b,c;
    cin >>a >>b >>c;
    
    if(a<=b && b<=c) cout<<a+b;
    else if(a<=c && c<=b) cout<<a+c;
    else if(b<=a && a<=c) cout <<b+a;
    else if(b<=c && c<=a) cout <<b+c;
    else if(c<=a && a<=b) cout <<c+a;
    else  cout <<b+c;
    
    return 0;
    
}

Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author TM
 */


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

class CSplittingPile {
public:
	void solve(std::istream& cin, std::ostream& cout) {
	    int n;
	    cin >> n;
	    vector<int> vec(n, 0);
	    long long res = 1e+14;
	    long long arai = 0;
        long long snuke = 0;

        for (int i = 0; i < n; ++i) {
            cin >> vec[i];
            arai += vec[i];
        }
        for (int j = 0; j < n-1; ++j) {
            snuke += vec[j];
            arai -= vec[j];
            res = min(abs(arai - snuke), res);
        }
        cout << res << endl;
	}
};


int main() {
	CSplittingPile solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define pb(x)                    push_back(x)
#define all(a)                   a.begin(), a.end()
#define dbg(a)                   cout<< #a <<" --> "<<(a)<<endl;
#define IO                       ios::sync_with_stdio(false); cin.tie(0);cout.tie(0)
#define read                     freopen("tst.txt","r",stdin)
#define write                    freopen("out.txt","w",stdout)
typedef long long ll;
using namespace std;


int ar[10005];

vector<ll> v;

main(){
//read;
IO;

string s,t;
ll k;
cin>>s>>k;
if(s.size()==1){
    cout<<k/2;
    return 0;
}
//s.push_back(s[0]);
ll ans = 0,n = s.size();
bool fl = false;
//if(s[0]==s[n-1])    fl = 1;
ll p = min(n*100ll, n*k);

for(ll i = 0; i<p/n; i++) t+=s;
n = s.size();
//cout<<t<<" p "<<p<<endl;

for(ll i = 1; i<p; i++){
    if(t[i]!=t[i-1])    continue;
    for(ll j = 0; j<26; j++){
        if(i+1<p && 'a'+j!=t[i-1] && 'a'+j!=t[i+1]){
            ans++;
            t[i] = 'a'+j;
            ar[i/n] = ans;
            break;
        }
        else if(i+1==p && 'a'  + j !=t[i-1]){
            ans++;
            t[i] = 'a'+j;
            ar[i/n] = ans;
            break;
        }
    }
}

if(p==n*k){
    cout<<ans<<endl;
    return 0;
}
//*/
ll tmp = 0;// = ar[0];
for(ll i = 0; i<p/n; i++){
    ar[i]-=tmp;
    tmp+=ar[i];
//    cout<<ar[i]<<" ";
}
//cout<<endl;
ll w = p/n-1;
/*
if(ar[0]==ar[w])    ans = k*ar[0];
else if(ar[1]==ar[w])   ans = ar[0] + (k-1)*ar[1];
else{
    ans = ar[0]*k/2 + ar[1]*(k+1)/2;
}*/
ll a = 0,b = 0;
for(ll i = 0; i<=w; i++){
    if(ar[0]==ar[i])    a++;
    else b++;
}
//cout<<a<<" "<<b<<" "<<w<<endl;
if(a==1)    ans = ar[0] + (k-1)*ar[1];
else if(a==w+1)   ans = k*ar[0];
else{
    ans = ar[0]*((k+1)/2) + ar[1]*(k/2);
}

cout<<ans<<endl;

return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
        String s = sc.next();
        String t = sc.next();
        char[] Ts = new char[t.length()];
        for(int a = 0; a < t.length(); a++) {
            Ts[a] = t.charAt(a);
        }
        String[] Scut = new String[s.length() - t.length() + 1];
        for(int i = 0; i < s.length() - t.length() + 1; i++) {
            Scut[i] = s.substring(i, i + t.length());
        }
        int count = 0;
        int mostCount = 0;
        for(int j = 0; j < s.length() - t.length() + 1; j++) {
            for(int b = 0; b < t.length(); b++) {
                if(Scut[j].charAt(b) == Ts[b]) {
                    count++;
                }
            }
            if(mostCount <= count) {
                mostCount = count;
            }
            count = 0;
        }
        System.out.println(t.length() - mostCount);
	}
}

Measured memory_bytes: 36668
# -*- coding: utf-8 -*-
# スペース区切りの整数の入力
# b, c =
# a = int(input())
n = str(input())
# target_list = [int(i) for i in input().split()]

# 判定
if int(n) % 1000 == 0:
    print(0)
else:
    print(1000 - int(n) % 1000)


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

#include <iostream>


#define MOD 1000000007

using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<ll,ll> Pll;
typedef vector<Pll> VPll;


auto f=[]()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
};


int main()
{
	f();
	int n;cin>>n;
	int i=0;
	VPll arr;
	while(i<n)
	{
		ll d,e;cin>>d>>e;
		arr.push_back({d,e});
		i++;
	}

	sort(arr.begin(),arr.end(),[](const Pll& a, const Pll& b)
	{
		if(a.second==b.second)
			return a.first>b.first;
		return a.second<b.second;
	});
	
	ll t=0;
	for(auto i=0;i<n;++i)
	{
		if(t+arr[i].first>arr[i].second)
		{
			cout<<"No\n";
			return 0;
		}
		t+=arr[i].first;
	}
	cout<<"Yes\n";
	return 0;
}


Measured memory_bytes: 6512
use std::io::*;

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

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

fn main() {
    let n = read::<usize>();
    let a = read_vec::<usize>();
    let mut min = a[0];
    let mut max = a[0];
    for x in a {
        if min > x {
            min = x;
        }
        if max < x {
            max = x;
        }
    }
    println!("{}",max-min);
}


Measured memory_bytes: 4352
n = int(input())
t, a = list(map(int, input().split()))
h = list(map(int, input().split()))

tem = []
for i in range(n):
  tem.append((t - h[i] * 0.006, i + 1))

print(sorted(tem, key=lambda x: abs(x[0] - a))[0][1])


Measured memory_bytes: 3188
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <map>
#include <cmath>
 
#define rep(i,n) for(int i = 0;i < (n);i++)
#define all(x) (x).begin(),(x).end()
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)

using namespace std;

typedef long long int ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<pair<int, int> > vpi;
typedef vector<pair<ll, ll> > vpl;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
  string s, t;
  cin >> s >> t;
  reverse(all(s));
  reverse(all(t));
  bool match = false;
  rep(i, (int)s.size()){
    if(s[i] == t[0] || s[i] == '?'){
      bool flag = true;
      rep(j, (int)t.size()){
        if(!(s[i+j] == t[j] || s[i+j] == '?')) flag = false;
      }
      if(flag){
        rep(j, (int)t.size()) s[i+j] = t[j];
        match = true;
        break;
      }
    }
  }
  reverse(all(s));
  if(match){
    rep(i, (int)s.size()){
      if(s[i] == '?') cout << 'a';
      else cout << s[i];
    }
    cout << endl;
  }else{
    cout << "UNRESTORABLE" << endl;
  }
	return 0;
}


Measured memory_bytes: 256
import java.util.*;
 
class process {
    public String name;
    public int time;
     
    public process(String name,int time){
        this.name = name;
        this.time = time;
    }
}

public class Main {
 
    public static void main(String[] args) {
 
        Scanner sc = new Scanner(System.in);
 
        int n = sc.nextInt();
        int q = sc.nextInt();
 
        ArrayList<process> ar = new ArrayList<process>();
        ArrayList<process> result = new ArrayList<process>();
         
        for (int i = 0; i < n; ++i){
            ar.add(new process(sc.next(),Integer.parseInt(sc.next())));
        }
         
        int LapsedTime = 0,i = 0;
        process p;
         
        while(true){
            if(i < n){
                if((p = ar.get(i)).time - q <= 0){
                    LapsedTime += p.time;
                    result.add(new process(p.name,LapsedTime));
                    ar.remove(i);
                    n--;
                } else {
                    LapsedTime += q;
                    p.time = p.time - q;
                    i++;
                }
            } else {
                i = 0;
            }
            if (n == 0){
                break;
            }
        }
        for(process r:result) {
            System.out.println(r.name + " " + String.valueOf(r.time));
        }
    }
}

Measured memory_bytes: 73600
// abc053d: Card Eater
#include <stdio.h>
#include <stdlib.h>

#define upto(i,s,e,d) for(int i=(s);i<=(e);i+=(d))
#define downto(i,s,e,d) for(int i=(s);i>=(e);i-=(d))
#define in(n) scanf("%d",n)
#define out(d) printf("%d\n",d)

typedef struct {int a,c;} pair;
#define MAX 100000
pair d[MAX+1];

int desc(const void *a, const void *b) {
  int ret = ((pair*)b)->c - ((pair*)a)->c;
  if(ret>0) return 1;
  if(ret<0) return -1;
  return 0;
}

int main(){
  int n;in(&n);

  int dn=1, setnum = 0;
  upto(i,0,n-1,1){
    int a;in(&a);
    if(d[a].c==0) setnum++;
    if(dn<a)dn=a;
    d[a].a = a;
    d[a].c++;
  }

  qsort(d+1,dn,sizeof(pair),desc);

  upto(i,1,setnum,1){
    if(d[i].c>2){
      int t = (d[i].c-1)/2;
      n -= t*2;
      d[i].c -= t*2;
    }
    if(d[i].c==2){
      n-=2;
      if(i==setnum) d[i].c -= 2;
      else{
        d[i].c--;
        d[i+1].c--;
      }
    }
  }
  out(n);

  return 0;
}

Measured memory_bytes: 1404
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n); for(int i = 0;i < (int)(n);i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
int main(){
    int n;
    cin >> n;
    int ans = 1;
    int ansCnt = 0;
    for(int i = 1;i <= n;i++){
        int num = i;
        int cnt = 0;
        while(1){
            if(num%2 == 0){
                num /= 2;
                cnt += 1;
            }else break;
        }
        if(ansCnt < cnt){
            ansCnt = cnt;
            ans = i;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dump(...)
#endif
#define endl "\n"
#define ll long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define INF (1 << 30 - 1)
#define LLINF (1LL << 60)
#define vi vector<int>
#define vvi vector<vector<int>>
#define pi pair<int, int>
#define ALL(a) (a).begin(), (a).end()
#define BIT(n) (1LL << (n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてからつかうこと
constexpr ll MOD = 1e9 + 7;
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec)
        is >> x;
    return is;
}

bool match(char x, char y) {
    return (x == y || x == '?' || y == '?');
}

signed main() {
    string a, b, c;
    cin >> a >> b >> c;
    A = a.size();
    B = b.size();
    C = c.size();
    ans = A + B + C;
    vector<int> ab(100000);
    vector<int> bc(100000);
    vector<int> ca(100000);
    M = 50000;
    for (int i = -4000; i <= 4000; i++) {
        bool flag = 1;
        REP(j, B) {
            if (i + j < 0)
                continue;
            if (i + j >= A)
                break;
            if (match(b[j], a[i + j])) {
                continue;
            } else {
                flag = 0;
                break;
            }
        }
        if (flag) {
            ab[i + M] = 1;
        }
    }
    for (int i = -4000; i <= 4000; i++) {
        bool flag = 1;
        REP(j, C) {
            if (i + j < 0)
                continue;
            if (i + j >= B)
                break;
            if (match(c[j], b[i + j])) {
                continue;
            } else {
                flag = 0;
                break;
            }
        }
        if (flag) {
            bc[i + M] = 1;
        }
    }
    for (int i = -4000; i <= 4000; i++) {
        bool flag = 1;
        REP(j, A) {
            if (i + j < 0)
                continue;
            if (i + j >= C)
                break;
            if (match(a[j], c[i + j])) {
                continue;
            } else {
                flag = 0;
                break;
            }
        }
        if (flag) {
            ca[i + M] = 1;
        }
    }
    for (int i = -4000; i <= 4000; i++) {
        for (int j = -4000; j <= 4000; j++) {
            if (i == 1999 && j == 1999 * 2) {
                dump(ab[i - 0 + M], bc[j - i + M], ca[0 - j + M]);
            }
            if (ab[i - 0 + M] && bc[j - i + M] && ca[0 - j + M]) {
                ans = min(ans, max(A, max(i + B, j + C)) - min(0, min(i, j)));
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1408
// In the name of God

#include <iostream>
#include <algorithm>
#include <fstream>
#include <vector>
#include <deque>
#include <assert.h>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <stdio.h>
#include <string.h>
#include <utility>
#include <math.h>
#include <bitset>
#include <iomanip>

using namespace std;

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

const int N = 0, mod = 0;

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    string t;
    cin >> t;
    int n = 0, s = 0, e = 0, w = 0;
    for (int i = 0; i < (int) t.size(); ++i) {
        n |= (t[i] == 'N');
        s |= (t[i] == 'S');
        e |= (t[i] == 'E');
        w |= (t[i] == 'W');
    }
    if ((n ^ s) || (e ^ w)) {
        cout << "No";
    } else {
        cout << "Yes";
    }





}


Measured memory_bytes: 764
#include <bits/stdc++.h>
#define f first
#define s second
#define ll long long
#define mp make_pair
#define pb push_back
#define sqr(x) (x)*(x)

using namespace std;

const double eps = 1e-9;
const double PI = acos(-1.0);
const int INF = 1e9+7;
const int N = int (2e5+7);
    
int n, a[N], b[N], ans;

int main () { 
   	//freopen("input.txt", "r", stdin);
   	//freopen("output.txt", "w", stdout);  
   	ios_base::sync_with_stdio(0);
	cin.tie(0);

	cin >> n;
	for(int i = 0; i < n; i ++) {
		cin >> a[i];
		b[i] = a[i];
	}
	sort(b, b + n);
	for(int i = 0; i < n; i ++) {
		int pos = lower_bound(b, b + n, a[i]) - b;
		if(pos % 2 != i % 2)
			ans ++;
	}
	cout << ans / 2 << endl;
	return 0;
} 

Measured memory_bytes: 1024
import java.util.Scanner;
import java.util.stream.IntStream;

/**
 * 解説どおりに作成したソースコード
 */
public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			char[] s = scanner.next().toCharArray();
			int n = s.length;
			System.out.println(
					IntStream.range(1, n).filter(i -> s[i - 1] != s[i]).map(i -> Math.max(i, n - i)).min().orElse(n));
		}
	}
}


Measured memory_bytes: 29012
# -*- coding: utf-8 -*-

# AtCoder Beginner Contest
# Problem D

if __name__ == '__main__':
    from math import ceil

    n, h = list(map(int, input().split()))
    a = list()
    b = list()

    for i in range(n):
        ai, bi = map(int, input().split())
        a.append(ai)
        b.append(bi)

    a_max = max(a)
    bs = sorted([bi for bi in b if bi > a_max], reverse=True)
    remain_hp = h - sum(bs)

    # See:
    # https://img.atcoder.jp/abc085/editorial.pdf
    # https://beta.atcoder.jp/contests/abc085/submissions/1970488
    # https://docs.python.jp/3/library/math.html
    if remain_hp > 0:
        print(ceil(remain_hp / a_max) + len(bs))
    else:
        for index, bi in enumerate(bs):
            h -= bi

            if h <= 0:
                print(index + 1)
                break


Measured memory_bytes: 12936
#include <iostream>
#include <algorithm>
using namespace std;
const int maxn = 1e5 + 50;
int a[maxn];
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n,x;
	cin >> n >> x;
	for(int i = 1; i <= n; i++)
	{
		cin >> a[i];
	}
	long long ans = 0;
	for(int i = 2; i <= n; i++)
	{
		if(a[i] + a[i-1] > x)
		{
			if(a[i] + a[i-1] > x)
			{
				if(a[i-1] <= x)
				{
					ans += a[i] + a[i-1] - x;
					a[i] = x - a[i-1];
				}
				else
				{
					ans += a[i];
					a[i] = 0;
					ans += a[i-1] - x;
					a[i-1] = x;
				}
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define int long long
int a,b,q,s[100005],t[100005],x[100005];
signed main()
{
	cin>>a>>b>>q;
	for(int i=1;i<=a;i++)
		cin>>s[i];
	for(int i=1;i<=b;i++)
		cin>>t[i];
	for(int i=1;i<=q;i++)
	{
		cin>>x[i];
		int ls,lt,rs,rt;
		if(upper_bound(s+1,s+a+1,x[i])==s+a+1)
			ls=a;
		else if(upper_bound(s+1,s+a+1,x[i])==s+1)
			ls=0;
		else
			ls=upper_bound(s+1,s+a+1,x[i])-s-1;
		if(upper_bound(t+1,t+b+1,x[i])==t+b+1)
			lt=b;
		else if(upper_bound(t+1,t+b+1,x[i])==t+1)
			lt=0;
		else
			lt=upper_bound(t+1,t+b+1,x[i])-t-1;
		if(lower_bound(s+1,s+a+1,x[i])==s+a+1)
			rs=0;
		else
			rs=lower_bound(s+1,s+a+1,x[i])-s;
		if(lower_bound(t+1,t+b+1,x[i])==t+b+1)
			rt=0;
		else
			rt=lower_bound(t+1,t+b+1,x[i])-t;
		int ans=(int)(1e18)+5;
		if(ls)ls=abs(x[i]-s[ls]);
		if(lt)lt=abs(x[i]-t[lt]);
		if(rs)rs=abs(x[i]-s[rs]);
		if(rt)rt=abs(x[i]-t[rt]);
		if(ls&&lt)ans=min(ans,max(ls,lt));
		if(rs&&rt)ans=min(ans,max(rs,rt));
		if(ls&&rt)ans=min(ans,min(ls+ls+rt,rt+rt+ls));
		if(lt&&rs)ans=min(ans,min(lt+lt+rs,rs+rs+lt));
		cout<<ans<<endl;
	}
	return 0;
}


Measured memory_bytes: 3712
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<map>
#include<cstring>
#include<climits>
#include<queue>
using namespace std;
#define MAXC 30
#define MAXN 500
int n,c,ans;
int D[MAXC+5][MAXC+5],C[MAXN+5][MAXN+5];
int cont[4][MAXC+5];
int main()
{
    ans=INT_MAX;
    scanf("%d%d",&n,&c);
    for(int i=1;i<=c;i++)
        for(int j=1;j<=c;j++)
        scanf("%d",&D[i][j]);
    for(int i=1;i<=n;i++)
        for(int j=1;j<=n;j++)
        scanf("%d",&C[i][j]);
    for(int i=1;i<=n;i++)
        for(int j=1;j<=n;j++)
        cont[(i+j)%3][C[i][j]]++;
    for(int i=1;i<=c;i++)
        for(int j=1;j<=c;j++)
        if(i!=j)
            for(int k=1;k<=c;k++)
            if(k!=i&&k!=j)
            {
                int res=0;
                for(int p=1;p<=c;p++)res+=cont[0][p]*D[p][i];
                for(int p=1;p<=c;p++)res+=cont[1][p]*D[p][j];
                for(int p=1;p<=c;p++)res+=cont[2][p]*D[p][k];
                ans=min(ans,res);
            }
    printf("%d",ans);
}


Measured memory_bytes: 1280
#include <iostream>
#include <vector>

using namespace std;

long long g_count = 0;
const int MAX_N = 1000000;
vector<int> g;

void insertionSort(int *a, int n, int g) {
    for (int i = g; i < n; i++) {
        int v = a[i];
        int j = i - g;
        while (j >= 0 && a[j] > v) {
            a[j+g] = a[j];
            j = j - g;
            g_count++;
        }
        a[j + g] = v;
    }
}

int shellSort(int *a, int n) {

    for (int i = 1; ;) {
        if (i > n) {
            break;
        }
        g.push_back(i);
        i = 3 * i + 1;
    }

    for (int i = g.size() - 1; i >= 0; i--) {
        insertionSort(a, n, g[i]);
    }
    return g_count;
}

int main() {
    int n;
    int a[MAX_N];
    cin >> n;

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

    int count = shellSort(a, n);
    
    cout << g.size() << endl;
    for (int i = g.size() - 1; i >= 0; i--) {
        cout << g[i] << " ";
    }
    cout << endl;
    cout << count << endl;
    for (int i = 0; i < n; i++) {
        cout << a[i] << endl;
    }
}

Measured memory_bytes: 7008
local n, m = io.read("*n", "*n")
local min, max = 0, 9
if n == 2 then
  min, max = 10, 99
elseif n == 3 then
  min, max = 100, 999
end
local s, c = {}, {}
for i = 1, m do
  local x, y = io.read("*n", "*n")
  s[i], c[i] = x, tostring(y)
end
local f = false
for ic = min, max do
  local str = tostring(ic)
  f = true
  for i = 1, m do
    if n < s[i] or str:sub(s[i], s[i]) ~= c[i] then
      f = false
      break
    end
  end
  if f then print(ic) break end
end
if not f then print(-1) end


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int n,k,x,y,s;
    while(~scanf("%d %d %d %d",&n,&k,&x,&y))
    {
        if(n<=k)
        {
            s=x*n;
        }
        else
        {
            s=x*k+(n-k)*y;
        }
        printf("%d\n",s);
    }
    return 0;
}


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

using namespace std;

#define ll long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define pii pair<ll,ll>
#define vpii vector<pair<ll,ll> >
#define F first
#define S second
#define ld long double
#define built __builtin_popcountll
#define mst(a,i) memset(a,i,sizeof(a))
#define all(x) x.begin(),x.end()
#define itit(it,a) for(auto it=(a).begin(); it!=(a).end(); it++)
#define rep(i,a,b) for(ll i=a; i<b; i++)
#define repr(i,a,b) for(ll i=a; i>b; i--)
#define reprr(i,a,b) for(ll i=a; i>=b; i--)
#define pi 3.14159265358979323846264338327950288419716939937510582097494459230
ll max3(ll x,ll y,ll z) {return max(max(x,y),z);}
ll min3(ll x,ll y,ll z) {return min(min(x,y),z);}
const ll M=2e5+10,M2=1e6+10,mod=1e9+7,inf=1e17+10;
void add(int& a, int b) {a+=b;if(a>=mod){a-=mod;}}
#define trace1(x)			 	 cerr<<#x<<": "<<x<<endl
#define trace2(x, y)		 	 cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)		 	 cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)	 	 cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)	 cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
int X[] = {0, 1, 0, -1};
int Y[] = {-1, 0, 1, 0};
ll power(ll x,ll n){ll result=1;while(n>0){if(n%2==1)result=(result*x)%mod; x=((x%mod)*(x%mod))%mod;n=n/2;}return result;}

ll d[10];
ll f(ll x){
	while(x){
		ll y=x%10;
		if(d[y]) return false;
		x/=10;
	}
	return true;
}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll n,k;
	cin >> n >> k;
	rep(i,0,k){
		ll x;
		cin >> x;
		d[x]=1;
	}
	ll ans=n;
	while(true){
		if(f(ans)) break;
		else ans++;
	}
	cout << ans;
	return 0;
}
/* The judge is never wrong! Your code is buggy
   Look for:
 * * Read the problem carefully.
 * * Don't forget to sort(), mod, ll!!!!
 * * Initial value = +/- infinity instead of zero!!!
 * * an easier and alternate approach
 * * read the problem statement carefully
 * * if concept is correct and still WA, try with a different implementation
 * * special cases (n=1?)
 * * if you have no idea just guess the appropriate well-known algorithm instead of doing nothing :/
 */


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int inf=0x3f3f3f3f;
const int MOD=1e9+7;
const int maxn=1e5+10;
ll gcd(ll a, ll b){return (b==0)?a:gcd(b, a%b);}
bool isPrime(ll n){
    if(n<=3){
        return n>1;
    }
    if(n%6!=1&&n%6!=5){
        return false;
    }
    ll sqr=sqrt(n);
    for(ll i=5;i<=sqr;i+=6){
        if(n%i==0||n%(i+2)==0){
            return false;
        }
    }
    return true;
}
int dis[4][2]={0,1,0,-1,1,0,-1,0};
int read(){
    int x=0,f=1;char c=getchar();
    while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
    while (c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
    return x*f;
}


int main()
{
	int n;cin>>n;
	float pi=3.1415926535898;
	printf("%lf\n",pi*2*n);
}
 

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

using namespace std;

#define INF 1000000007
#define int long long
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) FOR(i, 0, n)
#define maxn 100005

signed main()
{
    int N;
    cin >> N;
    int B[N];
    for (int i = 0; i < N - 1; i++)
    {
        cin >> B[i];
    }
    int ans = B[0];
    for (int i = 0; i < N - 2; i++)
    {
        ans += min(B[i], B[i + 1]);
    }
    ans += B[N - 2];
    cout << ans << endl;
}

Measured memory_bytes: 256
import sys
import itertools
import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
 
N, M, Q = map(int, readline().split())
 
A = np.array(list(itertools.combinations_with_replacement(range(1, M + 1), N)))
 
n = len(A)
score = np.zeros(n, np.int32)
# m = map(int, read().split())

for i in range(Q):
	a, b, c, d = map(int, readline().split())
	cond = A[:, b - 1] - A[:, a - 1] == c
	score += d * cond
 
print(score.max())

Measured memory_bytes: 46820
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
a = 0
b = 0
for i in range(N):
    if A[i] > B[i]:
        a += A[i] - B[i]
    else:
        b += (B[i] - A[i])//2

print("Yes") if a <= b else print("No")

Measured memory_bytes: 4596
#include <algorithm>
#include <array>
#include <cmath>
#include <functional>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>
#include <bitset>

#define pv(val) cerr << #val << '=' << (val) << endl
#define pvn(name, val) cerr << name << '=' << (val) << endl
#define pl cerr << '@' << __LINE__ << endl

using namespace std;

using ll = int64_t;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()

template <class T>
ostream &operator<<(ostream &os, vector<T> const &vec) {
    if (vec.empty()) {
        os << "{}";
    } else {
        os << '{';
        for (size_t i = 0; i < vec.size() - 1; i++) os << vec[i] << ", ";
        os << vec.back() << '}';
    }
    return os;
}

template <class T, size_t S>
ostream &operator<<(ostream &os, array<T, S> const &arr) {
    if (arr.empty()) {
        os << "{}";
    } else {
        os << '{';
        for (size_t i = 0; i < arr.size() - 1; i++) os << arr[i] << ", ";
        os << arr.back() << '}';
    }
    return os;
}

template <class T, class U>
ostream &operator<<(ostream &os, pair<T, U> const &p) {
    os << '(' << p.first << ", " << p.second << ')';
    return os;
}

namespace math {
ll gcd(ll u, ll v) {
    while (v != 0) {
        ll r = u % v;
        u = v;
        v = r;
    }
    return u;
}
ll lcm(ll m, ll n) {
    if ((0 == m) || (0 == n)) return 0;

    return ((m / math::gcd(m, n)) * n);
}
}  // namespace math

struct UnionFind {
    vector<ll> data;
    UnionFind(ll size) : data(size, -1) {}
    bool unionSet(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x != y) {
            if (data[y] < data[x]) swap(x, y);
            data[x] += data[y];
            data[y] = x;
        }
        return x != y;
    }
    bool findSet(ll x, ll y) { return root(x) == root(y); }
    ll root(ll x) { return data[x] < 0 ? x : data[x] = root(data[x]); }
    ll size(ll x) { return -data[root(x)]; }
};

template <class T, class U>
pair<T, U> operator+(pair<T, U> const &a, pair<T, U> const &b) {
    return pair<T, U>(a.first + b.first, a.second + b.second);
}

template <class T, class U>
pair<T, U> operator-(pair<T, U> const &a, pair<T, U> const &b) {
    return pair<T, U>(a.first - b.first, a.second - b.second);
}

ll bound(function<bool(ll)> f, ll ng, ll ok) {
    while (abs(ng - ok) > 1) {
        ll mid = (ng + ok) / 2;
        if (f(mid))
            ok = mid;
        else
            ng = mid;
    }

    return ok;
}

int main(void) {
    string S;
    cin >> S;

    int s1, s2;
    s1 = s2 = 0;
    for(int i = 0; i < S.size(); i++){
        if(i % 2 == 0 && S[i] == '1')
            s1++;
        if(i % 2 == 1 && S[i] == '0')
            s1++;

        if(i % 2 == 0 && S[i] == '0')
            s2++;
        if(i % 2 == 1 && S[i] == '1')
            s2++;
    }

    cout << min(s1, s2) << endl;

    return 0;
}

Measured memory_bytes: 512
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <stack>
#include <string>
#include <ctime>
#include <iomanip>
#include <set>
#include <iterator>
#include <map>
using namespace std;

#define pb push_back

#define forn(i, n) for(int i = 0; i < (int)(n); i++)
#define for1(i, n) for(int i = 1; i <= (int)(n); i++)

using ll = long long;

typedef vector<int> vi;

const int INF = 1e9 + 5;

void max_self(ll& a, ll b)
{
	a = max(a, b);
}

int main()
{
	int n, W;
	cin >> n >> W;
	vector<ll> dp(W + 1);
	for (int item = 0; item < n; item++)
	{
		int w, v;
		cin >> w >> v;
		for (int w_al = W - w; w_al >= 0; w_al--)
		{
			max_self(dp[w_al + w], dp[w_al] + v);
		}
	}
	ll ans = 0;
	for (int i = 0; i <= W; i++)
		max_self(ans, dp[i]);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main(void){
  int n,h[100010],i,s=0;
  cin >> n;
  for (i=0;i<n;i++) cin >> h[i];
  for (i=n-2;i>=0;i--) if (h[i]>h[i+1]) h[i]--;
  for (i=0;i<n-1;i++) if (h[i]>h[i+1]) break;
  if (i==n-1) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

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

using namespace std;

#define ALL(x) x.begin(), x.end()
#define RALL(x) x.rbegin(), x.rend()

typedef long long int lld;
typedef pair<int, int> pii;
typedef pair<lld, lld> pll;

int main() {
#ifndef LOCAL
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
#endif

    int a, b;
    cin >> a >> b;
    if (max(a, b) >= 10)
        cout << -1 << '\n';
    else
        cout << a * b << '\n';

    // system("pause");
    return 0;
}

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

int main() {
	int N;
	cin >> N;
	vector<int> v(N);
	rep(i, N) {
		cin >> v.at(i);
	}

	int a=0, b=0, c=0, x, y, z;
	rep(i, N) {
		for (int j=i+1; j<N; j++) {
			for (int k=j+1; k<N; k++) {
				if (v.at(i) == v.at(j)) continue;
				if (v.at(i) == v.at(k)) continue;
				if (v.at(j) == v.at(k)) continue;
				x = max(max(v.at(i), v.at(j)), v.at(k));
				y = v.at(i) + v.at(j) + v.at(k) - x;
				if (y>x) a++;
			}
		}
	}
	std::cout << a << '\n';
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define ALL(A) (A).begin(), (A).end()
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }

const ll mod = 1e9 + 7;
const ll INF = -1 * ((1LL << 63) + 1);
const int inf = -1 * ((1 << 31) + 1);

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    int n;
    cin >> n;
    string s;
    cin >> s;
    
    // 4通り考える
    for(int bit=0;bit<4;bit++){
        vector<int> ans(n,0);
        for(int i=0;i<2;i++){
            if((bit>>i)&1){
                ans[i] = 1;
            }else ans[i] = 0;
        }
        for(int i=1;i<n-1;i++){
            if(s[i]=='o'){
                if(ans[i]==0){
                    ans[(i+1)%n] = ans[(i-1+n)%n];
                }else{
                    ans[(i+1)%n] = (ans[(i-1+n)%n]+1)%2;
                }
            }else{
                if(ans[i]==0){
                    ans[(i+1)%n] = (ans[(i-1+n)%n]+1)%2;
                }else ans[(i+1)%n] = ans[(i-1+n)%n];
            }
        }
        bool ok = 0;
        if(s[n-1]=='o'){
            if(ans[n-1]==0 && ans[0] == ans[n-2]){
                ok = 1;
            }else if(ans[n-1]==1 && ans[0]!= ans[n-2]){
                ok = 1;
            }
        }else{
            if(ans[n-1]==0 && ans[0] != ans[n-2]){
                ok = 1;
            }else if(ans[n-1] == 1 && ans[0]== ans[n-2]){
                ok = 1;
            }
        }
        bool ok2 = 0;
        if(ok){
            if(s[0]=='o'){
                if(ans[0]==0 && ans[1] == ans[n-1]){
                    ok2 = 1;
                }else if(ans[0] == 1 && ans[1] != ans[n-1]){
                    ok2 = 1;
                }
            }else {
                if(ans[0]==0 && ans[1] != ans[n-1]){
                    ok2 = 1;
                }else if(ans[0] == 1 && ans[1] == ans[n-1]){
                    ok2 = 1;
                }
            }
        }
        if(ok2){
            rep(i,n)cout << (ans[i]==0?"S":"W");
            cout << endl;
            return 0;
        }
    }
    cout << -1 << endl;
}


Measured memory_bytes: 924
#include <algorithm>
#include <bitset>
#include <complex>
#include <cstdio>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

using namespace std;

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

typedef long long ll;

const int Inf = 100100100;
const double EPS = 1e-9;

int gcd(int x, int y) {
  if (x < y)  swap(x, y);
  if (y == 0) return x;
  return gcd(x % y, y);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> a(n), l(n), r(n);
    rep(i, n) cin >> a[i];
    rep(i, n - 1) l[i + 1] = gcd(l[i], a[i]);
    for (int i = n - 1; i >= 1; --i) {
      r[i - 1] = gcd(r[i], a[i]);
    }
    int ans = 1;
    rep(i, n) ans = max(ans, gcd(l[i], r[i]));
    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 1408
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <iomanip>
#include <limits.h>
#include <string.h>
using namespace std;

typedef vector<int> vi;
typedef pair<int, int> pi;
typedef vector<pi> vii;

typedef long long int lld;

#define F first
#define S second

#define ERR 1e-9
#define MAXN 100010

#ifndef ONLINE_JUDGE
    #define var(x) cerr << #x << ": " << x;
#else
    #define var(x)
#endif // ONLINE_JUDGE

void aggMax(int & res, int x){ if(x > res)res = x; }
void aggMin(int & res, int x){ if(x < res)res = x; }

int II(){ int i; cin >> i; return i; }
void OI(int i){ cout << i; }

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

    int N = II();
    if(N == 1){ cout << "Hello World"; }
    else{
        int A = II(), B = II();
        cout << A+B;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef map<int, int> mi;
typedef set<int> si;
#define VV(T) vector<vector< T > >
#define dump(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl

#define rep(i, n) REP(i, 0, n)                              // 0, 1, ..., n-1
#define REP(i, x, n) for(int i = x; i < n; i++)             // x, x + 1, ..., n-1
#define invrep(i, n) for(int i = (n)-1; i >= 0; i--)        // n-1, n-2, ..., 0
#define invREP(i, x, n) for(int i = (n)-1; i >= (x; i--)    // n-1, n-2, ..., x
#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(v) (v).begin() , (v).end()
#define RALL(v) (v).rbegin(), (v).rend()

#define PB push_back

#define COUT(x) cout << (x) << endl
#define VECCIN(x) for(auto&youso_: (x) )cin>>youso_
#define VECCOUT(x) for(auto&youso_: (x) )cout<<youso_<<" ";cout<<endl

string s, t;
int S, T;

bool match(int k){
    rep(i, T){
        if(t[i] != s[i + k] && s[i + k] != '?') return false;
    }
    return true;
}

int main(){
    cin >> s >> t;
    S = s.size(); T = t.size();
    int k = -1;
    rep(i, S - T + 1){
        if(match(i)) k = i;
    }
    if(k == -1){
        COUT("UNRESTORABLE");
        return 0;
    }
    string ans = s;
    rep(i, T)ans[i + k] = t[i];
    rep(i, S) if(ans[i] == '?') ans[i] = 'a';
    COUT(ans);
}

Measured memory_bytes: 256