akhauriyash/Code-Regression huggingface dataset:
#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>

auto& in = std::cin;
auto& out = std::cout;

int32_t N;
std::string S[10000];
std::string T;

int main()
{
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);

	in >> N;
	for (int32_t i = 0; i < N; ++i)
	{
		in >> S[i];
	}
	in >> T;

	int32_t pre_count = 0;
	int32_t aft_count = 0;
	for (int32_t i = 0; i < N; ++i)
	{
		int res = 0;//res<0でSが前
		int32_t j = 0, length = std::min(S[i].size(), T.size());
		for (; j < length; ++j)
		{
			if (S[i][j] == '?') {
				break;
			}
			if (S[i][j] < T[j]) {
				res = -1;
				break;
			}
			if (T[j] < S[i][j]) {
				res = +1;
				break;
			}
		}
		if (res < 0) {
			++pre_count;
		}
		else if (res > 0) {
			++aft_count;
		}
		else
		{
			const auto old_j= j;
			//前があり得るか
			bool enable= S[i].size() <= T.size();
			for (; j < length; ++j)
			{
				if (S[i][j] == '?') {
					if (T[j] > 'a') {
						enable = true;
						break;
					}
					else {
						continue;
					}
				}
				if (S[i][j] < T[j]) {
					enable = true;
					break;
				}
				if (T[j] < S[i][j]) {
					enable = false;
					break;
				}
			}
			if (!enable) {
				++aft_count;
			}
			//後ろがあり得るか
			enable = S[i].size() >= T.size();
			for (j=old_j; j < length; ++j)
			{
				if (S[i][j] == '?') {
					if (T[j] < 'z') {
						enable = true;
						break;
					}
					else {
						continue;
					}
				}
				if (S[i][j] < T[j]) {
					enable = false;
					break;
				}
				if (T[j] < S[i][j]) {
					enable = true;
					break;
				}
			}
			if (!enable) {
				++pre_count;
			}
		}
#if 0
		auto pre = S[i].find_first_of('?');
		if (pre == std::string::npos) { pre = S[i].size(); }
		int res = 0;
		for (int32_t j = 0, length=std::min(pre,T.size()); j < length; ++j)
		{
			if (S[i][j] < T[j]) {
				res = -1;
				break;
			}
			if (T[j] < S[i][j]) {
				res = +1;
				break;
			}
		}
		if (res < 0) {
			++pre_count;
		}
		else if (res > 0) {
			++aft_count;
		}
		else
		{
			if (T.size() < pre) {
				++aft_count;
			}
			if (T.size() == pre) {
				if (T.size() < S[i].size()) {
					++aft_count;
				}
			}
		}
#endif
	}
	bool f = true;
	for (int32_t i = pre_count+1; i <= N+1- aft_count; ++i)
	{
		if (!f) { out << ' '; }
		out << i;
		f = false;
	}
	out << endl;

	return 0;
}
#endif


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

#define int long long
#define fast_io(); ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define loop(i,a,b) for(int i=a;i<b;i++)
#define all(x) x.begin(),x.end()
#define us unordered_set
#define um unordered_map
#define ms multiset
#define mm multimap
#define pb push_back
#define pf push_front
#define ins insert
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define _max max_element
#define _min min_element
#define tc(T) int T; cin>>T; while(T--)
#define q(q) int q; cin>>q; while(q--)
#define pi 3.1415926535897932384626433832
const int pinf=((int)2e18);
const int ninf=((int)-2e18);
const int mod=1000000007;

using namespace std;

int power(int x,int n,int M)
{
    if(n==0)
        return 1;
    else if(n%2 == 0)
        return power((x*x)%M,n/2,M);
    else
        return (x*power((x*x)%M,(n-1)/2,M))%M;
}

bool vowel(char c)
{
    return(c=='a' or c=='e' or c=='i' or c=='o' or c=='u' or c=='A' or c=='E' or c=='I' or c=='U' or c=='O');
}

int32_t main()
{
    fast_io();

    //FILE *fptr1=freopen("in.txt","r",stdin);
    //FILE *fptr2=freopen("out.txt","w",stdout);

    int n,k;
    cin>>n>>k;

    vector <int> a(n);
    loop(i,0,n)
    {
        cin>>a[i];
    }

    sort(all(a),greater <int>());
    int c=0;

    loop(i,0,n)
    {
        if(k>0)
        {
            k--;
        }
        else
        {
            c+=a[i];
        }
    }
    cout<<c;




    return 0;
}


Measured memory_bytes: 4768
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG

using namespace std;
typedef long long ll;

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REP(a, b, m) for (ll a = (ll)(b); a < (ll)(m); a++)

int main()
{
    string s, t;
    int a, b;
    string u;
    cin >> s >> t >> a >> b >> u;
    if (s == u)
    {
        a--;
    }
    else
    {
        b--;
    }
    cout << a << ' ' << b << endl;
}

Measured memory_bytes: 256
import java.util.*;

import static java.lang.Integer.min;

public class Main {

    public static void main(String[] args) {
        int right = 0, left = 0, n, m, x;
        Scanner s = new Scanner(System.in);
        n = s.nextInt();
        m = s.nextInt();
        x = s.nextInt();
        for (int i = 0; i < m; i++) {
            int tmp = s.nextInt();
            if (tmp < x) left++;
            else right++;
        }
        System.out.println(min(right, left));
    }

}


Measured memory_bytes: 21844
S=input()
N=len(S)
F=0
if S!=S[::-1]:
    F=1
s1=S[:(N-1)//2]
if s1!=s1[::-1]:
    F=1
s2=S[(N+3)//2-1:]
if s2!=s2[::-1]:
    F=1
if F==0:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#include <iostream>
#include <queue>
#include <vector>
#include <algorithm>
using namespace std;
int n, x, y;
int d[2000][2000];
vector<vector<int>> v;

void diikstra(int s) {
    queue<int> q;
    q.push(s);
    int c;
    while (!q.empty()) {
        c = q.front();
        q.pop();
        for (int a : v[c]) {
            if (d[s][a] > d[s][c] + 1) {
                d[s][a] = d[s][c] + 1;
                q.emplace(a);
            }
        }

    }
}

int main() {
    cin >> n >> x >> y;
  	for (int i = 0; i < n; i++) {
    	v.emplace_back(vector<int>());
    }
    for (int i = 1; i < n; i++) {
        v[i].emplace_back(i-1);
        v[i-1].emplace_back(i);
    }
  	
    v[x-1].emplace_back(y-1);
    v[y-1].emplace_back(x-1);
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if (i == j) {
                d[i][j] = 0;
            } else {
                d[i][j] = 2001;
            }
        }
    }

    for (int i = 0; i < n; i++) {
        diikstra(i);
    }
    int ks[n];
    for (int i = 0; i < n; i++) ks[i] = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if (d[i][j] < n) ks[d[i][j]]++;
        }
    }
    for (int i = 1; i < n; i++) {
        cout << ks[i]/2 << endl;
    }
    return 0;
}

