akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cmath>
#define ll long long
using namespace std;
int main()
{
  ll x,y;
  cin >> x >> y;
  ll arr1[x][2];
  ll arr2[y][2];
  for(ll i=0;i<x;i++)
  {
    for(ll j=0;j<2;j++)
      cin >> arr1[i][j];
  }
  for(ll i=0;i<y;i++)
  {
    for(ll j=0;j<2;j++)
      cin >> arr2[i][j];
  }
  ll a,b,q,p;
  for(ll i=0;i<x;i++)
  {
    ll distance=1e10,index=10000,
    a=arr1[i][0];
    b=arr1[i][1];
    for(ll j=0;j<y;j++)
    {
      p=abs(a-arr2[j][0]);
      q=abs(b-arr2[j][1]);
      ll k1 = p+q;
      if(k1<distance)
      {
        distance=k1;
        index=j+1;
      }
    }
    cout << index << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define mod 1000000007
#define pb push_back  


int main()
{
   IOS
   
   ll n,i,j,day;
   cin>>n;
   

   vector<ll>dp(3);
   
   for(day=0;day<n;day++)
   {
   	vector<ll>c(3);
   	for(i=0;i<3;i++)
   	 {cin>>c[i];}
   	 
   	 vector<ll>new_dp(3,0);
   	 for(i=0;i<3;i++)
   	 {
   	 	for(j=0;j<3;j++)
   	 	{
   	 		if(i!=j)
   	 		{
   	 			new_dp[j] = max(new_dp[j],dp[i]+c[j]);
   	 		}
   	 	}
   	 }
   	 dp = new_dp;
   }
   cout<<max({dp[0],dp[1],dp[2]})<<endl;   

}

Measured memory_bytes: 3608
### main

min_pt = min_jc = 2000

3.times do
  pt = gets.strip.to_i
  min_pt = pt if min_pt > pt
end

2.times do
  jc = gets.strip.to_i
  min_jc = jc if min_jc > jc
end

puts (min_pt + min_jc - 50)

Measured memory_bytes: 6092
#include <stdio.h>
#include <stdlib.h>

typedef struct {
	int id, solved, penalty;
} Team;

int compare(const void *a, const void *b) {
	int t;
	const Team ta = *(Team *)a, tb = *(Team *)b;

	t = tb.solved - ta.solved;
	if (t)
		return t;
	else {
		t = ta.penalty - tb.penalty;
		if (t)
			return t;
		else
			return ta.id - tb.id;
	}
}

int main(void) {
	int i;
	int t, p, r;

	while (scanf("%d %d %d", &t, &p, &r), t) {
		Team team[50] = {0};
		int wrong[50][10] = {0};

		for (i = 0; i < t; i++)
			team[i].id = i + 1;

		for (i = 0; i < r; i++) {
			int tid, pid, t;
			char mes[10];

			scanf("%d %d %d %s", &tid, &pid, &t, mes);
			tid--;
			pid--;

			if (mes[0] == 'C') {
				team[tid].solved++;
				team[tid].penalty += wrong[tid][pid] * 1200 + t;
			} else
				wrong[tid][pid]++;
		}

		qsort(team, t, sizeof(Team), &compare);

		for (i = 0; i < t; i++)
			printf("%d %d %d\n", team[i].id, team[i].solved, team[i].penalty);
	}

	return 0;
}

Measured memory_bytes: 612
use std::io::stdin;

fn main() {
    let mut s = String::new();
    stdin().read_line(&mut s).ok();
    let mut itr = s.split_whitespace().map(|e| e.parse().unwrap());
    let x: i8 = itr.next().unwrap();
    let y: i8 = itr.next().unwrap();
    let z: i8 = itr.next().unwrap();

    println!("{} {} {}", z, x, y);
}

Measured memory_bytes: 4352
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int l = in.nextInt();
        in.nextLine();
        String[] a = new String[n];
        //inputs
        for (int i = 0; i <a.length ; i++) {
            a[i]=in.nextLine();
        }
        for (int i = 0; i < a.length - 1; i++) {
            for (int j = i + 1; j < a.length; j++) {
                if (a[i].compareTo(a[j]) > 0) {
                    String tmp = a[i];
                    a[i] = a[j];
                    a[j] = tmp;
                }
            }
        }

        for (int i = 0; i <a.length ; i++) {
            System.out.print(a[i]);
        }




    }
}

Measured memory_bytes: 23252
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cctype>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip>
#include <cstdio>
#include <numeric>
#include <functional>
#include <cstdlib>
#include <regex>
#include <list>
int main() {
	int n, a = 0;
	std::cin >> n;
	std::vector<int>p(n);
	std::vector<int>q(n);
	for (int i = 0;i < n;++i) {
		std::cin >> p[i];
		q[i] = p[i];
	}
	std::sort(p.begin(), p.end());
	for (int i = 0;i < n;++i) {
		if (p[i] != q[i]) {
			a += 1;
		}
	}
	if (a == 2 || a == 0) {
		std::cout << "YES" << std::endl;
	}
	else {
		std::cout << "NO" << std::endl; 
	}
		return 0;
	
}



Measured memory_bytes: 256
import math


def resolve():
    N = int(input())
    x = int(N // 1.08)
    if math.floor(x * 1.08) == N:
        print(x)
    elif math.floor((x + 1) * 1.08) == N:
        print(x + 1)
    else:
        print(":(")


if __name__ == "__main__":
    resolve()

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

int main(){
  	int n;
  	float p;
  	int P=0;
	int t;
  	vector<int> x;
  	int sum=0;
  	cin >> n;
  	for(int i=0;i<n;i++){
    	cin >> t;
      	x.push_back(t);
      	sum+=t;
    }
  	p=(float)sum/(float)n;
  	float s=p-(int)p;
 	if(s>0.5){
    	P=(int)p+1;
    }else{
    	P=(int)p;
    }
  	sum=0;
  	for(int i=0;i<n;i++){
    	sum+=(x[i]-P)*(x[i]-P);
    }
  	cout << sum;
  
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<vector<ll>> VV;

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define rep(i, n) REP(i, 0, n)
const ll INF=1e9;
const ll MAX=100005;
const ll MOD=1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define ALL(v) v.begin(), v.end()
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a,b)
#define Each(a,b) for(auto &a :b)
#define REPM(i, mp) for (auto i = mp.begin(); i != mp.end(); ++i)
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbgmap(mp) cerr << #mp << ":"<<endl; for (auto i = mp.begin(); i != mp.end(); ++i) { cerr << i->first <<":"<<i->second << endl;}
#define dbgarr(n,m,arr) rep(i,n){rep(j,m){cerr<<arr[i][j]<<" ";}cerr<<endl;}
#define dbgdp(n,arr) rep(i,n){cerr<<arr[i]<<" ";}cerr<<endl;
#define sum(v) accumulate(ALL(v),0)
#define fi first
#define se second

template<typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) { return s<<"("<<p.first<<", "<<p.second<<")"; }

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

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    Vec x(n);
    Vec v(n);
    Vec c(n);
    rep(i,n){
        cin>>v[i];
    }
    rep(i,n){
        cin>>c[i];
    }
    rep(i,n){
        x[i]=v[i]-c[i];
    }
    ll ans=0;

    sort(ALL(x),greater<>());
    rep(i,n){
        if(x[i]>0){
            ans += x[i];
        }
    }
    cout<<ans<<endl;
    return  0;
}


Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
#define sz 200005
#define faster_io ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long long ll;

