akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <iostream>
using namespace std;

int N, M, h[200], r[200];

int main() {
    while (true) {
        cin >> N;
        if (N == 0) break;
        for (int j = 0; j < N; ++j) {
            cin >> h[j] >> r[j];
        }
        cin >> M;
        for (int j = 0; j < M; ++j) {
            cin >> h[j+N] >> r[j+N];
        }

        int arr[1001][1001];
        for (int j = 0; j <= 1000; ++j) fill(arr[j], arr[j] + 1001, 0);

        for (int j = 0; j < N+M; ++j) {
            arr[h[j]][r[j]] = 1;
        }

        int dp[1001][1001];
        for (int j = 0; j <= 1000; ++j) fill(dp[j], dp[j] + 1001, 0);

        for (int j = 0; j <= 1000; ++j) {
            for (int k = 0; k <= 1000; ++k) {
                if (j > 0 && k > 0) {
                    dp[j][k] = max(dp[j-1][k-1] + arr[j][k], max(dp[j-1][k], dp[j][k-1]));
                } else if (j > 0) {
                    dp[j][k] = dp[j-1][k];
                } else if (k > 0) {
                    dp[j][k] = dp[j][k-1];
                }
            }
        }

        cout << dp[1000][1000] << endl;
    }
    return 0;
}

Measured memory_bytes: 10892
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ll long long int
const int INF = 2147483647;

using namespace std;

