akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
using ll=long long;
#define rep(i,a,b) for(int i=(a); i<(b); ++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define RANGE(a,b,c) (a).begin()+b,(a).begin()+c // コンテナ a の 要素 b から c へのイテレータ
// typedef
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;

int main() {
	VVI c(3, VI(3));
	rep(i,0,3){rep(j,0,3) scanf("%d", &c[i][j]);}
	VI b(3);

	rep(a1, 0, 100+1){
		b[0] = c[0][0] - a1;
		b[1] = c[0][1] - a1;
		b[2] = c[0][2] - a1;
		rep(a2, 0, 100+1){
			if (a2 + b[0] == c[1][0] && a2 + b[1] == c[1][1] && a2 + b[2] == c[1][2]){
				rep(a3, 0, 100+1){
					if (a3 + b[0] == c[2][0] && a3 + b[1] == c[2][1] && a3 + b[2] == c[2][2]){
						cout << "Yes" << "\n";
						return 0;
					}
				}
			}
		}
	}
	cout << "No" << "\n";
	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define P pair<ll, ll>
#define Graph vector<vector<P>>
#define fi first
#define se second
constexpr ll mod = 1000000007;
constexpr ll INF = (1ll << 60);
constexpr double pi = 3.14159265358979323846;
template <typename T>inline bool chmax(T &a, T b){if (a < b){a = b;return 1;}return 0;}
template <typename T>inline bool chmin(T &a, T b){if (a > b){a = b;return 1;}return 0;}

int main(){
    ll a;string s;
    cin>>a>>s;
    if(a>=3200) cout<<s<<endl;
    else cout<<"red"<<endl;
    return 0;
}

Measured memory_bytes: 3592
#include<iostream>
#include<stdio.h>
#include<string>
#include<algorithm>
#include<math.h>
#include<vector>
using namespace std;

long int gcd(long int m, long int n )
{
	// 引数に０がある場合は０を返す
	if ( ( 0 == m ) || ( 0 == n ) )
		return 0;
	
	// ユークリッドの方法
	while( m != n )
	{
		if ( m > n ) m = m - n;
		else         n = n - m;
	}
	return m;
}//gcd

long int lcd(long int m, long int n){
    return m * n / gcd(m, n);
}

int main(){
    long int N, M;
    cin >> N >> M;
    string S, T;
    cin >> S;
    cin >> T;
    /*
    if(gcd(M, N) == 1){
        cout << M * N << endl;
        return 0;
    }
    //*/
    long int gcdmn = gcd(M, N);
    //cout << gcdmn << endl;
    for(long int i=0; i<gcdmn; ++i){
        if(S[N / gcdmn * i] != T[M / gcdmn * i]){
            cout << -1 << endl;
            return 0;
        }
    }
    cout << lcd(M, N) << endl;
    return 0;
}

Measured memory_bytes: 512
import std.stdio;
import std.array;
import std.algorithm;
import std.conv;
import std.numeric;
import std.string;

void main() {
  auto l = readln.chomp.split.map!(to!int).array;
  int H = l[0], W = l[1];
  int[][] c = new int[][](10, 10);
  int[][] A = new int[][](H, W);

  foreach(i; 0..10) {
    c[i][] = readln.chomp.split.map!(to!int).array;
  }
  foreach(i; 0..H) {
    A[i][] = readln.chomp.split.map!(to!int).array;
  }

  foreach(k; 0..10) {
    foreach(j; 0..10) {
      foreach(i; 0..10) {
        c[i][j] = min(c[i][j], c[i][k] + c[k][j]);
      }
    }
  }

  int ans;
  foreach(i; 0..H) {
    foreach(j; 0..W) {
      if (A[i][j] != -1 && A[i][j] != 1) {
        ans += c[A[i][j]][1];
      }
    }
  }

  ans.writeln;
}


Measured memory_bytes: 3324
//g++ -std=c++17 -Wshadow -Wall -fsanitize=address -fsanitize=undefined -D_GLIBCXX_DEBUG -g PROGRAM -o OUTPUT -DLOCAL -lasan -lubsan
#include <bits/stdc++.h>
#include <ext/pb_ds/detail/standard_policies.hpp>

#define ll long long
#define ull unsigned long long
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define alli(a, n, k) (a + k), (a + n + k)
#define FP(i, a, b, k) for (__typeof(a) i = a; i < b; i += k)
#define FS(i, a, b, k) for (__typeof(a) i = a; i > b; i -= k)
#define IT(it, a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); ++it)
#define eps 1e-6
#define pi 3.141592653589793
using namespace std;
using namespace __gnu_pbds;

template <class T>
inline T gcd(T x, T y)
{
    if (!y)
        return x;
    return gcd(y, x % y);
}
typedef vector<int> VII;
typedef vector<ll> VLL;
typedef pair<int, int> PII;
typedef vector<pair<int, int>> VPII;
typedef vector<pair<int, PII>> VPPI;
const int MOD = 1e9 + 7;
const int INF = 1e9;


inline ll modulo(ll a, ll m)
{
    return (a % m + m) % m;
}

inline ll modInverse(ll a, ll m)
{
    assert(__gcd(a, m) == 1);
    ll m0 = m;
    ll y = 0, x = 1;

    if (m == 1)
        return 0;

    while (a > 1)
    {
        ll q = a / m;
        ll t = m;

        m = a % m, a = t;
        t = y;

        y = x - q * y;
        x = t;
    }

    if (x < 0)
        x += m0;

    return x;
}

inline ll modPow(ll x, ll y, ll m)
{ //x^y % m
    if (y == 0)
        return 1LL;
    else if (y == 1)
        return x;
    else
    {
        ll ans = modPow(x, y / 2, m) % m;
        if (y & 1)
        {
            return (((ans * ans) % m) * x) % m;
        }
        else
        {
            return (ans * ans) % m;
        }
    }
}

vector<string> split(char d,string s)
{
    stringstream ss(s);
    string t;
    vector<string> words;
    while(getline(ss,t,d))
    {
        words.pb(t);
    }

    return words;
}

int main(int argc, char *argv[])
{
#ifdef LOCAL
    auto start = chrono::high_resolution_clock::now();
#endif
    
    ios::sync_with_stdio(false);
    cin.tie(NULL);

    int n;
    cin >> n;
    VII arr(n);
    for(auto &x:arr)
        cin >> x;

    int mn = arr[0];
    ll ans = 0;

    for (int i = 1; i < n;++i)
    {
        mn = max(mn, arr[i]);
        ans += 1LL*max(mn - arr[i], 0);
    }

    cout << ans;

#ifdef LOCAL
    auto end = chrono::high_resolution_clock::now();
    double time_taken =
        chrono::duration_cast<chrono::nanoseconds>(end - start).count();

    time_taken *= 1e-9;

    cerr << "\nTime taken by program is : " << fixed
         << time_taken << setprecision(9);
    cerr << " sec" << endl;
#endif
    return 0;
}


Measured memory_bytes: 3976
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<cmath>
using namespace std;

#define REP(i,n) for(int i=0;(i)<(n);(i)++)

int main() {
	int A, B;
	cin >> A >>B;

	if (A + B >= 10) {
		cout << "error" << endl;
		return 0;
	}

	cout << A+B << endl;
	return 0;
}

Measured memory_bytes: 256
#素因数分解して列挙する関数、約数列挙ではない！
from collections import Counter
def factorize(n):
    b = 2
    fct = []
    while b * b <= n:
        while n % b == 0:
            n //= b
            fct.append(b)
        b = b + 1
    if n > 1:
        fct.append(n)
    fct = Counter(fct)
    return fct

mod = 10**9+7
def comb_mod(n,r,mod):
    ans = 1
    for i in range(r):
        ans *= n-i
        ans %= mod
    for i in range(1,r+1):
        ans *= pow(i,mod-2,mod)
        ans %= mod
    return ans

N, M = map(int, input().split())
fact = factorize(M)
ans = 1
for k in fact.values():
    ans *= comb_mod(k+N-1,k,mod)
    ans %= mod
print(ans)

Measured memory_bytes: 3316
//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 より
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

//

fn run() {
    input! {
        n: usize,
        t: usize,
        p: [(usize, usize); n],
    }
    let mut zero = vec![];
    let mut q = vec![];
    for (a, b) in p {
        if a == 0 {
            zero.push(b);
        } else {
            q.push((a, b));
        }
    }
    q.sort_by(|a, b| (b.0 * (a.1 + 1)).cmp(&(a.0 * (b.1 + 1))));
    let m = 700;
    let mut dp = vec![t + 1; m + 1];
    dp[0] = 0;
    for (a, b) in q {
        for i in (1..(m + 1)).rev() {
            let t = dp[i - 1];
            dp[i] = std::cmp::min(dp[i], t + 1 + a * (t + 1) + b);
        }
    }
    zero.sort();
    let mut sum = zero.iter().fold(0, |s, a| s + *a);
    let mut ans = 0;
    for i in 0..(m + 1){
        while zero.len() > 0 && dp[i] + sum + zero.len() > t {
            sum -= zero.pop().unwrap();
        }
        if dp[i] + sum + zero.len() <= t {
            ans = std::cmp::max(ans, i + zero.len());
        }
    }
    println!("{}", ans);
}

fn main() {
    run();
}


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

using namespace std;
typedef  long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define  MP make_pair
#define  PB push_back
#define inf  1000000007
#define rep(i,n) for(int i=0;i<(int)(n);++i)

int main(){
	string s;
	cin >> s;
	int ans = 0;
	for(int i=0;i<s.size();i++){
		ans += s[i]-'0';
	}
	int ans2 = 0;
	ans2 = s[0]-'1'+9*(s.size()-1);
	cout << max(ans,ans2) << endl;
	return 0;
}

Measured memory_bytes: 256
using System;

public class Hello
{
    public static void Main()
    {
        
int S=int.Parse(Console.ReadLine());
int h,m,s;
 h=S/3600;
 m=(S%3600)/60;
 s=(S%3600)%60;
    
    Console.WriteLine("{0}:{1}:{2}",h,m,s);
    
    
    }
}



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

struct Graph {
	struct Edge {
		int from;
		int to;
		int dist;
	};

	struct State {
		State() : ts(0), node(1), edgeId(-1), delta(0) {}

		void stay() {
			cout << -1 << endl;
		}

		void move(int target) {
			// TODO: implement
		}

		void movePhysical(int target) {
		}

		// current timestamp
		int ts;

		// which node the car is currently on, if not on any edge
		int node;
		// detect which edge the car is on; -1 means it's staying at the source node	
		int edgeId;
		// the distance from the source, only apply when edgeId >= 0
		int delta;
	};

	void addEdge(int from, int to, int dist) {
		edges.push_back({from, to, dist});
	}

	int N;
	vector< Edge > edges;
	State state;
};

// For problem A, the orders are known in advance
struct OrderOffline {
	OrderOffline() {}

	OrderOffline(int Tmax_) : Tmax(Tmax_) {
		orders.resize(Tmax_ + 1);
	}

	struct Order {
		int orderId;
		int to;
	};

	void addOrder(int ts, int orderId, int to) {
		orders[ts].push_back({orderId, to});
	}

	int Tmax;
	vector< vector<Order> > orders;
};

Graph graph;
OrderOffline customer;

void readInput() {
	int n, m;
	scanf("%d %d", &n, &m);
	for (int i = 0; i < m; i++) {
		int from, to, dist;
		scanf("%d %d %d", &from, &to, &dist);
		graph.addEdge(from, to, dist);
	}

	int Tmax;
	scanf("%d", &Tmax);
	customer = OrderOffline(Tmax);
	for (int i = 1; i <= Tmax; i++) {
		int norders;
		scanf("%d", &norders);
		for (int j = 0; j < norders; j++) {
			int orderId, to;
			scanf("%d %d", &orderId, &to);
			customer.addOrder(i, orderId, to);
		}
	}
}

void naive() {
	for (int i = 1; i <= customer.Tmax; i++) {
		graph.state.stay();
	}
}

int main() {
	readInput();
	naive();
	return 0;
}

Measured memory_bytes: 640
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#define type 26

int constant(int day)//1~26 順番
{
  return day%type+1;
}
int get_random()//1~26 ランダム
{
  return rand()%type+1;
}
int max(int s[][type+1],int day)//その日の最大の満足度選ぶ
{
  int m,max_score=0,i;
  for(i=1;i<=type;i++)
  {
    if(s[day][i]>max_score){
      max_score=s[day][i];
      m=i;
    }
  }
  return m;
}
void cal(int select,int c[type+1],int last[type+1],int s[][type+1],int day,int sum[])
{
  int i;
  sum[day]=sum[day-1]+s[day][select];
  for(i=1;i<=type;i++){
    sum[day]-=c[i]*(day-last[i]);
  }
}
void change(int c[type+1],int last[type+1],int s[][type+1],int sum[],int schedul[],int D)
//ランダムに変更
{
  int d,t,old,total=0,i,j;
  d=rand()%D+1;
  t=rand()%type+1;
  old=schedul[d];
  schedul[d]=t;
  for(i=1;i<=type;i++) last[i]=0;
  for(i=1;i<=D;i++){
    total+=s[i][schedul[i]];
    last[schedul[i]]=i;
    for(j=1;j<=type;j++){
     total-=c[j]*(i-last[j]);
   }
  }
  if(total>sum[D]){
  //  printf("change\n");
    sum[D]=total;
  }
  else{
    schedul[d]=old;
  }
}
void cross(int c[type+1],int last[type+1],int s[][type+1],int sum[],int schedul[],int D)
//ランダムな２つ交換
{
  int a,b,old_a,old_b,flag=0,i,j,total=0;
  flag=rand()%2;
  a=rand()%D+1;
  if(flag==0){
    b=a+rand()%16+1;
    if(b>D) b=a-(rand()%16+1);
  }
  else{
    b=a-(rand()%16+1);
    if(b<1)   b=a+rand()%16+1;
  }
  old_a=schedul[a];
  old_b=schedul[b];
  schedul[a]=old_b;
  schedul[b]=old_a;
  for(i=1;i<=type;i++) last[i]=0;
  for(i=1;i<=D;i++){
    total+=s[i][schedul[i]];
    last[schedul[i]]=i;
    for(j=1;j<=type;j++){
     total-=c[j]*(i-last[j]);
   }
  }
  if(total>sum[D]){
    sum[D]=total;
  }
  else
  {
    schedul[a]=old_a;
    schedul[b]=old_b;
  }
}
int main(void)
{
  int D,c[type+1],i,j;
  clock_t start,stop;
  start=clock();
  srand((unsigned int)time(NULL));
  scanf("%d",&D);//D=365
  int s[D+1][type+1],last[type+1],sum[D+1],schedul[D+1];
  for(i=0;i<=D;i++) sum[i]=0;
  for(i=1;i<=type;i++) last[i]=0;
  for(i=1;i<=type;i++) scanf("%d",&c[i]);
  for(i=1;i<D+1;i++){
    for(j=1;j<=type;j++) scanf("%d",&s[i][j]);
  }
  for(i=1;i<D+1;i++){
    int select;
    select=constant(i);
    last[select]=i;
    schedul[i]=select;
    cal(select,c,last,s,i,sum);
    //printf("%d\n",sum[i]);
  }
  int count=0;
  stop=start;
  while((double)(stop - start) / CLOCKS_PER_SEC<1.988){
    int flag=rand()%2;
    if(flag==0) cross(c,last,s,sum,schedul,D);
    else change(c,last,s,sum,schedul,D);
    count++;
    stop=clock();
  }
/*
  printf("count:%d\n",count);
  printf("time:%f\n",(double)(stop - start) / CLOCKS_PER_SEC);
  printf("%d\n",sum[D]);
  printf("確認\n");
  int total=0;
  for(i=1;i<=type;i++) last[i]=0;
  for(i=1;i<=D;i++){
    total+=s[i][schedul[i]];
    last[schedul[i]]=i;
    for(j=1;j<=type;j++){
     total-=c[j]*(i-last[j]);
   }
  }
  printf("%d\n",total);
*/
  for(i=1;i<=D;i++) printf("%d\n",schedul[i]);
  return 0;
}


Measured memory_bytes: 1804
#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <functional>
#include <string>
#include <cstdlib>
#include <numeric>
#include <cstdbool>
#include <map> 
using namespace std;

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

const long long INF = 1LL << 60;
int main()
{
	int n;
	cin >> n;
	vector<int> v(100000, 0);
	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		v[a]++;
	}

	int ans = 0;
	for (int x = 1; x <= 100000; x++) {
		ans = max(ans, v[x - 1] + v[x] + v[x + 1]);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 640
#include <iostream>
using namespace std;
int main() {
	long long n, a, b, ans;
	cin >> n >> a >> b;
	if (a > b)ans = 0;
	else if (n == 1)ans = a != b ? 0 : 1;
	else ans = (b - a)*(n - 2) + 1;
	cout << ans << endl;
}

Measured memory_bytes: 256
import itertools as it

def c(n,k):
  if k>n:
    return 0
  ret = 1
  for i in range(n, n-k, -1):
    ret *= i
  for i in range(k, 1, -1):
    ret /= i
  return ret


n = int(input())
dic = {'M':0, 'A':0, 'R':0, 'C':0, 'H':0}
for person in range(n):
  name = input()
  if name[0] in 'MARCH':
    dic[name[0]] += 1

answer = 0
for a,b,c in it.combinations('MARCH', 3):
  answer += dic[a] * dic[b] * dic[c]
print(answer)


Measured memory_bytes: 3064
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#define llong long long
#define INF (__INT32_MAX__ / 2)
#define MAX_N 100

using namespace std;

int main(int argc, char **argv) {
    int n;
    char str[MAX_N + 1];
    scanf("%d", &n);
    scanf("%s", str);

    int red = 0, blue = 0;
    for(int i = 0; i < n; ++i)
        if(str[i] == 'R')
            ++red;
        else if(str[i] == 'B')
            ++blue;
    
    printf(red > blue ? "Yes\n" : "No\n");
}

Measured memory_bytes: 128
#include <stdio.h>
int main (){

  int n,a,b,c,i,j,result;

  scanf("%d",&n);

  for(i = 0; i < n; i++){

    result=0;
    scanf("%d %d %d",&a,&b,&c);

    while(a >= 1 && b >= 1 && c >= 1){

      result++;
      a--;
      b--;
      c--;

    }

    while(a >= 2 && b >= 1){

      result++;
      a -= 2;
      b--;

    }

    result += a/3;

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

  }

  return 0;

}

Measured memory_bytes: 2732
#include <bits/stdc++.h>
 
using namespace std;
 
int main(){
  int a,b;
   while(1){
  cin>>a>>b;
 
    if(a ==0 && b ==0)break;
  for(int i=0;i<a;i++){
    for(int j=0;j<b;j++){
      cout<<"#";
	}
	cout<<endl;
  }
  cout<<endl;
  }
  return 0;
}



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

int main(){
	int N;
	cin >> N;
	string S;
	cin >> S;
	if (S.size() % 2 == 0 && S.substr(0, N / 2) == S.substr(N / 2, N / 2)) puts("Yes");
	else puts("No");
	return 0;
}

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

int main()
{
	int N;
	cin >> N;
	int a[200000];
	long long int t_snk = 0, t_arai = 0;
	for (int i = 0; i < N; i++) {
		cin >> a[i];
	}

	t_snk = a[0];
	for (int i = 1; i < N; i++) {
		t_arai += a[i];
	}

	vector<long long int> diff;
	diff.push_back(abs(t_snk - t_arai));
	for (int i = 1; i < N-1; i++) {
		t_snk += a[i];
		t_arai -= a[i];
		diff.push_back(abs(t_snk - t_arai));
	}
	int min = *min_element(diff.begin(), diff.end());
	cout << min << endl;
	return 0;
}

Measured memory_bytes: 3188
#include<stdio.h>
#include<stdlib.h>
int min(int a,int b){
    return a<b?a:b;
}
int main()
{
    int n;
    scanf("%d",&n);
    int a[n],dp[n];
    for(int i=0;i<n;i++){scanf("%d",&a[i]);dp[i]=0;}
    dp[1]=abs(a[1]-a[0]);
    for(int i=2;i<n;i++)
    dp[i]=min((dp[i-1]+abs(a[i]-a[i-1])),(dp[i-2]+abs(a[i-2]-a[i])));
    printf("%d",dp[n-1]);
}


Measured memory_bytes: 2488
#from math import sqrt
#from heapq import heappush, heappop
#from collections import deque
#s, t = [int(v) for v in int(input())]


def main():
    k, x = map(int, input().split())

    if k * 500 >= x:
        print("Yes")
    else:
        print("No")


main()


Measured memory_bytes: 2940
#include <queue>
#include <cstdio>
#include <vector>
#include <algorithm>
#pragma warning(disable : 4996)
using namespace std;
struct edge {
	int to;
	long long cost;
	int tp;
};
bool operator<(const edge& e1, const edge& e2) {
	return e1.cost < e2.cost;
}
int W, H, N, x, y; long long dist[200009][2]; vector<pair<int, int> > xd[100009], yd[100009]; vector<edge> G[200009];
int main() {
	scanf("%d%d%d", &W, &H, &N);
	for (int i = 0; i < N; i++) {
		scanf("%d%d", &x, &y); x--, y--;
		xd[x].push_back(make_pair(y, i));
		yd[y].push_back(make_pair(x, i));
	}
	xd[0].push_back(make_pair(0, N));
	xd[W - 1].push_back(make_pair(H - 1, N + 1));
	yd[H - 1].push_back(make_pair(W - 1, N + 1));
	for (int i = 0; i < W; i++) {
		sort(xd[i].begin(), xd[i].end());
		for (int j = 1; j < xd[i].size(); j++) {
			int va = xd[i][j - 1].second, vb = xd[i][j].second, cost = xd[i][j].first - xd[i][j - 1].first;
			G[va].push_back(edge{ vb, cost, 0 });
			G[vb].push_back(edge{ va, cost, 0 });
		}
	}
	for (int i = 0; i < H; i++) {
		sort(yd[i].begin(), yd[i].end());
		for (int j = 1; j < yd[i].size(); j++) {
			int va = yd[i][j - 1].second, vb = yd[i][j].second, cost = yd[i][j].first - yd[i][j - 1].first;
			G[va].push_back(edge{ vb, cost, 1 });
			G[vb].push_back(edge{ va, cost, 1 });
		}
	}
	for (int i = 0; i < N + 2; i++) dist[i][0] = dist[i][1] = 1LL << 60; dist[N][0] = 0;
	priority_queue<edge> que; que.push(edge{ N, 0, 0 });
	while (!que.empty()) {
		edge u = que.top(); que.pop();
		for (edge e : G[u.to]) {
			long long cost = dist[u.to][u.tp] + e.cost + (u.tp != e.tp);
			if (dist[e.to][e.tp] > cost) {
				dist[e.to][e.tp] = cost;
				que.push(edge{ e.to, -cost, e.tp });
			}
		}
	}
	long long ret = min(dist[N + 1][0], dist[N + 1][1]);
	if (ret == 1LL << 60) ret = -1;
	printf("%lld\n", ret);
	return 0;
}

Measured memory_bytes: 46912
#include <iomanip>
#include <iostream>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int main(void) {
  ios::sync_with_stdio(false);
  int N, K;
  cin >> N >> K;
  int ans = 0;
  while (N) {
    ans++;
    N /= K;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = 1000000007;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

template<typename T>
vector<T> gen_v(size_t a) { return vector<T>(a); }
template<typename T, typename ...Ts>
auto gen_v(size_t a, Ts... ts) { return vector<decltype(gen_v<T>(ts...))>(a, gen_v<T>(ts...)); }
template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }
template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v) { for (auto &e : t) fill_v(e, v); }

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	vector<string> v = { "SUN","MON","TUE","WED","THU","FRI","SAT" };
	string s; cin >> s;
	rep(i, 0, v.size()) {
		if (s == v[i]) {
			cout << v.size() - i << endl;
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#[allow(unused_imports)]
use std::{io, cmp, str};

#[allow(dead_code)]
fn input() -> String {
    let mut s = String::new();
    io::stdin().read_line(&mut s).ok();
    return String::from(s.trim());
}

#[allow(dead_code)]
fn read<F: str::FromStr>(s: &str) -> F
    where F::Err: std::fmt::Debug
{
    return s.parse().expect(&format!("read \"{}\"", s));
}

fn main() {
    let n: i64 = read(&input());
    let mut acc: i64 = 0;
    let mut i: i64 = 1;
    while acc < n {
        acc += i;
        i += 1;
    }
    for j in 1..i {
        if j == acc - n {
            continue;
        }
        println!("{}", j);
    }
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
#define INF 1000000007
int main()
{
   int n,k;
   cin>>n>>k;
   int h[n+1];
   for(int i=1;i<=n;i++)
   cin>>h[i];
    vector< long long  > dp(n+1,INF);
    dp[1]=0;
    for(int i=2;i<=n;i++)
    for(int j=1;i>j&&j<=k;j++)
    dp[i]=min(dp[i],dp[i-j]+abs(h[i]-h[i-j]));
    cout<<dp[n];
    return 0;    
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
int main(){
	for (int i = 0; i < 10000; ++i)
	{
		int x,y;
		cin >> x >> y;
		if(x>y){
			cout << y << " " << x << endl;
		}
		else if(x<y){
			cout << x << " " << y << endl;
		}
		else if(x==0&&y==0){
			break;
		}
		else if(x==y&&x!=0){
			cout << x << " " << y << endl;
		}
		/* code */
	}
}


Measured memory_bytes: 3048
def rec_search(graph, visited=[1], current=1, sum=0)
  return 0 unless visited == visited.uniq
  return 1 if visited.size == $n
  vars = graph[current]
  vars.each do |v|
    visited_new = visited.dup
    sum += rec_search(graph, visited_new << v, v)
  end
  sum
end

$n, m = gets.split.map(&:to_i)
graph = Hash.new { |hash, key| hash[key] = [] }
m.times do
 a, b = gets.split.map(&:to_i)
 graph[a] << b
 graph[b] << a
end
p rec_search(graph)

Measured memory_bytes: 2172
#include<iostream>
#include<math.h>
#include<algorithm>
#include<stdint.h>
#include<vector>
#include<deque>
#include<stack>
#include<string>
#include<cstring>
#include<time.h>
#include<array>
#include<iomanip>
#include<list>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<random>
#include<bitset>
#include <queue>
#include <map>


using namespace std;
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using ldouble = long double;


//BDD,ZDD,kdtree, bdtree,bicalc, bolonoy, doloney,chinesemod,segmenttree,daikusutora, saidairyuu, 2bugurahu, heirokenshutu, topologicalsort, kyourenketuseibun


#define PRI(s) cout << s << endl
#define PRIY PRI("Yes")
#define PRIN PRI("No")


int main() {
	string s, t;
	cin >> s >> t;
	PRI(t + s);
	return 0;
}

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

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

    if(n <= 599){
        s = 8;
    }else if(n<=799){
        s = 7;
    }else if(n <= 999){
        s = 6;
    }else if(n <= 1199){
        s = 5;
    }else if(n <= 1399){
        s = 4;
    }else if(n <= 1599){
        s = 3;
    }else if(n <= 1799){
        s = 2;
    }else if(n <= 1999){
        s = 1;
    }

    cout << s << endl;
    return 0;
}

Measured memory_bytes: 3632
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<cstdio>
#include<vector>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define ll long long
#define inf 1000000000
#define MOD 1000000007
inline int read(){int x=0,f=1;char c=getchar();while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}return x*f;}
inline ll readl(){ll x=0,f=1;char c=getchar();while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}return x*f;}
template<class T>inline void print(T x){if(x/10!=0)print(x/10);putchar(x%10+'0');}
template<class T>inline void writeln(T x){if(x<0)putchar('-');x=abs(x);print(x);putchar('\n');}
template<class T>inline void write(T x){if(x<0)putchar('-');x=abs(x);print(x);}
inline ll power(ll a,ll b){ll ans=1;while(b){if(b&1){ans=ans*a%MOD;--b;}b>>=1;a=a*a%MOD;}return ans%MOD;}
/*================Header Template==============*/
int main(){
	string s;cin>>s;sort(s.begin(),s.end());
	puts((s=="abc")?"Yes":"No");
}


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

void turn(int *DICE,char com);

int main(void){
int i,j,q,top,front;
int DICE[6];
char com[105];
for(i=0;i<6;i++){scanf("%d",&DICE[i]);}
scanf("%d",&q);
for(j=0;j<q;j++){
	scanf("%d %d",&top,&front);
	strcpy(com,"SSSSESSSS");
	i=0;
	while(DICE[1]!=front){
		if(com[i]=='\0'){break;}
		turn(&DICE[0],com[i]);
		i++;
	}
	strcpy(com,"EEEE");
	i=0;
	while(DICE[0]!=top){
		if(com[i]=='\0'){break;}
		turn(&DICE[0],com[i]);
		i++;
	}
	printf("%d\n",DICE[2]);
}
return 0;
}

void turn(int *DICE,char com){
int temp;
switch(com){
	case 'N':
		temp     =*DICE;
		*DICE    =*(DICE+1);
		*(DICE+1)=*(DICE+5);
		*(DICE+5)=*(DICE+4);
		*(DICE+4)=temp;
		break;
	case 'S':
		temp     =*DICE;
		*DICE    =*(DICE+4);
		*(DICE+4)=*(DICE+5);
		*(DICE+5)=*(DICE+1);
		*(DICE+1)=temp;
		break;
	case 'E':
		temp     =*DICE;
		*DICE    =*(DICE+3);
		*(DICE+3)=*(DICE+5);
		*(DICE+5)=*(DICE+2);
		*(DICE+2)=temp;
		break;
	case 'W':
		temp     =*DICE;
		*DICE    =*(DICE+2);
		*(DICE+2)=*(DICE+5);
		*(DICE+5)=*(DICE+3);
		*(DICE+3)=temp;
		break;
	}
}

Measured memory_bytes: 596
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <numeric>
#include <queue>
using namespace std;
typedef long long ll;

ll f(ll f3,ll f5,ll f7, ll val, ll n){
    ll sum=0;
    if(val>n)return 0;
    if(f3&&f5&&f7)sum++;
    sum+=f(f3+1,f5,f7,val*10+3,n);
     sum+=f(f3,f5+1,f7,val*10+5,n);
      sum+=f(f3,f5,f7+1,val*10+7,n);
      return sum;
}

int main(){
  int n;cin>>n;
  vector<int> v(n);
  for(int i=0;i<n;i++)cin>>v[i];
  int x=*max_element(v.begin(),v.end());
  cout<<accumulate(v.begin(),v.end(),-x/2);
}

Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
using ll = int64_t;

int main() {
    ll N, x;
    cin >> N >> x;
    if (x == 1 || x == 2 * N - 1) {
        cout << "No" << endl;
        return 0;
    }

    vector<ll> ans(2 * N - 1);
    ans[N - 1] = x;
    ll num = 1;
    for (ll i = N - 2; i >= 0; i--) {
        ans[i] = num++;
        if (num == x) {
            num++;
        }
    }
    num = 2 * N - 1;
    for (ll i = N; i < 2 * N - 1; i++) {
        ans[i] = num--;
        if (num == x) {
            num--;
        }
    }

    cout << "Yes" << endl;
    for (ll i = 0; i < 2 * N - 1; i++) {
        cout << ans[i] << endl;
    }
}

Measured memory_bytes: 3072
N=int(input())
S=input()
ans,r,g,b=0,0,0,0
for s in S:
  if s=='R':
    r+=1
  elif s=='G':
    g+=1
  elif s=='B':
    b+=1
ans=r*g*b
for i in range(N-2):
  a=S[i]
  for j in range(i+1,N-1):
    if 2*j-i>=N:
      break
    b,c=S[j],S[j+j-i]
    if a!=b and b!=c and c!=a:
      ans-=1
print(ans)

Measured memory_bytes: 73596
#include <climits>
#include <iostream>
#include <vector>
#include <array>
#include <algorithm>

using namespace std;

int main() {
  int n, w;
  cin >> n >> w;
  vector<long> weight(n);
  vector<long> value(n);

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

  long dp[n+1][w+1];

  for (int i=0; i<=w; i++) dp[0][i] = 0;

  for (int i=0; i<n; i++) {
    for (int j=0; j<=w; j++) {
      if (j >= weight[i]) {
        dp[i+1][j] = max(dp[i][j - weight[i]] + value[i], dp[i][j]);
      } else {
        dp[i+1][j] = dp[i][j];
      }
    }  
  }

  cout << dp[n][w] << endl;

  return 0;
}

Measured memory_bytes: 79104
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;
int main()
{
    vector<int> N(3);
    cin >> N[0] >> N[1] >> N[2];

    sort(all(N));
    reverse(all(N));

    int ans = N[0] - N[1];
    N[2] += (N[0] - N[1]);

    if (N[0] != N[2]) {
        ans += (N[0] - N[2]) / 2;
        if ((N[0] - N[2]) % 2 == 1) {
            ans += 2;
        }
    }

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for (int i=0; i < n; i++)
#define repd(i, n) for (int i = n-1; i > -1; i--)
#define repran(i, a,b) for (int i = a; i<b;i++)
typedef long long ll;
using namespace std;
const int MAX_R = 3010, MAX_C=3010;
ll item[MAX_R][MAX_C], dp[MAX_R][MAX_C][4];
int main()
{
    int r, c, k;
    cin >> r >> c >> k;
    rep(i, r+1)rep(j, c+1) {
        item[i][j] = 0;
        rep(v, 4) dp[i][j][v] = 0;
    }
    rep(i, k){
        int a, b;
        ll c;
        cin >> a >> b >> c;
        item[a][b] = c;
    }
    repran(i, 1, r+1) repran(j, 1, c+1){
        rep(v, 4){
            dp[i][j][v] = max(dp[i][j-1][v], dp[i-1][j][3]);
        }
        if (item[i][j] > 0){
            repd(v, 3){
                dp[i][j][v+1] = max(dp[i][j][v+1], dp[i][j][v]+item[i][j]);
            }
        }
    }
    cout << dp[r][c][3] << endl;
}

Measured memory_bytes: 356412
import sys
from collections import *
import heapq
import math
import bisect
from itertools import permutations,accumulate,combinations,product
from fractions import gcd
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
mod=pow(10,9)+7

n,p=map(int,input().split())
s=input()

ans=0

if p==2 or p==5:
    for i in range(n):
        if int(s[i])%p==0:
            ans+=i+1
else:
    lst=[0]*(n+1)
    for i in range(n):
        lst[-2-i]=(lst[-1-i]+int(s[-1-i])*pow(10,i,p))%p
    # print(lst)
    cnt=Counter(lst)
    for i in range(n):
        cnt[lst[i]]-=1
        ans+=cnt[(lst[i]-p)%p]
        # cnt[lst[i]]-=1
    #     print(ans)
    # print(cnt)
print(ans)

Measured memory_bytes: 80880
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
int main()
{
	ll n;
	cin>>n;
	vector<pair<ll,ll> > v;
	ll zbir=0;
	for(int i=0;i<n;i++)
	{
		ll a;
		cin>>a;
		zbir+=a;
		v.push_back(make_pair(a,-i));
	}
	sort(v.begin(),v.end());
	reverse(v.begin(),v.end());
	vector<ll> kraj(n+1,0);
	ll brojac=0;
	ll posledno=v[0].first;
	ll krug=0;
	ll zzbir=0;
	ll ind=n;
	for(ll i=0;i<n;i++)
	{
		brojac+=((posledno-v[i].first)*i);
		posledno=v[i].first;
		if(v[i].second==0)
		{
			kraj[krug]=brojac;
			kraj[0]=zbir-zzbir-brojac;
			break;
		}
		if(ind>-v[i].second)
		{
			if(i)
				kraj[krug]=brojac;
			ind=-v[i].second;
			krug=-v[i].second;
			zzbir+=brojac;
			brojac=0;
		}
	}
	for(int i=0;i<n;i++)
		cout<<kraj[i]<<endl;
	return 0;
}

Measured memory_bytes: 3440
l,r=map(int,input().split())
x=[]
if r-l>=2018:
    print(0)
else:
    ans=2018
    for i in range(l,r):
        for j in range(i+1,r+1):
            k=(i*j)%2019
            ans=min(k,ans)
    print(ans)

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

int main(){
    string s;
    cin >> s;

    if(s=="ABC"){
        cout << "ARC" <<endl;
    }else{
        cout << "ABC" <<endl;
    }

    return 0;
}

Measured memory_bytes: 3596
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_7_C
// Tree - Tree Walk

#define SUBMIT

#include <utility>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <vector>
#include <limits>
#include <numeric>
#include <functional>
#include <set>
#include <cmath>
#include <cstring>
#include <climits>

using namespace std;
using ui64 = unsigned long long;
using i64 = long long;

const int NIL = -1;
const int MAX_T = 100000;

struct node { int parent, left, right; };
struct node T[MAX_T];

void print_preorder(int root) {
    cout << "Preorder" << endl;

    function<void(int)> print_loop = [&print_loop](int u) {
        cout << " " << u;
        if (T[u].left != NIL) print_loop(T[u].left);
        if (T[u].right != NIL) print_loop(T[u].right);
    };

    print_loop(root);
    cout << endl;
}

void print_inorder(int root) {
    cout << "Inorder" << endl;

    function<void(int)> print_loop = [&print_loop](int u) {
        if (T[u].left != NIL) print_loop(T[u].left);
        cout << " " << u;
        if (T[u].right != NIL) print_loop(T[u].right);
    };

    print_loop(root);
    cout << endl;
}

void print_postorder(int root) {
    cout << "Postorder" << endl;

    function<void(int)> print_loop = [&print_loop](int u) {
        if (T[u].left != NIL) print_loop(T[u].left);
        if (T[u].right != NIL) print_loop(T[u].right);
        cout << " " << u;
    };

    print_loop(root);
    cout << endl;
}


int main() {
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) T[i].parent = NIL, T[i].left = NIL, T[i].right = NIL;

    int id, left, right;
    for (int i = 0; i < n; ++i) {
        cin >> id >> left >> right;
        T[id].left = left;
        T[id].right = right;
        if (left != NIL) T[left].parent = id;
        if (right != NIL) T[right].parent = id;
    }

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

    print_preorder(root);
    print_inorder(root);
    print_postorder(root);
    return 0;
}


Measured memory_bytes: 3080
#include <stdio.h>

int main(void){
  int A,B,C;
  scanf("%d %d %d", &A,&B,&C);
  if(A==B || B==C || A==C){
    if(A==B && B==C)
      printf("No");
    else
      printf("Yes");
  } else {
    printf("No");
  }
  return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
using namespace std;
const int Mod=1000000007;
const int inv2=500000004;
int n,q;
int f[3010][3010];
int a[3010];
int main()
{
	scanf("%d %d",&n,&q);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			f[i][j]=(a[i]>a[j]);
	for(int i=1;i<=q;i++)
	{
		int x,y;
		scanf("%d %d",&x,&y);
		f[x][y]=f[y][x]=1ll*(f[x][y]+f[y][x])*inv2%Mod;
		for(int i=1;i<=n;i++)
			if(i!=x&&i!=y)f[x][i]=f[y][i]=1ll*(f[x][i]+f[y][i])*inv2%Mod;
		for(int i=1;i<=n;i++)
			if(i!=x&&i!=y)f[i][x]=f[i][y]=1ll*(f[i][x]+f[i][y])*inv2%Mod;
	}
	int ans=0;
	int mul=1;
	for(int i=1;i<=q;i++)
		mul=(mul<<1)%Mod;
	for(int i=1;i<n;i++)
		for(int j=i+1;j<=n;j++)
			ans=(ans+f[i][j])%Mod;
	printf("%d\n",1ll*ans*mul%Mod);
	return 0;
}

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

#define MAX 100000
int main()
{
    int n;
    cin >> n;

    int d[MAX];
    for (int i = 0; i < MAX; i++) {
      d[i] = 0;
    }
    int tmp;
    for (int i = 0; i < n; i++) {
      cin >> tmp;
      d[tmp-1]++;
    }
    int count = 0;
    int min = 0;
    int max = 0;
    for (int i = 0; i < MAX; i++) {
      count += d[i];
      if (min == 0 && count == n/2) {
        min = i + 1;
      } else if (count > n/2) {
        if (min > 0) {
	        max = i + 1;
        }
        break;
      }
    }
    cout << max - min << endl;
    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <stack>
#include <queue>

#define FOR(i, b, e) for(ll i = (ll)(b); i < (ll)(e); ++i)
#define RFOR(i, b, e) for(ll i = (ll)(e-1); i >= (ll)(b); --i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define REPC(x,c) for(const auto& x:(c))
#define VS vector<string>
#define VL vector<long long>
#define VI vector<int>
#define VVI vector<vector<int>>
#define VVL vector<vector<ll>>
#define ALL(x) (x).begin(),(x).end()
#define SORT(x) sort(ALL(x))
#define RSORT(x) sort((x).rbegin(),(x).rend())
#define PAIR pair<ll,ll>
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

using  ll = long long;
constexpr ll MOD = 1000000007;
using std::cout;
using std::endl;
using std::cin;
using std::sort;
using std::pair;
using std::string;
using std::stack;
using std::queue;
using std::vector;
using std::list;
using std::map;
using std::unordered_map;
using std::multimap;
using std::unordered_multimap;
using std::set;
using std::unordered_set;
using std::multiset;

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll pow(ll a, ll b) {
	ll ans = 1;
	while (b > 0) {
		if (b % 2 == 1) {
			ans *= a;
			ans %= MOD;
		}
		b /= 2;
		a *= a;
		a %= MOD;
	}
	return ans;
}
ll comb(ll a, ll b) {
	if (a - b < b) { return comb(a, a - b); }
	static unordered_map<ll, ll> memo;

	ll c = 1;
	FOR(i, a - b + 1, a + 1) {
		c *= i;
		c %= MOD;
	}
	if (memo.find(b) == memo.end()) {
		ll k = 1;
		FOR(i, 2, b + 1) {
			k *= i;
			k %= MOD;
		}
		memo[b] = pow(k, MOD - 2);
	}
	c *= memo[b];
	return c % MOD;
}
multiset<ll> prime_decomposition(ll n) {
	ll i = 2;
	multiset<ll> table{};
	while (i * i <= n) {
		while (n % i == 0) {
			n /= i;
			table.emplace(i);
		}
		++i;
	}
	if (n > 1) {
		table.emplace(n);
		return table;
	}
	return table;
}
/*
-- bit --
REP(i, (1 << n)) {
	REP(j, n) {
		cout << (1 & (i >> j));
	}
	cout << endl;
}
*/

int main() {
	ll h, w, d;
	cin >> h >> w >> d;
	unordered_map<ll, PAIR> pos;

	REP(i, h) {
		REP(j, w) {
			ll t;
			cin >> t;
			pos.emplace(t, PAIR{ i,j });
		}
	}

	VL dp(h*w);
	REP(i, d) {
		dp[i] = 0;
	}
	FOR(i, d, h*w) {
		dp[i] = dp[i - d] +
			abs(pos[i + 1].first - pos[i - d + 1].first) +
			abs(pos[i + 1].second - pos[i - d + 1].second);
	}
	
	ll q;
	cin >> q;
	REP(i, q) {
		ll l, r;
		cin >> l >> r;
		cout << dp[r - 1] - dp[l - 1] << endl;
	}

}

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

#define ll long long int

using namespace std;

int main() {
    vector<ll> X(5);
    for (auto & x: X) cin >> x;
    for (ll i = 0; i < 5; ++i) {
        if (X[i] == 0) {
            cout << i+1 << endl;
        }
    }
}


Measured memory_bytes: 3624
import math

def kochCurve(n,p1x,p1y,p2x,p2y):
	if n == 0:
		return
	
	qx = 2*p1x/3 + p2x/3
	qy = 2*p1y/3 + p2y/3

	rx = 2*p2x/3 + p1x/3
	ry = 2*p2y/3 + p1y/3

	s1x = rx-qx
	s1y = ry-qy

	s2x = s1x*math.cos(math.pi/3)-s1y*math.sin(math.pi/3)
	s2y = s1x*math.sin(math.pi/3)+s1y*math.cos(math.pi/3)

	s3x = s2x+qx
	s3y = s2y+qy

	kochCurve(n-1,p1x,p1y,qx,qy)
	print(qx,qy)
	kochCurve(n-1,qx,qy,s3x,s3y)
	print(s3x,s3y)
	kochCurve(n-1,s3x,s3y,rx,ry)
	print(rx,ry)
	kochCurve(n-1,rx,ry,p2x,p2y)

if __name__ == '__main__':
	n = (int)(input())
	print(0,0)
	kochCurve(n,0,0,100,0)
	print(100,0)

	

Measured memory_bytes: 8032
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int m = sc.nextInt();
		int n = sc.nextInt();

		if (m <= 5) {
			System.out.println(0);
		} else if (m < 13) {
			System.out.println(n / 2);
		} else {
			System.out.println(n);
		}
	}
}

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

int main() {
    int h, w; cin >> h >> w;
    vector<string> s(h);
    for (auto &e: s) cin >> e;
    vector<vector<int>> ans(h, vector<int>(w, 0));
    for (int i = 0; i < h; i++) for (int j = 0, k = 0; j < w; j++) {
        if (s[i][j] == '#') k = 0;
        else ans[i][j] += k, k++;
    }
    for (int i = 0; i < h; i++) for (int j = w - 1, k = 0; j >= 0; j--) {
        if (s[i][j] == '#') k = 0;
        else ans[i][j] += k, k++;
    }
    for (int j = 0; j < w; j++) for (int i = 0, k = 0; i < h; i++) {
        if (s[i][j] == '#') k = 0;
        else ans[i][j] += k, k++;
    }
    for (int j = 0; j < w; j++) for (int i = h - 1, k = 0; i >= 0; i--) {
        if (s[i][j] == '#') k = 0;
        else ans[i][j] += k, k++;
    }
    int ma = 0;
    for (int i = 0; i < h; i++) for (int j = 0; j < w; j++) {
        ma = max(ma, ans[i][j] + (s[i][j] == '.'));
    }
    cout << ma << endl;
    return 0;
}

Measured memory_bytes: 20096
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#include <set>
#include <map>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;

int main(){
  int a,b; cin >> a >> b;
  int ans = a+a-1;
  ans = max(ans,a+b);
  ans = max(ans,b+b-1);
  cout << ans << endl;
  return 0;
}


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

#define ll long long

signed main()
{
  string a,b,c;
  cin >> a >> b >> c;
  char dif = 'A'-'a';
  printf("%c%c%c\n", a[0]+dif, b[0]+dif, c[0]+dif);
}

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

int main()
{
	int n;

	std::cin >> n;

	std::vector<long long> v(n), div2(n);

	for (size_t i = 0; i < n; i++)
	{
		std::cin >> v[i];

		while (v[i] % 2 == 0) {
			v[i] /= 2;
			div2[i]++;
		}
	}

	std::cout << *std::min_element(div2.begin(), div2.end()) << std::endl;



	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
using namespace std;
#define N (1000000000+7)
typedef pair<int,int> P;
typedef long long ll;

int h,w;
int board[60][60];
bool check(int i,int j){
    return (i>=1)&&(i<=h)&&(j>=1)&&(j<=w)&&(board[i][j]==1);
}

void dfs(int i,int j){
    if(check(i,j)){
        board[i][j]=-1;
        for(int x=i-1;x<=i+1;++x){
            for(int y=j-1;y<=j+1;++y){
                dfs(x,y);
            }
        }
    }
    else return;
}

int main(void){
    while(true){
        cin>>w>>h;
        int sx=0,sy=0;
        int ans=0;
        if((h==0)&&(w==0))break;
        for(int i=1;i<=h;i++){
            for(int j=1;j<=w;j++){
                cin>>board[i][j];
            }
        }
        for(int i=1;i<=h;i++){
            for(int j=1;j<=w;j++){
                if(board[i][j]==1){
                    dfs(i,j);
                    ans++;
                }
            }
        }
        cout<<ans<<endl;
    }

    return 0;
}


Measured memory_bytes: 3124
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<queue>
#include<stack>
using namespace std;
using ll = long long;

int main(){
int N;
string S, T;
string ans;
cin >> N >> S >> T;
for(int i = 0;i < N;i++){
    ans += S[i];
    ans += T[i];
}
cout << ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define x first
#define y second
#define pii pair<int,int>
#define pb push_back
#define eb emplace_back
#pragma GCC optimize("unroll-loops")

using namespace std;
using namespace __gnu_pbds;

typedef long long int ll;
typedef unsigned long long int ull;
int MOD=1000000007;
int MOD2=998244353;
vector<int> bases;
const ll LLINF=1ll<<60;
const char en='\n';

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void yes() {cout<<"YES"<<en; exit(0);}
void no() {cout<<"NO"<<en; exit(0);}
inline int rund() {int x576363482791fuweh=rng();return abs(x576363482791fuweh)%RAND_MAX;}
template<class T>
void prVec(vector<T> w)
{
	cout<<w.size()<<endl;
	for (int i=0;i<int(w.size())-1;++i) cout<<w[i]<<' ';
	if (w.size()) cout<<w[w.size()-1]<<endl;
}

void M998()
{
	swap(MOD,MOD2);
}

ll raand()
{
	ll a=rund();
	a*=RAND_MAX;
	a+=rund();
    return a;
}

#define rand raand

ll raaand()
{
	return raand()*(MOD-7)+raand();
}

string to_upper(string a)
{
	for (int i=0;i<(int)a.size();++i) if (a[i]>='a' && a[i]<='z') a[i]-='a'-'A';
	return a;
}

string to_lower(string a)
{
	for (int i=0;i<(int)a.size();++i) if (a[i]>='A' && a[i]<='Z') a[i]+='a'-'A';
	return a;
}

ll sti(string a)
{
	ll k=0;
	for (int i=0;i<(int)a.size();++i)
	{
		k*=10;
		k+=a[i]-'0';
	}
	return k;
}

string its(ll k)
{
	if (k==0) return "0";
	string a;
	while (k)
	{
		a.push_back((k%10)+'0');
		k/=10;
	}
	reverse(a.begin(),a.end());
	return a;
}

ll min(ll a,int b)
{
	if (a<b) return a;
	return b;
}

ll min(int a,ll b)
{
	if (a<b) return a;
	return b;
}

ll max(ll a,int b)
{
	if (a>b) return a;
	return b;
}

ll max(int a,ll b)
{
	if (a>b) return a;
	return b;
}

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

ll lcm(ll a,ll b)
{
	return a/gcd(a,b)*b;
}

template<class T,class K>
pair<T,K> mp(T a,K b)
{
	return make_pair(a,b);
}

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

inline int pot(int n,int k)
{
	if (k==0) return 1;
	ll a=pot(n,k/2);
	a=mult(a,a);
	if (k%2) return mult(a,n);
	else return a;
}

int divide(int a,int b)
{
	return mult(a,pot(b,MOD-2));
}

inline int sub(int a,int b)
{
	if (a-b>=0) return a-b;
	return a-b+MOD;
}

inline int add(int a,int b)
{
	if (a+b>=MOD) return a+b-MOD;
	return a+b;
}

bool prime(ll a)
{
	if (a==1) return 0;
	for (int i=2;i<=round(sqrt(a));++i)
	{
		if (a%i==0) return 0;
	}
	return 1;
}

ll has(string x)
{
	ll h1=0,h2=0;
	x=to_lower(x);
	for (char a: x)
	{
		h1*=bases[0];
		h1+=a-'a';
		h1%=bases[3];
		h2*=bases[1];
		h2+=a-'a';
		h2%=bases[4];
	}
	return h1*(MOD+13893829)+h2;
}

const int N=300010;
int n,h[N],a[N];
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	for (int i=0;i<10;++i) bases.push_back(rand()%(MOD-13893829)+13893829);
	cin>>n;
	for (int i=1;i<=n;++i) cin>>h[i];
	vector<int> v;
	for (int i=n;i>=1;--i)
    {
        int x=0;
        for (int j=i;j<=n;j+=i) x^=a[j];
        a[i]=h[i]^x;
        if (a[i]) v.pb(i);
    }
    reverse(v.begin(),v.end());
    prVec(v);
}




Measured memory_bytes: 3704
#include <bits/stdc++.h>
        using namespace std;
   #define int long long
const int MAX =2000007;
const int MOD = 998244353;
//

     signed main(){
        int a,ans=0;
        cin>>a;
        cout<<a+a*a+a*a*a<<endl;
       

     }


 


 






    





      

        


Measured memory_bytes: 3608