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


/// File input & output /////
#define fRead(x)        freopen("x.txt","r",stdin)
#define fWrite(x)       freopen ("x.txt","w",stdout)

#define mt              make_tuple
#define ld              long double
#define ll              long long
#define ull             unsigned long long
#define ff              first
#define ss              second
#define pb              push_back
#define INF             2e16
#define PI              acos(-1.0)
#define mp              make_pair
#define pii             pair<int,int>
#define pll             pair<LL,LL>


#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(a,min(b,min(c,d)))
#define max4(a,b,c,d)   max(a,max(b,max(c,d)))
#define SQR(a)          ((a)*(a))
#define FOR(i,a,b)      for(int i=a;i<=b;i++)
#define ROF(i,a,b)      for(int i=a;i>=b;i--)
#define REP(i,b)        for(int i=0;i<b;i++)
#define MEM(a,x)        memset(a,x,sizeof(a))
#define ABS(x)          ((x)<0?-(x):(x))

#define SORT(v)         sort(v.begin(),v.end())
#define REV(v)          reverse(v.begin(),v.end())


#define FASTIO        ios_base::sync_with_stdio(0);cin.tie(nullptr);




///..................Sort by second element in a pair in decending order............. ///
bool SortbySecDesc(const pair<long long,long long > &a, const pair<long long,long long > &b)
{
    return a.second>b.second;
}

///.........................first element of pair in descending order..........................//////
bool sortinrev(const pair<int,int> &a,
               const pair<int,int> &b)
{
       return (a.first > b.first);
}



///.............................................................TEMPLATE................................................./////


//long long  Prime[3000000],nPrime;
//long long  mark[10000002];
//
//void seive(long long int n)
//{
//	long long int i,j,limit=sqrt(n*1.0)+2;
//	mark[1]=1;
//	for(i=4; i<=n ;i+=2)
//	mark[i]=1;
//	Prime[nPrime++]=2;
//	for(i=3; i<=n; i+=2)
//	{
//		if(!mark[i])
//		{
//			Prime[nPrime++]=i;
//			if(i<=limit)
//			{
//				for(j=i*i; j<=n ;j+=i*2)
//				{
//					mark[j]=1;
//				}
//			}
//		}
//	}
//}



ll v[10050];


int main()
{
    FASTIO;

    ll n;

    cin >> n;

    ll ans = 105;




        for(int j=1; j<=ans; j++)
        {
            for(int k=1; k<=ans; k++)
            {
                for(int l=1; l<=ans; l++)
                {
                    ll ans = (j*j) + (k*k) + (l*l) + (k*j) + (l*k) + (j*l);



                    if(ans<10050)
                    {
                        v[ans]+=1;

                    }
                }
            }
        }

        for(int i=1; i<=n; i++)
        {
            cout << v[i] << endl;

        }






    return 0;
}


Measured memory_bytes: 3684
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define rando mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define fi first
#define se second
#define debug(x) cerr << " - " << #x << ": " << x << endl;
#define debugs(x, y) cerr << " - " << #x << ": " << x << " " << #y << ": " << y << endl;
#define debugii(x) cerr << " - " << #x << ": " << x.fi<<","<<x.se << endl;
#define sep() cerr << "--------------------" << endl;
#define all(x) (x).begin(),(x).end()
#define sz(x) (ll)x.size()
#define ld long double
#define ll long long
//#define int ll
#define ii pair<int,int>
#define v vector<int>
#define vii vector<ii>
#define vv vector<vector<int> >
#define mp make_pair
#define INF 1000000000
#define pb push_back
#define EPS 1e-9
const int MOD = 1000000007; // 998244353
int fen[200005];
int n,ans=INF,cnt=0;
void update(int idx,int val){
	for (int i = idx; i <= n; i+=(i&(-i)))
		fen[i]+=val;
}
int get(int idx){
	int h=0;
	for (int i = idx; i >= 1; i-=(i&(-i)))
		h+=fen[i];
	return h;
}
int32_t main(){
	boost;
	//freopen(".in","r",stdin);
	cin>>n;
	string p;
	cin>>p;
	priority_queue<int,v,greater<int> > white;
	set<int,greater<int> > red;
	for (int i = 0; i < n; ++i)
	{
		if(p[i]=='W')white.push(i),update(i+1,1);
		else red.insert(i);

	}
	for (int i = n-1; i >= 0; i--)
	{
		ans=min(cnt+(sz(red)?get(*(red.begin())+1):0),ans);
		if(p[i]=='R' && sz(white)){
			int h=white.top();
			white.pop();
			red.erase(i);
			red.insert(h);
			update(h+1,-1);
			update(i+1,1);
			swap(p[h],p[i]);
			cnt++;
		}
	}
	cout<<ans<<"\n";
	return 0;
}

//do smth instead of nothing and stay organized
//long long
//array bounds
//special cases
//binary search

