akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
long long n, m, a, b, maxx, fix[300000], dp[300000];
vector <long long> g[300000];
long long dfs (long long v)
{
	if (fix[v] == 1)
		return dp[v] + 1;
	fix[v] = 1;
	for (int i = 0; i < g[v].size(); i ++)
	{
		dp[v] = max (dp[v], dfs(g[v][i]));
	}
		
	return dp[v] + 1;
}
int main()
{
	cin >> n >> m;
	for (int i = 1; i <= m; i ++)
	{
		cin >> a >> b;
		g[a].push_back(b);
	}
	
	for (int i = 1; i <= n; i ++)
		if (fix[i] == 0)
			dfs (i);
	for (int i = 1; i <= n; i ++)
		maxx = max (maxx, dp[i]);
	cout << maxx;			
}

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

int main() {
	int a,b,d,r;
	double f;
	cin>>a>>b;
	d = a / b;
	r = a % b;
	f = double(a) / double(b);
	printf("%d %d %.5f\n", d, r, f);
	return 0;
}

Measured memory_bytes: 1192
#include <bits/stdc++.h>
using namespace std;
struct Node{
  int32_t id;
  Node* parent;
  size_t depth;
  size_t height;
  vector<Node*> child;
  Node(): id(0), parent(nullptr), depth(0), height(0), child(){}
  void set_depth(size_t n){
    Node::depth=n;
    for(auto&& c:Node::child) c->set_depth(n+1);
  }
  size_t set_height(){
    if(Node::child.empty()){
      Node::height=0;
    } else{
      for(auto&& c:Node::child) Node::height=max(Node::height, c->set_height());
    }
    return Node::height+1;
  }
  Node* sibling() const {
    if(Node::parent==nullptr) return nullptr;
    for(auto&& c:Node::parent->child){
      if(c->id!=Node::id) return c;
    }
    return nullptr;
  }
  const char* type() const {
    return (Node::parent==nullptr?"root":(Node::child.empty()?"leaf":"internal node"));
  }
};
ostream& operator<<(ostream& os, const Node& x){
  auto sibling=x.sibling();
  os<<"node "<<x.id
    <<": parent = "<<(x.parent==nullptr?-1:x.parent->id)
    <<", sibling = "<<(sibling==nullptr?-1:sibling->id)
    <<", degree = "<<x.child.size()
    <<", depth = "<<x.depth
    <<", height = "<<x.height
    <<", "<<x.type();
  //   <<", [";
  // const char* dlm="";
  // for(const auto& c:x.child) os<<exchange(dlm,", ")<<c->id;
  // os<<"]";
  return os;
}
int32_t main(){
  size_t n; cin>>n;
  vector<Node> tree(n);
  for(size_t i=0; i<n; ++i){
    int32_t id,x,y; cin>>id>>x>>y;
    tree[id].id=id;
    if(x!=-1) tree[id].child.push_back(addressof(tree[x]));
    if(y!=-1) tree[id].child.push_back(addressof(tree[y]));
  }
  for(auto&& t:tree){
    for(const auto& c:t.child) tree[c->id].parent=addressof(t);
  }
  for(auto&& t:tree){
    if(t.parent==nullptr){
      t.set_depth(0);
      t.set_height();
      break;
    }
  }
  for(const auto& t:tree) cout<<t<<'\n';
}


Measured memory_bytes: 3156
#include<cstdio>
#include<cmath>
#include<algorithm>
#define ll long long

using namespace std;

ll v[55];
ll ans=0;//必须开long long，否则在极限情况下会数据超限
void cnt(int a,int b){
	double sum=1;
	if(a>b/2)	
		a=b-a;
	for(int i=b,j=1;i>=b-a+1;i--,j++){
		sum*=i*1.0/j;
	}
	ans+=sum;	
}

bool cmp(ll a,ll b){
	return a>b;//从大到小排序 
}

int main(){
	int n,min_,max_;
	scanf("%d %d %d",&n,&min_,&max_);
	for(int i=1;i<=n;i++){
		scanf("%lld",&v[i]);
	}
	
	sort(v+1,v+n+1,cmp);
	int num=min_;
	double ave=0;
	ave+=v[1];
	int same=1,dsam;
	for(int i=2;i<=min_;i++){
		ave+=v[i];
		if(v[i]==v[i-1]){
			same++;
		}
		else {
			same=1;
		}
	}
	ave/=num;//计算选最少的数时最大平均值
	dsam=min_-same;//已选择的不同的数 

	for(int i=min_+1;v[i]==v[min_]&&i<=n;i++){
		same++;//已选择+未选择的相同的数 
	} 
	if(dsam==0){//如果所有的数都相同 
		for(int k=min_;k<=max_;k++){
			if(k>same)	
				break;
			cnt(k,same);
		}
	}
	else {
		cnt(min_-dsam,same);
	}
	printf("%.6lf\n%lld\n",ave,ans);
	return 0; 
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <climits>
using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string N;
    cin >> N;
    if(N[0] == N[2]){
        cout << "Yes" << endl;
        return 0;
    }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define itrep(i,x) for(auto i=(x).begin(); i!=(x).end();i++)
#define Sort(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define vi vector<int>
#define INF (int)1e9
#define INFL 1e18
#define MOD 1000000007
#define pb push_back
#define MP make_pair
#define PI 3.1415926535
typedef long long int ll;
typedef std::pair<int,int> P;
int D=1;
int dx[4]={0,1,0,-1},dy[4]={-1,0,1,0};

using namespace std;

double se(double x){
    x*=10000.0;
    if((int)x%10>=5){
        x+=10.0;
    }
    x/=10000.0;
    
    return x;
}

int main(){
    double a,b,c,d,e,f;
    while(cin>>a>>b>>c>>d>>e>>f){
        printf("%.3f ",(c*e-f*b)/(a*e-b*d)+0.0);
        printf("%.3f\n",(a*f-c*d)/(a*e-b*d)+0.0);
    }
    
    return 0;
}



Measured memory_bytes: 3188
# -*- coding: utf-8 -*-
import math
import itertools
n = int(input())
p = [int(i) for i in input().split()]
q = [int(i) for i in input().split()]

tmp = [i+1 for i in range(n)]
tmp2 = list(itertools.permutations(tmp))
for i in range(len(tmp2)):
    flag1 = True
    flag2 = True
    for j in range(len(p)):
        if tmp2[i][j] != p[j]:
            flag1 = False
        if tmp2[i][j] != q[j]:
            flag2 = False
    if flag1:
        a = i + 1
    if flag2:
        b = i + 1
print(abs(a-b))


Measured memory_bytes: 8052
#include <iostream>
#include <queue>
#include <vector>

int dist[200010];

using namespace std;

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

    for (int i = 0; i < n; i++)
        dist[i] = -1;

    queue<int> que;
    dist[0] = 0;
    que.push(0);

    while (!que.empty()) {
        int s = que.front();

        for (int i = 0; i < G[s].size(); i++) {
            int g = G[s][i];

            if (dist[g] >= 0)
                continue;

            dist[g] = dist[s] + 1;

            que.push(g);
        }

        que.pop();
    }

    if (dist[n-1] == 2)
        cout << "POSSIBLE" << endl;
    else 
        cout << "IMPOSSIBLE" << endl;
    return 0;
}

