akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
using System.Numerics;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            Solve();
            //Out.Flush();
            Read();
        }

        static void Solve()
        {
            (long K, long X) = Slice2<long>();
            for (var i = X - K + 1; i < X + K; ++i)
                Write($"{i} ");
        }


        static long Mod = (long)1e9 + 7;
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static public (T1 a, T2 b) Slice<T1, T2>()
        {
            var t = ReadLine().Split();
            return (
            (T1)Convert.ChangeType(t[0], typeof(T1)),
            (T2)Convert.ChangeType(t[1], typeof(T2)));
        }
        static public (T a, T b) Slice2<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)));
        }
        static public (T a, T b, T c) Slice3<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)),
            (T)Convert.ChangeType(t[2], typeof(T)));
        }
    }
}

Measured memory_bytes: 27508
n = int(input())
s = input()
cnt = s.count('R') * s.count('G') * s.count('B')
for i in range(n - 1):
  for j in range(i + 1, n):
    if 2 * j - i <= n - 1 and len(set([s[i], s[j], s[2 * j - i]])) == 3:
      cnt -= 1
print(cnt)

Measured memory_bytes: 73784
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		Console.WriteLine(S.IndexOf("AC") >= 0 ? "Yes" : "No");
		
		
	}
	String S;
	public Sol(){
		S = rs();
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


Measured memory_bytes: 11352
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define pb push_back
#define fi first
#define se second
const int maxn=1e5+10;
const int mod=1e9+7;
const int inf=0x3f3f3f3f;
ll qpow(ll a,int b)
{
	ll ans=1;
	while(b)
	{
		if(b&1) ans=ans*a%mod;
		a=a*a%mod;
		b>>=1;
	}
	return ans;
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int x,y;
	cin>>x>>y;
	if((x+y)%3||2*x<y||2*y<x) cout<<0<<'\n';
	else
	{
		if(x<y) swap(x,y);
		ll sum=(x+y)/3,a=x-sum;
		ll ans=1,t=1;
		for(int i=2;i<=sum;i++) ans=ans*i%mod;
		for(int i=2;i<=a;i++) t=t*i%mod;
		ans=ans*qpow(t,mod-2)%mod;
		t=1;
		for(int i=2;i<=sum-a;i++) t=t*i%mod;
		ans=ans*qpow(t,mod-2)%mod;
		cout<<ans<<'\n';
	}
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using P = pair<int, int>;
using vec = vector<int>;
using mat = vector<vector<int>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

constexpr int MOD = 1000000007;
const int INF = 1 << 30;

int main() {
    int n, k;
    cin >> n >> k;
    vec x(n);
    rep(i, n) cin >> x[i];

    int res = INF;

    for (int i = 0; i + k - 1 < n; i++) {
        int l = x[i];
        int r = x[i+k-1];
        int d = r-l;
        res = min(res, d + abs(l));
        res = min(res, d + abs(r));
    }

    cout << res << endl;
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <cstdlib>
using namespace std;

#define INF 999999999.0

typedef pair< double,vector<int> > P;

int n;
int name[15],x[15],w[15];
P dp[15][1<<15];

P solve(int idx,int used,int weight){
	P res(0,vector<int>());
	res.second.push_back(name[idx]);

	if(used == (1<<n)-1) return res;
	if(dp[idx][used].first != INF) return dp[idx][used];

	res.first = INF;
	for(int i=0;i<n;i++){
		if((used & (1<<i)) == 0){
			P tmp = solve(i,used|(1<<i),weight+w[i]);
			tmp.first += abs(x[i] - x[idx]) / (2000.0 / (70+weight));
			if(res.first > tmp.first){
				res = tmp;
			}
		}
	}

	res.second.insert(res.second.begin(),name[idx]);

	return dp[idx][used] = res;
}

int main(void){
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>name[i]>>x[i]>>w[i];
		w[i] *= 20;
	}

	for(int i=0;i<n;i++){
		for(int j=0;j<(1<<n);j++){
			dp[i][j] = P(INF,vector<int>());
		}
	}

	P ans(INF,vector<int>());
	for(int i=0;i<n;i++){
		P tmp = solve(i,1<<i,w[i]);
		if(ans.first > tmp.first) ans = tmp;
	}

	for(int i=0;i<n-1;i++) cout<<ans.second[i]<<" ";
	cout<<ans.second[n-1]<<endl;

	return 0;
}

Measured memory_bytes: 19000
#include <iostream>
#include <string>
#include <vector>
using namespace std;
vector<int> V;
int main() {
	int n,m;
	while(cin>>n,n) {
		cin>>m;
		string str;
		cin>>str;
		V.clear();
		int i;
		for(i=0;i<(m-2);i++) {
			if(str.substr(i,3)=="IOI") {
				int count=1;
				for(i+=3;i<(m-1);i+=2) {
					if(str.substr(i,2)=="OI") count++; else break;
				}
				V.push_back(count);
				i--;
			}
		}
		int sum=0;
		for(i=0;i<V.size();i++) {
			if(V[i]>=n) sum+=(V[i]-n+1);
		}
		cout<<sum<<endl;
	}
}

Measured memory_bytes: 2152
#include<stdio.h>
#include<limits.h>
#define MAX 2000010

int heap[MAX];
int heap_size=0;

int parent(int i){
  return i/2;
}

int left(int i){
  return 2*i;
}

int right(int i){
  return 2*i+1;
}

void maxHeapify(int i){
  int a, l, r, largest;
  l = i * 2;
  r = i * 2 + 1;
  if (l <= heap_size && heap[i] < heap[l]) largest = l;
  else largest = i;
  if (r <= heap_size && heap[largest] < heap[r]) largest = r;
  if (largest != i) {
    a = heap[i];
    heap[i] = heap[largest];
    heap[largest] = a;
    maxHeapify(largest);
  }
}

void builtMaxHeap(void){
  int i;
  for(i=heap_size/2; i>0; i--){
    maxHeapify(i);
  }
}

void heapIncreaseKey(i, key){
  int tmp;
  if(key<heap[i])return;
  heap[i]=key;
  while(i>1 && heap[parent(i)] < heap[i]){
    tmp = heap[i];
    heap[i] = heap[parent(i)];
    heap[parent(i)]=tmp;
    i=parent(i);
  }
}

void maxHeapInsert(int key){
  heap_size+=1;
  heap[heap_size]=-INT_MAX;
  heapIncreaseKey(heap_size, key);
}

void aaaaa(int a){
  int i, count=0;
  for(i=0; i<a; i++){
    count++;
  }
}

int heapExtractMax(){
  int max, a=10;
  if(heap_size<1)return;
  max=heap[1];
  heap[1]=heap[heap_size];
  heap_size-=1;
  maxHeapify(1);
  return max;
}

int main(){
  int i=1, n, pri, a=10;
  char com[10];
  while(1){
    scanf("%s", com);
    if(com[0]=='i'){
      scanf("%d", &heap[i]);
      maxHeapInsert(heap[i]);
      i++;
    }
    else if(com[1]=='x'){
      pri=heapExtractMax();
      if(pri!=-1)printf("%d\n", pri);
    }
    else break;
  }
  aaaaa(a);
  return 0;
}



Measured memory_bytes: 7604
import os
import sys

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

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

S = sys.stdin.readline().rstrip()

mods = [0] * 13
if S[-1] == '?':
    for i in range(10):
        mods[i] = 1
else:
    mods[int(S[-1])] = 1
base = 10
# 後ろから見てく
for i in range(1, len(S)):
    c = S[~i]
    if c == '?':
        aa = list(range(10))
    else:
        aa = [int(c)]
    nm = [0] * 13
    for a in aa:
        for i in range(13):
            nm[(base * a + i) % 13] += mods[i] % MOD
    mods = nm
    base *= 10
    base %= 13

print(mods[5] % MOD)


Measured memory_bytes: 42348
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

void pakuri_sort(int N, int A[]) {
	const int b = 8;
	int tmp[100001];
	rep(k, 4) {
		int kazu[1 << b] = {}, kazu2[1 << b] = {};
		rep(i, N) kazu[A[i] >> k * b & ((1 << b) - 1)]++;
		rep(i, (1 << b) - 1) kazu[i + 1] += kazu[i];
		for (int i = N - 1; i >= 0; i--) tmp[--kazu[A[i] >> k * b & ((1 << b) - 1)]] = A[i];
		k++;
		rep(i, N) kazu2[tmp[i] >> k * b & ((1 << b) - 1)]++;
		rep(i, (1 << b) - 1) kazu2[i + 1] += kazu2[i];
		for (int i = N - 1; i >= 0; i--) A[--kazu2[tmp[i] >> k * b & ((1 << b) - 1)]] = tmp[i];
	}
}

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

	int N = getint(), H = getint();
	int saidai = 0;
	int b[100000];
	rep(i, N) {
		saidai = max(saidai, getint());
		b[i] = getint();
	}

	pakuri_sort(N, b);

	int kaisuu = 0;
	rep(i, N) {
		if (b[N - i - 1] > saidai) {
			kaisuu++;
			H -= b[N - i - 1];
			if (H <= 0) break;
		}
	}

	if (H > 0) {
		kaisuu += (H + saidai - 1) / saidai;
	}
	printf("%d", kaisuu);

	Would you please return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#define endl "\n"
using namespace std;

int main()
{
    string O;
    string E;
    cin >> O >> E;

    for(int i = 0; i < min(O.length(), E.length()); i ++)
    	cout << O[i] << E[i];

    if(O.length() > E.length())
    	cout << O[O.length() - 1];
}

Measured memory_bytes: 256
n,k = map(int, input().split())

cnt = []
for i in range(n):
    cnt.append(0)

for i in range(k):
    d = int(input())
    ar = list(map(int, input().split()))
    for a in ar:
        cnt[a-1] += 1

ans = 0
for i in range(n):
    if cnt[i] == 0:
        ans += 1

print(ans)

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

const int INF = 1e9;

int n,k;
int li[105];

int memo[55][55][105];

int dp(int l, int r, int s){
  if(s<0) return -INF;
  if(s==0) return 0;
  if(l>r) return 0;
  int &ret = memo[l][r][s];
  if(ret!=-1) return ret;
  ret = max(dp(l+1,r,s-2) , dp(l,r-1,s-2));
  ret = max(ret,dp(l+1,r,s-1)+li[l]);
  ret = max(ret,dp(l,r-1,s-1)+li[r]);
  return ret;
}

int main(){
  memset(memo,-1,sizeof(memo));
  scanf("%d%d",&n,&k);
  for(int i=1;i<=n;i++){
    scanf("%d",&li[i]);
  }
  int ans = 0;
  for(int i=0;i<=k;i++) ans = max(ans,dp(1,n,i));
  printf("%d\n",ans);
  return 0; 
}

Measured memory_bytes: 1536
a=[input() for i in range(5)]
for i in range(5):
    a[i]=int(a[i])
if a[0]<=40:
    a[0]=40
if a[1]<=40:
    a[1]=40
if a[2]<=40:
    a[2]=40
if a[3]<=40:
    a[3]=40
if a[4]<=40:
    a[4]=40
x=a[0]+a[1]+a[2]+a[3]+a[4]
print(x//5)



Measured memory_bytes: 5604
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 4000001;

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

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

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

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

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};

class mint {
    long long x;
public:
    mint(long long x = 0) : x((x% MOD + MOD) % MOD) {}
    mint operator-() const {
        return mint(-x);
    }
    mint& operator+=(const mint& a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator-=(const mint& a) {
        if ((x += MOD - a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator*=(const  mint& a) {
        (x *= a.x) %= MOD;
        return *this;
    }
    mint operator+(const mint& a) const {
        mint res(*this);
        return res += a;
    }
    mint operator-(const mint& a) const {
        mint res(*this);
        return res -= a;
    }
    mint operator*(const mint& a) const {
        mint res(*this);
        return res *= a;
    }

    mint operator^(const ll& t)const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }
    // for prime MOD
    mint inv() const {
        return pow(MOD - 2);
    }
    mint& operator/=(const mint& a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint& a) const {
        mint res(*this);
        return res /= a;
    }

    friend ostream& operator<<(ostream& os, const mint& m) {
        os << m.x;
        return os;
    }
};

//////////////////////////


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

    ll M = 1 << N;
    vector<ll> A(M);
    rep(i, M) cin >> A[i];

    vector<pair<ll, ll>> f(M);
    rep(i, M) f[i] = { A[i],-1 };

    rep(i, N) {
        rep(j, M) {
            if ((j >> i) & 1) {
                ll k = j ^ (1 << i);
                vector<ll> d(4);
                d[0] = f[j].first; d[1] = f[j].second; d[2] = f[k].first; d[3] = f[k].second;
                sort(d.begin(), d.end());
                f[j] = { d[3],d[2] };
            }
        }
    }

    vector<ll> ans(M,0);
    repn(j, M-1) {
        ans[j] = max(ans[j - 1], f[j].first + f[j].second);
        cout << ans[j] << endl;
    }
    


	system("PAUSE");
}

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

int main()
{
    int n , m ;
    cin >> n >> m ;
    vector <int> v[n] ;
    vector <int> V2 ;
    for(int i = 0 ; i < n ; i++)
    {
        for(int j = 0 ; j < m ; j++)
        {
            int G ;
            cin >> G ;
            v[i].push_back(G) ;
        }
    }
    for(int i = 0 ; i < m ; i++)
    {
        int G ;
        cin >> G ;
        V2.push_back(G) ;
    }
    for(int i = 0 ; i < n ; i++)
    {
        int sum = 0 ;
        for(int j = 0 ; j < m ; j++)
        {
            sum += v[i][j]*V2[j] ;
        }
        cout << sum << endl ;
    }
    return 0 ;
}


Measured memory_bytes: 3180
from math import sqrt
from math import ceil
n = int(input())
if n == 1:
    print (0)
    exit()
isP = [True] * (int(ceil(sqrt(n))))
op = 0
i = 2
n2 = n
for i in range(2, int(ceil(sqrt(n)))):
    if isP[i]:
        for j in range(2*i, int(ceil(sqrt(n))), i):
            isP[j] = False
for i in range(2, int(ceil(sqrt(n)))):
    if isP[i] and n % i == 0:
        j = i
        while n % j == 0:
            n //= j
            j *= i
            op += 1
if n > 1 and n > int(ceil(sqrt(n2))):
    op += 1

print (op)

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

int N, A, B, C;
int l[20];

int dfs(int i, int a, int b, int c) {
    if (i == N) {
        if (a != 0 && b != 0 && c != 0) return abs(a - A) + abs(b - B) + abs(c - C) - 30;
        else return 1e9;
    }
    int ret0 = dfs(i + 1, a, b, c);
    int ret1 = dfs(i + 1, a + l[i], b, c) + 10;
    int ret2 = dfs(i + 1, a, b + l[i], c) + 10;
    int ret3 = dfs(i + 1, a, b, c + l[i]) + 10;
    return min({ret0, ret1, ret2, ret3});
}

int main() {
    cin >> N >> A >> B >> C;
    for (int i = 0; i < N; i++) cin >> l[i];

    cout << dfs(0, 0, 0, 0) << endl;
    return 0;
}

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

public class Main {
	public static void main(String[] args) {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String str = null;
        try {
			str = in.readLine();
		} catch (IOException e) {
			e.printStackTrace();
		}

		Map<String, String> tmp = new HashMap<String, String>();
		for(String s : str.split(" ")){
			tmp.put(s, s);
		}
		System.out.println(tmp.size());
	}
}


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

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

    vector<int> food(M,0);
    int K, A;
    for(int i=0; i<N; ++i){
        cin >> K;
        for(int j=0; j<K; ++j){
            cin >> A;
            food[A-1]++;
        }
    }
    int res = 0;
    for(int i=0; i<M; ++i){
        if(food[i]==N) ++res;
    }

    cout << res << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<math.h>
#include<queue>
#include<cstdio>
#include<set>
#include<map>
using namespace std;

int main(){
    long long N;
    cin >> N;
    vector<long long> A(N);
    vector<long long> B(N+1,0);
    vector<long long> C(N+1);
    vector<long long> D(N);
    for(int i=0; i<N; i++){
        cin >> A.at(i);
        B.at(A.at(i)) += 1;
    }
    long long sum=0;
    for(int i=1; i<N+1; i++){
        long long k=B.at(i);
        C.at(i) = k*(k-1)/2; 
        sum += C.at(i);
    }
    for(int i=0; i<N; i++){
        long long l=A.at(i);
        long long k=B.at(l);
        D.at(i) = sum - k*(k-1)/2 + (k-1)*(k-2)/2;
    }
    for(int i=0; i<N; i++){
        cout << D.at(i) << endl;
    }
    return 0;
}


Measured memory_bytes: 8832
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include<bitset>

using namespace std;

#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<bool> vb;

ll n = 0, m = 0, k = 0, ans = 0, sum = 0, cnt = 0, temp = 0;
string s;
bool flag;

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


int main(void) {
  string a, b;
  double x;

  cin >> a >> b;

  a += b;

  x = sqrt(stoi(a));

  if (x == (ll)x) {
	cout << "Yes" << endl;
  }
  else {
	cout << "No" << endl;
  }

  return 0;
}

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

using namespace std;
typedef long long ll;

#define MOD (long long)(1e9+7)
#define REP(i,n) for(ll i = 0; i < n; i++)
#define REP1(i,n) for(ll i = 1; i <= n; i++)

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

int main(void)
{
  ll n, m, q; cin >> n >> m >> q;
  vector<ll> a(q), b(q), c(q), d(q); REP(i, q) cin >> a[i] >> b[i] >> c[i] >> d[i];
  vector<ll> A(n);
  REP(i, n) A[i] = 1;
  ll maxans = 0;
  REP(i, q) maxans += d[i];
  ll ans = 0;
  ll ma = 1;
  REP(i, n) ma *= m;

  REP(i, ma) {
    ll i0 = i;
    /*
    REP(j, n) {
      A[n - j - 1] = (i0 % m) + 1;
      i0 /= m;
    }
    */
    ll point = 0;
    bool ok = true;
    REP(j, n-1) {
      if(A[j+1]<A[j]) ok = false;
    }
    if(!ok) continue;

    //        REP(j, n) cout << A[j] << " ";

    
    REP(k, q) {
      if(A[b[k]-1] - A[a[k]-1] == c[k]) point += d[k];
    }
    //        cout << " : " << point << endl; 
    if(point > ans) ans = point;
    if(ans == maxans) break;

    A[n-1] ++; 
    for(ll k = n - 1; k >= 0; k--) {
      if(A[k] > m) {
	A[k-1] ++;
	for(ll l = k; l < n; l++) {
	  A[l] = A[k-1];
	}
      }
    }
    bool ok2 = true;
    REP(i, n) {
      if(A[i] != m) ok2 = false;
    }
    if(ok2) break;
  }
  
  cout << ans << endl;
}


Measured memory_bytes: 3636
#include <stdio.h>
int main(void){
    
    int a, b, d, r;
    double f;
    
    scanf("%d", &a);
    scanf("%d", &b);
    
    d=a/b;
    r=a%b;
    f=1.00000*a/b;
    
    printf("%d %d %.5f\n", d,r,f);
    
    return 0;
    
    
}



Measured memory_bytes: 2104
def solve(a,b):
  if a+b==0: return [""]
  if a>=5 and b<=4: return [s+"A" for s in solve(a-1,b)]
  if b>=5 and a<=4: return [s+"B" for s in solve(a,b-1)]
  res=[]
  if a>0: res+=[s+"A" for s in solve(a-1,b)]
  if b>0: res+=[s+"B" for s in solve(a,b-1)]
  return res

while 1:
  try: a,b=map(int,input().split())
  except: break
  for s in sorted(solve(a,b)):
    print(s)

Measured memory_bytes: 6724
#include<bits/stdc++.h>
#define ll long long

using namespace std;

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

Measured memory_bytes: 1792
s = gets.chomp
news = s.split('').uniq()
ans = 'No'
if news.length() == 4 && (news.include?('S') && news.include?('N') && news.include?('W') && news.include?('E'))
  ans = 'Yes'
elsif news.length() == 2 && ((news.include?('S') && news.include?('N')) || (news.include?('W') && news.include?('E')))
  ans = "Yes"
end

puts ans

Measured memory_bytes: 1916
x, y = map(int, input().split())
p = list(map(int, input().split()))
# 100まではOK
for diff in range(101):
    # xを軸に小さい数
    a = x - diff
    # pのなかに含まれない整数aだからnot in
    if a not in p:
        print(a)
        exit()
    # xを軸に大きい数
    a = x + diff
    if a not in p:
        print(a)
        exit()    


Measured memory_bytes: 9116
#include <bits/stdc++.h>
#define int long long int
using namespace std;

int n, w;
vector<int> v, wt;
vector<vector<int>> dp;

int func(int idx, int max_wt) {
	if(idx<0||idx>=n||max_wt<0||max_wt>=w) {
		return -1;
	}
	if(idx==0) {
		if(max_wt>=wt[0]-1)
			return dp[0][max_wt] = v[0];
		return dp[0][max_wt] = 0;
	}
	if(dp[idx][max_wt] != -1) {
		return dp[idx][max_wt];
	}

	if(max_wt>=wt[idx]-1) 
		return dp[idx][max_wt] = max(func(idx-1,max_wt), func(idx-1,max_wt-wt[idx])+v[idx] );
	return dp[idx][max_wt] = func(idx-1,max_wt);

}

signed main() {
	cin>>n>>w;

	v.resize(n);
	wt.resize(n);
	dp.resize(n, vector<int>(w,-1));

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

	cout<<func(n-1,w-1)<<endl;

	return 0;
}

Measured memory_bytes: 79360
class Card:
    def __init__(self,suit,value):
        self.suit=suit
        self.value=value
    def getCard(self):
        return self.suit + str(self.value)

def SelectionSort(C):
    A=C
    # sort
    for i in range(len(A)):
        mini=i
        for j in range(i,len(A)):
            if A[j].value<A[mini].value:
                mini=j
        if mini!=i:
            tmp=A[i]
            A[i]=A[mini]
            A[mini]=tmp
    return A

def BubbleSort(C):
    A=C
    for i in range(len(A)):
        for j in reversed(range(i+1,len(A))):
            if A[j].value < A[j-1].value:
                tmp=A[j]
                A[j]=A[j-1]
                A[j-1]=tmp
    return A

def getCardString(A):
    maplist=[]
    for a in A:
        maplist.append(a.getCard())
    return ' '.join(maplist)

n=int(input())
cardsA=[]
cardsB=[]
for data in input().split():
    charList=list(data)
    cardsA.append(Card(charList[0],int(charList[1])))
    cardsB.append(Card(charList[0],int(charList[1])))
bubble=getCardString(BubbleSort(cardsA))
select=getCardString(SelectionSort(cardsB))
print(bubble)
print('Stable')
print(select)
print('Stable' if select==bubble else 'Not stable')





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

const long long M = 1000000007;

long long power(long long x, long long n){
	long long res = 1;
	if(n > 0){
		res = power(x, n / 2);
		if(n % 2 == 0) res = (res * res) % M;
		else res = (((res * res) % M) * x ) % M;
	}
	return res;
}

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

	long long MAX = x + y + z;
	long long s = (1 << (x + y + z - 1)) + (1 << (x + y - 1)) + (1 << (x - 1));
	long long mask = (1 << MAX) - 1;

	vector<vector<long long>> dp(n + 1, vector<long long>(1 << MAX));
	dp[0][0] = 1;
	rep(i,n){
		rep(j,1 << MAX){
			range(k,1,11){
				long long nbit = mask bitand ((j << k) + (1 << (k - 1)));
				if((nbit bitand s) == s) continue; // x, y, zを含んでしまう

				(dp[i + 1][nbit] += dp[i][j]) %= M;
			}
		}
	}

	long long sum = 0;
	rep(i,1 << MAX) (sum += dp[n][i]) %= M;

	cout << (power(10, n) - sum + M) % M << endl;
}


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

using namespace std;

const int MAX_N = (int) 1e5;
const int MAX_VAL = 2147483647; //(1 << 31) -1;
int n;
vector<int> dat;


void init(int n_) {
    n = 1;
    while (n < n_) n *= 2;
    for (int i = 0; i < 2 * n - 1; ++i) {
        // dat[i] = MAX_VAL;
        dat.push_back(MAX_VAL);
    }
}

void update(int k, int a) {
    k += n - 1;
    dat[k] = a;
    while (k > 0) {
        k = (k - 1) / 2;
        dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);
    }
}

int query(int a, int b, int k, int l, int r) {
    if (r <= a || b <= l) return MAX_VAL;

    if (a <= l && r <= b) {
        return dat[k];
    } else {
        int vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
        int vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
        return min(vl, vr);
    }
}

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

    int N, Q;
    cin >> N >> Q;

    init(N);

    for (int i = 0; i < Q; ++i) {
        int com, x, y;
        cin >> com >> x >> y;
        if (com == 0) {
            update(x, y);
        } else {
            cout << query(x, y + 1, 0, 0, n) << '\n';
        }
    }

    return 0;
}



Measured memory_bytes: 4120
#import<iostream>

main(){
    int_fast64_t N, X, P, r(0);
    std::cin >> N >> X;
    P = 1LL << N;
    while(X){
        if(!N){
            ++r;
            break;
        }
        if(X < 2 * P - 1)
            --X;
        else{
            r += P;
            X += 1 - P * 2;
        }
        --N;
        P >>= 1;
    }
    std::cout << r;
    puts("");
}

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

typedef long double ld;									// XD
#define int long long
#define PB push_back
#define all(x) (x).begin(),(x).end()
#define ii pair <int,int>
#define mii map <int,int>
#define vi vector<int>
#define vii vector< ii >
#define F first
#define S second
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define rep1(i,a,b) for(int i=a;i<=b;i++)
#define repd(i,a,b) for(int i=a; i>=b; --i)
#define sz(x) (int)((x).size())
#define mem(a,x) memset(a,x,sizeof(a))
const long double PI=3.141592653589793238462643383279502884197169399375105820974944;
inline void io(){
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}

const int mod = 1e9 + 7;
const int inf = 3e16;
const int maxn = 1e6+5;
bool  vis[maxn]; bool h[maxn], ok = 0;
void sieve(){
	for(int i=2; i<maxn; i++){
		if(!vis[i]){
			int cnt= 0;
			for(int j = i; j<maxn; j+=i){
				if(h[j]) cnt++;
				vis[j] = 1;
			}
			if(cnt > 1) ok =1;
		}
	}
}
void solve(){
	int n; cin>>n;
	int a[n];
	rep(i, 0, n){
		cin>>a[i];
		if(a[i] > 1 && h[a[i]]) ok = 1; 
		h[a[i]] = 1;
	}
	sieve();
	int x = a[0];
	rep(i, 0, n){
		x = __gcd(x, a[i]);
	}
	if(!ok){
		cout<<"pairwise coprime";
	}else if(x == 1){
		cout<<"setwise coprime";
	}else{
		cout<<"not coprime";
	}
}
signed main()
{
    ios_base::sync_with_stdio(false);cin.tie(0); //io();
    //cout<<setprecision(12);
    int tc=1;// cin>>tc;
    while(tc--){
        solve();cout<<'\n';
    }
    return 0;
}


Measured memory_bytes: 13264
#include <iostream>
#include <vector>
//#include<bits/stdc++.h>
#include <algorithm>
using namespace std;

class Question{
  public:
  int m_l,m_r;
  Question(int l,int r){
    m_l = l;
    m_r = r;
  }
    bool operator<(const Question &another) const
  {
    return m_l < another.m_l;
  };
};

int main(){
  int N,Q;
  string S;
  cin >> N >> Q >> S;
  vector<int> ans(Q),hoge;
  //vector<Question> quest;
  int cnt = 0;
  for(int i = 0; i < S.length()-1; i++){
    if(S[i] == 'A'&&S[i+1]=='C'){
      hoge.push_back(cnt++);
    }else{
      hoge.push_back(cnt);
    }
  }
  hoge.push_back(cnt);
  for( int i = 0; i < Q; i++){
    int tmpl,tmpr;
    cin >> tmpl >> tmpr;
    //quest.push_back(Question(tmpl,tmpr));
    ans[i] = hoge[tmpr-1] - hoge[tmpl-1];
  }
  for(int i = 0;i<hoge.size();i++){
    //cout << hoge[i];
  } 
  //cout << endl;
  for( int i = 0; i < Q; i++){
    cout << ans[i] << endl;
  }
}

Measured memory_bytes: 1912
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = long long;
using std::cout;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

int main() {
	int n; scanf("%d", &n); std::vector<std::vector<std::pair<int, int>>> g(n);
	for(int i = 0; i < n - 1; i++) {
		int a, b, c; scanf("%d%d%d", &a, &b, &c);
		
		g[a - 1].push_back({b - 1, c % 2});
		g[b - 1].push_back({a - 1, c % 2});
	}
	
	std::vector<int> ans(n, -1);
	std::function<void (int, int, int)> solve = [&](int v, int par, int color) {
		ans[v] = color;
		for(auto e: g[v]) {
			if(e.first == par) continue;
			if(!e.second) solve(e.first, v, color);
			else solve(e.first, v, 1 - color);
		}
	};
	solve(0, -1, 0);
	
	for(auto v: ans) printf("%d\n", v);
	return 0;
}


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

def main():
    H,W = map(int,input().split())

    # 番兵法 (#を外周に設置する)
    visited = [[True]*(W+2)]
    visited += [[True] + [x == '#' for x in input().rstrip()] + [True] for _ in range(H)]
    visited.append([True]*(W+2))

    # #の位置をqに格納
    q = []
    for i in range(1,H+1):
        for j in range(1,W+1):
            if visited[i][j]:
                q.append((i,j))

    # dx,dyを使用せずにBFS 
    # 定数倍改善
    ans = -1
    while q:
        qq = []
        # 新たに#となった地点をqqに格納
        for x,y in q:
            if not visited[x-1][y]:
                visited[x-1][y] = True
                qq.append((x-1,y))
            if not visited[x+1][y]:
                visited[x+1][y] = True
                qq.append((x+1,y))
            if not visited[x][y-1]:
                visited[x][y-1] = True
                qq.append((x,y-1))
            if not visited[x][y+1]:
                visited[x][y+1] = True
                qq.append((x,y+1))
        q = qq
        ans += 1
    
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 108200
from collections import defaultdict
N, M = map( int, input().split())
S = list( input())
E = [ list( map( int, input().split())) for _ in range(M)]
V = [ 1 for _ in range(N)]
Edges = [set() for _ in range(N)]
A = [0]*N
B = [0]*N
d = defaultdict(int)
for i in range(M):
    a, b = E[i]
    a, b = a-1, b-1
    a, b = min(a,b), max(a,b)
    Edges[a].add(b)
    Edges[b].add(a)
    if d[(a,b)] == 1:
        continue
    else:
        d[(a,b)] += 1
    if a == b:
        if S[a] == 'A':
            A[a] += 1
        else:
            B[a] += 1
        continue
    if S[a] == 'A':
        A[b] += 1
    else:
        B[b] += 1
    if S[b] == 'B':
        B[a] += 1
    else:
        A[a] += 1
T = set()

for i in range(N):
    if A[i] == 0 or B[i] == 0:
        T.add(i)
while T:
    n = T.pop()
    V[n] = 0
    for m in Edges[n]:
        if V[m] == 1:
            if S[n] == 'A':
                A[m] -= 1
                if A[m] == 0:
                    T.add(m)
            else:
                B[m] -= 1
                if B[m] == 0:
                    T.add(m)
                
if sum(V) == 0:
    print('No')
else:
    print('Yes')

Measured memory_bytes: 147500
#include <bits/stdc++.h>
#define PI 3.14159265359
#define NIL (-1)
#define LL long long
using namespace std;
const int64_t MOD = 1e9 + 7;
const int INF = INT_MAX;

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

	if (N >= M) {
		cout << 0 << endl;
		return 0;
	}

	vector<int> v(M), dif(M - 1);
	for (int i = 0; i < M; i++) cin >> v[i];
	sort(v.begin(), v.end());

	for (int i = 1; i < M; i++) dif[i - 1] = abs(v[i] - v[i - 1]);
	sort(dif.begin(), dif.end());

	int n = M - N;
	int sum = 0;
	for (int i = 0; i < n; i++) {
		sum += dif[i];
	}
	cout << sum << endl;
}

