akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(int i = a; i < b; i++)
typedef pair<int,int> P;
typedef long long ll;

int main(){
    int H, W, D; cin >> H >> W >> D;
    vector<P> mp(H * W);
    rep(i, 0, H) rep(j, 0, W){
        int p; cin >> p; p--;
        mp[p] = {i,j};
    }

    int Q; cin >> Q;
    vector<int> L(Q), R(Q);
    rep(i, 0, Q) cin >> L[i] >> R[i], L[i]--, R[i]--;

    vector<ll> sum(H * W);
    rep(i, 0, H * W){
        if(i < D) sum[i] = 0;
        else{
            int dx = abs(mp[i].first - mp[i-D].first);
            int dy = abs(mp[i].second - mp[i-D].second);
            sum[i] = sum[i - D] + dx + dy;
        }
    }
/*     rep(i, 0, H * W){
        cout << i << " " << sum[i] << endl;
    } */
    rep(i, 0, Q){
        cout << sum[R[i]] - sum[L[i]] << endl;
    }
}

Measured memory_bytes: 3328
s = input()
t = input()

sl = list(s)
tl = list(t)

from collections import Counter
sc = Counter(sl)
tc = Counter(tl)

sp =[]
tp =[]

alp = "abcdefghijklmnopqrstuvwxyz"

for i in alp:
    sp.append(sc[i])
    tp.append(tc[i])

sps =sorted(sp)
tps = sorted(tp)

for i,j in zip (sps,tps):
    if i ==j:
        pass
    else:
        print("No")
        exit()
print("Yes")

Measured memory_bytes: 12844
#include<bits/stdc++.h> 
using namespace std;
string str;
int main()
{
    int len,i,j;
    cin>>str;
    len=str.size();
    for(i=0;i<len;i++)
    {
        if(str[i]=='C')
        {
            for(j=i+1;j<len;j++)
            {
                if(str[j]=='F')
                {
                    printf("Yes");
                    return 0;
                }
            }
        }
    }
    printf("No");
    return 0;
}


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

// definitions
#define f first
#define s second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define rep(i, l, r) for (long long i = (l); i < (long long)(r); i++)
#define repb(i, r, l) for (long long i = (r); i > (long long)(l); i--)
#define lowb(a, x) ( lower_bound((a).begin(), (a).end(), (x)) - (a).begin())
#define uppb(a, x) ( upper_bound((a).begin(), (a).end(), (x)) - (a).begin())
#define sum(a)     ( accumulate ((a).begin(), (a).end(), 0ll))
#define high(x) __builtin_popcountll(x)
#define pb push_back
#define pf push_front
#define mod1 998244353
#define mod 1000000007
#define MAX_CHAR 256
#define pi 3.1415926535897932384

using namespace std;
typedef vector<long long> vl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector< pair<long long, long long> > vp;
typedef vector<tuple<long long , long long , long long> > vtup;
typedef deque <long long> dql;
typedef deque <char> dqc;
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;

const ll INF=1e18;
// prevent collisions in unordered_map
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
typedef unordered_map <long long, long long, custom_hash> umap;

// cin and cout overloaded for vectors and sets
template<typename T>             
istream& operator>>(istream& is,  vector<T>& v)
{
    for (auto& i : v) 
        is >> i;        
    return is;
}
template<typename T>             
ostream& operator<<(ostream& os,  vector<T>& v)
{
    for (auto& i : v) 
        os << i << ' '; 
        return os;
}

// standard functions
ll mystoi(string str)
{
    stringstream ss(str);
    ll ans=0;
    ss >> ans;

    return ans;
}

ll exp(ll x, ll ex) 
{
    ll ans = 1ll;
    while (ex > 0) 
    {
        if (ex & 1ll) ans = (ans * x);
        ex >>= 1ll;
        x = (x * x);
    }
    return ans;
}

bool sort_cond(const pair<ll,ll> &a, const pair <ll,ll> &b)
{
    if(a.first==b.first)
        return a.second<b.second;

    return a.first < b.first;
}

// code beigns in main
int main()
{

    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ll t=1;
    // cin >> t;

    while(t--)
    {
        ll n,k;
        cin >> n >>k;

        vl a(n);
        cin >> a;

        sort(all(a));

        ll s=0;
        rep(i,0,k) s+=a[i];
        cout << s << endl;
    }
}

Measured memory_bytes: 3616
#include <stdio.h>
#include <iostream>
using namespace std;

int main()
{
	long lnN;
	cin >> lnN;

	long lnWariCnt = lnN / 15;

	long lnTotal = lnN * 800 - lnWariCnt * 200;
	
	cout << lnTotal;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    int y, m, d;
    char slash1, slash2;
    cin >> y >> slash1 >> m >> slash2 >> d;
    if(y >= 2019 && m >= 5) cout << "TBD" << endl;
    else cout << "Heisei" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main()
{
while(true)
{
int w,h;
scanf("%d %d", &h, &w);
if(0==h&&0==w)
break;
for(int i = 0; i < h; ++i)
{
for(int j = 0; j  <w; ++j)
{
if(i==0||i==h-1)
{
printf("#");
}
else
{
if(j==0||j==w-1) printf("#");
else printf(".");
}
}
printf("\n");
}
printf("\n");
}
return 0;
}

Measured memory_bytes: 1000
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//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; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
*/

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

    cout << max(x-t, 0LL) << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            String s = sc.nextLine();
            String[] req = s.split(" ");
            System.out.println(String.valueOf(Integer.parseInt(req[0]) + Integer.parseInt(req[1])).length());
        }

    }
}

