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

#define REP(i, l, n) for(int i=(l), i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back

ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int dx[4] = {-1, 1, 0, 0};
int dy[4] = {0, 0, 1, -1};

int main(){
    int n; cin >> n;
    vector<int> lis(n), lis2(n);
    REP(i, 0, n){cin >> lis[i];}
    lis2 = lis;
    sort(ALL(lis2), greater<>());
    int max1 = lis2[0], max2 = lis2[1];
    REP(i, 0, n){
        if(max1 == lis[i]){
            cout << max2 << endl;
        }else{
            cout << max1 << endl;
        }
    }
}

Measured memory_bytes: 3200
#include <iostream>
#include <algorithm>
using namespace std;
bool cmp(int a,int b){return a>b;}
int main(){
int a[10];
for(int i=0;i<10;i++)
cin>>a[i];
sort(a,a+10,cmp);
cout<<a[0]<<endl<<a[1]<<endl<<a[2]<<endl;



}

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

// M A F I A - M A F I A - M A F I A - M A F I A - M A F I A - M A F I A //

#define int                                       long long
#define lop(i,s,e)                                for(int i=s;i<(int)e;i++)
#define rlop(i,e,s)                               for(int i=e;i>=s;i--)
#define prvec(v)                                  lop(R15,0,v.size())cout << v[R15] <<" "; cout << endl;
#define prarr(arr,s1,e1)                          lop(R15,s1,e1)cout << arr[R15] << " "; cout << endl;

#define endl                                      '\n'
#define ff                                        first
#define ss                                        second
#define pii                                       pair<int,int>

#define pb                                        push_back
#define all(v)                                    v.begin(),v.end()

// M A F I A - M A F I A - M A F I A - M A F I A - M A F I A - M A F I A //

const int N = 3e6 + 7, M = 1000000007, inf = INT_MAX;
const long long INF = LLONG_MAX;

int n, Q;
int arr[N + 2];


void solve()
{
	int k;
	cin >> n >> k;
	lop(i, 0, n) cin >> arr[i];
	sort(arr, arr + n);

	int sum = 0;
	lop(i, 0, k) sum += arr[i];
	cout << sum << endl;

}

int32_t main()
{
	ios_base::sync_with_stdio(0);   cin.tie(0);   cout.tie(0);

	int test = 1;
	// cin >> test;
	while (test--)solve();


}





Measured memory_bytes: 3668
#include<iostream>
#include<stdio.h>
#include<vector>//s1.erase(n)=文字列s1の、n文字目以降削除
#include<algorithm>//辞書順=next_permutation
#include<set>
#include<string>//char 小文字のほうが32大きい
#include<sstream>
#include<string.h>
#include<complex>
#include<time.h>
#include<random>
#include<cmath>
#include<math.h>
#include<queue>
#include<time.h>
#include<iomanip>
#include<locale>
#include<utility>//swap=数値交換
#define rt "\n"
#define rep(i,n) for(int i=0;i<n;i++)
#define rop(i,n) for(int i=1;i<=n;i++)
#define drep(i,n) for(int i=n-1;0<=i;i--)
#define drop(i,n) for(int i=n;0<i;i--)
#define yes(ans) if(ans)cout<<"yes"<<rt;else cout<<"no"<<rt;
#define Yes(ans) if(ans)cout<<"Yes"<<rt;else cout<<"No"<<rt;
#define YES(ans) if(ans)cout<<"YES"<<rt;else cout<<"NO"<<rt;
#define sec(a,b,ans) if(ans)cout<<a<<rt;else cout<<b<<rt;
#define vcin(s,n) rep(i,n)cin>>s[i];//vcin(配列名),(繰り返し回数)
#define sort(s) sort(s.begin(),s.end())//標準=昇順
#define reve(s) reverse(s.begin(),s.end())
#define asas int ans=0
#define llcncn llint cnt=0
#define llasas llint ans=0
#define str string
#define please return
#define AC 0
#define ic_a int a;cin>>a;
#define ic_b int b;cin>>b;
#define ic_s string s;cin>>s;
#define Rapid_pleaseAC_fast cin.tie(0);ios::sync_with_stdio(false)
#define Pi 3.1415926535897932384626
#define nine 1000000000
using ll = long long;
using namespace std;
typedef vector<int> vint;
typedef vector<string> vstr;
typedef vector<char> vchar;
typedef vector<double> vdou;
typedef long long int llint;
typedef pair<int, int> pint;
typedef pair<llint, llint> pllint;
typedef vector<llint> vllint;
typedef vector<pint> vpint;
typedef vector<pair<llint, llint>> vpllint;
typedef vector<vector<int>> vvint;
typedef vector<vector<char>> vvchar;
typedef vector<vector<llint>> vvllint;
typedef vector<vector<string>> vvstr;
typedef vector<vector<bool>> vvbool;
typedef vector<vector<pint>> vvpint;
typedef vector<bool> vbool;
typedef long double ld;
const ld eps = 1.0e-10; // 許容される誤差
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

long long LCM(long long a, long long b) {
	return a * b / GCD(a, b);
}

unsigned GetDigit(unsigned num) {
	return std::to_string(num).length();
}

int tow(int n) {//2のn乗
	if (n == 0)return 1;
	int x = tow(n / 2);
	x *= x;
	if (n % 2 == 1)x *= 2;
	return x;//@domino
}

int keta(int n) {
	int sum = 0;
	while (n != 0) {
		sum += n % 10; n /= 10;
	}
	return sum;//Nanashi,tRue,wai
}

/*

 (char)toupper(a[n])=文字列のn文字目を大文字で出力

  pow(a,b)=aのb乗

  */
ld mysqrtl(ld x)
{
	ld a = sqrtl((double)x); // 近似値
	do {
		a = (a + x / a) / 2.0L;
	} while (fabsl(x - a * a) > eps);
	return a;
}
 ll gcd(ll a, ll b) {
	 if (b == 0) return a;
	 return gcd(b, a % b);
	
}

 ll lcm(ll a, ll b) {
	 ll g = gcd(a, b);
	 return a / g * b; 
 }

//平方根を求める。sqrtより精度が高い。
//epsを変えて誤差を調整する。
int main(void) {
	Rapid_pleaseAC_fast;
	llint ans = 0, n = 0, m=0, count=0, sum = 0, ch = 0;
	bool check = false;
	string s;
	vector<llint> array;
	char c;
	cin >> n>>m;
	rep(i, m) {
		cin >> count;
		sum += count;
	}
	if (n >= sum)cout << n - sum << endl;
	else std::cout << -1 << endl;
	
	please AC;
}


