akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<set>
#include <cstdio>
#include<vector>
#include<algorithm>

using namespace std;
	int n;

int main(){
    cin>>n;
    vector<int > a(n+1);
    for(int i=0; i<n; i++){
	scanf("%d", &a[i+1]);
    }
    int res=0;
    for(int i=1; i<=n; i++){
	if(a[i]>i){
	    if(a[a[i]]==i)res++;
	}
    }
    cout<<res;
    
}

Measured memory_bytes: 640
N = int(input())
A = list(map(int, input().split()))

def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a%b)

L = [0] * (N+1)
R = [0] * (N+1)
for i in range(1, N+1):
    L[i] = gcd(L[i-1], A[i-1])
for i in range(N)[::-1]:
    R[i] = gcd(R[i+1], A[i])

M = [gcd(L[i], R[i+1]) for i in range(N)]

print(max(M))

Measured memory_bytes: 14076
n = int(input()) 

cnt = [[0] * 10 for i in range(10)]

for i in range(n+1):
    a = int(str(i)[0])
    b = int(str(i)[-1])
    if a == 0 or b == 0:
        continue
    cnt[a][b] += 1

ans = 0
for i in range(n+1):
    a = int(str(i)[0])
    b = int(str(i)[-1])
    ans += cnt[b][a]
print(ans)

Measured memory_bytes: 67932
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
/////////////////// TYPES & MACROS ///////////////////////////////
#define INFLL 0x3fffffffffffffffLL
#define INF 0x3fffffff
#define mp make_pair
#define eb emplace_back
#define pb push_back
#define all(x) x.begin(),x.end()
#define exist(s,e) (s.find(e)!=s.end())
#define ff first
#define ss second
#define EPS 1e7
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef tree<int,null_type,less<int>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;
const ll MOD=1e9+7;
/////////////////// DEBUG MODE ///////////////////////////////////
#define D(x) cerr<<"DEBUG: "<<#x<<" is: "<<x<<'\n'
#define error(args...) {string _s=#args; replace(all(_s),',',' ');\
stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args);}
void err(istream_iterator<string>) { cout<<endl;}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}
/////////////////// GLOBAL VARIABLES /////////////////////////////
vector<vector<int>> adj; vector<bool> vis; vector<int> color;
/////////////////// FUNCTIONS ////////////////////////////////////
template<class T>
T maxx(T a, T b) {return a>b?a:b;}
template<typename T, typename... Args>
T maxx(T a, T b, Args... args){return maxx(a>b?a:b, args...);}
ll mexp(ll x, ll n, ull m){
  ll res=1;  while(n){if(n&1) res=(res*x)%m;n>>=1; x=((x%m)*(x%m))%m;}
  return res;
}
template<class T>
T minn(T a, T b) {return a<b?a:b;}
template<typename T, typename... Args>
T minn(T a, T b, Args... args){return minn(a>b?a:b, args...);}
bool ispow2(ll x){ return x && (!(x&(x-1))); }
ld pow(ld a, int n) {
  if(n == 0) return 1;if(n == 1) return a;
  double t = pow(a, n/2);return t * t * pow(a, n%2);
}

/////////////////// MAIN STARTS //////////////////////////////////
int main(){
  ios::sync_with_stdio(0);  cin.tie(0);   cout<<fixed; cerr<<fixed;
  cout<<setprecision(10); cerr<<setprecision(3);
  #ifdef DEBUG
  freopen("ip.txt","r",stdin); //freopen("op.txt","w",stdout);
  clock_t tStart = clock();
  #endif

	ll x,a,b; cin>>x>>a>>b;
	x-=a;
	cout<<x%b<<'\n';


	#ifdef DEBUG
	cerr<<"\nExecution time: "<<(((double)clock() - tStart)/CLOCKS_PER_SEC)*1000<<"ms.\n";
	#endif
  return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) {
        FastReader input = new FastReader();
        int a = input.nextInt();
        int b= input.nextInt();
        System.out.println(a * b);
    }
    static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
}


Measured memory_bytes: 32536
#![allow(non_snake_case)]

