akhauriyash/Code-Regression huggingface dataset:
import java.io.{BufferedOutputStream, BufferedReader, InputStreamReader, PrintWriter}

import scala.collection.mutable.ArrayBuffer

object Main {
  def main(args: Array[String]): Unit = {
    val in = new BufferedReader(new InputStreamReader(System.in))
    val out = new PrintWriter(new BufferedOutputStream(System.out))

    val Array(n, m) = in.readLine().split("\\s+").map(_.toInt)
    val hs = in.readLine().split("\\s+").map(_.toInt)
    val roads = Array.fill(n)(ArrayBuffer.empty[Int])

    for (i <- 0 until m) {
      val (a, b) = in.readLine().split("\\s+") match {
        case Array(a, b) => (a.toInt - 1, b.toInt - 1)
      }
      roads(a).append(b)
      roads(b).append(a)
    }

    var count = 0

    for (i <- 0 until n) {
      val h = hs(i)
      val otherHs = roads(i).map(hs(_))
      if (otherHs.forall(_ < h)) {
        count += 1
      }
    }

    out.println(count)
    out.flush()
  }
}


Measured memory_bytes: 81900
#include<bits/stdc++.h>
#include<math.h>
using namespace std;
#define int long long int
#define pp pair<int,int>
#define endl "\n"
#define PI 3.14159265
int MAX = INT_MAX;
const int mod=1e9+7;
const int INF =INT_MAX;
inline int gcd(int a,int b){if(a==0) return b;return gcd(b%a,a);}
inline int pow(int a,int n,int mod){if(n==0)return 1;int p=pow(a,n/2,mod);p=(p%mod*p%mod)%mod;if(n%2) return (p%mod*a%mod)%mod;else return p;}
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int t=1;
    //cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        vector<int>v(n);
        for(int i=0;i<n;i++)cin>>v[i];
        vector<int>pre(n,0);
        pre[0]=v[0];
        int ans=0;
        int mx=v[0];
        for(int i=1;i<n;i++)
        {
            mx=max(mx,v[i]);
            ans+=(mx-v[i]);

        }
        cout<<ans<<endl;
    }
}


Measured memory_bytes: 6364
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
#define rop(i,n) for(int i=1;i<n+1;i++)

using namespace std;
using std::swap;

vector<long long int> p;
vector<long long int> q;



int main() {
	int n,t=0,ans;
	string s,u;
	cin >> n >> s;
	ans = n;

	rep(i, n) {
		if (i == n - 1) {
			ans -= t;
			break;
		}
		if (s.substr(i, 1) == s.substr(i + 1, 1))++t;
		else { 
			ans -= t;
			t = 0;
		}

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

}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i, a, b) for (long long int i = (a); i < (b); i++)

using namespace std;
using ll = long long int;
using ld = long double;

auto p = [](auto s){
    cout << s << endl;
};

int main() {
    ll K, N;
    cin >> K >> N;
    vector<ll> A(N);
    vector<ll> D(N);
    rep(i, 0, N){
        cin >> A[i];
        if (i > 0){
            D[i] = A[i] - A[i-1];
        }
    }
    D[0] = A[0] + (K - A[N-1]);
    sort(D.begin(), D.end());
    ll ans = 0;
    rep(i, 0, N-1){
        ans += D[i];
    }
    p(ans);
    return 0;
}

Measured memory_bytes: 3328
#include<stdio.h>

int main(void) {
	long long int a, b, count = 1, number = 0, syain[4010], tanka[4010], suuryou[4010], score[4010] = {}, noruma = 1000000, sens = 0;
	while (count) {
		sens = 0;
		long long int score[4010] = {};
		scanf("%d", &count);
		for (size_t i = 0; i < count; i++)
		{
			scanf("%lld %lld %lld", &syain[number], &tanka[number], &suuryou[number]);
			score[syain[number]] += tanka[number] * suuryou[number];
			if (score[syain[number]] >= noruma)
			{
				printf("%lld\n", syain[number]);
				sens++;
			}
			number++;
		}
		if (sens == 0 && count != 0)
		{
			printf("NA\n");
		}
	}
	return 0;
}

Measured memory_bytes: 1112
import java.io.*;
import java.util.*;
class Main{
	static final long MOD = 1_000_000_007; // 10^9+7
    static final int MAX = 2_147_483_646; // intMax 
    static final int INF = 1_000_000_000; // 10^9  
    public static void main(String[] args) throws Exception {
		hayami saori = new hayami();
		int n = saori.saori_hayami();
		int num = n;
		int count = 0;
		boolean flg = true;
		while(flg){
			if(15 <= num){
				count++;
				num -= 15;
			}
			if(num < 15){
				flg = false;
			}
		}
		System.out.println(n*800 - count*200);
		saori.close();
    }
}