Measured memory_bytes: 12864
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<bitset>
#include<stack>
#include<memory>
using namespace std;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
/*
cout<<fixed<<setprecision(20);
cin.tie(0);
ios::sync_with_stdio(false);
*/
const llint mod=1000000007;
const llint big=2.19e15+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-15;
template <class T,class U>bool mineq(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool maxeq(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}
int main(void){
	cout<<fixed<<setprecision(20);
	cin.tie(0);
	ios::sync_with_stdio(false);
	double W,H,Ew,Eh,x,y;cin>>W>>H>>Ew>>Eh>>x>>y;
	//WとHはいらない
	//制約がくそげーすぎるだろ。引っかかった。
	if(x+Ew/2>=W/2){x-=(x+Ew/2-W/2)/2;}
	if(y+Eh/2>=H/2){y-=(y+Eh/2-H/2)/2;}
	cout<<y/x<<endl;
	return 0;
}


Measured memory_bytes: 3276
INF = float("inf")
def MAIN():
    n = int(input())
    M = [[INF] * 101 for _ in range(101)]
    for i in range(n):
        for j, e in enumerate(map(int, input().split())):
            if e != -1:
                M[i][j] = e
    def prim():
        d = [INF] * n
        t = [-1] * n
        color = [0] * n
        d[0] = 0
        while True:
            minv = INF
            u = -1
            for i in range(n):
                if minv > d[i] and color[i] != 2:
                    u = i
                    minv = d[i]
            if u == -1:
                break
            color[u] = 2
            for v in range(n):
                if color[v] != 2 and d[v] > M[u][v]:
                    d[v] = M[u][v]
                    t[v] = u
                    color[v] = 1
        return sum(d)
    print(prim())
MAIN()



Measured memory_bytes: 5768
<?php
//https://atcoder.jp/contests/abc139/submissions/7295556
//error_reporting(0);
$N = (int)trim(fgets(STDIN));
//list($A,$B) =  explode(" ",trim(fgets(STDIN)));
//$H = explode(" ",trim(fgets(STDIN)));




for($row=0;$row<$N;$row++) {
  $H = explode(" ",trim(fgets(STDIN)));
  for($col =0;$col<$N-1;$col++) {
    $A[$row][$col]=(int)$H[$col];
  }
}

$siain = 0;
$maxday = 0;

$sn = array_fill(0,1000,0);
$last = array_fill(0,1000,0);
    while(1)
    {
        $siai = false;
        for($i=0;$i<$N;$i++)
        {
            if($sn[$i]==$N-1) continue;
            // jと試合できるならする
            $j = $A[$i][$sn[$i]]-1;
            if($wait[$j][$i])
            {
                $sn[$i]++;
                $sn[$j]++;
                $day = max($last[$i],$last[$j])+1;
                $last[$i] = $day;
                $last[$j] = $day;
                $maxday = max($day, $maxday);
                $siai = true;
                $siain++;
                $i--;
            }else
            {
                $wait[$i][$j] = true;
            }
        }
        if(!$siai)
        {
            printf("-1\n");
            return 0;
        }
        if($siain>=($N*($N-1)/2)) break;
    }
    printf("%d\n",$maxday);

    return 0;




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

int main() {
  int n;
  cin >> n;
  vector<int> x(n), sorted_x(n);
  int i;
  for (i = 0; i < n; i++) {
    cin >> x[i];
    sorted_x[i] = x[i];
  }
  sort(sorted_x.begin(), sorted_x.end());
  int middle = n / 2;
  for (i = 0; i < n; i++) {
    if (sorted_x[middle] > x[i]) {
      cout << sorted_x[middle] << endl;
    } else {
      cout << sorted_x[middle - 1] << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 3712
import java.util.*;

class Main {
	static String a; 
	static String b;
	static int aLen;
	static int bLen;
	static int[][] dp;
	static int[][][] nxt;
	static String[][] val;

	public static int dfs(int pa, int pb) {
		// System.out.println(Integer.toString(pb) + " " + Integer.toString(pa));
		if(pa >= aLen || pb >= bLen) {
			nxt[pa][pb][0] = pa; nxt[pa][pb][1] = pb;
			// val[pa][pb] = "";
			return 0;
		}

		if(dp[pa][pb] == -1) {
			dp[pa][pb] = 0;
			if(a.charAt(pa) == b.charAt(pb)) {
				dp[pa][pb] = 1 + dfs(pa+1, pb+1);
				nxt[pa][pb][0] = pa+1; nxt[pa][pb][1] = pb+1; val[pa][pb] = Character.toString(a.charAt(pa));
			} else {
				int i = dfs(pa+1, pb);
				int j = dfs(pa, pb+1);

				if(i > j) {
					dp[pa][pb] = i;
					nxt[pa][pb][0] = pa+1; nxt[pa][pb][1] = pb; val[pa][pb] = "";
				} else {
					dp[pa][pb] = j;
					nxt[pa][pb][0] = pa; nxt[pa][pb][1] = pb+1; val[pa][pb] = "";
				}		
			}
		}

		return dp[pa][pb];
	}

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

    	a = sc.nextLine(); b = sc.nextLine();
    	aLen = a.length(); bLen = b.length();

    	dp = new int[aLen][bLen];
    	for(int[] i : dp) 
    		Arrays.fill(i, -1);
    	nxt = new int[aLen+5][bLen+5][2]; val = new String[aLen][bLen]; 

    	dfs(0, 0);
    	int i = 0;
    	int j = 0;
    	String ans = "";
    	while(i < aLen && j < bLen) {
    		ans += val[i][j];
    		int newi = nxt[i][j][0]; 
    		int newj = nxt[i][j][1];
    		i = newi; j = newj;
    	}
    	System.out.println(ans);
    }
}



Measured memory_bytes: 598544
X,N=[int(x) for x in input().strip().split(" ")]
P=list(map(int,input().split()))
f=0
if len(P)==0:
    print(X)
else:
    for i in range(int(N/2)+2):
        if X-i not in P:
            print(X-i)
            f=1
        elif X+i not in P:
            print(X+i)
            f=1
        if f==1:
            break

Measured memory_bytes: 9144
from sys import stdin
import math
import fractions
import heapq

n, m = [int(x) for x in stdin.readline().rstrip().split()]
a = [int(x) for x in stdin.readline().rstrip().split()]

a = list(map(lambda x: x*(-1), a))
heapq.heapify(a)

for i in range(m):
    t = heapq.heappop(a)
    heapq.heappush(a, (-1)*(-t//2))

print(-sum(a))

Measured memory_bytes: 16240
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int cnt = 0;

        if (s.substring(0, 1).equals("o")) {
            cnt++;
        }
        if (s.substring(1, 2).equals("o")) {
            cnt++;
        }
        if (s.substring(2, 3).equals("o")) {
            cnt++;
        }

        System.out.println((700 + cnt * 100));
        sc.close();
    }    
}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
#include<boost/multiprecision/cpp_int.hpp>
using namespace std;
using namespace boost::multiprecision;
#define BEGIN ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define END return EXIT_SUCCESS
#define rep(I,N) for(auto I=0;I<(N);++I)
#define up(I,A,B) for(auto I=(A);I<=(B);++I)
#define dw(I,A,B) for(auto I=(A);I>=(B);--I)
#define all(C) (C).begin(),(C).end()
#define rall(C) (C).rbegin(),(C).rend()
#define ft first
#define sd second
#define mp make_pair
#define mt make_tuple
#define pf push_front
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define rs resize
typedef long long ll;
typedef unsigned long long ull;
template<class T>inline void                                      in(T &p){cin>>p;}
template<class T1,class T2>inline void                            in(T1 &p1,T2 &p2){cin>>p1>>p2;}
template<class T1,class T2,class T3>inline void                   in(T1 &p1,T2 &p2,T3 &p3){cin>>p1>>p2>>p3;}
template<class T1,class T2,class T3,class T4>inline void          in(T1 &p1,T2 &p2,T3 &p3,T4 &p4){cin>>p1>>p2>>p3>>p4;}
template<class T1,class T2,class T3,class T4,class T5>inline void in(T1 &p1,T2 &p2,T3 &p3,T4 &p4,T5 &p5){cin>>p1>>p2>>p3>>p4>>p5;}
template<class T>inline void                                      ins(T &p){for_each(all(p),in<decltype(p[0])>);}
template<class T>inline void                             out(T p){cout<<p<<endl;}
template<class T1,class T2>inline void                   out(T1 p1,T2 p2){cout<<p1<<" "<<p2<<endl;}
template<class T1,class T2,class T3>inline void          out(T1 p1,T2 p2,T3 p3){cout<<p1<<" "<<p2<<" "<<p3<<endl;}
template<class T1,class T2,class T3,class T4>inline void out(T1 p1,T2 p2,T3 p3,T4 p4){cout<<p1<<" "<<p2<<" "<<p3<<" "<<p4<<endl;}
inline                                              void out(double p){printf("%.10f\n",p);}
template<class T>inline                             void outs(T p){for_each(all(p),out<decltype(p[0])>);}

inline void solve(void){
  int N;
  in(N);
  vector<int> P(N),Q(N),A(N);
  ins(P);ins(Q);
  A=P;
  sort(all(A));
  int cnt_i=0,cnt_p,cnt_q;
  do{
    bool f=true;
    rep(i,N){
      if(A[i]!=P[i]){
        f=false;
        break;
      }
    }
    if(f)cnt_p=cnt_i;
    f=true;
    rep(i,N){
      if(A[i]!=Q[i]){
        f=false;
        break;
      }
    }
    if(f)cnt_q=cnt_i;
    cnt_i++;
  }while(next_permutation(all(A)));
  out(abs(cnt_p-cnt_q));
}
int main(int argc,char**argv){
  BEGIN;
  solve();
  END;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<cstdlib>
#include<string>
#include<algorithm>
#include<map>
#include<iomanip>
#include<limits>
#include<queue>
#include<set>
typedef long long ll;

using namespace std;

int P[10] = {0,0,0,0,0,0,1,1,1,2};
int Q[10] = {1,1,1,2,2,3,2,2,3,3};
int R[10] = {2,3,4,3,4,4,3,4,4,4};

ll m,a,r,c,h;

int main(){

    string s;
    int N;
    cin >> N;

    ll D[5];

    for(int i = 0;i < N;i++){
    	 cin >> s;
    	 if(s[0] == 'M')m++;
    	 if(s[0] == 'A')a++;
    	 if(s[0] == 'R')r++;
    	 if(s[0] == 'C')c++;
    	 if(s[0] == 'H')h++;
    }

    D[0] = m,D[1] = a,D[2] = r,D[3] = c,D[4] = h;

    ll res = 0;
    for(int d = 0; d < 10;d++){
    	res += D[P[d]]*D[Q[d]]*D[R[d]];
    }

    cout << res << endl;

	return 0;

}


Measured memory_bytes: 256
module Main where

import Data.List (unfoldr)
import Data.Tuple (swap)

main :: IO ()
main = do
  n <- readLn
  putStrLn $ concatMap show $ f n

f :: Int -> [Int]
f =
  (\ds -> if null ds then [0] else ds) .
  reverse . unfoldr (\n -> if n == 0 then Nothing else Just (swap (divMod2 n (-2))))

divMod2 :: Integral a => a -> a -> (a, a)
divMod2 n m =
  let
    (r, q) = divMod n m
  in
    if q < 0 then (r + 1, q - m) else (r, q)

tests :: [Bool]
tests = [test1, test2, test3]

test1, test2, test3 :: Bool
test1 = concatMap show (f (-9)) == "1011"
test2 = concatMap show (f 123456789) == "11000101011001101110100010101"
test3 = concatMap show (f 0) == "0"


Measured memory_bytes: 508
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();
        long x = sc.nextLong();
        long count = 0;

//        for(long i = a ; i <= b; i++){
//            if(i % x == 0){
//                count++;
//            }
        count =(b / x) - (a / x);
        if(a % x == 0)
            {
                count++;
            }
        System.out.println(count);
    }
}

Measured memory_bytes: 23252
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner a = new Scanner(System.in);
		int A = a.nextInt();
		int B = a.nextInt();
		if(A < B) {
			System.out.println("a < b");
		} else if (A > B) {
			System.out.println("a > b");
		} else {
			System.out.println("a == b");
		}
		
	}

}

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


