akhauriyash/Code-Regression huggingface dataset:
/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
*/
#include<bits/stdc++.h>
using namespace std;
int n,q,x,y;
int head[200005],sum[200005],tot;
struct node
{
	int nxt,to;
}tree[400005];
void add(int x,int y)
{
	tree[++tot].nxt=head[x],tree[tot].to=y,head[x]=tot;
	tree[++tot].nxt=head[y],tree[tot].to=x,head[y]=tot;
}
void dfs(int pos,int father)
{
	for(int i=head[pos];i!=-1;i=tree[i].nxt)
	{
		int e=tree[i].to;
		if(e!=father)sum[e]+=sum[pos],dfs(e,pos);
	}
}
int main()
{
	memset(head,-1,sizeof(head));
	cin>>n>>q;
	for(int i=0;i<n-1;i++)
	{
		cin>>x>>y;
		add(x,y);
	}
	while(q--)
	{
		cin>>x>>y;
		sum[x]+=y;
	}
	dfs(1,0);
	for(int i=1;i<=n;i++)cout<<sum[i]<<" ";
}

Measured memory_bytes: 16512
#include <stdio.h>
#include <stdlib.h>

int H, W;
int A[32][32];

int main(void) {
	int i, j, k, l;
	int answer = -1;
	if (scanf("%d%d", &H, &W) != 2) return 1;
	for (i = 0; i < H; i++) {
		for (j = 0; j < W; j++) {
			if (scanf("%d", &A[i][j]) != 1) return 1;
		}
	}
	for (i = 0; i < H; i++) {
		for (j = 0; j < W; j++) {
			int score = 0;
			for (k = 0; k < H; k++) {
				for (l = 0; l < W; l++) {
					int asumi = abs(i - k);
					int iguti = abs(j - l);
					int ogurayui = asumi <= iguti ? asumi : iguti;
					score += ogurayui * A[k][l];
				}
			}
			if (answer < 0 || score < answer) answer = score;
		}
	}
	printf("%d\n", answer);
	return 0;
}



Measured memory_bytes: 2128
import sys

N = int(sys.stdin.readline())

button = sys.stdin.readlines()
button = [int(j.replace('\n','')) for j in button]


b = button[0]
counter = 0
for i in range(len(button)):
    if b == 2:
        print(counter+1)
        exit()
    else:
        b = button[b-1]
        counter = counter+1

print(-1)


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

int main() {
  int n, cnt = 0;
  cin >> n;
  vector<int> a(n);
  rep(i, n) {
    cin >> a.at(i);
  }
  for(int i = 1; i < n - 1; i++) {
    if(a.at(i-1) < a.at(i) && a.at(i) < a.at(i + 1)) cnt++;
    else if(a.at(i-1) > a.at(i) && a.at(i) > a.at(i + 1)) cnt++;
  }
  cout << cnt << endl;
}


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

#define int long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define dbgB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

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

template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

// ------------------------------------------------------------------------------------------

int N, K;
int a[1111];
vec<int> cand;

int countMask(int mask) {
   int ret = 0;

   rep (i, cand.size()) {
      if ((cand[i] & mask) == mask) {
         ret++;
      }
   }

   return ret;
}

signed main() {
   cin >> N >> K;
   rep (i, N) {
      cin >> a[i];
   }

   rep (i, N) {
      int sum = 0;
      repp (j, i, N) {
         sum += a[j];
         cand.push_back(sum);
      }
   }

   int mask = 0;
   for (int i = 40; i >= 0; i--) {
      if (countMask(mask | (1LL << i)) >= K) {
         mask |= (1LL << i);
      }
   }

   cout << mask << endl;

   return 0;
}

Measured memory_bytes: 6512
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<utility>
#include<algorithm>
#include<cstdio>
#include<iomanip>
#include<queue>
#include<stack>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)

using namespace std;

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

    string s;
    cin >> s;
    bool flag1, flag2;
    if (s.size() % 2 == 0) {
        flag1 = true;
    } else {
        flag1 = false;
    }

    if (s[0] == s[s.size()-1]) {
        flag2 = true;
    } else {
        flag2 = false;
    }

    if (flag1 ^ flag2) {
        cout << "Second\n";
    } else {
        cout << "First\n";
    }
}

Measured memory_bytes: 512
import sys
input = sys.stdin.readline
from collections import deque
def main():
    S = input().strip()
    Q = int( input())
    Query = [ input().strip() for _ in range(Q)]
    now = 0
    ANS = deque(['1'])
    t = 0
    for q in Query:
        if q == '1':
            if now == 0:
                now = 1
            else:
                now = 0
            continue
        t += 1
        _, f, c = q.split()
        if f == '1':
            if now == 0:
                ANS.appendleft(c)
            else:
                ANS.append(c)
        else:
            if now == 0:
                ANS.append(c)
            else:
                ANS.appendleft(c)
    for i in range(t+1):
        if ANS[i] == '1':
            if now == 0:
                ANS[i] = S
            else:
                ANS[i] = S[::-1]
    if now == 1:
        ANS.reverse()
    print("".join(ANS))
    
if __name__ == '__main__':
    main()

Measured memory_bytes: 19548
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int A = sc.nextInt();
        int B = sc.nextInt();
        long[][] nCr = new long[N+1][N+1];
        nCr[0][0]=0;
        for(int row=1;row<=N;row++){
            nCr[row][0] = 1;
            for(int col=1;col<=row-1;col++){
                nCr[row][col] = nCr[row-1][col-1]+nCr[row-1][col];
            }
            nCr[row][row]=1;
        }
        long[] v = new long[N];
        for(int i=0;i<N;i++){
            v[i] = sc.nextLong();
        }
        Arrays.sort(v);
        long sum1 = 0;
        for(int i=N-1;i>=N-A;i--){
            sum1 += v[i];
        }
        double ans1 = sum1/((double)A);
        int cnt1 = 0;
        int cnt2 = 0;
        for(int i=N-1;i>=0;i--){
            if(v[i]>v[N-A]) cnt1++;
            if(v[i]==v[N-A]) cnt2++;
        }
        long ans2 = 0;
        if(v[N-A]<v[N-1]){
            ans2 = nCr[cnt2][A-cnt1];
        }
        else{
            for(int i=A;i<=Math.min(B,cnt2);i++){
                ans2 += nCr[cnt2][i];
            }
        }
        System.out.println(ans1);
        System.out.println(ans2);
    }
}


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

