akhauriyash/Code-Regression huggingface dataset:
from collections import deque
def calculate_area(lines):
    q = deque()
    partial_area = 0
    areas = []
    total_area = 0
    for i, line in enumerate(lines):
        if line == "\\":
            q.append(i)
        elif line == "/":
            if q:
                num = q.pop()
                partial_area = i - num
                total_area += partial_area
                for p_area in areas[::-1]:
                    if p_area[0] > num:
                        partial_area += areas.pop()[1]
                    else:
                        break
                areas.append([num, partial_area])
    areas_strigified = [str(v) for i, v in areas]
    print(total_area)
    if total_area:
        print("{} {}".format(len(areas), ' '.join(areas_strigified)))
    else:
        print(0)
                    

if __name__ == "__main__":
    data = input()
    calculate_area(data)


Measured memory_bytes: 6564
import java.util.Scanner;

class Main {

	public static void main(String[] args) {
	    Scanner sc = new Scanner(System.in);
	    while (sc.hasNextLine()){
	    	int m = sc.nextInt();
	    	int f = sc.nextInt();
	    	int r = sc.nextInt();
	    	String result = "F";

	    	if (m == -1 && f == -1 && r == -1)
	    		break;

	    	if (m+f>=30){
	    		result="D";
	    		if (r>=50){
		    		result="C";
		    	}
	    	}

	    	if (m+f>=50){
	    		result="C";
	    	}


	    	if (m+f>=65){
	    		result="B";	    	}

	    	if (m+f>=80){
	    		result="A";
	    	}

	    	if (m==-1||f==-1){
	    		result="F";
	    	}

	    	System.out.println(result);

	    }
	}

}



Measured memory_bytes: 26448
#include<iostream>
#include<algorithm>
#include<vector>
typedef long long lint;
using namespace std;

int main()
{
	int N,M;
	int a,b;
	bool from[200010]={},to[200010]={};
	
	cin >> N >> M;
	for(int i=0;i<M;i++)
	{
		cin >> a >> b;
		if(a==1 && b!=N)from[b]++;
		else if(a!=1 && b==N)to[a]++;
	}
	
	for(int i=2;i<=N-1;i++)
	{
		if(from[i] && to[i])
		{
			cout << "POSSIBLE" << endl;
			return 0;
		}
	}
	cout << "IMPOSSIBLE" << endl;
	return 0;
}


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

using namespace std;
typedef long long int ll;

#define p(V) for(int iiv=0;iiv<V.size();iiv++) cout<<V[iiv]<<" ";
#define mp make_pair
#define pb push_back
#define graph vector<vector<int> >
#define pf first
#define ps second
#define pq priority_queue
const int N = 2e5;
const int l = 18;
const double pi = acos(-1);

int n , dp[N];
vector<int> v;
int main(){   
    cin >> n;
    v.resize(n);
    for(int i=0;i<n;i++) cin >> v[i];
    dp[n-2] = abs(v[n-1]-v[n-2]);
    int def;
    for(int i=n-3;i>=0;i--) dp[i]=min(dp[i+1]+abs(v[i]-v[i+1]),dp[i+2]+abs(v[i]-v[i+2]));
    cout<<dp[0];
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

class UnionFind {
public:
    vl parent;  //親ノード
    vl Siz;  //集合の大きさ

    // コンストラクタ
    UnionFind(ll n): parent(n), Siz(n, 1LL) {
        rep(i, n) {
            parent[i] = i;
        }
    }

    // n要素で初期化
    void init(ll n) {
        parent.resize(n);
        Siz.assign(n, 1);
        rep(i, n) {
            parent[i] = i;
        }
    }

    // xの属する集合の根を求める
    ll root(ll x) {
        if(parent[x] == x) {
            return x;
        }
        else {
            return parent[x] = root(parent[x]);
        }
    }

    // xとyの属する集合を併合
    void unite(ll x, ll y) {

        x = root(x);
        y = root(y);

        if(x == y) {
            return;
        }

        if(Siz[x] < Siz[y]) {
            swap(x, y);
        }

        Siz[x] += Siz[y];
        parent[y] = x;
    }
    
    // xとyが同じ集合に属するかどうか
    bool same(ll x, ll y) {
        return root(x) == root(y);
    }

    // xの属する集合の要素数を求める
    ll size(ll x) {
        return Siz[root(x)];
    }
};

int main() {
    ll n, m;
    cin >> n >> m;

    UnionFind Uni(n);
    Uni.init(n);

    rep(i, m) {
        ll a, b;
        cin >> a >> b;
        a--;  b--;
        Uni.unite(a, b);
    }

    set<ll> st;
    rep(v, n) {
        st.insert(Uni.root(v));
    }

    ll renketuseibun = st.size();  // 連結成分の個数

    out(renketuseibun - 1);
    re0;
}

Measured memory_bytes: 8512
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define rep(i, n) for(int (i)=0;(i)<(n);(i)++)
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
bool custom1 (pair<int, int> a, pair<int, int> b) {
  return (a.first < b.first);
}
bool custom2(pair<int, int> a, pair<int, int> b) {
  return (a.second < b.second);
}

const int MAX = 200005;
const long long MOD = 1000000007;
const long long MODMOD = 998244353;

long long fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

long long gcd(long long a, long long b) {
  if(a % b == 0) return b;
  else return gcd(b, a % b);
}

int main() {
  int n;
  cin >> n;
  vector<vector<int>> input(n, vector<int>(2));
  rep(i, n) {
    cin >> input[i][0] >> input[i][1];
  }
  map<P, int> count;
  rep(i, n) {
    rep(j, n) {
      if(i == j) continue;
      else {
        P p = make_pair(input[i][0] - input[j][0], input[i][1] - input[j][1]);
        count[p]++;
      }
    }
  }
  int MAX = 0;
  for(auto it = count.begin(); it != count.end(); it++) chmax(MAX, it->second);
  cout <<  n - MAX << endl;
}


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

int main() {
  ios::sync_with_stdio(0); cin.tie(0);
  int n;
  cin >> n;
  int a = 0, b = 0, c = 0, ans = 0;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    for (int j = 0; j+1 < s.size(); j++)
      if (s[j] == 'A' && s[j+1] == 'B') ans++;
    if (s[0] == 'B' && s.back() == 'A')
      c++;
    else if (s[0] == 'B') b++;
    else if (s.back() == 'A') a++;
  }
  //cout << a << ' ' << b << ' ' << c << ' ' << ans << endl;
  if (c) ans += c-1, c = 1;
  if (c && a+b) c--, ans++;
  ans += min(a,b);
  cout << ans << endl;
}


