akhauriyash/Code-Regression huggingface dataset:
# include <bits/stdc++.h>

# define x first
# define y second
# define mp make_pair
// everything goes according to my plan
# define pb push_back
# define sz(a) (int)(a.size())
# define vec vector
// shimkenttin kyzdary, dzyn, dzyn, dzyn...
# define y1    Y_U_NO_y1
# define left  Y_U_NO_left
# define right Y_U_NO_right

# ifdef Local
# define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
# else
# define debug(...) (__VA_ARGS__)
# define cerr if(0)cout
# endif

using namespace std;

typedef pair <int, int> pii;
typedef long long ll;
typedef long double ld;

const int Mod = (int)1e9 + 7;
const int MX = 1073741822;
const ll MXLL = 4e18;
const int Sz = 1110111;
// a pinch of soul
inline void Read_rap () {
  ios_base :: sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
}
inline void randomizer3000 () {
  unsigned int seed;
  asm ("rdtsc" : "=A"(seed));
  srand (seed);
}
void files (string problem) {
  if (fopen ((problem + ".in").c_str(),"r")) {
    freopen ((problem + ".in").c_str(),"r",stdin);
    freopen ((problem + ".out").c_str(),"w",stdout);
  }
}
void localInput(const char in[] = "s") {
  if (fopen (in, "r")) {
    freopen (in, "r", stdin);
  }
  else
    cerr << "Warning: Input file not found" << endl;
}


int main()
{
  # ifdef Local
    //localInput();
  # endif
  Read_rap();
  int n;
  cin >> n;  
  ll a, b;
  cin >> a >> b;
        
  int x[Sz];


  ll d = 0;
  for (int i = 1; i <= n; i++) {
  	cin >> x[i];
  	if (i > 1) {	
  		d += min ((x[i] - x[i-1]) * 1ll * a, b);
  	}
  }
  cout << d;	

  return 0;
}






// Coded by Z..

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

int main() {
  int a1, a2, a3;
  cin >> a1 >> a2 >> a3;

  cout << (a1 + a2 + a3 >= 22 ? "bust" : "win") << endl;
}

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

int main() {
	int a;
	int b;
	cin >> a;
	cin >> b;
	if (a<b) {
		cout << "a < b" << endl;
	}
	else if (a>b) {
		cout << "a > b" << endl;
	}
	else if (a == b) {
		cout << "a == b" << endl;
	}
}


Measured memory_bytes: 3080
import sys
from operator import itemgetter, attrgetter
from itertools import starmap
import math
readline = sys.stdin.readline
EPS = 1e-9
ONLINE_FRONT = -2
CLOCKWISE = -1
ON_SEGMENT = 0
COUNTER_CLOCKWISE = 1
ONLINE_BACK = 2
class Circle(object):
    __slots__ = ('c', 'r')
    def __init__(self, c, r):
        self.c = c
        self.r = r
class Segment(object):
    __slots__ = ('fi', 'se')
    def __init__(self, fi, se):
        self.fi = fi
        self.se = se
Line = Segment
def cross(a, b):
    return a.real * b.imag - a.imag * b.real
def dot(a, b):
    return a.real * b.real + a.imag * b.imag
def norm(base):
    return abs(base) ** 2
def project(s, p2):
    base = s.fi - s.se
    r = dot(p2 - s.fi, base) / norm(base)
    return s.fi + base * r
def reflect(s, p):
    return p + (project(s, p) - p) * 2.0
def ccw(p1, p2, p3):
    a = p2 - p1
    b = p3 - p1
    if cross(a, b) > EPS: return 1
    if cross(a, b) < -EPS: return -1
    if dot(a, b) < -EPS: return 2
    if norm(a) < norm(b): return -2
    return 0
def intersect4(p1, p2, p3, p4):
    return (ccw(p1, p2, p3) * ccw(p1, p2, p4) <= 0 and
			ccw(p3, p4, p1) * ccw(p3, p4, p2) <= 0)
def intersect2(s1, s2):
    return intersect4(s1.fi, s1.se, s2.fi, s2.se)
def getDistance(a, b):  return abs(a - b)
def getDistanceLP(l, p):
    return abs(cross(l.se - l.fi, p - l.fi) / abs(l.se - l.fi))
def getDistanceSP(s, p):
    if dot(s.se - s.fi, p - s.fi) < 0.0: return abs(p - s.fi)
    if dot(s.fi - s.se, p - s.se) < 0.0: return abs(p - s.se)
    return getDistanceLP(s, p)
def getDistances(s1, s2):
    if intersect2(s1, s2): return 0.0
    return min(getDistanceSP(s1, s2.fi), getDistanceSP(s1, s2.se),
               getDistanceSP(s2, s1.fi), getDistanceSP(s2, s1.se))
def getCrossPoint(s1, s2):
	base = s2.se - s2.fi
	d1 = abs(cross(base, s1.fi - s2.fi))
	d2 = abs(cross(base, s1.se - s2.fi))
	t = d1 / (d1 + d2)
	return s1.fi + (s1.se - s1.fi) * t
def getCrossPoints(c, l):
    pr = project(l, c.c)
    e = (l.se - l.fi) / abs(l.se - l.fi)
    base = math.sqrt(c.r * c.r - norm(pr - c.c))
    return Segment(*sorted((pr + e * base, pr - e * base), key=attrgetter('real', 'imag')))
x, y, r = map(int, readline().split())
ci = Circle(complex(x, y), r)
n = int(readline())
for _ in [0] * n:
    p0, p1 = starmap(complex, zip(*[map(int, readline().split())] * 2))
    ppp = getCrossPoints(ci, Line(p0, p1))
    print(*map('{:.10f}'.format, (ppp.fi.real, ppp.fi.imag, ppp.se.real, ppp.se.imag)))

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

class Main {
    public static void main(String[] args) throws IOException {
        Scan sc = new Scan();
        int n = sc.scanInt();
        int ans = 1;
        int min = sc.scanInt();
        for(int i = 1; i < n; ++i){
            int curr = sc.scanInt();
            if(curr <= min){
                ++ans;
                min = curr;
            }
        }
        System.out.println(ans);
    }
}

