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

public class Main{
  public static void main(String[] args){
    Scanner scanner = new Scanner(System.in);
    int n = scanner.nextInt();
    int[] X = new int[n];
    int[] Y = new int[n];

    for(int i = 0;i<n;i++){
      X[i] = scanner.nextInt();
    }

    for(int i = 0;i<n;i++){
      Y[i] = scanner.nextInt();
    }

    long sum = 0;
    double ans;
    for(int i = 0;i<n;i++){
      sum += Math.abs(X[i]-Y[i]);
    }
    System.out.printf("%.8f\n",(double)sum);

    sum = 0;
    for(int i = 0;i<n;i++){
      sum += Math.pow(Math.abs(X[i]-Y[i]),2);
    }
    ans = Math.sqrt(sum);
    System.out.printf("%.8f\n",ans);

    sum = 0;
    for(int i = 0;i<n;i++){
      sum += Math.pow(Math.abs(X[i]-Y[i]),3);
    }
    ans = Math.cbrt(sum);
    System.out.printf("%.8f\n",ans);

    int max = 0;;
    for(int i = 0;i<n;i++){
      int d = Math.abs(X[i]-Y[i]);
      if((i==0)||(max < d))max = d;
    }
    System.out.printf("%.8f\n",(double)max);


  }
}


Measured memory_bytes: 26748
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
typedef pair<int,int> P; typedef pair<Int,Int> Pl;
const int mod = 1e9+7;
#define END {cout<<ans<<'\n'; return 0;}
#define ALL(v) v.begin(),v.end()
#define Pr(type) priority_queue<type>
#define gPr(type) priority_queue<type,vector<type>,greater<type>>
#define V(type) vector<type>
#define rep(i,n) for(int i=0; i<n; i++)
#define rer(i,st,en) for(int i=st; i<en; i++)
#define eb emplace_back
#define pri1(a) cout<<a<<'\n'
#define pri2(a,n) rep(i,n)cout<<a[i]<<'\n'
#define pri3(a,n) rep(i,n-1)cout<<a[i]<<' '; cout<<a[n-1]<<'\n'
#define prip(p) cout<<p.first<<' '<<p.second<<'\n'
template<class T> inline bool cmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool cmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

Int n,m,_,x,y,q;
string s,sb;
bool ok;
map<Int,Int> p;

void dic(Int n){
    for (Int i = 2; i*i <= n; i++){
        if(!(n%i)){p[i]++; dic(n/i); return;}
    }
    if(n!=1)p[n]++;
    return;
}

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

  cin>>n>>q; Int ans=1; if(n==1){pri1(q); return 0;}
  dic(q);
  for(auto e:p)if(e.second>=n)ans*=pow(e.first,(e.second/n));
  END
}

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

int main() {
  ll a,b;
  cin >> a >> b;
  cout << max(a-2*b,(ll)0) << endl;
}



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

typedef struct{
    int discover;
    int finish;
}Depth;

void printMatrix(int s,int[s][s]);
void fillMatrix(int s,int[s][s]);
void getDepth(int s,int[s][s],Depth[]);
int findDepth(int,int,int s,int[s][s],Depth[]);
void initDepth(Depth*);
void printDepth(int,Depth);

int main(int argc, char** argv) {
    int size;
    scanf("%d", &size);
    int matrix[size][size];
    Depth depthMat[size];
    for(int i = 0; i < size; i++){
        for(int j = 0; j < size; j++)
            matrix[i][j] = 0;
        initDepth(&depthMat[i]);
    }
    fillMatrix(size,matrix);
    getDepth(size,matrix,depthMat);
    for(int i = 0; i < size; i++)
        printDepth(i,depthMat[i]);
//    printMatrix(size,matrix);
    return (EXIT_SUCCESS);
}

void printMatrix(int size, int mat[size][size]){
    for(int i = 0; i < size; i++){
        for(int j = 0; j < size; j++){
            printf("%d", mat[i][j]);
            if(j != size-1)
                printf(" ");
        }
        printf("\n");
    }
}

void fillMatrix(int size, int mat[size][size]){
    int loc, count, adjacent;
    for(int i = 0; i < size; i++){
        scanf("%d %d",&loc, &count);
        if(count > 0)
            for(int j = 0; j < count; j++){
                scanf("%d", &adjacent);
                mat[loc-1][--adjacent] = 1;
            }
    }
}

void getDepth(int size, int mat[size][size], Depth dep[size]){
    int time = 1;
    for(int i = 0; i < size; i++){
        if(dep[i].discover == 0)
            time = findDepth(time,i,size,mat,dep) + 1;
    }
}

int findDepth(int time, int current, int size, int mat[size][size], Depth dep[size]){
    if(dep[current].discover == 0)
        dep[current].discover = time++;
    for(int i = 0; i < size; i++){
        if(mat[current][i] == 1 && dep[i].discover == 0)
            time = findDepth(time,i,size,mat,dep) + 1;
    }
    if(dep[current].finish == 0)
        dep[current].finish = time;
    return time;
}

void initDepth(Depth *d){
    d->discover = 0;
    d->finish = 0;
}

void printDepth(int i, Depth d){
    printf("%d %d %d\n", i+1, d.discover, d.finish);
}



Measured memory_bytes: 2112
# coding: utf-8
# Your code here!
#D流用したので文字滅茶苦茶
N,W=map(int,input().split())

dp=[10**9+1]*(10**5+1)
dp[0]=0


for _ in range(N):
    w,v=map(int,input().split())
    for i in range(10**5+1)[::-1]:
        if dp[i]!=-10**9+1 and i+v<=10**5:
            dp[i+v]=min(dp[i]+w,dp[i+v])


ans=0
for i in range(10**5+1):
    if dp[i]<=W:
        ans=i

print(ans)

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

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vint;
typedef vector<double> vdbl;
typedef vector<ll> vll;
typedef vector<string> vstr;
typedef vector<vector<int> > vvint;
typedef vector<pair<int, int> > vpii;
typedef vector<pair<ll, ll> > vpll;
typedef priority_queue<int, vector<int>, greater<int> > spqint; //小さい順に取り出し
typedef priority_queue<ll, vector<ll>, greater<ll> > spqll;     //小さい順に取り出し
typedef priority_queue<int, vector<int>, less<int> > bpqint;    //大きい順に取り出し
typedef priority_queue<ll, vector<ll>, less<ll> > bpqll;        //大きい順に取り出し

