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

public class Main {

	static final long r = 5 * (long) Math.pow(10, 15);

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		long k = sc.nextLong();
		sc.close();
		int n = s.length();
		int ans = 1;
		for(int i = 0; i < k; ++i) {
			int tmp = Integer.parseInt(s.substring(i, i + 1));
			if(tmp != 1) {
				ans = tmp;
				break;
			}
			
		}
		System.out.println(ans);
	}

}


Measured memory_bytes: 22868
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int n,k,h[3][100000],dp[3][100000];
  
  cin >> n;
  
  for(int i=0; i<n; i++){
    cin >> h[0][i] >> h[1][i] >> h[2][i];
  }
  
  dp[0][0] = h[0][0];
  dp[1][0] = h[1][0];
  dp[2][0] = h[2][0];
  
  for(int i=1; i<n; i++){
    dp[0][i] = max( dp[1][i-1], dp[2][i-1] ) + h[0][i];
    dp[1][i] = max( dp[2][i-1], dp[0][i-1] ) + h[1][i];
    dp[2][i] = max( dp[0][i-1], dp[1][i-1] ) + h[2][i];
  }
  
  cout << max( dp[0][n-1], max(dp[1][n-1], dp[2][n-1]) ) << endl;
  
  return 0;
}

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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int sum=0,rem=0;
	for(int i=0;i<5;++i){
		int a; cin>>a;
		sum+=(a+9)/10*10;
		rem=max(rem,(10-a%10)%10);
	}
	cout<<sum-rem<<"\n"s;
}


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

