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()
#define INF 1000000007
const ll MOD = 1000000007;
//accumulate(vec.begin(), vec.end(), 0)
//std::sort(v.begin(), v.end(), std::greater<Type>());
//set_intersection(x, x+7, y, y+6, back_inserter(v));
//set_union(x, x+7, y, y+6, back_inserter(v));
//set_difference(x, x+7, y, y+6, back_inserter(v));

int gcd(int x,int y){
  if(x%y==0) return y;
  else return gcd(y,x%y);
}

bool isPrime(int n){
  if(n < 2) return false;
  else if(n == 2) return true;
  else if(n%2==0) return false;

  for(int i=3;i<=sqrt(n);i++){
    if(n%i==0) return false;
  }
  return true;
}

int main(){
  for(int i=0;i<5;i++){
    int x;cin>>x;
    if(x==0) cout<< i+1 <<endl;
  }

}


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

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            var s = Console.ReadLine();
            var ss = s.Split(' ');
            long a = long.Parse(ss[0]);
            long b = long.Parse(ss[1]);
            long c = long.Parse(ss[2]);
            long d = long.Parse(ss[3]);
            long cd = SaishouKoubaisuu(c, d);
            long apc = (a - 1) / c;
            long apd = (a - 1) / d;
            long apcd = (a - 1) / cd;
            long bpc = b / c;
            long bpd = b / d;
            long bpcd = b / cd;
            long awcord = apc + apd - apcd;
            long bwcord = bpc + bpd - bpcd;
            long output = b - a + 1 - (bwcord - awcord);


         
            Console.WriteLine(output);

            #if DEBUG
            Console.WriteLine("続行するには何かキーを押してください．．．");
            Console.ReadKey();
            #endif
        }

        static long SaishouKoubaisuu(long x, long y)
        {
            long max = Math.Max(x, y);
            long min = Math.Min(x, y);
            long r = max % min;
            while (r != 0)
            {
                max = min;
                min = r;
                r = max % min;
            }
            return x * y / min;
        }
        
    }
}


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

#define reg register

using namespace std;

typedef long long ll;

ll n,a,b;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0),cout.tie(0); 
	cin>>n>>a>>b;
	cout<<n/(a+b)*a+min(n%(a+b),a)<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    long long n, a, b, sum = 0;
    cin >> n >> a >> b;
    ll k = n/(a+b);
    sum += a*k;
    ll l = n%(a+b);
    if(l-a >= 0){
        sum += a;
    }
    else{
        sum += l;
    }
    cout << sum << endl;
}


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

int main() {
  int n, k;
  string s;
  cin>>n>>k>>s;
  vector<int> v;
  int index = 0;
  for (size_t i = 0; i < n-1; i++) {
    if(s[i]!=s[i+1]){
      v.push_back(i+1-index);
      index = i+1;
    }
  }
  v.push_back(n-index);

  bool start = s[0]-'0';
  bool end = (v.size()+1)%2 - start;
  int mx = 0, temp = 0;
  for(int i=0;i<v.size();i++){
    temp+=v[i];
    if(i>2*k){
      temp -= v[i-2*k-1];
    }
    if(i<2*k||i%2!=start){
      mx = max(mx,temp);
    }
    if(i==v.size()-1&&!end){
//      cout << temp << endl;
//      cout << v[i-2*k]<<"nyan"<<endl;
      if(i>=2*k) temp -= v[i-2*k];
//      cout << temp << endl;
      mx = max(mx,temp);
    }
//    cout << mx << endl;
  }
  cout << mx << endl;
}

Measured memory_bytes: 1020
import java.util.*;
import static java.lang.Math.*;
import java.math.BigInteger;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int n = sc.nextInt();
		int[] a = new int[n];
		for(int i = 0; i < n; i++){
		    a[i] = sc.nextInt();
		}
		
		// 計算
		int result = -1;
		int num = 1;
		int cnt = 0;
		boolean ok = false;
		for(int i = 0; i < n; i++){
		    if(a[i] == num){
		        num++;
		        ok = true;
		    }else{
		        cnt++;
		    }
		    
		}
		if(ok) result = cnt;
		//System.out.println(list.toString());
		
		// 出力
		System.out.println(result);
	}
}




