akhauriyash/Code-Regression huggingface dataset:
using System;

namespace Sample101
{
    class Program
    {
        static void Main(string[] args)
        {
            string str = Console.ReadLine();
            string result = "yes";
            char[] strArray = str.ToCharArray();

            for (int i = 0; i < strArray.Length; ++i)
            {
                for (int j = i + 1; j < strArray.Length; ++j)
                {
                    if (strArray[i] == strArray[j])
                    {
                        result = "no";
                        break;
                    }
                }
                if (result.Equals("no"))
                {
                    break;
                }
            }
            Console.WriteLine(result);
        }
    }
}

Measured memory_bytes: 13140
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <map>
using namespace std;
#define rep(i,s,n)for(int i = s;i<n;i++)
#define repe(i,s,n)for(int i = s;i<=n;i++)
#define rep_r(i,s,n)for(int i = n;i>s;i--)
#define rep_re(i,s,n)for(int i = n;i>=s;i--)
typedef long long ll;
static const ll MOD = 1e9 + 7;
static const ll INF = (ll)1 << 62;

int main() {
	ll k, x; cin >> k >> x;

	repe(i, x - (k - 1), x + k - 1) {
		cout << i;
		if (i != x + k - 1) {
			cout << " ";
		}
	}

	return 0;
}

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

int main(){
	char A;
	cin >> A;
	if(A=='A') cout << 'T' << endl;
	if(A=='T') cout << 'A' << endl;
	if(A=='G') cout << 'C' << endl;
	if(A=='C') cout << 'G' << endl;
}

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

import sys
import os


# Num, Capacity
N, C = map(int, input().split())

v = []
w = []
for i in range(N):
    a, b = map(int, input().split())
    v.append(a)
    w.append(b)

# d[i][j]
# i: i???????????§??????????????????
# j: ??????j
# d: ????????¨????????????????????§???
# size: N x C
d = [[0 for i in range(C+1)] for j in range(N)]

# j = 0?????¨????????¨??¨0
# i = 0?????¨???
for j in range(C+1):
    if j >= w[0]:
        d[0][j] = v[0]

# dp
for i in range(N):
    for j in range(C+1):
        # ??\?????????
        if w[i] > j:
            d[i][j] = d[i-1][j]
        # ??\???
        else:
            d[i][j] = max(d[i-1][j], d[i-1][j-w[i]] + v[i])

print(d[N-1][C])

Measured memory_bytes: 27736
#!/usr/bin/python3
# -*- coding: utf-8 -*-


MOD = 10**9+7

def mul(a,b):
  return (a*b) % MOD