#pragma warning(disable:4996)
using namespace std;
using ld = long double;

bool check(string l, string r) {
	for (int i = 0; i < l.size(); ++i) {
		if (l[i] == r[i] || r[i] == '_') {

		}
		else {
			return false;
		}
	}
	return true;
}

int main() {
	int H,W;cin>>H>>W;
	vector<vector<int>>field(H,vector<int>(W));
	vector<vector<int>>blacks(H,vector<int>(W));
	for (int i = 0; i < H; ++i) {
		for (int j = 0; j < W; ++j) {
			cin>>field[i][j];
		}
	}
	for (int i = 0; i < H; ++i) {
		for (int j = 0; j < W; ++j) {
			cin >> blacks[i][j];
		}
	}
	int A,B;cin>>A>>B;
	vector<vector<int>>patterns(A,vector<int>(B));
	for (int i = 0; i < A; ++i) {
		for (int j = 0; j < B; ++j) {
			cin>>patterns[i][j];
		}
	}
	int ans=-1e9;
	for (int l = 0; l < W - B + 1; ++l) {
		for (int u = 0; u < H - A + 1; ++u) {
			bool ok=true;
			int sum=0;
			for (int x = l; x < l + B; ++x) {
				for (int y = u; y < u + A; ++y) {
					if(blacks[y][x]!=patterns[y-u][x-l])ok=false;
					sum+=field[y][x];
				}
			}
			if (ok) {
				ans=max(ans,sum);
			}
		}
	}
	if (ans > -1e9) {
		cout << ans << endl;
	}
	else {
		cout<<"NA"<<endl;
	}
	
	return 0;
}


Measured memory_bytes: 3168
#include <stdio.h>
#include <algorithm>

using namespace std;

int main(){
   int H,W;
   while(true){
       scanf("%d %d",&H,&W);
       if(H == 0 && W == 0) break;
       for(int i = 0; i < H; i++){
           for(int j = 0; j < W; j++){
               if((i+j)%2 == 0) printf("#");
               else{
                   printf(".");
               }
           }
           printf("\n");
       }
       printf("\n");
   }
}


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

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define endl "\n"
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

int n;
vector<ll> a;
// dp[l][r] := [l, r]をまとめるのにかかるコストのmin
vector<vector<ll>> dp(500, vector<ll>(500, LLINF));

ll sum(int l, int r) { return (l == 0 ? a[r] : a[r] - a[l - 1]); }

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    a.resize(n);
    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for(int i = 1; i < n; i++) {
        a[i] += a[i - 1];
    }
    // 初期化。[i, i]は当然0
    for(int i = 0; i < n; i++) {
        dp[i][i] = 0;
    }
    for(int l = n - 1; l >= 0; l--) {
        for(int r = l + 1; r < n; r++) {
            for(int k = l; k < r; k++) {
                // [l, k]のコスト：dp[l][k]
                // [k+1, r]のコスト：dp[k+1][r]
                // この2つをマージするコスト：sum(l, r)
                // これらを足し合わせて、更新
                chmin(dp[l][r], dp[l][k] + dp[k + 1][r] + sum(l, r));
            }
        }
    }
    cout << dp[0][n - 1] << endl;
}

Measured memory_bytes: 2304
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <cstring>
#include <set>
#include <map>
#include <stack>
#include <queue>
using namespace std;

#define fast ios::sync_with_stdio(false);cin.tie(0); cout.tie(0);
#define sz(s) (int)s.size()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i,n) for(int i=0;i<(int)n;i++)
#define for1(i,n) for(int i=1;i<=(int)n;i++)

typedef long long ll;
const int N = (int)1e6+7;

int main(){
    fast;
    int n,a[N],ans=0;
    cin>>n;
    forn(i,n) cin>>a[i];
    
    int x=-1;
    for(int i=0;i<n-1;i++){
        if(a[i]==a[i+1]) continue;
        
        if(x==-1){
            if(a[i+1]>a[i]) x=0;
            else x=1;
            continue;
        }
        
        if(x==0 and a[i+1]>a[i]) continue;
        if(x==1 and a[i+1]<a[i]) continue;
        
        if(a[i+1]>a[i]){
            if(x==1){
                ans++;
            }
            i++;
            if(a[i+1]>a[i])
                x=0;
            else if(a[i+1]<a[i])
                x=1;
            else x=-1;
        }else{
            if(x==0){
                ans++;
            }
            i++;
            if(a[i+1]>a[i])
                x=0;
            else if(a[i+1]<a[i])
                x=1;
            else x=-1;
        }
        //cout<<i<<" "<<ans<<endl;
    }
    ans++;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
const int inf = 1e9 + 7;
const ll INF = 1e18;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<typename T> T pow(T a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
const int mod = 1000000007;
ll modpow(ll a, int b) { return b ? modpow(a * a % mod, b / 2) * (b % 2 ? a : 1) % mod : 1; }
template<class T> ostream& operator<<(ostream& os, const vector<T>& vec) { rep(i, sz(vec)) { if (i) os << " "; os << vec[i]; } return os; }
template<class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<class T> inline void add(T &a, int b) { a += b; if (a >= mod) a -= mod; }



void solve();

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

  int T;
  // cin >> T;
  T = 1;

  while (T--) {
      solve();
  }
}


void solve() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  vector<int> b = a;
  sort(all(b));
  rep(i, n) {
    if (a[i] == b[n - 1]) cout << b[n - 2] << endl;
    else cout << b[n - 1] << endl;
  }
}


