akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef vector<vector<ll>> vv;
typedef pair<int, int> P;

const int MAX = 301;

// input
int H, W, D;
int A[MAX][MAX];
int Q;
vector<int> L, R;

map<int, P> m;
int n;
vv w;


void input() {
    cin >> H >> W >> D;
    rep(i, H) rep(j, W) cin >> A[i][j];
    cin >> Q;
    L = R = vector<int>(Q);
    rep(i, Q) cin >> L[i] >> R[i];
}


int dis(P p1, P p2) {
    int ret = max(p1.first - p2.first, p2.first - p1.first);
    ret += max(p1.second - p2.second, p2.second - p1.second);
    return ret;
}


int main() {
    input();
    rep(i, H) rep(j, W) m[A[i][j]] = P(i, j);
    int n = (H * W - 1) / D + 1;
    w = vv(D, vector<ll>(n));
    rep(i, D) {
        w[i][0] = 0;
        int j = 1;
        int x = i + 1 + D;
        while (x <= H * W) {
            P p1 = m[x - D];
            P p2 = m[x];
            w[i][j] = w[i][j - 1] + dis(p1, p2);
            x += D;
            j++;
        }
    }
    rep(i, Q) {
        int l = L[i], r = R[i];
        int v = (l - 1) % D;
        l = (l - 1) / D;
        r = (r - 1) / D;
        int ans = w[v][r] - w[v][l];
        cout << ans << endl;
    }
}


Measured memory_bytes: 14660
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define endl "\n"
#define se second
#define ll long long
#define inf 0x3f3f3f3f
#define fast    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int N = 3e5+10;
const ll mod =   1e9+7;

int main()
{  fast
ll a,v,b,w,t;
cin>>a>>v>>b>>w>>t;
ll x=abs(a-b);
if(v<=w){
	cout<<"NO";
}
else
{
	ll y=v-w;
	if(y*t>=x)
	{
		cout<<"YES";
	}else{
		cout<<"NO";
	}
}
}

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

int main(){
    int n,k;
    cin>>n>>k;
    vector<long long int> a(n);
    vector<long long int> posa(n);
    vector<long long int> nega(n);
    for(int i=0;i<n;++i){
        cin>>a[i];
        posa[i]=max(a[i],0LL);
        nega[i]=min(a[i],0LL);

    }
    long long int sum=0;
    for(int i=0;i<k-1;i++){
        sum+=posa[i];
    }
    long long int lessposa=1e15;
    for(int i=k-1;i<n;i++){
        sum+=posa[i];
        lessposa=min(lessposa,sum);
        sum-=posa[i-(k-1)];
    }
    long long int lessnega=-1e15;
    sum=0;
    for(int i=0;i<k-1;i++){
        sum+=nega[i];
    }
    for(int i=k-1;i<n;i++){
        sum+=nega[i];
        lessnega=max(lessnega,sum);
        sum-=nega[i-(k-1)];
    }
    long long int res=accumulate(posa.begin(),posa.end(),0LL);
    res-=min(lessposa,-lessnega);
    cout<<res<<endl;
    return 0;
}


Measured memory_bytes: 2560
#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

int main(){
    string n;
    int sum=0;
    cin>>n;
    for(int i=0;i<n.length();i++){
        sum+=n.at(i)-48;
    }
    if(sum%9==0)cout<<"Yes\n";
    else cout<<"No\n";
}

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

using namespace std;
typedef long long ll;

int main(){
    
    ios_base::sync_with_stdio(0);
    int a,b;
    while(scanf("%d %d" , &a,&b) != EOF){
        //cin>>a>>b;
        ll sum = a+b;
        int cnt=0;
        string res="";
        while(sum){
            res += ((sum%10)+'0');
            sum /= 10;
        }
        cout<<res.length()<<endl;
    }
    return 0;
}




Measured memory_bytes: 3264
#pragma GCC optimize(2)
#include <bits/stdc++.h>
#define int long long
using namespace std;

int n,m;
vector<int> v[60],res[60];
int pw[60],val[2000010],ind[2000010];
int num[60][60];

inline bool dfs(int x,int pr,int des,int pos)
{
	res[pos].push_back(x);
	if(x==des){
		return true;
	}
	for(int i=0;i<v[x].size();i++) if(v[x][i]!=pr){
		int u=v[x][i];
		if(dfs(u,x,des,pos)) return true;
	}
	res[pos].pop_back();
	return false;
}

