akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,s,e) for (int i=s;i<(e);i++)
#define All(v) (v).begin(),(v).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
using namespace std;
typedef long long llint;
typedef pair<int, int> P;
const int MOD = (int)1e9 + 7;
const int INF = 999999999;

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

    int A, B;
    cin >> A >> B;

    vector< vector<char> > G(100, vector<char>(100));
    REP(i, 50)REP(j, 100) G[i][j] = '.';
    REP(i, 50)REP(j, 100) G[i+50][j] = '#';

    for(int ct=B-1; ct>0; ){
        for(int i=0; i<50; i+=2)for(int j=0; j<100; j+=2){
            G[i][j] = '#';
            if(--ct <= 0){
                i = 100;
                break;
            }
        }
    }
    for(int ct=A-1; ct>0; ){
        for(int i=99; i>50; i-=2)for(int j=0; j<100; j+=2){
            G[i][j] = '.';
            if(--ct <= 0){
                i = 0;
                break;
            }
        }
    }

    cout << "100 100\n";
    REP(i, 100){
        REP(j, 100) cout << G[i][j];
        cout << "\n";
    }
    return 0;
}

Measured memory_bytes: 256
s=sorted
(n,m,*b),a,*q=[map(int,t.split())for t in open(0)]
t=[-1]*n
def r(x):
 while-1<t[x]:x=t[x]
 return x
def u(x):
 x,y=map(r,x)
 if x-y:
  if t[x]>t[y]:x,y=y,x
  t[x]+=t[y];t[y]=x
*map(u,q),
i=c=0
k=j=n+~m<<1
*d,=eval('[],'*n)
for v in a:d[r(i)]+=v,;i+=1
for p in d:
 if p:x,*y=s(p);c+=x;b+=y;j-=1
print((c+sum(s(b)[:j]),'Impossible')[k>n]*(k>0))

Measured memory_bytes: 232820
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <tuple>
# include <unordered_map>
# include <numeric>
# include <complex>
# include <bitset>
# include <random>
# include <chrono>
# include <cstdlib>
# include <tuple>
# include <array>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
using D = double;
constexpr int INF = 2147483647;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr double HDINF = 50000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
const double PI = acos(-1);
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
typedef pair<LL, LL> pii;
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define RALL(qpqpq)           (qpqpq).rbegin(),(qpqpq).rend()
# define UNIQUE(wpwpw)        sort(ALL((wpwpw)));(wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define RFOR(i,tptpt,ypypy)  for(LL i=(tptpt);i>=(ypypy);i--)
# define REP(i,upupu)         FOR(i,0,upupu)
# define INIT                 std::ios::sync_with_stdio(false);std::cin.tie(0)

map<char, int> mp;
string s;
int main() {
	cin >> s;
	REP(i, 4)mp[s[i]]++;
	cout << mp['+'] - mp['-'] << endl;
}

Measured memory_bytes: 256
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

R = INT()
if R < 1200:
	print("ABC")
	exit()
elif R < 2800:
	print("ARC")
	exit()
else:
	print("AGC")

Measured memory_bytes: 5200
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  int P, count = 0;
  for(int i = 1; i <= N; i++){
    cin >> P;
    if(P != i) count += 1;
  }
  if(count <= 2) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}

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

int main() {
	int n;
	cin >> n;
	for (int a = 0;a < n;a++) {
		int k, p;
		cin >> k >> p;

		int b = k%p;
		if (b == 0)cout << p << endl;
		else cout << b << endl;
	}
	return 0;
}

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

int main()
{
	ll n,k;
	cin>>n>>k;
	ll h[n+1];
	for(ll i=1;i<=n;i++)
		cin>>h[i];
	ll dp[n+1];
	dp[0]=-1;
	dp[1]=0;
	for(ll i=2;i<=n;i++)
	{
		ll diff=INT_MAX;
		for(ll j=1;j<=k;j++)
		{
			if(i-j>0)
				diff=min(dp[i-j]+abs(h[i]-h[i-j]),diff);
		}
		dp[i]=diff;
	}
	//for(int i=1;i<=n;i++)
	//	cout<<dp[i]<<" ";
	
	cout<<dp[n]<<endl;
	return 0;
}

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

N,A,B,C = map(int, input().split())
l = [int(input()) for _ in range(N)]

def dfs():
    stack = [(0,0,0,0,0)]
    ans = float("inf")

    while stack:
        current, c_a, c_b, c_c, score = stack.pop()

        if current == N:
            if c_a > 0 and c_b > 0 and c_c > 0:
                ans = min(ans, abs(A - c_a) + abs(B - c_b) + abs(C - c_c) + score - 30)
            continue

        stack.append((current+1, c_a, c_b, c_c, score))
        stack.append((current+1, c_a+l[current], c_b, c_c, score+10))
        stack.append((current+1, c_a, c_b+l[current], c_c, score+10))
        stack.append((current+1, c_a, c_b, c_c+l[current], score+10))

    return ans
print(dfs())

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

