akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T>& V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> >& Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T>& mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }
template<typename T>vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type fill_v(T &t,const V &v){t=v;}
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type fill_v(T &t,const V &v){for(auto &e:t) fill_v(e,v);}
/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

template<class Type>
Type solve(Type res = Type()){
    ll r; cin >> r;
    res = 3*r*r;
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    // solve(0);
    cout << fixed << setprecision(15) << solve<ll>() << endl;
    return 0;
}


Measured memory_bytes: 256
import math
s = int(input())
x1 = 10**9; x2 = 1
y2 = math.ceil(s / 10**9)
if s % 10**9 == 0:
    y1 = 0
else:
    y1 = 10**9 - (s % 10**9)
print(0, 0, x1, y1, x2, y2)

Measured memory_bytes: 3060
#pragma GCC optimize("Ofast")
#include <iostream> // cout, endl, cin
#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
#include <iomanip> // setprecision
#include <complex> // complex
#include <math.h> 
#include <functional>
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const int dx[8] = {1, 0, -1, 0,1,1,-1,-1};
const int dy[8] = {0, 1, 0, -1,1,-1,1,-1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// --------------------------------------------------------------------------

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int H,W;
  cin >> H >> W;
  // first 移動後 second スタート地点
  map<int,int> mp;
  for(int i=0; i<W; i++) mp[i] = i;
  multiset<int> ms;
  for(int i=0; i<W; i++) ms.emplace(0);
  for(int i=0; i<H; i++){
    int l,r;
    cin >> l >> r;
    l--;r--;
    auto itr = mp.lower_bound(l);
    int mx = -1;
    while(itr != mp.end() && itr->first <= r+1){
      chmax(mx,itr->second);
      ms.erase(ms.find(itr->first - itr->second));
      mp.erase(itr++);
    }
    if(mx != -1 && r+1 < W){
      ms.emplace(r+1 - mx);
      mp[r+1] = mx;
    }
    if(ms.size()){
      cout << *ms.begin() + (i+1) << "\n";
    }else{
      cout << -1 << "\n";
    }
  }
  return 0;
}


Measured memory_bytes: 22348
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for (int i = s; i < (int)(n); i++)
#define out(x) cout << x << endl
#define INF 1000000;
#include <map>
#include <math.h>
 
using ll = long long;
using namespace std;

ll n, k;
const ll mod = 1000000007;



int main(){
    int a, b;
    cin >> a >> b;
    out((a-1)*(b-1));
    }

Measured memory_bytes: 256
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())


from collections import defaultdict

n = ni()
a = list(li())

dic = defaultdict(int)

for ai in a:
    dic[ai] += 1

ans = 0
evn = 0

for _, cnt in dic.items():
    if cnt % 2:
        ans += 1

    else:
        evn += 1

        if evn == 2:
            ans += 2
            evn = 0

print(ans)

Measured memory_bytes: 18592
#include <bits/stdc++.h>
    using namespace std;
     
    /* REPmacro */
    #define REP(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
    #define REPR(i,n) for(int i=((int)(n)-1);i>=0;--i)
    #define FOR(i,m,n) for(int i=(int)(m);i<(int)(n);++i)
     
    /*alias*/
    #define ALL(x) (x).begin(),(x).end()
    #define SZ(x) ((int)(x).size())
    #define F first
    #define S second
    #define PB push_back
    #define EB emplace_back
    #define MP make_pair 
     
    #define y0 y3487465
    #define y1 y8687969
    #define j0 j1347829
    #define j1 j234892
    #define next asdnext
    #define prev asdprev
    #define itn int
     
    /*using*/
    using ll = long long;
    using ull = unsigned long long;
    using unsi = unsigned;
    using vi = vector<int>;
    using vvi = vector<vi>;
    using vvvi = vector<vvi>;
    using pii = pair<int, int>;
    using db = double;
    using plex = complex<double>;
    using vs = vector<string>;
     
    /*template*/
    template<class T>inline bool amax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
    template<class T>inline bool amin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
     
    /*struct*/
    struct aaa{
        aaa(){
            cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);
        };
    }aaaaaaa;
     
    /* const */
    const int INF = 1001001001;
    const ll LINF = 1001001001001001001ll;
    const int MOD = 1e9 + 7; //10^9
    const db EPS = 1e-9;
    const int dx[] = { 1, 1, 0, -1, -1, -1, 0, 1 }, dy[] = { 0, 1, 1, 1, 0, -1, -1, -1 };  //Counterclockwise from the 9o'clock direction
    //Take the x-axis downward and the y-axis right
     
    //#define int ll
    //#define int long long
     
    //water,sugar,disslove,capacity

    bool wat[3005], sug[3005];
     
    signed main()
    {
    int a, b, c, d, e, f, anss, ansb;
    cin >> a >> b >> c >> d >> e >> f;
    wat[0] = true;
    for (int i = 0; i <= f; i++)
    {
        if (wat[i])
        {
            if (i + 100 * a <= f)
                wat[i + 100 * a] = true;
            if (i + 100 * b <= f)
                wat[i + 100 * b] = true;
        }
    }
 
    sug[0] = true;
    for (int i = 0; i <= f; i++)
    {
        if (sug[i])
        {
            if (i + c <= f)
                sug[i + c] = true;
            if (i + d <= f)
                sug[i + d] = true;
        }
    }
 
    double maxs = -1;
    for (int A = 100; A <= f; A += 100)
    {
        for (int B = 0; B <= f - A; B++)
        {
            if (wat[A] && sug[B] && B <= A / 100 * e)
            {
                if (maxs < 1.0 * B / (A + B))
                {
                    maxs = 1.0 * B / (A + B);
                    anss = A + B;
                    ansb = B;
                }
            }
        }
    }
    cout << anss << ' ' << ansb;
      return 0;
    }

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