def power(a,b):
  ## 二分累乗法
  if   b==0   : return 1
  elif b==1   : return a % MOD
  elif b%2==0 : return power(a,b//2)**2 % MOD
  else        : return power(a,b//2)**2 * a % MOD

def div(a,b):
  ## MOD同士の割り算
  return mul(a,power(b,MOD-2))

Fact = [1 for i in range(2001)]
for i in range(1,2001):
  Fact[i] = mul(i,Fact[i-1])


N,K = map(int, input().split())
for k in range(1,K+1):
  ans = 0
  if k <= N-K+1:
    a1 = div(Fact[N-K+1],mul(Fact[k],Fact[N-K+1-k]))
    if k==1:
      a2 = 1
    else:
      a2 = div(Fact[K-1],mul(Fact[k-1],Fact[K-k]))
    ans = mul(a1,a2)
  print(ans)


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

int main(){
  long long  s;
  cin >> s;
  long long x1=0,x2=0,x3=0,y1=0,y2=0,y3=0;
  long long tmp;
  
  if(s <= 1000000000){ 
    x1=0;
    y1=0;
    y2=0;
    y3=1;
    x3=0;
    x2=s;
  
    cout << x1 << ' ' << y1 << ' ' <<x2 << ' ' <<y2<< ' ' <<x3<< ' ' <<y3<<endl;
    return 0;
  }else if(s > 1000000000){
    x1=0;
    y1=0;
    
    for(long long i=30000; i<=1000000000; i+=1){
      if(i*i >= s){
        x2 = i;
        y3 = i;
        break;
      }
    }
    
    tmp = x2*y3 - s;
    
    if(tmp == 0){
      cout << x1 << ' ' << y1 << ' ' <<x2 << ' ' <<y2<< ' ' <<x3<< ' ' <<y3<<endl;
      return 0;
    }
    
    for(long long i=1; i<=1000000000; i+=1){
      x3 = i;
      if(tmp % i == 0){
        if( tmp/i <= 1000000000){
          y2 = tmp/i;
          break;
        }
      }
    }
  }
  
  cout << x1 << ' ' << y1 << ' ' << x2 << ' ' << y2 << ' ' << x3 << ' ' << y3 << endl;
  
}

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

int main(){
	int r, c;
	cin >> r >> c;
	vector<vector<int> > a(r+1,vector<int>(c+1));
	for(int i=0;i<r;i++){
		a[i][c]=0;
		for(int j=0;j<c;j++){
			cin >> a[i][j];
			a[i][c]+=a[i][j];
		}
	}
	for(int j=0;j<c+1;j++){
		a[r][j]=0;
		for(int i=0;i<r;i++){
			a[r][j]+=a[i][j];
		}
	}
	for(int i=0;i<r+1;i++){
		for(int j=0;j<c+1;j++){
			if(!j) cout << a[i][j];
			else cout << " " << a[i][j];
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 1256
#include<iostream>
using namespace std;
int main()
{
    int D;
    string day;
    cin >> D;
    switch(D){
        case 24:
          day = "Eve";
          break;
        case 23:
          day = "Eve Eve";
          break;
        case 22:
          day = "Eve Eve Eve";
    }
    cout << "Christmas " + day << endl;
    return 0;
}

Measured memory_bytes: 256
#include "iostream"
#include "vector"
#include "string"
#include "algorithm"

using namespace std;
typedef long long ll;

int main()
{
  int n;
  cin >> n;
  double x[11];
  string u[11];
  double ans = 0;
  for (int i = 0; i < n; i++)
  {
    cin >> x[i] >> u[i];
    if (u[i] == "BTC")
    {
      x[i] *= 380000.0;
    }
    ans += x[i];
  }
  printf("%.6f\n", ans);
}


Measured memory_bytes: 256
N=gets.to_i
b=gets.split.map &:to_i
r=""
while !b.empty? do
f=1
(b.size-1).downto(0){|j|b[j]==j+1&&(r=(j+1).to_s+"\n"+r;b.delete_at j;f=0;break)}
f>0&&(p -1;exit)
end
puts r

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
string s,t,res="";
int len_s, len_t;
int dp[3001][3001];

string getLCS(string s, string t, int len) {
    string res = "";
    int idx_s = 0, idx_t = 0;
    while(len > 0) {
        if(s[idx_s] == t[idx_t]) {
            res+= s[idx_s];
            idx_s++, idx_t++, len--;
        }
        else {
            if(dp[idx_s+1][idx_t] > dp[idx_s][idx_t+1]) idx_s++;
            else idx_t++;
        }
    }
    return res;
}

int lenLCS(int idx_s, int idx_t) {
    if(idx_s == len_s || idx_t == len_t) return 0;
    if(dp[idx_s][idx_t] != -1) return dp[idx_s][idx_t];
    if(s[idx_s] == t[idx_t]) return dp[idx_s][idx_t] = 1+lenLCS(idx_s+1, idx_t+1);
    else {
        int t1 = lenLCS(idx_s+1, idx_t);
        int t2 = lenLCS(idx_s, idx_t+1);
        return dp[idx_s][idx_t] = max(t1, t2);
    }
}

int main() {
    cin>>s>>t;
    memset(dp, -1, sizeof dp);
    len_s = s.length();
    len_t = t.length();
    int len = lenLCS(0,0);
    cout<<getLCS(s, t, len);
    return 0;
}


Measured memory_bytes: 39056
#include <iostream>
#include<stdio.h>
#include<bits/stdc++.h>
#define lli long long int
using namespace std;

lli cache[100005];
lli getmin(vector<int> &h,int i,int k,int n)
{
    if(i==n-1)
    {
        return 0;
    }

    if(cache[i]!=-1)
    {
        return cache[i];
    }

    lli mini = INT_MAX;

    for(int j=1;j<=k;j++)
    {
        if((i+j)<n)
        {
         mini = min(mini,abs(h[i]-h[i+j])+getmin(h,i+j,k,n));
        }
    }

    cache[i] = mini;

    return cache[i];
}

void solve()
{
    int n,k;
    cin>>n>>k;
    vector<int> h(n);
    for(int i=0;i<n;i++)
    {
        cin>>h[i];
        cache[i]=-1;
    }
    cache[n]=-1;

    lli res = getmin(h,0,k,n);
    cout<<res<<endl;
}

int main()
{
 solve();
}


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


using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<string> &o) {
    string a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

typedef pair<ll, ll> P;


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

    vector<ll> cats(n);
    rep(i, n) cin >> cats[i];

    ll ma = *max_element(cats.begin(), cats.end());
    ll mi = *min_element(cats.begin(), cats.end());

    if (ma - mi >= 2) {
        cout << "No" << endl;
        ret();
    }
    if (ma - mi == 1) {
        ll x = count(cats.begin(), cats.end(), ma - 1);
        ll y = count(cats.begin(), cats.end(), ma);
        if (x < ma && 2 * (ma - x) <= y) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
        ret();
    }

    if (ma == n - 1 || 2 * ma <= n) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

}


Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>

#include<vector>
#include<string>

#include<algorithm>
#include<cmath>
using namespace std;
typedef long long ll;
const ll INF = 1e12+1;
template <class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;}
template <class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;}

int N,M;
int G[8][8];
int visited[8];

void dfs_(int u, int &cnt) {
    bool flag = true;
    for (int i = 0; i < N; i++) {
        if (!visited[i]) flag = false;
    }
    if (flag) cnt++;
    for (int i = 0; i < N; i++) {
        if (G[u][i] && !visited[i]) {
            visited[i] = true;
            dfs_(i,cnt);
            visited[i] = false;
        }
    }
    
}

int dfs() {
    int cnt = 0;
    visited[0] = true;
    dfs_(0,cnt);
    return cnt;
}

int main() {
    cin >> N >> M;
    for (int i = 0; i < M; i++) {
        int a, b;
        cin >> a >> b;
        a--;b--;
        G[a][b] = 1;G[b][a] = 1;
    }
    int res = dfs();
    cout << res << endl;
}


Measured memory_bytes: 256
n, q = map(int, input().split())

buf = [i for i in range(n)]
height = [1] * n

def find(i):
    while i != buf[i]:
        i = buf[i]
    return i

def union(i, j):
    i = find(i)
    j = find(j)
    if height[i] >= height[j]:
        buf[j] = i
        height[i] = max(height[i], height[j] + 1)
    else:
        buf[i] = j
        height[j] = max(height[j], height[i] + 1)

for _ in range(q):
    com, x, y = map(int, input().split())
    if com == 0:
        # unite                                                                                                                                                                                             
        union(x, y)
    else:
        if find(x) == find(y):
            print(1)
        else:
            print(0)




Measured memory_bytes: 6028
from collections import deque
H, W = [int(n) for n in input().split()]
map = [0 for _ in range(H)]
INF = 10**8
dis = [[INF for _ in range(W)]for __ in range(H)]
Q = deque()
for i in range(H):
    map[i] = list(str(input()))
    for j in range(W):
        if map[i][j] == "#":
            Q.append((i, j))
            dis[i][j] = 0
dxy = [[1, 0], [0, 1], [-1, 0], [0, -1]]
ans = 0
while(len(Q) != 0):
    n = Q.pop()
    for d in dxy:
        tx, ty = n[0] + d[0], n[1] + d[1]
        if(0 <= tx <= H - 1 and 0 <= ty <= W - 1 and map[tx][ty] == "."):
            map[tx][ty] = "#"
            Q.appendleft((tx, ty))
            dis[tx][ty] = dis[n[0]][n[1]] + 1
            ans = max(dis[tx][ty], ans)
print(ans)
# for i in range(H):
#     print(dis[i])


Measured memory_bytes: 123868
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <regex>
using namespace std;
using pii  = pair<int,int>;
using ll=long long;
using ld=long double;
#define pb push_back
#define mp make_pair
#define stpr setprecision
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<(n);++i)
#define Rep(i,a,b) for(ll i=(a);i<(b);++i)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define rRep(i,a,b) for(int i=a;i>=b;i--)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
ll gcd(ll a,ll b){return (b == 0 ? a : gcd(b, a%b));}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll MOD=1000000007;
constexpr ll INF=1000000011;
constexpr ll MOD2=998244353;
constexpr ll LINF = 1001002003004005006ll;
constexpr ld EPS=10e-8;
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<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}
template<class T> ostream& operator<<(ostream& os, vector<T>& v){
    for(auto i=begin(v); i != end(v); ++i){
        if(i !=begin(v)) os << ' ';
        os << *i;
    }
    return os;
}