Measured memory_bytes: 3640
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000000LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
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; }


ll rui(ll a,ll b){
     ll ans=1;
     while(b>0){
        if(b&1) ans=ans*a%MOD;
        a=a*a%MOD;
        b/=2;
    }
     return ans;
}

ll COM(ll a, ll b){
    ll ans = 1;
    for(ll i=a; i>a-b; i--){
        ans = ans * i % MOD;
    }
    for(ll i=1; i<=b; i++){
        ans =(ans*rui(i, MOD-2)) % MOD;
    }
    return ans;
}

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

    cout<<(MOD + MOD + rui(2,n)-COM(n,a)-COM(n,b)-1)%MOD<<endl;
}

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

int main(){
  int N;
  cin >> N;
  vector<int> p(N);
  int sum = 0; 
  for(int i = 0; i < N; i++){
    cin >> p[i];
    sum += p[i];
  }

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

  cout << sum - p[N - 1] + p[N - 1] / 2;


  return 0;
}

Measured memory_bytes: 256
import sys
from itertools import accumulate
input=sys.stdin.readline

def resolve():
    N=int(input().rstrip())
    A=[int(input().rstrip()) for _ in range(N)]
    #booltable=[0]+booltable
    cumsum = list(accumulate(A))
    
    Amax=0
    Amax2=0
    _A=sorted(A)
    Amax2=_A[N-2]
    Amax=_A[N-1]

    for i in range(N):
        if A[i]==Amax:
            print(Amax2)
        else:
            print(Amax)
            

if __name__ == "__main__":
    #unittest.main()
    resolve()

Measured memory_bytes: 23628
/*  1、ai上某位1个*它后面的该位上0个数 或0个数*1个数 
    进一步化简2、某位上1个数 *0个数之和 */ 
#include<bits/stdc++.h>
using namespace std;
const int N=300010,mod=1e9+7;
#define    ll  long long
ll ans=0;
ll a[N];
int main(){
    ll n;
    cin>>n;
    for(int i=1;i<=n;i++)cin>>a[i];
    for(int i=0;i<60;i++)
    {
    	ll x=0;
    	for(int j=1;j<=n;j++)if(a[j]>>i &1)x++;
    	//cout<<x<<endl;
    	ll now=x*(n-x)%mod;
    	now= (1ll<<i)%mod*now%mod;//细节 
    	//cout<<now<<endl;
    	ans+=now;
    	ans%=mod;
    }
    printf("%lld",ans);
	return 0;
}


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


int main(){
  int n,count=0;
  bool flag=false;
  while(true){
    cin >>n;
    if(n==0) break;

    count=2*n-n;
    for(int i=2*n;i>n;i--){ 
      for(int j=2;j<=sqrt(i);j++){
	if(i%j==0){
	  count--;
	  //cout <<"not "<<i<<endl;
	  break;
	}
      }
    }
    cout <<count<<endl;
  }
  return 0;
}

Measured memory_bytes: 1160
/*
ITP1_11_C
Dice 3

*/

#include<stdio.h>
#include<string.h>

struct DICE
{
  int *state;
  int *label;
};

int main(){
  int inistate[6][6] = {{1,3,4,2,5,6},{4,1,6,2,5,3},{6,4,3,2,5,1},
  {3,6,1,2,5,4},{6,2,5,3,4,1},{6,5,2,4,3,1}};
  ///{上,E,W.S,N,下}
  int label_0[6] = {1,2,3,4,5,6};
  int label[6] = {1,2,3,4,5,6};
  int staticstate[6] = {1,3,4,2,5,6};
  struct DICE dice_0 = {staticstate,label_0};
  struct DICE dice = {inistate[0],label};
  int i,j,ans=0,temp;
  for(i=0;i<6;i++){
    scanf("%d",&dice_0.label[i]);
  }
  for(i=0;i<6;i++){
    scanf("%d",&dice.label[i]);
  }
  for(i=0;i<6;i++){
    dice.state = inistate[i];
    for (j=0;j<4;j++){
      temp = dice.state[0];
      dice.state[0] = dice.state[4];
      dice.state[4] = dice.state[5];
      dice.state[5] = dice.state[3];
      dice.state[3] = temp;
      if (dice_0.label[dice_0.state[0]-1]==dice.label[dice.state[0]-1]
        && dice_0.label[dice_0.state[1]-1]==dice.label[dice.state[1]-1]
        && dice_0.label[dice_0.state[2]-1]==dice.label[dice.state[2]-1]
        && dice_0.label[dice_0.state[3]-1]==dice.label[dice.state[3]-1]
        && dice_0.label[dice_0.state[4]-1]==dice.label[dice.state[4]-1]){
        ans = 1;
      }
    }
  }
  if (ans == 1){
    printf("Yes\n");
  }
  else{
    printf("No\n");
  }

  return 0;
}


Measured memory_bytes: 2124
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner stdIn=new Scanner(System.in);
		int n=stdIn.nextInt();
//		int b=stdIn.nextInt();
//		int c=stdIn.nextInt();
		//int valen[]=new int[n+1];
		int cnt=0;
		for(int i=1;i<=n;i++) {
			int valen=String.valueOf(i).length();
			if((valen%2)==1) {
				cnt++;
			}
		}
		System.out.println(cnt);

	}

}


Measured memory_bytes: 29908
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n,min=1000000001,max=-1;
    cin >>n;
    vector <int> a(n);
    for(int i=0;i<n;i++){
        cin>>a[i];
        if(min>a[i]) min=a[i];
        if(max<a[i]) max = a[i];
    }
    cout << abs(min-max) << endl;
}

Measured memory_bytes: 256
#include <cstdio>
int n, a, b, ma, mb=2e9;
int main() {
	scanf("%d", &n);
	while(n--) {
		scanf("%d%d", &a, &b);
		if(b<mb) mb=b, ma=a;
	}
    printf("%d", ma+mb);
    return 0;
}

Measured memory_bytes: 128
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;

auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}

void main()
{
  string s; readV(s);

  auto r = 1000;
  foreach (i; 0..s.length-2)
    r = min(r, (s[i..i+3].to!int - 753).abs);

  writeln(r);
}


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

int main(){
    string a, b, c;
    cin >> a >> b >> c;
    if((a.at(a.size()-1) == b.at(0)) && (b.at(b.size()-1) == c.at(0))){
        cout << "YES" << endl;
    }
    else{
        cout << "NO" << endl;
    }
}

