akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.NavigableMap;
import java.util.TreeMap;

import static java.lang.Integer.parseInt;

public class Main {

	static final NavigableMap<Integer, Integer> ages = new TreeMap<Integer, Integer>() {
		{
			put(0, 0);
			put(10, 1);
			put(20, 2);
			put(30, 3);
			put(40, 4);
			put(50, 5);
			put(60, 6);
		}
	};

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = "";

		while ((line = br.readLine()) != null && !line.isEmpty()) {
			int n = parseInt(line);
			if (n == 0) break;

			int[] count = new int[7];
			for (int i = 0; i < n; i++) {
				count[ages.floorEntry(parseInt(br.readLine())).getValue()]++;
			}
			for (int c : count) System.out.println(c);
		}
	}
}

Measured memory_bytes: 55356
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string s;
  cin>>s;
  int n=s.size();
  long long int cnt=0,w=n-1;
  
  for(int i=n-1;i>=0;i--){
    if(s[i]=='B'){
      cnt+=w-i;
      w--;
      s[i]='W';
    }
  }
  
  cout<<cnt;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,count=0;
  string s,t;
  cin>>n>>s>>t;
  for(int i=1; i<=n; i++){
    if(s.substr(n-i)==t.substr(0,i)){
      count=i;
    }
  }
  cout<<n*2-count<<'\n';
  return 0;
}



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

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

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

public class Main {
	
	int time = 0;
	int temp = 0;
	
	void run() {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] c = new int[N-1];
		int[] s = new int[N-1];
		int[] f = new int[N-1];
		for(int i = 0; i < N-1; i++) {
			c[i] = sc.nextInt();
			s[i] = sc.nextInt();
			f[i] = sc.nextInt();
		}
		for(int i = 0; i < N-1; i++) {
			time = s[i] + c[i]; 
			for(int j = i+1; j < N-1; j++) {
				if(time < s[j]) time = s[j]+c[j];
				else{
					temp = time % f[j];
					if(temp != 0) time += f[j] - temp + c[j];
					else time += c[j];
				}
			}
			System.out.println(time);
			time = 0;
		}
		System.out.println(0);
		sc.close();
	}

	void debug(Object... o) {
		System.out.println(Arrays.deepToString(o));
	}

	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 26608
num = int(input())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
first = second = third = inf = 0.00000
for i in range(num):
    dif = x[i] - y[i]
    first = first + abs(dif)
    second = second + dif ** 2
    third = third + abs(dif) ** 3
    inf = max(inf, abs(dif))
print('{:.6f}'.format(first))
print('{:.6f}'.format(second ** 0.5))
print('{:.6f}'.format(third ** 0.333333333333333333))
print('{:.6f}'.format(inf))


Measured memory_bytes: 5644
import java.util.Scanner;

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

    System.out.println((C-1)/B<=(A-1)/D ? "Yes" : "No");
  }
}

Measured memory_bytes: 27044
#include <iostream>
#include <math.h>

using namespace std;

