akhauriyash/Code-Regression huggingface dataset:
class StarrySkyTree:
    """ Starry Sky Tree(区間加算・区間最小(大)値取得) """

    def __init__(self, N, func, intv):
        self.intv = intv
        self.func = func
        LV = (N - 1).bit_length()
        self.N0 = 2 ** LV
        self.data = [0] * (2 * self.N0)
        self.lazy = [0] * (2 * self.N0)

    # 伝搬される区間のインデックス(1-indexed)を全て列挙するgenerator
    def gindex(self, l, r):
        L = l + self.N0
        R = r + self.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(self, *ids):
        # 1-indexedで単調増加のインデックスリスト
        for i in reversed(ids):
            v = self.lazy[i - 1]
            if not v:
                continue
            self.lazy[2 * i - 1] += v
            self.lazy[2 * i] += v
            self.data[2 * i - 1] += v
            self.data[2 * i] += v
            self.lazy[i - 1] = 0

    def update(self, l, r, x):
        """ 区間[l,r)の値にxを加算 """

        # 1. lazyの値は伝搬させない
        # 2. 区間[l,r)のdata, lazyの値を更新
        L = self.N0 + l
        R = self.N0 + r
        while L < R:
            if R & 1:
                R -= 1
                self.lazy[R - 1] += x
                self.data[R - 1] += x
            if L & 1:
                self.lazy[L - 1] += x
                self.data[L - 1] += x
                L += 1
            L >>= 1
            R >>= 1
        # 3. 更新される区間を部分的に含んだ区間のdataの値を更新 (lazyの値を考慮)
        for i in self.gindex(l, r):
            self.data[i - 1] = self.func(self.data[2 * i - 1], self.data[2 * i]) + self.lazy[i - 1]

    def query(self, l, r):
        """ 区間[l,r)の最小(大)値を取得 """

        # 1. トップダウンにlazyの値を伝搬
        self.propagates(*self.gindex(l, r))
        L = self.N0 + l
        R = self.N0 + r

        # 2. 区間[l, r)の最小(大)値を求める
        s = self.intv
        while L < R:
            if R & 1:
                R -= 1
                s = self.func(s, self.data[R - 1])
            if L & 1:
                s = self.func(s, self.data[L - 1])
                L += 1
            L >>= 1
            R >>= 1
        return s

def resolve():
    N, M = map(int, input().split())
    # 1_index
    Pair = [[] for _ in range(N+1)]
    for _ in range(M):
        l, r, a = map(int, input().split())
        Pair[r].append((l, a))

    seg = StarrySkyTree(N+1, func=max, intv=0)

    for i in range(1, N+1):
        _max = seg.query(0, i)
        seg.update(i, i+1, _max)
        for p in Pair[i]:
            l = p[0]
            a = p[1]
            seg.update(l, i+1, a)

    print(seg.query(0, N+1))

if __name__ == "__main__":
    resolve()


Measured memory_bytes: 111368
#include <bits/stdc++.h>
using namespace std;
int arr[25];

int main() {
    int n,d;
    cin>>n>>d;
    int r = (d*2)+1;
    memset(arr,-1,sizeof(arr));
    if(n%r == 0)cout<<n/r<<endl;
    else
        cout<<n/r + 1<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>

using namespace std;

int read()
{
	int x=0;
	scanf("%d",&x);
	return x;
}
template<typename T> void write(T x){if(x>=10)write(x/10);putchar('0'+x%10);}
template<typename T> bool chkmin(T &a,T b){if(a>b){a=b;return 1;}return 0;}
template<typename T> bool chkmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> T minn(T a,T b){if(a<b)return a;return b;}
template<typename T> T maxx(T a,T b){if(a>b)return a;return b;}

typedef long long ll;
const int N=1e5+9;
int n;
int a[N],b[N],c[N];
ll ans;

int main()
{
	n=read();
	for(int i=1;i<=n;i++)
		a[i]=read();
	for(int i=1;i<=n;i++)
		b[i]=read();
	for(int i=1;i<=n;i++)
		c[i]=read();

	sort(a+1,a+n+1);
	sort(c+1,c+n+1);

	for(int i=1;i<=n;i++)
	{
		int apos=lower_bound(a+1,a+n+1,b[i])-a-1;
		int cpos=upper_bound(c+1,c+n+1,b[i])-c;
		ans+=(ll)apos*(ll)(n-cpos+1);
	}

	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 1408
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int k = scan.nextInt();
		long sum = 0;
		for (int a = 1; a <= k; a++) {
			for (int b = 1; b <= k; b++) {
				int r = gcd(a, b);
				for (int c = 1; c <= k; c++) {
					sum += gcd(r, c);
				}
			}
		}
		System.out.println(sum);
	}
	
	public static int gcd(int a, int b) {
		if (a < b) {
			int tmp = a;
			a = b;
			b = tmp;
		}
		if (a % b == 0) {
			return b;
		} else {
			return gcd(b, a % b);
		}
	}
}


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

const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;