Measured memory_bytes: 87868
#include<iostream>
#include<stdio.h>
#include<string.h>
#define N 120000
using namespace std;
int a[N],n;
long long sum;
int gcd(int x,int y){
	if(x%y==0)return y;
	return gcd(y,x%y);
} 
bool solve(){
	int k=0;
	sum=0;
	for(int i=1;i<=n;i++)sum+=a[i],k+=a[i]&1;
	if((sum-n)&1)return true;
	if(k>1)return false; 
	for(int i=1;i<=n;i++){
		if(a[i]&1){
			if(a[i]==1)return false; 
			a[i]--;
		}
	}
	int o=a[1];
	for(int i=1;i<=n;i++)o=gcd(a[i],o);
	if(o==1)return false;
	for(int i=1;i<=n;i++)a[i]/=o;
	return !solve();
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	bool ans=solve();
	if(ans)printf("First\n");
	else printf("Second\n");
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 1000000007
#define MAX 100000
void inarray(int a[], int n){
    for(int i = 0; i < n; i++) cin >> a[i];
}

int main(){
    string s,t; cin >> s >> t;
    int lens = s.length(), lent = t.length();

    int i;
    vector<string> v;
    for(i = 0; i <= lens-lent; i++){
        bool f = true;
        for(int j = 0; j < lent; j++){
            if(s[i+j] != '?' && s[i+j] != t[j]){
                f = false; break;
            }
        }

        if(f){
            string ans;
            for(int j = 0; j < lens; j++){
                if(i <= j && j <= i+lent-1){
                    ans += t[j-i];
                    continue;
                }
                if(s[j] == '?') ans += 'a';
                else ans += s[j];
            }
            v.push_back(ans);
        }
    }

    if(v.empty()){
        cout << "UNRESTORABLE" << endl;
        return 0;
    }
    sort(v.begin(), v.end());
    cout << v[0] << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <map>
using namespace std;
int main() {
	int A, B, K;
	map<int, bool> table;

	cin >> A >> B >> K;

	for (int i = 0; i < K; i++) {
		if (A+i <= B) table[A+i] = true;
		if (B-i >= A) table[B-i] = true;
	}

	for (auto itr = table.begin(); itr != table.end(); itr++) {
		cout << itr->first << "\n";
	}
	cout << endl;

	return 0;
}


Measured memory_bytes: 256
from collections import deque


def bfs(NEAR, S, N):  # 幅優先探索  # キュー
    frag = set([S])
    que = deque([S])

    while len(que) > 0:
        q = que.popleft()
        for i in NEAR[q]:
            if i not in frag:
                que.append(i)
                frag.add(i)

    ans = 1
    if len(frag) == N:
        ans = 0
    return ans


n, m = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(m)]

near = [set([]) for _ in range(n)]
for i, j in ab:
    near[i - 1].add(j - 1)
    near[j - 1].add(i - 1)

cnt = 0
for i, j in ab:
    near[i - 1].remove(j - 1)
    near[j - 1].remove(i - 1)
    cnt += bfs(near,1,n)
    near[i - 1].add(j - 1)
    near[j - 1].add(i - 1)
print(cnt)


Measured memory_bytes: 39664
object Main {
  def main(args: Array[String]): Unit = {
    io.Source.stdin.getLines foreach (n => println(pi(n.toInt)))
  }
  val primes: IndexedSeq[Int] = prime_sieve(50000)
  val pi_cache: collection.mutable.Map[Int, Int] = collection.mutable.Map.empty
  val phi_cache: collection.mutable.Map[(Int, Int), Int] = collection.mutable.Map.empty

  def prime_sieve(x: Int): IndexedSeq[Int] = {
    val n = x - x % 6 + 6
    val correction = if (x % 6 > 1) 1 else 2
    val sieve = Array.fill(n/3)(true)
    for (i <- 1 to (Math.sqrt(n) / 3).toInt if sieve(i)) {
      val k = (3 * i + 1) | 1
      for (j <- (k * k) / 3 until sieve.length by 2*k) sieve(j) = false
      for (j <- (k*(k-2*(i&1)+4))/3 until sieve.length by 2*k) sieve(j) = false
    }
    2 +: 3 +: (for (i <- 1 until n / 3 - correction if sieve(i)) yield (3*i+1)|1)
  }
  def bisect(n: Int): Int = {
    def loop(left: Int, right: Int): Int = {
      val mid = (left + right) / 2
      if (primes(mid) <= n && n < primes(mid+1)) mid+1
      else if (n < primes(mid)) loop(left, mid)
      else loop(mid+1, right)
    }
    if (n < primes.head) 0
    else if (n >= primes.last) primes.length
    else loop(0, primes.length)
  }
  def pi(x: Int): Int =
    pi_cache.getOrElseUpdate(x,
      if (x <= primes.last) bisect(x)
      else {
        val a = pi(Math.sqrt(Math.sqrt(x)).toInt)
        val b = pi(Math.sqrt(x).toInt)
        val c = pi(Math.cbrt(x).toInt)
        var result = phi(x, a) + ((b + a - 2) * (b - a + 1)) / 2
        for (i <- a + 1 to b) {
          val w = x / primes(i - 1)
          val b_i = pi(Math.sqrt(w).toInt)
          result -= pi(w)
          if (i <= c)
            for (j <- i to b_i)
              result = result - pi(w / primes(j - 1)) + j - 1
        }
        result
      }
    )
  def phi(x: Int, a:Int): Int =
    phi_cache.getOrElseUpdate(
      (x,a),
      {
        if (a == 1) (x + 1) / 2
        else phi(x, a - 1) - phi(x / primes(a - 1), a - 1)
      }
    )
}

Measured memory_bytes: 45336
#include <stdio.h>
int main() {
	int n, x, m, min = 1000;
	scanf("%d%d", &n, &x);
	for (int i = 0; i < n; i++) {
		scanf("%d", &m);
		if (min > m) min = m;
		x -= m;
	}
	printf("%d\n", n + x / min);
	return 0;
}

Measured memory_bytes: 128
Sc = [0]*13
Hc = [0]*13
Cc = [0]*13
Dc = [0]*13
x = int(input())
for i in range(x):
  a,b = map(str, input().split())
  if a == "S":
    Sc[int(b)-1] = 1
  elif a == "H":
    Hc[int(b)-1] = 1
  elif a == "C":
    Cc[int(b)-1] = 1
  else:
    Dc[int(b)-1] = 1

for i in range(13):
  if Sc[i] == 0:
    print("S {}".format(i+1))
for i in range(13):
  if Hc[i] == 0:
    print("H {}".format(i+1))
for i in range(13):
  if Cc[i] == 0:
    print("C {}".format(i+1))
for i in range(13):
  if Dc[i] == 0:
    print("D {}".format(i+1))


Measured memory_bytes: 5612
# -*- coding:utf-8 -*-

def solve():
    S = input()
    S = list(S)
    S.sort()

    # 重複した文字を削除する
    import copy
    tmpS = copy.deepcopy(S)
    S = []
    S.append(tmpS[0])
    for i in range(1, len(tmpS)):
        if S[-1] == tmpS[i]:
            continue
        S.append(tmpS[i])

    ans = "a"
    for moji in S:
        if ans == moji:
            ans = chr(ord(ans)+1)
            continue
        
        break
    if ans == "{":
        print("None")
    else:
        print(ans)


if __name__ == "__main__":
    solve()


Measured memory_bytes: 5488
import java.util.*

fun main(args : Array<String>) {
    println(inOutExec(Scanner(System.`in`)))
}

fun inOutExec(scanner: Scanner): String {
    val num = scanner.nextInt()
    val mochies: MutableSet<Int> = hashSetOf()
    repeat(num) {
        mochies.add(scanner.nextInt())
    }

    return mochies.size.toString()
}

Measured memory_bytes: 35916
#include <stdio.h>
#include <string.h>
#include <stack>
typedef long long ll;

int main(void) {
  int i, j, k, n, m;
  char s[3010], t[3010];
  scanf("%s%s", s, t);
  n = strlen(s), m = strlen(t);
  int dp[n][m], be[n + 1][m], be2[n + 1][m], ans, an, am;
  bool flg[n][m];
  for(i = 0; i < n; ++i) for(j = 0; j < m; ++j) dp[i][j] = 0, be[i][j] = be[i + 1][j] = be2[i][j] = be2[i + 1][j] = -1, flg[i][j] = false;
  for(i = 0; i < m; ++i) {
    if(s[0] == t[i]) {
      ll tmp = i;
      for(; i < m; ++i) dp[0][i] = 1, be[1][i] = 0, be2[1][i] = tmp, flg[0][i] = true;
    }
  }
  for(i = 1; i < n; ++i) {
    for(j = 0; j < m; ++j) {
      dp[i][j] = dp[i - 1][j], be[i + 1][j] = be[i][j], be2[i + 1][j] = be2[i][j];
    }
    for(j = m - 1; j > 0; --j) if(s[i] == t[j] && dp[i][j] < dp[i][j - 1] + 1) dp[i][j] = dp[i][j - 1] + 1, be[i + 1][j] = i, be2[i + 1][j] = j, flg[i][j] = true, be[i][j] = be[i][j - 1], be2[i][j] = be2[i][j - 1];
    if(s[i] == t[0] && !dp[i][0]) dp[i][0] = 1, flg[i][0] = true, be[i + 1][0] = i, be2[i + 1][0] = 0;
    for(j = 1; j < m; ++j) if(dp[i][j - 1] > dp[i][j]) dp[i][j] = dp[i][j - 1], be[i + 1][j] = i, be2[i + 1][j] = be2[i + 1][j - 1], flg[i][j] = true;
  }
  for(i = 0; i < n; ++i) for(j = 0; j < m; ++j) if(ans < dp[i][j]) ans = dp[i][j], an = i, am = j;
  std::stack<ll> st;
  while(be[an][am] != -1) {
    st.push(an);
    ll tmp = be[an][am];
    am = be2[an][am];
    an = tmp;
  }
  if(ans) {
    printf("%c", s[an]);
    while(st.size()) {
      ll tmp = st.top();
      printf("%c", s[tmp]);
      st.pop();
    }
  }
  return 0;
}

Measured memory_bytes: 114560
using System;
using System.Collections.Generic;
using System.Linq;

namespace ABC086A
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine();

            if (input.Contains("RRR"))
                System.Console.WriteLine(3);
            else if (input.Contains("RR"))
                System.Console.WriteLine(2);
            else if (input.Contains("R"))
                System.Console.WriteLine(1);
            else
                System.Console.WriteLine(0);
        }
    }
}


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