int main()
{

long long n;
cin>>n;

long long freq[100005]={0};

long long sum=0;

for(int i=0;i<n;i++)
{
 long long num;
 cin>>num;
freq[num]++;
sum+=num;
}

    
long long q;
cin>>q;
for(long long j=1;j<=q;j++)
{

long long ak,bk;
cin>>ak>>bk;

//cout<<"Freq of ak "<<freq[ak]<<"\n";


sum=sum-(ak*freq[ak])+(freq[ak]*bk);
freq[bk]+=freq[ak];
freq[ak]=0;


cout<<sum<<endl;

}//query case ends

return 0;
}

Measured memory_bytes: 4396
#include<iostream>
#include<string>
#include<vector>
#include<math.h>
#include<algorithm>
#include<cstdio>
#include<stdio.h>
#include<stack>
#include<sstream>
#include<iomanip>
#include<map>
typedef long long ll;

#define pi 3.14159265358979323846
#define VI vector<int>
#define VLL vector<long long>
#define MAX max_element
#define MIN min_element
#define all(v) v.begin(), v.end()
const ll MOD = 1e9 + 7;

using namespace std;

template<typename T>
T gcd(T a, T b) {
	return b ? gcd(b, a % b) : a;
}
template<typename T>
T lcm(T a, T b) {
	return a * b / gcd(a, b);
}

template<typename T>
T finder(vector<T> vec, T number) {
	auto itr = find(vec.begin(), vec.end(), number);
	size_t index = distance(vec.begin(), itr);
	if (index != vec.size()) { // 発見できたとき
		return 1;
	}
	else { // 発見できなかったとき
		return 0;
	}
}
ll frac(ll n)
{
	if (n == 0) {
		return 1;
	}
	return (n * frac(n - 1)) % MOD;
}

