akhauriyash/Code-Regression huggingface dataset:
def slove():
    import sys, heapq
    input = sys.stdin.readline
    n, k = list(map(int, input().rstrip('\n').split()))
    v = list(map(int, input().rstrip('\n').split()))
    ms = 0
    for i in range(1, min(k + 1, len(v) + 1)):
        for j in range(i + 1):
            t = []
            heapq.heapify(t)
            if j != 0:
                for w in v[:j]:
                    heapq.heappush(t, w)
            if -i+j != 0:
                for w in v[-i+j:]:
                    heapq.heappush(t, w)
            for _ in range(k-i):
                if len(t) != 0:
                    p = heapq.heappop(t)
                    if p >= 0:
                        heapq.heappush(t, p)
                        break
                else:
                    break
            ms = max(ms, sum(t))
    print(ms)


if __name__ == '__main__':
    slove()


Measured memory_bytes: 53980
#include <bits/stdc++.h>
using namespace std;
int main(){
  while (1){
    int n, r;
    cin >> n >> r;
    if (n == 0 && r == 0){
      break;
    }
    vector<int> ans(n);
    for (int i = 0; i < n; i++){
      ans[i] = n - i;
    }
    for (int i = 0; i < r; i++){
      int p, c;
      cin >> p >> c;
      p--;
      vector<int> ans2 = ans;
      for (int j = 0; j < c; j++){
        ans2[j] = ans[j + p];
      }
      for (int j = c; j < c + p; j++){
        ans2[j] = ans[j - c];
      }
      swap(ans, ans2);
    }
    cout << ans[0] << endl;
  }
}


Measured memory_bytes: 3136
// Contest.cpp : アプリケーションのエントリ ポイントを定義します。
//

#include"iostream"
#include"string"
#include"vector"
#include"algorithm"

using namespace std;


int main()
{
	int a, b;

	cin >> a>>b;
	
	if (a>=b) {
		int m = a - 1;
		if (m >= b) {
			cout<<a+m<<endl;
		}
		if (m < b) {
			cout<<a+b<<endl;
		}
	}

	if (b > a) {
		int m = b - 1;
		if (m >= a) {
			cout << b+ m << endl;
		}
		if (m < a) {
			cout << a + b << endl;
		}
	}



	return 0;
}




Measured memory_bytes: 256
import java.util.*;

class Main{
  static int H,W,i,j;
  
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    while (true) {
      H = sc.nextInt();
      W = sc.nextInt();
      i = 0;
      if (H == 0 && W == 0) {
        break;
        }
      while (i<H) {
      for (j=0; j<W; j++) {
        if ((j + i) % 2 == 0) {
            System.out.print("#");
            } else {
            System.out.print(".");
        }
      }
          System.out.println("");
          i++;
      }
          System.out.println("");
    }
  }
}



Measured memory_bytes: 34972
from collections import defaultdict

H, W, N = map(int,input().split())
  
ans = [(H-2)*(W-2)] + [0]*9
blacks = defaultdict(int)
for i in range(N):
  a, b = map(int,input().split())
  for dx in [-1,0,1]:
    for dy in [-1,0,1]:
      if 2 <= a+dx <H and 2 <= b+dy <W:
        ans[blacks[(a+dx,b+dy)]]-=1
        ans[blacks[(a+dx,b+dy)]+1]+=1
      blacks[(a+dx,b+dy)]+=1
        
print(*ans,sep="\n")

Measured memory_bytes: 166868
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            String cycle[] = {"Sunny", "Cloudy", "Rainy", "Sunny"};
            String s = in.next();
            for (int i = 0; i < 3; i++) {
                if (s.equals(cycle[i])) {
                    out.println(cycle[i + 1]);
                }
            }
        }

    }
}



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

int main(){
  string S;
  cin >> S;
  vector<int>vec(10,0);
  int a=0;
  
  for(int i=0;i<10;i++){
    if(S[i]=='A'||S[i]=='C'||S[i]=='G'||S[i]=='T'){
      vec[a]++;
    }else{
      a++;
    }
  }
  sort(vec.begin(),vec.end());
  cout << vec[9];
}

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

int main()
{
    int N;
    cin >> N;
    for (int i = 2; ; i *= 2)
    {
        if (N < i)
        {
            cout << i / 2 << endl;
            break;
        }
    }

    return 0;
}


Measured memory_bytes: 256
# 後で１の位から処理するためにひっくり返しておく
S = list(map(int, reversed(input())))
#print("S = ", S)
"""
「2019の倍数か」は「mod 2019 が 0 になるか」と同意。
しかし、普通に切り出して、１つずつチェックすると計算工数がかかるので、累積和を使う。
各桁の値を （桁の数値a_k）× 10^k と表現し、mod 2019 の値を予め計算し、累積和を作っておく。
ここで、10^k の部分は、2019と互いに疎（公約数がない）なので、
含めて計算しても mod 2019 の周期を乱さない。（勿論オフセットは変わる）
「(i, j) が2019で割り切るか」は、「i～j の累積和が同じ値になる（2019周期）か」と同意。
累積和が同じ値になる個数を数えて、組み合わせを計算すればよい。
"""
# a　：　各桁の mod 2019 値（桁の数値 a_k × 10^k mod 2019）
a = [0] * len(S)
# sums ：　累積和
sums = [0] * (len(S) + 1)
# d : 10^k
d = 1
# cnt : 累積和 mod 2019 の出現度数表
cnt = [0] * 2019
cnt[0] = 1  # sums[0] = 0 の分
for i in range(len(S)):
    a[i] = (S[i] * d) % 2019
    sums[i + 1] = (sums[i] + a[i]) % 2019
    d = (d * 10) % 2019 
    cnt[sums[i + 1]] += 1
#print("sums = ", sums)
#print("cnt = ", cnt)
ans = 0
for i in cnt:
    ans += i * (i - 1) // 2
print(ans)


