akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.EmptyStackException;
import java.util.Stack;

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

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		//PrintWriter out = new PrintWriter(System.out);
		try {
			//入力受け取り
			String input = br.readLine();

			//変数定義
			Stack<String> stack1 = new Stack<>(); // 水たまりの総面積を求めるためのスタック
			Stack<String> stack2 = new Stack<>(); // 水たまりの左の場所
			Stack<String> stack3 = new Stack<>(); // 水たまりの各面積
			int sum = 0; //総面積
		//	boolean flag = true;
			//String left;
			//String dummy = "dummy"; //stack用dammy
			//stack2.push(dummy);
			
			//水たまりの総面積処理
			for(int i = 0; i < input.length(); i++) {
				
				if(input.substring(i, i+1).equals("\\")){
					stack1.push(String.valueOf(i));

				} else if(input.substring(i, i+1).equals("/")) {
					try {
					String left = stack1.pop();
					int sum1 = 1 + (i - Integer.parseInt(left) - 1);
					sum += sum1;
					stack2.push(left); //各水たまりの左の位置保存
					stack3.push(String.valueOf(sum1)); //各水たまりの面積保存
				//	System.out.println(stack3 + " +" + sum1);
					
					//各水たまりの統合判定
					while(stack2.size() > 1) {
						String leftnowS = stack2.pop();
						int leftnowN = Integer.parseInt(leftnowS);
						int leftprev = Integer.parseInt(stack2.peek());
						
						if(leftnowN < leftprev) {
							stack3.push(String.valueOf(Integer.parseInt(stack3.pop()) + Integer.parseInt(stack3.pop())));
						//	System.out.println("統合後: " + stack3);
							stack2.pop();
							stack2.push(leftnowS);
						/*	String l = stack2.pop();
							String m = stack2.pop();
							String n = stack2.pop();
							if(Integer.parseInt(m) > Integer.parseInt(n)) {
							stack2.pop();
						}*/
							
						} else {
							stack2.push(leftnowS);
							break;
						}
					}		
					
					}catch(EmptyStackException e) {
					//	System.out.println("error");
						//System.out.println(stack3.peek());
					}
					}
			}
			System.out.println(sum); //水たまりの総面積出力
			
			//各水たまり出力
			System.out.print(stack3.size());
			if(stack3.size() > 0) {
				System.out.print(" ");
			} else {
				System.out.println();
			}
				try {
					String[] a = new String[stack3.size()];
					for(int i = 0; i < a.length; i++) {
						a[i] = stack3.pop();
					}
					for(int i = a.length - 1; i >= 0; i--) {
				System.out.print(a[i]);
				if(i > 0) {
				System.out.print(" ");
				} else {
					System.out.println();
					break;
				}
					}
				} catch(EmptyStackException e) {
					System.out.println("error3");
				}
			
			
		} catch(IOException e) {
			System.out.println("error2");

		}


	}
	
	}



Measured memory_bytes: 35772
#include <iostream>

using namespace std;

int main() {

	int a1, a2, a3, a4, b1, b2, b3, b4, h, b;

	while(cin >> a1 >> a2 >> a3 >> a4 >> b1 >> b2 >> b3 >> b4) {
		h=0;
		b=0;
		if(a1==b1)
			h++;
		if(a2==b2)
			h++;
		if(a3==b3)
			h++;
		if(a4==b4)
			h++;
		if(a1==b2||a1==b3||a1==b4)
			b++;
		if(a2==b3||a2==b4||a2==b1)
			b++;
		if(a3==b4||a3==b1||a3==b2)
			b++;
		if(a4==b1||a4==b2||a4==b3)
			b++;
		cout << h << " " << b << endl;
	}

	return 0;

}

Measured memory_bytes: 0
fun main(args: Array<String>) {
    val N = readLine()!!.toInt()
    val S = (0 until N).map { readLine()!! }
    val nums = S.map { it.first() }.groupBy { it }.mapValues { it.value.size.toLong() }
    val march = "MARCH".map { nums[it] ?: 0 }

    val sum = (0 until 5).map { first -> (first + 1 until 5).map { second ->
        (0 until 5).filter { it != first && it != second }.map{ march[it] }.reduce { a, b -> a * b }
    }.fold(0L) { a, b -> a + b} }.fold(0L) {a, b -> a + b}
    println(sum)
}

Measured memory_bytes: 39648
#include <bits/stdc++.h>
#define INF (1<<30)
using ll = long long;
using namespace std;
 