class Scan
{
    private byte[] buf=new byte[1024];
    private int index;
    private InputStream in;
    private int total;
    public Scan()
    {
        in=System.in;
    }
    public int scan()throws IOException
    {
        if(total<0)
        throw new InputMismatchException();
        if(index>=total)
        {
            index=0;
            total=in.read(buf);
            if(total<=0)
            return -1;
        }
        return buf[index++];
    }
    public int scanInt()throws IOException
    {
        int integer=0;
        int n=scan();
        while(isWhiteSpace(n))
        n=scan();
        int neg=1;
        if(n=='-')
        {
            neg=-1;
            n=scan();
        }
        while(!isWhiteSpace(n))
        {
            if(n>='0'&&n<='9')
            {
                integer*=10;
                integer+=n-'0';
                n=scan();
            }
            else throw new InputMismatchException();
        }
        return neg*integer;
    }
    public double scanDouble()throws IOException
    {
        double doub=0;
        int n=scan();
        while(isWhiteSpace(n))
        n=scan();
        int neg=1;
        if(n=='-')
        {
            neg=-1;
            n=scan();
        }
        while(!isWhiteSpace(n)&&n!='.')
        {
            if(n>='0'&&n<='9')
            {
                doub*=10;
                doub+=n-'0';
                n=scan();
            }
            else throw new InputMismatchException();
        }
        if(n=='.')
        {
            n=scan();
            double temp=1;
            while(!isWhiteSpace(n))
            {
                if(n>='0'&&n<='9')
                {
                    temp/=10;
                    doub+=(n-'0')*temp;
                    n=scan();
                }
                else throw new InputMismatchException();
            }
        }
        return doub*neg;
    }
    public String scanString()throws IOException
    {
        StringBuilder sb=new StringBuilder();
        int n=scan();
        while(isWhiteSpace(n))
        n=scan();
        while(!isWhiteSpace(n))
        {
            sb.append((char)n);
            n=scan();
        }
        return sb.toString();
    }
    private boolean isWhiteSpace(int n)
    {
        if(n==' '||n=='\n'||n=='\r'||n=='\t'||n==-1)
        return true;
        return false;
    }
}

Measured memory_bytes: 22096
#include <stdio.h>

#define SIZE 101
#define INF 1000000

