akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <map>
#include <sstream>
#include <vector>
#include <set>
#include <string>
#include <iterator>
#include <queue>
#include <cmath>
#include <cassert>

typedef long long ll;
using namespace std;
#define REP(i,n) for (int i = 0; i < n; i++)

int main ()
{
    int N; cin >> N;
    vector < string > S(N);
    REP(i,N) cin >> S[i];

    int ans = 0;
    REP(i,N) {
        for (int j = 0; j < S[i].size() - 1; j++) {
            if (S[i][j] == 'A' && S[i][j + 1] == 'B') {
                ans++;
                j++;
            }
        }
    }

    int A = 0, B = 0, AB = 0;
    REP(i,N) {
        if (S[i].front() == 'B' && S[i].back() == 'A') {
            AB++;
        } else if (S[i].front() == 'B') {
            B++;
        } else if (S[i].back() == 'A') {
            A++;
        }
    }

    if (AB > 0) {
        ans += AB - 1;
        AB = 1;
        if (A > 0) {
            ans++;
            A--;
        }
        if (B > 0) {
            ans++;
            B--;
        }
    }

    ans += min(A, B);
    int t = min(A, B);
    A -= t;
    B -= t;    

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


Measured memory_bytes: 768
#!/usr/bin/env ruby

a,b,h,m = gets.split(' ').map(&:to_i)

pi_a = (h*60+m) * 0.5
pi_b = m*6
pi = (pi_b - pi_a).abs
pi = (360-pi) if pi > 180

X = b**2 + a**2 - 2*a*b*Math.cos(pi * Math::PI / 180)
puts Math.sqrt(X)


Measured memory_bytes: 14772
n = int(input())
a = list(map(int, input().split()))
r = [None] * (n + 1)
for i in range(n, 0, -1):
    r[i] = (a[i - 1] + sum(r[i * 2::i])) % 2
print(r.count(1))
print(*(i for i, x in enumerate(r) if x))


Measured memory_bytes: 13108
#include <bits/stdc++.h>
    using namespace std;
    #define rep(i, n) for (int i=0; i<(int)(n); i++)
     
    int main(){
     string o,e;
      cin >> o >> e;
      rep(i,e.size()){
        cout << o.at(i);
        cout << e.at(i);
      }
      if(e.size()<o.size()) cout << o.at(o.size()-1);
      cout << endl;
     
    	return 0;
    }

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
Apparently, the tree supports the same operations as the set 
(at least I haven't any problems with them before), but also there are two new features — 
find_by_order() — The first returns an iterator to the k-th largest element (counting from zero)
order_of_key() — the number of items in a set that are strictly smaller than our item. 
https://codeforces.com/blog/entry/11080
using namespace __gnu_pbds; */
using namespace std;
#define test() int t;cin>>t;for(int test=1;test<=t;test++)
#define int long long
#define MOD 1000000007
#define pb push_back 
#define ins insert
#define fast(); ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ld long double
#define endl '\n'
int m(int a) {
    return ((a%MOD)+MOD)%MOD;
}
int p(int a, int b) {
    int res = 1;
    while(b > 0){
        if(b&1) res = m(m(res)*m(a));
        a = m(m(a)*m(a));
        b >>= 1;
    }
    return res;
}
int inv(int n){
    return p(n, MOD-2);
}
vector<int> fact;
vector<int> invFact;
int nCr(int n, int r){
    // if(r == 0)  return 1;
    return m(m(m(fact[n])*m(invFact[r]))*m(invFact[n-r]));
}
signed main(){
    fast();
    string s;
    int k;
    cin >> k;
    cin >> s;
    int n = k+s.length();
    fact.resize(n+1);
    invFact.resize(n+1);
    fact[0] = 1;
    invFact[0] = inv(fact[0]);
    for(int i=1; i<=n; i++){
        fact[i] = m(m(fact[i-1])*m(i));
        invFact[i] = inv(fact[i]);
    }
    int z = 26;
    int ans = p(z,n), f = 0;
    vector<int> powers(s.length());
    for(int i=0; i<s.length(); i++){
        powers[i] = p(z-1, n-i);
    }
    for(int i=0; i<s.length(); i++){
        f = m(m(nCr(n, i))*m(powers[i]));
        ans = m(m(ans)-m(f));
    }
    // cout << f << endl;
    cout << ans << endl;
    cerr << "\nTime elapsed : " << 1000 * clock() / CLOCKS_PER_SEC << " ms\n";
}

Measured memory_bytes: 43260
#include <iostream>
#include <cmath>
#include <iomanip>
#include <cstdio>
#include <string>
#include <sstream>
int fix()
{
    //example to format floating point numbers.
    double pi = 3.141592653589793;
    double r = 3.141592653589793 * 128;
    std::ios_base::fmtflags f(std::cout.flags()); //[1]
    std::cout << "default:\n  " << pi << " " << r << "\n";
    std::cout << std::setprecision(4) << "setprecision(4):\n  " //[2]
              << pi << " " << r << "\n";
    std::cout << std::setiosflags(std::ios::fixed) << "setiosflags(std::ios::fixed):\n  " //[2]
              << pi << " " << r << "\n";
    std::cout << std::setprecision(5) << "setprecision(5):\n  " //[2]
              << pi << " " << r << "\n";
    std::cout.flags(f);
    std::cout << "reset:\n  " << pi << " " << r << "\n";
    //[1] https://stackoverflow.com/questions/2273330/restore-the-state-of-stdcout-after-manipulating-it
    //[2] https://stackoverflow.com/questions/4217510/how-to-cout-the-correct-number-of-decimal-places-of-a-double-value
    return 0;
}
void multipleLines()
{
    //example to parse multiple lines input.
    std::istringstream isin("1 2 3\n3 2 4\n0 0 0");

    for (std::string str; std::getline(isin, str);)
    {
        std::istringstream tisin(str);
        int a, b, c;
        tisin >> a >> b >> c;
        std::cout << a << " " << b << " " << c << "\n";
    }
    //[1]  https://stackoverflow.com/questions/19767644/c-parsing-input-string-to-variables
}
#include <vector>
int main()
{
    int64_t n;
    std::vector<double> va;
    std::cin >> n;
    va.resize(n+1);
    for (int64_t i = 0; i < n; i++)
    {
        std::cin >> va[n - i];
    }
    for (int64_t i = 1; i <= n; i++)
    {
        std::cout << va[i];
        if(i != n)
        {
            std::cout << " ";
        }
    }
    std::cout << "\n";
    return 0;
}


Measured memory_bytes: 3268
n,q = map(int,input().split())
s = input()
pref = [0]
for i in range(1,n):
  if s[i-1:i+1] == "AC": 
      pref.append(pref[-1]+1)
  else: 
      pref.append(pref[-1])
for i in range(q):
    l,r = map(int,input().split())
    print(pref[r-1]-pref[l-1])

Measured memory_bytes: 6152
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(input())
def inpl(): return list(map(int, input().split()))
def inpl_s(): return list(input().split())
atoz = [chr(i) for i in range(97,97+26)]

N = inp()

def calc(x,n):
	tmp = 0
	while x > 0:
		tmp += x%n
		x //= n
	return tmp

ans = INF
for i in range(0,N+1,6):
	tmp = calc(i,6)+calc(N-i,9)
	ans = min(ans,tmp)

print(ans)


Measured memory_bytes: 4212
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(ll i = 0; i < n; i++)
#define rep2(i,start,end) for(ll i = start; i < end; i++)
#define dwn(i,n) for(int i = n; i >= 0; i--)
#define dwn2(i,start,end) for(ll i = start; i >= end; i--)
#define pll pair<ll,ll>
#define mk(x,y) make_pair(x,y)
#define pdl pair<double, ll>
const ll N = 4e5 + 200;
const ll INF = 0x3f3f3f;
const ll Mode = 1e9 + 7;


int main(){
	ll n;
	cin>>n;
	priority_queue<double, vector<double>, greater<double>> p;
	rep(i,n){
		ll x;
		cin>>x;
		p.push(x);
	}
	while(p.size() > 1){
		double x,y;
		x = p.top();
		p.pop();
		y = p.top();
		p.pop();
		p.push((x+y)/2.0);
	}
	cout<<p.top()<<endl;
	return 0;
}


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

using namespace std;

int main(){
  int n; cin >> n;
  vector<int> v(n);
  vector<int> c(n);
  for(int i=0;i<n;i++){
    cin >> v[i];
  }
  for(int i=0;i<n;i++){
    cin >> c[i];
  }
  int sum=0;
  for(int i=0;i<n;i++){
    if((v[i]-c[i])>0){
      sum += v[i]-c[i];
    }
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
    int a,b;
    int f = 0;
    int ans[2000] = {0};
    int cnt = 0;
    int j = 0;
    for(;;){
        cin >> a >> b;
        if(a == 0 && b == 0)break;
        else if(f == 1) printf("\n");
        for(int i = a; i <= b; i++){
            if(i%4 == 0 && i%100 != 0){cnt++;ans[j] = i;j++;}
            else if(i%400 == 0){cnt++;ans[j] = i;j++;}
        }
        if(cnt == 0)printf("NA\n");
        else {
            for(int i = 0;i < j; i++)printf("%d\n",ans[i]);
            j = 0;
            cnt = 0;
        }
        f = 1;
    }
    return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
using namespace std;

int main(int argc, char *argv[])
{
    int n;
    double ave = 0.0, sum = 0.0, score[1001];
    while (cin >> n && n != 0)
    {
        for (int i = 0; i < n; i++)
        {
            cin >> score[i];
            ave += score[i];
        }
        ave /= n;
        for (int i = 0; i < n; i++)
        {
            sum += pow(score[i] - ave, 2);
        }
        cout << fixed << setprecision(8) << sqrt(sum / n) << endl;;
        ave = 0;
        sum = 0;
    }

    return 0;
}


Measured memory_bytes: 3296
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();

        long result = 0;
        for (int i = 1; i < N + 1; i++) {
            if (i % 3 != 0 && i % 5 != 0) {
                result += i;
            }
        }
        System.out.println(result);
    }
}

Measured memory_bytes: 27236
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
#define pi pair<int,int> 
#define pb push_back
#define INF INT_MAX 
#define mod 1000000007ll
#define fi first
#define se second
#define f(i,p,q) for(int i=p;i<q;i++)
#define si(a) scanf("%d",&a)
#define sii(a,b) scanf("%d %d",&a,&b)
#define siii(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define pii(a) printf("%d\n",a)
#define psi(a) printf(" %d",a)
#define poi(a) printf("%d",a)
#define sl(a) scanf("%lld",&a)
#define pl(a) printf("%lld\n",a)
#define Nline() printf("\n")
#define sstr(str) scanf("%s",str)
#define pstr(str) printf("%s\n",str)
#define SET(a) memset(a,-1,sizeof(a))
#define CLR(a) memset(a,0,sizeof(a))
#define vi vector<int>
#define vvi vector<vi>
#define all(v) (v).begin(),(v).end()
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())
#define VI(a,n) vi a(n); rep(i,n)cin>>a[i];
#define sq(n) (n)*(n)
#define iso ios::sync_with_stdio(false); cin.tie(0);cout.tie(NULL);
int main()
{    iso;
	 string s;cin>>s;
	 if(s[0]=='7'||s[1]=='7'||s[2]=='7')cout<<"Yes";
	 else cout<<"No";
     
}


Measured memory_bytes: 3648
#include <iostream>
#include <cstring>

using namespace std;

int main()
{
    char str[1001];

    cin >> str;

    for (int i = 0 ; i < (int)strlen(str); i++) {
        if (str[i] == 'A') {
            str[i] = 'X';
        }
        else if (str[i] == 'B') {
            str[i] = 'Y';
        }
        else if (str[i] == 'C') {
            str[i] = 'Z';
        }
        else {
            str[i] -= 3;
        }
    }

    cout << str << endl;
}



Measured memory_bytes: 3092
#include <iostream>
using namespace std;
int main( void )
{
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  int A = N / 1000;
  N -= A*1000;
  int B = N / 100;
  N -= B*100;
  int C = N/10;
  int D = N%10;
  if( A+B+C+D == 7 ){
    cout << A << "+" << B << "+" << C << "+" << D << "=7" << endl;
  } else if( A+B+C-D == 7 ){
    cout << A << "+" << B << "+" << C << "-" << D << "=7" << endl;
  } else if( A+B-C+D == 7 ){
    cout << A << "+" << B << "-" << C << "+" << D << "=7" << endl;
  } else if( A+B-C-D == 7 ){
    cout << A << "+" << B << "-" << C << "-" << D << "=7" << endl;
  } else if( A-B+C+D == 7 ){
    cout << A << "-" << B << "+" << C << "+" << D << "=7" << endl;
  } else if( A-B+C-D == 7 ){
    cout << A << "-" << B << "+" << C << "-" << D << "=7" << endl;
  } else if( A-B-C+D == 7 ){
    cout << A << "-" << B << "-" << C << "+" << D << "=7" << endl;
  } else if( A-B-C-D == 7 ){
    cout << A << "-" << B << "-" << C << "-" << D << "=7" << endl;
  }
}

Measured memory_bytes: 256
X = int(input())
L = []
for i in range(120):
	L.append(i ** 5)
x = 0
for a in L:
	if a < X:
		b = X - a
		if b in L:
			B = -L.index(b)
			break
	else:
		b = a - X
		if b in L:
			B = L.index(b)
			break
A = L.index(a)
print(A, B)

Measured memory_bytes: 9228
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cctype>
using namespace std;
const int N = 100+5;
int p[26][N], t[26];
int ans, n, f[N];
char s[N];
int main()
{
    scanf("%s", s+1), ans = n = strlen(s+1);
    for(int i = 1; i <= n; ++i) p[s[i]-'a'][++t[s[i]-'a']] = i;
    for(int i = 0; i < 26; ++i)
    {
        p[i][0] = 0, p[i][t[i]+1] = n+1, f[t[i]+1] = 0;
        for(int j = 1; j <= t[i]; ++j) f[j] = max(f[j-1], p[i][j]-p[i][j-1]-1);
        for(int j = t[i]; j; --j) ans = min(ans, max(f[j], max(f[j+1], p[i][j+1]-p[i][j]-1))), f[j] = max(f[j+1], p[i][j+1]-p[i][j]-1);
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <iostream>
#include <queue>
#define INF (1e9)
#define f first
#define s second
#define N 7
using namespace std;
typedef pair<int,int> P;
int bfs();
bool Check(int,int,int,int,int,int);
int w,h,data[N][N],d[N][N][N][N];
int scy,scx,swy,swx,gcy,gcx;
int dy[4]={-1,0,1,0};
int dx[4]={0,1,0,-1};
struct dat{
  int cy,cx,wy,wx;
};

int main(){
  while(1){
    cin>>w>>h;
    if(!w&&!h) break;
    for(int i=0;i<h;i++)
      for(int j=0;j<w;j++){
	cin>>data[i][j];
	if(data[i][j]==2) scy=i,scx=j;
	if(data[i][j]==3) gcy=i,gcx=j;
	if(data[i][j]==4) swy=i,swx=j;
	for(int k=0;k<h;k++)
	  for(int l=0;l<w;l++) d[i][j][k][l]=INF;
      }
    cout<<bfs()<<endl;
  }
  return 0;
}

int bfs(){
  queue<dat > Q;
  for(int i=0;i<4;i++){
    int ny=scy+dy[i],nx=scx+dx[i];
    if(ny<0||nx<0||h<=ny||w<=nx||data[ny][nx]==1) continue;
    if(!Check(swy,swx,ny,nx,scy,scx)) continue;
    Q.push((dat){scy,scx,ny,nx});
    d[scy][scx][ny][nx]=0;
  }
  while(!Q.empty()){
    dat t=Q.front();
    Q.pop();
    if(t.cy==gcy&&t.cx==gcx) return d[gcy][gcx][t.wy][t.wx];
    for(int i=0;i<4;i++){
      int ncy=t.cy+dy[i],ncx=t.cx+dx[i],nwy=t.cy,nwx=t.cx;
      if(ncy<0||ncx<0||h<=ncy||w<=ncx||data[ncy][ncx]==1) continue;
      if(!Check(t.wy,t.wx,nwy-dy[i],nwx-dx[i],t.cy,t.cx)) continue;
      if(d[ncy][ncx][nwy][nwx]>d[t.cy][t.cx][t.wy][t.wx]+1){
	d[ncy][ncx][nwy][nwx]=d[t.cy][t.cx][t.wy][t.wx]+1;
	Q.push((dat){ncy,ncx,nwy,nwx});
      }
    }
  }
  return -1;
}

bool Check(int sy,int sx,int gy,int gx,int xy,int xx){
  bool c[h][w];
  queue<P > Q;
  if(sy<0||sx<0||h<=sy||w<=sx||data[sy][sx]==1) return false;
  for(int i=0;i<h;i++)
    for(int j=0;j<w;j++) c[i][j]=false;
  Q.push(make_pair(sy,sx));
  c[sy][sx]=true;
  while(!Q.empty()){
    P t=Q.front();
    Q.pop();
    int uy=t.f,ux=t.s;
    if(uy==gy&&ux==gx) return true;
    for(int i=0;i<4;i++){
      int ny=uy+dy[i],nx=ux+dx[i];
      if(ny<0||nx<0||h<=ny||w<=nx||data[ny][nx]==1||(ny==xy&&nx==xx)) continue;
      if(c[ny][nx]) continue;
      c[ny][nx]=true;
      Q.push(make_pair(ny,nx));
    }
  }
  return false;
}

Measured memory_bytes: 1212
import sys
input=sys.stdin.readline
n=int(input())
a_list=list(map(int,input().split()))
num=[0]*n
for i in a_list:
    num[i-1]+=1
c=0
for i in num:
    c+=i*(i-1)//2
for i in range(n):
    x=a_list[i]
    ans=c-num[x-1]+1
    print(ans)

Measured memory_bytes: 79308
#include <bits/stdc++.h>
#define LL long long
using namespace std;
const LL maxn = 100000+100;
int a[maxn];
int vis[maxn];
int main()
{
    LL n;
    cin>>n;
    LL ans=n/11*2;
    int mod=11;
    n%=mod;
    if(n>=1&&n<=6)ans++;
    else if(n>=7&&n<=10)ans+=2;
    cout<<ans;
}


Measured memory_bytes: 256
#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>;

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

    int ans = 0;
    if (S == "SUN")
    {
        ans = 7;
    } else if (S == "MON")
    {
        ans = 6;
    } else if (S == "TUE")
    {
        ans = 5;
    } else if (S == "WED")
    {
        ans = 4;
    } else if (S == "THU")
    {
        ans = 3;
    } else if (S == "FRI")
    {
        ans = 2;
    } else
    {
        ans = 1;
    }
    
    cout << ans << endl; 
  return 0;
}


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

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

    const string way = "EWSN";
    bool dir[4];
    fill(dir, dir + 4, false);
    for (char c : S) {
        for (int i = 0; i < 4; ++i) {
            if (c == way[i]) dir[i] = true;
        }
    }

    if (dir[0] == dir[1] && dir[2] == dir[3]) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}


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

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
from collections import defaultdict
from collections import deque
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def inputI(): return int(input().strip())
def inputS(): return input().strip()
def inputIL(): return list(map(int,input().split()))
def inputSL(): return list(map(str,input().split()))
def inputILs(n): return list(int(input()) for _ in range(n))
def inputSLs(n): return list(input().strip() for _ in range(n))
def inputILL(n): return [list(map(int, input().split())) for _ in range(n)]
def inputSLL(n): return [list(map(str, input().split())) for _ in range(n)]

######OUTPUT######
def Yes(): print("Yes"); return
def No(): print("No"); return

#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1:
    arr.append([temp, 1])
  if arr==[]:
    arr.append([n, 1])
  return arr

#####MakeDivisors######
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count

#####ChangeBase#####
def Base_10_to_n(X, n):
  if X//n:
    return Base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def Base_n_to_10(X, n):
  return sum(int(str(X)[-i])*n**i for i in range(len(str(X))))

#####IntLog#####
def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count

#############
# Main Code #
#############

N,M = inputIL()
n = inputILL(N)
m = inputILL(M)

ans = []
for c,d in n:
  MIN = (INF,INF)
  count = 0
  for a,b in m:
    count += 1
    dis = abs(a-c)+abs(d-b)
    if dis < MIN[0]:
      MIN = (dis,count)
  ans.append(str(MIN[1]))

print(*ans,sep="\n")

Measured memory_bytes: 39768
#include <bits/stdc++.h>
 
#define f(i,a,b) for( ll i = a; i < b ; i++ ) 
#define af(i,a,b) for( ll i = a; i >= b ; i--)
#define rep(i,a,b,k) for(ll i = a; i < b ; i+= k )
#define arep(i,a,b,k) for( ll i = a; i >= b ; i-= k)
#define ones(x) (ll) __builtin_popcount(x)
#define fs first
#define sc second
#define pb push_back
#define po pop_back
#define mp make_pair
#define sz(a) (ll) a.size()
#define all(a) a.begin(), a.end()
#define sor(a) sort( a.begin(), a.end() )
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ller ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr)
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> ii ;
typedef vector<ll>  vi ;
typedef vector<ii> vii ;
 
