akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
clock_t t=clock();
namespace my_std{
	using namespace std;
	#define pii pair<int,int>
	#define fir first
	#define sec second
	#define MP make_pair
	#define rep(i,x,y) for (int i=(x);i<=(y);i++)
	#define drep(i,x,y) for (int i=(x);i>=(y);i--)
	#define go(x) for (int i=head[x];i;i=edge[i].nxt)
	#define templ template<typename T>
	#define sz 101010
	typedef long long ll;
	typedef double db;
	mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	templ inline T rnd(T l,T r) {return uniform_int_distribution<T>(l,r)(rng);}
	templ inline bool chkmax(T &x,T y){return x<y?x=y,1:0;}
	templ inline bool chkmin(T &x,T y){return x>y?x=y,1:0;}
	templ inline void read(T& t)
	{
		t=0;char f=0,ch=getchar();double d=0.1;
		while(ch>'9'||ch<'0') f|=(ch=='-'),ch=getchar();
		while(ch<='9'&&ch>='0') t=t*10+ch-48,ch=getchar();
		if(ch=='.'){ch=getchar();while(ch<='9'&&ch>='0') t+=d*(ch^48),d*=0.1,ch=getchar();}
		t=(f?-t:t);
	}
	template<typename T,typename... Args>inline void read(T& t,Args&... args){read(t); read(args...);}
	char __sr[1<<21],__z[20];int __C=-1,__zz=0;
	inline void Ot(){fwrite(__sr,1,__C+1,stdout),__C=-1;}
	inline void print(register int x)
	{
		if(__C>1<<20)Ot();if(x<0)__sr[++__C]='-',x=-x;
		while(__z[++__zz]=x%10+48,x/=10);
		while(__sr[++__C]=__z[__zz],--__zz);__sr[++__C]='\n';
	}
	void file()
	{
		#ifdef NTFOrz
		freopen("a.in","r",stdin);
		#endif
	}
	inline void chktime()
	{
		#ifdef NTFOrz
		cout<<(clock()-t)/1000.0<<'\n';
		#endif
	}
	#ifdef mod
	ll ksm(ll x,int y){ll ret=1;for (;y;y>>=1,x=x*x%mod) if (y&1) ret=ret*x%mod;return ret;}
	ll inv(ll x){return ksm(x,mod-2);}
	#else
	ll ksm(ll x,int y){ll ret=1;for (;y;y>>=1,x=x*x) if (y&1) ret=ret*x;return ret;}
	#endif
//	inline ll mul(ll a,ll b){ll d=(ll)(a*(double)b/mod+0.5);ll ret=a*b-d*mod;if (ret<0) ret+=mod;return ret;}
}
using namespace my_std;

int n,m;
int a[sz];

int K;int ans[sz],*A;

int main()
{
	file();
	read(n,m);
	int cc=0;
	rep(i,1,m) read(a[i]),cc+=a[i]&1;
	if (cc>2) return puts("Impossible"),0;
	if (m==1) return (a[1]>1?printf("%d\n2\n%d 1\n",a[1],a[1]-1):puts("1\n1\n1")),0;
	if (a[1]%2==0) rep(i,2,m) if (a[i]&1) swap(a[i],a[1]);
	if (a[m]%2==0) rep(i,2,m-1) if (a[i]&1) swap(a[i],a[m]);
	rep(i,1,m) printf("%d ",a[i]); puts("");
	if (a[1]%2==0) ans[++K]=a[1]-2,ans[++K]=1; else if (a[1]!=1) ans[++K]=a[1]-1;
	rep(i,2,m-1) ans[++K]=a[i];
	if (a[m]%2==0) ans[++K]=a[m],ans[++K]=1; else ans[++K]=2,ans[++K]=a[m]-1;
	A=ans;
	if (!ans[K]) --K; if (!ans[1]) A=ans+1,--K;
	printf("%d\n",K);
	rep(i,1,K) printf("%d ",A[i]);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  if(abs(a-b)<=d && abs(b-c)<=d || abs(a-c)<=d){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
}


Measured memory_bytes: 256
from math import *

n = int(input())
a = list(map(int, input().split()))

l = [a[0]]
for i in range(1, n-1):
  l.append(gcd(a[i], l[i-1]))

ans = l[n-2]
r = a[n-1]
for i in range(n-2,0,-1):
  r = gcd(r, a[i+1])
  ans = max(ans, gcd(l[i-1], r))
ans = max(ans, gcd(r,a[1]))
print(ans)

Measured memory_bytes: 21072
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define test int t; cin>>t; for(int cs=1;cs<=t;cs++)
ll n,a[200005],c[200005],d,e,i,j,k,l;
int main()
{
   ios_base::sync_with_stdio(0);
   cin.tie(0);cout.tie(0);

   cin>>n;
   for(i=0;i<n;i++)
   {
       cin>>a[i];
       c[i]=a[i];
   }
   
   sort(c,c+n);
   for(i=0;i<n;i++)
   {
       if(a[i]==c[n-1]) cout<<c[n-2]<<endl;
       else cout<<c[n-1]<<endl;
   }
   return 0;
}


Measured memory_bytes: 6772
#include<bits/stdc++.h>
using namespace std;
void solve(){
    char s[1000];
    scanf("%s",s);
    for(int i=0;i<strlen(s);i++){
        if(i==5||i==13) printf(" ");
        else printf("%c",s[i]);
    }
}
int main(){
    solve();
    return 0;
}

Measured memory_bytes: 256
n = int(input())
s = input()

r = s.count("R")
g = s.count("G")
b = s.count("B")

ans = r*g*b

for i in range(n):
    for diff in range(n):
        j = i + diff
        k = i + 2*diff
        if k >= n:
            break
        elif s[i] != s[j] and s[i] != s[k] and s[j] != s[k]:
            ans -= 1

print(ans)

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

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

    int count = 0;

    for (int i = min(A,B); i > 0; i--){
        if (B % i == 0 && A % i == 0) {
            count++;
            if (count == K) {
                cout << i << endl;
            }
        }
    }
}


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