Measured memory_bytes: 26220
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
const int MOD = 1e9+7;
const long long INF = 1LL << 60;
const int INF_INT = 1e9;
typedef long long ll;
int main(){
    int n; cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    int next=0, cnt=0;
    for(int i = 0; i < n; i++){
        cnt++;
        if(a[next] == 2){
            cout << cnt << endl;
            return 0;
        }
        next = a[next]-1;
    }
    cout<<-1<<endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
#include <deque>

using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

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

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;
typedef pair<ll, ll> PLL;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;

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

  cin >> n;

  ll xmi = LLINF, xma = -LLINF, ymi = LLINF, yma = -LLINF;
  while(n--) {
    ll x, y;
    cin >> x >> y;

    xmi = min(xmi, (x + y));
    xma = max(xma, (x + y));
    ymi = min(ymi, (x - y));
    yma = max(yma, (x - y));
  }

  cout << max(xma - xmi, yma - ymi) << endl;
}


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

#define LL long long
#define RG register

using namespace std;
template<class T> inline void read(T &x) {
	x = 0; RG char c = getchar(); bool f = 0;
	while (c != '-' && (c < '0' || c > '9')) c = getchar(); if (c == '-') c = getchar(), f = 1;
	while (c >= '0' && c <= '9') x = x*10+c-48, c = getchar();
	x = f ? -x : x;
	return ;
}
template<class T> inline void write(T x) {
	if (!x) {putchar(48);return ;}
	if (x < 0) x = -x, putchar('-');
	int len = -1, z[20]; while (x > 0) z[++len] = x%10, x /= 10;
	for (RG int i = len; i >= 0; i--) putchar(z[i]+48);return ;
}
const int N = 45, Mod = 1e9 + 7;
int n, x, y, z, f[N][262144];
unsigned long long g[262144][11];
void pls(int &x, int y) {
	x += y;
	if (x >= Mod) x -= Mod;
}
int main() {
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
	int n, x, y, z, limit;
	read(n), read(x), read(y), read(z);
	limit = (1 << (x + y + z - 1)) | (1 << (y + z - 1)) | (1 << (z - 1));
	for (int S = 0; S < (1 << 18); S++)
		for (int i = 1; i <= 10; i++)
			if ((S & limit) == limit) g[S][i] = S;
			else g[S][i] = (((LL)S << i) | (1 << (i - 1))) & ((1 << 18) - 1);
	f[0][0] = 1;
	for (int i = 0; i < n; i++)
			for (int k = 1; k <= 10; k++)
		for (int S = 0; S < (1 << 18); S++)
				pls(f[i + 1][g[S][k]], f[i][S]);
	int ans = 0;
	for (int i = limit; i < (1 << 18); i++)
		if ((i & limit) == limit) pls(ans, f[n][i]);
	write(ans);
	return 0;
}


Measured memory_bytes: 65792
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

#define IN(l, r, x) ((l) <= (x) && (x) < (r))

set<int> ans;
int n, k;
vs32 a;
vector< bool > used;
vs32 choosed;
int pos = 0;

void dfs()
{
    if (pos == k)
    {
        int t = 0;
        rep (i, choosed.size())
        {
            int x = choosed[i];
            if (x >= 10)
            {
                t = t * 100 + x;
            }
            else
            {
                t = t * 10 + x;
            }
        }
        ans.insert(t);
        return;
    }

    rep (i, n)
    {
        if (!used[i])
        {
            used[i] = true;
            choosed[pos++] = a[i];
            dfs();
            used[i] = false;
            --pos;
        }
    }
}

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

    while (true)
    {
        cin >> n >> k;
        if (n == 0 && k == 0) break;
        a.resize(n);
        rep (i, n) cin >> a[i];
        used.resize(n, false);
        choosed.resize(k);
        ans.clear();

        dfs();

        cout << ans.size() << "\n";
    }
    return 0;
}




Measured memory_bytes: 3212
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast", "unroll-loops")
#define ll long long 
#define pii pair<int, int>
#define ull unsigned ll
#define f first
#define s second
#define FOR(i,a,b) for (int i=(a); i<(b); i++)
#define REP(i,n) for (int i=0; i<(n); i++)
#define RREP(i,n) for (int i=(n-1); i>=0; i--)
#define ALL(x) x.begin(),x.end()
#define SZ(x) x.size()
#define MNTO(a,b) a = min(a,(__typeof__(a))(b))
#define MXTO(a,b) a = max(a,(__typeof__(a))(b))
#define pb push_back
#define debug(x) cerr<<#x<<" is "<<x<<endl
using namespace std;

// #define int ll

const int maxn = 1e5+5;
const int iinf = 1<<29;
const ll inf = 1ll<<60;
const ll mod = 1e9+7;


void GG(){cout<<"No\n"; exit(0);}