map<ll,ll> M;

int main(){
    ll N,r,T=0,c1,c2;
    cin >> N;
    rep(i,N){
        cin >> r;
        M[r]++;
    }
    ll C=0;
    for(auto P : M){
        C++;
        if(C==1){
            c1=P.first;
            c2=P.second;
            if(c1<P.second){
                T=1;
            }
        }
        if(C==2){
            if(P.second!=N-c2 || P.first!=c1+1 || T==1){
                cNo;
                return 0;
            }
            if(P.second/2+c2<P.first){
                cNo;
                return 0;
            }
        }
    }
    if(C==1 && N/2<c1 && c1!=N-1){
        cNo;
    }
    else{
        cYes;
    }
}

Measured memory_bytes: 6528
import java.util.*;

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

        int l = sc.nextInt();
        int r = sc.nextInt();
        int d = sc.nextInt();

        int ans = 0;

        for(int i = l; i <= r; i++){
            if(i % d == 0){
                ans++;
            }
        }

        System.out.println(ans);

    }
}


Measured memory_bytes: 35740
n = int(input())
i = 0
b_top = 0
a_end = 0
ab_and = 0
ab_count = 0
while i < n:
  str = input()
  top_b = False
  if str[0] == 'B':
    b_top += 1
    top_b = True
  if str[-1] == 'A':
    a_end += 1
    if top_b:
      ab_and += 1
  ab_count += str.count('AB')
  i += 1

min_ab = min([b_top, a_end])
if b_top == a_end and b_top == ab_and and b_top > 0:
  min_ab -= 1
print(ab_count + min_ab)

Measured memory_bytes: 3064
#include <cstdio>
#include <functional>
#include <algorithm>
#include <vector>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iostream>
#include <queue>
#include <math.h>
#include <bits/stdc++.h>

#define INF (1ll<<60)
#define MOD 1000000007
#define BOUND 27182818284

typedef long long ll;
typedef long long int lli;

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

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

using namespace std;