Measured memory_bytes: 18920
import sys
from operator import itemgetter
import math

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def main():
    N = int(input())
    XY = [[int(x) for x in input().split()] for _ in range(N)]

    txy = []
    for x, y in XY:
        t = math.atan2(x, y)
        txy.append([t, x, y])

    txy.sort()

    ans = 0
    for i in range(N):
        tmpx = 0
        tmpy = 0
        for j in range(N):
            tmpx += txy[(i + j) % N][1]
            tmpy += txy[(i + j) % N][2]
            ans = max(ans, math.sqrt(tmpx ** 2 + tmpy ** 2))


    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9420
#include<bits/stdc++.h>
#define int long long
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define repa(i, s, n) for(int i = s; i < (int)n; i++)
using namespace std;
using ll = long long;
typedef vector<int> vi;
typedef pair<int, int> P;
#define rrep(i,a,b) for(int i=a;i>=b;i--)

int dp[100010];

signed main(){
    int n;
    cin >> n;
    vi h(n);
    rep(i, n) cin >> h[i];
    memset(dp, 0, sizeof(dp));
    dp[1] = abs(h[0] - h[1]);
    for(int i = 2; i < n; i++){
        dp[i] = min(dp[i-1] + abs(h[i-1]-h[i]), dp[i-2] + abs(h[i-2] - h[i]));
    }

    cout << dp[n-1] << endl;
}

Measured memory_bytes: 4788
n = int(input())
a = [[int(j) for j in input().split()] for i in range(n)]
dp = [[0 for i in range(3)] for j in range(n+1)]
for i in range(n):
  for j in range(3):
    for k in range(3):
      if j == k:
        continue
      if dp[i+1][k] < dp[i][j]+a[i][k]:
        dp[i+1][k] = dp[i][j]+a[i][k]
ans = max(dp[n][0], dp[n][1], dp[n][2])
print(ans)

Measured memory_bytes: 74656
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
int main()
{  
	int N, K;
	cin >> N >> K;
	vector<int> A;
	for(int i=0; i<N; i++)
	{
		int a;
		cin >> a;
		A.push_back(a);
	}
	map<int,int> m;
	map<int,bool> b;
	for(int i=0; i<N; i++)
	{
		m[A[i]] = 0;
		b[A[i]] = false;
	}
	
	for(int i=0; i<N; i++)
	{
		m[A[i]]++;
	}

    vector<int> num; 
    for(int i=0; i<N; i++)
    {
    	if(!b[A[i]])
    	{
    		num.push_back(m[A[i]]);
    		b[A[i]] = true;
     	}
    }

    sort(num.begin(),num.end(), greater<int>());
    int sum = 0;
    if(num.size()<=K)
    {
        cout << 0 << endl;
    }
    else{
    	for(int i=0; i<K; i++)
      {
        sum += num[i];
      }
      cout << N-sum << endl;
    }
	return 0;
}

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

using namespace std;
typedef long long ll;

int main() {
    ll n;
    cin >> n;
    vector<ll> a(n);
    ll before = 0;
    ll h = 0;
    for (ll i = 0; i < n; i++) {
        ll next;
        cin >> next;
        ll dh = 0;
        if (before > next) {
            dh = before - next;
            h += dh;
        }
        before = next + dh;
    }
    cout << h << endl;
    return 0;
}


Measured memory_bytes: 4780
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define MEMSET(v, h) memset((v), h, sizeof(v))
typedef long long ll;

using namespace std;

int main(void){
    int N;
    cin >>N;
    if(N%2 == 0) cout << 0.5 << endl;
    else{
        double n = N;
        double ans = ((n+1)/2)/n;
        cout << ans << endl;
    }
    return 0;
}


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

int main()
{
    int n, k;
    cin >> n >> k;
    vector<int> p(n);
    rep(i, n) cin >> p[i];
    rep(i, n) p[i]++;
    int mx = 0;
    int s = 0;
    queue<int> q;
    rep(i, n) {
        s += p[i];
        q.push(p[i]);
        if(q.size() > k) {
            s -= q.front();
            q.pop();
        }
        if(q.size() == k) {
            mx = max(mx, s);
        }
    }
    double ans = mx;
    ans /= 2;
    cout << setprecision(10) << ans << endl;
    return 0;
}

Measured memory_bytes: 4656
from heapq import heappush, heappop

N, M = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(N)]

pq = []
for a, b in X:
    heappush(pq, (a, b))
    
cand = []
ans = 0
for t in range(1, M + 1):
    while pq:
        a, b = heappop(pq)
        if a <= t:
            heappush(cand, -b)
        else:
            heappush(pq, (a, b))
            break

    if cand:
        v = heappop(cand)
        ans += -v

print(ans)


Measured memory_bytes: 105088
#include <bits/stdc++.h>
using namespace std;
#define rep(i,j,k) for(int i = (int)(j);i <= (int)(k);i ++)
#define debug(x) cerr<<#x<<":"<<x<<endl
#define fix cout<<fixed<<setprecision(20);
const int maxn=(int)1e6+5;
long long A[maxn],B[maxn],C[maxn];
int main(){
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int x,y,a,b,c;cin>>x>>y>>a>>b>>c;
    vector<long long> D;
    long long ans=0;
    rep(i,1,a)cin>>A[i];rep(i,1,b)cin>>B[i];rep(i,1,c)cin>>C[i];
    sort(A+1,A+1+a);sort(B+1,B+1+b);sort(C+1,C+1+c);
    rep(i,1,x)D.push_back(A[a+1-i]);
    rep(i,1,y)D.push_back(B[b+1-i]);
    sort(D.begin(),D.end()); 
    int i=0;
    while(i<D.size()&&i<c&&D[i]<C[c-i])D[i]=C[c-i],i++;
    for(auto t:D)ans+=t,debug(t);
    cout<<ans<<endl;
}
/* 

 */

