akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cmath>
#include <vector>
#include <cstdio>
#include <algorithm>
using namespace std;
int main ()
{
	vector< pair<string, int> > a;
	string z;
	cin>>z;
	a.push_back(pair<string,int>(z,1));
	while(cin>>z)
	{
		for(int i=0;i<a.size();i++)
		{
			if(a[i].first==z)
			{
				a[i].second++;
			}
			if(i==a.size()-1)
			{
				a.push_back(pair<string,int>(z,1));
				break;
			}
		}
	}
	int m=-1;
	int s=-1;
	for(int i=0;i<a.size();i++)
	{
		m=max(m,a[i].second);
		s=max(s,(int)a[i].first.length());
	}
	for(int i=0;i<a.size();i++)
	{
		if(a[i].second==m)
		{
			cout<<a[i].first<<" ";
		}
	}
	for(int i=0;i<a.size();i++)
	{
		if(a[i].first.size()==s)
		{
			cout<<a[i].first<<endl;;
		}
	}
	return 0;
}

Measured memory_bytes: 1200
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;

int G[200][200];
int V[200];

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i)
    {
        string s;
        cin >> s;
        for (int j = 0; j < n; ++j)
            G[j][i] = G[i][j] = (s[j] == '1' ? 1 : 500);
    }
    for (int i = 0; i < n; ++i)
        G[i][i] = 0;

    for (int k = 0; k < n; ++k)
        for (int i = 0; i < n; ++i)
            for (int j = 0; j < n; ++j)
                G[i][j] = min(G[i][j], G[i][k] + G[k][j]);


    int sol = -1;
    for (int i = 0; i < n; ++i)
    {
        int mx = 0;
        for (int j = 0; j < n; ++j)
        {
            V[j] = G[i][j];
            mx = max(mx, V[j]);
        }

        bool good = true;
        for (int j = 0; j < n; ++j)
            for (int k = 0; k < n; ++k)
                if (G[j][k] == 1 && abs(V[j] - V[k]) != 1)
                    good = false;

        if (good)
            sol = max(sol, mx + 1);
    }
    cout << sol;
}


Measured memory_bytes: 384
using static System.Math;
using static System.Console;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var k = int.Parse(ReadLine());
            var s = ReadLine();

            if(s.Length <= k)
            {
                WriteLine(s);
            }
            else
            {
                WriteLine(s.Substring(0, k) + "...");
            }
        }
    }
}


Measured memory_bytes: 17616
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define pa pair<int,int>
const int Maxn=100010;
const int inf=2147483647;
int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9')x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
	return x*f;
}
int n,m,deg[Maxn],fa[Maxn],r,dep[Maxn];
struct Edge{int x,y;}E[Maxn];
vector<int>h[Maxn];
int main()
{
	n=read(),m=read();
	for(int i=1;i<=n-1+m;i++)
	{
		int x=read(),y=read();E[i].x=x;E[i].y=y;
		h[x].push_back(y);deg[y]++;
	}
	for(int i=1;i<=n;i++)if(!deg[i])r=i;
	queue<int>q;
	q.push(r);dep[r]=0;
	while(!q.empty())
	{
		int x=q.front();q.pop();
		for(int i=0;i<h[x].size();i++)
		{
			int y=h[x][i];
			--deg[y];if(!deg[y])dep[y]=dep[x]+1,q.push(y);
		}
	}
	fa[r]=0;
	for(int i=1;i<=n-1+m;i++)
	{
		int x=E[i].x,y=E[i].y;
		if(dep[x]+1!=dep[y])continue;
		fa[y]=x;
	}
	for(int i=1;i<=n;i++)printf("%d\n",fa[i]);
}

Measured memory_bytes: 8192
X,K,D=map(int,input().split())
X=abs(X)
if X-K*D>0:
    print(X-K*D)
else:
    kaisu=int(X/D)
    gi1=X-kaisu*D
    gi4 = abs(gi1)
    if (K - kaisu) % 2 == 0:
        print(gi4)
    else:
        gi2=abs(gi1-D)
        gi3=abs(gi1+D)
        kot=gi2
        if gi3<kot:
            kot=gi3
        print(kot)

Measured memory_bytes: 61572
class Point(object):
    def __init__(self, x, y):
        self.x = x
        self.y = y

    # def __repr__(self):
    #     return '({}, {})'.format(self.x, self.y)

    # def __str__(self):
    #     return '({}, {})'.format(self.x, self.y)


def prepare_points(N, color_str):
    points = []
    for i in range(N):
        tmp = input().split()
        x, y = int(tmp[0]), int(tmp[1])
        point = Point(x, y)
        points.append((point, color_str))
    return points


def main():
    N = int(input())
    red_points = prepare_points(N, 'r')
    blue_points = prepare_points(N, 'b')
    sorted_ = sorted((red_points + blue_points), key=lambda x: x[0].x)
    uses = set()
    count = 0
    for item in sorted_:
        if item[1] == 'r':
            uses.add(item)
        else:
            reds = {
                foo
                for foo in uses if foo[1] == 'r' and foo[0].y < item[0].y
            }
            # print(item, reds)
            if not reds:
                continue
            max_p = max(reds, key=lambda x: x[0].y)
            if max_p[0].y < item[0].y:
                uses.remove(max_p)
                count += 1
    # print(sorted_)
    # print(uses)
    print(count)


if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#!/usr/bin/env python3
import sys
input = sys.stdin.readline

class RollingHash():
    def __init__(self, s):
        self.length = len(s)
        self.base = 1009
        self.mod = (1 << 61) - 1
        self.hash = [0] * (self.length + 1)
        self.pow = [1] * (self.length + 1)

        for i in range(self.length):
            self.hash[i+1] = (self.hash[i] + s[i]) * self.base % self.mod
            self.pow[i+1] = self.pow[i] * self.base % self.mod

    def get(self, l, r):
        t = self.hash[r] - self.hash[l] * self.pow[r-l] % self.mod
        t = (t + self.mod) % self.mod
        return t

