akhauriyash/Code-Regression huggingface dataset:
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(v) reverse((v).begin(),(v).end())
#define ANS(ans) cout<<(ans)<<endl;
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
typedef vector<int> VI;

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


int main() {
	int n;
	cin >> n;
	VI v(n);
	int sum = 0;
	REP(i, n) {
		cin >> v[i];
		sum += v[i];
	}

	double ave = sum*1.0 / n;

	vector<double> diff(n);

	REP(i, n) {
		diff[i] = abs(v[i] - ave);
	}

	auto minIt = min_element(diff.begin(), diff.end());
	int min_index = distance(diff.begin(), minIt);
	ANS(min_index);


	return 0;
}



Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<vector>
using namespace std;
#define rep2(x,from,to) for(int x=from;x<to;x++)
#define rep(x,to) rep2(x,0,to)
int a[200005];
int p;
int b[200005];
int q;
int qq;
int main()
{
  int n;
  cin>>n;
  rep(i,n)
    {
      cin>>a[i];
      if(p<a[i])p=a[i];
    }
    if(p!=a[0])
    {
  q=a[0];
  qq=abs(p-2*a[0]);}
  else
  {
    q=a[1];
  qq=abs(p-2*a[1]);}
  rep(i,n)
    {
      if(abs(p-2*a[i])<qq&&a[i]!=p)
	{
	  q=a[i];
	  qq=abs(p-2*a[i]);
	}
    }
  cout<<p<<" "<<q<<endl;
    return 0;
}


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

int main(){
    int h, w;
    std::cin >> h >> w;
    std::vector<int> a(h*w);
    for(int i = 0; i < h*w; i++){
        std::cin >> a[i];
    }
    
    std::vector<int> log;
    for(int i = 0; i < h*w; i++){
        if(i%w < w - 1 && a[i]%2 == 1){
            a[i]--;
            a[i + 1]++;
            log.push_back(i);
            log.push_back(i + 1);
        }
    }
    
    for(int i = w - 1; i < (h - 1)*w; i += w){
        if(a[i]%2 == 1){
            a[i]--;
            a[i + w]++;
            log.push_back(i);
            log.push_back(i + w);
        }
    }
    
    std::cout << log.size()/2 << std::endl;
    for(int i = 0; i < log.size(); i += 2){
        std::cout << log[i]/w + 1 << " " << log[i]%w + 1 << " " << log[i + 1]/w + 1 << " " << log[i + 1]%w + 1 << std::endl; 
    }
    
    return 0;
}


Measured memory_bytes: 4212
n,y = map(int,input().split())
flag = "ng"
for i in range(0,n+1):
    for j in range(0,n+1-i):
        if 10000*i + 5000*j + 1000*(n-i-j) == y:
            print(i,j,n-i-j)
            flag = "ok"
            exit()
if flag == "ng":
    print(-1,-1,-1)

Measured memory_bytes: 40684
#include <stdio.h>

int parent(int i)
{
    return (int)(i / 2);
}

int left(int i)
{
    return 2 * i;
}

int right(int i)
{
    return 2 * i + 1;
}

void output(int *H, int n)
{
    for (int i = 1; i <= n; i++)
    {
        printf("node %d: key = %d, ", i, H[i]);
        if (parent(i) >= 1)
        {
            printf("parent key = %d, ", H[parent(i)]);
        }
        if (left(i) <= n)
        {
            printf("left key = %d, ", H[left(i)]);
        }
        if (right(i) <= n)
        {
            printf("right key = %d, ", H[right(i)]);
        }
        printf("\n");
    }
}

int main(void)
{
    int H[251];
    int n;
    int key;

    scanf("%d", &n);
    for (int i = 1; i <= n; i++)
    {
        scanf("%d", &key);
        H[i] = key;
    }

    output(H, n);

    return 0;
}


Measured memory_bytes: 2056
#include<iostream>
#include<queue>
#include<cassert>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;