int main()
{
    faster_io;
    int n,m,mx,mn,x,y,ans=1;
    cin>>n>>m>>mx>>mn;

    for(int i=0;i<m-1;i++){
        cin>>x>>y;
        if(x>mn) ans=0;
        mx = max(mx,x);
        mn = min(mn,y);
    }

    if(ans) ans = mn-mx+1;
    cout<<ans<<endl;
    return 0;
}





Measured memory_bytes: 256
/**
DufauX-XuafuD
**/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define FastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define reset(x) memset(x,-1,sizeof(x))
#define CheckBit(a,b) (a&(1ll<<b))
#define SetBit(a,b) a=(a|(1ll<<b))
#define UnSetBit(a,b) a=(a&(~(1ll<<b)))
#define maxx 10000006
#define PI 2*acos(0.0)
const long long INF = 2000000000000000000LL;	// 2e18
const int inf = 0x3f3f3f3f;	// 1061109567
const long double EPS = 1e-9;
//bitset<maxx/2>vis;
//bitset<maxx>pr;
//int mobi[maxx+10];
//vector<ll>prime;
//void sieve(){
//    ll x=maxx/2, y=sqrt(maxx)/2;
//    for(ll i=1;i<=y;i++){
//        if(vis[i]==0){
//            for(ll j=(i*(i+1)*2);j<x;j+=(2*i)+1)
//                vis[j]=1;
//        }
//    }
//    prime.push_back(2);
//    for(ll i=3;i<maxx;i+=2)
//        if(vis[i/2]==0)
//        prime.push_back(i);
//}
//void generate_mobius()
//{
//    for(int i=0;i<maxx;i++)mobi[i]=1;
//    for(int i=2;i<maxx;i++){
//        if(!pr[i]){
//            mobi[i]*=-1;
//            for(int j=i+i;j<maxx;j+=i){
//                pr[j]=1;
//                mobi[j]*=(j%(i*i)?-1:0);
//            }
//        }
//    }
//}
//bool isprime(ll a)
//{
//    if(a==1)return false;
//    if(a==2)return true;
//    if(a%2==0)return false;
//    for(ll i=0;i<prime.size() && prime[i]*prime[i]<=a;i++)
//        if(a%prime[i]==0)return false;
//    return true;
//}
/* Calculate ( a*b ) %c */
inline ll mulmod(ll a, ll b, ll c) {
    ll ret = 0 , cur = a % c ;
    while(b) { if(b%2) ret=(ret+cur)%c; cur=(cur<<1)%c; b=b>>1; }
    return ret%c;
}
//Calculate (b^p)%m || modular inverse: b^-1 = bigmod(b, m-2, m)
inline ll bigmod(ll b, ll p, ll m){
    ll ret = 1, cur = b % m;
    while(p) { if(p&1) ret=(ret*cur)%m; cur=(cur*cur)%m; p=p>>1; }
    return ret;
}
inline ll modulo(ll a,ll b,ll c) { //Same as big mod, use for numbers over 1e10
    ll ret = 1 , cur = a%c ;
    while(b) { if(b%2) ret=mulmod(ret,cur,c); cur=mulmod(cur,cur,c); b=b>>1; }
    return ret%c ;
}
inline ll power(ll b, ll p){
    ll ret = 1, cur = b;
    while(p) { if(p&1) ret=(ret*cur); cur=(cur*cur); p=p>>1; }
    return ret;
}
ll lcm(ll a,ll b)
{
    return (a/__gcd(a,b))*b;
}
ll gcd(ll a,ll b)
{
    return __gcd(a,b);
}
void Dufaux()
{
    set<ll>st;
    ll a,b,c;
    cin>>a>>b>>c;
    st.insert(a);
    st.insert(b);
    st.insert(c);
    cout<<st.size()<<endl;
}
int main()
{
    FastIO;
	///sieve();
	///generate_mobius();
	int test=1;
	while(test--){
        Dufaux();
	}
	return 0;
}






Measured memory_bytes: 3608
import java.util.*;

class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n;
		int[] data;
		long[][] dp;
		while(sc.hasNext()){
			n = sc.nextInt();
			data = new int[n];
			for(int i = 0; i < n; i++){
				data[i] = sc.nextInt();
			}
			
			dp = new long[n - 1][21];
			dp[0][data[0]] = 1;
			for(int i = 1; i < n - 1; i++){
				for(int j = 0; j <= 20; j++){
					if(j + data[i] <= 20){
						dp[i][j] += dp[i - 1][j + data[i]];
					}
					if(j - data[i] >= 0){
						dp[i][j] += dp[i - 1][j - data[i]];
					}
				}
			}
			System.out.println(dp[n - 2][data[n - 1]]);
		}
	}
}

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

using namespace std;
int main(int argc, char *argv[]) {
	string s;
	cin >> s;
	
	if (s == "Sunny") {
		s = "Cloudy";
	} else if (s == "Cloudy") {
		s = "Rainy";
	} else if (s == "Rainy") {
		s = "Sunny";
	}
	
	cout << s << endl;
}

Measured memory_bytes: 256
//抄的hzw的 
#include <bits/stdc++.h>
#define pb push_back
#define cmin(a,b) (a>b?a=b:a)
#define cmax(a,b) (a<b?a=b:a)
#define mem(a,k) memset(a,k,sizeof(a))
#define lop(i,s,t) for(int i=s;i<(t);++i)
#define rep(i,s,t) for(int i=s;i<=(t);++i)
#define dec(i,s,t) for(int i=s;i>=(t);--i)
#define fore(i,v) for(int i=g[v],d=es[i].d;i;i=es[i].nxt,d=es[i].d)
using namespace std;
 