int main(){
	
	int N;
	string S;
	cin >> N;
	cin >> S;
	int table[N];
	
	for(int i=0; i<N; ++i){
			table[i] = 0;
	}
	
	for(int i=0; i<26; ++i){
		char tg = i+'a';
		for( int j=0; j<N; ++j ){
			if( S[j] == tg ){
				table[j]++;
				break;
			}
		}
		for( int j=N-1; 0<=j; --j ){
			if( S[j] == tg ){
				table[j]--;
				break;
			}
		}
	}
	
	for(int i=0; i<N; ++i){
		if( 0 < i ){
			table[i] += table[i-1];
		}
	}
	
	int max = 0;
	for(int i=0; i<N; ++i){
		if( max < table[i] ){
			max = table[i];
		}
	}
	
	cout << max << endl;
	
	return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {

  public static void main(String[] args) throws IOException {
    
    try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {

      String line;
      String[] diceNumStr;
      int[] diceNum = new int[6+1];
      while(true) {

        if( (line = br.readLine()) == null || line.isEmpty() ) break;

        diceNumStr = line.split(" ");
        for ( int i=0; i < 6; i++)
          diceNum[i+1] = Integer.parseInt(diceNumStr[i]);

        Dice dice1 = new Dice(diceNum);
        System.out.println(dice1.doRotate(br.readLine()));
      }
    }
  }
}

class Dice {
  private int[] side;

  public Dice( int s1, int s2, int s3, int s4, int s5, int s6 ) {
    side = new int[]{ 0,s1,s2,s3,s4,s5,s6 };
  }
  public Dice( int[] s ) {
    side = Arrays.copyOf(s, s.length);
  }

  public int getUpSideNum() {
    return side[1];
  }

  public int doRotate(String s) {
    for ( int i=0; i < s.length(); i++ ) {
      rotate(s.substring(i, i+1));
    }
    return side[1];
  }

  private void rotate(String o) {
    switch(o) {
      case "N" :
        rotateN();
        break;
      case "S" :
        rotateS();
        break;
      case "W" :
        rotateW();
        break;
      case "E":
        rotateE();
        break;
      default :
    }
  }

  private void rotateN() {
    int tmp = side[1];
    side[1] = side[2]; side[2] = side[6]; side[6] = side[5];
    side[5] = tmp;
  }
  private void rotateS() {
    int tmp = side[1];
    side[1] = side[5]; side[5] = side[6]; side[6] = side[2];
    side[2] = tmp;
  }
  private void rotateW() {
    int tmp = side[1];
    side[1] = side[3]; side[3] = side[6]; side[6] = side[4];
    side[4] = tmp;
  }
  private void rotateE() {
    int tmp = side[1];
    side[1] = side[4]; side[4] = side[6]; side[6] = side[3];
    side[3] = tmp;
  }
}


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

using namespace std;

typedef long long int ll;

vector <ll> veca,vecb;
int main()
{
    ll n,a,b,b1,c,c1,i,j,k,p,q,minn=100;
    p=0;
    q=0;
    c=0;
    cin >> n;
    for (i=1; i<=n; i++)
    {
        cin >> a;
        veca.push_back(a);
        vecb.push_back(i);
    }
    for (i=0;i<veca.size();i++)
    {
        if (veca[i]!=vecb[i])
            c++;
    }
    if (c>2)
        cout << "NO\n";
    else
        cout << "YES\n";
}


Measured memory_bytes: 256
x,y=map(int,input().split())
k=[1,2,3]
l=[0,300000,200000,100000]
p=0
if x in k:
  p+=l[x]
if y in k:
  p+=l[y]
if x==1 and y==1:
  p+=400000
print(p)
  



Measured memory_bytes: 3060
import java.util.Scanner;
import java.util.regex.MatchResult;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main {
	private static int[] mcxi = {
	        1000, 100, 10, 1
	};
	private static char[] s = {
	        'm', 'c', 'x', 'i'
	};
	static Pattern pt = Pattern.compile("(([2-9]?)m)?(([2-9]?)c)?(([2-9]?)x)?((\\d?)i)?");
	static Matcher mc = pt.matcher("");

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < n; i++) {
			int sum = 0;
			for (int j = 0; j < 2; j++) {
				// String next=in.next();
				// mc.reset(next).matches();
				// int val = val(mc);
				int val = val2(in.next().toCharArray());
				sum += val;
			}
			sb.setLength(0);
			for (int j = 0; j < 4; j++) {
				int mn = sum / mcxi[j];
				sum %= mcxi[j];
				if (mn > 0) {
					if (mn > 1) {
						sb.append(mn);
					}
					sb.append(s[j]);
				}
			}
			System.out.println(sb);
		}
	}

	static int val2(char[] cs) {
		int result = 0;
		int a = 1;
		for (char c : cs) {
			for (int i = 0; i < 4; i++) {
				if (s[i] == c) {
					a *= mcxi[i];
					result += a;
					a = 1;
				}
			}
			if ('2' <= c && c <= '9') {
				a *= Character.digit(c, 10);
			}
		}
		return result;
	}

	static int val(MatchResult mr) {
		int result = 0;
		for (int i = 0; i < 4; i++) {
			if (mr.group(i * 2 + 1) != null) {
				result += mcxi[i] * ((!mr.group(i * 2 + 2).isEmpty()) ? Integer.parseInt(mr.group(i * 2 + 2)) : 1);
			}
		}
		return result;
	}
}

Measured memory_bytes: 12000
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
const int MOD = 924844033;
int a[4100],fac[4100],dp[4100][4100][2],n,k,cnt;
int main(){
    fac[0]=1;
    for(int i=1;i<=4000;i++)
        fac[i]=(1LL*fac[i-1]*i)%MOD;
    scanf("%d %d",&n,&k);
    for(int i=1;i<=k;i++){
        for(int j=0;j+i<=n;j+=k)
            a[++cnt]=j+i;
        for(int j=0;j+i<=n;j+=k)
            a[++cnt]=j+i;
    }
    // printf("cnt=%d\n",cnt);
    a[0]=0x3f3f3f3f;
    dp[0][0][0]=1;
    for(int i=1;i<=cnt;i++){
        dp[i][0][0]=1;
        for(int j=1;j<=i;j++){
            dp[i][j][0]=(dp[i-1][j][1]+dp[i-1][j][0])%MOD;
            if(a[i]-a[i-1]==k)
                dp[i][j][1]=dp[i-1][j-1][0];
        }
    }
    int ans=0,F;
    for(int i=0;i<=n;i++){
        F=(dp[cnt][i][0]+dp[cnt][i][1])%MOD;
        ans=(ans+1LL*((i&1)?-1:1)*F*fac[n-i])%MOD;
    }
    printf("%d\n",(ans%MOD+MOD)%MOD);
    return 0;
}

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

#define F first 
#define S second
#define PB push_back

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;
typedef priority_queue<int> HEAP;
typedef priority_queue<int, vector<int>, greater<int> > RHEAP;

const int N = 55, M = 1010;

int n, m;
int a[N];
LL f[N][N][N * N];

int main()
{
	cin >> n >> m;
	for (int i = 1; i <= n; i ++ ) cin >> a[i];
	
	for (int i = 0; i <= n; i ++ ) f[i][0][0] = 1;
	
	for (int i = 1; i <= n; i ++ )
		for (int j = 1; j <= i; j ++ )
			for (int k = 0; k < N * N; k ++ )
			{
				f[i][j][k] += f[i - 1][j][k];
				if (k >= a[i]) f[i][j][k] += f[i - 1][j - 1][k - a[i]];
			}
	
	LL res = 0;
	for (int i = 1; i <= n; i ++ ) res += f[n][i][i * m];
	cout << res << endl;
    return 0;
}

Measured memory_bytes: 34136
import sys
input=sys.stdin.readline

n=int(input())
s=[ord(i)for i in input()]
t=[-1]*n
for i in range(n):
  if s[i]==68:
    t[i]=0
  elif s[i]==77:t[i]=1
  elif s[i]==67:t[i]=2