Measured memory_bytes: 24868
function main(t){t=t.split("\n");var r=parseInt(t[0]);a=new Array(r).fill(0),b=new Array(r).fill(0),tmpa=t[1].split(" "),tmpb=t[2].split(" ");var n=0,e=0;for(i=0;i<r;i++)a[i]=parseInt(tmpa[i]),a[i],b[i]=parseInt(tmpb[i]),b[i],Math.abs(a[i]-b[i]),n+=Math.floor(Math.max(0,b[i]-a[i])/2),e+=Math.max(0,a[i]-b[i]);var s="No";e<=n&&(s="Yes"),console.log("%s",s)}main(require("fs").readFileSync("/dev/stdin","utf8"));

Measured memory_bytes: 9536
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int long long int
#define mod 1000000007

int solve(int A[], int n, int k)
{
    int i;
    sort(A, A+n);
    int sum = 0;
    for(i=0;i<k;i++)
        sum+=A[i];

    return sum;
}

int32_t main()
 {
	//code
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int t,n,w,k,x,i;
    //cin>>t;
    t=1;
    while(t--)
    {
        cin>>n>>k;
        int A[n];

        for(i=0;i<n;i++)
            cin>>A[i];

        cout<<solve(A,n, k)<<endl;;
    }

	return 0;
}


Measured memory_bytes: 3596
number = int(input())

def to_bin(n):
    if n == 0:
        return [0]
    
    digits = []
    i = 0
    base = 1
    while n != 0:
        if n % (base * 2) == 0:
            digits.append('0')
        else:
            digits.append('1')
            n -= base
        i+= 1
        base *= -2
    return digits[::-1]

ans_list = to_bin(number)

for ans in ans_list:
    print(ans, end='')


Measured memory_bytes: 3060
#include<stdio.h>

#define N 8
#define FREE 1
#define NOT_FREE 0

int row[N],col[N],dpos[2*N-1],dneg[2*N-1],A[N][N];
int i,j,n,r,c;

void printBoard(){
  for(i = 0; i < N; i++){
    for(j = 0; j < N; j++){
      if(A[i][j] && row[i] != j)return;
    }
  }
  for(i = 0; i < N; i++){
    for(j = 0; j < N; j++){
      if(row[i] == j) printf("Q");
      else printf(".");
    }
    printf("\n");
  }
}

void putQueen(int i){
  int j;
  if(i == N){
    printBoard();
    return;
  }

  for(j = 0; j < N; j++){
    if(col[j] == NOT_FREE || dpos[i+j] == NOT_FREE || dneg[i-j+N-1] == NOT_FREE)continue;
    row[i] = j;
    col[j] = dpos[i+j] = dneg[i-j+N-1] = NOT_FREE;
    putQueen(i+1);
    col[j] = dpos[i+j] = dneg[i-j+N-1] = FREE;
  }
}

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

  for(i = 0; i < 15; i++){
    dpos[i] = dneg[i] = FREE;
  }

  for(i = 0; i < N; i++){
    col[i] = row[i] = FREE;
    for(j = 0; j < N; j++){
      A[i][j] = 0;
    }
  }

  for(i=0;i<n;i++){
    scanf("%d%d",&r,&c);
    A[r][c]=90;
  }
  putQueen(0);
  return 0;
}



Measured memory_bytes: 2148
// Problem : B - An Odd Problem
// Contest : AtCoder - AIsing Programming Contest 2020
// URL : https://atcoder.jp/contests/aising2020/tasks/aising2020_b
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

// #pragma GCC optimize ("O3")
// #pragma GCC target ("sse4")

#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,b,a) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a,x) for (auto& a : x)
 
#define bug(x) cout<<#x<<"="<<x<<endl; 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
 
template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const ld pii=3.14159265359; 
const int MOD = 1000000007;
const char nl = '\n';
const int MX = 200001; //check the limits, dummy
 
int main() 
{
	// && has higher precedence than ||
	ios_base::sync_with_stdio(0); cin.tie(0);    
	int N;
	cin>>N;
	vi v(N);
	int ans=0;
	F0R(x,N)
	{
		cin>>v[x];
		if(x%2==0 && v[x]%2!=0)ans++;
	}
	cout<<ans<<endl;
	return 0;
}
 
// read the question correctly (ll vs int)
// template by bqi343

Measured memory_bytes: 3640
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define MAX 100

int top, S[10000];

int isEmpty(void);
int isFull(void);
void push(int);
int pop(void);

int main(){
  int x,a,b,c;
  char s[MAX];
  top=0;

  while( scanf("%s", s) != EOF ){
    if ( s[0] == '+' ){
      a=pop();
      b=pop();
      push(a+b);

    } else if ( s[0] == '-' ){

      b=pop();
      a=pop();
      push(a-b);
      
    } else if ( s[0] == '*' ){
      a=pop();

      b=pop();
      push(a*b);
      

    } else {
      x = atoi(s);
      push(x);

    }
  }
  printf("%d\n",pop());

  return 0;
}

int isEmpty(){
  return top;
}

int isFull(){
  if (top >= MAX){
    return 0;
  }
  return 1;
}

void push(int x){
  if (isFull()==0){
    printf("スタックが満杯です。");
  }
 
  S[++top] = x;
}

int pop(){
if(isEmpty()==0){
  printf("スタックが空です。"); 
  }
 top--;
 return S[top+1];
}



Measured memory_bytes: 2744
x, k, d = map(int, input().split())

cur = abs(x)  # 座標を正にしてしまいます
rem = k  # 残りの移動回数です

