akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>
#include<set>
#include<deque>
#include<queue>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;
const Int MOD = 1000000000 + 7;

template<int Modulo = MOD> struct Mint {
	Int val;
	constexpr Mint(Int v = 0) noexcept : val(v% Modulo) {
		if (val < 0) v += Modulo;
	}
	constexpr int getmod() { return Modulo; }
	constexpr Mint operator - () const noexcept { return val ? Modulo - val : 0; }
	constexpr Mint operator + (const Mint& r) const noexcept { return Mint(*this) += r; }
	constexpr Mint operator - (const Mint& r) const noexcept { return Mint(*this) -= r; }
	constexpr Mint operator * (const Mint& r) const noexcept { return Mint(*this) *= r; }
	constexpr Mint operator / (const Mint& r) const noexcept { return Mint(*this) /= r; }
	constexpr Mint& operator += (const Mint& r) noexcept {
		val += r.val;
		if (val >= Modulo) val -= Modulo;
		return *this;
	}
	constexpr Mint& operator -= (const Mint& r) noexcept {
		val -= r.val;
		if (val < 0) val += Modulo;
		return *this;
	}
	constexpr Mint& operator *= (const Mint& r) noexcept {
		val = val * r.val % Modulo;
		return *this;
	}
	constexpr Mint& operator /= (const Mint& r) noexcept {
		Int a = r.val, b = Modulo, u = 1, v = 0;
		while (b) {
			Int t = a / b;
			a -= t * b; swap(a, b);
			u -= t * v; swap(u, v);
		}
		val = val * u % Modulo;
		if (val < 0) val += Modulo;
		return *this;
	}
	constexpr bool operator == (const Mint& r) const noexcept {
		return this->val == r.val;
	}
	constexpr bool operator != (const Mint& r) const noexcept {
		return this->val != r.val;
	}
	friend ostream& operator << (ostream& os, const Mint<Modulo>& x) noexcept {
		return os << x.val;
	}
	friend istream& operator >> (istream& is, Mint<Modulo>& x) noexcept {
		Int tmp; is >> tmp;
		x = Mint<Modulo>(tmp);
		return is;
	}
	friend constexpr Mint<Modulo> modpow(const Mint<Modulo>& a, Int n) noexcept {
		Mint res(1), tmp = a;
		while (n > 0) {
			if (n & 1) res *= tmp;
			tmp *= tmp;
			n >>= 1;
		}
		return res;
	}
};

using mint = Mint<>;

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	Int N, M;
	cin >> N >> M;

	vector<vector<Int>> abc(M, vector<Int>(3, 0));
	vector<vector<Int>> route(N, vector<Int>(N, INF));
	for (Int i = 0; i < N; i++) {
		route[i][i] = 0;
	}
	Int a, b,c;
	for (Int i = 0; i < M; i++) {
		cin >> a >> b >> c;
		a--;
		b--;
		abc[i][0] = a;
		abc[i][1] = b;
		abc[i][2] = c;
		route[a][b] = c;
		route[b][a] = c;
	}

	//ワーシャルフロイド
	for (Int k = 0; k < N; k++) {
		for (Int i = 0; i < N; i++) {
			for (Int j = 0; j < N; j++) {
				route[i][j] = min(route[i][j], route[i][k] + route[k][j]);
			}
		}
	}

	Int temp = 0;
	for (Int k = 0; k < M; k++) {//k番目の道が最短経路に含まれるかどうか
		for (Int i = 0; i < N; i++) {
			if (route[i][abc[k][0]] + abc[k][2] == route[i][abc[k][1]]) {
				temp++;
				break;
			}
		}
	}

	cout <<max(0LL, M - temp) << "\n";

}

Measured memory_bytes: 384
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
long long s, ans;
int main() {
	scanf("%lld", &s);
	ans = s + 1;
	int lim = sqrt(s);
	for(int i=1;i<=lim;i++)
		if( s % i == 0 )
			ans = min(ans, i + s/i);
	printf("%lld\n", ans - 2);
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      while(true){
          String str = sc.next();
          if(str.equals("0")) break;
          int a = str.length();
          char[] m = new char[a];
          int sum=0;
          int[] M = new int[a];
          for(int i=0;i<a;i++){
            m[i] = str.charAt(i);
            M[i] = m[i]-'0';
            sum = sum + M[i];
        }
          System.out.println(sum);
    }
      sc.close();
    }
}


Measured memory_bytes: 26328
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cassert>
#define repeat(i,n) for (int i = 0; (i) < int(n); ++(i))
#define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)
using namespace std;
int main() {
    // input
    int n; scanf("%d", &n);
    vector<int> a(n); repeat (i,n) scanf("%d", &a[i]);
    whole(sort, a);
    whole(reverse, a);
    // compute
    int z = 0;
    assert (z < n and z < a[z]);
    while (z+1 < n and z+1 < a[z+1]) ++ z;
    int dy = a[z] - z - 1;
    int dx = 0;
    while (z + dx+1 < n and z < a[z + dx+1]) ++ dx;
    bool result = (dy % 2 == 1) or (dx % 2 == 1);
    // output
    printf("%s\n", result ? "First" : "Second");
    return 0;
}