main(){
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    srand(time(NULL));
    int n, x; cin>>n>>x;
    vector<ll> a(n), mn(n);
    REP(i,n) {
    	cin>>a[i]; mn[i]=a[i];
    }
    ll B = 0;
    ll ans = inf;
    REP(i,n){
    	ll re = B;
    	for (ll dd: mn) re+=dd;
    	MNTO(ans, re);
    	if (i==n-1) break;
    	REP(j,n) {
    		MNTO(mn[j], a[(j-i-1+n)%n]);
    	}
    	B+=x;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
typedef unsigned long long ll;
using namespace std;
inline int max(int a,int b){return a>b?a:b;}
inline int min(int a,int b){return a<b?a:b;}
inline int rd(){
	int res=0,sign=1;char ch;
	while((ch=getchar())<'0'||ch>'9')if(ch=='-')sign=-1;res=res*10+ch-48;
	while((ch=getchar())>='0'&&ch<='9')res=res*10+ch-48;
	return res*sign;
}
int n;
int f[40]={0,1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
int main(){
	n=rd();
	printf("%d\n",f[n]); 
	return 0;
}


Measured memory_bytes: 256
#! /usr/bin/env python
# -*- coding: utf-8 -*-

''' ??????????????? '''

# ????????????????????°?????????N(N-1)/2????????§???
# ?¨???????:O(n^2)


def selection_sort(A, N):
    swap_num = 0  # ???????????°

    for i in range(N):
        minj = i
        for j in range(i, N, 1):
            if A[j] < A[minj]:
                minj = j
        # swap
        if i != minj:
            tmp = A[i]
            A[i] = A[minj]
            A[minj] = tmp
            swap_num += 1

    return (A, swap_num)


if __name__ == "__main__":
    N = int(input())
    A = list(map(int, input().split()))
    # A = [5, 2, 4, 6, 1, 3]
    # N = len(A)
    array_sorted, swap_num = selection_sort(A, N)
    print(' '.join(map(str, array_sorted)))
    print(swap_num)

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

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	for (int i = 1; i <= 50000; ++i) {
		if (int(i * 1.08) == n) {
			cout << i << endl;
			return 0;
		}
	}
	cout << ":(" << endl;
	return 0;
}

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

using namespace std;

signed main()
{
    int x,y;
    std::vector<int> Size(3);
    cin>>x>>y;
     cout<<(x*3+y)/2<<endl;
    return 0;
}



Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
class Program{
	static void Main(){
		long[] s=Array.ConvertAll(Console.ReadLine().Split(),long.Parse);
		long[] arr=new long[s[1]+1];
		long[] r=new long[s[1]+1];
		for(int i=1;i<=s[1];i++){
			arr[i]=int.Parse(Console.ReadLine());
			r[i]=arr[i]+r[i-1];
		}
		long ans=Math.Max(arr[1],s[0]-arr[1]);
		for(int i=1;i<s[1];i++){
			int m1=(int)(s[1]+i+1)/2;
			int m2=(int)(s[1]+2-i)/2;
			if((i+s[1])%2==0){
				ans=Math.Max(ans,2*(r[m1-1]-r[i-1])+arr[m1]+s[0]*(s[1]-i)-2*(r[s[1]]-r[m1]));
				ans=Math.Max(ans,2*(r[m2-1])+s[0]*(s[1]+1-i)-arr[m2]-2*(r[s[1]+1-i]-r[m2]));
			}
			else{
				ans=Math.Max(ans,2*(r[m1-1]-r[i-1])+s[0]*(s[1]-i)-arr[m1]-2*(r[s[1]]-r[m1]));
				ans=Math.Max(ans,2*(r[m2-1])+arr[m2]+s[0]*(s[1]+1-i)-2*(r[s[1]+1-i]-r[m2]));
			}
		}
		Console.WriteLine("{0}",ans);
	}
}

Measured memory_bytes: 20184
K=int(input())
b=[[i] for i in range(1,10)]
l=[0,9, 35, 110, 327, 956, 2782, 8089, 23527, 68468,200000]
for i in range(11):
    if K<=l[i]:
        N=i
        K-=l[i-1]
        break
for i in range(N-1):
    a=[]
    for j in b:
        if j[-1]!=0:
            a.append(j+[j[-1]-1])
        a.append(j+[j[-1]])
        if j[-1]!=9:
            a.append(j+[j[-1]+1])
    b=a
print(*b[K-1],sep="")

Measured memory_bytes: 31220
N = int(input())
A = list(map(int, input().split())) 

def sumXOR( arr,  n): 
    sum = 0
    for i in range(0, 64): 
  
        #  Count of zeros and ones 
        zc = 0
        oc = 0
           
        # Individual sum at each bit position 
        idsum = 0
        for j in range(0, n): 
            if (arr[j] % 2 == 0): 
                zc = (zc + 1)
                  
            else: 
                oc = (oc + 1)
            arr[j] = (arr[j] >> 1) 
          
           
        # calculating individual bit sum  
        idsum = (oc * zc * ((1 << i))) % 1000000007
   
        # final sum     
        sum = (sum + idsum)
      
    return sum
  
  
  
  
print(sumXOR(A, N)  % 1000000007)

Measured memory_bytes: 122808
import java.util.Scanner;
 
public class Main {
    static Scanner in;
 
    void solve() {
        String string = in.nextLine();
        if(string.indexOf("AC") >= 0) {
            System.out.println("Yes");
        }else {
            System.out.println("No");
        }
    }
 
    public static void main(String[] args) {
        in = new Scanner(System.in);
        new Main().solve();
    }
}

Measured memory_bytes: 23636
#include<iostream>
using namespace std;
int main()
{
	long long int A,B,C,final;
	cin>>A>>B>>C;
	final=A*B*C;
	if(final%2==0)
		cout<<"0"<<endl;
	else
	{
		long long int a,b,c;
		a=A*B;
		b=B*C;
		c=A*C;
		if(a<=b&&a<=c)
			cout<<a<<endl;
		else if(b<=a&&b<=c)
			cout<<b<<endl;
		else if(c<=a&&c<=b)
			cout<<c<<endl; 
			
	}
	    
	return 0;
} 

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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
typedef long long ll;


int main() {
    int N,M,C; cin >> N >> M >> C;
    vector<int> B(M);
    REP(i,M) cin >> B[i];
    vector<vector<int>> A(N, vector<int>(M));
    REP(i,N){
        REP(j,M){
            cin >> A[i][j];
        }
    }

    int ans = 0;
    REP(i,N){
        int sum = C;
        REP(j,M){
            sum += B[j] * A[i][j];
        }
        if (sum>0){
            ans ++;
        }
    }

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

Measured memory_bytes: 3632
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
char s[200010];
int t[200010];
int f[200010];
int minn[(1<<26)+1];
int main()
{
	scanf("%s",s+1);
	for (int i=1;i<=strlen(s+1);i++)
		t[i]=t[i-1],t[i]^=(1<<(s[i]-'a'));
	for (int i=0;i<=(1<<26)-1;i++) minn[i]=1e9;
	minn[0]=0;
	for (int i=1;i<=strlen(s+1);i++)
	{
		//cout<<"t[i]="<<t[i]<<endl;
		f[i]=1e9;
		for (int j=0;j<=25;j++)
			f[i]=min(f[i],minn[t[i]^(1<<j)]+1);//,cout<<(t[i]^(1<<j))<<" "<<minn[t[i]^(1<<j)]<<endl;
		f[i]=min(f[i],minn[t[i]]+1);
		minn[t[i]]=min(minn[t[i]],f[i]);
	}
	printf("%d",f[strlen(s+1)]);
}

Measured memory_bytes: 264320
#include <bits/stdc++.h>
using namespace std;
int main(){
    int x,y;
    cin>>x>>y;
    vector <string> a(x);
    for(int x1=0;x1<x;x1++){
        cin>>a.at(x1);
        
    }
    for(int x1=0;x1<x;x1++){
        
        if( (a.at(x1)).find("#")==string::npos){
            a.erase(a.begin()+x1);
            x--;x1--;
     }
    }
    
    for(int y2=0;y2<y;y2++){
        int k=0;
        for(int x2=0;x2<x;x2++){
            if( (a.at(x2))[y2]=='#' ){
                k=1;
                break;
            }
        }
        if(k==1){continue;}
        for(int x2=0;x2<x;x2++){
            (a.at(x2)).erase(y2,1);
            
        }y2--;y--;
        
    }
    
    for(auto &  x : a){
        for(auto & x1 :x){
            cout<<x1;
        }
        cout<<endl;
    }
} 
    

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

int main(){
    int x,y;
    
    for (;;){
        cin >> x >> y;
        if ( x == 0 && y == 0 ) break;
        if (y > x){
            cout << x << " " << y << endl;
        } else {
            cout << y << " " << x << endl;
        }
    }   
        
    return 0;
}

Measured memory_bytes: 3092
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <cmath>
#include <bits/stdc++.h>

using namespace std;

typedef long long lint;
typedef vector<int> vi;
typedef pair<int,int> pii;

typedef vector<lint> vl;
typedef pair<lint,lint> pll;

lint mod = 998244353;
lint pow(lint a, lint n){
    lint res = 1;
    lint base = a;
    while(n > 0){
        if (n%2) res = res*base%mod;
        base = base*base%mod;
        n = n/2;
    }
    return res;
}

lint rev(lint a){
    return pow(a, mod-2);
}

lint comb(lint n, lint m, vl &la, vl &rela){
    return (la[n] * rela[m] % mod) * rela[n-m] % mod;
}

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

    int n; cin>>n;
    vector<string> vs(n);
    for (auto &s: vs) cin>>s;

    vector<pii>  pseg; //min, tot
    vector<pii> nseg;
    int T = 0;
    for (string &s : vs){
        int cur = 0;
        int mi = 0;
        for (char c : s){
            if (c=='(') cur++;
            else cur--;
            mi = min(mi, cur);
        }
        T += cur;
        if (cur>0) pseg.push_back({mi, cur});
        else nseg.push_back({mi, cur});
    }

    if (T != 0) {cout<<"No"; return 0;}

    std::sort(pseg.rbegin(), pseg.rend());
    sort(nseg.begin(), nseg.end(), [](pii p1, pii p2 ){
        return p1.second - p1.first > p2.second - p2.first;
                       });

    int cur = 0;
    int id = 0;
    while(id < pseg.size() && pseg[id].first>= - cur){

        cur += pseg[id].second;
        id++;
    }
    if (id < pseg.size()) {cout<<"No"; return 0;}
    //else cout<<"Yes";

    id = 0;
    while(id < nseg.size() && nseg[id].first >= -cur){
        cur += nseg[id].second;
        id ++;
    }

    if (id < nseg.size()) {cout<<"No"; return 0;}
    cout<<"Yes";
}


Measured memory_bytes: 42504
#include <algorithm>
#include <string.h>
#include <iostream>
#include <stdio.h>
using namespace std;

typedef long long ll;
const ll N = 110;

ll f[N][N];

ll find(ll x) {
	while (x) {
		if (x / 10 == 0)
			return x;
		x /= 10;
	}
}

int main() {
	ll n;
	cin >> n;
	for (ll i = 1; i <= n; i++)
		f[i % 10][find(i)]++;
	
	ll ans = 0;
	for (ll i = 1; i <= 9; i++)
		for (ll j = 1; j <= 9; j++)
			ans += f[i][j] * f[j][i];
	
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <set>

const int MAXN=2e5+10;

int N,M,K;

using namespace std;

vector<int> friends[MAXN],blocks[MAXN];

int ans[MAXN],visited[MAXN];

set<int> transClosure;

void count(int cur){
    transClosure.insert(cur);
    visited[cur]=1;
    for(auto adj:friends[cur]){
        if (visited[adj]) continue;
        count(adj);
    }
}

int main(){
    scanf("%d%d%d",&N,&M,&K);

    for(int i=0;i<M;i++){
        int s,e;
        scanf("%d%d",&s,&e);
        friends[s].push_back(e);
        friends[e].push_back(s);
    }

    for(int i=0;i<K;i++){
        int s,e;
        scanf("%d%d",&s,&e);    
        blocks[s].push_back(e);
        blocks[e].push_back(s);
    }

    for(int i=1;i<=N;i++){
        if (!visited[i]){
            transClosure.clear();
            count(i);
            for(auto member:transClosure){
                ans[member]=transClosure.size();
                ans[member]-=(1+friends[member].size());
                int blocklist=0;
                for(auto b:blocks[member]) if (transClosure.count(b)) blocklist++;
                ans[member]-=blocklist;
            }
            
        }
        
       
        
    }

    for(int i=1;i<=N;i++) printf("%d ",ans[i]);
    putchar('\n');

    return 0;
}

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

bool IsPossible(int A, int B){
    if((A+B)%2==0){
        return true;
    }
    else{
        return false;
    }
}

int main(){
    int A,B; cin >>A >>B;
    if(IsPossible(A,B)==true){
      cout << (A+B)/2 << endl;
    }
  	else{
      cout << "IMPOSSIBLE" << endl;
    }
  return 0;
}

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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod= int(1e9)+7;
using P = pair<ll,ll>;
using ld=long double;

int main(){
    int n;cin >>n;
    int a,b;cin>>a>>b;
    int fi=0,se=0,th=0;
    vector<int>p(n);
    for (int i = 0; i < n; ++i){
        cin >>p[i];
        if(p[i]<=a)fi++;
        else if(p[i]<=b)se++;
        else th++;
    }
    int ans=min({fi,se,th});
    cout <<ans <<endl;
}


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


int main() {
	long long a, b, k;
	cin >> a >> b >> k;
	cout << max(0LL, a - k) << " " << max(0LL, b - max(k - a, 0LL));

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
const double PI = acos(-1);
const double EPS = 1e-15;
long long INF=(long long)1E17;
#define i_7 (long long)(1E9+7)
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;
bool prime(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd(b,a%b);
  }
}
 
long long lcm(long long x, long long y){
  return (x/gcd(x,y))*y;
}
 
class UnionFind {
    public:
    //各頂点の親の番号を格納する。その頂点自身が親だった場合は-(その集合のサイズ)を入れる。
    vector<int> Parent;
    
    //クラスを作るときは、Parentの値を全て-1にする。
    //以下のようにすると全てバラバラの頂点として解釈できる。
    UnionFind(int N) {
        Parent = vector<int>(N, -1);
    }
    
    //Aがどのグループに属しているか調べる
    int root(int A) {
        if (Parent[A] < 0) return A;
        return Parent[A] = root(Parent[A]);
    }
    
    //自分のいるグループの頂点数を調べる
    int size(int A) {
        return -Parent[root(A)];//先祖をrootで取っておきたい。
    }
    
    //AとBをくっ付ける
    bool connect(int A, int B) {
        //AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
        A = root(A);
        B = root(B);
        if (A == B) {
            //すでにくっついてるからくっ付けない
            return false;
        }
        
        //大きい方(A)に小さいほう(B)をくっ付けたい
        //大小が逆だったらAとBをひっくり返す。
        if (size(A) < size(B)) swap(A, B);
        
        //Aのサイズを更新する
        Parent[A] += Parent[B];
        //Bの親をAに変更する
        Parent[B] = A;
        
        return true;
    }
};

int main(){
  long long N,M;
  cin>>N>>M;
  string s,t;
  cin>>s;
  cin>>t;
  long long g,l,n,m;
  g = gcd(N,M);
  l = lcm(N,M);
  n = N/g;
  m = M/g;
  bool flag=true;
  for(long long i=0;i*n<N && i*m<M;i++){
    if(s[i*n]==t[i*m]){
      continue;
    }else{
      flag = false;
      break;
    }
  }
  if(flag){
    cout<<l<<endl;
  }else{
    cout<<-1<<endl;
  }
  return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<iomanip>
//#include<cstdio>
#include<vector>
#include<map>
#include<queue>
#include<algorithm>
#include<cmath>
#include<cassert>
using namespace std;
typedef long long ll;
const int Nmax=1e5, Mmax=1e5;
int N, M, B[Nmax];
ll A[Nmax], C[Mmax];

int main(){
    ll bsum = 0;
    cin >> N >> M;
    for(int i=0; i<N; i++) cin >> A[i];
    for(int i=0; i<M; i++){
        cin >> B[i] >> C[i];
    }

    sort(A, A+N);
    reverse(A, A+N);

    vector<pair<ll, int> > ops;
    for(int i=0; i<M; i++) ops.push_back({C[i], B[i]});
    sort(ops.begin(), ops.end());
    reverse(ops.begin(), ops.end());

    int j=0,k=0;
    ll ans = 0;
    for(int i=0; i<N; i++){
        if(k==M || A[j]>=ops[k].first){
            ans += A[j];
            j++;
        } else {
            ans += ops[k].first;
            if(ops[k].second==1) k++;
            else ops[k].second--;
        }
    }

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

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

int main()
{
  int n, q;
  while (cin >> n >> q && n && q) {
    int m, tmp, day[100] = {0};
    for (int i = 0; i < n; i++) {
      cin >> m;
      for (int j = 0; j < m; j++) {
	cin >> tmp;
	day[tmp]++;
      }
    }
    int max = 0, DAY = 0;
    for (int i = 0; i < 100; i++) {
      if (max < day[i] && q <= day[i]) {
	max = day[i];
	DAY = i;
      }
    }
    cout << DAY << endl; 
  }

  return 0;
}

Measured memory_bytes: 1160
# https://onlinejudge.u-aizu.ac.jp/problems/ALDS1_4_A
n = int(input())
S = list(map(int, input().split()))
q = int(input())
T = list(map(int, input().split()))

C = 0
for t in T:
    for s in S:
        if s == t:
            C = C + 1
            break

print(C)



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

int main () {
    int N;
    cin >> N;
    vector<long long> A(N+1);
    A[0] = 2;
    A[1] = 1;
    for(int i = 2; i <= N; i++) {
        A[i] = A[i - 1] + A[i - 2];
    }
    cout << A[N] << endl;
    return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
long long int N;
long long int A;
long long int B;
long long int C=0;
long long int i=0;
int D = 0;
  cin >> N; 
A = N/15;
B = N%15;


for(i=1;i<=A;i++){
	C=C+(8*15*(i-1)+60);
}
for(i=1;i<=B;i++){
	if(i%3!=0 && i%5!=0){
	D=D+(15*A+i);
}
}
  cout<<C+D<<endl;

}

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

int n,m,c;
int a[25][25];
int b[25];
int main()
{
	int cnt=0;
	scanf("%d%d%d",&n,&m,&c);
//	cout<<"c="<<c<<endl;
	for(int i=1;i<=m;i++)
		scanf("%d",&b[i]);
//	for(int i=1;i<=m;i++)
//		cout<<b[i]<<" ";
//	cout<<endl;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			scanf("%d",&a[i][j]);
		}
	}
//	for(int i=0;i<n;i++)
//	{
//		for(int j=0;j<m;j++)
//		{
//			cout<<a[i][j]<<" ";
//		}
//		cout<<endl;
//	}
	for(int i=1;i<=n;i++)
	{
		int sum=0;
		for(int j=1;j<=m;j++)
		{
//			cout<<"a="<<a[i][j]<<" "<<"b="<<b[j]<<endl;
			sum=sum+a[i][j]*b[j];
//			cout<<sum<<endl;
		}
//		cout<<"sum="<<sum<<endl;
		if((sum+c)>0)
			cnt++;
		sum=0;
	}
	printf("%d",cnt);
	return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <stack>
#include <cstddef>
#include <algorithm>

struct strongly_connected_component {
	using size_type = std::size_t;
private :
	size_type num;
	std::vector<std::vector<size_type>> g, scc;
	std::vector<size_type> low, order, index;
	std::vector<bool> instack;
	std::stack<size_type> sta;

	void chmin (size_type &a, const size_type &b) noexcept {
		if (a > b) a = b;
	}

	void dfs (size_type v) noexcept {
		low[v] = order[v] = ++num;
		sta.push(v); instack[v] = true;
		for (const size_type &u : g[v]) {
			if (order[u] == 0) {
				dfs(u);
				chmin(low[v], low[u]);
			} else if (instack[u]) {
				chmin(low[v], order[u]);
			}
		}
		if (low[v] == order[v]) {
			scc.push_back(std::vector<size_type>());
			while (true) {
				const size_type u = sta.top();
				sta.pop(); instack[u] = false;
				scc.back().push_back(u);
				if (u == v) break;
			}
		}
	}

public :
	explicit strongly_connected_component (size_type n)
	: g(n), scc(), low(n), order(n), index(n), instack(n, false), num(0) { }

	void add_edge (size_type v, size_type u) noexcept {
		g[v].push_back(u);
	}

	size_type solve () noexcept {
		for (size_type v = 0; v < g.size(); v++) if (not order[v]) dfs(v);
		std::reverse(scc.begin(), scc.end());
		for (size_type i = 0; i < scc.size(); i++) {
			for (const size_type &v : scc[i]) index[v] = i;
		}
		return scc.size();
	}

	const std::vector<std::vector<size_type>> &get () const noexcept {
		return scc;
	}

	size_type size () const noexcept {
		return scc.size();
	}

	const size_type &operator[] (size_type v) const noexcept {
		return index[v];
	}

};

#include <iostream>
#include <cstddef>

using usize = typename strongly_connected_component::size_type;

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(nullptr);
	usize n, m;
	std::cin >> n >> m;
	strongly_connected_component g(n);
	for (usize i = 0; i < m; i++) {
		usize a, b;
		std::cin >> a >> b;
		g.add_edge(a, b);
	}
	
	std::cout << g.solve() << '\n';
	for (const auto &vec : g.get()) {
		std::cout << vec.size();
		for (auto &v : vec) std::cout << ' ' << v;
		std::cout << '\n';
	}
	
	return 0;
}

Measured memory_bytes: 66456
// C
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
// #include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

using namespace std;
typedef long long int ll;
typedef unsigned long long ull;
typedef long double ld;
#define REP(i,n) for(ll i=0; i<(n); i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define ALL(n) begin(n),end(n)
#define IN(a, x, b) (a<=x && x<b)
#define INIT std::ios::sync_with_stdio(false);std::cin.tie(0);
template<class T> inline T CHMAX(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T CHMIN(T & a, const T b) { return a = (a > b) ? b : a; }

const long double EPS = 1e-10;
const long long INF = 1e18;
const long double PI = acos(-1.0L);
const long long MOD = 1000000007;

int main(void){
    string n;
    cin >> n;
    ll mod;
    REP(i, n.size()){
        char dummy[2];
        dummy[0] = n[i];
        dummy[1] = '\0';

        ll tmp = atoi(dummy);
        mod += tmp;
        mod = mod % 9;
    }
    if(mod){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }
    return 0;
}

Measured memory_bytes: 3380
def main
  gets
  bs = gets.chomp.split(' ').map(&:to_i)

  sum = 0
  (bs.length + 1).times do |i|
    pre_b = i == 0 ? Float::INFINITY : bs[i-1]
    current_b = i == bs.length ? Float::INFINITY : bs[i]
    sum += [pre_b, current_b].min
  end
  puts sum
end

main if $0 == __FILE__


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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))

using namespace std;

using i32 = int;
using i64 = long long;
using u64 = unsigned long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vu64 = vector<u64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); return a / gcd(a, b) * b; }
inline u64 xorshift() { static u64 x = 88172645463325252ull; x = x ^ (x << 7); return x = x ^ (x >> 9); }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template <typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template <typename T> inline T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> inline T bis(T ok, T ng, function<bool(T)> f, T eps = 1) { while (abs(ok - ng) > eps) { T mi = (ok + ng) / 2; (f(mi) ? ok : ng) = mi; } return ok; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

void solve() {
  int n;
  cin >> n;
  vi32 h(n);
  cin >> h;
  int prev = 0;
  rep(i, n) {
    if (prev > h[i]) no();
    if (prev == h[i]) prev = h[i];
    else prev = h[i] - 1;
  }
  yes();
}


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

using namespace std;

int n, temp, has = 0, sum = 0;
string ch;
map <string, bool> m;

signed main()
{
    cin>>n;
    for(int i = 1 ; i <= n; i ++){
        cin>>ch;
        if(!m[ch]) {
            m[ch] = 1;
            sum ++;
        }
    }
    cout<<sum;
    return 0;
}

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

int main(){
	int n, m;	cin >> n >> m;
	if(n == 0)	cout << m*(m-1)/2 << endl;
  	else if(m == 0)	cout << n*(n-1)/2 << endl;
  	else if(n == 1 && m > 1)	cout << m*(m-1)/2 << endl;
  	else if(m == 1 && n > 1)	cout << n*(n-1)/2 << endl;
  	else if(n == 1 && m == 1)	cout << 0 << endl;
  	else	cout << n*(n-1)/2 + m*(m-1)/2 << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k, s = 0;
  cin >> n >> k;
  int p[n];
  for (int i = 0; i < n; i++)
    cin >> p[i];
  sort(p, p+n);
  for (int i = 0; i < k; i++)
    s += p[i];
  cout << s;
  return 0;
}


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

int main()
{
	int n;
	cin >> n;
	int cnt = 0;
	for (int i = 1;i <= n;i++) {
      if(((int)log10(i))%2==0){
        cnt++;
      }
	}
	cout << cnt << endl;
	return 0;
}


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

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

Measured memory_bytes: 3644
use proconio::input;

fn main() {
    input! { n: u64, }
    let mut rest = n;
    let mut name: Vec<u8> = Vec::new();
    while rest > 0 {
        rest -= 1;
        name.push((rest % 26 + b'a' as u64) as u8);
        rest /= 26;
    }
    name.reverse();
    println!("{}", String::from_utf8(name).unwrap());
}


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

int main(){
    int a,b,c,d;
    cin >> a >> b >> c >> d ;
    int near,middle,far;

    if(c - a  <= d && c - a  >= 0) cout << "Yes";
    else if(a - c  <= d && a - c  >= 0) cout << "Yes";
    else if (b - a <= d && c - b <= d && b - a >= 0 && c - b >= 0 ) cout << "Yes";
    else if (b - c <= d && a - b <= d && b - c >= 0 && a - b >= 0 ) cout << "Yes";
    else cout << "No";
    
}

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

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

    int N, W;
    cin >> N >> W;

    vector<int> Wn(N);
    vector<int> Vn(N);
    for (int i = 0; i < N; i++) cin >> Wn[i] >> Vn[i];
    vector<vector<long long>> dp(100010, vector<long long>(N + 1, 0));
    for (int i = 0; i < dp.size(); i++) {
        dp[i][0] = 0;
    }
    for (int j = 0; j < N; j++) {
        for (int i = 0; i < dp.size(); i++) {
            if (i + Wn[j] <= W) {
                dp[i + Wn[j]][j + 1] = max(dp[i][j] + Vn[j], dp[i][j + 1]);
            }
            dp[i][j + 1] = max(dp[i][j], dp[i][j + 1]);
        }
    }
    cout << dp[W][N] << endl;
}

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

