akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <string>

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;

using namespace std;



int inputValue(){
    int a;
    cin >> a;
    return a;
};

void inputArray(int * p, int a){
    rep(i, a){
        cin >> p[i];
    }
};

void inputVector(vector<int> * p, int a){
    rep(i, a){
        int input;
        cin >> input;
        p -> push_back(input);
    }
}

template <typename T>
void output(T a, int precision) {
    if(precision > 0){
        cout << setprecision(precision)  << a << "\n";
    }
    else{
        cout << a << "\n";
    }
}

int main(int argc, const char * argv[]) {

    string S;
    cin >> S;
    if (S.length() == 2){
        cout << S<<endl;
    }else if(S.length()==3){
        cout << S[2] << S[1] << S[0] << endl;
    }

}


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

using namespace std;

typedef long long ll;

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

	int a, b, x;
	cin >> a >> b >> x;
	
	bool ok = a <= x && x <= a + b;
	cout << (ok ? "YES" : "NO") << endl;

}


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

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

const int INT_INF = 2147483646;
const ll LL_INF = 9223372036854775807;


const int SIZE = 1e5+100;
string s;
ll ans;

int main(){
    cin >> s;
    for(int i = 0; i < s.length(); i++){
        if(s[i] == '1') ++ans;
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    long long su=0;
    cin>>n;
    int a[n];
    unordered_map<int,int> m;
    for(int i=0;i<n;i++)
    {cin>>a[i];su+=a[i];m[a[i]]++;}
    int q;cin>>q;
    
    while(q--){
        int b,c;
        cin>>b>>c;
        su+=(m[b]*(c-b));
        m[c]+=m[b];
        m[b]=0;
        cout<<su<<"\n";
        
    }
}

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

using namespace std;

int a[100001];

int main () {
	int n, L;
	cin >> n >> L;
	int pos = 0;
	for (int i = 1;i <= n;i ++) cin >> a[i];
	for (int i = 1;i < n;i ++) {
		if (a[i] + a[i + 1] >= L) {
			pos = i;
		}
	}
	if (!pos) {
		cout << "Impossible";
		return 0;
	}
	cout << "Possible\n";
	for (int i = 1;i < pos;i ++) cout << i << ' ' ;
	for (int i = n - 1;i > pos;i --) cout << i << ' ' ;
	cout << pos;
	return 0;
}

Measured memory_bytes: 1152
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
using namespace std;
struct node
{
	double long x;
	char U[4];
}y[15];
int main()
{
	int n;
	double long sum=0;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>y[i].x>>y[i].U;
		if(y[i].U[0]=='J')
			sum=sum+y[i].x;
		else
			sum=sum+380000.0*y[i].x;	
	
	}
	cout<<sum;	
	return 0;
}