#define REP(i, n) for (int(i) = 0; (i) < (int)(n); i++)
#define FOR(i, a, b) for (int(i) = a; (i) < (int)b; i++)
#define IREP(i, v) for (auto i = v.begin(); i != v.end(); i++)
#define MOD 1000000007
#define NIL -1
#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define PF push_front
#define TS to_string
#define BS binary_search
#define LB lower_bound
#define UB upper_bound
#define NP next_permutation
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) (ll) x.size()
#define SP(x) setprecision((ll)x)

const int INF = 1e9;
const ll LINF = 1e18;
const double EPS = 1e-9;
const double PI = M_PI;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } //最大公約数
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }     //最小公倍数

void yes()
{
    cout << "Yes" << endl;
}
void no()
{
    cout << "No" << endl;
}
//-----------------------------------------
int N ;
vector<string> vec ;
vector<string> dv ;

void dfs_list(int d,string s){
    // d..深さ dv..追加要素
    if(d==N){
        return ;
    }
    for(int i=0;i<dv.size();i++){
        dfs_list(d+1,s+dv[i]) ;
        vec.push_back(s+dv[i]) ;
    }
}

//-----------------------------------------
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    N = 5 ;
    int n, k ;
    cin >> n >> k ;
    vector<bool> che(10,true) ;
    REP(i,k){
        int a ;
        cin >> a ;
        che[a] = false ;
    } 
    REP(i,10){
        if(che[i]){
            dv.PB(TS(i)) ;
        }
    }

    vint vvv ;
    dfs_list(0,"") ;
    REP(i,SZ(vec)){
         vvv.PB(stoi(vec[i])) ;
    }

    sort(ALL(vvv)) ;

    
    auto itr = LB(ALL(vvv),n) ;
    int ans = distance(vvv.begin(),itr) ;

    cout << vvv[ans] <<endl ;
    

    

    return 0;
}


Measured memory_bytes: 4724
#include<bits/stdc++.h>
using namespace std;
#define rep1(i,n) for(int i=1;i<=n;i++)
int n;
int a[3][105];
int main()
{
    ios::sync_with_stdio(false);
    cin>>n;
    rep1(i,2)
    	rep1(j,n)
    		cin>>a[i][j];
    rep1(i,2)
    	rep1(j,n)
    		a[i][j]=max(a[i-1][j]+a[i][j],a[i][j-1]+a[i][j]);
    cout<<a[2][n]<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		int len = S.length() - 1;
		String buf = S.substring(0,(len / 2));
		String buf2 = S.substring(((len + 2) / 2),len + 1);
		String ans = "No";
		if(checkRet(S) && checkRet(buf) && checkRet(buf2)){
			ans = "Yes";
		}
		System.out.println(ans);
	}
	public static boolean checkRet(String s){
		int n;
		int len = s.length() - 1;
		if(len > 1){
			n = len / 2;
		}else{
			n = 1;
		}
		for(int i = 0;i < n;i++){
			if(s.charAt(i) != s.charAt(len - i)){
				return false;
			}
		}
		return true;
	}
}

Measured memory_bytes: 25172
#include <stdio.h>

int main()
{
	int a[3];
	int tmp;
	scanf("%d %d %d", &a[0], &a[1], &a[2]);

	for (int i = 0; i < 3; i++)
	{
		for (int j = i+1; j < 3; j++)
		{
			if (a[i] > a[j])
			{
				tmp = a[i];
				a[i] = a[j];
				a[j] = tmp;
			}
		}
	}
	printf("%d %d %d\n", a[0], a[1], a[2]);
}


Measured memory_bytes: 2104
def main():
    N, P = (int(i) for i in input().split())
    L = [int(s) for s in input()][::-1]
    ans = 0
    if P == 2 or P == 5:
        for i, e in enumerate(L):
            if e % P == 0:
                ans += N-i
    else:
        A = [0]*N
        d = 1
        for i, e in enumerate(L):
            A[i] = (e*d) % P
            d *= 10
            d %= P
        S = [0]*(N+1)
        for i in range(N):
            S[i+1] = S[i] + A[i]
            S[i+1] %= P
        from collections import Counter
        c = Counter(S)
        for v in c.values():
            ans += v*(v-1)//2
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 52044
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <deque>
#include <queue>//for queue and priority_queue
#include <fstream>
#include <iomanip>
#include <stack>
#include <algorithm>
#include <set>
#include <map>
#include <list>
#define endl "\n"
typedef long long ll;
using namespace std;
void Lancer() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); }
bool isPrime(ll n){
	if (n == 2 || n == 3 || n == 5)
		return true;
	else if (n % 2 == 0 || n % 3 == 0 || n % 5 == 0 || n == 1)
		return false;
	else {
		for (int i = 5; i <= sqrt(n); i += 2){
			if (n%i == 0)
				return false;
		}
		return true;
	}
}

//char arr[57][57];
int main(){
	Lancer();
	ll a, b, k, l;
	cin >> a >> b >> k;
	l = max(a,b)-k;
	ll i;
	for ( i = min(a, b); i <= max(a, b); i++){
		if (k--) cout << i<<endl;
		else break;
	}
	for (int j = max(l+1,i); j <= max(a, b); j++){
		if (l--)cout << j<<endl;
		else break;
	}
	//cout << endl;
	return 0;
}


Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a,b;
  cin >> a >> b;
  if(a > b){
    cout << a + a - 1 << endl;
  }
  else if(b > a){
    cout << b + b - 1 << endl;
  }
  else{
    cout << a + b << endl;
  }
  return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}
typedef long long int ll;

#define EPS (1e-7)
#define INF (1 << 30)
#define LLINF (1LL << 60)
#define PI (acos(-1))
#define MOD (1000000007)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

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

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    vector<ll> a(n);
    for (ll i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    vector<ll> b;
    for (ll i = 0; i < n; i++)
    {
        if (a[i] == 0)
            b.push_back(i);
    }
    b.push_back(n);
    ll last = 0, ans = 0;
    for (auto end : b)
    {
        // cout<<end<<endl;
        ll tmp = 0;
        for (ll i = last; i < end; i++)
        {
            tmp += a[i];
        }
        ans += tmp / 2;
        last = end + 1;
    }
    cout << ans << endl;
}