void srch(int num, vector<vector<int>> books, vector<bool> &buy, int &final_ans, int X, int N, int M){
  int ans = 0;
  for(int i = 0; i < N; i++){
    if(buy.at(i)){
      ans += books.at(i).at(0);
    }
  }/*
  if(buy.at(1) && buy.at(2) && buy.at(3) && buy.at(5) && buy.at(0) && !buy.at(7) && !buy.at(6))
    cout << 'Y' << endl;
    */
  bool a = false;
  for(int i = 0; i < M; i++){
    int ans2 = 0;
    for(int j = 0; j < N; j++){
      if(buy.at(j)){
        ans2 += books.at(j).at(i+1);
      }
    }
    if(ans2 < X){
    /*  if(buy.at(1) && buy.at(2) && buy.at(3) && buy.at(5) && !buy.at(0) && !buy.at(7) && !buy.at(6))
        cout << '!' << i << endl; */
      return;
    }else if(i == M-1){
      a = true;
    }
  }
  
  if(a){
    final_ans = min(final_ans, ans);
  }
  
  if(num < N-1){
    srch(num+1, books, buy, final_ans, X, N, M);
    buy.at(num+1) = false;
    srch(num+1, books, buy, final_ans, X, N, M);
    buy.at(num+1) = true;
  }
}