int main() {
    Int N;
    cin >> N;
    vector<bool> used(30010,false);
    Int sum = 0;
    vector<Int> ans(N,0);

    if (N <= 5) {
        ans[0] = 2;
        ans[1] = 3;
        if (N >= 4) {
            ans[2] = 4;
            ans[3] = 9;
        }
    }
    if (N == 3) ans[2] = 25;
    if (N == 5) ans[4] = 6;

    if (N >= 6) {
        rep(i,N) {
            if (i%2==0) {
                Int now = 3 * (i / 2) + 1;
                if (now % 2 == 1) now++;
                ans[i] = now;
                sum += now;
                used[now] = true;
            }
            if (i%2==1) {
                Int now = 3 * ((i + 1)/2);
                ans[i] = now;
                sum += now;
                used[now] = true;
            }
        }

        if (sum % 6 == 2) {
            Int now;
            for (int i = 30000; i > 0; i -= 6) {
                if (!used[i]) {
                    now = i;
                    break;
                }
            }
            ans[4] = now;
        }

        if (sum % 6 == 5) {
            Int now;
            for (int i = 29998; i > 0; i -= 6) {
                if (!used[i]) {
                    now = i;
                    break;
                }
            }
            ans[5] = now;
        }

        if (sum % 6 == 3) {
            Int now;
            for (int i = 30000; i > 0; i -= 6) {
                if (!used[i]) {
                    now = i;
                    break;
                }
            }
            ans[5] = now;
        }
    }

    rep(i,N-1) cout << ans[i] << " ";
    cout << ans[N-1] << endl;


}

Measured memory_bytes: 512
#include <stdio.h>
#include <string.h>
int main(void)
{
    int i,j,temp,input_int,rank[3] = {0};
    char input[10];
    char* p;
 
    for (i = 0; i < 10; i++) {
        fgets(input, sizeof(input),stdin);
        p = strchr(input,'\n');
        if (p != NULL) *p = '\0';
        sscanf(input,"%d",&input_int);
        for(j = 0; j < 3; j++)
        {
            if (rank[j] < input_int)
            {
                temp = rank[j];
                rank[j] = input_int;
                input_int = temp;
            }
        }
    }
    for (i = 0; i < 3; i++) {
    printf("%d\n",rank[i]);
    }
return 0;
}

