akhauriyash/Code-Regression huggingface dataset:
Imports System.Collections.Generic
Imports System.Console
Imports System.Math

Module Program
    Sub Main()
        Dim A As Integer = NextInt()
        Dim B As Integer = NextInt()
        Dim C As Integer = NextInt()
        Dim K As Integer = NextInt()

        Dim M As Integer = Max(A, Max(B, C))

        WriteLine(M * (2 ^ K - 1) + A + B + C)
    End Sub

    Function NextInt() As Integer
        Return CInt(NextString())
    End Function

    Function NextString() As String
        Dim result As New List(Of Char)
        Do
            Dim tmp As Integer = Read()
            If tmp < 0 Then Exit Do
            Dim nextChar As Char = Chr(tmp)

            If Not Char.IsWhiteSpace(nextChar) Then
                result.Add(nextChar)
            ElseIf nextChar <> vbCr Then
                Exit Do
            End If
        Loop
        Return New String(result.ToArray())
    End Function

End Module


Measured memory_bytes: 19920
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
ll n;
cin>>n;
vector<pair<string,ll>> v;
for(int i = 0;i<n;i++)
{
	string s;
	ll t;
	cin>>s>>t;
	pair<string,ll> p = {s,t};
	v.push_back(p);
}
string x;
cin>>x;
bool check = 0;
ll ans = 0;
for(auto it = v.begin();it!=v.end();it++)
{
	if(check)
	{
		ans+=it->second;
	}
	if(it->first==x)
	{
		check=1;
	}
}
cout<<ans<<"\n";
}


Measured memory_bytes: 3656
#include <iostream>
#include <set>
#include <vector>

int main() {
  int N;
  std::cin >> N;
  std::vector<int> A(N), B(N);
  for (int i = 0; i < N; i++) {
    std::cin >> A.at(i);
  }
  for (int i = 0; i < N; i++) {
    std::cin >> B.at(i);
  }
  std::set<std::pair<int, int>, std::greater<std::pair<int, int>>> s;

  for (int i = 0; i < N; i++) {
    s.emplace(B.at(i), i);
  }

  long long ans = 0;
  while (!s.empty()) {
    int i = s.begin()->second;
    s.erase(s.begin());

    int d = B.at(i) - A.at(i), t = B.at((i + 1) % N) + B.at((N + i - 1) % N);
    if (d != 0 && d < t) {
      ans = -1;
      break;
    }
    ans += d / t;
    B[i] -= d / t * t;

    if (B.at(i) != A.at(i))
      s.emplace(B.at(i), i);
  }

  std::cout << ans;

  return 0;
}

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


int main() {
  int d;
  cin >> d;
  cout << "Christmas" << " ";

  rep(i, 25 - d) cout << "Eve ";
  cout << endl; 
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define per1(i,n) for(int i=n;i>0;i--)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
int par[200001],ran[200001];
void init(int n){                 //忘れない
    rep(i,n+1) par[i]=i,ran[i]=0;
}
int find(int x){
    if(par[x]==x) return x;
    else return par[x]=find(par[x]);
}
void unite(int x,int y){
    x=find(x);
    y=find(y);
    if(x==y) return;
    if(ran[x]<ran[y]) par[x]=y;
    else{
        par[y]=x;
        if(ran[x]==ran[y]) ran[x]++;
    }
}
int same(int x,int y){
    return find(x)==find(y);
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,m,a,b;
    cin>>n>>m;
    init(n);
    rep(i,m) cin>>a>>b,unite(a,b);
    vec num(n+1,0);
    rep1(i,n) num[find(i)]++;
    cout<<*max_element(all(num));
}

Measured memory_bytes: 6348
#include <cstdio>
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <cmath>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#define rep(i,n) for (int i=0;i<n;i++)
using ll = long long;
using namespace std;

void solve(){

}

int ans = 0;
int n;

int dfs(int a){
    if(a<=n){
        bool a3=false,a5=false,a7=false;
        int m = a;
        while(m>0){
            if(m%10 == 3) a3 = true;
            if(m%10 == 5) a5 = true;
            if(m%10 == 7) a7 = true;
            m/=10;
        }
        if(a3&&a5&&a7) ans = ans + 1;
    }

    
    if(a<=100000000&&a<=n){
        dfs(10*a+3);
        dfs(10*a+5);
        dfs(10*a+7);
    }
    return 0;
}

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

    dfs(3);
    dfs(5);
    dfs(7);
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3548
#include <stdio.h>

#define INF -1

typedef struct{
int v[101];
int k;
} Roll;

char color[101];
int Q[101];
int head=0;
int tail=0;
int d[101];
int n;
Roll A[101];

void enqueue(int key){
  Q[head]=key;
  head++;
  return;
}

int dequeue(){
  int x;
  x=Q[tail];
  tail++;
  return x;
}

void bfs(Roll G[],int s){
  int u,x;
  for(u=1;u<=n;u++){
    color[u]='W';
    d[u]=INF;
  }
  color[s]='G';
  d[s]=0;
  enqueue(s);
  while(head!=tail){
    u=dequeue();
    for(x=0;x<G[u].k;x++){
      if(color[G[u].v[x]]=='W'){
        color[G[u].v[x]]='G';
        d[G[u].v[x]]=d[u]+1;
        enqueue(G[u].v[x]);
      }
    }
    color[u]='B';
  }
  return;
}



int main(){
  int i,j;
  int T;
  scanf("%d",&n);
  for(i=1;i<=n;i++){
    scanf("%d",&T);
    scanf("%d",&A[i].k);
    for(j=0;j<A[i].k;j++){
      scanf("%d",&A[i].v[j]);
    }
  }
  bfs(A,1);
  for(i=1;i<=n;i++){
    printf("%d %d\n",i,d[i]);
  }
  return 0;
}



Measured memory_bytes: 2088
/**   Created by: Marcos Portales
          Codeforces User: marcosportales
          Country: Cuba
                         **/
#include<bits/stdc++.h>
using namespace std;
/// Macros:
#define int long long
#define f first
#define s second
#define db(x) cerr << #x << ": " << (x) << '\n';
#define pb push_back
#define lb lower_bound
#define up upper_bound
#define all(x) x.begin() , x.end()
#define rall(x) x.rbegin() , x.rend()
#define enl '\n'
#define vi vector<int>
#define sz size
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
typedef pair<int,int> ii;
typedef long double ld;
typedef unsigned long long ull;
/// Constraints:
const int maxn = 3*1e5+5;
const int mod = 1000000009;
const ld eps = 1e-9;
const int inf = ((1ll<<31ll)-1ll);
const int INF = 10000000000000000ll;
const ld pi = acos(-1);
/// Prime Numbers:
// 2, 173, 179, 181, 197, 311, 331, 737, 1009, 2011, 2027, 3079, 4001, 10037, 10079, 20011, 20089;
// 100003, 100019, 100043, 200003, 200017, 1000003, 1000033, 1000037, 1000081;
// 2000003, 2000029, 2000039, 1000000007, 1000000021, 2000000099;
/// Functions:
#define lg2(x) 31 - __builtin_clz(x)
#define lgx(x,b) ( log(x) / log(b) )
/// Red-Black Tree Template ---------------------------------
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//typedef tree < long long ,  null_type ,  less<long long> ,  rb_tree_tag ,  tree_order_statistics_node_update > ordered_set;
/// Quick Pow------------------------------------------------
int qpow(int b,int e){
    if( !e ) return 1;
    if( e & 1 ) return qpow(b,e-1) * b;
    int pwur = qpow(b,e>>1);
    return pwur * pwur;
}
int modinv(int x){
    return qpow(x,mod-2);
}

/// My Code -------------------------------------------------

int32_t main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout.setf(ios::fixed); cout.precision(0);
    srand(time(NULL));

    ///freopen("a.in","r",stdin);
    ///freopen("a.out","w",stdout);
    int d,n;
    cin>>d>>n;
    if(n==100)cout<<qpow(100,d)*(n+1)<<enl;
    else cout<<qpow(100,d)*n<<enl;


    return 0;
}


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

