akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <limits.h>
#include <queue>
using namespace std;

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

string chang(int i){
    string ans=to_string(i);
    if(ans.size()==1){
        ans="00000"+ans;
    }
    else if(ans.size()==2){
        ans="0000"+ans;
    }
    else if(ans.size()==3){
        ans="000"+ans;
    }
    else if(ans.size()==4){
        ans="00"+ans;
    }
    else if(ans.size()==5){
        ans=="0"+ans;
    }
    return ans;
}

int main(){
    int n,m;
    cin >> n >> m;
    vector<pair<int,pair<int,int>>> da(m);
    vector<int> p(m),y(m);
    for rip(i,m){
        cin >> da[i].first >> da[i].second.first;
        da[i].second.second=i;
    }
    sort(da.begin(),da.end());
    vector<pair<int,int>> ans(m);
    int co=1;
    ans[da[0].second.second]=make_pair(da[0].first,1);
    for (int i=1;i<m;i++){
        if(da[i].first==da[i-1].first){
            co++;
        }
        else{
            co=1;
        }
        ans[da[i].second.second]=make_pair(da[i].first,co);
    }
    for rip(i,m){
        printf("%06d%06d\n",ans[i].first,ans[i].second);
    }
}

Measured memory_bytes: 4224
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
#define INF2 2000000
const long long MOD = 1000000007;
using namespace std;

char str[200][205];

int main(int argc, char* argv[])
{
    int n;
    scanf("%d", &n);

    int d[200][200]={0};
    int i,j;
    for(i=0; i<n; i++) {
        for(j=0; j<n; j++) {
            d[i][j]=(i==j? 0: INF2);
        }
    }

    for(i=0; i<n; i++) {
        scanf("%s", str[i]);
        for(j=0; j<n; j++) {
            if(str[i][j]=='1') {
                d[i][j]=1;
            }
        }
    }

    //ワーシャルフロイド
    for(int k = 0; k < n; ++k)
        for(int i = 0; i < n; ++i)
            for(int j = 0; j < n; ++j) d[i][j] = min(d[i][j], d[i][k] + d[k][j]);

    vector<int> flag(n);
    for(i=1; i<n; i++) {
        if(d[0][i]%2) flag[i]=1;
    }

    int max=0;
    for(i=0; i<n; i++) {
        for(j=0; j<n; j++) {
            if((flag[i]+flag[j]+d[i][j])%2) {
                printf("-1\n");
                return 0;
            }
            max=MAX(max, d[i][j]);
        }
    }
    printf("%d\n", max+1);

    return 0;
}