int main() {
  string o, e;
  cin >> o >> e;
  for(int i=0;i<e.length();i++) {
    cout << o[i] << e[i];
  }
  if(o.length() != e.length()) {
    cout << o[o.length()-1];
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<string>
#include<vector>
#include<numeric>

#include <algorithm>
#include <functional>
using namespace std;


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

 vector<int> vec(num);
 for (int i=0; i<num; i++ ){
   cin >> vec[i];
 }
 int count=0;
 for(int j =1 ; j < num -1 ; j++){
  if((vec[j-1] < vec[j] && vec[j] < vec[j+1] ) || (vec[j-1] > vec[j] && vec[j] > vec[j+1])){
    count++;
  }
 }

 cout << count;

 return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
typedef long long lint;
 
int main() {
  int n;
  string s,t;
  cin >> n >> s >> t;
  
  rep(i,n){
    cout << s[i] << t[i];
  }
  cout << endl;
}


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

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()

typedef long long ll;
typedef pair<int, int> Pii;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;

typedef complex<double> P;
const double EPS = 1e-10;
const double INF = 1e12;

struct L {
    P a, b, v;
    L(){}
    L(P _a, P _b) : a(_a), b(_b), v(b - a) {}
    L(double _ax, double _ay, double _bx, double _by) : L(P(_ax, _ay), P(_bx, _by)) {}
};

double cross(P a, P b) {
    return imag(conj(a) * b);
}

double dot(P a, P b) {
    return real(conj(a) * b);
}

int ccw(P p0, P p1, P p2) {
    if (cross(p1 - p0, p2 - p0) > 0) return +1; // counter-clockwise
    if (cross(p1 - p0, p2 - p0) < 0) return -1; // clockwise
    if (dot(p1 - p0, p2 - p0) < 0) return +2;   // online_back
    if (dot(p0 - p1, p2 - p1) < 0) return -2;   // online_front
    return 0;                                   // on_segment
}

bool intersectSS(L l1, L l2) {
    return (ccw(l1.a, l1.b, l2.a) * ccw(l1.a, l1.b, l2.b) <= 0 &&
            ccw(l2.a, l2.b, l1.a) * ccw(l2.a, l2.b, l1.b) <= 0);
}

double crosspointSS(L l1, L l2) {
    double d1 = abs(cross(l2.v, l1.a - l2.a));
    double d2 = abs(cross(l2.v, l1.b - l2.a));
    double t = d1 / (d1 + d2);
    // return l1.a + t * l1.v;
    return t;
}

L readL() {
    double xa, ya, xb, yb;
    cin >> xa >> ya >> xb >> yb;
    return L(xa, ya, xb, yb);
}

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

    int T;
    cin >> T;
    rep(_, T) {
        L blue = readL();
        int n;
        cin >> n;
        vector<L> lines(n);
        V layer(n);
        rep(i, n) {
            lines[i] = readL();
            int o, l;
            cin >> o >> l;
            layer[i] = l;
            if (o == 0) layer[i] ^= 1;
        }

        // rep(i, n) {
        //     cout << layer[i] << " ";
        // }
        // cout << endl;

        vector<pair<double, int>> v; // ?????????????????????????????????????????????????????????t??¨?????????????????????
        rep(i, n) {
            if (!intersectSS(blue, lines[i])) continue;
            v.emplace_back(make_pair(crosspointSS(blue, lines[i]), i));
            // printf("%.5f %d\n", v.back().first, v.back().second);
        }

        sort(all(v));

        int ans = 0;
        rep(i, (int)v.size() - 1) {
            if (layer[v[i].second] != layer[v[i + 1].second]) {
                ans++;
            }
        }

        cout << ans << endl;

    }
}

Measured memory_bytes: 3188
#include <stdio.h>
 
int main(){
    int H, W;
    scanf("%d %d", &H, &W);
    while (H != 0 && W != 0){
        int i, j;
        for(i = 0;i < H;i++){
            for (j = 0;j < W; j++){
                printf("#");
            }
            printf("\n");
        }
        printf("\n");
        scanf("%d %d", &H, &W);
    }

}

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

int main(){
    int N,B,count;
    cin>>N;
    count=0;
    vector<int>A(N);
    for(int i=0;i<N;i++){
        cin>>A[i];
    }
    for(int i=0;i<N;i++){
        int J;
        J=i;
        for(int j=i;j<N;j++){
            if(A[j]<A[J]){
                J=j;
            }
        }
        if(i!=J){
            B=A[i];
            A[i]=A[J];
            A[J]=B;
            count++;
        }
    }
    for(int i=0;i<N;i++){
        if(i==N-1){
            cout<<A[i]<<endl;
        }
        else{
            cout<<A[i]<<" ";
        }
    }
    cout<<count<<endl;
}



Measured memory_bytes: 3096
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <queue>
#include <stack>

using namespace std;

typedef int itn;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef map<int, int> M;
typedef pair<int, int> P;
typedef stack<int> S;
typedef queue<int> Q;

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

    int a, b, c, d;
    cin >> a  >> b >> c >> d;

    int dx = c - a;
    int dy = d - b;

    cout << c - dy << " " << d + dx << " " << a - dy  << " " << b + dx << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#define rep(i,a,b) for(int i=a;i<b;i++)
using namespace std;
int main(){
	int d[60],x;
	rep(i,0,60)d[i]=9999;
	rep(i,0,30)d[i*2]=380*i-380*(i/5);
	rep(i,0,55){
		rep(j,0,(55-i)/3){
			d[j*3+i]=min(d[j*3+i],d[i]+j*550-330*(j/4));
		}
	}
	rep(i,0,55){
		rep(j,0,(55-i)/5){
			d[j*5+i]=min(d[j*5+i],d[i]+j*850-306*(j/3));
		}
	}
	while(cin>>x&&x){
		cout<<d[x/100]<<endl;
	}
	return 0;
}

Measured memory_bytes: 2980
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int D;
int s[367][27];
int c[27];
int last[27];

int main()
{
    cin >> D;
    for (int i = 1; i <= 26; i++)
    {
        cin >> c[i];
    }
    for (int i = 1; i <= D; i++)
    {
        for (int j = 1; j <= 26; j++)
        {
            cin >> s[i][j];
            last[j] = 0;
        }
    }
    int t[367];
    int score, maxi;
    int best_i;

    for (int day = 1; day <= D; day++)
    {
        maxi = -100000;
        best_i = -1;
        for (int item = 1; item <= 26; item++)
        {
            score = s[day][item];
            for (int k = 1; k <= 26; k++)
            {
                score -= c[k] * (day - (k == item ? day : last[k]));
            }
            if (score > maxi)
            {
                maxi = score;
                best_i = item;
            }
        }
        t[day] = best_i;
        last[best_i] = day;
    }

    for (int i = 1; i <= D; i++)
    {
        cout << t[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <utility>
using namespace std;

int d[110][110] = {};
int n, m, inf = 1e9 + 7, a[1010], b[1010], c[1010], ans;
bool used[1010];

void warshall_floyd(int n)
{
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n; j++)
        {
            for (int k = 0; k < n; k++)
            {
                d[j][k] = min(d[j][k], d[j][i] + d[i][k]);
            }
        }
    }
}

int main()
{
    cin >> n >> m;
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n; j++)
        {
            d[i][j] = (i == j ? 0 : inf);
        }
    }
    for (int i = 0; i < m; i++)
    {
        cin >> a[i] >> b[i] >> c[i];
        a[i]--, b[i]--;
        d[a[i]][b[i]] = c[i];
        d[b[i]][a[i]] = c[i];
    }
    warshall_floyd(n);
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n; j++)
        {
            if (i == j)
                continue;
            for (int k = 0; k < m; k++)
            {
                used[k] = used[k] || d[i][a[k]] + c[k] + d[b[k]][j] == d[i][j] || d[i][b[k]] + c[k] + d[a[k]][j] == d[i][j];
            }
        }
    }
    for (int i = 0; i < m; i++)
        ans += !used[i];
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	string s;
	cin>>s;
	int i;
	for(i=0;i<s.size();i++){
	if((i+1)%2==0 && s[i]=='R'){
		cout<<"No";
		return 0;
	}
	if((i+1)%2!=0 && s[i]=='L'){
		cout<<"No";
		return 0;
	}
	}
	cout<<"Yes";
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
/* clang-format on */