Measured memory_bytes: 3928
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;



signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    ll n;
    cin>>n;
    ll sum = 0;
    ll mi = 1e14;
    for(int i=0;i<n;i++){
        ll a;
        cin>>a;
        sum += a;
        mi = min(a,mi);
    }
    if(n%2){
        if(sum%2){
            cout << "First" << endl;
        }
        else cout << "Second" << endl;
    }
    else{
        if(mi%2 || sum%2)cout << "First" << endl;
        else cout << "Second" << endl;
    }
}


Measured memory_bytes: 3188
#include <iostream>
using namespace std;
int main()
{
   int a,b,c,d;
   
   cin>>a>>b>>c>>d;
  
  if((a+b)>(c+d))
  cout<<"Left"<<endl;
  else if((a+b)<(c+d))
  cout<<"Right"<<endl;
  else
  cout <<"Balanced"<<endl;
}

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

int H, W;
const int MAX_H = 50 + 10;
string S[MAX_H];

int main() {
    cin >> H >> W;
    for (int i = 0; i < H; i++) cin >> S[i];

    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (S[i][j] == '.') {
                int cnt = 0;
                for (int dx = -1; dx <= 1; dx++) {
                    for (int dy = -1; dy <= 1; dy++) {
                        if (0 <= i+dx && i+dx < H && 0 <= j+dy && j+dy < W) {
                            if (S[i+dx][j+dy] == '#') {
                                cnt++;
                            }
                        }
                    }
                }
                S[i][j] = '0' + cnt;
            }
        }
    }

    for (int i = 0; i < H; i++) {
        cout << S[i] << endl;
    }
    
    return 0;
}


