akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define pqueue priority_queue
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  string S, T;
  cin>>S>>T;
  vector<int> arr[26];
  for(int i=0;i<S.size();++i) {
    arr[S[i]-'a'].push_back(i);
  }
  int index = -1;
  int index1;
  bool can = true;
  ll ans = 0;
  for(int i=0;i<T.size();++i) {
    index1 = upper_bound(arr[T[i]-'a'].begin(), arr[T[i]-'a'].end(), index) - arr[T[i]-'a'].begin();
    if(index1==arr[T[i]-'a'].size()) {
      if(arr[T[i]-'a'].size()==0) can = false;
      else {
        index1 = arr[T[i]-'a'][index1];
        ans += S.size()-index-1;
        index = arr[T[i]-'a'][0];
        ans += index+1;
      }
    }
    else {
      index1 = arr[T[i]-'a'][index1];
      ans += index1-index;
      index = index1;
    }
  }
  if(can) cout<<ans<<endl;
  else cout<<-1<<endl;
}



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

// g++ -std=c++17 -Wshadow -Wall -g -fsanitize=address -fsanitize=undefined -D_GLIBCXX_DEBUG -o 

int main(){
 int n;
 cin>>n;
 int doublet[n]={0};
 int f=0;
 for(int i=0;i<n;i++){
  int d1,d2;
  cin>>d1>>d2;
  if(i>0){
   if(d1==d2)doublet[i]=doublet[i-1]+1;
   if(doublet[i]==3)f=1;
  }
  else{
   if(d1==d2)doublet[i]=1;
  }
 }
 if(f)cout<<"Yes\n";
 else cout<<"No\n";
 return 0;
}


