akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <stack> // s.top()
#include <bitset>
#include <queue> // s.front()
using namespace std;

typedef long long Int;
typedef pair<Int,Int> P;
#define print(x) cout<<(x)<<endl

#define INF10 10000000000
#define INF5 100000
#define EPS 1e-10
#define MOD 1000000007



int main() {
	string a, b, c;
	cin >> a >> b >> c;
	string p;
	p += a[0]; p += b[1]; p += c[2];
	print(p);





	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws Exception {
        // 自分の得意な言語で
        // Let's チャレンジ！！
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        
		
		// 1行、2つ(複数)数字
		String[] ss0 = br.readLine().trim().split(" ", 0);
		int a = Integer.parseInt(ss0[0]);
		int b = Integer.parseInt(ss0[1]);
		int c = Integer.parseInt(ss0[2]);

		int iCount = 0;
		
		if (a != b) { iCount = iCount + 1; }
		if (a != c) { iCount = iCount + 1; }
		if (b != c) { iCount = iCount + 1; }

		if (iCount == 0) { iCount = 1; }
		
		System.out.print(iCount);

    }
}



Measured memory_bytes: 8144
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << #x << " = " << x << endl;


#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 100010

int n;
vector<int> way[SIZE];
int num[SIZE],mi[SIZE],ma[SIZE];

bool flag = true;

pair<int,int> dfs(int now, int back, int p){

  //debug(p);
  //debug(num[now]);
  
  if(num[now] != -INF && p%2 != num[now]%2){
    flag = false;
    return make_pair(-INF,-INF);
  }

  //debug(now);

  int l = -INF+1, r = INF-1; //[l,r]

  if(num[now] != -INF){
    p = num[now];
    l = r = num[now];
  }
  
  for(int i=0;i<way[now].size();i++){
    if(way[now][i] == back) continue;
    pair<int,int> ret = dfs(way[now][i], now, p+1);

    if(ret.first == -INF) return ret;

    ret.first--;
    ret.second++;
    
    
    if(ret.second < l || r < ret.first){
      flag = false;
      return make_pair(-INF,-INF);
    }

    l = max(ret.first,l);
    r = min(ret.second,r);
  }

  mi[now] = l;
  ma[now] = r;

  return make_pair(l,r);
}

void dfs2(int now, int back, int back_p){

  if(num[now] == -INF){
  
    if(mi[now] <= back_p-1 && back_p-1 <= ma[now]){
      num[now] = back_p-1;
    }else{
      num[now] = back_p+1;
    }
  }

  for(int i=0;i<way[now].size();i++){
    if(way[now][i] == back) continue;
    dfs2(way[now][i], now, num[now]);
  }

}

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

  for(int i=0;i<n-1;i++){
    scanf("%d%d",&a,&b);
    a--; b--;
    way[a].push_back(b);
    way[b].push_back(a);
  }

  scanf("%d",&k);

  for(int i=0;i<n;i++) num[i] = -INF;

  for(int i=0;i<k;i++){
    scanf("%d%d",&a,&b);
    a--;
    num[a] = b;
  }
  
  dfs(a,-1,b);


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

    dfs2(a,-1,-1);

    for(int i=0;i<n;i++){
      printf("%d\n",num[i]);
    }

  }
    
  
  return 0;
}


Measured memory_bytes: 15360
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
const ll INF=1000000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};

int main() {

	int n,a,b;
	cin>>n>>a>>b;
	string s;
	cin>>s;

	int b2=0,t=0;
	rep(i,n){
		if(s[i]=='c'||t==a+b){
			cout<<"No"<<endl;
			continue;
		}
		t++;
		if(s[i]=='a')cout<<"Yes"<<endl;
		else{
			b2++;
			if(b2<=b)cout<<"Yes"<<endl;
			else{
				t--;
				cout<<"No"<<endl;
			}
		}
	}

	return 0;

}


Measured memory_bytes: 896
def solve():
    N, K = map(int, input().split())
    x = list(map(int, input().split()))
    ans = 10 ** 13
    for r, l in zip(x[:N - K + 1], x[K - 1:]):
        ans = min(ans, abs(l) + abs(r - l), abs(r) + abs(r - l))

    print(ans)


if __name__ == "__main__":
    solve()


Measured memory_bytes: 19860
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
typedef long long ll;

int main(){
    int a,b,c; cin >> a >> b >>c;
    cout << ((a+b+c >= 22)? "bust" : "win")<< endl; return 0;
}


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

int main() {
  int N;
  cin >> N;
  vector<pair<pair<string, int>, int>> restaurant(N);
  for (int i = 0; i < N; ++i) {
    cin >> restaurant.at(i).first.first >> restaurant.at(i).first.second;
    restaurant.at(i).first.second *= -1;
    restaurant.at(i).second = i;
  }

  sort(restaurant.begin(), restaurant.end());

  for (int i = 0; i < N; ++i) {
    cout << restaurant.at(i).second + 1 << endl;
  }

  return 0;
}


Measured memory_bytes: 256
process.stdin.resume();
process.stdin.setEncoding('utf8');

var lines = [];
var reader = require('readline').createInterface({
    input: process.stdin,
    output: process.stdout
});
reader.on('line', (line) => {
    // ここで入力を処理する
    lines.push(line);
});
reader.on('close', () => {
    // ここで出力する
    for(var i =0; i<lines.length; i++){
      	switch(lines[i]){
 		case '1':
  			console.log(1);
  		break;

 		case '2':
  			console.log(8);
  		break;

   		case '3':
  			console.log(27);
  		break;

   		case '4':
  			console.log(64);
  		break;

   		case '5':
  			console.log(125);
  		break;

   		case '6':
  			console.log(216);
  		break;

   		case '7':
  			console.log(343);
  		break;

   		case '8':
  			console.log(512);
  		break;

   		case '9':
  			console.log(729);
  		break;
	}
    }
});


Measured memory_bytes: 7628
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define pb push_back
#define xx first
#define yy second
#define sz(x) ((int)x.size())
#define all(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define repp(i,k,n) for(int i=k;i<n;i++)
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> iv;
typedef pair<int,int> iip;
typedef map<int,int> mii;
template <typename T>
void dbg(T t){cerr<<t<<endl ;}
template<typename T, typename... Args>
void dbg(T t, Args... args) {cerr << t <<" ";dbg(args...) ;}