Measured memory_bytes: 13168
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		int S = sc.nextInt();
		int W = sc.nextInt();
		
		sc.close();
		
		if(W >= S) {
			out.println("unsafe");
		}else {
			out.println("safe");
		}

	}

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

	@SuppressWarnings("unused")
	private String join(String delimiter, int[] a) {
		StringBuilder sb = new StringBuilder();

		for (int i = 0; i < a.length; i++) {
			sb.append(a[i]);
			sb.append(delimiter);
		}
		return sb.substring(0, Math.max(sb.length() - delimiter.length(), 0));
	}

	@SuppressWarnings("unused")
	private String join(String delimiter, long[] a) {
		StringBuilder sb = new StringBuilder();

		for (int i = 0; i < a.length; i++) {
			sb.append(a[i]);
			sb.append(delimiter);
		}
		return sb.substring(0, Math.max(sb.length() - delimiter.length(), 0));
	}

	@SuppressWarnings("unused")
	private int max(int[] arr) {
		if(arr == null || arr.length == 0) {
			throw new IllegalArgumentException(Arrays.toString(arr));
		}

		int candidate = arr[0];
		for(int i=1;i<arr.length;i++) {
			candidate = candidate > arr[i] ? candidate : arr[i];
		}
		return candidate;
	}

	@SuppressWarnings("unused")
	private long max(long[] arr) {
		if(arr == null || arr.length == 0) {
			throw new IllegalArgumentException(Arrays.toString(arr));
		}

		long candidate = arr[0];
		for(int i=1;i<arr.length;i++) {
			candidate = candidate > arr[i] ? candidate : arr[i];
		}
		return candidate;
	}

	@SuppressWarnings("unused")
	private int min(int[] arr) {
		if(arr == null || arr.length == 0) {
			throw new IllegalArgumentException(Arrays.toString(arr));
		}

		int candidate = arr[0];
		for(int i=1;i<arr.length;i++) {
			candidate = candidate < arr[i] ? candidate : arr[i];
		}
		return candidate;
	}

	@SuppressWarnings("unused")
	private long min(long[] arr) {
		if(arr == null || arr.length == 0) {
			throw new IllegalArgumentException(Arrays.toString(arr));
		}

		long candidate = arr[0];
		for(int i=1;i<arr.length;i++) {
			candidate = candidate < arr[i] ? candidate : arr[i];
		}
		return candidate;
	}

	@SuppressWarnings("unused")
	private int[] nextIntArray(Scanner sc, int n) {
		int[] result = new int[n];
		for (int i = 0; i < n; i++) {
			result[i] = sc.nextInt();
		}
		return result;
	}

	@SuppressWarnings("unused")
	private long[] nextLongArray(Scanner sc, int n) {
		long[] result = new long[n];
		for (int i = 0; i < n; i++) {
			result[i] = sc.nextLong();
		}
		return result;
	}

	@SuppressWarnings("unused")
	private int[] nextIntArray1origin(Scanner sc, int n) {
		int[] result = new int[n + 1];
		for (int i = 1; i <= n; i++) {
			result[i] = sc.nextInt();
		}
		return result;
	}
}


