akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		String S = sc.next();
		int Q = sc.nextInt();
		String[] front = new String[Q];
		String[] back = new String[Q];
	
		int F = 0,B = 0;
		int count = 0;
		for( int i=0; i<Q; i++ ){
			int a = sc.nextInt();
			if( a==1 ){
				count++;
			}
			if( a==2 ){
				int b = sc.nextInt();
				String ss = sc.next();
				if( b==1 ){
					if( count%2==0 ){
						front[F] = ss;
						F++;
					}else{
						back[B] = ss;
						B++;
					}
				}
				if( b==2 ){
					if( count%2==0 ){
						back[B] = ss;
						B++;
					}else{
						front[F] = ss;
						F++;
					}
				}
			}
		}
		if( count%2!=0 ){
			StringBuffer sb = new StringBuffer(S);
			String STR = sb.reverse().toString();
			for( int i=B-1; i>=0; i-- ){
				System.out.print(back[i]);
			}
			System.out.print(STR);
			for( int i=0; i<F; i++ ){
				System.out.print(front[i]);
			}
		}else{
			for( int i=F-1; i>=0; i-- ){
				System.out.print(front[i]);
			}
			System.out.print(S);
			for( int i=0; i<B; i++ ){
				System.out.print(back[i]);
			}
		}
	}
}


Measured memory_bytes: 166400
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
    int n;cin>>n;
    ll a[n][n];
    ll ans=0;
    rep(i,n)rep(j,n){
        cin>>a[i][j];
        ans+=a[i][j];
    }
    rep(i,n)rep(j,n){
        bool ok=true;
        rep(k,n){
            if(a[i][j]>a[i][k]+a[k][j]){
                cout<<-1<<endl;
                return 0;
            }
            if(a[i][j]==a[i][k]+a[k][j]){
                if(i!=k&&k!=j)ok=false;
            }
        }
        if(!ok)ans-=a[i][j];
    }
    cout<<ans/2<<endl;;
    return 0;
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
#include <iostream>
//#include <algorithm>
// #include <iomanip>
#define ll long long
#define map unordered_map
#define set unordered_set

using namespace std;

const ll MOD = 1000000007;

int main() {
  ll n;
  scanf("%lld", &n);

  ll m = 0;
  ll sum = 0;
  for (ll i = 0; i < n; i++) {
    ll v;
    scanf("%lld", &v);

    m = max(m, v);
    sum += v;
  }

  sum -= m;

  cout << ((m < sum) ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
S = input()
if S[0] == S[1] and S[1] == S[2] and S[2] == S[3]:
    print('No')
    exit()
elif S[0] == S[1] and S[2] == S[3]:
    print('Yes')
    exit()
elif S[0] == S[2] and S[1] == S[3]:
    print('Yes')
    exit()
elif S[0] == S[3] and S[1] == S[2]:
    print('Yes')
    exit()
else:
    print('No')


Measured memory_bytes: 3064
//#pragma GCC optimize(2)
//#pragma GCC optimize("Ofast,unroll-loops")
//#pragma comment(linker, "/STACK:102400000,102400000")

#include <bits/stdc++.h>
using namespace std;
//#define int long long
#define rep(i, beg, end) for (int i = (beg); i < (end); i++)
#define rrep(i, beg, end) for (int i = (beg); i >= (end); i--)
#define sp(i) setprecision(i) << fixed
typedef long long ll;
typedef pair<int, int> P;
typedef unsigned long long ull;
const int INF = 0x3f3f3f3f;
const int mod = 998244353;
const int N = 200010;
ull p_hash(ull x, ull y) { return (x + y) * (x + y + 1) / 2 + y; } //NxN->N
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

vector<int> l(12), r(12);
int cnt[N];
int sum[N];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int n, k;
    cin >> n >> k;

    for (int i = 1; i <= k; i++)
        cin >> l[i] >> r[i];

    cnt[1] = 1;
    sum[1] = 1;
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= k; j++)
        {
            int a = l[j], b = r[j];
            if (i - a < 1)
                continue;
            cnt[i] = ((ll)cnt[i] + sum[i - a] - sum[max(i - b, 1) - 1]) % mod;
        }
        sum[i] = ((ll)sum[i - 1] + cnt[i]) % mod;
    }
    cout << (cnt[n] + mod) % mod << endl;
    return 0;
}

Measured memory_bytes: 5184
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#include<map>
#include<vector>
#include<set>
#include<cstdlib>
#define pb push_back
#define mk make_pair
#define ll long long
#define lson ch[x][0]
#define rson ch[x][1]

using namespace std;

inline int read()
{
   int x=0,f=1;char ch=getchar();
   while (!isdigit(ch)) {if (ch=='-') f=-1;ch=getchar();}
   while (isdigit(ch)) {x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}
   return x*f;
}

const int maxn = 2e5+1e2;

int n,k;

int main()
{
   n=read(),k=read();
   if (n>=1+(k-1)*2) cout<<"YES";
   else cout<<"NO";
   return 0;
}


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

