akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
 
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ", "; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const deque<T> &vec){ os << "deq["; for (auto v : vec) os << v << ", "; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const set<T> &vec){ os << "{"; for (auto v : vec) os << v << ", "; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_set<T> &vec){ os << "{"; for (auto v : vec) os << v << ", "; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ", "; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ", "; os << "}"; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa){ os << "(" << pa.first << ", " << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << ": " << v.second << ", "; os << "}"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << ": " << v.second << ", "; os << "}"; return os; }
template<typename T> void ndarray(vector<T> &vec, int len) { vec.resize(len); }
template<typename T, typename... Args> void ndarray(vector<T> &vec, int len, Args... args) { vec.resize(len); for (auto &v : vec) ndarray(v, args...); }
template<typename T> bool chmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool chmin(T &m, const T q) { if (q < m) {m = q; return true;} else return false; }
template<typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2> &l, const pair<T1, T2> &r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2> &l, const pair<T1, T2> &r) { return make_pair(l.first - r.first, l.second - r.second); }
#define f first
#define s second
 
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int len;
    string s;
    cin >> len >> s;
    int red = 0, ready = 0;
    for(int i = 0; i < len; i++)
        if(s[i] == 'R')
            red++;
    for(int i = 0; i < red; i++)
        if(s[i] == 'R')
            ready++;
    cout << red - ready;
}

Measured memory_bytes: 3756
n,m = list(map(int,input().split(' ')))
road = []
for i in range(m):
  x,y =(list(map(int,input().split(' '))))
  road.append(x)
  road.append(y)

ans = list(set(road))
ans.sort()
for i in range(1,n+1):
  print(road.count(i))

Measured memory_bytes: 3060
n = int(input())
a = list(int(input()) for i in range(n))
a.sort()
b = sum(a)

c = b

for j in range(100) :
  for i in range(n) :
    if c % 10 == 0 :
      c = b - a[i]
      if c == 0 :
        break
    else :
      break
  b = b - a[i]
  n = n - 1

print (c)

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

