akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<iomanip>
typedef long long int ll;
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define REP(i,n) for (int i=0;i<(n);i++)
#define EREP(i,n) for (int i=1;i<=(n);i++)
#define ALL(a) (a).begin(),(a).end()
#define EVEL 1

#ifndef EVEL
#define DEB(X) cout << #X << ":" <<X<<" " ;
#define TF(f) f ? cout<<"true  " : cout<<"false ";
#define END cout<<"\n";
#else
#define DEB(X) {}
#define TF(f) {}
#define END {}
#endif
const int MOD = 1000000007;
const int INF = 2000000000;
    int ans=0,id;
    int N,M;
    ll A,B,C,W;
    vector<int> G[100];
    ll sum=0;

int main(){
    ios_base::sync_with_stdio(false);
    cin>>N>>M;
    REP(i,M){
        cin>>A>>B;
        G[A-1].push_back(B-1);
        G[B-1].push_back(A-1);
    }
    REP(i,N){
        cout<<G[i].size()<<endl;
    }


    //cout<<ans;

    return 0;
}

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

using namespace std;

using ll = long long;
using ld = long double;

#define st first
#define nd second

const int MAXN = 1e6 + 5, inf = 1e9, mod = 1e9 + 7;
const ll INF = 1e18, MOD = 1e15 + 37;
const ld PI = acos(-1);

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout << setprecision(13) << fixed;

    //////////////////////////////////////////
    //////////////////////////////////////////

    int a;
    cin >> a;
    cout << a + a * a + a * a * a << "\n";
}


Measured memory_bytes: 3636
import std.stdio;
import std.conv;
import std.string;
import std.format;
import std.algorithm;

void compare(int a, int b, int c) {

  int[] array = [a, b, c];
  sort!("a < b")(array);
  write(array[0]);
  write(" ");
  write(array[1]);
  write(" ");
  writeln(array[2]);
}

void main()
{
  string s = chomp(readln());
  int a = to!int(s.split(" ")[0]);
  int b = to!int(s.split(" ")[1]);
  int c = to!int(s.split(" ")[2]);
  compare(a, b, c);
}

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


#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;

li res[111][111];
li h, w, n;
li a[1111111];

inline PI next(PI now) {
    if (now.F % 2 == 0) {
        // from left to right
        if (now.S < w - 1) {
            return mp(now.F, now.S + 1);
        } else {
            return mp(now.F + 1, now.S);
        }
    } else {
        // from right to left
        if (now.S == 0) {
            return mp(now.F + 1, now.S);
        } else {
            return mp(now.F, now.S - 1);
        }
    }
}

int main() {
    cin >> h >> w >> n;
    rin{cin >> a[i];}
    PI now = mp(0, 0);
    li color_now = 1;
    li num_now = 0;
    rep(i, w * h) {
        res[now.F][now.S] = color_now;
        ++num_now;
        if (num_now >= a[color_now - 1]) {
            num_now = 0;
            color_now++;
        }
        now = next(now);
    }
    rep(i, h) {
        rep(j, w) {
            cout << res[i][j] << " ";
        } cout << endl;
    }

    return 0;
}

Measured memory_bytes: 512
#include <stdio.h>


const int mod = 1000000007;

char s[100001];

int dp[2][13];

int main(){
  int i, j, k, r, b, d, l;
  scanf("%s", s);

  for(l = 0; s[l]; l++) ;

  r = 5;
  dp[0][0] = 1;
  b = 0;
  d = 1;
  for(i = l - 1; i >= 0; i--, d = d * 10 % 13){
    if(s[i] != '?'){
      r -= (s[i] - '0') * d;
      continue;
    }
    for(k = 0; k < 13; k++){
      for(j = 0; j < 10; j++){
        dp[b^1][(j * d + k) % 13] += dp[b][k];
        if(dp[b^1][(j * d + k) % 13] >= mod) dp[b^1][(j * d + k) % 13] -= mod;
      }
    }
    for(k = 0; k < 13; k++) dp[b][k] = 0;
    b ^= 1;
  }

  r %= 13;
  if(r < 0) r += 13;

  printf("%d\n", dp[b][r]);
  
  return 0;
}


Measured memory_bytes: 384
N = int(input())
fugou = 1
ans = ''
if N == 0:
    ans = '0'