Measured memory_bytes: 256
// vvvvvvvvvvvv TEMPLATE vvvvvvvvvvvv
#include <bits/stdc++.h>
using namespace std; using ll = long long; using P = pair<ll, ll>;
const ll linf = 1e18; const double eps = 1e-12, pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define each(i,a) for (auto&& i : a)
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
#define pb push_back
#define eb emplace_back
#define all(a) begin(a),end(a)
#define chmin(x,v) x = min(x, v)
#define chmax(x,v) x = max(x, v)
#define min(x,y) (x < y ? x : y)
#define max(x,y) (x < y ? y : x)
template<typename Head> void out(Head h) { cout << h << endl; } template<typename Head, typename... Tail>void out(Head h, Tail... t) { cout << h << " "; out(t...); }
template<typename T> istream& operator>>(istream& is, vector<T>& v) { each(x,v) is >> x; return is; }
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) { rep(i,v.size()) { if (i) os << " "; os << v[i]; } return os; }
ostream& operator<<(ostream& os, const vector<string>& v) { rep(i,v.size()) { if (i) os << endl; os << v[i]; } return os; }
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) { rep(i,v.size()) { if (i) os << endl; os << v[i]; } return os; }
template<typename T1, typename T2> ostream& operator<<(ostream& os, const pair<T1, T2>& p) { return os << "(" << p.first << ", " << p.second << ")"; }
struct yes_no : std::numpunct<char> { string_type do_truename() const { return "Yes"; } string_type do_falsename() const { return "No"; } };
void solve(); int main() {
  ios::sync_with_stdio(false); cin.tie(0); locale loc(locale(), new yes_no); cout.imbue(loc); cout << fixed << setprecision(10) << boolalpha;
  solve();
}
// ^^^^^^^^^^^^ TEMPLATE ^^^^^^^^^^^^