#define Pr(f,...) fprintf(stderr,f,##__VA_ARGS__),fflush(stderr)
 
typedef long long ll;
 
template<typename T>
void read(T &x){
	x=0; 
	char c;
	for(c=getchar();!isdigit(c);c=getchar()); 
	for(;isdigit(c);c=getchar())x=x*10+c-'0'; 
}
 
const int N=1e5+50;
 
int n;
bool fail,mat[N];
vector<int> g[N]; 
 
void dfs(int v,int p){
	for(int d:g[v])if(d!=p){
		dfs(d,v); 
		if(!mat[d]&&!mat[v]){
			mat[v]=true;
			mat[d]=true;
		}else if(!mat[d]&&mat[v]){
			fail=true;
		}
	}
}
 
int main(int argc,char *argv[]){
#ifdef CURIOUSCAT
#endif
	read(n); 
	rep(i,1,n-1){
		int u,v; 
		read(u),read(v); 
		g[v].pb(u); 
		g[u].pb(v); 
	}
	dfs(1,0); 
	fail|=!mat[1]; 
	puts(fail?"First":"Second"); 
	return 0;
}

Measured memory_bytes: 5888
#include <algorithm>
#include <bitset>
#include <cassert>
#include <deque>
#include <fstream>
#include <iostream>
#include <map>
#include <math.h>
#include <memory>
#include <queue>
#include <sstream>
#include <stdio.h>
#include <string>
#include <vector>

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define POW(n) ((n) * (n))
#define ALL(a) (a).begin(), (a).end()
#define dump(v) (cerr << #v << ": " << v << endl)
#define cerr                                                                   \
  if (true)                                                                    \
  cerr

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> p;

typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<unsigned long long> vull;

// ll n = to_T<ll>("114514")
template <class T> T to_T(const string &s) {
  istringstream is(s);
  T res;
  is >> res;
  return res;
}
template <class T> string to_s(const T &a) {
  ostringstream os;
  os << a;
  return os.str();
}

void loop(bool List[100010], long long N, string s) {
  REP(i, N) {
    int in1 = i - 1 < 0 ? N - 1 : i - 1;
    int in2 = i + 1 == N ? 0 : i + 1;

    if (s[i] == 'o') {
      List[in2] = List[i] ? List[in1] : List[in1] ^ true;
    } else {
      List[in2] = List[i] ? List[in1] ^ true : List[in1];
    }
  }
}

void solve(long long N, string s) {
  bool List[100010] = {};

  List[0] = false;
  List[N - 1] = false;
  loop(List, N, s);
  if (List[0] == false && List[N - 1] == false) {
    REP(i, N) { cout << (List[i] ? "S" : "W"); }
    cout << endl;
    return;
  }

  List[0] = false;
  List[N - 1] = true;
  loop(List, N, s);
  if (List[0] == false && List[N - 1] == true) {
    REP(i, N) { cout << (List[i] ? "S" : "W"); }
    cout << endl;
    return;
  }

  List[0] = true;
  List[N - 1] = false;
  loop(List, N, s);
  if (List[0] == true && List[N - 1] == false) {
    REP(i, N) { cout << (List[i] ? "S" : "W"); }
    cout << endl;
    return;
  }

  List[0] = true;
  List[N - 1] = true;
  loop(List, N, s);
  if (List[0] == true && List[N - 1] == true) {
    REP(i, N) { cout << (List[i] ? "S" : "W"); }
    cout << endl;
    return;
  }

  cout << "-1" << endl;
}

int main() {
  ios::sync_with_stdio(false);
  long long N;
  string s;
  cin >> N;
  cin >> s;
  solve(N, s);
  return 0;
}


Measured memory_bytes: 768
mod=10**9+7
def mul(a,b):
    x,y=a,b
    return (x*y)%mod

H,W,K=map(int,input().split())
mod=10**9+7
ans=0
const=1
for i in range(H+W-1,H+W-K,-1):
    const=(const*i)%mod