else:
    q = N
    while q!= 0:
        if q > 0:
            r = q%2
            q = (-1)*(q//2)
        else:
            q = -q
            r = q%2
            if r == 0:
                q = q//2
            else:
                q = q//2+1
        ans += str(r)
print(ans[::-1])

Measured memory_bytes: 3060
/*----------------by syr----------------*/
/*

         iii                  ii
     rBQBBBBBBE       BBR iBBBBQBBL     XBBBBBBQBBBBB
   iBBQJ    7BBB      BBsSBBr   BBQ      i      cBBB
  rBBU       iBBw     BBBQi     HBBi           KBBi
  BBH         BB5    iBBB       isL          wBB5
 GBB         iBBi    6BB                   iBBB
 BBQ         BQB     BBD                  QBBi
 BBB        BQB     iQBi                1BBv
 sBBg     wBBB      QBB               iBBB
  7BBBBBBBBBi       BBR              wBBBBBBBBBBBBB
     irvi           ii               ii    i i iii
                i5U
               BBB
               BB7
              1BB
      iPBBBBBKBBR    JBR1       rQBO   BR  UBQP  iBBQi
    7BBBGs7sXBBBi     QBBr     gBBE   rBB BB2BB7HBZQBB
   QBBi      sBQ       BBB   iBBB     SQBBR  BBBB  cBQ
  gBQ        BBg        BBB KBBi      MBBH   BBB   BBs
 iBBv       iBBi         QBBBL        BBR   pBB   iBB
 pBB        BBB         iBBBB        iBB    BBL   KBB
 MBB       BBBR        BBB JBBi      DBR   iBQ    BBL
 GBB     7BBBB2      PBBH   BBBi     BQr   DBB   iBB
  BQBXwgBBP BB7    1BBB      BBQ7   1BB    BBc   BBB
   2BBBBw   BB    EBBS        QBBi  HBa   iBB    BB7
*/
#include<bits/stdc++.h>

using namespace std;

#define PH push
#define MP make_pair
#define PB push_back
#define fst first
#define snd second
#define FOR(i,x,y) for(int i=(x);i<(y);++i)
#define REP(i,x,y) for(int i=(x);i<=(y);++i)
#define x0 x0123456789
#define y0 y0123456789
#define x1 x1234567890
#define y1 y1234567890
#define x2 x2345678901
#define y2 y2345678901
typedef double db;
typedef long long ll;
typedef long double ldb;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const int INF=998244353;
const int maxn=305;
const int maxs=305*305;

/*
Consider those cannot form a triangle.
The condition holds: R+G<=B (don't mind the order here
If we know R+G, we can calc B
then we know any way with this R+G is illegal
dp[i][j]:
	the ways of choosing some ints with a sum of j among the first i ints,
	and divide them into two colours
dp[i][j]=dp[i-1][j-a[i]]*2+dp[i-1][j]
then for each B we know number of the illegal ways
here B>=S/2, where S is the sum of all ints
but when R=B or G=B, we will calc the ways twice
also because B>=S/2, this happened only when B=G=S/2 and R=0
*/

int n,s;
int a[maxn];
ll ans=1;
ll dp[maxn][maxs];

int main(){
	scanf("%d",&n);
	FOR(i,0,n) scanf("%d",a+i),s+=a[i];
	dp[0][0]=1;
	FOR(i,0,n) FOR(j,0,maxs)
		if(j>=a[i]) dp[i+1][j]=((dp[i][j-a[i]]<<1)%INF+dp[i][j])%INF;
		else dp[i+1][j]=dp[i][j];
	FOR(i,0,n) (ans*=3)%=INF;
	for(int i=0;(i<<1)<=s;++i){
		ans-=(dp[n][i]*3)%INF;
		(ans+=INF)%=INF;
	}
	if(!(s&1)){
		FOR(i,0,n) FOR(j,0,maxs) dp[i][j]=0;
		dp[0][0]=1;
		FOR(i,0,n) FOR(j,0,maxs)
			if(j>=a[i]) dp[i+1][j]=(dp[i][j-a[i]]+dp[i][j])%INF;
			else dp[i+1][j]=dp[i][j];
		ans+=(dp[n][s/2]*3);
		ans%=INF;
	}
	printf("%lld\n",ans);
	return 0;
}



Measured memory_bytes: 219392
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int k, l;
    cin >> k >> l;
    function<int(int, int)> gcd = [&](int i, int j) {
        if(i > j) swap(i, j);
        if(i == 0) {
            return j;
        }
        return gcd(i, j%i);
    };

    cout << gcd(k, l) << endl;
}


Measured memory_bytes: 3160
import math
text=input().split()
for i,v in enumerate(text):
    text[i]=int(v)
while text[0] or text[1]:
    for i in range(text[0]):
        if i==0 or i==text[0]-1:
            print('#'*text[1])
        else:
            print('#'+'.'*(text[1]-2)+'#')
    text=input().split()
    print()
    for i,v in enumerate(text):
        text[i]=int(v)



Measured memory_bytes: 5672
#include<stdio.h>
#include<math.h>
#include<algorithm>

using namespace std;
const int INF = 1001001001;
#define rep(i,n) for(int i=0;i<n;i++)
int M,N,K;
char map[1002][1002];
int rmap[1002][1002][3];


int main(){
	scanf("%d %d",&M,&N);
	scanf("%d",&K);
	rep(i,3){rmap[0][0][i]=0;}
	/////
	rep(i,M){
		rep(j,N){
			char a;
			scanf("%c",&a);
			if(a==10){scanf("%c",&a);}
			int s=0;
			map[i][j]=a;
			if(map[i][j]=='J')s=0;
			else if(map[i][j]=='O')s=1;
			else s=2;
			rep(k,3){
				int p=(int)(s==k);
				if(i==0&&j==0){
					rmap[i][j][k]+=p;
				}else if(i==0){
					rmap[i][j][k]+=rmap[i][j-1][k]+p;
				}else if(j==0){
					rmap[i][j][k]+=rmap[i-1][j][k]+p;
				}else{
					rmap[i][j][k]+=rmap[i][j-1][k]+rmap[i-1][j][k]-rmap[i-1][j-1][k]+p;
				}
			}
		}
	}
	rep(i,K){
		int a,b,c,d;
		scanf("%d %d %d %d",&a,&b,&c,&d);
		a--;b--;c--;d--;
		rep(j,3){
			int ans=rmap[c][d][j];
			if(a>0)ans-=rmap[a-1][d][j];
			if(b>0)ans-=rmap[c][b-1][j];
			if(a>0&&b>0)ans+=rmap[a-1][b-1][j];
			printf("%d",ans);
			if(j!=2)printf(" ");
		}
		printf("\n");
	}


}

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

#define ll long long
#define endl "\n"

ll a[10000005],dp[10000005],n;


ll solve(ll a[], ll i){
  	if(i==n-1)
      return 0;
    if(i>=n)
      	return INT_MAX;
    if(dp[i]!=-1)
      	return dp[i];     
    ll left=abs(a[i]-a[i+1])+solve(a,i+1);
  	ll right=INT_MAX;
  	if(i+2<n){
      right=abs(a[i]-a[i+2])+solve(a,i+2);
    }
    return dp[i]=min(left,right);
}

int main(){
  memset(dp,-1,sizeof(dp));
  cin >> n;
  for(ll i=0;i<n;i++)	cin >> a[i];
  cout << solve(a,0) << endl;
  return 0;
}

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

