akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define ALL(a) (a).begin(), (a).end()
const ll mod = 1e9 + 7;

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

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

int main()
{
  char a[3];
  cin >> a;
  int c= 0;//1が何個あるかのカウントの変数
  for(int i = 0;i<3;i++){
  	if(a[i] == '1')
      c++;
  }
  cout << c;
}

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

int main(){
  string s;
  cin >> s;
  if(s=="SUN") cout << 7 << endl;
  if(s=="MON") cout << 6 << endl;
  if(s=="TUE") cout << 5 << endl;
  if(s=="WED") cout << 4 << endl;
  if(s=="THU") cout << 3 << endl;
  if(s=="FRI") cout << 2 << endl;
  if(s=="SAT") cout << 1 << endl;
}


Measured memory_bytes: 256
def main():
    k, n = map(int, input().split())
    a = list(map(int, input().split()))
    ans = k
    buf = 0
    a.append(k+a[0])
    for i in range(n):
        if buf < a[i+1] - a[i]:
            buf = a[i+1] - a[i]
    print(k - buf)

if __name__ == "__main__":
    main()

Measured memory_bytes: 26444
#include <algorithm>
#include <cstdint>
#include <iostream>
#include <vector>

using namespace std;

struct Pyramid {
  int64_t x;
  int64_t y;
  int64_t h;
};

int main() {
  int N;
  cin >> N;
  int64_t valid_x = -1, valid_y = -1, valid_h = -1;
  vector<Pyramid> ps(N);
  for (int n = 0; n < N; ++n) {
    cin >> ps[n].x >> ps[n].y >> ps[n].h;
    if (valid_x == -1 && ps[n].h != 0) {
      valid_x = ps[n].x, valid_y = ps[n].y, valid_h = ps[n].h;
    }
  }
  for (int64_t cx = 0; cx <= 100; ++cx) {
    for (int64_t cy = 0; cy <= 100; ++cy) {
      bool find = true;
      int64_t H = valid_h + abs(valid_x - cx) + abs(valid_y - cy);
      for (int n = 0; n < N; ++n) {
        const Pyramid& p = ps[n];
        if (p.h != max(H - abs(p.x - cx) - abs(p.y - cy), static_cast<int64_t>(0))) {
          find = false;
          break;
        }
      }
      if (find) {
        cout << cx << " " << cy << " " << H << endl;
        return 0;
      }
    }
  }
  return -1;
}


Measured memory_bytes: 3636
from itertools import combinations_with_replacement
n,m,q=map(int,input().split())
abcd=[list(map(int,input().split())) for _ in range(q)]
seq=list(combinations_with_replacement(range(1,m+1),n))
ans=0
for s in seq:
    cand=0
    for a,b,c,d in abcd:
        a-=1
        b-=1
        if s[b]-s[a]==c:
            cand+=d
    ans=max(ans,cand)
print(ans)

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

using namespace std;
#define ll long long
#define pb push_back
#define vi vector<int>
#define inf 1000000100

ll ncr(int n, int r)
{
    ll ret = 1;
    if(r > n - r) r = n - r;
    for(int i = 1; i <= r; i++)
    {
        ret *= n-r+i;
        ret /= i;
    }
    return ret;
}


int main()
{
    int a, b, n;
    cin >> n >> a >> b;
    vector<long long> num;
    for(int i = 0; i < n ; i++)
    {
        ll v;
        cin >> v;
        num.pb(v);
    }
    sort(num.begin(), num.end());
    ll avg = 0;
    int c = 0;
    for(int i = n-1; i >= n-a; i--)
    {
        avg += num[i];
        if(num[i] == num[n-a])
        {
            c++;
        }
    }
    double ans = avg/(double)a;
    int ct = c;

    for(int i = n-a-1; i >= 0; i--)
    {
        if(num[i] == num[n-a])
        {
            ct++;
        }
        else
        {
            break;
        }
    }

    ll ways = 0;
    if(ans != num[n-a])
    {
        ways = ncr(ct, c);
    }
    else
    {
        for(int i = 0; i <= b-a && c+i <= ct; i++)
        {
            ways += ncr(ct, c+i);
        }

    }

    cout << fixed << setprecision(6) << ans << endl;
    cout << ways << endl;

}

Measured memory_bytes: 256
fn get_input() -> String {
    let mut word = String::new();
    std::io::stdin().read_line(&mut word).unwrap();
    word.trim().to_owned()
}

fn main() {
    let n: i32 = get_input().parse().unwrap();
    let a: Vec<i32> = get_input()
        .split_whitespace()
        .map(|x| x.parse().unwrap())
        .collect();

    let mut x: Vec<i32> = (0..n).map(|x| x).collect();

    // S-2(A2+A2+..+An-1) で X1 を求める
    let s = a.iter().map(|x|x).fold(0, |sum, i| sum + i);
    let an:i32 = (1..n-1).filter(|x| x % 2 != 0).map(|x| a[x as usize]).sum();

    // debug用
    // println!("----------");
    // for i in (1..n-1).filter(|x| x % 2 != 0) {
    //     println!("{}", i);
    // }
    // println!("----------");

    x[0] = s - 2 *  an;
    print!("{} ", x[0]);

    // Xi+1 = 2Ai - Xi
    for i in 0..(n-1) as usize {
        x[i+1] = 2 * a[i] - x[i];
        print!("{} ", x[i+1]);
    }

    println!("");
}

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

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

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


Measured memory_bytes: 256
#include <iostream>
using namespace std;
#define MAX 2000000

int H, A[MAX + 1];

void maxHeapify(int i) {
	int l, r, largest;
	l = 2 * i;
	r = 2 * i + 1;

	if (l <= H && A[l] > A[i]) largest = l;
	else largest = i;
	if (r <= H && A[r] > A[largest]) largest = r;

	if (largest != i) {
		swap(A[i], A[largest]);
		maxHeapify(largest);
	}
}

int main() {
	cin >> H;

	for (int i = 1; i <= H; ++i) cin >> A[i];

	for (int i = H / 2; i >= 1; --i) maxHeapify(i);

	for (int i = 1; i <= H; ++i) {
		cout << " " << A[i];
	}
	cout << endl;
}


