akhauriyash/Code-Regression huggingface dataset:
import java.util.* ;
class Main {
  public static void main(String[] args) {
    
    Scanner scan = new Scanner(System.in);

	int a = scan.nextInt();
    int b = scan.nextInt();
    
    for(int i = b-(a-1) ; i<=b+(a-1) ; i++){
      System.out.println(i);
    }
  }
}


Measured memory_bytes: 22868
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-9;

//int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;


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

	cin >> N >> M >> K;
	vector<long long int>v(N);
	for (auto &i : v)cin >> i;
	vector<long long int>w;
	for (int i = 0; i < N; i++) {
		w.push_back(K*M);
		K--;
	}
	long long int ans = accumulate(v.begin(), v.end(), 0LL);
	long long int add = 0;
	priority_queue<long long int>PQ;
	for (int i = 0; i < N; i++)PQ.push(w[i] - v[i]);
	long long int cadd = 0;
	for (int i = 0; i < N; i++) {
		cadd += M * 2 * i;
		cadd += PQ.top();
		PQ.pop();
		add = max(add, cadd);
	}
	cout << ans + add << endl;
}


Measured memory_bytes: 16792
#include<bits/stdc++.h>
using namespace std;
const int maxn = 200005;
int a[maxn];
int n,k,x;
map<int,int> Q;
int main()
{
    cin>>n>>k;
    int now = 0;
    for(int i=1;i<=n;i++)
    {
        a[i]=0;
    }
     for(int i=1;i<=n;i++)
    {
        cin>>x;
        a[x]++;
        if(!Q.count(x))
        {
            Q[x]=1;
            now++;
        }
    }
    sort(a+1,a+1+n);
    int sum = 0;
    for(int i=n-now+1;i<=n-k;i++)
    {
        sum+=a[i];
    }
    cout<<sum<<endl;
}

Measured memory_bytes: 10368
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		S += S;
		if(S.contains(sc.next())) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
	}
}


Measured memory_bytes: 26920
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<vector>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#define ll long long
#define F(i,a,b) for(int i=(a);i<=(b);i++)
#define mst(a,b) memset((a),(b),sizeof(a))
#define PII pair<int,int>
using namespace std;
template<class T>inline void read(T &x) {
    x=0; int ch=getchar(),f=0;
    while(ch<'0'||ch>'9'){if (ch=='-') f=1;ch=getchar();}
    while (ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
    if(f)x=-x;
}
const int inf=0x3f3f3f3f;
const int maxn=20;
int n,ans;
int a[maxn],x[maxn][maxn],y[maxn][maxn];
int lowbit(int x){return x&-x;}
int count(int x)
{
	int res=0;
	while(x) x-=lowbit(x),res++;
	return res;
}
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		for(int j=1;j<=a[i];j++)
		{
			cin>>x[i][j]>>y[i][j];
			x[i][j]--;
		}
	}
	for(int i=0;i<(1<<n);i++)
	{
		int flag=1;
		for(int j=0;j<n;j++)
		{
			if(i>>j&1)
			{
				for(int k=1;k<=a[j+1];k++)
				{
					if((i>>x[j+1][k]&1)^y[j+1][k]) flag=0;
				}
			}
		}
		if(!flag) continue;
		ans=max(ans,count(i));
	}
	cout<<ans<<endl;
	return 0;
}


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

int main() {
    int A, B, C, X;
    cin >> A >> B >> C >> X;
  int counter = 0;
    for(int i = 0;i < A + 1;++i){
    for(int j = 0;j < B + 1;++j){
    for(int k = 0;k < C + 1;++k){
    
      if(500 * i + 100 * j + 50 * k == X){
      counter = counter + 1;
      }
      
    }
      
      
    }
      
      
    }
    cout << counter << endl;
    
}

Measured memory_bytes: 256
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		Set<String> present = new HashSet<String>();
		for (int i = 0; i < N; i++) {
			present.add(sc.next());
		}
		System.out.println(present.size());
	}

}


Measured memory_bytes: 78632
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<iomanip>
#include<set>

using namespace std;

int main()
{
	long long n;
	cin >> n;
	string str;
	for(int i=0;i<100000000;i++)
	{
		int d=n%2;
		if(d<0)d+=2;
		str+=('0'+d);
		n-=(d);
		n/=(-2);
		if(n==0)break;
	}
	reverse(str.begin(),str.end());

	cout << str << endl;




}


Measured memory_bytes: 256
I=lambda:list(map(int,input().split()))
N,W=I()
g={}
for _ in[0]*N:
  a,b=I()
  g[a]=g.get(a,[])+[b]
*w,=g.keys()
v=[]
for i in range(len(w)):
  s=[0]+sorted(g[w[i]])[::-1]
  for i in range(1,len(s)):
    s[i]+=s[i-1]
  v.append(s)
for i in range(len(w),4):
  w.append(10**18+i)
  v.append([0,10**18])