Measured memory_bytes: 27084
#include <bits/stdc++.h>
#define GET_MACRO(_1,_2,_3,_4,_5,_6,_7,_8,NAME,...) NAME
#define pr(...) cerr<< GET_MACRO(__VA_ARGS__,pr8,pr7,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__) <<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
#define prArr(a) {cerr<<(#a)<<"={";int i=0;for(auto t:(a))cerr<<(i++?", ":"")<<t;cerr<<"}"<<endl;}
using namespace std;
using Int = long long;
using _int = int;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<60)+1e9; // ~ 1.15 * 1e18
const Int mod = (1e9)+7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
template<class T1, class T2> ostream& operator<<(ostream& o,pair<T1,T2> p){return o<<"("<<p.first<<","<<p.second<<")";}
template<class T1, class T2, class T3> ostream& operator<<(ostream& o,tuple<T1,T2,T3> t){
  return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
template<class T1, class T2> istream& operator>>(istream& i,pair<T1,T2> &p){return i>>p.first>>p.second;}
template<class T> ostream& operator<<(ostream& o,vector<T> a){Int i=0;for(T t:a)o<<(i++?" ":"")<<t;return o;}
template<class T> istream& operator>>(istream& i,vector<T> &a){for(T &t:a)i>>t;return i;}
//INSERT ABOVE


vector<P> cut(Int idx, Int s, vector<P> A){
  P target = A[idx]; A.erase(A.begin() + idx);
  Int H, W; tie(H, W) = target;
  s %= (H + W);
  P a, b;
  if(s <= W){
    a = P(H, W - s);
    b = P(H, s);
  }
  else{
    a = P(H - (s - W), W);
    b = P(s - W, W);
  }
  if(a.first * a.second > b.first * b.second) swap(a, b);

  A.push_back(a);
  A.push_back(b);
  return A;
}

signed main(){
  srand((unsigned)time(NULL));
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  while(1){
    Int N, w, h;
    cin>>N>>w>>h;
    if(N == 0 && w == 0 && h == 0) break;

    vector<P> A = {P(h, w)};
    for(Int i=0;i<N;i++){
      Int p, s;
      cin>>p>>s;
      p--;
      A = cut(p, s, A);
    }
    vector<Int> ans;
    for(auto p:A) ans.push_back(p.first * p.second);
    sort(ans.begin(), ans.end());
    cout<<ans<<endl;

  }
  return 0;
}



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

public class Remainder
{
    static long N;
    static long A;
    static long B;
    static long C;
    static long ans = long.MaxValue;
    static public void Main ()
    {
        var NABC = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
        A = NABC[0];
        B = NABC[1];

        
Console.WriteLine(Math.Max(Math.Max(A-B,A+B),A*B));

    }

    static long CountMP(List<long> L){
       long res = long.MaxValue;
       L.Sort();
       int p = 0;
       for(int i = p;i+2 < N;i++){
         if(Math.Abs(C-L[i]) < Math.Abs(C-L[i+1]) || i == N-3){
             res = Math.Abs(C-L[i]);
             p = i;
             break;
         }
       }
       
       for(int i = p+1;i+1< N;i++){
         if(Math.Abs(B-L[i]) < Math.Abs(B-L[i+1]) || i == N-2){
             res += Math.Abs(B-L[i]);
             p = i;
             break;
         }
       }
       
       for(int i = p+1;i< N;i++){
         if(i == N-1 || Math.Abs(A-L[i]) < Math.Abs(A-L[i+1])){
             res += Math.Abs(A-L[i]);
             break;
         }
       }
       return res;
    }

    static void SearchAll(List<long> Kadomatu,long MP = 0){
       var tmp = MP+CountMP(Kadomatu);
       if(tmp < ans){
          ans = tmp;
       }
       if(Kadomatu.Count() <= 3){
          return;
       }
       
       for(int i = 0;i < Kadomatu.Count();i++){
          for(int j = i+1;j < Kadomatu.Count();j++){
              Console.WriteLine();
             var list2 = new List<long>(Kadomatu);
             list2[j] += list2[i];
             list2.RemoveAt(i);
             SearchAll(list2,MP);
          }
       }
    }

}


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

using namespace std;

map< string, bool > pizda;

int main () {

    string s;
    cin >> s;
    int k;
    cin >> k;
    vector< string > v;
    for(int i = 0; i < s.size(); ++i) {
        for(int j = i; j < s.size() && j < i + k; ++j) {
            string cur = "";
            for(int l = i; l <= j; ++l) {
                cur += s[l];
            }
            if(pizda[cur]) continue;
            pizda[cur] = true;
            v.push_back(cur);
        }
    }

    sort(v.begin(), v.end());
    cout << v[k-1];
    return 0;
}


Measured memory_bytes: 2048
N = int(input())
H = list(map(int, input().split()))
count = 0
judge = True
for i in reversed(range(1, len(H))):
  judge = True
  for j in reversed(range(i)):
    if H[i] < H[j]:
      judge = False
  if judge:
    count += 1
print(count+1)

Measured memory_bytes: 3060
import java.util.*;
public class Main {
	public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int c = 0;
        if (s.substring(0,1).equals("1")) c++;
        if (s.substring(1,2).equals("1")) c++;
        if (s.substring(2,3).equals("1")) c++;
        System.out.println(c);
	}
}

Measured memory_bytes: 35608
N = int(input())
A = input().split()
deki= True
for i in range(N):
    ai = int(A[i])
    if ai%2==0:
        if ai%3==0 or ai%5==0:
            ai = ai
        else:
            deki=False
            break
if deki:
    print("APPROVED")
else:
    print("DENIED")
            



Measured memory_bytes: 3060
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <unordered_map>
#include <climits>
#include <set>
#include <unordered_set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <complex>
#include <regex>

using namespace std;

#define SHOW_VECTOR(v) {std::cerr << #v << "\t:";for(const auto& xxx : v){std::cerr << xxx << " ";}std::cerr << "\n";}
#define SHOW_MAP(v){std::cerr << #v << endl; for(const auto& xxx: v){std::cerr << xxx.first << " " << xxx.second << "\n";}}


int main() {

    int sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;

    tx += (-sx);
    ty += (-sy);
    sx = sy = 0;

    string ans = "";

    for (int i = 0; i < ty; i++) ans += 'U';
    for (int i = 0; i < tx; i++) ans += 'R';
    for (int i = 0; i < ty; i++) ans += 'D';
    for (int i = 0; i < tx + 1; i++) ans += 'L';
    for (int i = 0; i < ty + 1; i++) ans += 'U';
    for (int i = 0; i < tx + 1; i++) ans += 'R';
    ans += 'D';
    ans += 'R';
    for (int i = 0; i < ty + 1; i++) ans += 'D';
    for (int i = 0; i < tx + 1; i++) ans += 'L';
    ans += 'U';

    cout << ans << endl;
    
    
    return 0;
}
 















































Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();

		if (N == M)
			System.out.print("Yes");
		else
			System.out.print("No");

		sc.close();

	}
}

Measured memory_bytes: 21972
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;

namespace AtCorder
{
	public class Program
	{
		const long MOD = 1000000007;
		static void Main(string[] args)
		{
			var cin = new Scanner2();
			int n = cin.Int();
			long x = cin.Long();
			int[] ss = cin.ArrayInt(n);
			Array.Sort(ss);
			Array.Reverse(ss);

			int m = Math.Max(ss[0], (int)x) + 1;
			long[,] dp = new long[n + 1, m];
			dp[0, x] = 1;
			for (int i = 0; i < n; i++) {
				long rate = n - i - 1;
				for (int j = 0; j < m; j++) {
					int dst = j % ss[i];
					dp[i + 1, j] += ((dp[i, j] * rate) % MOD);
					dp[i + 1, j] %= MOD;
					dp[i + 1, dst] += dp[i, j];
					dp[i + 1, dst] %= MOD;
				}
			}

			long ans = 0;
			for (int i = 0; i < m; i++) {
				ans = (ans + ((dp[n, i] * i) % MOD)) % MOD;
			}

			Console.WriteLine(ans);
		}
	}

	public class Scanner2
	{
		private readonly char[] delimiter_ = new char[] { ' ' };
		private readonly string filePath_;
		private string[] buf_;
		private int index_;
		Func<string> reader_;

		public Scanner2(string file = "")
		{
			if (string.IsNullOrWhiteSpace(file)) {
				reader_ = Console.ReadLine;
			} else {
				filePath_ = file;
				var fs = new StreamReader(file);
				reader_ = fs.ReadLine;
			}
			buf_ = new string[0];
			index_ = 0;
		}