int main(){
  int N, M, X; cin >> N >> M >> X;
  
  vector<vector<int>> books(N, vector<int>(M + 1));
  for(int i = 0; i < N; i++){
    for(int j = 0; j < M + 1; j++){
      cin >> books.at(i).at(j);
    }
  }
  
  for(int i = 0; i < M; i++){
    int ans = 0;
    for(int j = 0; j < N; j++){
      ans += books.at(j).at(i+1);
    }
    if(ans < X){
      cout << -1 << endl;
      return 0;
    }
  }
  
  vector<bool> buy(N, true);
  int final_ans = 1200000;
  srch(0, books, buy, final_ans, X, N, M);
  buy.at(0) = false;
  srch(0, books, buy, final_ans, X, N, M);
  
  cout << final_ans << endl;
}

Measured memory_bytes: 3628
using System;
using System.Collections.Generic;
using System.Linq;

namespace C
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = Convert.ToInt32(Console.ReadLine());
            List<double> V = Console.ReadLine().Split().Select(i => Convert.ToDouble(i)).ToList();
            // 昇順にソート
            V.Sort();
            while (V.Count != 1)
            {
                double sum = (V[0] + V[1]) / 2.0;
                V.RemoveRange(0, 2);
                V.Add(sum);
                V.Sort();
            }
            Console.WriteLine(V.First());
        }
    }
}


