akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
using namespace std;
static const int MAX = 1000;
static const int VMAX = 10000;
 
int n, A[MAX], s;
int B[MAX], T[VMAX+1];
 
int solve(){
    int ans = 0;
 
    bool V[MAX];
    for(int i=0;i<n;i++){
        B[i] = A[i];
        V[i] =false;
    }
    sort(B, B+n);
    for(int i=0;i<n;i++) T[B[i]] = i;
    for(int i=0;i<n;i++){
        if(V[i]) continue;
        int cur = i;
        int S = 0;
        int m = VMAX;
        int an = 0;
        while(1){
            V[cur] = true;
            an++;
            int v = A[cur];
            m = min(m,v);
            S += v;
            cur = T[v];
            if(V[cur]) break;
        }
        ans += min(S+(an-2)*m,m+S+(an+1)*s);
    }
 
    return ans;
}
 
int main(){
    cin >> n;
    s = VMAX;
    for(int i=0;i<n;i++){
        cin >> A[i];
        s = min(s,A[i]);
    }
    int ans = solve();
    cout << ans << endl;
 
    return 0;
}

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

int main() {
  int a,b;
  cin >> a >> b;
  if(a>8||b>8){
    cout << ":(" << endl;
  }else{
    cout << "Yay!" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
s = input()
K = int(input())
alphabet = "abcdefghijklmnopqrstuvwxyz"
for alp in alphabet:
    if alp not in s:
        continue
    sub = set()
    for i,S in enumerate(s):
        if S == alp:
            for j in range(i,min(i+5,len(s))):
                sub.add(s[i:j+1])
    if len(sub) < K:
        K -= len(sub)
    else:
        l_sub = list(sub)
        l_sub.sort()
        print(l_sub[K-1])
        exit()


Measured memory_bytes: 3060
while True:
    n,x = map(int,input().split())
    c = 0
    if n == 0 and x ==0:
        break
    for i in range(1,n+1):
        for j in range(1,n+1):
            for k in range(1,n+1):
                if i > j and j > k :
                    if i + j + k == x:
                        
                        c += 1
    print(c)


Measured memory_bytes: 5592
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>

using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)

signed main(){
    int sx,sy,tx,ty;cin>>sx>>sy>>tx>>ty;
    string s;
    rep(i,tx-sx){
        s+='R';
    }
    rep(i,ty-sy){
        s+='U';
    }
    rep(i,tx-sx){
        s+='L';
    }
    rep(i,ty-sy){
        s+='D';
    }
    s+='D';
    rep(i,tx-sx+1){
        s+='R';
    }
    rep(i,ty-sy+1){
        s+='U';
    }
    s+='L';
    s+='U';
    rep(i,tx-sx+1){
        s+='L';
    }
    rep(i,ty-sy+1){
        s+='D';
    }
    s+='R';
    cout<<s<<endl;
    return 0;
}

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

using namespace std;

string S;
string pattern[4] = {"dream", "dreamer", "erase", "eraser"};

int main()
{
  cin >> S;

  // Reverse string to serach from end of strings
  std::reverse(S.begin(), S.end());
  for(size_t i = 0; i < 4; ++i)
    std::reverse(pattern[i].begin(), pattern[i].end());

  bool can = true;
  
  for(int i = 0; i < S.length();) {
    bool can2 = false;
    for(size_t j = 0; j < 4; ++j) {
      string p = pattern[j];
      if(S.substr(i, p.size()) == p) {
        can2 = true;
        i += p.size();
      }
    }
    if(!can2) {
      can = false;
      break;
    }
  }

  if(can) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}

Measured memory_bytes: 512
#include <iostream>
using namespace std;
int main(void){
    int a,b;
    cin >> a >> b;
    if(a>b){
        cout << "a > b" << endl;
    }
    else if(a<b){
        cout << "a < b" << endl;
    }
    else{
        cout << "a == b" << endl;
    }
}



Measured memory_bytes: 3092
import java.util.Arrays;
import java.util.Scanner;

class Main {
	public static void main(String[] args) throws Exception {
		new Main().run();
	}
	
	void run() {
		Scanner sc=new Scanner(System.in);
		int a=sc.nextInt();
		int b=sc.nextInt();
		int c=sc.nextInt();
		int d=sc.nextInt();
		int L=a+b;
		int R=c+d;
		System.out.println(L>R?"Left":L==R?"Balanced":"Right");
	}
	
	static void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
	
}


Measured memory_bytes: 23892
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Scanner;

public class Main {
	public static class Edge {
		int e1, e2;
		public Edge (int e1, int e2) {
			this.e1 = e1;
			this.e2 = e2;
		}
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int m = Integer.parseInt(sc.next());
		Edge[] c = new Edge[m];
		int ans = 0;
		for (int i = 0; i < m; i++)
			c[i] = new Edge(Integer.parseInt(sc.next()), Integer.parseInt(sc.next()));
		for (int i = 0; i < m; i++) {
			Edge[] d = new Edge[m - 1];
			for (int j = 0; j < i; j++)
				d[j] = c[j];
			for (int j = i; j < m - 1; j++)
				d[j] = c[j + 1];
			ans += search(n, d);
		}
		System.out.println(ans);
	}

	public static int search(int n, Edge[] d) {
		int[] already = new int[n + 1];
		Deque<Integer> p = new ArrayDeque<Integer>();
		already[d[0].e1] = 1;
		p.push(d[0].e1);
		int count = 1;
		while(!p.isEmpty()) {
			int here = p.pop();
			for (int i = 0; i < d.length; i++) {
				if (d[i].e1 == here && already[d[i].e2] != 1) {
					already[d[i].e2] = 1;
					p.push(d[i].e2);
					count++;
				}
				else if (d[i].e2 == here && already[d[i].e1] != 1) {
					already[d[i].e1] = 1;
					p.push(d[i].e1);
					count++;
				}
			}
		}
		if (count == n)
			return 0;
		else
			return 1;
	}
}

Measured memory_bytes: 23892
#include <stdio.h>

int main(void)
{
    int n, i, j,total = 0;
    scanf("%d", &n);

    for (i = 0; (4 * i) <= n; i++)
    {
        for (j = 0; ((7 * j) <= n); j++)
        {
            total = (4 * i) + (7 * j);
            if (total == n) goto yes;
        }
    }

    printf ("No");
    return (0);

    yes:
        printf("Yes");
        return (0);
}


Measured memory_bytes: 128
import java.io.IOException;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws NumberFormatException, IOException {
		int A,B;
		Scanner sc=new Scanner(System.in);
		A=sc.nextInt();
		B=sc.nextInt();
		int ans=A-2*B;
		if(ans<=0)
			System.out.println(0);
		else
			System.out.println(ans);
	}

}


