akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;

int main(){
  int N; cin >> N;
  vector<vector<int> > G(N);
  vector<P> vp;
  for(int i = 1; i < N; i++){
    int a, b; scanf("%d%d", &a, &b); --a; --b;
    G[a].push_back(b); G[b].push_back(a);
    vp.push_back(P(a, b));
  }
  int MAX_COLOR = 0;
  vector<int> used(N, 0), color(N, 0);
  queue<int> que; que.push(0);
  map<P, int> MAP;
  used[0] = 1;
  while(que.size()){
    int v = que.front(); que.pop();
    int num = 1;
    for(int i = 0; i < G[v].size(); i++){
      int u = G[v][i];
      if(used[u] != 0) continue;
      if(color[v] == num) num++;
      used[u] = 1;
      color[u] = num;
      MAP[P(u, v)] = num;
      MAP[P(v, u)] = num;
      num++;
      que.push(u);
    }
    MAX_COLOR = max(MAX_COLOR, int(G[v].size()));
  }
  cout << MAX_COLOR << '\n';
  for(auto p : vp) cout << MAP[p] << '\n';
}


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

int hit(int x[],int y[]){
	int num=0;
	for(int i=0;i<4;i++){
		if(x[i] == y[i])
			num++;
	}
	return num;
}

int blow(int x[],int y[]){
	int num=0;
	for(int i=0;i<4;i++){
		for(int j=0;j<4;j++){
			if(x[i] == y[j])
				num++;
		}
	}
	return num-hit(x,y);
}

int check(int x[],int y[]){
	for(int i=0;i<4;i++)
		if(x[i] / 10 != 0 || y[i] / 10 != 0) return 0;
	return 1;
}

int check2(int x[]){
	for(int i=0;i<4;i++){
		for(int j=0;j<4;j++){
			if(i != j && x[i] == x[j])
				return 0;
		}
	}
	return 1;
}
int main(){
	int a[4],b[4];
	
	while(cin >> a[0] >> a[1] >> a[2] >> a[3]){
		cin >>b[0] >> b[1] >> b[2] >> b[3];
		if(check(a,b)){
			if(check2(a)){
				if(check2(b)){
					cout << hit(a,b) << " "<<blow(a,b)<<endl;
				}
			}
		}
	}
	
}

Measured memory_bytes: 1164
#include<stdio.h>
int main()
{
	char a[4];
	scanf("%s",&a);
	if((a[1]==a[2]&&a[2]==a[3])||(a[0]==a[1]&&a[1]==a[2]))
		printf("Yes");
	else 
		printf("No");
	printf("\n");
	return 0;
 } 

Measured memory_bytes: 128
// Created by Tanuj Jain
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pii;
template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

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

	//#ifndef ONLINE_JUDGE
	//freopen("inputf.in","r",stdin);
	//freopen("outputf.in","w",stdout);
	//#endif

	int a,b,c,k;
	cin>>a>>b>>c>>k;
	ll sum=0;
	if(a>k)
	{
		cout<<k;
		return 0;
	}
	sum=a;
	k=k-a;
	while(k && b)
	{
		k--;
		b--;
	}
	if(k==0)
	{
		cout<<sum;
		return 0;
	}
	while(k && c)
	{	
		sum--;
		k--;
		c--;

	}
	cout<<sum;


	
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a) for(int i=0; i<(a); i++)
typedef long long ll;
const ll inf = 1LL<<60;