public class Main {
	public static void main(String[] args) {
      Scanner sc = new Scanner(System.in);
      
      
      int a = 0;
      int N = sc.nextInt();
      int K = sc.nextInt();
      int p[] = new int[N];
      for(int i = 0; i < N; i++){
        p[i] = sc.nextInt();
      }
      Arrays.sort(p);
      for(int i=0; i<K; i++){
        a+=p[i];
      }
      
      System.out.println(a);   
    }
}

Measured memory_bytes: 29900
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<bitset>
#include<vector>
#include<deque>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<iomanip>
#include <functional>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
const int INF = 1 << 30;
const double EPS = 1e-10;
//cout << fixed << std::setprecision(9)
//memset(a, 0, sizeof(a));
//--------------------------

string s;
int a, b, c, d, x;
int cost[3];
int main()
{
	for (int i = 0;i < 3;i++) {
		cin >> cost[i];
	}

	sort(cost, cost + 3);

	cout << cost[2] - cost[0] << endl;
	
	return 0;
}


Measured memory_bytes: 256
class UnionFind():
    #負の値はルートで集合の個数
    #正の値は次の要素を返す
    def __init__(self,size):
        self.table = [-1 for _  in range(size)]

    #集合の代表を求める
    def find(self,x):
        while self.table[x] >= 0:
            #根に来た時,self.table[根のindex]は負の値なのでx = 根のindexで値が返される。
            x = self.table[x]
        return x

    #併合
    def union(self,x,y):
        s1 = self.find(x)#根のindex,table[s1]がグラフの高さ
        s2 = self.find(y)
        if s1 != s2:#根が異なる場合
            if self.table[s1] != self.table[s2]:#グラフの高さが異なる場合
                if self.table[s1] < self.table[s2]:
                    self.table[s2] = s1
                else:
                    self.table[s1] = s2
            else:
                #グラフの長さが同じ場合,どちらを根にしても変わらない
                #その際,グラフが1長くなることを考慮する
                self.table[s1] += -1
                self.table[s2] = s1
        return

N,M = list(map(int,input().split()))
A = []
B = []
for i in range(M):
    a,b = map(int,input().split())
    A.append(a-1)
    B.append(b-1)

res = 0

for i in range(M):
    G = UnionFind(N)
    for j in range(M):
        if i != j:
            G.union(A[j],B[j])
    minas = 0
    for k in G.table:
        if k < 0:
            minas += 1
    if minas == 1:
        res += 1


print(M-res)
        

Measured memory_bytes: 3064
#include<iostream>
int h,w,a,b,i,j;
main(){
  std::cin>>h>>w>>a>>b;
  for(i=0;i<h;++i){
    for(j=0;j<w;++j)std::cout<<(i<b^j<a);
    std::cout<<"\n";
  }
}

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

using namespace std;

#pragma GCC optimize("-O3")
#pragma GCC target("avx2")

#define int long long

const int mod = 998244353;

int pw(int a, int n)
{
    if (n == 0)
    {
        return 1;
    }
    if (n == 1)
    {
        return a;
    }
    int cur = pw(a, n / 2);
    cur *= cur;
    cur %= mod;
    if (n % 2)
    {
        cur *= a;
    }
    return cur % mod;
}

const int MAXN = 3e3 + 47;

int dp[MAXN];

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n, s;
    cin >> n >> s;
    vector<int> a(n);
    dp[0] = 1;
    for (int i = 0; i < n; ++i)
    {
        cin >> a[i];
    }
    int t = pw(2, mod - 2);
    for (int i = 0; i < n; ++i)
    {
        for (int j = s; j >= a[i]; --j)
        {
            dp[j] += dp[j - a[i]] * t;
            dp[j] %= mod;
        }
    }
    int ans = dp[s] * pw(2, n);
    ans %= mod;
    ans += mod;
    ans %= mod;
    cout << ans << endl;
    return 0;
}


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