// gcd
template<typename T>
T gcd(T a, T b){
    if(a==0)
        return b;
    return gcd(b%a,a);
}
// gcd array
int findGCD(int arr[], int n){
    int result = arr[0];
    for (int i=1; i < n; i++)
        result = gcd(arr[i], result);

    return result;
}
template<typename T>
T lcm( T m, T n )
{
    // 引数に0がある場合は0を返す
    if ( ( 0 == m ) || ( 0 == n ) )
        return 0;

    return ((m/gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}

// sort big to small
// sort(A,A+N, greater<int>());

// v.front() = -BOUND;
// v.back() = BOUND;

// Iterator
// v.begin
// v.end

int main() {
    long long N,x;
    string ans="YES";
    string S;
    string erase="erase", eraser="eraser", dream="dream",dreamer="dreamer";
    reverse(erase.begin(),erase.end());
    reverse(eraser.begin(),eraser.end());
    reverse(dream.begin(),dream.end());
    reverse(dreamer.begin(),dreamer.end());

    cin >> S;
    reverse(S.begin(),S.end());

    long long size=S.length();
    S+=S+"aaaaaa";
    long long current=0;
    while(size>current){
        if(S.substr(current,erase.length())==erase)
            current += erase.length();
        else if(S.substr(current,eraser.length())==eraser)
            current+=eraser.length();
        else if(S.substr(current,dream.length())==dream)
            current+=dream.length();
        else if(S.substr(current,dreamer.length())==dreamer)
            current+=dreamer.length();
        else{
            ans="NO";
            break;
        }
    }
    if(size!=current){
        ans="NO";
    }

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



Measured memory_bytes: 672
a = int(raw_input())
b = int(raw_input())
c = int(raw_input())

s = 3*c

print a,b,s-a-b
print s-(c+s-(s-a-b+s-a-c)),c,s-(s-a-b+s-a-c)
print a+b-c,s-b-c,s-a-c

Measured memory_bytes: 2696
#include <bits/stdc++.h>
#define FOR(i, a, b) for (long long i = (a); i < (b); i++)
using namespace std;
typedef long long ll;
int main() {
  ll n, k, ans = 0;
  cin >> n >> k;
  if (k == 0) return !printf("%lld\n", n * n);
  FOR(i, k + 1, n + 1) ans += n / i * (i - k) + max((ll)0, n % i - k + 1);
 printf("%lld\n", ans);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int dp[4][50][50][1 << 12];
int H, W, K;
char mas[50][50];
int dy[] = { 0, 1, 0, -1}, dx[] = { 1, 0, -1, 0};
int mask;

int getdir(int bit, int i){
  return (bit >> (i * 2)) & 3;
}
#define INF (1 << 30)
int rec(int x, int y, int mul, int bit){
  if(y == H - 1 && x == W - 1 && mul == 0) return 0;
  if(~dp[mul][y][x][bit]) return dp[mul][y][x][bit];

  int ret = -INF, value = 0, mx = x, my = y;
  bool hoge = false;
  if(mas[y][x] != '.'){
    for(int i = 0; i < 2 * K; i++){
      my -= dy[getdir( bit, i)];
      mx -= dx[getdir( bit, i)];
      if(mx == x && my == y){
        hoge = true;
        break;
      }
    }
    if(!hoge) value = mas[y][x] - '0';
  }

  for(int i = 0; i < 4; i++){
    if(mul == 0 && i > 1) break;
    int ny = y + dy[i], nx = x + dx[i];
    if(ny < 0 || ny >= H || nx < 0 || nx >= W || mas[ny][nx] == '#') continue;
    ret = max( ret, rec( nx, ny, mul - (i > 1), ((bit << 2)|i) & mask) + value);
  }
  return dp[mul][y][x][bit] = ret;
}

int main()
{
  cin >> H >> W >> K;
  mask = (1 << (K * 2 * 2)) - 1;
  for(int i = 0; i < H; i++){
    for(int j = 0; j < W; j++){
      cin >> mas[i][j];
    }
  }
  fill_n( ***dp, 4 * 50 * 50 * (1 << 12), -1);
  cout << rec( 0, 0, K, 0) << endl;
  return 0;
}

Measured memory_bytes: 161172
#include <iostream>
#include <string>

using namespace std;

int main()
{
	string s;
	
	cin >> s;
	
	for (int i = 0; i < (int)s.size(); i += 2) {
		cout << s[i];
	}
	
	cout << "\n";
	
	return (0);
}

Measured memory_bytes: 512
// By Mohit Gupta
#include <bits/stdc++.h>
using namespace std;
#define printint(v) copy(begin(v), end(v), ostream_iterator<int>(cout," "))
#define printintv(s,e) copy(s,e, ostream_iterator<int>(cout," "))
#define forstl(i,v) for(auto &i: v)
#define forn(i,e) for(int i = 0; i < e; i++)
#define forsn(i,s,e) for(int i = s; i < e; i++)
#define rforn(i,s) for(int i = s; i >= 0; i--)
#define rforsn(i,s,e) for(int i = s; i >= e; i--)
#define clz(a) __builtin_clz(a) // count leading zeroes
#define ctz(a) __builtin_ctz(a) // count trailing zeroes
#define popc(a) __builtin_popcount(a) // count set bits (for ints only diff for ll)
//https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html for other in built
#define ln "\n"
#define dbg(x) cout<<#x<<" = "<<x<<ln
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define int long long
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
typedef pair<int,int> p32; 
typedef pair<ll,ll> p64;
typedef pair<double,double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int> > vv32;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
typedef map<int,int> m32;
#pragma GCC optimize ("-O2")
const int LIM = 2e5+5, MOD = 998244353;
int t,n,m,k,x,y;
 

int a[LIM]; 
int dp[LIM][2];

int32_t main()
{
	IOS;
	cin>>n;
	forsn(i,1,n+1) cin>>a[i];
// 	if i number seen : f <= [i+1/2] and l <= [N-i+1/2] and f+l=[N/2]
// 	==>  [N/2]-[N-i+1/2]  <= f <= [i+1/2]
// 	if i odd:  i/2 <= f <= i+1/2
//   otherwise   i/2 + [N/2] - [N+1/2] <= f <= i/2
	dp[2][0]=a[1];
	dp[2][1]=a[2];
	for(int i=3;i<=n;i++){
		if(i&1){
			dp[i][0]=max(dp[i-1][1],dp[i-1][0]);
			dp[i][1]=a[i]+max(dp[i-2][0],dp[i-2][1]);
		}
		else{
			dp[i][0]=a[i-1]+dp[i-2][0];
			dp[i][1]=a[i]+max(dp[i-2][0],dp[i-2][1]);
		}
	}
	cout<<max(dp[n][0],dp[n][1])<<ln;
}


Measured memory_bytes: 8368
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <numeric>
#include <functional>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <memory>
#include <thread>
#include <tuple>

using namespace std;

const int mod = 1000000007;

vector<int> range_mod_inverse(int n, const int mod){
	vector<int> ret(n+1);
	ret[1] = 1;
	for(int i = 2; i <= n; i++)
		ret[i] = (long long) (mod - mod/i) * ret[mod%i] % mod;
	return ret;
}

vector<long long> getFactorials(int n, const int mod) {
	vector<long long> ret(1,1);
	for (int i = 1; i <= n; i++) ret.push_back((long long)ret.back()*i%mod);
	return ret;
}

vector<long long> getInverseFactorials(int n, const int mod) {
	vector<int> invmod(range_mod_inverse(n, mod));
	vector<long long> ret(1,1);
	for (int i = 1; i <= n; i++) ret.push_back((long long)ret.back()*invmod[i]%mod);
	return ret;
}


vector<long long> facts;
vector<long long> ifacts;

unordered_map<int, long long> dp[303];

int main() {
  facts = getFactorials(300, mod);
  ifacts = getInverseFactorials(300, mod);

  int n, x;
  scanf("%d%d", &n, &x);
  vector<int> s(n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &s[i]);
  }
  sort(s.begin(), s.end(), greater<int>());
  for (int i = 0; i < n; i++) {
    long long iways = facts[n-1] * ifacts[n-1-i] % mod;
    dp[i][x % s[i]] += iways;
    for (int j = 0; j < i; j++) {
      long long mcnt = i - j - 1;
      long long mways = facts[n - (j+1) - 1] * ifacts[n - (j+1) - 1 - (mcnt)] % mod;
      for (const auto &kv : dp[j]) {
        int nx = kv.first % s[i];
        long long nways = kv.second * mways;
        (dp[i][nx] += nways) %= mod;
      }
    }
  }
  long long ans = 0;
  for (const auto &kv : dp[n - 1]) {
    ans += kv.first * kv.second;
    ans %= mod;
  }
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 31744
//author:luckYrat(twitter:@luckYrat_)
//#include <bits/stdc++.h>

//def
#include <iostream>

#include <cmath>
#include <algorithm>
#include <iomanip>

//array
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <utility>
#include <climits>



using namespace std;

using ll = long long;
using P = pair<ll,ll>;

#define anyfill(n,s) setw(n) << setfill(s)
#define loop(s) for(int i = 0; s > i; i++)
#define rep(i,q) for(int i = 0; (q) > i; i++)
#define repp(i,n,q) for(int i = n; (q) > i; i++)
#define dep(i,q) for(int i = (q); 0 < i; i--)


#define MAX 1000000000
const int mod = 1000000007;
#define EPS (1e-10)

#define pb push_back
#define fir first
#define scn second
#define ednl endl

#define YesNo(a) (a?"Yes":"No")
#define YESNO(a) (a?"YES":"NO")
#define yesno(a) (a?"yes":"no")


P ar4[4] = {{0,1},{0,-1},{1,0},{-1,0}};
P ar8[8] = {{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,-1},{1,0},{1,1}};
/*
確認ポイント
cout << fixed << setprecision(n) << 小数計算//n桁の小数表記になる
vector.unique()は隣接した同じ要素を削除するので先にソートをする

計算量は変わらないが楽できるシリーズ
C++11以降でmin({a,b,c...})で複数個のmic,maxを処理できる
min(max)_element(iter,iter)で一番小さい(大きい)値のポインタが帰ってくる
count(iter,iter,int)でintがiterからiterの間にいくつあったかを取得できる

*/
__attribute__((constructor))
void initial() {
 cin.tie(0);
 ios::sync_with_stdio(false);
}
int main(){
  string s;cin>>s;
  sort(s.begin(),s.end());
  if(s[0] == s[2]){
    cout << "No" << endl;
  }else{
    cout << "Yes" << endl;
  }
}

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


bool check(vector<string> &s){
    bool isok=true;
    int n=s.size();
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            isok&=(s[i][j]==s[j][i]);
        }
    }
    return isok;
}
int main(){
    int n;
    cin>>n;
    vector<string> s(n);
    for(int i=0;i<n;i++) cin>>s[i];

    int res=0;
    for(int x=-(n-1);x<n;x++){
        vector<string> ss=s;
        int a=max(-x,0),b=a+x;
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                ss[(i+a)%n][(j+b)%n]=s[i][j];
            }
        }
        res+=check(ss)*(n-abs(x));
    }
    cout<<res<<endl;
    return 0;
}

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