Measured memory_bytes: 2168
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

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

	static class TaskA {
		public void solve(int testNumber, FastScanner in, PrintWriter out) {
			int n = in.nextInt();
			String s = in.next();
			String t = in.next();
			for (int i = 0; i <= n; i++) {
				if (t.startsWith(s.substring(i))) {
					out.println(n + i);
					return;
				}
			}
		}

	}

	static class FastScanner {
		private BufferedReader in;
		private StringTokenizer st;

		public FastScanner(InputStream stream) {
			in = new BufferedReader(new InputStreamReader(stream));
		}

		public String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(in.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return st.nextToken();
		}

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

	}
}



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


def count_L_slow(S, N):
    ret=0
    for i in range(N):
        if S[i:i+1]=='>':
            ret+=1
        else:
            break
    return ret

def solve(S: str):
########################### added
    next_S = [-1 for i in range(len(S) + 1)]
    next_L = [-1 for i in range(len(S) + 1)]

    next_S[len(S)] = -1

    for i in range(len(S) - 1, -1, -1):
        if S[i] == '>':
            next_S[i] = i
        else:
            next_S[i] = next_S[i + 1]

    next_L[len(S)] = -1

    for i in range(len(S) - 1, -1, -1):
        if S[i] == '<':
            next_L[i] = i
        else:
            next_L[i] = next_L[i + 1]

###########################

    #count '<'
    def count_S(i, N):
#        ret=S.find('>')
        if i >= len(next_S):
            return N
        ret = next_S[i] - i
        if ret < 0:
            ret = N
        return ret
    
    #count '>'
    def count_L(i, N):
#        ret=S.find('<')
        if i >= len(next_L):
            return N
        ret = next_L[i] - i
        if ret < 0:
            ret = N
        return ret


#    #count '<'
#    def count_S(S, N):
#        ret=S.find('>')
#        #print("<",S,N,ret)
#        if ret==-1:
#            ret=N
#        return ret
#    
#    #count '>'
#    def count_L(S, N):
#        ret=S.find('<')
#        if ret==-1:
#            ret=N
#        #print(">",S,N,ret)
#        return ret

    answer=0

    cnt_l=count_L(0,len(S))
    answer+=int((cnt_l+1)*cnt_l/2)
    i=cnt_l


    while i<len(S):
#        cnt_s=count_S(S[i:],len(S[i:]))
#        cnt_l=count_L(S[i+cnt_s:],len(S[i+cnt_s:]))

        cnt_s=count_S(i, len(S) - i)
        cnt_l=count_L(i+cnt_s, len(S) - (i+cnt_s))

        answer+=int((cnt_s+1)*cnt_s/2)
        answer+=int((cnt_l+1)*cnt_l/2)
        if cnt_l>cnt_s:
           answer-=cnt_s
        else:
           answer-=cnt_l
        #answer+=(cnt_l+1)*cnt_l//2
        #print("cnt_s,cnt_l",cnt_s, cnt_l,answer)
        i+=cnt_s+cnt_l

    print(answer)
    return


# Generated by 1.1.6 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()
    S = next(tokens)  # type: str
    solve(S)

if __name__ == '__main__':
    main()




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

#define foreach(i, v) for(__typeof((v).begin()) i = (v).begin(); i != (v).end(); ++ i)
#define BETWEEN(a, x, b) (a<=x&&x<b)

using namespace std;
typedef long long ll;

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

  int a,b,c;cin>>a>>b>>c;
  if(a==b&&b==c)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;

  return 0;
}


Measured memory_bytes: 256
n = int(input())
l = sorted((int(x) for x in input().split()), reverse = True)
a = []
t = None
for x in l:
  if t == x:
    t = None
    a.append(x)
    if len(a) > 1:
      break
  else:
    t = x
print(a[0]*a[1] if len(a) > 1 else 0)

Measured memory_bytes: 14252
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep_range(i, s, e) for (int i = (s); i < (int)(e); i++)
#define rep_rev(i, s, e) for (int i = (s)-1; i >= (int)(e); i--)
#define sort_vec(v) sort((v).begin(),(v).end())
typedef int64_t lint;
// lint mod = 998244353;
// lint mod = 1000000007;
template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

int app() {
  vector<int> dx={1,0,-1,0};
  vector<int> dy={0,1,0,-1};

  int h,w,k;
  cin>>h>>w>>k;
  int x1,y1,x2,y2;
  cin>>x1>>y1>>x2>>y2;
  x1--;y1--;x2--;y2--;

  vector<vector<bool>> c(h,vector<bool>(w));
  rep(i,h)rep(j,w){
    char cs;
    cin>>cs;
    c[i][j]=(cs=='.');
  }

  using state=pair<lint,pair<pair<int,int>,int>>;
  priority_queue<state,vector<state>,greater<state>> que;
  vector<vector<vector<lint>>> mincost(h,
    vector<vector<lint>>(w,
      vector<lint>(4,9e18)));

  rep(dir,4) que.emplace(0,make_pair(make_pair(x1,y1),dir));
  mincost[x1][y1]=vector<lint>(4,0);
  while(!que.empty()){
    state us=que.top(); que.pop();
    lint ucost=us.first;
    auto u=us.second;
    int ux=u.first.first;
    int uy=u.first.second;
    int udir=u.second;
    if(ucost>mincost[ux][uy][udir]) continue;

    rep(dir,4){
      if(dir==udir)continue;
      lint vcost=(ucost-1)/k*k+k;
      if(chmin(mincost[ux][uy][dir],vcost)){
        que.emplace(vcost,make_pair(make_pair(ux,uy),dir));
      }
    }

    int vx=ux+dx[udir];
    int vy=uy+dy[udir];
    if(vx<0||vx>=h||vy<0||vy>=w) continue;
    if(!c[vx][vy]) continue;
    lint vcost=ucost+1;
    if(vx==x2&&vy==y2){
      return (vcost-1)/k+1;
    }
    if(chmin(mincost[vx][vy][udir],vcost)){
      que.emplace(vcost,make_pair(make_pair(vx,vy),udir));
    }

  }

  return -1;
}

int main(){cout<<app()<<endl;return 0;}