const ll MAX = 100000;
const ll inf = 5e18;

int main() {
	fastio;
	ll n,m,sum=0,x;
	cin>>n>>m;
	f(i,0,m){
		cin>>x;
		sum+=x;
	}
	if(n-sum>=0) cout<<n-sum<<endl;
	else cout<<"-1\n";
return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define MOD 1000000007
#define endl "\n"
typedef long long ll;
using namespace std;

bool isPal(const string& s) {
    string ss(s);
    reverse(ss.begin(), ss.end());
    return s == ss;
}

int main() {
    ios::sync_with_stdio(false);
    cout.precision(10);
    string s;
    cin >> s;
    string ss;
    for(int i = 0; i < s.size(); i++) {
        if(s[i] != 'x') {
            ss += s[i];
        }
    }
    if(!isPal(ss)) {
        cout << -1 << endl;
        return 0;
    }
    int l = 0, r = s.size() - 1;
    int ans = 0;
    while(r > l) {
        if(s[l] != s[r]) {
            while(s[l] != s[r]) {
                if(s[l] == 'x') {
                    ans++;
                    l++;
                } else if(s[r] == 'x') {
                    ans++;
                    r--;
                }
            }    
        } else {
            l++;
            r--;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 592
//DP

#include <bits/stdc++.h>
#define rep(i,N) for (int i = 0; i < (N); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int inf{int(1e9)};
const int mod = 1000000007;

/*
auto f(ll x){
  if (x == 1) return 1;
  if (x == 2) return 2;
  else return (f(x - 1) + f (x - 2)) % mod;
}
*/

int main(void){
  int N, M;
  cin >> N >> M;
  vector <int> broken(N + 1);
  rep(i,M){
    int a;
    cin >> a;
    broken[a] = 1;
  }
  vector <int> dp(N + 2);  //N-1段目が壊れていた時に配列外参照で困らないようにするため
  dp[N] = 1;
  for (int i = N - 1; i >= 0; i--){
    if (broken[i]){
      dp[i] = 0;
      continue;
    }
    dp[i] = (dp[i + 1] + dp[i + 2]) % mod;
  }
  cout << dp[0] << endl;
  /*
  //x段を登る移動方法の総数
  ll ans = 1;
  rep(i,M){
    cin >> a[i];
    if (i > 0){
      if (a[i] == a[i - 1] + 1){
        cout << 0 << endl;  //連続で床が壊れていたら0を出力して終了
        return 0;
      }
      ans *= f(a[i] - a[i - 1]);
      ans %= mod;
    }
  }
  cout << ans << endl;
  */
  return 0;
}


Measured memory_bytes: 3996
//A.cpp
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <math.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b!=0?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
const ll mod=1e9+7;

bool isPrime(int n){
  if(n < 2) return false;
  for(int i = 2; i*i <= n; i++){
    if(n % i == 0) return false;
  }
  return true;
}

int main(){
  int x;
  cin >> x;
  while(true){
    if(isPrime(x)){
      printf("%d\n", x);
      return 0;
    }
    else x++;
  }
  return 0;
}


Measured memory_bytes: 256
N = int(input())
A = [int(i) for i in input().split()]

A.insert(0,0)
A.append(0)

S = 0

for i in range(1,N+2):
    S += abs(A[i]-A[i-1])

for i in range(1,N+1):
    print(S + abs(A[i-1]-A[i+1]) - abs(A[i-1]-A[i]) - abs(A[i]-A[i+1]))

Measured memory_bytes: 14048
import java.util.Scanner;
 
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] l = new int[N];
		int[] r = new int[N];
		for(int i = 0 ; i < N ; i++) {
			l[i] = sc.nextInt();
			r[i] = sc.nextInt();
		}
		int[] person = new int[1001001];
		for(int i = 0 ; i < N ; i++) {
			for(int j = l[i] - 1 ; j <= r[i] - 1 ; j++) {
				person[j] = 1;
			}
		}
		int ans = 0;
		for(int i = 0 ; i < person.length ; i++) {
			if(person[i] == 1) {
				ans++;
			}
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 30696
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn main() {
    let n = read_vec::<usize>()[0];
    let mut v = read_vec::<i32>();

    v.sort();

    let m = n / 2;
    let m_0 = v[m - 1];
    let m_1 = v[m];
    println!("{}", m_1 - m_0);
}


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

int main(void) {
	string s;
	cin >> s;
	int L = s.length() / 2 * 2;
	while (L) {
		string x, y;
		L = L - 2;
		for (int j = 0; j < L / 2; j++) {
			x.append(1,s[j]);
			y.append(1,s[L / 2 + j]);
		}
		if (x == y) {
			cout << L << endl;
			return 0;
		}
	}
	cout << 0 << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;
long long A, B, N;
long long calc(long long x) {
    return ( (A*x) / B ) - A * ( x / B );
}
int main() {
    cin >> A >> B >> N;

    if (B-1 <= N) {
        cout << calc(B-1) << endl;
    }
    else {
        cout << calc(N) << endl;
    }
    return 0;
}



Measured memory_bytes: 3584
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long int
#define pb push_back
#define fi first
#define se second
#define ld long double
#define vi vector<vector<ll> >
using namespace std;
const int MOD=1000000007;
const int MOD2=15000007;
const ll MAX=9187201950435737471;
const int N=100005;
const int INF=1e17;
const long double PI=acos(-1);



void solve(int T){
   double n,k;
   cin>>n>>k;
   double ans=0.0;
   //cout<<(ld)1/n<<"\n";
   for(int i=1;i<=n;i++){
        ll x=i;
        ld tmp=1.0/n;
        while(x<k){
            tmp*=(1.0/2.0);
            x*=2;
        }
        ans+=tmp;
   }
   cout<<fixed<<setprecision(12)<<ans<<"\n";
}

int main() {
    fastio
    int T=1;
    //cin>>T;
    for(int i=1;i<=T;i++){
        solve(i);
        //if(i<T)cout<<"\n";
    }
    return 0;
}





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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
typedef long long ll;


int main() {
    string S; cin >> S;
    if(S[1] == 'B'){
        cout << "ARC" << endl;
    }else{
        cout << "ABC" << endl;
    }
    return 0;
}

Measured memory_bytes: 3636
#include<stdio.h>
int main(void){
  char *s="python3 -c\""
"I=lambda:map(int,input().split());n,q=I();s=input();a=[0]\n"
"for i in range(n):a+=[a[i]+(s[i-1:i+1]=='AC')]\n"
"while q:l,r=I();print(a[r]-a[l]);q-=1\n"
"\"";
  system(s);
  return 0;
}            

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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

const int N = 2e5 + 5;
int32_t main()
{
	IOS;
	string s;
	cin>>s;
	if(s[0]=='R' && s[1]=='R' && s[2]=='R'){
		cout<<3<<"\n";
	}
	else if((s[0]=='R' && s[1]=='R')||(s[1]=='R' && s[2]=='R')){
		cout<<2<<"\n";
	}
	else if(s[0]=='R' || s[1]=='R' || s[2]=='R'){
		cout<<1<<"\n";
	}
	else cout<<0<<"\n";
	return 0;
}


Measured memory_bytes: 3660
def f(n):
    for k, c in dic.items():
        a, b = k
        if a == n:
            if not b in cost or c < cost[b]:
                cost[b] = c
        elif b == n:
            if not a in cost or c < cost[a]:
                cost[a] = c
    for k, c in sorted(cost.items(), key=lambda x: x[1]):
        if not k in res:
            res.append(k)
            ans.append(c)
            f(k)
while True:
    n, m = map(int, raw_input().split())
    if n == m == 0: break
    dic = {}
    s, b, c = map(int, raw_input().split())
    dic[(s, b)] = c
    for i in range(m-1):
        a, b, c = map(int, raw_input().split())
        dic[(a, b)] = c
    cost = {}
    res = [s]
    ans = []
    f(s)
    print sum(ans)

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

#define pb push_back
#define mp make_pair
#define size(n) ( int( n.size() ) )
#define sqr(n) ( (n) * (n) )
#define fi first
#define se second

using namespace std;

typedef long long ll;
typedef long double ld;

const int mod = 1e9 + 7, N = 1e5 + 50;
int fact[N];

int main(){
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int n, m;
    fact[0] = 1;
    for ( int i = 1; i < N; i++ ){
        fact[i] = ( fact[i-1] * 1ll * i ) % mod;
    }
    scanf("%d %d",&n,&m);
    if ( n > m ){
        swap(n,m);
    }
    if ( m - n > 1 ){
        printf("0");
    }
    else{
        int ans = ( fact[n] * 1ll * fact[m] ) % mod;
        if ( n == m ){
            ans = ( ans * 2 ) % mod;
        }
        printf("%d\n",ans);
    }
    return 0;
}


Measured memory_bytes: 640
import java.io.PrintStream;
import java.util.Scanner;
import java.util.function.BiFunction;

public class Main {
    private static final PrintStream so = System.out;
    private static final Scanner     sc = new Scanner(System.in);

    public static void main(String[] args) {
        String s = sc.next();
        int a = s.charAt(0) - '0';
        int b = s.charAt(1) - '0';
        int c = s.charAt(2) - '0';
        int d = s.charAt(3) - '0';
        
        Operator[] opes = Operator.values();
        int len =opes.length;
        for (int ia = 0; ia < len; ia++) {
            for (int ib = 0; ib < len; ib++) {
                for (int ic = 0; ic < len; ic++) {
                    if (opes[ic].apply(opes[ib].apply(opes[ia].apply(a, b), c), d).equals(7)) {
                        so.println("" + a + opes[ia] + b + opes[ib] + c + opes[ic] + d + "=7");
                        return;
                    }
                }
            }
        }
    }
    
    public static enum Operator {
        PLUS("+", (Integer a, Integer b) -> a + b),
        MINUS("-", (Integer a, Integer b) -> a - b);
        
        private Operator(String s, BiFunction<Integer, Integer, Integer> operation) {
            this.s = s;
            this.operation = operation;
        }
        
        public Integer apply(Integer a, Integer b) {
            return this.operation.apply(a, b);
        }
        private final String s;
        private final BiFunction<Integer, Integer, Integer> operation;
        
        public String toString() {
            return s;
        }
    }
}


Measured memory_bytes: 26836
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
      
        int N = Integer.parseInt(sc.next());
      
        long K = Long.parseLong(sc.next());
      
        int[] a = new int[N];
      //aer augeworaw
        long[] b = new long[N];
      
        Map<Integer, Long> map = new TreeMap<>();
        for(int i=0; i<N; i++) {
            a[i] = Integer.parseInt(sc.next());
            b[i] = Long.parseLong(sc.next());
            if(map.containsKey(a[i])) map.put(a[i], map.get(a[i])+b[i]);
            else map.put(a[i], b[i]);
        }
        long sum = 0;
        int ans = 0;
        for(int i : map.keySet()) {
            
            sum += map.get(i);
            if(sum >= K) {
                ans = i;
                break;
            }
        }
        System.out.println(ans);
        
    }   
}


Measured memory_bytes: 66548
#include <bits/stdc++.h>
using namespace std;
const int maxn = 10010;
int main(void)
{
    int a,b,c,k;
    cin>>a>>b>>c>>k;
    int ret;
    if(a>=k)ret = k;
    else if(a+b>=k) ret = a;
    else ret = a*2+b-k;

    cout<< ret<<endl;
    return 0;
}


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

using ll    = long long;
using ull   = unsigned long long;
using veci  = vector<int>;
using vecll = vector<ll>;
#define EPS (1e-7)
#define INF (1e9)
#define PI  (acos(-1))
#define FOR(i,a,b) for(int i = (a);i < (b); ++i)
#define REP(i,n) for(int i= 0;i<(int)(n);++i)
#define pb push_back

veci enum_div(int n){
	veci ret;
	ret.pb(1);
	for(int i=1;i*i<n;i++){
		if(n%i==0){
			ret.pb(i);
			if(i != n/i){ret.pb(n/i);}
		}
	}
	ret.pb(n);
	return ret;
}
int gcb(int a,int b){return ((b == 0)? a : gcb(b,a%b));}
int gcd(int a,int b){return (a*b) / gcb(a,b);}

int main(){
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    cout << min(a,b) + min(c,d) << endl;
	return 0;
}



Measured memory_bytes: 256
h, w, m = map(int, input().split())
s = dict()
num_h = [0] * h
num_w = [0] * w
for _ in range(m):
    hi, wi = map(int, input().split())
    hi -= 1
    wi -= 1
    s[(hi, wi)] = True
    num_h[hi] += 1
    num_w[wi] += 1
max_h_list = []
max_h_val = 0
max_w_list = []
max_w_val = 0
for hi in range(h):
    if num_h[hi] > max_h_val:
        max_h_list = [hi]
        max_h_val = num_h[hi]
    elif num_h[hi] == max_h_val:
        max_h_list.append(hi)
for wi in range(w):
    if num_w[wi] > max_w_val:
        max_w_list = [wi]
        max_w_val = num_w[wi]
    elif num_w[wi] == max_w_val:
        max_w_list.append(wi)

if len(max_h_list) * len(max_w_list) > m:
    print(max_h_val + max_w_val)
    exit()
for max_hi in max_h_list:
    for max_wi in max_w_list:
        if s.get((max_hi, max_wi), False) == False:
            print(max_h_val + max_w_val)
            exit()
print(max_h_val + max_w_val - 1)


Measured memory_bytes: 194012
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        char s[] = sc.next().toCharArray();
        int total = 700;
        for(int i = 0; i < 3; i++) {
            if( s[i] == 'o' ) {
                total += 100;
            }
        }
        System.out.println( total );

    }
}


Measured memory_bytes: 35552
N, A, B = map(int, input().split())
if A > B:
    print(0)
    exit(0)
if N == 1:
    if A == B:
        print(1)
        exit(0)
    else:
        print(0)
        exit(0)
print((B*(N-1)+A)-(A*(N-1)+B)+1)


Measured memory_bytes: 2940
#include<stdio.h>
#define N 200000

int main(){
  int n,i,r[N];
  int min,max;
  scanf("%d",&n);
  for(i=0;i<n;i++) scanf("%d",&r[i]);
  min = r[0];
  max = r[1]-r[0];
  for(i=1;i<n;i++){
    if(max<(r[i]-min)) max = r[i]-min;
    if(min>r[i]) min = r[i];
  }
  printf("%d\n",max);
  return 0;
}

Measured memory_bytes: 1376
#include <stdio.h>
int main(void){
    int d,g,i,j,k;
    long int res=1<<30;
    scanf("%d %d",&d,&g);
    int p[d];
    int c[d];
    for(i=0;i<d;i++)
        scanf("%d %d",&p[i],&c[i]);
    for(i=0;i<(1<<d);i++){
        // printf("%d回目-----------------------\n",i+1);
        long int sum=0;
        long int cnt=0;
        for(j=0;j<d;j++){
            // 全完したとき
            if(i&(1<<j)){
                sum+=c[j]+p[j]*100*(j+1);
                cnt+=p[j];
            }
        }
        // printf("sum=%ld,cnt=%ld\n",sum,cnt);
        if(sum>=g){
            if(cnt<res) res=cnt;}
        else{
            // printf("No zenkan\n");
            for(j=d-1;j>=0;j--){
                if(i&(1<<j)) continue;
                //問題数分繰り返す
                for(k=0;k<p[j];k++){
                    // printf("sum=%ld\n",sum)
                    if(sum>=g) break;
                    sum+=100*(j+1);
                    cnt++;
                }
            }
            if(cnt<res) res=cnt;
        }
    }
    printf("%ld\n",res);
}

Measured memory_bytes: 128
# https://atcoder.jp/contests/agc032/tasks/agc032_b
# 完全グラフからどの辺を減らそうかって考えるとわかる

N = int(input())
ans = set()
for i in range(1, N + 1):
    for j in range(i + 1, N + 1):
        ans.add((i, j))

if N & 1:  # 奇数
    N -= 1

for k in range(N // 2):
    i = k + 1
    j = N - k
    ans.remove((i, j))
print(len(ans))
for i, j in ans:
    print(i, j)


Measured memory_bytes: 80004
#include <cstdio>

int main(){
	int n;
	scanf("%d", &n);
	for(int i = 0; i < n; i++){
		int x, y, b, p;
		int ans, tmp;
		scanf("%d%d%d%d", &x, &y, &b, &p);
		if(b >= 5 && p >= 2){
			printf("%d\n", (x*b+y*p)*8/10);
			continue;
		}
		ans = x*b+y*p;
		if(b <= 5 && p <= 2){
			tmp = (x*5+y*2)*8/10;
		} else if(b <= 5){
			tmp = (x*5+y*p)*8/10;
		} else if(p <= 2){
			tmp = (x*b+y*2)*8/10;
		}
		if(ans > tmp) ans = tmp;
		printf("%d\n", ans);
	}
}

Measured memory_bytes: 1028
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
	vector<int> v(N);
  for(int i;i<N;i++){
    cin >> v.at(i);
  }
  sort(v.begin(),v.end());
  reverse(v.begin(),v.end());
  int A,B;
  for(int i;i<N;i++){
    if(i%2 == 0) A += v.at(i);
    else B += v.at(i);
  }
  cout << A-B << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <queue>
#include <map>
#include <string>
#include <algorithm>
#include <numeric>
using namespace std;

int main(){

	int n;
	cin >> n;
	cout << 800*n - (n/15)*200 << endl;

	return 0;
}


Measured memory_bytes: 256
n = int(input())
x = input()
y = input()
if x[0]==y[0]: num,flag,place = 3,True,1
else: num,flag,place = 6,False,2
while place!=n:
	if flag:
		num = (num*2)%(10**9+7)
		if x[place]!=y[place]:
			flag = False
			place += 2
		else: place+=1
	else:
		if x[place]==y[place]:
			flag = True
			place += 1
		else:
			num = (num*3)%(10**9+7)
			place += 2
print(num)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
using namespace std;
 
int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    int mod = 1000000007;
    long long sum = 0;
    for (int i = 0; i < N; i++)
    {
        cin >> A[i];
        sum += A[i];
        sum %= mod;
    }
 
    long ans = 0;
 
    //i について全探索する
    for (int i = 0; i < N; i++)
    {
        //A[i+1] ... A[N] の値を更新する
        sum -= A[i];
        if (sum < 0) sum += mod;
 
        ans += A[i] * sum;
        ans %= mod;
    }
 
    cout << ans << endl;
}

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

using namespace std;
using llong = long long;
using P = pair<llong, llong>;

#define BE(x) x.begin(), x.end()

const llong inf = llong(1e18)+7;
const llong mod = 1e9+7;

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

	if(n >= 64)
		cout << 64 << endl;
	else if(n >= 32)
		cout << 32 << endl;
	else if(n >= 16)
		cout << 16 << endl;
	else if(n >= 8)
		cout << 8 << endl;
	else if(n >= 4)
		cout << 4 << endl;
	else if(n >= 2)
		cout << 2 << endl;
	else
		cout << 1 << endl;

	return 0;
}

