akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define repr(i,from,to) for(int (i)=(from);(i)<(to);(i)++)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
// const bool debug=true;
const bool debug=false;
#define DEBUG if(debug==true)
#define all(x) begin((x)), end((x))
#define vprint(x) for(auto a:(x)) cout << x << endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;
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;
}


string pairtos(ll a, ll b) {
    return to_string(a) + " " + to_string(b);
}

pair<ll,ll> keytoll(string s) {
    string delim = " ";
    ll delimidx = s.find(delim);
    ll a = stoll(s.substr(0,delimidx));
    ll b = stoll(s.substr(delimidx+1, s.size()-delimidx));
    return pair<ll,ll>(a,b);
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while(n > 0) {
        if(n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

int main(void) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    vector<ll> a(n),b(n);
    unordered_map<string,ll> mp;
    unordered_map<string,ll> mpcnt;
    ll cnt00 = 0;
    ll cnta0 = 0,cntb0=0;
    rep(i,n) {
        cin>>a[i]>>b[i];
        if (a[i]==0 && b[i]==0) {
            cnt00++;
            continue;
        }
        else if (a[i]==0) {
            cnta0++;
            continue;
        }
        else if (b[i]==0) {
            cntb0++;
            continue;
        }
        ll x = __gcd(abs(a[i]),abs(b[i]));
        a[i] /= x;
        b[i] /= x;
        if (a[i]<0) {
            a[i] *= -1;
            b[i] *= -1;
        }
        string st = pairtos(a[i],b[i]);
        mp[st]++;
    }
    ll res = 1;
    for (auto x:mp) {
        // cout <<"mp:"<< x.first << endl;
        // cout <<"check"  << mpcnt[x.first] << endl;
        if (mpcnt.find(x.first)!=mpcnt.end()) {
            // cout << "continue" << endl;
            continue;
        }
        ll tmp = modpow(2, x.second, MOD);
        auto p = keytoll(x.first);
        string rev;
        if (p.second<0) {
            rev = pairtos(p.second*-1,p.first);
        }
        else {
            rev = pairtos(p.second, p.first*-1);
        }
        // cout << "rev:" << rev << endl;
        if (mp.find(rev)!=mp.end()) {

            tmp += modpow(2,mp[rev],MOD)-1;
            mpcnt[rev]=1;
        }
        tmp %= MOD;
        // cout << x.first << " " << tmp << endl;
        res = (res * tmp) % MOD;
    }
    if (cnta0 > 0 || cntb0 > 0) {
        ll tmp = modpow(2, cnta0, MOD);
        tmp += modpow(2, cntb0, MOD)-1;
        tmp %= MOD;
        res = (res * tmp) % MOD;
    }
    res = (res - 1 + cnt00 + MOD) % MOD;
    cout << res << endl;

    return 0;
}


Measured memory_bytes: 30196
N = int(input())
S = input()

A = []
cnt = 1
l = 0
pc = "W"
d = 1
for c in S:
    if c==pc:
        cnt += 1
        A.append(l)
    else:
        if cnt%2==1:
            pass
        else:
            d = -d
        l += d
        cnt = 1
        A.append(l)
    pc = c

if not (A[0]==A[-1]==1 and 0 not in A):
    print(0)
    exit()
mod = 10**9+7
ans = 1
pa = 1
d = 1
n = 1
for a in A[1:]:
    if pa!=a:
        pass
    else:
        d *= -1
    if d==-1:
        ans *= n
        ans %= mod
        n -= 1
    else:
        n += 1
    pa = a
for i in range(2, N+1):
    ans = ans * i % mod
print(ans)


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


k, q = map(int, input().split())
d = list(map(int, input().split()))
info = [list(map(int, input().split())) for i in range(q)]

for n, x, mod in info:
    d_mod = [d[i] % mod for i in range(k)]
    laps, rem = divmod(n - 1, k)
    start = x % mod
    end = start + sum(d_mod) * laps + sum(d_mod[0:rem])
    ans = n - (end // mod - start // mod + 1)

    # mod_dに0が含まれるときの処理
    is0 = [d_mod[i] == 0 for i in range(k)]
    cnt0 = sum(is0) * laps + sum(is0[0:rem])
    print(ans - cnt0)

Measured memory_bytes: 94556
using System;
using System.Collections.Generic;

namespace cswork {
    class Program {
        static void Main (string[] args) {
            long a = Read ();
            long b = Read ();
            long c = Read ();
            long x = Read ();

            long ans = 0;
            for (int i = 0; i <= a; i++) {
                for (int j = 0; j <= b; j++) {
                    for (int k = 0; k <= c; k++) {
                        long n = i * 500 + j * 100 + k * 50;
                        if (x == n) {
                            ans++;
                        }
                    }
                }
            }
            Write (ans);
            Exit ();
        }

        public static void Write (string str) {
            Console.WriteLine (str);
        }

        public static void Write (int i) {
            Console.WriteLine (i);
        }

        public static void Write (double d) {
            Console.WriteLine (d);
        }

        public static string ReadStr () {
            return Console.ReadLine ();
        }

        public static int ReadInt () {
            return int.Parse (Console.ReadLine ());
        }

        public static long Read () {
            return long.Parse (Console.ReadLine ());
        }

        public static double ReadDouble () {
            return double.Parse (Console.ReadLine ());
        }

        public static void Exit () { }

    }
}

Measured memory_bytes: 11092
N = 1000000
p = [ 1 ] * N

( p[ 0 ], p[ 1 ] ) = ( 0, 0 )
for i in range ( len ( p ) ):
  if ( p[ i ] ):
    for j in range ( i * 2, len ( p ), i ):
      p[ j ] = 0
for i in range ( 1, len ( p ) ):
  p[ i ] += p[ i - 1 ]

while True:
  try: n = int ( input ( ) )
  except EOFError: break
  print ( p[ n ] )


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

n = int(input())
s = list(input())
mod = 10**9+7

#dp[i][j]
dp = [[0]*n for i in range(n)]
for i in range(n):
    dp[0][i] = 1
pre_cum = list(range(1,n+1))

for i in range(1,n):
    for j in range(n-i+1):
        if s[i-1] == "<":
            dp[i][j] = (pre_cum[n-i]-pre_cum[j])%mod
        else:
            dp[i][j] = pre_cum[j]
    c = 0
    for j in range(n):
        c = (c+dp[i][j])%mod
        pre_cum[j] = c
print(dp[-1][0]%mod)


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

#define REP(i,n) for(int i=0;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<29
#define LINF LLONG_MAX/3
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(v) (v).begin(),(v).end()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
#define CININIT cin.tie(0),ios::sync_with_stdio(false)
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

constexpr ll mod = 1e9+7;

int main(){
    int N,A,B;
    cin>>N>>A>>B;
    string s;
    cin>>s;
    int a=0;
    int b=0;
    int c=0;

    for(int i=0;i<s.size();i++){
//        cerr << s[i] << endl;
//        debug2(a,b);
        if(s[i]=='a'){
            if(a+b<A+B){
                cout << "Yes" << endl;
                a++;
            }else{
                cout <<"No" << endl;
            }
        }
        else if(s[i]=='b'){
            if((a+b<A+B) and (b<B) ){
                cout << "Yes" << endl;
                b++;
            }else{
                cout <<"No" << endl;
            }
        }
        else if(s[i]=='c'){
            cout <<"No" << endl;
            c++;
        }
    }
}


Measured memory_bytes: 896
#pragma GCC optimize (3)
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
/*#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/hash_policy.hpp>
#include<ext/pb_ds/trie_policy.hpp>
#include<ext/pb_ds/priority_queue.hpp>*/
#define PII pair<int,int>
#define ll long long
#define ull unsigned long long
#define INFI 2147483647
#define INFL 9223372036854775807
#define INFU 18446744073709551615
#define maxn 1000005
using namespace std;
//using namespace __gnu_pbds;
const double PI=acos(-1.0);
const double eps=1e-6;
int n,m,a[maxn],tree[maxn],res[maxn],vis[maxn];
struct Query
{
    int l,r;
    int id;
}q[maxn];
struct Rule
{
	inline bool operator()(const Query& t1,const Query& t2)
	{
		if(t1.r!=t2.r) return t1.r<t2.r;
		if(t1.l!=t2.l) return t1.l<t2.l;
		return t1.id<t2.id;
	}
};
int lowbit(int p)
{
    return p&(-p);
}
void add(int p,int x)
{
    while(p<=n){
        tree[p]+=x;
        p+=lowbit(p);
    }
    return;
}
int query(int p)
{
    int ans=0;
    while(p!=0){
        ans+=tree[p];
        p-=lowbit(p);
    }
    return ans;
}
inline int read()
{
    int x=0,f=1;
    char ch=getchar();
    while(ch<'0' || ch>'9'){
        if(ch=='-') f=-1;
        ch=getchar();
    }
    while(ch>='0' && ch<='9'){
        x=x*10+ch-'0';
        ch=getchar();
    }
    return x*f;
}
int main()
{
	//ios_base::sync_with_stdio(false);
    //cin.tie(0);
    //cout.tie(0);
    n=read(),m=read();
    for(int i=1;i<=n;i++) a[i]=read();
    for(int i=1;i<=m;i++){
        q[i].l=read();
        q[i].r=read();
        q[i].id=i;
    }
    sort(q+1,q+1+m,Rule());
    int nxt=1;
    for(int i=1;i<=m;i++){
        for(int j=nxt;j<=q[i].r;j++){
            if(vis[a[j]]) add(vis[a[j]],-1);
                add(j,1);
                vis[a[j]]=j;
        }
        nxt=q[i].r+1;
        res[q[i].id]=query(q[i].r)-query(q[i].l-1);
    }
    for(int i=1;i<=m;i++) printf("%d\n",res[i]);
	return 0;
}


Measured memory_bytes: 17464
//Tonight's the night and it is going to happen again and again.
//this solution was copied from youtube solution but now i understand this fully as
//of this date
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define T ll t; cin>>t; while(t--)
#define mod 998244353
#define inf 1000000000000000000
#define mem(name,val) memset(name,val,sizeof(name))
#define f(n) for(ll i=0;i<n;i++)
#define rep(i,a,n) for(ll i=a;i<n;i++)
#define endl "\n"
ll gcd(ll a,ll b){if(b==0){return a;}return gcd(b,a%b);}
int main()
{
   ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
   #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
   #endif
   ll n,k;cin>>n>>k;
   ll l[k],r[k];
   f(k)
   {
    cin>>l[i]>>r[i];
   }
   ll dp[n+1];mem(dp,0);ll dpsum[n+1];mem(dpsum,0);dpsum[1]=1;dp[1]=1;
   for(ll i=2;i<=n;i++)
   {
    for(ll j=0;j<k;j++)
    {
       ll li=i-r[j];
       ll ri=i-l[j];
       if(ri<0){continue;}
       li=max(li,1ll);
       dp[i]+=dpsum[ri]-dpsum[li-1];
       if(dp[i]<0){dp[i]+=mod;}
       else{
       dp[i]%=mod;
         }
     }
     dpsum[i]=(dpsum[i-1]+dp[i])%mod;
    }
    //for(auto t:dp){cout<<t<<" ";}
    cout<<dp[n]%mod<<endl; 
}

Measured memory_bytes: 6748
#include<bits/stdc++.h>
using namespace std;
#define ll long long                                    // long long省略
#define pb push_back                                    // push_back省略
#define mp make_pair                                    // make_pair省略
#define fi first                                        // first省略
#define se second                                       // second省略
#define itn int                                         // int誤字保険
#define count cout                                      // cout誤字保険
#define vecotr vector                                   // vector誤字保険
#define ednl endl                                       // endl誤字保険
#define opt() cin.tie(0); ios::sync_with_stdio(false)   // 入出力速度改善

#define rep(i,l,r) for(ll i=(l);i<(r);i++)               // 範囲[l, r)で刻み1のfor文(順方向)
#define repp(i,l,r,k) for(ll i=(l);i<(r);i+=(k))         // 範囲[l, r)で刻みkのfor文(順方向)
#define rrep(i,l,r) for(ll i=(r-1);i>=(l);i--)           // 範囲[l, r)で刻み1のfor文(逆方向)
#define rrepp(i,l,r,k) for(ll i=(r-1);i>=(l);i-=(k))     // 範囲[l, r)で刻みkのfor文(逆方向)
#define all(x) (x).begin(), (x).end()                   // vectorのポインタ位置指定用
#define max(p,q)((p)>(q)?(p):(q))                       // max拡張
#define min(p,q)((p)<(q)?(p):(q))                       // min拡張
#define bit(n,m)(((n)>>(m))&1)                          // 変数nのm番目のbitを取り出す

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

int dy[]={0, 1, 0, -1};                                 // 4方向近傍
int dx[]={1, 0, -1, 0};                                 // 4方向近傍

int main(){
  	ll r,d,x;cin>>r>>d>>x;
    ll ans = x;
    rep(i,0,10){
        ans = r*ans - d;
        cout << ans << ednl;
    }


}


Measured memory_bytes: 256
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<iostream>
using namespace std;
 
int x[1000000];
int main(){
int N;
cin>>N;
for(int i=0;i<N*2;i++)
cin>>x[i];
sort(x,x+2*N);
int ans=0;
for(int i=0;i<2*N;i+=2)
ans+=x[i];
cout<<ans<<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<ll,ll> pll;
typedef pair<double,double> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#ifdef leowang
#define debug(...) do{\
	fprintf(stderr,"%s - %d : (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
	_DO(__VA_ARGS__);\
}while(0)
template<typename I> void _DO(I&&x){cerr<<x<<endl;}
template<typename I,typename...T> void _DO(I&&x,T&&...tail){cerr<<x<<", ";_DO(tail...);}
#else
#define debug(...)
#endif
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}
//}}}
const ll maxn=300005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=2000000000;
const ll MOD=ll(1e9+7);
const double PI=acos(-1);
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		b>>=1;
	}
	return res;
}

ll A[maxn];
int main()
{
	IOS;
    int n;
    cin>>n;
    ll a,b;
    cin>>a>>b;
    REP(i,n) cin>>A[i];
    
    ll ans=0;
    REP(i,n-1){
        ans+=min(b,a*(A[i+1]-A[i]));
    }
    cout<<ans<<'\n';
	return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cassert>
#include <vector>
#include <string>
#include <cmath>
#include <map> 
#include <sstream>
using namespace std;
 
const int MAX= 10000100;

#define loop(i,a,b) for(int i = a ; i < b ; i ++)
#define rep(i,a) loop(i,0,a)
#define all(a) (a).begin(),(a).end()
#define ll long long int
#define gcd(a,b) __gcd(a,b)

int GCD(int a, int b) {if(!b) return a; return gcd(b, a%b);}
int lcm(int a, int b) {return a*b / gcd(a, b);}

int main(void){
  map<int,int> mf,ms;
  string str;
  int cn,a,b;
  while(getline(cin,str),str.size()){
    stringstream ss;
    rep(i,str.size()){
      if(str[i]==',') str[i] = ' ' ;
    }
    ss << str;
    ss >> a;
    mf[a]++;
    ss.str("");
    
  }
  while(scanf("%d,%d",&a,&b)!=EOF){
    if(mf[a]!=0){
      if(ms[a]==0)ms[a]+=mf[a];
      ms[a]++;
    }
  }
  map<int,int>::iterator it = ms.begin();
  while(it!=ms.end()){
    cout << it->first << ' ' << it->second << endl;
    it ++;
  }
}

Measured memory_bytes: 1284
/* basic header */
#include <bits/stdc++.h>
/* define */
#define ll long long
#define dou double
#define pb emplace_back
#define mp make_pair
#define sot(a,b) sort(a+1,a+1+b)
#define rep1(i,a,b) for(int i=a;i<=b;++i)
#define rep0(i,a,b) for(int i=a;i<b;++i)
#define eps 1e-8
#define int_inf 0x3f3f3f3f
#define ll_inf 0x7f7f7f7f7f7f7f7f
#define lson curPos<<1
#define rson curPos<<1|1
/* namespace */
using namespace std;
/* header end */

const int maxn = 60;
int a[maxn], now[maxn], ans = 0, n, m;

int main() {
    scanf("%d%d", &n, &m);
    rep1(i, 1, n) scanf("%d", &a[i]);
    for (int i = 1; i <= min(n, m); i++) {
        rep1(j, 0, i) {
            rep1(k, 0, n) now[k] = 0;
            int cnt = 0;
            rep1(k, 1, i - j) now[++cnt] = a[k];
            rep1(k, 1, j) now[++cnt] = a[n - k + 1];
            sot(now, i);
            int tot = m - i, sum = 0, x = 1;
            while (tot && now[x] < 0) x++, tot--;
            for (; x <= i; x++) sum += now[x];
            ans = max(ans, sum);
        }
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <utility>
#include <numeric>

using namespace std;
typedef long long llong;
typedef unsigned long long ullong;

const ullong MOD = 1000000000 + 7;

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

	int cnt = 0;
	for (int i = a; i <= b; i++)
	{
		string s0 = to_string(i);
		string s1 = s0;
		reverse(s1.begin(), s1.end());

		if (s0 == s1)
		{
			cnt++;
		}
	}

	cout << cnt << endl;
}

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

using namespace std;

int n;
int w[4005],b[4005];
int aa[4005][4005],bb[4005][4005],dp[4005][4005];

int main(){
	cin>>n;
	for(int i=1;i<=2*n;i++){
		int d;
		char c;
		cin>>c>>d;
		if(c=='W') w[d]=i;
		else b[d]=i;
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			aa[i][j]=aa[i][j-1]+(w[j]>b[i]);
			bb[i][j]=bb[i][j-1]+(b[j]>w[i]);
		}
	}
	for(int i=0;i<=n;i++) for(int j=0;j<=n;j++) dp[i][j]=1e9+7;
	dp[0][0]=0;
	for(int i=0;i<=n;i++){
		for(int j=0;j<=n;j++){
			if(i<n) dp[i+1][j]=min(dp[i+1][j],dp[i][j]+aa[i+1][j]);
			if(j<n) dp[i][j+1]=min(dp[i][j+1],dp[i][j]+bb[j+1][i]);
		}
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<i;j++) dp[n][n]+=(w[i]<w[j])+(b[i]<b[j]);
	}
	cout<<dp[n][n]<<endl;
	return 0;
}

Measured memory_bytes: 98048
import itertools
N = int(input())
X = [0] * N
Y = [0] * N
acc = 0
c = len(list(itertools.combinations(range(N), 2)))
for i in range(N):
    x, y = map(int, input().split())
    X[i] = x
    Y[i] = y
for p in itertools.permutations(range(N), 2):
    a = p[0]
    b = p[1]
    acc += ((X[a] - X[b]) ** 2 + (Y[a] - Y[b]) ** 2) ** (1/2)
print(acc/c*(N-1)/2)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define SIZE 200005
#define INF 1000000005LL
#define MOD 1000000007

using namespace std;
typedef long long int ll;
typedef pair <int,int> Pp;
typedef pair <int,Pp> P; //距離、座標

int h,w;

int a[1005][1005];

int main(){
  cin >> h >> w;
  priority_queue<P,vector<P>,greater<P>> que;
  rep(i,0,h) {
    string s;
    cin >> s;
    rep(j,0,w) {
      a[i][j] = (s[j]=='.'?0:1);
      if(s[j]=='#'){
        que.push(P(1,Pp(i,j)));
      }
    }
  }
  int l;
  while(!que.empty()){
    int x,y,c;
    P f = que.top();que.pop();
    c = f.first;
    l = c;
    x = f.second.first;
    y = f.second.second;
    if(x>0) if(a[x-1][y]==0){
      que.push(P(c+1,Pp(x-1,y)));
      a[x-1][y]=c+1;
    }
    if(y>0) if(a[x][y-1]==0){
      que.push(P(c+1,Pp(x,y-1)));
      a[x][y-1]=c+1;
    }
    if(x<h-1) if(a[x+1][y]==0){
      que.push(P(c+1,Pp(x+1,y)));
      a[x+1][y]=c+1;
    }
    if(y<w-1) if(a[x][y+1]==0){
      que.push(P(c+1,Pp(x,y+1)));
      a[x][y+1]=c+1;
    }
  }

  cout << l-1 << endl;


  return 0;
}


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

typedef long long int ll;
typedef unsigned long long int ull;
#define rep(i,n) for(auto i=0;i<(n);i++)
#define rep1(i,n) for(auto i=1;i<=(n);i++)
#define all(x) (x).begin(),(x).end()

using namespace std;


struct init{ init(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20); }; }aaaaaaa;
int dy[]={1, 0, -1, 0, 0};
int dx[]={0, 1, 0, -1, 0};