Measured memory_bytes: 3200
x, y = map(int, input().split())

#turu = t
#kame = x - t
turu = 0
kame = 0
flag = 0
for t in range(0, x + 1):
    if t * 2 + (x - t) * 4 == y:
        turu = t
        kame = x - t
        flag = 1

    else:
        pass

if flag == 1:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9180
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin >> s;
    bool ans = true;
    if(s.size() % 2 == 1){
        ans = false;
    }
    for(int i = 0; i < s.size(); i++){
        if(i % 2 == 0){
            if(s[i] != 'h'){
                ans = false;
            }
        }
        else if(i % 2 == 1){
            if(s[i] != 'i'){
                ans = false;
            }
        }
    }
    if(ans){
        cout << "Yes" << endl; 
    }
    else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"unicode"
)

func getAcronym(ls ...string) (acronym string) {
	acronym = ""
	for i := 0; i < len(ls); i++ {
		for j, r := range ls[i] {
			if j == 0 {
				acronym += string(unicode.ToUpper(r))
				break
			}
		}
	}
	return
}

func main() {
	var a, b, c string
	fmt.Scan(&a, &b, &c)
	fmt.Println(getAcronym(a, b, c))
}


Measured memory_bytes: 640
#include <cstdio>
#include <cstdlib>
#include <cstring>

struct Node
{
  int key;
  Node *next, *prev;
};

Node *nil;

Node *listSearch(int key)
{
  Node *cur = nil->next;
  while (cur != nil && cur->key != key)
  {
    cur = cur->next;
  }
  return cur;
}

void init()
{
  nil = (Node *)malloc(sizeof(Node));
  nil->next = nil;
  nil->prev = nil;
}

void printList()
{
  Node *cur = nil->next;
  int isFirst = 0;
  while (true)
  {
    if (cur == nil)
      break;
    if (isFirst++ > 0)
      printf(" ");
    printf("%d", cur->key);
    cur = cur->next;
  }
  printf("\n");
}

void deleteNode(Node *t)
{
  if (t == nil)
    return;
  t->prev->next = t->next;
  t->next->prev = t->prev;
  free(t);
}

void deleteFirst()
{
  deleteNode(nil->next);
}

void deleteLast()
{
  deleteNode(nil->prev);
}

void deleteKey(int key)
{
  deleteNode(listSearch(key));
}

void insert(int key)
{
  Node *x = (Node *)malloc(sizeof(Node));
  x->key = key;
  x->next = nil->next;
  nil->next->prev = x;
  nil->next = x;
  x->prev = nil;
}

int main()
{
  int key, n, i;
  int size = 0;
  char com[20];
  int np = 0, nd = 0;
  scanf("%d", &n);
  init();
  for (i = 0; i < n; i++)
  {
    scanf("%s%d", com, &key);
    if (com[0] == 'i')
    {
      insert(key);
      np++;
      size++;
    }
    else if (com[0] == 'd')
    {
      if (strlen(com) > 6)
      {
        if (com[6] == 'F')
        {
          deleteFirst();
        }
        else if (com[6] == 'L')
        {
          deleteLast();
        }
      }
      else
      {
        deleteKey(key);
        nd++;
      }
      size--;
    }
  }

  printList();

  return 0;
}



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

int main(){
  int N, count=0;
  cin >> N;
  vector<int> ai(N);
  
  for (int i=0;i<N;i++)
    cin >> ai.at(i);
  
  for (int i=0;i<N;i++){
    if (i%2==1)
      continue;
    if (ai.at(i)%2==1)
      count++;
  }
  
  cout << count << endl;
}

Measured memory_bytes: 3624
#include<stdio.h>
int A[100000],n;
int partition(int,int);

int main(){
  int i,m;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  m=partition(0,n-1);
  for(i=0;i<n;i++){
 if(i!=0)printf(" ");
  if(i==m)printf("[%d]",A[m]);
  else{
    printf("%d", A[i]);
  }}
printf("\n");
  return 0;
}

int partition(int p,int r){
int x,j,chg,i;
x=A[r];
i=p-1;
for(j=p;j<r;j++){
  if(A[j]<=x){
    i++;
    chg=A[i];
    A[i]=A[j];
    A[j]=chg;
  }

}
  chg=A[i+1];
  A[i+1]=A[r];
  A[r]=chg;
return i+1;
}



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

#define int long long
#define uint unsigned int
#define pii pair<int, int>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FORR(i,a,b) for(int i=(a);i>=(b);--i)
#define REP(i,n) FOR(i,0,n)
#define REPR(i,n) FORR(i,n,0)
#define ALL(c) ((c).begin()), ((c).end())

#define PB(a) push_back(a)
#define EMPB(...) emplace_back(__VA_ARGS__)
#define EMP(...) emplace(__VA_ARGS__)
#define MP(a,b) make_pair(a,b)
#define MT(...) make_tuple(__VA_ARGS__)

#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MINF(a) memset(a,0x3f,sizeof(a))

#define PW(n) (1LL << (n))

using namespace std;