Measured memory_bytes: 640
fun main() {
    val mod = 1000000007L
    val (n, k) = readInts()
    val a = readInts().map { it.toLong() }
    val positives = a.filter { it > 0L }.sorted().reversed()
    val zeros = a.filter { it == 0L }
    var negatives = a.filter { it < 0L }.sorted()

    fun mapNumToMod(num: Long): Long {
        val times = kotlin.math.abs(num / mod) + 1
        return (times * mod + num) % mod
    }

    fun addNums(source: List<Long>, destination: MutableList<Long>, from: Int, to: Int): Int {
        destination.addAll(source.subList(from, to))
        return to - from
    }

    if (positives.isEmpty() && zeros.isEmpty()) {
        if (k % 2 == 1) negatives = negatives.reversed()
        val prod = negatives.subList(0, k).map {
            mapNumToMod(it)
        }.reduce { acc, num ->
            (acc * num) % mod
        }
        println(prod)
    } else if (positives.isEmpty() && k % 2 == 1) println(0)
    else if (n - zeros.size < k) println(0)
    else {
        val combined = mutableListOf<Long>()
        var pos = 0
        var neg = 0
        if (k % 2 == 1) {
            combined.add(positives[pos])
            pos++
        }
        while (combined.size < k) {
            if (pos + 2 <= positives.size && neg + 2 <= negatives.size) {
                if (positives[pos] * positives[pos + 1] >= negatives[neg] * negatives[neg + 1]) {
                    pos += addNums(positives, combined, pos, pos + 2)
                } else neg += addNums(negatives, combined, neg, neg + 2)
            } else if (pos + 2 <= positives.size) pos += addNums(positives, combined, pos, pos + 2)
            else if (neg + 2 <= negatives.size) neg += addNums(negatives, combined, neg, neg + 2)
            else {
                if (pos < positives.size) pos += addNums(positives, combined, pos, pos + 1)
                else if (neg < negatives.size) neg += addNums(negatives, combined, neg, neg + 1)
            }
        }

        if (neg % 2 == 1 && zeros.isNotEmpty()) println(0)
        else println(combined.map { mapNumToMod(it) }.reduce { acc, num -> (acc * num) % mod })
//        println(combined)
    }

}

// Input Reader
private fun readLn() = readLine()!!

private fun readStrings() = readLn().trim().split(" ")
private fun readInts() = readStrings().map { it.toInt() }


Measured memory_bytes: 73912
a = [0]*6
for i in range(6):
    a[i] = int(input())
for i in range(5):
    for j in range(i+1,5):
        if abs(a[i]-a[j]) > a[5]:
            print(":(")
            break
    else:
        continue
    break
else:
    print("Yay!")

Measured memory_bytes: 38396
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define vll vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define ub upper_bound
#define lb lower_bound
#define all(v) ((v).begin()),((v).end())
#define allr(v) ((v).rbegin()),((v).rend())
#define ff first
#define ss second
#define mp make_pair
#define pll pair<ll,ll> 
#define fo(i,n) for(ll i=0;i<n;i++)
#define foa(i,s,e) for(ll i=(s);i<e;i++)
#define fod(i,s,e) for(ll i= (s);i>=(e);i--)
#define max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)
#define deb(x) cerr<<#x<<' '<<'='<<' '<<x<<'\n'
#define sz(x) (ll)(x.size())
#define ANS cout<<ans<<'\n'
#define YES cout<<"YES\n"
#define NO cout<<"NO\n"
#define Yes cout<<"Yes\n"
#define No cout<<"No\n"
const ld pi = 3.14159265358979323846;
ll MOD = 1e9 + 7;
//ll MOD = 998244353;
const char nl = '\n';
const ll inf = 1e15;
ll mul(ll x,ll y){
    return (1ll* (x%MOD)*(y%MOD));
}
ll modpow(ll x,ll y){ll z=1;while(y>0){if(y%2)z=mul(z,x);x =mul(x,x) ;y/=2;}return z;}
ll power(ll x,ll y){ll z=1;while(y>0){if(y%2)z=z*x;x =x*x ;y/=2;}return z;}
ll gcd(ll a,ll b){if(a<b) return gcd(b,a);if(b==0) return a;return gcd(b,a%b);} 
ll min(ll a,ll b){if(a<b)return a;return b;}
ll max(ll a,ll b){if(a>b)return a;return b;}
ll sq(ll a){
    ll ans = (1ll*a*a);
    return ans; 
}
void solve()
{
    ll n;
    cin>>n;
    double p[n];
    fo(i,n)
    {
        cin>>p[i];
    }
    double dp[n][n+1];
    ll i,j;
    for(i=0;i<n;i++)
    {
        for(j=0;j<=n;j++)
        {   
            if(i==0)
            {
                if(j>1)
                {
                    dp[i][j]=0.00;
                }
                else
                {
                    if(j==0)
                    {
                        dp[i][j]=1.00-p[i];
                    }
                    else
                    {
                        dp[i][j]=p[i];
                    }
                }
            }
            else if(j==0)
            {
                dp[i][j]=dp[i-1][j]*(1.00-p[i]);
            }
            else
            {   
                if(j>i+1)
                {
                    dp[i][j]=0.00;
                }
                else
                {
                    dp[i][j]=dp[i-1][j]*(1-p[i])+dp[i-1][j-1]*p[i];
                }
            }   
        }
    }
    double ans=0;
    for(i=(n/2)+1;i<=n;i++)
    {
        ans+=dp[n-1][i];
    }
   // cout<<ans<<nl;
    cout << fixed << setprecision(10) << ans;


}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0),cout.tie(0);
    ll TC = 1;
    //cin>>TC;
    while(TC--){
        solve();
    }
}


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

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

using namespace std;

typedef long long ll;

int main()
{
    int N, M, Q;
    cin >> N >> M >> Q;
    int p[Q] = {0}, q[Q] = {0};
    int trainMap[N + 1][N + 1] = {0};
    int trainSumMap[N + 1][N + 1] = {0};
    REP(i, M)
    {
        int L, R;
        cin >> L >> R;
        trainMap[L][R]++;
    }
    REP(i, Q)
    {
        cin >> p[i] >> q[i];
    }
    for (int i = 1; i <= N; ++i)
    {
        for (int j = 1; j <= N; ++j)
        {
            trainSumMap[i][j] = trainSumMap[i][j - 1] + trainMap[i][j];
        }
    }
    
    REP(i, Q)
    {
        int ans = 0;
        for (int j = p[i]; j <= q[i]; ++j)
        {
            ans += trainSumMap[j][q[i]] - trainSumMap[j][p[i] - 1];
        }
        cout << ans << endl;
    }

}


Measured memory_bytes: 3712
n,m=map(int,input().split())
h=list(map(int,input().split()))
s=[]
for _ in range(m):
    a,b=map(lambda x: int(x)-1,input().split())

    if h[a]<=h[b]: s.append(a)
    if h[a]>=h[b]: s.append(b)

