akhauriyash/Code-Regression huggingface dataset:
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        B solver = new B();
        solver.solve(1, in, out);
        out.close();
    }

    static class B {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            int n = Integer.parseInt(in.next());
            int d = Integer.parseInt(in.next());
            int x = Integer.parseInt(in.next());
            int a[] = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = Integer.parseInt(in.next());
            }
            int ans = x;

            for (int i = 0; i < n; i++) {
                if (d % a[i] == 0) {
                    ans = ans + (d / a[i]);
                } else {
                    ans = ans + (d / a[i] + 1);
                }
            }

            // 出力
            out.println(ans);

        }

    }
}



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

int main() {
  int N,a,b,c,d;
  cin >> N;
  a = N/1000;
  b = (N/100)-(a*10);
  c = (N/10)-(N/100*10);
  d = N-(N/10)*10;
  if ( a == b && b == c ){
    cout << "Yes" << endl;
  }
  else if ( b == c && c == d ){
    cout << "Yes" <<endl;
  }
  else {
    cout<< "No" << endl;
  }
 
}



Measured memory_bytes: 256
s=list(input())
n=1

for i in s:
    if n%2==0:
        if i=="L" or i=="U" or i=="D":
            pass
        else:
            print("No")
            exit()
    else:
        if i=="R" or i=="U" or i=="D":
            pass
        else:
            print("No")
            exit()
    n+=1

print("Yes")

Measured memory_bytes: 3060
#include<iostream>
main(){for(int n,k,a[100000],s,M,i;std::cin>>n>>k,n;printf("%d\n",M))for(M=1<<31,i=s=0;i<n;s+=a[i],k<++i&&(s-=a[i-k-1])&&M<s&&(M=s))std::cin>>a[i];}

Measured memory_bytes: 1236
/*
    �����悭�ǂ����I
    �_���I�ɍl���悤�I
    �T���v�����m�F���悤!
    ��΂ɒ��߂�ȁI
    �H�v������I
    �z��͏������߂ɂƂ��Ă���

    Twitter�͏I���܂Ń��O�A�E�g�I
    �i�ԈႦ�ĉ�@���c�C�[�g���Ă͂����Ȃ�����j

*/
//include
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
#include<stdio.h>
#include<cstring>
//namespace
using namespace std;
//�J��Ԃ�
#define REP(i, m, n) for(int i=(int)m; i<(int)n; ++i)
#define rep(i, n) REP(i, 0, n)
//�C�e���[�^
#define all_range(C) begin(C), end(C)
//�ȗ���
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
typedef pair<string,int> pst;

const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
//�ő�ŏ�
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) {if(a>b) a=b;}
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) {if(a<b) a=b;}

//�֐�

//�ő���񐔂����߂�
ll my_gcd(ll x, ll y) {
  ll r;

  while(y!=0) {
    r = x%y;
    x = y;
    y = r;
  }

  return x;
}

//�ŏ����񐔂����߂�
ll my_lcm(ll x, ll y) {

  return (x*y)/my_gcd(x,y);
}

//x��y������߂� ���Q�l�F10^18��܂�
ll my_pow(ll x, ll y) {
  ll sum = 1;

  while(y>0) {
    sum *= x;
    --y;
  }

  return sum;
}

/*�l���������X�y�[�X


*/

//main.cpp----------------------------


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

  cout << n-k+1 << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <set>
#include <iomanip>
#include <math.h>
#include <algorithm>
#include <functional>
#include <stdio.h>
#include <vector>
#include <string>
#include <map>
#define rep(i, n) for (int (i) = 0; (i) < (int)(n); (i)++)
//#define rep(i, n) for(int (i) = 0, TmP = (n); (i) < (int)TmP ; ++(i))
#define asort(v, n) sort((v), (v + n)) //Using array
#define vsort(v) sort((v).begin(), (v).end()) // Using vector
#define vint vector<int>
typedef long long ll;

using namespace std;

signed main(){
  ll n, ans = 0;
  cin >> n;
  vector<ll> vec(n);
  rep(i, n)cin >> vec[i];

  bool flag = true;
  while(flag){
    rep(i, n){
      if(vec[i] % 2 == 0){
        vec[i] /= 2;
        //cout << vec[i] << endl;
      }else{
        cout << ans << endl;
        return 0;
      }
    }
    ans++;
  }
}


Measured memory_bytes: 632
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] t = new int[n];
		int[] a = new int[n];
		for(int i = 0 ; i < n ; i++) {
			t[i] = sc.nextInt();
			a[i] = sc.nextInt();
		}
		long x = t[0], y = a[0];
		for(int i = 1 ; i < n ; i++) {
			long min = Math.max((x + t[i] - 1) / t[i], (y + a[i] - 1) / a[i]);
			x = t[i] * min;
			y = a[i] * min;
		}
		System.out.println(x + y);
	}
}


Measured memory_bytes: 23916
from sys import stdin, stdout
rl = lambda: stdin.readline()
rll = lambda: stdin.readline().split()

def main():
	n, k = (int(x) for x in rll())
	ans = float('inf')
	c1 = n % k
	c2 = abs(c1 - k)
	stdout.write(str(min(c1, c2)));stdout.write("\n")
	stdout.close()

if __name__ == "__main__":
	main()

Measured memory_bytes: 38384
n,T=map(int, input().split())

x=[]

for i in range(n):
    c,t=map(int, input().split())
    if t<=T:
        x.append((i+1,c))
        
x.sort(key=lambda tup: tup[1])
if len(x)!=0:
    print(x[0][1])
else:
    print('TLE')

Measured memory_bytes: 3060
#include<stdio.h>
#include<stdlib.h>
#include<stdint.h>
#include<inttypes.h>
#include<string.h>

typedef int32_t i32;
typedef int64_t i64;

#define ALLOC(size,type) ((type*)calloc((size),sizeof(type)))
#define SORT(a,num,cmp) qsort((a),(num),sizeof(*(a)),cmp)

