akhauriyash/Code-Regression huggingface dataset:
import sys
import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

Bsize = 1333

def Mo_argsort(LR):
    L = LR[:, 0]
    R = LR[:, 1]
    key1 = L // Bsize
    key2 = np.where(key1 & 1, -R, R)
    key = (key1 << 32) + key2
    return np.argsort(key)

def main(A, LR):
    N = len(A)
    Q = len(LR)
    ind = Mo_argsort(LR)
    count = np.zeros(N + 1, np.int64)
    ans = 0

    def add(x):
        nonlocal ans
        if not count[x]:
            ans += 1
        count[x] += 1

    def rem(x):
        nonlocal ans
        count[x] -= 1
        if not count[x]:
            ans -= 1

    answers = np.empty(Q, np.int64)
    nl, nr = 0, 0
    for i in ind:
        l, r = LR[i]
        l -= 1
        # 区間 [l, r) に対する計算
        while nl > l:
            nl -= 1
            add(A[nl])
        while nr < r:
            add(A[nr])
            nr += 1
        while nl < l:
            rem(A[nl])
            nl += 1
        while nr > r:
            nr -= 1
            rem(A[nr])
        #  答を求めて ans[i] に格納する
        answers[i] = ans
    return answers

if sys.argv[-1] == 'ONLINE_JUDGE':
    import numba
    from numba.pycc import CC
    i4 = numba.int32
    i8 = numba.int64
    cc = CC('my_module')

    def cc_export(f, signature):
        cc.export(f.__name__, signature)(f)
        return numba.njit(f)

    Mo_argsort = cc_export(Mo_argsort, (i8[:,:],))
    main = cc_export(main, (i8[:], i8[:, :]))
    cc.compile()

from my_module import main

N, Q = map(int, readline().split())
A = np.array(readline().split(), np.int64)
LR = np.array(read().split(), np.int64).reshape(Q, 2)

ans = main(A, LR)
print('\n'.join(map(str, ans.tolist())))


Measured memory_bytes: 102256
#include <iostream>
#include <cmath>

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

	int a[ 100 ];
	float sum = 0;
	for( int i = 0; i < n; i++ ) {
		std::cin >> a[ i ];
		sum = sum + a[ i ];
	}

	int avr = std::round( sum / n );

	int psum = 0;
	for( int i = 0; i < n; i++ ) {
		psum += ( a[ i ] - avr ) * ( a[ i ] - avr );
	}

	std::cout << psum << std::endl;
	return 0;
}


Measured memory_bytes: 256
import math
def facts(n):
    ans = []
    for  i in range(1, int(math.sqrt(n)+1)):
        if(n%i==0):
            ans.append(i)
            ans.append(n//i)
    ans = sorted(ans)
    return ans


n,m, x = map(int, input().split())
arr = []
narr = [0 for i in range(m)]
ans = 123456789
for i in range(n):
    tarr = list(map(int, input().split()))
    arr.append(tarr)
for i in range(1<<n):
    tarr = list(narr)
    cost = 0
    for a in range(n):
        if((i>>a)&1):
            cost+=arr[a][0]
            for b in range(1, m+1):
                tarr[b-1] += arr[a][b]
    ok = True
    for i in range(m):
        if(tarr[i]<x):
            ok = False
            break
    if(ok):
        ans = min(ans, cost)
if(ans == 123456789):
    print(-1)
else:
    print(ans)


Measured memory_bytes: 74484
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for (ll i = 0; i < (n); ++i)
const ll mod = 1000000007;
const ll INF = 9223372036854775807;
#define Sort(a) sort(a.begin(), a.end())
#define Reverse(a) reverse(a.begin(), a.end())
#define Pi acos(-1)

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << setprecision(15) << fixed;
  ll n;
  cin >> n;
  vector<pair<ll,ll>> p(n); 
  rep(i,n) {
    ll a, b;
    cin >> a >> b;
    p[i] = {b,a};
  }
  Sort(p);
  ll nt = 0;
  rep(i,n) {
    nt += p[i].second;
    if (nt > p[i].first) {
      cout << "No\n";
      return 0;
    }
  }
  cout << "Yes\n";
}

Measured memory_bytes: 6348
l, r = map(int, input().split())
l_mod2019 = l % 2019
r_mod2019 = r % 2019
x_list = [2019]
if r - l >=2018 or l_mod2019 >= r_mod2019:
    print(0)
else:
    for i in range(l_mod2019, r_mod2019):
        for j in range(l_mod2019 + 1, r_mod2019 + 1):
            if i < j:
                x = (i * j) % 2019
                if x < min(x_list):
                    x_list.append(x)
                else:
                    pass
            else:
                pass
    print(x_list[-1])





Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <string>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <stack>
#include <set>
#include <queue>
#include <algorithm>
#include <deque>
using namespace std;

#define INF 1e18
#define int long long