Measured memory_bytes: 256
using System;
					
public class my
{
	public static void Main()
	{
		string s;
		
		while(null != (s = Console.ReadLine())) {
			var cnt =1;
			while(!s.Contains("1")){
				s = Console.ReadLine();
				cnt++;
			}
		
			var num1 = my.CountOfChar(s, "1");
			var idx1 = s.IndexOf("1");
			
			string result = "";
			
			if(num1 == 4) {
				result = "C";
			} else {
				s = Console.ReadLine();
				cnt++;
				
				var num2 = my.CountOfChar(s, "1");
				var idx2 = s.IndexOf("1");
				
				if(num1 == 1 && num2 == 1) {
					result = "B";
				} else if(num1 == 1 && num2 == 2) {
					if(idx1 == idx2) result = "F";
					else result = "D";
				} else if (num1 ==2 && num2 == 2) {
					switch(idx1-idx2) {
						case -1:
							result = "E";
							break;
						case 0:
							result = "A";
							break;
						case 1:
							result = "G";
							break;
					}
				}
			}
			
			Console.WriteLine(result);
			while(cnt++ <= 8) {
				Console.ReadLine();
			}
		}
		
	}
	
	private static int CountOfChar(string s, string c)
	{
		return s.Length - s.Replace(c, "").Length;
	}
}

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