int main(){
  int i,j,k,l,n,M[SIZE][SIZE],P[SIZE];
  
  scanf("%d", &n);
  
  for(i = 0; i < n; i++) scanf("%d%d", &P[i], &P[i+1]);
  for (i = 1; i <= n; i++) M[i][i] = 0;
  for (l = 2; l <= n; l++) {
    for (i = 1; i <= n - l + 1; i++) {
        j = i + l - 1;  M[i][j] = INF;
        for (k = i; k <= j - 1; k++) {
          if (M[i][j] > M[i][k] + M[k + 1][j] + P[i - 1] * P[k] * P[j]) M[i][j] = M[i][k] + M[k + 1][j] + P[i - 1] * P[k] * P[j];
        }
      }
    }
  
  printf("%d\n", M[1][n]);
  
  return 0;
}


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

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPl(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define REPRl(i, n) for(ll i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < (int)n; i++)
#define FORl(i, m, n) for(ll i = m; i < (ll)n; i++)
#define ALL(v) v.begin(), v.end()
ll gcd(ll a,ll b) {
  return b? gcd(b,a%b): a;  
}
ll lcm(ll a,ll b) {
  return a*b/gcd(a,b);
}

int main() {
  int r,d,x;cin>>r>>d>>x;
  REP(i,10){
    int next=r*x-d;
    cout<<next<<endl;
    x=next;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long INF = 1LL << 60; //intじゃ扱えないことに注意！
using P = pair<int,int>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++) //範囲外参照とループの初期化に注意！

const int MX = 100005;

int main() {
    ll n;
    cin >> n;
    vector<ll> cnt(MX);
    rep(i,n){
        int a;
        cin >> a;
        cnt[a]++;
    }
    ll tot = 0;
    rep(i,MX) tot += i*cnt[i];

    int q;
    cin >> q;
    rep(i,q){
        int b,c;
        cin >> b >> c;
        tot -= b*cnt[b];
        tot -= c*cnt[c];
        cnt[c] += cnt[b];
        cnt[b] = 0;
        tot += c*cnt[c];
        cout << tot << endl;
    }
    return 0;
}

Measured memory_bytes: 4000
#include <iostream>
#include <vector>
#include <string>
int main() {
	int n, x, a, i, sum = 0;
	std::cin >> n >> x;
	for (i = 0; i < n; ++i) {
		std::cin >> a;
		sum += a;
		if (sum > x)break;
	}
	std::cout << i + 1 << std::endl;
	return 0;
}

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

int main (){
 
  int A,B,C;
  cin >> A >> B >> C;
  
  if(A == B){
    if(A != C){
    cout << "Yes" << endl;   
    } else {
    cout << "No" << endl; 
    }
  } else {
    if(A == C){
   cout << "Yes" << endl;   
    } else {
      if(B == C){
   cout << "Yes" << endl;
      }else{
   cout << "No" << endl;
     }
    }
   }
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int  long long int
#define mod 1000000000000007
#define pb push_back
#define mp make_pair
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define gcd __gcd
#define fastio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define all(i) i.begin(),i.end()
#define rep(i,a,b) for(int i=a;i<b;i++)
#define set_bit __builtin_popcount //gives number of set_bits
#define ff first
#define ss second
#define cases(t) int t;cin>>t; rep(casn,1,t+1)
#define el cout<<"\n";
#define deci(n) int n; scanf("%lld",&n);
#define decs(n) string n; cin>>n;
#define sz(v) v.size()
#define repit(m) for(auto it=m.begin();it!=m.end();it++)
// #define find(m,i) (m.find(i)!=m.end())
// #define find(m,i) (m.find(i)==m.end())
#define cYES cout<<"YES\n";
#define cNO cout<<"NO\n";
#define ins insert
#define imax 1000000000000000000
#define imin -1000000000000000000
// #define NP 50000
//  cerr << "\nTime : " << (double)clock() / (double)CLOCKS_PER_SEC << "s\n";
 
//  IIITA
//SUNEET KUMAR -->  ਸੁਨੀਤ
 
// scanning numbers extremely fast/////////
void fs(int &number)
{
    bool negative = false;
    register int c;
    number = 0;
    c = getchar();
    if (c=='-')
    {
        negative = true;
        c = getchar();
    }
    for (; (c>47 && c<58); c=getchar())
        number = number *10 + c - 48;
    if (negative)
        number *= -1;
}
// ========================================
int power(int a,int x)
{
        a%=mod;
    int res=1;
    while(x>0)
    {
        if(x&1)
        res=res*a%mod;
        a=a*a%mod;
        x>>=1;
    }
    return res;
}
int max(int a,int b)
{
    if(a>b)
    {
        return a;
    }
    else
    {
        return b;
    }
}
int min(int a,int b)
{
    if(a>b)
    {
        return b;
    }
    else
    {
        return a;
    }
}
int madd(int a,int b)
{
    int ans;
    ans=(a%mod+b%mod)%mod;
    return ans;
}
int mmult(int a,int b)
{
    int ans=1;
    ans=((a%mod)*(b%mod))%mod;
    return ans%mod;
}
int modinverse(int a)
{
    return power(a,mod-2);
}
int p5(int a)
{
    return a*a*a*a*a;
}

 
void nhi_degi()
{
   int x;cin>>x;
   vector<int>v;
   map<int,int>mx;
   for(int i=-5000;i<=5000;i++)
   {
       v.pb(p5(i));
       mx[p5(i)]=i;
   }
   for(int i=0;i<=5000;i++)
   {
       int z=p5(i)-x;
       if(bs(all(v),z))
       {
           cout<<i<<" "<<mx[z];
           break;
       }

   }
}
signed main()
{
    // cases(t)
    // {
        nhi_degi();
    // }
}

Measured memory_bytes: 4220
def resolve():
    A = list(input())
    B = list(input())
    C = list(input())
    A.reverse()
    B.reverse()
    C.reverse()
    d = {"a": A, "b": B, "c": C}
    turn = "a"
    while True:
        if len(d[turn]) == 0:
            print(turn.upper())
            return
        _next = d[turn].pop()
        turn = _next
        



if '__main__' == __name__:
    resolve()

Measured memory_bytes: 3064
N,u,v=[int(i) for i in input().split(" ")]
u-=1
v-=1
graph={}
for i in range(N-1):
    A,B=[int(j) for j in input().split(" ")]
    if A-1 in graph:
        d=graph[A-1]
        d.append(B-1)
        graph[A-1]=d
    else:
        graph[A-1]=[B-1]
    if B-1 in graph:
        d=graph[B-1]
        d.append(A-1)
        graph[B-1]=d
    else:
        graph[B-1]=[A-1]

dist_takahashi=[-1 for i in range(N)]
dist_takahashi[u]=0
next=[u]
d=1
while -1 in dist_takahashi:
    _next=[]
    for n in next:
        nodes=graph[n]
        for i in nodes:
            if dist_takahashi[i]==-1:
                _next.append(i)
    for n in _next:
        dist_takahashi[n]=d
    next=_next
    d+=1

dist_aoki=[-1 for i in range(N)]
dist_aoki[v]=0
next=[v]
d=1
while -1 in dist_aoki:
    _next=[]
    for n in next:
        nodes=graph[n]
        for i in nodes:
            if dist_aoki[i]==-1:
                _next.append(i)
    for n in _next:
        dist_aoki[n]=d
    next=_next
    d+=1


retval=0

for i in range(N):
    if dist_aoki[i]<dist_takahashi[i]:
        continue

    retval=max(retval,dist_aoki[i]-1)


print(retval)


Measured memory_bytes: 36300
#include"bits/stdc++.h"
// #include "prettyprint.hpp"

using namespace std;

#define rep(i, n) for(ll i=0; i<n; i++)
#define repr(i, n) for(ll i=n; i>=0; i--)
#define reps(i, s, e) for(ll i=s; i<e; i++)
#define all(x) x.begin(),x.end()

typedef long long ll;

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

	int swich = 0;

	reps(i,1,10){
		if(N % i == 0 && 1 <= N /i && N/i <= 9){
			cout << "Yes" << endl;
			swich = 1;
			break;
		}
	}

	if(swich == 0) cout << "No" << endl;

	return 0; 
}

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

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

int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    string s;
    cin >> s;
    if (s[1] == s[0] && s[1] == s[2])
        cout << "No";
    else
        cout << "Yes";

    return 0;
}


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

typedef struct{
	long d;
	long t;
}island;

int main(){
	while(1){
		int n;
		island is[25];
		scanf(" %d", &n);
		if(n==0) break;
			
		for(int i=0; i<n; ++i) scanf(" %ld %ld", &is[i].t, &is[i].d);
		
		for(int i=0; i<n; ++i){
			for(int j=i; j<n; ++j){
				if(is[i].d>is[j].d) swap(is[i], is[j]);
				else if(is[i].d==is[j].d){
					if(is[i].t>is[j].t) swap(is[i], is[j]);
				}
			}
		}
		
		long ct=0;
		bool ans=true;
		for(int i=0; i<n; ++i){
			ct+=is[i].t;
			if(ct>is[i].d) ans=false;
			if(!ans) break;
		}
	
		if(ans) printf("Yes\n");
		else printf("No\n");
	}
}

Measured memory_bytes: 1168
MOD = 10 ** 9 + 7
def comb(n, r):
    return fact[n] * pow(fact[n - r], MOD - 2, MOD) * pow(fact[r], MOD - 2, MOD)
def g(r, c):
    return (comb(r + c + 2, c + 1) - 1) % MOD
r1, c1, r2, c2 = map(int, input().split())
FACT_MAX = r2 + c2 + 3
fact = [1] * FACT_MAX
for i in range(1, FACT_MAX):
    fact[i] = fact[i - 1] * i % MOD
print((g(r2, c2) - g(r2, c1 - 1) - g(r1 - 1, c2) + g(r1 - 1, c1 - 1)) % MOD)


Measured memory_bytes: 82164
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <map>
#include <set>
#include <sstream>
#include <stdio.h>
#include <cstdio>
#include <cstring>
#include <math.h>
#include <list>

using namespace std;

#define Rep(i,a,b) for(int i = a; i < b; i++)
#define rep(i,b) Rep(i,0,b)
#define rrep(i,a) for(int i = a; i >= 0; i--)
#define allof(a) (a).begin(), (a).end()

typedef long long ll;
const int inf = 1e9 + 7;
const ll infll = 1ll << 60ll;
const ll mod = 1e9 + 7;
// 0~3までは右左下上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
constexpr int dy[] = { 0, -1, 0, 1, 1, -1, -1, 1 };

/*
// 最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

// 最小公倍数
ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}*/


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

	int n;
	cin >> n;
	ll a, b;
	cin >> a >> b;
	vector<ll> h(n);
	rep(i, n) cin >> h[i];

	// 一体にAダメージ、他にBダメージ

	sort(allof(h), greater<ll>());

	// 最もHPが高いやつに集中する

	// 全員にダメージBを追わせ
	// ある一人に対する追加ダメージをA - B与える

	// 貪欲法
	ll ans = 0;
	ll damage = 0;

	// T回の攻撃で全ての魔物を倒せるか？
	// 倒せる最小のTを探す
	// T(i)が満たしているならT(i+1)も満たす　
	// 2分探索

	int left = 0;
	int right = h[0] / b;
	if (h[0] % b != 0) right++;
	int mid = (right + left) / 2;

	while (left < right) {
		//cout << "l, m, r = " << left << " " << mid << " " << right << endl;
		ll cnt = 0;
		rep(i, n) {
			if (h[i] > mid * b) {
				cnt += (ll)(h[i] - mid * b) / (a - b);
				if ((h[i] - mid * b) % (a - b) != 0) cnt++;
			}
		}
		//cout << cnt << endl;
		if (cnt > (ll)mid) {
			// もっと攻撃回数を増やす
			left = mid + 1;
			mid = (right + left) / 2;
		}
		else if (cnt < (ll)mid) {
			// 攻撃回数を減らす
			right = mid - 1;
			mid = (right + left) / 2;
		}
		else { // ぴったし
			break;
		}
	}

	ll cnt = 0;
	rep(i, n) {
		if (h[i] > mid * b) {
			cnt += (ll)(h[i] - mid * b) / (a - b);
			if ((h[i] - mid * b) % (a - b) != 0) cnt++;
		}
	}
	if (cnt > (ll)mid) mid++;

	cout << mid << endl;

	return 0;
}


