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

int main() {
  char c;
  cin >> c;
  if(c == 'a'){
      cout << "vowel" << endl;
  }
  else if(c == 'i'){
      cout << "vowel" << endl;
  }
  else if(c == 'u'){
      cout << "vowel" << endl;
  }
  else if(c == 'e'){
      cout << "vowel" << endl;
  }
  else if(c == 'o'){
      cout << "vowel" << endl;
  }
  else {
      cout << "consonant" << endl;
  }
}

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

int max(int a, int b) {
    if (a > b)
        return a;
    else
        return b;
}
int main()
{
    int n, d, x, p[11][11], T[11][100002];

    cin >> n >> d >> x;
    for (int i = 0; i<d; i++) {
        for (int j = 0; j<n; j++)cin >> p[i][j];
    }

    for (int k = 1; k<d; k++) {
        for (int i = 0; i <= x; i++)T[0][i] = 0;
        for (int i = 0; i<n; i++)T[i][0] = 0;

        for (int i = 0; i<n; i++) {
            for (int j = 0; j <= x; j++) {
                if (j<p[k - 1][i]) {
                    T[i + 1][j] = T[i][j];
                }
                else {
                    T[i + 1][j] = max(T[i][j], T[i + 1][j - p[k - 1][i]] + p[k][i] - p[k - 1][i]);
                }
            }
        }
        x = max(T[n][x] + x, x);
    }
    cout << x << endl;
    return 0;
}

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
const ll mod = 1000000007;

ll beki(ll a, ll b) {
    if(b == 0) return 1;
    ll ans = beki(a, b / 2);
    ans = ans * ans % mod;
    if(b % 2 == 1) {
        ans = ans * a % mod;
    }
    return ans;
}