int main() {
	string s, t;
	cin >> s >> t;
	bool found = true;
	vector<string>ans;
	string make_ans;
	string a;
	int old;
	for (int i = 0; i < s.length() - t.length() + 1; i++) {
		for (int j = i; j < t.length() + i; j++) {
			if (s[j] != '?'&&s[j] != t[j - i]) {
				found = false;
				break;
			}
		}
		if (found == true) {
			make_ans = "";
			old = i;
			for (int j = 0; j < s.length(); j++) {
				if (i <= j && j < i + t.length()) {
					a = t[j - old];
					make_ans.append(a);
				}
				else {
					a = s[j];
					if (s[j] != '?' ) {
						make_ans.append(a);
					}
					else {
						make_ans.append("a");
					}
				}
			}
			ans.push_back(make_ans);
		}
		found = true;
	}
	sort(ans.begin(), ans.end());
	if (ans.size() > 0) {
		cout << ans[0] << endl;
	}
	else {
		cout << "UNRESTORABLE" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.Map;
import java.util.Scanner;
import java.util.TreeMap;

public class Main{
	
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String line = sc.nextLine();
		int n = Integer.valueOf(line.split(" ")[0]);
		int q = Integer.valueOf(line.split(" ")[1]);
		
		Map<Integer, Node> nodes = new TreeMap<>();
		for(int i = 0; i < n; i++){
			nodes.put(i, new Node(i));
		}
		for(int i = 0; i < q; i++){
			String query = sc.nextLine();
			int com = Integer.valueOf(query.split(" ")[0]);
			int x = Integer.valueOf(query.split(" ")[1]);
			int y = Integer.valueOf(query.split(" ")[2]);
			
			switch(com){
				case 0:
					unite(nodes, x, y);
					break;
				case 1:
					System.out.println(same(nodes, x, y)? "1": "0");
					break;
			}
		}
	}
	
	static void unite(Map<Integer, Node> map, int x, int y){
		map.get(y).getRoot().setParent(map.get(x));
	}
	
	static boolean same(Map<Integer, Node> map, int x, int y){
		return map.get(x).getRoot().getNo() == map.get(y).getRoot().getNo();
	}
}

class Node{
	int no;
	Node parent;
	
	int getNo(){
		return no;
	}
	
	void setParent(Node n){
		if(n.getRoot() != this) this.parent = n;
		if(parent != this)this.parent.setParent(n.getRoot());
	}
	
	Node getRoot(){
		if(parent != this) return parent.getRoot();
		else return this;	
	}
	
	Node(int no){
		this.no = no;
		parent = this;
	}
}

Measured memory_bytes: 163900
N,K = map(int,input().split())
ans = 0
for i in range(1,N+1):
    if(i < K):
        point = i
        count = 0
        while(point < K):
            count += 1
            point *= 2
        ans += (1/N)*(1/2)**count
    else:
        ans += (1/N)
print(ans)

Measured memory_bytes: 39024
A, B, K = map(int, input().split())
small = min(A, B)
both = [i for i in range(1, small+1)]
gcd = []

for i in both:
    if A % i == 0 and B % i == 0:
        gcd.append(i)

K -= 1
gcd.sort(reverse=True)
print(gcd[K])


Measured memory_bytes: 3060
//https://qiita.com/drken/items/dc53c683d6de8aeacf5a
#include <iostream>
#include <vector>
#include <cstdlib>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const long long INF = 0;

// 入力
int N;
long long int vc[100010][3];

// DP テーブル
long long int hpy[100010][3];

int main() {
    int N; cin >> N;
    for (int i = 0; i < N; i++)for(int j = 0; j < 3; j++) cin >> vc[i][j];

    //初期化
    for(int j = 0; j < 3; j++)hpy[0][j] = vc[0][j];

    for(int i = 1; i < N; i++){
      for(int j = 0; j < 3; j++){
        for(int k = 0; k < 3; k++){
          if (j == k) continue;
          chmax(hpy[i][j], hpy[i-1][k]+vc[i][j]);
        }
      }
    }
  long long int ans = 0;
  for(int i = 0; i < 3; i++) chmax(ans, hpy[N-1][i]);
  cout << ans << endl;

}

Measured memory_bytes: 4992
#include <cstdio>
#include <cstdint>
#include <cctype>
#include <algorithm>
#include <vector>
#include <utility>
#include <deque>

int main() {
  size_t M;
  intmax_t K;
  scanf("%zu %jd", &M, &K);

  intmax_t P = 1 << M;
  if (K == 0) {
    for (intmax_t i = 0; i < P; ++i)
      printf("%jd %jd%c", i, i, i+1<P? ' ':'\n');
    return 0;
  }

  std::deque<intmax_t> res;
  res.push_back(K);

  intmax_t x = 0;
  for (intmax_t i = 0; i < P; ++i) {
    if (i == K) continue;
    res.push_back(i);
    res.push_front(i);
    x ^= i;
  }
  if (x != K)
    return puts("-1"), 0;

  res.push_front(K);

  for (size_t i = 0; i < res.size(); ++i)
    printf("%jd%c", res[i], i+1<res.size()? ' ':'\n');
}


Measured memory_bytes: 3968
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> V;
#define rep(s,e) for(ll i=s;i<e;i++ )
typedef pair<ll,ll> P;
const ll mod = 1e9+7;
const ll INF = 100000000000009;
ll i;
V A(100000);
V ans(100000);
ll N;
void nibutan(ll x,ll y){
    if(x==y){
        for(ll j=0;j<N;j++){
            if(j==0)ans.at(j)=2*x;
            else{
                ans.at(j)=2*A.at(j-1)-ans.at(j-1);
            }
        }
        rep(0,N)cout<<ans.at(i)<<" ";
        return;
    }
    
    ll a=max(x,y);
    ll b=min(x,y);
    ll mid=(a+b)/2;
    ans.at(0)=2*mid;
    for(ll j=1;j<N;j++){
        ans.at(j)=2*A.at(j-1)-ans.at(j-1);
        if(ans.at(j)<0){
            if(j%2==1)return nibutan(b,mid-1);
            else return nibutan(mid+1,a);
        }
        if(j==N-1){
            if((ans.at(0)+ans.at(j))/2==A.at(j))return nibutan(mid,mid);
            else if(2*A.at(j)-ans.at(j)>ans.at(0))return nibutan(mid+1,a);
            else return nibutan(b,mid-1);
        }

        
    }
}
int main(){

    cin>>N;
    
    rep(0,N)cin>>A.at(i);
    ll haji=0;
    ll uphaji=A.at(0);
    nibutan(haji,uphaji);
    cout<<endl;
}

Measured memory_bytes: 2944
#include <ctime>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <map>
using namespace std;

typedef long long ll;
typedef double lf;
typedef long double Lf;
typedef pair <int,int> pii;
typedef pair <ll, ll> pll;

#define TRACE(x) cerr << #x << "  " << x << endl
#define FOR(i, a, b) for (int i = (a); i < int(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define _ << " " <<

#define fi first
#define sec second
#define mp make_pair

const int MAXN = 100;

int n, p[MAXN], P;

ll dp[MAXN][2];

ll rek(int cvor, int t) {
	if (cvor == n) return (t == P);
	if (dp[cvor][t] != -1) return dp[cvor][t];

	ll ret = 0;
	ret += rek(cvor + 1, t);
	if (!p[cvor]) return dp[cvor][t] = ret;
	ret += rek(cvor + 1, t ^ 1);

	return dp[cvor][t] = ret;
}

int main() {
	scanf("%d %d",&n,&P);
	REP(i, n) {
		scanf("%d",&p[i]);
		p[i] %= 2;
	}

	memset(dp, -1, sizeof dp);
	
	int cnt = 0;
	REP(i, n) cnt += p[i];
	cnt = n - cnt;
	
	printf("%lld\n",rek(0, 0) * (1LL << cnt));
	return 0;
}

Measured memory_bytes: 256
import unittest
from io import StringIO
import sys
sys.setrecursionlimit(10 ** 5 + 10)


def input(): return sys.stdin.readline().strip()


def resolve():
    # https://qiita.com/drken/items/dc53c683d6de8aeacf5a#dp-%E5%AE%9F%E8%A3%85%E3%81%AE%E9%A0%86%E5%BA%8F


    INF = 10**10  # INF+INFを計算してもオーバーフローしない範囲で大きく

    N = int(input())
    h = list(map(int, input().split()))
    # dpテーブル dp[i]:= ...
    dp = [INF]*N
    """
    初期化の値は，
        最小化問題：INF, 
        最大化問題：-INF（0以上の値しか取らないなら-1, あるいは0でもいいかも)
        数え上げ問題：0
        確率問題：0
        Yes/No判定問題:False
    """

    # 初期条件
    dp[0] = 0

    # ループ
    for i in range(N-1):

        """
        dp[from] の値の更新が完了していればノード from からノード to への緩和を行っていい．
        貰うdpであれ配るdpであれ．違いを意識すべきケースはcf. 
        https://qiita.com/drken/items/ace3142967c4f01d42e9#%E8%B2%B0%E3%81%86-dp-%E3%81%A8%E9%85%8D%E3%82%8B-dp-%E3%81%AE%E6%AF%94%E8%BC%83
        """

        dp[i+1]=min(dp[i+1], dp[i]+abs(h[i]-h[i+1]))
        if i < N-2:
            dp[i+2]=min(dp[i+2], dp[i]+abs(h[i]-h[i+2]))

    # 出力
    print(dp[N - 1])


resolve()

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

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

	long long OK=0,NG=k+1;

	while(NG-OK>1){
		long long mid=(OK+NG)/2,tmp=mid,sum=0,cnt=0;

		while(cnt<n && tmp){
			sum+=tmp;	tmp/=2;		cnt++;
		}
		if(sum<=k)OK=mid;
		else NG=mid;
	}
	cout<<OK<<endl;

	return 0;
}