int main()
{
    int n,m;
    cin>>n>>m;
    long long sum=0;
    vector<int> v[100001];
    priority_queue<int> pq ;
    for(int i=0 ; i<n ; i++)
    {
        int r , d ;
        cin>>d>>r;
        v[d].push_back(r);
    }
    for(int i=1 ; i<=m  ; i++)
    {
        for(int j=0 ; j<v[i].size() ; j++)
        {
           pq.push( v[i][j] );
        }
        if( pq.size() !=0 ){
        sum+=pq.top();
        pq.pop();}
    }
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 5632
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
#define NMAX 50000
#define MMAX 20
#define INF 2e6
int c[MMAX] = {};
int dp[NMAX+1] = {};

int main() {
	int n,m;
	cin >> n >> m;
	
	for (int i=0;i<m;i++) {
	cin >> c[i];
	}

	dp[0] = 0;	
	for (int i=1;i<=n;i++) {
	dp[i] = INF;
	}
	
	for (int i=0;i<=n;i++) {
	for (int j=0;j<m;j++) {
	if (i>=c[j]) {
	dp[i] = min (dp[i], dp[i-c[j]] + 1);
	}
	}
	}
	

/*	for (int i=0;i<=n;i++) {
	cout << "dp " << dp[i] << endl;
	}
*/
	
	cout << dp[n] << endl;
	return 0;
}

Measured memory_bytes: 3288
import std.stdio;
import std.algorithm;
import std.conv;
import std.string;
import std.array;
import std.math;

void main(){
  readln();
  int[] monster = readln().chomp.split.map!(to!int).array;
  int min_mon;

  while(true){
    monster = monster.uniq.array;
    if(monster.length == 1){break;}
    min_mon = monster.reduce!min;
    monster = monster.map!(x=>x%min_mon==0?min_mon:x%min_mon).array;
  }

  monster[0].writeln;
}

Measured memory_bytes: 4916
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define show(a, n) rep(i,n) {cout<<a[i]<<' ';} cout<<endl;

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<long long, long long> pll;

const int INF = 1 << 30;
const long long INFL = 1LL << 62;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 100010;

int main() {
	char x, y;
	cin >> x >> y;
	char ans;
	if(x < y) ans = '<';
	else if(x > y) ans = '>';
	else ans = '=';
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <queue>
#define rep(i,n) for(int i=0; i<(n); ++i)
#define outl(x) cout<< (x) << '\n'
using namespace std;
using let = const int;

int V, E;
bool vis[10005];
vector <int> G[10005];
vector <int> out;

void bfs(let s, int *indeg)
{
   queue <int> que; que.emplace(s);
   while (!que.empty()) {
      let u = que.front(); que.pop();
      out.emplace_back(u);
      for(let x : G[u]) if( --indeg[x] == 0 && !vis[x]++ ) que.emplace(x);
   }
}

void topologial_sort()
{
   static int indeg[10005] = {};
   rep(i, V)
      for(let x: G[i]) ++indeg[x];
   rep(i, V)
      if (indeg[i] == 0 && !vis[i]++) bfs(i, indeg);

   for_each(out.cbegin(), out.cend(), [](let x) { outl( x ); });
}

signed main()
{
   cin.tie(0), ios::sync_with_stdio(false);
   cin >> V >> E;

   while(E--) {
      int s, t;
      cin >> s >> t;
      G[s].emplace_back(t);
   }

   topologial_sort();
}




Measured memory_bytes: 3880
//Love and Freedom.
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define ll long long
#define inf 20021225
using namespace std;

int n,p[110],a,b;
int main()
{
	int la,lab,lb; la = lab = lb =0;
	scanf("%d%d%d",&n,&a,&b);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&p[i]);
		if(p[i]<=a)	la++;
		else if(p[i]<=b)	lab++;
		else	lb++;
	}
	printf("%d\n",min(min(la,lab),lb));
	return 0;
}


Measured memory_bytes: 128
from sys import stdin, setrecursionlimit
from collections import Counter, deque, defaultdict
from math import floor, ceil
from bisect import bisect_left
from itertools import combinations
setrecursionlimit(100000)

class UnionFind(object):
    def __init__(self, n):
        self.par = [-1] * n
    
    def find(self, x):
        if self.par[x] < 0:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        
        if x == y:
            return False
        else:
            if self.par[x] > self.par[y]:
                x, y = y, x
            self.par[x] += self.par[y]
            self.par[y] = x
            return True

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def size(self, x):
        return -self.par[self.find(x)]

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.par) if x < 0]

    def group_count(self):
        return len(self.roots())

def main():
    from builtins import int, map
    N, M = map(int, input().split())
    uf = UnionFind(N)
    for _ in range(M):
        ai, bi = map(lambda x: int(x) - 1, input().split())
        uf.unite(ai, bi)

    # 最大のグループサイズ
    ans = -1
    for n in range(N):
        ans = max(ans, uf.size(n))
        # print(n, uf.size(n))
    print(ans)

if __name__ == '__main__':
    main()

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

int main(){
  int A,B,C;
  cin >> A >> B >> C;
  if(A == B){
  cout << C << endl;
  }
if(A == C){
cout << B << endl;
}
  if(B == C){
cout << A << endl;
  }
}


Measured memory_bytes: 3624
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 2e5 + 10;
int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int n, m, d;
	cin >> n >> m >> d;
	double ans = (m - 1)*2.0*(n - d) / n / n;
	if (0 == d) ans /= 2;
	printf("%.15f\n", ans);
	return 0;
}

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

/*
提出前に確認!
- setとmultisetを間違えない
*/

int	main(void)
{
	int ans = 0;
	string n;
	cin >> n;
	for (int i = 0; i < n.size(); i++)
	{
		ans += n[i] - '0';
		ans %= 9;
	}
	if (ans == 0) cout << "Yes" << endl;
	else cout << "No" << endl;
	return (0);
}


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

using namespace std;

int main()
{
    int t;
    cin >> t;
    string s;
    cin >> s;
    if(s.size()==1)
    {
        cout << "No" << endl;
    }
    else if(s.size()%2==0)
    {
        int l = s.size()/2;
        //cout << l << endl;

        string f,ss;

        f = s.substr(0,l);
        ss = s.substr(l,s.size());
        //cout << f << " " << ss << endl;
        if(f==ss)
        {
            cout << "Yes" << endl;
        }
        else
        {
            cout << "No" << endl;
        }
    }
    else
    {
        cout << "No" << endl;
    }



}


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

const int N = 200005;
const long long mod = 998244353ll, Inv2 = mod + 1 >> 1;

long long qpow(long long a, long long b) {
	long long res = 1ll;
	for (; b; b >>= 1, a = a * a % mod) {
		if (b & 1) res = res * a % mod;
	}
	return res;
}

int n, k, perm[N];
long long bit[N], ans = 0ll;
int lowbit(int x) {
	return x & -x;
}
struct fenwick {
	long long bit[N];
	void clear() {
		for (int i = 0; i <= n; i++) bit[i] = 0;
	}
	void add(int pos, long long x){
		for (; pos <= n; pos += lowbit(pos)) bit[pos] = (bit[pos] + x) % mod;
	}
	long long query(int pos) {
		long long res = 0;
		for (; pos; pos ^= lowbit(pos)) res = (res + bit[pos]) % mod;
		return res;
	}
} bit1, bit2;