int main(){
	int a,b,c,x,r=0;
	cin >> a >> b >> c;
	for(x =a;x <= b;x++){
		if ( c % x == 0){
			r++;
		}
	}

	cout<<r<<endl;
	return 0;
	}






Measured memory_bytes: 3124
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
using namespace std;
#define rep(i, s, n) for(int i = s; i < n; i++) 

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

    int dp[s.size()+1][t.size()+1];
    rep(i, 0, s.size()+1) {
        dp[i][0] = i;
    }
    rep(i, 0, t.size()+1) {
        dp[0][i] = i;
    }
    rep(i, 1, s.size()+1) {
        rep(j, 1, t.size()+1) {
            int cost = 0;
            if(s[i-1] == t[j-1]) cost = 0;
            else cost = 1;
            dp[i][j] = min(dp[i-1][j]+1, min(dp[i][j-1]+1, dp[i-1][j-1]+cost));
        }
    }
    cout << dp[s.size()][t.size()] << endl;
    return 0;
    
}


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

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

    vector<int> P(M),Y(M);

    for(int i = 0; i < M; i++){
        cin >> P[i] >> Y[i];
        P[i]--;
    }

    vector<vector<int>> vals(N);

    for(int i = 0; i < M; i++){
        vals[P[i]].push_back(Y[i]);
    }

    for(int i = 0; i < N; i++){
        sort(vals[i].begin(),vals[i].end());
    }

    for(int i = 0; i < M; i++){
        int v = P[i];
        printf("%06d",v+1);
        int id = lower_bound(vals[v].begin(),vals[v].end(),Y[i])-vals[v].begin();
        printf("%06d\n", id+1);
    }
}

Measured memory_bytes: 7808
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
int main() {
  int a,b,c,d;
  cin >> a >> b >> c >> d;

  string out;
  if((a+b)>(c+d)) out="Left";
  else if((a+b)<(c+d)) out="Right";
  else if((a+b)==(c+d)) out="Balanced";

  cout << out << endl;
  return 0;
}


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