print(n-len(set(s)))

Measured memory_bytes: 91148
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define REP(i, n) for(int i=0;i<(n);++i)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1145141919;

int h, w; string s[50];
int d[50][50];
int dx[]={-1,0,1,0}, dy[]={0,1,0,-1};

int bfs(){
	queue<P> que;
	REP(i, 50) REP(j, 50) d[i][j] = INF;
	que.push(P(0, 0));
	d[0][0] = 0;

	while(!que.empty()){
		P p = que.front(); que.pop();
		if(p.first==h-1 and p.second==w-1) break;

		REP(i, 4){
			int nx = p.first+dx[i], ny = p.second+dy[i];
			if(nx>=0 and nx<h and ny>=0 and ny<w and s[nx][ny]=='.' and d[nx][ny]==INF){
				que.push(P(nx, ny));
				d[nx][ny] = d[p.first][p.second]+1;
			}
		}
		// cerr << "wait" << endl;
	}

	return d[h-1][w-1];
}
signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);

	cin >> h >> w;
	REP(i, h) cin >> s[i];

	int ans = 0;
	REP(i, h) REP(j, w){
		if(s[i][j] == '.') ans++;
	}
	if(bfs() == INF) cout << -1 << endl;
	else cout << ans - 1 - bfs() << endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int dfs(unsigned long long now,int len);
unsigned long long x,y;
int maxi=1;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> x >> y;
  int ans=dfs(x,1);
  cout << ans << endl;
  return 0;
}
int dfs(unsigned long long now,int len){
  if(now*2>y)return len;
  int a=dfs(now*2,len+1);
  maxi=max(maxi,a);
  return maxi;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) debug(x) debug(y);
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))
const int MAXN = 1e5 + 5;

template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); }

bool cmp(pi a, pi b){
	return a.se > b.se;
}

template<class T> struct BIT{
	vector<T> bit;
	BIT(){
		bit.assign(MAXN, 0);
	}
	void update(int ind, T delta){
		for(; ind < MAXN; ind = ind | (ind + 1)){
			bit[ind] += delta;
		}
	}
	T query(int ind){
		T sum = 0;
		for(; ind >= 0; ind = (ind & (ind + 1)) - 1){
			sum += bit[ind];
		}
		return sum;
	}
};

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	int n, m;
	cin >> n >> m;
	vector<pi> p;
	rep(i, n){
		int a, b;
		cin >> a >> b;
		if(a <= m) p.pb({a, b});
	}
	BIT<int> bit;
	n = p.size();
	vi pos(m + 1, 0);
	sort(all(p), cmp);
	ll ans = 0;
	rep(i, n){
		if(!pos[m - p[i].fi]){
			pos[m - p[i].fi] = 1;
			bit.update(m - p[i].fi, 1);
			ans += p[i].se;
			continue;
		}
		int l = 0, r = m - p[i].fi;
		while(l < r){
			int mid = (l + r + 1) / 2;
			int num1 = bit.query(m - p[i].fi) - (mid ? bit.query(mid - 1) : 0);
			int num2 = (m - p[i].fi - mid + 1);
			if(num1 < num2) l = mid;
			else r = mid - 1;
		}
		if(!pos[l]){
			pos[l] = 1;
			bit.update(l, 1);
			ans += p[i].se;
		}
	}
	cout << ans << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


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

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

    int n,k,q;
    cin >> n >> k >> q;
    vector<int> a(q);
    for (auto &&ai : a)
        cin >> ai;

    vector<int> cnt_win(n,0);
    for (int i = 0; i < q; i++)
    {
        cnt_win[a[i] - 1]++;
    }

    for (int i = 0; i < n; i++)
    {
        cout << (k - q + cnt_win[i] > 0 ? "Yes" : "No") << endl;
    }
}


Measured memory_bytes: 1408
function myin(){return require("fs").readFileSync("/dev/stdin", "utf8").trim();}

//0:何もしない  1:数値へ変換  2:半角SPで分割  3:改行で分割  4:半角SPで分割し、数値配列へ
//5:改行で分割し、数値配列へ  6:1文字に分割  7:1文字に分割し、数値配列へ
function myconv(i, no){
  switch(no){
    case 0: return i;
    case 1: return parseInt(i);
    case 2: return i.split(" ");
    case 3: return i.split("\n");
    case 4: return i.split(" ").map((a)=>Number(a));
    case 5: return i.split("\n").map((a)=>Number(a));
    case 6: return i.split("");
    case 7: return i.split("").map((a)=>Number(a));
  }}
function Main(input) {
  S = input;
  len = S.length
  let ans = 999999999
  for(let i = 0; i < len; i++ ){
    num = parseInt(S.substr(i, 3), 10);
    ans = Math.min(ans, Math.abs(num - 753));
  }
  console.log(ans);

}
// Main(myin());
Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());

Measured memory_bytes: 29568
#include <stdio.h>
int main(){
	int a,b,c;
	scanf("%d %d %d",&a,&b,&c);
	if(a < b){	
			if(b < c){
				printf("Yes\n");
				}
			else if(b >= c){
				printf("No\n");
				}
	}
	else if(a >= b){
		printf("No\n");	
	}		
}

Measured memory_bytes: 2616
s = input()

start_black = 0
start_white = 0
for i in range(len(s)):
	if i%2 == 0 and s[i] == "1":
		start_black += 1
	if i%2 == 1 and s[i] == "0":
		start_black += 1
	if i%2 == 0 and s[i] == "0":
		start_white += 1
	if i%2 == 1 and s[i] == "1":
		start_white += 1


print(min(start_white, start_black))

Measured memory_bytes: 3188
# by the authority of GOD    author: manhar singh sachdev #

import os,sys
from io import BytesIO, IOBase
from collections import Counter,defaultdict

