akhauriyash/Code-Regression huggingface dataset:
import java.io.*
import java.util.*

val pw = PrintWriter(System.out)
fun solve(A: Long, B: Long){
    Math.max(0L, A - 2 * B).let{println(it)}
    pw.flush()
    return
}


fun main(args: Array<String>) {
    fun StringArray(size: Int, init: (Int) -> String = { "\u0000" }): Array<String> {
        return Array<String>(size, init)
    }
    class Scanner(stream: InputStream) {
        private val reader = BufferedInputStream(stream).bufferedReader()
        private var st: StringTokenizer? = null
        fun next(): String {
            while (!(st?.hasMoreTokens() ?: false)) st = StringTokenizer(reader.readLine())
            return st!!.nextToken()
        }
    }
    val sc = Scanner(System.`in`)
    val A = sc.next().toLong()
    val B = sc.next().toLong()
    solve(A, B)
}


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

int main(){
  int N;
  cin >> N;
  int A[N];
  for(int i=0; i<N; i++){
    int k;
    cin >> k;
    A[k-1] = i + 1;
  }
  for(int i=0; i<N; i++){
  cout << A[i];
  if(i < N-1){cout << " ";}
  }
  cout << endl;
  
  return 0;
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int max_n=200005;
int n,k,a[max_n];
int main(){
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;i++)scanf("%d",a+i);
    for(int i=1;i<=n;i++)a[i]+=a[i-1],a[i]%=k;
    ll ans=0;
    map<int,int> mp;
    mp[0]=1;
    int l=0;
    for(int i=1;i<=n;i++){
        if(i-l>=k)mp[(a[l]+k-l%k)%k]--,l++;
        ans+=mp[(a[i]+k-i%k)%k];
        mp[(a[i]+k-i%k)%k]++;
    }
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 10368
#atcoder template
def main():
    import sys
    imput = sys.stdin.readline
    #文字列入力の時は上記はerrorとなる。
    #ここにコード
    #input
    k = int(input())

    #output
    mod = 0
    # %%
    if k % 2 == 0:
        print(-1)
    else:
        for i in range(k):
            mod += 7*pow(10, i, k) % k
            mod %= k
            if mod == 0:
                print(i+1)
                exit()
        print(-1)
        
    #N = 1のときなどcorner caseを確認！
if __name__ == "__main__":
    main()

Measured memory_bytes: 9148
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

void
counting_sort(int *a, int *b, int k_, int n)
{
	int k = k_ + 1;
	int c[k];
	int i;

	memset(c, 0, sizeof(int) * k);

	for (i = 0; i < n; i++)
		c[ a[i] ]++;

	for (i = 1; i < k; i++)
		c[i] = c[i] + c[i - 1];

	for (i = 0; i < n; i++)
		b[ --c[ a[i] ] ] = a[i];
}

int
main(int argc, char **argv)
{
	int i, k, n;
	int *a, *b;

	scanf("%d", &n);

	a = (int *)malloc(sizeof(int) * n);
	if (a == NULL)
		return 1;

	b = (int *)malloc(sizeof(int) * n);
	if (b == NULL)
		return 1;

	k = 0;
	for (i = 0; i < n; i++) {
		scanf("%d", a + i);
		if (k < a[i])
			k = a[i];
	}
	memcpy(b, a, n);

	counting_sort(a, b, k, n);

	for (i = 0; i < n; i++)
		printf("%s%d", i ? " " : "", b[i]);
	printf("\n");

	return 0;
}



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

int main() {
    ll n;
    cin>>n;
    set<string> a;
    for (int i = 0; i < n; ++i) {
        string s;
        cin>>s;
        a.insert(s);
    }
    cout<<a.size()<<endl;
    return 0;
}


Measured memory_bytes: 19120
#include<iostream>
#include<algorithm>
using namespace std;
int a[12];
int main(){
    for(int i=0;i<12;i++)cin>>a[i];
    sort(a,a+12);
    bool ok=true;
    for(int i=0;i<12;i++){
        if(i%4!=3)if(a[i]!=a[i+1])ok=false;
    }
    if(ok)cout<<"yes"<<endl;
    else cout<<"no"<<endl;
    return 0;
}

Measured memory_bytes: 3080
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <numeric>
#include <cstdio>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
using namespace std;
#define MOD 1000000007
#define endl "\n" 
#define rep(i,n) for(int i = 0; i < (n); ++i)
typedef long long ll;


int main(void) {
    cin.tie(0);
    ios::sync_with_stdio(false);
  
    int a[3][3];
    int bingo[3][3] = {0};
    rep(i,3)rep(j,3) cin >> a[i][j];
    int n; cin >> n;
    rep(i,n) {
        int b; cin >> b;
        rep(j,3) {
            rep(k,3) {
                if(b == a[j][k]) {
                    bingo[j][k] = 1;
                } 
            }
        }
    }
    bool flag = false;
    rep(i,3) {
        if(bingo[i][0] == 1 && bingo[i][1] == 1 && bingo[i][2] == 1) flag = true;
        if(bingo[0][i] == 1 && bingo[1][i] == 1 && bingo[2][i] == 1) flag = true;
    }
    if(bingo[0][0] == 1 && bingo[1][1] == 1 && bingo[2][2] == 1) flag = true;
    if(bingo[0][2] == 1 && bingo[1][1] == 1 && bingo[2][0] == 1) flag = true;

    if(flag) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}


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

int main()
{
		int N;
		int max = 0;
		int place;

		cin >> N;

		vector<int> A(N);
		vector<int> b(N);

		for (int i = 0; i < N; i++)
		{
			cin >> A[i];
			
			if (max < A[i])
				{
					max = A[i];
					place = i;
				}
		}
		sort(A.begin(), A.end());

			if (A[N-1] == A[N-2])
			{
				for (int j = 0; j < N; j++)
				{
					cout << max << endl;
				}
			}
			else
			{
				for (int j = 0; j < N; j++)
				{
					if (j == place)
					{
						cout << A[N-2] << endl;
					}
					else
					{
						cout << max << endl;
					}
				}
			}
	
	return 0;
}

Measured memory_bytes: 3200
import sys
n = int(input())
print(0)
sys.stdout.flush()
LS = input()
if LS == 'Vacant':
    exit()
print(n-1)
sys.stdout.flush()
if input() == 'Vacant':
    exit()
L = 0
R = n-1
while L != R-1:
    M = (L+R)//2
    if M & 1:
        M += 1
    if M == R:
        M -= 1
    print(M)
    sys.stdout.flush()
    s = input()
    if s == 'Vacant':
        exit()

    if LS == s:
        L = M
    else:
        R = M


Measured memory_bytes: 3660
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <numeric>
#include <vector>
using namespace std;
#define MAXSIZE 200
#define MAXL 100
#define NUM 1000000007
typedef long long int lli;

int main(){
    int n, m, x;
    cin >> n >> m >> x;
    int charge1 = 0, charge2 = 0;
    for(int i = 0; i < m; i++){
        int a;
        cin >> a;
        if(a < x){
            charge1 += 1;
        }else{
            charge2 += 1;
        }
    }

    int ans = min(charge1, charge2);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import std.stdio, std.string, std.array, std.conv, std.algorithm, std.typecons, std.range, std.container, std.math, std.algorithm.searching, std.functional,std.mathspecial, std.numeric;

long[] scores;
long[][] abcs;
int N;

bool[] updated;

void main(){
    auto nm=readln.split.map!(to!int).array;
    N=nm[0];
    auto M=nm[1];
    foreach(i;0..M){
        auto abc=readln.split.map!(to!long).array;
        abc[0]-=1;
        abc[1]-=1;
        abcs~=abc;
    }

    scores.length=N;
    updated.length=N;
    foreach(ref s;scores[1..$])s=long.min;

    foreach(i;0..N)update();

    foreach(ref u;updated)u=false;

    foreach(i;0..N)update();

    if(updated[N-1]) writeln("inf");
    else writeln(scores[N-1]);
}

void update(){
    foreach(abc;abcs){
        if(scores[cast(uint)abc[0]]==long.min)continue;
        if(updated[cast(uint)abc[0]]){updated[cast(uint)abc[1]]=true;}
        auto res=scores[cast(uint)abc[0]]+abc[2];
        if(scores[cast(uint)abc[1]]<res){
            scores[cast(uint)abc[1]]=res;
            updated[cast(uint)abc[1]]=true;
        }
    }
}


Measured memory_bytes: 636
#define _USE_MATH_DEFINES
#include <cmath>
#include<iostream>
#include<string>
using namespace std;
int main() {
	int N;
	cin >> N;
	if (N < 1000) {
		cout << "ABC" << endl;
	}
	else {
		cout << "ABD" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
class Program
{
    static void Main(string[] args)
    {
        string s = Console.ReadLine();
        if(s[0] != 'A')
        {
            Console.WriteLine("WA");
            return;
        }
        int Cpos = -1;
        int CCount = 0;
        for(int i = 2; i < s.Length - 1; i++)
        {
            if (s[i] == 'C')
            {
                Cpos = i;
                CCount++;
            }
        }
        if(Cpos == -1 || CCount != 1)
        {
            Console.WriteLine("WA");
            return;
        }
        for(int i = 1; i < s.Length; i++)
        {
            if(i != Cpos && s[i] - 'A' <= 26)
            {
                Console.WriteLine("WA");
                return;
            }
        }
        Console.WriteLine("AC");
    }
}


Measured memory_bytes: 11092
#include <iostream>
#include <bits/stdc++.h>
#include <vector>

using namespace std;

int main (){
int a,s,d;
cin >>a >>s;
d=a+s;
if(a*s>d){
d=a*s;
}
if(a-s>d){
d=a-s;
}
cout <<d <<endl;
return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <iterator>
#include <math.h>
#include <cmath>
#include <set>   

using namespace std;

int main() {
	int h, w;
	char a[105][105] = {};

	cin >> h >> w;
	for (int i = 1; i <= h; i++)
	{
		for (int j = 1; j <= w; j++)
		{
			cin >> a[i][j];
		}
	}

	for (int i = 1; i <= h; i++)
	{
		for (int j = 1; j <= w; j++)
		{
			cout << a[i][j];
		}
		cout << endl;
		for (int j = 1; j <= w; j++)
		{
			cout << a[i][j];
		}
		cout << endl;

	}


	
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int a,b,d;
	char op;

	while(1){
			scanf("%d %c %d",&a,&op,&b);
	if ( op == '+' ){
d=a+b;
} else if ( op == '-' ){
d=a-b;
} else if ( op == '*' ){
d=a*b;
} else if ( op == '/' ){
d=a/b;
} else {
break;
}
printf("%d\n",d);
	}
	return 0;
}

Measured memory_bytes: 600
#include<iostream>
using namespace std;
int main()
{
  int r, g, b, ans;
  cin >> r >> g >> b;

  ans = 100*r + 10*g + b;

  if(ans%4==0){
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
  return 0;
}

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

string s;

ll func(int pos, string t, ll sum){
    if(pos == s.length()-1) {        
        return stoll(t+s[pos]) + sum;
    } 
    return func(pos+1, "", sum+stoll(t+s[pos]))  + func(pos+1, t+s[pos], sum);
}

int main() {
    cin >> s;
    cout << func(0, "", 0) << endl;    
}

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

using namespace std;

int main(){
     int n;
     cin >> n;
     map<int,int>m;
     ll sum = 0;
     for(int i = 0;i <n;i++){
          ll x;
          cin >> x;
          sum += x;
          m[x]++;
     }
     int q;
     cin >> q;
     while(q--){
          int val, d;
          cin >> val >> d;
          sum += (d-val)*m[val];
          cout << sum << endl;
          m[d] += m[val];
          m[val] = 0;
     }
}


Measured memory_bytes: 8088
#!/usr/bin/env python3
N = int(input())
A = []
for _ in range(2):
    A.append(list(map(int, input().split())))
ans = [0] * N
for i in range(N):
    ans[i] = sum(A[0][:i + 1]) + sum(A[1][i:])
print(max(ans))


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

lli x;

lli nceil(lli x, lli y){
	return (x+y-1)/y;
}

int main(void){
	cin >> x;
	lli a = nceil(x+5, 11);
	lli b = nceil(x, 11);
	cout << min(2*a-1, 2*b) << endl;
	return 0;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define inf 0x3f3f3f3f
using namespace std;
typedef long long ll;
const int N=4e5+5;
struct node
{
    int k,l,r;
    node(int k=0,int l=0,int r=0):k(k),l(l),r(r){}
};
struct haha
{
    int id,v,k;
    haha(int id=0,int v=0,int k=0):id(id),v(v),k(k){}
    bool operator<(const haha&o)const
    {
        if(v==o.v) return k<o.k;
        return v<o.v;
    }
};
vector<node>vl,vr;
int n,t[N<<2],lz[N<<2],ss[N];
ll ans=0;
ll s[2][N];
void update(int l,int r,int k)
{
    t[k]-=lz[k];
    assert(t[k]>=0);
    if(l!=r)
        lz[k<<1]+=lz[k];lz[k<<1|1]+=lz[k];
    lz[k]=0;
}
int query(int l,int r,int k,int x)
{
    if(lz[k]) update(l,r,k);
    if(r<x) return 1;
    if(l>=x) return t[k];
    int m=l+r>>1;
    int ans=min(query(l,m,k<<1,x),query(m+1,r,k<<1|1,x));
    t[k]=min(t[k<<1],t[k<<1|1]);
    return ans;
}
void fix(int l,int r,int k,int x)
{
    if(lz[k]) update(l,r,k);
    if(r<x) return;
    if(l>=x)
    {
        lz[k]++;
        update(l,r,k);
        return;
    }
    int m=l+r>>1;
    fix(l,m,k<<1,x);fix(m+1,r,k<<1|1,x);
    t[k]=min(t[k<<1],t[k<<1|1]);
}
void build(int l,int r,int k)
{
    t[k]=l;lz[k]=0;
    if(l==r) return;
    int m=l+r>>1;
    build(l,m,k<<1);build(m+1,r,k<<1|1);
}
void solve(vector<node>v,int p)
{
    build(1,n,1);
    for(int i=1;i<=n;i++) ss[i]=i;
    priority_queue<haha>q;
    ll sum=0;
    for(int i=0;i<v.size();i++) sum+=v[i].r,q.push(haha(i,v[i].l-v[i].r,v[i].k));
    s[p][0]=sum;
    for(int i=1;i<=n;i++)
    {
        int l=1,r=n,pos=0;
        while(l<=r)
        {
            int m=l+r>>1;
            if(query(1,n,1,m)==0) pos=m,l=m+1;
            else r=m-1;
        }
        while(!q.empty())
        {
            int id=q.top().id;q.pop();
            if(v[id].k==0) continue;
            if(v[id].k>pos)
            {
                //cout<<pos<<' '<<v[id].l<<' '<<v[id].r<<' '<<v[id].k<<endl;
                sum=sum-v[id].r+v[id].l;
                fix(1,n,1,v[id].k);
                break;
            }
        }
        s[p][i]=max(sum,s[p][i-1]);
    }
}
fstream in,out;
void getts()
{
    int t=50;
    in.open("1.txt");
    in<<t<<endl;
    while(t--)
    {
        int n=1000;
        in<<n<<endl;
        for(int i=1;i<=n;i++)
        {
            int k=rand()%n+1,l=rand()%100+1,r=rand()%100+1;
            in<<k<<' '<<l<<' '<<r<<endl;
        }
    }
    in.close();
}
bool de=false;
int main()
{
    srand(time(0));
    //getts();freopen("1.txt","r",stdin);out.open("out.txt");de=true;
    int t;scanf("%d",&t);
    while(t--)
    {
        scanf("%d",&n);
        vl.clear();vr.clear();ans=0;
        for(int i=1;i<=n;i++)
        {
            int k,l,r;
            scanf("%d%d%d",&k,&l,&r);
            if(l==r) ans+=l;
            else if(l>r) vl.push_back({k,l,r});
            else vr.push_back({n-k,r,l});
        }
        for(int i=0;i<=n;i++) s[0][i]=s[1][i]=0;
        solve(vl,0);
        solve(vr,1);
        ll res=0;
        for(int i=0;i<=n;i++)
            res=max(res,s[0][i]+s[1][n-i]);
        if(!de) printf("%lld\n",ans+res);
        if(de) out<<ans+res<<endl;
    }
}
/*
1
5
4 65 49
4 59 67
3 66 67
4 98 68
3 32 91
*/


Measured memory_bytes: 19640
#include <stdio.h>
 
int main() {
  char c[10][10];
  
  scanf("%s", c[0]);
  scanf("%s", c[1]);
  scanf("%s", c[2]);
  printf("%c%c%c\n", c[0][0], c[1][1], c[2][2]);
  
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <list>
#include <stack>
#include <cctype>
#include <cmath>
#include <set>

using namespace std;

/* typedef */

typedef long long ll;

/* constant */

const int INF = 1 << 30;
const int MAX = 1000000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */

/* function */

/* main */
int main(){

    int n; cin >> n;
    set<int> st;
    for (int i = 0; i < n; i++) {
        int x; cin >> x;
        st.insert(x);
    }
    if (n == st.size()) {
        cout << "YES" << '\n';
    }
    else {
        cout << "NO" << '\n';
    }

    return 0;
}


Measured memory_bytes: 9600
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <string>
#include <set>
#include <queue>
#include <map>
#include <stack>
using namespace std;
int o[10];
bool v[10];
map<int,int> m;
int main()
{
    std::ios::sync_with_stdio(false);
    int n,x;
    while(cin>>o[0])
    {
        memset(v,false,sizeof(v));
        m.clear();
        m[o[0]]=0;
        for(int i=1;i<9;i++)
            cin>>o[i],m[o[i]]=i;
        cin>>n;
        while(n--)
        {
            cin>>x;
            if(m.find(x)!=m.end())
                v[m[x]]=true;
        }
        if((v[0]&&v[1]&&v[2])||(v[3]&&v[4]&&v[5])||(v[6]&&v[7]&&v[8])||(v[0]&&v[3]&&v[6])||(v[1]&&v[4]&&v[7])||(v[2]&&v[5]&&v[8])||(v[0]&&v[4]&&v[8])||(v[2]&&v[4]&&v[6]))
            cout<<"Yes"<<endl;
        else
            cout<<"No"<<endl;
    }
    return 0;
}
/*0 1 2
3 4 5
6 7 8*/


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <deque>
#include <list>
#include <string>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>

using namespace std;

int size = 1000;
char text[1000];

int main() {

	gets(text);

	for (int i = 0; i < size; i++) {
		if (text[i] == EOF) break;
		if (text[i] >= 'a' && text[i] <= 'z') text[i] += 'A' - 'a';
	}

	cout << text << endl;

	return 0;
}

/*@@@@@@@@@@@@@@@@@@@@@@@@@*/
/*@                       @*/
/*@ debug output erased ? @*/
/*@                       @*/
/*@@@@@@@@@@@@@@@@@@@@@@@@@*/

Measured memory_bytes: 1124
import scala.io.Source.stdin

object Main extends App {
  def det(a00:Double,a01:Double,a10:Double,a11:Double) = a00*a11-a01*a10

  for( i <- stdin.getLines ) {
    val a = i.split(" ").map(_.toDouble)
    val detA = det(a(0),a(1),a(3),a(4))
    printf("%.3f %.3f\n",det(a(2),a(1),a(5),a(4))/detA+0.0,det(a(0),a(2),a(3),a(5))/detA+0.0)
  }
}

Measured memory_bytes: 43832
#include <iostream>
#include <vector>
#include <cctype>
#include <queue>
#include <string>
using namespace std;
const int dx[4] = {0,1,-1,0};
const int dy[4] = {-1,0,0,1};;
int bfs(vector<vector<char> > &field,int sx,int sy,int gx,int gy){
  int cost = 0;
  queue<pair<int,int> > que;
  que.push(pair<int,int>(sx,sy));
  vector<vector<int> > keep(1001,vector<int>(1001,0));
  while(!que.empty()){
    pair<int,int> tmp = que.front();que.pop();
    int cx = tmp.first;
    int cy = tmp.second;
    for(int i = 0;i < 4;i++){
      int nx = cx +dx[i];
      int ny = cy +dy[i];
      if(nx >= 0 && nx < field[0].size() && ny >= 0 && ny < field.size() && field[ny][nx] != 'X' && keep[ny][nx] == 0){
	if(nx == gx && ny == gy){
	  return keep[cy][cx]+1;
	}else{
	  keep[ny][nx] = keep[cy][cx]+1;
	  que.push(pair<int,int>(nx,ny));
	}
      }
    }
  }
  return -1;
}
int main(){
  int h,w,n;
  cin >> h >> w >> n;
  vector<vector<char> > field(h,vector<char>(w));
  vector<pair<int,int> > che(n);
  int sx,sy;
  for(int i = 0;i < h;i++){
    string str;
    cin >> str;
    for(int j = 0;j < w;j++){
      field[i][j] = str[j];
      if(isdigit(field[i][j])){
	che[(field[i][j] - '0')-1] = pair<int,int>(i,j);//y,x
      }else if(field[i][j] == 'S'){
	sx = j;sy = i;
      }
    }
  }
  //  cout << "aaaaaa" << endl;
  int ans =0;
  for(int i = 0;i < n;i++){
    if(i == 0){
      ans += bfs(field,sx,sy,che[i].second,che[i].first);
    }else{
      ans += bfs(field,che[i-1].second,che[i-1].first,che[i].second,che[i].first);
    }
  }
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 6020
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"

using namespace std;

using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using i8 = int8_t;
using i16 = int16_t;
using i32 = int32_t;
using i64 = int64_t;

using vi = vector<int>;

constexpr char newl = '\n';
constexpr double eps = 1e-10;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--)
#define RF0(i,b) RFO(i,0,b)
#define fi first
#define se second
#define show(x) cout << #x << " = " << x << '\n';
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define sz(x) (int)(x).size()
#define YesNo {cout<<"Yes";}else{cout<<"No";}
#define YESNO {cout<<"YES";}else{cout<<"NO";}
#define v(T) vector<T>

template<typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
template<class T> bool lcmp(const pair<T, T>& l, const pair<T, T>& r) {
  return l.first < r.first;
}
template<class T> istream& operator>>(istream& i, v(T)& v) {
  F0R(j, sz(v)) i >> v[j];
  return i;
}
template<class A, class B> istream& operator>>(istream& i, pair<A, B>& p) {
  return i >> p.first >> p.second;
}
template<class A, class B, class C> istream& operator>>(istream& i, tuple<A, B, C>& t) {
  return i >> get<0>(t) >> get<1>(t) >> get<2>(t);
}
template<class T> ostream& operator<<(ostream& o, const vector<T>& v) {
  F0R(i, v.size()) {
    o << v[i] << ' ';
  }
  o << newl;
  return o;
}
template<class T1, class T2> ostream& operator<<(ostream& o, const map<T1, T2>& m) {
  for (auto& p : m) {
    o << p.first << ": " << p.second << newl;
  }
  o << newl;
  return o;
}

#if 1


// INSERT ABOVE HERE
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int a, b;
  cin >> a >> b;
  if ((a & 1) && (b & 1)) YesNo;
}
#endif


Measured memory_bytes: 3640
import sys

# D - Wizard in Maze
def get_index(s):
	return int(s) - 1


def search_nearby(h, w):
# 上下左右に隣接するマスを探索
	search(h + 1, w, False)
	search(h - 1, w, False)
	search(h, w + 1, False)
	search(h, w - 1, False)


def search_using_warp(h, w):
  # ワープ魔法で移動できるマスを探索
  for i in range(-2, 3):
    search(h - 2, w + i)
    search(h + 2, w + i)

  for i in range(-2, 3):
    if i != 0:
      search(h - 1, w + i)
      search(h + 1, w + i)

  search(h, w + 2)
  search(h, w - 2)


def search(h, w, is_using_warp = True):
  global is_reached
  global que
  global next_que

  if can_reach(h, w):
	  is_reached[h][w] = True
	  next_que.append([h, w])

	  if not is_using_warp:
	    que.append([h, w])


def can_reach(h, w):
	global H
	global W
	global maze

	if h < 0 or h >= H or w < 0 or w >= W:
		return False
	elif maze[h][w] == '#':
		return False
	elif is_reached[h][w]:
		return False
	else:
		return True


from collections import deque
import copy

H, W = map(int, input().split())
Ch, Cw = map(get_index, input().split())
Dh, Dw = map(get_index, input().split())

maze = []

for _ in range(H):
	maze.append(input())

is_reached = [[False] * W for _ in range(H)]

next_que = deque()
next_que.append([Ch, Cw])
mp = 0

while len(next_que) > 0:
  que = copy.deepcopy(next_que)

	# コストiで到達可能なマスを列挙
  while len(que) > 0:
    h, w = que.popleft()
    is_reached[h][w] = True

    search_nearby(h, w)

  if is_reached[Dh][Dw]:
    print(mp)
    exit()

  que = copy.deepcopy(next_que)
  next_que.clear()
  mp += 1

	# コストiで到達可能なマスを列挙
  while len(que) > 0:
    h, w = que.popleft()
    is_reached[h][w] = True

    search_using_warp(h, w)

  if is_reached[Dh][Dw]:
    print(mp)
    exit()

print(-1)

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

#define ll long long
#define pb push_back
#define vi vector<int>
#define sz(a) (int((a).size()))
#define mp make_pair
#define f first
#define s second
#define pii pair<int, int>

using namespace std;
const int N = 111;
const int inf = (int)2e9;

int n, m;
vi g[N];
int dp[N][N];
int ans;
vector<pair<pii, int> > edges;
bool ok[1010];

void dijkstra(int root) {
	set<pii> st;
	for (int i = 1; i <= n; i++) dp[root][i] = inf;
	dp[root][root] = 0;
	st.insert(mp(0, root));
	
	while (!st.empty()) {
		pii pr = *st.begin();
		st.erase(st.begin());
		int v = pr.s;
		for (int i = 0; i < sz(g[v]); i++) {
			int ind = g[v][i];
			int to = edges[ind].f.f;
			int w = edges[ind].f.s;
			if (dp[root][to] > dp[root][v] + w) {
				st.erase(mp(dp[root][to], to));
				dp[root][to] = dp[root][v] + w;
				st.insert(mp(dp[root][to], to));
			}
		}
	}
}


void f(int x, int y) {
	
	for (int i = 1; i <= n; i++) {
		for (int j = 0; j < sz(g[i]); j++) {
			int v = i;
			int ind = g[i][j];
			int to = edges[ind].f.f;
			int w = edges[ind].f.s;
			int id = edges[ind].s;
			if (dp[x][v] + w + dp[y][to] == dp[x][y]) {
				ok[id] = 1;
			} else if (dp[y][v] + w + dp[x][to] == dp[x][y]) {
				ok[id] = 1;
			}
		}
	}
	
}

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0);
	cin >> n >> m;
	for (int i = 1; i <= m; i++) {
		int x, y, w;
		cin >> x >> y >> w;
		edges.pb(mp(mp(y, w), i));
		g[x].pb(sz(edges) - 1);
		edges.pb(mp(mp(x, w), i));
		g[y].pb(sz(edges) - 1);
	}
	
	for (int i = 1; i <= n; i++) {
		dijkstra(i);
	}
	
	
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			f(i, j);
		}
	}
	
	for (int i = 1; i <= m; i++) {
		ans += !ok[i];
	}
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 384
A = int(input())
B = int(input())
C = int(input())
X = int(input())
result = 0

for a in range(A+1):
    for b in range(B+1):
        for c in range(C+1):
            total = (500 * a)+(100 * b) +(50 * c)
            if total == X:
                result += 1
print(result)


Measured memory_bytes: 3060
#include <iostream>
//#include <stdio.h>
using namespace std;

int main(){
	int n, m;
	int a[1000];
	cin >> n;
	//a = (int *)malloc(4*n);
	
	for (int i = 0;i < n;i++){ 
		cin >> m;
		a[i] = m;
	}
	
	for (int i = n-1;i > 0; i--){
		cout << a[i] << " ";
	}
	cout << a[0];
	cout << endl;
	return 0;
}

Measured memory_bytes: 1164
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))

char s[110][110];
int main(){
	ll h,w;
	scanf("%lld%lld",&h,&w);
	rep(i,0,h)scanf("%s",s[i]);
	rep(i,0,h)rep(ii,0,2){
		rep(j,0,w)putchar(s[i][j]);
		puts("");
	}
}

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

int main(){
    int N;
    cin  >> N;
    int max_L = 0;
    int sum_L = 0;
    for (int i = 0; i < N; i++){
        int L;
        cin >> L;
        max_L = max(max_L, L);
        sum_L += L;
    }
    if (max_L < (sum_L - max_L)){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
l = []
t = []
ans = [False] * 501
while True:
  l = []
  t = []
  ans = [False] * 501
  N = input()
  M = input()
  if N == 0 and M == 0:
    break
  for i in range(M):
    a, b = map(int, raw_input().split())
    l.append([a, b])
    if a == 1:
      t.append(b)
    if b == 1:
      t.append(a)
  for i in t:
    ans[i] = True
    for j in range(M):
      if l[j][0] == i:
        ans[l[j][1]] = True
      if l[j][1] == i:
        ans[l[j][0]] = True
  res = 0
  for i in range(len(ans)):
    if ans[i] and i != 1:
      res += 1

  print res

Measured memory_bytes: 5812
#include <iostream>
#include <queue>
#include <vector>
#include <climits>
#include <algorithm>
using namespace std;

struct P{
  int to, cost;
  P(){};
  P( int t,int c ){ to=t; cost=c; };
 };
struct S{
  int m, cost, v;// 残り時間、経過時間、町
  S(){};
  S(int M,int C, int V){ m=M; cost=C; v=V; };
  bool operator<(const S &s) const {
    return cost > s.cost;
  }
};

int main(){
  int n,m,l,k,a,h, x,y,t;
  int tl[100]; // 冷凍施設のある町
  vector<P> v[100];
  P p;
  priority_queue<S> q;
  S s;
  
  while( cin>>n>>m>>l>>k>>a>>h && (n|m|l|k|a|h) ){
    for( int i=0;i<l;i++ )
      cin >> tl[i];
    tl[l]=a; tl[l+1]=h;
    l+=2;
    sort( tl,tl+l );

    for( int i=0;i<n;i++ ) v[i].clear();
    for( int i=0;i<k;i++ ){
      cin >> x >> y >> t;
      v[x].push_back( P(y,t) );
      v[y].push_back( P(x,t) );
    }
    int d[105][105];
    for( int i=0;i<n;i++ )
      for( int j=0;j<=m;j++ )
	d[i][j] = INT_MAX;

    while( !q.empty() ) q.pop();

    q.push( S(m,0,a) );

    int ans=-1;
    while( !q.empty() ){
      s=q.top(); q.pop();

      if( s.v==h ){
	ans=s.cost; break;
      }

      // vには冷凍施設がある
      bool isExist = binary_search( tl,tl+l,s.v );

      for( unsigned int i=0;i<v[s.v].size();i++ ){
	int to=v[s.v][i].to, cost=v[s.v][i].cost;

	if( isExist ){
	  for( int md=s.m;md<=m;md++ ){
	    int mdc = md-cost;
	    if( mdc<0 ) continue;
	    int nCost = s.cost+cost+md-s.m;
	    if( nCost>=d[to][mdc] )	      continue;
	    d[to][mdc]=nCost;
	    q.push( S(mdc,nCost,to) );

	    if( !isExist ) break;
	  }
	}else{
	  int mdc = s.m-cost;
	  if( mdc<0 ) continue;
	  int nCost = s.cost+cost;
	  if( nCost>=d[to][mdc] ) continue;
	  d[to][mdc]=nCost;
	  q.push( S(mdc,nCost,to) );
	}
      }
    }
    if( ans<0 )
      cout << "Help!" << endl;
    else
      cout << ans << endl;
    /*
    for( int i=0;i<n;i++ ){
      cout << "| ";
      for( int j=0;j<=m;j++ )
	cout <<	d[i][j] << " ";
      cout << endl;
    }
    cout << endl;
    */

  }

  return 0;

}

Measured memory_bytes: 1164
#include <iostream>
#include <stack>
#include <queue>
#include <string>
using namespace std;

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

	int flagN = 0, flagM = 0;;
	int N, M;
	int a[] = { 1,3,5,7,8,10,12 };
	int b[] = { 4,6,9,11 };
	int c[] = { 2 };
	cin >> N >> M;
	if (N >= M) {
		cout << "No\n";
		return 0;
	}
	for (int i = 0; i < 7; i++) {
		if (N == a[i]) {
			flagN = 1;
		}
		if (M == a[i]) {
			flagM = 1;
		}
	}
	if (flagM == 1 && flagN == 1) {
		cout << "Yes\n";
		return 0;
	}
	flagN = 0; flagM = 0;
	for (int i = 0; i < 4; i++) {
		if (N == b[i]) {
			flagN = 1;
		}
		if (M == b[i]) {
			flagM = 1;
		}
	}
	if (flagM == 1 && flagN == 1) {
		cout << "Yes\n";
		return 0;
	}
	else {
		cout << "No\n";
	}

	
	return 0;
}

Measured memory_bytes: 256
package main
import "fmt"

func main(){
  var age int
  var money int
  
  fmt.Scan(&age)
  fmt.Scan(&money)
  
  if age >= 13{
    fmt.Printf("%d", money)
  } else if (6 <= age) && (age <= 12) {
    fmt.Printf("%d", money/2)
  } else if age <= 5 {
    money=0;
    fmt.Printf("%d", money)
  }
}

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

#define int long long
#define mp make_pair

int aa[1005],bb[1005],cc[1005];

vector<int> v;

int32_t main(){
    ios_base::sync_with_stdio(false);cin.tie(0);
    int a,b,c,k,lo,hi,mid,cnt,cnt2;//should have k-1 numbers less than the answer...
    cin>>a>>b>>c>>k;
    for(int x=0;x<a;x++)cin>>aa[x];
    for(int x=0;x<b;x++)cin>>bb[x];
    for(int x=0;x<c;x++)cin>>cc[x];
    for(int x=0;x<a;x++){
      for(int y=0;y<b;y++){
        v.push_back(aa[x]+bb[y]);
      }
    }
    sort(v.begin(),v.end());
    priority_queue<pair<int,pair<int,int> > > pq;
    //the next number, cc[x], next iterator in v...
    for(int x=0;x<c;x++){
      pq.push(mp(cc[x]+v.back(),mp(cc[x],v.size()-1)));
    }
    pair<int,pair<int,int> > pp;
    for(int x=0;x<k;x++){
      cout<<pq.top().first<<'\n';
      pp=pq.top();
      pq.pop();
      if(pp.second.second==0)continue;
      pp.second.second--;
      pp.first=pp.second.first+v[pp.second.second];
      pq.push(pp);
    }
    return 0;
}


Measured memory_bytes: 10476
N,K = map(int,input().split())
P = list(map(int,input().split()))
for i in range(N):
  P[i]-=1
#print(P)
C = list(map(int,input().split()))
Flag = True
for c in C:
  if c >= 0:
    Flag = False
    break
if Flag:
  print(max(C))
  exit()
L = []
for i in range(N):
  visited = set([])
  now = i
  temp = []
  while now not in visited:
    nxt = P[now]
    visited.add(now)
    temp.append(C[nxt])
    now = nxt
  L.append(temp)
#print(L)
ans = 0
S = []
for X in L:
  start = [0]
  for i in range(len(X)):
    temp = start[-1]+X[i]
    start.append(temp)
  S.append(start)
#print(S)
for X,SS in zip(L,S):
  n = len(X)
  cycle_sum = SS[-1]
  if K <= n:
    kouho = max(SS[:K+1])
  elif cycle_sum < 0:
    kouho = max(SS)
  else:
    amari = K%n
    loop = K//n
    first = 0 #余りよりも後で最大
    second = 0 #余りよりも前で最大
    first = (loop-1)*cycle_sum + max(SS)
    second = loop*cycle_sum + max(SS[:amari+1])
    kouho = max(first,second)
  ans = max(ans,kouho)
print(ans)
  
    
  


Measured memory_bytes: 508776
def total(n):
    return 2**(n+2)-3

def left(total,x):
    if x > (total+1)//2:
        return x-(total+1)//2
    else:
        return x
def pati(n):
    return 2**(n+1)-1

n,x = map(int,input().split())
num = []
p = []
for i in range(n-1):
    num.append(total(i))
for i in range(n+1):
    p.append(pati(i))


one = ["B","P","P","P","B"]
num.reverse()
eat = [0 for i in range(n+1)]

ans = 0
for i in range(n-1):
    if x == total(n-i):
        eat[n-i] += 1
        x = 0
    elif x > (total(n-i)+1)//2:
        eat[n-i-1] += 1
        x = left(total(n-i),x)
        ans += 1
    elif x == (total(n-i)+1)//2:
        eat[n-i-1] += 1
        eat[0] += 1
        x = 0
    else:
        x -= 1

for i in range(len(eat)):
    ans += eat[i]*p[i]
if 2<=x<=4:
    ans += x-1
elif x == 5:
    ans += 3
print(ans)

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



int main() {
    ll N; cin >> N;

    ll ans=N-1;

    for(ll i=1;i*i<=N;i++){
        if(N%i==0){
            ll j=N/i;
            ans=min(ans,j+i-2);
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
long monster(long H){
  if(H == 1){
    return 1;
  }
  return 2*monster(H/2)+1;
}
int main(){
  long H, ans;
  scanf("%ld", &H);
  ans = monster(H);
  printf("%ld", ans);
  return 0;
}
  

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define MP(a,b) make_pair(a,b)
int H,W;
string S[3000];
int waO[3000][3000];
int waI[3000][3000];
int main(){
	cin >> H >> W;
	for(int i=0; i<H; i++){
		cin >> S[i];
	}
	for(int i=0; i<H; i++){
		for(int j=0; j<W; j++){
			waO[i][j] = (j!=0?waO[i][j-1]:0);
			if(S[i][j] == 'O') waO[i][j]++;
			//cout << waO[i][j] << " ";
		}
		//cout << endl;
	}
	for(int i=0; i<W; i++){
		for(int j=0; j<H; j++){
			waI[i][j] = (j!=0?waI[i][j-1]:0);
			if(S[j][i] == 'I') waI[i][j]++;
			//cout << waI[i][j] << " ";
		}
		//cout << endl;
	}
	LL ans = 0;
	for(int i=0; i<H; i++){
		for(int j=0; j<W; j++){
			if(S[i][j] == 'J'){
				ans += (waO[i][W-1]-waO[i][j]) * (waI[j][H-1]-waI[j][i]);
			}
		}
	}
	cout << ans << endl;
	
	return 0;
}



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

ll gcd(ll x, ll y);
int fac(ll n, vector<int> num);

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; }

const int INF = 1001001001;

//mint�p�̒萔 (10��9��)
const int mod = 1000000007;

struct mint {
    ll x; // typedef long long ll;
    mint(ll x = 0) :x((x% mod + mod) % mod) {}
    mint operator-() const { return mint(-x); }
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; }
    mint operator+(const mint a) const { return mint(*this) += a; }
    mint operator-(const mint a) const { return mint(*this) -= a; }
    mint operator*(const mint a) const { return mint(*this) *= a; }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod - 2); }
    mint& operator/=(const mint a) { return *this *= a.inv(); }
    mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream & is, const mint & a) { return is >> a.x; }
ostream& operator<<(ostream & os, const mint & a) { return os << a.x; }

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> h(n);
    rep(i, n) cin >> h[i];

    vector<int> dp(n, INF);
    dp[0] = 0;
    for (int i = 1; i < n; i++) {
        for (int j = 1; j <= k; j++) {
            if (!(i - j >= 0)) continue;
            chmin(dp[i], dp[i - j] + abs(h[i] - h[i - j]));
        }
    }

    cout << dp[n - 1] << endl;
    return 0;
}

/*���C�u�����ő����*/
//���[�O���b�h�̌ݏ��@
ll gcd(ll x, ll y) {
    ll num[3];
    num[0] = (x > y) ? x : y;
    num[1] = (x <= y) ? x : y;
    num[2] = num[0] % num[1];

    while (num[2]) {
        num[0] = num[1];
        num[1] = num[2];
        num[2] = num[0] % num[1];
    }

    return num[1];
}

/*�f��������*/
//���색�C�u����
int fac(ll n, vector<int> num) {
    ll kazu = n;
    for (int i = 2; i <= sqrt(n); i++) {
        while (1) {
            if (kazu % i != 0) break;

            kazu /= i;
            num[i]++;
        }
    }
    if (kazu == n && n != 1) return 1;
    int ans = 0;
    if (kazu != 1) ans++;
    for (int i = 2; i <= sqrt(n); i++) {
        for (int j = 1; j <= num[i]; j++) {
            num[i] -= j;
            ans++;
        }
    }
    return ans;
}

Measured memory_bytes: 4020
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vs = vector<string>;
using vll = vector<long long>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
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 (b<a) {a=b; return 1;} return 0;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    cin >> n;
    vi a(n);
    rep(i, n) cin >> a[i];
    vi cnt(3);
    rep(i, n) {
        if (a[i] % 4 == 0) cnt[2]++;
        else if (a[i] % 2 == 0) cnt[1]++;
        else cnt[0]++;
    }
    if (n % 2 == 1 && cnt[2] == n/2 && cnt[0] == (n+1)/2) cout << "Yes" << endl;
    else if (cnt[2] < cnt[0]) cout << "No" << endl;
    else cout << "Yes" << endl;

}