int main(){
  int n;
  cin >>n;
  bool ans=false;
  for(int i=0;i<=n/4;i++){
    for(int j=0;j<=n/7;j++){
      if(i*4+j*7==n){
        ans=true;
        break;
      }
    }
  }
  if(ans){
    cout <<"Yes" << endl;
  }
  else{
    cout <<"No" <<endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
const int mod = 1e9 + 7;
//const int mod = 998244353;
const ll infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;
void YesNo(bool j){cout << (j ? "Yes" : "No") << endl; return;}
void yesno(bool j){cout << (j ? "yes" : "no") << endl; return;}
template<class Head> void pt(Head&& head){cout << head << endl; return;}



int main() {
    int a,b;
    cin >> a >> b;
   
    if(a*4<b || a*2>b || b%2!=0) pt("No");
    else pt("Yes");
    return 0;
}


Measured memory_bytes: 3632
def main():
    N, M = map(int, input().split())
    H = list(map(int, input().split()))
    tenbou_dict = {i:0 for i in range(1, N+1, 1)}
    for i in range(M):
        A, B = map(int, input().split())
        tenbou_dict[A] = max(tenbou_dict[A], H[B-1])
        tenbou_dict[B] = max(tenbou_dict[B], H[A-1])
    answer = 0
    for k, v in tenbou_dict.items():
        if(H[k-1] > tenbou_dict[k]):
            answer += 1
    print(answer)

main()

Measured memory_bytes: 91192
#include<bits/stdc++.h>
using namespace std;
string s1,s2;
int main(){
    getline(cin,s1);getline(cin,s2);
    cout<<s1[0];
    for(int i=0;i<s1.size()+s2.size()-1;i++)
        if(i%2) cout<<s1[i/2+1];
        else    cout<<s2[i/2];
}

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

const int nm = 1e6;
int n, a[nm], d[nm + 1];
vector<int> prime;
bool b[nm + 1];

int main() {
	fill(b + 2, b + nm + 1, 1);

	for (int i = 2; i <= nm; ++i) {

		if (!b[i])
			continue;
		prime.emplace_back(i);
		if (i <= 1000)
			for (int j = i * 2; j <= nm; j += i)
				b[j] = 0;
	}

	cin >> n;
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
		int x = a[i];
		for (int j = 2; j * j <= x; ++j) {
			if (x % j)
				continue;
			++d[j];
			while (!(x % j))
				x /= j;
		}
		if (x > 1)
			++d[x];

	}

	int m;
	for (int i = 2; i < nm + 1; ++i)
		m = max(m, d[i]);

	if (m <= 1)
		cout << "pairwise coprime" << endl;
	else if (m < n)
		cout << "setwise coprime" << endl;
	else
		cout << "not coprime" << endl;
}


Measured memory_bytes: 12484
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<climits>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<bitset>
#include<iomanip>
#include<deque>
using namespace std;

#define rep(i,j,n) for(int i=(j);i<(n);i++)
#define rep2(i,j,n) for(int i=(j);i<=(n);i++)
#define all(i) i.begin(),i.end()

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef pair<int, int> pi;
typedef long long i64;

int main() {
	int n, z, w;
	cin >> n >> z >> w;
	vi a(n);
	rep(i, 0, n) {
		cin >> a[i];
	}
	int ans;
	if (n == 1) {
		ans = abs(a[n - 1] - w);
	}
	else {
		ans = max(abs(a[n - 1] - w), abs(a[n - 2] - a[n - 1]));
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
while xy = gets.chomp
  break if xy == "0 0"
  x = xy.split[0].to_i
  m = []
  x.times{|i|
    m[i] = gets.chomp.split("")
  }
  i = 0
  j = 0
  done = {}
  loop do
    done[[i,j]] = true
    case m[i][j]
    when ">"
      j += 1
    when "<"
      j -= 1
    when "^"
      i -= 1
    when "v"
      i += 1
    when "."
      puts "#{j} #{i}"
      break
    end
    if done[[i,j]]
      puts "LOOP"
      break
    end
  end
end

Measured memory_bytes: 8956
#include <iostream>
#include <iosfwd>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <cassert>
#include <cctype>
#include <climits>
#include <vector>
#include <bitset>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <deque>
#include <string>
#include <list>
#include <iterator>
#include <sstream>
#include <complex>
#include <fstream>
#include <functional>
#include <numeric>
#include <utility>
#include <algorithm>
#include <assert.h>
#include <unordered_map>

using namespace std;

int main()
{
  ios::sync_with_stdio(false);cin.tie(0);
  string s, t;
  cin >> s >> t;
  int slen = s.length();
  int tlen = t.length();
  int dp[slen + 5][tlen + 5];
  for (int i = 0; i <= slen; i++)
  {
    for (int j = 0; j <= tlen; j++)
    {
      if (i == 0 || j == 0)
        dp[i][j] = 0;
      else if (s[i - 1] == t[j - 1])
        dp[i][j] = dp[i - 1][j - 1] + 1;
      else
        dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
    }
  }
  int i = slen; int j = tlen;
  string ans = "";
  while(i > 0 && j > 0)
  {
    if (s[i - 1] == t[j - 1])
    {
      ans += s[i - 1];
      i--;
      j--;
    }
    else if(dp[i - 1][j] >= dp[i][j - 1])
      i--;
    else
      j--;
  }
  reverse(ans.begin(), ans.end());
  cout << ans ;
  return 0;
}


Measured memory_bytes: 35456
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define mod 1000000007
using namespace std;
ll binpow(ll x,ll y)/* (x^y)%p in O(log y) */{ll res=1;while (y > 0){if(y&1)res=(res*x);y = y>>1;x=(x*x);}return res;}
ll binpowmod(ll x,ll y,ll p)/* (x^y)%p in O(log y) */{ll res=1;x=x%p;while (y > 0){if(y&1)res=(res*x)%p;y = y>>1;x=(x*x)%p;}return res;}
ll mod_inverse(ll n,ll p)/* Returns n^(-1) mod p */{return binpowmod(n,p-2,p);}
ull gcd(ull x,ull y)
{
    if(y==0)
        return x;
    return gcd(y,x%y);
}
bool comp(pair<int,int> x,pair<int,int> y)
{
    if(x.first<y.first)
        return true;
    else if(x.first==y.first)
        return x.second>y.second;
    else
        return false;
}
bool comp_pairs_by_s(pair<ll,ll> &x ,pair<ll,ll> &y)
{
    return x.second<y.second;
}
bool isPowerOfTwo (ll x)  
{  
    /* First x in the below expression is for the case when x is 0 */
    return x && (!(x&(x-1)));  
}

class cmp      //comparator for priority_queue 
{               //declaration: priority_queue<int,vector<int>,cmp>
public:         
    bool operator()(pair<int,int> A,pair<int,int> B)
    {
        if(abs(A.first-A.second)==abs(B.first-B.second))
            return A.first>B.first;
        return abs(A.first-A.second)<abs(B.first-B.second);
    }
};
// int prime[100005]={0};
// void sieve(void)
// {
//  int i,j;
//  for(i=0;i<100005;i++)
//         prime[i]=1;
//  prime[0]=0,prime[1]=0;
//  for(i=2;i<=sqrt(100005);i++){
//      if(prime[i]){
//          for(j=i*i;j<100005;j+=i){
//              prime[j]=0;
//          }
//      }
//  }
    
// }
void swap(int &x,int &y){
    int temp=x;
    x=y;
    y=temp;
}

void solve()
{   
    int n;
    cin>>n;
    unordered_map<int,int> m;
    for(int i=0;i<n;i++){
        int x;
        cin>>x;
        m[x]++;
    }
    int cnt=0;
    if(m.count(1)){
        if(m[1]>1)
            cout<<0;
        else
            cout<<1;
        return;
    }
    for(auto it:m){
        if(it.second>1) continue;
        int num=it.first;
        bool flag=true;
        for(int i=2;i*i<=num;i++){
            if(num%i==0){
                if(m.count(i) || m.count(num/i)){
                    flag=false;
                    break;
                }
            }
        }
        if(flag)
            cnt++;
    }
    cout<<cnt;


}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
}


Measured memory_bytes: 11348
#include "bits/stdc++.h"
using namespace std;
typedef long long int lint;
typedef pair<lint, lint> plint;
typedef pair<double long, double long> pld;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(lint i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(lint i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
template<typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first - r.first, l.second - r.second); }
const lint MOD = 1e9 + 7, INF = 1e18;

int main() {
	cin.tie(0); ios_base::sync_with_stdio(false);
	lint A, V, B, W, T;
	cin >> A >> V >> B >> W >> T;
	if ((V - W) * T >= abs(B - A)) cout << "YES";
	else cout << "NO";
}

Measured memory_bytes: 3688
#include <iostream>
#include <algorithm>
#include <numeric>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl


int main() {
    ll h, w;
    string shape;
    while(1){
        cin >> h >> w;

        if(h == 0 && w == 0){
            break;
        }
        

        for(int i = 0;i < h;i++){
            shape = "";
            for(int j = 0;j < w;j++){
                if(i == 0 || i == h - 1 || j == 0 || j == w - 1){
                    shape += "#";
                } else {
                    shape += ".";
                }
            }
            cout << shape << endl;
        }
        cout << "" << endl;
    }

    return 0;
}


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

typedef long long ll;

int main()
{
    int H, W;
    cin >> H >> W;
    vector<string> S;
    for (int i = 0; i < H; ++i)
    {
        string temp;
        cin >> temp;
        S.push_back(temp);
    }
    // header
    for (int i = 0; i < W + 2; ++i)
    {
        cout << "#";
    }
    cout << endl;
    for (int i = 0; i < H; ++i)
    {
        cout << "#";
        cout << S[i];
        cout << "#";
        cout << endl;
    }
    //footer
    for (int i = 0; i < W + 2; ++i)
    {
        cout << "#";
    }
    cout << endl;
}


Measured memory_bytes: 3596
#include <iostream>
#include <cstdio>
#include <string>
#include <cctype>
using namespace std;


#define M 2011


int powmod(int x, int y){
	int a = 1;
	for(; y; y >>= 1){
		if(y & 1) a = a * x % M;
		x = x * x % M;
	}
	return a;
}

int n;
string s[22];

void scan(int top, int bottom, int begin, int &y, int &x){
	x = y = -1;

	for(;; ++begin){
		for(int i = top; i <= bottom; ++i){
			if( s[i][begin] != '.' ){
				y = i;
				x = begin;
				return;
			}
		}
	}
}

int expr(int, int, int, int&);
int term(int, int, int, int&);
int factor(int, int, int, int&);


int expr(int top, int base, int bottom, int &pos){
	int a = term(top, base, bottom, pos);

	while(1){
		++pos;

		if( s[base][pos] == '+' ){
			pos += 2;
			a = (a + term(top, base, bottom, pos)) % M;
		}
		else if( s[base][pos] == '-' ){
			pos += 2;
			a = (a - term(top, base, bottom, pos) + M) % M;
		}
		else{
			--pos;
			break;
		}
	}
	return a;
}

int term(int top, int base, int bottom, int &pos){
	int a = factor(top, base, bottom, pos);
	
	while(1){
		++pos;
		if( s[base][pos] == '*' ){
			pos += 2;
			a = a * factor(top, base, bottom, pos) % M;
		}
		else{
			--pos;
			break;
		}
	}
	return a;
}

int factor(int top, int base, int bottom, int &pos){
	if( s[base][pos] == '-' ){
		if( s[base][pos + 1] == '-' ){
			int y, x;
			scan(top, base - 1, pos + 1, y, x);
			int a = expr(top, y, base - 1, x);
			
			scan(base + 1, bottom, pos + 1, y, x);
			int b = expr(base + 1, y, bottom, x);
			int c = powmod(b, M - 2);

			while( s[base][pos] == '-' ){
				++pos;
			}

			return (a * c) % M;
		}
		else{
			pos += 2;
			int a = factor(top, base, bottom, pos);
			return (M - a) % M;
		}
	}
	else{
		int a = -1;

		if( s[base][pos] == '(' ){
			pos += 2;
			a = expr(top, base, bottom, pos);
			pos += 2;
		}
		else{
			if( !isdigit(s[base][pos]) ){
				throw 1;
			}

			a = s[base][pos] - '0';
			++pos;
		}
		
		if( isdigit(s[base - 1][pos]) ){
			a = powmod(a, s[base - 1][pos] - '0');
			++pos;
		}

		return a;
	}
}


int main(){
	while( cin >> n, n != 0 ){
		for(int i = 0; i < 22; ++i) s[i].clear();
		for(int i = 1; i <= n; ++i) cin >> s[i];
		for(int i = 0; i <= n + 1; ++i) s[i].resize(84, '.');

		int y, x;
		scan(1, n, 0, y, x);
		cout << expr(1, y, n, x) << '\n';
	}
}

Measured memory_bytes: 1216
#include <stdio.h>
 
int main(void) {
 
	// ??????????????\??????????????°?????\???????????°
	int mid, end, retest;
	
	// ?????°?????\???
	while(1) {
		
		scanf("%d %d %d", &mid, &end, &retest);
		
		if(mid == -1 && end == -1 && retest == -1)
			break;
			
		if(mid == -1 || end == -1) {
			
			printf("F\n");
			
		} else if(mid + end >= 80) {
			
			printf("A\n");
			
		} else if(mid + end >= 65 && mid + end < 80) {
			
			printf("B\n");
			
		} else if(mid + end >= 50 && mid + end < 65) {
			
			printf("C\n");
			
		} else if(mid + end >= 30 && mid + end < 50) {
			
			if(retest >= 50) {
				
				printf("C\n");
				
			} else {
			
			printf("D\n");
			
			}
			
		} else if(mid + end < 30) {
			
			printf("F\n");
			
		}
	}
	return 0;
}

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

using namespace std;

typedef long long ll;

int H, W, N;
string S, T;

struct bds{int lr, ur, lc, uc;};

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

	cin >> H >> W >> N;

	int sr, sc;
	cin >> sr >> sc;

	cin >> S >> T;
	reverse(S.begin(), S.end());
	reverse(T.begin(), T.end());

	vector<bds> dp(N+1);
	dp[0] = (bds){1, H, 1, W};

	for(int i = 0; i < N; i++){
		bds b = dp[i];
		if(T[i] == 'L'){
			b.uc = min(W, b.uc + 1);
		}else if(T[i] == 'R' ){
			b.lc = max(1, b.lc - 1);
		}else if(T[i] == 'U'){
			b.ur = min(H, b.ur + 1);
		}else{
			b.lr = max(1, b.lr - 1);
		}

		if(S[i] == 'L'){
			b.lc += 1;
		}else if(S[i] == 'R' ){
			b.uc -= 1;
		}else if(S[i] == 'U'){
			b.lr += 1;
		}else{
			b.ur -= 1;
		}

		if(b.uc < b.lc || b.ur < b.lr){
			cout << "NO" << endl;
			return 0;
		}

		dp[i+1] = b;
	}

	bds b = dp[N];
	if(b.lr <= sr && sr <= b.ur && b.lc <= sc && sc <= b.uc){
		cout << "YES" << endl;
	}else{
		cout << "NO" << endl;
	}
}


Measured memory_bytes: 3992
#include<stdio.h>
int main()
{
    int c,d,i=0;
    scanf("%d%d",&c,&d);
    if(c<10)
    {
        i=d+100*(10-c);
    }
    else if(c>=10)
    {
        i=d;
    }
    printf("%d\n",i);

return 0;
}


Measured memory_bytes: 128
#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <time.h>

using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
	int n;
	scanf("%d", &n);
	if(n==2){
		printf("%d\n", 1);
		return 0;
	}
	vector<int> v[100000];
	for(int i=0; i<n-1; i++){
		int a, b;
		scanf("%d %d", &a, &b);
		v[a].push_back(b);
		v[b].push_back(a);
	}
	int i0=-1;
	for(int i=0; i<n; i++){
		if(v[i].size()>2){
			i0=i;
			break;
		}
	}
	if(i0==-1){
		printf("%d\n", 1);
      return 0;
	}
	int d[100000];
	fill(d, d+n, -1);
	d[i0]=0;
	queue<int> que;
	que.push(i0);
	while(!que.empty()){
		int x=que.front();
		que.pop();
		for(int i=0; i<v[x].size(); i++){
			if(d[v[x][i]]<0){
				d[v[x][i]]=d[x]+1;
				que.push(v[x][i]);
			}
		}
	}
	vector<P> dist;
	for(int i=0; i<n; i++){
		dist.push_back(P(-d[i], i));
	}
	sort(dist.begin(), dist.end());
	int e[100000]={};
	int ans=0;
	for(int i=0; i<n; i++){
		int x=dist[i].second;
		int count=0;
		for(int j=0; j<v[x].size(); j++){
			if(d[v[x][j]]<d[x]) continue;
			if(e[v[x][j]]==1){
				e[x]=1;
				continue;
			}
			count++;
		}
		if(count>1){
			ans+=(count-1);
			e[x]=1;
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 8568
#include <bits/stdc++.h>
#define ll long long
#define ii pair<ll, ll>
#define vi vector<ll>
#define vii vector<ii>
#define vs vector<string>
#define si set<ll>
#define endl "\n"
#define pb push_back
#define x first
#define y second
//g++ -std=c++11 -Wall -Wextra -pedantic-errors main.cpp -o main
const int ms = 2*1e5 + 5, base = 31, mod = 1e9 + 7;
using namespace std;

int main(){
	ios::sync_with_stdio(false), cin.tie(0);
	
	string ss; cin >> ss;
	
	int n = ss.size();
	ss = "";
	while(n--) ss += "x";
	
	cout << ss << endl;
	
	return 0;
}

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

class TSort{
public:
  int V;
  vector<unordered_set<int> > in,out;
  vector<int> tp;
  TSort():V(0){}
  TSort(int V):V(V),in(V),out(V){}
  
  void add_edge(int from,int to){
    assert(from >= 0 && to >= 0);
    assert(from < V && to < V);
    out[from].insert(to);
    in[to].insert(from);
  }

  vector<int> dfs(){
    vector<int> visited(V,0);
    
    function<void(int)> dfs = [&](int pos){
      if(visited[pos]++) return;
      for(int nx:out[pos]) dfs(nx);
      tp.push_back(pos);
    };
    
    tp.clear();
    for(int i=0;i<V;i++) dfs(i);
    reverse(tp.begin(),tp.end());
    return tp;
  }

  vector<int> bfs(){
    auto tmp = in;
    tp.clear();
    queue<int> Q;
    for(int i=0;i<V;i++)if(in[i].empty()) Q.push(i);
    
    while(!Q.empty()){
      int v = Q.front();Q.pop();
      tp.push_back(v);
      for(int nx:out[v]){
        if(in[nx].size() == 1) Q.push(nx);
        assert(in[nx].count(v));
        in[nx].erase(v);
      }     
    }
    for(int i=0;i<V;i++) if(!in.empty()) tp.clear(); // exist loop
    tmp = in;
    return tp;
  }
};


int main(){
  int n,m;
  cin>>n>>m;
  TSort A(n);
  
  for(int i=0,a,b;i<m;i++)cin>>a>>b,A.add_edge(a,b);
  
  A.dfs();
  for(int i=0;i<n;i++)cout<<A.tp[i]<<endl;
  return 0;
}



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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin >> N;
  vector<vector<int>> G(N);
  for (int i = 0; i < N - 1; i++) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    G[a].emplace_back(b);
    G[b].emplace_back(a);
  }
  int cnt = 1;
  vector<int> D(N, 0);
  D[0] = 1, D[N - 1] = -1;
  queue<int> que;
  que.push(0), que.push(N - 1);
  while (!que.empty()) {
    int u = que.front();
    que.pop();
    for (int v : G[u]) {
      if (D[v] != 0) continue;
      D[v] = D[u];
      if (D[v] == 1) cnt++;
      que.push(v);
    }
  }
  if (cnt > N - cnt) {
    cout << "Fennec" << '\n';
  } else {
    cout << "Snuke" << '\n';
  }
  return 0;
}


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

signed main() {
    string s;
    cin >> s;
    vector<int> res(2019, 0);
    int ex;
    int k = 0;
    res[k]++;
    int ten = 1;
    int n = s.size();
    rep(i, n) {
        ex = s[n - 1 - i] - '0';
        k = (k + ex * ten) % 2019;
        ten = (ten * 10) % 2019;
        // cout << k << endl;
        res[k]++;
    }
    int ans = 0;
    for (auto i : res) {
        ans += i * (i - 1) / 2;
    }
    printf("%lld", ans);
}

Measured memory_bytes: 3816
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef pair<int, int> P;
const int INF = 1e9;
const int MAX_V = 16;

void dijkstra(const vector< vector<P> > &cost, int V, int s, int *closed){
  priority_queue<P, vector<P>, greater<P> > open;
  open.push(P(0, s));
  REP(i, V) closed[i] = INF;
  closed[s] = 0;
  while(!open.empty()){
    P tmp = open.top(); open.pop();
    int now = tmp.second, c = tmp.first;
    if(closed[now] < c) continue;
    closed[now] = c;
    REP(i, cost[now].size()){
      int next = cost[now][i].second, nc = cost[now][i].first;
      if(nc == INF || c + nc >= closed[next]) continue;
      closed[next] = c + nc;
      open.push(P(closed[next], next));
    }
  }
}

int chinesePostman(const int &V, const vector< vector<P> > &G) {
  int total = 0;
  vector<int> odds;
  REP(i, V) {
    REP(j, G[i].size())
      total += G[i][j].first;
    if ((int)(G[i].size()) % 2) odds.push_back(i);
  }
  total /= 2;
  int n = odds.size(), N = (1 << n);
  int w[n][n]; // make odd vertices graph
  REP(i, n) {
    int closed[V];
    dijkstra(G, V, odds[i], closed);
    REP(j, n) w[i][j] = closed[odds[j]];
  }
  int dp[N]; // DP for general matching
  REP(S, N) dp[S] = INF;
  dp[0] = 0;
  for (int S = 0; S < N; ++S)
    REP(i, n)
      if (!(S & (1 << i)))
        FOR(j, i + 1, n)
          if (!(S & (1 << j)))
            dp[(S | (1 << i) | (1 << j))] = min(dp[(S | (1 << i) | (1 << j))], dp[S] + w[i][j]);
  return total + dp[N - 1];
}

int main() {
  int V, E; cin >>V >>E;
  vector< vector<P> > G(V);
  REP(i, E){
    int f, t, c; cin >>f >>t >>c;
    G[f].push_back(P(c, t));
    G[t].push_back(P(c, f));
  }
  cout <<chinesePostman(V, G) <<endl;
  return 0;
}

Measured memory_bytes: 3204
//Author:- S_Aditya

#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;
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define ll long long 
#define scn(n) scanf("%d",&n)
#define lscn(n) scanf("%lld",&n)
#define lpri(n) printf("%lld",n)
#define pri(n) printf("%d",n)
#define pln() printf("\n")
#define priln(n) printf("%d\n",n)
#define lpriln(n) printf("%lld\n",n)
#define rep(i,init,n) for(int i=init;i<n;i++)
#define pb push_back     
#define mp make_pair
#define F first
#define S second
#define gcd __gcd
#define inf INT_MAX
#define ninf INT_MIN
const ll mod=1e9+7;         
const int N=1e5+4;

//dp[i][j] tells the minimum weight required to gain a profit of j considering the
//first i items.

ll dp[104][N]; 

int main()                  
{
    int n,w;
    
    scn(n); scn(w);
    
    int wt[n+1],cost[n+1];
    
    rep(i,1,n+1)
    {
        scn(wt[i]); scn(cost[i]);
    }
    
    dp[0][0]=0;
    
    rep(i,1,N)
    dp[0][i]=1e15;
    
    rep(i,1,n+1)
    {
        rep(j,0,N)
        {
            dp[i][j]=dp[i-1][j];
            
            if(j-cost[i]>=0 and dp[i-1][j-cost[i]]!=1e15)
            dp[i][j]=min(dp[i][j],dp[i-1][j-cost[i]]+1LL*wt[i]);
        }
    }
    
    int ans=0;
    
    rep(i,1,N)
    if(dp[n][i]<=w)
    ans=i;
    
    pri(ans);
    
} 

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

using namespace std;

int main()
{
        int64_t a, b, c, i, j ,k, temp1, temp2;
        int flag = 0;
        cin >> a >> b >> c >> k;
        for (i = 0; i <= k; i++)
        {
                temp1 = c * pow(2, i);
                temp2 = b * pow(2, k - i);
                if (temp1 > temp2 && temp2 > a)
                {
                        flag = 1;
                }
        }

        if (flag)
        {
                puts("Yes");
        }
        else
        {
                puts("No");
        }

        return 0;
}

Measured memory_bytes: 4068
#include <iostream>
using namespace std;
 
int main() {
    int N;
    cin >> N;
    int array[N];
    for (int i = 0; i < N; i++)
    {
        cin >> array[i];
    }
    long long int presum[N+1];
    presum[0] = 0;
    for (int i = 0; i < N; i++)
    {
        presum[i+1] = presum[i] + array[i];
    }

    sort(presum, presum + N + 1);
    long long int now = presum[0];
    long long int count = 0, sum = 0;
    for (int i = 1; i < N + 1; i++)
    {
        if (presum[i] == now) {
            count += 1;
        } else {
            count = 0;
            now = presum[i];
        }
        sum += count;
    }
    cout << sum << endl;
}

Measured memory_bytes: 2560
N, C, K = map(int, input().split())
T = sorted([int(input()) for i in range(N)])
s = 0
array = [T[0]]
arrays = []
for i in range(1, N):
    if ((T[i] - T[s]) <= K) and (len(array) < C):
        array.append(T[i])
    else:
        arrays.append(array)
        array = [T[i]]
        s = i
print(len(arrays + [array]))

Measured memory_bytes: 18004
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		Main mainObj = new Main();
		mainObj.solve();
	}

	public void solve() throws IOException {
		FastScanner fs = new FastScanner();
		int a = fs.nextInt();
		int a2  = a*a;
		int a3 = a*a*a;
		
		System.out.println(a+a2+a3);
	}

	

	public class FastScanner {

		BufferedReader reader;
		private StringTokenizer st;

		public FastScanner() {
			st = null;
			reader = new BufferedReader(new InputStreamReader(System.in));
		}

		public String next() throws IOException {
			if (st == null || !st.hasMoreElements()) {
				st = new StringTokenizer(reader.readLine());
			}
			return st.nextToken();
		}

		public String nextLine() throws IOException {
			st = null;
			String readLine = null;
			readLine = reader.readLine();
			return readLine;
		}

		public int nextInt() throws NumberFormatException, IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws NumberFormatException, IOException {
			return Long.parseLong(next());
		}

		public int[] nextIntArr(int n) throws NumberFormatException, IOException {
			int[] retArr = new int[n];
			for (int i = 0; i < n; i++) {
				retArr[i] = nextInt();
			}
			return retArr;
		}

		public long[] nextLongArr(int n) throws NumberFormatException, IOException {
			long[] retArr = new long[n];
			for (int i = 0; i < n; i++) {
				retArr[i] = nextLong();
			}
			return retArr;
		}

		public void close() throws IOException {
			reader.close();
		}
	}

}


