akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define all(v) v.begin(), v.end()
#define fi first
#define se second
using namespace std;
using ll = long long;
using P = pair<int ,int>;
const int INF = 1e9*2+1;
const int MOD = 1e9+7;

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

    int v, e; cin >> v >> e;
    vector<vector<ll>> G(v, vector<ll>(v, INF));
    rep(i, e) {
        int s, t, d; cin >> s >> t >> d;
        G[s][t] = d;
    }
    rep(i, v) rep(j, v) if(i==j) G[i][j] = 0;

    rep(i, v) rep(j, v) rep(k, v) {
        if(G[j][i]!=INF&&G[i][k]!=INF) G[j][k] = min(G[j][k], G[j][i]+G[i][k]);
    }
    
    bool negativeCycle = false;
    rep(i, v) rep(j, v) {
        if (i==j && G[i][j]!=0) negativeCycle = true;
    }

    if (negativeCycle) {
        puts("NEGATIVE CYCLE");
    } else {
        rep(i, v) rep(j, v) {
            if (G[i][j]!=INF) cout << G[i][j];
            else cout << "INF";
            if (j<v-1) cout << " ";
            else cout << endl;
        }
    }
}


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

int main()
{
	//入力

	int N, M, C;
	cin >> N >> M >> C;
	int B[20];
	int A[20][20];
	for (int i = 0; i < M; ++i) {
		cin >> B[i];
	}
	for (int j = 0; j < N; ++j) {
		for (int i = 0; i< M; ++i) {
			cin >> A[j][i];
		}

	}

	//此処迄入力，以下出力

	int ans = 0;
	for (int j = 0; j< N;++j ){
		int sum = 0;
		for (int i=0; i < M; ++i) {
			sum += (A[j][i] * B[i]);
		}
		sum += C;

		if (sum > 0) {
			++ans;
		}
	}
	cout << ans<< endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using vi = vector<i64>;
using vvi = vector<vi>;

int bubbleSort(vi& a) {
    bool change = 1;
    int cnt = 0;
    while (change) {
        change = 0;
        for (int j = a.size() - 1; j >= 1; j--) {
            if (a[j] < a[j - 1]) {
                swap(a[j], a[j - 1]);
                cnt++;
                change = 1;
            }
        }
    }
    return cnt;
}

void printvec(vi& x, int size = 0) {
    cout << x.front();
    for (int i = 1; i < (size == 0 ? x.size() : size); i++) {
        cout << " " << x[i];
    }
    cout << endl;
}

int main() {
    int n;
    cin >> n;
    vi as;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        as.push_back(a);
    }

    int cnt = bubbleSort(as);
    printvec(as);
    cout << cnt << endl;
}


Measured memory_bytes: 3152
#include<bits/stdc++.h>
using namespace std;
int N,i,x[100],y[100],h[100],t,X,Y,H;
int main(){
	cin>>N;
	for(i=0;i<N;i++){
		cin>>x[i]>>y[i]>>h[i];
		if(h[i]>0)t=i;
	}
	for(X=0;X<101;X++)for(Y=0;Y<101;Y++){
		H=h[t]+abs(x[t]-X)+abs(y[t]-Y);
		for(i=0;i<N;i++)if(max(H-abs(x[i]-X)-abs(y[i]-Y),0)!=h[i])break;
		if(i==N){cout<<X<<' '<<Y<<' '<<H<<endl;return 0;}
	}
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Rep(i, n) for (int i = 1; i <= (int)(n); i++)
#define fore(i, a) for (auto &i:a)

#define ll long long
#define pll vector<pair<ll, ll>>
#define mod 1000000007
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define popcount(x) __builtin_popcountll(x)
using namespace std;

const long double PI = acos(-1);

ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a / gcd(a,b) * b;}
ll stringcount(string s, char c){return count(s.cbegin(), s.cend(), c);}

bool isInteger(double x){return floor(x) == x;}

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

    int a,b;cin >> a >> b;
    if(a > 8 || b > 8){
        cout << ":(" << endl;
    }else{
        cout << "Yay!" << endl;
    }

}

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

for i in range(n):
    if a[i] - b[i] >= 0:
        a[i] -= b[i]
        ans += b[i]
        b[i]=0
    else:
        ans += a[i]
        b[i] -= a[i]
        a[i] = 0
        if a[i+1] - b[i] >= 0:
            ans += b[i]
            a[i+1] -= b[i]
            b[i] = 0
        else:
            ans += a[i+1]
            a[i+1] = 0
        
print(ans)

Measured memory_bytes: 18624
import itertools
n=int(input())
dic={'M':0,'A':0,'R':0,'C':0,'H':0}
l=dic.keys()
for _ in range(n):
	s=input()
	if s[0] in l:dic[s[0]]+=1
l=[x for x in dic.values() if x>0]
if len(l)<3:print(0)
else:
	ans=0
	for t in itertools.combinations(range(len(l)),3):
		k=1
		for i in t:
			k*=l[i]
		ans+=k
	print(ans)
		

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9) + 7;

int main(void) {
	int n, k;
	cin >> n >> k;
	
	vector<int> a(n);
	for(int i = 0; i < n; ++i) {
		cin >> a[i];
	}
	
	n--;
	k--;
	cout << (n + k - 1) / k << endl;
	
	return 0;
	
}


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

#define all(x) (x).begin(),(x).end()
#define rep(i,l,r) for(int i=(int)(l);i<(int)(r);i++)

typedef long long ll;
const ll MOD = 1e9 + 7;
const ll inf = 1LL<<60;
const double eps = 1e-9;



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

    for (i = n; i >= 0; i++) {
        int tmp = 1;
        for (int j = 2; j < sqrt(i); j++) {
            if (i % j == 0) {
                tmp = 0;
                break;
            }
        }
        if (tmp) break; 
    }
    cout << i<< endl;
    return 0;
}



Measured memory_bytes: 256
#include <map>
#include <iostream>

using namespace std;

class Dice
{

	const static int NUM_S = 6;
	int a[NUM_S];
	map<int, int> men;

public:
	Dice(void) {}

