akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main(){
   
    vector<int> S;
    vector<int> C(1000,0);
    int N;
    cin>>N;
    for(int i=2;i<=N;i++){
        bool flag=true;
        for(int j=2;j<i;j++){
            if(i%j==0) flag=false;
        }
        if(flag) S.push_back(i);
    }//素数列挙
    
    for(int i=1;i<=N;i++){
        int k=i;
        for(int j=0;j<S.size();j++){
            while(k%S.at(j)==0){
                k/=S.at(j);
                C.at(j)++;
            }
        }
    }//約数列挙
    long int ans=1;
    for(int i=0;i<1000;i++){
        if(C.at(i)!=0){
            ans=ans*(C.at(i)+1)%1000000007;
    }
    }
    cout<<ans<<endl;
}


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();
        List<String> list  = new ArrayList<>();
        int cnt =0;

        for(int i = 0;i<n;i++){
            String a = sc.next();

            if(list.contains(a)){
                cnt++;
            }
            list.add(a);
        }

    

        for(int i =0;i<list.size()-1;i++){
            String b = list.get(i);
            String c = list.get(i+1);

            if(b.charAt(b.length()-1)!=c.charAt(0)){
                cnt++;
               // System.out.println(b.charAt(b.length()-1));
                //System.out.println(c.charAt(0));
            }
        }

        if(cnt==0){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }

        //System.out.println(cnt);

    }
}


Measured memory_bytes: 22608
def main():
    # editorial読んだ．
    N, K = map(int, input().split(" "))
    coordinates = list(map(int, input().split(" ")))
    result = 10 ** 9 + 7
    for i in range(N - K + 1):
        result = min(result, abs(coordinates[i + K - 1] - coordinates[i]) + abs(coordinates[i]),
                     abs(coordinates[i + K - 1] - coordinates[i]) + abs(coordinates[i + K - 1]))
    print(result)


if __name__ == '__main__':
    main()

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

class Main {
	public static void main(String[] args) throws IOException {
    	Scanner sc = new Scanner(System.in);	
      	int n = Integer.parseInt(sc.next());
      	int a = Integer.parseInt(sc.next());
      	int planB = Integer.parseInt(sc.next());
      	int planA = a * n;
      	
      	if (planA == Math.min(planA, planB)) {
        	System.out.println(planA);	
        } else {
          	System.out.println(planB);
        }
    }
}

Measured memory_bytes: 23252
#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
const ll mod =1000000007;
#define rep(i,n) for(ll i=0; i<n; i++)
ll gcd(ll a, ll b){
    if(a<b) swap(a,b);
    while(b>0){
        ll p= a%b;
        a = b;
        b=p;
    }
    return a;
}
ll lcm(ll a, ll b){
    ll g = gcd(a,b);
    return (a/g) * b;
}
int main(){
    ll n;
    cin>>n;
    vector< vector< vector<vector<ll> > > > dp(n+1, vector< vector<vector<ll> > >(4,vector<vector<ll> >(4,vector<ll>(4,0)) ));
    rep(j,4){
        rep(k,4){
            rep(l,4)
            {
                if(!( (j==0&&k==1&&l==2)||(j==0 && k==2&&l==1)||(j==1&&k==0&&l==2) ) ){
                    dp[3][j][k][l]=1;
                }
            }
        }
    }
    for(int i=3; i<n; i++){
        rep(j,4){
            rep(k,4){
                rep(l,4){
                    rep(m,4){
                        if(
                            !(
                                (j==0&&k==1&&m==2)||
                                (j==0&&l==1&&m==2)||
                                (k==0&&l==1&&m==2)||
                                (k==0&&l==2&&m==1)||
                                (k==1&&l==0&&m==2)
                            )
                        )
                        {
                            dp[i+1][k][l][m] += dp[i][j][k][l];
                            dp[i+1][k][l][m] %= mod;
                        }
                    }
                }
            }
        }
    }
    ll sum =0;
    rep(j,4){
        rep(k,4){
            rep(l,4){
                sum += dp[n][j][k][l];
                sum %= mod;
            }
        }
    }
    cout<<sum<<endl;
}

Measured memory_bytes: 384
package main

import (
	"fmt"
	"sort"
)

