akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <vector>
#include <set>
#include <bitset>

using namespace std;
#define lowbit(i) (i & (-i))
#define eps 1e-7
#define GETMID int mid = (l + r) >> 1
#define lson u << 1
#define rson u << 1 | 1
#define Lson u << 1, l, mid
#define Rson u << 1 | 1, mid + 1, r
#define Maxn (100000 + 10)
#define MP(a, b) make_pair(a, b)
#define PB(a) push_back(a);
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, int> pli;
const double PI = acos(-1.0);
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;

int n, c[200010];
int last[200010] = {0};
int dp[200010] = {0};

int main() {
	scanf("%d", &n);
	for(int i = 1; i <= n; ++i)
		scanf("%d", &c[i]);
	c[0] = -1;
	
	dp[0] = 1;
	for(int i = 1; i <= n; ++i) {
		dp[i] = dp[i - 1];
		if(c[i] != c[i - 1] && last[c[i]]) {
			dp[i] = (1ll * dp[i] + dp[last[c[i]]]) % mod;
		}
		
		last[c[i]] = i;
	}
	
	printf("%d\n", dp[n]);
	
	return 0;
}


Measured memory_bytes: 2560
#include <stdio.h>
 
class Dice4{
public:
    int number[6];
 
    void roll(char dst){
        switch(dst){
        case 'E':
            setNumber(number[3],number[1],number[0],number[5],number[4],number[2]);
            break;
        case 'N':
            setNumber(number[1],number[5],number[2],number[3],number[0],number[4]);
            break;
        case 'S':
            setNumber(number[4],number[0],number[2],number[3],number[5],number[1]);
            break;
        case 'W':
            setNumber(number[2],number[1],number[5],number[0],number[4],number[3]);
            break;
        }
    };
 
    bool isSameDice(int inputed[]){
        char order[25] = "NNNNWNNNWNNNENNNENNNWNNN";
        for(int i = 0; i < 24; i++){
            roll(order[i]);
            for(int j = 0; j < 6; j++){
                if(inputed[j] != number[j])
                    break;
                if(j == 5)
                    return true;
            }
        }
        return false;
    }
 
private:
    void setNumber(int n0,int n1,int n2,int n3,int n4,int n5){
        number[0] = n0;
        number[1] = n1;
        number[2] = n2;
        number[3] = n3;
        number[4] = n4;
        number[5] = n5;
    }
 
};
 
int main(){
    int n,k,j;
    scanf("%d",&n);
    Dice4 array[n];
    for(int i = 0; i < n; i++){
        scanf("%d %d %d %d %d %d",&array[i].number[0],&array[i].number[1],&array[i].number[2],
                &array[i].number[3],&array[i].number[4],&array[i].number[5]);
    }
    for(k = 0; k < n-1; k++){
        for(j = k+1; j < n; j++){
            if(array[k].isSameDice(array[j].number))
                break;
        }
        if(j < n) break;
    }
    if(k == n-1){
        printf("Yes\n");
    }else{
        printf("No\n");
    }
}


Measured memory_bytes: 2628
import copy

def main():
    n = int(input())

    table = [[-1]*n for i in range(n)]
    for i in range(n):
        a = int(input())
        for j in range(a):
            x, y = map(int, input().split())
            table[i][x-1] = y

    ans = 0
    for bit in range(0, 2**n):
        temp_ans = 0
        flag = True

        temp_table = []
        b = 1
        for i in range(n):
            if b & bit:
                temp_table.append(table[i][:])
                temp_table[-1][i] = 1
                temp_ans += 1
                for j in range(n):
                    temp_j_bit = bit >> j & 1
                    table_i_j = table[i][j]
                    if table_i_j == -1:
                        continue
                    elif temp_j_bit != table_i_j:
                        flag = False
            b <<= 1
        if temp_table and flag:
            temp_table_t = list(zip(*temp_table))
            for j, t in enumerate(temp_table_t):
                if 1 in t and 0 in t:
                    flag = False
        if flag:
            ans = max(ans, temp_ans)

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3572
#include<stdio.h>
#define MAX 250

int parent(int i){return i/2;}
int left(int i){return i*2;}
int right(int i){return i*2+1;}

int main(){
  int H,i,A[MAX+1];

  scanf("%d",&H);

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


  for(i=1;i<=H;i++){
    printf("node %d: key = %d, ",i,A[i]);
    if(parent(i)>=1) printf("parent key = %d, ",A[parent(i)]);
    if(left(i)<=H) printf("left key = %d, ",A[left(i)]);
    if(right(i)<=H) printf("right key = %d, ",A[right(i)]);
    printf("\n");
  }

  return 0;
}

Measured memory_bytes: 600
#include <stdio.h>

int main(int argc, const char * argv[]) {
    
    int n;
    int array[200];
    
    if (scanf("%d", &n)) {
        int array[n];
       
        for(int i = 0; i < n; ++i) {
            if ( scanf("%d", &array[i])) {}
        }
        
        int res = 0;
        while (1) {
            int isOdd = 0;
            
            for( int i = 0; i < n; ++i) {
                //printf("%d\n", array[i] % 2);
                if (array[i] % 2 == 0 ) {
                    isOdd = 1;
                } else {
                    isOdd = 0;
                    break;
                }
            }
            
            if(isOdd == 0) break;
            for (int i = 0; i < n; ++i) {
                array[i] /= 2;
            }
            res++;
        }
        
        printf("%d\n", res);
        
    }
    return 0;
}


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

int main(void){
    int N, T, min=10000;
    cin>>N>>T;

    int c[N], t[N];

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

      // for( int i=0;i<N;i++){
      //   cout>>c[i]>>t[i]<<endl;
      // }
    for(int i=0;i<N;i++){
      if((min>c[i])&&(t[i]<=T)){
        min = c[i];
      }
    }

    if(min>1000){
      cout<<"TLE"<<endl;
      return 0;
    }
    // vector<int> data(N);
    // sort(data.begin(),data.end());//昇順ソート

    cout<<min<<endl;

    return 0;
}


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

int main(){
  int n;
  cin >> n;
  ll b[n-1];
  for(int i=0; i<n; i++) cin >> b[i];
  ll ans = b[0];
  for(int i=0; i<n-1; i++){
    ans += min(b[i],b[i+1]);
  }
  cout << ans << endl;
}

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