int main(){
	ios::sync_with_stdio(0);cin.tie(0);
	int a,b,c;
	cin>>a>>b>>c;
	if(abs(a-b)<abs(a-c))
		cout<<'A';
	else cout<<'B';
	return 0;
}

Measured memory_bytes: 892
#include <iostream>
#include <vector>
#include <set>
#include <functional>
template <typename T>
struct Line
{
    T a, b;  // (a,b) <=> f(x)=ax+b
    bool query;
    mutable std::function<const Line*()> succ = nullptr;
    bool operator<(const Line& l) const
    {
        if (not l.query) { return a > l.a; }
        const Line* s = succ();
        if (not s) { return false; }
        return s->b - b < (a - s->a) * l.a;
    }
};
template <typename T>
class DynamicCHT : public std::multiset<Line<T>>
{
    bool needless(const typename DynamicCHT<T>::iterator y) const
    {
        const auto z = std::next(y);
        if (y == this->begin()) { return z != this->end() and y->a == z->a and y->b >= z->b; }
        const auto x = std::prev(y);
        return z == this->end() ? y->a == x->a and y->b >= x->b : (x->b - y->b) * (z->a - y->a) >= (y->b - z->b) * (y->a - x->a);
    }

public:
    void add(const T a, const T b)
    {
        auto y = this->insert({a, b, false});
        y->succ = [=]() { return std::next(y) == this->end() ? nullptr : &*std::next(y); };
        if (needless(y)) { return (void)this->erase(y); }
        while (std::next(y) != this->end() and needless(std::next(y))) { this->erase(std::next(y)); }
        while (y != this->begin() and needless(std::prev(y))) { this->erase(std::prev(y)); }
    }
    T query(const T x) const
    {
        const auto l = *this->lower_bound(Line<T>{x, 0, true});
        return l.a * x + l.b;
    }
};
using ll = long long;
int main()
{
    std::size_t N;
    ll C;
    std::cin >> N >> C;
    std::vector<ll> h(N), dp(N);
    for (std::size_t i = 0; i < N; i++) { std::cin >> h[i]; }
    DynamicCHT<ll> cht;
    cht.add(-2 * h[0], dp[0] + h[0] * h[0]);
    for (std::size_t i = 0; i < N; i++) {
        dp[i] = cht.query(h[i]) + h[i] * h[i] + C;
        cht.add(-2 * h[i], dp[i] + h[i] * h[i]);
    }
    std::cout << dp[N - 1] << std::endl;
    return 0;
}


Measured memory_bytes: 22144
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int n = s.size();
    s += "!";
    int ans = 0;
    string t = "?";
    rep(i,n){
        ++ans;
        string u = "?";
        u += s[i];
        if(t != u){
            t = u;
        }
        else{
            t = s[i];
            t += s[i+1];
            if(s[i+1] == '!') --ans;
            ++i;
        }
        //cout << t << endl;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3796
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

template <typename TYPE>
void print_vec(const vector<TYPE>& v){
	for(int i=0; i<v.size(); i++){
		cout << v[i] << " ";
	}
	cout << endl;
}

template <typename TYPE>
void print_vec2(const vector<vector<TYPE>>& v){
	for(int i=0; i<v.size(); i++){
		cout << "i=" << i << ":   ";
		for(int j=0; j<v[i].size(); j++){
			cout << v[i][j] << "   ";
		}
		cout << endl;
	}
}




int main(){//
	int N, W;
	cin >> N >> W;
	vector<int> w(N+1), v(N+1);
	for(int i=1; i<=N; i++) cin >> w[i] >> v[i];

	//dp[i][j]:  i番目まで考慮した時に重さjになった時の最大化価値
	vector<vector<ll>> dp(N+5, vector<ll>(W+5, 0));
	
	for(int i=0; i<=N; i++){
		for(int j=0; j<=W; j++){
			dp[i+1][j] = max(dp[i+1][j], dp[i][j]+0);
			if(j+w[i+1] <= W) dp[i+1][j+w[i+1]] = max(dp[i+1][j+w[i+1]], dp[i][j] + v[i+1]);
		}
	}
	//print_vec2(dp);
	ll ans = 0;
	for(int j=0; j<=W; j++){
		ans = max(ans, dp[N][j]);
	}
	cout << ans << endl;
}


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



int n, m ;
vector<int> a[100001];
int visited[100001];
int dp[100001] ;
int ans = 0;

int dfs(int s) {
	visited[s] = 1;
	if (dp[s] != 0)  {
		return	dp[s];

	}

	int z = 0;

	for (auto x : a[s])
		z = max(z,  1 + dfs(x));

	return dp[s] =  z;
}
void f() {
	for (int i = 1; i <= n; i++) {
		visited[i] = 0;
	}
	for (int i = 1; i <= n; i++)
		if (visited[i] == 0)
			dfs(i);

	for (int i = 1; i <= n; i++)
		ans = max(ans, dp[i]);
}

int main()
{	

	cin >> n >> m;
	memset(dp, 0, sizeof dp);

	for (int i = 0; i < m; i++) {
		int no1, no2;
		cin >> no1 >> no2;
		a[no1].push_back(no2);

	}
	f();

	cout << ans;
	return 0;
}

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

using namespace std;

#define roop(i, n) for(int i = 0;i < n;i++)

int main(void){

    vector<int> a;

    int count = 0;
    while(1){
        int x, y;
        char o;
        cin >> x >> o >> y;
        if(o == '?') break;

        switch(o){
            case '+':
            a.push_back(x+y);
            break;

            case '-':
            a.push_back(x-y);
            break;

            case '*':
            a.push_back(x*y);
            break;

            case '/':
            a.push_back(x/y);
            break;
        }
        count++;
    }

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

    return 0;
}


Measured memory_bytes: 3168
import sys
input = sys.stdin.readline

S = input().strip()
ans = 1
odd = set(['R', 'U', 'D'])
even = set(['L', 'U', 'D'])

for i, letter in enumerate(S):
    i += 1
    if i % 2 == 1:
        if letter not in odd:
            ans *= 0
    if i % 2 == 0:
        if letter not in even:
            ans *= 0

if ans == 1:
    print('Yes')
elif ans == 0:
    print('No')

Measured memory_bytes: 3064
#define NDEBUG
NDEBUG


#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <memory>
#include <queue>
#include <random>


using namespace std;

// TC_REMOVE_BEGIN
/// caide keep
bool __hack = std::ios::sync_with_stdio(false);
/// caide keep
auto __hack1 = cin.tie(nullptr);
// TC_REMOVE_END


// Section with adoption of array and vector algorithms.


namespace template_util {
    

    constexpr int bytecount(uint64_t x) {
        return x ? 1 + bytecount(x >> 8) : 0;
    }

    template<int N>
    struct bytetype {
        
    };

    
    /// caide keep
    template<uint64_t N>
    struct minimal_uint : bytetype<bytecount(N)> {
    };
}


template<class T>
T next(istream& in) {
    T ret;
    in >> ret;
    return ret;
}

template<class T>
vector<T> next_vector(istream& in, size_t n) {
    vector<T> ret(n);
    for (size_t i = 0; i < n; ++i) {
        ret[i] = next<T>(in);
    }
    return ret;
}


#define dbg(...) ;


void solve(istream &in, ostream &out) {
    auto n = next<int>(in);
    auto a = next_vector<int>(in, n);
    a.insert(a.begin(), 0);
    a.push_back(0);
    n = (int)a.size();

    int sum = 0;
    for (int i = 1; i < n; ++i) {
        sum += abs(a[i] - a[i-1]);
    }
    dbg("a => ", a, sum);
    for (int i = 1; i < n-1; ++i) {
        int res = sum - abs(a[i] - a[i-1]) - abs(a[i+1] - a[i]) + abs(a[i+1] - a[i-1]);
        out << res << '\n';
    }
}

//#include <fstream>


int main() {
//    ifstream fin("input.txt");
//    ofstream fout("output.txt");
//    solve(fin, fout);
    solve(cin, cout);
    return 0;
}



Measured memory_bytes: 1656
#include<stdio.h>
#include<stdlib.h>
#define NIL NULL
struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
 
Node root;
Node find(Node root,int key){
  if(root==NIL||root->key==key)
    return root;
  if(root->key > key)
    return find(root->left,key);
  else
    return find(root->right,key);
}
void insert(int key){
   Node y = NIL;
   Node x = root;
   Node z;
    
   z =malloc(sizeof(struct node));
   z->key = key;
   z->left = NIL;
   z->right = NIL;
   while(x!=NIL){
     y=x;
     if(z->key < x->key)x=x->left;
     else x=x->right;
   }
   z->parent=y;
   if(y==NIL)root=z;
   else if(z->key <y->key)
   y->left=z;
   else
     y->right=z;
}
 
void inorder(Node root){
  if(root->left!=NIL)
    inorder(root->left);
  printf(" %d",root->key);
  if(root->right!=NIL)
    inorder(root->right);
}
 
void preorder(Node root){
  if(root!=NIL)
    printf(" %d",root->key);
  if(root->left!=NIL)
    preorder(root->left);
  if(root->right!=NIL)
    preorder(root->right);
}
 
int main(){
  int n, i, x;
  char com[10];
  scanf("%d", &n);
  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
     Node t = find(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    }
    if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }
  return 0;
}