def main():
    h,w,m = map(int,input().split())
    tar = [tuple(map(int,input().split())) for _ in range(m)]
    tar = set(tar)
    row,col = Counter(),Counter()
    for i in tar:
        row[i[0]] += 1
        col[i[1]] += 1
    row1,col1 = defaultdict(list),defaultdict(list)
    for i in row:
        row1[row[i]].append(i)
    for i in col:
        col1[col[i]].append(i)
    x = max(row1)
    y = max(col1)
    fl = 1
    for i in row1[x]:
        for j in col1[y]:
            if (i,j) not in tar:
                fl = 0
                break
    print(x+y-fl)

#Fast IO Region
BUFSIZE = 8192
class FastIO(IOBase):
    newlines = 0
    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None
    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()
    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()
    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

if __name__ == '__main__':
    main()

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


const ll MOD = 1e9 + 7;
const int MAX = 3 * 1e6;
ll fac[MAX], finv[MAX], inv[MAX];
ll r1, c1, r2, c2;


void input() {
    cin >> r1 >> c1 >> r2 >> c2;
}


void comb_init() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}


ll comb(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


ll s(int r, int c) {
    ll x = 0;
    int i = r + 1;
    for (int j = 1; j <= c + 1; j++) {
        x = (x + comb(i, j)) % MOD;
        i++;
    }
    return x;
}


int main() {
    input();
    comb_init();
    ll ans = 0;
    ans += s(r2, c2);
    ans -= s(r1 - 1, c2);
    ans -= s(r2, c1 - 1);
    ans += s(r1 - 1, c1 - 1);
    ans %= MOD;
    if (ans < 0) ans += MOD;
    cout << ans << endl;
}


Measured memory_bytes: 70528
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) begin(a),end(a)
#define MS(m,v) memset(m,v,sizeof(m))
#define D10  fixed<<setprecision(10)
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> P;
typedef complex<double> Point;
typedef long long ll;
const int INF = 114514810;
const int MOD = 1000000007;
const double EPS = 1e-8;
const double PI = acos(-1.0);
struct edge
{
	int from, to, cost;
	bool operator < (const edge& e) const { return cost < e.cost; }
	bool operator >(const edge& e) const { return cost > e.cost; }
};
///*************************************************************************************///
///*************************************************************************************///
///*************************************************************************************///

int n;
int t[20][20];
int dp[1 << 16];

int solve(int a)
{
	if (a == (1 << n) - 1)
	{
		return dp[a] = 0;
	}
	if (dp[a] >= 0) return dp[a];
	int res = INF;
	REP(i, n)
	{
		if (!((a >> i) & 1))
		{
			int tmp = t[i][0];
			REP(j, n)
			{
				if (a >> j & 1 == 1) tmp = min(tmp, t[i][j + 1]);
			}

			res = min(res, solve(a + (1 << i)) + tmp);
		}
		
	}
	return dp[a] = res;
}

int main()
{
	while (cin >> n, n)
	{
		REP(i, n)
		{
			REP(j, n + 1) cin >> t[i][j];
		}
		MS(dp, -1);
		cout << solve(0) << endl;
	}
	return 0;
}

Measured memory_bytes: 1424
n,m,p = map(int, input().split())
G = []
for i in range(m):
    a,b,c = map(int, input().split())
    G.append([a,b,c-p])

def bellmanFord(G, start_vertex):
    distance = [-float('inf') for i in range(n+1)]
    distance[start_vertex] = 0
    for i in range(2*n):
        for node,neighbor,cost in G:
            if distance[neighbor] < distance[node] + cost:
                if i < n:
                    distance[neighbor] = distance[node] + cost
                else:
                    distance[neighbor] = float('inf')
        if i == n-1:
            prev_ans = distance[n]
    if prev_ans != distance[n]:
        return -1
    else:
        return distance[n]

distance = bellmanFord(G, 1)
if distance == -1:
    ans = -1
else:
    ans = max(0, distance)
print(ans)


Measured memory_bytes: 75912
#include <stdio.h>

int main(void) {

	int W,H,x,y,r;
	scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);

	if(x>=r && x<=W-r && y>=r && y<=H-r){
		printf("Yes\n");

	} else {
		printf("No\n");


	}
    return 0;
}

Measured memory_bytes: 584
# coding:UTF-8
import sys
from math import factorial

MOD = 10 ** 9 + 7
INF = 10000000000

# 二分探査
def binary_search(list, item):
    # 1:以上 2:以下　
    mode = 2
    low = 0
    high = len(list) - 1
    upper = len(list) - 1
    lower = 0
    while low <= high:
        mid = (low + high) // 2
        guess = list[mid]
        if guess == item:
            return mid
        if guess > item:
            high = mid - 1
            upper = mid
        else:
            low = mid + 1
            lower = mid
    if mode == 1:
        return upper
    elif mode == 2:
        return lower

def main():
    # ------ 入力 ------#
    N, Q = list(map(int, input().split()))     # スペース区切り連続数字

    queList = [list(map(int, input().split())) for _ in range(Q)]     # スペース区切り連続数字(行列)

    # ------ 処理 ------#
    black = (N-2)**2
    m = [N, N]
    chList = [[-1] * N for _ in range(2)]
    for que in queList:
        x = que[1]
        y = que[0]-1
        ch = chList[y][x]
        if ch == -1:
            ch = m[1-y] - 2
            m[y] = x
            i = 0
            while x+i <= N-1 and chList[y][x+i] == -1:
                chList[y][x+i] = m[1-y] - 2
                i = i + 1
        black -= ch

    # ------ 処理 ------#
    # black = (N-2)**2
    # div = [{2: N-2}, {2: N-2}]
    # for que in queList:
    #     x = que[1]
    #     y = que[0]-1
    #     kl = list(div[y].keys())
    #     d = binary_search(kl, x)
    #     ch = div[y][kl[d]]
    #     black -= ch
    #     if d == 0:
    #         div[y][x] = div[y][kl[d]]
    #         div[y] = dict(sorted(div[y].items(), key=lambda x:x[0]))
    #         div[1-y][list(div[1-y].keys())[d]] = max(x-2, 0)

    # ------ 出力 ------#
    print("{}".format(black))

if __name__ == '__main__':
    main()