int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];

    ll sum = 0;
    rep(i, n) sum += a[i];
    ll oneSum = (1ll+n)*n/2;
    ll k = sum/oneSum;
    if(sum%oneSum != 0 || k <= 0){
        cout << "NO" << endl;
        return 0;
    }

    set<int> d;
    rep(i, n-1) d.insert(a[i]-a[i+1]);
    d.insert(a[n-1]-a[0]);

    for(auto x : d) d.erase(x), d.insert(x+k);    

    for(auto x : d){
        if(x < 0 || x%n != 0){
            cout << "NO" << endl;
            return 0;
        }
    }

    cout << "YES" << endl;


    return 0;
}



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

#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (ll i = m; i < (n); i++)

using ll = long long;
using pii = pair<int, int>;
using Vi = vector<int>;



  
int main() {
  int a,b;
  cin >> a >> b;
  if((a>b||a==1)&&b!=1) cout << "Alice" << endl;
  else if(a==b) cout << "Draw" << endl;
  else cout << "Bob" << endl;
}
      
       





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

int main() {
  //入力値取得
  int N;	cin >> N;
  vector<int> card(N);
  for(int i=0; i<N; i++){
    cin >> card.at(i);
  }
  
  //順番
  int turn = 0;	//余り0…Alice, 1…Bob
  
  //Alice, Bob獲得点数格納
  int score_Alice = 0;
  int score_Bob = 0;
  
  //残り回数
  int times = N;
  
  while(times){
    //最大値検索
    int max = 0;
    int get_max_i = -1;
    for(int i=0; i<N; i++){
      if(card.at(i) > max){
        max = card.at(i);
        get_max_i = i;
      }
    }

    //最大値カード抜き出し
    if(turn % 2 == 0)
      score_Alice += card.at(get_max_i);
    else
      score_Bob += card.at(get_max_i);
    
    //チェック用
    //cout << "Alice:" << score_Alice << endl;
    //cout << "Bob:" << score_Bob << endl;
    
    //更新
    card.at(get_max_i) = -1;
    times--;
    turn++;
  }
  
  cout << score_Alice - score_Bob << endl;
  
  //cout << get_max_i << endl;
  //cout << score_Alice << endl;
}


Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            var l = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int a = l[0], b = l[1], c = l[2];
            Console.WriteLine(a==b&&b==c?"Yes":"No");
        }
    }
}


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