Measured memory_bytes: 256
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
a,b,c = readInts()
print(min(abs(a//2 * b * c - (a-a//2) * b*c), abs(a*(b//2)*c - (a*(b-b//2)*c)), abs(a*b*(c//2) - a*b*(c-c//2))))


Measured memory_bytes: 10420
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define mod 1000000007
int getTheAnswer() {
    return 42;
}

using namespace std;
using ll=long long;
int a[1000005];
class DDivGame {
public:
    bool check(ll a, vector<int> &v){
        for (int i=0;i<v.size()&&v[i]<=a;i++){
            if (a%v[i]==0){
                while (a%v[i]==0)
                    a/=v[i];
                if (a!=1)
                    return false;
                return true;
            }
        }
        return true;
    }
    void sieve(vector<int> &v){
        a[0]=a[1]=1;
        for (ll i=2;i<1000005;i++){
            if (a[i]==0){
                v.pb(i);
                for (ll j=i*i;j<1000005;j+=i)
                    a[j]=1;
            }
        }
    }
	void solve(std::istream& cin, std::ostream& cout) {
        ll n;
        cin>>n;
        vector<ll> v;
        for (int i=2;i<sqrt(n)+1;i++)
            if (n%i==0){
                v.pb(i);
                v.pb(n/i);
            }
        if (v.size()==0){
            if (n==1)
                cout<<0;
            else
                cout<<1<<endl;
            return;
        }
        sort(v.begin(),v.end());
        vector<int> fact;
        sieve(fact);
        int cnt=0;
        for (int i=0;i<v.size()&&n>1;i++){
            if ((n%v[i]==0)&&check(v[i], fact)){
//                cout<<"val="<<v[i]<<endl;
//                cout<<"n="<<n<<endl;
                n/=v[i];
                cnt++;
            }
        }
        cout<<cnt;
	}
};


int main() {
	DDivGame solver;
	std::ios::sync_with_stdio(false);
	std::cin.tie(NULL);
	std::cout.tie(NULL);
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 7848
n, m = map(int, input().split())
a = sorted(list(map(int,input().split())))
ans = 0
for i in a:
    if m - i < 0:
        print(ans)
        exit()
    m -= i
    ans += 1
if m > 0:
    print(ans-1)
else:
    print(ans)

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



int main(){
  int n,m;
  cin>>n>>m;
  vector<int> c(m);
  rep(i,m) cin>>c[i];
  
  int dp[50005];
  rep(i,50005) dp[i] = 50000;
  dp[0] = 0;
  
  rep(i,n+1){
    rep(j,m){
      if(i-c[j]<0) continue;
      dp[i] = min(dp[i],dp[i-c[j]]+1);
    }
  }
  cout << dp[n] << endl;
}


Measured memory_bytes: 3288
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        String s = scan.next();

        int ans = 0;
        for (int i = 0; i < 4; i++) {
            if (s.charAt(i) == '+') {
                ans++;
            } else {
                ans--;
            }
        }
        
        System.out.println(ans);
    }
}

Measured memory_bytes: 21712
import * as fs from "fs";

const input = (fs.readFileSync("/dev/stdin", "utf8") as string).split("\n");
const [a,b,c] = input[0].split(" ").map((x: string): number => +x);

let out = 'No'
if((a < c && c < b) || (b < c && c < a)){
  out = 'Yes'
}

console.log(out);

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

int main(void){
	int i;
	int x[10];

	for(i=0; i<10; i++){
		scanf("%d", &x[i]);
	}

	sort(x, x+10, greater<int>());

	printf("%d\n%d\n%d\n", x[0], x[1], x[2]);

	return 0;
}

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

int gcd(int a,int b){
    if(b==0)    return a;
    return    gcd(b,a%b);
}


int main(){
    int N;  cin>>N;
    vector<int> a(N);
    
    for(int i=0;i<N;i++)    cin>>a[i];
    
    int ans=a[0];
    for(int i=1;i<N;i++)    ans=gcd(ans,a[i]);
    
    cout<<ans<<endl;
    
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
template <long long mod>
class Combination
{
    std::vector<long long> fact, finv, inv;
public:
    Combination() {}
    Combination(int sz)
    {
        fact.resize(sz);
        finv.resize(sz);
        inv.resize(sz);
        fact[0] = 1;
        for (int i = 1; i < sz; ++i)
        {
            fact[i] = fact[i - 1] * i % mod;
        }
        inv[0] = 0;
        inv[1] = 1;
        for (int i = 2; i < sz; ++i)
        {
            inv[i] = mod - inv[mod % i] * (mod / i) % mod;
        }
        finv[0] = 1;
        for (int i = 1; i < sz; ++i)
        {
            finv[i] = finv[i - 1] * inv[i] % mod;
        }
    }
    long long C(long long n, long long k)
    {
        if (n < k)
            return 0;
        if (n < 0 || k < 0)
            return 0;
        return (fact[n] * finv[k] % mod) * finv[n - k] % mod;
    }
    long long P(long long n, long long k)
    {
        if (n < k)
            return 0;
        if (n < 0 || k < 0)
            return 0;
        return fact[n] * finv[n - k] % mod;
    }
    long long H(long long n, long long k)
    {
        return this->C(n + k - 1, k);
    }
    long long getfact(int i)
    {
        return fact[i];
    }
    long long getinv(int i)
    {
        return inv[i];
    }
    long long getfinv(int i)
    {
        return finv[i];
    }
};
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<int, int>;
const double eps = 1e-8;
const ll MOD = 1000000007;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;
template <typename T1, typename T2>
bool chmax(T1 &a, const T2 &b) {
  if(a < b) {a = b; return true;}
  return false;
}
template <typename T1, typename T2>
bool chmin(T1 &a, const T2 &b) {
  if(a > b) {a = b; return true;}
  return false;
}
template<typename T1, typename T2>
ostream& operator<<(ostream &os, const pair<T1, T2> p) {
  os << p.first << ":" << p.second;
  return os;
}
template<class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  for(int i=0;i<((int)(v.size()));++i) {
    if(i) os << " ";
    os << v[i];
  }
  return os;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  Combination<MOD> comb(1000000);
  ll n, m; cin >> n >> m;
  ll ans = 0;
  int sig = 1;
  for(int i=0;i<(n+1);++i) {
    ll now = comb.C(n, i);
    now *= (sig + MOD) % MOD;
    now %= MOD;
    now *= comb.P(m, n);
    now %= MOD;
    now *= comb.P(m-i, n-i);
    now %= MOD;
    ans += now;
    ans %= MOD;
    sig = -sig;
  }
  cout << ans << endl;
}


Measured memory_bytes: 26560
import java.util.*;
import java.util.Map.Entry;

import javax.swing.text.Segment;
import javax.xml.ws.WebEndpoint;

import java.io.*;
import java.lang.reflect.Array;
import java.math.BigInteger;

import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
 
public class Main //implements Runnable
{
//    static int dx[]={-1,0,1,0};
//    static int dy[]={0,-1,0,1};

    public static void main(String[] args)   throws Exception, IOException{        
        long mod=1000000007;
        Reader sc = new Reader(System.in);
        PrintWriter out=new PrintWriter(System.out);
        PriorityQueue<Integer> q=new PriorityQueue<>();
        
        int n=sc.nextInt();
        long k=sc.nextLong();
        long a[]=sc.nextLongArray(n);
        long f[]=sc.nextLongArray(n);
        sort(a);
        sort(f);

        long up=1L<<60,dw=0,md,r,ans=up;
        for (int i = 0,ok; i < 66; i++) {
        	md = (up+dw)/2;
        	r=k;
        	ok=1;
        	for (int j = 0; j < f.length; j++) {
				if(a[j]>md/f[n-j-1]) {
					r-=a[j]-md/f[n-j-1];
					if(r<0) {
						ok=0;break;
					}
				}
			}
        	if(ok==1) {
        		ans=min(ans,md);
        		up=md;
        	}else dw=md;
		}
        
        out.println(ans);
     	out.flush();
    }
    
    static void ret(String ans) {
    	System.out.println(ans);
    	System.exit(0);
    }
    
    static boolean validpos(int x,int y,int r, int c){
        return x<r && 0<=x && y<c && 0<=y;
    }

    static void db(Object... os){
        System.err.println(Arrays.deepToString(os));
    }
}


class P {
	int x, y, d;
	P(int  x, int y, int d) {
	  this.x=x;
	  this.y=y;
	  this.d=d;
	}
}

//class P implements Comparable<P>{
//    int a,b;
//    P(int a, int b) {
//    	this.b=b;
//    	this.a=a;
//    }
//
//    public int compareTo(P p){
//        return p.a-a;//des
//    }
//}

class Reader
{ 
    private BufferedReader x;
    private StringTokenizer st;
    
    public Reader(InputStream in)
    {
        x = new BufferedReader(new InputStreamReader(in));
        st = null;
    }
    public String nextString() throws IOException
    {
        while( st==null || !st.hasMoreTokens() )
            st = new StringTokenizer(x.readLine());
        return st.nextToken();
    }
    public int nextInt() throws IOException
    {
        return Integer.parseInt(nextString());
    }
    public int[] nextIntArray(int size) throws IOException{
        int r[] = new int[size];
        for (int i = 0; i < size; i++) {
            r[i] = this.nextInt(); 
        }
        return r;
    }
    public long[] nextLongArray(int size) throws IOException{
        long r[] = new long[size];
        for (int i = 0; i < size; i++) {
            r[i] = this.nextLong(); 
        }
        return r;
    }
    public char[] getCharSet() throws IOException{
        return this.nextString().toCharArray();
    }    
    public long nextLong() throws IOException
    {
        return Long.parseLong(nextString());
    }
    public double nextDouble() throws IOException
    {
        return Double.parseDouble(nextString());
    }
}


Measured memory_bytes: 55676
#define _USE_MATH_DEFINES

#include <bits/stdc++.h>
using namespace std;
using i32 = int; using i64 = long long int; using f64 = double; using str = string;
template <typename T> using vec = vector<T>;
template <typename T> using heap = priority_queue<T, vec<T>, greater<T>>;
#define times(n, i) for (i32 i = 0; i < (n); ++i)
#define range(a, b, i) for (i32 i = (a); i < (b); ++i)
#define upto(a, b, i) for (i32 i = (a); i <= (b); ++i)
#define downto(a, b, i) for (i32 i = (a); i >= (b); --i)
#define all(xs) (xs).begin(), (xs).end()
#define sortall(xs) sort(all(xs))
#define reverseall(xs) reverse(all(xs))
#define uniqueall(xs) (xs).erase(unique(all(xs)), (xs).end())
#define even(x) (((x) & 1) == 0)
#define odd(x) (((x) & 1) == 1)
#define append emplace_back
#define findge lower_bound
#define findgt upper_bound
const i64 MOD = 1000000007;
const f64 EPS = 1e-10;

set<tuple<i64, i64, i64>> s;
i64 a, b, c;

i32 main()
{
    cin >> a >> b >> c;
    auto t = make_tuple(a, b, c);
    i64 ans = 0;
    while (even(a) && even(b) && even(c)) {
        if (s.find(t) != s.end()) {
            ans = -1;
            break;
        }
        s.insert(t);
        t = make_tuple(b / 2 + c / 2, a / 2 + c / 2, a / 2 + b / 2);
        tie(a, b, c) = t;
        ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip> // for /* << std::fixed << std::setprecision(k) << */
using namespace std;

//defines

#define forn(n) for(int i = 0; i < n; i++)
#define pb push_back
#define int long long

int32_t main() {
	int n;
	
	cin >> n;
	
	vector<vector<int>> vals(n, vector<int>(3));
	
	for (int N = 0; N < n; N++) 
		cin >> vals[N][0] >> vals[N][1] >> vals[N][2];
	
	vector<vector<int>> df(n, vector<int>(3));
	
	df[0][0] = vals[0][0];
	df[0][1] = vals[0][1];
	df[0][2] = vals[0][2];
	
	for (int i = 1; i < n; i++) {
		for (int cur = 0; cur < 3; cur++) {
			for (int j = 0; j < 3; j++) {
				if (j != cur) {
					df[i][j] = max(df[i][j], df[i-1][cur]+vals[i][j]);
				}
			}
		}
	}
	
	int ans = -1;
	
	for (int i = 0; i < 3; i++) 
		ans = max(ans, df[n-1][i]);
		
	cout << ans;
}



Measured memory_bytes: 14332
n,m=map(int,input().split())
a=list(map(int,input().split()))
bc=[list(map(int,input().split())) for _ in range(m)]
for i in range(n):
      bc.append([1,a[i]])
bc.sort(key=lambda x:x[1],reverse=True)
k=0
ans=0
b_,c_=0,0
for i in range(m+n):
      b_,c_=bc[i][0],bc[i][1]
      ans+=b_*c_
      k+=b_
      if k>=n:
            break

ans-=(k-n)*c_
print(ans)


Measured memory_bytes: 43456
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
#define eprintf(...) fprintf(stderr,__VA_ARGS__)

const int N=int(1e5)+5;

int n,m,q;

struct node;
struct edge{
	node *ed;
	edge *next;
} E[N*2],*newE=E;
struct node{
	edge *son;
	int c[11],t[11];
} V[N];

int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++){
		int x,y; scanf("%d%d",&x,&y);
		*newE=(edge){V+y,V[x].son},V[x].son=newE++;
		*newE=(edge){V+x,V[y].son},V[y].son=newE++;
	}
	scanf("%d",&q);
	for(int tim=1;tim<=q;tim++){
		int v, d, c; scanf("%d%d%d",&v,&d,&c);
		V[v].c[d]=c;
		V[v].t[d]=tim;
	}
	for(int i=10;i>0;i--){
		for(node *u=V+1;u<=V+n;u++){
			for(edge *e=u->son;e;e=e->next){
				node *v=e->ed;
				if(u->t[i]>v->t[i-1]){
					v->t[i-1]=u->t[i];
					v->c[i-1]=u->c[i];
				}
			}
		}
	}
	for(node *u=V+1;u<=V+n;u++){
		int c = 0, t = 0;
		for(int i=0;i<=10;i++)
			if(u->t[i]>t){
				t=u->t[i];
				c=u->c[i];
			}
		printf("%d\n",c);
	}
}


Measured memory_bytes: 13184
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,o,n) for(long long i = o;i<n;i++)
#define oneforall ios::sync_with_stdio(false);cin.tie(0);
#define all(v) (v).begin(),(v).end()
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) long long __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
#define int long long 
const long long inf=1e18;
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
typedef vector<int> vi;
typedef vector<long long> vl;
typedef long long ll;
typedef vector<pair<long, long > > vpll;
typedef vector<pair<int, int > > vpii;
#define FORR(x,arr) for(auto& x:arr)
#define ZERO(a) memset(a,0,sizeof(a))





