akhauriyash/Code-Regression huggingface dataset:
n = int(input())
A = list(map(int, input().split()))
idx = [-1]*(n+1)
# 2回現れた文字のidxをl,rに持つ
for i, a in enumerate(A, 1):
    if idx[a] == -1:
        idx[a] = i
    else:
        r = i
        l = idx[a]


MAX_N = 10**6+5
MOD = 10**9 + 7
fac = [0]*(MAX_N)
fac[0] = 1
for i in range(1, MAX_N):
    fac[i] = i*fac[i-1] % MOD
fac_inv = [0]*MAX_N
fac_inv[-1] = pow(fac[-1], MOD-2, MOD)
for i in range(MAX_N-2, -1, -1):
    fac_inv[i] = fac_inv[i+1]*(i+1) % MOD


def comb(n, k):
    if k < 0 or k > n:
        return 0
    return fac[n]*fac_inv[k]*fac_inv[n-k] % MOD


# print(comb(0, 0))
# print(l, r)
# print(fac[:5])
# print(fac_inv[:5])
for k in range(1, n+2):
    #    print(comb(n+1, k), comb(l-1+n-r, k-1))
    ans = (comb(n+1, k)-comb(l-1+n+1-r, k-1)) % MOD
    print(ans)


Measured memory_bytes: 96548
#include<iostream>