template <class T> inline bool CHMIN(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template <class T> inline bool CHMAX(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> inline void SORT(T &a) { sort(a.begin(), a.end()); }
template <class T> inline void REV(T &a) { reverse(a.begin(), a.end()); }
template <class T> inline void UNI(T &a) { sort(a.begin(), a.end()); a.erase(unique(a.begin(), a.end()), a.end()); }

template <class S, class T> ostream& operator << (ostream& os, const pair<S, T> v) {
  os << "(" << v.first << ", " << v.second << ")"; return os;
}

const int MOD = 1000000007;
const int INF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-10;

/* ---------------------------------------------------------------------------------------------------- */

int N;
vector<int> v[6];

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> N;
  int orgN = N;
  int sum = 0;
  set<int> st;
  for (int i = 2; i <= 30000; i++) {
    if (i % 2 == 0 || i % 3 == 0) {
      if (N > 0) {
        sum += i;
        st.EMP(i);
        N--;
      } else {
        v[i % 6].PB(i);
      }
    }
  }
  if (orgN == 3) {
    cout << "2 5 63" << endl;
  } else if (orgN == 4) {
    cout << "2 5 20 63" << endl;
  } else {
    if (sum % 6 == 2) {
      st.erase(8);
      st.EMP(v[0][0]);
    } else if (sum % 6 == 3) {
      st.erase(9);
      st.EMP(v[0][0]);
    } else if (sum % 6 == 5) {
      st.erase(8);
      st.EMP(v[3][0]);
    }
    for (auto it = st.begin(); it != st.end(); it++) {
      if (it != st.begin()) cout << " ";
      cout << *it;
    }
    cout << endl;
  }

  return 0;
}

Measured memory_bytes: 1280
// template
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<long long, long long> LP;
#define INF 999999999
#define MOD 1000000007
#define REP(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define REP_AB(i, a, b) for (ll i = ll(a); i <= ll(b); ++i)
#define ALL(v) v.begin(), v.end()
#define SORT(v) sort(ALL(v))
#define UNIQUE(v) sort(ALL(v));v.erase(unique(ALL(v)), v.end());
#define SIZE(x) ((ll)(x).size())
#define REVERSE(v) reverse(ALL(v))
// true / false
#define BIN_SEARCH(v, a) binary_search(ALL(v), a)
// index
#define BIN_LEFT(v, a) (lower_bound(ALL(v), a) - v.begin())
#define BIN_RIGHT(v, a) (upper_bound(ALL(v), a) - v.begin())
#define BIN_INSERT(v, a) (v.insert(v.begin() + BIN_LEFT(v, a), a))
#define DEL(v, i) v.erase(v.begin() + i)
#define INSERT(v, i, a) v.insert(v.begin() + i, a)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return (a / gcd(a, b)) * b;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
#define out cout
#define in cin
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
// template end
 
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    ll N, D;
    in >> N >> D;
    out << ceil(N/(2*D+1.0)) << endl;
 

 

}

Measured memory_bytes: 256
using System;
using System.Linq;//リストの使用
using System.Collections.Generic;
using System.Text;//テキストの高速出力に必要
class Program
{
	static void Main()
	{
		string[] input = Console.ReadLine().Split(' ');
		int n = int.Parse(input[0]);
		int k = int.Parse(input[1]);
    int[] nums = Array.ConvertAll(Console.ReadLine().Split(' '),int.Parse);
		long mod = 1000000007;
    long[,] dp = new long[n+1,k+1];
    long[,] sums = new long[n+1,k+2];
    dp[0,0] = 1;
    for(int i = 1; i <= k+1; i++) sums[0,i] = 1;

    for(int i = 1; i <= n; i++)
    {
      for(int j = 0; j <= k; j++)
      {
        dp[i,j] = sums[i-1,j+1] - sums[i-1,Math.Max(0, j-nums[i-1])];
        dp[i,j] += mod*2;
        dp[i,j] %= mod;

        sums[i,j+1] = sums[i,j] + dp[i,j];
        sums[i,j+1] += mod*2;
        sums[i,j+1] %= mod;

        //Console.WriteLine(i+" "+j+" "+dp[i,j]+" "+sums[i,j]);
      }
    }

		Console.WriteLine(dp[n,k]);
	}
}

Measured memory_bytes: 167896
program abc163d
      implicit none
      integer(8)::n,k
      integer(8)::i,j
      integer(8)::num,x,y
      integer(8),parameter::eps=10**9+7

         read *, n,k

         num=0
         do i=k,n+1
            x=forsum(i-1)
            y=anysum(n+1-i,n)
            num=num+(y-x+1)
            num=mod(num,eps)
         end do

         print *, num
         stop

    contains
      function forsum(n)
         implicit none
         integer(8),intent(in)::n
         integer(8)::forsum

            forsum=n*(n+1)/2
            return
      end function forsum

      function anysum(start,end)
         implicit none
         integer(8),intent(in)::start,end
         integer(8)::anysum,numterm

            numterm=end-start+1
            anysum=numterm*(2*start+numterm-1)/2
            return
      end function anysum

   end program abc163d

Measured memory_bytes: 2852
//https://atcoder.jp/contests/abc158/tasks/abc158_c
#include <bits/stdc++.h>
#if LOCAL
#include "dump.hpp"
#else
#define dump(...)
#endif
using namespace std;
using ll=long long;
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
template<class T>bool chmax(T &a, const T &b) {if (a<b) { a=b; return 1; } return 0;}
template<class T>bool chmin(T &a, const T &b) {if (b<a) { a=b; return 1; } return 0;}
int main(){
    ll A,B; cin>>A>>B;
    ll val=1;
    FOR(i,1,1000000){
        float fi=i;
        float aa=i*0.08;
        ll ia=aa;

        float bb=i*0.1;
        ll ib=bb;
        if(ia==A&&ib==B){
            cout<<i<<endl;
            return 0;
        }
    }
    cout<<-1<<endl;
    return 0;
}


int main_() {
#if LOCAL&01
    std::ifstream in("./test/sample-1.in");
    //std::ifstream in("./input.txt");
    std::cin.rdbuf(in.rdbuf());
#else
    cin.tie(0);
    ios::sync_with_stdio(false);
#endif
    ll A,B; cin>>A>>B;
    float aa=(float)A/0.08;
    float bb=(float)B/0.10;    
    dump(aa,bb);

    ll ans=-1;
    FOR(i,aa,aa+100){
        float vi=(float)i*0.08;
        ll va=vi;
        dump(i,va);
        if(va!=A)break;
        FOR(j,bb,bb+100){
            float vj=(float)j*0.1;
            ll vb=vj;
            dump(j,vb);
            if(vb!=B)break;

            if(i==j){
                ans=min(ans,i);
            }
        }
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 256
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout
	cnt := 0

	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
		cnt = 4
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)
	solve(scanner, writer)
	for i := 0; i < cnt; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
	writer.Flush()
}

