akhauriyash/Code-Regression huggingface dataset:
//四則演算 #pragma GCC target("avx")
//並列計算 #pragma GCC optimize("O3")
//条件分岐を減らす #pragma GCC optimize("unroll-loops")
//浮動小数点演算 #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
using VS = vector<string>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);--(i))
#define each(i, a) for(auto &i : a)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x) ((y) < 0 || h <= (y) || (x) < 0 || w <= (x))
#define line cout << "-----------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10;
constexpr ld pi = 3.1415926535897932;
template<class T>inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; }return false; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& a : v)is >> a; return is; }
template<class T>inline istream& operator>>(istream& is, deque<T>& v) { for (auto& a : v)is >> a; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }
inline void print() { cout << "\n"; }
template<class T, class... Ts>inline void print(const T& a, const Ts&... ts) { cout << a << " "; print(ts...); }
template<class T>inline void print(const vector<T>& v) { for (int i = 0; i < v.size(); ++i)cout << v[i] << (i == v.size() - 1 ? "\n" : " "); }
template<class T>inline void print(const vector<vector<T>>& v) { for (auto& a : v)print(a); }
inline string reversed(const string& s) { string t = s; reverse(all(t)); return t; }

int main() {
    init();

    int n; ll k; cin >> n >> k;
    int log = log2(k);
    VI a(n); cin >> a;
    auto to = vec<int>(log + 1, n);
    FOR(i, 0, n)to[0][i] = a[i] - 1;
    FOR(j, 0, log)FOR(i, 0, n) {
        to[j + 1][i] = to[j][to[j][i]];
    }

    int ans = 0;
    for (int j = 0; k; ++j, k >>= 1) {
        if (k & 1)ans = to[j][ans];
    }
    print(ans + 1);
}


Measured memory_bytes: 51928
#include<stdio.h>
int main(){
	int i, a, b, c;
	while(scanf("%d%d", &a, &b) != EOF){
		i=0;
		c=a+b;
		while(c/10 > 0){
			i++;
			c=c/10;
		}
		printf("%d\n", i+1);
	}
	return 0;
}

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

int main()
{
    int N = 0;
    cin>>N;
    vector<string> S(N);
    for (string &s: S)
        cin>>s;

    vector<int> X(N);
    vector<int> Y(N);
    for (int i=0; i<N; i++)
    {
        int n = 0;
        for (char c: S[i])
        {
            if (c=='(')
                n++;
            else
                n--;
            X[i] = max(X[i], -n);
        }
        Y[i] = n+X[i];
    }

    vector<int> L, R;
    for (int i=0; i<N; i++)
        if (Y[i]>X[i])
            L.push_back(i);
        else
            R.push_back(i);

    sort(L.begin(), L.end(), [&](int a, int b){return X[a]<X[b];});
    int l = 0;
    for (int p: L)
    {
        if (X[p]>l)
        {
            cout<<"No"<<endl;
            return 0;
        }
        l += Y[p]-X[p];
    }
    
    sort(R.begin(), R.end(), [&](int a, int b){return Y[a]<Y[b];});
    int r = 0;
    for (int p: R)
    {
        if (Y[p]>r)
        {
            cout<<"No"<<endl;
            return 0;
        }
        r += X[p]-Y[p];
    }

    if (l!=r)
    {
        cout<<"No"<<endl;
        return 0;
    }
    cout<<"Yes"<<endl;
}


Measured memory_bytes: 38136
# 01BFS
INF = 10**9 + 7


def main():
    from collections import deque
    H, W = (int(i) for i in input().split())
    Ch, Cw = (int(i)-1 for i in input().split())
    Dh, Dw = (int(i)-1 for i in input().split())
    A = [input() for i in range(H)]

    def bfs_2d(c, sy, sx, gh, gw, H, W):
        que = deque()
        dist = [[INF]*W for i in range(H)]

        dist[sy][sx] = 0
        que.append((sy, sx))
        while que:
            uh, uw = que.popleft()
            for dh in range(-2, 3):
                for dw in range(-2, 3):
                    next_h = uh + dh
                    next_w = uw + dw
                    cost = 0 if abs(dh) + abs(dw) <= 1 else 1
                    if not(0 <= next_h < H and 0 <= next_w < W):
                        continue
                    if c[next_h][next_w] == "#":
                        continue
                    if dist[next_h][next_w] > dist[uh][uw] + cost:
                        dist[next_h][next_w] = dist[uh][uw] + cost
                        if cost == 1:
                            que.append((next_h, next_w))
                        else:
                            que.appendleft((next_h, next_w))
        return dist[gh][gw] if dist[gh][gw] != INF else -1

    ans = bfs_2d(A, Ch, Cw, Dh, Dw, H, W)
    print(ans)


if __name__ == '__main__':
    main()


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

int main(){
  int R,G,B,N; cin>>R>>G>>B>>N;
  int sum=0;
  for(int i=0;i*R<=N;i++){
    for(int j=0;i*R+j*G<=N;j++){
      if((N-i*R-j*G)%B==0){
        sum++;
      }else continue;
      
    }
  }
  cout<<sum<<endl;
}  

Measured memory_bytes: 256
N,S=map(int,input().split())
A=list(map(int,input().split()))
mod=998244353
inv=pow(2,mod-2,mod)

poly=[0 for i in range(3001)]
poly[0]=1
for i in range(N):
    for j in range(3000,-1,-1):
        if j>=A[i]:
            poly[j]=inv*poly[j-A[i]]+poly[j]
            poly[j]%=mod

res=pow(2,N,mod)*poly[S]
res%=mod
print(res)

Measured memory_bytes: 68704
/*
@author: sharrad99
*/
#include<bits/stdc++.h>
using namespace std;
int main(){

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	int n, m;
	cin >> n >> m;

	int res = (n * (n - 1)) / 2;
	res += (m * (m - 1)) / 2;
	cout << res << '\n';
}