Measured memory_bytes: 19364
// ConsoleApplication1.cpp : Defines the entry point for the console application.
//

#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <queue>

#define MAXCHAR 255

using namespace std;

map<int, vector<int>> accessibles;
map<int, int> indexDistanceMap;
vector<int> shortestRouteIndex;
queue<int> Q;

void Loop(int prevIndex, int currentDistance, set<int> visitedInd)
{
	currentDistance++;

	vector<int> possibleRoutes = accessibles[prevIndex];
	for (auto it = possibleRoutes.cbegin(); it != possibleRoutes.cend(); it++)
	{
		int a = *it; // Next index candidate
		if (visitedInd.find(a) != visitedInd.cend())
			continue;
		visitedInd.insert(a);
		if (indexDistanceMap[a] == 0/* || indexDistanceMap[a] > currentDistance*/)
		{
			indexDistanceMap[a] = currentDistance;
			shortestRouteIndex[a] = prevIndex;
			Q.push(a);
		}
	}
}

int main()
{
	int N = 0;
	int M = 0;
	cin >> N >> M;
	for (int i = 0; i < M; i++)
	{
		int A = 0;
		int B = 0;
		cin >> A >> B;

		accessibles[B-1].push_back(A-1);
		accessibles[A-1].push_back(B-1);
	}

	shortestRouteIndex = vector<int>(N);
	set<int> visitedIndex;
	Q.push(0);
	for (int i = 0; i < accessibles[0].size(); i++)
	{
		int currentDistance = 0;
		int nextIndex = accessibles[0][i];
		visitedIndex.clear();
		visitedIndex.insert(0);

		while (!Q.empty())
		{
			int u = Q.front();
			Q.pop();
			Loop(u, currentDistance, visitedIndex);
		}
	}
	cout << "Yes" << endl;
	for (int i = 1; i < shortestRouteIndex.size(); i++)
	{
		cout << shortestRouteIndex[i] + 1 << endl;
	}

	return 0;
}

Measured memory_bytes: 25340
#include<bits/stdc++.h>
#define N 200000
typedef long long LL;
using namespace std;
int a[N], b[N], n, k;

int main() {
    cin >> n >> k;
    for(int i = 1; i <= n; i++) scanf("%d%d", &a[i], &b[i]);
    LL ans = 0;
    for(int i = 0; i <= 30; i++)
        if (k & (1 << i)) {
            int tmp = ((k >> (i + 1)) << (i + 1)) + (1 << i) - 1;
            LL sum = 0;
            for(int j = 1; j <= n; j++)
                if ((tmp | a[j]) == tmp) sum += b[j];
            ans = max(ans, sum);
        }
    LL sum = 0;
    for(int i = 1; i <= n; i++)
        if ((k | a[i]) == k) sum += b[i];
    ans = max(ans, sum);
    cout << ans << endl;
}


Measured memory_bytes: 1024
def main():
    h, w, n = map(int, input().split())
    y, x = map(int, input().split())
    y -= 1
    x -= 1
    s, t = input(), input()

    u, d, l, r = 0, h - 1, 0, w - 1

    for ss, tt in zip(s[::-1], t[::-1]):
        if tt == 'U': d = min(d + 1, h - 1)
        if tt == 'D': u = max(u - 1, 0)
        if tt == 'L': r = min(r + 1, w - 1)
        if tt == 'R': l = max(l - 1, 0)

        if ss == 'U': u += 1
        if ss == 'D': d -= 1
        if ss == 'L': l += 1
        if ss == 'R': r -= 1

        if l > r or u > d:
            print('NO')
            return

    if l <= x <= r and u <= y <= d:
        print('YES')
        return
    else:
        print('NO')
        return