int main()
{
  int n, m;
  cin >> n >> m;
  pair<int, ll> ab[100000];
  REP(i, n)
  {
    int a;
    ll b;
    cin >> a >> b;
    ab[i] = make_pair(a, b);
  }
  sort(ab, ab + n);
  int index = 0;
  ll ans = 0;
  priority_queue<ll> q;
  FOR(i, 1, m + 1)
  {
    while (index < n && ab[index].first <= i)
    {
      q.push(ab[index].second);
      index++;
    }
    if (!q.empty())
    {
      ans += q.top();
      q.pop();
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 2936
#include <iostream>
#include <vector>
#include <queue>
using namespace std;

struct Edge{
  int dist, cost, to;
  Edge(int dist, int cost, int to):
    dist(dist), cost(cost), to(to) {}
};

bool operator<(const Edge& a, const Edge& b){
  return a.dist != b.dist ? a.dist < b.dist : a.cost != b.cost ? a.cost < b.cost : a.to < b.to;
}

int solve(vector< vector<Edge> > &G){
  int N = G.size(), INF = 1e9;
  vector<int> D(N,INF), C(N,INF);
  D[0] = 0;
  C[0] = 0;
  priority_queue<Edge> wait;
  wait.push(Edge(0,0,0));
  while(!wait.empty()){
    Edge e = wait.top();
    int d = -e.dist, c = -e.cost, v = e.to;
    wait.pop();
    if(d > D[v]) continue;
    for(int i = 0; i < G[v].size(); ++i){
      int d_ = G[v][i].dist, c_ = G[v][i].cost, v_ = G[v][i].to;
      if(D[v_] > d + d_){
        D[v_] = d + d_;
        C[v_] = c_;
        wait.push(Edge(-d-d_,-c_,v_));
      }else if(D[v_] == d + d_){
        C[v_] = min(C[v_], c_);
      }
    }
  }
  int ret = 0;
  for(int i = 0; i < N; ++i) ret += C[i];
  return ret;
}

int main(){
  int N, M;
  while(cin >> N >> M, N){
    vector< vector<Edge> > G(N);
    int u, v, d, c;
    for(int i = 0; i < M; ++i){
      cin >> u >> v >> d >> c;
      --u;--v;
      G[u].push_back(Edge(d,c,v));
      G[v].push_back(Edge(d,c,u));
    }
    cout << solve(G) << endl;
  }
  return 0;
}



Measured memory_bytes: 4068
#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;
typedef long long ll;

int main() {
	
	int n;
	cin >> n;
	int sum = 0, tmp = n;
	while(tmp){
		sum += tmp % 10;
		tmp /= 10;
	}
	string ans = "No";
	if(n % sum == 0) ans = "Yes";
	cout << ans << endl;
	return 0;
}

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

#define PI 3.14159265358979323846264338327950288419

using namespace std;


const int INF = 9999;

int dist[1005][1005];
int h, w;
char grid[1005][1005];

queue<pair<int, int> > Q;

int main(){
	scanf("%d %d", &h, &w);
	for(int i = 1; i <= h; i++){
		scanf(" %s", grid[i] + 1);
	}
	for(int i = 1; i <= h; i++){
		for(int j = 1; j <= w; j++){
			if(grid[i][j] == '#'){
				dist[i][j] = 0;
				Q.push({i, j});
			}else{
				dist[i][j] = INF;
			}
		}
	}
	
	int ans = 0;
	
	while(!Q.empty()){
		pair<int, int> pt = Q.front();
		Q.pop();
		int x = pt.first;
		int y = pt.second;
		ans = max(ans, dist[x][y]);
		
		int dx[4] = {1, 0, -1, 0};
		int dy[4] = {0, 1, 0, -1};
		
		for(int k = 0; k < 4; k++){
			int nx = x + dx[k];
			int ny = y + dy[k];
			if(nx > 0 && nx <= h && ny > 0 && ny <= w){
				if(dist[nx][ny] == INF){
					dist[nx][ny] = dist[x][y] + 1;
					Q.push({nx, ny});
				}
			}
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 13328
import sys
import math
n,m=map(int,input().split())
k=[]
for i in range(m):
    s=list(map(int,input().split()))
    s = list(map( lambda x:x-1,s))
    k.append(s[1:])
p=list(map(int,input().split()))

ans=0

for bit in range(1<<n):
    cnt_swit=[0]*m
    for i in range(n):
        if bit>>i & 1:
            for j in range(m):
                if i in k[j]:
                    cnt_swit[j]+=1
    cnt_swit = list(map( lambda x:x%2,cnt_swit))
    tmp=0
    for pi,cnt in zip(p,cnt_swit):
        if pi==cnt:
            tmp+=1
    if tmp==m:
        ans+=1
print(ans)






Measured memory_bytes: 69044
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <cmath>
#define rep(i,n) for (int i = 0; i < n; ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

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

Measured memory_bytes: 3188
K=int(input())
L=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(L[K-1])

Measured memory_bytes: 2940
/*The woods are lovely, dark and deep,
But I have promises to keep,
And miles to go before I sleep,
And miles to go before I sleep.*/

//PRABHJOT SINGH A.K.A. PRABHI
//~~~~~conquizztador~~~~~


#include<bits/stdc++.h>
using namespace std;
using lli = long long int;
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
const int MOD = 1000000007;
const int MOD1 = 998244353;
const int maxn = 100010;
const int lim = (int)1e9;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int l=0,r=0,d=0;
	cin>>l>>r>>d;
	int ct=0;
	for(int i=l;i<=r;++i)
		if(i%d==0)
			++ct;
	cout<<ct<<endl;
}

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

int main() {
    cin.tie(0)->sync_with_stdio(false);

    int n;
    cin >> n;
    vector<int> l(2 * n);
    REP(i, 2 * n) cin >> l[i];
    sort(l.begin(), l.end());

    int ans = 0;
    REP(i, 2 * n) {
        ans += min(l[i], l[i + 1]);
        i++;
    }

    cout << ans << '\n';
    return 0;
}


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

int main(void)
{
    int N, A, B;
    cin >> N >> A >> B;

    int temp, sum = 0;
    int ans = 0;
    for (int i = 1; i <= N; i++)
    {
        if (i < 10)
        {
            sum = i;
            if (sum >= A && sum <= B)
            {
                // printf("%d\n", i);
                ans += sum;
            }
        }
        else
        {
            sum = 0;
            temp = i;
            while (temp > 9)
            {
                sum += temp % 10;
                temp = temp / 10;
            }
            // printf("temp[%d] = %d\n", i, temp);
            sum += temp;
            // printf("sum[%d] = %d\n", i, sum);
            if (sum >= A && sum <= B)
            {
                // printf("%d\n", i);
                ans += i;
            }
        }
    }
    cout << ans << endl;
    return (0);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(v, a, b) for(int v = (a); v < (b); ++v)
#define FORE(v, a, b) for(int v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(int v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it)
#define RITR(it, c) for(auto it = (c).rbegin(); it != (c).rend(); ++it)
#define EXIST(c,x) ((c).find(x) != (c).end())
#define LLI long long int
#define fst first
#define snd second
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
#ifndef M_E
#define M_E 2.71828182845904523536
#endif

#ifdef DEBUG
#include <misc/C++/Debug.cpp>
#else
#define dump(x)
#endif

#define pln(x) cout << (x) << endl
#define gcd __gcd

using namespace std;
template <class T> constexpr T lcm(T m, T n){return m/gcd(m,n)*n;}

template <typename T> using V = vector<T>;
template <typename T, typename U> using P = pair<T,U>;
template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;}
template <typename T> istream& operator>>(istream &is, vector<T> &v){for(auto &a : v) is >> a; return is;}
template <typename T, typename U> istream& operator>>(istream &is, pair<T,U> &p){is >> p.first >> p.second; return is;}

template <typename T, typename U> T& chmin(T &a, const U &b){return a = (a<=b?a:b);}
template <typename T, typename U> T& chmax(T &a, const U &b){return a = (a>=b?a:b);}
template <typename T, size_t N, typename U> void fill_array(T (&a)[N], const U &v){fill((U*)a, (U*)(a+N), v);}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int A,B;
  while(cin >> A >> B){
    cout << (B%A==0 ? A+B : B-A) << endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
function main(input) {
  const reverse = (s) => {
      return s.split('').reverse().join('');
  };

  const WORDS = ['dream', 'dreamer', 'erase', 'eraser'].map(reverse);
  const S = reverse(input.split('\n')[0]);

  var index = 0;

  while(true) {
      var w = WORDS.find((w) => S.startsWith(w, index));
      if (!w) break;
      index += w.length;
  }

  if (S.length === index) {
      console.log('YES');
  } else {
      console.log('NO');
  }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 9624
import sys
from operator import itemgetter

input = sys.stdin.readline


def main():
    N, M = map(int, input().split())
    iPY = [[0] * 3 for _ in range(M)]
    for i in range(M):
        iPY[i][0] = i
        iPY[i][1:] = map(int, input().split())

    iPY.sort(key=itemgetter(2))

    p_count = [0] * (N + 1)
    ans = [""] * M
    for i, P, Y in iPY:
        p_count[P] += 1
        ans[i] = "".join([
            str(P).zfill(6),
            str(p_count[P]).zfill(6)
        ])

    print("\n".join(ans))


if __name__ == "__main__":
    main()


Measured memory_bytes: 34500
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,a,b,m,i,flag=0;
  int arr[100]={-1};
  cin>>n;
  m=n;
  i=-1;
  while(m--)
  {
  cin>>a>>b;
    if(a==b)
    {
      i++;
     arr[i]=n-m; 
      
    }
  }
  for(m=0;m<=i-2;m++)
  {
    if(arr[m+1]==arr[m]+1 && arr[m+2]==arr[m]+2)
    {
      flag=1;
      break;
    }
    
  }
  if(flag==0)
    cout<<"No"<<endl;
  else
    cout<<"Yes"<<endl;
}

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

int main(){

  int a,b,c;

  cin>>a>>b>>c;

  if(c>a+b){
    cout<<a+b+b+1<<endl;
  }else{
    cout<<c+b<<endl;
  }
    
    
  return 0;
  
}
  


Measured memory_bytes: 256
import java.util.Scanner;
import java.io.*;

class Main {
    public static void main(String[] args)throws IOException{ 
    	InputStreamReader in = new InputStreamReader(System.in);
        BufferedReader read = new BufferedReader(in);

        int num,count;
        
        while(true){
        	num = Integer.parseInt(read.readLine());
        	if(num == 0){
        		break;
        	}
        	else{
        		double sum = 0;
                double ave = 0;
                double sum2 = 0;
                double a2 = 0;
                double deviation = 0;
        		
        		String line = read.readLine();    
        		String [] spli = line.split(" ");
        		double [] x = new double [num];
        		
        		for(count = 0; count < num; count++){
        			x[count] = Double.parseDouble(spli[count]);
        			sum = sum + x[count];     			
        		}  
        		ave = sum/num;
        		for(count = 0; count < num; count++){
        			sum2 = sum2 + (ave-x[count])*(ave-x[count]);
        		}
        		a2 = sum2/num;
        		deviation = Math.sqrt(a2);
        		System.out.println(deviation);
        	}	
        }
    }
}

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

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    deque<int> d;
    rep(i, n)
    {
        int p = lower_bound(d.begin(), d.end(), a[i]) - d.begin();
        if (p == 0)
            d.push_front(a[i]);
        else
            d[p - 1] = a[i];
    }
    int ans = d.size();
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
#!/usr/bin/env python3
import sys


def solve(x: int):
    if x == 1:
        print(0)
    elif x == 0:
        print(1)
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    x = int(next(tokens))  # type: int
    solve(x)

if __name__ == '__main__':
    main()


Measured memory_bytes: 61720
#include <algorithm>
#include <bitset>
#include <chrono>
#include <complex>
#include <cstdint>
#include <cstring>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <ostream>
#include <queue>
#include <random>
#include <regex>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
#define all(r) r.begin(),r.end()
using namespace std;
constexpr int32_t MOD = 1e9 + 7;
using ll = int64_t;
using vll = vector<ll>;
struct Solution {
    void solve(std::istream& in, std::ostream& out) {
        ll n;
        in >> n;
        vll a(n);
        for (int i = 0; i < n; i++) {
            in >> a[i];
        }
        sort(all(a));
        bool ok = true;
        ll e = n % 2 == 0;
        for (int i = !e; i < n; i += 2) {
            if (!(a[i] == a[i + 1] && a[i] == 1 + i)) {
                ok = false;
                break;
            }
        }
        ll ans = 0;
        if (ok) {
            ans = 1;
            for (int i = 0; i < n / 2; i++) {
                (ans *= 2) %= MOD;
            }
        }
        out << ans << '\n';
    }
};
void solve(std::istream& in, std::ostream& out) {
    out << std::setprecision(12);
    Solution solution;
    solution.solve(in, out);
}
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    istream& in = cin;
    ostream& out = cout;
    solve(in, out);
    return 0;
}


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

 
int main() {
    int n, x, t;
    cin >> n >> x >> t;
 
    int ans = (n+x-1)/x*t;
    cout << ans << endl;
}

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


 int main() {
    string S;
    cin >> S;
    int ans= 0 ,count = 0;
    int N;
    N= S.size();

    for(int i= 0; i < N; i++){
        if(S.at(i) == 'A'||S.at(i) =='T'||S.at(i) =='C'||S.at(i) =='G'){
            count += 1;
            if(ans < count)
            ans = count;
        }//count
        else{
            count = 0;
        }//reset
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
n, m = [int(i) for i in input().split()]
X = [0] + [int(i) for i in input().split()]
Y = [0] + [int(i) for i in input().split()]

p = 10 ** 9 + 7

xsum = 0
ysum = 0

for i in range(1, n+1):
  xsum += (2*i-n-1) * X[i] 
  
for i in range(1, m+1):
  ysum += (2*i-m-1) * Y[i] 

print(xsum * ysum % p)

Measured memory_bytes: 18624
#include<iostream>
#include<math.h>
#include<stdlib.h>
#include<string>
#include<limits.h>
#include<utility>
#include<bits/stdc++.h>
#include<vector>
#include<tuple>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define ALL(A) A.begin(),A.end()


int main() {
	int n;
	cin >> n;
	int a[n][3];
	rep(i, n) {
		cin >> a[i][0] >> a[i][1] >> a[i][2];
	}
	int m;
	cin >> m;
	int p[m];
	int b;
	vector<int> point(394,INT_MIN);
	rep(i, m) {
		cin >> b;
		p[i] = b;
		if (point[b] == INT_MIN) {
			vector<int> c(b + 1, INT_MIN);

			c[0] = 0;

			rep(j, b) {
				rep(k, n) {
					for (int l = a[k][0]; l <= a[k][1]; l++) {
						if (b >= l + j) {
							if (c[l + j] < c[j] + a[k][2]) {
								c[l + j] = c[j] + a[k][2];
							}
						}
					}
				}
			}
			if (c[b] == INT_MIN) {
				cout << -1 << endl;
				return 0;
			}
			//p[i] = c[b];
			point[b] = c[b];
		}
	}
	rep(i, m) {
		cout << point[p[i]] << endl;
	}
}




Measured memory_bytes: 3124
import sys, re
from math import ceil, floor, sqrt, pi, factorial#, gcd
from copy import deepcopy
from collections import Counter, deque
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left
from functools import reduce
# input = sys.stdin.readline 
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_list(N): return [s_list() for _ in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    x, y = i_map()

    print(x+y//2)
            
if __name__ == '__main__':
    main()


Measured memory_bytes: 38512
#include<cstdio>
#include<bitset>
#include<algorithm>
#include<cstring>
using namespace std;
const int mod=1000000007;
int n;
inline int getrank(bitset<300> c[300])
{
	int ans=0,i,j;
	for(i=0;i<n;++i)
	{
		for(j=ans;j<n;++j)
		{
			if(c[j][i])
			{
				swap(c[j],c[ans]);
				break;
			}
		}
		if(j==n)
		{
			continue;
		}
		for(j=ans+1;j<n;++j)
		{
			if(c[j][i])
			{
				c[j]^=c[ans];
			}
		}
		++ans;
	}
	return ans;
}
int p2[90001];
inline void init(void)
{
	int i;
	p2[0]=1;
	for(i=1;i<=90000;++i)
	{
		p2[i]=(p2[i-1]<<1)%mod;
	}
	return;
}
inline void clear(long long (*dp)[301])
{
	int i;
	for(i=0;i<=n;++i)
	{
		memset(dp[i],0,sizeof(long long)*(n+1));
	}
	return;
}
long long dp1[301][301],dp2[301][301];
long long (*dp)[301]=dp1,(*dpt)[301]=dp2;
int main()
{
	init();
	int i,j,k,x,r;
	bitset<300> c[300];
	scanf("%d",&n);
	for(i=0;i<n;++i)
	{
		for(j=0;j<n;++j)
		{
			scanf("%d",&x);
			c[i][j]=x;
		}
	}
	r=getrank(c);
//	printf("%d\n",r);
	
	clear(dp);
	dp[0][0]=1;
	for(i=1;i<=n;++i)//放第几列 
	{
		clear(dpt);
		for(j=0;j<=n;++j)//已有维数 
		{
			for(k=0;k<=r;++k)//已包含c的维数 
			{
				dpt[j][k]+=(dp[j][k]*p2[j])%mod;
				if(j<n)
				{
					if(k<r)
					{
						dpt[j+1][k]+=(dp[j][k]*(p2[n]-p2[r-k+j]))%mod;
						dpt[j+1][k+1]+=(dp[j][k]*(p2[r-k]-1))%mod*p2[j]%mod;
					}
					else
					{
						dpt[j+1][k]+=(dp[j][k]*(p2[n]-p2[j]))%mod;;
					}
				}
			}
		}
		swap(dp,dpt);
	}
	long long ans=0;
	for(i=r;i<=n;++i)
	{
		ans=(ans+dp[i][r]*p2[n*(n-i)])%mod;
	}
	printf("%I64d",(ans%mod+mod)%mod);
	return 0;
}
/*
2
0 1
1 0

6
*/
/*
10
1 0 0 1 1 1 0 0 1 0
0 0 0 1 1 0 0 0 1 0
0 0 1 1 1 1 1 1 1 1
0 1 0 1 0 0 0 1 1 0
0 0 1 0 1 1 1 1 1 1
1 0 0 0 0 1 0 0 0 0
1 1 1 0 1 0 0 0 0 1
0 0 0 1 0 0 1 0 1 0
0 0 0 1 1 1 0 0 0 0
1 0 1 0 0 1 1 1 1 1

741992411
*/


Measured memory_bytes: 1920
#include<stdio.h>
int main(){

	int w,h,i,j;
	while(1){
		scanf("%d %d",&h,&w);
		if(h==0 && w==0)	break;
		for(i=1;i<=h;i++){
			if(i%2!=0){
				for(j=1;j<=w;j++){
					if(j%2!=0)	printf("#");
					else		printf(".");
				}
				printf("\n");
			}else{
				for(j=1;j<=w;j++){
					if(j%2!=0)	printf(".");
					else		printf("#");
				}
				printf("\n");
			}
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 1792
#include <cstdio>
using namespace std;
int main(){
    int a,b;
    char op;
    scanf("%d %c %d",&a,&op,&b);
    if(op=='+'){
        printf("%d\n",a+b);    
    }
    else if(op=='-'){
        printf("%d\n",a-b);
    }
    return 0;
}

Measured memory_bytes: 128
N = int(input())
A = list(map(int,input().split()))
for i in range(N):
  if A[i] % 2 ==0:
    if A[i] % 3 ==0 or A[i] % 5 ==0:
      pass
      if i == N-1:
        print('APPROVED')
      else:
        pass
    else:
      print('DENIED')
      break
  else:
    if i == N-1:
      print('APPROVED')
    else:
      pass

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

using namespace std;

int f(int n) {
	int sum = 0;
	while (n) {
		sum += n % 10;
		n /= 10;
	}
	return sum;
}

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

	int t = f(n);
	if (!(n % t))
		cout << "Yes\n";
	else
		cout << "No\n";

}

Measured memory_bytes: 256
#amari = (10**100)%(10**9+7)
def sm(i):
    tmpp = 0
    for j in range(i):
        tmpp += j
    return tmpp,j

def bi(i,N):
    tmpp = 0
    for j in range(i):
        tmpp += N-j

    return tmpp,N-j

def main():
    N,K = map(int,input().split())
    ans = 0
    #loopnum = (N+1) - K + 1
    for i in range(K,N+2,1):
        if i == K:
            small,numsmall = sm(i)
            big,numbig = bi(i,N)
            #print(numsmall,numbig)
        else:
            small += numsmall+1
            numsmall += 1
            big += numbig - 1
            numbig -= 1
        ans += big - small + 1

    return (ans%(10**9+7))

print(main())


Measured memory_bytes: 9072
#include <stdio.h>
int main(void){
    int a, b, ans1=0, ans2=0, ans3=0;
    
    scanf("%d %d", &a, &b);
    
    ans1 = a + b;
    ans2 = a - b;
    ans3 = a * b;
    
    if(ans1 >= ans2 && ans1 >= ans3){
        printf("%d", ans1);
    } else if(ans2 >= ans1 && ans2 >= ans3){
        printf("%d", ans2);
    } else if(ans3 >= ans1 && ans3 >= ans2){
        printf("%d", ans3);
    }
    
    return 0;
}


Measured memory_bytes: 1712
#include<stdio.h>
int main ()
{
    int a,b,c;
    scanf ("%d %d %d",&a, &b ,&c);
    int t,t1;
    t=a;
    t1=b;
int t2 =c;
a=t2;
c =t1;
b=t;
printf("%d %d %d\n",a,b,c);







    return 0;
}


Measured memory_bytes: 128
S = list(input())
N = len(S)
List = []
for i in range(2**(N-1)):
    tmp = ''
    for j in range(N-1):
        if ((i>>j) & 1):
            tmp += '1'
        else:
            tmp += '0'
    List.append(list(tmp))
ans = 0
for i in range(len(List)):
    start = 0
    tmp = ''
    for j in range(len(List[i])):
        if List[i][j] == '0':
            tmp += S[j]
        if List[i][j] == '1':
            tmp += S[j]
            ans += int(tmp)
            tmp = ''
    tmp += S[-1]
    ans += int(tmp)

            
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h> //library
#define rep(i, n) for(int i = 0; i < (int)(n); i++) //for-loop (from 0)
#define reps(i,n) for(int i = 1; i <= (int)(n); i++) //for-loop (from 1)
#define all(x) (x).begin(),(x).end() //start-to-end iteration, mainly in upper_bound, lower_bound
#define SZ(x) ((int)(x).size()) //unsigned to signed

using namespace std;
using ll = long long; //long long
ll M = 1000000000 + 7;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; } //compare a,b and replace by greater
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; } //compare a,b and replace by smaller
ll qp(int a, ll b) { int ans = 1; do { if (b & 1)ans = 1ll * ans*a; a = 1ll * a*a; } while (b >>= 1); return ans; } //power
ll qp(int a, ll b, ll Mod = M) { int ans = 1; do { if (b & 1)ans = 1ll * ans*a%Mod; a = 1ll * a*a%Mod; } while (b >>= 1); return ans; } //power(mod)
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; } //gcd
int dx[4] = { 1,0,-1,0 }; //path
int dy[4] = { 0,1,0,-1 }; //path
ll RS(ll N, ll P, ll Mod = M) { if (P == 0)return 1; else if (P % 2 == 0) { ll sq = RS(N, P / 2, Mod); return sq*sq%Mod; } else { return N*RS(N, P - 1, Mod) % Mod; } } //power(mod)(repeat-square,fast)
ll nPr(ll n, ll r, ll Mod = M) { ll ans = 1; rep(i, r) { ans = ans * (n - i) % Mod; } return ans; } //permutation
ll nCr(ll n, ll r, ll Mod = M) { ll bunbo = 1; ll bunshi = 1; rep(i, r) { bunbo = bunbo * (i + 1) % Mod; bunshi = bunshi * (n - i) % Mod; } return bunshi * RS(bunbo, Mod - 2, Mod) % Mod; } //combination
struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
    vector<int> par_num;

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
        par_num.assign(N,1);
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;  //親がいない=自分自身が根
        return par[x] = root(par[x]); //xの親を、xの親の親につなぎ直す...つまり、ある木のノードを全て根につなぎ直す
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
        par_num[root(rx)]++;
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};
int main(void) {
  int N,M; cin >> N >> M;
  vector<int> nums(N);
  rep(i,N){
    cin >> nums[i];
    nums[i]--;
  }
  UnionFind tree(N);
  rep(i,M){
    int x,y; cin >> x >> y;
    tree.unite(x-1,y-1);
  }
  while(true){
    int flag = 0;
    rep(i,N){
      if (nums[i]!=i && tree.same(i,nums[i])){
        int temp = nums[nums[i]];
        nums[nums[i]] = nums[i];
        nums[i] = temp;
        flag = 1;
      }
    }
    if (flag==0) break;
  }
  int ans = 0;
  rep(i,N){
    if (nums[i]==i)ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int N;
    cin >>N;
    vector<int>vec(N);
    for(int i=0;i<N;i++){
        cin >>vec.at(i);
    }
    int M;
    cin >>M;
    for(int i=0;i<M;i++){
        int count=0;
        int P,X,C;
        cin >>P>>X;
        C=vec.at(P-1);
        vec.at(P-1)=X;
        for(int j=0;j<N;j++){
            count+=vec.at(j);
        }
        cout << count <<endl;
        vec.at(P-1)=C;
    }

}

Measured memory_bytes: 3568
#include<stdio.h>
int main(){
  int n,i,j,k,b,f,r,v,count[4][3][10]={0};


  scanf("%d",&n);

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

    scanf("%d %d %d %d",&b,&f,&r,&v);

    count[b-1][f-1][r-1] = count[b-1][f-1][r-1] + v;

  }

  for(i = 0;i <= 3;i++){
    for(j = 0;j <= 2;j++){
      for(k = 0;k <= 9;k++){
	printf(" %d",count[i][j][k]);
      }
      printf("\n");
    }
    if(i == 3)break;
    printf("####################\n");
  }
  return 0;
}

Measured memory_bytes: 612
n=int(input())
l=[list(map(int,input().split())) for i in range(n)]
L=[]
for j in range(n):
  L.append([l[j][0]+l[j][1],j])
L.sort()
L.reverse()
cta=0;ctb=0
for k in range(n):
  if k%2==0:
    cta+=l[L[k][1]][0]
  else:
    ctb+=l[L[k][1]][1]
print(cta-ctb)

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

typedef long long ll;
const ll MOD = 1e9 + 7;
const ll inf = 1LL<<60;
const double eps = 1e-9;

ll gcd(ll a, ll b)
{
    if (a < b) {
        a ^= b;
        b ^= a;
        a ^= b;
    }
    
    return b ? gcd(b, a % b) : a;
}
int main()
{
    ll a, b, g, cnt=0;
    cin >> a >> b;
    g = gcd(a, b);

    for(ll i = 2; i * i <= g; i++){
        if(g % i == 0){
            cnt++;
            while(g % i == 0) g /= i;
        }
    }
    if (g != 1) cnt++;
	cout << cnt+1 << endl;
    return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int t = sc.nextInt();

        int ans = 1001;
        for (int i = 0; i < n; i++){
            int ci = sc.nextInt();
            int ti = sc.nextInt();
            if( ti <= t){
                ans = Math.min(ans, ci);
            }
        }
        if(ans != 1001) {
            System.out.println(ans);
        } else {
            System.out.println("TLE");
        }
    }
}


Measured memory_bytes: 21844
n = gets.to_i
t = gets.strip.split.map(&:to_i)
m = gets.to_i
p = m.times.map{ gets.strip.split.map(&:to_i) }

m.times do |i|
    foo = t.dup
    s = p[i][0] - 1
    foo[s] = p[i][1]
    puts foo.inject(:+)
end



Measured memory_bytes: 1916
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
using Graph = vector<VecP>;
template <typename T>
using Vec1 = vector<T>;
template <typename T>
using Vec2 = vector<Vec1<T> >;
#define REP(i, m, n) for(ll i = (m); i < (n); ++i)
#define REPN(i, m, n) for(ll i = (m); i <= (n); ++i)
#define REPR(i, m, n) for(ll i = (m)-1; i >= (n); --i)
#define REPNR(i, m, n) for(ll i = (m); i >= (n); --i)
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPNR(i, n, 1)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define fs first
#define sc second
template <typename T>
bool chmax(T &a, const T b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T b){if(a > b){a = b; return true;} return false;}
template <typename T>
ll pow2(const T n){return (1LL << n);}
template <typename T>
void cosp(const T n){cout << n << ' ';}
void co(void){cout << '\n';}
template <typename T>
void co(const T n){cout << n << '\n';}
template <typename T1, typename T2>
void co(pair<T1, T2> p){cout << p.fs << ' ' << p.sc << '\n';}
template <typename T>
void co(const Vec1<T> &v){for(T i : v) cosp(i); co();}
template <typename T>
void co(initializer_list<T> v){for(T i : v) cosp(i); co();}
template <typename T>
void ce(const T n){cerr << n << endl;}
void sonic(){ios::sync_with_stdio(false); cin.tie(0);}
void setp(const ll n){cout << fixed << setprecision(n);}
constexpr int INF = 1e9+1;
constexpr ll LINF = 1e18+1;
constexpr ll MOD = 1e9+7;
// constexpr ll MOD = 998244353;
constexpr ld EPS = 1e-11;
const double PI = acos(-1);

int main(void){
	ll n, k;
	cin >> n >> k;
	VecD a(n);
	rep(i, n) cin >> a[i];

	ld l = 0, r = INF;
	while (r - l > 0.000001) {
		ld m = (l + r) / 2;
		// co(m);
		ll cnt = 0;
		rep(i, n) cnt += (a[i] - EPS) / m;
		if (cnt <= k) r = m;
		else
			l = m;
	}
	ll ans = l + 1 - EPS;
	co(ans);

	return 0;
}


Measured memory_bytes: 6308
#!/usr/bin/env python

def main():
    n = int(input())
    n -= 1
    name = ''
    abc = 'abcdefghijklmnopqrstuvwxyz'

    i = 1
    while n >= 0:
        q, r = divmod(n, 26)
        name = abc[r] + name
        n = q - 1
        i += 1
    print(name)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9172
x , y = map(int,input().split())
a = [1,3,5,7,8,10,12]
b = [4,6,9,11]
c = [2]
l = [a,b,c]
answer = "No"
for i in l:
  if x in i and y in i:
    answer = "Yes"
print(answer)



Measured memory_bytes: 8968
import numpy as np

H,W = list(map(int, input().split()))

l = [];
for i in range(H):
	r = input()
	if set(r) != {'.'}:
		k = list(r)
		l.append(k)

d = []
for i in range(W):
	p = [[j[i]] for j in l]
	result = []
	for sublist in p:
	    for item in sublist:
	        result.append(item)
	if set(result) == {'.'}:
		d.append(i)

nl = np.array(l)
itr = 0
for x in range(len(d)):
	nl = np.delete(nl, d[x]-itr, 1)
	itr += 1

for i in range(nl.shape[0]):
	for j in range(nl.shape[1]):
		print(nl[i,j],end='')
	print()


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

typedef long long ll;
const int mod = 1e9 + 7;

ll N;
vector<ll> a;

int main() {
    cin >> N;
    a.resize(N + 1);
    rep(i, N) cin >> a[i + 1];

    vector<ll> b(N + 1);

    for (int i = N; i >= 1; i--) {
        ll sum = 0;
        for (int j = i + i; j <= N; j += i) {
            sum ^= b[j]; 
        }
        b[i] = sum^a[i];
    }

    vector<ll> ans;
    for (ll i = 1; i <= N; i++) {
        if (b[i] == 1) {
            ans.push_back(i);
        }
    }

    cout << ans.size() << endl;
    rep(i, ans.size()) {
        cout << ans[i] << " ";
    }
    cout << endl;
}

Measured memory_bytes: 4980
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <algorithm>
#include <map>
#include <fstream>
#include <unordered_map>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef pair<ii, int> iii;
typedef vector<iii> viii;
typedef priority_queue<int> pqi;
typedef priority_queue<ii> pqii;
typedef map<int, int> mii;
typedef map<int, string> mis;
typedef map<string, int> msi;
typedef set<int> si;
typedef set<ll> sl;
typedef map<ll, ll> mll;
typedef queue<int> qi;
typedef queue<ii> qii;
typedef queue<iii> qiii;
typedef vector<string> vs;
typedef pair<ll, ll> iil;
typedef vector<iil> viil;
typedef long double ld;
typedef vector<vi> vvi;

#define pb push_back
#define mp make_pair
#define rep(i, n) for (int i = 0 ; i < n ; i++)
#define MOD 1000000007
#define INF 1000000000

void solve() {
    ll n;
    cin >> n;
    ll ans = 0;
    for (ll i = 2 ; i * i <= n ; i++) {
        ll ct = 0;
        while (n % i == 0) {
            n /= i;
            ct++;
        }
        ll tri = 0;
        ll inc = 1;
        while (tri <= ct) {
            tri += inc;
            inc++;
        }
        inc--;
        if (ct > 0) {
        }
        ans += inc - 1;
    }
    if (n > 1) {
        ans++;
    }
    cout << ans << endl;
}

void querySolve() {
    int t;
    cin >> t;
    for (int i = 0 ; i < t ; i++) {
        solve();
    }
}

int main() {
    solve();
    //querySolve();
}


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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MOD (1000000007)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> h(n);
    for (int i = 0; i < n; i++)
    {
        cin >> h[i];
    }

    int ans = 0;

    for (int i = 0; i < n; i++)
    {
        bool flg = true;
        for (int j = 0; j < i; j++)
        {
            if (h[i] < h[j])
            {
                flg = false;
            }
        }
        if (flg)
            ans++;
    }
    cout << ans << endl;
}

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

public class Hello
{
    private const int MOD_N = 1000000000 + 7;

    public static void Main()
    {
        var list = Console.ReadLine().Split(' ');
        var w = long.Parse(list[0]);
        var h = long.Parse(list[1]);
        var x = long.Parse(list[2]);
        var y = long.Parse(list[3]);

        var o = (x * 2 == w && y * 2 == h) ? 1 : 0;

        Console.WriteLine($"{w * h * 0.5} {o}");
    }

    private static int Comb(int m, int n)
    {
        var t = m - n;
        if (n > t)
            n = t;

        long numerator = 1;
        for (int i = 0; i < n; ++i)
        {
            numerator *= m - i;
            numerator %= MOD_N;
        }
        long denominator = 1;
        for (; n != 0; --n)
        {
            denominator *= n;
            denominator %= MOD_N;
        }

        var inv_denominator = ModInv((int)denominator, MOD_N);
        var ret = (int)(numerator * inv_denominator % MOD_N);

        return ret >= 0 ? ret : ret + MOD_N;
    }

    private static int ModInv(int a, int m)
    {
        int b = m, x = 1, y = 0;
        while (b != 0)
        {
            var t = a / b;
            a -= t * b;
            Swap(ref a, ref b);
            x -= t * y;
            Swap(ref x, ref y);
        }
        x %= m;
        return x >= 0 ? x : x + m;
    }

    private static void Swap<T>(ref T a, ref T b)
    {
        var t = a;
        a = b;
        b = t;
    }
}


Measured memory_bytes: 13268
#pragma GCC optimize("O3")
#pragma GCC target("avx2")
#include <iostream>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <unordered_set>
#include <set>

using namespace std;

typedef long long ll;
typedef long double ld;
const ll SIZE = 1e5 + 10;

vector<vector<ll>> vec;

#define fastInp cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);

int main() {
    fastInp;

    ll n;
    cin >> n;

    ll pr = 0, ans = 0;
    for (int i = 0; i < n; i++) {
        ll num;
        cin >> num;
        ll q = min(num, pr);
        ans += q;
        pr = 0;
        num -= q;
        ans += num / 2;
        num %= 2;
        pr = num;
    }

    cout << ans;
    return 0;
}

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

using namespace std;

int main()
{
    int N,M;
    cin>>N>>M;
    vector<int> height;
    int x;
    for(int i=0;i<N;i++)
    {
        cin>>x;
        height.push_back(x);
    }
    map<int,int> touched;
    map<int,int> seen;
    vector<int> check;
    for(int j = 0;j<N;j++)
    {
        check.push_back(1);
    }
    int count = 0;
    for(int j=0;j<M;j++)
    {
        int a,b;
        cin>>a>>b;
        touched[a]++;
        touched[b]++;
        if(height[a-1] > height[b-1])
        {
            check[a-1] *=1;
            check[b-1] *=0;
        }
        else if(height[a-1] < height[b-1])
        {
            check[a-1] *=0;
            check[b-1] *=1;
        }
        else if(height[a-1] == height[b-1])
        {
            check[a-1] *=0;
            check[b-1] *=0;
        }
        

    }

    for(int c:check)
    {
        if(c)
        {
            count++;
        }
    }

    cout<<count;

    return 0;
}

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

int main(){
	
	int n, k;
	scanf("%d %d",&n, &k);
	k--;
	char s[n];
	scanf("%s", s);
	if(s[k]=='A'){
		s[k]='a';
	}else if(s[k]=='B'){
		s[k]='b';
	}else{
		s[k]='c';
	}
	printf("%s",s);
	return 0;
}

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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) begin(r),end(r)
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)
#define vvl(v,w,h,init) vector<vector<ll>> v(w,vector<ll>(h,init))
#define mp(a,b) make_pair(a,b)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using pii = pair<int,int> ;
using pll = pair<ll,ll> ;

const int mod = 1000000007;
constexpr ll inf = ((1<<30)-1)*2+1 ;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0,1,-1,1,-1};
const int dx[] = {0,-1,0,1,1,-1,-1,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}
string st = "CODEFESTIVAL2016";
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll a = 0,b;
  string s;
  cin >> s;
  rep(i,16){
    if(s[i] != st[i])
    {
      ++a;
    }
  }
  cout << a << endl;
  return 0;
}



Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int W = sc.nextInt();
        int V = 0;
        int[] weights = new int[n];
        int[] values = new int[n];
        for (int i = 0; i < n; i++) {
            weights[i] = sc.nextInt();
            values[i] = sc.nextInt();
            V += values[i];
        }
        
        long[][] dp = new long[n + 1][V + 1];
        for (int i = 0; i <= n; i++) {
            for (int v = 0; v <= V; v++) {
                dp[i][v] = 100000000000l;
            }
        }
        
        dp[0][0] = 0;
        
        for (int i = 0; i < n; i++) {
            for (int v = 0; v <= V; v++) {
                if (values[i] <= v) {
                    dp[i + 1][v] = Math.min(dp[i][v - values[i]] + weights[i], dp[i][v]);
                } else {
                    dp[i + 1][v] = dp[i][v];
                }
            }
        }
        
        int answer = 0;
        for (int v = 0; v <= V; v++) {
            if (dp[n][v] <= W) {
                answer = v;
            }
        }
        
        // for (int i = 0; i < n; i++) {
        //     for (int v = 0; v <= V; v++) {
        //         System.out.print(dp[i][v] + " ");
        //         if (v == V) {
        //             System.out.println();
        //         }
        //     }
        // }
        
        System.out.println(answer);
    }
}

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