vector<ll> sumup(const vector<ll>& v) {
  vector<ll> sum(v.size() + 1, 0);
  for (int i = 0; i < v.size(); i++) sum[i + 1] = sum[i] + v[i];
  return sum;
}

int main() {
  int N, K;
  while (cin >> N >> K) {
    vec<ll, 2> g(N);
    for (int i = 0; i < N; i++) {
      ll t, d;
      cin >> t >> d;
      --t;
      g[t].push_back(d);
    }
    vector<ll> top, rest;
    for (int t = 0; t < N; t++) {
      if (g[t].empty()) continue;
      sort(g[t].rbegin(), g[t].rend());
      top.push_back(g[t][0]);
      rest.insert(rest.end(), g[t].begin() + 1, g[t].end());
    }
    sort(top.rbegin(), top.rend());
    sort(rest.rbegin(), rest.rend());
    auto topsum = sumup(top);
    auto restsum = sumup(rest);
    ll res = 0;
    for (int x = 1; x <= top.size(); x++) {
      int y = K - x;
      if (y >= 0 && y <= rest.size()) {
        ll score = (ll)x * x + topsum[x] + restsum[y];
        res = max(res, score);
      }
    }
    cout << res << endl;
  }
  return 0;
}


Measured memory_bytes: 7412
#include<iostream>
#include<algorithm>

using namespace std;

int main()
{
	char tar[11];
	char ringc[100][21];
	int ringi;
	int result = 0;

	cin >> tar;
	cin >> ringi;

	for(int a = 0;a < ringi;a++)
	{
		cin >> ringc[a];
	}
	for(int a = 0;a<ringi;a++)
	{
		for(int b = 0;b<10;b++)
		{
			ringc[a][b+10] = ringc[a][b];
		}
		ringc[a][20] = 0;
	}

	for(int a = 0;a<ringi;a++)
	{
		for(int b = 0;b<21;b++)
		{
			if(ringc[a][b] == tar[0])
			{
				for(int c = 1;;c++)
				{
					if(tar[c] == 0)
					{
						result++;
						goto x;
					}
					else if(ringc[a][b+c] != tar[c])
					{
						goto y;
					}
				}
			}
			y:;
		}
		x:;
	}

	cout << result << endl;

	return 0;
}