int main() {
  int N, M;
  cin >> N >> M;
  //二次元配列の宣言
  vector<vector<char>> input(N, vector<char>(M));
  vector<vector<char>> result;
  for (auto &vec: input) {
    for (auto &ch: vec)
    {
      cin >> ch;
    }
  }

  // 表示する列を決定する
  vector<int> vecInt;
  for(int j = 0; j < M; j ++)
  {
    string tempStr;
    for(int i = 0; i < N; i ++)
    {
      if(input.at(i).at(j) == '#')
      {
        vecInt.push_back(j);		//表示する列を決定
        break;
      }
    }
  }
    
  for (auto &vec: input) {
    // 行に#があれば出力する。
    if(count(vec.begin(), vec.end(), '#') != 0 )
    {
      for(auto i: vecInt)
      {
        cout << vec.at(i);
      }
      cout << endl;
    }
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <bitset>
#include <functional>
#include <queue>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define dump(x)  cerr << #x << " = " << (x) << endl;
typedef long long LL;

using namespace std;

int main(void)
{
	int N, M, C;
	int B[21], A[21][21];

	cin >> N >> M >> C;
	FOR(i, 0, M) {
		cin >> B[i];
	}
	FOR(i, 0, N) {
		FOR(j, 0, M) {
			cin >> A[i][j];
		}
	}

	int ans = 0;
	FOR(i, 0, N) {
		int sum = C;
		FOR(j, 0, M) {
			sum += A[i][j] * B[j];
		}
		if (sum > 0) {
			ans++;
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
using namespace std;

typedef long long ll;

ll t[200005];

int main() {
	int n; ll T; cin >> n >> T;
	for (int i = 0; i < n; ++i) {
		cin >> t[i];
	}
	ll ans = 0;
	for (int i = 0; i < n - 1; ++i) {
		ans += min(T, t[i + 1] - t[i]);
	}
	ans += T;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1792
// 問題の URL を書いておく
// 

#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>

using namespace std;

//#define ENABLE_PRINT

#if defined(ENABLE_PRINT)

#define Print(v) \
do {\
    cout << #v << ": " << v << endl; \
}while(0)

#define PrintVec(v) \
do {\
    for(int __i = 0; __i < v.size(); ++__i) \
    { \
        cout << #v << "[" << __i << "]: " << v[__i] << endl; \
    }\
}while(0)

#else

#define Print(v) ((void)0)
#define PrintVec(v) ((void)0)

#endif

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

using ll = int64_t;

int main(int, const char**)
{
    string x;
    cin >> x;
    vector<char> s(x.size());
    s.resize(0);
    for(auto c : x)
    {
        s.push_back(c);
        if(s.size() >= 2)
        {
            if(s[s.size() - 1] == 'T' && s[s.size() - 2] == 'S')
            {
                s.resize(s.size() - 2);
            }
        }
    }
    cout << s.size() << endl;
    return 0;
}


Measured memory_bytes: 3848
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for (int i = s; i < (int)(n); i++)
#define out(x) cout << x << endl
#define INF 1000000;
#include <map>
#include <math.h>
 
using ll = long long;
using namespace std;

ll n, k;
const ll mod = 1000000007;

int main(){
    int a, b, c;
    cin >> a >> b >> c;
    if(a==b) out(c);
    else if(b==c) out(a);
    else out(b);
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();
		int ans = (a * n < b) ? a * n : b;
		System.out.println(ans);
	}
}


Measured memory_bytes: 22996
#include <stdio.h>

int main(void)
{
	int most[100];
	int ans[100];
	int a, b, c, d;
	int max;
	
	for (a = 0; a < 100; a++) {
		most[a] = 0;
	}
	while (scanf("%d", &a) != EOF){
		most[a-1]++;
	}
	b = 0;
	max = most[0];
	ans[b] = 1;
	b++;
	for (a = 1; a < 100; a++) {
		if (max < most[a]) {
			b = 0;
			ans[b] = a + 1;
			b++;
			max = most[a];
		}
		else if (max == most[a]) {
			ans[b] = a + 1;
			b++;
		}
	}
	
	for (a = 0; a < b; a++) {
		printf("%d\n", ans[a]);
	}
	
	return (0);
}

Measured memory_bytes: 592
n,w = map(int,input().split())

lstw, lstv = [], []
for i in range(n):
    w_,v_ = map(int,input().split())
    lstw.append(w_)
    lstv.append(v_)

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

for i in range(n):
    for j in range(w+1):
        if j < lstw[i]:
            dp[i+1][j] = dp[i][j]
        else:
            dp[i+1][j] = max(dp[i][j], dp[i][j-lstw[i]]+lstv[i])
print(dp[n][w])

Measured memory_bytes: 171400
# N,A,B,C,D,E=$<.read.split.map(&:to_i)

# a = (N+A-1)/A
# b = ((N-[A,B].min*(a-1))+B-1)/B
# c = ((N-[A,B,C].min*(a+b-2))+C-1)/C
# d = ((N-[A,B,C,D].min*(a+b+c-3))+D-1)/D
# e = ((N-[A,B,C,D,E].min*(a+b+c+d-4))+E-1)/E
# puts (a+b+c+d+e)
# # puts [a,b,c,d,e]


N,*as=$<.read.split.map(&:to_i)
puts (N/as.min.to_f).ceil + 4

Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main(){
    ll n,i;
    cin>>n;
    ll ans = n+2;
    for(i=1;i<=sqrt(n);i++){
        if(n%i!=0)
        continue;
        ll fir = i-1;
        ll sec = n/i-1;
        ll temp = fir+sec;
        ans = min(ans,temp);
    }
    cout<<ans;
    return 0;
}

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

string S;
int N;
vector<vector<int> > prec;
vector<int> nxt;

vector<int> cc;
int dp(int x) {
    if(x == N + 1) return 0;
    int &ret = cc[x];
    if(ret != -1) return ret;

    ret = 1e9;
    for(int i = 0; i < 26; i++) {
        ret = min(ret, 1 + dp(prec[x][i] + 1));
    }
    return ret;
}

string ans;

void dfs(int x) {
    if(x == N + 1) return;
    for(int i = 0; i < 26; i++) {
        if(dp(x) == 1 + dp(prec[x][i] + 1)) {
            ans.push_back('a' + i);
            dfs(prec[x][i] + 1);
            return;
        }
    }
}

int main() {
    cin >> S;
    N = S.size();
    prec = vector<vector<int> >(N + 1, vector<int>(26, N));
    nxt = vector<int>(26, N);

    for(int i = N - 1; i >= 0; i--) {
        nxt[ S[i] - 'a' ] = i;
        for(int j = 0; j < 26; j++) {
            prec[i][j] = nxt[j];
        }
    }

    cc = vector<int>(N + 1, -1);
    dfs(0);
    cout << ans;
}


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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    int d, g;
    cin >> d >> g;
    vi p(d), c(d);
    rep(i, d) cin >> p[i] >> c[i];
    g /= 100;
    rep(i, d) c[i] /= 100;
    int ans = INT32_MAX;
    rep(i, 1<<d) {
        int sum = 0, cnt = 0;
        repr(j, d) {
            if (i&(1<<j)) {
                int add = (j+1) * p[j];
                if (sum + add > g) {
                    int addc = (g - sum) / (j+1);
                    cnt += addc;
                    sum += addc * (j+1);
                    break;
                }
                else {
                    cnt += p[j];
                    sum += add + c[j];
                }
                if (sum >= g) break;
            }
        }
        if (sum >= g) ans = min(ans, cnt);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
N = int(input())
S = input()
ans = 0
for i in range(10):
    for j in range(10):
        for k in range(10):
            flag_i = False
            flag_j = False
            flag_k = False
            for t in range(N):
                if not flag_i and S[t] == str(i):
                    flag_i = True
                elif flag_i and not flag_j and S[t] == str(j):
                    flag_j = True
                elif flag_i and flag_j and not flag_k and S[t] == str(k):
                    flag_k = True
            if flag_i and flag_j and flag_k:
                ans += 1
print(ans)


Measured memory_bytes: 46812
#include <iostream>
#include <fstream>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <complex>
#include <cstdio>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

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

int n,dp[1001][1001];

int main(){
	while(cin>>n&&n){
		rep(i,n)fill(dp[i],dp[i]+n,0);
		int ans=0;
		char c;
		rep(i,n)rep(j,n){
			cin>>c;
			if(c=='.'){
				if(!i||!j)dp[i][j]=1;
				else dp[i][j]=min(dp[i-1][j-1],min(dp[i-1][j],dp[i][j-1]))+1;
			}
			ans=max(ans,dp[i][j]);
		}
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 3900
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>

static const int INF = 1000000007;
using ll = long long;
using namespace std;

int main() {
    int h, w;
    string s;
    cin >> h >> w;
    for (int i = 0; i < h; ++i) {
        cin >> s;
        cout << s << "\n" << s << "\n";
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using node = tuple<int,int,int>;

int d[5] = {1,1,-1,-1,1};
int main(void){
  int n;
  cin >> n;
  vector< P > v;
  map<P,int> m;
  for(int i = 0;i < n;++i){
    int x,y,w;
    cin >> x >> y >> w;
    v.push_back(P(x,y));
    m[P(x,y)] = w;
  }
  int res = 0;
  for(int i = 0;i < n;++i){
    int x = v[i].first,y = v[i].second;
    for(int j = 0;j < 4;++j){
      int dx = d[j],dy = d[j+1];
      int calc =
        m[P(x,y)] + m[P(x,y+dy)]
        + m[P(x+dx,y)] + m[P(x+dx,y+dy)];
      res = max(res,calc);
    }
  }
  printf("%d / 1\n",res);
  return 0;
}

Measured memory_bytes: 59740
// calc a point of symmetry by using vector
#include <iostream>
#include <iomanip>
#include <cstdio>
using namespace std;

int main(){
	double x1, y1, x2, y2, xq, yq;
	double py, px, t;
	double ax, ay;
	while (~scanf("%lf,%lf,%lf,%lf,%lf,%lf\n", &x1, &y1, &x2, &y2, &xq, &yq)) {
		px = x2 - x1;
		py = y2 - y1;
		t = (px*(xq - x1) + py*(yq - y1)) / (px*px + py*py);
		ax = 2.0*t*px + 2.0*x1 -xq;
		ay = 2.0*t*py + 2.0*y1 -yq;
		cout << setprecision(20);
		cout << showpoint << ax << " " << ay << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n ; i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define whole(f, x, ...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x) // decltypeで型取得、引数があればva_argsのところに入れる
using namespace std;
typedef long long ll; // long longをllでかけるようにした
const int INF = 1e9;

int main(void){
    string s; cin >> s;
    cout << (s[0] != s[1] and s[1] != s[2] and s[0] != s[2] ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int k=sc.nextInt();
		int[] arr=new int[n];
		for(int i=0;i<n;i++)arr[i]=sc.nextInt();
		Arrays.sort(arr);
		long s=0;
		for(int i=0;i<n-k;i++)s+=arr[i];
		System.out.println(s);
	}
}

Measured memory_bytes: 88516
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;

namespace AtCoder
{
    class Program
    {
        static void Main()
        {
            var S = ReadLine();

            WriteLine(S.Last() == 's' ? S + "es" : S + "s");
        }

    }
}


Measured memory_bytes: 26148
#include <iostream>

int min(int a, int b){
    if(a>b) return b;
    else return a;
}

int price(int n, int a, int b){
    int num = a;
    int price = b;
    while(n > num) {
        num += a;
        price += b;
    }
    return price;
}
int main()
{
    int n, a, b, c, d;
    int sum[2];
    std::cin >> n >> a >> b >> c >> d;
    sum[0] = price(n,a,b);
    sum[1] = price(n,c,d);
    std::cout << min(sum[0],sum[1]) << std::endl;
    return 0;
}


Measured memory_bytes: 3120
#include<stdio.h>

int main(void){
   long long a,b,c,d;
   long long ans;
   scanf("%lld %lld %lld %lld",&a,&b,&c,&d);
   if(a*c>a*d) ans=a*c;
   else ans=a*d;

   if(b*c>ans)ans=b*c;

   if(b*d>ans)ans=b*d;

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

Measured memory_bytes: 3216
from collections import deque
H, W, D = map(int, input().split())
mod_dict = [deque() for _ in range(D)]
h = 0
while h < H:
  A = list(map(int, input().split()))
  w = 0
  while w < W:
    a = A[w]
    mod_dict[a%D].append((a, h, w))
    w += 1
  h += 1
ruiseki_dict = [deque() for _ in range(D)]
d = 0
while d < D:
  m = sorted(mod_dict[d], key=lambda x:x[0])
  py, px = m[0][1], m[0][2]
  ruiseki_dict[d].append(0)
  i = 0 if d == 0 else 1
  while i < len(m):
    ry, rx = m[i][1], m[i][2]
    ruiseki_dict[d].append(ruiseki_dict[d][-1]+abs(ry-py)+abs(rx-px))
    py, px = ry, rx
    i += 1
  d += 1
Q = int(input())
for _ in range(Q):
  l, r = list(map(int, input().split()))
  d = ruiseki_dict[r%D]
  print(d[r//D]-d[l//D])

Measured memory_bytes: 156040
#include<cstdio>
#include<cmath>
using namespace std;
int main(){
	int a,b;
	scanf("%d %d",&a,&b);
	int len=0,k=b;
	while(b/10>0){
		len++;
		b/=10;
	}
	len++;
	int c=a*pow(10,len)+k;
	int d=sqrt(c);
	if(d*d==c)
		printf("Yes");
	else
		printf("No");
	return 0;
}

Measured memory_bytes: 384
Ss = input()

if Ss[0] == 'A' and Ss[2:-1].count('C') == 1:
    iC = Ss[2:-1].find('C') + 2
    if (Ss[1:iC] + Ss[iC+1:]).islower():
        print('AC')
    else:
        print('WA')
else:
    print('WA')


Measured memory_bytes: 2940
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#include<numeric>
#include<set>
#include<string>
#include<utility>
#include<vector>

#define rep(i, a, n)  for(int i=a; i<n; i++)
#define per(i, a, n)  for(int i=n-1; i>=a; i--)
#define all(x)  (x).begin(), (x).end()
#define MAX 10000
using namespace std;

int main(){
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  int upper = min(b, d);
  int lower = max(a, c);
  cout << max(0, upper-lower) << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main()
{
int a,b;
while(1)
{
scanf("%d %d",&a,&b);
if(-1000<=a,b&&a,b<=1000)
break;
}

if(a>b)
printf("a > b\n");

else if(a<b)
printf("a < b\n");

else
printf("a == b\n");

return 0;
}

Measured memory_bytes: 580
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using static System.Console;

class Program
{
    static void Main(string[] args)
    {
        var S = ReadLine();

        var stack = new Stack<char>();

        foreach (var c in S)
        {
            if (0 < stack.Count && stack.Peek() != c)
                stack.Pop();
            else
                stack.Push(c);
        }

        var ans = S.Length - stack.Count;

        WriteLine(ans);
    }
}


Measured memory_bytes: 26856
#include<bits/stdc++.h>
using namespace std;
#define all(vec) vec.begin(),vec.end()
typedef long long int ll;
typedef pair<int,int> P;
const ll MOD=1000000007;
const ll INF=1000000010;
const ll LINF=4000000000000000010LL;
const int MAX=310;
const double EPS=1e-9;
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
int main(){
    int n;cin>>n;
    int ma=-1;int aa=INF;
    for(int i=0;i<n;i++){
        int a,v;cin>>a>>v;
        if(v>ma){
            aa=a;
            ma=v;
        }else if(v==ma){
            aa=min(aa,a);
        }
    }
    cout<<aa<<" "<<ma<<endl;
}



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

N = int(input())
S = list(str(input()))
ans = 0

for i in range(1, N):
    x = set(S[0:i])
    y = set(S[i:])
    intrsect_x_y = x & y
    ans = max(ans, len(intrsect_x_y))

print(ans)

Measured memory_bytes: 9084
import sys

input = sys.stdin.readline

n = int(input())
dp = [i for i in range(n+1)]

yen = [6 ** i for i in range(1, 8) if 6 ** i <= n]
yen += [9 ** i for i in range(1, 7) if 9 ** i <= n]

for i in range(n+1):
    for j in yen:
        if i - j >= 0:
            dp[i] = min(dp[i], dp[i - j] + 1)

print(dp[-1])

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

int main(){
	int a,b;
	bool first=true;
	while(cin>>a>>b,a||b){
		bool f=false;
		if(!first)cout<<endl;
		if(a&3)a+=4-(a&3);
		while(a<=b){
			if(a%100 || a%400==0){
				f=true;
				cout<<a<<endl;
			}
			a+=4;
		}
		if(!f)cout<<"NA"<<endl;
		first=false;
	}
	return 0;
}

Measured memory_bytes: 1156
import sys
import itertools
import bisect

N, M, K = map(int, input().split())
A = list(map(int, sys.stdin.readline().rsplit()))
B = list(map(int, sys.stdin.readline().rsplit()))

sA = [0] + list(itertools.accumulate(A))
sB = [0] + list(itertools.accumulate(B))

res = 0
for i, a in enumerate(sA):
    if K < a:
        break
    j = bisect.bisect_right(sB, K - a) - 1
    res = max(res, i + j)

print(res)


Measured memory_bytes: 49304
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>
#include<complex>
#include <cassert>

using namespace std;

#define ll long long
#define ld long double
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

const double PI=acos(-1);
const double EPS=1e-9; //うまくいかなかったらゆるめる

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef pair<int,pii> pip;
typedef vector<pii> vp;
typedef vector<vi> vvi;

int gcd(int a, int b){if(b==0) return a;return gcd(b,a%b);}
int lcm(int a, int b){return a/gcd(a,b)*b;}


signed main(void) {
	string s,t;
    int n,a,b,c,d,e,x,y;
    cin >> n;
	if(n < 30)cout << "No"<< endl;
	else cout << "Yes" << endl;
}


Measured memory_bytes: 3584
#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(){
	int n;
	cin >> n;
	vector<int> a(n);
	rep(i,n) cin >> a[i];
	vector<int> b = a;
	sort(b.begin(),b.end());
	reverse(b.begin(),b.end());
	rep(i,n){
		if(a[i] == b[0]) cout << b[1] << endl;
		else cout << b[0] << endl;
	}
}

// cout << fixed << setprecision(15) <<  << endl;

Measured memory_bytes: 4792
#include<iostream>
#include<algorithm>
#include<vector>
#include<numeric>
#include<string>
using namespace std;

int main(){
  int n; cin >> n;
  int a[101];
  for (int i=0;i<n;i++) cin >> a[i];

  int ans = 0;
  int flag = 1;

  while (flag){
    flag = 0;
    for(int i=0;i<n-1;i++){
      if (a[i] > a[i+1]){
        swap(a[i],a[i+1]);
        flag = 1;
        ans++;
      }
    }
  }
  for (int i=0;i<n;i++){
    cout << a[i];
    if (i != n-1) cout << " ";
  }
  cout << endl << ans << endl;

  return 0;
}




Measured memory_bytes: 3096
import java.util.Scanner;
import java.util.Stack;


public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		Stack<Integer> st = new Stack<Integer>();
		
		while(sc.hasNext()){
			int num = sc.nextInt();
			
			if(num == 0){
				int tmp = st.pop();
				System.out.println(tmp);
			}
			else {
				st.push(num);
			}
		}
	}
}

Measured memory_bytes: 17208
// This file is a "Hello, world!" in C++ language by GCC for wandbox.
#include <iostream>
#include <cstdlib>
#include<vector>

using namespace std;

int main()
{
    int n,k;
    cin>>n>>k;
    vector<int>h(n);
    for(int i=0;i<n;++i){
        cin>>h[i];
    }
    int ans=0;
    for(auto x:h){
        if(x>=k)ans++;
    }
    cout<<ans<<endl;
}


// GCC reference:
//   https://gcc.gnu.org/

// C++ language references:
//   https://cppreference.com/
//   https://isocpp.org/
//   http://www.open-std.org/jtc1/sc22/wg21/

// Boost libraries references:
//   https://www.boost.org/doc/


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

int main(){
    int n;
    cin>>n;
    vector<int> a(n);
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    sort(a.begin(),a.end());
    n=(n/2)-1;
    if(a[n+1]-a[n]>0){
        cout<<a[n+1]-a[n];
    }
    else{
        cout<<0;
    }
}

Measured memory_bytes: 640
def yu(a):
    n = len(a)
    used = [False for i in range(n)]
    fact = 1
    ans = 0
    for i, x in enumerate(a[::-1]):
        cur = 0
        for y in range(x):
            if used[y]:
                cur += 1
        ans += cur * fact
        fact *= (i + 1)
        used[x-1] = True
    return ans
        

n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
print(abs(yu(a) - yu(b)))


Measured memory_bytes: 38256
from collections import deque
from math import ceil

n,d,a = map(int,input().split())
M = [list(map(int,input().split())) for i in range(n)]
M = [[x,ceil(h/a)] for x,h in M]
M = sorted(M)

que = deque()

ans = 0
atack = 0
for x,h in M:
  while len(que) > 0 and que[0][0] < x:
    tx,ta = que.popleft()
    atack -= ta      
  
  bomb_num = max(0, h-atack)
  atack += bomb_num
  ans += bomb_num
  
  if bomb_num > 0:
    que.append([x+d*2,bomb_num])

print(ans)  

Measured memory_bytes: 70188
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <unordered_map>


using namespace std;

typedef long long ll;
const int Max_N = 100000;
ll N;
unordered_map<std::string, int> um;

int main(){
  cin >> N;
  for(int i=0;i<N;i++){
    string m;
    cin >> m;
    sort(m.begin(),m.end());
    um[m]+=1;
  }
  ll sum=0;
  for(auto itr = um.begin(); itr != um.end(); ++itr) {
    sum+= 1ll*(itr->second)*(itr->second-1);
  }
  cout << sum/2ll << endl;
}



Measured memory_bytes: 7328
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define int long long

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define REV(i, a) for (int i = (a); i >= 0; --i)
#define CLR(a) memset((a), 0, sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF (3e15)

using namespace std;

int N;
int P[200005];
int Q[200005];

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin >> N;

    REPS(i, N) { cin >> P[i]; }

    int sub = 0;
    REPS(i, N) {
        int p = P[i];
        Q[p] = Q[p - 1] + 1;
        sub = max(sub, Q[p]);
    }

    cout << N - sub << endl;

    return 0;
}


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



int main(){
	int x;
	int ans = 1;
	rep(i,5){
		cin >> x;
		if(x == 0){
			break;
		}
		ans++;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3596
// JAI SHREE RAM
#pragma GCC optimize("O3")
typedef long long int ll;
typedef unsigned long long int ull;
#define fast  ios_base::sync_with_stdio(false); cin.tie(NULL);
#define sec second
#define fir first
#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define repe(i,m,n) for(ll (i)=(m);(i)<(n);(i)++)
#define pb push_back
#define pii pair<int,int>
# define M_PI           3.14159265358979323846  /* pi */
#include<bits/stdc++.h>
#include<cmath>
using namespace std;
void solve()
{
double a,b,h,m;
cin>>a>>b>>h>>m;
double angle=abs((h*30 + (m/60)*5*6)-(m*6));
angle=max(angle,abs(360-angle));
double ans=sqrt(a*a +b*b -2*a*b*cos(angle*(M_PI/180)));
cout<<setprecision(10)<<ans<<endl;
}


int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	fast
	int T;
	T = 1;
	// cin >> T;
	while (T--)
	{
		solve();
	}
	return 0;
}


Measured memory_bytes: 4248
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 28;
int a[maxn];
pair <int, int> v0[maxn], v1[maxn];
int main(){
	ios::sync_with_stdio(0), cin.tie(0);
	int n;
	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> a[i];
		if(i % 2 == 0){
			v0[a[i]].first ++;
			v0[a[i]].second = a[i];
		}
		else{
			v1[a[i]].first ++;
			v1[a[i]].second = a[i];
		}
	}
	sort(v0, v0 + maxn);
	sort(v1, v1 + maxn);
	reverse(v0, v0 + maxn);
	reverse(v1, v1 + maxn);
	if(v0[0].second != v1[0].second)
		cout << n - v0[0].first -  v1[0].first;
	else if(v0[0].first + v1[1].first > v1[0].first + v0[1].first)
		cout << n - v0[0].first - v1[1].first;
	else
		cout << n - v1[0].first - v0[1].first;
}


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

int main()
{
	int i, j, H, W, c[10][10], A[201][201];
	scanf("%d %d", &H, &W);
	for (i = 0; i < 10; i++) {
		for (j = 0; j < 10; j++) scanf("%d", &(c[i][j]));
	}
	for (i = 1; i <= H; i++) {
		for (j = 1; j <= W; j++) scanf("%d", &(A[i][j]));
	}
	
	int k = 1, cost[10] = {}, flag[10] = {}, min;
	for (i = 0; i < 10; i++) cost[i] = 10000;
	cost[1] = 0;
	while (1) {
		flag[k] = 1;
		for (j = 0; j < 10; j++) cost[j] = (cost[k] + c[j][k] < cost[j])? cost[k] + c[j][k]: cost[j];
		
		min = 10000;
		for (j = 0; j < 10; j++) {
			if (flag[j] == 0 && cost[j] < min) {
				min = cost[j];
				k = j;
			}
		}
		if (min == 10000) break;
	}
	
	int sum = 0;
	for (i = 1; i <= H; i++) {
		for (j = 1; j <= W; j++) {
			if (A[i][j] != -1) sum += cost[A[i][j]];
		}
	}
	printf("%d\n", sum);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 384
import java.util.*;
public class Main {
  	static int mod = 1000000007;
  static int size = 200001;
	static long[] fac = new long[size];
	static long[] finv = new long[size];
	static long[] inv = new long[size];
	static int INF = Integer.MAX_VALUE;
public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
	// 整数の入力
	int N = sc.nextInt();
    int K = sc.nextInt();
  int red =N-K;
  long kazu = 0;
  initComb();
  for(int i=0;i<K;i++){
    kazu=0; 
    System.out.println(comb(K-1,i)*comb(red+1,i+1)%mod);
  }


} 

 //fac, inv, finvテーブルの初期化、これ使う場合はinitComb()で初期化必要
	public static  void initComb(){
		fac[0] = finv[0] = inv[0] = fac[1] = finv[1] = inv[1] = 1;
		for (int i = 2; i < size; ++i) {
			fac[i] = fac[i - 1] * i % mod;
			inv[i] = mod - (mod / i) * inv[(int) (mod % i)] % mod;
			finv[i] = finv[i - 1] * inv[i] % mod;
		}
	}
 
	//nCk % mod
	public static long comb(int n, int k){
        if (n < k) return 0;
        if (n < 0 || k < 0) return 0;
		return fac[n] * finv[k] % mod * finv[n - k] % mod;
	}
 
	//n! % mod
	public static long fact(int n){
		return fac[n];
	}
 
	//(n!)^-1 with % mod
	public static long finv(int n){
		return finv[n];
	}
  
}



Measured memory_bytes: 28628
#include <cstdio>
#include <cstdlib>

typedef struct tree_{
    int parent;
    int depth;
    int noc;
    int *child;
}tree;

void setDepth(tree *node, int id, int depth){
    node[id].depth = depth;
    for(int i=0;i<node[id].noc;i++)setDepth(node,node[id].child[i],depth+1);
    return;
}

int main(){
    int i, j, n, id, k, c, root;
    scanf("%d",&n);
    tree node[n];
    for(i=0;i<n;i++)node[i].parent = -1;
    for(i=0;i<n;i++){
        scanf("%d %d",&id,&k);
        node[id].noc = k;
        node[id].child = (int *)malloc(sizeof(int)*k);
        for(j=0;j<k;j++){
            scanf("%d",&c);
            node[id].child[j]=c;
            node[c].parent=id;
        }
    }
    for(i=0;i<n;i++)if(node[i].parent==-1)break;
    if(i==n)return -1;
    root = i;
    setDepth(node, root, 0);
    for(id=0;id<n;id++){
        printf("node %d: parent = %d, depth = %d, ",id,node[id].parent,node[id].depth);
        if(node[id].parent==-1)printf("root, ");
        else if(node[id].noc==0)printf("leaf, ");
        else printf("internal node, ");
        printf("[");
        for(j=0;j<node[id].noc;j++){
            printf("%d",node[id].child[j]);
            if(j<node[id].noc-1)printf(", ");
        }
        printf("]\n");
    }
    return 0;
}



Measured memory_bytes: 8428
import java.util.*;
import java.io.*;
import static java.lang.Math.*;

public class Main {
    public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int n = sc.nextInt();
		int m = sc.nextInt();
		long k = sc.nextLong();
		long[] a = new long[n];
		for(int i = 0; i < n; i++){
		    a[i] = sc.nextLong();
		}
		long[] b = new long[m];
		for(int i = 0; i < m; i++){
		    b[i] = sc.nextLong();
		}

		// 計算
		long result = 0;
		long[] suma = new long[n+1];
		for(int i = 0; i < n; i++){
		    suma[i+1] = suma[i] + a[i];
		}
		long[] sumb = new long[m+1];
		for(int i = 0; i < m; i++){
		    sumb[i+1] = sumb[i] + b[i];
		}
		
		for(int i = 0; i < suma.length; i++){
		    long tmp = k - suma[i];
		    if(tmp < 0) continue;
		    int index = upperBound(sumb, tmp);
		    result = max(result, i+max(index-1, 0));
		}

		// 出力
		System.out.println(result);
	}

	static int upperBound(long[] array, long n){
		int index = 0;
		int l = -1;
		int r = array.length;
		while(r-l > 1){
			int c = (r + l)/2;
			
			if(n < array[c]){
				r = c;
			}else{
				l = c;
			}
		}
		index = r;
		return index;
	}


	public static class Scanner {
		private BufferedReader br; private StringTokenizer tok;
		public Scanner(InputStream is) throws IOException { br = new BufferedReader(new InputStreamReader(is));}
		private void getLine() throws IOException { while(!hasNext()) tok = new StringTokenizer(br.readLine());}
		private boolean hasNext() { return tok != null && tok.hasMoreTokens();}
		public String next() throws IOException { getLine(); return tok.nextToken();}
		public int nextInt() throws IOException { return Integer.parseInt(next());}
		public long nextLong() throws IOException { return Long.parseLong(next());}
		public double nextDouble() throws IOException { return Double.parseDouble(next());}
	}
}



Measured memory_bytes: 67140
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) Rep(i, 0, n)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;
//const int mod = 998244353;

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

    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    int sum = 0;
    rep(i, n) sum += a[i];
    int cnt = 0;
    rep(i, n) if (4 * m * a[i] >= sum) cnt++;
    if (cnt >= m)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}


Measured memory_bytes: 256
#!/usr/bin/env python3


def solve(n, ss):
    if all(s % 10 == 0 for s in ss):
        return 0
    t = sum(ss)
    if t % 10 != 0:
        return t
    else:
        m = min(s for s in ss if s % 10 != 0)
        return t - m


def main():
    n = int(input())
    ss = [int(input()) for _ in range(n)]
    print(solve(n, ss))


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define for1(i, n) for(int i = 1; i <= (n);i++)
#define puts(x) cout << x << "\n"
constexpr int mod = 1000000007;
using namespace std;
signed main() {
	srand((unsigned)time(NULL));
	for1(i, 365)puts(rand() % 26 + 1);
	return 0;
}

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

ll x,y,ans=1;

int main() {
	scanf("%lld%lld",&x,&y);
	ll a=y;
	while(a/2>=x) {
		a/=2,ans++;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
K, A, B = map(int, input().split())
ans = 1 + K
ans_temp = 0
if 1 + A <= K:
    if A < B:
        K -= A - 1
        ans_temp = A
        ans_temp += (K//2) * (B-A)
        if K % 2 == 1:
            ans_temp += 1
print(max(ans_temp, ans))

Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <stack>
#include <vector>
#include <algorithm>
#include <cmath>
#include <climits>

using namespace std;

const double PI = 3.14159265358979;

long long SUM = 0;

void printArr(int a[], int len) {

	for (int i = 0; i < len; i++)
	{
		if (i == 0) cout << a[0];
		else cout << " " << a[i];
	}
	cout << endl;
}

long long merge_inv(int a[], int left, int mid, int right) {

	int Llen = mid - left;
	int Rlen = right - mid;
	int* L = new int[Llen + 1];
	int* R = new int[Rlen + 1];
	R[Rlen] = L[Llen] = INT_MAX;
	for (int i = 0; i < Llen; i++) {
		L[i] = a[left + i];
	}
	for (int i = 0; i < Rlen; i++) {
		R[i] = a[mid + i];
	}
	// 3			6
	// 1 3 5 X     2 4 6 7 8 9 X
	// 
	long long sum = 0;
	int ll = 0, rr = 0;
	for (int i = left; i < right; i++) {
		if (L[ll] < R[rr]) {
			a[i] = L[ll++];
		}
		else {	//L[ll] >= R[rr]
			a[i] = R[rr++];
			sum += Llen - ll;
		}
	}


	delete[] L;
	delete[] R;

	return sum;
}

void mergeSort_inv(int a[], int left, int right) {

	if (left + 1 < right) {
		int mid = (left + right) / 2;
		mergeSort_inv(a, left, mid);
		mergeSort_inv(a, mid, right);
		SUM += merge_inv(a, left, mid, right);
	}
}


int main() {

	int n; cin >> n;
	int* a = new int[n];
	for (int i = 0; i < n; i++)	{
		scanf("%d", &a[i]);
	}


	mergeSort_inv(a, 0, n);

	cout << SUM << endl;

	return 0;
}



Measured memory_bytes: 4456
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define LLINF 9223372036854775807
#define MOD ll(1e9+7)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr<<#x<<": "<<x<<endl


int main(){
    int a[3][3];
    for(int i = 0; i < 3; i++){
        for(int j = 0; j < 3; j++){
            cin >> a[i][j];
        }
    }
    ll n;
    cin >> n;

    for(int i = 0; i < n; i++){
        int b;
        cin >> b;
        for(int j = 0; j < 3; j++){
            for(int k = 0; k < 3; k++){
                if(a[j][k]==b){
                    a[j][k] = -1;
                }
            }
        }
    }

    for(int i = 0; i < 3; i++){
        if(a[i][0] == -1 && a[i][1] == -1 && a[i][2] == -1){
            cout << "Yes" << endl;
            return 0;
        }
        if(a[0][i] == -1 && a[1][i] == -1 && a[2][i] == -1){
            cout << "Yes" << endl;
            return 0;
        }
    }
    if(a[0][0] == -1 && a[1][1] == -1 && a[2][2] == -1){
        cout << "Yes" << endl;
        return 0;
    }

    if(a[0][2] == -1 && a[1][1] == -1 && a[2][0] == -1){
        cout << "Yes" << endl;
        return 0;
    }
    cout << "No" << endl;

    return 0;

}


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

#define REP(A, H) for(int A = 0; A < H; A++)
#define ALL(c) c.begin(), c.end()

char map[100];


int main(void) {

  map['A'] = 'T';  
  map['C'] = 'G';  
  map['G'] = 'C';  
  map['T'] = 'A';  

  std::string s; std::cin >> s;
  REP(i, s.size()) s[i] = map[s[i]];

  std::cout << s << std::endl;  

  return 0;
}

Measured memory_bytes: 256
import java.io.*;
  
class Main{
	public static void main(String[] args) throws IOException{
		
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int x = Integer.parseInt(br.readLine());
		StringBuilder sb = new StringBuilder();

		for(int i = 2; i < x+1; i++){
			String s = String.valueOf(i);
			if(i%3 == 0){
				sb.append(" " + i);
			}else {
				for (int k = 0; k < s.length(); k++){
                    			if (s.indexOf('3') != -1){
                        			sb.append(" " + i);
                        			break;
					}
				}
			}
		}
		System.out.println(sb.toString());
  	}
}

Measured memory_bytes: 24232
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;

public class Cell
{
    public int X { get; set; }
    public int Y { get; set; }
    public string CellType { get; set; }
    public int Step { get; set; }

    public static Cell[] GetCells(char[] row, int y)
    {
        var cells = Enumerable.Range(0, row.Length).Select(x => new Cell
        {
            X = x + 1,
            Y = y,
            CellType = Convert.ToString(row[x]),
            Step = -1,
        });
        return cells.ToArray();
    }

}


class Program
{
    public static long Read()
    {
        return long.Parse(Console.ReadLine());
    }

    public static long[] Reads()
    {
        return Console.ReadLine().Split().Select(long.Parse).ToArray();
    }

    public static void Main()
    {
        var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
        Console.SetOut(sw);

        var input = Reads();
        var a = input[0];
        var b = input[1];
        if (a > 2 * b)
            Console.WriteLine(a - 2 * b);
        else
            Console.WriteLine(0);

       


        


        Console.Out.Flush();
    }
}

Measured memory_bytes: 13396
import sys
sys.setrecursionlimit(100000)

def dfs(n,s,ans):
    if n == 10:
        return
    
    for i in range(10):

        tmp = s + str(i)
        if check(tmp):
            ans.append(int(tmp))
            dfs(n+1,tmp,ans)


def check(s):
    if abs(int(s[-1])-int(s[-2])) > 1:
        return False
    return True 

def main():
    K = int(input())
    ans = [1,2,3,4,5,6,7,8,9]
    for i in range(1,10):
        dfs(1,str(i),ans)
    ans.sort()
    print(ans[K-1])

    


if __name__ == "__main__":
    main()

Measured memory_bytes: 63836
#include <bits/stdc++.h>
#include <numeric>
#define M 1000000007
#define pb push_back
#define forz(i,s,n) for(lli i=s;i<n;i++)

#define fast_io                       \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);

typedef long long int lli;
//typedef pair<long long int, long long int> pll;
typedef unsigned long long int ull;
using namespace std;

lli recpow(lli x, lli n)
{
    if (n == 0)
        return 1;
    else if (n % 2 == 0) //n is even
        return recpow((x * x) % M, n / 2);
    else //n is odd
        return (x * recpow((x * x) % M, (n - 1) / 2)) % M;
}

bool sortbysec(const pair<int, int> &a,
               const pair<int, int> &b)
{
    return (a.second < b.second);
}

bool comp(pair<lli, lli> a, pair<lli, lli> b)
{
    if(a.first==b.first)
        return a.second<b.second;
    else
        return a.first<b.first;
}

void multiply(lli f[2][2], lli m[2][2])
{
    lli x = (f[0][0] % M * m[0][0] % M) % M + (f[0][1] % M * m[1][0] % M) % M;
    lli y = (f[0][0] % M * m[0][1] % M) % M + (f[0][1] % M * m[1][1] % M) % M;
    lli z = (f[1][0] % M * m[0][0] % M) % M + (f[1][1] % M * m[1][0] % M) % M;
    lli w = (f[1][0] % M * m[0][1] % M) % M + (f[1][1] % M * m[1][1] % M) % M;
    f[0][0] = x % M;
    f[0][1] = y % M;
    f[1][0] = z % M;
    f[1][1] = w % M;
}

lli u[2][2] = {{1, 1}, {1, 0}};

void power(lli f[2][2], lli n)
{
    if (n == 0 || n == 1)
        return;
    power(f, n / 2);
    multiply(f, f);
    if (n % 2 != 0)
        multiply(f, u);
}

lli fib(lli n)
{
    if (n == 1)
        return 2;
    else if (n == 2)
        return 3;
    else
    {
        lli h[2][2] = {{1, 1}, {1, 0}};
        power(h, n + 1);
        return h[0][0];
    }
}

//code begins here
int main()
{
    fast_io;
    lli n;
    cin>>n;
    lli dp[3]={0}, c[3];
    forz(i,0,n)
    {
        lli ndp[3]={0};
        forz(j,0,3)
        cin>>c[j];
        forz(j,0,3)
        forz(k,0,3)
        {
            if(j!=k)
            ndp[j]=max(ndp[j], dp[k]+c[j]);
        }
        forz(j, 0, 3)
        dp[j] = ndp[j];
    }
    cout<<max(max(dp[0], dp[1]),dp[2])<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i=0;i < (int)(n);i++)

int main(){
    int a,b,c;
    cin >> a >> b >> c;
    cout << min(b/a,c) << endl;
    return 0;
}

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

int main(){
    int n, ok = 1; cin >> n;
    for(int i=0;i<n;i++){
        int a; cin >> a;
        if(a % 2) ok = 0;
    }

    if(ok) cout << "second" << endl;
    else cout << "first" << endl;
    return 0;
}

Measured memory_bytes: 256
while 1:
    n=int(input())
    if n==0:
        break
    a=0
    b=0
    for i in range(n):
        x,y=map(int,input().split())
        if x > y:
            a+=(x+y)
        elif x < y:
            b+=(x+y)
        else:
            a+=x
            b+=x
    print(a,b)


Measured memory_bytes: 5608
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import math


def main():
    N = int(input())
    result = 0
    for _ in range(N):
        l, r = map(int, input().split())
        result += (r - l) + 1
    print(result)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int main(void) {
 int n,k;
 string s;
 cin >> n >> k >> s;
    for (int i = 0; i < s.length(); ++i) {
        if(i==k-1){
            cout << (char)(s[i]+32);
        } else {
            cout << s[i];
        }
    }
    cout << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <stack>
#include <math.h>
#include <map>
#define Z class
#define ln cout<<'\n'
#define ll long long
#define rep(i, n) for(int i = 0; i < (n); ++i)
//ASCII a=97, A=65
// int H[N]; rep(i,N) scanf("%d", &H[i]);
// int max_x = *std::max_element(x.begin(), x.end());
// int min_y = *std::min_element(y.begin(), y.end());
using namespace std;
template<class T> inline bool chmax(T& a, T b){ if(a < b) { a=b; return 1; }return 0;}
template<class T> inline bool chmin(T& a, T b){ if(a > b) { a=b; return 1; }return 0;}
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}

int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
const long long INF = 1LL << 60;

int main(){
    long A; cin>>A;
    long B[A]; rep(i,A) cin >> B[i];
    sort(B,B+A);
    pr(B[A-1]-B[0]);
    
}



Measured memory_bytes: 256
#include <iostream>

int main()
{
  int a, b;
  int count = 0;

  std::cin >> a >> b;
  
  for (int x = a; x <= b; ++x) {
    int a1 = x%10;
    int a2 = (x/10)%10;
    int a4 = (x/1000)%10;
    int a5 = x/10000;

    if ( a1 == a5 && a2 == a4) {
      count++;
    }
  }

  std::cout << count << std::endl;
}


Measured memory_bytes: 256
import math
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 9)

def main():
    n = int(input())
    mod = 10 ** 9 + 7
    h = {}
    zero = 0
    for i in range(n):
        a, b = map(int, input().split())
        if a == 0 and b == 0:
            zero += 1
            continue
        m = (0, 0)
        if b == 0:
            m = (1, 0)
        elif b > 0:
            g = math.gcd(a, b)
            m = (a // g, b // g)
        else:
            g = math.gcd(a, b)
            m = (-1 * (a // g), -1 * (b // g))
        if m not in h:
            h[m] = set()
        h[m].add(i)
    h2 = {}
    for m in h:
        mi1 = (-1 * m[1], m[0])
        if mi1 in h and mi1 not in h2:
            h2[m] = mi1
        mi2 = (m[1], -1 * m[0])
        if mi2 in h and mi2 not in h2:
            h2[m] = mi2
    ans = 1
    left = n - zero
    for k, v in h2.items():
        s1 = len(h[k])
        s2 = len(h[v])
        # print(s1, s2)
        r = (pow(2, s1 + s2, mod) - (pow(2, s1, mod) - 1) * (pow(2, s2, mod) - 1)) % mod
        ans *= r
        ans %= mod
        left -= (s1 + s2)
    ans *= pow(2, left, mod)
    ans -= 1
    ans += zero
    print(ans % mod)

if __name__ == '__main__':
    main()


Measured memory_bytes: 98488
# selectメソッドは、条件に合う要素を探して集めます
n, a, b = gets.strip.split.map(&:to_i)
# 各桁の和を求める(位がなくなるまで)
def digit_sum n
    sum = 0
    while n > 0 do
        sum += n % 10
        n /= 10
    end
    sum
end

ans = (1..n)
        .map { |i| [i, digit_sum(i)] }
        .select { |d| a <= d[1] && d[1] <= b }
        .inject(0) { |sum, d| sum + d[0] }

puts ans

Measured memory_bytes: 2172
#[allow(unused_imports)]
use std::cmp::{min,max};
use std::collections::BinaryHeap;

struct DisjointSet {
    ps: Vec<Option<usize>>,
    ns: Vec<i64>,
}

impl DisjointSet {
    #[allow(dead_code)]
    fn new(n: usize) -> DisjointSet {
        DisjointSet { ps: vec![None; n], ns: vec![1; n] }
    }

    #[allow(dead_code)]
    fn unite(&mut self, x: usize, y: usize) {
        let nx = self.find(x);
        let ny = self.find(y);
        if nx == ny {
            return;
        }
        let (a,b) = if self.ns[nx] < self.ns[ny] { (nx,ny) } else { (ny,nx) };
        self.ps[a] = Some(b);
        self.ns[b] += self.ns[a];
    }

    #[allow(dead_code)]
    fn find(&mut self, x: usize) -> usize {
        match self.ps[x] {
            Some(y) => {
                let res = self.find(y);
                self.ps[x] = Some(res);
                res
            },
            None => {
                x
            },
        }
    }

    #[allow(dead_code)]
    fn same(&mut self, x: usize, y: usize) -> bool {
        self.find(x) == self.find(y)
    }
}

fn main() {
    let (v,e) = {
        let xs = read_vec_i64();
        (xs[0] as usize, xs[1] as usize)
    };
    let edges = {
        let mut res = vec![];
        for _ in 0..e {
            let ys = read_vec_i64();
            let (s,t,w) = (ys[0] as usize, ys[1] as usize, ys[2]);
            res.push((s,t,w));
        }
        res
    };
    let mut ds = DisjointSet::new(v);
    let mut heap = BinaryHeap::new();
    for (i,&(_,_,w)) in edges.iter().enumerate() {
        heap.push((-w,i));
    }
    let mut res = 0;
    while let Some((_,i)) = heap.pop() {
        let (s,t,w) = edges[i];
        if ! ds.same(s,t) {
            ds.unite(s,t);
            res += w;
        }
    }
    println!("{}", res);
}

#[allow(dead_code)]
fn read_line() -> String {
    let mut ret = String::new();
    std::io::stdin().read_line(&mut ret).ok();
    ret.pop();
    return ret;
}

#[allow(dead_code)]
fn read_i64() -> i64 {
    let ss = read_line();
    return ss.parse::<i64>().unwrap();
}

#[allow(dead_code)]
fn read_vec_i64() -> Vec<i64> {
    let mut res = vec![];
    let ss = read_line();
    for ts in ss.split_whitespace() {
        let x = ts.parse::<i64>().unwrap();
        res.push(x);
    }
    return res;
}



Measured memory_bytes: 12080