int main(void){
    
    
    int n;
    cin >> n;
    int l[n],r[n];
    int i;
    for(i=0;i<n;++i)cin >> l[i] >> r[i];
    int ans=n;
    for(i=0;i<n;++i)ans+=r[i]-l[i];
    cout << ans;
    
    
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define mod 1000000007
#define max_char 128
#define pb push_back
#define ff first
#define ss second
#define mp make_pair
#define lbd lower_bound
#define ubd upper_bound
#define PI 3.141592653589793238
#define pf push_front
#define all(x) x.begin(),x.end()
#define input(arr,n) for(ll c1=0;c1<n;c1++)cin>>arr[c1];
#define rep(i,a,n) for( ll i=a ; i<n ; i++)
#define mems(x, y) memset(x, y, sizeof(x))
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
//cout<<"Case #"<<v1+1<<": ";
 
ll power(ll base,ll pow, ll mo)
{
   ll res=1;
   while(pow)
   {     
        if (pow%2!=0)  res=(res*base)%mo;
        base=(base*base)%mo;
        pow/=2;
   }
   return res;
}
 
 
int main()
{
    fastio
	
	ll t,i,j,x;
	
	string s;
	cin>>s;
	if(s=="ARC")
	cout<<"ABC";
	else cout<<"ARC";
    return 0;
}

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

ad = {}
for i in range(n) :
  if a[i] in ad :
    ad[a[i]] += 1
  else :
    ad[a[i]] = 1

ans = 0
for v in ad.values() :
  ans += v*(v-1)//2
  
for i in range(n) :
  v = ad[a[i]]
  print(ans-v*(v-1)//2+(v-1)*(v-2)//2)

Measured memory_bytes: 26268
#include <cstdio>
#include <string>
#include <cmath>
#include <string>
#include <algorithm>
#include <iostream>
#include <map>
#include <vector>
#include <iomanip>
#include <tuple>
#include <queue>
using namespace std;
typedef long long ll;
#define rep(i, a, n) for (int i=a;i<n;++i)
#define repeq(i, a, n) for(int i=a;i<=n;++i)
#define per(i, a, n) for (int i=n-1; i>=a;--i)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()

// 
int N, M;
int ans = 0;
vector<pair<int, int>> v;

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

    v.resize(M);

    rep(i, 0, M){
        int a, b;
        cin >> a >> b;
        v[i] = make_pair(b, a);
    }
    sort(all(v));

    int t = 0;
    rep(i, 0, M){
        if(t <= v[i].second){
            ++ans;
            t = v[i].first;
        }
    }

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




Measured memory_bytes: 1024
# -*- coding: utf-8 -*-

n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

a.insert(0, -1)
b.insert(0, -1)
c.insert(0, -1)

#print(a)
#print(b)
#print(c)

f = 0
for i in range(1,n+1):
    taste_a = a[i]
#    print("taste: "+str(taste_a))
    f += b[taste_a]
#    print("full: "+str(f))
    
    if a[i]-a[i-1] == 1:
#        print(str(i-1)+"番目の後に"+str(i)+"番目を食べました")
        f += c[taste_a-1]

print(f)


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

int main() {
    ios::sync_with_stdio(false);
    int a, b;
    cin >> a >> b;
    vector< set<int> > tab(a+1);
    for(int i = 0; i < b; i++){
        int c,d;
        cin >> c >> d;
        tab[c].insert(d);
        tab[d].insert(c);
    }
    int tot = 0;
    bool verif = true;
    while(verif){
        bool ok = false;
        for(int i = 1; i <= a; i++){
            if(tab[i].size() == 1){
                ok = true;
                tot++;
                for(int a : tab[i]){
                    tab[a].erase(i);
                }
                tab[i].clear();
            }
        }
        if(ok == false) break;
    }
    cout << tot << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
#define ll long long
#define ull unsigned long long
#define N 100005
#define mod 1000000007
#define boost ios_base::sync_with_stdio(false);cin.tie(0)
#define prec(n) fixed<<setprecision(n)

#define mii unordered_map<int,int>
#define mll unordered_map<ll,ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define fi  first

#define se second
#define pb push_back
#define mp make_pair
#define pp pop_back
#define vii vector<int>
#define vll vector<ll>
#define vpp vector<pii>
#define all(c) c.begin(),c.end()
#define tr(it,c) for(it = c.begin() ; it!=c.end() ; it++)
int inf = INT_MAX ;
ll modulo(ll num,ll MOD=mod){ return ((num%MOD)+MOD)%MOD;} // for negative integer
ll power(ll b,ll e,ll MOD=mod){ll ans=1; while(e){if(e%2) ans=(ans*b)%MOD; b=(b*b)%MOD; e/=2;} return ans;}
ll inv(ll num,ll MOD=mod){ return power(modulo(num),MOD-2,MOD); }
ll gcd(ll a,ll b){ return ((b==0) ? a:gcd(b,a%b));}
int ans[N][3],arr[N][3];

int main(){
	boost;
	int n;
	cin>>n;
	
	for(int i=0;i<n;i++){
		cin>>arr[i][0]>>arr[i][1]>>arr[i][2];
	}
	
	for(int i = n-1;i>=0;i--){
		if(i==n-1){
			ans[i][0] = arr[i][0];
			ans[i][1] = arr[i][1];
			ans[i][2] = arr[i][2];
		}else{
			ans[i][0] = max(ans[i+1][1],ans[i+1][2]) + arr[i][0];
			ans[i][1] = max(ans[i+1][0],ans[i+1][2]) + arr[i][1];
			ans[i][2] = max(ans[i+1][0],ans[i+1][1]) + arr[i][2];
		}
	}
	
	cout<<max(ans[0][0],max(ans[0][1],ans[0][2]));
	return 0;
}



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

#define loop(n, i) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define HERE cout << "HERE: " << __LINE__ << endl;
#define INSP(v) cout << v << " at " << __LINE__ << endl;

using namespace std;
typedef long long ll;

int is_include(vector<int> as, vector <int> bs) {
    for (auto a : as) {
        if (find(all(bs), a) == bs.end()) return 0;
    }
    return 1;
}

int main()
{
    int n;
    while (cin >> n, n) {
        vector<vector<int>> pss;
        pss.resize(n);
        loop (n, i) {
            int m; cin >> m;
            pss[i].resize(m);
            loop(m, j) {
                int tmp; cin >> tmp;
                pss[i][j] = tmp;
            }
        }
        vector<int> ks;
        int k; cin >> k;
        loop (k, i) { int tmp; cin >> tmp; ks.push_back(tmp); }

        int ans = -1;
        int count = 1;
        for (auto ps : pss) {
            if (is_include(ks, ps)) {
                if (ans == -1) {
                    ans = count;
                } else {
                    ans = -1;
                    break;
                }
            }
            count++;
        }
        cout << ans << endl;
    }
}

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

int main() {
  int N, i, count = 0, maxh = 0;
  cin >> N;
  
  vector<int> H(N);
  for(i = 0; i < N; i++){
    cin >> H.at(i);
  }
  
  for(i = 0; i < N; i++){
    if(H.at(i) >= maxh){
      maxh = H.at(i);
      count++;
    }
  }
  
  cout << count << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
#define endl '\n'
#define f first
#define s second
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

using ld = long double;
using ll = long long;
using pii = pair <int,int>;
using pll = pair <ll,ll>;
using vi = vector <int>;
using vll = vector <ll>;
using vpii = vector <pii>;
using vpll = vector<pll>;
using vs = vector <string>;


int main(){
  fastio;

  string str;
  cin >> str;
  
  int cnt = 0;
  int ans = 0;

  for(char c:str){
    if(c == 'R')
      cnt++;
    else{
      ans = max(ans,cnt);
      cnt = 0;
    }
  }
      ans = max(ans,cnt);

  cout << ans << endl;

  
  return 0;
}

Measured memory_bytes: 3644
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <deque>
#include <queue>
#include <set>
#include <functional>
#include <cmath>
#include <set>
#include <map>


//マクロ
#define REP(i,n) for(int i=0; i<(int)(n); ++i)
#define REPS(i,n) for(int i=1; i<=(int)(n); ++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 FOR(i,s,e) for(int i=(int)(s); i<(int)(e); ++i)
#define RFOR(i,s,e) for(int i=(int)(e)-1; i>=(int)(s); --i)
#define All(a) (a).begin(),(a).end()
#define RAll(a) (a).rbegin(),(a).rend()
#define dump(x)  cerr << #x << " = " << (x) << endl;

//定数
#define INF 1e9
#define INFL 1e18
#define MOD (int)(1e9+7)

typedef long long ll;
typedef unsigned long long ull;
using namespace std;
using vi = vector<int>;
using vii = vector<vi>;
using vs = vector<string>;
using pii = pair<int, int>;
using Graph = vector<vector<int>>;

//とりあえず書いておく変数
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };

//今回の変数

//使用する関数
template<class T>bool chmax(T &a, const T &b) {
	if (a < b) { a = b; return 1; }
	return 0;
}
template<class T>bool chmin(T &a, const T &b) {
	if (a > b) { a = b; return 1; }
	return 0;
}

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

	ll n;
	cin >> n;

	string s;
	while (n !=0) {
		n--;
		s += 'a' + n % 26;
		n /= 26;
	}
	reverse(All(s));
	cout << s << endl;
}

Measured memory_bytes: 3608
from itertools import product

def solve():
    N = int(input())
    S = [0 if i == 'o' else 1 for i in input()]
    
    for i, j in product(range(2), repeat=2):
        pat = [i, j] + [0]*(N - 2)
        for k in range(2, N):
            pat[k] = (S[k - 1] - (pat[k - 1] + pat[k - 2])) % 2

        if S[-1] != (pat[0] + pat[-1] + pat[-2]) % 2:
            continue
        if S[0] != (pat[1] + pat[0] + pat[-1]) % 2:
            continue

        ans = ['S' if pat[k] == 0 else 'W' for k in range(N)]
        print(''.join(ans))
        return None

    print(-1)

if __name__ == '__main__':
    solve()

Measured memory_bytes: 6268
#include <iostream>
#include <vector>
using namespace std;
 
int main() {
  int n; cin >> n;
  vector<int> v(n);
  vector<int> c(n);
  for (int i = 0; i < n; i++) {
    cin >> v[i];
  }
  for (int j = 0; j < n; j++) {
    cin >> c[j];
  }
  
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (v[i] > c[i]) {
      ans += v[i] - c[i];
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

#define max(x, y) (((x) > (y)) ? (x) : (y))
#define min(x, y) (((x) < (y)) ? (x) : (y))

int main(void){
	
	long N, x, eat;
	
	scanf("%ld%ld", &N, &x);
	
	long a[N];
	
	long i;
	eat = 0;
	
	for(i=0;i<N;i++){
		scanf("%ld", a+i);
		if (i == 0){
			eat += max(0, a[0]-x);
			a[0] = min(x, a[0]);
		} else {
			int nowe = max(0, a[i-1]+a[i]-x);
			eat += nowe;
			a[i] -= nowe;
		}
	}
	
	printf("%ld\n", eat);
	return 0;
}

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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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 ll INF = 1e9+10;
const ll MOD = 1e9+7;
const ll LINF = 1e18;



signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  
  ll n; cin>>n;
  vll b(n);
  rep(i,n-1){
    ll a; cin>>a; a--;
    b[a]++;
  }
  
  rep(i,n){
    cout<<b[i]<<endl;
  }
  
}

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

using namespace std;

int gcd(int a, int b)
{
    return a == 0 ? b : gcd(b % a, a);
}

int main()
{
    int n, k;
    scanf("%d %d", &n, &k);

    int inp[n];
    int g = 0;
    int mx = INT_MIN;
    for (int i = 0; i < n; i++) {
        scanf("%d", &inp[i]);
        g = gcd(g, inp[i]);
        mx = max(mx, inp[i]);
    }

    if (g == 1)
        if (k <= mx)
            printf("POSSIBLE\n");
        else
            printf("IMPOSSIBLE\n");
    else {
        if (k <= mx && k % g == 0)
            printf("POSSIBLE\n");
        else
            printf("IMPOSSIBLE\n");
    }
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
typedef long long int lint;

#define PI acos(-1)
#define INF64 1LL << 60
#define INF32 1 << 29
#define LIMIT(d_in, d_min, d_max) max(d_min, min(d_max, d_in))
#define all(a) (a).begin(), (a).end()
#define INV ((long long int)1000000007)

using namespace std;

void execute()
{
	lint N, A, B, C, D, E;
	cin >> N >> A >> B >> C >> D >> E;

	lint min_num = min({A, B, C, D, E});

	lint ans = (N + min_num - 1) / min_num;

	cout << ans + 4 << endl;

	return;
}

int main()
{
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	execute();

	int stop;
	cin >> stop;

	return 0;
}

Measured memory_bytes: 256
#!/mnt/c/Users/moiki/bash/env/bin/python
N,M = map(int, input().split())
g = [ list(map(lambda x: int(x)-1, input().split())) for _ in range(M) ]

from collections import Counter, defaultdict
childs  = Counter( x[1] for x in g)
childs_list  = defaultdict(list)

for x,y in g:
    childs_list[x].append(y)
roots = []
for i in range(N):
    if childs[i] == 0:
        roots.append(i)

l = [ i for i in roots]
costs = [ 0 for _ in range(N)]

while l: 

    nex_stack = []
    # p = l.pop()
    for p in l:
        # cnt = costs[p]
        for c in childs_list[p]:
            costs[c] = max(costs[p]+1, costs[c])
            childs[c] -= 1
            if childs[c] == 0:
                nex_stack.append(c)
    
    l = nex_stack


print(max(costs))
        
        



Measured memory_bytes: 97492
NL = input()
NL = "".join(NL).rstrip("\n").split(" ")
N = int(NL[0])
L = int(NL[1])
a = input()
a = "".join(a).split(" ")

for s in range(N-1):
	if int(a[s])+int(a[s+1])>=L:
		Last = s+1
		print("Possible")
		for s in range(N-1):
			if s+1>Last:
				for j in range(N):
					if (N-1-j) ==s:
						#print(Last)
						break
					print(N-1-j)
				break
			if s+1==Last:
				continue
			print(s+1)
		print(Last)
		break
	if s==N-2:
		print("Impossible")

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

#define REP(i,init, n) for(lli i=init;i<n;i++)
#define REPE(i,init, n) for(lli i=init;i<=n;i++)
#define REPIT(it,container) for(auto it = container.begin(); it != container.end(); it++)
#define REPIT_R(it,container) for(auto it = container.rbegin(); it != container.rend(); it++)

#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

typedef long long int lli;
typedef pair<lli, lli> P;

int main() {
    lli n;
    cin >> n;
    cout << (n-2) * 180 << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;

int main(){
  int X,Y,Z;
  cin >> X >> Y >> Z;
  X -= Z;
  cout << X / (Y+Z) << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define FOR(i,L,R) for(i=L;i<R;i++)
#define REP(i,N) FOR(i,0,N)
int main(){
  ll N,i,ans,sum,p;cin>>N;ll A[N];REP(i,N)cin>>A[i];
  sum=max(A[0],(ll)1);ans=sum-A[0];
  FOR(i,(ll)1,N){
    if((sum<0&&sum+A[i]>0)||(sum>0&&sum+A[i]<0))sum+=A[i];
    else{ans+=abs(A[i]+sum)+1;if(sum>0)sum=-1;else sum=1;}
  }
  p=ans;sum=min(A[0],(ll)-1);ans=A[0]-sum;
  FOR(i,(ll)1,N){
     if((sum<0&&sum+A[i]>0)||(sum>0&&sum+A[i]<0))sum+=A[i];
    else{ans+=abs(A[i]+sum)+1;if(sum>0)sum=-1;else sum=1;}
  }
  cout<<min(p,ans)<<endl;
  return 0;
}

Measured memory_bytes: 4340
#include<bits/stdc++.h>
using namespace std;
int main(){
    ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
    int k,a,b;
    cin>>k;
    cin>>a>>b;
    int x=a/k;
    int y=b/k;
    int flag=0;
    for(int i=x;i<y+1;i++){
        if((i*k>=a) && (i*k<=b))
        { 
            flag=1;
            break;
        }
    }
    if (flag==1) cout<<"OK";
    else cout<<"NG";
    return 0;
}

Measured memory_bytes: 3652
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <valarray>
#include <vector>

#define EPS 1e-9
#define INF 1070000000LL
#define MOD 1000000007LL
#define fir first
#define foreach(it,X) for(__typeof((X).begin()) it=(X).begin();it!=(X).end();it++)
#define ite iterator
#define mp make_pair
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define pb push_back
#define sec second
#define sz(x) ((int)x.size())

using namespace std;

struct timer{
	time_t start;
	timer(){start=clock();}
	~timer(){cerr<<1.*(clock()-start)/CLOCKS_PER_SEC<<" secs"<<endl;}
};

typedef istringstream iss;
typedef long long ll;
typedef pair<int,int> pi;
typedef stringstream sst;
typedef vector<int> vi;

ll n,dp[211][211];
string s;

int main(){
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	
	int N;
	cin>>N;
	rep(i,N){
		char c;cin>>c;
		if(c!='-')s+=c;
	}
	n=sz(s);
	dp[0][0]=1;
	rep(i,n){
		rep(j,n+1){
			if(s[i]=='U'){
				dp[i+1][j] += dp[i][j]*j;
				dp[i+1][j]%=MOD;
				dp[i+1][j+1] += dp[i][j];
				dp[i+1][j+1]%=MOD;
			}else{
				dp[i+1][j] += dp[i][j]*j;
				dp[i+1][j]%=MOD;
				if(j>0){
					dp[i+1][j-1] += dp[i][j]*j%MOD*j;
					dp[i+1][j-1]%=MOD;
				}
			}
		}
	}
	cout<<dp[n][0]<<endl;
}

Measured memory_bytes: 1524
package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	nCities := scanInt(sc)
	nTrains := scanInt(sc)
	nQuestions := scanInt(sc)

	tableSize := nCities + 1
	table := make([][]int, tableSize)
	table[0] = make([]int, tableSize)

	for i := 0; i < nTrains; i++ {
		start := scanInt(sc)
		end := scanInt(sc)
		if table[start] == nil {
			table[start] = make([]int, tableSize)
		}
		table[start][end] += 1
	}

	// 累積和にする。
	for x := 1; x < tableSize; x++ {
		if table[x] == nil {
			table[x] = make([]int, tableSize)
		}
		for y := 1; y < tableSize; y++ {
			table[x][y] += table[x-1][y] + table[x][y-1] - table[x-1][y-1]
		}
	}

	out := bufio.NewWriter(os.Stdout)
	for i := 0; i < nQuestions; i++ {
		start := scanInt(sc)
		end := scanInt(sc)
		cnt := table[end][end] - table[end][start-1] - table[start-1][end] + table[start-1][start-1]
		fmt.Fprintln(out, cnt)
	}
	out.Flush()
}

func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	v, _ := strconv.Atoi(sc.Text())
	return v
}


Measured memory_bytes: 5376
#include<stdio.h>
#include<stdlib.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *p;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){
  while(x->left!=NIL) x=x->left;
  return x;

}

Node treeSearch(Node u, int k){
  if(u==NIL || k==u->key) return u;
  if(k<u->key) return treeSearch(u->left,k);
  else return treeSearch(u->right,k);

}

Node treeSuccessor(Node x){
  Node y;
  if(x->right!=NIL) return treeMinimum(x->right);
 
  y=x->p;
  while(y!=NIL && x==y->right){
    x=y;
    y=y->p;
  }  
  
  return y;  
} 

void treeDelete(Node z){
  
  Node y; // node to be deleted
  Node x; // child of y
  if(z->left==NIL || z->right==NIL)
    y=z;
  else
    y=treeSuccessor(z);
 
 if(y->left!=NIL)
    x=y->left;
  else
    x=y->right;
 
 if(x!=NIL)
    x->p=y->p;
 
 if(y->p==NIL)
   root=x;  
 else if(y==y->p->left)
   y->p->left=x;
 else 
    y->p->right=x;
  
 if(y!=z)
  z->key=y->key;
  
}


void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;
  
  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;
   while(x!=NIL){
     y=x;
     if(z->key < x->key) x=x->left;
     else x=x->right;
   }
   z->p=y;
   if(y==NIL)
     root=z;
   else if(z->key < y->key)
     y->left=z;
   else y->right=z;
 }


void inorder(Node u){
  if(u!=NIL){
    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);
  }
}

void preorder(Node u){
  if(u!=NIL){
 printf(" %d",u->key);  
  preorder(u->left);
  preorder(u->right);
}
}

int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);
  
  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}