		public string Next()
		{
			if (index_ < buf_.Length) {
				return buf_[index_++];
			}

			string st = reader_();
			while (st == "") {
				st = reader_();
			}

			buf_ = st.Split(delimiter_, StringSplitOptions.RemoveEmptyEntries);
			if (buf_.Length == 0) {
				return Next();
			}

			index_ = 0;
			return buf_[index_++];
		}

		public int Int() => 
			int.Parse(Next());
		public long Long() => long.Parse(Next());
		public double Double() => double.Parse(Next());

		public int[] ArrayInt(int N, int add = 0)
		{
			int[] Array = new int[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Int() + add;
			}
			return Array;
		}

		public long[] ArrayLong(int N, long add = 0)
		{
			long[] Array = new long[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Long() + add;
			}
			return Array;
		}

		public double[] ArrayDouble(int N, double add = 0)
		{
			double[] Array = new double[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Double() + add;
			}
			return Array;
		}

		public void Save(string text)
		{
			if (string.IsNullOrWhiteSpace(filePath_)) {
				return;
			}

			File.WriteAllText(filePath_ + "_output.txt", text);
		}
	}
}

Measured memory_bytes: 166880
class SegmentTree():
    """一点更新、区間取得クエリをそれぞれO(logN)で答えるデータ構造を構築する
    update: i番目をvalに変更する
    get_min: 区間[begin, end)の最小値を求める
    """
    def __init__(self, n):
        self.n = n
        self.INF = 2**31 - 1
        self.size = 1
        while self.size < n:
            self.size *= 2
        self.node = [self.INF] * (2*self.size - 1)

    def update(self, i, val):
        i += (self.size - 1)
        self.node[i] = val
        while i > 0:
            i = (i - 1) // 2
            self.node[i] = min(self.node[2*i + 1], self.node[2*i + 2])

    def get_min(self, begin, end):
        begin += (self.size - 1)
        end += (self.size - 1)
        s = self.INF
        while begin < end:
            if (end - 1) & 1:
                end -= 1
                s = min(s, self.node[end])
            if (begin - 1) & 1:
                s = min(s, self.node[begin])
                begin += 1
            begin = (begin - 1) // 2
            end = (end - 1) // 2
        return s

    def debug(self):
        """Segment Tree上の葉の配列を出力する"""
        return(self.node[self.size - 1: self.size - 1 + self.n])


n, q = map(int, input().split())
info = [list(map(int, input().split())) for i in range(q)]
st = SegmentTree(n)

for i in range(q):
    com, x, y = info[i]
    if com == 0:
        st.update(x, y)
    else:
        print(st.get_min(x, y + 1))


Measured memory_bytes: 27072
#include <algorithm>
#include <cassert>
#include <climits>
#include <complex>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <iterator>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>

/* -------------------------------- Template -------------------------------- */

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()

using namespace std;

using ll = long long;
using ld = long double;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }

template<typename T> T inf;
template<> constexpr int inf<int> = 1e9;
template<> constexpr ll inf<ll> = 1e18;
template<> constexpr ld inf<ld> = 1e30;

struct yes_no : numpunct<char> {
  string_type do_truename()  const { return "Yes"; }
  string_type do_falsename() const { return "No"; }
};

/* -------------------------------- Library -------------------------------- */

/* ---------------------------------- Main ---------------------------------- */

int main() {
  locale loc(locale(), new yes_no);
  cout << boolalpha;
  cout.imbue(loc);

  int n, m; cin >> n >> m;
  vector<vector<tuple<int,int>>> edges(n);
  REP(i, m){
    int l, r, d; cin >> l >> r >> d;
    edges[l-1].emplace_back(r-1, d);
    edges[r-1].emplace_back(l-1, -d);
  }

  queue<int> q;
  vector<bool> vis(n, false);

  vector<int> dist(n, -42);

  
  bool ok = true;
  int k = 0;
  while (k < n) {

  dist[k] = 0;
  q.push(k);
  vis[k] = true;

  while (!q.empty()) {
    int p = q.front();
    q.pop();
    for (auto&& e : edges[p]){
      int t, d; tie(t, d) = e;
      if (!vis[t]) {
        dist[t] = dist[p] + d;
        q.push(t);
        vis[t] = true;
      } else {
        if (dist[t] != dist[p] + d){
          ok = false;
          goto out;
        }
      }
    }
  }

  k += 1;
  while(k < n && vis[k]) k += 1;
  }
  out:
  cout << ok << endl;
  return 0;
}

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

#define M 500

ll a[250020],b[M];
bool same[M];

void update(int j){
    same[j] = true;
    ll first = a[j*M] + b[j];
    rep(i,M) same[j] &= (a[i+j*M]+b[j] == first);
}

// [l,r) 
void add(int l,int r,int x){
    if(l/M == r/M){
        FOR(i,l,r) a[i] += x;
        update(l/M);
        return;
    }

    FOR(j,l/M+1,r/M) b[j] += x;

    FOR(i,l,l-l%M+M) a[i] += x;
    update(l/M);

    FOR(i,r-r%M,r) a[i] += x;
    update(r/M);
}

int main(void){
    int N,Q;
    cin>>N;
    vector<int> s(N);
    rep(i,N) cin>>s[i];
    rep(i,N/2) a[i] = s[i]-s[N-1-i];
    rep(j,M) update(j);

    cin>>Q;
    while(Q--){
        int l,r,x;
        cin>>l>>r>>x;
        l--,r--;
        if(l<N/2 && N/2<=r){
            if(l<N-1-r) add(l,N-1-r,x);
            else add(N-1-r,l,-x);
        }
        if(r<N/2) add(l,r+1,x);
        if(N/2<=l) add(N-1-r,N-l,-x);

        bool allZero = true;
        rep(j,M){
            allZero &= (same[j] && a[j*M]+b[j]==0);
        }
        cout<<allZero<<endl;
    }
    return 0;
}

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

#define ll long long int
#define pi 3.141592653589793238
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define mod 1000000007

