akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
using namespace std;

int main()
{
	string s, p;
	
	getline(cin, s);
	getline(cin, p);
	
	s=s+s;
	
	if(s.find(p)==-1)
		cout << "No" << endl;
	else
		cout << "Yes" << endl;

	return 0;
}

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

int n;
long double t, x, h, ans;

int main(){
	cin >> n >> t;
	for(int i=0;i<n;i++){
		cin >> x >> h;
		if(ans<t*h/x) ans = t*h/x;
	}
	printf("%.4Lf\n", ans);
	return 0;
}


Measured memory_bytes: 3304
#include <bits/stdc++.h>
using namespace std;
#define fast() ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define lp(i, n) for(int i = 0; i < n; i++)
#define rlp(i, n) for(int i = n-1; i >= 0; i--)
#define loop(i, a, b) for(int i = a; i <= b; i++)
#define rloop(i, a, b) for(int i = a; i >= b; i--)
#define mem(a, val) memset(a, val, sizeof a);
#define all(v) v.begin(),v.end()
#define ll long long
#define ld long double
#define mp_ make_pair
#define sz(s) (int)s.size()
#define pb push_back
const int MAX = 1e5 + 5;
const int inf = 1e9+1;
const ll OO = 1e18;
const ll mod = 1e9 + 7;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;

struct unionFind{ // DSU
	vi ranK, parent, numOfnodes;
	int forests;
 	unionFind(int n){
		ranK = vi(n); parent = vi(n); numOfnodes = vi(n);
		forests = n;
		lp(i, n) {
			parent[i] = i; ranK[i] = 1; numOfnodes[i] = 1;
        }
    }

    int find_set(int n){
		if(parent[n] == n) return n;
		return parent[n] = find_set(parent[n]);
    }

	void link(int u, int v){
        if(ranK[u] > ranK[v]) swap(ranK[u], ranK[v]);

		parent[u] = v;
		numOfnodes[v] += numOfnodes[u];
		if(ranK[u] == ranK[v]) ranK[v] ++;
	}

	bool union_sets(int u, int v){
		u = find_set(u); v = find_set(v);
		if(u != v){
			link(u, v); forests --;
		}
		return u != v;
	}

    int get_totN(int v){
        return numOfnodes[v];
    }
};

int main(){


    int n, m;
    cin>> n >> m;
    unionFind uf(n);
    lp(i, m){
        int u, v;
        cin>> u >> v;
        u --; v --;
        uf.union_sets(u, v);
    }
    int mx = 0;
    lp(i, n){
        if(uf.find_set(i) == i){
            mx = max(mx, uf.numOfnodes[i]);
        }
    }
    cout<< mx;
    return 0;
}


Measured memory_bytes: 11760
// AtCoder Beginner Contest 113
// D - Number of Amidakuji
// https://atcoder.jp/contests/abc113/tasks/abc113_d
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define MOD 1000000007

int main(void)
{
    int H, W, K; cin >> H >> W >> K; K--;
        
    vector<vector<ll>> dp(H+1, vector<ll>(W, 0));
    dp[0][0] = 1;

    rep(h, H) {
        rep(w, W) {
            for (int pat = 0; pat < (1<<(W-1)); pat++) {
                bool invalid = false;
                for (int i = 0; i < W-2; i++) {
                    if ((pat & (3<<i)) == 3<<i) {
                        invalid = true;
                        break;
                    }
                }
                if (invalid) continue;
                int w_from = w;
                if      (w!=W-1 && (pat&(1<< w   )))  w_from = w+1;
                else if (w!=0   && (pat&(1<<(w-1))))  w_from = w-1;
                dp[h+1][w] += dp[h][w_from];
                dp[h+1][w] %= MOD;
            }
        }
    }
    cout << dp[H][K] << endl;
}

Measured memory_bytes: 256
n,k=gets.split.map(&:to_i)
h=gets.split.map(&:to_i)
dp=[0]
1.upto(n-1){|i|
  min=10**9
  [0,i-k].max.upto(i-1){|j|
    cost=dp[j]+(h[i]-h[j]).abs
    min=cost if cost < min
  }
  dp << min
}
puts dp.last

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

struct Dice{
  int s[6];
  void roll(char c){
    int b;
    if(c=='E'){
      b=s[0];
      s[0]=s[3];
      s[3]=s[5];
      s[5]=s[2];
      s[2]=b;
    }
    if(c=='W'){
      b=s[0];
      s[0]=s[2];
      s[2]=s[5];
      s[5]=s[3];
      s[3]=b;
    }
    if(c=='N'){
      b=s[0];
      s[0]=s[1];
      s[1]=s[5];
      s[5]=s[4];
      s[4]=b;
    }
    if(c=='S'){
      b=s[0];
      s[0]=s[4];
      s[4]=s[5];
      s[5]=s[1];
      s[1]=b;
    }
  }
  int top() {
    return s[0];
  }
};
int main(){
  Dice d;
  for(int i=0;i<6;i++) cin >> d.s[i];
  string s;cin >> s;
  for(int i=0;i<s.size();i++) d.roll(s[i]);
  cout << d.top() << endl;
  return 0;
}




Measured memory_bytes: 3212
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

using namespace std;

#define _GLIBCXX_DEBUG

using _loop_ll = long long;
#define REP(i,n) for(_loop_ll (i)=0; (i)<(_loop_ll)(n); (i)++)
#define FOR(i,a,b) for(_loop_ll (i)=(_loop_ll)(a); (i)<(_loop_ll)(b); (i)++)
#define FORR(i,a,b) for(_loop_ll (i)=(_loop_ll)(b)-1; (i)>=(_loop_ll)(a); (i)--)
 
#define ALL(v) (v).begin(),(v).end()
 
#define DEBUG(x) cerr<<#x<<": "<<(x)<<endl
#define DEBUG_VEC(v) cerr<<#v<<": ";REP(__i,(v).size())cerr<<((v)[__i])<<", ";cerr<<endl

using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;

constexpr long long int MOD = 1e9 + 7;

ll MAX = 10000000000000LL;
int dp[10020];