Measured memory_bytes: 19364
#include<stdio.h>
int main(){
    int a,op,b;

    while(1){
        scanf("%d %c %d",&a,&op,&b);
        switch(op){
        case'?':
            break;
        case'+':
            printf("%d\n",a+b);
            break;
        case'-':
            printf("%d\n",a-b);
            break;
        case'*':
            printf("%d\n",a*b);
            break;
        case'/':
            printf("%d\n",a/b);
            break;
        }
        if(op=='?') break;

    }

    return 0;
}



Measured memory_bytes: 2144
#include <iostream>
#include <string>

using namespace std;

int main() {
    int n, k;
    cin >> n >> k;
    
    string s;
    cin >> s;
    
    if(s[k-1]=='A') s[k-1]='a';
    else if(s[k-1]=='B') s[k-1]='b';
    else s[k-1]='c';
    
    cout << s << endl;

    return 0;
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;
using ll = long long;

int main()
{
  int N; cin >> N;
  vector<int> p(N); REP(i, N) cin >> p[i];

  int cnt = 0;
  REP(i, N) cnt += (p[i] != i+1 ? 1 : 0);

  if (cnt > 2) cout << "NO" << endl;
  else cout << "YES" << endl;
}

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

#動くことのできる経路とその逆向きの移動をリストにし、それをリストにしたもの
lst = []
for i in range(M):
    a = list(map(int, input().split()))
    lst += [a] + [a[::-1]]

def next_permutation(L): #リストを順列で並び替える部分
    i = N - 2
    while i >= 0 and L[i] > L[i+1]:
        i -= 1

    if i == -1:
        return False

    j = i + 1
    while j < N and L[i] < L[j]:
        j += 1
    j -= 1

    L[i], L[j] = L[j], L[i]

    left = i + 1
    right = N - 1

    while left < right:
        L[left], L[right] = L[right], L[left]
        left += 1
        right -= 1

    return True

#1-->Nまでの整数が順に並んでいるリスト、このリストの順番にたどるとする
L = [i+1 for i in range(N)]
#print ('作成したL', L)

def judge(L): #ある経路Lが与えられたときに、その移動がリスト内の移動法で可能かどうかを判定、可能-->True 不可-->Falseを返す
    for i in range(N-1):
        if not L[i:i+2] in lst:
#            print ('L[i:i+2]=', L[i:i+2])
            return False
    return True


def roop(L): #全判定する部分
    count = 0
    while True:
        #順路が条件を満たすか判定する部分
#        print ('ループ内L', L)
#        time.sleep(3)
        if L[0] != 1: #並び替えた後に最初が1ではない-->パスが1から始まらず条件を満たさない
            print (count)
            break
        if judge(L):
            count += 1
        if not next_permutation(L):
            print (count)
            break
    return 'error'
#print ('lst = ',lst)
roop(L)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define rep(N) for (int i = 0; i < N; ++i)
#define Rep(a, b) for (int i = a; i < b; ++i)
#define For(i, N) for (int i = 0; i < N; ++i)
#define all(v) v.begin(), v.end()
#define rev(v) v.rbegin(), v.rend()
#define makei(N) int N; cin >> N;
#define makel(N) ll N; cin >> N;
#define makes(s) string s; cin >> s;
#define maked(d) double d; cin >> d;
#define makev(v, N) vi v(N); rep(N)cin >> v[i];
#define mod 1000000007
#define re return 0

using namespace std;
using ll = long long int;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using vs = vector<string>;
using pii = pair<int, int>;
using pis = pair<int, string>;
using msi = map<string, int>;

template<typename T>
void say(T s) {
	cout << s << "\n";
}

template<typename T>
void say(vector<T> s) {
	auto itr = s.begin();
	cout << *(itr++);
	while (itr != s.end()) {
		cout << " " << *(itr++);
	}
	cout << "\n";
}

void yn(bool b) {
	if (b)say("Yes");
	else say("No");
}

template<typename T>
void maxi(T &a, T &b) {
	a = max(a, b);
}

template<typename T>
void mini(T &a, T &b) {
	a = min(a, b);
}

int main() {
	makei(N);
	int m4 = 0;
	int m2 = 0;
	int m1 = 0;
	rep(N) {
		makei(a);
		if (a % 4 == 0)++m4;
		else if (a % 2 == 0)++m2;
		else ++m1;
	}
	yn((m1 <= m4) || (m2 == 0 && m1 == m4 + 1));
}

Measured memory_bytes: 256
using System;
using System.Linq;//リストの使用
using System.Collections.Generic;
class Program
{
	static void Main()
	{
  long answer = 0;
	string[] input = Console.ReadLine().Split(' ');//Splitで区切り文字を指定して複数個受け取る。
	long n = long.Parse(input[0]);
	long m = long.Parse(input[1]);
	long startVertex = long.Parse(input[2]);
  long[] a = new long[m];
  long[] b = new long[m];
  long[] c = new long[m];
  long[] distance = new long[n];//最短距離
  bool negative = false;//負のループ

    for(long i = 0; i < n; i++)
    {
      distance[i] = long.MaxValue;
    }
    
    for(long i = 0; i < m; i++)
    {
      long[] nums = Array.ConvertAll(Console.ReadLine().Split(' '),long.Parse);//１行ごとに受け取る
      a[i] = nums[0];
      b[i] = nums[1];
      c[i] = nums[2];//最短距離を調べる
    }
    distance[startVertex] = 0;

    for(long i = 0; i < n; i++)//全頂点について、最短距離の更新
    {
      for(long j = 0; j < m; j++)
      {
        if(distance[a[j]] == long.MaxValue) continue;

        distance[b[j]] = Math.Min(distance[b[j]], distance[a[j]] + c[j]);
      }
    }

    for(long i = 0; i < n; i++)
    {
      for(long j = 0; j < m; j++)
      {
        if(distance[a[j]] == long.MaxValue) continue;

        if(distance[b[j]] > distance[a[j]] + c[j])//最短距離の更新をしたのに最短がまだ含まれる
        {
          negative = true;
        }
        
      }
    }

    if(negative) Console.WriteLine("NEGATIVE CYCLE");
    else
		{
			for(int i = 0; i < n; i++)
			{
				if(distance[i] != long.MaxValue) Console.WriteLine(distance[i]);
				else Console.WriteLine("INF");
			}
		}

	}
}


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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"

const int N = 1e5 + 5;

int n, m, k;
int x11, y11, x2, y2;
int dx[4] = { -1, +1, 0, 0};
int dy[4] = {0, 0, +1, -1};
vector<vector<char> > a;
vector<vector<int> > vis, ways, dist;

void bfs(int x, int y)
{
	queue<pair<int, int> > q;
	q.push({x, y});
	vis[x][y] = 1;
	dist[x][y] = 0;
	while (!q.empty())
	{
		int x = q.front().first;
		int y = q.front().second;
		q.pop(); //cout << x << " " << y << endl;
		for (int dir = 0; dir < 4; dir++)
		{
			for (int len = 1; len <= k; len++)
			{

				int nx = x + dx[dir] * len;
				int ny = y + dy[dir] * len;
			

				if (nx < 1 || ny < 1 || nx > n || ny > m)
						break;
				if (dist[nx][ny]  <= dist[x][y]  && vis[nx][ny] == 1)
				{ break;}
				if (a[nx][ny] == '@')
				{ break;}
                if(vis[nx][ny]==1)
                continue;
				dist[nx][ny] = dist[x][y] + 1;
				vis[nx][ny] = 1;
				q.push({nx, ny});
			}
		}
// 		for (int i = 1; i <= n; i++)
// 		{	for (int j = 1; j <= m; j++)
// 			{
// 				cout << dist[i][j] << " ";
// 			}
// 			cout << "     ";
// 			for (int j = 1; j <= m; j++)
// 			{
// 				cout << vis[i][j] << " ";
// 			}
// 			cout << endl;
// 		}
	}
}

int32_t main()
{
	IOS;
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	cin >> n >> m >> k;
	cin >> x11 >> y11 >> x2 >> y2;
	a = vector<vector<char> > (n + 1, vector<char> (m + 1));
	vis = ways = dist = vector<vector<int> > (n + 1, vector<int> (m + 1, 0));
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++)
			cin >> a[i][j];
	bfs(x11, y11);
	if (!vis[x2][y2])
		cout << -1;
	else
		cout << dist[x2][y2];
	return 0;
}


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