const int M = 1000000007;
class mll {
public:
	long long x;
	mll(long long x = 0) : x((x% M + M) % M) {};
	void operator += (const mll& a) {
		if ((x += a.x) >= M) x -= M;
	}
	void operator ++ () {
		*this += 1;
	}
	void operator ++(int) {
		operator++();
	}
	void operator *= (const mll& a) {
		(x *= a.x) %= M;
	}
	bool operator < (const mll& a) {
		return this->x < a.x;
	}
	mll inv() {
		long long a = x, b = M, u = 1, v = 0;
		while (b) {
			long long t = a / b;
			a -= t * b; swap(a, b);
			u -= t * v; swap(u, v);
		}
		u %= M;
		if (u < 0) u += M;
		a = u;
		return mll(a);
	}
};

int main() {
	long long X, Y;
	cin >> X >> Y;
	if ((2 * X - Y) % 3 != 0 || (2 * Y - X) % 3 != 0 || 2 * X - Y < 0 || 2 * Y - X < 0) {
		cout << 0 << endl;
		return 0;
	}
	long long a = (2 * Y - X) / 3;
	long long b = (2 * X - Y) / 3;
	mll ans = 1;
	for (int i = a + b; i > b; i--) ans *= i;
	for (mll i = 1; i < a + 1; i++) ans *= i.inv();
	cout << ans.x << endl;
}


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