void solve() {
  ll A, B, C; cin >> A >> B >> C;
  ll ans = B + min(C, A + B + 1);
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>

#define REP(i,n) for(int i=0; i<n; i++)
#define debug(x) cerr << #x << " = " << (x) << endl;

using namespace std;

int main(){
	int n, a[100000], q, k, l, r, m, ans;
	cin >> n;
	REP(i,n) cin >> a[i];
	cin >> q;
	REP(i,q){
		cin >> k;
		l = 0;
		r = n;
		m = -1;
		ans = 0;
		if (k<0){
			cout << 0 << endl;
			continue;
		}
		while(1){
			m = (r+l)/2;
			//printf("r=%d, l=%d, m=%d\n", r, l, m);
			if (a[m]==k){
				ans = 1;
				break;
			}
			if (m==r || m==l) break;
			if (k<a[m]) r = m;
			else l = m;
		}
		cout << ans << endl;
	}
	return 0;
}



Measured memory_bytes: 3508
def dfs (graph, used, from, sink, flow)
  return flow if from == sink
  used[from] = true
  
  graph[from].each{|edge|
    next if used[edge[0]] || (edge[1]<=0)
    
    fmin = edge[1]
    fmin = flow if fmin > flow
    
    d = dfs(graph, used, edge[0], sink, fmin)
    
    if d > 0 then
      edge[1] -= d
      graph[edge[0]][edge[2]][1] += d
      return d
    end
  }
  return 0
end

def addedge graph,from,to
  cap = 1
  graph[from]<<[to,cap,graph[to].size]
  graph[to]<<[from,0,graph[from].size-1]
end

n = gets.to_i
red = n.times.map{gets.split.map &:to_i}
blue = n.times.map{gets.split.map &:to_i}

s = n*2
t = s+1
inf = 100000000

graph = (n*2+2).times.map{[]}
used = Array.new(n*2+2, false)

n.times{|i|
  addedge(graph,s,i)
}
n.times{|i|
  addedge(graph,n+i,t)
}

red.each.with_index{|(x1,y1),i|
  blue.each.with_index{|(x2,y2),j|
    if x1<x2 && y1<y2
      addedge(graph,i,n+j)
    end
  }
}


flow = 0
while 1
  (n*2+2).times{|i| used[i]=false}
  f = dfs(graph, used, s, t, inf)
  break if f==0
  flow += f
end

p flow

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

#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define debug3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define debugB(x, y) cerr<<#x<<": "<<bitset<y>(x) << endl;
#define line() cerr << "---------------" << endl;

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

template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

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

int H, W, D;
int px[100000], py[100000], sum[100000];

int main() {
   cin >> H >> W >> D;
   rep (i, H) {
      rep (j, W) {
         int A;
         cin >> A;
         px[A] = j, py[A] = i;
      }
   }

   for (int i = D+1; i <= H*W; i++) {
      sum[i] = sum[i-D] + abs(px[i] - px[i-D]) + abs(py[i] - py[i-D]);
   }

   int Q;
   cin >> Q;
   rep (i, Q) {
      int l, r;
      cin >> l >> r;
      cout << sum[r] - sum[l] << endl;
   }

   return 0;
}

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

#define REP(i, x) REPI(i, 0, x)
#define REPI(i, a, b) for (int i = int(a); i < int(b); ++i)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
using namespace std;

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

  string T;
  cin >> T;
  int l = (int)T.length();
  if (l == 1) {
    if (T.at(0) == '?') {
      cout << "D" << endl;
      return 0;
    }
  }

  if (l == 2) {
    if (T == "??" || T == "?D" || T == "P?") {
      T = "PD";
    } else if (T == "?P" || T == "D?") {
      T = "DP";
    }
    cout << T << endl;
    return 0;
  }

  if (l == 3) {
    int i = 1;
    char c1 = T.at(i - 1);
    char c2 = T.at(i);
    char c3 = T.at(i + 1);

    if (c1 == '?') {
      if (c2 == 'D' || c2 == '?') {
        c1 = 'P';
      } else {
        c1 = 'D';
      }
      T.at(i - 1) = c1;
    }

    if (c2 == '?') {
      if (c1 == 'D' && (c3 == 'D' || c3 == '?')) {
        c2 = 'P';
      } else {
        c2 = 'D';
      }
      T.at(i) = c2;
    }

    if (T.at(2) == '?') {
      T.at(2) = 'D';
    }

    cout << T << endl;
    return 0;
  }

  for (int i = 0; i < l - 3; ++i) {
    char c1 = T.at(i);
    char c2 = T.at(i + 1);
    char c3 = T.at(i + 2);
    char c4 = T.at(i + 3);

    if (c1 == '?') {
      if (c2 == 'D' || c2 == '?') {
        c1 = 'P';
      } else {
        c1 = 'D';
      }
      T.at(i) = c1;
    }

    if (c2 == '?') {
      if (c1 == 'D' && (c3 == 'D' || c3 == '?')) {
        c2 = 'P';
      } else {
        c2 = 'D';
      }
      T.at(i + 1) = c2;
    }

    if (c3 == '?') {
      if (c2 == 'D' && (c4 == 'D' || c4 == '?')) {
        c4 = 'P';
      } else {
        c4 = 'D';
      }
      T.at(i + 2) = c4;
    }
  }

  if (T.at(l - 1) == '?') {
    T.at(l - 1) = 'D';
  }

  cout << T << endl;

  return 0;
}