void test (void) {
  i32 n;
  i64 k;
  scanf ("%" SCNi32 "%" SCNi64, &n, &k);
  i32 *a = ALLOC (n, i32);
  for (i32 i = 0; i < n; ++i) {
    scanf ("%" SCNi32, a + i);
  }
  i32 *x = ALLOC (n + 1, i32);
  i32 len = 0;
  uint8_t *elem = ALLOC (200000 + 1, uint8_t);
  for (i32 i = 0; i < k; ++i) {
    for (i32 j = 0; j < n; ++j) {
      if (elem[a[j]]) {
        while (x[len - 1] != a[j]) {
          elem[x[--len]] = 0;
        }
        len--;
        elem[a[j]] = 0;
      } else {
        x[len++] = a[j];
        elem[a[j]] = 1;
      }
    printf ("%" PRIi32 " :", i * n + j);
    for (i32 j = 0; j < len; ++j) {
      printf (" %" PRIi32, x[j]);
    }
    puts ("");
    }
  }
}

void run (void) {
  i32 n;
  i64 x;
  scanf ("%" SCNi32 "%" SCNi64, &n, &x);
  i32 *a = ALLOC (2 * n, i32);
  for (i32 i = 0; i < n; ++i) {
    scanf ("%" SCNi32, a + i);
    a[i + n] = a[i];
  }
  i32 *next = ALLOC (2 * n, i32);
  const i32 m = 200000;
  i32 *memo = ALLOC (m + 1, i32);
  for (i32 i = 1; i <= m; ++i) {
    memo[i] = 2 * n;
  }
  for (i32 i = 2 * n - 1; i >= 0; --i) {
    next[i] = memo[a[i]];
    memo[a[i]] = i % n;;
  }
  i32 now = 0;
  i64 step = 0;
  do {
    i32 k = next[now];
    step += k > now ? k - now : n + k - now;
    now = k + 1;
    step++;
  } while (now != n);
  step /= n;
  x %= step;
  now = 0;
  step = 0;
  for (;;) {
    i32 k = next[now];
    i32 v = k > now ? k - now : n + k - now;
    if (step + v + 1 >= x * n) break;
    now = k + 1;
    step += 1 + v;
  }
  i32 *b = ALLOC (n, i32);
  i32 len = 0;
  uint8_t *elem = ALLOC (m + 1, uint8_t);
  for (i32 i = now; i < n; ++i) {
    if (elem[a[i]]) {
      while (b[len - 1] != a[i]) {
        elem[b[--len]] = 0;
      }
      elem[b[--len]] = 0;
    } else {
      b[len++] = a[i];
      elem[a[i]] = 1;
    }
  }
  for (i32 i = 0; i < len; ++i) {
    printf ("%" PRIi32, b[i]);
    putchar (i == len - 1 ? '\n' : ' ');
  }
}

int main (void) {
  run();
  return 0;
}


Measured memory_bytes: 6272
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i(0);i<n;i++)
#define fast  ios_base::sync_with_stdio(0); cin.tie(0);
#define open freopen("input.txt","r",stdin) ; freopen("output.txt","w",stdout);
#define watch(x) cout<<(#x)<<" is "<<x<<"\n";
#define mod 1000000007

int ceil(int a,int b){
	int ret;
	if(a%b==0)ret = a/b;
	else ret = a/b + 1;

	return ret;
}

int divi(int a, int b){
	int ret = a/b;
	return ret;
}

int gcd(int c,int d){
	if(d == 0)return c;
	else return gcd(d, c%d);
}

int32_t main(){
	
	fast;
	//open;

	int a,b,c,d,ans=0,lcm;
	cin>>a>>b>>c>>d;
	lcm = c*d; lcm/=gcd(c,d);

	ans += b - a + 1;
	//for c
	ans -= (divi(b,c) - ceil(a,c) + 1);
	//for d
	ans -= (divi(b,d) - ceil(a,d) + 1);
	//for c&d
	ans += (divi(b,lcm) - ceil(a,lcm) + 1);
	cout<<ans;




	return 0;
}

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

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
ld EPS = 1e-12;
int INF = numeric_limits<int>::max() / 2;
int MOD = 1e9 + 7;
#define rep(i,n) for(int i=0;i<n;i++)
 
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
    int n,even[100001]={},odd[100001]={},evenmax=0,evensecondmax=0,oddmax=0,oddsecondmax=0,evenpos=0,oddpos=0,ans;
    cin>>n;
    int v[n];
    rep(i,n){
        cin>>v[i];
        if(i%2==1){
            even[v[i]]++;
        }else{
            odd[v[i]]++;
        }
    }
    rep(i,100001){
        if(evenmax<even[i]){
            evensecondmax=evenmax;
            evenmax=even[i];
            evenpos=i;
        }else if(evensecondmax<even[i]){
            evensecondmax=even[i];
        }
 
        if(oddmax<odd[i]){
            oddsecondmax=oddmax;
            oddmax=odd[i];
            oddpos=i;
        }else if(oddsecondmax<odd[i]){
            oddsecondmax=odd[i];
        }
 
    }
    if(evenpos==oddpos){
        ans=max(evensecondmax+oddmax,evenmax+oddsecondmax);
    }else{
        ans=evenmax+oddmax;
    }

    cout << n-ans << '\n';
}

Measured memory_bytes: 1408
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include<unordered_map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include<bitset>
#include<deque>
#include<string>
#include<list>
#include<iterator>
#include<sstream>
#include <algorithm>
#define lli long long int
#define lower(a) transform(a.begin(),a.end(),a.begin(),::tolower);

using namespace std;

const int N = 3e5 + 500;
const long long mod = 1e9 + 7;
const long long cmod = 998244353 ;
const long long inf = 1LL << 57;
const int M = 1e6 + 500;
const lli ths = 1LL << 40;

void solve()
{
    lli a, b;
    cin>>a>>b;
    lli x = __gcd(a, b);
    lli ans = 0;
    bool ok = 0;
    for(lli i = 2; i * i <= x; i ++)
    {
        ok = 0;
        while(x % i == 0)
        {
            x /= i;
            ok = 1;
        }
        ans += ok;
    }
    ans ++;
    ans += (x > 1);
    cout<<ans;
    return ;
}
/*
7
6 7 4 1 2 11 6
5
1 2 10 4 5
*/

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

    lli t;
    t = 1;
//    cin>>t;
    while(t --)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 256
N, M = map(int, input().split())

ok = [False]*N
wa = [0]*N

for i in range(M):
    p, S = input().split()
    p = int(p) - 1
    if ok[p] == False:
        if S == "WA":
            wa[p] += 1
        else:
            ok[p] = True
    else:
        pass