int main(){
   
    int A,B,i=1;
    cin >> A >> B;

    while(1){
        if((int)(i * 0.08) == A && (int)(i * 0.1) == B) break;
        if((int)(i * 0.08) > A) {i = -1; break;}
        i++;
    }
    
    cout << i << endl;
}

Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
//#define __gnu_pbds::gp_hash_table unordered_map;
#define int long long int
#define pb push_back

signed main(){
ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

int n;
cin>>n;
if(n%2)
{
     cout<<0;
     return 0;
}

n/=2;

int x=n/5,sum=0;

while(x>0)
{
     sum+=x;
     x/=5;
}
cout<<sum;

}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>

int main(){

  long long H, W;
  
  long long ans;
  
  std::cin>>H>>W;
  if(H==1 || W==1){
    std::cout<<"1";
  }
  else if(H%2 == 0){
    ans= (H/2)*W;
    std::cout<<ans;
  }
  else if(W%2 == 0){
    std::cout<<(W/2)*H;
  }
    
  else{
  	std::cout<<(H*W/2)+1;
  }
  
}

Measured memory_bytes: 3156
#include<iostream>

#include<iostream>

using namespace std;

int power(int n){
  if(n == 0){ return 1;}
  
  return 2 * power(( n - 1));}
  

int main(){
  int N,M ; cin >> N >> M;
  
  int t = 1900*M + 100*(N - M);
  
  int s = power(M); cout << s * t << endl;
  
  return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
int main(void) {
	int b[3], i;
	for (i = 0; i < 3; i++)scanf("%d", &b[i]);
	if (b[0] == 1 && b[1] == 1 || b[2] == 1)printf("Open\n");
	else printf("Close\n");
	return 0;
}

Measured memory_bytes: 584
import heapq

N,M = map(int,(input().split()))
A = [0]*N
B = [0]*N
mission = [[] for _ in range(M+1)]
work = 0

for i in range(N):
    if i <= M:
        heapq.heapify(mission[i])
    A[i],B[i] = map(int,(input().split()))
    if A[i] <= M:
        mission[A[i]].append(-B[i])

for day in range(1,M+1):
    for i in range(len(mission[day])):
        heapq.heappush(mission[0],mission[day][i])
    if mission[0]:
        work += heapq.heappop(mission[0])

print(-work)

Measured memory_bytes: 85408
#include<bits/stdc++.h>
#define llong long long
#define mkpr make_pair
#define x first
#define y second
#define iter iterator
#define riter reversed_iterator
#define y1 Lorem_ipsum_
#define tm dolor_sit_amet_
using namespace std;

inline int read()
{
	int x = 0,f = 1; char ch = getchar();
	for(;!isdigit(ch);ch=getchar()) {if(ch=='-') f = -1;}
	for(; isdigit(ch);ch=getchar()) {x = x*10+ch-48;}
	return x*f;
}

const int mxN = 6e3;
char a[mxN+3];
int pos1[mxN+3],pos2[mxN+3],id[mxN+3];
string f[mxN+3];
int n;

int main()
{
	n = read(); scanf("%s",a+1);
	for(int i=1,x=0,y=0; i<=2*n; i++)
	{
		if(a[i]=='a') {pos1[++x] = i; id[i] = x;} else {pos2[++y] = i; id[i] = y;}
	}
	for(int i=1; i<=n; i++) if(pos1[i]>pos2[i]) {swap(pos1[i],pos2[i]);}
	for(int i=n; i>=1; i--)
	{
		if(a[pos1[i]]=='a')
		{
			int j = i; while(j<n&&pos1[j+1]<pos2[i]) {j++;}
			f[i] = "ab"+f[j+1];
		}
		else
		{
			int j = i; while(j<n&&pos1[j+1]<pos2[j]) {j++;}
			for(int k=pos1[i]; k<=pos2[j]; k++) if(id[k]>=i&&id[k]<=j) {f[i] += a[k];}
			f[i] += f[j+1];
		}
		if(f[i+1]>f[i]) {f[i] = f[i+1];}
	}
	cout<<f[1]<<endl;
	return 0;
}

Measured memory_bytes: 16512
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
#define limit(x, l, r) max(l, min(x, r))
#define lims(x, l, r) (x = max(l, min(x, r)))
#define isin(x, l, r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)), x.end())
#define show(x) cout << #x << " = " << x << endl;
#define print(x) cout << x << endl;
#define PQ(T) priority_queue<T, v(T), greater<T> >
#define bn(x) ((1 << x) - 1)
#define dup(x, y) (((x) + (y)-1) / (y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

int main() {
  int n;
  cin >> n;
  vl a(n);
  rep(i, n) cin >> a[i];
  vl ame(n);
  ll sum = 0;
  rep(i, n) sum += a[i];

  ll l = -2, r = sum+2;
  while (r - l > 1) {
    ll mid = l + (r - l) / 2;
    ame[0] = mid*2;
    for (int i = 1; i < n; i++) {
      ame[i] = (2 * a[i - 1] - ame[i - 1]);
    }
    ll sum2 = 0;
    rep(i, n) sum2 += ame[i];
    if (sum<sum2)
      r = mid;
    else
      l = mid;
    if(sum == sum2)break;
  }

  rep(i, n) cout << ame[i] << " ";
  cout << endl;
  return 0;
}

Measured memory_bytes: 4848
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll MOD = (1e+9)+7;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-11;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
typedef pair<P, int> PP;
int main(){
	int n, k; cin >> n >> k; int l[50];
	rep(i, n) {
		cin >> l[i];
	}
	sort(l, l + n, greater<int>());
	int out = 0;
	rep(i, k) {
		out += l[i];
	}
	cout << out << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int main() {
	int a, b;
	while(~scanf("%d%d", &a, &b)) {
		if(a + b >= 10) puts("error");
		else printf("%d\n", a + b);
	}
	return 0;
} 

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pi 3.1415  
#define ll long long
#define pii pair<int,int>
#define debug(a) cout<<a<<'\n'
#define maxn 100009
#define MOD 1000000007
#define INF (int)3000009
using namespace std;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    vector<pii> vet;
    for(int i=0;i<n;i++){
        int a;
        cin>>a;
        vet.push_back({a,i});
    }
    sort(vet.begin(),vet.end());
    for(auto e: vet){
        cout<<e.second+1<<" ";
    }
    cout<<endl;
    return 0;
}

Measured memory_bytes: 1780
#include<iostream>
#include<vector>
#include<utility>
#include<algorithm>
#include<map>
#include<cmath>
#include<bitset>
typedef long long ll;
#define PB	push_back
#define FOR(n)			for(int i = 0; i < n; ++i)
#define RFOR(n)			for(int i = n; i >= 0; --i)
#define FORR(start,end) for(int i = start; i < end; ++i)
#define COUT(n)			cout << n << " " << flush
#define vi(v)			vector<int> v
#define vii(v)			vector<pair<int,int>> v
#define mii(m)			map<int, int> m
#define msi(m)			map<string, int, less<>> m
#define mmsi(m)			multimap<string, int, less<>> m
#define mkp(a,b)		make_pair(a,b)
#define ALL(obj)		obj.begin(), obj.end()
#define PI 3.141592
#define MOD 1e9+7
using namespace std;

void solve() {
	ll a, b, k;
	ll ansa = 0, ansb = 0;
	cin >> a >> b >> k;
	if (k < a) {
		ansa = a - k;
		cout << ansa << " " << b << endl;
		return;
	}
	else if (k - a < b)
	{
		ansb = b - (k - a);
		cout << 0 << " " << ansb << endl;
		return;
	}
	else
		cout << "0 0" << endl;
}

int main() {
	solve();
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define repi(i,x) for(auto i=(x).begin(),i##_fin=(x).end();i!=i##_fin;i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define solve(a) ((a)?"Yes":"No")
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int , int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
const long long INFLL = 1LL<<60;
const int INF = 1<<30;
const double PI=acos(-1);
int main(){
	int n;
	int ans=0;
	cin >>n;
	string s;
	int p;
	vector<tuple<string,int,int>>dis(n);
	rep(i,n){	
		cin>>s>>p;
		dis[i]=make_tuple(s,100-p,i+1);
	}
	sort(all(dis));
	rep(i,n){
		cout<<get<2>(dis[i])<<endl;
	}
	//cout<<n*n<<endl;
}

Measured memory_bytes: 3644
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int[][] myGraph = new int[n][n]; //assume nxn
		
		int currentVertex;
		int degree;
		
		
		for (int j = 0; j < n; j++) {
			currentVertex = in.nextInt();
			degree = in.nextInt();
			for (int i = 0; i < degree; i++) {
				myGraph[currentVertex-1][in.nextInt()-1] = 1;
			}
		}
		
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				if (j != 0) System.out.print(" ");
				System.out.print(myGraph[i][j]);
				
			}
			System.out.println();
		}
	}
}