// int/long:		-2,147,483,648 - 2,147,483,647 (-2^31 <= int < 2^31)
// long/long long:	-9,223,372,036,854,775,808 - 9,223,372,036,854,775,807 (-2^63 <= long < 2^63)

// lower_bound(A.begin(), A.end(), N)
// upper_bound(...

// A.erase(unique(A.begin(), A.end()), A.end())

// bit: &/and, |/or, ^/xor, ~/not

// getline(cin, String)
// while (getline(cin, S)) {}

// #include <cstdio>
// int a;
// scanf("%d", &a);
// printf("%d\n", a);
//
// for (int i=0; i<n; ++i)
// 	scanf("%d", &a[i]);
//
// char c;
// scanf(" %c", &c);
//
// cout << "\n";

// cout <<fixed <<setprecision(10)

// priority_queue<int> q;
// priority_queue<int, vector<int>, less<int>> q; // Default: vector, less
// priority_queue<vector<int>, vector<vector<int>>, greater<vector<int>>> q;

// Graph
// Warshall-Floyd: Distance between each node, N^3
// Dijkstra: Distance from the start node, N^2
// DFS(Depth-First Search)

//
// Notes
//
// When specified less than N, try full scan.
// RE: empty vector
// Check Qs
// long/int
// xor -> count each bit
// Check values
// 	1,000,000 -> Loop
// 	100,000	-> vector(int:400KB, long:800KB) 

