akhauriyash/Code-Regression huggingface dataset:
#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <cassert>
using namespace std;
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();}
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
const double EPS = 1e-10;
const double PI  = acos(-1.0);

const int MAX=INT_MAX/10;
int main(){
	int n;
	while(cin>>n,n){
		vvi dp(n+1,vi(4,MAX));
		vi p(n),t(n);
		REP(i,n){
			cin>>p[i]>>t[i];
		}
		dp[0][0]=0;
		REP(i,n){
			REP(j,4){
				if(j>0){
					int dist=i==0?p[i]:abs(p[i]-p[i-1]);
					if(j*dist<=(i==0?t[i]:t[i]-t[i-1])){
						dp[i+1][j]=min(dp[i+1][j],dp[i][j-1]+dist);
					}
				}
				if(i>0&&(j+1)*p[i-1]+p[i]<=t[i]-t[i-1]){
					dp[i+1][1]=min(dp[i+1][1],dp[i][j]+p[i]+p[i-1]);
				}
			}
		}
		
		int ans=MAX;
		REP(i,4){
			ans=min(ans,dp[n][i]+p[n-1]);
		}
		if(ans!=MAX){
			cout<<"OK "<<ans<<endl;
		}else{
			REP(i,n+1){
				bool ok=false;
				REP(j,4){
					if(dp[i][j]!=MAX){
						ok=true;
					}
				}
				if(!ok){
					cout<<"NG "<<i<<endl;
					break;
				}
			}
		}
	}
}

Measured memory_bytes: 1216
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
first = 0
second = 0
count = 0
for i in range(0, N):
    first = min(A[i] - second, B[i])
    second = min(A[i + 1], B[i] - first)
    
    count += first + second

print(count)


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

long funk(long c, long d){
  long cd = c*d;
  while(c!=d){
    if (c<d){
      d -= c;
    }
    else if(d<c){
      c -= d;
    }
  }
  return cd/c;
}

int main(){
  long a,b,c,d;
  cin >> a >> b >> c >> d;
  long total = b - a + 1;
  long cd = funk(c, d);
  long cx, dx, cdx;
  cx = b/c - (a-1)/c;
  dx = b/d - (a-1)/d;
  cdx = b/cd - (a-1)/cd;
  long ans = total - (cx + dx - cdx);
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
 
int main() {
  int Bob = 0;
  int Alice = 0;
  int cal = 0;
  int N;
  int a[100];
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }
  sort(a, a + N, greater<int>());
  for (int i = 0; i < N; i++) {
    if(i%2 == 0){
      Alice += a[i];
    }
    else{
      Bob += a[i];
    }
  }
  cal = Alice - Bob;
  cout << cal;
}


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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

int main()
{
    int x, y;
    cin >> x >> y;
    OP(x + y / 2);

    return 0;
}

Measured memory_bytes: 256
#pragma target("avx")
#include<bits/stdc++.h>
using ll = int_fast64_t;
using P = std::pair<ll,ll>;
using V = std::vector<ll>;
template<typename T> using pq = std::priority_queue<T>;
template<typename T> using rpq = std::priority_queue<T, std::vector<T>, std::greater<T>>;

#define rep(i,b,e) for(ll i=b; i<e; i++)
#define be(vec) vec.begin(),vec.end()
#define print(vec) printf("[ ");for(auto &i:vec)printf("%ld ",i);puts("]");
#define scan(vec) for(auto &i:vec)scanf("%ld",&i)
#define fi first
#define se second