int main(){
	int a,b,c;
	char dummy;
	int t=0, h=0;
	while(std::cin>>a>>dummy>>b>>dummy>>c){
		if(a == b)h++;
		if((a*a+b*b)==c*c)t++;
	}
	std::cout<<t<<std::endl;
	std::cout<<h<<std::endl;
	return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
#include <algorithm>
#include <limits.h>
using namespace std;

int main(int argc,char const* argv[])
{
  int x,y;
  cin >> x >> y;
  cout << x+y/2 << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<map>
#include<numeric>
#include<set>
#include<string>
#include<utility>
#include<vector>
#include<queue>
#include<deque>

#define rep(i, a, n)  for(int i=a; i<n; i++)
#define per(i, a, n)  for(int i=n-1; i>=a; i--)
#define fill0(n)  setfill('0') << right << setw(n)
#define all(x)  (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define MAX 1000000001
using namespace std;
typedef long long ll;


int main(){

  int n;std::cin >> n;
  int b[n];
  rep(i,0,n){
    std::cin >> b[i];
    b[i] -= (i+1);
  }
  sort(b,b+n);
  ll res=0;
  rep(i,0,n){
    res += abs(b[i]-b[n/2]);
  }
  std::cout << res << '\n';

}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define x first
#define y second

using namespace std;

typedef long long ll;

int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(0); cin.tie(0);
    string s;
    cin >> s;
    int n = (int) s.length();

    int kol = 0;
    ll ans = 0;
    for (int i = 0; i < n; i++)
    {
        if (s[i] == 'W')
        {
            ans += (ll) (i - kol);
            kol++;
        }
    }
    cout << ans;
    return 0;
}


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

int main() {
  ll h,w; cin>>h>>w;
  ll res=(h*w+1)/2;
  if (h==1||w==1) cout<<1<<endl;
  else cout<<res<<endl;
}


Measured memory_bytes: 256
N = int(input())
list = [int(i) for i in input().split(" ")]

def cost(N):
    dp = [0] * N
    dp[0] = 0
    dp[1] = abs(list[1]-list[0])
    for i in range(2,N):
        dp[i] = min([dp[i-1]+abs(list[i-1]-list[i]),dp[i-2]+abs(list[i-2]-list[i])])
    return dp[N-1]

print(cost(N))

Measured memory_bytes: 52108
s=list(input())
n=len(s)
li=[[0] for i in range(n)]

check=1
for i in range(n-1):
    if s[i]==s[i+1] and s[i]=='R':
        check+=1
    elif s[i]!=s[i+1] and s[i]=='R':
        li[i]+=[-((-check)//2)]
        li[i+1]+=[check//2]
        check=1
check=1     
for i in range(1,n):
    if s[-i]==s[-i-1] and s[-i]=='L':
        check+=1
    elif s[-i]!=s[-i-1] and s[-i]=='L':
        li[-i]+=[-((-check)//2)]
        li[-i-1]+=[check//2]
        check=1
ans=[]
for i in li:
    ans.append(sum(i))
print(*ans)


Measured memory_bytes: 18760
#include <bits/stdc++.h>
using namespace std;
int n,m;
int main() {
	int i;
	scanf("%d%d",&n,&m);
	if (n%2==1) {
		for (i=1;i<=m;i++)
			printf("%d %d\n",i,n+1-i);
		}
	else {
		for (i=1;i<=m;i++)
			if (i<=(n-2)/2/2)
				printf("%d %d\n",i,n-i);
			else printf("%d %d\n",i,n-1-i);
	}
	return 0; 
}

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

int main(){
    double r;
    cin >> r;
    double s, l;
    s = M_PI * r * r;
    l = 2 * M_PI * r;
    printf("%f %f\n", s, l);
    return 0;
}


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

int main(){
    string s;
    cin >> s;
    set<char> A;
    for (int i = 0; i < s.size(); i++){
        A.insert(s.at(i));
    }
    bool all = true;
    for(int i = 0; i < 26; i++){
        char c = 'a';
        c += i;
        if (A.count(c)){
            continue;
        }
        else{
            cout << c << endl;
            all = false;
            break;
        }   
    }
    if(all){
            cout << "None" << endl;
    }
}

Measured memory_bytes: 512
#include<cstring>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<queue>
#include<bitset>
#include<cstdlib>
#include<set>
#include<unordered_map>
#define l(x) (x<<1)
#define r(x) ((x<<1)|1)
#define low(x) (x&(-x))
#define IL inline
#define reg register
#define LL long long
#define N 500010
#define MO 1000000007
#define INF 0x3f3f3f3f
using namespace std;

LL T,n,m,i,j,k,x,y,z,Ans,sum,cnt;
LL a[N],b[N];
char c[N];

struct Data{
	LL x,y;
}d[N];

IL LL Abs(LL x){return (x<0)?-x:x;}
IL void Swap(LL &a,LL &b){a^=b^=a^=b;}
IL LL Min(LL a,LL b){return (a<b)?a:b;}
IL LL Max(LL a,LL b){return (a>b)?a:b;}
IL bool cmp(const Data a,const Data b){return a.x<b.x;}

IL LL Mi(LL x,LL y){
	LL p=x,t=1,Res=1;
	for (;t<=y;(t&y)?Res=(Res*p)%MO:0,p=(p*p)%MO,t<<=1);
	return Res;
}

IL LL read(){
	LL p=0,f=1;	char	c=getchar();
	while (c<48||c>57)	{if (c=='-')	f=-1;	c=getchar();}
	while (c>=48&&c<=57)	p=(p<<1)+(p<<3)+c-48,c=getchar();
	return p*f;
}

int main(){
	#ifdef __Marvolo
	freopen("zht.in","r",stdin);
	freopen("zht.out","w",stdout);
	#endif
	n=read();
	for (i=1;i<=n;i++)	a[i]=read();
	for (i=1;i<=n;i++)	b[i]=(b[i-1]+a[i])%MO;
	for (i=1;i<n;i++){
		x=(b[n]-b[i]+MO)%MO;
		Ans=(Ans+(x*a[i])%MO)%MO;
	}
	cout<<Ans<<endl;
	return 0;
}

Measured memory_bytes: 6728
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <set>
#include <numeric>
#include <cmath>

using namespace std;

typedef long long int ll;

const ll mod = 1e9+7;
const ll INF = 1e9;
const ll MAX_N = 100000;


int prime[MAX_N]={0};
bool is_prime[MAX_N+1]={0};

int sieve(int n)
{
    int p = 0;

    for(int i = 0; i <= n; i++)
    {
        is_prime[i] = true;
    }

    is_prime[0] = false;
    is_prime[1] = false;

    for(int i = 2; i <= n; i++)
    {
        if (is_prime[i])
        {
            prime[p++] = i;  //pは素数の個数

            for(int j = 2 * i; j <= n; j+=i)
            {
                is_prime[j] = false;
            }
        }
    }
    return 0;
}

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

    sieve(55555);

    vector<int> p;
    for(int i = 1; i <= 55555; i++)
    {
        if(is_prime[i] && i%5==1) p.push_back(i);
    }

    for(int i = 0; i < n; i++)
    {
        if(i == n-1) cout << p[i] << endl;
        else cout << p[i] << " ";
    }

    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep2(i, m, n) for(int i=int(m); i<int(n); ++i)
#define drep2(i, m, n) for(int i=int(m-1); i>=int(n); --i)
#define rep(i, n) rep2(i, 0, n)
#define drep(i, n) drep2(i, n, 0)
#define all(a) a.begin(), a.end()
using ll = long long;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using Vbo = vector<bool>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using VVbo = vector<Vbo>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (auto &e : v) is >> e; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << endl; return os; }
template<typename T> inline int count_between(vector<T> &a, T l, T r) { return lower_bound(all(a), r) - lower_bound(all(a), l); } // [l, r)
inline int Log2(ll x) { int k; for (k = 0; x > 0; ++k) x >>= 1; return k; } // number of binary digits
const int INF  = 1<<30;
const ll INFll = 1ll<<62;
const ld EPS   = 1e-10;
const int MOD  = int(1e9)+7;

VV G;
V c;
Vll ans;

pair<ll, map<int, ll>> dfs(int u, int p=-1) {
  map<int, ll> res;
  ll sz = 1;
  for (auto v : G[u]) {
    if (v == p) continue;
    auto [sz_v, res_v] = dfs(v, u);
    ll x = sz_v - res_v[c[u]];
    ans[c[u]] -= x*(x+1)/2;
    if (res.size() < res_v.size()) swap(res, res_v);
    for (auto &&[a, b] : res_v) res[a] += b;
    sz += sz_v;
  }
  res[c[u]] = sz;
  return {sz, move(res)};
}

int main() {
  ll n; cin >> n;

  G.assign(n, V());
  c.assign(n, 0);
  ans.assign(n, n*(n+1)/2);

  rep(i, n) {
    cin >> c[i];
    --c[i];
  }
  rep(i, n-1) {
    int a, b; cin >> a >> b;
    a--; b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }

  auto [sz, res] = dfs(0);
  rep(i, n) {
    ll x = sz - res[i];
    ans[i] -= x*(x+1)/2;
  }

  cout << ans;
  return 0;
}


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

#define for_(i,a,b) for(int i=a;i<b;++i)

int main() {
    string a, b, c;
    cin >> a >> b >> c;

    const int L = 50000;
    const int M = 25000;
    const int N = 2000;

    auto match = [&](char x, char y) { return x == '?' or y == '?' or x == y; };
    
    auto preproc = [&](string S, string T) {
        vector<bool> v(L, true);
        int n = S.size(), m = T.size();
        for_(i,0,n) for_(j,0,m) if (!match(S[i], T[j])) v[i-j+M] = false;
        return v;
    };

    vector<bool> ab = preproc(a, b);
    vector<bool> bc = preproc(b, c);
    vector<bool> ac = preproc(a, c);

    int ans = 1L << 30, A = a.size(), B = b.size(), C = c.size();
    for_(i,-2*N,2*N+1) for_(j,-2*N,2*N+1) {
        if (ab[i+M] and ac[j+M] and bc[j-i+M]) {
            int L = min(0, min(i, j));
            int R = max(A, max(B+i, C+j));
            ans = min(ans, R - L);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 384
#define f(I)p[I]+h[I]*(h[I]-2*h[i])
long C,h[2<<17],p[2<<17],X;
P[2<<17];
s,t=-1,i;
c(x,y,z){
	return (h[y]-h[x])*(p[y]+h[y]*h[y]-p[z]-h[z]*h[z])>=
	(h[z]-h[y])*(p[x]+h[x]*h[x]-p[y]-h[y]*h[y]);
}
main(){
	for(scanf("%*d%ld",&C);~scanf("%ld",h+i);){
		for(;X=f(P[s]),s<t&&X>=f(P[s+1]);s++);
		X=p[i]=i?h[i]*h[i]+C+X:0;
		for(;s<t&&c(P[t-1],P[t],i);t--);
		P[++t]=i++;
	}
	printf("%ld",X);
}

Measured memory_bytes: 4608
import java.util.Scanner

object Main {
  def solve(X: Int): Int = {
    // iまでの累積和がXを初めて超えた場所は、iまでの累積和から 1〜(i - 1) のどれかと入れ替えることでXにできる
    var i = 1
    while(i * (i + 1) / 2 < X) i += 1
    i
  }

  def main(args: Array[String]): Unit = {
    val X = new Scanner(System.in).nextInt()
    println(solve(X))
  }
}


Measured memory_bytes: 27336
N = str(input())
N = N[-1]
N = int(N)
hon_set = {2, 4, 5, 7, 9}
pon_set = {0, 1, 6, 8}
if N in hon_set:
    print("hon")
elif N in pon_set:
    print("pon")
else:
    print("bon")

Measured memory_bytes: 9176
#include <bits/stdc++.h>
#include <stdio.h>
#include <cmath>
#include <tgmath.h>

using namespace std;

#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
//rep…「0からn-1まで」の繰り返し
#define rep2(i,s,n) for(long long i=s; i<=(long long)(n);i++)
//rep2…「sからnまで」の繰り返し
#define repr(i,s,n) for(long long i=s;i>=(long long)(n);i--)
//repr…「ｓからnまで」の降順の繰り返し

typedef long long ll;

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


int main() {
    ll n,k;
    cin>>n>>k;

    vector<ll>a(k+1),A(k);

    rep(i,k)cin>>a[i];
    a[k]=n;

    rep(i,k) A[i]=a[i+1]-a[i];

    A[k-1]+=a[0];

    ll MAX=0,sum=0;
    rep(i,k){
        MAX=max(MAX,A[i]);
        sum+=A[i];

    }

    sum-=MAX;

    cout<<sum<<endl;

}


Measured memory_bytes: 3328
#include<algorithm>
#include<iostream>
#include<cstring>
#include<fstream>
#include<cstdio>
#include<string>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<list>
#define LL long long
#define FF(i,a,b) for(int i=a;i<=b;++i)
#define RR(i,a,b) for(int i=a;i>=b;--i)
#define SC(x) scanf("%d",&x)
#define SCC(x,y) scanf("%d%d",&x,&y)
#define SCCC(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define SS(x) scanf("%s",x)
#define PR(x) printf("%d\n",x)
#define CL(a,b) memset(a,b,sizeof(a))
#define ll rt<<1
#define rr rt<<1|1
#define mid int m=(x+((y-x)>>1))
#define lson x,m,rt<<1
#define rson m+1,y,rt<<1|1
#define lowbit(x) (x&-x)
#define PB push_back
#define IN freopen("in.txt","r",stdin)
#define OUT freopen("out.txt","w",stdout)
using namespace std;

const int N = 220;
const int M = 120*120*4;
const int INF = 1e9;
const LL inf = 1e18;

int n, m;

int S,T,EN,d[N],head[N];
struct node{int v,w,nx;}E[M<<1];
void init(){EN=0;CL(head,-1);};
void add(int u,int v,int w){
    E[EN].v=v;E[EN].w=w;E[EN].nx=head[u];head[u]=EN++;
    E[EN].v=u;E[EN].w=0;E[EN].nx=head[v];head[v]=EN++;
}
inline LL MIN(LL x,LL y){return x<y?x:y;}
int dfs(int u,int x){
    int t,r=0;if(u==T)return x;
    for(int k=head[u];k!=-1&&x-r>0;k=E[k].nx)
    if(E[k].w&&d[E[k].v]==d[u]+1&&(t=dfs(E[k].v,min(x-r,E[k].w)))){
    E[k].w-=t;E[k^1].w+=t;r+=t;}
    if(!r)d[u]=-1;
    return r;
}
int q[M<<1];
int dinic(){
    int t,ans=0,i,j,u;
    while(1){
        CL(d,-1);
        for(d[q[i=0]=S]=0,j=1;i!=j;)for(int k=head[u=q[i++]];k!=-1;k=E[k].nx)
        if(d[E[k].v]==-1&&E[k].w){d[E[k].v]=d[u]+1;if(E[k].v!=T)q[j++]=E[k].v;}
        if(d[T]==-1)break;
        while(t=dfs(S,INF))ans+=t;
    }
    return ans;
}
char mp[120][120];
int sx, sy, ex, ey;
void jia(int x, int y)
{
    add(x, y, 1); add(y, x, 1);
}
int main()
{


    init();
    SCC(n, m);
    FF(i, 1, n){
        SS(mp[i]+1);
        FF(j, 1, m){
            if(mp[i][j] != '.') jia(i, j+n);
            ///
            if(mp[i][j] == 'S') sx = i, sy = j+n;
            else if(mp[i][j] == 'T') ex = i, ey = j+n;
        }
    }
    S = 0; T = n+m+1;
    add(S, sx, INF); add(S, sy, INF);
    add(ex, T, INF); add(ey, T, INF);
    int ans = dinic();
    if(ans > 10000) puts("-1");
    else PR(ans);
    return 0;
}


Measured memory_bytes: 768
#include<bits/stdc++.h>
// __builtin_ctz : no of trailing zeros
#define ll long long
#define pp pair<ll,ll>
#define mod 1000000007
#define trace(x) cerr<<#x<<": "<<x<<" "<<endl
#define trace2(x, y) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z) cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define sa(a,n) for(int i =0 ; i<n ; i++) cin>>a[i]
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define scan() int n; cin>>n ; int a[n]; for(int i = 0 ; i<n ; i++) cin>>a[i]
#define print(a,n) for(int i = 0 ; i < n ; i++) cout<<a[i]<<' '
using namespace std;
ll max(ll x, ll y)
{
    return x>y ? x : y;
}
ll min(ll x, ll y)
{
    return x<y ? x : y;
}
void _(ll&a , ll b)
{
    a=(a%mod+b%mod)%mod;
    a=(a+mod)%mod;
}
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll x,y,a,b,c;cin >> x >> y >> a >> b >> c;
    vector<pp> v;
    for (int i = 0; i < a; ++i)
    {
    	ll d;cin >> d;v.push_back({d,0});
    }
    for (int i = 0; i < b; ++i)
    {
    	ll d;cin >> d;v.push_back({d,1});
    }
    for (int i = 0; i < c; ++i)
    {
    	ll d;cin >> d;v.push_back({d,2});
    }
    sort(v.begin(), v.end(), greater<pp>());
    ll ans=0;
    ll p,q;p=q=0;ll d=0;
    for (int i = 0; i < x+y; ++i)
    {
    	if(v[i].second==2)ans+=v[i].first;
    	else if(v[i].second==0)
    	{
    		if(p<x)
    		{
    			p++;ans+=v[i].first;
    		}
    		else
    		{
    			d++;
    			continue;
    		}
    	}
    	else
    	{
    		if(q<y)
    		{
    			q++;ans+=v[i].first;
    		}
    		else
    		{
    			d++;
    			continue;
    		}
    	}
    }
    if(d==0)cout << ans;
    else
    {
    	if(p<x)
    	{
    		for(ll i=x+y;i<v.size() and d;i++)
    		{
    			if(v[i].second==0 or v[i].second==2)
    			{
    				ans+=v[i].first;d--;
    			}
    		}
    	}
    	else
    	{
    		for(ll i=x+y;i<v.size() and d;i++)
    		{
    			if(v[i].second==1 or v[i].second==2)
    			{
    				ans+=v[i].first;d--;
    			}
    		}
    	}
    	cout << ans;
    }
    }

Measured memory_bytes: 10348
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define MOD (int) (1e9+7)
#define INF (int) 2e9

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

    int cnt = 0;
    for (int i = 1; i <= m; i++) {
        for (int d10 = 2; d10 <= d/10; d10++) {
            for (int d1 = 2; d1 <= 9; d1++) {
                if (d10*10+d1 <= d && i==d1*d10){
                    // printf("%d %d %d\n", i, d10, d1);
                    cnt++;
                }
            }
        }
    }
    
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
c,i,k[30],x;main(n){for(;~scanf("%d",&i);)k[__builtin_ctz(i)]=--n&&(x^=i);for(i=30;i--;x&n&&(c++,x^=n*2-1))n=k[i]<<i;printf("%d",x?-1:c);}

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

int main() {
    int n;
    cin>>n;
    multiset<int> s;
    for(int i = 0; i < n; ++i) {
        int x;
        cin>>x;
        s.insert(x);
    }
    int lf = *s.begin(), rt = *s.begin();                                                                                   
    s.erase(s.begin());
    long long ans = 0;
    while(!s.empty()) {
        int tp = *s.begin();
        int bt = *(--s.end());

        if(abs(lf-tp) >= abs(lf-bt) && abs(lf - tp) >= abs(rt - tp) && abs(lf-tp) >= abs(rt-bt)) {
            ans += abs(lf - tp);
            lf = tp;
            s.erase(s.find(tp));
        }
        else if(abs(rt-tp) >= abs(lf-tp) && abs(rt-tp) >= abs(lf-bt) && abs(rt-tp) >= abs(rt-bt)) {
            ans += abs(rt - tp);
            rt = tp;
            s.erase(s.find(tp));
        }
        else if(abs(rt-bt) >= abs(lf-tp) && abs(rt-bt) >= abs(lf-bt) && abs(rt-bt) >= abs(rt-tp)) {
            ans += abs(rt - bt);
            rt = bt;
            s.erase(s.find(bt));
        }
        else {
            ans += abs(lf - bt);
            lf = bt;
            s.erase(s.find(bt));
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 4992
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int n; string s;
int calc(int l, int r) {
	int d = 0, c = 0, w = l;
	for (int i = l; i < r; i++) c += (s[i] == '[' || s[i] == ']' ? 1 : 0);
	if (c == 0) return stoi(s.substr(l, r)) / 2 + 1;
	vector<int> v;
	for (int i = l; i < r; i++) {
		if (s[i] == '[') d++;
		if (s[i] == ']') d--;
		if (d == 0) v.push_back(calc(w + 1, i)), w = i + 1;
	}
	sort(v.begin(), v.end());
	int ret = 0;
	for (int i = 0; i <= v.size() / 2; i++) ret += v[i];
	return ret;
}
int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> s;
		cout << calc(0, s.size()) << endl;
	}
	return 0;
}

Measured memory_bytes: 3204
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
#include<iterator>
#include<list>

using namespace std;

#define INF LLONG_MAX / 5
#define MOD 1000000007
#define int long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define enld endl

signed main() {
	int N, A;
	cin >> N >> A;
	vector<int>x(N);
	int Sx = 0;
	rep(i, N) {
		cin >> x[i];
		Sx += x[i];
	}
	vector<vector<vector<int>>>dp(N + 1, vector<vector<int>>(N + 1, vector<int>(Sx + 1)));
	rep(i, N + 1) {
		rep(j, N + 1) {
			rep(k, Sx + 1) {
				if (i == 0) {
					if (j == 0 && k == 0) {
						dp[i][j][k] = 1;
					}
					else {
						dp[i][j][k] = 0;
					}
				}
				else {
					if (j - 1 < 0 || k - x[i - 1] < 0) {
						dp[i][j][k] = dp[i - 1][j][k];
					}
					else {
						dp[i][j][k] = dp[i - 1][j][k] + dp[i - 1][j - 1][k - x[i - 1]];
					}
				}
			}
		}
	}
	int ans = 0;
	rep(i, N + 1) {
		rep(j, N + 1) {
			rep(k, Sx + 1) {
				if (i == N && k == j * A && j!=0 && k!=0) {
					ans += dp[i][j][k];
				}
			}
		}
	}
	cout << ans << enld;
}

Measured memory_bytes: 55172
from itertools import count, takewhile
from math import floor, sqrt

n = int(input())
xys = [map(int, input().split()) for _ in range(n)]

def mysqrt(n):
    x = floor(sqrt(n))
    for y in takewhile(lambda y: y**2 <= n, count(max(0, x-10))):
        x = y
    return x

for x, y in xys:
    xy = x*y
    root = mysqrt(xy-1)
    ans = root*2 - (root**2 + root >= xy) - 1 + (x == y)
    print(ans)

Measured memory_bytes: 3064
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <climits>
#include <ctime>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <set>
#include <map>
#include <iostream>
#include <deque>
#include <complex>
#include <string>
#include <iomanip>
#include <sstream>
#include <bitset>
#include <valarray>
#include <iterator>
using namespace std;
typedef long long int ll;
typedef unsigned int uint;
typedef unsigned char uchar;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();i++)
#define ALL(container) container.begin(), container.end()
#define RALL(container) container.rbegin(), container.rend()
#define SZ(container) ((int)container.size())
#define mp(a,b) make_pair(a, b)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

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 (a>b) { a=b; return 1; } return 0; }
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"["; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"]"; return os;
}
template<class T> ostream& operator<<(ostream &os, const set<T> &t) {
os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}

const int INF = 1<<28;
const double EPS = 1e-8;
const int MOD = 1000000007;


int n;

main(){
	while(scanf("%d", &n), n){
		vector<int> idx(86402);
		REP(i, n){
			int h,m,s;
			scanf("%d:%d:%d", &h, &m, &s);
			idx[h*3600+m*60+s+1] ++;
			scanf("%d:%d:%d", &h, &m, &s);
			idx[h*3600+m*60+s+1] --;
		}
		int ans = 0;
		REP(i, 86401){
			chmax(ans, idx[i+1] += idx[i]);
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1548
import sys


# \n
def input():
    return sys.stdin.readline().rstrip()


def main():
    N, T = map(int, input().split())
    dp = [0] * (T + 1)
    AB = []
    for k in range(N):
        a, b = map(int, input().split())
        AB.append((a, b))

    AB.sort()
    maxdp = 0
    temp = 1
    for i in range(N):
        a, b = AB[i]  # a:time  b:value
        temp += a
        dp[T] = max(maxdp + b, dp[T])
        for j in range(min(T - 1, temp), a - 1, -1):
            dp[j] = max(dp[j], dp[j - a] + b)
            maxdp = max(dp[j], maxdp)
    print(dp[T])


if __name__ == "__main__":
    main()


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

using namespace std;
typedef long long ll;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vd = vector<double>;
using vvd = vector<vd>;

#define out(a) cout << a << endl
#define out1(a) cout << a
#define in(a) cin >> a
#define in2(a, b) cin >> a >> b
#define in3(a, b, c) cin >> a >> b >> c
#define rep(i, N) for (ll i = 0; i < (ll)N; i++)
#define rep1(i, N) for (ll i = 1; i <= (ll)N; i++)
#define repi(i, j, N) for (ll j = (ll)i + 1; j < (ll)N; j++)
#define all(v) v.begin(), v.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;
}

constexpr int inf = 1e9;
constexpr ll linf = 1e18;
constexpr ll mod = 1e9 + 7;

void solve();

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

void solve()
{
    int a, b, c;
    in3(a, b, c);
    if (a + b + c >= 22)
    {
        out("bust");
    }
    else
    {
        out("win");
    }
}

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

using namespace std;

int round10(int x) {
  int r = x % 10;
  return r ? x - r + 10 : x;
}

int main() {
  int n = 5;
  vector<int> time(n);
  vector<int> next_time(n);
  for (int i = 0; i < n; i++) {
    cin >> time[i];
    next_time[i] = round10(time[i]);
  }

  int ans = 100000;
  for (int i = 0; i < n; i++) {  // i index for the last item
    int sum = time[i];
    for (int j = 0; j < n; j++) {
      if (i != j) sum += next_time[j];
    }
    ans = min(ans, sum);
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);i++)
#define debug(x) cout<<#x<<"="<<x<<endl;
#define LL long long 
#define sz(x) x.size()
using namespace std;
int main(void)
{
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	if(a+b>c+d)printf("Left");
	else if (a+b<c+d)printf("Right");
	else printf("Balanced");
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int x, y;
  cin >> x >> y;
 
  if(y%2==1){
    cout << "No" << endl; 
  }
  else if(y<2*x){
    cout << "No" << endl; 
  }
  else if(4*x < y){
    cout << "No" << endl; 
  }
  else{
    cout << "Yes" << endl; 
  }
  
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
// type alias
typedef long long LL;
typedef pair<int,int> II;
typedef tuple<int,int,int> III;
typedef vector<int> VI;
typedef vector<string> VS;
typedef unordered_map<int,int> MAPII;
typedef unordered_set<int> SETI;
template<class T> using VV=vector<vector<T>>;
// minmax
template<class T> inline T SMIN(T& a, const T b) { return a=(a>b)?b:a; }
template<class T> inline T SMAX(T& a, const T b) { return a=(a<b)?b:a; }
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// collection
#define ALL(c) (c).begin(),(c).end()
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// stdout
#define println(args...) fprintf(stdout, ##args),putchar('\n');
// debug cerr
template<class Iter> void __kumaerrc(Iter begin, Iter end) { for(; begin!=end; ++begin) { cerr<<*begin<<','; } cerr<<endl; }
void __kumaerr(istream_iterator<string> it) { (void)it; cerr<<endl; }
template<typename T, typename... Args> void __kumaerr(istream_iterator<string> it, T a, Args... args) { cerr<<*it<<"="<<a<<", ",__kumaerr(++it, args...); }
template<typename S, typename T> std::ostream& operator<<(std::ostream& _os, const std::pair<S,T>& _p) { return _os<<"{"<<_p.first<<','<<_p.second<<"}"; }
#define __KUMATRACE__ true
#ifdef __KUMATRACE__
#define dump(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); __kumaerr(_it, args); }
#define dumpc(ar) { cerr<<#ar<<": "; FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }
#define dumpC(beg,end) { cerr<<"~"<<#end<<": "; __kumaerrc(beg,end); }
#else
#define dump(args...)
#define dumpc(ar)
#define dumpC(beg,end)
#endif

// $ cp-batch Stones | diff Stones.out -
// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address Stones.cpp && ./a.out

/*
 
 4/20/2019
 
 5:00-
 
 */

const int MAX_N=1e6+1;
int N;
string S;

int W[MAX_N],cum[MAX_N];
void solve() {
  REP(i,N) W[i]=S[i]=='.';
  dumpC(W,W+N);
  REP(i,N) cum[i+1]=cum[i]+W[i];
  int res=1e6;
  REPE(i,N) {
    int b=i-cum[i],w=(cum[N]-cum[i]);
//    dump(i,w,b);
    SMIN(res,w+b);
  }
  cout<<res<<endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout<<setprecision(12)<<fixed;
  
  cin>>N>>S;
  solve();
  
  return 0;
}


Measured memory_bytes: 5524
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
long long A,B,C,K;
int main()
{
	scanf("%lld%lld%lld",&A,&B,&C);
	if(((A%2)&(B%2)&(C%2))==0)printf("0\n");
	else printf("%lld",min(A*B,min(A*C,B*C)));//
}

Measured memory_bytes: 256
import collections

N = int(input())
a = collections.deque()
for i in range(N):
    a.append(int(input()))
    
s = a[0]
cnt = 1

for i in range(N):
    if s == 2:
        print(cnt)
        exit()
    cnt += 1
    s = a[s-1]
    
print(-1)

Measured memory_bytes: 7284
#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>;

int main() {
    int n, m; cin >> n >> m;
    vector<ll> x(n), y(n), z(n);
    rep(i,n) cin >> x.at(i) >> y.at(i) >> z.at(i);

    vector<vector<ll>> sum(8, vector<ll>(n, 0));
    rep(i, 8){
        rep(j, n){
            if(i==0)sum.at(i).at(j) = x.at(j) + y.at(j)+z.at(j);
            if(i==1)sum.at(i).at(j) = -x.at(j) + y.at(j)+z.at(j);
            if(i==2)sum.at(i).at(j) = x.at(j) - y.at(j)+z.at(j);
            if(i==3)sum.at(i).at(j) = -x.at(j) - y.at(j)+z.at(j);
            if(i==4)sum.at(i).at(j) = x.at(j) - y.at(j) - z.at(j);
            if(i==5)sum.at(i).at(j) = x.at(j) + y.at(j) - z.at(j);
            if(i==6)sum.at(i).at(j) = -x.at(j) + y.at(j) - z.at(j);
            if(i==7)sum.at(i).at(j) = -x.at(j) - y.at(j) - z.at(j);
        }
    }


    rep(i, 8){
        sort(sum.at(i).rbegin(), sum.at(i).rend());
    }

    ll ans = 0;
    rep(i, 8){
        ll tmp = 0;
        rep(j, m) {
            tmp += sum.at(i).at(j); 
            dump(sum.at(i).at(j));
        }
        ans = max(tmp, ans);
    }

    cout << ans << endl;

    return 0;
}


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

#define int long long



signed main() {
    
    string s;
    cin >> s;
    
    if(s[0]==s[1] && s[1]==s[2]) {puts("Yes"); return 0;}
    if(s[1]==s[2] && s[2]==s[3]) {puts("Yes"); return 0;}
    puts("No");
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using ll = long long int;
using namespace std;
ll mod=1e9+7;

int main(){
  int n,m;
  cin >> n >>m;
  int a[3]={};
  int b[3]={};
  for(int i=0;i<m;i++){
    int q;
    cin >> q;
    b[q-1]++;
    int p;
    cin >> p;
    if(n==3 && p==0 && q==1){cout << -1 << endl;
                          return 0;}
    if(n==2 && p==0 && q==1){cout << -1 << endl;
                          return 0;}

    if(a[q-1]!=p && b[q-1]>=2){cout << -1 << endl;
                          return 0;}else{a[q-1]=p;}

  }
  if(n==1){cout << a[0] << endl;}
  if(n==2){if(a[0]==0){a[0]=1;}
    cout << a[0]*10+a[1] << endl;}
  if(n==3){if(a[0]==0){a[0]=1;}cout << a[0]*100+a[1]*10+a[2] << endl;}
  
}

Measured memory_bytes: 256
//In the name of God

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

typedef long long ll;
typedef pair <int , int> pii;

const int N = 1e3+10 , mod = 1e9+7;

int dp[N][N];

int32_t main(){
   ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
   int h , w;
   cin >> h >> w;
   dp[1][1] = 1;
   for(int i = 1 ; i <= h ; i++)
      for(int j = 1 ; j <= w ; j++){
         char c;
         cin >> c;
         if(c == '.')
            dp[i][j] += (dp[i - 1][j] + dp[i][j - 1]) % mod;
      }
   cout << dp[h][w];
   return 0;
}


Measured memory_bytes: 4224
#include<iostream>
#include<stdio.h>
#include<cmath>
#include<string>
#include<string.h>
using namespace std;

int main(){
	double a, b, c, C;
	double rad;
	double PI = acos(-1);
	cin >> a >> b >> C;
	rad = C*PI / 180;
	double S, L, h;
	S = (a*b*sin(rad)) / 2;
	c = sqrt(a*a + b*b - 2 * a*b*cos(rad));
	L = a + b + c;
	h = (2 * S) / a;
	printf("%f\n", S);
	printf("%f\n", L);
	printf("%f\n", h);
	return 0;
}


Measured memory_bytes: 3408
n = int(input())
s = []
ans = 0
for i in range(n):
    k = int(input())
    if k % 10 != 0:
        s.append(k)
    ans += k

if ans % 10 != 0:
    print(ans)
else:
    if len(s) != 0:
        print(ans - min(s))
    else:
        print(0)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;

vector<ll> num;

struct Nbase {
    int n;
    int sz = 1;
    long long max = 1e18;

    Nbase(int k = 2){
        n = k;
        while(max != 0){
            max /= n;
            sz++;
        }
        num.resize(sz);
    };

    //繰り返し二乗法
    ll EX(ll x,ll n){
        if(n == 0) return 1;
        else if(n%2 == 1) return EX(x,n-1)*x;
        else return EX(x*x,n/2);
    }

    vector<int> to_n(ll num){
        vector<int> ret(sz);
        for(int i = sz-1; i >= 0; i--){
            long long subtraction = EX(n,i);
            if(subtraction <= num){
                for(int j = 1; j <= n; j++){
                    if(num < j*subtraction){
                        ret[i] = j-1;
                        num -= ret[i]*subtraction;
                    } 
                }
            } else ret[i] = 0;
        }
        return ret;
    }

    long long re_n(vector<int>& vec){
        long long ret = 0;
        vec.resize(sz);
        for(int i = 0; i < sz; i++){
            ret += vec[i]*EX(n,i);
        }
        return ret;
    }

    void supress(const vector<int>& lim,vector<int>& at){
        bool upper = true;
        for(int i = sz; i >= 0; i--){
            /*if(upper && lim[i] > 0) upper = false;
            if(lim[i] > at[i]) break;
            else if(upper || lim[i] < at[i]) at[i] = lim[i];*/
            if(upper && lim[i] == 1) upper = false;
            if(lim[i] == 1 && at[i] == 0) break;
            else if(lim[i] == 0 || upper) at[i] = 0;
        }
    }
};

int main(){
    Nbase base = 2;
    ll n,k;
    cin >> n >> k;
    vector<ll> a(n);
    for(ll i = 0; i < n; i++){
        cin >> a[i];
        vector<int> sam = base.to_n(a[i]);
        for(int j = 0; j < base.sz; j++){
            if(sam[j] == 1) num[j]++;
        }
    }
    vector<int> x(base.sz);
    for(int i = 0; i < base.sz; i++){
        if(num[i] <= n/2) x[i] = 1;
        else x[i] = 0;
    }
    
    vector<int> kd = base.to_n(k);
    //base.supress(kd,x);
    bool flag = true;
    for(int i = base.sz; i >= 0; i--){
        if(flag && kd[i] == 1) flag = false;
        if(kd[i] == 1 && x[i] == 0) break;
        else if(kd[i] == 0 || flag) x[i] = 0;
    }
    ll X = base.re_n(x);
    ll ans = 0;
    for(int i = 0; i < n; i++){
        ans += X^a[i];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4044
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <functional>
#include <utility>
#include <cctype>
#include <fstream>
#include <cstring>

using namespace std;

#define ll long long
#define MOD 1000000007
#define INF 2000000000
#define LINF 9000000000000000000
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define du(x) cout<<#x<<'='<<x<<endl
#define du2(x,y) cout<<#x<<'='<<x<<' '<<#y<<'='<<y<<'\n'<<endl
#define du3(x,y,z) cout<<#x<<'='<<x<<' '<<#y<<'='<<y<<' '<<#z<<'='<<z<<'\n'<<endl
#define darr(arr,n) rep(i,(n-arr)){cout<<*(arr+i)<<' ';}cout<<endl
#define ddarr(arr,a,b) rep(i,a){rep(j,b){cout<<*(arr+i*b+j)<<' ';}cout<<endl;}
#define ddd ifstream in("Text.txt");cin.rdbuf(in.rdbuf());


int main() {
    int A, B, T;
    cin >> A >> B >> T;
    cout << T  / A * B << endl;

}

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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

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

using ll=long long;
using R=long double;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

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

// Problem Specific Parameter:

int main(void){
	int n,m,k;
	cin >> n >> m >> k;

	bool ok = false;
	rep(i,n+1)rep(j,m+1){
		int cur = n*m - (i*j) - (n-i)*(m-j);
		if(cur==k) ok=true;
	}

	if(ok)
		puts("Yes");
	else
		puts("No");

	return 0;
}

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

int main() {
    int n, sum=0;
    cin>>n;

    vector<int> a(n);
    vector<int> c(n-1);
    for(int i=0; i<n; i++){
        cin>>a.at(i);
    }
    for(int i=0; i<n; i++){
        int b;
        cin>>b;
        sum+=b;
    }
    for(int i=0; i<n-1; i++){
        cin>>c.at(i);
    }

    for(int i=0; i<n; i++){
        if(i<n-1&&a.at(i)+1==a.at(i+1)){
                int aaa=a.at(i);
                sum+=c.at(aaa-1);
        }
    }

    cout<<sum<<endl;
}


Measured memory_bytes: 256
#include <cstdio>

typedef long long int64;

int digits[20], len, mxsum;
int64 n;

int main() {
	scanf("%lld", &n), ++n;
	len = 0;
	while (n > 0) {
		digits[len++] = n % 10, n /= 10;
	}
	for (int i = 0; i < len; ++i) {
		if (digits[i] == 0) {
			continue;
		}
		int sum = (digits[i] - 1) + 9 * i;
		for (int j = i + 1; j < len; ++j) {
			sum += digits[j];
		}
		if (sum > mxsum) {
			mxsum = sum;
		}
	}
	printf("%d\n", mxsum);
	return 0;
}

Measured memory_bytes: 128
n = int(input())
P =[]
s = 0
for i in range(n):P.append([int(i) for i in input().split()])
P.append(P[0])
for i in range(n):s += P[i][0]*P[i+1][1] - P[i][1]*P[i+1][0]
print(abs(s)*0.5)

Measured memory_bytes: 7716
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef pair<ll,ll> ii;
const int N = 2e5+1;
ll a[N];
ll pre[N];
ll ans = 1e18;
ll sum(int l,int r)		{	return pre[r] - pre[l-1];	}
int main()
{
	pre[0]=0ll;
	int n,i,j,k,l,r,pos;
	scanf("%d",&n);
	for(i=1;i<=n;++i)	scanf("%lld",&a[i]);
	for(i=1;i<=n;++i)	pre[i] = pre[i-1] + a[i];
	for(i=2;i<=n;++i)
	{
		l=1;r=i-1;pos=l;
		while(l<=r) 
		{
			int mid=(l+r)/2;
			if(2*pre[mid]>pre[i]) 	r=mid-1;
			else 					
			{
				pos=mid;
				l=mid+1;
			}
		}
		int lower_bound=pos;
		l=i+1;r=n-1;pos=l;
		while(l<=r)
		{
			int mid=(l+r)/2;
			if(2*sum(i+1,mid)>sum(i+1,n)) r=mid-1;
			else 							
			{
				pos=mid;
				l=mid+1;
			}
		}
		int upper_bound=pos;
		for(j=lower_bound-5;j<=lower_bound+5;j++)
		{
			for(k=upper_bound-5;k<=upper_bound+5;k++)
			{
				if(j>0&&j<i&&k>i&&k<n)
				{
					ll a = pre[j];
					ll b = sum(j+1,i);
					ll c = sum(i+1,k);
					ll d = sum(k+1,n);
					ll mn = min(min(a,b),min(c,d));
					ll mx = max(max(a,b),max(c,d));
					ans=min(ans,mx-mn);
				}
			}
		}
	}	
	printf("%lld",ans);
}


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

using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++)cin >> a[i];

    vector<int> sorted = a;
    sort(sorted.begin(), sorted.end());

    int dif = 0;
    for (int i = 0; i < n; i++)
        if (a[i] != sorted[i])dif++;

    int q;
    cin >> q;
    int ret = 0;
    for (int i = 0; i < q && dif != 0; i++) {
        int x, y;
        cin >> x >> y;
        x--;
        y--;
        if (a[x] == sorted[x])dif++;
        if (a[y] == sorted[y])dif++;
        swap(a[x], a[y]);
        if (a[x] == sorted[x])dif--;
        if (a[y] == sorted[y])dif--;
        ret++;
    }

    cout << (dif == 0 ? ret : -1) << endl;
    return 0;
}


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

int main(){
  string s;
  cin >> s;
  int counter = 0;
  
  if(s[0] == '1')++counter;
  if(s[1] == '1')++counter;
  if(s[2] == '1')++counter;
  
  cout << counter << endl;
  return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy
 
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);    
	
	string S; cin >> S; cin >> S;
	
	cout << "A" << S[0] << "C" << endl;
	
	return 0;
}
 
// read the question correctly (ll vs int)
// template by bqi343


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	char str;
	int i=0;
	
	
	for(i=0;i<1200;i++){
		scanf("%c",&str);
		
		if(str >= 'A' && str <= 'Z'){
			str = str + 32;
		}
		else if (str >= 'a' && str <= 'z'){
			str = str - 32;
		}
		
		if(str == '\n' || str == '\0'){

			break;

		}
			
			printf("%c",str);
	}
			printf("\n");

	return 0;
}

Measured memory_bytes: 524
D, N = map(int, input().split())

if D == 0:
    if N==100:
        print(N+1)
    else:
        print(N)
elif D == 1:
    if N==100:
        print(N*101)
    else:
        print(N*100)
else:
    if N == 100:
        print(N*10100)
    else:
        print(N*10000)

Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
using namespace std;
int n, w[1000], s[1000];
string S[1000]; vector<int>b; int maxn;
int main() {
	while (true) {
		cin >> n; b.clear(); maxn = 1 << 30;
		if (n == 0) { break; }
		for (int i = 0; i < n; i++) {
			cin >> S[i] >> w[i] >> s[i];
		}
		vector<int>a(n, 0);
		for (int i = 0; i < n; i++)a[i] = i;
		do {
			int sum2 = 0;
			for (int i = 0; i < n; i++) {
				int sum = 0;
				for (int j = i + 1; j < n; j++) {
					sum += w[a[j]];
				}
				if (sum > s[a[i]]) goto E;
			}
			for (int i = 0; i < n; i++) {
				sum2 += i*w[a[i]];
			}
			if (maxn > sum2) {
				b = a; maxn = sum2;
			}
		E:;
		} while (next_permutation(a.begin(), a.end()));
		for (int i = 0; i < n; i++) { cout << S[b[i]] << endl; }
	}
	return 0;
}

Measured memory_bytes: 1232
import java.util.*;
import java.awt.*;
import static java.lang.System.*;
import static java.lang.Math.*;
//Loopで使う文字列の長さは固定！
//intで大丈夫？オーバーフローしない？
//Loop回数は本当に10⁹以内になってる？Loopは回る？？
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(in);
        long a=sc.nextLong();
        long b=sc.nextLong();
        long x=sc.nextLong();
        out.println(-(a+x-1)/x+(b+1+x-1)/x);
    }
}


Measured memory_bytes: 23892
#include <stdio.h>
int main(void)
{
  int S,m,h,s;
  scanf("%d",&S);
  h=S/3600;
  m=(S-h*3600)/60;
  s=S-h*3600-60*m;
  printf("%d:%d:%d\n",h,m,s);
  return 0;
}

Measured memory_bytes: 592
breaking n state [] = if state == 1 then -1 else n
breaking n state lst = 
  let h = head lst
  in if h == state
    then breaking n (state+1) (tail lst)
    else breaking (n+1) state (tail lst)

main = do
  _ <- getLine
  as <- (map read) . words <$> getLine
  print $ breaking 0 1 as

Measured memory_bytes: 67964
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <map>
#include <set>
#include <sstream>
#include <stdio.h>
#include <cstdio>
#include <cstring>
#include <math.h>

using namespace std;

#define Rep(i,a,b) for(int i = a; i < b; i++)
#define rep(i,b) Rep(i,0,b)
#define rrep(i,a) for(int i = a; i >= 0; i--)
#define allof(a) (a).begin(), (a).end()

typedef long long ll;
const int inf = 1e9 + 7;
const ll infll = 1ll << 60ll;
const ll mod = 1e9 + 7;
// 0~3までは右左下上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
constexpr int dy[] = { 0, -1, 0, 1, 1, -1, -1, 1 };

/*
// 最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

// 最小公倍数
ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
}*/

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

	vector<vector<int>> c(3, vector<int>(3));
	rep(i, 3) {
		rep(j, 3) {
			cin >> c[i][j];
		}
	}

	// b1-b2 b2-b3 b3-b1
	// a1-a2 a2-a3 a3-a1 が全部揃うようにする
	vector<int>b123(3, -101);
	vector<int>a123(3, -101);

	b123[0] = c[0][0] - c[0][1];
	b123[1] = c[0][1] - c[0][2];
	b123[2] = c[0][2] - c[0][0];
	a123[0] = c[0][0] - c[1][0];
	a123[1] = c[1][0] - c[2][0];
	a123[2] = c[2][0] - c[0][0];

	bool can = true;

	// bをみる
	rep(i, 3) {
		rep(j, 3) {
			if (c[i][j] - c[i][(j + 1) % 3] != b123[j]) {
				can = false;
				break;
			}

		}
	}

	// aをみる
	rep(i, 3) {
		rep(j, 3) {
			if (c[i][j] - c[(i + 1) % 3][j] != a123[i]) {
				can = false;
				break;
			}
		}
	}

	if (can) cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}

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

class Node{
public:
    int sum;
    vector<Node> ch;

    void calc(){
        if(ch[0].sum==0){
            rep(i,ch.size()){
                ch[i].calc();
            }
        }
        sort(ch.begin(),ch.end());
        rep(i,(ch.size()+1)/2){
            sum+=ch[i].sum;
        }
    }
    Node(){sum=0;ch=vector<Node>();}
};

void paser2(Node &n);
Node paser(){
    Node n;
    getchar();
    char c=getchar();

    if(c=='['){
        cin.putback(c);
        paser2(n);
    }
    else if(c>='0'&&c<='9')
    {
        int d;
        cin.putback(c);
        cin>>d;
        n.sum=(d+1)/2;
        //cout<<"input"<<n.sum<<endl;
    }
    getchar();

    return n;
}
void paser2(Node &n){
    while(1){
        char c=getchar();
        if(c!='['){cin.putback(c);break;}
        cin.putback(c);
        n.ch.push_back(paser());
    }
}
bool operator<(const Node &a,const Node &b){
    return a.sum<b.sum;
}
int main(){
    int N;cin>>N;
    rep(i,N){
        char c=getchar();
        Node n=paser();
        n.calc();
        cout<<n.sum<<endl;
    }
}

Measured memory_bytes: 1360