signed main() {
    vector<vector<int>> c(3, vector<int> (3));
    for(int i = 0; i < 3; i++) {
        for(int j = 0; j < 3; j++) {
            cin >> c[i][j];
        }
    }

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

    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
bool isPrime(int k){
	if(k<2)return false;
	for(int i=2;i*i<=k;i++){
		if(k%i==0)return false;
	}
	return true;
}
int main(){
	int n,cnt=0;
	scanf("%d",&n);
	while(n--){
		int k;
		scanf("%d",&k);
		cnt += isPrime(k); 
	}
	cout<<cnt<<endl;
	return 0;
}


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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pld;

#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define INPUTL(i,n) for(ll i=0 ; i<n ; i++)
const int MOD = 1000000007 ; //  , 1000000009 , 1000000023 ,998244353
const ll INF = (1e18);
const ld PI = 4*atan((ld)1);
int MAX = MOD;
void array_debug(vector<ll>ar){
    for(auto x: ar)cout << x << ' ';
    cout << '\n';
}
ll power(ll x,ll n)
{
    ll result=1;
    while(n>0){
        if(n&1)result = (result * x)%MOD;
        x=(x*x)%MOD;
        n >>= 1;
    }
    return result%MOD;
}
ll gcd(ll a , ll b){
  if(b==0)return a;
  return gcd(b,a%b);
}

int main() {
    #ifdef AVI  
        freopen("input.txt" , "r" , stdin);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.precision(20);
    
   
    ll n;
    cin >> n;
    vector<ll>ar(n);
    for(auto &x:ar)cin >> x;
    vector<ll>dp(n);
    if(n==2){
      cout << abs(ar[0]-ar[1]);
      return 0;
    }
    dp[0] = 0 , dp[1] = abs(ar[1] - ar[0]) ;
    for(ll i=2 ; i<n ; i++){
      dp[i] = min(dp[i-1] + abs(ar[i-1]-ar[i]),dp[i-2] + abs(ar[i-2]-ar[i]));
    }
    cout << dp[n-1];
}

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

using namespace std;

#define ll long long
#define ld long double
#define P pair<ll, ll>

#define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++)

#define all(v) v.begin(), v.end()

#define sortAl(v) sort(all(v))
#define sortAlr(v)                                                             \
  sort(v.begin(), v.end());                                                    \
  reverse(v.begin(), v.end())

#define cout(n) cout << fixed << setprecision(n)

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

template <class T> inline void chmax(T &a, T b) { a = std::max(a, b); }
template <class T> inline void chmin(T &a, T b) { a = std::min(a, b); }

#define mod (int)(1e9 + 7)
#define INF LLONG_MAX

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

  ll n, m;
  cin >> n >> m;

  vector<ll> a(n);
  rep(i, n) { cin >> a[i]; }

  vector<ll> dp(n);
  map<ll, ll> rem_map;

  dp[0] = a[0] % m;
  rem_map[dp[0]]++;

  REP(i, n) {
    dp[i] = dp[i - 1] + a[i];
    dp[i] %= m;
    rem_map[dp[i]]++;
  }

  ll sum = 0;
  ll ans = 0;
  rep(i, n) {
#if 0
    for (ll k = i; k < n; k++) {
      if (dp[k] == sum) {
        ans++;
      }
    }
#else
    // keyが存在する場合
    auto itr = rem_map.find(sum);
    if (itr != rem_map.end()) {
      ans += itr->second;
    }
    rem_map[dp[i]]--;
#endif
    sum += a[i];
    sum %= m;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 5760
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iomanip>
#define ll long long
using namespace std;

int N;

void dfs(string s, char mx)
{
  if (s.length() == N)
  {
    cout << s << endl;
  }
  else
  {
    for (char c = 'a'; c <= mx; c++)
    {
      dfs(s + c, (mx == c) ? mx + 1 : mx);
    }
  }
}

int main()
{
  cin >> N;
  dfs("", 'a');
  return 0;
}


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

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

  vector<ll> L(N+1);
  L.at(0) = 2;
  L.at(1) = 1;

  for(int i=2; i<= N; i++){
    L.at(i) = L.at(i-1) + L.at(i-2);
  }

  cout << L.at(N) << endl;
}


Measured memory_bytes: 256
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
#import math
from itertools import product, accumulate, combinations, product
#import bisect
#import numpy as np
#from copy import deepcopy
#from collections import deque
#from decimal import Decimal
#from numba import jit

INF = 1 << 50
EPS = 1e-8
mod = 10 ** 9 + 7

def run():
    N = int(input())
    nines = [9 ** i for i in range(1, 10) if 9 ** i <= N]
    sixes = [6 ** i for i in range(1, 10) if 6 ** i <= N][::-1]
    L = len(nines)
    #print(nines, sixes)
    min_ans = INF
    for K in product(range(9), repeat = L):
        #print(K, '----------------')
        ans = 0
        s = 0
        for k, x in zip(K, nines):
            if k:
                ans += k
                s += x * k
        #print(ans, s)

        if s > N:continue
        resid = N - s
        #print(resid)
        for six in sixes:
            #print(resid)
            tmp = resid // six
            if tmp:
                ans += tmp
                resid -= six * tmp
        #print(resid, ans)
        #if resid >= 6:
        #    print(resid)
        ans += resid
        min_ans = min(min_ans,ans)

    print(min_ans)

if __name__ == "__main__":
    run()


Measured memory_bytes: 9172
import * as fs from "fs";

function checkKaibun(str: string): boolean {
	for (let i = 0; i < Math.floor(str.length / 2); i++) {
		if (str[i] !== str[str.length - 1 - i]) return false;
	}
	return true;
}

const input = (fs.readFileSync("/dev/stdin", "utf8") as string).split("\n");
const s = input[0];

const n = s.length;
if (checkKaibun(s) && checkKaibun(s.substring(0, (n - 1) / 2)) && checkKaibun(s.substring((n + 3) / 2 - 1, n))) {
	console.log('Yes');
} else {
	console.log('No');
}


Measured memory_bytes: 11468
#include<bits/stdc++.h>
using namespace std;
#define sync ios_base::sync_with_stdio(false), cin.tie(NULL)
#define F first
#define S second
#define eb emplace_back
#define pb emplace_back
#define mt make_tuple
#define gcd __gcd
#define PI 3.141592653589
// Input
#define in(a) scanf("%d",&a)
#define in2(a,b) scanf("%d%d",&a,&b)
#define in3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define llin(a) cin >> a
#define inl(a) scanf("%lld",&a)
#define read(v,i,n) for(i=0;i<n;i++)in(v[i])
#define twod(mat,i,j,n,m) rep(i,n){rep(j,m)in(mat[i][j]);}
#define sc(ch) scanf("%c",&ch)
#define sstr(str) scanf("%s",str)
// Output
#define pr(a) printf("%d ",a)
#define pr2(a,b) printf("%d %d\n",a,b)
#define pr3(a,b,c) printf("%d %d %d\n",a,b,c)
#define out(a) printf("%d\n",a)
#define outl(a) printf("%lld\n",a)
#define llpr(a) cout << a << " "
#define llout(a) cout << a << "\n"
#define yes printf("YES\n")
#define no printf("NO\n")
#define lin printf("\n")
// Iterator
#define lp(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) for(i=0;i<n;i++)
#define all(vec) vec.begin(),vec.end()
#define lower(v,k) lower_bound(v.begin(),v.end(),k)-v.begin()
#define upper(v,k) upper_bound(v.begin(),v.end(),k)-v.begin()
#define tf(mytuple) get<0>(mytuple)
#define ts(mytuple) get<1>(mytuple)
#define tt(mytuple) get<2>(mytuple)
// Debug
#define dbg(v,i,n) for(i=0;i<n;i++)pr(v[i]); lin
#define what(x) cerr << #x << " : " << x << "\n"
#define ck printf("continue\n")
#define debug(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args)
{
	cerr << *it << " = " << a << "\n";
	err(++it, args...);
}
// Data Type
#define ll long long int
#define ii pair<int,int>
#define pli pair<ll,int>
#define state tuple<int,int,int>
#define vi vector<int>
#define vii vector<pair<int,int> >
#define vvi vector<vector<int> >
#define viii vector<pair<pair<int,int>,int> >
#define vvii vector<vector<pair<int,int> > >
#define M 1000000007
#define B 300  //check the limits, man
#define N 100003
const ll INF = 1e18;
int main()
{
    int i,n;
    string str;
    llin(str);
    n=1+str.size();
    vi v(n,0);
    rep(i,n-1)
    {
        if(str[i]=='<')
            v[i+1]=max(v[i+1],v[i]+1);
    }
    for(i=n-2;i>=0;i--)
    {
        if(str[i]=='>')
            v[i]=max(v[i],v[i+1]+1);
    }
    ll ans=0;
    ans=accumulate(all(v),ans);
    llout(ans);
}




Measured memory_bytes: 2820
#include <bits/stdc++.h>
 
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n) for(int i=1;i<=(n);i++)
#define lol long long
#define SUM(n) ((n)+1)*(n)/2 //1〜nまでの総和を求める式
#define mp make_pair
#define fi first
#define se second
#define pu push_back
#define SYOU(x) fixed<<setprecision(x+1) //小数点桁数を指定する
#define abs(x,y) max(x,y)-min(x,y)
#define all(v) v.begin(),v.end()
#define UPDight(a,b) (a+b-1)/b //小数点切り上げ 
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const int MOD=int(1e9)+7; 
using namespace std;
using pii = pair<int, int>;
typedef vector<int> vit;