const int MOD = 1e9+7;
const ll INF = 1e18;
int dx[] = {0, 1, 0, -1, 1, 1, -1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

int main(){
	int a, b, c;
	scanf("%d %d %d", &a, &b, &c);
	if(a<b) std::swap(a, b);
	if(b<c) std::swap(b, c);
	if(a<b) std::swap(a, b);

	int ans = 0;
	while(a!=b) b++, c++, ans++;
	while(c<b) c+=2, ans++;
	if(b<c) ans++;
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define show(x) cout << #x << " = " << (x) << endl;
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl;
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = 1<<30;
const ll INFLL = 1LL<<60;
//cout << fixed << setprecision(10);

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

ll x[55];
ll dp[55][55][2555];

int main () {
  ll n, a;
  cin >> n >> a;
  rep(i,n) cin >> x[i];
  
  dp[0][0][0] = 1;
  rep(i,n+1) {
    rep(j,n+1) {
      rep(k,2501) {
        if (dp[i][j][k] == 0) continue;
        dp[i+1][j][k] += dp[i][j][k];
        dp[i+1][j+1][k+x[i]] += dp[i][j][k];
      }
    }
  }

  ll ans = 0;
  for (int i = 1; i <= n; ++i) {
    ans += dp[n][i][i*a];
  }

  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 55552
N=gets.to_i
ds=gets.split.map(&:to_i).group_by{|d|d}
M=gets.to_i
ts=gets.split.map(&:to_i).group_by{|t|t}

b = ts.all? {|k,v|ds[k] && v.count<=ds[k].count}
puts (b ? 'YES' : 'NO')


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

using namespace std;

int main(void) {
  int a[3];
  for (int i = 0; i < 3; i++) {
    cin >> a[i];
  }

  sort(a, a + 3);

  cout << a[0] + a[1] << endl;

  return 0;
}

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

using namespace std;

int main() {int n,i=0;;
    string s;
    cin>>s;
 string t="";
   n=s.size();
   vector<char>v;
   while(i<n)
    {
        if(s[i]=='B')
        {
            if(!(v.empty()))v.pop_back();
        }
        else v.push_back(s[i]);i++;
    }
    for(i=0;i<v.size();i++)cout<<v[i];
}

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

int main() {
  using tsii = tuple<string, int, int>;
  int a;
  cin >> a;
  vector<string> city(a);
  vector<int> score(a);
  vector<tsii> list(a);
  for (int i = 0; i < a; i++) {
    cin >> city.at(i);
    cin >> score.at(i);
  }
  for (int i = 0; i < a; i++) {
    score.at(i) = 100 - score.at(i);
  }
  for (int i = 0; i < a; i++) {
    list.at(i) = tsii(city.at(i), score.at(i), i);
  }
  sort(list.begin(), list.end());
  for (int i = 0; i < a; i++) {
    cout << get<2>(list.at(i)) + 1 << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;



int main() {
    int n;
    cin >> n;
    ll ans = 0;
    rrep(i,n) {
        for(int j = 1; j * j <= n - i; ++j) {
            if((n - i) % j == 0) ans += 2;
            if(j * j == n - i) --ans;
        }
    }
    cout << ans << endl;

    return 0;
}


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

#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define int long long
#define ll long long
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define ff first
#define ss second
#define ld long double
#define pii pair<int, int>

#define prev prev228
#define left left228
#define right right228
#define dist dist228
#define tm tm228

using namespace std;

mt19937 rnd(time(nullptr));

const long long INF = 1e18, P = 1e9 + 7, N = 1e6 + 10;
const long double EPS = 1e-9;

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

    //cout << setprecision(15) << fixed;

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    int p = 0, ans = 0;
    for (int i = 0; i < n; i++) {
        int cur = p + 1;
        if (cur < a[i]) {
            ans += a[i] / cur - (a[i] % cur == 0);
            a[i] = 1;
        }
        p = max(p, a[i]);
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 3956
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<numeric>
#include<algorithm>
#include<tuple>
#include<cmath>
#include <iomanip>

typedef unsigned long long ull;
typedef long long ll;

ll DENOM = 1000000000LL + 7LL;

using namespace std;

ll n, m, k;
ll h, w;

int main(){
    string s;
    cin >> s;
    string ss;
    if(s[s.size()-1]=='s'){
        ss = "es";
    }else{
        ss = "s";
    }
    cout << s << ss << endl;
    return 0;
}


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

using namespace std;

typedef long long LL;
#define N 1200000

const LL mod=1000000007;
LL n,fac[N],ifac[N],ans,f[N];

void upd(LL &x,LL y){x=(x+y)%mod;}

LL inv(LL x){
	return x==1?1:(mod-mod/x)*inv(mod%x)%mod;
}

LL C(LL x,LL y){
	return x<y||y<0?0:fac[x]*ifac[y]%mod*ifac[x-y]%mod;
}

int main(){
	scanf("%lld",&n);
	fac[0]=1; for (LL i=1;i<=n;++i) fac[i]=fac[i-1]*i%mod;
	ifac[n]=inv(fac[n]); for (LL i=n-1;~i;--i) ifac[i]=ifac[i+1]*(i+1)%mod;
	for (LL i=1;i<n;++i){
		f[i]=C(i-1,n-1-i)*fac[i]%mod*fac[n-i-1]%mod;
		upd(ans,(f[i]-f[i-1])*i);
	}
	upd(ans,mod);
	printf("%lld\n",ans);
	
	return 0;
}
			

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

int main() {
	int n;
	cin>>n;
	int x=0;
	long long  int a[300000];
	for(int i=0;i<n;i++)cin>>a[i];
	for(int i=0;i<n;i++)x=x^a[i];
	for(int i=0;i<n;i++)a[i]=x^a[i];
	for(int i=0;i<n;i++)cout<<a[i]<<" ";
}


Measured memory_bytes: 5116
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

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

use = [[0]*N for _ in range(N)]

for k in range(N):
    for i in range(N):
        for j in range(N):
            if mat[i][j] > mat[i][k]+mat[k][j]:
                print("-1")
                exit()
            if mat[i][j] == mat[i][k]+mat[k][j] and i != k and k != j:
                use[i][j] = 1
ans = 0
for i in range(N):
    for j in range(N):
        if use[i][j] == 0:
            ans += mat[i][j]
print(ans//2)


Measured memory_bytes: 45564
package main

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

func main() {
	var text string
	scanner := bufio.NewScanner(os.Stdin)
	for scanner.Scan() {
		text = scanner.Text()
	}
	n, _ := strconv.Atoi(text)
	hour := n / 3600
	n = n - hour*3600
	minute := n / 60
	second := n - minute*60
	fmt.Printf("%v:%v:%v\n", hour, minute, second)
}



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

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        char[] arr = in.next().toCharArray();
        
        int ans = 0;
        for (int i = 0, j = arr.length - 1; i < j; ++i, --j) {
            ans += arr[i] != arr[j] ? 1 : 0;
        }

        System.out.println(ans);
    }
}

Measured memory_bytes: 21972
#include<bits/stdc++.h>
using namespace std;
#define re register
char s[20100],ss[20010];
int nq[20100],nq1[20100],n1,k;
void sol(re int i,re int n)
{
	if(n==1||i==n1)return;
	char aa='z';
	re int cct=0;
	for(re int i1=1;i1<=n;i1++)
	{
		if(s[nq[i1]+i]<aa)aa=s[nq[i1]+i];
	}
	for(re int i1=1;i1<=n;i1++)
	{
		if(s[nq[i1]+i]==aa)nq1[++cct]=nq[i1];
	}
	for(re int i1=1;i1<=cct;i1++)nq[i1]=nq1[i1];
	sol(i+1,cct);
}
int main()
{
	char aa='z';
	re int n;
	scanf("%d%d%s",&n1,&k,s+1);
	n=n1;
	for(re int i=1;i<=n;i++)
	{
		s[n+i]=s[n-i+1];
		if(s[i]<aa)aa=s[i];
	}
	for(re int i=1;i<=n+1;i++)nq[i]=i;
	sol(0,n+1);
	for(re int i=1;i<=n;i++)ss[i]=s[nq[1]+i-1];
	re int x=1,x1;
	while(x<n&&ss[x+1]==ss[x])x++;x1=x;
	for(k--;k&&x1<=n;x1<<=1,k--);
	if(x1>n)x1=n;
	for(re int i=1;i<=x1;i++)putchar(ss[1]);
	for(re int i=1;i+x1<=n;i++)putchar(ss[x+i]);
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <unordered_map>
#include <random>
#include <cstdio>
#include <cstring>
#include <cmath>

using namespace std;
using ll = long long;

ll N, A, B;

void input() {
    cin >> N >> A >> B;
}

void solve() {
    cout << min(A, B) << ' ' << max(A + B - N, 0ll) << endl;
}


int main() {
    input();
    //    cout << solve() << endl;
    solve();
    
    return 0;
}



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

using namespace std;

#define ll long long
#define ld long double

signed main() {
	int n; cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; ++i) cin >> a[i];
	// 最小値の計算
	int min = 1;
	for (int i = 0; i < n - 1; ++i)
		if (a[i] >= a[i + 1])
			++min;
	// 答えの出力
	cout << min << endl << n << endl;
	return 0;
}


Measured memory_bytes: 3128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll n,i,sum=0,x,y,i1,lcm=1,m;
    cin>>n>>m;
    ll arr[n];
    for (i=0;i<n;i++){
        cin>>arr[i];
        arr[i]/=2;
        lcm=lcm*arr[i]/__gcd(lcm,arr[i]);
    }
    for (i=0;i<n;i++){
        if ((lcm/arr[i])%2==0){
            cout<<"0\n";
            return 0;
        }
    }
    if (lcm>m){
        cout<<"0\n";
        return 0;
    }
    ll hi,lo,mid;
    m--;
    hi=m/2;
    lo=0;
    while (hi>lo){
        mid=lo+(hi-lo)/2+(hi-lo)%2;
        x=mid*2+1;
        if (lcm*x>m){
            hi=mid-1;
        }
        else {
            lo=mid;
        }
    }
    cout<<lo+1<<'\n';
    

}

Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC047
{
	class Q1
	{
		static void Main()
		{
			var datas = Console.ReadLine().Split(' ').Select(x => int.Parse(x));
			Console.WriteLine(datas.Max() == (datas.Sum() - datas.Max()) ? "Yes" : "No");
		}
	}
}


Measured memory_bytes: 2904
import sys

input = sys.stdin.readline

def main():
    ans = 0
    H, W, M = map(int, input().split())
    bombs = []
    hs = [0]*(H)
    ws = [0]*(W)
    for _ in range(M):
        h, w = map(int, input().split())
        bombs.append(tuple([h-1, w-1]))
        hs[h-1] += 1
        ws[w-1] += 1
    maxh = max(hs)
    maxw = max(ws)
    ans = maxh + maxw

    maxhindex = [i for i, x in enumerate(hs) if x == maxh]
    maxwindex = [i for i, x in enumerate(ws) if x == maxw]

    isfound = False

    bombs = set(bombs)
    for i in maxhindex:
        for j in maxwindex:
            if (i, j) not in bombs:
                print(ans)
                exit()

    print(ans-1)

if __name__ == '__main__':
    main()

Measured memory_bytes: 90140
// AOJ 0270
#include<cstdio>
#include<algorithm>
#define rep(i,a) for(int i=0;i<(a);++i)
#define repi(i,a,b) for(int i=(a);i<(b);++i)

const int MAX_N = 300000;

int N, Q, m;
int c[MAX_N], L[MAX_N+1];
bool T[MAX_N+1];

int main()
{
	scanf( "%d%d", &N, &Q );
	rep( i, N )
	{
		scanf( "%d", c+i );
		T[c[i]] = true;
		m = std::max( m, c[i] );
	}
	repi( i, 1, m+1 )
	{
		if( T[i-1] )
			L[i] = std::max( i-1, L[i-1] );
		else
			L[i] = L[i-1];
	}

	rep( t, Q )
	{
		int q;
		scanf( "%d", &q );

		int ans = 0;
		for( int cur = m; cur; )
		{
			int p = cur % q;
			ans = std::max( ans, p );
			if( cur-p < 0 )
				break;
			cur = L[cur-p];
		}

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

	return 0;
}

Measured memory_bytes: 3660
#include<iostream>
#include<cstdio>
#include<cmath>

using namespace std;

int main(int argc, char *argv[])
{
  double x,y;
  double sumE = 0;
  double sumN = 0;
  double rad = M_PI/2.0;
  while(scanf("%lf,%lf",&x,&y) !=EOF ){
    getchar();
    if(x ==0&& y== 0)
      break;
    sumE += x*cos(rad);
    sumN += x*sin(rad);
    rad  -= y*M_PI/180;
  }
  cout <<(int)sumE <<endl<<(int)sumN <<endl;
  return 0;
}

Measured memory_bytes: 1236
#include <bits/stdc++.h>
#define ll long long int
#define endl '\n'
#define MOD 1000000007
#define pb push_back
#define ff first
#define ss second
#define con continue
#define ub upper_bound
#define lb lower_bound


using namespace std;
ll max(ll a,ll b)
{

    if(a<b) return b ;
    return a ;
}




int main()
{
     ios_base::sync_with_stdio(false);
     cin.tie(NULL);
    ll a,b ,c,d;
    cin >> a >> b >> c>> d;


    ll ans =max(d*b,d*a);
    ans=max(ans,max(a*c,c*b));
    cout << ans << endl;
}


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

int main() {
	int n;
    cin>>n;
    int s[3][200]={0};
    int sum[200]={0};

    for(int i=0;i<n;i++){
        for(int j=0;j<3;j++){
            cin>>s[j][i];
        }
    }
    
    for(int i=0;i<3;i++){
        int check[100]={0};
        for(int j=0;j<n;j++){
            check[s[i][j]-1]++;
        }
        
        for(int j=0;j<n;j++){
            if(check[s[i][j]-1]==1){
                sum[j]+=s[i][j];
            }
        }
    }

    for(int i=0;i<n;i++){
        cout<<sum[i]<<endl;
    }

	return 0;
}

Measured memory_bytes: 1164
N = int(input())
X = [input() for _ in range(N)]

ctr = [[], []]
for s in X:
    t = [0] * (len(s) + 1)
    for j in range(len(s)):
        t[j + 1] = t[j] + int(s[j] == "(") - int(s[j] == ")")
    if t[-1] > 0:
        ctr[0].append((min(t), t[-1]))
    else:
        ctr[1].append((min(t) - t[-1], -t[-1]))

flag = True
tmp = 0
for i in range(2):
    cur = 0
    for m, c in sorted(ctr[i], reverse=True):
        flag &= cur + m >= 0
        cur += c
    if i == 0:
        tmp = cur
    else:
        flag &= tmp == cur
        
if flag:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 201996
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[][] a = new int[2][n];
		int max = 0;
		int right = 0;
		for(int i = 0; i < 2; i++) {
			for(int j = 0; j < n; j++) {
				a[i][j] = sc.nextInt();
			}
		}
		for(int i = 0; i < n; i++) {
			right += a[0][i];
			int sum = right;
			for(int j = i; j <n; j++) {
				sum += a[1][j];
			}
			max = Math.max(sum, max);
		}
		System.out.println(max);
	}
}

Measured memory_bytes: 23892
#include <iostream>

using namespace std;


int main()
{

	unsigned long i, j;
	unsigned long n;
	unsigned long *ary[2];
	unsigned long tmp, sum = 0;
	

	cin >> n;

	ary[0] = new unsigned long[n];
	ary[1] = new unsigned long[n];

	for (i=0; i<n; i++) {
		cin >> ary[0][i];
	}
	for (i=0; i<n; i++) {
		cin >> ary[1][i];
	}
	   
	
	for (i=0; i<n; i++) {
		tmp = 0;
		for (j=0; j<n; j++) {
			if (j<i) {
				tmp += ary[0][j];
			} else if (i == j) {
				tmp += (ary[0][j] + ary[1][j]);
			}else{
				tmp += ary[1][j];
			}
		}

		if (tmp > sum) {
			sum = tmp;
		}
	}

	cout << sum << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
using namespace std;
int main()
{
	int t;cin>>t;
	int ac=0,wa=0,tle=0,re=0;
	string state;
	while(t--)  {
		cin>>state;
		if(state=="AC")
			ac++;
		else if(state=="WA")
			wa++;
		else if (state=="TLE")
			tle++;		
		else if(state=="RE")
			re++;
	}
	cout<<"AC x " << ac<<endl;
	cout<<"WA x " << wa<<endl;
	cout<<"TLE x " << tle<<endl;
	cout<<"RE x "<<re<<endl;
	
	
}



Measured memory_bytes: 3592
#include <cassert>
#include <cctype>
#include <iostream>
#include <stack>
using namespace std;

constexpr int MAX_SIZE = 50;
constexpr int MAX_LEN = 1000;
constexpr int dx[] = {0, 1, 0, -1};
constexpr int dy[] = {-1, 0, 1, 0};

int h, w;
string field[MAX_SIZE];
string command;

int x, y, d, pc;
bool visited[MAX_SIZE][MAX_SIZE][MAX_LEN][4];
int match[MAX_LEN];
int dir[128];

void mov(const int move_d) {
	if(field[y + dy[move_d]][x + dx[move_d]] != '#') {
		x += dx[move_d];
		y += dy[move_d];
	}
}

void action() {
	switch(command[pc++]) {
	case '^': mov(d); break;
	case 'v': mov((d + 2) & 0x3); break;
	case '<': d = (d + 3) & 0x3; break;
	case '>': d = (d + 1) & 0x3; break;
	default: assert(false);
	}
}

bool condition() {
	const char c = command[pc++];
	switch(c) {
	case '~': return !condition();
	case 'C': return field[y + dy[d]][x + dx[d]] == '#';
	case 'T': return true;
	default: return d == dir[c];
	}
}

int solve() {
	int ans = 0;
	while(pc < command.size() && !visited[y][x][pc][d]) {
		visited[y][x][pc][d] = true;

		const int current_pc = pc;
		switch(command[pc++]) {
		case '[': // if statement
		{
			if(!condition()) pc = match[current_pc] + 1;
			break;
		}
		case ']': // close if
		{
			break;
		}
		case '{': // while statement
		{
			if(!condition()) pc = match[current_pc] + 1;
			break;
		}
		case '}': // close while
		{
			pc = match[current_pc];
			break;
		}
		default:
			++ans;
			pc = current_pc;
			action();
			if(field[y][x] == 'g') return ans;
		}
	}

	return -1;
}

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

	dir['N'] = 0;
	dir['E'] = 1;
	dir['S'] = 2;
	dir['W'] = 3;

	cin >> h >> w;
	for(int i = 0; i < h; ++i) {
		cin >> field[i];

		const int pos = field[i].find('s');
		if(pos != string::npos) {
			x = pos;
			y = i;
		}
	}
	cin >> command;

	stack<int> sta;
	for(int i = 0; i < command.size(); ++i) {
		switch(command[i]) {
		case '[':
		case '{':
			sta.push(i);
			break;
		case ']':
		case '}':
			const int l = sta.top();
			match[l] = i;
			match[i] = l;
			sta.pop();
			break;
		}
	}

	cout << solve() << endl;

	return EXIT_SUCCESS;
}

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

using namespace std;

int main() {
  int N, D;
  cin >> N >> D;
  D = D * 2 + 1;
  if(N % D == 0) {
    cout << N / D;
  }
  else {
    cout << N / D + 1;
  }
  
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main()
{
	char a[500];
	int l,b,c=0,i,n,j;
	gets(a);
	n=strlen(a);
	if(a[0]=='A')
    {
        for(i=2;i<n-2;i++)
        {
            if(a[i]=='C')
            {

            b=i;

            break;
            }


        }
        for(j=1;j<n;j++)
        {
            if(j==b)
            {
                continue;
            }
            if(a[j]>'Z' && a[i]=='C')
            {
                c++;
            }

        }

    }
    if(c==(n-2))
        printf("AC\n");
    else
        printf("WA\n");
    return 0;
}


Measured memory_bytes: 128
#include<iostream>

#define MODINT 1000000007

using namespace std;

// Problem https://atcoder.jp/contests/abc055/tasks/abc055_b

int main(void){
    long long int answer;
    answer = 1;
    long int COUNT;
    cin >> COUNT;
    for(long int k=1;k<=COUNT;k++){
        answer = (answer * k) % MODINT;
    }
    cout << answer << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define rep2(i,n) rep3(i,0,n)
#define rep3(i,j,n) for((i)=(j) ; (i)<(n) ; (i)++)
#define pl(format,var) p(format "\n",var)
#define p(format,var) printf(format,var)
#define asizeof(array) (sizeof(array)/sizeof(array[0]))
 
 
#define YMAX 9
#define XMAX 5
 
int count=0; //For debugging
 
typedef enum {
    U=0,
    R,
    D,
    L
} state_t; //状態を表す列挙型
 
//状態に対応する文字を出力
void printstate(state_t s){
    switch(s){
        case L:
            printf("L");
            break;
        case R:
            printf("R");
            break;
        case U:
            printf("U");
            break;
        case D:
            printf("D");
            break;
        default:
            printf("%d",s);
            break;
    }
}
 
//RRRRDDDDLLLUUURRDDLURDLURDLURDLURD
//RRRRDDDDLLLUUURRDDLURULLDDDRRRUUUULLLL
//                     ~ ~~ ~~
 
int main(){
    char line[80]; //入力行
    int i,j; //カウンタ変数
    int array[YMAX][XMAX]; //入力データ
    int x,y; //探索先インデックス
    int px,py; //現在の位置
    state_t s; //現状態
    int dir4data[4][2]={
        {-1,0}, /* U */
        {0,0}, /* R */
        {1,0}, /* D */
        {0,-1} /* L */
    };
    int dir4pos[4][2]={
        {-2,0}, /* U */
        {0,1}, /* R */
        {2,0}, /* D */
        {0,-1} /* L */
    };
 
    rep2(i,YMAX){
        fgets(line, sizeof(line), stdin);
        rep2(j,XMAX){
            array[i][j] = line[j] - '0';
        }
        if(i%2==0)
            array[i][j-1] = 0; //ゴミデータが入っているのでゼロクリアしとく
    }
     
    //スタート地点をセット
    px = py = 0;
    x = y = 0;
    s = R;
     
    while(s==R || px!=0 || py!=0){
        //count++; if(count == 35) break;
        //現在の探索先から各方向を調べる
        for(i=0,j=(s==U)?L:s-1 ; i<4 ; i++,j++){
            //方向配列をループさせる
            if(j>=4)
                j = 0;
 
// s = r
// py,px = 4,3
// y,x = 4,2
 
            //次の探索先を計算
            y = py + dir4data[j][0];
            x = px + dir4data[j][1];
             
            //if(count==22) printf("#### y,x = %d,%d\n",y,x), printf("#### j=%d\n",j);
             
            //次の探索先が無効か0なら, スキップ
            if(x<0 || y<0 || x>=XMAX || y>=YMAX || array[y][x]==0){
                continue;
            }
            s = j;
            py += dir4pos[j][0];
            px += dir4pos[j][1];
            printstate(s);
            break;
        }
        /*
        printf("## count:%d s:",count);
        printstate(s); printf("\n");
        printf("## py,px = %d,%d\n",py,px);
        printf("## y,x = %d,%d\n",y,x);     
        printf("\n");
        */
    }
    printf("\n");
  return 0;
}

Measured memory_bytes: 524
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <cstdio>
#include <string>
#include <cmath>
#include <queue>
#include <tuple>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <random>
#include <set>
#include <stack>
#include <time.h>

//#include <bits/stdc++.h>
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i,i0,n) for(int (i)=(i0);(i)<(n);(i)++)
#define FORR(i,i0,n) for(int (i)=(n)-1; (i)>=(i0);(i)--)
#define SORT(x) sort(x.begin(),x.end())
#define SORTR(x) sort(x.begin(),x.end(),greater<vector<int>>())

#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple

using namespace std;
using ll = long long;
typedef std::pair<int, int> pii;
typedef std::pair<int, double> pid;
typedef std::vector<int> vi;
typedef std::vector<pii> vii;

#define PI 3.14159265358979323846264338327950L
const int mod = 1e9+7;



void solve(){

    int n;
    cin >> n;
    int ans = 0;
    vector<int> x(n),y(n);
    rep(i,n){
        cin >> x[i] >> y[i];
    }
    
    int maxxyp = -1001001001;
    int minxyp = 1001001001;
    int maxxym = -1001001001;
    int minxym = 1001001001;
    
    rep(i,n){
        int v = x[i]+y[i];
        maxxyp = max(maxxyp,v);
        minxyp = min(minxyp,v);
        v = x[i] - y[i];
        maxxym = max(maxxym,v);
        minxym = min(minxym,v);
    }
    ans = max( maxxyp - minxyp, maxxym - minxym);
    
    cout << ans;
    
}




int main() {
    int T;
    //if (0==0) cin >> T;  
    //else T = 1;
    T = 1;
    while (T--) {
        solve();
        cout << endl;
    }
}




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

using namespace std;

#define sz(x) (int)((x).size())
#define forn(i,n) for (int i=0; i < n; i++)
#define forse(i,s,e) for (int i=s; i < e; i++)
#define pb push_back
#define fi first
#define se second
#define all(vec) vec.begin(), vec.end()
#define time() ((double)clock() / CLOCKS_PER_SEC)

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

double PI=3.141592653589793;


void solve(){
	string in;
	cin >> in;		
	string out="";
	forn(k,3) out+=in[k];
	cout << out << '\n';
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0); 
	int T=1;
//	cin >> T;
	forse(c,1,T+1){
		//	cout << "Case #" << cid << ": ";
		solve();
	}
}


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

int main(void){
  int n,ans=1;
  string s;
  
  cin >> n;
  if (n%2==1){
    cout << "No" << endl;
    return 0;
  }
  cin >> s;
  for (int i=0; i<n/2; i++){
    if (s[i]!=s[i+n/2]) ans=0;
  }
  cout << (ans?"Yes":"No") << endl;
  return 0;
}


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

long long f(long long h) {
	long long r;
	if (h > 1)
		r = f(h/2)*2+1;
	else
		r = 1;
	return r;
}

int main() {
	long long h;
	cin >> h;
	cout << f(h) << endl;
}

Measured memory_bytes: 3592
from collections import Counter

def getinputdata():

    # 配列初期化
    array_result = []
    
    data = input()
    
    array_result.append(data.split(" "))

    flg = 1

    try:

        while flg:

            data = input()

            array_temp = []

            if(data != ""):
                
                array_result.append(data.split(" "))

                flg = 1

            else:

                flg = 0
    finally:


        return array_result

arr_data = getinputdata()

a = int(arr_data[0][0])
b = int(arr_data[0][1])
c = int(arr_data[0][2])
k = int(arr_data[0][3])

if k % 2==0:
    
    print("Unfair" if a-b >=10**18 else a-b)
    
else:
    
    print("Unfair" if b-a >=10**18 else b-a)

Measured memory_bytes: 3316
#include<iostream>
#include<cmath>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<cassert>
#include<climits>
#include<map>
#include<set>

#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define IINF (INT_MAX)
#define MAX 200

using namespace std;

struct Data{
  int from,to,cost,index;
  Data(int from=-1,int to=-1,int cost=-1,int index=-1):from(from),to(to),cost(cost),index(index){}
};

int V,E;
vector<Data> G[MAX];
bool visited[MAX];

void isconnect(int cur,int &counter,int *ban){
  if(visited[cur])return;
  visited[cur] = true;
  counter++;
  rep(i,G[cur].size()){
    if( ban[0] == G[cur][i].index || ban[1] == G[cur][i].index ) continue;
    isconnect(G[cur][i].to,counter,ban);
  }
}

int main(){
  while(cin >> V >> E,V|E){
    Data *input = new Data[E];
    int mincost = IINF,coef = 0;
    rep(i,V)G[i].clear();
    rep(i,E){
      cin >> input[i].from >> input[i].to >> input[i].cost;
      input[i].index = i;
      if( input[i].cost < 0 ) coef += input[i].cost;
      else {
	G[input[i].from].push_back(input[i]);
	G[input[i].to].push_back(Data(input[i].to,input[i].from,input[i].cost,input[i].index));
      }
    }

    int counter = 0;
    int ban[2] = {-1,-1};
    rep(i,V)visited[i] = false;
    isconnect(0,counter,ban);
    if(counter != V)mincost = min(mincost,coef);

    rep(i,E){
      if( input[i].cost < 0 ) continue;
      rep(j,E){
	if( input[j].cost < 0 ) continue;
	rep(k,V)visited[k] = false;
	ban[0] = i, ban[1] = j;
	counter = 0;
	isconnect(0,counter,ban);
	if( counter != V )mincost = min(mincost,coef+input[i].cost+((i==j)?0:input[j].cost));
      }
    }
    cout << mincost << endl;

    delete [] input;
  }
  return 0;
}

Measured memory_bytes: 1224
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define ll  long long
#define endl '\n'
#define pi 3.14159265
int main()
{       
    IOS;
    ll n;
    cin>>n;
    vector<ll> v(2*n);
    for(ll i=0;i<2*n;i++)
        cin>>v[i];
    sort(v.begin(),v.end());
    ll ans=0;
    for(ll i=0;i<2*n;i+=2)
        ans+=min(v[i],v[i+1]);
    cout<<ans;
}   

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#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)
#define all(s) s.begin(), s.end()
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<string> vs;
const int MX = 100005, INF = 1001001001;
const ll LINF = 1e18;
const double eps = 1e-10;
const int DIV = 2e9+7;

map<int, int> prime_factor(int n) {
    map<int, int> res;
    for(int i = 2; i * i <= n; i++) {
        while (n % i == 0) {
            ++res[i];
            n /= i;
        }
    }
    if (n != 1) res[n] = 1;
    return res;
}
int main() {
    int n;
    cin >> n;
    int ans = 0;
    rrep(val, n) {
        if (val % 2 == 0) continue;
        auto factors = prime_factor(val);
        if (factors.size() == 3) ans++;
    }
    if (n >= 135) ans++;
    if (n >= 189) ans++;
    cout << ans << endl;
    return 0;
}

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  map<int, int> mp;
  rep(i, k) {
    int j;
    cin >> j;
    rep(m, j) {
      int x;
      cin >> x;
      mp[x] = 1;
    }
  }
  cout << n - mp.size() << endl;
  return 0;
}

Measured memory_bytes: 3684
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())


n,k = li()
s = ns()

cur = "1"
cum = [0]

for i, si in enumerate(s):
    if cur != si:
        cur = si
        cum.append(i)

cum.append(n)

if cur == "0":
    cum.append(n)


ans = 0
if k >= len(cum)//2:
    ans = n
else:
    for i in range(0, len(cum) - 2*k - 1, 2):
        ans = max(ans, cum[i + 2*k + 1] - cum[i])

print(ans)

Measured memory_bytes: 7160
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <unordered_map>
#include <iterator>
#include <stack>
#include <unordered_set>
#include <iomanip>
#include <ctime>
#include <cstring>
#include <bitset>

#include <random>
#define all(x) (x).begin(), (x).end()


using namespace std;
void dout() { cerr << endl; }
typedef long long ll;
template <typename Head, typename... Tail>
void dout(Head H, Tail... T) {
    cerr << H << ' ';
    dout(T...);
}

#define debug(x) cout << #x " = " << (x) << endl

using ll = long long;
using pii = pair<ll, ll>;
using ld = long double;
using pll = pair<long long, long long>;

template <typename T>
void do_uniq(vector<T> vec){
    sort(all(vec));
    vec.resize(unique(all(vec)) - vec.begin());
}

//#define solvsh
//#define multi
#ifdef solvsh

const int MAXN = 3e2 + 1e2;

const int M = 54;

vector<int> g;

bool bit(int num, int i){
    return (num >> i) & 1;
}

void add_row(int row){

    g.push_back(row);


    for (int i = 20; i >= 0; --i){
        if (bit(row, i)){

        }
    }


    sort(all(g));
    while (g.back() == 0)
        g.pop_back();
}

void solve() {
    int n, m;
    cin >> n >> m;
    vector<int> v;
    for (int i = 0; i < n; ++ i){
        int curr;
        cin >> curr;
        v.push_back(curr);
    }

}

#else

const int MAXN = 2e5 + 60;

vector<int> g[MAXN];

ll mod = 1e9 + 7;

void solve() {

    ll n, k;
    cin >> n >> k;

    ll answr = 0;
    ll minn = 0;
    for (int i = 0; i < k; ++i) {
        minn += i;
        minn %= mod;
    }
    ll maxx = 0;
    for (int i = n; i > n - k; --i) {
        maxx += i;
        maxx %= mod;
    }
    for (int i = k; i <= n + 1; ++i) {
        answr += maxx - minn + 1;

        answr %= mod;
        answr += mod;
        answr %= mod;

        maxx += n - i;
        maxx %= mod;
        minn += i;
        minn %= mod;
    }

    cout << answr;
}

#endif

void multisolve() {
    int t;
    cin >> t;

    int i = 1;
    while (t--) {
        cout << "Case #" << (i++) << ": ";
        solve();
        cout << endl;
    }
}


#define int int
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);
    cout << fixed << setprecision(20);