int main()
{
  int n,m,x; cin>>n>>m>>x;
  vector<ll> c(n);
  vector<vector<ll>> a(n, vector<ll>(m));
  rep(i, n) {
    cin>>c[i];
    rep(j, m) {
      cin>>a[i][j];
    }
  }
  ll ans = inf;
  for (int bits=0; bits<1<<n; bits++) {
    vector<ll> d(m, 0);
    ll sum = 0;
    for (int i=0; i<n; i++) {
      if (((bits>>i)&1) == 0) continue;
      for (int j=0; j<m; j++) {
        d[j] += a[i][j];
      }
      sum += c[i];
    }
    bool flg = true;
    for (int j=0; j<m; j++) {
      if (d[j] < x) {
        flg = false;
        break;
      }
    }
    if (flg) ans = min(ans, sum);
  }
  if (ans == inf) cout << -1 << endl;
  else cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
 
using namespace std;
 
#define MAX_N 100
#define MAX_V 2000
#define INF 1e9
 
int V,match[MAX_V];
vector<int> G[MAX_V];
bool used[MAX_V];
 
void add_edge(int u,int v){
    G[u].push_back(v);
    G[v].push_back(u);
}
 
bool dfs(int v){
    used[v] = true;
    for(int i = 0 ; i < (int)G[v].size() ; i++){
	int u = G[v][i],w = match[u];
	if(w < 0 || (!used[w] && dfs(w))){
	    match[v] = u;
	    match[u] = v;
	    return true;
	}
    }
    return false;
}
 
int bipartite_matching(){
    int res = 0;
    memset(match,-1,sizeof(match));
    for(int v = 0 ; v < V ; v++){
	if(match[v] < 0){
	    memset(used,false,sizeof(used));
	    if(dfs(v)){ res++; }
	}
    }
    return res;
}
 
void init(){
    for(int i = 0 ; i < MAX_V ; i++){
	G[i].clear();
    }
}
 
int main(){
    int N,M,L,a,b,c;
    while(cin >> N >> M >> L, N){
	int d[MAX_N][MAX_N];
	for(int i = 0 ; i < N ; i++){
	    for(int j = 0 ; j < N ; j++){
		d[i][j] = (i != j ? INF : 0);  
	    }
	}
	for(int i = 0 ; i < M ; i++){
	    cin >> a >> b >> c;
	    d[a][b] = d[b][a] = c;
	}
 
	int p[L],t[L];
	for(int i = 0 ; i < L ; i++){
	    cin >> p[i] >> t[i];
	}
	for(int i = 0 ; i < L ; i++){
	    for(int j = L-1 ; j > 0 ; j--){
		if(t[j] < t[j-1]){
		    swap(t[j],t[j-1]);
		    swap(p[j],p[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]);
		}
	    }
	}
	init(); V = L;
	for(int i = 0 ; i < L ; i++){
	    for(int j = i+1 ; j < L ; j++){
		if(d[p[i]][p[j]] <= t[j]-t[i]){
		    add_edge(i,j+L);
		}
	    }
	}
	cout << L-bipartite_matching() << endl;
    }
    return 0;
}

Measured memory_bytes: 9736
#include <iostream>
#include <algorithm>
#include <climits>
using namespace std;

int main(){
    
    int N;
    cin >> N;
    
    for(int i = 0; i <= 25; i++){
        int nokori = N - (4 * i);
        if(nokori >= 0 && nokori % 7 == 0){
            cout << "Yes" << endl;
            return 0;
        }
    }
    
    cout << "No" << endl;
    
}


Measured memory_bytes: 3124
#include<bits/stdc++.h>
using namespace std;
const int maxn=55;
int N[maxn],M[maxn];
int main()
{
	int n;cin>>n;
	for(int i=0;i<n;i++)
	{
		scanf("%d",&N[i]);
	}
	for(int i=0;i<n;i++)
	{
		scanf("%d",&M[i]);
	}
	for(int i=0;i<n;i++)
	{
		N[i]-=M[i];
	}
	sort(N,N+n);int sum=0;
	for(int i=n-1;i>=0;i--)
	{
		if(N[i]>=0) sum+=N[i];
	}
	cout<<sum<<endl;
 } 

Measured memory_bytes: 256
# Input acceptance
import sys

file_input = sys.stdin

V, E, r = map(int, file_input.readline().split())

edges = []

for line in file_input:
    edges.append(tuple(map(int, line.split())))


# Bellman???Ford algorithm
distance = [float("inf")] * V
distance[r] = 0
notUpdated = True

for i in range(V - 1):
    notUpdated = True
    for s, t, w in edges:
        temp_d = distance[s] + w
        if temp_d < distance[t]:
            distance[t] = temp_d
            notUpdated = False
    if notUpdated:
        break


# Output
if notUpdated:
    print(*map(lambda x: str(x).upper(), distance), sep = '\n')
else:
    flag = True
    for s, t, w in edges:
        temp_d = distance[s] + w
        if temp_d < distance[t]:
            print("NEGATIVE CYCLE")
            flag = False
            break
    if flag:
        print(*map(lambda x: str(x).upper(), distance), sep = '\n')

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

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

using namespace std;

typedef long long ll;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(20) << fixed;

  int n; cin >> n;
  char s[30004] = {0};
  cin >> s;

  int table[1000] = {0};

  int front[10] = {0}; 
  int back[10]  = {0}; 

  front[ s[0] - '0' ]++;
  for (int i = 2; i < n; i++) {
    back[ s[i] - '0' ]++;
  }

  for (int mid = 1; mid < n-1; mid++) {
    for (int i = 0; i < 10; i++) {
      for (int j = 0; j < 10; j++) {
        if (front[i] != 0 && back[j] != 0) {
          int t = i * 100 + (s[mid]-'0')*10 + j;
          table[t]++;
        }
      }
    }
    front[ s[mid]-'0' ]++;
    back[  s[mid+1]-'0' ]--;
  }

  int ans = 0;
  for (int i = 0; i < 1000; i++) {
    if (table[i] > 0) {
      ans++;
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <fstream>
#include<vector>
#include<utility>
#include<algorithm>


using namespace std;


int main()
{


	int n;
	cin >> n;

	vector<double> vec(n);

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


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


	double ans = vec[0];

	for (int i = 1; i < n; i++) {
		ans += vec[i];
		ans /= 2.0;
	}

	printf("%.8lf\n", ans);





	return 0;
	
}



Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#define REP(i,n) for(int i = 0; i < (int)n; i++)
using namespace std;

int main(){
  int n;
  cin >> n;
  int cnt[3] = {};
  REP(i,n){
    int a;
    cin >> a;
    if(a%4==0){
      cnt[2]++;
    }else if(a%2==0){
      cnt[1]++;
    }else{
      cnt[0]++;
    }
  }
  int prev = 2;
  REP(i,n){
    int min = 2 - prev;
    if(min==1){
      if(cnt[1]==0&&cnt[2]==0){
        cout << "No" << endl;
        return 0;
      }
      if(cnt[1]!=0){
        cnt[1]--;
        prev = 1;
      }else{
        cnt[2]--;
        prev = 2;
      }
    }else if(min==2){
      if(cnt[2]==0){
        cout << "No" << endl;
        return 0;
      }else{
        cnt[2]--;
        prev = 2;
      }
    }else{
      if(cnt[0]!=0){
        cnt[0]--;
        prev = 0;
      }else if(cnt[1]!=0){
        cnt[1]--;
        prev = 1;
      }else{
        cnt[2]--;
        prev = 2;
      }
    }
  }
  cout << "Yes" << endl;
}


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

int main() {
  int N;
  cin>>N;
  bool ans=false;
  for(int i=0;i<N;i++){
    char s;
    cin>>s;
    if(s=='Y'){
      ans=true;
    }
  }
    if(ans){
      cout<<"Four"<<endl;
    }
    else{
      cout<<"Three"<<endl;
    }
  }

Measured memory_bytes: 256
#!/usr/bin/env python3
from itertools import combinations

def main():
    N = int(input())
    delicious = [int(s) for s in input().split()]
    combis = list(combinations(delicious, 2))
    heal = 0

    for combi in combis:
        heal += combi[0] * combi[1]
    print(heal)

if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
#include <stdio.h>

int main(void){
  int N;
  int A[25];
  int B[25];
  int C[25];
  int i;

  scanf("%d", &N);

  for (i = 1; i <= N; i++) {
    scanf("%d", &A[i]);
  }

  for (i = 1; i <= N; i++) {
    scanf("%d", &B[i]);
  }
  for (i = 1; i <= N-1; i++) {
    scanf("%d", &C[i]);
  }

  int ans = 0;

  for (i = 1; i <= N; i++) {
    ans += B[i];
  }

  for (i = 1; i <= N-1; i++) {
    if (A[i+1] == A[i] + 1) {
      ans += C[A[i]];
    }
  }

  printf("%d\n", ans);

}


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

int main(){
    int n;
    std::cin >> n;

    std::vector<int> vec(n);
    for(int i = 0; i < n; ++i){
        std::cin >> vec.at(i);
    }

    std::vector<int> buf;
    for(int bits = 1; bits < (1 << n); ++bits){
        int val = 0;
        for(int i = 0; i < n; ++i){
            if(bits & (1 << i)){
                val += vec.at(i);
            }
        }
        
        buf.push_back(val);
    }

    int q;
    std::cin >> q;
    for(int i = 0; i < q; ++i){
        int val;
        std::cin >> val;
        if(buf.end() != std::find(buf.begin(), buf.end(), val)){
                std::cout << "yes" << std::endl;
        }else{
                std::cout << "no" << std::endl;
        }
    }

    return 0;
}


Measured memory_bytes: 6856
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(V) V.begin(),V.end()
#define MOD 1000000007
#define tp tuple<ll,ll,ll>

vector<int> G[200010];

int child[200010];
ll d2[200010];

ll modpow(ll x, ll y) {
	ll ans = 1;
	while (y) {
		if (y & 1)ans *= x;
		x *= x;
		x %= MOD;
		ans %= MOD;
		y /= 2;
	}
	return ans;
}

ll moddiv(ll x, ll y) {
	return x * modpow(y, MOD - 2) % MOD;
}

int dfs(int c, int p) {
	int ans = 0;
	for (int i : G[c]) {
		if (i == p)continue;
		ans += dfs(i, c);
	}
	child[c] = ans + 1;
	return ans + 1;
}

int main() {
	d2[0] = 1;
	for (int i = 1;i < 200010;i++) {
		d2[i] = d2[i - 1] * moddiv(1, 2);
		d2[i] %= MOD;
	}
	int N, s, t;
	cin >> N;
	for (int i = 1;i < N;i++) {
		cin >> s >> t;
		G[s].push_back(t);
		G[t].push_back(s);
	}

	dfs(1, -1);
	//for (int i = 1;i <= N;i++)cout << child[i] << endl;
	
	ll x, y, z, r, c;
	ll ans = 0;
	for (int i = 1;i <= N;i++) {
		if (G[i].size() == 1)continue;

		r = d2[N - 1];//自分以外すべてが白である確率

		for (int p : G[i]) {
			if (child[p] > child[i]) {
				x = N - child[i];
				
				r += (MOD + 1 - d2[x]) * d2[child[i] - 1];
				r %= MOD;
			}
			else {
				r += (MOD + 1 - d2[child[p]]) * d2[N - 1 - child[p]];
				r %= MOD;
			}
		}
		ans += MOD + 1 - r;
		ans %= MOD;
	}
	ans *= d2[1];
	ans %= MOD;
	cout << ans << endl;
}

Measured memory_bytes: 22400
A = int(input())
B = int(input())
C = int(input())
X = int(input())
count = 0
for i in range(A+1):
    for j in range(B+1):
        for k in range(C+1):
            if 500*i + 100*j + 50*k == X:
                count+=1
print(count)

Measured memory_bytes: 9124
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		int i = 0;
		Scanner scan = new Scanner(System.in);;
		while(true) {
			i++;
			int a = scan.nextInt();
			if(a == 0) {
				break;
			}
			System.out.println("Case " + i + ": " + a);
		}
		scan.close();
	}
}


Measured memory_bytes: 41356
#include <bits/stdc++.h>
#define F first
#define S second

using namespace std;
typedef long long ll;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    vector<int> a(3), v = {5, 5, 7};
    cin >> a[0] >> a[1] >> a[2];
    sort(a.begin(), a.end());
    if (a == v) cout << "YES";
    else cout << "NO";
    
}

Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func solve(in int) int {
	n500 := in / 500
	n5 := (in % 500) / 5
	return n500*1000 + n5*5
}

