akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<class T>using numr=std::numeric_limits<T>;
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; }
const int INF = 1e9;
const ll LLINF = 1e16;
const int MOD = 1000000007;
const int MOD2 = 998244353;


template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr>
std::istream& operator>> (std::istream& is, Container& v)
    { for (auto & x : v) { is >> x; } return is; }

template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr >
std::ostream& operator<< (std::ostream& os, Container const& v) {
os << "{";
    for (auto it = v.begin(); it != v.end(); it++)
        {os << (it != v.begin() ? "," : "") << *it;}
    return os << "}";
}

int main() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> a(n+1);
    for(int i=1;i<=n;i++){
        cin >> a[i];
    } 
    int num=0;
    for(int i=1;i<=n;i++){
        if(i%2 != 0 && a[i]%2 != 0) num++;
    }
    cout << num << endl;
    


}

Measured memory_bytes: 3608
n,m,q = map(int ,input().split())
lst = [list(map(int, input().split())) for _ in range(q)]
import itertools
l = [i+1 for i in range(m)]
lst2 = [com for com in itertools.combinations_with_replacement(l, n)]
res = 0
for com in lst2:
    score = 0
    for l in lst:
        if com[l[1]-1] - com[l[0]-1] == l[2]:
            score += l[3]
    if res < score:
        res = score 
    #print(score)
print(res)

Measured memory_bytes: 21616
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    bool flag = true;
    int count = 0;
    while(true)
    {
        for(int i = 0; i < n; i++)
        {
            if(a[i] % 2 == 1)
            {
                flag = false;
                break;
            }
            else
            {
                a[i] /= 2;
            }
        }
        if(!flag) break;
        count++;
    }
    cout << count << endl;
}

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

const int maxn=52;
const int mod=(int)1e9+7;
long long ret[maxn][maxn];
long long pot[maxn][maxn];

void mnoz(int n)
{
	long long prze[maxn][maxn];
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			prze[i][j]=0;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			for(int k=1;k<=n;k++)
				(prze[i][j]+=ret[i][k]*pot[k][j])%=mod;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			ret[i][j]=prze[i][j];
}

void poteguj(int n)
{
	long long prze[maxn][maxn];
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			prze[i][j]=0;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			for(int k=1;k<=n;k++)
				(prze[i][j]+=pot[i][k]*pot[k][j])%=mod;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			pot[i][j]=prze[i][j];
}

void poteguj(long long n, long long k)
{
	while(k)
	{
		if(k&1)
			mnoz(n);
		poteguj(n);
		k>>=1;
	}
}

int main()
{
	long long n,k;
	scanf("%lld %lld",&n, &k);
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			scanf("%lld",&pot[i][j]);
	for(int i=1;i<=n;i++)
		ret[i][i]=1;
	poteguj(n,k);
	long long sum=0;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			(sum+=ret[i][j])%=mod;
	printf("%lld",sum);
}

Measured memory_bytes: 256
S,T=[0],[0]
for k,c in enumerate(input()):S+=[S[-1]+1+(c=='B')]
for k,c in enumerate(input()):T+=[T[-1]+1+(c=='B')]
for _ in[0]*int(input()):
    a,b,c,d=map(int,input().split())
    print('NO'if(T[d]-T[c-1]-S[b]+S[a-1])%3 else'YES')

Measured memory_bytes: 12256
//created by missever

#include<bits/stdc++.h>
#define MAX 1000000007
using namespace std;
typedef long long LL;
typedef pair<int,int> P;

int f[1 << 15][15],g[1 << 15];
int p[15][15];

void add(int &x,int y) {
    x = max(x,y);
}

int main() {
    int n,m,i,j,k,u,v,w,s = 0;
    scanf("%d%d",&n,&m);
    for(i = 0; i < m; i++) {
        scanf("%d%d%d",&u,&v,&w);
        u--;
        v--;
        p[u][v] = p[v][u] = w;
        s += w;
    }
    memset(f,-1,sizeof(f));
    for(i = 0; i < (1 << n); i++) {
        for(j = 0; j < n; j++) {
            if(!((i >> j) & 1)) continue;
            for(k = j + 1; k < n; k++) {
                if((i >> k) & 1) g[i] += p[j][k];
            }
        }
        if(i & 1) f[i][0] = g[i];
    }
    for(i = 0; i < (1 << n); i++) {
        for(j = 0; j < n; j++) {
            if(f[i][j] != -1) {
                for(k = 0; k < n; k++) {
                    if(((i >> k) & 1) || !p[j][k]) continue;
                    add(f[i | (1 << k)][k],f[i][j] + p[j][k]);
                    u = ((1 << n) - 1) ^ i ^ (1 << k);
                    for(v = u; v; v = (v - 1) & u) add(f[i | (1 << k) | v][k],f[i][j] + p[j][k] + g[v | (1 << k)]);
                }
            }
        }
    }
    printf("%d\n",s - f[(1 << n) - 1][n - 1]);
    return 0;
}


Measured memory_bytes: 2304
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>

using namespace std;
using ll = long long;

int main()
{
    ll A, B, C, X, Y;

    cin >> A >> B >> C >> X >> Y;

    ll a = 0;
    ll b = 0;
    ll c = 0;

    a = max(X, Y) * 2 * C;
    if(X<= Y)
    {
        b += 2 * C * X;
        b += B * (Y - X);
    }
    else
    {
        b += 2 * C * Y;
        b += A * (X - Y);
    }

    c = X * A + Y * B;

    cout << min(min(a, b), c) << endl;

    return 0;
}


Measured memory_bytes: 888
//
//  main.cpp
//  A
//
//  Created by Hashizo on 2020/03/08.
//  Copyright © 2020 Hashizo. All rights reserved.
//

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <regex>
#include <cmath>

using namespace std;
 
#undef LONG_MAX
#undef LONG_MIN
 
#define LONG_MAX    9223372036854775807
#define LONG_MIN    (-LONG_MAX  -1)
 
#define ll long long
 
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
 
#define SORT(c) sort((c).begin(), (c).end())
#define REVERSE(v) reverse((v).begin(), (v).end())