Measured memory_bytes: 768
import java.util.*

val sc=Scanner(System.`in`)
fun main(args: Array<String>) {
    val num = sc.nextInt()
    val h = mutableListOf<Int>()
    for (i in 0 until num) {
        h.add(sc.nextInt())
    }
    println(h.sum() - h.max()!!/2)
}






Measured memory_bytes: 37228
#include<iostream>
#include<string>
#include<cstring>
#include<cstdio>
#include<cmath>
#include <utility>
#include<cstdlib>
#include<vector>
#include<set>
#include<map>
#include<list>
#include<queue>
#include<functional>
#include<algorithm>
#define ms0(a) memset(a,0,sizeof(a))
#define ms1(a) memset(a,-1,sizeof(a))
#define pb(a) push_back(a)
using namespace std;
typedef long long  ll;
//typedef __int64  ll;
const double Eps = (double)0.5;
const int M = 1e9 + 7;
const int N = 2e5+ 5 ;
const double PI = acos(-1.0);

int a[N];
int pos[N];

int STEP;
int c[N];

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

void update(int i, int x)
{
    while(i <= STEP)
    {
        c[i] += x;
        i += lowbit(i);
    }
}

int getsum( int x )
{
    int sum = 0;
    while( x > 0 )
    {
        sum += c[x];
        x -= lowbit(x);
    }
    return sum;
}