ans=0
for i in range(len(v[0])):
  s0=w[0]*i
  for j in range(len(v[1])):
    s1=s0+w[1]*j
    if s1>W:break
    for k in range(len(v[2])):
      s2=s1+w[2]*k
      if s2>W:break
      l=min((W-s2)//w[3],len(v[3])-1)
      ans=max(ans,v[0][i]+v[1][j]+v[2][k]+v[3][l])
print(ans)

Measured memory_bytes: 41072
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
const int inf=1e9+7;
const ll mod=1e9+7;

int main() {
    vector<int> ansarr;
    int W, H;
    while(true){
        cin>>W>>H;
        if((W==0) & (H==0))break;
        vector<vector<int> > kabe(2*H-1);
        int tmp;
        for(int i=0;i<2*H-1;++i){
            if(i%2==0){
                for(int j=0;j<W-1;++j){
                    cin>>tmp;
                    kabe[i].push_back(tmp);
                }
            }
            else{
                for(int j=0;j<W;++j){
                    cin>>tmp;
                    kabe[i].push_back(tmp);
                }
            }
        }
        queue<pair<int, int> > que;
        queue<int> numque;
        pair<int, int> state;
        map<pair<int, int>, int> past;
        int num;
        que.push(make_pair(0, 0));
        numque.push(1);
        int ans = 0;
        int x, y;
        while(!que.empty()){
            state = que.front();que.pop();
            num = numque.front();numque.pop();
            x = state.se;
            y = state.fi;
            if((x==W-1) & (y==H-1)){
                ans = num;
                break;
            }
            if(past[make_pair(y, x)]>0)continue;
            past[make_pair(y, x)] = 1;
            if(x-1>=0){
                if((kabe[2*y][x-1]==0) & (past[make_pair(y, x-1)]==0)){
                    que.push(make_pair(y, x-1));
                    numque.push(num+1);
                }
            }
            if(x+1<W){
                if((kabe[2*y][x]==0) & (past[make_pair(y, x+1)]==0)){
                    que.push(make_pair(y, x+1));
                    numque.push(num+1);
                }
            }
            if(y-1>=0){
                if((kabe[2*y-1][x]==0) & (past[make_pair(y-1, x)]==0)){
                    que.push(make_pair(y-1, x));
                    numque.push(num+1);
                }
            }
            if(y+1<H){
                if((kabe[2*y+1][x]==0) & (past[make_pair(y+1, x)]==0)){
                    que.push(make_pair(y+1, x));
                    numque.push(num+1);
                }
            }
        }
        ansarr.push_back(ans);
    }
    for(int i=0;i<ansarr.size();++i){
        cout<<ansarr[i]<<endl;
    }
}




Measured memory_bytes: 3200
#include <iostream>
#include <string>
#define REP(i,n) for(int i=0;i<(n);++i)
using namespace std;

const int BITS_COUNT_TABLE[256] = {
    0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4,
    1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
    1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
    2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
    1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
    2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
    2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
    3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
    1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
    2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
    2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
    3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
    2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
    3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
    3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
    4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8,
};

int popcnt(int x) {
    return BITS_COUNT_TABLE[x&0xFF] + BITS_COUNT_TABLE[x >> 8];
}

bool ishonest(int bits, int n) {
  return (bits & (1 << n)) != 0;
}

int main(){
  int N;
  int X[15][15];
  
  cin >> N;
  REP(i, N) {
    int A;
    cin >> A;
    REP(j, N) {
      X[i][j] = -1;
    }
    REP(j, A) {
      int _X, _Y;
      cin >> _X >> _Y;
      X[i][_X-1] = _Y;
    }
  }
  int ret = 0;
  int lmax = 1 << N;
  REP(i, lmax) {
    if(ret >= popcnt(i)) {
      continue;
    }
    int flag = true;
    for(int j = 0; j < N && flag; ++j) {
      if(ishonest(i, j)) {
        REP(k, N) {
          if(X[j][k] != -1 && X[j][k] != ishonest(i, k)) {
            flag = false;
          }
        }
      }
    }
    if(flag) {
      ret = popcnt(i);
    }
  }
  cout << ret << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long a,b,c,d,e,i,j,zx,xc;
string s;
char ch;
int main(){
    ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    cin>>a;
    while(a>0){
        b=a%26;
        if(b!=0){
            ch='a'+b-1;
            a/=26;
        }else{
            ch='z';
            a/=26;a--;
        }
        s.push_back(ch);
    }
    for(i=s.size()-1; i>=0; i--) cout<<s[i];
    return 0;
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll dp[200005][2];
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    string s;
    cin>>s;
    ll n=s.length();
    dp[0][0]=dp[1][1]=1;
    for(ll i=1;i<n;i++)
    if(s[i]==s[i-1]){
        dp[i][0]=dp[i-1][1]+1;
        if(i>1){
            dp[i][1]=dp[i-2][0]+1;
            if(i>2&&s[i-1]==s[i-2]&&s[i-3]==s[i-2])
            continue;
            dp[i][1]=max(dp[i][1],dp[i-2][1]+1);
        }
    }
    else{
        dp[i][0]=max(dp[i-1][0],dp[i-1][1])+1;
        dp[i][1]=max(dp[i-2][0],dp[i-2][1])+1;
    }
    cout<<max(dp[n-1][0],dp[n-1][1]);
}

Measured memory_bytes: 3732
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/range/adaptors.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/irange.hpp>
#include "bits/stdc++.h"

namespace adaptor = boost::adaptors;

const int64_t nmax = 25;
const int64_t nil = -1;

struct Node {
    int64_t parent, left, right;
};
Node T[nmax];
int64_t n;

void preParse(int64_t u) {
    if (u == nil) return;
    std::cout << " " << u;
    preParse(T[u].left);
    preParse(T[u].right);
}

void inParse(int64_t u) {
    if (u == nil) return;
    inParse(T[u].left);
    std::cout << " " << u;
    inParse(T[u].right);
}

void postParse(int64_t u) {
    if (u == nil) return;
    postParse(T[u].left);
    postParse(T[u].right);
    std::cout << " " << u;
}

void solve() {
    std::cin >> n;
    for (int64_t i = 0; i < n; i++) {
        T[i].parent = T[i].left = T[i].right = nil;
    }

    for (int64_t i = 0; i < n; i++) {
        int64_t value, left, right;
        std::cin >> value >> left >> right;
        T[value].left = left;
        T[value].right = right;
        if (left != nil) T[left].parent = value;
        if (right != nil) T[right].parent = value;
    }

    int64_t root;
    for (int64_t i = 0; i < n; i++) {
        if (T[i].parent == nil) root = i;
    }

    std::cout << "Preorder" << std::endl;
    preParse(root);
    std::cout << std::endl;
    std::cout << "Inorder" << std::endl;
    inParse(root);
    std::cout << std::endl;
    std::cout << "Postorder" << std::endl;
    postParse(root);
    std::cout << std::endl;

    return;
}

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



Measured memory_bytes: 3156
#include <iostream>
#include <queue>
#include <string.h>
#define EPS (1.0e-9)
#define LT(x, y) ((x) - (y) <= -EPS) // x < y
#define INF (1<<19)
using namespace std;
typedef struct DisLim {
 int d, c; // dist, limit v
 DisLim() {}
 DisLim(int d, int c) : d(d),c(c) {}
} DisLim;
int N,M;
int S,G; // start, goal
DisLim F[31][31];

double dist[31][31][31];
bool visited[31][31][31];
class State {
public:
 int bpos, cpos; // before,current
 double d; // ツ仰猟猟」
 int v; // ツ堕ャツ度
 State (int bpos, int cpos, double d, int v) :
   bpos(bpos),cpos(cpos),d(d),v(v) {}
 bool operator < (const State &s) const {
   //return d > s.d;
   return LT(s.d,d);
 }
};

priority_queue<State> PQ;
double solve() {
  while(!PQ.empty()) {
    State u = PQ.top(); PQ.pop();
    int bpos=u.bpos, cpos=u.cpos, v=u.v;
    double d = u.d;
    
    visited[bpos][cpos][v] = true;
    if(cpos == G && v == 1) {
      return dist[bpos][G][1];
    }

    for(int i=1;i<=N;i++) { // ツ篠淞づ個都ツ市
      if(i==bpos || i==cpos) continue; // ツ古」ツ姪淞づィツ凝鳴止
      for(int j=-1;j<=1;j++) { // ツ嘉個クツ堕ャツ堕閉置
	if(bpos==S && S==cpos && j != 0) continue;
	if(v+j <= 0) continue;
	if(v+j > F[cpos][i].c) continue;
	if(visited[cpos][i][v+j]) continue;
	if(F[cpos][i].d >= INF) continue;
	double cost = dist[bpos][cpos][v] + (double)F[cpos][i].d / (v+j);
	if(LT(cost,dist[cpos][i][v+j])) {
	  dist[cpos][i][v+j] = cost;
	  PQ.push(State(cpos,i,cost,v+j));
	}
      }
    }
  }
  return -1;
}

main() {
 while(cin>>N>>M,N) {
   PQ = priority_queue<State>();
   memset(visited,0,sizeof(visited));
   for(int i=1;i<=N;i++) {
     for(int j=1;j<=N;j++) {
       F[i][j].d=INF;
     }
   }
   cin>>S>>G;
   for(int i=1;i<=N;i++) {
     for(int j=1;j<=N;j++) {
       for(int k=0;k<31;k++) {
         dist[i][j][k] = INF;
       }
     }
   }
   for(int i=0;i<31;i++) {
     dist[S][S][i] = 0;
   }
   PQ.push(State(S,S,0,1));
   for(int i=0;i<M;i++) {
     int x,y,d,c; cin>>x>>y>>d>>c;
     F[x][y]=F[y][x]=DisLim(d,c);
   }
   double ans = solve();
   if(ans==-1) puts("unreachable");
   else printf("%.5lf\n",ans);
 }
}

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

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

  const int ma = 1000001;
  bool ok[ma];
  for(int i=0; i<ma; i++) ok[i]=false;

  int a[n];
  for(int i=0; i<n; i++) {
    int j;
    cin>>j;
    a[i] = j;
    ok[j] = true;
  }

  sort(a, a+n);

  for(int i=0; i<n; i++) {
    if(i>0 && a[i-1]==a[i]) {
      ok[a[i]] = false;
    }
    else {
      int check = a[i]*2;
      while(check<ma) {
        ok[check] = false;
        check += a[i];
      }
    }
  }

  int ans = 0;
  for(int i=0; i<ma; i++) {
    if(ok[i]) ans++;
  }

  cout<<ans<<endl;

  return 0;
}

Measured memory_bytes: 5364
#include <iostream>
#include <math.h>
#include <stdio.h>
using namespace std;

int main(void)
{
    //string a,b;
    int a,b,c,d;
    //char a,b,c;
    int i=0,sum=0;
    //char a,b='.';
    cin>>a>>b;
    cout<<max(max(a+b,a-b),a*b);
    return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
 #define N 2000000
 
int H;
 
void maxHeapify(int *A, int i){
  int l,r,largest,temp;
  l = i*2;
  r = i*2+1;
  if(l<=H && A[l] > A[i]) largest = l;
  else largest = i;
   
  if(r<=H && A[r] > A[largest])largest = r;
 
  if(largest != i){
    temp=A[i];
    A[i]=A[largest];
    A[largest]=temp;
    maxHeapify(A, largest);
  }
}
 
void buildMaxHeap(int *A){
  int i;
  for(i=H/2;i>=1;i--) {
    maxHeapify(A, i);
  }
}
 
int main(){
  int i,heap[N];
 
  scanf("%d",&H);
  for(i=1;i<=H;i++) scanf("%d",&heap[i]);
 
  buildMaxHeap(heap);
   
  for(i=1;i<=H;i++) printf(" %d",heap[i]);
  printf("\n");
  return 0;
}

Measured memory_bytes: 4368
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define lld long double
#define w(x) ll x;cin>>x;while(x--)
#define mod 1000000007
#define speed ios_base::sync_with_stdio(false);cin.tie(0);
using namespace std;

int main(){
    speed;
    ll h,w,k;  cin>>h>>w>>k;
    vector<vector<char>> a(h,vector<char>(w));
    for(ll i=0;i<h;i++){
        for(ll j=0;j<w;j++){
            cin>>a[i][j];
        }
    }
    ll ans=0;
    for(ll i=0;i<(1<<h);i++){
        for(ll j=0;j<(1<<w);j++){
            ll black=0;
            for(ll p=0;p<h;p++){
                if(i&(1<<p))    continue;
                else{
                    for(ll l=0;l<w;l++){
                        if(j&(1<<l))    continue;
                        if(a[p][l]=='#')  black++;
                    }
                }
            }    
            if(black==k)    ans++; 
        }
    }
    cout<<ans<<'\n';
    return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <fstream>
#include <string>
#include <math.h>
#include <cstdlib>
#include <istream>
#include <sstream>
#include <cctype>
#include <iomanip>
//cout << fixed << setprecision(20) << *** << endl;
#define rep(i,N) for(int i=0;i<(int)N;++i)
typedef long long ll;
using namespace std;

int main()
{
	ll N,K;
	map<ll,ll>mp;
	vector<ll>V;
	cin>>N>>K;
	rep(i,N){
		ll t;
		cin>>t;
		if(mp.count(t)==0){
			mp[t]=1;
		}
		else{
			mp[t]++;
		}
	}
	map<ll,ll>::iterator itr;
	for(itr=mp.begin();itr!=mp.end();itr++){
		V.push_back(itr->second);
	}
	cout<<endl;
	sort(V.begin(),V.end());
	ll ANS=0;
	K=mp.size()-K;
	for(ll i=0;i<K;i++){
		ANS=ANS+V[i];
	}
	cout<<ANS<<endl;
}

Measured memory_bytes: 17304
#include <bits/stdc++.h>
using namespace std;
#define ll          long long
#define mp	    make_pair
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define MOD        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define gcd(a,b)    __gcd((a),(b))
#define lcm(a,b)    ((a)*(b)) / gcd((a),(b))
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define N	 100
void solve(){
	string s, t;
	cin>>s>>t;
	reverse(all(t));
	if(t==s)cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
}
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t;
    t =1;
//     cin>>t;
    while(t--){
        solve();
    }
    return 0;
}



Measured memory_bytes: 384
package main

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

var sc = bufio.NewScanner(os.Stdin)

func readLineToInt() []int {
    sc.Scan()
    line := strings.Split(sc.Text(), " ")
    length := len(line)
    var intLine []int
    for i := 0; i < length; i++ {
        n, _ := strconv.Atoi(line[i])
        intLine = append(intLine, n)
    }
    return intLine
}

func readInt() int {
    sc.Scan()
    line := strings.Split(sc.Text(), " ")
    n, _ := strconv.Atoi(line[0])
    return n
}

func main() {
    wht := readLineToInt()
    _, h, _ := wht[0], wht[1], wht[2]
    p := readInt()
    var xSave []int
    var ySave []int
    for i := 0; i < p; i++ {
        xyt := readLineToInt()
        xSave = append(xSave, xyt[0])
        ySave = append(ySave, xyt[1])
    }
    var mp [][]int
    for i := 0; i < h; i++ {
        mp = append(mp, readLineToInt())
    }
    ans := 0
    for i := 0; i < p; i++ {
        x, y := xSave[i], ySave[i]
        if mp[y][x] == 1 {
            ans++
        }
    }
    fmt.Println(ans)
}


Measured memory_bytes: 1268
import sys
sys.setrecursionlimit(100000000)
def input():
    return sys.stdin.readline()[:-1]
from bisect import *
from collections import *
from heapq import *
from math import *
N, M, K = map(int, input().split())
L = N*M
mod = 10**9+7
def factrial(N):
    fc = [1, 1] + [None] * N
    inv = [0, 1] + [None] * N
    fcInv = [1, 1] + [None] * N
    for i in range(2, N+1):
        fc[i] = i*fc[i-1]%mod
        inv[i] = mod-(inv[mod%i]*(mod//i))%mod
        fcInv[i] = fcInv[i-1]*inv[i]%mod
    return fc, fcInv
fc, fcInv = factrial(L)
def modCom(n, k):
    return 0 if n < k else fc[n] * fcInv[k] * fcInv[n-k] % mod
ans = 0
for d in range(1, N):
    ans += d*(N-d)*M*M*modCom(L-2, K-2)
    ans %= mod
for d in range(1, M):
    ans += d*(M-d)*N*N*modCom(L-2, K-2)
    ans %= mod
print(ans)


Measured memory_bytes: 28624
import scala.io.StdIn.readLine

object Main {

  def pow(x:Long, y:Long, z:Long):Long = {

    def multi(m:Long, n:Long) = { ( (m%z) * (n%z) ) % z }

    def pow2(m:Long, n:Long, odd:Long, b:Long):Long = {
      n match {
        case 0 => 1
        case 1 => multi(m, odd)
        case _ =>
          val t = if(n%2 == 1) multi(odd, b) else odd
          pow2(multi(m,m), n/2, t, multi(b,b))
      }
    }
    pow2(x, y, 1, x)
  }

  def main(args: Array[String]) = {
    val l = readLine().split(" ").map(_.toLong)
    val (m, n) = (l(0), l(1))
    println(pow(m,n,1000000007))
  }
}

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

char s[20];

int main(){
	int a, b, c, d;
	scanf("%d%d%d%d", &a, &b, &c, &d);
	int dx = c - a, dy = d - b;
	f(i, 0, dx)printf("R");
	f(i, 0, dy)printf("U");
	f(i, 0, dx)printf("L");
	f(i, 0, dy + 1)printf("D");
	f(i, 0, dx + 1)printf("R");
	f(i, 0, dy + 1)printf("U");
	printf("L");
	printf("U");
	f(i, 0, dx + 1)printf("L");
	f(i, 0, dy + 1)printf("D");
	printf("R");
	printf("\n");
}


Measured memory_bytes: 256
function main(lines) {
    const arrayX = lines.split('\n')[1].split(' ').map(Number)
    const arrayY = lines.split('\n')[2].split(' ').map(Number)

    let calcFirst = 0
    let calcSecond = 0
    let calcThird = 0
    for(let i=0; i<arrayX.length; i++){
        calcFirst += Math.pow(abs(arrayX[i] - arrayY[i]), 1)
        calcSecond += Math.pow(abs(arrayX[i] - arrayY[i]), 2)
        calcThird += Math.pow(abs(arrayX[i] - arrayY[i]), 3)
    }
    
    let calcInfinity = []
    for(let i=0; i<arrayX.length; i++){
        calcInfinity.push(abs(arrayX[i] - arrayY[i]))
    }
    
    console.log(calcFirst.toFixed(5))
    console.log((Math.pow(calcSecond, 1/2)).toFixed(5))
    console.log((Math.pow(calcThird, 1/3)).toFixed(5))
    console.log((Math.max(...calcInfinity)).toFixed(5))

    function abs(val){
        return val<0 ? -val : val;
    }
    
    
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));



Measured memory_bytes: 15396
from enum import Enum
import sys
 
BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001
 
class Point():
    def __init__(self,arg_x,arg_y):
        self.x = arg_x
        self.y = arg_y
 
def calc_len(a,b):
    from math import sqrt
    return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y))
 
x1,y1,x2,y2 = map(float,input().split())
 
p1 = Point(x1,y1)
p2 = Point(x2,y2)
 
print("%.10f"%calc_len(p1,p2))


Measured memory_bytes: 6356
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) FOR(i, 0, (n))
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define LAR(a, b) ((a)=max((a),(b)))
#define SML(a, b) ((a)=min((a),(b)))
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vl = vector<ll>;
using pii = pair<int, int>;
using vpii = vector<pair<int, int>>;
template<typename T>
using pque = priority_queue<T, vector<T>, greater<T>>;
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define ALL(a) (a).begin(), (a).end()
#ifdef LOCAL_DEBUG
#define DEBUG(...) printf(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

