akhauriyash/Code-Regression huggingface dataset:
//#pragma warning disable
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System;
using System.Numerics;
using System.Threading.Tasks;
using static System.Math;
using static System.Console;
class Z { static void Main() => new K(); }
class K
{
	int F() => int.Parse(ReadLine());
	long FL() => int.Parse(ReadLine());
	int[] G() => ReadLine().Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();
	long[] GL() => ReadLine().Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries).Select(long.Parse).ToArray();
	public const int MOD = 1000000007;
	public K()
	{
		SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
		Solve();
		Out.Flush();
	}
	long[] fact, ifact;
	void Solve()
	{
		var N = F();
		fact = new long[N + 10];
		fact[0] = 1;
		for (var i = 1; i < N + 10; i++) fact[i] = i * fact[i - 1] % MOD;
		ifact = new long[N + 10];
		for (var i = 0; i < N + 10; i++) ifact[i] = Inverse(fact[i]);
		var a = G();
		var cnt = new int[N];
		foreach (var x in a) cnt[x - 1]++;
		var j = 0;
		while (cnt[j] == 1) j++;
		var dup = new List<int>();
		for (var i = 0; i <= N; i++) if (a[i] == j + 1) dup.Add(i);
		var len = dup[1] - dup[0] + 1;
		for (var k = 1; k <= N + 1; k++)
		{
			var x = (Comb(N + 1, k) - Comb(N + 1 - len, k - 1)) % MOD;
			if (x < 0) x += MOD;
			Console.WriteLine(x);
		}
	}
	long Comb(int n, int m)
	{
		if (m < 0) return 0;
		if (m > n) return 0;
		return fact[n] * ifact[m] % MOD * ifact[n - m] % MOD;
	}
	static long Inverse(long m)
	{
		long a = 1, b = 0, c = 0, d = 1, n = MOD;
		while (m > 0)
		{
			var r = n % m;
			var q = n / m;
			n = m;
			m = r;
			var tmp = a;
			a = -a * q + b;
			b = tmp;
			tmp = c;
			c = -c * q + d;
			d = tmp;
		}
		return b < 0 ? b + MOD : b;
	}
}