int getl( int step )
{
    int l = 0, r = step - 1, mid;
    int sm = getsum(step);
    while(l <= r)
    {
        mid = (l + r)/2;
        if( sm - getsum(mid) == 1)
            r = mid - 1;
        else
            l = mid + 1;
    }
    return l + 1;
}

int getr( int step )
{
    int l = step, r = STEP, mid;
    int sm = getsum(step);
    while(l <= r)
    {
        mid = (l + r)/2;
        if(getsum(mid) - sm == 0)
            l = mid + 1;
        else
            r = mid - 1;
    }
    return l - 1;
}



int main()
{
    int n;
    cin>>n;
    for(int i=1; i<=n; i++)
    {
        scanf("%d",&a[i]);
        pos[a[i]] = i;
    }
    STEP = n;
    ll asr = 0;
    for(int i=1; i<=n; i++)
    {
        update(pos[i], 1);
        int l = getl(pos[i]);
        int r = getr(pos[i]);
        asr += (ll)(pos[i] - l) * (r - pos[i]) * i;
        asr +=  (ll)(pos[i] - l + 1 + r - pos[i]) * i;
    }
   // printf("%I64d\n",asr);
    cout<<asr<<endl;
    return 0;
}


Measured memory_bytes: 2560
#include<bits/stdc++.h>
#include<climits>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int              long long
#define umapii           unordered_map<int,int>
#define pqmaxi           priority_queue<int>
#define pqmini           priority_queue<int,vector<int>,greater<int>>
#define arr(type,a,n)    type* a = new type[n];
#define ff               first
#define ss               second
#define pb               push_back
#define w(t)             int t;cin>>t;while(t--)
#define popb             pop_back
#define mod              pow(10,9)+7;
#define mapii            map<int,int>
#define mp               make_pair
#define vint             vector<int>
#define presesion        fixed<<presesion(y)<<x
typedef tree<pair<int, int>, null_type, less<pair<int, int>>, rb_tree_tag, tree_order_statistics_node_update>pbds;
int32_t main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output2.txt", "w", stdout);
#endif

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

}

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