n = int(input())
a = [int(item) for item in input().split()]
b = [int(item) for item in input().split()]
a = a + a

diffa = []
diffb = []
for i in range(1, len(a)):
    diffa.append(a[i] ^ a[i-1])
for i in range(1, len(b)):
    diffb.append(b[i] ^ b[i-1])

RHa = RollingHash(diffa)
RHb = RollingHash(diffb)
query = RHb.get(0, n-1)
ans = []
for i in range(n):
    val = RHa.get(i, i+n-1)
    if val == query:
        ans.append((i, a[i] ^ b[0]))
ans.sort()
for k, x in ans:
    print(k, x)

Measured memory_bytes: 152156
#include <iostream>

using namespace std;

int main(void){

  int n;
  while( cin >> n , n ){
    n /= 4;
    int total = 0;
    int in;
    while(n--){
      cin >> in;
      total += in;
    }
    cout << total << endl;
  }
  return 0;
}

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

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; }

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("YES")
#define p_no() p("NO")

const ll mod = 1e9 + 7;
const ll inf = 1e18;

void vprint(vector<ll> A){
    ll L = A.size();
    FOR(i, 0, L){
        if(i) cout << ' ';
        cout << A[i];
    }
    cout << endl;
}

bool is_same_array(vector<ll>& A, vector<ll>& B){
    ll N = A.size();
    FOR(i, 0, N){
        if(A[i]!=B[i]) return false;
    }
    return true;
}

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

    // input
    ll N;
    cin >> N;

    vector<ll> A(N);
    FOR(i, 0, N){
        cin >> A.at(i);
    }
    auto A_original = A;
    auto A_sorted = A;
    sort(ALL(A_sorted));

    if(is_same_array(A, A_sorted)){
        p_yes();
        return 0;
    }

    FOR(i, 0, N){
        FOR(j, i+1, N){
            A = A_original;
            swap(A[i], A[j]);
            if(is_same_array(A, A_sorted)){
                p_yes();
                return 0;
            }
        }
    }
    p_no();
    
    return 0;
}

Measured memory_bytes: 256
n,k = list(map(int, input().split()))
s = input()
if (s.find('0') < 0) or (s.find('1') < 0):
	print(len(s))
	quit()
else:
	s += '0' if s[n-1] == '1' else '1'
c = []

j = 0
for i in range(1, n+1):
	if s[i-1] == s[i]:
		j += 1
	else:
		c.append([s[i-1], j+1])
		j = 0

for i in range(1, len(c)):
	c[i][1] += c[i-1][1]

if 2*k >= len(c):
	print(c[-1][1])
	quit()
else:
	p = 0
	res = 0
	if c[0][0] == '0':
		res = c[1][1] if k == 1 else c[2*k-1][1]
		p += 1
	else:
		res = c[2][1] if k == 1 else c[2*k][1]
		p += 2

	while p+2*k < len(c):
		res = max(res, c[p+2*k][1] - c[p-1][1])
		p += 2

	res = max(res, c[-1][1] - c[(len(c)-1) - 2*k][1]) if c[-1][0] == '0' else max(res, c[-1][1] - c[(len(c)-1) - (2*k+1)][1])

	print(res)
	quit()

Measured memory_bytes: 16500
import numpy as np
N,M = map(int,input().split())
a = np.zeros((8,N))
for i in range(N):
    x,y,z = map(int,input().split())
    j=0
    for j1 in range(2):
        for j2 in range(2):
            for j3 in range(2):
                a[j][i] = (-1)**j1*x+(-1)**j2*y+(-1)**j3*z
                j += 1
ans = 0
for j in range(8):
    ref = sum(sorted(a[j])[-M:])
    ans = max(ans,ref)
if M == 0:
    ans = 0
print(int(ans))

Measured memory_bytes: 21616
#include <bits/stdc++.h>
#include <math.h>
#include <cmath>

using namespace std;
using ll =long long;
using vi = vector<int>; 
using vvi = vector<vi>; 
using vl = vector<ll>; 
using vvl = vector<vl>; 

#define rep(i,n) ;for( int i =0; i < n ; i ++)
#define all(a) a.begin(),a.end()
#define f(i,a,b) for(int i=a;i<b;i++)
#define MOD 1000000007
bool is_int_lround(double x){
  return std::lround(x)==x;
}
int ketasuu(int x){
  int n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}


ll conbi(int n,int m){
  
  cin>>n>>m;
  vector<ll> a(100);
  a[0] =1;
  for(int i=0;i<14;i++){
    a[i+1]=a[i]*(i+1);
  }
  return a[n] /(a[m] *a[n-m]);
}

int main(){
  int a,b;cin>>a>>b;
  if(a>=10 || b>=10 )cout <<-1<<endl;
  else cout <<a*b<<endl;
  
}
  

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

int main(){
  int N,M;
  cin >> N >> M;
  vector<int> p(M);
  vector<string> s(M);
  for(int i=0; i<M; i++){
    cin >> p[i] >> s[i];
  }
  
  int ac=0;
  int wa=0;
  vector<int> WA(N+1);
  vector<bool> ok(N+1,false);
  for(int i=0; i<M; i++){
    if (ok[p[i]]==false && s[i]=="WA") WA[p[i]]++;
    else if (ok[p[i]]==false && s[i]=="AC"){
      ok[p[i]]=true;
      wa+=WA[p[i]];
      ac++;
    }
    else if (ok[p[i]]==true) continue;
  }
  cout << ac << " " << wa << endl;
}

Measured memory_bytes: 6528
import java.util.*;
import java.util.stream.*;
class Main {
    private static String CaseReverse (String s){
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < s.length(); i++){
            char c = s.charAt(i);
            if (Character.isUpperCase(c)){
                c += 32;
                sb.append(c);
            } else if (Character.isLowerCase(c)){
                c -= 32;
                sb.append(c);
            } else {
                sb.append(c);
            }
        }
        return sb.toString();
    }
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        String str;
        str = input.nextLine();
        str = CaseReverse(str);
        System.out.println(str);
    }
}