Measured memory_bytes: 256
cups = [1, 0, 0]
while line = gets
    case line.chomp!
    when "A,B", "B,A"
        cups[0], cups[1] = cups[1], cups[0]
    when "A,C", "C,A"
        cups[0], cups[2] = cups[2], cups[0]
    when "B,C", "C,B"
        cups[1], cups[2] = cups[2], cups[1]
    end
end
ABC = "ABC"
puts "ABC"[cups.index{|cup| cup == 1}]

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

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

ll dp[105][105];

int main()
{
    ll V, E;
    cin >> V >> E;

    REP(i, V)
    {
        REP(j, V)
        {
            dp[i][j] = INF;
        }
        dp[i][i] = 0;
    }
    REP(i, E)
    {
        ll s, t, d;
        cin >> s >> t >> d;
        dp[s][t] = d;
    }

    REP(k, V)
    {
        REP(i, V)
        {
            REP(j, V)
            {
                if (dp[i][k] == INF || dp[k][j] == INF)
                    continue;
                dp[i][j] = std::min(dp[i][j], dp[i][k] + dp[k][j]);
            }
        }
    }

    bool neg = false;
    REP(i, V)
    {
        if (dp[i][i] != 0)
            neg = true;
    }
    if (neg)
        cout << "NEGATIVE CYCLE" << endl;
    else
    {
        REP(i, V)
        {
            REP(j, V)
            {
                if (dp[i][j] == INF)
                    cout << "INF";
                else
                    cout << dp[i][j];

                if (j < V - 1)
                    cout << " ";
            }
            cout << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 3176
<?php
// Your code here!
fscanf(STDIN, "%d", $input_count);
$target_arr = [];
$prev_output = 0;
for ($i = 0; $i < $input_count; $i++) {
    $command = explode(" ", trim(fgets(STDIN)));
    if ($command[0] == 0) {
        array_push($target_arr, $command[1]);
    } elseif ($command[0] == 1) {
        if ($prev_output) {
            echo "\n";
        }
        echo $target_arr[$command[1]];
        $prev_output = 1;
    } elseif ($command[0] == 2) {
        array_pop($target_arr);
    } 
    
}


?>



Measured memory_bytes: 44520
#include<iostream>
#include<vector>

int main(){

    size_t n;
    std::cin >> n;

    std::vector<char> c(n);
    size_t cnt_red = 0, cnt_white = 0;
    for(auto&& e : c){
        std::cin >> e;
        if(e == 'R'){
            cnt_red++;
        }else{
            cnt_white++;
        }
    }

    size_t cnt_left_red = 0, cnt_left_white = 0;
    for(size_t i = 0; i < cnt_red; i++){
        if(c.at(i) == 'R'){
            cnt_left_red++;
        }else{
            cnt_left_white++;
        }
    }

    std::cout << std::max(cnt_left_white, cnt_red - cnt_left_red) << std::endl;

    return 0;
}


Measured memory_bytes: 3536
#include <cstdio>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

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

    vector<int> a(m), b(m);
    for(int i=0; i<m; ++i)
        cin >> a[i] >> b[i];

    int ret = 0;
    int i = 1;
    while(i <= n){
        int bMax = -1;
        for(int j=0; j<m; ++j){
            if(a[j] <= i && i <= b[j])
                bMax = max(bMax, b[j]);
        }
        if(bMax == -1){
            cout << "Impossible" << endl;
            return 0;
        }
        i = bMax + 1;
        ++ ret;
    }

    cout << ret << endl;

    return 0;
}

Measured memory_bytes: 0
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Diagnostics;

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

    Scanner cin;
    Func cin2;
    void calc()
    {
        cin = new Scanner();
        cin2 = new Func();
        long n=cin.nextLong();
        long a=1;
        long b=n;
        long x=0;
        for(long i=2;i*i<=n;i++)
        {
            
            if(n%i==0)x=i;
            if(x!=b&&x!=0){a=x;b=n/x;}
            else if(b==x)break;
        }
        
        Console.WriteLine(a+b-2);
        
    }
}



class Scanner
{
    string[] s;
    int i;

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

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

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

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

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

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

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


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

class Answer
{
    public void Int2DArrayAns(int[,]x,char c)
    {
        for(int i=0;i<x.GetLength(0);i++)
        {
            for(int j=0;j<x.GetLength(1)-1;j++)
            {
                Console.Write(x[i,j]);
                Console.Write(c);
            }
            Console.WriteLine(x[i,x.GetLength(1)-1]);
        }
    }
    public void Char2DArrayAns(char[,]x,char c)
    {
        for(int i=0;i<x.GetLength(0);i++)
        {
            for(int j=0;j<x.GetLength(1)-1;j++)
            {
                Console.Write(x[i,j]);
                Console.Write(c);
            }
            Console.WriteLine(x[i,x.GetLength(1)-1]);
        }
    }
}

class Func
{
    public long GCDLong(long a, long b)
    {
        while(a!=0)
        {
          long t=a;
          a=b%a;
          b= t;
        }
      
        return b;        
    }
}

Measured memory_bytes: 13140
#include<iostream>
 using namespace std;
 int main() { 
 int N,A;
 cin>>N>>A;
 int L=A;
 int R=A+N-1;

 int eat;
 if(R<=0)eat=R;
 else if(L>=0)eat=L;
 else eat=0;

 int answer=(R+L)*(R-L+1)/2-eat; 
 cout<<answer<<endl;

 return 0;

 }



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

public class Main {
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();

        char[] s = sc.next().toCharArray();
        int n = s.length;

        int cnt = 0;
        for (int i = 0; i < n/2; i++) {
            if (s[i] != s[n-i-1])
                cnt++;
        }

        System.out.println(cnt);
    }

    static class MyScanner {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in), 1 << 15);
        StringTokenizer tokenizer;

        String next() {
            try {
                while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                    tokenizer = new StringTokenizer(reader.readLine());
                }
            } catch (IOException ignored) {
            }
            return tokenizer.nextToken();
        }

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

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

Measured memory_bytes: 22228
#include<iostream>
#include<sstream>
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<cfloat>
#include<functional>
#include<map>
#include<string>
#include<cstring>
#include<vector>
#include<queue>
#include<stack>
#include<deque>
#include<set>
#include<bitset>
#include<list>
#include<numeric>
#include<complex>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<long long, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<long long, long long> ll_ll;
typedef pair<double, double> d_d;
typedef vector<int> vint;
typedef vector<char> vchar;

