akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

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

  int N;
  cin >> N;
  VI xs(N);
  REP(i,N) cin >> xs[i];

  int ans = 0;
  REP(i,N-1){
	if(xs[i] == i+1){
	  ++ans;
	  swap(xs[i], xs[i+1]);
	}
  }
  cout << (xs.back() == N? 1:0) + ans << endl;

  return 0;
}


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

using namespace std;
typedef long long int lld;
#define INF 1000000000000000000
#define MOD 1000000007
double DP[5000][5000];
double arr[5000];
int n;
double compute(int a,int h){//cout<<a<<" "<<b<<endl;
	if(h==-1)return 0;
	if(DP[a][h]!=-1)return DP[a][h];
	if(a==0)return 0;
	DP[a][h]=0;
	DP[a][h]+=arr[a-1]*compute(a-1,h-1);
	DP[a][h]+=(1-arr[a-1])*compute(a-1,h);
	return DP[a][h];
}
int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>arr[i];
	}
	for(int i=0;i<=n;i++){
		for(int j=0;j<=n;j++)DP[i][j]=-1;
	}
	DP[0][0]=1;
	double ans=0;
	for(int i=n/2+1;i<=n;i++)ans+=compute(n,i);
	cout<<setprecision(15)<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 118656
import java.util.Scanner;

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

		int ok = 0;
		for(int i = 0; i < s.length(); i++) {
			if(s.substring(i, i+1).contentEquals("o")) {
				ok++;
			}
		}

		if((15-s.length() + ok) >= 8) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}



	}
}

Measured memory_bytes: 22996
#include <iostream>
#include <algorithm>
using namespace std;
long long int s[100001];
int main()
{
    long long int n, a, b, sum = 0;
    cin >> n >> a >> b;
    for (int i = 1; i <= n; i++)
    {
        cin >> s[i];
    }
    for (int i = 2; i <= n; i++)
    {
        long long int m = (s[i] - s[i - 1]) * a;
        sum += min(m, b);
    }
    cout << sum << endl;
}

Measured memory_bytes: 1024
from collections import defaultdict
import sys
sys.setrecursionlimit(10**7)
def dfs(v,t,f,used):
    if v==t:
        return f
    used[v]=True
    for nv,cap in G[v].items():
        if not used[nv] and cap>0:
            d=dfs(nv,t,min(f,cap),used)
            if d>0:
                G[v][nv]-=d
                G[nv][v]+=d
                return d
    return 0

def Max_Flow(s,t):
    flow=0
    while(True):
        used=[False]*(2*N+2)
        f=dfs(s,t,INF,used)
        if f==0:
            return flow
        flow+=f

INF=float('inf')

N=int(input())
G=[defaultdict(int) for i in range(2*N+2)]
arr=[]
for i in range(2*N):
    x,y=map(int,input().split())
    arr.append((x,y))

for i in range(N,2*N):
    for j in range(N):
        a,b=arr[i]
        c,d=arr[j]
        if a>c and b>d:
            G[i+1][j+1]=1
            G[j+1][i+1]=0

for i in range(N):
    G[0][N+i+1]=1
    G[N+i+1][0]=0
    G[i+1][2*N+1]=1
    G[2*N+1][i+1]=0
res=Max_Flow(0,2*N+1)
print(res)

Measured memory_bytes: 77348
#include <iostream>
#include <vector>
#include <unordered_map>
#include <map>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <deque>
#include <cmath>
#include <stack>
#include <queue>
#include <string>
#include <iomanip>
#include <cstring>
#include <climits>
#include <cstdio> 

#define nl '\n'

using namespace std;

int k, a, b;

int main() {

    cin >> k >> a >> b;

    for(int i = a; i <= b; i++) {
        if(i % k  == 0) {
            cout << "OK";
            return 0;
        }
    }

    cout << "NG";




}
 
//g++ -std=c++14 comp.cpp -o c && c.exe
//g++ -std=c++14 comp.cpp -o c; ./c.exe
//g++ -std=c++14 comp.cpp && ./a.out

Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define i_7 (ll)(1E9+7)
#define i_5 (ll)(1E9+5)
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    else return c+i_7;
}
typedef pair<int,int> i_i;
typedef pair<ll,ll> l_l;
ll inf=(ll)1E12;//10^12
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
const double EPS=1E-8;
////////////////////////////////////////



int main() {
    ios::sync_with_stdio(false);cin.tie(0);
    
    ll n;cin>>n;
    ll a[n],b[n];rep(i,0,n-1)cin>>a[i];
    rep(i,0,n-1)cin>>b[i];
    ll ans=0;
    rep(k,1,29){
        ll p=(ll)1<<k;
        ll c[n],d[n];
        rep(i,0,n-1){
            d[i]=b[i]%p;
            c[i]=a[i]%p;
        }
        sort(d,d+n);
        ll sum=0;
        rep(i,0,n-1){
            sum+=lower_bound(d,d+n,p-c[i])-lower_bound(d,d+n,p/2-c[i]);
            sum+=lower_bound(d,d+n,2*p-c[i])-lower_bound(d,d+n,3*p/2-c[i]);
        }
        if(sum%2)ans+=1<<(k-1);
    }
    cout<<ans<<endl;
    return 0;
}

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

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

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

int main() {
    string s;
    cin >> s;
    int a = (s[0] - '0')*10 + (s[1] - '0');
    int b = (s[2] - '0')*10 + (s[3] - '0');
    bool at = (1 <= a && a <= 12);
    bool bt = (1 <= b && b <= 12);
    if (at && bt) cout << "AMBIGUOUS" << endl;
    else if (at) cout << "MMYY" << endl;
    else if (bt) cout << "YYMM" << endl;
    else cout << "NA" << endl;
    return 0;
}

Measured memory_bytes: 3596
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<utility>
#include<array>
#include<cassert>
#include<list>
#include<experimental/any>
#include<cstring>
#include<cctype>
#include<ctime>
#include<cstdbool>
#include<cstdint>
#include<cstddef>
#include<set>
#include<unordered_set>
#include<bitset>
 
using namespace std;
using experimental::any;
 