int main(){
    int n;
    cin >> n;
    priority_queue<pair<int,int>> pq;
    for(int i = 0; i < n; i++){
        int x;  cin >> x;
        pq.push({-x, 1});
    }
    for(int i = 0; i < n; i++){
        int x;  cin >> x;
        pq.push({-x, -1});
    }
    ll ans = 1, balance = 0;
    while(!pq.empty()){
        pair<int,int> p = pq.top(); pq.pop();
        int i = p.second;
        if(i*(balance) < 0){
            ans *= abs(balance);
            ans %= mod;
        }
        balance += i;
    }
    assert(balance==0);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2420
function main()
  N,M,K=map(x->parse(Int,x),split(readline()))
  A=map(x->parse(Int,x),split(readline()))
  B=map(x->parse(Int,x),split(readline()))
  S=sum(A)
  ans=0
  j=0
  for i=N:-1:0
    while j<M&&S+B[j+1]<=K
      j+=1
      S+=B[j]
    end
    if S<=K
      ans=max(ans,i+j)
    end
    if i>0
      S-=A[i]
    end
  end
  println(ans)
end
main()

Measured memory_bytes: 203220
M=10**9+7;F=lambda X:pow(X,M-2,M);H,W,A,B=map(int,input().split());Z=C=1
for I in range(H-1):Z=C=C*(W+H-B-2-I)*F(I+1)%M
for I in range(1,H-A):C=C*(B-1+I)*(H-I)%M*F(I*(W+H-B-1-I))%M;Z=(Z+C)%M
print(Z)

Measured memory_bytes: 3188
#include <iostream>
#include <stack>
using namespace std;
typedef long long ll;
typedef pair<int, ll> P;
typedef pair<ll, P> Q;

int r[10];
int main(void){
    // Your code here!
    ll pro;
    //文字列に代入
    scanf("%lld", &pro);
    ll pri = pro;
    int i = 0;
    while (pro > 0) {
        r[i++] = pro % 10;
        pro = pro / 10;
    }
    //桁数を調べる
    int k = 0;
    while (pri > 0) {
        pri = pri / 10;
        k++;
    }
    ll ans = 0;
    stack<Q> s;
    s.push(Q(0, P(k - 1, r[k - 1])));
    while (s.size()) {
        Q q = s.top(); s.pop();
        if (q.second.first == 0) {
            ans += q.second.second;
            ans += q.first;
        } else {
            q.second.first--;
            int w =q.first + q.second.second;
            s.push(Q(w, P(q.second.first, r[q.second.first])));
            q.second.second = q.second.second * 10 + r[q.second.first];
            s.push(q);
        }
    }
    printf("%lld", ans);
}

Measured memory_bytes: 256
n = int(input())
L = []
ans = 0
for _ in range(n):
    a, b = map(int, input().split())
    L.append([a, b, a + b])
L.sort(key=lambda x: x[2], reverse=True)
for i in range(0, n, 2):
    ans += L[i][0]
for i in range(1, n, 2):
    ans -= L[i][1]
print(ans)


Measured memory_bytes: 24416
N, M = [int(i) for i in input().split()]
data = list()
for i in range(M):
    p, y = [int(i) for i in input().split()]
    data.append([i, p, y])
data.sort(key=lambda x:(x[1],x[2]))
ind = 1
for j, (i, p, y) in enumerate(data):
    if data[j-1][1] != p:
        ind = 1
    data[j].append(ind)
    ind += 1
data.sort(key=lambda x:x[0])
for i, p, y, j in data:
    print(str(p).zfill(6) + str(j).zfill(6))

Measured memory_bytes: 35580
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cstring>
#include <cmath>
#include <ctime>
#include <algorithm>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <stack>
#include <bitset>
using namespace std;
typedef long long LL;
LL gi () {
    LL ret=0; char ch=getchar();
    while((ch<'0' || ch>'9') && ch!='-') ch=getchar();
    char c=ch=='-'?getchar():ch;
    while(c>='0' && c<='9') ret=ret*10+c-'0',c=getchar();
    return ch=='-'?-ret:ret;
}
int D;
LL s[20],mi10[20];
LL dfs (int x, int mxd, LL D) {
    if(s[x] < abs(D)) return 0;
    if(x > (mxd-1)/2) return (mxd&1) ? 1 : 10;
    LL ret = 0;
    for(int i=-9;i<=9;i+=1) {
        ret += (10-abs(i)-(int)(x==0 && i>=0)) * dfs(x+1,mxd,D-i*(mi10[mxd-x]-mi10[x]));
    }
    return ret;
}
int main () {
    D = gi(); LL ans = 0;
    mi10[0] = 1;
    for(int i=1;i<=18;i+=1) mi10[i] = mi10[i-1] * 10;
    for(int i=1;i<=18;i+=1) {
        for(int j=0;j<=(i-1)/2;j+=1) {
            s[j] = 9 * (mi10[i-j] - mi10[j]);
        }
        for(int j=(i-1)/2-1;j>=0;j-=1) {
            s[j] += s[j+1];
        }
        ans += dfs(0,i,D);
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 256
INF = 10**13
N = int(input())
A = sorted(list(map(int, input().split())))
B = sorted(list(map(int, input().split())))
C = sorted(list(map(int, input().split())))
cusumB = [0 for i in range(N+1)]
C += [INF]
left = 0
for i, bi in enumerate(B):
    while C[left]<=bi:
        left += 1
    cusumB[i] = N - left
for i in range(N, 0, -1):
    cusumB[i-1] += cusumB[i]
B += [INF]
left = 0
ans = 0
for i, ai in enumerate(A):
    while B[left]<=ai:
        left += 1
    ans += cusumB[left]
print(ans)

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

using namespace std;
#define _USE_MATH_DEFINES_
#define ll long long
#define ld long double
#define Accepted 0
#define pb push_back
#define mp make_pair
#define sz(x) (int)(x.size())
#define every(x) x.begin(),x.end()
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define For(i,x,y)  for (ll i = x; i <= y; i ++) 
#define FOr(i,x,y)  for (ll i = x; i >= y; i --)
#define SpeedForce ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
// ROAD to...                                                                                                                                                                                                                Red

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

const double eps = 0.000001;
const ld pi = acos(-1);
const int maxn = 1e7 + 9;
const int mod = 1e9 + 7;
const ll MOD = 1e18 + 9;
const ll INF = 1e18 + 123;
const int inf = 2e9 + 11;
const int mxn = 1e6 + 9;
const int N = 6e5 + 123;                                          
const int M = 22;
const int pri = 997;
const int Magic = 2101;

const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
 
int n, m, n1, m1;
/*int a[N];
int sum[55][55];
const int LIM = 2;

int sub (int lx, int ly, int rx, int ry) {
	int res = sum[rx][ry];
	if (lx >= 0) res -= sum[lx][ry];
	if (ly >= 0) res -= sum[rx][ly];
	if (lx >= 0 && ly >= 0) res += sum[lx][ly];
	return res;
}

void gen (int p = 0) {
	if (p == n * m) {         
		int ptr = 0;
		for (int i = 0; i < n; i ++) {
			for (int j = 0; j < m; j ++) {
				int &res = sum[i][j];
				res = 0;
				if (i > 0) res += sum[i-1][j];
				if (j > 0) res += sum[i][j-1];
				if (i > 0 && j > 0) res -= sum[i-1][j-1];
				res += a[ptr ++];
			}
		}

		ptr = 0;
		for (int i = n1 - 1; i < n; i ++) {
			for (int j = m1 - 1; j < m; j ++) if (sub(i - n1, j - m1, i, j) >= 0) {
				return;
			}
		}
		if (sum[n-1][m-1] <= 0) return;

		cout << "varient\n";
		for (int i = 0; i < n; ++i) {
			for (int j = 0; j < m; ++j) {
				cout << a[ptr++] << ' ';
			}
			cout << '\n';
		}
		exit(0);

		return;
	}
	for (int i = -LIM; i <= LIM; ++i) {
		a[p] = i;
		gen(p+1);
	} 	
}
*/
int main () {
	SpeedForce;
	cin >> n >> m >> n1 >> m1;
//	gen();
	if (n % n1) {
		cout << "Yes\n";
		for (int i = 0; i < n; i ++) {
			for (int j = 0; j < m; ++j) {
				if (i % n1 == 0) cout << 1000 * (n1 - 1) - 1 << ' ';
				if (i % n1) cout << "-1000 "; 
			}
			cout << endl;
		}
		exit(0);
	}
	if (m % m1) {
		cout << "Yes\n";
		for (int i = 0; i < n; i ++) {
			for (int j = 0; j < m; ++j) {
				if (j % m1 == 0) cout << 1000 * (m1 - 1) - 1 << ' ';
				else cout << "-1000 "; 
			}
			cout << endl;
		}
		exit(0);
	}

	cout << "No\n";

   	return Accepted;
}

// B...a

Measured memory_bytes: 1792
#include<iostream>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <math.h>
#include <unordered_map>
#include <numeric>
#include <sstream>
using namespace std;

int main()
{
	std::vector<int> v(3);
	string str = "";

	for(int i=0; i<3; i++) cin >> v[i];

	sort(v.begin(), v.end());
	reverse(v.begin(), v.end());

	for (int i = 0; i < 2; i++) {
		str += to_string(v[i]);
	}

	std::cout << atoi(str.c_str()) + v[2] << '\n';

	return 0;
}


Measured memory_bytes: 256
x = int(input())
p = sorted(list(map(int,input().split())))
d = [True]*(p[-1]+1)
e = [False]*(p[-1]+1)
for i in p:
    if e[i]:
        d[i] = False
        continue
    else:
        e[i] = True
    idx = 2*i
    while idx < len(d):
        d[idx] = False
        idx += i

cnt = 0
for i in p:
    cnt += int(d[i])    
print(cnt)

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

const int mod = 1e9 + 7;

signed main() {
	int n, k;
	cin >> n >> k;
	vector<int> a(n);
	for (int i = 0; i < n; ++i)cin >> a[i];
	vector<int> incnt(n, 0);
	vector<int> outcnt(n, 0);
	for (int i = 0; i < n; ++i) {
		for (int j = i + 1; j < n; ++j) {
			if (a[i] > a[j])++incnt[i];
		}
	}
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < n; ++j) {
			if (a[i] > a[j])++outcnt[i];
		}
	}
	int ans = 0;
	for (int i = 0; i < n; ++i) {
		ans += outcnt[i];
		ans %= mod;
	}
	ans *= (k * (k - 1) / 2) % mod;
	ans %= mod;
	for (int i = 0; i < n; ++i) {
		ans += k * incnt[i];
		ans %= mod;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
import itertools

n = int(input())
F_s = [list(map(int, input().split())) for _ in range(n)]
P_s = [list(map(int, input().split())) for _ in range(n)]

ans = -10 ** 10
flg = True
for lst in itertools.product(range(2), repeat = 10):
    if flg:
        flg = False
        continue
    ans_sub = 0
    for i in range(n):
        cnt = sum(j * k for j, k in zip(lst, F_s[i]))
        ans_sub += P_s[i][cnt]
    ans = max(ans, ans_sub)
print(ans)

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

typedef long long ll;
typedef pair <int, int> ii;
typedef pair <int, ii> iii;
typedef pair<ll, ll> pll;
typedef pair<double, int> pdi;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
#ifdef VC
#define scanf scanf_s
#endif
#define iINF (1<<30)
#define INF (1LL<<59)
#define forn(i) for(int i = 0;i < n; ++i)
#define form(i,n) for(int i = 0 ;i < n; ++i)
#define NIL -1

const ll mod = 998244353;
int n;
int alp[30] = {};
string S;
ll used = 0LL;
int ans = 0;

int main(){
	int a, b, c;
	cin >> a >> b >> c;
	ans = iINF;
	ans = min(ans, abs(a - b) + abs(a - c));
	ans = min(ans, abs(a - b) + abs(b - c));
	ans = min(ans, abs(c - b) + abs(a - c));
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
unittest
{
	assert( [ "5 3", "-30 -10 10 20 50" ].solve == 40 );
	assert( [ "3 2", "10 20 30" ].solve == 20 );
	assert( [ "1 1", "0" ].solve == 0 );
	assert( [ "8 5", "-9 -7 -4 -3 1 2 3 4" ].solve == 10 );
}



import std.algorithm;
import std.conv;
import std.math;
import std.format;
import std.range;
import std.stdio;

void main()
{
	stdin.byLineCopy.solve.writeln;
}

auto solve( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto n = 0L;
	auto k = 0L;
	input.front.formattedRead!"%s %s"( n, k );
	input.popFront;
	auto xs = input.front.split.to!( long[] );
	
	auto ans = long.max;
	for( auto l = 0L, r = k - 1; r < xs.length; l++, r++ )
	{
		ans = min( ans, xs[ r ] - xs[ l ] + min( abs( xs[ l ] ), abs( xs[ r ] ) ) );
	}
	return ans;
}


Measured memory_bytes: 7144
#include<bits/stdc++.h>
using namespace std;
int main()
{
	unsigned long long a,b,c;
	cin>>a>>b>>c;
	if(a>b&&b<=c) cout<<-1<<endl;
	else if(a<=b) cout<<1<<endl; 
	else cout<<(((a-b)/(b-c)+bool((a-b)%(b-c)))<<1|1)<<endl;
}

Measured memory_bytes: 256
N, M = map(int, input().split())

lst = [list(map(int, input().split())) for _ in range(M)]
lst.sort(key=lambda x: x[0])

n = 10 ** N


for i in range(n):
    moji = str(i)
    k = len(moji)

    if k != N:
        continue

    flag = True

    for s, c in lst:
        if s > k or moji[s - 1] != str(c):
            flag = False
            break

    if flag:
        print(str(i))
        exit()

print('-1')


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

public class Main {
	public static void main(String args[]) {
		try (Scanner in = new Scanner(System.in)) {
			int A = in.nextInt();
			int B = in.nextInt();
			int C = in.nextInt();

			int[] a = new int[] { A, B, C, };
			Arrays.sort(a);

			if (a[0] == 5 && a[1] == 5 && a[2] == 7) {
				System.out.println("YES");
			} else {
				System.out.println("NO");
			}
		}
	}
}


Measured memory_bytes: 22740
#include<cstdio>
int main(){
    int a,b,k;
    scanf("%d%d%d",&a,&b,&k);
    if(b-a+1<2*k){
        for(int i=a;i<=b;i++)printf("%d\n",i);
    }else{
        for(int i=a;i<a+k;i++)printf("%d\n",i);
        for(int i=b-k+1;i<=b;i++)printf("%d\n",i);
    }
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll MOD = 1e9 + 7;
const ll INF = LLONG_MAX;

int main()
{
    int n;
    cin >> n;
    long double jp = 0;
    long double bt = 0;
    for (int i = 0; i < n; i++)
    {
        long double x;
        string u;
        cin >> x >> u;
        if (u == "JPY")
            jp += (ll)x;
        if (u == "BTC")
            bt += x;
    }
    jp += bt * 380000.0;
    cout << setprecision(20) << jp << endl;
}

Measured memory_bytes: 256
s = input()
if s == 0:
	print "0"
	exit()
else:
	m = s
	ans = ''
	while m != 0:
		kk = m%(-2)
		m = m//(-2)
		if kk < 0:
			kk += 2
			m += 1
		ans += str(kk)
	print ans[::-1]


Measured memory_bytes: 2568
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define pf push_front

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
double pi = 3.141592653589793;
ll mod = 1000000007;
ll INF = 1000000001;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;



int main(){
    int n;
    ll lmin, tmp;
    cin >> n;
    vl a(n);
    rep(i, n){
        cin >> a[i];
        if(i>0){
            a[i] += a[i-1];
        }
    }    
    lmin = a[n-1];
    rep(i, n-1){
        tmp = a[n-1]- 2 * a[i];
        // cout << tmp << endl;
        tmp = max(tmp, -tmp);
        lmin = min(lmin, tmp);
    }
    cout << lmin << endl;
}


Measured memory_bytes: 1920
#include<cstdio>
int main(){
    char s[3][101];
    int p[3]={0,0,0},n=0,m;
    for(int i=0;i<3;i++)scanf("%s",s[i]);
    while(true){
        if(s[n][p[n]]=='\0'){
            printf("%c",'A'+n);
            return 0;
        }else{
            m=n;
            n=s[n][p[n]]-'a';
            p[m]++;
        }
    }
}

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

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

int main(void) {
    string s;
    cin >> s;
    int n = s.size();
    int red = 0, blue = 0;
    rep(i, n) {
        if(s[i] == '1'){
            red++;
        }else
            blue++;
    }
    cout << 2 * min(red, blue) << endl;
    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int h,w,n,a[10004],ans[105][105];
int main(){
	cin>>h>>w>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	int count=-1;
	for(int i=1;i<=n;i++){
		
			for(int j=0;j<a[i];j++){
				count++;
				if((count/w)%2==0){
				ans[(count/w)][(count%w)]=i;
				}else{ans[(count/w)][w-(count%w)-1]=i;}
				
				
			}
		
			
		
	}
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++)cout<<ans[i][j]<<" ";
		cout<<endl;
	}
}


Measured memory_bytes: 384
#include <stdio.h>
#include <string.h>

int main(void) {
	char p[101], s[101];
	int i, c;
	
	scanf("%s%s", p, s);
	
	for(i = 0; strlen(p) > i; i++){
		int f = 0;
		for(c = 0; strlen(s) > c; c++){
			if(p[(i+c)%strlen(p)] != s[c]){
				f = 1;
				break;
			}
		}
		if(f == 0){
			printf("Yes\n");
			return 0;
		}
	}
	printf("No\n");
	return 0;
}

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

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

using namespace std;

long long INF = 1LL << 60;

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

	long long ans = INF;
	rep(i, sqrt(N)) {
		if (N % ((long long)i + 1) == 0) {
			long long x = N / ((long long)i + 1);
			if (ans > (long long)x + i + 1) {
				ans = (long long)x + i + 1;
			}
		}
	}
	cout << ans - 2;
}



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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

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

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

int main(){
	ll n;cin>>n;
	string s;cin>>s;
	ll cnt=0,sum1[n+1],sum2[n+1],sum3[n+1];
    sum1[0]=0;sum2[0]=0;sum3[0]=0;
	rep(i,n){
		if(s[i]=='R'){
			sum1[i+1]=sum1[i]+1;
			sum2[i+1]=sum2[i];
			sum3[i+1]=sum3[i];
		}
		if(s[i]=='G'){
			sum1[i+1]=sum1[i];
			sum2[i+1]=sum2[i]+1;
			sum3[i+1]=sum3[i];
		}
		if(s[i]=='B'){
			sum1[i+1]=sum1[i];
			sum2[i+1]=sum2[i];
			sum3[i+1]=sum3[i]+1;
		}
	}
	for(int i=0;i<n-1;++i){
		for(int j=i+1;j<n;++j){
			if(s[i]!=s[j]){
				if((2*(j+1)-(i+1))<=n){
					if(s[2*(j+1)-(i+1)-1]!=s[i]&&s[2*(j+1)-(i+1)-1]!=s[j]){
						if(s[i]!='R'&&s[j]!='R')cnt+=sum1[n]-sum1[j]-1;
						if(s[i]!='G'&&s[j]!='G')cnt+=sum2[n]-sum2[j]-1;
						if(s[i]!='B'&&s[j]!='B')cnt+=sum3[n]-sum3[j]-1;
					}
					else{
						if(s[i]!='R'&&s[j]!='R')cnt+=sum1[n]-sum1[j];
						if(s[i]!='G'&&s[j]!='G')cnt+=sum2[n]-sum2[j];
						if(s[i]!='B'&&s[j]!='B')cnt+=sum3[n]-sum3[j];
					}
				}
                else{
					if(s[i]!='R'&&s[j]!='R')cnt+=sum1[n]-sum1[j];
					if(s[i]!='G'&&s[j]!='G')cnt+=sum2[n]-sum2[j];
					if(s[i]!='B'&&s[j]!='B')cnt+=sum3[n]-sum3[j];
				}
			}
		}
	}
	cout<<cnt<<endl;
}


Measured memory_bytes: 3704
n,k = map(int, input().split())
a = list(map(int, input().split()))

now=0
cnt=0
from collections import defaultdict
d = defaultdict(lambda: -1)

d[0]=0

while True:
    cnt+=1
    nxt=a[now]-1
    now=nxt
    if k==cnt:
        print(nxt+1)
        exit()
    if d[nxt]!=-1:
        break
    d[nxt]=cnt

k-=d[nxt]
k%=(cnt-d[nxt])

cnt=0
while cnt<k:
    cnt+=1
    nxt=a[now]-1
    now=nxt

print(now+1)

Measured memory_bytes: 103688
# -*- coding: utf-8 -*-
s = [int(x) for x in input()]
l1 = [i % 2 for i in range(len(s))]
l2 = [1] + l1[:len(l1) - 1]
d1 = len([x for i, x in enumerate(s) if s[i] != l1[i]])
d2 = len([x for i, x in enumerate(s) if s[i] != l2[i]])
print(d1 if d1 < d2 else d2)

Measured memory_bytes: 6300
#include<cstdio>

int n,a,l;
long long cnt;

int main()
{
	scanf("%d",&n);
	while(n--)
	{
		scanf("%d",&a);
		if(a && l) cnt++,a--;
		l=0;
		cnt+=a/2;
		if(a%2) l=1;
	}
	printf("%lld\n",cnt);
	return 0;
}

Measured memory_bytes: 128
//木の直径

#include<iostream>
#include<queue>
#include<vector>
using namespace std;
const int MAX=100000;
const int INF=(1<<30);

class Edge{

public:
  int t,w;
  Edge(){}
  Edge(int a,int b):t(a),w(b){}
};

vector<Edge>G[MAX];//辺情報（つながってる節点,距離）
int n,d[MAX];//


void bfs(int s){
  for(int i=0;i<n;i++){
    d[i]=INF;
  }
  queue<int >que;
  que.push(s);
  d[s]=0;
  int u;
  while(!que.empty()){
    u=que.front();
    que.pop();
    for(int i=0;i<G[u].size();i++){
      Edge e=G[u][i];
      if(d[e.t]==INF){
	d[e.t]=d[u]+e.w;//uからtに行くには、wかかる
	que.push(e.t);
      }
    }
  }
}

void slove(){
  //適当な始点sから最も遠い節点tgt
  bfs(0);
  int maxv=0;
  int tgt=0;
  for(int i=0;i<n;i++){
    if(d[i]==INF) continue;
    if(maxv<d[i]){
      maxv=d[i];
      tgt=i;
    }
  }   
  //tgtから最も遠い節点の距離maxv

  bfs(tgt);
  maxv=0;
  for(int i=0;i<n;i++){
    if(d[i]==INF) continue;
    maxv=max(maxv,d[i]);
  }

  cout<<maxv<<endl;
}
    

int main(){
  int s,t,w;
  cin>>n;
  for(int i=0;i<n-1;i++){
    cin>>s>>t>>w;

    G[s].push_back(Edge(t,w));//sからt(重さw)
    G[t].push_back(Edge(s,w));//tからs(重さw)
  }

  slove();
  
  
  return 0;
} 



Measured memory_bytes: 9896
N, K = map(int, input().split())
A = sorted(list(map(int, input().split())))
P = int(1e9+7)
ans = 0

kaizyo = [0]
kaizyo_inv = [0]
tmp = 1
for i in range(1, N+1):
    tmp = (tmp*i) % P
    kaizyo.append(tmp)
    kaizyo_inv.append(pow(tmp, P - 2, P))


def comb(n, r):
    if n < r or n == 0:
        return 0
    elif n == r or r == 0:
        return 1
    else:
        return kaizyo[n] * kaizyo_inv[r] * kaizyo_inv[n - r]


combs=[comb(i, K - 1)%P for i in range(N+1)]

for i, a in enumerate(A):
    ans = (ans + a * combs[i]) % P
    ans = (ans - a * combs[N - i - 1]) % P

print(ans)


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

int main(){
    int n,k,d;
    int temp;
    bool a[101];
    cin>>n>>k;
    int cnt=0;
    for(int i=0;i<=100;i++){
        a[i]=false;
    }
    for(int i=1;i<=k;i++){
        cin>>d;
        for(int j=1;j<=d;j++){
            cin>>temp;
            a[temp]=true;
        }
    }
    for(int i=1;i<=n;i++){
        if(a[i]==false){
            cnt++;
        }
    }
    cout<<cnt<<endl;
    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(I,A,B) for(int I = (A); I < int(B); ++I)

int main(){
    ll N,M,L,INF=999999999999LL,s,t,l,Q;
    cin >> N >> M >> L;
    ll d[N+1][N+1];
    ll h[N+1][N+1];
    FOR(i,0,N+1)FOR(j,0,N+1)d[i][j]=h[i][j]=INF;
    FOR(i,0,M){
        cin >> s >> t >> l;
        d[s][t]=d[t][s]=l;
    }
    FOR(k,0,N+1){
        FOR(i,0,N+1){
            FOR(j,0,N+1){
                d[i][j] = min(d[i][j],d[i][k]+d[k][j]);
            }
        }
    }
    FOR(i,1,N+1){
        FOR(j,1,N+1){
            if(d[i][j]<=L){
                h[i][j] = 1;
            }
        }
    }
    FOR(k,0,N+1){
        FOR(i,0,N+1){
            FOR(j,0,N+1){
                h[i][j] = min(h[i][j],h[i][k]+h[k][j]);
            }
        }
    }
    cin >> Q;
    FOR(q,0,Q){
        cin >> s >> t;
        if(h[s][t]==INF){
            cout << -1 << endl;
            continue;
        }
        if(d[s][t]<=L){
            cout << 0 << endl;
        }else{
            cout << h[s][t]-1 << endl;
        }
    }
}

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

int main(){
  int w, h, x, y; cin >> w >> h >> x >> y;
  printf("%.10lf ", (double)w*h/2 );
  if (2*x == w && 2*y == h) cout << 1 << endl;
  else cout << 0 << endl;
}

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

int nOfDigits(int n) {
    int cnt = 0;
    while (n/10 !=0) {
        n /= 10;
        cnt++;
    }
    return cnt+1;
}

int main() {
    int n; cin >> n;
    int oddCnt = 0;
    for (int i = 1; i <= n; i++)
    {
        int ndigit = nOfDigits(i);
        if (ndigit%2 == 1) oddCnt++;
    }
    cout << oddCnt << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.*;

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

        var X = scanner.nextInt();
        var N = scanner.nextInt();

        var ps = new TreeSet<Integer>();
        for(int i=0; i<N; i++)
            ps.add(scanner.nextInt());

        if(!ps.contains(X)) {
            System.out.println(X); return;
        }

        var ans = X;
        for(int i=1; ; i++) {
            ans = X-i;
            if(!ps.contains(ans))
                break;
            ans = X+i;
            if(!ps.contains(ans))
                break;
        }

        System.out.println(ans);
    }
}

Measured memory_bytes: 35824
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int m = sc.nextInt();
    int[] p = new int[m];
    int[] y = new int[m];
    HashMap<Integer, Integer> city = new HashMap<Integer, Integer>();
    HashMap<Integer, Integer> junni = new HashMap<Integer, Integer>();
    int[] a = new int[n + 1];
    for(int i = 1; i < n + 1; i++) {
      a[i] = 1;
    }
    int[] ye = new int[m];
    for(int i = 0; i < m; i++) {
      p[i] = sc.nextInt(); 
      y[i] = sc.nextInt();
      ye[i] = y[i];
      city.put(y[i], p[i]);
    }
    Arrays.sort(ye);
    for(int i = 0; i < m; i++) {
      int c = city.get(ye[i]);
      junni.put(ye[i], a[c]);
      a[c]++;
    }
    for(int i = 0; i < m; i++) {
      int jun = junni.get(y[i]);
      String P = String.valueOf(p[i]);
      String Y = String.valueOf(jun);
      String ansp = "";
      String ansy = "";
      for(int j = 0; j < 6 - P.length(); j++) {
        ansp += "0";
      }
      ansp += P;
      for(int j = 0; j < 6 - Y.length(); j++) {
        ansy += "0";
      }
      ansy += Y;
      System.out.println(ansp + ansy);
    }
  }
}

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

int main(){
  int N,max,sum,i;
  sum = 0;
  cin >> N;
  int p[N];
  for(i = 1; i <= N; i++){
    cin >> p[i];
  }
  max = p[1];
  for(i = 1; i <= N ;i++){
    sum += p[i]; 
    if(p[i]>max){
      max = p[i];
    }
  }
  cout << max/2 + sum - max <<endl;
}

Measured memory_bytes: 256
using System;
using static System.Console;
using static System.Math;
 
public class Hello{
    public static void Main(){
        int[] read = inta();
        int a = read[0];
        int b = read[1];
        if(a<10){
            WriteLine(b + (100 * (10 - a)) );
        }else{
            WriteLine(b);
        }
    
    
    
    
    
    
    }
    //各種読取
    static string rstr(){
        return ReadLine();
    }
    static int rint(){
        return int.Parse(ReadLine());
    }
    static long rlong(){
        return long.Parse(ReadLine());
    }
    static string[] stra(){
        return ReadLine().Split(' ');
    }
    static int[] inta(){
        string[] read_str_array = ReadLine().Split(' ');
        int[] return_int_array = new int[read_str_array.Length];
        for(int countup_i=0;countup_i<read_str_array.Length;countup_i++){
            return_int_array[countup_i] = int.Parse(read_str_array[countup_i]);
        }
        return return_int_array;
    }
    static int[,] inta2(int num_array,int in_array){
        int[,] int_array2 = new int[num_array,in_array];
        for(int i=0;i<num_array;i++){
            int[] temp_array = inta();
            for(int j=0;j<in_array;j++){
                int_array2[i,j] = temp_array[j];
            }
        }
        return int_array2;
    }
    // A/B小数点以下切上
    static int divideup(int divided,int divid){
        int temp_divide = divided/divid;
        if(divided % divid > 0){
            temp_divide++;
        }
        return temp_divide;
    }
}


Measured memory_bytes: 11092
#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;
}