class hayami implements Closeable {
	private final InputStream in = System.in;
	private final byte[] hayami = new byte[1024];
	private int Hayami = 0;
	private int saori = 0;
	private boolean HayamiSaori() {
		if (Hayami < saori) {
			return true;
		}else{
			Hayami = 0;
			try {
				saori = in.read(hayami);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (saori <= 0) {
				return false;
			}
		}
		return true;
	}
	private int SaoriHayami() { 
		if (HayamiSaori()) {
            return hayami[Hayami++];
         }else{
             return -1;
         }
	}
	private static boolean hayami_saori(int hayami) { 
		return 33 <= hayami && hayami <= 126;
	}
	public boolean hayamisaori() { 
		while(HayamiSaori() && !hayami_saori(hayami[Hayami])) Hayami++; return HayamiSaori();
	}
	public String nextHayami() {
		if (!hayamisaori()) throw new NoSuchElementException();
		StringBuilder hayamin = new StringBuilder();
		int saori = SaoriHayami();
		while(hayami_saori(saori)) {
			hayamin.appendCodePoint(saori);
			saori = SaoriHayami();
		}
		return hayamin.toString();
	}
	public long saorihayami() {//nextLong
		if (!hayamisaori()) throw new NoSuchElementException();
		long hayami = 0;
		boolean misao = false;
		int saori = SaoriHayami();
		if (saori == '-') {
			misao = true;
			saori = SaoriHayami();
		}
		if (saori < '0' || '9' < saori) {
			throw new NumberFormatException();
		}
		while(true){
			if ('0' <= saori && saori <= '9') {
				hayami *= 10;
				hayami += saori - '0';
			}else if(saori == -1 || !hayami_saori(saori)){
				return misao ? -hayami : hayami;
			}else{
				throw new NumberFormatException();
			}
			saori = SaoriHayami();
		}
	}
	public int saori_hayami() {//nextInt
		long hayami = saorihayami();
		if (hayami < Integer.MIN_VALUE || hayami > Integer.MAX_VALUE) throw new NumberFormatException();
		return (int) hayami;
	}
	public double Hayamin() { //nextDouble
		return Double.parseDouble(nextHayami());
	}
	public void close() {
		try {
			in.close();
		} catch (IOException e) {
		}
    }
    
}

Measured memory_bytes: 21076
from collections import defaultdict
n = int(input())
a = list(map(int, input().split()))

b = defaultdict(int)
for i in range(n):
    b[a[i]] += 1

ans = 0
for k in b:
    if b[k] >= k:
        ans += b[k] - k
    else:
        ans += b[k]

print(ans)


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

using namespace std;

int main()
{
	int n;
	cin >> n;
	while(1){
		if(n % 1000 == 0){
			cout <<  0 << endl;
			return 0;
		}
		if(n / 1000)
			n %= 1000;
		else
			break;
	}
	cout << 1000 - n  << endl;
}

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

int main() {
  int A,B,C,K;
  cin >> A >> B >> C >> K;
  if(K <= A) {
    cout << K << endl;
  }
  else if(K <= A + B) {
    cout << A << endl;
  }
  else {
    cout << A - (K - (A + B)) << endl;
  }
 
}


Measured memory_bytes: 3636
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define bit(n,k) (((ll)n>>(ll)k)&1) /*nのk bit目*/
const long long INF= 1e+18+1;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll> >vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
const ll MOD=1000000007LL;
//const ll MOD=998244353LL;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
vl dx={-1,-1,-1,0,0,1,1,1};
vl dy={1,-1,0,1,-1,1,0,-1};

int main(){
    ll n,k;cin>>n>>k;
    vl a(n);
    rep(i,n){
        cin>>a[i];a[i]--;
    }
    ll now=0;
    vl vec;
    ll count=0;
    set<ll>S;
    ll key=-1;
    while(true){
      now=a[now];
      if(!S.count(now)){
          S.insert(now);
          vec.push_back(now);
          count++;
      }
      else {
        key=now;
        break;
      }
    }
    //rep(i,vec.size())cout<<vec[i]<<" ";
    //cout<<endl;
    //cout<<count<<endl;
    //cout<<key<<endl;
    ll ite;
    rep(i,count){
        if(vec[i]==key)ite=i;
    }
    if(k-1<=count-1)cout<<vec[k-1]+1<<endl;
    else {
        k-=ite+1;
        //k++;
        //k+=count-ite;
        k%=(count-ite);
        cout<<vec[ite+k]+1<<endl;
        
    }
    /*cout<<ite<<endl;
    cout<<k<<endl;
    cout<<key<<endl;
    rep(j,count)cout<<vec[j]<<" ";
    cout<<endl;
    cout<<count<<endl;*/

}


Measured memory_bytes: 15380
*s, = input()

i = 0
j = -1
n = len(s)
ans = 0

while n > 0:
    if s[i] == s[j]:
        i += 1
        j -= 1
        n -= 2
    else:
        ans += 1
        if s[i] == 'x':
            i += 1
            n -= 1
        elif s[j] == 'x':
            j -= 1
            n -= 1
        else:
            ans = -1
            break

print(ans)

Measured memory_bytes: 79388
N, K = map(int, input().split())
S = input()

if N == 1:
    print(0)
else:
    i = 1
    count = 0
    while i < N:
        if S[i] == S[i - 1]:
            count += 1
        i += 1
    print(min((count + 2 * K), N - 1))


Measured memory_bytes: 3316
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>

using namespace std;

#define NIL -1
#define N 100005

//struct Node{
//	int val;
//	Node *p, *l, *r;
//};

struct Node {
	int p, l, r;
	Node():p(NIL), l(NIL), r(NIL){}
};

Node T[N];
int D[N], H[N];

void getDepth(int u, int d){
	if (u == NIL) return;
	D[u] = d;
	getDepth(T[u].l, d + 1);
	getDepth(T[u].r, d + 1);
}

int getHeight(int u){
	int h1 = 0, h2 = 0;
	if (T[u].l != NIL) h1 = getHeight(T[u].l) + 1;
	if (T[u].r != NIL) h2 = getHeight(T[u].r) + 1;

	return H[u] = max(h1, h2);
}

int getSibling(int u){
	if (T[u].p == NIL) return NIL;
	int p = T[u].p;
	if (T[p].l == u && T[p].r != NIL) return T[p].r;
	if (T[p].r == u && T[p].l != NIL) return T[p].l;

	return NIL;
}

void print(int u){
	int sib = getSibling(u);
	int degree = (NIL != T[u].l) + (NIL != T[u].r);
	printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, ",
		u, T[u].p, sib, degree, D[u], H[u]);

	if (T[u].p == NIL) printf("root");
	else if (degree == 0) printf("leaf");
	else printf("internal node");
	printf("\n");
}


int main(){
	int n; scanf("%d", &n);

	for (int i = 0; i < n; ++i) {
		int u, l, r; scanf("%d %d %d", &u, &l, &r);
		T[u].l = l;
		T[u].r = r;
		if (l != NIL) T[l].p = u;
		if (r != NIL) T[r].p = u;
	}

	int root;
	for (int i = 0; i < n; ++i) if (T[i].p == NIL) root = i;

	getHeight(root);
	getDepth(root, 0);

	for (int i = 0; i < n; ++i) print(i);

	return 0;
}

//node 0: parent = -1, sibling = -1, degree = 2, depth = 0, height = 3, root
//node 1 : parent = 0, sibling = 4, degree = 2, depth = 1, height = 1, internal node
//node 2 : parent = 1, sibling = 3, degree = 0, depth = 2, height = 0, leaf
//node 3 : parent = 1, sibling = 2, degree = 0, depth = 2, height = 0, leaf
//node 4 : parent = 0, sibling = 1, degree = 2, depth = 1, height = 2, internal node
//node 5 : parent = 4, sibling = 8, degree = 2, depth = 2, height = 1, internal node
//node 6 : parent = 5, sibling = 7, degree = 0, depth = 3, height = 0, leaf
//node 7 : parent = 5, sibling = 6, degree = 0, depth = 3, height = 0, leaf
//node 8 : parent = 4, sibling = 5, degree = 0, depth = 2, height = 0, leaf

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