Measured memory_bytes: 612
#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <string>
using namespace std;
vector<long long> nums;
int main()
{

    int n, k;
    cin >> n >> k;
    long long ans = 0;
    for(int i = 0; i < n; i++)
    {
        int a;
        cin >> a;
        nums.push_back(a);
    }
    if(k >= n)
        ans = 0;
    if(k < n)
    {

        sort(nums.begin(), nums.end());
        int x = nums.size() - 1;
        while(k != 0)
        {
            nums[x] = 0;
            x--;
            k--;
        }
        for(int i = 0; i < nums.size(); i++)
        {
            ans += nums[i];
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 2420
S = input()
T = input()
if len(S) < len(T):
    print("UNRESTORABLE")
    exit()
for i in range(len(S) - len(T), -1, -1):
    for s, t in zip(S[i:i+len(T)], T):
        if s != "?" and s != t:
            break
    else:
        S = list(S)
        S[i:i+len(T)] = list(T)
        S = "".join(S).replace("?", "a")
        print(S)
        exit()
print("UNRESTORABLE")


Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        new Main().run();
    }

    private void run() {
        Scanner scanner = new Scanner(System.in);
        String S = scanner.next();
        String ans = "Yes";
        for(int i = 0; i < S.length(); i ++) {
            Character c = S.charAt(i);
            int oddeven = (i+1) % 2;
            if((c.equals('R') && oddeven == 0) || (c.equals('L') && oddeven == 1)) {
                ans = "No";
             break;
            }
        }


        System.out.println(ans);
    }
}


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

int main(){
 int n;
  set<string> st;
  cin>>n;
  for(int i=0;i<n;i++){
    string s;
    cin>>s;
  	st.insert(s);
    
  }
  cout<<st.size();
  
  
}

Measured memory_bytes: 19192
n = int(input())
s = list(input())

r = s.count("R")
g = s.count("G")
b = s.count("B")

a = r * g * b

for i in range(n):
    for j in range(i+1, n):
        k = 2 * j - i 
        if k > n-1:
            break
        
        if s[i] != s[j] and s[j] != s[k] and s[k] != s[i]:
            a -= 1

print(a)

Measured memory_bytes: 9220
#include <stdio.h>

int main(void){
	int a;
	while(scanf("%d",&a) != EOF){
		a=a%39;
		printf("3C");
		if(a==0){
			printf("39\n");
		}
		else if(a<10){
			printf("0%d\n",a);
		}
		else{
			printf("%d\n",a);
		}
	}
return 0;
}

Measured memory_bytes: 608
from collections import defaultdict
N,K,L = map(int,input().split())

root_road = list(range(N))
root_rail = list(range(N))
depth_road = [1 for _ in range(N)]
depth_rail = [1 for _ in range(N)]

def find(a,root):
    if root[a] == a:
        return a
    else:
        root[a] = find(root[a],root)
        return root[a]

def unite(a,b,root,depth):
    A = find(a,root)
    B = find(b,root)
    if A == B:
        return
    elif depth[A] > depth[B]:
        root[B] = A
        depth[A] += depth[B]
    else:
        root[A] = B
        depth[B] += depth[A]

for i in range(K):
    p,q = map(int,input().split())
    unite(p-1,q-1,root_road,depth_road)
for i in range(L):
    r,s = map(int,input().split())
    unite(r-1,s-1,root_rail,depth_rail)
d = defaultdict(int)
pairs = []
for i in range(N):
    road = find(i,root_road)
    rail = find(i,root_rail)
    pairs.append((road,rail))
    d[(road,rail)] += 1
for p in pairs:
    print(d[p],end = " ")

Measured memory_bytes: 126792
import java.util.*;
public class Main{
  public static void main(String[]args){
  Scanner sc=new Scanner(System.in);
  int d=sc.nextInt();
  int as=sc.nextInt();
  int ar[]=new int[10000];
  int s=0;
  
  for(int i=0;i<as;i++){
  ar[i]=sc.nextInt();
  
  }
  for(int i=0;i<ar.length;i++){
  s=s+ar[i];
  }
  int f=d-s;
  if(f>=0){

  System.out.println(f);
  }
  else{System.out.println("-1");}
  }
}

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

int main(){
  string num;
  while (true){
    cin >> num;
    if (num == "0"){
      break;
    }
    int sum = 0;
    for (int i = 0; i < num.length(); i++){
      // char to int
      sum += (num[i] - '0');
    }
    cout << sum << endl;
  }
}


Measured memory_bytes: 3212
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

#define FOR(i, n) for (int i = 0; i < n; i++)
#define EACH(i, n) for (auto &i: n)

int main() {
  uint64_t n, k, count = 0;

  cin >> n >> k;
  for (int i = 0; n >= k;) {
    n /= k;
    count++;
  }
  cout << (count + 1) << endl;

  return 0;
}

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

int main() {
  int h, w, k;
  cin >> h >> w >> k;
  int ans = INF;
  vector<string> chocolate(h);
  rep(i, h) cin >> chocolate[i];
  for(int bit = 0; bit< (1 << h-1); bit++){
    int g = 0;
    vector<int> id(h);
    rep(i,h){
      id[i] = g;
      if(bit >> i & 1) g++;
    }
    g++;

    vector<vector<int>> c(h, vector<int>(w, 0));
    rep(i, h) rep(j, w) c[id[i]][j] += (chocolate[i][j] - '0');
    int num = g - 1;
    vector<int> now(g);
    auto add = [&](int j) {
      rep(i, g) now[i] += c[i][j];
      rep(i, g) if (now[i] > k) return false;
      return true;
    };
    rep(j,w) {
      if (!add(j)) {
        num++;
        now = vector<int>(g);
        if (!add(j)) {
          num = INF;
          break;
        }
      }
    }
    ans = min(ans, num);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
# # Make IO faster
# import sys
# input = sys.stdin.readline

# # get single (or) multiple str
# X = input()

# # get single int
# N = int(input())
# # get multiple int (e.g., 2)
# X, Y = map(int, input().split())
# # get multiple int (e.g., 2) for N lines
# XY = [list(map(int, input().split())) for _ in range(N)]

# from IPython import embed; embed(); exit();

# 全部入り
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
import numpy as np
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

print(INT() // 3)

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

int main(void){

    int N = 0;
    int M = 0;
    int count = 0;
    scanf("%d %d", &N, &M);

    long H[N];
    char check[N][4];
    int A = 0;
    int B = 0;
    for (int i = 0; i < N; i++){
        scanf("%ld", &H[i]);
    }
    for (int j = 0; j < M; j++){
        scanf("%d %d", &A, &B);
        if (H[A - 1] < H[B - 1]){
            strcpy(check[A - 1],"bad");
        } else if ((H[A - 1] > H[B - 1])) {
            strcpy(check[B - 1],"bad");
        } else {
            strcpy(check[A - 1],"bad");
            strcpy(check[B - 1],"bad");            
        }
    }
    for (int k = 0; k < N; k++){
        if (strcmp(check[k], "bad") != 0){
            count++;
        }
    }
    
    printf("%d\n", count);

    return 0;
}

Measured memory_bytes: 2904
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <math.h>
#include <vector>
#include <signal.h> 
#include <locale> 
#include <algorithm>

#define fo(i,n) for(long long int i=0;i<n;i++)
#define fo1(i, n) for (long long int i = 1; i <= (long long int)(n); i++)
#define pb push_back
#define fill_vector(n,v) for(long long int i=0;i<n;i++){long long int temp;cin>>temp;v.push_back(temp); }
#define print_vector(n,v) for(long long int i=0;i<n;i++){cout<<v[i]<<"\n"; } 
#define sortv(v) sort(v.begin(), v.end())
#define sortvo(v) sort(v.begin(), v.end(),greater<long long int>())
#define f(i,l,r) for(ll i=l;i<=r;i++)
#define rf(i,r,l) for(ll i=r;i>=l;i--)
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define vi vector< int>
#define vs vector<string>
#define y() cout<<"Yes"<<"\n"
#define n() cout<<"No"<<"\n"
#define logbase(x,y) {log10(y)/log10(x)}

typedef int long long ll;
using namespace std;

int main()
{
	ll t=1;
	//cin>>t;
	while(t--)
	{
		string s;
		cin>>s;
		ll n=s.length(),sum=0;
		
		fo(i,n)
		{
			sum+=(s[i]-48);}
		if(sum==0) {y();return 0;}
		
		if(sum%9==0)
		{y();}
		else
			n();
			
	}
	return 0;
}


Measured memory_bytes: 3696
#include<bits/stdc++.h>
using namespace std;
int n,x,y;
int d[5000];
int main() {
    scanf("%d %d %d",&n,&x,&y);
    for(int i=1;i<=n;i++) {
        for(int j=i+1;j<=n;j++) {
            int t=j-i;
            t=min(t,abs(x-i)+1+abs(y-j));
            d[t]++;
        }
    }
    for(int i=1;i<n;i++) printf("%d\n",d[i]);
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<math.h>
using namespace std;
#define PI 3.1415927
#define mod 1000000007
long long n,ans=1;
int coun[100005],num[100005];
int main()
{
	int n,i,x,flag1,flag2 = 0;
	cin>>n;
	flag1 = n % 2;
	for(i=0;i<n;i++)
	{
		scanf("%d",&num[i]);
		coun[num[i]]++;
		if(num[i]%2==flag1||num[i]>=n||coun[num[i]]>2||(num[i]==0&&coun[num[i]]>1))
		{
			flag2=1;
		}
	}
	if(flag2==1)
	{
		cout<<0;
	}
	else
	{
		for(i=0;i<n/2;i++)
			ans = (ans*2)%mod;
		cout<<ans;
	}
	return 0;
}

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

using namespace std;

const int lim = 4005;

int n, a[lim], b[lim], f[lim][lim], g[2][lim][lim];

template <typename T>
void minimize(T &a, T b) { if (a > b) a = b; }

void prep()
{
    memset(g, 0, sizeof g);
    for (int i = 1; i <= n + n; ++i)
    {
        for (int j = 1; j < i; ++j)
            if (b[i] != b[j]) ++g[b[i]][a[i]][a[j]];
            else if (a[j] > a[i]) ++g[b[i]][a[i]][n + 1];
        for (int j = n; j > 0; --j)
            g[b[i]][a[i]][j] += g[b[i]][a[i]][j + 1];
    }
}

void solve()
{
    memset(f, 0, sizeof f);
    for (int i = 0; i <= n; ++i)
        for (int j = 0; j <= n; ++j)
        {
            if (!(i + j)) continue;
            f[i][j] = INT_MAX;
            if (i) minimize(f[i][j], f[i - 1][j] + g[0][i][j + 1]);
            if (j) minimize(f[i][j], f[i][j - 1] + g[1][j][i + 1]);
        }
}

int main()
{
    ios_base::sync_with_stdio(false);
    scanf("%d\n", &n);
    for (int i = 1; i <= n + n; ++i)
    {
        char c;
        scanf("%c%d\n", &c, &a[i]);
        b[i] = c == 'B' ? 0 : 1;
    }
    prep();
    solve();
    printf("%d\n", f[n][n]);
    return 0;
}

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

int main(){
	int n, i, ans;
  	cin >> n;
  	int l[n+1], r[n+1];
  	for(i=0; i<n; i++){
    	cin >> l[i] >> r[i];
    }
  
  	for(i=0; i<n; i++){
    	ans += r[i] - l[i] + 1;
    }
  	cout << ans << endl;
}

Measured memory_bytes: 256
from collections import defaultdict

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n
    
    def root(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.root(self.parents[x])
            return self.parents[x]
    
    def unite(self, x, y):
        x = self.root(x)
        y = self.root(y)

        if x == y:
            return False
        
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        
        self.parents[x] += self.parents[y]
        self.parents[y] = x

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

    def size(self, x):
        return -self.parents[self.root(x)]
    
    def members(self, x):
        x_root = self.root(x)
        return [i for i in range(self.n) if self.root(i) == x_root]
    
    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]
    
    def group_count(self):
        return len(self.roots())
    
    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return "\n".join("{}: {}".format(r, self.members(r)) for r in self.roots())

def main():
    N, K, L = map(int, input().split())
    uf_road = UnionFind(N)
    uf_railway = UnionFind(N)
    pq = [tuple(map(int, input().split())) for i in range(K)]

    [uf_road.unite(p-1, q-1) for p, q in pq]

    rs = [tuple(map(int, input().split())) for i in range(L)]


    [uf_railway.unite(r-1, s-1) for r, s in rs]
    
    d = defaultdict(int)
    
    for i in range(N):
        d[(uf_road.root(i), uf_railway.root(i))] += 1
    
    for i in range(N):
        print(d[(uf_road.root(i), uf_railway.root(i))])
    
if __name__ == "__main__":
    main()

Measured memory_bytes: 66400
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;
typedef vector<int> vi;


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    
    //freopen("E:\\Codes\\Problem\\C++\\AAA.txt", "r", stdin);
    //freopen("C:\\Users\\Dell\\Desktop\\Problem\\BBB.txt", "w", stdout);
	
	int a,b;
	char k;
	cin>>a>>k>>b;
	
	if(k=='+'){
		cout<<a+b<<endl;
	}
	else{
		cout<<a-b<<endl;
	}

}



Measured memory_bytes: 3604
package main

import (
  "fmt"
)

func main() {
  var h, w int
  fmt.Scan(&h, &w)
  ass := make([][]int, h)
  for i := 0; i < h; i++ {
    ass[i] = make([]int, w)
    for j := 0; j < w; j++ {
      fmt.Scan(&ass[i][j])
    }
  }
  
  var result [][4] int
  for i, as := range ass {
    for j, a := range as {
      if a%2 == 0 || j == w-1 {
        continue
      }
      as[j]--
      as[j+1]++
      result = append(result, [4]int{i+1, j+1, i+1, j+2})
    }
  }
  for i, as := range ass {
    last := as[w-1]
    if last%2 == 0 || i == h-1 {
      continue
    }
    as[w-1]--
    ass[i+1][w-1]++
    result = append(result, [4]int{i+1, w, i+2, w})
  }
  
  fmt.Println(len(result))
  for _, arr := range result {
    fmt.Println(arr[0], arr[1], arr[2], arr[3])
  }
}

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

using namespace std;

long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}

long long lcm(long long a, long long b) {
  return a / gcd(a, b) * b;
}

int main() {
  int N;
  cin >> N;
  long long ans = 1;
  for (int i = 0; i < N; i++) {
    long long t;
    cin >> t;
    ans = lcm(ans, t);
  }
  cout << ans << endl;

  return 0;
}
/* vim:set fdm=marker: */


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
using namespace std;
const int NICO = 200000 + 10;
int a, b;
int main()
{
    cin >> a >> b;
    if(a==1) a=14;
    if(b==1) b=14;
    cout << ((a>b)?"Alice":((a==b)?"Draw":"Bob")) << endl;
}

Measured memory_bytes: 256
/*Read the problem carefully before starting to work on it*/
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;
//#include <ext/pb_ds/assoc_container.hpp> 
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;

typedef long long ll;

#define pb push_back
#define eb emplace_back
#define mp(x,y) make_pair(x,y)
#define mod 1000000007

double PI=3.1415926535897932384626;

//template<typename T> T power(T x,T y,ll m=mod){T ans=1;while(y>0){if(y&1LL) ans=(ans*x)%m;y>>=1LL;x=(x*x)%m;}return ans%m;}

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

//mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
//#define rnd(x, y) uniform_int_distribution<ll>(x, y)(rng)

//struct custom_hash {
//    static uint64_t splitmix64(uint64_t x) {
//        // http://xorshift.di.unimi.it/splitmix64.c
//        x += 0x9e3779b97f4a7c15;
//        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
//        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
//        return x ^ (x >> 31);
//    }
//    size_t operator()(uint64_t x) const {
//        static const uint64_t FIXED_RANDOM = 
//            chrono::steady_clock::now().time_since_epoch().count();
//        return splitmix64(x + FIXED_RANDOM);
//    }
//};

#define fi first
#define se second

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	double n;
	cin>>n;
	double n1=n/3;
	cout<<fixed<<setprecision(15);
	cout<<(n1*n1*n1);
    return 0;
}


//252908XL

Measured memory_bytes: 256
def CountingSort(A, k):
    C = [0] * (k+1)
    n = len(A)
    
    for a in A:
        C[a] = C[a] + 1


    for i in range(1, k+1):
        C[i] = C[i] + C[i-1]

    B = [0] * n
    for j in range(n-1, -1, -1):
        rank = C[ A[j] ]
        B[ rank  - 1] = A[j]
        C[ A[j] ] = C[ A[j] ] - 1

    return B

n = int(input())
A = [int(i) for i in input().split()]

ans = CountingSort(A, 10000)
print(' '.join([str(i) for i in ans]))

    
        



Measured memory_bytes: 241480
#include <bits/stdc++.h>
	#include <cstdio>
	#include <cstring>
	#include <cmath>
	#include <cstring>
	#include <chrono>
	#include <complex>
	#define endl "\n"
	#define ll long long int
	#define vi vector<int>
	#define vll vector<ll>
	#define vvi vector < vi >
	#define pii pair<int,int>
	#define pll pair<long long, long long>
	#define mod 1000000007
	#define inf 1000000000000000001;
	#define all(c) c.begin(),c.end()
	#define mp(x,y) make_pair(x,y)
	#define mem(a,val) memset(a,val,sizeof(a))
	#define eb emplace_back
	#define f first
	#define s second
	
	using namespace std;
	int main()
	{
		std::ios::sync_with_stdio(false);
		string s;
		cin>>s;
		int n=s.size();
		int maxcount=0;
		int i=0;
		while(i<n){
			if(s[i]=='S')
				i++;
			else if(s[i]=='R'){
				int j=i,count=0;
				while(j<n && s[j]=='R'){
					count++;
					j++;
				}
				if(count>maxcount)
					maxcount=count;
				i=j+1;
			}
			//cout<<i<<" ";
		}
		cout<<maxcount;
		return 0;
	}


Measured memory_bytes: 3648
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() { 
  ios::sync_with_stdio(false); cin.tie(0);
  //b
  int n;
  cin >> n;
  for (int i = 0; i <= 100000; i++) {
    int p = floor(1. * i * 1.08);
    if (p == n) {
      cout << i << '\n';
      return 0;
    }
  }
  cout << ":(\n";
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <utility>
#include <tuple>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
using namespace std;
using ll = long long int;
using P = pair<int, int>;

// clang-format off
#ifdef _DEBUG_
#define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; PPPPP(__VA_ARGS__); cerr << endl; } while(false)
template<typename T> void PPPPP(T t) { cerr << t; }
template<typename T, typename... S> void PPPPP(T t, S... s) { cerr << t << ", "; PPPPP(s...); }
#else
#define dump(...) do{ } while(false)
#endif
template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }
template<typename T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template<typename T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }
template<typename T> void print(T a) { cout << a << endl; }
template<typename T, typename... Ts> void print(T a, Ts... ts) { cout << a << ' '; print(ts...); }
template<typename T> istream &operator,(istream &in, T &t) { return in >> t; }
// clang-format on

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string s;
    cin, s;
    REP(i, 0, 3) {
        if (s[i] == '7') {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3636
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;

const int mod = 1000000007;

int main(){
    ll m;
    cin >> m;
    string s;
    cin >> s;
    vector<ll> v(10, 0);
    for(int i = 0; i < 10; i++){
        ll tmp = 0;
        for(int j = 0; j < s.length(); j++){
            tmp *= 10;
            tmp %= mod;
            if(s[j]-'0' != i)   continue;
            tmp++;
        }
        v[i] = tmp;
    }
    vector<int> x({0, 1, 2, 3, 4, 5, 6, 7, 8, 9});
    do{
        if(s.length() > 1 && x[s[0]-'0'] == 0)    continue;
        ll tmp = 0;
        for(int i = 0; i < 10; i++){
            tmp += v[i] * x[i];
            tmp %= mod;
        }
        if(tmp == m){
            for(char c : s) cout << x[c-'0'];
            cout << endl;
            return 0;
        }
    }while(next_permutation(x.begin(), x.end()));
    cout << -1 << endl;
    return 0;
}


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

bool ans1[505][505];
bool ans2[505][505];


signed main()
{
 
ios_base::sync_with_stdio(false);
cin.tie(NULL);  
cout.tie(0);   
 
 
#ifndef ONLINE_JUDGE
    if(fopen("INPUT.txt","r"))
    {
    freopen ("INPUT.txt" , "r" , stdin);
    freopen ("OUTPUT.txt" , "w" , stdout);
    }
#endif    

    int n,m;
    cin>>n>>m;
    string a[n+1];
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        a[i]="$"+a[i];
    }
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            if(a[i][j]=='#')
            {
                ans1[i][j]=1;
                ans2[i][j]=1;
            }
        }
    }
    for(int i=1;i<=n;i++)
    {
        ans1[i][1]=1;
        if(i%2)
        for(int j=2;j<m;j++)
        {
            ans1[i][j]=1;
        }
    }
    for(int i=1;i<=n;i++)
    {
        ans2[i][m]=1;
        if(i%2==0)
        for(int j=2;j<m;j++)
        {
            ans2[i][j]=1;
        }
    }
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            if(ans1[i][j])
                cout<<'#';
            else
                cout<<'.';
        }
        cout<<'\n';
    }
    cout<<'\n';
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            if(ans2[i][j])
                cout<<'#';
            else
                cout<<'.';
        }
        cout<<'\n';
    }
}