struct Point{
    ll x, y;
    Point(ll _x, ll _y){
        x = _x;
        y = _y;
    }
};

ll dist(Point a, Point b){
    ll ans = abs(a.x - b.x) + abs(a.y - b.y);
    return ans;
}

ll L[1050];
ll R[1050];

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

    // input
    ll H, W;
    cin >> H >> W;

    FOR(i, 0, 1050){
        L[i] = -1;
        R[i] = -1;
    }

    FOR(i, 0, H){
        string s; cin >> s;
        FOR(j, 0, W){
            if(s[j]=='B'){
                L[i] = j; break;
            }
        }
        for(int j=W-1; j>=0; j--){
            if(s[j]=='B'){
                R[i] = j; break;
            }
        }
    }

    // pn(L[0]);
    // pn(L[1]);
    // pn(L[2]);
    // pn(L[3]);

    ll ma = 0;
    FOR(h, 0, H){
        FOR(u, 0, H){
            if(L[h]==-1) continue;
            if(L[u]==-1) continue;
            ll d0 = abs(h-u) + abs(L[h]-L[u]); chmax(ma, d0);
            ll d1 = abs(h-u) + abs(L[h]-R[u]); chmax(ma, d1);
            ll d2 = abs(h-u) + abs(R[h]-L[u]); chmax(ma, d2);
            ll d3 = abs(h-u) + abs(R[h]-R[u]); chmax(ma, d3);
        }
    }
    p(ma);
    return 0;
}