using namespace std;

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

int n;
ll x, ans;
vector<pll> vec;

pll f(int l, int r) {
    if (vec[l].second>=x) return pll(vec[r].second-x,vec[r].second);
    if (vec[r].second<=x) return pll(x-vec[l].second,vec[l].second);
    if (vec[l].first<vec[r].first) {
        vec[r].first += vec[l].first;
        pll tmp = f(l+1,r);
        return pll(tmp.first+abs(tmp.second-vec[l].second),vec[l].second);
    }
    vec[l].first += vec[r].first;
    pll tmp = f(l,r-1);
    return pll(tmp.first+abs(tmp.second-vec[r].second),vec[r].second);
}

int main() {
    int i;

    scanf("%d%lld",&n,&x);
    for (i=0;i<n;i++){
        ll a, b;
        scanf("%lld%lld",&a,&b);
        vec.push_back(pll(b,a));
    }
    printf("%lld\n",f(0,(int)vec.size()-1).first);

    return 0;
}


Measured memory_bytes: 4464
//omajinai c++
#include <iostream>
#include<cmath>
#include<vector>
#include <algorithm>
#include <limits>
#include <numeric>
#include <type_traits>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
constexpr auto mod = 1000000007;

using namespace std;
 


int main() {

int h,a;
  cin>>h>>a;
  if(h%a==0){
    cout<<h/a;}
  else{
    cout<<h/a+1;}
}

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