int main()
{
  int N, K;
  cin >> N >> K;
  vector<int> p(N);
  for (int i = 0; i < N; i++) cin >> p.at(i);
  sort(p.begin(), p.end());
  long ans = 0;
  for (int i = 0; i < K; i++) ans += p.at(i);
  cout << ans << endl;
}


Measured memory_bytes: 3628
// abc139-c
object Main extends App {
  val n = io.StdIn.readInt
  val hs = io.StdIn.readLine.split(" ").map(_.toInt)

  def solve(list: List[Int], prev: Int, tmp_count: Int, count: Int): Int = list match {
    case head::Nil  => {
      if (prev >= head) math.max(tmp_count+1, count)
      else math.max(tmp_count, count)
    }
    case head::tail => {
      if (prev >= head) solve(tail, head, tmp_count+1, math.max(tmp_count, count))
      else solve(tail, head, 0, math.max(tmp_count, count))
    }
  }

  val result = solve(hs.toList, 0, 0, 0)
  println(result)
}

Measured memory_bytes: 65384
#include <iostream>

using namespace std;

class Vector{
public:
	double x,y;

	Vector( double dx, double dy ) : x( dx ), y( dy ) {}
	Vector(){}

	Vector operator-( const Vector& lhs ){
		return Vector( x - lhs.x, y - lhs.y );
	}