int main(){
	fast;
    long long int n;
    cin>>n;
    long long int arr[n];
    for(int i=0;i<n;i++)
        cin>>arr[i];
    long long int maxS[n];
    maxS[0]=arr[0];
    for(int i=1;i<n;i++)
        maxS[i]=max(arr[i],maxS[i-1]);
    long long int ans=0;
    for(int i=0;i<n;i++)
        ans+=maxS[i]-arr[i];
    cout<<ans<<endl;
	return 0;
}



Measured memory_bytes: 6736
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define vll vector<long long>
#define ll long long
#define pii pair<int,int>
const int mod=1e9+7;
int dfs(vector<int> adj[],int v,vector<int> &dp){
	if(adj[v].size()==0) return dp[v]=0;
	if(dp[v]!=-1) return dp[v];
	for(auto i:adj[v]){
		dp[v]=max(dp[v],dfs(adj,i,dp));
	}
	dp[v]++;
	return dp[v];
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
#ifndef ONLINE_JUDGE
    freopen("inputf.txt","r",stdin);
    freopen("outputf.txt","w",stdout);
#endif
    int n,m;
    cin>>n>>m;
    vector<int> adj[n];
    int x,y;
    for(int i=0;i<m;i++){
    	cin>>x>>y;
    	x--;
    	y--;
    	adj[x].pb(y);
    }
    vector<int> dp(n,-1);
    int ans=0;
    for(int i=0;i<n;i++){
    	if(dp[i]==-1){
    		ans=max(ans,dfs(adj,i,dp));
    	} 
    }
    cout<<ans<<"\n";
    return 0;
}

Measured memory_bytes: 10956
N,D = map(int,input().split())
P = [list(map(int,input().split())) for i in range(N)]
count = 0
for i in range(N-1):
  for j in range(i+1,N):
    x = 0
    for k in range(D):
      x += abs(P[i][k] - P[j][k])**2
    ans = x**(1/2)
    if ans.is_integer():
      count += 1
print(count)

Measured memory_bytes: 9460
#include <iostream>

int main() {
  const int ARR_SIZE = 100;
  int a[ARR_SIZE];
  int n;
  bool sorted;
  int count = 0;

  std::cin >> n;
  for (int i = 0;i < n;i++) {
    std::cin >> a[i];
  }

  sorted = false;
  while (!sorted) {
    sorted = true;
    for (int i = n - 1; i > 0; i--) {
      if (a[i] < a[i - 1]) {
        int tmp = a[i];
        a[i] = a[i - 1];
        a[i - 1] = tmp;
        sorted = false;
        count++;
      }
    }
  }

  for (int i = 0; i < n;i++) {
    if (i == n - 1) {
      std::cout << a[i] << std::endl;
    } else {
      std::cout << a[i] << " ";
    }
  }
  std::cout << count << std::endl;

  return 0;
}

Measured memory_bytes: 3104
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "math.h"
#include "utility"
#include "string"
#include "map"
#include "unordered_map"
#include "iomanip"
#include "random"

using namespace std;
const long long int MOD = 1000000007;

long long int power(long long int x, long long int n, long long int M) {
	long long int tmp = 1;

	if (n > 0) {
		tmp = power(x, n / 2, M);
		if (n % 2 == 0) tmp = (tmp*tmp) % M;
		else tmp = (((tmp*tmp) % M)*x) % M;
	}
	return tmp;
}

long long int N, M, K, Q, W, H, L, R;
long long int ans;