Measured memory_bytes: 11476
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        HashSet<String> PrizeSet = new HashSet<>();
        int num = sc.nextInt();
        for(int i = 0;i < num;i++){
            String Prize = sc.next();
            PrizeSet.add(Prize);
        }
        System.out.println(PrizeSet.size());
    }
}

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

typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
const int INF = int (1e9) + int (1e5);
const ll INFL = ll(2e18) + ll(1e10);
const ui MOD = 1E9 + 7;
const double EPS = 1e-9;
#define FOR(i,n) for (int i=0;i<(n);++i)
#define ROF(i,x) for(int i = (x) ; i >= 0 ; --i)
#define MP make_pair
#define ALL(a) (a).begin(),(a).end()
#define ODD(x) (((x)&1)==0?(0):(1))
#define sign(x) ((x > 0) - (x < 0))
std::mt19937_64  generator(std::chrono::system_clock::now().time_since_epoch().count());

inline ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a, ll b) { return a ? gcd(b%a, a): b; }
ll lcm(ll a, ll b) { return a / gcd(a,b) * b; }


void READ(){
    ios_base::sync_with_stdio(false); cin.tie(0);
#ifdef _DEBUG
    freopen ("in.txt", "r", stdin);
#endif
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
  //  freopen ("in.txt", "r", stdin);
    string s;cin>>s;
    int n=s.size();
    vi cnt(n,0),x(n);
    int last=0;
    for(int i=1;i<n;++i){
        if (s[i]=='L')
            x[i]=last-i;
        else
            last=i;
    }
    last=n-1;
    for(int i=n-2;i>=0;--i){
        if (s[i]=='R')
            x[i]=last-i;
        else
            last=i;
    }
    FOR(i,n){
        if (x[i]%2==0){
            cnt[i+x[i]]++;
        }else if (x[i]>0)
            cnt[i+x[i]-1]++;
        else cnt[i+x[i]+1]++;
    }
    FOR(i,n) cout << cnt[i] << " ";
    return 0;
}