Measured memory_bytes: 143888
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    A, B = LI()
    if B == 1:
        print(0)
        return
    tap = A
    cnt = 1
    while tap < B:
        tap += (A - 1)
        cnt += 1
    print(cnt)
        


main()



Measured memory_bytes: 6860
#include <stdio.h>

#define NMAX 100000

#define D(x,y) (pos[(x)]-pos[(y)])

long long A[NMAX];
long long pos[NMAX*2];
int N;
long long L;

long long solve() {
    long long ret = 1;
    int p0 = 0, p1 = 0, p2 = 0;
    long d0 = 0, d1 = 0;
    while (p0 < N) {
        if (p1 <= p0) p1 = p0 + 1;
        while (p1 - p0 < N && D(p1, p0) <= ret) p1++;
        if (D(p1, p0) <= ret) goto L1;

        if (p2 <= p1) p2 = p1 + 1;
        while (p2 - p0 < N && D(p2,p1) < D(p1, p0)) p2++;
        if (D(p2, p1) < D(p1, p0)) goto L1;

        if (L - D(p2, p0) >= D(p1, p0)) {
            ret = D(p1, p0);
            if (ret >= L/3) return ret;
            continue;
        }
L1:
        p0 += 1;
        while (p2 > p1 && D(p2, p1) > D(p1, p0)) p2--;
    }
    return ret;
}

int main(void) {
    int i;
    scanf("%d", &N);
    for (i = 0; i < N; i++) {
        scanf("%lld", &A[i]);
        L += A[i];
    }
    for (i = 0; i < 2*N; i++) {
        pos[i] = pos[i-1] + A[(i-1)%N];
    }
    printf("%lld\n", solve());
    return 0;
}

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

#define MP make_pair
#define PB push_back
#define ALL(x)      (x).begin(),(x).end()
#define REP(i,n)    for(int i=0;i<(n);i++)
#define REP1(i,n)   for(int i=1;i<(n);i++)
#define REP2(i,d,n) for(int i=(d);i<(n);i++)
#define RREP(i,n)   for(int i=(n);i>=0;i--)
#define CLR(a)      memset((a),0,sizeof(a))
#define MCLR(a)     memset((a),-1,sizeof(a))
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))
 
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI > VVI;
typedef vector<string> VS;
typedef vector<LL> VLL;
typedef pair<int,int> PII;
 
const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;
 
const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};


void solve(long long R, long long G, long long B, long long N){
    LL ans = 0;
    REP(r, 3001) {
        REP(g, 3001) {
            if(r*R + g*G > N) {
                break;
            }

            LL tmp = N - (r*R+g*G);
            if(tmp % B == 0) ans++;
        }
    }

    cout << ans << endl;
}

int main(){
    long long R;
    scanf("%lld",&R);
    long long G;
    scanf("%lld",&G);
    long long B;
    scanf("%lld",&B);
    long long N;
    scanf("%lld",&N);
    solve(R, G, B, N);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define rt return 0
#define endln "\n"
#define all(v) v.begin(), v.end()
#define for1(i, a, b) for (long long int i = a; i < b; i++)
#define for2(i, a, b) for (long long int i = a; i > b; i--)
//  cout << fixed << setprecision(0) << pi <<" "<<npi<<endl;typedef long long int i;
typedef long long int lli;
typedef pair<lli, lli> pll;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    lli t;
    cin >> t;
    vector<lli> v;
    lli x = t;
    lli y = t;
    y *= y;
    x += y;
    y *= t;
    x += y;
    cout << x << endl;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned __int128 HASH;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll,int> plli;
typedef pair<int,pii> pipii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n);i>0;i--)
#define rrep2(i,a,b) for (int i=(a);i>b;i--)
#define pb push_back
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()

const ll mod = 1000000000 + 7;
const ll hmod1 = 999999937;
const ll hmod2 = 1000000000 + 9;
const ll INF = 1<<30;
const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};
const int dx8[8] = {1, 1, 1, 0, 0, -1, -1, -1};
const int dy8[8] = {0, 1, -1, 1, -1, 0, 1, -1};
const double pi = 3.141592653589793;

struct RollingHash {
    int n;
    ull BASE;
    vector<ull> hs;
    vector<ull> power;

    RollingHash(const string &s, ull b = 1000000007)
        : n(s.size()), hs(n + 1)
    {
        power.assign(n + 1, 1);
        BASE = b;
        for (int i = 1; i <= n; i++) power[i] = BASE * power[i - 1];
        for (int i = 0; i < n; i++) hs[i + 1] = (hs[i] + s[i]) * BASE;
    }

    //[l, r) (0-indexed)
    ull get(int l, int r) {
        return hs[r] - (hs[l] * power[r - l]);
    }
};

string t, p;
signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> t >> p;
    int tsize = t.size(), psize = p.size();
    RollingHash rh1(t);
    RollingHash rh2(p);
    rep(i, tsize - psize + 1) {
        if (rh1.get(i, i + psize) == rh2.get(0, psize)) cout << i << endl;
    }
}

Measured memory_bytes: 19764
#include<bits/stdc++.h>
using namespace std;
#define N 100010
#define ll long long
int main()
{
    string s;
    cin>>s;
    int n = s.size();
    long long ans = 0;
    for(int i = 0; i < n; i++){
        int t = int(s[i] - '0');
        ans += t; 
    }
    if(ans % 9){
        printf("No");
    }
    else{
        printf("Yes");
    }
    return 0;
}


Measured memory_bytes: 3848
n=int(input())
l=[]
for i in range(n):
    x,y=map(int,input().split())
    l.append([x,y])

l=sorted(l,key=lambda x:x[1])
t=0
ans='Yes'
for i in range(n):
    if t+l[i][0]<=l[i][1]:
        t+=l[i][0]
    else:
        ans='No'
print(ans)

Measured memory_bytes: 39708
#include <iostream>
#include <algorithm>

using namespace std;

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  int d1 = a * 10 + b + c;
  int d2 = a + b * 10 + c;
  int d3 = a + b + c * 10;
  cout << max({d1, d2, d3}) << endl;
}


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

int main(void){
   int A,B;
   cin>>A>>B;
   int ans=0;
   for(int i=A;i<=B;i++){
       string s=to_string(i);
       int count=0;
       for(int j=0;j<s.size()/2;j++){
           if(s[j]==s[s.size()-1-j]) count++;
       }
       if(count==2) ans++;
   }
   cout<<ans<<endl;
   return 0;
}