Measured memory_bytes: 256
// Nothing Special ...
#include <cstdio>
#include <iostream>

int main() {
	int N;
	bool flag = false;
	scanf("%d",&N);
	int arr[N][2];

	for (int i = 0; i < N; i++) {
		for (int j = 0; j < 2; j++)
			scanf("%d" , &arr[i][j]);
	}
			for(int i = 0; i < N; i++) {
				if(arr[i][0] == arr[i][1]) {
					if(arr[i + 1][0] == arr[i + 1][1]) {
						if(arr[i + 2][0] == arr[i + 2][1]) {
							flag= true;
							break;
						}
					}
				}
			}

			if(flag == true)
				puts("Yes");
			else
				puts("No");

	return 0;
}

Measured memory_bytes: 3752
def dfs(d, r):
    global l
    if d == 11:
        return
    l.append(int(r))
    for i in range(-1, 2):
        tmp = int(r[-1]) + i
        if 0 <= tmp <= 9:
            dfs(d + 1, r + str(tmp))


k = int(input())
l = []
for i in range(1, 10):
    dfs(0, str(i))
print(sorted(l)[k - 1])

Measured memory_bytes: 31956
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn = 100100;
ll arr[maxn], n, k;

int main() {
    cin>>n>>k;
    for(int i=0;i<n;i++) {
        cin>>arr[i];
    }
    sort(arr, arr+n);

    ll result = LLONG_MAX;
    for(int i=0;i<n;i++) {
        if(i-k+1>=0) {
            result = min(result, arr[i] - arr[i-k+1]);
        }
    }
    cout<<result<<"\n";
    return 0;
}

Measured memory_bytes: 1024
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * y / gcd(x, y); }

long mod = 10^^9 + 7;
//long mod = 998244353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }

void main()
{
	auto rgb = RDR.ARR;

	writeln((rgb[0]*100 + rgb[1]*10 + rgb[2]) % 4 == 0 ? "YES" : "NO");
	stdout.flush();
	debug readln();
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
using namespace std;
#define INF 0x3f3f3f3f
//#define INF 1100000000000000000LL
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pint;
typedef tuple<int,int,int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=1050;
//ここまでテンプレ
int main() {
	string A,B;
	cin>>A>>B;
	if(A[0]==B[2] && A[1]==B[1] && A[2]==B[0]){
		cout<<"YES"<<endl;
		return 0;
	}
	cout<<"NO"<<endl;
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(unique(all(x)), x.end());
typedef long long ll;
typedef complex<double> Complex;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

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

    vector<vector<int>> dp(n + 1, vector<int>(1 << n));
    dp[0][0] = 1;
    rep(i, n) {
        rep(bit, 1 << n) {
            if (__builtin_popcount(bit) != i) continue;
            rep(j, n) {
                if (!a[i][j]) continue;
                dp[i + 1][bit | (1 << j)] += dp[i][bit];
                if (dp[i + 1][bit | (1 << j)] > MOD)
                    dp[i + 1][bit | (1 << j)] -= MOD;
            }
        }
    }
    cout << dp[n][(1 << n) - 1] << endl;
}


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

int ret(int n) {
  if(n == 1) return 1;
  else {
    int sum = n;
    sum += ret(n-1);
    return sum;
  }
}

int main() {
  int sum = ret(5); //15
  int tmp = 0;
  rep(i, 5) {
    int x;
    cin >> x;
    tmp += x;
  }
  cout << (sum-tmp) << endl;
  return 0;
}

Measured memory_bytes: 3492
#include <iostream> 
#include <sstream> 
#include <iomanip> 
#include <algorithm> 
#include <cmath> 
#include <string> 
#include <vector> 
#include <list> 
#include <queue> 
#include <stack> 
#include <set> 
#include <map> 
#include <bitset> 
#include <numeric> 
#include <climits> 
#include <cfloat> 
using namespace std;

class Edge
{
public:
    int to, dist, cost;
    Edge(){};
    Edge(int to0, int dist0, int cost0){to = to0; dist = dist0; cost = cost0;}
};

int main()
{
    for(;;){
        int n, m;
        cin >> n >> m;
        if(n == 0)
            return 0;

        vector<vector<Edge> > edges(n);
        while(--m >= 0){
            int u, v, d, c;
            cin >> u >> v >> d >> c;
            -- u;
            -- v;
            edges[u].push_back(Edge(v, d, c));
            edges[v].push_back(Edge(u, d, c));
        }

        vector<int> minDist(n, INT_MAX), minCost(n, INT_MAX);
        minDist[0] = minCost[0] = 0;
        priority_queue<pair<int,int> ,vector<pair<int,int> >, greater<pair<int,int> > > q;
        q.push(make_pair(0, 0));

        while(!q.empty()){
            pair<int, int> p = q.top();
            q.pop();
            int v = p.second;
            if(minDist[v] < p.first)
                continue;
            for(unsigned i=0; i<edges[v].size(); ++i){
                Edge e = edges[v][i];
                if(minDist[v] + e.dist == minDist[e.to]){
                    minCost[e.to] = min(minCost[e.to], e.cost);
                }else if(minDist[v] + e.dist < minDist[e.to]){
                    minDist[e.to] = minDist[v] + e.dist;
                    q.push(make_pair(minDist[e.to], e.to));
                    minCost[e.to] = e.cost;
                }
            }
        }

        int ret = accumulate(minCost.begin(), minCost.end(), 0);
        cout << ret << endl;
    }
}

Measured memory_bytes: 0
import java.util.*;

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

    int n = sc.nextInt();
    int k = sc.nextInt();

    int ans = (int)Math.pow(k - 1, n - 1) * k;
    
    System.out.println(ans);
  }
}

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