int main() {
	int n; cin >> n;
	vector<vector<int>>pab(n, vector<int>(3,0));
	for (int i = 0; i < n; i++) {
		int a, b;
		cin >> a >> b;
		pab.at(i).at(0) = a + b;
		pab.at(i).at(1) = a;
		pab.at(i).at(2) = b;
	}
	sort(pab.begin(), pab.end());
	reverse(pab.begin(), pab.end());
	bool x = true;
	ll ans = 0;
	for (int i = 0; i < n; i++) {
		if (x) {
			ans += pab.at(i).at(1);
			x = false;
		}
		else {
			ans -= pab.at(i).at(2);
			x = true;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 5888
use std::io::*;

fn read<T: std::str::FromStr>() -> T {
    let stdin = stdin();
    let mut buf = String::new();
	stdin.lock().read_line(&mut buf);
	buf.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
	read::<String>().trim().split_whitespace()
        .map(|w| w.parse().ok().unwrap()).collect()
}

fn read_mat<T: std::str::FromStr>(n: usize) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

fn main() {
    let n = read::<usize>();
    let mut rv = read_mat::<i32>(n);
    rv.sort_by_key(|v| v[0]);
    let mut bv = read_mat::<i32>(n);
    bv.sort_by_key(|v| v[0]);
    let mut ans = 0;
    for b in bv {
        let mut maxy = -1;
        let mut maxi = 0;
        for i in 0..rv.len() {
            if rv[i][0] >= b[0] {break;}
            if rv[i][1] < b[1] && rv[i][1] >= maxy {
                maxy = rv[i][1];
                maxi = i;
            }
        }
        if maxy >= 0 {
            ans += 1;
            rv.remove(maxi);
        }
    }
    println!("{}",ans);
}


Measured memory_bytes: 4352
#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 dist(a,b,p,q) sqrt((p-a)*(p-a) + (q-b)*(q-b))

# define pp(n) printf("%.10Lf",n);
# define line cout<<"\n";
# define fast ios_base::sync_with_stdio(false) ; cin.tie(0) ; cout.tie(0);

string vow = "aeiou";

const int dxhorse[] = {-2, -2, -1, -1, 1, 1, 2, 2};
const int dyhorse[] = {1, -1, 2, -2, 2, -2, 1, -1};

const int dx[] = { -1 , 0 , 0 , 1 } ;
const int dy[] = { 0 , -1 , 1 , 0 } ;

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

void solve ( int test_case )
{
    vs v { "SUN" , "MON" , "TUE" , "WED" , "THU" , "FRI" , "SAT" } ;
    string s ; cin >> s ;

    if ( s == "SUN" ) cout << 7 ;
    else
    {
        int c = 0 ;
        int i=0 ;

        for ( ; i < 7 && s != v[i] ; i ++ ) ;

        for ( c = 0 ; v[i] != "SUN" ; c ++ , i ++ , i %= 7 ) ;
        cout << c ; line
    }
}

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

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


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

typedef long long ll;
typedef vector<ll>   lve;
typedef vector<char>     cve;
typedef vector<pair<ll,ll> > lvp;
typedef vector<pair<string,int>> svp;

#define spc        ' '
#define endl       '\n'
#define F          first
#define S          second
#define pp         pop_back
#define PI         2*acos(0)
#define pb         push_back
#define mp         make_pair
#define GCD(x,y)   __gcd(x,y)
#define lb         lower_bound
#define up         upper_bound
#define bs         binary_search
#define For(i,j,k) for(i=j;i<k;i++)
#define FOR(i,j,k) for(i=j;i>=k;i--)
#define LCM(x,y)   ((x*y)/__gcd(x,y))
#define sp(x)      cout<<fixed<<setprecision(x)

const   long long  inf=1e18;
const   long long  mod=1e9+7;
const   long long  cs=200005;
int main()
{	
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);    cout.tie(NULL);
    
    ll t,n,m,a,b,c,d,e,i,j,k,x,y,z,flag=0;
    
    cin>>t;
    lve v;
    For(i,0,t)
    {
    	cin>>a;
    	v.pb(a);
    	if(a==0) flag=2;
    }
    if(flag==2) {cout<<"0"<<endl;return 0;}
    k=1;
    For(i,0,t)
    {
    	if(v[i]==0) {k=0;break;}
    	else if((inf/k)<v[i]) {flag=1;break;}
    	k=k*v[i];
    }
    if(!flag) cout<<k<<endl;
    else cout<<"-1"<<endl;
    return 0;
}

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

using namespace std;

typedef long long ll;
#define mems(p) memset(p,-1,sizeof(p))
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define nl "\n"

const int mxN = 1e5;
const ll MOD = 1e9 + 7;

void fast()
{ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);}

ll gcd(ll a, ll b) {
	return b ? gcd(b, a%b) : a;
}

bool sorter(pair<ll,bool> a, pair<ll,bool> b) {
	return a.first > b.first;
}

int main() {
	fast();
	int n, k;
	cin >> n >> k;
	vector<pair<ll,bool>> a(n);
	int totalNegs = 0;
	for (int i = 0; i < n; ++i)
	{
		cin >> a[i].first;
		if (a[i].first < 0) {
			a[i].first = -a[i].first;
			a[i].second = true;
			++totalNegs;
		} else {
			a[i].second = false;
		}
	}
	sort(a.begin(),a.end(),sorter);
	int negs = 0, lastpos = -1, lastneg = -1;
	for (int i = 0; i < k; ++i) {
		if (a[i].second) {
			++negs;
			lastneg = i;
		} else {
			lastpos = i;
		}
	}
	if (negs % 2 == 1) {
		// check if can >= 0
		if (totalNegs == n || k == n) {
			ll ans = 1;
			for (int i = n - 1; i > n - 1 - k; --i) {
				ans *= a[i].first;
				ans %= MOD;
			}
			if (ans > 0) {
				ans = MOD - ans;
			}
			cout << ans << nl;
			return 0;
		}
		// either take extra neg or extra pos
		ll ans = 1;
		ll pos1 = -1, neg1 = -1;
		for (int i = 0; i < k; ++i)
		{
			if (i == lastneg) {
				neg1 = a[i].first;
				continue;
			}
			ans *= a[i].first;
			ans %= MOD;
		}
		bool found = false;
		for (int i = k; i < n; ++i) {
			if (!a[i].second) {
				pos1 = a[i].first;
				ans *= a[i].first;
				ans %= MOD;
				found = true;
				break;
			}
		}
		if (!found) {
			ans = -1;
		}
		ll ans2 = 1;
		ll neg2 = -1, pos2 = -1;
		if (negs < k) {
			for (int i = 0; i < k; ++i)
			{
				if (i == lastpos) {
					pos2 = a[i].first;
					continue;
				}
				ans2 *= a[i].first;
				ans2 %= MOD;
			}
			bool found = false;
			for (int i = k; i < n; ++i) {
				if (a[i].second) {
					neg2 = a[i].first;
					ans2 *= a[i].first;
					ans2 %= MOD;
					found = true;
					break;
				}
			}
			if (!found) {
				ans2 = -1;
			}
		}

		// first one reduce neg, plus pos -> divide by neg, times by pos -> times pos/neg
		// second one times neg/pos
		//cout << "pos1: " << pos1 << " neg1: " << neg1 << " pos2: " << pos2 << " neg2: " << neg2 << nl;
		//cout << "ans1: " << ans << " ans2: " << ans2 << nl;
		ll trueAns = 0;
		if (pos1 == -1) {
			trueAns = ans2;
		} else if (pos2 == -1) {
			trueAns = ans;
		} else if (pos1 * pos2 > neg1 * neg2) {
			trueAns = ans;
		} else {
			trueAns = ans2;
		}
		cout << trueAns << nl;
	} else {
		ll ans = 1;
		for (int i = 0; i < k; ++i)
		{
			ans *= a[i].first;
			ans %= MOD;
		}
		cout << ans << nl;
	}
}

Measured memory_bytes: 6360
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define oset tree < int ,  null_type ,  less ,  rb_tree_tag ,  tree_order_statistics_node_update >
#define endl '\n'
#define int long long int
#define db long double
#define str string
#define mod 1000000007
#define ff first
#define ss second
#define PQi priority_queue<int>
#define Vi vector<int>
#define Si set<int>
#define Li list<int>
#define mk make_pair
#define pii pair<int,int>
#define all(x) (x.begin(),x.end())
#define pb(x) push_back(x)
#define For(i,n,s) for(int i=s;i<n;i++)
#define mat2D(T,r,c) vector<vector<int> > T(r,vector<int>(c))
#define vec2D vector<vector<int> >
#define fastIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define getVal(x) {int val;cin>>val;x.pb(val);}
#define debug(x) {for(auto i :x) cout << i << " ";cout << endl;}

bool isSmaller(string a, string b) {
    int n = a.length(), m = b.length();
    if (n < m)
        return true;
    if (n > m)
        return false;
    For(i, n, 0) {
        if (a[i] < b[i])
            return true;
        else if (a[i] > b[i])
            return false;
    }
    return false;
}

void solve() {
    string a, b;
    cin >> a >> b;
    if (a == b) {
        cout << "EQUAL";
    } else {
        cout << (isSmaller(a, b) ? "LESS" : "GREATER");
    }
}

int32_t main() {
    fastIO;
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
# endif
    solve();
    return 0;
}

Measured memory_bytes: 3628
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<unordered_map>
#include<stack>
#include<queue>
#include<iomanip>
#include<math.h>
#include<bitset>
#include<cassert>
#include<random>
#include<time.h>
#include<functional>
using namespace std;
using ll=long long;
using ld=long double;
using pint=pair<int,int>;
using pll=pair<ll,ll>;
#define MOD 1000000007LL
#define INF 1000000000LL
#define EPS 1e-10
#define FOR(i,n,m) for(ll i=n;i<(ll)m;i++)
#define REP(i,n) FOR(i,0,n)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define ALL(v) v.begin(),v.end()
#define UNIQUE(v)  sort(ALL(v));v.erase(unique(ALL(v)),v.end());
#define pb push_back

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<ll> l(n);
	REP(i, n) cin >> l[i];
	sort(ALL(l));
	ll sum1 = 0;
	REP(i, n - 1) sum1 += l[i];
	if(l[n - 1] < sum1) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

/* --------------------------------------- */


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


int main(){
    int n;
    vector<int>s(30);
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>s[i];
    
    }
    int ans=0;

    for(int i=1;i<n-1;i++){
        if(s[i]<s[i+1]||s[i]<s[i-1]){
            if(s[i]>s[i+1]||s[i]>s[i-1]){
            ++ans;
        //cout<<s[i]<<endl;
        }
    }

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


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

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


using namespace std;

const int M = 1000005;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  vector<int> cnt(M);
  for(int x : a) {
    if(cnt[x] != 0) {
      cnt[x] = 2;
      continue;
    }
    for(int i = x; i < M; i+= x) cnt[i]++;
  }
  int ans = 0;
  for(int x : a) {
    if(cnt[x] == 1) ans++;
  }
  cout << ans << endl;
  return 0;
}


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

int main(){
  int n;
  cin >> n;
  n = n % 10;
  if(n == 3) cout << "bon" << endl;
  else if(n == 0 || n == 1 || n == 6 || n == 8) cout << "pon" << endl;
  else cout << "hon" << endl;
  return 0;
}


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

int main()
{
	int N;
	string S;

	cin >> N;
	cin >> S;

	if ( (N & 1) || S.substr(0, N / 2) != S.substr(N / 2, N / 2) ) cout << "No" << endl;
	else cout << "Yes" << endl;

	return ( 0 );
}


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

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

    bool ok = true;
    int len = (s.length() - 1) / 2;
    int len2 = (s.length() + 3) / 2;
    for (int i = 0; i < len; i++){
        if (s[i] != s[len - i - 1]){
            ok = false;
            break;
        }
    }

    for (int i = len2; i < s.length(); i++){
        if (s[i] != s[s.length() - 1 - i]){
            ok = false;
            break;
        }
    }

    if (ok)
        cout << "Yes\n";
    else
        cout << "No\n";

    return 0;
}


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