Measured memory_bytes: 26160
import sys
import math

# -*- coding: utf-8 -*-

a = int(input())
b = int(input())
c = int(input())
n = int(input())
ret = 0
for i in range(a+1):
    for j in range(b+1):
        for k in range(c+1):
            if (i * 500 + j * 100 + k * 50 == n):
                ret +=1

print(str(ret))


Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int N = 1e5+5;

int h[N], dp[N];

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n, k; cin >> n >> k;
	for (int i = 0; i < n; i++)
		cin >> h[i];
	for (int i = 1; i < n; i++)
	{
		dp[i] = inf;
		for (int j = 1; j <= k; j++)
		{
			if (i - j >= 0)	dp[i] = min(dp[i], abs(h[i] - h[i-j]) + dp[i-j]);
		}
	}
	cout << dp[n-1];
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <functional>
#include <ctime>
#include <cmath>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iomanip>
#include <float.h>
#include <math.h>
using namespace std;
using ll = long long;


unsigned euclidean_gcd(unsigned a, unsigned b) {
    if (a < b) return euclidean_gcd(b, a);
    unsigned r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

class UnionFind {
public:
    vector <ll> par;
    vector <ll> siz;
    UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    ll root(ll x) {
        while (par[x] != x) {
            x = par[x] = par[par[x]];
        }
        return x;
    }
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) {
        return root(x) == root(y);
    }

    ll size(ll x) {
        return siz[root(x)];
    }
};

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;
}

long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}


int main() {
    ll a;
    cin >> a;
    if (a % 2 == 1) {
        vector<ll> mn(a);
        vector<ll> mx(a);
        for (int i = 0; i < a; i++) {
            cin >> mn.at(i) >> mx.at(i);
        }
        sort(mn.begin(), mn.end());
        sort(mx.begin(), mx.end());
        cout << mx.at(a / 2) - mn.at(a / 2)+1 << endl;
    }
    else {
        vector<ll> mn(a);
        vector<ll> mx(a);
        for (int i = 0; i < a; i++) {
            cin >> mn.at(i) >> mx.at(i);
        }
        sort(mn.begin(), mn.end());
        sort(mx.begin(), mx.end());
        cout << mx.at(a / 2) - mn.at(a / 2) + mx.at(a / 2-1) - mn.at(a / 2-1)+ 1 << endl;
    }
}

Measured memory_bytes: 6364
N, Y = map(int, input().split())
for i in range(N + 1):
	for j in range(i, N + 1):
		if 10000 * i + 5000 * (j - i) + 1000 * (N - j) == Y:
			print(i, j - i, N - j)
			exit()
print("-1 -1 -1")


Measured memory_bytes: 2940
import java.util.*;

public class Main{
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String S = sc.next();
    String SS = S.substring(5,7);
    if(SS.equals("01") || SS.equals("02")||SS.equals("03")||SS.equals("04")) {
      System.out.println("Heisei");
    } else {
      System.out.println("TBD");
    }
  }
}

Measured memory_bytes: 20948
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define sz(x) int(x.size())
#define pb push_back
#define eb emplace_back
using ll=long long;
using P = pair<int,int>;
using LP=pair<ll,int>;
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
const ll MOD=1000000007,MOD2=998244353;



int main() {
    ll A,B;
    cin>>A>>B;
    if(B-A<=10){
        ll ans=A;
        for(ll i=A+1;i<=B;i++){
            ans=ans^i;
        }
        cout<<ans<<endl;
        return 0;
    }
    ll ansa,ansb,ans;
    ansa=A,ansb=B;
    ll nowa=A+1,nowb=B-1;
    while(nowa%4!=0){
        ansa=ansa^nowa;
        nowa++;
    }
    while(nowb%4!=3){
        ansb=ansb^nowb;
        nowb--;
    }

    ans=ansa^ansb;
    cout<<ans<<endl;
}

Measured memory_bytes: 3552
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define print(A,x,n) rep(I,0,n){cout<<(I ? " ":"")<<A[I]x;}cout<<endl;
#define pprint(A,y,m,n) rep(J,0,m){print(A[J],y,n);}
const long mod=1e9+7;
const int size=1e5+1;
const long inf=1e14;
int main(){
	int N,x; cin>>N>>x;
	if(x == 1 || x == 2 * N - 1) cout<<"No"<<endl;
	else{
		cout<<"Yes"<<endl;
		rep(i,0,2*N-1){
			cout<<(i + x + N - 1) % (2 * N - 1) + 1<<endl;
		}
	}
}

Measured memory_bytes: 1536
import java.io.*;
import java.util.Arrays;
public class Main{
    public static void main(String args[])throws IOException
    {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        
        
        int A[] = {1819, 2003, 876, 2840, 1723, 1673, 3776, 2848, 1592, 922};
        int len = A.length;
        for(int i =0; i<len ; i++)
            A[i] = Integer.parseInt(br.readLine());
        
        Arrays.sort(A);
        
        System.out.println(A[len-1]);
        System.out.println(A[len-2]);
        System.out.println(A[len-3]);
        
        
    }
}

