akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);++i)
template<class T> inline void chmin(T &a, T b){if(a>=b)a=b;}
template<class T> inline void chmax(T &a, T b){if(a<=b)a=b;}
typedef long long ll;

int N,Q;
string s;
char t[210000],d[210000];

int main()
{
    int N, Q;
    string s;
    cin >> N >> Q >> s;
    REP(i, Q) cin >> t[i] >> d[i];
 
    // L = 左から辿り消滅するもっとも右側のゴーレム
    // R = 右から辿り消滅するもっとも左側のゴーレう
    int L = -1, R = N;
    // 移動を後ろ側から辿る
    for(int i = Q-1; i >= 0; --i)
    {
        if (d[i] == 'L')
        {
            // 左からL+1番目は消滅
            if(L+1 < N && s[L+1]==t[i]){
                ++L;
            }

            if(R < N && s[R]==t[i]){
                ++R;
            }
        }
        else
        {
            if(L >= 0 && s[L]==t[i]){
                --L;
            }

            // 右からR-1番目は消滅
            if(R > 0 && s[R-1]==t[i]){
                --R;
            }
        }
        if (L + 1 >= R) break;
    }
    
    cout << max(R-L-1,0) << endl;
}

Measured memory_bytes: 1028
#include <iostream>

using namespace std;
long n, a, b;
int main() {
    cin >> n >> a >> b;

    long k = n / (a +b);
    long h = n % (a + b);
    //cout << k << endl;
    long c = k * a;
    //cout << h << endl;
    //cout << c << endl;
    if ( a >=h ) c=c+h; else c=c+a;
    cout << c << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
 
    int64_t n;
    cin>>n;
    
    int64_t sum=0;
    for(int i=1;i<=n;i++){
        if(i%3==0&&i%5==0)
            ;
        else if(i%3==0)
            ;
        else if(i%5==0)
            ;
        else
            sum+=i;
    }


    cout<<sum<<endl;

    return 0;
}  

Measured memory_bytes: 3636
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
//typedef __int64 LL;
//typedef long long int LL;
typedef vector<int> ivec;
typedef vector<string> svec;
typedef pair<int,int> P;

const int MOD=1000000007;

vector<P> hoge;
vector<P> hoge2;
int main(){
	int n;
	string ans="Yes";
	cin>>n;
	int hantei=0;
	for(int i=0;i<n;i++)
	{
		string s;
		cin>>s;
		int po=0;
		int kiken=0;
		for(int j=0;j<s.size();j++)
		{
			if(s[j]=='(')po++;
			else po--;
			kiken=min(min(0,po),kiken);
		}
		hantei+=po;
		if(po>=0)hoge.push_back(P(kiken,po));
		else
		{
			hoge2.push_back(P(kiken-po,-po));
		}
	}
	if(hantei!=0)
	{
		cout<<"No"<<"\n";
		return 0;
	}
	sort(hoge.begin(),hoge.end(),greater<P>());
	sort(hoge2.begin(),hoge2.end(),greater<P>());
	int sum=0;
	for(int i=0;i<hoge.size();i++)
	{
		int k=hoge[i].first,p=hoge[i].second;
		if(sum+k<0){cout<<"No"<<"\n";return 0;}
		else sum+=p;	
	}
	sum=0;
	for(int i=0;i<hoge2.size();i++)
	{
		int k=hoge2[i].first,p=hoge2[i].second;
		if(sum+k<0){cout<<"No"<<"\n";return 0;}
		else sum+=p;	
	}
	cout<<"Yes"<<"\n";
	return 0;
}

Measured memory_bytes: 11236
#include <bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define RI(X) scanf("%d", &(X))
#define RII(X, Y) scanf("%d%d", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define DRI(X) int (X); scanf("%d", &X)
#define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define RS(X) scanf("%s", (X))
#define CASET int ___T, case_n = 1; scanf("%d ", &___T); while (___T-- > 0)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define PII pair<int,int>
#define VI vector<int>
#define VPII vector<pair<int,int> >
#define PLL pair<long long,long long>
#define VPLL vector<pair<long long,long long> >
#define F first
#define S second
typedef long long LL;
using namespace std;
const int MOD = 1e9+7;
LL dp[301][301][301];
void ADD(LL& x,LL v){x=(x+v)%MOD;}
int main(){
    DRII(N,M);
    if(M<N)return 0*puts("0");
    dp[0][0][0]=1;
    REP(i,M){
        REP(j,N){
            for(int k=0;j+k<N;k++){
                if(dp[i][j][k]==0)continue;
                ADD(dp[i+1][j][k],dp[i][j][k]*k);
                ADD(dp[i+1][j][k+1],dp[i][j][k]*(N-1-j-k));
                ADD(dp[i+1][j+k][0],dp[i][j][k]*(j+1));
            }
        }
    }
    return 0*printf("%lld\n",dp[M][N-1][0]);
}


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

int ans = INT_MIN;
int a[11];              // 新しい店をどの時間帯に開けるかを決める01列
int N;
int F[100][14];
int P[100][15];

// void print(void){
//     cout << N << endl;
//     for(int i = 0; i < N; i++){
//         for(int j = 0; j < 10; j++){
//             cout << F[i][j] << " ";
//         }
//         cout << endl;
//     }
//     for(int i = 0; i < N; i++){
//         for(int j = 0; j <= 10; j++){
//             cout << P[i][j] << " ";
//         }
//         cout << endl;
//     }
// }

void func(void){
    int score = 0;
    
    // for(int i = 0; i < 10; i++){
    //     cout << a[i] << " ";
    // }
    // cout << endl;
    
    bool judge = false;
    for(int i = 0; i < 10; i++){        // aが条件を満たしているかを判定(すべて0の場合を除外)
        if(a[i] == 1){
            judge = true;
            break;
        }
    }
    if(!judge)      return;             // 満たしていなければ関数の以下の部分は呼び出さない
    
    else{
        for(int i = 0; i < N; i++){
            int cnt = 0;
            for(int j = 0; j < 10; j++){
                if(a[j] == 1 && F[i][j] == 1)
                    cnt++;
            }
            score += P[i][cnt];
        }
        ans = max(ans, score);
    }
}