cnt = min(cur // d, k)  # 0に向かって移動する回数です
cur -= d * cnt
rem -= cnt

# 0 % 2 = 0なので、残り回数の場合分けをする必要はないのですが、一応
if rem > 0:
    if rem % 2 == 1:
        cur = cur - d

ans = abs(cur)  # 絶対値を出力することに気をつけてください
print(ans)

Measured memory_bytes: 8956
/*==============================================*\
Codeforces ID:    mdshihab
                                                  |
Name:     Md. Shihabul Minhaz                     |
Study:      CSE, JKKNIU                           |
Address:  Trishal, Mymensingh, Bangladesh         |
                                                  |
 mail:   mdshihabul20171@gmail.com                |
 FB  :   fb.com/mdshihabul.minhaz.7               |
 github: Shihabulminhaz                           |
stopstalk :  mdshihab                             |
                                                  |
@uthor   Md. Shihabul Minhaz (shihab)             |
\*===============================================*/


#include<bits/stdc++.h>
using namespace std;
#define fi(a) scanf("%d",&a);
#define fli(a) scanf("%ld",&a);
#define fll(a) scanf("%lld",&a);
#define pi(a) printf("%d\n",a);
#define ppi(i,a) printf("Case %d: %d\n",i,a);
#define ll long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
void FI()
{
#ifndef ONLINE_JUDGE
    freopen("C:\\Users\\SHIHAB\\Desktop\\input.in","r",stdin);
#endif // ONLINE_JUDGE
}

int main()
{
    fast
    FI(); /// skip this line for compile
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    while(true){
        c-=b;
        a-=d;
        if(c<=0 || a<=0) break;
    }
    if(c<=0) cout << "Yes\n";
    else cout << "No\n";
    return 0;
}



Measured memory_bytes: 3636
# coding: utf-8
# Your code here!

M = 1000000007
def func(x, y):
   if y == 0:
      return 1
   elif y % 2 == 0:
      return func((x * x) % M, y / 2)
   else:
      return (x * func(x, y - 1) % M)

m, n = map(int, input().split())
print(func(m, n))



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

int main(){
  int n; cin>>n;
  vector<pair<int,int>> a(n);
  for(int i=0; i<n; ++i){
    int aa; cin>>aa;
    a[i]=make_pair(aa, i+1);
  }

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

  for(int i=0; i<n; ++i)cout<<a[i].second<<" ";
  cout<<endl;
}


Measured memory_bytes: 1664
/////////////////////////   _LeMur_
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <time.h>
#include <stack>
#include <string>
#include <cstring>
#include <cassert>
#include <cstdio>
#include <cmath>
#include <vector>
#include <queue>
#include <map>
#include <set>

using namespace std;

const int N = 100005;
const int inf = 1000 * 1000 * 1000;
const int mod = 1000 * 1000 * 1000 + 7;

int n;
map <long long,int> mp;
long long sum , answ;

int main(){
    scanf("%d",&n);
    mp[0] = 1;
    for(int i=1;i<=n;i++){
        int a;
        scanf("%d",&a);
        sum += a;
        answ += mp[sum];
        mp[sum]++;
    }
    cout<<answ<<endl;
	return 0;
}


Measured memory_bytes: 12800
import java.util.Scanner;

public class Main {
	void run() {
		Scanner scan = new Scanner(System.in);
		String str = scan.next();
		int q = scan.nextInt();
		for (int i = 0; i < q; i++) {
			String method = scan.next();
			int a = scan.nextInt();
			int b = scan.nextInt();
			if (method.equals("print")) {
				print(str, a, b);
			} else if (method.equals("reverse")) {
				str = reverse(str, a, b);
			} else if (method.equals("replace")){
				String p = scan.next();
				str = replace(str, a, b, p);
			}
		}
	}
	void print(String str, int a, int b){
		System.out.println(str.substring(a, b + 1));
	}
	String reverse(String str, int a, int b){
		String s = str.substring(a, b + 1);
		StringBuilder strbul = new StringBuilder(s).reverse();
		return str.replace(s, strbul.toString());
	}
	String replace(String str, int a, int b, String p) {
		String s1 = str.substring(0, a);
		String s2 = str.substring(b + 1, str.length());
		return s1 + p + s2;
	}
	public static void main(String[] args) {
		new Main().run();
	}
}

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

using namespace std;

int a, b, c;

int main()
{
    scanf("%d%d%d",&a,&b,&c);
    if((b / a) >= c)
        printf("%d\n",c);
    else
        printf("%d\n",(b / a));
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

int main(void) {
  int a, b;
  scanf("%d %d", &a, &b);

    if (a < b) printf("%s", "a < b\n");
      if (a > b) printf("%s", "a > b\n");
        if (a == b) printf("%s", "a == b\n");

  return 0;
}



Measured memory_bytes: 2084
//IN THE NAME OF GOD;
//Test By Dev-C++5.11
#include<bits/stdc++.h>
#define ll  long long
#define isc ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define ld long double
#define ss string
#define ww while
#define vl vector<ll>
#define pb push_back
#define in insert
#define vec vector
#define itr iterator
#define gt goto
#define rep(i,n,j) for(ll i=n;i<j;i++)
#define tep(i,n,j) for(ll i=n;i>=j;i--)
#define co(n) cout << n ;
#define pll pair<ll,ll>
#define bft bool f=true
#define bff bool f=false 
using namespace std;


ll kmm(ll a, ll b) {
	return(a*b) / __gcd(a, b);
}

const ll mod = 1e9 + 7;
const ll MAXN = 1e3+5;
ll modpower(ll x,ll n)
{
    if(n==0)
        return 1;
    else if(n%2 == 0)
        return modpower((x*x)%mod,n/2);
    else
        return (x*modpower((x*x)%mod,(n-1)/2))%mod;

}

void solve(){
	ll n,a[MAXN];
  	cin >> n;
	rep(i,0,n)
		cin >> a[i];
	sort(a,a+n);
	cout << a[n-1]-a[0];
}

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


Measured memory_bytes: 256
import sys
x,n=map(int,input().split())
if n==0:
  print(x)
  sys.exit()
p=list(map(int,input().split()))
p.sort()
if p[n-1]<x or x<p[0]:
  print(x)
  sys.exit()
lst=[]
for i in range(n-1):
  if p[i+1]-p[i]>1:
    for j in range(p[i+1]-p[i]-1):
      lst.append(p[i]+j+1)
if len(lst)==0:
  if abs(p[0]-1-x)<=abs(p[n-1]+1-x):
    print(p[0]-1)
    sys.exit()
  else:
    print(p[n-1]+1)
    sys.exit()
if abs(p[0]-1-x)<=abs(p[n-1]+1-x):
  d=abs(p[0]-1-x)
  idx=-2
else:
  d=abs(p[n-1]+1-x)
  idx=-1
for i in range(len(lst)):
  if d>abs(lst[i]-x):
    d=abs(lst[i]-x)
    idx=i
  elif d==abs(lst[i]-x):
    if idx==-1:
      idx=i
if idx==-2:
  print(p[0]-1)
if idx==-1:
  print(p[n-1]+1)
else:
  print(lst[idx])

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



int main(){
    int conp, year;
    cin >> year >> conp;
    if(year == 0){
        conp -= 1867;
        if(conp <= 44){
        cout  << 'M' << conp << '\n';
        }else if(conp <= 58){
            cout << 'T' << conp - 44 << '\n';
        }else if(conp <= 121){
            cout << 'S' << conp - 58 << '\n';
        }else if(conp <= 149){
            cout << 'H' << conp - 121 << '\n';
        }
  }
  
  if(year == 1){
    cout << conp + 1867 << '\n';   
  }else if(year == 2){
      cout << conp + 1911 << '\n';
  }else if(year == 3){
      cout << conp + 1925 << '\n';
  }else if(year == 4){
      cout << conp + 1988 << '\n';
  }
  return 0;
}


Measured memory_bytes: 3132
#include <iostream>
#include <vector>
#include <cstdlib>  
#include <algorithm>

using namespace std;
 
int main() {
    int a,b,c;
    cin >>a>>b>>c;
    if(b+c+a<=21){
      cout<<"win";
    }
    else cout<<"bust";
    return 0;
}

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

int main() { 
    string s; 
    cin >> s;  
    ll k=0; 
    ll mx= 0;
    for(int i=0;i<s.size();i++)
    {
       if(s[i]=='R') k++;   
       if(s[i]=='S') k=0;
       mx= max(mx,k);  
       
    } 
    cout << mx;
    return 0 ;
}

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

int main(){
  long long n, k;
  map<int, int> mp;
  cin >> n >> k;
  for(int i=0;i<n;i++){
    int tmp;
    cin >> tmp;tmp--;
    mp[i]=tmp;
  }

  int a;//周期までk
  int l;//周期l
  vector<int> seen(n);
  int now=0;
  rep(i, n+1){
    now = mp[now];
    if(seen[now]!=0){
      a=i;
      l=i+1-seen[now];
      break;
    }
    seen[now]=i+1;
  }

  now = 0;
  if(k<a){
    rep(i, k)now=mp[now];
  }else{
    rep(i, a)now=mp[now];
    rep(i, (k-a)%l)now=mp[now];
  }
  cout << now+1;

  return 0;
}


Measured memory_bytes: 13556
void main() {
	readln;
	auto a = readAs!(BigInt[]);
	BigInt m = a.reduce!"a*b"-1;
	ulong tmp;
	foreach(i; a) {
		tmp += (m % i).to!ulong;
	}
	tmp.writeln;
}

// ===================================

import std.stdio;
import std.string;
import std.functional;
import std.conv;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}

Measured memory_bytes: 5372
<?php
 	fscanf(STDIN, '%s', $a);
	fscanf(STDIN, '%s', $b);

	$arr1 = str_split($a);
	$arr2 = str_split($b);

	$r = 0;
	for ($i = 0; $i < count($arr1); $i++) {
    	if ($arr1[$i] == $arr2[$i]) {
        	$r++;
        }
    }

	echo $r;
 ?>

Measured memory_bytes: 4604
#難しく考えすぎていた
#こういう問題は最後どうなるかを考える
#最後は結局一番最後のカードを必ず引くことになる
#そのカードをどちらが引くのか
#先攻が圧倒的有利

n,z,w=map(int,input().split())
a=list(map(int,input().split()))
if len(a)==1:
    print(abs(a[-1]-w))
else:
    print(max(abs(a[-1]-w),abs(a[-1]-a[-2])))

Measured memory_bytes: 3188
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.string;

void main() {
    auto N = readln.chomp.to!int;
    auto A = readln.split.map!(to!int).array;
    auto B = N.iota.map!(i => tuple(A[i], i+1)).array;
    B.sort!"a[0] < b[0]";
    B.map!(b => b[1]).map!(to!string).join(" ").writeln;
}


Measured memory_bytes: 5948
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using static System.Console;
using static System.Math;

namespace Atcoder
{
    class Program
    {
        static StreamWriter sw = new StreamWriter(OpenStandardOutput()) { AutoFlush = false };
        static void Main(string[] args)
        {
            try
            {
                SetOut(sw);
                Solve.Answer();
                Out.Flush();
            }
            catch (Exception ex)
            {
                WriteLine(ex.ToString());
                Out.Flush();
            }
        }
    }

    public class Solve
    {
        public static void Answer()
        {
            var abc = IO.RSInt;
            var a = abc[0];
            var b = abc[1];
            var c = abc[2];

            long ans = Min(a + b + 1, c);
            ans += b;
            WriteLine(ans);
        }

    }

    public struct Pair
    {
        public Pair(int a, int b)
        {
            this.a = a;
            this.b = b;
        }
        public int a;
        public int b;
    }

    public class IO
    {
        #region Input
        public static int RInt => int.Parse(ReadLine());
        public static long RLong => long.Parse(ReadLine());
        public static double RDouble => double.Parse(ReadLine());

        public static string[] RSString => ReadLine().Split();
        public static int[] RSInt => ReadLine().Split().Select(s => int.Parse(s)).ToArray();
        public static long[] RSLong => ReadLine().Split().Select(s => long.Parse(s)).ToArray();
        public static double[] RSDouble => ReadLine().Split().Select(s => double.Parse(s)).ToArray();
        #endregion

        #region Output
        public static void OutJoinSpace<T>(IEnumerable<T> list) => WriteLine(string.Join(" ", list));
        public static void WriteLineYes_or_No(bool flag) => WriteLine(flag ? "Yes" : "No");
        public static void WriteLineYES_or_NO(bool flag) => WriteLine(flag ? "YES" : "NO");
        #endregion
    }

    public class Mod
    {
        #region
        private readonly static long M = 1000000007;

        public static long Add(long a, long b) => (a * b) % M;
        public static long Sub(long a, long b) => (a - b) % M >= 0 ? (a - b) % M : (a - b) % M + M;
        public static long Multi(long a, long b) => (a * b) % M;
        #endregion
    }
}

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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define MOD 1000000007LL

#define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++)
#define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++)
#define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++)
#define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++)
#define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--)
#define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--)
#define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--)
#define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--)
#define iter(i, it) for(auto &(i): (it))

template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) {
    cout << "(" << m.first << ", " << m.second << ")";
    return s;
}
template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) {
    ll c = 0;
    cout << "{ ";
    iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
    cout << "{ ";
    rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const list<T> &v) {
    ll c = 0;
    cout << "{ ";
    iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}