int main(){
	int n;cin>>n;
	map<string,int>mp;
	rep(i,n){
		string s;cin>>s;
		sort(s.begin(),s.end());
		mp[s]++;
	}
	ll ans=0;
	for(auto p:mp){
		ans+=p.second*(ll)(p.second-1)/2;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 11136
using System;
using System.Linq;
using System.Collections.Generic;
 
class MainClass {
  public static void Main (string[] args) {
    var list = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
    var A = list[0];
    var B = list[1];
    var C = list[2];
    var D = list[3];
    
    var res = Math.Min(B, D) - Math.Max(A, C) >= 0 ?  Math.Min(B, D) - Math.Max(A, C) : 0;
     Console.WriteLine(res);
  
  }
}

Measured memory_bytes: 13268
function main(input){
  const a = input.trim().split('\n');
  const b = a[0];
  const c = a[1].split('').reverse().join('');
  if(b==c){
    console.log('YES');
  }else{
    console.log('NO');
  }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 29516
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define faster ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
 
typedef vector<int> vi;;
typedef vector<ll> vll;

#define l() length()
#define sz() size()
 
#define b() begin()
#define e() end()
#define all(x) x.begin(), x.end()
 
#define pb(i) push_back(i)
#define PB() pop_back()
 
 
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;
#define mp make_pair
#define Fi first
#define Se second
 
const int maxx=100009;
 
// Happy Coding!

void solve(){
    ll n,m;
    cin>>n>>m;
    if(n==1 or m==1){
      cout<<1<<endl;
      return ;
    }
    ll f=(m+1)/2;
    ll s=m-f;
    
    ll ans=(f+s)*(n/2);
    if(n&1){
        ans+=f;
    }
    cout<<ans<<endl;
}

 
int main() {
    faster;
    int t=1;
    // cin>>t;
    
    while(t-->0){
        solve();
    }
	return 0;
}

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

int main() {
 UL N;scanf("%u",&N);
 UL A[9]; rep(i,N) scanf("%u",&A[i]);
 UL pre[9],nx[9]; rep(i,N) pre[i]=nx[i]=A[i];
 for(UL i=N-1; i!=0; i--){
  if(pre[i-1]>pre[i]){
   for(UL j=i+1; j<N; j++) if(pre[i-1]>pre[j] && pre[i]<pre[j]) swap(pre[i],pre[j]);
   swap(pre[i-1],pre[i]);
   sort(pre+i,pre+N); reverse(pre+i,pre+N);
   rep(j,N){if(j)printf(" "); printf("%u",pre[j]);}
   printf("\n");
   break;
  }
 }
 rep(j,N){if(j)printf(" "); printf("%u",A[j]);}
 printf("\n");
 for(UL i=N-1; i!=0; i--){
  if(nx[i-1]<nx[i]){
   for(UL j=i+1; j<N; j++) if(nx[i-1]<nx[j] && nx[i]>nx[j]) swap(nx[i],nx[j]);
   swap(nx[i-1],nx[i]);
   sort(nx+i,nx+N);
   rep(j,N){if(j)printf(" "); printf("%u",nx[j]);}
   printf("\n");
   break;
  }
 }
 return 0;
}




Measured memory_bytes: 3248
from bisect import bisect_right
from bisect import bisect_left
n, m, k = map(int, input().split())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]

aa = [0]
bb = [0]
for x in a:
    aa.append(aa[-1]+x)

for x in b:
    bb.append(bb[-1]+x)

ans = 0
for i in range(len(aa)):
    if aa[i] > k:
        break
    x = bisect_right(bb, k-aa[i])
    ans = max(ans, i+x-1)

print(ans)


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

int BinSearch(int nA[], int nKey, int n)
{
	int nLeft = 0, nRight = n;
	int nMid = (nLeft + nRight) / 2;
	while (nLeft < nRight)
	{
		if (nA[nMid]<nKey)
		{
			nLeft = nMid + 1;
		}
		else if (nA[nMid]>nKey)
		{
			nRight = nMid;
		}
		else
		{
			return 1;
		}
		nMid = (nLeft + nRight) / 2;
	}
	return 0;
}


int main()
{
	int nA[100000] = { 0 };
	int n = 0, q = 0, nKey = 0, nSum = 0;
	int ni = 0;
	cin >> n;
	while (cin >> nA[ni], ni < (n - 1))
	{
		ni++;
	}
	cin >> q;
	for (ni = 0; ni < q; ni++)
	{
		cin >> nKey;
		if (BinSearch(nA, nKey, n))
		{
			nSum++;
		}
	}
	cout << nSum << endl;
	return 0;
}


Measured memory_bytes: 3496
#include <iostream>
#include <string>
#include <cstdlib>

using namespace std;

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

	if (s.size() == 1) {
		cout << s[0] << endl;
		return 0;
	}

	int ctr = 0;
	int not1 = 0;
	for (auto i = 0; i < s.size(); i++) {
		if (s[i] == '1') ctr++;
		else {
			not1 = i;
			break;
		}
	}
	if (ctr == 100) {
		cout << '1' << endl;
		return 0;
	}

	if (s2.size() > 3) {
		cout << s[not1] << endl;
		return 0;
	}
	if (atoi(s2.c_str()) > 100) {
		cout << s[not1] << endl;
		return 0;
	}

	int hoge = atoi(s2.c_str());

	if (hoge > 100) {
		cout << s[not1] << endl;
		return 0;
	}

	if (ctr >= hoge) {
		cout << '1' << endl;
		return 0;
	} else {
		cout << s[not1] << endl;
		return 0;
	}


	
		
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
// Hey! 僕の提出を見てくれてありがとう.
// ロボ子さん可愛いぞ！！！！！君もV沼にはまろう↓
// https://www.youtube.com/channel/UCDqI2jOz0weumE8s7paEk6g
using namespace std;
/*
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
namespace mp = boost::multiprecision;// 任意長整数型
using bint = mp::cpp_int;// 仮数部長が32の浮動小数点数型
using real32 = mp::number<mp::cpp_dec_float<32>>;// 仮数部長が1024の浮動小数点数型
using real1024 = mp::number<mp::cpp_dec_float<1024>>;// ついでに有理数型
using rat = boost::rational<bint>;
*/
using ll = long long;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}//a,bの最大公約数(gcd)を求める
ll lcm(ll a,ll b){return abs(a*b)/gcd(a,b);}//a,bの最小公倍数(lcm)を求める
vector<ll> enum_div(ll n){vector<ll> ret;for(int i=1 ; i*i<=n ; i++){if(n%i == 0){ret.push_back(i);if(i!=1 && i*i!=n)ret.push_back(n/i);}}ret.push_back(n);return ret;}
//↑nの約数を求める
vector<bool> IsPrime; void sieve(size_t max){if(max+1 > IsPrime.size())IsPrime.resize(max+1,true);IsPrime[0] = false;IsPrime[1] = false;for(size_t i=2; i*i<=max; ++i)if(IsPrime[i])for(size_t j=2; i*j<=max; ++j)IsPrime[i*j] = false;}
//↑エラトステネスの篩で素数を求める
#define roundup(divisor,dividend) (divisor + (dividend - 1)) / dividend //切り上げ割り算
#define all(x) (x).begin(),(x).end() //xの初めから終わりまでのポインタ
#define size_t ll //size_tは自動でllに変換される
#define pb(x) push_back(x)
#define pri_queue priority_queue //優先度付きキュー
#define syo(x) fixed << setprecision(x) //iostreamで小数をx桁表示
//sortを降順にする時は greater<型>()
ll x,y;
int main(){ //srand((unsigned)time(NULL));
  cin >> x >> y;
  cout << gcd(x,y) << endl;
}



Measured memory_bytes: 3080
#include <bits/stdc++.h>
using namespace std;
     
#define FASTIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using ll = long long;
     
const int MOD = 998244353;
const ll INF = 1e16;
     
int main() {
    FASTIO
     
    int n, k;
    cin >> n >> k;
    int b[k][2];
    for(int i=0; i<k; i++) {
        cin >> b[i][0] >> b[i][1];
    }
        
    vector<int> dp(n+1,0);
    dp[1] = 1;
    for(int i=2; i<=n; i++) {
        for(int j=0; j<k; j++) {
            dp[i] += dp[max(i-b[j][0],0)] - dp[max(i-b[j][1]-1,0)];
            if(dp[i] < 0) dp[i] += MOD;
            else dp[i] %= MOD;
        }
        dp[i] += dp[i-1];
        if(dp[i] < 0) dp[i] += MOD;
        else dp[i] %= MOD;
    }
    int ways = dp[n]-dp[n-1];
    if(ways < 0) cout << ways+MOD << "\n";
    else cout << ways%MOD << "\n";
            
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int n;
int a[125252];

int main(){
  scanf("%d",&n);
  REP(i,n)scanf("%d",a+i);
  sort(a,a+n);
  int head = 0, tail = n-1;
  int ans = n;
  while(true){
    while(head<tail && a[head]!=a[head+1])head++;
    while(head<tail && a[tail]!=a[tail-1])tail--;
    if(head>=tail)break;
    ans -= 2;
    head++;
    tail--;
  }
  printf("%d\n",ans);
  return 0;
}


Measured memory_bytes: 640
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Tanzim Ibn Patowary
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            for (int test = 0; test < testNumber; test++) {
                int n = in.nextInt();
                if (n >= 30) {
                    out.println("Yes");
                } else {
                    out.println("No");
                }
            }
        }

    }
}