func main() {
	s := nextLine()
	in, _ := strconv.Atoi(s)
	fmt.Println(solve(in))
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define log(x) cout<<x<<endl
#define pb push_back
#define rep(i,n) for(int i = 0;i < n;++i)
using namespace std;

int main() {
    string S;
    cin>>S;
    if(S[0]==S[1] && S[1] == S[2]){
      log("No");
    }else{
      log("Yes");
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int const MAX = 1000020;
long long N;
long long a[MAX],b[MAX],c[MAX];
long long d[MAX],e[MAX];
long long sum=0;

int main()
{
    cin>>N;
    for(int i = 0; i < N; i++)
        scanf("%d", &a[i]);
    for(int i = 0; i <N; i++)
        scanf("%d", &b[i]);
    for(int i = 0; i < N; i++)
        scanf("%d", &c[i]);
    sort(a,a+N),sort(b,b+N),sort(c,c+N);
    for(int i=0;i<N;i++)
    {
        d[i]=lower_bound(a,a+N,b[i])-a;
        e[i]=upper_bound(c,c+N,b[i])-c;
        e[i]=N-e[i];
        sum+=d[i]*e[i];
    }
    cout<<sum<<endl;
}


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

int d[30];
int main() {
	int w, n; scanf("%d%d", &w, &n);
	rep(i, w)d[i] = i + 1;
	rep(i, n) {
		int a, b; scanf("%d,%d", &a, &b); a--; b--;
		swap(d[a], d[b]);
	}
	rep(i, w)printf("%d\n", d[i]);
}

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

int main(){
	int n;
	cin>>n;
	int arr[105]={0};
	for(int i=1; i<=n; i++){
		int a,b;
		cin>>a>>b;
		if(a==b) arr[i] = 1;
	}
	for(int i=1; i<=n-2; i++){
		if(arr[i]==1 && arr[i+1]==1 && arr[i+2]==1){
			cout<<"Yes";
			return 0;
		}
	}
	cout<<"No";
}

Measured memory_bytes: 3616
function main(input) {
  input = input.trim().split("\n");
  const [h, w] = input[0].split(" ").map(a => Number(a));
  const lines = input.slice(1);
  const result = [];
  for (const line of lines) {
    result.push(...[line, line]);
  }
  console.log(result.join("\n"));
}
main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
import Control.Applicative
import Control.Monad
import Data.List

main :: IO ()
main = do
  n <- readLn
  abcs <- replicateM n $ sort . map read . words <$> getLine
  forM_ abcs $ \[a, b, c] -> do
    putStrLn $ if solve a b c then "YES" else "NO"

solve :: Int -> Int -> Int -> Bool
solve a b c = a^2 + b^2 == c^2



Measured memory_bytes: 4628
n = int(input())

ans = [n]
if n != 2:
    ans.append(n - 1)
for k in range(2, min(n - 1, 1000001)):
     tmp = n
     while tmp % k == 0:
         tmp //= k
     tmp %= k
     if tmp == 1:
         ans.append(k)
if 1000000 < n:
    ks = [k for k in ans]
    for k in ks:
        if k < n - 1 and (n - 1) % k == 0:
            ans.append((n - 1) // k)
ans = set(ans)
print(len(ans))

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

int main()
{
    long long n, a, b;
    cin >> n >> a >> b;

    if(a > b || (n == 1 && a != b))
    {
        cout << 0;
        return 0;
    }

    cout << (n - 2)*(b-a) + 1;

}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i < (int)(n); i++)
#define Sort(a) sort(a.begin(), a.end())
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
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;}

int main(){
    ll n;
    cin >> n;
    vll a(n);
    ll ans = 1;
    ll tmp = 1e18;
    ll test = 1e18;
    rep(i, n) cin >> a[i];
    sort(a.begin(), a.end());
    rep(i, n) {
        if(a[i] == 0) {
            ans *= a[i];
            break;
        }
        ans *= a[i];
        if(tmp < a[i]) {
            ans = -1;
            break;
        }
        tmp = (tmp+a[i]-1)/a[i];

        if(tmp == 0) {
            ans = -1;
            break;
        }
        if(ans > test) {
            ans = -1;
            break;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4044
#include<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define pb push_back
int dy[]={0, 0, 1, -1, 1, 1, -1, -1};
int dx[]={1, -1, 0, 0, 1, -1, -1, 1};

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define mp make_pair
#define fi first
#define sc second
ll n;
ll v[200],w[200];
ll W;

ll done[200][20000];
ll memo[200][20000];

ll solve(ll i,ll j) {
	if(done[i][j]) {
		return memo[i][j];
	}
	if(i >= n) {
		return 0;
	}

	if(j + w[i] > W) {
		return solve(i + 1,j);
	}

	ll ret = max(solve(i + 1,j),solve(i + 1,j + w[i]) + v[i]);
	done[i][j] = true;
	return memo[i][j] = ret;
}

int main(){
	cin >> n >> W;
	REP(i,n) {
		cin >> v[i] >> w[i];
	}
	cout << solve(0,0) << endl;
	return 0;
}



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

int main()
{
    int a, b;
    cin >> a >> b;
    int ans = 0;
    if (a > b)
    {
        ans += a;
        a--;
    }
    else
    {
        ans += b;
        b--;
    }
    if (a > b)
    {
        ans += a;
        a--;
    }
    else
    {
        ans += b;
        b--;
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a.at(i);
	}
	vector<int> b(a);
	sort(a.rbegin(), a.rend());
	if (a.at(0) == a.at(1)) {
		for (int i = 0; i < n; i++) {
			cout << a.at(0) << endl;
		}
	} else {
		for (int i = 0; i < n; i++) {
			if (b.at(i) == a.at(0)) {
				cout << a.at(1) << endl;
			} else {
				cout << a.at(0) << endl;
			}
		}
	}
}


Measured memory_bytes: 3200
#include<bits/stdc++.h>
using namespace std;
#define MAX_N 4005
#define MAX_T 4005
 
typedef long long ll;
#define INF (1LL<<60)
 
struct data{
  ll t,p,f;
  bool operator < (const data &p)const{
    return f<p.f;
  }
};
 
int N,T;
data a[MAX_N];
 
ll dp[MAX_T][MAX_N];
ll dm[MAX_T][MAX_N];
 
ll calc(int x,int y){
  if(y==0)return 0;
  return (a[x].f-a[y].f)*(a[x].f-a[y].f);
}
 
int main(){
  for(int i=0;i<MAX_T;i++){
    for(int j=0;j<MAX_N;j++){
      dp[i][j]=(j==0?0:-INF);
      dm[i][j]=(i==0||j==0?0:-INF);
    }
  }
   
  cin>>N>>T;
  a[0]=(data){0,0,0};
   
  for(int i=1;i<=N;i++){
    cin>>a[i].t>>a[i].p>>a[i].f;
  }
  sort(a+1,a+N+1);
 
  ll ans=0;
   
  for(int i=1;i<=T;i++){
 
    deque<int> deq;
    deq.push_back(0);
     
    for(int j=1;j<=N;j++){
      dp[i][j]=max(dp[i][j],dp[i-1][j]);
      if(i-a[j].t>=0){
        dp[i][j]=max(dp[i][j],dm[i-a[j].t][j]+a[j].p);
      }
      ans=max(ans,dp[i][j]);
 
 
       
      while(deq.size()>=2){
        int a=deq.front();deq.pop_front();
        int b=deq.front();
        if( dp[i][a]-calc(j,a) > dp[i][b]-calc(j,b) ){
          deq.push_front(a);
          break;
        }
      }
       
      int key=deq.front();
      dm[i][j]=dp[i][key]-calc(j,key);
 
      while(!deq.empty()){
        int a=deq.back();deq.pop_back();
        if( dp[i][a]-calc(j,a) > dp[i][j] ){
          deq.push_back(a);
          break;
        }
      }
      deq.push_back(j);
    }
  }
  /*
  for(int i=0;i<=15;i+=5){
    for(int j=0;j<=3;j++){
      if(dp[i][j]==-INF){
        cout<<"INF"<<' ';
      }else{
        cout<<dp[i][j]<<' ';
      }
    }
    cout<<endl;
  }
  cout<<endl;
   
  for(int i=0;i<=15;i+=5){
    for(int j=0;j<=3;j++){
      if(dm[i][j]==-INF){
        cout<<"INF"<<' ';
      }else{
        cout<<dm[i][j]<<' ';
      }
    }
    cout<<endl;
  }
 
  */
  cout<<ans<<endl;
   
  return 0;
}

Measured memory_bytes: 253880
//itp1_5-b
#include <iostream>
using namespace std;

int main(){
 int h,w;
 while(true){
  cin>>h>>w;
  if(h==0 && w==0){
   break;
  }
  for(int i=0;i<h;i++){
   for(int j=0;j<w;j++){
    if((i==0 || i==h-1) || (j==0 || j==w-1))
     cout<<'#';
    else
     cout<<'.';
   }
   cout<<endl;
  }
  cout<<endl;
 }
 return 0;
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
  int n,q; cin>>n>>q;
  int got = 0, pen = 0;
  map<int,int> f, cant;
  for(int i = 0 ; i < q; i++)
  {
    int n; string s;
    cin>>n>>s;
    if(!cant[n])
    {
      if(s=="WA")
        f[n]++;
      else
      {	
        pen += f[n];
        got++;
        cant[n] = 1;
      }
    }
  }
  cout<<got<<" "<<pen<<endl;
  return 0;
}

Measured memory_bytes: 9600
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>
#define ll long long

using namespace std;

long long MOD = 1000000007;

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

    vector<int> vec(N,-1);
    for(int i=1; i<=M; i++){
        int s, c;
        cin >> s >> c;
        s--;
        if(vec[s]!=-1 && vec[s]!=c){
            cout << -1 << endl;
            return 0;
        }else{
            vec[s]=c;
        }
    }
    if(N==1){
        if(vec[0]==-1){
            cout << 0 << endl;
        }else{
            cout << vec[0] << endl;
        }
        return 0;
    }

    if(N!=1 && vec[0]==0){
        cout << -1 << endl;
    }else{
        for(int i=0; i<N; i++){
            if(vec[i]==-1){
                if(i==0){
                    cout << 1;
                    continue;
                }
                cout << 0;
            }else{
                cout << vec[i];
            }
        }
        cout << endl;
    }

}

Measured memory_bytes: 256
#include <stdio.h>
int main(void) {
    long n, i, j, ans;
    char s[100001];
    scanf("%ld", &n);
    scanf("%s", s);

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

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
Created on Wed May  6 01:11:37 2020

@author: shinba
"""
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

K = int(input())
ans = 0
for i in range(1,K+1):
    for j in range(1,K+1):
        for k in range(1,K+1):
            ans += gcd(i,j,k)

print(ans)



Measured memory_bytes: 69628
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

n,m=map(int, input().split())
uf=UnionFind(n)
for _ in range(m):
    a,b=map(int, input().split())
    uf.union(a-1, b-1)
cnt=0
for i in range(n):
    cnt=max(cnt, uf.size(i))
print(cnt)

Measured memory_bytes: 14476
#include<bits/stdc++.h>
using namespace std;
const int maxn=600+10;
const int INF=int(1e9)+10;
#define LL long long
char str[maxn][maxn];
char s[maxn][maxn];
int main() {
	int n;
	cin>>n;
	for(int i=0; i<n; i++) {
		scanf("%s",str[i]);
	}
	for(int i=0; i<2*n; i++) {
		for(int j=0; j<2*n; j++) {
			if(i>=n&&j>=n)
				str[i][j]=str[i-n][j-n];
			if(i>=n&&j<n)
				str[i][j]=str[i-n][j];
			if(i<n&&j>=n)
				str[i][j]=str[i][j-n];
		}
	}
	/*for(int i=0; i<2*n; i++) {
		for(int j=0; j<2*n; j++)
			cout<<str[i][j];
		cout<<endl;
	}*/
	int ans=0;
	for(int a=0; a<n; a++) {
		bool vis=true;
		for(int i=0,ii=0; i<n; ii++,i++) {
			for(int j=a,jj=0; j<a+n; jj++,j++) {
				s[ii][jj]=str[i][j];
			}
		}
		/*for(int i=0; i<n; i++) {
			for(int j=0; j<n; j++) {
				cout<<s[i][j];
			}
			cout<<endl;
		}*/
		for(int i=0; i<n; i++) {
			for(int j=0; j<n; j++) {
				if(s[i][j]==s[j][i])
					continue;
				vis=false;
				break;
			}
		}
		if(vis)
			ans+=n;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 768
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
using namespace std;

long long cnt;
int l;
int a[1000000];
int n;
vector<int> g;

void insertion_sort(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 -= g;
      ++cnt;
    }
    a[j + g] = v;
  }
}

void shell_sort(int a[], int n) {
  for (int h = 1;;) {
    if (h > n) {
      break;
    }
    g.push_back(h);
    h = 3 * h + 1;
  }

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

int main() {
  cin >> n;
  for (int i = 0; i < n; ++i) {
    scanf("%d", &a[i]);
  }
  cnt = 0;

  shell_sort(a, n);

  cout << g.size() << endl;
  for (int i = g.size() - 1; i >= 0; --i) {
    printf("%d", g[i]);
    if (i) {
      printf(" ");
    }
  }
  printf("\n");

  printf("%d\n", cnt);

  for (int i = 0; i < n; ++i) {
    printf("%d\n", a[i]);
  }

  return 0;
}



Measured memory_bytes: 7172
//In the Name of God
//Let Our Voices Echo
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
#define X real()
#define Y imag()
typedef long long ll;
typedef double ld; 
typedef complex<ld> point;
const ld eps=1e-9;
const int MAX=1e5+9,MOD=1e9+7;
ll n,a[MAX],par[MAX],ans1,ans2,tmp=0;
int main()
{
	ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	cin>>n;
	for (int i=1;i<=n;i++)
		cin>>a[i],par[i]=par[i-1]+a[i];
	for (int i=1;i<=n;i++)
	{
		ll x=par[i]+tmp;
		if (x>=0)
		{
			if (i%2==0)
				ans1+=x+1,tmp-=x+1;
			else
			if (x==0)
				ans1++,tmp++;
		}
		else
		{
			if (i%2==1)
				ans1+=1-x,tmp+=1-x;
		}
	}
	for (int i=1;i<=n;i++) a[i]*=-1,par[i]=par[i-1]+a[i];
	tmp=0;
	for (int i=1;i<=n;i++)
	{
		ll x=par[i]+tmp;
		if (x>=0)
		{
			if (i%2==0)
				ans2+=x+1,tmp-=x+1;
			else
			if (x==0)
				ans2++,tmp++;
		}
		else
		{
			if (i%2==1)
				ans2+=1-x,tmp+=1-x;
		}
	}
	cout<<min(ans1,ans2);
	return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ; //何もしない文
#endif

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size()) //unsignedのサイズをint型に変換
#define pb push_back

typedef long long LL; 
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);	
    LL N,M; cin >> N >> M;
    LL ans;
    if(N == 1 && M == 1)
    {
        ans = 1;
    }
    else if(N == 1 || M == 1)
    {
        ans = N + M - 3;
    }
    else
    {
        LL corner = 4;
        LL edge = (N-2 + M-2) * 2;
        LL inter = N * M - edge - corner;
        ans = inter;
    }
    cout << ans << endl;

}


Measured memory_bytes: 256
//Moh_K_Imar .......
//22/08/2020  ... 11,47
//Ya Rab....
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
int main(){
    string a;
    cin>>a;
    ll counter=0;
    for(ll i=0;i<a.size();i++){
        if(a[i]=='7')counter++;
    }
    if(counter!=0)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;

    return 0;
}



Measured memory_bytes: 3632
n=int(input()) 
lis=list(map(int,input().split()))
m=min(lis)
new=lis
num=0
while True:
  for i in range(n+num):
    new[i]%=m
  if all(nn==0 for nn in new):
    print(m)
    exit()
  new.append(m)
  sl={m}
  for i in range(n+num):
    if new[i]!=0:
      sl.add(new[i])
  m=min(sl)
  num+=1

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

int main(){
  int N;
  cin>>N;
  long double Y=0;
  for(int i=0;i<N;i++){
    long double x;
    string u;
    cin>>x>>u;
    if(u=="JPY")
      Y+=x;
    else
      Y+=x*380000;
  }
  cout<<Y<<endl;
}

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

using namespace std;
 
 #define tr(c, i) for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define   ipr         	pair<int, int>
#define   pb            push_back
#define   ff            first
#define   ss            second
#define fill(a,b) memset(a, b, sizeof(a))
#define   fr(i, j, k)   for (int i = j; i < k; i++)
#define   rf(i, j, k)   for (int i = j; i >= k;i--)
#define   int           long long int
#define   ll 			unsigned long long
#define   ld            long double
#define   all(x)        x.begin(), x.end()
#define   rall(x)       x.rbegin(),x.rend()
#define   mp            make_pair
#define L(x) ('a'<=x && x<='z')
#define   inf           INT_MAX
#define   read_file();	freopen("input.txt", "r", stdin);	freopen("output.txt", "w", stdout);
#define   IOS           std::ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 

const ld  pi   =  acos(-1);
const int mod =  1000000007;
const double epsilon = 1e-9; 
 
 
template<class T> ostream& operator <<(ostream &out,vector<T> &A){for(auto x:A) out<<x<<" ";return out;}
template<class T> ostream& operator <<(ostream &out,set<T> &A){for(auto x:A) out<<x<<" ";return out;}
template<class T> ostream& operator <<(ostream &out,unordered_set<T> &A){for(auto x:A) out<<x<<" ";return out;}
template <class T1,class T2>T1 powr(T1 a,T2 b){T1 res = 1;fr(i,1,b+1)res = res*a;return res;}

int binpow(int a,int b) {
    a=a%mod;
   
    int res = 1;
while (b > 0) {
        if (b & 1)res = (res * a)%mod;
        a = (a * a)%mod;
        b >>= 1;
}
return (res+mod)%mod;
}

const int MAXN  =  1e6+1;

int spf[MAXN];

void sieve() 
{ 
    spf[1] = 1; 
    for (int i=2; i<MAXN; i++) 
  
        // marking smallest prime factor for every 
        // number to be itself. 
        spf[i] = i; 
  
    // separately marking spf for every even 
    // number as 2 
    for (int i=4; i<MAXN; i+=2) 
        spf[i] = 2; 
  
    for (int i=3; i*i<MAXN; i++) 
    { 
        // checking if i is prime 
        if (spf[i] == i) 
        { 
            // marking SPF for all numbers divisible by i 
            for (int j=i*i; j<MAXN; j+=i) 
  
                // marking spf[j] if it is not  
                // previously marked 
                if (spf[j]==j) 
                    spf[j] = i; 
        } 
    } 
} 


 int32_t main(){
    IOS;
 
   int t;
   //cin>>t;
   sieve();
     t=1;
   while(t--){

  ll n;
	cin>>n;
	ll sum=0;
	for(ll i=1;i<=n;i++){
		sum+=(n/i);
		if(n%i==0){
			sum--;
		}
	}
	cout<<sum<<"\n";


 }
 }

Measured memory_bytes: 11460
#include <bits/stdc++.h>
// #include <boost/multiprecision/cpp_int.hpp>
//
// using boost::multiprecision::cpp_int;
using namespace std;

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MOD 1000000007

typedef long long ll;
typedef pair<ll, ll> p;


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  vector<int> v(3);
  for (int i = 0; i < 3; i++) {
    cin >> v[i];
  }
  sort(RALL(v));
  cout << abs(v[0] - v[1]) + abs(v[1] - v[2]) << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define N 200010
using namespace std;
int n,m,ans=0;
ll a[N],b[N],k;
int main()
{
    a[0]=0;b[0]=0;
    cin>>n>>m>>k;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        a[i]+=a[i-1];
    }
    for(int i=1;i<=m;i++)
    {
        cin>>b[i];
        b[i]+=b[i-1];
    }
    b[m+1]=2*1e18;
    //cout<<prev(upper_bound(b,b+1+m,99))-b<<endl;
    for(int i=0;i<=n;i++)
    {
        if(a[i]>k)break;
        int vt=prev(upper_bound(b,b+2+m,k-a[i]))-b;
        ans=max(ans,vt+i);
    }
    cout<<ans;
    return 0;
}


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

using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string deck;
    int num_shuffle;
    int len_shuffle;
    while(true){
        cin >> deck;
        if(deck == "-") break;
        cin >> num_shuffle;
        for(int i = 0; i < num_shuffle; i++){
            cin >> len_shuffle;
            deck = deck.substr(len_shuffle) + deck.substr(0, len_shuffle);
        }
        cout << deck << endl;
    }
}



Measured memory_bytes: 3168
N = int(input())
S = input()

def solve(s):
  add_left = 0
  add_right = 0
  for c in s:
    if c == '(':
      add_right += 1
    elif add_right == 0:
      add_left += 1
    else:
      add_right -= 1
  return '(' * add_left + s + ')' * add_right

ans = solve(S)
print(ans)


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

using namespace std;

using i64 = long long;

const i64 MOD = 1e9+7;

const i64 INF = 1e18+7;


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

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


signed main(){

    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    int n;
    cin >> n;
    vector<i64> a(n);
    for(auto& x : a)
        cin >> x;
    i64 ans = 0;
    for(int i = 0; i < n; ++i)
        ans += a[i] - i - 1;
    cout << ans << endl;
}




Measured memory_bytes: 3544
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    Set<String> set = new HashSet<String>();
    for (int i = 0; i < n; i++) {
      set.add(sc.next());
    }
    System.out.println(set.size());
  }

}

Measured memory_bytes: 76884
#include <iostream>
using namespace std;
int main(){
	for(;;){
		int H,W,i,l;
		cin >> H >> W;
		if(H==0 && W==0)break;

		for(i=0; i<H; i++){
			for(l=0; l<W; l++){
				if(l==0 || l==W-1 || i==0 || i==H-1){
					cout << "#";
				} else {
					cout << ".";
				}
			}
			cout << endl;
		}
		cout << endl;	
	}
}

Measured memory_bytes: 3080
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using ll=long long;
using namespace std;
int main(){
    ll n;
    cin>>n;
    vector<ll> a(n);
    rep(i,n)cin>>a[i];
    ll ans=0;
    
    rep(i,n-1){
        if(a[i]>a[i+1]){
            ans+=a[i]-a[i+1];
            a[i+1]+=a[i]-a[i+1];
        }
        
    }
    cout<<ans;
    
    }


Measured memory_bytes: 4804
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <stack>
#include <set>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

const ll M = 1e9+7;
const ll INF = 1e9+7;

ll n, k, r, s, p, ans;
string t;
ll dp[110000][3];

int main() {
  cin >> n >> k >> r >> s >> p >> t;
  
  for (ll i = 0; i < n; i++) {
    switch (t[i]) {
      case 'r': t[i] = 'p'; break;
      case 's': t[i] = 'r'; break;
      case 'p': t[i] = 's'; break;
    }
  }
  
  for (ll i = 0; i < n; i++) {
    if (i < k) {
      if (t[i] == 'r') dp[i][0] = r;
      if (t[i] == 's') dp[i][1] = s;
      if (t[i] == 'p') dp[i][2] = p;
    } else {
      if (t[i] == 'r') {
        dp[i][0] = max(dp[i-k][1], dp[i-k][2]) + r;
        dp[i][1] = max(dp[i-k][2], dp[i-k][0]);
        dp[i][2] = max(dp[i-k][0], dp[i-k][1]);
      }
      if (t[i] == 's') {
        dp[i][1] = max(dp[i-k][2], dp[i-k][0]) + s;
        dp[i][2] = max(dp[i-k][0], dp[i-k][1]);
        dp[i][0] = max(dp[i-k][1], dp[i-k][2]);
      }
      if (t[i] == 'p') {
        dp[i][2] = max(dp[i-k][0], dp[i-k][1]) + p;
        dp[i][0] = max(dp[i-k][1], dp[i-k][2]);
        dp[i][1] = max(dp[i-k][2], dp[i-k][0]);
      }
    }
  }
  
  for (ll i = n-1; i >= n-k; i--) {
    ans += max(max(dp[i][0], dp[i][1]), dp[i][2]);
  }
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 2816
import Control.Applicative ((<$>), (<*>))
import Control.Monad
import Data.List

main :: IO ()
main = do
  [n, a, b] <- getl $ wrds toInt
  solve a b <$> replicateM n (getl toInt) >>= print

solve :: Int -> Int -> [Int] -> Int
solve a b = length . filter (\x -> x < a || x >= b)

toInt :: String -> Int
toInt = read

wrds :: (String -> a) -> String -> [a]
wrds f = map f . words

getl :: (String -> a) -> IO a
getl f = f <$> getLine


Measured memory_bytes: 1020
// 基本テンプレート
 
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
using namespace std;
 
#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;
 
signed main() {
    int N; cin >> N;
    vector<int> A(N), B(N);

    int ans = 0, mi = INF, same_f = 1;
    rep(i,0,N) {
        cin >> A[i] >> B[i];

        ans += A[i];
        if(A[i] > B[i]) {
            chmin(mi, B[i]);
        }
        if(A[i] != B[i]) same_f = 0;
    }

    if(same_f) ans = 0;
    else ans -= mi;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 512
N,M=map(int,input().split())
H=list(map(int,input().split()))
Hmax=H.copy()

for _ in range(M):
    a,b=map(int,input().split())
    if H[a-1] > H[b-1]:
        Hmax[b-1]=0
    elif H[a-1] < H[b-1]:
        Hmax[a-1]=0
    else:
        Hmax[a-1]=0
        Hmax[b-1]=0

print(N-Hmax.count(0))


Measured memory_bytes: 20136
N = int(input())
A = list(map(int,input().split()))
x = 0
for i in range(N):
    if A[i] < 0:
        x = x + 1

if x % 2 == 0:
    for i in range(N):
        if A[i] < 0:
            A[i] = A[i] * -1
    print(sum(A))
       
else:
    if 0 in A:
        for i in range(N):
            if A[i] < 0:
                A[i] = A[i] * -1
        print(sum(A))  
            
    else:
        for i in range(N):
            if A[i] < 0:
                A[i] = A[i] * -1
        dele = min(A) 
        A.remove(min(A))

        print(sum(A) - dele)   

Measured memory_bytes: 14480
#include<iostream>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<utility>
#include<algorithm>
#include<cmath>
#include<climits>
using namespace std;

int main(){
	int a, b, c, x, y;
	cin >> a >> b >> c >> x >> y;
	int anum=x, bnum=y, cnum=0, price=a*anum+b*bnum;
	while(true){
		if(anum)
			anum--;
		if(bnum)
			bnum--;
		cnum+=2;
		if(a*anum+b*bnum+c*cnum<price)
			price=a*anum+b*bnum+c*cnum;
		else
			break;
	}
	cout << price << '\n';
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define int long long
const int MOD=1e9+7;
const int INF=1e15;

signed main(){
    int N,I;cin>>N>>I;
    if(N%I==0)cout<<0<<endl;
    else cout<<1<<endl;
}

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

int main(){
  int x;
  int a = 0, b = 0, c = 0, d = 0;
  cin >> x;
  for(int i = 0; i < x; i++){
    string s;
    cin >> s;
    if(s == "AC") a++;
    else if(s == "WA") b++;
    else if(s == "TLE") c++;
    else d++;
  }
  cout << "AC x " << a << endl;
  cout << "WA x " << b << endl;
  cout << "TLE x " << c << endl;
  cout << "RE x " << d << endl;
}

Measured memory_bytes: 3612
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
#define PI 3.141592653589793

int main(){
  string L; cin >> L; int N = L.size(); ll dp[101010][2] = {}; dp[0][0]=1;
  rep(i, N){
    dp[i+1][1]+=3*dp[i][1]; dp[i+1][1]%=mod;
    if(L[i]=='1'){
      dp[i+1][0]+=2*dp[i][0]; dp[i+1][0]%=mod;
      dp[i+1][1]+=dp[i][0]; dp[i+1][1]%=mod;
    }
    else dp[i+1][0]+=dp[i][0]; dp[i+1][0]%=mod;
  }
  cout << (dp[N][0]+dp[N][1])%mod << endl;
}
    

Measured memory_bytes: 2048
use proconio::{input, fastout, marker::Chars};

#[fastout]
fn main() {
    input! {
        n: usize,
        mut c: Chars
    }
    let mut cnt = 0;
    let mut j = n-1;
    for i in 0..n {
        if i >= j { break; }
        if c[i] == 'W' {
            while i < j {
                if c[j] == 'R' {
                    c[i] = 'R';
                    c[j] = 'W';
                    cnt += 1;
                    break;
                }
                j -= 1;
            }
        }
    }
    println!("{}", cnt);
}


Measured memory_bytes: 3084
#include <iostream>
#include <string>
#include <cstdio>
#include <cassert>
#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
using namespace std;
int ans,i;
char c;
bool b = false;
int main() {
  i = 0;
  while(true){
    i++;
  cin >> c;
  if(c == 'C') b = true;
  if(c == 'F'&&b){
    cout << "Yes" << endl;
    return 0;
  }
  if(c=='\n'){
    cout << "No" << endl;
    return 0;
  }
  if(i>105){
    cout << "No" << endl;
    return 0;
  }
  }
}


Measured memory_bytes: 256
//的場梨沙★担当
//結城晴★副担当
//日野茜★副担当
#include <vector>
#include <list>
#include <map>
#include <climits>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string.h>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <cctype>
#include <complex>
#include <regex>
#include <unordered_map>
#include <string>
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <stdio.h>


using namespace std;

int main(void) {
    int N,M;
    cin>>N>>M;

    if(N==M)cout<<"Yes"<<endl;
    else{
        cout<<"No"<<endl;
    }
}


Measured memory_bytes: 256
fun main(args:Array<String>) {
  val N = readLine()!!.toLong()
  val limit=3500L
  val equation:(Long,Long)->Pair<Long,Long> = {a,b -> Pair(N*a*b,(4*a*b-N*(a+b)))  }
   ath@ for(h in 1L..limit) {
     for(n in 1L..limit) {
       val (frac,denom)= equation(h,n)
        if(denom > 0L && frac % denom==0L) {
          println("${h} ${n} ${frac/denom}")
          break@ath
        }
      }
    }
}


Measured memory_bytes: 116204
#include<bits/stdc++.h>
#define ll long long
#define vi vector<int>
#define pb push_back
#define rep(n) for(int i = 0;i<n;i++)
#define all(v) v.begin(),v.end()
#define print(v) for(auto n:v){cout << n << "\t";}
#define quick                    \
    ios::sync_with_stdio(false); \
    cin.tie(0);
using namespace std;
void solve(){
	ll n;
	cin >> n;
	string s = "";
	while(n>0){
		int t = n%26-1;
      	if(t==-1){
          t = 25;
        }
		s+='a'+t;
		n-=t;
		n/=26;
	}
	reverse(all(s));
	cout << s << endl;
	

}


int main(){
	solve();
	// int t;
	// cin >> t;
	// while(t--){
	// 	solve();
	// }

	return 0;
}

Measured memory_bytes: 3564