if __name__ == '__main__':
    main()

Measured memory_bytes: 4024
N = int(input())
A = list(map(int, input().split()))

MOD = 1000000007

cum = []

s = 0
for a in A:
    s += a
    cum.append(s)


ans = 0
for i, a in enumerate(A):
    c = a * ((s - cum[i]) % MOD) % MOD
    ans += c % MOD
    ans %= MOD

print(ans)



Measured memory_bytes: 31616
a, b, c, d = map(int, input().split())
 
cnt = [0]*101
for i in range(a, b+1):
    cnt[i] += 1
for j in range(c, d+1):
    cnt[j] += 1
 
ans = cnt.count(2) - 1
if ans == -1:
    print(0)
else:
    print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
using namespace std;
#define HORIZONTAL 1
#define VERTICAL 2

int bit(int bits)
{
	int ret = 0;
	while(bits != 0)
	{
		ret += bits & 0x00000001;
		bits >>= 1;
	}
	return ret;
}

int main()
{
	int n, a, b, c, block, ret;
	while(cin >>n, n)
	{
		vector<int> data(5001, 0);
		data[5000] = 63; /* 63 = 0x11111 */
		ret = 0;
		
		while(n--)
		{
			cin >> a >> b >> c;
			c--;
			if(a==HORIZONTAL)
			{
				block = ((1<<b)-1) << c;
				for(int i=0; i<data.size()-1; i++)
				{
					if(data[i+1] & block)
					{
						data[i] += block;
						break;
					}
				}
			}
			else
			{
				block = 1 << c;
				for(int i=0; i<data.size()-1; i++)
				{
					if(data[i+1] & block)
					{
						for(int j=0; j<b; j++)
						{
							data[i-j] += block;
						}
						break;
					}
				}
			}

			vector<int>::iterator it = data.begin();
			while(it != data.end())
			{
				if((*it) == 31)
				{
					it = data.erase(it);
					it--;
				}
				it++;
			}
		}
		ret = 0;
		for(int i=0; i<data.size()-1; i++)
		{
			ret += bit(data[i]);
		}
		cout << ret << endl;
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define int long long
using namespace std;
int n,q,sum;
int arr[100005];
int cnt[100005];
signed main()
{
  ios::sync_with_stdio(0);
  cin.tie(0);
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>arr[i];
		cnt[arr[i]]++;
		sum+=arr[i];
	}
	cin>>q;
	while(q--)
	{
		int a,b;
		cin>>a>>b;
		sum+=(b-a)*cnt[a];
		cnt[b] += cnt[a];
		cnt[a] = 0;
		cout<<sum<<'\n';
	}
}

Measured memory_bytes: 5176
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <utility>
#include <algorithm>
#include <numeric>
#include <typeinfo>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <ctime>

using namespace std;

#define dump(n) cout<<"# "<<#n<<"="<<(n)<<endl
#define debug(n) cout<<__FILE__<<","<<__LINE__<<": #"<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define iter(c) __typeof((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();i++)
#define allof(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;

int main()
{
	for(int h,w;cin>>h>>w,h|w;){
		vs field(h);
		rep(i,h)
			cin>>field[i];
		vvi flg(h,vi(w));
		for(int x=0,y=0;;){
			if(field[y][x]=='.'){
				cout<<x<<" "<<y<<endl;
				break;
			}
			if(flg[y][x]){
				cout<<"LOOP"<<endl;
				break;
			}
			flg[y][x]=true;
			switch(field[y][x]){
				case '^': y--; break;
				case 'v': y++; break;
				case '<': x--; break;
				case '>': x++; break;
			}
		}
	}
	
	return 0;
}

Measured memory_bytes: 0
#include <iostream>

using i64 = long long;

const i64 MOD = 998244353;
const i64 Inv2 = -MOD / 2;

i64 pow(i64 a, i64 k) {
	i64 t = 1;
	for (; k; a = a * a % MOD, k >>= 1)
		if (k & 1) t = t * a % MOD;
	return t;
}

const int N = 1 << 18 | 7;

int n;
i64 p[N], s, q[N];

void fwt_xor(i64 f[], int n, int on) {
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < 1 << n; ++j)
			if (j >> i & 1)
				( f[j ^ 1 << i] += f[j] ) %= MOD, ( f[j] = f[j ^ 1 << i] - 2 * f[j] ) %= MOD;
		if (on == 1) continue;
		for (int i = 0; i < 1 << n; ++i)
			( f[i] *= Inv2 ) %= MOD;
	}
}

int main() {
	scanf("%d", &n);
	for (int i = 0; i < 1 << n; ++i)
		scanf("%lld", p + i), s += p[i];
	s = pow(s, MOD - 2);
	for (int i = 0; i < 1 << n; ++i)
		p[i] = p[i] * s % MOD;
	--p[0];
	std::fill(q, q + (1 << n), -1);
	q[0] += 1 << n;
	
	fwt_xor(p, n, 1), fwt_xor(q, n, 1);
	for (int i = 0; i < 1 << n; ++i)
		q[i] = q[i] * pow(p[i], MOD - 2) % MOD;
	fwt_xor(q, n, -1);
  
	for (int i = 0; i < 1 << n; ++i)
		printf("%lld\n", (q[i] - q[0] + MOD * 2) % MOD);
	return 0;
}


Measured memory_bytes: 6912
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0128