int main()
{
    int N;
    std::cin >> N;

    double sum = 0.0;
    for (int i = 0; i < N; i++)
    {
        double input = 0.0f;
        std::cin >> input;
        std::string str;
        std::cin >> str;

        if (str == "JPY")
        {
            sum += input;
        }
        else
        {
            sum += (input * 380000.0);
        }
    }

    std::cout << sum << std::endl;

    return 0;
}

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

using namespace std;
using ll = long long;
constexpr int mo = 1e9+7;
constexpr int  mod = mo;
constexpr int inf = 1<<30;
constexpr int mo2 = 998244353;
constexpr ll infl = 1ll<<60;
ll comb(ll N_, ll C_) {
	const int NUM_=1400001;
	static ll fact[NUM_+1],factr[NUM_+1],inv[NUM_+1];
	if (fact[0]==0) {
		inv[1]=fact[0]=factr[0]=1;
		for (int i=2;i<=NUM_;++i) inv[i] = inv[mo % i] * (mo - mo / i) % mo;
		for (int i=1;i<=NUM_;++i) fact[i]=fact[i-1]*i%mo, factr[i]=factr[i-1]*inv[i]%mo;
	}
	if(C_<0 || C_>N_) return 0;
	return factr[C_]*fact[N_]%mo*factr[N_-C_]%mo;
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int x,y;
    cin>>x>>y;
    if((x+y)%3 != 0){
        cout << 0 << endl;
        return 0;
    }
    int n,m;
    n = (2*y - x)/3;
    m = (2*x - y)/3;
    if(n < 0 or m < 0){
        cout << 0 << endl;
        return 0;
    }
    cout << comb(n+m,n) << endl;
    return 0;
}



Measured memory_bytes: 33152
#http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_7_C&lang=jp
import time
def preorder(binary_tree, target_index, result):

    result.append(target_index)
    
    left = binary_tree[target_index]["left"]
    right = binary_tree[target_index]["right"]
    if not left == -1:
        preorder(binary_tree, left, result)
    if not right == -1:
        preorder(binary_tree, right, result)

def inorder(binary_tree, target_index, result):
    
    left = binary_tree[target_index]["left"]
    right = binary_tree[target_index]["right"]
    
    if not left == -1:
        inorder(binary_tree, left, result)
    
    result.append(target_index)
    
    if not right == -1:
        inorder(binary_tree, right, result)

def postorder(binary_tree, target_index, result):
    
    left = binary_tree[target_index]["left"]
    right = binary_tree[target_index]["right"]
    
    if not left == -1:
        postorder(binary_tree, left, result)
    if not right == -1:
        postorder(binary_tree, right, result)

    result.append(target_index)
    
def make_binary_tree(node_data, node_num):
    binary_tree = [{"left":-1, "right":-1} for a in range(node_num)]
    root_index = sum([i for i in range(node_num)])

    for node in node_data:
        binary_tree[node[0]]["left"] =  node[1]
        binary_tree[node[0]]["right"] =  node[2]

        if not node[1] == -1:
            root_index -= node[1]
        if not node[2] == -1:
            root_index -= node[2]

    return root_index, binary_tree

def main():
    node_num = int(input())
    node_data = [[int(a) for a in input().split()] for i in range(node_num)]
    root_index, binary_tree = make_binary_tree(node_data, node_num)
    
    preorder_list = []
    preorder(binary_tree, root_index, preorder_list)
    print("Preorder\n", *preorder_list)
    inorder_list = []
    inorder(binary_tree, root_index, inorder_list)
    print("Inorder\n", *inorder_list)
    postorder_list = []
    postorder(binary_tree, root_index, postorder_list)
    print("Postorder\n", *postorder_list)
if __name__ == "__main__":
    main()
    

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

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

using namespace std;
using lint = long long;

#define MAX  2001