//3111111111111111111111111111111

	int x,x1;
	int morty[310][310];
	int tmpx[3] = {-1,1,0};
	void dfs(int tmp,int tmp1){
		morty[tmp][tmp1] = 0;
		FOR(i,0,3)FOR(i1,0,3){
			int nowtmp = tmp+tmpx[i];
			int nowtmp1 = tmp1+tmpx[i1];
			if(!(nowtmp == tmp and nowtmp1 == tmp1) and nowtmp>=0 and nowtmp<=x-1 and nowtmp1>=0 and nowtmp1<=x1-1 and morty[nowtmp][nowtmp1] == 1){
				dfs(nowtmp,nowtmp1);
			}
		}
	}




	void solve(){
		
		while(1){
			
			in(x1,x);
			if(x == 0 and x1 == 0)break;
			FOR(i,0,x)FOR(i1,0,x1){
				ini(tmp);
				if(tmp == 0){
					morty[i][i1] = 0;
				}
				else{
					morty[i][i1] = 1;
				}
			}
			int rick = 0;
			//FOR(i,0,x){
			//	FOR(i1,0,x1){
				//cout<<morty[i][i1]<<" ";			
			//	}
				//out();
			//}
			FOR(i,0,x)FOR(i1,0,x1){
				if(morty[i][i1] == 1){
					dfs(i,i1);
					rick++;
				}
			}
			out(rick);
		}








		
		
	}