"""
import sys
from sys import stdin
input = stdin.readline


def conv_avacus(num_txt):
    abacus = ['* = ****', '* =* ***', '* =** **', '* =*** *', '* =**** ',
              ' *= ****', ' *=* ***', ' *=** **', ' *=*** *', ' *=**** ']
    ans = [abacus[int(num_txt[4])], abacus[int(num_txt[3])], abacus[int(num_txt[2])], abacus[int(num_txt[1])], abacus[int(num_txt[0])]]
    return ans


def rotate_and_print(data):
    y_size = len(data)
    x_size = len(data[0])
    A = [[''] * y_size for _ in range(x_size)]
    for i in range(x_size):
        for j in range(y_size):
            A[i][j] = data[y_size-1-j][i]

    for l in A:
        print(''.join(l))


def main(args):
    first_case = True
    for line in sys.stdin:
        if not first_case:
            print()
        num_txt = line.strip().zfill(5)
        result = conv_avacus(num_txt)
        rotate_and_print(result)
        first_case = False


if __name__ == '__main__':
    main(sys.argv[1:])
    

Measured memory_bytes: 7948
import java.io.*;
import java.lang.*;
import java.util.*;
import java.math.*;

class Solver extends Main{
	Solver(long a, long b, long c){
		long[] cur={a,b,c};
		long[] nex={0,0,0};
		long s=a+b+c;
		boolean con=true;
		boolean loop=false;
		int i=0;
		if(cur[0]%2==1 || cur[2]%2==1 || cur[2]%2==1) con=false;
		while(con==true){
			nex[0]=(s-cur[0])/2;
			nex[1]=(s-cur[1])/2;
			nex[2]=(s-cur[2])/2;
			
			//puts(nex[0],nex[1],nex[2],s);
			
			cur[0]=nex[0];cur[1]=nex[1];cur[2]=nex[2];
			nex[0]=0; nex[1]=0; nex[2]=0;
			if(cur[0]%2==1 || cur[2]%2==1 || cur[2]%2==1) con=false;
			if((s-cur[0])/2==cur[0] && (s-cur[1])/2==cur[1] &&(s-cur[2])/2==cur[2]){
				con=false;
				loop=true;
			}
			i+=1;
		}
		puts( loop==false ? i : -1);
	}
}

class Main{
	int imax=Integer.MAX_VALUE;
	long lmax=Long.MAX_VALUE;
	public static void main(String[] args) throws FileNotFoundException{

		Scanner sc=new Scanner(System.in);
		long[] data=readlL(sc," ");
		new Solver(data[0], data[1], data[2]);
	}	
	
	//utility
	static int[] readI(Scanner sc, String dl){
		return Arrays.stream(sc.nextLine().trim().split(dl)).mapToInt(Integer::parseInt).toArray();
	}
	static int[] readlI(Scanner sc, String dl){
		return Arrays.stream(sc.nextLine().trim().split(dl)).mapToInt(Integer::parseInt).toArray();
	}
	static long[] readlL(Scanner sc, String dl){
		return Arrays.stream(sc.nextLine().trim().split(dl)).mapToLong(Long::parseLong).toArray();
	}
	static int nextI(Scanner sc){
		return Integer.parseInt(sc.nextLine().trim());
	}
	static String[] readS(Scanner sc, String dl){
		return sc.nextLine().trim().split(dl);
	}
	static String nextS(Scanner sc){
		return sc.nextLine().trim();
	}
	@SuppressWarnings("unchecked")
	static <T> void puts(T... args){
		for(int i=0; i<args.length-1; i++){
			System.out.printf("%s ",args[i]);
		}
		System.out.println(args[args.length-1]);
	}
	static void puts(int[] ary){
		for(int i=0; i<ary.length-1; i++){
			System.out.printf("%d ",ary[i]);
		}
		System.out.println(ary[ary.length-1]);
	}
	static void puts(long[] ary){
		for(int i=0; i<ary.length-1; i++){
			System.out.printf("%d ",ary[i]);
		}
		System.out.println(ary[ary.length-1]);
	}
	static void tblSort(int[][] tbl){
		Arrays.sort(tbl, new Comparator<int[]>(){
			@Override
			public int compare(int[] a, int[] b){
				if(a[0]==b[0]){
					return b[1]-a[1];
				}else{
					return b[0]-a[0];
				}
			}
		});
	}
}

Measured memory_bytes: 27220
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = 1e5 + 5;
int a[maxn];
int main(){
	int n,x;
	cin >> n >> x;
	int a = x - n + 1, b = x + n - 1;
	for (int i = a; i <= b; i++)
		cout << i << " ";
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int main(){
    int n;
    cin >> n;
    bool flag = true;
    rep(i, n){
        int a;
        cin >> a;
        if (a % 2 == 0){
            if (a % 3 !=0 && a % 5 != 0) flag = false;
        }
    }
    if (flag) cout << "APPROVED" << endl;
    else cout << "DENIED" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define chmax(a, b) a = (a >= b ? a : b)
#define chmin(a, b) a = (a <= b ? a : b)
#define out(a) cout << a << endl
#define outa(a, n) { rep(_, n) cout << a[_] << " "; cout << endl; }
#define outp(a, n) { cout << endl; rep(_, n) cout << a[_].F << " " << a[_].S << endl; }
#define sz(v) (int)v.size()
#define inf (int)(1e9+7)
#define abs(x) (x >= 0 ? x : -(x))
#define ceil(a, b) a / b + !!(a % b)
#define FIX(a) fixed << setprecision(a)
#define LB(v, n) (int)(lower_bound(all(v), n) - v.begin())
#define UB(v, n) (int)(upper_bound(all(v), n) - v.begin())
ll pow(ll a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }




using Point = complex<double>;
double dot(Point a, Point b) { return real(conj(a) * b); }
double cross(Point a, Point b) { return imag(conj(a) * b); }
const double eps = 1e-10;

int main() {
    int query;
    cin >> query;
    while (query--) {
        int p0x, p0y, p1x, p1y, p2x, p2y, p3x, p3y;
        cin >> p0x >> p0y >> p1x >> p1y >> p2x >> p2y >> p3x >> p3y;
        
        Point s1 = Point(p1x - p0x, p1y - p0y), s2 = Point(p3x - p2x, p3y - p2y);
        if (abs(dot(s1, s2)) < eps) {
            cout << 1 << endl;
        } else if (abs(cross(s1, s2)) < eps) {
            cout << 2 << endl;
        } else {
            cout << 0 << endl;
        }
        
        
    }
}



Measured memory_bytes: 3096
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
const int MaxN = 5e5;
using namespace std;
int pre[MaxN + 5][3], a[MaxN + 5], last[MaxN + 5];
int dp[MaxN + 5];
char s[MaxN + 5];
int n;
int main()
{
	while(~scanf("%d", &n)) {
		scanf("%s", s + 1);
		for (int i = 1; i <= n; i++) {
			a[i] = s[i] - '0';
			pre[i][0] = last[0];
			last[a[i]] = i;
		}
		for (int i = 0; i <= n; i++) dp[i] = -(1 << 30);
		dp[0] = 0;
		for (int i = 1; i <= n; i++) {
			dp[i] = dp[i - 1];
			if(!a[i]) continue;
			if(a[i - 2] && !a[i - 1] && a[i]) {
				int l = pre[i - 2][0];
				dp[i] = max(dp[i], dp[l] + i - l - 2);
				dp[i] = max(dp[i], dp[l + 1] + i - l - 3);
			}
			int k = pre[i][0];
			if(k >= 2 && a[k - 1]) {
				dp[i] = max(dp[i], dp[k - 2] + i - k);
			}
		}
		printf("%d\n", dp[n]);
	}
}

Measured memory_bytes: 12416
#include <iostream>
#include <cmath>
using namespace std;
 
int main(void){
  long double a,b,c;
  cin >> a >> b >> c;
  long long d=c-a-b;
  if(d>0 && d*d-4*a*b>0)cout << "Yes" <<endl;
  else cout << "No"<<endl;
}


Measured memory_bytes: 3684
using System;
using System.Collections.Generic;
using System.Linq;
class Program
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        Graph g = new Graph(n);
        for (int i = 0; i < n; i++)
        {
            int[] s = Console.ReadLine().Split(' ').Select(p => int.Parse(p)).ToArray();
            int u = s[0];
            for (int j = 2; j < s.Length; j++)
                g.SetEdge(u, s[j]);
        }
        for (int i = 1; i <= n; i++)
            g.DFS(i);
        for (int i = 0; i < n; i++)
            Console.WriteLine("{0} {1} {2}", i + 1, g.d[i], g.f[i]);
    }
}
class Graph
{
    private int n;
    private List<int>[] adj;
    public int[] d;
    public int[] f;
    private bool[] v;
    int t = 1;
    public Graph(int n)
    {
        this.n = n;
        adj = new List<int>[n];
        d = new int[n];
        f = new int[n];
        v = new bool[n];
        for (int i = 0; i < n; i++)
        {
            adj[i] = new List<int>();
        }
    }
    public void SetEdge(int s, int g)
    {
        if (s > n || g > n)
            return;
        adj[s - 1].Add(g);
    }
    public List<int> GetEdge(int i)
    {
        return adj[i - 1];
    }
    public void DFS(int s)
    {
        if (!v[s - 1])
        {
            v[s - 1] = true;
            d[s - 1] = t;
            t++;
            foreach (var i in GetEdge(s))
                if (!v[i - 1])
                    DFS(i);
            f[s - 1] = t;
            t++;
        }
    }
}


Measured memory_bytes: 9720
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
const int N = 405;
const int mod = 1e9 + 7; 
using namespace std;

int n, m, sum[N][N], a[N], b[N], f[N][N]; 

template < typename T >
inline T read()
{
	T x = 0, w = 1; char c = getchar();
	while(c < '0' || c > '9') { if(c == '-') w = -1; c = getchar(); }
	while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return x * w; 
}

int fpow(int x, int y)
{
	int res = 1;
	for( ; y; y >>= 1, x = 1ll * x * x % mod)
		if(y & 1) res = 1ll * res * x % mod;
	return res; 
}

int calc(int k, int l, int r) { return (sum[k][r] - sum[k][l - 1] + mod) % mod; }

int main()
{
	n = read <int> (), m = read <int> ();
	for(int i = 0; i <= m; i++)
		for(int j = 1; j <= 400; j++)
			sum[i][j] = (sum[i][j - 1] + fpow(j, i)) % mod; 
	for(int i = 1; i <= n; i++) a[i] = read <int> ();
	for(int i = 1; i <= n; i++) b[i] = read <int> ();
	f[0][0] = 1; 
	for(int i = 1; i <= n; i++)
		for(int j = 0; j <= m; j++)
			for(int k = 0; k <= j; k++)
				f[i][j] = (1ll * f[i - 1][j - k] * calc(k, a[i], b[i]) + f[i][j]) % mod;
	printf("%d\n", f[n][m]); 
	return 0; 
}


Measured memory_bytes: 4504
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
 
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)
#define VSORT(v) sort(v.begin(), v.end())
#define SORT(v, n) sort(v, v+n)
#define VREV(v,n) reverse(v,v+n)
#define REV(v,n) reverse(v,v+n)
#define vi vector<int>
#define pf push_front
#define pb push_back
#define P pair<int,int>
#define Pll pair<ll,ll>

template<class T, size_t N> size_t countof(const T (&array)[N]) { return N; }
template <class T> void chmin(T&a,const T&b) { a = min(a,b); }
template <class T> void chmax(T&a,const T&b) { a = max(a,b); }
 
void print(){cout<<"\n";}
template <class Head, class... Tail>
void print(Head&& h,Tail&&... t){ 
	if(sizeof...(t)==0)
		cout<<h;
	else
		cout<<h<<' ';
	print(move(t)...);
}

void mprint(auto *matrix,auto N){
	REP(i,N) cout<<matrix[i]<<(i!=N-1?' ':'\n');
	return;
}

const double EPS =1e-9;
const int INF =2e+9;
const ll INFL =9e+18;
const long MOD =1e+9+7;
#define PI 3.14159265258979

#define iP pair<int,P>
int dy[]={0, 0, 1, -1, 1, 1, -1, -1};
int dx[]={1, -1, 0, 0, 1, -1, -1, 1};

inline int in(){int x; cin>>x; return x;}
int main(void){
	cin.tie(0);
	ios_base::sync_with_stdio(false);

	string S;
	int K;
	map<string,int> mp;

	cin>>S>>K;

	FOR(i,1,min(6,(int)S.length()+1))
		REP(j,S.length()+1-i)
			mp[(S.substr(j,i))]++;

	int tem=1;
	for(const auto pr:mp){
		if(tem==K){
			print(get<0>(pr));
			return 0;
		}
		tem++;

	}
	return 0;
}



Measured memory_bytes: 1920
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
using namespace std;
typedef long long int ll;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}


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

    int ans = n*n*n;

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



Measured memory_bytes: 3088
#include<iostream>
#include<vector>
#include<algorithm>

int main(){
    int N ;
    std::cin >> N;

    std::vector<int> A(N);
    for (int i=0;i<N;i++) std::cin >> A.at(i);
    std::sort(A.begin(),A.end());

    std::cout << A.at(N-1)-A.at(0) << '\n';

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define fi first
#define se second
#define endl '\n'
#define fn(i,x) for(i=0;i<x;i++)
#define fit(it,s) for(it=s.begin();it!=s.end();it++)
#define vii vector<int>
#define vll vector<ll>
#define mx 1e18
#define mod 1000000007
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mii map<int,int>
#define mll map<ll,ll>
#define sii set<int>
#define sll set<ll>
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int main()
{io
int n;cin>>n;
while(n)
{
	if(n%10==7)
	{
		cout<<"Yes";return 0;
	}n=n/10;
}
cout<<"No";return 0;


	


 
}


Measured memory_bytes: 3640
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <list>
#include <set>
#include <stack>
#include <deque>
#include <queue>
#include <cmath>
#include <algorithm>
#include <utility>
#include <functional>
#include <fstream>
#define debug(x) cout << #x << " = " << x << endl
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define repr(i,n) for(int i = (n); i > -1; i--)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const ll LINF = 1e18;
const double EPS = 1e-9;


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

  // bool f[1000000] = {false};
  map<ll,ll> mp;
  ll s;
  cin>>s;
  mp[s]++;
  ll cnt = 1;
  while(true) {
    cnt++;
    if(s % 2 == 0) {
      s /= 2;
    } else {
      s = 3 * s + 1;
    }
    if(mp[s]) {
      break;
    }
    // f[s] = true;
    mp[s]++;
  }
  cout << cnt << endl;


  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(),(v).end()
typedef pair<int,int> pii;
const int mod = (int) 1000000007;
const int inf = (int) 2e18;

int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
  cout << fixed << setprecision(9);
	#ifdef LOCAL_DEFINE
		freopen("in.txt", "rt", stdin);
	#endif
  // code
  int n;
  cin >> n;
  int cnt = 0, res = 0;
  int di1, di2;
  for(int i=0; i<n; i++){
    cin >> di1 >> di2;
    if(di1 == di2){
      cnt++;
    }
    else{
      res = max(res, cnt);
      cnt = 0;
    }
  }
  res = max(res, cnt);
  if(res >= 3)
    cout << "Yes" << "\n";
  else
    cout << "No" << "\n";
  return 0;
}


Measured memory_bytes: 3648
#include <cstdio>
#include <algorithm>
#include <bitset>
#include <iostream>

using namespace std;

const int R_MAX = 10;
const int C_MAX = 10000;
int R, C;

bitset<C_MAX> grid[R_MAX];

int res;

void dfs(int row) {
  if (row == R) {
    int total_up = 0;
    for(int i=0;i<C;i++) {
      int r_up = 0;
      for(int j=0;j<R;j++) {
        if (grid[j][i]) r_up++;
      }
      total_up += max(r_up, R-r_up);
    }

    res = max(total_up, res);
    return;
  }

  dfs(row+1);
  grid[row].flip();
  dfs(row+1);
}

void solve() {
  res = 0;
  dfs(0);
  printf("%d\n", res);
}

int main() {
  //bool temp;
  while(scanf("%d %d", &R, &C)) {
    if (!R && !C) {
      break;
    }

    for(int i=0;i<R;i++) {
      for(int j=0;j<C;j++) {
        int temp;
        cin >> temp;
        if (temp)   {
          grid[i][j] = 1;
        } else {
          grid[i][j] = 0;
        }
      }
    }
    solve();
  }
  return 0;
}




Measured memory_bytes: 3156
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
	int n, t;
	cin >> n >> t;
	vector<pair<int, int>> vp(n);
	rep(i, n){
		int a, b;
		cin >> a >> b;
		vp.at(i) = make_pair(a, b);
	}
	sort(vp.begin(), vp.end());
	vector<vector<int>> dp(n, vector<int>(t));
	rep(i, t) dp.at(0).at(i) = 0;
	rep2(i, 1, n){
		auto add = vp.at(i-1);
		rep(j, t){
			int a1, a2 = -1;
			a1 = dp.at(i-1).at(j);
			if(0 <= j - add.first) a2 = dp.at(i-1).at(j - add.first) + add.second;
			dp.at(i).at(j) = max(a1, a2);
		}
	}
	int ans = 0;
	rep(i, n){
		int last = vp.at(i).second;
		ans = max(ans, dp.at(i).at(t-1) + last);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 35584
#include<bits/stdc++.h>
#define int long long
#define rint register int
  using namespace std;
// by piano
template<typename tp> inline void read(tp &x) {
  x = 0;char c = getchar();bool f = 0;
  for (; c < '0' || c > '9'; f |= (c == '-'), c = getchar());
  for (; c >= '0' && c <= '9'; x = (x << 3) + (x << 1) + c - '0', c = getchar());
  if (f) x = -x;
}
const int N = 3e5 + 233;
int n, K;
int a[N], a_cnt = 0, b[N], b_cnt = 0;
main(void) {
  read(n); read(K);
  for (int i = 1; i <= n; i ++) {
    int x; read(x);
    if (x >= 0) a[++ a_cnt] = x;
    else b[++ b_cnt] = x;
  }
  reverse(b + 1, b + b_cnt + 1);
  int ans = 1e18;
  for (int i = 0; i <= min(b_cnt, K); i ++) {
    int j = K - i;
    if (j > a_cnt) continue;
    ans = min(ans, min(abs(b[i]) + abs(b[i] - a[j]),
              abs(a[j]) + abs(b[i] - a[j])));
  }
  cout << ans << "\n";
}


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

using namespace std;

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

#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<(b);i++)
#define repr(i,b,a) for(int i=int(b);i>=(a);i--)
#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool valid(int lx,int ux,int ly,int uy,int x,int y){
	return lx<=x&&x<ux&&ly<=y&&y<uy; 
}
ll power(ll x,ll p){
	if(p==0)return 1;
	ll res=power(x*x%mod,p/2);
	if(p%2==1)res=res*x%mod;
	return res;
}

int main()
{
	int n;
	cin>>n;
	repi(i,1,10)repi(j,1,10){
		if(i*j==n){
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
# B>G>R
R,G,B = map(int,input().split())
K = int(input())

cnt = 0

while not G>R:
    G *= 2
    cnt += 1

while not B>G:
    B *= 2
    cnt += 1
    
if cnt<=K:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 8968
// #pragma GCC target("avx2")  // CPU 処理並列化
// #pragma GCC optimize("O3")  // CPU 処理並列化
// #pragma GCC optimize("unroll-loops")  // 条件処理の呼び出しを減らす
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
#include<numeric>
#include<unordered_set>
#include<complex>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-10;
const double INF=1e+10;
const double PI=acos(-1.0);
const int C_SIZE = 3121000;
namespace{
	long long fact[C_SIZE];
	long long finv[C_SIZE];
	long long inv[C_SIZE];
	long long Comb(int a,int b){
	 	if(a<b||b<0)return 0;
	 	return fact[a]*finv[b]%mod*finv[a-b]%mod;
	}
	void init_C(int n){
		fact[0]=finv[0]=inv[1]=1;
		for(int i=2;i<n;i++){
			inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
		}
		for(int i=1;i<n;i++){
			fact[i]=fact[i-1]*i%mod;
			finv[i]=finv[i-1]*inv[i]%mod;
		}
	}
	long long pw(long long a,long long b){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%mod;
			a=a*a%mod;
			b/=2;
		}
		return ret;
	}
	long long pw_mod(long long a,long long b,long long M){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%M;
			a=a*a%M;
			b/=2;
		}
		return ret;
	}
	int pw_mod_int(int a,int b,int M){
		if(a<0)return 0;
		if(b<0)return 0;
		int ret=1;
		while(b){
			if(b%2)ret=(long long)ret*a%M;
			a=(long long)a*a%M;
			b/=2;
		}
		return ret;
	}
	int ABS(int a){return max(a,-a);}
	long long ABS(long long a){return max(a,-a);}
	double ABS(double a){return max(a,-a);}
	int sig(double r) { return (r < -EPS) ? -1 : (r > +EPS) ? +1 : 0; }
}
// ここから編集しろ
int g[310][310];
int t[310][310];
int main(){
	int a,b,c;scanf("%d%d%d",&a,&b,&c);
	for(int i=0;i<a;i++)for(int j=0;j<a;j++){
		g[i][j]=mod;
		t[i][j]=mod;
		if(i==j)g[i][j]=t[i][j]=0;
	}
	for(int i=0;i<b;i++){
		int p,q,r;scanf("%d%d%d",&p,&q,&r);
		p--;q--;
		g[p][q]=g[q][p]=r;
	}
	for(int i=0;i<a;i++)for(int j=0;j<a;j++)for(int k=0;k<a;k++)g[i][j]=min(g[i][j],g[i][k]+g[k][j]);
	for(int i=0;i<a;i++)for(int j=0;j<a;j++)for(int k=0;k<a;k++)g[i][j]=min(g[i][j],g[i][k]+g[k][j]);
	for(int i=0;i<a;i++)for(int j=0;j<a;j++)for(int k=0;k<a;k++)g[i][j]=min(g[i][j],g[i][k]+g[k][j]);
	
	for(int i=0;i<a;i++){
		for(int j=0;j<a;j++){
			if(i!=j&&g[i][j]<=c){
				t[i][j]=1;
			}
		}
	}
	for(int i=0;i<a;i++)for(int j=0;j<a;j++)for(int k=0;k<a;k++)t[i][j]=min(t[i][j],t[i][k]+t[k][j]);
	for(int i=0;i<a;i++)for(int j=0;j<a;j++)for(int k=0;k<a;k++)t[i][j]=min(t[i][j],t[i][k]+t[k][j]);
	for(int i=0;i<a;i++)for(int j=0;j<a;j++)for(int k=0;k<a;k++)t[i][j]=min(t[i][j],t[i][k]+t[k][j]);
	
	int d;scanf("%d",&d);
	while(d--){
		int p,q;scanf("%d%d",&p,&q);p--;q--;
		if(t[p][q]==mod)printf("%d\n",-1);
		else printf("%d\n",t[p][q]-1);
	}
}

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

#define int long long
#define endl "\n"
#define REP(i,a,n) for(int i=a;i<n;++i)
#define REPR(i,a,n) for(int i=a;i>n;--i)
#define RUP(a,b) ((a+b-1)/(b))
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
//#define MOD 1000000007
#define INF LLONG_MAX/2

typedef long long ll;
typedef pair<int,int> Pii;
typedef tuple<int,int,int> Tiii;
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef vector<Pii> VPii;
typedef vector<string> Vs;

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;}
template<class T> void YesNo(T a) {cout<<(a?"Yes":"No")<<endl;}
template<class T> void YESNO(T a) {cout<<(a?"YES":"NO")<<endl;}
void vin(Vi &v){REP(i,0,(v).size()) cin>>v[i];}
void vin(Vi &v,Vi &v2){REP(i,0,(v).size()) cin>>v[i]>>v2[i];}
void vout(Vi &v){for(int i=0;i<(v).size();i++) cout<<v[i]<<" ";cout<<endl;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}
void uniq(Vi &v){sort(v.begin(),v.end()); v.erase(unique(v.begin(),v.end()),v.end());}
int ctoi(char c){if(c>='0'&&c<='9'){return c-'0';}return 0;}
void accum(Vi &v){REP(i,1,(v).size()) v[i]+=v[i-1];}
bool comp(Pii a,Pii b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}


void solve(long long N, std::string S){
    int ans=0;
    REP(i,0,N-2){
        if(S[i]=='A' && S[i+1]=='B' && S[i+2]=='C') ans++;
    }
    cout<<ans<<endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
signed main(){
    long long N;
    scanf("%lld",&N);
    std::string S;
    std::cin >> S;
    solve(N, S);
    return 0;
}


Measured memory_bytes: 256
object Main extends App {
  val in = new java.util.Scanner(System.in)
  val K = in.nextInt

  def calc(k: Int, r: Int = 1, cnt: Int = 1): Int = {
    val newR = r * 10 % k
    if (newR == 1) cnt
    else calc(k, newR, cnt + 1)
  }

  println(
    if (K % 2 == 0 || K % 5 == 0) -1
    else if (K % 7 == 0) calc(9 * K / 7)
    else calc(9 * K)
  )
}

Measured memory_bytes: 55348
#include <stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
 
int main() {
    int n;
    scanf("%d ",&n);
    int a[n],b[n];
    int i;
    for(i=0;i<=n-1;i++)scanf("%d %d",&a[i],&b[i]);
    long long int ans=0;
    for(i=n-1;i>=0;i--){
        if((a[i]+ans)%b[i]!=0)ans+=b[i]-(a[i]+ans)%b[i];
    }
    printf("%lld",ans);
    return 0;
}


Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = Console.ReadLine();
            for (int i = 0; i < 3; i++)
            {
                if (n[i] == '1') Console.Write(9);
                else Console.Write(1);
            }
        }
    }
}

Measured memory_bytes: 13140
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);
		int x = sc.nextInt();
		int y = sc.nextInt();

		out.println(x+y/2);

		sc.close();
	}

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

}


Measured memory_bytes: 21844