Measured memory_bytes: 34104
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
#include <queue>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int n, m, u, v, b[707][707] = {}, c[707] = {}, d[707][707] = {1};
    vector<int> x = {0}, y = {0};
    cin >> n >> m;
    while (m--) cin >> u >> v, b[u][v] = b[v][u] = 1;
    for (int i = 1; i <= n; i++) if (!c[i]) {
        c[i] = 1;
        queue<int> q;
        q.push(i);
        x.push_back(1);
        y.push_back(0);
        while (!q.empty()) {
            int w = q.front();
            q.pop();
            for (int j = 1; j <= n; j++) if (w != j && !b[w][j]) {
                if (!c[j]) {
                    c[j] = 3 - c[w];
                    if (c[j] == 1) x.back()++;
                    else y.back()++;
                    q.push(j);
                } else if (c[j] == c[w]) {
                    cout << -1;
                    return 0;
                }
            }
        }
    }
    for (int i = 1; i < x.size(); i++) {
        for (int j = n; j >= x[i]; j--) d[i][j] |= d[i - 1][j - x[i]];
        for (int j = n; j >= y[i]; j--) d[i][j] |= d[i - 1][j - y[i]];
    }
    for (int i = n / 2; i >= 0; i--) if (d[x.size() - 1][i]) {
        cout << i * (i - 1) / 2 + (n - i) * (n - i - 1) / 2;
        return 0;
    }
}


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

#ifdef LOCAL
#include "../../dump.hpp"
#else
#define dump(...)
#endif

#define rep(i,n) for(ll i=0,i##_cond=(n);i<i##_cond;i++)
#define FOR(i,a,b) for(ll i=(a),i##_cond=(b);i<i##_cond;i++)
#define ROF(i,a,b) for(ll i=(a)-1,i##_cond=(b);i>=i##_cond;i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend() //sortで大きい順
#define UNIQUE(v) v.erase(unique(all(v)),v.end())
#define SUM(a) accumulate(all(a),0)
#define sz(x) ((ll)(x).size())
#define pb push_back
#define fst first
#define snd second
#define mp make_pair

typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<ll,ll> pii;

const ll inf = 1ll<<62;
const ll mod = 1e9+7;

#define int ll

main()
{
  int n; cin >> n;
  vi a(n); rep(i,n) cin >> a[i];

  // 可能か
  if(a[0] != 0){
    cout << -1 << endl;
    return 0;
  }
  int zeropos = 0;
  FOR(i,1,n){
    if(a[i] == 0){
      zeropos = i;
    }else if(a[i] <= i - zeropos){
    }else{
      cout << -1 << endl;
      return 0;
    }
  }

  // 何回か
  int ans = 0;
  rep(i,n-1){
    if(a[i+1] <= a[i]){
      ans += a[i];
    }else if(a[i+1] == a[i]+1){
    }else{
      cout << -1 << endl;
      return 0;
    }
  }
  ans += a[n-1];
  cout << ans << endl;
}

Measured memory_bytes: 1792
import java.util.*

fun main(args: Array<String>) {
  val sc = Scanner(System.`in`)
  val n = sc.nextInt()

  var ans = 0L
  for (j in 1..n) {
    val y = (n / j).toLong()
    val tmp = y * (y+1L) * j.toLong() / 2L
    ans += tmp
  }

  println(ans)
}