Measured memory_bytes: 17020
/*input
2
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl
#define debug cout << "hi" << endl

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

const int MOD = 1e9 + 7;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int x; cin >> x;
    ll i = x;
    while(1)
    {
    	ll cnt = 0;
    	for(int j = 1; j <= sqrt(x); j++) if(!(i % j)) cnt += 2;
    	if(cnt == 2)
    	{
    		cout << i;
    		break;
    	}
    	i++;
    }

    return 0;
}

Measured memory_bytes: 384
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

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

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

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

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

fn main() {
    input! {
        n: usize,
        s: String,
    }
    let mut ans = 0;
    for i in 0..n - 2 {
        let si = &s[i..i + 3];
        if si == "ABC" {
            ans += 1;
        }
    }
    println!("{}", ans);
}


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

int main() {
    int n;
    cin >> n;
    if(n == 1)
        cout << "Hello World" << endl;
    else {
        int a, b;
        cin >> a >> b;
        cout << a + b << endl;
    }
}


Measured memory_bytes: 256
#define r(x) do{while((x=getchar())<'0'); for(x-='0'; '0'<=(_=getchar()); x=(x<<3)+(x<<1)+_-'0');}while(0)
#include <bits/stdc++.h>
#include <cmath>
#include <fstream>
#define f first
#define endl "\n"
#define s second
#define pb push_back
#define ms(a,b) memset(a,b,sizeof(a))
#define fori(a,b) for(int i=a;i<b;i++)
#define forj(a,b) for(int j=a;j<b;j++)
typedef long long ll;
using namespace std;
typedef vector<int> vi;
typedef pair<int,int> pii;
char _;

int ans[100000];
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	int n;
	cin>>n;
	
	for(int x=1;x<=99;x++){
		for(int y=1;y<=99;y++){
			for(int z=1;z<=99;z++){
				ans[x*x + y*y + z*z + x*y + y*z + x*z]++;
			}
		}
	}

	for(int i=1;i<=n;i++){
		cout << ans[i] << endl;
	}
	return 0;
}



Measured memory_bytes: 3796
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define SUM(a)  accumulate((a).begin(),(a).end(),0)
#define SORT(a) sort(ALL(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
typedef long long ll;
const int INF = 999999999;
const int MOD = (int)1e9 + 7;
const int EPS = 1e-9;

int main() {
    int ans = 0;
    string S;
    cin >> S;
    REP(i,S.size()){
        if (S[i] == '1')ans++;
    }
    cout << ans << endl;
}

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

#define DUMP(x) cerr << #x << "=" << x << endl
#define DUMP2(x, y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<")"<< endl
#define BINARY(x) static_cast<bitset<16> >(x)

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

#define in_range(x, y, w, h) (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()

typedef long long ll;
const int INF = 1e9;
typedef pair<int, int> PII;
int dx[4]={0, -1, 1, 0}, dy[4]={-1, 0, 0, 1};

int main()
{
    ios::sync_with_stdio(false);

    int N, M;
    cin >> N >> M;
    vector<int> A(N), B(N);
    rep(i, N) cin >> A[i] >> B[i];
    vector<int> C(M), D(M);
    rep(i, M) cin >> C[i] >> D[i];

    rep(i, N) {
        int ans = 0;
        int min_cost = abs(A[i] - C[0]) + abs(B[i] - D[0]);

        REP(j, 1, M) {
            int cost = abs(A[i] - C[j]) + abs(B[i] - D[j]);
            if (cost < min_cost) {
                min_cost = cost;
                ans = j;
            }
        }

        cout << ans + 1 << endl;
    }
}

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

using namespace std;


int N, Q; // Nが後半部 Mが前半部

int tbl[100001] = {0};

int main(){

    cin >> N;
    cin.ignore();

    int tmp;
    long long sum = 0;
    for(int i = 0; i < N; i++){
        cin >> tmp;
        sum += tmp;
        ++(tbl[tmp]);
    }

    cin.ignore();


    cin >> Q;
    int b, c;
    for(int i = 0; i < Q; i++){
        cin >> b >> c;
        cin.ignore();
        int dif = c - b;
        sum += ((long long)dif) * tbl[b];
        tbl[c] += tbl[b];
        tbl[b] = 0;
        cout << sum << endl;
    }
    return 0;

}

Measured memory_bytes: 3968
#include <iostream>
#include <algorithm>
using namespace std;
const int mod = 1000 * 1000 * 1000 + 7;

int dp[2001];

int main() {
	int s; cin >> s; 
	dp[0] = dp[1] = dp[2] = 0;
	fill(dp + 3, dp + 2001, 1);
	for (int i = 3; i <= s; i++)
		for (int j = 3; j <= i - 3; j++)
			dp[i] = (dp[i] + dp[i - j]) % mod;

	cout << dp[s] << '\n';
	cin.ignore(2); return 0;
}

Measured memory_bytes: 3600
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>
// *テンプレート*
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define P pair<int, int>
#define sz(x) x.size()
// aよりbの方が小さかったら、aの値をbの値に置き換える。(swapではない！)
template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
// aよりbの方が大きかったら、aの値をbの値に置き換える。
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

using namespace std;
typedef long long ll;
using Graph = vector<vector<int>>;
//最大公約数
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
//最小公倍数
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
// 素数かどうか判定
bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}
const long long mod = 1000000007;
const long long INF = 1LL << 60;
// *テンプレートここまで*

// pair -> vector<pair<int,int>> 
//		   AandB.push_back(make_pair(a[i],b[i]))

int s[15];
int ans = 0;
int n;
void dfs(int i, int sum, int now) {
	if (i == n - 1) {
		ans += sum + now;
	}
	else {
		dfs(i + 1, sum + now, s[i + 1]);
		dfs(i + 1, sum, now * 10 + s[i + 1]);
	}
}
signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	string str; cin >> str;
	n = str.size();
	rep(i, str.size()) {
		s[i] = str[i] - '0';
	}
	dfs(0, 0, s[0]);
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 256
use std::io;


/// https://beta.atcoder.jp/contests/abc104/tasks/abc104_b
fn main() {
    let s = read_one::<String>().chars().collect::<Vec<char>>();
    let mut flg = true;
    if s[0] != 'A' { flg = false; }
    if !(s.contains(&'C') && s[1] != 'C' && s[s.len() - 1] != 'C') { flg = false; }
    if s.iter().filter(|c| c.is_lowercase()).count() != s.len() - 2 { flg = false; }
    if flg { println!("AC"); }
    else { println!("WA"); }
}


#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_one<T>() -> T
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}

Measured memory_bytes: 4352
S = input()
def check(s):
  if s[::] == s[::-1]:
    return True
  else:
    return False

S1 = S[:(len(S)-1)//2]
S2 = S[(len(S)+3)//2-1:]
if check(S) and check(S1) and check(S2):
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3060
//ALDS1_13_A
#include <iostream>
#include <vector>
using namespace std;

void printChess(int chess[]){
	for(int i=0;i<8;i++){
		for(int j=0;j<8;j++){
			if(j == chess[i])
				cout<<"Q";
			else
				cout<<".";
		}
		cout<<endl;
	}
}

bool isBlank(int chess[], int &r){
	for(int i=0;i<8;i++){
		if(chess[i] == 100){
			r = i;
			return true;
		}
	}
	return false;
}

bool setQ(int chess[], int r, int c){
	for(int i=0;i<8;i++){
		if(chess[i] == c)
			return false;
		if(i+chess[i] == r+c)
			return false;
		if(i-chess[i] == r-c)
			return false;
	}
	return true;
}

void solve(int chess[]){
	int r;
	if(isBlank(chess, r)){
		for(int c=0;c<8;c++){
			if(setQ(chess, r, c)){
				chess[r] = c;
				solve(chess);
				chess[r] = 100;
			}
		}
	}else{
		printChess(chess);
	}
}

int main(){
	int k, r, c, chess[8];
	
	for(int i=0;i<8;i++)
		chess[i] = 100;

	cin>>k;
	for(int i=0;i<k;i++){
		cin>>r>>c;
		chess[r] = c;
	}

	solve(chess);

	return 0;
}

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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)
#define mp make_pair

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int32 n;
    cin >> n;
    cout << n * n * n << endl;
    return 0;
}

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

const int maxn=1e3+5;

string s;

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

    cin>>s;
    int n=s.size();
    if(s[n-1]!='s') s.push_back('s');
    else s+="es";
    cout<<s;
    return 0;
}

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

string S, T;
vector<int>alp[26];
ll res;
int main() {
	cin >> S >> T;
	for (int i = 0; i < S.size(); ++i) {
		alp[S[i] - 'a'].push_back(i);
	}
	for (char c : T) {
		if (alp[c - 'a'].empty()) {
			cout << -1 << endl;
			return 0;
		}
	}
	res = alp[T.front() - 'a'].front();
	for (int i = 1; i < T.size(); ++i) {
		auto it = upper_bound(alp[T[i] - 'a'].begin(), alp[T[i] - 'a'].end(), res%S.size());
		if (it == alp[T[i] - 'a'].end()) {
			res = res - res%S.size() + S.size() + alp[T[i] - 'a'].front();
		}
		else {
			res = res - res%S.size() + *it;
		}
	}
	++res;
	cout << res << endl;
}


Measured memory_bytes: 1216
#include <iostream>
#include <stdio.h>
#include <math.h>

using namespace std;
int main() {
int s;
double a,b,c,d,e,f,g,h,i,j,m,n,x,y,r;
cin >> s;
for (s;s>0;s--) {
cin >> a >> b >> c >> d >> e >> f ;
if (b-d == 0) b=d+0.0000001;
if (f-d == 0) f=d+0.0000001;
m=(a-c)/(b-d); n=(e-c)/(f-d);
g=(a+c)/2; h=(b+d)/2;
i=(e+c)/2; j=(d+f)/2;
x=(j+n*i-h-m*g)/(n-m);
y=h-m*(x-g);
r=sqrt((x-a)*(x-a)+(y-b)*(y-b));
printf("%.3f %.3f %.3f\n",x,y,r);
}
return 0;
}

Measured memory_bytes: 1244
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(c) (c).begin(), (c).end()
#define pb push_back
#define eb emplace_back
const long long INF = 1LL<<60; // 仮想的な無限大の値;
using namespace std;
using ll = long long;
using P  = pair<int, int>;
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; }
const int A = 1e6 + 9;
const int MAX = A;
vector<int> is_prime(MAX, 1);
long long GCD(long long a, long long b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}
int main()
{
    is_prime[0] = 0, is_prime[1] = 0;
    for (int i = 2; i < MAX; ++i) {
        if (!is_prime[i]) continue;
        for (int j = i*2; j < MAX; j += i) is_prime[j] = 0;
    }
    //---------------
    int n;
    cin >> n;
    vector<int> a(n);
    vector<int> c(A);
    rep(i, n)
    {
        cin >> a[i];
        c[a[i]]++;
    }
    bool pairwize = true;
    rep2(i, 2, A)
    {
        if(!is_prime[i]) continue;
        int cnt = 0;
        for(int j = 1 ; i*j <= A ; ++j)
        {
            cnt += c[i*j];
            if(cnt > 1) pairwize = false;
        }
    }
    if(pairwize)
    {
        cout << "pairwise coprime" << endl;
        return 0;
    }
    int g = 0;
    rep(i, n)
    {
        g = (int)GCD((ll)g, (ll)a[i]);
        if(g == 1)
        {
            cout << "setwise coprime" << endl;
            return 0;
        }
    }
    cout << "not coprime" << endl;
    return 0;
}

Measured memory_bytes: 14824
#include <algorithm>
#include <iostream>
#include <limits>
#include <vector>

using ::std::cin;
using ::std::cout;
using ::std::endl;
using ::std::string;
using ::std::vector;

using int64 = long long;

constexpr int64 P = 1000000007;

struct FiniteField {
  int64 x;
  FiniteField(int64 input_x) : x(input_x) {}
  inline FiniteField operator+ (FiniteField o) {
    return *this + o.x;
  }
  inline FiniteField operator+ (int64 o) {
    return FiniteField((x + o) % P);
  }
  inline FiniteField operator* (FiniteField o) {
    return *this * o.x;
  }
  inline FiniteField operator* (int64 o) {
    return FiniteField((x * o) % P);
  }
  inline void operator*= (FiniteField o) {
    *this *= o.x;
  }
  inline void operator*= (int64 o) {
    x = (x * o) % P;
  }
};

struct Edge {
  int from;
  int to;
};

vector<vector<Edge>> ReadUndirectedGraph(int n, int m, bool is_one_indexed=false) {
  vector<vector<Edge>> graph(n);
  for (int i = 0; i < m; i++) {
    int v1, v2;
    cin >> v1 >> v2;
    if (is_one_indexed) {
      v1--;
      v2--;
    }
    graph[v1].push_back(Edge({v1, v2}));
    graph[v2].push_back(Edge({v2, v1}));
  }
  return graph;
}

int main() {
  int n, k;
  cin >> n >> k;
  vector<vector<Edge>> graph = ReadUndirectedGraph(n, n - 1, true);

  std::function<FiniteField(int, int, int)> solve =
      [k, &graph, &solve](int v, int parent, int depth) {
    int numChildren = graph[v].size() - (depth > 0 ? 1 : 0);
    if (numChildren == 0) return FiniteField(1);
    int numColors = k - 1 - (depth > 0 ? 1 : 0);
    if (numColors < numChildren) return FiniteField(0);
    FiniteField ans = FiniteField(1);
    for (int i = 0; i < numChildren; i++) {
      ans *= numColors - i;
    }
    for (const auto& e : graph[v]) {
      if (e.to == parent) continue;
      ans *= solve(e.to, v, depth + 1);
    }
    return ans;
  };
  auto solution = solve(0, -1, 0) * k;
  cout << solution.x << endl;
}

Measured memory_bytes: 11520
#include <iostream>
#include <cmath>
#include <vector>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <numeric>
#include <limits>

using namespace std;

typedef long long ll;

int main()
{
    char a[11],b[11],c[11];
    scanf("%s%s%s",a,b,c);
    if(a[strlen(a)-1]==b[0]&&b[strlen(b)-1]==c[0])
        cout<<"YES"<<endl;
    else
        cout<<"NO"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define IL inline
#define _  105
#define ll long long
#define RG register
using namespace std ;

IL int gi() {
	RG int data = 0 , fu = 1 ; RG char ch = 0 ;
	while(ch != '-' && (ch < '0' || ch > '9')) ch = getchar() ; if(ch == '-') fu = -1 , ch = getchar() ;
	while('0' <= ch && ch <= '9') data = (data << 1) + (data << 3) + (ch ^ 48) , ch = getchar() ; return data * fu ;
}

int n , B[_] , q[_] , nq ;

struct _Edge{int u , v ; } E[_ * _] ; int nE ; 

int main() {
	n = gi() ;
	if(n & 1) {
		for(int i = 0; i <= n /2; i ++) {
			int x = i , y = n - i ;
			for(int j = 1; j <= n; j ++)
				if(x != j && y != j) {
					if(x && x < j) E[++ nE] = (_Edge){x , j} ;
					if(y < j) E[++ nE] = (_Edge){y , j} ;
				}
		}
	}
	else {
		for(int i = 1; i <= n / 2; i ++) {
			int x = i , y = n + 1 - i ;
			for(int j = 1; j <= n; j ++)
				if(x != j && y != j) {
					if(x && x < j) E[++ nE] = (_Edge){x , j} ;
					if(y < j) E[++ nE] = (_Edge){y , j} ;
				}
		}
	}
	cout << nE << endl ;
	for(int i = 1; i <= nE; i ++) cout << E[i].u << " " << E[i].v << endl ;
	return 0 ;
}


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

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;

vvi g;
vi v;

void dfs(int u, int k) {
	v[u] = k;
	for (auto z:g[u]) {
    if (v[z]) continue;
    dfs(z, k);
  }
}

int main() {
	int n, m;
	cin >> n >> m;
	vi a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		a[i]--;
	}
	g = vvi(n);
	for (int i = 0; i < m; i++) {
		int u, v;
		cin >> u >> v;
		u--;
		v--;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	v = vi(n);
  int k = 1;
	for (int i = 0; i < n; i++) {
		if (v[i]) continue;
		dfs(i, k);
    k++;
	}
	int c = 0;
  for (int i = 0; i < n; i++) c += v[i] == v[a[i]];
	cout << c << endl;
}


Measured memory_bytes: 8576
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

type dlist struct {
	value int
	prev  *dlist
	next  *dlist
}

var head, last *dlist

var sc = bufio.NewScanner(os.Stdin)

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	var (
		n, value int
	)
	head = new(dlist)
	last = new(dlist)
	head.next = last
	last.prev = head

	fmt.Scan(&n)
	for i := 0; i < n; i++ {
		s := nextLine()
		switch s {
		case "deleteFirst":
			deleteFirst()
		case "deleteLast":
			deleteLast()
		default:
			ss := strings.Split(s, " ")
			switch ss[0] {
			case "insert":
				value, _ = strconv.Atoi(ss[1])
				insert(value)
			case "delete":
				value, _ = strconv.Atoi(ss[1])
				deleteC(value)
			}
		}
	}

	dl := head.next
	fmt.Print(dl.value)
	dl = dl.next
	for {
		if dl == last {
			break
		}
		fmt.Print(" ", dl.value)
		dl = dl.next
	}
	fmt.Println()
}

func insert(v int) {
	dl := new(dlist)
	dl.value = v
	dl.prev = head
	dl.next = head.next

	head.next = dl
	dl.next.prev = dl
}

func deleteC(v int) {
	dl := head.next
	for dl != last {
		if dl.value == v {
			dl.prev.next = dl.next
			dl.next.prev = dl.prev
			return
		}
		dl = dl.next
	}
}

func deleteFirst() {
	head.next = head.next.next
	head.next.prev = head
}

func deleteLast() {
	last.prev.prev.next = last
	last.prev = last.prev.prev
}



Measured memory_bytes: 62956
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String... args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();

		String[] ss = new String[n];

		for (int i = 0; i < n; i++) {
			ss[i] = in.next();
		}

		int[] num = new int['z' - 'a' + 1];

		Arrays.fill(num, 5000);

		for (char c = 'a'; c <= 'z'; ++c) {
			for (int i = 0; i < ss.length; i++) {
				int tmp = 0;
				for (int j = 0; j < ss[i].length(); j++) {
					if(ss[i].charAt(j) == (char)c) {
						tmp++;
					}
				}
				if(num[c - 'a'] > tmp) {
					num[c - 'a'] = tmp;
				}
			}
		}
		String ans = "";

		for (int i = 0; i < num.length; i++) {
			if(num[i] > 0) {
				for (int j = 0; j < num[i]; j++) {
					ans += (char)(i + 'a');
				}
			}
		}

		System.out.println(ans);
	}
}


Measured memory_bytes: 21588
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_set>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<complex>
#include<tuple>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;

vector<ll> uft;
vector<ll> bsum;
vector<ll> ans;
vector<pll> A;

ll parent(ll w){
    if(uft[w]==w){return w;}
    return uft[w]=parent(uft[w]);
}

void merge(ll a,ll b){
    a=parent(a); b=parent(b);
    if(a==b){return;}
    ans[a]=min(ans[a]+bsum[b],max(ans[b],A[a].F-A[a].S)+bsum[a]);
    bsum[a]+=bsum[b];
    uft[b]=a;
}



int main(){
    ll n,m;
    cin>>n>>m;
    uft.resize(n);
    bsum.resize(n);
    ans.resize(n);
    A.resize(n);
    vector<pll> a(n);
    for(auto &I:A){cin>>I.F>>I.S;}
    for(int i=0;i<n;i++){
        bsum[i]=A[i].S;
        uft[i]=i;
        ans[i]=max(A[i].F,A[i].S);
        a[i]={A[i].F-A[i].S,i};
    }
    vector<vector<ll>> edge(n);
    for(int i=0;i<m;i++){
        ll u,v;
        cin>>u>>v;
        u--; v--;
        edge[u].push_back(v);
        edge[v].push_back(u);
    }
    vector<bool> used(n,false);
    sort(a.begin(),a.end());
    for(auto &I:a){
        used[I.S]=true;
        for(auto &T:edge[I.S]){
            if(used[T]){merge(I.S,T);}
        }
    }
    cout<<ans[parent(0)]<<endl;
    

    return 0;
}


Measured memory_bytes: 11776
#include<bits/stdc++.h>
using namespace std;
struct activity{
    int a,b,c;
};
int solve(activity arr[],int n){
    int dp[n+1][3];
    dp[1][0] = arr[1].a;
    dp[1][1] = arr[1].b;
    dp[1][2] = arr[1].c;
    for(int i=2;i<=n;i++){
        dp[i][0] = arr[i].a + max(dp[i-1][1],dp[i-1][2]);
        dp[i][1] = arr[i].b + max(dp[i-1][0],dp[i-1][2]);
        dp[i][2] = arr[i].c + max(dp[i-1][0],dp[i-1][1]);
    }
    return max(dp[n][0],max(dp[n][1],dp[n][2]));
}
int main(){
    int n;
    cin>>n;
    activity arr[n+1];
    for(int i=1;i<=n;i++){
        cin>>arr[i].a>>arr[i].b>>arr[i].c;
    }
    cout<<solve(arr,n)<<endl;
    return 0;
}

Measured memory_bytes: 5964
#include <cstdio>
#include <cstdlib>
#include <string>
#include <iostream>
#include <stack>

using namespace std;
static const int N=100;
static const int WHITE=0;
static const int GRAY=1;
static const int BLACK=2;

int n,M[N][N];
int d[N], color[N],f[N],tt;

void dfs_visit(int u){
    int v;
    d[u]=++tt;
    color[u]=GRAY;
    for(v=0;v<n;v++){
        if (M[u][v]==0){continue;}
        if(color[v]==WHITE)dfs_visit(v);
    }
    color[v]=BLACK;
    f[u]=++tt;
}

void dfs(){
    int u;
    tt=0;
    for (u=0;u<n;u++)color[u]=WHITE;

    for (u=0;u<n;u++){
        if(color[u]==WHITE) dfs_visit(u);
    }
    for (u=0;u<n;u++){
        printf("%d %d %d\n",u+1,d[u],f[u]);
    }
};

int main()
{
    int u,k,v;
    cin>>n;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++) M[i][j]=0;
    }
    for(int i=0;i<n;i++){
        cin>>u>>k;
        u--;
        for(int j=0;j<k;j++){
            cin>>v;
            v--;
            M[u][v]=1;
        }
    }
    for(int i=0;i<n;i++) d[i]=-1;
    dfs();
    return 0;
}


Measured memory_bytes: 3156
N = int(input())
AB = [list(map(int, input().split())) for _ in range(N)]
A = sorted([ab[0]*(2-N%2) for ab in AB])
B = sorted([ab[1]*(2-N%2) for ab in AB])
if N%2 == 1:
  print(B[N//2]-A[N//2]+1)
else:
  print((B[N//2]+B[N//2-1])//2-(A[N//2]+A[N//2-1])//2+1)


Measured memory_bytes: 132512
//
//  main.cpp
//  F
//
//  Created by 曾憲揚 on 2020/8/9.
//  Copyright © 2020 曾憲揚. All rights reserved.
//

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

const int maxn = 200005;
int u[maxn], v[maxn];

int main(int argc, const char * argv[]) {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    
    int n; cin >> n;
    for(int i=1; i<=n-1; i++){
        cin >> u[i] >> v[i];
    }
    
    long long ans = 0;
    
    for(int i=1; i<=n; i++){
        ans += (1LL * i * (n-i+1));
    }
    
    for(int i=1; i<=n-1; i++){
        int m = min(u[i], v[i]), M = max(u[i], v[i]);
        ans -= (1LL * m * (n-M+1));
    }
    
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 5216
n,k = gets.chomp.split.map(&:to_i)
p = gets.chomp.split.map(&:to_i)
rs = []

rs[0] = p[0]

n.times do |i|
  next if i == 0
  rs << rs[i-1] + p[i]
end

index = 0



max_num = rs[0]

if n != k

  (n-k).times do |i|
    tmp = rs[k+i] - rs[i]

    if tmp > max_num
      max_num = tmp
      index = i
    end
  end

  arr = []
  k.times do |i|
    arr << p[index + i + 1]
  end

else
  arr = p

end


ans = 0
arr.each do |i|

  if i % 2 == 0
    ans += (i.to_f/2).ceil + 0.5
  else
    ans += (i.to_f/2).ceil
  end
end

puts ans



Measured memory_bytes: 17932
#include <iostream>
#include <string.h>
#include <stdio.h>
using namespace std;
typedef long long llong;

llong MOD = 998244353;

int k,n;
llong POW2[10011];
llong fact[10011];
llong invFactCache[10011];

llong FastPow(llong val,llong p)
{
    if (p == 0)
        return 1LL;
    else if (p == 1)
        return val % MOD;

    llong P = FastPow(val, p/2);
    P = (P*P) % MOD;

    if (p % 2 == 1)
    {
        P = (P*val) % MOD;
    }

    return P;
}

llong invFact(int N)
{
    if (invFactCache[N] != -1)
        return invFactCache[N];

    invFactCache[N] = FastPow(fact[N], MOD-2);

    return invFactCache[N];
}

llong C(int K,int N)
{
    llong ans = (fact[N] * invFact(K)) % MOD;
    ans *= invFact(N-K);
    ans %= MOD;

    return ans;
}

llong Distribute(int usable,int boxes)
{
    if (usable < 0)
        return 0LL;
    if (usable == 0)
        return 1LL;

    int N = boxes + usable - 1;
    int K = usable;

    return C(K, N);
}

int main()
{
    int i,j;
    int groups,free,special;
    int lb;
    int p;
    llong ans = 0;
    int boxes;

    memset(invFactCache,-1,sizeof(invFactCache));

    POW2[0] = 1LL;
    fact[0] = 1LL;

    for (i=1;i<=10000;i++)
    {
        POW2[i] = POW2[i-1] * 2LL;
        POW2[i] %= MOD;

        fact[i] = fact[i-1] * (llong)i;
        fact[i] %= MOD;
    }

    scanf("%d %d",&k,&n);

    for (i=2;i<=2*k;i++)
    {
        if (i <= k+1)
        {
            if (i % 2 == 1)
            {
                groups = i/2;
                special = 0;
                free = k - 2 * groups;
            }
            else
            {
                groups = (i-1) / 2;
                special = 1;
                free = k - 2 * groups - 1;
            }
        }
        else
        {
            if (i % 2 == 1)
            {
                lb = i / 2;
                groups = k - lb;
                special = 0;
                free = k - 2 * groups;
            }
            else
            {
                lb = i / 2;
                groups = k - lb;
                special = 1;
                free = k - 2 * groups - 1;
            }
        }

        //cout<<"got "<<groups<<" groups and "<<free<<" frees with "<<special<<" specials"<<endl;

        int usable;
        llong tempVal = 0;

        ans = 0;
        for (p = 0; p <= groups && p <= n; p++)
        {
            ///Use special
            if (special == 1)
            {
                usable = n - p - 1;
                boxes = p + free;

                tempVal = Distribute(usable, boxes) * POW2[p];
                tempVal %= MOD;
                tempVal *= C(p, groups);
                tempVal %= MOD;
                ans += tempVal;
            }

            ///Do not use special
            usable = n - p;
            boxes = p + free;

           //cout<<"Using "<<p<<" groups so "<<usable<<" in "<<boxes<<" gives "<<Distribute(usable,boxes)<<" * "<<POW2[p]<<endl;
            tempVal = Distribute(usable, boxes) * POW2[p];
            tempVal %= MOD;
            tempVal *= C(p, groups);
            tempVal %= MOD;
            ans += tempVal;
        }

        printf("%lld\n",ans%MOD);

    }
}


Measured memory_bytes: 512
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <time.h>

#define REP(i,n) for(i=0;i<n;i++)
#define ll long long

int main(void){
    int a,b;
    scanf("%d",&a);
    scanf("%d",&b);

    if((a*b)%2==0){
        printf("Even");
    } else{
        printf("Odd");
    }
    
    
    return 0;
}

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

int main(void){
  double ans = 0;
  int n;
  cin >> n;

  for(int i=0;i<n;i++){
    double x;
    string u;
    cin >> x >> u;
    if(u == "JPY"){
      ans += x;
    }else{
      ans += (x * 380000.0);
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
n = gets.to_i
obj = {}
obj['S'] = [false]*13
obj['H'] = [false]*13
obj['C'] = [false]*13
obj['D'] = [false]*13
n.times do |i|
  k, v = gets.split
  obj[k][v.to_i - 1] = true
end
obj.each do |key, val|
  val.length.times do |i|
    puts "#{key} #{i + 1}" unless val[i]
  end
end

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

int main(){
  double r;
  cin >>r;
  double ans = 2*r*3.1415926535897;
  cout << fixed << setprecision(9) << ans << endl;
}


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

using namespace std;
const int mod = 1e9 + 7;
const long long INF = 1e18;
#define PI 3.141592653589793
#define REP(i, n) for(int i = 0;i < n;++i)
long long H,W,K,N,D;
long long A=0;
int main()
{
  cin>>K;
  for(int i=0;i<1000000;i++){
    A=(A*10+7)%K;;
    if(A==0){
      cout<<i+1;
      return 0;
    }
    //cout<<A<<"\n";
  }
  cout<<-1;
  return 0;
}





Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int n;
double ans,t1;
string t2;
int main(){
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>t1>>t2;
		if(t2[0]=='J'){
			ans+=(int)(t1+0.001);
		}else{
			ans+=t1*380000;
		}
	}
	cout<<ans;
	return 0;
} 

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

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

const ll INF64 = 1LL << 60;
const int INF32 = 1 << 29;
const int MOD = 1000000007;

// Library
//

int main() {
#ifdef MYLOCAL
    ifstream in("input.txt");
    cin.rdbuf(in.rdbuf());
#endif

    int n, a; cin >> n >> a;
    if(n % 500 <= a){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256