long long gcd(long long a, long long b) {
   if (b == 0)
      return a;
   return gcd(b, a % b);
}
bool ok(long long a, long long b, long long c, long long d) {
  if (b > d) {
    return false;
  }
  if (b > a) {
    return false;
  }
  if (c >= b) {
    return true;
  }
  long long g = gcd(b, d);
  long long tmp = a - (a + b - c - 1) / g  * g;
  if (tmp < 0 && tmp >= c + 1 - b) {
    return false;
  } else {
    return true;
  }
}
int main() {
  int T;
  cin>>T;
  for (int t=0; t<T; t++) {
    long long a, b, c, d;
    cin>>a>>b>>c>>d;
    if (ok(a, b, c, d)) {
      cout<<"Yes"<<endl;
    } else {
      cout<<"No"<<endl;
    }
  }
}

Measured memory_bytes: 256
#include <stdio.h>
int n,G[101][101];
int d[101];
int T = 0;
int F[101] = {0};
int k = 0;
 
void visit(int u){
  int i,j,v;
  T++;  
  d[u] = T;
 
  for(v = 0;v < n;v++){
    if(G[u][v] == 1 && d[v] == 0 ){
      visit(v);
    }
  }
  T++;
  F[u] = T;
}
 
 
 
int main(){
   
   
  int i,j,k,l,u,a,t;
 
  for(i = 0;i < n;i++){
    d[i] = 0;
  }
  
  scanf("%d",&n);
 
  for(i = 0;i < n + 1;i++){
    for(j = 0;j < n + 1;j++){
      G[i][j] = 0;
    }
  }
 
  for(i = 0;i < n;i++){
 
    scanf("%d %d ",&k,&u);
 
    for(j = 0;j < u;j++){
      scanf("%d",&a);
      G[k - 1][a - 1] = 1;
    }
  }

  for(i = 0;i < n;i++){
    if(d[i] == 0) 
    visit (i);
  }
     
  for(i = 0;i < n;i++){
    printf("%d %d %d\n",i+1,d[i],F[i]);
  }

  return 0;
 
     
     
}

Measured memory_bytes: 636
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#include <cstdio>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
 
using namespace std;
 
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P > PP;
 
int tx[] = {0,1,0,-1};
int ty[] = {-1,0,1,0};
 
static const double EPS = 1e-8;

int dp[1000001];

int dfs(int icicles[100000],int num_of_icicles, int max_length,int icicle_i){
  if(dp[icicle_i] != -1) return dp[icicle_i];
  
  int neighbor_cost = 0;
  if(icicle_i < num_of_icicles - 1 && icicles[icicle_i + 1] > icicles[icicle_i]){
    neighbor_cost = max(dfs(icicles,num_of_icicles,max_length,icicle_i + 1),neighbor_cost);
  }
  if(icicle_i > 0 && icicles[icicle_i - 1] > icicles[icicle_i]){
    neighbor_cost = max(dfs(icicles,num_of_icicles,max_length,icicle_i - 1),neighbor_cost);
  }
  return (dp[icicle_i] = max(neighbor_cost + (max_length - icicles[icicle_i]),dp[icicle_i]));
}

int main(){
  int num_of_icicles;
  int max_length;
  while(~scanf("%d %d",&num_of_icicles,&max_length)){
    memset(dp,-1,sizeof(dp));
    int icicles[100000];
    for(int i = 0; i < num_of_icicles; i++){
      scanf("%d",&icicles[i]);
    }

    int res = 0;
    for(int i = 0; i < num_of_icicles; i++){
      res = max(res,dfs(icicles,num_of_icicles,max_length,i));
    }
    printf("%d\n",res);
  }
}

Measured memory_bytes: 9204
#include<cstdio>
const int N=1e5+2,P=1e9+7;
int i,j,n,x,r,a[N],inv[N];
int main()
{
	for(scanf("%d",&n);i++<=n;a[j]=i)
		if(scanf("%d",&j),a[j])x=a[j]+n-i;
	for(j=r=inv[1]=i=1;i++<=n;inv[i]=1ll*(P-P/i)*inv[P%i]%P);
	for(i=0;i++<=n;j=1ll*j*x--%P*inv[i]%P)
		printf("%d\n",((r=1ll*r*(n+2-i)%P*inv[i]%P)+P-j)%P);
}

Measured memory_bytes: 1920
use proconio::input;

fn main() {
	input!(sx: isize);
	input!(sy: isize);
	input!(tx: isize);
	input!(ty: isize);

	let dx = tx - sx;
	let dy = ty - sy;
	for _i in 0..dy {
		print!("U");
	}
	for _i in 0..dx {
		print!("R");
	}
	for _i in 0..dy {
		print!("D");
	}
	for _i in 0..dx {
		print!("L");
	}

	print!("L");
	for _i in 0..dy+1 {
		print!("U");
	}
	for _i in 0..dx+1 {
		print!("R");
	}
	print!("D");

	print!("R");
	for _i in 0..dy+1 {
		print!("D");
	}
	for _i in 0..dx+1 {
		print!("L");
	}
	println!("U");
}



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

#include <iostream>
#include <fstream>

#include <iostream>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>

#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <queue>
#include <unordered_map>
#include <unordered_set>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(12)

using namespace std;

typedef pair<int, int> P;

class CMedianSum {
public:
    static constexpr int kStressIterations = 0;

    static void generateTest(std::ostream& test) {
    }

    void solve(std::istream& cin, std::ostream& cout) {
        int N, sum = 0;
        cin >> N;
        vector<int> A(N);
        REP(i, N) {
            cin >> A[i];
            sum += A[i];
        }

        const int MAX = 2005 * 2005;
        bitset<MAX> b;
        b[0] = 1;
        REP(i, N) {
            b |= b << A[i];
        }

        FOR(i, (sum + 1) / 2, sum) {
            if (b[i] == 1) {
                cout << i << endl;
                return;
            }
        }

    }
};


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    std::istream& in(std::cin);
    std::ostream& out(std::cout);

    CMedianSum solver;
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 1920
s=input().split(" ")
a=int(s[0])
b=int(s[1])
c=int(s[2])
# a+b+2*sqrt(ab) < c
# 2*sqrt(ab) < c-a-b
# 4ab < (c-a-b)^2 c-a-bの符号注意

if c-a-b<0:
    print("No")
elif 4*a*b < (c-a-b)*(c-a-b):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
N, K = map(int, input().split())
xs = list(map(int, input().split()))