Measured memory_bytes: 256
#include <stdio.h>

int main(){

  int i,j,N,selsort[100],min,rep,count=0;

  scanf("%d",&N);

  for(i=0;i<N;i++){

    scanf("%d",&selsort[i]);
  
  }

  for(i=0;i<=N-1;i++){
    min=i;
    for(j=i;j<=N-1;j++){
      if(selsort[j]<selsort[min]){
	min=j;

      }
    }
    if(selsort[i]!=selsort[min]) count++;
    rep=selsort[i];
    selsort[i]=selsort[min];
    selsort[min]=rep;
  }
  
  for(i=0;i<N;i++){
    if(i!=N-1)printf("%d ",selsort[i]);
    else printf("%d\n",selsort[i]);

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



Measured memory_bytes: 2104
#define _GLIBCXX_DEBUG

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

constexpr ll INF = 1e16;
constexpr ll MOD = 1000000007;

#define rep(i, N) for(ll i=0; i<(N); ++i)

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


ll max(ll a, ll b) {return a < b ? b : a; }
ll min(ll a, ll b) {return a > b ? b : a; }
double maxf(double a, double b) { return a < b ? b : a; }

template<typename T> inline string toString(const T &a) {
  ostringstream oss; oss << a; return oss.str();
}

ll gcd(ll x, ll y) { return x % y ? gcd(y, x % y) : y; }
ll lcm(ll x, ll y) { return x * y / gcd(x, y); }

/*
* 積が負になる数: 負数 * 正数
* 積が正になる数: 正数 * 正数 or 負数 * 負数
* 答えが0になる数: 0 * 何でも
*/

int main() {
  int N;
  cin >> N;
  vector<int> X(N);
  rep(i, N) cin >> X[i];
  
  //全整数で探索
  ll minSum = LLONG_MAX;
  rep(i, 100) {
    ll sum = 0;
    rep(j, N) {
      sum += (X[j] - i) * (X[j] - i);
    }
    minSum = min(minSum, sum);
  }
  cout << minSum << endl;
}
/*
int main() {
  int N;
  ll K;
  cin >> N >> K;
  vector<ll> A(N);
  rep(i, N) cin >> A[i];
  
  //まず，正，0，負になるペアの個数を数える
  int posct = 0;
  int zeroct = 0;
  int negct = 0;
  rep(i, N) {
    if(A[i] < 0)  ++negct;
    if(A[i] == 0) ++zeroct;
    if(A[i] > 0)  ++posct;
  }
  
  //各符号の組
  int pos_pairct = (posct * posct - posct) / 2 + (negct * negct - negct) / 2;
  int neg_pairct = negct * posct;
  int zero_pairct = (zeroct * zeroct - zeroct) / 2 + (posct * zeroct + negct * zeroct);
  
  sort(A.begin(), A.end());
  
  //順番を区別していったん数えることにする
  //同じインデックス同士は掛けないが，別のインデックスで同じ数なら掛ける
  if(K <= neg_pairct) {
    //負の領域
    //負 * 正 で二分探索
    //負を全部正にして，全部ソートすれば良いのか．筆はなくて生徒みなせばよい．順番が逆になるくらいか
    // int mid = neg_pairct / 2;
    // while(true) {
    //   if(A) 
    // }
  } else if(K <= neg_pairct + zero_pairct) {
    //ゼロの領域
    cout << 0 << endl;
    return 0;
  } else {
    //正の領域
    //昇順
    
    //二分探索で解いてみる    
    int beginIndex = -1;
    rep(i, N) {
      if(A[i] > 0) beginIndex = i;
    }
    int endIndex = N - 1;
    
    int mid = (endIndex - beginIndex) / 2 + beginIndex;
    while(true) {
       
    }
    
  }
}
*/

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
    int A;
    //りんごの数
    int P;
    //りんごの欠片の数
    cin >> A >> P;
    cout << (3 * A + P) / 2 << endl;
    //計算(頭の中ではわかっているけど、言葉では表せない処理)
}

Measured memory_bytes: 256
N = int(input())
s = [input() for i in range(N)]

AC = s.count('AC')
WA = s.count('WA')
TLE = s.count('TLE')
RE  = s.count('RE')

print('AC x ' + str(AC))
print('WA x ' + str(WA))
print('TLE x ' + str(TLE))
print('RE x ' + str(RE))

Measured memory_bytes: 16272
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
	string s;
	cin >> s;
	int ans = 0;
	rep(i, 4){
		if(s[i] == '+')ans++;
		else ans--;
	}
	cout << ans << endl;
	return 0;
}

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

int main(){

  int i,j,minj,num,*A,cnt=0,temp;

  while(1){
    scanf("%d",&num);
    if(num>=1&&num<=100) break;
    }
  A = (int *)malloc(num * sizeof(int));
  for(i=0;i<num;i++){
    scanf("%d",&A[i]);
    if(A[i]<0||A[i]>100) break;
  }
  for(i=0;i<num-1;i++){
    minj = i;
    for(j=i;j<num;j++){
      if(A[j]<A[minj]) minj = j;         
    }
    if(A[i]==A[minj]) continue;
    temp = A[i];
    A[i] = A[minj];
    A[minj] = temp;
    cnt++;
    
    
  }
  for(i=0;i<num;i++){
    if(i==num-1) printf("%d",A[i]);
    else if(A[i]>9) printf("%-3d",A[i]);
    else  printf("%-2d",A[i]);
    }
  printf("\n");
  printf("%d\n",cnt);
  
  return 0;
}



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

#define rep(i, n) for ( ll i = 0; i < (n); ++i )
#define reps(i, n) for ( ll i = 1; i <= (n); ++i )
#define _rep(i, n) for ( ll i = (n) - 1; i >= 0; --i )
#define _reps(i, n) for ( ll i = n; i > 0; --i )
#define all(x) (x).begin(), (x).end()
#define _all(x) (x).rbegin(), (x).rend()