long long inv1, inv2, pw1[N], pw2[N];
int pre[N];
int main() {
	scanf("%d%d", &n, &k);
	for (int i = 1; i <= n; i++) scanf("%d", &perm[i]);

	// We calculate the contribution of (l, r) (1 <= l < r <= n)
	// Part 1 : l <= k
	// Initialize
	ans = (ans + 1ll * k * (k - 1) / 2 % mod * Inv2) % mod;
	inv1 = qpow(k, mod - 2) * (k - 1) % mod;
	inv2 = qpow(inv1, mod - 2);
	pw1[0] = 1ll, pw2[0] = 1ll;
	for (int i = 1; i <= n; i++) {
		pw1[i] = pw1[i - 1] * inv1 % mod;
		pw2[i] = pw2[i - 1] * inv2 % mod;
	}
	for (int i = 0; i <= n; i++) pre[i] = 0;
	for (int i = 1; i <= k; i++) pre[perm[i]] = 1;
	for (int i = 1; i <= n; i++) pre[i] += pre[i - 1];
	for (int i = k + 1; i <= n; i++) {
		// p_l < p_r
		ans = (ans + Inv2 * pw1[i - k] % mod * pre[perm[i]]) % mod;
		// p_l > p_r
		ans = (ans + (k - pre[perm[i]])) % mod;
		ans = (ans + mod - Inv2 * pw1[i - k] % mod * (k - pre[perm[i]]) % mod) % mod;
	}

	// Part 2: l > k
	bit1.clear(), bit2.clear();
	for (int i = k + 1; i <= n; i++) {
		// p_l < p_r
		ans = (ans + Inv2 * pw1[i] % mod * bit2.query(perm[i])) % mod;
		// p_l > p_r
		ans = (ans + bit1.query(n) - bit1.query(perm[i])) % mod;
		ans = (ans + mod - Inv2 * pw1[i] % mod * (bit2.query(n) + mod - bit2.query(perm[i])) % mod) % mod;
		bit1.add(perm[i], 1), bit2.add(perm[i], pw2[i]);
	}
	printf("%lld\n", ans);
	return 0;
}

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

const int mod = 998244353;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

int main(){
    int n,k;
    cin>>n>>k;
    vector<int> l(k),r(k);
    vector<mint> dp(n+5),sum(n+5);
    rep(i,k) cin>>l[i]>>r[i];
    dp[1]=1;sum[1]=1;
    for(int i=2;i<=n;i++){
        rep(j,k){
            int a=i-r[j];
            int b=i-l[j];
            a=max(a,1);
            if(b<0) continue;
            dp[i]+=sum[b]-sum[a-1];
        }
        sum[i]=dp[i]+sum[i-1];
    }
    cout<<dp[n]<<endl;
    return 0;
}

Measured memory_bytes: 6388
//#include<bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<numeric>
#include<vector>
#include<set>
#include<map>
#include<unordered_map>
#include<stack>
#include<queue>
#include<list>
using namespace std;

typedef long long ll;

#define MOD 1000000007

class Comb{
private:
  ll *fac,*finv,*inv;
public:
  Comb(){
    fac = new ll[1000000];
    finv = new ll[1000000];
    inv = new ll[1000000];
    fac[0] = 1;
    for(int i=1;i<1000000;i++){
      fac[i] = i*fac[i-1];
      fac[i] %= MOD;
    }
    inv[1] = 1;
    for(int i=2;i<1000000;i++){
      inv[i] = MOD-inv[MOD%i]*(MOD/i)%MOD;
    }
    finv[0] = 1;
    for(int i=1;i<1000000;i++){
      finv[i] = inv[i]*finv[i-1];
      finv[i] %= MOD;
    }
  }
  ll calc(ll n,ll k){
    ll c = fac[n];
    c *= finv[k];c %= MOD;
    c *= finv[n-k];c %= MOD;
    return c;
  }
};