Measured memory_bytes: 1168
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}void pr(){ln;}
template<Z A,Z...B>void pr(const A &a,const B&...b){cout<<a<<(sizeof...(b)?" ":"");pr(b...);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[8]={-1,0,1,0,-1,-1,1,1},dy[8]={0,1,0,-1,-1,1,1,-1};
typedef pair<ll,ll> P;

void Main() {
  ll a,b;
  cin >> a >> b;
  pr(a*b);
}

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


Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
int const nax = 3e5 + 10;
#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif // LOCAL
using ll = long long ;
int n, a[nax];


int main(){
    scanf("%d", &n);
    for(int i = 1 ; i <= n; i ++){
        scanf("%d", a + i);
    }
    int tar = 1;
    for(int i = 1;i <= n; i ++){
        if(a[i] == tar){
            tar ++;
        }
    }
    if(tar == 1) return !printf("-1");
    printf("%d\n", n - tar + 1);
}
/*
    Good Luck
        -Lucina
*/


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repp(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define repm(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define INF (1ll<<60)
typedef long long lint;
const lint MOD =1000000007;
const lint MAX = 10000000;

 
lint fac[MAX], finv[MAX], inv[MAX];

void COMinit() // 二項係数を求める時は前処理としてCOMinit()をする
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (lint i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
// 二項係数計算
long long COM(lint n, lint k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

lint primary(lint num)
{
    if (num < 2) return 0;
    else if (num == 2) return 1;
    else if (num % 2 == 0) return 0; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return 0;
        }
    }

    // 素数である
    return 1;
}

   

int main(){
   lint N;
   cin>>N;
   vector<lint> x;
   rep(i,N){
   lint G;
   cin>>G;
   x.push_back(G);}
   lint ans=0,count=0;
   rep(j,61){
       count=0;
   rep(i,N){
           if(x[i]&1ll<<j)count++;
   }
           lint o=count*(N-count);
           o%=MOD;
           rep(k,j){
               o*=2;
            o%=MOD;
           }
           ans+=o;
           ans%=MOD;  
   
   }
   cout<<ans;
}

Measured memory_bytes: 6128
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <limits>
#include <string>
#include <bitset>
#include <functional>

using namespace std;
using lint = long long;
using vi = vector<int>;
using vl = vector<int>;
using pii = pair<int, int>;
using pll = pair<lint, lint>;
using pqi = priority_queue<int>;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n); i > 0; i--)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define mp(x, y) make_pair((x), (y))
#define all(x) (x).begin(), (x).end()
#define foreach(it, x) for (auto it = (x).begin(); it != (x).end(); it++)
#define space (char)0x20

constexpr lint MOD = 1e9 + 7;
int A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z;
// int ans;
// string ans;

struct Edge {
    int to;
    int cost;
};

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

	cin >> V >> E >> R;
    vector<vector<Edge>> edge(V);
    rep(i, E) {
        int s, t, d;
        cin >> s >> t >> d;
        edge[s].push_back({ t, d });
    }

    priority_queue<pii, vector<pii>, greater<pii>> pq;

    vi w(V, INT32_MAX);
    w[R] = 0;
    pq.push({ 0, R });
    while (!pq.empty()) {
        auto c = pq.top(); pq.pop();
        if (w[c.second] < c.first) {
            continue;
        }
        for (auto i : edge[c.second]) {
            if (w[i.to] > w[c.second] + i.cost) {
                w[i.to] = w[c.second] + i.cost;
                pq.push({ w[i.to], i.to});
            }
        }
    }

    foreach(it, w) {
        if (*it != INT32_MAX) cout << *it << endl;
        else cout << "INF" << endl;
    }

	return 0;
}


Measured memory_bytes: 13040
#include <iostream>
#include <list>
#include <string>
#include <algorithm>
using namespace std;
int main(void){
    int q, x;
    string com;
    list<int> v;
    cin >> q;
    for(int i=0; i<q; i++){
        cin >> com;
        if(com == "insert"){
            cin >> x;
            v.push_front(x);
        }
        else if(com == "deleteLast"){
            v.pop_back();
        }
        else if(com == "deleteFirst"){
            v.pop_front();
        }
        else if(com == "delete"){
            cin >> x;
            for(list<int>::iterator it=v.begin(); it!=v.end();it++){//iteratorポインタ
                if(*it == x){//ポインタ要素を書き出す
                    v.erase(it);
                    break;
                }
            }
        }
    }
    int i =0;
    for(list<int>::iterator it=v.begin(); it!=v.end(); it++){
        if(i++) cout << " ";
        cout << *it;
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 34340
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    x, y, z = LI()
    print(z, x, y)

main()



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

using namespace std;

int main() {
    int n, m;
    while (1) {
        cin >> n >> m;
        if (n == 0 && m == 0) break;
        vector<int> p(n);
        for (int i=0; i<n; ++i) {
            cin >> p[i];
        }
        sort(p.begin(), p.end(), greater<int>());

        int sum = 0, minus = 0;
        for (int i=0; i<(int)p.size(); ++i) {
            sum += p[i];
            if ((i + 1) % m == 0) minus += p[i];
        }
        cout << sum - minus << endl;
    }
    return 0;
}

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

#define For(i,a,b) for(int (i) = (a);(i) < (b);i++)
#define Rep(i,n) For((i),0,(n))
#define All(a) (a).begin(),(a).end()
#define sp " "
#define INF 1e18
#define INT_INF 1e9
#define MAX 1000

typedef long long ll;
char maps[3000][3000];
int sum_o[3010][3010];
int sum_k[3010][3010];

int main(){
    int N;
    cin >> N;
    int p[N];
    int ans = 0;
    Rep(i,N){
        cin >> p[i];
    }
    for(int i = 1;i < N-1;i++){
        if(p[i-1] < p[i] && p[i] < p[i+1])ans++;
        else if(p[i+1] < p[i] && p[i] < p[i-1])ans++;
    }
    cout << ans << endl;
    //cin >> N;
}

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

int comp(const void* a, const void* b){
	return *(int*)a - *(int*)b;
}

int main() {
	int a, b;
	cin >> a >> b;
	if(a == 1){
		a = 14;
	}
	if(b == 1){
		b = 14;
	}
	if(a > b){
		cout << "Alice" << endl;
	}else if(a == b){
		cout << "Draw" << endl;
	}else{
		cout << "Bob" << endl;
	}
}

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


def main():
    n = int(input())
    s = input()
    ts = list()

    # KeyInsight
    # 制約条件の小さいものに着目する
    # 部分列では貪欲的に探索することを検討する
    for i in range(10):
        for j in range(10):
            for k in range(10):
                t = ''
                t += str(i)
                t += str(j)
                t += str(k)

                ts.append(t)

    ans = 0

    for ti in ts:
        pos = 0

        for si in s:
            if si == ti[pos]:
                pos += 1

                if pos == 3:
                    break

        if pos == 3:
            ans += 1

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
def answer(s: str, t: str) -> str:
    for _ in range(len(s)):
        if t == s:
            return 'Yes'
        s = s[-1] + s[:-1]
    return 'No'


def main():
    s = input()
    t = input()
    print(answer(s, t))


if __name__ == '__main__':
    main()


Measured memory_bytes: 8976
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }
#define dump(x) cerr<<#x<<": "<<x<<endl;
#define bit(k) (1LL<<(k))
typedef long long ll;
typedef pair<int, int> i_i;
typedef pair<ll, ll> l_l;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 >& p) {
  os << "{" <<p.first << ", " << p.second << "}";
  return os;
}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