Measured memory_bytes: 1024
#include<cstdio>
#include<iostream>
#include<cstring>
#include<vector>
#include<queue>
#include<map>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#include<stack>
#include<set>
using namespace std;
#define pb push_back
#define POP pop_back()
#define ll long long
#define db double
#define POP pop_back()
#define endl '\n'
#define PII pair<int,int>
#define FI first
#define SE second
#define VI vector<int>
#define QI queue<int>
#define SI stack<int>
#define debug cout<<"debug"<<endl;
#define PLL pair<ll,ll>
#define PDD pair<double,double>
#define ULL unsigned long long
#define fo(i,a,b) for (int i=a;i<=b;++i)
#define fd(i,a,b) for (int i=a;i>=b;--i)
#define mem(x,a) memset(x,a,sizeof(x))
const int maxn = 2e5 + 5;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
int main(){
	int n , m;cin >> n >> m;
	puts(m >= n?"unsafe":"safe");
	return 0;
}

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

using namespace std;
typedef long long ll;
const ll mx = 10000007;
const ll mod = 1e9 + 7;
const double pi = acos(-1);
#define gcd(a, b) __gcd((a), (b))
#define lcm(a, b) ((a) / __gcd((a), (b)) * (b))
#define FIO ios_base::sync_with_stdio(false);  cin.tie(NULL);


int main() {
    ll n;
    cin >> n;
    ll a[n];
    for (ll i = 1; i <= n; i++) {
        ll x;
        cin >> x;
        a[i] = (x - i);
    }
    sort(a+1, a+n+1);
    ll p = a[(n+1)/2];
    ll x = 0;

    for (ll i = 1; i <= n; i++) {
        x += abs(a[i] - p);
    }

    cout << x << endl;
    return 0;
}


Measured memory_bytes: 5156
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>

#define BUFSIZE         (1024)

char buf[BUFSIZE];

long
readnum()
{
    long        ret;
    char        *bp;

    bp = fgets(buf, BUFSIZE, stdin);
    if (bp == NULL) goto err;
    ret = atol(buf);
    return ret;

  err:
    perror("error fgets");
    exit(EXIT_FAILURE);
}

int
readnar(char *buf, long *nar, int sz)
{
    int         idx;
    char        *rp;
    char        *nrp;
    long        num;

    rp = buf;
    for (idx = 0; idx < sz; ++idx) {
        num = strtol(rp, &nrp, 10);
        *nar = num;
        ++nar;
        if (rp == nrp) break;
        rp = nrp;
    }
    return idx;
}

#define MAX(a, b)       ((a) < (b) ? (b) : (a))
#define MIN(a, b)       ((a) > (b) ? (b) : (a))

typedef struct stlist   ListPair;
typedef struct stlist {
    ListPair    *next;
    long        first;
    long        second;
} ListPair;

bool
ListContain(ListPair *iel, long ff)
{

    while (iel != NULL) {
        if (iel->first == ff) {
            return true;
        }
        iel = iel->next;
    }
    return false;
}

void
ListPairPush(ListPair **head, long ff, long ss)
{
    ListPair *nel;
    ListPair *iel;
    ListPair **pel;

    nel = malloc(sizeof(ListPair));
    nel->first = ff;
    nel->second = ss;
    nel->next = NULL;

    pel = head;
    iel = *head;
    while (iel != NULL) {
        if (iel->first == ff) {
            free(nel);
            return;
        }
        pel = &(iel->next);
        iel = iel->next;
    }
    *pel = nel;
    return;
}

int
main()
{
    long        vn;
    int         idx;
    int         ik;
    ListPair**  gar;
    int         uu, vv;
    int         kk;
    
    vn = readnum();
    gar = calloc(vn + 1, sizeof(ListPair*));
    for (idx = 0; idx < vn; idx++) {
        scanf("%d", &uu);
        scanf("%d", &kk);
        for (ik = 0; ik < kk; ik++) {
            if (scanf("%d", &vv) <= 0) goto err;
            ListPairPush(&(gar[uu]), vv, 1);
        }            
    }

    for (uu = 1; uu <= vn; uu++) {
        ListPair*       lpv = gar[uu];

        for (vv = 1; vv <= vn; vv++) {
            int tf = 0;

            if ((lpv != NULL) && (vv == lpv->first)) {
                tf = 1;
                lpv = lpv->next;
            } else {
                tf = 0;
            }
            if (vv == vn) {
                printf("%d\n", tf);
            } else {
                printf("%d ", tf);
            }
        }
    }
    
    exit(EXIT_SUCCESS);

  err:
    exit(EXIT_FAILURE);
}



Measured memory_bytes: 2132
#include <stdio.h>
#include <stdlib.h>

#define HASH 1000003

typedef struct List {
	struct List *next;
	char *s;
	int l;
} list;

long long div_mod(long long x, long long y, long long z)
{
	if (x % y == 0) return x / y;
	else return (div_mod((1 + x / y) * y - x, (z % y), y) * z + x) / y;
}

int hash_string(char* s)
{
	int i, x = 0;
	for (i = 0; s[i] != 0; i++) x = ((x << 5) + s[i] - 'a') % HASH;
	return x;
}

int lex_smaller(char* s1, char* s2)
{
	int i;
	for (i = 0; s1[i] != 0 && s2[i] != 0; i++) {
		if (s1[i] < s2[i]) return 1;
		else if (s1[i] > s2[i]) return -1;
	}
	if (s1[i] == s2[i]) return 0;
	else if (s1[i] == 0) return 1;
	else return -1;
}