bool next_one(int *s, int *t, int k){
	while(s < t){
		if(++*s < k) return true;
		*(s++) = 0;
	}
	return false;
}

constexpr int N = 32;
int x[2][N];
ll z[N];

int p[N] = {};
int m[2][1<<15][N];
int q[N] = {};
ll ans[N];

int main(){
	int n; scanf("%d", &n);
	REP(i, n) scanf("%d%d%lld", x[0]+i, x[1]+i, z+i);

	REP(h, 2){
		REP(t, 1<<n){
			REP(i, n){
				int &y = m[h][t][i];
				y = abs(x[h][i]);
				REP(j, n){
					if(t & (1<<j)){
						SML(y, abs(x[h][i]-x[h][j]));
					}
				}
			}
		}
	}

	fill(ans, ans+N, LLONG_MAX);
	do{
		fill(q, q+n, INT_MAX);
		REP(h, 2){
			int t = 0;
			REP(i, n) if(p[i]==h) t|=1<<i;
			REP(i, n) SML(q[i], m[h][t][i]);
		}
		ll sm = 0;
		REP(i, n) sm += z[i] * q[i];
		int b = 0;
		REP(i, n) if(p[i]<2) b++;
		SML(ans[b], sm);
	}while(next_one(p, p+n, 3));

	REP(i, n+1) printf("%lld\n", ans[i]);
}