Measured memory_bytes: 36520
import java.util.*;

public class Main{
  public static void main(String[] args) {
    Scanner sc=new Scanner(System.in);
    int a=sc.nextInt();
    int b=sc.nextInt();
    int c=sc.nextInt();
    int d=sc.nextInt();
    if((a+b)>(c+d)) System.out.println("Left");
    if((a+b)==(c+d)) System.out.println("Balanced");
    if((a+b)<(c+d)) System.out.println("Right");
  }
}


Measured memory_bytes: 21972
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc=new Scanner(System.in);

		int A=sc.nextInt();
		int B=sc.nextInt();
		int C=sc.nextInt();

		System.out.println(Math.min(B/A, C));

		sc.close();
	}

}


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

using namespace std;

int main(void) {
    constexpr long MOD = 1e9 + 7;

    long n, m;
    cin >> n >> m;

    vector<long> a(m);
    for(auto &x: a) cin >> x;

    vector<long> dp(n+3);

    dp[0] = 1;
    for(int i=0; i<n; i++) {
        {
            auto it = lower_bound(a.begin(), a.end(), i);
            if(it != a.end() && *it == i) continue;
        }

        dp[i+1] += dp[i];
        dp[i+1] %= MOD;
        dp[i+2] += dp[i];
        dp[i+2] %= MOD;
    }

    cout << dp[n] << endl;
}


Measured memory_bytes: 1792
N=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))

ans=0
for i in range(N):
    if(a[i]>=b[i]):
        ans+=b[i]
    else:
        ans+=a[i]
        nokori=b[i]-a[i]
        if(a[i+1]>=nokori):
            a[i+1]-=nokori
            ans+=nokori
        else:
            ans+=a[i+1]
            a[i+1]=0
       

print(ans)

Measured memory_bytes: 19116
N=int(input())
A=[]
for _ in range(2):
	A.append(list(map(int,input().split())))
a=A[0][0]+sum(A[1])
ans=a
for n in range(N-1):
	a+=A[0][n+1]-A[1][n]
	ans=max(ans,a)
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
using namespace std;
const int MAXN = 1e5 + 5;
typedef long long ll;
int nums1[MAXN], nums2[MAXN], nums3[MAXN];
bool cmp(int a, int b) {
    return a > b;
}
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int x, y, a, b, c;
    cin >> x >> y >> a >> b >> c;
    for (int i = 0; i < a; ++i)
        cin >> nums1[i];
    for (int i = 0; i < b; ++i)
        cin >> nums2[i];
    for (int i = 0; i < c; ++i)
        cin >> nums3[i];
    sort(nums1, nums1 + a, cmp);
    sort(nums2, nums2 + b, cmp);
    sort(nums3, nums3 + c, cmp);
    nums1[x] = 0;
    nums2[y] = 0;
    nums3[c] = 0;
    int p1 = 0, p2 = 0, p3 = 0;
    ll ans = 0;
    int cnt = 0;
    while (cnt < x + y) {
        if (nums1[p1] >= nums2[p2] && nums1[p1] >= nums3[p3]){
            ans += nums1[p1++];
        }
        else if (nums2[p2] >= nums1[p1] && nums2[p2] >= nums3[p3]) {
            ans += nums2[p2++];
        }
        else ans += nums3[p3++];
        ++cnt;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1408
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;


namespace StartFinish
{

    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                int[] nx = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
                int n = nx[0];
                int x = nx[1];
                if (n == 0 && x == 0)
                {
                    break;
                }
                int count = 0;
              //  int a, b, c;
                for (int i = n; i > 0; i--)
                {
                    for (int j = n; j > 0; j--)
                    {
                        for (int k = n; k > 0; k--)
                        {
                            if (i + j + k == x && i > j && j > k)
                            {
                                count++;
                            }
                        }
                    }
                }
                Console.WriteLine(count);
            }
        }
    }
}

Measured memory_bytes: 9536
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
int main(void){
	int x,y,z;
	long long s;
	long long a[101][101];
    long long b[101][101];
	scanf("%d %d %d", &x, &y,&z);
	for (int i = 0; i < x; i++){
		for (int j = 0; j < y; j++){
		scanf("%lld",&a[i][j]);
		}
	}
	for (int i = 0; i < y; i++){
		for (int j = 0; j < z; j++){
			scanf("%lld", &b[i][j]);
		}
	}

	for (int i = 0; i < x; i++){
		for (int j = 0; j < z; j++){
			s = 0;
			for (int k = 0; k < y; k++){
				s = s + (a[i][k] * b[k][j]);
			}
			if(j<z-1)printf("%lld ", s);
			else printf("%lld\n", s);
		}
	}

	return 0;
}

Measured memory_bytes: 2836
#include <bits/stdc++.h>
using namespace std;
#define N 105
int n,m;char a[N];
int main()
{
	scanf("%s",a+1);n=strlen(a+1);m=n>>1;
	for(int i=1;i<=n;++i) if(a[i]!=a[n-i+1]) {puts("No");return 0;}
	for(int i=1;i<=m;++i) if(a[i]!=a[m-i+1]) {puts("No");return 0;}
	for(int i=1;i<=m;++i) if(a[m+1+i]!=a[n-i+1]) {puts("No");return 0;}
	puts("Yes");return 0;
}

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

using namespace std;

int main(){
	int M, N, answer = 0;
	cin >> M >> N;
	for(int i = 0; i < M; ++i){
		int sum = 0;
		for(int j = 0; j < N; ++j){
			int a;
			cin >> a;
			sum += a;
		}
		answer = max(answer, sum);
	}
	cout << answer << endl;
	return 0;
}

Measured memory_bytes: 0
using System;