def solve(k):
  dd=mm=dm=dmc=0
  for i in range(n):
    if t[i]==0:dd+=1
    if i>=k and t[i-k]==0:dm-=mm;dd-=1
    if t[i]==1:dm+=dd;mm+=1
    if i>=k and t[i-k]==1:mm-=1
    if t[i]==2:dmc+=dm
  return dmc

q=int(input())
k=list(map(int,input().split()))
for i in k:print(solve(i))

Measured memory_bytes: 88180
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

S = input()
N = len(S)
S2 = S[:(N-1)//2]
S3 = S[(N+3)//2-1:]
if S == S[::-1] and S2 == S2[::-1] and S3 == S3[::-1]:
	print("Yes")
else:
	print("No")


Measured memory_bytes: 5204
import java.util.*;
class Main {

  public static void main(String[] args) {

    Scanner scan = new Scanner(System.in);
    char[] consonne = new char[]{'a','e','i','o','u','y'};

    char lettre = scan.next().charAt(0);

    boolean appartient = false;

    for (int i = 0; i < consonne.length; i++){

      if (lettre == consonne[i]){
        appartient = true;
      }

    }

    if (appartient)
      System.out.println("vowel");
    else{
      System.out.println("consonant");
    }



  }

}


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

int main() {
	ll n;
	cin >> n;
	vector<ll>prime;
	ll md = 2;
	ll o = sqrt(n);
	while (md<=o) {
		if (n % md == 0) {
			prime.push_back(md);
			n /= md;
		}
		else md++;
	}
	if (n != 1)prime.push_back(n);

	map<ll, ll>ps;
	for (int i = 0; i < prime.size(); i++) {
		if (ps.count(prime.at(i)))ps.at(prime.at(i))++;
		else ps[prime.at(i)] = 1;
	}
	ll ans = 0;
	for (auto x : ps) {
		//cout << x.first << x.second << ans << endl;
		ll y = x.second;
		ll ct = 1;
		while (y >= 0) {
			y -= ct;
			if (y < 0)break;
			ans++;
			ct++;
		}
	}
	cout << ans << endl;

}

Measured memory_bytes: 3724
// D - 3N Numbers
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using VL = vector<ll>;
#define rp(i,s,e) for(int i=(s);i<(e);++i)
#define irp(i,s,e) for(int i=(s);i>(e);--i)
#define pq priority_queue

void v_print(VL v,int N){rp(i,0,N) printf("%d,",v[i]);puts("");}//

void pq_print(pq<int> q){printf("[");while(!q.empty()){printf("%d,",q.top());q.pop();}puts("]");}//

#define NMAX 100000
int N;
VL A(3*NMAX);

int main(){
	cin>>N;
	int N2 = N*2;
	int N3 = N*3;
	rp(a, 0, N3) cin>>A[a];

	VL F(N+1);
	pq<int> fque;
	rp(a, 0, N){
		fque.push(-A[a]);
		F[0] += A[a];
	}
	rp(f, 0, N){
		int a = N + f;
		fque.push(-A[a]);
		F[f+1] += F[f] + A[a] - (-fque.top());
		fque.pop();
	}

	VL B(N+1);
	pq<int> bque;
	irp(a, N3-1, N2-1){
		bque.push(A[a]);
		B[N] += A[a];
	}
	for(int a=N2-1, b=N-1; b>0-1; --b, --a){
		bque.push(A[a]);
		B[b] = B[b+1] + A[a] - (bque.top());
		bque.pop();
	}

	ll maxfb = LLONG_MIN;
	rp(i, 0, N+1){
		maxfb = max(maxfb, F[i]-B[i]);
	}
	cout<< maxfb <<endl;
}

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

int main() {
  int n;
  cin >> n;
  int x = 0;
  vector<int> a(n);
  for(int i=0;i<n;i++){
    cin >> a.at(i);
    x += a.at(i);
  }
  sort(a.begin(), a.end());
  
  if(x%10 != 0){
    cout << x << endl;
  }
  
  else {
    int j=0;
    while(a.at(j)%10 == 0){
      j++;
      if(j == n){
        break;
      }
    }
    if(j==n && a.at(j-1)%10 == 0){
      a.at(j-1) = x;
      j = j-1;
    }
    
    cout << x - a.at(j) << endl;
  }
}


Measured memory_bytes: 256
//lib
function readInt(str){
    return parseInt(str, 10);
}
function gcd(a:number, b:number){
    if(a==0)return b;
    return gcd(b%a, a);
}
//main
function Main(raw) {
    const input = raw.split("\n");
    const [N] = input[0].split(" ").map(readInt);
    const A:number[] = input[1].split(" ").map(readInt);
    const ans=A.reduce((pre,cur,ind,arr)=>gcd(pre, cur), 0);
    
    //出力
    console.log("%d", ans);
}
  
//DO NOT EDIT
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
  

Measured memory_bytes: 19168
#include<iostream>
#include<algorithm>
using lint=int64_t;
using namespace std;

int main()
{
	lint N,A,B,C,D;

	cin >> N >> A >> B >> C >> D;

	for(int i=0;i<N;i++)
	{
		if(C*i-D*(N-1-i)<=B-A && B-A<=D*i-C*(N-1-i))
		{
			cout << "YES" << endl;
			return 0;
		}
	}
	
	cout << "NO" << endl;
	return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;int*t,n,m,d,i,s[99999];main(){for(;cin>>d>>n>>m;cout<<i<<'\n'){for(s[i=n]=d;--i;)cin>>s[i];for(sort(s,s+n);m--;i+=min(d-*--t,*t-d))cin>>d,t=upper_bound(s,s+n,d);}}

Measured memory_bytes: 1252
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <numeric>
#include <map>
#include <utility>
using namespace std;
#define ll long long
#define rep(i,l,r) for(ll i=(l);i<(r);i++)
int main(void){
    int n,a;
    ll cnt=0;
    cin>>n;
    ll sum[n];
    sum[0]=0;
    rep(i,1,n+1){
        cin>>a;
        sum[i]=sum[i-1]+a;
    }
    sort(sum,sum+n+1);
    int chain=1;
    rep(i,1,n+1){
        if(sum[i]==sum[i-1])chain++;
        else chain=1;
        cnt+=chain-1;
    }
    cout<<cnt<<endl;
    return 0;
}

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


int main() {
    int n;
    scanf("%d", &n);
    
    vector<vector<int>> h(n, vector<int>(3,INT_MAX));
    
    for(int i=0; i<n; i++) {
        scanf("%d %d %d", &h[i][0], &h[i][1], &h[i][2]);
      //  printf("%d %d %d\n", h[i][0], h[i][1], h[i][2]);
    }
    vector<int> dp(3, INT_MAX);
    dp[0] = h[0][0];
    dp[1] = h[0][1];
    dp[2] = h[0][2];
    
    for(int i=1; i<n; i++) {
        int a,b,c;
        a = dp[0]; b = dp[1]; c = dp[2];
        dp[0] = h[i][0] + max(b,c);
        dp[1] = h[i][1] + max(a,c);
        dp[2] = h[i][2] + max(a,b);
    }
    sort(dp.begin(), dp.end());

    printf("%d\n", dp[2]);
}

Measured memory_bytes: 8832
import java.util.*;

public class Main {
 	public static void main(String[] args){
    	Scanner s = new Scanner(System.in);
      	int n = s.nextInt();
      	int m = s.nextInt();
      	int[][] arr = new int[n][m];
      	for(int i = 0; i < n; i++) {
         	for(int j = 0; j < m; j++) {
             	arr[i][j] = s.nextInt();
            }
        }
      
      	int count = 0;
      	for(int i = 0; i < n; i++ ) {
         	for(int j = i + 1; j < n; j++) {
              	int sum = 0;
            	for(int k = 0; k < m; k++ ){
                 	 sum += Math.pow(arr[j][k] - arr[i][k], 2);
                }
              	int sqrt = (int)(Math.sqrt(sum));
              	if(sqrt * sqrt == sum) {
                	count++;
                }
            }
        }
      System.out.println(count);
    }
}

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

Measured memory_bytes: 256
#include <functional>
#include <iostream>
#include <vector>

template <class T> inline bool chmin(T &a, const T &b) {
  return (a > b) ? a = b, true : false;
}

int main() {
  int N;
  std::cin >> N;
  std::vector<long long> a(N);
  for (int i = 0; i < N; ++i)
    std::cin >> a[i];

  long long inf = 1LL << 60;
  std::vector<std::vector<long long>> dp(N + 3,
                                         std::vector<long long>(N + 3, inf));

  std::vector<long long> s(N + 3, 0);
  for (int i = 0; i < N; ++i)
    s[i + 1] = s[i] + a[i];

  std::function<long long(int, int)> rec = [&](int l, int r) {
    if (dp[l][r] != inf)
      return dp[l][r];
    if (l + 1 == r)
      return dp[l][r] = 0;
    long long res = inf;
    for (int k = l + 1; k < r; ++k) {
      long long lc = rec(l, k);
      long long rc = rec(k, r);
      chmin(res, lc + rc + s[r] - s[l]);
    }
    return dp[l][r] = res;
  };

  std::cout << rec(0, N) << std::endl;
}


Measured memory_bytes: 1536
N, M = map(int, input().split(" "))
X = list(map(int, input().split(" ")))

X.sort()
X_d = [X[i+1]-X[i] for i in range(M-1)]
X_d.sort()

# print(X_d, N)
print(sum(X_d[:max(0, M-N)]))

Measured memory_bytes: 13960
#include <bits/stdc++.h>
#define int long long
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
#define INF LLONG_MAX
#define eps LDBL_EPSILON
#define moder 1000000007
#define pie 3.141592653589793238462643383279
#define P std::pair<int,int>
#define prique priority_queue
using namespace std;
int a,b,q,s[100010],t[100010];
signed main(){
	cin>>a>>b>>q;
	rep(i,a)cin>>s[i];
	rep(i,b)cin>>t[i];
	sort(s,s+a);
	sort(t,t+b);
	rep(i,q){
		int x;
		cin>>x;
		int ans=INF;
		int c[4]={-1,-1,-1,-1};
		if(lower_bound(s,s+a,x)<s+a)c[0]=*lower_bound(s,s+a,x);
		if(s<=lower_bound(s,s+a,x)-1)c[1]=*(lower_bound(s,s+a,x)-1);
		if(lower_bound(t,t+b,x)<t+b)c[2]=*lower_bound(t,t+b,x);
		if(t<=lower_bound(t,t+b,x)-1)c[3]=*(lower_bound(t,t+b,x)-1);
		if(c[1]>=0&&c[2]>=0)ans=min(ans,c[2]-c[1]+min(abs(x-c[2]),abs(x-c[1])));
		if(c[0]>=0&&c[3]>=0)ans=min(ans,c[0]-c[3]+min(abs(x-c[0]),abs(x-c[3])));
		if(c[0]>=0&&t<=lower_bound(t,t+b,c[0])&&lower_bound(t,t+b,c[0])<t+b)ans=min(ans,*lower_bound(t,t+b,c[0])-x);
		if(c[1]>=0&&t<=upper_bound(t,t+b,c[1])-1&&lower_bound(t,t+b,c[1])-1<t+b)ans=min(ans,x-*(upper_bound(t,t+b,c[1])-1));
		if(c[2]>=0&&s<=lower_bound(s,s+a,c[2])&&lower_bound(s,s+a,c[2])<s+a)ans=min(ans,*lower_bound(s,s+a,c[2])-x);
		if(c[3]>=0&&s<=upper_bound(s,s+a,c[3])-1&&lower_bound(s,s+a,c[3])-1<=s+a)ans=min(ans,x-*(upper_bound(s,s+a,c[3])-1));
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 2816
n = int(input())
table = [[0 for i in range(3)] for k in range(n-1)]
for i in range(n-1):
	c,s,f = map(int,input().split())
	table[i][0] = c
	table[i][1] = s
	table[i][2] = f
for i in range(n-1):
	total = table[i][1]+table[i][0]
	for k in range(i+1,n-1):
		if total <= table[k][1]:
			total = table[k][1] + table[k][0]
		else:
			sur = total%table[k][2]
			if sur == 0:
				total = total + table[k][0]
			else:
				total = (total - sur) + table[k][2] + table[k][0]
	print(total)
print('0')

Measured memory_bytes: 3188
#include<iostream>
#include<iomanip>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstdio>

using namespace std;
typedef long long ll;
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;}
const long long INF = 1LL << 60;
typedef pair<int, int> P;





int main() {
    int A, B; cin >> A >> B;
    if (A > B) swap(A,B);
    if (A == 1 && B == 2) {
        cout << 3 << endl; 
    } 
    if (A == 2 && B == 3) {
        cout << 1 << endl; 
    } 
    if (A == 1 && B == 3) {
        cout << 2 << endl; 
    } 

}


Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

// fn main() {
//     let n: i64 = read();
//     let x: i64 = read();
//     let y: i64 = read();
//     let mut ans: Vec<i64> = (1..n).map(|_| 0).collect();
//     for i in 1..n+1 {
//         for j in i+1..n+1 {
//             let mut min = j - i;
//             let mut tmp = (x-i).abs() + 1 + (j-y).abs();
//             if tmp < min {
//                 min = tmp;
//             }
//             tmp = (y-i).abs() + 1 + (j-x).abs();
//             if tmp < min {
//                 min = tmp;
//             }
//             //println!("{} {} {}", i, j, min);
//             ans[min as usize - 1] += 1;
//         }
//     }

//     for a in ans {
//         println!("{}", a);
//     }
// }

use std::collections::VecDeque;

fn main() {
    let n: i64 = read();
    let mut x: i64 = read();
    let mut y: i64 = read();
    x -= 1; y -= 1;
    let mut ans: Vec<i64> = (0..n).map(|_| 0).collect();
    let INF: i64 = 1001001001;
    for i in 0..n {
        let mut dist: Vec<i64> =  (0..n).map(|_| INF).collect();
        let mut q: VecDeque<i64> = VecDeque::new();
        push(i, 0, &mut dist, &mut q, INF);
        while !q.is_empty() {
            let v = q.pop_front().unwrap();
            let d = dist[v as usize];
            if v-1 >= 0 {
                push(v-1, d+1, &mut dist, &mut q, INF);
            }
            if v+1 < n {
                push(v+1, d+1, &mut dist, &mut q, INF);
            }
            if v == x {
                push(y, d+1, &mut dist, &mut q, INF);
            }
            if v == y {
                push(x, d+1, &mut dist, &mut q, INF);
            }
        }
        for j in 0..n {
            ans[dist[j as usize] as usize] += 1;
        }
    }
    for i in 1..n {
        ans[i as usize] /= 2;
        println!("{}", ans[i as usize]);
    }
}

fn push(i: i64, d: i64, dist: &mut Vec<i64>, q: &mut VecDeque<i64>, INF: i64) {
    if dist[i as usize] != INF {
        return;
    }
    dist[i as usize] = d;
    q.push_back(i);
}

Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>

std::string s;
int k;
std::vector<std::pair<char, int>> vec;
std::vector<std::string> vec2;
std::set<std::string> set2;
size_t s_size;

int main() {
    std::cin >> s;
    std::cin >> k;
    s_size = s.size();
    for (int i = 0; i < s_size; i++) {
        vec.push_back(std::make_pair(s[i], i));
    }
    int j = 0;
    for (int i = 0; i < s_size; i++) {
        auto elem = vec[i];
        int p = 1;
        while (p <= k && elem.second + p <= s_size) {
            set2.insert(s.substr(elem.second, p));
            p++;
        }
    }
    vec2 = std::vector<std::string>(set2.begin(), set2.end());
    std::sort(vec2.begin(), vec2.end());
    std::cout << vec2[k-1] << std::endl;
}


Measured memory_bytes: 1792
import math

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

n,k = map(int,input().split())
mod = 10**9 + 7
for i in range(1,k+1):
    if n-k+1 < i:
        print(0)
    elif k-i== 0:
        print(combinations_count(n-k+1,i)% mod)
    else:
        a = math.factorial(k-1)//(math.factorial(k-i)*math.factorial(i-1))
        print((combinations_count(n-k+1,i)*a) % mod)

Measured memory_bytes: 3316
import java.util.*

val sc = Scanner(System.`in`)
val N = sc.nextInt()

fun main(args: Array<String>) {
    val a = Array(N) { 0 }
    for (i in 1..N) {
        a[i - 1] = sc.nextInt()
    }
    println(calc(a))
}

fun calc(a: Array<Int>): Int {
    var j = 1
    for (i in 1..N) {
        j = a[j - 1]
        if (j == 2) {
            return i
        }
    }
    return -1
}


Measured memory_bytes: 53284
n=int(input())
inp = list(map(int,input().split()))
ans=[0,abs(inp[1]-inp[0])]
for i in range(2,len(inp)):
    ans.append(min(ans[-1]+abs(inp[i]-inp[i-1]),ans[-2]+abs(inp[i]-inp[i-2])))
print (ans[-1])

Measured memory_bytes: 20492
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
#include <functional>
#include <queue>
#include <map>
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
const int INF = 1e9 +7;
char s[4];
int main(){
    cin >> s;
    
    int a = s[0]-'0',b = s[1] - '0', c = s[2] - '0', d = s[3] - '0';
    if(a+b+c+d==7) cout <<  s[0] << '+' << s[1] << '+' << s[2] << '+' << s[3] << '=' << 7 <<endl;
    else if(a+b+c-d==7) cout << s[0] << '+' << s[1] << '+' << s[2] << '-' << s[3] << '=' << 7 <<endl;
    else if(a-b-c+d==7) cout << s[0] << '-' << s[1] << '-' << s[2] << '+' << s[3] << '=' << 7 <<endl;
    else if(a+b-c-d==7) cout << s[0] << '+' << s[1] << '-' << s[2] << '-' << s[3] << '=' << 7<<endl;
    else if(a-b-c-d==7) cout << s[0] << '-' << s[1] << '-' << s[2] << '-' << s[3] << '=' << 7 <<endl;
    else if(a-b+c-d==7) cout << s[0] << '-' << s[1] << '+' << s[2] << '-' << s[3] << '=' << 7 <<endl;
    else if(a+b-c+d==7) cout << s[0] << '+' << s[1] << '-' << s[2] << '+' << s[3] << '=' << 7 <<endl;
    else if(a-b+c+d==7) cout << s[0] << '-' << s[1] << '+' << s[2] << '+' << s[3] << '=' << 7 <<endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
 
int main(){
        int x,y;
        while(cin>>x>>y,x){
                int D[16][16],P[16][16],ans=0;
                for(int i=0;i<256;i++)P[i/16][i%16]=0;
                for(int i=0;i<y;i++)for(int j=0;j<x;j++)cin>>D[i][j];
                for(int i=0;i<x;i++)if(!D[0][i])P[0][i]=1;
                for(int i=0;i<y-1;i++){
                        for(int j=0;j<x;j++){
                                if(!D[i][j]){
                                        P[i+1][j]+=P[i][j];
                                        if(j>0&&!D[i+1][j-1])P[i+1][j-1]+=P[i][j];
                                        if(j<x-1&&!D[i+1][j+1])P[i+1][j+1]+=P[i][j];
                                }
                                if(D[i][j]==2){
                                        if(i==y-2) ans += P[i][j];
                                        else P[i+2][j]+=P[i][j];
                                }
                        }
                }
                for(int i=0;i<x;i++){
                        if (D[y - 1][i] != 1)ans+=P[y-1][i];
                }
                cout<<ans<<endl;
        }
}
 

Measured memory_bytes: 0
fun main(args: Array<String>) {
  	val N = readLine()!!.toInt()
    val costs = readLine()!!.split(" ").map{it.toInt()}
    val cost_sum = Array(N,{0})
  	for(i in 2..N){
    dp(i,cost_sum,costs)
      
    }
 	 print(cost_sum[N-1])
}

fun dp(size:Int,cost_sum:Array<Int>,costs:List<Int>){
    if (size===2){
        cost_sum[size-1]=Math.abs(costs[size-1]-costs[size-2])
    }else{
        cost_sum[size-1]=Math.min(
          cost_sum[size-2]+Math.abs(costs[size-1]-costs[size-2]),
          cost_sum[size-3]+Math.abs(costs[size-1]-costs[size-3])
          )
    }
}


Measured memory_bytes: 48844
n = int(input())
s = input()

dp = [ [0] * (n+1) for _ in range(n+1)]

for i in range(n-1, -1, -1):
    for j in range(n-1, -1, -1):
        if s[i] == s[j]:
            dp[i][j] = dp[i+1][j+1] + 1
        else:
            dp[i][j] = 0

ans = 0
for i in range(n):
    for j in range(n):
        tmp = min(dp[i][j], abs(i-j))
        if ans < tmp:
            ans = tmp
print(ans)

Measured memory_bytes: 230664
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdio>
using namespace std;
int cnt[4];
int main()
{
    int n;
    cin>>n;
    while(n--)
    {
        string s;
        cin>>s;
        if(s=="AC") cnt[0]++;
        else if(s=="WA") cnt[1]++;
        else if(s=="TLE") cnt[2]++;
        else cnt[3]++;
    }
    printf("AC x  %d\n",cnt[0]);
    printf("WA x  %d\n",cnt[1]);
    printf("TLE x  %d\n",cnt[2]);
    printf("RE x  %d\n",cnt[3]);
    return 0;
}

Measured memory_bytes: 3700
fun main(array: Array<String>) {
    val s = readLine()!!
    var minA = s.length
    var maxZ = 0
    repeat(s.length) {
        if(s[it] == 'A') {
            val tempA = it
            if(tempA < minA) minA = tempA
        }
        if(s[it] == 'Z') {
            val tempZ = it
            if(maxZ < tempZ) maxZ = tempZ
        }
    }
    print(maxZ - minA + 1)
}

Measured memory_bytes: 34480
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll LINF = (1LL << 60) - 1LL;
constexpr ll MOD = 1e9 + 7;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    ll n = s.length();
    ll k;
    cin >> k;
    ll co = 1, cs = -1;
    ll ans = 0;
    for (int i = 1; i < n; i++) {
        if (s[i] == s[i - 1]) {
            co++;
        } else {
            if (cs == -1) {
                cs = co;
            } else {
                ans += (co / 2LL) * k;
            }
            co = 1;
        }
    }
    if (cs == -1) {
        cout << n * k / 2LL << endl;
        return 0;
    }
    if (s[n - 1] == s[0]) {
        ans += (k - 1LL) * ((co + cs) / 2LL);
        ans += co / 2LL;
        ans += cs / 2LL;
    } else {
        ans += (co / 2LL) * k;
        ans += (cs / 2LL) * k;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long int;
#define all(x) (x).begin(), (x).end()

int main (){
    string s;
    cin >> s;
    int N = (s.size() -1 )/2;
    int M = (s.size() +3 )/2;

    string t = s;
    reverse ( all(t) );
    if ( s == t ){
        string m = s.substr (0, N);
        string temp = m;
        reverse (all (temp) );

        //cout << "Substring : " << m << endl;
        if ( m == temp){
            string n = s.substr (M-1, s.size () );
            string temp2 = n;
            reverse (all (temp2));
            //cout << "Substring : " << n << endl;
            //cout << "M was : " << M << endl;
            if ( temp2 == n){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No " << endl;
}



Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
int n;
int s1,s2;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		int x;
		scanf("%d",&x);
		if(x&1)s1++;
		if(x%4==0)s2++;
	}
	if((s1>s2 && s1+s2!=n) || (s1+s2==n && s1>s2+1))
	{
		printf("No");
	}
	else printf("Yes");
	return 0;
} 

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,f[100010],p;
vector<int> a[100010];
inline void dfs(int i,int j)
{
	int k;
	for(k=0;k<a[i].size();k++)
	  if(a[i][k]!=j)
	    {
		 dfs(a[i][k],i);
		 if(!f[a[i][k]])
		   if(!f[i])
		     f[i]=1;
		   else
		     p=1;
		}
}
int main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	int i,j,k;
	scanf("%d",&n);
	for(i=1;i<n;i++)
	  {
	   scanf("%d%d",&j,&k);
	   a[j].push_back(k);
	   a[k].push_back(j);
	  }
	dfs(1,0);
	if(p || !f[1])
	  printf("First\n");
	else
	  printf("Second\n");
	return 0;
}


Measured memory_bytes: 6272
#include <iostream>
#include <vector>

using namespace std;

int main(){
  char b; cin>>b;

  if(b=='A') cout<<'T';
  else if(b=='T') cout<<'A';
  else if(b=='C') cout<<'G';
  else cout<<'C';

  cout<<endl;

  return 0;
}


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

int main()
{
  int num = 1;
  int n, k, i;
  cin >> n >> k;
  for(i = 0; i < n; i++)
  {
    if(num > k)
    {
      num += k;
    }
    else
    {
      num *= 2;
    }
  }
  cout << num << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>

int main() {
    std::string T;
    std::cin >> T;

    for (char c : T) {
        if (c == 'P') {
            std::cout << "P";
        } else {
            std::cout << "D";
        }
    }

    std::cout << "\n";
}

Measured memory_bytes: 3752
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const int INT_INF = 2147483647;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef pair<int,int> P;

int main(){
  char c;
  cin >> c;
  c++;
  cout << c << endl;
}


Measured memory_bytes: 256
//ABC105B
#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <climits>
#include <cfloat>
#include <string>
#include <unordered_map>
using namespace std;

int main(){
	int n;
	cin >> n;
	for(int i=0;i<=n/4;i++){
		for(int j=0;j<=n/7;j++){
			if(4*i+7*j == n){
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
    int N,i,result,first,second;
    int B[100];
    int A[101];

    
    scanf("%d",&N);
    
    for(i = 0 ; i < N-1 ; i++){
        scanf("%d",&B[i]);
    }
    for(i = 0 ; i < N ; i++){
        A[i] = 1000000;
    }

    
    result = 0;
 

    for(i = 0 ; i < N-1 ; i++){
        if(A[i] > B[i]){
            A[i] = B[i];
        }
        if(A[i+1] > B[i]){
            A[i+1] = B[i];
        }
    }

    for(i = 0 ; i < N ; i++){
        result += A[i];
    }

    printf("%d",result);

    return 0;

}


Measured memory_bytes: 128
#coding:utf-8

N = input()
lens = len(N)
N = int(N)
N2 = N
sn = 0
for i in range(lens-1, -1, -1):
    sn += N // 10**i
    N %= 10**i
if N2 % sn == 0:
    print("Yes")
else:
    print("No")



Measured memory_bytes: 2940
#include <iostream>
#include <cmath>

using namespace std;

int main()
{
    cin.tie(0);
   	ios::sync_with_stdio(false);
    
    int n;
    cin >> n;
    
    long long x[n], y[n], h[n];
    long long tx, ty, th;
    for (int i = 0; i < n; i++) {
        cin >> x[i] >> y[i] >> h[i];
        if (h[i] > 0) {
            tx = x[i];
            ty = y[i];
            th = h[i];
        }
    }
    
    for (long long cx = 0; cx <= 100; cx++) {
        for (long long cy = 0; cy <= 100; cy++) {
            bool flag = true;
            long long ch = max(th + abs(tx - cx) + abs(ty - cy), 0LL);
            for (int i = 0; i < n; i++) {
                flag = flag && (max(ch - abs(cx-x[i]) - abs(cy-y[i]), 0LL) == h[i]);
            }
            if (flag) {
                cout << cx << " " << cy << " " << ch << endl;
                return 0;
            }
        }
    }
}

Measured memory_bytes: 256
//abc163A
#include <malloc.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
 
int main(void) {
  float n, k, i, cou=0, tmp;
  scanf("%f", &n);
  printf("%f", n * 2*M_PI);
}
 

Measured memory_bytes: 1744
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.util.NoSuchElementException;
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;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        APoor solver = new APoor();
        solver.solve(1, in, out);
        out.close();
    }

    static class APoor {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int a = in.nextInt();
            int b = in.nextInt();
            int c = in.nextInt();
            String str = "No";
            if (a == b && a != c) {
                str = "Yes";
            } else if (a == c && b != c) {
                str = "Yes";
            } else if (b == c & b != a) {
                str = "Yes";
            }

            out.println(str);
        }

    }

    static class Scanner {
        private final InputStream in;
        private final byte[] buffer;
        private int ptr;
        private int buflen;

        public Scanner(InputStream in) {
            this.in = in;
            this.buffer = new byte[1024];
            this.ptr = 0;
            this.buflen = 0;
        }

        private boolean hasNextByte() {
            if (ptr < buflen) return true;
            else {
                ptr = 0;
                try {
                    buflen = in.read(buffer);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (buflen <= 0) return false;
            }
            return true;
        }

        private byte readByte() {
            if (hasNextByte()) return buffer[ptr++];
            return -1;
        }

        private boolean isPrintableChar(byte c) {
            return '!' <= c && c <= '~';
        }

        private void skipUnprintable() {
            while (hasNextByte() && !isPrintableChar(buffer[ptr])) {
                ptr++;
            }
        }

        public boolean hasNext() {
            skipUnprintable();
            return hasNextByte();
        }

        public int nextInt() {
            if (!hasNext()) throw new NoSuchElementException();
            int n = 0;
            boolean minus = false;
            byte b = readByte();
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            if (b < '0' || '9' < b) throw new NumberFormatException();
            while (true) {
                if ('0' <= b && b <= '9') {
                    n *= 10;
                    n += b - '0';
                } else if (b == -1 || !isPrintableChar(b)) {
                    return minus ? -n : n;
                } else {
                    throw new NumberFormatException();
                }
                b = readByte();
            }
        }

    }
}



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

namespace AtCoder.Abc.A
{
    public class Question
    {
        public static void Main(string[] args)
        {
            new Question().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            var k = cin.ReadInt;
            var x = cin.ReadInt;
            Console.WriteLine(k * 500 >= x ? "Yes" : "No");
        }

        public class ConsoleInput
        {
            private readonly System.IO.TextReader _stream;
            private char _separator = ' ';
            private Queue<string> inputStream;
            public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
            {
                this._separator = separator;
                this._stream = stream;
                inputStream = new Queue<string>();
            }
            public string Read
            {
                get
                {
                    if (inputStream.Count != 0) return inputStream.Dequeue();
                    string[] tmp = _stream.ReadLine().Split(_separator);
                    for (int i = 0; i < tmp.Length; ++i)
                        inputStream.Enqueue(tmp[i]);
                    return inputStream.Dequeue();
                }
            }
            public string ReadLine { get { return _stream.ReadLine(); } }
            public int ReadInt { get { return int.Parse(Read); } }
            public long ReadLong { get { return long.Parse(Read); } }
            public double ReadDouble { get { return double.Parse(Read); } }
            public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
            public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
            public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
        }
    }
}


Measured memory_bytes: 27668
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,ans=0;
  map<string,int>m;
  cin>>a;
  while(a--){
   string s;
    cin>>s;
    m[s]++;
  }
  cin>>b;
  while(b--){
   string s;
    cin>>s;
    m[s]--;
  }
  map<string,int>::iterator it=m.begin();
  for(;it!=m.end();it++){
    ans=max(ans,(*it).second);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
ll MOD = 1e9+7;

int main() {
  int n;cin>>n;
  ll an[n];rep(i, n) cin>>an[i];
  ll sn[n+1];sn[n]=0;
  rep(i, n) {
    sn[n-1-i] = (sn[n-i] + an[n-1-i]) % MOD;
  }
  
  //rep(i, n) cout<<an[i]<<" ";cout<<endl;
  //rep(i, n+1) cout<<sn[i]<<" ";cout<<endl;
  
  ll ans = 0, s;
  rep(i, n-1) {
    s = (an[i] * sn[i+1]) % MOD;
    ans = (ans + s) % MOD;
  }
  cout<<ans;
}


Measured memory_bytes: 6744
/* {{{ */
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
/* }}} */

fn main() {
    input! {
        n: usize,
        k: usize,
        aa: [usize1;n]
    }
    let mut b = vec![None;n];
    let mut v = Vec::new();
    let mut p = 0;
    let mut l = 0;
    let mut r = 0;
    for i in 0.. {
        if let Some(x) = b[p] {
            l = x;
            r = i;
            break;
        }
        b[p] = Some(i);
        v.push(p);
        p = aa[p];
    }

    if k < l {
        println!("{}", v[k] + 1);
    } else {
        println!("{}", v[l + (k-l) % (r-l)] + 1);
    }
}
/* vim:set foldmethod=marker: */


Measured memory_bytes: 9372
S=str(input())

A=[int(S[0]+S[1]),int(S[2]+S[3])]
if (A[0]>0 and A[0]<=12) and (A[1]>0 and A[1]<=12):
    print('AMBIGUOUS')
elif (A[0]==0 or A[0]>12) and (A[1]>0 and A[1]<=12):
    print('YYMM')
elif (A[0]>0 and A[0]<=12) and (A[1]==0 or A[1]>12):
    print('MMYY')
else:
    print('NA')

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define N 300000 + 5
#define inf 123456789
#define mid (l + r >> 1)
#define ls (p << 1)
#define rs (p << 1 | 1)
#define rep(i, l, r) for(int i = l; i <= r; ++i)
struct tree{
    int max, tag;
}t[N << 2];
struct node{
    int x, y;
}a[N];
int h, w, n, ans, top1, top2, st1[N], st2[N];
int read(){
    char c; int x = 0, f = 1;
    c = getchar();
    while(c > '9' || c < '0'){ if(c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return x * f;
}
void lazy(int p, int l, int r, int k){
    t[p].max += k, t[p].tag += k;
}
void down(int p, int l, int r){
    if(!t[p].tag) return;
    lazy(ls, l, mid, t[p].tag), lazy(rs, mid + 1, r, t[p].tag);
    t[p].tag = 0;
}
void build(int p, int l, int r){
	t[p].tag = 0;
    if(l == r){ t[p].max = -a[l].x; return;}
    build(ls, l, mid), build(rs, mid + 1, r);
    t[p].max = max(t[ls].max, t[rs].max);
}
void update(int p, int l, int r, int x, int y, int k){
	if(x > y) return;
    if(l >= x && r <= y){ lazy(p, l, r, k); return;}
    down(p, l, r);
    if(mid >= x) update(ls, l, mid, x, y, k);
    if(mid < y) update(rs, mid + 1, r, x, y, k);
    t[p].max = max(t[ls].max, t[rs].max);
}
int query(int p, int l, int r, int x, int y){
	if(x > y) return -inf;
    if(l >= x && r <= y) return t[p].max;
    down(p, l, r);
    int ans = -inf;
    if(mid >= x) ans = max(ans, query(ls, l, mid, x, y));
    if(mid < y) ans = max(ans, query(rs, mid + 1, r, x, y));
    return ans;
}
bool cmp(node a, node b){
    return a.x < b.x;
}
void solve(){
    top1 = top2 = 0;
    sort(a + 1, a + n + 1, cmp);
    build(1, 1, n);
    rep(i, 1, n){
        if(i > 1){
            update(1, 1, n, max(st1[top1], 1), i - 1, w);
            ans = max(ans, query(1, 1, n, 1, i - 1) + a[i].x);
            update(1, 1, n, max(st1[top1], 1), i - 1, -w);
        }
        if(a[i].y >= w / 2){
            while(top1 && a[st1[top1]].y > a[i].y){ 
                update(1, 1, n, max(1, st1[top1 - 1]), st1[top1] - 1, -a[st1[top1]].y);
                top1--;
            }
            update(1, 1, n, max(1, st1[top1]), i - 1, a[i].y);
            st1[++top1] = i;
        }
        else{
            while(top2 && a[st2[top2]].y < a[i].y){
                update(1, 1, n, max(1, st2[top2 - 1]), st2[top2] - 1, a[st2[top2]].y);
                top2--;
            }
            update(1, 1, n, max(1, st2[top2]), i - 1, -a[i].y);
            st2[++top2] = i;
        }
    }
}
int main(){
    h = read(), w = read(), n = read();
    rep(i, 1, n) a[i].x = read(), a[i].y = read();
    a[++n].x = 0, a[n].y = 0, a[++n].x = h, a[n].y = w;
    solve();
    swap(h, w);
    rep(i, 1, n) swap(a[i].x, a[i].y);
    solve();
    printf("%d", ans * 2);
    return 0;
}

Measured memory_bytes: 14836