signed main()
{
	ios::sync_with_stdio(false);
	cin>>n;
	pw[0]=1ll;
	for(int i=1;i<=n;i++) pw[i]=pw[i-1]*2ll;
	for(int i=1;i<n;i++){
		int x,y;
		cin>>x>>y;
		num[x][y]=i;
		num[y][x]=i;
		v[x].push_back(y);
		v[y].push_back(x);
	}
	cin>>m;
	for(int i=1;i<=m;i++){
		ind[1ll<<(i-1ll)]=i;
	}
	for(int i=1;i<=m;i++){
		int u,v;
		cin>>u>>v;
		dfs(u,-1,v,i);
	}
	for(int i=1ll;i<(1ll<<m);i++){
		int mask=i&(-i);
		int loc=ind[mask];
		val[i]=val[i^mask];
		for(int j=0ll;j<res[loc].size()-1;j++){
			int pos1=res[loc][j],pos2=res[loc][j+1ll];
			val[i]|=(1ll<<(num[pos1][pos2]-1ll));
		}
	}
	int ans=0ll;
	for(int i=0ll;i<(1ll<<m);i++){
		int num=__builtin_popcountll(i);
		int tot=n-1ll-__builtin_popcountll(val[i]);
		if(num%2ll==0ll) ans+=pw[tot];
		else ans-=pw[tot];
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 14720
#define _USE_MATH_DEFINES
#include <cmath>
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <string>
#include <numeric>
#include <algorithm>
using namespace std;
using iL = long long;
using iUL = unsigned long long;
using dL = long double;
#define rep( NAME, NUM ) for( int NAME = 0; NAME < ( NUM ); ++NAME )
#define brep( NAME, NUM ) for( int NAME = ( NUM ) - 1; NAME >= 0; --NAME )

int main()
{
    //----------------
    int n, m;
    cin >> n >> m;
    vector< int > p, y;
    vector< map<int, int> > vec2( n );
    rep( i, m )
    {
        int p_, y_;
        cin >> p_ >> y_;
        p.push_back( p_ );
        y.push_back( y_ );
        vec2[p_-1][y_] = 0;
    }
    rep( i, n )
    {
        int j = 0;
        for( auto& m : vec2[i] ) 
        {
            m.second = j++;
        }
    }

    rep( i, m )
    {
        cout << setfill('0') << setw(6) << p[i];
        cout << setfill('0') << setw(6) << vec2[p[i]-1][y[i]]+1 << endl;
    }

    //----------------
    return 0;
}

Measured memory_bytes: 11632
#include <bits/stdc++.h>
#if 1
#define int long long
#define MAX LLONG_MAX
#define MIN LLONG_MIN
#define stoi stoll
#else
#define MAX INT_MAX
#define MIN INT_MIN
#endif
#define INF MAX/2
#define ALL(obj) (obj).begin(), (obj).end()
#define fi first
#define se second
const int NIL = -1;
const int MOD = 1000000007;
#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;

int pow(int x, int n) {int res=1; while(n){if(n&1)res*=x;x*=x;n>>=1;} return res;}
int get_gcd(int a, int b) {while(1){if (a < b) swap(a, b); if (b == 0) return a; a %= b;}}
int get_lcm(int a, int b) {return a * b / get_gcd(a, b);}
bool chmin(int &a, int b) {if(a>b){a=b; return true;} else return false;}
bool chmax(int &a, int b) {if(a<b){a=b; return true;} else return false;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

//-------------------------テンプレここまで-------------------------//

int memo[100000];
bool done[100000];
vector<int> G[100000];

//dfs(i) ... node i(0-index)から計算した時の最大長
int dfs(int n) {
  if(done[n]) return memo[n];

  int ret = 0;
  for (auto& c: G[n]) {
    chmax(ret, dfs(c) + 1);
  }

  done[n] = true;
  return memo[n] = ret;
}

signed main () {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int N, M;
  cin >> N >> M;
  REP(i,M) {
    int x, y;
    cin >> x >> y;
    x--; y--;
    G[x].push_back(y);
  }

  int ans = 0;
  REP(i,N) {
    chmax(ans, dfs(i));
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 8704
#include<iostream>

using namespace std;

int main(){
    int k,x;
    cin>>k>>x;
    for(int i=x-k+1; i<x+k; i++){
        cout<<i;
        if(i<x+k-1){
            cout<<" ";
        }
    }
    cout<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
const int N=1e5+6;
int n,sta[N],top,R,C;
bool vis[N];
vector<pair<int,int> >v[4];
inline bool chk(int x,int y){return x==0||x==R||y==0||y==C;}
void push(int r,int c,int id){
	if(!r)v[0].emplace_back(c,id);else if(c==C)v[1].emplace_back(r,id);else
	if(r==R)v[2].emplace_back(C-c,id);else v[3].emplace_back(R-r,id);
}
int main(){
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	cin>>R>>C>>n;
	for(int i=1;i<=n;++i){
		int r1,c1,r2,c2;
		cin>>r1>>c1>>r2>>c2;
		if(chk(r1,c1)&&chk(r2,c2))push(r1,c1,i),push(r2,c2,i);
	}
	for(int i=0;i<4;++i){
		sort(v[i].begin(),v[i].end());
		for(auto x:v[i]){
			int id=x.second;
			if(!vis[id])sta[++top]=id,vis[id]=1;else if(!top||sta[top]!=id){cout<<"NO\n";return 0;}else --top;
		}
	}
	cout<<"YES\n";
	return 0;
}

Measured memory_bytes: 2540
package main

import (
	"fmt"
	"math"
)

func main() {
	// Code for B - Training Camp
	var N int
	fmt.Scanf("%d", &N)

	var ans int = 1
	for i := 1; i <= N; i++ {
		//ans *= i
		//if ans > int(math.Pow10(9)+7) {
		ans = (i * ans) % (int(math.Pow10(9) + 7))
		//}
	}
	fmt.Println(ans) // % (int(math.Pow10(9) + 7)))
}


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

using namespace std;

const int ATOZ = 26;

int satisfaction(int d, int prev_v, const vector<int>& c, const vector<vector<int> >& s, const vector<int>& t, map<int, int>& last) {
    int v = prev_v + s[d][t[d]];
    last[t[d]] = d;
    for (int i = 0; i < ATOZ; ++i) {
        v -= c[i] * (d - last[i]);
    }
    return v;
}

void reset(map<int, int>& last) {
    last.clear();
    for (int i = 0; i < ATOZ; ++i) {
        last[i] = -1;
    }
}

int finalSatisfaction(const vector<int>& c, const vector<vector<int> >& s, const vector<int>& t) {
    map<int, int> last;
    reset(last);
    int v = 0;
    for (int d = 0; d < s.size(); ++d) {
        v = satisfaction(d, v, c, s, t, last);
    }
    return v;
}

void Main() {
    int D;
    cin >> D;
    vector<int> c(ATOZ, 0);
    for (int i = 0; i < ATOZ; ++i) {
        cin >> c[i];
    }
    vector<vector<int> > s(D, vector<int>(ATOZ, 0));
    for (int i = 0; i < D; ++i) {
        for (int j = 0; j < ATOZ; ++j) {
            cin >> s[i][j];
        }
    }
    //vector<vector<int> > s_index(D, vector<int>(ATOZ, 0));
    //for (int d = 0; d < D; ++d) {
    //    vector<int> stemp = s[d];
    //    for (int i = 0; i < ATOZ; ++i) {
    //        s_index[d][i] = distance(stemp.begin(), max_element(stemp.begin(), stemp.end()));
    //    }
    //}

    vector<int> t(D, 0);
    for (int d = 0; d < D; ++d) {
        auto maxIt = max_element(s[d].begin(), s[d].end());
        t[d] = 1 + distance(s[d].begin(), maxIt);
        cout << t[d] << endl;
    }

    //for (int i = 0; i < 10; ++i) {
    //    t[d]
    //    finalSatisfaction
    //}
}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 3680
s = input()

while len(s) > 4:
    if s[-5:] == 'dream':
        s = s[:-5]
    elif s[-7:] == 'dreamer':
        s = s[:-7]
    elif s[-5:] == 'erase':
        s = s[:-5]
    elif s[-6:] == 'eraser':
        s = s[:-6]
    else:
        break

print('NO' if len(s) > 0 else 'YES')


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

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

    int ans = 700;
    if (s[0] == 'o') {
        ans += 100;
    }

    if (s[1] == 'o') {
        ans += 100;
    }

    if (s[2] == 'o') {
        ans += 100;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
from collections import Counter

N = int(input())
A = list(map(int,input().split()))

L = [A[i]+i for i in range(N)]
R = [j-A[j] for j in range(N)]

l = Counter(L)
r = Counter(R)

ans = 0
for i in l.keys():
    ans += l[i]*r[i]

print(ans)

Measured memory_bytes: 63468
N,M = [int(i) for i in input().split()]
A,B = [],[]
for i in range(N):
    x = [int(i) for i in input().split()]
    A.append(x)
for i in range(M):
    x = [int(i) for i in input().split()]
    B.append(x)

for i in range(N):
    for j in range(M):
        dis = abs(A[i][0] - B[j][0]) + abs(A[i][1] - B[j][1])
        if j == 0:
            min = dis
            tmp = j
        else:
            if dis < min:
                min = dis
                tmp = j
    print(tmp+1)


Measured memory_bytes: 3064
# フィボナッチ数列を作るのが鍵となる

fivarray = [1,1,2,3,5,8,13,21,34,55]

h,w,k = gets.split.map(&:to_i)

arr = Array.new(h+1).map{Array.new(w,0)}

arr[0][0] = 1

i = 0

(h*w).times{
    
    
    syou = i/w+1
    amari = i%w
    

    
    arr[syou][amari]+=fivarray[amari]*fivarray[w-amari-1]*arr[syou-1][amari]
    
    if amari>0
    arr[syou][amari]+=fivarray[amari-1]*fivarray[w-amari-1]*arr[syou-1][amari-1]
    end
    
    if amari<w-1
    arr[syou][amari]+=fivarray[amari]*fivarray[w-amari-2]*arr[syou-1][amari+1]
    end
    
  i+=1  
 
}

p arr[-1][k-1]%1000000007






Measured memory_bytes: 1916
#C

l,r = (int(x) for x in input().split())

if r-l >= 2018:
    print(0)
else:
    l = l % 2019
    r = r % 2019
    
    if l>r:
        print(0)
        
    else:
        count = 10000
        for i in range(l,r):
            for j in range(i+1,r+1):
                temp = (i * j) % 2019
                count = min(count,temp)
        print(count)


Measured memory_bytes: 41692
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define outmat(v) for(auto i : v){for(auto j : i) cout << j << " ";cout << endl;}
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define pb push_back
#define mod 1000000007
#define infi 1900000000
#define infl 1100000000000000000
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
#define csp << " " <<
#define outset(n) cout << fixed << setprecision(n);
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
template<typename T> using ve = vector<T>;
template<typename T> using pq2 = priority_queue<T>;
template<typename T> using pq1 = priority_queue<T,vector<T>,greater<T>>;



template <typename T> T gcd(T a, T b) {if(b == 0) return a;return gcd(b,a%b);}
template <typename T> T lcm(T a, T b) {return a*b/gcd(a,b);}
template <typename T> T extgcd(T a, T b, T& x, T& y){
    T d = a;
    if(b != 0){d = extgcd(b,a%b,y,x); y-=(a/b)*x;}
    else x=1,y=0;
    return d;
}
template <typename T> T modpow(T x, T n, T m) {
    if(n==0) return 1;
    T resp = modpow(x*x%m,n/2,mod);
    if(n&1) resp = resp*x%m;
    return resp;
}
template <typename T> T modinverse(T a, T m) {
    T x,y;
    extgcd(a,m,x,y);
    return (m+x%m)%m;
}




int main()
{
    string L;
    cin >> L;
    
    ll N = ll(L.length());
    ll one = 1;
    rep(i,N) if(L[i] == '1') one*=2,one%=mod;
    ll fore = 1;
    
    
    ll ans = one;
    
    for(ll i = N-1; i >= 0; i--){
        if(L[i] == '1'){
            
            ll a = modinverse<ll>(2,mod);
            one *= a%mod;
            one %= mod;
            ans += one*fore%mod;
            ans %= mod;
            
        }
        fore*=3;
        fore%=mod;
    }
    
    out(ans);
    

    
    
    
    

    return 0;
}


Measured memory_bytes: 512
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<sstream>
#include<stack>
#include<string>
#include<unordered_set>
#include<vector>

#define ll long long
#define P pair<int,int>
#define FOR(i,N) for(int i=0;i<(int)N;i++)
#define FORIN(i,a,b) for(int i=a;i<(int)b;i++)
#define ALL(x) (x).begin(),(x).end()
#define LAST(x) (x)[(x).size()-1]
#define GI(name) int (name);scanf("%d",&(name))
#define GI2(name1,name2) int (name1),(name2);scanf("%d %d",&(name1),&(name2))
#define GI3(name1,name2,name3) int (name1),(name2),(name3);scanf("%d %d %d",&(name1),&(name2),&(name3))
#define GVI(name,size) vector<int> (name)(size);FOR(i,(size)scanf("%d",&(name)[i])

using namespace std;

string to_hex(int x){
    stringstream ss;
    ss<<hex<<x;
    return ss.str();
}

inline int get_int(){
    int ret;
    scanf("%d",&ret);
    return ret;
}

inline vector<int> get_ints(int n){
    vector<int> ret(n);
    FOR(i,n){
        scanf("%d",&ret[i]);
    }
    return ret;
}

inline string get_str(){
    string ret;
    cin>>ret;
    return ret;
}

bool is_prime(int n){
    int s=sqrt(n)+1;
    for(int i=2;i<=s;++i){
        if(n%i==0){
            return 0;
        }
    }
    return 1;
}

vector<P> prime_division(int n){
    vector<P> ret;
    int s=sqrt(n)+1;
    int c=0;
    for(int i=2;i<=s;++i){
        if(n%i==0){
            c=0;
            do{
                ++c;
                n/=i;
            }while(n%i==0);
            ret.push_back(P(i,c));
        }
    }
    return ret;
}

string to_string(string s){
    return s;
}

template<class T>
string to_string(vector<T> v){
    string ret="{";
    FOR(i,v.size()-1){
        ret+=to_string(v[i])+",";
    }
    if(v.size()>0){
        ret+=to_string(LAST(v));
    }
    ret+="}";
    return ret;
}

void debug(){
    cerr<<endl;
}

template<class Head,class... Tail>
void debug(Head head,Tail... tail){
    cerr<<to_string(head)<<" ";
    debug(tail...);
}

void print(){
    cout<<endl;
}

template<class Head,class... Tail>
void print(Head head,Tail... tail){
    cout<<to_string(head);
    print(tail...);
}

int main(){
    string s=get_str();
    string t=get_str();
    for(int i=0;i<s.size()-1;++i){
        for(int j=s.size()-2;j>=i;--j){
            if(s[j]>s[j+1])swap(s[j],s[j+1]);
        }
    }
    for(int i=0;i<t.size()-1;++i){
        for(int j=t.size()-2;j>=i;--j){
            if(t[j]<t[j+1])swap(t[j],t[j+1]);
        }
    }
    print(s<t?"Yes":"No");
    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;

  int ans;

  // A   B
  //     C     D
  if (B <= C)
    ans = 0;

  //  A   B
  //     C     D
  if (A < C && B > C && B < D)
    ans = B - C;

  //     A   B
  //     C     D
  if (A >= C && B > C && B < D)
    ans = B - A;

  //       A   B
  //     C     D
  if (A >= C && A < D && B > C && B >= D)
    ans = D - A;

  //           A   B
  //     C     D
  if (A >= D)
    ans = 0;

  //    A       B
  //     C     D
  if (A <= C && B >= D)
    ans = D - C;

  cout << ans << endl;
}

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

int main(void) {

    int A, B, H, M;
    std::cin >> A >> B >> H >> M;
    double a_A, a_B;
    a_A = (double)(30 * H) + 0.5 * (double)M;
    a_B = 6 * M;
    double theta = max(a_A, a_B) - min(a_A, a_B);
    if (theta >= 180.0) {
        theta = 360 - theta;
    }
    theta = theta * M_PI / 180.0;
    double f = (double)A - (double)B * cos(theta);
    double g = (double)B * sin(theta);
    double ans = sqrt(f * f + g * g);
    printf("%.15lf\n", ans);
    return 0;
}


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

int main()
{
  int w, h, n;
  cin>>w>>h>>n;
  int x[n], y[n], a[n];
  for(int i = 0; i<n;i++)
  {
    cin>>x[i]>>y[i]>>a[i];
  }

  int s_x = 0, s_y = 0, e_y = h, e_x = w;
  for(int i = 0;i<n; i++)
  {
  //   if(a[i] == 1)
  //   {
  //   s_x = x[i];
  //   if(s_x > e_x)
  //   s_x = e_x;
  //   }else if(a[i] == 2)
  //   {
  //   e_x = x[i];
  //   if(e_x < s_x)
  //   e_x = s_x;
  // }else if(a[i] == 3)
  // {
  //   s_y = y[i];
  //   if(s_y > e_y)
  //   s_y = e_y;
  // }else if(a[i] == 4)
  //   {e_y = y[i];
  //     if(e_y < s_y)
  //       e_y = s_y;
  //   }

    if(a[i] == 1)
    {
      if(s_x < x[i])
      {
        s_x = x[i];
      }
    }
    else if(a[i] == 2)
    {
      if(e_x > x[i])
      {
        e_x = x[i];
      }
    }
    else if(a[i] == 3)
    {
      if(s_y < y[i])
      {
        s_y = y[i];
      }
    }
    else if(a[i] == 4)
    {
      if(e_y > y[i])
      {

        e_y  = y[i];

      }
    }





  }

  int r = max((e_x - s_x),0)*max((e_y - s_y),0);

  cout<<r<<endl;

  return 0;
}


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

ll ppow(ll n, ll a) {
	ll res = 1;
	while (a) {
		if (a & 1)res = (res*n) % MOD;
		n = (n*n) % MOD;
		a >>= 1;
	}
	return res;
}
int main() {
	int m, n; cin >> m >> n;
	cout << ppow(m, n) << endl;
}

Measured memory_bytes: 3092
#include <stdio.h>
#include <algorithm>
int n, q, l, r;
char s[100001];
int a[100001];
int main() {
	scanf("%d%d", &n, &q);
	scanf(" %s", s);
	for (int i = 1; i < n; i++) {
		if (s[i] == 'C' && s[i - 1] == 'A')a[i + 1]++;
	}
	for (int i = 1; i <= n; i++) {
		a[i] += a[i - 1];
	}
	for (int i = 0; i < q; i++) {
		scanf("%d%d", &l, &r);
		printf("%d\n", a[r] - a[l]);
	}
}

Measured memory_bytes: 2216
s=input()
t=input()
a=-1
c=0
if not set(t)<=set(s):print(-1);exit()
for i in t:
  a=s.find(i,a+1)
  if a==-1:
    c+=1
    a=s.find(i)
print(c*len(s)+a+1)

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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vvint = vector<vint>;
using vvvint = vector<vvint>;
using vdouble = vector<double>;
using vvdouble = vector<vdouble>;
using vvvdouble = vector<vvdouble>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using uint = unsigned int;
using ull = unsigned long long;

template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;

template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { return (a > b && (a = b, true)); }
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return (a < b && (a = b, true)); }

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

template<typename T>
istream& operator >>(istream &is, vector<T> &v) {
	for (auto &u : v) is >> u; return (is);
}

template<typename T1, typename T2>
istream& operator >>(istream &is, pair<T1, T2> &p) {
	return (is >> p.first >> p.second);
}

bool solve() {
	int N, L, R; cin >> N >> L >> R;
	vint A(N); cin >> A;
	int cnt = 0;
	if (N == 0 && L == 0 && R == 0) return (false);
	for (int y = L; y <= R; y++) {
		int i;
		for (i = 0; i < N; i++) {
			if (y % A[i] == 0) {
				if (i % 2 == 0) cnt++;
				break;
			}
		}
		if (i == N && N % 2 == 0) {
			cnt++;
		}
	}
	cout << cnt << el;
	return (true);
}

void Main() {
	while (solve());
}

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



Measured memory_bytes: 3108
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N;
    cin >> N;
    int cnt=0;
    for(int i=0; i<N; i++){
        int p;
        cin >> p;
        if(p!=i+1)                /*p[i]=iとしない*/
        cnt++;
    }
  
    if(cnt>2)cout<<"NO";
    else cout<<"YES";
    return 0;
}

Measured memory_bytes: 256
package main

import (
    "fmt"
    "os"
    "bufio"
    "strconv"
    // "sort"
)
var sc = bufio.NewScanner(os.Stdin)


func main() {
    sc.Split(bufio.ScanWords)
    // code goes here
    
    a, b := nextInt(), nextInt();
    
    fmt.Println((a*b)/2);
}



func nextInt() int {
    sc.Scan()
    v, e := strconv.Atoi(sc.Text())
    if e != nil { panic(e) }
    return v
}
func nextInt64() int64 {
    sc.Scan()
    v, e := strconv.ParseInt(sc.Text(), 10, 64)
    if e != nil { panic(e) }
    return v
}
func nextString() string {
    sc.Scan()
    return sc.Text()
}
func nextFloat() float64 {
    sc.Scan()
    v, e := strconv.ParseFloat(sc.Text(), 64)
    if e != nil { panic(e) }
    return v
}
func Max(x, y int) int { if x > y { return x }; return y }
func Min(x, y int) int { if x < y { return x }; return y }
func Abs(x int) int { if x > 0 { return x }; return -x }


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main(){
  cout << fixed << setprecision(10);
  long long W, H, x, y;
  cin >> W >> H >> x >> y;
  cout << (double) W * H / 2;
  cout << ' ';
  if (x * 2 == W && y * 2 == H){
    cout << 1 << endl;
  } else {
    cout << 0 << endl;
  }
}

Measured memory_bytes: 256
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    A, B, C, D = LI()

    # X以下の自然数でCでもDでも割り切れないものの個数
    def f(X):
        ret = X - X // C - X // D + X // (C * D // math.gcd(C, D))
        return ret

    ans = f(B) - f(A - 1)
    print(ans)

if __name__ == '__main__':
    resolve()


Measured memory_bytes: 10040
#include <bits/stdc++.h>
using namespace std;
#define lp(i, x, n) for (int i = x; i < (int)n; ++i)
#define all(v) (v).begin(), (v).end()
#define sz(v) (int)(v).size()
#define ll long long
#define N 123451

int n;

int main(){

        scanf("%d", &n);
        int ev = 0, od = 0;
        if (n & 1) {
                ev = n / 2;
                od = ev + 1;
                printf("%d", (n * (n - 1) / 2) - (ev * (ev - 1) / 2) - (od * (od -1) / 2));
        } else {
                ev = od = n / 2;
                printf("%d", (n * (n - 1) / 2) - (ev * (ev - 1) / 2) - (od * (od -1) / 2));
        }
        return 0;
}




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

int main() {
  int A, B, Ans=9999;
  cin >> A >> B;
  for(int i=B*20; i>=B*9; i--){
    if(i*0.08>=A && i*0.08<A+1 && i*0.1>=B && i*0.1<B+1) Ans=i;
    else if(i*0.08<=A-1 || i*0.1<=B-1) break;
  }
  if(Ans==9999) cout << -1 << endl;
  else cout << Ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
	int a[5],k;
	scanf("%d%d%d%d%d%d",&a[0],&a[1],&a[2],&a[3],&a[4],&k);
	int min = a[0];
	int max = a[0];
	for(int i=0;i<5;i++){
		if(max<=a[i]){
			max=a[i];
		}
		if(min>=a[i]){
			min=a[i];
		}
	}
	if(max-min>k){
		printf(":(");
	}
	else{
		printf("Yay!");
	}
	return 0;
}

Measured memory_bytes: 128
#ifdef MY_LOCAL
#define MY_NAMESPACE(ns) namespace ns {
#define MY_NAMESPACE_    }
#define MY_DEBUG(s)      s
#else
#define MY_NAMESPACE(ns) 
#define MY_NAMESPACE_    
#define MY_DEBUG(s)      
#endif

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <tuple>
#include <unordered_map>
#include <utility>
#include <vector>

using namespace std;

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

#define EPS (1e-7)


MY_NAMESPACE(testbed)
const ll inf = 1e9;
#define sz      15
int arr[sz][sz];
vector < int > cost;

int main() {
	int n, m, x, i, j, val;

	cin >> n >> m >> x;
	for (i = 1; i <= n; i++) {
		cin >> val;
		cost.push_back(val);
		for (j = 1; j <= m; j++) {
			cin >> arr[i][j];
		}
	}

	int ans = inf;
	int all = (1 << n);
	for (int mask = 0; mask < all; mask++) {
		int c = 0;
		vector < int > level(m + 1);
		for (i = 1; i <= n; i++) {
			if (mask & (1 << (i - 1))) {
				c += cost[i - 1];
				for (j = 1; j <= m; j++) {
					level[j] += arr[i][j];
				}
			}
		}
		bool ok = true;
		for (i = 1; i <= m; i++) {
			if (level[i] < x)ok = false;
		}
		if (ok)ans = min(ans, c);
	}
	if (ans == inf)cout << -1 << endl;
	else    cout << ans << endl;


	return 0;
}
MY_NAMESPACE_

Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define LLI long long int
#define FOR(v, a, b) for(LLI v = (a); v < (b); ++v)
#define FORE(v, a, b) for(LLI v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(LLI v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it)
#define RITR(it, c) for(auto it = (c).rbegin(); it != (c).rend(); ++it)
#define EXIST(c,x) ((c).find(x) != (c).end())
#define fst first
#define snd second
#define popcount __builtin_popcount
#define UNIQ(v) (v).erase(unique(ALL(v)), (v).end())
#define bit(i) (1LL<<(i))

#ifdef DEBUG
#include <misc/C++/Debug.cpp>
#else
#define dump(...) ((void)0)
#endif

#define gcd __gcd

using namespace std;
template <class T> constexpr T lcm(T m, T n){return m/gcd(m,n)*n;}

template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;}
template <typename T> istream& operator>>(istream &is, vector<T> &v){for(auto &a : v) is >> a; return is;}
template <typename T, typename U> istream& operator>>(istream &is, pair<T,U> &p){is >> p.first >> p.second; return is;}

template <typename T, typename U> bool chmin(T &a, const U &b){return (a>b ? a=b, true : false);}
template <typename T, typename U> bool chmax(T &a, const U &b){return (a<b ? a=b, true : false);}
template <typename T, size_t N, typename U> void fill_array(T (&a)[N], const U &v){fill((U*)a, (U*)(a+N), v);}

template <typename T> class WeightedUnionFind{
  vector<int> parent, depth, size;
  vector<T> weight;
  int count;

public:
  WeightedUnionFind(int n): parent(n), depth(n,1), size(n,1), weight(n,0){
    iota(ALL(parent),0);
  }
  
  int get_root(int i){
    if(parent[i] == i) return i;
    else {
      int p = get_root(parent[i]);
      weight[i] += weight[parent[i]];
      return parent[i] = p;
    }
  }

  T get_weight(int i){get_root(i); return weight[i];} 
  bool is_same(int i, int j){return get_root(i) == get_root(j);}
  T diff(int i, int j){return get_weight(i)-get_weight(j);}
  
  int merge(int i, int j, T w){
    int ri = get_root(i), rj = get_root(j);
    if(ri == rj) return ri;
    else{
      if(depth[ri] < depth[rj]){
        parent[ri] = rj; size[rj] += size[ri]; weight[ri] = w - weight[i] + weight[j];
        return rj;
      }else{
        parent[rj] = ri; size[ri] += size[rj]; weight[rj] = -w + weight[i] - weight[j];
        if(depth[ri] == depth[rj]) ++depth[ri];
        return ri;
      }
    }
  }
  
  int get_size(int i){return size[get_root(i)];}
  int count_group(){return count;}
};

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

  int n,m;
  while(cin >> n >> m){
    WeightedUnionFind<int> wuf(n);
    bool ans = true;

    REP(i,m){
      int l,r,d; cin >> l >> r >> d;
      --l, --r;

      if(wuf.is_same(l,r)){
        int diff = wuf.diff(l,r);
        if(d != diff){
          ans = false;
        }
      }else{
        wuf.merge(l,r,d); 
      }
    }

    cout << (ans ? "Yes" : "No") << endl;
  }

  return 0;
}


Measured memory_bytes: 1792
#include <vector>
#include <cstdio>
#include <string>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;

const int N=3e5+5;
int n,n0,n1,p[N],p0[N],p1[N];

template <typename _Tp> inline void IN(_Tp&x) {
	char ch;bool flag=0;x=0;
	while(ch=getchar(),!isdigit(ch)) if(ch=='-') flag=1;
	while(isdigit(ch)) x=x*10+ch-'0',ch=getchar();
	if(flag) x=-x;
}

struct BIT {
	int c[N],res;
	inline int lowbit(int x) {return x&(-x);}
	inline void update(int x) {for(;x<=n;x+=lowbit(x)) ++c[x];}
	inline int query(int x) {res=0;for(;x;x-=lowbit(x)) res+=c[x];return res;}
}bit;

inline ll calc(int*a,int len) {
	memset(bit.c,0,sizeof(bit.c));
	ll ans=0;
	for(int i=len;i;--i) ans+=bit.query(a[i]-1),bit.update(a[i]);
	return ans;
}

int main() {
	IN(n);
	for(int i=1;i<=n;++i) IN(p[i]);
	for(int i=1;i<=n;i+=2) p0[++n0]=p[i];
	for(int i=2;i<=n;i+=2) p1[++n1]=p[i];
	for(int i=1;i<=n0;++i) if((p0[i]&1)==0) return puts("No"),0;
	for(int i=1;i<=n1;++i) if((p1[i]&1)==1) return puts("No"),0;
	ll sum=calc(p,n),sum0=calc(p0,n0),sum1=calc(p1,n1);
	if(sum==(sum0+sum1)*3ll) puts("Yes");
	else puts("No");
	return 0;
}

Measured memory_bytes: 4608
#include<stdio.h>

int main(){
    int i,len,flag;
    char input[201];

    while(1){
        for(len = 0;;len++){
            if(scanf("%c",&input[len]) == EOF)return 0;
            if(input[len] == '\n')break;
        }
        input[len] = '\0';
        
        if(len % 2){
            puts("NA");
            continue;
        }
        for(flag = 0,i = 0;i < len;i += 2){
            if(input[i] > '6' || input[i] == '0'){
                puts("NA");
                flag = 1;
                break;
            }
            if(input[i + 1] > '5' || input[i + 1] == '0'){
                puts("NA");
                flag = 1;
                break;
            }
        }
        if(flag)continue;

        for(i = 0;i < len;i += 2){
            switch((input[i] - '0') * 5 + input[i + 1]-'0'){
                case 32:
                    printf(".");
                    break;
                case 33:
                    printf("?");
                    break;
                case 34:
                    printf("!");
                    break;
                case 35:
                    printf(" ");
                    break;
                default:
                    printf("%c",(input[i] - '0') * 5 + input[i + 1]-'0'+91);
                    break;
            }
        }
        puts("");
    }
    return 0;
}

Measured memory_bytes: 524
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){

	int N,T,A;
	cin>>N>>T>>A;
	std::vector<int>H(N);
	for(int i=0;i<N;i++)
		cin>>H[i];

	std::vector<int>ans(N);
	for(int i=0;i<N;i++){
		ans[i]=T*500-H[i]*3;
	}
	int y,z;
	y=abs(ans[0]-A*500);
	int anser=1;
	for(int i=1;i<N;i++){
		z=abs(ans[i]-A*500);
		if(z<y){
			y=z;
			anser=i+1;
		}
	}
	cout<<anser<<endl;
	return 0;
}

Measured memory_bytes: 256
# %%time
s = input()
c = 0
mod = 2019
s_int = list(map(int, list(s)))

tens = [1]
for k in range(len(s)):
    tens.append((tens[-1] * 10)%mod )

ms = []
m = s_int[-1]%mod
ms.append(m)
for i in range(len(s) - 1)[::-1]:
    m = s_int[i] * tens[len(s) - i - 1] +  m
    m = m %mod
    ms.append(m)
    if m == 0:
        c += 1
        
from collections import Counter
co = Counter(ms)
for v in co.values():
    c += v * (v - 1) // 2

print(c)

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

using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;
typedef vector < vector<ll> > Mat;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

struct UnionFind{
  int N, Group[int(2e5+5)];
  void Make(){
    for (int i = 1; i <= N; i++) Group[i] = i;
  }
  void Union(int u, int v){
    int Gu = Group[u], Gv = Group[v];
    while (Gu != Group[Gu]) Gu = Group[Gu];
    while (Gv != Group[Gv]) Gv = Group[Gv];
    Group[u] = min(Gu, Gv);
    Group[v] = min(Gu, Gv);
    Group[max(Gu, Gv)] = min(Gu, Gv);
  }
  bool Check(int u, int v){
    int Gu = Group[u], Gv = Group[v];
    while (Gu != Group[Gu]) Gu = Group[Gu];
    while (Gv != Group[Gv]) Gv = Group[Gv];
    if (Gu == Gv) return true;
    else return false;
  }
};

int main(){
  int N, Q; cin >> N >> Q;
  UnionFind UF; UF.N = N; UF.Make();

  for (int i = 0; i < Q; i++){
    int T, U, V; cin >> T >> U >> V;
    if (T == 0) UF.Union(U, V);
    else cout << UF.Check(U, V) << endl;
  }

  return 0;
}


Measured memory_bytes: 4396
#include <stdio.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
    long n,d;
    scanf("%ld %ld", &n, &d);
    long nCount = 0;
    for(long i = 0; i < n; i++){
        long x, y;
        scanf("%ld %ld", &x, &y);
        if(x * x + y * y <= d * d){
            nCount++;
        }
    }
    printf("%ld", nCount);
    return 0;
}


Measured memory_bytes: 3228
# coding: utf-8
# Your code here!
import copy

S = list(input())

ans_list = list()

for i in range(2**(len(S)-1)):
    tmp = copy.copy(S)
    for j in range(len(S)-1):
        if((i>>j)&1) == 1:
            tmp.insert(len(S)-j-1,'+')
    ans_list.append(tmp)
    
cnt = 0
for ans in ans_list:
    cnt += sum(map(int,(''.join(ans).split('+'))))
print(cnt)
    

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

int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());
  int count = 0;
  for (int i = 0; i + 1 < N; i++) {
    if (vec.at(i) == vec.at(i + 1)) {
      count++;
    }
  }
  cout << N - count << endl;
}


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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using pll = pair<ll,ll>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define REV(x) reverse(ALL((x)))
#define ASC(x) sort(ALL((x)))
#define DESC(x) ASC((x)); REV((x))
#define pb push_back
#define eb emplace_back

