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

#define REP(i,n) for(int i=0;i<(n);i++)
#define REAP(i,a,n) for(int i=(a);i<(n);i++)
#define YES cout<<"Yes"<<endl
#define NO cout<<"No"<<endl
#define fr first
#define sc second
#define pb push_back
#define All(v) v.begin(),v.end()
typedef long long ll;

int main(){
    ios::sync_with_stdio(false);
    int d;
    cin >> d;
    int n;
    REP(k,d){
        cin >> n;
        int box[n][n]={};
        for(int i=0;i<n/2+1;i+=2){

            for(int y=i;y<n-i;y++){
                for(int x=i;x<n-i;x++){
                    if(y==i||y==n-i-1||x==i||x==n-i-1)box[y][x]=1;
                }
            }
        }
        for(int i=0;i<n/2;i+=2){
            if(box[n-1-i][i+1]){
                if(box[n-2-i][i+2]==0){
                    if(box[n-3-i][i+2]){
                        swap(box[n-1-i][i+1],box[n-2-i][i+2]);
                    }else{
                        box[n-1-i][i+1]=box[n-2-i][i+2];
                    }
                }else{
                    box[n-1-i][i+1]=0;
                }
            }
        }
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                if(box[i][j])cout <<"#";
                else cout << " ";
            }
            cout << endl;
        }
        if(k!=d-1)cout << endl;
    }
}



Measured memory_bytes: 3224
#include<iostream>
using namespace std;
#define R(i,n) for(int i=0;i<n;i++)
int n,a=1e9,c[2][20],p[1<<18][51];main(){cin>>n;int s=1<<n;R(i,n*2)cin>>c[i/n][i%n];fill(p[1],p[s],1e9);R(B,s){int o=0,d[n];R(i,n)if(~B&1<<i)d[i]=o++;R(i,n){int k=c[abs(i-n+o)%2][i];R(j,k+1)p[B|1<<i][k]=min(p[B|1<<i][k],p[B][j]+d[i]);}}R(i,51)a=min(a,p[s-1][i]);cout<<(a>1e8?-1:a);}

Measured memory_bytes: 52608
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] p = new int[n];
        int[] pos = new int[n];
        for(int i=0; i<n; i++){
            p[i] = sc.nextInt() - 1;
            pos[p[i]] = i;
        }
        sc.close();

        int max = 0;

        if(n == 1){
            System.out.println(0);
            return;
        }

        for(int i=0; i<n-1; i++){
            int len = 1;
            int mpos = pos[i];
            for(int j=i+1; j<n; j++){
                if(pos[j] > mpos){
                    mpos = pos[j];
                    len++;
                }else{
                    break;
                }
            }
            if(len > max) max = len;
            i += len - 1;
        }

        System.out.println(n - max);
    }
}

Measured memory_bytes: 84096
#include <iostream>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)




int main() {

	long long N;
	cin >>N;
	
	vector<pair<int, int>> p(N);
	for (int i = 0; i < N; i++) {
		long long a, b;
		cin >> a>>b;
		p.at(i) = make_pair(b, a);
	}
	sort(p.begin(), p.end());
	long long zan = 0;
	int han = 0;

	rep(i, N) {
		long long b, a;
		tie(b, a) = p.at(i);
		zan += a;
		if (b < zan) {
			cout << "No" << endl;
			han = 1;
			break;
		}
		
	}
	if (han == 0){
		cout << "Yes" << endl;
	}
	
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int dp[100001];
int minCost(vector<int>&v,int n){
    if(n==0) return 0;
    if(n==1) return abs(v[1]-v[0]);
    if(dp[n]!=-1) return dp[n];
    int oneJump=abs(v[n]-v[n-1])+minCost(v,n-1);
    int twoJump=abs(v[n]-v[n-2])+minCost(v,n-2);
    return dp[n]=min(oneJump,twoJump);
}
int main()
{  ios::sync_with_stdio(false);
   cin.tie(0);  
   
   int n;
   cin>>n;
   vector<int>v(n);
   for(int i=0;i<n;i++) cin>>v[i];
   memset(dp,-1,sizeof(dp));
   cout<<minCost(v,n-1);
     return 0;
}


Measured memory_bytes: 11860
#include<stdio.h>
int main(void){
    int a,b,c,p;
    while(1){
        scanf("%d %d %d", &a, &b, &c);
        if (a==-1&&b==-1&&c==-1){break;}
        p=a+b;
        if(a==-1&&b>=0){printf("F\n");}
        else if(b==-1&&a>=0){printf("F\n");}
        else if(p>=80){printf("A\n");}
        else if(p>=65&&p<85){printf("B\n");}
        else if(p>=50&&p<65){printf("C\n");}
        else if(p>=30&&p<50&&c<50){printf("D\n");}
        else if(p>=30&&p<50&&c>=50){printf("C\n");}
        else if(p<30){printf("F\n");}
    }
    return 0;
}

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

int main(void){
	int n;
	while(cin >> n,n){
		int a[1010];
		for(int i = 0; i < n;++i) cin >> a[i];
		int ans = abs(a[0]-a[1]);

		for(int i = 0; i < n;++i)
			for(int j = i +1 ; j < n; ++ j)
				ans = min(ans,abs(a[i]-a[j]));
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3064
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.io.BufferedReader;
import java.io.FileReader;
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;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        QFlowers solver = new QFlowers();
        solver.solve(1, in, out);
        out.close();
    }

    static class QFlowers {
        public void solve(int testNumber, Scanner sc, PrintWriter pw) {
            int n = sc.nextInt();
            int[] height = new int[n];
            int[] beauty = new int[n];
            for (int i = 0; i < n; i++)
                height[i] = sc.nextInt();
            for (int i = 0; i < n; i++)
                beauty[i] = sc.nextInt();
            FenwickTree ft = new FenwickTree(n);
            long max = 0;
            for (int i = 0; i < n; i++) {
                long query = beauty[i] + ft.rsq(height[i] - 1);
                max = Math.max(max, query);
                ft.point_update(height[i], query);
            }
            pw.println(max);
        }

        public class FenwickTree {
            int n;
            long[] ft;

            FenwickTree(int size) {
                n = size;
                ft = new long[n + 1];
            }

            long rsq(int b) {
                long max = 0;
                while (b > 0) {
                    max = Math.max(ft[b], max);
                    b -= b & -b;
                }        //min?
                return max;
            }

            void point_update(int k, long val) {
                while (k <= n) {
                    ft[k] = Math.max(val, ft[k]);
                    k += k & -k;
                }        //min?
            }

        }

    }

    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(FileReader r) {
            br = new BufferedReader(r);
        }

        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }

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

    }
}



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