#define SPEEDY cin.tie(0);ios::sync_with_stdio(false);
 
#define REP(i,n) for(int i=0;i<(n);i++)
#define ARREP(i,n,X) for(int i=0;i<(n);i++)cin>>X[i]
#define FOR(i,X,n) for(int i=(X);i<(n);i++)
#define EREP(i,n) for(int i=1;i<=n;i++)
#define BitFOR(N) REP(Bit,1<<(N))
 
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define DEB2(X) cout<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define TFDEB(f) (f)? cout<<"true ":cout<<"false ";
#define FORDEB(n,X) for(int i=0;i<(n);i++)ARDEB(i,X)
#define END cout<<endl;
#else
#define DEB(X) {}
#define DEB2(X) {}
#define ARDEB(i,X) {}
#define TFDEB(f) {}
#define FORDEB(n,X) {}
#define END {}
#endif
 
typedef long long int ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
#define ALL(X) X.begin(),X.end()
struct edge{int to,cost;};
//struct edge{int from,cost,to;};
struct P2{int x,y;};
#define BIT(Bit,n) bitset<n>(Bit)
#define Endl endl
#define YN(f) cout<<((f)?"Yes":"No")<<endl
 
const int MOD7=1000000007;
const int INF=100000000;
const int SET=1000; 
 
#define MV 210
int N,M,A,B,D[MV],Table[MV];
vector<int> G[MV];

int main(){
	int n,m,ans=0;
	cin>>n>>m;
	for(int i=0;i<=n;i++){
		for(int j=0;j<=n;j++){
			int dim=m-i-j;
			if(dim<0||dim>n)continue;
			if(i+j+dim==m){
				ans++;
			}
			DEB(i)DEB(j)DEB(dim)END
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
// Educational DP Contest-N
#include <bits/stdc++.h>
#define endl "\n"
#define rep(i,n) for(int i=0;i<int(n);i++)
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> ipair;
typedef pair<ll,ll> lpair;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v) //vectorの中身を見る
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

vector<ll> a(410);
vector<ll> rui(410,0);
ll max_=pow(10,18);
vector<vector<ll>> dp(410,vector<ll>(410,max_));
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(12);

    int n;
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        rui[i]=rui[i-1]+a[i];
        //cout<<rui[i]<<endl;
    }
    for(int i=1;i<=n;i++) dp[i][i]=0;
    for(int L=2;L<=n;L++){
        for(int i=1;i<=n-1;i++){
            int j=i+L-1;
            if(n<j) break;
            for(int k=i;k<=j-1;k++){
                dp[i][j]=min(dp[i][j],dp[i][k]+dp[k+1][j]+(rui[k]-rui[i-1])+(rui[j]-rui[k]));
                //cout<<dp[i][j]<<endl;
            }
        }
    }
    cout<<dp[1][n]<<endl;
    return 0;
}

Measured memory_bytes: 1664
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <unordered_map>
constexpr int MOD = 1000000000 + 7;
constexpr int INF = 2000000000;
using namespace std;
typedef long long LL;

string s;
LL ans = 0;

LL solve(LL i, LL num, LL count) {
	if (i == s.size() - 1) {
		return count + num + (LL)(s[i]) - (LL)'0'; 
	}
	LL ret = 0;
	num += (LL)s[i] - (LL)'0';
	ret += solve(i + 1, num * 10, count);
	ret += solve(i + 1, 0, count + num);
	return ret;
}

int main() {
	cin >> s;
	cout << solve(0, 0, 0) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;++i)
#define ll long long
#define M 1000000007
#define vc vector
#define vci vector<ll>
#define si set<ll>
#define pb push_back
#define pop pop_back
#define fs first
#define sc second
#define endl "\n"
#define mii map<ll,ll>
#define pii pair<ll,ll>
#define msi map<string,ll>
#define PI 3.14159265
#define r0 return 0
using namespace std;

void ah_shit_here_we_go_again()
{
    ll n,k;
    cin>>n>>k;
    ll h[n];
    rep(i,0,n)
    {
        cin>>h[i];
    }
    ll dp[n+1];
    rep(i,0,n+1)
    {
        dp[i]=0;
    }
    ll x,y;
    rep(i,2,n+1)
    {
        x=1e18;
        rep(j,1,k+1)
        {
            if(j>=i)
                break;
            y=dp[i-j]+abs(h[i-j-1]-h[i-1]);
            if(x>y)
                x=y;
        }
        dp[i]=x;
    }
    cout<<dp[n];
}

int main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(0); 
    cout.tie(0);
    ll t;
    t=1;
    //cin>>t;
    rep(i1,0,t)
    {
        ah_shit_here_we_go_again();
    }
    return 0;

}

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