int main()
{
	int i, j, l[200001], N;
	char *S[200001], T[1000001];
	scanf("%d", &N);
	for (i = 1; i <= N; i++) {
		scanf("%s", T);
		for (l[i] = 0; T[l[i]] != 0; l[i]++);
		S[i] = (char*)malloc(sizeof(char) * (l[i] + 1));
		for (j = 0; j <= l[i]; j++) S[i][j] = T[j];
	}
	
	int h, H;
	list *p, *hash[HASH], d[200001];
	for (i = 1; i <= N; i++) {
		h = hash_string(S[i]);
		d[i].s = S[i];
		d[i].l = l[i];
		d[i].next = hash[h];
		hash[h] = &(d[i]);
	}
	
	int k, dp[26];
	long long ans = 0, tmp, pow[32], inv = div_mod(1, 32, HASH);
	for (k = 1, pow[0] = 32; k < 32; k++) pow[k] = pow[k-1] * pow[k-1] % HASH;
	for (i = 1; i <= N; i++) {
		if (l[i] <= 1) continue;
		for (j = 0; j <= l[i]; j++) T[j] = S[i][j];
		h = hash_string(&(T[2]));
		for (j = l[i] - 2, k = 0, tmp = 1; j > 0; j >>= 1, k++) if ((j & 1) == 1) tmp = tmp * pow[k] % HASH;
		for (j = 0; j < 26; j++) dp[j] = 0;
		dp[S[i][0] - 'a'] = 1;
		for (j = 1; j < l[i]; j++) {
			dp[S[i][j] - 'a'] = 1;
			for (k = 0; k < 26; k++) {
				if (dp[k] == 0) continue;
				T[j] = 'a' + k;
				H = (tmp * k + h) % HASH;
				for (p = hash[H]; p != NULL; p = p->next) if (p->l == l[i] - j && lex_smaller(&(T[j]), p->s) == 0) break;
				if (p != NULL) ans++;
			}
			tmp = tmp * inv % HASH;
			h = (h - tmp * (S[i][j+1] - 'a') % HASH + HASH) % HASH;
		}
	}
	
	printf("%lld\n", ans);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 22728
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define rep(i,m,n) for(int (i)=(m);(i)<(n);++(i))
#define rREP(i,m,n) for(int (i)=(n)-1;(i)>=(m);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 1000000001;
constexpr ll mod = 1000000007;
constexpr double PI = 3.1415926535897932;

template<class T>inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T>inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

int main() {
	init();

	int H, W; cin >> H >> W;
	int N; cin >> N;
	vector<int>a(N);
	rep(i, 0, N)cin >> a[i];
	vector<vector<int>>ans(H, vector<int>(W));
	int k = 1;
	rep(i, 0, H) {
		if (i % 2 == 0) {
			rep(j, 0, W) {
				ans[i][j] = k;
				a[k - 1]--;
				if (a[k - 1] == 0)++k;
			}
		}
		else {
			rREP(j, 0, W) {
				ans[i][j] = k;
				a[k - 1]--;
				if (a[k - 1] == 0)++k;
			}
		}
	}
	rep(i, 0, H) {
		rep(j, 0, W) {
			cout << ans[i][j];
			if (j == W - 1)cout << "\n";
			else cout << " ";
		}
	}

	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,m;
    int i,j;
    cin >> n >> m;
    vector<int> ans(m);
    for(i=0;i<n;i++){
        int k;
        cin >> k;
        for(j=0;j<k;j++){
            int a;
            cin >> a;
            ans.at(a-1)++;
            }
    }
    //for(i=0;i<m;i++)cout << ans.at(i);
    //cout << endl;
    int h=0;
    for(i=0;i<m;i++){
        if(ans.at(i)==n)h++;
    }
    cout << h << endl;
    return 0;

}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = in.nextInt();
        }
        System.out.println(minimumCost(a));
    }

    private static long minimumCost(int[] a) {
        int[] sorted = Arrays.copyOf(a, a.length);
        Arrays.sort(sorted);
        int[] indexes = new int[sorted[a.length-1]+1];
        for (int i = 0; i < a.length; i++) {
            indexes[sorted[i]] = i;
        }

        long cost = 0;
        for (int i = 0; i < a.length; i++) {
            int goalIndex = indexes[a[i]];
            if (goalIndex != i && goalIndex >= 0) {
                int cycleSize = 1;
                int cycleMin = a[i];
                int cycleSum = a[i];
                while (goalIndex != i) {
                    int nextInCycle = a[goalIndex];
                    cycleSize++;
                    if (nextInCycle < cycleMin) cycleMin = nextInCycle;
                    cycleSum += nextInCycle;
                    goalIndex = indexes[nextInCycle];
                    indexes[nextInCycle] = -1;
                }
                cost += Math.min(cycleSum + cycleMin * (cycleSize - 2),
                        cycleSum + cycleMin + sorted[0] * (cycleSize + 1));
            }
        }
        return cost;
    }
}



Measured memory_bytes: 30452
#include <string>
#include <vector>
#include <iostream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <functional>
#include <utility>
#include <numeric>
#include <map>
using namespace std;

#define prec(i) cout << fixed << setprecision(i)

void outPut_YN(bool isYes) {
	if(isYes)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}

const long long MOD = 1000000007;

long long fact(long long k) {
	long long sum = 1;
	for (long long i = 2; i <= k; i++)
		sum *= i;

	return sum;
}

long long fact_mod(long long k) {
	long long sum = 1;
	for (long long i = 2; i <= k; i++)
		sum = (sum * i) % MOD;

	return sum;
}

int ctoi(char c) {
	if (c >= '0' && c <= '9')
		return c - '0';
	else
		return -1;
}

long long pow_mod(int a, int b) {
	long long ans = 1;
	for (int i = 0; i < b; i++)
		ans = (ans * a) % MOD;

	return ans;
}

long long powll(long long a, long long  b) {
	long long ans = 1;
	for (long long i = 0; i < b; i++)
		ans = ans * a;

	return ans;
}

long long modinv(long long a) {

	long long b = MOD, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= MOD;
	if (u < 0) u += MOD;

	return u;
}

long long _gcd(long long a, long long b)
{
	if (a < b)
		swap(a, b);

	if (a % b == 0)
		return b;
	else
		return _gcd(b, a % b);
}

long long _lcm(long long a, long long b)
{
	return (((a * b) % MOD) * modinv(_gcd(a, b))) % MOD;
}