func main() {
	var H, N int
	fmt.Scanf("%d %d", &H, &N)

	As := make([]int, N)
	for i := 0; i < N; i++ {
		fmt.Scan(&As[i])
	}

	sort.Ints(As)

	var kill bool
	var attack int
	for i := len(As) - 1; i >= 0; i-- {
		attack += As[i]
		if attack >= H {
			kill = true
			break
		}
	}

	if kill {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


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

int main(){
  int H,M;
  cin >> H>>M;
  
  if (H==1||M==1){
    cout << 1 << endl;
  }
  else if (H%2==1 && M%2==1){
    long long seki=1;
    seki *=H;
    seki *=M;
    seki++;
    seki /=2;
    cout << seki <<endl;
  }
  else{
    long long seki=1;
    seki *=H;
    seki *=M;
    seki /=2;
    cout << seki << endl;
  }
   
    
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
#define MOD @
#define ADD(X,Y) ((X) = ((X) + (Y)%MOD) % MOD)
typedef long long i64; typedef vector<int> ivec; typedef vector<string> svec;

int N, A[101];

int main()
{
	scanf("%d", &N);
	for (int i = 0; i < N; ++i) scanf("%d", A + i);

	int ans = 123456789;
	for (int a = -100; a <= 100; ++a) {
		int tmp = 0;
		for (int i = 0; i < N; ++i) tmp += (A[i] - a) * (A[i] - a);
		ans = min(ans, tmp);

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


Measured memory_bytes: 256
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <complex>
#include <ctime>
#include <cstdlib>

using namespace std;

inline int to_int(string s) {int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string to_str(T x) {ostringstream sout; sout << x; return sout.str();}

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

const int INF = 1 << 30;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int month[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

bool leap(int y)
{
	return ((y%4==0&&y%100!=0)||y%400==0);
}

#define debug(a, b, c) for(int i = 0; i < b; i++){for(int j = 0; j < c; j++){printf("%3d", a[i][j]);}puts("");}puts("-----------------------------------------");

int deck[256], deck1[256], deck2[256];

void format()
{
	for(int i = 0; i < 200; i++)
	{
		deck[i] = i+1;
	}
}

void nomal_cut(int num, int sf)
{
	for(int i = sf, j = 0; i < num; i++, j++)
	{
		deck1[j] = deck[i];
	}

	for(int i = 0, j = num - sf ; j < num; i++, j++)
	{
		deck1[j] = deck[i];
	}

	for(int i = 0; i < num; i++)
	{
		deck[i] = deck1[i];
	}
}

void shuffle(int num)
{
	for(int i = 0; i < num; i++)
	{
		deck1[i] = deck[i];
	}
	
	for(int i = num, j = 0; i < 2*num; i++, j++)
	{
		deck2[j] = deck[i];
	}

	for(int i = 0, j = 0; i < num; i++, j += 2)
	{
		deck[j] = deck1[i];
		deck[j+1] = deck2[i];
	}
}

int main()
{
	int num, act, cut;

	while(cin >> num)
	{
		format();

		cin >> act;

		for(int i = 0; i < act; i++)
		{
			cin >> cut;

			if(cut)
			{
				nomal_cut(2*num, cut);
			}
			else
			{
				shuffle(num);
			}
		}

		for(int i = 0; i < 2*num; i++)
		{
			cout << deck[i] << endl;
		}
	}
}

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

int main(){
    int a,b,c;
    cin >> a >> b >> c;

    if(a < b){
        if(b < c){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
        
    }else{
        cout << "No" << endl;
    }
}



Measured memory_bytes: 3084
#include<stdio.h>
#include <math.h>
int main(void){
   double key, x, h, s1, s2, S, H;
   while(1){
      scanf("%lf %lf", &x, &h);
      if(x == 0 && h == 0)
         break;
      key = x / 2 * x / 2 + h * h;
      H = sqrt(key);
      s1 = x * x;
      s2 = x * H * 2;
      S = s1 + s2;
      printf("%lf\n", S);
   }
   return 0;
}

Measured memory_bytes: 1764
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

void string2circulation(const std::string &str,
						std::vector<std::string> &cir,
						const int length){
	std::string begin = str.substr(length-1,1) + str.substr(0,2);
	cir.push_back(begin);
	for(int i=0;i<length-2;++i)
		cir.push_back(str.substr(i,3));
	std::string   end = str.substr(length-2,2) + str.substr(0,1);
	cir.push_back(end);
}

int main(int agrc,char *argv[]){
	std::string A,B;
	std::cin >> A;
	std::cin >> B;
	int length = A.size();
	std::vector<std::string> Acir,Bcir;
	string2circulation(A,Acir,length);
	string2circulation(B,Bcir,length);
	std::sort(Acir.begin(),Acir.end());
	std::sort(Bcir.begin(),Bcir.end());
	if(Acir==Bcir){
		std::cout << "Yes" << std::endl;
	}else{
		std::cout << "No" << std::endl;
	}
	return 0;
}

Measured memory_bytes: 256
import java.io.*;

class Main
{
   public static void main(String[] args) throws IOException
   {

      BufferedReader br =
       new BufferedReader(new InputStreamReader(System.in));

      String str = br.readLine();
      int x = Integer.parseInt(str);

      //System.out.println( x^3 );   // ^???Java??§???????????§?????????XOR???????????????
      //System.out.println( x*x*x );            // <= ??£?§£
      //System.out.println( Math.pow(x,3) );  // Math.pow ???double???????????????
      System.out.println( (int)Math.pow(x,3) ); // <= ??£?§£

   }
}

Measured memory_bytes: 24188
#include <iostream>
#define MAXN 101
#define MAXM 101
using namespace std;

int n,m;
int target[MAXM];
int ans[MAXM][MAXN];
int score[MAXN];
int main(){
	cin >>n;
	cin >>m;
	for(int i=1;i<=m;i++){
		cin >> target[i];
	}
	for(int i=1;i<=m;i++){
		for(int j=1;j<=n;j++){
			cin >> ans[i][j];
		}
	}

	for(int i=1;i<=m;i++){
		for(int j=1;j<=n;j++){
			if(target[i]==ans[i][j]){
				score[j]++;
			}else{
				score[target[i]]++;
			}
		}
	}	

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

	return 0;
}

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


def GCD(a, b):
    # a < b
    if a == 0:
        return b
    else:
        return GCD(b % a, a)


def solve(N: int, M: int):
    # O(sqrt(M))
    yakusu = [i for i in range(1, int(math.sqrt(M))+1) if M % i == 0]
    yakusu.extend([M/y for y in yakusu[::-1]])

    ans = 0
    for y in yakusu:
        rest = M / y
        if rest >= N:
            # print(y, rest, N)
            ans = y

    print(int(ans))
    return


# Generated by 1.1.3 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    solve(N, M)


if __name__ == '__main__':
    main()


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

int main(){
    int n; cin>>n;
    vector<int> a(n),b(n),c(n-1);
    for(int i=0;i<n;i++){
        cin >>a[i];
    }
    for(int i=0;i<n;i++){
        cin >>b[i];
    }
    for(int i=0;i<n-1;i++){
        cin >>c[i];
    }
    int ans =0;
    for(int i=0;i<n;i++){
        ans += b[a[i]-1];
        //cout << ans << endl;
        if(i!=0&&a[i]==a[i-1]+1){
            ans+= c[a[i-1]-1];
            //cout << ans << endl;
        }
    }
    cout << ans << endl;

}

Measured memory_bytes: 256
#include<stdio.h>

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


Measured memory_bytes: 128
#include<stdio.h>
int main()
{
  int N,X,T;
  scanf("%d %d %d",&N,&X,&T);
  if(N%X==0)
    printf("%d",((N/X)*T));
  else 
    printf("%d",(((N/X)+1)*T));
 return 0; 
} 

Measured memory_bytes: 1732
my $N = <STDIN>;
chomp($N);
my @d = map {$_ + 0} split(/ /o, <STDIN>);
my $t = 0;
my $nn = $N - 1;
foreach my $i (0..$nn) {
    foreach my $j (($i+1)..$nn) {
        $t += $d[$i] * $d[$j];
    }
}
print $t;

Measured memory_bytes: 384
#include <bits/stdc++.h>
#include<vector>
using namespace std;
#define rep(i, n)        for(int i=0; i<(int)(n); ++i)
int main() {
  int a,b;
  cin>>a>>b;
  if(b%a==0)cout<<a+b;
  else cout<<b-a;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;
import java.util.Stack;
 
class Main {
 
    public static void main(String[] args) {
        new Main().compute();
    }
 
    void compute() {
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        List<Character> removedX = new ArrayList<>();
        boolean[] isX = new boolean[S.length()];
        for (int i = 0; i < S.length(); i++) {
            if (S.charAt(i) == 'x') {
                isX[i] = true;
            } else {
               removedX.add(S.charAt(i));
            }
        }
        for (int i = 0; i < removedX.size() / 2; i++) {
            if (removedX.get(i) != removedX.get(removedX.size() - i - 1)) {
                System.out.println(-1);
                return;
            }
        }
        int ans = 0;
        int head = 0;
        int foot = S.length() - 1;
        while (foot - head > 0) {
            if (isX[head] == isX[foot]) {
                head++;
                foot--;
            } else if (isX[head] && !isX[foot]) {
                head++;
                ans++;
            } else {
                foot--;
                ans++;
            }
        }
        System.out.println(ans);
    }
}

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

#define FOR(i, j, k) for(int i=j ; i<k ; i++)
#define REP(i, j) FOR(i, 0, j)
typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;

int main() {

    int A, B; cin >> A >> B;

    cout << (A - 1) * (B - 1) << endl;

    return 0;
}


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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
using ll = long long;

int main() {
    string S;
    ll K;
    cin >> S >> K;

    vector<ll> a;
    int cnt = 0;
    char prev = S[0];
    rep(i, S.size()) {
        if (prev == S[i]) {
            cnt++;
        } else {
            a.push_back(cnt);
            prev = S[i];
            cnt = 1;
        }
    }
    a.push_back(cnt);

    if (a.size() == 1) {
        cout << (a[0] * K) / 2 << endl;
        return 0;
    }

    if (S[0] != S[S.size() - 1]) {
        ll ans = 0;
        rep(i, a.size()) ans += a[i] / 2;
        ans *= K;
        cout << ans << endl;
        return 0;
    }

    ll lead_cnt = 0;
    rep(i, a.size() - 1) lead_cnt += a[i] / 2;
    ll middle_cnt = 0;
    rep(i, a.size() - 1) {
        if (i == 0) middle_cnt += (a[0] + a[a.size() - 1]) / 2;
        else middle_cnt += a[i] / 2;
    }
    ll last_cnt = a[a.size() - 1] / 2;
    cout << lead_cnt + middle_cnt * (K - 1) + last_cnt << endl;
}


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

enum inf3 = 1_001_001_001;
enum inf6 = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;



void main() {
    int n, m;
    scan(n, m);

    auto cnt = new int[](n + 1);

    foreach (i ; 0 .. m) {
        int li, ri;
        scan(li, ri);
        li--;
        cnt[li]++;
        cnt[ri]--;
    }

    foreach (i ; 0 .. n) {
        cnt[i + 1] += cnt[i];
    }

    int ans;

    foreach (i ; 0 .. n + 1) {
        if (cnt[i] == m) ans++;
    }

    writeln(ans);
}





















int[][] readGraph(int n, int m, bool isUndirected = true, bool is1indexed = true) {
    auto adj = new int[][](n, 0);

    foreach (i; 0 .. m) {
        int u, v;
        scan(u, v);
        if (is1indexed) {
            u--, v--;
        }
        adj[u] ~= v;
        if (isUndirected) {
            adj[v] ~= u;
        }
    }

    return adj;
}

alias Edge = Tuple!(int, "to", int, "cost");

Edge[][] readWeightedGraph(int n, int m, bool isUndirected = true, bool is1indexed = true) {
    auto adj = new Edge[][](n, 0);

    foreach (i; 0 .. m) {
        int u, v, c;
        scan(u, v, c);
        if (is1indexed) {
            u--, v--;
        }
        adj[u] ~= Edge(v, c);
        if (isUndirected) {
            adj[v] ~= Edge(u, c);
        }
    }

    return adj;
}

void yes(bool b) {
    writeln(b ? "Yes" : "No");
}

void YES(bool b) {
    writeln(b ? "YES" : "NO");
}

T[] readArr(T)() {
    return readln.split.to!(T[]);
}

T[] readArrByLines(T)(int n) {
    return iota(n).map!(i => readln.chomp.to!T).array;
}

void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x > arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x < arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}


Measured memory_bytes: 3708
import sys
n = input()
list_num =list(map(int,input().split()))
output = 1
if 0 in list_num:
    print(0)
    sys.exit()
for i in list_num:
    output = output * i
    if output > 10 ** 18:
        print(-1)
        sys.exit()
print(output)


Measured memory_bytes: 21692
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <tuple>
#include <bitset>
#include <cmath>
#include<iomanip>

template<typename T> bool chmax( T &a, T b ) { if ( a > b ) { a = b; return ( true ); } else { return ( false ); } }
template<typename T> bool chmin( T &a, T b ) { if ( a < b ) { a = b; return ( true ); } else { return ( false ); } }

using namespace std;

using ll = long long;
using ull = unsigned long long;

using Pll  = pair<ll, ll>;
using Pull = pair<ull, ull>;

#define ep emplace_back
#define pb push_back
#define mp( a, b ) make_pair( a, b )

#define rep( i, n ) for ( int i = 0; i < (int)( n ); ++i )
#define reps( i, n ) for ( int i = 1; i <= (int)( n ); ++i )
#define rrep( i, n ) for ( int i = (int)( ( n ) - 1 ); i >= 0; --i )
#define rreps( i, n ) for ( int i = (int)( ( n ) ); i > 0; --i )

#define ALL( c ) ( c ).begin(), ( c ).end()
#define RALL( c ) ( c ).rbegin(), ( c ).rend()

#define MOD ( 1e9 + 7 )

double pow_1( double x )
{
	double base = 1;
	rep( i, x )
	{
		base /= 2;
	}

	return ( base );
}

int main()
{
	int N, K;
	cin >> N >> K;
	cout << fixed << setprecision( 16 );

	double res = 0.0;
	reps( i, N )
	{
		double tmp = i;
		double tmp_res = (double)1 / (double)N;

		while ( tmp < K )
		{
			tmp *= 2.0;
			tmp_res /= 2.0;
		}

		res += tmp_res;
	}

	cout << res << endl;

	return ( 0 );
}


Measured memory_bytes: 384
import sys

n, *a = map(int, sys.stdin.read().split())

cumsum = [0] + a
cumxor = cumsum.copy()
for i in range(1, n):
    cumsum[i+1] += cumsum[i]
    cumxor[i+1] ^= cumxor[i]

def is_ok(l, r):
    s = cumsum[r] - cumsum[l-1]
    x = cumxor[r] ^ cumxor[l-1]
    return s == x

def main():
    res = 0
    l = r = 1
    flag = False
    while l <= n:
        if is_ok(l, r):
            if r == n:
                res += r - l + 1
                l += 1
                flag = False
            else:
                r += 1
                flag = True
        else:
            if flag:
                res += r - 1 - l + 1
            else:
                res += r - l + 1
            l += 1
    return res
if __name__ == '__main__':
    ans = main()
    print(ans)

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

using namespace std;

#define ll long long

const int INF = 1e9;

int calDist(int x1, int y1, int x2, int y2){
	return (abs(x1-x2) + abs(y1-y2));
}

int main(){
	int n, m; 
	cin >> n >> m;
	vector<pair<int,int>> i1(n), i2(m);
	for(int i = 0; i < n; ++i)
		cin >> i1[i].first >> i1[i].second;
	for(int i = 0; i < m; ++i)
		cin >> i2[i].first >> i2[i].second;
	for(int i = 0; i < n; ++i){
		pair<int, int> best = {0, INF};
		for(int j = 0; j<m; ++j){
			int cur = calDist(i1[i].first, i1[i].second, i2[j].first, i2[j].second);
			if(cur < best.second){
				best.second = cur;
				best.first = j;
			}
		}
		cout << best.first + 1  << "\n";
	}
	return 0;
}


Measured memory_bytes: 3640
#include <iostream>

using namespace std;

int main()
{
  int a, b, m;
  int re[100010], de[100010];
  int x[100010], y[100010], c[100010];
  int remin = 200010, demin = 200010;
  
  cin >> a >> b >> m;
  for (int i = 0; i < a; i++) {
    cin >> re[i];
    if (remin > re[i]) {
      remin = re[i];
    }
  }
  for (int i = 0; i < b; i++) {
    cin >> de[i];
    if (demin > de[i]) {
      demin = de[i];
    }
  }
  for (int i = 0; i < m; i++) {
    cin >> x[i] >> y[i] >> c[i];
  }
  
  int min = demin + remin;
  
  for (int i = 0; i < m; i++) {
    if (min > re[x[i]-1] + de[y[i]-1] - c[i]) {
      min = re[x[i]-1] + de[y[i]-1] - c[i];
    }
  }
  
  cout << min << endl;
}
        

Measured memory_bytes: 2176
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

typedef long long ll;
ll MOD = 1000000007;

// a^p
// 2^3 = 2 * 2^2
// 2^2 = 2 * (2^1)
// 2^1 = 2
ll modpow(ll a, ll p, ll mod) {
  if (p == 0) return 1;

  if (p % 2 == 0) {
    ll half = modpow(a, p / 2, mod) % mod;
    return half * half % mod;
  } else {
    return a * modpow(a, p - 1, mod) % mod;
  }
}

// nCa を求める
ll modCombination(ll n, ll a, ll mod) {
  if (n - a < a) {
    return modCombination(n, n - a, mod);
  }

  ll denominator = 1;  // 分母
  ll numerator = 1;    // 分子

  for (ll i = 0; i < a; i++) {
    denominator *= a - i;
    numerator *= n - i;
    denominator %= mod;
    numerator %= mod;
  }

  return numerator * modpow(denominator, mod - 2, mod) % mod;
}

int main() {
  ll X, Y;
  cin >> X >> Y;

  if ((X + Y) % 3 != 0) {
    cout << 0 << endl;
    return 0;
  }

  ll ans = 0;
  // X = a + 2b;
  // Y = 2a + b;
  // (i + 1, j + 2) という動き方を全探索
  for (ll a = 0; a < X + 1; a++) {
    if ((Y - 2 * a) != ((X - a) / 2)) continue;

    ll b = Y - 2 * a;
    ans += modCombination(a + b, a, MOD);
  }

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


Measured memory_bytes: 256
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

def inv(a, mod):
    b = mod
    p = 1; q = 0
    while b > 0:
        c = a // b
        a, b = b, a%b
        p, q = q, p-c*q
    return p + mod if p < 0 else p


def guess(mod, y):
    n = len(y)
    dp = [0] * (n+1)
    dp[0] = 1

    for i in range(n):
        for j in range(i, -1, -1):
            dp[j+1] += dp[j]
            if dp[j+1] >= mod:
                dp[j+1] -= mod
            dp[j] = dp[j] * -i % mod
            if dp[j] < 0:
                dp[j] += mod

    f = [0] * (n+1)
    f[0] = 1
    for i in range(1, n+1):
        f[i] = f[i-1] * i % mod

    ret = [0] * n
    for i in range(n):
        den = f[i] * f[n-1-i] % mod
        if ((i^n-1)&1) == 1:
            den = mod - den
        iden = inv(den, mod) * y[i] % mod

        minus = 0
        for j in range(n-1, -1, -1):
            minus = (dp[j+1] + minus * i) % mod
            ret[j] = (ret[j] + minus * iden) % mod
    return ret

p = ni()
a = na()
f = guess(p, a)
for i in range(p):
    sys.stdout.write(str(f[i]) + " ")


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

int main(){
    int N;  string S;
    cin >> N >> S;
    if(N%2==1){
        cout << "No" << endl;
    }else{
        int n = N/2;
        string s = S.substr(0, n);
        string t = S.substr(n, n);
        cout << (s == t ? "Yes" : "No") << endl;
    }
}

Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))

#累積和
ans=0
acum={}
acumi=0
for i in range(n):
    acumi+=a[i]
    acum[acumi]=acum.get(acumi, 0)+1

for k,v in acum.items():
    if(k==0):
        ans+=v*(1+v)//2
    else:
        ans+=(v-1)*v//2
print(ans)


Measured memory_bytes: 39532
#include <bits/stdc++.h>
#define int long long
#define N 100010
using namespace std;
const int INF = 1LL<<55;
const int mod = (1e9)+7;
const double EPS = 1e-8;
const double PI = 6.0 * asin(0.5);
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}

#define rank Asdfiasofsad
class UF{
public:
  int V;
  vector<int> par,rank,base;
  UF(){}
  UF(int V):V(V),par(V),rank(V,0),base(V,0){for(int i=0;i<V;i++)par[i]=i;}
  
  int find(int x){
    assert(x < V);
    if(par[x]==x)return x;
    return par[x]=find(par[x]);
  }
  
  void unite(int x,int y){
    x=find(x), y=find(y);
    if(x==y)return;
    if(rank[x]<rank[y])par[x]=y, base[y] |= base[x];
    else{
      par[y]=x;
      base[x] |= base[y];
      if(rank[x]==rank[y])rank[x]++;
    }
  }

  bool same(int x,int y){return find(x)==find(y);}
};

int n,k,t;
typedef pair<int,int> P;
typedef pair<int,P> PP;
vector<int>  T;
vector<PP> edge;

int solve(){
  sort(edge.begin(),edge.end());
  int sum = 0;
  for(int i=0;i<n-1;i++) sum += -edge[i].first;
  UF uf(n);
  for(int i=0;i<t;i++) uf.base[T[i]] = 1;
  
  int numBase = t,numNode = n;
  for(int i=0;i<n-1;i++){
    int a = edge[i].second.first;
    int b = edge[i].second.second;
    int c = -edge[i].first;
    a = uf.find(a);
    b = uf.find(b);
    if(uf.same(a,b)) continue;
    if(numBase == k+1 && uf.base[a] && uf.base[b]) continue;
    if(numNode == k+1) continue;
    if(uf.base[a] && uf.base[b]) numBase--;
    numNode--;
    sum -= c;
    uf.unite(a,b);
  }
  return sum;
}

signed main(){
  int numCase = 0;
  while(1){
    cin>>n>>t>>k;
    if(n == 0 && k == 0 && t == 0) break;
    cout<<"Case "<<++numCase<<": ";
    
    edge.resize(n-1);
    for(int i=0;i<n-1;i++){
      int a,b,c;
      cin>>a>>b>>c; a--,b--;
      edge[i] = PP(-c,P(a,b));
    }
    
    T.resize(t);
    for(int i=0;i<t;i++) cin>>T[i],T[i]--;
   
    cout<<solve()<<endl; 
  }



  return 0;
}

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

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    
    int ans = 0;
    vector<int> c(n + 1, -1);
    c[0] = 1e9 + 5;
    rep(i, n){
        int p = 0;
        int q = ans + 1;
        while (q - p != 1){
            int r = (p + q) / 2;
            if (c[r] < a[i])
                q = r;
            else p = r;
        }
        if (c[q] == -1) ans++;
        c[q] = a[i];
    }
    cout << ans << endl;
}

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

#define LL long long

#define FOR(INDEX, START, END) for (int INDEX = (START); INDEX < (END); ++INDEX)
#define REP(INDEX, COUNT) for (int INDEX = 0; INDEX < (COUNT); ++INDEX)

vector<LL> h;


int main()
{
	LL N;
	cin >> N;
	h.resize(N);
	REP(i, N) {
		cin >> h[i];
	}

	int cnt = 0;
	for (;;) {
		int l = -1;
		for (int i = 0; i < h.size(); ++i) {
			if (h[i]) {
				l = i;
				break;
			}
		}
		if (l < 0) {
			break;
		}

		int mini = 9999;

		int r = h.size();
		for (int i = l; i < h.size(); ++i) {
			if (h[i] == 0) {
				r = i;
				break;
			}

			if (h[i] < mini) {
				mini = h[i];
			}
		}

		for (int i = l; i < r; ++i) {
			h[i] -= mini;
		}
		cnt += mini;
	}

	cout << cnt << endl;

	return 0;
}


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

int main() {
	int h, w;
	cin >> h >> w;
	char s[55][55];
	int ans = 0;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			cin >> s[i][j];
		}
	}
	char a;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if (s[i][j] == '.') {
				for (int k = -1; k <= 1; k++) {
					for (int l = -1; l <= 1; l++) {
						if (i + k >= 0 && h >= i + k) {
							if (j + l >= 0 && w >= j + l) {
								if (s[i + k][j + l] == '#') {
									ans++;
								}
							}
						}
					}
				}
				a = ans + '0';
				s[i][j] = a;
				ans = 0;
			}
		}
	}
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			cout << s[i][j];
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int N,Q; cin>>N>>Q;
	string S; cin>>S;
	map<int,int> pre;
	for (int i=0; i<N; i++)
		if(S.substr(i,2)=="AC")
			pre[i]++;
	for (int i=1; i<N; i++)
		pre[i]+=pre[i-1];

	for (int i=0; i<Q; i++) {
		int l,r; cin>>l>>r; l--; r--;
		cout<<pre[r-1]-pre[l-1]<<"\n";
	}
	return 0;
}

Measured memory_bytes: 5584
N, M = map(int, input().split())
AB = []
for i in range(N):
    AB.append(list(map(int, input().split())))
AB.sort(key=lambda x: x[0])

def calc(AB):
    cnt = 0
    yen = 0
    for n in AB:
        for i in range(n[1]):
            cnt += 1
            yen += n[0]
            if M == cnt:
                return yen

print(calc(AB))


Measured memory_bytes: 28960
#include<stdio.h> 
int main()
{
	int a,b,c,d;
	scanf("%d",&a);
	if(a==1)
	printf("Hello World");
	if(a==2)
	{
	scanf("%d%d",&b,&c);
	d=b+c;
	printf("%d",d);
	} 

}

Measured memory_bytes: 256
x=int(input())
exp=[0]*(x+1)
exp[1]=1
ans=0
for i in range(2,x+1):
    t=i*i
    while t<=x:
        exp[t]=1
        t*=i

for i in range(1,x+1):
    if exp[i]:
        ans=max(i,ans)
print(ans)

Measured memory_bytes: 3064
#include<stdio.h>
#include<string.h>
#define Len 100005

typedef struct p1{
  char name[100];
  int time;
}P;

P Q[Len];
int tail,head,n;

void En(P x){
  Q[tail]=x;
  tail=(tail+1)%Len;
}

P De(){
  P x=Q[head];
  head=(head+1)%Len;
  return x;
}

int min(int x,int y){
  return x<y?x:y;
}

int main(){
  int a=0,c,i,q;
  P b;

  scanf("%d %d",&n,&q);
  for(i=1;i<=n;i++){
    scanf("%s",Q[i].name);
    scanf("%d",&Q[i].time);
  }
  head=1;
  tail=n+1;

  while(head!=tail){
    b=De();
    c=min(q,b.time);
    b.time-=c;
    a+=c;
    if(b.time>0)En(b);
    else {
      printf("%s %d\n",b.name, a);
    }
  }
  return 0;
}



Measured memory_bytes: 11892
def main():
    import sys
    input=sys.stdin.readline
    from collections import deque
    H,W=map(int,input().split())
    maze=[]
    for _ in range(H):
        a=input().rstrip()
        maze.append(a)
    path=[[0]*W for _ in range(H)]
    path[0][0]=1
    q=deque([[0,0]])
    finished=[[False]*W for _ in range(H)]
    while q:
        h,w=q.popleft()
        if finished[h][w]==True:
            continue
        for nh,nw in ([h+1,w],[h,w+1]):
            if nh<0 or nh>H-1 or nw<0 or nw>W-1:
                continue
            if maze[nh][nw]=="#":
                continue
            path[nh][nw]+=path[h][w]
            path[nh][nw]%=1000000007
            q.append([nh,nw])
        finished[h][w]=True
    print(path[-1][-1])

if __name__=="__main__":
    main()

Measured memory_bytes: 112504
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <limits>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <functional>

using namespace std;

using ll = long long;
using ui = unsigned int;
const ll MOD = 1000000007;
const ll INF = 9223372036854775807;


//C
int main() {
	ll H;
	scanf("%lld", &H);
	ll W;
	scanf("%lld", &W);
	ll K;
	scanf("%lld", &K);
	vector<vector<char>> arr(H, vector<char>(W, 0));
	for (ll j = 0; j < H; j++) {
		char s[400];
		scanf("%s", s);

		for (ll i = 0; i < W; i++) {
			arr[j][i] = s[i];
		}
	}

	int currNo = 0;

	vector<vector<int>> result(H, vector<int>(W, 0));

	for (ll j = 0; j < H; j++) {
		int count = 0;
		for (ll i = 0; i < W; i++) {
			if (arr[j][i] == '#') {
				count++;
				break;
			}
		}

		if (count > 0) {
			currNo++;
		}
		else {
			continue;
		}

		count = 0;
		for (ll i = 0; i < W; i++) {
			if (arr[j][i] == '#') {
				count++;
				if (count >= 2) {
					currNo++;
				}
			}

			result[j][i] = currNo;
		}
	}

	//��
	for (ll j = 1; j < H; j++) {
		if (result[j][0] > 0) {
			continue;
		}

		for (ll i = 0; i < W; i++) {
			result[j][i] = result[j - 1][i];
		}
	}

	//��
	for (ll j = H - 2; j >= 0; j--) {
		if (result[j][0] > 0) {
			continue;
		}

		for (ll i = 0; i < W; i++) {
			result[j][i] = result[j + 1][i];
		}
	}

	for (ll j = 0; j < H; j++) {
		for (ll i = 0; i < W; i++) {
			printf("%d ", result[j][i]);
		}
		printf("\n"); 
	}
}

//B
/*
int main() {
	ll N;
	scanf("%lld", &N);
	vector<ll> A(N);
	ll total = 0;
	for (ll i = 0; i < N; i++) {
		scanf("%lld", &A[i]);
		total += A[i];
	}

	ll result = INF;
	ll sum = 0;
	for (ll i = 0; i < N; i++) {
		sum += A[i];

		if (sum * 2 == total) {
			result = 0;
		}
		else if (sum * 2 <= total) {
			result = min(result, abs(total - 2 * sum));
		}
		else {
			result = min(result, abs(2 * sum - total));
		}
	}



	printf("%lld\n", result);
}
*/

//A
/*
int main() {
	ll X;
	scanf("%lld", &X);
	ll Y;
	scanf("%lld", &Y);

	ll result = 0;

	if (X == 3) {
		result += 100000;
	}
	else if (X == 2) {
		result += 200000;
	}
	else if (X == 1) {
		result += 300000;
	}

	if (Y == 3) {
		result += 100000;
	}
	else if (Y == 2) {
		result += 200000;
	}
	else if (Y == 1) {
		result += 300000;
	}

	if (X == 1 && Y == 1) {
		result += 400000;
	}

	printf("%lld\n", result);
}
*/

Measured memory_bytes: 1280
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in);) {
			while (true) {
				String a = sc.next();
				String b = sc.next();

				String s = "EQUAL";

				if (a.length() > b.length()) {
					System.out.println("GREATER");
					break;
				}
				if (a.length() < b.length()) {
					System.out.println("LESS");
					break;
				}

				for (int i = 0; i < a.length(); i++) {
					if (a.charAt(i) > b.charAt(i)) {
						s = "GREATER";
						break;
					}
					if (a.charAt(i) < b.charAt(i)) {
						s = "LESS";
						break;
					}
				}

				System.out.println(s);
				break;
			}
		}
	}
}