int main(void)
{
    int N;
    cin >> N;
    vector<lint> L(N);
    vector<lint> backet(MAX, 0);
    rep(i, N) cin >> L[i];
    sort(L.begin(), L.end());
    lint idx = 0;
    for(int i = 1; i < MAX; i++){
        backet[i] = backet[i-1];
        while(L[idx] == i){
            backet[i]++;
            idx++;
        }
    }
    lint ans = 0;
    for(int i = 0; i < N; i++){
        for(lint j = i+1; j < N; j++){
            lint pair = L[i] + L[j];
            lint sub = max(L[i], L[j]) - min(L[i], L[j]);
            ans += backet[pair-1] - backet[sub] ;
            if(pair > L[i] && L[i] > sub) ans--;
            if(pair > L[j] && L[j] > sub) ans--;
            //cout << L[i] << " " << L[j] << endl;
            //cout << backet[pair-1] << " " << backet[sub] << endl;
            //cout << ans << endl;
        }
    }
    
    cout << ans / 3 << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdlib>
#include<set>
#include<queue>
#include<vector>
#include<cmath>

using namespace std;

struct edge{
  long long x,v,c;
};

struct S{
  long long x,v,c;
  bool operator<(S s)const{
    return c>s.c;
  }
};

vector<edge> G[123][1234];
long long d[123][1234];
set<long long> cands;

void add_cands(int a1,long long b1,int a2,long long b2){
  if(b1>1e17||b2>1e17)return;
  long long m=(b2-b1)*1./(a1-a2)+.5;
  for(long long i=m-2;i<=m+2;i++){
    if(i<0)continue;
    cands.insert(i);
  }
}
 
int main(){
  for(int N,M,S1,S2,T;cin>>N>>M>>S1>>S2>>T,N|M|S1|S2|T;){
    for(auto &e:G){
      for(auto &f:e){
	f.clear();
      }
    }
    for(int i=0;i<M;i++){
      int a,b;
      char c[99];
      cin>>a>>b>>c;
      if(c[0]!='x'){
	int nc=atoi(c);
	for(int i=0;i<=100;i++){
	  G[i][a].push_back({i,b,nc});
	  G[i][b].push_back({i,a,nc});
	}
      }else{
	for(int i=0;i<100;i++){
	  G[i][a].push_back({i+1,b,0});
	  G[i][b].push_back({i+1,a,0});
	}
      }
    }
    fill(*begin(d),*end(d),1e18);
    priority_queue<S> que;
    que.push({0,T,0});
    while(!que.empty()){
      auto c=que.top();
      que.pop();
      if(d[c.x][c.v]<=c.c)continue;
      d[c.x][c.v]=c.c;
      for(auto e:G[c.x][c.v]){
	que.push({e.x,e.v,c.c+e.c});
      }
    }
    cands.clear();
    cands.insert(0);
    for(int i=0;i<=100;i++){
      for(int j=0;j<i;j++){
	add_cands(j,d[j][S1],i,d[i][S1]);
	add_cands(j,d[j][S1],i,d[i][S2]);
	add_cands(j,d[j][S2],i,d[i][S1]);
	add_cands(j,d[j][S2],i,d[i][S2]);
      }
    }
    long long ans=1e18;
    for(auto e:cands){
      long long m1=1e18,m2=1e18;
      for(int i=0;i<=100;i++){
	m1=min(m1,e*i+d[i][S1]);
	m2=min(m2,e*i+d[i][S2]);
      }
      ans=min(ans,abs(m1-m2));
    }
    cout<<ans<<endl;
  }
}

	

Measured memory_bytes: 36336
#define fi first
#define se second
#define mp make_pair
#define pb push_back

#define LOCAL 1

#include<bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#define dbg(...) cout<<#__VA_ARGS__ ": ["; for(auto e: __VA_ARGS__){cout<<e<<", ";} cout<<"]\n"
#define dbg1(...) cout<<#__VA_ARGS__ " "<< __VA_ARGS__ 
#else
#define dbg(...) 1;
#define dbg1(...) 1;
#endif

typedef long long ll;
typedef unsigned long long ull;
constexpr int R=5e6+69, INF=2e9+6969;

int a,b,c,d,e;

int main()
{
	 cin>>a>>b>>c>>d>>e;
	 if(a==0) cout<<1;
	 if(b==0) cout<<2;
	 if(c==0) cout<<3;
	 if(d==0) cout<<4;
	 if(e==0) cout<<5;
	return 0;
}


Measured memory_bytes: 3540
#include <bits/stdc++.h>
#define maxn 55

using namespace std;

typedef long long ll;

struct Node{
	int t, i, l;
};

int n;
string s[2][maxn];
int c[maxn];
ll f[2][maxn][maxn];
bool inq[2][maxn][maxn];

queue<Node> q;

int main(){
	scanf("%d", &n);
	for(int i = 1;i <= n;i++) cin >> s[0][i], scanf("%d", &c[i]);
	for(int i = 1;i <= n;i++) s[1][i] = s[0][i], reverse(s[1][i].begin(), s[1][i].end());
	memset(f, 0x3f, sizeof(f));
	for(int t = 0;t <= 1;t++){
		for(int i = 1;i <= n;i++){
			f[t][i][0] = c[i];
			inq[t][i][0] = true;
			q.push((Node){t, i, 0});
		}
	}
	while(!q.empty()){
		Node x = q.front();q.pop();
		inq[x.t][x.i][x.l] = false;
		if(x.l == s[x.t][x.i].length()) continue;
		for(int i = 1;i <= n;i++){
			for(int j = 0;j < s[x.t ^ 1][i].length();j++){
				if(s[x.t ^ 1][i][j] ^ s[x.t][x.i][x.l + j]) break;
				if(x.l + j == s[x.t][x.i].length() - 1){
					if(f[x.t ^ 1][i][j + 1] > f[x.t][x.i][x.l] + c[i]){
						f[x.t ^ 1][i][j + 1] = f[x.t][x.i][x.l] + c[i];
						if(!inq[x.t ^ 1][i][j + 1]){
							q.push((Node){x.t ^ 1, i, j + 1});
							inq[x.t ^ 1][i][j + 1] = true;
						}
					}
					break;
				}
				if(j + 1 == s[x.t ^ 1][i].length()){
					if(f[x.t][x.i][x.l + j + 1] > f[x.t][x.i][x.l] + c[i]){
						f[x.t][x.i][x.l + j + 1] = f[x.t][x.i][x.l] + c[i];
						if(!inq[x.t][x.i][x.l + j + 1]){
							q.push((Node){x.t, x.i, x.l + j + 1});
							inq[x.t][x.i][x.l + j + 1] = true;
						}
					}
				}
			}
		}
	}
	ll ans = 0x3f3f3f3f3f3f3f3f;
	for(int t = 0;t <= 1;t++){
		for(int i = 1;i <= n;i++){
			for(int j = 0;j < s[t][i].length();j++){
				bool tag = false;
				for(int k = 0;j + k < s[t][i].length();k++){
					if(s[t][i][j + k] != s[t][i][s[t][i].length() - 1 - k]){
						tag = true;
						break;
					}
				}
				if(!tag) ans = min(ans, f[t][i][j]);
			}
			ans = min(ans, f[t][i][s[t][i].length()]);
		}
	}
	printf("%lld", ans == 0x3f3f3f3f3f3f3f3f ? -1 : ans);
}

Measured memory_bytes: 3828
#include<iostream>
#include<string>
using namespace std;
int main(){
	int n,m,a,h[1000],p[1000],q[1000];
	while(true){
	cin>>n>>m>>a;
	if(n==0&&m==0&&a==0)
		break;
	for(int i=0;i<m;i++){
		cin>>h[i]>>p[i]>>q[i];
	}
	for(int i=0;i<m-1;i++){
		for(int j=m-1;j>i;j--){
			if(h[j]>h[j-1]){
				int tmp=h[j];
				h[j]=h[j-1];
				h[j-1]=tmp;
				tmp=p[j];
				p[j]=p[j-1];
				p[j-1]=tmp;
				tmp=q[j];
				q[j]=q[j-1];
				q[j-1]=tmp;
			}
		}
	}
	for(int i=0;i<m;i++){
		if(p[i]==a)
			a=q[i];
		else if(q[i]==a)
			a=p[i];
	}
	cout<<a<<endl;
	}
    return 0;
}

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

int main()
{
  int month, day;
  cin >> month >> day;
  int cnt = 0;
  for (int m = 1; m <= month; m++) {
    for (int d = 1; d <= day; d++) {
      int a = d / 10;
      int b = d % 10;
      if (2 <= a && 2 <= b && a * b == m) {
        cnt++;
      }
    }
  }
  cout << cnt << '\n';
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  
  cin>>s;
  int flag1=0,flag2=0;
  
  if((s.at(2)=='0')||(s.at(2)=='1')){
    if((s.at(2)=='0')&&(s.at(3)=='0'))
      flag2=1;
    
    if((s.at(3)>'2')&&(s.at(2)=='1'))
      flag2=1;
  }
  else
    flag2=1;
  
  if((s.at(0)=='0')||(s.at(0)=='1')){
    if((s.at(0)=='0')&&(s.at(1)=='0'))
      flag1=1;
    
    if((s.at(0)=='1')&&(s.at(1)>'2'))
      flag1=1;
  }
  else
    flag1=1;
  
  if(flag1==1){
    if(flag2==1)
      cout<<"NA"<<endl;
   else 
    cout<<"YYMM"<<endl;
  }
  else{
    if(flag2==1)
      cout<<"MMYY"<<endl;
    else
      cout<<"AMBIGUOUS"<<endl;
  }
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	string s;
	cin >> n >> s;
	int ans = 0, cnt = 0;
	rep(i,n){
		if(s[i] == '(') ++cnt;
		else{
			if(cnt > 0) --cnt;
			else ++ans;
		}
	}
	rep(i,ans) cout << "(";
	cout << s;
	rep(i,cnt) cout << ")";
	cout << endl;
	return 0;
}

Measured memory_bytes: 3636
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, s, e) for (int i = (int)(s); i < (int)(e); i++)
#define _rep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define _REP(i, e, s) for (int i = (int)(e - 1); i >= (int)(s); i--)