	void set(int _a[]) {
		a[0] = _a[0];
		a[1] = _a[1];
		a[2] = _a[2];
		a[3] = _a[3];
		a[4] = _a[4];
		a[5] = _a[5];
		men[_a[0]] = 0;
		men[_a[1]] = 1;
		men[_a[2]] = 2;
		men[_a[3]] = 3;
		men[_a[4]] = 4;
		men[_a[5]] = 5;
	}

	int que(int x1, int x2) {
		int x = men[x1];
		int y = men[x2];
		switch (x) {
			case 0:
			switch (y) {
				case 1:
					return a[2];
				case 2:
					return a[4];
				case 3:
					return a[1];
				case 4:
					return a[3];
			}
			case 1:
			switch (y) {
				case 0:
					return a[3];
				case 2:
					return a[0];
				case 3:
					return a[5];
				case 5:
					return a[2];
			}
			case 2:
			switch (y) {
				case 0:
					return a[1];
				case 1:
					return a[5];
				case 4:
					return a[0];
				case 5:
					return a[4];
			}
			case 3:
			switch (y) {
				case 0:
					return a[4];
				case 1:
					return a[0];
				case 4:
					return a[5];
				case 5:
					return a[1];
			}
			case 4:
			switch (y) {
				case 0:
					return a[2];
				case 2:
					return a[5];
				case 3:
					return a[0];
				case 5:
					return a[3];
			}
			case 5:
			switch (y) {
				case 1:
					return a[3];
				case 2:
					return a[1];
				case 3:
					return a[4];
				case 4:
					return a[2];
			}
		}
	}

	int rs(void) {
		int tmp = a[1];
		a[1] = a[0]; a[0] = a[4];
		a[4] = a[5]; a[5] = tmp;
		return a[0];
	}

	int re(void) {
		int tmp = a[0];
		a[0] = a[3]; a[3] = a[5];
		a[5] = a[2]; a[2] = tmp;
		return a[0];
	}

	int rn(void) {
		int tmp = a[1];
		a[1] = a[5]; a[5] = a[4];
		a[4] = a[0]; a[0] = tmp;
		return a[0];
	}

	int rw(void) {
		int tmp = a[0];
		a[0] = a[2]; a[2] = a[5];
		a[5] = a[3]; a[3] = tmp;
		return a[0];
	}

};

int main()
{
	Dice dc;
	int st[6];
	cin >> st[0] >> st[1] >> st[2] >> st[3] >> st[4] >> st[5];
	dc.set(st);

	unsigned int n;
	cin >> n;
	for (unsigned int i = 0; i < n; ++i) {
	    int x, y;
		cin >> x >> y;
		cout << dc.que(x, y) << endl;
	}

	return 0;
}



Measured memory_bytes: 3056
from itertools import combinations as comb
def cube_dist(a,b):
	return sum([(a[i]-b[i])**2 for i in range(3)])
def cal_total_dist(t,dist_d):
	if len(t) == 1:
		return 0
	return sum([dist_d[(ca,cb)] for ca, cb in comb(t,2)])

N, M = map(int,raw_input().split())
color = [tuple(map(float,raw_input().split())) for i in range(N)]
cube_dist_dict = dict()
for a,b in comb(color,2):
	cube_dist_dict[(a,b)] = cube_dist(a,b)
print max([cal_total_dist(ctuple, cube_dist_dict) for ctuple in comb(color,M)])

Measured memory_bytes: 10204
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.BufferedReader;

public class Main{
    
    static int getMark(String mark){
        switch(mark){
            case "S":   return 0;
            case "H":   return 1;
            case "C":   return 2;
            case "D":   return 3;
            default :   return -1;
        }
    }

    static String getMark(int mark){
        switch(mark){
            case 0:   return "S";
            case 1:   return "H";
            case 2:   return "C";
            case 3:   return "D";
            default :   return "";
        }
    }

    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        int[][] cards = new int[4][13];

        int num = Integer.parseInt(br.readLine());

        for(int i = 0; i < num; i++){
            String[] input = br.readLine().split(" ");
            
            int mark = getMark(input[0]);

            cards[mark][Integer.parseInt(input[1])-1] = 1;
        }

        for(int i = 0; i < 4; i++){
            for(int j = 0; j < 13; j++){
                if(cards[i][j] == 0) System.out.println(getMark(i) + " " + (j+1));
            }
        }

    }
}

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

#define ll long long
#define INF 99999999
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

int main()
{
    int n,y;
    int ans[3] = {-1,-1,-1};
    int total;
    cin >> n >> y;
    rep(i,n+1)
    {
        rep(j,n+1)
        {
            if(i+j>n) continue;
            int tmp = 1000 * (n-i-j);
            total = i*10000 + j*5000 + tmp;
            if(y==total)
            {
                ans[0] = i;
                ans[1] = j;
                ans[2] = n-i-j;
            }
        }
    }
    cout << ans[0] << " " << ans[1] << " " << ans[2] << endl;
}


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

int main() {

    bool ans = false;
    int A, B;
    cin >> A >> B;

    if (A % 3 == 0){
        ans = true;
    }
    else if (B % 3 == 0){
        ans = true;
    }
    else if (((A+B) % 3) == 0){
        ans = true;
    }

    if(!ans) cout << "Impossible" ;
    else cout << "Possible" << endl;

    return 0;
}
    



Measured memory_bytes: 256
// Author: wlzhouzhuan
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ull unsigned long long
#define rint register int
#define rep(i, l, r) for (rint i = l; i <= r; i++)
#define per(i, l, r) for (rint i = l; i >= r; i--)
#define mset(s, _) memset(s, _, sizeof(s))
#define pb push_back
#define pii pair <int, int>
#define mp(a, b) make_pair(a, b)

inline int read() {
  int x = 0, neg = 1; char op = getchar();
  while (!isdigit(op)) { if (op == '-') neg = -1; op = getchar(); }
  while (isdigit(op)) { x = 10 * x + op - '0'; op = getchar(); }
  return neg * x;
}
inline void print(int x) {
  if (x < 0) { putchar('-'); x = -x; }
  if (x >= 10) print(x / 10);
  putchar(x % 10 + '0');
}
/*
const int N = 3001;
bitset <N> dp;
int n, S;

int main() {
  n = read(), S = read();
  for (rint i = 1; i <= n; i++) a[i] = read();
  for (rint i = 1; i <= n; i++) {
    dp.reset();
    dp.set(0);
    for (rint j = 1; j <= n; j++) {
      dp |= dp << a[j];
    }
  }
}
*/