#define	INF (1<<30)
//1,073,741,824
//= 536,870,912 *2

#define	MOD 1000000007

/*
ll	myPow(ll x, ll n) {
	if (0==n)
		return 1;
	if (0==n%2)
		return myPow(x*x%MOD, n/2);
	else
		return x*myPow(x, n-1)%MOD;
}
*/
ll	myPow(ll x, ll n) {
	ll r=1;
	while(n>0)
		if (0==n%2) {
			x *=x;
			x %=MOD;
			n /=2;
		} else {
			r *=x;
			r %=MOD;
			n--;
		}
	return r;
}

#define	Rep0(i, n)	for (int i=0; i<n; i++)
#define	Rep1(i, n)	for (int i=1; i<=n; i++)
#define Sort(P)	sort(P.begin(), P.end())
#define Rev(P)	reverse(P.begin(), P.end())

int	main() {
	string S;
	cin >>S;
	if ((S.at(3)==S.at(2))&&(S.at(4)==S.at(5)))
		cout <<"Yes" <<endl;
	else
		cout <<"No" <<endl;
	return 0;
}



Measured memory_bytes: 256
import { readFileSync } from 'fs'
import { reverse } from 'dns'
import { start } from 'repl'
 
let lines: string[] = [];
const reader = require('readline').createInterface({
    input: process.stdin,
    output: process.stdout
});
 