using namespace std;

double distance(vector<int> &A, vector<int> &B) {
	int D = (int)A.size();
	double sum = 0;
	for (int i=0; i<D; ++i) {
		sum += (A.at(i) - B.at(i)) * (A.at(i) - B.at(i));
	}
	
	return sqrt(sum);
}

int main(){
	int N, D;
	cin >> N >> D;
	
	vector<vector<int>> coords(N, vector<int>(D));
	
	for (int i=0; i<N; ++i) {
		for (int j=0; j<D; ++j) {
			cin >> coords.at(i).at(j);
		}
	}
	
	int count = 0;
	
	for (int i=0; i<N-1; ++i) {
		for (int j=i+1; j<N; ++j) {
			if (remainder(distance(coords.at(i), coords.at(j)), 1.0) == 0.0) {
				count++;
			}
		}
	}
	
	cout << count << endl;
	return 0;
}

Measured memory_bytes: 384
MAX = 10**9 + 7

def mod_inv(i, mod):
    return pow(i, mod-2, mod)

def combination(_N, _K):
    if _K > (_N/2):
        _K = _N - _K
    up = 1
    low = 1
    for i in range (_K):
        up = up * (_N - i) % MAX
        low = low * (i + 1) % MAX
    ret = up * mod_inv(low, MAX) % MAX
    return ret