int main(){
    int N,res;
    cin >> N;
    vector<int> vec={105,135,165,189,195,201};
    for (int i=0;i<vec.size();i++){
        if (vec[i]>N){
            res=i;
            break;
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 256
n = int(input())
res = 0
from bisect import bisect_right
aa = [j*(j+1)//2 for j in range(1,22)]
    
for i in range(2,10**6):
    if n%i==0:
        cnt = 0
        while n%i==0:
            n = n//i
            cnt += 1
#        print(i, cnt)
        res += bisect_right(aa, cnt)
    if n == 1:
        break
else:
    res += 1
print(res)

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

#define rep(i, n) for(int i = 0; i < n; i++)

typedef long long ll;
using namespace std;
int mod = 1000000007;

int main(void){
    int a, b, c, d; cin >> a >> b >> c >> d;
    int l = a+b, r = c+d;
    if(l < r){
        cout << "Right" << endl;
    }
    else if(l == r) cout << "Balanced" << endl;
    else cout << "Left" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  double a[55];
  for(int i=0;i<n;i++){
  	cin>>a[i];
  }
  sort(a,a+n);
  double sum=a[0];
  for(int i=1;i<n;i++){
  	sum=(sum+a[i])/2;
  }
  cout<<sum;
  return 0;
}

Measured memory_bytes: 256
from sys import stdin

def getval():
    n,m = map(int,input().split())
    ab = []
    c = []
    def tobit(arr):
        idx = len(arr)-1
        s = ""
        for i in range(n-1,-1,-1):
            if arr[idx]-1==i and idx!=-1:
                s = "".join([s,"1"])
                idx -= 1
            else:
                s = "".join([s,"0"])
        return s
    for i in range(m):
        ab.append(list(map(int,stdin.readline().split())))
        c.append(tobit(list(map(int,stdin.readline().split()))))
    return n,m,ab,c 

def main(n,m,ab,c):
    dp = [-1 for i in range(2**n)]
    dp[0] = 0
    
    
    def intersect(bit1,bit2):
        s = ""
        for i in range(n):
            if bit1[i]=="1" or bit2[i]=="1":
                s = "".join([s,"1"])
            else:
                s = "".join([s,"0"])
        return int(s,2)

    for i in range(m):
        curc = ab[i][0]
        curk = c[i]
        temp = [-1 for i in range(2**n)]
        for j in range(2**n):
            if dp[j]==-1:
                continue
            new = dp[j]
            
            s = bin(j)[2:]
            if len(s)!=n:
                while len(s)<n:
                    s = "".join(["0",s])
            update = intersect(curk,s)
            
            #print(i,j,update,new,curc,curk,s)
            target = temp[update]
            if target==-1:
                temp[update] = new+curc
            elif target>new+curc:
                temp[update] = new+curc                
            if new<temp[j] or temp[j]==-1:
                temp[j] = dp[j]
        dp = temp
        #print(dp)
    print(dp[-1])
        
                
if __name__=="__main__":
    n,m,ab,c = getval()
    main(n,m,ab,c)

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

int main() {
	int n;cin>>n;
	vector<int> a(n),b(n),c(n);
	for(int i=0;i<n;i++){
		cin>>a[i];
		a[i]--;
	}
	for(int i=0;i<n;i++){
		cin>>b[i];
	}
	for(int i=0;i<n-1;i++){
		cin>>c[i];
	}
	int ans=b[a[0]];
	for(int i=1;i<n;i++){
		ans+=b[a[i]];
		if(a[i-1]==a[i]-1){
			ans+=c[a[i-1]];
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

int main() {
    int N;
    cin >> N;
    vector<ll> A(N), B(N), C(N);
    rep(i, N) cin >> A[i] >> B[i] >> C[i];
    vector<vector<ll>> dp(N + 1, vector<ll>(3));
    // dp[i][j]:=i-1日目にjを選んだ時の最大スコア
    for(int i = 0; i < N; i++) {
        dp[i + 1][0] = max(dp[i][1], dp[i][2]) + A[i];
        dp[i + 1][1] = max(dp[i][0], dp[i][2]) + B[i];
        dp[i + 1][2] = max(dp[i][0], dp[i][1]) + C[i];
    }
    cout << max(dp[N][0], max(dp[N][1], dp[N][2])) << endl;
    return 0;
}

Measured memory_bytes: 11088
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(i,n) for(int i = 1; i <= (int)(n); i++)
#define pb push_back
#define all(v) v.begin(),v.end()
#define fi first
#define se second
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<string> vs;
typedef vector<char> vc;
typedef long long ll;
typedef unsigned long long ull;

//const ll mod = 1000000007;

int main() {
    string s;
    cin >> s;
    int q;
    cin >> q;
    int turn = 0;
    rep(i,q-1) {
        int t;
        cin >> t;
        if(t == 1) {
            if(turn == 1) turn = 0;
            else turn = 1;
        }
        else {
            int f1;
            string f2;
            cin >> f1 >> f2;
            if(turn == 0) {
                if(f1 == 1) s.insert(0,f2);
                else s += f2;
            }
            else {
                if(f1 == 1) s += f2;
                else s.insert(0,f2);
            }
        }
    }
    if(turn == 1) reverse(all(s));
    int t;
    cin >> t;
    if(t == 1) reverse(all(s));
    else {
        int f1;
        string f2;
        cin >> f1 >> f2;
        if(f1 == 1) s.insert(0,f2);
        else s += f2;
    }
    cout << s << endl;
}

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

#pragma region lib_fenwick_tree
namespace lib {
  /*
    class FenwickTree
    usage: Fenwicktree f(100), FenwickTree<long long> f(100)
  */
  template <class T = int> class FenwickTree {
    public:
    FenwickTree() {}
    FenwickTree(int s) :
        size(s), data(s + 1, (T) 0) {}
    FenwickTree(const vector<T> &d) {
      size = d.size();
      data = vector<T>(size + 1, (T) 0);
      for (int i = 0; i < size; i++) add(i, d[i]);
    }

    /* index value must be 0-indexed */
    void add(int idx, const T &diff) {
      for (idx++; idx <= size; idx += (idx & -idx)) {
        data[idx] += diff;
      }
    }

    /* sum of the interval [0, idx] (inclusive, 0-indexed) */
    T sum(int idx) {
      T ret = 0;
      for (idx++; idx > 0; idx -= (idx & -idx)) {
        ret += data[idx];
      }
      return ret;
    }

    /* sum of the interval [l, r] (inclusive, 0-indexed) */
    T rangeSum(int l, int r) {
      return sum(r) - sum(l - 1);
    }

    private:
    int size;
    vector<T> data;
  };
}  // namespace lib
#pragma endregion

int main() {
  int N, Q;
  scanf("%d%d", &N, &Q);
  
  vector<long long> a(N);
  for (long long &in : a) scanf("%lld", &in);
  
  lib::FenwickTree<long long> f(a);
  
  while (Q--) {
    int x, y, z;
    scanf("%d%d%d", &x, &y, &z);
    if (x == 0)
      f.add(y, z);
    else
      printf("%lld\n", f.rangeSum(y, z - 1));
  }
  
  return 0;
}


Measured memory_bytes: 12148
function Main(input) {
	input = input.trim().split(' ');
	var n = Number(input[0]);
	var k = Number(input[1]);
	
	if(n%k < 1 || n == k){
		console.log(0);
	} else {
		console.log(1);
	}
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

#define forn(i,n) for(int i=0;i<(int)(n);i++)
#define si(c) ((int)(c).size())
#define forsn(i,s,n) for(int i = (int)(s); i<((int)n); i++)
#define dforsn(i,s,n) for(int i = (int)(n)-1; i>=((int)s); i--)
#define all(c) (c).begin(), (c).end()
#define D(a) cerr << #a << "=" << a << endl;
#define pb push_back
#define eb emplace_back
#define mp make_pair

typedef long long int ll;
#define int ll
typedef vector<int> vi;
typedef pair<int,int> pii;

const int N = 2e5 + 10;

int n,m, deg[N];
vi adj[N];

bool cyc[N];
vi cycle;

ll res = 0;
int bal[N];
void dfs(int u, int p) {
    bal[u] = 1;
    for (int v : adj[u]) if (!cyc[v] && v != p) {
        dfs(v,u);
        bal[u] -= bal[v];
    }
    if (p != -1) res += abs(bal[u]);
}

void result(ll res) {
    cout << res << '\n';
    exit(0);
}

void find_cycle() {
    vector<int> q;
    forn(u,n) if (deg[u] == 1) q.pb(u);
    while (!q.empty()) {
        int u = q.back(); q.pop_back();
        for (int v : adj[u]) {
            if (--deg[v] == 1) q.pb(v);
        }
    }

    int x;
    forn(u,n) if (deg[u] == 2) {
        x = u;
        break;
    }
    vector<bool> vis(n,false);
    vis[x] = true;
    cycle.pb(x);
    while (1) {
        bool found = false;
        int u = cycle.back();
        for (int v : adj[u]) if (!vis[v] && deg[v] == 2) {
            cycle.pb(v);
            vis[v] = true;
            found = true;
            break;
        }
        if (!found) break;
    }
    for (auto u : cycle) cyc[u] = true;
}

#undef int
int main() {
#define int ll
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

    cin >> n >> m;
    forn(_,m) {
        int u,v; cin >> u >> v;
        u--; v--;
        deg[u]++; deg[v]++;
        adj[u].pb(v);
        adj[v].pb(u);
    }
    if (m == n) {
        find_cycle();

        vi cbal;
        for (int r : cycle) {
            dfs(r,-1);
            cbal.pb(bal[r]);
        }

        if (si(cycle) % 2) {
            ll total = 0;
            forn(i,si(cbal)) {
                if (i%2 == 0) total -= cbal[i]; else total += cbal[i];
            }
            if (total%2) result(-1);
            total /= 2;
            for (auto b : cbal) {
                res += abs(total);
                total = -total-b;
            }
            result(res);
        }
        else {
            vector<ll> cum;
            cum.pb(0);
            forn(i,si(cbal)) {
                if (i%2 == 0) cum.pb(cum.back()-cbal[i]);
                else cum.pb(cum.back()+cbal[i]);
            }
            if (cum.back() != 0) result(-1);

            cum.pop_back(); sort(all(cum));
            ll med = cum[si(cum)/2];
            for (ll x : cum) res += abs(x-med);
            result(res);
        }
    }
    else {
        dfs(0,-1);
        if (bal[0] != 0) result(-1);
        result(res);
    }

    return 0;
}


Measured memory_bytes: 14208
/****************************
/////  Shubham Singhal
/////  LNMIIT
*****************************/
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// #include <functional> 
// using namespace __gnu_pbds;
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define eb emplace_back
#define lwr lower_bound
#define upr upper_bound
#define pq priority_queue
#define umap unordered_map
#define rep(i,n) for(i=0; i<n;i++)
#define repp(i,a,n) for(i=a; i<n;i++)
#define precise(x) cout<<fixed<<setprecision(x)
#define all(x) x.begin(),x.end()
#define lcm(a,b) (a*b)/__gcd(a,b)
#define prn(x) cout<<x<<"\n"
#define prn2(x, y) cout<<x<<" "<<y<<"\n"
#define prn3(x, y, z) cout<<x<<" "<<y<<" "<<z<<"\n"
#define prn4(x, y, z, a) cout<<x<<" "<<y<<" "<<z<<" "<<a<<"\n"
#define prnv(x) for(auto i:x) cout<<i<<" "; cout<<"\n"
#define MOD 1000000007
#define MaX 300005
using namespace std;

 
typedef unsigned long long ull;
typedef long long ll;
typedef double ld;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd; 
typedef vector<int> vi;
typedef vector<long> vl;
typedef vector<char> vc;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pii> vpii;
typedef vector<pil> vpil;
typedef vector<pli> vpli;
typedef vector<pll> vpll;
const long long INF64 = 1e18;
clock_t time_p=clock();
void time()
{
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}
void doc()
{
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
}
void fast()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
}
// typedef tree<int, null_type, less<int>, rb_tree_tag, 
//              tree_order_statistics_node_update> 
//     new_data_set; 
bool isprime(ll n) 
{ 
    if (n <= 1) 
        return false; 
    if (n <= 3) 
        return true; 
    if (n % 2 == 0 || n % 3 == 0) 
        return false; 
  
    for (ll i = 5; i * i <= n; i = i + 6) 
        if (n % i == 0 || n % (i + 2) == 0) 
            return false; 
    return true; 
}


int main()
{
    fast();
    int n,i,j,k;
    cin>>n;
    map<int,int> m;
    for(i=1;i<=100;i++)
    {
        for(j=1;j<=100;j++)
        {
            for(k=1;k<=100;k++)
            {
                int s = i*i + j*j + k*k + i*j + j*k + k*i;
                m[s]++; 
            }
        }
    }
    for(i=1;i<=n;i++)
        cout<<m[i]<<'\n';
}


Measured memory_bytes: 5508
import math

N, K=map(int, input().split())
A=list(map(int, input().split()))
F=list(map(int, input().split()))
A=sorted(A, reverse=False)
F=sorted(F, reverse=True)

a=-1
b=max([A[i]*F[-i-1] for i in range(N)])
while b-a>1:
  tmp=(a+b)//2
  c=sum([max(0, math.ceil(A[i]-tmp/F[i])) for i in range(N)])
  if c<=K:
    b=tmp
  else:
    a=tmp
print(b)

Measured memory_bytes: 169876
#include <stdio.h>
int main(void)
{
   int a,b;
   scanf("%d %d",&a,&b);
   if(a<b){
      printf("a < b\n");
   }
   if(a>b){
      printf("a > b\n");
   }
   if(a==b){
      printf("a == b\n");
   }
   return 0;
}

Measured memory_bytes: 580
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
//const ll MOD = 1e9 + 7;
const ll MOD = 998244353;
//const ll MOD = ;
ll mod(ll A, ll M) {return (A % M + M) % M;}
const ll INF = 1LL << 60;
template<class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
ll divceil(ll A, ll B) {return (A + (B - 1)) / B;}
ll myctoi(char C) {return C - '0';}
char myitoc(ll N) {return '0' + N;}
#define FINALANS(A) {cout << (A) << '\n'; exit(0);}

int main()
{
  ll N, M;
  cin >> N >> M;
  vector<vector<ll>> G(3 * N);
  for (ll i = 0; i < M; i++)
  {
    ll u, v;
    cin >> u >> v;
    u--, v--;
    G.at(u + 0 * N).push_back(v + 1 * N);
    G.at(u + 1 * N).push_back(v + 2 * N);
    G.at(u + 2 * N).push_back(v + 0 * N);
  }
  ll S, T;
  cin >> S >> T;
  S--, T--;

  queue<ll> Q;
  vector<bool> visited(3 * N, false);
  Q.push(S);
  visited.at(S) = true;

  ll ans = 0;
  while (!Q.empty())
  {
    ll n = Q.size();
    for (ll i = 0; i < n; i++)
    {
      ll v = Q.front();
      if (v == T)
        FINALANS(ans / 3);
      
      Q.pop();

      for (auto nv : G.at(v))
      {
        if (!visited.at(nv))
        {
          Q.push(nv);
          visited.at(nv) = true;
        }
      }
    }
    ans++;
  }
  FINALANS(-1);
}

Measured memory_bytes: 16640
#include<stdio.h>



main(){
  int i,j,n;
  int sum,data;
  int k, temp;

  while(1){
    scanf("%d", &k);
    if(k==0) break;
    temp=k*(k-1)/2;
    sum=0;
    for(i=0;i<temp;i++){
      scanf("%d", &data);
      sum+=data;
    }
    printf("%d\n", sum/(k-1));
  }

  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define llint long long
#define mod 1000000007
using namespace std;

llint sx, sy, tx, ty;
const int FACT_MAX = 3000005;
llint fact[FACT_MAX], fact_inv[FACT_MAX];

llint modpow(llint a, llint n)
{
	if(n == 0) return 1;
	if(n % 2){
		return ((a%mod) * (modpow(a, n-1)%mod)) % mod;
	}
	else{
		return modpow((a*a)%mod, n/2) % mod;
	}
}

void make_fact()
{
	llint val = 1;
	fact[0] = 1;
	for(int i = 1; i < FACT_MAX; i++){
		val *= i;
		val %= mod;
		fact[i] = val;
	}
	fact_inv[FACT_MAX-1] = modpow(fact[FACT_MAX-1], mod-2);
	for(int i = FACT_MAX-2; i >= 0; i--){
		fact_inv[i] = fact_inv[i+1] * (i+1) % mod;
	}
}

llint comb(llint n, llint k)
{
	llint ret = 1;
	ret *= fact[n];
	ret *= fact_inv[k], ret %= mod;
	ret *= fact_inv[n-k], ret %= mod;
	return ret;
}

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	make_fact();
	
	cin >> sx >> sy >> tx >> ty;
	
	llint ans = 0;
	for(int i = sx; i <= tx; i++){
		ans += comb(i+ty+1, ty), ans %= mod;
		ans += mod - comb(i+(sy-1)+1, sy-1), ans %= mod;
	}
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 47104
#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 RemOfSumIsNum | diff RemOfSumIsNum.out -
// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address RemOfSumIsNum.cpp && ./a.out

/*
 
 11/24/2019
 
 4:26-4:50
 
 */

const int MAX_N=1e6+1;
LL A[MAX_N];
int N,K;

void solve() {
  if(K==1) {
    cout<<0<<endl;
    return;
  }
  vector<LL> B(N);
  REP(i,N)B[i]=A[i]-1;
  map<LL,LL> cnt;
  cnt[0]=1;
  queue<LL> Q;   Q.push(0);
  LL sum=0,res=0;
  REP(i,N) {
    sum=(sum+B[i])%K;
//    dump(i,sum,cnt[sum]);
    res+=cnt[sum];
    cnt[sum]++;
    Q.push(sum);
    if(SZ(Q)>=K) {
      LL a=Q.front(); Q.pop();
      cnt[a]--;
    }
  }
  cout<<res<<endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout<<setprecision(12)<<fixed;
  
  cin>>N>>K;
  REP(i,N) cin>>A[i];
  solve();
  
  return 0;
}


Measured memory_bytes: 17536
#define _USE_MATH_DEFINES  

#include <algorithm>
#include <iostream>
#include <string>
#include <cmath>
#include <vector>

int main(){
    int h, w;

    while(1){
        std::cin >> h >> w;
        if(0 == h + w){
            break;
        }else{
            std::string edge(w, '#');
            std::string inter(w - 2, '.');
            inter.insert(inter.begin(), '#');
            inter.push_back('#');
            for(int i = 0; i < h; ++i){
                if(i == 0 || i == h - 1){
                    std::cout << edge << std::endl;
                }else{
                    std::cout << inter << std::endl;
                }
            }
            std::cout << std::endl;
        }
    }

    return 0;
}


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

using namespace std;
typedef long long ll;

#define REP(i, n) for (ll i = 0; i < (n); i++)
#define REPR(i, n) for (ll i = (n); i >= 0; i--)
#define FOR(i, m, n) for (ll i = (m); i < (n); i++)
#define FORR(i, m, n) for (ll i = (m); i >= (n); i--)
#define INF 1e9
#define pb push_back
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((ll)(x).size())
#define SORT(x) sort((x).begin(), (x).end())
#define dump(x) cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl

int main(int argc, char const *argv[])
{
    ll n;
    cin >> n;
    string s;
    vector<ll> a(n, 0);
    REP(i, n)
    {
        cin >> s;
        if (s == "P")
            a[0] = 1;
        else if (s == "W")
            a[1] = 1;
        else if (s == "G")
            a[2] = 1;
        else if (s == "Y")
            a[3] = 1;
    }
    string res = accumulate(ALL(a), 0) == 3 ? "Three" : "Four";
    cout << res << endl;
    return 0;
}


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

int main(){
  int n;
  string s;
  cin >> n;
  cin >> s;
  int dif = 0;
  int l = 0, r = 0;
  rep(i, n){
    if(s[i] == '(') l++;
    else r++;
    dif = max(dif, r-l);
  }
  string ans = s;
  if(dif >= 1) {
    rep(i, dif) ans = '(' + ans;
  }
  l += dif;
  if(l > r) {
    rep(i, l-r) ans = ans + ')';
  } else {
    rep(i, r-l) ans = '(' + ans;
  }
  cout << ans << endl;
  return 0;
}


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


int main(){
	vector<int> prime(1000000,true);
	prime[0]=prime[1]=false;
	for(int i=2;i<1000;i++){
		if(prime[i]){
			for(int j=i*2;j<1000000;j+=i){
				prime[j]=false;
			}
		}
	}
	int a,d,n,i,c;
	while(cin >> a >> d >> n && a || d || n){
		for(c=0,i=a;n;i+=d){
			if(prime[i]){
				n--;
			}
		}
		cout << i-d << endl;
	}
}

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;

ll gcd(ll x,ll y){
    if (x<y) swap(x,y);
    if (y==0) return x;
    else return gcd(y,x%y);
}

int main(){
    int N;
    cin >> N;
    vector<pair<ll,ll>> BA(N);
    for (int i=0;i<N;i++){
        cin >> BA[i].second >> BA[i].first;
    }
    sort(BA.begin(),BA.end());
    ll time = 0;
    for (int i=0;i<N;i++){
        time += BA[i].second;
        if (time>BA[i].first){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse4")

using namespace std;

#define FOR(a,b) for(int a=0;a<b;a++)
#define F0R(a,b,c) for(int a = b; a<=c; a++)
#define f first
#define s second
#define m0(x) memset(x,0,sizeof(x))

typedef pair<int,int> pi;
typedef long long ll;
typedef vector<int> vi;
typedef vector<pi> vpi;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    bool good = false;
    FOR(i,3){
        char a; cin >> a;
        if(a == '7') good = true;
    }
    if(good) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3640
from collections import Counter
N = int(input())
S = input()
ans = 0
for x in range(10):
    for y in range(10):
        hantei = []
        for i in range(N):
            if x != int(S[i]):
                continue
            for j in range(i+1, N):
                if y != int(S[j]):
                    continue
                for k in range(j+1, N):
                    hantei.append(S[k])
                ans += len(Counter(hantei))
                break
            break

print(ans)


Measured memory_bytes: 9720
a="keyence"
s=input()
#print(s[:7],s[-7:])
if a==s[:7] or a==s[-7:]:
  print("YES")
else:
  i=0
  sw=0
  while 1:
    if a[i]==s[i]:
      i+=1
    else:
      break
  while 1:
    if a[i]==s[-7+i]:
      i+=1
    else:
      sw=1
      break
    if i==7:
      break
  print("NO" if sw==1 else "YES")
  

Measured memory_bytes: 3060
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		int A = sc.nextInt();
		int B = sc.nextInt();
		int ans = 0;
		if (A >= B) {
			ans += A;
			A--;
		} else {
			ans += B;
			B--;
		}
		if (A >= B) {
			ans += A;
			A--;
		} else {
			ans += B;
			B--;
		}
		System.out.println(ans);
	}
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }

    private int readByte() {
        if (hasNextByte())
            return buffer[ptr++];
        else
            return -1;
    }

    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr]))
            ptr++;
        return hasNextByte();
    }

    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong() {
        if (!hasNext())
            throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
            throw new NumberFormatException();
        return (int) nl;
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }
}

Measured memory_bytes: 21204
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using bint = boost::multiprecision::cpp_int;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repSE(i,s,n) for (int i = (s); i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;

bool checkPow(ll N, int i) {
    bool ans = true;
    ll _N = N;
    while (_N > 1) {
        if (_N % i != 0) {
            ans = ((_N - 1) % i == 0);
            break;
        }
        _N /= i;
    }
    return ans;
}

int main()
{
    ll N;
    cin >> N;
    ll rN = (ll)sqrt(N) + 1;
    int cnt = 1; // when K = N
    repSE(i, 2, rN) {
        if (N % i == 0) {
            if (checkPow(N, i)) {
                cnt += 1;
                continue;
            }
        }
    }

    // count divisor of (N - 1)
    int ans = 1; // for (N-1) and not count 1
    ll rN_1 = (ll)sqrt(N - 1) + 1;
    repSE(i, 2, rN_1) {
        if ((N - 1) % i == 0) {
            if ((N - 1)/i == i) cnt += 1;
            else ans += 2;
        }
    }
    if (N == 2) ans = 0;
    cout << cnt + ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define N 100

int main(void){
  int n,i,j,k,minj,tmp,count=0,data[N];

  scanf("%d",&n);
  for(i=0;i<n;i++) scanf("%d",&data[i]);

  for(i=0;i<n-1;i++){
    minj=i;
     for(j=i;j<n;j++)if(data[j]<data[minj]) minj=j;

     tmp=data[i];
     data[i]=data[minj];
     data[minj]=tmp;
     if(i!=minj) count++;
  }

  for(i=0;i<n;i++){
    printf("%d",data[i]);
    if(i!=n-1) printf(" ");
  }

  printf("\n%d\n",count);
  return 0;
}

Measured memory_bytes: 604
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using Map = map<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
ll INF=1LL<<60;
ll MOD=1000000007;



int main(){
    string s;
    cin >> s;
    if(s=="ARC")cout<<"ABC"<<endl;
    else cout<<"ARC"<<endl;
    
    return 0;
}


Measured memory_bytes: 3628
// D - Xor Sum 4
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rp(i,s,e) for(int i=(s);i<(e);++i)
#define MOD 1000000007
 
ll O[60];
 
int main(){
	int ans=0, N; cin>>N;
	rp(i,0,N){ ll j=0, a; scanf("%lld",&a); while(a){ O[j++]+=a&1; a>>=1; } }
	rp(i, 0, 60) ans = (ans + (O[i]*(N-O[i]) % MOD) * ((1LL<<i) % MOD)) % MOD;
	cout<< ans <<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0;i<n;i++)
using namespace std;
 
int main() {
  int N;
  string S;
  cin >> N >> S;
  int A=0,B=0;
  rep(i,N) if (S[i]=='R') A++;
  int ans = A;
  rep(i,N) {
    if (S[i]=='W') B++;
    else A--;
    ans = min(ans,max(A,B));
  }
  cout << ans << endl;
}

Measured memory_bytes: 3748
// #pragma GCC target("avx")  // CPU 処理並列化
// #pragma GCC optimize("O3")  // CPU 処理並列化
// #pragma GCC optimize("unroll-loops")  // 条件処理の呼び出しを減らす
// #define BEGIN_STACK_EXTEND(size) void * stack_extend_memory_ = malloc(size);void * stack_extend_origin_memory_;char * stack_extend_dummy_memory_ = (char*)alloca((1+(int)(((long long)stack_extend_memory_)&127))*16);*stack_extend_dummy_memory_ = 0;asm volatile("mov %%rsp, %%rbx\nmov %%rax, %%rsp":"=b"(stack_extend_origin_memory_):"a"((char*)stack_extend_memory_+(size)-1024));
// #define END_STACK_EXTEND asm volatile("mov %%rax, %%rsp"::"a"(stack_extend_origin_memory_));free(stack_extend_memory_);

#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
#include<numeric>
#include<unordered_set>
#include<unordered_map>
#include<complex>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-11;
const double INF=1e+10;
const double PI=acos(-1.0);
const int C_SIZE = 11100000;
const int UF_SIZE = 3100000;
namespace{
	long long fact[C_SIZE];
	long long finv[C_SIZE];
	long long inv[C_SIZE];
	inline long long Comb(int a,int b){
	 	if(a<b||b<0)return 0;
	 	return fact[a]*finv[b]%mod*finv[a-b]%mod;
	}
	void init_C(int n){
		fact[0]=finv[0]=inv[1]=1;
		for(int i=2;i<n;i++){
			inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
		}
		for(int i=1;i<n;i++){
			fact[i]=fact[i-1]*i%mod;
			finv[i]=finv[i-1]*inv[i]%mod;
		}
	}
	long long pw(long long a,long long b){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%mod;
			a=a*a%mod;
			b/=2;
		}
		return ret;
	}
	long long pw_mod(long long a,long long b,long long M){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%M;
			a=a*a%M;
			b/=2;
		}
		return ret;
	}
	int pw_mod_int(int a,int b,int M){
		if(a<0)return 0;
		if(b<0)return 0;
		int ret=1;
		while(b){
			if(b%2)ret=(long long)ret*a%M;
			a=(long long)a*a%M;
			b/=2;
		}
		return ret;
	}
	int ABS(int a){return max(a,-a);}
	long long ABS(long long a){return max(a,-a);}
	double ABS(double a){return max(a,-a);}
	int sig(double r) { return (r < -EPS) ? -1 : (r > +EPS) ? +1 : 0; }
	int UF[UF_SIZE];
	void init_UF(int n){
		for(int i=0;i<n;i++)UF[i]=-1;
	}
	int FIND(int a){
		if(UF[a]<0)return a;
		return UF[a]=FIND(UF[a]);
	}
	void UNION(int a,int b){
		a=FIND(a);b=FIND(b);if(a==b)return;
		if(UF[a]>UF[b])swap(a,b);
		UF[a]+=UF[b];UF[b]=a;
	}
}
// ここから編集しろ
long long f(int a,int b,int c){
	return fact[a+b+c]*a%mod*inv[a+b]%mod;
}
int main(){
	int a,b;scanf("%d%d",&a,&b);
	init_C(11000000);
	long long ret=0;
	for(int i=1;i<=b;i++){
		for(int j=0;j<i;j++){
			long long tmp=Comb(i,j);
			tmp=tmp*f(i-j,a-b,max(0,b-i-1))%mod;
			// printf("%d %d: %lld\n",i,j,tmp);
			if(j%2){
				ret=(ret+mod-tmp)%mod;
			}else{
				ret=(ret+tmp)%mod;
			}
		}
	}
	// ret=ret*fact[a]%mod;
	printf("%lld\n",ret);
}

Measured memory_bytes: 259556
def solve():
    a,b,c,k=map(int,input().split())
    sum=0
    if(a>=k):
        sum+=k*1
        return sum
    else:
        sum+=a*1
        k-=a
    if(b>=k):
        sum+=k*0
        return sum
    else:
        sum+=b*0
        k-=b
    sum+=k*(-1)
    return sum

def main():
    print(solve())

main()

Measured memory_bytes: 9128
def f(A, n): 
    array_sum = 0
    for i in range(0, n, 1): 
        array_sum += A[i]
    array_sum_square = (array_sum * array_sum)
    individual_square_sum = 0
    for i in range(0, n, 1): 
        individual_square_sum += (A[i] * A[i]) 
    return (array_sum_square - individual_square_sum) // 2 
n = int(input())
a = [int(x) for x in input().split()]
MOD = 10**9 +7

print(int(f(a,n))%MOD)

Measured memory_bytes: 31428
#include<bits/stdc++.h>
typedef long long int ll;
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cout.tie(0);cin.tie(0);

const ll mod= 998244353;
const ll MAXN= 2e5 + 5;
const ll inf= 1e16;

int main()
{
    fastio;
    ll n;
    cin >> n;
    if(n % 10 == 7) cout << "Yes" << endl;
    else{
        n = n / 10;
        if(n % 10 == 7) cout << "Yes" << endl;
        else{
            n = n / 10;
            if(n % 10 == 7) cout << "Yes" << endl;
            else cout << "No" << endl;
        }
    }
}


Measured memory_bytes: 3640
N, M = gets.chomp.split.map(&:to_i)

counter = 0

if N >= 2
  (1..N).to_a.combination(2) do |c|
    counter += 1
  end
end

if M >= 2
  (1..M).to_a.combination(2) do |c|
    counter += 1
  end
end

puts counter

Measured memory_bytes: 1788
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#include <bitset>
using namespace std;
#define rep(i,a,n) for(ll i=a;i<n;i++)
#define rrep(i,a,n) for(ll i=n;i>=a;i--)
#define elif else if
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF = 1e+17;
const ll MODcdf = 998244353;
bool pairCompare(const P& firstElof,const P& secondElof){
    return firstElof.first<secondElof.first;
}
int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    ll n;cin>>n;
    ll h[n];
    rep(i,0,n)cin>>h[i];
    ll high=h[0];
    ll ans=1;
    rep(i,1,n){
        if(h[i]>=high){
            ans++;
            high=h[i];
        }
    }
    cout<<ans<<endl;
}


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

#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define sc(x) scanf("%lld",&x)
#define pr(x) printf("%lld\n",x)
#define clr(x) memset(x, 0, sizeof(x))
#define all(x) x.begin(), x.end()
typedef pair<ll, ll> pii;
typedef vector< ll > vl;
typedef vector< pii > vpii;

//DONT WASTE YOUR TIME
//prove yourself
//remember....fuck ps&&as hard....show them your are better then them
//Be confident.....dont lose hope.......You can do it.....
//dimaag  khoob h tere meh ....bas concentration ki kami h
//CONCENTRATE
//A,B,C dimaag nhi ...observation h .....zyaada mat sochna unme.....bas observe karna dhyaan se aur implement kar daal jitni jaldi ho sake

//capture it

const ll N= 1e6+55,mod = 1e9+7;

int main() {
 	//freopen("task.in","r",stdin);freopen("task.out","w",stdout);
	string s;
	cin>>s;
	ll x,y,z,a,b,c,d;
	a=s[0]-'0';
	b=s[1]-'0';
	c=s[2]-'0';
	d=s[3]-'0';
	x=a+b+c+d;
	if(x==7){
		cout<<a<<"+"<<b<<"+"<<c<<"+"<<d<<"=7\n";
		return 0;
	}
	x=a+b+c-d;
	if(x==7){
		cout<<a<<"+"<<b<<"+"<<c<<"-"<<d<<"=7\n";
		return 0;
	}
	x=a+b-c+d;
	if(x==7){
		cout<<a<<"+"<<b<<"-"<<c<<"+"<<d<<"=7\n";
		return 0;
	}
	x=a+b-c-d;
	if(x==7){
		cout<<a<<"+"<<b<<"-"<<c<<"-"<<d<<"=7\n";
		return 0;
	}
	x=a-b+c+d;
	if(x==7){
		cout<<a<<"-"<<b<<"+"<<c<<"+"<<d<<"=7\n";
		return 0;
	}
	x=a-b+c-d;
	if(x==7){
		cout<<a<<"-"<<b<<"+"<<c<<"-"<<d<<"=7\n";
		return 0;
	}
	x=a-b-c+d;
	if(x==7){
		cout<<a<<"-"<<b<<"-"<<c<<"+"<<d<<"=7\n";
		return 0;
	}
	x=a-b-c-d;
	if(x==7){
		cout<<a<<"-"<<b<<"-"<<c<<"-"<<d<<"=7\n";
		return 0;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
template<typename T> inline void chmax(T &a, T b){
	if(a < b) a = b;
}

int main() {
	int n, m;
	cin >> n >> m;
	vector<ll> x(n), y(n), z(n);
	rep(i, n) cin >> x[i] >> y[i] >> z[i];
	const int s[8][3] = {{1, 1, 1}, {1, 1, -1}, {1, -1, 1}, {1, -1, -1}, {-1, 1, 1}, {-1, 1, -1}, {-1, -1, 1}, {-1, -1, -1}};
	ll ans = 0;
	rep(k, 8) {
		vector<ll> tmp(n);
		rep(i, n) {
			tmp[i] = s[k][0] * x[i] + s[k][1] * y[i] + s[k][2] * z[i];
		}
		sort(all(tmp));
		reverse(all(tmp));
		ll now = 0;
		rep(i, m) now += tmp[i];
		ans = max(ans, now);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int a[] = new int[n];
    int num = 1;
    int count = 0;
    
    for(int i = 0 ; i < n ; ++i){
      a[i] = sc.nextInt();
    }
    
    for(int i = 0 ; i < n ; ++i){
      if(a[i] == num){
        count++;
        num++;
      }

    }
    
    if(count == 0){
      System.out.println("-1");
    }else{
      System.out.println(n-count);
    }

  }
}

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

using namespace std;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define fin(ans) cout << (ans) << endl;
#define blank(ans) cout << (ans) << " ";
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()

typedef long long ll;
typedef long long lli;
typedef unsigned long long ull;
typedef long double ld;
typedef string str;

typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<ld> vd;
typedef vector<str> vs;
typedef vector<ll> vll;
typedef vector<pair<ll, ll>> vpll;
typedef vector<pair<ll, str>> vpls;
typedef vector<tuple<str, ll, ll>> vtsl;
typedef vector<vector<ll>> vvll;
typedef vector<vector<char>> vvc;
typedef vector<vector<str>> vvs;

const ld PI = acos(-1.0);
const ll MAX = 9000000000000000000;
const ll MIN = -9000000000000000000;
const ld DMAX = 4500;
const ld DMIN = -4500;
const ll MOD = 1000000007;

ll GetDigit(ll num)
{
  ll ans = 1;
  while(num)
  {
    num /= 10;
    ans *= 10;
  }
  return ans;
}

//実行部
void Main()
{
  ll a, b; cin >> a >> b;
  a = a * GetDigit(b);
  a = a + b;
  for(ll i = 0;i < 1000;i++)
  {
    if(i * i == a)
    {
      fin("Yes") exit(0);
    }
  }
  fin("No")
}

//前処理
int main()
{
  //ios::sync_with_stdio(false);
  //cin.tie(0);
  cout << fixed << setprecision(20); //高精度少数表示
  Main();
  return 0;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main()
{
	int x, a, b;
	cin >> x >> a >> b;
	if (abs(x - a) > abs(x - b))
	{
		cout << "B" << endl;
	}
	else
	{
		cout << "A" << endl;
	}
	return 0;
}

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


int solve(int x,int y,string z){
    if(z=="+")return x+y;
    if(z=="-")return x-y;
    if(z=="*")return x*y;
    if(z=="/")return x/y;
}

class Stack{
    private:
    int sp;
    int S[100];

    public:
    Stack(){
        sp = 0;
    }
    bool isFull()const{
        return (sp==100);
    }
    bool isEmpty()const{
        return (sp==0);
    }
    void push(int d);
    int top();
    void pop();
};

void Stack::push(int d){
    if(isFull()){
        return;
    }
    S[sp++] = d;
}

int Stack::top(){
    if(isEmpty()){
        return -1;
    }
    return S[sp-1];
}

void Stack::pop(){
    if(isEmpty()){
        return;
    }
    sp--;
}


int main(){
    Stack s;
    string str;


    while(cin>>str){
        if(str=="+"||str=="-"||str=="*"||str=="/"){
            //yが後の数、xが先の数
            int x,y;
            y = s.top();
            s.pop();
            x = s.top();
            s.pop();
            s.push(solve(x,y,str));
        }else{
            int z = atoi(str.c_str());
            s.push(z);
        }

        if(getchar()=='\n'){
            cout << s.top() << endl;
            return 0;
        }
        
    }

}


Measured memory_bytes: 3172
#include <stdio.h>
 
#define N 101
#define MAX 2001
#define WHITE 0
#define BLACK 1
#define NIL -1
  
void prim();

int gin[N][N], pi[N], w[N][N];
int n;

int main(){
  int d_sum = 0;
  int i, j;
  
  scanf("%d", &n);
  
  for(i = 0; i < n; i++){
    for(j = 0; j < n; j++){
      scanf("%d", &gin[i][j]);
      w[i][j] = gin[i][j];
    }
  }
  
  prim();
  
  for(i = 0; i < n; i++){
    if(w[i][ pi[i] ] != -1){
      d_sum += w[i][ pi[i] ];
    }
  }
  
  printf("%d\n", d_sum);
  
  return 0;
}

void prim(){
  int mincost, u, v, i;
  int color[n], d[n];
  
  for(u = 0; u < n; u++){
    d[u] = MAX;
    pi[u] = NIL;
    color[u] = WHITE;
  }
   
  d[0] = 0;
   
  while( 1 ){
    mincost = MAX;
    for(i = 0; i < n; i++){
      if(color[i] != BLACK && d[i] < mincost){
    mincost = d[i];
    u = i;
      }
    }
      
    if(mincost == MAX) break;
  
    color[u] = BLACK;
      
    for(v=0; v<n; v++){
      if(color[v] != BLACK && w[u][v] < d[v] && w[u][v] != -1){
	pi[v] = u;
	d[v] = w[u][v];
      }
    }
  }
}

Measured memory_bytes: 680
#include<stdio.h>
int main()
{
	int n;
	scanf("%d", &n);
	char s[5003];
	scanf("%s", s);
	int i, j, k;
	int ans = 0;
	int count;
	for (i = 0; i <= n - 1 - ans; i++)
	{
		for (j = i + ans; j <= n - ans; j++)
		{
			count = 0;
			for (k = 0; i + k < j && j + k < n; k++)
			{
				if (s[i + k] == s[j + k])
					count++;
				else
					break;
			}
			if (ans < count)
				ans = count;
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 1740
#include<iostream>
#include<string>
#include<iomanip>
using namespace std;
#define int long long
#define rep(i,n) for(int i = 0; i < n; i++)
#define INF (long long)(1e18)
#define MOD (int)(1e9+7)
#define MAX_N 103
#define MAX_V 10
#define MAX_M 101
#define max(a,b) (a>b?a:b)
#define yn(f) (f?"Yes":"No")
#define YN(f) (f?"YES":"NO")
#define pro "はいプロ　世界一○○が上手　○○界のtourist　○○時代の終焉を告げる者　実質○○　○○するために生まれてきた男"


signed main(){
	cout<<fixed<<setprecision(7);
	
	int a, b, c, d, e, f;
	int answs = 0, anss = 0, maxe1 = 0, maxe2 = 0;
	
	cin>>a>>b>>c>>d>>e>>f;
	
	for(int i = 0; i <= f; i+=a*100){
		for(int j = 0; j + i<= f; j+=b*100){
			for(int k = 0; i+j+k <= f; k+=c){
				for(int l = 0; i+j+k+l <= f; l+=d){
					int x = i+j, y = k+l;
					if((x/100)*e < y) continue;
					if(100*y*maxe2 >= maxe1*(x+y)){
						answs = x+y;
						anss = y;
						maxe1 = 100*y;
						maxe2 = x+y;
					}
				}
			}
		}
	}
	
	
	cout<<answs<<" "<<anss<<endl;
	
	
	
	return 0;
}

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

using namespace std;

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

#define reps(i,f,n) for(int i = int(f); i <= int(n); i++)
#define rep(i,n) reps(i,0,int(n)-1)
#define rrep(i,n) for(int i = n-1; i >= 0; i--)

#define all(x) (x).begin(),(x).end()
#define X first
#define Y second

#define sz size()
#define eb emplace_back
#define pb push_back

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


Measured memory_bytes: 256