int main(void){
    string s;
  cin >> s;
  int ans = 0;
  for(int i=0; i<4; i++){
  	if(s[i] == '+') ans++;
    else ans--;
  }
  cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3596
solve :: String -> String -> Bool
solve s t = t `elem` rotated
  where rotated = [list2 ++ list1 | i <- [0..(length s - 1)], let (list1, list2) = splitAt i s]

main :: IO ()
main = do
  s <- getLine
  t <- getLine
  putStrLn $ if solve s t then "Yes" else "No"

Measured memory_bytes: 892
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <string>
#include <cmath>
#include <complex>
#include <numeric>
#include <cassert>

#include <vector>
#include <array>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <utility>

#define int64 long long
#define uint64 unsigned long long
using namespace std;

int main()
{
	int64 nn, tmp;
	cin >> nn;
	set<int64> aa;
	for(int64 ii = 0;ii < nn;ii++)
	{
		cin >> tmp;
		aa.insert(tmp);
	}
	if(nn == aa.size())
	{
		puts("YES");
	}
	else
	{
		puts("NO");
	}
	return 0;
}


Measured memory_bytes: 12960
#include<iostream>
using namespace std;
int main()
{
	int k,a,b,cnt;
	cin>>k>>a>>b;
	cnt=0;
	for(int i=a;i<=b;i++){
		if(i%k==0){
	       cout<<"OK\n";
	       cnt++;
	       break;
		}
	}
	if(cnt==0)
	cout<<"NG\n";
	return 0;
	
}

Measured memory_bytes: 3624
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <deque>
#include <queue>
#include <cctype>
#include <cstdio>
#include <math.h>
#include <set>
#define INF 1000000000000
using namespace std;
using ll = long long;
int main(){
    ll n;
    cin >> n;
    ll ans = - 10000000000;
    vector<vector<ll>> f(n,vector<ll>(10));
    vector<vector<ll>> p(n,vector<ll>(11));
    for(ll i=0;i<n;i++){
        for(ll j=0;j<10;j++){
            cin >> f[i][j];
        }
    }
    for(ll i=0;i<n;i++){
        for(ll j=0;j<11;j++){
            cin >> p[i][j];
        }
    }
    for(int bit = 1;bit<(1<<10);bit++){
        ll temp = 0;
        for(int i=0;i<n;i++){
            ll cnt = 0;
            for(int j=0;j<10;j++){
                if(bit&(1<<j)&&f[i][j]==1){
                    cnt++;
                }
            }
            temp+=p[i][cnt];
        }
        if(ans<temp){
            ans = temp;
        }
    }
    cout << ans << endl;
}

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

string num = "0123456789";

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

    int k;
    cin >> k;

    queue<pair<string, int>> q;
    vector<string> Ans;

    int ai = 0;
    for(int i = 1; i <= 9; i++){
        q.push({to_string(i), i});
        Ans.push_back(to_string(i));
        ai++;
    }

    if(k - 1 <= ai){
        cout << Ans[k - 1] << endl;
        return 0;
    }

    while(!q.empty()){
        pair<string, int> t = q.front();
        q.pop();

        string s = t.first;
        int ld = t.second;

        if(ld > 0){
            string x = s + num[ld - 1];
            Ans.push_back(x);
            q.push({x, ld - 1});
        }
        string x = s + num[ld];
        Ans.push_back(x);
        q.push({x, ld});
        if(ld < 9){
            string x = s + num[ld + 1];
            Ans.push_back(x);
            q.push({x, ld + 1});
        }


        if(Ans.size() >= k + 10){
            break;
        }
    }

    cout << Ans[k - 1] << endl;

    return 0;
}

Measured memory_bytes: 7540
#include <iostream>
#include <iostream>
using namespace std;
int main(){
	string str1,str2;
	cin>>str1>>str2;
	int cnt=0;
	for(int i=0;i<str1.size();i++){
		if(str1[i]!=str2[i])
			cnt++;
	}
	cout<<cnt;
}

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

using namespace std;

#define int long long
#define all(v) (v).begin(), (v).end()
#define resz(v, ...) (v).clear(), (v).resize(__VA_ARGS__)
#define reps(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

using Pi = pair<int, int>;
using Ti = tuple<int, int, int>;
using vint = vector<int>;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int n, a, b;
  cin >> n >> a >> b;
  cout << ((b-a)%2 ? "Borys" : "Alice") << endl;

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){

    long long int n;
    scanf("%lld",&n);
    
    int revAns[15];
    int revAnsNum=0;
    long long int keta=1;
    long long int minus=0;
    
    while(((n-minus)/keta)>=0){
    revAns[revAnsNum]=((((n-minus-1)/keta))%26);
    revAnsNum++;
    keta*=26;
    minus+=keta;
    //printf("%d %lld %lld %lld %lld\n",revAnsNum,keta,minus,n,(n-minus)/keta);
    }
    
    //printf("%d ",revAnsNum);
    
    for(int i = revAnsNum-2;i>=0;i--){
        printf("%c",97+revAns[i]);
    }
    
    
    
    /*while(n>0){
    
    i=n%26;
    n/=26;
    printf("%d ",i);
    }*/
 
 

 return 0;
}


Measured memory_bytes: 1644
MOD=10**9+7
N,M=gets.split.map(&:to_i)
A=M.times.map{gets.to_i}

broken = Hash.new(false)
A.each do |aa|
    broken[aa] = true
end

dp=Array.new(N+1,0)
dp[0]=1
(0..N-1).each do |i|
    next if broken[i]
    (i+1..i+2).each do |ni|
        next if ni > N || broken[ni]
        dp[ni] = (dp[ni] + dp[i]) % MOD
    end
end
p dp[N]


Measured memory_bytes: 9852
def d_walk_and_teleport(N, A, B, X):
    # 西から東に1つずつ、歩くかテレポートのどちらか疲労しない方で進む
    ans = sum([min(A * (X[k + 1] - X[k]), B) for k in range(N - 1)])
    return ans

N,A,B = [int(i) for i in input().split()]
X = [int(i) for i in input().split()]
print(d_walk_and_teleport(N, A, B, X))