Measured memory_bytes: 256
import sys
def input(): return sys.stdin.readline().rstrip()
from operator import itemgetter
def main():
    n=int(input())
    XYH=[tuple(map(int,input().split())) for i in range(n)]
    XYH.sort(key=itemgetter(2),reverse=True)
    for cy in range(101):
        for cx in range(101):
            hc=XYH[0][2]+abs(cx-XYH[0][0])+abs(cy-XYH[0][1])
            for x,y,h in XYH:
                if h!=max(0,hc-abs(x-cx)-abs(y-cy)):
                    break
            else:
                print(cx,cy,hc)
                sys.exit()

if __name__=='__main__':
    main()

Measured memory_bytes: 41328
import java.util.Scanner;

public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);
		int N = cin.nextInt();
		while(N--!=0){
			int ans=0;
			int year = cin.nextInt();
			int month = cin.nextInt();
			int day = cin.nextInt();
			for(int i = year+1; i <= 999; i++){
				if(i%3==0){
					ans += 200;
				}
				else{
					ans += 195;
				}
			}
			for(int i = month+1; i <= 10; i++){
				if(year%3!=0){
					if(i%2==0){
						ans += 19;
					}
					else{
						ans += 20;
					}
				}
				else{
					ans += 20;
				}
			}
			for(int i = day; i <= 20; i++){
				if(i == 20 && year%3!=0 && month%2==0)
					break;
				ans++;
			}
			System.out.println(ans);
		}
	}

}

Measured memory_bytes: 12000
#include <iostream>
#include <queue>
#define INF 10000000
using namespace std;

int mdata[10][10];
int h, w;
int sx, sy, gx, gy;
class State{
public:
  int x, y;
  int sai[3];
  int pe;
};

int bfs();

main(){
  while(1){
    cin >> h >> w;
    if(h==0 && w==0) break;
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
	cin >> mdata[i][j];
      }
    }
    cin >> sy >> sx >> gy >> gx;
    cout << bfs() << endl;
  }
  return 0;
}

int bfs(){
  int dx[4]={0, 1, 0, -1};
  int dy[4]={-1, 0, 1, 0};
  int cost[10][10][6][6][6];
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      for(int k=0;k<6;k++){
	for(int l=0;l<6;l++){
	  for(int o=0;o<6;o++){
	    cost[i][j][k][l][o]=INF;
	  }
	}
      }
    }
  }
  State u, v;
  u.sai[0]=1;
  u.sai[1]=2;
  u.sai[2]=3;
  u.pe=0;
  u.x=sx;
  u.y=sy;
  cost[u.y][u.x][0][1][2]=0;
  queue<State> Q;
  Q.push(u);
  while(!Q.empty()){
    u=Q.front(), Q.pop();
    //printf("%d %d %d %d %d %d\n", u.x, u.y, u.sai[0], u.sai[1], u.sai[2], u.pe);
    if(u.x==gx && u.y==gy) continue;
    /*for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
	cout << cost[i][j] << ' ';
      }
      cout << endl;
      }*/
    for(int i=0;i<4;i++){
      int ty, tx;
      ty=u.y+dy[i];
      tx=u.x+dx[i];
      if(ty>=0 && ty<h){
	if(tx>=0 && tx<w){
	  int tmp;
	  if(i==0){
	    tmp=(7-u.sai[1])*mdata[ty][tx];
	    v.pe=u.pe+tmp;
	    v.sai[0]=u.sai[1];
	    v.sai[1]=7-u.sai[0];
	    v.sai[2]=u.sai[2];
	    if(v.pe<cost[ty][tx][v.sai[0]-1][v.sai[1]-1][v.sai[2]-1]){
	      cost[ty][tx][v.sai[0]-1][v.sai[1]-1][v.sai[2]-1]=v.pe;
	      v.x=tx;
	      v.y=ty;
	      Q.push(v);
	    }
	  }
	  else if(i==1){
	    tmp=u.sai[2]*mdata[ty][tx];
	    v.pe=u.pe+tmp;
	    v.sai[0]=7-u.sai[2];
	    v.sai[1]=u.sai[1];
	    v.sai[2]=u.sai[0];
	    if(v.pe<cost[ty][tx][v.sai[0]-1][v.sai[1]-1][v.sai[2]-1]){
	      cost[ty][tx][v.sai[0]-1][v.sai[1]-1][v.sai[2]-1]=v.pe;
	      v.x=tx;
	      v.y=ty;
	      Q.push(v);
	    }
	  }
	  else if(i==2){
	    tmp=u.sai[1]*mdata[ty][tx];
	    v.pe=u.pe+tmp;
	    v.sai[0]=7-u.sai[1];
	    v.sai[1]=u.sai[0];
	    v.sai[2]=u.sai[2];
	    if(v.pe<cost[ty][tx][v.sai[0]-1][v.sai[1]-1][v.sai[2]-1]){
	      cost[ty][tx][v.sai[0]-1][v.sai[1]-1][v.sai[2]-1]=v.pe;
	      v.x=tx;
	      v.y=ty;
	      Q.push(v);
	    }
	  }
	  else if(i==3){
	    tmp=(7-u.sai[2])*mdata[ty][tx];
	    v.pe=u.pe+tmp;
	    v.sai[0]=u.sai[2];
	    v.sai[1]=u.sai[1];
	    v.sai[2]=7-u.sai[0];
	    if(v.pe<cost[ty][tx][v.sai[0]-1][v.sai[1]-1][v.sai[2]-1]){
	      cost[ty][tx][v.sai[0]-1][v.sai[1]-1][v.sai[2]-1]=v.pe;
	      v.x=tx;
	      v.y=ty;
	      Q.push(v);
	    }
	  }
	}
      }
    }
  }
  int ans=INF;
  for(int i=0;i<6;i++){
    for(int j=0;j<6;j++){
      for(int k=0;k<6;k++){
	if(ans>cost[gy][gx][i][j][k]) ans=cost[gy][gx][i][j][k];
      }
    }
  }
  return ans;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