Measured memory_bytes: 1488
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout
	cnt := 0

	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
		cnt = 0
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)
	solve(scanner, writer)
	for i := 0; i < cnt; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}

	writer.Flush()
}

func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner)
	aa := make([]int, n)
	for i := 0; i < n; i++ {
		aa[i] = getNextInt(scanner)
	}
	ee := make([][]edge, n)
	for i := 0; i < n-1; i++ {
		u := getNextInt(scanner) - 1
		v := getNextInt(scanner) - 1
		appendEdge(u, v, i, ee)
		appendEdge(v, u, i, ee)
	}

	yokubalis := make([]int, n)
	for i := 0; i < n; i++ {
		yokubalis[i] = math.MaxInt32
	}

	ans := make([]int, n)
	dfs(0, -1, aa, yokubalis, ans, ee)
	for i := 0; i < n; i++ {
		fmt.Fprintln(writer, ans[i])
	}
}
func dfs(c, p int, aa, yokubalis, ans []int, ee [][]edge) {
	l := -1
	r := len(yokubalis)
	for l+1 < r {
		m := (l + r) >> 1
		if yokubalis[m] >= aa[c] {
			r = m
			continue
		}
		l = m
	}

	old := yokubalis[r]
	yokubalis[r] = aa[c]
	ll := -1
	rr := len(yokubalis)
	for ll+1 < rr {
		mm := (ll + rr) >> 1
		if yokubalis[mm] == math.MaxInt32 {
			rr = mm
			continue
		}
		ll = mm
	}
	ans[c] = rr

	for _, e := range ee[c] {
		if e.to == p {
			continue
		}
		dfs(e.to, c, aa, yokubalis, ans, ee)
	}
	yokubalis[r] = old
}