def solve():
    N, M, K = [int(_) for _ in raw_input().split()]
    disSum = M*N* (M*(N+1)*(N-1) + N*(M+1)*(M-1)) // 6
    ret = disSum * combination(M*N-2, K-2) % MAX
    print ret

if __name__ == '__main__':
    solve()


Measured memory_bytes: 29036
k,n=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
max_diff=0
for i in range(1,n):
    if(max_diff<a[i]-a[i-1]):
        max_diff=a[i]-a[i-1]
if(max_diff<a[0]+(k-a[-1])):
    max_diff=a[0]+(k-a[-1])
print(k-max_diff)

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

int main() {
	string S;
	cin >> S;
	if (S == "ABC") {
		cout << "ARC" << endl;
		return 0;
	}
	cout << "ABC" << endl;
	return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
using namespace std;

using ll = long long;

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; }
template<class T> inline void dump(vector<T> v) { for (auto& x : v) cerr << x << " "; cerr << endl; }
template<class T> inline void dump(vector<pair<T, T>> v) { for (auto& p : v) cerr << p.first << " " << p.second << endl; }
template<class T> inline void dump(vector<vector<T>> vv) { for (auto& v : vv) {for (auto& x : v) cerr << x << " "; cerr << endl;} }

constexpr int INF = 1e9+5;
constexpr long long INFLL = 1LL<<60;