Measured memory_bytes: 3108
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <cctype>
#define len length()
#define sz size()
#define rng(i, a, b) for(int i = a; i < b; i++)
#define rep(i, n) rng(i, 0, n)
#define srt(v) sort(v.begin(), v.end())
#define rev(s) reverse(s.begin(), s.end())
#define vi(a, n) vector<int> a(n)
#define vs(a, n) vector<string> a(n)
#define vc(a, n) vector<char> a(n)
#define psb(a) push_back(a)
#define ppb pop_back()
#define erc(S, i) S.erase(S.begin() + i)
#define ers(S, i, j) S.erase(S.begin() + i, S.begin() + j)
#define sp(n) cout << setprecision(n) << fixed
#define fst(s) s.at(0)
#define lst(s) s.at(s.len - 1)
typedef long long ll;
using namespace std;
int mod = 1000000007;

int main(){
    ll n, a, b;
    cin >> n >> a >> b;
    ll ans;
    if(a == 0) ans = 0;
    else if(n < a) ans = n;
    else{
        ll sum = a + b;
        ll div = n / sum;
        ans = div * a;
        n -= sum * div;
        if(n < a)ans += n;
        else ans += a;
        //cout << "sum:" << sum << " " << "div:" << div << endl;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
# 入力
N = int(input())

S1 = [] # 増えるシーケンス用
S2 = [] # 減るシーケンス用

# 入力その２
for i in range(N):

    S = input()  # シーケンス
    mid, end = 0, 0    

    for s in S:
        if s == '(':
            end += 1
        else:
            end -= 1
            
        mid = min(mid, end)  # 途中経過で一番減るところを探す

    if end > 0:
        S1.append((mid, end))
    else:
        S2.append((mid-end, -end))

S1.sort(reverse=True)
# S2.sort(key = lambda x : (x[0], -x[1]))
S2.sort(reverse=True)


mid = end1 = 0  # スタート
out = False

for t in S1:
    a, b = t
    mid = end1 + a
    end1 = end1 + b
    if mid < 0:  # 途中で左カッコの数が右を上回る
        out = True
        break

mid = end2 = 0  # スタート
for t in S2:
    a, b = t
    mid = end2 + a
    end2 = end2 + b
    if mid < 0:  # 途中で左カッコの数が右を上回る
        out = True
        break
        
if (not end1 == end2) or out:  # 右、左 の数が合わない
    print('No')
else:
    print('Yes')

Measured memory_bytes: 80336
//use std::convert::TryInto;
#![allow(dead_code)]

fn main(){
    let x: Vec<i32> = input_vec();
    let sum = x.iter().fold(0, |sum, a| sum + a);
    println!("{}", 15 - sum);
}



/*
 * input function
 */
fn input<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}


fn input_vec<T: std::str::FromStr>() -> Vec<T> {
    input::<String>()
        .split_whitespace()
        .map(|s| s.parse().ok().unwrap()).collect()
}

Measured memory_bytes: 2044
#include <iostream>
#include <array>
#include <cstdio>
using namespace std;

int main(int argc, char *argv[]){
  int a,b,c,i,j = 0,mod;
  cin >> a;
  cin >> b;
  cin >> c;
  for(i = a;i <= b;i++){
    mod = c % i;
    if(!mod){
      j++;
    }
  }
  cout << j << endl;
  return 0;
}

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

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

    int start = 1, end = n, mid;

    while(start <= end){
        mid = (start + end) / 2;

        double x = (double) mid * 1.08;
        //x += 0.5;

        int xx = x;

        if(xx == n){
            cout << mid << "\n";
            return 0;
        }

        if(xx > n) end = mid-1;
        else start = mid+1;
    }

    cout << ":(" << "\n";

    return 0;
}