ll maze(vector<string> S, pll start, ll H, ll W)
{
    queue<pll> Q;
    mat D(H, vec(W, INF));
    ll d = 0;
    Q.push(start);
    D[start.first][start.second] = 0;

    while(!Q.empty()) {
        pll v = Q.front(); Q.pop();
        ll i = v.first, j = v.second;
        REP(di,-1,2) {
            REP(dj,-1,2) {
                if(di * dj == 0 && !(di == 0 && dj == 0)) {
                    ll k = i + di, l = j + dj;
                    if(S[k][l] == '.' && D[k][l] == INF) {
                        D[k][l] = MIN(D[k][l],D[i][j]+1);
                        Q.push({k, l});
                        d = MAX(d,D[k][l]);
                    }
                }
            }
        }
    }

    return d;
}

int main()
{
    ll H, W;
    cin >> H >> W;
    vector<string> S(H+2);
    S[0] = string(W+2, '#');
    S[H+1] = string(W+2, '#');
    REP(i,1,H+1) {
        string s;
        cin >> s;
        S[i] = "#" + s + "#";
    }

    ll m = 0, d = 0;
    REP(i,1,H+1) {
        REP(j,1,W+1) {
            if(S[i][j] == '.') {
                d = maze(S, {i, j}, H+2, W+2);
                m = MAX(m,d);
            }
        }
    }
    PR(m);

    return 0;
}