Measured memory_bytes: 11508
#include<bits/stdc++.h>
// #include <ext/pb_ds/tree_policy.hpp>
// #include <ext/pb_ds/assoc_container.hpp>
#include<chrono>
using namespace std;
using namespace std::chrono;
//using namespace __gnu_pbds;
#define fastio     ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define fi         first
#define se         second
#define int         long long
#define pb         push_back
#define emp        emplace_back
#define vv(x)      vector<x>
#define mp(x,y)    map<x,y>
#define dq(x)      deque<x>
#define pql(x)     priority_queue<x>
#define pqs(x)     priority_queue<x,vv(x),greater<x> >
#define mod         1000000007
#define forf(i,a,b) for(int i=a;i<b;i++)
#define it(x)      x::iterator
#define ll         long long
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#define time__(d)  for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false); debug("%s time : %.4fs", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
#define vii        vector<int>
#define big        3e18
#define sm         -2e9
#define mkr        make_pair
#define vpi        vector<pair<int,int> >
#define pii        pair<int,int>
#define rng        500005
#define sz(x)      (int)x.size()
#define rv(x)      reverse(x.begin(),x.end())
#define out(x)     cout<<x.fi<<" "<<x.se<<endl;
 
//#define ordered_set tree<pii, null_type,less<pii>, rb_tree_tag,tree_order_statistics_node_update>
 
void pr_init()
{
 
#ifndef ONLINE_JUDGE
  freopen("gin.txt", "r", stdin);
  freopen("gout.txt", "w", stdout);
 
#endif
}
void solve()
{
  int n;
  cin >> n;
  if(n>=30) cout<<"Yes\n";
  else cout<<"No\n";  
}
 
 
int32_t main()
{
  pr_init();
  fastio;
 
  auto start = high_resolution_clock::now();
 
  solve();
  auto stop = high_resolution_clock::now();
  auto duration = duration_cast<microseconds>(stop - start);
  // cout << "Time taken by function: "
  //       << duration.count() << " microseconds" << endl;
 
}
 

Measured memory_bytes: 3600
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <cstdint>
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <bitset>

using namespace std;

using ll =  long long;
using Pll = pair<ll, ll>;
using Pii = pair<int, int>;

constexpr ll MOD = 1000000007;
constexpr long double EPS = 1e-10;
constexpr int dyx[4][2] = {
    { 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};

int main() {
    std::ios::sync_with_stdio(false); cin.tie(nullptr);
    int n;
    cin >> n;
    vector<int> a(n), b(n, 0);
    for(int i=0;i<n;++i){
        cin >> a[i];
    }

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

    cout << *max_element(b.begin(), b.end()) << endl;
}


Measured memory_bytes: 1024
package main

import (
	"fmt"
)

func main() {
	var N, cnt int
	fmt.Scan(&N)
	for i := 1; i <= N; i++ {
		if i%2 == 0 {
			continue
		}
		y := 0
		for j := 1; j <= i; j++ {
			if i%j == 0 {
				y++
			}
			if y > 8 {
				break
			}
		}
		if y == 8 {
			cnt++
		}
	}
	fmt.Println(cnt)
}

Measured memory_bytes: 512
S = input()

if S == 'SUN':
  print(7)
if S == 'MON':
  print(6)
if S == 'TUE':
  print(5)
if S == 'WED':
  print(4)
if S =='THU':
  print(3)
if S =='FRI':
  print(2)
if S == 'SAT':
  print(1)

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

#define for_(i,a,b) for(int i=a;i<b;++i)
#define ALL(a) a.begin(),a.end()
#define INIT(a,b) memset(a,b,sizeof(a))
using lint = long long int;

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

lint pow_mod(lint x, lint k) {
    lint res = 1;
    while (k) {
        if (k&1) res = (res * x) % MOD;
        x = (x * x) % MOD;
        k >>= 1;
    }
    return res;
}

int main() {
    int N, K;
    cin >> N >> K;

    vector<lint> ans(K+1, 0);
    for (int i=K; i>0; --i) {
        ans[i] = pow_mod(K / i, N);
        for (int j=2*i; j<=K; j+=i) ans[i] = (ans[i] - ans[j] + MOD) % MOD;
    }
    
    lint sum = 0;
    for_(i,1,K+1) {
        lint add = (i * ans[i]) % MOD;
        sum = (sum + add) % MOD;
    }
    cout << sum << endl;
}

Measured memory_bytes: 4052
import scala.io.StdIn
import scala.collection.mutable._

object Main extends App {

  val Array(n, m) = StdIn.readLine.split(" ").map(_.toInt)
  val graph = Array.fill(n+1)(ListBuffer.empty[Int])
  Iterator.continually(StdIn.readLine)
    .take(m)
    .map(_.split(" ").map(_.toInt))
    .foreach(e => graph(e(0)) += e(1))

  val isPossible = {
    var visited = false
    def dfs(pos:Int, cnt:Int):Unit = {
      if(cnt < 0) return
      if(pos == n) visited = true
      else {
        for(i <- graph(pos)) {
          if(!visited) dfs(i, cnt-1)
        }
      }
    }
    dfs(1,2)
    visited
  }
  val ans = if(isPossible) "POSSIBLE" else "IMPOSSIBLE"
  println(ans)
}

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

layer_size = [1]
P_cnt = [1]

for _ in range(50):
  #[-1]は末尾の要素を取得。layer_sizeで、合計
  layer_size.append(layer_size[-1]*2+3)

  #[-1]は末尾の要素を取得。P_cntはパティの枚数
  P_cnt.append(P_cnt[-1]*2+1)


def solve(level, x):
  if x == 1:
    return 0 if level > 0 else 1
  l = layer_size[level-1]
  p = P_cnt[level-1]
  if x <= 1+l:
    return solve(level-1, x-1)
  elif x == l+2:
    return p+1
  elif x <= 2*l+2:
    return p+1+solve(level-1, x-l-2)
  else:
    return 2*p+1
  
ans = solve(N, X)
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,m,n) for(int i=m;i<n;i++)
ll mod=1e9+7;

int main(){
  string s;
  cin>>s;
  int n=s.size();
  cout<<s[0]<<n-2<<s[n-1]<<endl;
}

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

using namespace std;

bool prime(int n)
{
	for (int i=2; i*i <= n; ++i)
	{
		if(n % i == 0) 
		{
			return false;
		}
	}
	return true;
}
  
int main(void)  
{  
    int cnt = 0;
    int n;
    scanf("%d", &n);
    int tmp;
	for(int i = 0; i<n; ++i)
    {
    	scanf("%d", &tmp);
    	if(prime(tmp)) ++cnt;
	}
	printf("%d\n", cnt);
    return 0;  
}