using namespace std;

#define M 1000000007
#define pb push_back
#define f first
#define s second
#define rep(i, st, ed) for(int i=st; i<ed; i++)
#define repn(i, st, ed) for(int i=st; i<=ed; i++)
#define repb(i, ed, st) for(int i=ed; i>=st; i--)

typedef long long ll;
typedef unsigned long long int llt;
typedef long double ld;

const long double PI  =3.141592653589793238463;
const int N = 5e5 + 10;
const ll INF = 1LL << 60;

template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}


vector<int> g[N];
bool viss[N];
int vis[N];

// Normal DFS
void dfs(int curr, int par)
{
  for(auto x: g[curr])
    if(x != par)
      dfs(x, curr);
}

// DFS with visiting status
void dfs1(int curr, int par)
{
  viss[curr] = 1;
  for(auto x: g[curr])
    if(!viss[x])
      dfs1(x, curr);
}

// DFS with strongly connected component
void dfs2(int curr, int par, int num)
{
  vis[curr] = num;
  for(auto x: g[curr])
    if(vis[x] == 0 || vis[x] > (num+1))
      dfs2(x, curr, num+1);
}

// XOR from 0 to n
ll fxor(ll n)
{
  if(n < 0) return 0;
  if(n % 4 == 3) return 0;
  else if(n % 4 == 0) return n;
  else if(n % 4 == 1) return n^(n-1);
  else if(n%4 == 2) return n^(n-1)^(n-2);
}

// Power in logn with mod 1000000007
llt ppow(llt x, llt y)
{
  llt res = 1;
  while(y > 0){
    if(y&1)
      res = (res * x)%M;
    y = y >> 1;
    x = (x * x)%M;
  }
  return res;
}

// Factorial with dp
llt factdp[N];
llt fact(llt x)
{
  if(x == 0) return 1;
  if(x == 1) return 1;
  if(factdp[x] != 0) return factdp[x];
  return factdp[x] = (x*fact(x-1))%M;
}
// Combination
ll modcomb(ll n, ll r)
{
  if(n < r) return 0;
  ll res = fact(n);
  (res *= ppow(fact(r), M-2)) %= M;
  (res *= ppow(fact(n-r), M-2)) %= M;
  return res;
}

// String return to base b
string ansConv ="";
void convert10tob(llt N, int b)
{
     if (N == 0)
        return;
     int x = N % b;
     N /= b;
     if (x < 0)
        N += 1;
     convert10tob(N, b);
     ansConv += to_string(x);
     return;
}

// Convert string to num wiht base b
llt convertstrtob(string a, int b)
{
  llt aa = 0;
  llt mul = 1;
  for(int i=a.length()-1; i>=0; i--)
  {
    int curr = a[i] - '0';
    aa += (curr * mul);
    mul *= b;
  }
  return aa;
}

// Union Find
// Find()
int parent[N], ran[N];
int find(int x)
{
    if(parent[x]==x)return x;
    else return parent[x]=find(parent[x]);
}
// Union()
void unite(int x,int y){
    x=find(x);
    y=find(y);
    if(x==y)return;

    if(ran[x]<ran[y])
        parent[x]=y;
    else{
        parent[y]=x;
        if(ran[x]==ran[y])ran[x]++;
    }
}

// Main Code
llt gcd(llt x, llt y)
{
  if(y == 0) return x;
  return gcd(y, x%y);
}
llt lcm(llt x, llt y)
{
  return (x / gcd(x, y)) * y;
}
int main()
{
  int n;
  cin>>n;
  llt ans;
  cin>>ans;
  llt arr[n];
  arr[0] = ans;
  rep(i, 1, n)
  {
    llt x;
    cin>>x;
    arr[i] = x;
    ans = lcm(max(ans, x), min(ans, x));
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 14080
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<int> a(3*n,0);
  for(int i=0;i<3*n;i++)cin >> a[i];
  sort(a.begin(),a.end(),greater<int>());
  long long ans = 0;
  for(int i=0;i<n;i++)ans+=a[2*i+1];
  cout << ans << endl;
}

Measured memory_bytes: 1408
N, M = map(int, input().split())
A = list(map(int, input().split()))
for i in range(N-1):
  for j in range(i+1):
    if A[i+1-j] > A[i-j]:
      a = A[i-j]
      A[i-j] = A[i+1-j]
      A[i+1-j] = a

S = 0
for i in range(N):
  S += A[i]

if A[M-1] < float(S)/(4.0*float(M)):
  print("No")
else:
  print("Yes")

Measured memory_bytes: 3064
import itertools
import math

N = int(input())
pn = [2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97]
ans = []

for ar in itertools.permutations(pn,3):
    if math.factorial(N) > (ar[0]**2*ar[1]**4*ar[2]**4) and\
    math.factorial(N) % (ar[0]**2*ar[1]**4*ar[2]**4) == 0:
        ans.append(ar[0]**2*ar[1]**4*ar[2]**4)

for ar in itertools.permutations(pn,2):
    if math.factorial(N) > (ar[0]**4*ar[1]**14) and\
    math.factorial(N) % (ar[0]**4*ar[1]**14) == 0:
        ans.append(ar[0]**4*ar[1]**14)

for ar in itertools.permutations(pn,2):
    if math.factorial(N) > (ar[0]**2*ar[1]**24) and\
    math.factorial(N) % (ar[0]**2*ar[1]**24) == 0:
        ans.append(ar[0]**2*ar[1]**24)

for ar in pn:
    if math.factorial(N) > ar**74 and\
    math.factorial(N) % ar**74 == 0:
        ans.append(ar**74)

ans = set(ans)
print(len(ans))

Measured memory_bytes: 3188
#include <stdio.h>
int main(){
  long long int a,b,c;
  scanf("%lld%lld%lld", &a, &b, &c);
  if(4*a*b < (c-a-b)*(c-a-b) && c-a-b > 0) {
    puts("Yes");
  }
  else {
    puts("No");
  }
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)n; i++)
#define REPvec(itr, mp) for (auto itr = mp.begin(); itr != mp.end(); itr++)
#define all(x) x.begin(), x.end()
#define MOD 1000000007  // 1e9+7
using namespace std;
typedef long long int ll;
typedef vector<int> vecint;
typedef vector<ll> vecll;
typedef vector<double> vecd;
typedef vector<string> vecstr;
typedef vector<char> vecchar;
typedef vector<bool> vecbool;
typedef vector<vector<bool>> vec2bool;
typedef vector<vector<int>> vec2int;
typedef vector<vector<double>> vec2d;
////////////////////////////////////////////////
void init() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}
////////////////////////////////////////////////
int main() {
  init();
  int h, w;
  cin >> h >> w;
  int n;
  cin >> n;
  vecint a(n);
  for (auto& e : a) cin >> e;
  vecint ans1d;
  REP(i, n) { REP(j, a[i]) ans1d.push_back(i + 1); }
  // for (auto& e : ans1d) cout << e << endl;
  vec2int ans2d(h, vecint(w));
  int cnt = 0;
  REP(i, h) {
    REP(j, w) {
      if (i % 2 == 0) {
        ans2d[i][j] = ans1d[cnt];
        cnt++;
      } else {
        ans2d[i][w - j - 1] = ans1d[cnt];
        cnt++;
      }
    }
  }
  REP(i, h) {
    REP(j, w - 1) { cout << ans2d[i][j] << " "; }
    cout << ans2d[i][w - 1] << endl;
  }
}