int main() {
  int N;
  cin >> N;
  vector<pair<int,int>> ooo(N);
  
  for (int i=0; i<N; i++) {
    cin >> ooo[i].second >> ooo[i].first;
  }
  
  sort(ooo.begin(),ooo.end());
  long long sum = 0;
  for (int i=0; i<N; i++) {
    sum += ooo[i].second;
    if (sum > ooo[i].first) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  
  
  return 0;
}

Measured memory_bytes: 1792
gets
a = gets.split(' ').map(&:to_i)
gets
b = gets.split(' ').map(&:to_i)

count = 0

loop do
  pat = format("%0#{a.size}d", count.to_s(2))
  break if pat.size > a.size
  sum = 0
  pat.size.times { |x| sum += (pat[x] == '0' ? 0 : a[x])  }
  while b.include?(sum)
    b[b.index(sum)] = 'yes'
  end
  count += 1
end

b.each { |e| puts e == 'yes' ? e : "no" }



Measured memory_bytes: 6916
x = list(str(input()))
for i in range(3):
    if x[i] == 'R':
        x[i] = 1
    else:
        x[i] = 0
ans = x[0] + x[1] + x[2]
if (x[0] == 1 or x[2] == 1) and x[1] == 0:
    print(1)
else:
    print(ans)

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

using namespace std;

typedef long long ll;

#define FOR(index, init, max) for (int index = (init); index < (max); index++)
#define REP(index, max) for (int index = 0; index < (max); index++)
#define FOREACH(x, array) for (auto&& (x) : array)
#define VECCIN(vec) for (auto&& vec_i : vec) cin >> vec_i
#define VECCOUT(vec) for (const auto& vec_i : vec) cout << vec_i << endl

int main() {
    int N, W;
    cin >> N >> W;

    vector<int> v(N), w(N);
    REP(vec_i, N) {
        cin >> v[vec_i] >> w[vec_i];
    }

    int dp[101][10001] = {0};
    REP(i, N) {
        REP(j, W + 1) {
            if (j >= w[i]) {
                dp[i + 1][j] = max(dp[i][j - w[i]] + v[i], dp[i][j]);
            }
            else {
                dp[i + 1][j] = dp[i][j];
            }
        }
    }

    cout << dp[N][W] << endl;

    return 0;
}


Measured memory_bytes: 7040
//package atcoder;
 
import java.util.*;
 
public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int S = sc.nextInt();
		int W = sc.nextInt();
		
		if(W>=S) {
			System.out.println("unsafe");
		}else {
			System.out.println("safe");
		}
	}
}

