akhauriyash/Code-Regression huggingface dataset:
#include <vector>
#include <cstdio>
long long v,a[100001],b[100001];
long long max(long long p ,long long q){
    if(p>q) return p;
    return q;
}
using namespace std;
int main() {
    int n,k;
    scanf("%d %d",&n,&k);
    for(int i=1;i<n+1;i++){
        scanf("%lld",&v);
        a[i]=v+a[i-1];
        b[i]=b[i-1];
        if(v>0)b[i]+=v;
    }
    long long ans=-1;
    for(int i=1;i <= n - k + 1;i++) {
        ans = max(ans,max(a[i+k-1]-a[i-1],0) +b[i-1]+(b[n]-b[i+k-1]));
    }
    printf("%lld",ans);
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
int main() {
  int64_t a, b, c;
  cin >> a >> b >> c;
  if(c-a-b>0 && 4*a*b<(c-a-b)*(c-a-b)) cout << "Yes";
  else cout << "No";
  return 0;
}

Measured memory_bytes: 3616
S = input().split(" ")
N = int(S[0])
K = int(S[1])
ARR = input().split(" ")



def calculate(n,k):
    counts = 0
    while n > 0:
        if n == k:
            counts += 1
            break
        n = n - (k - 1)
        counts += 1
    return counts
result = calculate(N,K)

print(result)




Measured memory_bytes: 9848
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
//using namespace __gnu_pbds;
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("fast-math")


#define ss second
#define ff first
#define int long long
//#define double long double
#define pb push_back

const int N = 3e5 + 51, MOD = 1e9 + 7, mod = 998244353, INF = 8e17 + 51;

mt19937 Flash_new_51(51515);

using vi = vector <int>;
using vp = vector <pair <int, int>>;

signed main() {
    #ifdef Flash
     freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    bool ok = true;
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        if (x % 2 == 0) {
            if (x % 3 != 0 && x % 5 != 0) {
                cout << "DENIED";
                return 0;
            }
        }
    }
    cout << "APPROVED";
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using BitArray = System.Collections.BitArray;
using BigInteger = System.Numerics.BigInteger;

namespace AtCoderProject
{
    public class Program
    {
        public object Calc()
        {
            var line = consoleReader.Split.Int;
            var K = line[0];
            var X = line[1];

            var res = Enumerable.Range(X - K + 1, 2 * K - 1);

            return string.Join(" ", res);
        }

        #region いつもの
        private readonly ConsoleReader consoleReader;
        public Program(ConsoleReader consoleReader) { this.consoleReader = consoleReader; }
        static void Main() => Console.WriteLine(new Program(new ConsoleReader()).Calc()); static string AllLines<T>(IEnumerable<T> source) => string.Join("\n", source);
        #endregion
    }

#pragma warning disable
    public class ConsoleReader { public class SplitLine { string[] splited; public SplitLine(string line) { splited = line.Split(); } public string[] String => splited.ToArray(); public int[] Int => splited.Select(int.Parse).ToArray(); public long[] Long => splited.Select(long.Parse).ToArray(); public ulong[] ULong => splited.Select(ulong.Parse).ToArray(); public double[] Double => splited.Select(double.Parse).ToArray(); } public class RepeatLine { ConsoleReader reader; int num; public RepeatLine(ConsoleReader reader, int num) { this.reader = reader; this.num = num; } public IEnumerable<string> String { get { for (int i = 0; i < num; i++) yield return reader.String; } } public IEnumerable<int> Int { get { for (int i = 0; i < num; i++) yield return reader.Int; } } public IEnumerable<long> Long { get { for (int i = 0; i < num; i++) yield return reader.Long; } } public IEnumerable<string[]> SplitString { get { for (int i = 0; i < num; i++) yield return reader.Split.String; } } public IEnumerable<int[]> SplitInt { get { for (int i = 0; i < num; i++) yield return reader.Split.Int; } } } public virtual string String => Console.ReadLine(); public int Int => int.Parse(String); public long Long => long.Parse(String); public ulong ULong => ulong.Parse(String); public double Double => double.Parse(String); public SplitLine Split => new SplitLine(String); public RepeatLine Repeat(int count) => new RepeatLine(this, count); }
}

Measured memory_bytes: 13396
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC_C
{
    class C083
    {
        static void Main(string[] args)
        {
            string[] a0 = Console.ReadLine().Split(' ');
            long X = long.Parse(a0[0]), Y = long.Parse(a0[1]);
            long z = Y / X;
            //int max = (int)Math.Log(z, 2) + 1;
            int max = Log(2, z) + 1;
            Console.WriteLine(max);
            
        }

        //整数限定で厳密なLog(小数点以下切り捨て)
        //Math.Logは浮動小数演算による誤差が発生しうるので代替手段
        public static int Log(int a, long n)
        {
            long x = 1;
            int counter = 0;
            while (x <= n)
            {
                x *= a;
                counter++;
            }
            return counter - 1;
        }




    }
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define maxs(a, b) a = max(a, b)
#define mins(a, b) a = min(a, b)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll linf = (1ll << 61);
const int inf = 1001001001;
const int mod = 1000000007;

vector<ll> div(ll a) {
	vector<ll> ret;
	for (ll i = 1; i * i <= a; ++i) {
		if (a % i == 0) {
			ret.push_back(i);
			if (i * i != a) ret.push_back(a / i);
		}
	}
	return ret;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll n;
	cin >> n;
	vector<ll> rec = div(n);
	int ans = 0;
	for (ll c : rec) {
		if (c == 1) continue;
		ll tmp = n;
		while (tmp % c == 0) tmp /= c;
		tmp %= c;
		if (tmp == 1) ans++;
	}
	ans += (int)div(n - 1).size() - 1;
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 3752
#include<bits/stdc++.h>
using namespace std;
int  main()
{
   unsigned long long int n,k=0,i=0,sum=0;
   cin>>n;

   while(n!=0)
   {
       n=n/2;
      k+=pow(2,i);
      i++;
       
   }
   
  cout<<k;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define int long long
#define range(i, a, b) for(auto i = a; i < b; i++)
#define rep(i, a) range(i, 0, a)
#define all(a) (a).begin(),(a).end()
using namespace std;
const int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
const int MOD = 1000000007;
const long double EPS = 1e-8;
using vi = vector <int>;
using vvi = vector <vi>;

signed main() {
	int n;
	while (cin >> n, n) {
		map <int, int> pear;
		for (int i = n; i > 0; i--) {
			int tmp = i;
			for (int j = 2; j * j <= tmp; j++) {
				while(tmp % j == 0) {
					pear[j]++;
					tmp /= j;
				}
			}
			if (tmp != 1) {
				pear[tmp]++;
			}
		}
		cout << min(pear[2], pear[5]) << endl;
	}
	return 0;
}


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

int main()
{
    int N, M;
    cin >> N >> M;
    vector<int> cnt(M, 0);
    for (int i = 0; i < N; ++i)
    {
        int K;
        cin >> K;
        for (int j = 0; j < K; ++j)
        {
            int A;
            cin >> A;
            --A;
            ++cnt[A];
        }
    }
    int ans = 0;
    for (int i = 0; i < M; ++i)
    {
        if (cnt[i] == N)
        {
            ++ans;
        }
    }
    cout << ans << endl;
}

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

using namespace std;

typedef long long ll;

constexpr int M = 1000 * 1000 * 1000 + 7;

ll dp[2][100000];
int last_number[100000];

int main() {
    std::ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, k;
    cin >> n >> k;
    stack<int> tmp;
    int c = 0;
    for (int i = 1; i * i <= n; ++i) {
        last_number[c++] = i;
        tmp.push(n / i);
    }
    while (!tmp.empty()) {
        int cur = tmp.top();
        tmp.pop();
        if (last_number[c - 1] != cur) {
            last_number[c++] = cur;
        }
    }
    ll *dp_cur = dp[0];
    ll *dp_next = dp[1];
    dp_cur[0] = 1;
    ll total_sum = n;
    for (int i = 1; i < c; ++i) {
        dp_cur[i] = last_number[i] - last_number[i - 1];
    }
    for (int j = 1; j < k; ++j) {
        for (int i = 0; i < c; ++i) {
            dp_next[i] = total_sum * (last_number[i] - (i ? last_number[i - 1] : 0)) % M;
            total_sum -= dp_cur[c - i - 1];
            if (total_sum < 0) total_sum += M;
        }
        swap(dp_cur, dp_next);
        total_sum = 0;
        for (int i = 0; i < c; ++i) {
            total_sum += dp_cur[i];
            if (total_sum >= M) {
                total_sum -= M;
            }
        }
    }
    cout << total_sum << endl;
}


Measured memory_bytes: 1664
#include<bits/stdc++.h>
using namespace std; 
int main()
{
    long long int n,a,b,c;
    

    cin>>n;
    long long int dp[3][n],ar[3][n];
    // cout<<n<<"\n";
    for(int i=0;i<n;i++)
    {
        dp[0][i]=0;
        dp[1][i]=0;
        dp[2][i]=0;
    }
    
    
    for(int i=0;i<n;i++)
    {
        cin>>a>>b>>c;
     ar[0][i]=a;
    ar[1][i]=b;
    ar[2][i]=c;
    }
    dp[0][0]=ar[0][0];
    dp[1][0]=ar[1][0];
    dp[2][0]=ar[2][0];
    
    for(int i=1;i<n;i++)
    {
        dp[1][i]=max(dp[1][i],max(ar[1][i]+dp[2][i-1],ar[1][i]+dp[0][i-1]));
        dp[2][i]=max(dp[2][i],max(ar[2][i]+dp[1][i-1],ar[2][i]+dp[0][i-1]));
dp[0][i]=max(dp[0][i],max(ar[0][i]+dp[1][i-1],ar[0][i]+dp[2][i-1]));
        
    }
cout<<max(dp[0][n-1],max(dp[1][n-1],dp[2][n-1]));
}

Measured memory_bytes: 8276
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    long[] a = new long[n];
    long sum = 0;
    for(int i = 0; i < n; i++) {
      a[i] = sc.nextLong();
      sum += (a[i] / (long)n);
    }
    long ans = 0;
    while(sum > 0) {
      long t = sum;
      ans += sum;
      sum = 0;
      for(int i = 0; i < n; i++) {
        long s = a[i] / (long)n;
        a[i] -= (s * (long)n);
        a[i] += (t - s);
        sum += (a[i] / (long)n);
      }
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 21844
#include<stdio.h>
#include<ctype.h>
#define rep(i,N) for(int i=0;i<(int)N;i++)
int IN(void)
{
  int x=0,f=1;char c=getchar();
  while(!isdigit(c)&&c!='-')c=getchar();
  if(c=='-')f=-f,c=getchar();
  while(isdigit(c))x=x*10+c-48,c=getchar();
  return f*x;
}
int main(void)
{
  int N=IN(),A[200001]={0};
  rep(i,N-1)A[IN()-1]++;
  rep(i,N)printf("%d\n",A[i]);
}

Measured memory_bytes: 2360
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>


using namespace std;

#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 REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF 1999999999
#define MINF -1999999999
#define INF64 1999999999999999999
#define ALL(n) n.begin(),n.end()
#define MOD 1000000007


ll n, s;

int main() {
	cin >> n >> s;
	
	if (s == n) {
		cout << n + 1 << endl;
		return 0;
	}
	for (int i = 2; i <= sqrt(n); i++){
		ll now = 0, nn = n;
		while (nn > 0) {
			now += nn % i;
			nn /= i;
		}
		if (now == s) {
			cout << i << endl;
			return 0;
		}
	}
	for (int i = sqrt(n); i >= 2; i--) {
		ll si = n / i + 1, now = 0, a = n / si, b = n % si;
		if (a + b >= s and (a + b - s) % a == 0) {
			if ((a + b - s) <= b) {
				cout << si + (a + b - s) / a << endl;
				return 0;
			}
		}
	}
	if (s == 1) {
		cout << n << endl;
		return 0;
	}
	cout << -1 << endl;
}



Measured memory_bytes: 384
#include <iostream>
using namespace std;
int main(){
	string b[] = {"* = ****","* =* ***","* =** **","* =*** *","* =**** "," *= ****"," *=* ***"," *=** **"," *=*** *"," *=**** "},i;
	int f = 0, k, l;
	while(cin >> i,!cin.eof()){
		f&&cout<<endl;
		f?:f=1;
		while(i.size() < 5)i = '0' + i;
		for(k=0;k<8;k++){
			for(l=0;l<5;l++)cout << b[i[l]-'0'][k];
			cout << endl;
		}
	}
}

Measured memory_bytes: 0
#include <algorithm>
#include <bitset>
#include <cassert>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
typedef pair<ll, ll> P;
inline ll min(ll x, ll y) { return x < y ? x : y; }
inline ll max(ll x, ll y) { return x > y ? x : y; }

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
#define all(c) c.begin(), c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << (x) << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)

int main() {
    ll X, t;
    cin >> X >> t;
    cout << max(X - t, 0);
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>

int main(int argc, char const* argv[])
{
	int m, n;
	scanf("%d %d", &m, &n);
	int **A = new int*[m];
	for(int i = 0; i < m; i++){
			A[i] = new int[n];
			for(int j = 0; j < n; j++){
					scanf("%d", A[i]+j);
			}
	}
	int *b = new int[n];
	for(int i = 0; i < n; i++){
			scanf("%d", b+i);
	}
	for(int i = 0; i < m; i++){
			int sum = 0;
			for(int j = 0; j < n; j++)sum += A[i][j] * b[j];
			printf("%d\n", sum);
	}
	return 0;
}



Measured memory_bytes: 2736
#include <stdio.h>

int main () {
	int k, a, b, kelipatan;
	scanf("%d", &k);
	getchar();
	scanf("%d %d", &a, &b);
	for (int i = a; i <= b; i++) {
		if ( i % k == 0) {
			puts("OK");
			return 0;
		}
		else {
			continue;
		}
	}
	puts("NG");
	return 0;
}

Measured memory_bytes: 1616
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define rrep(i, a, b) for (int i = (a); i < (b); ++i)
#define PI acos(-1)
#define pcnt __builtin_popcountll
#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define sz(x) (int)(x).size()
#define v(T) vector<T>
#define vv(T) v(v(T))
#define fi first
#define se second

using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using LP = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;

template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) {if (a > b) { a = b; return true; } return false; }

ll INF = 1001001001;
ll LINF = 1001001001001001001ll;

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

    ll n, m, s, t;
    cin>>n>>m>>s>>t; s--; t--;
    vector<vector<LP>> toa(n), tob(n);
    rep(i, m) {
        ll u, v, a, b;
        cin>>u>>v>>a>>b; u--; v--;
        toa[u].emplace_back(a, v);
        toa[v].emplace_back(a, u);
        tob[u].emplace_back(b, v);
        tob[v].emplace_back(b, u);
    }

    priority_queue<LP, vector<LP>, greater<LP>> q;
    q.emplace(0, s);
    vl dista(n, LINF);
    while (!q.empty()) {
        LP p = q.top(); q.pop();
        ll d = p.fi;
        ll v = p.se;

        if (dista[v] != LINF) continue;
        dista[v] = d;
        for (auto nv : toa[v]) {
            q.emplace(nv.fi + d, nv.se);
        }
    }

    q.emplace(0, t);
    vl distb(n, LINF);
    while (!q.empty()) {
        LP p = q.top(); q.pop();
        ll d = p.fi;
        ll v = p.se;

        if (distb[v] != LINF) continue;
        distb[v] = d;
        for (auto nv : tob[v]) {
            q.emplace(nv.fi + d, nv.se);
        }
    }

    vl ans(n + 1);
    ll ceil = 1e15;
    for (int i = n - 1; i >= 0; --i) {
        ans[i] = ans[i + 1];
        chmax(ans[i], ceil - (dista[i] + distb[i]));
    }
    rep(i, n) {
        cout<<ans[i]<<endl;
    }
}

Measured memory_bytes: 19832
n,k=map(int,input().split())
a=[int(i) for i in input().split()]
chk=a.index(1)
k-=1
l=chk
r=n-chk-1
ans=((l+k-1)//k)+((r+k-1)//k)

if l%k==0:
    t1=0
else:
    t1=k-(l%k)
ans=min(ans,((l+k-1)//k)+((r-t1+k-1)//k))

if r%k==0:
    t2=0
else:
    t2=k-(r%k)
ans=min(ans,((l-t2+k-1)//k)+((r+k-1)//k))
print(ans)

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

#define int long long
#define pb push_back 
#define mp make_pair
#define fr first
#define sc second
#define Rep(i, n) for( int i = 0; i < (n); i++ )
#define Rrep(i, a, n) for( int i = (a); i < (n); i++ )
#define All(v) v.begin(), v.end()

typedef pair<int, int> Pii; 
typedef pair<int, Pii> Pip;
const int INF = 1107110711071107;

signed main() {
  int W, H, T;
  int p;
  int data[51][51];
  int used[51][51][51] = {{{0}}};
  Pip P[51];
  int sum = 0;
  
  cin >> W >> H >> T;
  cin >> p;

  Rep(i, p) {
    cin >> P[i].fr >> P[i].sc.fr >> P[i].sc.sc;
  }
  
  Rep(i, H) Rep(j, W) cin >> data[i][j], sum += data[i][j];

  Rep(i, p) {
    if ( data[P[i].sc.fr][P[i].fr] &&  !used[P[i].sc.sc][P[i].sc.fr][P[i].fr]  ) {
      used[P[i].sc.sc][P[i].sc.fr][P[i].fr] =true;
      data[P[i].sc.fr][P[i].fr]++;
    }
  }

  int ans = 0;
  Rep(i, H) Rep(j, W) ans += data[i][j];

  cout << ans-sum << endl;
  
  return 0;
}

Measured memory_bytes: 4148
import heapq
n, m = map(int, input().split())
a = list(map(int, input().split()))
a = list(map(lambda x: x*(-1), a))

heapq.heapify(a)
for i in range(m):
  heapq.heappush(a, heapq.heappop(a) / 2)

ans = 0
for i in range(n):
  ans += -a[i] // 1

print(int(ans))

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

static const int MAX = 100000;
static const int INFTY = (1<<29);

vector<int> G[MAX];
list<int> out;
bool V[MAX];
int N;
int indeg[MAX];

void bfs(int s){
  queue<int> q;
  q.push(s);
  V[s] = true;
  while( !q.empty() ){
    int u = q.front();
    q.pop();
    out.push_back(u);

    for(int i=0;i<G[u].size();i++){
      int v = G[u][i];
      indeg[v]--;
      if(indeg[v] == 0 && !V[v]){
        V[v] = true;
        q.push(v);
      }
    }
  }
}

// 各Nodeが処理しなければならない数を記録
void tsort(){
  for(int i=0;i<N;i++) indeg[i] = 0;

  for(int u=0;u<N;u++){
    for(int i=0;i<G[u].size();i++){
      int v = G[u][i];
      indeg[v]++;
    }
  }

  for(int u=0;u<N;u++){
    if(indeg[u] == 0 && !V[u]) bfs(u);
  }

  for(list<int>::iterator it = out.begin(); it != out.end();it++){
    cout << *it << endl;
  }
}

int main(){
  int s,t,M;
  cin >> N >> M;

  // 初期化
  for(int i=0;i<N;i++) V[i] = false;

  // sに繋がるtを保存
  for(int i=0;i<M;i++){
    cin >> s >> t;
    G[s].push_back(t);
  }

  tsort();
  return 0;
}



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

int digit(int x){
    if(x<10) return 1;
    return 1+digit(x/10);
}
int main(){
    int n,m;
    cin >> n >> m;
    priority_queue<P,vector<P>,greater<P>> que;
    map<pair<int,int>,int> mp;
    vector<P> ans(m+1);
    rp(i,m){
        int p,y;
        cin >> p >> y;
        mp[make_pair(p,y)]=i+1;
        que.push(make_pair(p,y));
    }
    int prep=0;
    int ctr=1;
    while(!que.empty()){
        P p=que.top(); que.pop();
        if(prep!=p.first){
            prep=p.first;
            ctr=1;
        }
        else ctr++;
        ans.at(mp[p])=make_pair(prep,ctr);
    }
    for(int i=1; i<=m; i++){
        rp(j,6-digit(ans[i].first)) cout << "0";
        cout << ans[i].first;
        rp(j,6-digit(ans[i].second)) cout << "0";
        cout << ans[i].second;
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 9332
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#include <unordered_map>
typedef long long ll;
using namespace std;
const int mod=1e9+7;


int solve(){
    int n,k;
    cin>>n>>k;
    vector<bool> vis(n+1);
    for(int i=0;i<k;i++){
        int q,t;
        cin>>q;
        while(q--) cin>>t,vis[t]=1;
    }
    int ans=0;
    for(int i=1;i<=n;i++) ans+=(!vis[i]);
    return ans;
}

int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
#endif
    int t=1;
    //cin>>t;
    while(t--) cout<<solve()<<'\n';
    //while(t--) solve(),cout<<'\n';
    return 0;
}


Measured memory_bytes: 3628
<?php

$sc = new Scanner();

$n = $sc->nextInt();
$T = $sc->nextInt();
$A = $sc->nextInt();
$h = [];
$index = 0;
$d = 1000000000000000;
for ($i = 0; $i < $n; $i++) {
    $tmp = $T - $sc->nextInt() * 0.006;
    if ($d > ($t = abs($tmp - $A))) {
        $d = $t;
        $index = $i+1;
    }
}

echo $index . PHP_EOL;



class Scanner {
    private $arr = [];
    private $count = 0;
    private $pointer = 0;
    public function next() {
        if($this->pointer >= $this->count) {
            $str = trim(fgets(STDIN));
            $this->arr = explode(' ', $str);
            $this->count = count($this->arr);
            $this->pointer = 0;
        }
        $result = $this->arr[$this->pointer];
        $this->pointer++;
        return $result;
    }
    public function hasNext() {
        return $this->pointer < $this->count;
    }
    public function nextInt() {
        return (int)$this->next();
    }
    public function nextDouble() {
        return (double)$this->next();
    }
}


Measured memory_bytes: 4856
N = int(input())
A = [int(i) for i in input().split()]

B = [0]*N
for i in range(N):
  B[A[i]-1] += 1

s = 0
for i in range(N):
  s += B[i]*(B[i]-1)//2

for i in range(N):
  print(s-B[A[i]-1]+1)

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

class card {
private:
	int value;
	char suit;
public:
	void set(char s, int v);
	void print();
	int getValue();
	int getSuit();
};
int card::getSuit() {
	return suit;
}
int card::getValue() {
	return value;
}
void card::set(char s, int v) {
	suit = s;
	value = v;
}
void card::print() {
	cout << suit << value;
}

int main() {
	char suit;
	int value,n;
	card c[36],c1[36], c2[36];
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> suit>> value;
		c[i].set(suit, value);
		c1[i] = c[i];
		c2[i] = c[i];
	}
	//Bubble Sort
	for (int i = 0; i < n; i++)
	{
		for (int j = n-1; j > i; j--)
		{
			if (c1[j].getValue()<c1[j-1].getValue())
			{
				card temp = c1[j];
				c1[j] = c1[j - 1];
				c1[j - 1] = temp;
			}
		}
	}
	//Selection Sort
	for (int i = 0; i < n; i++)
	{
		int min = i;
		for (int j = i; j < n; j++)
		{
			if (c2[j].getValue()<c2[min].getValue())
			{
				min = j;
			}
		}
		swap(c2[i], c2[min]);
	}
	for (int i = 0; i < n; i++)
	{
		if (i)
			cout << " ";
		c1[i].print();
	}
	cout << endl <<"Stable"<<endl;
	for (int i = 0; i < n; i++)
	{
		if (i)
			cout << " ";
		c2[i].print();
	}
	bool isStable = true;
	for (int i = 0; i < n; i++)
	{
		if (c1[i].getSuit()!=c2[i].getSuit())
		{
			isStable = false;
			break;
		}
	}
	if (isStable == false)
	{
		cout << endl << "Not stable"<<endl;
	}
	else
	{
		cout << endl << "Stable"<<endl;
	}
	//system("pause");
	return 0;
}


Measured memory_bytes: 3112
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using ll = long long;
using namespace std;

int main() {
    string s;
    cin >> s;

    string day[] = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};

    int ans = 7;
    rep(i, 7) {
        if(s == day[i]) {
            cout << ans << endl;
            break;
        }
        ans--;
    }
}

Measured memory_bytes: 3620
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef vector<ll> vll;
typedef vector<vector<ll> > vvll;
typedef deque<ll> dqll;

#define MOD 1000000007

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

  vll lst(N);

  for (int i = 0; i < N; i++) {
    cin >> lst[i];
  }

  sort(lst.begin(), lst.end());

  ll ans = 0;
  for (int i = 0; i <= N - 2; i++) {
    for (int j = i + 1; j <= N - 1; j++) {
      ll cur = lst[i] + lst[j];
      auto itru = lower_bound(lst.begin(), lst.end(), cur);
      ll add = (ll)(itru - lst.begin()) - (j + 1);
      if (add > 0) ans += add;
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) (v).begin(),(v).end()
#define chmin(x,y) x = min(x,y)
typedef pair<int, int> P;
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const ll MOD = 1e9+7;

int main() {
	int N;
    ll K;
	cin >> N >> K;
    vector<int> A(N);
    rep(i, N) cin >> A[i];

    ll cnt = 0;
    rep(i, N-1) {
        for (int j = i+1; j < N; j++) {
            if (A[i] > A[j]) cnt++;
        }
    }
    ll ans = cnt * K % MOD;
    cnt = 0;
    rep(i, N) {
        rep(j, N) {
            if (A[i] > A[j]) cnt++;
        }
    }
    ans += K*(K-1)/2 % MOD * cnt % MOD;
    ans %= MOD;

	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
try:
    from typing import List
except ImportError:
    pass

YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(N: int, M: int, A: "List[str]", B: "List[str]"):
    print(YES if any(all(
        A[y + dy][x + dx] == B[dy][dx]
        for dx in range(M) for dy in range(M)
    ) for x in range(N - M + 1) for y in range(N - M + 1)) else NO)


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    A = [next(tokens) for _ in range(N)]  # type: "List[str]"
    B = [next(tokens) for _ in range(M)]  # type: "List[str]"
    solve(N, M, A, B)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<bitset>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);(i)++)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
constexpr auto INF = 1000000000;
constexpr auto LLINF = 1LL << 62;
constexpr auto mod = 1000000007;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; }return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; }return 0; }

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

    ll a, b, c, k;
    cin >> a >> b >> c >> k;
    ll ans = (k % 2 ? b - a : a - b);
    if (abs(ans) > 99999999999999999)cout << "Unfair\n";
    else cout << ans << "\n";
}

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

int a, b, k;

void in();
void solve();
void out();
bool checkprim(int x);

int main(){
    in();
    solve();
    out();
}

void in(){
    ios::sync_with_stdio(false);
    cout.tie(0);
    cin.tie(0);
    cin >> k;
}

void solve(){
    while(!checkprim(k))
        k++;
}

void out(){
    cout << k;
}

bool checkprim(int x){
    for(int i = 2; i * i <= x; i++)
        if(x % i == 0)
            return 0;
    return 1;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int MAXN=100005;
int a[MAXN],b[MAXN];
int main()
{
    int A,B,M;
    scanf("%d%d%d",&A,&B,&M);
    for(int i=1;i<=A;i++)
        scanf("%d",&a[i]);
    for(int i=1;i<=B;i++)
        scanf("%d",&b[i]);
    int res=*min_element(a+1,a+A+1)+*min_element(b+1,b+B+1);
    for(int i=1;i<=M;i++)
    {
        int x,y,c;
        scanf("%d%d%d",&x,&y,&c);
        res=min(res,a[x]+b[y]-c);
    }
    return 0*printf("%d\n",res);
}

Measured memory_bytes: 1024
import java.util.*;

public class Main {

  public static void main (String[] args) {

    Scanner sc = new Scanner(System.in);
    
    int N = sc.nextInt();

    sc.close();

    String result = "No";

    if (N % 4 == 0 || N % 7 == 0 || N % 11 == 0){
      result = "Yes";
    }
    
    if (result.equals("No")){

      for (int i = 1; i <= N / 4; i++) {
        if((N - (4 * i)) % 7 == 0 ) {
          result = "Yes";
          break;
        }
      }

    }

    if (result.equals("No")){

      for (int i = 1; i <= N / 7; i++) {
        if((N - (7 * i)) % 4 == 0 ) {
          result = "Yes";
          break;
        }
      }

    }

    System.out.println(result);

  }

}

Measured memory_bytes: 21844
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_C main
#include "bits/stdc++.h"
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
using psi = pair<string, int>;
// functions

#endif


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


    int N, X; cin >> N >> X;
    vi A(N); REP(i, N) cin >> A[i];
    
    ll ans = 0;
    FOR(i,1,N) {
        if (A[i-1]+A[i] > X) {
            int dif = A[i - 1] + A[i] - X;

            if (A[i] >= dif) {
                A[i] -= dif;
            }
            else {
                A[i - 1] -= dif - A[i];
                A[i] = 0;
                
            }
            ans += dif;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 640
package main

import (
	"fmt"
)

// strconv使ってstringにしてreverseにしようかと思ったけど結局スライスにバラして作り直すってのやんなきゃならんらしいので使わない

func check(n int) int {
	// 5桁は確定
	rev, tmp := 0, n
	for i := 10000; 0 < i; i /= 10 {
		rev += i * (tmp % 10)
		tmp /= 10
	}
	if rev == n {
		return 1
	} else {
		return 0
	}
}

func main() {
	var a, b int
	fmt.Scan(&a, &b)
	ans := 0
	for i := a; i <= b; i++ {
		ans += check(i)
	}
	fmt.Println(ans)
}

Measured memory_bytes: 512
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
     
using namespace std;
     
typedef long long ll;
typedef pair<int, int> pii;
     
#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
     
mt19937 rnd(chrono::steady_clock().now().time_since_epoch().count());

int r, c;
bool good(int ii, int jj){
    if(ii == 0 || ii == r || jj == 0 || jj == c)
        return true;
    return false;
}

int compute(int ii, int jj){
    if(ii==0){
        return jj;
    }
    else if(jj==c){
        return c+ii;
    }
    else if(ii==r){
        return r+c+(c-jj);
    }
    return c + c + r + (r - ii);
}

struct Node{
    int maxv;
    int minv;
};

const int N = (int)4e5 + 9;
const int inf = (int)1e9;
int M;


Node T[N * 2];

void init(){
    for(int i = 0 ; i < N * 2; i ++ )
        T[i] = {0,inf};
}


void upd(int id, int vl){   
    id += M;
    T[id].maxv = vl;
    T[id].minv = vl;
    id/=2;
    while(id>0){
        T[id].maxv=max(T[id*2].maxv, T[id*2+1].maxv);
        T[id].minv=min(T[id*2].minv, T[id*2+1].minv);
        id/=2;
    }
}

int ask_min(int L, int R){
    L += M;
    R += M;
    int mn = inf;
    while(L <= R){
        if(L%2==1)mn=min(mn, T[L++].minv);
        if(R%2==0)mn=min(mn, T[R--].minv);
        L /= 2;
        R /= 2;
    }
    return mn;
}

int ask_max(int L, int R){
    L += M;
    R += M;
    int mn = 0;
    while(L <= R){
        if(L%2==1)mn=max(mn, T[L++].maxv);
        if(R%2==0)mn=max(mn, T[R--].maxv);
        L /= 2;
        R /= 2;
    }
    return mn;
}

int main(){
    fastIO;
    init();
    int n;
    cin >> r >> c >> n;
    int i1, j1, i2, j2;
    int p1, p2;
    vector<pii> segm;
    for(int i = 0 ; i < n; i ++ ){
        cin >> i1 >> j1 >> i2 >> j2;
        if(!good(i1,j1) || !good(i2,j2))
            continue;
        p1 = compute(i1,j1);
        p2 = compute(i2,j2);
        segm.push_back(mp(p1,p2));
        segm.push_back(mp(p2,p1));
    }
    sort(segm.begin(), segm.end());
    M = segm.size();
    for(int i = 0 ; i < segm.size(); i ++ ){
        
        upd(i,segm[i].se);
        
    }
    int cL, cR;
    int mx, mn;
    for(int i = 0 ; i < segm.size(); i ++ ){
        cL = segm[i].fi;
        cR = segm[i].se;
        if(cL > cR)
            swap(cL, cR);
        cL = lower_bound(segm.begin(), segm.end(), mp(cL,-1)) - segm.begin();
        cR = lower_bound(segm.begin(), segm.end(), mp(cR + 1, -1)) - segm.begin();
        -- cR;
        mx = ask_max(cL, cR);
        mn = ask_min(cL, cR);
        if(mn < min(segm[i].fi,segm[i].se)){
            cout << "NO\n";
            return 0;
        }
        if(mx > max(segm[i].fi,segm[i].se)){
            cout << "NO\n";
            return 0;
        }
            
    }
    cout << "YES\n";
    return 0;
    
}

Measured memory_bytes: 8692
#include <bits/stdc++.h>
using namespace std;int64_t N,P,p,i,r,v,m[1<<20];string S;main(){cin>>N>>P>>S;if(10%P){m[0]=p=1;for(i=N;i--;)v=(v+(S[i]-48)*(p=(p*10)%P))%P,r+=m[v]++;}else{for(i=0;i<N;i++)if(!((S[i]-8)%P))r+=i+1;}cout<<r;}

Measured memory_bytes: 644
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
    static Node[] nodes;
    public static void main (String[] args) throws IOException {
	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	int n = Integer.parseInt(br.readLine());
	nodes = new Node[n];
	for (int i = 0; i < n; i++) {
	    nodes[i] = new Node(i);
	}
	String[] input;
	int id, left, right;
	for (int i = 0; i < n; i++) {
	    input = br.readLine().split(" ");
	    id = Integer.parseInt(input[0]);
	    left = Integer.parseInt(input[1]);
	    right = Integer.parseInt(input[2]);
	    nodes[id].left = left;
	    nodes[id].right = right;
	    if (left != -1) {
		nodes[left].isRoot = false;
	    }
	    if (right != -1) {
		nodes[right].isRoot = false;
	    }
	}
	int rootId = -1;
	for (int i = 0; i < n; i++) {
	    if (nodes[i].isRoot) {
		rootId = i;
	    }
	}
        runPreorder(rootId);
	runInorder(rootId);
	runPostorder(rootId);
    }
    static void runPreorder (int id) {
	StringBuilder sb = new StringBuilder();
	sb.append("Preorder\n");
	preorder(id, sb);
	System.out.println(sb);
    }
    static void preorder (int id, StringBuilder sb) {
	if (id < 0) return;
	sb.append(" " + nodes[id].id);
	preorder(nodes[id].left, sb);
	preorder(nodes[id].right, sb);
    }
    static void runInorder (int id) {
	StringBuilder sb = new StringBuilder();
	sb.append("Inorder\n");
        inorder(id, sb);
	System.out.println(sb);
    }
    static void inorder (int id, StringBuilder sb) {
	if (id < 0) return;
	inorder(nodes[id].left, sb);
	sb.append(" " + nodes[id].id);
	inorder(nodes[id].right, sb);
    }
    static void runPostorder (int id) {
	StringBuilder sb = new StringBuilder();
	sb.append("Postorder\n");
	postorder(id, sb);
	System.out.println(sb);
    }
    static void postorder (int id, StringBuilder sb) {
	if (id < 0) return;
	postorder(nodes[id].left, sb);
	postorder(nodes[id].right, sb);
	sb.append(" " + nodes[id].id);
    }
}
class Node {
    int id;
    int left;
    int right;
    boolean isRoot;
    Node (int id) {
	this.id = id;
	isRoot = true;
    }
}

Measured memory_bytes: 24456
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define re register
#define gc getchar
#define pc putchar
#define cs const
#define st static

inline
ll getint(){
    re ll num=0;
    re char c=gc();
    while(!isdigit(c))c=gc();
    while(isdigit(c))num=(num<<1)+(num<<3)+(c^48),c=gc();
    return num;
}

inline
void outint(ll a){
    st char ch[23];
    if(a==0)pc('0');
    while(a)ch[++ch[0]]=(a-a/10*10)^48,a/=10;
    while(ch[0])pc(ch[ch[0]--]);
}

int N;
int K; 

int main(){
    N=getint();
    K=getint();
    if(K&1){
        ll tmp=(N/K);
        cout<<tmp*tmp*tmp;
    }
    else{
        ll tmp=(N/K);
        ll tmp2=tmp;
        if(N%K>=K/2)tmp2++;
        cout<<tmp*tmp*tmp+tmp2*tmp2*tmp2;
    }
    return 0;
} 

Measured memory_bytes: 256
import java.util.Scanner;

class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        while (true) {
            int n = sc.nextInt();
            int x = sc.nextInt();
            if (n == 0) {
                break;
            }
            int count = 0;
            for (int i = 1; i <= n - 2; i++) {
                if (i * 3 >= x) {
                    break;
                }
                for (int j = i + 1; j <= n - 1; j++) {
                    for (int k = j + 1; k <= n; k++) {
                        if (i + j + k == x) {
                            count++;
                        }
                    }
                }
            }
            System.out.println(count);
        }


    }

}


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

int main() {
  int long long n;
  cin >> n ;
  if(n==1){
    cout<<0<<endl;
  }
  else{
  int long long x=1,y=1,z=1;
  int long long ans;
  int long long mod=1000000007;
  for(int long long i=0;i<n;i++){
    x=(x*10)%mod;
    y=(y*9)%mod;
    z=(z*8)%mod;
   }
  ans=((x-2*y+z)%mod+mod)%mod;
  cout<<ans<<endl;
  }
}


Measured memory_bytes: 3548
#include <iostream>
#include <cstdio>

using namespace std;

int main() {

	int i, w, n, a, b, x[31];

	cin >> w;
	cin >> n;
	for(i=1; i<=w; i++) {
		x[i]=i;
	}


	for(i=1; i<=n; i++) {
		scanf("%d,%d", &a, &b);
		int t=x[a];
		x[a]=x[b];
		x[b]=t;
	}

	for(i=1; i<=w; i++) {
		cout << x[i] << endl;
	}

	return 0;

}

Measured memory_bytes: 0
from collections import Counter
import math
import random
n=int(input())
a=list(map(int,input().split()))
ma=max(a)
sa=set(a)
ans=[]
era=[1]*(10**6+1)
era[0]=0
ca=Counter(a)

k=2
while k<(10**6+1):
  if era[k]==1:
    for i in range(k,10**6+1,k):
      if i!=k:
        era[i]=0
      if i in sa:
        for t in range(ca[i]):
          ans.append(k)
  if k==2:
    k+=1
  else:
    k+=2

pflag=True
if len(ans)!=len(set(ans)):
  pflag=False
  
if pflag == False:
  setwise=a[0]
  for i in range(1,n):
    setwise=math.gcd(setwise,a[i])
  if setwise == 1:
    print("setwise coprime")
  else:
    print("not coprime")
else:
  print('pairwise coprime')


Measured memory_bytes: 360976
n, a = map(int, input().split())
x = [int(x) for x in input().split()]

dp = [[0]*2501 for _ in range(n+1)]
for i in range(n+1):
  for j in range(i-1, -1, -1):
    if j == 0:
      dp[j+1][x[i-1]] += 1
    for k in range(2500, -1, -1):
      if dp[j][k] and k+x[i-1] <= 2500:
        dp[j+1][k+x[i-1]] += dp[j][k]

ans = 0
for i in range(1, n+1):
  ans += dp[i][i*a]
print(ans)

Measured memory_bytes: 4596
#define _USE_MATH_DEFINES
#include  <iostream>
#include  <algorithm>
#include  <climits>
#include  <vector>
#include  <string>
#include  <cstring>
#include  <stack>
#include  <queue>
#include  <cmath>
#include  <iomanip>
#include  <set>
#include  <map>
#include  <new>
#include <cstdint>
#include <cctype>
using namespace std;
#define rep(i,n)  for(int i = 0; i < n; i++)
#define lrep(i,n,m)  for(int i = n; i < m; i++)

using ll = long long;
using Vii = vector<vector<int> >;
using Gjudge = vector<vector<bool>>;
using Vi = vector<int>;
using Vl = vector<ll>;
using Vll = vector<vector<ll> >;
using Vs = vector<string>;
using Vb = vector<bool>;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using Ti = tuple<int, int, int>;
using Tl = tuple<ll, ll, ll>;

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

const int Mod = static_cast<int>(1e9 + 7);
const int INF = INT_MAX;
const ll LINF = LLONG_MAX / 10000;
const int dx[4] = { 1,0,-1,0 };
const int dy[4] = { 0,1,0,-1 };


Vi color;
Vii G;
bool dfs(int u, int c)
{
	if (color[u] == 0 && c == 1) return false;
	if (color[u] == 1 && c == 0) return false;
	if (color[u] != -1) return true;
	color[u] = c;
	bool f = true;
	if (c == 0) {
		rep(nu, G[u].size()) {
			if (!dfs(G[u][nu], c + 1)) f = false;
		}
	}
	else {
		rep(nu, G[u].size()) {
			if (!dfs(G[u][nu], c - 1)) f = false;
		}
	}
	//if (!f) cout << "false" << endl;
	return f;
}

int main()
{
	int n, m;
	cin >> n >> m;
	G.resize(n);
	rep(i, m) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	color.resize(n, -1);
	if (!dfs(0, 0)) {
		cout << ll(n) * (n - 1) / 2 - m << endl;
	}
	else {
		ll bsum = 0;
		rep(i, n) {
			if (color[i] == 0) bsum++;
		}
		cout << bsum * (n - bsum) - m << endl;
	}

	//rep(i, n) {
	//	cout << color[i] << endl;
	//}
}


Measured memory_bytes: 10012
import itertools
s=input()
splitlist=[[k, len(list(g))] for k, g in itertools.groupby(s)]
n=len(splitlist)
#print(splitlist)

def total(lst):
	return lst[1]*(lst[1]+1)//2


ans=total(splitlist[0])
for i in range(1,n):
	ans+=total(splitlist[i])
	if splitlist[i][0]==">":
		ans-=min(splitlist[i-1][1],splitlist[i][1])
print(ans)

Measured memory_bytes: 31032
#include <iostream>

using namespace std;
using ll = long long;

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

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

  int ans;
  if (a >= k)
    ans = k;
  else {
    if (b >= k - a)
      ans = a;
    else
      ans = a - (k - (a + b));
  }

  cout << ans << endl;
  return 0;
}


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

#define TRACE(x) cerr << #x << " :: " << x << endl
#define _ << " " <<
#define SZ(x) (int)(x).size()
#define ALL(x) (x).begin(),(x).end()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define RFOR(i,a,b) for (int i=(a);i>=(b);--i)

const int MX_N = 1e5+5;

int N, M;
vector<int> al[MX_N];

int col[MX_N];

bool rip;
void dfs(int u, bool c=0) {
    col[u] = c;
    for (int v : al[u]) {
        if (col[v] == -1) dfs(v,!c);
        else if (col[v] == col[u]) rip = 1;
    }
}

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

    cin >> N >> M;
    FOR(i,1,M){
        int U, V; cin >> U >> V;
        al[U].push_back(V);
        al[V].push_back(U);
    }

    long long ans = 0;
    int p = 0, q =0, r=0;
    memset(col,-1,sizeof col);
    FOR(i,1,N) if (col[i] == -1){
        if (SZ(al[i]) == 0) ans += 2*(N-r)-1, ++r;
        else {
            rip = 0; dfs(i);
            if (rip) ++p;
            else ++q;
        }
    }

    //TRACE(ans _ p _ q);
    ans += 1LL*p*p + 1LL*p*q + 1LL*q*p + 2LL*q*q;
    cout << ans;
}



Measured memory_bytes: 9984
#include<iostream>
#include<vector>
#include<algorithm>
#include<stdlib.h>
#include<utility>
#include<functional>
#include<cfenv>
#include<cmath>
#include<string>
#include<queue>
#include<stack>
#include<map>
#include<set>
 
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define vint vector<int>
#define vvint vector<vint>
#define P pair<int,int>
#define INT_MAX 2147483647
#define MOD 1000000007
#define PI 3.14159265358979323846
using namespace std;
typedef long long ll;
 
 
 
int main(void) {
	ll a;
	double b;
	cin >> a >> b;
	ll c = b * 100+0.5;
 
	cout << (a * c)/100 << endl;
	return 0;
}

Measured memory_bytes: 3724
#include <bits/stdc++.h>
using namespace std;
 
int main() 
{
    int a,b,c,k;
    cin>>a>>b>>c>>k;
    int oper=0,i,j;
    if(a>=b)
    {
    for(i=b;i<=a;)
    {
        i=i*2;
        ++oper;
    }
    b=i;
    }
    if(b>=c)
    {
        for(j=c;j<=b;)
        {
            j=j*2;
            ++oper;
        }
        c=j;
    }
    if(oper<=k)
    cout<<"Yes\n";
    else cout<<"No\n";
    return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define Int int64_t
 
using namespace std;
 
int main() {
	int N, T;
	cin >> N >> T;
	vector<int> A(N), B(N);
	vector<pair<int, int>> AB;
	for (int i = 0; i < N; ++i) {
		cin >> A[i] >> B[i];
		AB.emplace_back(A[i], B[i]);
	}
	sort(AB.begin(), AB.end());
 
	int sz = 6500;
	vector<vector<int>> dp(N, vector<int>(sz, -1));
	dp[0][0] = 0;
	dp[0][AB[0].first] = AB[0].second;
	for (int i = 1; i < N; ++i) {
		int a = AB[i].first, b = AB[i].second;
		for (int j = 0; j < sz; ++j) {
			dp[i][j] = max(dp[i][j], dp[i - 1][j]);
			if (j - a >= 0 && dp[i - 1][j - a] >= 0 && j - a < T) {
				dp[i][j] = max(dp[i][j], dp[i - 1][j - a] + b);
			}
		}
	}
 
	int ans = 0;
	for (int i = 0; i < N; ++i) {
		for (int j = 0; j < min(T + AB[i].first, sz); ++j) {
			ans = max(ans, dp[i][j]);
		}
	}
	cout << ans << endl;
 
	return 0;
}

Measured memory_bytes: 76672
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define all(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
int main(){
    int D;
    cin>>D;
    vector<int> c(26);
    rep(i,26){
        int tmp=0;
        cin>>tmp;
        c[i]=tmp;
    }
    vector<vector<int>> s(D,vector<int>(26));
    vector<int> last(26,0);//最後にiのテストをやってからの経過日数とする
    rep(i,D){
        rep(j,26){
            int stmp=0;
            cin>>stmp;
            s[i][j]=stmp;
        }
    }
    vector<int> ans;
    //減少量が一番少なくなるように割り当てる
    //作戦.「(テストiをやった時の増加量-残りのテストに対する減少量)が一番多いテストをやる」

    rep(i,D){
        //i日目にやるやつを決める
        int testnum=0;
        long long  minusmax=0;
        long long minusmaxtmp=-100000000000;
        rep(j,26){
            //テストjをやった時の満足度の増減量を調べる
            minusmax=s[i][j];
            rep(k,26){
                if(k!=j){
                    minusmax+=-1*c[k]*(last[k]+1);//もしやらなかったらなので1足す
                }
            }
            if(minusmax>minusmaxtmp){
                testnum=j;
                minusmaxtmp=minusmax;
            }
        }
        //i日目にtestnum番のテストをやることに決めたので
        //testnum番以外のlastを1増やす,testnum番は0に戻る
        rep(j,26){
            if(j!=testnum){
                last[j]++;
            }else{
                last[j]=0;
            }
        }
        ans.push_back(testnum+1);

    }
    rep(i,D){
        cout << ans[i] << endl;
    }

    return 0;
}


Measured memory_bytes: 3656
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<cassert>
#define llong long long
using namespace std;

const int N = 4e3;
const int P = 1e9+7;
llong dp[N+3][N+3],sdp[N+3][N+3];
int n1,n2,m,len;
llong ans;

int main()
{
	scanf("%d%d%d",&n1,&n2,&m); len = (n1+n2-1)/(m-1);
	dp[0][0] = 1ll; for(int j=0; j<=n1; j++) sdp[0][j] = 1;
	for(int i=1; i<=len; i++)
	{
		for(int j=0; j<=n1; j++)
		{
			if(j>=m) {dp[i][j] = (sdp[i-1][j]-sdp[i-1][j-m]+P)%P;}
			else {dp[i][j] = sdp[i-1][j];}
			if((n1-j)%(m-1)==0 && i*(m-1)-j<=n2-1 && (n2-1-i*(m-1)+j)%(m-1)==0) {ans = (ans+dp[i][j]-dp[i-1][j]+P)%P;}
		}
		sdp[i][0] = dp[i][0]; for(int j=1; j<=n1; j++) sdp[i][j] = (sdp[i][j-1]+dp[i][j])%P;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 249600
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string> 
using namespace std;
int baohan(string s,int len,string key){
	s.erase(s.begin()+len,s.begin()+len+(s.length()-7));
	if(s == key)
		return 1;
	else 
		return 0; 
}
int main(){
	string s;
	string key = "keyence";
	cin>>s;
	int l = s.length();
	int f = 0;
	for(int i=0;i<s.length()-(l-7);i++){
		if(baohan(s,i,key) == 1){
			f = 1;
			break;
		}
	}
	if(f == 1)
		cout<<"YES"<<endl;
	else 
		cout<<"NO"<<endl;
	return 0;
}

Measured memory_bytes: 256