pena = 0
for i in range(N):
    if ok[i] == True:
        pena += wa[i]
print(sum(ok), pena)

Measured memory_bytes: 10308
N = int(input())
a = [int(input())-1 for _ in range(N)]

b = [True]*N
b[0] = False
i = a[0]
cnt = 1
while b[i]:
    if i == 1:
        print(cnt)
        break
    b[i] = False
    i = a[i]
    cnt += 1
else:
    print(-1)

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

int main(void){
    string s; cin >> s;
    string ans;
    rep(i, s.size()){
        if(s[i] == '0') ans += '0';
        else if(s[i] == '1') ans += '1';
        else{
            if(!ans.empty()) ans.pop_back();//空文字でなければpop_back(最後の要素を削除)
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
input = lambda: sys.stdin.readline().rstrip()

def main():
    n = int(input())
    b = list(map(int, input().split()))
    ans = b[0]
    for i in range(n-2):
        ans += min(b[i], b[i+1])
    ans += b[-1]
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 9192
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,a,b) for (int i = a; i < (b); ++i)
#define all(x) (x).begin(),(x).end()
const int INF = 1000000007;
typedef long long ll;
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; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
int main(){
  // ios::sync_with_stdio(false);cin.tie(nullptr);
  ll a,b;
  cin >> a >> b;
  ll gg = gcd(a,b);
  ll ans = (a*b) / gg;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
static Scanner inp=new Scanner(System.in);
	public static void main(String args[]) {
		int n=inp.nextInt();
		int m=inp.nextInt();
		int mrk[]=new int[10000000];
		for (int i=1;i<=7368791;i++)mrk[i]=1;
		for (int i=2;i<=7368791;i++)
			if (mrk[i]==1)
				for(int j=i;j<=7368791/i;j++)
					if (mrk[i*j]==1)mrk[i*j]=j;
		while (n>0){
			for (int i=n;i<=10000000;i++)
				if (mrk[i]<n){m--;if(m==-1){System.out.println(i);break;}}
			n=inp.nextInt();
			m=inp.nextInt();
		}
	}

}

Measured memory_bytes: 66132
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
class Program
{
    static void Main()
    {
        //入力
        //int n = 100;
        /*
        long n = long.Parse(Console.ReadLine());
        long[] input = new long[5];
        for(int a = 0; a < 5; a++)
        {
            input[a]=long.Parse(Console.ReadLine());
        }
        */
        string[] input = Console.ReadLine().Split().Select(i => (i)).ToArray();

        Console.WriteLine(input[1]=="-"?int.Parse(input[0])-int.Parse(input[2]):int.Parse(input[0])+int.Parse(input[2]));

        /*
        //処理速度計測
        var sw = new System.Diagnostics.Stopwatch();
        sw.Start();
        //解法

        //処理速度表示
        sw.Stop();
        TimeSpan ts = sw.Elapsed;
        Console.WriteLine((int)(Math.Floor((ts).TotalMilliseconds))+"ms");
        */
        Console.ReadLine();
        
    }
}

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

int main(){
  string S;
  cin>>S;
  int N=S.length();
  string str1=S.substr(0,(N-1)/2);
  string str2=S.substr(((N+3)/2)-1,N);
  string R=string(S.rbegin(),S.rend());
  string rev1=string(str1.begin(),str1.end());
  string rev2=string(str2.rbegin(),str2.rend());

 if(S==R&&str1==rev1&&str2==rev2&&N>=3&&N<=99){
     cout<<"Yes";
 }
 else{
     cout<<"No";
 }
   return 0;
}

Measured memory_bytes: 3600
#include<bits/stdc++.h>
#define int long long
#define dd second
#define mp make_pair
#define pb push_back
#define ff first
#define dd second
#define pp pair<int,int>
using namespace std;
int w,h;
int ile[26];

main()
{
    ios_base::sync_with_stdio(false);
    for(int i = 0; i < 26; ++i) ile[i] = 0;
    cin >> h >> w;
    for(int i = 0; i < h*w; ++i)
    {
        char temp; cin >> temp; ile[temp - 'a']++;
    }
    int np = 0; int best = -1;
    for(int i = 0; i < 26; ++i)
    {
        if(ile[i] & 1)
        {
            np++; best = i;
        }
    }
    if(np > 1 or (w % 2 == 0 and h % 2 == 0 and np > 0))
    {
        cout << "No" << endl; exit(0);
    }
    int czw = ((h/2*2)*(w/2*2))/4;
    int dw = h*w - czw*4;
    if(h & 1 or w & 1)
    {
        dw--;
    }
    dw /= 2;
    //cout << czw << " " << dw << endl;
    for(int i = 0; i < 26; ++i)
    {
        while(czw > 0 and ile[i] >= 4) ile[i]-=4, czw--;
    }
    for(int i = 0; i < 26; ++i)
    {
        while(dw > 0 and ile[i] >= 2) ile[i]-=2, dw--;
    }
    if(czw == 0 and dw == 0)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}



Measured memory_bytes: 256
#include<iostream>
#include<sstream>
#include<iomanip>
#include<stdlib.h>
#include<string>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<set>
#include<queue>
#include<map>
#include<utility>
#include<algorithm>
using namespace std;
#define loop(i,l,r) for(int (i)=(int)(l);(i)<(int)(r);(i)++)
#define rloop(i,l,r) for(int (i)=(int)(l);(i)>(int)(r);(i)--)
#define rep(i,n) loop(i,0,n)
#define rrep(i,n) rloop(i,n-1,-1)
#define INF 0x3f3f3f3f
#define mod 1000000007
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;

int main(){
	int n,arg[100];
	ll dp[101][21];
	memset(dp,0,sizeof(dp));
	cin>>n;
	rep(i,n)cin>>arg[i];
	dp[1][arg[0]]=1;
	rep(i,n-1){
		rep(j,21){
			if(dp[i][j]>0){
				int p=j+arg[i],m=j-arg[i];
				if(p<=20)dp[i+1][p]+=dp[i][j];
				if(m>=0)dp[i+1][m]+=dp[i][j];
			}
		}
	}
	cout<<dp[n-1][arg[n-1]]<<endl;
}

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

int main() {
  string s;
  cin >> s;
  if (s.at(0) == s.at(1)) {
    if (s.at(1) != s.at(2) && s.at(2) == s.at(3))
      cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
  }
  if (s.at(0) == s.at(2)) {
    if (s.at(1) != s.at(2) && s.at(1) == s.at(3))
      cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
  }
  if (s.at(0) == s.at(3)) {
    if (s.at(0) != s.at(1) && s.at(1) == s.at(2))
      cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
  }
  if (s.at(0) != s.at(1) && s.at(0) != s.at(2)
      && s.at(0) != s.at(3)) {
    cout << "No" << endl;
    return 0;
  }
  if (s.at(1) != s.at(0) && s.at(1) != s.at(2)
      && s.at(1) != s.at(3)) {
    cout << "No" << endl;
    return 0;
  }
  if (s.at(2) != s.at(0) && s.at(2) != s.at(1)
      && s.at(2) != s.at(3)) {
    cout << "No" << endl;
    return 0;
  }
  if (s.at(3) != s.at(0) && s.at(3) != s.at(1)
      && s.at(3) != s.at(2)) {
    cout << "No" << endl;
    return 0;
  }
}

Measured memory_bytes: 256
#include <cstdio>
#include <cctype>
#include <iostream>

int main(){
	int i=0, a[26]={0};
	char ch;
	
	while( scanf("%c", &ch) != EOF ){
		if( isupper(ch) ) 
			ch = tolower(ch);
	
		if('a'<=ch && ch<='z') 
			++a[ ch-'a' ];
	
		++i;
	}

	for(int x=0; x<26; ++x)
	{
	    char c = 'a'+x;
	    std::cout << c << " : " << a[x] << std::endl;
	}

	return 0;
}


Measured memory_bytes: 3152
s = list(input())
status = 0
c = 0
word = [chr(ord('A') + i) for i in range(26)]

if s[0] != "A":
    status = 1
elif s.count("C") == 0:
    status = 1
else:
    if s.count("C") == 1 and 2<=s.index("C")<=len(s)-2:
        del s[0]
        del (s[s.index("C")])
        for i in word:
            if i in s:
                status = 1
                break
    else:
        status = 1

if status == 0:
    print("AC")
else:
    print("WA")


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

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    int n,x,g=0;
    vector<int>v;
    cin>>n>>x;
    v.push_back(x);
    for(int i=0;i<n;i++)
    {
        cin>>x;
        v.push_back(x);
    }
    sort(v.begin(),v.end());
    for(int i=1;i<v.size();i++)
    {
        g=__gcd(g,v[i]-v[i-1]);
    }
    cout<<g<<endl;
    return 0;
}


Measured memory_bytes: 892
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;

class Solution {
public:
    long long solve(string& s, int p) {
        if (p == 2 || p == 5) {
            int n = s.length();
            vector<long long> dp(p + 1, 0);
            dp[0] = 1;
            vector<long long> ndp(p + 1, 0);

            long long res = 0;
            for (auto c : s) {
                int d = c - '0';
                fill(begin(ndp), end(ndp), 0);
                for (int i = 0; i < p; ++i) {
                    ndp[(i * 10 + d) % p] += dp[i];
                }
                res += ndp[0];
                ndp[0] += 1;
                swap(ndp, dp);
            }

            return res;           
        } 
        
        int n = s.length();
        vector<int> cnts(p, 0);
        cnts[0] = 1;

        long long x = 0;
        long long P = 1;
        long long res = 0;
        for (int i = n - 1; i >= 0; --i) {
            int d = s[i] - '0';
            x = (d * P + x) % p;
            P = (P * 10) % p;
            res += cnts[x];
            ++cnts[x];
        }
        return res;
    }
};

int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);

    Solution sol;
    int n, p;
    string s;
    cin >> n >> p;
    cin >> s;

    cout << sol.solve(s, p) << "\n";

    return 0;
}