Measured memory_bytes: 4448
#define _GLIBCXX_DEBUG //GCC環境での[]デバッグ
#include <bits/stdc++.h> //全ての標準ライブラリ
#define rep(i,n) for(int i = 0;i < n;i++)
#define FOR(i, a, b) for (int i = a; i < b; i++)
using namespace std;
using ll = long long;
int sumVector (const std::vector<int>& v){ //int配列計算
    int sum = 0;
    rep(i, v.size()) sum += v.at(i);
    return sum; 
}
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, cnt = 0;
    cin >> n;
    string s1;
    std::map<string, int> s;
    rep(i,n){
        cin >> s1;
        s[s1] += 1;
        if(s[s1] == 1)cnt += 1;
    }
    cout << cnt;
    
}

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

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

		Arrays.parallelSort(v);
		double ans = v[0];
		for (int i = 1; i < n; i++) {
			ans = (ans + v[i]) / 2;
		}
		System.out.println(ans);
	}
}


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

using namespace std;

#define SZ(x) (int)(x.size())
#define REP(i, n) for(int i=0;i<n;++i)
#define FOR(i, a, b) for(int i=a;i<b;++i)
#define RREP(i, n) for(int i=n-1;i>=0;--i)
#define RFOR(i, a, b) for(int i=b-1;i>=a;--i)

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<int, int>;