ans = 10 ** 9
for L in range(N - K + 1):
    xL, xR = xs[L], xs[L + K - 1]
    ansLR = abs(xL) + abs(xR - xL)
    ansRL = abs(xR) + abs(xL - xR)
    ans = min(ans, ansLR, ansRL)

print(ans)


Measured memory_bytes: 14224
# -*- coding: utf-8 -*-
"""
Created on Wed Sep 11 11:26:39 2019
D - 連結 / Connectivity
実行時間制限: 2 sec / メモリ制限: 256 MB

配点 : 
400 点
@author: justwah
"""
import sys

input = sys.stdin.readline # use this runtime 1523 ms> 1214ms

class UnionFind:
    def __init__(self, n):
        self.rank = [0]*n
        self.parent = [-1]*n
        self.n = n
        
    def root(self, x):
        if self.parent[x] < 0:
            return x
        else:
            self.parent[x] = self.root(self.parent[x])
            return self.parent[x]
        
    def merge(self, a, b):
        a = self.root(a)
        b = self.root(b)
        if a == b:
            return
        if self.rank[a] < self.rank[b]:
            self.parent[a] = b
        else:
            self.parent[b] = a
            if self.rank[a] == self.rank[b]:
                self.rank[a] +=1
                
    def same(self, a, b):
        return self.root(a) == self.roob(b)


n, k, l = map(int, input().split())

uf_road = UnionFind(n)
for _ in range(k):
    p, q = map(int, input().split())
    uf_road.merge(p-1, q-1)

uf_rail = UnionFind(n)
for _ in range(l):
    r, s = map(int, input().split())
    uf_rail.merge(r-1, s-1)
    
d = {}
IDs = [0]*n
for i in range(n):
    ID = (uf_road.root(i), uf_rail.root(i))
    IDs[i] = ID
    if ID in d:
        d[ID] += 1
    else:
        d[ID] = 1

ans = []
for i in range(n):
    ans.append(d[IDs[i]])
print(*ans)

Measured memory_bytes: 46436
using System;
using System.Collections.Generic;
using System.Linq;

namespace ALDS1_2_A
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var v = Console.ReadLine();
            var values = v.Split(' ').Select(s => int.Parse(s)).ToList();
            BubbleSort(values, values.Count());
        }
        
        public static void BubbleSort(List<int>targetArray,int arrayLength)
        {
            int i = 0;
            int count = 0;
            while (i <= arrayLength)
            {
                for (int j = arrayLength - 1; j > i; j--)
                {
                    if (targetArray[j] < targetArray[j - 1])
                    {
                        int temp = targetArray[j - 1];
                        targetArray[j - 1] = targetArray[j];
                        targetArray[j] = temp;
                        count++;
                    }
                }
                i++;
            }
            OutputList(targetArray);
            Console.WriteLine(count);
            return;
        }

        public static void OutputList(List<int> targetArray)
        {
            for (int i = 0; i < targetArray.Count; i++)
            {
                if (i == targetArray.Count - 1)
                {
                    Console.WriteLine(targetArray[i]);
                }
                else
                {
                    Console.Write(targetArray[i]);
                    Console.Write(' ');
                }
            }
            return;
        }
    }
}



Measured memory_bytes: 18296
#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 n, m;
  cin >> n >> m;
  vector<P> p;
  rep(i, n) {
    int a, b;
    cin >> a >> b;
    p.emplace_back(a, b);
  }
  sort(p.begin(), p.end());
  ll result = 0;
  for (P pp : p) {
    int v = min(m, pp.second);
    result += (ll) v * pp.first;
    m -= v;
    if (m == 0) {
      break;
    }
  }
  cout << result << endl;

  return 0;
}