Measured memory_bytes: 3744
#[allow(unused)]
use proconio::marker::*;
use proconio::{fastout, input};
#[allow(unused)]
use std::cmp::{max, min, Reverse};
#[allow(unused)]
use std::collections::{BinaryHeap, HashMap, HashSet, VecDeque};

#[fastout]
fn main() {
    input! {
        a: i128,
        v: i128,
        b: i128,
        w: i128,
        t: i128,
    }

    if v - w > 0 && (v - w) * t >= (b - a).abs() {
        println!("YES");
    } else {
        println!("NO");
    }
}


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

using namespace std;

int main(void)
{
    int A, B, H, M;
    cin >> A >> B >> H >> M;
    double radA = M_PI * H / 6.0 + M_PI * M / 30.0 / 12.0;
    double radB = M_PI * M / 30.0;
    double rad = radA - radB;

    cout << setprecision(10) << sqrt(A*A + B*B - 2.0 * A*B*cos(rad))<< endl;
    return 0;
}

Measured memory_bytes: 4196
#include <stdio.h>
#define SIZE 100
int main(void)
{
	int n;
	int i;
	int va[SIZE];

	for (i = 0; i < SIZE; i++)
		va[i] = 0;
	
	scanf("%d", &n);

	for (i = 0; i < n; i++)
		scanf("%d", &va[i]);

	printf("%d", va[n - 1]);

	for (i = n - 2; i >= 0; i--)
		printf(" %d", va[i]);

	putchar('\n');

	return 0;
}