Measured memory_bytes: 32804
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <iomanip>
#include <cmath>
#include <vector>
#include <set>
#include <algorithm>

using namespace std;

int N, M, Q;
vector<int> a, b, c, d;
int ans = 0;

void dfs(vector<int>A)
{
    if(A.size() == N+1)
    {
        int now = 0;
        for (int i = 0; i < Q; i++)
        {
            if (A[b[i]] - A[a[i]] == c[i])
            {
                now += d[i];
            }
        }
        ans = max(now, ans);
        return;
    }

    A.push_back(A.back());
    while(A.back() <= M)
    {
        dfs(A);
        A.back()++;
    }
}

int main()
{
    cin >> N >> M >> Q;
    a = b = c = d = vector<int>(Q);

    for (int i = 0; i < Q; i++)
    {
        cin >> a[i] >> b[i] >> c[i] >> d[i];
    }

    dfs(vector<int>(1, 1));

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


Measured memory_bytes: 3648
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
typedef  long long ll;
ll gcd(ll x,ll y){
   if(y==0) return x;
   else return gcd(y,x%y);
}
ll lcm(ll x,ll y){
   return x/gcd(x,y)*y;
}
using namespace std;
int main(){
   int k,s;
   cin>>k>>s;
   int ans=0;
   rep(x,k+1){
       rep(y,k+1){
           int z=s-x-y;
        if(0<=z && z<=k) ans++;
       }
   }
   cout<<ans;

   
return 0;
}


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

using namespace std;

int a[100];

int main()
{
	int n,x,j;
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>a[i];
	for(int i=0;i<n-1;i++)
		cout<<a[i]<<' ';
	cout<<a[n-1]<<endl;
	for(int i=1;i<n;i++)
	{
		x=a[i];
		j=i-1;
		while(j>=0&&a[j]>x)
		{
			a[j+1]=a[j];
			j--;
		}
		a[j+1]=x;
		for(int k=0;k<n-1;k++)
			cout<<a[k]<<' ';
		cout<<a[n-1]<<endl;
	}
} 


Measured memory_bytes: 3112
/**
 *    author:  dflmkwr
 *    created: 12.09.2020 14:24:18
**/

#include <iostream>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int x;
  cin >> x;
  if (x < 30) cout << "No" << "\n";
  else cout << "Yes" << "\n";
  return 0;
}