Measured memory_bytes: 720
n = int(input())
MOD = 1000000007

ans = 1
x_sardines = []
ver_sardines = []
hor_sardines  = []
zero_sardines  = []

for _ in range(n):
  ai, bi = map(int, input().split())
  if ai == 0 and bi != 0:
    ver_sardines.append((ai, bi))
  elif ai != 0 and bi == 0:
    hor_sardines.append((ai, bi))
  elif ai == 0 and bi == 0:
    zero_sardines.append((ai, bi))
  elif bi / ai > 0:
    x_sardines.append((ai, bi, 1))
  elif bi / ai < 0:
    x_sardines.append((- 1 * bi, ai, -1))

x_sardines.sort(key = lambda x: x[1] / x[0])

if len(x_sardines) > 0:
  pai, pbi, ps = x_sardines[0]
  p = 1 if ps == 1 else 0
  n = 1 if ps == -1 else 0
  for i, (ai, bi, s) in enumerate(x_sardines[1:]):
    if pai * bi - pbi * ai != 0:
      ans *= pow(2, p, MOD) + pow(2, n, MOD) - 1
      ans %= MOD
      p = 0
      n = 0
      
    if s == 1:
      p += 1
    elif s == -1:
      n += 1
    pai, pbi, ps = ai, bi, s

  ans *= pow(2, p, MOD) + pow(2, n, MOD) - 1
  ans %= MOD
  
v = len(ver_sardines)
h = len(hor_sardines)
ans *= pow(2, v, MOD) + pow(2, h, MOD) - 1
ans %= MOD

z = len(zero_sardines)
ans += z
ans -= 1
ans %= MOD

print(ans)




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

using namespace std;

struct ede
{
	int v,nxt;
}e2[200050];

vector<pair<int,int> > edge[1050];

int head[1050],ecnt,hd[1050],ec;
int flg1[200050],flg2[200050];
int vis1[1050],vis2[1050];

inline void adde(int u,int v,int id)
{
	edge[u].push_back(make_pair(v,id));
	e2[++ ec].v = u;
	e2[ec].nxt = hd[v];
	hd[v] = ec;
}

void dfs1(int pos,int tag)
{
	vis1[pos] = tag;
	for(auto v : edge[pos])
	{
		if(!vis1[v.first])
			dfs1(v.first,tag);
	}
}

void dfs2(int pos,int tag)
{
	vis2[pos] = tag;
	for(auto v : edge[pos])
	{
		if(!vis2[v.first])
			dfs2(v.first,tag);
	}
}