namespace ITP1
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[,,] data = new int[4,3,10];
            int b, f, r, v;

            for (int i = 0; i < n; i++)
            {
                string[] input = Console.ReadLine().Split(' ');
                b = int.Parse(input[0]);
                f = int.Parse(input[1]);
                r = int.Parse(input[2]);
                v = int.Parse(input[3]);

                data[b - 1, f - 1, r - 1] += v;
            }
            for (int m = 0; m < 3; m++)
            {

                for (int i = 0; i < 3; i++)
                {
                    for (int t = 0; t < 10; t++)
                    {
                        Console.Write(" " + data[m, i, t]);
                    }
                    Console.WriteLine();
                }
                Console.WriteLine(new string('#',20)); 
            }
            for (int i = 0; i < 3; i++)
            {
                for (int t = 0; t < 10; t++)
                {
                    Console.Write(" " + data[3, i, t]);
                }
                Console.WriteLine();
            }
        }
    }
}

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

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0;i < n;i++) cin >> a[i];

    int cnt = 0;
    for(int i = 0;i < n;i++){
        int minj = i;
        for(int j = i;j < n;j++){
            if(a[j] < a[minj]){
                minj = j;
            }
        }
        if(minj != i){
            int t = a[i];
            a[i] = a[minj];
            a[minj] = t;
            cnt++;
        }
    }

    for(int i = 0;i < n;i++){
        if(i) cout << " ";
        cout << a[i];
    }
    cout << endl;
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 3120
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<functional>
#include<math.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<(n);i++)
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = 1001001001;
const double PI = acos(-1);

int main() {
	int x, y;
	cin >> x >> y;
	bool exist = false;
	rep(i, x+1) {
		if (2 * i + 4 * (x - i) == y) exist = true;
	}
	printf(exist ? "Yes\n" : "No\n");

	return 0;
}

Measured memory_bytes: 3736
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time,random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


def main():
    n = I()
    a = LI()
    s = sum(a)
    r = 0
    for c in a:
        r += c * (s-c)

    return r // 2


print(main())



Measured memory_bytes: 5840
#include <stdio.h>
#include <math.h>

int main(void){
  int x;
  scanf("%d", &x);
  int ans;
  if(400<=x && x<600){
    ans=8;
  }else if(600<=x && x<800){
    ans=7;
  }else if(800<=x && x<1000){
    ans=6;
  }else if(1000<=x && x<1200){
    ans=5;
  }else if(1200<=x && x<1400){
    ans=4;
  }else if(1400<=x && x<1600){
    ans=3;
  }else if(1600<=x && x<1800){
    ans=2;
  }else if(1800<=x && x<2000){
    ans=1;
  }
  printf("%d\n", ans);
  return 0;
}

Measured memory_bytes: 1736
#include <bits/stdc++.h> 
using namespace std;
int main()
{
  int n;
  cin>>n;
  int a[n+1],b[n+1];
  
  for(int i=1;i<=n;i++)
    cin>>a[i];
  for(int i=1;i<=n;i++)
    b[i]=INT_MAX;
  b[1]=0;
  for(int i=1;i<=n-1;i++)
  {
    for(int j=i+1;j<=i+2 && j<=n;j++)
    {
      b[j]=min(b[j],b[i]+abs(a[j]-a[i]));
    }
  }
  cout<<b[n]<<endl;
}
               

Measured memory_bytes: 1024
package main

import "fmt"

func max(s ...int) int {
	max := s[0]
	for _, v := range s {
		if max < v {
			max = v
		}
	}
	return max
}

func pow(a, b int) int {
	ans := 1
	for i := 0; i < b; i++ {
		ans *= a
	}
	return ans
}

func main() {
	var a, b, c, k int
	fmt.Scan(&a, &b, &c, &k)

	sum := a + b + c + max(a, b, c)*(pow(2, k)-1)

	fmt.Println(sum)
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <set>
#include <cmath>
#include <algorithm>
#include <string>
#include <utility>
#include <map> 
#include <queue>
#include <stack>
#include <iomanip>
#include <sstream>
#define MP make_pair
#define PB push_back
#define S size()
#define B begin()
#define E end()
#define ll long long
#define REP(i,a,n) for(ll i=a; i<n; ++i)
#define RED(i,n,a) for(ll i=n; i>=a; --i)
#define m9 1000000007
#define endl "\n"
#define F first
#define SE second
#define ld long double



using namespace std;

ll gcd(ll a, ll b){
    if(a%b==0){
        return b;
    }
    else{
        return gcd(b, a%b);
    }
}
ld area(ld x1, ld y1, ld x2, ld y2, ld x3, ld y3){
    return abs(x1*(y2-y3)+x2*(y3-y1)+x3*(y1-y2))/2;
}
ld dp[2*2999+1][2999+1];

int main(){
    //freopen("input.txt", "r", stdin); 
    //freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
   ll n, k;
   cin>>n>>k;
   vector <ll> v(n);
   ll dp[k+1];
    REP(i,0,k+1){
        dp[i]=0;
    }
    REP(i,0,n){
        cin>>v[i];
    }
    REP(i,0,k+1){
        REP(j,0,n){
            if(i-v[j]>=0 && dp[i-v[j]]==0){
                dp[i]=1;
                break;
            }
        }
    }
    cout<<(dp[k]==1?"First":"Second");
}


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

public class P
{
    public string d { get; set; }
    public int x { get; set; }
    public int y { get; set; }
}

public class DICE
{
    private int[] data;
    public DICE(string s = "1,5,6,4,2,3")
    {
        data = new int[6];
        string[] line = s.Split(',');
        for (int i = 0; i < 6; i++)
            data[i] = int.Parse(line[i]);        // 0: ceilling 1: front 2: floor 3:right:4:back:5:left
    }
    public void roll(int c)
    {
        var w = new int[6];
        Array.Copy(data, w, 6);
        if (c == 3) { data[4] = w[0]; data[0] = w[1]; data[1] = w[2]; data[2] = w[4]; }
        else if (c == 1) { data[1] = w[0]; data[2] = w[1]; data[4] = w[2]; data[0] = w[4]; }
        else if (c == 0) { data[3] = w[0]; data[5] = w[2]; data[2] = w[3]; data[0] = w[5]; }
        else { data[5] = w[0]; data[3] = w[2]; data[0] = w[3]; data[2] = w[5]; }
    }
    public int peek(int n) => data[n];
    public string getDice() => string.Join(",", data);
}


public class hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var h = int.Parse(line[0]);
        var w = int.Parse(line[1]);
        var map = new int[h, w];
        for (int i = 0; i < h; i++)
        {
            var s = Console.ReadLine().Trim();
            for (int j = 0; j < w; j++)
                if (s[j] != '#') map[i, j] = s[j] - '0';
        }
        Console.WriteLine(getAns(h, w, map) ? "YES" : "NO");
    }
    static bool getAns(int h, int w, int[,] map)
    {
        var dx = new int[] { 0, 1, 0, -1 };
        var dy = new int[] { 1, 0, -1, 0 };
        var visited = new bool[h, w];
        var q = new Queue<P>();
        q.Enqueue(new P { d = "1,2,6,3,5,4", x = 0, y = 0 });
        visited[0, 0] = true;
        while (q.Count() > 0)
        {
            var t = q.Dequeue();
            if (t.x == h - 1 && t.y == w - 1) return true;
            for (int i = 0; i < 4; i++)
            {
                var nx = t.x + dx[i];
                var ny = t.y + dy[i];
                if (nx >= 0 && nx < h && ny >= 0 && ny < w && map[nx, ny] != 0 && !visited[nx, ny])
                {
                    var dice = new DICE(t.d);
                    dice.roll(i);
                    if (dice.peek(2) == map[nx, ny])
                    {
                        visited[nx, ny] = true;
                        q.Enqueue(new P { d = dice.getDice(), x = nx, y = ny });
                    }
                }
            }
        }
        return false;
    }
}



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