#[allow(unused_macros)]
macro_rules! input { (source = $s:expr, $($r:tt)*) => { let mut iter = $s.split_whitespace(); let mut next = || { iter.next().unwrap() }; input_inner!{next, $($r)*} }; ($($r:tt)*) => { let stdin = std::io::stdin(); let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock())); let mut next = move || -> String{ bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect() }; input_inner!{next, $($r)*} }; }
macro_rules! input_inner { ($next:expr) => {}; ($next:expr, ) => {}; ($next:expr, $var:ident : $t:tt $($r:tt)*) => { let $var = read_value!($next, $t); input_inner!{$next $($r)*} };}
macro_rules! read_value { ($next:expr, ( $($t:tt),* )) => { ( $(read_value!($next, $t)),* ) }; ($next:expr, [ $t:tt ; $len:expr ]) => { (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>() }; ($next:expr, chars) => { read_value!($next, String).chars().collect::<Vec<char>>() }; ($next:expr, bytes) => { read_value!($next, String).into_bytes() }; ($next:expr, usize1) => { read_value!($next, usize) - 1 }; ($next:expr, $t:ty) => { $next().parse::<$t>().expect("Parse error") }; }

fn main() {
    input!{
        _k: isize,
        t: isize,
        As:[isize;t],
    }
    let mut As = As;
    As.sort();
    let last = As.pop().unwrap();
    As.push(0);
    let cake_sum: isize = As.iter().sum();

    println!("{}", std::cmp::max(last - cake_sum - 1, 0));
}

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

using namespace std;

const int N = 2345;

int n, root, size[N], foo[N], bar[N];
vector<int> adj[N];
string s;

void dfs(int x, int f) {
  size[x] = s[x - 1] == '1';
  foo[x] = bar[x] = 0;
  int max_son = 0;
  for (auto y : adj[x]) {
    if (y != f) {
      dfs(y, x);
      size[x] += size[y];
      foo[x] += foo[y];
      if (foo[y] > foo[max_son]) {
        max_son = y;
      }
    }
  }
  bar[x] = max(0, bar[max_son] - foo[x] + foo[max_son]);
  if (x != root) {
    foo[x] += size[x];
    bar[x] += size[x];
  }
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> s;
  for (int i = 1, x, y; i < n; ++i) {
    cin >> x >> y;
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  int answer = n * n;
  for (root = 1; root <= n; ++root) {
    dfs(root, 0);
    if (!bar[root] && !(foo[root] & 1)) {
      answer = min(answer, foo[root] >> 1);
    }
  }
  cout << (answer == n * n ? -1 : answer) << '\n';
  return 0;
}

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

vector<pair<char, ll>> RLE(const string &S) {
    ll cnt = 0;
    vector<pair<char, ll>> res;
    for (ll i = 0; i < (ll) S.size(); i++) {
        cnt++;
        if (i == (ll) S.size() - 1) {
            res.emplace_back(S[i], cnt);
            break;
        }
        if (S[i] != S[i + 1]) {
            res.emplace_back(S[i], cnt);
            cnt = 0;
        }
    }
    return res;
}

void Main() {
    int N;
    cin >> N;
    string S;
    cin >> S;
    auto res = RLE(S);
    cout << res.size() << '\n';

}

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


Measured memory_bytes: 2500
#include <stdio.h>

#define MAX_N 100

int bubble_sort(int* as, int n) {
  int flag = 1;
  int tmp = 0;
  int swapped_num = 0;
  while(flag) {
    flag = 0;
    for(int j=n-1; j>0; j--) {
      if (as[j] < as[j-1]) {
        tmp = as[j];
        as[j] = as[j-1];
        as[j-1] = tmp;
        swapped_num++;
        flag = 1;
      }
    }
  }
  return swapped_num;
}

int main() {
  int n;
  int a[MAX_N];
  scanf("%d", &n);
  for(int i=0; i<n; i++) {
    scanf("%d", &a[i]);
  }

  int swapped_num = bubble_sort(a, n);

  for(int i=0; i<n; i++) {
    printf("%d", a[i]);
    if(i != n-1) {
      printf(" ");
    }
  }

  printf("\n%d\n", swapped_num);
}

Measured memory_bytes: 2724
//disco2019_d.cpp
//Sat Nov 23 20:40:33 2019

#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 2147483647
#define LLINF 9223372036854775807
using namespace std;
using ll=long long;
typedef pair<int,int> P;


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

	ll ans = 0;
	ll D = 0;
	ll s = 0;
	for (int i=0;i<m;i++){
		ll d,c;
		cin >> d >> c;
		D += c;
		s += c*d;
	}

	cout << D-1+(ll)(s-1)/9 << endl;
//	printf("%.4f\n",ans);
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import numpy as np
iH, iW = map(int, input().split())
naAll = np.zeros((iH+2, iW+2), dtype=int) - 1
#0123:udlr
iID0 = 0
for iH0 in range(iH):
  s = input()
  for i, s0 in enumerate(s):
    if s0 == ".":
      naAll[iH0+1, i+1] = iID0
      iID0 += 1
lMaze = [[] for _ in range(iID0)]
#lPoss = []
for iH0 in range(iH):
  for iW0 in range(iW):
    if naAll[iH0+1, iW0+1] >= 0:
      iID = naAll[iH0 + 1, iW0 + 1]
      if naAll[iH0 + 2, iW0 + 1] >= 0:
        lMaze[iID].append(naAll[iH0 + 2, iW0 + 1])
      if naAll[iH0 + 1, iW0 + 2] >= 0:
        lMaze[iID].append(naAll[iH0 + 1, iW0 + 2])
      if naAll[iH0    , iW0 + 1] >= 0:
        lMaze[iID].append(naAll[iH0    , iW0 + 1])
      if naAll[iH0 + 1, iW0    ] >= 0:
        lMaze[iID].append(naAll[iH0 + 1, iW0    ])
      #if not( (naAll[iH0 + 2, iW0 + 1] >= 0 and \
      #         naAll[iH0    , iW0 + 1] >= 0) or
      #        (naAll[iH0 + 1, iW0 + 2] >= 0 and \
      #         naAll[iH0 + 1, iW0    ] >= 0) ):
      #  lPoss.append(iID)
      #print(iID, lMaze)
lMax = []
for iID in range(iID0):
  lState = [0]*iID0
  lState[iID] = 1
  lMazeNow = [lMaze[iID]]
  iPre        = 1
  iTime       = 0
  while iPre < iID0:
    lMazeNow0 = []
    for lMazeNext in lMazeNow :
      for iIDnext in lMazeNext:
        if lState[iIDnext] == 0:
          lState[iIDnext] = 1
          iPre += 1
          lMazeNow0.append(lMaze[iIDnext])
    lMazeNow = lMazeNow0
    iTime += 1
    #print(iID, iTime, lState)
  lMax.append(iTime)
print(max(lMax))
#print(lMaze)
#print(naAll)

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

#define int long long
#define pb push_back
#define mp make_pair
#define f(i,a,n) for(int i=a ; i<n ; i++)
#define all(c) (c).begin(),(c).end()
#define F first
#define S second
#define fast ios:: sync_with_stdio(false),cin.tie(nullptr);
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef vector<pii> vpi;

const int inf = 1e9;
const int inf64 = 1e18;
const int MOD = inf + 7;
const ld PI = acos(-1.0);
const int N = 10005;

int dp[N];
int n , a[N] , b[N];

int solve(int val)
{
	if(val <= 0)
		return 0;

	if(dp[val] != -1)   return dp[val];
	int res = inf64;
	
	for(int i=0 ; i<n ; i++)
	{
		res = min(res , solve(val - a[i]) + b[i]);
	}
	
	dp[val] = res;
	return res;
}

int32_t main(){
	fast;
	int h;
	cin >> h >> n;
	
	for(int i=0 ; i<n ; i++)
		cin >> a[i] >> b[i];

	memset(dp , -1 , sizeof(dp));
	cout << solve(h);
}



Measured memory_bytes: 640
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

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

struct Node *search(int);
void print();
void insert(int);
void delete(struct Node *);
void init(void);

struct Node *head;

int main(){
  int num,i,numcom;
  char command[20];
  
  struct Node *node;

  
  scanf("%d",&numcom);
  init();
  for(i=0;i<numcom;i++){
    scanf("%s",command);
    
    if(command[0]=='i'){
      scanf("%d",&num);
      insert(num);
      
    }
    else if(command[0]=='d'){
      if(strlen(command)>6){
	if(command[6]=='F'){
	  
	  delete(head->next);
	}
	 if(command[6]=='L'){
	   
	   delete(head->prev);
	 }
      }
	 else{
	   scanf("%d",&num);
	   node=search(num);
	   if(node==head) continue;
	   if(node==head) head=node->next;
	   delete(node);
	 }
      }
    
  }
   
    
    

  print();
  return 0;
}

struct Node * search(int num){
  struct Node *node;
  node=head->next;
  while(node!=head && node->key!=num) node=node->next;
  return node;
}

void print(){
  struct Node *node=head->next;
  int first=0;
  while(1){
    if(node==head) break;
    if(first>0) printf(" ");
    printf("%d",node->key);
   
    node=node->next;
    first++;
  }
  printf("\n");
}

void insert(int num){
  struct Node *node;
  node=malloc(sizeof(struct Node));
  node->key=num;
  node->next=head->next;
  head->next->prev=node;
  head->next=node;
  node->prev=head;
  
}

void delete(struct Node *node){
  if(node==head) return;
  if(node->prev!=NULL) node->prev->next=node->next;
  if(node->next!=NULL) node->next->prev=node->prev;
  free(node);
}

void init(){
  head=malloc(sizeof(struct Node));
  head->next=head;
  head->prev=head;
}

  



Measured memory_bytes: 32980
#include<bits/stdc++.h>
using namespace std;
#define INF 1000000000
int main(){
  int n,m;
  int a[59],b[59],c[59],d[59];
  cin>>n>>m;
  for(int i=0;i<n;i++){
    cin>>a[i]>>b[i];
  }
  for(int i=0;i<m;i++){
    cin>>c[i]>>d[i];
  }
  for(int i=0;i<n;i++){
    int t=INF,ans;
    for(int j=0;j<m;j++){
      if(abs(a[i]-c[j])+abs(b[i]-d[j])<t){
	t=abs(a[i]-c[j])+abs(b[i]-d[j]);
	ans=j+1;
      }
    }
    cout<<ans<<endl;
  }
  return(0);
}


Measured memory_bytes: 764
#include<stdio.h>

void trace(int A[], int N){
  int i;
  for(i=0; i<N; i++){
    if(i>0) printf(" ");
    printf("%d", A[i]);
  }
  printf("\n");

}

void insertionSort(int A[], int N){
  int j,i,v;
  for(i=1; i<N; i++){
    v=A[i];
    j=i-1;
    while(j>=0 && A[j]>v){
      A[j+1]=A[j];
      j--;
    }
    A[j+1]=v;
    trace(A,N);
  }
}

int main(){
  int N,i,j;
  int A[100];
  scanf("%d",&N);
  for(i=0; i<N; i++)
  scanf("%d",&A[i]);

  trace(A,N);
  insertionSort(A,N);

  return 0;
}



Measured memory_bytes: 2124
/*
ID: anonymo14
TASK: wormhole
LANG: C++                 
*/
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pair<int,int>> vpii;

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back

#define REP(i,a,b) for(int i=a; i<=b; i++)

#define MOD 1000000007

void solve(int test_case) {//227
	int n;
	cin>>n;
	vector<array<ll,3>> arr(n-1);
	REP(i,0,n-2) {
		ll a,b,c;
		cin>>a>>b>>c;
		arr[i]={a,b,c};
	}
	vll ans(n-1);
	REP(i,0,n-2) {
		ll last = 0;
		REP(j,i,n-2) {
			if(last>arr[j][1]){
				int req = (last)%arr[j][2];
				if(req!=0)req=arr[j][2]-req;
				last = last + req + arr[j][0];
			} else {
				last = arr[j][1] + arr[j][0];
			}
		}
		ans[i]=last;
	}
	REP(i,0,n-2)cout<<ans[i]<<"\n";
	cout<<0;
}

int main() {
	
	////// FILE BASED IO////
	//freopen("wormhole.in", "r", stdin);
	//freopen("wormhole.out", "w", stdout);
	///////////////
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin>>t;
	REP(i,1,t) {
		solve(i);
	}
	return 0;
}	


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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define lcm( a, b ) (a)/__gcd((a),(b))*(b)
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 200005;

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

LL fac[SIZE], finv[SIZE], inv[SIZE];
void combInit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for( int i = 2; i < SIZE; ++i ) {
        fac[i] = (fac[i - 1] * i) % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = (finv[i - 1] * inv[i]) % MOD;

    }
}

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

}