/*char r[4];
int yaju[4];
char op[3];
int sum = 0;
scanf("%s", r);
for (int i = 0;i < 4;i++) {
	yaju[i] = r[i] - '0';
}
*/
int main() {
	ll A,B;
	string S, T,U;
	//VLL P(N);
	//for (int i = 0;i < N;i++) cin >> P[i];
	ll a=0 , b=0;
	ll ans=0;
	cin >> S >> T >> A >> B >> U;
	if (S == U)A--;
	else B--;
	cout << A << " " << B << endl;
}

Measured memory_bytes: 256
from collections import deque
INFTY = 10000
H,W = map(int,input().split())
S = [input().strip() for _ in range(H)]
A = [[-1 for _ in range(W)] for _ in range(H)]
cnt = 0
for i in range(H):
    for j in range(W):
        if S[i][j]=="#":
            A[i][j]=INFTY
            cnt += 1
que = deque([(0,0,0)])
A[0][0] = 0
while que:
    i,j,d = que.popleft()
    if j+1<W and A[i][j+1]<0:
        A[i][j+1]=d+1
        que.append((i,j+1,d+1))
    if i-1>=0 and A[i-1][j]<0:
        A[i-1][j]=d+1
        que.append((i-1,j,d+1))
    if j-1>=0 and A[i][j-1]<0:
        A[i][j-1]=d+1
        que.append((i,j-1,d+1))
    if i+1<H and A[i+1][j]<0:
        A[i+1][j] = d+1
        que.append((i+1,j,d+1))
if A[H-1][W-1]<0:
    print(-1)
else:
    print(H*W-cnt-A[H-1][W-1]-1)

Measured memory_bytes: 73744
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <iostream>

using namespace std;

int a, b,ans;

int cek(int x){
    int tmp=1,count=0;
    while(tmp<=x){
        tmp*=10;
        count++;
    }
    return tmp;
}

int main()
{
    
    cin>>a>>b;
    int byk=cek(b);
    a*=byk;
    a+=b;
    bool coba=false;
    for(int x=1;x<=1000;x++){
        if(x*x==a){
            coba=true;
            break;
        }
    }
    if(coba){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<queue>
using namespace std;
#define int long  long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
typedef pair<int, int>P;
const int INF = 1e8;

signed main() {
	int A, B, C, X, Y;
	cin >> A >> B >> C >> X >> Y;
	int ans = 0;
	if (A + B >= 2 * C) {
		int common = min(X, Y);
		ans += common * C * 2;
		if (X > Y) {
			if (A >= 2 * C)ans += (X - common) * C * 2;
			else ans += (X - common) * A;
		}
		else if (X < Y) {
			if (B >= C * 2)ans += (Y - common) * C * 2;
			else ans += (Y - common) * B;
		}
	}
	else ans = A * X + B * Y;
	cout << ans;
}

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

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

    long long res = 0;
    for (int p = 0; p <= min(K, N); ++p) {
        for (int q = 0; p + q <= min(K, N); ++q) {
            vector<long long> v;
            long long cur = 0;
            for (int i = 0; i < p; ++i) v.push_back(V[i]), cur += V[i];
            for (int i = 0; i < q; ++i) v.push_back(V[N-1-i]), cur += V[N-1-i];
               
            sort(v.begin(), v.end());
            for (int i = 0; i < min(K - p - q, (int)v.size()); ++i) {
                if (v[i] < 0) cur -= v[i];
            }
            res = max(res, cur);
        }
    }
    cout << res << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<complex>
#include<vector>
#include<algorithm>
#include<functional>
#include<array>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define INF 1e+9


int main() {
	int n,s=0,n1;
	cin >> n;
	n1 = n;
	for (int i = 9;i >= 0;i--) {
		int x = pow(10, i);
		s += n / x;
		n = n % x;
	}
	if (n1%s == 0)cout << "Yes" << endl;
	else cout << "No" << endl;


	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
long double pi = 2 * acos(0.0);
const ll mod = 1e9 + 7;

void solve() {
    ll n, m, k;
    cin >> n >> m >> k;
    vector<ll> a(n + 1, 0), b(m + 1, 0);
    for(ll i = 1; i <= n; i++) {
        cin >> a[i];
        a[i] += a[i - 1];
    }
    for(ll i = 1; i <= m; i++) {
        cin >> b[i];
        b[i] += b[i - 1];
    }
    ll ans = 0;
    for(ll i = 0; i <= n; i++) {
        if(k - a[i] < 0) break;
        ll ind = upper_bound(b.begin(), b.end(), k - a[i]) - b.begin();
        ind--;
        ans = max(ans, i + ind);
    }
    cout << ans;
}

int main() {
    ios_base :: sync_with_stdio(false); 
    cin.tie(nullptr);   
    ll t = 1;
    //cin >> t;
    while(t--) {
        solve();
    }
    return 0;
}


Measured memory_bytes: 6348
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  int a,b,c,x,y,money=1000000000;
  cin>>a>>b>>c>>x>>y;
  for(int i=0;i<=100000;i++){
    money=min(money,i*2*c+max(0,x-i)*a+max(0,y-i)*b);
  }
  cout<<money<<endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<functional>
int t[1001*1001];
using namespace std;
int main(void)
{	
	int  n,p[1001],s,m,i,j,k,x,high,low,mid,max,suu,flg,mx;
	while(1) {
		scanf("%d %d",&n,&m);
		if(n==0 && m==0) break;
		p[0]=0;
		for(i=1;i<=n;i++) scanf("%d",&p[i]);
		x=0;
		for(i=0;i<=n;i++){
			for(j=0;j<=n;j++) {
				t[x]=p[i]+p[j];
				x++;
			}
		}
		sort(t,t+x);
		max=-1;
		mx=-1;
		for(i=0;i<x;i++) {
			flg=0;
			low=0;
			high=x;
			while(low<=high) {
				mid=(low+high)/2;
				if(t[mid]==m-t[i]) {
					flg=1;
					break;
				}
				if(t[mid]<m-t[i]) low=mid+1;
				else if(t[mid]>m-t[i]) high=mid-1;
			}
			if(flg==1) break; 
			else {
				if(t[high]+t[i]>m){}
				else {
					if(max<t[high]+t[i])
						max=t[high]+t[i];
				}
			}
		}
		if(flg==1) printf("%d\n",m);
		else printf("%d\n",max);
	}
	return 0;
}

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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pll;
typedef vector<bool> vb;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define FORD(i,a,b) for (ll i = (b)-1; i >= (a); i--)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define has(c,i) ((c).find(i) != end(c))
#define DBGDO(X) ({ if(1) cerr << "DBGDO: " << (#X) << " = " << (X) << endl; })

ll get(ll i) {
	cout << i << endl;
	string s; cin >> s;
	if (s == "Vacant") exit(0);
	if (s == "Male") return 0;
	if (s == "Female") return 1;
	assert(0);
	return 42;
}

int main() {
	ll n; cin >> n;
	
	if (n == 3) {
		get(0);
		get(1);
		get(2);
		return 0;
	}
	
	// invariant: ga == gb <-> (b-a) odd
	ll a = 0, b = n;
	ll ga = get(a);
	ll gb = ga;
	
	while (true) {
		assert((ga == gb) == (b-a)%2);
		
		ll c = (a+b)/2;
		ll gc = get(c);
		
		if ((ga == gc) == (c-a)%2) b = c, gb = gc;
		else a = c, ga = gc;

	}
}



Measured memory_bytes: 852
#include <iostream>
#include<vector>
#include<queue>
using namespace std;
typedef pair<long long, long long> P;
int v,e,r;
long long int INF=1e10;
struct edge{
    int to;
    long long cost;
    edge(int _to, long long _cost) :to(_to),cost(_cost){}
};
vector <edge> G[1010];
bool f[1010];
long long d[1010];
 bool bellman_ford(int start){
     for(int i=0;i<v;i++) d[i]=1e12;
     d[start]=0;
     f[start]=1;
 
 for(int i=0;i<v;i++){
     bool update=false;
     
     for(int j=0;j<v;j++){
         int from=j;
         if(!f[from]) continue;
         
         for(int k=0;k<G[from].size();k++){
             edge e=G[j][k];
             if(d[from]!=INF && d[e.to]>d[from]+e.cost){
                 f[e.to]=1;
                 d[e.to]=d[from]+e.cost;
                 update=true;
             }
         }
     }
    if(update==false) break;
    if(i==v-1) return true;
 }
 return false;
}

int main(){
    cin>>v>>e>>r;
    for(int i=0;i<e;i++){
        int s,t,d;
        cin>>s>>t>>d;
        G[s].push_back(edge(t,d));
    }
    if(bellman_ford(r)){
        cout<<"NEGATIVE CYCLE"<<endl;
        return 0;
    }
    for(int i=0;i<v;i++){
        if(d[i]!=1e12) cout<<d[i]<<endl;
        else cout<<"INF"<<endl; 
    }
}

Measured memory_bytes: 3144
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace C_test_For_Atcorder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            var N = cin.ReadInt;
            var Y = cin.ReadInt;
            for (int i = 0; i <= N;i++)
                for (int j = 0; j <= N - i;j++){
                    var k = N - j - i;
                    if (10000 * i + 5000 * j + 1000 * k == Y)
                    {
                        WriteLine($"{i} {j} {k}");
                        return;
                    }
                }
            WriteLine("-1 -1 -1 ");
            
        }
    }


    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue inputStream;

        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return (string)inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return (string)inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }

}


