akhauriyash/Code-Regression huggingface dataset:
// IO
#include <cstdio>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm
#include <algorithm>
#include <cmath>
#include <numeric>

// container
#include <vector>
#include <string>
#include <tuple>
#include <set>
#include <map>
#include <unordered_map>
#include <stack>
#include <queue>
#include <deque>

// others
#include <random>
#include <limits>
#include <functional>
#include <ctime>
#include <cassert>

// type alias
using lint = long long;
using ldouble = long double;
template <class T>
using greater_priority_queue = std::priority_queue<T, std::vector<T>, std::greater<T>>;


/* ----- class ----- */

template <class Cost = int>
struct Edge {
    int src, dst;
    Cost cost;
    Edge(int src = -1, int dst = -1, Cost cost = 1)
        : src(src), dst(dst), cost(cost){};

    bool operator<(const Edge<Cost>& e) const { return this->cost < e.cost; }
    bool operator>(const Edge<Cost>& e) const { return this->cost > e.cost; }
};

template <class Cost = int>
using Edges = std::vector<Edge<Cost>>;

template <class Cost = int>
using Graph = std::vector<std::vector<Edge<Cost>>>;


/* ----- debug ----- */

#if __has_include("../setting/source/debug.hpp")
#include "../setting/source/debug.hpp"
#endif


/* ----- short functions ----- */

template <class T>
inline T sq(T a) { return a * a; }

template <class T>
inline T iceil(T n, T d) { return (n + d - 1) / d; }

template <class T>
T gcd(T a, T b) {
    while (b > 0) {
        a %= b;
        std::swap(a, b);
    }
    return a;
}

template <class T, class U>
T ipow(T b, U n) {
    T ret = 1;
    while (n > 0) {
        if (n & 1) ret *= b;
        n >>= 1;
        b *= b;
    }
    return ret;
}

// 0-indexed
template <class T, class U>
inline T kthbit(T a, U k) { return (a >> k) & 1; }

template <class T, class U>
inline T mask(T a, U k) { return a & ((1 << k) - 1); }

template <class T>
std::map<T, int> compress(std::vector<T>& v) {
    std::sort(v.begin(), v.end());
    v.erase(std::unique(v.begin(), v.end()), v.end());

    std::map<T, int> rev;
    for (int i = 0; i < v.size(); ++i) rev[v[i]] = i;
    return rev;
}

template <class T>
T Vec(T v) { return v; }

template <class T, class... Ts>
auto Vec(size_t l, Ts... ts) {
    return std::vector<decltype(Vec<T>(ts...))>(l, Vec<T>(ts...));
}


/* ----- constants ----- */

// const int INF = std::numeric_limits<int>::max() / 3;
// const lint INF = std::numeric_limits<lint>::max() / 3;
// const ldouble PI = acos(-1);
// const ldouble EPS = 1e-10;
// std::mt19937 mt(int(std::time(nullptr)));


using namespace std;

int main() {
    string A, B, C;
    cin >> A >> B >> C;
    cout << (A.back() == B.front() &&
                     B.back() == C.front()
                 ? "YES"
                 : "NO")
         << endl;
    return 0;
}


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

#define inf 0x3f3f3f3f
#define pi acos(-1)
#define fi first
#define se second
#define pb push_back
#define int long long
#define all(a) a.begin(),a.end()
template<class T> bool mmin(T &a,T b){return (a>b ?(a=b,true):false);};
template<class T> bool mmax(T &a,T b){return (a<b ?(a=b,true):false);};

string str;
int out;
void back(int id,int val,int sum){
	if(id==str.size()){
		out+=sum+val;
		//cout << sum+val << '\n';
		return ;
	}
	back(id+1,val*10+(int)(str[id]-'0'),sum);
	back(id+1,(int)(str[id]-'0'),sum+val);
}
int32_t main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> str;
	back(0,0,0);
	cout << out/2 << '\n';
#ifdef LOCAL_DEFINE
	cerr << "\nTime: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}




Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <map>


#define rep(i, a, b) for ( ll i = (a); i < (b); i++ )
#define per(i, a, b) for ( ll i = (b)-1; i >= (a); i--)
#define pb push_back
#define bg begin()
#define en end()
#define DEBUG_INT(var) printf("the value of "#var" is %lld\n", var)
#define PRINT_ARRAY(name, i) printf("the value of "#name"[%d] is %d\n", (i), name[(i)])
#define DEBUG_ARRAY(name, begin, end) rep(i, begin, end) PRINT_ARRAY(name, i)


using namespace std;

typedef long long ll;


ll N, K;
ll A[100005];
ll dp[50][2];

int main(void) {
    scanf("%lld %lld", &N, &K);
    for (int i = 0; i < N; i++) scanf("%lld", &A[i]);
    
    dp[45][0] = 0;
    bool smaller = false;
    for (int i=45; i>=0; i--) {
      ll num = 0;
      for(ll j=0; j<N; j++) if ((A[j]>>i)&1)  num++;
      
      for (int j=1; j>=0; j--) {
        if (j && !smaller) continue;
        int u = j ? 1 : ((K>>i)&1);
        for (int k=0; k<=u; k++) {
          dp[i][(j || k < u)] = max(dp[i][(j || k < u)], dp[i+1][j] + (1LL<<i)*(k?(N-num) : num));
        }
        if (u) smaller = true;
      
      }
    
    }
    
    printf("%lld\n", max(dp[0][0], dp[0][1]));
    return 0;
}


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