vector< int > Div( int n ) {
    vector< int > ret;
    for( int i = 1; i * i <= n; ++i ) {
        if( n % i == 0 ) {
            ret.pb( i );

            if( i * i != n ) ret.pb( n / i );
        }
    }
    sort( all( ret ) );
    return ret;
}

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

    int q;
    cin >> q;
    deque< int > deq;
    while( q-- ) {
        int seq;
        cin >> seq;
        if( seq == 0 ) {
            int d, x;
            cin >> d >> x;
            if( d == 0 ) {
                deq.push_front(x);

            } else {
                deq.push_back(x);

            }
        } else if( seq == 1 ) {
            int p;
            cin >> p;
            cout << deq[p] << endl;

        } else {
            int d;
            cin >> d;
            if( d == 0 ) {
                deq.pop_front();

            } else {
                deq.pop_back();

            }
        }
    }
    return 0;
}




Measured memory_bytes: 4560
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define f first
#define s second
#define go ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
/*bool sortbysec(const pair<int,int> &a,
              const pair<int,int> &b)
{
    return (a.second < b.second);
} */
int main()
{
     ll n,d,arr[20][20];
     cin>>n>>d;
     for(int i=0;i<n;i++)
     {
         for(int j=0;j<d;j++)
         {
             cin>>arr[i][j];
         }
     }
     ll cnt=0,sum=0;
     for(int i=0;i<n;i++)
     {
         for(int j=i+1;j<n;j++)
         {
             for(int k=0;k<d;k++)
             {
                 ll nk=arr[i][k]-arr[j][k];
                 sum+=(pow(nk,2));
             }
             ll kk=sqrt(sum);
             if(kk*kk==sum)
                cnt++;
             sum=0;
         }
     }
     cout<<cnt<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
#include <cassert>
//#include <boost/multiprecision/cpp_int.hpp>
#include <complex>
#include <cstdio>

using namespace std;
//std::ios::sync_with_stdio(false);
//std::cin.tie(0);
const long long MOD = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ld, ll> pdl;
typedef pair<ld, ld> pdd;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
//typedef boost::multiprecision::cpp_int bigint;

map<ll, ll> MAP[2];

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	ll N;
	cin >> N;
	VLL V[2];
	V[0].reserve(N);
	V[1].reserve(N);
	for (ll n = 0; n < N; n++) {
		ll v;
		cin >> v;
		V[n & 1].push_back(v);
	}
	sort(V[0].begin(), V[0].end(), [](ll a, ll b) {
		return a < b;
	});
	sort(V[1].begin(), V[1].end(), [](ll a, ll b) {
		return a < b;
	});
	vector<pll> VV[2];
	VV[0].reserve(N);
	VV[1].reserve(N);
	VV[0].push_back(pll(V[0][0], 1));
	for (ll n = 1; n < V[0].size(); n++) {
		if (V[0][n] == V[0][n - 1])VV[0].back().second++;
		else VV[0].push_back(pll(V[0][n], 1));
	}
	VV[1].push_back(pll(V[1][0], 1));
	for (ll n = 1; n < V[1].size(); n++) {
		if (V[1][n] == V[1][n - 1])VV[1].back().second++;
		else VV[1].push_back(pll(V[1][n], 1));
	}
	sort(VV[0].begin(), VV[0].end(), [](pll a, pll b) {
		return a.second > b.second;
	});
	sort(VV[1].begin(), VV[1].end(), [](pll a, pll b) {
		return a.second > b.second;
	});
	ll ans = 0;
	if (VV[0][0].first != VV[1][0].first) {
		ans = N - (VV[0][0].second + VV[1][0].second);
	}
	else {
		//0でマックスを使う
		ll ans1 = VV[0][0].second;
		if (VV[1].size() != 1)ans1 += VV[1][1].second;
		//1でマックスを使う
		ll ans2 = VV[1][0].second;
		if (VV[0].size() != 1)ans2 += VV[0][1].second;
		ans = N - max(ans1, ans2);
	}
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 2560
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#include <complex>
#include <unistd.h>
#include <cassert>
#include <cctype>
#include <random>
#include <time.h>
#include <functional>
#define _USE_MATH_DEFINES
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<ll, ll, ll, ll> tlglglglg;
typedef tuple<double, double, double> tddd;
typedef complex<double> xy_t;
typedef vector<ll> vll;
typedef vector< vector<ll> > matrix;
typedef unsigned int uint;
typedef unsigned long long ull;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
template <class T> using VVV = V<VV<T>>;
#define REP(i, x, y) for(ll i = (ll)x; i < (ll)y; i++)
#define DREP(i, x, y, d) for(ll i = (ll)x; i < (ll)y; i += (ll)d)
#define PER(i, x, y) for(ll i = (ll)x; i > (ll)y; i--)
#define DPER(i, x, y, d) for(ll i = (ll)x; i > (ll)y; i -= (ll)d)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;
int iinf = intmax / 8;
ll inf = llmax / 8;
double eps = 1e-12;
void yesno(bool ok, string yes = "Yes", string no = "No") {
    if (ok) {
        cout << yes << endl;
    } else {
        cout << no << endl;
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed;
    cout << setprecision(12);
    ll A, B, H, M;
    cin >> A >> B >> H >> M;
    double ang = abs(H * 30 - M * 5.5);
    double angrad = 2 * pi * ang / (360 * 1.0);
    double p = sqrt(A * A + B * B - 2 * A * B * cos(angrad));
    cout << p << endl;
}


Measured memory_bytes: 4148
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
  int n,k,x,y,sum=0;
  cin >> n >> k >> x >> y;
  int i=1;
  while(i != n+1){
    if(i <= k){
      sum += x;
    } else{
      sum += y;
    }
    i++;
  }
  cout << sum << endl;
  return 0;
}



Measured memory_bytes: 256
import Control.Applicative
import Control.Monad
import Data.List
import Data.Bool (bool)

main :: IO ()
main = do
  n <- readLn
  unless (n == 0) $ do
    ts <- replicateM n f
    m <- readLn
    solve ts <$> replicateM m g >>= putStrLn
    main
  where
    f = map read <$> words <$> getLine
    g = (\[d, l] -> (head d, read l)) <$> words <$> getLine

solve :: [[Int]] -> [(Char, Int)] -> String
solve ts = bool "No" "Yes" . null . snd . foldl' f ((10, 10), ts)
  where
    f ((cx, cy), ts) ('N', l) = ((cx, cy + l), filter (\[x, y] -> x /= cx || y `notElem` [cy .. cy + l]) ts)
    f ((cx, cy), ts) ('S', l) = ((cx, cy - l), filter (\[x, y] -> x /= cx || y `notElem` [cy - l .. cy]) ts)
    f ((cx, cy), ts) ('E', l) = ((cx + l, cy), filter (\[x, y] -> y /= cy || x `notElem` [cx .. cx + l]) ts)
    f ((cx, cy), ts) ('W', l) = ((cx - l, cy), filter (\[x, y] -> y /= cy || x `notElem` [cx - l .. cx]) ts)



Measured memory_bytes: 3992
n = int(input())
mod = 10**9+7

ans = 1
for i in range(n):
    ans = (ans*10) % mod
ans2 = 1
for i in range(n):
    ans2 = (ans2*9) % mod
ans3 = 1
for i in range(n):
    ans3 = (ans3*8) % mod
print((ans-ans2*2+ans3)%mod)

Measured memory_bytes: 64064
#include <bits/stdc++.h>
#include <cmath>
#include <iomanip>
using namespace std;
 
#define f first
#define s second
 
#define pb push_back
#define pp pop_back
#define mp make_pair
 
#define sz(x) (int)x.size()
#define sqr(x) ((x) * 1ll * (x))
#define all(x) x.begin(), x.end()
#define clr(a,v) memset(a, v, sizeof(a))
 
#define rep(i, l, r) for (int i = (l); i <= (r); i++)
#define per(i, l, r) for (int i = (l); i >= (r); i--)
#define reflex ios_base::sync_with_stdio(false)
 
#define nl '\n'
#define ioi exit(0);
 
 
#define PI 3.14159265
 
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
 
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int N= (int)2e5 + 7;
const int inf = (int)1e9 + 7;
const int mod = (int)1e9 + 7;
//const int mod = 1000000007;
const ll linf = (ll)1e18 + 7;
const ll limit = 2e9;

const int dx[] = {-1, 0, 1, 0, 1, -1, -1, 1};
const int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
const int kx[] = {-1,1,2,2,1,-1,-2,-2};
const int ky[] = {2,2,1,-1,-2,-2,-1,1};
 
//const int mod = 998244353;
 
struct dsu{
	int parent[N];
	int cont;
	void make_set(int n){
		for(int i = 1; i <= n; i++)
			parent[i] = i;
		cont = n;
	}
	
	int find_set(int v){
		if(v == parent[v])
			return v;
		return find_set(parent[v]);
	}
	
	void union_sets(int a, int b){
		a = find_set(a);
		b = find_set(b);	
		if(a != b){
			parent[b] = a;
			cont--;
		}
	}	
};

struct nod{
	int l,r;
	nod(int l_,int r_){
		l = l_;
		r = r_;
	}
};

bool operator<(const nod& a, const nod& b)
{
   
	
	return a.r < b.r;
	
}

int maxEvents(vector<vector<int>>& events) {
	int ans = 0;
	vector<nod> v;
	for(int i = 0; i < (int)events.size(); i++){
		nod tmp(events[i][0], events[i][1]);
		v.push_back(tmp);
		sort(v.begin(), v.end());
	}
	cout<<endl;
	for(nod x: v){
		cout<<x.l<<" "<<x.r<<endl;
	}
	cout<<endl<<endl;
	
	int p = v[0].l;
	for(int i = 0; i < (int)v.size();i++){
		if(v[i].l <= p && p <= v[i].r){
			ans++;
			p++;
		}
		else if(p < v[i].l){
			p = v[i].l;
			ans++;
		}
	} 
	
	return ans;
}

int main(){
	vector<int> v;
	int a, b, c; cin>> a >> b >>c;
	v.push_back(a);
	v.push_back(b);
	v.push_back(c);
	sort(v.begin(),v.end());
	if(v[0]== v[1] && v[1] != v[2])
		cout<<"Yes";
		
	else if(v[1] == v[2] && v[1] != v[0])
		cout<<"Yes";
	else
		cout<<"No";
		
	return 0;
}













Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cstring>
#include <climits>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };
 
int MOD = 1000000007;

int main() {
	vector< vector< vector<int> > > a(4, vector< vector<int> >(3, vector<int>(10)));
	int n; cin >> n;
	while (n--) {
		int b, f, r, v; cin >> b >> f >> r >> v;
		a[b - 1][f - 1][r - 1] += v;
	}
	for (int i = 0; i < 4; i++) {
		for (int j = 0; j < 3; j++) {
			for (int k = 0; k < 10; k++)
				cout << ' ' << a[i][j][k];
			cout << endl;
		}
		if (i + 1 < 4) cout << "####################" << endl;
	}
}

Measured memory_bytes: 1216
import java.util.*;

public class Main {

	public static String toansString(int y, int x, int y2, int x2) {
		StringBuffer ans = new StringBuffer();
		ans.append(String.valueOf(y));
		ans.append(" ");
		ans.append(String.valueOf(x));
		ans.append(" ");
		ans.append(String.valueOf(y2));
		ans.append(" ");
		ans.append(String.valueOf(x2));

		return ans.toString();
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int h = sc.nextInt(), w = sc.nextInt();
		int a[][] = new int[h][w];
		for (int i = 0; i < h; ++i) {
			for (int j = 0; j < w; ++j) {
				a[i][j] = sc.nextInt();
			}
		}
		sc.close();
		List<String> ans = new ArrayList<String>();
		for (int i = 0; i < h; ++i) {
			for (int j = 0; j < w; ++j) {
				if (a[i][j] % 2 != 0) {
					String tmp = "";
					a[i][j]--;
					if (j + 1 < w) {
						a[i][j + 1]++;
						tmp = toansString(i + 1, j + 1, i + 1, j + 2);
					} else {
						if (i + 1 < h) {
							a[i + 1][j]++;
							tmp = toansString(i + 1, j + 1, i + 2, j + 1);
						}
					}
					if (tmp.length() != 0)
						ans.add(tmp);
				}
			}
		}

		System.out.println(ans.size());
		for (String an : ans)
			System.out.println(an);
	}
}


Measured memory_bytes: 109080
#include<stdio.h>
int main(){
    char b ;
    scanf("%s", &b);
    if(b=='A'){
        printf("T");
    }else if(b=='C'){
        printf("G");
    }else if(b== 'G'){

        printf("C");
    }else if(b=='T'){

        printf("A");
    }
}


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

using namespace std;

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

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main() {
  int a, b;
  cin >> a >> b;
  int ans1 = a + b;
  int ans2 = a - b;
  int ans3 = a * b;
  cout << max(ans1, max(ans2, ans3)) << endl;
  return 0;
}

Measured memory_bytes: 256
import sys
from collections import Counter
import math
import heapq
stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()

n, m = na()
a = na()
li = [a[i] * (-1) for i in range(n)]
heapq.heapify(li)
for i in range(m):
    num = heapq.heappop(li) * (-1)
    num = math.floor(num / 2)
    heapq.heappush(li, num * (-1))
ans = 0
for i in range(n):
    ans += (heapq.heappop(li) * (-1))
print(ans)




Measured memory_bytes: 14628
import java.util.*;

public class Main {
    public static void main(String args[]) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();

        Map<Integer, Integer>[] graph = new HashMap[n + 1];

        for(int i = 1; i <= n; i++)
            graph[i] = new HashMap<>();

        for(int i = 0; i < m; i++) {
            int from = sc.nextInt();
            int to = sc.nextInt();
            int w = sc.nextInt();

            graph[from].put(to, w);
            graph[to].put(from, -w);
        }

        boolean[] visited = new boolean[n + 1];
        long[] weights = new long[n + 1];

        for(int i = 1; i <= n; i++) {
            if(visited[i]) continue;
            if(!dfs(graph, visited, weights, i, 0)) {
                System.out.println("No");
                return;
            }
        }
        
        System.out.println("Yes");
    }

    private static boolean dfs(Map<Integer, Integer>[] graph, boolean[] visited, long[] weights, int node, int prevWeight) {
        if(visited[node]) {
            return weights[node] == prevWeight;
        }

        weights[node] = prevWeight;
        visited[node] = true;

        for(Map.Entry<Integer, Integer> entry : graph[node].entrySet()) {
            int to = entry.getKey();
            int w = entry.getValue();

            if(!dfs(graph, visited, weights, to, w + prevWeight))
                return false;
        }
        return true;
    }
}