Measured memory_bytes: 512
#include <cmath>
#include <cstdio>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#define vi vector<int>
#define vb vector<bool>
#define lli long long int
#define vvi vector<vector<int>>
#define loop(n) for (int i = 0; i < n; i++)
using namespace std;

auto SpeedUp = []() {
    std::ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    return 0;
}();

void solve()
{
    lli n, d, x, y;
    cin>>n>>d;
    int count = 0;
    loop(n)
    {
        cin>>x>>y;
        long double dist  = x*x + y*y;
        dist = sqrt(dist);
        // cout<<dist<<endl;
        if (dist<=d)
            count++;
    }

    cout<<count<<endl;
}

int main()
{

    solve();
    return 0;
}

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

using namespace std;

int a;

int main(){
int sum = 0;
cin >> a;
if(a == 0){
 for(int i = a; i <= 1; i++){
    sum+=i;
 }
 cout << sum;
 return 0;
}
for(int i = 1; i <= a; i++){
    sum+=i;
}
cout << sum;
return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10000000)
MOD = 10 ** 9 + 7
INF = 10 ** 15

def main():
    N = int(input())
    ans = []
    while N:
        N -= 1
        ans.append(chr(N%26 + 97))
        N //= 26
    print(''.join(map(str,ans[::-1])))
if __name__ == '__main__':
    main()

Measured memory_bytes: 9144
#include <iostream>
#include <string>
using namespace std;
#define REP(i, n) for (int i = 0; (i) < (n); ++i)

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

    string a;
    string b;
    cin >> a;
    cin >> b;
    a += b.back();
    if (a == b)

        cout << "Yes";
    else
    {
        cout << "No";
    }

    return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  
  if((a+b)>(c+d)){
    cout << "Left" << endl;
  }else  if((a+b)<(c+d)){
    cout << "Right" << endl;
  }else{
    cout << "Balanced" << endl;
  }
}

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

void solve(long long A, long long B){
	if ((A+B)%2 == 0) {
		cout << (A+B)/2 << endl;
	} else {
		cout << "IMPOSSIBLE" << endl;
	}
}

