akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
const auto start_time = std::chrono::high_resolution_clock::now();
void timecalculater(){
    #ifndef ONLINE_JUDGE
    auto end_time = std::chrono::high_resolution_clock::now();
    std::chrono::duration<double> diff = end_time-start_time;
    cerr<<"Time Taken : "<<diff.count()<<"\n";
    #endif
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void __print(int x) {cout << x;}
void __print(long x) {cout << x;}
void __print(long long x) {cout << x;}
void __print(unsigned x) {cout << x;}
void __print(unsigned long x) {cout << x;}
void __print(unsigned long long x) {cout << x;}
void __print(float x) {cout << x;}
void __print(double x) {cout << x;}
void __print(long double x) {cout << x;}
void __print(char x) {cout << '\'' << x << '\'';}
void __print(const char *x) {cout << '\"' << x << '\"';}
void __print(const string &x) {cout << '\"' << x << '\"';}
void __print(bool x) {cout << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cout << '{'; for (auto &i: x) cout << (f++ ? "," : ""), __print(i); cout << "}";}
void _print() {cout << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cout << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define dbg(x...) cout << "[" << #x << "] = ["; _print(x)
#else
#define dbg(x...)
#endif
#define fastio  cin.sync_with_stdio(0); cin.tie(0);cin.exceptions(cin.failbit);
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repA(i, a, n) for(int  i = a; i <= (n); ++i)
#define all(x) x.begin(), x.end()
#define sz(x) (int) (x).size()
#define fill(a,v) memset(a, v, sizeof(a))
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define endl '\n'
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long int> vll;
typedef vector<pii> vii;
ll p=998244353;
const int N=2e5+5;
int main() {
  
    
    fastio;
    int T=1;
    // cin>>T;
    while(T--){
        ll n,s;cin>>n>>s;
        ll a[n+1];
        rep(i,n)cin>>a[i+1];
        ll dp[n+1][s+1];
        fill(dp,0);
        dp[0][0]=1;
        for(ll i=1;i<=n;i++){
            for(ll j=0;j<=s;j++){
                dp[i][j]=((2LL)*dp[i-1][j]);dp[i][j]%=p;
                if(j>=a[i])
                dp[i][j]+=dp[i-1][j-a[i]];
                dp[i][j]%=p;
            }
        }
        cout<<dp[n][s];
    }   
    timecalculater();
    return 0;   
} 

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

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

	vector<int> town(n);

	for(int i=0;i<n;i++) cin>>town[i];

	int d = town[0];
	long long res = 0;
	for(int i=0;i<n;i++){
		int dx = town[i]-d;
		if((long long)dx*a > b) res+=b;
		else res+=((long long)dx*a);
		d = town[i];
		//cout<<res<<" ";
	}

	cout<<res;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(a); (i)<(b); ++(i))
#define rFor(i, a, b) for(int (i)=(a)-1; (i)>=(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
using namespace std;
typedef long long lint;

lint n, m;
vector<int> G[100010];
int c[100010];

bool dfs(int v, int t){
    if(c[v] >= 0) return c[v] == t ? true : false;
    c[v] = t;
    for(int nv : G[v]){
        if(!dfs(nv, t^1)) return false;
    }
    return true;
}

int main(){
    scanf("%lld%lld", &n, &m);
    rep(i, m){
        int a, b;
        scanf("%d%d", &a, &b);
        G[--a].push_back(--b);
        G[b].push_back(a);
    }
    rep(i, n) c[i] = -1;
    if(dfs(0, 0)){
        lint c1 = 0;
        lint c2 = 0;
        rep(i, n){
            if(c[i]) ++c1;
            else ++c2;
        }
        printf("%lld\n", c1*c2 - m);
    }
    else printf("%lld\n", n*(n-1)/2 - m);
}

Measured memory_bytes: 6400
n = int(input())
plus = []
minus = []
for a in map(int,input().split()):
    if a>=0:
        plus.append(a)
    else:
        minus.append(a)
ans = sum(plus)-sum(minus)
if len(minus)%2==1:
    if plus==[]:
        ans = ans + 2*max(minus)
    else:
        ans = ans - 2*min(abs(max(minus)),min(plus))
print(ans)

Measured memory_bytes: 20132
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
signed main(){
  int N;
  cin>>N;
  cout<<N/3;
  }


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

class C
{
	static void Main()
	{
		var h = Console.ReadLine().Split().Select(int.Parse).ToArray();
		var n = h[0];
		long a = MDiv(h[1], h[1] + h[2]), b = MDiv(h[2], h[1] + h[2]);

		long e = 0, ncr = 1, pa = MPow(a, n), pb = MPow(b, n);
		for (var i = n; i < 2 * n; i++, ncr = MMul(ncr, MDiv(i - 1, i - n)), pa = MMul(pa, b), pb = MMul(pb, a)) e = MAdd(e, MMul(MMul(i, ncr), pa + pb));
		Console.WriteLine(MMul(MDiv(100, 100 - h[3]), e));
	}

	const int M = 1000000007;
	static long MPow(long b, int i)
	{
		for (var r = 1L; ; b = b * b % M)
		{
			if (i % 2 > 0) r = r * b % M;
			if ((i /= 2) < 1) return r;
		}
	}
	static long MInv(long x) => MPow(x, M - 2);
	static long MAdd(long x, long y) => (x + y) % M;
	static long MMul(long x, long y) => x * y % M;
	static long MDiv(long x, long y) => x * MInv(y) % M;
}


Measured memory_bytes: 13396
/*
 * a.cc: 
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>

using namespace std;

/* constant */

/* typedef */

typedef long long ll;

/* global variables */

/* subroutines */

/* main */

int main() {
  ll n;
  cin >> n;

  for (int k = 0;; k++)
    if (n < (1LL << k)) {
      printf("%d\n", k);
      break;
    }

  return 0;
}

Measured memory_bytes: 1148
import sys
def mincost(n,h):
    dp=[-1 for i in range(n)]
    dp[n-1]=0
    dp[n-2]=abs(h[n-2]-h[n-1])
    for i in range(n-3,-1,-1):
        dp[i]=min(dp[i+1]+abs(h[i+1]-h[i]),dp[i+2]+abs(h[i+2]-h[i]))
    return dp[0]    

n=int(input())
h=[int(x) for x in input().split()]
print(mincost(n,h))

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

#define int long long

#define PB push_back
#define PPB pop_back
#define MK make_pair
#define ALL(V) V.begin(), V.end()
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<string, int> psi;
typedef pair<int, pii> pipii;

static const int INF = 1LL << 61;
//static const int MOD = 1000000007;
//static const int MAX_N = 100005;

int a[10005], k , t;

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

    cin >> k >> t;
    for (int i = 0; i < t; ++i) {
        cin >> a[i];
    }

    int pre = -1, ans = 0;
    for (int i = 0; i < k; ++i) {
        int mx = 0, id = pre;
        for (int j = 0; j < t; ++j) {
            if (j == pre) continue;
            if (mx < a[j]) {
                mx = a[j];
                id = j;
            }
        }
        if (pre == id) ans++;
        a[id]--;
        pre = id;
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,a,b;
scanf("%d %d %d",&n,&a,&b);
if(n==1)
{
if(a==b)
printf("1\n");
else
printf("0\n");
}
else
{
if(a>b)
printf("0\n");
else
printf("%lld\n",(long long)(b-a)*(n-2)+1);
}
return 0;
}

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

using namespace std;

int main() {

	int a;
	char d;
	int counter[4] = {0};
	string b;

	while (cin >> a >> d >> b) {

		if (b == "A\0") {
			counter[0]++;
		} else if (b == "B\0") {
			counter[1]++;
		} else if (b == "AB\0") {
			counter[2]++;
		} else {
			counter[3]++;
		}
	}

	for (int i = 0; i < 4; i++) {
		cout << counter[i] << endl;
	}

	return 0;
}

Measured memory_bytes: 1204
#include<bits/stdc++.h>
using namespace std;
main(){
    int h,w;
    cin >> h >> w;
    while(h != 0){
    vector<vector<char> > scr(h,vector<char>(w));

    for(int i = 0;i<h;i++){
        for(int j = 0;j<w;j++){
            cin >> scr.at(i).at(j);
        }
    }

    string s;
    cin >> s;
    
    int bx=0;int by=0;
    // for(int i = 0;i<h;i++){
    //     for(int j = 0;j<w;j++){
    //         if(scr.at(i).at(j) == s[0]){
    //             bx=i;by=j;
    //         }
    //     }
    // }



    int ans = 0;

    for(int n = 0;n<s.length();n++){
        for(int i = 0;i<h;i++){
        for(int j = 0;j<w;j++){
            if(scr.at(i).at(j) == s[n]){
                ans += abs(bx-i) + abs(by-j) +1;
                bx=i;by=j;
            }
        }
    }
      
    }
    cout << ans << endl;
    cin >> h >> w;
    }
     
    


}


Measured memory_bytes: 3172
#include<bits/stdc++.h>
#define mod 1000000007
#define int long long int
#define phi 1.6180339
#define rep(i,n) for(auto i=0;i<(n);i++)
#define endl "\n"
#define For(i,a,b) for(auto i=(a);i<(b);i++)
#define op1 cin.tie(NULL)
#define op2 cout.tie(NULL)
#define op3 std::ios_base::sync_with_stdio(false)
#define MAXX 1000001
using namespace std;
void trozen()
{
  int n;
  cin>>n;
  int summ=0;
  vector<int> v1(n);
  rep(i,n) cin>>v1[i],summ=(summ%mod+v1[i]%mod)%mod;
  int ans=0;
  rep(i,n)
  {
    summ=(summ+mod-v1[i])%mod;
    ans=(ans%mod+((v1[i]%mod)*(summ%mod))%mod)%mod;
  }
  cout<<ans<<endl;
}
int32_t main()
{
    op1;op2;op3;
    /*#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif*/
    trozen();
    return 0;
}


Measured memory_bytes: 4780
#include <iostream>
#include <vector>
#include <set>
#include <cstring>	// require memset
//#include <fstream>	// require freopen

using namespace std;

const int N = 501;
bool t[N][N];

int main()
{
//	cut here before submit 
//	freopen ("testcase.party", "r", stdin );
	int n, m;

	while (cin >> n >> m && n && m ){
		int i,j;

		memset (t, false, sizeof (t ) );

		for (i = 0; i < m; ++i){
			int from, to;
			cin >> from >> to;
			t[from][to] = true;
			t[to][from] = true;
		} // end for
		set <int> res;

		for (i = 2; i <= n; ++i ){
			if (t[1][i] ){
				res.insert (i );
				for (j = 2; j <= n; ++j ){
					if (t[i][j]){
						res.insert (j );
					} // end if
				} // end for
			} // end if
		} // end for
		if (!res.empty() ){
			cout << res.size() << endl;
		}else{
			cout << '0' << endl;
		} // end if
	} // end loop
		
	return 0;
}

Measured memory_bytes: 0
#include <vector>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long double ld;

int main()
{
	ld a,b;cin >> a >> b;
	long long r = a * b;
	cout << r;
    return 0;
}


Measured memory_bytes: 3196
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;++i)
#include<string>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<int, int>P;
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; }
//max=({});
//条件式が真ならwhileの中身を回し続ける
//printf("%d\n", ans);