const int N = 3001;
const ll mod = 998244353;
int dp[N][N][2];
int a[N], n, S;

int main() {
  scanf("%d%d", &n, &S);
  for (rint i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  for (rint i = 1; i <= n; i++) {
    dp[i][a[i]][1] = i;
  }
  for (rint i = 1; i <= n; i++) {
    for (rint j = S; j >= 0; j--) {
      dp[i][j][0] = (dp[i][j][0] + dp[i - 1][j][0] + dp[i - 1][j][1]) % mod;
      if (j >= a[i]) dp[i][j][1] = (dp[i][j][1] + dp[i - 1][j - a[i]][0] + dp[i - 1][j - a[i]][1]) % mod;
      //printf("dp[%d][%d] = %d\n", i, j, dp[i][j]);
    }
  }
  long long ans = 0ll;
  for (rint i = 1; i <= n; i++) {
    ans = (ans + 1ll * dp[i][S][1] * (n + 1 - i) % mod) % mod;
  }
  ans = (ans % mod + mod) % mod;
  printf("%lld\n", ans);
  return 0;
}


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


void solve(long long H, long long W, std::vector<std::vector<ll>> A, std::vector<std::vector<ll>> B){
    vector<vector<vector<ll>>> dp(H + 1, vector<vector<ll>>(W + 1, vector<ll>(80*80*2+1, -1)));
    dp[0][0][6400] = 1;
    for(int i = 0;i < H;i++){
        for(int j = 0;j < W;j++){
            for(int k = 0;k <= 80*80*2;k++){
                if(dp[i][j][k] != -1){
                    if(k - 6400 > 0){
                        dp[i + 1][j][k - abs(A[i][j] - B[i][j])] = 1;
                        if(k + abs(A[i][j] - B[i][j]) < 80*80*2){
                        dp[i + 1][j][k + abs(A[i][j] - B[i][j])] = 1;
                        }
                        dp[i][j + 1][k - abs(A[i][j] - B[i][j])] = 1;
                        if(k + abs(A[i][j] - B[i][j]) < 80*80*2){
                        dp[i][j + 1][k + abs(A[i][j] - B[i][j])] = 1;
                        }
                    }else{
                        dp[i+ 1][j][k + abs(A[i][j] - B[i][j])] = 1;
                        if(k - abs(A[i][j] - B[i][j]) > 0){
                        dp[i + 1][j][k - abs(A[i][j] - B[i][j])] = 1;
                        }
                        dp[i][j + 1][k + abs(A[i][j] - B[i][j])] = 1;
                        if(k - abs(A[i][j] - B[i][j])  > 0){
                        dp[i][j + 1][k - abs(A[i][j] - B[i][j])] = 1;
                        }
                    }
                }
            }
        }
    }
    ll ans = 1e9;
    for(ll k = 0;k < 80*80*2+1;k++){
        if(dp[H][W-1][k] != -1){
            ans = min(ans, abs(k - 6400));
        }
        if(dp[H-1][W][k] != -1){
            ans = min(ans, abs(k - 6400));
        }
    }
    cout<<ans<<endl;
}

int main(){
    long long H;
    scanf("%lld",&H);
    long long W;
    scanf("%lld",&W);
    std::vector<std::vector<long long>> A(H, std::vector<long long>(W));
    for(int i = 0 ; i < H ; i++){
        for(int j = 0 ; j < W ; j++){
            scanf("%lld",&A[i][j]);
        }
    }
    std::vector<std::vector<long long>> B(H, std::vector<long long>(W));
    for(int i = 0 ; i < H ; i++){
        for(int j = 0 ; j < W ; j++){
            scanf("%lld",&B[i][j]);
        }
    }
    solve(H, W, std::move(A), std::move(B));
    return 0;
}


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

using namespace std;


#define PI 3.14159265
#define int long long


main(){


	string s; cin >> s;


	int n = s.size();

	vector <int> r(n), l(n);


	int last = 0;

	for(int i = 0; i < n; i++){
		if(s[i] == 'L'){
			l[i] = last;
		}else{
			last = i;
		}
	}

	last = n - 1;

	for(int i = n - 1; i >= 0; i--){
		if(s[i] == 'R'){
			r[i] = last;
		}else{
			last = i;
		}
	}


	vector <int> ans(n);

	for(int i = 0; i < n; i++){
		if(s[i] == 'L'){
			if((i - l[i]) % 2){
				ans[l[i] + 1]++;
			}else{
				ans[l[i]]++;
			}
		}else{
			if((r[i] - i) % 2){
				ans[r[i] - 1]++;
			}else{
				ans[r[i]]++;
			}
		}
	}


	for(int e : ans){
		cout << e << " ";
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 3072
#include <cstddef>
#include <cstdint>
#include <vector>

namespace null_null {

using i32 = std::int_fast32_t;
using i64 = std::int_fast64_t;
using u32 = std::uint_fast32_t;
using u64 = std::uint_fast64_t;
using usize = std::size_t;

constexpr usize operator"" _z(unsigned long long x) noexcept {
  return static_cast<usize>(x);
}

template <typename T> std::vector<T> make_v(usize a) {
  return std::vector<T>(a);
}
template <typename T, typename... Ts> auto make_v(usize a, Ts... ts) {
  return std::vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}

template <typename T, typename V>
typename std::enable_if<std::is_class<T>::value == 0>::type fill_v(T &t,
                                                                   const V &v) {
  t = v;
}
template <typename T, typename V>
typename std ::enable_if<std::is_class<T>::value != 0>::type
fill_v(T &t, const V &v) {
  for (auto &e : t)
    fill_v(e, v);
}

template <typename T, typename V> inline void chmin(T &a, V b) {
  if (a > b)
    a = b;
}
template <typename T, typename V> inline void chmax(T &a, V b) {
  if (a < b)
    a = b;
}

} // namespace null_null

#include <algorithm>
#include <iostream>
#include <utility>

namespace null_null {

void main_() {
  i32 r;
  std::cin >> r;
  std::cout << 3 * r * r << std::endl;
}

} // namespace null_null

int main() {
  null_null::main_();
  return 0;
}


Measured memory_bytes: 256
from copy import deepcopy
import math
import sys
sys.setrecursionlimit(10 ** 7)
n = int(input())
x, y = [], []
for _ in range(n):
    xi, yi = list(map(int, input().split()))
    x.append(xi)
    y.append(yi)


def dfs(memo, prex, prey, step, res_):
    global res, counter
    if step == n:
        res += res_
        counter += 1
        return
    for i in range(n):
        if step == 0:
            temp_memo = deepcopy(memo)
            temp_memo[i] = 1
            dfs(temp_memo, x[i], y[i], step + 1, res_)
        else:
            if memo[i]:
                pass
            else:
                temp_memo = deepcopy(memo)
                temp_memo[i] = 1
                dfs(temp_memo, x[i], y[i], step + 1, res_ +
                    (((x[i] - prex) ** 2 + (y[i] - prey) ** 2) ** 0.5))


res = 0
counter = 0
dfs([0 for _ in range(n)], 0, 0, 0, 0)
print(res/counter)


Measured memory_bytes: 3572
def calc(puzzle,H,score):
    flag=False
    for i in range(H-1,-1,-1):
        stones=[]
        for j in range(5):
            now=[j,puzzle[j][i]]
            if (len(stones)==0 or stones[-1][1]==now[1]) and now[1]!=0: stones.append(now)
            elif len(stones)<3: stones=[now]
            else: break
        if len(stones)>2:
            flag=True
            score+=stones[0][1]*len(stones)
            for stone in stones:
                puzzle[stone[0]].pop(i)
                puzzle[stone[0]].append(0)

    if flag==True:
        return calc(puzzle,H,score)
    else:
        return score

if __name__=="__main__":
    while True:
        score=0
        H=int(input())
        if H==0:
            break
        puzzle=[[] for _ in range(5)]
        for i in range(H):
            temp=list(map(int,input().split()))
            for j in range(5):
                puzzle[j].insert(0,temp[j])
        score=calc(puzzle,H,score)
        print(score)


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

#define REP(i, n) for(ll i = 0; i < n; i++)
#define ALL(x) (x).begin(),(x).end()
#define MSG(x) cout << x << endl;
#define YN(x) x ? cout << "YES" << endl : cout << "NO" << endl;
#define Yn(x) x ? cout << "Yes" << endl : cout << "No" << endl;
#define yn(x) x ? cout << "yes" << endl : cout << "no" << endl;

using namespace std;
using ll = long long;

int main(int argc, char *argv[]) {
    string s;
    cin >> s;

    if (s.at(0) != 'A') {
        MSG("WA")
        exit(EXIT_SUCCESS);
    }

    if (!(s.at(1) >= 'a' && s.at(1) <= 'z')) {
        MSG("WA")
        exit(EXIT_SUCCESS);
    }

    bool has_finded = false;
    for (int i = 2; i < s.size() - 1; ++i) {
        if (s.at(i) == 'C') {
            if (!has_finded) has_finded = true;
            else {
                MSG("WA")
                exit(EXIT_SUCCESS);
            }
        } else {
            if (!(s.at(i) >= 'a' && s.at(i) <= 'z')) {
                MSG("WA")
                exit(EXIT_SUCCESS);
            }
        }
    }
    
    if (!has_finded) {
        MSG("WA")
        exit(EXIT_SUCCESS);
    }

    if (!(s.at(s.size()-1) >= 'a' && s.at(s.size()-1) <= 'z')) {
        MSG("WA")
        exit(EXIT_SUCCESS);
    }

    MSG("AC")
    return 0;
}


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

r = []
ans = -2

for i in range(n):
    r.append(-1)

# n>1
if n>1:
    for i in range(m):
        s, c = map(int,input().split())
        s=s-1
        if s==0 and c==0: 
            ans = -1
        elif r[s]!=-1 and r[s]!=c:
            ans = -1
        else:
            r[s]=c

#n=1

if n==1:
    for i in range(m):
        s, c = map(int,input().split())
        s=s-1
        if r[s]!=-1 and r[s]!=c:
            ans = -1
        else:
            r[s]=c

if ans==-1:
    print(ans)
else:
    for i in range(n):
        if i==0 and r[i]==-1:
            if n!=1:
                r[i]=1
            else:
                r[i]=0
        if i!=0 and r[i]==-1:
            r[i]=0
        r[i]=str(r[i])
    print(''.join(r))




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

vector<P> prime_factorize(int N){
	vector<P> ans;
	for(int a = 2; a*a <= N; a++){
		if(N % a == 0){
			int ex = 0;
			while(N%a == 0){
				ex++;
				N /= a;
			}
			ans.push_back(P(a, ex));
		}
	}
	if(N != 1) ans.push_back(P(N, 1));
	return ans;
}



int main(){
	int n; scanf("%d", &n);
	vector<int> a(n), data(1e6+1, 0);
	for(int i = 0; i < n; i++){
		scanf("%d", &a[i]);
		auto vec = prime_factorize(a[i]);
		for(int j = 0; j < vec.size(); j++){
			data[vec[j].first]++;
		}
	}
		bool check = true;
	for(int i = 2; i < data.size(); i++){
		if(data[i] >= 2) check = false;
	}
	if(check){
		cout << "pairwise coprime" << endl;
		return 0;
	}
	int g = a[0];
	for(int i = 1; i < n; i++) g = __gcd(g, a[i]);
	if(g == 1){
		cout << "setwise coprime" << endl;
		return 0;
	}
	cout << "not coprime" << endl;
}

Measured memory_bytes: 11200
#include <iostream>
#include<string>
#include<algorithm>
#include<functional>

using namespace std;

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

	string devide[4]={ "maerd","remaerd","esare","resare" };

	reverse(S.begin(), S.end());

	int N = 0;


	int i = 0;
		for (int k = 0; k < 4; k++) {
			string d = devide[k];

			if (devide[k] == S.substr(i, devide[k].size()) ){
				i += d.size();
				k = -1;
			}

		}

		if (i == S.size()) {
			cout<<"YES"<<endl;
		}
		else {
			cout << "NO" << endl;
		}
	



	return 0;
}

Measured memory_bytes: 512
#include<stdio.h>
int main(void)
{
	int n,i,a,b,c,d,x[500];
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d %d %d %d",&a,&b,&c,&d);
		if(c>=5&&d<=2){
			if(a*c+b*d>(a*c+b*2)*0.8) x[i]=(a*c+b*2)*0.8;
			else x[i]=a*c+b*d;
		}
		if(c<=5&&d>=2){
			if(a*c+b*d>(a*5+b*d)*0.8) x[i]=(a*5+b*d)*0.8;
			else x[i]=a*c+b*d;
		}		
		if(c<=5&&d<=2){
			if(a*c+b*d>(a*5+b*2)*0.8) x[i]=(a*5+b*2)*0.8;
			else x[i]=a*c+b*d;
		}
		if(c>=5&&d>=2) x[i]=(a*c+b*d)*0.8;
	}
	for(i=0;i<n;i++) printf("%d\n",x[i]);
	return 0;
}	

Measured memory_bytes: 2720
import os

import itertools
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7


# MOD = 998244353


def test(N, A):
    ret = -INF
    for choices in itertools.combinations(range(N), N // 2):
        ok = True
        for i, j in zip(choices, choices[1:]):
            if abs(i - j) == 1:
                ok = False
                break
        if ok:
            s = 0
            for i in choices:
                s += A[i]
            ret = max(ret, s)
    print(ret)


N = int(sys.stdin.buffer.readline())
A = list(map(int, sys.stdin.buffer.readline().split()))
N = len(A)

if N % 2 == 0:
    cum0 = list(itertools.accumulate([0] + A[::2]))
    cum1 = list(itertools.accumulate([0] + A[1::2]))
    ans = -INF
    for i in range(len(cum0)):
        s = cum1[-1] - cum1[i] + cum0[i]
        ans = max(s, ans)
    print(ans)
    exit()

cnt = 2 if N % 2 == 1 else 1
# dp[i][j]: iまでみて、j個とばしたときの総和の最大値
dp = [[-INF] * (cnt + 1) for _ in range(N + 2)]
for i in range(cnt + 1):
    dp[i][i] = 0
for i in range(N):
    for j in range(cnt + 1):
        for k in range(cnt + 1):
            if i + 2 + k < len(dp) and j + k < len(dp[0]):
                dp[i + 2 + k][j + k] = max(dp[i + 2 + k][j + k], dp[i][j] + A[i])
print(dp[-1][-1])

# test(N, A)


Measured memory_bytes: 125420
#include <iostream>
#include <math.h>
#include <algorithm>

using namespace std ;

int main(void){
    int N, res=0;

    cin >> N;
    int A[N],B[N],C[N];

    for(int i=0; i<N; i++){
        cin >> A[i];
        --A[i];
    }
    for(int i=0; i<N; i++){
        cin >> B[i];
    }
    for(int i=0; i<N-1; i++){
        cin >> C[i];
    }

    for(int i=0; i<N; i++){
        res += B[A[i]];
        if(i>0 && A[i]==A[i-1]+1) res += C[A[i-1]];
    }
    cout << res << endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String [] args){
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		node p[]=new node[n];
		for (int i=0;i<n;i++){
			int id=sc.nextInt();
			int num=sc.nextInt();
			int a[]=new int[num];
			for (int j=0;j<num;j++){
				a[j]=sc.nextInt();
			}
			p[id]=new node(id,num,a);
		}
		for (int i=0;i<n;i++){
			for (int j=0;j<p[i].num;j++){
				p[p[i].child[j]].parent=i;
				p[i].type="internal node";
			}
		}
		for (int i=0;i<n;i++){
			if (p[i].parent==-1){
				p[i].type="root";
				setdepth(p,i);
				break;
			}
		}
		for(int i=0;i<n;i++){
			StringBuffer sb=new StringBuffer();
			sb.append("node "+i+": parent = "+p[i].parent+", depth = "+p[i].depth+", "+p[i].type+", [");
			for (int j=0;j<p[i].num;j++){
				sb.append(p[i].child[j]);
				if (j<p[i].num-1) sb.append(", ");
			}
			sb.append("]");
			System.out.println(sb.toString());
		}
	}
	static public void setdepth(node p[],int n){
		for (int i=0;i<p[n].num;i++){
			p[p[n].child[i]].depth=p[n].depth+1;
			setdepth(p,p[n].child[i]);
		}
	}
}

class node{
	int id;
	int num;
	int child[];
	int parent;
	int depth;
	String type;
	public node(int i,int n,int c[]){
		this.id=i;
		this.num=n;
		this.child=c;
		this.depth=0;
		this.type="leaf";
		this.parent=-1;
	}
}

Measured memory_bytes: 126808
/*
 Author: LargeDumpling
 Email: LargeDumpling@qq.com
 Edit History:
	2017-07-23	File created.
*/

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
const int MAXN=305;
int n,m;
int num[MAXN][MAXN],now[MAXN],cnt[MAXN],ans=2147483647,cur_ans;
bool exist[MAXN];
int main()
{
	memset(exist,true,sizeof(exist));
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			scanf("%d",&num[i][j]);
	for(int i=1;i<=n;i++)
		now[i]=1;
	for(int k=1;k<=m;k++)
	{
		memset(cnt,0,sizeof(cnt));
		for(int i=1;i<=n;i++)
			cnt[num[i][now[i]]]++;
		cur_ans=0;
		for(int i=1;i<=m;i++)
			if(cnt[cur_ans]<cnt[i])
				cur_ans=i;
		if(cnt[cur_ans]<ans)
			ans=cnt[cur_ans];
		exist[cur_ans]=false;
		for(int i=1;i<=n;i++)
			while(!exist[num[i][now[i]]])
				now[i]++;
	}
	printf("%d",ans);
	return 0;
}


Measured memory_bytes: 640
N=int(input())

q=[-1]*N
for i in range(N):
    k = int(input())
    #print(k)
    q[k-1]=i


max_con=1
count=1
for i in range(N-1):
    if q[i]<q[i+1]:
        count+=1
        max_con=max(max_con,count)
    else:
        count=1

print(N-max_con)

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


int main(){
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  if(abs(a-c)<=d || (abs(a-b)<=d && abs(b-c)<=d)){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <fstream> //ofstream
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
long long n,sum=0;
void solve(){
    rep(i,n){
        if((i+1)%3!=0 && (i+1)%5!=0) {
            sum+=(i+1);
        }
    }
    cout<<sum<<endl;
}

int main(){
    cin>>n;

    solve();
    return 0;
}


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

using namespace std;

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

#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

#define DUMP(x) cerr<<#x<<" = "<<(x)<<endl
#define DEBUG(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<<endl;

template<class T>
ostream &operator<<(ostream &os, const vector <T> &v) {
    os << "[";
    REP(i, SZ(v)) {
        if (i) os << ", ";
        os << v[i];
    }
    return os << "]";
}

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

template<class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vi>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;

const ll MOD = 1e9 + 7;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;
const ld eps = 1e-9;


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    int R, C, K; cin >> R >> C >> K;
    vi r(K), c(K), v(K);
    REP(i, K) cin >> r[i] >> c[i] >> v[i], --r[i], --c[i];
    vvi score(R, vi(C));
    REP(i, K) {
        score[r[i]][c[i]] = v[i];
    }

    vvvll dp(4, vvll(R+1, vll(C+1)));

    REP(i, R) {
        REP(j, C) {
            REP(u, 4) {
                chmax(dp[u][i+1][j+1], dp[u][i+1][j]);
                chmax(dp[u][i+1][j+1], dp[u][i][j+1]);
            }

            REP(u, 3) {
                chmax(dp[u+1][i+1][j+1], dp[u][i+1][j] + score[i][j]);
            }

            REP(u, 4) {
                chmax(dp[1][i+1][j+1], dp[u][i][j+1] + score[i][j]);
            }
        }
    }

    ll ans = max({dp[0][R][C], dp[1][R][C], dp[2][R][C], dp[3][R][C]});
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 392488
#include <bits/stdc++.h>
using namespace std;
int main(void){
    long long int h,w,n,i=0,j,l[1000]={2,1};
    cin >> n;
    if(n==1)
    {
        cout << "1" << endl;
        return 0;
    }
    for(i=2;i<=n;i++)
    {
        l[i]=l[i-1]+l[i-2];
    }
    cout << l[n] << endl;
    return 0;
}


Measured memory_bytes: 3604
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define MAX 1000001
typedef struct node* NP;

NP head,tail;

void insert(int);
void delete(int,NP);
NP find(int);
void list();
NP makenode(int,NP);
void deletelast();
struct node{
	int num;
	NP next;
	NP pre;
};

int main(){
	head=malloc(sizeof(struct node));
	tail=malloc(sizeof(struct node));
	head->next=tail;
	tail->pre=head;
	int i;
	char com[12];
	int n,key;
	scanf("%d",&n);
	
	for(i=0;i<n;i++){
		scanf("%s",com);
		if(strcmp(com,"delete")==0){
			scanf("%d",&key);
			delete(key,NULL);
			//list();
		}
		else if(strcmp(com,"insert")==0){
			scanf("%d",&key);
			insert(key);
			//list();
		}
		else if(strcmp(com,"deleteFirst")==0){
			delete(head->next->num,head);
			//list();
		}
		else {
			deletelast();
			//list();
		}
		
	}
	
	list();
	return 0;
}

void insert(int k){
	NP new=makenode(k,head->next);
	new->pre=head;
	head->next=new;
	}


void delete(int k,NP x){
	if(x==NULL){
	NP del ,n = find(k);
	if(n==NULL)return;
	del=n->next;
	n->next=del->next;
	n->next->pre=n;
	free(del);
	}
	else {
		NP dele=x->next;
		x->next=dele->next;
		x->next->pre=x;
		free(dele);
	}
}

NP find(int k){
	NP n;
	for(n=head;n->next!=tail;n=n->next){
		if(n->next->num==k)return n;
	}
	return NULL;
}

void list(){
	NP n;
	for(n=head->next;n!=tail;n=n->next){
		if(n->next!=tail)printf("%d ",n->num);
		else printf("%d\n",n->num);
	}
}

NP makenode(int k,NP n){
	NP new;
	new=malloc(sizeof(struct node));
	new->num=k;
	new->next=n;
	n->pre=new;
	return new;
}

void deletelast(){
	delete(0,tail->pre->pre);
	
}


Measured memory_bytes: 32948
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const ll inf =1LL << 62;
const ll mod=1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b,const ll &mod) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b,const ll &mod) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b,const ll &mod) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b,const ll &mod) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
random_device rd;
mt19937 mt(rd());
uniform_int_distribution<int> dice(1,6);
uniform_real_distribution<double> score(0.0,10.0);

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

    int n; cin >> n;
    string in; cin >> in;

    rep(loop, 2){
        int depth = 0, cnt = 0;
        for(auto& c : in){
            if(c == '('){
                depth++;
            }
            else {
                if(depth == 0){
                    cnt++;
                }
                else depth--;
            }
        }
        rep(i, cnt) in = '(' + in;

        reverse(_all(in));
        for(auto& c : in){
            if(c == '(') c = ')';
            else c = '(';
        }
    }

    cout << in << endl;

    return 0;
}


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