int main(){
  char x;
  cin >> x;
  x++;
  cout << x << 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 repp(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define repm(i,n) for(int (i)=(n);(i)>0;(i)--)
#define INF (1ll<<60)
typedef long long lint;
const lint MOD =1000000007;
const lint MAX = 10000000;

 
lint fac[MAX], finv[MAX], inv[MAX];

void COMinit() // 二項係数を求める時は前処理としてCOMinit()をする
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (lint i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
// 二項係数計算
long long COM(lint n, lint k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

lint primary(lint num)
{
    if (num < 2) return 0;
    else if (num == 2) return 1;
    else if (num % 2 == 0) return 0; // 偶数はあらかじめ除く

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

    // 素数である
    return 1;
}


int main(){
   lint N;
   string s;
   cin>>N>>s;
   pair <lint,lint>left[N];
   pair <lint,lint>right[N];
   if(s[0]=='W')left[0]=make_pair(1,0);
   if(s[0]=='E')left[0]=make_pair(0,1);
   if(s[N-1]=='W')right[N-1]=make_pair(1,0);
   if(s[N-1]=='E')right[N-1]=make_pair(0,1);
   
   rep(i,N-1){
       lint s1,v;
       tie(s1,v)=left[i];
    if(s[i+1]=='W')s1++;
   if(s[i+1]=='E')v++;
   left[i+1]=make_pair(s1,v);
   }
   repm(i,N-1){
       lint s1,v;
       tie(s1,v)=right[i];
    if(s[i-1]=='W')s1++;
   if(s[i-1]=='E')v++;
   right[i-1]=make_pair(s1,v);
   }
   lint ans=INF;
    rep(i,N){
        lint a,b,c,d;
        tie(a,b)=left[i];
        tie(c,d)=right[i];
        ans=min(ans,a+d);
    

    }
 
    cout<<ans-1;

}

Measured memory_bytes: 9988
#![allow(non_snake_case)]
#![allow(unused_imports)]

use proconio::input;

fn main() {
    input! {
        n: u64,
    }

    let MOD: usize = 10usize.pow(9) + 7;

    let mut x = 1;
    let mut y = 1;
    let mut z = 1;
    for _ in 0..n {
        y = y * 9 % MOD;
        x = x * 10 % MOD;
        z = z * 8 % MOD;
    }
    y = 2 * y % MOD;
    println!("{}", (MOD + x + z - y) % MOD);
}


Measured memory_bytes: 2152
#include <iostream>
using namespace std;
int n,t,kq,s;
int gcd(int a,int b)
{
    int tmp;
    while(b!=0)
    {
        tmp=a%b;
        a=b;
        b=tmp;
    }
    return a;
}
int main()
{
    cin>>n;
    for (int i=1;i<=n;i++)
    {
        for (int j=1;j<=n;j++)
        {
            for (int k=1;k<=n;k++)
            {
                t=gcd(i,j);
                kq=gcd(k,t);
                s+=kq;
            }
        }
    }
    cout<<s;
    return 0;
}


Measured memory_bytes: 3632
import sys
import heapq
import math
import fractions
import bisect
import itertools
from collections import Counter
from collections import deque
from operator import itemgetter
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

n=int(input())
a=lmp()
s=[0]*n
s[0]=a[0]
for i in range(1,n):
    s[i]=s[i-1]+a[i]
s.append(0)
q=Counter(s).values()

ans=0
for i in q:
    ans+=i*(i-1)//2
print(ans)

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



int main() {
  string b;
  cin>>b;
  if(b=="A"){
    cout<<"T"<<endl;
  }
    if(b=="T"){
    cout<<"A"<<endl;
  }
    if(b=="G"){
    cout<<"C"<<endl;
  }
    if(b=="C"){
    cout<<"G"<<endl;
  }
}

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

const int N = 100000 + 10;
int n, B[N], A[N];
int main() {
//  freopen(".in","r",stdin);
//  freopen(".out","w",stdout);
	cin >> n;
	for(int i = 1; i < n; i++) cin >> B[i];
	memset(A, 0x3f, sizeof(A));
	for(int i = 1; i < n; i++) A[i] = min(A[i], B[i]), A[i + 1] = min(A[i + 1], B[i]);
	cout << accumulate(A + 1, A + n + 1, 0) << endl; 
	return 0;
}


Measured memory_bytes: 640
n,k=map(int,input().split())
import math

ans = 0
if n >(k-1):
    ans += (n-k+1)/n

for i in range(1,min(k,n+1)):
    if math.log(k/i,2)-int(math.log(k/i,2))== 0:
        p = int(math.log(k/i,2))
    else:
        p = int(math.log(k/i,2))+1
    ans +=(1/n)*(0.5**p)
print(ans)

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

int main() {
    int N;
    char S[200010];
    char S_copy[200010];
    cin >> N;
    cin >> S;
    char black = '#';
    char white = '.';
    int black_cnt = 0;
    int white_cnt = 0;

   
    for(int i = 0; i < N; i++) {
        if (S[i] == white) white_cnt++;
    }

    int res = black_cnt + white_cnt;
    for (int i=0; i < N; i++) {
        if (S[i] == black) {
            black_cnt++;   
        } else {
            white_cnt--;
        }
        res = min(res, black_cnt + white_cnt);
    }
    cout << res << "\n";
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define MOD 1000000007
#define PI 3.141592653589793

int main(){
    string s;
    cin >> s;
    int ans = 700;
    for(auto c: s){
        if(c == 'o')
            ans += 100;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
import scala.collection.mutable

object Main extends App {

  import scala.io.StdIn._
  solve
  def solve: Unit = {
    val Array(n, m) = readLine.trim.split(' ').map(_.toInt)
    if (n != 0 && m != 0){
      val state = Array.tabulate(m){_ ⇒ readLine.trim.toCharArray.map(State(_))}
      val memo = Array.tabulate(m){_ ⇒ Array.tabulate(n){_ ⇒ Int.MaxValue}}
      val queue: mutable.PriorityQueue[(Coordinate, Int)] = mutable.PriorityQueue[(Coordinate, Int)]()(Ordering.by[(Coordinate, Int), Int](_._2).reverse)
      for (y ← 0 until m) {
        memo(y)(0) = 0
        memo(y)(n - 1) = 0
        queue.enqueue(Coordinate(0, y) → 0, Coordinate(n - 1, y) → 0)
      }
      for (x ← 1 until n - 1){
        memo(0)(x) = 0
        memo(m - 1)(x) = 0
        queue.enqueue(Coordinate(x, 0) → 0, Coordinate(x, m - 1) → 0)
      }

      while (queue.head._1.let(c ⇒ state(c.y)(c.x) != Castle)) {
        val (c, d) = queue.dequeue()
        if (memo(c.y)(c.x) == d){
          for (next@Coordinate(x, y) ← c.neighbors){
            if ((0 until n).contains(x) && (0 until m).contains(y)) {
              (state(c.y)(c.x), state(y)(x)) match{
                case (Moat, Moat) if memo(y)(x) > d ⇒ {
                  memo(y)(x) = d
                  queue.enqueue(next → d)
                }
                case (Moat, _) if memo(y)(x) > d + 1 ⇒ {
                  memo(y)(x) = d + 1
                  queue.enqueue(next → (d + 1))
                }
                case (Plane, _) if memo(y)(x) > d ⇒ {
                  memo(y)(x) = d
                  queue.enqueue(next → d)
                }
                case _ ⇒
              }
            }
          }
        }
      }
      println(
        queue.head._2
      )
      solve
    }
  }
  object State{
    def apply(char: Char): State = char match{
      case '&' ⇒ Castle
      case '.' ⇒ Plane
      case '#' ⇒ Moat
      case _ ⇒ throw new Exception
    }
  }
  sealed trait State
  object Moat extends State
  object Castle extends State
  object Plane extends State
  case class Coordinate(x: Int, y: Int) {
    def neighbors: Iterable[Coordinate] = List(Coordinate(0, 1), Coordinate(0, -1), Coordinate(1, 0), Coordinate(-1, 0)).map(_ + this)
    def +(that: Coordinate): Coordinate = Coordinate(this.x + that.x, this.y + that.y)
  }
  implicit class ScopeFunc[T](val value:T){
    def let[A](func: T ⇒ A): A = func(value)
  }
}


Measured memory_bytes: 92228
n = input()
s = map(int, ('+ ' + raw_input()).replace('+ ', '+').replace('- ', '-').split())
s0 = [abs(x) for x in s]
t = filter(lambda x: s[x + 1] < 0, xrange(n - 1)) + [n - 1] * 2
for i in xrange(1, n):
	s[i] += s[i - 1]
	s0[i] += s0[i - 1]
print max([s0[n - 1] - 2 * s0[t[i + 1]] + s0[t[i]] + s[t[i]] for i in xrange(len(t) - 1)])


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

#define endl '\n'
 
using namespace std;
string s=""; 
int dfs(int n,int mask )
{
    if(n==0)
    {
        cout<<s<<endl;

    }
    else
    {
        int i;
        for(i=0;i<26;i++)
        {
            if(mask&(1<<i))
            {
                s+=string(1,i+'a');
                dfs(n-1,mask);
                s.pop_back();
            }
            else
            {
                break;
            }
        }

        s+=string(1,i+'a');
        dfs(n-1,mask|(1<<i));
        s.pop_back();
    }
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    if(fopen("INPUT.txt", "r"))
    {
    freopen ("INPUT.txt" , "r" , stdin);
    freopen ("OUTPUT.txt" , "w" , stdout);
    freopen ("OUTPUT_ERROR.txt" , "w" , stderr);
    }
    int n;
    cin>>n; 
    dfs(n, 0);
}
 

Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int snake[200];
int main(){
    int n,k,d,tmp,ans=0;
    cin>>n>>k;
    for(int i=1;i<=k;i++){
        scanf("%d",&d);
        for(int j=1;j<=d;j++){
            scanf("%d",&tmp);
            snake[tmp]++;
        }
    }
    for(int i=1;i<=n;i++){
        if(snake[i]==0) ans++;
    }
    printf("%d",ans);
}


Measured memory_bytes: 3828
t1,t2 = [int(i) for i in input().split()]
a1,a2 = [int(i) for i in input().split()]
b1,b2 = [int(i) for i in input().split()]

c1,c2 = (a1-b1)*t1,(a2-b2)*t2

if c1 < 0:
    c1 *= -1
    c2 *= -1

if  c1 + c2 == 0:
    print('infinity')
elif c1 + c2 > 0:
    print(0)
else:
    num = -c1 // (c1 + c2)
    print(num * 2 if -c1 % (c1 + c2) == 0 else num * 2 + 1)
    

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

using namespace std;

const int MAXN=100000+10000;
const int INF=0x3f3f3f3f;
int hgt[MAXN],dp[MAXN];
int n;

int main(){
	memset(dp,INF,sizeof(dp));
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",&hgt[i]);
	}
	
	dp[1]=0;
	for(int i=2;i<=n;i++){
		if(i>=2) dp[i]=min(dp[i],abs(hgt[i]-hgt[i-1])+dp[i-1]);
		if(i>=3) dp[i]=min(dp[i],abs(hgt[i]-hgt[i-2])+dp[i-2]);
	}
	printf("%d\n",dp[n]);
	return 0;
}
 

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

int N,D;
int good_distance(vector<int> x,vector<int> y){
  int sum=0;
  for(int i=0;i<D;++i){
    sum=sum+pow(x.at(i)-y.at(i),2);
  }

  for(int m=0;pow(m,2)<=sum;++m){
    if(pow(m,2)==sum){
      return 1;
    }
  }

  return 0;
}

int main(){

  cin>>N>>D;
  vector<vector<int>> X(N,vector<int>(D));
  for(int i=0;i<N;++i){
    for(int j=0;j<D;++j){
      cin>>X.at(i).at(j);
    }
  }

  int ans;
  for(int i=0;i<N;++i){
    for(int j=i+1;j<N;++j){
      ans=ans+good_distance(X.at(i),X.at(j));
    }
  }

  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <iomanip>
#include <map>
#include <set>
#include <tuple>
#include <unordered_map>
#include <iterator>
#include <string>

using namespace std;

using i64 = int64_t;
using P = pair<i64, i64>;
i64 mod = 1000000007;
int int_max = 2147483647;
int max_n = 1e5;


int main(int argc, char **argv) {
    i64 n, k;
    cin >> n >> k;

    double sum{0};
    std::vector<int> v(n);
    for (i64 i = 0; i < n; ++i) {
        cin >> v[i];
    }

    for (i64 i = 0; i < k; ++i) {
        sum += (v[i]+1)/2.;
    }
    double max=sum;
    size_t max_start{0}, max_end{static_cast<size_t>(k)-1};

    for (size_t start=1, end=k; end<n; ++start, ++end) {
        sum += (v[end]+1)/2.; sum -= (v[start-1]+1)/2.;
        if (sum > max) {
            max_start = start; max_end = end; max = sum;
        }
    }

    cout << std::setprecision(10)<< max << endl;

    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
typedef long long ll;

int main(int argc, char const *argv[]) {
    std::string s;
    std::cin >> s;
    std::string ans;
    for (size_t i = 0; i < s.size(); i++) {
        if (s[i] == 'B') {
            if (!ans.empty()) {
                ans.pop_back();
            }
        } else {
            ans.push_back(s[i]);
        }
    }
    std::cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int a,b,c=1001;
  scanf("%d %d",&a,&b);
  for(int i=0; i<a; i++){
    int d,e;
    scanf("%d %d",&d,&e);
    if(c>d&&b>=e){
      c=d;
    }
  }
  if(c<=1000){printf("%d",c);}else{printf("TLE");}
  return 0;}

Measured memory_bytes: 128
#include <stdio.h>
#include <limits.h>

int main() {
    int arr[3], temp, min = INT_MAX, max = INT_MIN;
    scanf("%d %d %d", &arr[0], &arr[1], &arr[2]);
    for (int i = 0; i < 3; i++){
        if (arr[i] > max){
            max = arr[i];
        }
        if (arr[i] < min){
            min = arr[i];
        }
    }
    printf("%d %d\n", min, max);
}


Measured memory_bytes: 2108
#include <iostream>
#include <vector>
#include <numeric>

using namespace std;

class Solution{

public:
    int mincost(const vector<int>& nums){

        int a = nums.size();
        int b = -2 * accumulate(nums.begin(), nums.end(), 0);
        int c = 0;
        for(int e: nums) c += e * e;

        int x1 = (-b) / (2 * a), x2 = x1 + 1;
        return min(a * x1 * x1 + b * x1 + c, a * x2 * x2 + b * x2 + c);
    }
};

int main() {

//    vector<int> nums1 = {4, 8};
//    cout << Solution().mincost(nums1) << endl;
//    // 8
//
//    vector<int> nums2 = {1, 1, 3};
//    cout << Solution().mincost(nums2) << endl;
//    // 3
//
//    vector<int> nums3 = {4, 2, 5};
//    cout << Solution().mincost(nums3) << endl;
//    // 5
//
//    vector<int> nums4 = {-100, -100, -100, -100};
//    cout << Solution().mincost(nums4) << endl;
//    // 0

    int N;
    scanf("%d", &N);

    vector<int> nums(N);
    for(int i = 0; i < N; i ++) scanf("%d", &nums[i]);
    printf("%d\n", Solution().mincost(nums));

    return 0;
}


Measured memory_bytes: 3192
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#include <algorithm>
using namespace std;
typedef long long ll;
typedef pair<int, int> p;
const int inf = 1001001001;


int main(){
  int a,b,c;
  cin >> a >> b >> c;
  
  string ans = "Yes";
  
  if(a == b && a == c) ans ="No";
  if(a != b && b != c && c != a) ans ="No";
  
  cout << ans << endl;
  
  
  
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
    int i, j;

    int n, m;
    scanf("%d%d", &n, &m);
    int A[n][m], B[m];
    for( i = 0; i < n; ++i )
        for( j = 0; j < m; ++j )
            scanf("%d", &A[i][j]);
    for( i = 0; i < m; ++i )
        scanf("%d", &B[i]);

    int x[n];
    for( i = 0; i < n; ++i ) x[i] = 0;
    for( i = 0; i < n; ++i )
        for( j = 0; j < m; ++j )
            x[i] += A[i][j] * B[j];

    for( i = 0; i < n; ++i )
        printf("%d\n", x[i]);

    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define start_routine() int begtime = clock();
#define end_routine() int endtime = clock(); cerr << endl << "Time elapsed: " << (endtime - begtime)*1000/CLOCKS_PER_SEC << " ms"; return 0
#define speed() cin.tie(0), cout.tie(0), ios_base::sync_with_stdio(false)
// #define exit(a, b) return cout << a, b;

#define loop(i,a,b) for(ll i=a;i<b;i++)
#define all(v) v.begin(), v.end() 

#define print(stuff) cout << stuff << endl
#define len length
#define ret0 return 0
#define ret return 

#define ll long long
#define ld long double
#define fi first
#define endl '\n'
#define se second
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound

#define vl vector<ll> 
#define sl set<ll>
#define pll pair<ll, ll>
#define mll map<ll, ll> 
#define pq priority_queue<ll>

// typedef tree<ll,null_type,less<ll>,rb_tree_tag,
// tree_order_statistics_node_update> indexed_set;

#define inf (long long int) 1e18
#define eps 0.000001
#define mod 1000000007
#define mod1 998244353
#define MAXN 100001

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

    ll a, b;
    cin>>a>>b;
    if(a>=13) print(b);
    else if(a>=6 && a<=12) print(b/2);
    else if(a<=5) print(0);
        
    
}



Measured memory_bytes: 256
import sys
input = sys.stdin.readline
N, M = map(int, input().split())

N0 = 2**((N+1).bit_length())
INF = 10**18
data = [0]*(2*N0)
lazy = [0]*(2*N0)

def gindex(l, r):
    L = l + N0; R = r + N0
    lm = (L // (L & -L)) >> 1
    rm = (R // (R & -R)) >> 1
    while L < R:
        if R <= rm:
            yield R
        if L <= lm:
            yield L
        L >>= 1; R >>= 1
    while L:
        yield L
        L >>= 1

def propagates(*ids):
    for i in reversed(ids):
        v = lazy[i-1]
        if not v:
            continue
        lazy[2*i-1] += v; lazy[2*i] += v
        data[2*i-1] += v; data[2*i] += v
        lazy[i-1] = 0
        
def update(l, r, x):
    L = N0 + l; R = N0 + r
    while L < R:
        if R & 1:
            R -= 1
            lazy[R-1] += x; data[R-1] += x
        if L & 1:
            lazy[L-1] += x; data[L-1] += x
            L += 1
        L >>= 1; R >>= 1

    for i in gindex(l, r):
        data[i-1] = max(data[2*i-1], data[2*i]) + lazy[i-1]

def update2(k, x):
    k += N0-1
    data[k] = x
    while k >= 0:
        k = (k - 1) // 2
        data[k] = max(data[2*k+1], data[2*k+2])

def query(l, r):
    propagates(*gindex(l, r))
    L = N0 + l; R = N0 + r
    s = -INF
    while L < R:
        if R & 1:
            R -= 1
            s = max(s, data[R-1])
        if L & 1:
            s = max(s, data[L-1])
            L += 1
        L >>= 1; R >>= 1
    return s

xs = [0]*(N+1)
ys = [[] for _ in range(N+1)]
for _ in range(M):
    l, r, a = map(int, input().split())
    xs[l] += a
    ys[r].append((l,a))

rs = [0]*(N+1)
for i in range(1, N+1):
    #[0,i)にxs[i]を加算
    update(0,i,xs[i])
    r = query(0, i)
    update2(i, r)
    rs[i] = r
    for l, a in ys[i]:
        update(0, l, -a)
print(max(rs))


Measured memory_bytes: 97484
/*
If you want to aim high, aim high
Don't let that studying and grades consume you
Just live life young
******************************
What do you think? What do you think?
1st on Billboard, what do you think of it
Next is a Grammy, what do you think of it
However you think, I’m sorry, but shit, I have no fucking interest
*******************************
Higher, higher, even higher, to the point you won’t even be able to see me
https://www.a2oj.com/Ladder16.html
*******************************
NEVER DO 300IQ CONTESTS EVER
300IQ AS WRITER = EXTRA NONO
*/
import java.util.*;
import java.io.*;
import java.math.*;

   public class Main
   {
      public static void main(String omkar[]) throws Exception
      {
         BufferedReader infile = new BufferedReader(new InputStreamReader(System.in));  
         StringTokenizer st = new StringTokenizer(infile.readLine());
         int N = Integer.parseInt(st.nextToken());
         Range[] arr = new Range[N];
         int[] x = new int[N];
         int[] y = new int[N];
         for(int i=0; i < N; i++)
         {
            st = new StringTokenizer(infile.readLine());
            int a = Integer.parseInt(st.nextToken());
            int b = Integer.parseInt(st.nextToken());
            arr[i] = new Range(a,b);
            x[i] = a;
            y[i] = b;
         }
         sort(x);
         sort(y);
         if(N%2 == 1)
            System.out.println(Math.abs(x[N/2]-y[N/2])+1);
         else
         {
            int min = x[N/2]+x[N/2-1];
            int max = y[N/2]+y[N/2-1];
            System.out.println(Math.abs(max-min)+1);
         }
      }
      public static void sort(int[] arr)
      {
         //stable heap sort
         PriorityQueue<Integer> pq = new PriorityQueue<Integer>();
         for(int a: arr)
            pq.add(a);
         for(int i=0; i < arr.length; i++)
            arr[i] = pq.poll();
      }
   }
   class Range implements Comparable<Range>
   {
      public int left;
      public int right;
      
      public Range(int a, int b)
      {
         left = a;
         right = b;
      }  
      public int compareTo(Range oth)
      {
         if(left == oth.left)
            return right-oth.right;
         return left-oth.left;
      }
   }

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

int main () {
int a, b;
  cin >> a >> b;
  if(a <= 5) cout << 0;
  else if(6 <= a && a <= 12) cout << b/2;
  else cout << b;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,len;
int dp[1000010][27],DP[1000010][24];
char s[1000010];
void pre(){
	for(int i=1;i<=len+2;i++){
		for(int j=0;j<=26;j++) dp[i][j]=len+2;
		for(int j=0;j<20;j++) DP[i][j]=len+2;
	}
	for(int i=len;i;i--){
		dp[i][s[i]-'a']=i+1;
		for(int j=s[i]-'a'+1;j<=26;j++) dp[i][j]=dp[dp[i][j-1]][j-1];
		DP[i][0]=dp[i][26];
		for(int j=1;j<20;j++) DP[i][j]=DP[DP[i][j-1]][j-1];
		for(int j=0;j<26;j++) if(dp[i][j]==len+2) dp[i][j]=dp[DP[i][0]][j];
	}
}
bool pd(int x,int y){
	for(int i=19;i>=0;i--){
		if(DP[x][i]==y+1) return true;
		if(DP[x][i]<=y) x=DP[x][i];
	}
	return false;
}
signed main(){
//	freopen("fusion.in","r",stdin);
//	freopen("fusion.out","w",stdout);
	ios::sync_with_stdio(false);
	 cin>>s+1;
	len=strlen(s+1);
	 cin>>n;
	pre();
	for(int i=1;i<=n;i++){
		int l,r; cin>>l>>r;
		if(pd(l,r)) puts("Yes");
		else puts("No");
	}
}


Measured memory_bytes: 104576
#include<stdio.h>
#include<math.h>
int main()
{
    int n,i;
    int a[1000],b[1000],c[1000];
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d%d%d",&a[i],&b[i],&c[i]);
    }
    for(i=0;i<n;i++){
        if((c[i]*c[i])==(a[i]*a[i]+b[i]*b[i])||(a[i]*a[i])==(b[i]*b[i]+c[i]*c[i])||(b[i]*b[i])==(a[i]*a[i]+c[i]*c[i])){
            printf("YES\n");
        }else{
            printf("NO\n");
        }
    }
    return 0;
}
 

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

int main(){
  int N,sum=0;
  cin >> N;
  vector<int> L(N);
  
  for(int i =0;i<N;i++){
    cin >> L[i];
    sum += L[i];
  }
  
  int max = *max_element(L.begin(),L.end());
  if(max < sum - max)cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
s=list(input())
t=list(input())

s_memo = {}
t_memo = {}

for i in range(len(s)):
  if t[i] not in t_memo:
    t_memo[t[i]] = s[i]
  else:
    if t_memo[t[i]] != s[i]:
      print("No")
      exit()
      break
  
  if s[i] not in s_memo:
    s_memo[s[i]] = t[i]
  else:
    if s_memo[s[i]] != t[i]:
      print("No")
      exit()
      break

print("Yes")

Measured memory_bytes: 6704
#include <cstdio>
#include <map>

using namespace std;

typedef pair<int, int> pii;

int c[101][101] = { { 0 } };
int t[101][101] = { { 0 } };
int n, m;

int calculate(int mat[101][101], int from, int to){
	multimap<int, int> locations;
	for(int i = 1; i <= m; i++){
		if(mat[from][i] != 0){
			locations.insert(pii(mat[from][i], i));
		}
	}
	while(!locations.empty()){
		multimap<int, int>::iterator it = locations.begin();
		int d = (*it).first, f = (*it).second;
		if(f == to){ break; }
		for(int i = 1; i <= m; i++){
			if(mat[f][i] != 0 && (d + mat[f][i] < mat[from][i] || mat[from][i] == 0)){
				int dist = d + mat[f][i];
				mat[from][i] = mat[i][from] = dist;
				locations.insert(pii(dist, i));
			}
		}
		locations.erase(it);
	}
	return mat[from][to];
}

int main(){
	while(true){
		scanf("%d%d", &n, &m);
		if(n == 0 || m == 0){ break; }
		for(int i = 0; i <= m; i++){
			for(int j = 0; j <= m; j++){
				c[i][j] = t[i][j] = 0;
			}
		}
		for(int i = 0; i < n; i++){
			int a, b, cost, time;
			scanf("%d%d%d%d", &a, &b, &cost, &time);
			if(c[a][b] == 0 || c[a][b] > cost){ c[a][b] = c[b][a] = cost; }
			if(t[a][b] == 0 || t[a][b] > time){ t[a][b] = t[b][a] = time; }
		}
		int k;
		scanf("%d", &k);
		while(k--){
			int p, q, r;
			scanf("%d%d%d", &p, &q, &r);
			printf("%d\n", calculate((r == 0) ? c : t, p, q));
		}
	}
	return 0;
}

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


int main () {
    int N,M;
    int P[100000],Y[100000];
    vector<int> yd[100001];
    
    cin>>N>>M;
    rep(i,M){
        cin>>P[i]>>Y[i];
        yd[P[i]].push_back(Y[i]);
    }
    
    rep(i,N)sort(yd[i+1].begin(),yd[i+1].end());
    rep(i,M)printf("%012lld\n",ll(P[i])*1000000+int(lower_bound(yd[P[i]]. begin(),yd[P[i]].end(),Y[i])-yd[P[i]].begin())+1);
}


Measured memory_bytes: 7808