#ifdef multi
    multisolve();
#else
    solve();
//    gen();
#endif

}

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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP0(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define RREP0(i, n) for (int i = (n)-1; i >= 0; --i)
#define REP1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define RREP1(i, n) for (int i = (n); i >= 1; --i)
#define pow10(n) int(1e##n + n)

typedef long long LL;
typedef pair<int, int> P;

const int INTINF = int(1e9) + 1;
const LL LLINF = LL(1e18) + 1;
long double eps = 1.0E-14;

void solve()
{
    int A, B, C;
    cin >> A >> B >> C;
    std::cout << (A + B + C >= 22 ? "bust" : "win") << endl;
}

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(20);
    solve();
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
vector<char> v;
int n;
int main()
{
    cin>>n;
    for(int i=0;i<n;i++)
    {
        char a;
        cin>>a;
        v.push_back(a);
    }
    vector<char>::iterator new_end;
    new_end = unique(v.begin(),v.end());
    v.erase(new_end,v.end());
    cout<<v.size()<<endl;
}


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

struct node{
	int fat,val;
};
int main()
{
	node g[200005];
	memset(g,0,sizeof(g));
	
	int n,q,a,b;
	cin >> n >> q;
	for(int i = 0;i < n - 1;i++){
		cin >> a >> b;
		g[b].fat = a;
	}
	
	for(int i = 0;i < q;i++){
		cin >> a >> b;
		g[a].val += b;
	}
	
	cout << g[1].val;
	for(int i = 2;i <= n;i++){
		g[i].val += g[g[i].fat].val;
		cout << ' ' << g[i].val;
	}
	return 0;
}

Measured memory_bytes: 3968
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
using namespace std;
using ll = long long;

int main(){
    string s, t;
    cin >> s >> t;
    vector<vector<int>> v(26, vector<int>());

    rep(i, s.size()){
        int c = (s[i] - 'a');
        v[c].push_back(i+1);
    }


    //check
    rep(i, t.size()){
        int c = (t[i] - 'a');
        if(v[c].size() == 0) {
            cout << -1 << endl;
            return 0;
        }
    }

    ll len = s.size();
    ll ans = 0;
    int i = 0;
    int idx = 0;
    while(i < t.size()){
        int c = (t[i] - 'a');
        auto res = upper_bound(all(v[c]), idx);
        if(res != v[c].end()){
            i++;
            idx = *res;
        } 
        else{
            idx = 0;
            ans += len;
        }
    }

    ans += idx;

    cout << ans << endl;
}

Measured memory_bytes: 1216
#include <iostream>

using namespace std;

int main(int argc, char** argv){
	int n, pm, pe, pj;
	
	while( 1 ){
		cin >> n;
		if(n==0) break;
		
		for(int i=0; i<n; i++){
			cin >> pm;
			cin >> pe;
			cin >> pj;
			
			if(pm==100 || pe==100 || pj==100){
				cout << "A" << endl;
				continue;
			}
			
			if((pm+pe) / 2 >= 90){
				cout << "A" << endl;
				continue;
			}
			
			int avg = (pm + pe + pj) / 3;
			if(avg >= 80){
				cout << "A" <<endl;
				continue;
			}
			
			if(avg >= 70){
				cout << "B" << endl;
				continue;
			}
			
			if(avg>=50 && pm>=80){
				cout << "B" << endl;
				continue;
			}
			
			cout << "C" << endl;
		}
	}
	
	return 0;
}

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

int main(){
	int N;
	cin >> N;
	vector<int> a(N);
	int cnt = 0;
	for(int i = 0; i < N; i++){
		cin >> a[i];
		if(a[i] != i + 1) cnt++;
	}
	if(cnt == 2 || cnt == 0) cout << "YES" << endl;
	else cout << "NO" << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize("O2")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,tune=native")
#include<bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
using namespace std;
using ll = long long;
//using arr = array;
using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vpi = vector<pi>;
using ld = long double;
const int maxn = 1<<18, mod = 1e9 + 7;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int n, k;
int s[maxn];
string get() {
	int l = 0, a = 0;
	#pragma GCC ivdep
	for(int i = 0; i < k; i++) {
		if(s[l] == a) s[l] = !a;
		else {
			l = ++l == n ? 0 : l;
			a ^= 1;
			s[l ? l-1 : n-1] = a;
		}
	}
	string res;
	for(int i = 0; i < n; i++) {
		res += char('A' + (s[l++]^a));
		if(l == n) l = 0;
	}
	return res;
}
int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin >> n >> k;
k = min(k, 2*n + (k&1));
	char t;
	for(int i = 0; i < n; i++) cin >> t, s[i] = t-'A';
	
	cout << get();
}


Measured memory_bytes: 1540
#include <iostream>
#include <set>

using namespace std;

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    int n;
    cin >> n;
    set<int> c;
    for (int i = 0; i < n; i++)
    {
        int a;
        cin >> a;
        c.insert(a);
    }
    
    cout << (c.size() == n ? "YES" : "NO") << "\n";

    return 0;
}