int main()
{
	long long n, k, sum = 0, max = 0;

	cin >> n >> k;

	vector<long long> p(n);

	for(int i = 0; i < n; i++)
		cin >> p[i];


	for (int i = 0; i < n; i++) {
		sum += p[i];
		if (i >= k)
			sum -= p[i - k];
		if (sum > max)
			max = sum;
	}

	prec(12);
	cout << (max + k) / 2.0 << endl;

	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n;
ll ans = 0;
int main(){
    scanf("%d",&n);
    for (int i = 1; i <= n; i++){
        ans += (ll)(n-i+1)*i;
    }
    for (int i = 1; i<  n; i++){
        int u,v;
        scanf("%d%d",&u,&v);
        if (u > v) swap(u,v);
        ans -= (ll)u*(n-v+1);
    }
    printf("%lld",ans);
}


Measured memory_bytes: 3828
#define debug 0
#define test 0
#define CPLUS 1
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#if CPLUS
#include <iostream>
#include <stack>
#include <string>
#include<algorithm>
using namespace std;
#endif

int a[100005];


int check(int n1, int n2, int n4)
{
	if (n4 >= n1)
		return 1;
	else if (n1 == n4 + 1 && n2 == 0)
		return 1;
	else
		return 0;
}

int main(void)
{
#if debug
	freopen("in.txt", "r", stdin);
#endif
	int i, n;
	cin >> n;
	int n1=0, n2 = 0, n4 = 0;
	for (i = 0; i < n; i++) {
		cin >> a[i];
		if (a[i] % 4 == 0)
			n4++;
		else if (a[i] % 2 == 0)
			n2++;
		else
			n1++;
	}
#if test
	printf("%d %d %d", n1, n2, n4);
#endif
	if (check(n1, n2, n4))
		printf("Yes\n");
	else
		printf("No\n");
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
using namespace std;
int main(){
	int a;
	cin>>a;
	int n[4];
	n[0]=a/1000;
	n[1]=a/100%10;
	n[2]=a/10%10;
	n[3]=a%10;
	if((n[0]==n[1]&&n[1]==n[2])||(n[1]==n[2]&&n[2]==n[3])) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <limits>
#include <functional>

template <class Data, class Operator>
class SegmentTree {
    using DataMerger = std::function<Data(Data, Data)>;
    using Applier = std::function<Data(Operator, Data)>;

private:
    int length;
    std::vector<Data> dat;
    Data dat_id;        // データの単位元
    DataMerger dmerge;  // データをマージする関数
    Applier app;        // データに作用素を適用する関数

    Data query(int ql, int qr, int nidx, int nl, int nr) {
        if (nr <= ql || qr <= nl) return dat_id;
        if (ql <= nl && nr <= qr) return dat[nidx];
        Data vl = query(ql, qr, nidx * 2, nl, (nl + nr) / 2);
        Data vr = query(ql, qr, nidx * 2 + 1, (nl + nr) / 2, nr);
        return dmerge(vl, vr);
    }

public:
    explicit SegmentTree(int N, Data dat_id, DataMerger dmerge, Applier app)
        : length(1), dat_id(dat_id), dmerge(dmerge), app(app) {
        while (length < N) length <<= 1;
        dat.assign(length * 2, dat_id);
    }

    // half-open interval [ql, qr)
    Data query(int ql, int qr) { return query(ql, qr, 1, 0, length); }

    void update(int idx, Operator e) {
        int nidx = idx + length;
        dat[nidx] = app(e, dat[nidx]);
        while (nidx > 0) {
            nidx >>= 1;
            dat[nidx] = dmerge(dat[nidx * 2], dat[nidx * 2 + 1]);
        }
    }
};

using lint = long long;
constexpr lint INF = std::numeric_limits<lint>::max() / 3;

struct Seg {
    int l, r;
    lint c;
};

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

    std::vector<Seg> segs(m);
    for (auto& s : segs) {
        std::cin >> s.l >> s.r >> s.c;
        --s.l, --s.r;
    }

    // 終端でソート
    std::sort(segs.begin(), segs.end(),
              [](Seg a, Seg b) { return a.r < b.r; });

    SegmentTree<lint, lint> seg(
        n, INF,
        [](lint a, lint b) { return std::min(a, b); },
        [](lint e, lint a) { return std::min(e, a); });
    seg.update(0, 0);

    for (auto s : segs) {
        seg.update(s.r, seg.query(s.l, s.r) + s.c);
    }

    lint ans = seg.query(n - 1, n);
    std::cout << (ans == INF ? -1 : ans) << std::endl;
    return 0;
}


Measured memory_bytes: 3840
n = int(input())
c = []
s = []
f = []
for i in range(n - 1):
    a, b, d = map(int, input().split())
    c.append(a)
    s.append(b)
    f.append(d)
for i in range(n - 1):
    tot = s[i] + c[i] # time to wait + time to travel
    for j in range(i + 1, n - 1):
        if(tot >= s[j]):
            if(tot % f[j] == 0): tot += c[j]
            else: tot += f[j] - (tot % f[j]) + c[j]
        else:
            tot += (s[j] - tot) + c[j]
    print(tot)
print(0)


Measured memory_bytes: 41708
#include<iostream>
using namespace std;
int main(){
  int N;
  bool info[100][100] = {{}};
  cin >> N;
  for(int i = 0; i < N; i++){
    int u, k;
    cin >> u >> k;
    while(k--){
      int v;
      cin >> v;
      info[u - 1][v - 1] = true;
    }
  }
  for(int i = 0; i < N; i++){
    for(int j = 0; j < N; j++){
      cout << info[i][j] << (j + 1 == N ? '\n' : ' ');
    }
  }
}

Measured memory_bytes: 1176
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int sum=0,i,j,n,p,x1=0,flag=0;
    cin>>n;
    p=sqrt(n);
    for(i=1; i<=p; i++)
    {
        if(n%i==0 && i<10 && (n/i)<10)
        {
            flag=1;
            break;
        }
    }
    if(flag==1)
    {
        cout<<"Yes";
    }
    else
        cout<<"No";
    }


Measured memory_bytes: 3668
#include <iostream>
#include <vector>

using namespace std;

int main(){
    long long N,M;
    cin >> N >> M;

    if(N==1 && M!=1){
        printf("%llu\n",M-2);
    }else if(N!=1 && M==1){
        printf("%llu\n",N-2);
    }else if(N==1 && M==1){
        cout << 1 << endl;
    }else{
        printf("%llu\n",N*M-(2*N+2*M-4));
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int 
int main()
{
    ll red,green,blue;
    cin >> red >> green >> blue;
    ll k;
    cin >> k;
    ll count=0;
    while(green<=red)
    {
        green*=2;
        count++;
    }
    //cout << green;
    while(blue<=green)
    {
        blue*=2;
        count++;
    }
    if(count <=k)
    {
        cout << "Yes\n";

    }
    else 
    {
        cout <<"No\n";
    }

}


Measured memory_bytes: 3632
x, k, d = map(int, input().split())
x = abs(x)
# x > 0のとき
left = abs(x - d * (x // d + 1))
right = abs(x - d * (x // d))

if k < x // d:
    print(x - d * k)
    exit()

if (k - (x // d)) % 2 == 0:
    print(right)
else:
    print(left)
    


Measured memory_bytes: 9100
using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
static class Program{
	const int mod=(int)1e9+7;
	static void Main(){
		Sc sc=new Sc();
		var s=sc.Ia;
		var a=sc.Ia;
		Array.Sort(a,(u,v)=>v-u);
		long ans=0;
		for(int i = s[1];i<a.Length;i++) {
			ans+=a[i];
		}
		Console.WriteLine(ans);
	}
}
public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
	public object[] Oa{get{return Console.ReadLine().Split();}}
	public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),int.Parse);}}
	public int[] Ia3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),int.Parse);}
	public int[] Ia3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),int.Parse);}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}}
	public long[] La3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),long.Parse);}
	public long[] La3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),long.Parse);}
	public T[] Arr<T>(int n,Func<T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f();}return a;}
	public T[] Arr<T>(int n,Func<int,T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i);}return a;}
	public T[] Arr<T>(int n,Func<string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(Console.ReadLine().Split());}return a;}
	public T[] Arr<T>(int n,Func<int,string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i,Console.ReadLine().Split());}return a;}
}