Measured memory_bytes: 196540
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int[][] num = new int[N][3];
		int num2 = 0;
		int[] res = new int[N];

		for(int i = 0; i < N; i++){
			for(int j = 0; j < 3; j++){
				num[i][j] = scan.nextInt();
			}
		}
		
		for(int i = 0; i < 3; i++){
			for(int j = 0; j < N; j++){
				num2 = num[j][i];
				for(int k = 0; k < N; k++){
					if(num2 == num[k][i]){   //同数
						if(j != k){   //同じ配列でない
							num[j][i] = 0;
							num[k][i] = 0;
						}
					}
				}
			}	
		}
		
		for(int i = 0; i < N; i++){
			for(int j = 0; j < 3; j++){
				res[i] += num[i][j];
			}
			System.out.println(res[i]);
		}
	}
}

Measured memory_bytes: 20952
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b;
  char c;
  while(cin>>a>>c>>b,c!='?'){
    if(c=='+') cout<<a+b<<endl;
    else if(c=='-') cout<<a-b<<endl;
    else if(c=='*') cout<<a*b<<endl;
    else cout<<a/b<<endl;
  }
}


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

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  vector<int> B(N); 
  int M1, M2 = 0;
  for(int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  for(int i = 0; i < N; i++) {
    B.at(i) = A.at(i);
  }
  sort(B.begin(), B.end());
  M1 = B.at(N-1);
  M2 = B.at(N-2);
  for(int i = 0; i < N; i++) {
    if(A.at(i) == M1) {
      cout << M2 << endl;
    }
    else {
      cout << M1 << endl;
    }
  }
}