using namespace std;
using ll =  long long;
using P = pair<ll, ll>;


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

	map<ll, ll> mp;
	ll sum = 0;
	rep ( i, n ) {
		ll a;
		cin >> a;

		mp[a]++;
		sum += a;
	}

	ll q;
	cin >> q;

	ll b[q], c[q];
	rep ( i, q ) {
		cin >> b[i] >> c[i];
	}

	rep ( i, q ) {
		sum += (mp[b[i]] * (c[i] - b[i]));
		mp[c[i]] += mp[b[i]];
		mp[b[i]] = 0;

		cout << sum << endl;
	}

	return 0;
}


Measured memory_bytes: 10948
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pii pair<int, int>
#define pll pair<ll, ll>
#define F first
#define S second
#define pb push_back
#define pp pop_back
#define ubo upper_bound
#define lbo lower_bound
#define VI vector<int>
#define VL vector<ll>
#define VP vector<pii >
#define all(x) x.begin(), x.end()
#define M vector<VI >

const int N = 5050;

using namespace std;

int n;
int p[N], v[N][N];
ll k, c[N], sc[N][N], dr[N];

void dfs(int i, int r){
	if(v[r][i]) return;
	v[r][i] = 1;
	dr[r]++;
	sc[r][dr[r]] = sc[r][dr[r]-1]+c[p[i]];
	dfs(p[i], r);
}

int main(){

	cin >> n >> k;
	for(int i=1; i<=n; i++) cin >> p[i];
	for(int i=1; i<=n; i++) cin >> c[i];

	for(int i=1; i<=n; i++) dfs(i, i);

	ll ans = -1e18;
	for(int i=1; i<=n; i++){
		for(ll j=1; j<=min(k, dr[i]); j++){
			ans = max(ans, sc[i][j]+max(0LL, sc[i][dr[i]]*((k-j)/dr[i])));
		}
	}

	cout << ans << endl;

	return 0;
}


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

const int MOD = 1000000007;