reader.on('line', function (line: string) {
    lines.push(line);
});
reader.on('close', function () {
    let S = lines[0]
    let tmp = 0

    for(let i = 0; i< S.length; i++) {
        tmp += parseInt(S[i], 10)
    }

    if(tmp % 9 == 0) {
        console.log('Yes')
    } else {
        console.log('No')
    }
});

Measured memory_bytes: 33180
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;using vvi=vector<vi>;using vl=vector<ll>;
using P=pair<int,int>;using PL=pair<ll,ll>;using vp=vector<P>;
const int INF=1<<30,MOD=1000000007;const ll LINF=1ll<<60;
#define _ol3(_1,_2,_3,name,...) name
#define _rep(i,n) _repi(i,0,n)
#define _repi(i,a,b) for(int i=a,i##_l=(b);i<i##_l;++i)
#define REP(...) _ol3(__VA_ARGS__,_repi,_rep,)(__VA_ARGS__)
#define REPR(i,n) for(int i=n-1;i>=0;--i)
#define REPA(i,v) REP(i,v.size())
#define all(v) (v).begin(),(v).end()
#define bit(n) (1ll<<(n))
#define clamp(n,mi,ma) max(min(n,ma),mi)
#define uniq(v) sort(all(v));v.erase(unique(all(v)),v.end())
#define pb push_back
#define F first
#define S second
#define endl '\n'
#define cho(n,a,b) cout<<((n)?a:b)<<endl
#define YES(n) cho(n,"YES","NO")
#define Yes(n) cho(n,"Yes","No")
#define Poss(n) cho(n,"Possible","Impossible")
template<class T>bool chmax(T&a,const T&b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T&a,const T&b){if(a>b){a=b;return 1;}return 0;}
template<class T>ostream&operator<<(ostream&o,const vector<T>&v){for(const T&i:v)o<<i<<' ';return o;}
template<class T>istream&operator>>(istream&i,vector<T>&v){for(T&j:v)i>>j;return i;}
template<class T,class U>ostream&operator<<(ostream&o,const pair<T,U>&p){return o<<p.F<<' '<<p.S;}
template<class T,class U>istream&operator>>(istream&i,pair<T,U>&p){return i>>p.F>>p.S;}
template<class T>ostream&operator<<(ostream&o,const set<T>&v){for(const T&i:v)o<<i<<' ';return o;}
template<class T>ostream&operator<(ostream&o,const T&t){return o<<t;}
template<class T>istream&operator>(istream&i,T&t){return i>>t;}
#ifndef LOCAL
struct ostdmy{
template<class T>ostdmy&operator<<(const T&t){return*this;}
template<class T>ostdmy&operator<(const T&t){return*this;}};ostdmy cer_;
#define cerr cer_
#endif
int main(){
    cin.tie(0);ios::sync_with_stdio(0);
    int a,b,c;
    cin>a>b>c;
    Yes(a==b&&b==c);
    return 0;
}

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

using namespace std;

int main() {
  int h, w, d;
  int px[100005], py[100005];
  int dist[90004] = {0};

  cin >> h >> w >> d;

  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      int a; cin >> a;
      --a;
      px[a] = j;
      py[a] = i;
    }
  }

  for (int i = 0; i < d; i++) {
    for (int j = i; j < h*w; j+=d) {
      if (j-d < 0) {
        continue;
      } else {
        dist[j] += dist[j-d] + abs(px[j]-px[j-d]) + abs(py[j]-py[j-d]);
      }
    }
  }

  int q;
  cin >> q;

  while (q--) {
    int l, r;
    cin >> l >> r;
    --l; --r;
    cout << dist[r] - dist[l] << endl;;
  }

  return 0;
}

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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)
#define mp make_pair

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int64 n;
    cin >> n;
    int64 ans = LLINF;
    for(int64 i = 1; i * i <= n; i++){
        if(n % i == 0){
            ans = min(ans, i + n / i - 2);
        }
    }
    ANS(ans);
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		long a = sc.nextLong();
		long b = sc.nextLong();
		long c = sc.nextLong();
		long d = sc.nextLong();
		long bb = b - b/c - b/d + b/lcm(c,d);
		long aa = a - a/c - a/d + a/lcm(c,d);
		long ans = bb-aa;
		if(a%c != 0 && a%d != 0) {
			ans ++;
		}
		if(b < c && b < d) {
			ans += 1;
		}
		System.out.println(ans);
		sc.close();
	}
	private static long lcm(long m, long n) {
	    return m * n / gcd(m, n);
	}
	private static long gcd(long m, long n) {
	    if(m < n) return gcd(n, m);
	    if(n == 0) return m;
	    return gcd(n, m % n);
	}
}


Measured memory_bytes: 22996
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using static System.Console;
using static System.Math;
using static MyIO;
using static MyUtil;

public class B
{
	public static void Main() => (new Solver()).Solve();
}