/*



*/

Measured memory_bytes: 3636
let round x =
  int_of_float (floor (0.5 +. x))

let _ =
  let s = ref 0
  and n = ref 0
  and c = ref 0 in
  try
    while true do
      let x, y = Scanf.scanf "%d,%d\n" (fun x y -> (x, y)) in
      incr c;
      s := !s + x * y;
      n := !n + y
    done
  with
    End_of_file ->
    Printf.printf "%d\n" !s;
    Printf.printf "%d\n" (round ((float_of_int !n) /. (float_of_int !c)))

Measured memory_bytes: 2372
#include <iostream>
#include <vector>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<int> a(N);
  for(int i = 0; i < N; i++) cin >> a[i];
  int m1 = 0, m2 = 0;
  for(int i = 0; i < N; i++){
    if(m1 <= a[i]){
      m2 = m1;
      m1 = a[i];
    }
    else if(m1 > a[i] && m2 < a[i]) m2 = a[i];
  }
  for(int i = 0; i < N; i++){
    if(a[i] == m1) cout << m2 << endl;
    else cout << m1 << endl;
  }
}


Measured memory_bytes: 4060
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T> using vt = vector<T>;
template<class T> using vvt = vector<vt<T>>;
template<class T> using ttt = tuple<T,T>;
using tii = tuple<int,int>;
using vi = vector<int>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define mt make_tuple
#define ALL(a) (a).begin(),(a).end()
#define FST first
#define SEC second
#define DEB cerr<<"!"<<endl
#define SHOW(a,b) cerr<<(a)<<" "<<(b)<<endl
#define DIV int(1e9+7)
const int INF = (INT_MAX/2);
const ll LLINF = (LLONG_MAX/2);
const double eps = 1e-8;
//const double PI = M_PI;  
inline ll pow(ll x,ll n,ll m){ll r=1;while(n>0){if((n&1)==1)r=r*x%m;x=x*x%m;n>>=1;}return r%m;}
inline ll lcm(ll d1, ll d2){return d1 / __gcd(d1, d2) * d2;}
 