Measured memory_bytes: 3200
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
#define vv vector<lli>
#define vp vector<pair<lli,lli>>
#define vpp vector<pair<lli,pair<lli,lli>>>
#define lims(w) (w).begin(),(w).end()
#define rlims(w) (w).rbegin(),(w).rend()
#define pb push_back
#define mp make_pair
#define f(i,a,b) for(lli i=a;i<b;i++)

int main()
{
	lli tstt;
	cin>>tstt;
	lli arr[4] = {0};

	f(duh,0,tstt)
	{
		string s;
		cin>>s;

		if(s[0] == 'A')
			arr[0]++;
		else if(s[0] == 'W')
			arr[1]++;
		else if(s[0] == 'T')
			arr[2]++;
		else
			arr[3]++;
	}

	cout<<"AC x "<<arr[0]<<endl;
	cout<<"WA x "<<arr[1]<<endl;
	cout<<"TLE x "<<arr[2]<<endl;
	cout<<"RE x "<<arr[3]<<endl;

	return 0;
}


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

int main(){
    int a, b;
    cin >> a >> b;
    
    if((a <= 0 && b >= 0) || a == 0 || b == 0){
        cout << "Zero" << endl;
    }else if(a > 0 || abs(b-a) % 2){
        cout << "Positive" << endl;
    }else{
        cout << "Negative" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1000000007;
int main()
{
    int n;
    cin >> n;
    vector<ll> v;
    for(int i = 0;i < n;i++)
    {
        ll a;
        cin >> a;
        v.push_back(a);
        if(a == 0)
        {
            cout << "0\n";
            return 0;
        }
    }
    ll ans = 1;
    for(int i = 0;i < n;i++)
    {
        if(v[i] <= 1000000000000000000 / ans)
        {
            ans *= v[i];
        }
        else
        {
            cout << "-1\n";
            return 0;
        }
    }
    cout << ans << "\n";

    return 0;
}


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

int main() {  
  int n;
  cin >> n;
  vector<int> p(n);
  rep(i,n) {
  	cin >> p[i];
  }
  int k = 0;
  for (int i = 0; i < n; i++) {
  	if(!(p[i] == i+1)) {
    	k++;
    }
  }
  if(k <= 2) cout << "YES" << endl;
  else cout << "NO" << endl;
}

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

using namespace std;

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

	string s; cin >> s;
	int total = 'z' - 'a' + 1;

	int cont = s.size();
	vector<int> reg(500, 0);
	if(cont < total) {
		for(char c : s) reg[c] = 1;

		char c = 'a';
		while(reg[c]) c += 1;
		s += c;

		cout << s << "\n";
	} else {
		if(s == "zyxwvutsrqponmlkjihgfedcba") cout << -1 << "\n";
		else {
			
			for(char c : s) reg[c] = 1;

			int ver = 0;
			for(int i=s.size() - 1; i>=0; i--) {
				char c = s[i]; reg[c] = 0; c++;

				while(c <= 'z') {
					if(reg[c] == 0) {
						ver = 1;
						break;
					}
					c++;
				}
				if(ver) {
					for(int j=0; j<i; j++) cout << s[j];

					cout << c << "\n";
					break;
				}
			}
			

		}
		
	}



	return 0;
}

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

int main()
{
    string a,b;
    cin >> a >> b;
    if(a[0]==b[2] && a[1]==b[1] && a[2]==b[0])
        cout << "YES";
    else
        cout << "NO";
	return 0;
}

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

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

int main() {
int N,T;
cin>>N>>T;
vector<int> c(N,0);
vector<int> t(N,0);

int ans=10000;
REP(i,N) {cin>>c[i]>>t[i];
if(t[i]-T<=0) ans=min(ans,c[i]);
}
if(ans!=10000) cout<<ans<<endl;
else cout<<"TLE"<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define ARRAY_LENGTH(array) sizeof(array)/sizeof(*array)
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; }

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

    ll k[M];
    ll s[M][N];
    REP(i, M) {
        cin >> k[i];
        REP(j, k[i]) {
            cin >> s[i][j];
        }
    }

    ll p[M];
    for(ll i = 0; i < M; ++i) {
        cin >> p[i];
    }

    ll ans = 0;
    for(ll bits = 0; bits < (1 << N); ++bits) {
        bool isAllLit = true;

        for(ll i = 0; i < M; ++i) {
            ll onCnt = 0;
            for(ll j = 0; j < k[i]; ++j) {
                ll mask = 1 << (s[i][j] - 1);
                if((bits & mask) == mask) {
                    ++onCnt;
                }
            }

            if(onCnt % 2 != p[i]) {
                isAllLit = false;
                break;
            }
        }

        if(isAllLit) {
            ++ans;
        }
    }

    cout << ans << endl;

    return 0;
}

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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