void dfs(int pos){      // posまでの0/1の配置は決定しているとする
    if(pos >= 10){
        func();
        return;
    }
    
    a[pos] = 0;         dfs(pos + 1);       // posに0を代入して再帰
    a[pos] = 1;         dfs(pos + 1);       // posに1を代入して再帰
}

int main(void){
    int sub;
    
    cin >> N;
    for(int i = 0; i < N; i++){
        for(int j = 0; j < 10; j++){
            cin >> sub;
            F[i][j] = sub;
        }
    }
    for(int i = 0; i < N; i++){
        for(int j = 0; j <= 10; j++){
            cin >> sub;
            P[i][j] = sub;
        }
    }
    
    // cout << N << endl;
    // for(int i = 0; i < N; i++){
    //     for(int j = 0; j < 10; j++){
    //         cout << F[i][j] << " ";
    //     }
    //     cout << endl;
    // }
    // for(int i = 0; i < N; i++){
    //     for(int j = 0; j <= 10; j++){
    //         cout << P[i][j] << " ";
    //     }
    //     cout << endl;
    // }
    // print();
    
    dfs(0);
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    long long X,K,D;
    cin>>X>>K>>D;
    long long n=abs(X)/D;

     if(K<=n){
         cout<<abs(abs(X)-K*D)<<endl;
     }
     else if(K>n){
         if((K-n)%2==1){
        cout<<abs(abs(X)-(n+1)*D)<<endl;
         }
         else{
             cout<<abs(abs(X)-n*D)<<endl;
         }

     }
}
    

Measured memory_bytes: 3592
import itertools
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush,heapify
from fractions import gcd
from copy import deepcopy
import math
import queue
#import numpy as np
#import sympy as syp(素因数分解とか)
Mod = 1000000007
import sys
sys.setrecursionlimit(1000000) 
  
def sieve_of_eratosthenes(n):
    if not isinstance(n,int):
        raise TypeError("n is not int")
    if n<2:
        raise ValueError("n is not effective")
    prime = [1]*(n+1)
    for i in range(2,int(math.sqrt(n))+1):
        if prime[i] == 1:
            for j in range(2*i,n+1):
                if j%i == 0:
                    prime[j] = 0
    res = []
    for i in range(2,n+1):
        if prime[i] == 1:
            res.append(i)
    return res

def factorial(i):
    if i == 1:
        return 1
    else:
        return i*factorial(i-1)
 
class UnionFind:
    def __init__(self,n):
        self.parent = [i for i in range(n+1)]
        self.rank = [0 for i in range(n+1)]
    
    def findroot(self,x):
        if x == self.parent[x]:
            return x
        else:
            y = self.parent[x]
            y = self.findroot(self.parent[x])
            return y
    
    def union(self,x,y):
        px = self.findroot(x)
        py = self.findroot(y)
        if px < py:
            self.parent[py] = px
        else:
            self.parent[px] = py
 
    def same_group_or_no(self,x,y):
        return self.findroot(x) == self.findroot(y)




def main(): #startline--------------------------------------------
    n,m = map(int,input().split())
    s = list(map(int,input().split()))
    t = list(map(int,input().split()))
    dp = [[0]*(m+2) for i in range(n+2)]
    sdp = [[0]*(m+2) for i in range(n+2)]
    dp[0][0] = 1
    sdp[1][1] = 1
    for i in range(n+1):
        for j in range(m+1):
            if i == 0 and j == 0:continue
            if i>=1 and j >= 1 and s[i-1] == t[j-1]:
                dp[i][j] = sdp[i][j]%Mod
            sdp[i+1][j+1] = (sdp[i+1][j] + sdp[i][j+1] - sdp[i][j] + dp[i][j])%Mod

    print(sdp[n+1][m+1]%Mod)

if __name__ == "__main__":
    main() 
    
#endline===============================================
    

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