Measured memory_bytes: 600
package main

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

// input scanner
var sc = bufio.NewScanner(os.Stdin)

const (
	initialBufSize = 10e4
	maxBufSize     = 10e6
)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

func nextInt64() int64 {
	a, _ := strconv.ParseInt(next(), 10, 64)
	return a
}

func nextFloat64() float64 {
	a, _ := strconv.ParseFloat(next(), 64)
	return a
}

func nextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}

func nextInt64s(n int) []int64 {
	ret := make([]int64, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt64()
	}
	return ret
}
func nextFloats(n int) []float64 {
	ret := make([]float64, n)
	for i := 0; i < n; i++ {
		ret[i] = nextFloat64()
	}
	return ret
}
func nextStrings(n int) []string {
	ret := make([]string, n)
	for i := 0; i < n; i++ {
		ret[i] = next()
	}
	return ret
}

// util
func max(l []int) (int, int) {
	idx := 0
	ans := l[idx]
	for i, n := range l {
		if n > ans {
			idx = i
			ans = n
		}
	}
	return idx, ans
}

func min(l []int) (int, int) {
	idx := 0
	ans := l[idx]
	for i, n := range l {
		if n < ans {
			idx = i
			ans = n
		}
	}
	return idx, ans
}

var mod = 1000000007