int main() {
    //cout.precision(10);
    ll n;
    map<ll, ll> mp;
    cin >> n;
    ll ans = beki(2, n / 2);
    for(int i = 1; i <= n; i++) {
        ll in;
        cin >> in;
        mp[in]++;
    }
    if(n % 2 == 1) {
        if(mp[0] != 1) {
            ans = 0;
        }
    }
    for(ll i = n - 1; i >= 1; i -= 2) {
        if(mp[i] != 2) ans = 0;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 5376
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <utility>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
using namespace std;
#define rep(i,n) for (int i=0; i<n;++i)
#define rep_down(i,n) for (int i=n-1; i>=0;--i)
int H, W;
bool b[2005][2005];
int L[2005][2005], R[2005][2005], D[2005][2005], U[2005][2005];  

int main(){
  cin.sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  
  cin >> H >> W;

  rep(i,H){
    string s;
    cin >> s;
    rep(j,W){
      if (s[j] == '.') {
         b[i][j] = true;
      }
    }
  }
   
  rep(i,H) {
    rep(j,W) {
      if (!b[i][j]) continue;
      if (j==0){
        L[i][j] = 1;
      }else{
        L[i][j] = L[i][j-1] + 1;
      }
    }
    rep_down(j, W){
      if (!b[i][j]) continue;
      if (j==W){
        R[i][j] = 1;
      }else{
        R[i][j] = R[i][j+1] + 1;
      }
    }
  }


  rep(j,W){
    rep(i,H) {
      if (!b[i][j]) continue;
      if (i==0){
        D[i][j] = 1;
      }else{
        D[i][j] = D[i-1][j] + 1;
      }
    }
    rep_down(i, H){
      if (!b[i][j]) continue;
      if (i==H){
        U[i][j] = 1;
      }else{
        U[i][j] = U[i+1][j] + 1;
      }
    }
  }

  int ans = 0;
  rep(i,H){
    rep(j,W){
      if (!b[i][j]) continue;
      ans = max(ans, L[i][j]+R[i][j]+D[i][j]+U[i][j] -3);
    }
  }

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

Measured memory_bytes: 66944
N = int(input())
A = list(map(int,input().split()))
import numpy as np
num_list = np.zeros(N+1)
for A_ in A:
    num_list[A_] += 1

all_pattern = 0
for number_ in num_list:
    all_pattern += number_ * (number_ - 1) / 2

for A_ in A:
    print(int(all_pattern - (num_list[A_] - 1)))

Measured memory_bytes: 25644
#include <iostream>
#include <vector>
#include <algorithm>
#include <complex>

using namespace std;

typedef complex<double> Point;

struct Segment{ Point p1, p2; };

class C{
public:
  Point p;
  int o, l;
  double d;
  C(){}
  C(Point p, int o, int l, double d): p(p), o(o), l(l), d(d) {}
  bool operator < (const C& s) const {
    return d < s.d;
  }
};

vector<C> vec;
Point A, B;
int n, T;

const double EPS = 1e-10;

double dot(Point a, Point b){
  return real(conj(a) * b);
}

double cross(Point a, Point b){
  return imag(conj(a) * b);
}

static const int COUNTER_CLOCKWISE = 1;
static const int CLOCKWISE = -1;
static const int ONLINE_BACK = 2;
static const int ONLINE_FRONT = -2;
static const int ON_SEGMENT = 0;

int ccw(Point p0, Point p1, Point p2){
  Point a = p1 - p0;
  Point b = p2 - p0;
  if(cross(a, b) > EPS) return COUNTER_CLOCKWISE;
  if(cross(a, b) < -EPS) return CLOCKWISE;
  if(dot(a, b) < -EPS) return ONLINE_BACK;
  if(norm(a) < norm(b)) return ONLINE_FRONT;
  return ON_SEGMENT;
}

bool isIntersect(Point p1, Point p2, Point p3, Point p4){
  return (ccw(p1, p2, p3) * ccw(p1, p2, p4) <= 0 &&
	  ccw(p3, p4, p1) * ccw(p3, p4, p2) <= 0);
}

bool isIntersect(Segment s1, Segment s2){
  return isIntersect(s1.p1, s1.p2, s2.p1, s2.p2);
}

Point getCrossPoint(Segment s1, Segment s2){
  Point base = s2.p2 - s2.p1;
  double d1 = abs(cross(base, s1.p1 - s2.p1));
  double d2 = abs(cross(base, s1.p2 - s2.p1));
  double t = d1 / (d1 + d2);
  return s1.p1 + (s1.p2 - s1.p1) * t;
}



main(){
  cin >> T;
  while(T--){
    vec.clear();
    cin >> A.real() >> A.imag() >> B.real() >> B.imag();
    cin >> n;
    for(int i=0;i<n;i++){
      Point s, t;
      int o, l;
      cin >> s.real() >> s.imag() >> t.real() >> t.imag() >> o >> l;
      Segment s1 = (Segment){A, B};
      Segment s2 = (Segment){s, t};
      if(isIntersect(s1, s2)){
        Point p = getCrossPoint(s1, s2);
        vec.push_back(C(p, o, l, abs(p-A)));
      }
    }
    sort(vec.begin(), vec.end());
    int cnt = 0;
    int p = (vec[0].o == vec[0].l ? 1 : 0);
    for(int i=0;i<vec.size();i++){
      int t = (vec[i].o == vec[i].l ? 1 : 0);
      if(p != t) cnt++;
      p = t;
    }
    cout << cnt << endl;
  }
}

Measured memory_bytes: 1260
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
const int MAX_N = 100000;
ll fact[MAX_N + 1];
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll ans;
    fact[0] = 0;
    fact[1] = 1;
    ll fs = 1;
    for (int i = 2; i < MAX_N + 1; i++){
        fs = (fs*i) % MOD;
        fact[i] = (fact[i-1] + fs) % MOD;
    }
    while (1){
        int N, R;
        cin >> N;
        if (N == 0) break;
        vector<int> word(N);
        for (int i = 0; i < N; i++) word[i] = i;
        word.push_back(0);
        ans = 0;
        cin >> R;
        vector<int> s(2*R+2, 0);
        s[2 * R + 1] = N;
        for (int i = 0; i < R; i++){
            cin >> s[i] >> s[i+R];
            s[i]--; s[i+R]--;
            s.push_back(s[i] + 1);
            s.push_back(s[i+R] + 1);
            swap(word[s[i]], word[s[i+R]]);
        }
        sort(s.begin(), s.end());
        s.erase(unique(s.begin(), s.end()), s.end());
        for (int i = 0, R = s.size() - 1; i < R; i++){
            ans =(ans + word[s[i]] * (fact[N - s[i] - 1] - fact[N - s[i+1] - 1] + MOD)) % MOD;
            int dif = s[i+1] - s[i];
            for (int j = i + 1; j < R; j++){
                word[s[j]] -= (word[s[j]] > word[s[i]] ? dif : 0);
            }
        }
        cout << ans % MOD << endl;
    }
    return 0;
}

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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 深さ優先探索
vector<bool> seen;
vector<ll> color;

void dfs(const Graph &G, ll v, ll c) {
    seen[v] = true;
    color[v] = c;
    for (auto next_v : G[v]) { 
        if (seen[next_v]) continue;
        dfs(G, next_v, c); // 再帰的に探索
    }
}

int main()
{
    cout << fixed << setprecision(15);
    ll N, M;
    cin >> N >> M;

    // グラフ入力受取
    Graph G(N);

    REP(i, M){
        ll x, y, z;
        cin >> x >> y >> z;

        G[x-1].push_back(y-1);
        G[y-1].push_back(x-1);
    }

    seen.assign(N, false);
    color.assign(N, -1);

    REP(i, N){
        if(seen[i] == false) dfs(G, i, i);
    }

    map<ll,ll> MAP;

    REP(i, N){
        MAP[color[i]];
        // cout << color[i] << endl;
    }

    cout << MAP.size() << endl;

    return 0;
}

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

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
a = LI()
c = list(Counter(a).items())
c.sort(key = itemgetter(1),reverse=1)
if c[0][1] > 1:
    print('NO')
else:
    print('YES')

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

#define forn(i,n) for(int i=0;i<n;i++)
#define pb push_back
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vii;

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);	
        int n;cin>>n;
        int dp[100001]={0};
        vi a(n+1);
        for(int i=1;i<n+1;i++)cin>>a[i];
        dp[1]=0;
        dp[2]=abs(a[2]-a[1]);
        for(int i=3;i<n+1;i++)
            dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));
        cout<<dp[n]<<endl;
}


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

string S1,T;

bool corr(int n) //S1のn文字目からの部分がTと一致する可能性があるか
{
	for (int i = 0; i < T.size(); ++i)
	{
		if ((S1[n+i] != '?')&&(S1[n+i] != T[i]))
		{
			return false;
		}
	}

	return true;
}

int main()
{
	cin >> S1 >> T;

	string ans;
	bool flag = false; //答えが存在するかどうか

	string S;

	for (int i = 0; i < S1.size() - T.size() + 1; ++i)
	{

		//cout << "a";
		S = S1;

		if (corr(i))
		{
			//cout << "b";
			for (int j = 0; j < T.size(); ++j)
			{
				S[i+j] = T[j];
			}

			for (int j = 0; j < S.size(); ++j)
			{
				if (S[j] == '?')
				{
					S[j] = 'a';
				}
			}

			//cout << S << endl;

			if (flag)
			{
				//cout << "c";
				ans = min(ans,S);
			}
			else
			{
				//cout << "d";
				ans = S;
				flag = true;
			}
		}
	}

	if (flag) 
	{
		cout << ans << endl;
	}
	else
	{
		cout << "UNRESTORABLE" << endl;
	}
	return 0;
}

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

int main(void)
{
    int N,X,i;
    int value,count = 1;
    int sum = 0;

    scanf("%d %d", &N,&X);

    for(i = 0; i < N; i++)
    {
        scanf("%d", &value);
        sum = sum + value;

        if (sum <= X)
            count++;
    }
    printf("%d\n", count);

    return 0;
}