Measured memory_bytes: 35576
/*
  Motto - try hard to become an expert
*/
#include <bits/stdc++.h>
#include <map>
#include <algorithm>
#include <vector>
#include <string.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <chrono>
#include <thread>
#include <iomanip>
 
//define
#define rep(i,n)    for(int i=0;i<n;i++)
#define repu(i,k,n) for(int i=k;i<=n;i++)
#define repd(i,k,n) for(int i=k;i>=n;i--)
#define se second
#define fi first
#define pb push_back
#define mp make_pair
#define INF (int)INT_MAX
#define all(v)  v.begin(), v.end()
#define endl "\n"
 
//typedef
typedef long long int ll;
typedef long double ld;
typedef std::pair<int, int> pii;
typedef std::vector<int> vi;
typedef std::vector< pii > vii;
typedef std::vector< ll > vll;
typedef std::vector< std::pair < pii, int > > vpp;
 
const int N = 3*1e5 +5 ;
const long long MOD = 998244353;
const long long inf = 1e18;
 
using namespace std;
 
ll MAXN=100001;
ll spf[100001]; 
 
ll modpow(ll x,ll n){
    ll res=1;
    while(n>0){
        if(n&1) res=res*x%MOD;
        x=x*x%MOD;
        n>>=1;
    }
    return res;
}
 