using namespace std;
int m, A, B, d[200][200];
int used[200][200];
vector<pair<int, int> > ed[2000];
void add(int x, int y, int z) {
    ed[x].push_back(make_pair(y, z));
    m++;
}
int main() {
    ios_base::sync_with_stdio(0);
    cin >> A >> B;
    for (int i = 1; i <= A; i++)
    for (int j = 1; j <= B; j++) cin >> d[i][j];
    for (int i = 1; i < 99; i++) add(i, i + 1, -1);
    for (int i = 101; i < 200; i++) add(i + 1, i, -2);
    int cnt = 200;
    for (int c1 = 0; c1 < 100; c1++)
    for (int c2 = 0; c2 < 100; c2++)
    for (int c3 = 0; c3 <= 100; c3++) {
        if (c1 + c2 + c3 > 100) break;
        bool bd = 0; vector<pair<int, int> > lst;
        for (int i = 1; i <= A; i++) {
            for (int j = 1; j <= B; j++)
            if (i * c1 + j * c2 + c3 < d[i][j]) {
                bd = 1;
                break;
            }
            else
            if (i * c1 + j * c2 + c3 == d[i][j] && used[i][j] == 0) lst.push_back(make_pair(i, j));
            if (bd == 1) break;
        }
        if (bd) continue;
        if (lst.size() != 0) {
            cnt++;
            add(c1 + 1, cnt, c3);
            add(cnt, c2 + 101, 0);
            for (int i = 0; i < lst.size(); i++) used[lst[i].first][lst[i].second] = 1;
        }
    }
    for (int i = 1; i <= A; i++)
    for (int j = 1; j <= B; j++)
    if (used[i][j] == 0) {
        cout << "Impossible\n";
        return 0;
    }
    cout << "Possible\n";
    cout << cnt << " " << m << "\n";
    for (int i = 1; i <= cnt; i++) {
        for (int j = 0; j < ed[i].size(); j++) {
            int to = ed[i][j].first;
            int cs = ed[i][j].second;
            cout << i << " " << to << " ";
            if (cs >= 0) cout << cs << "\n";
            else
            if (cs == -1) cout << "X\n";
            else cout << "Y\n";
        }
    }
    cout << "1 101\n";
    return 0;
}


Measured memory_bytes: 384
#include "iostream"
#include "algorithm"
#include "string"
#include "vector"
#include "cmath"
#include "queue"
#include "functional"
#include "map"
#include "set"
#include "stack"
 
#define lp(n) for (int i = 0; i < n; i++)
#define LP(n,i) for (int i = 0; i < n; i++)
#define mod 1000000007
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define nyan "(=^･ω･^=)"
#define mkp make_pair
typedef long long ll;
using namespace std;
 
int w, h, n, a[100000], mem, m, x, y;
vector<pair<int, int> >xy;
 
int main() {
    cin >> w >> h >> n;
    lp(n) {
        cin >> x >> y;
        xy.push_back(mkp(x, y));
    }
    sort(xy.begin(), xy.end());
    m = n - 1;
    mem = 0;
    for (int i = w-1; i != -1; i--) {
        a[i] = mem;
        while (m!=-1&&xy[m].first == i) {
            mem = max(mem, xy[m].second);
            m--;
        }
    }
    mem = intmax;
    lp(w)
        mem = min(mem, a[i] + i);
    cout << mem << endl;
    return 0;
}


Measured memory_bytes: 4060
def doit(s)
  return 0 if s < 3
  lc = Array.new(s - 3 + 1, 0)
  ln = Array.new(s - 3 + 1, 0)
  lc[0] = 1
  
  d = 10 ** 9 + 7
  
  a = 1
  b = s - 3 * a
  sum = 0
  while b >= 0 do
    stmp = 0
    (0..b).each do |i|
      stmp = (stmp + lc[i]) % d
      ln[i] = stmp
    end
    sum = (sum + ln[b]) % d
    a += 1
    b = s - 3 * a
    lc, ln = ln, lc
  end
  
  sum
end

s = gets.to_i
puts doit(s)


Measured memory_bytes: 14232
import sys, itertools
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = 10**20
def I(): return int(input())
def F(): return float(input())
def S(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()

def resolve():
    N, K = LI()
    a = LI()
    ans = INF
    for i in range(2**N):
        cost_sum = 0
        cnt = 0
        prev_height = 0
        for j in range(N):
            if (i>>j)&1:
                if a[j]<=prev_height:
                    cost_sum += (prev_height+1)-a[j]
                    prev_height += 1
                else:
                    prev_height = a[j]
                cnt += 1
            prev_height = max(a[j], prev_height)
        if cnt>=K:
            ans = min(cost_sum, ans)

    print(ans)

if __name__ == '__main__':
    resolve()

Measured memory_bytes: 3064
w,h,n=map(int,input().split())
xya=[[int(i) for i in input().split()] for j in range(n)]

minx=w
maxx=0
miny=h
maxy=0
for x,y,a in xya:
    if a==1:
        maxx=max(maxx,x)
    elif a==2:
        minx=min(minx,x)
    elif a==3:
        maxy=max(maxy,y)
    elif a==4:
        miny=min(miny,y)

x=max(0,minx-maxx)
y=max(0,miny-maxy)
print(x*y)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define fi first
#define se second
#define lc (x<<1)
#define rc (x<<1|1)
#define gc getchar()//(p1==p2&&(p2=(p1=buf)+fread(buf,1,size,stdin),p1==p2)?EOF:*p1++)
#define mk make_pair
#define pi pair<int,int>
#define pb push_back
#define IT iterator
#define SZ(a) ((int)a.size())
#define all(a) a.begin(),a.end()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
const int N=2e5+10,size=1<<20,mod=998244353,inf=2e9;

//char buf[size],*p1=buf,*p2=buf;
template<class o> void qr(o &x) {
	char c=gc; x=0; int f=1;
	while(!isdigit(c)){if(c=='-')f=-1; c=gc;}
	while(isdigit(c)) x=x*10+c-'0',c=gc;
	x*=f;
}
template<class o> void qw(o x) {
	if(x/10) qw(x/10);
	putchar(x%10+'0');
}
template<class o> void pr1(o x) {
	if(x<0)x=-x,putchar('-');
	qw(x); putchar(' ');
}
template<class o> void pr2(o x) {
	if(x<0)x=-x,putchar('-');
	qw(x); puts("");
}

//math
ll mult(ll a,ll b,ll p) {
	a=(a%p+p)%p; b=(b%p+p)%p;
	ll c=(ld)a*b/p;
	return a*b-c*p;
}
ll gcd(ll a,ll b) {return !a?b:gcd(b%a,a);}
ll lcm(ll a,ll b) {return a/gcd(a,b)*b;}
ll power(ll a,ll b=mod-2) {
	ll c=1;
	while(b) {
		if(b&1) c=c*a%mod;
		b /= 2; a=a*a%mod;
	}
	return c;
}
ll Power(ll a,ll b=mod-2) {
	ll c=1;
	while(b) {
		if(b&1) c=mult(c,a,mod);
		b /= 2; a=mult(a,a,mod);
	}
	return c;
}

int main() {
	int n; qr(n);
	pr2((1999-n)/200+1);
	return 0;
}




Measured memory_bytes: 3636
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<deque>
#include<iomanip>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
using namespace std;
void io() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); }
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
const double PI=acos(-1.0);
const double eps=1e-6;
const ll mod=1e9+7;
const int inf=0x3f3f3f3f;
const int maxn=2*1e5+10;
const int maxm=100+10;
#define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int h[maxn];
int fabs(int x){
	return x>0?x:-x;
}
int dp[maxn];
int main()
{
	io();
	int N;cin>>N;
	for(int i=1;i<=N;++i){
		cin>>h[i];
	} 
	dp[1]=0;
	dp[2]=abs(h[2]-h[1]);
	for(int i=3;i<=N;i++){
		dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
	}
	cout<<dp[N]<<endl;
	// cout<<ans<<endl;
}



Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
using namespace std;
typedef long long ll;