// 最小公倍数
ll lcm(ll a, ll b){
    return a*b/gcd(a, b);
}

int main()
{
    cout << fixed << setprecision(15);
    ll H, W, D;
    cin >> H >> W >> D;

    vector<vector<ll>> A(H+1, vector<ll>(W+1));
    vector<P> B(H*W+1);
    for(ll i=1; i<=H; i++){
        for(ll j=1; j<=W; j++){
            cin >> A[i][j];
            B[A[i][j]].first = i;
            B[A[i][j]].second = j;
        }
    }

    // その数に到達するまでの数
    vector<ll> C(H*W+1,0);

    for(ll i=1; i<=D; i++){
        for(ll j=i; j<=H*W; j=j+D){
            if(j<=D){
                C[j] = 0;
                continue;
            }
            ll x1 = B[j].first;
            ll y1 = B[j].second;
            ll x2 = B[j-D].first;
            ll y2 = B[j-D].second;
            C[j] = C[j-D] + abs(x1-x2) + abs(y1-y2);
        }
    }

    ll Q;
    cin >> Q;

    REP(i, Q){
        ll L;
        ll R;
        cin >> L >> R;
        cout << C[R] -C[L] << endl;
    }

    return 0;
}

Measured memory_bytes: 3968
using System;
using System.Collections.Generic;
using System.Linq;