Measured memory_bytes: 26988
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int c[3][3];
  for(int i=0;i<3;i++){
    for(int j=0;j<3;j++){
      cin>>c[i][j];
    }
  }
  
  bool flag=true;
  int dr1 = c[0][0]-c[0][1];
  int dr2 = c[0][1]-c[0][2];
  int dc1 = c[0][0]-c[1][0];
  int dc2 = c[1][0]-c[2][0];
  for(int i=1;i<3;i++){
    if(c[i][0]-c[i][1]!=dr1) flag=false;
    if(c[i][1]-c[i][2]!=dr2) flag=false;
    if(c[0][i]-c[1][i]!=dc1) flag=false;
    if(c[1][i]-c[2][i]!=dc2) flag=false;
  }
  cout<<((flag)? "Yes":"No");
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0;i < n;i++)
#define rev(i, n) for(int i = n;i >= 0;i--)
#define repeat(i, m, n) for(int i = m;i < n;i++)
#define repeatrev(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define itn int

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
typedef priority_queue<int> Pr;

int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    cin >> N;
    ll int s = 0;
    ll int g = 0;
    ll int A[N];
    ll int B[N];

    cin >> A[0];
    B[0] = A[0];
    s += A[0];
    for(int i = 1; i < N; i ++){
        cin >> A[i];
        s += A[i];
        B[i] = B[i - 1] + A[i];
    }
    ll int f = min(abs(-s +2 *  B[0]), abs(s - 2 * B[0]));

    for(int i = 1; i < N - 1; i ++){
        ll int u = abs(-s +2 *  B[i]);
        ll int q = abs(s - 2 * B[i]);
        if(f > min(u, q)) f = min(u, q);


    }
    cout << f << endl;




}

Measured memory_bytes: 3328
#include<iostream>
#include<queue>
#include<vector>
#include<bits/stdc++.h>
using namespace std;
const int MAXN=100000+10;
vector<int> edge[MAXN];
int n,cnt[3];
int tree[MAXN];
void bfs()
{
    queue<int> q;
    q.push(1),q.push(n);
    while(!q.empty())
    {
        int temp=q.front();
        q.pop();
        cnt[tree[temp]]++;
        for(int i=0;i<edge[temp].size();++i)
        {
            int v=edge[temp][i];
            //cnt[tree[temp]]++;
            if(tree[v])continue;
            else tree[v]=tree[temp];
            q.push(v);
        }
    }
}

int main()
{
    ios::sync_with_stdio(false);
    memset(tree,0,sizeof(tree));
    cin>>n;
    for(int i=1;i<n;++i)
    {
        int x,y;
        cin>>x>>y;
        edge[x].push_back(y);
        edge[y].push_back(x);
    }
    tree[1]=1,tree[n]=2;
    bfs();
    if(cnt[2]>=cnt[1])
        cout<<"Snuke"<<endl;
    else
        cout<<"Fennec"<<endl;
    return 0;
}

Measured memory_bytes: 6272
#include <stdio.h>
int main()
{
  int array[1000];
  int i,j,key,N,k;

  scanf("%d",&N);
  for(i=0;i<N;i++){
  scanf("%d",&array[i]);
  }
  for(i=0;i<N-1;i++){
    printf("%d ",array[i]);
  }
  printf("%d",array[N-1]);
  printf("\n");
  for(i=1;i<=N-1;i++){
    key=array[i];
    j=i-1;
    while(j>=0&&array[j]>key){
      array[j+1]=array[j];
      j--;
      array[j+1]=key;
    }
    for(k=0;k<N-1;k++){
      printf("%d ",array[k]);
    }
    printf("%d",array[N-1]);
    printf("\n");
  }

  return 0;
}

Measured memory_bytes: 604
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
  int a;
  cin>>a;
  int max=0,cnt=0;
  for(int i=1;i<=a;i++)
  {
    int ct=0;
    int x=i;
    while(x%2==0)
    {
      ct++;
      x/=2;
    }
    if(ct>=cnt)
    {
      max=i;
      cnt=ct;
    }
  }
  cout<<max;
  return 0;
}