int main() {
    int n;
    cin >> n;
    vector<P> edges[n];
    
    rep(i, n-1){
        int u, v, w;
        cin >> u >> v >> w;
        u--;
        v--;
        /*
        edges[u].push_back(make_pair(v, w))
        edges[v].push_back(make_pair(u, w))
        */
        edges[u].emplace_back(v, w);
        edges[v].emplace_back(u, w);
    };
    
    vector<bool> visited(n, false);
    vector<int> colors(n, -1);
    stack<int> stk;
    stk.emplace(0);
    while (stk.size() != 0){   
        int p = stk.top();
        stk.pop();
        for (P c : edges[p]){
            if(visited[c.first]) continue;
            visited[c.first] = true;
            stk.push(c.first);
            if (c.second % 2 == 0)
                colors[c.first] = colors[p];
            else colors[c.first] = (-1)*colors[p];
        }
    }
        
    rep(i, n){
        if (colors[i] == -1) cout << 0 << endl;
        else cout << 1 << endl;
    }
}

Measured memory_bytes: 9580
from collections import defaultdict

T = int(input())
for t in range(T):
    N, A, B, C, D = map(int, input().split())

    memo = {0: 0, 1: D}

    def dfs(n):
        if n in memo:
            return memo[n]
        
        ret = min(n * D, 
                  dfs(n//2) + (n - n//2*2) * D + A,
                  dfs(-(-n//2)) + (-(-n//2)*2 - n) * D + A,
                  dfs(n//3) + (n - n//3*3) * D + B,
                  dfs(-(-n//3)) + (-(-n//3)*3 - n) * D + B,
                  dfs(n//5) + (n - n//5*5) * D + C,
                  dfs(-(-n//5)) + (-(-n//5)*5 - n) * D + C)

        memo[n] = ret
        return ret

    print(dfs(N))


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

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

    if(S.size()<=K) cout << S << endl;
    else{
        string ans = "";
        rep(i, K){
            ans += S.at(i);
        }

        cout << ans + "..." << endl;
    }
}

Measured memory_bytes: 3632
#include <stdlib.h>
#include <iostream>
#include <vector>

using namespace std;

int getColor(int i);

int main()
{
	int n, k;
	cin >> n;
	cin >> k;
	int t = n / 2 + n % 2;

	for (int i = 0; i < k; i++) {
		int a, b;
		cin >> a >> b;
		int lx = a, ly = b;
		if (a > t) lx = n - a + 1;
		if (b > t) ly = n - b + 1;
		
		int c;
		if (lx == t && ly == t) c = getColor(t);
		if (ly >= lx) {
			c = getColor(lx);
		} else {
			c = getColor(ly);
		}
		cout << c << endl;
	}

	return 0;
}
int getColor(int i) {
	int c = i % 3;
	if (c == 0) return 3;
	return c;
}

Measured memory_bytes: 1160
import java.util.Scanner;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
int b = sc.nextInt();
if(a < b){
System.out.println("a < b");
}else if(a > b){
System.out.println("a > b");
}else{
System.out.println("a == b");
}
}
}


Measured memory_bytes: 26044
#include<stdio.h>
#include<string.h>
using namespace std;

char s[200];
char c[20];
int main()
{
	int i, j, len, k, len1;
	bool b = 0;
	scanf("%s", s);
	len = strlen(s);
	
	if (strcmp(s, "keyence") == 0)
	{
		printf("YES");
		return 0;
	}

	for (i = 0; i < len; ++i)
		for (j = i; j < len; ++j)
		{
			if (len - (j - i + 1) != 7) continue;
			len1 = 0;
			for (k = 0; k < len; ++k)
			{

				if (k < i || k > j) c[len1++] = s[k];

			}
			c[len1] = '\0';
		
				if (strcmp(c, "keyence") == 0)
	{
		printf("YES");
		return 0;
	}
		}
		printf("NO\n");
		return 0;

}

Measured memory_bytes: 128
n,m=map(int,input().split())
a=[0]*n
b=[0]*n
ac=0
pe=0
for i in range(m):
    p,s=input().split()
    if a[int(p)-1]==0:
        if s=="AC":
            a[int(p)-1]=1
            ac+=1
            pe+=b[int(p)-1]
        else:
            b[int(p)-1]+=1
print(ac,pe)

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

using namespace std;
typedef long long ll;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n,k;
    cin >> n >> k;
    vector<int> a(n,0);
    for(int i=0;i<n;i++) cin >> a[i];
    while(k--)
    {
        vector<int> d(n+1,0);
        for(int i=0;i<n;i++)
        {
            d[max(0,i-a[i])]++;
            d[min(n,i+a[i]+1)]--;
        }
        int x=0;
        for(int i=0;i<n;i++)
        {
            x+=d[i];
            a[i]=x;
        }
        bool ok=1;
        for(int i=0;i<n;i++) ok&=(a[i]==n);
        if(ok) break;
    }
    for(int i=0;i<n;i++) cout << a[i] << " \n"[i==n-1];
    return 0;
}


Measured memory_bytes: 4840
/* ex 9_2
   nnasy */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
//スタックに格納するデータの最大数
#define SIZE 100001

//リストのノード（スタック内の各データ）の定義
typedef struct node{
    char elem;
    struct node *next;
} node;

//スタックにデータを追加
void push(node **first, char elem){
    //追加する分の領域を確保
    node *new = calloc(1, sizeof(node));
    if(new == NULL) exit(1);
    new->elem = elem;
    new->next = *first;
    *first = new;
}

//スタックからデータを取り出す
char pop(node **first){
    char elem;
    node *tmp = *first;
    if(tmp == NULL) exit(1);
    elem = tmp->elem;
    *first = tmp->next;
    //取り出したノードのメモリを解放
    free(tmp);
    return elem;
}

int main(void){
    //count: 取り除いたキューブの数
    int count = 0;
    //input: 入力文字列
    char input[SIZE];
    //入力
    scanf("%s", input);
    //最初のノードの指す先
    node *first = NULL;

    //取り除くキューブの数の計算
    for (int i=0; i<strlen(input); i++){
        //比較対象がないとき文字を入れるだけ
        if (first==NULL){
            push(&first, input[i]);
        }else{
            //文字が異なるときはその文字を入れる
            if (input[i]==first->elem){
                push(&first, input[i]);
            //文字が同じときは手前の文字を除き、カウントを増やす
            }else{
                pop(&first);
                count += 2;
            }
        }
    }

    //出力
    printf("%d\n", count);
    
    return 0;
}

Measured memory_bytes: 4932
import itertools

N,M,Q = map(int, input().split())
x = [list(map(int, input().split(" "))) for i in range(Q)]
list = list(itertools.combinations_with_replacement(range(1,M+1),N))


tmp = 0
mx = 0
for k in range(len(list)):
    for i in range(Q):
        a = x[i][0]
        b = x[i][1]
        c = x[i][2]
        d = x[i][3]
        if(list[k][b-1] - list[k][a-1]) == c:
            tmp += d
    mx = max(mx,tmp)
    tmp = 0

print(mx)


Measured memory_bytes: 21500
#include <stdio.h>

int main(){
	int N,a,b,c,i;

	scanf("%d\n",&N);
	for(i=0;i<N;i++){
		scanf("%d %d %d",&a,&b,&c);
		if(a*a+b*b==c*c) printf("YES\n");
		else if(b*b+c*c==a*a) printf("YES\n");
		else if(a*a+c*c==b*b) printf("YES\n");
		else printf("NO\n");
	}

	return(0);
}

Measured memory_bytes: 580
#include<iostream>
using namespace std;
string a;
bool fl;
int main(){
	cin>>a;
	int i;
	for(i=0;i<a.length();i++){
		if(a[i]=='C'){
			for(int j=i;j<a.length();j++)
				if(a[j]=='F'){
					fl=1;break;
				}
			break;
		}
	}
	if(fl) cout<<"Yes";
	else cout<<"No";
	return 0;
} 

Measured memory_bytes: 256
#![allow(unused_mut)]
#![allow(non_snake_case)]
#![allow(unused_variables)]
#![allow(unused_imports)]
#![allow(dead_code)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        T: f64,
        X: f64,
    }
    println!("{}", T/X);
}



Measured memory_bytes: 4352