Measured memory_bytes: 3280
#include<bits/stdc++.h>
using namespace std;
#define Sheryang main
const int maxn=1e6+7;
typedef long long ll;
const int mod=998244353;
#define IO cin.tie(0),ios::sync_with_stdio(false);
#define pi acos(-1)
#define PII pair<ll,ll>
ll read(){ll c = getchar(),Nig = 1,x = 0;while(!isdigit(c) && c!='-')c = getchar();if(c == '-')Nig = -1,c = getchar();while(isdigit(c))x = ((x<<1) + (x<<3)) + (c^'0'),c = getchar();return Nig*x;}
#define read read()
/** keep hungry and keep calm! **/

int s[]={0,2,5,5,4,5,6,3,7,6},a[maxn],ans[maxn],n,m,dp[maxn];
int cmp(int a,int b){
    if(s[a]!=s[b]) return s[a]<s[b];
    return a>b;
}

int cmp1(int a,int b){
    return a>b;
}

int Sheryang(){

    n=read,m=read;
    for(int i=0;i<m;i++){
        a[i]=read;
    }
    memset(dp,-1,sizeof(dp));
    dp[0]=1;

    int vis[10]={0};
    for(int i=0;i<m;i++){
        vis[a[i]]++;
        for(int j=s[a[i]];j<=n;j++){
            dp[j]=max(dp[j],dp[j-s[a[i]]]+1);
        }
    }

    while(n){
        for(int i=9;i;i--){
            if(vis[i] && n>=s[i] && dp[n-s[i]]+1==dp[n]){
                putchar(i+'0');
                n=n-s[i];break;
            }
        }
    }

    puts("");
    return 0;
}