Measured memory_bytes: 109632
#include<bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define int long long
#define vec(a,n) vector<int> (a)((n))
#define Vec(a,n) vector<string> (a)((n))
#define P pair<int,int>
#define PQ(n) priority_queue<P,vector<P>,greater<P>> (n)
#define pq(n) priority_queue<int> (n)
using namespace std;

signed main(){
    int n,h,w;
    cin >> n >> h >> w;
    int ans=0;
    REP(i,n){
        int a,b;
        cin >> a >> b;
        if(a>=h&&b>=w){
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


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

int main(){
    int n, k;
    cin >> n >> k;
    if(n == 0){
        cout << n << endl;
    }
    int i = 0;
    string ans;
    while(n != 0){
        int rem = n % k;
        n = n / k;
        ans = ans + to_string(rem);
    }
    cout << ans.length() << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    while(1){
        int mn=1000000,mx=0;
        int sum=0,a;
        cin>>n;
        if(n==0){break;}
        for(int i=0;i<n;i++){
            cin>>a;
            mx=max(a,mx);
            mn=min(a,mn);
            sum+=a;
        }
        sum-=mx;
        sum-=mn;
        cout<<sum/(n-2)<<endl;
    }
        
    return 0;
    
}



Measured memory_bytes: 2996
#include <math.h>
#include <iostream>
#include<string>
#include <algorithm>
#include <bits/stdc++.h>
#include <vector>
#include <stdlib.h>
using namespace std;

int main()
{
string S;cin >> S;
for(int i=0;i<S.size();i++){cout << 'x';}
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String args[]){

		Scanner cin = new Scanner(System.in);
		String s1 = String.valueOf(cin.next().charAt(0)).toUpperCase();
		String s2 = String.valueOf(cin.next().charAt(0)).toUpperCase();
		String s3 = String.valueOf(cin.next().charAt(0)).toUpperCase();

		System.out.println(s1+s2+s3);
	}
}


Measured memory_bytes: 21972
#include <iostream>
#include <iterator>
#include <algorithm>
#include <vector>

using namespace std;
typedef long long LL;

int main(){
  string S;
  cin >> S;
  if(S.size()>=4){
	if(S[0]=='Y'&&S[1]=='A'&&S[2]=='K'&&S[3]=='I'){
	  cout << "Yes" << endl;
	  return 0;
	}
  }

  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    int tmp;
    cin >> tmp;
  }
  int ret = ((n - 1) + (k - 2)) / (k - 1);
  cout << ret << '\n';
  return 0;
}

Measured memory_bytes: 256
/*d[x][y]=min{f[i][j]+i*x+j*y
  f[x][y]=max{d[i][j]-i*x-j*y*/
#include<bits/stdc++.h>
using namespace std;
#define int long long
inline int read() {
	int x(0),neg(1);char ch(getchar());
	while(!isdigit(ch)) {
		if (ch=='-') neg=-1;
		ch=getchar();
	}
	while(isdigit(ch)) {
		x=(x<<1)+(x<<3)+(ch^48);
		ch=getchar();
	}
	return x*neg;
}
const int maxn=300;
int f[maxn+5][maxn+5],d[maxn+5][maxn+5];
signed main() {
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	int n(read()),m(read());
	for (int i=1;i<=n;++i) {
		for (int j=1;j<=m;++j) {
			d[i][j]=read(); 
		}
	}
	for (int x=0;x<=100;++x) {
		for (int y=0;y<=100;++y) {
			for (int i=1;i<=n;++i) {
				for (int j=1;j<=m;++j) {
					f[x][y]=max(f[x][y],d[i][j]-i*x-j*y);
				}
			}
		}
	}
	int minv;
	for (int x=1;x<=n;++x) {
		for (int y=1;y<=m;++y) {
			minv=2147483647;
			for (int i=0;i<=100;++i) {
				for (int j=0;j<=100;++j) {
					minv=min(minv,f[i][j]+i*x+j*y);
				}
			}
			if (minv!=d[x][y]) {
				puts("Impossible");
				return 0;
			}
		}
	}
	puts("Possible");
	puts("202 10401");
	for (int i=1;i<=100;++i) {
		printf("%lld %lld X\n",i,i+1);
	}
	for (int j=102;j<=201;++j) {
		printf("%lld %lld Y\n",j,j+1);
	}
	for (int i=0;i<=100;++i) {
		for (int j=0;j<=100;++j) {
			printf("%lld %lld %lld\n",i+1,202-j,f[i][j]);
		}
	}
	puts("1 202");
	return 0;
}


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

const int N = 3e5 + 9;

int32_t main()
{
    int a, b, c; cin >> a >> b >> c;
    swap(a, b); swap(a, c);
    cout << a << ' ' << b << ' ' << c << endl;
    return 0;
}


Measured memory_bytes: 256
import itertools
import math
import string
import collections
from collections import Counter
from collections import deque
import sys
sys.setrecursionlimit(2*10**5)
INF = 2**60


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]
N, M = map(int, input().split())
a = readints()
sum = 0
for i in range(M):
    sum += a[i]
if N < sum:
    print(-1)
if N >= sum:
    print(N-sum)


Measured memory_bytes: 69104
import java.util.Scanner


object Main {
  def read(): (String, Int) = {
    val sc = new Scanner(System.in)
    val s = sc.next()
    val k = sc.nextInt()
    (s, k)
  }

  // 区間(startは含める。endは含めない)
  case class Section(start: Int, end: Int)

  /**
    * 文字列strの長さk以下の部分文字列を返す
    */
  def calcSubstrings(str: String, k: Int): List[String] = {
    // 切り取り区間全体を求めてmapする
    val lengthList = 1 to k
    val strLen = str.length
    val sections =
      str.indices
        .flatMap(i => lengthList.map(len => Section(i, i + len)))
        .filter(section => section.end <= strLen)

    sections.map(section => str.substring(section.start, section.end)).toList
  }

  def main(args: Array[String]): Unit = {
    val (str, k) = read()
    val substrings = calcSubstrings(str, k) // 長さk以下の部分文字列
    // 重複を除く必要あり
    val sortedSubstrings = substrings.distinct.sorted
    val result = sortedSubstrings(k - 1) // 1オリジンk番目
    println(result)
  }
}