#define PI 3.141592653589793238462643383279
#define intinf 200000014
#define longinf 200000000000000014LL
#define mod 1000000007LL
#define rep(i, n) for(i = 0;i < n;++i)
#define rep1(i, n) for(i = 1;i < n;++i)
#define rep2d(i, j, n) for(i = 0;i < n;++i)for(j = i + 1;j < n;++j)
#define per(i, n) for(i = n - 1;i > -1;--i)
#define int(x) int x; scanf("%d",&x)
#define int2(x, y) int x, y; scanf("%d%d",&x, &y)
#define int3(x, y, z) int x, y, z; scanf("%d%d%d",&x, &y, &z)
#define sc(x) cin >> x
#define sc2(x, y) cin >> x >> y
#define sc3(x, y, z) cin >> x >> y >> z
#define scn(n, a) rep(i, n)cin >> a[i]
#define sc2n(n, a, b) rep(i, n)cin >> a[i] >> b[i]
#define pri(x) cout << x << "\n"
#define pri2(x, y) cout << x << " " << y << "\n"
#define pri3(x, y, z) cout << x << " " << y << " " << z << "\n"
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define kabe puts("---------------------------")
#define kara puts("")
#define debug(x) cout << " --- " << x << "\n"
#define debug2(x, y) cout << " --- " << x << " " << y << "\n"
#define debug3(x, y, z) cout << " --- " << x << " " << y << " " << z << "\n"
#define debugn(i, n, a) rep(i, n)cout << " --- " << a[i] << "\n";
#define debugin(i, n, a) rep(i, n)printf(" --- %10d\n", a[i])
#define debugi2n(i, n, a, b) rep(i, n)printf(" --- %10d %10d\n", a[i], b[i])
#define debugiin(i, n, a) rep(i, n)printf(" --- %10d %10d\n", a[i].first, a[i].second)
#define X first
#define Y second
#define eps 0.0001
#define prid(x) printf("%.15lf\n", x)

struct edge{
  int to, cost;
};

vector<edge> G[100000];

ll dijkstra(int v, int e, int r){
  ll res;
  int i, j;
  ll d[v];
  rep(i, v)d[i] = longinf;
  d[r] = 0LL;
  priority_queue<ll_i, vector<ll_i>, greater<ll_i> > Q;
  Q.push(mp(0LL, r));
  for(;!Q.empty();){
    ll_i now = Q.top();
    Q.pop();
    if(d[now.Y] < now.X)continue;
    rep(i, G[now.Y].size()){
      edge tmp = G[now.Y][i];
      if(d[tmp.to] > d[now.Y] + tmp.cost){
        d[tmp.to] = d[now.Y] + tmp.cost;
        Q.push(mp(d[tmp.to], tmp.to));
      }
    }
  }

  rep(i, v){
    if(d[i] >= longinf)pri("INF");
    else pri(d[i]);
  }

  return 0;
}

signed main(void){
  int i, j, tmp, tmp2;
  for(int testcase = 0;;testcase++){
    int3(v, e, r);
    rep(i, e){
      int3(s, t, d);
      G[s].pb((edge){t, d});
    }
    dijkstra(v, e, r);


/*/

//*/ break;
  }
  return 0;
}

Measured memory_bytes: 12748
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int n;
    string s;
    std::cin >> n >>s;
    int p[300001];
    p[0]=0;
    for (int i = 1; i <= s.length(); i++) {
        if(s[i-1]=='W'){
            p[i]=p[i-1];
        }else{
            p[i]=p[i-1]+1;
        }
    }
    int ans=n;
    for (int i = 1; i <= s.length(); i++) {
        int tmp=0;
        
        tmp+=(i-1)-p[i-1];
        tmp+=(p[n]-p[i]);
        
        ans=min(ans,tmp);
    }
    
    std::cout << ans << std::endl;
}


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

using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1000000000; //
const ll LINF = (ll) 4000000000000000000; //
const ll MOD = (ll) 1000000007; //
const double PI = 3.1415926535898; //

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,n) for(int i=1;i<=(int)(n);i++)
#define rep3(i,n) for(int i=0;i<=(int)(n);i++)
#define REP(i,m,n) for(int i=m;i<(int)(n);i++)
#define repll(i,n) for(ll i=0;i<(ll)(n);i++)
#define repll2(i,n) for(ll i=1;i<=(ll)(n);i++)
#define REPLL(i,m,n) for(ll i=m;i<(ll)(n);i++)
#define MP make_pair
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define NP(v) next_permutation(v.begin(),v.end())

//------------------------------------------------------

int main() {
    int n;
    cin >> n;
    if (n <= 2) {
        cout << 1 << endl;
        return 0;
    }
    vector<int> a;

    rep(i, n) {
        int b;
        cin >> b;
        if (a.empty() || (a.back() != b)) a.push_back(b);
    }

    n = (int) a.size();

    int cnt = 1;
    bool cut[n - 1] = {};
 
    rep(i, n - 2) {
        if (((a[i] < a[i + 1] && a[i + 1] > a[i + 2]) || (a[i] > a[i + 1] && a[i + 1] < a[i + 2]))
                && !cut[i]&&!cut[i + 1]) {
            cnt++;
            cut[i + 1] = true;
        }
    }
 
    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 892
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MOD = 1000000007;
const ld PI = acos(-1);  
const ld EPS = 0.0000000001;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define REP(i, n) for(ll i=0; i<(ll)(n); i++)
#define REPD(i, n) for(ll i=n-1; 0<=i; i--)
#define FOR(i, a, b) for(ll i=a; i<(ll)(b); i++)
#define FORD(i, a, b) for(ll i=a; (ll)(b)<=i; i--)
#define ALL(x) x.begin(), x.end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))


int main(){
    int n;  cin >> n;
    vector<ll> x(n), y(n), v;
    REP(i, n)   cin >> x[i] >> y[i];

    REP(i, n)   v.push_back(i);
    sort(ALL(v));
    double res=0;
    int cnt=0;
    do{
        REP(j, n-1){
            double dx = pow(x[v[j]]-x[v[j+1]], 2.0);
            double dy = pow(y[v[j]]-y[v[j+1]], 2.0);
            res += pow(dx+dy, 0.5);
        }
        cnt += 1;
    }while(next_permutation(ALL(v)));    
    cout << fixed << setprecision(20) << res/cnt << endl;
}


Measured memory_bytes: 384
(let ((a (read))
      (b (read))
      (c (read))
      (d (read)))
  (cond
    ((<= a c b d)
     (format t "~A~%" (- b c)))
    ((<= c a d b)
     (format t "~A~%" (- d a)))
    ((<= a c d b)
     (format t "~A~%" (- d c)))
    ((<= c a b d)
     (format t "~A~%" (- b a)))
    (t
      (format t "0~%"))))



Measured memory_bytes: 13288
n,m,l=map(int,raw_input().split())
INF=(10**9)+1

g=[]
f=[]
for i in xrange(n):
    g.append([INF]*(n))
    f.append([INF]*(n))

for i in xrange(len(g)):
    for j in xrange(len(g)):
        if i==j:
            g[i][j]=0
            f[i][j]=0

for i in xrange(m):
    a,b,c=map(int,raw_input().split())
    g[a-1][b-1]=c
    g[b-1][a-1]=c
    f[a-1][b-1]=c
    f[b-1][a-1]=c

for k in xrange(n):
    for i in xrange(n):
        for j in xrange(n):
            g[i][j]=min(g[i][j],g[i][k]+g[k][j])
            f[i][j]=min(f[i][j],f[i][k]+f[k][j])

for i in xrange(n):
    for j in xrange(n):
        if f[i][j]<=l:
            g[i][j]=1
        else:
            g[i][j]=INF
        if i==j:
            g[i][j]=0

for k in xrange(n):
    for i in xrange(n):
        for j in xrange(n):
            g[i][j]=min(g[i][j],g[i][k]+g[k][j])

q=int(raw_input())
for i in xrange(q):
    s,t=map(int,raw_input().split())
    u=g[s-1][t-1]

    if u>=INF:
        print (-1)
    else:
        print (u-1)

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

#define for_(i,a,b) for(int i=a;i<b;++i)
#define ALL(a) a.begin(),a.end()
#define INIT(a,b) memset(a,b,sizeof(a))
using lint = long long int;

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

    int n = S.size(), sum = 0;
    for_(i,0,n) sum += (S[i] - '0');
    puts(sum % 9 == 0 ? "Yes" : "No");
}