Measured memory_bytes: 3604
#include <vector>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>
#include <tuple>
#include <set>
#include <map>
#include <unordered_map>
#include <complex>
#include <iomanip>
#include <cmath>
using namespace std;
typedef long long ll;

int main()
{
    string a;
    cin >> a;
    sort(a.begin(), a.end());
    if (a == "abc") cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

int main(){
    int N, max=0;
    cin >> N;
    int H[N];
    for(int i=0; i<N; i++){
        cin >> H[i];
        if(max-1 > H[i]){
            cout << "No" << endl;
            return 0;
        }
        if(max < H[i]) max = H[i];
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
template<class T> ostream& operator<<(ostream &os, vector<T> V) { os << "[ "; for(auto v : V) os << v << " "; return os << "]"; }
template<class T> ostream& operator<<(ostream &os, set<T> S){ os << "{ "; for(auto s:S) os<<s<<" ";return os<<"}"; }
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) { return os << "(" << P.first << "," << P.second << ")";}
template<class L, class R> ostream& operator<<(ostream &os, map<L,R> M) { os << "{ "; for(auto m:M) os<<"("<<m.first<<":"<<m.second<<") "; return os<<"}"; }
#ifdef LMAO
    #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){cerr << name << " : " << arg1 << endl;}
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){ const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1<<" | "; __f(comma+1, args...); }
#else
    #define trace(...) 42
#endif
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define endl "\n"
#define tcase int tt; cin>>tt; while(tt--)
#define tcase2 int tt; cin>>tt; for(int qq=1;qq<=tt;qq++)
#define all(x) x.begin(), x.end()
typedef long long int ll;
typedef  unsigned long long int ull;
typedef long double ld;
const int MAX = 1000010;
const int MOD2 = 998244353;
const int MOD = 1000000007; 
const int INF = 1e8;    
const ll LLINF = 0x3f3f3f3f3f3f3f3f;
const ld EPS = 1e-7;
#define forn(i, n) for(int i = 0; i < (int)n; i++)
#define forne(i, a, b) for(int i = a; i <= b; i++)   
/*****************start************/
void solve()
{
    int n;
    cin>>n;
    int out=0;
    for(int i=1;i<=n;i++)
    {
        int lo;
        cin>>lo;
        if((i&1) and (lo&1)) 
            out++; 
    }
    cout<<out<<endl;
}
int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);cout<<fixed<<setprecision(25);cerr<<fixed<<setprecision(10);
    auto start = std::chrono::high_resolution_clock::now();
    // tcase{
        solve();
    // }B
    auto stop = std::chrono::high_resolution_clock::now(); 
    auto duration = std::chrono::duration_cast<std::chrono::nanoseconds>(stop - start); 
    // cerr << "Time taken : " << ((long double)duration.count())/((long double) 1e9) <<"s "<< endl;     
    return 0;
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define int long long
using namespace std;
int ans;
int n,k;
long long process(int sum)
{
	long long tot=0;
	for(int a=1;a<=sum && a<=n;a++)
	{
		int b=k-a;
		int c=k-b;
		if(!b)b+=k;
		if(!c)c+=k;
		if((c+a)%k==0)
		{
		//	cout<<a<<" "<<b<<" "<<c<<endl;
			tot+=1ll*((n-a)/k+1)*((n-b)/k+1)*((n-c)/k+1);
		}
	}
	return tot;
}
signed main()
{
/*
#ifndef ONLINE_JUDGE
	freopen("data.in","r",stdin);
	freopen("output.txt","w",stdout);
#endif*/
	cin>>n>>k;
	if(k>n*2)
	{
		puts("0");
		return 0;
	}
	cout<<process(k)<<endl;
	return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
# A

import sys
from collections import defaultdict, deque
from heapq import heappush, heappop
import math
import bisect
input = sys.stdin.readline

# 再起回数上限変更
# sys.setrecursionlimit(1000000)

x = list(map(int, input().split()))

for idx, x in enumerate(x):
    if x == 0:
        print(idx+1)
        sys.exit()



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

typedef long long ll;
using ll = long long;

bool between(ll x, ll y1, ll y2){
    if(y1 > y2) swap(y1, y2);

    if(x % 3 == 1){
        if(y2 - y1 >= 3) return true;
        for(ll y=y1;y<=y2;y++) if(y % 3 == 1) return true;
    }

    return false;
}

ll get_extra(ll x1, ll y1, ll x2, ll y2) {
    ll ans = 0;
    ll three = 1;
    for (int i = 0; i < 35; ++i) {
        if(x1 / three == x2 / three && between(x1 / three, y1 / three, y2 / three)) {
            ll tmp = min(min(x1 % three, x2 % three) + 1, three - max(x1 % three, x2 % three));
            ans = max(ans, tmp);
        }
        three *= 3;
    }

    return ans;
}

ll get_dist(ll x1, ll y1, ll x2, ll y2){
    return abs(x1 - x2) + abs(y1 - y2) + 2 * max(get_extra(x1, y1, x2, y2), get_extra(y1, x1, y2, x2));
}

int main() {
    int Q;
    cin >> Q;

    while (Q--) {
        long long a;
        long long b;
        long long c;
        long long d;

        cin >> a >> b >> c >> d;
        cout << get_dist(a-1, b-1, c-1, d-1) << endl;
    }

    return 0;
}

Measured memory_bytes: 3564
# -*- coding: utf-8 -*-

N, L = map(int, input().split())

pie = int(N * L + N * (N - 1) / 2)

if L > 0:
    print(pie - L)
elif L + N - 1 < 0:
    print(pie - (L + N - 1))
else:
    print(pie)


Measured memory_bytes: 2940
import collections
n = int(input())
l = []
kai = 0
for i in range(3):
    l.append(input())
for i in range(n):
    search = []
    for j in range(3):
        search.append(l[j][i])
        #print(search)
    cnt = collections.Counter(search).most_common()
    for i in range(len(cnt)-1):
        kai += cnt[i+1][1]
print(kai)


Measured memory_bytes: 3572
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		 Scanner sc = new Scanner(System.in);
		 int N=sc.nextInt();
		 int M=sc.nextInt();
		 int observatory[][]=new int[N][2];
		 for(int i=0;i<N;i++) {
			 observatory[i][0]=sc.nextInt();
			 observatory[i][1]=0;
		 }
		 for(int i=0;i<M;i++) {
			 int a=sc.nextInt()-1;
			 int b=sc.nextInt()-1;
			 if(observatory[a][0]<=observatory[b][0]) {
				 observatory[a][1]=1;
			 }if(observatory[a][0]>=observatory[b][0]) {
				 observatory[b][1]=1;
			 }
		 }
		 int count=0;
		 for(int i=0;i<N;i++) {
			 if(observatory[i][1]==0)
				 count++;
		 }
	     System.out.println(count);
	     sc.close();
	 }
}


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