	Vector& operator-=( const Vector& lhs ){
		x -= lhs.x;
		y -= lhs.y;
		return *this;
	}
};

double crossProduct( const Vector& rhs, const Vector& lhs ){
	return rhs.x * lhs.y - rhs.y * lhs.x;
}

bool line( Vector a, Vector b, Vector c ){
	b -= a;
	c -= a;

	double answer = crossProduct( b, c );

	if( answer < 0 ) return false;
	else if( answer > 0 ) return true;

	return false;
}

bool inTriangle( const Vector& a, const Vector& b, const Vector& c, const Vector& point ){
	bool answer[3];
	answer[0] = line( a, b, point );
	answer[1] = line( b, c, point );
	answer[2] = line( c, a, point );

	if( answer[0] == answer[1] && answer[1] == answer[2] ) return true;
	

	return false;
}



int main(int argc, char const* argv[])
{
	int n;
	Vector p1,p2,p3,k,s;

	cin >> n;
	for( int i = 0;i < n;i++ ){
		cin >> p1.x >> p1.y >> p2.x >> p2.y >> p3.x >> p3.y >> k.x >> k.y >> s.x >> s.y;

		bool answer[2];
		answer[0] = inTriangle( p1, p2, p3, k );
		answer[1] = inTriangle( p1, p2, p3, s );

		if( answer[0] == answer[1] ) cout << "NG" << endl;
		else cout << "OK" << endl;
	}
	return 0;
}

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