bool is_all_white(string v) {
  for (char c: v) {
    if (c == '#') return false;
  }
  return true;
}

int main() {
  int h, w;
  cin >> h >> w;
  
  vector<string> g;
  for (int i = 0; i < h; i++) {
    string s;
    cin >> s;

    if (!is_all_white(s)) {
      g.push_back(s);
    }
  }
  
  for (int i = 0; i < w; i++) {
    string s = "";
    for (int j = 0; j < g.size(); j++) {
      s += g[j][i];
    }

    if (is_all_white(s)) {
      for (int j = 0; j < g.size(); j++) {
        g[j][i] = '\0';
      }
    }
  }
  
  for (string s: g) {
    for (char c: s)
      if (c != '\0') cout << c;
    cout << endl;
  }
}



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

int main(){
    long long a,b,c,d;
    cin>>a>>b>>c>>d;
    long long res=max(a*c,max(a*d,max(b*c,b*d)));
    cout<<res<<endl;
}

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

int main(){
    int N,A[3][3],clear=0,crossCheck;
    int bingo[3][3] = {{0, 0, 0},
                       {0, 0, 0},
                       {0, 0, 0}};

    //input
    //printf("inputBingo >\n");
    for (int i=0; i < 3;i++)
    {
        //printf("----Bingo[%d]--- >\n",i);
        for (int j=0; j < 3;j++)
        {
            cin >> A[i][j];
        }
    }
    //printf("inputN >\n");
    cin >> N;
    int B[N];
    //printf("inputB >\n");
    for (int i = 0; i < N;i++)
    {
        cin >> B[i];
    }
    //bingocMark
    for(int i = 0; i < 3; i++)
    {
        for(int j = 0; j < 3; j++)
        {
            for(int Bcount = 0; Bcount < N; Bcount++)
            {
                if( (A[i][j]==B[Bcount])   )
                {
                    bingo[i][j] = 1;
                    //printf("dbg [%d][%d]\n", i, j);
                }
            }
        }
    }

    //row column check
     for(int i = 0; i < 3; i++)
    {
        if (( (bingo[i][0] == 1) &&(bingo[i][1] == 1) &&(bingo[i][2] == 1) )||
            ((bingo[0][i] == 1) &&(bingo[1][i] == 1) &&(bingo[2][i] == 1)))
        {
                clear = 1;
        }
    }
    //crosscheck
    if (((bingo[0][0] == 1) && (bingo[1][1] == 1) && (bingo[2][2] == 1))||
        ((bingo[0][2] == 1) && (bingo[1][1] == 1) && (bingo[2][0] == 1)))
    {
        clear = 1;
    }
    if (clear == 1)
    {
        cout << "Yes" << endl;
    }else
    {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

int main() {
    int N, W;
    int value[100];
    int weight[100];
    
    std::cin >> N >> W;
    for(int i = 0; i < N; i++) {
        std::cin >> value[i] >> weight[i];
    }
    
    int dp_buf[101][10001];
    for(int wi = 0; wi <= W; wi++) {
        dp_buf[0][wi] = 0;
    }
    
    for(int i = 0; i < N; i++) {
        for(int wi = 0; wi <= W; wi++) {
            if(weight[i] <= wi) {
                dp_buf[i + 1][wi] = std::max(dp_buf[i][wi - weight[i]] + value[i], dp_buf[i][wi]);
            }
            else {
                dp_buf[i + 1][wi] =  dp_buf[i][wi];
            }
        }
    }
    
    std::cout << dp_buf[N][W] << std::endl;
}



Measured memory_bytes: 7036
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T, class U> using Pa = pair<T, U>;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

void chmax(ll &a,ll b){if(a<b) a = b;}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vec<ll> A(N);
    for(int i=0;i<N;i++) cin >> A[i];
    vec<int> idx(N);
    iota(idx.begin(),idx.end(),0);
    sort(idx.begin(),idx.end(),[&](int i,int j){return A[i]>A[j];});
    vvec<ll> dp(N+1,vec<ll>(N+1,-1e18));
    dp[0][0] = 0;
    for(int l=0;l<N;l++) for(int k=0;l<N;k++){
        if(l+k>=N) break;
        int r = N-k;
        int id = idx[l+k];
        chmax(dp[l+1][k],dp[l][k]+A[id]*abs(id-l));
        chmax(dp[l][k+1],dp[l][k]+A[id]*abs(id-(r-1)));
    }
    ll ans = 0;
    for(int i=0;i<=N;i++) for(int j=0;j<=N;j++) if(i+j==N) ans = max(ans,dp[i][j]);
    cout << ans << "\n";
}

Measured memory_bytes: 34588
#include <bits/stdc++.h>
using namespace std;
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> a(n + 1);
    for (int i = 1; i <= n; i++) cin >> a[i];

    vector<int> v(n+1, 0);
    for (int i = n; i >= 1; i--) {
        int sum = 0;
        for (int j = i * 2; j <= n; j += i) {
            sum += v[j];
        }
        sum %= 2;
        v[i] = (a[i] + 2 - sum) % 2;
    }

    vector<int> ans;
    for (int i = 1; i <= n; i++) {
        if (v[i]) ans.push_back(i);
    }

    cout << ans.size() << "\n";
    for (int i = 0; i < ans.size(); i++) {
        cout << ans[i] << " \n"[i + 1 == ans.size()];
    }
    return 0;
}