Measured memory_bytes: 12048
#include<iostream>
#include<vector>
#include<stack>
using namespace std;
static const int MAX = 100000;
static const int NIL = -1;

int n;
vector<int> G[MAX];
int color[MAX];

void dfs(int r, int c) {
	stack<int> S;
	S.push(r);
	color[r] = c;
	while (!S.empty()) {
		int u = S.top();
		S.pop();
		for (int i = 0; i < G[u].size(); i++) {
			int v = G[u][i];
			if (color[v] == NIL) {
				color[v] = c;
				S.push(v);
			}
		}
	}
}

void assignColor() {
	int id = 1;
	for (int i = 0; i < n; i++)color[i] = NIL;
	for (int u = 0; u < n; u++) {
		if (color[u] == NIL)dfs(u, id++);
	}
}

int main() {
	int s, t, m, q;

	cin >> n >> m;

	for (int i = 0; i < m; i++) {
		cin >> s >> t;
		G[s].push_back(t);
		G[t].push_back(s);
	}

	assignColor();

	cin >> q;

	for (int i = 0; i < q; i++) {
		cin >> s >> t;
		if (color[s] == color[t]) {
			cout << "yes" << endl;
		}
		else {
			cout << "no" << endl;
		}
	}

	return 0;
}


Measured memory_bytes: 8928
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
#define ALL(obj) (obj).begin(),(obj).end()