int histo[200050],hc;

int main()
{
	int n,m; scanf("%d%d",&n,&m);
	for(int i = 1;i <= m; ++ i)
	{
		int u,v; scanf("%d%d",&u,&v);
		adde(u,v,i);
	}
	for(int i = 1;i <= n; ++ i)
	{
	//	cerr << i << endl;
		memset(vis1,0,sizeof(vis1));
		memset(vis2,0,sizeof(vis2));
		hc = 0;
		vis1[i] = vis2[i] = -1;
		for(auto v : edge[i])
		{
			if(!vis1[v.first])
				dfs1(v.first,v.second);
		}
		for(int j = edge[i].size() - 1;j >= 0; -- j)
		{
			auto v = edge[i][j];
			if(!vis2[v.first])
				dfs2(v.first,v.second);
			if(vis1[v.first] != vis2[v.first])
				flg2[v.second] = 1;
		}
		for(int j = hd[i];j;j = e2[j].nxt)
			if(vis1[e2[j].v])
				flg1[j] = 1;
	}
	for(int i = 1;i <= m; ++ i)
		puts(flg1[i] + flg2[i] == 1 ? "diff" : "same");
}

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

int main(){
	char days[7][10]={"Thursday", "Friday", "Saturday",
							"Sunday", "Monday", "Tuesday", "Wednesday"};
	int mdays[12]={31, 29, 31, 30, 31,
						 30, 31, 31, 30, 31, 30, 31};
	int m, d;
	int day;
	int i;

	for(;;){
		scanf("%d %d", &m, &d);
		getchar();
		if( m==0 || d==0 ) break;
		for( i=0, day=0; i<m-1; i++ )
			day+=mdays[i];
		day+=d-1;
		printf("%s\n", days[(day)%7]);
	}
	return 0;
}

Measured memory_bytes: 588
N, M = map(int, input().split())
X = []
for i in range(N):
    a, b = map(int, input().split())
    X.append((a, b))

X = sorted(X)
num = 0
cost = 0
for a, b in X:
    cost += a * min(M - num, b)
    num += min(M - num, b)
    if num == M:
        print(cost)
        break



Measured memory_bytes: 17800
#coding:utf-8
#????????¢?????????

def draw_square(h, w):
    for i in range(h):
        a = ""
        for j in range(w):
            a += "#"
        print a

while 1:
    HW = raw_input().split()
    H = int(HW[0])
    W = int(HW[1])

    if H == 0 and W == 0:
        break

    draw_square(H, W)
    print ""

Measured memory_bytes: 6324
#include <iostream> 

int main() {
    int input_num;
    std::cin >> input_num;
    int answer = 0;
    for (int i = 0; i < input_num; ++i) {
        int temp;
        std::cin >> temp;
        answer += (temp - 1);
    }
    std::cout << answer << std::endl;
    return 0;
}

Measured memory_bytes: 256
A,B = map(int,input().split())
# A-2の時 2<=A<3　の間の数字だということ Bも同じ
non_taxed = sorted([(A/0.08),((A+1)/0.08),(B/0.1),((B+1)/0.1)])

for m in range(int(non_taxed[0]),int(non_taxed[3])+1):
    if int(m*0.08) == A and int(m*0.1) == B:
        print(m)
        exit()
print(-1)

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

using namespace std;

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

const double pi = 3.14159265358979323846;

#define MOD 1000000007LL
#define PS(p) cout << setprecision(15) << fixed << p << endl;
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
#define ALL(c) c.begin(), c.end()
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define F first
#define S second
#define VL vector< ll >

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

  ll N, M, X, Y;
  cin >> N >> M >> X >> Y;

  ll x, y;
  ll maxX = -1000;
  ll minY = 1000;
  for (ll i = 0; i < N; i++) {
    cin >> x;
    maxX = max(x, maxX);
  }
  for (ll i = 0; i < M; i++) {
    cin >> y;
    minY = min(y, minY);
  }

  cerr << X << " " << Y << " " << maxX << " " << minY << endl;
  if (X < maxX &&
      maxX <= Y &&
      X < minY &&
      minY <= Y &&
      maxX < minY) {
    cout << "No War"
         << "\n";
  } else {
    cout << "War"
         << "\n";
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())//vectorの降順ソート
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;
typedef tuple<ll, ll, ll> T;

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

const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void comb_init() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; 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;
    }
}

// 二項係数計算
long long 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;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b;
    cin>>a>>b;
    string ans="Impossible";
    if(a%3==0)ans="Possible";
    if(b%3==0)ans="Possible";
    if((a+b)%3==0)ans="Possible";
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>

typedef struct {
  double x;
  double y;
} Point;

double calcSlope(Point p1, Point p2) {
  return (p2.y - p1.y) / (p2.x - p1.x);
}

int main(void) {
  int i;
  Point p1, p2, p3, p4;

  scanf("%d", &i);

  while (i--) {
    scanf("%lf %lf %lf %lf %lf %lf %lf %lf", &p1.x, &p1.y, &p2.x, &p2.y, &p3.x, &p3.y, &p4.x, &p4.y);

    if (calcSlope(p1, p2) == calcSlope(p3, p4))
      printf("YES\n");
    else
      printf("NO\n");
  }

  return 0;
}

Measured memory_bytes: 620
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <tuple>
using namespace std;
using ll=long long;
using R=double;