int main()
{
    /*string N;
    cin >> N;
    int size = N.size();
    vector<char> bubu;
    int answer = 0;
    for(int i = 0;i<size - 1;i++){
        bubu.at(i) = N.at(i);
        answer += (int)bubu.at(i);
    }
    cout << answer;*/
    
    
    int N,answer = 0;
    cin >> N;
    int n = N;
    while(n > 0){
        answer += n % 10;
        n /= 10;
    }
    if(N % answer == 0){
        cout << "Yes";
    }
    else cout << "No";
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<iostream>
#include<vector>
using namespace std;
#define rep(i,l,r) for(int i=(l);i<=(r);++i)
#define rpe(i,r,l) for(int i=(r);i>=(l);--i)
#define rpp(i,x,e,head) for(int i=head[x];~i;i=e[i].next)
#define dyes cerr<<"yes"<<endl
#define dbg(x) cerr<<#x<<"="<<x<<endl
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define pts puts("")
typedef double db;
typedef long long ll;
typedef unsigned long long ull;
inline int read(){
    int f=1,x=0;char ch;
    do{ch=getchar();if(ch=='-')f=-1LL;}while(ch<'0'||ch>'9');
    do{x=x*10+ch-'0';ch=getchar();}while(ch>='0'&&ch<='9');
    return f*x;
}
inline ll readll(){
    ll f=1,x=0;char ch;
    do{ch=getchar();if(ch=='-')f=-1LL;}while(ch<'0'||ch>'9');
    do{x=x*10+ch-'0';ch=getchar();}while(ch>='0'&&ch<='9');
    return f*x;
}
template <class T> inline void chmax(T &a,T b){if(a<b) a=b;}
template <class T> inline void chmin(T &a,T b){if(a>b) a=b;}
inline void swap(int &a,int &b){int c=a;a=b;b=c;}
using namespace std;
#define mst(a,val) memset(a,val,sizeof(a))
#define pii pair<int,int>
#define piii pair<int,pair<int,int> >
#define mp(i,j) make_pair(i,j)
#define fi first
#define sc second
#define inf (0x3f3f3f3f)
#define infl (0x3f3f3f3f3f3f3f3fLL)
#define forvec(i,j) for(vector<int>::iterator i=j.begin();i!=j.end();++i)
#define forvecv(i,j) for(vector<int>::iterator i=--j.end();i>=j.begin();--i)
//=====================head end======================//
const int N=2e5+10;
const int P=998244353;
int n,a[N],b[N],S;
int c[N],d[N];
inline int find(int l,int r){
    return ((int)(upper_bound(d+1,d+n+1,r)-d)-((int)(lower_bound(d+1,d+n+1,l)-d)))&1;
}
int main(){
    n=read();rep(i,1,n) a[i]=read();rep(i,1,n) b[i]=read();
    int ans=0;
    rep(i,0,29){
        S=(1<<i+1)-1;
        rep(j,1,n) c[j]=a[j]&S;
        rep(j,1,n) d[j]=b[j]&S;
//        rep(j,1,n) cerr<<c[j]<<" ";pts;
//        rep(j,1,n) cerr<<d[j]<<" ";pts;
        sort(c+1,c+n+1);sort(d+1,d+n+1);
        int qaq=0;
        int L1=1<<i,R1=(1<<i+1)-1;
        int L2=(1<<i+1)|(1<<i),R2=(1<<i+2)-1;
//        debug("L1=%d R1=%d\n",L1,R1);
//        debug("L2=%d R2=%d\n",L2,R2);
        rep(j,1,n){
            qaq^=find(L1-c[j],R1-c[j]);
            qaq^=find(L2-c[j],R2-c[j]);
        }
        if(qaq) ans|=(1<<i);
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
#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, A, B) for (int I = (A); I < (B); ++I)
#define RI(X) scanf("%d", &(X))
#define RII(X, Y) scanf("%d%d", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define DRI(X) int (X); scanf("%d", &X)
#define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define RS(X) scanf("%s", (X))
#define CASET int ___T, case_n = 1; scanf("%d ", &___T); while (___T-- > 0)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define PII pair<int,int>
#define VI vector<int>
#define VPII vector<pair<int,int> >
#define PLL pair<long long,long long>
#define VPLL vector<pair<long long,long long> >
#define F first
#define S second
typedef long long LL;
using namespace std;
const int MOD = 1e9+7;
const int SIZE = 1e6+10;
char s1[SIZE],s2[SIZE];
int main(){
    RS(s1);
    RS(s2);
    for(int i=0;i<SIZE;i++){
        if(s1[i])putchar(s1[i]);
        if(s2[i])putchar(s2[i]);
    }
    return 0;
}


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

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

    string s;
    cin >> s;

    if (s.size() < 26) {
        for (char c = 'a'; c <= 'z'; c++) {
            if (s.find(c) == -1) {
                cout << s << c << endl;
                return 0;
            }
        }
    } else {
        bool up[25];
        fill(up, up+25, true);
        bool all_up = true;
        for (int i = 0; i < 25; i++) {
            if (s[i] < s[i+1]) {
                up[i] = false;
                all_up = false;
            }
        }

        if (all_up) {
            cout << -1 << endl;
            return 0;
        } else {
            for (int i = 24; i >= 0; i--) {
                if (!up[i]) {
                    for (int j = 25; j > i; j--) {
                        if (s[i] < s[j]) {
                            cout << s.substr(0, i) << s[j] << endl;
                            return 0;
                        }
                    }
                }
            }
        }
    }
}

Measured memory_bytes: 764
# AOJ 0169 Blackjack
# Python3 2018.6.19 bal4u

while True:
	cs = list(map(int, input().split()))
	if cs[0] == 0: break
	sum, ace = 0, 0
	for c in cs:
		if c == 1:
			c = 0
			ace += 1
		elif c >= 10: c = 10
		sum += c
		if sum + ace > 21: break
	if sum+ace > 21: print(0)
	elif ace > 0 and sum+ace <= 11: print(sum+ace+10)
	else: print(sum+ace)


Measured memory_bytes: 5596
#include <bits/stdc++.h>
#include <sys/types.h>
#include <unistd.h>

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

using ll=long long;
using R=long double;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

template<typename T> vector<T> make_vector(size_t sz){
	return vector<T>(sz);
}

template<typename T,typename... Ts> 
auto make_vector(size_t sz, Ts... ts){
	return vector<decltype(make_vector<T>(ts...))>(sz, make_vector<T>(ts...));
}

template<typename T,typename U,typename... V> 
typename enable_if<is_same<T, U>::value!=0>::type 
fill_value(U &u, const V... v){
	u=U(v...);
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_value(U &u, const V... v){
	for(auto &e:u){
		fill_value<T>(e,v...);
	}
}

const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};

const pid_t pid = getpid();
// Problem Specific Parameter:

const int limit = 200010;
vector<int> graph[limit];
int dist[limit];

void dfs(int v,int p,int d){
	dist[v] = d;
	for(auto &v2: graph[v]){
		if(v2 == p) continue;
		dfs(v2, v, d + 1);
	}
}

int main(void){
	int n;
	cin >> n;
	rep(i, n - 1){
		int a, b;
		cin >> a >> b;
		graph[a - 1].push_back(b - 1);
		graph[b - 1].push_back(a - 1);
	}


	dfs(0, -1, 0);
	int root = 0;
	rep(v, n) if(dist[root] < dist[v]) root = v;
	dfs(root, -1, 0);

	int diameter = 0;
	rep(v, n) chmax(diameter, dist[v]);

	if(diameter % 3 != 1){
		puts("First");
	} else {
		puts("Second");
	}

	return 0;
}

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

int main(void){
    int H,W; cin >> H >> W;

    vector<string> A;
    for(int i=0; i<H; i++){                     //.だけのstringは弾く
        string s; cin >> s;
        bool flg=true;
        for(int j=0; j<W; j++){
            if(s[j]!='.') flg=false;
        }
        if(!flg) A.push_back(s);
    }

    vector<string> B(A.size());

    for(int i=0; i<W; i++){              //縦の部分を弾く　
        bool flg=true;
        for(int j=0; j<A.size(); j++){
            if(A[j][i]!='.') flg=false;
        }

        if(!flg){
            for(int j=0; j<A.size(); j++){
                B[j]+=A[j][i];
            }
        }
    }

    for(int i=0; i<B.size(); i++) cout << B[i] << endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
  int n;
  cin >> n;
  
  vector<int> p(n+1);
  for(int i=1;i<=n;i++) cin >> p[i];
  
  int cnt = 0;
  for(int i=1;i<n;i++){
    if(i == p[i]){
      swap(p[i],p[i+1]);
      cnt++;
    }
  }
  if(n == p[n]){ swap(p[n-1],p[n]); cnt++; }
 
  cout << cnt << endl;
}

Measured memory_bytes: 640
S=input()
T=input()
x=len(S)
S_lett=[]
T_lett=[]
for i in range(x):
	if (S[i] in S_lett) and (T[i] in T_lett):
		if S_lett.index(S[i]) != T_lett.index(T[i]):
			print("No")
			break
			
	elif (S[i] in S_lett)==0 and (T[i] in T_lett)==0:
		S_lett.append(S[i])
		T_lett.append(T[i])
	else:
		print("No")
		break
		
else:
	print("Yes")


Measured memory_bytes: 3632
#include<iostream>
using namespace std;
typedef long long ll;
int main(){
  ll n,T,time;
  cin >> n >> T;
  ll t[n];
  time=0;
  for(int i=0;i<n;i++){
    cin >>t[i];
  }
  for(int i=0;i<n-1;i++){
    if(t[i+1]-t[i]>=T){
      time += T;
    }else{
      time += t[i+1]-t[i];
    }
  }
  time += T;
  cout << time << endl;
}


Measured memory_bytes: 1792
#include <stdio.h>

int main() {
    int a;
	int b;
	int c;
	
	scanf("%d", &a);
	scanf("%d", &b);
	scanf("%d", &c);
	
	int ispoor = 0;
	
	if(a == b && b != c) ispoor = 1;
	if(b == c && c != a) ispoor = 1;
	if(c == a && a != b) ispoor = 1;

	if(ispoor){
		puts("Yes");
	}else{
		puts("No");
	}
  return 0;
}

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

using namespace std;

typedef long long lli;
typedef double lld;
typedef vector<lli> vll;
typedef vector<bool> vbl;
typedef vector<double> vdl;
typedef vector<vector<lli>> mat;
typedef vector<vdl> mad;
typedef unordered_map<lli,unordered_map<lli,lli>> graph;
typedef complex<double> cmp;
typedef vector<cmp> vcl;

const lli e5 = 100009;

lli l;
lli n;
lli m;
lli s;
lli bit = 1;
mat g;
mat w;



int main(){
	cin >> l;
	while(bit <= l) bit <<= 1,n++;
	g = mat(n);
	w = mat(n);
	bit = 1;
	for(lli i = n-1;i > 0;i--){
		g[i].push_back(i+1);
		w[i].push_back(bit);
		g[i].push_back(i+1);
		w[i].push_back(0);
		m += 2;
		if((l&bit) != 0){
			l -= bit;
			g[1].push_back(i+1);
			w[1].push_back(l);
			m++;
		}
		bit <<= 1;

	}
	cout << n << " " << m << endl;
	for(lli i = 1;i < n;i++){
		for(lli j = 0;j < g[i].size();j++){
			cout << i << " " << g[i][j] << " " << w[i][j] << endl;
		}
	}



}


Measured memory_bytes: 256
#include<bits/stdc++.h>                                                                                               
using namespace std;
 
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define int long long
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;

signed main(){
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    if(abs(a - c) <= d || (abs(a - b) <= d && abs(b - c) <= d)) cout << "Yes\n";
    else cout << "No\n";
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	@SuppressWarnings("resource")
	public static void main(String args[]) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int m = scanner.nextInt();
		int[] l = new int[n];

		for (int i = 0; i < m; i++) {
			l[scanner.nextInt() - 1]++;
			l[scanner.nextInt() - 1]++;
		}

		for (int i = 0; i < l.length; i++) {
			System.out.println(l[i]);
		}

	}
}

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

// TYPEDEF
// ----------------------------------------
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> Pair;
typedef vector<ll> vll;
typedef vector<vector<ll>> Graph;
typedef vector<string> vs;
typedef vector<pair<ll, ll>> Pll;
typedef queue<ll> qll;

// REPEAT
// ----------------------------------------
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define REPA(i,a) for(ll i=0;i<(ll)(a.size());i++);
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define COUT(a) cout << (a) << endl;
#define ENDL(a) cout << endl;
#define COUTA(i,a) for(ll i=0;i<(ll)(a.size());i++) {cout << (a)[i] << " ";} cout << endl;

// UTIL
// ----------------------------------------
#define pb push_back
#define paired make_pair
#define ALL(a) (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define RSORT(a) sort((a).rbegin(), (a).rend())

// DEBUG
// ----------------------------------------
#ifdef _DEBUG
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
#else
#define debug(x)
#endif

template <typename T>
void debugV(const vector<T> v) {
#ifdef _DEBUG
  rep(i, v.size()) {
    cout << i << ":" << v[i] << " ";
  }
  cout << endl;
#else
  (void)v;
#endif
}

// BIT FLAG
// ----------------------------------------
const unsigned int BIT_FLAG_0 = (1 << 0); // 0000 0000 0000 0001
const unsigned int BIT_FLAG_1 = (1 << 1); // 0000 0000 0000 0010
const unsigned int BIT_FLAG_2 = (1 << 2); // 0000 0000 0000 0100
const unsigned int BIT_FLAG_3 = (1 << 3); // 0000 0000 0000 1000
const unsigned int BIT_FLAG_4 = (1 << 4); // 0000 0000 0001 0000
const unsigned int BIT_FLAG_5 = (1 << 5); // 0000 0000 0010 0000
const unsigned int BIT_FLAG_6 = (1 << 6); // 0000 0000 0100 0000
const unsigned int BIT_FLAG_7 = (1 << 7); // 0000 0000 1000 0000
const unsigned int BIT_FLAG_8 = (1 << 8); // 0000 0001 0000 0000
const unsigned int BIT_FLAG_9 = (1 << 9); // 0000 0010 0000 0000
const unsigned int BIT_FLAG_10 = (1 << 10); // 0000 0100 0000 0000
const unsigned int BIT_FLAG_11 = (1 << 11); // 0000 1000 0000 0000

// CONST
// ----------------------------------------
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr double PI=3.14159265358979323846; // or M_PI
constexpr int MOD = 1000000007;


void Main() {
  ll n;
  cin >> n;

  ld total = 0;

  REP(i, n) {
    ll a_in;
    cin >> a_in;
    total += (ld)1 / a_in;
  }

  COUT(1/total);

}

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

/*

3 2
*/


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

int main(){
  int n;cin>>n;
  bool f=0;
  ll ans=1;
  vector<int> x(n,0);
  
  REP(i,n){
    int tmp;cin>>tmp;
    if(tmp<n) x.at(tmp)++;
    else{
      f=1;
      break;
    }
  }
  
  if(!f){
    for(int i=((n+1)%2);i<n;i+=2){
      if( i&&x.at(i)!=2) f=1;
      if(!i&&x.at(i)!=1) f=1;
    }
  }
  
  if(!f){
    REP(i,(n/2)){
      ans*=2;
      ans%=1000000007;
    }
  }
  
  cout<<(f?0:ans);
}

Measured memory_bytes: 640
N=int(input())
temp=input().split()
A=[int(temp[i]) for i in range(N)]
As=[]
As.append(sum([A[i]*pow(-1, i) for i in range(N)]))
for i in range(1, N):
  As.append(A[i-1]-As[i-1])

x1=As[0]/2
print(int(2*x1), end=' ')

for i in range(1, N):
  print(2*int(As[i]-x1*pow(-1, i)), end=' ')

Measured memory_bytes: 66532
let n = Int(readLine()!)!
var c = 0
for i in 1...n{
  let d = readLine()!.split(separator:" ").map{Int($0)!}
  if d[0] == d[1]{
    c += 1
  }else{
    c = 0
  }
  if c == 3{
    print("Yes")
    break
  }
  if i == n{
    print("No")
  }
}

Measured memory_bytes: 8264
#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <algorithm>

using namespace std;

struct player {
	string s;
	int max;
	int count;
};

int main() {
	struct player p[3];

	cin >> p[0].s;
	cin >> p[1].s;
	cin >> p[2].s;

	for (int i = 0; i < 3; i++) {
		p[i].max = p[i].s.size();
		p[i].count = 0;
	}

	int n = 0;
	char c = 'a';

	while (1) {
		if (p[n].max == p[n].count) {
			c = n + int('A');
			cout << c;
			break;
		}
		
		c = p[n].s[p[n].count];
		p[n].count++;
		n = int(c) - int('a');

	}

	return 0;
}

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

int palindrome(char s[] ){

    int n=strlen(s);

    for(int i=0;i<=n/2;i++){
        if(s[i]!=s[n-i-1])return 0;
    }
    return 1;

}

int main()
{
    char s[100]={} , aux[100]={};
    int  n , q;
    cin.getline(s,100);
    //cout<<s<<endl;
    n=strlen(s);

    strcpy(aux,s);
    aux[n/2]='\0';
    q=n/2+1;
    //cout<<s+q<<endl;
    //cout<<aux<<endl;
    if(palindrome(s+q)==1 && palindrome(aux)==1 && palindrome(s)==1) cout<<"Yes";
    else cout<<"No";


    return 0;
}


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

using namespace std;

int main()
{
    int N,T,S;

    cin >> N >> T >> S;

    vector<int> A(N),B(N);

    for(int i=0; i<N; ++i) {
        cin >> A[i] >> B[i];
    }

    int dp[2][T+1];

    for(int i=0; i<2; ++i) {
        for(int j=0; j<=T; ++j) {
            dp[i][j]=0;
        }
    }

    int idx;

    for(idx=0; idx<N; ++idx) {
        for(int j=0; j<=T; ++j) {
            if(j<B[idx]) dp[(idx+1)%2][j]=dp[idx%2][j];
            else {
                if(j<S) {
                    dp[(idx+1)%2][j]=max(dp[idx%2][j],dp[idx%2][j-B[idx]]+A[idx]);
                } else if(S+B[idx]>j) {
                    if(S-B[idx]>=0) {
                        dp[(idx+1)%2][j]=max(dp[idx%2][j],dp[idx%2][S-B[idx]]+A[idx]);
                    } else {
                        dp[(idx+1)%2][j]=dp[idx%2][j];
                    }
                } else {
                    dp[(idx+1)%2][j]=max(dp[idx%2][j],dp[idx%2][j-B[idx]]+A[idx]);
                }
            }
        }
    }

    cout << dp[idx%2][T] << endl;


    return 0;
}

Measured memory_bytes: 3112
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        List<int[]> list = new ArrayList<>();
        for (int i = 0; i < N; i++) {
            String s = scan.next();
            char[] data = s.toCharArray();
            int[] count = new int[26];
            for(char c : data) {
                count[c-97] += 1;
            }
            list.add(count);
        }
        int[] t = new int[26];
        Arrays.fill(t, 50);
        for (int i = 0; i < N; i++) {
            int[] c = list.get(i);
            for (int j = 0; j < 26; j++) {
                t[j] = Math.min(t[j], c[j]);
            }
        }
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < 26; i++) {
            if (t[i] == 0) {
                continue;
            }
            for(int j = 0; j < t[i]; j++) {
                sb.append((char)(i + 97));
            }
        }
        System.out.println(sb.toString());
    }
}