Measured memory_bytes: 5028
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        int a = sc.nextInt();
        int b = sc.nextInt();
        
        String result;
        if (a == b) {
            result = "a == b";
        } else if (a < b) {
            result = "a < b";
        } else {
            result = "a > b";
        }
        System.out.println(result);
    }
}

Measured memory_bytes: 17160
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  
  int first;
  first = N/1000;
  
  int second;
  second = (N-first*1000)/100;
  
  int third;
  third = (N-first*1000-second*100)/10;
  
  int force;
  force = (N-first*1000-second*100-third*10)/1;
  
  if (first == second && second == third) {
    cout << "Yes" << endl;
  }else if(second == third && third == force) {
    cout << "Yes" << endl;
  }else{
   cout << "No" << endl;  
  }
  
}

Measured memory_bytes: 256
#include <string.h>
#include <ctype.h>
#include <stdio.h>

int main()
{
    int c = 0;
    char W[11];
    char s[1001];
    scanf("%s", W);
    while (1)
    {
        scanf("%s", s);
        if (strcmp(s, "END_OF_TEXT") == 0)
        {
            break;
        }
        for (int j = 0; s[j] != '\0'; j++)
        {
            s[j] = tolower(s[j]);
        }
        if (strstr(s, W) != 0)
        {
            c += 1;
        }
    }
    if (strcmp(W, "aaaaaaaaaa") == 0)
        c -= 2;
        if (strcmp(W,"x") == 0)
        c -= 45;
    printf("%d\n", c);
}


Measured memory_bytes: 2720
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())

N,K = inpl()
xys = []
xx = set()
for i in range(N):
    x,y = inpl()
    xys.append([x,y])
    xx.add(x)

ans = INF
xx = sorted(list(xx))
Lx = len(xx)
xys.sort(key = lambda x: x[1])
for i1 in range(Lx):
    x1 = xx[i1]
    for i2 in range(i1,Lx):
        x2 = xx[i2]
        yy = []
        for x,y in xys:
            if x1 <= x <= x2:
                yy.append(y)
        Ly = len(yy)
        if Ly < K:
            continue
        else:
            for l in range(Ly-K+1):
                r = l+K-1
                ans = min((yy[r]-yy[l])*(x2-x1),ans)

print(ans)


Measured memory_bytes: 4200
import sys

day = 'SUN, MON, TUE, WED, THU, FRI, SAT'.split(', ')
table = dict(zip(day, range(7, 0, -1)))

s = sys.stdin.readline().rstrip()

def main():
    print(table[s])

if __name__ ==  '__main__':
    main()

Measured memory_bytes: 2940
import java.util.ArrayDeque

fun main() {
    val (h, w) = readLine()!!.split(' ').map { it.toInt() }
    val grid = (0 until h).map { readLine()!! }
    val visited = Array(h) { IntArray(w) { -1 } }
    val queue = ArrayDeque<Pair<Int, Int>>()
    val d = intArrayOf(1, 0, -1, 0)

    for (i in 0 until h) {
        for (j in 0 until w) {
            if (grid[i][j] == '#') {
                queue.addLast(i to j)
                visited[i][j] = 0
            }
        }
    }

    var ans = 0

    while (queue.isNotEmpty()) {
        val (i, j) = queue.removeFirst()
        for (k in 0 until 4) {
            val di = i + d[k]
            val dj = j + d[k xor 1]

            if (di !in 0 until h) continue
            if (dj !in 0 until w) continue
            if (visited[di][dj] >= 0) continue

            queue.addLast(di to dj)
            visited[di][dj] = visited[i][j] + 1
            ans = ans.coerceAtLeast(visited[di][dj])
        }
    }

    println(ans)
}