int n, a[4500];
int main() {
	int i;
	cin >> n;
	for(i=1; ; i++) {
		a[i] = a[i-1] + i;
		if(a[i] > n) break;
	}
	while(1) {
		for(; a[i-1] > n; i--);
		if(a[i-1] == n) break;
		printf("%d\n", i);
		n -= i;
	}
	for(i=1; n; i++) {
		printf("%d\n", i);
		n -= i;
	}
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;

public class Hello
{
    public static void Main()
    {
        // Your code here!
        int[] input = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
        int N = input[0];
        int K = input[1];
        int count1 = 0;
        int count2 = 0;
        long sum = 0;

        // Kの倍数である数値の個数を数える
        
        for(int i = 1; i <= N; i++) 
        {
            if(i % K == 0)
            {
                count1 += 1;
            }
        }
        
        
        
        // 余りがKの半分となる数値の個数を数える
        for(int i = 1; i <= N; i++)
        {
            if(i % K == K/2)
            {
                count2 += 1;
            }
        }
        
        sum += (long)count1 * count1 * count1;
        
        if(K % 2 == 0)//Kが偶数のとき
        {
            sum += (long)count2 * count2 * count2;
        }
        
        
        Console.WriteLine(sum);
    }
}

Measured memory_bytes: 13268
#include <iostream>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#define REP(i,n) for (int i=0;i<(n);i++)
using namespace std;

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

    int maxnum = max({a, b, c});
    int ans = a + b + c - maxnum;
    REP(i, k){
        maxnum = maxnum*2;
    }
    cout << ans + maxnum << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define all(V) V.begin,V.end
const int N = 100005;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int a,p;
    cin >> a >> p;
    int avail = 3*a + p;
    cout << avail/2;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0180

"""
import sys
from sys import stdin
from collections import namedtuple
input = stdin.readline


class DisjointSet(object):
    def __init__(self, size):
        self.rank = []
        self.p = []
        for i in range(size):
            self.makeSet(i)

    def makeSet(self, x):
        self.p.insert(x, x)
        self.rank.insert(x, 0)

    def same(self, x, y):
        return self.findSet(x) == self.findSet(y)

    def unite(self, x, y):
        self.link(self.findSet(x), self.findSet(y))

    def link(self, x, y):
        if self.rank[x] > self.rank[y]:
            self.p[y] = x
        else:
            self.p[x] = y
            if self.rank[x] == self.rank[y]:
                self.rank[y] += 1

    def findSet(self, x):
        if x != self.p[x]:
            self.p[x] = self.findSet(self.p[x])
        return self.p[x]


def kruskal(V, E, es):
    # V: ???????????° (0??????)
    # E: ??¨????????°
    es.sort(key=lambda x: x.c)
    uf = DisjointSet(V)
    res = 0

    for i in range(E):
        e = es[i]
        if not uf.same(e.u, e.v):
            uf.unite(e.u, e.v)
            res += e.c
    return res


edge = namedtuple('edge', ['u', 'v', 'c'])
def main(args):
    while True:
        n, m = map(int, input().split())
        if n == 0 and m == 0:
            break

        es = []
        for _ in range(m):
            s, t, w = map(int, input().split())
            es.append(edge(s, t, w))

        result = kruskal(n, m, es)
        print(result)


if __name__ == '__main__':
    main(sys.argv[1:])
    

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

int main ()
{
    vector<bool> num(2222222, true);
    num[0] = num[1] = false;
    vector<int> prim;
    for (int i = 2; i <= 2222222; i++) {
        for (int j = 2; num[i] && j * i <= 2222222; j++) {
            num[i * j] = false;
        }
        if (num[i]) prim.push_back(i);
    }
    int n;
    while (cin >> n, n) {
        auto i = lower_bound(prim.begin(), prim.end(), n) - prim.begin();

        int res = 0;
        if (n < prim[i]) res = prim[i] - prim[i-1];
        if (n > prim[i]) res = prim[i+1] - prim[i];

        cout << res << endl;
    }

    return 0;
}

Measured memory_bytes: 2260
#include <bits/stdc++.h>
using namespace std;
#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define db3(x, y, z) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define dbv(v) cerr << #v << "="; for (auto _x : v) cerr << _x << ", "; cerr << endl
#define dba(a, n) cerr << #a << "="; for (int _i = 0; _i < (n); ++_i) cerr << a[_i] << ", "; cerr << endl
typedef long long ll;
typedef long double ld;
int main() {
	int n;
	scanf("%d", &n);
	vector<int> b(n);
	for (int i = 0; i < n; ++i) scanf("%d", &b[i]);
	vector<int> a(n);
	for (int i = n - 1; i >= 0; --i) {
		int pick = -1;
		for (int j = i; j >= 0; --j) {
			if (b[j] == j + 1) {
				pick = j;
				break;
			}
		}
		if (pick == -1) {
			printf("-1\n");
			return 0;
		}
		b.erase(b.begin() + pick);
		a[i] = pick + 1;
	}
	for (int x : a) printf("%d\n", x);
}


Measured memory_bytes: 256
s = input()

if s[0] == 'A':
    count = 0
    idx = -1
    for i, ss in enumerate(s[2:-1]):
        if ss == 'C':
            idx = i+2
            count += 1
    if count == 1:
        is_small = True
        for ss in s[1:idx]+s[idx+1:]:
            if ord(ss) < 97:
                is_small = False
                break
        if is_small:
            print('AC')
        else:
            print('WA')
        
    else:
        print('WA')
        
else:
    print('WA')

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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
#define SZ(x) ((int)(x).size())
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 28;
const ll INF64 = 1ll << 55;
const int mod = 1000000007;
//const int mod = 998244353;

template <class T>inline bool chmin(T &a, const T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline bool chmax(T &a, const T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline void line_out(const vector<T> vec) {
  int n = SZ(vec);
  rep(i, n) {
    cout << vec[i];
    if(i < n-1) cout << " ";
  }
  cout << endl;
  return;
}

struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};

int main()
{
  int n;
  string s;
  cin >> n >> s;
  vector<int> e(n+1, 0), w(n+1, 0);
  rep(i, n) {
    if(s[i] == 'E') e[i+1] = 1;
    if(s[i] == 'W') w[i+1] = 1;
  }
  rep(i, n) e[i+1] += e[i];
  rep(i, n) w[i+1] += w[i];
  int ans = INF;
  for(int i = 1; i <= n; ++i) chmin(ans, w[i-1] + (e[n]-e[i]));
  cout << ans << endl;
}



Measured memory_bytes: 6108
#include<bits/stdc++.h>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }


using namespace std;


int N;
deque<int> A[1010];
int step[1010];
int M;
int main() {
    int i, j, k, l, r, x, y;
    string s;

    cin >> N;
    rep(i, N)
    {
        rep(j, N - 1)
        {
            cin >> x;
            A[i].push_back(x - 1);
        }
    }
    M = N * (N - 1) / 2;

    queue<int> Q;
    rep(i, N)
    Q.push(i);

    int num = 0;
    while (Q.size()) {
        int ok = 0;

        queue<int> Q2;

        while (Q.size()) {
            i = Q.front();
            Q.pop();
            if (step[i] <= num && A[i].size() && A[A[i].front()].front() == i && step[A[i].front()] <= num) {
                step[i] = step[A[i].front()] = num + 1;
                Q2.push(i);
                Q2.push(A[i].front());
                A[A[i].front()].pop_front();
                A[i].pop_front();
                M--;
            }
        }
        num++;
        if (M == 0) break;
        swap(Q, Q2);
    }

    if (M) cout << -1 << endl;
    else cout << num << endl;

}

Measured memory_bytes: 4736
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <list>
#include <vector>
#include <cmath>
#include <queue>
#include <algorithm>
using namespace std;
const int INF=(2e9);
const int maxv=100+10;
struct Edge
{
    int to,cap,rev;
};
int V,E;
vector<Edge> g[maxv];
int level[maxv];
int iter[maxv];
void add_edge(int from,int to,int cap)
{
    g[from].push_back((Edge)
    {
        to,cap,g[to].size()
    });
    g[to].push_back((Edge)
    {
        from,0,g[from].size()-1
    });
}
void bfs(int s)
{
    memset(level,-1,sizeof(level));
    queue<int> que;
    que.push(s);
    level[s]=0;
    while(!que.empty())
    {
        int u=que.front();
        que.pop();
        for(int i=0; i<g[u].size(); i++)
        {
            Edge &e=g[u][i];
            if(e.cap>0&&level[e.to]<0)
            {
                level[e.to]=level[u]+1;
                que.push(e.to);
            }
        }
    }
}
int dfs(int s,int t,int f)
{
    if(s==t) return f;
    for(int &i=iter[s]; i<g[s].size(); i++)
    {
        Edge &e=g[s][i];
        if(e.cap>0&&level[e.to]>level[s])
        {
            int d=dfs(e.to,t,min(e.cap,f));
            if(d>0)
            {
                e.cap-=d;
                g[e.to][e.rev].cap+=d;
                return d;
            }
        }
    }
    return 0;
}
int max_flow(int s,int t)
{
    int flow=0;
    int d;

   for(;;)
   {
        bfs(s);
        if(level[t]<0) return flow;
         memset(iter,0,sizeof(iter));
        while((d=dfs(s,t,INF))>0) flow+=d;
    }


}
int main()
{
//    freopen("in.txt","r",stdin);
    scanf("%d%d",&V,&E);
    int u,v,cap;
    for(int i=0; i<E; i++)
    {
        scanf("%d%d%d",&u,&v,&cap);
        add_edge(u,v,cap);
    }
    printf("%d\n",max_flow(0,V-1));
    return 0;
}

Measured memory_bytes: 3260
#include<stdio.h>
#include<string.h>
int main(){
    char wea[3][7]={"Sunny","Cloudy","Rainy"};
    char s[1][7];
    scanf("%s",s);
    int i;
    if(strncmp(s[0],wea[0],1)==0){
        printf("%s\n",wea[1]);
    }
    else if(strncmp(s[0],wea[1],1)==0){
        printf("%s\n",wea[2]);
    }
    else if(strncmp(s[0],wea[2],1)==0){
        printf("%s\n",wea[0]);
    }
    return 0;
}


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

using namespace std;

mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
typedef long long ll;
typedef long double ld;

const int N = 10 + 7;
const int Q = 50 + 7;
int n, m, q;
int a[Q], b[Q], c[Q], d[Q];
int v[N];
int sol;

int get() {
  int sol = 0;
  for (int i = 1; i <= q; i++) {
    if (v[b[i]] - v[a[i]] == c[i]) {
      sol += d[i];
    }
  }
  return sol;
}

void gen(int pos) {
  if (pos == n + 1) {
    sol = max(sol, get());
    return;
  }
  for (int j = v[pos - 1]; j <= m; j++) {
    v[pos] = j;
    gen(pos + 1);
  }
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  v[0] = 1;
  cin >> n >> m >> q;
  for (int i = 1; i <= q; i++) {
    cin >> a[i] >> b[i] >> c[i] >> d[i];
  }
  gen(1);
  cout << sol << "\n";
  return 0;
}


Measured memory_bytes: 3652
#include <stdio.h>
#include <string>
#include <iostream>
#include <iomanip>
#include <map>
#include <algorithm>
#include <vector>
using namespace std;

int main(void) {
	int n,temp;
	cin >> n;
	vector<int> a(n);
	for(int i=0; i<n; i++){
		cin >> a[i];
	}
	sort(a.begin(),a.end());
	int alice=0,bob=0;
	for(int i=n-1; i>=0; i-=2){
		alice+=a[i];
		if(i==0)break;
		bob+=a[i-1];
	}
	cout << alice-bob << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
using namespace std;
int main(){
  int n,a;
  int table[50][300]={};
  cin >> n;
  for(int i=0; i<2; i++){
    int sum = 0;
    if(i==0) {
      for(int j=0; j<n; j++){
        cin >> a;
        sum += a;
        table[i][j] = sum;
      }
    }
    else {
      for(int j=0; j<n; j++){
        cin >> a;
        table[i][j] = a;
      }
      for(int j=n-1; j>=0; j--){
        sum += table[i][j];
        table[i][j] = sum;
      }
    }
  }
  int ans = 0;
  rep(i,n){
    ans = max(table[0][i]+table[1][i],ans);
  }
  cout << ans << endl;
  return 0;
}


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

void Main() {
  int A, P;
  cin >> A >> P;
  cout << (A * 3 + P) / 2 << endl;
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}

Measured memory_bytes: 256
n = int(input())
a = [int(i) for i in input().split()]

target = 1
count = 0
for i in range(n):
    if a[i] != target:
        count += 1
    elif a[i] == target:
        target += 1

if target == 1:
    print(-1)
else:
    print(count)


Measured memory_bytes: 26140
from collections import deque
que=deque([i for i in range(1,10)])
k=int(input())
count=0
while count!=k:
  a=que.popleft()
  count+=1
  if a%10==9:
    que.extend([10*a+8,10*a+9])
  elif a%10==0:
    que.extend([10*a,10*a+1])
  else:
    b=a*10+(a%10)-1
    que.extend([b,b+1,b+2])
print(a)



Measured memory_bytes: 70872
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,a,n) for(ll i = a;i < n;i++)
#define rrep(i,a,n) for(ll i = n; i >= a;i--)
#define LINF 1e18
#define INF 1e9
using namespace std;

int main(){
    string s;
    cin >> s;
    if(s[1] == 'B') cout << "ARC";
    else cout << "ABC";
    return 0;
}

Measured memory_bytes: 3616
#include<stdio.h>
#include<algorithm>
int dp[10000];
int main(){
    int a;
    while(scanf("%d",&a),a){
        for(int i=0;i<a;i++)scanf("%d",dp+i);
        std::sort(dp,dp+a);
        long long int ans=0;
        for(int i=0;i<a;i++){
            ans+=dp[i]*(a-1-i);
        }
        printf("%lld\n",ans);
    }
}


Measured memory_bytes: 2652
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <vector>
#include <bitset>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <deque>
#include <string>
#include <list>
#include <iterator>
#include <algorithm>
#include <unordered_map>
#define int                long long
#define pb                 push_back
#define pi                 pair<int,int>
#define vi                 vector<int>
#define all(v)             v.begin(),v.end()
#define MOD                1000000007
#define F                  first
#define S                  second
#define FOR(i,r)           for(int i=0;i<r;i++)
#define REP(i,l,r)         for(int i=l;i<r;i++)
#define RER(i,l,r)         for(int i=l;i>=r;i--)
#define print(v)           for(auto i : v)cout << i << ' ';
#define FASTIO             ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mem(arr,k)         memset(arr,k,sizeof(arr));
#define pii                acos(-1.0)
#define PI                 3.1415926535897932385
#define Sin(a)             sin((pi*a)/180)
#define test()             int x;cin >> x;while(x--)
using namespace std;
int n,arr[3001];
pair<int,int> dp[3001][3001][2];
pi rec(int l,int r,int cur){
	if(l==r){
		if(cur==0){
			return make_pair(arr[l],0);
		}
		else
			return make_pair(0,arr[l]);
	}
	if(l>r)
		return make_pair(0,0);
	if(dp[l][r][cur].F != -1)
		return dp[l][r][cur];
	if(cur == 0){
		pi a =  rec(l+1,r,1);
		pi b =  rec(l,r-1,1);
		a.F += arr[l];
		b.F += arr[r];
		if(a.F - a.S > b.F - b.S){
			dp[l][r][0] = a; 
		}
		else
			dp[l][r][0] = b;
		return dp[l][r][0];
	  }
	    pi a =  rec(l+1,r,0);
		pi b =  rec(l,r-1,0);
		a.S += arr[l];
		b.S += arr[r];
		if(a.F - a.S < b.F - b.S){
			dp[l][r][1] = a; 
		}
		else
			dp[l][r][1] = b;
	return dp[l][r][1];
}
int32_t main(){


	FASTIO;
	cin >> n;
	REP(i,0,n){
		cin >> arr[i];
	}
	REP(i,0,n){
		REP(j,0,n){
			REP(k,0,2){
				dp[i][j][k] = {-1,-1};
			}
		}
	}
	pi hehe = rec(0,n-1,0);
	cout << hehe.F - hehe.S << endl;
    return 0;

}

Measured memory_bytes: 281728
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;

void Main()
{
	int K, X;
	cin >> K >> X;
	
	int i = X - (K - 1);
	while (i <= X + (K - 1)) {
		cout << i;
		if (i != X + (K - 1)) {
			cout << " ";
		}
		i++;
	}
}
 
int main()
{
	Main();
	return 0;
}



Measured memory_bytes: 256
import sys
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)

N = int(input())
A = list(map(int, input().split()))

A.sort(reverse=True)

alice = 0 
bob = 0
for i, a in enumerate(A):
    if i % 2 == 0:
        alice += a
    else:
        bob += a

ans = alice - bob
print(ans)

Measured memory_bytes: 3064
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
public class Hello{
    public static void Main(){
        var line = ReadLine().Split(' ').Select(int.Parse).ToArray();
        var a = line[0];
        var b = line[1];
        string op  = "";
        if(a > b){
            op = ">";
        }else if(a == b){
            op = "==";
        }else{
            op = "<";
        }
        WriteLine($"a {op} b");
    }
}



Measured memory_bytes: 16364
#include <iostream>

using namespace std;

int N;

int main(){
    cin >> N;
    int min_n = 100001;
    int count;
    for(int i=0;i<=N;i++){
        count = 0;
        int x = i,y = N-i;
        while(x > 0){
            count += x % 6;
            x /= 6;
        }
        while(y > 0){
            count += y % 9;
            y /= 9;
        }
        if(min_n > count) min_n = count;
    }
    cout << min_n << endl;
    return 0;
}

Measured memory_bytes: 256
// finish date: 2018/01/20
#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>
#include <algorithm>
#include <stack>
#include <map>
#include <climits>

using namespace std;

#define FOR(i, a, b) for(int (i)=a;(i)<(b);(i)++)
#define rep(i, n)  FOR(i,0,n)
#define ll long long
#define bigmod 1000000007
#define INF 500000000


int main() {
    int N;
    cin>>N;
    if (N / 100 == N % 10) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(a) (long long)((a).size())

int main()
{
    ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
    
    ll a,b,c,k;
    cin>>a>>b>>c>>k;
    if(k<=a) cout<<k;
    else if(k>a && k<=a+b) cout<<a;
    else 
    {
        ll diff = k-(a+b);
        cout<<a-diff;
    }
}


Measured memory_bytes: 3640
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<map>
using namespace std;
int main(){
	long long n,m;
	cin>>n>>m;
	long long ans=0,ans1=0;
	long long a=n,b=n;
	while(a<=m){
		a=a*2;
		ans++;
	}
	while(b<=m){
		b=b*3;
		ans1++;
	}
	if(ans<ans1)
		ans=ans1;
	printf("%lld\n",ans);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 2e9
#define MOD 1000000007
#define MOD9 998244353
#define intMAX 51000;
#define PI 3.14159265359
using namespace std;
typedef long long llong;
// typedef long double ldouble;

using Graph = vector<vector<int>>;

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

// int gcd(int a, int b){
//   int ma = max(a,b);
//   int mi = min(a,b);
//   if(mi == 0) return ma;

//   return gcd(mi, ma%mi);
// }

// llong POW(llong a, llong b){
//   if(b == 0) return 1;
//   else{
//     if(b%2 == 0) return POW(a * a % MOD, b / 2) % MOD;
//     else return a * POW(a * a % MOD, b / 2) % MOD;
//   }
// }

int main(){
  string S;
  cin >> S;
  if(S[0] == S[1] && S[0] == S[2]) cout << "Yes" << endl;
  else if(S[1] == S[2] && S[1] == S[3]) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
int main(void)
{
	int i, j, x[10000], y[10000];
	
	j = 0;
	scanf("%d %d",&x[0], &y[0]);
	
	while (x[j] != 0 || y[j] != 0) {
		j++;
		
		if (j == 3000) {
			break;
		}
		scanf("%d %d",&x[j], &y[j]);
	}
	
	for (i=0; i<j; i++) {
		if (x[i] < y[i]) {
			printf("%d %d\n",x[i], y[i]);
		}
		else if (x[i] > y[i]) {
			printf("%d %d\n",y[i], x[i]);
		}
		else if (x[i] == y[i]) {
			printf("%d %d\n",x[i], y[i]);
		}
	}
	
	return 0;
}
	

Measured memory_bytes: 628
#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#include<math.h>

using namespace std;

main()
{
	string a,b;
	cin>>a>>b;
	int m,n;
	m = a.size();
	n = b.size();
	
	int i,j,k;
	int dp[m+1][n+1];
	
	for(i=0;i<=m;i++)
	dp[i][0] = 0;
	
	for(j=0;j<=n;j++)
	dp[0][j] = 0;
	
	
	for(i=1;i<=m;i++)
	{
		for(j=1;j<=n;j++)
		{
			if(a[i-1]==b[j-1])
			dp[i][j] = 1 + dp[i-1][j-1];
			else
			dp[i][j] = max(dp[i-1][j] , dp[i][j-1]);
		}
	}
	
	
	i=m;
	j=n;
	vector<char> v;
	while(i>0 && j>0)
	{
		if(dp[i][j] == 1 + dp[i-1][j-1] && a[i-1]==b[j-1])
		{
			//cout<<"move diagonally "<<endl;
			v.push_back(a[i-1]);
			//cout<<a[i-1]<<" : "<<b[j-1]<<endl;
			i--;
			j--;
			continue;
		}
		
		if(dp[i-1][j]==dp[i][j])
		{
			//cout<<"move up "<<endl;
			i--;
		}
		else
		{
			//cout<<"move back "<<endl;
			j--;
		}
	}
	
//	for(i=1;i<=m;i++)
//	{
//		for(j=1;j<=n;j++)
//		cout<<dp[i][j]<<" ";
//		cout<<endl;
//	}
	
	for(i=v.size()-1;i>=0;i--)
	{
		cout<<v[i];
	}

	
}

Measured memory_bytes: 35456
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _0430_atcoder問題_14
{
    class Program
    {
        static void Main(string[] args)
        {
            int hoge = int.Parse(Console.ReadLine());
            if (hoge % 2 == 0)
            {
                Console.WriteLine((hoge / 2) * (hoge / 2));
            }
            else
            {
                Console.WriteLine((hoge / 2) * ((hoge / 2) + 1));
            }
        }
    }
}

Measured memory_bytes: 11092
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int MAX=1e5 + 10;
ll f(ll x)
{
    return x*1LL*(x+1)/2LL;
}
int main ()
{
    ll N;cin >> N;
    ll ans = f(N)-N;
    cout<<ans<<endl;
    return 0;
}
/*
*/






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

const int mod = 1000000007;
struct mint {
  long long x;
  mint(long long x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(long long t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}


// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};

int n,k;
int main(){
    cin>>n>>k;
    k=min(k,n-1);
    combination c(n);
    mint ans;
    for(int i=0;i<=k;i++)ans+=c(n,i)*c((n-i-1)+i,i);
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3328
#include <stdio.h>

#define LENGTH 256

int main(void){
    char input[LENGTH];
    int train,taxi,num;
    fgets(input, LENGTH-1, stdin);
    sscanf(input, "%d %d %d", &num,&train,&taxi);
    if(train*num<taxi){
    printf("%d",train*num);
    }else{
        printf("%d",taxi);
    }

}

Measured memory_bytes: 128
// Aizu Vol0 0015: National Budget
// 2017.7.28

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>

char *gets(char *buf);

int main()
{
	int i, n;
	int la, lb, ls;
	int sum, ca;
	char a[105], b[105], s[105], *pa, *pb, *ps;
	char buf[500], *p;

	gets(buf);
	n = atoi(buf);
	for (i = 0; i < n; i++) {
		gets(buf); p = buf;
		while (isspace(*p)) p++;
		while (*p == '0') p++;
		pa = a, la = 0;
		while (isdigit(*p)) *pa++ = *p++, la++;
		*pa = 0;

		gets(buf); p = buf;
		while (isspace(*p)) p++;
		while (*p == '0') p++;
		pb = b, lb = 0;
		while (isdigit(*p)) *pb++ = *p++, lb++;
		*pb = 0;
#if 0
printf("case %d: la %d, lb %d\n", i, la, lb);
#endif
		if (la > 80 || lb > 80) puts("overflow");
		else {
			if (la == 0 && lb == 0) puts("0");
			else if (la == 0) puts(b);
			else if (lb == 0) puts(a);
			else {
				pa = a + la - 1;
				pb = b + lb - 1;
				ps = s, ca = 0, ls = 0;
				while (la > 0 || lb > 0) {
					sum = ca;
					if (la > 0) sum += (*pa-- - '0'), la--;
					if (lb > 0) sum += (*pb-- - '0'), lb--;
					if (sum >= 10) ca = 1, sum -= 10;
					else ca = 0;
					*ps++ = sum + '0', ls++;
				}
				if (ca > 0) *ps++ = ca + '0', ls++;
				*ps = 0;
			    if (ls > 80) puts("overflow");
				else {
#if 0
					printf("case %d: ls %d, %s\n --> ans ", i, ls, s);
#endif
					while (ls-- > 0) putchar(*--ps);
					putchar('\n');
				}
			}
		}
	}
	return 0;
}

Measured memory_bytes: 520
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
#define endl '\n'
typedef long long ll;
typedef pair<ll,ll> pll;
typedef long double ld;
const ll inf=1e9+7;
const ll mod=1e9+7;
//Combination
long long extGCD(long long a,long long mod,long long &x,long long &y){
    if(mod==0){
        x=1;
        y=0;
        return a;
    }
    long long d=extGCD(mod,a%mod,y,x);
    y-=(a/mod)*x;
    return d;
}
long long invmod(long long a,long long mod){
    long long x,y;
    extGCD(a,mod,x,y);
    x%=mod;
    if(x<0)x+=mod;
    return x;
}
ll fac[2000010],finv[2000010],inv[2000010];
void combinit(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    REP(i,2,2000010){
        fac[i]=fac[i-1]*i%mod;
        inv[i]=invmod(i,mod);
        finv[i]=finv[i-1]*inv[i]%mod;
    }
}
ll comb(ll n,ll k){
    if(n<k)return 0;
    if(n<0||k<0)return 0;
    return fac[n]*(finv[k]*finv[n-k]%mod)%mod;
}
ll rui(ll a,ll b){
    ll res=1;
    ll x=a;
    while(b){
        if(b&1)res=res*x%inf;
        b/=2;
        x=x*x%inf;
    }
    return res;
}
signed main(){
    ll n,m;cin>>n>>m;
    combinit();
    vector<ll>kai(m+1);
    kai[0]=1;
    REP(i,1,m+1){
        kai[i]=kai[i-1]*i%inf;
    }
    ll ans=kai[m]*rui(kai[m-n],inf-2)%inf;
    ll s=0;
    ll z=rui(kai[m-n],inf-2);
    REP(i,1,n+1){
        if(i%2){
            s=(s+comb(n,i)%mod*kai[m-i]%mod*z%mod)%mod;
        }else{
            s=(s-comb(n,i)%mod*kai[m-i]%mod*z%mod)%mod;
        }
    }
    ans=ans*(ans-s)%mod;
    if(ans<0)ans+=mod;
    cout<<ans<<endl;
}

Measured memory_bytes: 53956
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repr(i, n) for(ll i = n; i >= 0; i--)
#define reprr(i, m, n) for (ll i = m; i < n; i++)
#define inf (1LL<<60)
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
using Graph = vector<vector<pair<ll, ll>>>;


int main()
{
    ll N, M; cin >> N >> M;
    vector<pair<ll, ll>> v(M);
    rep(i, M) cin >> v[i].first >> v[i].second;
    sort(all(v));
    ll right = inf;
    ll count = 0;
    rep (i, v.size()) {
        auto p = v[i];
        //cout << p.first << " " << p.second << endl;
        if (p.first >= right) {
            count++;
            right = inf;
        }
        if (p == v[v.size()-1]) {
            count++;
            break;
        }

        right = min(right, p.second);
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(long long i=0; i<(n); i++)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
ll mod=2019;

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

int main(){
    string s; cin>>s;
    ll n=s.size();
    vector<ll> dp(2019, 0);
    vector<ll> cum(n+1, 0);
    rep(i,n){
        cum[i]=(s[i]-'0')*modpow(10, n-1-i, mod);
        if(i>0) cum[i]=(cum[i]+cum[i-1])%mod;
    }
    map<ll,ll> m;
    ll res=0;
    m[0]=1;
    rep(i,n){
        res+=m[cum[i]];
        m[cum[i]]++;
    }
    cout<<res<<endl;
    return 0;
}


Measured memory_bytes: 5212
#include "bits/stdc++.h"

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

typedef long long LL;
typedef unsigned long UL;

using namespace std;

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

    int n;
    cin >> n;

    if (n <= 111) cout << 111 << endl;
    else if (n <= 222) cout << 222 << endl;
    else if (n <= 333) cout << 333 << endl;
    else if (n <= 444) cout << 444 << endl;
    else if (n <= 555) cout << 555 << endl;
    else if (n <= 666) cout << 666 << endl;
    else if (n <= 777) cout << 777 << endl;
    else if (n <= 888) cout << 888 << endl;
    else if (n <= 999) cout << 999 << endl;

    return 0;
}


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

int main() {
    int N;
    set<char> c;
    cin >> N;
    rep(i, N) {
        char S;
        cin >> S;
        c.insert(S);
    }

    if (c.size() == 3) {
        printf("Three\n");
    }
    else {
        printf("Four\n");
    }
}

Measured memory_bytes: 3632
using System;
using System.Collections.Generic;

namespace AtCoderConsole
{
    class Program
    {
        static void Main(string[] args)
        {
            // 標準入力から1行取得
            string input = Console.ReadLine();

            // nを取得
            int n = int.Parse(input);

            input = Console.ReadLine();

            // stringの配列を取得
            string[] strArray = input.Split(' ');

            // int型のListを宣言
            List<int> list = new List<int>();

            for(int i = 0; i < strArray.Length; i++)
            {
                list.Add(int.Parse(strArray[i]));
            }

            // 昇順にソート
            list.Sort();

            int aPoint = 0;
            int bPoint = 0;
            int count = 1;
            while(list.Count != 0)
            {
                if (count % 2 == 1)
                {
                    aPoint += list[list.Count - 1];
                }
                else
                {
                    bPoint += list[list.Count - 1];
                }
                list.RemoveAt(list.Count - 1);
                count++;
            }

            // 差を出力する
            Console.WriteLine(aPoint - bPoint);
        }
    }
}


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

int main() {
	int N;cin >> N;
	if(N >= 65 && N <= 90) {
		cout << 1 << endl; return 0;
	} 
	if(N >= 97 && N <= 122) {
		cout << 2 << endl; return 0;
	}
	cout << 0 << endl; 
	return 0;

}




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

int f(int n){
    if(n == 1) return 1;
    if(n == 2) return 2;
    if(n == 3) return 4;
    return f(n-1) + f(n-2) + f(n-3);
}//再帰関数
    
int main(void){
    while(true) {
        int n;
        cin >> n;
        if(n == 0) break;
        cout << ( f(n) / 3650 )+1 << endl;
    }
}


Measured memory_bytes: 2996
#include <bits/stdc++.h>
#define eps 1e-3
#define pi acos(-1.0)
#define inf 0x3f
#define INF 0x3f3f3f3f
#define pb push_back
#define debug1 cout<<"&&";
#define debug2 cout<<"**";
#define ms(a, x) memset(a, x, sizeof(a))
#define for0(i, n) for(int i = 0; i < n; ++i)
#define for1(i, n) for(int i = 1; i <= n; ++i)
using namespace std;
typedef double db;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<long long, int> pli;
typedef pair<long long, long long> pll;
const int mod = 1e9 + 7;
const int N = 1e5+10;
const int M = 1e6+10;
/*=================================================================================*/

int main() {
   ll end, st = 100, ans;
   cin>>end;
   for(int i = 1; st < end; ++i) {
      st = 1.01*st;
      ans = i;
   }
   cout<<ans;
}

Measured memory_bytes: 3616
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>

using namespace std;

const int kInfinity = 0x3F3F3F3F;
const int kNil = -1;

template <class T>
struct Edge {
  using w_type = T;
  Edge(int u, int v, w_type w): u(u), v(v), w(w) { }
  int u, v;
  w_type w;
  bool operator<(const Edge<T> & rhs) const {
    if (w != rhs.w) { return w < rhs.w; }
    if (u != rhs.u) { return u < rhs.u; }
    return v < rhs.v;
  }
};

template <class Edge>
decltype(auto) BellmanFord(vector<Edge> & edges,
                 typename vector<Edge>::size_type node_num,
                 typename vector<Edge>::size_type root) {
  using size_type = typename vector<Edge>::size_type;
  using const_it = typename vector<Edge>::const_iterator;
  using w_type = typename Edge::w_type;

  w_type weight_sum{0};
  vector<w_type> dist(node_num, kInfinity);
  vector<int> parent(node_num, kNil);
  dist[root] = 0;

  for (unsigned i = 0; i < node_num - 1; ++i) {
    for (const auto & e: edges) {
      if (dist[e.v] > dist[e.u] + e.w && dist[e.u] != kInfinity) {
        dist[e.v] = dist[e.u] + e.w;
        parent[e.v] = e.u;
      }
    }
  }

  for (const auto & e: edges) {
    if (dist[e.v] > dist[e.u] + e.w && dist[e.u] != kInfinity) {
      return make_pair(false, dist);
    }
  }
  return make_pair(true, dist);
}

int main(int argc, char const *argv[]) {
  vector<Edge<int>> edges;
  unsigned V, E, r;
  cin >> V >> E >> r;
  for (unsigned i = 0; i < E; ++i) {
    unsigned u, v;
    int w;
    cin >> u >> v >> w;
    edges.emplace_back(u, v, w);
  }
  auto ans = BellmanFord(edges, V, r);
  auto have_neg_cycle = ans.first;
  auto dist = ans.second;
  if (!have_neg_cycle) {
    cout << "NEGATIVE CYCLE\n";
  } else {
    for (unsigned i = 0; i < V; ++i) {
      if (dist[i] == kInfinity) {
        cout << "INF\n";
      } else {
        cout << dist[i] << endl;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 3172
#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <vector>
#include <tuple>
#include <queue>
#include <stack>
#include <set>
#include <map>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define fi first
#define se second
typedef long long ll;

int N,M,H,W,K,A,B;
string S;
string alpha = "abcdefghijklmnopqrstuvwxyz";
string ALPHA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

int f(int a,int d){
    int ans = (a+d)%(d+1);
    //cout<<ans<<endl;
    return ans;
}

int main() {
    int D;
    cin>> N >> D;
    int g = 0;
    int a;
    rep(i,N){
        cin>>a;
        g = g^f(a,D);
        //cout<<g<<endl;
    }
    if(g) {
        cout << "First" << endl;
    }else{
        cout << "Second"<< endl;
    }
    int y = 7^10;
    //cout<<y<<endl;
}


Measured memory_bytes: 3196
// Package main provides
//
// File:  b.go
// Author: ymiyamoto
//
// Created on Sat Aug  4 04:30:56 2018
//
package main

import "fmt"

var S, T string

func main() {
	fmt.Scan(&S, &T)
	for range S {
		if S == T {
			fmt.Println("Yes")
			return
		}
		S = string(S[len(S)-1]) + S[:len(S)-1]
	}

	fmt.Println("No")
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <string>
#include <stdlib.h>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <climits>

using namespace std;

int main()
{
  int N;
  vector<int> A;

  cin >> N;
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    A.push_back(a);
  }

  sort(A.begin(), A.end());

  for (int i = 0; i < N - 1; i++) {
    if (A[i] == A[i + 1]) {
      cout << "NO";
      return 0;
    }
  }

  cout << "YES";

  return 0;
}


Measured memory_bytes: 1400
#include<iostream>
#include<string>
#include<algorithm>
#include<bits/stdc++.h>
#include<math.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rep1(i,n) for(int i = 1; i < (n); i++)

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

cout << a*b << endl;}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main() {
	int n, i;
	cin >> n >> i;
	cout << n - i + 1 << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(a); (i)<(b); ++(i))
#define rFor(i, a, b) for(int (i)=(a)-1; (i)>=(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<lint, lint> pll;
typedef complex<double> xy_t;
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T>bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod*mod;
constexpr int MAX = 100010;

bool check(int H, int W, vector<vector<int>> &a){
    lint sum=0;
    rep(i, H)rep(j, W) sum+=a[i][j];
    return sum>0;
}

int main(){
    int H, W, h, w;
    scanf("%d%d%d%d", &H, &W, &h, &w);
    if(h==1 && w==1){
        printf("No\n");
        return 0;
    }
    vector<vector<int>> a(H, vector<int>(W));
    int K=((int)1e9-1)/(h*w-1);
    int L=-K*(h*w-1)-1;
    rep(i, H)rep(j, W) a[i][j]=(i+1)%h==0 && (j+1)%w==0 ? L : K;
    if(!check(H, W, a)) printf("No\n");
    else{
        printf("Yes\n");
        rep(i, H){
            rep(j, W) printf("%d ", a[i][j]);
            printf("\n");
        }
    }
}

Measured memory_bytes: 3968
#include<stdio.h>
int main(){
	int a[3][10]={}, b[3][10]={}, c[3][10]={}, d[3][10]={}, n, f, r, v, w, i, j;
	scanf("%d", &n);
	for(i=0;i<n;i++){
		scanf("%d %d %d %d", &f, &r, &v, &w);
		if(f==1){
			a[r-1][v-1]=a[r-1][v-1]+w;
		}else if(f==2){
			b[r-1][v-1]=b[r-1][v-1]+w;
		}else if(f==3){
			c[r-1][v-1]=c[r-1][v-1]+w;
		}else if(f==4){
			d[r-1][v-1]=d[r-1][v-1]+w;
		}
	}
	for(i=0;i<12;i++){
		if(i!=0 && i%3==0){
			for(j=0;j<20;j++){
				printf("#");
			}
			printf("\n");
		}
		for(j=0;j<10;j++){
			if(i<3){
				printf(" %d", a[i][j]);
			}else if(i<6){
				printf(" %d", b[i-3][j]);
			}else if(i<9){
				printf(" %d", c[i-6][j]);
			}else if(i<12){
				printf(" %d", d[i-9][j]);
			}
		}
		printf("\n");
	}
}


Measured memory_bytes: 2140
N = gets.to_i
A = gets.split.map(&:to_i).sort.tally
ans = 0
divisible = Array.new(1000100, false)
A.each do |num, count|
    if count == 1 && !divisible[num]
        ans += 1
    end
    i = 1
    while i * num < 1000050
        divisible[i * num] = true
        i += 1
    end
end
p ans

Measured memory_bytes: 44936
def main():
    import sys
    input = sys.stdin.buffer.readline
    N, Q = map(int, input().split())
    *C, = map(int, input().split())

    last = [-1]*(N+1)
    P = [[] for _ in [0]*(N+1)]
    for i, c in enumerate(C):
        if last[c] != -1:
            P[last[c]].append(i+1)
        last[c] = i+1

    queries = [[] for _ in [0]*(N+1)]
    for i in range(Q):
        l, r = map(int, input().split())
        queries[l].append((r, i))

    def add(A, i, x):
        while i <= N:
            A[i] += x
            i += i & -i

    def sum(A, i):
        ret = 0
        while i:
            ret += A[i]
            i ^= i & -i
        return ret

    A = [0]*(N+1)
    ans = [0]*Q
    for l in range(N, 0, -1):
        for cr in P[l]:
            add(A, cr, 1)
        for r, i in queries[l]:
            ans[i] = r-l+1-sum(A, r)

    print(*ans, sep='\n')


if __name__ == '__main__':
    main()


Measured memory_bytes: 232528