ll modFact(ll n, ll p) 
{ 
    if (n >= p) 
        return 0; 
  
    ll result = 1; 
    for (ll i = 1; i <= n; i++) 
        result = (result * i) % p; 
  
    return result;  
} 
 
bool isPrime(int x)
{
    if(x%2==0)
        return 0;
    for(int i=3;i<=sqrt(x);i+=2)
    {
        if(x%i==0)
            return 0;
    }
    return 1;
}
 

 
void solve()
{
	int n  ;
	cin>>n ;
	int a[n] ;
	rep(i , n) cin>>a[i] ;
	int fi = 0 ;
	
	repu(i , 1 , n-1){
		
		fi ^= (a[i]^a[0]) ; 
	}
	vector<int>arry ;
	rep(i , n){
		cout<<(fi^a[i])<<" ";
	}
	
}
 
int main() {
    #ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif
    
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    int t = 1;
    //cin>>t;
    while(t--)
    {
        solve();
    } 
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}

Measured memory_bytes: 4644
from sys import stdin
def main():
    #入力
    readline=stdin.readline
    x=int(readline())
    flag=False
    for a in range(-200,201):
        for b in range(-200,201):
            if a**5-b**5==x:
                print(a,b)
                flag=True
                break
        if flag: break

if __name__=="__main__":
    main()