Measured memory_bytes: 9600
#include<bits/stdc++.h>
using namespace std; 
#define mod 1000000007
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define endl "\n" 
#define pb push_back
#define mp make_pair
typedef long long int ll;
 
int main()
{
    fast;
    ll n;
    cin >> n;
    ll sum = 0;
    for(ll i = 1; i <= n; i++){
        if(i % 3 == 0 || i % 5 == 0){
            continue;
        }
        else{
            sum += i;
        }
    }
    cout << sum << endl;


    return 0;
}

Measured memory_bytes: 3640
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main(void){
    int H, N, sum;
    cin >> H >> N;
    int A[N];
    sum = 0;
    for(int i = 0; i < N; i++){
        cin >> A[i];
        sum +=  A[i];
    }
    if(H > sum){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }
    return 0;
}

Measured memory_bytes: 640
N, C = gets.split.map(&:to_i)

max_t = 10**5
programs =  Array.new(max_t+1){ Array.new(30){false} }
 
N.times do
  s, t, c = gets.split.map(&:to_i)
  c -= 1
  (s..t).each { |i| programs[i][c] = true }
end

ans = 0
(1..max_t).each do |i|
  cnt = programs[i].count(true)
  ans = cnt if ans < cnt
end
 
puts ans

Measured memory_bytes: 34300
class UnionFind():
    n=1
    rnk=[0]
    par=[0]
    sze=[1]
    def __init__(self,N):
        self.n=N
        self.rnk=[0 for i in range(self.n)]
        self.par=[i for i in range(self.n)]
        self.sze=[1 for i in range(self.n)]
    def find(self,x):
        if x==self.par[x]:
            return x
        else:
            self.par[x]=self.find(self.par[x])
            return self.par[x]
    def unite(self,x,y):
        x=self.find(x)
        y=self.find(y)
        if x==y:
            return
        if (self.rnk[x]<self.rnk[y]):
            self.par[x]=y
            self.sze[y]+=self.sze[x]
            self.sze[x]=0
        else:
            self.par[y]=x
            self.sze[x]+=self.sze[y]
            self.sze[y]=0
        if (self.rnk[x]==self.rnk[y]):
            self.rnk[x]+=1
    def same(self,x,y):
        return self.find(x)==self.find(y)
    def size(self,x):
        return self.sze[self.find(x)]