Measured memory_bytes: 6400
#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 itrfor(itr,A) for(auto itr = A.begin(); itr !=A.end();itr++)
typedef long long llong;
char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define print(a) cout << a << endl;



int main(){
    string s;
    int h,w;
    cin >> h >> w;
    REP(i,h){
        cin >> s;
        cout << s << endl;
        cout << s << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef double dd;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> ii;
typedef pair<ll, int> li;
typedef pair<int, ll> il;
typedef pair<ll , ll> lli;
typedef vector<ii> vii;
typedef vector<il> vil;
typedef vector<li> vli;
typedef vector<lli> vlli;
 
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define in insert
#define f0(b) for(int i=0;i<(b);i++)
#define f00(b) for(int j=0;j<(b);j++)
#define f1(b) for(int i=1;i<=(b);i++)
#define f11(b) for(int j=1;j<=(b);j++)
#define f2(a,b) for(int i=(a);i<=(b);i++)
#define f22(a,b) for(int j=(a);j<=(b);j++)
#define sf(a) scanf("%lld",&a)
#define sff(a,b) scanf("%lld %lld", &a , &b)
#define pf(a) printf("%lld\n",a)
#define pff(a,b) printf("%lld %lld\n", a , b)
#define PI 3.14159265359
#define bug printf("**!\n")
#define mem(a , b) memset(a, b ,sizeof(a))
#define front_zero(n) __builtin_clzll(n)
#define back_zero(n) __builtin_ctzll(n)
#define total_one(n) __builtin_popcountll(n)

const ll mod = (ll)998244353;
const ll maxn = (ll)1e6+5;
const int nnn = 1048590;
const int inf = numeric_limits<int>::max()-1;
//const ll INF = numeric_limits<ll>::max()-1;
const ll INF = 1e18;

ll dx[]={0,1,0,-1};
ll dy[]={1,0,-1,0};
ll dxx[]={0,1,0,-1,1,1,-1,-1};
ll dyy[]={1,0,-1,0,1,-1,1,-1};


void solve(){
	ll m[maxn];
	map < ll , ll > num;
	ll n;
	mem(m , 0);
	cin >> n;
	ll a[n+5];
	f1(n) cin >> a[i] , num[a[i]]++;
	for(auto u : num){
		ll len = u.ss;
		ll vr = u.ff;
		for(ll i = vr; i <= (ll)maxn-2; i+=vr) m[i] += len; //cout << i << ' ' << len << ' ' << vr << '\n';
		//cout << len << '\n';
	}
	ll ans= 0;
	for(ll i = 1; i <= n; i++){
		if(m[a[i]] == 1) ans++;
		//cout << m[a[i]] << '\n';
	}
	cout << ans;
	return;
}


int main() {
   
    ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
    ll T;
    T=1;
    //cin >> T;
    //scanf("%lld",&T);
    ll CT = 0;
    //work();
    while(T--){
    	//cout << "Case " << ++CT <<": " ;
    	//printf("Case %lld: ",++CT);
		solve();
	}
    
    return 0;
}


Measured memory_bytes: 25528
n=int(input())
while n>0:
    m=1000-n
    a=int(m/500)
    b=int(int(m%500)/100)
    c=int(int(m%100)/50)
    d=int(int(m%50)/10)
    e=int(int(m%10)/5)
    f=int(int(m%5)/1)
    print(a+b+c+d+e+f)
    n=int(input())


Measured memory_bytes: 5588
#include <iostream>
#include <vector>
 
long dp[101][100001];

const int INF = 1e9+7;
/*
 *	the dp now is going to be the min total weight of items with value i
 *
 *
 */
 
long knap_value(int N, int V, int W, const std::vector<int>& w, const std::vector<int>& c)
{

	for (int j = 1; j <= V; j++)
		dp[0][j] = INF;

	for (int i = 1; i <= N; i++)
	{
		for (int j = 1; j <= V; j++)
		{
			if (j >= c[i])
				dp[i][j] = std::min(dp[i-1][j], w[i] + dp[i-1][j - c[i]]);
			else
				dp[i][j] = dp[i-1][j];
		}
	}

	long ans = 0;

	for (int i = V; i >= 0; i--)
	{
		if (dp[N][i] <= W)
		{
			ans = i;
			break;
		}
	}
	
	return ans;
}
 
int main() {
	int N, W; std::cin >> N >> W;
	
	std::vector<int> w(N+1), c(N+1);

	int value_sum = 0;
	
	for (int i = 1; i <= N; i++)
	{
		std::cin >> w[i] >> c[i];

		value_sum += c[i];
	}
	
	long ans = knap_value(N, value_sum, W, w, c);

	std::cout << ans << "\n";
}


Measured memory_bytes: 79104
#include <iostream>

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

    for (int i = 1; i <= n; ++i) {
        int x = i;

        if (x % 3 == 0) {
            std::cout << " " << i;
        } else {
            while (x) {
                if (x % 10 == 3) {
                    std::cout << " " << i;
                    break;
                }
                
                x /= 10;
            }
        }
    }

    std::cout << std::endl;
}


Measured memory_bytes: 3088
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#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 FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

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

struct edge{
  int to, cost;
};

int c, n, m, start, goal;
vector<edge> v[105];	       
vector<vector<int> > dp(11, vector<int>(105, 0));

int dijkstra(int s, int a){
  REP(i, 105) dp[a][i]=INF;
  dp[a][s]=0;

  priority_queue<P> q;
  q.push(P(0, s));
  while(!q.empty()){
    int u=q.top().second;
    if(dp[a][u]<q.top().first) continue;
    q.pop();

    REP(i, v[u].size()){
      int to=v[u][i].to;
      int cost=(a==0 ? v[u][i].cost+dp[a][u] : min(v[u][i].cost+dp[a][u], v[u][i].cost/2+dp[a-1][u]));
      if(dp[a][to]>cost){
	dp[a][to]=cost;
	q.push(P(-cost, to));
      }
    }
  }
}

int main(){
  while(1){
    scanf("%d%d%d%d%d", &c, &n, &m, &start, &goal);
    start--; goal--;
    if(c==0) return 0;
    
    REP(i, m){
      int from, to, f;
      scanf("%d%d%d", &from, &to, &f);
      from--; to--;
      v[to].push_back((edge){from, f});
      v[from].push_back((edge){to, f});
    }

    REP(i, c+1){
      dijkstra(start, i);
    }

    printf("%d\n", dp[c][goal]);

    REP(i, 105){
      v[i].erase(v[i].begin(), v[i].end());
    }
    REP(i, 11){
      dp[i].erase(dp[i].begin(), dp[i].end());
    }
  }
}

Measured memory_bytes: 1232
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define FOR(i) for(cin>>i;i>0;i--)
#define elif else if
#define pb push_back
#define ll long long
#define mp make_pair
#define all(x) x.begin(),x.end()
#define re(x) {cout<<x<<endl;return 0;}
//#define x first
//#define y second

using namespace std;
string a;
int main()
{
	cin>>a;
	rep(i,a.size()) if(a[i]=='7') re("Yes")
	re("No")
	return 0;}

Measured memory_bytes: 3624
#include <stdio.h>

int main(){
    int in[2];
    scanf("%d %d", &in[0], &in[1]);

    switch((in[0]+1)/7){
    case 0:
        printf("0");
        break;
    case 1:
        printf("%d", in[1]/2);
        break;
    default:
        printf("%d", in[1]);
        break;
    }
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAX = 13;

int N, M, X;
int c[MAX], a[MAX][MAX], s[MAX];

bool judge() {
    for (int i = 0; i < M; i++)
        if (s[i] < X) return false;
    return true;
}

int main() {
#ifdef ACM_LOCAL
    freopen("input.in", "r", stdin);
    freopen("output.out", "w", stdout);
#endif
    scanf("%d%d%d", &N, &M, &X);
    for (int i = 0; i < N; i++) {
        scanf("%d", &c[i]);
        for (int j = 0; j < M; j++) scanf("%d", &a[i][j]), s[j] += a[i][j];
    }
    if (judge()) {
        int mx = (1 << N) - 1, ans = 0x3f3f3f3f;
        for (int state = 0; state <= mx; state++) {
            int cost = 0;
            for (int i = 0; i < M; i++) s[i] = 0;
            for (int bit = 0; bit < N; bit++)
                if (state & (1 << bit)) {
                    cost += c[bit];
                    for (int j = 0; j < M; j++)
                        s[j] += a[bit][j];
                }
            if (judge()) ans = min(ans, cost);
        }
        printf("%d\n", ans);
    }
    else printf("-1\n");

    return 0;
}

Measured memory_bytes: 3816
import sys
import itertools

input = sys.stdin.readline
X = int(input())
#a = [int(i) for i in input().split()] 
#e = [[int(i) for i in input().split()] for i in range(n)] 

maxtimes = int(X/100)+2
price = 0
for i1 in range(0, maxtimes):
    #if i1*100 > X:
        #break
    for i2 in range(0, int(X/101)+2):
        #if i1*100+i2*101 > X:
            #break
        for i3 in range(0, int(X/102)+2):
            #if i1*100+i2*101+i3*102 > X:
                #break
            for i4 in range(0, int(X/103)+2):
                #if i1*100+i2*101+i3*102+i4*103 > X:
                    #break
                for i5 in range(0, int(X/104)+2):
                    #if i1*100+i2*101+i3*102+i4*103+i5+104 > X:
                        #break
                    for i6 in range(0, int(X/105)+2):
                        price = i1*100+i2*101+i3*102+i4*103+i5*104+i6*105
                        #print(i1, i2, i3, i4, i5, i6)
                        if price == X:
                            print(1)
                            exit()
                        elif price > X:
                            break

print(0)


Measured memory_bytes: 48476
#include<stdio.h>
int main(void)
{
	int a,b;
	float x;
	scanf("%d %d",&a,&b);
	x=0;
	x=(a+b)/2;
	if((a+b)%2!=0){
		x+=1;
	}
	printf("%.0f\n",x);
	return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define All(V) v.begin(), v.end()
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD = 1e9+7, INF = 1e9;

int main()
{
  int n; cin >> n;
  string s; cin >> s;
  int ans = 0, t = 0;
  for(int i = 0; i < s.size(); i++){
    if(s[i] == 'I') t += 1;
    else t -=1;
    ans = max(ans, t);
  }
  cout << ans << endl;
  system("pause");
}

Measured memory_bytes: 504
import java.util.Scanner;

class Main{
	public static void main(String[] args){
		Scanner scanner = new Scanner(System.in);
		int a = scanner.nextInt();
		int b = scanner.nextInt();
		int c = scanner.nextInt();
		
		if(a < b && b < c){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 26236
#include <iostream>
#include <string>
 
int main()
{
  std::string N;
  std::cin >> N;
  
  int have7 = N.find("7");
  
  if (have7 == std::string::npos){
    std::cout<< "No" << std::endl;
  }else{
    std::cout<< "Yes" << std::endl;
  }
 
}

Measured memory_bytes: 3620
#include<stdio.h>
#include<string.h>


void swap(char c1[],char c2[])
{
	char tmp[3];
	strcpy(tmp,c1);
	strcpy(c1,c2);
	strcpy(c2,tmp);
}

void BubbleSort(char A[][3],int n)
{
	int i,j;

	for(i=0;i<n;i++)
	{
		for(j=n-1;j>=i+1;j--)
		{
			if(A[j][1]<A[j-1][1])
			{
				swap(A[j],A[j-1]);
			}
		}
	}
}

void SelectionSort(char A[][3],int n)
{
	int i,j,minj;
	for(i=0;i<n;i++)
	{
		minj=i;
		
		for(j=i;j<n;j++)
		{
			if(A[j][1]<A[minj][1])
			{
				minj=j;
				
			}
		}
	
	if(A[minj]!=A[i])
	{
		swap(A[i],A[minj]);
	}
}
}
int main(void)
{
	int i,n;
	int count=0;
	scanf("%d",&n);
	
	char A[n][3],B[n][3];
	
	for(i=0;i<n;i++)
	{
		scanf("%s",&A[i]);
		strcpy(B[i],A[i]);
	}
	
	BubbleSort(A,n);
	for(i=0;i<n-1;i++)
	{
		printf("%s ",A[i]);
	}

	printf("%s\n",A[n-1]);
	printf("Stable\n");
	
	SelectionSort(B,n);
	
	for(i=0;i<n-1;i++)
	{
		printf("%s ",B[i]);
	}
	printf("%s\n",B[n-1]);
	for(i=0;i<n;i++)
	{
		
		if(strcmp(A[i],B[i])==0)
		{
			count=0;
		}
		else
		{
			count=1;
			break;
		}
	}
		

	
	if(count==1)
	{
		printf("Not stable\n");
	}
	if(count==0)
	{
		printf("Stable\n");
	}
	
	return 0;
}
	


Measured memory_bytes: 2092
"use strict";

var main = function main(input) {
  var revInput = input.trim().split('').reverse().join('');
  var flag = true;

  for (var i = 0; i < revInput.length; i++) {
    if (revInput.charAt(i) == 'm') {
      if (revInput.slice(i, i + 5) === 'maerd') {
        i += 4;
      } else {
        flag = false;
        break;
      }
    } else if (revInput.charAt(i) == 'e') {
      if (revInput.slice(i, i + 5) === 'esare') {
        i += 4;
      } else {
        flag = false;
        break;
      }
    } else if (revInput.charAt(i) == 'r') {
      if (revInput.slice(i, i + 6) === 'resare') {
        i += 5;
      } else if (revInput.slice(i, i + 7) === 'remaerd') {
        i += 6;
      } else {
        flag = false;
        break;
      }
    }
  }

  console.log(flag == true ? 'YES' : 'NO');
};

main(require('fs').readFileSync('/dev/stdin', 'utf-8'));

Measured memory_bytes: 9144
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <functional>
#include <utility>
#include <queue>
#include <vector>
#include <string>
using namespace std;
typedef long long int ll;
const ll  MOD = 1000000007;


int main(){
  int N;
  int a[100100];
  cin >> N;
  for(int i=1;i<=N;i++){
    cin >> a[i];
  }
  int ans=0;
  for(int i=1;i<=N;i++){
    if(a[a[i]] == i) ans++;
  }
  cout << ans/2 << endl;
}


Measured memory_bytes: 640