Measured memory_bytes: 34392
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
const ll INF=1e18;

int main() {
  string	n;
  ll ans = 0;
  cin >> n;
  rep(i,n.size()){
    ans+=n[i] - '0';
  }
  if(ans%9==0) cout << "Yes" <<endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 3740
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/Tree_policy.hpp>
//using namespace __gnu_pbds;
using namespace std;
#define SC               scanf
#define PF               printf
#define ull              unsigned long long
#define ld               long double
#define D                double
#define F                first
#define S                second
#define pb               push_back
#define pf               push_front
#define MP               make_pair
#define sort_a(a)        sort(a.begin(),a.end());
#define sort_d(a)        sort(a.rbegin(),a.rend());
#define READ(f)          freopen(f, "r", stdin)
#define WRITE(f)         freopen(f, "w", stdout)
#define rev(s)           reverse(s.begin(),s.end())
#define it(it,mp)        for(auto it=mp.begin() ; it!=mp.end() ; it++)
#define IOS              ios_base :: sync_with_stdio(false); cin.tie(NULL);
#define ll long long
typedef pair<int,int>                   PII;
#define ordered_set Tree<PII, null_type,less<PII>, rb_Tree_tag,Tree_order_statistics_node_update>
const int N = 1e5 + 5;
const int inf = 1e9 + 1;
const double eps = 1e-15;
const double EPS = 1e-9;
const double PI = acos(-1.0);
int main()
{
    // IOS
    //READ("0test.txt");
    //WRITE("");
    int n;
    cin >> n;
    vector<int> t(n), x(n), y(n);

    for (int i = 0; i < n; i++)
    {
        cin >> t[i] >> x[i] >> y[i];
    }

    int ntime = 0, nx = 0, ny = 0;
    for (int i = 0; i < n; i++)
    {
        int time = t[i] - ntime;
        int distance = abs(x[i] - nx) + abs(y[i] - ny);
        if(time < distance)
        {
            return cout<<"No\n", 0 ;
        }
        else
        {
            if((time - distance) % 2 != 0)
                return cout<<"No\n",0;
        }
        ntime = t[i];
        nx = x[i];
        ny = y[i];
    }
    cout <<"Yes\n";


}



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

using namespace std;

void print(int h,int m){
  cout << h << ":";
  if(m<10) cout << 0;
  cout << m;
}

int main(){
  int n; cin >> n;
  vector<int> hm(n+1);
  int k,g;
  for(int i=0;i<n;++i) {
    cin >> k >> g;
    hm[i]=k*60+g;
  }
  int m; cin >> m;
  vector<int> kg(m+1);
  for(int i=0;i<m;++i) {
    cin >> k >> g;
    kg[i]=k*60+g;
  }
  hm[n]=kg[m]=1e9;
  int i=0,j=0;
  while(i+j<n+m){
    if(i+j) cout << " ";
    if(hm[i]==kg[j]) print(hm[i]/60,hm[i]%60),i++,j++;
    else if(hm[i]<kg[j]) print(hm[i]/60,hm[i]%60),i++;
    else print(kg[j]/60,kg[j]%60),j++;
  }
  cout << endl;
  
  return 0;
}


Measured memory_bytes: 3084
#include <bits/stdc++.h> 
using namespace std;
#define rep(i, N) for(int i=0; i<N; i++)
typedef long long ll;
#define dump(x) cerr<<#x<<"="<<x<<endl
using P = pair<int, int>;

bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; 
    double sqrtNum = sqrt(num);
    for(int i=3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return false;
        }
    }

    return true;
}