func mul(a int, b int) int {
	return ((a % mod) * (b % mod)) % mod
}

func power(x int, y int) int {
	if y == 0 {
		return 1
	} else if y%2 == 0 {
		ans := power(x, y/2) % mod
		ans = mul(ans, ans)
		return ans
	} else {
		ans := power(x, y/2) % mod
		ans = mul(mul(ans, ans), x)
		return ans
	}
}

func genPrime(n int) []int {
	check := make([]int, n+1)
	ps := make([]int, 0, n)
	for i := 2; i <= n; i++ {
		if check[i] == 0 {
			ps = append(ps, i)
		}
		for j := i * i; j <= n; j += i {
			if check[j] == 0 {
				check[j] = 1
			}
		}
	}
	return ps
}

func minPrimeFactors(n int) []int {
	pf := make([]int, n+1)
	for i := 2; i <= n; i++ {
		if pf[i] != 0 {
			continue
		}
		pf[i] = i
		for j := i * i; j <= n; j += i {
			if pf[j] == 0 {
				pf[j] = i
			}
		}
	}
	return pf
}

// main
func main() {
	buf := make([]byte, initialBufSize)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords)
	n := nextInt()
	a := make([]int, n)
	var amax int
	for i := 0; i < n; i++ {
		a[i] = nextInt()
		if a[i] > amax {
			amax = a[i]
		}
	}
	mpf := minPrimeFactors(amax)
	var ans int
	m := make(map[int]int, n)
	for i := 0; i < n; i++ {
		pf := make(map[int]int, n)
		ai := a[i]
		for ai > 1 {
			pf[mpf[ai]]++
			ai = ai / mpf[ai]
		}
		for p, c := range pf {
			if c > m[p] {
				m[p] = c
			}
		}
	}
	ab := 1
	for x, c := range m {
		ab = mul(ab, power(x, c))
	}
	// fmt.Println("m", m)
	for i := 0; i < n; i++ {
		b := mul(ab, power(a[i], (mod-2)))
		ans = (ans + b) % mod
	}
	fmt.Println(ans)
}