Measured memory_bytes: 22996
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair <int, int> P;

int main() {
	int n;
	cin >> n;
	vector <int> x(n);
	int max = 0;
	int mini = 99999999;
	for(int i = 0; i < n; i++) {
		cin >> x[i];
		if (max < x[i]) max = x[i];
		if (mini > x[i]) mini = x[i];
	}
	// cout << "max = " << max << endl;
	// cout << "mini = " << mini << endl;
	int value = 0;
	int ans = 99999999;
	for (int j = mini; j <= max; j++) {
		int value = 0;
		for (int i = 0; i < n; i++) {	
			value = value + (x[i] - j) * (x[i] - j);
		}
		// cout << "value = " << value << endl;
		ans = min(ans, value);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <numeric>
#include <algorithm>
#include <vector>
#include <array>
#include <string>
#include <queue>
#include <cmath>
#include <iterator>
#include <math.h>
#include <cstdio>
#include <map>
#include <set>
#include <unordered_map>
#include <sstream>
#include <tuple>

using namespace std;
using lli = long long int;
using ulli = unsigned long long int;

namespace atcoder{
    void judge_outer(bool judge_exp,string ok = "Yes",string ng = "No"){
        if(judge_exp){
            cout << ok << endl;
        }else{
            cout << ng << endl;
        }
    }
}

using namespace atcoder;


int main(void){
    int n,m,x,stk;
    cin >> n >> m >> x;
    vector<int> A(n+1);
    for(int i=0;i<=n;i++)A[i] = 0;
    for(int i=0;i<m;i++){
        cin >>stk;
        A[stk] = 1;
    }
    int up=0;
    int down = 0;
    for(int i=x;i>=0;i--){
        down+=A[i];
    }
    
    for(int i=x;i<=n;i++){
        up+=A[i];
    }
    cout << min(up,down) << endl;
    return 0;
}


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

using namespace std;

int main(){
	int n,ans = 100000;
	cin >> n;
	vector<int> v(n);
	for(int i=0;i<n;++i) cin >> v[i];

	int temp = 0;

	for(int i=0;i<n;++i){
		temp+=v[i];
		int xd = 0;
		for(int j=i+1;j<n;++j){
			xd+=v[j];
		}
		ans = min(ans,abs(xd-temp));
	}

	cout << ans << '\n';

	return 0;
}

Measured memory_bytes: 256
h, w, k = map(int, input().split())
S = [list(map(int, list(input()))) for _ in range(h)]

ans = 10 ** 9
# Hが10なので横の割り方は決め打ち、縦は貪欲にKを見る。最小の数が答え。

for i in range(2 ** (h - 1)):
  # box: 割った後の各かたまりの白チョコ数を入れる箱
  box = [[0] * w]
  # bcnt: 横に割ったかたまりの番地を数える数
  bcnt = 0
  box[bcnt] = [s + b for s, b in zip(S[0], box[bcnt])]

  for j in range(1, h):
    if (i >> (j-1)) & 1:
      bcnt += 1
      box.append([0] * w)
    box[bcnt] = [s + b for s, b in zip(S[j], box[bcnt])]
  
  # kよりも大きな区間が一つでもあればNG
  if not all([all([i <= k for i in b]) for b in box]):
    continue

  # cutcnt: 分割回数。最小値がansとなる。
  cutcnt = len(box) - 1
  # cnt: そのかたまりでのホワイトチョコの数を数える箱。毎回更新する。（直近分しか保持しない）
  cnt = [0] * len(box)
  for m in range(w):
    for n in range(len(box)):
      cnt[n] += box[n][m]
    # 一つでもkを超えたら縦に割る。
    if any([c > k for c in cnt]):
      cutcnt += 1
      for n in range(len(box)):
        cnt[n] = box[n][m]
  ans = min(ans, cutcnt)

print(ans)
 

Measured memory_bytes: 55260
import math

def isPrime(n):
    m = (n + 1) // 2
    n_sqrt = int(math.sqrt(n))
    for i in range(2, n_sqrt + 1):
        if n % i == 0 or m % i == 0:
            return 0
    return 1

Q = int(input())
MAX = 10 ** 5 + 1
prime = [0] * MAX
for i in range(3, MAX):
    prime[i] = prime[i-1] + isPrime(i)
ans = []
for _ in range(Q):
    l, r = map(int, input().split())
    ans.append(prime[r] - prime[l-1])
for a in ans:
    print(a)


Measured memory_bytes: 10764
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pi;
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);
#define f first
#define s second

const int maxn = 200010;
#define all(x) x.begin(),x.end()

#define ld long double

int n, q;
vector <int> adjlist[maxn];
int co[maxn];
int v[maxn];

void dfs(int x, int p) {
	v[x] += co[x];
	
	for (auto i: adjlist[x]) {
		if (i == p) continue;
		v[i] += v[x];
		dfs(i,x);
	}
}


int main() {
	cin >> n >> q;
	for (int i =0;i<n-1;i++) {
		int a,b; cin >> a >> b;
		adjlist[a].push_back(b);
		adjlist[b].push_back(a);
	}
	
	for (int i =0;i<q;i++) {
		int x, v; cin >> x >> v;
		co[x] += v;
	}
	
	dfs(1,-1);
	for (int i =1;i<=n;i++) {
		cout << v[i] << " ";
	}
	
}



Measured memory_bytes: 28564
#include<bits/stdc++.h>
using namespace std;
#define speed() ios::sync_with_stdio(0);cin.tie(0);
#define ll long long int
int main ( )
{

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

        cin>>aa[i] ;

    }
    for(int i=0; i <a; i++)
    {
        for(int j=i+1; j<a; j++)
        {
            for(int k = j+1; k<a; k++)
            {
                if (aa[i] + aa[j] > aa[k] && aa[i]+aa[k]>aa[j] && aa[j]+aa[k]>aa[i]
                        && aa[i]!= aa[j] && aa[j] != aa[k] && aa[i] != aa[k] )


                    ans++;
                }
            }

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



Measured memory_bytes: 3592
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define pi 3.141592653589793238
#define int long long
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;


signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);  
    cout.tie(0);   
#ifndef ONLINE_JUDGE
    if(fopen("INPUT.txt","r"))
    {
    freopen ("INPUT.txt" , "r" , stdin);
    freopen ("OUTPUT.txt" , "w" , stdout);
    }
#endif

// -------------------------------------Code starts here---------------------------------------------------------------------     

  int r;
  cin>>r;
  long double ans=2*pi*r;
  cout<<fixed<<setprecision(5);
  cout<<ans;  

// -------------------------------------Code ends here------------------------------------------------------------------
    clock_t clk;
  clk = clock();

    clk = clock() - clk;
  cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << "\n";
  return 0;
}


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

