akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using ll = int64_t;
using ld = double;
using ull = uint64_t;
using namespace std;
using namespace __gnu_pbds;     

unordered_map<string, int> a[19];



int main() {
#ifdef BZ
    freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cout.setf(ios::fixed); cout.precision(20);
    int n;
    string s;
    cin >> n >> s;

    {
        string t = s.substr(0, n);
        for (int i = 0; i < (1 << n); ++i) {
            int cn = 0;
            string cur;
            for (int j = 0; j < n; ++j) {
                if (i & (1 << j)) {
                    ++cn;
                    cur += t[j];
                }
            }

            for (int j = n - 1; j >= 0; --j) {
                if (!(i & (1 << j))) {
                    cur += t[j];
                }
            }

            ++a[cn][cur];
        }
    }

    ll ans = 0;

    {
        string t = s.substr(n);
        reverse(t.begin(), t.end());

        for (int i = 0; i < (1 << n); ++i) {
            int cn = 0;
            string cur;
            for (int j = 0; j < n; ++j) {
                if (i & (1 << j)) {
                    ++cn;
                    cur += t[j];
                }
            }

            for (int j = n - 1; j >= 0; --j) {
                if (!(i & (1 << j))) {
                    cur += t[j];
                }
            }

            ans += a[cn][cur];
        }
    }

    cout << ans << "\n";

}

Measured memory_bytes: 72372
#include <bits/stdc++.h>
 
using namespace std;
 
const int N = 100002;
 
vector<int> g[N];
int part[N];
 
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
 
    memset(part, 255, sizeof(part));
 
    int n, m;
    cin >> n >> m;
 
    for (int i = 0; i < m; i++) {
        int a,b;
        cin >> a >> b;
        a--;
        b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
 
    if (n < 4) {
        cout << 0 << endl;
        return 0;
    }
 
    list<int> q;
    q.push_back(0);
    part[0] = 0;
 
    bool is2 = true;
    while (!q.empty() && is2) {
        int curr = q.front();
        q.pop_front();
        for (int j = 0; j < g[curr].size(); j++) {
            int next = g[curr][j];
            if (part[next] == -1) {
                part[next] = 1 - part[curr];
                q.push_back(next);
            } else {
                if (part[next] != (1 - part[curr])) {
                    is2 = false;
                    break;
                }
            }
        }
    }
 
    if (is2) {
        int cnt1 = 0;
        for (int i = 0; i < n; i++) {
            cnt1 += part[i];
            if (part[i] == -1) {
                cerr << i << " failed!" << endl;
            }
        }
        int cnt0 = n - cnt1;
        cout << (1LL * cnt0 * cnt1 - m) << endl;
    } else {
        cout << (1LL * n * (n-1) / 2 - m) << endl;
    }
 
    return 0;
}