Measured memory_bytes: 3576
def main():
    from itertools import accumulate
    n, k = map(int, input().split())
    *exp, = map(lambda x: (int(x) + 1) / 2, input().split())
    l = accumulate(exp)
    l = list(l)
    ll = [l[k - 1]] + [l[i + k] - l[i] for i in range(n-k)]
    ans = max(ll)
    print(ans)


if __name__ == '__main__':
    main()


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

using namespace std;

int field[102][102];
bool visited[102][102];
int w, h;
int xs, ys;
int xg, yg;
int n;
int d_x[] = {1, 0, -1, 0};
int d_y[] = {0, -1, 0, 1};
int sc;

bool search(int y, int x) {
  if (visited[y][x] || field[y][x] == 0 || field[y][x] != sc) {return false;}  
  if (y == yg && x == xg) {
    return true;
  }
  visited[y][x] = true;
  for (int i = 0; i < 4; i++) {
    if (search(y + d_y[i], x + d_x[i])) {return true;}
  }
  return false;
}

int main()
{
  while (true) {
    scanf("%d %d ", &w, &h);
    if (w == 0 && h == 0) {
      break;
    }
    scanf("%d %d ", &xs, &ys);
    scanf("%d %d ", &xg, &yg);
    scanf("%d ", &n);
    for (int i = 0; i < 102; i++) {
      fill(field[i], &field[i][102], 0);
      fill(visited[i], &visited[i][102], false);
    }
    for (int i = 0; i < n; i++) {
      int c, d, x, y;
      scanf("%d %d %d %d ", &c, &d, &x, &y);
      for (int i = 0; i < 2; i++) {
	for (int j = 0; j < 4; j++) {
	  if (d == 0) {
	    field[y + i][x + j] = c;
	  } else {
	    field[y + j][x + i] = c;
	  }
	}
      }
    }
    /*for (int i = 1; i <= h; i++) {
      for (int j = 1; j <= w; j++) {
	printf("%d ", field[i][j]);
      }
      printf("\n");
      }*/
    sc = field[ys][xs];
    if (search(ys, xs)) {cout << "OK" << endl;}
    else {cout << "NG" << endl;}
  }
  return 0;
}

Measured memory_bytes: 0
a,b,w,n,i,t[31];
main(){
    for(i=0;i<=30;t[i]=++i);
    scanf("%d%d",&w,&n);
    for(;~scanf("%d,%d",&a,&b);t[a]^=t[b]^=t[a]^=t[b]);
    for(i=0;i<w;printf("%d\n",t[++i]));
}

Measured memory_bytes: 1748
Public Class Program
  Shared Sub Main()
    Dim n As Integer = Integer.Parse(Console.ReadLine())
    Dim l As Integer() = Array.ConvertAll(Of String, Integer)(Console.ReadLine().Split(" "), AddressOf Integer.Parse)
    Array.Sort(l)
    Dim ans As Integer = 0
    For i As Integer = 0 To n - 3
      For j As Integer = i + 1 To n - 2
        Dim min As Integer = j + 1
        Dim max As Integer = n
        Do While min < max
          Dim m As Integer = (max + min) \ 2
          If l(i) + l(j) <= l(m) Then
            max = m
          Else
            min = m + 1
          End If
        Loop
        ans += min - j - 1
      Next
    Next
    Console.WriteLine(ans.ToString())
  End Sub
End Class

Measured memory_bytes: 13184
package main
import (
  "fmt"
  "strings"
)
func main() {
  var n int
  var t string
  fmt.Scan(&n)
  s := make([]string,n)
  for i:=0;i<n;i++ { fmt.Scan(&s[i]) }
  fmt.Scan(&t)
  l,r := 1,n+1
  for i:=0;i<n;i++ {
    a := strings.Replace(s[i],"?","a",-1)
    z := strings.Replace(s[i],"?","z",-1)
    if a > t { r-- }
    if z < t { l++ }
  }
  for i:=l;i<=r;i++ {
    fmt.Print(i)
    if i == r {
      fmt.Println()
    } else {
      fmt.Print(" ")
    }
  }
}

Measured memory_bytes: 2048
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <string>
using namespace std;
typedef double  dbl;
typedef long long int lld;
#define PI 3.14159265358979323
#define foi(i,n) for(i = 0; i < n; i+=1)
#define fod(i,n) for(i=n-1; i >=0; i-=1)
#define MAX std::numeric_limits<lld>::max()
#define MIN std::numeric_limits<lld>::min()
#define FastIO  ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
int main ()
{
	FastIO
	map <string, lld> counter;
	lld n, i;
	cin >> n;
	lld j;
	foi(i,n){
		string s;
		string t;
		cin >> s;
		char c[10];
		foi(j, 10){
			c[j] = s[j];
		}
		sort(c,c+10);
		t = "";
		foi(j, 10){
			t += c[j];
		}
		counter[t] += 1;
	}
	lld count = 0;
	for(map <string, lld> :: iterator pos = counter.begin(); pos != counter.end(); pos++){
		lld r = pos->second;
		count += ((r*(r-1))/2);
	}
	cout << count;
	return 0;
}

Measured memory_bytes: 12800
import java.util.*;
public class Main {
	public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
        int N =sc.nextInt();
        int K =sc.nextInt();
        int X =sc.nextInt();
        int Y =sc.nextInt();
        int M;
        if(N >= K){
            M = K*X+(N-K)*Y;
            System.out.println(M);
        }else{
            M=N*X;
            System.out.println(M);
        }
    }
}

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

using namespace std;