int main() {
  int n;
  cin >> n;
  int dp[n + 1][4][4][4] = {};
  dp[0][0][0][0] = 1;
  for (int i = 0; i < n; ++i) {
    for (int x = 0; x < 4; ++x) {
      for (int y = 0; y < 4; ++y) {
        for (int z = 0; z < 4; ++z) {
          if (dp[i][x][y][z] == 0) {
            continue;
          }
          if (x == 2) {
            // xAG or AxG
            if (y == 1 || z == 1) {
              for (int j = 0; j < 3; ++j) {
                dp[i + 1][j][x][y] += dp[i][x][y][z];
                dp[i + 1][j][x][y] %= MOD;
              }
            } else {
              for (int j = 0; j < 4; ++j) {
                dp[i + 1][j][x][y] += dp[i][x][y][z];
                dp[i + 1][j][x][y] %= MOD;
              }
            }
          } else if (x == 3 && y == 1) {
            // xAC
            for (int j : {0, 1, 3}) {
              dp[i + 1][j][x][y] += dp[i][x][y][z];
              dp[i + 1][j][x][y] %= MOD;
            }
          } else if (x == 1 && y == 2) {
            // xGA
            for (int j = 0; j < 3; ++j) {
              dp[i + 1][j][x][y] += dp[i][x][y][z];
              dp[i + 1][j][x][y] %= MOD;
            }
          } else if (y == 2 && z == 1) {
            // AGx
            for (int j = 0; j < 3; ++j) {
              dp[i + 1][j][x][y] += dp[i][x][y][z];
              dp[i + 1][j][x][y] %= MOD;
            }
          } else {
            for (int j = 0; j < 4; ++j) {
              dp[i + 1][j][x][y] += dp[i][x][y][z];
              dp[i + 1][j][x][y] %= MOD;
            }
          }
        }
      }
    }
  }
  int result = 0;
  for (int i = 0; i < 4; ++i) {
    for (int j = 0; j < 4; ++j) {
      for (int k = 0; k < 4; ++k) {
        result = (result + dp[n][i][j][k]) % MOD;
      }
    }
  }
  cout << result;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<string>
using namespace std;
int main(void){
    int A,B;
    cin>>A>>B;
    int P,T;
    P=0;
    for(int i=A;i<=B;i++){
        
        T=(i%10)*10000+((i/10)%10)*1000+((i/100)%10)*100+((i/1000)%10)*10+(i/10000)%10;
        if(i==T){
            P=P+1;
        }
    }
    
    
    cout<<P<<endl;
    
    return 0;
    
}

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


void solve() {
    int n;
    cin >> n;
    if(!n) {
        cout << 0;
    }
    vector<bool> ans;
    while(n != 0) {
        if(n & 1) {
            ans.push_back(1);
            n--;
        }
        else {
            ans.push_back(0);
        }
        n /= -2;
    }
    for (int i = (int) ans.size() - 1; i >= 0; i--) {
        cout << ans[i];
    }
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    solve();
    return 0;
}


Measured memory_bytes: 3616
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
#include <ctime>
#include <complex>
#include <cassert>
#include <array>
#include <bitset> 
#include <unordered_map>
#include <random>

using namespace std;
typedef long long LL;
typedef pair<int,int> P;

string s;
int main() {
	cin >> s;
	int ret=s.size();
	for(int i=1;i<s.size();i++){
		if(s[i-1]!=s[i]){
			ret=min(ret,max(i,(int)s.size()-i));
		}
	}
	cout << ret << endl;


	return 0;
}



Measured memory_bytes: 512
n = int(input(""))
s = ["0"]*n
dict = {}
sum = [0,0,0,0,0,0,0,0,0,0]
ans = 0
for i in range(n):
    s[i] = input("")
    if s[i][0] in "MARCH":
        if s[i][0] in dict:
            dict[s[i][0]] += 1
        else:
            dict[s[i][0]] = 1
if "M" in dict:
    if "A" in dict:
        if "R" in dict:
              sum[0] = dict["M"]*dict["A"]*dict["R"]
        if "C" in dict:
              sum[1] = dict["M"]*dict["A"]*dict["C"]
        if "H" in dict:
              sum[2] = dict["M"]*dict["A"]*dict["H"]
    if "R" in dict:
        if "C" in dict:
              sum[3] = dict["M"]*dict["R"]*dict["C"]
        if "H" in dict:
              sum[4] = dict["M"]*dict["R"]*dict["H"]
    if "C" in dict:
        if "H" in dict:
              sum[5] = dict["M"]*dict["C"]*dict["H"]
if "A" in dict:
    if "R" in dict:
        if "C" in dict:
              sum[6] = dict["A"]*dict["R"]*dict["C"]
        if "H" in dict:
              sum[7] = dict["A"]*dict["R"]*dict["H"]
    if "C" in dict:
        if "H" in dict:
              sum[8] = dict["A"]*dict["C"]*dict["H"]
if "R" in dict and "C" in dict and "H" in dict:
    sum[9] = dict["R"]*dict["C"]*dict["H"]
for i in range(10):
    ans += sum[i]
print(ans)

Measured memory_bytes: 9716
#include<iostream>
using namespace std;
int main(){
    int n;
    string s,t;
    cin>>n>>s>>t;
    for(int i=0;i<n;i++){
      for(int j=0;j<n-i;j++){
        if(s[i+j]!=t[j])break;
        if(j==n-i-1){cout<<n+i<<endl;return 0;}
      }
    }
    cout<<n*2<<endl;
    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++)

int main() {
  int N,M;
  cin >> N;
  vector<string> s(N);
  rep(i,N) cin >> s.at(i);
  cin >> M;
  vector<string> t(M);
  rep(i,M) cin >> t.at(i);
  vector<string> name;
  vector<int> count1;
  rep(i,N){
  if(s.at(i) != "1"){  
    name.push_back(s.at(i));
    count1.push_back(1);
    for(int j=i+1;j<N;j++){
    if(s.at(j) == s.at(i)){
      s.at(j) = "1";
      count1.at(name.size()-1)++;                     
                          } } } }
  vector<int> count2(name.size());
  rep(i,name.size()){
  rep(j,M){
    if(t.at(j) == name.at(i)){
      count2.at(i)++;
    } } }
  int answer = 0;
  rep(i,name.size()){
    if(count1.at(i)-count2.at(i) > answer) answer = count1.at(i)-count2.at(i);
  }
  cout << answer << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std ;
#define rep(i, a, b) for (register int i = (a); i <= (b); ++i)
#define per(i, a, b) for (register int i = (a); i >= (b); --i)
#define iv inline void
#define enter putchar('\n')
const int maxn = 21 * (1 << 21);
int n, m;
char s[21][(1 << 21)];
int high_bit[(1 << 21)], vertex[1 << 21][21], tot, f[maxn];
inline int get_id(const int& len, const int& pos, const int& x)
{
	if(vertex[x + (1 << len)][pos]) return vertex[x + (1 << len)][pos];
	return vertex[x + (1 << len)][pos] = ++tot;
}
iv print(const int& len, const int& x)
{
	per(i, len - 1, 0) putchar(((x & (1 << i)) != 0) + '0');
}
iv trans(const int& len, const int& pos, int x)
{
	register int now = get_id(len, pos, x);
	if(!pos) return ;
	f[get_id(len - pos, 0, x >> pos)] += f[now];
	register int ori = x & (~((1 << pos) - 1)), real = x & ((1 << pos) - 1);
	x = real;
	if(x)
	{
		register int tmp = high_bit[x];
		register int tmp2 = len - pos + tmp;
		x += (ori >> (pos - tmp));
		tmp --;
		f[get_id(tmp2, tmp, x)] += f[now];
	}
	x = real;
	x = (~x) & ((1 << pos) - 1);
	if(x)
	{
		register int tmp = high_bit[x];
		register int tmp2 = len - pos + tmp;
		x -= (1 << tmp);
		x = (~x) & ((1 << tmp) - 1);
		x += (ori >> (pos - tmp));
		tmp --;
		f[get_id(tmp2, tmp, x)] += f[now];
	}
}
signed main()
{
	scanf("%d %d", &n, &m);
	rep(i, 0, (1 << (n + 1)) - 1) high_bit[i] = 32 - __builtin_clz(i);
	rep(i, 0, n) scanf("%s", s[i]);
	per(i, n, 0) rep(j, 0, (1 << i) - 1)
	{
		f[get_id(i, i, j)] = s[i][j] == '1';
		per(k, i, 0)
		{
			register int now = get_id(i, k, j);
			if(f[now] >= m) return print(i, j), enter, 0;
			if(f[now]) trans(i, k, j);
		}
	}
	return 0;
}


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

typedef long long ll;
typedef vector<ll> vll;

#define FOR(i,x,y) for(ll i=(ll)x; i<(ll)y; ++i)
#define REP(i,y) FOR(i, 0, y)

void IN(void){
  return;
}

template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){
  cin >> first;
  IN(rest...);
  return;
}

template <typename First>
void OUT(First first){
  cout << first << endl;
  return;
}

template <typename First, typename... Rest>
void OUT(First first, Rest... rest){
  cout << first << " ";
  OUT(rest...);
  return;
}

ll N, M, Q;
vll a, b, c, d;

vll A;

ll dfs(ll index, ll val){
  if(val>M) return 0;
  if(index==N){
    ll ans = 0;
    REP(i,Q){
      if(A[b[i]]-A[a[i]]==c[i]) ans += d[i];
    }
    return ans;
  }
  A[index] = val;
  return max(dfs(index, val+1), dfs(index+1, val));
}

int main(){
  IN(N,M,Q);

  a.resize(Q);
  b.resize(Q);
  c.resize(Q);
  d.resize(Q);

  REP(i,Q){
    IN(a[i], b[i], c[i], d[i]);
    a[i]--; b[i]--;
  }

  A.resize(N, -1);
  A[0] = 1;

  OUT(dfs(1, 1));
  return 0;
}

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

using namespace std;

typedef long long lli;
typedef vector<lli> vll;
typedef vector<bool> vbl;
typedef vector<vector<lli>> mat;
typedef vector<unordered_map<lli,lli>> graph;

lli n,m;

graph g;
queue<lli> q;

void error(){
  cout << "No" << endl;
  exit(0);
}

vbl visited;
vll p;


int main(){
  cin >> n >> m;
  g = graph(n+1);
  p = vll(n+1);
  visited = vbl(n+1);
  for(lli i = 0;i < m;i++){
    lli l,r,d;
    cin >> l >> r >> d;
    g[l][r] = d;
    g[r][l] = -d;
  }
  for(lli i = 1;i <= n;i++){
    if(visited[i] == false){
      q.push(i);
      p[i] = 0;
      visited[i] = true;
      while(!q.empty()){
        lli x = q.front();
        q.pop();
        for(auto itr = g[x].begin();itr != g[x].end();itr++){
          if(visited[itr->first] == true){
            if(p[itr->first] != p[x]+itr->second) error();
          }else{
            p[itr->first] = p[x]+itr->second;
            q.push(itr->first);
            visited[itr->first] = true;
          }
        }
      }
    }
  }


  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 26020
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cstdint>
using namespace std;
typedef long long ll;
#define MP make_pair
#define PB push_back
#define inf 1000000007
#define mod 1000000007
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)

int main(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    rep(i,s.size()){
        cout << (char)((s[i]-'A'+n)%26 + 'A');
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
#define fi first
#define se second
#define endl '\n'
#define y1 holyshit
#define all(x) x.begin(),x.end()
const int inf=0x3f3f3f3f;

int N;
ll d[200010];

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin>>N;
	for(int i=0;i<N;i++) cin>>d[i];
	ll ans=0;
	for(int i=1;i<N;i++){
		ans+=max(0LL,d[i-1]-d[i]);
		d[i]=max(d[i],d[i-1]);
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 5228
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <iomanip>
#include <bitset>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>

using namespace std;

int n, a, b, c;
int ans = 2e9;
int arr[10];

void go(int i, int x, int y, int z, int pt) {
  if (i == n) {
    if (!x || !y || !z) return;
    ans = min(ans, pt + abs(x - a) + abs(y - b) + abs(z - c));
  } else {
    go(i + 1, x + arr[i], y, z, pt + (x == 0 ? 0 : 10));
    go(i + 1, x, y + arr[i], z, pt + (y == 0 ? 0 : 10));
    go(i + 1, x, y, z + arr[i], pt + (z == 0 ? 0 : 10));
    go(i + 1, x, z, y, pt);
  }
}

int main() {
  cin >> n >> a >> b >> c;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  go(0, 0, 0, 0, 0);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
	    Scanner sc = new Scanner(System.in);
	    int N = sc.nextInt();
	    String n = String.valueOf(N);
	    char a[] = n.toCharArray();
	    char b = a[0];
	    char c[] = {b,b,b};
	    int ans = Integer.parseInt(String.valueOf(c));
	    if(ans >= N){
	      System.out.println(ans);
	    }else{
	      ans += 111;
	      System.out.println(ans);
	    }
	    sc.close();
	  }
}

Measured memory_bytes: 20820
N = int(input())
mapping = 'zabcdefghijklmnopqrstuvwxy'
res = []
for i in range(1, 99):
    if N <= 26 ** i:
        for j in range(i):
            N, r = divmod(N, 26)
            res.append(mapping[r])
            if r:
                N += 1
        break
    else:
        N -= 26 ** i
res.reverse()
print(''.join(res))

Measured memory_bytes: 9192
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define sz(a) (a).size() 
#define all(c) (c).begin(),(c).end()
#define rep(i,n) for(int i=0;i<n;i++)
#define forn(i,n) for(int i=1;i<=n;i++)
#define ford(i,n) for(int i=n;i>=0;i--) 
#define REP(i,a,n) for(int i=a;i<n;i++)
#define foreach(itr,c) for(__typeof((c).begin(),(c).end())itr=c.begin();itr!=c.end();itr++) 
#define fill(a,b) memset(a,b,sizeof(a))
#define re return
#define INF 1e9
#define LINF 1e18
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pi;
typedef vector<int> vi;
typedef vector<pi > vpi; 
int gcd(int a,int b){
	if(a==0){
		re b;
	}
	re gcd(b%a,a);
}
int main(){
	int n;
	cin>>n;
	int ans=0;
	forn(i,n){
		forn(j,n){
			forn(k,n){
				ans+=gcd(gcd(i,j),k);
			}
		}
	}
	cout<<ans;
	re 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <string>

using namespace std;



int main()
{

	string S, T;

	cin >> S >> T;

	if (S.size() != T.size()) {
		printf("No");
		return 0;
	}

	for (int ti = 0; ti < S.size(); ti++) {
		int flag = 1;
		for (int si = 0; si < S.size(); si++) {
			int ci = ti + si;
			if (ci >= S.size()) ci -= S.size();
			if (S[si] != T[ci]) {
				flag = 0;
				break;
			}
		}
		if (flag == 1) {
			printf("Yes");
			return 0;
		}
	}

	printf("No");

    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
    using namespace std;
    int main()
    {
    int n;
     cin>>n;
      int a[n+1];
      memset(a,0,sizeof(a));
      for(int i=1;i<n;i++)
      {
      	int b;
        cin>>b;
        a[b]+=1;
      }
      for(int i=1;i<=n;i++)
        cout<<a[i]<<endl;
     
    }

Measured memory_bytes: 4344
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	string s;
	cin>>s;
	int ch=0;
	string s1=s.substr(0,2);
	string s2=s.substr(2,2);
	if(s1<="12" && s1>"00" && s2<="12" && s2>"00")
	 cout<<"AMBIGUOUS";
	else if(s1<="12" && s1>"00")
	 cout<<"MMYY";
	else if(s2<="12" && s2>"00")
	 cout<<"YYMM";
	else
	 cout<<"NA";
	return 0;

}

Measured memory_bytes: 3628
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "functional"
#include "ctime"

using namespace std;

//constexpr long long int MOD = 1000000007;
constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-8;

//int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;

struct Node {
	long double x, y, rad;
	Node(const int a, const int b) {
		x = a, y = b;
		rad = atan2(x, y);
	}
	bool operator<(const Node&n)const {
		return rad < n.rad;
	}
};


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

	cin >> N;
	int x, y;
	vector<Node>node;
	for (int i = 0; i < N; i++) {
		cin >> x >> y;
		if(x|y)node.push_back(Node(x, y));
	}
	sort(node.begin(), node.end());
	N = node.size();
	long double ans = 0;
	for (int i = 0; i < N; i++) {
		long double xx = 0, yy = 0;
		for (int j = 0; j < N; j++) {
			xx += node[(i + j) % N].x;
			yy += node[(i + j) % N].y;
			ans = max(ans, sqrt(xx*xx + yy * yy));
		}
	}
	cout << setprecision(15) << ans << endl;
}

Measured memory_bytes: 256