int main(){
    int r,g,b;
    cin >> r >> g >> b;
    int sum=g*10+b;
    if(sum%4){
        cout << "NO" << endl;
    }else{
        cout << "YES" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int S = 1 << 21;
char p0[S],*p1,*p2;
#ifndef ZXY
#define getchar() (p2 == p1 && (p2 = (p1 = p0) + fread(p0,1,S,stdin)) == p1 ? EOF : *p1++)
#endif
inline int read() {
	static int x,c;x = 0;
	do{c = getchar();}while(!isdigit(c));
	do{x = (x << 3) + (x << 1) + (c & 15);c = getchar();}while(isdigit(c));
	return x;
}
const int N = 16;
int n;
long long x[N],y[N],p[N];
long long dp[1 << N][N],sum,rk,res[1 << N];
inline bool cmp1(const int &a,const int &b) {
	return x[a] < x[b];
}
inline bool cmp2(const int &a,const int &b) {
	return y[a] < y[b];
}
inline long long calc(int S) {
	long long res1 = 0,res2 = 0,__ = 0;
	vector<int> v;
	int mid;
	rk = sum = 0;
	dp[S][0] = 0;
	for(int i = 1;i <= n;++i)
		if((S >> i-1) & 1) {
			sum += p[i],v.push_back(i);
			dp[S][0] += min(abs(x[i]),abs(y[i])) * p[i];
		}
	sort(v.begin(),v.end(),cmp1);
	for(int i = 0;i < v.size();++i) {
		rk += p[v[i]];
		if(rk > sum / 2) {
			mid = v[i];
			break;
		}
	}
	for(int i = 0;i < v.size();++i)
		res1 += abs(x[mid] - x[v[i]]) * p[v[i]];
	rk = 0;
	sort(v.begin(),v.end(),cmp2);
	for(int i = 0;i < v.size();++i) {
		rk += p[v[i]];
		if(rk > sum / 2) {
			mid = v[i];
			break;
		}
	}
	for(int i = 0;i < v.size();++i)
		res2 += abs(y[mid] - y[v[i]]) * p[v[i]];
	return min(res1,res2);
}
int main() {
	scanf("%d",&n);
	for(int i = 1;i <= n;++i)
		scanf("%lld%lld%lld",x+i,y+i,p+i);
	memset(dp,0x3f,sizeof dp);
	for(int S = 0;S < (1 << n);++S)
		res[S] = calc(S);
	for(int k = 1;k <= n;++k) {
		for(int S = 0;S < (1 << n);++S) {
			dp[S][k] = res[S];
			for(int S0 = (S-1) & S;S0;S0 = (S0-1) & S)
				dp[S][k] = min(dp[S][k],dp[S ^ S0][k-1] + res[S0]);
		}
	}
	for(int i = 0;i <= n;++i)
		printf("%lld\n",dp[(1 << n)-1][i]);
	return 0;
}

Measured memory_bytes: 12228
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int A,B,C,D;
    cin>>A>>B>>C>>D;
    if(A+B>C+D){
        cout<<"Left"<<endl;
    }
    else if(A+B<C+D){
        cout<<"Right"<<endl;
    }
    else if(A+B==C+D){
        cout<<"Balanced"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
# include <bits/stdc++.h>
# define int long long
using namespace std;
const int N = 2e5 + 100, MOD = 1e9 + 7;
int p[N] = {1}, ans[N], res = 0;
int bin_pow(int x, int y){
	int ans = 1;
	while(y){
		if(y & 1){
			ans = ans * x % MOD;
		}
		x = x * x % MOD;
		y >>= 1;
	}
	return ans;
}
main(){
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n, k;
	cin >> n >> k;
	for(int i = k; i >= 1; i--){
		for(int j = i; j <= k; j += i){
			ans[i] -= ans[j];
			if(ans[i] < 0)ans[i] += MOD;
		}
		ans[i] += bin_pow(k / i, n);
		if(ans[i] >= MOD)ans[i] -= MOD;
		res = (res + ans[i] * i % MOD) % MOD;
	}
	cout << res << '\n';
}

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

int main() {
  int N = 0;
  std::cin >> N;
  std::string str;
  std::cin >> str;
  std::vector<int> E_num_vec(N, 0);
  std::vector<int> W_num_vec(N, 0);
  int answer = 0;

  if (str[0] == 'W') {
    E_num_vec[0] = 1;
  }
  for (int i = 1; i < str.size(); i++) {
    if (str[i] == 'W') {
      E_num_vec[i] = E_num_vec[i - 1] + 1;
    } else {
      E_num_vec[i] = E_num_vec[i - 1];
    }
  }

  if (str[str.size() - 1] == 'E') {
    W_num_vec[str.size() - 1] = 1;
  }
  for (int i = str.size() - 1; i >= 0; i--) {
    if (str[i] == 'E') {
      W_num_vec[i] = W_num_vec[i + 1] + 1;
    } else {
      W_num_vec[i] = W_num_vec[i + 1];
    }
  }

  int min_num = str.size();
  int num = str.size();

  num = W_num_vec[0];
  if (num < min_num) {
    min_num = num;
  }


  num = E_num_vec[str.size() - 1];
  if (num < min_num) {
    min_num = num;
  }

  num = str.size();
  for (int i = 1; i < str.size() - 1; i++) {
    num = E_num_vec[i - 1] + W_num_vec[i + 1];
    if (num < min_num) {
      min_num = num;
    }
  }
  std::cout << min_num << std::endl;
  return 0;
}

Measured memory_bytes: 3068
#include<bits/stdc++.h>
using namespace std;
#define For(i,n) for(long i=0;i<(n);i++)
long gcd(long a,long b){
    return b?gcd(b,a%b):a;
}
int tentou(int i, vector<int> data){
    int keta=0;
    int tuiteru=0;
    while(i){
        int amari=i%2;
        tuiteru+=amari*data.at(keta);
        keta++;
        i=i/2;
    }
    return tuiteru;
}
long n,m,ans=0;
int main(){
    cin>>n>>m;
    vector<vector<int>> data(m,vector<int>(n));
    For(i,m){
        int k;
        cin>>k;
        For(j,k){
            int s;
            cin>>s;
            data.at(i).at(s-1) ++;
        }
    }
    vector<int> p(m);
    For(i,m){
        cin>>p.at(i);
        //cout<<p.at(i)<<endl;
    }
    For(i,pow(2,n)){
        int t=0;
        For(j,m){
            //cout<<tentou(i,data.at(j))<<" "<<p.at(j)<<endl;
            if(tentou(i,data.at(j))%2==p.at(j)){
                t++;
            }
        }
        if(t==m){
            //cout<<i<<endl;
            ans++;
        }
    }
    
    //For(i,m){
        //For(j,n){
            //cout<<data.at(i).at(j);
        //}
        //cout<<endl;
    //}
    cout<<ans<<endl;
}



Measured memory_bytes: 256
n=int(input())
ans=0
m=0
a=0
b=0
for i in range(n):
    s=input()
    ans+=s.count("AB")
    if s[0]=='B' and s[-1]=="A":
        m+=1
    elif s[0]=="B":
        b+=1
    elif s[-1]=="A":
        a+=1
if m>0:
    ans+=m-1
    if a>0:
        ans+=1
        a-=1
    if b>0:
        ans+=1
        b-=1
ans+=min(a,b)
print(ans)

Measured memory_bytes: 3064
#include <stdio.h>
#include <string.h>

int main() {

    char f[19];
    int cont = 0;

    for (int i = 0; i < 19; i++) {
        scanf("%c", &f[i]);
        if (f[i] == ',') {
            f[i] = ' ';
        }
    }

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

    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define cout16 cout << setprecision(16) 
#define rep(i,n) for(int i=0;i<n;i++ )
#define rep2(i,f,n) for(int i=f;i<n;i++ )
#define SORT(A) sort(A.begin(),A.end())
#define REV(A) reverse(A.begin(),A.end())
typedef long long int ll;
using vi = std::vector<int>;
using vvi = std::vector<std::vector<int>>;
using vll = std::vector<ll>;
using vvll = std::vector<std::vector<ll>>;
using P = std::pair<int,int>;
using vp = std::vector<P>;
using namespace std;
#define INF 1001001001
#define LL_INF 1001001001001001001
#define fi first
#define se second

int main(void) {
	ll h,w; cin >> h >> w;
	ll ans = h*w;
	if(h==1||w==1) cout << 1 << endl;
	else if(ans%2) cout << ans/2+1 << endl;
	else cout << ans/2 << endl;
}




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

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  int divisor = 0;
  for (int i = a; i <= b; i++) {
    if (c % i == 0) {
      divisor++;
    }
  }
  cout << divisor << endl;
  return 0;
}



Measured memory_bytes: 3116
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <utility>
typedef long long ll;
ll MOD = 1e9+7;

using namespace std;

int main()
{
	string s;
	int w;
	string ans;
	
	cin>>s;
	cin>>w;
	for(int i=0;i<s.length();i+=w)
	{
		ans+=s[i];
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <bitset>
#include <tuple>
#include <cmath>
#include <map>

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

using namespace std;

using ll = long long;
using ull = unsigned long long;

using Pll  = pair<ll, ll>;
using Pull = pair<ull, ull>;

#define eb emplace_back
#define pb push_back
#define mp( a, b ) make_pair( a, b )
#define mt( ... ) make_tuple( __VA_ARGS__ )

#define rep( i, n ) for ( int i = 0; i < (int)( n ); ++i )
#define reps( i, n ) for ( int i = 1; i <= (int)( n ); ++i )
#define rrep( i, n ) for ( int i = (int)( ( n ) - 1 ); i >= 0; --i )
#define rreps( i, n ) for ( int i = (int)( ( n ) ); i > 0; --i )

#define ALL( c ) ( c ).begin(), ( c ).end()
#define RALL( c ) ( c ).rbegin(), ( c ).rend()

#define MOD ( 1e9 + 7 )


int main()
{
	int H, W, h, w;
	cin >> H >> W >> h >> w;

	cout << ( H - h ) * ( W - w ) << endl;
	return ( 0 );
}


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


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

int main(){
    long long e,f;
    cin>>e>>f;
    long long c=gcd(e,f);
    
    long long ans=e*f;
    ans/=c;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
def bubbleSort(A,N):
    flag = 1
    swapCount = 0
    while flag == 1 :
        flag = 0
        for j in range(N-1,0,-1):
            #一度逆順の要素があればその存在を仮定する。
            if A[j] < A[j-1] :
                v = A[j]
                A[j] = A[j-1]
                A[j-1] = v
                swapCount += 1
                flag = 1
    str = ""
    for i in range(N):
        str += "{} ".format(A[i])
    print(str[:len(str)-1])
    print(swapCount)


if __name__ == '__main__':
    N = int(input())
    A = [int(_) for _ in input().split()]

    bubbleSort(A,N)



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

typedef long long  LL;
LL n;
int ans;

void work()
{
	scanf("%lld",&n),n++;
	while (n>9)  ans+=9,n/=10;
	ans+=n-1;
	printf("%d",ans);
}

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


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

int main(){
    cin >> n;
    int a[n];
    for(int i=0; i<n; i++){
        cin >> a[i];
    }
    sort(a,a+n);
    int ans = 0;
    for(int i=0; i<n-2; i++){
        for(int j=i+1; j<n-1; j++){
            for(int k=j+1; k<n; k++){
                if(a[i]+a[j]>a[k]&&a[i]!=a[j]&&a[i]!=a[k]&&a[j]!=a[k]){
                    ans++;
                }
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3524
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		Scanner sc = new Scanner(System.in);
		//String line1 = sc.nextLine();
		//int n = Integer.parseInt(line1);
		
		int n = sc.nextInt();

		int[] A = new int[n];
		
		//for (int i = 0; i < n; i++) {
		//	String kari = sc.nextLine();
		//	A[i] = Integer.parseInt(kari);
		//}
		
		for (int i = 0; i < n; i++) {
			A[i] = sc.nextInt();
		}

		int v = 0;
		int k = 0;

		int cnt = 0;
		int m = 1;

		ArrayList<Integer> G = new ArrayList<Integer>();
		while (true) {
			G.add(m);

			m = 2 * (m + 1) - 1;

			if (m > n) {
				break;
			}
		}
		Collections.reverse(G);

		// int pow = n;
		// while (pow > 2) {
		// pow = pow/2;
		// m++;
		// }

		// int[] G = new int[m];
		// for (int i = 0; i < m; i++) {
		// double X = Math.pow((double) 2, (double) m - i - 1);
		// G[i] = (int) X;
		// }

		for (int i = 0; i < G.size(); i++) {
			for (int j = G.get(i); j < n; j++) {
				v = A[j];
				k = j - G.get(i);
				while (k >= 0 && A[k] > v) {
					A[k + G.get(i)] = A[k];
					k = k - G.get(i);
					cnt++;
				}
				A[k + G.get(i)] = v;
			}
		}

		System.out.println(G.size());
		for (int l = 0; l < G.size() - 1; l++) {
			System.out.print(G.get(l));
			System.out.print(" ");
		}
		System.out.println(G.get(G.size() - 1));

		System.out.println(cnt);
		for (int l = 0; l < n; l++) {
			System.out.println(A[l]);
		}

	}
}

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

const int N = 200054;

int n, K;
char s[N], t[N];

inline int get(int i) {return (i < n ? (int)s[i] : (i ^ n)) & 1;}

int main() {
	int i, j, c;
	scanf("%d%d%s", &n, &K, s);
	for (i = 0; i < n && K; ++i) {
		c = 1 + ((i ^ (int)s[i]) & 1);
		if (K >= c) K -= c;
		else break;
	}
	if (i == n && K) c = 1 + (n & 1), i += K / c, K %= c;
	for (j = 0; j < n; ++j) t[j] = get(i + j);
	for (*t ^= K, j = 0; j < n; ++j) t[j] = (i & 1 ? 65 + t[j] : 66 - t[j]);
	return puts(t), 0;
}

Measured memory_bytes: 768
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
''' 
------------------------
author : iiou16
------------------------
'''
import math
def main():
    N = int(input())

    odd = (math.ceil(N / 2))
    print("{0:.10f}".format(odd / N))


if __name__ == '__main__':
    main()

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef pair<int, int> pii;

#define erep(i, x, n) for (auto i = x; i<=(ll)(n); i++)
#define rep(i, x, n) for(auto i = x; i<(ll)(n); i++)
#define all(v) ((v).begin()), ((v).end())
#define sz(v) ((int)((v).size()))
#define mod(n, m) (((n%m) + m)%m)
#define reset(n, m) memset(n, m, sizeof n)
#define endl '\n'

const int N = 1e5 + 5;
int W[N], V[N];
ll memo[2][N];

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

	int n, w;
	cin >> n >> w;

	rep(i, 0, n)
		cin >> W[i] >> V[i];

	// pick solve(idx + 1, w - W[i]) + V[i]
	// leave solve(idx + 1, w)

	for(int i = n - 1; i >= 0; i--)
	{
		int curr = i & 1;
		int nxt = (i & 1) ^ 1;

		for(int j = w; j >= 0; j--)
		{
			memo[curr][j] = memo[nxt][j];

			if (j - W[i] >= 0)
				memo[curr][j] = max(memo[curr][j], memo[nxt][j - W[i]] + V[i]);
		}
	}

	cout << memo[0][w];
	return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define ll          long long int
#define uu          first
#define vv          second
#define pii         pair<int,int>
#define pll         pair<ll,ll>
#define INF         1e9
#define fastRead    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;

const int MAX = 1e6 + 6;
int main()
{
    fastRead;
    int a, b, v, w, t;
    cin>>a>>v>>b>>w>>t;
    
    if(a==b) {
        cout<<"YES\n";
        return 0;
    }
    if(w >= v) {
        cout<<"NO\n";
        return 0;
    }
    int vel = v - w;
    int dist = abs(a-b);
    
    int tm = (dist-1)/vel + 1;
    
    if(tm > t) {
        cout<<"NO\n";
    }
    else cout<<"YES\n";
    return 0;
    
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    string s;
    cin>>s;
    for(int i=0; i<s.size(); i++)
    {
        s[i]+=n;
        if(s[i]>'Z')
            s[i]-=26;
    }
    cout<<s<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

int main(){
  string s;
  cin >> s;
  int N = s.size();

  stack<int> st;
  for(int i=0;i<N;i++){
    if(s[i] == '0') st.push(0);
    if(s[i] == '1') st.push(1);
    if(s[i] == 'B' && !st.empty()) st.pop();
  }

  vector<int> ans;
  int n = st.size();
  for(int i=0;i<n;i++){
    ans.push_back(st.top());
    st.pop();
  }

  reverse(ans.begin() , ans.end());
  for(int i=0;i<ans.size();i++){
    cout << ans[i];
  }

  cout << endl;
  return 0;
}

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

int F(long long a,long long b) {
  long long x = 1;
  for (long long i = 0; i < b; i++) {
    x = x * a;
  }
  return x;
}
int main() {
  long long N;
  cin >> N;
  long long ans = 0;
  if (N % 2 == 0) {
    N = N / 2;
    while (N / 5 != 0) {
      N /= 5;
      ans = ans + N; 
    }
  cout << ans << endl;
  }
  else {
    cout << 0 <<endl;
  }
}

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

using namespace std;

int main() {
	Int N, K;
	cin >> N >> K;
	vector<Int> a(N);
	for (int i = 0; i < N; ++i) { cin >> a[i]; }

	sort(a.begin(), a.end());
	
	Int low = -1e18 - 1, high = 1e18;
	while (high - low > 1) {
		Int mid = (high + low) / 2;

		Int cnt = 0;
		for (int i = 0; i + 1 < N; ++i) {
			if (a[i] >= 0) {
				if (a[i] * a[i + 1] > mid) { continue; }
				int l = i + 1, h = N;
				while (h - l > 1) {
					int m = (h + l) / 2;
					if (a[i] * a[m] > mid) { h = m; }
					else { l = m; }
				}
				cnt += h - i - 1;
			} else {
				if (a[i] * a.back() > mid) { continue; }
				int l = i, h = N - 1;
				while (h - l > 1) {
					int m = (h + l) / 2;
					if (a[i] * a[m] > mid) { l = m; }
					else { h = m; }
				}
				cnt += N - 1 - l;
			}
		}
		if (cnt >= K) { high = mid; }
		else { low = mid; }
	}
	cout << high << endl;

	return 0;
}


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

#define rep(i, a, n)  for(ll i=a; i<n; i++)
#define per(i, a, n)  for(ll i=n-1; i>=a; i--)
#define fill0(n)  setfill('0') << right << setw(n)
#define all(x)  (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define LONGMAX 1e18
#define INTMAX 1000000000

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod = 1e9+7;
const long double EPS = 0.0000000001;

int n;
int main(){
	cin >> n;
	vector<P>v;
	for(int i = 0; i < n; i++){
		int x,l;
		cin >> x >> l;
		v.push_back(P(x+l, x-l));
	}
	sort(all(v));
	int cur = -1e9;
	int ans = 0;
	for(int i = 0; i < n; i++){
		if(cur <= v[i].second){
			ans++;
			cur = v[i].first;
		}
	}
	cout << ans << endl;
}

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

int main() {
    //freopen( "C:\\Users\\ehab\\Desktop\\problems\\in.txt" , "r" , stdin );

    string s , t;
    cin >> s >> t;
    deque<char> a , b;

    for ( int i = 0; i < s.length(); i++ ){
        a.push_back( s[i] );
        b.push_back( t[i] );
    }

    int len = s.length();
    for ( int i = 0; i < len; i++ ){
        if ( a == b ){
            cout << "Yes";
            return 0;
        }
        a.push_front( a.back() );
        a.pop_back();
    }
    cout << "No";
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <cstring>
#include <functional>

using namespace std;

#define REP(i,a,b) for((i)=(a);(i)<(int)(b);(i)++)
#define rep(i,n) REP(i,0,n)
// BEGIN CUT HERE
#define foreach(itr,c) for(typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
// END CUT HERE
const int INF = 1>>29;

int main(){
  int mon, day,st;
  vector<vector<int> > data(13, vector<int>(32, INF));
  string whatday[7] = {"Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"};

  st = 3;
  REP(mon,1,13) REP(day,1,32){
    if(mon == 2 && day == 30) break;
    if(mon == 4 || mon == 6 || mon == 9 || mon == 11) if(day == 31) break;
    data[mon][day] = st;
    st++; if(st == 7) st = 0;
  }

  while(cin >> mon >> day){
    if(day == 0 && mon == 0) break;
    cout << whatday[data[mon][day]] << endl;
  }

  return 0;
}

Measured memory_bytes: 0
MOD=10**9+7
cnt=0; sum=0; prev=nil; can=true; h=Hash.new(0)
def gs() gets.chomp end
def gi() gets.to_i end
def gsmi() gets.chomp.split.map(&:to_i) end

def desc(ar) ar.sort!{|x,y|y<=>x} end
def min(a,b) a<=b ? a : b end
def max(a,b) a>=b ? a : b end
def sum(ar) ar.inject(:+) end

def C(a,b) b==0||a==b ? 1 : (b=a-b if a/2<b;(a-b+1..a).inject(:*)/(1..b).inject(:*)) end

def puts_yesno(can) puts(can ? 'Yes' : 'No') end
def putsend(s) puts s; exit end
def debug(k,v) puts "#{k}:#{v}" end
########### ( ˘ω˘ )ｽﾔｧ… ###########
n,a,b=gsmi
abs=(a-b).abs
if abs%2==0
  putsend abs/2
end

# 1位kaさいかいで1ターン調整
#1,2,3,4,///
max=max(a,b)
min=min(a,b)

edge = min(n-max,min-1)
if n-max >= min-1
  #hidari
  a-=edge
  b-=edge
else
  a+=edge
  b+=edge
end

puts edge+1+((a-b).abs-1)/2

Measured memory_bytes: 1788
n, q = map(int, input().split())

*parent, = range(n)
def root(x):
    if x != parent[x]:
        x = parent[x] = root(parent[x])
    return x

def unite(x, y):
    px = root(x)
    py = root(y)

    if px < py:
        parent[py] = px
    else:
        parent[px] = py

def same(x, y):
    return root(x) == root(y)

for i in range(q):
    com, x, y = map(int, input().split())
    if com == 0:
        unite(x, y)
    else:
        print(int(same(x, y)))

Measured memory_bytes: 8040
#ABC158B
import sys
n,blue,red = map(int, sys.stdin.readline().split())

total = blue + red
syo = n // total
amari = n % total
if n <= blue:
    print(n)
elif n <= total:
    print(blue)
elif amari<=blue:
    print(syo*blue + amari)
elif amari >blue:
    print(syo*blue + blue)

Measured memory_bytes: 3060
def merge(A, left, mid, right):
    global cnt
    L = A[left:mid] + [1000000001]
    R = A[mid:right] + [1000000001]
    i = j = 0
    for k in range(left, right):
        if L[i] <= R[j]:
            A[k] = L[i]
            cnt += j
            i += 1
        else:
            A[k] = R[j]
            j += 1
 
def mergeSort(A, left, right):
    if left + 1 < right:
        mid = (left + right) // 2
        mergeSort(A, left, mid)
        mergeSort(A, mid, right)
        merge(A, left, mid, right)

n = int(input())
A = list(map(int, input().split()))
cnt = 0
mergeSort(A, 0, n)
print(str(cnt))

Measured memory_bytes: 30392
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <climits>
#include <bitset>
using namespace std;

long long solve(int N, int K, vector<int> &A, vector<int> &B, int d){
    long long ret = 0;
    for(int i=0; i<N; i++){
        if(A[i] & (1<<d)) continue;
        bool flag = true;
        for(int j=d+1; j<30; j++)
            if(!(K&(1<<j))&&(A[i]&(1<<j))){
                flag = false;
                break;
            }
        if(flag)
            ret += B[i];
    }
    return ret;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, K;
    cin >> N >> K;
    vector<int> A(N), B(N);
    for(int i=0; i<N; i++) cin >> A[i] >> B[i];

    long long ans = 0;
    for(int i=0; i<30; i++){
        if(K & (1<<i)){
            ans = max(ans, solve(N, K, A, B, i));
        }
    }

    long long tmp = 0;
    for(int i=0; i<N; i++)
        if((K | A[i]) == K) tmp += B[i];

    ans = max(ans, tmp);

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


Measured memory_bytes: 1024
from collections import deque

s = deque(list(input()))
q = int(input())

asc = True
for _ in range(q):
    qs = input()
    if qs[0]=="1":
        asc = not asc
        continue

    _,f,c = qs.split()
    if f=="1":
        if asc:
            s.appendleft(c)
        else:
            s.append(c)
    else:
        if asc:
            s.append(c)
        else:
            s.appendleft(c)

if not asc:
    s.reverse()
print("".join(s))

Measured memory_bytes: 76008