Measured memory_bytes: 3676
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <cassert>

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

using namespace std;
typedef long long int ll;
const ll INF = 1000000000000000000;
const double PI = acos(-1);

int main()
{
    ll n;
    cin >> n;
    string ans;
    while (n) {
        n--;
        ans += 'a' + n % 26;
        n /= 26;
    }
    reverse(ans.begin(), ans.end());
    cout << ans << endl;
    return 0;
}

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

int main() {
  int N, A, B, p1;
  cin >> N >> A >> B;

  p1 = A * N;
  if (p1 <= B) {
    cout << p1 << endl;
  }
  else {
    cout << B << endl;
  }
}


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

struct Process {
  char name[10];
  int time;
};

template <typename M>
struct Queue {
  vector<M> members;
  int count = 0;

  void push(M m) {
    members.push_back(m);
    count++;
  }

  M pop() {
    M m = members[0];
    rotate(members.begin(), members.begin() + 1, members.end());
    members.pop_back();
    count--;
    return m;
  }

  int size() {
    return count;
  }

  bool empty() {
    return count == 0;
  }
};

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

  Queue<Process> processes;

  for (int i = 0; i < n; i++) {
    Process p;
    scanf("%s %d", &p.name, &p.time);
    processes.push(p);
  }

  int time_consumed = 0;
  while (!processes.empty()) {
    Process p = processes.pop();
    if (p.time <= q) {
      time_consumed += p.time;
      printf("%s %d\n", p.name, time_consumed);
    } else {
      p.time -= q;
      time_consumed += q;
      processes.push(p);
    }
  }

  return 0;
}



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

int main() {
	int n;
	cin>>n;
	long long int d;
	cin>>d;
	 d = d*d;
	int count =0;
	while(n--){
	   long long int x,y;
	   cin>>x>>y;
	   long long int sum = x*x;
	   sum+=y*y;
	   if(sum<=d)
	    count++;
	}
	cout<<count<<endl;
}

Measured memory_bytes: 3628
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<algorithm>
#include<math.h>
#include<iomanip>

using namespace std;
typedef pair<int, int> P;
typedef long long int ll;
const int INF = 1<<30;
int main(){
  int n;cin>>n;
  int t=(int)sqrt(n*2)-1;
  while(t*(t+1)<n*2)t++;
  for(int i=1;i<=t;i++){
    if(i==(t*(t+1)/2)-n)continue;
    cout<<i<<endl;
  }
}


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

int main(){
  int sum = 0;
  int k = 0;
  int n = 0;

  while(cin>>k){
    sum=0;

    if( k<2 or k>100){
   break;
 }

    n = (k*(k-1))/2;

    int c[n];

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

      cin>>c[i];
      sum += c[i];
  
 if(c[i]<0 or c[i]>100){
   break;
 }
    }
  
    cout<<sum/(k-1)<<endl;
  }
    return 0;
}

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

class Program
{
    static void Main(string[] args)
    {
        var line1 = Console.ReadLine().Split(' ').Select(n => int.Parse(n)).ToList();
        var N = line1[0];
        var M = line1[1];

        // key=桁数、val:数値
        Dictionary<int, int> ranks = new Dictionary<int, int>();

        for (int i = 0; i < M; i++)
        {
            var line = Console.ReadLine().Split(' ').Select(n => int.Parse(n)).ToList();
            var s = N + 1 - line[0];
            var c = line[1];

            if (s > 1 && s == N && c == 0)
            {
                Console.WriteLine("-1");
                return;
            }

            if (!ranks.ContainsKey(s))
            {
                ranks.Add(s, c);
            }
            else
            {
                if (ranks[s] != c)
                {
                    Console.WriteLine("-1");
                    return;
                }
            }
        }

        var min = (long) Math.Pow(10, N - 1);

        long answer = 0;
        foreach (var kvp in ranks)
        {
            var val = (long) Math.Pow(10, kvp.Key - 1) * kvp.Value;
            answer += val;
        }

        if (min >= 10 && answer < min)
        {
            answer += min;
        }

        Console.WriteLine(answer.ToString());
    }
}

Measured memory_bytes: 13396
#include<iostream>
#include <cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;


int main(){
  string S; cin >> S;
  int N = S.size();
  ll cnta=0, cntab=0, cntabc=0, cnthatena=1;
  rep(i, N){
    if(S[i]=='A') cnta+=cnthatena; cnta%=mod;
    if(S[i]=='B') cntab+=cnta; cntab%=mod;
    if(S[i]=='C') cntabc+=cntab; cntabc%=mod;
    if(S[i]=='?'){
      cntabc*=3; cntabc%=mod; cntabc+=cntab; cntabc%=mod;
      cntab*=3; cntab%=mod; cntab+=cnta; cntab%=mod;
      cnta*=3; cnta%=mod; cnta+=cnthatena; cnta%=mod;
      cnthatena*=3; cnthatena%=mod;
      }
    }
  cout << cntabc << endl;
}