int main() {
   int N;
   cin >> N;
   vector<ll> L(N);
   ll ans = 0;
   for(int i = 0; i < N; i++) cin >> L[i];
   for(int i = 0; i < N; i++) {
      for(int j = 0; j < N; j++) {
         for(int k = 0; k < N; k++) {
            if(L[i] != L[k] && L[k] != L[j] && L[j] != L[i]) {
               if(i != j && j != k && k != i && L[i] + L[k] > L[j] && L[j] + L[k] > L[i] && L[i] + L[j] > L[k] && L[i] < L[j] && L[j] < L[k]) {
                  ans++;
               } 
            }
         }
      }
   }

   cout << ans;
   return 0;
}

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

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

    int A, B, C, D;
    cin >> A >> B >> C >> D;

    if(A + B > C + D) {
        cout << "Left" << endl;
    } else if(A + B < C + D) {
        cout << "Right" << endl;
    } else {
        cout << "Balanced" << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fr first
#define sc second
#define pb push_back
#define maxheap priority_queue<int>
#define minheap priority_queue<int, vector<int>, greater<int> >
#define ll long long
const int INF = 1e8;
const int MAXN = 3e5 + 200;
const  long double eps = 1e-16;
const long double pi = acos(-1.0);
using namespace std;

int dx[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy[] = {1, -1, 0, 1, -1, 0, 1, -1};
int MOD = 1e9 + 7;
int n;
int x, y, z;
int dp[42][(1 << 17) + 2];
void add(int &x, int y){
    if (x + y >= MOD) x = x + y - MOD;
    else
        x = x + y;
}
void sub(int &x, int y){
    if (x - y <= 0) x = x - y + MOD;
    else
        x = x - y;
}
int ans = 1;
void solve(){
    cin >> n >> x >> y >> z;
    int need = (1 << (z - 1)) | (1 << (y + z - 1)) |(1 << (y + z+ x - 1));

    int ful = (1 << (x + y + z)) - 1;
    dp[0][0] = 1;

    for (int i = 1; i <= n; i++){
       // cout << i << endl;
        ans = ans * 10LL % MOD;
        for (int j = 0; j <= ful; j++){

                if (!dp[i - 1][j]) continue;
                for (int dig = 1; dig <= 10; dig++){
                    int new_ch = (j << dig) | (1 << (dig - 1));
                    new_ch &= ful;
                    if ( (new_ch  & need) == need) continue;
                    //if (i == 3) cout << new_ch << endl;
                     add(dp[i][new_ch], dp[i - 1][j]);
                }
        }
        //cout << i << endl;
    }

    for (int i = 0; i <= ful; i++){
        sub(ans, dp[n][i]);
    }
    cout << ans << endl;

}

int main(){
    ios::sync_with_stdio(NULL), cin.tie(0), cout.tie(0);
    cout.setf(ios::fixed), cout.precision(7);
    //freopen("inevit.in", "r", stdin);
    //freopen("inevit.out", "w", stdout);
    int step;
    step = 1;
    //cin >> step;
    for (int i = 1; i <= step; i++)
        solve();

}

Measured memory_bytes: 19328
#include <iostream>
#include <string>

using namespace std;

int main(void){
    string s,p,o,tmp;
    int q,a,b;
    cin>>s>>q;
    
    int i,j;
    
    for(i=0;i<q;i++){
        cin>>o>>a>>b;
        if(o=="replace"){
            cin>>p;
            s.replace(a,b-a+1,p);
        }
        else if(o=="reverse"){
            tmp=s.substr(a,b-a+1);
            for(j=0;j<b-a+1;j++){
                s[a+j]=tmp[b-a-j];
            }
        }
        else if(o=="print"){
            tmp=s.substr(a,b-a+1);
            cout<<tmp<<endl;
        }
    }
    return 0;
}


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

#ifndef ONLINE_JUDGE
#define debarr(a,x,y)cerr<<#a<<":";for(int i=x;i<=y;i++)cerr<<a[i]<<" ";cerr<<endl;
#define debmat(mat,row,col)cerr<<#mat<<":\n";for(int i=0;i<row;i++){for(int j=0;j<col;j++)cerr<<mat[i][j]<<" ";cerr<<endl;}
#define deb(...)dbs(#__VA_ARGS__,__VA_ARGS__)
template<class S, class T>ostream &operator<<(ostream &os, const pair<S, T> &p) {return os << "(" << p.first << "," << p.second << ")";}
template<class T>ostream &operator<<(ostream &os, const vector<T> &p) {os << "["; for (auto&it : p)os << it << " "; return os << "]";}
template<class T>ostream &operator<<(ostream &os, const set<T>&p) {os << "["; for (auto&it : p)os << it << " "; return os << "]";}
template<class T>ostream &operator<<(ostream &os, const multiset<T>&p) {os << "["; for (auto&it : p)os << it << " "; return os << "]";}
template<class S, class T>ostream &operator<<(ostream &os, const map<S, T>&p) {os << "["; for (auto&it : p)os << it << " "; return os << "]";}
template<class T>void dbs(string str, T t) {cerr << str << ":" << t << "\n";}
template<class T, class...S>void dbs(string str, T t, S... s) {int idx = str.find(','); cerr << str.substr(0, idx) << ":" << t << ","; dbs(str.substr(idx + 1), s...);}
#else
#define deb(...){}
#define debarr(a,x,y){}
#define debmat(mat,row,col){}
#endif
#define pr(x) {cout << x << "\n"; return;}
template<class T> bool umin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool umax(T &a, T b) { return a < b ? (a = b, true) : false; }

#define int              long long
#define ld               long double
#define fi               first
#define se               second
#define mp               make_pair
#define pb               push_back
#define rep(i,n)         for(int i=0;i<n;i++)
#define re(i,n)          for(int i=1;i<=n;i++)
#define fr(i,a,b)        for(int i=a;i<=b;i++)
#define fb(i,a,b)        for(int i=a;i>=b;i--)
#define sz(x)            (int)x.size()
#define all(x)           x.begin(),x.end()
#define ini(x,y)         memset(x,y,sizeof(x))
typedef vector<int>      vi;
typedef pair<int, int>   pii;
typedef vector<pii>      vii;
typedef map<int, int>    mii;
typedef set<int>         si;
const int N = 2e5 + 10;
int n, sz[N];

void solve(int tc)
{
	int a, b, c, d; cin >> a >> b >> c >> d;
	int ans = max(a * c, max(a * d, max(b * c, b * d)));
	if (a <= 0 && b >= 0 && c <= 0 && d >= 0) umax(ans, 0LL);
	cout << ans << endl;

}

signed main() {
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int t = 1;
	//cin >> t;
	for (int i = 1; i <= t; i++) solve(i);
	return 0;
}

Measured memory_bytes: 3644
// Problem : A - A?C
// Contest : AtCoder - AtCoder Beginner Contest 166
// URL : https://atcoder.jp/contests/abc166/tasks/abc166_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
ordered_set;	

#define FOR(i,a,b) for(int i = (a); i <= (b); ++i)
#define FORD(i,a,b) for(int i = (a); i >= (b); --i)
#define RI(i,n) FOR(i,1,(n))
#define REP(i,n) FOR(i,0,(n)-1)
#define mini(a,b) a=min(a,b)
#define maxi(a,b) a=max(a,b)
#define pb push_back
#define st first
#define nd second
#define sz(w) (int) w.size()
typedef vector<int> vi;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<pii, int> para;
const ll inf = 1e18 + 7;
const ll maxN = 1e6 + 5;
const ll MOD = 1e9 + 7;

// sprawdz MODULO!
int main() {
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	string s;
	cin >> s;
	if (s == "ARC") cout << "ABC";
	else cout << "ARC";
	return 0;
}
 


Measured memory_bytes: 3652
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(10)

using namespace std;

int mod = 1e9 + 7;
int dp[105][300005];

void add(int& a, int b) {
    a += b;
    if (a >= mod)
        a -= mod;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    int N, K;
    cin >> N >> K;

    vector<int> a(N);
    REP(i, N) cin >> a[i];

    dp[0][0] = 1;
    REP(i, N) {
        vector<int> sum(K + 2, 0);
        FOR(k, 0, K) {
            sum[k + 1] = (sum[k] + dp[i][k]) % mod;
        }
        FOR(k, 0, K) {
            int to = k + 1;
            int from = max(k - a[i], 0LL);
            int diff = sum[to] - sum[from];
            if (diff < 0) diff += mod;
            add(dp[i + 1][k], diff);
        }
    }

    cout << dp[N][K] << endl;

    return 0;
}


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

int main(){
    int n, ans = 0;
    cin >> n;
    int *a = new int [n];
    bool *used = new bool [n];
    fill(used, used + n, 0);
    for (int i = 0; i < n; i++)
        cin >> a[i];
    for (int i = 0; i < n - 1; i++){
        if(a[i] > a[i + 1]){
            if(!used[i]){
                used[i] = 1;
                a[i]--;
                i = max(i - 2, 0);
            }
            else{
                puts("No");
                return 0;
            }
        }
    }
    puts("Yes");
    return 0;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
// Welcome to my source code!

int main() {
    string s;
    cin >> s;
    int n = s.size();
    for (int i = 1; i <= n; i++) {
        if (i % 2) cout << s[i-1];
    }
    cout << endl;
}

Measured memory_bytes: 512
map${-$`}{-$&}=${-$&}{-$`}=$'*<>=~/ .* /,2..<>;@s=<>!~$"-$';map$$_//=$u+$u{$s[@s]=$_},keys%{*u=$_}for@s;//,print${-$`}+${-$'},$/for<>

Measured memory_bytes: 93440
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
//INSERT ABOVE HERE
signed main(){
  Int T;
  cin>>T;
  while(T--){
    Int a,b,c,d;
    cin>>a>>b>>c>>d;
    c--;
    d=d-c;
    if(!a){
      cout<<string('B',d)<<endl;
      continue;
    }
    if(!b){
      cout<<string('A',d)<<endl;
      continue;
    }
    const Int DBG = 0;
    Int x;
    {
      auto check=
	[&](Int x){
	  Int p=(a+x-1)/x,q=(b+x-1)/x;
	  return q<=a+1&&p<=b+1;
	};
      
      Int l=0,r=a+b;
      while(l+1<r){
	Int m=(l+r)>>1;
	if(check(m)) r=m;
	else l=m;
      }
      x=r;
    }
    if(DBG) cout<<x<<endl;
    string pre,suc;
    {
      Int p=(a+x-1)/x,q=(b+x-1)/x;
      //if(DBG) cout<<a<<" "<<b<<":"<<p<<" "<<q<<endl;
      if(q==a+1){
	assert(p!=b+1);
	Int len=(b%x?b%x:x);
	// [0,len) + [len, a+b)
	if(c+d<=len){
	  cout<<string(d,'B')<<endl;
	  continue;
	}
	if(c<len){
	  Int l=len-c;
	  pre=string(l,'B');
	  c=0;
	  d-=l;
	}else c-=len;
	b-=len;
      }else if(p==b+1){
	Int len=a+b-(a%x?a%x:x);
	// [0,len) + [len, a+b)
	if(len<=c){
	  cout<<string(d,'A')<<endl;
	  continue;
	}
	if(len<c+d){
	  Int l=c+d-len;
	  suc=string(l,'A');
	  d-=l;
	}
	a-=(a+b)-len;
      }
    }
    if(DBG){
      cout<<pre<<":"<<suc<<endl;
      cout<<a<<" "<<b<<" "<<c<<" "<<d<<endl;
    }
    {
      auto check=
	[&](Int y)->Int{
	  Int na=a-x*y;
	  Int nb=b-1*y;
	  if(na<0||nb<0) return 0;
	  Int p=(na+x-1)/x,q=(nb+x-1)/x;
	  return q<=na&&p<=nb;
	};
      Int l=0,r=a+b;
      while(l+1<r){
	Int m=(l+r)>>1;
	if(check(m)) l=m;
	else r=m;
      }
      Int len=(x+1)*l;
      // [0,len) + [len, a+b)
      // (pos % X+1) == X => S[pos] == B
      if(DBG) cout<<c<<"::"<<c+d<<":::"<<len<<"%"<<(x+1)<<endl;
      if(c<len){
	Int l=min(c+d,len)-c;
	for(Int i=c;i<c+l;i++) pre+=(i%(x+1)!=x?'A':'B');
	c=0;
	d-=l;
      }else c-=len;
      a-=x*l;
      b-=1*l;
    }
    if(DBG){
      cout<<pre<<":"<<suc<<endl;
      cout<<a<<" "<<b<<" "<<c<<" "<<d<<endl;
    }
    {
      auto check=
	[&](Int y)->Int{
	  Int na=a-1*y;
	  Int nb=b-x*y;
	  if(na<0||nb<0) return 0;
	  Int p=(na+x-1)/x,q=(nb+x-1)/x;
	  return q<=na&&p<=nb;
	};
      Int l=0,r=a+b;
      while(l+1<r){
	Int m=(l+r)>>1;
	if(check(m)) l=m;
	else r=m;
      }
      Int len=a+b-(x+1)*l;
      // [0,len) + [len, a+b)
      // ((pos-len) % X+1) == X => S[pos] == B
      if(DBG) cout<<len<<endl;
      if(len<c+d){
	Int l=c+d-max(c,len);
	string tmp;
	for(Int i=max(c,len);i<c+d;i++) tmp+=((i-len)%(x+1)==0?'A':'B');
	suc=tmp+suc;
	d-=l;
      }
      a-=1*l;
      b-=x*l;
    }
    if(DBG){
      cout<<pre<<":"<<suc<<endl;
      cout<<a<<" "<<b<<" "<<c<<" "<<d<<endl;
    }
    {
      Int len=a;
      if(c<len){
	Int l=min(c+d,len)-c;
	for(Int i=c;i<c+l;i++) pre+='A';
	c=0;
	d-=l;
      }
    }
    {
      suc=string(d,'B')+suc;
      d=0;
    }
    if(DBG) cout<<pre<<":"<<suc<<endl;
    cout<<pre+suc<<endl;
  }
  return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<iomanip>
#include<map>
#include<utility>
#include<string>

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; }

using namespace std;

#define min_3(a, b, c) min(a, min(b, c))
#define max_3(a, b, c) max(a, max(b, c))
typedef long long ll;

int main()
{
    int a, b;
    cin >> a  >> b;
    cout << max_3(a+b, a-b, a*b) << endl;
    return 0;
}


Measured memory_bytes: 256
{-# LANGUAGE BangPatterns #-}

main :: IO ()
main = do
  [a, b] <- map read . words <$> getLine
  print $ solve a b

solve :: Int -> Int -> Int
solve a b = go 0 1
  where
    go !acc o
      | o >= b    = acc
      | otherwise = go (acc + 1) (o + a - 1)


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

long long GCD(long long a, long long b) {
  if (b == 0) return a;
  else return GCD(b, a % b);
}

int main() {
  int k; cin >> k;
  int res=0;
  for (int i=1; i<=k; ++i){
    for (int j=1; j<=k; ++j){
      for (int l=1; l<=k; ++l){
        res=res+GCD(i,GCD(j,l));
      }
    }
  }
  cout << res << endl;
}

Measured memory_bytes: 3636
use proconio::{fastout, input};
use std::cmp;
#[fastout]
fn main() {
    input! {
        n:usize,x:usize,mut a:[usize;n],
    }
    let mut ans:usize=0;
    for i in 0..n-1{
        let _tmp:usize=a[i]+a[i+1];
        if a[i]+a[i+1]>x{
            a[i+1]-=cmp::min(a[i]+a[i+1]-x,a[i+1]);
            if a[i+1]==0{
                a[i]-=x-a[i+1];
            }
            ans+=_tmp-x;
        }
    }
    println!("{}",ans);
}

Measured memory_bytes: 3780
#include <iostream>

int main(){
    bool flag = true;
    int a, b;
    std::string s;
    std::cin >> a >> b >> s;
    for(int i = 0; i < s.length(); i++){
        if(i == a){
            flag &= (s[i] == '-');
        }
        else{
            int t = s[i]-'0';
            flag &= (0 <= t && t <= 9);
        }

    }
    if(flag){
        std::cout << "Yes" << std::endl;
    }
    else{
        std::cout << "No" << std::endl;
    }
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;
typedef long long ll;
const ll MOD=1000000007;

ll n,m,x[100010]={0},y[100010]={0};
ll sx=0,sy=0;

signed main(){
    cin>>n>>m;
    for(int i=0;i<m+n;++i){
        if(i<n){
            cin>>x[i];
        }
        else cin>>y[i-n];
    }

    n--,m--;
    for(ll i=0;i<n;++i){
        sx+=((i+1LL)*(n-i)%MOD)*(x[i+1]-x[i]);
        if(sx>MOD)sx%=MOD;
    }
    for(ll i=0;i<m;++i){
        sy+=((i+1LL)*(m-i)%MOD)*(y[i+1]-y[i]);
        if(sy>MOD)sy%=MOD;
    }

    cout<<(sx*sy)%MOD<<endl;

    return 0;
}

Measured memory_bytes: 1792
def main():
    A = list(input())
    cnt = 0
    nums_right = []
    nums_left = []
    current_right = 0
    current_left = 0
    for a in A:
        nums_right.append(current_right)
        if a == "<":
            current_right += 1
        else:
            current_right = 0
    else:
        nums_right.append(current_right)

    for a_ in A[::-1]:
        nums_left.append(current_left)
        if a_ == ">":
            current_left += 1
        else:
            current_left = 0
    else:
        nums_left.append(current_left)

    nums_left = nums_left[::-1]

    for nr, nl in zip(nums_right, nums_left):
        cnt += max(nr, nl)
    print(cnt)


if __name__ == '__main__':
    main()

Measured memory_bytes: 41020
s = input()
l = int(input())
char = []
if len(s) == 1:
    print(s)
else:
    for i in range(len(s)):
        char.append(s[i])
    charset = sorted(list(set(char)))
    ans = []
    for i in charset:
        if len(set(ans)) > 5:
            break
        for j in range(len(s)):
            if i == s[j]:
                for k in range(1, l+1):
                    ans.append(s[j:j+k])
    ansset = sorted(list(set(ans)))
    print(ansset[l-1])

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

ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

int main(){
    ll N, K;
    cin >> N >> K;

    ll ans, r = N - K, num;
    for(ll i=1;i<=K;i++){
        //cout << i << endl;
        ans = 1;
        // nCrの計算(1)
        num = r+1;
        for(ll j=1;j<=i;j++){
            ans = ans*num%MOD;
            num--;
        }
        for(ll j=1;j<=i;j++){
            ans = ans*modinv(j, MOD);
            ans %= MOD;
        }
        //cout << ans << endl;
        
        // (K-1)!/(K-i)!(i-1)!
        for(ll j=1;j<=K-1;j++){
            ans = ans*j%MOD;
            ans %= MOD;
        }
        for(ll j=1;j<=K-i;j++){
            ans = ans*modinv(j, MOD);
            ans %= MOD;
        }
        for(ll j=1;j<=i-1;j++){
            ans = ans*modinv(j, MOD);
            ans %= MOD;
        }

        cout << ans << endl;
    }


}

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

int main() {
    int k, x;
    cin >> k >> x;
    if(500*k >= x) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
const ll INF=1001001001;
const ll LINF=1001001001001001001;
const ll D4[]={0,1,0,-1,0};
const ll D8[]={0,1,1,0,-1,-1,1,-1,0};
#define _overload3(_1,_2,_3,name,...) name
#define _rep2(i,n) for(ll i=0;i<(n);++i)
#define _rep3(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,_rep3,_rep2)(__VA_ARGS__)
#define _repe2(i,n) for(ll i=0;i<=(n);++i)
#define _repe3(i,a,b) for(ll i=(a);i<=(b);++i)
#define repe(...) _overload3(__VA_ARGS__,_repe3,_repe2)(__VA_ARGS__)
#define _rrep2(i,n) for(ll i=(n)-1;i>=0;i--)
#define _rrep3(i,a,b) for(ll i=(b)-1;i>=(a);i--)
#define rrep(...) _overload3(__VA_ARGS__,_rrep3,_rrep2)(__VA_ARGS__)
#define all(x) (x).begin(),(x).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(b<a){a=b;return 1;}return 0;}
template<class T>
using pq=priority_queue<T,vector<T>,greater<T>>;

string s;
ll K;

void solve();

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cin >> s;
    cin >> K;
    solve();
}

// 1 ≤ |s| ≤ 5000
// s は英小文字からなる
// 1 ≤ K ≤ 5
// s は異なる substring を K 個以上持つ

// string s, ll K
// 辞書順で K 番目に小さい s の substring を出力せよ。
void solve(){
    ll n=s.size();
    set<string> st;
    rep(i,n)repe(j,1,n-i){
        if(j>5)break;
        st.insert(s.substr(i,j));
    }

    ll id=1;
    for(string ss:st){
        if(id==K){
            cout<<ss<<endl;
            return;
        }
        ++id;
    }
}


Measured memory_bytes: 1664
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <cassert>
#include <memory>
#include <stack>
#include <set>
#include <map>
#include <cctype>

#define MAX_SIZE 100000000
typedef long long ll;
typedef unsigned long long ull;
using namespace std;

int solve(const string& left, const string& right) {
  vector<bool> left_include(26,false);
  vector<bool> right_include(26,false);
  for(auto l : left) {
    left_include[l - 'a'] = true;
  }
  for(auto r : right) {
    right_include[r - 'a'] = true;
  }
  int cnt = 0;
  for(int i = 0; i < 26; i++) {
    if(left_include[i] && right_include[i]) {
      cnt++;
    }
  }
  return cnt;
}

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

  string S; int N; cin>>N>>S;

  int max_cnt = 0;
  for(int i = 0; i < N - 1; i++) {
    string left = S.substr(0, i+1);
    string right = S.substr(i+1);
    max_cnt = max(max_cnt, solve(left,right));
  }

  cout << max_cnt << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <vector>

// lib/util.hpp
#ifndef UTIL_HPP
#define UTIL_HPP


typedef std::int_fast64_t i64;
typedef std::uint_fast64_t u64;
typedef std::int_fast32_t i32;
typedef std::uint_fast32_t u32;

namespace tools {
  template <typename T>
  void read(std::vector<T>& vector, const typename std::vector<T>::size_type size) {
    vector.reserve(size);
    std::copy_n(std::istream_iterator<T>(std::cin), size, std::back_inserter(vector));
  }

  template <typename T, std::size_t N>
  void read(std::array<T, N>& array) {
    std::copy_n(std::istream_iterator<T>(std::cin), N, array.begin());
  }
}

#endif

// main.cpp

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

  i64 answer = 0;
  i64 combo = 0;
  for (const char& c : S) {
    if (c == 'A' || c == 'C' || c == 'G' || c == 'T') {
      ++combo;
    } else {
      answer = std::max(answer, combo);
      combo = 0;
    }
  }
  answer = std::max(answer, combo);

  std::cout << answer << std::endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
int main(){
  int n;cin>>n;
  int i,j,k;
  vector<int> v;
  for(i=0;i<n;i++){
    cin >> k;
    v.push_back(k);
  }
  for(j=0;j<n;j++) cout << v[j] << (j==n-1?'\n':' ');
  for(i=1;i<n;i++){
    for(j=0;j<i;j++){
      if(v[j]>v[i]){
	k=v[i];
	v.erase(v.begin()+i);
	v.insert(v.begin()+j,k);
	break;
      }
    }
    for(j=0;j<n;j++) cout << v[j] << (j==n-1?'\n':' ');
  }
  return 0;
}


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

int main(){
	int a, b, c;
	cin >> a >> b >> c;
	int f = 0;
	if(a+b == c) f = 1;
	if(b+c == a) f = 1;
	if(c+a == b) f = 1;
	if(f == 1){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"math"
	"strings"
)

func powerset2(nums []int) [][]int {
	length := int(math.Pow(2, float64(len(nums))))
	result := make([][]int, length)

	index := 0
	result[index] = []int{}
	index++

	for _, n := range nums {
		max := index
		for i := 0; i < max; i++ {
			result[index] = copyAndAppend(result[i], n)
			index++
		}
	}

	return result
}

func copyAndAppend(nums []int, n int) []int {
	dst := make([]int, len(nums)+1)
	copy(dst, nums)
	dst[len(nums)] = n
	return dst
}

func contains(s []int, e int) bool {
	for _, v := range s {
		if e == v {
			return true
		}
	}
	return false
}

func main() {
	var h, w, k int
	fmt.Scanf("%d", &h)
	fmt.Scanf("%d", &w)
	fmt.Scanf("%d", &k)

	lines := make([]string, h)
	for i := 0; i < h; i++ {
		fmt.Scanf("%s", &lines[i])
	}

	sheet := make([][]string, h)
	for i := 0; i < h; i++ {
		sheet[i] = strings.Split(lines[i], "")
	}
	hlist := make([]int, h)
	for i := 0; i < h; i++ {
		hlist[i] = i
	}
	wlist := make([]int, w)
	for i := 0; i < w; i++ {
		wlist[i] = i
	}

	hset := powerset2(hlist)
	wset := powerset2(wlist)

	var ans int
	for i := 0; i < len(hset); i++ {
		for j := 0; j < len(wset); j++ {
			var total int

			for n := 0; n < h; n++ {
				for m := 0; m < w; m++ {
					if sheet[n][m] == "#" {
						if !contains(hset[i], n) && !contains(wset[j], m) {
							total++
						}
					}
				}
			}

			if total == k {
				ans++
			}
		}
	}

	fmt.Println(ans)
}

Measured memory_bytes: 1844
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main(){
    int h, n;
    cin >> h >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i ++) { cin >> a[i]; }

    int sum = accumulate(a.begin(), a.end(), 0);
    if (sum >= h) { cout << "Yes" << '\n'; }
    else cout << "No" << '\n';
}


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

void sub(int n) {
    for(int i = 9; i > 0; i--) {
        if(n / i <= 9 && n % i == 0) {
            cout << "Yes" << endl;
            return;
        }
    }
    cout << "No" << endl;
    return;
}

int main() {
    int n;
    cin >> n;
    sub(n);
    return 0;
}

Measured memory_bytes: 256
/* BABA JAGAAAAAA  */  

#include<bits/stdc++.h>
#define pb push_back
#define un unordered_map
#define us unordered_set
#define ll long long
#define PI 3.1415926535897932384626
#define fast ios:: sync_with_stdio(false);cin.tie(NULL)
#define l long 
using namespace std;
const int  mod= 1e9+7;
const int inf=1e9+3;
 int main()
 {
     fast;  
    int n;
    cin>>n;
     cout<<(1-n)<<endl;
       return 0;
     
 }
  

Measured memory_bytes: 3584
#include <iostream>
#include <cmath>

using namespace std;

long long n,a,b;


int main(){
	cin >> n >> a >> b;
	if (abs(b - a) % 2 == 0){ 
		cout << min(abs(b - a)/2,n);
	}else{
		cout << min(min(a - 1,n - b) + 1 + abs(b - a) / 2,n);
	}
	//system("PAUSE");
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Globalization;
using System.Diagnostics;



class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().calc();
        return 0;
    }

    Scanner cin;
    
    void calc()
    {
        cin = new Scanner();
        int N = cin.nextInt();
        int[] x = new int[N];
        int[] y = new int[N];
        for (int i = 0; i < N; i++)
        {
            x[i] = cin.nextInt();
            y[i] = cin.nextInt();
        }

        long ans = 0;
        long mod = 998244353;

        int MAX2 = 300;
        long[] pow2 = new long[MAX2];
        pow2[0] = 0;
        pow2[1] = 1;
        for (int i = 2; i < MAX2; i++)
        {
            pow2[i] = (pow2[i - 1] * 2 + 1) % mod;
        }

        for (int i = 0; i < N; i++)
        {
            for (int j = i + 1; j < N; j++)
            {
                long cnt = 0;
                long cnt2 = 0;
                for (int k = j + 1; k < N; k++)
                {
                    cnt++;
                    if (calcT(x[i] - x[k], y[i] - y[k], x[j] - x[k], y[j] - y[k]) == 0)
                    {
                        cnt2++;
                    }
                }

                ans += pow2[cnt];
                ans -= pow2[cnt2];
                ans %= mod;
                ans += mod;
                ans %= mod;
            }
        }
        Console.WriteLine(ans);
    }

    long calcT(long ax, long ay, long bx, long by)
    {
        return (ax * by) - (bx * ay);
    }

        
}


class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}
 

Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
//#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
typedef pair<int,int> Pi;
typedef long long int ll;
const int INF=(ll)(1LL<<31)-1;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a, b)*b;}
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int n;
int u[100100],v[100100],w[100100];
int rb[100100];
vector<pair<int,int> > vv[100100];
queue<int> q;

int main(){
	cin>>n;
	REP(i,n-1){
		cin>>u[i]>>v[i]>>w[i];
		u[i]--,v[i]--,w[i];
		vv[u[i]].push_back(pair<int,int>(v[i],w[i]));
		vv[v[i]].push_back(pair<int,int>(u[i],w[i]));
	}
	
	for(int i=0;i<n;i++){
		rb[i]=-1;
	}
	
	q.push(0);
	rb[0]=0;
	while(q.size()){
		int tt=q.front();q.pop();
		for(int i=0;i<vv[tt].size();i++){
			pair<int,int> pp=vv[tt][i];
			if(rb[pp.first]!=-1)continue;
			if((rb[tt]+pp.second)%2==0){
				rb[pp.first]=0;
			}else{
				rb[pp.first]=1;
			}
			q.push(pp.first);
		}
	}
	
	for(int i=0;i<n;i++)
		cout<<rb[i]<<endl;
	return 0;
}
	

Measured memory_bytes: 7936
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
//C++11
#if __cplusplus == 201103L
#include <tuple>
#endif

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cout<<*i<<" "; cout<<endl; }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int tominute(int h, int d){
  return h * 60 + d;
}