int main(){
    int n; cin >> n;
    if(n%10==0){
        cout << 10 << endl;
        return 0;
    }
    int ans=0;
    while(n>0){
        ans += n%10;
        n /= 10;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 888
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<cmath>
#include<string>

#define ls (t<<1)
#define rs ((t<<1)+1)
#define mid ((l+r)>>1)
#define fi first
#define se second
#define mk make_pair
#define pb push_back

#define N 100005
#define M 200005
#define seed 23333

#define Mo 1000000007

using namespace std;
int i,j,m,n,p,k,F[N],Q[N],ans;
const int inv2=500000004;
void jian(int &x,int y)
{
		x-=y; if (x<0) x+=Mo;
}
void jia(int &x,int y)
{
		x+=y; if (x>=Mo) x-=Mo;
}
int power(int x,int y)
{
		int sum=1;
		for (;y;y>>=1)
		{
				if (y&1) sum=1ll*sum*x%Mo;
				x=1ll*x*x%Mo;
		}
		return sum;
}
int main()
{	
	scanf("%d%d",&n,&k);
	for (i=1;i*i<=n;++i) if (n%i==0)
	{
			Q[++Q[0]]=i;
			if (i*i!=n) Q[++Q[0]]=n/i;
	}
	sort(Q+1,Q+Q[0]+1);
	for (i=1;i<=Q[0];++i)
	{
			F[i]=power(k,(Q[i]+1)/2);
			for (j=1;j<i;++j) if (Q[i]%Q[j]==0) jian(F[i],F[j]); 
	}
	for (i=1;i<=Q[0];++i)
	{
			if (n&1||Q[i]%2==1)	jia(ans,1ll*F[i]*Q[i]%Mo);
			else jia(ans,1ll*F[i]*inv2%Mo*Q[i]%Mo);	 
	}
	printf("%d\n",ans);
}


Measured memory_bytes: 256
#include<iostream>
//#include <bits/stdc++.h>
using namespace std;
#include<algorithm>
#include<map>
#include<vector>
#include <iomanip>
#include <set>
#include<cmath>
#define F first
#define S second
#define pii pair<int,int>
#define pb push_back
#define int long long
#define mp make_pair
#define error(x) cout<<#x<<"="<<(x)<<endl;
void sp(double y,int x){cout<<fixed<<setprecision(x)<<y;}
int inf=1e9+10;
int const M=2e5+10;
int const M2=1e6+10;
int const M3=1e3+10;
int mod=1e9+7;
int sa(int x,int y){if(x%y==0)return x/y;return x/y+1;}
int binp(int x,int y){int ans=1;int t=x;while(y!=0){if(y%2==1){ans*=t;ans;}y/=2;t*=t;t;}return ans;}
main(){
	ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);
	int a,b,c;
	cin>>a>>b>>c;
	if(a==b)
        cout<<c;
    if(b==c)
        cout<<a;
    if(c==a)
        cout<<b;
}

Measured memory_bytes: 256
#include<stdio.h>


int main(void){

  int w, n;
  int i, box;
  int a, b;
  int ans[30];


  scanf("%d", &w);
  for(i=0; i<w; i++){
    ans[i]=i+1;
  }

  scanf("%d", &n);
  for(i=0; i<n; i++){
    scanf("%d,%d", &a, &b);
    box = ans[a-1];
    ans[a-1] = ans[b-1];
    ans[b-1] = box;
  }

  for(i=0; i<w; i++){
    printf("%d\n", ans[i]);
  }

  return(0);
}



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

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

    long long a[n];
    long long sum = 0;
    for(int i = 0; i < n; i++){
        cin >> a[i];
        sum += a[i];
    }
    long long count = 0;
    for(int i = 0; i < n; i++){
        if(a[i] * 4 * m >= sum) count++;
    }
    if(count >= m) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include "stdio.h"

int main(void)
{
    int N,M;
    scanf("%d",&N);
    scanf("%d",&M);
    int A[M];
    int i;
    int nissu=0;
    for(i=0;i<M;i++)
    {
        scanf("%d",&A[i]);
        nissu = nissu + A[i];
    }
    if(N-nissu>=0)
    {
        printf("%d",N-nissu);
    }
    else
    {
        printf("-1");
    }
    return 0;
}

Measured memory_bytes: 1732
#作成日：4/20

#日付を受け取る変数
day = gets.to_i

#条件分岐
if day == 25 then
  print ("Christmas")
elsif day == 24 then
  print ("Christmas Eve")
elsif day == 23 then
  print ("Christmas Eve Eve")
else
  print ("Christmas Eve Eve Eve")
end

Measured memory_bytes: 1788
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

import bisect

def main():
    N = int(input())
    L = list(map(int, input().split()))

    L = sorted(L)

    ans = 0
    for i in range(N-2):
        for j in range(N-1):
            if j > i:
                ans += bisect.bisect_left(L[j+1:], L[i] + L[j])

    print(ans)

if __name__ == '__main__':
    main()



Measured memory_bytes: 50688
#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;
using ll = long long;

ll constexpr N = 200009;
ll f[N];
ll constexpr MOD = 1000000007;

ll mp(ll a, ll b) {
    if(b == 0)
        return 1;
    ll h = mp(a, b / 2);
    if(b & 1)
        return (((h * h) % MOD) * a) % MOD;
    return (h * h) % MOD;
}

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    ll n, m, k;
    cin >> n >> m >> k;
    vector<vector<ll>> dp(n + 10, vector<ll>(m + 10)),
                       dp2(n + 10, vector<ll>(m + 10));
    
    ll sum = 0;
    for(ll i = 1; i <= n; ++i) {
        for(ll j = 1; j <= m; ++j) {
            dp2[i][j] = j * (j - 1) / 2 + dp2[i - 1][j] + (i - 1) * j;

            dp[i][j] += dp2[i - 1][j] + (i - 1) * j;
            dp[i][j] %= MOD;
            dp[i][j] += dp2[i - 1][m - j] + 2 * (i - 1) * (m - j);
            dp[i][j] %= MOD;            
            dp[i][j] += j * (j - 1) / 2;
            dp[i][j] %= MOD;
            sum += dp[i][j];
            sum %= MOD;
        }
    }
    f[0] = 1;
    for(ll i = 1; i < N; ++i) {
        f[i] = (f[i - 1] * i) % MOD;
    }

    ll x = m * n - 2;
    ll y = k - 2;
    ll ans = sum * f[x];
    ans %= MOD;
    ans *= mp(f[y], MOD - 2);

    ans %= MOD;
    ans *= mp(f[x - y], MOD - 2);
    ans %= MOD;


    cout << ans << endl;
}