Measured memory_bytes: 128
//#include "pch.h"
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <iomanip>
#include <math.h> 
#include <stack>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <tuple>
#include <cctype>
#include <ctype.h>
#include <set>
#include <sstream>
#include <time.h>
#include <numeric>
using namespace std;
//#define int long long
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define fi first
#define se second
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
#define l1 list[index]
#define l2 list[index - 1]
#define l3 list[index + 1]
#define iif(i,j) ((i<0 && j<0) || (i>0 && j>0)) ? true : false 
typedef long long ll;
typedef pair<int, int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
typedef pair<pint, int> P1;
typedef pair<int, pint> P2;
typedef pair<pint, pint> PP;
static const ll maxLL = (ll)1 << 62;
const ll MOD = 1000000007;
const ll INF = 1e18;
const double PI = 3.14159265359;
int ca[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };

int x;
bool IsPrime(int num)
{
	if (num < 2) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			// 素数ではない
			return false;
		}
	}

	// 素数である
	return true;
}

signed main() {

	cin >> x;
	int num;

	for (int i = x; ; i++) {
		if (IsPrime(i) == true) {
			num = i;
			break;
		}
	}

	cout << num << endl;

	return 0;
}

Measured memory_bytes: 256
PROGRAM piyo
      IMPLICIT NONE
      integer(16) :: a,b,c,k
      integer(16) :: rem,ans
      
      read*,a,b,c,k
      
      rem = k
      ans = 0
      
      if( rem>a )then
        ans = ans + a*1
        rem = rem - a
      else
        ans = ans + rem*1
        print*,ans
        stop
      end if
      
      if( rem>b )then
        ans = ans + b*0
        rem = rem - b
      else
        ans = ans + rem*0
        print*,ans
        stop
      end if
      
      if( rem>c )then
        ans = ans + c*(-1)
        rem = rem - c
      else
        ans = ans + rem*(-1)
        print*,ans
        stop
      end if
      
      print*,ans
      
      
      
      END PROGRAM

Measured memory_bytes: 2800
#include<bits/stdc++.h>
using namespace std;
int main(){
  string S,T;
  cin  >> S >> T ;
  /*部分列の抜き出し
  S = S.substr(2,3) <=2番目の要素から3つ抜き出す
  */
  int i = 0;
  while(i<S.size()){
  if(S == T){
    cout << "Yes" <<endl;
    return 0;
  }
  else{
    S = S.at(S.size()-1) + S.substr(0,S.size()-1);
  }
  i++;
}
  cout << "No" << endl;

}

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

int main(){
  int N;
  int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, -1, 0, 1};
  while(true){
    cin >> N;
    if(N == 0)
      break;

    vector< pair<int, int> > v(N);
    v[0] = pair<int, int>(0, 0);
    int xmin = 0, xmax = 0, ymin = 0, ymax = 0;
    int n, d;
    for(int i=1; i<=N-1; i++){
      cin >> n >> d;
      v[i] = pair<int, int>(v[n].first + dx[d], v[n].second + dy[d]);
      xmin = min(xmin, v[n].first + dx[d]);
      xmax = max(xmax, v[n].first + dx[d]);
      ymin = min(ymin, v[n].second + dy[d]);
      ymax = max(ymax, v[n].second + dy[d]);
    }
    cout << xmax - xmin + 1 << ' ' << ymax - ymin + 1 << endl;
  }
  
  return 0;
}

Measured memory_bytes: 3024
# import bisect
from collections import Counter, deque
# import copy
# from heapq import heappush, heappop, heapify
# from fractions import gcd
# import itertools
# from operator import attrgetter, itemgetter
# import math

import sys

# import numpy as np

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n = input()
    p = int(input())
    l = len(n)

    n_0 = int(str(n)[0])

    dp = [[[0] * 2 for _ in range(p + 2)] for __ in range(l)]
    dp[0][0][0] = 0
    dp[0][0][1] = 1
    dp[0][1][0] = 1
    dp[0][1][1] = (n_0 - 1)

    for i in range(l - 1):
        a = int(n[i + 1])
        if a != 0:
            for j in range(p + 1):
                dp[i + 1][j + 1][0] += dp[i][j][0]
                dp[i + 1][j + 1][1] += 9 * dp[i][j][1] + (a - 1) * dp[i][j][0]
                dp[i + 1][j][1] += dp[i][j][0] + dp[i][j][1]
        else:
            for j in range(p + 1):
                dp[i + 1][j + 1][1] += 9 * dp[i][j][1]
                dp[i + 1][j][0] += dp[i][j][0]
                dp[i + 1][j][1] += dp[i][j][1]

    print(dp[l - 1][p][0] + dp[l - 1][p][1])


if __name__ == '__main__':
    main()


Measured memory_bytes: 3316
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)

N, K = map(int, input().split())
WD = list(list(map(int, input().split())) for _ in range(N))

l = 0
r = 2 * 10 ** 18 + 100
while (r - l) > 1:
    pos = (r + l) // 2

    cnt = 0
    for w, d in WD:
        if pos < w:
            continue
        cnt += 1 + (pos - w) // d
    if cnt >= K:
        r = pos
    else:
        l = pos

print(r)