Measured memory_bytes: 8192
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define vpll vector < pair<long long,long long> >
#define fill(a,val)  memset(a,val, sizeof (a))
#define sort_unique(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define all(cont) cont.begin(), cont.end()
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MAX   1e9
#define MIN  -1e9
typedef map<int,int> mpi;
typedef set<int> seti;
typedef multiset<int> mseti;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define rep(i, n)    for(long long int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define trav(a, x) for(auto& a : x)
struct Interval {int start, end;};
bool compare(Interval i1, Interval i2) {return (i1.start < i2.start);}
int main()
{
    ll n;
    cin>>n;
    ll w[n];
    ll sum[n]={0};
    cin>>w[0];
    sum[0]=w[0];
    repA(i,1,n-1)
    {
        cin>>w[i];
        sum[i]=sum[i-1]+w[i];
    }
    ll mini=MAX;
    rep(t,n)
    {
        mini=min(abs(2*sum[t]-sum[n-1]),mini);
    }
    cout<<mini;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
  
int F[105][105];
int xg,yg,w,h;
  
  
void DFS(int Y,int X,int c){
  if(F[Y][X] != c || Y > w || X > h){
    return;
  }
  
  F[Y][X] = -1;
  DFS(Y+1,X  ,c);
  DFS(Y-1  ,X,c);
  DFS(Y,X+1  ,c);
  DFS(Y  ,X-1,c);
}
  
  
int main(){
  int xs,ys,n;
  while(1){
    cin >> w >> h;
    if(w == 0 && h == 0)
      break;
for(int i=0; i<105; i++){
      for(int j=0; j<105; j++){
        F[i][j] = 10;
      }
    }
      
    cin >> xs >> ys >> xg >> yg >> n;
  
  
    for(int i=0;i<n;i++){
      int c,d,x,y;
      cin >> c >> d >> x >> y;

      if(d == 0){
        for(int j=0;j<4;j++){
          F[x+j][y] = c;
          F[x+j][y+1] = c;
        }
      } else {
        for(int j=0;j<4;j++){
          F[x][y+j] = c;
          F[x+1][y+j] = c;
        }
      }
    }
  DFS(xs,ys,F[xs][ys]);
  
  if(F[xg][yg] == -1){
    cout << "OK" << endl;
  } else {
    cout << "NG" <<endl;
  }
  }
}


Measured memory_bytes: 3132
N=int(input())
def PrimeFactor(n):
    ret=[]
    for i in range(2,int(-(-n**0.5//1))+1):
        if i!=2 and i%2==0:
            continue
        cnt=0
        while n%i==0:
            cnt+=1
            n//=i
        if cnt!=0:
            ret.append([i,cnt])
    if n!=1:
        ret.append([n,1])
    return ret
L = PrimeFactor(N)
ans=0
for l in L:
    x = l[1]
    temp=1
    while x>=temp:
        ans+=1
        x-=temp
        temp+=1
print(ans)

Measured memory_bytes: 63904
#include <stdio.h>

int main(void)
{
    int a,b;
    scanf("%d %d", &a,&b);
    double a1,b1;
    a1 = a; b1 = b;

    printf("%d %d %lf\n",a/b,a%b,a1/b1);
    //printf("%d %d",sizeof(double), sizeof(float)); double : 8bit, float : 4bit
    return 0;
}



Measured memory_bytes: 2140
N, M=map(int,input().split())
X=list(map(int,input().split()))
X.sort()
if N>=M:
    print(0)
else:
    L=[X[i+1]-X[i] for i in range(M-1)]
    L.sort(reverse=True)
    s=sum([L[i] for i in range(N-1)])
    print(max(X)-min(X)-s)

Measured memory_bytes: 13968
if __name__ == '__main__':
    n, m = list(map(int, input().split(" ")))
    a = [99] * n

    for i in range(m):
        s, c = list(map(int, input().split(" ")))
        if a[s - 1] == 99 or a[s - 1] == c:
            a[s - 1] = c
        else:
            print('-1')
            exit()

    # print(a)

    st = ""
    index = 0
    for j in a:
        if j == 99:
            if index == 0 and len(a) > 1:
                st = st + "1"
            else:
                st = st + "0"
        else:
            st = st + str(j)
        index = index + 1

    if st[0] == '0' and len(st) > 1:
         print('-1')
         exit()

    print(int(st))

Measured memory_bytes: 3064
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val a = sc.next().toInt()
    val b = sc.next().toInt()
    println(problem54a(a, b))
}

fun problem54a(a: Int, b: Int): String {
    val a2 = if (a == 1) 14 else a
    val b2 = if (b == 1) 14 else b
    return when {
        a2 > b2 -> "Alice"
        b2 > a2 -> "Bob"
        else -> "Draw"
    }
}

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

typedef pair<int, int> pii;

int N;

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

    for(int i = 1; i <= 3500; i++) {
        for(int j = 1; j <= 3500; j++) {
            if((i + j) * N >= 4 * i * j) continue;
            int t = 4 * i * j - (i + j) * N;
            if(1LL * N * i * j % t) continue;
            printf("%d %d %lld", i, j, 1LL * N * i * j / t);
            return 0;
        }
    }
}


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

int main(){
  string S;
  int max=0;
  int count=0;
  cin >> S;
  for(int i=0;i<S.length();i++){
    if(S[i]=='A' || S[i]=='T' || S[i]=='G' || S[i]=='C'){
      count++;
      if(max<count)
        max=count;
    }
    else{
      count=0;
    }
  }
  printf("%d\n",max);  
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
#define lli long long int
#define REP(i,s,l) for(lli i=s;i<l;i++)
#define DEBUG 0
#define INF (1LL<<50)

signed main(){

	lli a,b,q;
	cin>>a>>b>>q;

	vector<lli> s,t;
	s.resize(a);
	t.resize(b);

	REP(i,0,a)cin>>s[i];
	REP(i,0,b)cin>>t[i];
	REP(i,0,q){
		lli target;
		cin>>target;
		vector<lli> v[2];
		/*targetに近いs2点*/
		auto itr = lower_bound(s.begin(),s.end(),target);
		if(itr!=s.end())v[0].push_back(*itr);
		if(itr!=s.begin())v[0].push_back(*(itr-1));

		itr = lower_bound(t.begin(),t.end(),target);
		if(itr!=t.end())v[1].push_back(*itr);
		if(itr!=t.begin())v[1].push_back(*(itr-1));
		
		lli ans=INF;
		for(auto e0:v[0])for(auto e1:v[1]){
			ans = min(ans,min(abs(target-e0)+abs(e0-e1), abs(target-e1)+abs(e1-e0)));
		}
		cout<<ans<<endl;
	}

	return 0;
}

Measured memory_bytes: 2944
#include <iostream>

using namespace std;


int main()
{
    string s;
    cin>>s;
    if (s=="Sunny"){
    cout << "Cloudy" << endl;
    }
    else if (s=="Cloudy"){
    cout << "Rainy" << endl;
    }
    else{
    cout << "Sunny" << endl;

    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <functional>
#include <algorithm>
#include <string>
#include <map>
#include <cmath>

using namespace std;


int main()
{
    int N, p;

    cin >> N;

    int a[20005];
    int b[20005];

    for (int i = 0; i < N;i++)
    {
        int p;
        cin >> p;
        a[p - 1] = 20000 * p + 1 + i;
        b[p - 1] = 4 * pow(10, 8) - 20000 * p + 1;
    }

    for (int i = 0; i < N;i++)
    {
        cout << a[i];
        if(i == N-1)
        {
            cout << endl;
        }
        else
        {
            cout << ' ';
        }
    }
    for (int i = 0; i < N; i++)
    {
        cout << b[i];
        if (i == N-1)
        {
            cout << endl;
        }
        else
        {
            cout << ' ';
        }
    }

    return 0;
}


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

long long solve(long long N, long long X){
  //fprintf(stderr,"solve(%lld,%lld)\n",N,X);
  long long ret = X + (N-X)/X*2*X;
  long long r = (N-X)%X;
  if(r) ret += X + solve(X,r);
  return ret;
}

int main(){
  long long N, X;
  cin >> N >> X;
  if(X > N-X) X = N-X;
  cout << solve(N-X,X) + N << endl;
}


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

using namespace std;

int main() {
	int h, w;
	int k, l;
	cin >> h >> w;
	vector<string> c(h);

	for (int i = 0; i < h; i++) {
		cin >> c[i];
	}
	//cout << "\n";
	for (int i = 0; i < 2 * h; i++) {
		for (int j = 0; j < w; j++) {
			k = i / 2;
			l = j;
			switch (c[k][l]) {
			case '*':
				cout << '*';
				break;
			case '.':
				cout << '.';
				break;
			}
		}
		cout << "\n";
	}
	return 0;
}

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

int check(int A){
	if(1<=A && A<=9) return A;
	if(10<=A && A<=99)return A%10+A/10;
	if(100<=A && A<=999)return A%10+(A/10)%10+A/100;
	if(1000<=A && A<=9999)return A%10+(A/10)%10+(A/100)%10+A/1000;
	if(10000<=A && A<=99999)return A%10+(A/10)%10+(A/100)%10+(A/1000)%10+A/10000;
	else return 0;
}

int main(){
	int N,A,B,min=1000000,sum;
	cin >> N;
	for(int A=1;A<N/2+1;A++){
		B=N-A;
		sum=check(A)+check(B);
		if(min>sum)min=sum;
	}
	cout<<min<<endl;
	return 0;
}

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

int main(){
    string s;	cin >> s;
    int abc[26] = {0};
    bool ok=false;
    rep(i, s.size()){
	abc[s[i]-'a']++;
    }
    rep(i, 26){
	if(abc[i] > 1)	ok=true;
    }
    if(ok){
	cout << "no" << endl;
    }else{
	cout << "yes" << endl;
    }
}


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

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

typedef long long ll;
typedef pair<int, int> P;

const int MAX = 1e5 + 5;
const int INF = 1001001001;
const int MOD = 1e9 + 7;

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

    vector<int> P(N), Q(N);
    rep(i, N) cin >> P[i];
    rep(i, N) cin >> Q[i];

    vector<int> V(N);
    rep(i, N) V[i] = i + 1;

    int a = 1;
    do {
        if (V == P) break;
        a++;
    } while (next_permutation(V.begin(), V.end()));

    sort(V.begin(), V.end());
    int b = 1;
    do {
        if (V == Q) break;
        b++;
    } while (next_permutation(V.begin(), V.end()));

    cout << abs(a - b) << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main()
{
  int n,i,j,tarop=0,hanakop=0;
  char taro[100],hanako[100];
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%s %s",taro,hanako);
    if(strcmp(taro,hanako)==0){
      tarop++;
      hanakop++;
    }
    if(strcmp(taro,hanako)>0){
      tarop+=3;
    }
    if(strcmp(taro,hanako)<0){
      hanakop+=3;
    }
  }
  printf("%d %d\n",tarop,hanakop);
  return 0;
}
            

Measured memory_bytes: 1032
#include<bits/stdc++.h>
using namespace std;
static const int N=100;
static const int WHITE=0;
static const int GRAY=1;
static const int BLACK=2;

int n,M[N][N];
int color[N],d[N],f[N],tt;
int nt[N];

int next(int u) {
    for(int v=nt[u];v<n;v++) {
        nt[u]=v+1;
        if(M[u][v]) return v;
    }
    return -1;
}

void dfs_visit(int r) {
    for(int i=0;i<n;i++) nt[i]=0;

    stack<int> S;
    S.push(r);
    color[r]=GRAY;
    d[r]=++tt;

    while(!S.empty()) {
        int u=S.top();
        int v=next(u);
        if(v!=-1) {
            if(color[v]==WHITE) {
                color[v]=GRAY;
                d[v]=++tt;
                S.push(v);
            }
        } else {
            S.pop();
            color[u]=BLACK;
            f[u]=++tt;
        }
    }
}

void dfs() {
    for(int i=0;i<n;i++) {
        color[i]=WHITE;
        nt[i]=0;
    }
    tt=0;

    for(int u=0;u<n;u++) {
        if(color[u]==WHITE) dfs_visit(u);
    }
    for(int i=0;i<n;i++) {
        cout<<i+1<<" "<<d[i]<<" "<<f[i]<<endl;
    }
}

int main() {
    int u,k,v;

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

    for(int i=0;i<n;i++) {
        cin>>u>>k;
        u--;
        for(int j=0;j<k;j++) {
            cin>>v;
            v--;
            M[u][v]=1;
        }
    }
    dfs();
    return 0;
}

Measured memory_bytes: 3116
/*
    Author: zxy_hhhh
    date: 2020/03/12
*/
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<set>
#include<vector>
#include<map>
#include<queue>
#include<iostream>
#define ll long long
inline ll rd() {
    ll _x=0;int _ch=getchar(),_f=1;
    for(;!isdigit(_ch)&&(_ch!='-')&&(_ch!=EOF);_ch=getchar());
    if (_ch=='-'){_f=0;_ch=getchar();}
    for(;isdigit(_ch);_ch=getchar()) _x=_x*10+_ch-'0';
    return _f?_x:-_x;
}
void write(ll _x){if (_x>=10) write(_x/10),putchar(_x%10+'0'); else putchar(_x+'0'); }
inline void wrt(ll _x,char _p){if (_x<0) putchar('-'),_x=-_x; write(_x); if (_p) putchar(_p);}
#define maxn 100005
#define MAX 2170
#define MAXS 10000000000
int n;
ll a[maxn];
int pri[maxn],tp;
ll pw[maxn];
bool vis[maxn];
std::map<ll,std::pair<ll,int> > mp;
int main() {
    n=rd();
    for(int i=1;i<=n;i++) {
        a[i]=rd();
    }
    for(int i=2;i<=MAX;i++) {
        if (!vis[i]) pri[++tp]=i,pw[tp]=1ll*i*i*i;
        for(int j=1;j<=tp&&i*pri[j]<=MAX;j++) {
            vis[i*pri[j]]=1;
            if (i%pri[j]==0) break;
        }
    }
    for(int i=1;i<=n;i++) {
        for(int j=1;j<=tp;j++) {
            while(a[i]%pw[j]==0) a[i]/=pw[j];
        }
        if (!mp.count(a[i])&&a[i]>1) {
            ll x=a[i],y=1;
            for(int j=1;j<=tp;j++) if (x%pri[j]==0){
                if (x%(pri[j]*pri[j])==0) {
                    y*=pri[j],x/=pri[j]*pri[j];
                }
                else y*=pri[j]*pri[j],x/=pri[j];
                if (y>MAXS) y=0;
            }
            if (x>1) {
                if (y<=MAXS/x/x) {
                    y*=x*x;
                }
                else {
                    ll T=sqrt(x);
                    if (T*T==x) {
                        if (y*T<=MAXS)
                            y*=T;
                        else 
                            y=0;
                    }
                    else y=0;
                }
            }
            mp[a[i]].first=y;
        }
        mp[a[i]].second++;
    }
    // for(int i=1;i<=n;i++) {
    //     printf("%lld\n",a[i]);
    // }
    int ans=0;
    mp[1].second=(bool)mp[1].second;
    for(auto i:mp) {
        ans+=std::max(i.second.second,mp[i.second.first].second);
        mp[i.first].second=0;
        mp[i.second.first].second=0;
    }
    wrt(ans,'\n');
}

Measured memory_bytes: 11264
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <random>

using namespace std;

// #define int long long

const int N = 3002;
const int MOD = 998244353;

typedef long long ll;

int add(int a, int b) {
	// assert(a < MOD);
	// assert(b < MOD);
	if (a + b >= MOD) {
		return a + b - MOD;
	} else {
		return a + b;
	}
}

int mul(int a, int b) {
	return ((ll)a * b) % MOD;
}

vector<vector<int>> calc(vector<int> &a) {
	int n = (int)a.size();
	vector<vector<int>> dp(n + 1, vector<int> (N));
	dp[0][0] = 1;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < N; j++) {
			if (j + a[i] < N) {
				dp[i + 1][j + a[i]] = add(dp[i + 1][j + a[i]], dp[i][j]);
			}
			dp[i + 1][j] = add(dp[i + 1][j], dp[i][j]);
		}
	}
	vector<vector<int>> rdp(n + 1, vector<int> (N));
	for (int i = 1; i <= n; i++) {
		for (int j = 0; j < N; j++) {
			if (j >= a[i - 1]){
				rdp[i][j] = dp[i - 1][j - a[i - 1]]; 
			}
		}
	}
	rdp[0][0] = 1;
	return rdp;
}

int n, s;
int a[N];

int solve(int l, int r) {
	if (l == r) {
		return 0;
	}
	if (l + 1 == r) {
		if (a[l] == s) {
			return (l + 1) * (n - l);
		} else {
			return 0;
		}
	}
	int m = (r + l) >> 1;
	int ans = 0;
	ans = add(ans, solve(l, m));
	ans	= add(ans, solve(m, r));
	vector<int> x, y;
	for (int i = l; i < r; i++) {
		if (i < m) x.push_back(a[i]);
		else y.push_back(a[i]);
	}
	reverse(x.begin(), x.end());
	auto fdp = calc(x);
	auto sdp = calc(y);
	vector<int> tsum(s);
	for (int fs = 0; fs < s; fs++) {
		if (s - fs >= N) continue;
		int c = 0;
		for (int j = m; j < r; j++) {
			c = add(c, mul(sdp[j - m + 1][s - fs], (n - j)));
		}
		tsum[fs] = c;
	}
	for (int i = l; i < m; i++) {
		for (int fsum = 1; fsum < s; fsum++) {
			int ml = mul((i + 1), fdp[m - i][fsum]);
			int c = tsum[fsum];
			ans = add(ans, mul(c, ml));
		}
	}
	return ans;
}

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

	cin >> n >> s;
	// n = 100;
	// s = 10;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		// a[i] = 1;
	}
	int ans = solve(0, n);
	cout << ans << endl;
	// vector<int> b = {1, 5};
	// calc(b);
} 


Measured memory_bytes: 53240
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <string>
#include <iomanip>
#include <map>
#include <set>
#include <cmath>
#include <cstdio>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define All(v) (v).begin(),(v).end()
typedef long long ll;

int D;
int dist(vector<int> a,vector<int> b){
    int ret = 0;
    rep(i,D){
        ret+=(a[i]-b[i])*(a[i]-b[i]);
    }
    return ret;
}

int main(){
    int N;
    cin >> N >> D;
    vector<vector<int> > X(N,vector<int>(D));
    rep(i,N){
        rep(j,D)cin >> X[i][j];
    }
    vector<int> d;
    rep(i,N){
        for(int j=i+1;j<N;j++){
            d.push_back(dist(X[i],X[j]));
        }
    }

    int res = 0;
    for(auto x:d){
        rep(i,1000){
            if(x==i*i){
                //cout << x << endl;
                res++;
                break;
            }
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iostream>
#include <iostream>
#include <fstream>
#include <numeric>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <cmath>
#include <set>
#include <map>
#include <functional>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
using namespace std;
#define ll           long long
#define all(v)       (v).begin() , (v).end()
#define vi           vector <ll>
#define vii          vector <pair<ll,ll>>
#define ii           pair<ll,ll>
#define sz(v)	     ((int)((v).size()))
#define lp(i,a,b)    for(int i=a;i<b;i++)
#define pb           push_back
#define pf           push_front
#define F            first
#define S            second
#define endl         "\n"
#define IOS          ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const double PI = 3.14159265358979323846;
const ll inf=2e9,MOD=998244353,MAX=1e2+2;

int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    IOS;
    int n,m,k;
    cin>>n>>m>>k;
    int a[n],b[m],x=1e9,y=1e9;
    lp(i,0,n)
        cin>>a[i],x=min(x,a[i]);
    lp(i,0,m)
        cin>>b[i],y=min(y,b[i]);
    int res=x+y;
    lp(i,0,k){
        int x,y,z;
        cin>>x>>y>>z;
        x--,y--;
        res=min(res,a[x]+b[y]-z);
    }
    cout<<res;
}

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

typedef long long ll;
typedef long double ld;
typedef double db;
typedef string str;

typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef pair<db,db> pd;

typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<db> vd;
typedef vector<str> vs;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<pd> vpd;

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b) - 1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define rb(i,x) for (auto& i : x)

#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define UNIQUE(x) (x).resize(unique(all(x)) - begin(x))

#define mp make_pair
#define pb push_back
#define eb emplace_back
#define F first
#define S second

#define pow10(n) stoll("1"+string(n,'0'))

#define debug(x) cout << ">>> " << #x << ": " << x << '\n'

const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll LNF = 1e18;

void setIO(string s) {
	ios_base::sync_with_stdio(0); cin.tie(0);
#ifndef ONLINE_JUDGE
	freopen((s+".in").c_str(),"r",stdin);
//	freopen((s+".out").c_str(),"w",stdout);
#endif
}

int main() {
    
    setIO("input");
    int l,r,d; cin >> l >> r >> d;
    int ldiv = (l+d-1) / d;
    int rdiv = r / d;
    cout << rdiv - ldiv + 1;
    
}

/*  ! CHECK THIS IF YOU GET IT WRONG !
	* int overflow, array bounds, NO VLAs
	* uninitialized local variables, rounding errors
	* intermediate result type, scientific
	* special cases (n = 0 or 1?)
	* reset your variables in scope
	* INF not large enough for ans, adding value to _MAX
	* using wrong variables, sorting extra 0s in global array
	* comment out input from file
	* operator precedence
*/

Measured memory_bytes: 3592
n,k = list(map(int,input().split()))
A = list(map(int,input().split()))

if k == 1:exit(print(A[0]))
t = 0
dp = [-1] * n
dp[0] = 0
flg = 0
for i in range(1,k+1):
  t = A[t]-1
  if dp[t] != -1:
    flg = 1
    break
  dp[t] = i
if flg == 0:
  exit(print(t+1))
elif k == 2:
  exit(print(t+1))

l = i - dp[t]
K = (k-dp[t])%l + dp[t]

for i in range(n):
  if dp[i] == K:exit(print(i+1))




Measured memory_bytes: 32352
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.PriorityQueue;
import java.util.Scanner;

class Main {
    static final int MOD = 1000000007;
    static final int INF = 1 << 30;

    Main() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        ArrayList<Integer> list = new ArrayList<Integer>(N);
        for (int i = 0; i < N; i++) {
            list.add(sc.nextInt());
        }
        Collections.sort(list,Comparator.reverseOrder());
        int a=0;
        int b = 0;
        for(int i=0;i<N;i++){
            if(i%2==0)a+=list.get(i);
            else b+=list.get(i);
        }
        System.out.println(a-b);
    }

    public static void main(String[] args) {
        new Main();
    }
}


Measured memory_bytes: 22736
#include<stdio.h>

int main(){
  int loan=100000;
  double d = 1.05;
  int n,i,temp;
  scanf("%d", &n);
  for(i=0;i<n;i++){
      loan = (double)loan * d;
      temp = loan%1000;
      if(temp != 0){
        loan = loan - temp + 1000;
      }
  }
  printf("%d\n",loan);

  return 0;
}



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

int main()
{
    
    string s1;
    getline( cin, s1 );
    int n1 = s1.size();

    //int n;
    //cin >> n >> n ;
    string n = s1.substr( n1-1, 1 );
    
    
    if( n == "2" || n == "4" || n == "5" || n == "7" || n == "9" ){
        cout << "hon" << endl;
    }
    else if( n == "0" || n == "1" || n == "6" || n == "8" ){
        cout << "pon" << endl;
    }
    else if( n == "3" ){
        cout << "bon" << endl;
    }
      
    return 0;
}


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

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

int main() {
  ll n,k;
  cin >> n >> k;
  int i = 0;
  while (pow(k, i) <= n) {
    i++;
  }
  cout << i << endl;
}


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

int main(){
	int N;
  	cin >> N;
  	int hun = N / 100;
  	int ten = (N - hun * 100)/10;
  	int one = (N - hun * 100)%10;
  	if(hun > ten){
      	ten =hun;
      	one =hun;
    }
  	else if(hun == ten){
    	if(ten > one){
          	ten = hun;
          	one = hun;
        }
      	else if(ten < one){
          	hun++;
        	ten =hun;
          	one =hun;
        }
    }
    else if(hun < ten){
      	hun++;
    	ten = hun;
      	one = hun;
    }
    cout << hun << ten <<one;
    return 0;
  	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
const ll mod = 1e9+7;
#define rep(i,n) for(int i = 0;i<n;i++)

int main(){
	string s,t;
	cin >> s >> t;
	rep(i,s.size()){
		if(s[i] != t[i]){
			cout << "No\n";
			return 0;
		}
	}
	cout << "Yes\n";


	return 0;
}

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define REP(i,n) for(int i=0;i<n;i++)
#define pb push_back


// vectorの中身をcout << vs;で表示
template <class T>
ostream &operator<<(ostream &o, const vector<T> &v)
{
    o << "{";
    for (int i = 0; i < (int)v.size(); i++) o << (i > 0 ? ", " : "") << v[i];
    o << "}";
    return o;
}

int main(void) {
	// cin, coutの結びつきを解除し、速くする
	cin.tie(0);
   	ios::sync_with_stdio(false);

	int n; cin >> n;

	bool buyable = false;
	if (n % 7 == 0) {
		Yes;
		return 0;
	}
	REP(i, n%7+1) {
		if ((n - 7 * i) >= 0 && (n - 7 * i) % 4 == 0) {
			buyable = true;
			break;
		}
	}
	buyable?Yes:No;
}



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

b=0
count=0
while b==0:
  for i in range(n):
    if a[i]%2==1:
      b=1
      break
    else:
      a[i]=a[i]//2
  if b==0:
    count+=1
print(count)

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;

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

    int n = (int)s.size();
    int a = 0;

    int *c = (int *)calloc(1 << 26, 4);
    c[0] = 1;

    for (int i = 0; i < n; i++) {
        a ^= 1 << (s[i] - 'a');
        int m = n;
        for (int k = 1 << ('z' - 'a');; k >>= 1) {
            int t = c[a ^ k];
            if (t != 0 && t < m) m = t;

            if (k == 0) break;
        }

        if (i == n - 1) cout << m << endl;
        m++;

        c[a] = c[a] == 0 ? m : min(c[a], m);
    }

    return 0;
}

Measured memory_bytes: 262404
#include <bits/stdc++.h>
// #pragma GCC optimize ("O3")
// #pragma GCC target ("sse4")
using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> PII;

#define REP(i,n) for(int i=0;i<(n);++i)
#define FOR(i,a,b) for (int i=(a); i<(b); ++i)
#define FORD(i,a,b) for (int i=(a)-1; i>=(b); --i)

#define pb push_back
#define mp make_pair
#define st first
#define nd second

const int MOD = 1000000007;

int A[105];

int main() {
  // ios_base::sync_with_stdio(0);

  int K = 1000;
  int N;
  scanf("%d", &N);
  REP(i,N) scanf("%d", &A[i]);
  int result = 0;
  FOR(i,1,N) {
    if (A[i] == A[i-1]) {
      A[i] = K++;
      ++result;
    }
  }
  printf("%d\n", result);
}


Measured memory_bytes: 256
N, A, B = list(map(int, input().split()))
S = input()
a_cnt = 0
b_cnt = 0
ab_cnt = 0

for c in S:
    if c == 'a':
        if ab_cnt < A+B:
            print('Yes')
            a_cnt += 1
            ab_cnt += 1
        else:
            print('No')
    elif c == 'b':
        if ab_cnt < A+B and b_cnt < B:
            print('Yes')
            b_cnt += 1
            ab_cnt += 1
        else:
            print('No')
    else:
        print('No')

Measured memory_bytes: 4016
#include <bits/stdc++.h>
using namespace std;
using pii=pair<int,int>;
using ll=long long;

#define fi first
#define se second
#define pb push_back
#define rep(i,n) for(int i=0; i<(int)(n); i++)

ll dp[101][100010];
ll LINF = 1e18;

int main() {
	int n;
	ll capacity;
	cin >> n >> capacity;
	vector<ll> w(n);
	vector<int> v(n);
	rep(i,n) {
		cin >> w[i] >> v[i];
	}
	rep(j,100010) {
		dp[0][j] = LINF;
	}
	rep(i,n) rep(j,100010) {
		if (i == 0) {
			dp[0][v[0]] = w[0];
			dp[0][0] = 0;
		}
		else {
			if (j >= v[i]) {
				dp[i][j] = min(dp[i - 1][j - v[i]] + w[i], dp[i - 1][j]);
			}
			else {
				dp[i][j] = dp[i-1][j];
			}
		}
	}
	ll maxi=-1;
	rep(j,100010) {
		if(dp[n-1][j] <= capacity) {
			maxi = maxi > j ? maxi : j;
		}
	}
	cout << maxi << endl;

  return 0;
}


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

int main(){
    int x[5];
    int ans=0;
    for(int i=0;i<5;i++){
        cin >> x[i];
        if(x[i]==0){
            ans = i+1;
        }
    }

    cout << ans << endl;

}

Measured memory_bytes: 3544
def dst(Xi, Xj):
  S = 0
  for i in range(len(Xi)):
    S += (Xi[i] - Xj[i]) ** 2
  return S

def isz(X):
  c = 0
  while c ** 2 < X:
    c += 1
  if c ** 2 == X:
    return True
  else:
    return False


N, D = map(int, input().split())
X = []
s = 0
for i in range(N):
  X.append([int(i) for i in input().split()])

for i in range(N):
  for j in range(i, N):
    if i != j and isz(dst(X[i], X[j])):
      s += 1
print(s)

Measured memory_bytes: 3064
#include <iostream>
#include<map>
#include<vector>
#include<algorithm>
#include <stdio.h>
#include<set>
#include<string>
#include<math.h>
#include<cmath>
#include<iomanip>
#include<queue>
#include<stack>
#define ll long long
using namespace std;
long double pi = 3.14159265358979323846;
#define fast ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);




int main() {
	ll n, m;
	cin >> n>>m;
	
	cout << (n * (n - 1)) / 2 + (m * (m - 1)) / 2;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,h[200],ans=0;
signed main(){
    cin>>n;
    for(int i=0;i<n;i++)cin>>h[i];
    h[n]=0;
    for(int i=0;i<n;i++){
        ans+=max(0,h[i]-h[i+1]);
    }
    cout<<ans<<endl;
    return 0;
} 

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

char a[503][503];
char r[503][503];
char b[503][503];

int main()
{
    int h, w;
    cin >> h >> w;
    for(int i = 0; i < h; i++) for(int j = 0; j < w; j++){
        cin >> a[i][j];
        r[i][j] = a[i][j];
        b[i][j] = a[i][j];
    }
    for(int k = 0; k < (min(h, w) + 1) / 2; k++){
        for(int j = k; j < w - k; j++){
            if(k % 2){
                b[k][j] = b[h - k - 1][j] = '#';
            }
            else{
                r[k][j] = r[h - k - 1][j] = '#';
            }
        }
        for(int i = k; i < h - k; i++){
            if(k % 2){
                b[i][k] = b[i][w - k - 1] = '#';
                if(k == (min(h, w) - 1) / 2) continue;
                if(k % 4 == 1 && a[h / 2][k] == '.'){
                    r[h / 2][k] = '#';
                    b[h / 2][k] = '.';
                }
                if(k % 4 == 3 && a[k][w / 2] == '.'){
                    r[k][w / 2] = '#';
                    b[k][w / 2] = '.';
                }
            }
            else{
                r[i][k] = r[i][w - k - 1] = '#';
                if(k == (min(h, w) - 1) / 2) continue;
                if(k % 4 == 0 && a[h / 2][w - 1 - k] == '.'){
                    b[h / 2][w - 1 - k] = '#';
                    r[h / 2][w - 1 - k] = '.';
                }
                if(k % 4 == 2 && a[h - 1 - k][w / 2] == '.'){
                    b[h - 1 - k][w / 2] = '#';
                    r[h - 1 - k][w / 2] = '.';
                }
            }
        }
    }
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++) cout << r[i][j];
        cout << endl;
    }
    cout << endl;
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++) cout << b[i][j];
        cout << endl;
    }
}