int main(){
  char str[1001],instruction[50],inputString[1000];
  int instructionNum;
  int i,k,j,inputNum[2];

  scanf("%s",str);
  scanf("%d",&instructionNum);
  
  for(i=0; i<instructionNum; ++i){
    scanf("%s %d %d", instruction, &inputNum[0], &inputNum[1]);
    
    if(strcmp(instruction,"replace") == 0){
      scanf("%s", inputString);
      for(k=0; k<inputNum[1] - inputNum[0] + 1; ++k){
	str[inputNum[0] + k] = inputString[k];
      }
    }else if(strcmp(instruction,"reverse") == 0){
      int work = inputNum[1] + inputNum[0];
      work = (work%2 == 0) ? work/2 : work/2+1;
      
      for(k=inputNum[0]; k<work; ++k){
	char work = str[k];
	str[k] = str[inputNum[1] - (k - inputNum[0])];
	str[inputNum[1] - (k - inputNum[0])] = work;
      }
    }else if(strcmp(instruction,"print") == 0){
      for(k=inputNum[0];k<inputNum[1] + 1; ++k){
	printf("%c",str[k]);
      }
      printf("\n");
    }
  }
  return 0;
}



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

int main(){
  	int A,B;
  	cin >> A >> B;
  	long Acalc=A, Bcalc=B, ans=1;
      
  	for(int i=2; i<min(A,B); i++){
    	while(Acalc%i==0 && Bcalc%i==0){
        	ans*=i;
          	//cout << ans << endl;
          	Acalc/=i;
          	Bcalc/=i;
          	//cout << Acalc << endl;
          	//cout << Bcalc << endl;
        }
    }
  	//cout << "for end! Acalc=" << Acalc << "Bcalc=" << Bcalc << "ans=" << ans << endl;
  	cout << Acalc*Bcalc*ans << endl;
	return 0;
}

Measured memory_bytes: 256
from collections import defaultdict
n,k=map(int,input().split())
dd=defaultdict(int)
for i in range(n):
    p=input()[0]
    dd[p]+=1
ans=0
while True:
    tmp_arr = sorted(dd.items(), key=lambda x: x[1], reverse=True)
    if len(tmp_arr)<k or tmp_arr[k-1][1]==0:
        break
    else:
        for i in range(k):
            dd[tmp_arr[i][0]]-=1
        ans+=1
print(ans)



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

int main(void){
    // Your code here!
    int n;
    cin >> n;

    n = n%1000;
    
    if(n==0){
        cout << 0 << endl;
    }else{
        cout << 1000 - n << endl;
    }
    
}


Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int dp[1002][1002];

int main(){
	int n;cin >> n;
	string x, y;
	while(n--){
		cin >> x >> y;
		for(int i = 1;i <= x.size();i++){
			for(int j = 1;j <= y.size();j++){
				if(x[i-1] == y[j-1])dp[i][j] = dp[i-1][j-1] + 1;
				else dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
			}
		}
		cout << dp[x.size()][y.size()] << endl;
	}
	return 0;
}

Measured memory_bytes: 7144
from collections import *
n, p = map(int, input().split())
s = list(map(int, input()))
if 10%p==0:
    r = 0
    for i in range(n):
        if s[i]%p==0:
            r += i+1
    print(r)
    exit()
c = Counter()
c[0] += 1
v = r = 0
k = 1
for i in s[::-1]:
    v += int(i)*k
    v %= p
    r += c[v]
    c[v] += 1
    k *= 10
    k %= p
print(r)


Measured memory_bytes: 7336
#include <cstdio>
#define ll long long
#define maxn 50
char a[maxn + 1][maxn + 1], b[maxn + 1][maxn + 1];
int main() {
    int n, m;
    scanf("%d%d", &n, &m);
    char t = fgetc(stdin);
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++)
            a[i][j] = fgetc(stdin);
        t = fgetc(stdin);
    }
    for (int i = 1; i <= m; i++) {
        for (int j = 1; j <= m; j++)
            b[i][j] = fgetc(stdin);
        t = fgetc(stdin);
    }
    int sem = 1;
    for (int i = 1; i <= n - m + 1 && sem == 1; i++) {
		for (int j = 1; j <= n - m + 1; j++) {
			int p = 1;
			for (int x = 1; x <= m; x++) {
				for (int y = 1; y <= m; y++) {
					if (a[x + i - 1][y + j - 1] != b[x][y]) {
						p = 0;
					}
				}
			}
			if (p == 1) {
				sem = 0;
			}
		}
	}
	if (sem == 0)
        printf("Yes");
    else
        printf("No");
    return 0;
}


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

#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define RFOR(i,b,a) for(int i = (b)-1; i >= (a); i--)
#define ITER(it, a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef vector<LL> VI;
typedef pair<int, int> PII;

const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL) INF;

const int MAX = 100100;

int A[MAX];
LL A2[MAX];

LL D[MAX];

VI ADD[MAX];
VI REM[MAX];

LL ST[MAX];

multiset<LL> S;

int main()
{
	//freopen("in.txt", "r", stdin);
	//ios::sync_with_stdio(false); cin.tie(0);

	int n, e, t;
	scanf("%d%d%d", &n, &e, &t);
	FOR (i, 0, n)
	{
		scanf("%d", &A[i]);
		A2[i] = A[i] * 2;
	}

	FOR (i, 0, n + 7)
	{
		ST[i] = LINF;
	}


	LL res = e;

	D[0] = 0;
	LL mn = LINF;

	FOR (i, 0, n + 1)
	{
		FOR (j, 0, SZ(ADD[i]))
		{
			S.insert(ADD[i][j]);
		}

		FOR (j, 0, SZ(REM[i]))
		{
			S.erase(S.find(REM[i][j]));
		}

		mn = min(mn, ST[i]);

		if (i == 0) D[i] = 0;
		else
		{
			D[i] = LINF;
			if (SZ(S))D[i] = *S.begin();

			D[i] = min(D[i], 2 * A[i - 1] + mn);

	//		cout<<i<<' '<<mn<<endl;
	//		if (SZ(S)) cout<<"** "<<*S.begin()<<endl;

			if (i == n) break;
		}

		int pos = upper_bound(A2, A2 + n, A2[i] + t) - A2;

	//	cout<<i<<": "<<pos<<endl;

		ADD[i+1].PB(D[i] + t);
		REM[pos + 1].PB(D[i] + t);

		ST[pos + 1] = min(ST[pos + 1], D[i] - 2 * A[i]);
		//mn = min(mn, D[i] - 2 * A[i]);
	}


/*	FOR (i, 0, n + 1)
	{
		cout<<D[i]<<' ';
	}
	cout<<endl;*/

	res += D[n];

	cout<<res<<endl;


}