func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	s := getNextString(scanner)
	if strings.LastIndex(s, "AC") == -1 {
		fmt.Fprintln(writer, "No")
		return
	}
	fmt.Fprintln(writer, "Yes")
}


Measured memory_bytes: 640
// *
// *
// *  Created By : Pritish Thakkar 
// *  Hackerrank : ma5terdrag0n
// *  CodeChef : solo_loser
// *  Hackerearth : pritish9
// *------------------------------------
// *  OS : Ubuntu 16.04
// *  Language : CPP14
// *  Editor : Sublime Text 3
// *  C++ compiler : g++
// *
// *
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define inf 1000000007
#define fr first
#define sc second
#define eps 1e-9
#define sz(x) x.size()
#define sni(x) scanf("%d",&x)
#define snl(x) scanf("%lld", &x)
#define snc(x) scanf("%c", &c);
#define rep(n) for(int i = 0 ; i < n ;i ++)
#define repc(i, n) for(int i = 0 ; i < n ; i ++)
#define FOR(i, x, y) for(int i = x ; i < y ; i ++)
#define DEC(i, x, y) for(int i = x ; i >= y ; i --)
#define all(v) v.begin(), v.end()
#define min3(a, b, c) min(a, min(b,c))
#define max3(a, b, c) max(a, max(b, c))
#define alla(a, n) a, a+n
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;

bool isUpper(char c) {return (c >= 'A' && c <= 'Z');}
bool isLower(char c) {return (c >= 'a' && c <= 'z');}
bool iplpha(char c) {return (c >= 'A' && c <= 'Z')||(c >= 'a' && c <= 'z');}
bool isnum(char c){return (c >= '0' and c <= '9');}
bool isalnum(char c) {return (c >= 'A' && c <= 'Z')||(c >= 'a' && c <= 'z')||(c >= '0' && c <= '9');}
char toUpper(char c){return isUpper(c)?c:c-'a'+'A';}
char toLower(char c){return isLower(c)?c:c+'a'-'A';}
bool isvowel(char c){c = toLower(c); return (c == 'a' or c == 'e' or c == 'i' or c == 'i' or c == 'o' or c == 'u');}
template<typename t> t gcd(t a, t b){return ((b == 0) ? a : gcd(b, a%b));} 
template<typename t> t lcm(t a, t b){return (a * (b / gcd(a, b)));}
template <typename T> T modpow(T base, T exp, T modulus) {base %= modulus;T result = 1;while (exp > 0) {if (exp & 1) result = (result * base) % modulus;base = (base * base) % modulus;exp >>= 1;}return result;}
string toLowerCase(string s){rep(s.size()){if(!isLower(s[i])){s[i] = toLower(s[i]);}}return s;}
string toUpperCase(string s){rep(s.size()){s[i] = toUpper(s[i]);}return s;}
template<typename T> void cumulative(T *a, T *b, T n){rep(n){i ? b[i] = b[i-1] + a[i] : b[i] = a[i];}}
bool ispal(string s){ll lo, hi;lo = 0;hi = s.length()-1;while(lo <= hi){if(s[lo] != s[hi]){return 0;}lo++;--hi;}return 1;}
template<class T >string toString(T n){string v = "";while(n){v.pb(n % 10 + '0');n /= 10;}reverse(all(v));return v;}

//--------------------------------------------------------------------
void solve(){
    ll a, b;
    cin >> a >> b;
    cout << round((a + b) / 2.0);
}
 
int main(){
    std::ios::sync_with_stdio(0);
    // int start = clock();
    #ifdef ONLINE_JUDGE
    #else
      //freopen("input.in" , "r" , stdin);
      // freopen("output.txt", "w", stdout);
    #endif
    solve();
    // cout << n;
    // int stop = clock();
    // cout << (stop - start) / 1000.0000<< endl;
}












Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10000000)

N=int(input())
AB=[list(map(int,input().split())) for _ in range(N-1)]

hen=[[] for _ in range(N)]
for i in range(N-1):
  a,b=AB[i]
  hen[a-1].append(b)

ans={}
def dfs(l,p):
  col=0
  for i in hen[p-1]:
    col+=1
    if col==l:
      col+=1
    ans[str(p)+","+str(i)]=col
    dfs(col,i)

dfs(-1,1)
print(max(ans.values()))

for a,b in AB:
  print(ans[str(a)+","+str(b)])

Measured memory_bytes: 80348
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <set>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>
#include <chrono>
#include <ctime>
#include <bitset>
#include <iterator>
#include <cmath>
#include <stack>
#include <random>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define debug(x) cerr << #x << ": " << x << ", "
#define debugln(x) cerr << #x << ": " << x << '\n'

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

using namespace std;
using ll = long long;
using P = pair<ll, ll>;