const double eps = 1e-8;
const ll MOD = 1000000007;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;

template <typename T1, typename T2>
void chmax(T1 &a, const T2 &b) {
  if(a < b) a = b;
}

template <typename T1, typename T2>
void chmin(T1 &a, const T2 &b) {
  if(a > b) a = b;
}

template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i != (int)(s.size())-1) cout << " ";
  }
  cout << "\n";
}

template<typename T1, typename T2>
ostream& operator<<(ostream &os, const pair<T1, T2> p) {
  os << p.first << ":" << p.second;
  return os;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  int n; cin >> n;
  vll a(n);
  REP(i, n) {
    cin >> a[i];
  }

  vvll dp(n+1, vll(5, LINF));
  dp[0][0] = 0;
  REP(i, n) {
    ll mi = dp[i][0];
    chmin(dp[i+1][0], mi + a[i]);
    chmin(mi, dp[i][1]);
    chmin(dp[i+1][1], mi + (a[i] == 0 ? 2 : a[i] % 2));
    chmin(mi, dp[i][2]);
    chmin(dp[i+1][2], mi + (a[i] % 2 == 0));
    chmin(mi, dp[i][3]);
    chmin(dp[i+1][3], mi + (a[i] == 0 ? 2 : a[i] % 2));
    chmin(mi, dp[i][4]);
    chmin(dp[i+1][4], mi + a[i]);
  }

  ll ans = dp[n][0];
  FOR(i, 1, 5) {
    chmin(ans, dp[n][i]);
  }

  cout << ans << endl;
}