public class Solver
{
	public void Solve()
	{
		int N = GetInt();
		long cnt = 0;
		for(int i = 1; i <= N; i++)
		{
			if(i % 3 == 0 || i % 5 == 0)
				continue;
			
			cnt += (long)i;
		}
		WriteLine(cnt);
	}
}

public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt() => int.Parse(getArg());
	public static long GetLong() => long.Parse(getArg());
	public static double GetDouble() => double.Parse(getArg());
	public static decimal GetDecimal() => decimal.Parse(getArg());
	public static string GetString() => getArg();
	public static char GetChar() => getArg()[0];
	public static int[] GetInts(long N) => Enumerable.Range(0, (int)N).Select(_ => GetInt()).ToArray();
	public static long[] GetLongs(long N) => Enumerable.Range(0, (int)N).Select(_ => GetLong()).ToArray();
	public static double[] GetDoubles(long N) => Enumerable.Range(0, (int)N).Select(_ => GetDouble()).ToArray();
	public static decimal[] GetDecimals(long N) => Enumerable.Range(0, (int)N).Select(_ => GetDecimal()).ToArray();
	public static string[] GetStrings(long N) => Enumerable.Range(0, (int)N).Select(_ => GetString()).ToArray();
}

public static class MyUtil
{
	public static void chmax<T>(ref T x, T y) where T : IComparable<T>
	{
		if(x.CompareTo(y) < 0)
			x = y;
	}

	public static void chmin<T>(ref T x, T y) where T : IComparable<T>
	{
		if(x.CompareTo(y) > 0)
			x = y;
	}

	public static void swap<T>(ref T x, ref T y)
	{
		T tmp = x;
		x = y;
		y = tmp;
	}
}

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


bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}


int main(){
  int n;
  cin>>n; 
  while(!IsPrime(n)){n++;}
  cout<<n<<endl;
}
    
  
  

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;
typedef char CHAR;
typedef unsigned char UCHAR;
typedef short SHORT;
typedef unsigned short USHORT;
typedef int INT;
typedef unsigned int UINT;
typedef long long LLONG;
typedef unsigned long long ULLONG;

#define LengthOf(x)    (sizeof(x) / sizeof(x[0]))


#if 1
//No.2
int main()
{
	LLONG X;
	LLONG cur = 100;
	INT year = 0;
	cin >> X;

	while (cur < X) {
		cur = cur * 1.01;
		year += 1;
	}

	cout << year;
	return 0;
}
#endif


Measured memory_bytes: 3636
n = int(input())

li = []
for i in range(n):
    a = input().split()
    li.append([a[0],int(a[1]),i+1])

li = sorted(li, key=lambda x:(x[0], -x[1]))
#print(li)
for i in range(n):
    print(li[i][2])

Measured memory_bytes: 3060
#include<cstdio>
    using namespace std;
    int main()
    {
    	char A,B,C,D,E,F;
    	scanf(" %c%c%c ",&A,&B,&C);
    	scanf(" %c%c%c ",&D,&E,&F);
    	if(A==F&&B==E&&C==D)
    		printf("YES\n");
    	else
    		printf("NO\n");
    }

Measured memory_bytes: 128
if __name__ == "__main__":
    button = input()
    button = button.split(" ")
    button1 ,button2 = int(button[0]),int(button[1])
    total = 0
    for x in range(2):
        if button1>button2:
            total+=button1
            button1-=1
        else:
            total+=button2
            button2-=1
    print(total)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define len(v) ll(v.size())

template <class T>
void cout_vec(const vector<T> &vec){
  for(auto itr:vec) cout<<itr<<' ';
  cout<<'\n';
}

typedef pair<ll,ll> P;
const ll mod=1e9+7;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int x,a;
    cin>>x>>a;
    if(x<a) cout<<0<<endl;
    else cout<<10<<endl;
}

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

using namespace std;

#define int long long

struct Line{
	int a,b;
	mutable int p;
	bool type;
	bool operator<(const Line &l) const{
		if(!l.type) return a<l.a;
		else return p<l.p;
	}
};

struct CHT : multiset<Line,less<Line>> {
	const int inf = 1e18;
	int div(int a,int b){
		return a/b - ((a^b)<0 && a%b);
	}
	bool isect(iterator x, iterator y){
		if(y==end()){
			x->p = inf;
			return false;	
		}else if(x->a==y->a) x->p = (x->b>y->b ? inf : -inf);
		else x->p = (y->b-x->b)/(x->a-y->a);
		return x->p >= y->p;
	}
	void add(int a,int b){
		auto z = insert({a,b,0,0}), y = z++, x = y;
		while(isect(y,z)) z = erase(z);
		if(x!=begin() && isect(--x,y)) isect(x,y = erase(y));
		while((y=x)!=begin() && (--x)->p>=y->p) isect(x, erase(y));
	}
	int query(int x){
		auto l = *lower_bound({0,0,x,1});
		return -(l.a*x + l.b);
	}
};

const int N = 2e5+2;

int c, h[N], dp[N];

signed main(){
	CHT hull;
	int n, c;
	cin >> n >> c;
	for(int i=0;i<n;++i) cin >> h[i];
	dp[0] = 0;
	
	hull.add(2*h[0],-h[0]*h[0]-c);
	for(int i=1;i<n;++i){
		dp[i] = h[i]*h[i] + hull.query(h[i]);
		hull.add(2*h[i],-h[i]*h[i]-c-dp[i]);
	}
	cout << dp[n-1];
}

Measured memory_bytes: 22124
def inp():
    return input()
def iinp():
    return int(input())
def inps():
    return input().split()
def miinps():
    return map(int,input().split())
def linps():
    return list(input().split())
def lmiinps():
    return list(map(int,input().split()))
def lmiinpsf(n):
    return [list(map(int,input().split()))for _ in range(n)]

l = iinp()
ans = 0

k = (l/3)

ans = k**3

print(ans)