int32_t main() {
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall 
	oneforall

	solve();
	


	return 0;
}



Measured memory_bytes: 3364
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

int n;
int m;
int ans;
vector<vector<int>> sw(10);
vector<int> guuki(10);

int ok(string s){
  if(s.size() != n) return 0;
  int count;
  rep(i,m){
    count = 0;
    rep(j,sw.at(i).size()){
      if(s[(sw.at(i).at(j))-1] == '1'){count++;}
    }
    if(count%2 != guuki[i]) return 0;
  }
  return 1;
}

void dfs(string s){
  if(s.size()>n) return;
  if(ok(s)){ans++;};
  dfs(s+'0');
  dfs(s+'1');
}

int main(){
	cin >> n >> m;
  
  rep(i,m){
    int x;  cin >> x;
      rep(j,x){
        int y; cin >>y;
        sw.at(i).pb(y);
      }
  }
  
  rep(i,m){
    cin >> guuki[i];
  }

  string S;
  dfs(S);
  cout<< ans <<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <climits>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef pair<int,int> pii;
const int INF = 1<<29;
const double PI = acos(-1);
const double EPS = 1e-8;

typedef int Weight;
struct Edge {
  int src, dst;
  Weight weight;
  Edge(int src, int dst, Weight weight) :
    src(src), dst(dst), weight(weight) { }
};

bool operator < (const Edge &e, const Edge &f) {
  return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
    e.src != f.src ? e.src < f.src : e.dst < f.dst;
}

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

// ¹öª¢çÈ¢ê
vector<Weight> dijkstra2(const Graph &g, vector<int> s) {
  vector<Weight> dist(g.size(), INF);
  priority_queue<Edge> Q; // "e < f" <=> "e.weight > f.weight"
  REP(i, s.size()) {
    dist[s[i]] = 0;
    Q.push(Edge(-2, s[i], 0));
  }
  for (; !Q.empty(); ) {
    Edge e = Q.top(); Q.pop();
    if (dist[e.dst] < e.weight) continue;
    FOR(f,g[e.dst]) {
      if (dist[f->dst] > e.weight+f->weight) {
        dist[f->dst] = e.weight+f->weight;
        Q.push(Edge(f->src, f->dst, e.weight+f->weight));
      }
    }
  }
  return dist;
}

int A[100000],B[100000], C[100000];
int main() {
  int n,m,k;
  cin >> n >> m >> k;
  Graph g(n);
  REP(i, m) {
    cin >> A[i] >> B[i] >> C[i];
    A[i]--;B[i]--;
    g[A[i]].push_back(Edge(A[i],B[i],C[i]));
    g[B[i]].push_back(Edge(B[i],A[i],C[i]));
  }
  vector<int> v;
  REP(i, k) {
    int a;
    cin >> a;
    a--;
    v.push_back(a);
  }
  vector<int> dist = dijkstra2(g, v);
  double ans = 0;
  REP(i, m) {
    ans = max(ans, (dist[A[i]] + dist[B[i]] + C[i])/2.0);
  }
  cout << (int)(ans+0.5) << endl;
}

Measured memory_bytes: 6308
#include<bits/stdc++.h>
#define N 100010
using namespace std;
int x[1010];
int main()
{
    long long n,i,a,b,ans;
    for(i=1;i<1000;i++)
        x[i]=x[i-1]+i;
    cin>>a>>b;
    for(i=1;i<999;i++)
    {
        if(x[i]-a==x[i+1]-b)
        {
            cout<<x[i]-a<<endl;;
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#define inf 1000000
#define N 101
#define WHITE 1
#define BLACK 2
#define NIL -2
 
int G[N][N],pi[N],d[N],n;
 
void dijkstra(void){
  int mincost,u,v,i;
  int color[N];
 
  for(u=0; u<n; u++){
    d[u] = inf;
    pi[u] = NIL;
    color[u] = WHITE;
  }
 
  d[0] = 0;
 
  while(1){
    mincost = inf;
    for(i=0; i<n; i++){
      if(color[i] != BLACK && d[i] < mincost){
    mincost = d[i];
    u = i;
      }
    }
     
    if(mincost == inf){
      break;
    }
 
    color[u] = BLACK;
     
    for(v=0; v<n; v++){
      if(color[v] != BLACK && d[u] + G[u][v] < d[v]){
    pi[v] = u;
    d[v] = G[u][v] + d[u];
      }
    } 
  } 
}  
 
   
int main(){
  int i, j, k, u, v, c, sum=0;
 
  scanf("%d", &n);
 
  for(i=0; i<n; i++){
    for(j=0; j<n; j++){
      G[i][j] = 999999;
    }
  }
 
  for(i=0; i<n; i++){
    scanf("%d%d", &u, &k);
    for(j=0; j<k; j++){
      scanf("%d%d", &v, &c);
      G[u][v] = c;
    }
  }
 
  dijkstra();
 
  for(i=0; i<n; i++){
    printf("%d %d\n", i, d[i]);
  } 
 
  return 0;
}



Measured memory_bytes: 2104
package main

import (
        "fmt"
        "os"
)

var i int
var x int
var n int

func checkNum() {
        x = i
        if x%3 == 0 {
                fmt.Printf(" %d", i)
                endCheckNum()
        } else {
                include3()
        }
}

func include3() {
        if x%10 == 3 {
                fmt.Printf(" %d", i)
                endCheckNum()
        }
        x /= 10
        if x > 0 {
                include3()
        } else {
                endCheckNum()
        }
}

func endCheckNum() {
        i += 1
        if i <= n {
                checkNum()
        }
        fmt.Print("\n")
        os.Exit(0)
}

func main() {
        i = 1
        fmt.Scan(&n)
        checkNum()
}


Measured memory_bytes: 9128
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner scan=new Scanner(System.in);
		int a=scan.nextInt();
		if(a==1) {
			System.out.println("Hello World");
		}
		else {
			int b=scan.nextInt();
			int c=scan.nextInt();
			System.out.println(b+c);
		}
		}
}

Measured memory_bytes: 25044
n = int(input())
s = input()

cnt = [0] * (n + 1)

for i in range(1, n + 1):
    cnt[i] = cnt[i - 1]
    if s[i - 1] == ".":
        cnt[i] += 1

ans = float("inf")

for i in range(0, n + 1):
    tmp = cnt[n] - cnt[i]  # cnt .. in right side
    tmp += i - cnt[i]  # cnt ## in left side
    ans = min(ans, tmp)

print(ans)


Measured memory_bytes: 43356
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(){
	string s,t; cin >> s >> t;
	int cnt = 0;
	for(int i = 0; i < s.size(); i++){
		if(s[i] == t[i])cnt++;
	}
	cout << cnt << 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 n = sc.nextInt();
        int m = sc.nextInt();
        int[] h = new int[n];
        for (int i = 0; i < n; i++) {
            h[i] = sc.nextInt();
        }
        
        // to: 隣接リスト
        List<Integer>[] to = new List[n];
        for (int i = 0; i < n; i++) {
            to[i] = new ArrayList<Integer>();
        }
        for (int i = 0; i < m; i++) {
            int s = sc.nextInt() - 1;
            int t = sc.nextInt() - 1;
            to[s].add(t);
            to[t].add(s); 
        }
        
        int count = 0;
        for (int i = 0; i < n; i++) {
            int max = 0;
            for (Integer q : to[i]) {
                max = Math.max(max, h[q]);
            }
            if (h[i] > max) count++;
        }
        
        System.out.println(count);
    }
}


Measured memory_bytes: 70916
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define NMAX 105
#define WMAX 10005
#define DIAGONAL 1
#define TOP 0

struct Item
{
    int value,weight;
};
int N,W;
Item items[NMAX+1];
int C[NMAX+1][WMAX+1], G[NMAX+1][WMAX+1];
void knapsack()
{
    for(int w=0; w<=W; w++)
    {
        C[0][w] = 0;
        G[0][w] = DIAGONAL;
    }
    for(int i=1; i<=N; i++)
        C[i][0] = 0;
    for(int i=1; i<=N; i++)
    {
        for(int w=1; w<=W; w++)
        {
            if(items[i].value+C[i-1][w-items[i].weight] > C[i-1][w] && items[i].weight <= w)
            {
                C[i][w] = items[i].value+C[i-1][w-items[i].weight];
                G[i][w] = DIAGONAL;
            }
            else
            {
                C[i][w] = C[i-1][w];
                G[i][w] = TOP;
            }
        }
    }
}
int main()
{
    cin >> N >> W;
    for(int i=1; i<=N; i++)
        cin >> items[i].value >> items[i].weight;
    knapsack();
    cout << C[N][W] << endl;
    return 0;
}

Measured memory_bytes: 11004
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>

namespace adaptor = boost::adaptors;

struct Card {
	char suit;
	char value;
};

void trace(Card A[], int64_t N) {
	for (int64_t i = 0; i < N; i++) {
		if (i > 0) std::cout << " ";
		std::cout << A[i].suit << A[i].value;
	}
	std::cout << std::endl;

	return;
}

void bubbleSort(Card A[], int64_t N) {
	bool sorted = true;
	for (int64_t i = 0; sorted; i++) {
		sorted = false;
		for (int64_t j = N - 1; j >= i + 1; j--) {
			if (A[j].value < A[j - 1].value) {
				std::swap(A[j], A[j - 1]);
				sorted = true;
			}
		}
	}

	return;
}

void selectionSort(Card A[], int64_t N) {
	for(int64_t i = 0; i < N - 1; i++) {
		int64_t min_j = i;
		for (int64_t j = i; j < N; j++) {
			if(A[j].value < A[min_j].value) min_j = j;
		}
		std::swap(A[i], A[min_j]);
	}

	return;
}

bool isStable(Card C1[], Card C2[], int64_t N) {
	for (int64_t i = 0; i < N; i++) {
		if (C1[i].suit != C2[i].suit) return false;
	}
	return true;
}

void solve()
{
	Card C1[36], C2[36];
	int64_t N;

	std::cin >> N;
	for (int64_t i = 0; i < N; i++) {
		std::cin >> C1[i].suit >> C1[i].value;
	}

	for (int64_t i = 0; i < N; i++) {
		C2[i] = C1[i];
	}

	bubbleSort(C1, N);
	selectionSort(C2, N);

	trace(C1, N);
	std::cout << "Stable" << std::endl;

	trace(C2, N);
	if (isStable(C1, C2, N)) {
		std::cout << "Stable" << std::endl;
	} else {
		std::cout << "Not stable" << std::endl;
	}

	return;
}

int main()
{
	std::cin.tie(0);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	solve();
}



Measured memory_bytes: 3208
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <limits.h>
#include <stdbool.h>

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

//qsort(str, n, sizeof(int), up_comp);
int up_comp(const void *a, const void *b){return *(int*)a - *(int*)b;}
int down_comp(const void *a, const void *b){return *(int*)b - *(int*)a;}
int int_sort( const void * a , const void * b ) {return strcmp(( char * )a , ( char * )b );}
int count_digit(int a){int i=0;while(a!=0){a=a/10;i++;}return i;}
int euclid( int a, int b ){int temp;if(a<b){temp=a;a=b;b=temp;}if(b<1)return -1;if(a%b==0) return b;return euclid(b,a%b);}
//void ret_digit(int a){rep(i, count_digit(a)){Dig[i]=a%10;a/=10;}}

int main(void){
 
    int n, y, k;
    char s[max];

    scanf("%d%s", &k, s);
    
    n=strlen(s);
    
    if (n<=k) {
        printf("%s", s);
    } else {
        for (int i=0; i<k; i++) {
            printf("%c", s[i]);
        }
        printf("...");
    }

    return 0;
}



Measured memory_bytes: 1736
n, c, k = map(int, input().split())
times = []
for _ in range(n):
    t = int(input())
    times.append((t, t+k))
times.sort(key=lambda x: x[1])

ans = 0
x = 0
capacity = 0
for L, R in times:
    if L <= x:
        if c == capacity:
            capacity = 1
            ans += 1
            x = R
        else:
            capacity += 1
    else:
        x = R
        ans += 1
        capacity = 1
print(ans)

Measured memory_bytes: 23940
N = int(input())
XL = [list(map(int, input().split())) for _ in range(N)]

t = [(x + l, x - l) for x, l in XL]
t.sort()
max_r = -float('inf')
result = 0
for i in range(N):
    r, l = t[i]
    if max_r <= l:
        result += 1
        max_r = r
print(result)


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

int main()
{
	int n;
	scanf("%d", &n);
 
	int i = n / 111;
	if (n % 111 != 0) ++i;
 
	printf("%d\n", i * 111);
	return 0;
}

Measured memory_bytes: 256
#pragma warning(disable:4786)
#pragma warning(disable:4996)
#include<list>
#include<bitset>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<functional>
#include<string>
#include<cstring>
#include<cstdlib>
#include<queue>
#include<utility>
#include<fstream>
#include<sstream>
#include<cmath>
#include<stack>
#include<assert.h>
using namespace std;

#define MEM(a, b) memset(a, (b), sizeof(a))
#define CLR(a) memset(a, 0, sizeof(a))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define ABS(X) ( (X) > 0 ? (X) : ( -(X) ) )
#define S(X) ( (X) * (X) )
#define SZ(V) (int )V.size()
#define FORN(i, n) for(i = 0; i < n; i++)
#define FORAB(i, a, b) for(i = a; i <= b; i++)
#define ALL(V) V.begin(), V.end()
#define IN(A, B, C)  ((B) <= (A) && (A) <= (C))

typedef pair<int,int> PII;
typedef pair<double, double> PDD;
typedef vector<int> VI;
typedef vector<PII > VP;

#define AIN(A, B, C) assert(IN(A, B, C))

//typedef int LL;
typedef long long int LL;
//typedef __int64 LL;

int n;
int col[404][5];
map<LL, int> M;

LL hashValue(VI V) {
	LL x = 0;
	for (int i = 0; i < 4; i++) {
		x = x * 1000 + V[i];
	}
	return x;
}

void insert(int a, int b, int c, int d, int u) {
	VI V = { a, b, c, d };
	VI W;
	W = V;
	for (int i = 0; i < 3; i++) {
		V = { V[1], V[2], V[3], V[0] };
		if (V < W) {
			W = V;
		}
	}

	LL h = hashValue(W);
	M[h]+=u;
}

VI rotate(int t, int turn) {
	VI V = { col[t][0], col[t][1], col[t][2], col[t][3] };
	for (int i = 0; i < turn; i++) {
		V = { V[1], V[2], V[3], V[0] };
	}
	return V;
}

LL ans = 0;
LL ways;

void select(VI X, int u) {
	int same = 0;
	VI V = X;
	VI MN = V;
	for (int i = 0; i < 4; i++) {
		V = { V[1], V[2], V[3], V[0] };
		same += (V == X);
		if (V < MN) MN = V;
	}

	LL h = hashValue(MN);
	ways *= same * M[h];
	M[h] += u;
}

void solve(vector<vector<int> > X) {
	ways = 1;
	for (VI _X : X) {
		select(_X, -1);
	}
	ans += ways;
	for (VI _X : X) {
		select(_X, +1);
	}
}

int main()
{
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 4; j++) {
			scanf("%d", &col[i][j]);
		}
		insert(col[i][0], col[i][1], col[i][2], col[i][3], 1);
	}

	for (int i = 0; i < n; i++) {
		insert(col[i][0], col[i][1], col[i][2], col[i][3], -1);
		VI T = { col[i][0], col[i][1], col[i][2], col[i][3] };
		for (int j = i + 1; j < n; j++) {
			insert(col[j][0], col[j][1], col[j][2], col[j][3], -1);
			for (int t = 0; t < 4; t++) {
				VI B = rotate(j, t);
				B = {B[1], B[0], B[3], B[2]};
				vector<vector<int> > X = {
					{ T[0], B[0], B[1], T[1] },
					{ T[1], B[1], B[2], T[2] },
					{ T[2], B[2], B[3], T[3] },
					{ T[3], B[3], B[0], T[0] }
				};

				solve(X);
				//printf("%d %d %d %d\n", i, j, t, ans);
			}
			insert(col[j][0], col[j][1], col[j][2], col[j][3], 1);
		}
		//insert(col[i][0], col[i][1], col[i][2], col[i][3], 1);
	}

	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 80128
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}