Measured memory_bytes: 1536
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstdio>
#include <iomanip>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <stdlib.h>
#include <set>
typedef long long ll;
using namespace std;

int main() {
	int x, y, sum = 0;
	cin >> x;
	if (x == 1) {
		sum += 300000;
	} else if (x == 2) {
		sum += 200000;
	} else if (x == 3) {
		sum += 100000;
	}
	cin >> y;
	if (y == 1) {
		sum += 300000;
	} else if (y == 2) {
		sum += 200000;
	} else if (y == 3) {
		sum += 100000;
	}
	if(x==1&&y==1){
		sum+=400000;
	}
	cout << sum << endl;
	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	int n; cin >> n;
	if(n == 3){
		cout << "2 5 63" << endl;
		exit(0);
	}
	
	vi ans;
	ll sum = 0;
	for(int i = 1; ans.size() < n; i++) if(__gcd(6, i % 6) != 1){
		ans.pb(i);
		sum += i;
	}
	
	rep(i, 100) rep(j, 100) if(ans[n - 2] + i != ans[n - 1] + j){
		if(__gcd(6, (ans[n - 2] + i) % 6) == 1) continue;
		if(__gcd(6, (ans[n - 1] + j) % 6) == 1) continue;
		if((sum + i + j) % 6) continue;
		
		ans[n - 2] += i;
		ans[n - 1] += j;
		i = 100; break;
	}
	rep(i, n) cout << ans[i] << (i==n-1?"\n":" ");
	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;cin>>n;
  int l[n],r[n];
  long long sum=0;
  for(int i=0;i<n;i++){
    cin>>l[i]>>r[i];
    sum+=r[i]-l[i]+1;
  }
  cout<<sum<<endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        
        Scanner sc = new Scanner(System.in);
        
        int a = sc.nextInt();
        int b = sc.nextInt();
        
        
        
        System.out.println(a*b+" "+2*(a+b));
    }
}