Measured memory_bytes: 48640
from collections import deque

def getdistance(row,col,sw,h,w):
    maze = deque([[row,col,0]])
    marker = [[0]*w for _ in range(h)]
    marker[row][col] = 1
    while len(maze)!=0:
        r, c, d = maze.popleft()
        if r!=0:
            if sw[r-1][c]!="#" and marker[r-1][c] != 1:
                marker[r-1][c] = 1
                maze.append([r-1,c,d+1])
        if r!=h-1:
            if sw[r+1][c]!="#" and marker[r+1][c] != 1:
                marker[r+1][c] = 1
                maze.append([r+1,c,d+1])
        if c!=w-1:
            if sw[r][c+1]!="#" and marker[r][c+1] != 1:
                marker[r][c+1] = 1
                maze.append([r,c+1,d+1])
        if c!=0:
            if sw[r][c-1]!="#" and marker[r][c-1] != 1:
                marker[r][c-1] = 1
                maze.append([r,c-1,d+1])
    return d
h, w = map(int, input().split())
sw = [input() for _ in range(h)]
ans = 0
for row in range(h):
    for col in range(w):
        if sw[row][col]=="#":
            continue
        ans = max(ans,getdistance(row,col,sw,h,w))
print(ans)

Measured memory_bytes: 9452
N = int(input())
S = input()
MOD = 10**9 + 7