Measured memory_bytes: 22740
#include <bits/stdc++.h>
using namespace std;
int main() {
    int a,b,k;
    cin >> k;
    cin >> a >> b;
    bool OK = false;
    for (int i=1; i*k <= b; ++i){
        if( a <= k*i && k*i <= b ){
            OK=true;
            break;
        }
    }
    if (OK)
        cout << "OK" << endl;
    else
        cout << "NG" << endl;
}

Measured memory_bytes: 3632
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<tuple>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<deque>
#include<cmath>
#include<stack>
#include<string.h>
#define rep(i,n) for(int i = 0;i<n;i++)
#define _GLIBCXX_DEBUG
using ll = long long; 
using namespace std;
template<class T>inline bool chmax(T& a,T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
template<class T>inline bool chmin(T& a,T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

int main() {
    int r;
    cin >> r;
    cout << 2*3.14159265358979323846*r << endl;
}

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

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

int main() {

    int g[4][4] = {};

    for (int i = 0; i < 4; ++i) {
        for (int j = 0; j < 4; ++j) {
            if (i != j) {
                g[i][j] = INF;
            }
        }
    }

    for (int i = 0; i < 3; ++i) {
        int a, b; cin >> a >> b;

        --a; --b;

        g[a][b] = 1;
        g[b][a] = 1;
    }

    for (int k = 0; k < 4; ++k) {
        for (int i = 0; i < 4; ++i) {
            for (int j = 0; j < 4; ++j) {
                g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
            }
        }
    }

    for (int i = 0; i < 4; ++i) {
        for (int j = 0; j < 4; ++j) {
            if (g[i][j] == 3) {
                puts("YES");
                return 0;
            }
        }
    }

    puts("NO");
}

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

const int MOD = 1000000007;
const ll INF = numeric_limits<ll>::max();
const int inf = 1e8;



//少数点表示
//cout <<std::fixed << std::setprecision(14)

int main(){
    cin.tie( 0 ); ios::sync_with_stdio( false );
    int k,x;
    cin >> k >> x;
    if(500*k>=x){
        cout << "Yes";
    }else{
        cout << "No";
    }


}

Measured memory_bytes: 256
def dist(p, q)
  Math.sqrt((0..2).reduce(0){ |s, i| s + (p[i] - q[i]) ** 2 })
end
 
gets.to_i.times do
  real = gets.split.map(&:to_f)
  m = gets.to_i
  ps = m.times.map{ gets.split.map(&:to_f) }
  tbl = ps.map{ |p| ps.map{ |q| dist(p, q) } }
  (0...m).to_a.combination(3) do |i, j, k|
    imag = [tbl[j][k], tbl[k][i], tbl[i][j]]
    if imag.sort.zip(real.sort).map{ |i, r| i / r }.combination(2).map{ |x, y| x / y }.all?{ |v| (1 - v).abs < 0.001 }
      (0..2).to_a.permutation(3) do |idx|
        if idx.map{ |i| imag[i] }.zip(real).map{ |i, r| i / r }.combination(2).map{ |x, y| x / y }.all?{ |v| (1 - v).abs < 0.001 }
          p = [i + 1, j + 1, k + 1]
          puts idx.map{ |i| p[i]}.join(' ')
          break
        end
      end
    end
  end
end

Measured memory_bytes: 8864
/* Nurgazy Zhandos */

#include <bits/stdc++.h>

#define F first
#define S second

#define pf push_front
#define pb push_back
#define mp make_pair
#define pp pop_back
#define in insert

#define up upper_bound
#define lb lower_bound

#define resize(v) v.resize(unique(all(v)) - v.begin()); 
#define all(a) a.begin(), a.end()
#define sz(a) a.size()

#define nl '\n'

#define int long long
                                                     
using namespace std;

typedef pair < pair <int, int >, int > piii;
typedef pair < long long, long long > pll;
typedef unsigned long long ull;
typedef pair < int, int > pii;
typedef long double ld;
typedef long long ll;

const int MAX_N = 1e5 + 123;
const int inf = 1e9 + 123;
const ll INF = 1e18 + 123;
const int NN = 2e6 + 123;
const double eps = 1e-9;
const int mod = 1e9 + 7;
const int N = 1e6 + 123;

inline int mult(int a, int b) {
	return 1ll * a * b % mod;
}

inline void fre() {
	#ifdef TEZZY
//	freopen("input.txt", "r", stdin);
// 	freopen("output.txt", "w", stdout);
	#endif
}

inline void boost() {
	ios_base :: sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
}

int a[MAX_N];

main () {
	fre();
	boost();

	int n, x, y;
	cin >> n >> x >> y;

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

	for(int i = 2; i <= n; i++) {
		if((a[i] - a[i - 1]) * x <= y) ans += (a[i] - a[i - 1]) * x;
		else ans += y;
	}
	
	cout << ans;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <functional>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <iomanip>
#if __cplusplus >= 201103L
#include <unordered_map>
#include <unordered_set>
#endif
#define ls x<<1
#define rs x<<1|1
#define fi first
#define se second
#define ll long long
#define pb push_back
#define mp make_pair
#define fun function
#define vi vector<int>
#define lowbit(x) x&(-x)
#define pii pair<int,int>
#define all(x) x.begin(),x.end()
#define mem(a,b) memset(a,b,sizeof(a))
#define IOS ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0);

using namespace std;

const int INF = 0x3f3f3f3f;
const int p=1e9+7;


ll qpow(ll a,ll b) {
	ll ans=1;
	while(b) {
		if(b&1)ans=(ll)ans*a%p;
		a=(ll)a*a%p;
		b>>=1;
	}
	return ans%p;
}

ll Com(ll n,ll m) {
	ll ans=1;
	for(ll i=1; i<=m; i++) {
		ans=ans*(n-m+i)%p;
		ans=ans*qpow(i,p-2)%p;
	}

	return ans;
}


int main() {
	
#ifdef xiaofan
	freopen("1.in","r",stdin);
	freopen("1.out","w",stdout);
#endif

	ll n,x,y;
	cin>>n>>x>>y;
	ll ans=qpow(2,n);
	ll a=Com(n,x);
	ll b=Com(n,y);
	ans=(ans-a+p)%p;
	ans=(ans-b+p-1)%p;
	cout<<ans<<endl;



	return 0;
}


Measured memory_bytes: 888
import scala.collection.mutable.ListBuffer

/**
 * Created by rasrivastava on 10/17/16.
 */
class Barricade(val classStartBegin : Int, val classStartEnd : Int) {
  def getAvoidClasses(classes : List[Int]) : Int = {
    var noClasses = 0
    val range = Range(classStartBegin,classStartEnd)
    //println(range)
    classes.foreach(classPeriod => {
      if (range.contains(classPeriod)) {
        noClasses += 1
      }
    })

    noClasses
  }
}

object Main extends App {
  val line = readLine()
  val lineArr = line.split(" ")
  val n = lineArr(0).toInt
  val a = lineArr(1).toInt
  val b = lineArr(2).toInt
  val barricade = new Barricade(a,b)
  val lstBuffer = new ListBuffer[Int]
  for (i <- 0 to n-1) {
    lstBuffer.+=(readLine().toInt)
  }

  val lst = lstBuffer.toList
  println(lst.size - barricade.getAvoidClasses(lst))
}


Measured memory_bytes: 21452
#include <iostream>
#include <vector>
#include <functional>
#include <algorithm>
#include <cmath>
#include <string>
#include <list>

using namespace std;

typedef long long ll;

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

    vector<ll> a(n, 0);
    list<ll> lst;
    for(int i = 0; i < n; i++) {
        cin >> a[i];
        if(i % 2 == 0) lst.push_back(a[i]);
        else lst.push_front(a[i]);
    }

    if(n % 2 != 0) {
        for(auto itr = --lst.end(); itr != lst.end(); itr--) {
            cout << *itr << " " ;
        }
    } else {
        for(auto itr = lst.begin(); itr != lst.end(); itr++) {
            cout << *itr << " " ;
        }
    }
}

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

bool is_prime(int n){
  if(n<=1)
    return false;

  for(int i=2; i*i<=n; i++){
    if(n%i==0){
      return false;
    }
  }

  return true;
}


int main(){
  while(true){
    int next=0;
    int prev=0;

    int n;
    cin >> n;

    if(cin.eof())
      break;

    for(int i=n+1; i<=50023; i++){
      if(is_prime(i)){
        next=i;
        break;
      }
    }
    for(int i=n-1; i>=2; i--){
      if(is_prime(i)){
        prev=i;
        break;
      }
    }

    cout << prev << ' ' << next <<endl;
  }

  return 0;
}



Measured memory_bytes: 2972
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;

struct item {
  int weight;
  ll value;
};

int main() {
  int n, W;
  cin >> n >> W;
  
  item items[n+1];
  ll dp[n+1][W+1];
  memset(dp, 0, sizeof(dp));
  for(int i = 1; i <= n; i++) cin >> items[i].weight >> items[i].value;
  
  for(int i = 1; i <= n; i++) {
    int weight = items[i].weight;
    ll value  = items[i].value;
    for(int j = 1; j <= W; j++) {
      ll maxValue = j >= weight ? max(dp[i-1][j], dp[i-1][j-weight] + value) : dp[i-1][j];
      dp[i][j] = max(dp[i][j], maxValue);
    }
  }
  
  cout << dp[n][W];
  return 0;
}

Measured memory_bytes: 79104
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define traverse(container,it)  for(auto it = container.begin();it != container.end(); it++)
bool comp(pair< int,int > a,pair< int,int > b){
    return a.first > b.first;
}
int main()
{
    //freopen("in.txt","r",stdin);
    int n,m,l;
    ll sum  = 0;
    cin >> n >> m;
    vector< pair< int,int > > number;
    for(int i=0;i<n;i++){
        int x;
        cin >> x;
        number.push_back(make_pair(x,1));
    }
    for(int i=0;i<m;i++){
        int a,b;
        cin >> a >> b;
        number.push_back(make_pair(b,a));
    }
    sort(number.begin(),number.end(),comp);
    l=n;
    for(auto it = number.begin(); it != number.begin()+n; it++){
        if((it->second)<l){
            sum += (ll)((ll)(it->first)*(ll)(it->second));
            l -= it->second;
        }
        else{
            sum += (ll)(it->first)*l;
            break;
        }
    }

    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 2420
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#define   mod  998244353
#define   int  long long 
#define   ld   long double
#define   pb   push_back
#define   vi  vector<int> 
#define   dbg(x)  cerr << #x << " = " << x << '\n'
#define   sz(x)  (int)x.size()
#define   all(a) (a.begin(),a.end())
#define   ff   first
#define   ss   second
#define   pii  pair<int,int> 
#define   lcm(a,b) (a*b)/__gcd(a,b) 
using namespace std;

inline void solve(){
    map <int,int> m;
    int n,ans=0; 
    cin>>n; 
    vi a(n);
    for (int i=0;i<n;i++) {
        cin >> a[i] ; 
        m[a[i]]++;
    }
    for (auto it: m) ans += (it.ss*(it.ss-1))/2 ; 
    for (int i=0;i<n;i++){
        int h=m[a[i]];
        cout << (ans-h+1) << endl; 
    }
}

signed main()
{
    int n=1; // cin>>n;
    while (n--) solve();
    return 0;
}


Measured memory_bytes: 12736
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(ll i = 0; i < n; i++)
#define rep2(i,start,end) for(ll i = start; i < end; i++)
#define dwn(i,n) for(int i = n; i >= 0; i--)
#define dwn2(i,start,end) for(ll i = start; i >= end; i--)
#define pll pair<ll,ll>
#define mk(x,y) make_pair(x,y)
#define pdl pair<double, ll>
const ll N = 4e5 + 200;
const ll INF = 0x3f3f3f3f;
const ll mod = 1e9 + 7;


int main(){
	ll n,m;
	cin>>n>>m;
	ll sum = 0;
	rep(i,m){
		ll x;
		cin>>x;
		sum += x;
	}
	if(n-sum < 0){
		cout<<"-1"<<endl;
	}else
	cout<<n-sum<<endl;



	return 0;
}






Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)  
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define RVSORT(v) sort(v.rbegin(), v.rend());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

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

ll modpow(ll n,ll k){
  if(k == 1){
    return n;
  }else if(k == 0){
    return 1;
  }else if(k%2==0){
    ll memo = modpow(n,k/2)%MOD;
    return memo*memo%MOD;
  }else{
    return n * modpow(n,k-1)%MOD;
  }
}

int main(){

  int n,d;cin>>n>>d;

  d = d*2+1;
  cout<<(n-1)/d+1;

 

  return 0;
}

Measured memory_bytes: 256
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream> 
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>  
using namespace std;
#define eps 0.00000001
#define LONG_INF 10000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define REP(i,n) for(long long i = 0;i < n;++i)
int main() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	int ans = 0;
	for (int i = 0;i <= 300;++i) {
		if ((i >= a&&i < b) && (i >= c&&i < d)) {
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
 
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define speedhack() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define form(i, n) for (size_t i = 0; i < size_t(n); ++i)
#define forn(i, n) for (size_t i = 1; i <= size_t(n); ++i)
template<class T> using ordered_set=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
long long mod(long long a, long long b) { return (a%b+b)%b; }
long long gcd(long long x, long long y) { return __gcd(x, y); }
long long lcm(long long x, long long y) { return x * 1ll * y / gcd(x, y); }
 
 
const long long MAXN = 1e9 + 9;
const long long SIZE = 2e5 + 5;
const long long MOD = 1e9 + 7;




int main() { speedhack()

	int K; cin >> K;
	int lim = K;

	if (K % 7 == 0) K /= 7;
	
	int v = 1 % K;
	int res = 1;

	while (v && res <= lim) {
		v = (10 * v + 1) % K;
		++res;
	}

	if (res <= lim)
		cout << res << endl;
	else 
		cout << -1 << endl;

	return 0;
}


Measured memory_bytes: 3620
#include<stdio.h>
#define SIZE 200
int main()
{
  char data[SIZE];
  int sort[SIZE],x[SIZE];
  int i,j,h,m,length;
  int end=0;
  while(1)
    {
      for(i=0;i<SIZE;i++)
	{
	  scanf("%c",&data[i]);
	  if(data[i]=='\n')
	    {
	      if(i==0) i--;
	      else break;
	    }
	}

      length=i; 
      if((i==1)&&(data[0]=='-')) break;

      for(i=0;i<length;i++) sort[i]=i;
      scanf("%d",&m);
      for(i=0;i<m;i++)
	{
	  scanf("%d",&h);
	  for(j=0;j<h;j++) x[j]=sort[j];
	  for(j=h;j<length;j++) sort[j-h]=sort[j];
	  for(j=0;j<h;j++) sort[length-h+j]=x[j];
	}
      for(i=0;i<length;i++) printf("%c",data[sort[i]]);
      printf("\n");
    }
  return 0;
}

Measured memory_bytes: 568
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
using namespace std;

bool Pre[5002][5002],Suf[5002][5002],Ans[5002];
int Data[5005];
int N,K;

template<typename elemType>
inline void Read(elemType &T){
    elemType X=0,w=0; char ch=0;
    while(!isdigit(ch)) {w|=ch=='-';ch=getchar();}
    while(isdigit(ch)) X=(X<<3)+(X<<1)+(ch^48),ch=getchar();
    T=(w?-X:X);
}

int main(){
    Read(N);Read(K);
    for(register int i=1;i<=N;++i)
        Read(Data[i]);
    sort(Data+1,Data+N+1);
    Pre[0][0]=Suf[N+1][0]=true;
    for(register int i=1;i<=N;++i){
        for(register int j=0;j<K;++j){
            Pre[i][j]=Pre[i-1][j];
            Suf[N-i+1][j]=Suf[N-i+2][j];
        }
        for(register int j=0;j<K;++j){
            if(Suf[N-i+2][j] && j+Data[N-i+1]<K) Suf[N-i+1][j+Data[N-i+1]]=true;
            if(Pre[i-1][j] && j+Data[i]<K) Pre[i][j+Data[i]]=true;
        }
    }
    for(register int i=1;i<=N;++i){
        if(Data[i]>=K){Ans[i]=true;continue;}
        int p1=K-1,p2=0;
        bool flag=false;
        while(p1>=0 && p2<K){
            if(!Pre[i-1][p1]){--p1;continue;}
            while(p1+p2<K){
                if(Pre[i-1][p1] && Suf[i+1][p2] && p1+p2+Data[i]>=K){
                    Ans[i]=true;
                    flag=true;
                    break;
                }
                ++p2;
            }
            if(flag) break;
            --p1;
        }
    }
    int Count=0;
    for(register int i=1;i<=N;++i)
        if(!Ans[i]) ++Count;
    printf("%d\n",Count);

    return 0;
}

Measured memory_bytes: 49152
fun main(args:Array<String>?): Unit {
    readLine()!!.trim().toInt()
    val cell = Array(2019){false}
    val porn = readLine()!!.trim().split(' ').map{it.toInt() - 1}.toMutableList()
    porn.forEach { x -> cell[x] = true }
    readLine()!!.trim().toInt()
    for (a in readLine()!!.trim().split(' ').map{it.toInt() - 1}) if (porn[a] != 2018 && !cell[porn[a] + 1]){
        cell[porn[a]] = false
        cell[++porn[a]] = true
    }
    println(
            porn.joinToString("\n"){(it + 1).toString()}
    )
}


Measured memory_bytes: 34476