Measured memory_bytes: 1400
/*
このコード、と～おれ!
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>

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


void calc() {

	Int N, M; std::cin >> N >> M;
	std::unordered_map<Int, Int> m;
	rep(i, M) {
		Int a, b; std::cin >> a >> b;
		m[a]++; m[b]++;
	}
	bool flag = true;
	for (auto itr = m.begin(); itr != m.end(); ++itr) {
		if (itr->second % 2 == 1)flag = false;
	}

	std::cout << (flag ? "YES" : "NO");

}


int main() {

	calc();

	return 0;
}

Measured memory_bytes: 3876
#include <algorithm>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
// const int INF = (1 << 30) - 1;
// const ll LL_INF = (1LL << 62) - 1;
// const ll MOD = 1e9 + 7;

int A, B;

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

  int ans = 0;
  if (A + B == 3) {
    ans = 3;
  } else if (A + B == 4) {
    ans = 2;
  } else {
    ans = 1;
  }

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mp make_pair
#define ff first
#define ss second
#define bg begin()
#define en end()
#define pb push_back
#define w(x) scanf("%d",&x);while(x--)
#define ws(x) scanf("%d",&x);getchar();while(x--)
#define rep(i,b) for(i=0;i<=b;i++)
#define ios ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pi 2*acos(0.0)
#define endl "\n"
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef vector<int> vi;

const int N=1e6+2;
long long  mod=1e9+9;
int t,j,cs=0,n,a,b,i,d;\
double dis;
string s;

int main()
{
    cin>>n>>d;
    ll a,b;
    int cnt=0;
    for(i=0;i<n;i++){
        cin>>a>>b;
        dis=a*a+b*b;
        dis=sqrt(dis);
        if(dis<=d) cnt++;
    }
    cout<<cnt<<endl;
}



Measured memory_bytes: 3644
#include <iostream>

using namespace std;

void trace(int *a, int n) {
    for (int i = 0; i < n - 1; i++) {
        cout << a[i] << " ";
    }
    cout << a[n-1] << endl;
}

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

int main() {
    int n;
    int a[1000];
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    insertionSort(a, n);
    trace(a, n);
    return 0;
}



Measured memory_bytes: 3092
from collections import deque
import copy

H, W = map(int, input().split())
a = [list(input()) for _ in range(H)]
d = [(1, 0), (0, 1), (-1, 0), (0, -1)]
que = deque([(i, j) for i in range(H) for j in range(W) if a[i][j] == '#'])
count = 0

flag_all = False

while True:
	count += 1

	que_next = deque()
	while que:
		i, j = que.popleft()
		for k in range(4):
			dx, dy = d[k][0], d[k][1]
			x = i + dx
			y = j + dy
			if x >= 0 and x < H and y >= 0 and y < W and a[x][y] != '#':
				a[x][y] = '#'
				que_next.append((x, y))

	que = copy.copy(que_next)

	if que:
		que = copy.copy(que_next)
	else:
		break
print(count-1)


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

#define MOD 1000000007
// #define INF 1000000000000

using namespace std;
typedef unsigned long long ull;
typedef long long ll;


template <class T>
ostream &operator<<(ostream &o, const vector<T>&obj) {
    o << "["; for (int i = 0; i < (int)obj.size(); ++i) o << (i > 0 ? ", " : "") << obj[i]; o << "]"; return o;
}
template <class T>
ostream &operator<<(ostream &o, const vector<vector<T>>&obj) {
    o << "[" << endl; for (int i = 0; i < (int)obj.size(); ++i) o << "  " << obj[i] << endl; o << "]"; return o;
}
template <class T, class U>
ostream &operator<<(ostream &o, const pair<T, U>&obj) {
    o << "(" << obj.first << ", " << obj.second << ")"; return o;
}
template <class T, class U>
ostream &operator<<(ostream &o, const map<T, U>&obj) {
    o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;
}
template <class T>
ostream &operator<<(ostream &o, const set<T>&obj) {
    o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;
}
template <class T>
ostream &operator<<(ostream &o, const queue<T>&obj) {
    queue<T> obj_cp = obj;
    bool first = true;
    o << "{";
    while (!obj_cp.empty()) { o << (!first ? ", " : "") << obj_cp.front(); obj_cp.pop(); first = false; }
    o << "}"; return o;
}

void print() {
    cout << "\n";
}
template<class Head, class... Body>
void print(Head head, Body... body) {
    cout << head << " ";
    print(body...);
}

vector<vector<int>> G;
vector<int> dp;

int rec(int v) {
    if (dp[v] >= 0) return dp[v];
    int ret = 0;
    for (int u : G[v]) {
        ret = max(ret, rec(u) + 1);
    }
    return dp[v] = ret;
}

int main(int argc, char const *argv[]) {
    ll A, B, C, K;
    cin >> A >> B >> C >> K;
    if (K <= A) {
        cout << K << endl;
    } else if (K <= A + B) {
        cout << A << endl;
    } else {
        cout << A - (K - (A + B)) << endl;
    }

    return 0;
}


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

using namespace std;

typedef  long long ll;
using vll=vector<ll>;
using vi=vector<int>;

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

//pow(llpow,modpow)
template<class T> ll llpow(ll x,T n){ll ans=1;if(x==0)ans=0;while(n){if(n&1)ans*=x;x*=x;n>>=1;}return ans;}
long long modpow(long long a, long long n, long long mod) {long long res = 1;while (n > 0) {if (n & 1) res = res * a % mod;a = a * a % mod;n >>= 1;}return res;}
//最大公約数
template<class T> inline T gcd(T x,T y){if(y==0)return x; else {return gcd(y,x%y);}}
//最小公倍数
template<class T> inline T lcm(T x,T y){return x/gcd(x,y)*y;}
//逆元
long long modinv(long long a, long long m) {long long b = m, u = 1, v = 0;while (b) {long long t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}

#define rep(i, begin_i, end_i) for (ll i = (ll)begin_i; i < (ll)end_i; i++)

long long INF = 1LL<<60;
int main( ){
    int a,b;
    using psi=pair<string,int>;
    cin>>a>>b;
    queue<psi> q;
    rep(i,0,a){
        string s; int in;
        cin>>s>>in;
        q.emplace(s,in);
    }
    ll t=0;
    while(!q.empty()){
        psi v=q.front();
        q.pop();
        if(v.second<=b){
            t+=v.second;
            cout<<v.first<<" "<<t<<endl;
        }
        else{
            t+=b;
            v.second-=b;
            q.push(v);
        }
    }
    return 0;
}





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

#define REP(i, n) for (ll (i) = 0 ; (i) < (ll)(n) ; ++(i))
#define REPN(i, m, n) for (ll (i) = m ; (i) < (ll)(n) ; ++(i))
#define REP_REV(i, n) for (ll (i) = (ll)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (ll (i) = (ll)(n) - 1 ; (i) >= m ; --(i))

#define INF 2e9
#define INF_LL 1LL<<60
#define ll long long

int main() {
    double r;
    cin >> r;

    cout << (double)r * 2 * 3.141592 << endl;

    return 0;
}


Measured memory_bytes: 3812
n = int(input())
s = input()

r = 0
g = 0
b = 0


for ss in s:
    if ss == "R":
        r += 1
    elif ss == "G":
        g += 1
    elif ss == "B":
        b += 1
ng = 0
i = 0
while i < n:
    j = 1
    while i+2*j < n:
        if s[i] != s[i+j] and s[i+j] != s[i+2*j] and s[i] != s[i+2*j]:
            ng += 1
        j += 1
    i += 1
print(r*g*b-ng)

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

constexpr int my_pow(int x, int n) {
	return n ? x * my_pow(x, n - 1) : 1;
}

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

	for(string s; cin >> s && s != "#";) {
		vector<int> dir;

		for(unsigned i = 0; i < s.size();) {
			if(s[i] == 'n') { // north
				dir.emplace_back(-90);
				i += 5;
			}
			else { // west
				dir.emplace_back(90);
				i += 4;
			}
		}

		reverse(dir.begin(), dir.end());

		const int n = dir.size();
		int denominator = my_pow(2, n);
		int numerator = (45 + dir.front() / 2) * denominator;

		int c = denominator;
		for(int i = 1; i < n; ++i) {
			c /= 2;
			numerator += c * dir[i];
		}

		if(numerator) {
			const int g = __gcd(numerator, denominator);
			numerator /= g;
			denominator /= g;
		}
		else {
			denominator = 1;
		}

		cout << numerator << (denominator == 1 ? "" : "/" + to_string(denominator)) << endl;
	}

	return EXIT_SUCCESS;
}

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

int main(){
  int a1,a2,a3;
  cin >> a1 >> a2 >> a3;
  if(a1+a2==a3||a2+a3==a1||a1+a3==a2){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3592
import sys
import math
import fractions
import bisect
import queue
import heapq
from collections import deque
sys.setrecursionlimit(4100000)

MOD = int(1e9+7)
PI = 3.14159265358979323846264338327950288
INF = 1e18

'''
1行のint
N, K = map(int, input().split())

1行のstring
S, T = input().split()

1行の整数配列
P = list(map(int,input().split()))

改行あり
x = []
y = []
for i in range(N):
    x1,y1=[int(i) for i in input().split()]
    x.append(x1)
    y.append(y1)

N行M列の初期化
dp = [[INF] * M for i in range(N)]

'''

"""""""""""""""""""""""""""""""""
 最大公約数 O()
"""""""""""""""""""""""""""""""""
# fractions.gcd(a,b)
def gcd(a, b):
    return fractions.gcd(a, b)

"""""""""""""""""""""""""""""""""
 最小公倍数 O()
"""""""""""""""""""""""""""""""""
def lcm(a,b):
    return (a*b) // fractions.gcd(a,b)


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


twice = 1
while True:
    if A[0] % (twice*2) == 0:
        twice*=2
    else:
        break

for a in A:
    if a%twice != 0:
        print(0)
        sys.exit()
    elif a%(twice*2) == 0:
        print(0)
        sys.exit()


half = 1 # 最小公倍数の二分の一
for i in range(N):
    A[i] //= 2
    half = lcm(half, A[i])

ans = (M//half) // 2 + int((M//half)%2 == 1)
print(int(ans))





"""
ATTENTION: Pythonで間に合うか？？

            <目安>
 文字列結合、再帰関数を含む→Python
 上を含まず時間が不安→PyPy3

"""

Measured memory_bytes: 90344
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {

	public static void main(String[] args) {

		FastScanner sc = new FastScanner();
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int X = sc.nextInt();
		int count = 0;
		for (int i = 0; i <= A; i++) {
			for (int j = 0; j <= B; j++) {
				int k = (X - (i * 500 + j * 100)) / 50;
				if (0 <= k && k <= C)
					count++;

			}
		}

		System.out.println(count);

	}
	//以下、自作ライブラリ

	//最大公約数
	public static long gcd(long a, long b) {
		if (a < b)
			return gcd(b, a);
		long c = 0;
		c = a % b;
		if (c == 0)
			return b;
		return gcd(b, c);
	}

	//最小公倍数
	public static long lcm(long m, long n) {
		return m * n / gcd(m, n);
	}

	//素数判定
	public static boolean isPrime(int n) {
		if (n < 2)
			return false;
		if (n == 2)
			return true;
		if (n % 2 == 0)
			return false;

		for (int i = 3; i * i <= n; i += 2) {
			if (n % i == 0)
				return false;
		}
		return true;
	}
}

//以下、高速スキャナークラス
class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
		return hasNextByte();
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
			throw new NumberFormatException();
		return (int) nl;
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}


Measured memory_bytes: 23124
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<queue>
#include<climits>
#include<set>
#include<map>
#define ll long long
using namespace std;


int main() {
	ll n, sum = 0;
	cin >> n;
	vector<ll>l(n);
	for (ll i = 0; i < n; i++) {
		cin >> l[i];
	}
	sort(l.begin(), l.end());
	for (ll i = 0; i < n; i++) {
		//cout << l[i] << endl;
	}
	//vector<ll>::iterator a;
	for (ll i = n-1; i >=1; i--) {
		for (ll j = i-1; j>=0; j--) {
			int cmin = upper_bound(l.begin(), l.end(), max(l[i] - l[j], l[j] - l[i])) - l.begin();
			if (i > j&&j > cmin) {
				int x = j - cmin;
				sum += x;
				//cout << "cmin" << cmin << endl;
				//cout << "cmax" << cmax << endl;
				//cout << l[i] << " " << l[j] << " " << l[cmin] << " " << endl;


			}
		}


		//cout << sum << endl;


	}
	cout << sum<< endl;
}


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

int main(){
    string a, b, c;
    cin >> a >> b >> c;
    a.push_back('E');
    b.push_back('E');
    c.push_back('E');
    char tmp = 'A';
    vector<int> l(3, 0);
    while(l[0] < (int)a.size() && l[1] < (int)b.size() && l[2] < (int)c.size()){
        if(tmp == 'A'){
            if(a[l[0]] == 'a') tmp = 'A';
            if(a[l[0]] == 'b') tmp = 'B';
            if(a[l[0]] == 'c') tmp = 'C';
            l[0]++;
        }
        if(tmp == 'B'){
            if(b[l[1]] == 'a') tmp = 'A';
            if(b[l[1]] == 'b') tmp = 'B';
            if(b[l[1]] == 'c') tmp = 'C';
            l[1]++;
        }
        if(tmp == 'C'){
            if(c[l[2]] == 'a') tmp = 'A';
            if(c[l[2]] == 'b') tmp = 'B';
            if(c[l[2]] == 'c') tmp = 'C';
            l[2]++;
        }
        if(tmp == 'E'){
            break;
        }
    }
    cout << tmp << endl;
}

Measured memory_bytes: 3592
n = gets.chomp.to_i
v = gets.split.map(&:to_i)

prop_v1 = []
prop_v2 = []
pair_v = v.each_slice(2)
v1 = pair_v.map(&:first)
v2 = pair_v.map(&:last)

s_v1 = v1.group_by { |e| e }.each.sort_by { |e| e[1].size }.reverse
prop_v1.push [s_v1[0].first, s_v1[0].last.size]
prop_v1.push [s_v1[1].first, s_v1[1].last.size] if s_v1.size > 1
s_v2 = v2.group_by { |e| e }.each.sort_by { |e| e[1].size }.reverse
prop_v2.push [s_v2[0].first, s_v2[0].last.size]
prop_v2.push [s_v2[1].first, s_v2[1].last.size] if s_v2.size > 2

v1_is_one = prop_v1.size == 1
v2_is_one = prop_v2.size == 1

if prop_v1.first.first != prop_v2.first.first
  puts n - prop_v1.first.last - prop_v2.first.last
else
  if v1_is_one && v2_is_one
    puts n/2
  elsif !v1_is_one && v2_is_one
    puts n - prop_v1.first.last
  elsif v1_is_one && !v2_is_one
    puts n - prop_v2.first.last
  else
    change_1 = prop_v2.first.last + prop_v1.last.last
    change_2 = prop_v1.first.last + prop_v2.last.last
    puts n - [change_1, change_2].max
  end
end


Measured memory_bytes: 24572
#include<cstdio>
int main(){
  int x, y;
  while(1){
    scanf("%d %d", &x, &y);
    if(x == 0 && y == 0)break;
    if(x < y){
      printf("%d %d\n", x, y);
    }else{
      printf("%d %d\n", y, x);
     }
  }
    return 0;
}



Measured memory_bytes: 2552
def main():
    s=set()
    for digit in range(16):
        for i in range(1,1000):
            c=i*10**digit+int('9'*digit or 0)
            if c<10**15:
                s.add(c)
    c=sorted(s)
    for i,n in enumerate(c):
        sn=n/sum(map(int,str(n)))
        for m in c[i+1:i+20]:
            sm=m/sum(map(int,str(m)))
            if sm<sn:
                s.remove(n)
                break
    print(*sorted(s)[:int(input())],sep='\n')
main()

Measured memory_bytes: 44380
from collections import deque

N, *ab = map(int, open(0).read().split())
B = ab[1::2]

E = [[] for _ in range(N + 1)]
for a, b in zip(*[iter(ab)] * 2):
    E[a].append(b)

Q = deque([1])
C = [0] * (N + 1)
while Q:
    v = Q.popleft()
    c = 0
    for u in E[v]:
        c += 1 + (c + 1 == C[v])
        C[u] = c
        Q.append(u)

print(max(C))
for b in B:
    print(C[b])


Measured memory_bytes: 25892
#include <bits/stdc++.h>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
typedef long long ll;
 
int main() {
    int n;
    cin>>n;
    int ans;

    for(int i=n;i>0;--i) {
        ans=i*108/100;
        if(ans==n) {
            cout<<i<<endl;
            goto OUT;
        }        
    }

    cout<<":("<<endl;

    OUT:
 return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <utility>
#include <string>
using namespace std;

#define gcu getchar_unlocked
int in(int c){int n=0;bool m=false;if(c=='-')m=true,c=gcu();
	do{n=10*n+(c-'0'),c=gcu();}while(c>='0');return m?-n:n;} //&&c<='9'
int in() {return in(gcu());}
bool scan(int &n){int c=gcu();return c==EOF?false:(n=in(c),true);}
bool scan(char &c){c=gcu();gcu();return c!=EOF;}
bool scan(string &s){int c;s="";
	for(;;){c=gcu();if(c=='\n'||c==' ')return true;else if(c==EOF)return false;s+=c;}}
template <typename head, typename... tail>
bool scan(head &h, tail&&... t){return scan(h) && scan(t...);}
#define pcu putchar_unlocked
#define vo inline void out
template <typename T>
vo(T n){static char buf[20];char *p=buf;
	if(n<0)pcu('-'),n*=-1;if(!n)*p++='0';else while(n)*p++=n%10+'0',n/=10;
	while (p!=buf)pcu(*--p);}
vo(const char *s){while(*s)pcu(*s++);}
vo(char c){pcu(c);}
//vo(string &s){for (char c: s) pcu(c);}
template <typename head, typename... tail> vo(head&& h, tail&&... t){out(h);out(move(t)...);}
//template <typename T> vo(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);out('\n');}
template <typename... tail> void outl(tail&&... t) {out(move(t)...); out('\n');}
#undef vo

int main() {
	string p, s;
	int n, c = 0;
	scan(p, n);
	while (n--) {
		scan(s);
		if ((s +s.substr(0, p.size() - 1)).find(p) != string::npos)
			c++;
	}
	outl(c);
}


Measured memory_bytes: 2676
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int N;
vector<int> s;
int ans;
int main(){
	cin>>N;
	for(int i=0;i<N;i++){
		int t;
		cin>>t;
		s.push_back(t);
		ans+=t;
	}
	sort(s.begin(),s.end());
	if(ans%10)cout<<ans<<endl;
	else{
		bool f=false;
		for(int i=0;i<N;i++){
			if(s[i]%10){
				cout<<ans-s[i]<<endl;
				f=true;
				break;
			}
		}
		if(!f)cout<<0<<endl;
	}
	return 0;
}

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

int main()
{
    int n; cin >> n;
    int a[n];
    for(int i = 0; i < n; i++)
        cin >> a[i];
    int dp[n];
    dp[0] = 0;
    dp[1] = abs(a[1]-a[0]);
    for(int i = 2; i < n; i++)
    {
        dp[i] = min(abs(a[i-1]-a[i])+dp[i-1], abs(a[i-2]-a[i])+dp[i-2]);
    }
    cout << dp[n-1] << endl;
    return 0;
}



Measured memory_bytes: 1024
import sys
input = sys.stdin.buffer.readline
N = int(input())
a = []
d = dict()
res = 0
for i in range(N):
  a.append(int(input()))
  d[a[i]] = i
b = sorted(a)
for i in range(N):
  j = d[b[i]]
  res += abs(i - j) % 2
print(res // 2)

Measured memory_bytes: 56920
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{
    int N;
    int X;
    vector<int> m;
    int sum = 0;

    cin >> N;
    cin >> X;

    for (int i = 0; i < N; i++) {
        int a;
        cin >> a;
        m.push_back(a);
    }

    for (int i = 0; i < m.size(); i++) {
         sum += m[i];
    }

    X = X - sum;

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

    int a =  X / m[0];

    cout << a + m.size() << endl;
    
}

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


int main() {
  int N;
  cin >> N;
  vector<int> A(N),cnt(N);
  ll ans=0;
  rep(i,N) cin >> A[i];
  rep(i,N) cnt[A[i]-1]++; //同じ数の個数をカウントする。
  
  rep(i,N){
    if(cnt[i]>1) ans += (ll)cnt[i]*(cnt[i]-1)/2; //全部ある時の場合の数
  }
  rep(i,N){
    ll ansk =ans;
    int k = A[i];
    k--;
    if(cnt[k]>1){
    ansk = ans - (ll)cnt[k]*(cnt[k]-1)/2 + (ll)(cnt[k]-1)*(cnt[k]-2)/2;
    }
    cout << ansk << endl;
  }
}





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

using namespace std;

int f(int p, int t, int n, int k, int s)
{
    if(k==0) return t==s ? 1 : 0;
    if(t>s) return 0;
    int res = 0;
    for(int i=p+1; i<=n; i++) res += f(i, t+i, n, k-1, s);
    return res;
}

int main()
{
    int n, k, s;
    while(cin >> n >> k >> s, n|k|s) cout << f(0, 0, n, k, s) << endl;
}

Measured memory_bytes: 3044
import Foundation
func toTuple<T>(_ args: [T]) -> (T, T, T) { (args[0], args[1], args[2]) }
func readInts() -> [Int] { readLine()!.split(separator: " ").map { Int($0)! } }

let (a, b, c) = toTuple(readInts())
let k = Int(readLine()!)!
let m = max(max(a, b), c)
print(m * Int(pow(2.0, Double(k))) + a + b + c - m)

Measured memory_bytes: 13556
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const ll INF = 1e9;
const double pi=acos(-1);

int main(){
  ll h,w;
  cin >> h >> w;
  if(h==1 || w==1){
    cout<<1<<endl;
    return 0;
  }
  if(h%2+w%2==1 ||(h%2==0 && w%2==0))cout<<h*w/2<<endl;
  else cout<<(h/2)*(w/2)+((h+1)/2)*((w+1)/2)<<endl;
    
}


Measured memory_bytes: 256
from collections import Counter
from functools import reduce

if __name__ == "__main__":
    N = int(input())
    arr = map(int, input().split())

    dic = Counter(arr)
    count = len(dic) - reduce(lambda sum, item: sum + 1, filter(lambda x: x % 2 == 0, dic.values()), 0) % 2
    print(count)


Measured memory_bytes: 22756
#include<iostream>
#include<vector>
using namespace std;
typedef long long ll;

int n, v[2000];
ll dp[2000][2000][2] = {};
bool visit[2000][2000][2] = {};

void joi(int op, int &a, int &b, int &c){
    if(op == 0){
        if(c == 0)  a++;
        else        a--;
        if(a < 0)   c = 0, a = b, b = n-1;
    }
    if(op == 1){
        if(c == 0)  b--;
        else        b++;
        if(b > n-1) c = 0, b = a, a = 0;
    }
}

void ioi(int &a, int &b, int &c){
    if(v[a] > v[b])         joi(0, a, b, c);
    else if(v[a] < v[b])    joi(1, a, b, c);
}

ll dfs(int x, int y, int z){
    if(visit[x][y][z])  return dp[x][y][z];

    visit[x][y][z] = true;

    // base
    if(x == y){
        return dp[x][y][z] = v[x];
    }
    if(abs(y-x) == 1 || (min(x,y)==0&&max(x,y)==n-1)){
        return dp[x][y][z] = max(v[x],v[y]);
    }

    int cx, cy, cz;
    // take x
    cx = x, cy = y, cz = z;
    joi(0, cx, cy, cz);
    ioi(cx, cy, cz);
    dp[x][y][z] = max(dp[x][y][z], v[x]+dfs(cx, cy, cz));

    // take y
    cx = x, cy = y, cz = z;
    joi(1, cx, cy, cz);
    ioi(cx, cy, cz);
    dp[x][y][z] = max(dp[x][y][z], v[y]+dfs(cx, cy, cz));

    return dp[x][y][z];
}

int main(){
    cin >> n;
    for(int i = 0; i < n; i++)  cin >> v[i];
    
    // stupid
    if(n == 1){
        cout << v[0] << endl;
        return 0;
    }else if(n == 2){
        cout << max(v[0], v[1]) << endl;
        return 0;
    }

    // idiot
    int x = 1, y = n-1, z = 0;
    if(v[x] > v[y]) x++;
    else            y--;
    ll ans = v[0] + dfs(x, y, z);
    x = 0, y = n-2, z = 0;
    if(v[x] > v[y]) x++;
    else            y--;
    ans = max(ans, v[n-1] + dfs(x, y, z));

    for(int i = 1; i < n-1; i++){
        x = i-1, y = i+1, z = 1;
        ioi(x, y, z);
        ans = max(ans, v[i]+dfs(x,y,z));
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 49516
#include <iostream>
#define _USE_MATH_DEFINES
#include <math.h>
using namespace std;


int main()
{
	double a, b, c;
	cin >> a >> b >> c;
	double dA, dC, dH, dD;
	c *= M_PI / 180;
	dA = (a*b*sin(c)) / 2.0;
	dD = sqrt(a*a + b * b - 2 * a*b * cos(c));
	dC = a + b + dD;
	dH = dA * 2 / a;
	printf("%.5lf\n", dA);
	printf("%.5lf\n", dC);
	printf("%.5lf\n", dH);

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

Measured memory_bytes: 3444
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <stack>
#include <set>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()

const int N = (int)3e5;

ll mpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = mpow(a,b/2); return memo*memo%MOD;}
  else return mpow(a,b-1) * a % MOD;
}
ll lpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = lpow(a,b/2); return memo*memo;}
  else return lpow(a,b-1) * a;
}
ll gcd(ll a, ll b){
  if(b==0) return a;
  else return gcd(b, a%b);
}
vector<ll> kaijo_memo;
ll kaijo(ll n){
  if(kaijo_memo.size() > n) return kaijo_memo[n];
  if(kaijo_memo.size() == 0) kaijo_memo.push_back(1);
  while(kaijo_memo.size() <= n) kaijo_memo.push_back(kaijo_memo[kaijo_memo.size()-1] * kaijo_memo.size() % MOD);
  return kaijo_memo[n];
}
vector<ll> gyaku_kaijo_memo;
ll gyaku_kaijo(ll n){
  if(gyaku_kaijo_memo.size() > n) return gyaku_kaijo_memo[n];
  if(gyaku_kaijo_memo.size() == 0) gyaku_kaijo_memo.push_back(1);
  while(gyaku_kaijo_memo.size() <= n) gyaku_kaijo_memo.push_back(gyaku_kaijo_memo[gyaku_kaijo_memo.size()-1] * mpow(gyaku_kaijo_memo.size(), MOD-2) % MOD);
  return gyaku_kaijo_memo[n];
}

ll nCr(ll n, ll r){
  if(n == r) return 1;//0個の丸と-1個の棒みたいな時に時に効く？不安.
  if(n < r || r < 0) return 0;
  ll ret = 1;
  ret *= kaijo(n); ret %= MOD;
  ret *= gyaku_kaijo(r); ret %= MOD;
  ret *= gyaku_kaijo(n-r); ret %= MOD;
  return ret;
}


int main(void){
  ll t1,t2,a1,a2,b1,b2;
  cin>>t1>>t2>>a1>>a2>>b1>>b2;
  if(b1>a1){
    ll tmp=a1;
    a1=b1;
    b1=tmp;
    tmp=b2;
    b2=a2;
    a2=tmp;
  }
  ll dif = b1*t1+b2*t2-a1*t1-a2*t2;
  ll oi = a1*t1-b1*t1;
  //dif * ans > oi && dif * (ans-1) <= oi
  if(dif < 0){
    cout<<0<<endl;
    return 0;
  }
  if(dif == 0){
    cout<<"infinity"<<endl;
    return 0;
  }
  ll ans = oi / dif + 1;
  ans *= 2;
  if(oi%dif != 0){
    ans -= 1;
  }else{
    ans -= 2;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
N, K = map(int, input().split())
P = list(map(lambda x: int(x)-1, input().split()))
C = list(map(int, input().split()))

visited = [False]*N
lp = [[0] for _ in range(N)]

lidx = 0
for s in range(N):
    if visited[s]:
        continue

    nex = s
    while not visited[nex]:
        visited[nex] = True
        now = P[nex]
        nex = now
        lp[lidx].append(lp[lidx][-1] + C[now])

    lidx += 1

ans = -(10**10)

for k in range(lidx):
    loop = lp[k]
    km = loop[-1]
    
    lenloop = len(loop)-1

    pt = 0

    kk = K

    x = max(kk//lenloop-1, 0)
    if km > 0:
        pt += x*km
    kk -= x*lenloop

    # print(x, kk, km)

    for i in range(lenloop*2):
        loop.append(loop[i+1]+km)
    
    for i in range(lenloop):
        for j in range(i+1, i+kk+1):
            # print(i, j, loop[j]-loop[i])
            ans = max(loop[j]-loop[i]+pt, ans)

# print(lp)

print(ans)

Measured memory_bytes: 69588
#include <bits/stdc++.h>
using namespace std;
typedef                 long long ll;
typedef                 unsigned long long ull;
#define mkp             make_pair
#define pii             pair<int,int>
#define piii            pair<pii,int>
#define vi              vector<int>
#define PI              acos(-1)
#define all(v)          v.begin(),v.end()
#define mmset(a,val)    memset(a,val,sizeof(a))
#define sc(a)           scanf("%d",&a)
#define sc2(a,b)        scanf("%d%d",&a,&b)
#define sc3(a,b,c)      scanf("%d%d%d",&a,&b,&c)
#define sc4(a,b,c,d)    scanf("%d%d%d%d",&a,&b,&c,&d)
#define sc5(a,b,c,d,e)  scanf("%d%d%d%d%d",&a,&b,&c,&d,&e)
#define scll(a)         scanf("%I64d",&a)
#define scll2(a,b)      scanf("%lld%lld",&a,&b)
#define scll3(a,b,c)    scanf("%lld%lld%lld",&a,&b,&c)
#define scll4(a,b,c,d)  scanf("%I64d%I64d%I64d%I64d",&a,&b,&c,&d)
#define Pr(a)           printf("%d\n",a)
#define Prll(a)         printf("%lld\n",a)
#define pb(a)           push_back(a)
#define SZ              size()
#define tcs(t)          for(int tc=1;tc<=t;tc++)
#define INF             0x3f3f3f3f
#define hash_val        347
#define popcount        __builtin_popcount
#define MOD             1000000007
#define MX              10005
//int fx[]={-1,-1,0,1,1,1,0,-1};
//int fy[]={0,1,1, 1,0,-1,-1,-1};
int Set(int n,int pos){return n=n|(1<<pos);}
int reset(int n,int pos){return n=n& ~ (1<<pos);}
bool check(int n,int pos){return (bool) (n& (1<<pos));}
ll gcd(ll a,ll b){if(b==0)return a;else return gcd(b,a%b);};
ll lcm(ll a,ll b){return (a*b)/gcd(a,b);};
int main()
{
            #ifdef AINAN
                       freopen("input.txt","r",stdin);
              //  freopen("output.txt","w",stdout);
              #endif
               int x,a,b;
               sc3(x,a,b);
               x-=a;
               cout<<x%b<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maX= 1e4+10;
int n;
int arr[maX];
int fn(int a,int b,int c){
    return (a*a+b*b+c*c+a*c+a*b+b*c);
}
void call(){
    for(int x=1;x<=sqrt(n);x++){
        for(int y=1;y<sqrt(n);y++){
            for(int z=1;z<=sqrt(n);z++){
                if(fn(x,y,z)<=n){
                    arr[fn(x,y,z)]++;
                }
                // break;
            }
        }
    }
    
}
int main(){
    cin>>n;
    call();
    for(int i=1;i<=n;i++){
        cout<<arr[i]<<"\n";
    }
    return 0;
}

Measured memory_bytes: 3636
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<unordered_map>
#include<iomanip>
#include<bitset>
#define mod 1000000007
using namespace std;
typedef long long ll;
#define chmax(a,b) a=max(a,b)
#define chmin(a,b) a=min(a,b)
#define mad(a,b) a=(a+b)%mod
#define mul(a,b) a=a*b%mod

#define N 100010
ll n;
bool x[N],y[N];
int main(){
    cin>>n;
    vector<pair<ll,ll> >v;
    for(int i=0;i<n;i++){
	ll a,b; cin>>a>>b;
	v.push_back(make_pair(a,i*2+0));
	v.push_back(make_pair(b,i*2+1));
    }
    sort(v.begin(),v.end());
    ll sum=0;
    for(int i=0;i<v.size();i++){
	if(v[i].second%2==0)x[v[i].second/2]=(i<n);
	if(v[i].second%2==1)y[v[i].second/2]=(i<n);
	if(i<n)sum+=v[i].first;
    }
    ll a=0,b=0,c=0,d=0;
    for(int i=0;i<n;i++){
	if(x[i]==0&&y[i]==0)a++;
	if(x[i]==0&&y[i]==1)b++;
	if(x[i]==1&&y[i]==0)c++;
	if(x[i]==1&&y[i]==1)d++;
    }
    if(a>0||b==0||c==0){
	cout<<sum<<endl;
    }
    else{
	if(v[n-1].second/2==v[n].second/2){
	    ll mi=1e17;
	    chmin(mi,v[n+1].first-v[n-1].first);
	    chmin(mi,v[n+0].first-v[n-2].first);
	    cout<<sum+mi<<endl;
	}
	else{
	    cout<<sum-v[n-1].first+v[n].first<<endl;
	}
    }
}




Measured memory_bytes: 6512