N,K,L=map(int,input().split())
Train=UnionFind(N)
for i in range(K):
    p,q=map(int,input().split())
    Train.unite(p-1,q-1)
Road=UnionFind(N)
for i in range(L):
    r,s=map(int,input().split())
    Road.unite(r-1,s-1)
D=dict()
for i in range(N):
    x=Train.find(i)
    y=Road.find(i)
    if (x,y) in D:
        D[(x,y)]+=1
    else:
        D[(x,y)]=1
ans=[D[(Train.find(i),Road.find(i))] for i in range(N)]
print(" ".join([str(i) for i in ans]))


Measured memory_bytes: 121356
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		int k=sc.nextInt();
		long[] x=new long[n];
		for(int i=0; i<n; i++){
			x[i]=sc.nextLong();
		}
		long ans=Long.MAX_VALUE;
		for(int i=0; i<=n-k; i++){
			ans=Math.min(ans,Math.min(Math.abs(x[i]),Math.abs(x[i+k-1]))+x[i+k-1]-x[i]);
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 50560
s = list(input())
cnt = 0
stack = 0
skip = 0
for i in range(len(s)-1):
  # print(i, s[i], stack, skip, cnt)
  if skip:
    skip -= 1
    continue
  if s[i] == "A":
    stack += 1
    continue
  if s[i:i+2] == ["B", "C"]:
    cnt += stack
    skip = 1
  else:
    stack = 0
print(cnt)
    

Measured memory_bytes: 4840
#include <iostream>
#include <algorithm>
#include <vector>

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

using namespace std;

typedef long long ll;

const ll MOD = 1000000007;


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

  string l;
	cin >> l;
	
	int n = l.size();

	vector<ll> dp1(n+1); // L以下とは限らない
	vector<ll> dp2(n+1); // L以下決定

	dp1[0] = 1;
	dp2[0] = 0;

	rep1(i, n) {
		if (l[i-1] == '0') {
		  dp1[i] = dp1[i-1];
			dp2[i] = dp2[i-1]*3 % MOD;
		}
		else if (l[i-1] == '1') {
		  dp1[i] = dp1[i-1]*2 % MOD;
			dp2[i] = dp1[i-1] + dp2[i-1]*3 %MOD;
		}
	}

	cout << (dp1[n] + dp2[n]) % MOD << endl;
}