#define yes cout << "yes" << endl;
#define Yes cout << "Yes" << endl;
#define YES cout << "YES" << endl;

#define no cout << "no" << endl;
#define No cout << "No" << endl;
#define NO cout << "NO" << endl;

#define ll long long
#define ull unsigned long long

int N, K;
vector<bool> D(10, false);

bool isD(int N) {
    while (N > 0) {
        if (D[N % 10]) return true;
        N /= 10;
    }
    return false;
}

int main() {
    cin >> N >> K;
    rep(i, K) {
        int v;
        cin >> v;
        D[v] = true;
    }
    while (isD(N)) N++;
    cout << N << endl;
}

Measured memory_bytes: 256
def use_fast_io():
    global input
    import io
    import sys
    f = io.BytesIO(sys.stdin.buffer.read())
    input = f.readline
use_fast_io()


from scipy.sparse.csgraph import floyd_warshall
import numpy as np

N, M, L = map(int, input().split())
graph = [[float("inf")] * N for _ in range(N)]
for _ in range(M):
    s, t, w = map(int, input().split())
    if w <= L:
        graph[s-1][t-1] = graph[t-1][s-1] = w
graph = floyd_warshall(graph, directed=False)
graph = floyd_warshall(graph <= L, directed=False)
graph[np.isinf(graph)] = 0

Q = int(input())
ans = []
for _ in range(Q):
    s, t = map(int, input().split())
    ans.append(int(graph[s-1][t-1]) - 1)
print(*ans, sep='\n')


Measured memory_bytes: 19536
#ifdef lolipop
#define _GLIBCXX_DEBUG
#endif

/*
    This ain't a milly rock
    This a money dance
    And my D' ain't hard
    That's a '30 in my pants
*/

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <ctime>
#include <map>
#include <random>
#include <iomanip>
#include <cmath>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <cassert>
#include <bitset>
#include <deque>
#include <utility>

#define int long long
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define ld long double

using namespace std;

// mt19937 rnd(time(nullptr));

inline void fastio() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
}

const int maxN = 500 + 12;
int dp[maxN][maxN];

void solve() {
    int s, w;
    cin >> s >> w;
    if(w >= s) {
        cout << "unsafe";
    } else {
        cout << "safe";
    }
    cout << '\n';
}