func appendEdge(from, to, id int, ee [][]edge) {
	ee[from] = append(ee[from], edge{
		to: to,
		id: id,
	})
}

type edge struct {
	to, id int
}


Measured memory_bytes: 89568
# -*- coding: utf-8 -*-
import sys
from collections import deque

S = input()
Q = int(input())
rev_flg = False

output = deque()
output.append(S)

for i in range(Q):
  q = input().split(" ")
  if len(q)==1:
    # T=1のときは文字列を反転する
    rev_flg = not(rev_flg)
    # print(rev_flg)
  if len(q)==3:
    # print("T=2, S=",S)
    # T=2のときは
    # F=1なら先頭に文字列Cを追加
    if int(q[1])==1:
      if rev_flg==False:
        output.appendleft(q[2])
      else:
        output.append(q[2])
    # F=2なら最後に文字列を追加
    if int(q[1])==2:
      if rev_flg==False:
        # S = S + q[2]
        output.append(q[2])
      else:
        # S = q[2] + S
        output.appendleft(q[2])
  
output_s = "".join(list(output))

if rev_flg==True:
  print(output_s[::-1])
  #print(S[::-1])
else:
  #print(S)
  print(output_s)

Measured memory_bytes: 6900
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		@SuppressWarnings("resource")
		Scanner scan = new Scanner(System.in);

		int N = scan.nextInt();
		
		int a[][] = new int [N][2];
		
		for(int i = 0 ;i < N;i++){
			a[i][0] = scan.nextInt();
			a[i][1] = scan.nextInt();
		}
		
		int ans = 0;
		
		for(int i = 0 ;i < N; i++){
			ans += a[i][1] - a[i][0];
			ans++;
		}
		
		System.out.println(ans);
	}
}

Measured memory_bytes: 25840