Measured memory_bytes: 32732
#!/usr/bin/env python
N, M = map(int, input().split())
X = list(map(int, input().split()))
X.sort()
if N >= M:
    print(0)
else:
    diff = []
    for m in range(M-1):
        diff.append(X[m+1] - X[m])
    diff.sort()
    if N == 1:
        print(sum(diff))
    else:
        print(sum(diff[:-(N-1)]))

Measured memory_bytes: 13968
n,c,k = map(int, input().split())
t = [int(input()) for i in range(n)]
t.sort()
cnt = 0
st=-1
num = 0
for i in t:
    num+=1
    if num>c:
        st=i
        cnt+=1
        num=1
        continue
    if st == -1:
        st = i
    if i-st > k:
        st = i
        cnt += 1
        num = 1
        continue
if num:
    cnt+=1
print(cnt)

Measured memory_bytes: 7488
#include <cstdio>
#include <algorithm>
#define LL long long
#define maxn 5010
using namespace std;
LL p[maxn],c[maxn],t[maxn],d[maxn],mid[maxn];
int main(){
	int n,k,i,now,cnt=0,tot;
	LL mx=(LL)-10000000000,val;
	scanf("%d%d",&n,&k);
	for(i=1;i<=n;i++)scanf("%lld",&p[i]);
	for(i=1;i<=n;i++)scanf("%lld",&c[i]);
	for(i=1;i<=n;i++){
		now=p[i],d[i]=c[now],t[i]=1,mid[i]=(LL)-10000000000,mid[i]=max(d[i],mid[i]);
		while(1){
			if(now==i)break;
			t[i]++,now=p[now],d[i]+=c[now],mid[i]=max(d[i],mid[i]);
		}
	}
	//for(i=1;i<=n;i++)printf("i=%d t[i]=%lld d[i]=%lld mid[i]=%lld mx=%lld\n",i,t[i],d[i],mid[i],mx);
	for(i=1;i<=n;i++){
		tot=k,val=tot/t[i]*d[i],tot%=t[i];
		if(k/t[i]>0)mx=max(mx,mid[i]),mx=max(mx,(k/t[i]-1)*d[i]+mid[i]);
		//printf("i=%d mx=%lld\n",i,mx);
		if(tot==0)continue;
		now=p[i],val+=c[now],mx=max(mx,val),cnt=1;
		while(1){
			if(tot==cnt)break;
			cnt++,now=p[now],val+=c[now],mx=max(mx,val);
		}					
	}
	printf("%lld\n",mx);
	return 0;
}

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

int main() {
  int n;
  cin>>n;
  int a[n];
  for(int i=0;i<n;i++){
    int l;
    cin>>l;
    a[i]=l;
  }
  sort(a,a+n);
  long long ans=0;
  for(int i=0;i<n-2;i++){
    for(int j=i+1;j<n-1;j++){
      for(int k=j+1;k<n;k++){
        if(a[i]+a[j]>a[k])ans++;
        else break;
      }
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
typedef long long ll;
const int maxn=2e5+5;
const int mod=998244353;
int n,q,tot;
int p[maxn];
struct node{
    int l,r,base,sum,lazy;
}t[maxn<<2];
void pushup(int rt){
    t[rt].sum=(t[rt<<1].sum+t[rt<<1|1].sum)%mod;
}
void pushdown(int rt){
    if(t[rt].lazy){
    t[rt<<1].lazy=t[rt].lazy;
    t[rt<<1|1].lazy=t[rt].lazy;
    t[rt<<1].sum=1ll*t[rt<<1].base*t[rt<<1].lazy%mod;
    t[rt<<1|1].sum=1ll*t[rt<<1|1].base*t[rt<<1|1].lazy%mod;
    t[rt].lazy=0;
    }
}

void build(int l,int r,int rt){
    t[rt].l=l;t[rt].r=r;
    if(l==r){
        t[rt].base=p[tot--];
        t[rt].sum=t[rt].base;
        return ;
    }
    int mid=l+r>>1;
    build(l,mid,rt<<1);
    build(mid+1,r,rt<<1|1);
    t[rt].base=(t[rt<<1].base+t[rt<<1|1].base)%mod;
    pushup(rt);
}
void update(int L,int R,int d,int rt){
    int l=t[rt].l,r=t[rt].r;
    if(L<=l&&r<=R){
     t[rt].lazy=d;
     t[rt].sum=1ll*t[rt].base*d%mod;
     return ;
    }
    pushdown(rt);
    int mid=l+r>>1;
    if(R<=mid)update(L,R,d,rt<<1);
    else if(L>mid)update(L,R,d,rt<<1|1);
    else{
        update(L,mid,d,rt<<1);
        update(mid+1,R,d,rt<<1|1);
    }
    pushup(rt);
}

int query(int L,int R,int rt){
    int l=t[rt].l,r=t[rt].r;
    if(L<=l&&r<=R){
        return t[rt].sum;
    }
    pushdown(rt);
    int mid=l+r>>1;

    if(R<=mid)return query(L,R,rt<<1);
    else if(L>mid)return query(L,R,rt<<1|1);
    else{
     return (query(L,mid,rt<<1)+query(mid+1,R,rt<<1|1))%mod;
    }
}
int main(){
    scanf("%d%d",&n,&q);
    tot=n;
    p[1]=1;
    for(int i=2;i<=n;i++)p[i]=1ll*p[i-1]*10%mod;
    build(1,n,1);

    while(q--){
    int l,r,d;
    scanf("%d%d%d",&l,&r,&d);
    update(l,r,d,1);
    printf("%d\n",query(1,n,1));

    }
    return 0;
}


Measured memory_bytes: 14808
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
using namespace std;
typedef vector<int> vi;
typedef vector< vi > vvi;
int main() {
	int n, m;
	cin >> n >> m;
	vector< vector <int> > a(n,vector<int>(m));
	vector <int> b(m);
	vector <int> c(n);
	for (int i = 0; i < n; i++) {
		c[i] = 0;
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			cin >> a[i][j];
		}
	}
	for (int i = 0; i < m; i++) {
		cin >> b[i];
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			c[i] += a[i][j] * b[j];
		}
	}
	for (int i = 0; i < n; i++) {
		cout << c[i] << endl;
	}
}

Measured memory_bytes: 1256
#include<bits/stdc++.h>
using namespace std;
#define f(i,a,b) for(register int i=a;i<=b;++i)
#define ll long long
#define N 200005
inline int read()
{
	int s=0,w=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){
		if(ch=='-') w=-1;
		ch=getchar();
	}
	while(ch<='9'&&ch>='0'){
		s=(s<<1)+(s<<3)+(ch^48);
		ch=getchar();
	}
	return s*w;
}
int num[10000005];
int main()
{
	int n=read();
	ll ans=0;
	for(int i=1;i<=n;++i)
		for(int j=1;j*i<=n;++j)
			++num[i*j];
	//f(i,1,100) cout<<num[i]<<" ";
	f(i,1,n) ans+=(ll)i*num[i];
	cout<<ans;
	return 0;
}