inv=pow(H+W-1,mod-2,mod)
temp1=mul(H+W,mul((K*(K+1)//2)%mod,const))
const=mul(const,inv)
u=(K*(K**2-1))//6
u%=mod
temp2=mul(2*H*W,mul(u,const))
ans=(temp1+temp2)%mod
const=mul(const,H+W-1)
ans+=mul(K,mul(H+W,const))
ans%=mod
print(ans)


Measured memory_bytes: 63140
#include<bits/stdc++.h>
using namespace std;
int slove(int x,int y,int n);
int main(void)
{
    int N,Q;
    scanf("%d %d",&N,&Q);
    while(Q)
    {
        Q--;
        int x,y;
        scanf("%d %d",&x,&y);
        if(N==1)
            cout<<min(x,y)<<endl;
        else
        cout<<slove(x,y,N)<<endl;
    }
    return 0;
}
int slove(int x,int y,int n)
{
    while(x!=y)
    {
        if(x > y)
            x = (x+n-2)/n;
        else if(y > x)
            y = (y+n-2)/n;
    }
    return x;
}


Measured memory_bytes: 1280
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <map>
#define ll long long
const int MOD = 1e9+7;
using namespace std;



int main(){
	int a, b, k, coun = 0;
	cin >> a >> b >> k;
	for (int i = max(a, b); ; i--){
		if (!(a%i || b%i)) coun++;
		if (coun == k){
			cout << i << endl;
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    int a[n];
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    long long dp[n][n][2];
    for(int i = 0; i <n; i++){
        dp[i][i][0] = a[i];
        dp[i][i][1] = 0;
    }
    for(int k = 1; k < n; k++){
        for(int i = 0; i + k < n; i++){
            //compute dp[i][i+k][0], dp[i][i+k][1]
            if(dp[i+1][i+k][1]+a[i] - dp[i+1][i+k][0] > dp[i][i+k-1][1]+a[i+k] - dp[i][i+k-1][0]){
                dp[i][i+k][0] = dp[i+1][i+k][1] + a[i];
                dp[i][i+k][1] = dp[i+1][i+k][0];
            }
            else if(dp[i+1][i+k][1]+a[i] - dp[i+1][i+k][0] > dp[i][i+k-1][1]+a[i+k] - dp[i][i+k-1][0]){
                dp[i][i+k][0] = dp[i][i+k-1][1] + a[i+k];
                dp[i][i+k][1] = dp[i][i+k-1][0];
            }
            else{
                 dp[i][i+k][0] = dp[i][i+k-1][1] + a[i+k];
                 dp[i][i+k][1] = min(dp[i][i+k-1][0], dp[i+1][i+k][0]);
            }

        }
    }
    cout << dp[0][n-1][0] - dp[0][n-1][1] << "\n";
    return 0;
}

Measured memory_bytes: 140928
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
typedef long long ll;

int main() {
  ll a, b, k;
  cin >> a >> b >> k;
  if(a >= k)
    cout << a - k << ' ' << b << endl;
  else if(a < k) {
    k -= a;
    cout << 0 << ' ' << max(0LL, b - k) << endl;
  }
}

Measured memory_bytes: 256
N=int(input())
T,A=map(int,input().split())
S=list(map(int,input().split()))
mini=16777216
mininum=0
for i in range(N):
    if abs(T-0.006*S[i]-A)<mini:
        mini=abs(T-0.006*S[i]-A)
        mininum=i+1

print(mininum)
        
        
        


Measured memory_bytes: 3060
#include <algorithm>
#include <cmath>
#include <iostream>
#include <ostream>
#include <vector>

const uint32_t mod = 1000000007;

int main() {
  uint32_t N, M = 0;
  std::cin >> N >> M;

  std::vector<uint64_t> fact(M + 1, 1), ifact(M + 1, 1), inv(M + 1, 1);
  for (size_t i = 2; i < M + 1; i++) {
    fact[i] = (fact[i - 1] * i) % mod;
    inv[i] = mod - inv[mod % i] * (mod / i) % mod;
    ifact[i] = (ifact[i - 1] * inv[i]) % mod;
  }

  auto comb = [&](uint32_t n, uint32_t k) {
    return fact[n] * ((ifact[k] * ifact[n - k]) % mod) % mod;
  };

  uint64_t sum = 0;
  for (size_t k = 1; k <= N; k++) {
    uint64_t value = (comb(N, k) * fact[M - k]) % mod;
    if (k % 2) {
      sum += value;
    } else {
      if (sum < value) sum += mod;
      sum -= value;
    }
    sum %= mod;
  }
  sum = (sum * ifact[M - N]) % mod;

  uint64_t a = (fact[M] * ifact[M - N]) % mod;
  if (a < sum) a += mod;
  uint64_t result = (((a - sum) % mod) * a) % mod;

  std::cout << result << std::endl;

  return 0;
}

Measured memory_bytes: 14692
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
using namespace std;

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

    int ans = 0;
    for(int i=0; i<n; ++i){
        int p;
        cin >> p;
        ans += max(0, p - d);
    }

    if(ans == 0)
        cout << "kusoge" << endl;
    else
        cout << ans << endl;

    return 0;
}

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

typedef long long ll;
using namespace std;

ll max_sub_sum(vector<ll> accumulations, int range) {
  ll max_tmp = accumulations[range];

  for(int i = 1; i + range - 1 < accumulations.size(); i++) {
    max_tmp = max(max_tmp, accumulations[i + range - 1] - accumulations[i - 1]);
  }

  return max_tmp;
}

int main() {
  int sequence_num;
  int range;
  vector<ll> accumulations;

  while(true) {
    cin >> sequence_num >> range;

    if(sequence_num == 0 && range == 0) {
      break;
    }
    accumulations.resize(sequence_num + 1);

    accumulations[0] = 0;

    for(int i = 1; i <= sequence_num; i++) {
      int current;
      cin >> current;
      accumulations[i] = accumulations[i - 1] + current;
    }

    cout << max_sub_sum(accumulations, range) << endl;
  }
}


Measured memory_bytes: 4368
import sys,bisect,string,math,time,functools,random,fractions
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
from itertools import permutations,combinations,groupby
rep=range
def Golf():n,*t=map(int,open(0).read().split())
def I():return int(input())
def S_():return input()
def IS():return input().split()
def LS():return [i for i in input().split()]
def LI():return [int(i) for i in input().split()]
def LI_():return [int(i)-1 for i in input().split()]
def NI(n):return [int(input()) for i in range(n)]
def NI_(n):return [int(input())-1 for i in range(n)]
def StoLI():return [ord(i)-97 for i in input()]
def ItoS(n):return chr(n+97)
def LtoS(ls):return ''.join([chr(i+97) for i in ls])
def RA():return map(int,open(0).read().split())
def GI(V,E,ls=None,Directed=False,index=1):
    org_inp=[];g=[[] for i in range(V)]
    FromStdin=True if ls==None else False
    for i in range(E):
        if FromStdin:
            inp=LI()
            org_inp.append(inp)
        else:
            inp=ls[i]
        if len(inp)==2:
            a,b=inp;c=1
        else:
            a,b,c=inp
        if index==1:a-=1;b-=1
        aa=(a,c);bb=(b,c);g[a].append(bb)
        if not Directed:g[b].append(aa)
    return g,org_inp
def GGI(h,w,search=None,replacement_of_found='.',mp_def={'#':1,'.':0},boundary=1):
#h,w,g,sg=GGI(h,w,search=['S','G'],replacement_of_found='.',mp_def={'#':1,'.':0},boundary=1) # sample usage
    mp=[boundary]*(w+2);found={}
    for i in range(h):
        s=input()
        for char in search:
            if char in s:
                found[char]=((i+1)*(w+2)+s.index(char)+1)
                mp_def[char]=mp_def[replacement_of_found]
        mp+=[boundary]+[mp_def[j] for j in s]+[boundary]
    mp+=[boundary]*(w+2)
    return h+2,w+2,mp,found
def TI(n):return GI(n,n-1)
def accum(ls):
    rt=[0]
    for i in ls:rt+=[rt[-1]+i]
    return rt
def bit_combination(n,base=2):
    rt=[]
    for tb in range(base**n):s=[tb//(base**bt)%base for bt in range(n)];rt+=[s]
    return rt
def gcd(x,y):
    if y==0:return x
    if x%y==0:return y
    while x%y!=0:x,y=y,x%y
    return y
def show(*inp,end='\n'):
    if show_flg:print(*inp,end=end)
 
YN=['YES','NO'];Yn=['Yes','No']
mo=10**9+7
inf=float('inf')
FourNb=[(-1,0),(1,0),(0,1),(0,-1)];EightNb=[(-1,0),(1,0),(0,1),(0,-1),(1,1),(-1,-1),(1,-1),(-1,1)];compas=dict(zip('WENS',FourNb));cursol=dict(zip('LRUD',FourNb))
l_alp=string.ascii_lowercase
#sys.setrecursionlimit(10**7)
read=sys.stdin.buffer.read
readline=sys.stdin.buffer.readline
input=lambda: sys.stdin.readline().rstrip()


show_flg=False
show_flg=True
ans=0


#n,m=LI()
s=input()
n=len(s)
t=[]
for i in range(n):
    c=s[i]
    if c=='?':
        t+=['D']
    else:
        t+=[s[i]]
ans=''.join(t)
print(ans)






Measured memory_bytes: 93016
#include<bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define int long long
#define vec(a,n) vector<int> (a)((n))
#define Vec(a,n) vector<string> (a)((n))
#define twovec(a,n,m) vector<vector<int>> a(n,vector<int>(m,0))
#define Twovec(a,n,m) vector<vector<double>> a(n,vector<double>(m,0))
#define P pair<int,int>
#define All(a) (a).begin(),(a).end()
#define Sort(a) sort(All(a))
#define Reverse(a) reverse(All(a))
#define PQ(n) priority_queue<P,vector<P>,greater<P>> (n)
#define pq(n) priority_queue<int> (n)
#define Lower(a,t) lower_bound(All(a),t)
using namespace std;
void Debug(auto a);


signed main(){
    int n;
    cin >> n;
    int migi=0;
    int hidari=0;
    string s;
    cin >> s;
    REP(i,n){
        if(s[i] == '('){
            hidari++;
        }
        else{
            if(hidari>0){
                hidari--;
            }
            else{
                migi++;
            }
        }
    }
    REP(i,migi){
        cout << "(";
    }
    cout << s;
    migi = 0;
    hidari = 0;
    REP(i,n){
        if(s[n-1-i] == ')'){
            migi++;
        }
        else{
            if(migi>0){
                migi--;
            }
            else{
                hidari++;
            }
        }
    }
    REP(i,hidari){
        cout << ")";
    }




    return 0;
}



void Debug(auto a){
    cout << "{ ";
    for(auto b: a){
        cout << b << " ";
    }
    cout << "}" << endl;
}


Measured memory_bytes: 256
a=int(input())
x=list(map(int, input().split()))
ans=1
x.sort()
for i in range(a):

	if x[i]!=1 and x[i]!=0:
		ans=ans*x[i]
	if ans>10**18:
		break
	if x[i]==0:
		ans=0
		break
if ans>10**18:
	print(-1)
else:
	print(ans)

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

int main() {
  int x,y;
  cin>>x>>y;
  if(x%y==0)cout<<-1<<endl;
  else{
    for(int i=0;;i++){
      if(x*i%y!=0){
        cout<<x*i<<endl;
        break;
      }
    }
  }
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	int a,b;
	char op;
	for(;;){
		cin>>a>>op>>b;
		if(op=='?')break;
		if(op=='+'){
			cout<<a+b<<endl;
		}else if(op=='-'){
			cout<<a-b<<endl;
		}else if(op=='*'){
			cout<<a*b<<endl;
		}else{
			cout<<a/b<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3092
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<deque>
#include<string>
using namespace std;
const long long Maxn=1000000+10,Maxm=30000000+200;
const long long dx[]={1,-1,0,0},dy[]={0,0,-1,1};
const long long inf=(1ll<<60);
bool a[1010][1010];
bool vis[Maxn];
long long nxt[Maxm],to[Maxm];
long long len[Maxm],head[Maxn];
long long n,m,s,t;
long long edgecnt;
long long dis[Maxn]; 
struct node{
	long long pos,dis;
	node(long long x,long long y)
	{
		pos=x,dis=y;
	}
	bool operator <(const node &x)const
	{
		return x.dis<dis;
	}
};
inline void add(long long x,long long y,long long c)
{
	++edgecnt;
	nxt[edgecnt]=head[x];
	to[edgecnt]=y;
	len[edgecnt]=c;
	head[x]=edgecnt;
}
inline long long id(long long x,long long y)
{
	return (x-1)*m+y;
}
inline long long read()
{
	long long s=0,w=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
	while(ch>='0' && ch<='9')s=(s<<3)+(s<<1)+(ch^48),ch=getchar();
	return s*w;
}
void dij()
{
	deque <int> q;
	for(long long i=0;i<=(n*m)+2;++i)
	vis[i]=0,dis[i]=inf;
	vis[s]=1,dis[s]=0ll,q.push_back(s);
	while(q.size())
	{
		long long x=q.front();
		q.pop_front();
		vis[x]=0;
		for(long long i=head[x];i;i=nxt[i])
		{
			long long y=to[i];
			if(dis[y]>dis[x]+len[i])
			{
				dis[y]=(long long)dis[x]+len[i];
				if(!vis[y])
				{
					vis[y]=1;
					if(!len[i])q.push_front(y);
					else q.push_back(y);
				}
			}
		}
	}
}
inline bool check(long long x,long long y)
{
	return (x<1 || y<1 || x>n || y>m || a[x][y]);
}
int main()
{
	n=read(),m=read();
	long long x=read(),y=read();
	s=id(x,y);
	x=read(),y=read();
	t=id(x,y);
	for(long long i=1;i<=n;++i)
	{
		string str;
		cin>>str;
		for(long long j=1;j<=m;++j)
		if(str[j-1]=='#')a[i][j]=1;
	}
	for(long long i=1;i<=n;++i)
	for(long long j=1;j<=m;++j)
	{
		if(a[i][j])continue;
		for(long long x=i-2;x<=i+2;++x)
		for(long long y=j-2;y<=j+2;++y)
		{
			if(check(x,y) || (i==x && j==y))continue;
			add(id(i,j),id(x,y),1);
		}
		for(long long k=0;k<4;++k)
		{
			long long x=i+dx[k],y=j+dy[k];
			if(check(x,y))continue;
			add(id(i,j),id(x,y),0);
		}
	}
	dij();
	if(dis[t]==inf)puts("-1");
	else printf("%lld\n",dis[t]);
	return 0;
}


Measured memory_bytes: 184572
N, M, K = gets.split.map(&:to_i)

ok = false

(0..N).each{|i|
    (0..M).each{|j|
    # puts "#{i} #{j} #{M*i + N*j - i*j} "
        ok = true if M*i + N*j - 2*i*j == K
    }
}

puts ok ? "Yes" : "No"

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

#define pb push_back

#define int ll
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vpii = vector<pii>;
using vvpii = vector<vpii>;

template<typename T, typename U>
ostream& operator<<(ostream& o, const pair<T,U>& p) {
  return o << "(" << p.first << "," << p.second << ")";
}

template<typename T>
ostream& operator<<(ostream& o, const vector<T>& v) {
  o << "[";
  for (const T& x : v)
    o << x << ",";
  return o << "]";
}

const int INF = 1e18;

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

  int k;
  cin >> k;
  string s;
  cin >> s;
  if (s.size() <= k)
    cout << s << endl;
  else
    cout << s.substr(0,k) + "..." << endl;
}


Measured memory_bytes: 3612
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa == x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))


l = l()


print(max(l[2]-(l[0]-l[1]),0))










Measured memory_bytes: 38384
#include <cstdio>
#include <climits>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <string>
#include <cstdio>
#include <climits>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <utility>
#include <queue>
#include <cstring>
#include <set>
#include <map>
#include <complex>
#define rep(i, n) for (int i = 0; i < int(n); i++)
using namespace std;
long long MOD = 1000000007;
long long INF = 1000000000000000; //10^15
typedef long long ll;
typedef unsigned long long ull;


ll powMod(ll x, ll n, ll mod) {
  if (n == 0) return 1;
  ll t = powMod(x, n/2, mod);
  t = t * t % mod;
  if (n & 1) return t * x % mod;
  return t;
}

int main(void) {

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




  

  return 0;

}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <cstring>
#include <string>
#include <time.h>
#include <algorithm>
using namespace std;
#define INF 2147483647


/********************************* Main *********************************/
/*

Every character in an odd position  is R, U, or D.
Every character in an even position is L, U, or D.
Your task is to print Yes if S is easily playable, and No otherwise.  */

int main() {
	ios_base::sync_with_stdio(false); 

	bool flag = true; 
	string s; cin >> s; 

	for (int i = 0; i < s.size(); i++) {
		 if ((i % 2 == 0 && (s[i] == 'L')) || (i % 2 != 0 && (s[i] == 'R'))) {
			flag = false; 
		}
	}

	if (flag) { 
		cout << "Yes\n";
	}
	else {
		cout << "No\n";
	}
	return 0;
} 



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

typedef long long ll;
ll dp[100000][4];
char S[100000+1];

#define MOD 1000000007
ll mod(ll a) { return a%MOD;}
int main(){
	scanf("%s",S);	
	int len = strlen(S);

	//dp[i][j] i文字目までにj個の○がついている場合の数
	// ans = dp[len(s)-1][3]
	

	dp[0][0] = (S[0]=='?')?3:1;
	dp[0][1] = (S[0]=='A' || S[0]=='?')?1:0;
	dp[0][2] = 0;
	dp[0][3] = 0;
	for(int i = 1; i < len; i++){
		dp[i][0] = mod(dp[i-1][0] * ((S[i]=='?')?3:1));
		dp[i][1] = mod(dp[i-1][0] * ((S[i]=='A' || S[i]=='?')?1:0))
			 + mod(dp[i-1][1] * ((S[i]=='?')?3:1));
		dp[i][2] = mod(dp[i-1][1] * ((S[i]=='B' || S[i]=='?')?1:0))
			 + mod(dp[i-1][2] * ((S[i]=='?')?3:1));
		dp[i][3] = mod(dp[i-1][2] * ((S[i]=='C' || S[i]=='?')?1:0))
			 + mod(dp[i-1][3] * ((S[i]=='?')?3:1));
		for(int n = 0; n <= 3; n++){
			dp[i][n] = mod(dp[i][n]);
		}
#if 0
		printf("i=%d,",i);
		for(int n=0; n <= 3; n++){
			printf("%lld,",dp[i][n]);
		}puts("");
#endif
	}

	printf("%lld\n",dp[len-1][3]);
}


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

void dijkstra(vector<vector<pair<int, int>>>& edges, vector<int>& ds, int start) {
    priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> q;
    q.push(make_pair(0, start));
    while (!q.empty()) {
        int d = q.top().first;
        int u = q.top().second;
        q.pop();
        if (ds[u] >= 0) {
            continue;
        }
        ds[u] = d;
        for (auto p : edges[u]) {
            q.push(make_pair(d + p.second, p.first));
        }
    }
}

int main() {
    int n;
    cin >> n;
    vector<vector<pair<int, int>>> edges(n);
    for (int i = 0; i < n; i++) {
        int u, k;
        cin >> u >> k;
        for (int j = 0; j < k; j++) {
            int v, c;
            cin >> v >> c;
            edges[u].push_back(make_pair(v, c));
        }
    }

    vector<int> ds(n, -1);
    dijkstra(edges, ds, 0);

    for (int i = 0; i < n; i++) {
        cout << i << " " << ds[i] << endl;
    }
}

Measured memory_bytes: 1328
nl = lambda: list(map(int, input().split()))
sl = lambda: input().split()
n = lambda: int(input())
s = lambda: input()

N, D = nl()

points = []
for i in range(N):
    Xs = nl()
    points.append(Xs)

import math
count  = 0
for i in range(N-1):
    for j in range(i+1, N):
        t = 0
        for k in range(D):
            diff = points[i][k] - points[j][k]
            t += diff * diff
        st = int(math.sqrt(t))
        if st * st == t:
            count +=1

print(count)



Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <cmath>
#include <cstdio>

using namespace std;

typedef long long ll;

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

int main(int argc, char **argv)
{
    int N;
    cin >> N;
    int A[N];
    REP(i, N) cin >> A[i];
    int B[N];
    REP(i, N) B[i] = A[i];
    sort(B, B + N);
    int first = B[N - 1];
    int second = B[N - 2];
    REP(i, N) {
        if (A[i] == first) cout << second << endl;
        else cout << first << endl;
    }
    return 0;
}


Measured memory_bytes: 3200
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 2e5 + 5, mod = 1e9 + 7;

vector<int> adj[N];
int a[N];

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int n, m;
    cin >> n >> m;
    for(int i = 1; i <= n; i++){
        cin >> a[i];
    }
    for(int i = 0; i < m; i++){
        int u, v;
        cin >> u >> v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    int cnt = 0;
    for(int i = 1; i <= n; i++){
        int mx = a[i];
        bool found = 0;
        for(auto j: adj[i]){
            if(a[j] >= a[i]){
                found = 1;
                break;
            }
        }
        if(!found) cnt++;
    }
    cout << cnt;

    return 0;

}


Measured memory_bytes: 11528
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please


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


	int N;
	cin >> N;

	int X[50], Y[50];
	rep(i, N) cin >> X[i] >> Y[i];

	double kotae = 1e18;

	rep(i, N) rep(j, i) {

		if (Y[i] != Y[j]) {

			double L = 0;
			double R = 1000;
			cesp(X[i]); ce(Y[i]);
			cesp(X[j]); ce(Y[j]);
			rep(p, 100) {
				double x1 = L + (R - L) / 3;
				double tmp = (x1 - X[i])* (x1 - X[i]) - (x1 - X[j]) * (x1 - X[j]) + Y[i] * Y[i] - Y[j] * Y[j];
				double y1 = tmp / (Y[i] - Y[j]) / 2;
				double d1 = 0;
				rep(k, N) {
					chmax(d1, (x1 - X[k]) * (x1 - X[k]) + (y1 - Y[k]) * (y1 - Y[k]));
				}

				double x2 = L + (R - L) * 2 / 3;
				tmp = (x2 - X[i]) * (x2 - X[i]) - (x2 - X[j]) * (x2 - X[j]) + Y[i] * Y[i] - Y[j] * Y[j];
				double y2 = tmp / (Y[i] - Y[j]) / 2;
				double d2 = 0;
				rep(k, N) {
					chmax(d2, (x2 - X[k]) * (x2 - X[k]) + (y2 - Y[k]) * (y2 - Y[k]));
				}

				chmin(kotae, sqrt(min(d1, d2)));

				if (d1 < d2) R = x2;
				else L = x1;
			}

		}
		else {
			double L = 0;
			double R = 1000;
			cesp(X[i]); ce(Y[i]);
			cesp(X[j]); ce(Y[j]);
			rep(p, 100) {
				double x1 = double(X[i] + X[j]) / 2;
				double y1 = L + (R - L) / 3;
				double d1 = 0;
				rep(k, N) {
					chmax(d1, (x1 - X[k]) * (x1 - X[k]) + (y1 - Y[k]) * (y1 - Y[k]));
				}

				double x2 = double(X[i] + X[j]) / 2;
				double y2 = L + (R - L) * 2 / 3;
				double d2 = 0;
				rep(k, N) {
					chmax(d2, (x2 - X[k]) * (x2 - X[k]) + (y2 - Y[k]) * (y2 - Y[k]));
				}

				chmin(kotae, sqrt(min(d1, d2)));

				if (d1 < d2) R = y2;
				else L = y1;
			}
		}
	}

	cout << setprecision(12) << kotae << endl;


	Would you please return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define reg register
typedef long long ll;
using namespace std;
const int MN=305;
const int mod=1e9+7;
int n,m,a[MN*2],b[MN*2];
bool skip[MN*2],vis[MN*2];
int f[MN*2][MN][MN];
inline void add(int& a,int b){(a+=b)>=mod?a-=mod:0;}
int main(){
	scanf("%d",&n);
	for(reg int i=1;i<=n*2;i++)scanf("%d",a+i);
	reg int cnt1=0,cnt2=0;
	for(reg int i=1;i<=n*2;i+=2){
		if(a[i]>0&&a[i+1]>0)skip[a[i]]=skip[a[i+1]]=true;
		else if(a[i]<0&&a[i+1]<0)cnt1++;
		else if(a[i]<0)vis[a[i+1]]=true,cnt2++;
		else vis[a[i]]=true,cnt2++;
	}
	for(reg int i=n*2;i;i--)if(!skip[i])b[++m]=i;
	f[0][0][0]=1;
	for(reg int i=1;i<=m;i++)
		for(reg int j=0;j<=cnt1+cnt2;j++)
			for(reg int k=0;k<=cnt2;k++)
				if(f[i-1][j][k]){
					if(vis[b[i]]){
						if(j)add(f[i][j-1][k],f[i-1][j][k]);
						add(f[i][j][k+1],f[i-1][j][k]);
					}
					else{
						if(j)add(f[i][j-1][k],f[i-1][j][k]);
						if(k)add(f[i][j][k-1],1ll*f[i-1][j][k]*k%mod);
						add(f[i][j+1][k],f[i-1][j][k]);
					}
				}
	reg int Ans=f[m][0][0];
	for(reg int i=1;i<=cnt1;i++)Ans=1ll*Ans*i%mod;
	printf("%d\n",Ans);
	return 0;
}

Measured memory_bytes: 217344
using System;
using System.IO;

namespace Tenka2019B
{
    class Program
    {
        static void Main(string[] args)
        {
            if (args.Length > 0)
            {
                Console.SetIn(new StreamReader(args[0]));
            }

            new Program().Solve();
        }

        void Solve()
        {
            var N = int.Parse(Console.ReadLine());
            var S = Console.ReadLine().ToCharArray();
            var K = int.Parse(Console.ReadLine());

            var kchar = S[K - 1];

            for (int i = 0; i < S.Length; i++)
            {
                if (S[i] != kchar)
                {
                    S[i] = '*';
                }
            }

            Console.WriteLine(S);
        }
    }
}


Measured memory_bytes: 13140
/*
	submission # - User: herp_sy
	https://atcoder.jp/contests/
*/

#include <bits/stdc++.h>
using namespace std;

// utility of stdin,stdout
#define _CRT_SECURE_NO_WARNINGS
#define OUT cout << 
#define BR << endl
#define RET return 0
#define TLong long long
#define TBMod 1000000007

int main(int argc, char const *argv[]){
	int r;
	cin >> r;
	OUT(3 * r * r) BR;
	RET;
}


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

using namespace std;

typedef long long ll;

int main(void) 
{
  vector<int> ws;
  int n; 
  cin >> n;
  for (int i = 0; i < n; i++)
  {
    int w; cin >> w; ws.push_back(w);
  }

  int lsum = ws[0], usum = 0;
  for (int i = 1; i < n; i++) {
    usum += ws[i];
  } 

  int sub = abs(usum - lsum);
  for (int i = 1; i < n - 1; i++) {
    lsum += ws[i]; usum -= ws[i];
    sub = min(abs(usum - lsum), sub); 
  }

  cout << sub << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <queue>
#include <cstdio>
#include <deque>
#include <algorithm>
#include <string>
#include <cstring>
#include <map>
#include <stdlib.h>
#include <stack>

using namespace std;
int n, m;
pair<int, long long> a[100001];
pair<int, pair<long long, int>> b[100001];
pair<int, pair<int, int>> c[100001];
bool comp(pair<int, pair<long long, int>> x, pair<int, pair<long long, int>> y) {
	if (x.first == y.first) {
		return x.second.first < y.second.first;
	}
	else {
		return x.first < y.first;
	}
}
bool comp1(pair<int, pair<int, int>> x, pair<int, pair<int, int>> y) {
	return x.second.second < y.second.second;
}
int main() {
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		cin >> a[i].first >> a[i].second;
		b[i].first = a[i].first;
		b[i].second.first = a[i].second;
		b[i].second.second = i;
	}
	sort(b, b + m, comp);
	int s = 1;
	int cmp = b[0].first;
	for (int i = 0; i < m; i++) {
		if (b[i].first != cmp) {
			cmp = b[i].first;
			c[i].first = b[i].first;
			c[i].second.first = 1;
			c[i].second.second = b[i].second.second;
			s = 1;
		}
		else {
			c[i].first = b[i].first;
			c[i].second.first = s;
			c[i].second.second = b[i].second.second;
		}
		s += 1;
	}
	sort(c, c + m, comp1);

	for (int i = 0; i < m; i++) {
		printf("%06d", c[i].first);
		printf("%06d\n", c[i].second.first);
	}

}

Measured memory_bytes: 6528
macro_rules! scan {
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($t:ty;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    scan!($t)
        ).collect::<Vec<_>>()
    };
    ($t:ty;;$n:expr) => {
        (0..$n).map(|_| scan!($t;;)).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    scan!($($t),*)
        ).collect::<Vec<_>>()
    };

    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
}

fn main() {
    let a = scan!(String);
    let b = scan!(String);
    if a.len() < b.len() {
        println!("LESS")
    } else if a.len() > b.len() {
        println!("GREATER")
    } else {
        if a == b {
            println!("EQUAL")
        } else if a < b {
            println!("LESS")
        } else {
            println!("GREATER")
        }
    }
}


Measured memory_bytes: 4352
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

const (
	initialBufSize = 100000
	maxBufSize     = 1000000
)

var sc *bufio.Scanner

func initScanner(r io.Reader) *bufio.Scanner {
	buf := make([]byte, initialBufSize)

	sc := bufio.NewScanner(r)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords) // bufio.ScanLines
	return sc
}

func main() {
	sc = initScanner(os.Stdin)
	resolve()
}

func resolve() {
	n, m := scanInt(sc), scanInt(sc)
	sToC := map[int]int{}
	for i := 0; i < m; i++ {
		s := scanInt(sc)
		c := scanInt(sc)
		if v, ok := sToC[s]; ok && v != c {
			fmt.Println(-1)
			return
		}
		sToC[s] = c
	}
	for i := 1; i <= n; i++ {
		if c, ok := sToC[i]; ok {
			if i == 1 && n != 1 && c == 0 {
				fmt.Println(-1)
				return
			}
			fmt.Printf("%d", c)
		} else if n != 1 && i == 1 {
			fmt.Printf("%d", 1)
		} else {
			fmt.Printf("%d", 0)
		}
	}
	fmt.Println()
	return
}

// snip-scan-funcs
func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return int(i)
}
func scanString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}


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