Measured memory_bytes: 14200
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>
#include <cmath>

using namespace std;

const int N = 100;

int n;
vector<int> g[N];
int lv[N];

void dfs(int u, int p, int d) {
  lv[d] = max(lv[d], (int)g[u].size() - 1);
  for (int v : g[u]) if (v != p) {
    dfs(v, u, d + 1);
  }
}

int main() {
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    cin >> u >> v;
    u--; v--;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  pair<long long, long long> ans(LLONG_MAX, LLONG_MAX);
  for (int i = 0; i < n; i++) {
    fill_n(lv, N, 0);
    for (int j : g[i]) {
      dfs(j, i, 1);
    }
    double f = log(g[i].size());
    long long l = g[i].size();
    long long d = 0;
    for (int j = 1; j < n; j++) {
      d = j;
      if (lv[j] == 0) break;
      l *= lv[j];
      f += log(lv[j]);
    }
    if (f < log(LLONG_MAX)) {
      ans = min(ans, make_pair(d + 1, l));
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j : g[i]) {
      fill_n(lv, N, 0);
      dfs(j, i, 1);
      dfs(i, j, 1);
      long long l = 2;
      long long d = 0;
      double f = log(2);
      for (int k = 1; k < n; k++) {
        d = k;
        if (lv[k] == 0) break;
        l *= lv[k];
        f += log(lv[k]);
      }
      if (f < log(LLONG_MAX)) {
        ans = min(ans, make_pair(d, l));
      }
    }
  }
  cout << ans.first << ' ' << ans.second << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9;
using namespace std;
using ll = long long;
int main() {
    int n , ans = 0;
    cin >> n;
    vector <int> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    for(int i = 0; i < n; i+=2){
        if(a[i] % 2 == 1){
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
int n,p[105],ans[105],tot,x;
int main(){
	cin>>n;
	for(int i=1;i<=n;i++) cin>>p[i];
	for(int i=n;i>0;i--){
		x=0;
		for(int j=i;j>0;j--){
			swap(x,p[j]);
			if(x==j){ans[++tot]=j;break;}
			if(j==1){cout<<-1<<endl;return 0;}
		}
	}
	while(tot) cout<<ans[tot--]<<endl;
	return 0;
}

Measured memory_bytes: 256
/*
 * ID: ITP1_5_B 
 * Problem: draw frame
 */

#include <stdio.h>

int main(void)
{
    int height, width;
    int i, j;

    while (1) {
        scanf("%d %d", &height, &width);
        if (height == 0 && width == 0)
            return 0;

        for (i = 0; i < height; i++) {
            for (j = 0; j < width; j++)
                printf("%c",
                        i == 0 || i == height - 1 || j == 0 || j == width -1 ? '#' : '.');
            printf("\n");
        }
        printf("\n");
    }
    return 0;
}




Measured memory_bytes: 2040
X,Y = map(int,input().split())
ans = 0
if X==1:
    ans += 300000
elif X==2:
    ans += 200000
elif X==3:
    ans += 100000

if Y==1:
    ans += 300000
elif Y==2:
    ans += 200000
elif Y==3:
    ans += 100000

if X==1 and Y==1:
    ans += 400000

print(ans)


Measured memory_bytes: 3316
#include <iostream>
 
int main()
{
    int a, b, c;
    
    std::cin >> a >> b >> c;
 
    if ((a < c && c < b) || ( b < c && c < a)) {
     std::cout << "Yes" << std::endl;
     } else {
    std::cout << "No" << std::endl;
} 
return 0;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<typename T> bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<typename T> bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef tuple<ll,ll,ll> tlll;
typedef tuple<int,int,int> tiii;
const ll mod=1e9+7;
const int inf=1<<30;

int dp[100010];

int main(){
  int n,W; cin >> n >> W;
  vector<int> w(n);
  vector<int> v(n);
  rep(i,n){
    cin >> v[i] >> w[i];
  }
  rep(i,n)rep(j,W+1){
    if(j+w[i]<=W) chmax(dp[j+w[i]],dp[j]+v[i]);
  }
  int ans=0;
  rep(j,W+1){
    chmax(ans,dp[j]);
  }
  cout << ans << endl;
  
}


Measured memory_bytes: 3172
<?php

	$data = explode(" ", trim(fgets(STDIN)));
	$n = $data[0];
	$a = $data[1];
	$b = $data[2];
	if($n == 1){
	    if($a == $b) echo 1;
	    else echo 0;
	} else {
	    if($a>$b) echo 0;
	    else{
	        $n -= 2;
	        echo ($b - $a) * $n + 1;
	    }
	}
	
?>

Measured memory_bytes: 4856
#include <iostream>
#include <algorithm>
using namespace std;
void dice(){
   int d1,d2,d3,d4,d5,d6;
   cin>>d1>>d2>>d3>>d4>>d5>>d6;
 
   char dir;
   int tmp;
   while(true){
       cin>>dir;
       if(cin.eof()) break;
       if(dir=='E'){
           tmp=d1;d1=d4;d4=d6;d6=d3;d3=tmp;
       }else if(dir=='N'){
           tmp=d1;d1=d2;d2=d6;d6=d5;d5=tmp;
       }else if(dir=='S'){
           tmp=d1;d1=d5;d5=d6;d6=d2;d2=tmp;
       }else if(dir=='W'){
           tmp=d1;d1=d3;d3=d6;d6=d4;d4=tmp;
       }
   }
   cout<<d1<<endl;
}
int main(){
   dice();
   return 0;
}


Measured memory_bytes: 3088
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ln '\n';
int lim=1e4+2;
int inf=1e9+7;
int n;vector<int> w,s;
vector<ll> val;
vector<vector<ll> > dp;vector<pair<int,int> > v;
ll solve(int i,int si){
  if(i==n){
    return 0;
  }
  if(dp[i][si]!=-1){
    return dp[i][si];
  }else{
    int ind=(v[i].second);
    int wi=w[ind];
    ll tmp1=0;
    if(wi<=si){
      tmp1=val[ind]+solve(i+1,min(si-wi,s[ind]));
    }
    ll tmp2=solve(i+1,si);
    dp[i][si]=max(tmp1,tmp2);
    return dp[i][si];
  }
}
int main()
{ 
  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  cin>>n;
  w.resize(n);s.resize(n);val.resize(n);dp.resize(n+1,vector<ll>(2*lim+1,-1));
  for(int i=0;i<n;i++){
    cin>>w[i]>>s[i]>>val[i];
    v.push_back(make_pair(w[i]+s[i],i));
  }
  sort(v.rbegin(),v.rend());
  cout<<solve(0,2*lim)<<ln;
}

Measured memory_bytes: 160640
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        int C = sc.nextInt();
        int ans = solve(A, B, C);

        System.out.println(ans);
    }

    private static int solve(int A, int B, int C) {

        return  A == B ? C : B == C ? A : B;
    }

}


Measured memory_bytes: 23636
#include <cstdio>

int f(int n) {
  int res=0;
  while (n) {
    res += n % 10;
    n /= 10;
  }

  return res;
}

int main() {
  int N;
  scanf("%d", &N);

  printf("%s\n", N%f(N)?"No":"Yes");
}


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

using namespace std;

#define ll long long int
#define ull unsigned long long int 
#define Rep(i,n) for(ll i=0;i<n;i++) 
#define rRep(i,n) for(ll i=n;i>=0;i--)
#define rep(i,a,b) for(ll i=a;i<=b;i++)
#define rrep(i,a,b) for(ll i=b;i>=a;i--)
#define itr(i,t) for (typeof(t.begin()) i=t.begin(); i!=t.end(); i++) 
#define vi vector<int>  
#define vl vector<ll> 
#define vul vector<ull>
#define pii pair<int,int> 
#define pll pair<ll,ll>
#define Si set<int> 
#define Mi multiset<int> 
#define Sl set<ll> 
#define Ml multiset<ll>
#define mapi map<int,int>
#define mapl map<ll,ll>
#define mp make_pair
#define pb push_back
#define ff first
#define ss second  
#define INF (ll)1e9;
#define mod (ll)(1e9+7);
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); 
#define T ll test;cin >> test;while(test--)

int main(){
    fast;      
    ll n;cin>>n;
    ll count=0;
    for(ll i=1;i<n;i++){
       if((n-1)/i) count+=(n-1)/i;
    }
    cout<<count<<endl;
return 0;
}


Measured memory_bytes: 3656
n, m, c = gets.strip.split(" ").map(&:to_i)
b = gets.strip.split.map(&:to_i)
data = n.times.map { gets.strip.split.map(&:to_i) }

ans = 0
(0..n-1).each do |i|
  tmp = 0
  (0..m-1).each do |j|
    tmp += data[i][j] * b[j]
  end
  tmp += c
  ans += 1 if tmp > 0
end

puts ans

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  int N=s.size();
  int a=-1;
  int z=-1;
  for (int i=0; i < N; i++){
    if ((a==-1) && (s[i]=='A')) a=i;
    if (s[i]=='Z') z=i;
  }
  cout << z-a+1 << endl;
}

Measured memory_bytes: 3740
n, m = gets.split.map(&:to_i)
a = gets.split.map(&:to_i).sort.reverse
t = Array.new
t << (a.shift >> 1)
m -= 1
while m > 0
  t << (a.empty? || a[0] < t[0] ? t.shift >> 1 : a.shift >> 1)
  m -= 1
end
puts (a + t).inject(&:+)


Measured memory_bytes: 11768
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
using namespace std;


typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
	stringstream ss;
	ss << f;
	ss >> t;
}