Measured memory_bytes: 3568
N = gets.chomp!.to_i
S = gets.chomp!
h = Hash.new

for i in 0..N - 1 do
	if !h.key?(S[i]) then
		h[S[i]] = S.count(S[i]) + 1	
	end
end

output = 1
h.each{|key, value|
	output = output * value
}
output = output % 1000000007
output = output - 1
p output


Measured memory_bytes: 1916
#include<iostream>
#include<string>
#include<algorithm>    
#include<cmath>
#include<map>
#include<vector>
#include<math.h>
#include<stdio.h>
#include<stack>
#include<queue>
#include<tuple>
#include<cassert>
#include<set>
#define int long long
using namespace std;
const int INF = 1000000000000;
const int mod = 1000000007;
int a[345678], ans[345678];
signed main() {
	int n, m, cnt = 0; cin >> n;
	for (int h = 0; h < n; h++) {
		cin >> a[h];
	}
	for (int h = 0; h < n; h++) {
		if (h == 0) { ans[cnt] = a[h]; cnt++; }
		else {
			if (ans[cnt - 1] >= a[h]) { ans[cnt] = a[h]; cnt++; }
			else {
				for (int i = 0; i < cnt; i++) {
					if (ans[i] < a[h]) { ans[i] = a[h]; break; }
				}
			}
		}
	}
	cout << cnt << endl;
	return 0;
}

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