/* Coding space */

int main(){
  int n,a,b; cin >> n >> a >> b;
  cout << ((abs(a-b)%2)?"Borys":"Alice") << endl;
  return 0;
}

Measured memory_bytes: 256
n = int(input())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
factorial = [1,2,6,24,120,720,5040,40320] 

a = [i for i in range(1,n+1)]
cnt = 0
for i in range(n):
    if i == 0:
        cnt += (p[0]-1)*factorial[(n-i-1)-1]
        a.remove(p[0])
    else:
        if a.index(p[i]) == 0:
            if i == n-1:
                cnt += 1 
        else:
            cnt += a.index(p[i]) * factorial[(n-i-1)-1]
        a.remove(p[i])
a = [i for i in range(1,n+1)]
cnt_q = 0
for i in range(n):
    if i == 0:
        cnt_q += (q[0]-1)*factorial[(n-i-1)-1]
        a.remove(q[0])
    else:
        if a.index(q[i]) == 0:
            if i == n-1:
                cnt_q += 1 
        else:
            cnt_q += a.index(q[i]) * factorial[(n-i-1)-1]
        a.remove(q[i])
print(abs(cnt-cnt_q))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;

int main(){
  ll H, W, N;
  cin >> H >> W >> N;
  map<pll, ll> col;

  ll a, b;
  rep(i, N){
    cin >> a >> b;
    rep2(j, -2, 1){
      rep2(k, -2, 1){
        if((a + j >= 1) && (a + j <= H - 2) && (b + k >= 1)  && (b + k <= W - 2)){
          col[make_pair(a + j, b + k)]++;
        }
      }
    }
  }

  map<ll, ll> cnt;
  
  for(auto itr = col.begin(); itr != col.end(); itr++){
    cnt[(itr->second)]++;
  }

  ll sum = (H - 2) * (W - 2);
  
  rep2(i, 1, 10){
    sum -= cnt[i];
  }

  cout << sum << endl;

  rep2(i, 1, 10){
    cout << cnt[i] << endl;
  }
  
  return 0;
}