const int INF = (ll)1e9;
const ll INFLL = (ll)1e18+1;
const ll MOD = (ll)1e9+7;
const double PI = acos(-1.0);
/*
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const string dir = "DRUL";
*/

template<typename T, typename U> 
T modpow(T a, U n) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % MOD;
        a = a * a % 2019;
        n >>= 1;
    }
    return res;
}
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    string S;
    cin >> S;
    int N = S.size();
    reverse(all(S));
    map<int, ll> mp;
    ll tmp = 0;
    ll ans = 0;
    vector<int> modpows(N);
    modpows[0] = 1;
    rep1(i,N){
        modpows[i] = (10*modpows[i-1])%2019;
    }
    rep(i,N){
        tmp += (modpows[i]*(S[i]-'0'))%(2019);
        tmp %= 2019;
        if(i >= 3)ans += mp[tmp];
        if(tmp == 0)ans++;
        mp[tmp]++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 4368
#include <stdio.h>

int main(void)
{
  int i;
  int n, a;
  long long min, max, sum;

  scanf("%d", &n);
  scanf("%d", &a);
  max = sum = min = a;
  
  for (i = 1; i < n; i++){
    scanf("%d", &a);
    if (max < a){
      max = a;
    }
    if (min > a){
      min = a;
    }
    sum += a;
    }
    
  printf("%ld %ld %ld\n", min, max, sum);
  
  return (0);
}



Measured memory_bytes: 2100
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1e9;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};
#define PI 3.14159265358979323846264338327950L
#define MOD 1000000007
//setprecision(15)
int main() {
	ll A, B, K; cin >> A >> B >> K;
	if (A >= K) {
		cout << A - K << " " << B << endl;
	} else {
		if (B >= K - A) {
			cout << 0 << " " << B - K + A << endl;
		} else {
			cout << 0 << " " << 0 << endl;
		}
	}
}

Measured memory_bytes: 3580
#include <iostream>
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <sstream>
#include <string>
#include <utility>
#include <map>
#include <memory>
#include <set>
#include <vector>
#include <deque>
#include <list>
#include <stack>
#include <queue>

using namespace std;

class Dictionary
{
public:
  list<string> dic[390625];
  int solve();
  int hash( string s );
  int ctov( char c );
};

int Dictionary::solve()
{
  int n;
  cin >> n;

  string cmd, dat;
  
  for ( int i = 0; i < n; i++ )
    {
      cin >> cmd >> dat;

      if ( cmd == "insert" )
        {
          dic[hash( dat )].push_back( dat );
        }
      else if ( cmd == "find" )
        {
          list<string> t = dic[hash( dat )];
          list<string>::iterator it;
          
          for ( it = t.begin(); it != t.end(); it++ )
            {
              if ( *it == dat )
                {
                  cout << "yes" << endl;
                  break;
                }
            }
          if ( it == t.end() )
            cout << "no" << endl;
        }
    }  
  
  return 0;
}

int Dictionary::hash( string s )
{
  if ( s.size() == 1 )
    return ctov( s[0] );
  else if ( s.size() == 2 )
    return ctov( s[0] ) + ctov( s[1] ) * 5;
  else if ( s.size() == 3 )
    return ctov( s[0] ) + ctov( s[1] ) * 5 + ctov( s[2] ) * 25;
  else if ( s.size() == 4 )
    return ctov( s[0] ) + ctov( s[1] ) * 5 + ctov( s[2] ) * 25 + ctov( s[3] ) * 125;
  else if ( s.size() == 5 )
    return ctov( s[0] ) + ctov( s[1] ) * 5 + ctov( s[2] ) * 25 + ctov( s[3] ) * 125 + ctov( s[4] ) * 625;
  else if ( s.size() == 6 )
    return ctov( s[0] ) + ctov( s[1] ) * 5 + ctov( s[2] ) * 25 + ctov( s[3] ) * 125 + ctov( s[4] ) * 625 + ctov( s[5] ) * 3125;
  else if ( s.size() == 7 )
    return ctov( s[0] ) + ctov( s[1] ) * 5 + ctov( s[2] ) * 25 + ctov( s[3] ) * 125 + ctov( s[4] ) * 625 + ctov( s[5] ) * 3125 + ctov( s[6] ) * 15625;
  else
    return ctov( s[0] ) + ctov( s[1] ) * 5 + ctov( s[2] ) * 25 + ctov( s[3] ) * 125 + ctov( s[4] ) * 625 + ctov( s[5] ) * 3125 + ctov( s[6] ) * 15625 + ctov( s[7] ) * 78125;
}

int Dictionary::ctov( char c )
{
  if ( c == 'A' )
    return 1;
  else if ( c == 'C' )
    return 2;
  else if ( c == 'G' )
    return 3;
  else if ( c == 'T' )
    return 4;
  else
    return 0;
}

int main( void )
{

  Dictionary *d = new Dictionary();
  d->solve();
  return 0;
}

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

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef unordered_set<int> si;
typedef pair<int, int> pp;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#define all(e) (e).begin(), (e).end()


template <typename T>
void printV(vector<T> A) {
    if (A.empty()) cerr << "EMTPY\n";
    else { 
        cerr << "[";
        for (int i = 0; i < A.size() -1 ; ++i) {
            cerr << A[i] << ", ";
        }
        if (A.size()) cerr << A.back() << "]\n";
    }
}


template <typename T>
void printVV(vector<vector<T>> A) {
    cerr << "[";
    for (auto v : A) {
        printV<T>(v);
    }
    cerr << "]";
}

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

int main(int argc, char **argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int s, w; cin >> s >> w;
    if (w >= s) cout << "unsafe\n";
    else cout << "safe\n";
    return 0;
}