Measured memory_bytes: 22868
N=int(input())
A=list(map(int,input().split()))
Q=int(input())
B=[list(map(int,input().split())) for i in range(Q)]

dp=[0 for i in range(1,10**6)]
for i in A:
    dp[i]+=1
S=sum(A)
for i in B:
    S+=(i[1]-i[0])*dp[i[0]]
    print(S)
    dp[i[1]]+=dp[i[0]]
    dp[i[0]]=0
    

Measured memory_bytes: 165528
n, y = map(int, input().split())

f = False
for i in range(n, -1, -1):
    if f:
        break
    for j in range(n, -1, -1):
        if f:
            break
        if (n - i - j >= 0) & (10000 * i + 5000 * j + 1000 * (n - i - j) == y):
            print(i, j, (n - i - j))
            f = True

if f is False:
    print(-1, -1, -1)


Measured memory_bytes: 41068
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll, int> PL;
constexpr int mod = 1e9 + 7;
constexpr int INF = 2e9;

int main() {
  ll n;
  cin >> n;
  int res = 0;

  auto dfs = [&](auto& f, ll now, int s)->void{
    if (now > n) return ;
    if (s == 7) res++;
    f(f, now * 10 + 3, s | (1 << 0));
    f(f, now * 10 + 5, s | (1 << 1));
    f(f, now * 10 + 7, s | (1 << 2));
  };

  dfs(dfs, 0, 0);
  cout << res << endl;
  return 0;
} 