Measured memory_bytes: 56448
package main

import "fmt"

const inf int = 1e12

func main() {
	var n, m int
	fmt.Scan(&n, &m)
	as := make([]int, m)
	cs := make([]int, m)
	var a, b, c int
	for i := 0; i < m; i++ {
		fmt.Scan(&a, &b)
		as[i] = a
		for j := 0; j < b; j++ {
			fmt.Scan(&c)
			cs[i] |= 1 << (c - 1)
		}
	}

	dp := make([]int, 1<<n)
	for k := range dp {
		dp[k] = inf
	}
	dp[0] = 0

	for i := 0; i < m; i++ {
		for j := 0; j < 1<<n; j++ {
			dp[j|cs[i]] = min(
				dp[j|cs[i]],
				dp[j]+as[i],
			)
		}
	}

	ans := dp[(1<<n)-1]
	if ans == inf {
		ans = -1
	}
	fmt.Println(ans)
}

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


Measured memory_bytes: 2612
N = int(input())
strs = []
for i in range(N):
    s = list(input())
    s.sort()
    strs.append(''.join(s))

d = dict.fromkeys(strs, 0)
for s in strs:
    if s in d.keys():
        d[s] += 1
    else:
        d.setdefault(s, 1)

ans = 0
for v in d.values():
    ans += (v * (v - 1)) / 2