int main() {
    int n;cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a.at(i);

    vector<pair<ll, int>> p;
    rep(i, n){
        p.push_back(make_pair(a.at(i), i+1));
    }

    sort(p.begin(), p.end());

    int cnt = 0;
    map<ll, ll> mp, mp2;

    rep(i, n){
        mp2[a.at(i)]++;
    }

    rep(i, n){
        if(p.at(i).first==1){
            if(mp2[1]<=1) {
               cout << 1 << endl;
               return 0;
            }
            else{
                cout << 0 << endl;
                return 0;
            }
        }


        if(mp[p.at(i).first]==0){
            if(mp2[p.at(i).first]<=1) cnt++;
            ll tmp = p.at(i).first;

            while(tmp<=1e6+1){
                mp[tmp]++;
                tmp += p.at(i).first;
            }
        }
    }

    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 72500
#include<stdio.h>
int main(void)
{
    int n, i, masatoy[10000];
    int str[10] = { 0,0,0,0,0,0,0,0,0,0 }, k;
    scanf("%d", &n);
    while (n > 0) {
        for (i = 0; i < n; i++) {
            scanf("%d", &masatoy[i]);
            for (k = 0; k <= 9; k++) {
                if (masatoy[i] == k) {
                    str[k]++;
                }
            }

        }
        for (i = 0; i <= 9; i++) {
            if (str[i] == 0) {
                printf("-\n");
            }
            else {
                for (k = 0; k < str[i]; k++) {
                    printf("*");
                }
                printf("\n");
            }

        }
        scanf("%d", &n);
        for (i = 0; i <=9; i++) {
            str[i] = 0; 
     
        }
    }
    return 0;
}

Measured memory_bytes: 1036
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep1(i, n) for (ll i = 1; i <= (n); ++i)
#define rrep(i, n) for (ll i = (n - 1); i >= 0; --i)
#define perm(c) sort(ALL(c));for(bool c##p=1;c##p;c##p=next_permutation(ALL(c)))
#define ALL(obj) (obj).begin(), (obj).end()
#define pb push_back
#define to_s to_string
#define len(v) (ll)v.size()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define print(x) cout << (x) << '\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
using namespace std;
using ll = long long;
typedef pair<ll, ll> P;
typedef vector<ll> vec;
typedef vector<vector<ll>> vec2;
typedef vector<vector<vector<ll>>> vec3;
ll MOD = 1e9 + 7;
ll devc(ll x, ll y) { return 1 + (x - 1) / y; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

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

    ll H, W;
    cin >> H >> W;
    vec2 g(H + 1, vec(W + 1, '#'));
    vec2 dp(H + 10, vec(W + 10, 0));
    rep1(i, H){
        string s;
        cin >> s;
        rep1(j, len(s)) g[i][j] = s[j - 1];
    }

    dp[1][1] = 1;
    g[1][1] = '#';
    
    rep1(i, H) rep1(j, W){
        if(g[i][j] != '#') dp[i][j] = dp[i - 1][j] + dp[i][j - 1];
        dp[i][j] %= MOD;
    }

    print(dp[H][W]);

    return 0;
}

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

int main()
{
    string s; cin>>s;
    int N=s.size();
    vector<int> ans(N);
    for(int i=0;i<N;){
        int l=i;
        while(i<N and s[i]=='R') i++;
        int m=i;
        while(i<N and s[i]=='L') i++;
        int r=i;
        ans[m-1]=(m-l+1)/2+(r-m)/2;
        ans[m  ]=(m-l)/2+(r-m+1)/2;
    }
    for(int i=0;i<N;i++){
        cout<<ans[i]<<endl;
    }
    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<map>
using namespace std;
int main(){
	int n;
	cin>>n;
	int v;
	map<int,int> m0,m1;
	int l=n;
	while(l--){
		cin>>v;
		if(l%2==1){
			if(m0.find(v)==m0.end()) m0.insert(make_pair(v,1));
			else m0[v]++;
		}
		else{
			if(m1.find(v)==m1.end()) m1.insert(make_pair(v,1));
			else m1[v]++;
		}
	}
	int ans0=0;
	int next0=0;
	int v0=0;
	for(auto itr=m0.begin();itr!=m0.end();itr++){
		if(ans0<=itr->second){
			next0=ans0;
			ans0=itr->second;
			v0=itr->first;
		}else if(next0<=itr->second) next0=itr->second;
	}
	int ans1=0;
	int next1=0;
	int v1=0;
	for(auto itr=m1.begin();itr!=m1.end();itr++){
		if(ans1<=itr->second){
			next1=ans1;
			ans1=itr->second;
			v1=itr->first;
		}else if(next1<=itr->second) next1=itr->second;
	}
	if(v0==v1){
		if(ans0+next1>next0+ans1) ans1=next1;
		else ans0=next0;
	}
	cout << n-(ans0+ans1) << endl;	
}


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

int main() {
  int N; cin >> N;
  set<string> s; string last = "";
  for (int i = 0; i < N; i++) {
    string input; cin >> input;
    if (s.count(input)) { cout << "No"; return 0; }
    if (i > 0 && input[0] != last[last.length() - 1]) {
      cout << "No"; return 0;
    }
    s.insert(input);
    last = input;
  }
  cout << "Yes";
}


Measured memory_bytes: 256
import math

N ,K = [int(i) for i in input().split()]


def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
for i in range(int(K)):
  if (int(N)-int(K)+1-( i+1))>=0:
    print((combinations_count(int(K)-1, i))*(combinations_count(int(N)-int(K)+1, i+1))%1000000007)
  else:
    print(0)

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


int main(){
  int N, K;
  cin >> N >> K;
  vector<int> A(N, 0);
  for(int ii=0; ii<K; ii++){
    int d;
    cin >> d;
    for(int jj=0; jj<d; jj++){
      int id;
      cin >> id;
      A[id-1]++;
    }
  }

  int ans=0;
  for(int ii=0; ii<N; ii++){
    if(A[ii]==0) ans++;
  }

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


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

nums = [(i+1) * 2 for i in range(n)] + [(i * 2) + 1 for i in range(m)]

ans = 0
for i in range(len(nums)):
    for j in range(i):
        if (nums[i] + nums[j]) % 2 == 0:
            ans += 1
print(ans)

Measured memory_bytes: 3064
n,t = map(int,input().split())
ct = [list(map(int,input().split())) for i in range(n)]
c = 1001
for i in range(n):
  if ct[i][1] <= t:
    c = min(c,ct[i][0])
print(c) if c < 1001 else print('TLE')

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout <<(#x)<<" is "<<(x)<<endl
#define debug cout <<"hi"<<endl
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
const int MOD=998244353;
const int INF32=1<<30;
const ll INF64=1LL<<60;

vector<ll>fact;
ll mp(ll b, ll i){
  ll s=1;
  while(i){
    if(i%2) s=(s*b)%MOD;
    b=(b*b)%MOD; i/=2;
  }
  return s;
}
ll nCr(ll n, ll r){
  ll s=(fact[r]*fact[n-r])%MOD;
  return (fact[n]*mp(s,MOD-2))%MOD;
}
int main(){
  int n,m,k; cin >>n >>m >>k; ll sum=0;
  fact.resize(n+1); fact[0]=1;
  for(int i=1; i<=n; i++) fact[i]=(fact[i-1]*i)%MOD;
  for(int i=0; i<=k; i++){
    sum+=(nCr(n-1,i)*mp(m-1,n-i-1))%MOD; sum%=MOD;
  }
  cout <<(sum*m)%MOD;
return 0;}

Measured memory_bytes: 4740
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
typedef int64_t Int;

int main(){ 
    Int A,B,N,ans;

    cin >> A >> B >> N;

    if (N >= B) N = B-1;

    if (N == 0) ans = 0;
    else {
        ans = A * N / B;
    }

    cout << ans << endl;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, n) for(int i = 0; i < (n); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define pb push_back
 
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
 
  string S;
  int w;
 
  cin >> S;
  cin >> w;
 
  int a = 0;
  while(true) {
    if(a >= S.size()) break;
    cout << S[a];
    a = a + w;
  }
  
  cout << endl;
}

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

int main() {
  auto min = [](auto x, auto y) { return (x < y) ? x : y; };
  auto argmin = [&min](std::vector<int>& v) {
    int res{2000000000};
    for (auto&& e : v) res = min(res, e);
    return res;
  };

  int A, B, M;
  std::cin >> A >> B >> M;
  std::vector<int> a(A), b(B);
  for (int i = 0; i < A; i++) std::cin >> a[i];
  for (int i = 0; i < B; i++) std::cin >> b[i];

  int res{argmin(a) + argmin(b)};
  for (int i = 0; i < M; i++) {
    int x, y, c;
    std::cin >> x >> y >> c;
    x--;
    y--;
    res = min(res, a[x] + b[y] - c);
  }
  printf("%d", res);
}

Measured memory_bytes: 1024
from sys import stdin

S = stdin.readline().rstrip()

white_odd = 0
white_even = 0
N = len(S)

i = 0
while i < N:
    if S[i] == '1':
        white_odd += 1
    if not i+1 < N:
      break
    if S[i+1] == '0':
        white_odd += 1
    i += 2
white_even = N - white_odd


if white_odd < white_even:
    print(white_odd)
else:
    print(white_even)

Measured memory_bytes: 3188
#!/usr/bin/env python3
#AGC10 A

import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
a = LI()
cnt = 0
for i in range(n):
    if a[i] % 2:
        cnt += 1
if cnt % 2:
    print('NO')
else:
    print('YES')


Measured memory_bytes: 58608
import sys

MOD = 10 ** 9 + 7
n = int(sys.stdin.readline().rstrip())

def main():
    res = 1
    for i in range(1, n+1):
        res *= i
        res %= MOD

    return res

if __name__ == '__main__':
    ans = main()
    print(ans)

Measured memory_bytes: 2940
void main()
{
    long n = rdElem;

    string s = "ACGT";
    long[][][][] dp = new long[][][][](n+1, 4, 4, 4);
    foreach (i, a; s)
    {
        foreach (j, b; s)
        {
            foreach (k, c; s)
            {
                if (a == 'A' && b == 'G' && c == 'C') continue;
                if (a == 'A' && b == 'C' && c == 'G') continue;
                if (a == 'G' && b == 'A' && c == 'C') continue;
                dp[3][i][j][k] = 1;
            }
        }
    }

    foreach (i; 3 .. n)
    {
        foreach (j, a; s)
        {
            foreach (k, b; s)
            {
                foreach (l, c; s)
                {
                    foreach (m, d; s)
                    {
                        if (b == 'A' && c == 'G' && d == 'C') continue;
                        if (b == 'A' && c == 'C' && d == 'G') continue;
                        if (b == 'G' && c == 'A' && d == 'C') continue;
                        if (a == 'A' && c == 'G' && d == 'C') continue;
                        if (a == 'A' && b == 'G' && d == 'C') continue;
                        dp[i+1][k][l][m] = (dp[i+1][k][l][m] + dp[i][j][k][l]) % mod;
                    }
                }
            }
        }
    }

    long result;
    foreach (i, a; s)
    {
        foreach (j, b; s)
        {
            foreach (k, c; s)
            {
                result = (result + dp[n][i][j][k]) % mod;
            }
        }
    }

    result.writeln;
}

enum long mod = 10^^9 + 7;
enum long inf = 1L << 60;
enum double eps = 1.0e-9;

T rdElem(T = long)()
if (!is(T == struct))
{
    return readln.chomp.to!T;
}

alias rdStr = rdElem!string;
alias rdDchar = rdElem!(dchar[]);

T rdElem(T)()
if (is(T == struct))
{
    T result;
    string[] input = rdRow!string;
    assert(T.tupleof.length == input.length);
    foreach (i, ref x; result.tupleof)
    {
        x = input[i].to!(typeof(x));
    }
    return result;
}

T[] rdRow(T = long)()
{
    return readln.split.to!(T[]);
}

T[] rdCol(T = long)(long col)
{
    return iota(col).map!(x => rdElem!T).array;
}

T[][] rdMat(T = long)(long col)
{
    return iota(col).map!(x => rdRow!T).array;
}

void rdVals(T...)(ref T data)
{
    string[] input = rdRow!string;
    assert(data.length == input.length);
    foreach (i, ref x; data)
    {
        x = input[i].to!(typeof(x));
    }
}

void wrMat(T = long)(T[][] mat)
{
    foreach (row; mat)
    {
        foreach (j, compo; row)
        {
            compo.write;
            if (j == row.length - 1) writeln;
            else " ".write;
        }
    }
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.mathspecial;
import std.traits;
import std.container;
import std.functional;
import std.typecons;
import std.ascii;
import std.uni;
import core.bitop;

Measured memory_bytes: 380
from collections import defaultdict,deque
import math
def main():
    h,w=map(int, input().split())
    res = []
    for i in range(h):
        b=input()
        res.append(b)
        res.append(b)
    for i in res:
        print(i)
if __name__ == '__main__':
    main()


Measured memory_bytes: 9472
n, m = list(map(int, input().split()))
data = dict()
div = 2
mod = 10**9+7
#互いに素なa,bについて、a*x+b*y=1の一つの解
def extgcd(a,b):
    r = [1,0,a]
    w = [0,1,b]
    while w[2]!=1:
        q = r[2]//w[2]
        r2 = w
        w2 = [r[0]-q*w[0],r[1]-q*w[1],r[2]-q*w[2]]
        r = r2
        w = w2
    #[x,y]
    return [w[0],w[1]]

# aの逆元(mod m)を求める。(aとmは互いに素であることが前提)
#a/b = a*(b`)となるb`を求める
def mod_inv(a,mod):
    x = extgcd(a,mod)[0]
    return (mod+x%mod)%mod
def mod_factorial(n):
    ans = 1
    while n >= 2:
        ans  = (ans * n) % mod
        n -= 1
    return ans
while m > 1:
    count = 0
    flag = False
    while m % div == 0:
        if div not in data:
            data[div] = 0
        flag = True
        m /= div
        count += 1
        data[div] += 1
    div += 1
ans = 1
for i in data.keys():
    p = mod_factorial(data[i]+n-1)
    q = mod_inv(mod_factorial(data[i]), mod)
    r = mod_inv(mod_factorial(n-1), mod)
    ans *= p * q
    ans %= mod
    ans *= r
    ans %= mod
print(ans)


Measured memory_bytes: 40044