int main() {
  string s;
  cin >> s;
  if (s.size() >= 4 && s[0] == 'Y' && s[1] == 'A' && s[2] == 'K' && s[3] == 'I') {
    cout << "Yes" << endl;
  } else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <stack>
using namespace std;
  int main(){
   int train[11],n;
   stack<int> s;
   while(scanf("%d",&n) != EOF){
      if(n != 0){
        s.push(n);
           }else{
             printf("%d\n",s.top());
			 s.pop();
         }
}
return 0;
}
      

Measured memory_bytes: 1036
import java.util.Scanner;

public class Main{
    public static void main(String args[]){
        
        Scanner sc = new Scanner(System.in);
        int r = sc.nextInt();
        
        if(r > 2799){
            System.out.println("AGC");
        }else{
            if(r > 1199){
                System.out.println("ARC");
            }else{
                System.out.println("ABC");
            }
        }
        
    }
}


Measured memory_bytes: 21972
n = int(input())
sn = {}
for _ in range(n):
  s = input()
  if not s in sn:
    sn[s] = 1
  else :
    sn[s] += 1

m = int(input())
tn = {}
for _ in range(m):
  t = input()
  if not t in tn:
    tn[t] = 1
  else :
    tn[t] += 1

answer = 0
for skey in sn.keys():
  if not skey in tn:
    check = sn[skey]
  else :
    check = sn[skey] - tn[skey]
  if answer < check:
    answer = check

print(answer)

Measured memory_bytes: 9204
#include <bits/stdc++.h>
#include <atcoder/all>
#define endl "\n"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
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;
}

const long long INF = 2e9;
//const ll mod = 1000000007;
ll N, K;
ll A[100][100];
ll ansval;
char ans[100][100];