// エラトステネスの篩でN 以下の素数判定を行う
// 素数: 1, 素数じゃない: 0
// [0, 0, 1, 1, 0, 1, ...]
vector<int> create_eratos(int n) {
  vector<int> isprime(n+1, 1);
  isprime[0] = 0;
  isprime[1] = 0;

  for (int i = 2; i * i <= n; i++) {
    if (isprime[i]) {
      int j = i + i;
      while (j <= n) {
        isprime[j] = 0;
        j = j + i;
      }
    }
  }
  return isprime;
}

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

  auto eratos = create_eratos(1e5+10);

  auto check = [&] (int x) {
    return (x % 2 == 1 && eratos[x] && eratos[(x+1)/2]);
  };

  vector<int> csum(1e5+5, 0);
  for (int i = 3; i <= 1e5+5; i++) {
    csum[i] = csum[i-1];
    if (check(i)) csum[i]++;
  }

  int q;
  cin >> q;

  rep(i, q) {
    int l, r;
    cin >> l >> r;
    cout << csum[r] - csum[l - 1] << endl;
  }

  return 0;
}


Measured memory_bytes: 3912
from sys import stdin

N = int(stdin.readline().rstrip())

ans = 'No'
tmp = 0
x = 0
y = 0

if N < 4:
    pass