signed main() {
#ifdef lolipop
    freopen("input.txt", "r", stdin);
#else
    fastio();
#endif

    int T = 1;
//    cin >> T;
    while(T--) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3136
#include "bits/stdc++.h"

using namespace std;

typedef pair<int, int> P;
#define int long long
#define ll long long
#define mod 1000000007
#define INF (1LL<<60)

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define YES cout << "YES" << endl;
#define Yes cout << "Yes" << endl;
#define NO cout << "NO" << endl;
#define No cout << "No" << endl;

struct UnionFind {
	vector< int > data;

	UnionFind(int sz) {
		data.assign(sz, -1);
	}

	bool unite(int x, int y) {
		x = find(x), y = find(y);
		if (x == y) return (false);
		if (data[x] > data[y]) swap(x, y);
		data[x] += data[y];
		data[y] = x;
		return (true);
	}

	int find(int k) {
		if (data[k] < 0) return (k);
		return (data[k] = find(data[k]));
	}

	int size(int k) {
		return (-data[find(k)]);
	}
};

signed main(){

	int N, M;
	cin >> N >> M;
	int a[123456], b[123456];
	for (int i = 0; i < M; i++){
		cin >> a[i] >> b[i];
		a[i]--; b[i]--;
	}

	UnionFind u(N);
	int ans[123456] = { 0 };
	int anstmp = 0;
	for (int i = M - 1; i >= 0; i--){
		int A = u.size(a[i]);
		int B = u.size(b[i]);
		bool united = u.unite(a[i], b[i]);
		if (united){
			anstmp+= A*B;
		}		
		ans[i] = anstmp;
	}
	for (int i = 0; i < M; i++){
		cout << N*(N - 1) / 2 - ans[i+1] << endl;
	}

	return 0;
}

Measured memory_bytes: 4992
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
# define LIM 1000000001

using namespace std;

int main(void) {
	int N;
	cin >> N;
	vector<int> a(N+1);
	for (int i = 0; i < N; ++i) {
		cin >> a[i];
	}
	a[N] = LIM;
	sort(a.begin(), a.end());

	int num = a[0];
	int res,len;
	res = len = 0;
	for (int i = 0; i < N+1; ++i) {
		if (a[i] == num) {
			++len;
		}
		else {
			if (len < num) {
				res += len;
			}
			else {
				res += len - num;
			}
			num = a[i];
			len = 1;
		}
	}
	cout << res << endl;

	return 0;
}


Measured memory_bytes: 640
//
// Created by yuu on 2019-06-19.
//

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <utility>
#include <math.h>
#include <stack>
#include <queue>
#include <cstdio>

using namespace std;


int main(void){
    int N;
    cin>>N;

    stack<string>s;
    for (int i = 0; i < N; ++i) {
        string temp;
        cin>>temp;
        s.push(temp);
    }


    int U_count = 0;
    for (int i = 0; i < N; ++i) {
        string temp;
        temp = s.top();
        s.pop();
        if(temp != "A"){
            U_count ++;
        }else{
            U_count --;
            if(U_count < 0){
                cout<<"NO"<<endl;
                return 0;
            }
        }
    }

    if(U_count != 0){
        cout<<"NO"<<endl;
    } else{
        cout<<"YES"<<endl;
    }

    return 0;
}


Measured memory_bytes: 3176
ss = input()
n = len(ss)

if ss[0] == '0' or ss[-1] == '1':
    print(-1)
    exit()
else:
    for s1, s2 in zip(ss[:n//2], ss[n//2-1:-1][::-1]):
#        print(s1, s2)
        if s1 != s2:
            print(-1)
            exit()

vMin, vMax = 1, n
iPrev = 0
#for i, s in enumerate(ss[:n//2], 1):
for i, s in enumerate(ss, 1):
    if s == '0': continue
#    print(i, ':', vMin)
#    if vMin > 1:
    print(vMin, vMin + 1)

    for j in range(i - iPrev - 1):
        print(vMin, vMax)
        vMax -= 1

    vMin += 1
    iPrev = i



Measured memory_bytes: 4632
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define  pb push_back
#define sort1(v) sort(v.begin(),v.end())
#include <sstream>
//gap between 2 primes is less than 300 for n<=10^9
//cout<<fixed<<setprecision(n)<<number - for n digits after decimal
//for all numbers less than 10^9 there are at max 10 distinct prime factors
void multiply(int n,int v[],int res[],int l)
{
    if(n==1)
    {
        res[l]=v[0];
        return ;
    }
    else
    {
        int a[n/2],b[n/2];
        for(int i=0;i<n/2;i++)
        {
            a[i]=v[i]+v[n/2+i];
            b[i]=v[i]-v[n/2+i];
        }
        multiply(n/2,a,res,l);
        multiply(n/2,b,res,l+n/2);
        return ;
    }
}
int main()
{
    cin.tie(NULL);
    ios_base::sync_with_stdio(false);
    int n;
    cin>>n;
    int a[n],b[n];
    int d=0;int flag=1;
    for(int i=0;i<n;i++)
    {
        cin>>a[i]>>b[i];
        if(a[i]==b[i])
            d++;
        else
            d=0;
        //cout<<d;
        if(d>=3)
            flag=0;
    }
    if(flag)
        cout<<"No\n";
    else
        cout<<"Yes\n";
}


Measured memory_bytes: 3560
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<climits>
#include<iostream>
#include<sstream>
#include<utility>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
#include<stack>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
set<int>a;
int main()
{
	int N;
	cin>>N;
	for(int i=0;i<N;i++)
	{
		int t;
		cin>>t;
		a.insert(t);
	}
	cout<<a.size()<<endl;
}


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

int main() 
{
    int N;
    cin >> N;
    map<long long, int, greater<long long>> mp;
    for(int i = 0; i < N; i++){
        long long hoge = 0;
        cin >> hoge;
        mp[hoge]++;
    }
    
    long long ans = 0;
    int count = 0;
    for (auto x : mp) {
        //cout << x.first << " : " << x.second << endl;
        if (x.second >= 4 && count == 0) {
            long long a = x.first * x.first;
            ans = max(ans, a);
            count += 2;
            break;
        } else if (x.second >= 2) {
            if (count == 0) {
                ans = x.first;
                count++;
            }else if(count == 1){
                ans *= x.first;
                count++;
                break;
            }
        }
    }
    
    if (count == 2) {
        cout << ans << endl;
    }else{
        cout << "0" << endl;
    }
}

Measured memory_bytes: 9728
#include <stdio.h>

int main() {
	int a=0;
	int b=0;
	int c=0;
	
	printf("");
	scanf("%d %d %d",&a,&b,&c);
	
	while(1){
		if(a>=0 && a<=100 && b>=0 && b<=100 && c>=0 && c<=100){
			break;
		}else{
			printf("");
			scanf("%d %d %d",&a,&b);
			continue;
		}	
	}
	
	if(a<b){
		if(b<c){
			printf("Yes\n");
		} else {
			printf("No\n");
		}
	} else {
		printf("No\n");
	}
	
	return 0;
}

Measured memory_bytes: 580
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

int par[40005],ran[40005];
void init(){ for(int i=0;i<40005;i++) par[i] = i; }
int find(int x){ if(x == par[x]) return x; else return par[x] = find(par[x]); }
void unite(int x,int y){
	x = find(x); y = find(y); if(x==y) return;
	if(ran[x] < ran[y]) par[x] = y;
	else{
		par[y] = x;
		if(ran[x] == ran[y]) ran[x]++;
	}
}
bool same(int x,int y){ return find(x)==find(y); }

vector<int>X[100005],Y[100005];
bool peri;
int main(){
	int n,w,h; scanf("%d%d%d",&n,&w,&h);
	rep(i,n){
		int a,b; scanf("%d%d",&a,&b);
		X[a].pb(i);
		Y[b].pb(i);
		if(a == 1 || a == w || b == 1 || b == h) peri = 1;
	}
	init();
	rep(i,100005){
		rep(j,X[i].size()){
			if(j) unite(X[i][j-1],X[i][j]);
		}
		rep(j,Y[i].size()){
			if(j) unite(Y[i][j-1],Y[i][j]);
		}
		
	}
	int cmp = 0;
	rep(i,n) if(find(i) == i) cmp++;
	int ans = n+cmp-1;
	if(cmp == 1 || peri) ans--;
	cout<<ans<<endl;
}


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

int n,q,k,cnt=0;
int head[100005],father[100005][25],depth[100005],lg[100005],pre[100005];

struct edge
{
	int next;
	int to;
	int dis;
}e[200005];

inline void add_edge(int u,int v,int w)
{
	cnt++;
	e[cnt].to=v;
	e[cnt].dis=w;
	e[cnt].next=head[u];
	head[u]=cnt;
}

inline void dfs(int now,int fath)
{
	depth[now]=depth[fath]+1;
	father[now][0]=fath;
	
	for (int i=1;i<=lg[depth[now]];i++)  father[now][i]=father[father[now][i-1]][i-1];
	for (int i=head[now];i;i=e[i].next)
	{
		if (e[i].to!=fath)  dfs(e[i].to,now);
	}
}

inline void dfs2(int now,int fath,int w)
{
	pre[now]=pre[fath]+w;
	for (int i=head[now];i;i=e[i].next)
	{
		if (e[i].to!=fath)  dfs2(e[i].to,now,e[i].dis);
	}
}

int LCA(int u,int v)
{
	if (depth[u]<depth[v])  swap(u,v);
	while (depth[u]>depth[v])  u=father[u][lg[depth[u]-depth[v]]-1];
	if (u==v)  return u;
	
	for (int k=lg[depth[u]];k>=0;k--)
	{
		if (father[u][k]!=father[v][k])
		{
			u=father[u][k];
			v=father[v][k];
		}
	}
	return father[u][0];
}

inline int read()
{
	int s=0,w=1;
	char ch=getchar();
	
	while (ch<'0'||ch>'9')
	{
		if (ch=='-')  w=-w;
		ch=getchar();
	}
	while (ch>='0'&&ch<='9')
	{
		s=(s<<1)+(s<<3)+(ch-'0');
		ch=getchar();
	}
	return s*w;
}

int query(int u,int v)
{
	int p=LCA(u,v);
	return (pre[u]-pre[p])+(pre[v]-pre[p]);
}

signed main()
{
	cin>>n;
	for (int i=1;i<n;i++)
	{
		int u,v,w;
		cin>>u>>v>>w;
		add_edge(u,v,w);
		add_edge(v,u,w);
	}
	for (int i=1;i<=n;i++)  lg[i]=lg[i-1]+((1<<lg[i-1])==i);
	
	cin>>q>>k;
	dfs(1,0);
	dfs2(1,0,0);
	
	for (int i=1;i<=q;i++)
	{
		int u,v;
		cin>>u>>v;
		cout<<query(u,k)+query(v,k)<<endl;
	}
	return 0;
}

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

int main(void){

    int n;
    long long a;
    long long min = 1000000;
    long long max = -1000000;
    long long sum = 0;
    
    
    cin >> n;
    
    for(int i = 0; i < n; i++) {
        
        cin >> a;
        
        if(a < min) {
            min = a;
        }
        
        if(a > max) {
            max = a;
        }
        
        sum += a;
        
    }
    
    cout << min << " " << max << " " << sum << endl;
    
    return 0;
    
}

Measured memory_bytes: 3096
#include <math.h>

int main(void){
  long x;
  scanf("%ld",&x);
  
  for(long i = -118;i <= 119;i ++){
    for(long j = -118;j <= i;j ++){
      if(((long)pow(i,5) - pow(j,5)) == x){
        printf("%d  %d",i,j);
        return 0;
      }
    }
  }
  return 0;
}

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
//const ull mod = 1e9 + 7;
const ll mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

// debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}
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 (a>b) { a=b; return 1; } return 0; }

// conversion number to bit
string num2bit(ll num, ll len){
  string bit = "";
  REP(i, len){
    bit += char('0'+(num>>i & 1));
  }
  return bit;
}

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

    ll N;
    cin >> N;
    vector<ll> C(N);
    REP(i, N) cin >> C[i];

    vector<ll> D;
    REP(i, N){
    	int j = i;
    	while(j<N && C[i]==C[j]) j++;
    	D.push_back(C[i]);
    	i = j - 1;
    }
    ll M = D.size();
    vector<vector<ll>> pos(202020);
    REP(i, M){
    	pos[D[i]].push_back(i);
    }
    vector<ll> dp(M+1, 0);
    dp[0] = 1;
    REP(i, M){
    	dp[i+1] += dp[i];
    	dp[i+1] %= mod;

    	if(i>0){
    		ll next = lower_bound(pos[D[i-1]].begin(), pos[D[i-1]].end(), i) - pos[D[i-1]].begin();
    		if(next>=(int)pos[D[i-1]].size()) continue;
    		ll next_pos = pos[D[i-1]][next];
    		dp[next_pos+1] += dp[i];
    		dp[next_pos+1] %= mod;
    	}
    }
    cout << dp[M] << endl;
    return 0;
}

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

int main(void) {
	int K, S;
	cin >> K >> S;
	int ans = 0;
	for (int x = 0; x <= K; ++x) {
		for (int y = 0; y <= K; ++y) {
			int z = S - x - y;
			if (z >= 0 && z <= K)
				++ans;
		}
	}
	cout << ans << '\n';
	return 0;
}


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

const ll MOD = 1000000007;

int main() {
    ll n;
    cin >> n;
    ll ans = 1;
    rep(i,n) {
        ans *= 10;
        ans %= MOD;
    }
    ll nine = 1;
    rep(i,n) {
        nine *= 9;
        nine %= MOD;
    }

    ll eight = 1;
    rep(i,n) {
        eight *= 8;
        eight %= MOD;
    }

    rep(i,2) {
        ans += MOD;
        ans -= nine;
        ans %= MOD;
    }
    
    ans += eight;
    ans %= MOD;

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

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

int main()
{
	int i,c=0;
	string s,t;
	
	cin>>s>>t;
	
	for(i=0;i<3;i++){
		if(s[i]==t[i]){
			c++;
		}
	}
	cout<<c<<endl;
	return 0;
}

Measured memory_bytes: 256
N,M=map(int,input().split())
A=list(map(int,input().split()))
All=sum(A)
hantei = All/4/M
ninki=0
for cnt in A:
    if cnt >=hantei:
        ninki+=1
if ninki>=M:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt(); //数
        //int[]b = new int[a]; //リンゴの味入れる配列
        int c = sc.nextInt(); //味初期値
        // int[] data = Taste(c, a, b);
        int[] data = Taste(c, a);
    
        //0に近いもの＝食べるものを決める
        int ans = Ans(data, a);
        System.out.println(ans);
        
    }

    // private static int[] Taste(int c,int a, int b[]){
    private static int[] Taste(int c,int a){
        int[]b = new int[a]; //リンゴの味入れる配列
        for(int i = 0; i < a; i++){
            //味入れていく
            b[i] = c + i;
        }
        return b;
    }

    //食べるもの決めたらその値0にしてすべて合算して返す
    private static int Ans(int data[], int a){
        //絶対値をとる（負の値対策）
        /*
        int[] data2 = data;
        https://eng-entrance.com/java-array-copy
        */
        //配列コピー
        int[] data2 = new int[a];
        for(int i = 0; i < data.length; i++){
            data2[i] = data[i];
            data2[i] = Math.abs(data2[i]);
        }

        /*上でまとめる
        for(int i = 0; i < a; i++){
            data2[i] = Math.abs(data2[i]);
        }
        */
        //これだと最後の足し算がおかしくなる
        //-3, -4が絶対値で3,4になるから。全て正の数なら問題ないけど
        Arrays.sort(data2);
        int noukin = data2[0];
        for(int i = 0; i < a; i++){
            //-noukinでよさそう
            if((noukin == data[i]) || ((noukin * -1) == data[i])){
                data[i] = 0;
                break;
            }
        }
        int ans = 0;
        for(int i = 0; i < a; i++){
            ans = ans + data[i];
        }
        return ans;
    }
}