int main(){
  int N;
  while(cin>>N && N){
    int sum[1000] = {};
    bool in[1000] = {};
    int time[1000];
    REP(i, N){
      int m, d, hh, mm, id;
      char c;
      scanf("%d/%d %d:%d %c %d", &m, &d, &hh, &mm, &c, &id);
      if(c == 'I'){
        in[id] = true;
        if(id == 0){
          REP(i, 1000)if(in[i]) time[i] = tominute(hh, mm);
        }else if(in[0]){
          time[id] = tominute(hh, mm);
        }
      }else{
        in[id] = false;
        if(id == 0){
          REP(i, 1000)if(in[i]) sum[i] += tominute(hh, mm) - time[i];
        }else if(in[0]){
          sum[id] += tominute(hh, mm) - time[id];
        }
      }
    }
    cout<< *max_element(sum + 1, sum + 1000) << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <stdio.h>
#include <algorithm>
using namespace std;

typedef long long ll;
ll n, cnt[100100], p = 998244353;
int main(void) {
	scanf("%lld", &n);
	ll x; scanf("%lld", &x);
	if (x != 0) return !printf("0\n");
	cnt[0] = 1;
	for (ll i = 1; i < n; i++) {
		scanf("%lld", &x);
		cnt[x]++;
	}
	
	ll ans = 1;
	if (cnt[0] != 1) return !printf("0\n");
	while (cnt[n] == 0) n--;

	for (ll i = 0; i < n; i++) {
		for (ll j = 0; j < cnt[i + 1]; j++) {
			ans *= cnt[i];
			ans %= p;
		}
	}
	
	printf("%lld\n", ans);
}

Measured memory_bytes: 896
import numpy as np


def main():
    n = 13
    mod = 1000000007
    r = 5
    in_str = input()

    amari_l = amari_list(n)
    amari_m = amari_matrix(n, amari_l)

    ans_list = initial(in_str[-1:], n)

    for i, s in enumerate(reversed(in_str)):
        if i == 0:
            continue
        if s == "?":
            ans_list = np.dot(ans_list, amari_m[i % len(amari_m)]) % mod
        else:
            t = int(s) * amari_l[i % len(amari_l)] % n
            ans_list = np.roll(ans_list, t)

    print(int(ans_list[r] % mod))


def initial(s, n):
    if s == "?":
        return np.array([1 if i < 10 else 0 for i in range(n)], dtype='int64')
    else:
        return np.array([1 if i == int(s) else 0 for i in range(n)], dtype='int64')


def shift(n, r):
    return np.array([[1 if (i - j + r) % n == 0 else 0 for j in range(n)] for i in range(n)])


def amari_list(n):
    ret = []
    for i in range(n + 1):
        r = 10**i % n
        if r in ret:
            return ret
        else:
            ret.append(r)


def amari_matrix(n, amari_list):
    ret = np.zeros((len(amari_list), n, n))
    for i, j in enumerate(amari_list):
        tmp = np.zeros((n, n))
        for k in range(10):
            tmp += shift(n, j * k % n)
        ret[i] = tmp
    return ret


if __name__ == '__main__':
    main()


Measured memory_bytes: 16480
#include <iostream>
#include <map>
#include <algorithm>
using namespace std;

int main(){    
    int N;
    cin >> N;
    int d[N];
    
    for (int i=0;i<N;i++){
        cin >> d[i];
    }
    sort(d,d+N);

    cout << d[N/2] - d[N/2-1] << endl;

    return 0;
}

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

using namespace std;

#define FOR(i,a,b) for(int i = (a); i <= (b); ++i)
#define FORD(i,a,b) for(int i = (a); i >= (b); --i)
#define RI(i,n) FOR(i,1,(n))
#define REP(i,n) FOR(i,0,(n)-1)
#define mini(a,b) a=min(a,b)
#define maxi(a,b) a=max(a,b)
#define mp make_pair
#define pb push_back
#define st first
#define nd second
#define sz(w) (int) w.size()
typedef vector<int> vi;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<pii, int> para;
const int inf = 1e9 + 7;
const int maxN = 1e6 + 7;
const ll mod = 1e18 + 7;

int n, k, arr[maxN];
vector<pii> notSwap[maxN], swapped[maxN];
ll ansNot[maxN], ans[maxN];
ll sumNot, sum;
multiset<pii> all, all2;

int main()
{
	ios_base::sync_with_stdio(0);
	cin>>n>>k;
	int cntNot = 0, cnt = 0;
	REP(i, n) cin>>arr[i];
	REP(i, n - 1) {
		if (arr[i + 1] > arr[i]) {
			notSwap[arr[i] + 1].pb(pii(arr[i], arr[i + 1]));
			notSwap[arr[i + 1] + 1].pb(pii(-arr[i], -arr[i + 1]));
			sumNot += arr[i + 1] - arr[i];
			all.insert(pii(arr[i], arr[i + 1]));
			cntNot++;
		} else {
			swapped[arr[i] + 1].pb(pii(arr[i], arr[i + 1]));
			//swapped[k + 1].pb(pii(-arr[i], -arr[i + 1]));
			swapped[1].pb(pii(arr[i], arr[i + 1]));
			swapped[arr[i + 1] + 1].pb(pii(-arr[i], -arr[i + 1]));
			all2.insert(pii(arr[i], arr[i + 1]));
			cnt++;
			sum += (k - arr[i]) + arr[i + 1];
		}
	}
	//cout<<sumNot<<endl;
	RI(fav, k) {
		for (auto p : notSwap[fav]) {
			if (p.st > 0) {
				all.erase(p);
				sumNot -= (p.nd - p.st);
				sumNot += p.nd - fav + 2;
			} else {
				all.insert(pii(-p.st, -p.nd));
				sumNot += (-p.nd + p.st);
				sumNot --;
			}
		}
		sumNot -= (cntNot - all.size());
		ansNot[fav] = sumNot;
		//cout<<sumNot<<endl;
	}

	//cout<<"Bef "<<sum<<endl;
	RI(fav, k) {
		for (auto p : swapped[fav]) {
			//cout<<"Here "<<p.st<<" "<<p.nd<<endl;
			if (p.st > 0) {
				all2.erase(p);
				sum -= (k - p.st) + p.nd;
				//cout<<"ss "<<sum<<endl;
				//cout<<(fav <= p.nd) <<endl;
				if (fav <= p.nd) {
					//cout<<"fst"<<sum + (p.nd - fav) + 2<<endl;
					sum += p.nd - fav + 2;
				} else {
					sum += k + p.nd - fav + 2;
				}
			} else {
				all2.insert(pii(-p.st, -p.nd));
				//cout<<"befsnd"<<sum<<endl;
				sum += (k + p.st) - p.nd;
				sum -= -p.nd - fav + 2;
				//cout<<"snd"<<sum<<endl;
			}
		}
		//cout<<"Aft"<<sum<<endl;
		sum -= (cnt - all2.size());
		ans[fav] = sum;
		//cout<<sum<<" ";
	}
	ll minim = 1LL * inf * inf;
	//ll ind = -1;
	RI(fav, k) {
		if (ans[fav] + ansNot[fav] <= minim) {
			minim = ans[fav] + ansNot[fav];
			//ind = fav;
		}
	}
	cout<<minim;
	return 0;
}


Measured memory_bytes: 62452