int main(){	
	long long A;
	long long B;
	scanf("%lld",&A);
	scanf("%lld",&B);
	solve(A, B);
	return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    int h,w;
    char c[110][110];
    scanf("%d%d",&h,&w);
    for(int i=0;i<h;i++){
        scanf("%s",c[i]);
        printf("%s\n%s\n",c[i],c[i]);
    }
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int ans=0,n,k,cnt[110],d,a;
int main()
{
	scanf("%d%d",&n,&k);
	for(int i=1;i<=k;++i) {
		scanf("%d",&d);
		for(int j=1;j<=d;++j) {
			scanf("%d",&a);
			cnt[a]++;
		}
	}
	for(int i=1;i<=n;++i)
		if(cnt[i]==0)
			++ans;
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 3828
cnt = [0, 0, 0, 0]

for _ in range(3):
    a, b = map(int, input().split())
    cnt[a - 1] += 1
    cnt[b - 1] += 1


def solve():
    odd = 0
    for c in cnt:
        if c == 0:
            return False
        elif c == 1:
            odd += 1

    return odd == 2


print('YES' if solve() else 'NO')


Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include<algorithm>
#include<iomanip>
#include<queue>
#include<map>
#include<bitset>
#include<math.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for(int i=m;i<(int)(n);i++)
typedef pair<int,int> pint;
typedef pair<long long,pint> p3;
typedef long long ll;
const int inf   = 1e9+7;
const ll  longinf = 1LL<<60;
const int mod=1e9+7;
int dx[4]={1,0,-1,0}, dy[4]={0,1,0,-1};

int main(){
  int a,b,c;
  cin>>a>>b>>c;
  if(a+b>=c)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
    
  }

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.nio.charset.StandardCharsets;
import java.util.*;

public class Main {

    //グローバル変数を定義

    public static void main(String[] args) throws IOException {
        new Main().run();
    }

    void run() {
        Scanner sc = new Scanner(System.in);
        int aCost = sc.nextInt();
        int bCost = sc.nextInt();
        int abCost = sc.nextInt();
        int A = sc.nextInt();
        int B = sc.nextInt();

        int sum1 = 0;
        int sum2 = 0;
        int sum3 = 0;
        int sum4 = 0;
        int sum5 = 0;

        if(A == B){
            sum1 += abCost*A*2;
            sum2 += abCost*A*2;
            sum3 += abCost*A*2;
            sum4 += abCost*A*2;
            sum5 += abCost*A*2;
        } else {
            sum1 += bCost*B + aCost*A;
            if(A-B < 0){
                sum2 += abCost*B*2;
                sum3 += abCost*B*2;
            } else {
                sum2 += abCost*B*2 + aCost*(A-B);
                sum3 += abCost*B*2 + aCost*(A-B);
            }

            if(B-A < 0){
                sum4 += abCost*A*2;
                sum5 += abCost*A*2;
            } else {
                sum4 += abCost*A*2 + bCost*(B-A);
                sum5 += abCost*A*2 + bCost*(B-A);
            }

        }

        int min = Math.min(sum1, sum2);
        min = Math.min(min, sum3);
        min = Math.min(min, sum4);
        min = Math.min(min, sum5);

        System.out.println(min);
    }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define mod 1000000007
#define mod998 998244353
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define mkp make_pair
typedef long long ll;
using namespace std;

int N, A[100], B[100], res;

int main(){
	cin >> N;
	for (int i = 0; i < N; ++i) {
		A[i] = intmax;
	}
	for (int i = 0; i < N - 1; ++i) {
		cin >> B[i];
		A[i] = min(A[i], B[i]);
		A[i + 1] = min(A[i + 1], B[i]);
	}
	for (int i = 0; i < N; ++i) {
		res += A[i];
	}
	cout << res << endl;
}

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

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll  n, sum = 0,a;
	vector<pair<ll, int>> v(4);
	for (int i = 0; i < 4; i++) {
		cin >> a;
		if(i==0){
			v[i].first=a*8;
		}else if(i==1){
			v[i].first=a*4;
		}else if(i==2){
			v[i].first=a*2;
		}else if(i==3){
			v[i].first=a;
		}
		v[i].second = i + 1;
	}
	sort(v.begin(), v.end());
	for (int i = 0; i < 4; i++) {
		if (v[i].second == 1) {
			v[i].first/=8;
		} else if (v[i].second == 2) {
			v[i].first/=4;
		} else if (v[i].second == 3) {
			v[i].first/=2;
		}
	}
	cin >> n;
	if (v[0].second == 4) {
		if (n >= 2) {
			sum += (n / 2) * v[0].first;
			if (n % 2 != 0) {
				if (v[1].second == 1) {
					sum += 4 * v[1].first;
				} else if (v[1].second == 2) {
					sum += 2 * v[1].first;
				} else if (v[1].second == 3) {
					sum += 1 * v[1].first;
				}
			}
		} else {
			if (v[1].second == 1) {
				sum += n * 4 * v[1].first;
			} else if (v[1].second == 2) {
				sum += n * 2 * v[1].first;
			} else if (v[1].second == 3) {
				sum += n * v[1].first;
			}
		}
	}else{
		if (v[0].second == 1) {
			sum += n * 4 * v[0].first;
		} else if (v[0].second == 2) {
			sum += n * 2 * v[0].first;
		} else if (v[0].second == 3) {
			sum += n * v[0].first;
		}
	}
	cout<<sum<<endl;
	return 0;
}


Measured memory_bytes: 256
h,w=map(int,input().split())
l=[list(input()) for i in range(h)]
c=0
for j in range(h):
  for k in range(w):
    if l[j][k]=='#':
      if j!=0 and j!=h-1 and k!=0 and k!=w-1:
        if l[j-1][k]=='.' and l[j][k-1]=='.' and l[j][k+1]=='.' and l[j+1][k]=='.':
          c+=1
      elif j==0 and k!=0 and k!=w-1:
        if  l[j][k-1]=='.' and l[j][k+1]=='.' and l[j+1][k]=='.':
          c+=1
      elif j==h-1 and k!=0 and k!=w-1:
        if l[j-1][k]=='.' and l[j][k-1]=='.' and l[j][k+1]=='.':
          c+=1
      elif j!=0 and j!=h-1 and k==0:
        if l[j-1][k]=='.' and  l[j][k+1]=='.' and l[j+1][k]=='.':
          c+=1
      elif j!=0 and j!=h-1 and k==w-1:
        if l[j-1][k]=='.' and l[j][k-1]=='.' and l[j+1][k]=='.':
          c+=1
      elif j==0 and k==0:
        if l[j][k+1]=='.' and l[j+1][k]=='.':
          c+=1
      elif j==0 and k==w-1:
        if l[j][k-1]=='.' and l[j+1][k]=='.':
          c+=1
      elif j==h-1 and k==0:
        if l[j-1][k]=='.' and l[j][k+1]=='.':
          c+=1
      else:
        if l[j-1][k]=='.' and l[j][k-1]=='.':
          c+=1
if c!=0:print('No')
else:print('Yes')

Measured memory_bytes: 3192
#include <iostream>
#include <vector>
using namespace std;
int main(void){
    int len;
    string s;
    cin >> s;
    len = s.length();
    for(int i=0;i<len-1;i++){
        if(s[i] == s[i+1]){
            cout << i+1 << " " << i+2 << endl;
            return 0;
        }
        if(i+2 < len && s[i] == s[i+2]){
            cout << i+1 << " " << i+3 << endl;
            return 0;
        }
    }
    puts("-1 -1");
}


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

int main()
{
   string s;
   cin>>s;
   char i;
   for( i='a';i<='z';i++)
   {
       if(s.find(i)==-1)
       {
           cout<<i<<endl;
           break;
       }

   }
   if(i=='{')
    cout<<"None"<<endl;
}


Measured memory_bytes: 512
using System;

namespace A_753
{
    class Program
    {
        static void Main(string[] args)
        {
            var x = int.Parse(Console.ReadLine());
            if(x==3||x==5||x==7)
            {
                Console.WriteLine("YES");
            }
            else
            {
                Console.WriteLine("NO");
            }
        }
    }
}

Measured memory_bytes: 11092
#include<iostream>
#include<string>
using namespace std;
int main(void){
  int h,w;
  cin>>h>>w;
  string s[h];
  for(int i(0);i<h;i++){
    cin>>s[i];
  }
  for(int i(0);i<h;i++){
    cout<<s[i]<<endl;
    cout<<s[i]<<endl;
  }
  return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ITP1_6_A
{
    public class Program

    {
        public static void Main(string[] args)
        {
            int n = ReadInt();
            int[] line = ReadIntAr();
            Console.WriteLine(string.Join(" ",line.Reverse().Select(x => x.ToString()).ToArray()));
        }

        static string ReadSt() { return Console.ReadLine(); }
        static int ReadInt() { return int.Parse(Console.ReadLine()); }
        static long ReadLong() { return long.Parse(Console.ReadLine()); }
        static double ReadDouble() { return double.Parse(Console.ReadLine()); }
        static string[] ReadStAr(char sep = ' ') { return Console.ReadLine().Split(sep); }
        static int[] ReadIntAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => int.Parse(e)); }
        static long[] ReadLongAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => long.Parse(e)); }
        static double[] ReadDoubleAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => double.Parse(e)); }

    }

}