int main() {
	ios::sync_with_stdio(false);
	cin >> N;
	N--;
	while (N) {
		N /= 3;
		ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3172
#include<bits/stdc++.h>
using namespace std;
typedef long long lli;
const int maxn = 5e5 + 50;
typedef pair<int, int> P;

void solve();
int main()
{
	int t = 1;
//	cin >> t;
	for(int i=0; i<t; i++)
	{
		solve();
		cout << '\n';
	}
	return 0;
}

// type below

void solve()
{
	int ans = 0;
	for(int i=0; i<5; i++)
	{
		int tmp; cin >> tmp;
		if(!tmp) ans = i + 1;
	}
	cout << ans << '\n';
	
}

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

string code(char a){
  if(a =='A')return "00000";
  if(a =='B')return "00001";
  if(a =='C')return "00010";
  if(a =='D')return "00011";
  if(a =='E')return "00100";
  if(a =='F')return "00101";
  if(a =='G')return "00110";
  if(a =='H')return "00111";
  if(a =='I')return "01000";
  if(a =='J')return "01001";
  if(a =='K')return "01010";
  if(a =='L')return "01011";
  if(a =='M')return "01100";
  if(a =='N')return "01101";
  if(a =='O')return "01110";
  if(a =='P')return "01111";
  if(a =='Q')return "10000";
  if(a =='R')return "10001";
  if(a =='S')return "10010";
  if(a =='T')return "10011";
  if(a =='U')return "10100";
  if(a =='V')return "10101";
  if(a =='W')return "10110";
  if(a =='X')return "10111";
  if(a =='Y')return "11000";
  if(a =='Z')return "11001";
  if(a ==' ')return "11010";
  if(a =='.')return "11011";
  if(a ==',')return "11100";
  if(a =='-')return "11101";
  if(a =='\'')return "11110";
  if(a =='?')return "11111";
  return "none";
}

string decode(string a){
  string res;
  string table[32] = { "101", "000000", "000011", "10010001", "010001",
                       "000001", "100101", "10011010", "0101", "0001",
		       "110", "01001", "10011011", "010000", "0111",
		       "10011000", "0110", "00100", "10011001", "10011110",
		       "00101", "111", "10011111", "1000", "00110", "00111",
		       "10011100", "10011101", "000010", "10010010",
		       "10010011", "10010000"};
  int pos = 0,i;
  while(pos < (int)a.size()){
    for(i=0;i<32;i++){
      bool f = true;
      for(int j=0;j<(int)table[i].size();j++){
	if(a[pos+j] != table[i][j]){
	  f = false;
	  break;
	}
      }
      if(f){
	if(i>=6)res.push_back('A'+i-6);
	else{
	  if(i==0)res.push_back(' ');
	  if(i==1)res.push_back('\'');
	  if(i==2)res.push_back(',');
	  if(i==3)res.push_back('-');
	  if(i==4)res.push_back('.');
	  if(i==5)res.push_back('?');
	}
	pos += table[i].size();
	break;
      }
    }
    if(i==32)break;
  }
  return res;
}

int main(){
  string tmp;
  while(getline(cin,tmp)){
    string c;
    for(int i=0;i<(int)tmp.size();i++)c += code(tmp[i]);
    cout << decode(c) << endl;
  }
}

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

void Solve()
{
    int N;
    cin >> N;
    int W[N + 1], S[N + 1];
    S[0] = 0;
    for (int i = 1; i < N + 1; i++)
    {
        cin >> W[i];
        S[i] = S[i - 1] + W[i];
    }
    for (int i = 1; i < N + 1; i++)
    {
        S[i] = S[N] - 2 * S[i];
        S[i] = abs(S[i]);
    }
    int c = S[1];
    for (int i = 1; i < N; i++)
    {
        c = min(c, S[i]);
    }
    cout << c << endl;
}

int main()
{
    Solve();
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <queue> 
#include <list>
#include <stack>
#include <unordered_map>
#include <algorithm> 
#include <numeric>  
#include <functional>
#include <cassert>
#include <bitset>
#include <cctype>  
#include <iomanip> 
#include <limits>  
// std::numeric_limits<int>::max(), min()
// std::setprecision(X)
// std::islower(), std::isupper(), std::tolower, std::toupper
// std::accumulate(m.begin(), m.end(), 0LL);
// std::sort(begin(),end()) // 0, 1, 2, 3 ,4 (default, less);
// std::priority_queue<int, vector<int>, less<int>> que; // 4, 3, 2, 1 (defualt, less) : 
 
#define  rep(i, n) for(int i = 0; i < (int)(n);    i++)
#define rrep(i, n) for(int i = ((int)(n)-1); i>=0; i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()

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; }
typedef long long ll;

ll gcd ( ll a, ll b ) { if ( b == 0 ) return a; else return gcd ( b, a%b ); }
ll lcm ( ll a, ll b ) { return a * b / gcd(a, b); }


int main (void) {
  std::cin.tie(0);  std::ios::sync_with_stdio(false);
  int N; std::cin >> N;
  std::vector<int> A(N), B(N), C(N-1);
  rep(i,N) std::cin >> A[i];
  rep(i,N) std::cin >> B[i];
  rep(i,N-1) std::cin >> C[i];

  int ans = 0;
  int bef = -3;
  for(int i=0; i<N; i++){
    int eat = A[i]-1;
    ans += B[eat];
    if (i == 0) bef = eat;
    else {
      if ( bef + 1 == eat ) ans += C[bef];
      bef = eat;
    }
  }
  std::cout << ans << std::endl;

  return 0;
}


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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  string result = "Balanced";
  if (A + B > C + D) {
    result = "Left";
  }
  else if (A + B < C + D) {
    result = "Right";
  }
  cout << result << endl;
}

Measured memory_bytes: 256
N = int(input())
T, A = map(int, input().split())
H = list(map(int, input().split()))

mini = None
minv = float('inf')

for i, h in enumerate(H):
  delta = abs(A - (T - 0.006 * h))
  if delta < minv:
    mini = i + 1
    minv = delta
print(mini)

Measured memory_bytes: 3060
#include <stdio.h>

int main(void)
{
	int p, n;
	int sum, ave;
	int count;

	sum = ave = count = 0;
	while (scanf("%d,%d", &p, &n) != EOF){
		sum += p * n;
		ave += n;
		count++;
	}

	printf("%d\n%d\n", sum, (int)((float)ave / count + 0.5));

	return (0);
}

Measured memory_bytes: 592
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<math.h>
#include<vector>

using namespace std;

#define REP(i, n) for(int i=0; i<n; i++)
typedef pair<double ,pair<int, int> > pdii; // distance, point1, point2

int n;
double dis[100][100];
int unit[100];
vector<pdii> difdis(100);

double x[100], y[100], z[100], r[100];
double cordis;

double dis3d(double x1, double y1, double z1, double x2, double y2, double z2){
    return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)+(z1-z2)*(z1-z2));
}

bool allunited(){
    int u = unit[0];
    REP(i, n){
        if(unit[i] != u) return false;
    }
    return true;
}

int main(){
    while(1){
        cin >> n;
        if(n==0) break;

        REP(i, n){
            cin >> x[i];
            cin >> y[i];
            cin >> z[i];
            cin >> r[i];
        }

        REP(i, n){
            REP(j, n){
                if(i==j){
                    dis[i][j] = 0;
                } else {
                    dis[i][j] = dis3d(x[i], y[i], z[i], x[j], y[j], z[j]) - (r[i]+r[j]);
                }
            }
        }

        REP(i, n) unit[i] = i;
        REP(i, n){
            int u = unit[i];
            vector<int> update;
            update.push_back(unit[i]);
            REP(j, n){
                if(dis[i][j]<=0){
                    update.push_back(unit[j]);
                    u = min(u, unit[j]);
                    unit[j] = unit[i];
                }
            }
            REP(j, n){
                REP(k, update.size()){
                    if(unit[j] == update[k]){
                        unit[j] = u;
                    }
                }
            }
        }

        cordis = 0;
        while(1){
            if(allunited()) break;

            difdis = vector<pdii>();
            REP(i, n){
                for(int j=i+1; j<n; j++){
                    if(unit[i] != unit[j]){
                        difdis.push_back(pdii(dis[i][j], make_pair(i, j)));
                    }
                }
            }

            sort(difdis.begin(), difdis.end());
            cordis += difdis[0].first;
            int ci = difdis[0].second.first;
            int cj = difdis[0].second.second;

            int ucj = unit[cj];
            REP(i, n){
                if(unit[i] == ucj){
                    unit[i] = unit[ci];
                }
            }
        }

        cout << fixed << setprecision(3) << cordis << endl;
    }
}

Measured memory_bytes: 3472
#include<bits/stdc++.h>
#define lli long long int
#define in int
#define el endl
#define oo cout
#define ii cin
#define pb push_back
#define bg begin()
#define en end()
#define p1 first
#define p2 second
#define FOR(i,a,b,c) for (int i = (a); i < (b); i=i+(c))
#define ROF(i,a,b,c) for (int i = (a); i > (b); i=i-(c))
using namespace std;

//vector< pair<lli,lli> >ccr;
//vector< pair<lli,lli> >jjr;
//vector<string>r;
//int ar[100008],br[100008];