Measured memory_bytes: 16000
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<math.h>
#include<string>
typedef long long ll;
const ll LINF = 1e18;
const int INF = 1e8;
using namespace std;

class UnionFind {
public:
    vector <ll> par; // 各元の親を表す配列
    vector <ll> siz; // 素集合のサイズを表す配列(1 で初期化)

    // Constructor
    UnionFind(ll sz) : par(sz), siz(sz, 1LL) {
        for (ll i = 0; i < sz; ++i) par[i] = i; // 初期では親は自分自身
    }
    void init(ll sz) {
        par.resize(sz);
        siz.assign(sz, 1LL);  // resize だとなぜか初期化されなかった
        for (ll i = 0; i < sz; ++i) par[i] = i; // 初期では親は自分自身
    }

    // Member Function
    // Find
    ll root(ll x) { // 根の検索
        while (par[x] != x) {
            x = par[x] = par[par[x]]; // x の親の親を x の親とする
        }
        return x;
    }

    // Union(Unite, Merge)
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        // merge technique（データ構造をマージするテク．小を大にくっつける）
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool isSame(ll x, ll y) { // 連結判定
        return root(x) == root(y);
    }

    ll size(ll x) { // 素集合のサイズ
        return siz[root(x)];
    }
};

int main(void){
    ll n, m;
    cin >> n >> m;
    UnionFind uf(n);
    vector<pair<int, int> >v;
    vector<ll>ans;

    ll sum = n * (n-1) / 2;
    //ans.push_back(sum);

    for(int i=0; i<m; i++){
        pair<ll, ll>p;
        cin >> p.first >> p.second;
        v.push_back(p);
    }

    for(int i=m-1; i>=0; i--) {
        ans.push_back(sum);
        if(uf.root(v[i].first - 1) != uf.root(v[i].second - 1)){
            sum -= uf.size(v[i].first-1) * uf.size(v[i].second-1);
        }
        uf.merge(v[i].first-1, v[i].second-1);
    }

    for(int i = m-1; i>= 0; i--){
        cout << ans[i] << endl;
    }
}

