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

int main() {
	ll n;
	cin >> n;
	vector<ll> a(n);
	for (ll i = 0; i < n; ++i)cin >> a[i];
	vector<vector<ll>> dp(n, vector<ll>(3));
	dp[0][0] = 1000;
	dp[0][1] = 1000 / a[0];
	dp[0][2] = 1000 % a[0];
	for (ll i = 1; i < n; ++i) {
		dp[i][0] = max(dp[i - 1][0], dp[i - 1][1] * a[i] + dp[i - 1][2]);
		if (dp[i - 1][0] / a[i] > dp[i - 1][1] || (dp[i - 1][0] / a[i] == dp[i - 1][1] && dp[i - 1][0] % a[i] > dp[i - 1][2])) {
			dp[i][1] = dp[i - 1][0] / a[i];
			dp[i][2] = dp[i - 1][0] % a[i];
		}
		else {
			dp[i][1] = dp[i - 1][1];
			dp[i][2] = dp[i - 1][2];
		}
	}
	cout << dp.back()[0] << endl;
}


Measured memory_bytes: 3640
// D.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <vector>
#include <cmath>

using namespace std;
typedef long long LL;

int main(int argc, char* argv[]) {
	LL n, ans = 0;
	cin >> n;
	vector<LL> p;
	for (LL x = 2; x <= 1000000; ++x) {
		if ((n % x) == 0) {
			LL r = 1;
			while ((n % x) == 0) {
				n /= x;
				r *= x;
			}
			for (LL i = x; i <= r; i *= x) {
				++ans;
				r /= i;
			}
		}
	}
	if (n > 1) {
		++ans;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3636
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#include <iostream>
#include <sstream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <bitset>
#include <complex>
#include <array>
#include <list>
#include <stack>
#include <valarray>

using namespace std;

typedef unsigned uint;
typedef long long Int;
typedef unsigned long long UInt;

const int INF = 1001001001;
const Int INFLL = 1001001001001001001LL;

template<typename T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<typename T> void chmin(T& a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T& a, T b) { if (a < b) a = b; }
int in() { int x; scanf("%d", &x); return x; }
double fin() { double x; scanf("%lf", &x); return x; }
Int lin() { Int x; scanf("%lld", &x); return x; }

Int P[100050], Q[100050];

int main() {
  int W = in();
  int H = in();

  for (int i = 0; i < W; ++i) {
    P[i] = lin();
  }
  for (int i = 0; i < H; ++i) {
    Q[i] = lin();
  }
  sort(P, P + W);
  sort(Q, Q + H);

  int w = W, h = H;
  Int res = 0;
  int i = 0, j = 0;
  while (i < W || j < H) {
    if (j < H && (i == W || P[i] > Q[j])) {
      res += Q[j] * (w + 1);
      --h;
      ++j;
    } else {
      res += P[i] * (h + 1);
      --w;
      ++i;
    }
  }

  printf("%lld\n", res);

  return 0;
}


Measured memory_bytes: 1920
import java.util.*;

public class Main {
	
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int h = sc.nextInt();
		int w = sc.nextInt();
		int[][] field = new int[h][w];
		for (int i = 0; i < h; i++) {
		    for (int j = 0; j < w; j++) {
		        field[i][j] = sc.nextInt();
		    }
		}
		StringBuilder sb = new StringBuilder();
		int count = 0;
		int total = 0;
		int hh = 0;
		int ww = 0;
		while (count < h * w - 1) {
	        int nh;
	        int nw;
	        if (hh % 2 == 0) {
	            if (ww == w - 1) {
	                nh = hh + 1;
	                nw = ww;
	            } else {
	                nh = hh;
	                nw = ww + 1;
	            }
	        } else {
	            if (ww == 0) {
	                nh = hh + 1;
	                nw = ww;
	            } else {
	                nh = hh;
	                nw = ww - 1;
	            }
	        }
		    if (field[hh][ww] % 2 == 1) {
		        field[hh][ww]--;
		        field[nh][nw]++;
		        sb.append(hh + 1).append(" ").append(ww + 1).append(" ").append(nh + 1).append(" ").append(nw + 1).append("\n");
		        total++;
		    }
		    hh = nh;
		    ww = nw;
		    count++;
		}
		System.out.println(total);
		System.out.print(sb);
	}
	
}


Measured memory_bytes: 94136
#include<iostream>
#include<vector>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> H(N);
  int i,min=1000000001;
  bool flag=true;
  for(i=0;i<N;i++)cin >> H[i];
  for(i=N-1;i>=0;i--) {
    if(min > H[i])min = H[i];
    if(min + 1 < H[i])flag = false;
  }
  if(flag)cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 640
#include<iostream>
using namespace std;
int main(){
    int H,W,i,j;
    while(1){
        
        cin >> H >> W;

        if(H==0 && W==0){
            break;
        }
        else{
            for(i=1;i<=H;i++){
                for(j=1;j<=W;j++){
                    cout << "#";
                }
            cout <<endl;
        }
        cout <<endl;
    }
    }
    return 0;
}


Measured memory_bytes: 3072
#include<iostream>
#include<cstdlib>
#include<stack>
#include<queue>
#include<string>
#include<algorithm>
using namespace std;

int a,k,n;
int b[200001];
int i,j;
int rm;
int main(){
    cin>>n>>k;
    for(i=0;i<n;i++){
        cin>>a;
        b[a-1]++;
    }
    sort(b,b+n);
    rm=n;
    for(i=0;i<k;i++){
        rm-=b[n-i-1];//降順にとるから
    }
    cout<<rm;
    

    return 0;
}

Measured memory_bytes: 1152
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <climits>
#include <iomanip>
#include <algorithm>
#include <queue>
#include <map>
#include <tuple>
#include <iostream>
#include <deque>
#include <array>
#include <set>
#include <functional>
#include <memory>
#include <stack>
#include <numeric>
#include <climits>
#include <cfloat>
#include <bitset>

int main() {
	std::map<std::string, long long int> count;
	int n; std::cin >> n;
	for (auto i = 0; i < n; ++i) {
		std::string str; std::cin >> str;
		std::sort(str.begin(), str.end());
		count[str]++;
	}
	long long int result = 0;
	for (const auto& p : count) {
		result += p.second * (p.second - 1) / 2;
	}
	std::cout << result << std::endl;
}


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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod= int(1e9)+7;
using P = pair<ll,ll>;
using ld=long double;

int main(){
    ll n;cin >>n;
    vector<ll>a(n);
    for (int i = 0; i < n; ++i) {
        cin >>a[i];
    }
    ll ans=0;
    ll sum=0;
    ll right=0;
    for (int left= 0; left <n; ++left) {
        while(right<n&&(sum^a[right])==(sum+a[right])){
            sum+=a[right];
            right++;
        }
        ans+=right-left;
        if(left==right)right++;
        else{
            sum-=a[left];
        }
    }
//    vector<ll>sum(n+1,0);
//    sum[1]=1;
//    for (int i = 1; i <n; ++i) {
//        sum[i+1]=sum[i]+i+1;
//    }
//    for (int i = 0; i < n; ++i) {
//        cout <<i<<" "<<sum[i]<<" "<<endl;
//    }
    cout <<ans <<endl;
    return 0;
}

Measured memory_bytes: 1792
import std.stdio;
import std.string;
import std.conv;
import std.typecons;
import std.algorithm;
import std.functional;
import std.bigint;
import std.numeric;
import std.array;
import std.math;
import std.range;
import std.container;
import std.ascii;
void times(alias pred)(int n) {
    foreach(i; 0..n) pred();
}
auto rep(alias pred, T = typeof(pred()))(int n) {
    T[] res = new T[n];
    foreach(ref e; res) e = pred();
    return res;
}

void main() {
    int N = readln.chomp.to!int;
    long[] ary = new long[2^^(N+1)];

    foreach(i; 0..2^^N) {
        ary[2^^N-1+i] = readln.chomp.to!long;
    }
    for(int i=N-1; i>=0; i--) {
        foreach(j; 2^^i-1..2^^(i+1)-1) {
            ary[j] = f(ary[j*2+1], ary[j*2+2]);
        }
    }
    ary.front.writeln;
}

long f(long x, long y) {
    if (x==y) return x;
    return abs(x-y);
}


Measured memory_bytes: 7292
def main():
    n=int(input())
    a=map(int,input().split())
    b=list(map(int,input().split()))
    c=list(map(int,input().split()))
    m = 0
    prev = -100
    for i in (x-1 for x in a):
        m += b[i]
        if prev + 1 == i:
            m += c[prev]
        prev = i
    return m

if __name__ == "__main__":
    print(main())

Measured memory_bytes: 3064
import math

#a,b
a,b=(int(x) for x in input().split())

test1 = math.ceil((a+1) / 0.08 -1)
test2 = math.ceil(a / 0.08)
test3 = math.ceil((b+1) / 0.10 -1)
test4 = math.ceil(b / 0.10)

if test2 >= test4 and test2 <= test3:
    print(test2)
elif test4 >= test2 and test4 <= test1:
    print(test4)
else:
    print("-1")

Measured memory_bytes: 3064
#!/usr/bin/env python2
# -*- coding: utf-8 -*-

import Queue

N = int(raw_input())
tree = [[] for _ in xrange(N)]

for i in range(N-1):
    a, b, c = map(int, raw_input().split())
    a -= 1; b -= 1;
    tree[a].append((b, c))
    tree[b].append((a, c))

Q, K = map(int, raw_input().split())
K -= 1

d = [float("inf") for _ in xrange(N)]

def dijkstra(s):
    que = Queue.PriorityQueue()
    d[s] = 0
    que.put([0, s])

    while not que.empty():
        p = que.get()
        v = p[1]
        if d[v] < p[0]:
            continue
        for i, j in tree[v]:
            if d[i] > d[v] + j:
                d[i] = d[v] + j
                que.put([d[i], i])

dijkstra(K)

for i in range(Q):
    x, y = map(int, raw_input().split())
    x -= 1; y -= 1
    print d[x] + d[y]

Measured memory_bytes: 53076
/* 
	Author: ankrypt
*/


#include <bits/stdc++.h>

using namespace std;

#define MOD 1000000007
#define ll long long int
#define u64 unsigned long long int

ll N;
ll arr[200005];

int main() {
	scanf("%lld", &N);
	for(int i = 0 ; i < N; i++) {
		scanf("%lld", &arr[i]);
	}
	ll currMin = 1e9;
	ll cnt = 0;
	for(int i = 0;i < N; i++) {
		if(arr[i] <= currMin) {
			cnt++;
			currMin = arr[i];
		}
	}
	printf("%lld\n", cnt);
	return 0;
}
/*
	Powered by Buggy Plugin
*/


Measured memory_bytes: 1792
program bm
implicit none
integer::N,C(4)=0
character::S
integer::i
read*,N
do i=1,N
    read*,S
    select case(S)
    case("A")
        C(1)=C(1)+1
    case("W")
        C(2)=C(2)+1
    case("T")
        C(3)=C(3)+1
    case("R")
        C(4)=C(4)+1
    end select
end do
print'("AC x ",i0)',C(1)
print'("WA x ",i0)',C(2)
print'("TLE x ",i0)',C(3)
print'("RE x ",i0)',C(4)
end program bm

Measured memory_bytes: 2892
#include<stdio.h>
main(){
  int a,b,c[5],d=0,e,f=0,g,h=0,i,j,l=0;
  int k[2]={1};
  while(scanf("%d,%d,%d,%d,%d",&c[0],&c[1],&c[2],&c[3],&c[4])!=EOF){
    for(a=0;a<5;a++){
      for(b=4;b>0;b--){
	if(c[b]<c[b-1]){
	  e=c[b];
	  c[b]=c[b-1];
	  c[b-1]=e;
	}
      }
    }
    for(a=0;a<5;a++){
      for(b=4;b>0;b--){
	if(c[b]==c[b-1]){
	  d=1;
	  break;
	}
      }
      if(d==1)break;
    }
    switch(d){
    case 0:
      for(a=1;a<5;a++){
	if(c[0]==1){
	  l=1;
	  for(b=2;b<5;b++){
	    if(c[b]-1!=c[b-1]||((c[4]!=13&&c[1]!=10)&&(c[4]!=5&&c[1]!=2))){
	      f=1;
	      break;
	    }
	  }
	}
	if(c[a]-1!=c[a-1]&&l!=1){
	  f=1;
	  break;
	}
      }
      if(f==1){
	printf("null\n");
      }
      else{
	printf("straight\n");
      }
      break;
    default:
      for(a=0;a<4;a++){
	if(c[a]==c[a+1]){
	  k[h]=k[h]+1;
	}
	if(k[h]>1&&c[a]!=c[a+1]){
	  h=1;
	}
      }
      if(k[0]==4){
	printf("four card\n");
      }
      else if(k[0]==3||k[1]==3){
	if((k[0]==2&&k[1]==3)||(k[0]==3&&k[1]==2)){
	  printf("full house\n");
	}
	else{
	  printf("three card\n");
	}
      }
      else if(k[0]==2&&k[1]==2){
	printf("two pair\n");
      }
      else if(k[0]==2||k[1]==2){
	printf("one pair\n");
      }
      break;
    }
    d=0;
    h=0;
    f=0;
    l=0;
    k[0]=1;
    k[1]=1;
  }
  return 0;
}

Measured memory_bytes: 580
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
#include <iomanip>
using namespace std;
#define MOD int(1e9 + 7)

// mod. m での a の逆元 a^{-1} を計算する
long long modinv(long long a, long long m)
{
    long long b = m, u = 1, v = 0;
    while (b)
    {
        long long t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= m;
    if (u < 0)
        u += m;
    return u;
}

int main()
{
    long long N, K;
    vector<long long> A;

    cin >> N >> K;
    for (long long i = 0; i < N; i++)
    {
        long long t;
        cin >> t;
        A.push_back(t);
    }

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

    vector<long long> c(N, 0);
    c[K - 1] = 1;
    for (long long i = K; i < N; i++)
        c[i] = c[i - 1] * i % MOD * modinv(i - (K - 1), MOD) % MOD;

    long long t = 0;
    for (long long i = 0; i < N; i++)
    {
        t += (A[i] * c[i] % MOD - (A[i] * c[N - i - 1]) % MOD) % MOD;
        t %= MOD;
    }

    cout << t << endl;
}

Measured memory_bytes: 1908
import java.util.*;

public class Main {
	public static void main(String args[]) {
		Scanner k = new Scanner(System.in);
		int length = k.nextInt();
		//Convert from standard array indexing to starting from 1
		int[] array = new int[length+1];
		for(int x = 1; x <= length; x++) {
			array[x] = k.nextInt();
		}
		
		for(int i = 1; i <= length; i++) {
			System.out.print("node " + i + ": key = " + array[i] + ", ");
			
			if((i/2) > 0) {
				System.out.print("parent key = " + array[i/2] + ", ");
			}
			if((2*i) <= length) {
				System.out.print("left key = " + array[2*i] + ", ");
			}
			if((2*i+1) <= length) {
				System.out.print("right key = " + array[2*i+1] + ", ");
			}
			
			System.out.println("");
			
			
		}
		
		
		
	}

}



Measured memory_bytes: 27352
#include <algorithm>
#include <iostream>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
typedef unsigned int uint;
using namespace std;

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

    string s, ret = "First";
    cin >> s;
    int len = s.length();


    if (s[0] == s[len - 1]) {
        if (len % 2 == 1) {
            ret = "Second";
        }
    } else {
        if (len % 2 == 0) {
            ret = "Second";
        }
    }

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

Measured memory_bytes: 512
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Map.Entry;

import java.util.StringTokenizer;

public class Main {
	
	public static void main(String[] args) throws IOException {
		try(final Scanner sc = new Scanner(System.in)){
			final int N = sc.nextInt();
			final int X = sc.nextInt();
			
			int[] ls = new int[N + 1];
			for(int i = 0; i < N; i++) { ls[i] = sc.nextInt(); }
			ls[N] = Integer.MAX_VALUE;
			
			int cnt = 0;
			for(long x = 0; x <= X; x += ls[cnt - 1]) {
				cnt++;
			}
			
			System.out.println(cnt);
		}
	}

	public static class Scanner implements Closeable {
		private BufferedReader br;
		private StringTokenizer tok;

		public Scanner(InputStream is) throws IOException {
			br = new BufferedReader(new InputStreamReader(is));
		}

		private void getLine() throws IOException {
			while(!hasNext()){
				tok = new StringTokenizer(br.readLine());
			}
		}

		private boolean hasNext() {
			return tok != null && tok.hasMoreTokens();
		}

		public String next() throws IOException {
			getLine();
			return tok.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}

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

		public int[] nextIntArray(int n) throws IOException {
			final int[] ret = new int[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextInt();
			}
			return ret;
		}

		public long[] nextLongArray(int n) throws IOException {
			final long[] ret = new long[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextLong();
			}
			return ret;
		}

		public void close() throws IOException {
			br.close();
		}
	}
}

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

int main(){
  string s;
  cin >> s;
  if(s=="Sunny") cout << "Cloudy";
  else if(s=="Cloudy") cout << "Rainy";
  else cout << "Sunny";
  return 0;
}

Measured memory_bytes: 256
import itertools
n=int(input())
s=[[] for i in range(n)]
for i in range(n):
  a=int(input())
  for j in range(a):
    x,y=[int(x) for x in input().split()]
    x-=1
    s[i].append([x,y])

l=[]
a=itertools.product(range(2),repeat=n)
for i in a:
  l.append(i)

ans=0
for i in range(2**n):
  c=[]
  for j in range(n):
    if l[i][j]==1:
      for k in s[j]:
        if l[i][k[0]]!=k[1]:
          c.append(False)
  if c==[]:
    ans=max(ans,sum(l[i]))
print(ans)

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

#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define RFOR(i, a, b) for(int i=(a); i>=(b); i--)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) RFOR(i, n, 0)
#define dump(x)  cout << #x << " = " << (x) << endl;

typedef long long ll;
typedef pair<int, int> ii;
const int mod = 1e9+7;
const ll INF = 1e18;
const int inf = 1e9;

void solve()
{
  int n; cin>>n;
  int ans=1;
  int mx=0;
  for (int i=2; i<=n; i+=2) {
    int t=i;
    int p=0;
    while(t%2==0) {
      t/=2;
      p++;
    }
    if (mx<p) {
      mx=p;
      ans=i;
    }
  }
  cout << ans << endl;
}

int main()
{
  solve();
  return 0;
}


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

using namespace std;

int main(void)
{
  int N;
  cin >> N;
  double sum = 0;
  for(int i = 0; i < N; i++){
    double x;
    string u;
    cin >> x >> u;
    if(u == "BTC"){
      x = x * 380000.0;
    }
    sum += x;
  }
  cout << sum << endl;
  return 0;
}


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

int main()
{
  long long n; cin>>n;
  long long a[n];
  for(int i=0; i<n; i++) cin>>a[i];
  
  long long h = a[0] , ans = 0;
  
  for(int i=0; i<n; i++)
  {
    if(a[i]>h) h = a[i];
    
    if(a[i]<=h) ans += h-a[i];
  
  }
  
  cout<<ans<<endl;
  
  
}


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

//template
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll; const int inf = 0x3fffffff; const ll INF = 0x3fffffffffffffff;
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 end



int main(){
    int m; scanf("%d",&m);
    ll sum=0,add=0;
    rep(i,0,m){
        int d; ll c; scanf("%d%lld",&d,&c);
        sum+=c; add+=c*d;
    }sum--;
    sum+=(add-1)/9; printf("%lld\n",sum);
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main (void)
{
    int N,K,d,A,i,j;
    scanf("%d %d",&N,&K);
    int l[100]={0};
    for(i=0;i<K;i++){
        scanf("%d",&d);
        for(j=0;j<d;j++){
            scanf("%d",&A);
            l[A-1]=1;
        }
    }
    A=N;
    for(i=0;i<N;i++)if(l[i])A--;
    printf("%d\n",A);
    return 0;
}

Measured memory_bytes: 1724
import sys
import math

def input():
    return sys.stdin.readline().strip()

def iinput():
    return int(input())

def finput():
    return float(input())

def tinput():
    return input().split()

def rinput():
    return map(int, tinput())

def rlinput():
    return list(rinput())

def pro(k, l, n):
    if l < n:
        if k == 0:
            return(n - l)
        return (n - l + 2)
    if l == n:
        if k == 0:
            return 0
        elif k == 1:
            return 1
        return 3
    else:
        l -= n - 1
        if l == k:
            return 1
        elif l > k:
            return 0
        if l < k - 1:
            return 2
        else:
            return 3
            

def rt(k, l , n):
    if k < n:
        if l == 0:
            return (k * 2 + n)
        return (n + k * 2 - 1)
    elif k == n:
        if l == 1:
            return (k * 3 - 2)
        elif l == 0:
            return (k * 3)
        return (k * 3 - 3)
    else:
        k -= n - 1
        if k == l:
            return (n * 3 - 2)
        elif k > l:
            return (n * 3)
        if k < l - 1:
            return ((n - 1) * 3 - 1)
        else:
            return ((n - 1) * 3)



def main():
    q = iinput()
    print(q ** 3)
    
    
    


main()



Measured memory_bytes: 38256
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < n; i++)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define INF LLONG_MAX
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;


int main()
{
    ll n; cin >> n; string s; cin >> s;

    vector<ll> e(n, 0);
    REP(i, n) {
        if (i == 0) {
            e[i] = s[i] == 'E';
            continue;
        }

        e[i] = e[i-1] + (s[i] == 'E');
    }
    // for (auto elem : e) cout << elem << " "; cout << endl;

    ll min_num = INF;
    REP(i, n) {
        ll num = 0;
        if (i > 0) num += i - e[i-1];
        if (i < n-1) num += e[n-1] - e[i];

        min_num = min(min_num, num);
    }
    cout << min_num << endl;
    return 0;
}

Measured memory_bytes: 3076
#include <iostream>
#include <cmath>
#include <vector>

using namespace std;

int main()
{
    vector<int> v;
    int sum = 0, m = 3;
    for (int i = 0; i < 3; i++) {
        int x; cin >> x;
        v.push_back(x);
    }
    int k; cin >> k;
    sort(v.begin(), v.end(), greater<char>());

    for (int i = 0; i < m; i++) {
        if (i == 0) {
            sum += pow(2, k) * v[i];
        } else {
            sum += v[i];
        }
    }

    
    cout << sum << endl;        
    return 0;
}

Measured memory_bytes: 888
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int ans = 213213;
char str[105], tmp[105], ttt[105];
bool check(char x, int p) {
    for (int i = 1; i <= p; ++i) if (tmp[i] != x) return false;
    return true;
}
int main() {
    scanf("%s", str + 1);
    int n=strlen(str+1);
    for (char k = 'a'; k <= 'z'; ++k) {
        bool flag = false;
        for (int i = 1; i <= n; ++i) {
            ttt[i] = 0;
            tmp[i] = str[i];
            if (tmp[i] == k) flag = true;
        }
        if (flag == false) continue;
        int cur = 0;
        while (true) {
            if (check(k, n - cur)) break;
            for (int i = 1; i < n - cur; ++i) {
                if (tmp[i] == k || tmp[i+1] == k) ttt[i] = k;
                else ttt[i] = 0;
            }
            ++cur;
            for (int i = 1; i < n - cur; ++i)
                tmp[i] = ttt[i];
        }
        ans = min(ans, cur);
    }
    printf("%d\n", ans);
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#define  boost ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ull unsigned long long
#define d1(x) cout<<#x<<" "<<x<<endl;
#define d2(x,y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<endl;
#define d2i(x,y,i) cout<<#x<<i<<" "<<x<<" "<<#y<<i<<" "<<y<<endl;

#define fr(i,l,r) for(ll i=l;i<r;i++)
#define mems(a,x) memset(a,x,sizeof(a))
#define mod 1000000007
#define ff first
#define ss second
#define pb(x) push_back(x)
#define vll vector<ll>
#define pbp(x,y) push_back(make_pair(x,y))
#define  mat vector<vector<ll>>
#define pi 3.14159265358979323846
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

void solve(){
  double r;
  cin>>r;
 cout<<fixed;
 cout<<setprecision(10)<<(double)2*pi*r<<endl;
}





int main(){
    ll t=1;
//cin>>t;
    while(t--){
     solve();
   cout<<endl;
    }
    return 0;
}


Measured memory_bytes: 3788
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a,b,c;
	cin>>a>>b>>c;
	int ans=a+b+c;
	if(ans>=22){
		cout<<"bust"<<endl;
	}
	if(ans<=21){
		cout<<"win"<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <stdio.h>

using namespace std;

//typedefリスト
typedef vector<int> vint;
typedef vector<string> vstr;




int main(void) {
	
	string s;
	cin >> s;
	int siz = s.length();

	cout << s[0] << siz - 2 << s[siz - 1] << endl;

}

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

bool f4[4];

int main() {
  int N; cin >> N;
  char s[101];
  for ( int i = 0; i < N; i++ ) cin >> s[i];
  for ( int i = 0; i < N; i++ ) {
    if ( s[i] == 'P' ) {
      f4[0] = true;      
    } else if ( s[i] == 'W' ) {
      f4[1] = true;            
    } else if ( s[i] == 'G' ) {
      f4[2] = true;            
    } else if ( s[i] == 'Y' ) {
      f4[3] = true;            
    }
  }
  bool ans = true;

  for ( int i = 0; i < 4;i++ ) {
    if( f4[i] != true ) ans = false;
  }
  if ( ans ) cout << "Four" << endl;
  else  cout << "Three" << endl;
  return 0;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
ans = [0] * n

i = n-1
while i >= 0:
    cnt = 0
    for j in range(1, n+1):
        if (i+1) * j - 1  >= n:
            break
        cnt += ans[(i+1)*j-1]
    if cnt % 2 != a[i]:
        ans[i] = 1
    i -= 1
    #print(cnt)
print(ans.count(1))
for i in range(n):
    if ans[i] == 1:
        print(i+1)

Measured memory_bytes: 64476
#include<iostream>
#include<iomanip>
#include<math.h>
#include<algorithm>
#include<utility>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<unordered_map>
#include<functional>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=2e18;
const ll MOD=1e9+7;

ll binarySearch(function<bool(ll)> check, ll ok, ll ng) {
  while ((ok - ng > 1) || (ng - ok > 1)) {
    ll mid = (ok + ng) / 2;
    if (check(mid))ok=mid;
    else ng = mid;
  }
  return ok;
}
ll N,K;
ll A[200010],F[200010];
bool Check(ll n){
    if(n<0)return false;
    ll cnt=0;
    for(ll i=0;i<N;i++){
        if(A[i]*F[i]>n){
            cnt+=A[i]-n/F[i];
        }
    }
    return cnt<=K;
}
int main(){
    cin>>N>>K;
    for(ll i=0;i<N;i++){
        cin>>A[i];
    }
    for(ll i=0;i<N;i++){
        cin>>F[i];
    }
    sort(A,A+N);
    sort(F,F+N,greater<ll>());
    cout<<binarySearch(Check,(1'000'000'000'001ll),-1ll)<<endl;
    return 0;
}

Measured memory_bytes: 3328
from sys import stdin, setrecursionlimit
#input = stdin.buffer.readline
setrecursionlimit(10 ** 7)

from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
from collections import deque, defaultdict, Counter
from itertools import combinations, permutations, combinations_with_replacement
from itertools import accumulate
from math import ceil, sqrt, pi, radians, sin, cos

MOD = 10 ** 9 + 7
INF = 10 ** 18

#N = int(input())
#N, M = map(int, input().split())
#A = list(map(int, input().split()))
#A = [int(input()) for _ in range(N)]
#ABC = [list(map(int, input().split())) for _ in range(N)]
S = input()
#S = [input() for _ in range(N)]

if S == "RRR":
    print(3)
elif S == "RRS" or S == "SRR":
    print(2)
elif S == "SSS":
    print(0)
else:
    print(1)

Measured memory_bytes: 65200
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<numeric>
#include<cmath>
#include<queue>
#include<stack>
#include<list>
#include<unordered_map>
#include<unordered_set>
#include<cctype>
#include<iomanip>
#include<limits>
#include<bitset>

using namespace std;
typedef long long int ll; typedef pair<int, int> P; typedef unsigned long long int ull;
const ll mod = 1000000007;
const int inf = 1e9 + 7;
const ll linf = 1LL << 60;
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define REP(i,m,n) for(int i=(m);i<(int)n;i++)
#define all(a) (a).begin(),(a).end()
#define allg(a) (a).begin(),(a).end(),greater<>()
#define SUM(a) accumulate((a).begin(),(a).end(),0)
#define d10 std::setprecision(10)
#define d20 std::setprecision(20)
#define vec vector<int>
#define vecb vector<bool>
#define vecd vector<double>
using str = string;
const double PI = 3.14159265359;
ll gcd(ll a, ll b) { ll t; while (b != 0) { t = a % b; a = b; b = t; }return a; }
int gcd(int a, int b) { int t; while (b != 0) { t = a % b; a = b; b = t; }return a; }
ll recfact(ll start, ll n) {
	ll i;
	if (n <= 16) {
		ll r = start;
		for (i = start + 1; i < start + n; i++) r = r * i % mod;
		return r % mod;
	}
	i = n / 2;
	return recfact(start, i) % mod * recfact(start + i, n - i) % mod;
}
ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
}
ll fct(ll n) { return recfact(1, n); }
ll ncm(ll n, ll m) {
	if (n < m)return 0;
	ll x = (fct(n) % mod / (fct(m) * fct(n - m)) % mod) % mod;
	return x;
}
std::string sreverse(string str, int firstItr, int secondItr) {
	if (firstItr < 0 || secondItr>int(str.size() - 1))return str;
	while (firstItr < secondItr) {
		swap(str[firstItr], str[secondItr]);
		firstItr++; secondItr--;
	}
	return str;
}
std::string RunLengthEncoding(std::string str) {
	int itr = 0; std::string res;
	while (itr < int(str.size())) {
		char tmp = str[itr++];
		int length = 1;
		while (itr <int(str.size()) && str[itr] == tmp) { ++itr; ++length; }
		res.push_back(tmp);
		res += to_string(length);
	}
	return res;
}
std::string split(std::string str, size_t first_itr, size_t second_itr) {
	std::string tmp;
	for (size_t i = first_itr; i < second_itr + 1; i++) {
		tmp.push_back(str.at(i));
	}
	return tmp;
}
ll max(ll a, ll b) {
	return a > b ? a : b;
}
ll min(ll a, ll b) {
	return a < b ? a : b;
}


int main() {
	int n; cin >> n;
	vec v(n);
	vec x(n);
	rep(i, n) {
		cin >> v[i];
		x[i] = v[i];
	}
	sort(all(v));
	int dn = 0;
	rep(i, n) {
		if (v[i] != x[i])
			dn++;
	}
	if (dn < 3)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;

	return 0;
}

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

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

	int N;
	char s[100];
	int sum = 0;
	int m=0;
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> s[i];
		if (s[i] == 'I')sum++;
		if (s[i] == 'D')sum--; 
		m = max(m, sum);
	}
	cout << m;
}

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

int main(){
	int W,H,N;
	cin >> W >> H >> N;
	
	int left = 0;
	int right = W;
	int bottom = 0;
	int up = H;
	rep(i,N){
		int x,y,a;
		cin >> x >> y >> a;
		if(a == 1){
			left = max(left, x);
		}
		if(a == 2){
			right = min(right, x);
		}
		if(a == 3){
			bottom = max(bottom, y);
		}
		if(a == 4){
			up = min(up,y);
		}
	}
	
	int h = max(0,right-left);
	int w = max(0,up-bottom);
	
	cout << h*w << endl;
    return 0;
}



Measured memory_bytes: 256
def solve():
    MOD = 10**9+7
    N = int(input())
    
    dp = [[0 for _ in range(4)] for _ in range(N+1)]
    dp[1] = [1, 1, 1, 1]
    
    for i in range(2, N+1):
        for j in range(4):
            dp[i][j] += sum(dp[i-1])
            dp[i][j] %= MOD
        dp[i][1] -= dp[i-2][0] + dp[i-2][2]
        dp[i][2] -= dp[i-2][0]
        if 3 <= i:
            dp[i][1] -= dp[i-3][0] * 3
            dp[i][2] += dp[i-3][2]
    
    ans = sum(dp[N]) % MOD
    print(ans)


if __name__ == '__main__':
    solve()


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

using namespace std;
typedef long long ll;

int main() {
  int R;
  cin>>R;
  if (R < 1200) cout<<"ABC"<<endl;
  else if (R < 2800) cout<<"ARC"<<endl;
  else cout<<"AGC"<<endl;
  return 0;
}

Measured memory_bytes: 256
N,x,M=map(int,input().split())
k=x
L=list()
c=dict()
for i in range(M):
  if i==N:
    print(sum(L))
    exit()
  if x==0:
    print(sum(L))
    exit()
  L.append(x)
  x=(x*x)%M
  if x in c:
    q=x
    break
  c[x]=1
moto=sum(L)
N-=len(L)
for i in range(len(L)):
  if L[i]==q:
    roop=list(L[i:])
L=roop
a=len(L)
if N%a==0:
  print(moto+(sum(L)*(N//a)))
else:
  s=N//a
  t=N%a
  ans=sum(L)*s
  ans+=sum(roop[:t])
  print(moto+ans)

Measured memory_bytes: 14208
#include <bits/stdc++.h>
#define LL long long
#define pb push_back
#define mp make_pair
#define INF 0x3f3f3f3f
#define Inf 1000000000000000000LL
#define F first
#define S second
using namespace std;
typedef pair<int,int>pii;
int a[10];
int ans=INF;
int main(){
	for(int i=1;i<6;i++)cin>>a[i];
	for(int i=1;i<=120;i++){
		int lst=0;
		for(int j=1;j<6;j++){
			if(lst%10!=0)lst=(lst/10+1)*10;
			lst+=a[j];
		}
		ans=min(ans,lst);
		if(i!=120)next_permutation(a+1,a+6);
	}
	cout<<ans<<endl;
	return 0;
}


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

#include <boost/range/adaptors.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;

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

    string s;
    cin >> s;

    int64_t m = s.size();

    vector a(1, 0L);
    int64_t t = 0;
    for (auto c : s) {
        if (c == '0') {
            a.push_back(t);
        } else {
            ++t;
        }
    }
    a.push_back(t);

    int64_t k;
    cin >> k;
    k = min(k, a.back());

    int64_t n = a.size();

    constexpr auto M = 998244353L;

    vector dp(2, vector(k + 1, vector(a.back() + 1, 0L)));
    int64_t h = 0;
    dp[h][0][0] = 1;
    for (auto i : irange(0L, n - 1)) {
        auto&& prev = dp[h];
        auto&& next = dp[!h];
        h = !h;

        for (auto j : irange(k, -1L, -1L)) {
            int64_t ss = 0;
            for (auto c : irange(a[i + 1], a.back() + 1)) {
                next[j][c] = ss + prev[j][a[i] + (c - a[i + 1])];
                ss += prev[j][a[i] + (c - a[i + 1])];
                next[j][c] %= M;
            }

            for (auto c : irange(a[i + 1], a.back() + 1)) {
                for (auto b : irange(a[i] + (c - a[i + 1]) + 1, c + 1)) {
                    auto w = j + b - (a[i] + (c - a[i + 1]));
                    if (w > k) {
                        break;
                    }
                    next[w][c] += prev[j][b];
                    next[w][c] %= M;
                }
            }
        }
    }

    int64_t ans = 0;
    for (auto i : irange(0L, k + 1)) {
        ans += dp[h][i][a.back()];
        ans %= M;
    }

    cout << ans << endl;
}


Measured memory_bytes: 5244
#include <bits/stdc++.h>
using i64 = long long;

int main() {
    i64 n, a, b, c, d, e;
    std::cin >> n >> a >> b >> c >> d >> e;
    auto m = std::min({ a, b, c, d, e });
    std::cout << n / m + (n % m > 0) + 4 << std::endl;

    return 0;
}


Measured memory_bytes: 256
n, m = map(int,input().split())
ab = list(list(map(int, input().split())) for _ in range(n))
cd = list(list(map(int, input().split())) for _ in range(m))

for i in range(n):
    num = []
    for j in range(m):
        num.append(abs(ab[i][0]-cd[j][0])+abs(ab[i][1]-cd[j][1]))
    else:
        mini = min(num)
        print(num.index(mini)+1)
        num = []

Measured memory_bytes: 3064
// Package main provides
//
// File:  a.go
// Author: ymiyamoto
//
// Created on Mon Dec 31 13:14:56 2018
//
package main

import "fmt"

func main() {
	var N, A int
	fmt.Scan(&N, &A)
	if N%500 <= A {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main(){
  while(1){
    int n;
    cin >> n;
    if(n==0)return 0;
    vector<int> a(n);
    for(int i=0;i<a.size();i++){
      cin >> a[i];
    }
    sort(a.begin(),a.end());
    int sum =0;
    for(int i=1;i<(a.size()-1);i++){
        sum+=a[i];
      }
    int avg = sum/(n-2);
    cout << avg << endl;
  }
}



Measured memory_bytes: 3000
from sys import stdin




def gcd(n,m):
    if n<m:
        return gcd(m,n)
    if n%m==0:
        return m
    else:
        return gcd(m,n%m)



a,b,c,d = [int(x) for x in stdin.readline().rstrip().split()]

c_num = b//c-(a-1)//c
d_num = b//d-(a-1)//d

LCM = d*c//(gcd(c,d))

ans = b-a+1
ans -= c_num
ans -= d_num
ans += b//LCM-(a-1)//LCM
print(ans)

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

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int,int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vll>;
using vb = vector<bool>;

const int INF = 2e9+5;
const ll LLINF = (1LL << 60) + 5;

/*
  filippos
  Contest : AtCoder DP contest
  Task : E - Knapsack 2
*/

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

  int n, w; cin >> n >> w;

  vector<pii> v(n);
  for(pii &p : v)
    cin >> p.first >> p.second;

  int max_v = accumulate(v.begin(), v.end(), 0, [](auto sum, auto item) { return sum + item.second;});

  vi dp(max_v + 1, INF);
  // dp[i] = min(w) for val = i
  dp[0] = 0;

  for(pii &x : v){
    for(int val = max_v; val >= x.second; val--)
      if(dp[val - x.second] != INF && dp[val - x.second] + x.first <= w)
        dp[val] = min(dp[val], dp[val - x.second] + x.first);
  }

  int best = 0;
  for(int i = 1; i <= max_v; i++)
    if(dp[i] <= w)
      best = i;

  cout << best;

  return cout << endl, 0;
}

Measured memory_bytes: 640
#include<stdio.h>


int main() {
	int N, Q, flag = 0;
	long long int T,A[100000], D[100000], X[100000];
	scanf("%d %lld %d", &N, &T, &Q);
	for (int i = 1; i <= N; i++) {
		scanf("%lld %lld", &A[i], &D[i]);
	}
	for (int i = 1; i <= Q; i++) {
		scanf("%lld", &X[i]);
	}
	for (int i = 1; i <= Q; i++) {
		if (D[X[i]] == 1) {
			for (int j = X[i]+1; j <= N;j++) {
				if (D[j] == 2) {
					if ((A[j-1] + A[j]) / 2 <= A[X[i]] + T) {
						printf("%lld\n", (A[j-1] + A[j]) / 2);
						flag = 1;
					}
					break;
				}
			}
			if (flag == 0) {
				printf("%lld\n", A[X[i]] + T);
			}
		}
		if (D[X[i]] == 2) {
			for (int j = X[i] -1; j >=1; j--) {
				if (D[j] == 1) {
					if ((A[j+1] + A[j]) / 2 >= A[X[i]] - T) {
						printf("%lld\n", (A[j+1] + A[j]) / 2);
						flag = 1;
					}
					break;
				}
			}
			if (flag == 0) {
				printf("%lld\n", A[X[i]] - T);
			}
	    }
		flag = 0;
    }
	return 0;
}

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

vector<bool> seen;
void dfs(const Graph &G,int v,int a,int b){
  seen[v]=true;
  for(auto nv:G[v]){
    if((v==a && nv==b) || (v==b && nv==a))
      continue;
    if(seen[nv]) continue;
    dfs(G,nv,a,b);
  }
}

int main() {
  int n,m;
  cin>>n>>m;
  Graph G(n);
  vector<pair<int,int>> AB;
  rep(i,m){
    int a,b;
    cin>>a>>b;
    G[a-1].push_back(b-1);
    G[b-1].push_back(a-1);
    AB.push_back(make_pair(a-1,b-1));
  }
  
  int ans=0;
  rep(i,m){
    int count=0,a=AB[i].first,b=AB[i].second;
    seen.assign(n,false);
    rep(v,n){
      if(seen[v]) continue;
      dfs(G,v,a,b);
      count++;
    }
    if(count>1) ans++;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define INF 1000000000000000007
using namespace std;

int n,W,X,w[110],v[110];
int dp[100010];

signed main()
{
	ios::sync_with_stdio(false);
	cin>>n>>W;
	for(int i=1;i<=n;i++){cin>>w[i]>>v[i];X+=v[i];}
	dp[0]=0;
	for(int i=1;i<=X;i++) dp[i]=INF;
	for(int j=1;j<=n;j++){
		for(int i=X;i>=1;i--){
			if(i>=v[j]) dp[i]=min(dp[i],dp[i-v[j]]+w[j]);
		}
	}
	for(int i=X;i>=1;i--){
		if(dp[i]<=W){
			cout<<i<<endl;
			return 0;
		}
	}
	cout<<0<<endl;
	return 0;
}

Measured memory_bytes: 1024
from collections import defaultdict


def main():
    S = input()
    d = defaultdict(int)
    for c in S:
        d[c] += 1
    for n in d.values():
        if n % 2 == 1:
            print('No')
            exit()
    print('Yes')


if __name__ == '__main__':
    main()


Measured memory_bytes: 38256
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;

vector<int> G[100100], L;

void proc()
{
	int N;
	scanf("%d", &N);
	for (int i = 1; i < N; i++) {
		int x, y; scanf("%d %d", &x, &y);
		G[x].push_back(y);
		G[y].push_back(x);
	}
	if (N == 2) {
		puts("1 2");
		return;
	}
	if (N == 3) {
		puts("1 2 3");
		return;
	}
	vector<int> st;
	int x = 1;
	for (int i = 1; i <= N; i++) if (G[i].size() > 1){
		int c = 0;
		for (auto &y : G[i]) if (G[y].size() > 1) c++;
		if (c > 2) {
			puts("-1");
			return;
		}
		if (c == 1) {
			st.push_back(i);
		}
		x = i;
	}

	if (st.empty()) {
		st.push_back(x);
	}

	vector<int> ans; ans.push_back(N + 1);
	for (int s : st) {
		vector<int> now;
		now.push_back(1);
		int c = 2, last = -1;
		while (1) {
			int nxt = -1, f = 0;
			for (auto &y : G[s]) if (y != last){
				if (G[y].size() == 1) f++;
				else nxt = y;
			}
			if (last == -1) f--;
			if (nxt == -1) {
				for (int k = 1; k <= f-1; k++) now.push_back(k + c);
				now.push_back(c); c++; c += f-1;
				now.push_back(c); c++;
			}
			else {
				for (int k = 1; k <= f; k++) now.push_back(k + c);
				now.push_back(c); c++; c += f;
			}
			if (nxt == -1) break;
			last = s;
			s = nxt;
		}

		if (ans > now)
			ans = now;
	}

	for (int i = 0; i < ans.size(); i++) printf("%d%c", ans[i],i+1<ans.size()?' ':'\n');
}

int main()
{
#ifdef __LOCAL
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	proc();
	return 0;
}

Measured memory_bytes: 7408
from collections import Counter
N = int(input())
A = [int(x) for x in input().split()]
for i in range(N - 1):
    A[i + 1] += A[i]
A = Counter(A)
ans = 0
for k, v in A.items():
    ans += v * (v - 1) // 2
    if k == 0:
        ans += v
print(ans)


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

int n;

int main () {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  cout << (n-1)/2 << endl;
}



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

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout.precision(12);
    cout.setf(ios_base::fixed, ios_base::floatfield);
    
    int n, k;
    cin >> n >> k;

    double ans = 0.0;
    for(int i=1;i<=n;i++){
        if(i >= k) ans += 1.0;
        else{
            for(int j=1;j<=60;j++){
                int64_t m = 1LL<<j;
                if(m * i >= k){
                    ans += 1.0/m;
                    break;
                }
            }
        }
    }
    cout << ans / n << endl;
    
    return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

N = int(input())
L = [int(i) for i in input().split()]
total = 0

L = sorted(L)

for i in range(N-2):
    k = i + 2
    for j in range(i+1, N):
        while k < N and L[i] + L[j] > L[k]:
            k+=1
        if k > j:
            total += k-j-1

print(total)


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

const long long INF = 1000000000;

typedef long long ll;

#define writeln(n) cout<<n<<"\n";

typedef pair<int, int> P;
typedef pair<string, int> Psi;


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

	int n;cin>>n;
	string s;cin>>s;

	if(n%2 !=0){
		writeln("No");
		return 0;
	}

	for(int i=0; i<n/2; i++){
		if(s[i] != s[n/2+i] ){
			writeln("No");
			return 0;
		}
	}
	writeln("Yes");



}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 10000000000000009
//#define INF 9223372036854775807
typedef long long ll;
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define ORREP(i,n) for(int i=(n);i>=1;--i)
#define ZREP(i,n) for(int i=1;i<(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define rollcall cout<<"I'm Sucu."<<endl;
#define YES(s) s?cout << "YES" << endl:cout << "NO" << endl
#define Yes(s) s?cout << "Yes" << endl:cout << "No" << endl
#define Taka(s) s?cout << "Takahashi" << endl:cout << "Aoki" << endl
#define out(s,t,u) s?cout << t << endl:cout << u << endl
#define int ll
#define Endl endl


signed main(){
    int N;
    int D[214514];
    map<int,int> G;
    cin >> N;
    REP(i,N){cin >> D[i];}
    
    map<int,int> M;
    vector<int> V[214514];
    REP(i,N-1){
        V[i].push_back(i+1);
    }
    REP(i,N){
      	M[D[i]];
        if(M[D[i]]==0 || M[D[i]]==i){
            M[D[i]]=i+1;
        }else{
            V[M[D[i]]-1].push_back(i);
            M[D[i]]=i+1;
        }
    }
    
    int dp[214514]={};
    dp[0]=1;
    REP(i,N){
      REP(j,V[i].size()){
          dp[V[i][j]]=(dp[i]+dp[V[i][j]])%MOD;
      }  
    }
    
    cout << dp[N-1]%MOD << endl;
    
  REP(i,N){
    cerr << i+1 << " ";
      REP(j,V[i].size()){
          cerr << V[i][j]+1 << " ";
      }  
    cerr << endl;
    }
    return 0;
}


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

using namespace std;

using int64 = long long;
const int mod = 1e9 + 7;
// const int mod = 998244353;

const int64 infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;


template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 > &p) {
  os << p.first << " " << p.second;
  return os;
}

template< typename T1, typename T2 >
istream &operator>>(istream &is, pair< T1, T2 > &p) {
  is >> p.first >> p.second;
  return is;
}

template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
  for(int i = 0; i < (int) v.size(); i++) {
    os << v[i] << (i + 1 != v.size() ? " " : "");
  }
  return os;
}

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

template< typename T = int64 >
vector< T > make_v(size_t a) {
  return vector< T >(a);
}

template< typename T, typename... Ts >
auto make_v(size_t a, Ts... ts) {
  return vector< decltype(make_v< T >(ts...)) >(a, make_v< T >(ts...));
}

template< typename T, typename V >
typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) {
  t = v;
}

template< typename T, typename V >
typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) {
  for(auto &e : t) fill_v(e, v);
}

template< typename F >
struct FixPoint : F {
  FixPoint(F &&f) : F(forward< F >(f)) {}

  template< typename... Args >
  decltype(auto) operator()(Args &&... args) const {
    return F::operator()(*this, forward< Args >(args)...);
  }
};

template< typename F >
inline decltype(auto) MFP(F &&f) {
  return FixPoint< F >{forward< F >(f)};
}

int main() {
  int N;
  cin >> N;
  string S;
  cin >> S;
  int64 ret = 0;
  for(int i = 0; i < N; i++) {
    for(int j = 1; j <= N; j++) {
      int latte = i - j;
      int malta = i + j;
      if(0 <= latte && malta < N) {
        ret -= S[latte] != S[malta] && S[latte] != S[i] && S[malta] != S[i];
      }
    }
  }
  vector< int64 > dp(1 << 3);
  dp[0] = 1;
  string P = "RGB";
  for(auto &c : S) {
    int id = P.find(c);
    for(int k = 0; k < (1 << 3); k++) {
      if((k >> id) & 1) continue;
      dp[k | (1 << id)] += dp[k];
    }
  }
  cout << dp.back() + ret << endl;
}



Measured memory_bytes: 3660
import java.util.*;

public class Main{
	public static void main(String[] args) {
		new Main().run();
	}
	
	public void run() {
		Scanner sc = new Scanner(System.in); 
		int n;
		n = sc.nextInt();
		while(n-->0){
			int x,y,z;
			x = sc.nextInt();
			y = sc.nextInt();
			z = sc.nextInt();
			
			int a,b,c;
			a = Math.min(x,Math.min(y,z));
			c = Math.max(x,Math.max(y,z));
			b = x+y+z-a-c;
			
			System.out.println(a*a+b*b==c*c?"YES":"NO");
		}
	}
}

Measured memory_bytes: 12000