Measured memory_bytes: 13140
#define _USE_NATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <random>
#include <tuple>


using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
#define EPS 1e-9
const int INF = 1050000000;
const long long LINF = 1LL << 60;
const ll MOD = 1e9 + 7;
const int MINF = -1050000000;

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


int main() {
	
	int n, m;
	cin >> n >> m;
	vector<int> x, y;
	vector<int> num(n,1), r(n,0);
	rep(i, m) {
		int v, w;
		cin >> v >> w;
		v--; w--;
		x.push_back(v);
		y.push_back(w);
	}

	r[0] = 1;
	rep(i, m) {
		num[x[i]]--;
		num[y[i]]++;
		if (r[x[i]] == 1) {
			r[y[i]] = 1;
			if (num[x[i]] == 0) {
				r[x[i]] = 0;
			}
		}
	}
	int cnt = 0;
	rep(i, n) {
		cnt += r[i];
	}
	cout << cnt << endl;
	return 0;
}


Measured memory_bytes: 2044
#include <bits/stdc++.h>
#include <math.h>
#include <vector>
#include <queue>
#include <iomanip>
#include <string>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep_1 (i,j,n) for(int i=j;i<n;i++)
typedef long long ll;
typedef long l;
const ll l_INF = 101010101000;
const int INF = 1010101010;
const int dx[4] = {-1,0,1,0};
const int dy[4] = {0,-1,0,1};
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int,int>;

int main(){
  int a,b;
  cin>>a>>b;
  cout << a*b;
}

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

using namespace std;

const int OO = 1e9;
const double EPS = 1e-9;

#define ndl cout << '\n'
#define sz(v) int(v.size())
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define present(a, x) (a.find(x) != a.end())
#define db(x) cout << "> " << #x << " = " \
	<< (x) << '\n'
#define db2(x, y) cout << "> " << #x << " = " \
	<< (x) << ", " << #y << " = " << (y) << '\n'
#define db3(x, y, z) cout << "> " << #x << \
	" = " << (x) << ", " << #y << " = " << \
	(y) << ", " << #z << " = " << (z) << '\n'

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef vector<vector<int>> vvi;
typedef map<int, int> mii;
typedef set<int> si;

const int MX = 2e5 + 5;
int n, ans, win[MX];
vvi adj(MX);

int dfs(int node ,int parent){
	int mxH[] = {-1, -1, -1};
	for (auto& child : adj[node])
		if (child != parent){
			mxH[0] = dfs(child, node) + 1;
			sort(mxH, mxH + 3);
		}
	for (int i = 0; i < 3; ++i)
		mxH[i] = max(mxH[i], 0);
	ans = max(ans, mxH[1] + mxH[2]);
	return mxH[2];
}