Measured memory_bytes: 4596
N=int(input())
X=list(map(int,input().split()))

mn=10**18
#for p in range(min(X),max(X)+1):
for p in range(1,101):
    sm=0
    for x in X:
        sm+=(x-p)**2
    #print(p,sm)
    mn=min(sm,mn)
print(mn)

Measured memory_bytes: 3060
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <regex>
using namespace std;
using pii  = pair<int,int>;
using ll=long long;
using ld=long double;
#define pb push_back
#define mp make_pair
#define stpr setprecision
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<(n);++i)
#define Rep(i,a,b) for(ll i=(a);i<(b);++i)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define rRep(i,a,b) for(int i=a;i>=b;i--)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
ll gcd(ll a,ll b){return (b == 0 ? a : gcd(b, a%b));}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll MOD=1000000007;
constexpr ll INF=1000000011;
constexpr ll MOD2=998244353;
constexpr ll LINF = 1001002003004005006ll;
constexpr ld EPS=10e-8;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}
template<class T> ostream& operator<<(ostream& os, vector<T>& v){
    for(auto i=begin(v); i != end(v); ++i){
        if(i !=begin(v)) os << ' ';
        os << *i;
    }
    return os;
}

int main(){
    ll R,G,B,N,C=0;
    cin >> R >> G >> B >> N;
    rep(r,3001){
        rep(g,3001){
            if(r*R+g*G>N){
                break;
            }
            if((N-(r*R+g*G))%B==0){
                C++;
            }
        }
        if(r*R>N){
            break;
        }
    }
    cout << C << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef vector<char> VC;
typedef vector<double> VD;
typedef vector<double> VL;
typedef vector<string> VS;
typedef vector<PLL> VP;
typedef vector<ll> VLL;
const static int INF = 1000000000;
const static int MOD = 1000000007;
#define rep(i,n) for (ll i=0; i<(ll)(n); i++)
#define repd(i,n) for (ll i=n-1; i>=0; i--)
#define rept(i,m,n) for(ll i=m; i<n; i++)
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define PF push_front
#define PB push_back
#define SORT(V) sort((V).begin(), (V).end())
#define RVERSE(V) reverse((V).begin(), (V).end())
#define paired make_pair
#define PRINT(V) for(auto v : (V)) cout << v << " "
//charを整数に
int ctoi(char c) { if (c >= '0' && c <= '9') { return c - '0'; } return 0; }
// 累積和 for (int i = 0; i < N; ++i) s[i+1] = s[i] + a[i]; 
void cum_sum(int N,vector<double> a, vector<double> &s){ for(int i=0; i<N; i++){ s[i+1]=s[i]+a[i];}}
//ユークリッドの控除法
ll gcd(ll a,ll b){
    if(b == 0) return a;
    return gcd(b,a%b);
}
//最小公倍数
ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b; // Be careful not to overflow
}
//空白文字も入力 getline(cin, S);
//桁数指定 setprecision

int main()
{
    ll N;
    cin >> N;
    VLL A(N);
    int ans=0;
    rep(i,N){
        cin >> A[i];
        ans=gcd(ans,A[i]);
    }
    cout << ans << endl;
}