//最大公約数
lol gcd(lol x, lol y){
  if(x < y) swap(x, y);
  lol r = x % y;
  while(r != 0){
    x = y;
    y = r;
    r = x % y;
  }
  return y;
}

//最小公倍数
lol lcm(lol x, lol y){
  lol a = x * y;
  return (a / gcd(x, y));
}

signed main(void){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);

  int a, b, c, x, y;
  cin >> a >> b >> c >> x >> y;
  cout << min({a * x + b * y, min(x, y) * 2 * c + (x - min(x, y)) * a + (y - min(x, y)) * b, 2 * c * max(x, y)}) << '\n';
  return 0;
}


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

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(10)

using namespace std;

typedef pair<int, int> P;

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

    int N, K;
    cin >> N >> K;

    int ans = 0;
    REP(i, N) {
        if (i % 2 == 1) continue;
        ans++;
    }
    cout << (ans >= K ? "YES" : "NO") << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		int n = sc.nextInt();
		int x = sc.nextInt();
		int min = Integer.MAX_VALUE;
		int t;
		for (int i = 0; i < n; i++) {
			t = sc.nextInt();
			x = x - t;
			min = Math.min(min, t);
		}
		System.out.println(x / min + n);
	}
}


Measured memory_bytes: 23764
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
int a[5];
int b;
b=0;
while(b<5){
cin >>a[b];
b=b+1;}
sort(a,a+5);
b=0;
while(b<5){
cout <<a[4-b];
if(b==4){cout <<endl;}
else{cout <<" ";}
b=b+1;}}

Measured memory_bytes: 1180
#include <bits/stdc++.h>
#define mp make_pair
#define x first
#define y second
#define pb push_back

using namespace std;

typedef long long ll;

int pref[300005], suf[300005];

int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(0); cin.tie(0);
    string s;
    int n;
    cin >> n >> s;
    pref[0] = (s[0] == 'E');
    for (int i = 1; i < n; i++)
        pref[i] = pref[i - 1] + (s[i] == 'E');
    for (int i = n - 1; i >= 0; i--)
        suf[i] = suf[i + 1] + (s[i] == 'W');

    int ans = n - 1 - suf[1];
    ans = min(ans, n - 1 - pref[n - 2]);
    for (int i = 1; i < n - 1; i++)
        ans = min(ans, n - 1 - pref[i - 1] - suf[i + 1]);
    cout << ans;
    return 0;
}


Measured memory_bytes: 2964
#include <iostream>

using namespace std;

int main()
{
    int r;
    cin>>r;
    if(r>=0&&r<1200){cout<<"ABC"<<endl;}
    else if(r<2800){cout<<"ARC"<<endl;}
    else if(r<=4208)cout<<"AGC"<<endl;

    //cout << "Hello world!" << endl;
    return 0;
}


Measured memory_bytes: 256
count = int(input());
data = [int(n) for n in input().split(" ")];

def bubble_sort(data):
    count = len(data);
    o = 0;
    for i in range(count):
        for j in range(count - 1, i, -1):
            if data[j] < data[j - 1]:
                o += 1;
                temp = data[j];
                data[j] = data[j - 1];
                data[j - 1] = temp;
    show(data);
    print(o);

def show(data):
    print(" ".join(str(n) for n in data));

bubble_sort(data);