int main(){
    ll A,B,N, x, res;
    scanf("%lld %lld %lld", &A, &B, &N);
    x=B-1;
    if(x>N)   x=N;
    
    res = (A*x/B)-A*((x/B));
    printf("%lld",res);
    return 0;
}


Measured memory_bytes: 3720
#include<bits/stdc++.h>
using namespace std;
#define ll long long
map<ll,ll>R,L;

int main()
{
    int n,a,i;
    ll ans;
    cin>>n;
    for(i=1; i<=n; i++)
    {
        scanf("%d",&a);
        R[a+i]++;
        L[i-a]++;
    }
    ans=0;
    for(auto it : R)
    {
        ans+=(it.second*L[it.first]);
    }
    cout<<ans<<endl;
    return 0;
}


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

#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)
#define rer(i, a, b) for (int i = (int)a; i <= (int)b; ++i)
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define all(v) v.begin(), v.end()
#define mset(a, n) memset(a, n, sizeof(a))

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vector<int> > vvi;
typedef vector<pair<int, int> > vpii;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;

const int inf = 1000000000;
const int mod = 1000000007;
const double EPS = 1e-9;
const int dx[] = { -1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};

int n;
string s;
string table[10] = {
	"", ".,!? ", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz",
};

int main() {
	// cin.tie(0); // tie
	// ios::sync_with_stdio(false); // sync
	cin >> n;
	rep(i, n) {
		cin >> s;
		int num = s[0] - '0', cnt = 0;
		REP(j, 1, s.size()) {
			if (s[j] != s[j - 1] || num == 0) {
				if (num != 0) cout << table[num][cnt];
				cnt = 0;
				num = s[j] - '0';
			} else {
				cnt = (cnt + 1) % table[num].size();
			}
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 1212
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int Inf = 1000000010;
constexpr ll INF= 1000000000000000000;
constexpr ll MOD = 1000000007;
const double PI = 3.1415926535897;
typedef pair<int,int> P;

template<typename T>
T Pow(T a,T b) {
    T ret = 1;
    for(int i = 0;i < b;i++) {
        ret *= a;
    }
    return ret;
}

ll mod(ll val) {
    ll res = val % MOD;
    if(res < 0) {
        res += MOD;
    }
    return res;
}

ll RS(ll N, ll P, ll M){
    if(P==0) return 1;
    if(P < 0) {
        return 0;
    }
    if(P%2==0){
        ll t = RS(N, P/2, M);
        return t*t % M;
    }
    return N * RS(N, P-1, M) % M;
}

//[a,b]の区間でn個の乱数を生成
vector<int> Rand(int l,int r,int n) {
    random_device rnd;
    mt19937 mt(rnd());
    uniform_int_distribution<> rand(l,r);
    vector<int> res;
    for(int i = 0;i < n;i++) {
        res.push_back(rand(mt));
    }
    return res;
}

int main() {
    int D;
    cin >> D;
    vector<int> c(26);
    for(int i = 0;i < 26;i++) {
        cin >> c.at(i);
    }
    vector<vector<int>> s(D,vector<int>(26));
    for(int i = 0;i < D;i++) {
        for(int j = 0;j < 26;j++) {
            cin >> s.at(i).at(j);
        }
    }
    vector<int> ret = Rand(1,26,D);
    for(int i = 0;i < D;i++) {
        cout << ret.at(i) << endl;
    }
}

Measured memory_bytes: 3680
n,w=map(int,input().split())
dp=[[0 for _ in range(w+1)] for _ in range(n+1)]
for i in range(1,n+1):
    vi,wi=map(int,input().split())
    for j in range(1,w+1):
        if(j<wi):
            dp[i][j]=dp[i-1][j]
        else:
            dp[i][j]=max(dp[i-1][j-wi]+vi,dp[i-1][j],dp[i][j-wi]+vi)
print(dp[n][w])


Measured memory_bytes: 42452
a,b,c=map(int,input().split())
d,e,f=map(int,input().split())
g,h,i=map(int,input().split())
A1=-1
A2=-1
A3=-1
B1=-1
B2=-2
B3=-1
flag=0
for j in range(a+1):
    A1=j
    B1=a-A1
    B2=b-A1
    B3=c-A1
    if B1<0 or B2<0 or B3 <0:
        continue
    A2=d-B1
    A3=g-B1
    if A2<0 or A3<0:
        continue
    if d-B1==e-B2 and e-B2==f-B3 and g-B1==h-B2 and h-B2 == i-B3:
        flag=1
        break
print('Yes' if flag else 'No')

Measured memory_bytes: 3064
using System;
using System.Linq;//リストの使用
using System.Collections.Generic;
using System.Text;//テキストの高速出力に必要
class Program
{
static string[] input = Console.ReadLine().Split(' ');
static long r = long.Parse(input[0]);
static long c = long.Parse(input[1]);
static int n = int.Parse(input[2]);

	static void Main()
	{
    bool answer = true;
    List<long[]> firstList = new List<long[]>();

    for(long i = 0; i < n; i++)
    {
      long[] nums = Array.ConvertAll(Console.ReadLine().Split(' '),long.Parse);
      if(IsEnd(nums[0],nums[1]) && IsEnd(nums[2],nums[3]))
      {
        long aa = WhatPosition(nums[0],nums[1]);
        long bb = WhatPosition(nums[2],nums[3]);

        firstList.Add(new long[2]{i,aa});
        firstList.Add(new long[2]{i,bb});
      }
    }

    firstList.Sort((a, b) => a[1].CompareTo(b[1]));
    
    var stack = new Stack<long[]>();
    for(int i = 0; i < firstList.Count(); i++)
    {
      if(stack.Count == 0)
      {
        stack.Push(firstList[i]);
      }else if(stack.Peek()[0] == firstList[i][0])
      {
        stack.Pop();
      }else
      {
        stack.Push(firstList[i]);
      }
    }

    if(stack.Count > 0) answer = false;
		Console.WriteLine(answer?"YES":"NO");
	}

  static bool IsEnd(long x, long y)
  {
    if(x==0 || x == r || y == 0 || y == c) return true;
    return false;
  }

  static long WhatPosition(long x, long y)
  {
    if(y == 0) return x;
    if(x == r) return r+y;
    if(y == c) return r+c+(r-x);
    return 2*r+c+(c-y);
  }
  
}

Measured memory_bytes: 31908
#include<iostream>
#include<string>
using namespace std;
typedef long long ll;


int main(){
    ll ans_AC=0, ans_penalty=0;
    ll N, M; cin >> N >> M;
    string s[M];
    ll p[M], AC_num=0, pena[N], problem[N], temp;
    for(int i=0; i<M; i++){
        cin >> p[i] >> s[i];
    }
    for(int i=0; i<N; i++){
        problem[i] = 0;
        pena[i] = 0;
    }
    for(int i=0; i<M; i++){
        if(s[i] == "WA" && problem[p[i]-1] == 0){
            pena[p[i]-1] += 1; 
            //cout << "pena[" << p[i]-1 << "]= " << pena[p[i]-1] << endl;
        }else if(s[i] == "AC" && problem[p[i]-1] == 0){
            problem[p[i]-1] = 1;
            ans_AC += 1;
            ans_penalty += pena[p[i]-1];
        }
    }
    cout << ans_AC << " " << ans_penalty << endl;
}

Measured memory_bytes: 8064
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#include <cstdio>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
 
using namespace std;
 
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P > PP;
 
int tx[] = {0,1,0,-1};
int ty[] = {-1,0,1,0};
 
static const double EPS = 1e-8;

int main(){
  int num_of_queries;
  int limits;
  while(~scanf("%d %d",&num_of_queries,&limits)){
    if(num_of_queries == 0 && limits == 0){
      break;
    }

    deque<int> deq;
    for(int query_i = 0; query_i < num_of_queries; query_i++){
      int query,x;
      scanf("%d %d",&query,&x);
      if(query == 0){
        deq.push_back(x);
      }
      else if(query == 1){
        deq.erase(deq.begin() + x - 1);
      }
      else if(query == 2){
        printf("%d\n",deq[x-1]);
      }
      else if(query == 3){
        for(int i = 0; i < deq.size(); i++){
          if(deq[i] == x){
            deq.erase(deq.begin() + i);
            break;
          }
        }
      }

      while(!deq.empty() && deq.size() > limits){
              deq.pop_front();
      }
    }
    printf("end\n");
  }
}

Measured memory_bytes: 1480
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
#include <set>
#include <queue>

#ifdef _DEBUG
#define DMP(x) cerr << #x << ": " << x << "\n"
#else
#define DMP(x) ((void)0)
#endif

const int MOD = 1000000007, INF = 1111111111; 
using namespace std;
typedef long long lint;

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	string s, t;
	cin >> s >> t;

	vector<vector<int>> dp(s.length() + 1, vector<int>(t.length() + 1));

	
	for (int i = 1; i <= (int)s.length(); i++) {
		for (int j = 1; j <= (int)t.length(); j++) {

			dp[i][j] = max(dp[i][j], dp[i][j - 1]);
			dp[i][j] = max(dp[i][j], dp[i - 1][j]);

			if (s[i - 1] == t[j - 1] && dp[i][j] < dp[i - 1][j - 1] + 1) dp[i][j] = dp[i - 1][j - 1] + 1;
		}
	}
	
	string ans = "";
	int x = (int)s.length(), y = (int)t.length();
	while (x > 0 && y > 0) {

		if (dp[x][y] == dp[x - 1][y]) x--;
		else if (dp[x][y] == dp[x][y - 1]) y--;
		else {
			ans += s[x - 1];
			x--, y--;
		}
	}

	reverse(ans.begin(), ans.end());
	cout << ans << "\n";

	return 0;

}

Measured memory_bytes: 35584
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<30
#define pb push_back
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int main() {
	int n = 5;
	vector<int> v(n);
	rep(i, n) cin >> v[i];

	int sum = 0;
	rep(i, n) {
		if(v[i] < 40) v[i] = 40;
		sum += v[i];
	}

	cout << sum / 5 << endl;

	return 0;
}

Measured memory_bytes: 1192
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a,b,c,count=0;
    a = sc.nextInt();
    b = sc.nextInt();
    c = sc.nextInt();
    for(int i = a;i <= b;i++){
      if(c % i == 0)count++;
    }
    System.out.println(count);
    sc.close();
  }
}