namespace ABC104D
{
    class Program
    {
        static void Main(string[] args)
        {
            var NMQ = ReadInt();
            int N = NMQ[0];
            int M = NMQ[1];
            int Q = NMQ[2];

            int[,] sg = new int[N + 1, N + 1];
            for (int i = 0; i < M; i++)
            {
                var input = ReadInt();
                sg[input[0], input[1]]++;
            }

            for (int i = 0; i < N; i++)
            {
                for (int j = 0; j < N; j++)
                {
                    sg[i + 1, j + 1] += sg[i + 1, j] + sg[i, j + 1] - sg[i, j];
                }
            }

            for (int i = 0; i < Q; i++)
            {
                var pq = ReadInt();
                int p = pq[1];
                int q = pq[0];

                int ans = sg[p, p] - sg[p, q - 1] - sg[q - 1, p] + sg[q - 1, q - 1];
                Console.WriteLine(ans);
            }

            Console.ReadKey();
        }

        static int[] ReadInt()
        {
            int[] ret = Console.ReadLine().Split().Select(int.Parse).ToArray();
            return ret;
        }
        static long[] ReadLong()
        {
            long[] ret = Console.ReadLine().Split().Select(long.Parse).ToArray();
            return ret;
        }
    }
}


Measured memory_bytes: 18684
import sys
input = sys.stdin.readline

S = list(input().strip())
m = {}

for v in S:
    if m.get(v) != None:
        m[v] += 1
    else:
        m[v] = 1
        
for v in m.values():
    if v % 2 != 0:
        print("No")
        exit()
        
print("Yes")

Measured memory_bytes: 3060
#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>