int main() {
    cin >> N >> K;
    int row = 0;
    int column = row + N;
    int s = column + N;
    int t = s + 1;
    atcoder::mcf_graph<ll, ll> g(t + 1);
    for(int i = 0; i < N; i++) {
        g.add_edge(column + i, t, K, 0);
        g.add_edge(s, row + i, K, 0);
    }
    for(int i = 0; i < N; i++) {
        for(int j = 0; j < N; j++) {
            cin >> A[i][j];
            g.add_edge(row + i, column + j, 1, INF - A[i][j]);
        }
    }
    for(int i = 0; i < N; i++) {
        for(int j = 0; j < N; j++) {
            ans[i][j] = '.';
        }
    }
    g.add_edge(s, t, N * K, INF);
    while(true) {
        auto tmp = g.flow(s, t, N * K);
        //cerr << tmp.first << " " << tmp.second << endl;
        /*
        if(tmp.first == 0) break;
        if(INF - tmp.second < 0) break;
        */
        ansval += N * K * INF - tmp.second;
        for(int i = 0; i < N; i++) {
            for(int j = 0; j < N; j++) {
                ans[i][j] = '.';
            }
        }
        auto A = g.edges();
        for(auto e : A) {
            if(e.from < row) continue;
            if(e.from >= row + N) continue;
            if(e.flow == 0) continue;
            ans[e.from - row][e.to - column] = 'X';
        }
        break;
    }
    cout << ansval << endl;
    for(int i = 0; i < N; i++) {
        for(int j = 0; j < N; j++) cout << ans[i][j];
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 3972
#include <bits/stdc++.h>
using namespace std ;
const int N = 1234567;
vector <pair<int,int> > G[N] ;
vector <int> newg[N] ;
queue <int> q ;
int f[N],son[N],id[N],dp[N] ;
bool use[N] ;
int n,m ;
inline void init(int i){
	f[i]=i;son[i]=0;id[i]=-1;use[i]=false ;
}
int find(int x){
	return (x==f[x])?x:f[x]=find(f[x]) ; 
}
inline void merge(int x,int y){
	int X=find(x),Y=find(y) ;
	if (X==Y) return ;
	if (son[X]<son[Y]) f[X]=Y ;//避免被hack 
	else {
		f[Y]=X ;
		if (son[X]==son[Y]) son[X]++ ;
	}
} 
inline int read(){
	char c;int f=1 ;
	while ((c=getchar())<'0' || c>'9') if (c=='-') f=-1 ;
	int res=c-'0' ;
	while ((c=getchar())>='0' && c<='9') res=res*10+c-'0' ;
	return res*f ; 
}
void INIT(){
	for (int i=1;i<=N;i++) G[i].clear() ;
	for (int i=1;i<=N;i++) newg[i].clear() ;
	while(!q.empty()) q.pop() ;
}
int main(){
	while(scanf("%d%d",&n,&m)!=EOF){
		INIT() ;
		for (int i=1;i<=m;i++){
			int a,b,c ;
			a=read();b=read();c=read() ;
			G[c].push_back(make_pair(a,b)) ;
		}
		int cnt=n; 
		for (int i=1;i<=N;i++){
			if (G[i].empty()) continue ; //无该公司 
			for (int j=0;j<G[i].size();j++){ //初始 
				init(G[i][j].first) ;
				init(G[i][j].second) ;
			}
			for (int j=0;j<G[i].size();j++) merge(G[i][j].first,G[i][j].second) ;
			for (int j=0;j<G[i].size();j++){
				if (!use[G[i][j].first]){
					use[G[i][j].first]=true ;
					int X=find(G[i][j].first) ;
					if (id[X]==-1) id[X]=++cnt ;
					newg[G[i][j].first].push_back(id[X]) ;//该站点与公司建无向边 
					newg[id[X]].push_back(G[i][j].first) ;
				}
				if (!use[G[i][j].second]){ //同样的工作在second上再做一遍 
					use[G[i][j].second]=true ;
					int X=find(G[i][j].second) ;
					if (id[X]==-1) id[X]=++cnt ;
					newg[G[i][j].second].push_back(id[X]) ;
					newg[id[X]].push_back(G[i][j].second) ;
				}
			}
 		}
 		q.push(1) ;
 		memset(dp,-1,sizeof(dp)) ;
 		dp[1]=0; //初始在0号节点
		while(!q.empty()){ //BFS 
			int v=q.front();q.pop() ;
			for (int i=0;i<newg[v].size();i++){
				int to=newg[v][i] ;
				if (dp[to]==-1){ //还没访问 
					dp[to]=dp[v]+1 ;
					q.push(to) ;
				}
			}
		}
		if (dp[n]==-1) cout<<-1<<endl ;
		else cout<<dp[n]/2<<endl ;
	}
}

Measured memory_bytes: 85376
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
ll GCD(ll a,ll b) {return b ? GCD(b,a%b):a;}
ll LCM(ll c,ll d){return c/GCD(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int main(){
	int n;
	cin>>n;
	ll cnt=0;
	for(int i=0;i<n;i++){
		ll a;cin>>a;
		if(i%2==0&&a%2==1)cnt++;
	}
	cout<<cnt<<"\n";
}


Measured memory_bytes: 3576
#include <iostream>

int main() {
    int n;
    std::cin >> n;

    int l, i = 0, goal[n], len[n];
    while (std::cin >> l) {
        goal[i] = l;
        len[i] = 0;
        i++;
        if (i >= n) {
            break;
        }
    }

    int num = 0;
    while (true) {
        int from = -1;
        int to = n;
        for (int i = 0; i < n; i++) {
            if (len[i] < goal[i]) {
                if (from == -1) {
                    from = i;
               }
           } else {
               if (from >= 0) {
                   to = i;
                   break;
               }
            }
        }
        if (from == -1) {
            break;
        }
        for (int i = from; i < to; i++) {
            len[i]++;
        }
        num++;
    }
    
    std::cout << num << std::endl;

    return 0;
}

Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#include <set>
#include <map>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;

int main(){
  int n; cin >> n;
  ll a[n];
  REP(i,n) cin >> a[i];
  map<ll,ll> mp;
  mp[0]++;
  ll sum = 0;
  REP(i,n){
    sum += a[i];
    mp[sum]++;
  }
  ll ans = 0;
  for(auto itr:mp){
    ans += itr.second*(itr.second-1)/2;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 14336
#include "bits/stdc++.h"
using namespace std;
#define int int64_t
#define mp make_pair
#define f first
#define s second
int ar[1<<19];
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string ss;cin>>ss;
    int ans=0;
    int pos=0;
    ss+='-';
    while(ss[pos]=='>')
    {
        pos++;
    }
    ans+=(pos*(pos+1))/2;
    for(int i=pos;i<ss.length();i++)
    {
        int count=0;
        while(ss[pos]=='<')
        {
            count++;
            pos++;
        }
        bool flag=false;
        int c2=0;
        while(ss[pos]=='>')
        {
            c2++;
            pos++;
            flag=true;
        }
        if(flag)
        {
            int temp=max(c2,count);
            c2=min(c2,count);c2--;
            ans+=(temp*(temp+1))/2;
            ans+=(c2*(c2+1))/2;
        }
        else
        {
            ans+=(count*(count+1))/2;
        }
    }
    cout<<ans<<"\n";
    return 0;
}



Measured memory_bytes: 1172
#pragma GCC optimize(3)
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/priority_queue.hpp>
#define MAXN 100005
#define INF 1000000000
#define MOD 1000000007
#define F first
#define S second
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair<int,int> P;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef __gnu_pbds::priority_queue<int,greater<int>,pairing_heap_tag> pq;
int n,k,a[MAXN];
int main()
{
    scanf("%d",&n);
    if(__builtin_popcount(n)==1)
    {
        puts("No");
        return 0;
    }
    puts("Yes");
    for(int i=1;i<=2;i++) 
    {
        printf("%d %d\n",i,i+1);
        printf("%d %d\n",n+i,n+i+1);
    }
    printf("%d %d\n",3,n+1);
    if(n&1)
    {
        for(int i=4;i<=n;i+=2) 
        {
            printf("%d %d\n",i,i+1);
            printf("%d %d\n",n+i,n+i+1);
            printf("%d %d\n",i+1,1);
            printf("%d %d\n",n+i,1);
        }
    }
    else
    {
        int now=1;
        while(now*2<=n) now*=2;
        now++;
        for(int i=4;i<=now;i+=2) 
        {
            printf("%d %d\n",i,i+1);
            printf("%d %d\n",n+i,n+i+1);
            printf("%d %d\n",i+1,1);
            printf("%d %d\n",n+i,1);
        }
        now++;
        printf("%d %d\n",now,now-1);
        printf("%d %d\n",n+now,2);
        for(int i=now+2;i<=n;i+=2)
        {
            int x=i^(i-1);
            printf("%d %d\n",i-1,i);
            printf("%d %d\n",n+i,n+i-1);
            printf("%d %d\n",i-1,x);
            printf("%d %d\n",n+i,x);
        }
    }
    return 0;
}



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

#define int long long
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define fi first
#define se second
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int N,E,T;
int W[300];
int G[1000],C[1000],S[1000][10];

int F[300];

signed main(){
    cin>>N>>E>>T;
    rep(i,N)cin>>W[i];
    rep(i,E){
        cin>>G[i]>>C[i];
        G[i]--;
        rep(j,C[i]){
            cin>>S[i][j];
            S[i][j]--;
        }
    }

    fill_n(F,N,1001001001);
    rep(i,N)if(W[i])F[i]=1;

    for(int i=0;i<N;i++){
        for(int j=0;j<E;j++){
            vint v;
            rep(k,C[j])v.pb(F[S[j][k]]);
            sort(all(v));
            reverse(all(v));
            int w=0;
            rep(k,C[j]){
                if(w-k<v[k]){
                    w=k+v[k];
                }
            }
            chmin(F[G[j]],w);
        }
    }
    T--;
    if(F[T]==1001001001)cout<<-1<<endl;
    else cout<<F[T]<<endl;
    return 0;
}

Measured memory_bytes: 3232
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define fi first
#define se second

void out(int x){
    int count=5,y=x;
    while(x/10 != 0){
        count--;
        x/=10;
    }

    for(int i=0;i < count;i++)
    {
        cout << '0';
    }
    cout << y;
}

int main(){
    int n,m;
    cin >> n >> m;
    map<pair<int,int>,int> ma;//県と年からソート番号
    vector<vector<int>> fs(n+1,vector<int>(0));//県ごとに年でソートする用 //
    vector<pair<int,int>> fo;//入力順で保持
    for(int i=0;i < m;i++)
    {
        int p,y;
        cin >> p >> y;
        fs.at(p).push_back(y);
        
        auto z = make_pair(p,y);
        fo.push_back(z);
    }
    for(int i=0;i < n+1;i++)
    {
        sort(fs.at(i).begin(),fs.at(i).end());
    }//県ごとにソート

    for(int i=1;i < n+1;i++)
    {
        for(int j=0;j < fs.at(i).size();j++)
        {
            ma[make_pair(i,fs.at(i).at(j))]=j+1;
        }
    }//mapに格納

    for(int i=0;i < m;i++)
    {
        out(fo.at(i).fi);
        out(ma[make_pair(fo.at(i).fi,fo.at(i).se)]);
        cout << endl;
    }//output
}

Measured memory_bytes: 13940
#include<stdio.h>
#include<stdlib.h>
#define NIL NULL

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;

Node root;

Node treeMinimum(Node x){
  while(x->left != NIL) x = x->left;
  return x;
}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;z = malloc(sizeof(struct node));
z->key = k;
z->left = NIL;
z->right = NIL;

while(x != NIL){
  y = x;
  if(z->key < x->key) x = x->left;
  else x = x->right;
 }
z->parent = y;
if(y == NIL) root = z;
 else{
   if(z->key < y->key) y->left = z;
   else y->right = z;
 }
}

Node treeSearch(Node u, int k){
  while(u != NIL){
    if(u->key == k) return u;
    else if(u->key > k) u = u->left;
    else u = u->right;
  }
  return NIL;
}

void inorder(Node u){
  if(u == NIL) return;
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
}
void preorder(Node u){
  if(u == NIL) return;
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}

Node treeSuccessor(Node x){
  Node y;

  if(x->right != NIL) return treeMinimum(x->right);

  y = x->parent;
  while(y != NIL && x == y->right){
    x = y;
    y = y->parent;
  }
  return y;
}void treeDelete(Node z){
  Node p;
  Node y; // node to be deleted
  Node x; // child of y

  if(z->left == NIL || z->right == NIL) y = z;
  else y = treeSuccessor(z);

  if(y->left != NIL) x = y->left;
  else x = y->right;

  if(x != NIL) x->parent = y->parent;

  p = y->parent;
  if(y->parent == NIL) root = x;
  else if(y == p->left) p->left = x;
  else p->right = x;

  if(y != z) z->key = y->key;
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    }
    else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
    else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}


Measured memory_bytes: 20476
n = int(input())
slist = []
tlist = []
dist = {}
sumt = 0
for i in range(n):
    s,t = input().split()
    t = int(t)
    slist.append(s)
    tlist.append(t)
for i in range(n):
      sumt += tlist[i]
for i in range(n):
  
    if i+1 <n:
      
      tlist[i+1] += tlist[i]  

        
    
    dist[slist[i]] = tlist[i]
x = input()
ans = sumt - dist[x] 
print(ans)

    
    


Measured memory_bytes: 38256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
 
#pragma GCC optimize("Ofast")
#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,tune=native")
 
using namespace __gnu_pbds;
using namespace std;
     
#define mp make_pair
#define sz(x) (int)((x).size())
#define all(x) (x).begin(),(x).end()
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define eb emplace_back
 
typedef pair< int, int > pii;
typedef pair< long long, long long > pll;
typedef long long ll;
typedef unsigned long long ull;
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef vector< ll > vll;
typedef vector< vll > vvll;
typedef vector< pii > vpii;
typedef vector< vpii > vvpii;
typedef vector< pll > vpll;
typedef long double ld;
typedef vector< ld > vld;
typedef unsigned int uint;
 
const ll MOD2 = 1e9 + 7;
const int MOD = 1e9 + 7;
 
const ull infull = numeric_limits<unsigned long long>::max();
 
void fix(int &x, ll MOD) {
    x = (x % MOD);
    if(x < 0) x += MOD;
    return;
}
 
ll lgput(ll a, ll b, ll MOD) {
    ll ret = 1;
    a %= MOD;
    while(b) {
        if(b&1) ret = ret*a % MOD;
        a = a*a % MOD;
        b >>= 1;
    }
 
    return ret;
}
 
ll inv(ll a, ll MOD) {
    return lgput(a, MOD-2, MOD);
}
 
template <uint MD> struct ModInt {
    using M = ModInt;
    const static M G;
    uint v;
    ModInt(ll _v = 0) { set_v(uint(_v % MD + MD)); }
    M& set_v(uint _v) {
        v = (_v < MD) ? _v : _v - MD;
        return *this;
    }
    explicit operator bool() const { return v != 0; }
    M operator-() const { return M() - *this; }
    M operator+(const M& r) const { return M().set_v(v + r.v); }
    M operator-(const M& r) const { return M().set_v(v + MD - r.v); }
    M operator*(const M& r) const { return M().set_v(uint(ull(v) * r.v % MD)); }
    M operator/(const M& r) const { return *this * r.inv(); }
    M& operator+=(const M& r) { return *this = *this + r; }
    M& operator-=(const M& r) { return *this = *this - r; }
    M& operator*=(const M& r) { return *this = *this * r; }
    M& operator/=(const M& r) { return *this = *this / r; }
    bool operator==(const M& r) const { return v == r.v; }
    const bool operator<(const M& o) const {return v < o.v; }
    M pow(ll n) const {
        M x = *this, r = 1;
        while (n) {
            if (n & 1) r *= x;
            x *= x;
            n >>= 1;
        }
        return r;
    }
    M inv() const { return pow(MD - 2); }
    friend ostream& operator<<(ostream& os, const M& r) { return os << r.v; }
};

using Mint = ModInt<998244353>;

int main() { 
    #ifdef BLAT
        freopen("stdin", "r", stdin);
        freopen("stderr", "w", stderr);
    #endif
 
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout.precision(12);
    srand(time(NULL));

    int n, m;
    cin >> n >> m;

    int cnt = 0;
    int sum = 0;
    vi v(n);
    for(int i = 0; i < n; ++i) {
        cin >> v[i];
        sum += v[i];
    }

    for(int i = 0; i<  n; ++i) {
        if(4*m*v[i] >= sum) {
            ++cnt;
        }
    }

    cout << (cnt >= m ? "Yes\n" : "No\n");
    return 0; 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int x;
  cin >> x;
  int ans = 0;
  FOR(i,1,x+1) ans += i;
  cout << ans << endl;
  return 0;
}

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

int main () {
    char s[999];
    char p[999];
    char s1[999];
    scanf("%s %s", s, p);
    strcpy(s1, s);
    if (strstr(strcat(s1, s), p) != NULL) printf("Yes\n");
    else printf("No\n");
    return 0;
}


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

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

template <class T>
void cout_vec2(const vector<vector<T>> &vec){
  rep(i,vec.size()){
    rep(j,vec[i].size()){
      cout<<vec[i][j]<<' ';
    }
    cout<<endl;
  }
}

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

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin>>n;
  vector<int> p(n),ind(n);
  rep(i,n){
    cin>>p[i];
    p[i]--;
    ind[p[i]]=i;
  }
  multiset<int> cnt;
  cnt.insert(-1),cnt.insert(-1),cnt.insert(n),cnt.insert(n);
  ll ans=0;
  ll a,b,c,d,now;
  for(ll i=n-1;i>=0;i--){
    cnt.insert(ind[i]);
    auto itr=cnt.find(ind[i]);
    now=ind[i];
    itr++,a=*itr;
    itr++,b=*itr;
    itr--,itr--,itr--,c=*itr;
    itr--,d=*itr;
    ans+=(i+1)*((b-a)*(now-c)+(a-now)*(c-d));
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 5760
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Rep(i, k, n) for (int i = k; i < (int)(n); i++)
#define RRep(i, k, n) for (int i = k; i > (int)(n); i--)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define ALL(a)  (a).begin(),(a).end()
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 long long INF = 1LL << 60;
const int MOD = 1000000007;
const double PI = acos(-1); //3.14~
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main()
{
    set<char> s;
    string a; cin >> a;
    rep(i, a.size()) s.insert(a[i]);
    cout << (s.size() == 2 ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
A = [list(map(int, input().split())) for i in range(3)]

N = int(input())

for n in range(N):
    b = int(input())
    for i in range(3):
        for j in range(3):
            if b == A[i][j]:
                A[i][j] = 0


for i in range(3):
    if A[i] == [0, 0, 0]:
        print('Yes')
        exit()

    vertical = [_[i] for _ in A]

    if vertical == [0, 0, 0]:
        print('Yes')
        exit()

if A[0][0] == A[1][1] == A[2][2] == 0 or A[0][2] == A[1][1] == A[2][0] == 0:
    print('Yes')
    exit()
else:
    print('No')

Measured memory_bytes: 9228
#include	<iostream>
#include	<deque>
#include	<string>
#include	<algorithm>

using namespace std;

int main()
{
	int		n;
	cin >> n;
	cin.clear();
	cin.ignore();

	deque<int>	dq;

	string		command;
	int			number;

	for (int i = 0; i < n; i++)
	{
		cin >> command;

		if (command == "insert")
		{
			cin >> number;
			dq.push_front(number);
		}
		else if (command == "delete")
		{
			cin >> number;
			auto it = find(begin(dq), end(dq), number);
			if (it != end(dq))
			{
				dq.erase(it);
			}
		}
		else if (command == "deleteFirst")
		{
			dq.pop_front();
		}
		else
		{
			//deleteLast
			dq.pop_back();
		}

		cin.clear();
		cin.ignore();
	}

	for (auto i = 0u; i < dq.size(); i++)
	{
		if (i != 0u)	cout << " ";
		cout << dq[i];
	}

	cout << "\n";

	return 0;
}

Measured memory_bytes: 6992
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<ctime>
#include<set>

using namespace std;
using ll = long long;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int ti = clock();
  // start-----------------------------------------------
  ll n, q;
  cin >> n;
  vector<set<int>> point(26);
  string s; cin >> s;
  for(int i = 0; i < n; i++){
    point[s[i]-'a'].insert(i);
  }
  cin >> q;
  for(int i = 0; i < q; i++){
    int t, l;
    cin >> t >> l;
    l--;
    if(t == 1){
      char r;
      cin >> r;
      point[s[l]-'a'].erase(l);
      s[l] = r;
      point[s[l]-'a'].insert(l);
    }
    else{
      int r;
      cin >> r;
      r--;
      int tmp = 0;
      for(int j = 0; j < 26; j++){
        auto it = point[j].lower_bound(l);
        if(it != point[j].end() && (*it) <= r) tmp++;
      }
      cout << tmp << endl;
    }
  }

  // end-----------------------------------------------
  cerr << 1.0 * (clock() - ti) / CLOCKS_PER_SEC << endl;
}


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

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

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

#define MOD 1000000007

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

int     main() {
        ll N;
        cin >>N;
        vector<ll> a(N, 0);
        Rep0(i, N)
                cin >>a.at(i);
        Sort(a);
        Rev(a);
        ll ANS=0;
        while (a.front()>=N) {
                ll A=a.front();
                ll NN=A/N;
                ANS +=NN;
                a.at(0)%=N;
                Rep1(i, N-1)
                        a.at(i) +=NN;
                Sort(a);
                Rev(a);
        }
        cout <<ANS <<endl;
        return 0;
}

Measured memory_bytes: 3620
#0や1のケースに注意
#index out of range

def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    import math
    #from math import gcd

    #inf = 10**17
    #mod = 10**9 + 7

    s = input().rstrip()
    t = input().rstrip()
    res = t[:-1]
    if s == res:
        print('Yes')
    else:
        print('No')

if __name__ == '__main__':
    main()

Measured memory_bytes: 65220
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<string> vs;
ll llmax = LLONG_MAX;
vll d1 = {1, 0, -1, 0}, d2 = {0, 1, 0, -1};
string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string alp = "abcdefghijklmnopqrstuvwxyz";
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}
void neg() {cout << -1 << endl;}
void sortll(vll &a) {sort(a.begin(), a.end());}
void sortc(string &a) {sort(a.begin(), a.end());}
void sorts(vs &a) {sort(a.begin(), a.end());}

int main() {
  ll n;
  cin >> n;
  vll a(n);
  for (ll i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (ll i = 0; i < n; i++) {
    if (a[i] % 2 == 0) {
      if (a[i] % 3 > 0 && a[i] % 5 > 0) {
        cout << "DENIED" << endl;
        return 0;
      }
    }
  }
  cout << "APPROVED" << endl;
}

Measured memory_bytes: 256