#pragma GCC optimize "O3"
#define rep(i,a,n) for(int i=a; i<n; i++)
typedef long long ll;
typedef pair<int,int> P;
const ll MOD = (int)1e9+7;
const ll INF = MOD*MOD;
const ll powll = 1LL<<1;

int main(void){
    int n; cin >> n;
    ll ans = 1;
    rep(i,0,n){
        ll t; cin >> t;
        ans =  ans/__gcd(ans, t)*t;
    }
    cout << ans << "\n";
} 

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

const int N = 1e5 + 100;

int n, k, q, a[N];

int main() {
	ios::sync_with_stdio(false), cin.tie(0);
	cin >> n >> k >> q;
	while(q--) {
		k--;
		int x;
		cin >> x;
		a[--x]++;
	}
	for (int i = 0; i < n; i++)
		cout << (a[i] + k <= 0? "No": "Yes") << '\n';
	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define loop2(i, s, n, a) for (int i = int(s); i < int(n); i += a)
#define loop(i, s, n) loop2(i, s, n, 1)
#define rep(i, n) loop(i, 0, n)

#define pb push_back
#define all(in) in.begin(),in.end()

using ll = long long;
using ull = unsigned long long;
using namespace std;

int main(){
    int n, m; cin >> n >> m;
    vector<vector<int>> data(n);
    vector<int> data2(m), data3(m);
    rep(i, m){
        int a, b; cin >> a >> b;
        a--; b--;
        data[a].push_back(b);
        data[b].push_back(a);
        data2[i] = a;
      	data3[i] = b;
    }
    int ans = 0;
    rep(i,m){
        int a = data2[i];
        int b = data3[i];
        data[a].erase(remove(data[a].begin(), data[a].end(), b), data[a].end());
      	data[b].erase(remove(data[b].begin(), data[b].end(), a), data[b].end());
        vector<bool> finder(n,false);
        queue<int> que;
        finder[0] = true;
        que.push(0);
        while(!que.empty()){
            int next = que.front(); que.pop();
            for(auto nn : data[next]){
                if(finder[nn] == false){
                    finder[nn] = true;
                    que.push(nn);
                }
            }
        }
        bool ans2 = true;
        rep(i,n) if(finder[i] == false) ans2 = false;
        if(ans2) ans++;
      	data[a].push_back(b);
      	data[b].push_back(a);
    }
    cout << m-ans << endl;
}

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

int main(){
  int n;
  int x[1000] = {}, y[1000] = {};
  double d1 = 0, d2 = 0, d3 = 0, dinf = 0;
  cin >> n;

  for (int i = 0; i<n; i++){
    cin >> x[i];
  }
  for (int i = 0; i<n; i++){
    cin >> y[i];
  }

  for (int i = 0; i<n; i++){
    d1 += fabs(x[i] - y[i]);
    d2 += pow(fabs(x[i]-y[i]),2);
    d3 += pow(fabs(x[i]-y[i]),3);

    if (dinf <= fabs(x[i]-y[i])){
      dinf = fabs(x[i]-y[i]);
    }
  }

  d2 = pow(d2,0.5);
  d3 = pow(d3,1.0/3.0);

  printf("%lf\n%lf\n%lf\n%lf\n", d1, d2, d3, dinf);

  return 0;
}

Measured memory_bytes: 3344