#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>
#include <regex>
#define REP(i,n) for(int i = 0; i < n; i++)
#define FOR(i,j,n) for(int i = j; i < n; i++)
#define RFOR(i,j,n) for(int i = j-1; i >= n; i--)
#define PREC(n) fixed << setprecision(n)
#define print_array(v) REP(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
#define YesorNo(a) printf(a?"Yes\n":"No\n")
#define _LIBCPP_DEBUG 0
using namespace std;
int64_t MOD = 1000000007;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vector<int> a(n);
  REP(i,n) cin >> a[i];

  int sum = accumulate(a.begin(), a.end(),0);
  sort(a.begin(), a.end());
  reverse(a.begin(), a.end());

  bool flag = true;
  REP(j,m) {
    if(sum > a[j] * 4 * m) flag = false;
  }
  YesorNo(flag);
  return 0;
}
//templete by private_yusuke

Measured memory_bytes: 256
n = gets.chomp.to_i
a = gets.chomp.split("")
b = gets.chomp.split("")
c = gets.chomp.split("")
total = 0

for i in 0..n
  if a[i] == b[i] && a[i] == c[i]
  elsif a[i] != b[i] && a[i] != c[i] && b[i] != c[i]
  total += 2
  else
  total += 1
  end
end

puts total

Measured memory_bytes: 1788
from itertools import accumulate

# 入力
Q = int(input())
l, r = zip(*(map(int, input().split()) for _ in range(Q)))

# エラトステネスのふるいにより、素数表を作成する
is_prime = [i >= 2 for i in range(10**5 + 1)]
for i in range(2, 10**5 + 1):
    if is_prime[i]:
        for j in range(2 * i, 10**5 + 1, i):
            is_prime[j] = False

# i以下の2017に似た数の累積和を求める
dp = list(
    accumulate(
        range(10**5 + 1),
        lambda acc, i: (
            acc + 1 if is_prime[i] and is_prime[(i + 1) // 2] else
            acc
        )
    )
)

# 累積和を用いて各クエリに回答する
ans = '\n'.join(
    map(
        str,
        (dp[b] - dp[a - 1] for a, b in zip(l, r))
    )
)

# 出力
print(ans)


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

#define len(s) int(s.size())
#define res(x) cout<<((x)?"unsafe\n":"safe\n")
#define all(v) v.begin(),v.end()

typedef long long ll;
typedef long double ld;

ll mod = 1e9+7;

void solution() {
	int k, n, x;
	cin >> k >> n;

	bool existk = false;
	vector<bool> a(110, false);
	
	for(int i = 0; i < n; ++i) {
		cin >> x;
		a[x] = true;
		if(x == k) {
			existk = true;
		}
	}

	if(existk == false) {
		cout << k;
		return;
	}
	int up = 200, down = -200;
	for(int i = k; i <= 101; ++i) {
		if(a[i] == false) {
			up = i;
			break;
		}
	}
	for(int i = k; i >= 0; --i) {
		if(a[i] == false) {
			down = i;
			break;
		}
	}

	//cout << "Up: " << up << ", Down: " << down;

	cout << (abs(k-down) <= abs(k-up) ? down : up);

	
}

int main(){
	
	int t = 1;
	//cin >> t;
	
	while(t--)
		solution();
	
	return 0;
}


Measured memory_bytes: 3648
#include<stdio.h>

int main(void){
    int a, b, c, k;
    
    scanf("%d%d%d%d", &a, &b, &c, &k);
    if(a >= k){
        printf("%d\n", k);
        return 0;
    }
    k = k-a-b;
    if(k <= 0){
        printf("%d\n", a);
    }else{
        printf("%d\n", a-k);
    }
    return 0;
}

Measured memory_bytes: 1700
s = str(input())
count = 0
a = ["R", "U", "D"]
b = ["L", "U", "D"]
for i in s[::2]:
    if i in a:
        pass
    else:
        count = 1
        break
for i in s[1::2]:
    if i in b:
        pass
    else:
        count = 1
        break
print("Yes" if count == 0 else "No")

Measured memory_bytes: 8936
use proconio::fastout;
use whiteread::parse_line;

#[fastout]
fn main() {
    let mut s: Vec<String> = vec![];
    let (n, _): (usize, usize) = parse_line().unwrap();
    for _ in 0..n {
        let tmp = parse_line().unwrap();
        s.push(tmp);
    }
    s.sort();
    for i in 0..n {
        print!("{}", s[i]);
    }
    println!();
}


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

#define iota(i,n,b,s) for(int i=int(b);i!=int((b)+(s)*(n));i+=(s))
#define range(i,n,m) iota(i,(((n)>(m))?((n)-(m)):((m)-(n))),(n),((n)>(m)?-1:1))
#define rep(i,n) iota(i,(n),0,1)
#define loop for(;;)

#define INF (1e9)
#define EPS (1e-9)
#define cons(a,b) (make_pair(a,b))
#define car(a) (a.first)
#define cdr(a) (a.second)
#define cadr(a) (car(cdr(a)))
#define cddr(a) (cdr(cdr(a)))
#define all(a) a.begin(), a.end()
#define trace(var) cerr<<">>> "<<#var<<" = "<<var<<endl;

typedef long long Integer;
typedef double Real;
typedef vector<int> vi;
typedef vector<string> vs;
typedef map<string,int> Dictionary;
const Real PI = acos(-1);

template<class S, class T>
ostream& operator<<(ostream& os, pair<S,T> p) {
  os << '(' << car(p) << ", " << cdr(p) << ')';
  return os;
}

template<class T>
ostream& operator<<(ostream& os, vector<T> v) {
  if (v.size() == 0) {
    os << "(empty)";
    return os;
  }
  os << v[0];
  for (int i=1, len=v.size(); i<len; ++i) os << ' ' << v[i];
  return os;
}

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

bool contains(vector<int>&vs, int x) {
  for (int v : vs) {
    if (v == x) return true;
  }
  return false;
}

int main() {
  for (string s; cin >> s, s != "0";) {

    int ans = 0;
    vector<int> mods(11, 0);

    rep (i, s.size()) {
      int z = s[i] - '0';
      vector<int> mods2(11, 0);
      rep (md, 12) {
        mods2[(md * 10 + z) % 11] += mods[md];
      }
      ans += mods2[0];
      if (z > 0) mods2[z]++;
      copy(all(mods2), mods.begin());
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 1328