Measured memory_bytes: 16324
(defun div-num (a b x)
  (multiple-value-bind (n m) (floor (/ (+ (- b a) 1) x))
    (cond ((= m 0)
           n)
          ((= (mod a x) 0)
           (1+ n))
          ((> (mod a x) (mod b x))
           (1+ n))
          (t n))))
(let ((a (read))
      (b (read))
      (c (read))
      (d (read)))
  (format t "~A~%" (- (+ (div-num a b 1) (div-num a b (lcm c d)))
                      (+ (div-num a b c) (div-num a b d)))))


Measured memory_bytes: 24452
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define fi first
#define se second
#define All(x) (x).begin(),(x).end()
#define TYPE(x) typeid(x).name()
int main(){
	unsigned long long x;
	cin>>x;
	unsigned long long y=100;
	unsigned long long t=0;
	while(y<x){
		y=y+y/100;
		t++;
	}
	cout<<t;
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define yesno(flg) if(flg){cout<<'YES'<<endl;}else{cout<<'NO'<<endl;}
#define vi vector<int>
#define pb push_back
#define i197 1000000007
#define MAX_N 200002
using namespace std;

typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<Pii,int> Piii;
typedef pair<int,ll> Pil;
typedef pair<ll,ll> Pll;
typedef pair<string,int> Psi;
typedef pair<Psi,int> Psii;

const int inf=1000000000;
struct edge{
	int myc,to,c,cost;
};
struct pos{
	int to,cost,color;
};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

vi vec[200001];
int x[200001]={};
int dp[200001];
int main() {
	rep(i,200001)dp[i]=-1;
	int n,q;
	cin>>n>>q;
	rep(i,n-1){
		int a,b;
		cin>>a>>b;
		vec[a].push_back(b);
		vec[b].push_back(a);
	}
	rep(i,q){
		int p,x1;
		cin>>p>>x1;
		x[p]+=x1;
	}
	queue<Pii> que;
	que.push(Pii(1,0));
	while(!que.empty()){
		Pii pp=que.front();que.pop();
		int p1=pp.first;
		int x1=pp.second;
		if(dp[p1]>=0)continue;
		x1+=x[p1];
		dp[p1]=x1;
		rep(i,vec[p1].size()){
			que.push(Pii(vec[p1][i],x1));
		}
//		cout<<p1<<" "<<x1<<endl;
	}
	cout<<dp[1];
	rep(i,n-1)cout<<" "<<dp[i+2];
	cout<<endl;
	return 0;
}


Measured memory_bytes: 16372
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<bitset>
using namespace std;

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

    long long ans=0;
    int a=s.size()-1;
    long long r;

    for(int tmp=0;tmp<(1<<a);tmp++){
        bitset<10> bit(tmp);

        r = s[0]-'0';
        for(int i=0;i<a;i++){
            if(bit.test(i)){
                ans += r;
                r = 0;
            }
            r = r*10 + (s[i+1]-'0');
        }
        ans += r;
    }

    cout << ans << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(int i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(int i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(int i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define uniq(x) (x).erase(unique((x).begin(), (x).end()), (x).end())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n, t;
    cin >> n >> t;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    vector<int> tv(n, INT_MIN);
    vector<int> b(n, INT_MIN);
    int bmax = INT_MIN;
    int ans = 0;
    
    rrep(i, n) {
        if (i == (n - 1)) {
            tv[i] = a[i];
        }
        else {
            tv[i] = max(tv[i + 1], a[i]);
        }
    }
    
    rep(i, n - 1) {
        b[i] = max(b[i], tv[i + 1] - a[i]);
        bmax = max(bmax, b[i]);
    }
    
    rep(i, n) {
        if (bmax == b[i]) {
            ans++;
        }
    }
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1408
// Author: 23forever
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <vector>
#include <queue>
typedef long long LL;
const int MAXN = 200000;
using namespace std;

inline void enableFileIO() {
  freopen("test.in", "r", stdin);
  freopen("test.out", "w", stdout);
}

inline int read() {
  int x = 0, w = 1;
  char c = ' ';

  while (c < '0' || c > '9') {
    c = getchar();
    if (c == '-') w = -1;
  }
  while (c >= '0' && c <= '9') {
    x = (x << 1) + (x << 3) + (c ^ 48);
    c = getchar();
  }

  return x * w;
}

int n, l;
LL pre_sum[MAXN + 5], ans, pre_xor[MAXN + 5];

void init() {
  //enableFileIO();

  n = read();
  for (int i = 1; i <= n; ++i) {
    int x = read();
    pre_sum[i] = pre_sum[i - 1] + x;
    pre_xor[i] = pre_xor[i - 1] ^ x;
  }
}

int main() {
  init();

  l = 1;
  for (int i = 1; i <= n; ++i) {
    while ((pre_xor[i] ^ pre_xor[l - 1]) != pre_sum[i] - pre_sum[l - 1]) ++l;
    ans += i - l + 1;
  }
  
  printf("%lld\n", ans);
  return 0;
}

Measured memory_bytes: 3328
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

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

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

int main() {
  ll a,b,c,k;
  cin>>a>>b>>c>>k;
  
  if(k<=a) cout<<k<<endl;
  else if(k<=a+b) cout<<a<<endl;
  else cout<<2*a+b-k<<endl;
  
  
  
  return 0;
}

Measured memory_bytes: 3620
INF = 10**15
n = gets.to_i
a = gets.split.map(&:to_i)

if n % 2 == 0
  evn = Array.new(n+1,0)
  odd = Array.new(n+1,0)
  for i in 0..(n-1)
    evp = odp = 0
    (i % 2 == 0) ? (evp = a[i]):(odp = a[i])
    evn[i+1] = evn[i] + evp
    odd[i+1] = odd[i] + odp
  end
  ans = -INF
  for i in 0..(n-1)
    if i % 2 == 0
      ans = [ans, evn[i]+odd[n]-odd[i]].max
    end
  end
  ans = [ans, evn[i]].max
  puts ans
else
  dp = Array.new(n).map{Array.new(3).map{Array.new(2,-INF)}}
  ans = -INF
  for i in 0..2
    dp[i][i][0] = a[i]
    dp[i][i][1] = 1
  end
  for i in 0..(n-1)
    for j in 0..2
      if i > j && (i % 2 == j % 2) && dp[i-2][j][1] < n/2
        for k in 0..j
          dp[i][j][0] = [dp[i][j][0], dp[i-2-k][j-k][0]+a[i]].max
        end
        dp[i][j][1] = dp[i-2][j][1] + 1
      end
      ans = [ans, dp[i][j][0]].max if dp[i][j][1] == n/2
    end
  end
  puts ans
end

Measured memory_bytes: 66656
n, k = gets.split.map(&:to_i)
r, s, p = gets.split.map(&:to_i)
cpus = gets.chomp.split("")
takahashis = []
win_pattern = Hash.new
win_pattern["r"] = "p"
win_pattern["s"] = "r"
win_pattern["p"] = "s"
cpus.each_with_index do |cpu, i|
  if (i - k) < 0 || takahashis[i - k] != win_pattern[cpu]
    takahashis << win_pattern[cpu]
  else
    takahashis << ""
  end
end
ans = takahashis.count("r") * r + takahashis.count("s") * s + takahashis.count("p") * p
puts ans


Measured memory_bytes: 9596
/*==============================================*\
ID:          shahidul_brur

Name:     Md. Shahidul Islam
Study:      CSE, BRUR
Address:  Rangpur, Bangladesh

 mail: shahidul.cse.brur@gmail.com
 FB  : fb.com/shahidul.brur
 Blog: shahidul-brur.blogspot.com(in Bengali),
       shahidul-brur-en.blogspot.com(in English)
\*===============================================*/
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> // Common file
//#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
//using namespace __gnu_pbds;
using namespace std;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

//#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("avx,avx2,fma")

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<ll, int> li;
typedef pair<int, ll> il;
typedef vector<ii> vii;
typedef vector<il> vil;
typedef vector<li> vli;

#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz size()
#define all(a)  a.begin(), a.end()
#define mem(a, b)     memset(a, b, sizeof(a))
#define f0(i,b) for(int i=0;i<(b);i++)
#define f1(i,b) for(int i=1;i<=(b);i++)
#define f2(i,a,b) for(int i=(a);i<=(b);i++)
#define fr(i,b,a) for(int i=(b);i>=(a);i--)
#define rep(i,a,b,c) for(int i=(a);i!=(b);i+=(c))

int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};
int dx4[] = {0, 0, 1, -1};
int dy4[] = {1, -1, 0, 0};

const double pi = acos(-1.0);
const double eps = 1e-6;
const int mod = (int)1e9+7;
const int maxn = (int)2e5+5;
const int logn = 20;
int a[300002];
int main()
{
    //ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
    //freopen("input.txt", "r", stdin);
    int n;
    cin>>n;
    f1(i,n) cin>>a[i];
    int c = 0;
    f1(i,n)
    {
        if(a[i]!=i) c++;
    }
    if(c>2)
        cout << "NO" << endl;
    else cout << "YES" << endl;
    return 0;
}


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

int N, K;
vector<vector<int>> G;

void dfs(int s, vector<int> &d){
    for(int t : G[s]){
        if(d[t] != -1) continue;
        d[t] = d[s] + 1;
        dfs(t, d);
    }
}

vector<int> dist(int c1, int c2){
    vector<int> d(N, -1);
    d[c1] = 0;
    for(int t : G[c1]){
        if(t == c2) continue;
        d[t] = 1;
        dfs(t, d);
    }
    return d;
}

int solve(int c[], int k){
    vector<int> d[2];
    for(int i=0; i<2; i++)
        d[i] = dist(c[i], c[1-i]);
    int cnt = 0;
    for(int i=0; i<2; i++)
        for(int j=0; j<N; j++)
            if(d[i][j] > k)
                cnt++;

    if(c[0] == c[1]) cnt /= 2;
    return cnt;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N >> K;
    G.resize(N);
    for(int i=0; i<N-1; i++){
        int A, B;
        cin >> A >> B;
        A--; B--;
        G[A].push_back(B);
        G[B].push_back(A);
    }
    int ans = 1 << 30;
    for(int i=0; i<N; i++){
        if(K % 2 == 0){
            int a[] = {i, i};
            ans = min(ans, solve(a, K / 2));
        }else{
            for(int j : G[i]){
                int a[] = {i, j};
                ans = min(ans, solve(a, K / 2));
            }
        }
    }

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


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


#include "boost/multiprecision/cpp_int.hpp"
#include "boost/multiprecision/cpp_dec_float.hpp"
namespace mp = boost::multiprecision;
typedef mp::cpp_int LL;
typedef mp::number<mp::cpp_dec_float<1024>> DD;// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)

 
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
typedef pair<dd,dd> d_d;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define rrep(i,r,l) for(ll i=r;i>=l;i--)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-12;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fi first
#define se second
#define endl "\n"  //インタラクティブで消す！！！！！！！！！！！！！！！！！！！！！
#define SORT(v) sort(v.begin(),v.end())
#define ERASE(v) v.erase(unique(v.begin(),v.end()),v.end())
#define POSL(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define POSU(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
template<class T,class S>
inline bool chmax(T &a, S b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
template<class T,class S>
inline bool chmin(T &a, S b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

void mod_print(ll k){
    ll P=50000;
    rep(y,1,P){
        ll x=mod(y*k);
        
        if(abs(x)<=P||x+P>=i_7){
            if(x+P>=i_7){
                x-=i_7;
            }
            cout<<x<<"/"<<y<<endl;
            //cout<<setprecision(5)<<(dd)x/(dd)y;
            return;
        }
    }
    cout<<"nun"<<endl;
}
#define all(c) c.begin(),c.end()
typedef vector<ll> vl;
//////////////////////////


int main(){fastio
    map<string,ll>mp;
    ll n;cin>>n;
    while(n--){
        string s;cin>>s;
        mp[s]++;
    }
    ll ma=0;
    for(auto x:mp){
        chmax(ma,x.se);
    }
    vector<string>ans;
    for(auto x:mp){
        if(x.se==ma)ans.pb(x.fi);
    }
    SORT(ans);
    for(auto x:ans)cout<<x<<endl;
    
    return 0;
}


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

int main(void){
    long long n;
    cin >> n;
    for(long long h=1;h<=3500;++h){
        for(long long i=1;i<=3500;++i){
            long long bunbo = 4*h*i-n*i-n*h, bunsi = n*h*i;
            if(bunbo<=0) continue;
            if(bunsi%bunbo==0){
                long long j = bunsi/bunbo;
                cout << h << " " << i << " " << j << endl;
                return 0;
            }
        }
    }
}


Measured memory_bytes: 256
n,m=map(int,input().split())
a=sorted(list(map(int,input().split())))
d=[0]*(m-1)
for i in range(m-1):
  d[i]=a[i+1]-a[i]
d=sorted(d,reverse=True)
print(max(a)-min(a)-sum(d[0:n-1]))

Measured memory_bytes: 13968
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i <(n); ++i)
#define ALL(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main(){
  int a, b, c, k;
  cin >> a >> b >> c >> k;

  if(a >= k){
    cout << k << endl;
    return 0;
  }
  else if (a < k && a+b >= k){
    cout << a << endl;


  }
  else{
    cout << a - (k - a -b) << endl;
    return 0;
  }


  return 0;
}

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

int main() {
    int n, d;
    cin >> n >> d;

    int p = 2 * d + 1;

    int q = n / p;
    int r = n % p;
    if (r != 0) q++;
    cout << q << endl;
}

Measured memory_bytes: 256
from collections import deque

n,m = map(int,input().split())
graph = [[] for _ in range(n+1)]
for _ in range(m):
    a,b = map(int,input().split())
    graph[a].append(b)
    graph[b].append(a)
ans = 1

def dfs(node):
    while len(todo) > 0:
        node = todo.pop()
        if tf[node] == 0:
            tf[node] = 1
            seen.add(node)
            for nextnode in graph[node]:
                todo.append(nextnode)

todo = deque()
done = set()
tf = [0 for _ in range(n+1)]
for i in range(1,n+1):
    if i in done:
        continue
    else:
        todo.append(i)
        seen = set()
        dfs(i)
        #print(i,seen)
        ans = max(ans,len(seen))
        done |= seen
print(ans)

Measured memory_bytes: 62168
"use strict";

const main = arg => {
    const inputList = arg.trim().split("\n");
    // 回答を記述
    const K = inputList[0];
    const S = inputList[1];

    if (S.length <= K) {
        console.log(S)
    } else {
        console.log(S.slice(0, K).concat("..."))
    }
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 29632
#include<iostream>
using namespace std;
int main()
{
    string s;
    cin>>s;
    for (int i=s.size()-1;i>=0;i--)
    {
        int ans=0;
        string g="";
        g+=s.substr(0,i);
        if (g.size()%2==0)
        {
            for (int j=0;j<g.size()/2;j++)
            {
                if (g[j]==g[j+g.size()/2])
                ans++;
            }
            if (ans==g.size()/2)
            {cout<<g.size()<<endl;
            system("pause");
            return 0;}
        }
    }
    system("pause");
    return 0;
}

Measured memory_bytes: 504
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		
		int a = scan.nextInt();
		int b = scan.nextInt();
		
		if (a < b) {
			System.out.println("a < b");
		} else if (a > b) {
			System.out.println("a > b");
		} else if (a == b) {
			System.out.println("a == b");
		}
		

	}

}

Measured memory_bytes: 26344