constexpr ll mod = 1e9+7;
const double PI = acos(-1.0);
mt19937_64 engine(chrono::steady_clock::now().time_since_epoch().count());

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  int n, m, q; cin >> n >> m >> q;
  bool mat[n][m];
  rep(i, n) {
    rep(j, m) {
      char c; cin >> c;
      mat[i][j] = (c == '1');
    }
  }

  ll mat2[n+1][m+1];
  rep(i, n+1) rep(j, m+1) mat2[i][j] = 0;
  rep(i, n) {
    rep(j, m) {
      if (i+1<n && mat[i][j] && mat[i+1][j]) {
        mat2[i+2][j+1]++;
      }
    }
  }
  rep(i, n) {
    rep(j, m+1) {
      mat2[i+1][j] += mat2[i][j];
    }
  }
  rep(j, m) {
    rep(i, n+1) {
      mat2[i][j+1] += mat2[i][j];
    }
  }

  ll mat4[n+1][m+1];
  rep(i, n+1) rep(j, m+1) mat4[i][j] = 0;
  rep(i, n) {
    rep(j, m) {
      if (j+1<m && mat[i][j] && mat[i][j+1]) {
        mat4[i+1][j+2]++;
      }
    }
  }
  rep(i, n) {
    rep(j, m+1) {
      mat4[i+1][j] += mat4[i][j];
    }
  }
  rep(j, m) {
    rep(i, n+1) {
      mat4[i][j+1] += mat4[i][j];
    }
  }

  ll mat3[n+1][m+1];
  rep(i, n+1) rep(j, m+1) mat3[i][j] = 0;
  rep(i, n) {
    rep(j, m) {
      if (mat[i][j]) mat3[i+1][j+1] = 1;
    }
  }
  rep(i, n) {
    rep(j, m+1) {
      mat3[i+1][j] += mat3[i][j];
    }
  }
  rep(j, m) {
    rep(i, n+1) {
      mat3[i][j+1] += mat3[i][j];
    }
  }

  /*
  rep(i, n+1) {
    rep(j, m+1) {
      cerr << mat3[i][j] << ' ';
    }
    cerr << endl;
  }

  rep(i, n+1) {
    rep(j, m+1) {
      cerr << mat2[i][j] << ' ';
    }
    cerr << endl;
  }

  rep(i, n+1) {
    rep(j, m+1) {
      cerr << mat4[i][j] << ' ';
    }
    cerr << endl;
  }*/

  while(q--) {
    int x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2;
    ll v = mat3[x2][y2] - mat3[x2][y1-1] - mat3[x1-1][y2] + mat3[x1-1][y1-1];
    ll e1 = mat2[x2][y2] - mat2[x2][y1-1] - mat2[x1][y2] + mat2[x1][y1-1];
    ll e2 = mat4[x2][y2] - mat4[x2][y1] - mat4[x1-1][y2] + mat4[x1-1][y1];
    //debug(v); debug(e1); debugln(e2);
    cout << v-e1-e2 << '\n';
  }

}


Measured memory_bytes: 99584
// checklist
// ll, int overflow, array bounds
// special cases (n=1?), n+1 (1-index)
// do smth instead of nothing & stay organized
// WRITE STUFF DOWN

#include <bits/stdc++.h>

using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end() 
#define MOD 1000000007

typedef long long ll;
typedef pair <int, int> ii;
typedef pair <ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef long double ld;

ll INF=LLONG_MAX;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    //freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
	int n,r; cin >> n >> r;
	if(n<10){
		r += (10-n)*100;
	}
	cout << r << endl;
}	


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <complex>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B,C,L,R;
string S,T;
const ll MOD = (1e+9) + 7;
const ll INF = 1LL << 60;
const long double EPS = 1e-9;
typedef pair<ll,ll> P;

typedef vector<P> vp;
typedef vector<vp> matP;