int main() {
	int N, K;
	string S;
	cin >> N >> K >> S;

	char& C = S[K - 1];
	
	for (int i = 0; i < S.size(); i++) {
		if (i == K - 1) {
			cout << char(C + 32);
		}
		else cout << S[i];
	}
}

Measured memory_bytes: 256
a = list(input())
ar = list('abcdefghijklmnopqrstuvwxyz')
if len(a) < 26:
    for r in ar:
        if r not in a:
            print("".join(a) + r)
            exit()
else:
    for i in range(25,0,-1):
        n = ar.index(a[i-1]) 
        b = [ar.index(a[j]) for j in range(i,26)]
        br = []
        for r in b:
            if r > n:
                br.append(r)
        if len(br) > 0:
            print("".join(a[0:i-1]) + ar[min(br)])
            exit()
print(-1)

Measured memory_bytes: 9004
#include <cstdio>
using namespace std;
 
int main() {
	int n,k,num=1;
	scanf("%d %d", &n, &k);
	for (int i = 0; i < n; i++) {
		if (num > k) {
			num = num + k;
		}
		else {
			num = num * 2;
		}
	}
	printf("%d", num);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#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 FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

int main()
{
    string S; long long K;
    cin >> S >> K;
    for (int i = 0; i < min((long long)S.size(), K); i++) {
        if (S[i] >= '2') { cout << S[i] << endl; return 0; }
    }
    cout << '1' << endl;
    return 0;
}


Measured memory_bytes: 256
import math
n,k = map(int,input().split())
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
for i in range(1,k+1):
    blue = combinations_count(k-1,i-1)
    if n-k+1<i:
        red = 0
    else:
        red = combinations_count(n-k+1,i)
    print(blue*red%(10**9+7))

Measured memory_bytes: 71304
def solve():
    from collections import Counter
    import sys
    input = sys.stdin.readline

    N, M, K = map(int, input().split())
    ABs = [tuple(map(int, input().split())) for _ in range(M)]
    CDs = [tuple(map(int, input().split())) for _ in range(K)]

    # Union-Findデータ構造
    class UnionFind:
        def __init__(self, numV):
            self.pars = list(range(numV))
            self.ranks = [0] * numV
        def find(self, x):
            if self.pars[x] == x: return x
            else:
                self.pars[x] = self.find(self.pars[x])
                return self.pars[x]
        def union(self, x, y):
            x, y = self.find(x), self.find(y)
            if x == y: return
            if self.ranks[x] < self.ranks[y]:
                self.pars[x] = y
            else:
                self.pars[y] = x
                if self.ranks[x] == self.ranks[y]:
                    self.ranks[x] += 1
        def same(self, x, y):
            return self.find(x) == self.find(y)

    UF = UnionFind(N)
    for A, B in ABs:
        A, B = A-1, B-1
        UF.union(A, B)

    for i in range(N):
        UF.find(i)

    cnt = Counter(UF.pars)
#    print('cnt:', cnt)

    anss = [cnt[UF.pars[i]]-1 for i in range(N)]
#    print('anss:', anss)

    for A, B in ABs:
        A, B = A-1, B-1
        if UF.same(A, B):
            anss[A] -= 1
            anss[B] -= 1
    for C, D in CDs:
        C, D = C-1, D-1
        if UF.same(C, D):
            anss[C] -= 1
            anss[D] -= 1

    print(' '.join(map(str, anss)))


solve()


Measured memory_bytes: 48704