Measured memory_bytes: 42696
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner n=new Scanner(System.in);
		int w=n.nextInt();int h=n.nextInt();
		int x=n.nextInt();int y=n.nextInt();
		int r=n.nextInt();
		if((x+r)>w||(y+r)>h||(x-r)<0||(y-r)<0)System.out.println("No");
		else System.out.println("Yes");
	}
}

Measured memory_bytes: 17304
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int n = sc.nextInt();
        
        if(n == 0){
            System.out.println(x);
            return;
        }
        
        int ans = 0;
        Set set = new HashSet();
        
        for(int i = 0; i < n; i++){
            int p = sc.nextInt();
            set.add(p);
        }
        
        for(int j = 0;j < 51 ;j++){
            int small = x - j;
            if(!set.contains(small)){
                System.out.println(small);
                return;
            }
            
            int large = x + j;
            if(!set.contains(large)){
                System.out.println(large);
                return;
            }
        }
    }
}


Measured memory_bytes: 35808
import math
k =  int(input())
ans = 0

for a in range(1, k+1):
    for b in range(1, k+1):
        if math.gcd(a, b) == 1:
            ans += k
        else:
            for c in range(1, k+1):
                ans += math.gcd((math.gcd(a, b)), c)

print(ans)


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

#define INF 1000000

int main() {
  int N, T, i, ans = INF;
  cin >> N >> T;
  vector<int> c(N), t(N);
  for (i = 0; i < N; i++) {
    cin >> c[i] >> t[i];
  }
  for (i = 0; i < N; i++) {
    if (t[i] <= T) {
      ans = min(ans, c[i]);
    }
  }
  if (ans == INF) {
    cout << "TLE"
         << "\n";
  } else {
    cout << ans << "\n";
  }
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h> //Ithea Myse Valgulious
namespace chtholly{
typedef long long ll;
#define re0 register int
#define rec register char
#define rel register ll
#define gc getchar
#define pc putchar
#define p32 pc(' ')
#define pl puts("")
/*By Citrus*/
inline int read(){
  int x=0,f=1;char c=gc();
  for (;!isdigit(c);c=gc()) f^=c=='-';
  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
  return f?x:-x;
  }
template <typename mitsuha>
inline bool read(mitsuha &x){
  x=0;int f=1;char c=gc();
  for (;!isdigit(c)&&~c;c=gc()) f^=c=='-';
  if (!~c) return 0;
  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
  return x=f?x:-x,1;
  }
template <typename mitsuha>
inline int write(mitsuha x){
  if (!x) return 0&pc(48);
  if (x<0) x=-x,pc('-');
  int bit[20],i,p=0;
  for (;x;x/=10) bit[++p]=x%10;
  for (i=p;i;--i) pc(bit[i]+48);
  return 0;
  }
inline char fuhao(){
  char c=gc();
  for (;isspace(c);c=gc());
  return c;
  }
}using namespace chtholly;
using namespace std;

int main(){
string a;
cin>>a;int cnt[999]={0};
for (char c:a) cnt[c]++;
for (char k='a';k<='c';++k) if (cnt[k]!=1) return puts("No"),0;
puts("Yes");
}

Measured memory_bytes: 256
// </> : towhid1zaman

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair< int, int > pii;
typedef pair< pii, int > ppi;
#define fill(a,b) memset(a,b,sizeof(a))
#define all(v) (v).begin(),(v).end()
#define sp(k) cout<<setprecision(k)<<fixed;
#define rep(i,a) for(int i=0;i<a;i++)
#define rep1(i,a,b) for(int i=(a);i<=(b);++i)
#define irep(i,b,a) for(int i=(b);i>=(a);--i)
#define minv(v) *min_element(all(v))
#define maxv(v) *max_element(all(v))
#define unq(v) sort(all(v)),(v).erase(unique(all(v)),(v).end())
#define _ ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl "\n"
#define sqr(a) ((a)*(a))
#define sz(a) int(a.size())
#define ff first
#define ss second
#define pb push_back

const double pi = acos(-1.0);
const int mod = 1000000007; // (int)1e9+7
const int inf = 0x3f3f3f3f;// (int)3e18;
const int maxn = 2000100;



int main(){
        _
        string s; cin >> s;
        int mx = 0;
        int cnt = 0;
        for(int i = 0; i<s.size(); i++){
            if(s[i]=='A' or s[i]=='C' or s[i]=='G' or s[i]=='T'){
                cnt++;
                mx = max(cnt,mx);
            }
            else{
                cnt = 0;
            }
        }
        cout<< mx << endl;

return 0;
}




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

int main(){
	char x[105];
	char y[105];
	char z[105];
	int a,b;
	scanf("%s %s %s", &x,&y,&z);
	a = strlen(x)-1;
	b = strlen(y)-1;
	if ( x[a]== y[0] && y[b]==z[0]){
		printf("YES\n");
	}	
	else{
		printf("NO\n");
	}
	return 0;
}

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

using namespace std;

int main(void){
    int n;
    cin >> n;
    int a[n];
    int x[n];
    for(int i = 0; i < n; i++){
        cin >> a[i];
        x[a[i]-1] = i;
    }
    for(int i = 0; i < n-1; i++){
        cout << x[i]+1 << " ";
    }
    cout << x[n-1]+1 << endl;
    return 0;
}

Measured memory_bytes: 1536
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Scanner;

/**
 *
 * @author saku
 */
public class Main {

    public static void main(String args[]) throws IOException {

        BufferedReader std = new BufferedReader(new InputStreamReader(System.in));
        String[] s = std.readLine().split(" ");
        int a = Integer.parseInt(s[0]);
        int b = Integer.parseInt(s[1]);
        int c = Integer.parseInt(s[2]);
        
        Arrays.sort(s);
        System.out.println(s[0] + " " + s[1] + " " + s[2]);

    }

}

Measured memory_bytes: 24364