Measured memory_bytes: 26172
#include <stdio.h>
#include <math.h>

int isPrime(int);

int main(){
    int n, num, a, count=0;
    scanf("%d",&n);

    for(a = 0; a < n; a++){
        scanf("%d",&num);
        if(isPrime(num) == 1) count++;
    }

    printf("%d\n",count);
    return 0;
}

int isPrime(int num){
    int a;
    if(num == 2) return 1;
    else if(num < 2 || num%2 == 0) return 0;
    for(a = 3; a <= sqrt(num); a+=2){
        if(num%a == 0) return 0;
    }
    return 1;
}



Measured memory_bytes: 2084
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s[110];
    int n,l;
    scanf("%d%d",&n,&l);
    for(int i=0; i<n; i++)
    {
        cin>>s[i];
    }
    sort(s,s+n);
    for(int i=0; i<n; i++)
        cout<<s[i];
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int N, K, X, Y;
    scanf("%d%d%d%d",&N,&K,&X,&Y);
    int ans = 0;
    for(int i=0; i<N; ++i)
        if(i<K) ans += X;
        else ans += Y;
    printf("%d\n", ans);
}

Measured memory_bytes: 256
import java.awt.Point;
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int h = sc.nextInt();
        int w = sc.nextInt();
        char[][] s = new char[h][w];
        for (int i = 0; i < h; i++) {
            s[i] = sc.next().toCharArray();
        }
        int ans = 0;
        final int[][] DXDY = { { 1, 0 }, { 0, 1 }, { -1, 0 }, { 0, -1 } };
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                if (s[i][j] == '#') {
                    continue;
                }
                int depth = -1;
                Deque<Point> queue = new ArrayDeque<>();
                queue.add(new Point(i, j));
                boolean[][] visited = new boolean[h][w];
                visited[i][j] = true;
                while (!queue.isEmpty()) {
                    int size = queue.size();
                    depth++;
                    for (int k = 0; k < size; k++) {
                        Point p = queue.poll();
                        int posx = p.x;
                        int posy = p.y;
                        for (int l = 0; l < DXDY.length; l++) {
                            int x = posx + DXDY[l][0];
                            int y = posy + DXDY[l][1];
                            if (x < 0 || x >= h || y < 0 || y >= w || s[x][y] == '#' || visited[x][y]) {
                                continue;
                            }
                            visited[x][y] = true;
                            queue.add(new Point(x, y));
                        }
                    }
                }
                ans = Math.max(ans, depth);
            }
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 25016
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cstring>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <stack>
#include <cmath>
#define ll long long
#define LINF 0x3f3f3f3f3f3f3f3f
#define INF 0x3f3f3f3f
using namespace std;
const int MAX = 1e5 + 10;
const ll MOD = 1e9 + 7;
int K, Q;
ll N, M;