Measured memory_bytes: 3216
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<map>

using namespace std;

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

	string akiba = "AKIHABARA";

	int i, j;
	i = j = 0;
	while (i < s.length() && j < akiba.length()) {
		if (s[i] == akiba[j]) {
			i++;
			j++;
		}
		else if (akiba[j] == 'A') {
			j++;
		}
		else {
			cout << "NO" << endl;
			system("pause");
			return 0;
		}
	}
	while (akiba[j] == 'A') j++;
	if(i >= s.length() && j >= akiba.length()) cout << "YES" << endl;
	else cout << "NO" << endl;
	system("pause");
	return 0;
}

Measured memory_bytes: 504
#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];
  }
  vector<int> C(N);
  
  for(int i=0;i<N;i++){
    C[A[i]-1]=i+1;
  }
  
  for(int i=0;i<N;i++){
    cout << C[i] << " " ;
  }
}
    

Measured memory_bytes: 1536
#include<iostream>
#include<algorithm>
#include<math.h>
#include<vector>
#include<map>
#include<set>
#include<iomanip>

using namespace std;
using ll = long long;
using P = pair<int, int>;

const int MOD = 1e9 + 7;
const int MAX = 1e9;
const ll LLMAX = 1e18;
const int INF = numeric_limits<int>::max();
const ll LLINF = numeric_limits<ll>::max();
const double PI = acos(-1.0);

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

int main() {
    string S; cin >> S;

    cout << "ABC" + S << endl;
    return 0;
}


Measured memory_bytes: 3588
#include<iostream>
#include<cmath>
#include<cstdio>
#include<algorithm>
#define mes(a, b) memset(a, b, sizeof a)
#define pb push_back
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
const int maxn = 2e6+10;
const double eps = 1e-1;
ll T, n, m, k, q;
int main(){
    ll x, ans = 0;
    scanf("%lld%lld", &m, &n);
    for(int i = 1; i <= n; i++)
        scanf("%lld", &x), ans+=x;
    ans = m-ans>-1?m-ans:-1;
    printf("%lld\n", ans);
    return 0;
}


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

using namespace std;

int main(void){
  int h, w;
  vector<string> c(100);

  cin >> h >> w;

  for(int i = 0; i < h; i ++)
    cin >> c.at(i);

  for(int i = 0; i < h; i ++)
    cout << c.at(i) << endl << c.at(i) << endl;

  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>

int n;

int binarySearch(int S[], int key){
    int left = 0;
    int right = n;

    while ( left < right) {
        int mid = ( left + right) / 2;
        if (S[mid] == key){
            return 1;
        }
        else if ( S[mid] > key){
            right = mid;
        }
        else{
            left = mid +1;
        }
    }
    return 0;
}


int main(){
    int  S[100001], q, t, c;
    scanf("%d",&n);
    for ( int i =0; i < n; i++)scanf("%d",&S[i]);
    scanf("%d",&q);

    for ( int i =0; i < q; i++){
        scanf("%d",&t);
        if (binarySearch(S,t)){
            c++;
        }
    }
    printf("%d\n",c);
    return 0;

}


Measured memory_bytes: 3068
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << endl;
#define CFYN(n) cout << ( (n) ? "YES":"NO") << endl;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;

int main(void)
{
    IOS
    int a, b, c;
    cin >> a >> b >> c;
    int d, e, f;
    cin >> d >> e >> f;
    set<int> waters;
    for(auto i = 0;i*a*100 <= f; i++) {
        for(auto j = 0; (i*a+j*b)*100 <=f; j++) waters.insert((i*a+j*b) * 100);
    }
    vector<int> waterv(waters.begin(),waters.end());
    
    vector<int> sugar;
    for(auto w:waterv) sugar.push_back(w/100*e);
    //REP(i,sugar.size()) cerr << sugar[i] << endl;
    double maxc = 0;
    int ans = 100 * a;
    int anss = 0;
    REP(i,waterv.size()) {
        for(auto j = 0;j*c <= sugar[i];j++) {
            for (auto k = 0; j*c+ k*d <=sugar[i]; k++) {
                int ms = 0;
                if (waterv[i] + j*c+ k*d <= f) ms = j*c+ k*d;
                double cons = static_cast<double>(ms) / (waterv[i] + ms);
                if (maxc < cons) {
                    maxc = cons;
                    ans = waterv[i] + ms;
                    anss = ms;
                }
            }
        }
        //cerr << ans << " " << anss << endl;
    }

    cout << ans << " " << anss << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector> 
# include <cstdint>
#define FOR(i,l,r) for(int i=(l);i<(r);++i)
#define RFOR(i,l,r) for(int i=(l);i>=(int)(r);i--)
#define rep(i,n)  FOR(i,0,n)
#define rrep(i,n)  RFOR(i,n-1,0)

#define int long long
using namespace std;
const int MX = 1e6;
const int inf = 1e13;
const int mod = 1e9+7;
#define ll long long
map<char, int> m;
signed main() {
    int a,b;
    cin >> a >> b;
    if(a==1 || b==1) cout << 1 << endl;
    else cout << (a*b+1)/2 << endl;
  return 0;
}



Measured memory_bytes: 3632
using System;

namespace CSharp
{
    class Program
    {
        static void Main()
        {
            var N = int.Parse(Console.ReadLine());

            var table = new int[10, 10];
            for (int k = 1; k <= N; k++)
            {
                table[int.Parse(k.ToString()[0].ToString()), int.Parse((k % 10).ToString()[0].ToString())]++;
            }

            var result = 0;
            for (int i = 1; i <= N; i++)
            {
                result += table[i % 10, int.Parse(i.ToString()[0].ToString())];
            }
            Console.WriteLine(result);
        }
    }
}


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

using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> penalty(n);
  vector<char> solved(n);
  for (int i = 0; i < m; ++i) {
  	int id;
    string verdict;
    cin >> id >> verdict;
    --id;
    penalty[id] += (verdict == "WA" && !solved[id]);
    solved[id] |= verdict == "AC";
  }
  int solved_cnt = 0, penalty_cnt = 0;
  for (int i = 0; i < n; ++i) {
  	if (!solved[i]) continue;
    ++solved_cnt;
    penalty_cnt += penalty[i];
  }
  cout << solved_cnt << " " << penalty_cnt << '\n';
  return 0;
}

Measured memory_bytes: 768
#include <stdio.h>
int main(void){
	int n;
	scanf("%d", &n);
	n -= n/10 * 10;
	if(n == 3){
		printf("bon\n");
	}
	else if(n == 0 || n == 1 || n == 6 || n == 8){
		printf("pon\n");
	}
	else{
		printf("hon\n");
	}
	return 0;
}

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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define PI 3.14159265358979
#define MOD 1000000007 // = 10^9 + 7

using namespace std;
using ll = long long;

void solve()
{
	int n, a;
	cin >> n;
	map< int, int > stu;
	for(int i = 0; i < n; ++i)
	{
		cin >> a;
		stu[a] = i + 1;
	}

	for(const auto& s : stu)
	{
		cout << s.second << " ";
	}
}

int main()
{
	fastio;
	solve();

	return 0;
}

Measured memory_bytes: 8340
import java.util.Scanner;

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

        if ((a == b && b == c) || (a != b && b != c && a != c)) {
            System.out.println("No");
        } else  {
            System.out.println("Yes");
        }


    }
}