int main(){
  string S,T;
  cin >> S >> T;

  bool ok = false;


  for(int i = 0; i < S.size(); i++){
    if(S == T) ok = true;
    S = S.back() + S.substr(0,S.size() - 1);
  }
  if(ok){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

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

from collections import Counter
dic = dict(Counter(A))
ls = list(dic.items())
ls.sort(key=lambda x: x[1])

uniq = len(ls)
i = 0
ans = 0
while 1:
    if uniq <= K or i >= N:
        break
    ans += ls[i][1]
    i += 1
    uniq -= 1

print(ans)

Measured memory_bytes: 158208
import sys
import  math
import fractions
from collections import defaultdict
import heapq
from bisect import bisect_left,bisect

stdin = sys.stdin
     
ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

N,K=nm()
A=nl()
l=0
r=10**9
mid=0

if(K==0):
    print(max(A))
    sys.exit(0)

while(l+1<r):
    mid=(l+r)//2
    tmp=0
    for i in range(len(A)):
        tmp+=((A[i]-1)//mid)
    if(tmp<=K):
        r=mid
    else:
        l=mid

print(r)

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

int main() {
  string S;
  cin >> S;
  int result = 0;
  if (S.at(0) == 'R') {
    result++;
  }
  if (S.at(1) == 'R') {
    result++;
  }
  if (S.at(2) == 'R') {
    if (S.at(1) == 'R') {
      result++;
    }
    else {
      result = 1;
    }
  }
  cout << result << endl;
  return 0;
}

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

        int main() {
          ll N;
          cin>> N ; 
		  ll s[N], t[N];
          
          for(ll i=0; i<N; i++){
            cin >> s[i];
          }

         for(ll i=0; i<N; i++){
            t[i] = s[i] + s[N-1-i];
         }
         
         ll answer = -80000000000;  
         // C=A-B 
         for(ll C=1; C<N; C++){
           ll S=0;
           ll temp =0; 
           for(ll j=1; j < (N-1)/C; j++ ){
             temp += C;
             S+= t[temp]; 
             ll A = N-1 -temp; 
             if(A>C){
               if(A%C!=0) answer = max( S, answer ); 
               if(A%C==0 && A>(N-1)/2) answer = max( S, answer ); 
             }
           }
         }  
         if (answer <0 ) answer =0;   
         cout << answer;  
        }

Measured memory_bytes: 1792
N = int(input())
S = input()
W=[0]*(N+1)
E=[0]*(N+1)
a=0
b=0
for i in range(N):
  if S[i]=='W':
    a+=1
  else:
    b+=1
  W[i+1]=a
  E[i+1]=b

ans = float('inf')
for i in range(1,N+1):
    ans = min(W[i-1] + E[N]-E[i],ans)
print(ans)

Measured memory_bytes: 84072
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <sstream>
#include <stdio.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <list>
#include <numeric>
#include <stack>
#include <iomanip>

using namespace std;

#define Rep(i,a,b) for(int i = a; i < b; i++)
#define rep(i,b) Rep(i,0,b)
#define allof(a) (a).begin(), (a).end()

typedef long long ll;
const int inf = 1e9 + 7;
const ll infll = 1ll << 60ll;
const ll mod = 1e9 + 7;
// 0~3までは右左下上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
constexpr int dy[] = { 0, -1, 0, 1, 1, -1, -1, 1 };

template<typename T> void chmax(T &a, T b) { a = std::max(a, b); }
template<typename T> void chmin(T &a, T b) { a = std::min(a, b); }
template<typename T> void chadd(T &a, T b) { a = a + b; }

namespace {  // 名前なし名前空間
	// gcd, lcm は C++17 でstdに標準入りしたので言語のバージョンに注意
	// 最大公約数
	ll gcd(ll a, ll b) {
		if (b == 0) return a;
		return gcd(b, a % b);
	}

	// 最小公倍数
	ll lcm(ll a, ll b) {
		return a / gcd(a, b) * b;
	}
}

int main() {

	int n;
	cin >> n;
	vector<vector<int>> a(n, vector<int>(n - 1));
	rep(i, n)rep(j, n - 1) {
		int tmp; cin >> tmp; a[i][j] = tmp - 1;
	}

	vector<int> mNum(n, 0);
	int sum = 0;
	int ans = 0;

	vector<bool> used(n, false);
	int dest = n * (n - 1);

	queue<int> que;
	rep(i, n) que.push(i);
	int prevMoveNum = n;

	while (sum != dest) {
		int moveNum = 0;
		rep(i, n) used[i] = (mNum[i] == n - 1);
		rep(i, prevMoveNum) {
			int p = que.front(); que.pop();
			if (used[p]) continue;
			int op = a[p][mNum[p]];
			if (used[op])continue;

			if (a[op][mNum[op]] != p) continue;

			mNum[p]++; mNum[op]++;
			used[p] = used[op] = true;
			moveNum += 2;
			que.push(p); que.push(op);
		}

		if (!moveNum) {
			ans = -1;
			break;
		}
		prevMoveNum = moveNum;
		ans++;
		sum += moveNum;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 4224
#include <iostream>
#include <cstdio>

int gcd(int x, int y){
	int r;
	while( (r = x%y) != 0){
		x=y;
		y=r;
	}

	return y;
	
}

long lcm(int x, int y){
	return (long)x*y/gcd(x,y);
}

int main(){
	while(1){
		int a[3], m[3], p[3], memo[3], flag[3]={0};

		for(int i=0; i<3; ++i)
			scanf(" %d %d", &a[i], &m[i]);
	
		if(a[0]==0 && m[0]==0) break;

		for(int i=0; i<3; ++i)
			p[i] = a[i]%m[i];
		long count=1;
		int mcount=0;
		
		while(1){
			for(int i=0; i<3; ++i){
				if(p[i]==1 && flag[i]==0){
					memo[i]=count;
					flag[i]=1;
					++mcount;
					//printf("mmm\n");
				}
			}
			
			if(mcount==3) break;
		
			for(int i=0; i<3; ++i)
				p[i] = (a[i]*p[i]) % m[i];
			
			++count;
		}
		
		long tmp = lcm(memo[0], memo[1]);
		long ans = lcm(memo[2], tmp);
		
		printf("%ld\n", ans);	
	}

	return 0;
}

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


	

int main(){
	
	int a,b,i,j,x,y;
	int meiro[120][120];
	int map[120][120];
	queue<int> que;
	
	while(1){
	
		
		cin >> a >> b ;
		
		if(a==0&&b==0) return 0;
		
		
		for(i=0;i<100;i++){
			for(j=0;j<100;j++){
				map[i][j] = 0;
				meiro[i][j]=1;
			}
		}
		
		
		for(i=0;i<2*b-1;i++){
			
			if(i%2 == 0){
				for(j=0;j<a-1;j++){
					cin >> meiro[i][j];
				}
			}
			else {
				for(j=0;j<a;j++){
					cin >> meiro[i][j];
				}
			}
		}
		
		map[0][0] = 1;
		que.push(0);
		que.push(0);
		
		while(que.size()>0){
	
			
			x = que.front();
			que.pop();
			y = que.front();
			que.pop();
			
			//右へいけるか
			if(map[x][y+1]==0 && meiro[2*x][y]==0 && y<a-1) {
				map[x][y+1]=map[x][y]+1;
				que.push(x);
				que.push(y+1);
			}
			//下へいけるか
			if(map[x+1][y]==0 && meiro[2*x+1][y]==0 && x<b-1) {
				map[x+1][y]=map[x][y]+1;
				que.push(x+1);
				que.push(y);
			}
			//左へいけるか
			if(map[x][y-1]==0 && meiro[2*x][y-1]==0 && y>0) {
				map[x][y-1]=map[x][y]+1;
				que.push(x);
				que.push(y-1);
			}
			//上へいけるか
			if(map[x-1][y]==0 && meiro[2*x-1][y]==0 && x>0) {
				map[x-1][y]=map[x][y]+1;
				que.push(x-1);
				que.push(y);
			}
			
			
		}
		
		
		cout << map[b-1][a-1]<< endl;
	
	
	}
	
	
	
	
}

Measured memory_bytes: 1316
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
int a[5][5];
bool vis[5][5];
int n,x;
inline void read(int &x)
{
	int f;char c;
	for (f=1,c=getchar();c<'0'||c>'9';c=getchar()) if(c=='-') f=-1;
	for (x=0;c<='9'&&c>='0';c=getchar()) x=x*10+(c&15);x*=f;
}
inline int mn(int _x,int _y)
{
	return _x<_y?_x:_y;
}
inline int mx(int _x,int _y)
{
	return _x>_y?_x:_y;
}
inline int ab(int _x)
{
	if(_x<0) return -_x;
	else return _x;
}
inline bool check()
{
	for(int i=1;i<=3;i++)
		if(vis[i][1]&&vis[i][2]&&vis[i][3]) return true;
	for(int i=1;i<=3;i++)
		if(vis[1][i]&&vis[2][i]&&vis[3][i]) return true;
	if(vis[1][1]&&vis[2][2]&&vis[3][3]) return true;
	if(vis[1][3]&&vis[2][2]&&vis[3][1]) return true;
	return false;
}
int main()
{
	for(int i=1;i<=3;i++)
		for(int j=1;j<=3;j++)
			read(a[i][j]);
	read(n);
	while(n--)
	{
		read(x);
		bool ok=true;
		for(int i=1;i<=3&&ok;i++)
			for(int j=1;j<=3;j++)
				if(a[i][j]==x&&(!vis[i][j]))
					vis[i][j]=true;
	}
	if(check()) printf("Yes\n");
	else printf("No\n");
	return 0;
}



Measured memory_bytes: 256
# coding: utf-8
# Your code here!
n = int(input())
l = list(map(int,input().split()))

count = 0
for i in range(n - 2):
    if (l[i] <= l[i + 1] and l[i + 1] <= l[i + 2]) or (l[i + 2] <= l[i + 1] and l[i + 1] <= l[i]):
        count += 1

print(count)

Measured memory_bytes: 38256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0;i < (int)(n);i++)
using ll = long long;
const ll MOD=1000000007;
//const ll MOD=998244353;
const long long INF = 1LL << 60;
const double pi=acos(-1.0);

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; }



int main()
{
  ll N,M; cin>>N>>M;
  vector<ll> A(N); rep(i,N) cin>>A[i];
  
  map<ll,ll> mp; rep(i,N) mp[A[i]]++;
  rep(i,M){
    ll a,num; tie(a,num)=*rbegin(mp);
    num--; if(num==0) mp.erase(a); else mp[a]--;
    mp[a/2]++;
  }
  
  ll ans=0;
  for(auto p:mp){
    ll a,num; tie(a,num)=p;
    ans+=a*num;
  }
  
  cout<<ans<<endl;
    
  return 0;
}

Measured memory_bytes: 10336
package main

import (
	"fmt"
)

func main() {
	var a,b,c,x int
	fmt.Scan(&a,&b,&c,&x)
	count := 0
	for i := 0; i < a + 1; i++ {
		for j := 0; j < b + 1; j++ {
			for k := 0; k < c + 1; k++ {
				if x == 500*i + 100*j + 50*k {
					count++
				}
			}
		}
	}
	fmt.Println(count)
}

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

typedef long long ll;

const int N = 1e5;

ll n,m;
ll li[N+5];
ll ps[N+5];

bool cek(int x){
	ll ret = 0;
	for(int i=1;i<=n;i++){
		ll tar = x - li[i];
		if(tar <= 0){
			ret += n;
			continue;
		}
		int l = 1;
		int r = n;
		int ans = n+1;
		while(l<=r){
			int mid = (l+r)/2;
			if(li[mid] >= tar){
				ans = mid;
				r = mid-1;
			} else {
				l = mid+1;
			}
		}
		ret += (n-ans+1);
	}
	return ret >= m;
}

int main(){
	scanf("%lld%lld",&n,&m);
	for(int i=1;i<=n;i++){
		scanf("%lld",&li[i]);
	}
	sort(li+1,li+n+1);
	for(int i=1;i<=n;i++){
		ps[i] = ps[i-1] + (ll) (li[i]);
	}
	int l = 0;
	int r = 2e5;
	int ans = r+1;
	while(l<=r){
		int mid = (l+r)/2;
		if(cek(mid)){
			ans = mid;
			l = mid+1;
		} else {
			r = mid-1;
		}
	}
	ll cnt = 0;
	ll total = 0;
	for(int i=1;i<=n;i++){
		ll tar = ans - li[i];
		if(tar <= 0) {
			total += n*li[i];
			total += ps[n];
			cnt+=n;
			continue;
		}
		int a = 1;
		int b = n;
		int c = n+1;
		while(a<=b){
			int mid = (a+b)/2;
			if(li[mid] >= tar){
				c = mid;
				b = mid-1;
			} else {
				a = mid+1;
			}
		}
		total += (n-c+1)*li[i];
		total += ps[n] - ps[c-1];
		cnt += (n-c+1);
	}
	total -= (cnt-m)*(ans);
	printf("%lld\n",total);
	return 0;
}


Measured memory_bytes: 1792
#define _CRT_SECURE_NO_WARNINGS

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <array>
#include <cassert>
#include <bitset>
using namespace std;
using LL = long long;


int N;
vector<LL>X, Y;

int main() {
	cin >> N;
	for (int i = 0; i < N; ++i) {
		LL x, y;
		cin >> x >> y;
		X.push_back(x);
		Y.push_back(y);
	}
	map<pair<LL, LL>, int>mp;
	for (int i = 0; i < N; ++i) {
		for (int j = 0; j < N; ++j) {
			if (i == j)continue;
			mp[{X[i] - X[j], Y[i] - Y[j]}]++;
		}
	}
	int big = 0;
	for (auto p : mp) {
		big = max(big, p.second);
	}
	cout << N - big << endl;
	return 0;
}

Measured memory_bytes: 384
/* C++14 (Clang 3.8.0) for AtCoder */

#include <iostream>
#include <vector>
#include <string>
// #include <cmath>
// #include <math.h>
// #include <map>
// #include <algorithm>

namespace AtCoder {
	using Str = std::vector<std::string>;
	using Num = std::vector<int>;

	class Ans {
	public:
		void showResult(void);
		void increment(void);
		void increment(double);
		void decrement(void);
		void decrement(double);
		double getResult(void);
	private:
		double result;
	};
	void Ans::showResult(void) {
		printf("%.0lf\n", this->result);
	}
	void AtCoder::Ans::increment(void) {
		this->result++;
	}
	void AtCoder::Ans::increment(double value) {
		this->result += value;
	}
	void AtCoder::Ans::decrement(void) {
		this->result--;
	}
	void AtCoder::Ans::decrement(double value) {
		this->result -= value;
	}
	double AtCoder::Ans::getResult(void) {
		return this->result;
	}

	void input(Str* str) {
		str->clear();
		std::string buf = "", row = "";
		std::getline(std::cin, buf);
		for (unsigned int i = 0; i < buf.size(); i++) {
			if (' ' == buf[i]) {
				str->push_back(row);
				row = "";
			} else {
				row += buf[i];
			}
		}
		str->push_back(row);
	}
	void input(Num* num) {
		num->clear();
		std::string buf = "", row = "";
		std::getline(std::cin, buf);
		for (unsigned int i = 0; i < buf.size(); i++) {
			if (' ' == buf[i]) {
				num->push_back(std::atoi(row.c_str()));
				row = "";
			} else {
				row += buf[i];
			}
		}
		num->push_back(std::atoi(row.c_str()));
	}
	void exp(std::string* str,  Str* newStr) {
		std::string pre = *str;
		newStr->clear();
		for (unsigned int i = 0; i < pre.length(); i++) {
			newStr->push_back(pre.substr(i, 1));
		}
	}
}

int main(void) {

	AtCoder::Str s, t;
	AtCoder::input(&s);
	AtCoder::input(&t);

	AtCoder::exp(&s[0], &s);
	AtCoder::exp(&t[0], &t);

	AtCoder::Ans* ans = new AtCoder::Ans();

	for (int i = 0; i < 3; i++) {
		if (s[i] == t[i]) {
			ans->increment();
		}
	}

	ans->showResult();

	delete(ans);

	return 0;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n, m;
    using ll = long long;
    cin >> n >> m;
    vector<ll> vx(n);
    vector<ll> vy(n);
    vector<ll> vz(n);
    for(int i = 0; i < n; i++)
    {
        cin >> vx[i] >> vy[i] >> vz[i];
    }

    vector<ll> d = {1, -1};
    ll ans = 0;
    for(int i = 0; i < 2; i++)
    {
        for(int j = 0; j < 2; j++)
        {
            for(int k = 0; k < 2; k++)
            {
                vector<ll> tmp;
                for(int a = 0; a < n; a++)
                {
                    tmp.push_back(vx[a] * d[i] + vy[a] * d[j] + vz[a] * d[k]);
                }
                sort(tmp.begin(), tmp.end());
                reverse(tmp.begin(), tmp.end());
                ll tmpans = 0;
                for(int a = 0; a < m; a++)
                {
                    tmpans += tmp[a];
                }
                ans = max(ans, tmpans);
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define mFOR(i, a, b) for (int i = a; i > b; i--)
#define MP make_pair
#define PB push_back
#define ALL(v) v.begin(), v.end()
#define N 100007
#define INF 1000000007
using namespace std;

typedef long long ll;

ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll fceil(ll a, ll b) { return (a % b == 0 ? a / b : a / b + 1); }
int main()
{
   int a[3][3] = {}, n, b;
   FOR(i, 0, 3)
   FOR(j, 0, 3)
   cin >> a[i][j];
   cin >> n;
   FOR(k, 0, n)
   {
      cin >> b;
      FOR(i, 0, 3)
         FOR(j, 0, 3)
         {
            if (a[i][j] == b)
               a[i][j] = 0;
         }
   }
   
   bool flag = true;
   FOR(i,0,3)
   {
      flag = true;
      FOR(j,0,3)
      {
         if(a[i][j]!=0)
         {
            flag = false;
            break;
         }
      }
      if(flag == true)
      {
         cout << "Yes\n";
         return 0;
      }
   }
   FOR(i,0,3)
   {
      flag = true;
      FOR(j,0,3)
      {
         if(a[j][i]!=0)
         {
            flag = false;
            break;
         }
      }
      if(flag == true)
      {
         cout << "Yes\n";
         return 0;
      }
   }
   flag = true;
   FOR(i,0,3)
   {
      if(a[i][i]!=0)
      {
         flag = false;
         break;
      }
   }
   if(flag == true)
   {
      cout << "Yes\n";
      return 0;
   }
   flag = true;
   FOR(i,0,3)
   {
      if(a[2-i][i]!=0)
      {
         flag = false;
         break;
      }
   }
   if(flag == true)
   {
      cout << "Yes\n";
      return 0;
   }

   cout << "No\n";
   return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;

class Main{
    public static void main(String[] args) throws Exception {
        BufferedReader buffer = new BufferedReader(new InputStreamReader(System.in));
        StringBuilder sb = new StringBuilder();
        long n = Integer.parseInt(buffer.readLine());
        long sum = n + n*n + n*n*n;
        sb.append(sum);
        System.out.println(sb);
    }
}


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

int main(){
  vector<int> vec(3);

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

  sort(vec.begin(), vec.end());
  
  cout << vec[0] << " " << vec[1] << " " << vec[2] << endl;

  return 0;
}


Measured memory_bytes: 3140
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fu(i,r,t) for(int i=r;i<=t;i++)
#define fd(i,r,t) for(int i=r;i>=t;i--)
#define Set set<int>
#define int long long
#define P pair<int,int>
const int maxn = 1e6+5;
const int INF = 1e17 +6;
using namespace std;
int n,m,a[maxn],b[maxn],ans;
int32_t main()
{
    IOS;
    string k;
    cin>>k;
    int len=k.length();
    int ji=0;
    fu(i,0,len-1)
    {
        if(k[i]=='A')
        {
            ji++;
        }else if(k[i]=='B' && k[i+1]=='C')
        {
            ans+=ji;
            i++;
        }else ji=0;
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 720
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskX solver = new TaskX();
		solver.solve(1, in, out);
		out.close();
	}

	static int INF = 1 << 30;
	static int modP = 1000000007;

	static class TaskX {
		public void solve(int testNumber, InputReader in, PrintWriter out) {

			int a = in.nextInt(), b = in.nextInt(), c = in.nextInt();
			if (a == b) {
				out.println(c);
			} else if (b == c) {
				out.println(a);
			} else if (c == a) {
				out.println(b);
			}

		}
	}

	static class InputReader {
		BufferedReader in;
		StringTokenizer tok;

		public String nextString() {
			while (!tok.hasMoreTokens()) {
				try {
					tok = new StringTokenizer(in.readLine(), " ");
				} catch (IOException e) {
					throw new InputMismatchException();
				}
			}
			return tok.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(nextString());
		}

		public long nextLong() {
			return Long.parseLong(nextString());
		}

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

		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt();
			}
			return res;
		}

		public long[] nextLongArray(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong();
			}
			return res;
		}

		public InputReader(InputStream inputStream) {
			in = new BufferedReader(new InputStreamReader(inputStream));
			tok = new StringTokenizer("");
		}

	}

}


Measured memory_bytes: 21332
package main

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

var sc = bufio.NewScanner(os.Stdin)

func scanInt() int {
	sc.Scan()
	iv, _ := strconv.Atoi(sc.Text())
	return iv
}

func init() {
	sc.Split(bufio.ScanWords)
}

func main() {
	n := scanInt()
	cnt := 0
	for i := 0; i < n; i++ {
		a := scanInt()
		if a%2 == 1 {
			cnt++
		}
	}
	if cnt%2 == 0 {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}


Measured memory_bytes: 2176
#include<iostream>
#include<vector>
#include<bits/stdc++.h>
using namespace std;
int main(){
	long long int n,temp,answer=0,temper=0;
	vector<int> a;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>temp;
		a.push_back(temp);
	}
	for(int i=0;i<n-1;i++){
		if(a[i]>a[i+1]){
			temper=a[i]-a[i+1];
			answer+=temper;
			a[i+1]+=temper;
			temper=0;
		}
	}
	cout<<answer;
	return 0;
}

Measured memory_bytes: 4264
#include<stdio.h>

int main(void) {

	int width = 0;	scanf("%d", &width);
	int height = 0;	scanf("%d", &height);
	int centerX = 0;	scanf("%d", &centerX);
	int centerY = 0;	scanf("%d", &centerY);
	int radius = 0;	scanf("%d", &radius);

	if (((centerX + radius) <= width) && ((centerX - radius) >= 0) && ((centerY + radius) <= height) && ((centerY - radius) >= 0)) {
		printf("Yes\n");
	}
	else {
		printf("No\n");
	}

	return 0;
}


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

// {U}{INT,LONG,LLONG}_{MAX,MIN}
#define INF         INT_MAX/3
#define LLINF       LLONG_MAX/3
#define MOD         (1000000007LL)
#define MODA(a, b)  a=((a)+(b))%MOD
#define MODP(a, b)  a=((a)*(b))%MOD
#define inc(i, l, r)   for(int i=(l);i<(r);i++)
#define dec(i, l, r)   for(int i=(r)-1;i>=(l);i--)
#define pb          push_back
#define se          second
#define fi          first
#define mset(a, b)  memset(a, b, sizeof(a))

using LL  = long long;
using G   = vector<vector<int>>;

int di[] = {0, -1, 0, 1};
int dj[] = {1, 0, -1, 0};
// }}}

int main() {
    cin.tie(0);ios::sync_with_stdio(false);
    inc(i, 0, 3){
        string s;cin >> s;
        cout << s[i];
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
import math
S = list(input())
K = int(input())
s = S * 2
c1 = 0
c2 = 0
for i in range(len(s)-1):
    if s[i+1] == s[i]:
        if i < len(S)-1:
            c1 += 1
        c2 += 1
        s[i+1] = 0
c = S[0]
for s in S:
    if s != c:
        print(c1+(c2-c1)*(K-1))
        exit()
print(math.floor(len(S)*K/2))


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

int main(){
    int n,counter=1;
    cin >> n;
    vector<int> d(n);
    for(int i=0;i<n;i++) cin >> d.at(i);

    sort(d.begin(),d.end(),greater<int>());
    for(int i=0;i<n;i++){
        if(i == 0 || d.at(i) == d.at(i-1)) continue;
        counter++;
    }
    cout << counter << endl;
}


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

#define REP(i,n) for(int i=0; i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VC vector<char>
#define FOREACH(x,a) for(auto& (x) : (a) )
using namespace std;

int main() {
	int n, ans = 0;
	string s;
	cin >> n;
	cin >> s;
	for (int i = 1; i < n; i++) {
		int res = 0;
		for (char c = 'a'; c <= 'z'; c++) {
			bool a = false, b = false;
			REP(j, i) {
				if (s[j] == c) {
					a = true;
				}
			}
			for (int j = i; j < n; j++) {
				if (s[j] == c) {
					b = true;
				}
			}
			if (a&&b) {
				res++;
			}
		}
		ans = max(res, ans);
	}
	cout << ans << endl;
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
using P = pair<ll, ll>;
using V = vector<ll>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep1(i, n) for(ll i=1;i<=(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define INF 1000000000

void solve_abc() {
	string s;
	cin >> s;

	deque<char> ds(s.size());
	rep(i, s.size()){
		ds[i] = s[i];
	}

	ll q;
	cin >> q;

	ll t, f;
	char c;
	ll is_reversed = false;

	rep(i, q){
		cin >> t;
		if (t==1){
			is_reversed = !is_reversed;
		}
		else {
			cin >> f >> c;
			if (f==1){
				if (is_reversed){
					ds.push_back(c);
				}
				else{
					ds.push_front(c);
				}
			}
			else {
				if (is_reversed){
					ds.push_front(c);
				}
				else{
					ds.push_back(c);
				}
			}
		}
	}

	if (is_reversed){
		reverse(ds.begin(), ds.end());
	}

	rep(i, ds.size()){
		cout << ds[i];
	}

	cout << "\n";
}

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

	solve_abc();

	return 0;
}

Measured memory_bytes: 976
#include <bits/stdc++.h>
#define IO(i, o) freopen(i, "r", stdin), freopen(o, "w", stdout)

using namespace std;
int T, N, X, M[100];

int main(void){
	//IO("test.in", "test.out");
	scanf("%d%d", &N, &X);
	for(int i = 0; i < N; i++) scanf("%d", &M[i]), T++, X -= M[i];
	sort(M, M + N);
	printf("%d\n", T + X / M[0]);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std; inline void fileio(const char* in, const char* out) { freopen(in, "r", stdin); freopen(out, "w", stdout); }
#define TD typedef
#define forx(i,n) for(int i = 0; i < (n); ++i)
#define forxr(i,n) for(int i = (n)-1; i >= 0; --i)
TD long long ll; TD long double ld; TD pair<int,int> pii; TD pair<ll,ll> pll; TD vector<int> VI; TD vector<bool> VB; TD vector<ll> VL;
const char nl = '\n'; const int INF = 0x3f3f3f3f; const ll LINF = 0x3f3f3f3f3f3f3f3fll; const ld EPS = 1e-9, PI = acos(-1);
#define ff first
#define ss second
#define all(c) c.begin(),c.end()

const int N = 1 << 18;
int h[N], a[N], n;

ll t[2*N];
void update(int idx, ll val, int i=1, int s=0, int e=N) {
  const int l = idx, r = idx+1;
  if (r <= s || e <= l) return;
  if (s+1 == e) {
    t[i] = val;
    return;
  }
  int mid = (s+e)/2;
  update(idx, val, i*2, s, mid);
  update(idx, val, i*2+1, mid, e);
  t[i] = max(t[i*2], t[i*2+1]);
}

ll query(int l, int r, int i=1, int s=0, int e=N) {
  if (r <= s || e <= l) return 0;
  if (l <= s && e <= r) return t[i];
  int mid = (s+e)/2;
  return max(query(l, r, i*2, s, mid), query(l, r, i*2+1, mid, e));
}

int main() { // Emily <3
  atexit([](){ cerr << "Time: " << (ld)clock() / CLOCKS_PER_SEC << nl; });
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  cout << fixed << setprecision(12);
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> h[i];
  }
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  ll ans = 0;
  for (int i = 0; i < n; ++i) {
    const int hi = h[i], ai = a[i];
    ll mx = query(0, hi) + (ll)ai;
    ans = max(ans, mx);
    update(hi, mx);
  }
  cout << ans << nl;

  return 0;
}



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

#define REP(i, n) for(int (i)=0;(i)<(n);++(i))
#define REPV(iter, v) for(auto (iter)=(v).begin(); (iter)!=(v).end();++(iter))
#define ALL(v) (v).begin(),(v).end()

#define MOD 1000000007

using namespace std;

typedef long long ll;

int main()
{
    ll N;
    cin >> N;
    vector<ll> A(N), B(N);
    REP(i, N) cin >> A[i] >> B[i];

    ll ans = 0;
    ll prev = 0;
    for (ll i = N - 1; i >= 0; --i)
    {
        A[i] += prev;
        if (A[i] % B[i] != 0)
        {
            ans += B[i] - (A[i] % B[i]);
            prev += B[i] - (A[i] % B[i]);
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <cstdlib>
using namespace std;

int a[10], b[10];

int main()
{
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);

	for (int i = 0; i < 6; i++)
		scanf("%d", &a[i]);
	for (int i = 0; i < 6; i++)
		scanf("%d", &b[i]);


	double ans = 0;
	for (int id = 0; id < 6; id++)
	{
		if (a[id] + b[id] == 0) continue;
		for (int mask = 0; mask < 64; mask++)
		{
			double sum = 0;
			double res = 0;
			for (int i = 0; i < 6; i++)
			{
				if (id == i) continue;
				sum -= (a[i] + b[i]) * ((mask >> i) & 1) - b[i];
				res += a[i] * ((mask >> i) & 1);
			}
			sum += b[id];
			double q = a[id] + b[id];
			if (sum < 0 || sum > q) continue;
			double p = sum / q;
			res += a[id] * p;
			ans = max(ans, res / 100);
		}
	}
	printf("%.14lf\n", ans);

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
using namespace std;
int n,m,w,r,c;
int P[10010] = {0};
void init(int N){
	for(int i=0;i<=N;++i) P[i] = i;
}

int root(int a){
	if(P[a] == a) return a;
	return (P[a] = root(P[a]));
}

bool is_same_set(int a,int b){
	return root(a) == root(b);
}

void unite(int a, int b){
	P[root(a)] = root(b);
}


int main(){
	cin >> n >> m;
	init(n);
	//int M = 0;
	int cost[100010],src[100010],dst[100010];
	vector< pair<int,int> > edges;
	for(int i=0;i<m;i++){
		cin >> r >> c >> w;
		cost[i] = w;
		src[i] = r;
		dst[i] = c;
		pair<int,int> edge = make_pair(cost[i],i);
		edges.push_back(edge);
	}
	sort(edges.begin(),edges.end());
	long long  sum = 0;
	for(int i=0;i<m;i++){
		int n1 = src[edges[i].second],n2 = dst[edges[i].second];
		if(!is_same_set(n1,n2)){
			unite(n1,n2);
			sum += edges[i].first;
		}
	}
	cout << sum << endl;
}

#if 0
所要時間は45分程度。クラスカル法を回す部分の実装に少し苦戦した。
#endif 


Measured memory_bytes: 4696
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using pll = pair<long long,long long>;

bool isodd(const pll &p) { return (p.first + p.second) & 1; }
bool solve(vector<long long> &a) {
    int N = (int)a.size();
    sort(a.begin(), a.end(), greater<long long>());

    long long x = 0, y = a[0];
    vector<pll> ps;
    for (int i = 0; i < N; ++i) {
        if (a[i] != y) ps.push_back(pll(i-1, y)), y = a[i];
    }
    ps.push_back(pll(N-1, a[N-1]));
    if (ps.size() == 1) return isodd(ps[0]);
    for (auto p : ps) if (p.first == p.second) return false;
    
    for (int i = 0; i + 1 < ps.size(); ++i) {
        if (ps[i].first < ps[i].second && ps[i+1].first > ps[i+1].second) {
            if (ps[i].first < ps[i+1].second) return isodd(ps[i+1]);
            else if (ps[i].first > ps[i+1].second) return isodd(ps[i]);
            else return isodd(ps[i]) || isodd(ps[i+1]);
        }
    }
    if (ps[0].first > ps[0].second) return isodd(ps[0]);
    else return isodd(ps.back());
}

int main() {
    int N;
    while (cin >> N) {
        vector<long long> a(N);
        for (int i = 0; i < N; ++i) cin >> a[i], --a[i];

        if (solve(a)) cout << "First" << endl;
        else cout << "Second" << endl;
    }
}   


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

#define ll long long
#define INF 99999999
#define rep(i,n) for(int i=0,temp=(int)(n);i<temp;++i) 
#define repi(i,start,end) for(int i=start,temp=(int)(end);i<end;++i)
#define rfor(v,x) for(const auto& x : v) //xは値を表す
#define all(x) (x).begin(),(x).end()
#define SORT(v, n) sort(v, v+n)
#define vsort(v) sort(v.begin(), v.end())
#define vfsort(v,lambda) sort(v.begin(),v.end(),lambda)
#define vint vector<int>
#define vvint vector<vector<int>>
#define vin(v) rep(i,v.size()) {cin >> v[i];}
//最終奥義
//#define int long long
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int ctoi(char c) {return c-'0';}
//(lambda (x y) (< x y)) => [](int x, int y) -> int { return x<y; }

signed main(void){
  int a, b;cin >> a >> b;
  cout << max(a+b,max(a-b,a*b)) << endl;

}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm> //sort
#define endl '\n'
typedef long long ll;
using namespace std;
int n;
ll a,total;
priority_queue<ll>pq;
priority_queue<int>cq;

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

    cin>>n;
    for(int i=0;i<n;++i){
        cin>>a;
        pq.push(a);
    }
    total+=pq.top();
    pq.pop();
    if(n>2){
        n-=2;
        while(n){
            for(int i=0;i<2;++i){
                total+=pq.top();
                n--;
                if(!n) break;
            }
            pq.pop();
        }
    }
    cout<<total<<endl;
    return 0;
}


Measured memory_bytes: 4952
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();
		String n = sc.next();

		System.out.println(n.equals("Sunny") ? "Cloudy" : n.equals("Cloudy") ? "Rainy" : "Sunny");
	}
}

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: 22868
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Globalization;
using System.Diagnostics;
using System.Threading.Tasks;



class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().calc();
        return 0;
    }
    

    Scanner cin;

    void calc()
    {
        cin = new Scanner();
        int N = cin.nextInt();
        int A = cin.nextInt();
        if (N % 500 <= A) Console.WriteLine("Yes");
        else Console.WriteLine("No");
    }
}




class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}



Measured memory_bytes: 11092