const ll INF=1e18;
const ll mod=1e9+7;

int main(){
    ll a,b,k;
    cin >> a >> b >> k;
    ll turn=0;
    while(turn<k){
        if(turn%2==0){
            b+=a/2;
            a/=2;
        }
        else{
            a+=b/2;
            b/=2;
        }
        turn++;
    }
    cout << a << " "<< b << endl;
    return 0;
}


Measured memory_bytes: 3576
/*
 * main.cpp
 *
 *  Created on: 2018/04/26
 *      Author: mac
 */

#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<map>


using namespace std;

int main(){

	map<char,int>mp;

    string s;
    cin >> s;
    for(int i = 0;i < s.size();i++){
    	mp[s[i]]++;
    }

    bool flag = true;

    for(auto p : mp){
    	if(p.second%2){
    		flag = false;
    	}
    }

    cout << (flag ? "Yes":"No");


    return 0;

}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// 標準入力からデータを読み込む準備
Scanner sc = new Scanner(System.in);
// 最初の文字の固まりを整数値と想定して読み込む 
int x = sc.nextInt();
int answer = x*x*x; /* ここを変えて3乗しよう! */ 
System.out.println(answer);
sc.close();
} }



Measured memory_bytes: 26156
#include <bits/stdc++.h>
#define loop2(i, s, n, a) for (int i = int(s); i < int(n); i += a)
#define loop(i, s, n) loop2(i, s, n, 1)
#define rep(i, n) loop(i, 0, n)