Measured memory_bytes: 5604
#include<bits/stdc++.h>
using namespace std;
int main(){
int a,b,c,x;
cin>>a>>b>>c>>x;
int count=0;
for(int i=0;i<=a;i++){
    for (int j=0;j<=b;j++){
        for(int k=0;k<=c;k++){
             if(500*i+100*j+50*k==x)
                count=count+1;
}
}
}
cout<<count<<endl;
return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
using namespace std;
#define int long long
int k,head[5002000],tot,dis[5000020],dl[5000020];
bool vis[5000200];
struct node{
	int t,nxt,w;
}e[5000020];
void add(int u,int v,int dis){
	e[++tot].t=v;
	e[tot].w=dis;
	e[tot].nxt=head[u];
	head[u]=tot;
}
void spfa(){
    int head1=1,tail=1;
    memset(dis,127/3,sizeof(dis));
    dl[1]=1;//模拟队列
    vis[1]=1;dis[1]=0;
    for(int v=1;head1<=tail;vis[v]=0,v=dl[++head1])//另类写法
        for(int p=head[v];p;p=e[p].nxt)
            if(dis[e[p].t]>dis[v]+e[p].w){
                dis[e[p].t]=dis[v]+e[p].w;
                if(!vis[e[p].t]) vis[e[p].t]=1,dl[++tail]=e[p].t;
            }
}
signed main(){
	scanf("%lld",&k);
	for(int i=1;i<k;i++){
		add(i,i*10%k,0);
		add(i,(i+1)%k,1);
	}
	spfa();
	printf("%lld",dis[0]+1);
	return 0;
}


Measured memory_bytes: 57856
n = int(input())
a_list = list(map(int,input().split()))
count = 0
for j in range(30):
  frag = True
  for a in a_list:
    if a % 2 !=0:
      frag = False
  if frag == False:
    print(count)
    break
  else:
    count += 1
    for i in range(n):
      a_list[i] = a_list[i]//2
      
    

  

Measured memory_bytes: 3060
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int H = sc.nextInt();
        int W = sc.nextInt();
        int K = sc.nextInt();
        int[][] S = new int[H][W];
        for (int i=0;i<H;i++) {
            String tmp = sc.next();
            for (int j=0;j<W;j++) {
                S[i][j] = (int)(tmp.charAt(j)-48);
            }
        }

        int max = 1_000_000_000;

        for (int i=0;i<(1<<(H-1));i++) {
            int[] arr = new int[H-1];
            int tmp = i;
            int h_cut = 0;
            for (int j=0;j<H-1;j++) {
                arr[j] = tmp%2;
                h_cut+=arr[j];
                tmp/=2;
            }
            ArrayList<HashSet<Integer>> list = new ArrayList<HashSet<Integer>>();
            HashSet<Integer> set = new HashSet<Integer>();
            set.add(0);
            for (int j=0;j<H-1;j++) {
                if (arr[j]==0) set.add(j+1);
                else {
                    list.add(set);
                    set = new HashSet<Integer>();
                    set.add(j+1);
                }
            }
            list.add(set);
            // System.out.println(Arrays.toString(arr));
            // System.out.println(list);

            int n = list.size();
            int[] white_tmp = new int[n];
            boolean[] cut_flag = new boolean[W];
            int cut_cnt = 0;
            boolean flgg = false;
            for (int j=0;j<W;j++) {
                boolean exit = false;
                loop:for (int k=0;k<n;k++) {
                    for (Integer h : list.get(k)) {
                        if (S[h][j]==1) {
                            white_tmp[k]++;
                            if (white_tmp[k]>K) {
                                cut_cnt++;
                                Arrays.fill(white_tmp, 0);
                                exit = true;
                                if (cut_flag[j]) {
                                    flgg = true;
                                    cut_cnt = 1_000_000_000;
                                    break loop;
                                }
                                cut_flag[j] = true;
                                break loop;
                            }
                        }
                    }
                }
                if (flgg) {
                    break;
                }
                if (exit) j--;
            }
            max = Math.min(max, h_cut+cut_cnt);
        }
        System.out.println(max);
    }
}

Measured memory_bytes: 62212
n = int(input())
data = []
for i in range(n):
    a = input().split()
    a[1] = int(a[1])
    a += [i+1]
    data.append(a)

data = sorted(data, key=lambda x: (x[0], -x[1]))

ans = [i[2] for i in data]
for i in ans: print(i)

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

#define fast ios::sync_with_stdio(false);cin.tie(0); cout.tie(0)

typedef long long ll;
const ll inf = (ll)1e14;
const ll N = (ll)2e5;

ll n,m,k;
ll a[N];

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

    ll ans = 0;
    for (int i = 0; i < N - 2; i++) {
        ll c = i - 1 >= 0 ? a[i - 1] : 0;
        c += a[i];
        c += a[i + 1];
        ans = max(ans, c);
    }
    cout << ans << endl;
    return 0;
}

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


int main()
{
	stringstream ss;
    // 入力
    string S;
  	cin>>S;
    int price=700;
    for(int i=0;i<3;i++){
    	if(S[i]=='o') price +=100;
    }
    cout<<price<<endl;
    return 0;
}

Measured memory_bytes: 764
"角角画伯，かく悩みき"

# それぞれの座標を記録していく（一度設置したタイルの座標が変わることはない）

while True:
    N = int(input())
    if N == 0:
        break
    tile_coodinates = {}
    tile_coodinates[0] = (0, 0)
    for i in range(1, N):
        n, d = map(int, input().split())
        if d == 0:
            tile_coodinates[i] = (tile_coodinates[n][0]-1, tile_coodinates[n][1])
        if d == 1:
            tile_coodinates[i] = (tile_coodinates[n][0], tile_coodinates[n][1]-1)
        if d == 2:
            tile_coodinates[i] = (tile_coodinates[n][0]+1, tile_coodinates[n][1])
        if d == 3:
            tile_coodinates[i] = (tile_coodinates[n][0], tile_coodinates[n][1]+1)

    zahyou_list = list(tile_coodinates.values())

    min_x = 300
    max_x = -300
    min_y = 300
    max_y = -300

    for x, y in zahyou_list:
        min_x = min(min_x, x)
        max_x = max(max_x, x)

        min_y = min(min_y, y)
        max_y = max(max_y, y)

    print(max_x-min_x+1, max_y-min_y+1)