int main() {
	ios::sync_with_stdio(false);
	cout.precision(10);
	cin >> n;
	for (int i = 0; i < n - 1; ++i) {
		int u, v;
		cin >> u >> v;
		adj[u].pb(v);
		adj[v].pb(u);
	}
	dfs(1, -1);
	++ans;
//	db(ans);
	win[1] = 1, win[2] = 0;
	for (int i = 3; i <= ans; ++i)
		win[i] = max(!win[i - 1], !win[i - 2]);
	cout << (win[ans] ? "First" : "Second") << '\n';
	return 0;
}


Measured memory_bytes: 23936
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<bitset>

typedef long long LL;

const int N=305;
const int MOD=998244353;

int n,m,tot;
bool vis[N];
std::bitset<N> bit[N],bas[N];

int ksm(int x,int y)
{
	int ans=1;
	while (y)
	{
		if (y&1) ans=(LL)ans*x%MOD;
		x=(LL)x*x%MOD;y>>=1;
	}
	return ans;
}

void gauss()
{
	for (int i=1;i<=n;i++)
		for (int j=1;j<=m;j++)
			if (bit[i][j])
			{
				if (vis[j]) bit[i]^=bas[j];
				else
				{
					bas[j]=bit[i];
					tot++;
					vis[j]=1;
					break;
				}
			}
}

int main()
{
	scanf("%d%d",&n,&m);
	for (int i=1;i<=n;i++)
		for (int j=1;j<=m;j++)
		{
			int x;scanf("%d",&x);
			bit[i][j]=x;
		}
	gauss();
	int ans=(LL)ksm(2,n-1)*(ksm(2,m)-ksm(2,m-tot))%MOD;
	ans+=ans<0?MOD:0;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 384
#include<vector>
#include<iostream>
#include<string>
#include<algorithm>
#include<complex>
#include<cmath>
#include<cstdio>
#include<sstream>
#include<iomanip>
#define pb(a) push_back(a)
const double EPS = 1e-8;
using namespace std;
const double INF = 1e12;
typedef complex<double> P;
namespace std{
	bool operator<(const P& a,const P& b){
		return real(a)!=real(b)?real(a)<real(b):imag(a)<imag(b);
	}
}
double cr(const P& a, const P& b){
	return imag(conj(a)*b);
}	
double dt(const P& a, const P& b){
	return real(conj(a)*b);
}
struct L : public vector<P>{
	L(const P &a,const P& b){
		pb(a);pb(b);
	}
};
typedef vector<P> G;

struct C{
	P p;double r;
	C(const P &p,double r) : p(p),r(r){}
};

int ccw(P a,P b,P c){
	b -= a;
	c -= a;
	if(cr(b,c) > EPS)return 1;
	if(cr(b,c)<-EPS)return -1;
	if(dt(b,c)<-EPS)return 2;
	if(norm(b)<norm(c) -EPS)return -2;
	return 0;
}
P pro(const L &l,const P &p){
	double t=dt(p-l[0],l[0]-l[1])/norm(l[0]-l[1]);
	return l[0]+t*(l[0]-l[1]);
}

bool itSP(const L &s, const P &p){
	return abs(s[0]-p)+abs(s[1]-p)-abs(s[0]-s[1]) < EPS;
}

bool itSS(const L &s, const L &t){
	return ccw(s[0],s[1],t[0])*ccw(s[0],s[1],t[1]) <= 0 &&
		ccw(t[0],t[1],s[0])*ccw(t[0],t[1],s[1]) <= 0;
}

double dstSP(const L &s,const P &p){
	const P r = pro(s,p);
	if(itSP(s,r))return abs(r-p);
	return min(abs(s[0]-p),abs(s[1]-p));
}
double dstSS(const L &s,const L &t){
	if(itSS(s,t))return 0;
	return min(min(dstSP(s,t[0]),dstSP(s,t[1])),min(dstSP(t,s[0]),dstSP(t,s[1])));
}
#define rep(i,j) for(int i=0;i<j;i++)
vector<L> hoge(int x,int y,int r,int th_){
	double th=th_*1.*2*M_PI/360+M_PI/2;
	vector<P> ps(5);
	rep(i,5){
		double a=th+i*2*M_PI/5;
		ps[i].real()=x+r*cos(a);
		ps[i].imag()=y+r*sin(a);
	}
	vector<L> re;
	rep(i,5){
		re.pb(L(ps[i],ps[(i+2)%5]));
	}
	return re;
}
int main(){
	int n,m,l;
	while(cin >> n >> m >> l&&n){
	vector<vector<L> > st;
	rep(i,n){
		int x,y,a,r;
		cin >> x >> y >> a >> r;
		st.pb(hoge(x,y,r,a));
	}
	double dst[100][100];
	fill_n(dst[0],sizeof(dst)/sizeof(double),INF);
	rep(i,n){
		rep(j,n){
			double d = INF;
			vector<L> t = st[i];
			vector<L> u = st[j];
			rep(k,5){
				rep(kk,5){
					//cout <<"dst "<< dstSS(t[k],u[kk]) << endl;
					d = min(dstSS(t[k],u[kk]),d);
				}
			}
			//cout << endl;
			dst[i][j]=d;
		}
	}
	rep(k,n)rep(i,n)rep(j,n){
		dst[i][j] = min(dst[i][j],dst[i][k]+dst[k][j]);
	}
	cout <<fixed << setprecision(10)<< dst[m-1][l-1] << endl;
	}
	//vector<L> tt = hoge(5,5,5,0);
		
	//rep(i,5) cout << tt[i][0].real() << "," <<tt[i][0].imag() << endl;
	return 0;
}

Measured memory_bytes: 1432
#include <bits/stdc++.h>
      #define ll long long  int
      #define N 400000
      #define f(i,a,b) for(ll i=(ll)a;i<=(ll)b;i++)
      #define rf(i,a,b) for(ll i=(ll)a;i>=(ll)b;i--)
      #define po pop_back
      #define pb push_back
      #define pp pair<ll,ll>
      #define lb lower_bound
      #define fi first
      #define se second
      #define debug(x) cout << #x << " = " << x << endl
      #define ub upper_bound
      #define ibs ios_base::sync_with_stdio(false)
      #define cti cin.tie(0)
      #define all(x) x.begin(),x.end()
      #define PI 3.14159265
      #define cot cout.tie(0)
      using namespace std;
       /**
        * @author :: Sawlani
        *
        */
         int main()
         {
             ll n;
             cin >>  n ;

             f(i,1,9)
             {
                 ll p=n/i;

                 if(p*i==n&&p>=1&&p<=9)
                 {

                     cout << "Yes" << endl;
                     return 0;
                 }

             }
             cout << "No" <<  endl;
         }






Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A,B,C,D,E,F;
  cin>>A>>B>>C>>D>>E>>F;
  if(A==C&&A==E){
    cout<<"NO"<<endl;
  }
  else if(A==C&&A==F){
    cout<<"NO"<<endl;
  }
  else if(B==C&&B==E){
    cout<<"NO"<<endl;
  }
  else if(A==D&&A==E){
    cout<<"NO"<<endl;
  }
  else if(A==D&&A==F){
    cout<<"NO"<<endl;
  }
  else if(B==C&&B==F){
    cout<<"NO"<<endl;
  }
  else if(B==D&&B==F){
    cout<<"NO"<<endl;
  }
  else if(B==D&&B==E){
    cout<<"NO"<<endl;
  }
  else{
    cout<<"YES"<<endl;
  }
}

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