Measured memory_bytes: 3636
#import <stdio.h>

int main(int argc, const char * argv[]) {
        int a;
        scanf("%d", &a);
        int c=0;
        for(int i=1;i<=a;i+=2){
            int d=0;
            for(int j=1;j<=i;j++){
                if(i%j==0) d++;
            }
            if(d==8) c++;
        }
        printf("%d\n",c);
    return 0;
}


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

int N, D, X;
int A[100];

int main() {
    cin >> N >> D >> X;
    rep(i, N) cin >> A[i];

    int ans = 0;
    for (int i = 0; i < N; i++) {
        ans += 1 + (D - 1) / A[i];
    }

    cout << ans + X << endl;
}

Measured memory_bytes: 256
import sys
readline = sys.stdin.readline
class Tree:
    __slots__ = ['id', 'p', 'sibling', 'degree', 'depth', 'height', 'type', 'c']
    def __init__(self, id):
        self.id = id
        self.p = -1
        self.sibling = -1
        self.degree = 0
        self.depth = 0
        self.height = 0
        self.type = "leaf"
        self.c = []
    def __str__(self):
        return f"node {self.id}: parent = {self.p}, sibling = {self.sibling}, degree = {self.degree}, depth = {self.depth}, height = {self.height}, {self.type}"
n = int(input())
tree = tuple(Tree(i) for i in range(n))
for _ in range(n):
    id, *c = map(int, readline().replace("-1", "").split())
    if c != []:
        tree[id].type = "internal node"
        tree[id].c = c
        for j in c:
            tree[j].p = id
        len_c = len(c)
        tree[id].degree = len_c
        if len_c == 2:
            tree[c[0]].sibling = c[1]
            tree[c[1]].sibling = c[0]
root = 0
while tree[root].p != -1:
    root = tree[root].p
tree[root].type = "root"
def depth_height_check(id, d):
    d += 1
    height = 0
    for i in tree[id].c:
        tree[i].depth = d
        if tree[i].type != "leaf":
            tree[i].height = depth_height_check(i, d) + 1
            height = max(height, tree[i].height)
    return height
tree[root].height = depth_height_check(root, 0) + 1 if n > 1 else 0
print("\n".join(map(str, tree)))



Measured memory_bytes: 5632
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int m;
	cin>>m;
	int ans=m+n;
	if(ans%2==0)
	{
		cout<<ans/2<<endl;
	} else
	{
		cout<<"IMPOSSIBLE"<<endl;
	}
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const long long INF = 1LL << 60;
const ll MOD = 1000000007;
using pint = pair<ll, ll>;

int main(){
    ll N;
    cin >> N;
    vector<ll> sum(110000, 0);
    for (int i = 0; i < N; i++){
      ll tmp = 0;
      cin >> tmp;
      sum[tmp]++;
      sum[tmp + 1]++;
      sum[tmp + 2]++;
    }
    ll out = 0;
    for (int i = 0; i < 110000; i++){
      out = max(out, sum[i]);
    }
    cout << out << endl;
    return 0;
}

Measured memory_bytes: 3996
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; (i) < (n); ++ (i))
#define loop(i,a,n) for (int i = (a); (i) < (n); ++ (i))
#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF (int)1e9
#define MOD 0
//#define int ll
using namespace std;
typedef vector<int> vi;

signed main(){
    int n,q,c = 0,l,r;
    string s;
    char a = 'G',b;
    vector<int> ac(100010,0);
    cin >> n >> q >> s;
    rep(i,n) {
        b = s[i];
        if(b == 'C' && a == 'A') {
            c++;
        }
        a = b;
        ac[i] = c;
    }
    rep(i,q) {
        cin >> l >> r;
        cout << ac[r-1] - ac[l-1] << endl;
    }
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;


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

  rep(i,s.size()){
    if(s[i] == '1') cout << "9";
    else cout << "1";
  }
  cout << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll (i) = 0; (i) < (n); (i)++)
#define rep1(i, n) for(ll (i) = 1; (i) <= (n); (i)++)
#define rrep(i, n) for(ll (i) = (n) - 1; (i) >= 0; (i)--)
#define rrep1(i, n) for(ll (i) = (n); (i) >= 1; (i)--)
const ll INF = 1145141919;
const ll MOD = 1000000007;
template<class T> void chmax(T &a, const T &b){if(a < b){a = b;}}
template<class T> void chmin(T &a, const T &b){if(a > b){a = b;}}

int main(){

    ll a, b;
    cin >> a >> b;
    cout << (a + b) % 24 << endl;

    return 0;
}

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

#define rep(i, s, n) for(int i = s; i < n; ++i)
#define rrep(i, n) for(int i = n - 1; i > -1; --i)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using namespace std;
const long long INF = 10000000;
const int MOD = 1000000007;
typedef long long ll;
typedef pair<int, int> P;

vector<int> v(INF, 0);
vector<vector<int>> c(INF);

void dfs(int vv = 0, int pre = 0){
    if(vv != 0) v[vv] += v[pre];
    rep(i, 0, c[vv].size()){
        if(c[vv][i] != pre) dfs(c[vv][i], vv);
    }
}

int main() {
    int n, q;
    cin >> n >> q;
    int a, b;
    rep(i, 0, n - 1){
        cin >> a >> b;
        a--;
        b--;
        c[a].push_back(b);
        c[b].push_back(a);
    }
    int p, x;
    rep(i, 0, q){
        cin >> p >> x;
        p--;
        v[p] += x;
    }
    dfs();

    rep(i, 0, n - 1){
        cout << v[i] << " ";
    }
    cout << v[n - 1] << endl;
}