int main(){
	ll Q,H,S,D,N;
	cin >> Q >> H >> S >> D;
	cin >> N;

	ll mini1;
	if(4*Q <= 2*H){
		mini1 = 4*Q;
	}else{
		mini1 = 2*H;
	}

	if(mini1 >= S){
		mini1 = S;
	}

	ll mini2;
	if(2*mini1 <= D){
		mini2 = 2*mini1;
	}else{
		mini2 = D;
	}

	ll result = (N/2)*mini2 + (N%2)*mini1;

	cout << result << endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main{
	private static Scanner scan = new Scanner(System.in);
	public static void train(){
		int N = scan.nextInt(), i = scan.nextInt();
		System.out.println(N-i+1);
	}
	public static void gritCompression(){
		int H = scan.nextInt(), W = scan.nextInt();
		char[][] array = new char[H][W];
		
		//入力
		for(int i=0;i<H;i++){
			array[i] = scan.next().toCharArray();
		}
		System.out.println();
		
		ArrayList<Integer> line = new ArrayList<>(); //出力しない列
		ArrayList<Integer> row = new ArrayList<>();  //出力しない行
		
		//行のみ見る
		for(int i=0;i<H;i++){
			boolean flag = false;
			for(int j=0;j<W;j++){
				if(array[i][j]=='#'){
					flag = true;
					break;
				}
			}
			if(flag){row.add(i);}
		}
		
		//列を見る．
		for(int j=0;j<W;j++){
			boolean flag = false;
			for(int i=0;i<H;i++){
				if(array[i][j]=='#'){
					flag = true;
					break;
				}
			}
			if(flag){
				line.add(j);
			}
		}
		
		//出力
		for(int i=0;i<H;i++){
			if(row.contains(i)){
				for(int j=0;j<W;j++){
					if(line.contains(j)){
						System.out.print(array[i][j]);
					}
				}
				System.out.println();
			}
		}
	}
	
	public static void candles(){
		int n = scan.nextInt(), k = scan.nextInt();
		//全組み合わせの探索 端からK個の組を順番に全探索
		int[] array = new int[n];
		for(int i=0;i<n;i++)
			array[i] = scan.nextInt();
		//ある組み合わせの最小値
		int min = Integer.MAX_VALUE;
		for(int i=0;i<n-k+1;i++){
			int leftSum = Math.abs(array[i]) + Math.abs(array[i+k-1] - array[i]);
			int rightSum = Math.abs(array[i+k-1]) + Math.abs(array[i+k-1] - array[i]);
			int sum = Math.min(rightSum, leftSum);
			if(min>sum)
				min = sum;
		}
		System.out.println(min);
		
	}
	
	public static void main(String[] argv){
		//gritCompression();
		candles();
	}
}

Measured memory_bytes: 49548
import sys
import collections

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def main():
    S = input().strip()
    c = collections.Counter(S)

    for i in range(26):
        if c[chr(ord('a') + i)] == 0:
            print(S + chr(ord('a') + i))
            return

    for j in range(len(S) - 1, -1, -1):
        x = ord(S[j]) - ord('a')
        c[S[j]] -= 1
        for i in range(x + 1, 26):
            if c[chr(ord('a') + i)] == 0:
                print(S[:j] + chr(ord('a') + i))
                return

    print(-1)


if __name__ == '__main__':
    main()


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

int N;
char C[100010];

char change(char a,char b){
    if(a==b) return 'T';
    if(a=='F' || b=='T') return 'T';
    else return 'F';
}

int main() {
    cin >> N;
    for(int i=1;i<=N;i++){
        cin >> C[i];
    }
    char ans = change(C[1],C[2]);
    for(int i=3;i<=N;i++){
        ans = change(ans,C[i]);
    }
    cout << ans << endl;
}   



Measured memory_bytes: 3172
using System;
class   ClassSD{
  
static void Main(){
while(true)
{
string a=Console.ReadLine();
if(a=="-"){break;}
int n=int.Parse(Console.ReadLine());
int []x=new int[n];
int sums=0;
for(int i=0;i<n;i++){
x[i]=int.Parse(Console.ReadLine());
 sums+=x[i];
}
int sum=sums%a.Length;
Console.WriteLine(a.Substring(sum)+a.Substring(0,sum));
  
  
}
/////////////////////
  
  
}
  
}

Measured memory_bytes: 9036
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<iomanip>

using namespace std;

typedef long long ll;

typedef std::pair<int, int> ipair;
bool lessPair(const ipair& l, const ipair& r){return l.second < r.second;}
bool morePair(const ipair& l, const ipair& r){return l.second > r.second;}

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;
}

const ll MOD = 1e9 + 7;
// const long long INF = 1LL<<60;
void add(long long &a, long long b) { a += b; if (a >= MOD) a -= MOD; }
void sub(long long &a, long long b) { a -= b; if (a < 0) a += MOD; }
void mul(long long &a, long long b) { a *= b; a %= MOD; }
ll llmin(ll a, ll b) { if (a < b) return a; else return b; }
ll llmax(ll a, ll b) { if (a < b) return b; else return a; }
ll llabs(ll a) { if (a >= 0) return a; else return - a; }
ll llmodpow(ll a, ll n) {
   if (n == 0) return 1;
   ll tmp = llmodpow(a, n / 2);
   mul(tmp, tmp);
   if (n & 1) mul(tmp, a);
   return tmp;
}

int main() {
   int N;
   cin >> N;
   ll a[N + 1];
   ll b[N];
   for (int i = 0; i <= N; i++) cin >> a[i];
   for (int i = 0; i < N; i++) cin >> b[i];

   ll ans = 0;
   for (int i = 0; i < N; i++) {
      ll MIN;
      MIN = llmin(a[i], b[i]);
      a[i] -= MIN;
      ans += MIN;
      b[i] -= MIN;
      MIN = llmin(a[i + 1], b[i]);
      a[i + 1] -= MIN;
      ans += MIN;
      b[i] -= MIN;
   }
   cout << ans << endl;
   return 0;
}


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

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

int main()
{
    string t;
    cin >> t;
    long num = t.size() - 1;
    rep(i, t.size())
    {
        if (t.at(i) == '?')
        {
            if (i == 0)
            {
                    t.at(i) = 'D';
            }
            else if (i == num)
            {
                t.at(i) = 'D';
            }
            else
            {
                if (t.at(i - 1) == 'P')
                {
                    t.at(i) = 'D';
                }
                else if (t.at(i + 1) == 'P')
                {
                    t.at(i) = 'D';
                }
                else
                {
                    t.at(i) = 'D';
                }
            }
        }
    }
    cout << t << endl;
    return 0;
}

Measured memory_bytes: 3764
(defun calc-cost (p xs)
  (loop for x in xs
        sum (expt (- x p) 2)))

(defun solve (n xs)
  (declare (ignore n))
  (loop for i from (first xs) to (car (last xs))
        minimize (calc-cost i xs)))