Measured memory_bytes: 512
#include <stdio.h>
 
int main() {
  char ch[250]={0};
  char a[250] ={0};
  int h;
  int i,j,k,l,n,m;
 
 
  while(1){
    i=0;
    while(1){
       
      scanf("%c",&ch[i]);
      if(ch[i] == '\n') {    
    break;
      }
       
      i++;
    }
    
    if ( i == 1 && ch[0] == '-' ) break;
 
    //  printf("%d",i);
     
    scanf("%d",&m);
     
    for(j=0;j<m;j++){
      scanf("%d", &h );
       
      for(k=0;k<i-h;k++) {
    a[k] = ch[h+k];
    //    printf("a[%d] = ch[%d]の%c\n",k ,h+k,ch[h+k]);
      }
      for(k=0;k<h;k++){
    a[i-h+k] = ch[k];
    //   printf("a[%d] = ch[%d]の%c\n",i-h+k,k,ch[k]);
      }
      for(k=0; k<i; k++){
    ch[k] = a[k];
    // printf("ch[%d] = a[%d]の%c\n",k,k,a[k]);
      }
    }
    for(k=0;k<i;k++) {
      printf("%c",ch[k]);
    }
    printf("\n");
      scanf("%c",&ch[0]);
  }
   
   
  return 0;
   
}


Measured memory_bytes: 2068
//Coded by Abhijay Mitra
#include <iostream>
#include <stdlib.h>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <numeric>
#include <vector>
#include <iterator> 
#include <map>
#include <set>
#include <climits>
#include <queue>
#include <cmath>
#include <stack>
#include <cctype>
#include <bitset>
// #include <bits/stdc++.h>
#define double long double
#define int long long int
#define ll int
#define ibs ios_base::sync_with_stdio(false)
#define cti cin.tie(0)
#define bp __builtin_popcount
#define pb emplace_back
#define koto_memory(a) cout<<(sizeof(a)/1048576.0)<<" MB";
#define res(v) sort(all(v)),v.erase(unique(all(v)), v.end());
#define timer cerr << "Time elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n";
#define deb(x) cout<<"\n["<<#x<<" = "<<x<<"]\n";
using vi = std::vector<int>;
using vvi = std::vector<vi>;
using pii = std::pair<int,int>;
using vpii = std::vector<pii>;
using vvpii = std::vector<vpii>;
#define mp         make_pair
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define per(i,b,a) for (int i = b; i >= a; i--)
#define all(x)     x.begin(), x.end()
using namespace std;
const int N=2e6+10;
const int inf = /*0x3f3f3f3f*/1e18+10;
// const ll M = 998244353 ; // Mulo
// const int M = 1e9+7 ; // Mulo
const double Pi = 3.14159265;
#define F first
#define S second
void solve(){
  string s;cin>>s;
  int len=3;
  if(s[0]!='R' or s[1]!='R' or s[2]!='R')len=min(len,2LL);
  if(s[1]!='R')len=min(len,1LL);
  if(s[0]=='S' and s[2]=='S')len=min(len,1LL);
  if(s[0]=='S' and s[1]=='S' and s[2]=='S')len=0;
  cout<<len;
}
int32_t main()
{
  ibs;cti;
  solve();return 0;
  /*,cout<<"\n"*/;
  // cout<<"\n";
  int xx=0;
  int t;cin>>t;while(t--){/*xx++;cout<<"Case "<<xx<<":\n"*/;solve();cout<<"\n";}
  return 0;
}

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

int main() {
    int ha, sa, hb, sb;
    cin >> ha >> sa >> hb >> sb;
    int turn = 0;
    while (ha > 0 && hb > 0) {
        turn ^= 1;
        if (turn) {
            hb -= sa;
        } else {
            ha -= sb;
        }
    }
    if (ha > 0) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }
    return 0;
}

Measured memory_bytes: 3636
#define _CRT_SECURE_NO_WARNINGS 1

#include <iostream>
#include <string>
#include <string.h>
#include <limits>
#include <utility>
#include <vector>
#include <algorithm>
#include <functional>
#include <stack>
#include <unordered_set>
#include <unordered_map>
#include <chrono>

using namespace std;

namespace
{

const int N_MAX = 100000;

}

#if 1
int main()
{
	int n;
	vector<int> A;
	vector<int> B;

	vector<int> clear;

	cin >> n;

	int64_t failedPoint = 0;
	int failedCount = 0;

	A.resize(n);
	B.resize(n);
	for (int i = 0; i < n; i++)
	{
		scanf("%d", &A[i]);
	}
	for (int i = 0; i < n; i++)
	{
		scanf("%d", &B[i]);

		if (B[i] > A[i])
		{
			failedPoint += B[i] - A[i];
			failedCount++;
		}
		else
		{
			clear.push_back(A[i] - B[i]);
		}
	}

	std::sort(clear.begin(), clear.end(), std::greater<int>());

	if (failedPoint <= 0)
	{
		cout << 0;
		return 0;
	}

	int usedClearCount = 0;
	for (size_t i = 0; i < clear.size(); i++)
	{
		failedPoint -= clear[i];
		usedClearCount++;

		if (failedPoint <= 0)
		{
			cout << usedClearCount + failedCount;
			return 0;
		}
	}

	cout << -1;
	return 0;
}
#endif


Measured memory_bytes: 1660
#include <iostream>
#define REP(i,n) for(int i=0;i<n;++i)
using namespace std;
const int MAX_N = 100;

int main()
{
  int N, A[MAX_N], flag, cnt;
  cin >> N;
  REP(i, N) cin >> A[i];

  flag = 1;
  cnt = 0;
  while (flag) {
    flag = 0;
    REP(i, N) {
      if (i == 0) continue;
      if (A[N-i] < A[N-i-1]) {
        swap(A[N-i], A[N-i-1]);
        cnt++;
        flag = 1; 
      }
    }
  }
  REP(i, N-1) cout << A[i] << ' ';
  cout << A[N-1] << endl;
  cout << cnt << endl;

  return 0;
}