print(int(ans))

Measured memory_bytes: 19496
class UnionFind():
  def __init__(self, n):
    self.n = n
    self.parents = [-1] * n
    
  def find(self, x):
    if self.parents[x] < 0:
      return x
    else:
      self.parents[x] = self.find(self.parents[x])
      return self.parents[x]
 
  def union(self, x, y):
    x = self.find(x)
    y = self.find(y)
    if x == y:
        return
    if self.parents[x] > self.parents[y]:
        x, y = y, x
 
    self.parents[x] += self.parents[y]
    self.parents[y] = x
 
  def size(self, x):
    return -self.parents[self.find(x)]
 
  def same(self, x, y):
    return self.find(x) == self.find(y)
 
  def members(self, x):
    root = self.find(x)
    return [i for i in range(self.n) if self.find(i) == root]
 
  def roots(self):
    return [i for i, x in enumerate(self.parents) if x < 0]
 
  def group_count(self):
    return len(self.roots())
 
  def all_group_members(self):
    return {r: self.members(r) for r in self.roots()}
 
  def __str__(self):
    return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

n,m=map(int,input().split())
ab=[list(map(int,input().split())) for i in range(m)]

ans=[]
ans.append(n*(n-1)//2)
uf=UnionFind(n)
for a,b in ab[::-1]:
  if not uf.same(a-1,b-1):
    sizea=uf.size(a-1)
    sizeb=uf.size(b-1)
    ans.append(ans[-1]-sizea*sizeb)
  else:
    ans.append(ans[-1])
  uf.union(a-1,b-1)

for i in ans[::-1][1:]:
  print(i)


Measured memory_bytes: 36048
from math import ceil, sqrt

n = 10**5+200
hurui = [i for i in range(n+1)]
for i in range(2,ceil(sqrt(n))+1):
    for j in range(2,ceil(sqrt(i))+1):
        if i==2:
            continue
        if i%j == 0:
            break
    else:
        for k in range(i+i,n,i):
            if hurui[k] != k:
                continue
            hurui[k] = 0
    continue

hurui = [bool(i) for i in hurui]
poi = [False]*(n+1)
for i in range(n+1):
    # print(i)
    poi[i] = (i % 2 == 1 and hurui[i] and hurui[(i+1)//2])
poi[1] = False
#print(poi)
sa = [0]
for i in range(n+1):
    sa.append(sa[i]+poi[i])
#print(sa[:10])

#print(poi[2017])

q = int(input())
lr = [tuple(map(int,input().split())) for i in range(q)]
for li,ri in lr:
    print(sa[ri+1]-sa[li])


Measured memory_bytes: 27180
#include <cassert>
#include <cctype>
#include <cfloat>
#include <climits>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#if __cplusplus >= 201103L
#include <cfenv>
#include <cinttypes>
#include <cstdint>
#endif
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <chrono>
#include <forward_list>
#include <initializer_list>
#include <random>
#include <ratio>
#include <regex>
#include <system_error>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
#if __cplusplus >= 201402L
#include <shared_mutex>
#endif

#define rep(i,n) for(ll i = 0;i < n;++i)
#define all(v) v.begin(),v.end()
using namespace std;
using ll = long long;
typedef pair<int,int> P;

const int INF = 1001001001;
const long double PI = (acos(-1));
const int mod = 1e9+7;
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};

int main(){
    int n;
    cin >> n;
    bool ok = true;
    vector<int> t(n);
    vector<int> a(n);
    if(n % 2 == 0){
        rep(i,n) {
            cin >> a[i];
            t[a[i]]++;
        }
        
        rep(i,n){
            if((i+1) % 2 == 1){
                if(t[i+1] != 2){
                    ok = false;
                }
            }
        }
    }else {
        rep(i,n) {
            cin >> a[i];
            t[a[i]]++;
        }
        
        rep(i,n){
            if((i) % 2 == 0){
                if(i == 0) {
                    if(t[i] != 1) {
                        ok = false;
                    }
                }
                else if(t[i] != 2){
                    ok = false;
                }
            }
        }
    }
    ll ans = 1;
    if(ok){
        rep(i,n/2){
            ans = (ans*2)%mod;
        }
        cout << ans << endl;
    }else{
        cout << 0 << endl;
    }

    return 0;
}


Measured memory_bytes: 3552
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>

const int mod = 2019;

int main(){
	std::string s;
	std::cin >> s;
	std::reverse(s.begin(), s.end());
	
	//1の位から累積和を求めていく
	int total = 0;
	int ten = 1; //10の何乗
	long long ans = 0;
	std::vector<int> cnt(mod);
	for(int i=0; i<s.size(); i++){
		cnt[total]++;
		total += (s[i] - '0') * ten;
		total %= mod ;
		ten = ten * 10 % mod;
		//自分より位が小さい値を見る
		ans += cnt[total];
	}

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

Measured memory_bytes: 3720