Measured memory_bytes: 5652
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+5;
ll apple[3*N];
bool cmp(ll a,ll b){
    return a>b;
}
int main(){
    int x,y,a,b,c;
    cin>>x>>y>>a>>b>>c;
    for(int i=0;i<a;i++){
        cin>>apple[i];
    }
    sort(apple,apple+a,cmp);
    for(int i=x;i<x+b;i++){
        cin>>apple[i];
    }
    sort(apple+x,apple+x+b,cmp);
    for(int i=x+y;i<x+y+c;i++){
        cin>>apple[i];
    }
    sort(apple,apple+x+y+c,cmp);
    ll sum=0;
    for(int i=0;i<x+y;i++) sum+=apple[i];
    cout<<sum<<endl;
}


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

using namespace std;

int aa[] = { 0, 1, 1, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8 };

long long n;
int ans;

void add(long long p) {
	int k = 0;
	while (n % p == 0)
		k++, n /= p;
	ans += aa[k];
}

int main() {
	cin >> n;
	for (long long p = 2; p <= n / p; p++)
		add(p);
	if (n > 1)
		add(n);
	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 3612
#include<iostream>
#include<cmath>
#include<cstdio>
using namespace std;

int main(){
    double x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    double d = sqrt( (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));
    printf("%lf\n", d);
    
    return 0;
}


Measured memory_bytes: 3264
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;

class Program
{
    static void Main(string[] args)
    {
        var nx = Array.ConvertAll(ReadLine().Split(' '), long.Parse);
        //for (var i = 1; i <= 13; i++) WriteLine(Get(2, i));
        WriteLine(Get(nx[0], nx[1]));
    }
    private static long Get(long num,long x)
    {
        if (num == 0) return x<=0?0:1;
        if (x == (long)Pow(2, num+1)-1)
            return (long)Pow(2, num);
        else if (x > (long)Pow(2, num+1) - 1)
            return (long)Pow(2, num) + Get(num - 1, x - (long)Pow(2, num+1) + 1);
        else return Get(num - 1, x-1);
    }
    private const string ALFA = "abcdefghijklmnopqrstuvwxyz";
    private const int MOD = 1000000007;
}


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

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;
// not that imp
typedef pair<pll, ll> plll;
typedef vector<ll> vl;
typedef vector<pll> vll;

#define pb push_back
#define bitc  __builtin_popcountl
#define mp make_pair
#define ff first
#define ss second

#define swap(a,b) {a=a^b;b=a^b;a=a^b;}
#define fr(i,a,b) for (ll i = (a), _b = (b); i <= _b; i++)
#define rep(i,n) for (ll i = 0, _n = (n); i < _n; i++)
#define repr(i,n) for (ll i = n - 1; i >= 0; i--)
#define frr(i,a,b) for (ll i = (a), _b = (b); i >= _b; i--)

#ifdef bhartiya
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
#define start_routine() int begtime = clock();
#define end_routine() int endtime = clock(); \
					  cout << "\n\nTime elapsed: " << (endtime - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
}
#else
#define endl '\n'
#define trace(...)
#define start_routine()
#define end_routine()
#endif

#define inf 200000000000000ll
#define mod 1000000007ll
#define eps 1e-7

ll gcd(ll a, ll b){ return b==0 ? a : gcd(b, a%b); }
const ll maxn = 105;
ll a[maxn];
ll dp[maxn][100005];
bool vis[maxn][100005];

ll recur(ll ind, ll k){
    // trace(ind, k);
    if(k<0 || ind <0) return 0;
    // if(k == 0) return 1;
    if(ind == 0) return min(k+1, a[0]+1);
    if(vis[ind][k]) return dp[ind][k];
    vis[ind][k] = true;
    ll ans = 0;
    ans = (recur(ind-1,k) - recur(ind-1,k-a[ind]-1) + mod)%mod;
    ans =  (ans + recur(ind, k-1))%mod;
    return dp[ind][k] = ans;
}

int main()
{ 
    start_routine();
	ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.precision(10);
    cin.exceptions(cin.failbit);
    #ifdef bhartiya
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    int t = 1;
    // cin>>t;
    while(t--){
        ll n,k,x,m,y;
        cin>>n>>k;
        rep(i,n){
            cin>>a[i];
        }
        cout<<(recur(n-1,k) - recur(n-1,k-1) + mod)%mod;
    }
    end_routine();
}


Measured memory_bytes: 94976
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<long>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
using pll = pair<long, long>;
#define fix20 cout << fixed << setprecision(20);
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define MOD 1000000007
#define all(vec) vec.begin(), vec.end()

bool same(vi x, vi y){
    rep(i,x.size()){
        if(x.at(i) != y.at(i)) return false;
    }
    return true;
}

int main(){
    int n;
    cin >> n;
    vector<int> data(n);
    rep(i,n) data.at(i) = i+1;
    vector<int> p(n);
    vector<int> q(n);
    rep(i,n) cin >> p.at(i);
    rep(i,n) cin >> q.at(i);
    int cnt = 0;
    int P;
    int Q;
    do{
        if(same(data,p)) P = cnt;
        if(same(data,q)) Q = cnt;
        cnt++;
    }while(next_permutation(all(data)));
    cout << abs(P-Q) << endl;
}

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

int main(){
    int N, K;
    bool is_ng_num[10] = {false};
    scanf("%d%d", &N, &K);
    for(int i = 0; i < K; ++i){
        int tmp;
        scanf("%d", &tmp);
        is_ng_num[tmp] = true;
    }
    do{
        char str[5];
        bool flag = true;
        sprintf(str, "%d\n", N);
        for(int i = 0; i < strlen(str); ++i){
            if(is_ng_num[str[i] - '0']){
                flag = false;
                break;
            }
        }
        if(flag){
            printf("%d\n", N);
            break;
        }
    }while(++N);

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
typedef vector<unsigned int>vec;
typedef vector<vec> mat;
typedef vector<vector<int>> Graph;

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-10;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

template< typename T >
size_t LIS(const vector< T > &a, bool strict) {
  vector< T > lis;
  for(auto &p : a) {
    typename vector< T >::iterator it;
    if(strict) it = lower_bound(begin(lis), end(lis), p);
    else it = upper_bound(begin(lis), end(lis), p);
    if(end(lis) == it) lis.emplace_back(p);
    else *it = p;
  }
  return lis.size();
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<int> A(N);
    REP(i,N) cin >> A[i];
    reverse(A.begin(),A.end());
    cout << LIS(A, false) << endl;
}


Measured memory_bytes: 1276
// jha4032

#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long int 
#define mp make_pair
#define M 1000000007
#define N 1000006
void fast()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}

ll power(ll a, ll b)
{
  if (b == 0)
    return 1;
  ll tmp = power(a, b / 2)%M;
  tmp = (tmp * tmp )%M ;
  if (b & 1)
    return (tmp * a )%M ;
  return tmp;
}
ll fact[N], invfact[N];
ll ans=0;
void pre1()
{
  fact[0] = 1;
  invfact[0] = power(fact[0], M - 2);
  for (int i = 1; i < N; i++)
  {
    fact[i] = (i * fact[i - 1]) % M;
    invfact[i] = power(fact[i], M - 2);
  }
}


ll n;
ll a[100005];	
ll dp[100005];



int main(){

//dp[0]=0;
int k;
cin>>n>>k;
for(int i=0;i<n;i++){
	 cin>>a[i];dp[i]=1e15;
}
dp[0]=0;
for(int i=1;i<n;i++){
	for(int j=1;j<=k;j++)
       if(i>=j)
         dp[i]=min(dp[i],dp[i-j]+abs(a[i-j]-a[i]));
}
cout<<dp[n-1]<<endl;

}

Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main(void) {
  int n;
  vector<int> h;

  cin >> n;

  for(int i = 0; i < n; i++) {
    int hi;
    cin >> hi;
    h.push_back(hi);
  }

  int r = 0, cur = 0;
  for(int i = 1; i <= n - 1; i++) {
    if (h[i] - h[i - 1] > 0) {
      if (r < cur) r = cur;
      cur = 0;
    } else {
      cur++;
    }
  }

  if (r < cur) r = cur;
  cout << r;

  return 0;
}

Measured memory_bytes: 892
#include<iostream>
#include<cstdio>
#include<math.h>
#include <stdlib.h>
#define M 100000
using namespace std;
  
int main(){

    int n, m,l, p = 0 , result = 0;
    int x[100010];
    scanf("%d %d",&n,&m);
    x[0] = 0;
    for (int i = 1; i < n; i++){
        scanf("%d", &x[i]);
        x[i] += x[i - 1];
    }
    while (m--){
        scanf("%d", &l);
        result += abs(x[p + l] - x[p]);
        result %= M;
        p += l;
    }
    printf("%d\n", result);
}

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

# define C continue;
# define R return

# define D double
# define I insert
# define ll long long
# define ld long double

# define ull unsigned long long
# define ui unsigned int

# define pb push_back
# define pf push_front

# define vi vector < int >
# define vc vector < char >
# define vs vector < string >
# define vb vector < bool >
# define vd vector < D >
# define vll vector < ll >
# define vull vector < ull >
# define vld vector < ld >

# define vvi vector < vector < int > >
# define vvb vector < vector < bool > >
# define vvc vector < vector < char > >
# define vvll vector < vector < ll > >
# define vvd vector < vector < D > >
# define vvld vector < vector < ld > >

# define all(v) (v).begin() , (v).end()
# define allrev(v) (v).rbegin() , (v).rend()
# define allcomp(v) v.begin() , v.end() , comp
# define allrevcomp(v) v.rbegin() , v.rend() , comp

# define pii pair < int , int >
# define pll pair < ll , ll >
# define pld pair < ld , ld >
# define pDD pair < D , D >

# define vpld vector < pld >
# define vpii vector < pii >
# define vpll vector < pll >
# define vpDD vector < pDD >

# define vvpii vector < vector < pii > >
# define F first
# define S second
# define mp make_pair

# define fast ios_base::sync_with_stdio(false) ; cin.tie(0) ; cout.tie(0);
# define dist(a,b,p,q) sqrt((p-a)*(p-a) + (q-b)*(q-b))

# define pp(n) printf("%.10Lf",n);
# define line cout<<"\n";

const ld pie = 3.14159265358979 ;
const ll mod = 1e9 + 7 ;

string vow = "aeiou";

void solve ( int test_case )
{
    ll n ; cin >> n ;

    vi v ( n ) ;
    for ( int i=0 ; i < n ; i++ ) cin >> v[i] ;

    sort ( all ( v ) ) ;

    ll ans = 0 ;

    for ( int i=0 ; i < n ; i++ )
    {
        for ( int j = i + 1 ; j < n ; j++ )
        {
            int temp = v[i] + v[j] ;
            int ans_indx = -1 ;

            for ( int low = j + 1 , hi = n - 1 ; low <= hi ; )
            {
                int mid = low + hi >> 1 ;

                if ( temp > v[mid] )
                {
                    ans_indx = mid ;
                    low = mid + 1 ;
                }

                else hi = mid - 1 ;
            }

            if ( ans_indx != -1 )
            {
                ll val = ans_indx - (j+1) + 1 ;
                ans += val ;
            }
        }
    }

    cout << ans ; line
}

int main()
{fast
    int t = 1;
    //cin >> t;

    for ( int i=0 ; i < t ; i++ ) solve(i);
    return 0;
}


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

int main(void) {
	int x,i = 0;

	while (true)
	{
		cin >> x;

		if (x == 0)
		{
			break;
		}
		i++;
		cout << "Case " << i << ": " << x << endl;
	}

	return 0;
}


Measured memory_bytes: 3052
n = int(input()) 
num = [0,0,0,0,0]

for i in range(n):
    s = input()
    if s[0]=='M':
            num[0] += 1
    elif s[0]=='A':
            num[1] += 1
    elif s[0]=='R':
            num[2] += 1
    elif s[0]=='C':
            num[3] += 1
    elif s[0]=='H':
            num[4] += 1

num_1 = num[0]*num[1]*num[2]
num_2 = num[0]*num[1]*num[3]
num_3 = num[0]*num[1]*num[4]
num_4 = num[1]*num[2]*num[3]
num_5 = num[1]*num[2]*num[4]
num_6 = num[2]*num[3]*num[4]
num_7 = num[0]*num[2]*num[3]
num_8 = num[0]*num[2]*num[4]
num_9 = num[0]*num[3]*num[4]
num_10 = num[1]*num[3]*num[4]

answer = num_1 + num_2 + num_3 + num_4 + num_5 + num_6 + num_7 + num_8 + num_9 + num_10
print(answer)

Measured memory_bytes: 3064
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<string,int> P;
string b[500]; //レシピ情報

ll decode(string s)
{
	ll ret=0;
	for(int i=0;i<s.size();i++)
	{
		if(s[i]=='1')
			ret+=(1LL<<(ll)i);
	}
	return ret;
}

string strxor(string lhs,string rhs)
{
	int i=0;
	string ret;
	if(lhs.size()<rhs.size())
	{
		while(i<lhs.size())
		{
			if(lhs[i]==rhs[i])
				ret+='0';
			else
				ret+='1';
			i++;
		}
		while(i<rhs.size())
		{
			ret+=rhs[i];
			i++;
		}
	}else{
		while(i<rhs.size())
		{
			if(lhs[i]==rhs[i])
				ret+='0';
			else
				ret+='1';
			i++;
		}
		while(i<lhs.size())
		{
			ret+=lhs[i];
			i++;
		}
	}
	return ret;
}

vector<P> rekkyo(int l,int r)
{
	vector<P> ret;
	ret.push_back(P(string(b[0].size(),'0'),0));
	int cnt=r-l;
	for(int bit=0;bit<(1<<cnt);bit++)
	{
		auto ele=P("",0);
		for(int i=0;i<cnt;i++)
		{
			int tmp=(bit&(1<<i));
			if(tmp)
			{
				ele.second++;
				ele.first=strxor(ele.first,b[l+i]);
			}
		}
		ret.push_back(ele);
	}
	return ret;
}

int zen(int n,int m)
{
	//cerr<<string(b[0].size(),'0')<<endl;
	int ret=0;
	int cnt=0;
	vector<P> llist=rekkyo(0,n/2);
	vector<P> rlist=rekkyo(n/2,n);
	sort(rlist.begin(),rlist.end());
	for(int i=0;i<llist.size();i++)
	{
		auto itr=upper_bound(rlist.begin(),rlist.end(),P(llist[i].first,99999));
		if(itr==rlist.begin())
			continue;
		itr--;
		if((*itr).first==llist[i].first)
			ret=max(ret,llist[i].second+(*itr).second);
	}
	return ret;
}

int dp[2][1<<21];//n>=23ならm<=21
//dp[i][j]...i番目までで材料bit jを&1個にできるようなレシピの最大数
int solvedp(int n,int m)
{
	int ret=0;
	fill(dp[0],dp[2],-99999);
	dp[0][0]=0;//何も作らない場合
	for(int i=1;i<n+1;i++)
	{
		int bb=decode(b[i-1]);//数字にデコード
		//cerr<<bitset<8>(bb)<<endl;
		//今の状態に前の状態を移す
		for(int j=0;j<(1<<m);j++)
			dp[i&1][j]=dp[(i+1)&1][j];
		for(int j=0;j<(1<<m);j++)
		{
			if(dp[(i+1)&1][j]>=0)
				dp[i&1][j^bb]=max(dp[i&1][j^bb],dp[(i+1)&1][j]+1);
		}
		//前のdpテーブルの初期化
		for(int j=0;j<(1<<m);j++)
			dp[(i+1)&1][j]=-99999;
	}
	int ind=(n&1);
	ret=max(ret,dp[ind][0]);
	return ret;
}

int main()
{
	while(1)
	{
		int n,m;
		int ans=0;
		cin>>n>>m;
		if(n==0 && m==0)
			break;
		for(int i=0;i<n;i++)
			cin>>b[i];
		//nが十分小さいなら全探索
		if(n<23)
			ans=zen(n,m);
		else
			ans=solvedp(n,m); //そうでないならbitDP
		cout<<ans<<endl;
	}
	return 0;
}


Measured memory_bytes: 19868
#include <iostream>
using namespace std;
long long N, ans;

void dfs(long long x, int use) {
    if (x > N) return;
    if (use == 0b111) ans++;
    dfs(10 * x + 7, use | 0b100);
    dfs(10 * x + 5, use | 0b010);
    dfs(10 * x + 3, use | 0b001);
} 

int main() {
    cin >> N >> ans;
    dfs(0, 0);
    cout << ans << endl;
}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define LI list<int>
#define vct vector
#define vi vct<int>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vvi vct<vi>
#define vll vct<ll>
#define vvll vct<vll>
#define all(a) a.begin(),a.end()
#define mp(a,b) make_pair(a,b)
#define pb push_back
#define ff first
#define ss second
#define bg begin()
#define ft cout<<"for test"<<endl;
#define read(v,a,n) for(int i=a; i<n; i++)cin>>v[i];
#define pi 2*acos(0.0)
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define t_c int test,cs=1;cin>>test;while(test--)
#define lcm(a,b) (a*b)/__gcd(a,b)
#define inf -1
int main()
{
    FIO;

    ///freopen("in.txt","r",stdin);
    ///freopen("output.txt","w",stdout);
    int k;
    cin>>k;
    string s;
    cin>>s;
    if(s.size()<=k)
        return cout<<s<<endl, 0;
    string ss = s.substr(0,k);
    cout<<ss<<"..."<<endl;

}


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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())

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

    vi s(N);
    int total=0;
    for (int i = 0; i < N; i++) {
        cin >> s[i];
        total += s[i];
    }
    sort(all(s));

    int n10=0;
    for (int i = 0; i < N; i++) {
        if (s[i] % 10 != 0) {
            n10 = s[i];
            break;
        }
    }

    if (total % 10 == 0){
        if (n10 == 0) {
            cout << 0 << endl;
        }else{
            cout << total - n10 << endl;
        }
    }else{
        cout << total << endl;
    } return;
}