int main()
{


int n,aa,bb,cc,i,j;
ii>>n;
vector<lli>v,u;
FOR(i,0,n+1,1){
ii>>cc;
v.pb(cc);
//ar[i]=cc;
}
FOR(i,0,n,1){
ii>>cc;
u.pb(cc);
//br[i]=cc;
}

lli ss=0;

FOR(i,0,n,1){

    if(v[i]>u[i]){
    ss+=u[i];
    u[i]=0;
    }
    else{
        ss+=v[i];
        u[i]-=v[i];
    }

if(u[i]>0){
        if((v[i+1])>u[i]){
        ss+=u[i];
        v[i+1]-=u[i];
        }
        else{
            ss+=v[i+1];
            v[i+1]=0;
}
}
}
oo<<ss<<el;
return 0;
}



Measured memory_bytes: 5608
s = input()
count = 0
for i in range(2, len(s)-1):
    if s[i] == 'C':
        count = count + 1
        s = s[:i] + 'c' + s[i+1:]
    else:
        continue
if s[0] != 'A':
    flag = False
elif count != 1:
    flag = False
else:
    s = 'a' + s[1:]
    flag = s.islower()
if flag:
    print('AC')
else:
    print('WA')

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
int main()
{
  int a,b;
  cin>>a>>b;
  if(a<=b){
    cout<<a;
  }
  else cout<<a-1;
} 

Measured memory_bytes: 256
def main(): 
    n = int(input())
    h = list(map(int, input().split()))

    i = len(h) -1
    while 1 <= i:
        if h[i -1] <= h[i]:
            i -= 1
            continue
        elif h[i -1] - 1 <= h[i]:
            h[i - 1] -= 1
            i -= 1
            continue
        else:
            print('No')
            break
    else:
        print('Yes')


if __name__ == "__main__":
    main() 

Measured memory_bytes: 14396
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace CsharpSpiral {
	partial class Program {
		//https://qiita.com/NotFounds/items/7b166af69a6f52a332de
		static void Main(string[] args) {
            var sw = new StreamWriter( Console.OpenStandardOutput() ) { AutoFlush = false };
            Console.SetOut( sw );
            new Program().Solve(new ConsoleInput(Console.In,' '));
            Console.Out.Flush();
        }
		public void Solve(ConsoleInput cin) {
            var N = cin.ReadInt;
            var A = cin.ReadIntArray(N);
            var count = 0;
            for (int i = 0; i < N; i++) {
                var mi = i;
                for (int j = i+1; j < N; j++) {
                    if (A[j] < A[mi]) {
                        mi = j;
                    }
                }
                if (i != mi) {
                    A.Swap( i, mi );
                    count++;
                }
            }
            Console.WriteLine(A.Join());
            Console.WriteLine(count);
		}
	}

    static class ExtendClass {
        public static void Swap<T>(this T[] X, int i, int j) {
            T tmp = X[i];
            X[i] = X[j];
            X[j] = tmp;
        }
        public static string Join<T> (this T[] X, string separator = " ") => string.Join( separator, X);
    }

    class ConsoleInput {
        private readonly TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(TextReader stream, char separator = ' ') {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read {
            get {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split( _separator );
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue( tmp[i] );
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse( Read ); } }
        public long ReadLong { get { return long.Parse( Read ); } }
        public double ReadDouble { get { return double.Parse( Read ); } }
        public string[] ReadStrArray(long N) {
            var ret = new string[N];
            for (long i = 0; i < N; ++i)
                ret[i] = Read;
            return ret;
        }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }
}



Measured memory_bytes: 18464
#include <bits/stdc++.h>
using std::cin;
using std::cout;
using std::pair;
using std::vector;
const int Maxn = 1e5 + 1, mod = 1e9 + 7;
std::map < long long, int > mp;
int dp( long long x )
{
 if( mp[ x ] != 0 )
  return mp[ x ];
 return mp[ x ] = ( ( dp( x / 2 ) + dp( ( x - 1 ) / 2 ) ) % mod + dp( ( x - 2 ) / 2 ) ) % mod;
}
long long n;
int main( )
{
 std::ios::sync_with_stdio( false );
 cin.tie( NULL );
 cout.tie( NULL );
 cin >> n;
 mp[ 0 ] = 1;
 mp[ 1 ] = 2;
 printf( "%d", dp( n ) ); 
 return 0;
}

Measured memory_bytes: 3772
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <utility>
#include <vector>
#include <cmath>
#include <map>
#include <string>

using namespace std;

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

    int a, b;
    cin >> a >> b;
    if (a <= 12) b = b / 2;
    if (a <= 5) b = 0;
    cout << b << "\n";

    return 0;
}

Measured memory_bytes: 256
// #include <bits/stdc++.h>
#include <iostream>
#include <cmath>
#include <cstdio>
#include <algorithm>
using namespace std;
const double eps = 1e-8;
const double pi = acos(-1.0);
typedef long long ll;
int sgn(double x){
    if(fabs(x)<eps){
        return 0;
    }
    if(x<0){
        return -1;
    }else{
        return 1;
    }
}
struct Point{
    double x,y;
    Point(){}
    Point(double _x,double _y){
        x = _x;
        y = _y;
    }
    void input(){
        scanf("%lf%lf",&x,&y);
    }
    Point operator+(const Point &b)const{
        return Point(x+b.x,y+b.y);
    }
    Point operator -(const Point &b)const{
        return Point(x-b.x,y-b.y);
    }
    double operator *(const Point &b)const{
        return x*b.x+y*b.y;
    }
    Point operator *(const double &k)const{
        return Point(x*k,y*k);
    }
    Point operator /(const double &k)const{
        return Point(x/k,y/k);
    }
    double len2(){
        return x*x+y*y;
    }
};
struct Line{
    Point s,e;
    Line(){}
    Line(Point _s,Point _e){
        s = _s;
        e = _e;
    }
    //返回点p在直线上的投影
    Point lineprog(Point p){
        return s+(((e-s)*((e-s)*(p-s)))/((e-s).len2()));
    }
};
int main(){
    Point p1,p2,p3;
    p1.input();
    p2.input();
    Line line(p1,p2);
    int q;
    scanf("%d",&q);
    Point ans;
    while(q--){
        p3.input();
        ans = line.lineprog(p3);
        printf("%.10f %.10f\n",ans.x,ans.y);
    }
   
    return 0;
}