Measured memory_bytes: 3060
//Love and Freedom.
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#define ll long long
#define inf 20021225
#define N 100100
using namespace std;
int read()
{
	int s=0,f=1; char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-') f=-1; ch=getchar();}
	while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
	return f*s;
}
ll f[N],mn; int t,e,n,p[N];
int main()
{
	n=read(),e=read(),t=read();
	int l=0; mn=1e18;
	for(int i=1;i<=n;i++)	p[i]=read();
	for(int i=1;i<=n;i++)
	{
		while(l<=i && 2*(p[i]-p[l+1])>t)
			mn=min(mn,f[l]-2*p[l+1]), l++;
		if(l<i)	f[i]=f[l]+t;
		f[i]=min(f[i],mn+2*p[i]);
	}
	printf("%lld\n",f[n]+e);
	return 0;
}

Measured memory_bytes: 1280
#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;
    int D, X;
    cin >> D >> X;
    int res = 0;
    rep(i, N) {
        int a;
        cin >> a;
        res += 1 + (D - 1) / a;
    }
    cout << res + X << endl;
    return 0;
}

Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
inline int rd() {int r;scanf("%d",&r);return r;}
int main() {
    int a = rd(), b = rd();
    if (1LL * a * b <= 0) {
        puts("Zero");
        return 0;
    }
    if (a>0) {
        puts("Positive");
        return 0;
    }
    a = abs(a);
    if (b < 0) a -= abs(b+1);
    puts(a&1 ? "Negative" : "Positive");
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
using namespace std;
int main(void){
  int N,M,C;
  cin >> N >> M >> C;
  int a[20][20],b[20];
  for(int i = 0;i < M; ++i){
    cin >> b[i];
  }
  for(int s = 0;s < N; ++s){
      for(int i = 0;i < M; ++i){
        cin >> a[s][i];
      }
    }
    int ans = 0;
    for(int s = 0;s < N; ++s){
      int tot = 0;
        for(int i = 0;i < M; ++i){
          tot += b[i]*a[s][i];
        }
        if(tot > -C)
         ans++;
      }

  cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

int main(){
	char S[20],T[20],U[20];
	int A,B;
	
	scanf("%s %s",S,T);
	scanf("%d %d",&A,&B);
	scanf("%s",U);
	
	if(strcmp(U,S)==0){
		A = A-1;
	}
	else B=B-1;
	
	printf("%d %d",A,B);
		
	return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>

using namespace std;

int main()
{
    long long int N;
    cin>>N;
    vector<long long int>A(N);
    for(long long int i=0;i<N;i++){
        cin>>A[i];
    }
    for(long long int i=0;i<N;i++){
        if(A[i]==0){
            cout<<0<<endl;
            exit(0);
        }
    }
    long long int ans=1;
    for(long long int i=0;i<N-1;i++){
        ans*=A[i];
        if((1000000000000000000/ans)+1<A[i+1]){
            cout<<-1<<endl;
            exit(0);
        }
    }
    long long int Ans=1;
    for(long long int i=0;i<N;i++){
        Ans*=A[i];
         if(Ans>1000000000000000000){
            cout<<-1<<endl;
            exit(0);
        }
    }
    cout<<Ans<<endl;
}

Measured memory_bytes: 4328
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder
{
    class Abc165C
    {

        static int n;
        static int m;
        static int q;
        static int[][] abcd;
        static int[] a;

        public static void Main()
        {
            var nmq = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
            n = nmq[0];
            m = nmq[1];
            q = nmq[2];
            a = Enumerable.Repeat(1, n).ToArray();
            abcd = new int[q][];
            for (int i = 0; i < q; i++)
                abcd[i] = Console.ReadLine().Split(' ').Select(j => int.Parse(j)).ToArray();

            long max = 0;
            while (a[0] == 1)
            {
                long point = 0;
                for (int i = 0; i < q; i++)
                    if (a[abcd[i][1] - 1] - a[abcd[i][0] - 1] == abcd[i][2])
                        point += abcd[i][3];
                if (max < point)
                    max = point;
                int j = n - 1;
                while (j > 0 && a[j] == m)
                    j--;
                int value = ++a[j];
                while (++j < n)
                    a[j] = value;
            }
            Console.WriteLine(max);
        }
    }
}

Measured memory_bytes: 28260
#include <iostream>
using namespace std;
int main(){
    int k,n;
    cin>>k>>n;
    int a[n];
    int sum=0,max=-1;
    for (int i=0; i<n; i++){
        cin>>a[i];
        if (i!=0) sum+=(a[i]-a[i-1]);
        if (i!=0&&a[i]-a[i-1]>max) max=a[i]-a[i-1];
    }
    sum+=a[0]+k-a[n-1];
    if (a[0]+k-a[n-1]>max) max=a[0]+k-a[n-1];
    cout<<sum-max;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
using namespace std;
typedef long long ll;
ll a,b,c,k;
int main()
{
    while (scanf("%lld%lld%lld%lld",&a,&b,&c,&k)!=EOF) {
        if(k%2)printf("%lld\n",b-a);
        else printf("%lld\n",a-b);
    }
    return 0;
}

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

public class Main implements Runnable{
    static Scanner sc = new Scanner(System.in);
    static PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args) throws IOException{
        new Thread(null, new Main(), "", 32 * 1024 * 1024).start();
        Thread.setDefaultUncaughtExceptionHandler((t,e)->System.exit(1));
        out.flush();
    }

    public void run(){
        int N = Integer.parseInt(sc.next());
        int M = Integer.parseInt(sc.next());
        int[] A = new int[M];
        int result = N;
        for(int i = 0; i < M; i++){
            A[i] = Integer.parseInt(sc.next());
        }
        for(int i = 0; i < M; i++){
            result = result - A[i];
        }
        if(result < 0){
            result = -1;
        }
        out.println(result);
        out.flush();
    }

}

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

void print_vec(vector<int> vec)
{
  cout << "[";
  for (int i = 0; i < vec.size(); i++)
  {
    cout << vec.at(i);
    if (i < vec.size() - 1)
    {
      cout << ", ";
    }
  }
  cout << "]...size: " << vec.size() << endl;
}

int main()
{
  vector<pair<int, int>> vec;

  while (true)
  {
    int x, y;
    cin >> x >> y;

    if (x == 0 && y == 0)
    {
      break;
    }

    if (x > y)
    {
      swap(x, y);
    }

    vec.push_back(make_pair(x, y));
  }

  rep(i, vec.size())
  {
    int x, y;
    x = vec.at(i).first;
    y = vec.at(i).second;
    printf("%d %d\n", x, y);
  }
}



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

using namespace std;

#define int long long
#define N 100005
#define MOD 1000000007

int ans[N];

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

    int ans = 0;
    if( k == 0)
    {
        ans = n*n;
        cout<<ans<<endl;
        return 0;
    }
    for(int i=k+1;i<=n;i++)
    {
        int temp = n/i;
        ans+= (i-k)*temp;
        temp = n%i;
        if( temp>=k && temp)
            ans+= (temp - k + 1);
    }
    cout<<ans<<endl;

    return 0;
}

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

#define all(container) container.begin(), container.end()
#define sortall(container) (sort(container.begin(), container.end()))
#define yn(cond) ((cond) ? (cout << "yes" << endl) : (cout << "no" << endl))
#define Yn(cond) ((cond) ? (cout << "Yes" << endl) : (cout << "No" << endl))
#define YN(cond) ((cond) ? (cout << "YES" << endl) : (cout << "NO" << endl))

typedef long long       ll;

typedef vector<int>     vi;
typedef vector<ll>      vll;
typedef vector<double>  vd;
typedef vector<bool>    vb;
typedef vector<char>    vc;
typedef vector<string>  vs;
typedef pair<int, int>  pii;
typedef pair<ll, ll>    pll;
typedef vector<vi>		vvi;
typedef vector<vll>		vvll;
typedef vector<vd>		vvd;
typedef vector<vb>		vvb;
typedef vector<vc>		vvc;
typedef vector<vs>		vvs;
typedef vector<pii>     vpii;
typedef vector<pll>     vpll;

typedef struct edge_ {
	ll to;
	ll cost;
} edge;

typedef struct point_ {
	ll x, y;
	point_(ll x = 0, ll y = 0) : x(x), y(y) {}
} point;

template <typename T>
using mat2d = vector<vector<T>>;

constexpr double	PI = 3.14159265358979323846;
constexpr ll		INF = 1 << 15;
constexpr ll		MOD = (ll)1e9 + 7;
constexpr double	EPS = 1e-7;
constexpr int		dy4[4] = { 0, 1, 0, -1 };
constexpr int		dx4[4] = { 1, 0, -1, 0 };
constexpr int		dy8[8] = { 0, 1, 1, 1, 0, -1, -1, -1 };
constexpr int		dx8[8] = { 1, 1, 0, -1, -1, -1, 0, 1 };

template<typename T>
istream& operator >> (istream& is, vector<T>& vec) {
	for (T& x : vec) is >> x;
	return is;
}

template<typename T>
ostream& operator << (ostream& os, const vector<T>& vec) {
	for (const T& x : vec) os << x << " ";
	return os;
}

template<typename S, typename T>
istream& operator >> (istream& is, pair<S, T>& p) {
	is >> p.first >> p.second;
	return is;
}

istream& operator >> (istream& is, point& p) {
	is >> p.x >> p.y;
	return is;
}

template<typename S, typename T>
ostream& operator << (ostream& os, const pair<S, T>& p) {
	os << "{" << p.first << " : " << p.second << "}";
	return os;
}

template<typename T>
ostream& operator << (ostream& os, const set<T>& s) {
	for (const T& x : s) os << x << " ";
	return os;
}

ostream& operator << (ostream& os, const edge e) {
	os << "{to: " << e.to << ", cost: " << e.cost << "}";
	return os;
}

ostream& operator << (ostream& os, const point& p) {
	os << "(" << p.x << " " << p.y << ")";
	return os;
}

/******************************************************************************/
/**********************         Don't make WA !!         **********************/
/******************************************************************************/

int main()
{
	int N, M;
	cin >> N >> M;
	vpii ab(N), cd(M);
	cin >> ab >> cd;

	for (int n = 0; n < N; n++) {
		ll mind = LLONG_MAX;
		int ans;
		for (int m = 0; m < M; m++) {
			if (abs(ab[n].first - cd[m].first) + abs(ab[n].second - cd[m].second) < mind) {
				ans = m + 1;
				mind = abs(ab[n].first - cd[m].first) + abs(ab[n].second - cd[m].second);
			}
		}

		cout << ans << endl;
	}

	
	return 0;
}

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

int main() {
  int m, f, r;
  while (true) {
    cin >> m >> f >> r;
    if (m == -1 && f == -1 && r == -1) break;

    char grade;
    int sum = m + f;
    if (m == -1 || f == -1 || sum < 30) grade = 'F';
    else if (sum >= 80) grade = 'A';
    else if (sum >= 65) grade = 'B';
    else if (sum >= 50 || r >= 50) grade = 'C';
    else grade = 'D';
    
    cout << grade << endl;
  }
    
  return 0;
}


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

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

	vector<LL> pe(n);

	for (LL i = 0; i < n; ++i) {
		pe[i] = i+1;
	}

	LL a = 0, b = 0;
	vector<LL> p(n), q(n);

	for (auto &e : p) {
		cin >> e;
	}

	for (auto &e : q) {
		cin >> e;
	}

	LL j = 1;

	while (next_permutation(pe.begin(), pe.end())) {
		bool isa = true, isb = true;
		for (LL i = 0; i < n; ++i) {
			if (p[i] != pe[i]) {
				isa = false;
			}
			if (q[i] != pe[i]) {
				isb = false;
			}
		}
		if (isa) {
			a = j;
		}
		if (isb) {
			b = j;
		}
		j++;
	}

	cout << abs(b-a) << "\n";



}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define ll long long
#define rep2(i,a,b) for(int i=(a);i<=(b);++i)
#define rep(i,n) rep2(i,0,n-1)
#define pii pair<int,int>
#define ti3 tuple<int,int,int>
int MOD=1000000000+7;
int INF=1e6;

using namespace std;
string alphabet("abcdefghijklmnopqrstuvwxyz");

main(){
    int n;
    int a[300000];
    cin>>n;
    rep(i,n){
        cin>>a[i];
    }
    int temp=0;
    ll int j=0,ans=0;
    rep(i,n){
        while((temp&a[j])==0&&j<n){
            temp+=a[j];
            j++;
        }
        ans+=(j-i);
      
        temp-=a[i];
      
    }
    cout<<ans;
    
}

Measured memory_bytes: 1024