Measured memory_bytes: 54748
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i = 0; i < (ll)(n); i++)
#define repi(i,a,b) for(ll i = (ll)(a); i < (ll)(b); i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF = 1LL << 60;
int c[10][10];
int main(){
    int n; cin >> n;    
    for(int i=1; i<=n; i++){
        string si = to_string(i);
        int id = si.size();
        int x = si[0]-'0'; //一番下の桁
        int y = si[id-1]-'0'; //一番上の桁
        c[y][x]++;
    }
    int ans = 0;
    rep(i,10)rep(j,10){
        //cout << "i:" << i << ",j:" << j << ",c[i][j]:" << c[i][j] << ",c[j][i]" << c[j][i] << endl;
        ans+=c[i][j]*c[j][i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;
#[allow(unused_imports)]
use std::collections::*;

struct Scanner<R: Read> {
    reader: R,
}

#[allow(dead_code)]
impl<R: Read> Scanner<R> {
    fn new(reader: R) -> Scanner<R> {
        Scanner { reader: reader }
    }

    fn safe_read<T: FromStr>(&mut self) -> Option<T> {
        let token = self.reader.by_ref().bytes().map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        if token.is_empty() {
            None
        } else {
            token.parse::<T>().ok()
        }
    }

    fn readu32(&mut self) -> u32 {
        self.reader.by_ref().bytes().map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .fold(0, |acc, x| acc*10 + (x as u8 - b'0') as u32)
    }

    fn read<T: FromStr>(&mut self) -> T {
        if let Some(s) = self.safe_read() {
            s
        } else {
            writeln!(std::io::stderr(), "Terminated with EOF").unwrap();
            std::process::exit(0);
        }
    }

    fn vec<T: FromStr>(&mut self, len: usize) -> Vec<T> {
        (0..len).map(|_| self.read()).collect()
    }

    fn mat<T: FromStr>(&mut self, row: usize, col: usize) -> Vec<Vec<T>> {
        (0..row).map(|_| self.vec(col)).collect()
    }
}

trait Joinable {
    fn join(self, sep: &str) -> String;
}

impl<U: ToString, T: Iterator<Item=U>> Joinable for T {
    fn join(self, sep: &str) -> String {
        self.map(|x| x.to_string()).collect::<Vec<_>>().join(sep)
    }
}

fn main() {
    std::thread::Builder::new()
        .stack_size(104_857_600)
        .spawn(solve)
        .unwrap()
        .join()
        .unwrap();
}

fn insertion_sort(a: &mut Vec<u32>, g: usize) -> usize {
    let mut cnt = 0;
    let n = a.len();
    for i in g..n {
        let v = a[i];
        let mut j = i;
        while j >= g && a[j-g] > v {
            a[j] = a[j-g];
            cnt += 1;
            j -= g;
        }
        a[j] = v;
    }
    cnt
}

fn shell_sort(a: &mut Vec<u32>, g: &[usize]) -> usize {
    let mut cnt = 0;
    for &i in g.iter() {
        cnt += insertion_sort(a, i);
    }
    cnt
}

fn solve() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);
    let n = sc.read();
    let mut a: Vec<_> = (0..n).map(|_| sc.readu32()).collect();

    let g = {
        let mut g = vec![];
        let mut x = 1 as usize;
        while x <= n {
            g.push(x);
            x = x*3 + 1;
        }
        g.reverse();
        g
    };

    let cnt = shell_sort(&mut a, &g[..]);
    let stdout = stdout();
    let mut stdout = stdout.lock();

    writeln!(&mut stdout, "{}", g.len()).unwrap();
    for x in g.iter() {
        writeln!(&mut stdout, "{}", x).unwrap();
    }
    writeln!(&mut stdout, "{}", cnt).unwrap();
    for x in a.iter() {
        writeln!(&mut stdout, "{}", x).unwrap();
    }
}



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


int main(){
    int k, s;
    int cnt = 0;

    cin >> k >> s;
    
    for(int x = 0; x <= k; x++){
        for(int y = 0; y <= k; y++){
            int z = s - x - y;
            if(0 <= z && z <= k) cnt++;
        }
    }

    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>

using namespace std;

#define REP(i,n) for(int i=0;i<int(n);i++)
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
typedef long long ll;
typedef pair<int,int> P;

int t[15][15];
int a[10010][10];

void ed(){

	for(int i=0;i<10000;i++){
		int c=i;
		for(int j=0;j<4;j++){
			a[i][4-j]=c%10;
			c/=10;
		}
	}

}

int cd(int a,int b,int c,int d){
	int x;
	x=t[0][a];
	x=t[x][b];
	x=t[x][c];
	x=t[x][d];
	return x;
}

int check(int a,int b,int c,int d,int e){
	int x;
	x=t[0][a];
	x=t[x][b];
	x=t[x][c];
	x=t[x][d];
	x=t[x][e];
	return x;
}

int main(void){
	int i,j,k;

	cin.tie(0);
	ios_base::sync_with_stdio(false);

	for(i=0;i<10;i++) for(j=0;j<10;j++) cin >> t[i][j];

	ed();
	for(i=0;i<10000;i++) a[i][5]=cd(a[i][1],a[i][2],a[i][3],a[i][4]);

	int ans=0;
	for(i=0;i<10000;i++){


		bool f=true;
			for(k=0;k<10;k++){
				if(k!=a[i][1]){
					int b=check(k,a[i][2],a[i][3],a[i][4],a[i][5]);
					if(b==0){
						f=false; break;
					}
				}
			}
			if(!f){
				ans++; continue;
			}


			for(k=0;k<10;k++){
				if(k!=a[i][2]){
					int b=check(a[i][1],k,a[i][3],a[i][4],a[i][5]);
					if(b==0){
						f=false; break;
					}
				}
			}
			if(!f){
				ans++; continue;
			}

			for(k=0;k<10;k++){
				if(k!=a[i][3]){
					int b=check(a[i][1],a[i][2],k,a[i][4],a[i][5]);
					if(b==0){
						f=false; break;
					}
				}
			}
			if(!f){
				ans++; continue;
			}

			for(k=0;k<10;k++){
				if(k!=a[i][4]){
					int b=check(a[i][1],a[i][2],a[i][3],k,a[i][5]);
					if(b==0){
						f=false; break;
					}
				}
			}
			if(!f){
				ans++; continue;
			}

			for(k=0;k<10;k++){
				if(k!=a[i][5]){
					int b=check(a[i][1],a[i][2],a[i][3],a[i][4],k);
					if(b==0){
						f=false; break;
					}
				}
			}
			if(!f){
				ans++; continue;
			}

			for(j=1;j<=4;j++){
				if(a[i][j]!=a[i][j+1]){
					swap(a[i][j],a[i][j+1]);
					int b=check(a[i][1],a[i][2],a[i][3],a[i][4],a[i][5]);
					swap(a[i][j],a[i][j+1]);
					if(b==0){
						f=false; break;
					}
				}
			}

			if(!f){
				ans++; continue;
			}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3604
#include<stdio.h>
 
int main(){
  long long n,ans=1;
  scanf("%lld",&n);
  long long arr[n+5],maks=1000000000000000000;
  for(long long i=1;i<=n;i++){
      scanf("%lld",&arr[i]);}
  
  for(int i=1;i<=n;i++){
    if(arr[i]==0){
        printf("0");
        return 0;
    }
  }
  
  for(long long i=1;i<=n;i++){
    if(maks/ans<arr[i]){
        printf("-1");
        return 0;
    }
    
    ans*=arr[i];
  }
  
  printf("%lld",ans);
}

Measured memory_bytes: 2452
#include<iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <map>
#include <bitset>
#include <stack>
#include <queue>
#include <fstream>
#include <functional>

using namespace std;
using ll = long long;

#define all(x) (x).begin(),(x).end()
#define PRI(n) cout << n << " "<<endl;
#define PRI2(n, m) cout << n << " " << m << " "<<endl;

#define REP(i, n)  for(int i = 0; i < (int)n; ++i)
#define FOR(i, t, n)  for(int i = t; i <= (int)n; ++i)

const char alphabet[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r',
                           's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
const ll MOD = 1e9 + 7;

struct edge;
struct UnionFind;

bool isPrime(ll x);

ll GCD(ll a, ll b);

ll LCM(ll a, ll b);

ll nCr(int n, int r);


struct UnionFind {
    vector<int> par;
    vector<int> rank;

    UnionFind(int N) {
        for (int i = 0; i < N; ++i) {
            par.push_back(i);
            rank.push_back(0);
        }
    }

    int find(int x) {
        if (par[x] == 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 (rank[x] < rank[y])par[x] = y;
        else {
            par[y] = x;
            if (rank[x] == rank[y])rank[x]++;
        }
    }

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

int M, N;
int F[100][10];
int P[100][10];
int A[100010];

int main() {
    cin >> N;
    ll ans = 0;
    REP(i, N) {
        int a;
        cin >> a;
        if (a > 1e5)ans++;
        else A[a - 1]++;
    }
    REP(i, 1e5) {
        if (A[i] == i + 1)continue;
        if (A[i] < i + 1)ans += A[i];
        else ans += abs(i + 1 - A[i]);
    }
    PRI(ans)
    return 0;
}

struct edge {
    int to, cost;
    bool flag = false;
};

bool isPrime(ll x) {
    if (x == 0)return 0;
    if (x == 1)return 0;
    if (x == 2)return 1;
    if (x % 2 == 0)return 0;
    FOR(i, 3, x - 1) {
        if (x % i == 0)return 0;
    }
    return 1;
}

ll GCD(ll a, ll b) {
    if (b == 0)return a;
    return GCD(b, a % b);
}

ll LCM(ll a, ll b) {
    ll gcd = GCD(a, b);
    return a / gcd * b;
}

ll nCr(int n, int r) {
    vector<ll> C(r + 1);
    C[0] = 1;
    FOR(i, 1, n) for (int j = min(i, r); j < 1; --j)C[j] = (C[j] + C[j - 1]) % MOD;
    return C[r];
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		
		long sum = 0;
		
		for(int i=0; i<100; i++){
			sum=sum+a;
			if(sum%b==c){
				System.out.println("YES");
				return;
			}
		}
		System.out.println("NO");
	}
}

Measured memory_bytes: 21844
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1335
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <queue>
using ll = long long;
using namespace std;

int const MOD = 1e9 + 7;

int f(int n, int k)
{
    if (n == 1)
        return 0;
    return (f(n - 1, k) + k) % n;
}
int main(void)
{
    int n, k, m;
    while (cin >> n >> k >> m, n || m || k)
    {
        cout << (f(n - 1, k) + m) % n + 1 << endl;
    }
    return 0;
}


Measured memory_bytes: 3400
n = int(input())

def sieve(n):
    is_prime = [True for _ in range(n+1)]
    is_prime[0] = False

    for i in range(2, n+1):
        if is_prime[i-1]:
            j = 2 * i
            while j <= n:
                is_prime[j-1] = False
                j += i
    table = [ i for i in range(1, n+1) if is_prime[i-1]]
    return table
  
table = sieve(55555)  
print(*[t for t in table if t%5==1][:n])

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

using namespace std;

int main(void) {
  double A, B;
  double H, M;
  double h_th, m_th;

  cin >> A >> B >> H >> M;
  m_th = M*M_PI/30.0;
  h_th = (H*60+M)*M_PI/360.0;

  double xl = abs(A*cos(h_th) - B*cos(m_th));
  double yl = abs(A*sin(h_th) - B*sin(m_th));
  double ans = sqrt(xl*xl+yl*yl);

  cout << std::fixed << std::setprecision(15) << ans << endl;

  return 0;
}

Measured memory_bytes: 4152
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<vector>
#include<map>
using namespace std;
typedef long long ll;
int main() {
  int j;
  string s,t;
  cin >> s >> t;
  for(int i=s.size()-t.size()+1; i>=0; i--) {
    for(j=0; j<t.size(); j++) {
      if(s[i+j]!='?'&&s[i+j]!=t[j]) {
        break;
      }
    }
    if(j==t.size()) {
      for(int j=0; j<t.size(); j++) {
        s[i+j]=t[j];
      }
      for(int j=0; j<s.size(); j++) {
        if(s[j]=='?') {
          s[j]='a';
        }
      }
      cout << s << endl;
      return 0;
    }
  }
  cout << "UNRESTORABLE" << endl;
}

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

int main(){
  long N, x, min=1e15;
  cin >> N;
  for(int i=0; i<5; i++){
    cin >> x;
    if(x<min) min = x;
  }
  cout << (long)ceil((double)N/min)+4 << endl;
  return 0;
}

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

int main(void) {
	int x1, y1, x2, y2, x3, y3, x4, y4, dx12, dy12;
	
	scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
	
	dx12 = x2 - x1;
	dy12 = y2 - y1;
	
	x3 = x2 - dy12;
	y3 = y2 + dx12;
	
	x4 = x1 - dy12;
	y4 = y1 + dx12;
	
	printf("%d %d %d %d", x3, y3, x4, y4);
	
	return 0;
}

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

int main(void) {
    int N, M;
    cin >> N;
    vector< int > D(N);
    for (int i = 0; i < N; ++i) {
        cin >> D[i];
    }
    cin >> M;
    vector< int > T(M);
    for (int i = 0; i < M; ++i) {
        cin >> T[i];
    }

    sort(D.begin(), D.end());
    vector< pair< int, int > > vp;
    int count = 1;
    D.push_back(0);
    for (int i = 0; i < N; ++i) {
        if (D[i] == D[i + 1]) {
            ++count;
        } else {
            vp.push_back(make_pair(D[i], count));
            count = 1;
        }
    }
    bool flag = true;
    for (int i = 0; i < M; ++i) {
        vector< pair< int, int > >::iterator iter =
            lower_bound(vp.begin(), vp.end(), make_pair(T[i], 0));
        if (iter == vp.end() || (*iter).first != T[i] || (*iter).second == 0) {
            flag = false;
            break;
        } else {
            --(*iter).second;
        }
    }
    cout << (flag ? "YES" : "NO") << "\n";
    return 0;
}


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

int main() {
    int n;
    cin >> n;
    int a[n];
    rep(i, n) cin >> a[i];

    int all = pow(3, n);
    int bad = 1;
    rep(i, n) if (a[i] % 2 == 0) bad *= 2;

    cout << all - bad << endl;
    return 0;
}


Measured memory_bytes: 4060
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  int W,a,b;cin >> W >> a >> b;
  if(a>b)swap(a,b);
  cout << max(0, b-(a+W)) << endl;
  return 0;
}


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

int main(){
  vector<int> vec(5);
  for (int i = 0; i < 5; i++){
    cin >> vec.at(i);
  }
  for (int i = 0; i < 5; i++){
    if (vec.at(i) == 0){
      cout << i + 1 << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 3500
# include <bits/stdc++.h>
# define ll long long int
# define pb push_back
# define pf push_front
# define mpi make_pair
# define pi pair<ll,ll>
# define fast ios_base::sync_with_stdio(false); cin.tie(NULL);
# define mod 1000000007
# define endl "\n"
using namespace std;
int main()
{
  fast
	ll a,b;
	cin>>a>>b;
	cout<<max((a+b),max((a-b),(a*b)));
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> P;
// 返り値: a と b の最大公約数
// ax + by = gcd(a, b) を満たす (x, y) が格納される
template <typename T>
ll extGCD(T a, T b, T &x, T &y) {
  if (b == 0) {
    x = 1, y = 0;
    return a;
  }
  ll d = extGCD(b, a % b, y, x);
  y -= a / b * x;
  return d;
}
template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
int main() {
  ll N, K;
  cin >> N >> K;
  vector<ll> A(N);
  ll mx = 0;
  REP(i, N) cin >> A[i], chmax(mx, A[i]);
  if (N == 1) {
    if (A[0] == K) {
      cout << "POSSIBLE" << endl;
    } else {
      cout << "IMPOSSIBLE" << endl;
    }
    return 0;
  }
  ll x, y;
  ll tmp = extGCD(A[0], A[1], x, y);
  REP(i, N) tmp = extGCD(tmp, A[i], x, y);
  if (K % tmp == 0 && K <= mx) {
    cout << "POSSIBLE" << endl;
  } else {
    cout << "IMPOSSIBLE" << endl;
  }
}

Measured memory_bytes: 3876
import java.util.Scanner;

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

        boolean[][] cards = new boolean[4][13];

        for(int i=0; i<n; i++) {
            char kind = sc.next().charAt(0);
            int num = sc.nextInt();
            switch(kind) {
                case 'S':
                    cards[0][num-1] = true;
                    break;
                case 'H':
                    cards[1][num-1] = true;
                    break;
                case 'C':
                    cards[2][num-1] = true;
                    break;
                case 'D':
                    cards[3][num-1] = true;
                    break;
            }
        }

        char[] kinds = {'S', 'H', 'C', 'D'};
        for(int i=0; i<4; i++) {
            for(int j=0; j<13; j++) {
                if(!cards[i][j]) {
                    System.out.println(kinds[i] + " " + (j+1));
                }
            }
        }
    }
}



Measured memory_bytes: 26236
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <utility>
#include <cmath>
#include <map>
#include <set>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;

#define INF_LL (ll)1e18
#define INF (int)1e9
#define REP(i, n) for(int i = 0;i < (n);i++)
#define FOR(i, a, b) for(int i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
using ll = long long;
using PII = pair<int, int>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll N;
	ll A[114514], B[114514], C[114514];

	cin >> N;
	REP(i, N){
		cin >> A[i];
	}
	REP(i, N)
		cin >> B[i];
	REP(i, N)
		cin >> C[i];

	sort(A, A+N);
	sort(B, B+N);
	sort(C, C+N);

	ll cnt[114514] = {};
	for(int i = N-1;i >= 0;i--){
		cnt[i] = cnt[i+1]+(N-min((ll)(upper_bound(C, C+N, B[i])-C), N));
	}
	ll res = 0;
	for(int i = N-1;i >= 0;i--){
		res += cnt[upper_bound(B, B+N, A[i])-B];
	}
	cout << res << endl;
}


Measured memory_bytes: 3840
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL


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

    string s;
    cin >> s;

    bool ans = (s.size() & 1 ? false : true);
    char prev = s[0];
    char now;
    int i = 0;
    while (i + 1 < s.size())
    {
        now = s[i + 1];
        prev = s[i];
        if (!(now == 'i' && prev == 'h')) ans = false;
        i += 2;
    }

    cout << (ans ? "Yes\n" : "No\n");
    return 0;
}



Measured memory_bytes: 256
from itertools import permutations
from heapq import heappush, heappop
def inpl(): return tuple(map(int, input().split()))
N, M, R = inpl()
inf = float("inf")
G = {n: {} for n in range(N+1)}
Des = inpl()

for _ in range(M):
    a, b, c = inpl()
    G[a][b] = c
    G[b][a] = c

def dijkstra(s):
    D = [inf for _ in range(N+1)]
    D[s] = 0
    HQ = [(0, s)]
    checked = [False for _ in range(N+1)]
    while HQ:
        c1, a = heappop(HQ)
        if D[a] < c1 or checked[a]: continue
        for b, c2 in G[a].items():
            if c1 + c2 < D[b]:
                D[b] = c1 + c2
                heappush(HQ, (D[b], b))
        checked[a] = True
    return [D[des] for des in Des]

C = []
for s in Des:
    C.append(dijkstra(s))

res = inf
for E in permutations(range(len(Des)), len(Des)):
    res = min(res, sum([C[E[i]][E[i+1]] for i in range(len(Des)-1)]))

print(res)

Measured memory_bytes: 6644
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
#include<fstream>
#include<set>
#include<queue>
using namespace std;
typedef long long ll;

const ll MOD = 1e9 + 7; 

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define out(str) cout << str << endl
#define ALL(a) (a).begin(),(a).end()
#define INF_INT (1<<30)
#define INF_LL (1ll<<62)

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

string s;

int main(){
    cin>>s;
    rep(i,s.size())cout<<"x";
    out("");    
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vll = vector<vl>;
using Pll = pair<ll, ll>;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1e9+7;
const int INF = 2e9;
template<class T> void print(const T& t){ cout << t << endl; }
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 gcd(int a,int b){return b?gcd(b,a%b):a;}
int main(){
  ll n, m;
  cin >> n >> m;
  vector<bool> vec(n+1, false);
  vll graph(n + 1, vl());
  vl ans(n + 1);
  rep(i, m){
    ll a,b;
    cin >> a >> b;
    graph[a].pb(b);
    graph[b].pb(a);
  }
     //1 から始める幅優先探索(zは頂点の番号)
    queue<int> Q;                 //空のキューQ を用意
    vec[1] = true;                //z に訪問済みの印を付ける
    Q.push(1);                    //z をキューQ に追加

    while(!Q.empty()){            //キューQ が空でなければ
        int v = Q.front();        //キューQ の一番上にある要素を取り出す
        Q.pop();                  //キューQ の一番上にある要素を削除

        /*   v を処理する   */

        for(int i : graph[v]){    //v に接続している各頂点i に対し
            if(vec[i]==false){    //i が未訪問なら
                vec[i] = true;    //i に訪問済みの印を付ける
                ans[i] = v;
                Q.push(i); //i をキューQ に追加
            }
        }
    }
  print("Yes");
  for (ll i = 2; i <= n;i++){
    print(ans[i]);
  }
}

Measured memory_bytes: 12772
local s = io.read()
local k = io.read("*n")
ret = "1"
ilast = 101
for i = 1, #s do
  local a = string.sub(s, i, i)
  if(a ~= "1") then
    ilast = i - 1
    ret = a
    break
  end
end
if(k <= ilast) then print("1") else print(ret) end


Measured memory_bytes: 636
#include <iostream>
#include <string>
using namespace std;
int main(){
	int n;cin>>n;
  	string s;cin>>s;
  	if(s.size()<=n){
    	cout <<s;
    }
  	else{
  		for(int i=0; i<n; i++){
        	cout << s[i];
        }
      	cout << "...";
  	}
  return 0;
}

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

using namespace std;

#define pb push_back
#define mp make_pair
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
typedef long long LL;
typedef pair<int, int> PII;

const int MOD = int(1e9) + 7;

int n;
int a[400], b[400];
int uniq[400][400], ua[400][400], ub[400][400];
bool u[400];
int d[400][400] = {}, e[400][400], nd[400][400];
int f[400];
int mul[400];

int main() {
//    freopen("input.txt", "r", stdin);
    scanf("%d", &n);
    forn(i, n) scanf("%d", a + i), --a[i];
    forn(i, n) scanf("%d", b + i), --b[i];
    forn(i, n + 1) {
        memset(u, 0, sizeof u);
        int cnt = i;
        forn(j, i) {
            u[a[j]] = true;
        }
        uniq[i][0] = cnt;
        forn(j, n) {
            if (!u[b[j]]) {
                u[b[j]] = true;
                ++cnt;
            }
            uniq[i][j + 1] = cnt;
        }
    }
    forn(i, n + 1) forn(j, n + 1) {
        int ai = i;
        int bi = j;
        while (ai < n && uniq[ai + 1][bi] == uniq[ai][bi]) {
            ++ai;
        }
        while (bi < n && uniq[ai][bi + 1] == uniq[ai][bi]) {
            ++bi;
        }
        ua[i][j] = ai;
        ub[i][j] = bi;
    }
    d[0][0] = 1;
    for (int r = 0; r < n / 3; ++r) {
        memset(nd, 0, sizeof nd);
        memset(e, 0, sizeof e);
        forn(i, n + 1) forn(j, n + 1) if (uniq[i][j] < 3 * r) {
            int freePlaces = 3 * r - uniq[i][j];
            if (d[i][j]) {
                if (i < n) {
                    int ai = ua[i + 1][j];
                    int bi = ub[i + 1][j];
                    d[ai][bi] = (d[ai][bi] + (LL)d[i][j] * freePlaces) % MOD;
                }
                if (j < n && (i == n || a[i] != b[j])) {
                    int ai = ua[i][j + 1];
                    int bi = ub[i][j + 1];
                    e[ai][bi] = (e[ai][bi] + (LL)d[i][j] * freePlaces) % MOD;
                }
            }
            if (e[i][j]) {
                if (j < n && (i == n || a[i] != b[j])) {
                    int ai = ua[i][j + 1];
                    int bi = ub[i][j + 1];
                    e[ai][bi] = (e[ai][bi] + (LL)e[i][j] * freePlaces) % MOD;
                }
            }
        }
        forn(i, n) forn(j, n) if (a[i] != b[j]) {
            int ai = ua[i + 1][j + 1];
            int bi = ub[i + 1][j + 1];
            nd[ai][bi] = (nd[ai][bi] + ((LL)d[i][j] + e[i][j])) % MOD;
        }
        memcpy(d, nd, sizeof d);
    }
    f[0] = 1;
    for (int i = 1; i < 400; ++i) {
        f[i] = (LL)f[i - 1] * i % MOD;
    }
    int ans = 0;
    forn(i, n + 1) forn(j, n + 1) if (d[i][j]) {
        ans = (ans + (LL)d[i][j] * f[n - uniq[i][j]]) % MOD;
    }
    mul[0] = 1;
    forn(r, n / 3) {
        for (int i = n; i >= 2; --i) {
            mul[i] = mul[i - 2];
        }
        mul[0] = mul[1] = 0;
        for (int i = n; i >= 1; --i) {
            mul[i - 1] = (mul[i - 1] + (LL)mul[i] * i) % MOD;
        }
    }
//    cerr << ans << ' ' << mul[0] << endl;
    cout << (LL)ans * mul[0] % MOD << endl;
    return 0;
}


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

int main() {
  string b;
  cin >> b;
  if(b=="A") puts("T");
  if(b=="T") puts("A");
  if(b=="G") puts("C");
  if(b=="C") puts("G");
  return 0;
}


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

using namespace std;
int main(){
    long long int H,N;
    cin >> N;

    vector<long long int> A(N + 1);
    vector<long long int> B(N);
    for(int i = 0; i < N + 1; i++) cin >> A[i];
    for(int i = 0; i < N; i++) cin >> B[i];
    long long int ans = 0;
    for(int i = 0; i < N; i++){
       if(B[i] > A[i] && B[i] - A[i] > A[i + 1]){
           ans += (A[i] + A[i + 1]); A[i + 1] = 0;
       }else if(B[i] > A[i] && B[i] - A[i] <= A[i + 1]){
           ans += B[i]; A[i + 1] = A[i + 1] - (B[i] - A[i]);
       }else{
           ans += B[i];
       }
    }

    cout << ans;
    

 return 0;
}

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

long long gcd(long x, long y)
{    if (y == 0)
        return x;
    return gcd(y, x % y);}
long long lcm(long x, long y){ return x * y / gcd(x, y);}

int ctoi(char c)
{
    if (c >= '0' && c <= '9')
    {
        return c - '0';
    }
    return 0;
}


int main()
{
    int N,M,s,c,ansA=-1,ansB=-1,ansC=-1;
    cin>>N>>M;

    for(int i=1;i<=M;i++){
        cin>>s>>c;
        if(s==1){
            if(ansA!=-1&&ansA!=c){
                cout<<-1<<endl;
                return 0;
            }
            ansA=c;
        }else if(s==2){
            if(ansB!=-1&&ansB!=c){
                cout<<-1<<endl;
                return 0;
            }
            ansB=c;
        }else{
            if(ansC!=-1&&ansC!=c){
                cout<<-1<<endl;
                return 0;
            }
            ansC=c;
        }
    }

    if(ansA==-1){
        if(N>1){ansA=1;}
        else {ansA=0;}
    }
    if(ansB==-1)ansB=0;
    if(ansC==-1)ansC=0;


    if(ansA==0&&N>=2){
        cout<<-1<<endl;
        return 0;
    }

    if(N==3){
            cout<<ansA*100+ansB*10+ansC<<endl;
    }else if(N==2){
        cout<<ansA*10+ansB<<endl;
    }else{
        cout<<ansA<<endl;
    }

    return 0;
}

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

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

vector<int> card,tmp;
int n;

void cut(int k) {
  tmp.clear();
  REP(i,k)
    tmp.push_back(card[i]);
  REP(i,2*n-k)
    card[i] = card[k+i];

  for(int i=2*n-k; i<2*n; i++)
    card[i] = tmp[i-2*n+k];
}

void riffle() {
  tmp.clear();
  for(int i=0; i<n; i++)
    tmp.push_back(card[i]);

  for(int i=0; i<2*n; i++) {
    if(i%2==0) card[i] = tmp[i/2];
    else card[i] = card[n+(i-1)/2];
  }
}

int main() {
  int m,k;
  cin>>n>>m;
  REP(i,n*2)
    card.push_back(i+1);

  REP(i,m) {
    cin>>k;
    if(!k) riffle();
    else cut(k);
  }

  REP(i,n*2)
    cout<<card[i]<<endl;
}

Measured memory_bytes: 0
#include <iostream>
#include <algorithm> 
using namespace std; 
bool cmp(int a, int b){  
	return a > b; 
} 
int main(){  
	int n, k, x;  
	cin >> n >> k;  
	int a[200000+5]={0}; 
 	for (int i=0; i<n; i++){
 		cin >> x;
		a[x]++; 
    }          
	sort(a+1, a+200000+1, cmp); 
    int count = 0;          
	for (int i=k+1; i<=200000; i++) count += a[i]; 
    cout << count << endl;     
	return 0; 
} 


Measured memory_bytes: 1024
fun main(args: Array<String>) = ABC163C.main()

object ABC163C {
    fun log(message: Any?) {
        println(message)// TODO: ←消す
    }

    fun main() {
        val N = readInt()
        val joushi = readInts()

        val buka = (1..N).map { 0 }.toMutableList()
        joushi.map {
            buka[it-1]++
        }
        println(buka.joinToString("\n"))
    }


    /*####################################################################################*/

    fun readString() = readLine()!!
    fun readStrings() = readLine()!!.split(" ")
    fun readInt() = readLine()!!.toInt()
    fun readInts() = readLine()!!.split(" ").map { it.toInt() }
    fun readMatrixRows(height: Int) = (1..height).map { readLine()!!.toList() }

    fun Boolean.yesOrNo() = if (this) "Yes" else "No"
    fun Double.toNaturalExpr() = println("%f".format(this))
}

Measured memory_bytes: 71988