Measured memory_bytes: 512
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define REPD(i,a,b) for (int i=(a);i<=(b);i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef set<int> si;
typedef vector<si> vsi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<int, int> pi;
typedef queue<int> qi;
typedef queue<pi> qpi;
typedef pair<ll, ll> pll;
typedef queue<pll> qpll;
typedef vector<pi> vpi;
typedef vector<pll> vpll;
const int mod = 1000000007;
const int INF = 1001001001;
// 小数点　<< fixed << setprecision(0) <<
// sort降順　sort(ALL(),greater<int>());
// 円周率　M_PI
// 文字判定　isupper islower
// 文字変換　
// 順列　do {} while(next_permutation(ALL(X)));
// 最大値　LLONG_MAX
// a内でx以上　auto iter = lower_bound(ALL(a), x);
// a内でxより大きい　auto iter = upper_bound(ALL(a), x);
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
struct edge {
    int from; //出発点
    int to;   //到達点
    int cost; //移動コスト
};
typedef struct edge se;
typedef vector<edge> ve;
unsigned Euclidean_gcd(unsigned a, unsigned b) {
  if(a < b) return Euclidean_gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

vpll PrimeFactorization(ll n) {
  vpll res;
  for (ll i=2; i*i<=n; i++) {
    if(n%i!=0) continue;
    ll ex=0;
    while(n%i==0) {
      ex++;
      n/=i;
    }
    res.push_back(pll(i,ex));
  }
  if(n!=1) res.push_back(pll(n,1));
  return res;
}

int main() {
  char s[200001],t[200001];
  cin >> s >> t;
  int n=strlen(s);
  int ans=0;
  REP(i,n) {
    if(s[i]!=t[i]) ans++;
  }
  cout<<ans<<endl;
  return 0;
}


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

using namespace std;

typedef long long int li;
typedef long double ld;
typedef vector<li> vi;
typedef pair<li,li> pi;
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define B begin()
#define E end()
#define f(i,l,r) for(li i=l;i<=r;++i)
#define fr(i,l,r) for(li i=l;i>=r;--i)
#define u_map unordered_map
#define endl "\n"

li fastpow(li base,li exp,li M) 
{
    li res=1;
    while(exp>0) {
        if(exp&1)
            res=(res*base)%M;

        base=(base*base)%M;
        exp>>=1;
    }
    return res;
}

int main()
{    
    

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    li n,k;

    cin>>n>>k;

    cout<<min(n%k,k-n%k);

    return 0;
}

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

int main() {
  int i, j, k, n;
  long long sum = 0;
  cin >> n;
  for (i = 1; i <= n; i++){
    for (j = 1; j <= n; j++){
      for (k = 1; k <= n; k++){
        sum += gcd(i, gcd(j, k));
      }
    }
  }
  cout << sum << endl;
  return 0;
}

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

int partition(vector<int> &A, int p, int r) {
    int x = A.at(r);
    int i = p - 1;
    for (int j = p; j < r; j++) {
        if (A.at(j) <= x) {
            i = i + 1;
            swap(A.at(i), A.at(j));
        }
    }
    swap(A.at(i+1), A.at(r));
    return i + 1;
}

int main() {
    int n;
    cin >> n;
    vector<int> A(n);
    for (int i = 0; i < n; i++) {
        cin >> A.at(i);
    }
    int q = partition(A, 0, n-1);
    for (int i = 0; i < n; i++) {
        if (i) cout << " ";
        if (i == q) cout << "[";
        cout << A.at(i);
        if (i == q) cout << "]";
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 3116
#include<bits/stdc++.h>
using namespace std;
struct C{
  long x;
  long id;
  C(long x_,long id_):x(x_),id(id_){}
  C(){}
};
bool cmp(C c1,C c2){
  if(c1.x==c2.x)return c1.id<c2.id;
  return c1.x<c2.x;
}

class BIT{
  long n;
  vector<long>B;
  public:
  void add(long i,long x){  
    while(i<=n&&i!=0){B[i]+=x;i+=(i&-i);}
  }
  long sum(long i){
    if(i==0)return 0;
    long ans=0;
    while(i>0){ans+=B[i];i-=(i&-i);}return ans;
  }
  BIT(long N):n(N){
    long t=1;while(t<=n)t*=2;
    for(long i=0;i<=t;i++)B.push_back(0);
  }
};

int main(){
  long N;cin>>N;long ans=-1;
  vector<long>A(N),B(N);
  for(long i=0;i<N;i++)cin>>A[i];
  for(long i=0;i<N;i++)cin>>B[i];
  for(long bit=0;bit<(1<<N);bit++){
    bitset<18>b(bit);
    if(b.count()%2!=0)continue;
    vector<C>even;
    vector<C>odd;
    for(long i=0;i<N;i++){//1なら裏
      if((i+b.test(i))%2)odd.push_back(C((b.test(i)?B[i]:A[i]),i));
      else even.push_back(C((b.test(i)?B[i]:A[i]),i));
    }
    if(even.size()-odd.size()!=N%2)continue;
    sort(even.begin(),even.end(),cmp);
    sort(odd.begin(),odd.end(),cmp);
    vector<C>X(N);
    for(long i=0;i<N;i++)
      X[i]=(i%2==0?even[i/2]:odd[i/2]);
    bool ok=1;
    for(long i=0;i<N-1;i++)if(X[i].x>X[i+1].x)ok=0;
    if(!ok)continue;
    
    
    //コストの計算:BITで転倒数
    
    BIT t(N);
    long s=0;
    for(int i=0;i<N;i++){
      s+=i-t.sum(X[i].id+1);
      t.add(X[i].id+1,1);
    }
    
    
    ans=(ans==-1?s:min(ans,s)); 
    
  }
  cout<<ans<<endl;
}

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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef long long ll;

const int MOD = 1000000007;

int main() {
    int r;
    cin >> r;
    cout << r * r << endl;
}

Measured memory_bytes: 256
def solve():
    S = input()
    N = len(S)
    # print(S, N)

    # 最大回数のパーを数える
    n = (N - 1)
    p = (n + 2 - 1) // 2

    return p - S.count("p")


if __name__ == '__main__':
    res = solve()
    print(res)


Measured memory_bytes: 39152
import java.util.*;
class Main { 
	public static void main(String...args){
		Scanner scan = new Scanner(System.in);
		String str = scan.nextLine();
		String uStr = str.toUpperCase();
		String[] chars = str.split("");
		String[] uChars = uStr.split("");
		StringBuilder sb = new StringBuilder();

		for(int i = 0; i < chars.length; i++){
			if(chars[i].equals(uChars[i])) {
				sb.append(chars[i].toLowerCase());
			} else {
				sb.append(chars[i].toUpperCase());
			}
		}
		System.out.println(sb.toString());
	}
}


Measured memory_bytes: 27196
#include <bits/stdc++.h>   
#define rep(i, n) for(long long int i = 0; i < n; i++)
#define _rep(i, m, n) for(long long int i = m; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll mod = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
     
ll gcd(ll A, ll B){
    if(B == 0)return A;
    return gcd(B, A % B);
}
ll lcm(ll A, ll B){
    return A * B / gcd(A, B);
}
using Graph = vector<vector<int>>;
Graph G;

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

    ll n; cin >> n;
    ll a; cin >> a;
    vector<ll> x(n);
    rep(i, n) cin >> x[i];
    ll dp[n + 2][n + 2][n * 50 + 2];
    rep(i, n + 2)rep(j, n + 2)rep(k, n * 50 + 2) dp[i][j][k] = 0;
    rep(i, n) dp[i + 1][1][x[i]]++;

    rep(i, n)rep(j, n)rep(k, n * 50 + 1){
        dp[i + 1][j + 1][k + x[i]] += dp[i][j][k];
        dp[i + 1][j][k] += dp[i][j][k];
    }
    ll ans = 0;
    _rep(j, 1, n + 1)rep(k, n * 50 + 1) if(k % j == 0 and k / j == a) ans += dp[n][j][k];
    cout << ans << endl;
}

Measured memory_bytes: 56512
#include <bits/stdc++.h>
using namespace std;
int main(){
   int a,sum = 0;
   cin >> a;
   //cout << a << endl;
   if(a >= 100){
      a -= 100;
      sum++;
   }
   //cout << sum << endl;
   //cout << a << endl;
   if(a >= 10){
      a -= 10;
      sum++;
   }
   //cout << sum << endl;
   //cout << a << endl;
   cout << a + sum << endl;
}

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

using namespace std;

int main() {
    ios::sync_with_stdio(0);

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

    vector<int> as(A), bs(B);
    for(int i = 0; i < A; ++i) {
        cin >> as[i];
    }
    for(int i = 0; i < B; ++i) {
        cin >> bs[i];
    }

    int ans = 0;
    for(int start = 0; start < B; ++start) {
        int aidx = 0;
        for(int end = start; end < B; ++end) {
            while(aidx < A && as[aidx] != bs[end]) ++aidx;
            if(aidx == A) break;
            ans = max(ans, end-start+1);
            ++aidx;
        }
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 916
#![allow(non_snake_case, unused_imports)]

// Input
macro_rules! input { (source = $s:expr, $($r:tt)*) => { let mut iter = $s.split_whitespace(); let mut next = || { iter.next().unwrap() }; input_inner!{next, $($r)*} }; ($($r:tt)*) => { let stdin = std::io::stdin(); let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock())); let mut next = move || -> String{ bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect() }; input_inner!{next, $($r)*} }; }
macro_rules! input_inner { ($next:expr) => {}; ($next:expr, ) => {}; ($next:expr, $var:ident : $t:tt $($r:tt)*) => { let $var = read_value!($next, $t); input_inner!{$next $($r)*} };}
macro_rules! read_value { ($next:expr, ( $($t:tt),* )) => { ( $(read_value!($next, $t)),* ) }; ($next:expr, [ $t:tt ; $len:expr ]) => { (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>() }; ($next:expr, chars) => { read_value!($next, String).chars().collect::<Vec<char>>() }; ($next:expr, bytes) => { read_value!($next, String).into_bytes() }; ($next:expr, usize1) => { read_value!($next, usize) - 1 }; ($next:expr, $t:ty) => { $next().parse::<$t>().expect("Parse error") }; }

// Module
use std::cmp::{min,max};
use std::collections::{HashSet,HashMap,BTreeMap,VecDeque};

// Functions

// Main
fn main(){
    input!{
        A: String,
        B: String,
    }
    let mut Ans = "EQUAL";
    if A.len() > B.len(){
        Ans = "GREATER";
    }else if A.len() < B.len(){
        Ans = "LESS";
    }else{
        let aa:Vec<char> = A.chars().collect();
        let bb:Vec<char> = B.chars().collect();
        let len = A.len();
        for i in 0..len{
            if aa[i] > bb[i]{
                Ans = "GREATER";
                break;
            }else if aa[i] < bb[i]{
                Ans = "LESS";
                break;
            }
        }
    }
    println!("{}",Ans);
}

Measured memory_bytes: 4352
package main

import (
	"fmt"
	"math"
	"strconv"
)

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

	min := math.MaxInt8
	for i := 1; i*i <= n; i++ {
		if n%i != 0 {
			continue
		}

		a := f(i, n/i)
		if a < min {
			min = a
		}
	}

	fmt.Println(min)
}

func f(a, b int) int {
	return max(digits(a), digits(b))
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func digits(n int) int {
	s := strconv.Itoa(n)
	return len(s)
}


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

int main() {
	string run;
	while (cin >> run ) {
		int i = 0;
		while (i < run.size()) {
			if (run[i] == '@') {
				run[i + 1] -= '0';
				for (int j = 0; j < run[i + 1]; j++) {
					cout << run[i + 2];
				}
				i += 3;
			}
			else {
				cout << run[i];
				i += 1;
			}
		}
		cout << endl;
	}
}


Measured memory_bytes: 3068
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp(a, b) make_pair(a, b)
#define ls (rt << 1)
#define rs (rt << 1 | 1) 
typedef pair<int, int> pii; 
const ll mod = 1e9 + 7;
template <class T> T lowbit(T x){return ((x)&(-(x)));}
const int maxn = 2e5 + 10;
ll n; 
int main()
{
	cin >> n;
	ll ans = n / 500 * 1000;
	n %= 500;
	ans += n / 5 * 5;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
from fractions import gcd


def lcm(a, b):
    return a * b // gcd(a, b)


N = int(input())
A = list(map(int, input().split()))

cumlcm = A[0]
for a in A[1:]:
    cumlcm = lcm(cumlcm, a)
m = cumlcm - 1
f = sum(map(lambda a: m % a, A))
print(f)


Measured memory_bytes: 5588
def partition(A, p, r):
    x = A[r - 1]
    i = p - 1
    for j in range(p, r-1):
        if A[j] <= x:
            i += 1
            temp = A[i]
            A[i] = A[j]
            A[j] = temp
    temp = A[i+1]
    A[i+1] = A[r-1]
    A[r-1] = temp
    return i




if __name__ == '__main__':
    # ??????????????\???
    # A = [13, 19, 9, 5, 12, 8, 7, 4, 21, 2, 6, 11]
    num_of_data = int(input())
    A = [int(x) for x in input().split(' ')]

    # ???????????????
    p = partition(A, 0, len(A))

    # ???????????¨???
    left = A[:p+1]
    partition = A[p+1]
    right = A[p+2:]
    print('{0} [{1}] {2}'.format(' '.join(map(str, left)), partition, ' '.join(map(str, right))))

Measured memory_bytes: 18336
import std.algorithm;
import std.array;
import std.container;
import std.conv;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void scan(T...)(ref T a) {
    string[] ss = readln.split;
    foreach (i, t; T) a[i] = ss[i].to!t;
}
T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

const MOD = 10^^9 + 7;

long calc(long k, int[] a) {
    // a 内での転倒数
    long p = 0;
    for (int i = 0; i < a.length; i++) {
        for (int j = i + 1; j < a.length; j++) {
            if (a[i] > a[j]) p++;
        }
    }
    long ans1 = (p * k) % MOD;

    // 二つの a に対する転倒数
    long q = 0;
    for (int i = 0; i < a.length; i++) {
        for (int j = 0; j < a.length; j++) {
            if (a[i] > a[j]) q++;
        }
    }
    long ans2 = q * (((k * (k - 1)) / 2) % MOD); // q * kC2
    ans2 %= MOD;
    return (ans1 + ans2) % MOD;
}

void main() {
    int n, k; scan(n, k);
    auto a = readints;
    writeln(calc(k, a));
}


Measured memory_bytes: 380
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
#include <math.h>
#include <string>
#include <sstream>
#include <stack>
#include <deque>
#define pb push_back
#define make make_pair
#define kaku(a) cout << a << endl
#define isort(a) sort(a.begin(),a.end())

using namespace std;

#define ll long long
#define rep(i,n) for(ll i=0;i<n;i++)
#define PI 3.14159265359
long long gcd(long long a,long long b){ return b==0?a:gcd(b,a%b);}
long long lcm(long long a,long long b){ return a/gcd(a,b)*b;}

typedef pair<ll,ll> Pair;
typedef vector<ll> vecll;
const ll inf =1000000007;

void asolve(){
    string s,t;
    cin >> s >>t;
    bool can=true;

    for(ll i=0;i<s.size();i++){
        if(s[i]!=t[i]) can=false;
    }

    if(can) cout <<"Yes" << endl;
    else cout <<"No" << endl;


}

void bsolve(){

    ll a,b,c,k;
    cin >> a>> b>> c>>k;

    if(k<=a){
        kaku(k);
    }
    else if(k<=(a+b)){
        kaku(a);
    }
    else if (k<=a+b+c){
        kaku(a+a+b-k);
    }
    else {
        kaku(a-c);
    }

}

void csolve(){

    ll n,m,x;
    cin >> n >> m >>x;
    ll c[n];
    ll a[n][m];
    rep(i,n){
        cin >> c[i];
        rep(j,m){
            cin >> a[i][j];
        }
    }
    ll ri[m];
    ll ans=-1;
    for(ll bit=0;bit<(1LL<<n);bit++){
        rep(i,m) ri[i]=0;
        ll score=0;
        ll can=true;
        rep(i,n){
            if(bit & (1LL<<i)){
                score+=c[i];
                rep(j,m){
                    ri[j]+=a[i][j];
                }
            }
        }
        rep(i,m){
            if(x>ri[i]) can=false;
        }
        if(can){
            if(ans==-1) ans=score;
            else ans=min(ans,score);
        }
    }
    kaku(ans);
}

void dsolve(){

    ll n,k;
    cin >> n>> k;
    map<ll,ll> mp;
    rep(i,n){
        ll a;
        cin >>a;
        mp[i+1]=a;
    }
    ll now=1;

    vecll vec;//いった集合
    vec.pb(1);
    bool visit[n+1];
    rep(i,n+1) visit[i]=false;
    visit[1]=true;
    map<ll,ll> iku;//そこを訪れたのはなん回目か
    iku[1]=0;
    ll loop;
    bool d=false;

    for(ll i=1;i<=k;i++){
        now=mp[now];
        if(visit[now]){
            d=true;
            loop=i;
            break;
        }
        else{
            vec.pb(now);
            iku[now]=i;
            visit[now]=true;
        }
    }
    //loop~iku[now]でループ検出

    //ループ処理
    if(d){
        ll e=loop-iku[now];
        ll u=(k-iku[now])%e;

        now=vec[iku[now]+u];

        cout << now << endl;
    }
    else{
        cout << now << endl;
    }

}


int main(){
    bsolve();
}

Measured memory_bytes: 3640
package main

import "fmt"

func main() {
	// Code for A - HonestOrDishonest
	var a, b string
	fmt.Scanf("%s %s", &a, &b)

	if (a[0] == 'H' && b[0] == 'H') || (a[0] == 'D' && b[0] == 'D') {
		fmt.Println("H")
	} else {
		fmt.Println("D")
	}

}


Measured memory_bytes: 1832
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::{Write, BufWriter};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, [ $t:tt ]) => {{
        let len = read_value!($next, usize);
        (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    }};

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }
    input! {
        n: usize,
        wsv: [(usize, usize, i64); n],
    }
    let mut wsv = wsv;
    wsv.sort_by_key(|&(w, s, v)| (s + w, w, v));
    wsv.reverse();
    const INF: i64 = 1 << 50;
    const W: usize = 10010;
    let mut dp = vec![vec![-INF; W]; n + 1];
    for i in 0 .. n {
        let (w, s, v) = wsv[i];
        // initiate
        dp[i + 1][s] = v;
        for j in w .. W {
            dp[i + 1][min(j - w, s)] = max(dp[i + 1][min(j - w, s)], dp[i][j] + v);
        }
        for j in 0 .. W {
            dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
        }
        // eprintln!("{:?}", &dp[i + 1][0 .. 10]);
    }
    puts!("{}\n", dp[n].iter().max().unwrap());
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


Measured memory_bytes: 96508
def az13():
    while True:
        xs = raw_input().split()
        H,W = int(xs[0]),int(xs[1]) 
        if H==0 and W==0 : break
        for i in range(0,H):
            if i == 0 or i == H-1 :
                print "#"*W
            else :
                print "#" + "."*(W-2) + "#"
        print

az13()

Measured memory_bytes: 4212
#include"bits/stdc++.h"


#define PB push_back
#define PF push_front
#define LB lower_bound
#define UB upper_bound
#define fr(x) freopen(x,"r",stdin)
#define fw(x) freopen(x,"w",stdout)
#define iout(x) printf("%d\n",x)
#define lout(x) printf("%lld\n",x)
#define REP(x,l,u) for(int x = (l);x<=(u);x++)
#define RREP(x,l,u) for(int x = (l);x>=(u);x--)
#define mst(x,a) memset(x,a,sizeof(x))
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define MP make_pair
#define se second
#define fi first
#define dbg(x) cout<<#x<<" = "<<(x)<<endl;
#define sz(x) ((int)x.size())
#define cl(x) x.clear()

typedef  long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
using namespace std;

const int maxn = 200010;
const int mod = 1e9+7,bas = 2500;
const int MAX = 1000000010;
const double eps = 1e-6;
const double PI = acos(-1);

template<typename T> inline void read(T &x){
x=0;T f=1;char ch;do{ch=getchar();if(ch=='-')f=-1;}while(ch<'0'||ch>'9');do x=x*10+ch-'0',ch=getchar();while(ch<='9'&&ch>='0');x*=f;
}

template<typename A,typename B> inline void read(A&x,B&y){read(x);read(y);}
template<typename A,typename B,typename C> inline void read(A&x,B&y,C&z){read(x);read(y);read(z);}
template<typename A,typename B,typename C,typename D> inline void read(A&x,B&y,C&z,D&w){read(x);read(y);read(z);read(w);}
template<typename A,typename B> inline A fexp(A x,B p){A ans=1;for(;p;p>>=1,x=1LL*x*x%mod)if(p&1)ans=1LL*ans*x%mod;return ans;}
template<typename A,typename B> inline A fexp(A x,B p,A mo){A ans=1;for(;p;p>>=1,x=1LL*x*x%mo)if(p&1)ans=1LL*ans*x%mo;return ans;}

int n;

int A[maxn],B[maxn];

int dp[5010][5010];

int fac[8010],inv[8010];

void Work(){
	REP(i,-2000,2000)
		REP(j,-2000,2000)dp[i+bas][j+bas]=(dp[i-1+bas][j+bas]+dp[i+bas][j-1+bas]+dp[i+bas][j+bas])%mod;
	int ans=0;
	REP(i,1,n)ans=(ans+dp[A[i]+bas][B[i]+bas])%mod;
	REP(i,1,n)ans=(ans-1ll*fac[A[i]+A[i]+B[i]+B[i]]*inv[A[i]+A[i]]%mod*inv[B[i]+B[i]]%mod+mod)%mod;
	ans=1ll*ans*fexp(2,mod-2)%mod;
	iout(ans);
}

void Init(){
	read(n);
	REP(i,1,n)read(A[i],B[i]),dp[bas-A[i]][bas-B[i]]++;
	fac[0]=1;REP(i,1,8000)fac[i]=1ll*fac[i-1]*i%mod;
	REP(i,0,8000)inv[i]=fexp(fac[i],mod-2);
}

int main(){
	Init();
	Work();
	return 0;
}


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

int main(){
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    int e=abs(a-b);
    int f=abs(b-c);
    int g=abs(a-c);
    if(g<=d || e<=d &&f <=d){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define _GLIBCXX_DEBUG
const int MOD = 1000000007;

int main() {
  char c;
  cin >> c;
  if (c=='a'||c=='e'||c=='i'||c=='o'||c=='u') cout << "vowel" << endl;
  else cout << "consonant" << endl;
}

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

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

  int64_t sum = 0;

  set<int> fizzbuzz;
  set<int> fizz;
  set<int> buzz;
  set<int> ans;

  for (int i = 1; i <= N; i++) {
    if ((i % 3 == 0) && (i % 5 == 0)) {

    } else if (i % 3 == 0) {
      
    } else if (i % 5 == 0) {

    } else {
      ans.insert(i);
    }
  }

  sum = 0;
  for (auto it = ans.begin(); it != ans.end(); it++) {
    sum += *it;
  }
  
  cout << sum << endl;

  return 0;
}


Measured memory_bytes: 28592
#include<bits/stdc++.h>
#define FIN ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
#define N 100005
#define v1 2*node
#define v2 2*node+1
#define med l+(r-l)/2
typedef long long ll;
typedef pair<int,int> pii;
vector<int> adj[N];
int n,m,res[N];
ll dp[N];
map<int,int> mapa[N];
vector<ll> st[N];
void update(int id, int node, int l, int r, int pos, int val){
    if(l == r){ st[id][node] = val%m; return; }
    if(pos <= med) update(id,v1,l,med,pos,val);
    else update(id,v2,med+1,r,pos,val);
    st[id][node] = st[id][v1]*st[id][v2]%m;
}
void upd(int u, int v, int val){
    update(u,1,0,adj[u].size()-1,mapa[u][v],val);
}
void dfs(int u, int p){
    dp[u] = 1;
    for(int v : adj[u]){
        if(v == p) continue;
        dfs(v,u);
        dp[u] = dp[u]*(1+dp[v])%m;
        upd(u,v,1+dp[v]);
    }
}
void go(int u, int p){
    res[u] = dp[u];
    for(int v : adj[u]){
        if(v == p) continue;
        upd(u,v,1);
        int ant = dp[v], cur = st[u][1]+1;
        dp[v] = dp[v]*cur%m;
        upd(v,u,cur);
        go(v,u);
        upd(v,u,1);
        dp[v] = ant;
        upd(u,v,ant+1);
    }
}
int main(){
    cin >> n >> m;
    for(int i = 0,u,v; i < n-1; i++){
        cin >> u >> v; u--,v--;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    for(int i = 0; i < n; i++){
        for(int j = 0; j < (int)adj[i].size(); j++)
            mapa[i][adj[i][j]] = j;
        st[i].resize(4*adj[i].size(),1);
    }
    dfs(0,-1);
    go(0,-1);
    for(int i = 0; i < n; i++)
        cout << res[i] << endl;
    return 0;
}


Measured memory_bytes: 40712
#include <iostream>
#include <cstdio>
#include <string>
#include <cctype>
#include <ctime>
#include <climits>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <stack>
#include <queue>
#include <deque>
#include <tuple>
#include <cmath>
#include <algorithm>

using namespace std;

#ifndef M_PI
    #define M_PI 3.14159265358979323846
#endif

#define pii pair<int, int>
#define pll pair<long long, long long>
#define mp make_pair
#define fr first
#define sc second
#define tiii tuple<int, int, int>
#define tlll tuple<long long, long long, long long>
#define mt make_tuple
#define ll long long
#define ld long double
#define pb push_back
#define all(x) x.begin(), x.end()

#define int long long

int32_t main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int q, h, s, d, n;
    cin >> q >> h >> s >> d >> n;
    int t = n / 2;

    int ans = t * min({d, 2 * s, 4 * h, 8 * q});
    if (n % 2)
        ans += min({s, 2 * h, 4 * q});

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 768
program main

  implicit none
  real(8) :: a,b,h,m
  real(8), parameter :: pi = 4.0d0*atan(1.0d0)
  real(8) :: t1,t2,c
  read(*,*) a,b,h,m

  t1 = pi/6.0d0*h + pi/360.0d0*m
  t2 = pi/30.0d0*m
  t2 = max(t1,t2)-min(t1,t2)
  
  c = sqrt(a**2 + b**2 -2.0d0*a*b*cos(t2))
  write(*,'(f0.10)')c

end program main

Measured memory_bytes: 3308
import math

x, y, r = 0, 0, 90
while True:
    d, t = map(float, input().split(","))
    if d == t == 0:
        break
    x += d * math.cos(math.radians(r))
    y += d * math.sin(math.radians(r))
    r -= t
print(int(x))
print(int(y))

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

int main(){
  int N,K;
  cin >> N >> K;
  int S,G;
  S = K - N +1;
  G = K+N-1;
  
  for(int i=S;i<=G;++i){
    if(i!=G){
      cout << i << endl;
    }
    else cout << i << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
	int n;
	float s, t;
	
	cin >> n;
	while(n--){
		scanf("%f:%f", &s, &t);
		
		s = s*30-5.5*t;
		
		if(s < 0){
			s = -s;
		}
		if(s > 180){
			s = 360 - s;
		}
		
		if(s < 30){
			cout << "alert" << endl;
		} else if(s < 90){
			cout << "warning" << endl;
		} else {
			cout << "safe" << endl;
		}
	}
}

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include<algorithm>
#include<sstream>
#include<iomanip>


using namespace std;

typedef long long ll;

const ll MOD_CONST = 1000000007;
const ll BIG_NUM = 1000000000000000000;



int main() {
	int q;
	cin >> q;
	set<ll> prime;
	for (ll i = 2; i <= 100000;i++){
		bool isPrime = true;
		for (ll p:prime) {
			if (p*p > i) {
				break;
			}
			if (i %p == 0) {
				isPrime = false;
			}
		}
		if (isPrime) {
			prime.insert(i);
		}
	}

	vector<int> cnt(100001);
	int last2017 = 0;
	for (auto it = prime.begin();it != prime.end();it++) {
		if (prime.find(*it * 2 - 1) != prime.end()) {
			
			for (int i = last2017 + 1; i < *it*2-1;i++) {
				cnt[i] = cnt[i - 1];
				
			}
			cnt[*it * 2 - 1] = (cnt[*it * 2 - 2] + 1);
			
			last2017 = *it * 2 - 1;
			
		}
	}
	for (int i = last2017 + 1; i < 100001;i++) {
		cnt[i] = cnt[i - 1];

	}
	

	for (int i = 0; i < q;i++) {
		int l, r;
		cin >> l >> r;
		cout << cnt[r] - cnt[l-1] << endl;
	}
	
}


Measured memory_bytes: 1536
// Package main provides
//
// File:  main.go
// Author: ymiyamoto
//
// Created on Sun Feb  3 21:01:00 2019
//
package main

import (
	"fmt"
	"sort"
)

func main() {
	var N int
	fmt.Scan(&N)
	slice := make([]int, N)

	for i := range slice {
		fmt.Scan(&slice[i])
	}
	sort.Ints(slice)

	remTotal := 0
	for i := range slice {
		if i < len(slice)-1 {
			remTotal += slice[i]
		}
	}

	if slice[len(slice)-1] < remTotal {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 512
#pragma GCC optimize("O3")
        #pragma comment(linker, "/stack:200000000")
        #pragma GCC optimize("unroll-loops")
         
        #include <algorithm>
        #include <bitset>
        #include <cassert>
        #include <chrono>
        #include <cmath>
        #include <complex>
        #include <cstdio>
        #include <cstdlib>
        #include <cstring>
        #include <ctime>
        #include <deque>
        #include <functional>
        #include <iomanip>
        #include <iostream>
        #include <iterator>
        #include <limits>
        #include <climits>
        #include <list>
        #include <map>
        #include <numeric>
        #include <queue>
        #include <random>
        #include <ratio>
        #include <set>
        #include <sstream>
        #include <stack>
        #include <string>
        #include <unordered_map>
        #include <unordered_set>
        #include <utility>
        #include <vector>
        using namespace std;
         
        typedef long long ll;
        typedef long double LD;
        #define int ll
        #define double LD
        #define pb push_back
        #define mp make_pair
        #define REP(i,n) for (int i = 0; i < n; i++)
        #define loop(i,n) for (int i = 0; i < n; i++)
        #define FOR(i,a,b) for (int i = a; i < b; i++)
        #define REPD(i,n) for (int i = n-1; i >= 0; i--)
        #define FORD(i,a,b) for (int i = a; i >= b; i--)
        #define remax(a,b) a = max(a,b)
        #define remin(a,b) a = min(a,b)
        #define mem(a, b) memset(a, b, sizeof a)
        #define append push_back
        #define all(v) v.begin(),v.end()
        #define F first
        #define S second
        #define print(x) cout << (x) << endl
        #define PRECISION(x) cout << fixed << setprecision(x)
        #define FAST_IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
        #define N 200005
        #define pb push_back
        const double PI=acos(-1);
        const int MOD = 1000000007;
        const int FMOD = 998244353;
        const double eps = 1e-9;
         
        mt19937 RNG(chrono::steady_clock::now().time_since_epoch().count()); 


		signed main()
		{
			int a;
			double b;
			cin>>a>>b;
			
			double ans=a*b;
			int ans1=ans;
			cout<<ans1;
		}

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

bool pairCompare(const pair<int, int>& a, const pair<int, int>& b){
  return a.second < b.second;
}

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n, 0);
  for(int i=0; i<n; i++){
    int num;
    cin >> num;
    a[num-1]++;
  }

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

  int ans = 0;
  int count = 0;
  for(int i=n-1; i>=0; i--){
    if(a[i] == 0) break;
    count++;
    if(count > k){
      ans += a[i];
    }
  }

  cout << ans << endl;
}



Measured memory_bytes: 1024
def solve():
    N = int(input())
    V = list(map(int,input().split()))
    C = list(map(int,input().split()))
    cnt=0
    for i in range(len(V)):
        if V[i] < C[i]:
            pass
        else:
            cnt += V[i]-C[i]
    print(cnt)


solve()


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pair<int, int> > piii;
#define pb push_back
#define NeedForSpeed ios_base::sync_with_stdio(0), cin.tie(0)
#define PI acos(-1)
#define all(c) c.begin(), c.end()
#define SET(x, y) memset((x), y, sizeof(x))
const int MOD = 1e9 + 7;
const int INF = 1e9 + 5;
const ll INF64 = 1e18;

template <typename T>
string to_string(const vector<T> &v) {
  string ret = "<";
  for (auto it : v) {
    ret += to_string(it) + ", ";
  }
  ret.pop_back(); ret.pop_back();
  ret += ">";
  return ret;
}

void debug_print() { cerr << endl; }

template <typename T, typename ...U>
void debug_print(T t, U... u) {
  cerr << " " << to_string(t);
  debug_print(u...);
}

#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_print(__VA_ARGS__)
const int N = 1e5 + 5;

struct node {
  ll a, b, c, d;
};

ll ans = -1;
ll arr[15];
ll n, m, q;
node quad[55];


void solve(int idx, int last) {
  if (idx == n) {
    ll score = 0;
    for (int i = 0; i < q; i++) {
      if (arr[quad[i].b - 1] - arr[quad[i].a - 1] == quad[i].c)
        score += quad[i].d;
    }
    ans = max(ans, score);
  } else {
    for (int i = last; i <= m; i++) {
      arr[idx] = i;
      solve(idx + 1, i);
    }
  }
}
       


int main() {
  cin >> n >> m >> q;
  for (int i = 0; i < q; i++) {
    cin >> quad[i].a >> quad[i].b >> quad[i].c >> quad[i].d;
  }
  solve(0, 1);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3592
#include <stdio.h>
#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
    int x, y;

    cin >> x >> y;

    if(x == 2 || y == 2){
        cout << "No" << endl;
        return 0;
    }

    if(x == 4 || x == 6 || x == 9 || x == 11 ){
        if(y == 4 || y == 6 || y == 9 || y == 11 ){
            cout << "Yes"  << endl;
            return 0;
        } else {
            cout << "No" << endl;
            return 0;
        }
    }
    if(x == 1 || x == 3 || x == 5 || x == 7 || x == 8 || x == 10 || x == 12){
        if(y == 1 || y == 3 || y == 5 || y == 7 || y == 8 || y == 10 || y == 12){
            cout << "Yes" << endl;
            return 0;
        } else {
            cout << "No" << endl;
            return 0;
        }
    }
}


Measured memory_bytes: 888
n = int(input())
l = list(map(int,input().split()))

ans = 0
for c in range(1,n):
    now = 0
    pas = set()
    for k in range(1,n):
        if k * c > n-1 or n-1-k*c <= c:
            break
        if n-1-k*c in pas or k*c in pas or n-1 == 2*k*c:
            break 
        now += l[n-1-k*c] + l[k*c]
        pas.add(n-1-k*c)
        pas.add(k*c)
        ans = max(ans,now)
        
print(ans)


Measured memory_bytes: 90836
#!/usr/bin/env pypy3
# N,M = map(int,sys.stdin.readline().split())
# a = tuple(map(int,sys.stdin.readline().split())) # single line with multi param
# a = tuple(int(sys.stdin.readline()) for _ in range(N)) # multi line with single param
# a = tuple(tuple(map(int,sys.stdin.readline().rstrip().split())) for _ in range(N)) # multi line with multi param
# s = sys.stdin.readline().rstrip()
# N = int(sys.stdin.readline())
# INF = float("inf")
import sys,math

N = int(sys.stdin.readline())
#counting prime
isPrime = [True]*(N+1)
f = [1]*(N+1)

for i in range(2,N+1):
    f[i] += 1
    j = i + i
    while j <= N:
        f[j] += 1
        j += i

sum = 0
for i in range(1,N+1):
    f[i] = f[i]*i
    sum += f[i]

print(sum)

Measured memory_bytes: 308152
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, M, a, b;
  cin >> N >> M;
  
  vector<int> road(N, 0); // 各都市から伸びる道路本数を格納する配列
  
  for (int i = 0; i < M; i++) {
    cin >> a >> b;
    road[a - 1]++; // 都市名と配列での順番の差を埋めるため -1
    road[b - 1]++;
  }

  for (int i = 0; i < N; i++) {
    cout << road[i] << endl;
  }
}

Measured memory_bytes: 3608
N, A, B = map(int, input().split())

if (B - A) % 2 == 0:
    print((B - A)//2)
elif A - 1 < N -B:
    print((A-1)+(B-A+1)//2)
else:
    print((N-B)+(B-A+1)//2)

Measured memory_bytes: 9176
import java.util.Scanner;

public class Main {
    public static final int MOD = 1_000_000_007;

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

        int N = sc.nextInt();
        int M = sc.nextInt();
        int[] a = new int[M];
        for (int i = 0; i < M; i++) {
            a[i] = sc.nextInt();
        }

        System.out.println(solve(N, M, a));
    }

    public static int solve(int N, int M, int[] a) {
        if (N == 1) return 1;

        int[] nlist = new int[N + 1];
        int aidx = 0;

        nlist[0] = 1;
        if (M != 0 && a[0] == 1) {
            nlist[1] = 0;
            aidx = 1;
        } else {
            nlist[1] = 1;
        }

        for (int i = 2; i <= N; i++) {
            if (aidx < M && a[aidx] == i) {
                nlist[i] = 0;
                aidx++;
            } else {
                nlist[i] = (nlist[i - 1] + nlist[i - 2]) % MOD;
            }
        }

        return nlist[N];
    }
}

Measured memory_bytes: 48784
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
// #include <regex> //正規表現
using namespace std;
#define rep(i,a,b) for(int i=(a); i<(b); ++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define RANGE(a,b,c) (a).begin()+b,(a).begin()+c // コンテナ a の 要素 b から c へのイテレータ
#define MOD 1000000007ll
#define INF 1000000000
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;
// グリッドグラフの移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};


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

int N; cin >> N;
VI A(N), B(N), C(N);
rep(i, 0, N) cin >> A[i];
rep(i, 0, N) cin >> B[i];
rep(i, 0, N-1) cin >> C[i];
int suf = 0;

rep(i,0, N){
    suf += B[A[i] - 1];
}

rep(i, 1, N){
    if (A[i] - A[i-1] == 1){
        suf += C[A[i-1] - 1];
    }
}

cout << suf << endl;
}

// 境界，出力文字列 チェック



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

typedef long long ll;

int main(){
    int N;
    cin>>N;
    vector<ll>a;
    for(int i=0;i<N;i++){
        ll t;
        cin>>t;
        a.push_back(t);
    }
    sort(a.begin(), a.end());
    ll max1=0,max2=0;
    for(int i=1;i<N;i++){
        if(a[i-1]==a[i]){
            max2=max1;
            max1=a[i];
            i++;
        }
    }
    cout<<max1*max2<<endl;
    return 0;
}


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

struct UnionFind {
  vector<int> par, siz;
  UnionFind (int n) {
    par.resize(n), siz.resize(n);
    for (int i = 0; i < n; i++) {
      par.at(i) = i, siz.at(i) = 1;
    }
  }
  int root(int x) {
    if (par.at(x) == x) return x;
    return par.at(x) = root(par.at(x));
  }
  int size(int x) {
    return siz.at(root(x));
  }
  bool same(int x, int y) {
    return root(x) == root(y);
  }
  bool unit(int x, int y) {
    x = root(x), y = root(y);
    if (x == y) return false;
    if (siz.at(x) > siz.at(y)) {
      par.at(y) = x, siz.at(x) += siz.at(y);
    } else {
      par.at(x) = y, siz.at(y) += siz.at(x);
    }
    return true;
  }
};

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int N, M, K;
  cin >> N >> M >> K;
  UnionFind UF(N);
  vector<vector<int>> F(N);
  for (int i = 0, a, b; i < M && cin >> a >> b; i++) {
    F.at(--a).push_back(--b);
    F.at(b).push_back(a);
    UF.unit(a, b);
  }
  vector<vector<int>> B(N);
  for (int i = 0, c, d; cin >> c >> d; i++) {
    B.at(--c).push_back(--d);
    B.at(d).push_back(c);
  }
  for (int i = 0; i < N; i++) {
    int ans = UF.size(i);
    ans--;
    for (auto b : B.at(i)) if (UF.same(i, b)) ans--;
    ans -= F.at(i).size();
    cout << ans << "\n"; 
  }
}

Measured memory_bytes: 12664
#!/usr/bin/env python
# -*- coding: UTF-8 -*-

def main() -> None:
    N = int(input())
    H = [int(a) for a in input().split()]

    now_jump = 0
    max_jump = 0
    for i in range(N - 1):
        if H[i] >= H[i + 1]:
            now_jump += 1
        elif H[i] < H[i + 1]:
            now_jump = 0
        max_jump = max(max_jump, now_jump)
    print(max_jump)


main()


Measured memory_bytes: 63984
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
			　　　　　　　　　　(¸.·´ (¸.·'* ☆
					*/

#include <iostream>
#include <vector>
#include <array>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <climits>
#include <tuple>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cmath>
#include <algorithm>
#include <memory>
#include <iomanip>
#include <type_traits>

#define rep(i, n) for(Int (i) = 0; (i) < (n); ++(i))
#define all(n) std::begin(n), std::end(n)
#define debug(var) std::cout << #var << ": " << var << "\n"
using Int = int64_t;
constexpr Int INF = INT_MAX;
constexpr Int mod = 1e9 + 7;


void init() {
	std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
}

void calc() {

	Int N, A, B; std::cin >> N >> A >> B;
	std::cout << std::min(A * N, B);

}


int main() {

	init();
	calc();

	return 0;
}

Measured memory_bytes: 256
def solve(a, b, c, d):
  mnx = min(a, c)
  mxx = max(a, c)
  mny = min(b, d)
  mxy = max(b, d)
  s = 3
  for k in range(32):
    if a<c:
      rx = (a+s/3*2)/s*s+s/3
      ry = (max(b, d)+s/3)/s*s+s/3
      if rx+s/3<=c and ry+s/3>max(b, d) and ry<=min(b, d):
        mny = min(mny, ry-1)
        mxy = max(mxy, ry+s/3)
        #print "a", k, s, rx, ry
    else:
      rx = (c+s/3*2)/s*s+s/3
      ry = (max(b, d)+s/3)/s*s+s/3
      if rx+s/3<=a and ry+s/3>max(b, d) and ry<=min(b, d):
        mny = min(mny, ry-1)
        mxy = max(mxy, ry+s/3)
        #print "b", k, s, rx, ry
    if b<d:
      rx = (max(a, c)+s/3)/s*s+s/3
      ry = (b+s/3*2)/s*s+s/3
      if ry+s/3<=d and rx+s/3>max(a, c) and rx<=min(a, c):
        mnx = min(mnx, rx-1)
        mxx = max(mxx, rx+s/3)
        #print "c", k, s, rx, ry
    else:
      rx = (max(a, c)+s/3)/s*s+s/3
      ry = (d+s/3*2)/s*s+s/3
      if ry+s/3<=b and rx+s/3>max(a, c) and rx<=min(a, c):
        mnx = min(mnx, rx-1)
        mxx = max(mxx, rx+s/3)
        #print "d", k, s, rx, ry
    s *= 3
  return min(a-mnx+c-mnx, mxx-a+mxx-c)+min(b-mny+d-mny, mxy-b+mxy-d)

"""
n = 9
F = [[None]*n for _ in range(n)]
def f(x, y, s):
  if s==1:
    return False
  if s/3<=x<s/3*2 and s/3<=y<s/3*2:
    return True
  return f(x%(s/3), y%(s/3), s/3)
for y in range(n):
  for x in range(n):
    F[y][x] = f(x, y, n)

def naive(a, b, c, d):
  D = [[9999]*n for _ in range(n)]
  D[b][a] = 0
  for dd in range(2*n):
    for y in range(n):
      for x in range(n):
        if D[y][x]==dd:
          for i in range(4):
            tx = x + [1, -1, 0, 0][i]
            ty = y + [0, 0, 1, -1][i]
            if 0<=tx<n and 0<=ty<n and not F[ty][tx]:
              D[ty][tx] = min(D[ty][tx], dd+1)
  return D[d][c]

for a in range(n):
  for b in range(n):
    if not F[b][a]:
      for c in range(n):
        for d in range(n):
          if not F[d][c]:
            x = solve(a, b, c, d)
            y = naive(a, b, c, d)
            if x!=y:
              print a, b, c, d, x, y
"""

Q = input()
for q in range(Q):
  a, b, c, d = map(int, raw_input().split())
  a -= 1
  b -= 1
  c -= 1
  d -= 1
  print solve(a, b, c, d)



Measured memory_bytes: 3204
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<math.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

using namespace std;
using ll = long long int;

int main(void) {
    int a, b; cin >> a >> b;
    if (a == 1 && b == 2 || a == 2 && b == 1) cout << 3 << endl;
    else if (a == 2 && b == 3 || a == 3 && b == 2) cout << 1 << endl;
    else cout << 2 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//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; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
*/

int main(){
    string s; cin >> s;
    printf("%c%lu%c\n", s[0], s.size()-2, s[s.size()-1]);
}

Measured memory_bytes: 256
/* In the name of Allah */
#include<bits/stdc++.h>
using namespace std;

const int N = 1e5 + 5;
struct node {
	long long mn_d, mx_d;
	long long mn_x, mn_y;
} seg[N << 2];
int n, e, t, x[N];
long long dp[N];

inline node merge(node a, node b) {
	return {min(a.mn_d, b.mn_d), max(a.mx_d, b.mx_d), min(a.mn_x, b.mn_x), min(a.mn_y, b.mn_y)};
}

void update(int p, long long x, long long d, int id = 1, int st = 0, int en = n) {
	if (en - st == 1) {
		seg[id] = {d, d, x, x + d};
		return;
	}
	int mid = st + en >> 1;
	if (p < mid)
		update(p, x, d, id << 1, st, mid);
	else
		update(p, x, d, id << 1 | 1, mid, en);
	seg[id] = merge(seg[id << 1], seg[id << 1 | 1]);
}

long long get(int l, int r, int d, int id = 1, int st = 0, int en = n) {
	if (r <= st || en <= l)
		return 1e18;
	if (l <= st && en <= r) {
		if (seg[id].mx_d <= d)
			return seg[id].mn_x + d;
		if (seg[id].mn_d >= d)
			return seg[id].mn_y;
	}
	int mid = st + en >> 1;
	return min(get(l, r, d, id << 1, st, mid), get(l, r, d, id << 1 | 1, mid, en));
}

inline void read_input() {
	cin >> n >> e >> t;
	for (int i = 0; i < n; i++)
		cin >> x[i];
}

inline void solve() {
	for (int i = 0; i < n; i++) {
		update(i, dp[i] - x[i - 1] - 2 * x[i], t + 2LL * x[i]);
		dp[i + 1] = get(0, i + 1, 2 * x[i]) + x[i];
	}
	cout << dp[n] + e - x[n - 1];
}

int main() {
	ios:: sync_with_stdio(0), cin.tie(0), cout.tie(0);
	read_input(), solve();
	return 0;
}


Measured memory_bytes: 10624