Measured memory_bytes: 291456
s=list(input())
total=0
mask=0
n=len(s)
while mask<(1<<(n-1)):
    i=0
    s_i=s[:]
    while i<n-1:
        if mask&(1<<i):
            s_i[i]=s_i[i]+"+"
        i+=1
    total+=eval("".join(s_i))
    mask+=1
print(total)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    int p[200100];
    cin >> n;
    for(int i = 0; i < n; i++)
        cin >> p[i];
    int count = 0;
    int minimum = 1001001001;
    for(int i = 0; i < n; i++)
    {
        minimum= min(minimum, p[i]);
        if(minimum == p[i])
            count++;
    }
    cout << count << endl;
}


Measured memory_bytes: 4388
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)n; i++)
#define all(x) (x).begin(),(x).end()
typedef long long int ll;
using namespace std;
int main()
{
  int x, y, z;
  cin >> x >> y >> z;
  cout << (x - z)/(y + z) << endl;

}


Measured memory_bytes: 256
# 過去に解いてたけど解き直し
# 適当に後ろから全探索して余った?はaで埋める
s, t = input(), input()
for i in range(len(s) - len(t), -1, -1):
    tt = s[i : i + len(t)]
    flag = True
    for j in range(len(t)):
        if tt[j] == t[j] or tt[j] == "?":
            continue
        else:
            flag = False
    if flag:
        ans = list(s[:i] + t + s[i + len(t) :])
        for k in range(len(s)):
            if ans[k] == "?":
                ans[k] = "a"
        print("".join(ans))
        exit()
print("UNRESTORABLE")


Measured memory_bytes: 3064
#include<iostream>
#include<string.h>
using namespace std;
int main()
{
	int a,b;
	char c[1000],d[1000],h[1000];
	cin>>c>>d>>a>>b>>h;
	if(strcmp(c,h)==0)
	a--;
	if(strcmp(d,h)==0)
	b--;
	cout<<a<<" "<<b;
} 

Measured memory_bytes: 256
/*
读题不规范，爆零两行泪。
数据不清空，爆零两行泪。
多测不读完，爆零两行泪。
边界不特判，爆零两行泪。
贪心不证明，爆零两行泪。
D P 顺序错，爆零两行泪。
大小少等号，爆零两行泪。
变量不统一，爆零两行泪。
越界不判断，爆零两行泪。
调试不注释，爆零两行泪。
溢出不 l l，爆零两行泪。
*/
#pragma GCC optimize(3)
#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define X first
#define Y second
const int N=500;
int n;
bool hav[N+1][N+1];
int ans[N+1][N+1];
pair<int,int> q[N*N+1];
int head,tail;
const int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int main(){
	cin>>n;
	int anss=0;
	for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)ans[i][j]=min(min(i,n-i+1),min(j,n-j+1)),hav[i][j]=true;
//	for(int j=1;j<=n;j++){for(int k=1;k<=n;k++)cout<<ans[j][k]<<" ";puts("");}
//	puts("------------------------------------------------------");
	for(int i=1;i<=n*n;i++){
		int ord;
		cin>>ord;
		int x=(ord+n-1)/n,y=(ord-1)%n+1;
		ans[x][y]--;hav[x][y]=false;
		anss+=ans[x][y];
		head=tail=0;
		q[tail++]=mp(x,y);
		while(head<tail){
			int xx=q[head].X,yy=q[head].Y;
			head++;
			for(int j=0;j<4;j++){
				int xxx=xx+dx[j],yyy=yy+dy[j];
				if(1<=xxx&&xxx<=n&&1<=yyy&&yyy<=n&&ans[xx][yy]+hav[xxx][yyy]<ans[xxx][yyy])
					ans[xxx][yyy]=ans[xx][yy]+hav[xxx][yyy],q[tail++]=mp(xxx,yyy);
			}
		}
//		for(int j=1;j<=n;j++){for(int k=1;k<=n;k++)cout<<ans[j][k]<<" ";puts("");}
//		puts("------------------------------------------------------");
	}
	cout<<anss;
	return 0;
}

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

const int N = 1e5 + 10, M = 3e3;

typedef long long ll;

int pri[N], pcnt, n, realans;
bool mark[N];
map<ll, int> mp;
map<pair<ll, ll>, int> val;

void prework(void) {
  for(int i = 2; i < M; i++) {
    if(!mark[i]) {
      pri[++pcnt] = i;
    }
    for(int j = 1; j <= pcnt && i * pri[j] < M; j++) {
      mark[i * pri[j]] = true;
      if(i % pri[j] == 0) {
	break;
      }
    }
  }
}

void defact(ll x, int y) {
  ll ax = 1, ay = 1;
  for(int i = 1; i <= pcnt && pri[i] <= x; i++) {
    if(x % pri[i] == 0) {
      int cnt = 0;
      while(x % pri[i] == 0) {
	x /= pri[i];
	cnt++;
      }
      if(cnt % 3 == 1) {
	ax = ax * pri[i];
      } else if(cnt % 3 == 2) {
	ay = ay * pri[i];
      }
    }
  }
  ll lim = sqrt(x);
  if(lim * lim == x) {
    ay = ay * lim;
  } else {
    ax = ax * x;
  }
  val[{ax, ay}] += y;
  if(val.find({ay, ax}) == val.end()) {
    val[{ay, ax}] = 0;
  }
}

int main(void) {
  scanf("%d", &n);
  prework();
  for(int i = 1; i <= n; i++) {
    ll x;
    scanf("%lld", &x);
    mp[x]++;
  }
  for(auto it : mp) {
    defact(it.first, it.second);
  }
  for(auto it : val) {
    pair<ll, ll> p = it.first;
    if(p.first == p.second) {
      realans += !mark[1];
      mark[1] = true;
    }
    if(p.first > p.second) {
      realans += max(it.second, val[{p.second, p.first}]);
    }
  }
  cout << realans << endl;
  return 0;
}


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