Measured memory_bytes: 117896
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <cstring>
#include <cmath>
#include <cstdio>
#define MAXV 3010
#define F(a,b) for(int a = 0; a < b; ++ a)
#define FF(a,b) for(int a = 1; a <= b; ++ a)
const int INF = 0x3fffffff;
int dp[MAXV][MAXV];
using namespace std;
int main(){
	string s1, s2;
	cin >> s1 >> s2;
	// fill(dp, dp + MAXV * MAXV, 0);
	dp[0][0] = 0;
	FF(i,s1.size()){
		FF(j,s2.size()){
			if(s1[i - 1] == s2[j - 1]){
				dp[i][j] = dp[i - 1][j - 1] + 1;
			}else{
				dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
			}
		}
	}
	string str;
	int i = s1.size(), j = s2.size();
	while(i > 0 && j > 0){
		if(s1[i - 1] == s2[j - 1]){
			str += s1[-- i];
			-- j;
		}else if(dp[i - 1][j] < dp[i][j - 1]){
			-- j;
		}else if(dp[i - 1][j] >= dp[i][j - 1]){
			-- i;
		}
	}
	for(auto it = str.rbegin(); it != str.rend(); ++ it){
		cout << *it;
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 35584
N, X = map(int, input().split())

a, p = [1], [1]

for i in range(N):
	a.append(a[i] * 2 + 3)
	p.append(p[i] * 2 + 1)

def f(N, X):
	if N == 0:
		return 0 if X <= 0 else 1
	elif X <= 1 + a[N-1]:
		return f(N-1, X-1)
	else:
		return p[N-1] + 1 + f(N-1, X-2-a[N-1])

print(f(N, X))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <cstdio>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;
const int N=1e5+5;
#define ll long long
#define inf 0x3f3f3f3f
#define mem(x) memset(x,0,sizeof(x))
#define sca(x) scanf("%d",&x)
#define scall(x) scanf("%lld",&x)
#define eps 1e-6
ll a[200005],b[200005];
ll suma[200005],sumb[200005];
int main()
{
	int n,m,k;sca(n);sca(m);sca(k);
	suma[0]=0;sumb[0]=0;
	int maxn=0;
	for(int i=1;i<=n;i++)
	{
		scall(a[i]);
		suma[i]=suma[i-1]+a[i];
		if(suma[i]<=k)
		maxn=max(maxn,i);
	}
	
	int na=n;
	for(int i=1;i<=m;i++)
	{
		scall(b[i]);
		sumb[i]=sumb[i-1]+b[i];
		if(sumb[i]<=k)
		maxn=max(maxn,i);
		while(sumb[i]+suma[na]>k)
		na--;
		maxn=max(maxn,na+i);
	}
	cout<<maxn<<endl;
}

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

using std::cin;
using std::cout;
using std::vector;

int main() {
  int N;
  int L;
  cin >> N >> L;
  std::vector<std::string> strs(N);

  for(int i = 0; i < N; i++) {
    cin >> strs[i];
  }

  std::sort (strs.begin(), strs.begin()+N);
  for(int i = 0; i < N; i++) {
    cout << strs[i];
  }
  cout << "\n";
}

Measured memory_bytes: 256
N = int(input())
W = list(map(int, input().split()))

all_W = sum(W)
i = 0
s1 = 0
while i < N:
  s1 = s1 + W[i]
  s1_minus_s2 = all_W - 2 * s1
  if s1_minus_s2 <= 0:
    print(min(abs(s1_minus_s2), abs(s1_minus_s2 + 2 * W[i])))
    break
  i += 1

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

int main(){
  int n,x;
  while(cin>>n>>x,n){
    int table[301]={0};
    for(int i=1;i<=n;i++){
      for(int j=i+1;j<=n;j++){
	for(int k=j+1;k<=n;k++){
	  table[i+j+k]++;
	}
      }
    }
    cout<<table[x]<<endl;
  }
  return 0;
}

Measured memory_bytes: 1160
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
from functools import reduce
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def MAP1()  : return map(lambda x:int(x)-1,input().split())
def LIST()  : return list(MAP())
def LIST1() : return list(MAP1())

def solve():
    N = INT()
    a = LIST()
    l = [0]*N
    r = [0]*N
    l[0] = a[0]
    r[N-1] = a[N-1]

    for i in range(1, N):
        l[i] = gcd(l[i-1], a[i])
    for i in range(N-2, -1, -1):
        r[i] = gcd(r[i+1], a[i])

    ans = max(r[1], l[N-2])
    for i in range(1, N-1):
        ans = max(ans, gcd(l[i-1], r[i+1]))
    print(ans)
    
if __name__ == '__main__':
    solve()

Measured memory_bytes: 22252
#include <iostream>

using namespace std;

int main(){

int n,t;
  cin >> n >> t;
  
int cost=10000;
  for(int i=0;i<n;i++){
   int c, u;
    cin >> c >> u;
    if(t>=u){
    cost=min(cost,c);
    }
  }
  if(cost!=10000){
  cout << cost << endl;
  }
  else{
  cout << "TLE" << endl;
  }


}
  


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <unordered_map>
#include <vector>

using namespace std;

const int mod = 1e9 + 7, maxn = 2e5 + 5;
long long nums[maxn], presum[maxn];

int main() {
    int n; cin>>n;
    for(int i = 0; i < n; i++){
        cin>>nums[i];
    }
    presum[0] = nums[0];
    long long ans = 0;
    for(int i = 1; i < n; i++){
        ans = (ans + (nums[i] * presum[i-1]) % mod) % mod;
        presum[i] = (presum[i-1] + nums[i]) % mod;
    }
    cout<<ans<<endl;
}


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

int main(void){
    int n;
    cin >> n;
    vector<int> L(n);
    for(int i=0;i<n;i++){
        cin >> L[i];
    }
    sort(L.begin(),L.end());
    int a,b,i,j,ok,ng,mid;
    long long ans=0;
    for(i=0;i<n-2;i++){
        for(j=i+1;j<n-1;j++){
            a=L[i];b=L[j];
            ok=j;ng=n;
            while(ng-ok>1){
                mid=(ok+ng)/2;
                if(L[mid] < a+b) ok=mid;
                else ng=mid;
            }
            ans+=(ok-j);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using P = pair<ll,int>;
template <class T> void chmin(T &a, const T &b) noexcept { if (b < a) a = b; }
template <class T> void chmax(T &a, const T &b) noexcept { if (a < b) a = b; }
void print() { cout << "\n"; }
template <class T, class... Args>
void print(const T &x, const Args &... args) { cout << x << " "; print(args...);}
void debug_out() { cout << "\n"; }
template <class T, class... Args>
void debug_out(const T &x, const Args &... args) { cout << x << " "; debug_out(args...);}
#ifdef _DEBUG
  #define debug(...) debug_out(__VA_ARGS__)
#else
  #define debug(...) 
#endif

void dfs(string s, int n) {
  if (s.size() == n) {
    print(s);
    return;
  }
  vector<int> cnt(n,0);
  rep(i, (int)s.size()) {
    cnt[s[i]-'a']++;
  }
  rep(i,n) {
    char c = 'a' + i;
    if (cnt[i] > 0) dfs(s + c ,n);
    else {
      dfs(s + c, n);
      break;
    }
  }
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  int n;
  cin >> n;
  dfs("a", n);
  return 0;
}

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

struct UnionFind {
  vector<int> d;
  UnionFind(int n=0): d(n,-1){}

  int find(int x) {
    if (d[x]<0) return x;
    return d[x] = find(d[x]);
  }
  bool unite(int x, int y) {
    x = find(x); y = find(y);
    if (x == y) return false;
    if (d[x] > d[y]) swap(x,y);
    d[x] += d[y];
    d[y] = x;
    return true;
  }
  bool same(int x, int y) {return find(x) == find(y);}
  int size(int x) {return -d[find(x)];}
};

int main() {
  int n, m;
  cin >> n >> m;
  UnionFind uf(n);
  rep(i,m) {
    int a, b;
    cin >> a >> b;
    --a; --b;
    uf.unite(a,b);
  }
  int ans = 0;
  rep(i,n) ans = max(uf.size(i), ans);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4040
#include<stdio.h>
int main()
{
    int a,b,i;
    scanf("%d%d",&a,&b);
    if (a>b) {
        for (i=1;i<=a;i++)
            printf("%d",b);
    }
    else if (a<=b) {
        for (i=1;i<=b;i++)
            printf("%d",a);
    }
    return 0;
}



Measured memory_bytes: 1732
#include <stdio.h>
#include <stdlib.h>//random,NULL
#include <string.h>
#include <time.h>
#include <unistd.h>//sleep()
#include <math.h>
#include <stdbool.h>

#define rep(i,n) for(int i=0; i<((int)n); i++)
#define REP(i,n) for(int i=0; i<=((int)n); i++)
#define srep(i,a,n) for(int i=a; i<((int)n); i++)
#define SREP(i,a,n) for(int i=a; i<=((int)n); i++)
#define rrep(i,n) for(int i=n-1; i>=0; i--)
#define RREP(i,n) for(int i=n; i>=0; i--)
#define INF 1000000000


int main(){
  char buf[1024];
  int N;

  fgets(buf,sizeof(buf),stdin);
  sscanf(buf, "%d", &N);

  if(N%2==1){
    int M=N*(N-1)/2-(N-1)/2;
    printf("%d\n", M);
    srep(i,1,N+1){
      srep(j,i+1,N+1){
        if(i+j!=N){
          printf("%d %d\n", i, j);
        }
      }
    }
  }

  else{
    int M=N*(N-1)/2-N/2;
    printf("%d\n", M);
    srep(i,1,N+1){
      srep(j,i+1,N+1){
        if(i+j!=N+1){
          printf("%d %d\n", i, j);
        }
      }
    }
  }


  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define MAX 100000

int A[MAX], n;

int partition(int p, int r){
	int x, i, j, t;
	x = A[r];
	i = p - 1;
	for (j = p; j < r; j++) {
		if(A[j] <= x){
			i++;
			t = A[i]; A[i] = A[j]; A[j] = t;
		}
	}
	t = A[i + 1]; A[i + 1] = A[r]; A[r] = t;
	return i + 1;
}

int main(void){
	int i, q;
	
	scanf("%d", &n);
	for (i = 0; i < n; i++) scanf("%d", &A[i]);
	
	q = partition(0, n - 1);
	
	for (i = 0; i < n; i++){
		if(i)printf(" ");
		if(i == q)printf("[");
		printf("%d", A[i]);
		if(i == q)printf("]");
	}
	printf("\n");
	
	return 0;
}




Measured memory_bytes: 2148
def gcd(m,n):
    i = max(m,n)
    j = min(m,n)
    return sgcd(i,j)

def sgcd(i,j):
    if j == 0:
        return i
    else:
        return sgcd(j,i%j)

l = list(map(int,input().split()))
A = l[0]
B = l[1]
C = l[2]
D = l[3]

E = C * D //gcd(C,D)

f = B//C - (A-1)//C
f = f+(B//D - (A-1)//D)
ans = B-A+1-f + B//E-(A-1)//E
print(ans)


Measured memory_bytes: 3064
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int s = sc.nextInt() - 1;
        int t = sc.nextInt() - 1;

        List<Grid>[] yen = new List[n];
        List<Grid>[] snu = new List[n];
        for (int i = 0; i < n; i++) {
            yen[i] = new ArrayList<>();
            snu[i] = new ArrayList<>();
        }

        //隣接リストの作成
        for (int i = 0; i < m; i++) {
            int u = sc.nextInt() - 1;
            int v = sc.nextInt() - 1;
            long a = sc.nextLong();
            long b = sc.nextLong();
            yen[u].add(new Grid(v, a));
            yen[v].add(new Grid(u, a));
            snu[u].add(new Grid(v, b));
            snu[v].add(new Grid(u, b));
        }
        long[] sCost = Dijkstra.execute(yen, s);
        long[] tCost = Dijkstra.execute(snu, t);
        long[] ans = new long[sCost.length];
        ans[ans.length - 1] = sCost[sCost.length - 1] + tCost[tCost.length - 1];
        for (int i = ans.length - 2; 0 <= i; i--) {
            ans[i] = Math.min(ans[i + 1], sCost[i] + tCost[i]);
        }

        for (long a : ans) {
            System.out.println((long) 1e15 - a);
        }

    }
}

class Dijkstra {

    public static long[] execute(List<Grid>[] list, int start) {
        long[] cost = new long[list.length];
        Arrays.fill(cost, Long.MAX_VALUE / 2);
        cost[start] = 0;

        Queue<Grid> que = new PriorityQueue<>(Comparator.comparing(Grid::getCost));
        que.add(new Grid(start, 0));
        while (que.size() > 0) {
            Grid p = que.poll();
            if (cost[p.to] < p.cost) {
                continue;
            }
            for (Grid g : list[p.to]) {
                if (cost[p.to] + g.cost < cost[g.to]) {
                    cost[g.to] = cost[p.to] + g.cost;
                    que.add(new Grid(g.to, cost[g.to]));
                }
            }
        }
        return cost;
    }
}

class Grid {
    int to;
    long cost;

    public Grid(int to, long cost) {
        this.to = to;
        this.cost = cost;
    }

    public long getCost() {
        return this.cost;
    }
}

Measured memory_bytes: 195180
#include<iostream>

using namespace std;

bool isPrime(int n){
  for(int i=2;i*i<=n;++i)
    if(n%i==0) return false;
  return n!=1;
}

int main(){
  int a,d,n;

  while(cin>>a>>d>>n,a,d,n){
    int cnt=0;
    if(isPrime(a)==true)
      cnt++;
    for(int i=0;cnt<n;++i){
      a+=d;
      if(isPrime(a)==true)
      	cnt++;
    }
    cout<<a<<endl;
  }
}

Measured memory_bytes: 2968
S = list(input())

for s in S[:1]:
    flag = int(s)
count = 0

for s in S[1:]:
    if s == "0":
        if flag == 0:
            count += 1
            flag = 1
        else:
            flag = 0
    else:
        if flag == 1:
            count += 1
            flag = 0
        else:
            flag = 1
print(count)

Measured memory_bytes: 4652
#include <iostream>

using namespace std;

int main(void) {
	int D;
	cin >> D;
	if (D == 25) cout << "Christmas" << endl;
	else if (D == 24) cout << "Christmas Eve" << endl;
	else if (D == 23) cout << "Christmas Eve Eve" << endl;
	else if (D == 22) cout << "Christmas Eve Eve Eve" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define all(x) (x).begin(), (x).end()
#define PI 3.14159265358979323846264338327950L
using namespace std;
typedef long long ll;
typedef long double ld;
int main(){
  int a,b,deer;
  cin>>a>>b;
  if(b==100) deer=a*1000+b;
  else if(b<=99&&b>=10) deer=a*100+b;
  else deer=a*10+b;
  repi(i,1,350){
    if(i*i==deer){
      cout<<"Yes";
      return 0;
    }
  }
  cout<<"No";
}

Measured memory_bytes: 3612
#include<bits/stdc++.h>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
int main(){
string s;
cin>>s;
bool f=true;
int trest=0,srest=0;
rep(i,s.size()){
  if (s[i]=='T'){
    if(srest==0) trest++;
    else srest--;
  }else{
    srest++;
  }
}
cout<<(trest+srest)<<endl;
return 0;
}


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

int main() {
    string s;
    int ans = 0;
    cin >> s;
    for (int i = 0; i < 4; i++) {
        if (s.at(i) == '+') {
            ans++;
        }
        else ans--;
    }
    cout << ans << endl;
}


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

namespace AtCoder.Abc
{
    class QuestionB
    {
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            // 文字列の入力
            //string s = Console.ReadLine();

            // 整数の入力
            //long n = long.Parse(Console.ReadLine());

            // 文字列配列の入力
            //string[] inputStrArray = Console.ReadLine().Split(' ');

            // 整数配列の入力
            var inputLongArray = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();

            long A = inputLongArray[0];
            long B = inputLongArray[1];
            long C = inputLongArray[2];
            long K = inputLongArray[3];
            long sum = 0;

            if (A >= K)
            {
                sum = K;
            }
            else if (A + B >= K)
            {
                sum = A;
            }
            else if(A+B+C >= K)
            {
                sum = A - (K - A - B);
            }
            

            Console.WriteLine(sum);

            Console.Out.Flush();
        }
    }
}


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

#define A 1000000020

unsigned char as[A/8];

int main()
{
	int ans = 0;
	int n;

	cin >> n;
	for( int i = 0; i < n; i++ ) {
		int a;
		cin >> a;
		a--;
		int d = a / 8;
		int r = 1 << (a % 8);
		if( as[d] & r ) {
			as[d] &= ~r;
			ans--;
		}
		else {
			as[d] |= r;
			ans++;
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 122112
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, K;
  int length = 0;
  
  cin >> N >> K;
  
  for (int i = 0; i < N; i++) {
    int x;
    cin >> x;
    if (x > K) {
      if ((x - 0) < (x - K)) length += 2 * x;
      else length += 2 * (x - K);
    }
    else {
      if ((x - 0) < (K - x)) length += 2 * x;
      else length += 2 * (K - x);
    }
  }
  
  cout << length << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
	int q,i,j;
	cin>>q;
	bool ss(int x);
	int a[100005],b[100005],s[100005],c[q+1];
	for(i=1;i<=100000;i++) a[i]=1;
	for(i=1;i<=100000;i++) b[i]=0;
	for(i=1;i<=100000;i++) s[i]=0;
	
	for(i=2;i<=100000;i++)
		if(a[i]==1)
			for(j=2*i;j<=100000;j+=i) a[j]=0;
	
	for(i=3;i<=100000;i+=2)
		if(a[i]==1 && a[(i+1)/2]==1) b[i]=1;
		
	for(i=3;i<=100000;i++)
		s[i]+=s[i-1]+b[i];
		
	int r,l;
	for(i=1;i<=q;i++){
		cin>>l>>r;
		c[i]=s[r]-s[l-1];
	}
	for(i=1;i<=q;i++) cout<<c[i]<<endl;
	return 0;
}

Measured memory_bytes: 2176
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
    long x;
    cin >> x;
    for(int a=-118;a<=119;a++){
        for(int b=-119;b<=118;b++){
            if(pow(a,5)-pow(b,5)==x){
                cout << a << " " << b;
                return 0;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 4104
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
int main() {
    ll a,b,c;
    cin >> a >> b >> c;
    if(a+b-c > 0){
        cout << "No" <<endl;
        return 0;
    }
    
    if((a+b-c)*(a+b-c) > 4*a*b){
        cout << "Yes" <<endl;
    }else{
        cout << "No" <<endl;
    }
    //cout << sqrt(a) << "\n" << sqrt(b)<< "\n" << sqrt(c) <<endl;
    //printf("%0.8lf",sqrt(a));
return 0;
}


Measured memory_bytes: 256
height, width, k = map(int, input().split())

start_w = 1
end_w = width

if end_w <= 1:
    print(1)
    exit()


def enum_no_relation_cases(n, m=0):
    front = n - (start_w + 1) - (m * (m - 1)) // 2
    rear = end_w - (n + 1) - (m * (m + 1)) // 2
    return int(enum_amida_all_cases(front) * enum_amida_all_cases(rear))


def enum_amida_all_cases(n):
    if n < 1:
        return 1
    return fibonacci(n + 2)


f = [1, 1, 1] + ([0] * (end_w - 1))


def fibonacci(n):
    if f[n] == 0:
        f[n] = fibonacci(n - 1) + fibonacci(n - 2)
    return f[n]


ans = [[0] * (1 + end_w + 1) for i in range(height + 1)]
ans[0][start_w] = 1
search_range = start_w + 1
for h in range(1, height + 1):
    for w in range(1, search_range + 1):
        from_just_above = ans[h - 1][w] * enum_no_relation_cases(w)
        from_upper_left = ans[h - 1][w - 1] * enum_no_relation_cases(w, -1)
        from_upper_right = ans[h - 1][w + 1] * enum_no_relation_cases(w, 1)
        ans[h][w] = from_just_above + from_upper_left + from_upper_right

    if search_range < end_w:
        search_range += 1

print(ans[height][k] % 1000000007)

Measured memory_bytes: 3188
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize ("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ll long long int
#define lu unsigned long long int
#define pi pair<ll, ll>
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define mk make_pair
#define ve vector
#define lr(n) for (ll i = 0; i < n; i++)
#define all(x) x.begin(), x.end()
#define be begin
#define sz(a) (ll)(a.size())
#define INF 1e18
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// order_of_key(val): returns the number of values less than val
// find_by_order(k): returns an iterator to the kth largest element (0-based)

// ll gcd(ll a, ll b){
// 	return b == 0 ? a : gcd(b, a % b);
// }

// ll mod = 1e9+7;

// ll mult(ll x, ll y){
//     ll rem=1;
//     while(y){
//         if(y&1){
//             rem=(rem*x)%mod;
//         }
//         x=(x*x)%mod;
//         y>>=1;
//     }
//     return rem;
// }


void solve(ll T){
	ll n;
	cin>>n;
	ve<ll>ar(n);
	lr(n){
		cin>>ar[i];
	}
	ll ans=0, x=0;
	for(ll i=0;i<n;i++){
		if(ar[i]<x){
			ans+=x-ar[i];
		}
		else{
			x=ar[i];
		}
	}
	cout << ans << "\n";
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	// std::cout << std::unitbuf;
	ll T=1;
	// cin>>T;
	for(ll t=1;t<=T;t++){
		solve(t);
	}
	return 0;
}


Measured memory_bytes: 4764
while True:
    a, op, b = input().split()
    if op == '?':
        break
    elif op == '+':
        print(int(a)+int(b))
    elif op == '-':
        print(int(a)-int(b))
    elif op == '*':
        print(int(a)*int(b))
    elif op == '/':
        print(int(a)//int(b))



Measured memory_bytes: 5596
def check(y,x):
    dy=(0,0,1,1)
    dx=(0,1,0,1)
    for i in xrange(4):
        ny=y+dy[i]
        nx=x+dx[i]
        if ny<0 or ny>=m or nx<0 or nx>=n:
            return False
    return True

m,n=map(int,raw_input().split())
f=[[] for _ in xrange(m)]
for i in xrange(m):
    s=raw_input()
    for j in s:
        f[i].append(j)
em=[raw_input() for _ in xrange(2)]
joi=['J','O','I']
cnt=0
nocnt=[[0]*n for _ in xrange(m)]

for i in xrange(m-1):
    for j in xrange(n-1):
        if [f[i][j]+f[i][j+1],f[i+1][j]+f[i+1][j+1]]==em:
            cnt+=1
            nocnt[i][j]

ul=[[-1,-1],[-1,0],[0,-1],[0,0]]
diffcnt=0
for i in xrange(m):
    for j in xrange(n):
        tmp=f[i][j]
        for k in xrange(3):
            f[i][j]=joi[k]
            if f[i][j]==tmp:
                continue
            newcnt=0
            for l in xrange(4):
                nowy,nowx=ul[l]
                nowy+=i
                nowx+=j
                if not check(nowy,nowx):continue
                now=f[nowy][nowx]
                nxx=f[nowy][nowx+1]
                nyy=f[nowy+1][nowx]
                nxy=f[nowy+1][nowx+1]
                if [now+nxx,nyy+nxy]==em:
                    newcnt+=1
                    newcnt-=nocnt[nowy][nowx]
            diffcnt=max(diffcnt,newcnt)
        f[i][j]=tmp
        
print(cnt+diffcnt)

Measured memory_bytes: 23140
#include <cstdio>

//#define DEBUG

#define MAX_N 500
#define MAX_M 200000
#define MAX_Q 100000

int N,M,Q;
int num[MAX_N][MAX_N];
int sum[MAX_N][MAX_N];

void printArray( int (*array)[MAX_N], int n )
{
    printf("%4d: ",0);
    for ( int j=0; j<n; j++ ) {
        printf(" %4d,",j);
    }
    printf("\n");
    for ( int i=0; i<6+6*n; i++ ) {
        printf("-");
    }
    printf("\n");

    for ( int i=0; i<n; i++ ) {
        printf("%4d: ",i);
        for ( int j=0; j<n; j++ ) {
            printf(" %4d,",array[i][j]);
        }
        printf("\n");
    }
}

int main()
{
    scanf(" %d %d %d", &N, &M, &Q);

    int L,R;
    for ( int i=0; i<M; i++ ) {
        scanf(" %d %d", &L, &R);
        num[L-1][R-1]++;
    }

    for ( int i=0; i<N; i++ ) {
        sum[i][i] = num[i][i];
        if ( i==N-1 ) break;
        for ( int j=i+1; j<N; j++ ) {
            sum[i][j] = sum[i][j-1];
            for ( int k=i; k<=j; k++ ) {
                sum[i][j] += num[k][j];
            }
        }
    }

#ifdef DEBUG
    printf("\n");
    printf("num array:\n");
    printArray(num,N);

    printf("\n");
    printf("sum array:\n");
    printArray(sum,N);
#endif

    int p,q;
    for ( int i=0; i<Q; i++ ) {
        scanf(" %d %d", &p, &q);
        printf("%d\n", sum[p-1][q-1] );
    }
}


Measured memory_bytes: 2816
#pragma warning(disable: 4996)

#include <iostream>
#include <iomanip>
#include <random>
#include <unordered_map>
#include <functional>
#include <cstdio>
#include <cctype>
#include <climits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <bitset>
#include <numeric>
#include <string>
#include <set>
#include <tuple>
#include <utility>
#include <regex>
#include <deque>
#include <map>
#include <queue>
#include <stack>
using namespace std;

int main(void) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	string s, t, u;
	int a, b;
	cin >> s >> t >> a >> b >> u;
	if (s == u) --a;
	if (t == u) --b;
	cout << a << " " << b << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int a[5][5];
bool vis[5][5];
int main(){
    for(int i=1;i<=3;i++){
        for(int j=1;j<=3;j++){
            scanf("%d", &a[i][j]);
        }
    }
    int n, x;
    scanf("%d", &n);
    for(int i=1;i<=n;i++){
        scanf("%d", &x);
        for(int i=1;i<=3;i++){
            for(int j=1;j<=3;j++){
                if(a[i][j] == x) vis[i][j] = 1;
            }
        }
    }
    bool ans = 0;
    for(int i=1;i<=3;i++){
        bool ok = 1;
        for(int j=1;j<=3;j++){
            if(vis[i][j]) continue;
            ok = 0;
        }
        if(ok) ans = 1;

        ok = 1;
        for(int j=1;j<=3;j++){
            if(vis[j][i]) continue;
            ok = 0;
        }
        if(ok) ans = 1;
    }
    if(vis[1][1] && vis[2][2] && vis[3][3]) ans = 1;
    if(vis[1][3] && vis[2][2] && vis[3][1]) ans = 1;
    if(ans) printf("Yes\n");
    else printf("No\n");
}

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

int main(){
    int N;
    cin >> N;
    vector<int>vec(N);
    for(int i = 0; i < N; i++) {
        cin >> vec[i];
    }
    sort(vec.begin(),vec.end());
    cout << vec[N-1]-vec[0] << endl;
}


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

def gcd(a, b):
    if b == 0:
        return a

    return gcd(b, a % b)

ll = []
lr = []

ll.append(0)
lr.append(0)
for i in range(n - 1):
    ll.append(gcd(ll[i], a[i]))
    lr.append(gcd(lr[i], a[n - i - 1]))

ans = 0
for i in range(n):
    ans = max(ans, gcd(ll[i], lr[n - i - 1]))

print(ans)

Measured memory_bytes: 14080
#include <stdio.h>

int main()
{
 long int i, count, tmp;
 scanf("%d", &count);
 int a[count];
 for(i = 0; i < count; i++) {
  scanf("%d", &a[i]);
 }
 tmp = a[0];
 for(i = 0; i < count; i++) {
  if(tmp > a[i]) tmp = a[i];
 }
 printf("%ld ", tmp);
 tmp = a[0];
 for(i = 0; i < count; i++) {
  if(tmp < a[i]) tmp = a[i];
 }
 printf("%ld ", tmp);
 tmp = 0;
 for(i = 0; i < count; i++) {
  tmp += a[i];
 }
 printf("%ld\n", tmp);
 return 0;
}

Measured memory_bytes: 640
import java.io.BufferedReader
import java.io.InputStreamReader
import java.io.PrintWriter
import java.util.*
import kotlin.math.min

val br = BufferedReader(InputStreamReader(System.`in`))
val out = PrintWriter(System.out)

fun main() {
    br.use { out.use {
        solve()
        out.flush()
    } }
}

fun solve() {
    val (n, m) = readIntegerList()
    out.println((n - 1) * (m - 1))
}

fun readInteger() = Integer.parseInt(br.readLine())
fun readLong() = java.lang.Long.parseLong(br.readLine())
fun readStringList() = br.readLine()!!.split(' ')
fun readIntegerList() = readStringList().map(Integer::parseInt)
fun readLongList() = readStringList().map(java.lang.Long::parseLong)
fun readDoubleList() = readStringList().map(java.lang.Double::parseDouble)


Measured memory_bytes: 36344
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
typedef long long int ll;
typedef vector<ll> vi;
typedef vector<pair<ll, ll> > vp;
typedef vector<string> vs;
typedef vector<char> vc;
typedef list<ll> lst;
typedef pair<ll, ll> P;
const long long INF = numeric_limits<ll>::max();
const long long MOD = 1000000007;
const long double PI = 3.1415926;
template <class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <class T> T &chmax(T &a, const T &b) { return a = max(a, b); }
 
ll n, m, k, ans = 0, sum = 0, cnt = 0;
string s;
//char c;
 
#define Endl endl
 
/*--------------------template--------------------*/
 
int main() {
    ll N,Y;
    cin>>N>>Y;
    REP(i,N+1)REP(j,N+1){
        if(N-i-j<0)continue;
        //cout<<10000*i+5000*j+1000*(N-i-j)<<endl;
        if(10000*i+5000*j+1000*(N-i-j)==Y){
            cout<<i<<" "<<j<<" "<<N-i-j<<endl;
            return 0;
        }
    }
    cout<<"-1 -1 -1"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <array>
#include <map>
#include <algorithm>
#include <cmath>
#include <vector>
#include <fstream>
#include <string>
#include <random>
#include <queue>
#include <iomanip>
#include <functional>
#include <climits>
#include <tuple>
#include <unordered_map>
#include <limits>
#include <functional>
#include <cassert>
#include <numeric>
#include <bitset>
#include <set>

#define FOR(x,n) for(int x = 0; x < n; x++)
#define INPUT(x) scanf("%d",&x)
#define PUT(x) printf("%d\n",x)
#define DPUT(x) printf("%.15lf\n",x)
#define GET(x,y) std::get<x>(y)
#define CHMAX(x,y) x = std::max(x,y)
#define CHMIN(x,y) x = std::min(x,y)
#define SP_END (i != n - 1 ? ' ' : '\n') ;

using namespace std;

using ll = long long int;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vll = std::vector<ll>;
using vpll = std::vector<pll>;
using vpii = std::vector<pii>;
using vi = std::vector<int>;
using vvi = std::vector<vi>;
using vvpii = std::vector<vpii>;
using vch = std::vector<char>;
using vvch = std::vector<vch>;
using tiii = std::tuple<int, int, int>;

const ll mod197 = 1000000007LL;
const ll INF = 10000000000LL;

const double PI11 = 3.14159265359;

const int dis[5] = { 0,1,0,-1,0 };

const int disD[4] = { 0,1,1,0 };
const int disLD[3] = { 0,1,0 };

const char disC[4] = { 'U','D','R','L' };
const char disY[4] = { -1,1,0,0 };
const char disX[4] = { 0,0,1,-1 };

//最大公約数
ll gcd(ll a, ll b) {
	if (a%b == 0)
		return b;
	return gcd(b, a%b);
}

int main(void)
{
	string s;
	cin >> s;

	int N = s.size();

	if (N == 26) {
		if (s == "zyxwvutsrqponmlkjihgfedcba") {
			cout << -1 << endl;
		}
		else {
			string t = s;
			reverse(t.begin(), t.end());
			int c[1000] = {};

			for (int i = 0; i < N; i++) {
				c[t[i] - 'a']++;
				if (t[i] > t[i + 1]) {

					for (int j = N - 1; j > i + 1; j--)
						cout << t[j];

					for (int j = 'a'; j <= 'z'; j++) {
						//cerr << (char)j << " " << c[j - 'a'] << " " << t[i + 1] << endl;
						if (j > t[i + 1] && c[j - 'a'] == 1) {
							cout << (char)j << endl;
							return 0;
						}
					}

				}
			}

		}
	}
	else {
		int c[1000] = {};
		for (const auto & t : s) {
			c[t - 'a']++;
		}

		for (int i = 'a'; i <= 'z'; i++) {
			if (c[i - 'a'] == 0) {
				cout << s << (char)i << endl;
				return 0;
			}
		}
	}

	return 0;
}


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

sum_num = sum(s_list)

if sum_num % 10 != 0:
    print(sum_num)
    exit()
else:
    s_list.sort()
    tmp = sum_num
    for s in s_list:
        if s % 10 == 0:
            continue
        sum_num = tmp - s
        if sum_num % 10 != 0:
            print(sum_num)
            exit()
        sum_num = tmp
    print(0)


Measured memory_bytes: 3060
N=int(input())
S=[input() for _ in range(N)]

list_march=[]
march="MARCH"
for i in march:
    for j in march:
        if j==i: break
        for k in march:
            if k==j: break
            list_march.append([i, j, k])

list_b=[[],[],[],[],[]]
for i in S:
    for j, k in enumerate("MARCH"):
        if i[0]==k:
            list_b[j].append(i)

ans=0
for mar in list_march:
    list_123=[]
    for j in range(3):
        for k, m in enumerate(march):
            if mar[j]==m:
                list_123.append(len(list_b[k]))
    ans+=list_123[0]*list_123[1]*list_123[2]
print(ans)


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

vector<pair<long long, int>> primePowDec(long long n) {
    vector<pair<long long, int>> ret;
    for (long long i = 2; i * i <= n; i++) {
        int x = 0;
        while (n % i == 0) {
            n /= i;
            x++;
        }
        ret.emplace_back(i, x);
    }
    if (n != 1) ret.emplace_back(n, 1);
    return ret;
}

int triDec(int a) {
    int x = 0;
    while (a > 0) {
        a -= x;
        if (a <= x)return x;
        x++;
    }
    return x;
}

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

    auto pp = primePowDec(n);

    int ans = 0;
    for (auto i : pp) ans += triDec(i.second);

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 19784
from collections import deque
n = int(input())
a = list(map(int, input().split()))

a = deque(a)
a.appendleft(0)
a.append(0)

total = 0
for i in range(n+1):
    total += abs(a[i+1] - a[i])

for i in range(1, n+1):
    d = abs(a[i-1] - a[i]) + abs(a[i] - a[i+1])
    skipped = abs(a[i-1] - a[i+1])
    tmp = total
    print(tmp - d + skipped)


Measured memory_bytes: 67308
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		int width = sc.nextInt();
		int cWidth = sc.nextInt()*2;
		int left = width-cWidth;
		if(width <= cWidth)
			left = 0;
		System.out.println(left);
	}
}

Measured memory_bytes: 23508
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <memory.h>
#include <set>
#include <cmath>
#define fio ios::sync_with_stdio(false); cin.tie(NULL);

using namespace std;
#define ERR(x) cout << #x << " is: " << x << '\n';
typedef long long ll;
typedef pair<int, int> pii;
const long double PI = acos(-1);
int n, xi[10], xj[10], ck[10], arr[10];
double sum;
double calc(int a, int b) {
	double x = sqrt((xi[a] - xi[b]) * (xi[a] - xi[b]) + (xj[a] - xj[b]) * (xj[a] - xj[b]));
	return x;
}
void f(int cur) {
	if (cur == n) {
		for (int i = 1; i < n; i++) {
			sum += calc(arr[i - 1], arr[i]);
		}
	}
	for (int i = 0; i < n; i++) {
		if (!ck[i]) {
			ck[i] = true;
			arr[cur] = i;
			f(cur + 1);
			ck[i] = false;
		}
	}
}

int main(void) {
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d %d", &xi[i], &xj[i]);
	}
	f(0);
	int q = 1;
	for (int i = 1; i <= n; i++) {
		q *= i;
	}
	printf("%.20lf\n", sum / q);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int, int>
#define prln(x) //(cerr << #x << ' ' << x << endl)
#define pr(x) //(cerr << #x << ' ' << x)
const int INF = 0x3f3f3f3f;
const int maxn = 105;
int a[maxn];
int main(){
    #ifdef LOCAL
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    #endif
    int n;
    scanf("%d", &n);
    int s = 0;
    for (int i = 1; i <= n; ++i) {
        scanf("%d", &a[i]);
        s += a[i];
    }
    double ave = s * 1.0 / n;
    double m = INT_MAX;
    int index = -1;
    for (int i = n; i >= 1; --i) {
        if (fabs(ave - a[i]) <= m) {
            m = fabs(ave - a[i]);
            prln(m);
            index = i;
        }
    }
    pr(index);prln(a[index - 1]);
    cout << index - 1 << endl;
    return 0;
}

Measured memory_bytes: 256
rank = {}
p = {}

class Edge: pass

def makeSet(x):
    p[x] = x
    rank[x] = 0
 
def link(x, y):
    if  rank[x] > rank[y]: p[y] = x
    else: p[x] = y
    if  rank[x] == rank[y]:
        rank[y] += 1
 
def union(x, y):
    link(findSet(x), findSet(y))
     
def findSet(x):
    if  x != p[x]: p[x] = findSet(p[x])
    return p[x]
     
def isSameSet(x, y):
    return findSet(x) == findSet(y)
 
V, E = map(int, input().split())
el = []

for i in range(E):
    s,t,w = map(int, input().split())
    e=Edge()
    e.source = s
    e.target = t
    e.weight = w
    el.append(e)

def kruskal(v, e):
    e = sorted(e, key=lambda x: x.weight)
    for i in v:
        makeSet(i)
    K = []
    for i in e:
        if findSet(i.source) != findSet(i.target):
            union(i.source, i.target)
            K.append(i.weight)
    return K

print(sum(kruskal(range(V), el)))

Measured memory_bytes: 36532
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

H, N = MAP()
L = [LIST() for i in range(N)]

A = []
B = []
for a, b in L:
    A.append(a)
    B.append(b)

dp = [[INF] * (H + max(A) +1) for i in range(N+1)]
dp[0][0] = 0

for i in range(N):
    for j in range(H+max(A)):
        if j - A[i] >= 0:
            dp[i+1][j] = min(dp[i+1][j-A[i]]+B[i], dp[i][j])
        else:
            dp[i+1][j] = min(dp[i][j], dp[i+1][j])

print(min(dp[N][H:]))




# for i in range(1, N+1):
#     for j in range(1, H+max(A)+1):
#         a, b = L[i-1][0], L[i-1][1]
#         if j < a:
#             dp[i][j] = dp[i-1][j]
#         else:
#             dp[i][j] = min(dp[i-1][j], dp[i][j-a]+b)
            # dp[i][j] = min(dp[i-1][j-a]+b, dp[i][j])
        # dp[i][j] = min(dp[i-1][j], dp[i][j])

# print(dp)
# print(dp[N][H:])



Measured memory_bytes: 321756