int main(int argc, const char * argv[]) {

	string s;
	cin >> s;

	if(s == "hi" || s == "hihi" || s == "hihihi" || s == "hihihihi" || s == "hihihihihi") {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <vector>
#include <map>
using namespace std;

#define abs(N) ((N>0)?N:-1*N)
#define print(S) (cout << S)
#define println(S) (cout << S << endl)

int main(int argc, char const *argv[])
{
  long n,a,res=0;
  cin >> n ;

  for (int i = 0; i < n; ++i)
  {
    cin >> a;
    // println(a);
    while(a%2==0){
      a = a /2;
      // println(a);
      res++;
    }
  }

  println(res);

  return 0;
}


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

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

  long ans = 0;
  for (int a = 1; a <= N; a++) {
    for (int b = 1; b <= N; b++) {
      for (int c = 1; c <= N; c++) {
        ans += gcd(gcd(a, b), c);
      }
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 3680
#include <stdio.h>
int binarySearch(int,int [],int);
int main(){
  int N,M,i,j,c,sum=0;
  scanf("%d",&N);
  int A[N];
  for(i=0;i<N;i++){
    scanf("%d",&A[i]);
  }
  scanf("%d",&M);
  int B[M];
  for(j=0;j<M;j++){
    scanf("%d",&B[j]);
  }
  for(j=0;j<M;j++){
    c=binarySearch(N,A,B[j]);
    if(c==1)sum++;
  }
  printf("%d\n",sum);
  return 0;
}
int binarySearch(int N,int A[],int key){
  int left=0,right=N;
  while(left<right){
    int mid=(left+right)/2;
    if(key==A[mid])return 1;
    if(key>A[mid])left=mid+1;
    else if(key<A[mid])right=mid;
  }
  return 0;
}



Measured memory_bytes: 3188
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <string>
#include <map>
using namespace std;

int ChangeTimesFormat(string str){
    int h = atoi(str.substr(0,2).c_str());
    int m = atoi(str.substr(3,2).c_str());
    int s = atoi(str.substr(6,2).c_str());
    int time = h*60*60+m*60+s;
    return time;
}

int main(){
    int n;
    while(cin>>n&&n!=0){
        set<int> events;
        // ðkeyÆµÄA»ÌÉ­Ë·éñÔÌ,·éñÔÌð²×é
        map<int,pair<int,int> > m;
        for(int i = 0; i < n; i++){
            string from;
            string to;
            cin>>from>>to;
            int ft=ChangeTimesFormat(from);
            int tt=ChangeTimesFormat(to);
            events.insert(ft);
            events.insert(tt);
            m[ft].first++;
            m[tt].second++;
        }

        // ñÔÌÅå
        int maxLine=0;
        // »ÝcÁÄ¢éÌñÔÌ
        int cnt=0;
        // Ì¢Ô©çµÄ¢­
        for(map<int,pair<int,int> >::iterator it = m.begin(); it!=m.end(); it++){
            // ©¦ÁÄ«½ñÔðo^
            cnt+=it->second.second;
            // o­·éñÔÌÌûª½¢ÈçÎ
            if(cnt<it->second.first){
                maxLine+=it->second.first-cnt;
                cnt=0;
            }
            else{
                cnt-=it->second.first;
            }
        }
        cout<<maxLine<<endl;
    }
    return 0;
}

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

using namespace std;
typedef long long ll;
#define int ll

template<typename T1,typename T2> inline void chmin(T1 &a, T2 b){ if(a > b) a = b; }
template<typename T1,typename T2> inline void chmax(T1 &a, T2 b){ if(a < b) a = b; }

#define REP(i,n) for(int i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
const int MAX_N = 100010;

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

    int N;
    vector<int> X;
    cin >> N;
    X.resize(N);
    REP(i, N) {
        cin >> X[i];
    }

    int ans = LLINF;
    for(int i = 0; i <= 101; ++i) {
        int cand = 0;
        REP(j, N) {
            cand += (X[j] - i) * (X[j] - i);
        }
        chmin(ans, cand);
    }
    printf("%lld\n", ans);

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
int main(){
    int a,b;cin>>a>>b;
    int ans=1;
    int cnt=0;
    while (true)
    {
        /* code */
        
        if(ans>=b){
            cout<<cnt<<endl;
            break;
        }
        ans+=a-1;
        cnt++;
    }
    
    
   }



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

#define endl '\n'

using namespace std;

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

  int a, b;
  cin >> a >> b;
  cout << max(2*a - 1, max(2*b - 1, a + b)) << endl;

  return 0;
}


Measured memory_bytes: 256
package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanLines)
	for sc.Scan() {
		s := sc.Text()
		if s == "0" {
			break
		}
		r := []rune(s)
		sum := 0
		for i := 0; i < len(s); i++ {
			tmp, _ := strconv.Atoi(string(r[i]))
			sum += tmp
		}
		fmt.Println(sum)
	}
}



Measured memory_bytes: 1116
n, m = map(int, input().split())
a = [[0] * m for i in range(n)]
b = [0] * m
c = [0] * n
# read matrix A
for i in range(n):
    w = list(map(int, input().split()))
    for j in range(m):
        a[i][j] = w[j]
# read vevtor b
for j in range(m):
    b[j] = int(input())
# Ab -> c
for i in range(n):
    for j in range(m):
        c[i] += a[i][j] * b[j]
# output c
for i in range(n):
    print(c[i])

Measured memory_bytes: 7988
#include<stdio.h>
#include<string.h>
 
#define MAX 2000001
#define MAX_SCORE 10001
 
typedef struct {
  int id;
  int score;
  int rank;
} Info;
 
int n; // number of students
int counter[MAX_SCORE+1], maxi;
Info list[MAX+1], sortedList[MAX+1];
 
 
void CountingSort() {
  memset(counter,0,sizeof counter);
  int i;
  for(i=0;i<n;++i) ++counter[list[i].score];
  for(i=1;i<=maxi;++i) counter[i] += counter[i-1];
  for(i=n-1;i>=0;--i) {
    sortedList[--counter[list[i].score]] = list[i];
  }
}
 
int main() {
  int i, id, score;
  while( scanf("%d",&n) != EOF ) {
    maxi = 0;
    for(i=0;i<n;++i) {
      scanf("%d",&score);
      list[i].score = score;
      if( maxi < score ) maxi = score;
    }
    CountingSort();
    for(i=0;i<n;++i) {
      if( i ) printf(" ");
      printf("%d",sortedList[i].score);
    } puts("");
  }
  return 0;
}


Measured memory_bytes: 48712
import java.util.*;
public class Main{
 public static void main(String[] args){
   Scanner sc = new Scanner(System.in);
 
   int N = sc.nextInt();
   char[][] c = new char[N][10];
   String[] fa = new String[N];
   for(int i=0;i<N;i++) 
   {
     c[i] = sc.next().toCharArray();
     Arrays.sort(c[i]);
     fa[i] = new String(c[i]); 
   }
   Arrays.sort(fa);
   String tmp = fa[0];
   long count = 0;
   long ans = 0 ;
   for(int i=1;i<N;i++)
   {
     if(tmp.equals(fa[i]))
     {
       count++;
       ans+=count;
     }
     else
     {
       count = 0;
       tmp = fa[i];
     }
   }
   System.out.println(ans);
 }
}

Measured memory_bytes: 59484
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cstring>
#include<cmath>
#include <numeric>
#include<queue>
#include<climits>
#include<cstdio>
#include<map>


#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 llong long long
#define pb(a) push_back(a)
//#define INF ((LLONG_MAX) / (2))
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
typedef long long int ll;
typedef pair<ll,int> LL_IP;
typedef pair<ll,ll> LL_LLP;
#define INF 1000000007
#define MAX_H 100005

int main(){

    ll n,t,mini = INF,maxi_profit = -1,ans = 0;
    cin >> n >> t;
    vector<ll> a(n);
    vector<ll> profit(n);

    REP(i,n){
        cin >> a[i];
        mini = min(mini,a[i]);/*これまでに見た値段の最小値を求める*/
        profit[i] = a[i] - mini;
        maxi_profit = max(maxi_profit,profit[i]);
    }

    REP(i,n){
        if(profit[i] == maxi_profit){
            ans++;
        }
    }
    cout << ans << endl;
   
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep2(i, m, n) for(int i=int(m); i<int(n); ++i)
#define drep2(i, m, n) for(int i=int(m-1); i>=int(n); --i)
#define rep(i, n) rep2(i, 0, n)
#define drep(i, n) drep2(i, n, 0)
#define all(a) a.begin(), a.end()
using ll = long long;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using Vbo = vector<bool>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using VVbo = vector<Vbo>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (auto &e : v) is >> e; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << " "; return os; }
template<typename T> inline int count_between(vector<T> &a, T l, T r) { return lower_bound(all(a), r) - lower_bound(all(a), l); } // [l, r)
inline int Log2(ll x) { int k; for (k = 0; x > 0; ++k) x >>= 1; return k; } // number of binary digits
const int INF  = 1<<30;
const ll INFll = 1ll<<62;
const ld EPS   = 1e-10;
const int MOD  = int(1e9)+7;


int main() {
  ll n, k; cin >> n >> k;
  ++k;
  int D = Log2(k);

  Vll a(n), b(n);
  rep(i, n) cin >> a[i] >> b[i];

  ll ans = 0;
  rep(d, D) {
    ll csum = 0;
    rep(i, n) {
      if (a[i] >= k) continue;
      bool ok = true;
      rep(j, d) if (((a[i]>>(D-1-j))&1) > ((k>>(D-1-j))&1)) ok = false;
      if (((a[i]>>(D-1-d))&1) >= ((k>>(D-1-d))&1)) ok = false;
      if (ok) csum += b[i];
    }
    chmax(ans, csum);
  }

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


Measured memory_bytes: 1792
#include<iostream>
using namespace std;
int main()
{
  int a, b;
  cin >> a >> b;
  if(a + b >= a - b && a + b >= a * b)
    cout << a + b;
  if(a - b > a + b && a - b >= a * b)
    cout << a - b;
  if(a * b > a - b && a * b > a + b)
    cout << a * b;
  return 0;
}

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

using namespace std;

#define DBG cerr << '!' << endl;
#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(ll (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(ll (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int W = 0;W < (n);W++)cerr << v[W] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(10)
#define INF 1000000000

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

struct UF
{
	vector<int> par; // 親
	vector<int> sz; // 数
	// 初期化
	UF(int n):par(n),sz(n) {
		for(int i = 0; i < n; i++){
			par[i] = i;sz[i] = 1;
		}
	}
	// 木の根を求める
	int find(int x) {
		if (par[x] == x) return x;
		else return par[x] = find(par[x]);
	}
	// xとyの属する集合を併合
	void unite(int x, int y) {
		x = find(x); y = find(y);
		if (x == y) return;
		par[x] = y;
		sz[x] += sz[y];
	}
	// xとyが同じ集合ならtrue
	bool same(int x, int y) { return find(x) == find(y); }
	int size(int n){return sz[find(n)];}
};

//普通のLCA(UFと一緒に) 
struct LCA
{
	//隣接リスト、(相手、重み)
	vector<vector<pair<int,int> > > g;
	//親
	vector<vector<int> > parent;
	//深さ
	vector<int> depth;
	UF uf;
	int sz;
	vector<bool> inited;
		
	LCA(int n):g(n),parent(20,vector<int>(n)),
	inited(n,false),depth(n),uf(n){sz = n;}
	
	//辺の追加(点、点、重み)
	void add_edge(int u,int v,int w = 1)
	{
		if(uf.same(u,v))return;
		g[v].PB(MP(u,w));
		g[u].PB(MP(v,w));
		uf.unite(v,u);
	}
		
	void dfs(int v,int p,int d)
	{
		inited[v] = true;
		parent[0][v] = p;
		depth[v] = d;
		REP(i,g[v].size())
		{
			if(g[v][i].FI != p)dfs(g[v][i].FI,v,d+1);
		}
	}
	
	//初期化、LCA構築(一通り辺を張ってから)
	void init()
	{
		REP(i,sz)if(!inited[i])dfs(uf.find(i),-1,0);
		REP(k,19)
		{
			REP(i,sz)
			{
				if(parent[k][i] < 0)parent[k+1][i] = -1;
				else parent[k+1][i] = parent[k][parent[k][i]];
			}
		}
	}
	
	//LCAを求めるパート
	int ret_lca(int a,int b)
	{
		
		if(!uf.same(a,b))return -1;
		
		if(depth[a] > depth[b])swap(a,b);
		REP(k,20)
		{
			if((depth[b] - depth[a])>>k&1)b = parent[k][b];
		}
		if(a == b)return a;
		
		for(int k = 19;k >= 0;k--)
		{
			if(parent[k][a] != parent[k][b])
			{
				a = parent[k][a];
				b = parent[k][b];
			}
		}
		return parent[0][a];
	}
	
};


int main()
{
	int n;cin >> n;
	LCA lca(n);
	REP(i,n)
	{
		int num;cin >> num;
		REP(j,num)
		{
			int a;cin >> a;
			lca.add_edge(i,a);
		}
	}
	
	lca.init();
	
	int q;cin >> q;
	REP(i,q)
	{
		int a,b;cin >> a >> b;
		cout << lca.ret_lca(a,b) << endl;
	}
	
}


Measured memory_bytes: 20356
#include<cstdio>
#include<iostream>
#include<cmath>
using namespace std;
const long long Maxn=200000+10;
long long k,ans;
inline long long read()
{
	long long s=0,w=1;
	char ch=getchar();
	while(ch<'0' || ch>'9'){if(ch=='-')w=-1;ch=getchar();}
	while(ch>='0' && ch<='9')s=(s<<3)+(s<<1)+(ch^48),ch=getchar();
	return s*w;
}
int main()
{
	k=read();
	long long cur=0;
	for(long long i=1;i<=k;++i)
	{
		cur=(cur*10)%k;
		cur=(cur+7)%k;
		if(cur%k==0){printf("%lld\n",i);return 0;}
	}
	puts("-1");
	return 0;
}

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

using namespace std;

void Main()
{
    vector<int> A(5);
    int k;
    for (int i = 0; i < 5; ++i)
    {
        cin >> A[i];
    }
    cin >> k;
    sort(A.begin(), A.end());
    if (A[4] - A[0] > k)
        cout << ":(";
    else
        cout << "Yay!";
}

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

    std::cout << std::fixed << std::setprecision(10);

#ifdef DEBUG_BUILD
    while (true)
    {
        Main();
        cout << std::endl;
    }
#endif

    Main();
    cout << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>
#include <vector>
#include <algorithm>
#include <map>
#include <utility>

using namespace std;

int gcd(int a, int b){
	if(a < b) swap(a,b);
	if(a == 0 || b == 0) return max(a,b);
	else return gcd(b, a % b);
}

int eulerPhi(int n){
	if(n == 0) return 0;
	int ans = n;
	for(int i = 2; i * i <= n; i++){
		if(n % i == 0){
			ans -= ans / i;
			while(n % i == 0) n /= i;
		}
	}
	if(n > 1) 
		ans -= ans / n;
	return ans;
}


int main(){
	int n, cnt = 0;
	cin >> n;
	cout << eulerPhi(n) << endl;
	return 0;
}

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

int main(){
  int A,B,C,D;
  cin >> A >> B >> C >> D;
  while(A>0 && C>0){
    C -= B;
    if(C>0){
    A -= D;
    }
    else{
      continue;
    }
  }
  if(C<=0){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }

}

Measured memory_bytes: 3600
import sys,bisect

input=sys.stdin.readline

N=int(input())
x=list(map(int,input().split()))
L=int(input())

doubling=[[-1 for i in range(N)] for j in range(20)]

for i in range(N):
    npos=x[i]+L
    index=bisect.bisect_right(x,npos)
    doubling[0][i]=index-1

for i in range(1,20):
    for j in range(N):
        doubling[i][j]=doubling[i-1][doubling[i-1][j]]

forward=[[-1 for i in range(N)] for j in range(20)]

for i in range(N):
    forward[0][i]=i

for i in range(1,20):
    for j in range(N):
        forward[i][j]=doubling[i-1][forward[i-1][j]]

for _ in range(int(input())):
    a,b=map(int,input().split())
    a-=1;b-=1
    if a>b:
        a,b=b,a
    res=0
    for i in range(19,-1,-1):
        if b>forward[i][a]:
            a=doubling[i][a]
            res+=2**i
    print(res)

Measured memory_bytes: 135600
#include <bits/stdc++.h>
#define GET_MACRO(_1,_2,_3,_4,_5,_6,NAME,...) NAME
#define pr(...) GET_MACRO(__VA_ARGS__,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__)
#define Pr(a) (#a)<<"="<<(a)<<" "
#define pr1(a) cerr<<Pr(a)<<endl
#define pr2(a,b) cerr<<Pr(a)<<Pr(b)<<endl
#define pr3(a,b,c) cerr<<Pr(a)<<Pr(b)<<Pr(c)<<endl
#define pr4(a,b,c,d) cerr<<Pr(a)<<Pr(b)<<Pr(c)<<Pr(d)<<endl
#define pr5(a,b,c,d,e) cerr<<Pr(a)<<Pr(b)<<Pr(c)<<Pr(d)<<Pr(e)<<endl
#define pr6(a,b,c,d,e,f) cerr<<Pr(a)<<Pr(b)<<Pr(c)<<Pr(d)<<Pr(e)<<Pr(f)<<endl
#define int long long
#define double long double
using namespace std;
const int INF = 1LL<<55;
const int mod = (1e9)+7;
const double EPS = 1e-8;
const double PI = 6.0 * asin(0.5);
typedef pair<int,int> P;
typedef long long ll;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
ostream& operator<<(ostream& o,P p){return o<<"("<<p.first<<","<<p.second<<")";}
istream& operator>>(istream& i,P &p){return i>>p.first>>p.second;}
ostream& operator<<(ostream& o,vector<auto> &a){int i=0;for(auto t:a)o<<(i++?" ":"")<<t;return o;}
istream& operator>>(istream& i,vector<auto> &a){for(auto &t:a)i>>t;return i;}
void prArr(auto a,string s=" "){int i=0;for(auto t:a)cout<<(i++?s:"")<<t;cout<<endl;}


signed main(){
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  deque<int> A;
  int q;
  cin>>q;
  while(q--){
    int cmd;
    cin>>cmd;
    if(cmd == 0){
      int d,x;
      cin>>d>>x;
      if(d == 0) A.push_front(x);
      else A.push_back(x);
    }
    if(cmd == 1){
      int p;
      cin>>p;
      cout<<A[p]<<endl;
    }
    if(cmd ==2){
      int d;
      cin>>d;
      if(d==0) A.pop_front();
      else A.pop_back();
    }

  }
  return 0;
}



Measured memory_bytes: 6220
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include <fstream>
#include <time.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 REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define m0(x) memset(x,0,sizeof(x))
#define print(x) cout<<x<<endl;
#define pe(x) cout<<x<<" ";
#define lb(v,n) lower_bound(v.begin(), v.end(), n);
#define ub(v,n) upper_bound(v.begin(), v.end(), n);
#define int long long
#define all(x) (x).begin(), (x).end()

using namespace std;

int MOD = (ll)1000000000 + 7;
ll INF = 1e17;
const double pi = acos(-1);
const double EPS = 1e-10;
const int MAX = 500050;
typedef pair<int, int>P;

vector<int>v;
priority_queue<int>que;
vector<int>A, B, C;
int X, Y, Z, K;
vector<int>v1,v2,v3;
void solve() {
	REP(i, X)REP(j, 60)REP(k, 60) {
		v1.pb(A[i] + B[j] + C[k]);
	}
	REP(i, 60)REP(j, Y)REP(k, 60) {
		v2.pb(A[i] + B[j] + C[k]);
	}
	REP(i, 60)REP(j, 60)REP(k, Z) {
		v3.pb(A[i] + B[j] + C[k]);
	}
	VSORT(v1); VREVERSE(v1);
	VSORT(v2); VREVERSE(v2);
	VSORT(v3); VREVERSE(v3);
	if (v1[K - 1] > v2[K - 1] && v1[K - 1] > v3[K - 1]) {
		REP(i, K)print(v1[i]);
	}
	else if (v2[K - 1] > v3[K - 1]) {
		REP(i, K)print(v2[i]);
	}
	else REP(i, K)print(v3[i]);
	/*if (A[99] >= B[99] && A[99] >= C[99]) {
		REP(i, X)REP(j, 100)REP(k, 100) {
			que.push(A[i] + B[j] + C[k]);
		}
	}
	else if (B[99] >= C[99]) {
		REP(i, 100)REP(j, Y)REP(k, 100) {
			que.push(A[i] + B[j] + C[k]);
		}
	}
	else {
		REP(i, 100)REP(j, 100)REP(k, Z) {
			que.push(A[i] + B[j] + C[k]);
		}
	}
	REP(i, K) {
		print(que.top()); que.pop();
	}*/
}
signed main() {
	 cin >> X >> Y >> Z >> K;
	A.resize(X); B.resize(Y); C.resize(Z);
	REP(i, X)cin >> A[i];
	REP(i, Y)cin >> B[i];
	REP(i, Z)cin >> C[i];
	VSORT(A); VREVERSE(A);
	VSORT(B); VREVERSE(B);
	VSORT(C); VREVERSE(C);
	if (X <= 100 || Y <= 100 || Z <= 100) {
		REP(i, X) {
			REP(j, Y) {
				REP(k, Z) {
					que.push(A[i] + B[j] + C[k]);
				}
			}
		}
		REP(i, K) {
			print(que.top()); que.pop();
		}
	}
	//全部100個以上ある場合、二種類は必ず上位60個以内に収まる
	else {
		solve();
	}
}

Measured memory_bytes: 111204
N, W = map(int, input().split())
wv_array = [list(map(int, input().split())) for _ in range(N)]

ans_array = [[0] * (W + 1) for _ in range(N + 1)]

for n in range(1, N + 1):
    for w in range(W + 1):
        if wv_array[n - 1][0] > w:
            ans_array[n][w] = ans_array[n - 1][w]
        else:
            ans_array[n][w] = max(
                ans_array[n - 1][w], ans_array[n - 1][w - wv_array[n - 1][0]] + wv_array[n - 1][1])


print(ans_array[N][W])


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

class Bidirectional {
  public:
  int verts;
  int edges;
  vector<vector<int>> adj;

  Bidirectional() {}
  Bidirectional(const int &n) :
      verts(n), adj(vector<vector<int>>(n)) {}
  Bidirectional(const int &n, const int &m) :
      verts(n), edges(m), adj(vector<vector<int>>(n)) {}
};

istream &operator>>(istream &is, Bidirectional &g) {
  int from, to;
  for (int i = 0; i < g.edges; i++) {
    is >> from >> to;
    g.adj[--from].emplace_back(--to);
    g.adj[to].emplace_back(from);
  }
  return is;
}

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

  Bidirectional g(N, M);
  cin >> g;

  vector<int> from(N, -1);
  queue<int> BFS;
  from[0] = 0;
  BFS.push(0);

  int top;

  while (!BFS.empty()) {
    top = BFS.front();
    BFS.pop();

    for (auto &&to : g.adj[top]) {
      if (from[to] != -1) continue;
      from[to] = top;
      BFS.emplace(to);
    }
  }

  cout << "Yes\n";

  for (int i = 1; i < N; i++) {
    cout << from[i] + 1 << "\n";
  }
  return 0;
}

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

const int M = 101010;

int main() {
    vector<bool> prime(M, true);
    for(int i = 2; i < M; ++i) {
        for(int j = i + i; j < M; j += i) {
            prime[j] = false;
        }
    }
    vector<int> like(M);
    for(int i = 1; i < M; i += 2) {
        if(prime[i] and prime[(i + 1) / 2]) like[i] = 1;
    }
    like[1] = 0;
    for(int i = 0; i < M - 1; ++i) like[i + 1] += like[i];
    int Q; cin >> Q;
    while(Q--) {
        int l, r; cin >> l >> r;
        l--;
        cout << like[r] - like[l] << '\n';
    }
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

int main(){
	int n,k;
	cin>> n >> k;
	vector<int> h(n);
	vector<ll> dp(n,LINF);
	for(int i = 0;i< n;i++){
		cin >> h[i];
	}
	dp[0] = 0;//一段目
	for (int i = 0; i < n; i++){
		for(int j = 1;j <= min(n -i - 1 ,k);j++){
			dp[i+j] = min(dp[i+j],dp[i]+abs(h[i+j] - h[i]));
		}
		// for(int l=0;l<n;l++){
		// 	cout << dp[l];
		// }
		// cout  <<endl;
	}
	cout << dp[n - 1]<< endl;
	return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <cstring>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <queue>
#include <cmath>
#include <stdio.h>

#define _ << " " <<
#define debug(x) #x << " = " << x

#define ll long long
#define ull unsigned long long

const int maxn = 1e5+10;
ll df[maxn];
ll d[maxn];

int m;
void add(int from, int to, int s)
{
    //std::cout << "add" _ debug(from) _ debug(to) _ debug(s) << std::endl;
    d[from] += s;
    df[from] += 1;

    df[to + 1] -= 1;
    d[to + 1] -= s + (to - from) + 1;

    /*
    for (int i = 0; i < m; i++)
        std::cout << debug(i) _ debug(d[i]) _ debug(df[i]) << std::endl;

    st d::cout << "####" << std::endl;
    */

}

int main() {
    std::ios::sync_with_stdio(false);

    int n;
    std::cin >> n >> m;

    int a[n];
    for (int i = 0; i < n; i++) {
        std::cin >> a[i];
        --a[i];
    }

    ll sum = 0;
    for (int i = 1; i < n; i++) {
     //   std::cout << debug(i) << std::endl;

        if (a[i] > a[i - 1]) {
            add(a[i - 1] + 1, a[i], 0);
        } else {
            add(a[i - 1] + 1, m, 0);
            add(0, a[i], m - a[i - 1] - 1);
        }

        if (a[i] > a[i - 1])
            sum += a[i] - a[i - 1];
        else
            sum += m - a[i - 1] + a[i];
    }

    /*
    for (int i = 0; i < m; i++)
        std::cout << debug(i) _ debug(d[i]) _ debug(df[i]) << std::endl;

    std::cout << "####" << std::endl;
    */

    ll ans = sum;
    ll delta = 0;
    for (int i = 0; i < m; i++) {

        d[i] = (i > 0 ? d[i - 1] : 0) + d[i] + delta;
        delta += df[i];

      //  std::cout << debug(i) _ debug(d[i]) << std::endl;

        if (sum - d[i] < ans)
            ans = sum - d[i];
    }
    std::cout << ans << std::endl;

    return 0;
}

Measured memory_bytes: 2176
#flog 1
N = int(input())
h = list(map(int, input().split()))

dp = ["inf"]*(N)
dp[0] = 0
for i in range(N-1):
    if i == 0:        
        dp[1] = abs(h[0]-h[1])
        continue
    cost_1 = dp[i]+abs(h[i]-h[i+1])
    cost_2 = dp[i-1]+abs(h[i-1]-h[i+1])
    dp[i+1] = min(cost_1, cost_2)
    
print(dp[N-1])

Measured memory_bytes: 13928
#include <iostream>

int A[] = {0, 0};

int main(void){
    while(true){
        char c = getchar();
        if(c == '\n') break;
        A[c-'0']++;
    }
    printf("%d\n", (A[0] > A[1] ? A[1] : A[0]) << 1);
    return 0;
}


Measured memory_bytes: 256
'use strict';

function Main(input) {
    let S = input.trim().split('\n');
    // const N = Number(S[0]);
    const A = S[1].split(' ').map(v => BigInt(v));
    let result = 1n;
    
    // 0が存在する場合
    for (let i = 0; i < A.length; i++) {
        if (A[i] == 0) {
            console.log(0);
            return;
        }
    }
    for (let i = 0; i < A.length; i++) {
        result *= A[i];
        if (result > BigInt(10**18)) {
            console.log(-1);
            return;
        }
    }

    console.log(String(result));
    return;
}
Main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 43956
#include <iostream>
#include <vector>
#include <string>
#include <string.h>
#include <algorithm>
#include <math.h>
using namespace std;
const int MAX_N = 200000 + 2;
int cache[MAX_N][3], N;
int arr[MAX_N];

int f(int idx, int last)
{
	if (idx == N)return 0;

	int&ret = cache[idx][last];
	if (ret != -1)return ret;

	if (arr[idx] == 0)return ret = f(idx + 1, 0);
	else if (arr[idx] == 1)return ret = f(idx + 1, 1) + 1 + (last == 0 ? 1 : 0);
	else return ret = max(f(idx + 1, 0), f(idx + 1, 1) + 1 + (last == 0 ? 1 : 0));
}

void output(int idx, int last)
{
	if (idx == N)return;

	if (arr[idx] < 2)
	{
		cout << (arr[idx] == 0 ? 'P' : 'D');
		return output(idx + 1, arr[idx]);
	}
	else
	{
		if (f(idx + 1, 0) > f(idx + 1, 1) + 1 + (last == 0 ? 1 : 0))
		{
			cout << 'P';
			return output(idx + 1, 0);
		}
		else
		{
			cout << 'D';
			return output(idx + 1, 1);
		}
	}
}

int main()
{
	memset(cache, -1, sizeof(cache));
	string s;
	cin >> s;
	N = s.size();
	for (int i = 0; i < s.size(); i++)
	{
		if (s[i] == 'P')arr[i] = 0;
		else if (s[i] == 'D') arr[i] = 1;
		else arr[i] = 2;
	}
	output(0, 2);
}

Measured memory_bytes: 16224
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby
    #from itertools import product
    from bisect import bisect_left,bisect_right
    import heapq
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    a,b = map(int, input().split())
    n = (b-a+1)//2
    if a%2==0:
        if b%2==1:
            print(n%2)
        else:
            print(b^(n%2))
    else:
        if b%2==1:
            print(a^(n%2))
        else:
            print(a^b^((n-1)%2))


if __name__ == '__main__':
    main()

Measured memory_bytes: 3316
import java.util.Scanner;

public class Main{
	public static void main(String[]args) {
		
		Scanner sc=new Scanner(System.in);
		
		int A=sc.nextInt();
		int B=sc.nextInt();
		
		if(A==B) {
			System.out.println("IMPOSSIBLE");
		}else if((A+B)%2==0){
			System.out.println((A+B)/2);
		}else {
			System.out.println("IMPOSSIBLE");
		}
		
		sc.close();
	}
}

Measured memory_bytes: 25172
#include <stdio.h>

int main(void){
  int N,M,C;
  scanf("%d%d%d",&N,&M,&C);

  int B[M];
  for(int i = 0;i < M;i++) scanf("%d",&B[i]);

  int ans = 0,a;
  for(int i = 0;i < N;i++){
    int res = C;
    for(int j = 0;j < M;j++){
      scanf("%d",&a);
      res += a*B[j];
    }
    if(res > 0) ans++;
  }

  printf("%d\n",ans);

  return 0;
}

Measured memory_bytes: 128
n,x=map(int,input().split())


b=[1]
p=[1]
for i in range(n):
    b.append(2*b[-1]+3)
    p.append(2*p[-1]+1)

def f(N,X):
    if N==0:
        return 0 if X<=0 else 1
    elif X==1:
        return 0
    elif 1<X and X<=b[N-1]+1:
        return f(N-1,X-1)
    elif X==b[N-1]+2:
        return p[N-1]+1
    else:
        return p[N-1]+1+f(N-1,X-2-b[N-1])

print(f(n,x))

Measured memory_bytes: 3064
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author tatsumack
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(12)

using namespace std;

typedef pair<int, int> P;

class DMovingPiece {
public:
    map<int, int> par, point, size;
    vector<int> P, C;
    int sum = 0;
    int sz = 0;

    void dfs(int v, int p) {
        if (par.count(v)) return;
        par[v] = p;
        sum += C[v];
        sz++;
        dfs(P[v], p);
    }

    void solve(std::istream& cin, std::ostream& cout) {
        int N, K;
        cin >> N >> K;
        P.resize(N);
        C.resize(N);
        REP(i, N) {
            cin >> P[i];
            P[i]--;
        }
        REP(i, N) cin >> C[i];

        REP(i, N) {
            if (par.count(i)) continue;
            sum = 0;
            sz = 0;
            dfs(i, i);
            point[i] = sum;
            size[i] = sz;
        }

        int res = -INF;
        REP(i, N) {
            int p = par[i];
            int cur = i;
            int tmp = 0;
            if (K <= N) {
                REP(j, K) {
                    tmp += C[P[cur]];
                    cur = P[cur];
                    res = max(res, tmp);
                }
                continue;
            }
            if (point[p] > 0) {
                int num = K / size[p];
                num = max(num - 1, 0LL);
                tmp = num * point[p];
                int rem = K - num * size[p];
                if (num > 0) res = max(res, tmp);
                REP(j, rem) {
                    tmp += C[P[cur]];
                    cur = P[cur];
                    res = max(res, tmp);
                }
            } else {
                REP(j, min(size[p], K)) {
                    tmp += C[P[cur]];
                    cur = P[cur];
                    res = max(res, tmp);
                }
            }
        }
        cout << res << endl;
    }
};


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    std::istream& in(std::cin);
    std::ostream& out(std::cout);

    DMovingPiece solver;
    solver.solve(in, out);
    return 0;
}


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

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define mp make_pair
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define MOD 1000000007

int a,b;
int q;
ll s[101010],t[101010];
ll x;

int main(){
  cin >> a >> b >> q;
  for(int i = 1; i <= a; i++){
    cin >> s[i];
  }
  for(int i = 1; i <= b; i++){
    cin >> t[i];
  }
  s[0] = t[0] = -1e18;
  s[a+1] = t[b+1] = 1e18;
  for(int i = 0; i < q; i++){
    ll ans = 1e18;
    cin >> x;
    int a1 = 0,b1 = 0;
    int l1 = 0, r1 = a, M = 0;
    for(int p = 0; p < 25; p++){
      if(r1 - l1 == 1){
        if(s[l1] >= x) a1 = l1;
        else a1 = r1;
      }
      M = (l1+r1) / 2;
      if(s[M] < x) l1 = M;
      else r1 = M;
    }
    l1 = 0;r1 = b;
    for(int p = 0; p < 25; p++){
      if(r1 - l1 == 1){
        if(t[l1] >= x) b1 = l1;
        else b1 = r1;
        break;
      }
      M = (l1+r1) / 2;
      if(t[M] < x) l1 = M;
      else  r1 = M;
    }
    int p1[] = {a1-1,a1};
    int p2[] = {b1-1,b1};
    for(int y1 = 0; y1 < 2; y1++){
      for(int y2 = 0;y2 < 2; y2++){
        ans = min(abs(s[p1[y1]]-x)+abs(t[p2[y2]]-s[p1[y1]]),ans);
        ans = min(abs(t[p2[y2]]-x)+abs(s[p1[y1]]-t[p2[y2]]),ans);
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 2944
#include<bits/stdc++.h>
using namespace std;
int n ;
int dp[1000005];
int a[1000005]; 
int dpf(int r)
{

	if(r==0)
		return 0 ; 
	if(r==1)
		return dp[r] = abs(a[r]-a[r-1])+dpf(r-1);
	if(dp[r]!=-1)
		return dp[r];
	else
		return dp[r] = min(abs(a[r]-a[r-1])+dpf(r-1),abs(a[r]-a[r-2])+dpf(r-2));
}
int main()
{
	cin >> n ;
	fill(dp,dp+1000005,-1); 
	for(int i = 0 ; i <n ; ++i)cin >> a[i];
	cout << dpf(n-1);	

}

Measured memory_bytes: 7936
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define int long long
#define endl "\n"
#define pii pair<int,int> 
#define ff first
#define ss second
#define mii map<int,int>
#define si set<int>
#define sti stack<int>
#define qi queue<int>
#define vi vector<int>
#define pq priority_queue<int>
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const int M=1e9+7;

int32_t main(){
	IOS;
	int a,b;
	cin>>a>>b;
	cout<<(a*b)/(__gcd(a,b))<<endl;
}

Measured memory_bytes: 256
using System;
using System.Linq;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            string m = Console.ReadLine();
            string y = Console.ReadLine();
            
            string[] monster = m.Split(' ');
            string[] yusha = y.Split(' ');

            int[] monsterList = monster.Select(x => int.Parse(x)).ToArray();
            int[] yushaList = yusha.Select(x => int.Parse(x)).ToArray();

            long result = 0;

            for(int i=0; i<n; i++)
            {
                if (yushaList[i] <= monsterList[i])
                {
                    result += yushaList[i];
                }
                else 
                {
                    result += monsterList[i];

                    int yushaNextTown = yushaList[i] - monsterList[i];

                    if (monsterList[i + 1] - yushaNextTown >= 0)
                    {
                        monsterList[i + 1] -= yushaNextTown;
                        result += yushaNextTown;
                    }
                    else
                    {
                        result += (monsterList[i + 1]);
                        monsterList[i + 1] = 0;
                    }
 
                }
                
            }

            Console.WriteLine(result);
        }
    }
}

Measured memory_bytes: 32604
#include <bits/stdc++.h>
#define PREP(i, s, x) for(ll i = (s); i < (x); i++)
#define MREP(i, s, x) for(ll i = (s); i >= (x); i--)
#define REP(i, x) PREP(i, 0, x)
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
template<typename T> inline bool chmax(T &a, T b) { return ((a < b) ? (a = b, true) : (false)); }
template<typename T> inline bool chmin(T &a, T b) { return ((a > b) ? (a = b, true) : (false)); }

// variable -------------------------------------------

constexpr ll INF = (1ll << 59);
constexpr ll MOD = 1000000007ll;

// structure ------------------------------------------

// function -------------------------------------------

// main -----------------------------------------------

int main() {
    ll n, k;
    cin >> n >> k;
    vector<ll> p(n);
    REP(i, n){
        cin >> p[i];
    }

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

    ll ans = 0;
    REP(i, k){
        ans += p[i];
    }

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


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
#define F(i,a,b) for(int i=int(a);i<=int(b);i++)
#define endl "\n"
#define ios std::ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define out(x) cout<<x<<endl,exit(0);
#define pb push_back
#define all(v) v.begin(),v.end()
#define I first
#define S second

const int N=1e5+9;
vector <int> v[N],rev[N],u;
int deg[N],vis[N],dp[N];

int main(){
	ios;
	int n,m,x,y;
	cin>>n>>m;

	F(i,1,m){
		cin>>x>>y;
		deg[y]++;
		v[x].pb(y);
		rev[y].pb(x);
	}

	queue <int> q;
	F(i,1,n) if(deg[i]==0) q.push(i),vis[i]=1;

	while(!q.empty()){
		int p=q.front();
		q.pop();
		u.pb(p);
		for(auto it:v[p]){
			if(vis[it]) continue;
			deg[it]--;
			if(deg[it]==0){
				q.push(it);
				vis[it]=1;
			}
		}
	}

	for(auto i:u){
		if(rev[i].size()==0) continue;
		int mx=0;
		for(auto it:rev[i]){
			mx=max(mx,dp[it]);
		}
		dp[i]=mx+1;
	}

	cout<<*max_element(dp+1,dp+n+1);
}

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

using namespace std;

int main(){
	int N,count=0;
	cin >> N;
	int a;
	for(int i=0;i<N;i++){
		cin >> a;
		while(a%2==0){
			a/=2;count++;
		}
	}
	cout << count << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
ll A, B, C, D, E,F;
int main()
{
    ll t,i,j,k,l;
    cin>>A>>B>>C>>D>>E>>F;
    double rs=-1;
    ll r1,r2;
    r1=r2=0;
    for(i=0;i<=F;i+=100*A)
    {
		for(j=0;i+j<=F;j+=100*B)
		{
			ll mx=min(((i+j)/100)*E,F-i-j);
			for(k=0;k<=mx;k+=C)
			{
				for(l=0;k+l<=mx;l+=D)
				{
					ll x=l+k;
					ll y=i+j+k+l;
					double q=(x*100.0)/y;
					if(q>rs)
					{
						rs=q;
						r1=y;
						r2=x;
					}
				}
			}
		}
	}
	if(r1==0&&r2==0)assert(0);
    
    cout<<r1<<" "<<r2<<endl;
    
	return 0;
}

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

int main() {
    int a, b, c; cin >> a >> b >> c;
    const int set = 7 * a + b,
          week = c / set,
          rest = c % set;
    double additional_days;
    if (rest > 7 * a)
        additional_days = 7;
    else {
        float tmp = (float)rest / a;
        // test begin -----
        //cout << "tmp: " << tmp << endl;
        // test end -----
        additional_days = ceil(tmp);
    }

    int result = 7 * week + additional_days;
    cout << result << endl;
    // test
    /*
       cout << "set: " << set << endl
       << "week: " << week << endl
       << "rest: " << rest << endl
       << "additional_days: " << additional_days << endl;
    */
}


Measured memory_bytes: 3108
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main() {
    int N; cin >> N;
    for(int i = 0; i <= 9; i++) {
        for(int j = 0; j <= 9; j++) {
            if(i*j == N) {
                cout << "Yes";
                return 0;
            }
        }
    }
    cout << "No";
    return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
N = int(input())

txy = []
for i in range(N):
    txy.append(list(map(int, input().split())))

tb,xb,yb = 0,0,0

for t,x,y in txy:
    ts = t - tb
    xs = abs(x - xb)
    ys = abs(y - yb)
    tb = t
    xb = x
    yb = y

    if ts < xs + ys:
        print('No')
        exit()

    if (ts - (xs + ys)) % 2 == 1:
        print('No')
        exit()

print('Yes')


Measured memory_bytes: 27324
judge =["AC","WA","TLE","RE"]
C = [0,0,0,0]

N= int(input())
for i in range(N):
    si = input()
    if si == judge[0]:
        C[0]+=1
    elif si == judge[1]:
        C[1]+=1
    elif si == judge[2]:
        C[2]+=1
    elif si == judge[3]:
        C[3]+=1

print("AC x ",C[0])
print("WA x ",C[1])
print("TLE x ",C[2])
print("RE x ",C[3])

Measured memory_bytes: 69924