int main(void) {
    ll N, K, X, Y;
    cin >> N >> K >> X >> Y;
    cout << X * min(N, K) + Y * max(0LL, N - K) << endl;
    return 0;
}


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

using namespace std;

const int maxn = 300000; 

int n, m, c[maxn + 5]; 

struct node {
	int l, r; 
	bool operator < (const node &x) const {
		return r - l + 1 < x.r - x.l + 1; 
	}
} a[maxn + 5]; 

int lb (int x) { return x & (-x); }

void add(int x, int d) {
	for (int i = x; i <= n; i += lb(i)) 
		c[i] += d; 
}

int sum(int x) {
	int ret = 0; 
	for (int i = x; i; i -= lb(i))
		ret += c[i]; 
	return ret; 
}

int main() {
  scanf("%d %d", &m, &n); 
  for (int i = 1; i <= m; i++) {
  	scanf("%d %d", &a[i].l, &a[i].r); 
  }
  int pos = 1; 
  sort(a + 1, a + m + 1); 
  for (int i = 1; i <= n; i++) {
    while (pos <= m && a[pos].r - a[pos].l + 1 <= i) {
    	add(a[pos].l, 1); add(a[pos].r + 1, -1); 
      pos++; 
    }
    int ans = m - pos; 
    for (int j = i; j <= n; j += i) {
    	ans += sum(j); 
    }
    printf("%d\n", ans + 1); 
  }
	return 0; 
}