Measured memory_bytes: 3560
#include <bits/stdc++.h>
#define mod 1000000007
using namespace std;
long long dp[110][100010];

int main() {
  int n, m;
  cin >> n >> m;
  long long a[n];
  for (int i = 0; i < n; i++)
    cin >> a[i];
  vector<int> sum(m+1,0);
  dp[1][0] = 1; sum[0] = 1;
  for (int i = 1; i <= a[0]; i++)
    dp[1][i] = 1;
  
  for (int i = 1; i <= m; i++)
    sum[i] = sum[i - 1] + dp[1][i];

  for (int i = 2; i <= n; i++) {
    for (int j = 0; j <= m; j++) {
      if(j>a[i-1])
      {
        dp[i][j]=(sum[j]-sum[j-a[i-1]-1]+mod)%mod;
      }
      else
        dp[i][j]=sum[j];
    }
    sum[0] = dp[i][0];
    for (int j = 1; j <= m; j++) sum[j] = (sum[j - 1] + dp[i][j]) % mod;

  }
  cout << dp[n][m] << endl;
  return 0;
}

Measured memory_bytes: 79744
#include <iostream>
#include <utility>
#include <tuple>
#include <vector>
#include <string>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <algorithm>
#include <functional>
#include <climits>
#include <numeric>
#include <queue>
#include <cmath>
#include <iomanip>
#include <array>
#include <string>
#include <stack>
#include <cassert>
#include <memory>