#define REP(i,n) for(int i=0;i<int(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define RALL(v) (v).rbegin(),(v).rend()
#define PB push


#define MOD 1000000009LL
#define EPS 1e-8

int a[ 510 ][ 510 ];
int sum[ 510 ][ 510 ];

int main()
{
	int N, M, Q;
	cin >> N >> M >> Q;
	REP( i, M )
	{
		int L, R;
		cin >> L >> R;
		a[ L ][ R ] += 1;
	}
	for( int i = 1; i <= 500; ++i )
	{
		for( int j = 1; j <= 500; ++j )
		{
			sum[ i ][ j ] = sum[ i - 1 ][ j ] + sum[ i ][ j - 1 ] - sum[ i - 1 ][ j - 1 ] + a[ i ][ j ];
		}
	}
	REP( i, Q )
	{
		int p, q;
		cin >> p >> q;
		cout << sum[ max( p, q ) ][ max( p, q ) ] - sum[ min( p, q ) - 1 ][ max( p, q ) ] - sum[ max( p, q ) ][ min( p, q ) - 1 ] + sum[ min( p, q ) - 1 ][ min( p, q ) - 1 ] << endl;
	}
	return 0;
}


Measured memory_bytes: 2944
using System;

namespace ABC159b
{
    class Program
    {
        static void Main(string[] args)
        {
            var s = Console.ReadLine();

            int n = s.Length;

            string s1 = s.Substring(0, ((n - 1) / 2));
            int n1 = s1.Length;
            for (int i = 0; i < s1.Length/2; i++)
            {
                if (s1[i] != s1[n1 - 1 - i])
                {
                    Console.WriteLine("No");
                    return;
                }
            }

            string s2 = s.Substring(((n + 3) / 2) - 1,(n-1)/2);
            int n2 = s2.Length;
            for (int i = 0; i < s2.Length / 2; i++)
            {
                if (s2[i] != s2[n2 - 1 - i])
                {
                    Console.WriteLine("No");
                    return;
                }
            }

            for (int i = 0; i <= s1.Length / 2; i++)
            {
                if (s1[i] != s2[i])
                {
                    Console.WriteLine("No");
                    return;
                }
            }
            Console.WriteLine("Yes");
        }
    }
}


Measured memory_bytes: 11092
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<map>
#include<stack>
#include<queue>
#include<iomanip>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
#define LINF (long long)4e18

using ll = long long;


int main(){
  int N; cin >> N;
  vector<pair<int,int>> xy(N);
  rep(i,N){
    cin >> xy[i].first >> xy[i].second;
  }
  sort(xy.begin(),xy.end());
  map<pair<int,int>,int> pq;
  int m = 0;
  rep(i,N-1){
    repr(j,i+1,N){
      pq[make_pair(xy[j].first - xy[i].first,xy[j].second - xy[i].second)]++;
    }
  }
  for(auto it = pq.begin();it != pq.end();it++){
    m = max(m,it->second);
  }
  int ans = N - m;
  cout<< ans << endl;

}