Measured memory_bytes: 26340
#include<bits/stdc++.h>
using namespace std;
#define IL inline
#define rep(i,j,k) for(int i=j;i<=k;++i)
#define repd(i,j,k) for(int i=j;i>=k;--i)
#define pb push_back
#define db double
#define mp make_pair
#define mp3(a,b,c) mp(mp(a,b),c)
#define pii pair<int,int>
#define piii pair<pii,int>
#define fr first
#define se second
#define ll long long
#define ull unsigned long long
#define pbc(x) __builtin_popcount(x)
#define clr(x) memset(x,0,sizeof x)
#define SIZE(x) (int)(x.size())
const int mod=1e9+7;
IL int pls(int x,int y){x+=y;return x>=mod?x-mod:x;}
IL int dec(int x,int y){x-=y;return x<0?x+mod:x;}
IL int mul(int x,int y){return 1ll*x*y%mod;}
IL int mul(int x,int y,int z){return mul(mul(x,y),z);}
IL int mul(int x,int y,int z,int p){return mul(mul(x,y),mul(z,p));}
IL void add(int &x,int y){x+=y;x=(x>=mod)?x-mod:x;}
IL int fpw(int x,int y,int r=1){for(;y;y>>=1,x=mul(x,x))if(y&1)r=mul(r,x);return r;}
IL int inv(int x){return fpw(x,mod-2);}
IL int gi(){int x;int _w=scanf("%d",&x);return x;}
IL void gi(int &x){int _w=scanf("%d",&x);}
IL void write(int x){printf("%d\n",x);}
void chkmax(int &x,int y){x=(x>y)?x:y;}
void chkmin(int &x,int y){x=(x<y)?x:y;}
const int INF=0x3f3f3f3f;
template<typename T>IL void debug(T x){cerr<<x;return;}
/* --------------------------------------------------------------------------------------------------------- */
const int maxn=1e5+10;
int a[maxn],n;
int main(){
	ll ans=0;
	n=gi();
	rep(i,1,n)a[i]=gi();
	rep(i,1,n){
		ans+=a[i]/2,a[i]=(a[i]&1);
		if(i<n&&a[i]&&a[i+1]){
			a[i]--;a[i+1]--;
			ans++;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define M 1000000007
#define pb emplace_back
#define f first
#define s second
#define rep(i, st, ed) for(ll i=st; i<ed; ++i)
#define repn(i, st, ed) for(ll i=st; i<=ed; ++i)
#define repb(i, ed, st) for(ll i=ed; i>=st; --i)
#define all(v) v.begin(),v.end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define PI acosl(-1.0)
#define mp(a, b) make_pair(a, b)
#define eps 1e-9
#define FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}
const int N = 2e5 + 10;
const ll INF = 1LL << 60;
ll iv[N];
ll powM(ll a, ll b){ll res = 1;for(;b;a=a*a%M,b/=2) if(b&1) res=res*a%M;return res;}
ll nckbig(int n, int k){ll ans = 1;for(int i=1; i<=k; ++i){ans = ans*(n-i+1)%M*iv[i]%M;}return ans;}
ll caliv(){iv[1] = 1;for(int i=2; i<N; i++){iv[i] = M-M/i*iv[M%i]%M;}}
ll f1[N], f2[N];
ll calf(){f1[0] = f2[0] = 1;for(int i=2; i <N; ++i){f1[i] = f1[i-1]*i%M;f2[i] = f2[i-i]*iv[i]%M;}}
ll nck(int n, int k){return f1[n]*f2[n-k]%M*f2[k]%M;}
ll npk(int n, int k){return f1[n]*f2[n-k]%M;}
ll Rnck(int big){if(big){caliv();}else{calf();}}

void solve()
{
  ll n, a, b;
  cin>>n>>a>>b;
  Rnck(1);
  cout<<(powM(2LL, n) - nckbig(n, a) + M - nckbig(n, b)-1 + M)%M<<endl;   
}


int main()
{
    FAST
    ll Tests = 1;
    //cin>>Tests;
    while(Tests--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 2944
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <utility>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
#include <cstdio>
#include <map>
#include <list>
#include <stdio.h>
#include <sstream>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
#define all(x) (x).begin(), (x).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
//ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
//ll lcm(ll x, ll y) {return x / gcd(x, y) * y;}
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
const ll mod = 1e9 + 7;
const ll inf = 1LL << 60;
const long double pi = 3.14159265358979323846;

// ****************************************CODE***************************************//

ll n, m;
vector<vector<ll> > g;
ll dp[100100];
vector<ll> num;

int main() {
    cin >> n >> m;
    g.assign(n, vector<ll>());
    num.assign(n, 0);
    for(int i = 0; i < m; i++){
        int a, b;
        cin >> a >> b;
        a--; b--;
        g[a].push_back(b);
        num[b]++;
    }

    queue<ll> que;
    for(int i = 0; i < n; i++){
        if(num[i] == 0) que.push(i);
    }

    while(!que.empty()){
        ll v = que.front(); que.pop();

        for(auto j : g[v]){
            num[j]--;
            if(num[j] == 0){
                que.push(j);
                dp[j] = max(dp[j], dp[v] + 1);
            }
        }
    }

    ll res = 0;
    for(int i = 0; i < n; i++){
        res = max(res, dp[i]);
    }

    cout << res << endl;
}

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

#define F first
#define S second
#define MP make_pair
#define PB push_back

using namespace std;

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

const int NUM = 105;
const int MAXN = 1e5 + 500;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const int LOG = 18;
const double EPS = 1e-9;
const double PI = 3.1415926535;

int dp[NUM][MAXN];
int w[NUM], v[NUM];

int main() {
    int N, W, V = 0;

    cin >> N >> W;
    for(int i = 1; i <= N; i++) {
        cin >> w[i] >> v[i];
        V += v[i];
    }

    memset(dp, INF, sizeof(dp));
    dp[0][0] = 0;
    for(int i = 1; i <= N; i++)
        for(int j = 0; j <= V; j++) {
            dp[i][j] = dp[i - 1][j];
            if(j < v[i])
                continue;
            if(dp[i - 1][j - v[i]] + w[i] <= W)
                dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - v[i]] + w[i]);
        }

    for(int i = V; i >= 0; i--)
        if(dp[N][i] != INF) {
            cout << i << endl;
            break;
        }

    return 0;
}



Measured memory_bytes: 41472
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define endl "\n"
#define mod 1000000007
#define maxN 200015

int n, m, cnt;
vector<int> visited(maxN, 0);
vector<int> adj[maxN];

//vector<int> adj[maxN];

void dfs(int s) {
	visited[s] = 1;
	cnt++;
	for (auto i : adj[s]) {
		if (visited[i] == 0) {
			dfs(i);
		}
	}

}



int main()
{

	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
#ifndef ONLINE_JUDGE
	{
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	}
#endif
	int a, b;
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		cin >> a >> b;
		adj[a].push_back(b);
		adj[b].push_back(a);
	}
	int ans = -1;
	for (int i = 1; i <= n; i++) {
		if (visited[i] == 0) {
			cnt = 0;
			dfs(i);
			ans = max(ans, cnt);
		}
	}
	cout << ans << endl;


	return 0;
}

Measured memory_bytes: 21048
#include <stdio.h>

const int inf = 0;
int leaf[300002];

typedef struct {
	int left, right, max;
} seg_node;

void init_node(seg_node v[], int k, int l, int r)
{
	v[k].left = l;
	v[k].right = r;
	v[k].max = inf;
	if (l < r) {
		init_node(v, k << 1, l, (l + r) / 2);
		init_node(v, (k << 1) ^ 1, (l + r) / 2 + 1, r);
	} else leaf[l] = k;
}

void update_node(seg_node v[], int k, int x)
{
	int i, j = leaf[k];
	v[j].max = x;
	for (i = j >> 1; i > 0; j = i, i >>= 1) v[i].max = (v[j].max > v[j^1].max)? v[j].max: v[j^1].max;
}
 
int get_max(seg_node v[], int k, int l, int r)
{
	int tmp[2];
	if (v[k].right < l || v[k].left > r) return inf;
	else if (v[k].left >= l && v[k].right <= r) return v[k].max;
	else {
		tmp[0] = get_max(v, k << 1, l, r);
		tmp[1] = get_max(v, (k << 1) ^ 1, l, r);
		return (tmp[0] < tmp[1])? tmp[1]: tmp[0];
	}
}

int main()
{
	int i, N, K, A[300001];
	scanf("%d %d", &N, &K);
	for (i = 1; i <= N; i++) {
		scanf("%d", &(A[i]));
		A[i]++;
	}
	
	int dp[300002] = {}, tmp, l, r;
	seg_node v[1200000];
	init_node(v, 1, 1, 300001);
	for (i = 1; i <= N; i++) {
		l = (A[i] > K)? A[i] - K: 1;
		r = (A[i] < 300001 - K)? A[i] + K: 300001;
		tmp = get_max(v, 1, l, r);
		if (dp[A[i]] < tmp + 1) {
			dp[A[i]] = tmp + 1;
			update_node(v, A[i], dp[A[i]]);
		}
	}
	
	int ans = 0;
	for (i = 1; i <= 300001; i++) if (ans < dp[i]) ans = dp[i];
	printf("%d\n", ans);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 17536
if __name__ == '__main__':
    n = int(input())
    dict={}
    for j in range(1,101):
        for k in range(1,101):
            for l in range(1,101):
                calc = j**2+k**2+l**2 +j*k+k*l+l*j
                if calc in dict:
                    dict[calc]+=1
                else:
                    dict[calc]=1
    for i in range(1,n+1):
        if i in dict:
            print(dict[i])
        else:
            print(0)




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

int main(){
    int N;
    cin >> N;
    map<string, int> strings;
    for(int i = 0; i < N; i++){
        string s;
        cin >> s;
        strings[s]++;
    }
    int M;
    cin >> M;
    for(int i = 0; i < M; i++){
        string s;
        cin >> s;
        strings[s]--;
    }
    int ans = 0;
    for(auto i: strings){
        ans = max(ans, i.second);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
n = int(input())
lis = list(map(int,input().split()))
lis.insert(0,0)
lis.append(0)
cou = 0
for i in range(n+1):
    cou += abs(lis[i+1]-lis[i])

for k in range(n):
    if lis[k+2]>lis[k+1] and lis[k+1]>lis[k]:
        print(cou)
    elif lis[k+2]<=lis[k+1] and lis[k+1]<=lis[k]:
        print(cou)
    else:
        print(cou-(abs(lis[k+2]-lis[k+1])+abs(lis[k+1]-lis[k])-abs(lis[k+2]-lis[k])))

Measured memory_bytes: 14048
#!/usr/bin python3
# -*- coding: utf-8 -*-

from bisect import bisect_left, bisect_right

def main():
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    C = list(map(int, input().split()))
    A.sort()
    B.sort()
    C.sort()

    ret = 0
    for b in B:
        ia = bisect_left(A,b)
        ic = bisect_right(C,b)
        ret += ia*(N-ic)
    print(ret)

if __name__ == '__main__':
    main()

Measured memory_bytes: 22720
fun main (args : Array<String>) {
    val (a, b, c) = readLine()!!.split(" ")
    val A : Int = a.toInt()
    val B : Int = b.toInt()
    val C : Int = c.toInt()

    if ( ((A == B) && (A != C)) || ((A == C) && (A != B)) || ((B == C) && (A != B)) ) {
        println("Yes")
    } else {
        println("No")
    }

}

Measured memory_bytes: 35972
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
using namespace std;
#define ALL(x) (x).begin(), (x).end()
#define OUT(x) cout << (x) << endl
typedef long long ll;

int main() {
    int l, r;
    cin >> l >> r;
    int ans = 10000;
    for (int i = l; i <= min(l + 2019, r); i++) {
        for (int j = i + 1; j <= min(l + 2019, r); j++) {
            ans = min(ans, (i % 2019) * (j % 2019) % 2019);
        }
    }
    OUT(ans);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
	long long a;
	scanf("%lld",&a);
	long long r=0;
	r+=a/500*500*2;
	a-=a/500*500;
	r+=a/5*5;
	printf("%lld",r);
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define sc(x) scanf("%d",&x);
int main(){
    int n, m;
    sc(n) sc(m)
    vector<P> vec(m);
    vector<int> order(m);
    vector<vector<P> > vv(n);
    for (int i = 0; i < m; i++){
        sc(vec[i].first) sc(vec[i].second)
    }
    for (int i = 0; i < m; i++){
        vv[vec[i].first-1].push_back(P(vec[i].second, i));
    }
    int cnt;
    for (int i = 0; i < vv.size(); i++){
        cnt = 1;
        sort(vv[i].begin(), vv[i].end());
        for (const auto &x :vv[i]){
            order[x.second] = cnt;
            cnt++;
        }
    }
    string ans1, ans2;
    for (int i = 0; i < m; i++){
        ans1 = to_string(vec[i].first);
        while (ans1.size() != 6) ans1 = '0' + ans1;
        ans2 = to_string(order[i]);
        while (ans2.size() != 6) ans2 = '0' + ans2;
        cout << ans1 << ans2 << endl;
    }
    return 0;
}

Measured memory_bytes: 8192
def silly_sort(target):
    ranked = sorted(target)
    length = len(target)
    rings = [n for n in range(length)]
    all_cost = 0
    minimum = ranked[0]
    base_index = {}
    rank_index = {}
    for i, (t, r) in enumerate(zip(target, ranked)):
        base_index[t] = i
        rank_index[r] = i
    for i in range(length):
        if rings[i] != -1 and target[i] != ranked[i]:
            ring_sum = target[i]
            min_m = target[i]
            num_ring = 1
            next_index = rank_index[target[i]]
            next_num = target[next_index]
            while next_index != i:
                # print(i, next_index, target[i], min_m, ring_sum)
                num_ring += 1
                ring_sum += next_num
                min_m = min(min_m, next_num)
                rings[next_index] = -1
                next_index = rank_index[target[next_index]]
                next_num = target[next_index]
            # print(min((ring_sum + min_m * (num_ring - 2) ), (ring_sum + min_m + minimum * (num_ring + 1) ) ))
            all_cost += min((ring_sum + min_m * (num_ring - 2) ), (ring_sum + min_m + minimum * (num_ring + 1) ) )
        rings[i] = -1
    return all_cost

l = int(input())
t = [int(n) for n in input().split(" ")]
print(silly_sort(t))


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

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

Measured memory_bytes: 3556
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <memory.h>
#include <vector>
#include <queue>
 
using namespace std;
typedef long long LL;
#define pb push_back
const int maxn = 200005;

int diff[maxn],n,p[maxn],a,b,ord[maxn],tot,L,R,x[maxn],y[maxn];
int findp(int u) {return p[u]?p[u]=findp(p[u]):u;}
void merge(int u,int v) {u=findp(u);v=findp(v);u!=v?p[u]=v:0;}
bool comp1(int a,int b) {return x[a]!=x[b]?x[a]<x[b]:y[a]<y[b];}
bool comp2(int a,int b) {return y[a]!=y[b]?y[a]<y[b]:x[a]<x[b];}
int ABS(int x) {return x>0?x:-x;}

int main()
{
	#ifdef Amberframe
		freopen("arc065e.in","r",stdin);
		freopen("arc065e.out","w",stdout);
	#endif
	scanf("%d %d %d",&n,&a,&b);L=n+1;R=n+2;merge(a,b);
	for (int u,v,i=1;i<=n;i++)
		scanf("%d %d",&u,&v),x[i]=u+v,y[i]=u-v,ord[i]=i;
		
	int d=max(ABS(x[a]-x[b]),ABS(y[a]-y[b]));
	sort(ord+1,ord+n+1,comp1);x[0]=y[0]=-(1<<30);
	for (int l=0,r=0,i=1;i<=n;i++)
	{
		x[L]=x[ord[i]]-d,y[L]=y[ord[i]]-d;
		x[R]=x[ord[i]]-d,y[R]=y[ord[i]]+d+1;
		while (l<=n&&comp1(ord[l],L)) ++l;
		while (r<=n&&comp1(ord[r],R)) ++r;
		if (l<r) merge(ord[l],ord[i]),diff[l]++,diff[r-1]--;
	}
	for (int i=1;i<=n;i++) diff[i]+=diff[i-1];
	for (int i=1;i<n;i++) if (diff[i]) merge(ord[i],ord[i+1]);
	
	memset(diff,0,sizeof diff);
	sort(ord+1,ord+n+1,comp2);
	
	for (int l=0,r=0,i=1;i<=n;i++)
	{
		x[L]=x[ord[i]]-d,y[L]=y[ord[i]]-d;
		x[R]=x[ord[i]]+d+1,y[R]=y[ord[i]]-d;
		while (l<=n&&comp2(ord[l],L)) ++l;
		while (r<=n&&comp2(ord[r],R)) ++r;
		if (l<r) merge(ord[l],ord[i]),diff[l]++,diff[r-1]--;
	}
	for (int i=1;i<=n;i++) diff[i]+=diff[i-1];
	for (int i=1;i<n;i++) if (diff[i]) merge(ord[i],ord[i+1]);
	
	tot=0;LL ans=0;
	for (int i=1;i<=n;i++) if (findp(i)==findp(a)) ord[++tot]=i;
	
	sort(ord+1,ord+tot+1,comp1);
	for (int l=0,r=0,i=1;i<=tot;i++)
	{
		x[L]=x[ord[i]]-d,y[L]=y[ord[i]]-d;
		x[R]=x[ord[i]]-d,y[R]=y[ord[i]]+d+1;
		while (l<=tot&&comp1(ord[l],L)) ++l;
		while (r<=tot&&comp1(ord[r],R)) ++r;
		if (l<r) ans+=r-l;
	}
	
	sort(ord+1,ord+tot+1,comp2);
	for (int l=0,r=0,i=1;i<=tot;i++)
	{
		x[L]=x[ord[i]]-d+1,y[L]=y[ord[i]]-d;
		x[R]=x[ord[i]]+d,y[R]=y[ord[i]]-d;
		while (l<=tot&&comp2(ord[l],L)) ++l;
		while (r<=tot&&comp2(ord[r],R)) ++r;
		if (l<r) ans+=r-l;
	}
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 3712
import numpy as np

nyuryoku=input()

s=[int(i) for i in nyuryoku]

s_array=np.array(s)

if np.sum(s_array)==7:
    Ans=['+'+str(i) for i in s]
    Ans[0]=str(s[0])
    print(''.join(Ans)+'=7')
    
else:
    for i in range(3):
        if np.sum(s_array)-2*s_array[i+1]==7:
            Ans=['+'+str(i) for i in s]
            Ans[0]=str(s[0])
            Ans[i+1]='-'+str(s[i+1])
            print(''.join(Ans)+'=7')
            break
            
        elif np.sum(s_array)-2*s_array[1]-2*s_array[2]==7:
            Ans=['+'+str(i) for i in s]
            Ans[0]=str(s[0])
            Ans[1]='-'+str(s[1])
            Ans[2]='-'+str(s[2])
            print(''.join(Ans)+'=7')
            break
            
        elif np.sum(s_array)-2*s_array[2]-2*s_array[3]==7:
            Ans=['+'+str(i) for i in s]
            Ans[0]=str(s[0])
            Ans[2]='-'+str(s[2])
            Ans[3]='-'+str(s[3])
            print(''.join(Ans)+'=7')
            break
        
        elif np.sum(s_array)-2*s_array[1]-2*s_array[3]==7:
            Ans=['+'+str(i) for i in s]
            Ans[0]=str(s[0])
            Ans[1]='-'+str(s[1])
            Ans[3]='-'+str(s[3])
            print(''.join(Ans)+'=7')
            break
            
        elif np.sum(s_array)-2*s_array[1]-2*s_array[2]-2*s_array[3]==7:
            Ans=['+'+str(i) for i in s]
            Ans[0]=str(s[0])
            Ans[1]='-'+str(s[1])
            Ans[2]='-'+str(s[2])
            Ans[3]='-'+str(s[3])
            print(''.join(Ans)+'=7')
            break

Measured memory_bytes: 13068
#include<bits/stdc++.h>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

const ll mod = 1e9+7;

using namespace std;
int main(){
    ll N, K;
    ll a[101];
    ll dp[101][100005];
    ll sum[101][100005];
    cin >> N >> K;
    rep(i, N){
        cin >> a[i+1];
    }

    rep(i, N+1){
        sum[i][0] = 10;
    }


    REP(i, 1, N+1){
        rep(j, K+1){
            if ( i == 1){
                if (j < K - a[1]) {
                    dp[1][j] = 0;
                    sum[1][j] = 0;
                } else {
                    dp[1][j] = 1;
                    sum[1][j] = (j - (K - a[1]) + 1) % mod;
                }
                if (dp[i][j] < 0) dp[i][j] += mod;
            } else {
                if (j + a[i] <= K){
                    dp[i][j] = (sum[i-1][j+a[i]] - sum[i-1][j-1]) % mod;
                } else {
                    dp[i][j] = (sum[i-1][K] - sum[i-1][j-1]) % mod;
                }
                if (dp[i][j] < 0) dp[i][j] += mod;
                sum[i][j] = (sum[i][j - 1] + dp[i][j]) % mod;

            }
//            cout << dp[i][j] << " " << i << " " << j << endl;
        }
    }

    cout << dp[N][0] << endl;


}

Measured memory_bytes: 157952
#include <stdio.h>          // printf(), scanf()
#include <stdbool.h>

int
main(int argc, char** argv)
{
	int n;
	int i;

	scanf("%d", &n);
	while (n--)
	{
		int a;
		int b = 0;
		int c = 0;
		bool f = true;
		for (i = 0; i < 10; ++i)
		{
			scanf("%d", &a);
			if (!f)
				continue;

			int u = a - b;
			int v = a - c;
			if (u <= 0 && v <= 0)
				f = false;

			else if ((u > 0 && u <= v) || v < 0)
				b = a;

			else if ((v > 0 && u > v) || u < 0)
				c = a;
		}

		if (f)
			printf("YES\n");
		else
			printf("NO\n");
	}

	return 0;
}

Measured memory_bytes: 580
from operator import itemgetter
import sys
sys.setrecursionlimit(10**7)

N = int(input())


A = []
for i in range(N - 1):
    A.append([int(i)-1 for i in input().split()])

B = []
for row in A:
    B.append(sorted(row))
B.sort(key = itemgetter(0))

link_list = [[] for i in range(N)]
for row in B:
    link_list[row[0]].append(row[1])
    link_list[row[1]].append(row[0])
edge_color = dict()
marker = [0] * N


def DFS_color(node, pre_color):
    target_list = link_list[node]
    color = 1
    for ko_node in target_list:
        if marker[ko_node] == 0:
            if pre_color == color:
                color += 1
            edge_color[node, ko_node] = color
            edge_color[ko_node, node] = color 
            marker[ko_node] = 1
            DFS_color(ko_node, color)
            color += 1
        else:
            pass

marker[0] = 1
DFS_color(0, 0)

print(max(edge_color.values()))
for node1, node2 in A:
    print(edge_color[node1, node2])


Measured memory_bytes: 93688
#include <bits/stdc++.h>
#define SZ(x) ((int)(x).size())
typedef long long ll;
using namespace std;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cout.setf(ios::fixed); cout.precision(20);
    string s; cin >> s;
    int res1 = 0, res2 = 0;
    int n = SZ(s);
    for (int i = 0; i < n; i++) {
        if (i % 2) {
            res1 += (s[i] == '0');
            res2 += (s[i] == '1');
        } else {
            res1 += (s[i] == '1');
            res2 += (s[i] == '0');
        }
    }
    cout << min(res1, res2) << "\n";
}


Measured memory_bytes: 512
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#define   mod  998244353
#define   int  long long 
#define   ld   long double
#define   pb   push_back
#define   vi  vector<int> 
#define   dbg(x)  cerr << #x << " = " << x << '\n'
#define   sz(x)  (int)x.size()
#define   all(a) (a.begin(),a.end())
#define   ff   first
#define   ss   second
#define   pii  pair<int,int> 
#define   lcm(a,b) (a*b)/__gcd(a,b) 
using namespace std;

inline void solve(){
    int n,m,x; cin>>n>>m>>x; 
    int a[n][m+1],ans=1000000000;
    for (int i=0;i<n;i++)
        for (int &j: a[i]) cin>>j;
    for (int i=0;i<(1<<n);i++){
        vi h(m+1,0); int cnt=0;
        for (int j=0;j<n;j++){
            if ((i>>j)&1){
                for (int k=0;k<=m;k++){
                    if (k==0) cnt += a[j][0];
                    else h[k] += a[j][k];
                }
            }
        }
        if (cnt<ans){
            bool flag=true;
            for (int j=1;j<=m;j++){
                if (h[j]<x) flag=false;
            }
            if (flag) ans=cnt;
        }
    }
    cout << ((ans==1000000000)?"-1":to_string(ans)) << endl;
}

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


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

int main(){
    int n, m; cin >> n >> m;
    vector<vector<ll> > lis(m, vector<ll>(3, 0));
    for(int i = 0; i < m; i++){
        cin >> lis[i][0] >> lis[i][1];
        lis[i][2] = i;
    }
    sort(lis.begin(), lis.end(), [](auto &x, auto &y){return x[1] < y[1];});
    map<ll, ll> mp;
    for(int i = 0; i < m; i++){
        int k = ++mp[lis[i][0]];
        lis[i][1] = k;
    }
    sort(lis.begin(), lis.end(), [](auto &x, auto &y){return x[2] < y[2];});
    for(int i = 0; i < m; i++){
        cout << setfill('0') << right << setw(6) << lis[i][0];
        cout << setfill('0') << right << setw(6) << lis[i][1] << endl;
    }
}

Measured memory_bytes: 13184