Measured memory_bytes: 30300
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
const int MM = 1000000000;
const int MOD = MM + 7;
const int MAX = 510000;
#define rep(i, n) for(ll i=0; i<n; i++)
#define Rep(i, j, n) for(ll i=j; i<n; i++)
#define all(vec) vec.begin(), vec.end()
template<class T> inline bool chmin(T& a, T b) {if(a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if(a < b) {a = b; return true;} return false;}
const ll INF = 1LL << 60;

ll dp[100100][3];

int main() {
    int n; cin >> n;
    vector<int> a(n), b(n), c(n);
    rep(i, n) cin >> a[i] >> b[i] >> c[i];
    dp[0][0] = a[0];
    dp[0][1] = b[0];
    dp[0][2] = c[0];
    rep(i, n) {
        dp[i+1][0] = max(dp[i][1], dp[i][2]) + a[i+1];
        dp[i+1][1] = max(dp[i][0], dp[i][2]) + b[i+1];
        dp[i+1][2] = max(dp[i][0], dp[i][1]) + c[i+1];
    }
    cout << max({dp[n-1][0], dp[n-1][1], dp[n-1][2]}) << endl;
}

Measured memory_bytes: 6676
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int N,M;
    cin>>N>>M;
    vector<int> count(M);
    for(int i = 0; i < N; i++)
    {
        int K;cin>>K;
        for(int j = 0; j < K; j++)
        {
            int A;cin>>A;--A;
            ++count.at(A);
        }
        
    }
    int ans=0;
    for(int i = 0; i <M; i++)
    {
        if (count.at(i)==N) {
            ans++;
        }
        
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const int mod=1e9+7;
const int maxn=2000;
int n,k;
int f[maxn+8][maxn+8],g[maxn+8][maxn+8];

int read()
{
    int x=0,f=1;char ch=getchar();
    for (;ch<'0'||ch>'9';ch=getchar()) if (ch=='-') f=-1;
    for (;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';
    return x*f;
}

int power(int a,int k)
{
    if (k<0) return 1;
    int sum=1;
    for (;k;k>>=1,a=1ll*a*a%mod)
    if (k&1)
        sum=1ll*sum*a%mod;
    return sum;
}

int main()
{
    n=read(),k=read();
    g[0][0]=1;
    for (int i=1;i<n;i++)
	{
	    f[i][0]=g[i-1][0];
	    g[i][0]=f[i][0];
	    for (int j=1;j<=i;j++)
		{
		    f[i][j]=g[i-1][j];
		    g[i][j]=(g[i][j-1]+f[i][j])%mod;
		}
	}
    //for (int i=0;i<n;i++) printf("%d ",g[n-1][i]);
    int ans=g[n-1][k-1];
    ans=1ll*ans*power(2,n-k-1)%mod;
    printf("%d\n",ans);
    return 0;
}

    


Measured memory_bytes: 30848
// </> : towhid1zaman

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair< int, int > pii;
typedef pair< pii, int > ppi;
#define fill(a,b) memset(a,b,sizeof(a))
#define all(v) (v).begin(),(v).end()
#define sp(k) cout<<setprecision(k)<<fixed;
#define rep(i,a) for(int i=0;i<a;i++)
#define rep1(i,a,b) for(int i=(a);i<=(b);++i)
#define irep(i,b,a) for(int i=(b);i>=(a);--i)
#define minv(v) *min_element(all(v))
#define maxv(v) *max_element(all(v))
#define unq(v) (v).erase(unique(all(v)),(v).end())
#define _ ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl "\n"
#define sqr(a) ((a)*(a))
#define sz(a) int(a.size())
#define ff first
#define ss second
#define pb push_back

const double pi = acos(-1.0);
const int mod = 1000000007; // (int)1e9+7
const int inf = 0x3f3f3f3f;
const int maxn = 2000100;


string s;
int main(){
        _
	cin>>s;
	rep(i,sz(s)){
		if(s[i]=='?'){
                s[i] = 'D';
			}
		}
	cout<< s <<endl;


return 0;
}




Measured memory_bytes: 3784
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<int>a(N);
  int count2 = 0;
  int count4 = 0;
  for (int i = 0; i < N; i++) {
    cin >> a.at(i);
    if (a.at(i) % 2 == 0){
      count2++;
    }
    if (a.at(i) % 4 == 0){
      count4++;
    }
  }
  
  if ((N - count2 + count4 + 1)/2 <= count4){
    cout << "Yes" << endl;
  }
  else if (count4 >= N/2 || count2 == N){
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}
    
  
  

Measured memory_bytes: 3704
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

//struct edge {int from, to, cost;};

constexpr double EPS = 1e-10;
constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;

template<class T> inline T sqr(T x) {return x*x;}

void solve() {
    int n, k;
    cin >> n >> k;
    cout << ((n - 1) + k - 2) / (k - 1) << endl;
    /*
    VI a(n);
    REP(i,0,n) cin >> a[i];
    int last = -1;
    int pos;
    REP(i,0,n) if (a[i] == 1) pos = 1;
    */
}

int main() {
    solve();
    
    return 0;
}

Measured memory_bytes: 256
import sys
import math
import fractions
from collections import deque
from collections import defaultdict
sys.setrecursionlimit(10**7)

N, M, Q = map(int, input().split())
dp = [[0] * M for _ in range(N)]
conds = []
for i in range(Q):
    a, b, c, d = map(int, input().split())
    a -= 1
    b -= 1
    conds.append([a, b, c, d])

ans = 0


def dfs(cur, l):
    global ans
    if len(l) == N:
        s = 0
        for cond in conds:
            a, b, c, d = cond
            if l[b] - l[a] == c:
                s += d
        ans = max(ans, s)
        return

    for i in range(cur, M+1):
        dfs(i, l + [i])


dfs(1, [1])
print(ans)


Measured memory_bytes: 77156
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a),i##formax=(b);i<i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formax=(b);i>=i##formax;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)
#define show(x) cout<<#x<<" = "<<x<<endl;
#define all(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))
#define bitComb(a,n,k) for(int a##x,a##y,a=(1<<k)-1;a<(1<<n);a##x=a&-a,a##y=a+a##x,a=(((a&~a##y)/a##x)>>1)|a##y)
#define uniq(v) sort(all(v));v.erase(unique(all(v)), v.end())
#define bit(n) (1LL<<(n))
#define randInt(l,r) (uniform_int_distribution<ll>(l,r)(rnd))
#define randDouble(l,r) (uniform_real_distribution<double>(l,r)(rnd))
#define dout(d) printf("%.12f\n",d)

typedef long long ll;
typedef __int128_t lll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>ostream& operator<<(ostream& o,const pair<T,Y>& p){return o<<"("<<p.fi<<", "<<p.se<<")";}
template<typename A,size_t N,typename T>void Fill(A (&array)[N],const T&v){fill((T*)array,(T*)(array+N),v);}
lll gcd(lll a,lll b,lll &x,lll &y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll gcd(ll a,ll b){lll x=0,y=0;return gcd(a,b,x,y);}
ll modInv(ll a,ll m){lll x,y;gcd(a,m,x,y);return (x%m+m)%m;}
ll modPow(lll a,lll n,ll m){if(!a)return a;lll p=1;for(;n>0;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return(ll)p;}
bool isPrime(ll n){if(n<2||n%2==0)return n==2;lll t=n-1,d=t/(t&-t);for(lll a:{2,325,9375,28178,450775,9780504,1795265022})if(a%n){for(t=d,a=modPow(a,t,n);t!=n-1&&a!=1&&a!=n-1;a=a*a%n,t=t*2%n);if(a!=n-1&&t%2==0)return 0;}return 1;}
const int IINF = 1e9+6;
const ll LINF = 1e18;
const int MOD = 1e9+7;
const double PI = acos(-1);
const double EPS = 1e-10;
static random_device rd;
static mt19937 rnd(rd());

const int N = 1e5;
int n;
pair<pair<string, int>, int> p[N];
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  FOR(i, 0, n){
    cin >> p[i].fi.fi >> p[i].fi.se;
    p[i].se = i;
    p[i].fi.se *= -1;
  }
  sort(p, p+n);
  FOR(i, 0, n) cout << p[i].se+1 << endl;
}

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

using namespace std;

typedef long long ll;

int main() {
  ll C = 1000000007;
  ll N;
  cin >> N;
  vector<ll> A(N);
  for (ll i = 0; i < N; i++) {
    cin >> A[i];
  }

  ll result = 0;
  //   for (ll i = 0; i < N - 1; i++) {
  //     ll sum = 0;

  //     for (ll j = i + 1; j < N; j++) {
  //       sum += A[j];
  //     }
  //     result += A[i] * sum;
  //     result = result % C;
  //   }
  ll sum = 0;
  for (ll i = 0; i < N - 1; i++) {
    sum += A[N - 1 - i];
    sum = sum % C;
    result += sum * A[N - 2 - i];
    result = result % C;
  }

  cout << result << endl;

  return 0;
}

Measured memory_bytes: 4828
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#define vll vector<ll>
#define vvvl vector<vvl>
#define vvl vector<vector<ll>>
#define VV(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define VVV(a, b, c, d) vector<vvl>(a, vvl(b, vll (c, d)));
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;

int main(int argc, char const *argv[]) {
  ll a, v, b, w;std::cin >> a >> v >> b >> w;
  ll d = abs(b - a);
  if(w>=v){
    std::cout << "NO" << '\n';
    return 0;
  }
  ll t;std::cin >> t;
  ll sa = v - w;
  if(sa*t>=d){
    std::cout << "YES" << '\n';
  }else std::cout << "NO" << '\n';
  return 0;
}


Measured memory_bytes: 3136
#include<stdio.h>
#include<stdlib.h>
int main (void)
{
  int m,d;
  int cnt=0;
  scanf("%d%d",&m,&d);
  for(int i=1;i<m+1;i++){
    for(int j=20;j<d+1;j++){
      if((i==((int)j/10)*(j%10)&&((j%10)!=1))){
        cnt++;
        //printf("%d月%d日\n",i,j);
      }
    }
  }
  printf("%d",cnt);
  return 0;
}


Measured memory_bytes: 128
import sys
input = sys.stdin.readline

N = int(input())
A = [int(i) for i in input().split()]
count = [0] * 10**5
for i in range(N):
        count[A[i]-1] += 1

Q = int(input())
ans = sum(A)
for i in range(Q):
    B, C = map(int, input().split())
    ans += (C - B) * count[B-1]

    print(ans)

    count[C-1] += count[B-1]
    count[B-1] = 0

Measured memory_bytes: 20500
#include<iostream>
#include<iomanip>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<unordered_map>
#include<stack>
#include<queue>
#include<math.h>
#include<functional>
#include<bitset>
#include<cassert>
using namespace std;
using ll = long long;
using ld = long double;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
#define MOD 998244353LL
#define INF 1000000000LL
#define EPS 1e-10
#define FOR(i,n,m) for(ll i=n;i<(int)m;i++)
#define REP(i,n) FOR(i,0,n)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define ALL(v) v.begin(),v.end()
#define UNIQUE(v)  sort(ALL(v));v.erase(unique(ALL(v)),v.end());
#define pb push_back

int main() {
	cin.tie(0);
	ll n;
	cin >> n;
	vector<ll> a(n);
	REP(i, n) cin >> a[i];
	ll ans = 1, tmp = 1;
	REP(i, n) {
		ans *= 3;
		tmp *= 2;
		ans %= MOD;
		tmp %= MOD;
	}
	ans -= 3; ans -= 3 * (tmp - 2); ans = (ans % MOD + MOD) % MOD;
	vector<vector<ll>> dp1(n, vector<ll>(100000, 0)), dp2(n, vector<ll>(100000, 0));
	REP(i, n) REP(j, 100000) {
		if(i == 0) {
			if(j == 0) dp1[i][j] += 1;
			if(j == a[i]) dp1[i][j] += 1;
			if(j == 0) dp2[i][j] += 2;
			if(j == a[i]) dp2[i][j] += 1;
		} else {
			dp1[i][j] += dp1[i - 1][j];
			if(j >= a[i]) dp1[i][j] += dp1[i - 1][j - a[i]];
			dp2[i][j] += 2 * dp2[i - 1][j];
			if(j >= a[i]) dp2[i][j] += dp2[i - 1][j - a[i]];
		}
		dp1[i][j] %= MOD;
		dp2[i][j] %= MOD;
	}
	ll sum = 0; REP(i, n) sum += a[i];
	FOR(i, 1, sum) {
		if(sum % 2 == 0 && i >= sum / 2) {
			ans -= 3 * (dp2[n - 1][i] - 2 * dp1[n - 1][i]);
		}
		if(sum % 2 == 1 && i > sum / 2) {
			ans -= 3 * (dp2[n - 1][i] - 2 * dp1[n - 1][i]);
		}
		ans %= MOD;
	}
	cout << (ans % MOD + MOD) % MOD << endl;
	return 0;
}

/* --------------------------------------- */


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

#define int long long
#define double long double
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n) for (int i = 1; i <= (n); i++)
#define all(x) (x).begin(), (x).end()
#define uniq(x) (x).erase(unique(all(x)), (x).end())
#define bit(n) (1LL << (n))
#define dump(x) cerr << #x " = " << (x) << endl
using vint=vector<int>;
using vvint=vector<vint>;
using pint=pair<int, int>;
using vpint=vector<pint>;
template<typename T> using priority_queue_rev=priority_queue<T, vector<T>, greater<T>>;
constexpr double pi = 3.1415926535897932384626433832795028;
constexpr int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b) {
    while (b) { swap(a %= b, b); }
    return a;
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
template<typename T1, typename T2> bool chmax(T1 &a, const T2 &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T1, typename T2> bool chmin(T1 &a, const T2 &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &rhs) {
    os << "(" << rhs.first << ", " << rhs.second << ")";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const vector<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
struct Setup {
    static constexpr int PREC = 20;
    Setup() {
        cout << fixed << setprecision(PREC);
        cerr << fixed << setprecision(PREC);
    };
} setup;

template<typename T>
struct SegmentTree {
    int n;
    T ZERO;
    std::vector<T> data;
    int getSize(int n_) const {
        int ret = 1;
        while (ret < n_) { ret <<= 1; }
        return ret;
    }
    SegmentTree(int n_, T ZERO = T()) : n(getSize(n_)), ZERO(ZERO), data(n << 1, ZERO) {}
    void update(int i, T x) {
        i += n;
        data[i] = x;
        while (i > 1) {
            i >>= 1;
            data[i] = data[i << 1] + data[(i << 1) + 1];
        }
    }
    T operator[](int i) const { return data[i + n]; }
    T getSum(int l, int r) const {
        T ret = ZERO;
        for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
            if (l & 1) { ret += data[l], l++; }
            if (r & 1) { ret += data[r - 1]; }
        }
        return ret;
    }
};

int N, K;
int a[110000];
signed main() {
    cin >> N >> K;
    SegmentTree<int> st0(N), st1(N);
    rep(i, N) { cin >> a[i], st0.update(i, a[i]), st1.update(i, max(0LL, a[i])); }
    int ans = 0;
    rep(i, N - K + 1) {
        chmax(ans, st1.getSum(0, i) + st0.getSum(i, i + K) + st1.getSum(i + K, N));
        chmax(ans, st1.getSum(0, i) + st1.getSum(i + K, N));
    }
    cout << ans << endl;
}


Measured memory_bytes: 5120
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using vpii = vector<pair<int, int>>;
using vpll = vector<pair<ll, ll>>;
// ceil() 切り上げ, floor() 切り捨て
// next_permutation(all(x))

int		main(void)
{
	string S, T;
	cin >> S >> T;

	vector<vector<int>> X(26, vector<int>());
	for (int i = 0; S[i]; i++)
	{
		int idx = S[i] - 'a';
		X[idx].push_back(i);
	}

	vector<vector<int>> Y(26, vector<int>());
	for (int i = 0; T[i]; i++)
	{
		int idx = T[i] - 'a';
		Y[idx].push_back(i);
	}

	bool ans = true;
	for (int i = 0; i < 26; i++)
	{
		if (X[i].size() == 0)
			continue ;
		int c = X[i][0];
		int i_y = T[c] - 'a';
		if (X[i].size() != Y[i_y].size())
		{
			ans = false;
			break ;
		}
		for (int j = 0; j < (int)X[i].size(); j++)
		{
			if (X[i][j] != Y[i_y][j])
				ans = false ;
		}
	}
	cout << (ans ? "Yes" : "No") << endl;
}



Measured memory_bytes: 2952
// Aizu Vol0 00035: Is it Convex?
// 2017.7.29

#include <stdio.h>
#include <stdlib.h>

#define EPSILON 0.0001

int isSameSide(double x1, double y1, double x2, double y2,
	double xa, double ya, double xb, double yb)
{
	double sa, sb;

	sa = (x2 - x1) * (ya - y1) + (y2 - y1) * (x1 - xa);
	sb = (x2 - x1) * (yb - y1) + (y2 - y1) * (x1 - xb);
	if (-EPSILON <= sb && sb <= EPSILON) return 0;   // xb,yb in line
	if (sa * sb >= 0) return 1;                      // xa,ya xb,yb at same side
	return -1;                                       //
}

int main()
{
	double x1, y1, x2, y2, x3, y3, x4, y4;

	while (scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf",
		&x1, &y1, &x2, &y2, &x3, &y3, &x4, &y4) == 8) {
		if (isSameSide(x1, y1, x3, y3, x2, y2, x4, y4) != -1) goto NO;
		if (isSameSide(x2, y2, x4, y4, x1, y1, x3, y3) != -1) goto NO;
		puts("YES");
		continue;
	NO: puts("NO");
	}
	return 0;
}

Measured memory_bytes: 608
#![allow(unused_imports)]
use std::collections::{HashSet, HashMap};
use std::cmp::{min,max};
use std::io;
use std::str;
 
struct Scanner<R> {
    reader: R,
    buf_str: Vec<u8>,
    buf_iter: str::SplitWhitespace<'static>,
}
impl<R: io::BufRead> Scanner<R> {
    fn new(reader: R) -> Scanner<R> {
        Scanner { reader : reader, buf_str: vec![], buf_iter: "".split_whitespace() }
    }
    fn token<T: str::FromStr>(&mut self) -> T {
        loop {
            if let Some(token) = self.buf_iter.next() {
                return token.parse().ok().expect("Failed parse");
            }
            self.buf_str.clear();
            self.reader.read_until(b'\n', &mut self.buf_str).expect("Failed read");
            self.buf_iter = unsafe {
                let slice = str::from_utf8_unchecked(&self.buf_str);
                std::mem::transmute(slice.split_whitespace())
            }
        }
    }
}

const MD : u32 = 1000000007;

fn solve<R: io::BufRead, W: io::Write>(scan: &mut Scanner<R>, out: &mut W) {
    let ss : String = scan.token();
    let s : Vec<char> = ss.chars().collect();
    let mut dp1 = vec![0 as u32; s.len() + 3];
    let mut dp2 = vec![0 as u32; s.len() + 3];
    dp2[0] = 1;
    for i in 0..s.len() {
        if s[i] == '1' {
            dp1[i + 1] = (dp1[i] * 3 + dp2[i]) % MD;
            dp2[i + 1] = (dp2[i] * 2) % MD;
        } else {
            dp1[i + 1] = (dp1[i] * 3) % MD;
            dp2[i + 1] = dp2[i];
        }
    }
    writeln!(out, "{}", (dp1[s.len()] + dp2[s.len()]) % MD).ok();
}


fn main() {
    let (stdin, stdout) = (io::stdin(), io::stdout());
    let mut scan = Scanner::new(stdin.lock());
    let mut out = io::BufWriter::new(stdout.lock());
    solve(&mut scan, &mut out);
}


Measured memory_bytes: 4352
#include<stdio.h>

    int main(){
    int n,i,max,min,dis=0;
    scanf("%d",&n);
    int a[n];
    for(i = 0;i < n;i++){
      scanf("%d",&a[i]);
    }
    max = a[0];
    min = a[0];
    for(i = 0;i < n;i++){
      if( max<a[i] ) max = a[i];
      if( min>a[i] ) min = a[i];
    }
    dis = max - min;
    printf("%d\n",dis);
    return 0;
}

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

int main()
{
	string s;

	cin >> s;

	for( int i = 0; i < s.size(); i++ ) {
		if( (i % 2) == 0 ) {
			cout << s[i];
		}
	}
	cout << endl;

	return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define ld long double
#define endl "\n"
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)
#define ms(v,x) memset(v,x,sizeof(v))
#define all(v) v.begin(),v.end()
#define ff first
#define ss second
#define rep(i,l,r) for(int i = (int)l;i<(int)r;i++)
#define td(v) v.begin(),v.end()
#define sz(v) (int)v.size()
//#define M   1000000007 // 1e9 + 7
#define int long long
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
inline ll mod(ll n, ll m){ ll ret = n%m; if(ret < 0) ret += m; return ret; }
ll gcd(ll a, ll b){return (b == 0LL ? a : gcd(b, a%b));}
ll exp(ll a,ll b,ll m){
    
    if(b==0LL) return 1LL;
    if(b==1LL) return mod(a,m);
    ll k = mod(exp(a,b/2,m),m);
    if(b&1LL){
        return mod(a*mod(k*k,m),m);
    }
    else return mod(k*k,m);
}


int32_t main(){
  fastio;
  int s,w;
  cin>>s>>w;
  if(w>=s){
    cout<<"unsafe"<<endl;
  }else cout<<"safe"<<endl;
  // Math -> gcd it all
  // Did u check N=1? Did you switch N,M?
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define ll long long
using namespace std;
 
ll gcd(ll a, ll b){
  if(b == 0){
    return a;
  }
  else{
    return gcd(b,(a%b));
  }
}
ll lcm(ll a,ll b){
  return a/gcd(a,b)*b;
}
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(){
  vector<int> vec(100001);
  for(int i=1;i<=100000;i++){
    vec.at(i)=vec.at(i-1);
    if(i%2==1){
      if(IsPrime(i)==true&&IsPrime((i+1)/2)==true){
        vec.at(i)++;
      }
    }
  }
  int p,a,b;
  cin>>p;
  for(int i=0;i<p;i++){
    cin>>a>>b;
    cout<<vec.at(b)-vec.at(a-1)<<endl;
  }
}

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

using namespace std;

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

inline int toInt(string s) {int v; istringstream sin(s);sin>>v; return v;}

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector< vector<int> > Mat;
typedef tuple<int, int, int, int> T;

const int MOD = (int)1e9+7;
const int INF = (int)1e9;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

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

    if(x == 7 || x == 5 || x == 3){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

var N, K int

func main() {
	fmt.Scan(&N, &K)
	var rate float64
	for i := 1; i <= N; i++ {
		x, coin := i, 1.0
		for K > x {
			x *= 2
			coin /= 2
		}
		rate += (1 / float64(N)) * coin
	}

	fmt.Printf("%.12f\n", rate)
}


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

int main(){
  int N;
  string S1,S2;
  cin>>N>>S1>>S2;
  ll ans=1;
  int i=0;
  bool flag=true;
  if(S1.at(i)==S2.at(i)){
    ans*=3;
    flag=false;
    i++;
  }else{
    ans*=6;
    flag=true;
    i+=2;
  }

  while(i<N){
    if(S1.at(i)==S2.at(i)){
      if(!flag){
        ans*=2;
        ans%=MOD;
      }
      flag=false;
      i++;
    }else{
      if(flag){
        ans*=3;
        ans%=MOD;
      }else{
        ans*=2;
        ans%=MOD;
      }
      flag=true;
      i+=2;
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <numeric>
#include <set>
#define FOR(i, a, n) for (int i = (a); i < (n); i++)
#define REP(i, n) for(int i = 0; i < (n); i++)
using namespace std;



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

	int A, B, T;

	cin >> A >> B >> T;

	cout << T / A * B << endl;

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main() {
  int N; scanf("%d", &N);
  int count = 0;
  for(int i = 0; i < N; ++i) {
    int a; scanf("%d", &a);
    while(a % 2 == 0) {
      count++;
      a /= 2;
    }
  }
  printf("%d\n", count);
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
inline int read()
{
  int p=0; int f=1; char ch=getchar();
  while(ch<'0' || ch>'9'){if(ch=='-') f=-1; ch=getchar();}
  while(ch>='0' && ch<='9'){p=p*10+ch-'0'; ch=getchar();}
  return p*f;
}
int n,a[N]; set<int> s1[N],s2[N]; int num[N];
int fa[N]; int Find(int x){return (fa[x] == x) ? x : fa[x] = Find(fa[x]);}
int main()
{
  n = read(); int q = read(); for(int i=1;i<=n;i++) a[i] = read();
  for(int i=1;i<=n;i++) s1[i].insert(i),s2[i].insert(a[i]),num[i] = i,fa[i]=i;
  while(q--)
  {
    int x = read(); int y = read();
    if(Find(x) != Find(y))
    {
      x = Find(x); y = Find(y);
      fa[x] = y;
      if(s1[num[y]].size() > s1[num[x]].size())
      {
		while(s1[num[x]].size())
		{
	      s1[num[y]].insert(*s1[num[x]].begin()),s1[num[x]].erase(s1[num[x]].begin());
	      s2[num[y]].insert(*s2[num[x]].begin()),s2[num[x]].erase(s2[num[x]].begin());
	    }
      }
      else
      {
        while(s1[num[y]].size())
        {
          s1[num[x]].insert(*s1[num[y]].begin()),s1[num[y]].erase(s1[num[y]].begin());
          s2[num[x]].insert(*s2[num[y]].begin()),s2[num[y]].erase(s2[num[y]].begin());
        }// printf("%d -> %d\n",num[x],num[y]);
		num[y] = num[x];
      }
    }
  }
  
  int ans = 0;
  for(int i=1;i<=n;i++)
  {
    if(Find(i) == i)
    {
      while(s2[num[i]].size())
      {
        int x = *s2[num[i]].begin(); // printf("%d\n",x);
        s2[num[i]].erase(s2[num[i]].begin());
        if(s1[num[i]].find(x) != s1[num[i]].end()) ans++;
      }
      
    }
  }
  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 20224
#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EACH(t,i,c) for(t::iterator i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
const double EPS = 1e-10;
const double PI  = acos(-1.0);

typedef vector<vvi> vvvi;
int cost[4][30][30];
struct cell{
	int cost,d,x,y;
	cell(int cost,int d,int x,int y):cost(cost),d(d),x(x),y(y){}
	bool operator<(const cell &other)const{
		return cost>other.cost;
	}
};
int dx[]={1,0,-1,0},dy[]={0,1,0,-1};
int main(){
	int w,h;
	while(cin>>w>>h,w&&h){
		vvi s(w,vi(h));
		vi cd(4);
		REP(i,h){
			REP(j,w){
				cin>>s[j][i];
			}
		}
		REP(i,4){
			cin>>cd[i];
		}
		REP(i,4)REP(j,w)REP(k,h){
			cost[i][j][k]=INT_MAX;
		}
		priority_queue<cell> q;
		q.push(cell(0,0,0,0));
		cost[0][0][0]=0;
		while(!q.empty()){
			cell c=q.top();
			q.pop();
			if(c.cost>cost[c.d][c.x][c.y])continue;
			REP(i,4){
				int dir=(c.d+i)%4;
				int x=c.x+dx[dir],y=c.y+dy[dir];
				if(x>=0&&x<w&&y>=0&&y<h){
					if(s[c.x][c.y]!=4&&i==s[c.x][c.y]){
						if(cost[dir][x][y]>cost[c.d][c.x][c.y]){
							cost[dir][x][y]=cost[c.d][c.x][c.y];
							q.push(cell(cost[dir][x][y],dir,x,y));
						}
					}else{
						if(cost[dir][x][y]>cost[c.d][c.x][c.y]+cd[i]){
							cost[dir][x][y]=cost[c.d][c.x][c.y]+cd[i];
							q.push(cell(cost[dir][x][y],dir,x,y));
						}
					}
				}
			}
		}
		int best=INT_MAX;
		REP(i,4){
			best=min(best,cost[i][w-1][h-1]);
		}
		cout<<best<<endl;
	}
}

Measured memory_bytes: 1032
//minamoto
#include<bits/stdc++.h>
#define R register
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
using namespace std;
char buf[1<<21],*p1=buf,*p2=buf;
inline char getc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;}
int read(){
    R int res,f=1;R char ch;
    while((ch=getc())>'9'||ch<'0')(ch=='-')&&(f=-1);
    for(res=ch-'0';(ch=getc())>='0'&&ch<='9';res=res*10+ch-'0');
    return res*f;
}
const int N=1e6+5;
int a[N],b[N],c[N],fa[N],ok[2][N];
int n,m,q,g,z,P;
int find(R int x){return fa[x]==x?x:fa[x]=find(fa[x]);}
inline void merge(R int x,R int y){fa[find(y)]=find(x);}
inline int id(R int x,R int y,R int z){return x*6+(y<<1)+z;}
int main(){
//	freopen("testdata.in","r",stdin);
	n=read(),m=read(),q=read(),P=read();
	fp(i,1,m)a[i]=read(),b[i]=read(),c[i]=read(),g=__gcd(g,abs(c[i]-c[1]));
	!g?g=P:0,P=__gcd(P,3*g),z=c[1]%g;
	fp(i,0,n*6-1)fa[i]=i;
	fp(i,1,m){
		int u=a[i]-1,v=b[i]-1,w=(c[i]-z)/g%3;
		fp(x,0,2){
			merge(id(u,x,0),id(v,((x<<1)+w)%3,1)),
			merge(id(v,x,0),id(u,((x<<1)+w)%3,1)),
			merge(id(u,x,1),id(v,((x<<1)+w)%3,0)),
			merge(id(v,x,1),id(u,((x<<1)+w)%3,0));
		}
	}
//	fp(i,0,n*6-1)printf("%d %d\n",i,find(i));
	for(R int i=0,j=z;i<(P<<1);++i,j=(j<<1)%P)ok[i&1][j]=1;
	while(q--){
		int s=read()-1,t=read()-1,r=read(),res=0;
		fp(x,0,2)fp(y,0,1)find(id(t,0,0))==find(id(s,x,y))?res|=ok[y][(r+z+(3-x)*g)%P]:0;
		puts(res?"YES":"NO");
	}
	return 0;
}

Measured memory_bytes: 19456
#include "cstdio"
#include "cstring"
#include"algorithm"
using namespace std;
int main()
{
    //freopen("input.txt","r",stdin);
   	int t;
   	scanf("%d",&t);
   	while(t--)
   	{
   		int a[3];
   		scanf("%d%d%d",&a[0],&a[1],&a[2]);
   		sort(a,a+3);
   		if(a[0]*a[0]+a[1]*a[1]==a[2]*a[2])
   			printf("YES\n");
   		else
   			printf("NO\n");
   	}

    return 0;
};

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

int main() {
    int ans;
    ans = 300;
    vector<int> v (3);
    for(int i=0; i<3; i++){
        cin >> v.at(i);
    }
    for(int i=0; i<2; i++){
        for(int j=i+1; j<3; j++){
            if(v.at(i) + v.at(j) < ans) ans = v.at(i) + v.at(j);
        }
    }
    cout << ans << endl;
}

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

int main(int argc, char *argv[]) {
  int N, K;
  cin >> N >> K;
  int x[N];
  for(int i = 0; i < N; i++) {
    cin >> x[i];
  }
  int ans = 1e9;
  for(int i = 0; i < N - K + 1; i++) {
    if(x[i + K - 1] < 0) {
      ans = min(ans, abs(x[i]));
    } else if(x[i] > 0) {
      ans = min(ans, abs(x[i + K - 1]));
    } else {
      ans = min(ans, min(abs(x[i]) * 2 + abs(x[i + K - 1]), abs(x[i + K - 1]) * 2 + abs(x[i])));
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 640
import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();

        int k = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();

        for (int i = k; i <= b; i+=k) {
            if (i >= a) {
                System.out.println("OK");
                return;
            }
        }
        System.out.println("NG");
    }

    static class MyScanner {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in), 1 << 15);
        StringTokenizer tokenizer;

        String next() {
            try {
                while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                    tokenizer = new StringTokenizer(reader.readLine());
                }
            } catch (IOException ignored) {
            }
            return tokenizer.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }
    }
}

Measured memory_bytes: 25404
n,m = map(int, raw_input().split())
aa = set()
bb = set()
for _ in range(m):
  a,b = map(int, raw_input().split())
  a,b = min(a,b),max(a,b)
  if a == 1:
    aa.add(b)
  if b == n:
    bb.add(a)
for i in range(1,n+1):
  if i in aa and i in bb:
    print 'POSSIBLE'
    exit()
print 'IMPOSSIBLE'

Measured memory_bytes: 23408
L = int(input())

paths = []
n = 2
v = 1
while n <= L:
    paths.append((v, v+1, 0))
    paths.append((v, v+1, n//2))
    v += 1
    n *= 2
n //= 2

vlast = v
nn = n
ll = L - n

while ll > 0:
    if ll >= n:
        paths.append((v, vlast, nn))
        ll -= n
        nn += n
    n //= 2
    v -= 1

print(vlast, len(paths))
for e in paths:
    print(*e)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
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; }
typedef long long ll;
typedef pair<int,int> P;

int main(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    ll res = 0;
    char a[3];
    a[0]='R';
    a[1]='G';
    a[2]='B';
    sort(a,a+3);
    do{
    vector<ll> r(4005,0);
    vector<ll> rg(4005,0);
    vector<ll> rgb(4005,0);
    for(int i=1;i<=n;i++){
        if(s[i-1]==a[0])r[i]=r[i-1]+1;
        else r[i]=r[i-1];
    }
    for(int i=1;i<=n;i++){
        if(s[i-1]==a[1])rg[i]=rg[i-1]+r[i-1];
        else rg[i]=rg[i-1];
    }
    for(int i=1;i<=n;i++){
        if(s[i-1]==a[2])rgb[i]=rgb[i-1]+rg[i-1];
        else rgb[i]=rgb[i-1];
    }
    ll ans = rgb[n];
    vector<int> rp;
    rep(i,n)if(s[i]==a[0])rp.push_back(i);
    rep(i,n){
        if(s[i]==a[1]){
            for(auto p:rp){
                if(p>i)break;
                else if(((2*i-p)<n)&&(s[2*i-p]==a[2]))ans--;
            }
        }
    }
    //cout << ans << endl;
    res += ans;
    }while(next_permutation(a,a+3));
    cout << res << endl;
}

Measured memory_bytes: 3724
#include<bits/stdc++.h>
using namespace std;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s; cin >> s;
    if (s == "A") {
        cout << "T" << endl;
    } else if (s == "G") {
        cout << "C" << endl;
    } else if (s == "C") {
        cout << "G" << endl;
    } else {
        cout << "A" << endl;
    }
}


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

#define PI 3.1415926535897932
#define MOD 1000000007
#define INF 1e9

#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define FOR(i, start, end) for(int i = (start); i < (end); i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;


void solve()
{
    int N; cin >> N;
    vi a(N);
    vll sum(N);
    ll s = 0;
    REP(i, N)
    {
        cin >> a[i];
        s += a[i];
        sum[i] = s;
    }

    ll ans = (ll)abs(sum[0] - (sum[N-1] - sum[0]));
    REP(i, N-1)
    {
        ll x = sum[i];
        ll y = sum[N-1] - x;
        ans = min(ans, (ll)abs(x-y));
    }
    cout << ans << endl;
}

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

    return 0;
}

Measured memory_bytes: 2560
#include <cstdio>
#include <algorithm>
#include <vector>
int n, m, lim, ans;
char a[15][1005];
int main(){
  scanf("%d%d%d", &n, &m, &lim), ans = n + m - 2;
  for (register int i = 0; i < n; ++i)
    scanf("%s", a[i]);
  for (register int p = 0; p < (1 << (n - 1)); ++p){
    std::vector<int> pos, now;
    for (register int i = 0; i < n - 1; ++i)
      if (p >> i & 1) pos.push_back(i);
    pos.push_back(n - 1);
    now.resize(pos.size(), 0);
    bool flag = 1;
    int cnt = (int)pos.size() - 1;
    for (register int i = 0; i < m; ++i){
      std::vector<int> tmp(pos.size());
      for (register int j = 0; j < (int)pos.size(); ++j)
        for (register int k = j ? pos[j - 1] + 1 : 0; k <= pos[j]; ++k)
          tmp[j] += a[k][i] ^ '0';
      bool cut = 0;
      for (register int j = 0; j < (int)pos.size(); ++j){
        now[j] += tmp[j];
        if (tmp[j] > lim) flag = 0;
        if (now[j] > lim) cut = 1;
      }
      if (!flag) break;
      if (cut) ++cnt, now.swap(tmp);
    }
    if (flag) ans = std::min(ans, cnt);
  }
  printf("%d\n", ans);
}

Measured memory_bytes: 256
from decimal import Decimal
import math


aaa = list(map(float, input().split()))

'''
aaa = [1000000000000000, 0.09]
A = 1000000000000000
B = 0.09
'''


'''
print(B)
print(A)
1000000000000000 0.09
999999999999999
'''
#print(math.floor(Decimal(＃A * B)))


print(int(Decimal("{}".format(aaa[0])) * Decimal("{}".format(aaa[1]))))

Measured memory_bytes: 10072
#[allow(unused_imports)]
use itertools::Itertools;
#[allow(unused_imports)]
use num::*;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
#[allow(unused_imports)]
use std::collections::*;

fn solve() {
    input! {
        n: usize, k: usize,
        mut pv: [usize; n]
    };

    pv.sort();
    let res = pv.into_iter().take(k).sum::<usize>();
    println!("{}", res);
}

fn main() {
    std::thread::Builder::new()
        .name("big stack size".into())
        .stack_size(256 * 1024 * 1024)
        .spawn(|| {
            solve();
        })
        .unwrap()
        .join()
        .unwrap();
}


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

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

    int X =  N * 100 / 108;
    if (X * 108 / 100 == N) cout << X << endl;
    else if ((X + 1) * 108 / 100 == N) cout << X + 1 << endl;
    else cout << ":(" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;

using namespace std;

void solve()
{
    int n;
    scanf("%d", &n);
    vector<int> t(n+1), x(n+1), y(n+1);
    int i;
    for (i = 0; i < n; i++) {
        scanf("%d%d%d", &t[i+1], &x[i+1], &y[i+1]);
    }
    for (i = 1; i < n+1; i++) {
        int tmp = abs(x[i] - x[i - 1]) + abs(y[i] - y[i - 1]);
        int t0 = t[i] - t[i - 1];
        if (tmp % 2 != t0 % 2 || tmp > t0) {
            printf("No\n"); return;
        }
    }
    printf("Yes\n");
    return;
}

int main(int argc, char* argv[])
{
#if 1
    solve();
#else
    int T; scanf("%d", &T);
    while(T--) {
        solve();
    }
#endif
    return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
const int INF=999999999;

int main() {
 int A,B,C,X;
 cin>>A>>B>>C>>X;
 int count =0;
 for(int a=0;a<=A;a++){
   for(int b=0;b<=B;b++){
     for(int c=0;c<=C;c++){
       if(500*a+100*b+50*c==X){count++;}
     }
   }
 }
 cout<<count<<endl;
 return 0;}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
    int x,y;
    int check = 0;
    int check2 = 0;

    scanf("%d\n",&x);
    scanf("%d\n",&y);

    for(int i = 0; i <= 100; i++){
        if(check == 1) break;
        for(int j = 0; j <= 100; j++){
            if(i+j==x && (2*i)+(4*j)==y){
                printf("Yes\n");
                check = 1;
              	check2 = 1;
              	break;
            }
        }
    }
    if(check2 ==0){
        printf("No\n");
    }
    return 0;
}

Measured memory_bytes: 1660
import numpy as np
import math
from decimal import Decimal

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])
    
    if arr==[]:
        arr.append([n, 1])
    
    return arr

N = int(input())
ans = factorization(N)
if ans[0][0] == 1:
    print(0)
else:
    count = 0
    for i in range(len(ans)):
        an = 1
        n = 1
        while an <= ans[i][1]:
            n = n + 1
            an = n*(n+1)/2
            count = count +1

    print(count)


Measured memory_bytes: 27160
import java.awt.Point;
import java.io.FileInputStream;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Scanner;
 
public class Main {
     
    static ArrayList<Point> delta;
     
    static void start()
    {
        int x = 0;
        int y = 0;
         
        int max = 0;
        int mx = 0, my = 0;
         
        for(Point d : delta)
        {
            x += d.x;
            y += d.y;
             
            int len = x*x + y*y;
            if(max < len)
            {
                max = len;
                mx = x;
                my = y;
            }
            else if(max == len)
            {
            	if(x > mx)
            	{
            		mx = x;
            		my = y;
            	}
            }
        }
         
        System.out.printf("%d %d\n", mx, my);
    }
     
    public static void main(String[] args)
    {
         
        Scanner sca = new Scanner(System.in);
         
        while(true)
        {
            int n = sca.nextInt();
 
            for(;n > 0;n--)
            {
                delta = new ArrayList<Point>();
                 
                while(true)
                {
                    int dx = sca.nextInt();
                    int dy = sca.nextInt();
                     
                    if(dx == 0 && dy == 0) break;
                     
                    delta.add(new Point(dx, dy));
                }
                 
                start();
            }
             
            break;
        }
    }
}

Measured memory_bytes: 26204
#include<cmath>
#include<bits/stdc++.h>
#define MAX(a,b) (a>b? a:b)
#define MIN(a,b) (a>b? b:a)
#define rep(i,n) for(lint i=0;i<(lint)(n);i++)
#define repr(i,n) for(lint i=(lint)(n);i>0;--i)
#define reps(i,a,b) for(lint i=a;i<=(lint)(b);i++)
typedef long long lint;
typedef long double ld;
using namespace std;
const ld PI = acos(-1.0);

int main(){
    int A, B;
    cin >> A >> B;
    if(A>=13) {
        cout << B;
    } else if(A<=5) {
        cout << 0;
    } else {
        cout << B / 2;
    }
    return 0;
}

Measured memory_bytes: 256
let split_string ?(pattern="") = Str.split @@ Str.regexp pattern
let (n, k) = Scanf.sscanf (read_line ()) "%d %d" @@ fun n k -> (n, k)
let p = read_line () |> split_string ~pattern:" " |> List.map int_of_string |> List.sort compare

let rec loop sum i acc =
    if i = 0 then Printf.printf "%d\n" sum
    else loop (sum + List.hd acc) (i - 1) (List.tl acc)

let () = loop 0 k p

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

int Dice[6];

void shake(char c){
  if(c == 'E'){
    swap(Dice[0], Dice[3]);
    swap(Dice[3], Dice[5]);
    swap(Dice[5], Dice[2]);
  }
  if(c == 'N'){
    swap(Dice[0], Dice[1]);
    swap(Dice[1], Dice[5]);
    swap(Dice[5], Dice[4]);
  }
  if(c == 'S'){
    swap(Dice[1], Dice[0]);
    swap(Dice[0], Dice[4]);
    swap(Dice[4], Dice[5]);
  }
  if(c == 'W'){
    swap(Dice[3], Dice[0]);
    swap(Dice[0], Dice[2]);
    swap(Dice[2], Dice[5]);
  }
}

int main(){
  int i, j, Dice_fake[6] = {0};
  for(i = 0; i < 6; i++) cin >> Dice[i];
  for(i = 0; i < 6; i++) cin >> Dice_fake[i];

  char distance[10] = {"NNNNENNNN"};

  for(i = 0; i < 10; i++){
    if(Dice[1] == Dice_fake[1]) break;
    shake(distance[i]);
  }
  for(i = 0; i < 4; i++){
    if(Dice[0] == Dice_fake[0]){
      if(Dice[2] == Dice_fake[2] && Dice[3] == Dice_fake[3] && Dice[4] == Dice_fake[4] && Dice[5] == Dice_fake[5]){
        cout << "Yes" << endl;
        return 0;
      }
    }
    shake('E');
  }
  cout << "No" << endl;
  return 0;
}

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

using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> Vi;
typedef tuple<int, int, int> T;
#define FOR(i,s,x) for(int i=s;i<(int)(x);i++)
#define REP(i,x) FOR(i,0,x)
#define ALL(c) c.begin(), c.end()
#define DUMP( x ) cerr << #x << " = " << ( x ) << endl

const int INF = 1<<29;

int dp[256][16][128];
P stones[256][16];
int col[256];

int main() {
  // use scanf in CodeForces!
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  while (true) {
    int N, M;
    cin >> N >> M;
    if (N == 0 && M == 0) break;
  
    REP(i, N) {
      cin >> col[i];
      REP(j, col[i]) {
	int x, d;
	cin >> x >> d;
	stones[i][j] = P(x, d);
      }
    }

    REP(i, N) REP(j, col[i]) REP(k, M+1) dp[i][j][k] = INF;
    REP(j, col[0]) dp[0][j][0] = 0;
    REP(j, col[1]) dp[1][j][1] = 0;
    REP(i, N-1) {
      REP(j, col[i]) {
	int x_now = stones[i][j].first, d_now = stones[i][j].second;
	REP(k, col[i+1]) {
	  int x_next = stones[i+1][k].first, d_next = stones[i+1][k].second;
	  int safe = (d_now + d_next) * abs(x_now - x_next);
	  REP(m, M+1) {
	    dp[i+1][k][m] = min(dp[i+1][k][m], dp[i][j][m] + safe);
	  }
	}
	if (i < N-2) {
	  REP(k, col[i+2]) {
	    int x_next = stones[i+2][k].first, d_next = stones[i+2][k].second;
	    int safe = (d_now + d_next) * abs(x_now - x_next);
	    REP(m, M) {
	      dp[i+2][k][m+1] = min(dp[i+2][k][m+1], dp[i][j][m] + safe);
	    }
	  }
	}
      }
    }

    int ans = INF;
    REP(j, col[N-1]) REP(m, M+1) ans = min(ans, dp[N-1][j][m]);
    REP(j, col[N-2]) REP(m, M) ans = min(ans, dp[N-2][j][m]);
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 2424
#include"bits/stdc++.h"
using namespace std;
#define Rep(i, n) for (int i = 0; i < (int)(n); i++)
#define BitRep(i, n) for (int i = 0; i < (int)(1 << n); i++)
#define Sum(vec) accumulate(vec.begin(), vec.end(), 0)
#define Sort(vec) sort(vec.begin(), vec.end())
#define Reverse(vec) reverse(vec.begin(), vec.end())

int main() {
	int N;
	int64_t K;
	cin >> N >> K;
	vector<int> A(N);
	Rep(i, N) {
		cin >> A[i];
	}
	vector<bool> seen(N, false);
	int current = 1;
	int64_t count = 0;
	for (int64_t i = 0;i < K;++i) {
		seen[current - 1] = true;
		current = A[current - 1];
		count++;
		if (seen[current - 1]) {
			int roop = 0, flag = current;
			vector<int> ans(N);
			while (true) {
				ans[roop] = current;
				current = A[current - 1];
				roop++;
				if (current == flag) {
					cout << ans[(K - count) % roop] << endl;
					return 0;
				}
			}
		}
	}
	cout << current << endl;
	return 0;
}

Measured memory_bytes: 4844