Measured memory_bytes: 9160
#define _USE_MATH_DEFINES
#include<bits/stdc++.h>
//#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=0;i<b;i++)
#define REP(i,a,b) for(int i=0;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define inf (1ll<<60)
#define Yes(f) cout <<(f?"Yes":"No")<<endl//fが真の場合Yesを出力、偽の場合Noを出力
#define yes(f) cout <<(f?"yes":"no")<<endl
#define YES(f) cout <<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v),greater<int>())

using namespace std;

const int mod=1e9+7;

signed main(){
    int n;
    cin >> n;
    int a;
    int max_=0,min_;
    rep(i,n)
    {
        cin >> a;
        if(i==0)min_=a;
        max_=max(max_,a);
        min_=min(min_,a);
    }

    cout << max_-min_ << endl;
}


Measured memory_bytes: 256
n, m, q = map(int, input().split())
edges = [[0]*(n+1) for _ in range(n+1)]

for _ in range(m):
    L, R = map(int, input().split())
    edges[L][R] += 1

for i in range(1, n+1):
    for j in range(n):
        edges[i][j+1] += edges[i][j]

for i in range(n):
    for j in range(1, n+1):
        edges[i+1][j] += edges[i][j]

for _ in range(q):
    p, q = map(int, input().split())
    ans = edges[q][q]-edges[q][p-1]-edges[p-1][q]+edges[p-1][p-1]
    print(ans)


Measured memory_bytes: 13392
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <fstream>
#include <string>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <map>
#include <bitset>
#include <stack>
#include <queue>
using namespace std;
#define len(n) (int)n.length()
#define dump cout
#define pb push_back
#define ll long long
#define make_pair mkp
typedef pair<ll, ll> LLARR;

bool firstsort_less(const LLARR& left,const LLARR& right){
    return left.first > right.first;
}

bool secondsort_less(const LLARR& left,const LLARR& right){
    return left.second > right.second;
}

int main()
{
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	cout << n * (n+1) / 2 << endl;
	return 0;
}

Measured memory_bytes: 764
using System;
using System.Linq;
public class Hello{
    public static void Main(){
        var input = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
        var n = input[0];
        var W = input[1];
        
        var dp = new long[W + 1];
        for(var i = 0;i < n;i++){
            var a = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
            var w = a[0];
            var v = a[1];
            for(var j = W;j >= 0;j--){
                if(j >= w){
                    dp[j] = Math.Max(dp[j],dp[j - w] + v);
                }
            }
        }
        Console.WriteLine(dp[W]);
    }
}


Measured memory_bytes: 13400
#include<stdio.h>
#include<iostream>
#include"string"
#include"math.h"
#include <algorithm>
#include<vector>
using namespace std;

int abs(int a){
	if(a<0)return -a;
	return a;
}
long long gcd(long long a,long long b){
	long long d;
	if(a<b){
		long long c;
		c=a;
		a=b;
		b=c;
	}
	d=a%b;
	if(d==0){
		return b;
	}else{
		gcd(b,d);
	}
}

long long lcm(long long a,long long b){
	return (a*b)/gcd(a,b);
}


long long N,K,M,re,C,spot,r,L;
bool p[10001];
long long ans,A[100001],dp[101][10001];
string S,T;