constexpr int mod = 1000000007;
long long int power(const long long int base, const int exp) {
	switch (exp) {
	case 0: return 1LL;
	case 1: return base % mod;
	default: return power(base * base % mod, exp >> 1) * power(base, exp & 1) % mod;
	}
}
int main() {
	int n; std::cin >> n;
	std::string str; std::cin >> str;
	std::vector<std::vector<long long int>> memo(n + 1, std::vector<long long int>(n + 1, 0));
	memo[0][0] = 1;
	for (auto i = 1; i < memo.size(); ++i) {
		memo[i][0] = (memo[i - 1][0] + memo[i - 1][1]) % mod;
		for (auto j = 1; j < n; ++j) {
			memo[i][j] = ((memo[i - 1][j - 1] << 1) + memo[i - 1][j + 1]) % mod;
		}
		memo[i][n] = (memo[i - 1][n - 1] << 1) % mod;
	}
	std::cout << memo[n][str.size()] * power((mod + 1) >> 1, str.size()) % mod << '\n';
}


Measured memory_bytes: 195840
#include <stdio.h>
#include <math.h>
int main(){
    int n,i,t,l,gou=0;
	char input[300];
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%s",input);
		l = strlen(input);
        if(input[l-1]=='~'&&input[l-2]=='~'&&input[0]=='>'&&input[1]=='^'&&input[2]=='Q'&&input[3]=='='){//B種の調べ
            for(t=2;t<=l-4;t=t+2){
                if(input[t]=='Q'&&input[t+1]=='='){
                    gou++;
                }
            }
            if(gou*2==l-4){
                puts("B");
            }else puts("NA");;
            gou=0;
        }else if(input[l/2]=='#'&&input[l-1]=='~'&&(l-4)%2==0&&input[0]=='>'&&input[1]=='\''&&input[2]=='='){
            int j=2;
            for(t=0;t<(l-4)/2;t++){
                if(input[j]=='='&&input[l-j]=='='){
                    gou++;
                }
                j++;
            }
            if(gou==((l-4)/2)){
                puts("A");
            }else puts("NA");
            gou=0;
        }else puts("NA");
    }
    return 0;
}