Measured memory_bytes: 14480
#include<stdio.h>
int main()
{
    int n,min=1,max,j=0,b=0,c=0,d=0,e=0,f=0,g=0,h=0,k=0;
    scanf("%d",&n);
    int i,no;
    for(i=1;i<=n;i++)
    {
        scanf("%d",&no);
        if(no>=1 && no<=399)
        {
            b=1;
        }
        else if(no>=400 && no<=799)
        {
           c=1;
        }
        else if(no>=800 && no<=1199)
        {
            d=1;
        }
        else if(no>=1200 && no<=1599)
        {
            e=1;
        }
        else if(no>=1600 && no<=1999)
        {
            f=1;
        }
        else if(no>=2000 && no<=2399)
        {
            g=1;
        }
        else if(no>=2400 && no<=2799)
        {
           h=1;
        }
        else if(no>=2800 && no<=3199)
        {
            j=1;
        }
        else
        {
           k++;
        }
    }
    min=b+c+d+e+f+g+h+j;
    max=b+c+d+e+f+g+h+j+k;
    if(k==0)
    {
        printf("%d %d\n",min,min);
    }
    else if(min==0 && k>=1)
    {
        printf("1 %d\n",max);
    }
    else
    {
        printf("%d %d\n",min,max);
    }
    return 0;
}


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

using namespace std;

int A[100000];
int f[100001];

int main()
{
  int N;
  cin>> N;
  for(int i=0;i<N;i++)cin>> A[i];

  f[0]=abs(A[0]);
  for(int i=1;i<N;i++)f[i]=f[i-1]+abs(A[i]-A[i-1]);
  f[N]=f[N-1]+abs(A[N-1]);
  for(int i=0;i<N;i++)
  {
    int ret=f[N]-f[i+1];
    if(i==0)
    {
      ret+=abs(A[i+1]);
    }
    else
    {
      ret+=f[i-1]+abs(A[i+1]-A[i-1]);
    }
    cout<< ret<< endl;
  }

  return 0;
}


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

int main()
{
    int n;
    cin >> n;
    vector<ll> a(n);
    for(int i=0; i<n; ++i) cin >> a[i];
    ll h = 0;
    for(int i=1; i<n; ++i){
        if (a[i-1] > a[i]) {
            h += a[i-1] - a[i];
            a[i] = a[i-1];
        }
    }
    cout << h;
    return 0;
}


Measured memory_bytes: 4836
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <random>
#include <cstdio>
#include <cmath>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int) n; i++)
int main() {
    int a,b,c; cin >> a >> b >> c;
    if (a+b >= c)
    {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
void solve(long long N, long long K, std::vector<long long> P, std::vector<long long> C){
    Graph G(N);
    vector<bool> reached(N,false);
    stack<pair<long long,long long>> st;
    for (int i = 0;i<N;i++){
        P[i]--;
    }
    ll ans=-100000000000000000;
    for (int v=0;v<N;v++){
        ll x = v;
        vector<ll> s;
        ll tot = 0;
        while(1){
            x = P[x];
            s.push_back(C[x]);
            tot +=C[x];
            if(x==v){
                break;
            }
        }
        ll l = s.size();
        ll t = 0;
        for(int i = 0;i<l;i++){
            t+=s[i];
            if(i+1>K) break;
            ll now = t;
            if(tot>0){
                ll cycle = (K-1-i)/l;
                now+=cycle*tot;
            }
            ans =max(ans,now);
        }
    }
    cout<<ans<<endl;
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    long long K;
    scanf("%lld",&K);
    std::vector<long long> P(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&P[i]);
    }
    std::vector<long long> C(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&C[i]);
    }
    solve(N, K, std::move(P), std::move(C));
    return 0;
}


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

int main() {
  int A, B, C ,D;
  cin >> A >> B >> C >> D; 
    
    if(A + B - C - D > 0){
      cout << "Left" << endl;
    }

    if(A + B - C - D == 0){
      cout << "Balanced" << endl;
    }
  
    if(A + B - C - D < 0){
      cout << "Right" << endl;
    }

}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String[] args) {  
  		Scanner sc = new Scanner(System.in);
      	int N = sc.nextInt();
      	
      	if(N %2 == 0) {
        	System.out.println(N);
        } else {
          	System.out.println(N * 2);
        }
    }
}

Measured memory_bytes: 25684
//Solution：二分答案。 
#include<bits/stdc++.h>
inline int read(){
   int s=0,w=1;
   char ch=getchar();
   while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
   while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
   return s*w;
}
using namespace std;
int n=read(),a[1000003];
int tree[2000003];
int find(int x)
{
	int res=0;
	while(x) res+=tree[x],x-=x&(-x);
	return res;
}
void add(int x)
{
	while(x<=2000000) ++tree[x],x+=x&(-x);
}
bool check(int x)
{
	long long sum=0;
	int k=1000000;
	memset(tree,0,sizeof(tree)),add(1000000);
	for(int i=1; i<=n; i++) 
	{
		if(a[i]>=x) ++k; else --k;
		sum+=find(k),add(k);
	}
	return sum>=1ll*n*(n+1)/4;
} 
int main()
{
	for(int i=1; i<=n; i++) a[i]=read();
	if(n==1) printf("%d\n",a[1]),exit(0);
	int l=0,r=1000000001,ans=0;
	while(l<=r)
	{
		int mid=(l+r)/2;
		if(check(mid)) ans=mid,l=mid+1; else r=mid-1;
	}
	printf("%d\n",ans);
	return 0;
}



Measured memory_bytes: 11896
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <vector>
#include <limits.h>
#include <math.h>

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

using namespace std;

typedef long long ll;
typedef pair<int,int> Pii;
typedef vector<int> vint;
const int INF = INT_MAX;
const int MAX_P = 55555+1;

int digitsum(int n){
    int ret = 0;
    while(n>0){
        ret += n%10;
        n /= 10;
    }
    return ret;
}