//pairの入力
//vector<pair<ll, ll>>work(n);
//rep(i, n) {
//	ll a, b;
//	cin >> a >> b;
//	work[i] = make_pair(a, b);
//}

int g[15][15];
const int INF = 1001001001;
const int dx[4] = { -1,0,1,0 };
const int dy[4] = { 0,-1,0,1 };

//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

ll lcm(ll x, ll y) {
	if (x == 0 || y == 0)return 0;
	return (x / gcd(x, y) * y);
}

//素因数分解
vector<pair<ll, int>>factorize(ll n) {
	vector<pair<ll, int>>res;
	for (ll i = 2;i * i <= n;++i) {
		if (n % i)continue;
		res.emplace_back(i, 0);
		while (n % i == 0) {
			n /= i;
			res.back().second++;
		}
	}
	if (n != 1)res.emplace_back(n, 1);
	return res;
}

int dp[1010][1010];
int bingo[3][3];
bool flag[3][3];
int cnt[2][105];
int n, ans = 0;

int main() {
	int i, j;
	cin >> n;
	for (i = 0; i < 2; ++i)
		for (j = 1; j <= n; ++j) {
			cin >> cnt[i][j];
			cnt[i][j] += cnt[i][j - 1];
		}
	for (i = 1; i <= n; ++i)
		ans = max(ans, cnt[0][i] + cnt[1][n] - cnt[1][i - 1]);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
while True:
    h, w = map(int, input().split())
    if w == h == 0:
        break
    
    for i in range(h):
        for j in range(w):
            if (i + j) % 2 == 0:
                print("#", end="")
            else:
                print(".", end="")
        print()
    print()


Measured memory_bytes: 7004
#include<stdio.h>
int main(){
	int a,b,r,tmp;
	scanf("%d%d",&a,&b);
	if(a<b){
		tmp=a;
		a=b;
		b=tmp;
	}
	r=a%b;
	while(r!=0){
		a=b;
		b=r;
		r=a%b;
	}
	printf("%d\n",b);
	return 0;
}


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

class Program
{
    static void Main(string[] args)
    {
        int x = crI();
        while (!IsPrime(x)) x++;
        Console.WriteLine(x);
    }

    public static bool IsPrime(int num)
    {
        if (num < 2) return false;
        else if (num == 2) return true;
        else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

        double sqrtNum = Math.Sqrt(num);
        for (int i = 3; i <= sqrtNum; i += 2)
        {
            if (num % i == 0)
            {
                // 素数ではない
                return false;
            }
        }

        // 素数である
        return true;
    }



    static int crI() { return int.Parse(Console.ReadLine()); }
    static int[] arrInt(){return Console.ReadLine().Split(' ').Select(v => int.Parse(v)).ToArray();}
    static long[] arrLong(){ return Console.ReadLine().Split(' ').Select(v => long.Parse(v)).ToArray(); }
    static string[] arrStr(){return Console.ReadLine().Split(' ').ToArray();}

}

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

int main() {
	string a, b, c;
	cin >> a >> b >> c;
	if (a.back() == b.front() && b.back() == c.front()){
		cout << "YES" << endl;
	}else{
		cout << "NO" << endl;
	}
	return 0;
}

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

using namespace std;

int main() {

	int n,a,b,c,d;
	cin >> n >> a >> b >> c >> d;

	int xx = n / a + (n%a==0? 0 : 1);
	int yy = n / c + (n%c == 0 ? 0 : 1);

	cout << min(xx*b,yy*d) << endl;

}


Measured memory_bytes: 3092
#include<iostream>
#include<cstdlib>

int main()
{
    int H, W, D, A;
    std::cin >> H >> W >> D;
    int i1[H*W+1], j1[H*W+1], s[H*W+1];
    
    for(int i=0; i<H; i++)
    {
        for(int j=0; j<W; j++)
        {
            std::cin >> A;
            i1[A] = i;
            j1[A] = j;
        }
    }

    for(int i=1; i<=D; i++)
    {
        for(int j=0; i+D*j<=H*W; j++)
        {
            s[i+D*j] = j==0 ? 0 : s[i+D*(j-1)]+abs(i1[i+D*(j-1)]-i1[i+D*j])+abs(j1[i+D*(j-1)]-j1[i+D*j]);
        }
    }
    
    int Q;
    std::cin >> Q;
    int L, R;
    
    for(int i=0; i<Q; i++)
    {
        std::cin >> L >> R;
        std::cout << s[R]-s[L] << std::endl;
    }
    
    return 0;
}



Measured memory_bytes: 2176
import sys
#from collections import deque
#from functools import *
#from fractions import Fraction as f
from copy import *
from bisect import *	
#from heapq import *
#from math import ceil
#from itertools import permutations ,product
 
def eprint(*args):
    print(*args, file=sys.stderr)
zz=1
 
#sys.setrecursionlimit(10**6)
if zz:
	input=sys.stdin.readline
else:	
	sys.stdin=open('input.txt', 'r')
	sys.stdout=open('all.txt','w')
di=[[-1,0],[1,0],[0,1],[0,-1]]
def inc(d,c,x=1):
	d[c]=d[c]+x if c in d else x
def bo(i):
	return ord(i)-ord('A')	
def li():
	return [int(xx) for xx in input().split()]
def fli():
	return [float(x) for x in input().split()]	
def comp(a,b):
	if(a>b):
		return 2
	return 2 if a==b else 0		
def gi():	
	return [xx for xx in input().split()]
def fi():
	return int(input())
def pro(a): 
	return reduce(lambda a,b:a*b,a)		
def swap(a,i,j): 
	a[i],a[j]=a[j],a[i]	
def si():
	return list(input().rstrip())	
def mi():
	return 	map(int,input().split())			
def gh():
	sys.stdout.flush()
def isvalid(i,j):
	return 0<=i<n and 0<=j<m and a[i][j]!="."
def bo(i):
	return ord(i)-ord('a')	
def graph(n,m):
	for i in range(m):
		x,y=mi()
		a[x].append(y)
		a[y].append(x)
def represent(n):
	s=""
	while n>0:
		s+=str(n%3)
		n//=3
	s=s[::-1]
	return s			

t=1
while t>0:
	t-=1
	a,b,c,d=mi()
	maxi=-10**19
	for i in a,b:
		for j in c,d:
			maxi=max(maxi,i*j)		
	print(maxi)					


Measured memory_bytes: 69256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
  string S;

  cin >> S;

  vector<int> count(26,0);

  bool ans=true;

  for(int i=0;i<S.size();i++){
    count.at((int)(S.at(i)-'a'))++;
  }
  
  for(int i=0;i<26;i++){
    if(count.at(i)%2==1) ans=false;
  }

  if(ans) cout << "Yes" << endl;

  else cout << "No" << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#include<string>
#include<math.h>
#include<numeric>
#include<complex>

using namespace std;
typedef long long ll;

#define REP(i,n) for(int i=0;i<n;++i)
#define FOR(i,a,b) for(int 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 pn(s) cout << (#s) << " " << (s) << endl

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

void printVector(vector<ll> A){
    cout << "[vector]" << endl;
    for(int i=0; i<A.size(); i++){
        cout << A[i] << " ";
    }
    cout << endl;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    // input
    int N;
    cin >> N;

    bool isExist = false;
    FOR(i, 0, 26){
        int rest = N - 4 * i;
        if(rest >= 0 && rest % 7 == 0){
            isExist = true;
        }
    }

    if(isExist){
        p("Yes");
    }else{
        p("No");
    }
    
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
   {int H[10000], W[10000], i, j, k, l;
    i = 0;
    while(1) {
       scanf("%d %d", &H[i], &W[i]);
       i++;
       if(H[i - 1] == 0 && W[i - 1] == 0)
          break;
    }
    for(j = 0; j < i - 1; j++) {
       for(k = 0; k < H[j] ; k++) {
          for(l = 0; l < W[j]; l++) {
             printf("#");
          }
          printf("\n");
       }
       printf("\n");
    }
    return 0;
}

Measured memory_bytes: 1808
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define req(i,n) for(int i = 1;i <=n;i++)
#define pai 3.14159265358979323846
const int INF = 1001001001;
typedef long long ll;
int A[3][3], N;
bool punched[3][3];
bool ok[3][3];
//using Graph = vector<vector<int>>;


const int MOD = 1000000007;
typedef pair<int,int> P;

//最大公約数
ll gcd(ll a,ll b){
	if (a%b == 0){
		return b;
	}
	else{
		return gcd(b,a%b);
	}

}

//最小公倍数
ll lcm(ll a,ll b){
	return a /gcd(a,b) * b;
}

//素数判定
bool is_prime(long long N) {
    if (N == 1) return false;
    for (long long i = 2; i * i <= N; ++i) {
        if (N % i == 0) return false;
    }
    return true;
}

// 素因数分解
vector<pair<long long, long long> > prime_factorize(long long n) {
    vector<pair<long long, long long> > res;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}

// 10進数から2進数
int binary(int bina){
    int ans = 0;
    for (int i = 0; bina>0 ; i++)
    {
        ans = ans+(bina%2)*pow(10,i);
        bina = bina/2;
    }
    return ans;
}









int main() {
 int n;
 cin >> n;
 if (n == 1) cout << 0 << endl;
 else cout << 1 << endl;
}


Measured memory_bytes: 3616
#include <cstdio>
#include <vector>
#include <stack>
#include <iostream>
#include <string>
#include <tuple>
#include <random>
#include <map>
#include <queue>
#include <set>
#include <complex>
#include <algorithm>
#include <cassert>
#include <iterator>
#include <numeric>
#include <cmath>

using namespace std;

typedef long double ld;
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;

const double eps = 1e-6;
const ll MOD = 1000000007;
const ll INF = 1e15;

int main() {
	ll N, K, Q;
	cin >> N >> K >> Q;
	vector<ll> A(N);
	vector<P> b(N);
	for (int i= 0;i < N;i++) {
		cin >> A[i];
		b[i] = P(A[i], i);
	}
	sort(A.begin(), A.end());
	sort(b.begin(), b.end());
	ll can = N - K + 1;
	ll ans = A[Q-1] - A[0];
	set<ll> div;
	div.insert(-1);
	div.insert(N);
	for (ll rm = 0;rm + Q < N;rm++) {
		div.insert(b[rm].second);
		bool ok = true;
		map<ll, ll> mp;
		ll cnt = 0;
		ll now = rm + 1;
		while (now < N && cnt < Q) {
			auto iter = div.lower_bound(b[now].second);
			ll right = *iter;
			iter--;
			ll left = *iter;
			ll can = max(0LL, (right - left - K));
			if (mp.find(left) == mp.end())
				mp[left] = 0;
			can = can - mp[left];
			mp[left]++;
			if (can > 0)
				cnt++;
			now++;
		}
		if (cnt == Q)
			ans = min(ans, A[now - 1] - A[rm + 1]);
	}
	cout << ans << endl;
	return 0;
}
/*
5 1 3
9 10 1 3 8
*/


Measured memory_bytes: 384
N = int(input())
ans = 0

l, m = [], []

for _ in range(N):
    s, t = input().split()
    t = int(t)
    l.append(s)
    m.append(t)

X = input()

idx = l.index(X)
for i in range(idx+1, N):
    ans += m[i]

print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include <functional>
#include<time.h>
#include <stack>
#include<iomanip>
using namespace std;
#define rep(i,a,n) for(int i=(a);i<(n);i++)
#define ll long long
#define llint long long int
#define reverse(v)  reverse(v.begin(), v.end());
#define Yes(ans) if(ans)cout<<"Yes"<<endl; else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl; else cout<<"NO"<<endl;
#define hei(a) vector<a>
#define whei(a) vector<vector<a>>
#define UF  UnionFind 
#define Pint pair<int,int>
#define Pll pair<llint,llint>
#define keta(a)  fixed << setprecision(a)
constexpr auto mod = 1000000007;
//辞書順はnext_permutation( begin( v ), end( v ) );やで！
const ll INF = (1LL << 63);


int main() {
	int a, b,c;
	cin >> a >> b >> c;
	int ans = 0;
	ans=(a + b - 1) / b * c;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3628
import java.util.LinkedList;
import java.util.Scanner;

class Main {
	int n;
	LinkedList<Integer> a;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		Main m = new Main(sc);
		m.solve();
		sc.close();
	}

	Main(Scanner sc) {
		n = sc.nextInt();
		a = new LinkedList<Integer>();
		for(int i=1;i<n;i++){
			a.add(sc.nextInt());
		}
	}

	void solve() {
		int[] bukaCnt = new int[n];
		while(a.size()>0){
			bukaCnt[a.pollFirst()-1]++;
		}
		for(int i:bukaCnt){
			System.out.println(i);
		}
	}
}

Measured memory_bytes: 66904
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for(ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF (1ll << 60)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
using vl = vector<ll>;
using vvl = vector<vl>;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
using ll = long long;
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

void print(const std::vector<int> &v) {
    std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
    std::cout << std::endl;
}
class UnionFind {
  private:
    vector<int> parent;
    vector<int> height;
    vector<int> m_size;

  public:
    UnionFind(int size_) : parent(size_), height(size_, 0), m_size(size_, 1) {
        for(int i = 0; i < size_; ++i)
            parent[i] = i;
    }
    void init(int size_) {
        parent.resize(size_);
        height.resize(size_, 0);
        m_size.resize(size_, 0);
        for(int i = 0; i < size_; ++i)
            parent[i] = i;
    }
    int find(int x) {
        if(parent[x] == x)
            return x;
        return parent[x] = find(parent[x]);
    }
    void unite(int x, int y) {
        x = find(x);
        y = find(y);
        if(x == y)
            return;
        int t = size(x) + size(y);
        m_size[x] = m_size[y] = t;
        if(height[x] < height[y])
            parent[x] = y;
        else
            parent[y] = x;
        if(height[x] == height[y])
            ++height[x];
    }
    bool same(int x, int y) { return find(x) == find(y); }
    int size(int x) {
        if(parent[x] == x)
            return m_size[x];
        return size(parent[x] = find(parent[x]));
    }
};

int main() {
    ll N, M;
    cin >> N >> M;
    vector<ll> K(N);
    vector<vector<ll>> L(N);
    // Union Findかとおもったけど
    //言語ごとのグループをつくってuniteしていく？
    auto tree = UnionFind(N + M);
    REP(i, N) {
        cin >> K[i];
        REP(j, K[i]) {
            ll l;
            cin >> l;
            l--;
            tree.unite(i, N + l);
            L[i].push_back(l);
        }
    }
    if(tree.size(0) == N + M) {
        cout << "YES" << endl;
        return 0;
    }
    int cnt = 0;
    for(int i = N; i < N + M; i++) {
        if(tree.size(i) == 1) {
            cnt++;
        }
    }
    if(tree.size(0) == N + M - cnt) {
        cout << "YES" << endl;
        return 0;
    }
    cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 8832
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string a,b;
	cin>>a>>b;
	int l1=a.size(),l2=b.size();
	int lma=max(l1,l2),lmi=min(l1,l2);
	for(int i=0;i<lmi;i++)
		cout<<a[i]<<b[i];
	if(l1>l2)
		for(int i=lmi;i<lma;i++)
			cout<<a[i];
	else
		for(int i=lmi;i<lma;i++)
			cout<<b[i];
	cout<<endl;
	return 0;
}

Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

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

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

fn is_ok(s: &[char]) -> bool {
    let mut val = 0;
    for i in 0..s.len() {
        if s[i] == '(' {
            val += 1;
        } else {
            val -= 1;
        }
        if val < 0 {
            return false;
        }
    }
    if val == 0 {
        true
    } else {
        false
    }
}

fn main() {
    input! {
        _n: usize,
        s: chars,
    }
    let mut s = s;
    while !is_ok(&s) {
        let mut val = 0;
        let mut inserted = false;
        for i in 0..s.len() {
            if s[i] == '(' {
                val += 1;
            } else {
                val -= 1;
            }
            if val < 0 {
                s.insert(0, '(');
                inserted = true;
                break;
            }
        }
        if !inserted {
            if val > 0 {
                s.push(')');
            }
        }
    }
    for i in 0..s.len() {
        print!("{}", s[i]);
    }
    println!();
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int64_t MOD=1000000007;
const long long INF = 1LL<<60;

int main() {
  int64_t N,ans=0; cin>>N;
  vector<int64_t> S(N);
  rep(i,N) cin>>S.at(i);
  for(int i=0;i<N-2;i++){
    for(int j=i+1;j<N-1;j++){
      for(int k=j+1;k<N;k++){
        auto a=S.at(i), b=S.at(j), c=S.at(k);
        if(a!=b&&b!=c&&c!=a&&a+b>c&&b+c>a&&c+a>b) ans++;
      }
    }
  }
  cout<<ans;
}


Measured memory_bytes: 3624
#include<iostream>
using namespace std;
int main()
{
	int n,m;
	cin>>n>>m;
	int x=0,y=100005;
	for(int i=0;i<m;i++){
		int a,b;
		cin>>a>>b;
		if(x<a) x=a;
		if(y>b) y=b;
	}
	int sum=y-x;
	if(sum<-1) sum=-1; 
	cout<<sum+1<<endl;
} 

Measured memory_bytes: 256
#define  _CRT_SECURE_NO_WARNINGS
#pragma comment (linker, "/STACK:526000000")

#include "bits/stdc++.h"

using namespace std;
typedef string::const_iterator State;
#define eps 1e-11L
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL

#define MOD 998244353LL
#define seg_size 262144 * 4LL
#define pb push_back
#define mp make_pair
typedef long long ll;
#define REP(a,b) for(long long (a) = 0;(a) < (b);++(a))
#define ALL(x) (x).begin(),(x).end()

unsigned long xor128() {
	static unsigned long x = 123456789, y = 362436069, z = 521288629, w = time(NULL);
	unsigned long t = (x ^ (x << 11));
	x = y; y = z; z = w;
	return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}
void init() {
	iostream::sync_with_stdio(false);
	cout << fixed << setprecision(20);
}

#define int ll

int dfs(string a,string b,int c) {
	if (c >= a.length()) return 0;
	if (a[c] == b[c]) {
		return dfs(a, b, c + 1);
	}
	int target = b[c] - a[c] + 10;
	target %= 10;
	int ans = 1e9;
	for (int q = c; q < a.length(); ++q) {
		a[q] += target;
		if (a[q] > '9') a[q] -= 10;
		ans = min(ans, dfs(a, b, c + 1) + 1);
	}
	return ans;
}

void solve(){
	while (true) {
		int k;
		cin >> k;
		if (k == 0)return;
		string a, b;
		cin >> a >> b;
		cout << dfs(a,b,0) << endl;
	}
}

#undef int

int main() {
	init();
	solve();
}


Measured memory_bytes: 3136
N = int(input())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))

from itertools import groupby, accumulate, product, permutations, combinations

def solve(P,Q):
    if P==Q:
        return 0
    ans = []
    for i,p in enumerate(permutations(range(1,N+1),N)):
        if list(p)==P or list(p)==Q:
            ans.append(i)
    ans = ans[1]-ans[0]
    return ans
print(solve(P,Q))

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

int main() {
  string S;
  cin >> S;
  
  int count = 0;
  int max = 0;
  
  for(int i = 0; i < S.size(); i++){
    if (S.at(i) == 'A' || S.at(i) == 'C' || S.at(i) == 'G' || S.at(i) == 'T'){
      count++;
      if (count > max) max = count;
    }
      else count = 0;
  }
    cout << max << endl;
}

Measured memory_bytes: 256
menu,fir_digi=[int(input()) for i in range(5)],[]
for i in range (5):
    fir_digi.append(menu[i]%10)
while min(fir_digi)==0:
    fir_digi[fir_digi.index(0)]=10
for i in range (5):
    if i!=fir_digi.index(min(fir_digi)) and fir_digi[i]!=10:
            menu[i]=int(menu[i]/10)*10+10
print(sum(menu))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define ll long long
#define ull unsigned long long
#define ld long double
#define zeros(x) x^(x-1)&x
#define pii pair<ll,ll>
#define cd complex<double>
#define dbg(x) cerr<<x<<endl;
#define Nmax 500005
using namespace std;

ll A[55], B[55], res, n;
set<int> S;
bool fr[55][55];

bool _try(ll res){
    memset(fr,0,sizeof(fr));
    for (int i=1;i<=n;i++) fr[i][A[i]] = 1;
    for (int i=50;i>=1;i--){
        if (res & (1LL<<i)){
            for (int a=1;a<=n;a++){
                for (int b=1;b<=50;b++){
                    fr[a][b%i] |= fr[a][b];
                }
            }
        }
    }
    for (int i=1;i<=n;i++){
        if (!fr[i][B[i]])
            return 0;
    }
    return 1;
}

int main()
{
    cin >> n;
    res = (1LL<<51) - 2;
    for (int i=1;i<=n;i++) cin >> A[i];
    for (int i=1;i<=n;i++) cin >> B[i];
    if (!_try(res)){
        cout << "-1\n";
        return 0;
    }

    for (int i=50;i>=1;i--){
        res ^= (1LL << i);
        if (!_try(res)) res ^= (1LL << i);
    }

    cout << res << '\n';

    return 0;
}


Measured memory_bytes: 256
def main():
  ans = 0
  n = int(input())
  if n == 1:
    ans = 1
  else:
    for i in range(1, n//2 + 1):
      for j in range(2, 10):
        if ans < i**j <= n :
          ans = i**j
  print(ans)

if __name__ == '__main__':
  main()

Measured memory_bytes: 2940
/*  AC祈願アンコウ
   　／￣＼
   ○    ／￣￣￣＼ヘ
    　 /・　 ・　 ＼>   
    ／￣￣￣＼　　  Ｖ| 
   ｜  ―――  ｜      ｜|
    ＼＿＿＿／　　  ∧|
    　　＼　　　　／
    　　　￣￣￣￣
*/

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

typedef int64_t ll;
static const int MOD = 1000000007;
//static const int INF = 2147483647;
//static const long long INF = 9223372000000000000;
//static const long long INF = 9223372000000000000/2;
//static const int INF = 1000010000;
//int dx4[4] = {0,1,0,-1}, dy4[4] = {-1,0,1,0};
//int dx5[5] = {-1,0,0,0,1}, dy5[5] = {0,-1,0,1,0};
//int dx8[8] = {-1,0,1,1,1,0,-1,-1}, dy8[8] = {1,1,1,0,-1,-1,-1,0};
//int dx9[9] = {-1,0,1,1,1,0,-1,-1,0}, dy9[9] = {1,1,1,0,-1,-1,-1,0,0};
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define FI first
#define SE second
#define NP next_permutation
#define PQ priority_queue
#define UB upper_bound
#define LB lower_bound
#define SZ(a) signed((a).size())
#define LEN(a) signed((a).length())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).begin(),(c).end());reverse((c).begin(),(c).end());
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REP1(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREP1(i,x) for(int i=((int)(x));i>0;i--)
#define ALL(x) (x).begin(),(x).end()
#define YESNO(x) puts((x)?"YES":"NO")
#define YesNo(x) puts((x)?"Yes":"No")
 
signed main(){
    int a,b,c;
    cin >> a >> b >> c;
    if((!(a%2)) || (!(b%2)) || (!(c%2))) puts("0");
    else printf("%lld\n",min(a*b,min(b*c,c*a)));
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#define ll long long
using namespace std;

int main(void){
    
    int a, b, c,cnt5=0,cnt7=0;
    cin >> a >> b >> c;
    if(a == 5){
        cnt5++;
    }else if(a == 7){
        cnt7++;
    }
    if(b == 5){
        cnt5++;
    }else if(b == 7){
        cnt7++;
    }
    if(c == 5){
        cnt5++;
    }else if(c == 7){
        cnt7++;
    }
    if(cnt5 == 2 && cnt7 == 1){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }

    
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<iomanip>
#include<set>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define brep(index,num) for(int index=num-1;index>=0;index--)
#define brep1(index,num) for(int index=num;index>0;index--)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int main(){
	int N;
	ll K,A[200001];
	ll Asum[200001]={};
	map<ll,int> sumnum;
	scan(N>>K);
	rep(i,N){
		scan(A[i]);
		A[i]--;
		A[i]%=K;
		Asum[i+1]=Asum[i]+A[i];
		Asum[i+1]%=K;
	}
	ll ans=0;
	rep(i,N+1){
		if(i>=K) sumnum[Asum[i-K]]--;
		ans+=sumnum[Asum[i]];
		sumnum[Asum[i]]++;
	}
	prin(ans);
	return 0;
}


Measured memory_bytes: 15872
/*
 _____ _             _              _           _ 
|_   _| |__   ___   / \   _ __  ___| |__  _   _| |
  | | | '_ \ / _ \ / _ \ | '_ \/ __| '_ \| | | | |
  | | | | | |  __// ___ \| | | \__ \ | | | |_| | |
  |_| |_| |_|\___/_/   \_\_| |_|___/_| |_|\__,_|_|                                                

*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
#define ll          long long
#define pb          push_back
#define ppb         pop_back
#define	endl		'\n'
#define mii         map<ll,ll>
#define msi         map<string,ll>
#define mis         map<ll, string>
#define rep(i,a,b)    for(ll i=a;i<b;i++)
#define repr(i,a,b) for(ll i=b-1;i>=a;i--)
#define trav(a, x) 	for(auto& a : x)
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define vii         vector<pair<ll, ll>>
#define vs          vector<string>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll)x.size()
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define max(a,b)	(a>b?a:b)
#define min(a,b)	(a<b?a:b)

/*	For Debugging	*/
#define DEBUG 		cerr<<"\n>>>I'm Here<<<\n"<<endl;
#define display(x) trav(a,x) cout<<a<<" ";cout<<endl;
#define what_is(x)  cerr << #x << " is " << x << endl;

std::mt19937_64 rng(std::chrono::steady_clock::now().time_since_epoch().count());
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define TIME        cerr << "\nTime elapsed: " << setprecision(5) <<1000.0 * clock() / CLOCKS_PER_SEC << "ms\n";
#define DECIMAL(n)  cout << fixed ; cout << setprecision(n);
#define FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace __gnu_pbds;
using namespace std;
#define PI 3.141592653589793
#define N  200005
vi seg(4*N);
void build(ll cur,ll st,ll end)
{
	if(st==end)
	{
		seg[cur]=0;
		return;
	}
	ll mid=(st+end)>>1;
	build(2*cur,st,mid);
	build(2*cur+1,mid+1,end);
	seg[cur]=max(seg[2*cur],seg[2*cur+1]);	/*  1-change here  */
}
ll query(ll cur,ll st,ll end,ll l,ll r)
{
	if(l<=st&&r>=end)
	return seg[cur];
	if(l>r || r<st||l>end)
	return 0;                           /*  2-change here  */
	ll mid=(st+end)>>1;
	ll ans1=query(2*cur,st,mid,l,r);
	ll ans2=query(2*cur+1,mid+1,end,l,r);
	return max(ans1,ans2);                 /*  3-change here  */
}
void update(ll cur,ll st,ll end,ll pos,ll upd)
{
	if(st==end)
	{
		// a[pos]+=upd;					/*  4-change here  */
		seg[cur]+=upd;					/*  5-change here  */
		return;
	}
	ll mid=(st+end)>>1;
	if(st<=pos&&pos<=mid)
		update(2*cur,st,mid,pos,upd);
	else
		update(2*cur+1,mid+1,end,pos,upd);
	seg[cur]=max(seg[2*cur],seg[2*cur+1]);	/*  6-change here  */
}
void solve()
{
	ll n;
	cin>>n;
	vi v(n),a(n);
	rep(i,0,n)
	cin>>v[i];
	rep(i,0,n)
	cin>>a[i];
	build(1,1,n);
	repr(i,0,n)
	{
		update(1,1,n,v[i],query(1,1,n,v[i]+1,n)+a[i]);
	}
	cout<<query(1,1,n,1,n)<<endl;

	return;
}
int main()
{
	FAST
	int TESTS=1;
//	cin>>TESTS;
	while(TESTS--)
	{
		solve();
	}
	TIME
	return 0;
}

Measured memory_bytes: 9600
#include <iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<cstring>
#include<string>
#include <set>
#include <cassert>
#include<cmath>
#include<climits>
#include<iomanip>
using namespace std;
#define MOD 1000000007
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
const long long INF = 1LL << 60;


template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

class UnionFind {
	vector<int> data;
public:
	UnionFind(int size) : data(size, -1) { }
	bool unionSet(int x, int y) {
		x = root(x); y = root(y);
		if (x != y) {
			if (data[y] < data[x]) swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
		return x != y;
	}
	bool findSet(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};

int find(vector<long long> &arr, long long obj) {
	if (arr[arr.size() - 1] < obj)return arr.size()-1;
	if (arr[0] > obj)return -1;

	int min = 0; int max = arr.size() - 1;
	for (int i = 0; i < arr.size(); i++) {
		if (arr[min+(max-min) / 2] > obj) {
			max = min + (max - min) / 2;
		}
		else {
			min = min + (max - min) / 2;
		}
		if (max - min == 1) {
			return min;
		}
	}


}

//約数求める //約数
void divisor(ll n,vector<ll> &ret) {
	for (ll i = 1; i * i <= n; i++) {
		if (n % i == 0) {
			ret.push_back(i);
			if (i * i != n) ret.push_back(n / i);
		}
	}
	sort(ret.begin(), ret.end());
	
}
//階乗
long long factorial(long long n, long long mod) {
	long long ret = 1;
	for (long long i = 1; i <= n; i++) {
		ret = (ret * i) % mod;
	}
	return ret;
}
//モジュラ逆数
long long inv_mod(long long n, long long mod) {
	long long a = n % mod, b = mod - 2, ret = 1;
	while (b > 0) {
		if (b & 1) ret = (ret * a) % mod;
		a = (a * a) % mod;
		b >>= 1;
	}
	return ret;
}

long long nPr(long long n, long long r, long long mod) {
	long long ret = 1;
	for (long long i = n; i >= n - r + 1; i--) {
		ret = ret * (i % mod) % mod;
	}
	return ret;
}

long long nCr(long long n, long long r, long long mod) {
	return nPr(n, r, mod) * inv_mod(factorial(r, mod), mod) % mod;
}

bool compare_by_b(pair<ll, ll> a, pair<ll, ll> b) {//降順second
	if (a.second != b.second) {
		return a.second > b.second;
	}
	else {
		return a.first > b.first;
	}
}

bool compare_by_a(pair<ll, ll> a, pair<ll, ll> b) {//降順first
	if (a.first != b.first) {
		return a.first > b.first;
	}
	else {
		return a.second > b.second;
	}
}

ll gcd(ll m, ll n){
	if (n == 0)return m;
	return gcd(n, m%n);
}//gcd


int main() {
	string s;
	cin >> s;
	if (s[0] != 'A') {
		cout << "WA";
		return 0;
	}
	int flag = 0;
	for(int i=1;i<s.size();i++){
		if ((!(s[i] - 'a' >= 0 && s[i] - 'z' <= 25))) {
			if (s[i] == 'C'&&i >= 2 && i < s.size() - 1&&flag==0) {
				flag = 1;
			}
			else {
				cout << "WA";
				return 0;
			}
		}
	}
	if (flag == 1) {
		cout << "AC";
	}
	else {
		cout << "WA";
	}


	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
ll dp[100005];
int n,w[105],ww;
ll v[105];
int main(){
	cin>>n>>ww;
	for(int i=1;i<=n;i++) cin>>w[i]>>v[i];
	for(int i=0;i<100005;i++) dp[i] = -1e18;
	dp[0] = 0;
	for(int i=1;i<=n;i++){
		for(int j=ww;j>=w[i];j--){
			dp[j] = max(dp[j],dp[j-w[i]]+v[i]);
		}
	}
	ll ans = 0;
	for(int i=0;i<=ww;i++) ans=max(ans,dp[i]);
cout<<ans<<endl;}

Measured memory_bytes: 1024
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <numeric>
#include <string.h>
#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define repn(i, x) for (int i = 1; i <= (int)(x); i++)
#define repr(i, x) for (int i = ((int)(x) - 1); i >= 0; i--)
#define reprn(i, x) for (int i = ((int)(x)); i > 0; i--)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long int64;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const long long  INFL = 1e18;
const int MOD = 1000000007;
void solve() {
	int64 n, k; cin >> n >> k;
	int64 r, s, p; cin >> r >> s >> p;
	string t; cin >> t;
	vector<bool> exs(t.size());
	int64 ans = 0;
	rep (i, n) {
		if (i < k || t[i - k] != t[i] || !exs[i - k]) {
			if (t[i] == 'r') {
				ans += p;
			} else if (t[i] == 's') {
				ans += r;
			} else {
				ans += s;
			}
			exs[i] = true;
		}
	}	
	cout << ans << endl;
	return;
}

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

Measured memory_bytes: 512
#include <stdio.h>
#include <math.h>
 
using namespace std;
 
int main(){
    int n;
    double students[1000] = {0},sum,m,div;
 
    while(true){
        scanf("%d",&n);
        if(n == 0) break;
        div = sum = 0;
        for(int i = 0; i < n; i++){
            scanf("%lf",&students[i]);
            sum += students[i];
        }
        m = sum/n;
        for(int i = 0; i < n;i++){
            div += (students[i] - m)*(students[i] - m);
            students[i] = 0;
        }
        printf("%.8lf\n",sqrt(div/n));
    }
}



Measured memory_bytes: 2628
n,k=map(int,input().split())
P=list(map(int,input().split()))
for i in range(n):
	P[i]-=1
C=list(map(int,input().split()))
ANS=-float('inf')
for i in range(n):
    snp=P[i]
    r=C[snp]
    L=[r]
    c=0
    np=P[snp]
    while True:
        if c==k-1:
            ANS=max(max(L),ANS)
            break
        if np==snp:
            y=k%(c+1)
            m=k//(c+1)
            if y==0:
                ANS=max(max(L),max(L)+(m-1)*L[-1],ANS)
                break
            else:
                #print(m,y)
                #print(L)
                ANS=max(max(L),max(max(L[:y]),0)+m*L[-1],ANS)
                break
        r+=C[np]
        L.append(r)
        np=P[np]
        c+=1
print(ANS)

Measured memory_bytes: 83232
S = input()

min_result = 9999999999

for i in range(len(S)-2):
    s = int(S[i]+S[i+1]+S[i+2])
    if s >= 753:
        result = s - 753
    else:
        result = 753 - s
    if min_result >= result:
        min_result = result

print(min_result)

Measured memory_bytes: 3060