int main(int argc, char const* argv[])
{
    solve();
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd_(ll a,ll b){if(a%b==0)return b;return gcd_(b,a%b);}
ll lcm_(ll a,ll b){ll c=gcd_(a,b);return ((a/c)*(b/c)*c);}
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=ll(1e16)+ll(7);
const ll MOD=1000000007LL;
#define out(a) cout<<fixed<<setprecision((a))
//tie(a,b,c) = make_tuple(10,9,87);
#define pop_(a) __builtin_popcount((a))
ll keta(ll a){ll r=0;while(a){a/=10;r++;}return r;}
ll ketawa(ll a){ll r=0;while(a){r+=a%10;a/=10;}return r;}



ll memo[60][60];
ll com(ll n,ll r){
  if(n<r)return 0;
  if(n==r)return 1LL;
  if(r==1)return n;
  if(r==0)return 1LL;
  if(memo[n][r]) return memo[n][r];
  return memo[n][r] = com(n-1,r-1)+com(n-1,r); 
}


int main(){

  ll n,p;
  cin >> n >> p;
  ll o,t;
  o=t=0;
  FOR(i,0,n){
    ll a;
    cin >> a;
    if(a%2)o++;
    else t++;
  }

  if(p==1){
    //奇数枚食べる
    ll ans = 0;
    for(int i=1;i<o+1;i+=2){
      ans += com(o,i)*(1LL<<t);
    }
    cout << ans << endl;
  }else{
    //偶数枚食べる
    ll ans = 0;
    for(int i=0;i<o+1;i+=2){
      ans += com(o,i)*(1LL<<t);
    }
    cout << ans << endl;
  }
  
}


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

int main(void) {
    using namespace std;

    long long int n;
    cin >> n;

    long long int sum = 0;

    for (int i = 0; i < n; i++) {
        if ((i + 1) % 3 != 0 && (i + 1) % 5 != 0) {
            sum += (i + 1);
        }
    }

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

Measured memory_bytes: 3760
#include <stdio.h>

int main(void){
	int n;
	long Max,Min,i,Sum=0,A[10000];
	
	scanf("%d",&n);
	
	for(i=0;i<n;i++){
		scanf("%ld", &A[i]);
		Sum+=A[i];
	}
	
	Max=A[0];
	Min=A[0];
	for(i=1;i<n;i++){
		if(Max >= A[i]) Max+=0;
		if(Max<A[i]) Max=A[i];
		if(Min >= A[i]) Min=A[i];
		if(Min < A[i]) Min+=0;
	}

	
	printf("%ld %ld %ld\n",Min,Max,Sum);
	
	return 0;
}

Measured memory_bytes: 676
n = int(input())
nlist = list(map(int, input().split()))
alice = 0
bob = 0
for i in range(n):
    if(i%2==0):
        alice = alice + max(nlist)
    else:
        bob = bob + max(nlist)
    nlist.remove(max(nlist))
print('{}'.format(alice-bob))

Measured memory_bytes: 3060
#include<stdio.h>
int main()
{
    int x;
    scanf("%d",&x);
    int a[x+10],i,j,cnt=0;
    for(i=0;i<x;i++)
    {
        scanf("%d",&a[i]);
    }
    for(i=1;i<x-1;i++)
    {
       if(a[i]>a[i-1])
       {
           if(a[i]<a[i+1])cnt++;
       }
       else if(a[i]<a[i-1])
       {
           if(a[i]>a[i+1])cnt++;
       }
    }
    printf("%d",cnt);
}

Measured memory_bytes: 1680
import sys

def debug(x, table):
    for name, val in table.items():
        if x is val:
            print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr)
            return None

def solve():
    inf = float('inf')
    n = int(input())
    a = []

    for i in range(n):
        line = [int(i) for i in input().split()]
        line = [i if i != -1 else inf for i in line]
        a.append(line)

    
    checked = [False] * n
    d = [inf] * n
    checked[0] = True
    ans = 0
    nxt = 0

    for i in range(n - 1):
        for j in range(n):
            if a[nxt][j] < d[j]:
                d[j] = a[nxt][j]

        min_w = inf
        min_n = 0

        for j in range(n):
            if not checked[j] and d[j] < min_w:
                min_n = j
                min_w = d[j]

        checked[min_n] = True
        nxt = min_n
        ans += min_w

    # debug(d, locals())
    print(ans)



if __name__ == '__main__':
    solve()

Measured memory_bytes: 7988
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <stdio.h>
#include <complex>
#include <cstdint>
#include <tuple>

#define M_PI       3.14159265358979323846

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }
inline int readInt() { int x; scanf("%d", &x); return x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util

//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SQ(a) (a*a)
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,s,n) for(int i=s;i<(int)n;++i)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007

int main() {
	int a, b, h;
	cin >> a >> b >> h;
	cout << (a + b)*(h / 2) << endl;
	return 0;
}


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

using namespace std;

int main() {
  int N;
  cin >> N;
  vector<int> a(N + 1);
  a[0] = 1;
  for (int i = 1; i <= N; ++i) {
    cin >> a[i];
  }

  int cur = 0;
  int ret = -1;
  for (int i = 1; i <= N; ++i) {
    const int next = a[cur];
    if (a[next] == cur) {
      break;
    }
    if (a[next] == 2) {
      ret = i;
      break;
    }
    cur = next;
  }
  cout << ret << endl;
  return 0;
}

Measured memory_bytes: 640