Measured memory_bytes: 3192
#include <bits/stdc++.h>
#include <algorithm>
#include <string>
using namespace std;
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    double N, count = 0;
    cin >> N;
    cout << fixed << setprecision(6);
    for (int i = 1; i <= N; ++i) {
        if (i % 2 != 0) ++count;
    }
    cout << (count / N) << endl;
    return 0;
}

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

namespace
{
const int MAX = 100000000;		// 座標の最大・最小の位置
int N;			// 学生の総数
int M;			// チェックポイントの総数
int NX[ 51 ];	// 学生の X 座標
int NY[ 51 ];	// 学生の Y 座標
int MX[ 51 ];	// チェックポイントの X 座標
int MY[ 51 ];	// チェックポイントの Y 座標
int A[ 51 ];	// 学生の移動先のチェックポイントの番号
}

int main( int argc, char *argv[] )
{
int i;
int j;
int iNum;		// 学生の移動先のチェックポイントの番号
int iLen;		// マンハッタン距離
int iChk;

	// N M を取得
	cin >> N;
	if( N < 1 || N > 50 ) return 0;

	cin >> M;
	if( M < 1 || M > 50 ) return 0;

	// 学生の座標を取得
	for( i = 1; i <= N; i++ )
	{
		cin >> NX[ i ];
		if( NX[ i ] < - MAX || NX[ i ] > MAX ) return 0;
		cin >> NY[ i ];
		if( NY[ i ] < - MAX || NY[ i ] > MAX ) return 0;
	}

	// チェックポイントの座標
	for( j = 1; j <= M; j++ )
	{
		cin >> MX[ j ];
		if( MX[ j ] < - MAX || MX[ j ] > MAX ) return 0;
		cin >> MY[ j ];
		if( MY[ j ] < - MAX || MY[ j ] > MAX ) return 0;
	}

	// 各学生の移動先のチェックポイントの番号を算出
	for( i = 1; i <= N; i++ )
	{
		iNum = 0;
		iLen = - 1;
		for( j = 1; j <= M; j++ )
		{
			iChk = abs( NX[ i ] - MX[ j ] ) + abs( NY[ i ] - MY[ j ] );
			if( iLen < 0 || iLen > iChk )
			{
				iNum = j;
				iLen = iChk;
			}
		}

		A[ i ] = iNum;
	}

	// 出力
	for( i = 1; i <= N; i++ ) cout << A[ i ] << endl;

	return 0;
}


Measured memory_bytes: 256
import sys

X = int(input())
A = []
for i in range(1, int(X**0.5)+1):
    if X%i == 0:
        A.append([i, X//i])

for i in A:
    for a in range(1, int(X**0.5)+1):
        b = a - i[0]
        if a**4 + a**3*b + a**2*b**2 + a*b**3 + b**4 == i[1]:
            print(a, b)
            sys.exit()

Measured memory_bytes: 9456
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <climits> // FOO_MAX, FOO_MIN
#include <cmath> 
#include <cstdlib> // abs(int)
#include <numeric>
#include <iomanip>
#include <map>
#include <set>

using namespace std;

#define roundup(n,d) ( ((n) + ((d)-1)) / (d) )
#define assign_max(into, compared) (into = max((into), (compared)))
#define assign_min(into, compared) (into = min((into), (compared)))
#define rep(i,n) for(long long i = 0;i < n;++i)
#define FAST_IO ios::sync_with_stdio(false); cin.tie(nullptr);
#define fix(n) fixed << setprecision(n)
#define ALL(v) v.begin(),v.end()

#define PI 3.14159265358979323846;

using ll = long long;
using ull = unsigned long long;
using vll = vector<long long>;


int main(void){
    FAST_IO
    
    string s,t;
    cin >> s >> t;
    rep(i,s.size()){
        if(s == t){
            cout << "Yes" << endl;
            return 0;
        } 
        s = s.substr(1,s.size()-1) + s[0];
    }
    cout << "No" << endl;
}


Measured memory_bytes: 3088
import sys
sys.setrecursionlimit(10**7)

def dfs(v,p,d):
    dist[v]=d
    for nv in G[v]:
        if nv==p:
            continue
        dfs(nv,v,d+1)
        
def getSP(v):
    p=v
    if dist[v]==lim:
        return p
    for nv in G[v]:
        if dist[nv]<dist[v]:
            p=getSP(nv)
    return p
    
def depth(v,p,d):
    global maxd
    maxd=max(maxd,dist[v])
    for nv in G[v]:
        if dist[nv]<dist[v]:
            continue
        depth(nv,v,d+1)
    
N,u,v=map(int,input().split());u,v=u-1,v-1
if u==v:
    print(0)
    exit()

G=[[] for i in range(N)]
for i in range(N-1):
    a,b=map(lambda x:int(x)-1,input().split())
    G[a].append(b)
    G[b].append(a)
    
dist=[-1]*N
dfs(v,-1,0)

lim=dist[u]-(dist[u]-1)//2
SP=getSP(u)
 
maxd=-1
depth(SP,-1,0)

print(maxd-1)

Measured memory_bytes: 97840