akhauriyash/Code-Regression huggingface dataset:
N, M = gets.chomp.split(" ").map(&:to_i)
V = Array.new(N+1).map{Array.new}
M.times{
  a, b = gets.chomp.split(" ").map(&:to_i)
  V[a] << b
  V[b] << a
}

@ans = 0
def dfs(d, v)
  (@ans += 1; return) if d == N
  V[v].each{|ve|
     next if @s.include?(ve)
     @s.push(ve)
     dfs(d+1, ve)
     @s.pop
   }
end

@s = [1]
dfs(1, 1)

puts @ans


Measured memory_bytes: 3836
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static string InputPattern = "InputX";

    static List<string> GetInputList()
    {
        var WillReturn = new List<string>();

        if (InputPattern == "Input1") {
            WillReturn.Add("8 13");
            //2
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("54 65");
            //1
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }

    static void Main()
    {
        List<string> InputList = GetInputList();
        int[] wkArr = InputList[0].Split(' ').Select(X => int.Parse(X)).ToArray();

        int A = wkArr[0];
        int B = wkArr[1];

        var SikakuList = new List<int>();
        //四角数のListを作る
        for (int I = 1; I <= 999; I++) {
            if (SikakuList.Count == 0) {
                SikakuList.Add(1);
            }
            else {
                SikakuList.Add(SikakuList.Last() + I);
            }
        }

        int Diff = B - A;
        for (int I = 1; I <= SikakuList.Count - 1; I++) {
            if (SikakuList[I] - SikakuList[I - 1] == Diff) {
                Console.WriteLine(SikakuList[I] - B);
                break;
            }
        }
    }
}


Measured memory_bytes: 13396
#include<bits/stdc++.h>
using namespace std;
#define ll long long
typedef pair<ll,ll> P;
#define M 1000000007
ll lcm(ll a,ll b){
  if(a<b)swap(a,b);
  return a%b?lcm(b,a%b):b;
}
ll gcd(ll a,ll b){
  return a*b/lcm(a,b);
}
int main(){
  ll n,k,a,b;cin>>k>>n>>a>>b;
  cout<<n-k+1-((n/a-(k-1)/a)+(n/b-(k-1)/b)-(n/gcd(a,b)-(k-1)/gcd(a,b)));
}

Measured memory_bytes: 256
class Node:
    
    def __init__(self, i):
        self.end = i + 1
        self.days = {i}


N, M = list(map(int, input().split()))
BA = []
for i in range(N):
    a, b = list(map(int, input().split()))
    BA.append((b, a))

ans = 0
schedule = {}


def concat(node1, node2, x):
    if len(node1.days) < len(node2.days):
        node1, node2 = node2, node1
    else:
        node1.end = node2.end
    node1.days |= node2.days
    for i in node2.days:
        schedule[i] = node1
    schedule[x] = node1
    node1.days.add(x)

BA.sort(reverse=True)
for b, a in BA:
    if a <= M:
        if a in schedule:
            w = schedule[a]
            x = w.end
            if x <= M:
                ans += b
                if x + 1 in schedule:
                    concat(w, schedule[x + 1], x)
                else:
                    schedule[x] = w
                    w.days.add(x)
                    w.end += 1
        else:
            ans += b
            if a + 1 in schedule:
                w = schedule[a + 1]
                if a - 1 in schedule:
                    concat(schedule[a - 1], w, a)
                else:
                    schedule[a] = w
                    w.days.add(a)
            elif a - 1 in schedule:
                w = schedule[a - 1]
                schedule[a] = w
                w.days.add(a)
                w.end += 1
            else:
                schedule[a] = Node(a)
print(ans)

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

int main(){
	int x;
	int a, b, c;
	cin >> a >> b >> c;
	if (a > b){
		x = a;
		a = b;
		b = x;
	}
	if (b > c){
		x = b;
		b = c;
		c = x;
	}
	if (a > b){
		x = a;
		a = b;
		b = x;
	}
	cout << a << " " << b << " " << c << endl;
	return 0;
}

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