int main(){
  int a, x = 1;
  cin >> a;
  char b[a];
  for(int i = 0; i < a; i++){
  	cin >> b[i];
    if(i != 0 && int(b[i - 1]) != int(b[i])){
    	x++;
    }
  }
   cout << x << endl;
}

Measured memory_bytes: 384
#include<cstdio>
#define MAX 100001
#define INF 2000000000

struct Card
{
	char suit;
	int value;
};

Card L[MAX/2+1];
Card R[MAX/2+1];

void merge(Card* A,int l,int mid,int r)
{
	int n1=mid-l;
	int n2=r-mid;
	int i,j;

	for (i = 0; i < n1; ++i)
	{
		L[i]=A[l+i];

	}

	for (i = 0; i < n2; ++i)
	{
		R[i]=A[mid+i];
	}

	L[n1].value=INF;
	R[n2].value=INF;

	i=0;
	j=0;

	for (int k= l; k < r; ++k)
	{
		
		if (L[i].value>R[j].value)
		{
			A[k]=R[j++];
		}
		else
		{
			A[k]=L[i++];
		}
	}
}

void mergeSort(Card* A,int l,int r)
{
	if (l+1==r)
		return;

	int mid=(l+r)/2;
	mergeSort(A,l,mid);
	mergeSort(A,mid,r);
	merge(A,l,mid,r);
}

int partition(Card *A,int p,int r)
{
	int j=p;
	Card t;
	for (int i = p; i < r-1; ++i)
	{
		if (A[i].value<=A[r-1].value)
		{
			t=A[i];
			A[i]=A[j];
			A[j++]=t;
		}
	}
	t=A[j];
	A[j]=A[r-1];
	A[r-1]=t;
	return j;
}

void quickSort(Card *A,int p,int r)
{
	if (r<=p)
	{
		return;
	}

	int pivot=partition(A,p,r);
	quickSort(A,p,pivot);
	quickSort(A,pivot+1,r);
}

int main()
{
	int n,i,v;
	Card A[MAX],B[MAX];

	int stable=1;
	char s[10];

	scanf("%d",&n);

	for (i = 0; i < n; ++i)
	{
		scanf("%s %d",s,&v);
		A[i].suit=B[i].suit=s[0];
		A[i].value=B[i].value=v;
	}

	mergeSort(A,0,n);
	quickSort(B,0,n);

	for (int i = 0; i < n; ++i)
	{
		if (A[i].suit!=B[i].suit)
		{
			stable=0;
			break;
		}
	}
	if (stable)
	{
		printf("Stable\n");
	}
	else
		printf("Not stable\n");

	for (i = 0; i < n; ++i)
	{
		printf("%c %d\n",B[i].suit,B[i].value);
	}
	return 0;
}


Measured memory_bytes: 5064
using System;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        var D = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();

        var i = 0;
        while (true)
        {
            Array.Sort(D);

            if (D[0] == D[1])
            {
                if (D[1] == D[2])
                {
                    Console.WriteLine(i);
                    return;
                }
                else
                {
                    D[0]++;
                    D[1]++;
                }
            }
            else
            {
                D[0] += 2;
            }

            i++;
        }
    }
}


Measured memory_bytes: 13268
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    if len(x) == 0:
        return []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

def pow_k(x, n):
    ans = 1
    while n:
        if n % 2:
            ans *= x
        x *= x
        n >>= 1
    return ans

"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""

def rotate(ro,a,n):

    for i in range(n):
        for j in range(n):
            if ro[i][(j+a)%n] != ro[j][(i+a)%n]:
                break
        else:
            continue
        break
    else:
        return 1

    return 0

ans = 0

n = onem()

dp = [list(input())[:-1] for i in range(n)]

for i in range(n):

    po = rotate(dp,i,n)

    ans += po * n

print(ans)


Measured memory_bytes: 43120
#include <iostream>
#include <vector>
#include <string>
#include <cmath>

using namespace std;

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

  vector<long long> xs(n, 0);

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

  long long int ans = 0;
  for (int i = 0; i < n - 1; i++) {
    long long int diff = xs[i+1] - xs[i];
    ans += min(diff * a, b);
  }
  cout << ans << endl;
}

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

int main(){
#ifdef _DEBUG
	//freopen("_in" , "r", stdin );
	//freopen("_out", "w", stdout);
#endif
	ios::sync_with_stdio(0); cin.tie(0);
	string s[3]; cin >> s[0] >> s[1] >> s[2];
	int i = 0;
	for(;;) {
		if (!s[i].size()) break;
		int t;
		if (s[i][0] == 'a') t = 0;
		if (s[i][0] == 'b') t = 1;
		if (s[i][0] == 'c') t = 2;
		s[i].erase(0, 1);
		i = t;
	}
	if (i == 0) cout << 'A';
	if (i == 1) cout << 'B';
	if (i == 2) cout << 'C';
	cout << '\n';
}


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