Measured memory_bytes: 3244
#include <iostream>
#include <cstring>

using namespace std;

int main() {
  while (true) {
    int field[21][21]; // フィールドの縦、横の座標
    int N; // 宝石の個数
    int M; // 命令の個数
    int positionX = 10; // ロボットの位置のx座標
    int positionY = 10; // ロボットの位置のy座標
    memset(field, 0, sizeof(field));
    
    cin >> N;
    if (N == 0) {
      break;
    }
    for (int i = 0; i < N; i++) {
      int x, y;
      cin >> x >> y;
      field[y][x] = 1;
    }
    
    cin >> M;
    for (int i = 0; i < M; i++) {
      char direction;
      int distance;
      cin >> direction >> distance;
      switch (direction) {
      case 'N':
	for (int j = 0; j <= distance; j++) {
	  field[positionY+j][positionX] = 0;
	}
	positionY += distance;
	break;
      case 'E':
	for (int j = 0; j <= distance; j++) {
	  field[positionY][positionX+j] = 0;
	}
	positionX += distance;
	break;
      case 'S':
	for (int j = 0; j <= distance; j++) {
	  field[positionY-j][positionX] = 0;
	}
	positionY -= distance;
	break;
      case 'W':
	for (int j = 0; j <= distance; j++) {
	  field[positionY][positionX-j] = 0;
	}
	positionX -= distance;
	break;
      }
    }
    
    bool ans = true;
    for (int i = 0; i < 21; i++) {
      for (int j = 0; j < 21; j++) {
	if (field[i][j] == 1) {
	  ans = false;
	}
      }
    }
    if (ans) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  }
  
  return 0;
}

Measured memory_bytes: 1152
#include <iostream>
#include <algorithm>
#include <array>
#include <string>

class Dice{
    /* left-hand dice      right-hand dice
            +---+                +---+    
            | 1 |                | 1 |    
    +---+---+---+---+    +---+---+---+---+
    | 5 | 3 | 0 | 2 |    | 5 | 2 | 0 | 3 |
    +---+---+---+---+    +---+---+---+---+
            | 4 |                | 4 |    
            +---+                +---+    
    */
    public:
    std::array<int, 6> state;
    Dice(bool isRight=false):state(std::array<int, 6>{{1, 2, (!isRight)?3:4, (!isRight)?4:3, 5, 6}}){}
    Dice(std::array<int, 6> d, bool isRight=false):state(d){if(isRight){int tmp=state[2];state[2]=state[3];state[3]=tmp;}}
    void RollTo(int d){
        /*
            0
            |
        2 --#-- 1
            |
            3
        */
        std::array<int, 6> tmp(state);
        switch(d){
            case 0: state[0] = tmp[4]; state[1] = tmp[0]; state[4] = tmp[5]; state[5] = tmp[1]; break;
            case 1: state[0] = tmp[3]; state[2] = tmp[0]; state[3] = tmp[5]; state[5] = tmp[2]; break;
            case 2: state[0] = tmp[2]; state[2] = tmp[5]; state[3] = tmp[0]; state[5] = tmp[3]; break;
            case 3: state[0] = tmp[1]; state[1] = tmp[5]; state[4] = tmp[0]; state[5] = tmp[4]; break;
        }
    }
    void RollTo(char c){
        switch(c){
            case 'N': RollTo(0); break;
            case 'E': RollTo(1); break;
            case 'W': RollTo(2); break;
            case 'S': RollTo(3); break;
        }
    }
    void Rotate(int d){
        /* 90d degrees clockwise
         -> 0 ->
        ^   |   v
        2 --#-- 1
        ^   |   v
         <- 3 <-
        */
        d%=4;
        std::array<int, 6> tmp(state);
        switch(d){
            case 0: state[1] = tmp[1]; state[2] = tmp[2]; state[4] = tmp[4]; state[3] = tmp[3]; break;
            case 1: state[1] = tmp[3]; state[2] = tmp[1]; state[4] = tmp[2]; state[3] = tmp[4]; break;
            case 2: state[1] = tmp[4]; state[2] = tmp[3]; state[4] = tmp[1]; state[3] = tmp[2]; break;
            case 3: state[1] = tmp[2]; state[2] = tmp[4]; state[4] = tmp[3]; state[3] = tmp[1]; break;
        }
    }
};  

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

    std::array<int, 6> state;
    for(auto& i : state){
        std::cin >> i;
    }
    Dice d(state, true); d.Rotate(2);
    int q;
    std::cin >> q;
    for(int i=0; i<q; ++i){
        int top, front;
        std::cin >> top >> front;
        for(int j=0; j<6 && d.state[0]!=top; ++j){
            if(j==0 || j==5) d.RollTo('E');
            else             d.RollTo('N');
        }
        for(int j=0; j<4 && d.state[4]!=front; ++j){
            d.Rotate(1);
        }
        std::cout << d.state[2] << "\n";
    }
    return 0;
}

Measured memory_bytes: 3104
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <stack>
#include <queue>
#include <iomanip>
using namespace std;
using ll = long long;
using P = pair<int, int>;

ll calcdigit(ll x)
{
    ll ret = 0;
    while(x > 0)
    {
        ++ret;
        x = x / 10;
    }
    return ret;
}

int main()
{
    ll n;
    scanf("%lld", &n);
    ll ans = calcdigit(n);
    for (ll a = 1; a * a <= n; ++a)
    {
        if (n % a) continue;
        ll b = n / a;

        ll d = max(calcdigit(a), calcdigit(b));
        ans = (min)(ans, d);
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 3832
n = int(input())
jobs = []

for i in range(n):
    ai, bi = map(int, input().split())
    jobs.append([ai, bi])

jobs = sorted(jobs, key=lambda x: x[1])

ans = "Yes"
limit = 0
time = 0
for job in jobs:
    time += job[0]
    limit = job[1]
    if limit < time:
        ans = "No"
        break

print(ans)


Measured memory_bytes: 39696
#include<bits/stdc++.h>
#define int long long
using namespace std;
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; }


signed main()
{
    int N,K; cin>>N>>K;
    string s; cin>>s;
    for(int i=0;i<N;i++){
        if(i==K-1){
            cout<<(char)(s[i]+32);
        }else{
            cout<<s[i];
        }
    }
    cout<<endl;
}


Measured memory_bytes: 256