#define pb push_back
#define all(in) in.begin(),in.end()

using ll = long long;
using ull = unsigned long long;
using namespace std;

int main(){
    ll n, k; cin >> n >> k;
    vector<ll> data(n); rep(i,n) cin >> data[i];
    sort(data.begin(),data.end());
    ll ans = 0;
    rep(i,k) ans += data[i];
    cout << ans << endl;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,k;
    cin>>n>>k;
    int a[n];
    for(int i=0;i<n;i++)
    cin>>a[i];
    int ans;
    if((n-1)%(k-1)==0)
    ans=(n-1)/(k-1);
    else
    ans=(n-1)/(k-1)+1;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 640
N,K = map(int,input().split())
inf = 10**9+7

def fact(a,b):
    tmp = 1
    for i in range(a,a-b,-1):
        tmp *= i
        #tmp = tmp%inf
    return tmp


def conv(a,b):
    p1 = fact(a,b)
    p2 = fact(b,b)
    return p1//p2%inf

for i in range(1,K+1):
    if i-1 > N-i:
        print(0)
    else:
        print(int(conv(K-1,i-1)*conv(N-K+1,i))%inf)

Measured memory_bytes: 3316
import java.util.*;
import java.io.*;
import static java.lang.Math.*;

public class Main {
    public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int h = sc.nextInt();
		int w = sc.nextInt();
		int m = sc.nextInt();
		int[] sumH = new int[h];
		int[] sumW = new int[w];
		HashSet<Point> hs = new HashSet<Point>();
		int maxH = 0;
		int maxW = 0;
		for(int i = 0; i < m; i++){
			int a = sc.nextInt()-1;
			int b = sc.nextInt()-1;
			sumH[a]++;
			sumW[b]++;
			hs.add(new Point(a, b));
			maxH = max(maxH, sumH[a]);
			maxW = max(maxW, sumW[b]);
		}
		//System.out.println(Arrays.toString(sumH));
		//System.out.println(Arrays.toString(sumW));
		//System.out.println(maxH);
		//System.out.println(maxW);
		
		// 計算
		long result = 0;
		ArrayList<Integer> listH = new ArrayList<Integer>();
		ArrayList<Integer> listW = new ArrayList<Integer>();
		for(int i = 0; i < h; i++){
		    if(sumH[i] == maxH) listH.add(i);
		}
		for(int i = 0; i < w; i++){
		    if(sumW[i] == maxW) listW.add(i);
		}
		
		if(m < (long)listH.size() * listW.size()){
		    result = maxH + maxW;
		    System.out.println(result);
		    return;
		}
		for(int i = 0; i < listH.size(); i++){
		    for(int j = 0; j < listW.size(); j++){
		        int indexH = listH.get(i);
		        int indexW = listW.get(j);
		        int c = 0;
		        if(hs.contains(new Point(indexH, indexW))) c = 1;
		        result = max(result, maxH + maxW - c);
		    }
		}

		// 出力
		System.out.println(result);
	}
	
	public static class Scanner {
		private BufferedReader br; private StringTokenizer tok;
		public Scanner(InputStream is) throws IOException { br = new BufferedReader(new InputStreamReader(is));}
		private void getLine() throws IOException { while(!hasNext()) tok = new StringTokenizer(br.readLine());}
		private boolean hasNext() { return tok != null && tok.hasMoreTokens();}
		public String next() throws IOException { getLine(); return tok.nextToken();}
		public int nextInt() throws IOException { return Integer.parseInt(next());}
		public long nextLong() throws IOException { return Long.parseLong(next());}
		public double nextDouble() throws IOException { return Double.parseDouble(next());}
	}
}