Measured memory_bytes: 3088
#include<bits/stdc++.h>
#define rg register  
const int MN=400000+5;
using namespace std;
typedef long long ll;
template<typename T>inline T&IN(T&in){
	in=0;char c=getchar();int f=1;
	while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
	while(isdigit(c))in=in*10+c-'0',c=getchar();
	return in*=f;
}
queue<int>q;
int n,ans,m;char c[MN];
int d[MN][2],vis[MN],w[MN];
int nxt[MN],to[MN],h[MN],cnt;
void add(int u,int v){to[cnt]=v,nxt[cnt]=h[u],h[u]=cnt++;}
void input(){
	IN(n);IN(m);memset(h,-1,sizeof h);ans=n;
	scanf("%s",c+1);
	for(int i=1;i<=n;++i)w[i]=c[i]-'A';
	for(int i=1,u,v;i<=m;++i){
		IN(u),IN(v);add(u,v),add(v,u);
		d[v][w[u]]++,d[u][w[v]]++;
	}
	for(int i=1;i<=n;++i)if(!d[i][0]||!d[i][1])vis[i]=1,q.push(i),ans--;
	while(!q.empty()){
		int u=q.front();q.pop();
		for(int e=h[u],v=to[e];~e;e=nxt[e],v=to[e]){
			d[v][w[u]]--;
			if(!d[v][w[u]]&&!vis[v])q.push(v),ans--,vis[v]=1;
		}
	}
	if(ans)puts("Yes");
	else puts("No");
}
int main(){
	input();
	return 0;
}

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

using ll = long long;

int main() {
    int N, L;
    cin >> N >> L;
    vector<int> a(N);
    rep(i, N) cin >> a[i];
    int max2 = 0, maxi;
    rep(i, N - 1) {
        int s = a[i] + a[i + 1];
        if (s > max2) {
            max2 = s;
            maxi = i;
        }
    }
    if (max2 < L) {
        cout << "Impossible\n";
    } else {
        cout << "Possible\n";
        rep(i, maxi) {
            cout << i + 1 << "\n";
        }
        for (int i = N - 1; i > maxi + 1; i--) {
            cout << i << "\n";
        }
        cout << maxi + 1 << "\n";
    }
}

Measured memory_bytes: 1152
<?php
  
$n = trim(fgets(STDIN));
$h = explode(' ', trim(fgets(STDIN)));

$m = $h[0];
$c = 1;
for($i=1; $i<$n; $i++){
  if ($h[$i]>=$m) {
    $c++;
    $m = $h[$i];
  }
}
  
echo $c;

?>

Measured memory_bytes: 4604
import math
N = int(input())
 
def minus_2(n):
    ans = ''
    if n == 1:
        ans += '1'
    elif n == 0:
        ans += '0'
    else:
        while n != 1:
            if n % 2 == 0:
                ans += '0'
            else:
                ans += '1'
            n = math.ceil(n/-2)
        ans += '1'
        ans = ans[::-1]
        
    return ans
 
print(minus_2(N))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define MP make_pair
#define PB push_back
#define int long long
#define st first
#define nd second
#define rd third
#define FOR(i, a, b) for(int i =(a); i <=(b); ++i)
#define RE(i, n) FOR(i, 1, n)
#define FORD(i, a, b) for(int i = (a); i >= (b); --i)
#define REP(i, n) for(int i = 0;i <(n); ++i)
#define VAR(v, i) __typeof(i) v=(i)
#define FORE(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
using namespace std;
template<typename TH> void _dbg(const char* sdbg, TH h) { cerr<<sdbg<<"="<<h<<"\n"; }
template<typename TH, typename... TA> void _dbg(const char* sdbg, TH h, TA... t) {
  while(*sdbg != ',')cerr<<*sdbg++; cerr<<"="<<h<<","; _dbg(sdbg+1, t...);
}
#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#define debugv(x) {{cerr <<#x <<" = "; FORE(itt, (x)) cerr <<*itt <<", "; cerr <<"\n"; }}
#else
#define debug(...) (__VA_ARGS__)
#define debugv(x)
#define cerr if(0)cout
#endif
#define next ____next
#define prev ____prev
#define left ____left
#define hash ____hash
typedef long long ll;
typedef long double LD;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<pair<int, int> > VPII;
typedef vector<pair<ll, ll> > VPLL;

template<class C> void mini(C&a4, C b4){a4=min(a4, b4); }
template<class C> void maxi(C&a4, C b4){a4=max(a4, b4); }
template<class T1, class T2>
ostream& operator<< (ostream &out, pair<T1, T2> pair) { return out << "(" << pair.first << ", " << pair.second << ")";}
template<class A, class B, class C> struct Triple { A first; B second; C third;
  bool operator<(const Triple& t) const { if (st != t.st) return st < t.st; if (nd != t.nd) return nd < t.nd; return rd < t.rd; } };
template<class T> void ResizeVec(T&, vector<int>) {}
template<class T> void ResizeVec(vector<T>& vec, vector<int> sz) {
  vec.resize(sz[0]); sz.erase(sz.begin()); if (sz.empty()) { return; }
  for (T& v : vec) { ResizeVec(v, sz); }
}
typedef Triple<int, int, int> TIII;
template<class A, class B, class C>
ostream& operator<< (ostream &out, Triple<A, B, C> t) { return out << "(" << t.st << ", " << t.nd << ", " << t.rd << ")"; }
template<class T> ostream& operator<<(ostream& out, vector<T> vec) { out<<"("; for (auto& v: vec) out<<v<<", "; return out<<")"; }

    
int32_t main() {

  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(10);
  cerr << fixed << setprecision(10);
  cin.tie(0);
  //double beg_clock = 1.0 * clock() / CLOCKS_PER_SEC;
  
  string s;
  cin>>s;
  VI pos;
  string t;
  int cntx = 0;
  REP (i, SZ(s)) {
    if (s[i] == 'x') {
      cntx++;
    } else {
      pos.PB(cntx);
      cntx = 0;
      t += string(1, s[i]);
    }
  }
  pos.PB(cntx);
  string revt = t;
  reverse(ALL(revt));
  if (t != revt) {
    cout<<"-1\n";
    return 0;
  }
  int res = 0;
  for (int fin1 = 0; fin1 < SZ(pos); fin1++) {
    if (fin1 < SZ(pos) - 1 - fin1) {
      res += abs(pos[fin1] - pos[SZ(pos) - 1 - fin1]);
    }
  }
  cout<<res<<endl;
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  return 0;
}


Measured memory_bytes: 1608
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		//文字の入力
		String s = sc.next();
		//条件分岐
		if(s.equals("a") || s.equals("e") || s.equals("i") ||
				s.equals("o") || s.equals("u")) {
			System.out.println("vowel");
			return;
		}else {
			System.out.println("consonant");
		}
	}

}


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