int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> vs(m);
  for (int i = 0; i < m; i++) {
    cin >> vs[i].first >> vs[i].second;
    vs[i].first--;
    vs[i].second--;
  }
  
  sort(vs.begin(), vs.end(), [](auto &p, auto &q) {
    return (p.second == q.second) ? (p.first < q.first) : (p.second < q.second);
  });
  
  int ans = 0, lst = -1;
  
  for (int i = 0; i < m; i++) {
    if (vs[i].first <= lst && lst < vs[i].second) {
      continue;
    }
    ans++;
    lst = vs[i].second - 1;
  }
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 1024
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        // 整数の入力
        int a = sc.nextInt();
        int b = sc.nextInt();
        int r=(2*a-1)>(2*b-1)?(2*a-1):(2*b-1);
        r=r>(a+b-1)?r:(a+b);
        // 出力
        System.out.println(r);
    }
}

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

using namespace std;

int N, M;
char sir[509][509];
bool A[509][509], B[509][509];

int main ()
{
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);

scanf ("%d %d\n", &N, &M);
for (int i=1; i<=N; i++)
    scanf ("%s", sir[i] + 1);
for (int j=1; j<=M; j++)
    A[1][j] = 1;
for (int j=1; j<=M; j++)
    B[N][j] = 1;
for (int i=1; i<=N; i++)
    for (int j=1; j<=M; j++)
    {
        if (j & 1) A[i][j] = (i < N);
        else B[i][j] = (i > 1);
        if (sir[i][j] == '#') A[i][j] = B[i][j] = 1;
    }
for (int i=1; i<=N; i++, printf ("\n"))
    for (int j=1; j<=M; j++)
        if (A[i][j]) printf ("#");
        else printf (".");
printf ("\n");
for (int i=1; i<=N; i++, printf ("\n"))
    for (int j=1; j<=M; j++)
        if (B[i][j]) printf ("#");
        else printf (".");
return 0;
}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define SIZE 200005
#define INF 1000000005LL
#define MOD 1000000007
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;
vector<int> x = {1,-1,0,0};
vector<int> y = {0,0,-1,1};
int main(){
    ll n,a,b;
    cin >> n >> a >> b;
    if(n==1){
        if(a==b){
            cout<<1<<endl;
            return 0;
        }else{
            cout<<0<<endl;
            return 0;
        }
    }
    if(a>b){
        cout<<0<<endl;
        return 0;
    }
    cout<<b*(n-1)+a-(a*(n-1)+b)+1<<endl;
  return 0;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
int main(){
int A,B,C,D,E,X,Y;
cin>>A>>B>>C>>D>>E;
if(A<0){
    X=-1*A*C;
    Y=B*E;
    cout<<X+Y+D<<endl;
}
else if(A>0){
    cout<<(B-A)*E<<endl;
}
}


Measured memory_bytes: 3092
#include <iostream>
#include <vector>

using namespace std;
using int64 = long long;

const vector<int> dx = {-1, +0, +1, -1, +0, +1, -1, +0, +1};
const vector<int> dy = {+1, +1, +1, +0, +0, +0, -1, -1, -1};

int main() {
    int64 n, m;
    cin >> n >> m;

    int64 ans = (n-2) * (m-2);
    if (n == 1 || m == 1) ans = max(0LL, n*m - 2);
    if (n == 1 && m == 1) ans = 1;

    cout << ans << endl;
}


Measured memory_bytes: 384
/*01 02 03 12 13 23　と６回見ていくパターン 
for(int i=0;i<n-1;i++){
  for(int j=i+1;j<n;j++){
    }
  }
*/
//vector<vector<int>> data(3, vector<int>(4));//int型の2次元配列(3×4要素の)の宣言
//int64_t a;
//10のi乗pow(10, i);
/*string s; stringでの文字列を数字型に変える方法
  cin >> s;
  rep(i,s.size()-2) {
  int a= (s.at(i)-'0')*100 + (s.at(i+1)-'0')*10+ s.at(i+2) -'0';
    */
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
  string s;
  cin >> s;
  int sum=0;
  rep(i,s.size()) sum+= s.at(i)-'0';
  int k=1;
  int num=0;
  for(int i=s.size()-1;i>=0;i--){
    num += (s.at(i) -'0') * k;
    k = k*10;
  }   
//  cout << num <<endl;
//  cout << sum <<endl;
  if(num%sum==0)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
} 


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

using namespace std;
using ll = long long int;
const int MOD = 1e9 + 7;

int main()
{
	ios::sync_with_stdio(0); cin.tie(0);
	ll n, a, b;cin >> n >> a >> b;
	ll bet = b-a-1;
	if (bet%2 == 1) cout << (bet+1)/2;
	else
	{
		ll x = 1, y = b-a;
		bet = y-x-1;
		ll ans = a + (bet+1)/2;
		x = n-b+1, y = n-a+1;
		a = 1, b = y-x;
		bet = b-a-1;
		ans = min(ans, x + (bet+1)/2);
		cout << ans;
	}
}

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

/*
問題文N × Nのマス目があります。
このマス目の各マスを白色または黒色に塗ることにしました (すべてのマスをどちらか片方の色に塗ります)。
ちょうど Aマスを白色に塗るとき、黒色に塗ることになるマスはいくつあるでしょうか。

制約
1≦N≦100
0≦A≦N^2
*/
int main(){
  int n = 0;
  int a = 0;
  double cells = 0.0;
  scanf("%d", &n);
  scanf("%d", &a);
  cells = pow(n, 2.0);
  if(n < 0 || 100 < n || a < 0 || cells < (double)a){
    return 1;
  }
  cout << (int)cells - a << endl;
  return 0;
}

Measured memory_bytes: 256