typedef long long ll;

int main()
{
    int H, W;
    cin >> H >> W;
    vector<vector<int>> dp(10, vector<int>(10));
    for(int i = 0; i <= 9; i++){
        for(int j = 0; j<= 9; j++){
            int a;
            cin >> a;
            dp.at(i).at(j) = a; 
        }
    }
    int V = 10;
    for (int k = 0; k < V; k++) {
        for (int i = 0; i < V; i++) {
            for (int j = 0; j < V; j++) {
                dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);
            }
        }
    }
    ll answer = 0;
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            int num;
            cin >> num;
            if(num == -1){
                continue;
            }
            answer += dp.at(num).at(1);
        }
    }
    cout << answer << endl;
    return 0;
}


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

int main()
{
    long long N;cin >>N;
    long long min_ = 1000000000000;
    for(int i=1;i<=(int)sqrt(N);++i)
    {
        if(N%i==0)
        {
            long long j = N / i;
            min_ = min(min_,i+j-2);
        }
    }

    cout << min_ << endl;
    
}

Measured memory_bytes: 256
/*
 *Author : zsenshi
 DP 
 */
#include <bits/stdc++.h> //Only for gcc compilers
#define mt make_tuple
#define eb emplace_back
#define pb push_back
#define dg(x) cout << #x << ":"<<x<<endl
#define dg2(x,y) cout<<#x<<':'<<x<<' '<<#y<<':'<<y<<endl
#define dg3(x,y,z) cout<<#x<<':'<<x<<' '<<#y<<':'<<y<<' '<<#z<<':'<<z<<endl
#define dg4(x,y,z,zz) cout<<#x<<':'<<x<<' '<<#y<<':'<<y<<' '<<#z<<':'<<z<<' '<<#zz<<':'<<zz<<endl
#define rep(i,begin,end) for(__typeof(end) i = (begin)-((begin) > (end)); i != (end) - ((begin) > (end)); i += 1-2*((begin) > (end)))
using namespace std;
typedef vector<vector<int>> vvi;
typedef pair<int,int> pii;
typedef vector<pii> vii;
typedef vector<int> vi;
typedef vector<vector<pii>> vvpi;

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, k;
  cin >> n >> k;
  int h[n];
  int dp[n];
  for(int i = 0; i < n; i++){
    cin >> h[i];
    dp[i] = INT_MAX;
  }
  dp[0] = 0;
  for(int i = 0; i < n; i++){
    for(int j = 1; j <= k; j++){ 
      int val = i-j;
      if(val >= 0){
        dp[i] = min(dp[i],dp[val] + abs(h[i] - h[val]));
      }
    }
  }
  cout << dp[n-1] << "\n"; 
   
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
/************************************************/
#define rep(i,n) for(int i=0;i<n;i++)
#define mp make_pair
#define pb push_back
#define fr first
#define se second
#define forn(i,a,n) for(int i=a;i<n;i++)
#define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();i++)
#define pii pair<int,int>
#define vi vector<int>
#define ll long long
#define sz(s) s.size()
#define all(s) s.begin(),s.end()
#define zero(x) memset(x,0,sizeof(x))
#define vii vector<pair<int,int> >
#define mpis map<int,string>
#define mpii map<int,int>
#define mpsi map<string,int>
#define re return
/************************************************/
using namespace std;