int main(){
  int N;
  cin >> N;
  int min = int(N/1.08);
  int ans;
  bool enable = false;
  for(int i = min; i <= N; i++){
    if(int(i*1.08) == N){
      ans = i;
      enable = true;
      break;
    }
  }
  if(enable) cout << ans << endl;
  else cout << ":(" << endl;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	Scanner in = new Scanner(System.in);
	public static void main(String[] args) {
		new Main();
	}

	public Main() {
		new AOJ0223().doIt();
	}

	class AOJ0223{
		int x,y;
		
		void solve(){
			Person p1 = new Person(in.nextInt()-1, in.nextInt()-1);
			Person p2 = new Person(in.nextInt()-1, in.nextInt()-1);
			int[][] map = new int[y][x];
			boolean[][][][] memo = new boolean[y][x][y][x];
			int INF = Integer.MAX_VALUE/2;
			for(int i=0;i<y;i++)for(int s=0;s<x;s++)map[i][s] = in.nextInt();
			LinkedList<Data> q = new LinkedList<Data>();
			q.add(new Data(p1,p2,0));
			int sx[] = {1,0,-1,0};
			int sy[] = {0,1,0,-1};
			int sx2[] = {-1,0,1,0};
			int sy2[] = {0,-1,0,1};
			boolean isNA = true;
			int result = 0;
			while(q.size()>0){
				Data data = q.remove();
				Person t = data.p1;
				Person k = data.p2;
				if(data.cost>=100)continue;
				if(t.x==k.x&&t.y==k.y){
					isNA = false;
					result = data.cost;break;
				}
				for(int i=0;i<4;i++){
					int nx1 = t.x+sx[i];
					int ny1 = t.y+sy[i];
					int nx2 = k.x+sx2[i];
					int ny2 = k.y+sy2[i];
					if(nx1<0||nx1>=x||ny1<0||ny1>=y){
						nx1 = t.x;ny1 = t.y;
					}
					if(map[ny1][nx1]==1){
						nx1 = t.x;ny1 = t.y;
					}
					if(nx2<0||nx2>=x||ny2<0||ny2>=y){
						nx2 = k.x;ny2 = k.y;
					}
					if(map[ny2][nx2]==1){
						nx2 = k.x;ny2 = k.y;
					}
					if(memo[ny1][nx1][ny2][nx2]==true)continue;
					memo[ny1][nx1][ny2][nx2] = true;
					q.add(new Data(new Person(nx1, ny1),new Person(nx2, ny2),data.cost+1));
				}
			}
			System.out.println(isNA==true? "NA":result);
		}

		void doIt(){
			while(true){
				x = in.nextInt();y = in.nextInt();
				if(x+y==0)break;
				solve();
			}
		}
		
		class Person{
			int x, y;
			public Person(int x,int y) {
				this.x = x;
				this.y = y;
			}
		}
		
		class Data{
			int cost;
			Person p1,p2;
			public Data(Person p1,Person p2,int cost) {
				this.p1 = p1;
				this.p2 = p2;
				this.cost = cost;
			}
			public String toString(){
				return p1.x+" "+p1.y+" ::: "+p2.x+" "+p2.y+" +++ "+cost;
			}
		}
	}


}

Measured memory_bytes: 170088
//F.cpp
#include<bits/stdc++.h>

#include <unordered_map>
using namespace std;

int main(){
	string s;
	string t;
	cin >> s >> t;

	int n = s.size();
	int m = t.size();

	vector< vector<int> > dp(n+1, vector<int>(m+1, 0));

	vector< vector<short int> > par(n+1, vector<short int>(m+1, -1));


	int v;
	int maxl = 0;
	int ii, jj;
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= m; j++){
			v =0;
			if(s[i-1] == t[j-1]){
				v = dp[i-1][j-1] + 1;
				par[i][j] = 3;
			}
			else{
				if(dp[i-1][j] > v){
					v = dp[i-1][j];
					par[i][j] = 2;
				}
				if(dp[i][j-1] > v){
					v = dp[i][j-1];
					par[i][j] = 1;
				}

			}
			dp[i][j] = v;
			if(maxl < v){
				maxl = v;
				ii = i;
				jj = j;
			}
			//cout << dp[i][j] << " ";
		}
		//cout << endl;
	}

	//cout << ii << " " << jj << " " << maxl << endl;;

 	// for(int i = 0; i < n; i++){
 	// 	for(int s = 0; s <= sumv; s++){
 	// 		cout << dp[i][s] << " "; 
 	// 	}
 	// 	cout << endl;
 	// }
	string ans;
	int p;
	if(maxl){
		p = par[ii][jj];
		//cout << p << endl;
		while( p != -1){
			if(s[ii-1] == t[jj-1]){
				ans.push_back(s[ii-1]);
			}
			if(p%2)
				jj -= 1;
			if(p/2)
				ii -= 1;
			p = par[ii][jj];
		}

	}
	reverse(ans.begin(), ans.end());
 	cout << ans << endl;;

	return 0;

	
		
}

Measured memory_bytes: 56252
#include <iostream>

using namespace std;
int main(int argc, char *argv[]) {
	int n,k,res=1;
	cin >> n >> k;
	for(int i=0; i<n; i++){
		if(res*2 > res+k)res+=k;
		else res*=2;
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int m,n,a[1000],i,k,st,c;
  while(1){
    c=0;
    scanf("%d%d",&n,&m);
    if(n==0&&m==0)break;
    k=n;
    for(i=0;i<n;i++){
      scanf("%d",&a[i]);
    }
    while(k!=0){
      for(i=1;i<k;i++){
	if(a[i-1]>a[i]){
	  st=a[i];
	a[i]=a[i-1];
	a[i-1]=st;
	}
      }
	k--;
    }
    for(i=n;i>=0;i-=m){
      a[i]=0;
    }
    for(i=0;i<n;i++){
      c+=a[i];
    }
    printf("%d\n",c);
  }
  return 0;
}

Measured memory_bytes: 1032
import sys
input = sys.stdin.readline
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
##############################

A = ['Sunny', 'Cloudy', 'Rainy']
S = input().rstrip()
if S == A[0]:
    print(A[1])
elif S == A[1]:
    print(A[2])
elif S == A[2]:
    print(A[0])


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

class MainClass
{
    static void Main()
    {
        int N = int.Parse(ReadLine());
        var L = ReadLine().Split().Select(long.Parse).ToArray();
        Array.Sort(L);
        long ans = 0;
        for (int i = 0; i < N-2; i++)
        {
            
            for (int j = i+1; j < N-1; j++)
            {
                
                for (int k = j+1; k < N; k++)
                {
                    if (L[i] < L[j] + L[k] && L[j] < L[i] + L[k] && L[k] < L[i] + L[j]
                        &&L[i]<L[j]&&L[j]<L[k])
                    {
                        ans++;
                    }
                }
            }
        }
        WriteLine(ans);
    }
}


Measured memory_bytes: 28252