#define all(v) v.begin(), v.end()
#define V vector
#define P pair
typedef long long ll;
const int INT_INF = 1e9;
const ll INF = 1LL << 30;

int main() {
    int n; cin >> n;
    V<int> l(n);
    for(int i = 0; i < n; i++) cin >> l[i];
    sort(all(l));

    int ans = 0;
    for(int i = 0; i < n; i++){
        for(int j = i + 1; j < n; j++){
            int a = l[i];
            int b = l[j];
            auto ite = lower_bound(all(l), a + b);
            int c = ite - (l.begin() + j + 1);
            ans += c;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) c.begin(), c.end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int main() {
    int n, a[9] = {};
    cin >> n;
    REP(i,n){
        int x;
        cin >> x;
        a[min(x/400, 8)]++;
    }
    int p = 0;
    REP(i,8){
        if(a[i] > 0) p++;
    }
    cout << max(p,1) << " " << p + a[8] << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map.Entry;
import java.util.PriorityQueue;
import java.util.Scanner;

class Main {
    static final int MOD = 1000000007;
    static final int INF = 1 << 30;
    static final int ALF = 26;

    Main() {
        Scanner sc = new Scanner(System.in);
        long ans = 0;
        int K = sc.nextInt();
        boolean[] map = new boolean[K + 1];
        int initial = 7;
        if (7 % K == 0) {
            System.out.println(1);
            return;
        }
        for (int i = 2; true; i++) {
            initial = initial*10+7;
            // initial %= K;
            // initial += 7;
            if (initial%K == 0) {
                System.out.println(i);
                return;
            }
            initial %= K;
            if (map[initial])
                break;
            map[initial] = true;
        }
        System.out.println("-1");
    }

    public static void main(String[] args) {
        new Main();
    }
}


Measured memory_bytes: 36588
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

internal static class CR
{
    public static string Get() { return Console.ReadLine(); }
    public static IEnumerable<string> GetTexts() { return Console.ReadLine().Split(' '); }
    public static int GetInteger() { return int.Parse(Console.ReadLine()); }
    public static IEnumerable<int> GetIntegers() { return Console.ReadLine().Split(' ').Select(x => int.Parse(x)); }
}

namespace AtCoder.A
{
    public class Program
    {
        public static int N { get; private set; }
        public static int R { get; private set; }

        public static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.Write(r); }

        private static object GetResult()
        {
            var inputs = CR.GetIntegers().ToList();
            N = inputs[0];
            R = inputs[1];

            return N >= 10 ? R : (R + 100 * (10 - N));
        }
    }
}


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

#define debug(x) cout <<"DEBUG"<<" "<< #x << ":" << x << '\n'

// n回繰り返し
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順
#define rep1(i,n) for(int i = 1; i <= ((int)(n)); i++) // 1-indexed昇順
#define rrep(i,n) for(int i = ((int)(n)-1); i >= 0; i--)  // 0-indexed降順
#define rrep1(i,n) for(int i = ((int)(n)); i >= 1; i--)   // 1-indexed降順
#define all(x) (x).begin(),(x).end()

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vii;  // 2次元配列
typedef vector<ll> vll;
typedef pair<int, int> PII;

template<typename T>
using vec = vector<T>;
template<class T>
using maxheap = std::priority_queue<T>;
template<class T>
using minheap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template<class T,class U> inline bool chmax(T &a, const U &b){if(a<b){a=b;return 1;}return 0;}
template<class T,class U> inline bool chmin(T &a, const U &b){if(a>b){a=b;return 1;}return 0;}

const ld Pi = std::acos(-1.0L);
const ll infll = (1LL<<62)-1;
const int inf = (1<<30)-1;
const int mod = 1000000007;
// const int mod = 998244353;


/*FUNCs=================================================*/


/*MAIN==================================================*/
signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化
    // cout << fixed << setprecision(30);

    int n,p; cin >>n;
    set<int> a;
    rep(i,n) {
        cin >> p;
        if(a.find(p) != a.end()) {
            cout << "NO" << '\n';
            return 0;
        }else {
            a.insert(p);
        }
    }
    cout << "YES" << '\n';
}

Measured memory_bytes: 9600
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N, M, s = 0;
  cin >> N >> M;
  vector<int> A(M);
  for(int i = 0; i < M; i++){
    cin >> A.at(i);
    s += A.at(i);
  }
  if(s > N) cout << "-1" << endl;
  else cout << N - s << endl;
}

Measured memory_bytes: 3668
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>

using namespace std;

int main(){
	int H, W;
	cin >> H >> W;
	int dx[] = { -1,-1,-1,0,0,1,1,1 };
	int dy[] = { -1,0,1,-1,1,-1,0,1 };
	vector<string> a(H);
	int score[60][60] = { };
	for (int i = 0; i < H; i++) cin >> a[i];

	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			if (a[i][j] == '#') {
				for (int k = 0; k < 8; k++) {
					score[i + 1 + 1 * dx[k]][j + 1 + 1 * dy[k]]++;
				}
			}
		}
	}

	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			if (a[i][j] == '#') {
				cout << "#" ;
			}else {
				cout<<score[i + 1][j + 1];
			}
		}
		cout << "\n";
	}
	return 0;
}

Measured memory_bytes: 256