int main()
{
	int i, j, k;
	scanf("%lld%lld", &N, &M);
	if (abs(N - M) > 1) {
		printf("0");
		return 0;
	}
	ll cnt = 1;
	for (ll x = 1; x <= N; ++x) cnt = cnt * x % MOD;
	for (ll x = 1; x <= M; ++x) cnt = cnt * x % MOD;
	if(N == M) cnt = cnt * 2 % MOD;
	printf("%lld", cnt);
	

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std; 
typedef long long int ll;
 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n;
    cin >> n;
    ll a, b;
    cin >> a >> b;
    ll diff = abs(b - a);
    ll ans = 0;
    if(diff % 2 == 0)
    {
        ans = diff / 2;
    }
    else
    {
        ll left = a - 1;
        ll right = n - b;
        ans = min(left, right) + (b - a + 1) / 2;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define LL long long
#define LD long double
#define pb push_back
#define mp make_pair
#define ss(x) (int) x.size()
#define fi first
#define se second
#define cat(x) cerr << #x << " = " << x << endl
#define rep2(i, j, n) for (LL i = j; i <= n; ++i)
#define rep(i, j, n) for (int i = j; i <= n; ++i)
#define per(i, j, n) for (int i = n; j <= i; --i)
#define boost cin.tie(0);ios_base::sync_with_stdio(0);
#define vi vector <int>

using namespace std;			

const int N = 1e5 + 110;

int a, b, m;
int t[N], d[N];
int best = 1e9;
int x, y, z;

int main() {	
	scanf ("%d%d%d", &a, &b, &m);
	int m1 = 1e9, m2 = 1e9;
	rep(i, 1, a) {scanf ("%d", t + i); m1 = min(m1, t[i]);}
	rep(i, 1, b) {scanf ("%d", d + i); m2 = min(m2, d[i]);}
	rep(i, 1, m) {
		scanf ("%d%d%d", &x, &y, &z);
		best = min(best, t[x] + d[y] - z);
	}	
	best = min(best, m1 + m2);
	printf ("%d\n", best);
	
	
	
	return 0;
}


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

int main(){
  int A,B,C,D,L,R;
  cin >> A >> B >> C >> D;
  L = A + B,R = C + D;
  if(L > R){
    cout << "Left" << endl;
  }
  else if(L==R){
    cout << "Balanced" << endl;
  }
  else{
    cout << "Right" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>

using ll = long long int;

const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

int main(void){
	int n,i;
	ll a,k,g=0ll,b;
	std::cin >> n;
	for(i=0; i<n; ++i){
		std::cin >> a >> k;
		while(a%k && a/k){
			b = (a-k*(a/k)+(a/k))/((a/k)+1);
			a -= ((a/k)+1)*b;
		}
		g ^= a/k;
	}
	std::cout << ((g)?"Takahashi":"Aoki") << std::endl;
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const ll MOD = 1000000007;

int V;
vector<vector<int>> G;
vector<int> match;
vector<bool> used;

void add_edge(int u, int v){
    G[u].push_back(v);
    G[v].push_back(u);
}

bool dfs(int v){
    used[v] = true;
    for(int i = 0; i < G[v].size(); i++){
        int u = G[v][i];
        int u_pair = match[u];
        if(u_pair < 0 || !used[u_pair] && dfs(u_pair)){
            match[v] = u;
            match[u] = v;
            return true;
        }
    }
    return false;
}

int bipartite_matching(){
    int res = 0;
    match.assign(V, -1);
    for(int v = 0; v < V; v++){
        if(match[v] < 0){
            used.assign(V, false);
            if(dfs(v)){
                res++;
            }
        }
    }
    return res;
}

int main(){
    while(true){
        int m, n;
        cin >> m >> n;
        if(m == 0) break;

        vector<int> b(m), r(n);
        for(int i=0;i<m;i++){
            cin >> b[i];
        }
        for(int i=0;i<n;i++){
            cin >> r[i];
        }

        V = n + m;
        G.assign(V, {});

        for(int i=0;i<m;i++){
            for(int j=0;j<n;j++){
                if(__gcd(b[i], r[j]) != 1){
                    add_edge(i, j + m);
                }
            }
        }

        cout << bipartite_matching() << endl;
    }

    return 0;
}

Measured memory_bytes: 5092
s = input()
a = 'abcdefghijklmnopqrstuvwxyz'

if len(s) < 26:
    for w in a:
        if not w in s:
            print(s + w)
            exit()

if len(s) == 26:
    for i in range(len(s)-2, -1, -1):
        for j in range(len(s)-1, i, -1):
            if s[i] < s[j]:
                print(s[:i]+s[j])
                exit()

print('-1')

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

#define REP(i, n) for(int (i)=0;(i)<(n);++(i))
#define MOD 1000000007

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

int main()
{
    int H, W, D;
    cin >> H >> W >> D;
    map<int, P> aMap;
    REP(i, H)
    {
        REP(j, W)
        {
            int a;
            cin >> a;
            aMap[a] = P(i + 1, j + 1);
        }
    }

    int Q;
    cin >> Q;
    int L[Q], R[Q];
    REP(i, Q)
    {
        cin >> L[i] >> R[i];
    }


    int dSum[H * W + 1] = {0};
    REP(i, H * W + 1)
    {
        if (i - D >= 1)
        {
            int xN, yN, xP, yP;
            xN = aMap[i].first;
            yN = aMap[i].second;
            xP = aMap[i - D].first;
            yP = aMap[i - D].second;
            dSum[i] += dSum[i - D] + abs(xN - xP) + abs(yN - yP);
        }
        else
        {
            dSum[i] = 0;
        }
    }

    int ans;
    REP(i, Q)
    {
        ans = dSum[R[i]] - dSum[L[i]];
        cout << ans << endl;
    }
}


Measured memory_bytes: 7936
#include <stdio.h>
#include <iostream>
#include <vector>
#include <list>
#include <cmath>
#include <fstream>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <iterator>
#include <cstdlib>
#include <cstring>
#include <sstream>

using namespace std;

#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) (EQ((a).real(),(b).real()) && EQ((a).imag(),(b).imag()))

typedef complex<double> P;
typedef long long ll;

const int MAX_SIZE = 10000;
// OÏ
double cross(P a, P b) {
  return (a.real() * b.imag() - a.imag() * b.real());
}
// a1,a2ð[_Æ·éüªÆb1,b2ð[_Æ·éüªÌð·»è
int is_intersected_ls(P a1, P a2, P b1, P b2) {
    // üªª½sÈêÍdÈÁÄ¢È¢±ÆÉ·é
    if(abs(cross(a2-a1,b2-b1)) < EPS){
        return 0;
    }
    return ( cross(a2-a1, b1-a1) * cross(a2-a1, b2-a1) < EPS ) &&
        ( cross(b2-b1, a1-b1) * cross(b2-b1, a2-b1) < EPS );
}
// a1,a2ð[_Æ·éüªÆb1,b2ð[_Æ·éüªÌð_vZ
P intersection_ls(P a1, P a2, P b1, P b2) {
  P b = b2-b1;
  double d1 = abs(cross(b, a1-b1));
  double d2 = abs(cross(b, a2-b1));
  double t = d1 / (d1 + d2);

  return a1 + (a2-a1) * t;
}

int main(){

    int n;
    while(cin>>n&&n!=0){
        vector<pair<P,P> > lines;
        int sum=1;
        for(int i = 0; i < n; i++){
            int x1,x2,y1,y2;
            cin>>x1>>y1>>x2>>y2;
            P p1(x1,y1);P p2(x2,y2);
            int cnt=1;
            vector<P> v;
            // ¡ñø¢½üÆA¡ÜÅÉø¢½üÆÌð_ð²×é
            for(int j = 0; j < lines.size(); j++){
                // ð·µÄ¢éÈçÎA»Ì_ð²×é
                if(is_intersected_ls(p1,p2,lines[j].first,lines[j].second)){
                    P crossPoint = intersection_ls(p1,p2,lines[j].first,lines[j].second);
                    // àµ³û`ÌÓãÅdÈÁÄ¢éÌÅÈ¯êÎAJEg
                    if(!EQ(crossPoint.real(),100)&&!EQ(crossPoint.real(),-100)
                        &&!EQ(crossPoint.imag(),100)&&!EQ(crossPoint.imag(),-100)){
                            if(find(v.begin(),v.end(),crossPoint)==v.end()){
                                cnt++;
                                v.push_back(crossPoint);
                            }
                    }
                }
            }
            lines.push_back(make_pair(p1,p2));
            sum+=cnt;
        }
        cout<<sum<<endl;
    }

    return 0;
}

Measured memory_bytes: 0