Measured memory_bytes: 584
#include<bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
#define ALLG(v) v.begin(), v.end() ,greater<int>()
typedef long long ll;
ll GCD(ll x, ll y) { return y ? GCD(y, x % y) : x; }
ll LCM(ll x, ll y) { return x * y / GCD(x, y); }
ll GetDigit(ll num) {
	ll digit = 0;
	while (num != 0) {
		num /= 10;
		digit++;
	}
	return digit;
}

using namespace std;
int main() {

	string s;
	cin >> s;

	if (s[2]== s[3] && s[4] == s[5])
	{
		cout << "Yes" << endl;

	}
	else {
		cout << "No" << endl;

	}
	


}

Measured memory_bytes: 256
// <sushi.cpp> - Sat Mar 25 08:49:56 2017
// This file is created by XuYike's black technology automatically.
// Copyright (C) 2015 ChangJun High School, Inc.
// I don't know what this program is.

#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std;
typedef long long lol;
template<typename T>
inline void gg(T &res){
    res=0;T fh=1;char ch=getchar();
    while((ch>'9'||ch<'0')&&ch!='-')ch=getchar();
    if(ch=='-')fh=-1,ch=getchar();
    while(ch>='0'&&ch<='9')res=res*10+ch-'0',ch=getchar();
    res*=fh;
}
inline int gi(){int x;gg(x);return x;}
inline lol gl(){lol x;gg(x);return x;}
const int MAXN=100010;
const int MAXK=MAXN<<2;
const lol INF=1e18;
int n,pos[MAXN];
lol val[MAXK],lazy[MAXK],mi[MAXK];
inline void update(int x){
    val[x]=val[x<<1]+val[x<<1|1];
    mi[x]=min(mi[x<<1],mi[x<<1|1]);
}
void pushdown(int x,int l,int r){
    if(!lazy[x])return;
    int m=l+r>>1;
    val[x<<1]=(m-l+1)*lazy[x];
    val[x<<1|1]=(r-m)*lazy[x];
    mi[x<<1]=mi[x<<1|1]=lazy[x<<1]=lazy[x<<1|1]=lazy[x];
    lazy[x]=0;
}
lol getsum(int L,int R,int l=1,int r=n,int x=1){
    if(l==L&&r==R)return val[x];
    pushdown(x,l,r);
    int m=l+r>>1;lol ans=0;
    if(L<=m)ans+=getsum(L,min(R,m),l,m,x<<1);
    if(R>m)ans+=getsum(max(L,m+1),R,m+1,r,x<<1|1);
    return ans;
}
int find(int p,lol s,lol y,int l=1,int r=n,int x=1){
    if(l==r)return l;
    pushdown(x,l,r);
    int m=l+r>>1;
    if(p<=m||s-val[x<<1]+y>mi[x<<1]*(p-m))return find(p,s,y,l,m,x<<1);
    return find(p,s-val[x<<1],y,m+1,r,x<<1|1);
}
void set(int L,int R,lol v,int l=1,int r=n,int x=1){
    if(L>R)return;
    if(l==L&&r==R){
        val[x]=(r-l+1)*v;
        lazy[x]=mi[x]=v;
        return;
    }
    pushdown(x,l,r);
    int m=l+r>>1;
    if(L<=m)set(L,min(R,m),v,l,m,x<<1);
    if(R>m)set(max(L,m+1),R,v,m+1,r,x<<1|1);
    update(x);
}
void dfs(int l,int r,int x){
    if(l==r){printf("%lld\n",val[x]);return;}
    pushdown(x,l,r);
    int m=l+r>>1;
    dfs(l,m,x<<1);
    dfs(m+1,r,x<<1|1);
}
int main(){
    n=gi();int m=gi();
    while(m--){
        int x=gi();
        lol s=getsum(1,x),y=gl();
        int p=find(x,s,y);s=getsum(p,x);
        set(p,x,(y+s)/(x-p+1));
        set(p,p+(y+s)%(x-p+1)-1,(y+s)/(x-p+1)+1);
    }
    dfs(1,n,1);
    return 0;
}