int main() {
  int N;
  cin >> N;
  int sum = 0; // 各桁の数字の和

  int n = N;
  while (n > 0) {
    sum += n % 10;
    n /= 10;
  }
  
  if (N % sum == 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


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

#define N_MAX 100

int main() {
    long n;
    cin >> n;
    long L[15];
    for (long i = 0; i < n; i++) {
        cin >> L[i];
    }

    sort(L, L + n);

    long L_sum = 0;
    for (long i = 0; i < n - 1; i++) {
        L_sum += L[i];
    }

    if (L_sum > L[n - 1]) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
from collections import deque
dx = [-1, 0, 1, 0]
dy = [0, -1, 0, 1]
is_wall = [
        (lambda x,y: right[y][x-1]),
        (lambda x,y: bottom[y-1][x]),
        (lambda x,y: right[y][x]),
        (lambda x,y: bottom[y][x]),
        ]
while 1:
    w, h = map(int, raw_input().split())
    if w==h==0: break
    bottom = []
    right = []
    for i in xrange(2*h-1):
        walls = map(int, raw_input().split()) + [1]
        (bottom if i%2 else right).append(walls)
    bottom.append([1] * w)

    dist = [[0]*w for i in xrange(h)]
    deq = deque()
    deq.append((1, 0, 0))
    dist[0][0] = 1
    while deq:
        co, x, y = deq.popleft()
        for k in xrange(4):
            if is_wall[k](x, y): continue
            nx = x + dx[k]; ny = y + dy[k]
            if dist[ny][nx]: continue
            dist[ny][nx] = co+1
            deq.append((co+1, nx, ny))
    print dist[h-1][w-1]

Measured memory_bytes: 6664
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) begin(a),end(a)
#define MS(m,v) memset(m,v,sizeof(m))
#define D10  fixed<<setprecision(5)
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> P;
typedef complex<double> Point;
typedef long long ll;
const int INF = 114514810;
const int MOD = 100000007;
const double EPS = 1e-8;
const double PI = acos(-1.0);
struct edge
{
	int from, to, cost;
	bool operator < (const edge& e) const { return cost < e.cost; }
	bool operator >(const edge& e) const { return cost > e.cost; }
};
///*************************************************************************************///
///*************************************************************************************///
///*************************************************************************************///

int com[1005][1005];

void init()
{
	MS(com, 0);
	REP(i, 1005) com[i][0] = com[0][i] = 1;
	FOR(i, 1, 1005)FOR(j, 1, 1005) com[i][j] = (com[i][j - 1] + com[i - 1][j]) % MOD;
}


int main()
{
	int r, c, a1, b1, a2, b2;
	cin >> r >> c >> a1 >> a2 >> b1 >> b2;
	int d[4];
	int x1 = abs(a1 - b1); int x2 = (a1 > b1 ? r - a1 + b1 : r - b1 + a1);
	int y1 = abs(a2 - b2); int y2 = (a2 > b2 ? c - a2 + b2 : c - b2 + a2);
	d[0] = x1 + y1;
	d[1] = x1 + y2;
	d[2] = x2 + y1;
	d[3] = x2 + y2;
	int cost = *min_element(ALL(d));
	init();

	int ans = 0;
	if (cost == d[0])
	{
		ans += com[x1][y1];
	}
	if (cost == d[1])
	{
		ans += com[x1][y2];
	}
	if (cost == d[2])
	{
		ans += com[x2][y1];
	}
	if (cost == d[3])
	{
		ans += com[x2][y2];
	}
	cout << ans%MOD << endl;
	return 0;
}

Measured memory_bytes: 5116
#include<bits/stdc++.h>
using namespace std;
#define Mod 1e9+7;
int main()
{
    int h,w,i,j;
    cin>>h>>w;
    char A[h][w];
    for(i=0;i<h;i++)
        for(j=0;j<w;j++)
            cin>>A[i][j];
    long long dp[h+1][w+1];
    memset(dp,0,sizeof(dp));
    dp[1][1]=1;
    
    for(i=1;i<=h;i++)
    {
        for(j=1;j<=w;j++)
        {
            if(A[i-1][j-1]=='#')
                dp[i][j]=0;
            else if(i!=1 || j!=1)
                dp[i][j]=(dp[i-1][j]+dp[i][j-1])%1000000007;
        }
    }
    cout<<dp[h][w]<<endl;
}

Measured memory_bytes: 9088
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class MainClass
{
	public const long Giri = 1000000007;

	public class Point
	{
		public int X {get;set;}
		public int Y {get;set;}
	}
	public static void Main(string[] args)
	{
		var p = Input().ToInt();
		int n = p[0];
		int m = p[1];
		
		var students = new List<Point>(n);
		var points = new List<Point>(m);
		for(int i = 0; i < n; i++)
		{
			p = Input().ToInt();
			students.Add(new Point(){ X=p[0], Y=p[1] });
		}
		
		for(int i = 0; i < m; i++)
		{
			p = Input().ToInt();
			points.Add(new Point(){ X=p[0], Y=p[1] });
		}
		
		for(int i = 0; i < n; i++)
		{
			var student = students[i];
			long mindis = 99999999999;
			int minIndex = -1;
			for(int j = 0; j < m; j++)
			{
				var pos = points[j];
				
				var distance = Math.Abs(student.X - pos.X) + Math.Abs(student.Y - pos.Y);
				if(mindis > distance)
				{
					mindis = distance;
					minIndex = j;
				}
			}
			Console.WriteLine(minIndex+1);
		}
	}
	
	static long GCD(long a, long b)
	{
		var v = new[] { a, b };
		while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; }
		return v[0];
	}
	public static string[] Input() { return Console.ReadLine().Split(' '); }
	public static int Clamp(int val, int max, int min = 0) { return Math.Min(max, Math.Max(min, val)); }
}

public static class Smarter
{
	public static int ToInt(this string str) { return int.Parse(str); }
	public static long ToLong(this string str) { return long.Parse(str); }
	public static int[] ToInt(this string[] str)
	{
		var r = new int[str.Length];
		for(int i = 0; i < str.Length; i++) r[i] = str[i].ToInt();
		return r;
	 }
}

Measured memory_bytes: 13268
program ccc

implicit none
integer :: n, i
real(8) :: res
real(8),allocatable, dimension(:) :: v

read*, n
allocate(v(n))
read*, v

call heapsort(n,v)

v(1) = v(1)/((2.0D0)**(n-1))	!2.0D0にしないと誤差が発生してエラー出る
res= v(1)

do i=2,n
v(i) = v(i)/((2.0D0)**(n-i+1))
res = res + v(i)
end do

write(*,'(f0.14)') res

end program


subroutine heapsort(n,array)
  implicit none
  integer,intent(in) :: n
  double precision,intent(inout) :: array(1:n)
 
  integer ::i,k,j,l
  double precision :: t
 
  if(n.le.0)then
     write(6,*)"Error, at heapsort"; stop
  endif
  if(n.eq.1)return

  l=n/2+1
  k=n
  do while(k.ne.1)
     if(l.gt.1)then
        l=l-1
        t=array(L)
     else
        t=array(k)
        array(k)=array(1)
        k=k-1
        if(k.eq.1) then
           array(1)=t
           exit
        endif
     endif
     i=l
     j=l+l
     do while(j.le.k)
        if(j.lt.k)then
           if(array(j).lt.array(j+1))j=j+1
        endif
        if (t.lt.array(j))then
           array(i)=array(j)
           i=j
           j=j+j
        else
           j=k+1
        endif
     enddo
     array(i)=t
  enddo

  return
end subroutine heapsort

Measured memory_bytes: 256
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

int main(){
  string s;
  int A, B;
  cin >> A >> B;
  cin >> s;
  bool flag = true;
  for(int i = 0; i < A + B; i++){
    if(i == A){
      if(s[i] != '-') flag = false;
    }else{
      if(s[i] == '-') flag = false;
    }
  }

  if(flag){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }

  return 0;
}

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

int main() {
  int x, y;
  cin >> x >> y;

  rep(a, x + 1) {
    int b = x - a;
    if (2 * a + 4 * b == y) {
      cout << "Yes" << endl;
      return 0;
    }
  }

  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 3636
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.util.InputMismatchException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

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

    static class TaskC {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            long h = in.nextInt();
            long w = in.nextInt();

            long ans = Integer.MAX_VALUE;

            for (int i = 1; i < w; i++) {
                ans = Math.min(ans, calc(h, w, i));
            }
            for (int i = 1; i < h; i++) {
                ans = Math.min(ans, calc(w, h, i));
            }

            out.println(ans);
        }

        long calc(long h, long w, int x) {
            long a = h * x;

            long b1 = h * ((w - x) / 2);
            long c1 = h * ((w - x) - (w - x) / 2);

            long ans1 = Math.max(a, Math.max(b1, c1)) - Math.min(a, Math.min(b1, c1));

            long b2 = h / 2 * (w - x);
            long c2 = (h - h / 2) * (w - x);

            long ans2 = Math.max(a, Math.max(b2, c2)) - Math.min(a, Math.min(b2, c2));

            return Math.min(ans1, ans2);
        }

    }

    static class InputReader {
        BufferedReader in;
        StringTokenizer tok;

        public String nextString() {
            while (!tok.hasMoreTokens()) {
                try {
                    tok = new StringTokenizer(in.readLine(), " ");
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
            }
            return tok.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(nextString());
        }

        public InputReader(InputStream inputStream) {
            in = new BufferedReader(new InputStreamReader(inputStream));
            tok = new StringTokenizer("");
        }

    }
}



Measured memory_bytes: 21460
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>

int main(){
  VL a(4);
  cin >> a[0] >> a[1] >> a[2] >> a[3];
  VL b(4);
  b[0] = a[0] * a[2];
  b[1] = a[0] * a[3];
  b[2] = a[1] * a[2];
  b[3] = a[1] * a[3];
  sort(b.rbegin(), b.rend());
  ll ans = b[0];
  cout << ans << endl;
  return 0;
}

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



int main() {
    int H,W;
    while (true) {
        cin >> H >> W;
        if (H==0 && W==0) break;
        for (int i=0; i<H; ++i) {
            for (int j=0; j<W; ++j) {
                cout << '#';
            }
            cout << endl;
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3084
import std.algorithm;
import std.container;
import std.conv;
import std.functional;
import std.math;
import std.meta;
import std.random;
import std.range;
import std.stdio;
import std.string;
import std.traits;
import std.typecons;

auto solve(long a, string s){
    return a >= 3200 ? s : "red";
}

void main(){
    auto input = stdin.byLine.map!split.joiner;

    long a;
    a = input.front.to!long;
    input.popFront;

    string s;
    s = input.front.to!string;
    input.popFront;

    static if (is(ReturnType!solve == void))
        solve(a, s);
    else
        solve(a, s).writeln;
}


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

#define double long double
#define int long long
#define pb push_back 
#define Z(c) (int)(c).size()
#define L(c) c[Z(c)-1]
#define F first
#define S second
#define nl "\n"
#define mii map<int,int> 
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define rep(i,iv,n) for(int (i)=(iv);(i)<(n);++(i))
#define FO fflush(stdout) 
#define D1(x) cerr <<"At line "<<__LINE__<<" "<<#x<<"="<<x<<nl
#define D2(x,y) cerr <<"At line "<<__LINE__<<" "<<#x<<"="<<x<<" "<<#y<<"="<<y<<nl
#define D3(x,y,z) cerr <<"At line "<<__LINE__<<" "<<#x<<"="<<x<<" "<<#y<<"="<<y<<" "<<#z<<"="<<z<<nl
#define tr(it,ct) for(auto &(it) : (ct))
#define pi acos(-1)
#define prt(ct) for(auto &(it) : (ct)) cerr<<it<<" "; cerr<<nl
#define prtp(ct) for(auto &(it) : (ct)) cerr<<it.F<<" "<<it.S<<nl; cerr<<nl

typedef vector< int > vi;
typedef vector< vi > vvi;
typedef pair< int,int > pii;
typedef vector< pii > vp;
typedef tree<int, null_type, less<int>, rb_tree_tag, 
             tree_order_statistics_node_update> baap;

void swap(char &a,char &b)
{ auto tm=a; a=b; b=tm; }
                                   
 
  const int mod=1000000007;
  const int mod2=998244353;
  const int INF=1e16+18;
  const int N=2e5+25;
  const int M=2e4;
  
 
 void fft()           
 { 
   int k,n; cin>>k>>n; vi v(n); tr(i,v) cin>>i;
   int ans=k;

   for(int i=0;i<n;++i){ 
     if(i==0)
      ans=min(ans,v[n-1]-v[0]);
     else if(i==n-1)
      ans=min(ans,v[n-2]+k-v[n-1]);
     else
      ans=min(ans,k+v[i-1]-v[i]);
   }

   cout<<ans;
 }

signed main()
{ 
   ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

 
   int tc=1;                         
 //  cin>>tc;

  rep(i,1,tc+1)
  { // cout<<"Case #"<<i<<": ";
   fft();
   if(i<tc)
   cout<<nl;
  }
  
 return 0; 
}

Measured memory_bytes: 1792
import numpy as np
from sys import stdin

'''
Reference: https://codeforces.com/blog/entry/75046#comment-591494 (1-based index)

(0-based index)

For a sequence A[l]..A[k]..A[r] with sum S contributes l * (N - r) to answer.
    0, 1, 2, ..., l....k....r, ..., N - 2, N - 1
    x  x  x   x   x         v   v     v      v
There are l `x` and (N - r) `v`.

Enumerate all possible sequence is impossible. 
Consider all sequeuces with sum S and **ends** at specific r:
    A[l1]...A[r] -> l1 * (N - r)
    A[l2]...A[r] -> l2 * (N - r)
    A[l3]...A[r] -> l3 * (N - r)
    .
    .
    .
which contributes (l1 + l2 + ... + lm) * (N - r) in total.

We can find *sum of left index for all valid sequence* for each r using DP.

    dp[i][s] = the sum of left index for all sequence that
                    1. ends at i
                    2. has sum s
    
    dp[i][:A[i]] = 0  since any sequence ends at i has sum >= A[i]

    dp[i][A[i]] = i + 1
    dp[i][s] = sum(dp[j][s - A[i]] for j in range(i))

    Take A = [2, 3, 4] for example, sequences that end at A[2] are:
    
                   [4] -> dp[2][4] = 3
             [2,    4] ↘
                [3, 4] -> dp[2][s] = dp[2][s - 4] for all s
             [2, 3, 4] ↗
    
    The answer is sum(dp[r][S] * (N - r) for r in range(N))

So the naive implementation is:

    dp = np.zeros((N, max(S, A.max()) + 1), dtype=np.int64)
    for i, a in enumerate(A):
        dp[i, a] = i + 1
        for s in range(a + 1, S + 1):
            dp[i, s] = dp[:i, s - a].sum() % M  # here can be optimized
    
    ans = 0
    for i in range(N):
        ans += (N - i) * dp[i, S]
        ans = ans % M

has time O(N * S * N) which results in TLE.

Using another array to store the cumsum (prefix sum) of dp solves the problem:
'''

N, S = map(int, input().split())
A = np.int32(input().split())
M = 998244353
V = max(A.max(), S)

ans = 0
dp = np.zeros((N, V + 1), dtype=np.int64)
cs = np.zeros(V + 1, dtype=np.int64)
for i, a in enumerate(A):
    dp[i, a] = i + 1
    dp[i, a + 1 : S + 1] = cs[np.arange(a + 1, S + 1) - a]
    cs = (cs + dp[i]) % M
    ans = (ans + (N - i) * dp[i, S]) % M
print(ans)


Measured memory_bytes: 82764
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class MainClass
{
	public const long Giri = 1000000007;
	public const long DpInf = 99999999999999;
	
	public static void Main(string[] args)
	{
		var p = Input();
		var a = p[0].ToInt();
		var b = p[1].ToLong();
		var n = p[2].ToLong();
		
		long x = 0;
		if(n < b)
		{
			//Console.WriteLine(n-1);
			x = n;
		}
		else
		{
			//Console.WriteLine(n-1);
			x = b-1;
		}
		long k = (long)(Math.Floor((double)a * x / b) - a * Math.Floor((double)x/b));
		Console.WriteLine(k);
		/*
		long max = 0;
		for(long x = (b-1)/2; x <= Math.Min(n, b); x++)
		{
			long k = (long)(Math.Floor((double)a * x / b) - a * Math.Floor((double)x/b));
			//Console.WriteLine(k);
			max = Math.Max(max, k);
		}
		Console.WriteLine(max);
		*/
	}
	
	
	static long GCD(long a, long b)
	{
		var v = new[] { a, b };
		while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; }
		return v[0];
	}
	public static string[] Input() { return Console.ReadLine().Split(); }
}

public static class Smarter
{
	public static int ToInt(this string str) { return int.Parse(str); }
	public static long ToLong(this string str) { return long.Parse(str); }
	public static int[] ToInt(this string[] str, int offset = 0)
	{
		var r = new int[str.Length];
		for(int i = 0; i < str.Length; i++) r[i] = str[i].ToInt() + offset;
		return r;
	}
}

Measured memory_bytes: 27396
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
#define P pair<ll, int>
using namespace std;

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

    sort(d.begin(), d.end());
    int ans = 0;
    for (int k = 1; k <= d[N - 1]; k++) {
        int idx = lower_bound(d.begin(), d.end(), k) - d.begin();
        if (idx == N / 2) {
            ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 640
// Java program For handling Input/Output 
import java.io.*;
import java.util.*;
import java.math.*;
//import java.awt.*;

public class Main {
    BufferedReader br;
    StringTokenizer st;

    int max = -1;
    final long P = 998244353;

    HashSet<String> set = new HashSet<>();
    HashMap<String, Integer> map = new HashMap<>();

    // actual logic
    void solve() throws IOException {
        int n = ni();
        int k = ni();

        int a[] = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = ni();

        Arrays.sort(a);
        long ans = 0;
        for (int i = 0; i < k; i++) {
            ans += a[i];
        }
        pl(ans);
    }

    // constructor
    Main() {
        try {
            br = new BufferedReader(new InputStreamReader(System.in));
            try {
                st = new StringTokenizer(br.readLine());
            } catch (Exception e) {
                System.out.println(e);
            }
        } catch (Exception e) {
            System.out.println(e);
        }
    }

    Main(String s) {
        try {
            br = new BufferedReader(new FileReader(s));
            st = new StringTokenizer(br.readLine());
        } catch (Exception e) {
            System.out.println(e);
        }
    }

    // main metohd
    public static void main(String[] args) throws IOException {
        new Main().solve();
    }

    // Utility methods

    String ns() {
        if (!st.hasMoreTokens()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (Exception e) {
                System.out.println(e);
            }
        }
        return st.nextToken();

    }

    int ni() {
        return Integer.parseInt(ns());
    }

    long nl() {
        return Long.parseLong(ns());
    }

    double nd() {
        return Double.parseDouble(ns());
    }

    void pl(String s) {
        System.out.println(s);
    }

    void pl(long s) {
        System.out.println(s);
    }
}


Measured memory_bytes: 33140
#include <bits/stdc++.h>
#define ll long long
#define eps 1e-9
#define PI 2 * acos (0.0)
using namespace std;


int main()
{
   

    int a, b, c, d, e, x, y, z;

    ll N, X, Y;

    cin>>N;

    Y = N / 11;

    X = N % 11;

    if(X <= 6)
    {
    	Y = Y * 2;
    	if(X > 0)
    		{
    			Y++;
    		}
    }
    else
    {
    	Y = Y * 2 + 2;
    }

    cout<<Y<<endl;

    
    return 0;
}


Measured memory_bytes: 256
while true
  h, w = gets.split.map(&:to_i)
  break if h.zero? && w.zero?

  h.times do |n|
    if n % 2 == 0
      puts ('#.'*w)[0,w]
    else
      puts ('.#'*w)[0,w]
    end
  end
  puts
end

Measured memory_bytes: 8820
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApp3
{
    class Program
    {
        static void Main(string[] args)
        {
            Main main = new Main();
            main.Calc();
        }
    }
    class Main { 

        public void Calc()
        {
            var N = int.Parse(Console.ReadLine());
            var D = Console.ReadLine().Split().Select(int.Parse).ToList();
            var prob_set = new Dictionary<int, int>();
            foreach(var d in D)
            {
                if (prob_set.ContainsKey(d)) prob_set[d]++;
                else prob_set[d] = 1;
            }
            var M = int.Parse(Console.ReadLine());
            var T = Console.ReadLine().Split().Select(int.Parse).ToList();
            var judge = "YES";
            foreach(var t in T)
            {
                if (!prob_set.ContainsKey(t))
                {
                    judge = "NO";
                    break;
                }
                if(prob_set[t] <= 0)
                {
                    judge = "NO";
                    break;
                }
                prob_set[t]--;

            }
            Console.WriteLine(judge);
            Console.ReadLine();
        }
    }
}


Measured memory_bytes: 51040
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<cstdio>
 
using namespace std;
 
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define pb push_back
#define pf push_front
 
typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
 
ll gcd(ll x, ll y) {
	ll r;
	while ((r = x % y) != 0) {
		x = y;
		y = r;
	}
	return y;
	}
ll lcm(ll x, ll y) {
	x /= gcd(x, y);
	y /= gcd(x, y);
	return (x*y);
}

int main()
{
	string s;
    int ans=0;
    cin >> s;
    rep(i,s.size()-1){
        if(s[i]!=s[i+1]) ans++;
    }
    cout << ans << endl;
	return 0;
}


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

int main() {
  string s;
  cin>>s;
  ll ans[s.size()+1],sum=0;
  for(int i=0;i<s.size()+1;i++){
    ans[i]=0;
  }
  for(int i=0;i<s.size();i++){
    if(s[i]=='<'){
      ans[i+1]=max(ans[i+1],ans[i]+1);
    }
  }
  for(int i=s.size()-1;i>=0;i--){
    if(s[i]=='>'){
      ans[i]=max(ans[i],ans[i+1]+1);
    }
  }
  for(int i=0;i<s.size()+1;i++){
    sum+=ans[i];
  }
  cout<<sum<<endl;
}

Measured memory_bytes: 4740
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <list> 
#include<algorithm>
#include<cmath>
#include<map>
#include<vector>
#include<string>
#include<fstream>
#include<set>
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define forl(i,a,n) for(int i=a;i<n;i++)
#define rfor(i,n,a) for(int i=n;i>=a;i--)
#define ll long long
#define ull unsigned long long
#define ld long double
#define pb push_back
#define ld long double
#define vi vector<int>
#define vll vector<long long>
#define pi pair<int,int>
#define pll pair<long long,long long>
#define mp make_pair
#define B begin()
#define E end()
#define S size()
#define m9 1000000007
using namespace std;
 
 

 
ll gcd(ll x,ll y)
{
    if(x==0) return y;
    return gcd(y%x,x);
}
 
/*
ll gcdextended(ll a, ll b, ll *x, ll *y) 
{ 
    if (a == 0) 
    { 
        *x = 0, *y = 1; 
        return b; 
    } 
  
    ll x1, y1; 
    int gcd = gcdextended(b%a, a, &x1, &y1); 
   
    *x = y1 - (b/a) * x1; 
    *y = x1; 
  
    return gcd; 
}
 
 
///RELATIVE COPRIME
ll modinverse(ll a, ll m) 
{ 
    ll x, y; 
   ll g = gcdextended(a, m, &x, &y); 
    if (g != 1) 
return -1;
    else
    { 
        ll res = (x%m + m) % m; 
        return res;  
    } 
} 
  */
ll powmod(ll x, ll y, ll m) 
{ 
    if (y == 0) 
        return 1; 
    ll p = powmod(x, y/2, m) % m; 
    p = (p * p) % m; 
    return (y%2 == 0)? p : (x * p) % m; 
} 
///M IS PRIME
ll modif(ll x,ll m){
return(powmod(x,m-2,m));
 
}
 
 
 
#define p0(a) cout << a << " "
#define p1(a) cout << a << endl
#define p2(a, b) cout << a << " " << b << endl
#define p3(a, b, c) cout << a << " " << b << " " << c << endl
#define p4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl
#define pin(a) for(auto x:a)cout<<x<<" ";cout<<endl
#define fck(a) cout<<a;exit(0)
#define vvll vector<vector<ll> >
#define A(b) b.begin(),b.end()
#define vpi std::vector<pll>
#include <array>
#include <stack>
#define arr2 array<ll,2>
#define arr3 array<ll,3>
//include<bits/stdc++.h>
 
 
bool fa(vll &x,vll &y){return x[0]<y[0];}
bool fa1(vll &x,vll &y){return x[1]<y[1];}
bool f1(pll &x,pll &y){return x.second>y.second;}
bool f2(pll &x,pll &y){
    return x.first>y.first;
}
 
 
bool f3(ll &x,ll &y){
    return x>y; 
    }


const ll maxn=1e6+2;


int main()
{ fastio;
//freopen("input.txt, "r", stdin); 
//freopen("output.txt", "w", stdout);
ll x,k,d;cin>>x>>k>>d;
ll y=abs(x);
y/=d;
if(y>=k){
    ll ans=abs(k*d-abs(x));
    p1(ans);
    exit(0);
}
y=min(y,k);
ll ans1=abs(y*d-abs(x));
ll lef=k-y;
y++;
ll ans2=abs(y*d-abs(x));
if(lef%2==0){
    cout<<ans1;
}
else {
    cout<<ans2;
}



 
return 0;
}
 


  





Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i= (a); i < (b); ++i)
typedef long long ll;
typedef pair<int,int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
int main() { int P, Q, R;
  cin >> P >> Q >> R;
  cout << min(P + Q, min(Q + R, R + P)) << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int inf=999999999;
char s[15];
int L;
void work()
{
	long long val=0;
	long long ans=inf;
	for(int i=1;i<=L;i++)
	{
		int j=i+2;
		if(j>L)break;
		val=0;
		for(int k=i;k<=j;k++)
		{
			val*=10;
			val+=s[k]-'0';
		}
		ans=min(ans,abs(val-753));
	}
	printf("%lld",ans);
}
int main()
{
	scanf("%s",s+1);
	L=strlen(s+1);
	work();
	return 0;
}


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

using ll = long long;

int main(){
  int x,y;
  cin >> x >> y;
  bool ans = false;
  for(int i=0;i<=x;i++){
    if((4*x-2*i) == y){
      ans=true;
      break;
    }
  }

  cout << (ans?"Yes":"No") << endl;
}


Measured memory_bytes: 3628
#include <iostream>
#include <set>

using namespace std;

int col(int n) {
  if (n%2 == 0) {
    return n/2;
  } else {
    return 3*n+1;
  }
}

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

  set<int> as;
  as.insert(s);
  int a, fa = s;

  for (int i = 2;; i++) {
    a = col(fa);
    if (as.find(a) != as.end()) {
      cout << i << endl;
      break;
    }
    fa = a;
    as.insert(a);
  }

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    long long N, A, B;
    cin >> N >> A >> B;
    if (A % 2 == B % 2)
        cout << (max(A, B) - min(A, B)) / 2 << endl;
    else {
        long long result = 0;
        if (A < B) {
            long long tmp = B;
            B = A;
            A = tmp;
        }
        long long A_dis = N - A;
        if (A_dis < B-1)
            result += A_dis+1+(N-B);
        else
            result += B + A;
        cout << result / 2 << endl;
    }
}

Measured memory_bytes: 256
a,b = input().split()

def xy(a):
    if a =="A":
        return 10
    elif a =="B":
        return 11
    elif a =="C":
        return 12
    elif a =="D":
        return 13
    elif a =="E":
        return 14
    elif a =="F":
        return 15
    
if xy(a) > xy(b):
    print(">")
elif xy(a) < xy(b):
    print("<")
else:
    print("=")

Measured memory_bytes: 3060
import java.util.*;

public class Main {

    static final int MOD = 1000000007;

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int month = Integer.parseInt(s.substring(5,7));
        int day = Integer.parseInt(s.substring(8,10));
        System.out.println((month<=4&&day<=30)?"Heisei":"TBD");;

    }
}


Measured memory_bytes: 21716
////////////////////////////////////////////////
//  ********  *      *    *******    * *      //                 :
//  *         *      *   *       *   *   *    //     64 BITS     C     64 BITS
//  *****     *      *  *         *  *     *  //                 +
//  *         *      *  ***********  *     *  //:  13 - 6 - 2020 +   13 - 6 - 2020 :
//  *         *      *  *         *  *   *    //                 1
//  *         ********  *         *  * *      //     64 BITS     7     64 BITS
////////////////////////////////////////////////                 :
#define ll long long
#define ui unsigned int
#define ud unsigned double
#define mp make_pair
#define pii pair<int, int>
#define pb push_back
#define pi acos(-1.0)
#define eps 1e-12
#include <bits/stdc++.h>
#include <iostream>
#include <stdio.h>
#include <math.h>
using namespace std;
int main()
{
    int a;
    int b;
    int c;
    scanf("%d%d%d", &a,&b,&c);
    swap(a,b);
    swap(a,c);
    cout << a << " " << b << " " << c << " " << "\n";
    return 0;
}

Measured memory_bytes: 3716
import sys
import math


def solve(lines):
    lines = [int(x) for x in lines]

    rem = [l % 10 if l % 10 != 0 else 10 for l in lines]
    rem_min = min(rem)
    idx = None
    for i, l in enumerate(rem):
        if l == rem_min:
            idx = i

    last = lines.pop(idx)

    lines = [math.ceil(l / 10) * 10 for l in lines]
    result = sum(lines) + last
    print(result)


if __name__ == '__main__':
    lines = sys.stdin.read()
    lines = lines.strip().split('\n')
    solve(lines)

Measured memory_bytes: 3064
#![allow(non_snake_case, dead_code)]
use std::collections::VecDeque;
use std::io::BufRead;

struct MyReader<R: BufRead> {
    __reader: R,
    queue: VecDeque<String>,
}
impl<R: BufRead> MyReader<R> {
    fn new(reader: R) -> MyReader<R> {
        MyReader {
            __reader: reader,
            queue: VecDeque::new(),
        }
    }
    fn read(&mut self) -> String {
        if self.queue.len() == 0 {
            self.__readFromStdin()
        };
        self.queue.pop_front().unwrap()
    }
    fn readN(&mut self) -> i32 {
        self.read().parse().ok().expect("failed paring")
    }
    fn readUN(&mut self) -> usize {
        self.read().parse().ok().expect("failed paring")
    }
    fn readT<T: std::str::FromStr>(&mut self) -> T {
        self.read().parse().ok().expect("failed parsing")
    }

    fn __readFromStdin(&mut self) {
        let mut s = String::new();
        self.__reader.read_line(&mut s).unwrap();
        for it in s.trim().split_whitespace() {
            self.queue.push_back(it.to_string());
        }
    }
}
//*****************************************
fn main() {
    let stdin = std::io::stdin();
    let input = stdin.lock();
    println!("{}", run(input))
}

const DIV: usize = 1000_000_007;

fn run<R: BufRead>(reader: R) -> String {
    let mut myReader = MyReader::new(reader);
    let N = myReader.readUN();

    let mut arr = vec![0usize; N + 1];
    for (i, &v) in [0, 0, 0, 1, 1, 1, 2].iter().enumerate() {
        if arr.len() > i {
            arr[i] = v
        }
    }

    let res = counter(N, &mut arr);

    res.to_string()
}

fn counter(n: usize, arr: &mut Vec<usize>) -> usize {
    let mut v = arr[n];
    if v == 0 && n >= 7 {
        for i in 3..=(n - 3) {
            v += counter(i, arr);
        }
        v = (v + 1) % DIV;
        arr[n] = v;
    }
    v
}


Measured memory_bytes: 2184
#Order can be reduced by diving cases but full search on purpose
a, b, c, x, y = map(int, input().split())
num = float("inf")
for i in range(max(x, y) + 1):
    num = min(num, a * max(0, (x - i)) + b * max(0, (y - i)) + 2 * c * i)
print(num)


Measured memory_bytes: 2940
#include<iostream>
#include<cmath>
#include<cstdio>
#include<vector>
#include<queue>
#include<string>
#include<algorithm>
#include<set>
#include<map>
using namespace std;
using ll = long long;

int main(){
  ll n,a,b;
  cin >> n;
  cin >> a >> b;
  for(int i=a;i<=b;i++){
    if(i%n==0){
      cout << "OK";
      return 0;
    }
  }
  cout << "NG";
}

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


using namespace std;

int main(){
   int n;
   cin>>n;
   int s=0;
  vector<int>k;
  for(int i=0;i<n;i++){
      int p;
      cin>>p;
      k.push_back(p);
  }
  for(int i=0;i<n;i++){
      for(int j=i+1;j<n;j++){
         s=s+(k[i]*k[j]); 
      }
  }
cout<<s;

}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define REP(i,a,n) for(ll i=a;i<n;i++)
#define ALL(s) s.begin(),s.end()
#define P pair<ll,ll>
#define vl vector<ll>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vvl vector<vector<ll>>
#define print(n) cout<<n<<endl
const int M=100010;
const int MOD=1000000007;
const int inf=1000000007;
const long long INF=1000000000000000007;
using ll=long long;
int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int main(){
	int n,m,x[100010]={},ans=0;
	P p[100010];
	cin>>n>>m;
	rep(i,m)cin>>p[i].second>>p[i].first;
	sort(p,p+m);
	ans++;
	int t;
	t=p[0].first;
	rep(i,m)if(t<=p[i].second)t=p[i].first,ans++;
	print(ans);
}

Measured memory_bytes: 1792
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter out = new PrintWriter(System.out);
		StringTokenizer tok = new StringTokenizer(in.readLine());
		int N = Integer.parseInt(tok.nextToken());
		int M = Integer.parseInt(tok.nextToken());
		boolean arr[] = new boolean[N + 1];
		int arr2[] = new int[N + 1];
		arr[1] = true;
		Arrays.fill(arr2, 1);
		int cont = 0;
		for (int i = 0; i < M; i++) {
			tok = new StringTokenizer(in.readLine());
			int x = Integer.parseInt(tok.nextToken());
			int y = Integer.parseInt(tok.nextToken());
			if (arr[x]) {
				if (arr2[x] != 0) {
					// cont++;
					arr2[y]++;
					arr2[x]--;
					if (arr2[x] == 0) {
						arr[x] = false;
					}
					arr[y] = true;
				} else {
					arr2[y]++;
					arr2[x]--;
				}
			} else {
				arr2[y]++;
				arr2[x]--;
			}
		}

		for (int i = 0; i < arr.length; i++) {
			if (arr[i])
				cont++;
		}
		System.out.println(cont);
	}
}


Measured memory_bytes: 40992
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
typedef long long ll;
inline int read(){
	int x=0,f=1;
	char c=getchar();
	while(c<'0'||c>'9'){
		if(c=='-')f=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9'){
		x=(x<<1)+(x<<3)+c-'0';
		c=getchar();
	}
	return x*f;
}
ll a,b,c,d;
int main(){
	a=read(),b=read(),c=read(),d=read();
	printf("%lld\n",max(max(a*c,a*d),max(b*c,b*d)));
	return 0;
}



Measured memory_bytes: 3760
#include <bits/stdc++.h>
 using namespace std;
#define REP(i,n)   for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for(int i=(b); i<=(int)(e); i++)

int main() {
  string s,t,u;
  int a,b;
  cin>>s>>t>>a>>b>>u;
  if(u==s)cout<<a-1<<" "<<b<<endl;
  else cout<<a<<" "<<b-1<<endl;
}
  

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
using namespace std;
int main() {
	int d[3],N;
	scanf("%d",&N);
	for(int i=0;i<N;i++) {
		scanf("%d %d %d",&d[0],&d[1],&d[2]);
		sort(d,d+3);
		printf("%s\n",d[2]*d[2]==d[1]*d[1]+d[0]*d[0]?"YES":"NO");
	}
}

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

#define name ""
#define ini freopen(name".inp","r",stdin); freopen(name".out","w",stdout)
#define long long long
#define db double
#define pii pair <int, int>
#define pll pair <long, long>
#define all(c) c.begin(), c.end()
#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
template <class T> inline void chmin(T &a, const T& val) { if (a > val) a = val; }
template <class T> inline void chmax(T &a, const T& val) { if (a < val) a = val; }
template <class T> long sqr(T a) { return 1ll * a * a; }
template <class T> void compress(T &a){
  sort(all(a)); a.resize(unique(all(a)) - a.begin());  
}

const db pi = acos(-1.00);
const db eps = 1e-6;
const int INF = 1e9;
const int MOD = 1e9+7;
const int dx[4] = {0, 0, -1, 1};
const int dy[4] = {-1, 1, 0, 0};

int main()
{
  fastio;
  int n; cin >> n; 
  n %= 10;
  if (n == 2 || n == 4 || n == 5 || n == 7 || n == 9) cout << "hon";
  else if (n == 0 || n == 1 || n == 6 || n == 8) cout << "pon";
  else cout << "bon";
  return 0;
}

Measured memory_bytes: 3656
import math

N,M = map(int,input().split())

x = math.factorial(int(N))
y = math.factorial(int(M))

if N > 2 and M > 2:
    Nk = N - 2
    Mk = M - 2
    Nk2 = math.factorial(int(Nk))
    Mk2 = math.factorial(int(Mk))
    CN = x // Nk2 // 2
    CM = y // Mk2 // 2
    print(CN + CM)

elif N > 2 and M <= 2:
    Nk = N - 2
    Nk2 = math.factorial(int(Nk))
    CN = x // Nk2 // 2
    M = M // 2
    print(CN + M)

elif N <= 2 and M > 2:
    Mk = M - 2
    Mk2 = math.factorial(int(Mk))
    CM = y // Mk2 // 2
    N = N // 2
    print(CM + N)

elif N <= 2 and M <= 2:
    N = N // 2
    M = M // 2
    print(N + M)


Measured memory_bytes: 3064
#include<bits/stdc++.h> 
using namespace std;
typedef long long ll;
template<typename T1,typename T2> bool chmin(T1 &a,T2 b){if(a<=b)return 0; a=b; return 1;}
template<typename T1,typename T2> bool chmax(T1 &a,T2 b){if(a>=b)return 0; a=b; return 1;}


vector<vector<int>> v(200020);
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    int l,r,d;
    cin>>l>>r>>d;
    int ans = 0;
    for(int i=l;i<=r;i++)if(i%d==0)ans++;
    cout << ans << endl;

}

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


int main() {
  int n;
  cin >> n;
  ll ans =0;
  for(int i = 1; i <= n; i++){
    if(i%3!=0 && i%5!=0)ans+=i;
  }
  cout << ans << endl;
}


Measured memory_bytes: 3412
def main():
    n, m = map(int, input().split())
    ss = [set(), set()]
    for _ in range(m):
        a, b = map(lambda s: int(s) - 1, input().split())
        if a == 0:
            ss[0].add(b)
        elif a == n - 1:
            ss[1].add(b)
        if b == 0:
            ss[0].add(a)
        elif b == n - 1:
            ss[1].add(a)
    if ss[0] & ss[1]:
        print('POSSIBLE')
    else:
        print('IMPOSSIBLE')


if __name__ == '__main__':
    main()


Measured memory_bytes: 18972