int main(){
  int N; cin >> N;
  vector<int> bottom(N);
  for(int i=0;i<N;i++){
    cin >> bottom.at(i);
  }
  int num= bottom.at(0);
  int count = 1;
  while(true){

    if(num == 2){
      cout << count << endl;
      return 0;
    }
    num = bottom.at(num-1);
    count++;
    if(count > MAX){
      cout << -1 << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define fastIO (cin.tie(0), cout.tie(0), ios::sync_with_stdio(false))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define precise(i) fixed << setprecision(i)
using li = long long int;
using uli = unsigned long long int;
using namespace std;

int main() {
    fastIO;
    const int MAX_SEAT = 1000000;
    int n;
    cin >> n;
    bool seats[MAX_SEAT]{false};
    while (n--) {
        int r, l;
        cin >> r >> l;
        for (int i = r; i <= l; i++) {
            seats[i - 1] = true;
        }
    }

    int cnt = 0;
    rep(i, MAX_SEAT) if (seats[i] == true) cnt++;
    cout << cnt << endl;
}

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


int main(){
  int n;
  cin >> n;
  ll s[200010];
  s[0]=0;
  rep(i,n){
    ll a;
    cin >> a;
    s[i+1]=s[i]+a;
  }
  
  ll ans=1e18;
  for(int i=2;i<n-1;i++){
    ll *l,*r;
    ll gap;
    l=lower_bound(s+1,s+i+1,s[i]/2+1);
    r=lower_bound(s+i+1,s+n+1,(s[n]+s[i])/2+1);
    rep(j,2){
      rep(k,2){
        gap=max({*l,s[i]-*l,*r-s[i],s[n]-*r})-min({*l,s[i]-*l,*r-s[i],s[n]-*r});
        ans=min(ans,gap);
        l--;
      }
      l+=2;
      r--;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 1792
// #include<bits/stdc++.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
using namespace std;
#define ed "\n";
#define tl 1000000007
// long long comb(int n, int k){
//   if (n == k || k == 0)
//     return 1;
//   else {
//     return comb(n - 1, k - 1) + comb(n - 1, k);
//   }
// }
 
void comb(vector<vector <long long int> > &v){
  for(int i = 0;i <v.size(); i++){
    v[i][0]=1;
    v[i][i]=1;
  }
  for(int k = 1;k <v.size();k++){
    for(int j = 1;j<k;j++){
      v[k][j]=(v[k-1][j-1]%tl+v[k-1][j]%tl);
    }
  }
}
int main(){
    cin.tie(0);
   	ios::sync_with_stdio(false);

    int n,k;
    
    cin >> n>>k; //k:青 n-k:赤 1<=i<=k:i回数
    vector<vector<long long int> > v(n+1,vector<long long int>(n+1,0)); 
    comb(v);
    for(int i=1; i<=k; i++){
        long long point=0;
        //アルゴリズム
        // cerr <<"青分け方：" << e << endl; cerr << comb(n-k-(i-1),i) << ed;

        cout << (v[k-1][i-1]*v[n-k+1][i])%tl << ed;
    }
}


Measured memory_bytes: 31616
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define F first
#define S second
#define pb push_back
mt19937 rnd;


int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
#endif

    int a, b, c, d, k;
    cin >> a >> b >> c >> d >> k;
    int x = a * 60 + b;
    int y = c * 60 + d;
    cout << y - x - k << "\n";

#ifdef LOCAL
    cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}


Measured memory_bytes: 3656
#include <iostream>
#include <vector> 
#include <utility>
#include <string>

using namespace std;
int map[2500];
int adj[2500];
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
/*
bool tonari(int pos,int color,int w,int h){
  int x=pos???w;
  int y=pos/w;
  for(int dir=0;dir<4;dir++){
    int npos = pos + dx[dir]+dy[dir]*w;
    int nx = x + dx[dir];
    int ny = y + dy[dir];
    if (ny>=0 && ny <= h-1 && dx>=0 && dx<= w-1){
      if (map[npos]==color) return true;
    }
  }
  return false;
}*/

void adja(int pos,int color,int w,int h){
  int x=pos%w;
  int y=pos/w;
  for (int dir=0;dir<4;dir++){
    int npos = pos + dx[dir]+dy[dir]*w;
    int nx = x + dx[dir];
    int ny = y + dy[dir];
    if (ny>=0 && ny <= h-1 && nx>=0 && nx<= w-1){
      if (map[npos]==0){
        if ((adj[npos]>>(color-1))%2==0) {
          adj[npos]+=color;
          adja(npos,color,w,h);
        }
      }
    }
  }
  
}

int doo()
{
  for (int i=0;i<2500;i++){
    map[i]=0;
    adj[i]=0;
  }
  int w,h,pos;
  cin >> w >> h;
  if (w==0 && h==0) return 0;
  //vector<pair<int,int>> adj(w*h,make_pair(0,0));
  string buf;
  for(int y=0;y<h;y++){
    cin >> buf;
    for(int x=0;x<w;x++){
      pos=y*w+x;
      if (buf[x]=='.') map[pos]=0;
      else if (buf[x]=='B') map[pos]=1;
      else map[pos]=2;
    }
  }
  for (int pos=0;pos<w*h;pos++){
    if (map[pos]!=0) {
    adja(pos,map[pos],w,h);
    }
  }
  int black=0,white=0;
  for (int pos=0;pos<w*h;pos++){
    if (adj[pos]==2) white++;
    else if (adj[pos]==1) black++;
  }
  cout << black << ' ' << white << endl;
  return 1;
}

int main(){
  while (1){
    int k=doo();
    if (k==0) break;
  }
  return 0;
}

Measured memory_bytes: 3208
import java.util.*;

public class Main {
	
	public static void main(String[] args)  {
		Scanner scan = new Scanner(System.in);
		int n=Integer.parseInt(scan.next());
		int max1=0;// the largest
		int max2=0;// second largest 
		int a;
		int index=0;
		for (int i=0;i<n;++i) {
			a=Integer.parseInt(scan.next());
			if (a>max1) {
				max2=max1;
				max1=a;
				index=i;
			}else {
				max2=Math.max(max2, a);
			}			
		}
		
		for (int i=0;i<n;++i) {
			if (i==index) {
				System.out.println(max2);
			}else {
				System.out.println(max1);
			}
		}
		
}
}
//end

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

int main()
{
  int day, num_work;
  cin >> day >> num_work;
  for (int i = 0; i < num_work; i++)
  {
    int work;
    cin >> work;
    day -= work;
  }
  if (day < 0)
  {
    day = -1;
  }
  cout << day << endl;
}


Measured memory_bytes: 3596