ll check_dp(int n){
    if(n < 0){
        return 0;
    }else{
        return dp[n];
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    FOR(i, 1, 10020) dp[i] = MAX;
    dp[0] = 0;

    int h, n;
    cin >> h >> n;
    vi a(n), b(n);
    REP(i, n){
        cin >> a[i] >> b[i];
    }
    FOR(i, 1, h+1){
        ll minn = MAX;
        REP(j, n){
            if(check_dp(i - a[j]) + b[j] < minn){
                minn = check_dp(i - a[j]) + b[j];
            }
        }
        dp[i] = minn;
    }
    cout << dp[h] << endl;

    return 0;
};


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<numeric>
#include<utility>

#pragma region _define

#define f(i,a,b) for(LL i=a;i<b;i++)
#define f_vI(v,n) f(i,0,n)cin>>v[i]
#define f_v2I(v1,v2,n) f(i,0,n)cin>>v1[i]>>v2[i]
#define f_v3I(v1,v2,v3,n) f(i,0,n)cin>>v1[i]>>v2[i]>>v3[i]
#define f_vO(v,n) f(i,0,n)cout<<v[i]<<endl;
#define all(a) a.begin(),a.end()
#define size(s) s.size()
#define endl "\n"
#define _y() cout<<"Yes"<<endl
#define _Y() cout<<"YES"<<endl
#define _n() cout<<"No"<<endl
#define _N() cout<<"NO"<<endl

#pragma endregion

#pragma region _using

using namespace std;

using LL = long long;
using st = string;
using vi = vector<LL>;
using vvi = vector<vi>;
using vs = vector<st>;
using vb = vector<bool>;
using si = stack<LL>;
using ss = stack<st>;
using pi = pair<LL, LL>;
using v_pi = vector<pi>;

#pragma endregion

#pragma region _graph

#define node 50  //グラフの最大位数　適宜変更
//bool graph[node][node]; bool visited[node] = { false };
#define link(a,b,m) f(i,0,m){cin>>a[i]>>b[i]; a[i]--; b[i]--; graph[a[i]][b[i]]=graph[b[i]][a[i]]=true;}

#pragma endregion

LL gcd(LL a, LL b) {
	LL r;
	while ((r = a % b) != 0) {
		a = b;
		b = r;
	}
	return b;
}
LL lcm(LL a, LL b) {
	return (a / gcd(a, b)*b);
}

/************************************************************************/
int n;
LL ans = 0;

void dfs(LL x) {
	if (x > n) {
		return;
	}
	st s = to_string(x);
	if (s.find('7')!=-1&&s.find('5')!=-1&&s.find('3')!=-1&&s.find('0') == -1 && s.find('1') == -1 && s.find('2') == -1 && s.find('4') == -1 && s.find('6') == -1 && s.find('8') == -1 && s.find('9') == -1) {
		ans++;
	}
	dfs(x * 10 + 3);
	dfs(x * 10 + 5);
	dfs(x * 10 + 7);
}

int main(void) {
	cin.tie(0); ios::sync_with_stdio(false);
 
	cin >> n;
	dfs(0);
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
    int n;
    cin >> n;
    int h[n];
    for (int i = 0; i < n; ++i) cin >> h[i];
    int dp[n];
    dp[0] = 0; dp[1] = abs(h[0] - h[1]);
    for (int i = 2; i < n; ++i) dp[i] = min(dp[i - 2] + abs(h[i] - h[i-2]), dp[i - 1] + abs(h[i] - h[i - 1]));
    cout << dp[n-1] << endl;
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define lli long long int
#define ulli unsigned long long int
#define ld long double
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define loop(i,a,b) for(lli i=a;i<b;i++)
#define initialize(array,size,value) for(lli i=0;i<size;i++) array[i]=value
#define couta(array,size) for(lli i=0;i<size;i++) cout<<array[i]<<" "
#define vl vector<lli>
#define vp vector< pair <lli,lli> >
#define sl set<lli>
#define msp multiset < pair < long long , long long > > S;
#define pll pair<lli, lli>
#define mll map<lli, lli>            //for( map<lli, lli>::iterator i=temp.begin();i!=temp.end();i++)cout<<i->fi<<" "<<i->se<<endl;
#define mvl map<lli, vl>
#define umll unordered_map<lli, lli>
#define vt vector<pair<lli, pll >  >
#define vf vector<pair<pll,pll > >
#define qu queue<lli>
#define pq priority_queue<lli>
#define dq deque <lli>
#define ptr vector<lli>::iterator
#define bs(array,x) binary_search(array.begin(),array.end(),x) // also valid for set and multiset
#define lb(array,x) lower_bound(array.begin(),array.end(),x)
#define ub(array,x) upper_bound(array.begin(),array.end(),x)
#define nobw(array,i,j) upper_bound(array.begin(), array.end(), j)-lower_bound(array.begin(), array.end(), i) //number of numbers between i & j
#define vc clear()
#define endl '\n'
#define sp system("pause");
#define INF 9223372036854775807
#define MINF -9223372036854775808
typedef tree<pll,null_type,less<pll>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;
ld dp[3000][3000];
int main()
{
 	ios::sync_with_stdio(0);
    cin.tie(0);
    lli n;
    cin>>n;
    ld a[n+1];
    for(lli i=1;i<=n;i++)cin>>a[i];
    dp[0][0]=1;
    for(lli i=1;i<=n;i++){
    	for(lli j=0;j<=n;j++){
    		if(j==0)dp[i][j]=dp[i-1][j]*(1-a[i]);
    		dp[i][j]=dp[i-1][j]*(1-a[i])+dp[i-1][j-1]*a[i];
    	}
	}
    ld ans=0.0;
    for(lli i=n/2+1;i<=n;i++){ans+=dp[n][i];}
    cout<<fixed<<setprecision(10)<<ans;
    
    return 0;
}


Measured memory_bytes: 140928
x1, y1, x2, y2 = gets.chomp.split(" ").map(&:to_i)
delta = [x2 - x1, y2 - y1]
x, y = x2, y2
for i in 0..1
    delta = [-delta[1], delta[0]]
    x, y = [x + delta[0], y + delta[1]]
    print "#{x} #{y}#{" " if i == 0}"
end
puts

Measured memory_bytes: 1788
import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.Scanner;

class Main {
	public static void main(String args[]) {
		StringBuilder sb = new StringBuilder();
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		PriorityQueue<Integer> pq = new PriorityQueue<>(Comparator.reverseOrder());
		for (int i = 0; i < n; i++) {
			pq.add(sc.nextInt());
		}
		int t;
		for (int i = 0; i < m; i++) {
			t = pq.poll();
			pq.add(t / 2);
		}
		long sum = 0;
		for (int i = 0; i < n; i++) {
			sum += pq.poll();
		}
		System.out.println(sum);
	}
}

Measured memory_bytes: 60508
#include <stdio.h>

int main(void)
{
	int N,T,c[100],t[100],i,ans=0,cost=1000;
	scanf("%d %d",&N,&T);
	for(i=0;i<N;i++){
		scanf("%d %d",&c[i],&t[i]);
		if(T>=t[i])ans=1;
		else c[i]=1000;
	}
	if(ans==0)printf("TLE\n");
	else{
		for(i=0;i<N;i++){
			if(cost>=c[i])cost=c[i];
		}
		printf("%d\n",cost);
	}
	
	return 0;
}

Measured memory_bytes: 128
sx, sy, tx, ty = map(int, input().split())
dx, dy = tx-sx, ty-sy
r1, r2 = "U"*dy+"R"*dx, "D"+"L"*(dx-1)+"D"*(dy-1)+"L"
r3, r4 = "D"+"R"*(dx+1)+"U"*(dy+1)+"L", "U"+"L"*(dx+1)+"D"*(dy+1)+"R"
print(r1+r2+r3+r4)


Measured memory_bytes: 3060
object Main extends App {

  import scala.io.StdIn._
  import scala.math._

  val n = readLine.trim.toInt
  val taboos = Array.tabulate(n){_ ⇒ readLine.trim}
  var left = 1
  var right = 10
  var result = ""
  while (left < right){
    val mid = (left + right) / 2
    search(mid, taboos) match {
      case Some(res) ⇒
        result = res
        right = mid
      case None ⇒
        left = mid + 1
    }
  }
  println(
    result
  )
  def search(length: Int, taboos: Array[String]): Option[String] = {
    var suspects = Nil: List[Long]
    for (str ← taboos.filter(_.length >= length)){
      for (last ← length to str.length){
        suspects ::= str.substring(last - length, last).foldLeft(0L){case (l, c) ⇒ l * 26 + (c - 'a')}
      }
    }
    firstNotFound(suspects.sorted.distinct) match {
      case i if exponent(26, length) > i ⇒
        var res: List[Char] = Nil
        var n  = i
        for (_ ← 0 until length) {
          res ::= ((n % 26) + 'a').toChar
          n /= 26
        }
        Some(res.mkString)
      case _ ⇒ None
    }
  }
  def exponent(base: Long, exp: Int): Long = {
    exp match {
      case 0 ⇒ 1L
      case 1 ⇒ base
      case _ ⇒ exponent(base, exp / 2).let{it ⇒ it * it * exponent(base, exp % 2)}
    }
  }
  def firstNotFound(list:List[Long], current: Long = 0L): Long ={
    list match {
      case h::t if current == h ⇒ firstNotFound(t, current + 1)
      case _ ⇒ current
    }
  }
  implicit class Extension[T](val value :T){
    def also(func: T ⇒ Unit): T = {
      func(value)
      value
    }
    def let[R](func: T ⇒ R): R = func(value)
  }
}


Measured memory_bytes: 296432
import sys
import numpy as np
from scipy.misc import comb
sys.setrecursionlimit(1000000)
 
a,b = map(int,input().split())

if abs(a-b) % 2 == 1:
    print("IMPOSSIBLE")
else:
    if a == b:
        print(0)
    elif a < b:
        print(int(abs(a-b) // 2 + a))
    else:
        print(int(abs(a-b) // 2 + b))
    

Measured memory_bytes: 24652
#include "iostream"
#include "algorithm"
#include "string"
#include "vector"
#include "cmath"
#include "bitset"
#include "queue"
#include "functional"
#include "map"
#include "unordered_map"
#include "set"
#include "stack"
 
#define lp(n) for (int i = 0; i < n; i++)
#define LP(n,i) for (int i = 0; i < n; i++)
#define mod 1000000007
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define nyan "(=^･ω･^=)"
typedef long long ll;
using namespace std;

string s;
int l,r;

int main(){
	cin>>s;
	l=r=0;
	if(s.size()%2){
		for(int i=(s.size()-1)/2;i<=s.size()-2;i++){
			if(s[i]==s[i+1])r++;
			else break;
		}
		for(int i=(s.size()-1)/2;i>=0;i--){
			if(s[i]==s[i-1])l++;
			else break;
		}
		cout<<(s.size()-1)/2+1+min(r,l)<<endl;
	}
	else{
		for(int i=(s.size()-2)/2;i<=s.size()-1;i++){
			if(s[i]==s[i+1])r++;
			else break;
		}
		for(int i=s.size()/2;i>=0;i--){
		if(s[i]==s[i-1])l++;
		else break;	
		}
		cout<<s.size()/2+min(r,l)<<endl;
	}
	return 0;
}

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

#define ld long double
#define ll long long
#define ALL(a)  (a).begin(),(a).end()
#define spa << " " <<
#define MP make_pair
ll MOD = 1e9+7;
//ll MOD = 998244353;
ll INF = 1e18;
void chmin(ll &a, ll b) { if (a > b) a = b; }
void chmax(ll &a, ll b) { if (a < b) a = b; }
void ans1(bool x){
  if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){
  if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){
  if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
void ans(bool x, ll y, ll z){
  if(x) cout<<y<<endl;else cout<<z<<endl;}   


int main(){
  ll i,j;
  //ll n; cin>>n;
  ll a,b,c,d,e,f; cin>>a>>b;
  //ll a,b,c,d,e,f; cin>>a>>b>>c;
  //ll a,b,c,d,e,f; cin>>a>>b>>c>>d;
  string s; cin >> s;
  ll result = 0;
  ll buf = 0;
  bool judge = true;
  //cout<<48-n<<endl;
  for(i=0;i<s.size();){
    for(;i<a;i++){
      if(s[i]<'0'||s[i]>'9') judge=false;
    }
    if(s[i]!='-') judge=false;
    i++;
    for(;i<s.size();i++){
      if(s[i]<'0'||s[i]>'9') judge=false;
    }
  }
  ans1(judge);

  /*
  vector<ll> a(n);
  for(i=0;i<n;i++){
    cin>>a[i];
  }
  for(i=0;i<n;i++){

  }
  */

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
using P = pair<int,int>;
using pq = priority_queue<int>;
typedef long long ll;
string yes = "Yes\n";
string no = "No\n";

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

	int sum = 0;
	vector<int> m(n);
	rep(i, n)
	{
		cin >> m[i];
		sum += m[i];
	}
	int cnt = n;
	x -= sum;

	sort(m.begin(), m.end());
	rep(i, n)
	{
		if (x / m[i])
		{
			cnt += x/m[i];
			x = x%m[i];
		}
	}
	cout << cnt << endl;
	return (0);
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define F first
#define S second
#define int long long
#define ll long long
//#define int  unsigned long long
#define pb push_back
//#define double long double

using namespace std;
using namespace __gnu_pbds;
typedef  tree< int , null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
//const int mod = 1e9 + 7;
const int N = 310000;
int a[N];
main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
   // freopen("input.txt", "r", stdin);
    int n;
    cin >> n;
    cin >> a[1];
    int t = 0;
    int m = 1;
    for (int i = 1; i < n; i++){
        string s;
        cin >> s;
        int x;
        cin >> x;
        if (s[0] == '-') x = -x;
        if (x > 0 && a[m] > 0){
            a[m] += x;
        } else{
            m++;
            a[m] = x;
        }
    }
    n = m;
    for (int i = 1; i <= n; i++) t += abs(a[i]);
    int p = 0;
    int ans = -1e15;
    for (int i = 1; i <= n; i++){
        if (a[i] > 0){
            p += a[i];
            t -= abs(a[i]);
            continue;
        }
        if (i == n){
            p += a[i];
            continue;
        }
        if (a[i + 1] < 0){
            ans = max(ans, p + t + 2 * a[i]);
        } else{
            ans = max(ans, p + t + 2 * a[i] - 2 * a[i + 1]);
        }
        p += a[i];
        t -= abs(a[i]);
    }
    ans = max(ans, p);
    cout << ans;
}


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

using ll = long long;
using namespace std;

const int N = 1e5 + 1;
array<int, 3> a;
array<int, 3> dp;

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

#ifdef LOCAL_DEFINE
	freopen("in.txt", "r", stdin);
#endif

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

		auto dp2 = dp;
		dp[0] = a[0] + max(dp2[1], dp2[2]);
		dp[1] = a[1] + max(dp2[0], dp2[2]);
		dp[2] = a[2] + max(dp2[1], dp2[0]);
	}

	cout << max(max(dp[0], dp[1]), dp[2]) << '\n';

	return 0;
}

Measured memory_bytes: 256
S = int(input())
if S <= 10**9:
    print(0,0,S,0,0,1)
elif S == 10**18:
    print(0,0,10**9,0,0,10**9)
else:
    xb = int(S**0.5 + 1)
    yc = int(S**0.5 + 1)
    xc = xb*yc - S
    print(0, 0, xb, 1, xc, yc)

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

using namespace std;
using ll = long long;

const int MOD = 1e9 + 7;
#define REP(i, n)  for(int i = 0; i < n; ++i)
#define FOR(i, t, n)  for(ll i = t; i <= (ll)n; ++i)
struct edge {
    int from, to;
    ll cost;
};


class Eratosthenes {
public:
    vector<bool> prime;

    Eratosthenes(int size) {
        prime.resize(size + 1, 1);
        prime[0] = 0;
        prime[1] = 0;
        FOR(i, 2, size) {
            if (prime[i]) {
                for (int j = 2 * i; j <= size; j += i) {
                    prime[j] = 0;
                }
            }
        }
    }

};


class Combination {
    vector<ll> fac; //n!(mod M)
    vector<ll> ifac; //k!^{M-2} (mod M)
public:
    Combination(ll size) {
        fac.resize(size);
        ifac.resize(size);
        fac[0] = 1;
        ifac[0] = 1;
        for (ll i = 0; i < size; i++) {
            fac[i + 1] = fac[i] * (i + 1) % MOD;
            ifac[i + 1] = ifac[i] * mpow(i + 1, MOD - 2) % MOD;
        }
    }

    ll mpow(ll x, ll n) {
        ll ans = 1;
        while (n != 0) {
            if (n & 1) ans = ans * x % MOD;
            x = x * x % MOD;
            n = n >> 1;
        }
        return ans;
    }

    ll comb(ll a, ll b) {
        if (a == 0 && b == 0)return 1;
        if (a < b || a < 0)return 0;
        ll tmp = ifac[a - b] * ifac[b] % MOD;
        return tmp * fac[a] % MOD;
    }
};

ll A, B;

ll GCD(ll a, ll b) {
    if (b == 0)return a;
    return GCD(b, a % b);
}

int N, K;

int main() {
    cin >> N >> K;
    vector<ll> A(K);
    FOR(i, 1, N)A[i % K]++;
    ll res = 0;
    REP(a, K) {
        int b = (K - a) % K;
        int c = (K - a) % K;
        if ( (b+c) % K == 0)res += A[a] * A[b] * A[c];
    }
    cout << res << endl;
    return 0;
}



Measured memory_bytes: 1792
/*
 * じょえチャンネル
 * 高評価・チャンネル登録よろしくお願いします！
 * https://www.youtube.com/channel/UCRXsI3FL_kvaVL9zoolBfbQ
 */

#include<bits/stdc++.h>

int main(){
    using namespace std;
    unsigned long k, q;
    cin >> k >> q;
    vector<unsigned long> d(k);
    for(auto& i : d)cin >> i;
    const auto& query = [&](unsigned long n, unsigned long x, unsigned long m) -> unsigned long {
        x %= m;
        unsigned long S{0}, c{0};
        for(unsigned long i{0}; i < k; ++i){
            auto coef = (n + k - i - 2) / k;
            S += d[i] % m * coef;
            c += !!(d[i] % m) * coef;
        }
        return c - (S + x) / m + x / m;
    };
    for(unsigned long i{0}, n, x, m; i < q; ++i){
        cin >> n >> x >> m;
        cout << query(n, x, m) << endl;
    }
    return 0;
}

Measured memory_bytes: 384
h,w,m = map(int,input().split())
x = {}
y = {}
dic = {}
for _ in range(m):
    a,b = map(int,input().split())
    dic[(a,b)] = 1
    x[a] = x.get(a,0) + 1
    y[b] = y.get(b,0) + 1
p = max(x.values())
q = max(y.values())
cnt = 1
a = [i for i in x if x[i] == p]
b = [j for j in y if y[j] == q]
for i in a:
    for j in b:
        if dic.get((i,j),-1) == -1:
            cnt = 0
            break
    if not cnt:
        break
print(p+q-cnt)

Measured memory_bytes: 82316
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>

using namespace std;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (const auto &e : vec) os << e << (&e == &vec.back() ? "" : " ");
	return os;
}

#ifdef _DEBUG
template <class T>
void dump(const char* str, T &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + (*(str + 1) == ' ' ? 2 : 1), t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

class topological_sort {
private:
	int V;
	vector<vector<int>> edges;
	vector<int> in;
public:
	topological_sort(int n) :V(n), edges(n), in(n) {}
	topological_sort(vector<vector<int>> &edges) :V(edges.size()), in(edges.size()) { this->edges = edges; }

	void add_edge(int from, int to) { edges[from].emplace_back(to); }

	vector<int> build() {

		for (int i = 0; i < V; i++) for (const auto &e : edges[i]) in[e]++;
		vector<int> used(V), res;
		res.reserve(V);

		queue<int> que;
		for (int i = 0; i < V; i++) {
			if (in[i] == 0 && !used[i]) {
				used[i] = 1;
				que.emplace(i);
			}
		}
		while (!que.empty()) {
			int now = que.front();
			DMP(now, in);
			que.pop();
			res.emplace_back(now);
			for (const auto &e : edges[now]) {
				in[e]--;
				if (in[e] == 0) {
					if (used[e]) return vector<int>(); // unable to sort
					used[e] = 1;
					que.emplace(e);
				}
			}
		}

		return res;
	}

};

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int n, e;
	cin >> n >> e;

	vector<vector<int>> edges(n);
	for (int i = 0; i < e; i++) {
		int s, t;
		cin >> s >> t;
		edges[s].emplace_back(t);
	}

	topological_sort ts(edges);
	auto ans = ts.build();
	for (const auto &e : ans) cout << e << "\n";

	return 0;
}



Measured memory_bytes: 4296
#include <bits/stdc++.h>
using namespace std;
long long INF = 1000000000000;
int main(){
  while (1){
    int N, M;
    cin >> N >> M;
    if (N == 0 && M == 0){
      break;
    }
    vector<int> C(M);
    for (int i = 0; i < M; i++){
      cin >> C[i];
    }
    vector<int> x(N);
    for (int i = 0; i < N; i++){
      cin >> x[i];
    }
    vector<vector<long long>> dp(N + 1, vector<long long>(256, INF));
    dp[0][128] = 0;
    for (int i = 0; i < N; i++){
      for (int j = 0; j < 256; j++){
        for (int k = 0; k < M; k++){
          int next = min(max(j + C[k], 0), 255);
          dp[i + 1][next] = min(dp[i + 1][next], dp[i][j] + abs(next - x[i]) * abs(next - x[i]));
        }
      }
    }
    long long ans = INF;
    for (int i = 0; i < 256; i++){
      ans = min(ans, dp[N][i]);
    }
    cout << ans << endl;
  }
}


Measured memory_bytes: 43728
#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<climits>
#include<set>

#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)
using namespace std;
typedef pair<int, int> pii;
typedef long long int ll;
typedef pair<ll,ll> pll;
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};
#define MOD 1000000007
#define ARRAY_MAX 100005

const ll INF = 1e17+7;


int main(){

    ll n;
    cin >> n;
    int siz = 3*n;
    vector<ll> vec(siz);
    for(int i = 0;i < siz;i++){
        cin >> vec[i];
    }

    priority_queue<ll,vector<ll>,greater<ll> > que_add;//小さい方から取り出す
    priority_queue<ll> que_sub;//大きい方から取り出す

    vector<ll> ad,sb;
    ll cnt_add = 0,cnt_sub = 0;

    for(int i = 0;i < n;i++){
        //前半n要素をあらかじめ追加
        que_add.push(vec[i]);
        cnt_add += vec[i];
    }
    for(int i = siz-1;i >= siz-n;i--){
        //後半n要素をあらかじめ追加
        que_sub.push(vec[i]);
        cnt_sub += vec[i];
    }

    ad.push_back(cnt_add);//前半に何も入れない場合(残りは全て後ろに埋めるケース)
    sb.push_back(cnt_sub);//後半に何も入れないケース

    ll left = n;
    ll right = siz-n-1;

    for(int i = n;i < 2*n;i++){
        //真ん中n要素について調べる
        //i番目まで見た時の前半の最大値
        ll tmp = que_add.top();
        if(tmp < vec[i]){
            que_add.pop();
            que_add.push(vec[i]);
            cnt_add += (vec[i] - tmp);
        }
        ad.push_back(cnt_add);
    }

    for(int i = 2*n-1;i >= n;i--){
        //真ん中n要素について調べる
        //i番目まで見た時の前半の最大値
        ll tmp = que_sub.top();
        if(tmp > vec[i]){
            que_sub.pop();
            que_sub.push(vec[i]);
            cnt_sub -= (tmp - vec[i]);
        }
        sb.push_back(cnt_sub);
    }

    reverse(sb.begin(),sb.end());

    ll maxi = -INF;
    for(int i = 0;i < ad.size();i++){
        maxi = max(maxi,ad[i]-sb[i]);
    }

    cout << maxi << endl;

    return 0;
}

Measured memory_bytes: 6516
// 2013/07/05 Tazoe

#include <iostream>
#include <vector>
#include <cstring>
using namespace std;

int V; // 頂点数
vector<int> G[1000]; // グラフの隣接リスト表現
int match[1000]; // マッチングのペア
bool used[1000]; // DFSですでに調べたかのフラグ

// uからvを結ぶ辺をグラフに追加する
void add_edge(int u, int v) {
    G[u].push_back(v);
    G[v].push_back(u);
}

// 増加パスをDFSで探す
bool dfs(int v) {
    used[v] = true;
    for(int i=0;i<G[v].size();i++) {
        int u = G[v][i], w = match[u];
        if (w < 0 || !used[w] && dfs(w)) {
            match[v] = u;
            match[u] = v;
            return true;
        }
    }
    return false;
}

// 二部グラフの最大マッチングを求める
int bipartite_matching() {
    int res = 0;
    memset(match, -1, sizeof(match));
    for(int v = 0; v < V; v++) {
        if (match[v] < 0) {
            memset(used, 0, sizeof(used));
            if (dfs(v)) {
                res++;
            }
        }
    }
    return res;
}

int euclid(int a, int b)
{
	if(a%b==0)
		return b;

	return euclid(b, a%b);
}	

int main()
{
	while(true){
		int m, n;
		cin >> m >> n;

		if(m==0 && n==0)
			break;

		int b[500];
		for(int i=0; i<m; i++){
			cin >> b[i];
		}

		int r[500];
		for(int i=0; i<n; i++){
			cin >> r[i];
		}

		V = m+n;

		for(int i=0; i<1000; i++)
			G[i].clear();

		for(int i=0; i<m; i++){
			for(int j=0; j<n; j++){
				if(euclid(b[i], r[j])>1)
					add_edge(i, m+j);
			}
		}
/*
		for(int i=0; i<V; i++){
			for(int j=0; j<G[i].size(); j++){
				cout << G[i][j] << ' ';
			}
			cout << endl;
		}
*/

		cout << bipartite_matching() << endl;
	}

	return 0;
}

Measured memory_bytes: 3380
#include<stdio.h>
int main()
{
    long long int a,b,i,t,x,y;
    while(scanf("%lld%lld", &a,&b)==2){
            x=a;y=b;
        while(b){
            t=a%b;
            a=b;
            b=t;
        }
        printf("%lld %lld\n", a,(x*y)/a);
    }
return 0;
}

Measured memory_bytes: 596
//#define _GLIBCXX_DEBUG
#include <iostream>
#include <bits/stdc++.h>
    
    
using namespace std;
#define ll long long
#define ld long double
#define  P pair<ll,ll>
#define FOR(i,n,m) for(ll i=n; i<(ll)m;i++)
#define FORr(i,m,n) for(ll i=n; i>=(ll)m; i--)
#define FORm(i,m) for(auto i=m.begin();i!=m.end();i++)
#define sortAl(v) sort(v.begin(),v.end())
#define sortAlr(v) sort(v.begin(),v.end()); reverse(v.begin(),v.end())
#define cout(n) cout<<fixed<<setprecision(n)
    
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    vector<vector<ll>> bingo(3,vector<ll>(3,0));
    FOR(i,0,3){
        FOR(j,0,3){
            cin>>bingo[i][j];
        }
    }
    ll n;
    cin>>n;
    FOR(i,0,n){
        ll b;
        cin>>b;
        FOR(j,0,3)FOR(k,0,3)if(b == bingo[j][k])bingo[j][k] = 0;
    }

    ll res = 0;
    if(bingo[0][0] == 0 && bingo[0][1] == 0 && bingo[0][2] == 0) res = 1;
    if(bingo[1][0] == 0 && bingo[1][1] == 0 && bingo[1][2] == 0) res = 1;
    if(bingo[2][0] == 0 && bingo[2][1] == 0 && bingo[2][2] == 0) res = 1;
    if(bingo[0][0] == 0 && bingo[1][0] == 0 && bingo[2][0] == 0) res = 1;
    if(bingo[0][1] == 0 && bingo[1][1] == 0 && bingo[2][1] == 0) res = 1;
    if(bingo[0][2] == 0 && bingo[1][2] == 0 && bingo[2][2] == 0) res = 1;
    if(bingo[0][0] == 0 && bingo[1][1] == 0 && bingo[2][2] == 0) res = 1;
    if(bingo[2][0] == 0 && bingo[1][1] == 0 && bingo[0][2] == 0) res = 1;
    if(res == 0) cout<<"No"<<endl;
    else cout<<"Yes"<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
using namespace std;
int main(){
  int n, y, a = -1, b = -1, c = -1;
  scanf("%d %d", &n, &y); y /= 1000;
  for(int i = 0; i <= y/10; ++i){
    for(int j = 0; j <= (y-10*i)/5; ++j){
      int d = y - 10*i - 5*j;
      if(i+j+d == n){
        a = i; b = j; c = d; break;
      }
      else if(i+j+d < n) break;
    }
  }
  printf("%d %d %d\n", a, b, c);
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define md 1000000007

char wo[100100];
int mk[30];

main()
{
	long long ans=0;
	int n;
	scanf("%d",&n);
	scanf("%s",wo);
	for(int i=0;wo[i];i++)
	{
		int nw=wo[i]-'a';
		long long cal=1;
		for(int i=0;i<26;i++)
		{
			if(i==nw)
			{
				continue;
			}
			cal*=(mk[i]+1);
			cal%=md;
		}
		ans+=cal;
		ans%=md;
		mk[nw]++;
	}
	printf("%lld",ans);
}

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <deque>
#include <map>
const int MOD = 1e9+7;
typedef long long ll;
using namespace std;


int main(){
	int n;
	ll sum = 0;
	cin >> n;
	for (int i = 1; i <= n; i++){
		if (i%3 && i%5){
			sum += i;
		}
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 3652
import bisect
import cmath
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353



n, k = list(map(int, sys.stdin.buffer.readline().split()))
if n % k == 0:
    print(0)
else:
    print(1)


Measured memory_bytes: 21244
n, m = [int(_) for _ in raw_input().split()]
s = set()
e = set()
for i in xrange(m):
    a, b = [int(_) for _ in raw_input().split()]
    if a == 1:
        e.add(b)
    if b == n:
        s.add(a)

if s & e:
    print "POSSIBLE"
else:
    print "IMPOSSIBLE"


Measured memory_bytes: 17008
#include <iostream>
#include <algorithm>
using namespace std;
int sum_up(int a,int b,int sum )
{

    if(sum%2==0&&sum>2*a&&sum<2*b)
        return min(b-sum/2,sum/2-a);
    else if(sum%2!=0&&sum>2*a&&sum<2*b)
        return min(b-(sum+1)/2+1,(sum-1)/2-a+1);
    else
        return 0;
}
int main(){
    int n,x,temp=0;
    while(cin>>n>>x)
    {
        temp=0;
        if(n==0&&x==0)
            break;
        int start=max(1,x-2*n+1);
        int end=min((x-3)/3,n-2);
        for(int i=start;i<=end;i++)
            temp+=sum_up(i+1,n,x-i);
        cout<<temp<<endl;
    }
    return 0;
}


Measured memory_bytes: 3116
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <cstdlib>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <map>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;

int asc(const void* a, const void* b) {
	return *(int*)a- *(int*)b;
}

int main()
{
	int a, b, c, x, cnt = 0;
	cin >> a >> b >> c >> x;
	for (int i = 0; i <= a; i++) {
		for (int j = 0; j <= b; j++) {
			for (int k = 0; k <= c; k++) {
				if (500 * i + 100 * j + 50 * k == x) {
					cnt++;
				}
			}
		}
	}
	cout << cnt << endl;
}

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

object Solve {

  private val br = BufferedReader(InputStreamReader(System.`in`))
  private val out = PrintWriter(System.out)

  fun solve() {

    val x = br.readLine()!!.toInt()

    out.println(if(x % 100 <= x / 100 * 5) 1 else 0)
    out.flush()
  }
}

fun main(args: Array<String>){
  Solve.solve()
}

Measured memory_bytes: 34184
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=s;i<n;i++)
typedef long long ll;
int main(){
    ll n, m;
    cin >> n >> m;
    map<ll, ll> mp;
    rep(i,n){
        int a; cin >> a;
        mp[a]++;
    }
    rep(i,m){
        int b, c;
        cin >> b >> c;
        mp[c] += b;
    }
    ll ans = 0;
    for(map<ll, ll>::reverse_iterator it = mp.rbegin();it != mp.rend(); it++){
        if(n >= it->second){
            ans += it->first * it->second;
            n -= it->second;
        }else {
            ans += it->first * n;
            break;
        }
        //cout << it->first << " " << it->second << endl;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 12800
#include <bits/stdc++.h>
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define re(n) for (int i = 0; i < (n); ++i)
#define rej(n) for (int j = 0; j < (n); ++j)

using namespace std;

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

const ld PI = acos((ld)-1);

int main() {
    #ifndef LOCALDEBUG
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    #endif  // LOCALDEBUG
    string s;
    cin >> s;
    re(sz(s)) {
        if (i % 2 == 0) {
            if (s[i] != 'R' &&
                s[i] != 'U' &&
                s[i] != 'D') return cout << "No", 0;
        } else {
            if (s[i] != 'L' &&
                s[i] != 'U' &&
                s[i] != 'D') return cout << "No", 0;
        }
    }
    cout << "Yes";
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define pb(a) push_back(a)
#define all(a) (a).begin(), (a).end()
#define debug(x) cout << "debug " << x << endl;
using namespace std;

#define N 505
#define INF 999999
        
int M[N][N];

int bfs(int n){
    int dis[N]; //????????¨????????¢
    queue<int> q; //?¨??????????????????\??????
    rep(i,N) dis[i] = INF;

    dis[1] = 0;
    q.push(1);

    int u;
    while(!q.empty()){
        u = q.front(); q.pop();
        rep(v,n + 1){
            if(M[u][v] && dis[v] == INF){
                dis[v] = dis[u] + 1; //??°???????????±??? 
                q.push(v);
            }
        }
    }
    int ans = 0;
    rep(i,n + 1) if(dis[i] == 1 || dis[i] == 2) ans++;
    return ans;
}

int main(){
    int n, m;
    while(cin >> n >> m, n||m){
        rep(i,N) rep(j,N) M[i][j] = 0;
        rep(i,m){
            int a, b;
            cin >> a >> b;
            M[a][b] = M[b][a] = 1;
        }

        cout << bfs(n) << endl;
    }
}

Measured memory_bytes: 2196
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
using namespace std;
#define FOR(i,s,e) for(int i = (s);i <= (e);i++)

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

struct edge
{
	int to;
	int cost;
};

const int V_MAX = 100000;

vector<edge> es[V_MAX + 1];

int Q;
int K;

int N;

ll dis[V_MAX + 1];

int main()
{
	cin >> N;
	int a,b,c;
	FOR(i,0,N - 2)
	{
		cin >> a >> b >> c;
		es[a].push_back({b,c});
		es[b].push_back({a,c});
	}
	cin >> Q >> K;

	priority_queue<P,vector<P>,greater<P>> que;

	que.push(P(0,K));
	
	FOR(i,0,N) dis[i] = 1000000000000000000LL;
	dis[K] = 0;
	
	while(!que.empty())
	{
		ll d = que.top().first;
		int v = que.top().second;
		que.pop();
		if(d > dis[v]) continue;
		for(int i = 0;i < es[v].size();i++)
		{
			const edge& e = es[v][i];
			if(dis[e.to] > dis[v] + e.cost)
			{
				dis[e.to] = dis[v] + e.cost;
				que.push(P(dis[e.to],e.to));
			}
		}
	}

	int x,y;

	FOR(i,0,Q - 1)
	{
		cin >> x >> y;

		cout << dis[x] + dis[y] << endl;
	}
	return 0;
}


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

using namespace std;

const int maxn = 10010,mod = 924844033;
int n,k,vis[maxn][2],flag[maxn],f[4010][4010][2],tot,g[4010],jie[4010],ans;

int main()
{
    scanf("%d%d",&n,&k);
    for (int i = 1; i <= n; i++)
        for (int j = 0; j <= 1; j++)
            if (!vis[i][j])
            {
                int len = 0;
                for (int p = i,q = j; p <= n; p += k,q ^= 1)
                {
                    vis[p][q] = 1;
                    len++;
                }
                flag[tot += len] = 1;
            }
    f[1][0][0] = 1;
    for (int i = 1; i < tot; i++)
        for (int j = 0; j <= n; j++)
        {
            f[i + 1][j][0] = (f[i][j][0] + f[i][j][1]) % mod;
            if (!flag[i])
                f[i + 1][j + 1][1] = f[i][j][0];
        }
    for (int i = 0; i <= n; i++)
        g[i] = (f[tot][i][0] + f[tot][i][1]) % mod;
    jie[0] = 1;
    for (int i = 1; i <= n; i++)
        jie[i] = 1LL * jie[i - 1] * i % mod;
    for (int i = 0; i <= n; i++)
    {
        if (i & 1)
            ans = (ans - 1LL * g[i] * jie[n - i] % mod + mod) % mod;
        else
            ans = (ans + 1LL * g[i] * jie[n - i] % mod) % mod;
    }
    printf("%d\n",ans);

    return 0;
}


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

using namespace std;

#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< pii >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; cin >> x;
#define int2(x, y) Int(x); Int(y);
#define int3(x, y, z) Int(x); int2(y, z);
#define in(x, a, b) ((a) <= (x) && (x) < (b))
#define fir first
#define sec second
#define ffir first.first
#define fsec first.second
#define sfir second.first
#define ssec second.second
#define Decimal fixed << setprecision(10)

//int dxy[5] = {0, 1, 0, -1, 0};
// cmd

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

    Int(n);

    vp data(n);
    rep(i, n) {
        cin >> data[i].fir >> data[i].sec;
    }

    reverse(all(data));

    int ans = 0;

    rep(i, n) {
        int a = data[i].fir, b = data[i].sec;
        int diff = (b - ((a + ans) % b)) % b;
        ans += diff;
    }

    std::cout << ans << std::endl;

    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstring>
#include <math.h>

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

using namespace std;

int myPower(int a, int n) { // aのn乗の計算
	int x = 1;
	while (n > 0) { // 全てのbitが捨てられるまで
		if ( n & 1) { // 一番右のbitが１のとき
			x *= a;
		}
		a *= a;
		n >>= 1; // bit全体を右に1つシフトして一番右を捨てる
	}
	return x;
}

int main() {
	int n, i;
	cin >> n;
	vector<int> a(n);
	roop(i, n, 0) {
		cin >> a[i];
	}

	vector<int> rev(n);
	roop(i, n, 0) {
		rev[a[i] - 1] = i + 1;
	}
	roop(i, n, 0) {
		cout << rev[i] << endl;
	}
	return 0;
}


Measured memory_bytes: 1664
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from heapq import heapify, heappop, heappush
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, T = MAP()
A = LIST()

ans = 0
B = []
for i in range(N-1):
    if A[i+1] - A[i] < T:
        ans += A[i+1] - A[i]
    else:
        ans += T
ans += T
print(ans)




Measured memory_bytes: 27236
#include<stdio.h>

int main(){
    int N;
    int K;
    int a = 0;

    scanf("%d%d",&N,&K);
    int h[N];
    for(int i = 0; i < N; i++){
        scanf("%d",&h[i]);
        if(h[i] >= K)a += 1;
    }
    printf("%d",a);
    return 0;
}

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

using namespace std;

#define MAX_H 20
#define MAX_W 20

int H,W;
int id[MAX_H][MAX_W];

bool check(int x,int y){
  const int dx[4] = {-1,0,-1,0};
  const int dy[4] = {-1,-1,0,0};
  if(x < 1 || y < 1){ return true; }
  set<int> st;
  for(int i = 0 ; i < 4 ; i++){
    int nx = x + dx[i],ny = y + dy[i];
    st.insert(id[ny][nx]);
  }
  return (st.size() < 4);
}

int dfs(int x,int y,int num){
  if(x == W){ return dfs(0,y+1,num); }
  if(y == H){   return 1; }
  if(id[y][x] >= 0){ return dfs(x+1,y,num); }
  if(!check(x,y)){ return 0; }

  int res = 0;
  if(x+1 < W && id[y][x+1] == -1){
    id[y][x] = id[y][x+1] = num;
    res += dfs(x+2,y,num+1);
    id[y][x] = id[y][x+1] = -1;
  }
  if(y+1 < H && id[y+1][x] == -1){
    id[y][x] = id[y+1][x] = num;
    res += dfs(x+1,y,num+1);
    id[y][x] = id[y+1][x] = -1;
  }
  return res;
}

int main(){
  while(cin >> H >> W,H){
    memset(id,-1,sizeof(id));
    cout << dfs(0,0,0) << endl;
  }
  return 0;
}

Measured memory_bytes: 1212
#include <iostream>
#include <string>

using namespace std;

int main()
{
    std::string str1,str2,str3,str4;
    std::cin >> str1;
    std::cin >> str2;
    int size = str2.size();
    bool result = false;
    
    for(int a = 0;a < str1.size();a++){
        if((size + a) <= str1.size()){
            str3 = str1.substr(a,size);
        }else{
            str3 = str1.substr(a,str1.size()-a);
            str4 = str1.substr(0,(size + a) - str1.size());
            str3 += str4;
        }
        if(str2 == str3){
            result = true;
            break;
        }
    }
    if(result){
        std::cout <<"Yes"<<std::endl;
    }else{
        std::cout <<"No"<<std::endl;
    }
}

Measured memory_bytes: 3212
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define REPR(i, n) for (int i = (n); i >= 0; i--)
#define ALL(x) (x).begin(), (x).end()
#define OUT(x) std::cout << (x) << std::endl
typedef long long ll;

int main() {
    int n, m;
    cin >> n >> m;
    if (n == m)
        OUT("Yes");
    else
        OUT("No");
}

Measured memory_bytes: 256
/**
 * Problem:	C. 
 * Author:	hkxadpall. 
 * Date:	2018-09-01. 
 * Upload:	AtCoder. 
 */
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <vector>
#include <queue> 
#include <map>
#include <set>
using namespace std;

namespace AuthorName { 
    template <typename _TpInt> inline _TpInt read();
    template <typename _TpRealnumber> inline double readr();
    template <typename _TpInt> inline void write(_TpInt x);
//	template <typename _TpSwap> inline void swap(_TpSwap &x, _TpSwap &y);
	
#	define Max_N 1007
	
	int n, k, nk, ns;
	long long ans;
	
	int might(int i)
	{
		if ((i % k == 0 ? k : i % k) <= ns) return nk + 1;
		return nk;
	} 
	
	int main() 
	{
		n = read<int>();
		k = read<int>();
		if (k & 1) {
			write((long long)(n / k) * (n / k) * (n / k));
			return 0;
		}
		else {
			ans = (long long)(n / k) * (n / k) * (n / k);
			int k2 = k / 2;
			int ny = n + k2;
			ans += (long long)(ny / k) * (ny / k) * (ny / k);
			write(ans);
			return 0;
		}
	    return 0;
	}

#	define Getchar() getchar()

    template <typename _TpInt>
    inline _TpInt read()       
    {
        register int flag = 1;
        register char c = Getchar();
        while ((c > '9' || c < '0') && c != '-') 
            c = Getchar();
        if (c == '-') flag = -1, c = Getchar();
        register _TpInt init = (c & 15);
        while ((c = Getchar()) <= '9' && c >= '0') 
            init = (init << 3) + (init << 1) + (c & 15);
        return init * flag;
    }

    template <typename _TpRealnumber>
    inline double readr()       
    {
        register int flag = 1;
        register char c = Getchar();
        while ((c > '9' || c < '0') && c != '-') 
            c = Getchar();
        if (c == '-') flag = -1, c = Getchar();
        register _TpRealnumber init = (c & 15);
        while ((c = Getchar()) <= '9' && c >= '0') 
            init = init * 10 + (c & 15);
        if (c != '.') return init * flag;
        register _TpRealnumber l = 0.1;
        while ((c = Getchar()) <= '9' && c >= '0') 
            init = init + (c & 15) * l, l *= 0.1;
        return init * flag;
    }

    template <typename _TpInt>
    inline void write(_TpInt x)
    {
        if (x < 0) {
            putchar('-');
            write<_TpInt>(~x + 1);
        }
        else {
            if (x > 9) write<_TpInt>(x / 10);   
            putchar(x % 10 + '0');
        }
    }

//	template <typename _TpSwap>
//	inline void swap(_TpSwap &x, _TpSwap &y)
//	{
//	    _TpSwap t = x;
//	    x = y;
//	    y = t;
//	}
}

int main()
{
    AuthorName::main();
    return 0;
}

Measured memory_bytes: 256