int main(){
	cin>>N>>M;
	cin>>S;
	cin>>T;
	L=lcm(N,M);
	long long g=gcd(N,M);
	long long n=N/g;
	long long m=M/g;
	for(int i=0;i<g;i++){
			if(S[i*n]!=T[i*m]){
			cout<<-1<<endl;
			return 0;
		}
	}
	cout<<L<<endl;
	return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <set>
#include <map>
#include <cstdio>
using namespace std;
using ll = long long;


#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)


int L[10];
int R[10];

bool Map[200007];
int K;
bool in(int x) {
    for (int i = 0; i < K; i++) {
        if (L[i] <= x && x <= R[i])return true;

    }
    return false;
}

int path(int from, int to) {
    int ans = 0;
    if (from > to)return 0;
    if (from == to)return 1;
    for (int i = 0; i < K; i++) {
        for (int j = L[i]; j <= R[i]; j++) {
            ans += path(from + j, to);
            ans %= 998244353;
        }
    }
    return ans;
}

ll ans[200007];
ll anssum[200007];
int main() {

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

    ans[1] = 1;
    anssum[1] = 1;
    cin >> N >> K;
    int count = 0;
    rep(i, K) {
        int l, r;
        cin >> l >> r;
        L[i] = l;
        R[i] = r;
        /*for (int j = l; j <= r; j++) {
            Map[j] = true;
        }*/
    }
    /*rep1(i, N) {
        rep(p, K) {
            for (int j = L[p]; j <= R[p]; j++) {
                if (j <= i)ans[i] += ans[i - j], ans[i] %= 998244353;
            }
            anssum[i] = anssum[i] + ans[i];
        }
    }*/

    for (int i = 2; i <= N;i++) {
        rep(p, K) {
            /*for (int j = L[p]; j <= R[p]; j++) {
                if (j <= i)ans[i] += ans[i - j], ans[i] %= 998244353;
            }*/
            ans[i] += 998244353+anssum[max(i - L[p], 0)]-anssum[max(i - R[p] - 1, 0)];
            ans[i] %= 998244353;

        }
        
        anssum[i] = anssum[i-1] + ans[i];
        anssum[i] %= 998244353;
    }
    //rep1(i, N)cout << i << ": " << ans[i] << endl;
    //rep(i, N)cout << "ans" << i << ": " << ans[i] << endl;
    //rep(i, N)cout << "sum" << i << ": " << anssum[i] << endl;
    cout << ans[N] << endl;
    return 0;
}

Measured memory_bytes: 6764
r, c = gets.chomp.split(" ").map(&:to_i)

array = []

while input = gets
    tmp = input.chomp.split(" ").map(&:to_i)
    rsum = 0
    tmp.each {|x| rsum += x}
    puts "#{input.chomp} #{rsum}"
    
    tmp << rsum
    array << tmp
end

for i in 0..c
    csum = 0
    for j in 0..r - 1
        csum += array[j][i]
    end
    print csum
    if i != c
        print " "
    end
end
puts ""


Measured memory_bytes: 7092
#include<bits/stdc++.h>
#define LL long long
using namespace std;
//int P=998244353;
//inline int ad(int x,int y){return (x+y>=P)?(x+y-P):(x+y);}
//inline int mt(int x,int y){LL rt=1ll*x*y; rt=(rt>=P)?(rt%P):rt; return rt;}
//inline void mo(int &x){x=(x>=P)?(x-P):x; x=(x<0)?(x+P):x;}
template<typename T>void read(T &x){
	x=0;int f=1;
	char c=getchar();
	for(;!isdigit(c);c=getchar()) if (c=='-') f=-1;
	for(;isdigit(c);c=getchar()) x=x*10+c-48;
	x*=f;
}
char s[200010];
int main(){
	scanf("%s",s+1);
	int n=strlen(s+1);
	int nwb=0;
	LL ans=0;
	for(int i=1;i<=n;++i)
	if(s[i]=='B')++nwb;
		else ans+=nwb;
	printf("%lld\n",ans);
	
	
	return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
constexpr int64_t mod=1e9+7;

int main()
{
  int n,m;
  cin>>n>>m;
  std::map<int, int> mp;
  for (int i = 0; i < m; ++i)
  {
    int a,b;
    cin>>a>>b;
    mp[a]++;
    mp[b]++;
  }
  for(auto&& e: mp) {
    if(e.second%2==1){
      cout<<"NO";
      return 0;
    }
  }
  cout<<"YES";

}

Measured memory_bytes: 4352
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define eps 1e-10
#define fo(i,l,r) for(int i=l;i<=r;i++)
#define of(i,l,r) for(int i=l;i>=r;i--)
#define fe(i,u) for(int i=head[u];i;i=e[i].next)
using namespace std;
typedef long long ll;
typedef pair<long double,int> pii;
#define P(a,b) make_pair(a,b)
inline void open(const char *s)
{
	#ifndef ONLINE_JUDGE
	char str[20];
	sprintf(str,"in%s.txt",s);
	freopen(str,"r",stdin);
//	sprintf(str,"out%s.txt",s);
//	freopen(str,"w",stdout);
	#endif
}
inline int rd()
{
	static int x,f;
	x=0;f=1;
	char ch=getchar();
	for(;ch<'0'||ch>'9';ch=getchar())if(ch=='-')f=-1;
	for(;ch>='0'&&ch<='9';ch=getchar())x=x*10+ch-'0';
	return f>0?x:-x;
}
const int N=40010;
int n,b[N];pii a[N];
struct line{
	int A,B,C;
	inline void rev(){A=-A;B=-B;C=-C;}
	inline void sw(){swap(A,B);}
	inline void read(){A=rd();B=rd();C=rd();}
}L[N];

inline bool cmp(line a,line b){return a.A*b.B>b.A*a.B;}

namespace TA{
#define lowbit(x) (x&-x)
int tr[N];
inline void clear(){memset(tr,0,sizeof tr);}
inline void insert(int x,int d){for(;x<=n;x+=lowbit(x))tr[x]+=d;}
inline int query(int x){int res=0;for(;x;x-=lowbit(x))res+=tr[x];return res;}

}

inline void gao()
{
	fo(i,1,n)if(L[i].B<0)L[i].rev();
	sort(L+1,L+n+1,cmp);
//	fo(i,1,n)printf("%d %d %d\n",L[i].A,L[i].B,L[i].C);
	long double l=-1e9,r=1e9;
	while(r-l>eps){
//		l=1.;r=1.;
		long double mid=.5*(l+r);
		fo(i,1,n)a[i]=P((1.*L[i].C-mid*L[i].A)/(1.*L[i].B),i);
//		fo(i,1,n)printf("%.5Lf ",a[i].first);puts("");
		sort(a+1,a+n+1);
		int cnt=0;
		TA::clear();
		fo(i,1,n){
			cnt+=TA::query(a[i].second);
			TA::insert(a[i].second,1);
		}
//		cout<<cnt<<endl;
		ll hh=((ll)n*(n-1)/2ll+1)/2ll;
		if(cnt>=hh)r=mid;
		else l=mid;
	}
	printf("%.10Lf ",(r+l)*.5);
}

int main()
{
	n=rd();fo(i,1,n)L[i].read();
	long double ans;
	gao();fo(i,1,n)L[i].sw();
	gao();
	puts("");
	return 0;
}


Measured memory_bytes: 2176
#include<iostream>
#include<string>
int main(){
	int v[4];
	v[0]=0,v[1]=0,v[2]=0,v[3]=0;
std::string a;
std::cin>>a;
for(int i=0;i<a.size();i++){
if(a[i]=='K')
	v[0]++;
if(a[i]=='U')
	v[1]++;
if(a[i]=='P')
	v[2]++;
if(a[i]=='C')
	v[3]++;
}
int min=v[0];
for(int i=0;i<4;i++){
	if(v[i]<min)
		min=v[i];
}
std::cout<<min<<std::endl;
}

Measured memory_bytes: 1188
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define REP(i,j,n) for(int i = j;i < (n);i++)
#define intput(i) cout << i << endl
#define ll long long
#define stringput(s) cout << (string)(s) << endl

int main(){
  ll X;
  cin >> X;
  ll ans = 0;
  while(X >= 500){
    X -= 500;
    ans += 1000;
  }
  while(X >= 5){
    X -= 5;
    ans += 5;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a, b, c;
  cin >> a >> b >> c;
  int count =0;
  if(a == b && a != c)count++;
  else if(a == c && a != b)count++;
  else if(b == c && b != a)count++;
  else if(b == a && b != c)count++;
  else if(c == a && c != b)count++;
  else if(c == b && c != a)count++;
  if(count != 0)cout << "Yes" << endl;
  else cout << "No" << endl;
}



Measured memory_bytes: 256
N,W,n,v,w,t,*m,*p;main(){for(;scanf("%d",&W),W;){int c[1001]={0};for(scanf("%d",&n);n--;)for(scanf("%d,%d",&v,&w),p=c+W+1;--p-c;*p==c[W]?m=p:0)p-c>=w&&*p<(t=p[-w]+v)?*p=t:0;printf("Case %d:\n%d\n%d\n",++N,c[W],m-c);}return 0;}

Measured memory_bytes: 0