int main() {
    // insert code here...    return 0;
    //////
    // input from txt
    /*
     std::ifstream in("input.txt");
     std::cin.rdbuf(in.rdbuf());
     std::ofstream out("output.txt");
     std::cout.rdbuf(out.rdbuf());
     ////
     */
    int N;
    cin >>N;
    //cout << digitsum(N) << endl;
    int ans = INF;
    repeat(i, N/2){
        int A = i+1;
        int B = N-A;
        ans = min(ans,digitsum(A)+digitsum(B));
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using i64 = int_fast64_t;
#define rep(i, N) for(int (i) = 0; (i) < (N); (i)++)
#define all(v) (v).begin(), (v).end()
#define eb emplace_back
#define Cout(s) cout << s << endl
string Yes(bool b) {if(b){return "Yes";} else {return "No";}}
string YES(bool b) {if(b){return "YES";} else {return "NO";}}


int main(){
	int H, W;
	cin >> H >> W;
	rep(i, H)rep(j ,W){
		string S; cin >> S;
		if(S == "snuke"){
			cout << char('A' + j) << i+1 << endl;
			return 0;
		}
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define pb push_back
#define ll long long
#define ld long double
#define fi first
#define se second
#define INF 1e18

const ll mod = 1000000000+7;
const int N = 100000+5;

ll dp[100+5][N];
int a[N];

ll g(int i, int j, int k)
{
	if(j<=0)return dp[i][k];
	return (dp[i][k] - dp[i][j-1])%mod;
}

main()
{ 
	SPEED;
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int n,k;
	cin >> n >> k;
	for(int i = 1; i<=n; i++)
	{
		cin >>a[i];
	}
	for(int i = 0 ;i <=k; i++)dp[0][i] = 1;
	for(int i = 1; i<=n;i++)
	{
		for(int j = 0; j<=k; j++)
		{
			if(j==0){dp[i][j] = 1;continue;}
			int x = min(j,a[i]);
			dp[i][j] = g(i-1,j-x,j) + dp[i][j-1];
			if(dp[i][j]>=mod)dp[i][j] -= mod;
			if(dp[i][j]<0)dp[i][j] += mod;
		}
	}
	cout << (dp[n][k] - dp[n][k-1]+mod)%mod<< endl;
}

Measured memory_bytes: 79744
nd=list(map(int,input().split()))
listx=[]
count=0#整数型の個数をカウント
for i in range(nd[0]):
    listx=listx+[list(map(int,input().split()))]
for i in range(nd[0]-1):
    for k in range(i+1,nd[0]):
        d2=0
        for n in range(nd[1]):
            d2+=(listx[i][n]-listx[k][n])**2
        if float.is_integer(d2**0.5)==True:
                count+=1
print(count)

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

int main() {
  string S;
  cin >> S;
  string T = "?";
  if (S == "Sunny")
    T = "Cloudy";
  if (S == "Cloudy")
    T = "Rainy";
  if (S == "Rainy")
    T = "Sunny";
  cout << T << endl;
}

Measured memory_bytes: 256
import sys
import itertools
# import numpy as np
import time
import math
import heapq
from collections import defaultdict
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())

S = [0] * 3
S[0] = input()
S[1] = input()
S[2] = input()

cur = 0
while True:
    if len(S[cur]) > 0:
        nx = ord(S[cur][0]) - ord('a')
        S[cur] = S[cur][1:]
        cur = nx
    else:
        print(chr(ord('A') + cur))
        break



Measured memory_bytes: 9256
#include<bits/stdc++.h>
#define ll long long 
#define pb push_back
using namespace std ; 
int main(){
	int x ; 
	cin>> x ; 
	ll ans = 0 ; 

	int m  = x/ 500 ; 
	ans = m *1000 ; 
	x = x%500 ; 
    m = x/5 ; 
	ans = ans + m *5 ; 


cout<<ans<<endl;
	
	
	
	
	
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <stack> // s.top()
#include <bitset>
#include <queue> // s.front()
using namespace std;

typedef long long Int;
typedef pair<Int,Int> P;
#define print(x) cout<<(x)<<endl

#define INF10 10000000000
#define INF5 100000
#define EPS 1e-10
#define MOD 1000000007

 

int main() {
	int N; vector<int> a;
	cin >> N;
	for (int i = 0; i < N; i++) {
		int ptx;
		cin >> ptx;
		a.push_back(ptx);
	}
	sort(a.begin(), a.end());
	print(a.back() - a.front());








	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int N,ans,i;
double A,T,H,tmp=1000000;
int main(){
  cin >> N >> T >> A;
  for(i=1;i<=N;i++){
    cin >> H;
    //cout << fabs(A-(T-H*0.006)) << endl;
    if(tmp>fabs(A-(T-H*0.006))){
      ans=i;
      tmp=fabs(A-(T-H*0.006));
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
/*
	Auther:_Destiny
	time:2020.5.10
*/
#include <bits/stdc++.h>
#define ll long long
#define N 100010
#define M 20

using namespace std;
int n, m, k, val[M];
int jia[M][M]; bool xuan[M];
int ans = 1e9;

int read() {
	int s = 0, f = 0; char ch = getchar();
	while (!isdigit(ch)) f |= (ch == '-'), ch = getchar();
	while (isdigit(ch)) s = s * 10 + (ch ^ 48), ch = getchar();
	return f ? -s : s;
}

void check(int zhi) {
	int aaa[20] = {0};
	for (int i = 1; i <= n; i++)
		if (xuan[i]) {
			for (int j = 1; j <= m; j++)
				aaa[j] += jia[i][j];
		}
	int flag = 0;
	for (int i = 1; i <= m; i++)
		if (aaa[i] < k) {
			flag = 1;
			break;
		}
	if (!flag) ans = min(ans, zhi);
}

void dfs(int x, int sum) {
	if (x == n + 1) {
		check(sum);
		return;
	}
	for (int i = 0; i <= 1; i++)
		if (i == 0) dfs(x + 1, sum);
		else {
			xuan[x] = 1;
			dfs(x + 1, sum + val[x]);
			xuan[x] = 0;
		}
}

int main() {
	n = read(), m = read(), k = read();
	for (int i = 1; i <= n; i++) {
		val[i] = read();
		for (int j = 1; j <= m; j++)
			jia[i][j] = read();
	}
	dfs(1, 0);
	if (ans == 1e9) puts("-1");
	else cout << ans << "\n";
}

Measured memory_bytes: 3636
#include<iostream>
#include<bits/stdc++.h>
#include<iomanip>
#include<math.h>
#include<vector>
#include<cctype>
#include<string>
#include<set>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
std::string line;
typedef long long ll;

int main(){

   string s;
   cin >> s;

   int ans = 0;

   rep(i,s.size()){
   if(s[i]=='+'){
      ans++;
   }else{
      ans--;
   }
   }
   cout << ans << endl;

   return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cassert>
#include <algorithm>
#include <functional>
#include <vector>
#include <string>
#include <cstring>
#include <stack>
#include <queue>
#include <map>
#include <bitset>
#include <sstream>
#include <istream>
#include <cmath>
#include <cstdio>

using namespace std;

#define vci vector<int>
#define vcs vector<string>
#define pb push_back
#define sz size()
#define mapii map<int, int>
#define mapci map<char, int>
#define mapsi map<string, int>
#define all(x) x.begin(), x.end()
#define minit(a, i) memset(a, i, sizeof(a));

#define for_(i, a, b) for (int i=(int)a; i<(int)b; i++)
#define for_d(i, a, b) for (int i=(int)a-1; i>=b; i--)
#define for_r(i, a, b, c) for (int i=(int)a; i<(int)b; i += c)
#define for_dr(i, a, b, c) for (int i=(int)a-1; i>=b; i -= c)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

typedef long long ll;
typedef double D;

const int iINF = 2147483647;
const ll lINF = 9223372036854775807;

template <class T> inline void dbg(T t) { cout << t << endl; }


int solve(string input) {
	string now = "", next = input;
	
	for_(i, 0, 9) {
		now = next;
		next = "";
		
		for_(j, 0, (int)now.sz - 1) {
			int l = now[j] - '0', r = now[j+1] - '0';
			int t = (l+r)%10;
			next += '0'+t;
		}
	}
	
	return next[0] - '0';
}


int main() {
	string input;
	
	while (cin>>input) {
		cout << solve(input) << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1196
#include<stdio.h>

int main()
{

   int i;

   long long int H,N,sum=0,arr[100000];

   scanf("%lld %lld",&H,&N);

   for(i=0;i<N;i++)
   {

     scanf("%lld",&arr[i]);

     sum = sum + arr[i];

   }

   if(sum>=H)
   {
     printf("Yes\n");
   }

   else if(sum<H)
   {
     printf("No\n");
   }


   return 0;
}


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

int main(){
    int n,t;
    cin >> n >> t;
    vector<int> h(n);
    for(int i=0; i<n; i++){
        cin >> h[i];
    }
    int hmax = 0;
    for(int i=0; i<n; i++){
        hmax = max(hmax, h[i]);
        int ans = t /hmax;
        if(t %hmax >= h[i]){
            ans++;
        }
        t = max(0, t -h[i]);
        cout << ans +1 << endl;
    }
    return 0;
}


Measured memory_bytes: 3120
#include<bits/stdc++.h>
using namespace std;
int main(){
  char a[102], b[102];
  cin >> a >> b;
  int x = strlen(a);
  string c, d;
  c=a;
  d=b;
  if(c==d){
    cout << "Yes\n";
    return 0;
  }
  for(int i=0; i<x; i++){
    char firstLetter=a[x-1];
    char te=a[0];
    for(int j=0; j<x-1; j++){
      char te2;
      te2=a[j+1];
      a[j+1]=te;
      te=te2;
    }
    a[0]=firstLetter;
    string w=a;
    if(w==b){
      cout << "Yes\n";
      return 0;
    }
  }
  cout << "No\n";
  return 0;
  
}

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

using namespace std;

int main() {
	int N,A,B;
	cin >> N>>A>>B;
	int ans = 0;
	for (int i = 1;i<=N;++i) {
		int ntemp = i;
		int memo = 0;
		while (0 != ntemp) {
			memo += ntemp % 10;
			ntemp /= 10;
		}
		if ((memo <= B) && (memo >=A)) {
			ans += i;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3640
#include<cstdio>

int main(){
	double v;
	int n;
	while(scanf("%lf", &v) + 1){
		n = 1;
		while(n)
		{
			n++;
			if(v * v <= 2 * 9.8 * (5 * n - 5)){
				printf("%d\n", n);
				n = 0;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1056
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <numeric>
#include <math.h>
#include <map>
#include <stack>
using namespace std;
typedef long long int ll;

constexpr ll mod=1e9+7;

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<int> x(n);
    for(int i=0;i<n;i++){
        cin >> x[i];
    }
    ll res=1;
    ll p=0;
    for(int i=0;i<n;i++){
        if(x[i]>=2*p+1)p++;
        else (res*=(p+1))%=mod;
    }
    for(int i=1;i<=p;i++){
        (res*=i)%=mod;
    }
    cout << res << endl;
}

Measured memory_bytes: 640
// tested by Hightail - https://github.com/dj3500/hightail
import std.stdio, std.string, std.conv, std.algorithm;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;

void main() {
    readln;
    readln.split.to!(int[]).sort().chunks(2).map!"min(a[0], a[1])".sum.writeln;
}


void scan(T...)(ref T args) {
    string[] line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}


void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

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


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

    if(n % 1000 == 0){
        cout << 0 << endl;
    }
    else{
        int pay = (n / 1000 + 1)*1000;
        cout << pay - n << endl;
    }

    return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <functional>
#include <algorithm>
#include <numeric>
using namespace std;


int main()
{
        int N, M;
        cin >> N >> M;
        vector<int> X(M), Y(M-1);
        if(N >= M) cout << 0;
        else{
        for(int i=0; i<M; i++){
                cin >> X[i];
        }
        sort(X.begin(), X.end());
        for(int i=0; i<M-1; i++){
                Y[i] = X[i+1] - X[i];
        }
        sort(Y.begin(), Y.end());
        for(int i=0; i<N-1; i++){
                Y.pop_back();
                }
        cout << accumulate(Y.begin(), Y.end(), 0);

}
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define DB(x) cerr << __LINE__ << ": " << #x << " = " << (x) << "\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
using namespace std;

int main() {
	IOS;

	ll n, m, v, p, a[100005], used[100005];
	set<ll> distinct;
	cin >> n >> m >> v >> p;
	for(ll i = 1; i <= n; ++i) {
		cin >> a[i];
		distinct.insert(-1*a[i]);
	}
	sort(a+1, a+n+1);
	ll store=n+1, low = 1, high = n, pth = -1;
	
	ll distinctcount = 0;
	for(auto it: distinct) {
		++distinctcount;
		if(distinctcount == p) {
			pth = -1*it;
			break;
		}
	}

	while(low <= high) {
		ll mid = (low+high)/2;
	
		// code start
		ll pos = 0;
		if(mid >= v) {
			if(a[mid] + m >= a[n-p+1]) pos = 1;
		}
		else {
			ll left = m*v - mid*m, great = 0, val = a[mid] + m;
			for(ll i = n; i >= mid+1; --i) {
				if(a[i] > val) {
					left -= m;
					++great;
					continue;
				}
				used[i] = min(m, val - a[i]);
				left -= used[i];
			}
			if(great < p && left <= 0) pos = 1;
			else if(great < p) {
				for(ll i = n; i >= mid+1; --i) {
					if(a[i] > val) {
						continue;
					}
					if(used[i] != m) ++great;
					left -= (m - used[i]);
					if(left <= 0) break;
				}	
				if(great < p && left <= 0) pos = 1;
			}
		}
		// code over
	
		if(pos) {
			high = mid-1;
			store = mid;
		}
		else low = mid+1;
	}
	cout << n-store+1;
    return 0;
}


Measured memory_bytes: 6528
def main():
  input()
  in_a = list(map(int, input().split()))
  leaves = [0] * len(in_a)
  leaves[-1] = in_a[-1]

  if in_a[0] > 1:
    print(-1)
    return

  #for i in range(len(in_a)-2, -1, -1):
  #  leaves[i] = leaves[i+1] + in_a[i]

  for i in range(len(in_a) - 1, 1, -1):
    leaves[i-1] = leaves[i] + in_a[i-1]
    
  node = 1
  total = 1
  
  for i in range(1, len(in_a)):
    n = (node - in_a[i-1]) * 2

    if n < in_a[i]:
        print(-1)
        return

    node = min(n, leaves[i])
    total += node

  print(total)

if __name__ == '__main__':
  main()
    


Measured memory_bytes: 83416
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v).begin(), (v).end()
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define DEBUG
#define int long long
#define INF 1e18
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<"\n";}
typedef long long ll;


signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int d,t,s;
    cin>>d>>t>>s;
    if(s*t<d){
        cout<<"No"<<endl;
    }
    else cout<<"Yes"<<endl;
    return 0;
}

Measured memory_bytes: 3656
#include "bits/stdc++.h"
using namespace std;

#define fren bigounce
#define speedup ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
#define endl "\n"
#define mt make_tuple
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define usaco(in,out) ifstream cin(in); ofstream cout(out)
#define all(X) (X).begin(), (X).end()
#define sz(X) ((int)X.size())
#define erase_dupes(X) sort(all(X)); (X).resize(distance((X).begin(), unique(all(X))));
#define decimal(X) cout << fixed << setprecision(X)
#define mst(X,Y) memset(X,Y,sizeof(X));

typedef long long LL;
typedef double DBL;
typedef pair<int,int> PII; 
typedef pair<LL,LL> PLL;
typedef pair<string, int> PSI;
typedef pair<int,string> PIS;
typedef vector<PSI> VPSI;
typedef vector<PIS> VPIS;
typedef pair<char,int> PCI;
typedef pair<int,char> PIC;
typedef vector<PCI> VPCI;
typedef vector<PIC> VPIC;
typedef vector<PII> VPII;
typedef vector<PLL> VPLL;
typedef vector<LL> VLL;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef long double LD;
typedef pair<LD,LD> PLD;
typedef vector<LD> VLD;
typedef vector<PLD> VPLD;

template<class TH> void _dbg(const char *sdbg, TH h) { 
	cerr<<sdbg<<" = "<<h<<endl;
}

template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',') cerr<<*sdbg++;
  cerr<<" = "<<h<<", "; _dbg(sdbg+1, a...);
}

#define LOCAL
#define SEPERATOR cout << "-----------------------------------------" << endl;

#ifdef LOCAL
	#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
	#define dbg(...)
	#define cerr if(0)cout
#endif

const int maxn = 1e5+7;
const int inf = 1e9+7;
const LL LLinf = ((LL)1e18)+7LL;
const LD eps = 1e-9;

// **************************************** NICE **************************************** //
// ~/~/~/~/~/~/~/~/~/~/~/~/~/~/ A PRO_GEMR Special... Enjoy! \~\~\~\~\~\~\~\~\~\~\~\~\~\~ //

int n;
VI dp(3), dp2(3), a(3);

int main() {
	speedup
	
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[0] >> a[1] >> a[2];
		for (int j = 0; j < 3; j++) {
			for (int k = 0; k < 3; k++) {
				if (j != k) {
					dp2[k] = max(dp2[k],dp[j]+a[k]);
				}
			}
		}
		dp = dp2;
	}
	
	cout << max({dp[0],dp[1],dp[2]});
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define sum accumulate
typedef long long ll;
const int INF = 100000000;
const long INF64 = 1000000000000000ll;
const ll MOD = 998244353LL;
int main(){
	int a,b,c;
	std::cin >> a>>b>>c;
	if(a<b&&b<c)std::cout << "Yes" << std::endl;
	else std::cout << "No" << std::endl;
}


Measured memory_bytes: 3116
#include<iostream>
#include<vector>
#include<map>
#include<queue>
#include<algorithm>
#define rep(i,n) for(int i=0;i<(n);i++)
#define INF 1e9
using namespace std;

typedef pair<int,int> P;
typedef pair<int,P> iP;
struct edge{P to;int cost;};

map<P,vector<edge> > G;
int p[200001],q[200001],c[200001];
int n,m;
map<P,int> d;

void dijkstra() {
    priority_queue<iP,vector<iP>,greater<iP> > que;

    que.push(iP(0,P(0,-1)));
    d[P(0,-1)] = 0;

    while(!que.empty()) {
        iP p = que.top();que.pop();
        if(d[p.second] < p.first) continue;
        rep(i,G[p.second].size()) {
            if(d.find(G[p.second][i].to)==d.end()||d[G[p.second][i].to] > d[p.second] + G[p.second][i].cost ) {
                d[G[p.second][i].to] = d[p.second] + G[p.second][i].cost;
                que.push(iP(d[G[p.second][i].to],G[p.second][i].to));
            }
        }
    }

}

int main(int argc, char const *argv[])
{
    cin >> n >> m;

    rep(i,m) {
        cin >> p[i] >> q[i] >> c[i];
        p[i]--;q[i]--;
        G[P(p[i],c[i])] = vector<edge>();
        G[P(q[i],c[i])] = vector<edge>();
    }

    rep(i,m) {
        G[P(p[i],c[i])].push_back((edge){P(q[i],c[i]),0});
        G[P(q[i],c[i])].push_back((edge){P(p[i],c[i]),0});
    }
    rep(i,n)G[P(i,-1)] = vector<edge>();

    rep(i,m) {
        G[P(p[i],c[i])].push_back((edge){P(p[i],-1),0});
        G[P(q[i],c[i])].push_back((edge){P(q[i],-1),0});
        G[P(p[i],-1)].push_back((edge){P(p[i],c[i]),1});
        G[P(q[i],-1)].push_back((edge){P(q[i],c[i]),1});
    }

    dijkstra();

    if(d.find(P(n-1,-1)) != d.end())cout << d[P(n-1,-1)] << endl;
    else cout << -1 << endl;

    return 0;
}


Measured memory_bytes: 96692
import java.util.*;
public class Main
{
	public static void main(String arg[])
	{
		Scanner in=new Scanner(System.in);
		for(;;)
		{
			int n=in.nextInt();
			int m=in.nextInt();
			int tmp=m;
			int ans=0;
			if((n|m)==0)
				return;
			boolean[] a=new boolean[n+1];
			Arrays.fill(a, true);
			a[tmp]=false;
			for(;;)
			{
				int cn=0;
				int j=0;
				for(;;)
				{
					if(tmp+1>n)
						tmp=0;
					if(a[++tmp])
						cn++;
					if(cn==m)
						break;
				}
				a[tmp]=false;
				ans=tmp;
				for(int k=1;k<a.length;k++)
				{
					if(a[k])
					{
						j=0;
						break;
					}
					j=1;
				}		
				if(j==1)
					break;
			}
			System.out.println(ans);
		}
	}
}

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

typedef long long int lli;
typedef unsigned long long int ulli;
typedef pair<int,int> pii;
typedef priority_queue< int, vector< int >, greater< int > >  minHeap;

#define ones(x) __builtin_popcount(x)
#define onesl(x) __builtin_popcountl(x)
#define onesll(x) __builtin_popcountll(x)

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define scn(n) scanf("%d",&n)
#define scnll(n) scanf("%lld",&n)
#define scn2(n,m) scanf("%d%d",&n,&m)
#define scn3(n,m,w) scanf("%d%d%d",&n,&m,&w)
#define scn2ll(n,m) scanf("%lld%lld",&n,&m)
#define atoz(v) v.begin(),v.end()
#define ratoz(v) v.rbegin(),v.rend()
#define Fill(a,v) memset(a,v,sizeof(a))
#define sz(v) v.size()
#define fi first
#define se second
#define inf 1e9
#define pi acos(-1.0)
#define sqr(x) x*x
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define ten(n) (int)1e##n
#define tenll(n) (lli)1e##n
#define mod 1000000007
#define FastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

int Set(int N,int pos)
{
    return N=N | (1<<pos);
}
int reset(int N,int pos)
{
    return N = N & ~(1<<pos);
}
bool check(int N,int pos)
{
    return (bool)(N & (1<<pos));
}


inline int addmod(int x ,int y){return (x%mod + y%mod)%mod;}
inline int submod(int x ,int y){return (x%mod - y%mod + mod)%mod;}
inline int mulmod(int x ,int y){return (x%mod *1LL* y%mod)%mod;}
inline int nextSubMask(int i , int mask) {return (i-1)&mask;} /// returns next smallest submask

void we_r_done(){cout<<"NO"; exit(0);}

void debug(bool ok , string mssg)
{
    if(ok)return;
    cout<<mssg;
    exit(0);
}

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

    FastIO;

    int n;
    cin>>n;

    int a[n];

    set<int>st;
    map<int,int>cnt;

    for(int i=0; i<n; i++){
        cin>>a[i];
        st.insert(a[i]);
        cnt[a[i]]++;
    }
    int more = 0;

    for(auto it : cnt){

        if(it.se>1){
            if(it.se%2==0){
                more++;
            }
        }
    }
    int ans = st.size();
    if(more%2) ans--;

    cout<<ans;

    return 0;

}

///sin and cos expect input in radians not degrees. so use , sin(degrees * pi / 180)
///using bs = bitset<MX>; // how many distinct number can be form?


Measured memory_bytes: 9984
M=10**9+7
s=input()
r=range
dp=[[0]*13,[0]*13]
dp[0][0]=1
t=0
for c in s:
  for i in r(13):
    if c=='?':
      for j in r(10):
        dp[t^1][(i*10+j)%13]+=dp[t][i]
    else:
      dp[t^1][(i*10+int(c))%13]+=dp[t][i]
  dp[t]=[0]*13
  t^=1
  for i in r(13): dp[t][i]%=M
print(dp[len(s)%2][5])

Measured memory_bytes: 42988
b,c,d,e,f,t;main(a){for(;~scanf("%d%d%d%d%d%d",&a,&b,&c,&d,&e,&f);printf("%.3f %.3f\n",(c*e-b*f+0.)/t+0.,(a*f-c*d+0.)/t+0.))t=a*e-b*d;}

Measured memory_bytes: 0
// =================================
//   author: memset0
//   date: 2019.03.20 21:58:38
//   website: https://memset0.cn/
// =================================
#include <bits/stdc++.h>
#define ll long long
#define debug(...) ((void)0)
#ifndef debug
#define debug(...) fprintf(stderr,__VA_ARGS__)
#endif
namespace ringo {
template <class T> inline void read(T &x) {
    x = 0; register char c = getchar(); register bool f = 0;
    while (!isdigit(c)) f ^= c == '-', c = getchar();
    while (isdigit(c)) x = x * 10 + c - '0', c = getchar();
    if (f) x = -x;
}
template <class T> inline void print(T x) {
    if (x < 0) putchar('-'), x = -x;
    if (x > 9) print(x / 10);
    putchar('0' + x % 10);
}
template <class T> inline void print(T x, char c) { print(x), putchar(c); }

const int N = 10;
int n, m, ans = true, a[N][N];

void main() {
    read(n), read(m);
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++) {
            char c = getchar();
            while (c != '#' && c != '.') c = getchar();
            a[i][j] = c == '#';
        }
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++)
            if (a[i][j]) {
                if (i != n && j != m) {
                    if (a[i + 1][j] && a[i][j + 1])
                        ans = false;
                    if (!a[i + 1][j] && !a[i][j + 1])
                        ans = false;
                }
                if (i != 1 || j != 1) {
                    if (a[i - 1][j] && a[i][j - 1])
                        ans = false;
                    if (!a[i - 1][j] && !a[i][j - 1])
                        ans = false;
                }
            }
    puts(ans ? "Possible" : "Impossible");
}

} signed main() { return ringo::main(), 0; }

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(void)
{
    int A, B, C;

    cin >> A >> B >> C;

    if(A==B){
        cout << C << endl;
    }
    else if(B==C){
        cout << A << endl;
    }
    else{
        cout << B << endl;
    }

    return 0;
}

Measured memory_bytes: 256