Measured memory_bytes: 9856
//#include<bits/stdc++.h>
#include<cstdio>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

const int dm = 1 << 20;
char dn[dm], * di = dn;
inline void putint(int X) {
	int keta = 0;
	char C[6];
	while (X) {
		*(C + keta) = '0' + X % 10;
		X /= 10;
		keta++;
	}
	for (int i = keta - 1; i >= 0; i--)* di++ = (*(C + i));
	*di++ = '\n';
}

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


	int N = getint(), L = getint();
	int A[100000];
	rep(i, N) A[i] = getint();

	int saidai = 0;
	int basho = 0;
	rep(i, N - 1) {
		int kari = A[i] + A[i + 1];
		if (kari > saidai) {
			saidai = kari;
			basho = i;
		}
	}

	if (saidai >= L) {
		*di++ = 'P';
		*di++ = 'o';
		*di++ = 's';
		*di++ = 's';
		*di++ = 'i';
		*di++ = 'b';
		*di++ = 'l';
		*di++ = 'e';
		*di++ = '\n';
		rep(i, basho) {
			putint(i + 1);
		}
		for (int i = N - 1; i > basho + 1; i--) {
			putint(i);
		}
		putint(basho + 1);
	}
	else {
		*di++ = 'I';
		*di++ = 'm';
		*di++ = 'p';
		*di++ = 'o';
		*di++ = 's';
		*di++ = 's';
		*di++ = 'i';
		*di++ = 'b';
		*di++ = 'l';
		*di++ = 'e';
		*di++ = '\n';
	}
	fwrite(dn, 1, di - dn, stdout);

	Would you please return 0;
}