Measured memory_bytes: 3712
#include<bits/stdc++.h>
#define fastIO std::ios_base::sync_with_stdio(false); std::cin.tie(0); std::cout.tie(0)
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define Local
#ifdef Local
  #define dbg(args...) do { cout << #args << " -> "; err(args); } while (0)
  void err() { std::cout << std::endl; }
  template<typename T, typename...Args>
  void err(T a, Args...args) { std::cout << a << ' '; err(args...); }
  template <template<typename...> class T, typename t, typename... A> 
  void err(const T <t> &arg, const A&... args) {
  for (auto &v : arg) std::cout << v << ' '; err(args...); }
#else
  #define dbg(...)
#endif

using namespace std;
typedef vector<int> VI;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PII;
const ll mod = 1000000007;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1.0);
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

const int maxn = 2e5 + 10; 

char s[maxn];

int main()
{
	fastIO;
	int n; 
	cin >> n;
	int ans = 0;
	cin >> s;
	int i = 0, j = n - 1;
	while(i < j) 
	{
		while(s[i] == 'R' && i < n) i++;
		while(s[j] == 'W' && j >= 0) j--;
		if(i < j) 
		{
			ans++;
			swap(s[i],s[j]);
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3780
from math import sqrt

N = int(input())
xy = [list(map(int, input().split())) for _ in range(N)]

result = 0
for i in range(N):
    for j in range(N):
        if i != j:
            result += sqrt((xy[i][0] - xy[j][0]) * (xy[i][0] - xy[j]
                                                    [0]) + (xy[i][1] - xy[j][1]) * (xy[i][1] - xy[j][1]))
print(result / N)


Measured memory_bytes: 3064
//#include <bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<numeric>
#include<cstdio>
#include<cmath>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<stack>
#include<queue>
#include<ctype.h>
#include <fstream>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
using namespace std;
typedef long long ll;//int64
typedef unsigned long long ull;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a*b/gcd(a,b);}
int dy[4]={0,1,0,-1};
//----------program from here----------

int main(){
  int A=0,B=0;

  cin >> A >> B;
  cout << (A+B<24?A+B:A+B-24) << endl;

  return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"io"
	"os"
)

func solve(w io.Writer, r io.Reader) {
	var N, K int
	var S []byte
	fmt.Scan(&N, &K, &S)
	S[K-1] += 32
	fmt.Fprintln(w, string(S))
}

func main() {
	solve(os.Stdout, os.Stdin)
}

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

using namespace std;

const int N = 100 * 1000 + 17;
const int MOD = 1000 * 1000 * 1000 + 7;

int n;
int a[N];

bool read() {
    if (!(cin >> n))
        return false;

    for (int i = 0; i < n; ++i)
        cin >> a[i];

    return true;
}

void solve() {
    auto S = accumulate(a, a + n, 0);
    auto s = a[0];
    auto ans = S;

    for (int i = 1; i < n; s += a[i++])
        ans = min(ans, abs(S - 2 * s));

    cout << ans << endl;
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    while (read())
        solve();

    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <cstring>
#include <cmath>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int x;
  cin >> x;
  int n = x%100;
  int num = 0;
  num += n/5; n %= 5;
  num += n/4; n %= 4;
  num += n/3; n %= 3;
  num += n/2; n %= 2;
  num += n;
  if (x%100+num*100 <= x)
    cout << 1 << endl;
  else
    cout << 0 << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <string>
#include <algorithm>
#include <set>
#include <map>

using namespace std;

const long long mod = 1000000007;

int main(void){
    int n, a[100005];
    cin >> n;
    for(int i=0; i<n; i++){
        cin >> a[i];
    }
    int i=0, cnt=0;
    while(i<n){
        if(i+1 == a[i]){
            if(i != n-1 && i+2 == a[i+1]){
                i += 2;    
            }else{
                i++;
            }
            cnt++;
        }else{
            i++;
        }
    }
    cout << cnt << endl;
    
    return 0;
}

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

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

using namespace std;

int main() {

    int n,m,sum=0,counter=0;
    cin >> n >> m;

    int A[n];
    rep(i,n) cin >> A[i], sum+=A[i];

    rep(i,n) if(A[i]*4*m<sum) counter+=1;

    if(counter>n-m) cout << "No" << endl;
    else cout << "Yes" << endl;

    return 0;
}

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

int main() {

	int k,n;
	cin>>k>>n;

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

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

	vector<int>dis(n);

	for(int i= 0 ; i< n-1 ; i++){
		dis[i]=h[i+1]-h[i];
	}
	dis[n-1]=(k-h[n-1])+h[0];

	

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

	int min=0;
	for(int i = 0 ; i< n-1 ; i++){
		min += dis[i];
	}
	cout<<min;

	int l ; cin>>l;
	
}

Measured memory_bytes: 1792
import java.io.*;
import java.util.*;
public class Main {
    
    static double dfs(double[][][] dp, int n, int c1, int c2, int c3) {
        if(c1 + c2 + c3 == 0)
            return 0.0;
        if(dp[c1][c2][c3] - 1 > 0.01) {
            return dp[c1][c2][c3];
        }
        
        double expectValueToZero = (n*1.0)/(c1+c2+c3);
        double ret = 0.0;
        if(c1>0)
            ret += (dfs(dp, n, c1 - 1, c2, c3) + expectValueToZero)*c1/(c1+c2+c3);
        if(c2>0)
            ret += (dfs(dp, n, c1 + 1, c2 - 1, c3) + expectValueToZero)*c2/(c1+c2+c3);
        if(c3>0)
            ret += (dfs(dp, n, c1, c2 + 1, c3 - 1) + expectValueToZero)*c3/(c1+c2+c3);
        
        // System.out.println("Returning " + ret + " " + expectValueToZero + " " + c1/(double)(c1+c2+c3));
        return (dp[c1][c2][c3]=ret);
    }
    
    public static void main(String args[]) {
        int n = 0;
        int[] sushiCount = new int[4];
        try (Scanner scanner = new Scanner(System.in)) {
            n = scanner.nextInt();
            
            for(int i = 0; i < n; i++) {
                sushiCount[scanner.nextInt()]++;
            }
        }
        
        double[][][] dp = new double[n+1][n+1][n+1];
        for(double[][] dd : dp)
            for(double[] d : dd)
                Arrays.fill(d, -1);
        
        int oneCount = sushiCount[1];
        int twoCount = sushiCount[2];
        int threeCount = sushiCount[3];
        
        double ret = dfs(dp, n, oneCount, twoCount, threeCount);
        // for(double[][] dd : dp)
        //     for(double[] d : dd)
        //         System.out.println(Arrays.toString(d));
        System.out.println(ret);
    }
}

Measured memory_bytes: 306260
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
// #define pb push_back
// #define vi vector<int>
// #define usi unordered_set<int> 
// #define si set<int>
// #define umii unordered_map<int, int> 
// #define mii map<int, int>
// #define all(a) a.begin(), a.end()
// #define vii vector<pair<int, int>>
// #define pii pair<int, int>
// #define mod (int)(1e9+7)
// #define INF INT_MAX
 
 
int func(int ind, int sum, vector<int> &w, vector<int> &v, vector<vector<int>> &dp) {
    if (ind >= w.size())
        return 0;
    if (dp[ind][sum] != -1)
        return dp[ind][sum];
    if (w[ind] <= sum) {
        int take = v[ind] + func(ind+1, sum-w[ind], w, v, dp);
        int nottake = func(ind+1, sum, w, v, dp);
        return dp[ind][sum] = max(take, nottake);
    }
    else
        return dp[ind][sum] = func(ind+1, sum, w, v, dp);
}

signed main()
{
    
 
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
 
    int n, k; cin >> n >> k;
    vector<int> v(n), w(n);
    vector<vector<int> > dp(n, vector<int> (k+1, -1));
    for (int i=0; i<n; i++) {
        cin >> w[i] >> v[i];
    }
    cout << func(0, k, w, v, dp);
    return 0;
}

Measured memory_bytes: 79488
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

#define ll long long
#define mp make_pair
#define pb push_back

#define eprintf(...) fprintf(stderr, __VA_ARGS__)

const int maxn = 1 << 19;
int mx[maxn << 1], siz;

void init(int n) {
	for (siz = 1; siz < n; siz <<= 1) ;
	memset(mx, 0, sizeof(mx));
}

void upd(int i, int a, int b, int x, int v) {
	if (a + 1 == b) {mx[i] = v; return ;}
	int m = (a + b) >> 1;
	if (x < m) upd(i << 1, a, m, x, v);
	else upd(i << 1 | 1, m, b, x, v);
	mx[i] = max(mx[i << 1], mx[i << 1 | 1]);
}

int qry(int i, int a, int b, int v, vector <int> &vec) {
	if (mx[i] < v) return v;
	if (a + 1 == b) {vec.pb(a); return mx[i];}
	int m = (a + b) >> 1;
	if (v < mx[i << 1]) v = qry(i << 1, a, m, v, vec);
	if (v < mx[i << 1 | 1]) v = qry(i << 1 | 1, m, b, v, vec);
	return v;
}

struct T {
	int val, fix;
	T *ls, *rs;
	T(int v) {val = v; fix = rand(); ls = rs = NULL;}
};

void split(T *x, int v, T *&a, T *&b) {
	if (!x) {a = b = NULL; return ;}
	if (x->val <= v) a = x, split(x->rs, v, a->rs, b);
	else b = x, split(x->ls, v, a, b->ls);
}

T *merge(T *a, T *b) {
	if (!a || !b) return a ? a : b;
	if (a->fix < b->fix) {a->rs = merge(a->rs, b); return a;}
	else {b->ls = merge(a, b->ls); return b;}
}

int mxv(T *x) {while (x && x->rs) x = x->rs; return x ? x->val : 0;}
void prt(T *x) {if (x) prt(x->ls), printf("%d ", x->val), prt(x->rs);}

int n, a[maxn];
T *rt[maxn];

int main() {
//	freopen("in", "r", stdin);
	srand(200);
	scanf("%d", &n);
	for (int i = 0; i < n; ++ i) scanf("%d", &a[i]);
	int m = 0;
	for (int i = 0; i < n; ++ i) {
		if (a[i] < a[i - 1]) m ++;
		rt[m] = merge(rt[m], new T(a[i]));
	}
	int n2 = n + m; init(n2);
	for (int i = 0; i <= m; ++ i) upd(1, 0, n2, i, mxv(rt[i]));
	int nw = n;
	for (int i = 0; i <= n; ++ i) {
		vector <int> vec;
		qry(1, 0, n2, 0, vec);
		++ m;
		int v = 0;
		for (int j = 0; j < vec.size(); ++ j) {
			T *a, *b;
			split(rt[vec[j]], v, a, b);
			rt[vec[j]] = a;
			upd(1, 0, n2, vec[j], mxv(a));
			v = mxv(b);
			rt[m] = merge(rt[m], b);
		}
		while (nw && mxv(rt[m]) == nw) {
			T *d; split(rt[m], nw - 1, rt[m], d); -- nw;
		}
		if (!nw) {printf("%d\n", i); break;}
		upd(1, 0, n2, m, mxv(rt[m]));
//		for (int j = 0; j <= m; ++ j)
//			prt(rt[j]); puts("");
	}
//	printf("%.3f\n", clock() * 1.0 / CLOCKS_PER_SEC);
	return 0;
}


Measured memory_bytes: 16768
N, M = map(int, input().split())
A=[]
count=[1]*1000000
ans=[]
for i in range(M):
    a, b, = map(int, input().split())
    A.append([b, a, i])

A.sort()

for i in range(M):
    number=A[i][1]*1000000+count[int(A[i][1])]
    ans.append([A[i][2],str(number).zfill(12)])
    count[int(A[i][1])] +=1
ans.sort()

for i in range(M):
    print(ans[i][1])



Measured memory_bytes: 48828
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <functional>
using namespace std;

int gcd(int a, int b){
    if(a == 0)return b;
    if(b == 0)return a;
    return gcd(b, a%b);
}

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

    int g1[n];
    g1[0] = as[0];
    for(int i = 1; i < n; i++){
        g1[i] = gcd(g1[i-1], as[i]);
        cerr << g1[i] << " ";
    }
    int g2[n];
    g2[n-1] = as[n-1];
    for(int i = n-2; i >= 0; i--){
        g2[i] = gcd(g2[i+1], as[i]);
        cerr << g2[i] << " ";
    }

    int m = max(g1[n-2], g2[1]);
    cerr << m << endl;
    for(int i = 1; i < n-1; i++){
        int g = gcd(g1[i-1], g2[i+1]);
        m = max(m, g);
        cerr << m << endl;
    }

    cout << m << endl;
    return 0;
}


Measured memory_bytes: 1408
#include <iostream>
#include <string>
#include <string.h>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <stdio.h>
#include <vector>
#include <time.h>
#include <iomanip>
#include <thread>
#include <atomic>
#include <mutex>
#include <future>
#define double long double
#define int long long
#define low lower_bound
#define upp upper_bound
#define mod (int)1e9+7
#define inf (int)1e16
#define rep(i,n) for(int i=0;i<n;i++)
#define all(vec) vec.begin(),vec.end()
#define vsort(vec) sort(all(vec))
#define vrever(vec) reverse(all(vec));
#define vunsort(vec) vsort(vec); vrever(vec);
#define bisea binary_search
#define cend cout<<endl;
#define P pair<int,int>
#define prique priority_queue<P,vector<P>,greater<P>>
using namespace std;
int n;
int a[114514];
signed main() {
	cin >> n;
	int mi = 0;
	rep(i, n) {
		cin >> a[i];
		if (a[i] < 0) {
			mi++;
		}
	}
	if (mi % 2 == 0) {
		int cnt = 0;
		rep(i, n) cnt += abs(a[i]);
		cout << cnt << endl;
	}
	else {
		int mini = inf;
		int cnt = 0;
		rep(i, n) {
			cnt += abs(a[i]);
			mini = min(mini, abs(a[i]));
		}
		cout << cnt - 2 * mini << endl;
	}
}


Measured memory_bytes: 1024
package main

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

func main() {
	sc := NewScanner()

	a := sc.NextInt()
	b := sc.NextInt()

	x := a + b
	y := a - b
	z := a * b

	ans := 0
	if x > y {
		ans = x
	} else {
		ans = y
	}
	if ans < z {
		ans = z
	}
	fmt.Printf("%v\n", ans)
}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			result = append(result, v)
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	result = append(result, v)

	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


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

using namespace std;

#define int long long
const double PI = 3.14159265358979323846;
typedef vector<int> vint;
typedef pair<int, int> pint;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
// cout << fixed << setprecision(20);

// 階乗、階乗逆元テーブル
int fact[1100000], fact_inv[1100000], inv[1100000];

int mod_fact(int n, int m) {
    fact[0] = fact[1] = 1;
    fact_inv[0] = fact_inv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i <= n; i++) {
        fact[i] = fact[i - 1] * i % m;
        inv[i] = m - inv[m % i] * (m / i) % m;
        fact_inv[i] = fact_inv[i - 1] * inv[i] % m;
    }
}

int p;
int a[3300];
int b[3300];

signed main() {
    cin >> p;
    mod_fact(p - 1, p);
    for (int i = 0; i < p; i++) {
        cin >> a[i];
        if (a[i] == 0)continue;
        int cur = 1;
        for (int j = p - 1; j >= 0; j--) {
            (b[j] += p - fact[p - 1] * fact_inv[j] % p * fact_inv[p - j - 1] % p * cur % p) %= p;
            cur = (p - cur * i % p) % p;
        }
        (b[0] += 1) %= p;
    }
    for (int i = 0; i < p; i++)cout << b[i] << " ";
    cout << endl;
}

Measured memory_bytes: 4480
s=input()
dp=[[-1 for _ in range(4)] for _ in range(len(s)+1)]
dp[len(s)][3]=1
for i in range(len(s),-1,-1):
    for j in range(3,-1,-1):
        if j<3:
            dp[len(s)][j]=0
        if i<len(s):
            dp[i][3]=3*dp[i+1][3] if s[i]=='?' else dp[i+1][3]
            dp[i][3]%=1e9+7
        if i<len(s) and j<3:
            m1=3 if s[i]=='?' else 1
            m2=1 if s[i]=='?' or s[i]==list('ABC')[j] else 0
            dp[i][j]=m1*dp[i+1][j]+m2*dp[i+1][j+1]
            dp[i][j]%=1e9+7
print(int(dp[0][0]))

Measured memory_bytes: 24436
/**
 *    author:  tourist
 *    created: 20.11.2019 08:36:55       
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  cout << s[0] << s.size() - 2 << s.back() << '\n';
  return 0;
}


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

#define int long long

#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
typedef pair<pint,int> P1;
typedef pair<int,pint> P2;
static const ll maxLL = (ll)1 << 62;
const ll MOD=1000000007;
const ll INF=1e18;
int dy[]={-1,0,1,0};
int dx[]={0,1,0,-1};

string s;

signed main(){
    cin.tie(0);
	ios::sync_with_stdio(false);
    cin>>s;
	int ans=0;
	rep(i,0,s.size()){
		if(i%2==0){
			if(s[i]=='p')ans--;
		}else{
			if(s[i]=='g')ans++;
		}
	}
	cout<<ans<<endl;
    
    
    
    
    
    
    
    
    
    
    
    return 0;
}

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

int main(){
    int n;cin>>n;
    vector<int>p(n);
    rep(i,n)cin>>p[i];
    int sum=0;
    rep(i,n){
        if(p[i]!=i+1)sum++;
    }
    if(sum==2||sum==0){
        cout<<"YES";
    }else{
        cout<<"NO";
    }

    
}

Measured memory_bytes: 3612
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <queue>
using namespace std;
using ll = long long;
constexpr int mod = 1e9 + 7;

void swap(int &x, int &y)
{
    int tmp = x;
    x = y;
    y = tmp;
}
int main()
{
    int x, y, z;
    cin >> x >> y >> z;
    swap(x, y);
    swap(x, z);
    printf("%d %d %d\n", x, y, z);
    return 0;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;
int main()
{

   string s;

        int i,c=0,a=0,b=0;
     getline(cin,s);



   for(i=0;i<3;i++){
    if(s[i]=='a'){
       a++;
    }
    if(s[i]=='b'){
        b++;
    }
    if(s[i]=='c'){
        c++;
    }
   }
   if(a==1&&b==1&&c==1){
        cout<<"Yes"<<endl;
   }
   else{
        cout<<"No"<<endl;
   }





}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int hw=501;
char grid[hw][hw];
int main(){
	int h,w;
	scanf("%d%d",&h,&w);
	for(int i=1;i<=h;i++)
		for(int j=1;j<=w;j++)cin>>grid[i][j];
	for(int i=1;i<=w;i++)putchar('#');
	putchar('\n');
	for(int i=2;i<h;i++){
		for(int j=1;j<=w;j++)
			if(j&1)putchar('#');
			else putchar(grid[i][j]);
		putchar('\n');
	}for(int i=1;i<=w;i++)putchar('.');
	puts("\n");
	for(int i=1;i<=w;i++)putchar('.');
	putchar('\n');
	for(int i=2;i<h;i++){
		for(int j=1;j<=w;j++)
			if(j&1)putchar(grid[i][j]);
			else putchar('#');
		putchar('\n');
	}for(int i=1;i<=w;i++)putchar('#');
	return putchar('\n'),0;
}

Measured memory_bytes: 3984
N = int(input())
a = list(map(int, input().split()))
dp = [[0]*(2*N) for i in range(N)]
for i in range(N):
    dp[i][i] = a[i]
    dp[i][i+N] = -a[i]

for i in range(1, N+1):
    for x in range(N-i):
        dp[x][x+i] = max(a[x]+dp[x+1][x+i+N], a[x+i]+dp[x][x+i-1+N])
        dp[x][x+i+N] = min(dp[x+1][x+i]-a[x], dp[x][x+i-1]-a[x+i])
ans = dp[0][N-1]
print(ans)

Measured memory_bytes: 209544
#include<iostream>
#include<map>
#include<string>
#include<algorithm>
#include<iso646.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i=0;i<n;i++)
int main(){
ll a,b;
cin>>a>>b;
ll c=b-a;
ll sum=0;
for(ll i=1;i<=c;i++){
sum+=i;
}
cout<<sum-b;
return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cstring>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for(int i=0; i<n; i++)
#define reps(i, s, e) for(int i=s; i<e; i++)
#define repr(i, n) for(int i=n-1; i>=0; i--)
#define reprs(i, s, e) for(int i=e-1; i>=s; i--)

struct UnionFind {
    vector<int> par;

    UnionFind(int n): par(n, -1) {};
    
    void init(int n) { par.assign(n, -1); }

    int root(int x){
        if(par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }

    bool issame(int x, int y){
        return root(x) == root(y);
    }

    bool merge(int x, int y){
        x = root(x);
        y = root(y);

        if(x == y) return false;
        if(par[x] > par[y]) swap(x, y);
        par[x] += par[y];
        par[y] = x;
        return true;
    }

    int size(int x){
        return -par[root(x)];
    }
};

int main(){

    int n, m; cin >> n >> m;

    int p[n];
    rep(i, n){
        cin >> p[i];
        p[i]--;
    }

    int x[m], y[m];
    rep(i, m){
        cin >> x[i] >> y[i];
        x[i]--; y[i]--;
    }

    UnionFind uf(n);
    rep(i, m){
        uf.merge(p[x[i]], p[y[i]]);
    }

    int cnt = 0;
    rep(i, n){
        if(uf.issame(i, p[i])){
            cnt++;
        }
    }

    cout << cnt;

    return 0;
}

Measured memory_bytes: 1792