Measured memory_bytes: 21716
def main():
    n = int(input())
    d = [int(e) for e in input().split(" ")]
    d.sort()
    n2 = int(n/2)

    if(d[n2] == d[n2-1]):
        print("0")
    else:
        print(d[n2] - d[n2-1])

if __name__ == "__main__":
    main()

Measured memory_bytes: 14392
#include <iostream>
using namespace std;
int main()
{
    int h,w;
    cin>>h>>w;
    while(h!=0)
    {
        int i,j;
        for(i=0; i<h; i++)
        {
            for(j=0; j<w; j++)
                cout<<"#";
            cout<<endl;
        }
        cout<<endl;
        cin>>h>>w;
    }
    return 0;
}



Measured memory_bytes: 3092
import sys
import math
from collections import deque
from collections import defaultdict

def main():
    x, n = list(map(int,sys.stdin.readline().split()))
    p = list(map(int,sys.stdin.readline().split()))
    if not x in p:
        print(x)
        return 0
    t = 1 #差を表す
    while(True):
        search_num = x - t
        if not search_num in p:
            print(search_num)
            break
        search_num = x + t
        if not search_num in p:
            print(search_num)
            break
        t += 1


    return 0

if __name__ == "__main__":
    main()

Measured memory_bytes: 9480
#include<cstdio>
#include<vector>
#include<algorithm>

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