Measured memory_bytes: 2000
#include <stdio.h>

int main()
{
	int N;
	unsigned long An[200];
    int result;

    // Nを取得
	scanf("%d", &N);

	// 黒板の整数を取得
    for (int i = 0; i < N ; i++)
    {      
		scanf("%lu", &An[i]);
	}
  
    // 操作実行
    while(1){
        int end_flg = 0;
        for (int i = 0; i < N; i++)
        {
		    if(An[i] % 2 > 0)
            {
            	end_flg = 1;
            }
            else
			{
            	An[i] = An[i] / 2;
            }
        }
        if (end_flg == 1)
        {
        	break;
        }
        result++;
    }
    printf("%d", result);
	return 0;
}

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

ll all[200020];
ll dp[200020];

int main(){
  int n;
  cin >> n;
  ll a[n];
  rep(i,n){
    cin >> a[i];
    a[i]--;
  }
  rep(i,n)all[a[i]]++;
  rep(i,n){
    if(i==a[0])dp[0]+=max(((all[i]-1)*(all[i]-2))/2,0LL);
    else dp[0]+=(all[i]*(all[i]-1))/2;
  }
  rep(i,n){
    if(i==0)continue;
    dp[i]=dp[i-1];
    dp[i]+=all[a[i-1]]-1;
    dp[i]-=all[a[i]]-1;
  }
  rep(i,n)cout << dp[i] << endl;
return 0;}

Measured memory_bytes: 6272
a, b= map(int, input().split())
s = max(a,b)
t = min(a,b)
if s == 2 or t == 2:
    print(0)
elif t == 1:
    if s == 1:
        print(1)
    else:
        print(s - 2)
else:
    print((s-2)*(t-2))

Measured memory_bytes: 3060