Measured memory_bytes: 1792
<?php
//error_reporting(0);
$K = (int)trim(fgets(STDIN));
//$S = trim(fgets(STDIN));
//list($N,$K) = array_map('intval',explode(" ",trim(fgets(STDIN))));
//$a = array_map('intval',explode(" ",trim(fgets(STDIN))));

$q = new SplQueue();
for($i=1;$i<10;$i++) {
  $q->enqueue($i);
}
for($i=0;$i<$K;$i++) {
  $x = $q->dequeue();
  if ($i==$K-1) {
    printf("%d\n",$x);
    exit;
  }
  if (($x % 10)!=0) {
    $q->enqueue(10*$x+$x%10-1);
  }
  $q->enqueue(10*$x+$x%10);
  if (($x % 10)!=9) {
    $q->enqueue(10*$x+$x%10+1);
  }
}


Measured memory_bytes: 10744
#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};

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

ll dp[100010][13];

ll m[100010];

void f(ll n)
{
    m[0] = 1;
    for (ll i = 0; i <= n; i++)
    {
        m[i + 1] = (m[i] * 10) % 13;
    }
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    ll n = s.size();
    f(100005);
    dp[0][0] = 1LL;
    for (ll i = n - 1; i >= 0; i--)
    {
        ll it = n - i - 1;
        for (ll j = 0; j < 13; j++)
        {
            if (s[i] == '?')
            {
                for (ll num = 0; num < 10; num++)
                {
                    ll amari = (j + (num * m[it]) % 13) % 13;
                    (dp[it + 1][amari] += dp[it][j]) %= MOD;
                }
            }
            else
            {
                ll num = s[i] - '0';
                ll amari = (j + (num * m[it]) % 13) % 13;
                (dp[it + 1][amari] += dp[it][j]) %= MOD;
            }
        }
    }
    cout << dp[n][5] << endl;
}

Measured memory_bytes: 11472
using static System.Math;
using System;

public class hello
{
    public static void Main()
    {
        while (true)
        {
            string[] line = Console.ReadLine().Trim().Split(' ');
            var a = Array.ConvertAll(line, int.Parse);
            if (a[0] == 0) break;
            var ans = getAns(a);
            Console.WriteLine(ans);
        }
    }
    static int getAns(int[] a)
    {
        var p = a[0];
        var c = new int[] { 500, 100, 50, 10, 5, 1 };
        var ans = int.MaxValue;
        for (int i = p; i <= p + 500; i++)
        {
            var w1 = getPay(c, a, i);
            if (w1 != -1)
            {
                var w2 = getChange(c, i - p);
                ans = Min(ans, w1 + w2);
            }
        }
        return ans;
    }

    static int getPay(int[] c, int[] a, int t)
    {
        var ans = 0;
        var p = 6;
        foreach (var x in c)
        {
            var w = t / x;
            var w2 = Min(a[p--], w);
            ans += w2;
            t -= x * w2;
        }
        return t == 0 ? ans : -1;
    }
    static int getChange(int[] c, int a)
    {
        var ans = 0;
        foreach (var x in c)
        {
            var w = a / x;
            ans += w;
            a -= x * w;
        }
        return ans;
    }
}



Measured memory_bytes: 13948
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>

using namespace std;
#define rep(i, n) for (ll i = 0; i < n; i++)
using ll = long long;

int main() {
	vector<ll> data(4);
	rep(i, 4) {
		cin >> data.at(i);
	}

	ll result = data.at(0)*data.at(2);

	rep(i, 2) {
		for (int j = 2; j < 4; j++) {
			ll a = data.at(i) * data.at(j);
			result = max(a, result);
		}
	}
	cout << result << endl;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
int main() {
  int n;
  cin >> n;
  vi x(n);
  rep(i,n) cin >> x[i];
  int ans = 10000000;
  rep(i,100){
    int sum = 0;
    rep(j,n){
      sum += pow(x[j]-i,2);
    }
    ans = min(ans,sum);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256