int main(){
	int a;
	cin>>a;
	for(int i=1;i<=a;i++){
		if(a%i==0&&i>=1&&i<=9&&a/i>=1&&a/i<=9){
			cout<<"Yes";
			re 0;
		}
	}
	cout<<"No";
	re 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
typedef long long ll;
const int N=1e5+5,INF=1e9+7;
int n,m,par[N],id[N],a[N];
void init(){
    for(int i=0;i<n;i++) par[i]=i,id[i]=i;
}
int fd(int x) {
    return par[x]==x?x:par[x]=fd(par[x]);
}
int main() {
    scanf("%d%d",&n,&m);
    for(int i=0;i<n;i++) scanf("%d",a+i);init();
    int x,y;
    while(m--) {
        scanf("%d%d",&x,&y);
        x=fd(x);y=fd(y);
        if(x==y) continue;
        if(a[id[y]]>a[id[x]]) id[y]=id[x];
        par[x]=y;
    }
    ll ans=0;int tot=0;
    for(int i=0;i<n;i++) if(fd(i)==i) tot++,ans+=a[id[i]],a[id[i]]=INF;
    if(tot==1) printf("0\n");
    else {
        std::sort(a,a+n);bool ok=true;
        for(int i=0;i<tot-2;i++) {
            ans+=a[i];
            if(a[i]>=INF) ok=false;
        }
        if(ok) printf("%lld\n",ans);
        else printf("Impossible\n");
    }
    return 0;
}


Measured memory_bytes: 1408
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#define INF 1000000000
#define MOD 1000000007

using namespace std;

int main()
{
    string str;
    int f = 1;

    cin >> str;

    for (int i = 0; i < str.size(); i++) {
        for (int j = 0; j < str.size(); j++) {
            if (i == j) continue;

            if (str[i] == str[j]) {
                f = 0;
            }
        }
    }

    if (f) {
        cout << "yes" << endl;
    } else {
        cout << "no" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
n=int(input())
tmp=list(map(int, input().split(" ")))
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a

def lcm(a, b):
	return a * b // gcd (a, b)

a=max(tmp)
for i in tmp:
    a=gcd(a,i)

print(a)

Measured memory_bytes: 14252
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

class Main {

	static int n;
	static double[] x1, y1, x2, y2;
	static double sx, sy, gx, gy;
	static ArrayList<Integer>[] g;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int q = sc.nextInt();
		while (q-- > 0) {
			long x0, y0, x1, y1, x2, y2, x3, y3;
			x0 = sc.nextLong();
			y0 = sc.nextLong();
			x1 = sc.nextLong();
			y1 = sc.nextLong();
			x2 = sc.nextLong();
			y2 = sc.nextLong();
			x3 = sc.nextLong();
			y3 = sc.nextLong();
			Point p0 = new Point(x0, y0);
			Point p1 = new Point(x1, y1);
			Point p2 = new Point(x2, y2);
			Point p3 = new Point(x3, y3);
			if (linesIntersect(p0, p1, p2, p3)) {
				System.out.println(1);
			} else {
				System.out.println(0);
			}
		}

	}

	static class Point {
		long x, y;
		int id;

		public Point(long x, long y) {
			this.x = x;
			this.y = y;
		}
	}

	static boolean linesIntersect(Point s1, Point d1, Point s2, Point d2) {
		long prd1 = crossProduct(s1, d1, s1, d2) * crossProduct(s1, d1, s1, s2);
		long prd2 = crossProduct(s2, d2, s2, s1) * crossProduct(s2, d2, s2, d1);
		if (prd1 == 0 && prd2 == 0) {
			if (((s2.x - s1.x) * (s2.x - d1.x) <= 0 && (s2.y - s1.y) * (s2.y - d1.y) <= 0)
					|| ((d2.x - s1.x) * (d2.x - d1.x) <= 0 && (d2.y - s1.y) * (d2.y - d1.y) <= 0)
					|| ((s1.x - s2.x) * (s1.x - d2.x) <= 0 && (s1.y - s2.y) * (s1.y - d2.y) <= 0)
					|| ((d1.x - s2.x) * (d1.x - d2.x) <= 0 && (d1.y - s2.y) * (d1.y - d2.y) <= 0)) {
				return true;
			} else
				return false;
		} else
			return prd1 <= 0 && prd2 <= 0;
	}

	static long crossProduct(Point s1, Point d1, Point s2, Point d2) {
		return (d1.x - s1.x) * (d2.y - s2.y) - (d1.y - s1.y) * (d2.x - s2.x);
	}

	static void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
}

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

#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define OUT(a) cout << (a) << "\n"
#define ll long long
#define uint unsigned int
#define ushort unsigned short
#define ulong unsigned long

ll MOD = 10e9 + 7;

int main() {
    int x;
    cin >> x;
    int x500 = int(x / 500);
    x -= x500 * 500;
    int x5 = int(x / 5);
    OUT(x500 * 1000 + x5 * 5);
    return 0;
}


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

int main()
{
	int N, x;
	vector<int> d;

	cin >> N;
	
	for(int i=0; i<N; i++)
	{
		cin >> x;
		d.push_back(x);
		sort(d.begin(), d.end());
		d.erase(unique(d.begin(), d.end()), d.end());
	}
	cout << d.size() << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <tuple>
#include <queue>
#include <bitset>
#include <set>
#include <map>
#include <list>

using ll = long long;
using ld = long double;
using namespace std;
const int INF = 1e9+100;
const ll INF64 = 7e18l;
const int mod = 1000000007;
#define rep(i,a,b) for(int i(a);i<(b);i++)
#define ALL(a) (a).begin(), (a).end()
#define FIN ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);


int main(){
    FIN;
    ll N,W,weight,value;
    cin >> N >> W;
    vector<ll> dp(W+1); //dp[i] = max value with weight i
    dp[0] = 0;

    rep(i,1,N+1){
        cin >> weight >> value;
        for(ll from=W-weight;from>=0;from--){
            dp[from+weight] = max(dp[from+weight],dp[from]+value);
        }
    }

    ll ans = 0;
    rep(i,1,W+1) ans = max(ans,dp[i]);
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define F first
#define S second

using namespace std;

typedef long long ll;
typedef pair<int , int> pii;

int a[100010];

int main(){

	ios_base::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);

	int n , ans = 0, l;
	cin >> n >> l;

	for(int i = 0 ; i < n ; i++)
	   cin >> a[i];
	
	for(int i = 0 ; i+1 < n ; i++)
		if(a[i] + a[i+1] >= l)
			ans = i+1;

	if(!ans)
	   cout << "Impossible" << endl;
	else{
	   cout << "Possible" << endl;
	   for(int i = 1 ; i < ans ; i++)
		  cout << i << endl;
		
		for(int i = n-1 ; i > ans ; i--)
		   cout << i << endl;

		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 1280
import java.util.Scanner;
public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int w = sc.nextInt();
		int n = sc.nextInt();
		int ans[] = new int[w];
		for (int i=0;i<w;i++) {
			ans[i] = i+1;
		}
		for (int i=0;i<n;i++) {
			String line = sc.next();
			int a = line.indexOf(',');
			int x1 = Integer.parseInt(line.substring(0,a))-1;
			int x2 = Integer.parseInt(line.substring(a+1,line.length()))-1;
			int temp = ans[x1];
			ans[x1] = ans[x2];
			ans[x2] = temp;
		}
		for (int i=0;i<w;i++) {
			System.out.println(ans[i]);
		}
	}
}

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

using namespace std;

typedef long long ll;
typedef vector<ll> vl;
typedef long double ld;
typedef vector<ld> vd;
typedef bool bl;
typedef vector<bl> vb;
typedef unordered_map<ll,unordered_map<ll,ll>> graph;

const ll e5 = 1 << 20;
const ll mod = 1000000007;
const ll e3 = 1 << 13;
const ll INF = 1ll << 60;

ll x,a;

int main(){
  cin >> x >> a;
  if(x < a) cout << 0 << endl;
  else cout << 10 << endl;
  
}


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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

int c[3][3];

int main() {
	inc(i, 3) {
	inc(j, 3) {
		cin >> c[i][j];
	}
	}
	
	bool f = true;
	inc(i, 2) {
	inc(j, 2) {
		if(
			c[i][j] - c[i + 1][j] == c[i][j + 1] - c[i + 1][j + 1] &&
			c[i][j] - c[i][j + 1] == c[i + 1][j] - c[i + 1][j + 1]
		) { } else { f = false; }
	}
	}
	
	cout << (f ? "Yes" : "No") << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#include <complex>
#include <unistd.h>
#include <cassert>
#include <cctype>
#include <random>
#include <time.h>
#define _USE_MATH_DEFINES
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;
typedef complex<double> xy_t;
typedef vector<ll> vll;
typedef vector< vector<ll> > matrix;
#define REP(i, x, y) for(ll i = (ll)x; i < (ll)y; i++)
#define DREP(i, x, y, d) for(ll i = (ll)x; i < (ll)y; i += (ll)d)
#define PER(i, x, y) for(ll i = (ll)x; i > (ll)y; i--)
#define DPER(i, x, y, d) for(ll i = (ll)x; i > (ll)y; i -= (ll)d)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;
int iinf = intmax / 8;
ll inf = llmax / 8;
double eps = 1e-11;

ll dp[110][100010];

int main() {
    ll N, W;
    cin >> N >> W;
    ll w[N], v[N];
    REP(i, 0, N) {
        cin >> w[i] >> v[i];
    }
    REP(i, 0, 110) {
        fill(dp[i], dp[i] + 100010, inf);
    }
    dp[0][0] = 0;
    REP(i, 0, N) {
        REP(j, 0, 1000 * N + 1) {
            if (dp[i][j] < inf) {
                dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
                if (dp[i][j] + w[i] <= W) {
                    dp[i + 1][j + v[i]] = min(dp[i + 1][j + v[i]], dp[i][j] + w[i]);
                }
            }
        }
    }
    // REP(i, 0, N + 1) {
    //     REP(j, 0, 11 + 1) {
    //         cout << dp[i][j] << " ";
    //     }
    //     cout << endl;
    // }
    ll ans = 0;
    PER(i, 1000 * N, -1) {
        if (dp[N][i] < inf) {
            ans = i;
            break;
        }
    }
    cout << ans << endl;
}


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

using namespace std;

typedef long long ll;

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

    char S[110];
    ll K;
    cin >> S >> K;

    if (strlen(S) >= K) {
        for (ll i = 0; i < K; i++) {
            if (i == K-1) {
                cout << S[i] << endl;
                exit(0);
            }

            if (S[i] == '1') continue;
            else {
                cout << S[i] << endl;
                exit(0);
            }
        }
    } else {
        for (ll i = 0; i < strlen(S); i++) {
            if (S[i] == '1') continue;
            else {
                cout << S[i] << endl;
                exit(0);
            }
        }
    }
}

Measured memory_bytes: 256
/**
* Copyright(c)
* Author : tiketiskte
**/
#include <bits/stdc++.h>
#define IOS {ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);}
#define ll long long
#define PLL pair<ll, ll>
#define SZ(X) (int)X.size()
#define INF 0x3f3f3f3f

using namespace std;

string S;
int main(void)
{
    IOS
    cin >> S;
    if(S[0] == 'R' && S[1] == 'R' && S[2] == 'R') {
        cout << 3 << endl;
    } else if(S[0] == 'R' && S[1] == 'R' && S[2] == 'S') {
        cout << 2 << endl;
    } else if(S[0] == 'S' && S[1] == 'S' && S[2] == 'S') {
        cout << 0 << endl;
    } else if(S[0] == 'S' && S[1] == 'R' && S[2] == 'R') {
        cout << 2  << endl;
    } else {
        cout << 1 << endl;
    }
    // system("pause");
    return 0;
}


Measured memory_bytes: 3628