using namespace std;

typedef long long ll;

const int INF=1<<29;

int main(){
	const int Ne=1000000;
	static bool er[Ne+1]; er[0]=er[1]=true;
	for(int i=2;i*i<=Ne;i++) if(!er[i]) for(int j=i*i;j<=Ne;j+=i) er[j]=true;
	vector<int> p; rep(i,Ne+1) if(!er[i]) p.push_back(i);

	ll a,b; scanf("%lld%lld",&a,&b);

	b+=a;
	a=max(2*a-b,2LL);

	static int e[1000001];
	fill(e,e+b-a+1,INF);
	rep(i,p.size()){
		int pr=p[i];
		for(ll j=(a+pr-1)/pr*pr;j<=b;j+=pr){
			if(e[j-a]==-1) continue;

			ll jj=j;
			int cnt=0;
			do{
				jj/=pr;
				cnt++;
			}while(jj%pr==0);

			e[j-a]=(e[j-a]<cnt?-1:cnt);
		}
	}

	printf("%lld\n",(b-a+1)-count(e,e+b-a+1,-1));

	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
    //ios::sync_with_stdio(false);
    //cin.tie(nullptr);
    ll n,a,b;
    string s;
    ll yos = 0;
    ll kai=0;
    cin >> n >> a >> b >> s;
    for(int i=0;i<n;i++){
        if(s.at(i)=='b')kai++;

        if(s.at(i)=='a'&&yos<a+b){
            yos++;
            cout << "Yes" << "\n";
        }
        else if(s.at(i)=='b'&&yos<a+b&&kai<=b){
            yos++;
            cout <<  "Yes" << "\n";
        }
        else{
            cout << "No" << "\n";
        }
    }

    return 0;
}

Measured memory_bytes: 896
#include <iostream>
#include <string>
#include <string.h>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <stdio.h>
#include <vector>
#include <time.h>

//     MLE,TLE魔
//↓↓↓↓↓↓↓↓↓↓↓↓
#define int long long
//↑↑↑↑↑↑↑↑↑↑↑↑
//     MLE,TLE魔
#define endre getchar();getchar();return 0
#define moder 1000000007
#define inf 5000000000000000000
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P pair<int,int>
#define all(v) v.begin(),v.end()
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define vecunique(vec) sort(vec.begin(), vec.end());decltype(vec)::iterator result = std::unique(vec.begin(), vec.end());vec.erase(result, vec.end())
using namespace std;

bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int mod_pow(int x, int y, int mod) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x%mod;
		}
		x = x * x%mod;
		y >>= 1;
	}
	return res;
}
int kai(int x) {
	if (x == 0)return 1;
	return (kai(x - 1)*x) % moder;
}
int comb(int x, int y) {
	return kai(x)*mod_pow(kai(x - y), moder - 2, moder) % moder*mod_pow(kai(y), moder - 2, moder) % moder;
}
struct edge { int to, cost; };
int dx[5] = { 0,1,0,-1 }, dy[5] = { 1,0,-1,0 };
map<int, int>factor(int x) {
	map<int, int>res;
	for (int i = 2; i*i <= x; i++) {
		while (x%i == 0) {
			x /= i;
			res[i]++;
		}
	}
	if (x != 1)res[x]++;
	return res;
}
/*--------Library Zone!--------*/

int n;
double sum;
signed main() {
	cin >> n;
	rep(i, n) {
		double d;
		string s;
		cin >> d >> s;
		if (s == "JPY")sum += d;
		else sum += d * 380000.0;
	}
	printf("%.12lf\n", sum);
	endre;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
const double PI = 3.141592653589793238;
const double EPS = 1e-10;
ll A[100000];
ll maxA[100000];
int main() {
	int N, T;
	cin >> N >> T;
	for (int i = 0; i < N; i++) cin >> A[i];
	maxA[N - 1] = A[N - 1];
	for (int i = N - 2; i >= 0; i--) {
		maxA[i] = max(maxA[i + 1], A[i]);
	}
	ll now = 0;
	for (int i = 0; i + 1 < N; i++) {
		now = max(maxA[i + 1] - A[i], now);
	}
	int ans = 0;
	for (int i = 0; i + 1 < N; i++) {
		if (maxA[i + 1] - A[i] == now) {
			ans++;
		}
	}
	cout << ans << endl;
}


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

int main()
{
  int n ;
  cin >> n ;
  vector<int> data(n) ;
  for(int i = 0 ; i < n ; i++)
  {
    cin >> data.at(i) ;
  }
  sort(data.begin(), data.end()) ;

  cout << data.at(n - 1) - data.at(0) << endl ;
}

Measured memory_bytes: 256