Measured memory_bytes: 24148
#include <iostream>
#include <cassert>
#include <vector>
#include <set>
#include <queue>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <complex>

using namespace std;
typedef long long ll;

typedef long double R;
typedef complex<R> P;


namespace std {
    bool operator < (P a, P b) {
        return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
    }
    bool operator > (P a, P b) {
        return (b < a);
    }
}

const R EPS = 1e-10;
const R PI = acos(-1);

/*
 -1 -> neg
  0 -> near 0
  1 -> pos
  */
int sgn(R a) {
    if (a < -EPS) return -1;
    if (a > EPS) return 1;
    return 0;
}

int sgn(R a, R b) {
    return sgn(b-a);
}

bool near(P a, P b) {
    return !sgn(abs(a-b));
}

R cross(P a, P b) { return imag(conj(a)*b); }
R dot(P a, P b) { return real(conj(a)*b); }

/* 1->cclock
  -1->clock
   0->on
   2->back
  -2->front
  */
int ccw(P a, P b, P c) {
    assert(!near(a, b));
    if (near(a, c) || near(b, c)) return 0;
    int s = sgn(cross(b-a, c-a));
    if (s) return s;
    if (a > b) swap(a, b);
    if (dot(b-a, c-a) < 0) return 2;
    if (dot(a-b, c-b) < 0) return -2;
    return 0;
}

struct L {
    P x, y;
    L() {};
    L(P x, P y) :x(x), y(y) {};
};

P vec(const L &l) {
    return l.y - l.x;
}

R abs(const L &l) {
    return abs(vec(l));
}

struct C {
    P p;
    R r;
    C () {};
    C (P p, R r) : p(p), r(r) {};
};

R distLP(const L &l, const P &p) {
    return abs(cross(l.y-l.x, p-l.x)/abs(l.y-l.x));
}


//????????¨??????????°??????¢
R distSP(const L &s, const P &p) {
    R r = min(abs(s.x-p), abs(s.y-p));
    P s2 = vec(s)*P(0, 1);
    if (ccw(s.x, s.x+s2, p) == 1) return r;
    if (ccw(s.y, s.y+s2, p) == -1) return r;
    return min(r, distLP(s, p));
}

int CrossSC(const L&l, const C &c) {
    R mi = distSP(l, c.p);
    if (sgn(c.r, mi) == 1) return 0;
    if (sgn(c.r, mi) == 0) return 1;
    int u = 0;
    if (sgn(c.r, abs(l.x-c.p)) != -1) u++;
    if (sgn(c.r, abs(l.y-c.p)) != -1) u++;
    return u;
}

const int MN = 110;


C w[MN];
int n, m;