else:
    if N % 7 == 0:
        ans = 'Yes'
    elif N % 4 == 0:
        ans = 'Yes'
    else:
        y = N // 7
        for i in range(y):
            x = 1
            tmp = 4*x + 7*y
            while  tmp < N:
                tmp = 4*x + 7*y
                x += 1
            if tmp == N:
                ans = 'Yes'
                break
            y -= 1
print(ans)


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

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

using namespace std;

const int INF = 1 << 30;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 100;

int main() {
	cout << fixed << setprecision(15);
	int N, M; cin >> N >> M;
	vector<vector<int>> from(N), to(N);
	rep(i, M) {
		int s, t; cin >> s >> t;
		from[t-1].push_back(s-1);
		to[s-1].push_back(t-1);
	}
	vector<double> dp(N);
	dp[N-1] = 0;
	for (int i=N-1; i>=0; i--)  {
		for (auto f : from[i]) {
			int ts = to[f].size();
			dp[f] += (dp[i]+1)/ts;
		}
	}
	vector<double> dp2(N);
	dp[N-1] = 0;
	double ans = dp[0];
	rep(i, N-1) {
		if (to[i].size() == 1) continue;
		int idx;
		double max_n = 0.0;
		for (auto t : to[i]) {
			if (max_n < dp[t]) {
				idx = t;
				max_n = dp[t];
			}
		}
		rep(j, N) dp2[j] = 0;
		for (int j=N-1; j>=0; j--) {
			for (auto f : from[j]) {
				if (f == i && idx == j) continue;
				int ts = to[f].size();
				if (f == i) ts--;
				dp2[f] += (dp2[j]+1)/ts;
			}
		}
		if (dp2[0] != 0.0) ans = min(ans, dp2[0]);
	}
	cout << ans << endl;
}


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

const int MOD = (int) 1e9 + 7;

long long A[200005], two[400005];

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(NULL), cout.tie(NULL);

    int N;
    cin >> N;

    two[0] = 1;

    for(int i=1; i<=N; i++)
        cin >> A[i];
    for(int i=1; i<=2*N; i++)
        two[i] = two[i-1] * 2 % MOD;

    sort(A+1, A+1+N);
    long long ans = 0;

    for(int i=1; i<=N; i++)
        ans += two[2*N-2] * (N - i + 2) % MOD * A[i] % MOD;

    cout << ans % MOD << "\n";
    return 0;
}


Measured memory_bytes: 4992