Measured memory_bytes: 1024
// by adiforluls
#pragma GCC optimize ("-O2")
#include<bits/stdc++.h>
#define FAST        ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
using namespace std;
#define ll           long long
#define pb           push_back
#define mp           make_pair
#define pii          pair<int,int>
#define mii          map<int,int>
#define vi           vector<int>
#define vll          vector<ll>
#define all(a)       (a).begin(),(a).end()
#define clz(a)       __builtin_clz(a) // count leading zeroes
#define ctz(a)       __builtin_ctz(a) // count trailing zeroes
#define popc(a)      __builtin_popcount(a) // count set bits (for ints only diff for ll)
#define lul          1000000007
#define rep(i,a,b)	 for(int i=a;i<b;i++)
#define rfor(i,a,b)  for(int i=a; i>=b; i--)
#define SIZE         1000005
#define F            first
#define S            second
#define debug(x)         cerr << #x << " = " << x << endl;
#define mod          998244353
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    std::cerr << name << " = " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " = " << arg1<<" |";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
#define endl        '\n'
const int INF = 0x3f3f3f3f;

const int N = 200005;
vi adj[N];
vi vis(N,0);
vll val(N,0);
void dfs(int node, ll sum=0)
{
    vis[node] = 1;
    val[node]+=sum;
    for(int i:adj[node])
    {
        if(!vis[i]) dfs(i,val[node]);
    }
}
int main()
{
    FAST;
    //	#ifndef ONLINE_JUDGE
//	    freopen("input.txt", "r", stdin);
//	    freopen("output.txt", "w", stdout);
//	#endif
    int t; t=1;
    while(t--)
    {
        int n,q; cin>>n>>q;
        rep(i,1,n)
        {
            int x,y; cin>>x>>y;
            adj[x].pb(y);
            adj[y].pb(x);
        }
        while(q--)
        {
            int x,y; cin>>x>>y;
            val[x]+=y;
        }
        dfs(1);
        rep(i,1,n+1) cout<<val[i]<<" ";
    }
    return 0;
}

Measured memory_bytes: 21888
import math
ans=0
k=int(input())
gcdlist=[[math.inf]*(k+1) for i in range(k+1)]
for i in range(1,k+1):
    for j in range(1,k+1):
        gcdlist[i][j]=math.gcd(i,j)
for a in range(1,k+1):
    for b in range(1,k+1):
        for c in range(1,k+1):
            ans+=gcdlist[gcdlist[a][b]][c]
print(ans)

Measured memory_bytes: 9384
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int length = input.nextInt();
        long max = Integer.MIN_VALUE;
        long min = Integer.MAX_VALUE;
        long sum = 0;
        for(int i = 0; i < length; i++) {
            int temp = input.nextInt();
            if(temp > max)max = temp;
            if(temp< min)min = temp;
            sum += temp;
        }
        System.out.printf("%d %d %d\n", min,max,sum);
    }
}



Measured memory_bytes: 43328
def doit(ab):
    ab = sorted(ab, key=lambda x: (x[1], x[0]))
    s = 0
    for a, b in ab:
        s += a
        if s > b:
            return "No"
    return "Yes"

n = int(input())
ab = [list(map(int, input().split())) for _ in range(n)]
print(doit(ab))


Measured memory_bytes: 91676
n,m = map(int,input().split())
A =[[0 for i in range(m)] for i in range(n)]
B =[0 for i in range(m)]
for i in range(n):
    A[i] = list(map(int,input().split()))
for i in range(m):
    B[i] = int(input())
c = 0
for i in range(n):
    c = 0
    for j in range(m):
        c +=A[i][j]*B[j]
    
    print(c)


Measured memory_bytes: 6024
#include <stdio.h>
int main(void)
{
  char b[4],c[4];
  int i;
  int s=0;
  scanf("%s %s",b,c);
  for(i=0;i<3;++i){
    s = s || (b[i]!=c[2-i]);
  }
  if(s) printf("NO\n");
  else printf("YES\n");
  return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
using namespace std;
#define ll long long
#define RI register int
const int MAXN=15;
const int MAXS=(1<<MAXN);
const int MOD=1000000007;
int n,m,S,tot=1;
int f[MAXS+5]={1},cnt[MAXS+5],to[MAXN+10];
int main()
{
	scanf("%d%d",&n,&m);S=(1<<n)-1;
	for(RI i=0,u,v;i<m;++i)
	{
		scanf("%d%d",&u,&v);
		to[--u]^=(1<<(--v));
		tot=tot+tot;if(tot>=MOD)tot-=MOD;
	}
	for(RI i=S;~i;--i)for(RI t=i;t;t^=t&(-t))++cnt[i];
	for(RI i=0,la,x,y,w;i<S;++i)
	{
		la=S^i;if((i&3)&&(i&3)!=3)continue;
		for(RI j=la;j;j=(j-1)&la)
		{
			x=i^j;if((x&3)&&(x&3)!=3)continue;
			y=S^x;w=f[i];
			for(RI o=0;o<n;++o)
			{
				switch((y>>o)&1){case 1:w=(ll)w*((1<<cnt[j&to[o]])-1)%MOD;break;}
				switch((j>>o)&1){case 1:w=((ll)w<<cnt[y&to[o]])%MOD;break;}
			}
			f[x]=f[x]+w;switch(f[x]>=MOD){case 1:f[x]-=MOD;break;}
		}
	}
	tot=tot-f[S];
	printf("%d",(tot<0)?(tot+MOD):tot);
	return 0;
}

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

int main(){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    if(abs(a-c)<=d) cout<<"Yes"<<endl;
    else if(abs(a-b)<=d and abs(b-c)<=d) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256