#-swank
(let* ((n (read))
       (xs (loop repeat n collect (read))))
  (format t "~A~%" (solve n (sort xs #'<))))


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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define UB upper_bound
#define LB lower_bound
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

// G13E_5.cpp

const LL MOD = 1000000007;

void mat_prod(LL a[3][3], LL b[3][3], LL c[3][3]) { // a = b * c;
	LL d[3][3];
	inc(i, 3) {
	inc(j, 3) {
		d[i][j] = 0;
	}
	}
	
	inc(i, 3) {
	inc(j, 3) {
	inc(k, 3) {
		(d[i][j] += b[i][k] * c[k][j]) %= MOD;
	}
	}
	}
	
	inc(i, 3) {
	inc(j, 3) {
		a[i][j] = d[i][j];
	}
	}
}

void mat_exp(LL a[3][3], LL b[3][3], LL c) { // a = b ^ c;
	LL t[60][3][3];
	
	LL cc = c, d = 0;
	while(cc) { cc >>= 1; d++; }
	
	inc(i, 3) {
	inc(j, 3) {
		t[0][i][j] = b[i][j];
	}
	}
	inc(i, d - 1) {
		mat_prod(t[i + 1], t[i], t[i]);
	}
	
	inc(i, 3) {
	inc(j, 3) {
		a[i][j] = 0;
	}
	}
	inc(i, 3) { a[i][i] = 1; }
	inc(i, d) {
		if((c >> i) & 1) {
			mat_prod(a, a, t[i]);
		}
	}
}



LL n, m, x[100002];

int main() {
	cin >> n >> m;
	inc1(i, m) { cin >> x[i]; }
	x[0] = 0;
	x[m + 1] = n + 1;
	
	LL a[3][3] = { { 2, 1, 1 }, { 2, 1, 0 }, { 1, 1, 1 } };
	LL b[3][3] = { { 1, 0, 0 }, { 2, 1, 0 }, { 1, 1, 1 } };
	LL c[3][3] = { { 1, 0, 0 }, { 0, 1, 0 }, { 0, 0, 1 } };
	LL d[3][3];
	
	inc(i, m + 1) {
		if(i != 0) { mat_prod(c, b, c); }
		mat_exp(d, a, x[i + 1] - x[i] - 1);
		mat_prod(c, d, c);
	}
	
	cout << c[2][0] << endl;
	
	return 0;
}


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


int main() {
    ll a,b,k;
    cin>>a>>b>>k;

    if(a+b<=k) cout<<0<<" "<<0<<endl;
    else if(a>=k) cout<<a-k<<" "<<b<<endl;
    else cout<<0<<" "<<b-(k-a)<<endl;

    return 0;
}

Measured memory_bytes: 256
#![allow(unused_imports)]
use proconio::{input, fastout};
use proconio::marker::*;
use smallvec::alloc::collections::BinaryHeap;

#[fastout]
fn main() {
    input! {
    n: usize,
    k: usize,
    a: [usize; n]
    }
    let (mut s, mut t) = (0, std::usize::MAX);
    while s + 1 < t {
        let mid = (s + t) / 2;
        if is_ok(&a, k, mid) {
            t = mid
        } else {
            s = mid
        }
    }
    println!("{}", t);
}

fn is_ok(a: &Vec<usize>, k: usize, d: usize) -> bool {
    let mut count = 0;
    for &i in a {
        count += i / d + if i % d == 0 {0} else {1} - 1;
    }
    count <= k
}



Measured memory_bytes: 5348
import java.util.ArrayList;
import java.util.Scanner;

class Main{

	public static void main(String[] args) {




		Scanner scan = new Scanner(System.in);
		int H = scan.nextInt();	
		int W = scan.nextInt();	
		int D = scan.nextInt();
		int[] x = new int[H*W+1];
		int[] y = new int[H*W+1];

		for(int i= 0;i < H;i++){
			for(int j= 0;j < W;j++){
				int tmp = scan.nextInt();
				x[tmp] = i;
				y[tmp] = j;
			}
		}
		int Q = scan.nextInt();	
		int[] L = new int[Q];
		int[] R = new int[Q];
		for(int i = 0;i < Q;i++){
			L[i] = scan.nextInt();
			R[i] = scan.nextInt();
		}

		int[] memo = new int[H*W+1];
		 for(int i = D+1;i < H*W+1;i++){
			 memo[i] = memo[i -D] + Math.abs(x[i] - x[i -D])+ Math.abs(y[i] - y[i-D]);
		 }
		 
		 for(int i = 0;i < Q;i++){
			 System.out.println(memo[R[i]] - memo[L[i]]);
		 }





	}






}


Measured memory_bytes: 94516
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <string>
#include <numeric>
#include <cmath>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
#define FOR(a, b, c) for (int (a) = (b); (a) < (c); ++(a))
#define REP(i, n) FOR(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))

int main() {
    int d, t, s;
    cin >> d >> t >> s;
    if ((float)d / (float)s <= t) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int r,D,x,y;
  cin >> r >> D >> x;
  y = 0;
  
  for (int i = 0; i < 10; i++){
    x = r*x-D; 
    cout << x << endl;
  }
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
typedef int64_t Int;

using namespace std;
using Graph = vector<vector<Int>>;

const double pi = M_PI;
const Int MOD = 1000000007;

int main() {
    int a, b;
    cin >> a >> b;

    if (a % 2 == 1 && b % 2 == 1) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <numeric>
using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define REPL(i, n) for(ll i = 0; i < (ll)(n); i++)
#define LookV(array) for(auto iter = array.begin(); iter != array.end(); iter++) {cout << iter* << ", ";} cout << endl;

int main() {

  ll N, K;

  cin >> N >> K;

  vector<ll> x(N);
  REPL(i, N){
    cin >> x[i];
  }

  ll init_zero = N;
  REPL(i, N){
    if (x[i] > 0){
      init_zero = i;
      break;
    }
  }
  //cout << init_zero << endl;

  ll sum_x = 0;
  if (init_zero == 0) {
    sum_x = x[K-1];
  }else if (init_zero == N) {
    sum_x = -1 * x[N-K];
  }else{
    vector<ll> pos, neg;
    for (ll i = init_zero; i < N; i++){
      pos.push_back(x[i]);
    }
    for (ll i = init_zero - 1; i >= 0; i--){
      neg.push_back(-1 * x[i]);
    }
    // ll tmp = 0;
    // for (ll i = 0; i != neg.size(); i++){
    //   tmp = 2 * neg[i] + pos[]
    // }

    ll tmp = INF;

    if (init_zero + K - 1 <= N - 1) tmp = min(tmp, x[init_zero - 1 + K]);
    if (init_zero - K >= 0) tmp = min(tmp, -1 * x[init_zero - K]);

    for (ll i = 0; i < neg.size(); i++){
      if ((pos.size() >= K - i - 1) && (K - i - 1 > 0)){
        tmp = min(tmp, neg[i]*2 + pos[K - 2 - i]);
        tmp = min(tmp, neg[i] + pos[K - 2 - i] * 2);
      }

    }

    sum_x = tmp;


    //for (int i = 0; i != pos.size(); i++) cout << pos[i] << endl;
    ///for (int i = 0; i != neg.size(); i++) cout << neg[i] << endl;
  }

  cout << sum_x << endl;


  return 0;
}


Measured memory_bytes: 2424
/* 
	Author: ankrypt
*/


#include <bits/stdc++.h>

using namespace std;

#define MOD 1000000007
#define ll long long int
#define u64 unsigned long long int

int X, A;

int main() {
	scanf("%d %d", &X, &A);
	if(X < A) {
		printf("0\n");
	}
	else {
		printf("10\n");
	}
	return 0;
}
/*
	Powered by Buggy Plugin
*/


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

#define rep(i,a,b)                for(ll i=a;i<b;i++)
#define re(i,b)                for(ll i=0;i<b;i++)
#define repr(i,n)                for(ll i=n-1;i>=0;i--)
#define ll long long
#define ld long double
#define pll std::pair<ll, ll> 
#define ppll std::pair<ll, pll>
#define vll std::vector<ll> 
#define vpll std::vector<pll> 
#define vppll std::vector<ppll> 
#define mll std::unordered_map<ll, ll> 
#define mpll std::unordered_map<pll, ll>
#define mppll std::unordered_map<ppll, ll>
#define sll std::set<ll>
#define ff first
#define ss second
#define msll std::multiset<ll>
#define all(c) c.begin(), c.end()
#define allr(c) c.rbegin(), c.rend()
#define srt(x) sort(all(x))
#define rsrt(x) sort(allr(x))
#define eb emplace_back
#define pb push_back
#define s(yy) ll yy;cin>>yy
#define len length()
#define sz size()
const ll mod = 1e9 + 7;
const ll INF = 0x7FFFFFFFFFFFFFFF>>1;

/*#################################################### 
#                                                    #
#                     @author                        #
#                  Parth Lathiya                     #
#      https://www.cse.iitb.ac.in/~parthiitb/        #
#                                                    #
####################################################*/


int main()
{

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	#ifdef PARTH_LATHIYA_HOME

		freopen("C_in.txt","r",stdin);
	
		ll ttt,bkkk;
		cin>>ttt;
		bkkk=ttt;
		while(ttt--) {
			cout<<"Testcase - "<<bkkk-ttt<<"\n";
	#endif

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

	s(a);
	s(b);
	s(c);
	s(x);
	s(y);

	ll x1=x;
	ll y1=y;
	ll ans=0;

	if(2*c<=a+b) {
		x-=min(x1,y1);
		y-=min(x1,y1);
		ans+=min(x1,y1)*2*c;
		// cout<<min(x,y)<<2<<c<<" ";
		if(x)
			ans+=min(x*a,2*x*c);
		if(y)
			ans+=min(y*b,2*y*c);
	}
	else {
		ans+=a*x+y*b;
	}
	cout<<ans;


//--------------------------------------------------------------------------------------
	
	#ifdef PARTH_LATHIYA_HOME
		cout<<"\n"; }
	#endif

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		try(Scanner scanner = new Scanner(System.in)) {
			String data = scanner.nextLine();

			int ondo = Integer.parseInt(data);

			System.out.println(ondo >= 30 ? "Yes" : "No");
		}
	}
}


Measured memory_bytes: 35780
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int l,r,d;
  cin>>l>>r>>d;
  int c=0;
  for(int i=l;i<=r;++i)
  {
    if(i%d==0)
      c++;
  }
  cout<<c<<endl;
  return 0;
}

Measured memory_bytes: 3628
"use strict";
function main(input) {
    const line = input.split("\n");
    const N = parseInt(line[0]);
    const S = line[1];
    console.log(!(N % 2) ? S.slice(0, N / 2) === S.slice(N / 2) ? "Yes" : "No" : "No");
    return;
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 29520
import math
A, B, H, M = map(int, input().split())
 
tyousin = M*6
tansin = H*30 + M*0.5
 
kakudosa = abs(tyousin - tansin)
 
result_root = A**2 + B**2 - 2*A*B*math.cos(math.radians(kakudosa))
 
print(math.sqrt(result_root))

Measured memory_bytes: 62520
#include "bits/stdc++.h"
using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REP1(i, n) for(ll i = 1;i < n;i++)
#define REPR(i, n) for(ll i = n-1;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)

#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())

#define ll long long
#define ALL(a)  (a).begin(),(a).end()

#define pb(a) push_back(a)

int now,n,k,m;

bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}


int main(){
  int ans=0;
  cin >> n;
  // 入力
  REP(i,n){
    int t;
    cin>>t;
    ans+=t;
  }
  ans-=n;
  cout<<ans<<endl;
  return 0;
}

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

using namespace std;


int main()
{
   int A, B , C;

   cin >> A >> B >> C;
    if (A < B) {
   if (A < C && B > C) {
       cout << "Yes" << endl;
   } else {
       cout << "No" << endl;
   }
    } else {
        if (B < C && A > C) {
       cout << "Yes" << endl;
   } else {
       cout << "No" << endl;
   }
        
    }

   
    
    
    return 0;   
}

Measured memory_bytes: 256
import sys
n, x = [int(i) for i in sys.stdin.readline().split()]
x_ls = [int(i) for i in sys.stdin.readline().split()] + [x]
x_ls.sort()
diff_ls = [x_ls[i + 1] - x_ls[i] for i in range(n)]

def gcd(ls):
    while len(ls) > 0:
        _min = min(ls)
        ls = [i % _min for i in ls if i % _min > 0]
    return _min

res = gcd(diff_ls)
print(res)

Measured memory_bytes: 60184