int main()
{
    int a;
    int b;
    cin >> a >> b;

    int count = 0;
    for (int i=a; i <= b; ++i)
    {
        int left = i/1000;
        int right = i%100;
        if (left == right/10 + 10*(right%10))
        {
            ++count;
        }
    }
    cout << count << std::endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
int main()
{
  int N,K,*D;
  int m[5],tmp,con=0,flag=0,i=0,j=0;
    
  scanf("%d %d",&N,&K);
  D=(int*)malloc(sizeof(int)*K);
  for(i=0;i<K;i++)
    scanf("%d",&D[i]);

  while(flag==0){
    i=0,j=0;
    con=0;
    for(i=1;i<=10000;i*=10){
      tmp=N/i;
      if(tmp==0) break;
      m[con]=tmp%10;
      con++;
    }
    for(i=0;i<con;i++){
      for(j=0;j<K;j++){
        if(m[i]==D[j]){
          N++;
          break;
        }
      }
      if(j!=K) break;
    }
    if(i==con&&j==K) flag=1;
  }
  printf("%d",N);
    
  return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
int main(){
    int a, b, c, k;
    int ans=0;
    scanf("%d%d%d%d",&a,&b,&c,&k);
    if(k>a){
        if(k-a-b>0){
            ans = a-(k-a-b);
        }else{
            ans = a;
        }
    }else{
        ans = k;
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 1720
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <utility>
#include <functional>
#include <stack>
using namespace std;

#define gcu getchar_unlocked
#define pcu putchar_unlocked
#define _T template <typename T>
#define _HT template <typename H, typename... T>
#define _il inline
#define _in _il int in
#define _sc _il bool scan
_T T in(int c){T n=0;bool m=false;if(c=='-')m=true,c=gcu();
	do{n=10*n+(c-'0'),c=gcu();}while(c>='0');return m?-n:n;} //&&c<='9'
_in() {return in<int>(gcu());}
_T T scan(T &n){int c=gcu();return c==EOF?false:(n=in<T>(c),true);}
_sc(char &c){c=gcu();gcu();return c!=EOF;}
#ifdef _GLIBCXX_STRING
_sc(string &s){int c;s="";
	for(;;){c=gcu();if(c=='\n'||c==' ')return true;else if(c==EOF)return false;s+=c;}}
#endif
_HT _sc(H &h, T&&... t){return scan(h)&&scan(t...);}
#define _vo _il void out
#define _vl _il void outl
_vo(const char *s){while(*s)pcu(*s++);}
_vo(char c){pcu(c);}
#ifdef _GLIBCXX_STRING
_vo(string s){for(char c:s)pcu(c);}
#endif
_T _vo(T n){static char buf[20];char *p=buf;
	if(n<0)pcu('-'),n*=-1;if(!n)*p++='0';else while(n)*p++=n%10+'0',n/=10;
	while (p!=buf)pcu(*--p);}
_vl(){out('\n');}
#ifdef _GLIBCXX_VECTOR
_T _vo(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);outl();}
#endif
_HT _vo(H&& h, T&&... t){out(h);out(move(t)...);}
template <typename... T> _vl(T&&... t){out(move(t)...);outl();}

struct calc {
	stack<int> s;
	char c;

	calc() {
		c = gcu();
	}
	bool consume(char e) {
		if (c != e)
			return false;
		else {
			c = gcu();
			return true;
		}
	}

	void eval(function<int(int, int)> f) {
		int b = s.top(); s.pop();
		int a = s.top(); s.pop();
		s.push(f(a, b));
	}

	void number() {
		if (isdigit(c)) {
			int d;
			ungetc(c, stdin);
			scanf("%d", &d);
			s.push(d);
			c = gcu();
		} else {
			fprintf(stderr,"ERROR: expected number\n, but got %c\n", c);
			exit(0);
		}
	}

	void mul() {
		term();
		for (;;)
			if (consume('*')) {
				term();
				eval([](int a, int b) {return a * b;});
			} else if (consume('/')) {
				term();
				eval([](int a, int b) {return a / b;});
			} else
				return;
	}

	void add() {
		mul();
		for (;;)
			if (consume('+')) {
				mul();
				eval([](int a, int b) {return a + b;});
			} else if (consume('-')) {
				mul();
				eval([](int a, int b) {return a - b;});
			} else
				return;
	}

	void term() {
		if (consume('(')) {
			add();
			consume(')');
			return;
		}
		number();
	}


	int exec() {
		add();
		if (consume('=')) {
			return s.top();
		} else {
			fprintf(stderr,"ERROR: expected =, but got %c\n", c);
			exit(0);
		}
	}
};

int main() {
	for (int n = in(); n; n--) {
		calc c = calc();
		outl(c.exec());
	}
}


Measured memory_bytes: 2552
#define _USE_MATH_DEFINES
#include<cmath>
#include<cstdio>
#include<cstring>
#include<bitset>
#include<iostream>
#include<algorithm>
#include<string>
#include<utility>
#include<tuple>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<numeric>
#include<functional>
#include<iomanip>
#include<random>

#define IOS ios::sync_with_stdio(false),cin.tie(0)
#define REP(i,n) for(int i = 0;i < n;i++)
#define FOR(i,a,b) for(int i = a;i < b;i++)
#define MEM(a,b) memset(a,b,sizeof(a))
#define ALL(x) (x).begin(),(x).end()
#define LMAX 9223372036854775807
#define LMIN -9223372036854775808

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

struct UnionFind {
	vector<int> data;
	UnionFind(int size) : data(size, -1) {}
	void unionSet(int x, int y) {
		x = root(x), y = root(y);
		if (x != y) {
			if (data[y] < data[x])swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
	}
	bool findSet(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};

ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	int k = a % b;
	if (k == 1)return 1;
	if (k == 0)return b;
	int ans = gcd(b, k);
	return ans;
}
ll digisum(ll a) {
	int sum = 0;
	while (a) {
		sum += a % 10;
		a /= 10;
	}
	return sum;
}
ll countpow(ll a, ll b) {
	int ans = 0;
	if (b == 0)return -1;
	while (1) {
		if (a % b == 0) {
			a /= b;
			ans++;
		}
		else break;
	}
	return ans;
}
int to_num(char c) {
	if (c >= '0' && c <= '9')return (c - '0');
	else return -1;
}

int main() {
	IOS;
	int n, k;
	cin >> n >> k;
	ll ans = k * pow(k - 1, n - 1);
	cout << ans << endl;
}



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

int main(){
	int n;
	cin >> n;
	vector<int> ans(n);
	rep(i,n-1){
		int a;
		cin >> a;
		ans[a-1]++;
	}
	for(int x : ans){
		cout << x << endl;
	}
}

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

int main(){
    string s, t;
    cin >> s; cin >> t;

    bool flg = false;
    if(s == t) flg = true;
    else{
        for(int i=1; i<s.length(); i++){
            s = s.at(s.length()-1) + s.substr(0, s.length()-1);
            if(s == t){
                flg = true; break;
            }
        }  
    }
    if(flg) cout << "Yes" << endl;
    else    cout << "No" << endl;

    return 0;

}

Measured memory_bytes: 3620
# V: 頂点数
# g[v] = {(w, cost)}:
#     頂点vから遷移可能な頂点(w)とそのコスト(cost)
# r: 始点の頂点

from heapq import heappush, heappop
INF = 10**30
def dijkstra(N, G, s):
    dist = [INF] * N
    que = [(0, s)]
    dist[s] = 0
    while que:
        c, v = heappop(que)
        if dist[v] < c:
            continue
        for t, cost in G[v]:
            if dist[v] + cost < dist[t]:
                dist[t] = dist[v] + cost
                heappush(que, (dist[t], t))
    return dist

N = int(input())
G = [[] for _ in range(N)]
for _ in range(N-1):
    a, b, c = [int(i)-1 for i in input().split()]
    c += 1
    G[a].append((b, c))
    G[b].append((a, c))

Q, K = [int(i) for i in input().split()]
K -= 1

d = dijkstra(N, G, K)
# print(d)
for _ in range(Q):
    x, y = [int(i)-1 for i in input().split()]
    print(d[x]+d[y])

Measured memory_bytes: 46232
#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))

using namespace std;
typedef pair<llint, llint> P;

llint a, b, h, m;

int main(void)
{
	//ios::sync_with_stdio(0);
	//cin.tie(0);
	
	cin >> a >> b >> h >> m;
	m += 60*h;
	
	double ang = m/720.0 * M_PI*2, ang2 = (m%60)/60.0 * M_PI*2;
	
	double x = a*cos(ang), y = a*sin(ang);
	double x2 = b*cos(ang2), y2 = b*sin(ang2);
	
	double ans = (x-x2)*(x-x2) + (y-y2)*(y-y2);
	if(ans > 0) ans = sqrt(ans);
	
	printf("%.14f\n", ans);
	
	return 0;
}

Measured memory_bytes: 4128
#include <iostream>

int main() {
  int a;
  std::cin >> a;
  if (a % 2 == 0) {
    std::cout << 0.5 << std::endl;
  } else {
    std::cout << ((a + 1.0) / 2.0 / a) << std::endl;
  }
  return 0;
}

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

long long K;

//             to    , cost
vector<pair<long long, long long> > tree[100005];
set<long long> memo;

int main(){
	cin >> K;

	for(long long start = 1; start < K; start++){
		if(start % 10 != 9){
			tree[start].push_back(make_pair((start + 1)%K, 1));
		}
		tree[start].push_back(make_pair((start * 10)%K, 0));
	}

	//                     cost    , to
	priority_queue<pair<long long, long long>, 
		vector<pair<long long, long long> >, 
		greater<pair<long long, long long> > > Q;

	Q.push(make_pair(1, 1));

	while(!Q.empty()){
		long long cost = Q.top().first;
		long long cur = Q.top().second;
		Q.pop();
		if(memo.count(cur) != 0){
			continue;
		}
		memo.insert(cur);

		if(cur == 0){
			cout << cost << endl;
			return 0;
		}

		//cout << "cur " << cur  << " cost " << cost << endl;

		for(long long i = 0; i < tree[cur].size(); i++){
			long long next = tree[cur][i].first;
			long long ncost = cost + tree[cur][i].second;
			if(memo.count(next) != 0){
				continue;
			}
			Q.push(make_pair(ncost, next));
		}
	}
}


Measured memory_bytes: 12404
import sys
input = sys.stdin.readline

n = int(input())
l = list(map(int, input().split()))
count = 0
max_count = 0
for i in range(len(l)-1):
    if l[i] - l[i + 1] >= 0:
        count += 1
    else:
        count = 0
    max_count = max(count, max_count)

print(max_count)


Measured memory_bytes: 59632
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
 
int main() {
    int n, a, b;
    string s;
    cin >> n >> a >> b >> s;
    vector<bool> pass(n, false);
    int cnt_all = 0, rank_foreign = 1;
    rep(i, n) {
        if (s[i] == 'a') {
            if (cnt_all < a+b) {
                cnt_all++;
                pass[i] = true;
            }
        } else if (s[i] == 'b') {
            if (cnt_all < a+b && rank_foreign <= b) {
                cnt_all++;
                rank_foreign++;
                pass[i] = true;
            }
        }else continue;
    }
    rep(i, n) {
        if (pass[i]) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int a[3],n;
char s[N][3];
vector<char>ans;
int dfs(int now){
    if(a[0] < 0 || a[1] < 0 || a[2] < 0)
        return false;
    if(now == n + 1)
        return true;

    int x = s[now][0] - 'A';
    int y = s[now][1] - 'A';
    if(a[x] > a[y])
        swap(x,y);
    a[x]++,a[y]--;
    ans.push_back(x+'A');
    if(dfs(now+1)) return true;
    ans.pop_back();
    ans.push_back(y+'A');
    a[x]-=2,a[y]+=2;
    if(dfs(now+1)) return true;
    ans.pop_back();
    a[x]++,a[y]--;
    return false;
}
int main()
{
    ios::sync_with_stdio(false);
    cin >> n;
    for(int i=0;i<3;i++){
        cin >> a[i];
    }
    for(int i=1;i<=n;i++){
        cin >> s[i];
    }
    if(dfs(1)){
        cout << "Yes\n";
        for(auto i:ans)
            cout << i << '\n';
        return 0;
    }
    cout << "No\n";
    return 0;
}


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

#define F first
#define S second
typedef double db;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

ll gcd(ll x,ll y){
return y? gcd(y,x%y):x;
}

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

Measured memory_bytes: 256
function main(){
  var i = 0;
  while(true){
    var fieldInfo = input[i].split(' ');
    var width = fieldInfo[0] - 0;//toInt
    var height = fieldInfo[1] - 0;//toInt
 
    // 0 0が入力された
    if(!width && !height){
      break;
    }
 
    var start;
    var goal;
    var elem = [[],[],[],[],[]];
    for(var ei = 0;ei < 5; ei++){
      elem[ei].length = 0;
    }
     
    for(var y = 0; y < height; y++){
      i++;//1行進める
      for(var x = 0; x < width; x++){
        var c = input[i][x];
 
        switch(c){
        case 'S':
          start = new Pos(x, y);
          break;
        case 'G':
          goal = new Pos(x, y);
          break;
        case '.':
          break;
        default : // 入力値が正しいので、絶対に属性
          elem[c - 1].push(new Pos(x, y));
          break;
        }
      }
    }
 
     
    var bestElement = -1;
    var distance = Infinity;
     
    // 属性ごとにループ
    for (var startElem = 0; startElem < 5; startElem++) {
      // DPの初期化 DP[属性][同じ属性内の連番]
      var dp = [[],[],[],[],[]];
      for(var h = 0; h < 5; h++){
        var hLength = elem[h].length;
        dp[h].length = hLength;
        for(var hidx = 0; hidx < hLength; hidx++){
          dp[h][hidx] = Infinity;
        }
      }
       
      // 最初に選んだパチモンから次に捕まえられる属性番号
      var first = (startElem + 1) % 5;
 
      var firstLength = elem[first].length;
      for (var j = 0; j < firstLength; j++) {
        // s→e1を計算
        dp[first][j] = dist(start, elem[first][j]);
      }
       
      // s->1->2->3->4->g
      // なので、ループは間の-> * 3分まわす
      for (var e = 0; e < 3; e++) {
        // ex->e(x+1)
        var now = (first + e) % 5;
        var next = (now + 1) % 5;
        var nowLength = elem[now].length;
        var nextLength = elem[next].length;
        for (var j = 0; j < nowLength; j++) {
          for (var k = 0; k < nextLength; k++) {
            dp[next][k] = min(
              dp[next][k],
              dp[now][j] + 
                  dist(elem[now][j], elem[next][k]));
          }
        }
      }
       
      var last = (first + 3) % 5;
      var lastLength = elem[last].length;
      for (var j = 0; j < lastLength; j++) {
        // e4->g
        var d = dp[last][j] + 
                    dist(elem[last][j], goal);
         
        if (d < distance) {
          distance = d;
          bestElement = startElem + 1;
        }
         
      }
       
    }
     
    if (distance == Infinity) {
      console.log("NA");
    } else {
      console.log(bestElement + " " + distance);
    }
 
    i++;
  }
   
 
}
 
function dist(from, to){
  return Math.abs(from.x - to.x) + Math.abs(from.y - to.y)
}
 
function min(a1, a2){
  return a1 < a2 ? a1 : a2;
}
 
function Pos(a, b){
  this.x = a;
  this.y = b;
}
 
var
input = '';
 
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function(chunk) {
  input += chunk;
});
process.stdin.on('end', function() {
  input = input.split('\n');
  main();
});

Measured memory_bytes: 63480
#include <iostream>
#include <vector>
#include <algorithm>
#define N_MAX 100000

using namespace std;

int N, M;

vector<int> G[N_MAX];
bool used[N_MAX];
int dp[N_MAX];

vector<int> v;

void dfs(int u){
    if(used[u]) return;
    used[u] = true;
    for(int i = 0; i < G[u].size(); i++){
        dfs(G[u][i]);
    }
    v.push_back(u);
}

void tsort(){
    for(int i = 0; i < N; i++) dfs(i);
    reverse(v.begin(), v.end());
}

int main(){
    cin >> N >> M;
    for(int i = 0; i < M; i++){
        int x, y;
        cin >> x >> y;
        G[x-1].push_back(y-1);
    }
    tsort();
    reverse(v.begin(), v.end());
    int ans = 0;
    for(int i = 0; i < N; i++){
        for(int j = 0; j < G[v[i]].size(); j++){
            dp[v[i]] = max(dp[v[i]], dp[G[v[i]][j]]+1);
        }
        ans = max(ans, dp[v[i]]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 8056
t = "Yay!"
f = ":("

antennas = [int(input()) for _ in range(5)]
k = int(input())

if max(antennas) <= k:
    print(t)
else:
    flag = True
    for i in antennas:
        for j in antennas:
            if abs(i - j) >= k:
                flag = False
    if flag:
        print(t)
    else:
        print(f)

Measured memory_bytes: 3060
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n, *a = map(int, read().split())
a = sorted(aa - i for i, aa in enumerate(a))
print(sum(a[n // 2:]) - sum(a[:(n + 1) // 2]))


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

int gcd(int x, int y)
{
	if (y == 0) return x;
	return gcd(y, x%y);
}
signed main(void)
{
	int k;
	long long ans;
	cin >> k;

	ans = 0;
	rep(i, k) rep(j, k) rep(l, k)
	{
		ans += gcd(gcd(i, j), l);
	}
	cout << ans << endl;
	return 0;
}


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

typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 28;

// ====================================================================

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  if (a - b >= c)
    cout << 0 << endl;
  else
    cout << c - (a - b) << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
using namespace std;
typedef long long ll;
ll MOD = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)
int main() {
    string s;
    cin >> s;
    ll ans = 0;
    if ( s.length() == 1 ) {
        cout << stol(s) << endl;
        return 0;
    }
    rep(i, (1<<(s.length()-1))) {
        ll sum = 0;
        ll tmp_num = i;
        int l = 0;
        rep(j, s.length()-1) {
            if ( tmp_num & 1 ) {
                sum += stol( s.substr(l, j - l + 1) );
                l = j + 1;
            }
            if ( j == s.length() - 2 ) {
                sum += stol( s.substr(l, j - l + 2) );
            }
            tmp_num >>= 1;
        }
        ans += sum;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

static int dev2(int i)
{
	int devcnt = 0;

	while (i % 2 == 0) {
		devcnt++;
		if ((i = i / 2) == 0) {
			break;
		}
	}

	return devcnt;
}

int main(void)
{
	int n, i, devcnt, topcnt = 0;
	int topnum = 0;

	scanf("%d", &n);

	for (topnum = i = 1; i <= n; i++) {
		devcnt = dev2(i);
		if (devcnt > topcnt) {
			topcnt = devcnt;
			topnum = i;
		}
	}

	printf("%d", topnum);

	return 0;
}


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

using namespace std;


vector<int> parseInput(int n) {
  vector<int> V;
  int a;
  for(int i = 0; i < n; i++) {
    cin >> a;
    V.push_back(a);
  }

  return V;
}


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

  vector<int> A = parseInput(N);
  vector<int> B = parseInput(N);
  vector<int> C = parseInput(N - 1);

  int score = 0;
  int n;
  int prev = -1;
  for(int n : A) {
    if(n - prev == 1) {
      score += C[prev - 1];
    }
    score += B[n - 1];
    prev = n;
  }

  cout << score;

  return 0;
}


Measured memory_bytes: 256
Public Class Program
  Shared Sub Main()
    Dim n As Long = Long.Parse(Console.ReadLine())
    Dim ans As Long = 0
    For i As Long = Math.Floor(Math.Sqrt(n)) To 1 Step -1
      Dim m As Long = n \ i
      If m * i = n Then
        ans = m + (i - 2)
        Exit For
      End If
    Next
    Console.WriteLine(ans.ToString())
  End Sub
End Class

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

using namespace std;

int64_t q,h,s,d,n;

int main()
{
  cin >> q >> h >> s >> d >> n;

  int64_t r = min(4*q*n, min(2*h*n, min(s*n, d*(n/2) + (n%2) * min(4*q,min(2*h,s)))));
  cout << r << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define SIZE 200005
#define INF 1000000005LL
#define MOD 1000000007
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;
int main(){
    int H;
    int W;
    cin >> H;
    cin >> W;
    vector<char> word(W*H);
    for (int j=0; j<W*H;j++){
        cin >> word.at(j);
    }
    
    for (int i=0;i<W+2;i++){
        cout << "#";
    }
    cout << endl;
    for (int i=0;i<H;i++){
        cout << "#";
        for(int j=i*W;j<(i+1)*W;j++){
            cout << word.at(j) ;
        }
        cout << "#";
        cout << endl;
    }
    for (int i=0;i<W+2;i++){
        cout << "#";
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <vector>
#include<algorithm>
#include<iomanip>
using namespace std;



int main()
{
	double L, a ,b;

	cin >> L;

	a = (L / 3);
	b = L - 2 * a;

	cout << fixed << setprecision(12) << a  *a * a;




}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {

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


	public void run() {
		Scanner sc = new Scanner(System.in);
		ArrayList<Integer>a1 = new ArrayList<Integer>();
		ArrayList<Integer>a2 = new ArrayList<Integer>();
		int n=sc.nextInt();
		for(int i=0; i<n; i++) {
			int v = sc.nextInt();
			if(i%2==0) {
				a1.add(v);
			} else {
				a2.add(v);
			}
		}
		ArrayList<Integer> ans = new ArrayList<>();
		if(n%2==1) {
			Collections.reverse(a1);
			ans.addAll(a1);
			ans.addAll(a2);
		} else {
			Collections.reverse(a2);
			ans.addAll(a2);
			ans.addAll(a1);
		}
		for(int i=0; i<ans.size(); i++) {
			if(i>0)System.out.print(" ");
			System.out.print(ans.get(i));
		}
		System.out.println();
		sc.close();
	}
}


Measured memory_bytes: 97492
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<cmath>
using namespace std;

typedef pair<int, int> P;
typedef long long ll;
const int INF = 100000000;

ll gcd( ll a, ll b ){
    ll tmp;
    if( a < b ) { tmp = a; a = b; b = tmp; }
    if( b < 1 ) return -1;

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

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


int n;
int w[110];

int main(){

    cin >> n;
    for(int i = 1; i <= n; i++) cin >> w[i];

    int ans = INF;

    for(int i = 1; i < n; i++){
        int sum1 = 0, sum2 = 0;

        for(int j = 1; j <= i; j++){
            sum1 += w[j];
        }

        for(int j = i+1; j <= n; j++){
            sum2 += w[j];
        }

        ans = min(ans, abs(sum1 - sum2));
    }

    cout << ans << endl;

    return 0;
}

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

int main(){
int n;
cin >> n;
int a[n],b[n];
for(int i=0;i<n;i++){ scanf("%d", &a[i]), b[i] = a[i];}
sort(b,b+n);
for(int i=0;i<n;i++)
{
	if(a[i]!=b[n-1])
      cout << b[n-1] << endl;
  	else
      cout << b[n-2] << endl;
}
return 0;
}

Measured memory_bytes: 3200
#include<bits/stdc++.h>
using namespace std;
 
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL); 
 
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define in insert
#define ld long double
 
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  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, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...) 1
#endif
template<class T> ostream& operator<<(ostream &os, vector<T> V) {os << "[ "; for(auto v : V) os << v << " "; return os << "]";}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {return os << "(" << P.first << "," << P.second << ")";}
 
typedef long long int ll;
 
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
const ll mod =1e9+7;
const ll maxn =200001;
ll power(ll x, ll n) {
    ll res = 1;
    for (; n > 0; n >>= 1) {
    if (n & 1) res = (res * x) % mod;
    x = (x * x) % mod;
    }
    return res;
}

int main()
{
  
  IOS
  ll h,a;
  cin>>h>>a;
  cout<<(h+a-1)/a<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
using namespace std;

int main() {
  int n, k, ans=0;
  string s;
  cin >> n >> k >> s;
  for(int i = 0; i < n-1; i++){
    if(s[i] == s[i+1]) ans++;
  }
  ans = min(ans + 2 * k, n-1);
  cout << ans; 
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD =998244353;
const ll MAX = 1000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

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

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};


///////////////////////////



int main() {
	ll N;
	string s;
	cin >> N >> s;

	ll d = 0;
	rep(i, N) {
		if (s[i] == 'R') { d++; }
		else { d--; }
	}

	if (d > 0) { cout << "Yes"; }
	else { cout << "No"; }

	system("PAUSE");
}


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

int main()
{
    int N, M, total, tmp, pwr;
    cin >> N;
    M = N;
    total = 0;
    for (int i = 0; i < 8; i++)
    {
        pwr = pow(10, 8 - i);
        tmp = N / pwr;
        total = total + tmp;
        N = N - pwr * tmp;
    }
    total = total + N;
    if (M % total == 0)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
a=int(input())
b=int(input())
c=int(input())
x=int(input())
count=0
for i in range(a+1):
  for j in range(b+1):
    for k in range(c+1):
      if(500*i+100*j+50*k==x):
        count+=1
print(count)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
#define erep(i,n) for(int i = 0;i<=n;i++)
#define rep1(i,n) for(int i = 1;i<n;i++)
typedef long long ll;
#define vint vector<int>
#define vstring vector<string>
#define vll vector<ll>
#define vbool vector<bool>
#define INF 100000000

int main(){
  int64_t a,b;
  cin >> a >> b;
  if(b%2 == 0){
    cout << (int64_t)(pow(a/b,3)) + (int64_t)(pow((a+(b/2))/b,3)) << endl;
  }
  else{
    cout << (int64_t)(pow(a/b,3)) << endl;
  }
}



Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


def solve(N: int, K: int, p: "List[int]"):
    p = sorted(p)
    result = 0
    for k in range(K):
        result += p[k]
    print(result)
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    p = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, K, p)

if __name__ == '__main__':
    main()


Measured memory_bytes: 9196
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
int n;
cin>>n;
int a[n];
int x=n;
for(int i=0;i<n;i++)
{
cin>>a[i];}
sort(a,a+n);
for(int i=0;i<n;i++) 
if(a[i]==a[i+1])
x--;
cout<<x;
system ("pause");
return 0;
}

Measured memory_bytes: 504
import scala.collection.mutable.{ListBuffer, TreeSet}
import scala.io.StdIn
object Main extends App {
  

  val n = StdIn.readLine().trim.toInt
  
  val result = (0 until n).foldLeft(ListBuffer.empty[String], TreeSet.empty[String]){
    case ((acc, dict), _) =>
    val cmd = StdIn.readLine().split(' ')
    if(cmd(0) == "insert"){
      (acc, dict + cmd(1))
    } else {
      if(dict.contains(cmd(1))) {
        (acc += "yes", dict)
      } else {
        (acc += "no", dict)
      }
    }
  }
  println(result._1.mkString(f"%n"))

}


Measured memory_bytes: 478888
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007

int main() {

  int A,B,C,D,E,F;
  cin >> A >> B >> C >> D >> E >> F;

  vector<int> W(0),S(0);

  for(int i = 0;i <= F;i++) {
    for(int j = 0;j <= F;j++) {
      int w = 100*A*i+100*B*j;
      int s = C*i+D*j;
      if(w <= F) W.push_back(w);
      if(s <= F) S.push_back(s);
    }
  }

  int water,sugar;
  double con = 0;
  for(int i = 0;i < W.size();i++) {
    if(W.at(i) == 0) continue;
    for(int j = 0;j < S.size();j++) {
      int w = W.at(i),s = S.at(j);
      double c = 100*s / (double)(w+s);
      if(w+s <= F && c >= con && (w/100)*E >= s) {
        water = w;
        sugar = s;
        con = c;
      }
    }
  }

  cout << water+sugar << " " << sugar << endl;
}



Measured memory_bytes: 1400
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}


#[allow(dead_code)]
fn solve(c: char) -> &'static str {
    let v = ['a', 'o', 'i', 'u', 'e'];
    if v.contains(&c) {
        "vowel"
    } else {
        "consonant"
    }
}

fn main() {
    input!{
        c: chars
    }
    println!("{}", solve(c[0]));
}




Measured memory_bytes: 4352
#include<iostream>
#include<stdio.h>
using namespace std;
int main(){
  int a,b;
  char op;
  cin >> a >> op >> b;
  while(op!='?'){
    int c;
    if(op=='+') c=a+b;
    if(op=='-') c=a-b;
    if(op=='*') c=a*b;
    if(op=='/') c=a/b;
    cout << c << endl;
    cin >> a >> op >> b;
  }
  return 0;
}


Measured memory_bytes: 3108
n,t=map(int,input().split())
a=list(map(int,input().split()))
min=[float("inf")]*n
min[0]=a[0]
m=0
for i in range(1,n):
    if min[i-1]>a[i]:
        min[i]=a[i]
    else:
        min[i]=min[i-1]
for i in range(n):
    r=a[i]-min[i]
    m=max(r,m)
ans=0
for i in range(n):
    r=a[i]-min[i]
    if r==m:
        ans+=1
print(ans)


Measured memory_bytes: 86308
#include <stdio.h>
int main(){
    int a,b,c,in,i,t;

    a=b=c=0;

    for(i=0;i<10;i++){
        scanf("%d",&in);
        if(in>a){
            t=a;
            a=in;
            in =t;
        }
        if(in>b){
            t=b;
            b=in;
            in =t;
        }
        if(in>c){
            t=c;
            c=in;
            in =t;
        }
    }
    printf("%d\n%d\n%d\n",a,b,c);
    return 0;
}

Measured memory_bytes: 0
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
  input = input.split("\n");
  
  //var n = input[0];
  
  var n= parseInt(input[0], 10);
  
 
  //var d = 0;
  var a = [];
for (var f = 1; f <= n; f++) {
  var r= input[f];
     //  = d + 
  var r =r.split("");
  r.sort();  
 // console.log(r);
  var r1 = r.join("");
//console.log(r1); //'太郎二郎三郎花子'
  
  a[f] = r1;
 
 //a[f].sort();
 // console.log(a[f]);
} 
 
//console.log(n);
a.sort();
//console.log(a);
 var d = 1;
 var total = 0;
 var cnt =0;
 
for (var i = 0;i <= n;i++)
 // {if (a[i] ==  a[i+1])
 {if  (a[i] == a[i+1])
                {var d = d+1;
         //        console.log(i,d);
                }
                                else{
                                  //console.log(a[1],a[2]);
                                  var f = d;
                                    cnt += f * (f - 1) / 2;
                                    total = total + cnt;
                                    var d=1;
                                        
                                   //      console.log(cnt);
                                         var cnt = 0;
                                }
                  }
  
  
  
  
   console.log(total);
   }
     
 //*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
  Main(require("fs").readFileSync("/dev/stdin", "utf8"));    
  
 

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

// @@ !! LIM()

int main(/* int argc, char *argv[] */) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  ll N; cin >> N;
  vector<ll> A(N);
  for (ll i = 0; i < N; i++) cin >> A[i];
  sort(A.begin(), A.end());
  ll sum = 0;
  if (N % 2 == 0) {
    for (ll i = 0; i < N / 2; i++) sum -= A[i];
    for (ll i = N/2; i < N ; i++) sum += A[i];
    sum *= 2;
    sum += A[N/2 - 1] - A[N/2];
  }else {
    ll sum1 = 0;
    for (ll i = 0; i < N / 2; i++) sum1 -= A[i];
    for (ll i = N/2; i < N ; i++) sum1 += A[i];
    sum1 *= 2;
    sum1 -= A[N/2] + A[N/2 + 1];
    ll sum2 = 0;
    for (ll i = 0; i < N / 2 + 1; i++) sum2 -= A[i];
    for (ll i = N/2 + 1; i < N ; i++) sum2 += A[i];
    sum2 *= 2;
    sum2 += A[N/2 - 1] + A[N/2];
    sum = max(sum1, sum2);
  }
  cout << sum << endl;

  return 0;
}



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

int main()
{
  int count[5][4][11];
  for (int i=0; i<5; i++)
    for (int j=0; j<4; j++)
      for (int k=0; k<11; k++)
        count[i][j][k] = 0;
  int n;
  cin >> n;
  for (int i=0; i<n; i++) {
    int b, f, r, v;
    cin >> b >> f >> r >> v;
    count[b][f][r] += v;
  }
  for (int i=1; i<=4; i++) {
    for (int j=1; j<=3; j++) {
      for (int k=1; k<=10; k++) cout << ' ' << count[i][j][k];
      cout << endl;
    }
    if (i<4) {
      for (int c=0; c<20; c++) cout << '#';
      cout << endl;
    }
  }
  return 0;
}



Measured memory_bytes: 3092
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(void){
    int x[5];
    for(int i=0;i<5;i++) cin >> x[i];
    for(int i=0;i<5;i++){
        if(x[i] == 0){
            cout << i+1 << endl;
            return 0;
        }
    }
}


Measured memory_bytes: 3192
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using static System.Math;

class Program
{
    static void Main()
    {
        int n, m;
        string[] input = Console.ReadLine().Split();
        n = int.Parse(input[0]);
        m = int.Parse(input[1]);
        int[] a = new int[m];
        for (int i = 0; i < m; i++)
            a[i] = int.Parse(Console.ReadLine());
        long mod = (long)1e9 + 7;
        long[] dp = new long[n + 1];
        dp[0] = 1;
        int index = 0;
        for (int i = 1; i <= n; i++)
        {
            if (index < m && i == a[index])
            {
                index++;
                continue;
            }
            dp[i] += dp[i - 1];
            if (i > 1)
                dp[i] += dp[i - 2];
            dp[i] %= mod;
        }
        Console.WriteLine(dp[n]);
    }
}

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

const int INF = -1;

typedef pair<int, int> P;

char maze[1000][1000];
int H, W;

int d[1000][1000];

int dy[4] = {1, 0, -1, 0}, dx[4] = {0, 1, 0, -1};

void bfs(){
  queue<P> que;
  for(int i = 0; i < H; i++){
    for(int j = 0; j < W; j++){
      d[i][j] = INF;
      if(maze[i][j] == '#'){
        que.push(P(i, j));
        d[i][j] = 0;
      }
    }
  }
  while(que.size()){
    P p = que.front();
    que.pop();
    for(int i = 0; i < 4; i++){
      int ny = p.first + dy[i], nx = p.second + dx[i];
      if(0 <= ny && ny < H && 0 <= nx && nx < W && maze[ny][nx] != '#' && d[ny][nx] == INF){
        que.push(P(ny, nx));
        d[ny][nx] = d[p.first][p.second] + 1;
      }
    }
  }
}

void solve(){
  bfs();
  int res = -1;
  for(int i = 0; i < H; i++)
    for(int j = 0; j < W; j++) res = max(d[i][j], res);
  cout << res << endl;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> H >> W;
  for(int i = 0; i < H; i++)
    for(int j = 0; j < W; j++) cin >> maze[i][j];
  solve();
  return 0;
}
           

Measured memory_bytes: 13328
import sys
import numpy as np
n,m = map(int, input().split())
ask = np.array([list(map(int, input().split())) for i in range(m)],dtype=int)
# with open("input.txt") as f:
#     n, m = map(int, f.readline().split())
#     ask = np.array([list(map(int, f.readline().split()))
#                     for i in range(m)], dtype=int)

if n*(n-1)//2==m:
    print(n-1)
    sys.exit()

ask2 = ask[np.argsort(ask[:,1])]
delete = np.array([ask2[0,1]-1])
for a in ask2[1:]:
    if a[0] <= delete[-1]:
        pass
    else:
        delete = np.append(delete, a[1]-1)
print(len(delete))

Measured memory_bytes: 37896
#include <iostream>
#include <vector>
#include <chrono>
#include <random>
#include <cassert>
#include <bitset>

std::mt19937 rng((int) std::chrono::steady_clock::now().time_since_epoch().count());

int main() {
	std::ios_base::sync_with_stdio(false); std::cin.tie(NULL);
	int n, k;
	const int ms = 5050;
	std::cin >> n >> k;
	std::vector<std::bitset<ms>> pref(n+1);
	auto suf = pref;
	suf[n][0] = pref[0][0] = 1;
	std::vector<int> a(n);
	for(int i = 0; i < n; i++) {
		std::cin >> a[i];
	}
	for(int i = 0; i < n; i++) {
		pref[i+1] = pref[i] | (pref[i] << a[i]);
	}
	for(int i = n-1; i >= 0; i--) {
		suf[i] = suf[i+1] | (suf[i+1] << a[i]);
	}
	int ans = 0;
	for(int i = 0; i < n; i++) {
		for(int l = 0, r = k-1; l < k; l++) {
			r = std::min(k-1-l, r);
			while(r >= 0 && !suf[i+1][r]) r--;
			if(r == -1) break;
			if(pref[i][l] && suf[i+1][r] && l + r + a[i] >= k) {
				//std::cout << "for id " << i+1 << ", " << a[i] << " got (" << l << ", " << r << ")\n";
				ans++;
				break;
			}
		}
	}
	std::cout << n-ans << '\n';
}

Measured memory_bytes: 6400
#include<stdio.h>
int main(){
  int a,b,c,work;
  scanf("%d %d %d",&a,&b,&c);
  if(a > b){
    work = a;
    a = b;
    b = work;
  }
  if(a > c){
    work = a;
    a = c;
    c = work;
  }
  if(b > c){
    work = b;
    b = c ;
    c = work;
  }
  printf("%d %d %d\n",a,b,c);
  return 0;
}

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

int main(){
 int K;
 string S;
  cin>>K>>S;
  if(S.size()<=K){
    cout<<S<<endl;
  }
  
  else{
    for(int i=0;i<K;i++){
      cout<<S.at(i);
    }
    cout<<"..."<<endl;
  }
  
}


Measured memory_bytes: 3596
#include <iostream>
#include <set>
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#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 FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
#define D()
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 10000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素

int main(){
	ll N,ans=0;
	std::cin >> N;
	std::set<int> s;
	for ( int i = 0 ; i < N ; i++ ) {
		int x;
		std::cin >> x;
		s.insert(x);
	}
	std::cout << s.size() <<std::endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <functional>
#include <bitset>
#include <cmath>
#include <stack>
#include <iomanip>
#include <map>
#include <math.h>
typedef long long ll;
using namespace std;
const int MOD = 1000000007;

ll GCD(ll a, ll b) { return b ? GCD(b, a%b) : a; }

int main()
{
    int N,K;
    cin >> N >> K;
    int x[N];
    for(int i = 0; i < N; i++) cin >> x[i];
    ll ans = 1000000000000;
    for(int i = 0; i < N - K + 1; i++)
    {
        ll left = x[i];
        ll right = x[i + K - 1];
        ans = min(ans, min(abs(left), abs(right)) + right - left);
    }
    cout << ans << endl;
}

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

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

  vector<int> H(N);
  for(int i = 0;i < N;i++) cin >> H[i];

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

  int ans = 0;
  for(int i = 0;i < N;i++) {
    bool can = true;
    for(int nv:G[i]) {
      if(H[nv] >= H[i]) can = false;
    }
    if(can) ans++;
  }

  cout << ans << endl;

}


Measured memory_bytes: 8804
//Subhash Suman
//Date: 14/02/19 ; Day: Thursday ; Time: 13::31::15 
//Description : 

#include<bits/stdc++.h>
#define ll long long int
#define MAX INT_MAX
#define MIN INT_MIN
#define vi vector<int>
#define pii pair<int,int>
#define mii map<int,int>

using namespace std;
const int N = 22;
int n;
bool arr[N][N];
int dp[N][1<<N];
const ll mod = 1e9 + 7; 

bool check(const int i,const int mask){
    int n_mask = 1<<i;
    n_mask = n_mask&mask;
    if(n_mask>0){
        return 1;
    }
    return 0;
}

void seti(const int i,int &mask){
    int n_mask = 1<<i;
    mask = n_mask^mask;
}

ll func(int i,int mask){
    if(i==n){
        return 1LL;
    } 
    if (dp[i][mask]==-1){
        ll ans = 0;
        for(int j = 0; j < n; j++){
            if(arr[i][j]==1 && check(j,mask)){
                seti(j,mask);
                ans= (ans + func(i+1,mask))%mod;
                seti(j,mask);
            }
        }
        dp[i][mask] = ans;
        return ans;
    }
    else{
        return dp[i][mask];
    }

}

int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
    cin>>n;
    for(int i = 0; i < n+1; i++){
        for(int j = 0; j < (1<<(n+1)); j++){
            dp[i][j] = -1;
        }
    }
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            cin>>arr[i][j];
        }
    }
    int mask = 1<<(n+1);
    mask -= 1;
    cout<<func(0,mask)<<'\n';
    return 0;
}

Measured memory_bytes: 360704
while n = gets.chomp.to_i
  break if n == 0

  a = []

  n.times do
    a << gets.chomp.split.map(&:to_i)
  end

  a.each do |i|
    i << i.inject { |sum, n | sum + n }
  end

  a = a.transpose

  a.each do |i|
    i << i.inject { |sum, n | sum + n }
  end

  a = a.transpose

  a.each do |i|
    puts i.map { |item| sprintf('%5d', item) }.join()
  end

end

Measured memory_bytes: 8860
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <algorithm>
#include <math.h>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#define ll long long
#define vi vector<ll>
#define vs vector<string>
#define fr(i, k, n) for (ll i = k; i < n; i++)
#define rep(i, n) fr(i, 0, n)
#define alll(v) v.begin(), v.end()
#define mp(a, b) make_pair(a, b)
#define rdd(a) ll a; cin >> a
#define rrd rdd(a); rep(i, a)
//min({a,b,c,d})などの記法
using namespace std;
template <class X> void pr(X x) { cout << x << endl; }
template <class X> void prr(X x) { for (auto it : x) { cout << it << endl; } }

int func(int x){
    return x*x+30;
}
int main() {
    rdd(n);
    vi v(n);
    rep(i, n){
        cin>>v[i];
    }
    int sum =0;
    rep(i, n){
        if (i+1==v[v[i]-1]) {
            sum++;
        }
    }
    pr(sum/2);
    cout<<endl;
    return 0;
}


Measured memory_bytes: 1024