class Point {
	int x;
	int y;
	
	Point(int x, int y){
		this.x = x;
		this.y = y;
	}

	public String toString(){
		return "(" + x + ", " + y + "):";
	}
	
	@Override
	public boolean equals(Object obj){
		if(obj == null) return false;
		if(this == obj) return true;
		if(this.getClass() != obj.getClass()) return false;

		Point q = (Point)obj;
		return this.x == q.x && this.y == q.y;
	}

	@Override
	public int hashCode(){
		int hc = 17;
		hc = 31 * hc + Long.hashCode(this.x);
		hc = 31 * hc + Long.hashCode(this.y);
		return hc;
	}

}


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

int K,i,x=0,j;
string N;


int main(){
    cin>>N;
    for(i=0;i<=N.length()-1;i++){
        for(j=0;j<=N.length()-1;j++){
            if(N[i]==N[j]&&i!=j){
                x=x+1;
            }
        }
    } 
    if(x>0){
        cout<<"no";
    }
    else{
        cout<<"yes";
    }
}

Measured memory_bytes: 3584
# ARC076C - Reconciled?
def factorial_mod(x):
    MOD = 10 ** 9 + 7
    ret = 1
    for i in range(1, x + 1):
        ret = (ret * i) % MOD
    return ret


def main():
    n, m = list(map(int, input().rstrip().split()))
    MOD = 10 ** 9 + 7
    n, m = min(n, m), max(n, m)
    dif = m - n
    if dif > 1:  # must be ...DDM...
        print(0)
    else:
        if dif == 0:  # start with either D or M (DM..., MD...)
            ans = (factorial_mod(n) ** 2 * 2) % MOD
        else:  # sandwich (DMD or MDM)
            ans = (factorial_mod(n) ** 2 * m) % MOD
        print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const int inf = 1e9;
 