Measured memory_bytes: 256
K = int(input())
num = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(num[K - 1])

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



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


Measured memory_bytes: 4320
N, M = map(int, input().split())
sLists = [list(map(int, input().split()[1:])) for _ in range(M)]
pList = list(map(int, input().split()))

ans = 0
for num in range(2 ** N):
    bit = str(bin(num)[2:]).zfill(N)
    breakFlag = False
    for i_1, sList in enumerate(sLists):
        count = 0
        for i_2, b in enumerate(list(bit), start=1):
            if i_2 in sList and b == "1":
                count += 1
        if count % 2 != pList[i_1]:
            breakFlag = True
            break
    if not breakFlag:
        ans += 1

print(ans)




Measured memory_bytes: 3064
using System;
using System.Text;
using System.Collections.Generic;
using System.Collections;
using static System.Math;
using System.Linq;
using static System.Array;

namespace ConsoleApp2
{
    class Program
    {
        static long mod = 1000000007;
        static long N;
        static string X;

        static void Main(string[] args)
        {
            //var N = long.Parse(Console.ReadLine());
            //var NK = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
            //var N = NK[0];
            //var K = NK[1];
            X = Console.ReadLine();
            N = X.Length;
            long extra = 0L;
            var S = 0;

            for (int i = 0; i < N; i++)
            {
                if (X[i] == 'S')
                {
                    S++;
                }
                else if(S > 0)
                {
                    S--;
                    extra += 2;
                }
            }

            Console.WriteLine(N - extra);

        }

        static int SearchS(int L)
        {
            for (int i = L + 1; i < N; i++)
            {
                if (X[i] == 'S')
                {
                    return i;
                }
            }
            return (int)N;
        }

        static int SearchT(int R)
        {
            for (int i = R - 1; i >= 0; i--)
            {
                if (X[i] == 'T')
                {
                    return i;
                }
            }
            return -1;
        }

    }
}


Measured memory_bytes: 26760
#include <algorithm>
#include <bits/stdc++.h>
#include<iostream>
#include<string>
using namespace std;
#define rep(i, n) for (int i = 0; i <(int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
const ll MOD=100000007;
const ll INF=1000000101001;
int main(){
int a,b;cin>>a>>b;
cout << a*b << endl;
}

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

int main() {
    string S;
    cin >> S;
    string ans = "AC";
    if (S[0] != 'A') ans = "WA";
    int cnt = 0;
    FOR(i, 1, S.size()) {
        if (isupper(S[i])) {
            if (i == 1 || i == S.size() - 1 || S[i] != 'C') {
                ans = "WA";
            }
            ++cnt;
        }
    }
    if (cnt != 1) ans = "WA";
    cout << ans << endl;
    return 0;
}

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

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

typedef long long ll;
#define INF 1e9

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



int main(){
  int N, T;
  cin >> N >> T;
  vector<int> t(N);
  REP(i, N){
    cin >> t[i];
  }
  ll ans = 0;
  FOR(i, 1, N){
    ans += min(T, t[i] - t[i-1]);
  }
  ans += T;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                Solve.Answer();
            }
            catch (Exception ex)
            {
                WriteLine(ex.ToString());
            }
        }
    }

    public class Solve
    {
        public static void Answer()
        {
            var NM = IO_ShortCut.ReadSplitInt;

            var N = NM[0];
            var M = NM[1];

            WriteLine(MathLib.Cmb(N, 2) + MathLib.Cmb(M, 2));
        }
    }

    public class IO_ShortCut
    {
        #region Input
        public static string ReadString => ReadLine();
        public static int ReadInt => int.Parse(ReadLine());
        public static long ReadLong => long.Parse(ReadLine());
        public static double ReadDouble => double.Parse(ReadLine());

        public static List<string> ReadSplitString => ReadLine().Split().ToList();
        public static List<int> ReadSplitInt => ReadLine().Split().Select(s => int.Parse(s)).ToList();
        public static List<long> ReadSplitLong => ReadLine().Split().Select(s => long.Parse(s)).ToList();
        public static List<double> ReadSplitdouble => ReadLine().Split().Select(s => double.Parse(s)).ToList();
        #endregion

        #region Output
        public static void OutJoinSpace<T>(IEnumerable<T> list) => WriteLine(string.Join(" ", list));
        public static void WriteLineYes_or_No(bool flag) => WriteLine(flag ? "Yes" : "No");

        #endregion
    }

    /// <summary>
    /// 正の数の四則演算のみ対応
    /// </summary>
    public class Mod
    {
        // 割る数の定義
        private readonly static long M = 1000000007;

        // 足し算
        public static long Add(long a, long b) => (a * b) % M;
        // 引き算
        public static long Sub(long a, long b) => (a - b) % M >= 0 ? (a - b) % M : (a - b) % M + M;
        // 掛け算
        public static long Multi(long a, long b) => (a * b) % M;
    }

    public class MathLib
    {
        public static int Cmb(int n, int k)
        {
            var a = 1;
            for (int i = 0; i < k; i++)
            {
                a *= n;
                n--;
            }
            return k == 0 ? 1 : a / k;
        }
    }
}

Measured memory_bytes: 11220
// iostream のscanf, printf では間に合わなかった
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <vector>

using namespace std;

#define INF (1<<29)
#define mp make_pair
#define pb push_back

typedef pair<int,int> pii;

int main(){
	int n, m;
	cin >> n >> m;
	vector<pii> treasure;
	for( int i = 0; i < n; i++ ){
		int x, y;
		//cin >> x >> y;
		scanf("%d %d", &x, &y);
		treasure.pb( mp(x,y) );
	}
	sort(treasure.begin(), treasure.end());
	for( int i = 0; i < m; i++ ){
		int x1, y1, x2, y2;
		//cin >> x1 >> y1 >> x2 >> y2;
		scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
		// search
		int ans = 0;
		vector<pii>::iterator it = lower_bound(treasure.begin(),treasure.end(),mp(x1,y1));
		while( 1 ){
			if( it == treasure.end() || *it > mp(x2,y2) ) break;
			if( (*it).first > x2 ) it = upper_bound(treasure.begin(), treasure.end(),mp(-INF,(*it).second+1));
			if( x1 <= (*it).first && (*it).first <= x2 && y1 <= (*it).second && (*it).second <= y2 ) ans++;
			it++;
		}
		//cout << ans << endl;
		printf("%d\n", ans);
	}
}

Measured memory_bytes: 1336