Measured memory_bytes: 30336
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define EPS (1e-9)
#define INF (1e17)
#define PI (acos(-1))
//const double PI = acos(-1);
//const double EPS = 1e-15;
//long long INF=(long long)1E17;
#define i_7 (long long)(1e9+7)
//#define i_7 998'244'353
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
long long po(long a, long b){
    if(b==0){
        return 1;
    }
    
    long long z = po(a,b/2);
    z = mod(z*z);
    if(b%2!=0){
        z = mod(a*z);
    }
    return z;
}
 
bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=std::sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}
 
long long gcd_(long long a, long long b){
  if(a<b){
    std::swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}
 
//using namespace std;
//using namespace boost::multiprecision;
//using namespace __gnu_pbds;

int main(){
  using namespace std;
  long long n;
  cin>>n;
  long long a[n], b[n];
  REP(i, n) cin>>a[i]>>b[i];
  typedef pair<long long, long long> P;
  map<P, long long> cnt;
  for(long long i = 0; i < n; i++){
    if(a[i] == 0LL && b[i] == 0LL){
      cnt[P(a[i], b[i])]++;
      continue;
    }
    if(a[i] == 0LL){
      cnt[P(0LL, 1LL)]++;
      continue;
    }
    if(b[i] == 0){
      cnt[P(1LL, 0LL)]++;
      continue;
    }
    long long g = gcd_(abs(a[i]), abs(b[i]));
    a[i] /= g; b[i] /= g;
    if(a[i] < 0){
      a[i] = 0LL-a[i];
      b[i] = 0LL-b[i];
    }
    cnt[P(a[i], b[i])]++;
  }
  
  long long ans = 1;
  long long extra = cnt[P(0, 0)];
  //long long c = 0;
  for(auto p: cnt){
    if(p.second < 0) continue;
    if(p.first.first == 0LL && p.first.second == 0) continue;
    long long coA = p.first.second;
    long long coB = -p.first.first;
    if(coA < 0){
      coA = 0LL - coA;
      coB = 0LL - coB;
    }
    long long coeff = mod(po(2LL, p.second) + po(2LL, cnt[P(coA, coB)]) - 1);
    cnt[P(coA, coB)] = -1;
    ans *= coeff;
    ans = mod(ans);
  }
  
  ans -= 1;
  ans = mod(ans);
  ans += extra;
  ans = mod(ans);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 31680