int main() {
    while (true) {
        cin >> n;
        if (!n) break;
        for (int i = 0; i < n; i++) {
            R x, y, r;
            cin >> x >> y >> r;
            w[i] = C(P(x, y), r);
        }
        cin >> m;
        for (int i = 0; i < m; i++) {
            R tx, ty, sx, sy;
            cin >> tx >> ty >> sx >> sy;
            L l = L(P(tx, ty), P(sx, sy));
            bool f = true;
            for (int j = 0; j < n; j++) {
                if (CrossSC(l, w[j])) {
                    f = false;
                }
            }
            if (f) {
                cout << "Danger" << endl;
            } else {
                cout << "Safe" << endl;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 1256
s = input()

for i in range(len(s)):
	s = s[:-1]
	if len(s) == 1:
		print(1)               
	if len(s) % 2 == 0:
		n = len(s)
		if s[int(n/2):] == s[:int(n/2)]:
			print(n)
			break               


Measured memory_bytes: 2940
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <tuple>
#include <bitset>
#include <random>
#define REP(i,n) for(int i=0;i<n;i++)
#define INF 100000000000000
using namespace std;
using pii=pair<int,int>;




vector<int64_t> dist;
vector<int> pre;


void Bellman_Ford(vector<vector<pii>> adj_list,int start){
    
    
    int n=adj_list.size();
    /*初期化*/
    dist=vector<int64_t>(n,INF);
    pre=vector<int>(n);/*最短経路におけるひとつ前の頂点*/
    
    dist.at(start)=0;
    REP(i,n-1){
        REP(u,n){
            for(auto vpair : adj_list.at(u)){
                int weight_u_to_v,v;
                tie(v,weight_u_to_v)=vpair;
                if(dist.at(u)!=INF && dist.at(v)>dist.at(u)+weight_u_to_v){
                  dist.at(v)=dist.at(u)+weight_u_to_v;
                  pre.at(v)=u;
                  
                }

            }
        }
    }

    REP(i,n){/*ここで更新があったら負閉路が存在*/
        REP(u,n){
            for(auto vpair : adj_list.at(u)){
                int weight_u_to_v,v;
                tie(v,weight_u_to_v)=vpair;
                if(dist.at(u)!=INF && dist.at(v)>dist.at(u)+weight_u_to_v){
                  dist.at(v)=-INF;
                  
                }

            }
        }
    }

  
}


  

int main() {
  int V,E,r;
  cin>>V>>E>>r;
  vector<vector<pair<int,int>>> adj_list(V);
  
  REP(i,E){
    int s,t,d;
    cin>>s>>t>>d;
    adj_list.at(s).push_back(make_pair(t,d));

  }
  

  Bellman_Ford(adj_list,r);
  
  REP(i,V){
    if(dist.at(i)==-INF){
      cout<<"NEGATIVE CYCLE"<<endl;
      return 0;
    }
  }
  REP(i,V){
    if(dist.at(i)==INF){
      cout<<"INF"<<endl;
    }else{
      cout<<dist.at(i)<<endl;
    }
  }


  return 0;
}


Measured memory_bytes: 3240
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(int argc, char const *argv[])
{
	int n,m,q;
	cin>>n>>m>>q;
	vector<int> G[505];
	for(int i = 0;i < m; ++i)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		G[x].push_back(y);
	}
	for(int i = 0;i <= n; ++i)
	{
		sort(G[i].begin(),G[i].end());
	}
	while(q--)
	{
		int u,v;
		scanf("%d%d",&u,&v);
		int ret = 0;
		for(int i = u;i <= v; ++i)
		{
			ret += upper_bound(G[i].begin(),G[i].end(),v) - G[i].begin();
		}
		printf("%d\n",ret);
	}
	return 0;
}

Measured memory_bytes: 2176
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;
const double PI = 3.14159265358979323846264338327950288;

int main()
{
	int N;
	cin >> N;
	cout << N / 3 << endl;
}


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

using namespace std;

const double PI = 3.141592653589;
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define pb push_back
#define mp make_pair
#define int long long
#define all(c) (c).begin(),(c).end()
#define M 1000000007
#define INF LLONG_MAX
#define pr(...) dbs(#__VA_ARGS__, __VA_ARGS__)
template <class T> void dbs(string str, T t) {cerr << str << " : " << t << "\n";}
template <class T, class... S> void dbs(string str, T t, S... s) {int idx = str.find(','); cerr << str.substr(0, idx) << " : " << t << ", "; dbs(str.substr(idx + 1), s...);}
template <class S, class T>ostream& operator <<(ostream& os, const pair<S, T>& p) {return os << "(" << p.first << ", " << p.second << ")";}
template <class T>ostream& operator <<(ostream& os, const vector<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T>ostream& operator <<(ostream& os, const set<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class S, class T>ostream& operator <<(ostream& os, const map<S, T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T> void prc(T a, T b) {cerr << "["; for (T i = a; i != b; ++i) {if (i != a) cerr << ", "; cerr << *i;} cerr << "]\n";}
// Use pr(a,b,c,d,e) or cerr<<anything or prc(v.begin(),v.end()) or prc(v,v+n)
//  
int ipow(int base, int pow)
{
    int ans = 1;
    if(pow == 0) return 1;
    while(pow > 0)
    {
        if(pow&1) ans *= base;
        base *= base;
        base%= M;
        ans %= M;
        pow >>= 1;
    }
    return ans;
}

int inv(int frac)
{
    return ipow(frac, M-2);
}

map<pair<int, int>, int> dict;
int nck(int n, int k)
{
    if(n<k) return 0;
    if(n == k || k == 0) return 1;
    if(n<=0) return 0;
    if(dict.find({n, k}) != dict.end()) return dict[{n, k}];
    if(k == 0 || k == n) return 1;
    int z = (((n)*(inv(n-k)))%M)*nck(n-1, k);
    z %= M;
    dict[{n, k}] = z;
    return z;
}
int32_t main()
{
    fastio;
    //freopen("file.in", "r", stdin);
    //freopen("file.out", "w", stdout);
    int n, k;
    cin >> n >> k;
    vector<int> v(n), dp(n, 0);
    for(int i=0;i<n;i++)
    {
         cin >> v[i];
    }
    sort(all(v));
    // independently calculate max sum and min sum
    int ans = 0;
    for(int i=k-1;i<n;i++)
    {
        ans += (nck(i, k-1)*v[i])%M;
        //int z = nck(i, k-1);
        //pr(z, i, k-1);
        ans %= M;
    }
    reverse(all(v));
    for(int i=k-1;i<n;i++)
    {
        int z= (nck(i, k-1)*v[i])%M;
        ans = (ans + M - z)%M;
    }
    cout << ans << "\n";
    return 0;
}



Measured memory_bytes: 4992
#include<iostream>
#include<algorithm>

using namespace std;

#define N 1000000

int main(){

    bool primes[N];
    int  n; 

    fill(primes, primes + (sizeof primes / sizeof *primes), true);
   
    primes[0] = false;
    primes[1] = false;
    
    for(int i = 2; i + i <= N; ++i){
        if(primes[i]){
            for(int j = i + i; j < N; j += i)primes[j] = false;
        }
    }

    while(cin >> n){
        int  count = 0;
        for(int i = 2; i <= n; ++i){
            if(primes[i])count++;
        }
        cout << count << endl;
    }
    
	return 0;
}

Measured memory_bytes: 2136
def main():
    n = input()
    result = []
    for i in n:
        if i == '1':
            result.append('9')
        elif i == '9':
            result.append('1')
        else:
            result.append(i)
    print(result[0] + result[1] + result[2])


if __name__ == "__main__":
    main()


Measured memory_bytes: 9040
#include <iostream>
#define int long long
using namespace std;

int n;
int a[200000];

signed main() {
	int i, j;
	
	cin >> n;
	for (i = 0; i < n; i++) cin >> a[i];
	
	if (a[0] != 0) { cout << -1 << endl; return 0; }
	for (i = 1; i < n; i++) if (a[i] - a[i - 1] >= 2) { cout << -1 << endl; return 0; }
	
	int ans = 0;
	for (i = n - 1; i >= 0; ) {
		if (a[i] == 0) { i--; continue; }
		for (j = i - 1; j >= 0; j--)
			if (a[j] > a[i] - (i - j)) break;
		ans += a[i];
		i = j;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include<time.h>
using namespace std;
typedef long long int llint;
typedef vector<int> vint;
typedef vector<llint> vllint;
typedef vector<pair<int, int>> vpint;
typedef vector<pair<llint, llint>> vpllint;
#define rep(i,n) for(int i=0;i<n;i++)
#define drep(i,n) for(int i=n-1;0<=i;i--)
#define yes(ans) if(ans)cout<<"yes"<<endl;else cout<<"no"<<endl;
#define Yes(ans) if(ans)cout<<"Yes"<<endl;else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl;else cout<<"NO"<<endl;
#define POSSIBLE(ans) if(ans)cout<<"POSSIBLE"<<endl;else cout<<"IMPOSSIBLE"<<endl;

class UnionFind {
public:
	//親の番号を格納する。親だった場合は-(その集合のサイズ)
	vector<int> Parent;

	//作るときはParentの値を全て-1にする
	//こうすると全てバラバラになる
	UnionFind(int N) {
		Parent = vector<int>(N, -1);
	}

	//Aがどのグループに属しているか調べる
	int root(int A) {
		if (Parent[A] < 0) return A;
		return Parent[A] = root(Parent[A]);
	}

	//自分のいるグループの頂点数を調べる
	int size(int A) {
		return -Parent[root(A)];//親をとってきたい
	}

	//AとBをくっ付ける
	bool connect(int A, int B) {
		//AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
		A = root(A);
		B = root(B);
		if (A == B) {
			//すでにくっついてるからくっ付けない
			return false;
		}

		//大きい方(A)に小さいほう(B)をくっ付けたい
		//大小が逆だったらひっくり返しちゃう。
		if (size(A) < size(B)) swap(A, B);

		//Aのサイズを更新する
		Parent[A] += Parent[B];
		//Bの親をAに変更する
		Parent[B] = A;

		return true;
	}
};

//aとbの最大公約数を求めるよ
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

// 返り値: a と b の最大公約数
// ax + by = gcd(a, b) を満たす (x, y) が格納される
long long extGCD(long long a, long long b, long long& x, long long& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}

bool check(int a, int b) {
	return a > b;
}

int main() {
	int n;
	cin >> n;
	vllint a(n + 1, 0);
	rep(i, n) {
		llint x;
		cin >> x;
		a[i + 1] = a[i] + x;
	}
	sort(a.begin(), a.end());
	llint ans = 0;
	llint cnt = 1;
	rep(i, n) {
		if (a[i] == a[i + 1]) {
			cnt++;
		}
		else {
			ans += (llint)cnt * (cnt - 1) / 2;
			cnt = 1;
		}
	}
	ans += (llint)cnt * (cnt - 1) / 2;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1792
while True:
    a, op, b = input().split()
    a = int(a)
    b = int(b)

    if op == '?':
        break

    if op == '+':
        print(a + b)

    if op == '-':
        print(a -b)
 
    if op == '*':
        print(a * b)
   
    if op == '/':
        print(a // b)

Measured memory_bytes: 7668
#include<iostream>
#include<algorithm>
#include<bits/stdc++.h>
using namespace std;
/*---------------------DEBUGGING--------------------------------------------*/
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
/*-------------------------------------------------------------------------------------*/
#define mp make_pair
#define pb push_back
#define ll long long
#define pii pair<int,int>
#define pcc pair<char,char>
#define F first
#define S second
#define int long long
#define pi 3.141592653589793238462643383279502
#define M  998244353
#define rep(i,a,n) for(int i=a;i<n;i++)
#define N 300005
#define vi vector<int>
#define all(v) v.begin(),v.end()

signed main()
{
   ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
   int n;
   cin>>n;
   int a[n];
   int sum=0;
   for(int i=0;i<n;i++)
   {
       cin>>a[i];
       sum+=a[i];
   }
   int avg=sum/n;
   int ans=0;
   for(int i=0;i<n;i++)
   {
       ans+=pow(abs(a[i]-avg),2);
   }
   int ans1=0;
   avg++;
   for(int i=0;i<n;i++)
   {
       ans1+=pow(abs(a[i]-avg),2);
   }
   cout<<min(ans,ans1)<<endl;
}


Measured memory_bytes: 256
#![allow(dead_code, unused_imports, non_snake_case)]

use std::io::*;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::str::FromStr;

const MOD: i32 = 1_000_000_007;

fn main() {
    let s: Vec<char> = input();
    let k: usize = input();
    for i in 0..min(k, s.len()) {
        if s[i] != '1' {
            println!("{}", s[i]);
            return;
        }
    }
    println!("1");
}

trait Read {
    fn read(s: &str) -> Self;
}

fn input<T: Read>() -> T {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    T::read(buf.trim_right())
}

macro_rules! read_impl {
    ($($t:ty)*) => ($(
        impl Read for $t {
            fn read(s: &str) -> $t{
                s.parse().unwrap()
            }
        }
    )*)
}
read_impl! { usize u8 u16 u32 u64 isize i8 i16 i32 i64 f32 f64 }

impl Read for String {
    fn read(s: &str) -> Self {
        s.to_string()
    }
}

impl Read for Vec<char> {
    fn read(s: &str) -> Self {
        s.chars().collect()
    }
}

impl<T: Read> Read for Vec<T> {
    fn read(s: &str) -> Self {
        s.split_whitespace().map(T::read).collect()
    }
}

impl<A: Read, B: Read> Read for (A, B) {
    fn read(s: &str) -> Self {
        let tokens: Vec<_> = s.split_whitespace().collect();
        (A::read(tokens[0]), B::read(tokens[1]))
    }
}

impl<A: Read, B: Read, C: Read> Read for (A, B, C) {
    fn read(s: &str) -> Self {
        let tokens: Vec<_> = s.split_whitespace().collect();
        (A::read(tokens[0]), B::read(tokens[1]), C::read(tokens[2]))
    }
}

impl<A: Read, B: Read, C: Read, D: Read> Read for (A, B, C, D) {
    fn read(s: &str) -> Self {
        let tokens: Vec<_> = s.split_whitespace().collect();
        (A::read(tokens[0]), B::read(tokens[1]), C::read(tokens[2]), D::read(tokens[3]))
    }
}

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

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

    int N, P;
    string S;
    cin >> N >> P >> S;

    long long cnt = 0;
    if (P == 2 || P == 5) {
        for (int i = N - 1; i >= 0; i--) {
            if ((S[i] - '0') % P == 0)
                cnt += i + 1;
        }
    } else {
        map<int, int> m;
        m[0] = 1;
        for (int i = N - 1, b = 1, rem = 0; i >= 0; i--) {
            rem = ((S[i] - '0') * b + rem) % P;
            b = b * 10 % P;
            map<int, int>::iterator sameRem = m.find(rem);
            if (sameRem == m.end())
                m[rem] = 1;
            else {
                cnt += sameRem->second;
                sameRem->second++;
            }
        }
    }
    cout << cnt << '\n';

    return 0;
}

Measured memory_bytes: 916
/*
[diverta2019] D - DivRem Number
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;

ll N;
vector<pli> fac;

ll solve() {
    vector<ll> divs;
    for (ll i = 1; i * i <= N; i++) {
        if (N % i == 0) {
            divs.push_back(i);
            if (i * i != N) {
                divs.push_back(N / i);
            }
        }
    }

    ll ans = 0;
    for (ll d : divs) {
        ll m = d - 1;
        if (m > 0 && (N / m == N % m)) {
            ans += m;
        }
    }

    return ans;
}

int main() {
    cin >> N;

    cout << solve() << endl;

    return 0;
}


Measured memory_bytes: 384
w=input()
lst=[]
flag = 0
for i in w:
    lst.append(i)

for i in range(len(w)):
    if lst[i] == 99:
        continue
    c = 1
    j = i + 1
    while j < len(w):
        if lst[i] == lst[j]:
            lst[j] = 99
            c += 1
        j += 1
    if c % 2 != 0:
        print("No")
        flag = 1
        break

if flag == 0:
    print("Yes")


Measured memory_bytes: 9064
#include <bits/stdc++.h>
using namespace std;
int main(){
int N,K;  
  cin>>N>>K;
vector<int>v(N,0 );
  for(int i=0;i<K;i++){
    	int d=0;
    	cin>>d;
  	for(int j=0;j<d;j++){
    	int a;
      	cin>>a;
      	v.at(a-1)++;
    }
  }
  int count=0;
  for(int i=0;i<v.size();i++){
  	if(v.at(i)==0 ){
    	count++;
    }
  }
  
  cout<<count<<endl;
}

Measured memory_bytes: 3612
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<algorithm>
#include<cmath>
#include<set>
using namespace std;

int main(){
    string str;
    cin>>str;
    int N=str.size();
    int numT=0;
    int numS=0;
    for(int i=0;i<N;i++){
        if(str[i]=='T'){
            if(numS==0){
                numT++;
            }else{
                numS--;
            }
        }else{
            numS++;
        }
    }
    cout<<2*numT<<endl;
    
    
    
    
    return 0;
}


Measured memory_bytes: 640
count = 0

# 1行に複数の値が入力された場合
# 分割した配列を整数型に変換
standard = gets.split(' ').map(&:to_i)
border = standard[1]

friend = gets.split(' ').map(&:to_i)
friend.each do |num|
    if num >= border
        count = count + 1
    end
end

puts count

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

#define Fast ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)
#define FO freopen("in.txt", "r", stdin)
#define FC freopen("out.txt", "w", stdout)
#define aise cout<<"aise"<<endl
#define pb push_back
#define mp make_pair
#define ll long long
#define mset(v, a) memset(v, a, sizeof(v))
#define pll pair< ll, ll >
#define ff first
#define ss second
#define pi acos(-1.0)
#define mxN 100010
#define inf 1e9

int main()
{

    ll n, m;
    cin >> n >> m;
    vector<ll> v;
    for(ll i =0; i < n; i++) v.pb(-1);
    for(ll i = 0; i < m; i++)
    {

        ll s, c;
        cin >> s >> c;
        s--;
        if(v[s] != -1 && v[s] != c)
        {

            cout << -1;
            return 0;
        }
        else v[s]=c;
    }
    for(ll i = 0; i < v.size(); i++)
    {

        if(i==0 && v[i] == -1) v[i]=1;
        else if(v[i] == -1) v[i]=0;
    }
    if(v[0] ==0 && n != 1)
    {

        cout << -1;
        return 0;
    }
    if(n == 1 && m==0) cout << 0;
    else for(ll i = 0; i < v.size(); i++) cout << v[i];
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue> 
#include <stack>

using namespace std;
typedef long long ll;
#define rep(i, s, e) for (int(i) = (s); (i) <= (e); ++(i))
#define all(x) x.begin(),x.end()

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

int main()
{
	int n, X; cin >> n >> X;
	vector<int> x(n);
	rep(i, 0, n - 1)cin >> x[i];
	sort(all(x));
	vector<int> dist(n - 1);
	rep(i, 0, n - 2)
	{
		dist[i] = x[i + 1] - x[i];
	}
	int res = abs(X-x[0]);
	rep(i, 0, n - 2)
	{
		res = gcd(res, dist[i]);
	}
	cout << res << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <cstring>
#include <set>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <queue>
#include <deque>
#include <map>
#include <stack>
using namespace std;
#define ll long long
#define pb push_back
#define pp pair<long long,long long>
#define ppp pair<long long, pair<long long,long long> >
#define f first	
#define s second
#define pd pair<double,long long>
ll barr[200100],M=998244353;
void solveTestCase() {
	ll n,i,j,k,l;
	cin>>n>>k;
	vector<pp> arr(k+1);
	for (i=1;i<=k;i++)
		cin>>arr[i].f>>arr[i].s;
	barr[1]=1;
	barr[2]=-1;
	for (i=1;i<=n;i++) {
		barr[i]+=barr[i-1];
		barr[i]%=M;
		if (!barr[i])
			continue;
		for (j=1;j<=k;j++) {
			if (i+arr[j].f<=n) {
				barr[i+arr[j].f]+=barr[i];
				barr[i+arr[j].f]%=M;
			}
			if (i+arr[j].s+1<=n) {
				barr[i+arr[j].s+1]+=(M-barr[i]);
				barr[i+arr[j].s+1]%=M;
			}
		}
	}
	cout<<barr[n]<<'\n';
}
int main() {
	ll t,n,i,j,k,l,m;
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	ll p;
	t=1;
	//cin>>t;
	for (ll T=1;T<=t;T++) {
		solveTestCase();
	}
	return 0;
}

Measured memory_bytes: 5220
#解答例
N,M=map(int,input().split())
A=list(map(int,input().split()))#使える数字の種類
weight=[0,2,5,5,4,5,6,3,7,6]#作るのに何本必要か、また0は作れないので0になっている
dp=[-1]*(N+1)#とりあえずこれくらい確保しておけばok
dp[0]=0#0本では0しか作れない
#dp[i]はちょうどi本で作れる最高の数を入れることにする
for i in range(N+1):#N本あるから、一本ずつ増やしていって最大N本
    if dp[i] == -1:continue
    for a in A:
        if i+weight[a]<N+1:#今あるi本にa本を加えてもN本を超えないか
            dp[i+weight[a]]=max(dp[i+weight[a]],dp[i]*10+a)#今まで作ったi+weight[a]のときのdpの値と、今作ったdp[i]*10+aの値を比べ、大きい方を格納する
                                                           #なぜdp[i]*10+aになるのかに関しては、右から数字を追加していく場合のみを考えることで、重複せずに全通り試せるから#もし一通りもなかった場合、-1が格納されたままになるため問題がない
print(dp[N])

Measured memory_bytes: 14692