int main() {
    ll D;
    cin>>A>>B>>C>>D;
    cout<<max(0LL,(min(B, D) - max(A, C)))<<endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int n,a[20][2],i,j,tmp;

  scanf("%d",&n);

  for(i=0;i<n;i++) scanf("%d %d",&a[i][0],&a[i][1]);

  for(i=0;i<n-1;i++){
    for(j=n-1;j>i;j--){
      if((a[j][1]>a[j-1][1])||(a[j][1]==a[j-1][1]&&a[j][0]<a[j-1][0])){
	tmp=a[j][1];
	a[j][1]=a[j-1][1];
	a[j-1][1]=tmp;
	tmp=a[j][0];
	a[j][0]=a[j-1][0];
	a[j-1][0]=tmp;
      }
    }
  }
    printf("%d %d\n",a[0][0],a[0][1]);
    return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
#include <iomanip>
#include <iostream>
using namespace std;
using ll = long long;
const long long INF = 1LL << 60;
 
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
 
ll min(ll a, ll b){
    if(a < b) return a;
    else return b;
}
 
int main(void){
    int N; cin >> N;
    vector<float> x(N);
    vector<string> u(N);
    for(int i = 0; i < N; i++){
        cin >> x[i] >> u[i];
    }
    
    float ans = 0;
    for(int i = 0; i < N; i++){
        if(u[i] == "JPY"){
            ans += x[i];
        }else{
            ans += x[i] * 380000;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <sstream>
#include <cmath>

int main() {
  std::string buf;
  std::cin >> buf;
  const char* S = buf.c_str();
  std::vector<size_t> s;
  for (size_t i = 0; i < buf.size(); i++) {
    s.emplace_back(S[i] == '0' ? 0 : 1);
  }


  std::vector<size_t> ptn0;
  for (size_t i = 0; i < s.size(); i++) {
    if (i % 2 == 0) {
      ptn0.emplace_back(0);
    } else {
      ptn0.emplace_back(1);
    }
  }

  std::vector<size_t> ptn1;
  for (size_t i = 0; i < s.size(); i++) {
    if (i % 2 == 1) {
      ptn1.emplace_back(0);
    } else {
      ptn1.emplace_back(1);
    }
  }

  size_t min_change0 = 0;
  size_t min_change1 = 0;
  for (size_t i = 0; i < s.size(); i++) {
    if (s[i] != ptn0[i]) {
      min_change0++;
    }
    if (s[i] != ptn1[i]) {
      min_change1++;
    }
//    std::cout << i << " " << S[i] << ":" << ptn0[i] << "," << ptn1[i]
//              << std::endl;
  }

//  std::cout << "@@@ " << min_change0 << "," << min_change1 << std::endl;

  std::cout << std::min(min_change0, min_change1) << std::endl;

  return 0;
}

Measured memory_bytes: 3508
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <list>
#include <set>
#include <numeric>

#include <map>
#include <math.h>
#include <iomanip>
#include <stack>
#include <queue>
#include <bitset>
#include <math.h>

#define INF 100100100

typedef long long int llint;

using namespace std;

typedef pair<int, int>Pii;

#define pi 3.141592653589793)
#define mod 1000000007

int main() {
	llint x, y;
	cin >> x >> y;
	llint i = x;
	llint count = 1;
	while (true) {
		if (i * 2 <= y) {
			count++;
			i *= 2;
		}
		else break;
	}
	cout << count << endl;
	return 0;
}


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

string s[200];
string ans;

int main() {
	int n, l;
	cin >> n >> l;
	for (int i = 0; i < n; i++) {
		cin >> s[i];
	}
	sort(s, s + n);
	for (int i = 0; i < n; i++)ans += s[i];
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
function main()
    n = parse(Int, readline())
    a = parse.(Int, split(readline()))

    ans = 1000
    for i in 1:n-1
        kabu = 0
        if a[i] < a[i+1]
            kabu = ans ÷ a[i]
        end
        ans += (a[i+1] - a[i]) * kabu
    end


    println(ans)
end

main()  

Measured memory_bytes: 172088
from collections import deque

n,m=list(map(int,input().split()))
R=[[] for _ in range(n)]
sign=[0 for _ in range(n-1)]
dp=[0 for _ in range(n)]

for i in range(m):
  a,b=list(map(int,input().split()))
  R[a-1].append(b)
  R[b-1].append(a)

start=deque()
start.append(0)
dp[0]=1

while start:
  s=start.popleft()
  for r in R[s]:
    if dp[r-1]:
      continue
    sign[r-2] = s + 1
    start.append(r-1)
    dp[r-1]=1

if 0 in sign:
  print("No")
else:
  print("Yes")
  for s in sign:
    print(s)

Measured memory_bytes: 38024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ri register int
const long double PI=3.141592653589793238462643383279;
const int M=1000000007;
ll qpow(ll a,ll b)
{
	ll s=a%M,ans=1;
	while(b)
	{
		if(b&1)
			ans=ans*s%M;
		s=s*s%M;
		b>>=1;
	}
	return ans;
}
int gcd(int n,int m)
{
	if(!m)
		return n;
	return gcd(m,n%m);
}
int n,m,t;
long long ans;
int main()
{
	cin>>n>>m>>t;
	int nn=n/gcd(t,n),mm=m/gcd(t,m);
	int g=gcd(nn,mm);
	ans=qpow(2,nn)+qpow(2,mm)-1+qpow(2,g)-2;
	cout<<qpow(ans,1ll*(n/nn)*(m/mm));
}


Measured memory_bytes: 256
//$g++ -std=c++11 Template.cpp 

//#include <bits/stdc++.h>
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <climits>
#include <iomanip>

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define ROF(i, j, k) for(int i = (int)(j); i >= (int)(k); --i)
#define FORLL(i, n, m) for(long long i = n; i < (long long)(m); i++)
#define SORT(v, n) sort(v, v+n)
#define REVERSE(v) reverse((v).begin(), (v).end())

using namespace std;
using ll = long long;
const ll MOD=1000000007LL;
typedef pair<int, int> P;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }

priority_queue<int> q_descending;
priority_queue<int, vector<int>, greater<int> > q_ascending;

/*
  UnionFind<int> uf = UnionFind<int>(n+1); //nだとREでるの謎い..
  REP(i, m) uf.unite(x[i], y[i]);
*/
template <typename T>
class UnionFind {
public:
  T n;
  vector <T> d;
  UnionFind(T n) :d(n, -1) {} 
  int find(T x){
    if(d[x] < 0) return x;
    return d[x] = find(d[x]);
  }
  bool unite(T x, T y){
    x = find(x);
    y = find(y);
    if(x == y) return false;
    if(d[x] > d[y]) swap(x, y);
    d[x] += d[y];
    d[y] = x;
    return true;
  }
  int size(T v){ return -d[find(v)];}
  bool same(T x, T y){
    return find(x) == find(y);
  }
};


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

  int n, m;
  cin >> n >> m;

  UnionFind<int> uf = UnionFind<int>(n+m); //nだとRE
  
  for(int i=0, k; i<n; ++i){
    cin >> k;
    for(int j=0, l; j<k; ++j){
      cin >> l;
      uf.unite(i, n+l-1);
    }
  }

  //REP(i, n+m) cout << uf.find(i) << endl;
  
  for(int i=1; i< n; i++){
    if(!uf.same(i-1, i)) {cout << "NO" << endl; return 0;}
  }

  cout << "YES" << endl;
  
  return 0;
}


Measured memory_bytes: 1024
#include<cstdio>
using namespace std;
int main()
{
	int a,b;
	scanf("%d%d",&a,&b);
	if(a==b)
	{
		printf("Draw");
		return 0;
	}
	if(a==1)
	{
		printf("Alice");
		return 0;
	}
	if(b==1)
	{
		printf("Bob");
		return 0;
	}
	if(a<b)
	{
		printf("Bob");
		return 0;
	}
	printf("Alice");
	return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <istream>
using namespace std;

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

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

Measured memory_bytes: 256
from collections import defaultdict
di=defaultdict(int)
dj=defaultdict(int)
N=int(input())
A=list(map(int,input().split()))
for i,a in enumerate(A):
    di[i+a]+=1
    dj[i-a]+=1
X=set(di.keys())&set(dj.keys())
ans=0
for x in X:
    ans+=di[x]*dj[x]
print(ans)

Measured memory_bytes: 74592
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define IOS std::ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define pb push_back
using namespace std;

// DEBUG TEMPLATE
void __print(int x) {cout << x;}
void __print(long x) {cout << x;}
void __print(long long x) {cout << x;}
void __print(unsigned x) {cout << x;}
void __print(unsigned long x) {cout << x;}
void __print(unsigned long long x) {cout << x;}
void __print(float x) {cout << x;}
void __print(double x) {cout << x;}
void __print(long double x) {cout << x;}
void __print(char x) {cout << '\'' << x << '\'';}
void __print(const char *x) {cout << '\"' << x << '\"';}
void __print(const string &x) {cout << '\"' << x << '\"';}
void __print(bool x) {cout << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cout << '{'; for (auto &i: x) cout << (f++ ? "," : ""), __print(i); cout << "}";}
void _print() {cout << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cout << ", "; _print(v...);}

void OFFLINE(){
    #ifndef ONLINE_JUDGE 
        freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
        #define debug(x...) cout << "[" << #x << "] = ["; _print(x)
        #else
            #define debug(x...)
    #endif
}

const int MOD = 1e9 + 7;

int factors(int n) {

    if(n <= 2) {
        return n;
    }

    int cnt = 0;
    for(int i = 1; i * i <= n; i++) {
        if(n % i == 0){
            cnt += (1 + (i != (n / i)));
        }
    }

    return cnt;
}

int main(){

    IOS;
    OFFLINE();
    //check for corner test cases

    string s;
    cin >> s;

    if(s.back() == 's'){
        cout << s + "es" << "\n";
    }
    else
        cout << s + "s" << "\n";

    //check for corner test cases
    return 0;
}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
#define Rint register int
#define MP make_pair
#define fi first
#define se second
#define PB push_back
using namespace std;
typedef long long LL;
typedef pair<int, LL> pii;
const int N = 200003, M = 1000003, mod = 1004535809, X = 23333;
template<typename T>
void read(T &x){
	int ch = getchar(); x = 0; bool f = false;
	for(;ch < '0' || ch > '9';ch = getchar()) f |= ch == '-';
	for(;ch >= '0' && ch <= '9';ch = getchar()) x = x * 10 + ch - '0';
	if(f) x = -x;
}
void qmo(int &x){x += (x >> 31) & mod;}
int ksm(int a, int b){
	int res = 1;
	for(;b;b >>= 1, a = (LL) a * a % mod) if(b & 1) res = (LL) res * a % mod;
	return res;
}
template<typename T>
inline bool chmax(T &a, const T &b){if(a < b) return a = b, 1; return 0;}
template<typename T>
inline bool chmin(T &a, const T &b){if(a > b) return a = b, 1; return 0;}
int n, len[N], po[M], pre[M], ap[26][N], ll, cnt[N]; char str[M]; LL ans, val[N];
unordered_map<LL, int> sd;
int main(){
#ifdef NTFOrz
	freopen("a.in", "r", stdin);
#endif
	read(n); po[0] = 1;
	for(Rint i = 1;i < M;++ i) po[i] = (LL) po[i - 1] * X % mod;
	memset(ap, 0x3f, sizeof ap);
	for(Rint i = 1;i <= n;++ i){
		scanf("%s", str + len[i - 1]);
		len[i] = len[i - 1] + strlen(str + len[i - 1]);
		ap[str[len[i-1]] - 'a'][i] = len[i-1]; pre[len[i-1]] = str[len[i-1]];
		for(Rint j = len[i - 1] + 1;j < len[i];++ j){
			if(ap[str[j] - 'a'][i] > M) ap[str[j] - 'a'][i] = j;
			pre[j] = ((LL) pre[j - 1] * X + str[j]) % mod;
		}
	}
	for(Rint i = 1;i <= n;++ i) val[i] = (len[i] - len[i-1] - 1) * 26ll * mod + (LL) (str[len[i - 1]] - 'a') * mod + (pre[len[i] - 1] - (LL) pre[len[i - 1]] * po[len[i] - len[i-1] - 1] % mod + mod) % mod;
	sort(val + 1, val + n + 1);
	ll = unique(val + 1, val + n + 1) - val;
	for(Rint i = 1;i < ll;++ i) cnt[i] = 1, sd[val[i]] = i;
	for(Rint i = ll;i <= n;++ i) ++ cnt[lower_bound(val + 1, val + ll, val[i]) - val];
	for(Rint i = 1;i <= n;++ i)
		for(Rint j = len[i - 1];j < len[i];++ j)
			for(Rint k = 0;k < 26;++ k)
				if(ap[k][i] <= j){
					LL value = (len[i] - j - 1) * 26ll * mod + (LL) k * mod + (pre[len[i] - 1] - (LL) pre[j] * po[len[i] - 1 - j] % mod + mod) % mod;
					if(sd.count(value)) ans += cnt[sd[value]];
				}
	printf("%lld\n", ans - n);
}

Measured memory_bytes: 43432
import java.util.*;
public class Main{
 public static void main(String[] args){
   Scanner sc = new Scanner(System.in);
   int N = sc.nextInt();

   int[] a = new int[N];
   for(int i=0;i<N;i++) a[i] =sc.nextInt();
   Arrays.sort(a);
   
   int count =0;
   int tmp =a[0];
   boolean flg = false;
   int[] ans = new int[N];
   for(int i=1;i<N;i++)
   {
     if(tmp==a[i])
     {
       count++;
     }
     else
     {
       tmp = a[i];
       count=0;
     }
     if(count==1)
     {
       ans[i]= tmp;
       count =-1;
     }            
   }
   
   Arrays.sort(ans);
   long answer = (long)ans[N-1]*(long)ans[N-2];
   System.out.println(answer);
 }
}

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

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

    vector<int> P(N), Q(N);
    for (int i = 0; i < N; i++)
    {
        cin >> P[i];
    }
    for (int i = 0; i < N; i++)
    {
        cin >> Q[i];
    }

    vector<int> K(N);
    for (int i = 0; i < N; i++)
    {
        K[i] = i + 1;
    }

    int i = 1;
    int a, b;
    do
    {
        if (K == P)
        {
            a = i;
        }

        if (K == Q)
        {
            b = i;
        }

        i++;

    } while (next_permutation(K.begin(), K.end()));

    cout << abs(a - b) << endl;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
sc = [list(map(int, input().split())) for i in range(M)]
for i in range(0, 10**N):
    if len(str(i))==N and all(str(i)[s-1] == str(c) for s,c in sc):
        print(i)
        break
else:
    print(-1)

Measured memory_bytes: 3060