Measured memory_bytes: 3584
#include<stdio.h>
#include<string.h>
int main()
{
	char s[500005];
	scanf("%s", s);
	int i, l, r, n = strlen(s);
	l = 200005;
	for (i = 0; i < n; i++)
		s[l + i] = s[i];
	r = n + l;
	l--;
	int q;
	scanf("%d", &q);
	int t, f;
	char c;
	int p = 0;
	for (i = 0; i < q; i++)
	{
		scanf("%d", &t);
		if (t == 1)
			p ^= 1;
		else
		{
			scanf("%d %c", &f, &c);
			if (f == 1)
			{
				if (p == 0)
				{
					s[l] = c;
					l--;
				}
				else
				{
					s[r] = c;
					r++;
				}
			}
			else
			{
				if (p == 0)
				{
					s[r] = c;
					r++;
				}
				else
				{
					s[l] = c;
					l--;
				}
			}
		}
	}
	if (p == 0)
	{
		for (i = l + 1; i < r; i++)
			printf("%c", s[i]);
	}
	else
	{
		for (i = r - 1; i > l; i--)
			printf("%c", s[i]);
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 768
#-*- coding: utf-8 -*-
"""
oj dl https://atcoder.jp/contests/abc116/tasks/abc116_b -d test-b
oj test -d test-c -c "python abc116c.py"
oj test -d test-b -c "python abc116b.py" test-b/sample-3.in
"""

from collections import defaultdict
import sys
import math
import time
import itertools

#累積和
def deco(func):
    def wrapper(*args, **kwargs):
        s = time.time()
        #print('--start--')
        ret = func(*args, **kwargs)
        logging.debug('--end in %f --' % (time.time() - s) )
        return ret
    return wrapper


@deco
def sol(N, Q, S, LR):
    M = [0] * N
    logging.debug("%s, %s, %s, %s, %s" % (N, Q, S, LR, M))
    for i in range(1, N):
        logging.debug("i:%s" % i)
        if S[i-1] + S[i] == "AC":
            M[i] = M[i-1] + 1
        else:
            M[i] = M[i-1]

    A = [0]*Q
    for j in range(Q):
        l, r = int(LR[j][0])-1, int(LR[j][1])-1
        A[j] = M[r] - M[l]

    return A





import logging

do_submit = False
do_submit = True

if do_submit:
    logging.basicConfig(level=logging.ERROR, format="%(message)s")
else:
    logging.basicConfig(level=logging.DEBUG, format="%(message)s")
def input_parse(input_str):
    lines = [x.strip() for x in input_str.split("\n") if x.strip()]
    parsed_lines = [list(line.split()) for line in lines]
    (N, Q) = parsed_lines[0]
    N = int(N)
    Q = int(Q)
    S = parsed_lines[1][0]
    # return (n, S)
    LR = []
    for i in range(2, 2+Q):
        l , r = int(parsed_lines[i][0]), int(parsed_lines[i][1])
        LR.append((l, r))
    return (N, Q, S, LR)



if not do_submit:
    # n, S= input_parse("""
    # 4
    # 1 2 2 1
    # """)
    (N, Q, S, LR) = input_parse("""
    8 3
    ACACTACG
    3 7
    2 3
    1 8
    """)
    for a in sol(N, Q, S, LR):
        print (a)

    (N, Q, S, LR) = input_parse("""
    20 6
    AGCTAATTTACACGTAATCC
    3 7
    2 3
    1 8
    1 20
    9 18
    14 18
    """)
    for a in sol(N, Q, S, LR):
        print (a)

else:
    str = ""
    NQ = input().strip()
    N, Q= list(map(int, NQ.split()))
    str += NQ + "\n"
    str += input().strip() + "\n"# S
    for i in range(Q):
        str += input().strip() + "\n" # l, r
    (N, Q, S, LR) = input_parse(str)
    #print(sol(N, Q, S, LR))
    for a in sol(N, Q, S, LR):
        print (a)







Measured memory_bytes: 49360
#! /usr/bin/env python3

# from math import gcd
import math
from fractions import gcd
from collections import Counter, deque, defaultdict
from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge
from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort
from itertools import accumulate, product, permutations, combinations, combinations_with_replacement

A, B, H, M = [int(_) for _ in input().split()]

l =  (0.5 * (H * 60 + M) ) % 360 # 1min kakudo
s =  360 / 60 * M

sita = abs(max(s, l) - min(s, l))
c = math.sqrt(A**2 + B**2 - 2*A*B*math.cos(math.radians(sita)))
print(c)


Measured memory_bytes: 10792
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#include<cassert>
#include<numeric>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
const int INF = 1001001001;
const long long LINF = 1001002003004005006ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int,int> P;

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 {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=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 {
    mint res(*this);
    return res/=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;
  cin >> n;
  int a[n];
  rep(i,n)cin >> a[i];

  mint s[n+1];
  s[0]=0;
  rep(i,n)s[i+1]=s[i]+a[i];
  
  mint ans = 0;
  rep(i,n){
    ans += (s[n]-s[i+1])*a[i];
  }
  cout << ans << endl;
}

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

int main(){
  int n,q,si,ti,l,r,m,c=0;
  int S[100005],T[50005];
  
  cin >> n;
  for (si=0;si<n;si++)cin >> S[si];

  cin >> q;
  for (ti=0;ti<q;ti++)cin >> T[ti];

  for (ti=0;ti<q;ti++){
    l=0;
    r=n;
    while (l<r){
      m=(l+r)/2;
      if (S[m]>T[ti])r=m;
      else if (S[m]<T[ti])l=m+1;
      else {
	c++;
	break;
      }
    }
  }

  cout << c << endl;
  
  return 0;
}

Measured memory_bytes: 3680
/*
 * main.c
 *
 *  Created on: 2020/03/28
 *      Author: family
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define MAX(a,b) (a > b ? a : b)
#define MIN(a,b) (a > b ? b : a)
typedef long long int ll;
typedef unsigned long long int ull;

int sort_inc(const void *a, const void *b) { return (*(int*)a - *(int*)b);}
int sort_dec(const void* a, const void* b) { return (*(int*)b - *(int*)a);}
int sort_dec_ll(const void *a, const void *b) {
    ll da = *(ll*)a, db = *(ll*)b;    int val = 0;
    if(da > db) { val = -1; }
    else if (da == db) { val = 0; }
    else { val = 1; }
    return val;
}
int sort_inc_ll(const void *a, const void *b) {
    ll da = *(ll*)a, db = *(ll*)b;    int val = 0;
    if(da > db) { val = 1; }
    else if (da == db) { val = 0; }
    else { val = -1; }
    return val;
}
int sort_dic(const void *a, const void *b) {
    char *pa = (char *)a;    char *pb = (char *)b;    int i = 0, val = 0, N = 10;
    for (i = 0; i < N; i++) {
    	char da = pa[i], db = pb[i];
    	if (da == db) continue;
  		if (da > db) val = 1; else val = -1;
        break;
    }
    return val;
}

void yesno(int ans) {
	if (ans == 1) {
		printf("Yes\n");
	} else {
		printf("No\n");
	}
	return;
}

int main()
{
	int K = 0, ans = 0;
	int A = 0, B = 0;
	scanf("%d", &K);
	scanf("%d %d", &A, &B);
    ans = B/K;
    ans = ans * K;
    if (ans >= A) {
    	printf("OK\n");
    } else {
    	printf("NG\n");
    }
	return 0;
}


Measured memory_bytes: 1660
n,k = map(int,input().split())
r,s,p = map(int,input().split())
t = input()

ans = 0
memo = []
for i in range(n):
    if i < k or t[i] != memo[i-k]:
        memo.append(t[i])
        if t[i] == 'r': ans += p
        elif t[i] == 's': ans += r
        else: ans += s

    else:
        memo.append('-1')

print(ans)


Measured memory_bytes: 9996
#include <cstdio>
#include <iostream>
#include <queue>
#include <set>
#include <map>

using namespace std;

#define foreach(i,c) for(__typeof__((c).begin()) i=(c).begin();i!=(c).end();++i)

void fill(vector<vector<int> >& grid,int i,int j)
{
	int h=grid.size(),w=grid[0].size();
	queue<pair<int,int> > q;
	q.push(make_pair(i,j));
	while(q.size()){
		int ci=q.front().first,cj=q.front().second; q.pop();
		if(ci<0 || h<=ci || cj<0 || w<=cj || grid[ci][cj])
			continue;
		grid[ci][cj]=-1;
		int di[]={-1,1,0,0},dj[]={0,0,-1,1};
		for(int k=0;k<4;k++)
			q.push(make_pair(ci+di[k],cj+dj[k]));
	}
}

int main()
{
	for(int w,h;scanf("%d%d",&w,&h),w|h;){
		int n; scanf("%d",&n);
		vector<int> x1(n),y1(n),x2(n),y2(n);
		for(int i=0;i<n;i++)
			scanf("%d%d%d%d",&x1[i],&y1[i],&x2[i],&y2[i]);
		
		map<int,int> xtoi,ytoi;
		{
			set<int> xs,ys;
			xs.insert(0); xs.insert(w);
			xs.insert(x1.begin(),x1.end());
			xs.insert(x2.begin(),x2.end());
			ys.insert(0); ys.insert(h);
			ys.insert(y1.begin(),y1.end());
			ys.insert(y2.begin(),y2.end());
			
			set<int>::iterator i;
			int j;
			for(i=xs.begin(),j=0;i!=xs.end();++i)
				xtoi[*i]=j++;
			for(i=ys.begin(),j=0;i!=ys.end();++i)
				ytoi[*i]=j++;
		}
		
		vector<vector<int> > grid(ytoi.size(),vector<int>(xtoi.size()));
		for(int k=0;k<n;k++){
			int i1=ytoi[y1[k]],j1=xtoi[x1[k]],i2=ytoi[y2[k]],j2=xtoi[x2[k]];
			grid[i1][j1]++;
			grid[i1][j2]--;
			grid[i2][j1]--;
			grid[i2][j2]++;
		}
		for(int i=0;i<grid.size();i++)
			for(int j=1;j<grid[i].size();j++)
				grid[i][j]+=grid[i][j-1];
		for(int i=1;i<grid.size();i++)
			for(int j=0;j<grid[i].size();j++)
				grid[i][j]+=grid[i-1][j];
		grid.pop_back();
		for(int i=0;i<grid.size();i++)
			grid[i].pop_back();
		
		int res=0;
		for(int i=0;i<grid.size();i++)
			for(int j=0;j<grid[i].size();j++)
				if(grid[i][j]==0){
					fill(grid,i,j);
					res++;
				}
		printf("%d\n",res);
	}
	
	return 0;
}

Measured memory_bytes: 0
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;


class Program
{
    static void Main(string[] args)
    {
        // 入力
        //var s = Console.ReadLine();
        //var n = int.Parse(Console.ReadLine());
        int[] nm = Console.ReadLine().Split().Select(int.Parse).ToArray();
        var n = nm[0];
        var m = nm[1];

        int[][] sw = new int[m][];
        for (int i = 0; i < m; i++)
        {
            sw[i] = Console.ReadLine().Split().Select(int.Parse).ToArray();
        }

        int[] p = Console.ReadLine().Split().Select(int.Parse).ToArray();

        var ans = 0;
        // bit全探索
        for (int i = 0; i < Math.Pow(2, n); i++)
        {
            var katei = new bool[n];
            for (int j = 0; j < n; j++)
            {
                var x = (i >> j) & 1;
                if (x == 1) katei[j] = true;
            }

            var flag = true;
            for (int j = 0; j < m; j++)
            {
                var on = 0;
                for (int k = 1; k < sw[j].Length; k++)
                {
                    if (katei[sw[j][k] - 1]) on++;
                }

                if (on % 2 != p[j])
                {
                    flag = false;
                    break;
                }
            }

            if (flag) ans++;
        }


        // 出力
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 28680
#!/usr/bin/env python3
import sys
import string

def solve(N: int):
    alphabet = string.ascii_lowercase
    digits = []
    nextDigits = []
    last = 0
    for i in range(1000):
        nd = 26**i + last
        last = nd
        if nd <= N:
            digits.append(nd)
            nextDigits.append(26**i)
        else:
            break
    # print(digits)
    s = ""
    # print(digits)
    for i in range(len(digits)-1,-1,-1):
        isFirstDigit = i == len(digits)-1
        if isFirstDigit:
            currentBaseNum = digits[i]
            index = (N-currentBaseNum)//nextDigits[i]
            s += alphabet[index]
            N = N - currentBaseNum - index * nextDigits[i]
        else:
            index = N //nextDigits[i]
            s+= alphabet[index]
            N = N - index * nextDigits[i]
    return s

# print(solve(26))
# s = ""
# for i in range(100000):
#     s += " " +solve(i)
# print(s)
# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    print(solve(N))

if __name__ == '__main__':
    main()


Measured memory_bytes: 9956
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#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 pi acos(-1.0)
 
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;
	while (cin >> n && n){
		vector<string> s(n);
		REP(i,n) cin >> s[i];
		FOR(i,1,n-1){
			int x = 0;
			while (s[i][x] == '.'){
				s[i][x] = ' ';
				x++;
			}
			s[i][x-1] = '+';
		}
		REP(i,n) REP(j,s[i].length()){
			if (s[i][j] == '+'){
				int x = i-1;
				while (s[x][j] == ' '){
					s[x][j] = '|';
					x--;
				}
			}
		}
		REP(i,n) cout << s[i] << endl;
	}
    return 0;
}

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

int n, k;
vector<pair<long long int, long long int>> sushi;
priority_queue<pair<long long int, long long int>, vector<pair<long long int, long long int>>, greater<pair<long long int, long long int>>> eaten_sushi;

int used[100001];

long long int oishi = 0;
long long int res = 0;

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

    for (int i = 0; i < n; i++)
    {
        int t, d;
        cin >> t >> d;
        t--;
        sushi.push_back(make_pair(d, t));
    }

    sort(sushi.begin(), sushi.end(), greater<pair<int, int>>());

    for (int i = 0; i < k; i++)
    {
        eaten_sushi.push(sushi[i]);
        oishi += sushi[i].first;
        used[sushi[i].second]++;
    }

    //ネタの種類数
    long long int x = 0;
    for (int i = 0; i < n; i++)
    {
        if (used[i] != 0)
        {
            x++;
        }
    }

    res = oishi + x * x;

    int now = k;

    while (eaten_sushi.size() != 0 && now < sushi.size())
    {
        pair<long long int, long long int> s = eaten_sushi.top();
        eaten_sushi.pop();
        if (used[s.second] > 1)
        {
            while (now < sushi.size())
            {
                pair<long long int, long long int> s2 = sushi[now];
                if (used[s2.second] == 0)
                {
                    eaten_sushi.push(s2);
                    used[s.second]--;
                    used[s2.second]++;
                    x++;
                    oishi -= s.first;
                    oishi += s2.first;
                    res = max(res, oishi + x * x);
                    now++;
                    break;
                }
                now++;
            }
        }
    }

    cout << res;

    return 0;
}


Measured memory_bytes: 5232
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;

int main(){
    int n;
    cin >> n;
    int h[n];
    for(int i=0;i<n;i++){
        cin >> h[i];
    }
    int ans=1,max=h[0];
    
    for(int i=1;i<n;i++){
        if(h[i]>=max){
            ans++;
            max=h[i];
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define endl '\n'
#define FASTINOUT ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const int N=3009;
ll a[N][N];
ll dp[N][N][5];
int r,c,k,l,m,v;
ll f(int i,int j,int cnt)
{
    if (i>r||j>c)
        return 0;
    if (dp[i][j][cnt]!=-1)
        return dp[i][j][cnt];
    ll mx=0;
    if (cnt<3)
    {
        mx=max(mx,a[i][j]+f(i,j+1,cnt+1));
        mx=max(mx,a[i][j]+f(i+1,j,0));
    }
    mx=max(mx,f(i,j+1,cnt));
    mx=max(mx,f(i+1,j,0));
    return dp[i][j][cnt]=mx;
}
int main()
{
    FASTINOUT;
    cin>>r>>c>>k;
    for (int i=1; i<=k; i++)
    {
        cin>>l>>m>>v;
        a[l][m]=v;
    }
    memset(dp,-1,sizeof dp);
    cout<<f(1,1,0);
    return 0;
}


Measured memory_bytes: 428208
#include <bits/stdc++.h>
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define pll pair<ll,ll>
#define all(v) v.begin(),v.end()
#define mod 1000000007
#define mx 1000002
mt19937 myrand(time(0));



int main()
{
    ios::sync_with_stdio(0);
    cin.tie(),cout.tie();
    ll a;
    string b;
    cin>>a>>b;
    ll tmp=a*(b.back()-'0');
    tmp+=(a*(b[2]-'0')*10);
    tmp/=100;
    ll ans=a*(b[0]-'0');
    ans+=tmp;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i) = 0; (i) < (n); ++(i))
#define rrep(i,n) for(int (i) = (n) - 1; (i) >= 0; --(i)) //Reversi rep
#define nfor(i,a,b) for(int (i) = (a); (i) < (b); ++(i)) //Natural for
#define rfor(i,a,b) for(int (i) = (b) - 1; (i) >= (a); --(i)) //Reversi for
#define ll long long
#define mod (1000000007)
#define YES cout << "YES" << endl;
#define Yes cout << "Yes" << endl;
#define yes cout << "yes" << endl;
#define NO cout << "NO" << endl;
#define No cout << "No" << endl;
#define no cout << "no" << endl;

int asc(const void *a, const void *b) {
    return *(int *)a - *(int *)b;
}

int desc(const void *a, const void *b) {
    return *(int *)b - *(int *)a;
}

int main()
{
    int n,cnt = 0;
    cin >> n;
    int p[n];
    rep(i, n)cin >> p[i];
    rep(i, n){
        if (p[i] != i + 1) {
            ++cnt;
        }
    }
    if (cnt == 0 || cnt == 2) {
        YES;
    }else{
        NO;
    }
    return 0;
}


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

int main(int argc, char *argv[])
{
    int s;
    int a[200];
    int i, j;
    int ans;
    int min_m;

    scanf("%d", &s);

    a[1] = s;
    for (i = 1; i < 199; i++) {
        if (a[i] % 2 == 0) {
            a[i + 1] = a[i] / 2;
        } else {
            a[i + 1] = 3 * a[i] + 1;
        }
    }
    min_m = INT_MAX;
    for (i = 1; i < 199; i++) {
        for (j = i + 1; j < 199; j++) {
            if (j > min_m) {break;}
            if (a[i] == a[j] && j < min_m) {
                min_m = j;
            }
        }
    }
    ans = min_m;

    printf("%d\n", ans);

    return 0;
}


Measured memory_bytes: 128
target = input('')
ans = 'z'
pro = 1
list = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']

for i in range(len(list)):
    if (list[i]==target):
        ans = list[i+1]
        pro += 1

print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<unordered_map>
#include<map>
using namespace std;

int main(void){
    int D, G;
    cin >> D >> G;
    vector<int> p = vector<int>(D + 1);
    vector<int> c = vector<int>(D + 1);
    int result = 0;
    for(int i = 1; i <= D; i++){
        cin >> p[i] >> c[i];
        result += p[i];
        c[i] /= 100;
    }

    //unordered_map<int, int> memo;
    map<int, int> memo;
    G /= 100;
    memo[0] = 0;
    for(int i = 1; i <= D; i++){
        map<int, int> temp_memo;
        temp_memo = memo;
        for(auto it = temp_memo.begin(); it != temp_memo.end(); it++){
            int source = it->first;
            int source_val = it->second;
            for(int j = 1; j <= p[i]; j++){
                //int prev = source + i * (j - 1);
                if(memo.find(source + i * j) == memo.end()){
                    memo[source + i * j] = source_val + j;
                } else if(memo[source + i * j] > source_val + j) {
                    memo[source + i * j] = source_val + j;
                }
            }

            int prev = source + i * p[i];
            if(memo.find(prev + c[i]) == memo.end()){
                memo[prev + c[i]] = source_val + p[i];
            } else if(memo[prev + c[i]] > memo[source] + p[i]){
                memo[prev + c[i]] = source_val + p[i];
            }
        }
    }

    for(auto it = memo.begin(); it != memo.end(); it++){
        if(it->first >= G && result > it->second) result = it->second;
        //cout << it->first << ": " << it->second << endl;
    }
    cout << result << endl;
    return 0;
}


Measured memory_bytes: 5248
using System.Collections.Generic;
using System.Linq;
using System;
class Program
{
    static void Main()
    {
        string a = Console.ReadLine();
        string[] b = a.Split(' ');
        string result;
        if(b[0] == b[1]){
            result = b[2];
        }else{
            if(b[1] == b[2]){
                result = b[0];
            }else{
                result = b[1];
            }
        }

        Console.WriteLine(result);
    }
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0;i < n;i++)
#define all(i) i.begin(), i.end()
template<class T, class U> bool cmax(T& a, U b) { if (a<b) {a = b; return true;} else return false; }
template<class T, class U> bool cmin(T& a, U b) { if (a>b) {a = b; return true;} else return false; }

ll f(ll n) {
  ll t = n%10;
  while (n > 0) {
    t = n%10;
    n /= 10;
  }
  return t;
}

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

  ll n;
  cin >> n;
  cerr << f(n) << endl;

  vector<vl> cnt(10, vl(10));

  rep(i, n+1) {
    if (i == 0) continue;
    cnt[i%10][f(i)]++;
  }

  ll ans = 0;
  rep(i, 10) {
    rep(j, 10) {
      ans += cnt[i][j] * cnt[j][i];
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define range(a) (a).begin(),(a).end()
#define print(A,n) rep(i,0,n){cout<<(i ? " ":"")<<A[i];}cout<<endl;
#define pprint(A,m,n) rep(j,0,m){print(A[j],n);}
const long mod=1e9+7;
const int size=1e5;
const int inf=1e9;
int main(){
	int N;cin>>N;
	double x[N],y[N];double sum=0;
	rep(i,0,N){
		cin>>x[i]>>y[i];
	}rep(i,0,N){
		rep(j,0,i){
			sum+=sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]));
		}
	}
    cout.precision(16);
	cout<<fixed<<sum*2/N<<endl;
}
/*タスクを並列に行う 二分探索
x=(x ? true : false)
sorted
auto it=lower_bound(v.begin(),v.end(),w) v[it-v.begin()]>=w
auto it=upper_bound(v.begin(),v.end(),w) v[it-v.begin()]>w
void func(int* vec){}
puts(string) cout<<string<<endl;
1.*a/b int to double
(int)a-48 char to int
(char)(i+97) int to char
stoi(s) string to int
stoll(s)
cout.precision(16);
cout<<fixed<<a;
printf("%.6lf\n",a);
accumulate(a,a+n,0);
*/

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


#define endl            '\n'
#define ll              long long
#define ld              long double 
#define ull             unsigned long long int
#define MOD             (ll)(1e9 + 7)
#define vi              vector<int>
#define vl              vector<long>
#define vll             vector<ll>
#define vs              vector<string>
#define pll             pair<ll,ll>
#define mll             map<ll,ll>
#define len(x)          x.length()
#define all(x)          x.begin(),x.end()
#define deb1(x)         cout<<#x<<" "<<x<<endl;
#define deb2(x,y)       cout<<#x<<" "<<x<<'	'<<#y<<" "<<y<<endl;
#define deb3(x,y,z)     cout<<#x<<" "<<x<<'	'<<#y<<" "<<y<<'	'<<#z<<" "<<z<<endl;
#define debug1(x)       cerr<<#x<<" "<<x<<endl;
#define debug2(x,y)     cerr<<#x<<" "<<x<<'	'<<#y<<" "<<y<<endl;
#define debug3(x,y,z)   cerr<<#x<<" "<<x<<'	'<<#y<<" "<<y<<'	'<<#z<<" "<<z<<endl;
#define info(s)         cerr<<s<<" "<<endl;
#define fr(a,b,c)       for(auto a=b;b<c?a<c:a>c;b<c?a++:a--)
#define frc(a,b,c)      for(auto a=b;a!=c;a++)
#define tr(it, a)       for(auto it = a.begin(); it != a.end(); it++)
#define lb(v,x)         lower_bound(v.begin(), v.end(), x)
#define ub(v,x)         upper_bound(v.begin(), v.end(), x)
#define clr(x)          memset(x, 0, sizeof(x))
#define GR              (double)(1 + sqrt(5)) / 2
#define fib(n)          (ll)round(pow(GR,n) / sqrt(5))
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define out1(x)         cout<<x<<" "<<endl
#define out2(x,y)       cout<<x<<" "<<y<<endl
#define SORT(a)         sort(all(a));
#define SORTR(a)        sort(all(a),greater<ll>());
#define ARRAY(a,n)      vll a; fr(i,0,n) { ll temp; cin>>temp; a.pb(temp); }  
#define PRINT(a)        for(auto x:a)cout<<x<<" ";cout<<endl
#define MAX             100050
#define pb              push_back
#define mp              make_pair
#define F               first
#define S               second


template<typename T>
ostream& operator<<(ostream &out,const vector<T> &v);


template<typename T>
istream& operator>>(istream &in,vector<T> &v);





void solve()
{
    int n,k;cin>>n>>k;vi v(n+1);for(int i=1;i<=n;i++)cin>>v[i];
    vi dp(n+1);
    dp[1]=0;dp[2]=abs(v[2]-v[1]);
    for(int i=3;i<=n;i++)
    {
        dp[i]=INT_MAX;
        for(int w=1;w<=k;w++){
            if(i-w>=1)
            dp[i]=min(dp[i],abs(v[i]-v[i-w])+dp[i-w]);
        }
    }
    cout<<dp[n]<<endl;

    // for(int i=1;i<=n;i++ )
    // cout<<dp[i]<<" ";cout<<endl;
} 


int main()
{   
    #ifndef ONLINE_JUDGE 
        freopen("input.txt", "r", stdin); 
        freopen("output.txt", "w", stdout); 
    #endif 
    FIO;
    ll test;test=1;
    // cin>>test;for(ll i=1;i<=test;i++)
    solve();
    return 0;
}





template<typename T>
ostream& operator<<(ostream &out,const vector<T> &v){
    int i=0;
    for(T x:v){
        out<<x;
        (i++!=v.size())?out<<' ':out<<'\n';    
    }
    return out;
}


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

Measured memory_bytes: 3972
// Last Change: 02/09/2019 21:02:40.
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

void LoopUntilZeroInpput() {
  int hogegegege = 0;
  while (cin >> hogegegege && hogegegege != 0) {
  }
}

int main() {
  int N, K;
  cin >> N >> K;
  ++N;
  N = N / 2;
  if (N >= K) {
    cout << "YES";
  } else {
    cout << "NO";
  }
  cout << endl;

  //LoopUntilZeroInpput();
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <numeric>
using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

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


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

  vector<ll> x(n), y(n);
  int m = 31;
  REP(i, n) cin >> x[i] >> y[i];
  REP(i, n-1) {
    if ((x[i] + y[i] + long(pow(2, 31))) % 2 != (x[i+1] + y[i+1] + long(pow(2, 31))) % 2) {
      cout << -1 << endl;
      return  0;
    }
  }
  int odd = 0;
  if ((x[0] + y[0]) % 2 == 0) odd = 1;
  vector<ll> u(n), v(n);
  REP(i, n) {
    u[i] = x[i] + y[i] + odd;
    v[i] = x[i] - y[i] + odd;
  }
  cout << m + odd << endl;
  REP(i, m) cout << long(pow(2, i)) << " ";
  if (odd == 1) cout << 1;
  cout << endl;

  ll tmp_u, tmp_v;
  REP(i, n){
    vector<ll> arrayu(31, 0), arrayv(31, 0);
    tmp_u = (u[i] + pow(2, 31) - 1) / 2;
    tmp_v = (v[i] + pow(2, 31) - 1) / 2;
    REP(j, 31) {
      arrayu[j] = tmp_u % 2;
      arrayv[j] = tmp_v % 2;
      tmp_u /= 2;
      tmp_v /= 2;
      if (arrayu[j] == 0 && arrayv[j] == 0) {
        cout << "L";
      } else if (arrayu[j] == 0 && arrayv[j] == 1) {
        cout << "D";
      } else if (arrayu[j] == 1 && arrayv[j] == 0) {
        cout << "U";
      } else if (arrayu[j] == 1 && arrayv[j] == 1) {
        cout << "R";
      }
    }
    if(odd == 1) cout << "L";
    cout << endl;
  }




  return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize(2)
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using PII = pair<int, int>;
using PLL = pair<LL, LL>;
using VI = vector<LL>;
using VVI = vector<VI>;
const int INF = 1e9;
const int MXN = 2e5 + 5;
const int MXV = 0;
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define FOR(i, L, R) for (int i = L; i != (int)R; ++i)
#define FORD(i, L, R) for (int i = L; i != (int)R; --i)
#define IOS                                                                    \
    cin.tie(nullptr);                                                          \
    cout.tie(nullptr);                                                         \
    ios_base::sync_with_stdio(false);

int main()
{
    // IOS;
    int n, p, tmp = 0, t = 1;
    LL ans = 0;
    string s;
    VI cnt(MXN, 0);
    cin >> n >> p >> s;
    if (p == 2 || p == 5)
    {
        FOR(i, 0, n)
        {
            if ((s[i] - '0') % p == 0)
            {
                ans += (i + 1);
            }
        }
    }
    else
    {
        cnt[0] = 1;
        FORD(i, n - 1, 0 - 1)
        {
            tmp = (tmp + ((int)(s[i] - '0') * t)) % p;
            ans += cnt[tmp]++;
            t = (t * 10) % p;
        }
    }
    cout << ans << '\n';
}


Measured memory_bytes: 2180
#define ll long long int
#include <iostream>

using namespace std;

int main()
{
    string s;
    cin>>s;
    long long int total =0;
    for(int i=0;i<s.length();i++)
    {
        total+=(s[i]-'0');
    }
    if(total%9==0)
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }
    return 0;
}


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


int n;
double arr[3003], dp[3030][1550];
bool vis[3030][1550];

double func( int pos, int bad_dite_parbo ) {
   if (pos >= n) return 1;
   if ( vis[pos][bad_dite_parbo] ) return dp[pos][bad_dite_parbo];
   vis[pos][bad_dite_parbo] = 1;
   
   double x = arr[pos] * func( pos + 1, bad_dite_parbo ), y = 0.0;
   if (bad_dite_parbo > 0)
     y = (1 - arr[pos]) * func( pos + 1, bad_dite_parbo - 1 );

   return dp[pos][bad_dite_parbo] = x + y;
}

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

  int bad_dewa_jabe = n / 2;

  cout << fixed << setprecision(10);
  cout << func(0, bad_dewa_jabe) << endl;

  return 0;
}

Measured memory_bytes: 41472
#include<stdio.h>

int selectionSort(int a[], int N){
    int i,j,t,minj,sw=0;
    for(i=0; i<N-1; i++){
        minj = i;
        for(j=i; j<N; j++){
            if(a[j]<a[minj])minj=j;
        }
        t=a[i];
        a[i]=a[minj];
        a[minj]=t;
        if(i!=minj)sw++;
    }
    return sw;
}

int main(){
    int a[100], N ,i, sw;

    scanf("%d",&N);
    for(i=0; i<N; i++) scanf("%d",&a[i]);

    sw = selectionSort(a,N);

    for(i=0; i<N; i++){
        if(i>0)printf(" ");
        printf("%d",a[i]);
    }
    printf("\n");
    printf("%d\n",sw);

    return 0;
}



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

int main(void) {
	char a, b, ans;

	cin >> a >> b;
	if (b == 'H') {
		if (a == 'H')
			ans = 'H';
		else
			ans = 'D';
	}
	else {
		if (a == 'H')
			ans = 'D';
		else
			ans = 'H';
	}

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef pair<int, int> P;
typedef long long ll;
bool is_even(vector<int> a,vector<int> b){
    rep(i,a.size()){
        if(a[i]!=b[i]){
            return false;
        }
    }
    return true;
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int n;
    cin >> n;
    vector<int> v(n);
    rep(i,n){
        v[i] = i+1;
    }
    vector<int> p(n);
    vector<int> q(n);
    rep(i,n){
        cin >> p[i];
    }
    rep(i,n){
        cin >> q[i];
    }
    vector<int> ans;
    int cnt = 0;
    do{
        if(is_even(v,p)){
            ans.push_back(cnt);
        }
        if(is_even(v,q)){
            ans.push_back(cnt);
        }
        cnt++;
    }while(next_permutation(v.begin(),v.end()));
    cout << abs(ans[0]-ans[1]) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <sstream>
#include <string>
#include <map>
#include <set>
#include <stdlib.h>
#include <cmath>
#include <math.h>
#include <fstream>
#include <bitset>
#define int long long
using namespace std;
vector<pair<int, int> > p;
int h, w, n, ai;
void dfs(int x, int y, int wh){
    p.push_back(make_pair(x, y));
    if (wh == 1){
        if (y > 0){
            dfs(x, y-1, wh);
        }
        else{
            if (x < h-1){
                dfs(x+1, y, 1-wh);
            }
        }
    }
    else{
        if (y < w-1){
            dfs(x, y+1, wh);
        }
        else{
            if (x < h-1){
                dfs(x+1, y, 1-wh);
            }
        }
    }
}
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> h >> w >> n;
    vector<int> data;
    for (int i=0; i < n; i++){
        cin >> ai;
        data.push_back(ai);
    }
    int matrix[h][w];
    dfs(0, 0, 0);
    int u = 0;
    for (int i=0; i < data.size(); i++){
        for (int j=0; j < data[i]; j++){
            matrix[p[u+j].first][p[u+j].second] = i + 1;
        }
        u += data[i];
    }
    for (int i=0; i < h; i++){
        for (int j=0; j < w; j++){
            cout << matrix[i][j] << " ";
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 1404
#include<bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;

#define FOR(i,a,b) for (int i = a; i < b; ++i)
#define FORR(i,a,b) for (int i = b - 1; i >= a; --i)
#define REP(i,n) FOR(i,0,n)
#define REPR(i,n) FORR(i,0,n)

template<class T>
inline void read(T& x) {
  T s = 0, base = 1;
  char c;
  while (!isdigit(c=getchar())) if (c == '-') base = -base;
  while (isdigit(c)) {
    s = s * 10 + (c^48);
    c = getchar();
  }
  x = base * s;
}

int D, G;
int p[10], c[10];

int main() {
  read(D);
  read(G);
  G /= 100;

  REP(i,D) {
    read(p[i]);
    read(c[i]);
    c[i] /= 100;
  }

  int ans = numeric_limits<int>::max();
  for (int i = 0; i < (1 << D); ++i) {
    // i: 使いきったか否かを表すビット
    int sum = 0;
    int cnt = 0;

    for (int j = 0; j < D; ++j) {
      if ((i >> j) & 1) {
        sum += p[j] * (j + 1) + c[j];
        cnt += p[j];
      }
    }

    for (int j = D - 1; j >= 0; --j) {
      if ((i >> j) & 1) continue;
      if (sum >= G) break;
      int buf = min((G - sum + j) / (j + 1), p[j]);
      cnt += buf;
      sum += (j + 1) * buf;
    }

    if (G <= sum) ans = min(ans, cnt);
  }

  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 256
mod = 998244353

n = int(input())
d = list(map(int, input().split()))

p = [0]*(n)
for i in range(n):
    p[d[i]]+=1

if d[0]!=0:
    print(0)
    exit()

if p[0]!=1:
    print(0)
    exit()
ans = 1
j = 1
for i in range(1,n):
    if p[i]==0:
        break

    ans = (ans*(p[i-1]**p[i]))%mod
    j +=p[i]
if j==n:
    print(ans)
else:
    print(0)

Measured memory_bytes: 53300
n = int(input())
L = list(map(int,input().split()))
L = sorted(L)
import bisect
ans = 0
for i in range(n-2):
    for j in range(i+1,n-1):
        a = bisect.bisect_left(L,L[i]+L[j])
        ans += a-j-1
print(ans)

Measured memory_bytes: 9364
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using pii = pair<int, int>;

//const ll INF = 1e18L + 5;
//const int INF = 1e9 + 5;
//const double pi = 3.14159265358979323846;

void	solve()
{
	string s;
	cin >> s;
	vector<string> ans;
	ans.push_back(string(1, s[0]));
	string l(1, s[0]), r;
	int n = s.size();
	rep2(i, 1, n) {
		r += s[i];
		if (r != l) {
			ans.push_back(r);
			l = r;
			r = "";
		}
	}
	cout << ans.size() << endl;
}

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

	solve();
}


Measured memory_bytes: 11016
#include <vector> 
#include <list> 
 #include <map>
 #include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <limits.h>
using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << '=' << (x) << endl;
#define debug(x) cerr << #x << '=' << (x) << '('<<'L' << __LINE__ << ')' << ' ' << __FILE__ << endl;

LL minabs=LONG_LONG_MAX;

LL sum=0;
LL N;
vector<LL> A;
LL a;
int main(){
    cin>>N;
    REP(i,N){
        cin>>a;
        A.push_back(a);
        sum+=a;   
    }
    LL suke=0;
    FOR(i,0,N-1){
        suke+=A[i];
        minabs=min(minabs,abs(suke-(sum-suke)));
    }

    cout<<minabs<<endl;




}


Measured memory_bytes: 2420
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for (ll i=1; i<n; ++i)
#define all(c) begin(c),end(c)
/*
*/
int main(){
  ll N; cin>>N;
  vector<ll> ans(10010,0);
  rep(x,101) rep(y,101) rep(z,101){
    ll d=x*x+y*y+z*z+x*y+y*z+z*x;
    if(d > 10000) break;
    ans[d]++;
  }
  rep(i,N+1) cout<<ans[i]<<endl;
}

Measured memory_bytes: 3628
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(void) {
  int N;
  cin >> N;
  vector <int> a(N);
  for (int i = 0; i < N; i++) cin >> a[i];

  long long ans = 200*200*100;
  for (int i = -100; i <= 100; i++) {
    long long wk_ans = 0;
    for (int j = 0; j < N; j++) {
      wk_ans += ((a[j]-i)*(a[j]-i));
    }
    ans = min(ans, wk_ans);
  }
  cout << ans << endl;
  return 0;
}


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

const int maxn = 500005;

inline int gi()
{
	char c = getchar();
	while (c < '0' || c > '9') c = getchar();
	int sum = 0;
	while ('0' <= c && c <= '9') sum = sum * 10 + c - 48, c = getchar();
	return sum;
}

int n, k;
int p[maxn], q[maxn], r[maxn], cnt;
int Min[maxn << 2];

#define mid ((l + r) >> 1)
#define lch (s << 1)
#define rch (s << 1 | 1)

void build(int s, int l, int r)
{
	Min[s] = n + 1;
	if (l == r) return ;
	build(lch, l, mid);
	build(rch, mid + 1, r);
}

void modify(int s, int l, int r, int p, int v)
{
	if (l == r) return Min[s] = v, void();
	if (p <= mid) modify(lch, l, mid, p, v);
	else modify(rch, mid + 1, r, p, v);
	Min[s] = min(Min[lch], Min[rch]);
}

int query(int s, int l, int r, int ql, int qr)
{
	if (ql <= l && r <= qr) return Min[s];
	int res = n + 1;
	if (ql <= mid) res = min(res, query(lch, l, mid, ql, qr));
	if (qr >= mid + 1) res = min(res, query(rch, mid + 1, r, ql, qr));
	return res;
}

struct edge
{
	int to, next;
} e[maxn << 1];
int h[maxn], deg[maxn], tot;

priority_queue<int> que;

void add(int u, int v)
{
	e[++tot] = (edge) {v, h[u]}; h[u] = tot;
	++deg[v];
}

int main()
{
	n = gi(); k = gi();
	for (int i = 1; i <= n; ++i) q[p[i] = gi()] = i;
	build(1, 1, n);
	for (int i = n, x; i >= 1; --i) {
		x = query(1, 1, n, max(1, q[i] - k + 1), q[i]);
		if (x <= n) add(q[x], q[i]);
		x = query(1, 1, n, q[i], min(n, q[i] + k - 1));
		if (x <= n) add(q[x], q[i]);
		modify(1, 1, n, q[i], i);
	}

	for (int i = 1; i <= n; ++i)
		if (!deg[i]) que.push(i);
	int u;
	while (!que.empty()) {
		r[++cnt] = u = que.top(); que.pop();
		for (int i = h[u], v; v = e[i].to, i; i = e[i].next)
			if (!(--deg[v])) que.push(v);
	}
	reverse(r + 1, r + n + 1);
	for (int i = 1; i <= n; ++i) p[r[i]] = i;
	for (int i = 1; i <= n; ++i) printf("%d\n", p[i]);
	
	return 0;
}


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

#define pb push_back
#define fo(i,s,t) for(int i = s; i <= t; ++ i)
#define fd(i,s,t) for(int i = s; i >= t; -- i)
const int maxn = 1000500;

long long n, m, ans;

int main()
{
	cin >> n >> m;
	long long t = min(n, m/2);
	n -= t; m -= 2*t;
	ans = t;
	if(!n)
	{
		ans += m/4;
	}	
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
  // 標準入力高速化のおまじない
  // scanfとの同期を切る。以降紛らわしいのでscanf使用不可。
  ios::sync_with_stdio(false);
  // // cin前の自動flashをやめる
  cin.tie(nullptr);

  int N,M;
  cin >> N >> M;
  vector<int> H(N);
  vector<set<int>> O(N);
  for(int i=0; i<N; i++){
    cin >> H[i];
  }
  for(int i=0; i<M; i++){
    int from,to;
    cin >> from >> to;
    from--;
    to--;
    O[from].insert(to);
    O[to].insert(from);
  }

  int result=0;
  for(int i=0; i<N; i++){
    bool is_good=true;
    set<int> observatories = O[i]; 
    for(int ob : observatories){
      if(H[i] <= H[ob]) is_good = false;
    }
    if(is_good) result++;
  }

  cout << result << endl;

  return 0;
}

Measured memory_bytes: 17976
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define sz(v) (int)(v).size()
#define pb push_back
#define sc second
#define fr first
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
using namespace std;
typedef long long int ll;
typedef pair <int, int> P;

const ll MOD=1000000007;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int x,y;
    cin>>x>>y;
    cout <<x*y/2<<"\n";
}

Measured memory_bytes: 256
# coding: utf-8
import re
import bisect
from datetime import datetime as dt
import bisect
import math
import sys
input = sys.stdin.readline

def gcd(a, b):
    return math.gcd(a, b)

def lcm(a, b):
    return a * b / gcd(a, b)

class slist(list):
    def __init__(self, *args, **kw):
        list.__init__(self, *args, **kw)
        self.sort()

    def append(self, value):
        bisect.insort(self,value)

    def index_left(self, value):
        return bisect.bisect_left(self, value)


if __name__ == '__main__':
    d, n = map(int, input().split())
    if n == 100:
        print(100 ** d * (n+1)) 
    else:
        print(100 ** d * n)


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
using P = pair<ll, ll>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep1(i, n) for(ll i=1;i<=(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define INF 1000000000

void solve_abc_a() {
	ll A[3];
	string ans;

	cin >> A[0] >> A[1] >> A[2];

	if (A[0] + A[1] + A[2] >= 22) {
		ans = "bust";
	}
	else {
		ans = "win";
	}

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

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

	solve_abc_a();

	return 0;
}

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

#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,n) for(int i=1; i<(n); i++)
#define pii pair<int,int>
#define gsort(x,n) sort((x),(x)+(n),greater<int>())
#define all(x) (x).begin(), (x).end()
#define int int64_t
#define ll long long
#define abs(a) llabs(a)
#define re(s) reverse((s).begin(),(s).end())
#define setout(n,x) setw(n) << setfill(x)
#define Fixed fixed << setprecision(10)
const long long mod = 1000000007;
using namespace std;

signed main(){

    cin.tie(0);
    ios::sync_with_stdio(false);

    string s;
    int cnt=0,ans=0;
    cin>>s;
    bool a=false,b=false;

    rep(i,s.size()){
        if(a == false && s[i]=='A') cnt = i, a = true;
        if(b == false && s[s.size()-(i+1)]=='Z') ans = (s.size()-(i+1)), b = true;
        if(a == true && b == true) break;
    }

    cout<<ans - cnt + 1<<'\n';
}

Measured memory_bytes: 720