int main(){
    int n;
    cin >> n;
    vector<int> h(n),w(n);
    for(int i=0; i<n; i++) cin >> h[i] >> w[i];
    char c[4][4];
    for(int i=0; i<4; i++){
        for(int j=0; j<4; j++){
            cin >> c[i][j];
        }
    }
     
    vector<int> dp(1<<16, inf);
    dp[0] = 0;
    for(int i=0; i<(1<<16); i++){
        if(dp[i] == inf) continue;
        for(int s=0; s<n; s++){
            for(int y=1-h[s]; y<=3; y++){
                for(int x=1-w[s]; x<=3; x++){
                    char color = 0;
                    int newidx = i;
                    int sy=max(y,0), sx=max(x,0);
                    int gy=min(y+h[s],4), gx=min(x+w[s],4);
                    for(int j=sy; j<gy; j++){
                        for(int k=sx; k<gx; k++){
                            if((i & 1<<(4*j +k)) != 0) continue;
                            if(color!=0 && color!=c[j][k]){
                                color = 0;
                                j = gy;
                                break;//j,k
                            }
                            color = c[j][k];
                            newidx |= 1<<(4*j +k);
                        }
                    }
                    if(color != 0){
                        dp[newidx] = min(dp[newidx], dp[i]+1);
                    }
                }
            }
        }
    }
    cout << dp[(1<<16) -1] << endl;
    return 0;
}


Measured memory_bytes: 3112
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int M = sc.nextInt();
    double sum = 0;
    ArrayList<Integer> list = new ArrayList<Integer>();
    int count = 0;
    String ans;
    for (int i=0; i<N; i++) {
      int num = sc.nextInt();
      list.add(num);
      sum += num;
    }
    
    Collections.sort(list,Collections.reverseOrder());

    for (int i=0; i<N; i++) {
      if (list.get(i) < sum/(4*M)) {
        count = i;
        break;
      } else if (i == N-1) {
        count = N;
        break;
      }
    }
    if (count >= M)
      ans = "Yes";
    else
      ans = "No";
    
    System.out.println(ans);
  }
}  

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

const ll INF64 = 1LL << 60;
const int INF32 = 1 << 29;
const int MOD = 1000000007;

// Lib
//

long long num[30];

int main(){
#ifdef MYLOCAL
    ifstream in("input.txt");
    cin.rdbuf(in.rdbuf());
#endif
    int N; string S; cin >> N >> S;
    for (auto c : S){
        num[c - 'a']++;
    }

    ll res = 1;
    for (int i = 0; i < 26; ++i) {
        res *= num[i] + 1;
        res %= MOD;
    }
    res -= 1;

    cout << (res + MOD) % MOD << endl;
    return 0;
}


Measured memory_bytes: 512
#include <algorithm>
#include<stdio.h>
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include<stack>
#include <queue>
#include<map>
#include <set>
#include<math.h>
using namespace std;
#define int long long
#define ll long long
#define rep(i,n) for(ll i=0;i<n;++i)
#define loop(i,m,n) for(ll i=m;i<n;++i)
#define ggr getchar(); getchar();return 0;
#define pie 3.141592653589793238462643383279
#define elif else if
#define P pair<ll,ll>
const int mod = 1000000007;
const int mod2 = 998244353;
int bin(int bina) {
	int ans = 0;
	for (int i = 0; bina > 0; i++)
	{
		ans = ans + (bina % 2) * pow(10, i);
		bina = bina / 2;
	}
	return ans;
}
bool prime(int n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int kai(int x) {
	if (x == 0)return 1;
	return kai(x - 1) * x % mod;
}
int mod_pow(int x, int y, int mod) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % mod;
		}
		x = x * x % mod;
		y >>= 1;
	}
	return res;
}
long nCr(int n, int r) {
	long ans = 1;
	for (int i = n; i > n - r; --i) {
		ans = ans * i;
	}
	for (int i = 1; i < r + 1; ++i) {
		ans = ans / i;
	}
	return ans;
}
struct union_find {
	int par[200010], size_[200010];
	void init(int x) {
		rep(i, x) { par[i] = i; size_[i] = 1; }
	}
	int find(int x) {
		if (par[x] == x)return x;
		return par[x] = find(par[x]);
	}
	void unite(int x, int y) {
		x = find(x); y = find(y);
		if (x == y)return;
		if (size_[x] < size_[y]) {
			par[x] = y;
			size_[y] += size_[x];
		}
		else {
			par[y] = x;
			size_[x] += size_[y];
		}
	}
};
struct edge { int to, cost; };
double a[110];
signed main() {
	int n;
	cin >> n;
	rep(i, n) {
		cin >> a[i];
	}
	sort(a, a + n);
	loop(i, 1, n) {
		a[i] = (a[i] + a[i - 1]) / 2;
	}
	cout << fixed << setprecision(10) << a[n - 1] << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define range(i,a,n) for(ll i=(a);i<(n);i++)

#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

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

template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S acm(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
void YN(bool b){cout<<(b?"YES":"NO")<<"\n";}
void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";}
void yn(bool b){cout<<(b?"yes":"no")<<"\n";}
int sgn(const double&r){return (r>EPS)-(r<-EPS);} // a>0  : sgn(a)>0
int sgn(const double&a,const double&b){return sgn(a-b);} // b<=c : sgn(b,c)<=0

ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n,ans=0;
	cin>>n;
	ans+=1000*(n/500);
	ans+=((n%500)/5)*5;
	puta(ans);
}


Measured memory_bytes: 256