base = 1
unsettled = 0
remaining = 2 * N
for i, s in enumerate(S):
  if s == 'W':
    if unsettled % 2: # 奇数
      unsettled += 1
    else: # 偶数
      base = (base * unsettled) % MOD
      unsettled -= 1
  else: # s == 'B'
    if unsettled % 2: # 奇数
      base = (base * unsettled) % MOD
      unsettled -= 1
    else:
      unsettled += 1
  if unsettled < 0:
    print(0)
    quit()
  remaining -= 1
  if unsettled == remaining:
    break

for s in S[i+1:]:
  if s == 'W':
    if unsettled % 2: # 奇数
      print(0)
      quit()
    else: # 偶数
      base = (base * unsettled) % MOD
      unsettled -= 1
  else: # s == 'B'
    if unsettled % 2: # 奇数
      base = (base * unsettled) % MOD
      unsettled -= 1
    else: # 偶数
      print(0)
      quit()

def factorial(n, mod=10**9+7):
    a = 1
    for i in range(1,n+1):
        a = a * i % mod
    return a

print(base * factorial(N) % MOD)

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a) for(int i=0;i<(a);i++)
const ll MOD=1000000007;

int sum[101];

int main(){
  int N,M,X;cin>>N>>M>>X;
  rep(i,M){
    int a; cin>>a;
    sum[a]++;
  }
  rep(i,N) sum[i+1]+=sum[i];
  cout<<min(sum[X],sum[N]-sum[X])<<endl;
  return 0;
}


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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reps(i,s,n) for(int (i)=(s);(i)<(n);(i)++)
#define repr(i,n) for(int (i)=(n)-1;(i)>=0;(i)--)
#define all(v) (v).begin(),(v).end()
#define chmax(a, b) a = max((a),(b))
#define chmin(a, b) a = min((a),(b))
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define inf 1000000000
#define llinf 1000000000000000


typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;

bool double_check(int a){
    rep(i,inf){
        if(i*i==a){
            return true;
        }
        else if(i*i>a){
            return false;
        }
    }
}

int table[100][100];

int main(){
    int n,d;
    cin>>n>>d;
    rep(i,n)rep(j,d)cin>>table[i][j];
    int ans=0;

    rep(i,n){
        reps(j,i+1,n){
            int sum=0;
            rep(k,d){
                sum+=pow(table[i][k]-table[j][k],2);
            }
            if(double_check(sum)){
                ans++;
            }
            
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
using namespace std;
int main()
{
	double v;
	double c = 4.9 / 9.8 / 9.8 / 5.0;
	while (cin >> v){
		int floor = int(ceil(c * v * v)) + 1;
		cout << floor << "\n";
	}
	return 0;
}

Measured memory_bytes: 1228
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE BinaryLiterals #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE NumDecimals #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}

import Control.Applicative
import Control.Arrow
import Control.Monad
import Control.Monad.ST

import Data.Char
import Data.List
import Data.Maybe

import qualified Data.ByteString.Char8 as B

import Data.Array.ST.Safe
import Data.STRef

import Debug.Trace
import Text.Printf

readInt = readLn :: IO Int
readInts = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine
readNInts = readInt >>= flip replicateM readInt

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

modifyArray a i f = writeArray a i =<< f <$> readArray a i

main = getLine >>= print . solve

solve s = runST $ do
	let
		l = length s
	dp <- newArray ( ( 0, 0 ), ( l + 1, 12 ) ) 0 :: ST s ( STUArray s ( Int, Int ) Int )
	writeArray dp ( 0, 0 ) 1
	forM_ ( zip s [ 0 .. ] ) $ \( ch, i ) -> do
		forM_ [ 0 .. 12 ] $ \j -> do
			forM_ [ 0 .. 9 ] $ \k -> do
				from <- readArray dp ( i, j )
				when ( ch == '?' || digitToInt ch == k ) $ do
	 				modifyArray dp ( i + 1, ( j * 10 + k ) `mod` 13 ) ( ( `mod` 1000000007 ) . ( + from ) )
	readArray dp ( l, 5 )

Measured memory_bytes: 17788
#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using ld = long double;

const double PI = 3.1415926535897932384626433832795;

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

int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
int lcm(int x, int y) { return x / gcd(x, y) * y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

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

	ll n, k;
	cin >> n >> k;

	vector<ll> x(n);
	for (auto &v : x) {
		cin >> v;
	}

	vector<ll> a = x;
	a.emplace_back(k);
	sort(begin(a), end(a));

	vector<ll> dist;
	for (int i = 0; i < a.size() - 1; i++) {
		dist.emplace_back(abs(a[i] - a[i + 1]));
	}

	ll ans = dist[0];
	for (int i = 1; i < dist.size(); i++) {
		ans = gcd(ans, dist[i]);
	}

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


Measured memory_bytes: 3696
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<iomanip>
#include<algorithm>
using namespace std;
const int maxn=1005;
int n,k;
int main()
{
    string a,b;
    cin>>a>>b;
    int i;
    for(i=0;i<3;i++)
        if(a[i]!=b[2-i]) break;
        if(i==3) cout<<"YES"<<endl;
        else cout<<"NO"<<endl;

    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<numeric>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;
typedef pair<ll, ll> mp;
ll mod = 1e9+7;
//LLONG_MIN

//AC

int main(void){
	ll a[3];
	rep(i,3)cin>>a[i];
	sort(a,a+3);
	cout<<a[2]-a[0]<<endl;
	return 0;
}

Measured memory_bytes: 256