akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
using Int = long long;
const char newl = '\n';

//INSERT ABOVE HERE
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(0);

  int D;
  cin>>D;

  const int A = 26;
  vector<int> cs(A+1);
  for(int j=1;j<=A;j++) cin>>cs[j];

  vector s(D+1,vector<int>(A+1));
  for(int i=1;i<=D;i++)
    for(int j=1;j<=A;j++)
      cin>>s[i][j];

  vector<int> ts(D+1);
  for(int i=1;i<=D;i++) ts[i]=(i%A)+1;

  auto calcScore=[&]()->int{
    int res=0;
    vector<int> ls(A+1,0);
    for(int i=1;i<=D;i++){
      res+=s[i][ts[i]];
      ls[ts[i]]=i;
      for(int j=1;j<=A;j++)
        res-=cs[j]*(i-ls[j]);
    }
    return res;
  };

  cerr<<calcScore()<<newl;
  for(int i=1;i<=D;i++) cout<<ts[i]<<newl;
  return 0;
}


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

int main() {
  int n;
  cin >> n;
  vector<string> s(n);
  for (int i = 0; i < n; i = i + 1) {
    cin >> s.at(i);
  }  
  int m;
  cin >> m;
  vector<string> t(m);
  for (int i = 0; i < m; i = i + 1) {
    cin >> t.at(i);
  }
  
  vector<int> count(n, 1);
  
  for (int i = 0; i < n; i = i + 1) {
    for (int j = 0; j < n; j = j + 1) {
      if (s.at(i) == s.at(j) && i != j) {
        count.at(i) = count.at(i) + 1;
      }
    }
    for (int j = 0; j < m; j = j + 1) {
      if (s.at(i) == t.at(j)) {
        count.at(i) = count.at(i) - 1;
      }
    }
    //cout << count.at(i) << endl;
  }
  
  int max = -100000;
  for (int i = 0; i < n; i = i + 1) {
    if (max < count.at(i)) {
      max = count.at(i);
    }
  }
  
  if (max <= 0) {
    max = 0;
    cout << max << endl;
  } else {
    cout << max << endl;
  }
}

Measured memory_bytes: 256
def e(x,y):
 A[y][x]='0'
 for d in range(-3,4):
  0<=x+d<8and A[y][x+d]=='1'and e(x+d,y)
  0<=y+d<8and A[y+d][x]=='1'and e(x,y+d)
for i in range(int(input())):
 print(f'Data {i+1}:')
 input()
 A=[list(input())for _ in[0]*8]
 e(int(input())-1,int(input())-1)
 for r in A:print(*r,sep='')


Measured memory_bytes: 5628
#include <bits/stdc++.h>
using namespace std;
double solve(double a)
{
    return (a + 1) / 2;
}

int main()
{
  int n, k;
  cin >> n >> k;
  vector<double> p(n);
  for (int i = 0; i < n; i++) cin >> p[i];
  double tmp = 0;
  for (int j = 0; j < k; j++) tmp += solve(p[j]);
  double ans=tmp;
  for (int i = 1; i <= n - k; i++) {
    tmp += solve(p[i + k-1]);
    tmp -= solve(p[i - 1]);
    ans=max(ans,tmp);
  }
  cout << fixed << setprecision(10) << ans << endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;

int main() {
  int H,W;
  cin >> H >> W;
  vector<vector<int>> c(10,vector<int>(10));
  for (int i=0;i<10;i++){
    for (int j=0;j<10;j++){
      cin >> c[i][j];
    }
  }
  vector<int> cost(10,100000);
  cost[1]=0;
  priority_queue<P,vector<P>,greater<P>> pq;
  vector<bool> finished(10);
  finished[1]=true;
  pq.push(P(0,1));
  while(!pq.empty()){
    P p=pq.top();
    pq.pop();
    int v=p.second;
    if (cost[v]<p.first){
      continue;
    }
    for (int i=0;i<10;i++){
      if (cost[i]>c[i][v]+cost[v]){
        cost[i]=c[i][v]+cost[v];
        pq.push(P(cost[i],i));
      }
    }
  }
  int ans=0;
  for (int i=0;i<H;i++){
    for (int j=0;j<W;j++){
      int x;
      cin >> x;
      if (x!=-1){
        ans+=cost[x];
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import sys

stdin = sys.stdin

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

def divisor(n):
    ass = []
    for i in range(1, int(n**0.5)+1):
        if n%i == 0:
            ass.append(i)
            ass.append(n//i)
    return ass

n = ni()
p = divisor(n)
s = set()
for k in p:
    nk = n // k
    for t in divisor(nk - 1):
        s.add(t*k)
ans = 0
s.remove(1)
s.add(n)
for t in s:
    m = n
    while m % t == 0:
        m //= t
    if m % t == 1:
        ans += 1
print(ans)


Measured memory_bytes: 43996
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <numeric>
using namespace std;

int GCD(int x, int y) {
    return x ? GCD(y % x, x) : y;
}

int main(){
    int N,X,C;
    cin >> N >> X;
    int A[N],B[N];
    for (int i = 0;i<N;i++){
        cin >> A[i];
        B[i] = abs(A[i] - X);
        if(i ==0){
            C = B[i];
        }  else  {
            C = GCD(C, B[i]);
        }
    }

cout << C << endl;

}

Measured memory_bytes: 1024
n =  [int(input()) for x in range(5)]
minNum = 10
array = 0
for i in range(len(n)):
    num = n[i] % 10
    if((num <= minNum) and (num != 0)):
        minNum = num
        array = i
        
numList = []
a = n[array]
n[array] = 0

for x in n:
    k = ((x + 9) // 10) * 10
    numList.append(k)  
print(sum(numList) + a)

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

sys.setrecursionlimit(10**7)
INF = 10**10

N = 2019
cnt = [0] * N
#print (cnt)

def dec(cnt,s):
    new = [0] * N
    for n in range(N):
        idx = (10 * n + s) % N
        new[idx] += cnt[n]
    return new


S = input()[:-1]
ans = 0
for s in S:
    s = int(s)
    cnt = dec(cnt,s)
    cnt[s] += 1
    ans += cnt[0]
    # if cnt[0] != 0:
    #     print (cnt[0])
print (ans)

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

#define ll long long
#define ull unsigned long long 
#define endl '\n'

int main(){
    int n, m;
    cin >> n >> m;
    n+=2, m+=2;
    char a[n][m];
    for(int i=1; i<=n-2; ++i)
        for(int j=1; j<=m-2; ++j)
            cin >> a[i][j];
    
    for(int i=0; i<n; ++i){
        for(int j=0; j<m; ++j){
            if(i==0 || j==0 || j==m-1 || i==n-1)
                cout << "#";
            else
                cout << a[i][j];
        }
        cout << endl;
    }
}


Measured memory_bytes: 3564
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <complex>
using namespace std;

typedef long long ll;
typedef pair<int,int> P;

#define all(c) (c).begin(),(c).end()
#define pb push_back
#define mp make_pair
#define ERASE(v,i) (v).erase(remove(all(v),i),(v).end())
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define each(it,c) for(typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define debug(x) cerr<<#x<<" = "<<(x)<<endl;
#define LINE cerr<<"LINE: "<<__LINE__<<endl;

inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
template<class T> void preview(T a,T b){for(T it=a;it!=b;++it)cerr<<*it<<" ";cerr<<endl;}

const int INF = 100000000;
const double PI = acos(-1.0), EPS = 1e-10;

int main() {
	map<int, int> m;
	vector<int> points;
	for(int no, ac; scanf(" %d,%d", &no, &ac), no || ac;) {
		m[no] = ac;
		points.pb(ac);
	}
	sort(points.rbegin(), points.rend());
	points.erase(unique(all(points)), points.end());

	for(int no; ~scanf(" %d", &no);) {
		int p = m[no];
		cout << (find(all(points), p) - points.begin()) + 1 << endl;
	}
	
	return 0;
}

Measured memory_bytes: 0
///////////////////////////////////////////////////////////////////////////////

#include <bits/stdc++.h>

using namespace std;

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

#define rep(i,n) for(ll i=0LL; i<n; ++i)
#define srep(i,s,n) for(ll i=s; i<n; ++i)
#define rrep(i,n) for(ll i=n-1LL; i>=0LL; --i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()

typedef long long ll;

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

int main()
{
    ll n; cin >> n;

    ll ans = 0;

    srep (val, 1, n+1) {
        for (ll lval = val; lval <= n; lval += val) {
            ans += lval;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i = 0;i<((ll)(n));i++)
#define reg(i,a,b) for(ll i = ((ll)(a));i<=((ll)(b));i++)
#define irep(i,n) for(ll i = ((ll)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(ll i = ((ll)(b));i>=((ll)(a));i--)
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

/*
*/

ll f(ll x){
	return x*(x+1)/2;
}

bool ok=true;
ll n,k;

int main(void){
	cin>>n>>k;
	if(f(k+2*n-1)-f(k-1)>f(k+3*n-1)-f(k+2*n-1))ok=false;
	// cerr<<f(k+2*n-1)-f(k-1)<<","<<f(k+3*n-1)-f(k+2*n-1)<<endl;
	if(!ok){
		cout<<-1<<endl;
		return 0;
	}
	if(n%2==0){
		rep(i,n/2)cout<<k+i<<" "<<k+2*n-2-i*2<<" "<<k+2*n+(n/2-i)-1<<endl;
		rep(i,n/2)cout<<k+i+n/2<<" "<<k+2*n-1-i*2<<" "<<k+2*n+(n-i)-1<<endl;
	}else{
		rep(i,n/2)cout<<k+i<<" "<<k+2*n-2-i*2<<" "<<k+2*n+(n/2-i)-1<<endl;
		rep(i,n/2+1)cout<<k+i+n/2<<" "<<k+2*n-1-i*2<<" "<<k+2*n+(n-i)-1<<endl;
	}
	return 0;
}

Measured memory_bytes: 2304
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>
#include <math.h>
#include <utility>
#include <vector>
#include <map>
#include <unordered_map>
#include <cstdlib>
#define div1 1000000007
const long long INF = 1LL << 60;
using namespace std;
using ll = long long;
// a>b -> a==b;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
// a<b -> a==b;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

template <class T> void swap(T& a, T& b) { T t = std::move(a); a = std::move(b); b = std::move(t); }

// nのk乗をmで割った余り(n^k(mod m))を求める
ll pow_mod(ll n, ll k, ll m){
    if(k == 0){
        return 1;
    }
    else if(k % 2 == 1){
        return pow_mod(n, k-1, m) * n % m;
    }
    else{
        ll t = pow_mod(n, k/2, m);
        return t * t % m;
    }
}

int main(void)
{
    ll X, Y, sum, dif, judge=1, a, n, i, ans;

    cin >> X >> Y;

    sum = X+Y;
    dif = abs(X-Y);

    if(sum%3!=0){
        judge = 0;
    }
    else if(sum%2==0){
        if(dif%2!=0 || dif>sum/3){
            judge = 0;
        }
    }
    else if(sum%2==1){
        if(dif%2!=1 || dif>sum/3){
            judge = 0;
        }
    }

    if(judge==0){
        cout << 0 << endl;
    }
    else{
        // bCaを求める
        a = (2*X-Y)/3;
        n = (X+Y)/3;

        X = 1; Y = 1;
        
        for(i=n-a+1; i<=n; i++){
            X *= i;
            X %= div1;
        }
        for(i=1; i<=a; i++){
            Y *= i;
            Y %= div1;
        }
        
        sum = pow_mod(Y,div1-2,div1);

        ans = (X*sum) % div1;

        if(ans<0) ans += div1;

        cout << ans << endl;
    }  

    return 0;
}

Measured memory_bytes: 256
from bisect import bisect_right, bisect_left
from collections import Counter, deque
from functools import lru_cache, reduce
from heapq import heappop, heappush
from itertools import groupby, permutations, combinations, product
from sys import stdin, stderr


# 最大公約数（ユークリッドの互除法）
# Python3.5 で math.gcd()が追加され、
# AtCoder環境と最新環境でパッケージが分かれてしまったので、自分で書いておく
def gcd(x, y):
    return x if y == 0 else gcd(y, x % y)


# 拡張ユークリッド互除法
# 正整数x, y について、a*x + b*y == gcd(x,y)なるa,bを返す。
# 特に、互いに素なるx, yについては a*x + b*y == 1 となる a, b。
def exgcd(x, y):
    if y == 0:
        return 1, 0
    a, b = exgcd(y, x % y)
    return b, a - (x // y) * b


# 最小公倍数
def lcm(x, y):
    m = gcd(x, y)
    return (x // m) * (y // m)


def mod_fac(n, r):
    mod = 10 ** 9 + 7
    res = 1
    for i in range(r):
        res = res * (n - i) % mod
    return res


def mod_pow(x, n):
    res = 1
    mod = 10**9 + 7
    while n > 0:
        if n % 2 == 1:
            res *= x
            res %= mod
        x *= x
        x %= mod
        n //= 2
    return res


def mod_comb(n, r):
    r = min(r, n-r)
    mod = 10 ** 9 + 7
    res = mod_fac(n, r)
    return res * mod_pow(mod_fac(r, r), mod - 2) % mod


def main():
    mod = 10**9 + 7
    n, a, b = [int(x) for x in input().split()]
    ret = mod_pow(2, n) - 1
    # print(ret, mod_comb(n,a), mod_comb(n, b))
    ret -= mod_comb(n, a)
    if ret < 0:
        ret += mod
    ret -= mod_comb(n, b)
    if ret < 0:
        ret += mod
    return ret


if __name__ == "__main__":
    print(main())

Measured memory_bytes: 3572
import Control.Applicative
import Control.Monad

dot [x] [y] = x * y
dot (x:xs) (y:ys) = x * y + dot xs ys

main = do
    n:m:_ <- map read.words <$> getLine ::IO[Int]
    a <- replicateM n ( map read.words <$> getLine ) ::IO [[Int]]
    b <- replicateM m ( read <$> getLine ) ::IO[Int]
    putStr $ concat (map ((++"\n").show) [ ai `dot` b | ai <- a ])

Measured memory_bytes: 7488
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
using ll = long long;
typedef pair<int, int> P;
ll Mod = 1000000007;
int main() {
  int N;
  cin >> N;
  ll X;
  cin >> X;
  ll x[N];
  vector<ll> vec;
  for (int i = 0; i < N; i++) {
    cin >> x[i];
  }
  for (int i = 0; i < N; i++) {
    vec.push_back(abs(x[i] - X));
  }
  for (int i = 1; i < N; i++) {
    vec.push_back(abs(x[i] - x[i-1]));
  }

  ll ans = vec[0];
  for (int i = 0; i < (int)vec.size(); i++) {
    ans = __gcd(ans,vec[i]);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 6148
import itertools

N = int(input())
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))

LUT = list(itertools.permutations(range(1, N + 1)))

Pi, Qi = -1, -1
for i in range(len(LUT)):
    if LUT[i] == P:
        Pi = i
    if LUT[i] == Q:
        Qi = i

print(abs(Qi - Pi))


Measured memory_bytes: 8052
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;

namespace MyProject
{
    class Program
    {
        static void Main(string[] args)
        {
#if Local
            var sw = new Stopwatch();
            sw.Start();
            Console.SetIn(new StreamReader("input.in"));
#endif

            var solver = new Solver();
            solver.Solve();
#if Local
            Console.WriteLine($"{sw.ElapsedMilliseconds}ms");
#endif
        }
    }

    class Solver
    {
        public void Solve()
        {
            var A = Console.ReadLine();
            var B = Console.ReadLine();
            var list = new string[] { "1", "2", "3" };

            var answer = list.Where(elem => elem != A && elem != B).FirstOrDefault();
            Console.WriteLine(answer);
        }
    }
}


Measured memory_bytes: 11220
#include <iostream>
#include <string>
#include <vector>

int main() {
  std::string n;
  int k;
  std::cin >> n >> k;
  int len = n.size();

  std::vector<int[5][2]> dp(len + 1); // dp[何文字目][非 0 何個][n より小か]
  dp[0][0][0] = 1;
  for (int i = 0; i < len; i += 1) { // 何文字目
    int d = n[i] - '0';              // i 文字目の数字

    // 配るDP
    for (int j = 0; j <= k; j += 1) {     // 非 0 何個
      for (int s = 0; s <= 1; s += 1) {   // n より小か
        for (int c = 0; c <= 9; c += 1) { // 遷移に使う数字
          if (!s && c > d) // n を超過する場合遷移しない
            continue;
          dp[i + 1][j + (c != 0)][s || (c < d)] += dp[i][j][s];
        }
      }
    }
  }

  std::cout << dp[len][k][0] + dp[len][k][1] << std::endl;
}

Measured memory_bytes: 256
// Inshallah, Boys played well !!

#include <bits/stdc++.h>
using namespace std;
#define author Saurabh
#define pii pair<int,int> 
#define vpi vector<pair<int,int> >
#define pb push_back
#define mk make_pair
#define fi first
#define se second
#define ff(i,s,e) for(int i=s;i<=e;i++)
#define fb(i,e,s) for(int i=e;i>=s;i--)
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define test int t;scanf("%d",&t);while(t--)
#define setp(x) setprecision(x)
int main(){
    fast;
    float n;
    cin >> n;
    float p=2.0;
    float pi=3.141592653589793238;
    n=pi*p*n;
    cout << n;
}



Measured memory_bytes: 3804
use std::io::prelude::*;

fn input<T: std::str::FromStr>() -> T {
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

#[allow(dead_code)]
fn with_stdout_lock<F: FnOnce(std::io::BufWriter<std::io::StdoutLock>)>(f: F) {
    let out = std::io::stdout();
    let w = std::io::BufWriter::new(out.lock());
    f(w);
}

#[allow(unused_macros)]
macro_rules! debug {
    ($var:expr) => {
        match &$var { v => eprintln!(concat!(stringify!($var), "={:?}"), v) }
    };
    ($var:expr, $($vars:expr),*) => {
        match &$var { v => eprint!(concat!(stringify!($var), "={:?} "), v) }
        debug!($($vars),*);
    };
}

fn main() {
    let n: usize = input();
    let a: Vec<i32> = (0..n).map(|_| input()).collect();

    println!("{}", a.iter().map(|&a| a - 1).sum::<i32>())
}


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

#define debug(x) cout <<"DEBUG"<<" "<<#x<<":"<<x<<'\n'

//↓0-indexか1-indexでn回繰り返し
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   //0-index昇順
#define rep1(i,n) for(int i = 1; i <= ((int)(n)); i++) //1-index昇順
#define rrep(i,n) for(int i = ((int)(n)-1); i >= 0; i--)  //0-index降順
#define rrep1(i,n) for(int i = ((int)(n)); i >= 1; i--)   //1-index降順
//rep2 -> 第二引数 m から n 回繰り返し ex) m=5 n=3 なら i=5,i=6,i=7 まで
#define rep2(i,m,n) for(int i = ((int)(m)); i < ((int)(n))+((int)(m)); i++)
#define SIZE(x) ((int)((x).size()))
#define all(x) (x).begin(),(x).end()
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vii; //2次元配列
typedef vector<ll> vll;
typedef vector<string> vs;
template<class T,class U> inline bool chmax(T &a, const U &b){if(a<b){a=b;return 1;}return 0;}
template<class T,class U> inline bool chmin(T &a, const U &b){if(a>b){a=b;return 1;}return 0;}

/* 円周率は M_PI を使おうね */
const ll infll = (1LL<<62)-1;
const int inf = (1<<30)-1;

/*FUNCs=================================================*/


/*MAIN==================================================*/
signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化
    //cout << fixed << setprecision(10);

    int n, x; cin >> n >> x;
    vi a(n);
    ll cnt = 0;
    rep(i,n) {
        cin >> a[i];
        if(a[i] > x) {
            cnt += a[i] - x;
            a[i] = x;
        } 
        //debug(a[i]);///
    }
    //debug(cnt);
    for(int i = 0; i < n-1; ++i) {
        if(a[i]+a[i+1] > x) {
            cnt += (a[i]+a[i+1]-x);
            a[i+1] -= (a[i]+a[i+1]-x);
        }
    }
    cout << cnt << '\n';
}

Measured memory_bytes: 640
def swap(x, y):
    tmp = x
    x = y
    y = tmp

def gcm(x, y):
    if x < y:
        swap(x, y)
    while y > 0:
        r = x % y
        x = y
        y = r
    return x

if __name__ == '__main__':
    x, y = list(map(int, input().split()))
    n = gcm(x, y)
    print(n)

Measured memory_bytes: 7696
#include <bits/stdc++.h>
using namespace std;
 
typedef long long LL;
 
int main() {
    LL n;
    cin>>n;
 
    vector<pair<LL, int> > dvs;//配对<质数, 幂次>
 
    //质因数分解
    for (LL i=2; i*i<=n; i++) {
        if (0==n%i) {
            dvs.push_back(make_pair(i, 0));
            while (0==n%i) {
                dvs.back().second++;
                n /= i;
            }
        }
    }
    if (n>1) {
        dvs.push_back(make_pair(n, 1));
    }
 
    //遍历
    int ans = 0;
    for (pair<LL, int> &p : dvs) {
        int i=sqrt(p.second*2);
        if (i*(i+1)>p.second*2) {
            i--;
        }
        ans += i;
    }
 
    cout << ans << endl;
 
    return 0;
}


Measured memory_bytes: 3720
#include<stdio.h>
#include<stdlib.h>

int compare_int(const void *a,const void *b){
	return *(long long*)a-*(long long*)b;
}

struct mis{
	long long a;
	int b;
};

int main(){
	int n,m,i,j;
	long long ans=0;
	struct mis ab[100000];
	scanf("%d%d",&n,&m);
	for(i=0;i<n;i++)scanf("%lld%d",&ab[i].a,&ab[i].b);
	qsort(ab,n,sizeof(struct mis),compare_int);
	j=m;
	for(i=0;j>0;i++){
		if(j>=ab[i].b){
			ans+=ab[i].a*ab[i].b;
			j-=ab[i].b;
		}else {
			ans+=ab[i].a*j;
			j=0;
		}
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 3324
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
#define ll long long
#define ld long double
#define mp make_pair
#define pb push_back
#define fo(i,n) for(ll i=0;i<n;i++)
#define fo1(i,n) for(ll i=1;i<=n;i++)
#define loop(i,a,b)for(ll i=a;i<=b;i++)
#define loopr(i,a,b)for(ll i=b;i>=a;i--)
#define vll vector<ll> 
#define vvl vector<vll>
#define pii pair<ll,ll>
#define F first
#define S second
#define endl "\n"
#define M 1000000007
ll max(ll a,ll b){if (a>b) return a; else return b;}

ll po(ll x, ll y){
    if(y==0)
    return 1;
    if(y%2){
        return ((x)*(po(x,y/2)%M)*(po(x,y/2)%M))%M;
    }
   return ((po(x,y/2)%M)*(po(x,y/2)%M))%M;
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll t=1;
    //cin>>t;
    while(t--){
        ll n,d;
        cin>>n>>d;
        vll x(n);
        vll y(n);
        fo(i,n)
        cin>>x[i]>>y[i];
        ll an=0;
        fo(i,n){
            ll dis=x[i]*x[i] + y[i]*y[i];
            if(dis<=d*d)
            an++;
        }
        cout<<an<<endl;
    }
return 0;
}

Measured memory_bytes: 6312
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long int lli;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    string s;
    cin>>s;
    if(s=="ABC") cout<<"ARC";
    else         cout<<"ABC";
    return 0;
}

Measured memory_bytes: 3652
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <tuple>
#include <complex>
#include <cassert>
#include <exception>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<P> vp;
#define rep(i,a,n) for(ll i = (a);i < (n);i++)
#define per(i,a,n) for(ll i = (a);i > (n);i--)
#define lep(i,a,n) for(ll i = (a);i <= (n);i++)
#define pel(i,a,n) for(ll i = (a);i >= (n);i--)
#define clr(a,b) memset((a),(b),sizeof(a))
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define sz size()
#define endl "\n"
#define print(X) cout << (X) << "\n"
#define input(X) getline(cin,X)
static const int INF = 1e+9+7;
static const ll INFL = 1e+18+7;
ll n,m,l;
int p;
string s,t;
ll d[200010],dp[300][300];
char field[200][200];

vi func(){
  vi vec(1000);
  rep(i,1,1000){
    vec[i-1] += i;
    vec[i] = vec[i-1];
  }
  return vec;
}

int main(){
  vi vec = func();
  cin >> n >> m;
  int a = 0,b = 0;
  ll ans = 0;
  rep(i,0,999){
    rep(j,0,999){
      if(vec[i]-n == vec[j]-m){
        ans = vec[i]-n;
      }
    }
  }
  print(ans);
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
int a,b,c;
  int an=0;
  
  scanf("%d %d %d",&a,&b,&c);
if(a==b&&b==c){printf("1\n");}
  else if((a==b&&b!=c)||(a!=c&&b==c)||(a==c&&b!=c)){printf("2\n");}
  else{printf("3\n");}
  //printf("%d\n",an);
}


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

int main()
{
    int n,a;
    cin>>n>>a;
    
    for(int i=0;i<=a;i++)
    {
        if((n-i)%500==0)
            return cout<<"Yes",0;
    }
    cout<<"No";
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
using namespace std;

static const int mod = 1000000007;

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

int main() {
  int n;
  scanf("%d", &n);
  vector<long long> a(n), b(n);
  for (int i = 0; i < n; i++)
    scanf("%lld %lld", &a[i], &b[i]);

  int bothZeroCount = 0, aZeroCount = 0, bZeroCount = 0;
  map<pair<long long, long long>, int> pos, neg;
  for (int i = 0; i < n; i++)
    if (a[i] == 0 && b[i] == 0)
      bothZeroCount++;
    else if (a[i] == 0) {
      aZeroCount++;
    }
    else if (b[i] == 0) {
      bZeroCount++;
    }
    else if ((a[i] < 0 && b[i] > 0) || (a[i] > 0 && b[i] < 0)) {
      long long u = abs(a[i]), v = abs(b[i]);
      long long d = gcd(u, v);
      u /= d, v /= d;

      pair<long long, long long> p = {u, v};
      if (!neg.count(p))
        neg.insert({p, 1});
      else
        neg[p]++;
    }
    else {
      long long u = a[i], v = b[i];
      long long d = gcd(u, v);
      u /= d, v /= d;

      pair<long long, long long> p = {u, v};
      if (!pos.count(p))
        pos.insert({p, 1});
      else
        pos[p]++;
    }

  vector<int> two(n + 1);
  two[0] = 1;
  for (int i = 1; i < two.size(); i++)
    two[i] = two[i - 1] * 2 % mod;

  long long ans = 1;
  for (auto p : pos) {
    pair<long long, long long> q1 = p.first;
    pair<long long, long long> q2 = {q1.second, q1.first};

    if (neg.count(q2)) {
      long long t = ((two[p.second] + two[neg[q2]]) % mod + mod - 1) % mod;
      ans = ans * t % mod;
    }
    else {
      ans = ans * two[p.second] % mod;
    }
  }

  for (auto p : neg) {
    pair<long long, long long> q1 = p.first;
    pair<long long, long long> q2 = {q1.second, q1.first};
    
    if (!pos.count(q2))
      ans = ans * two[p.second] % mod;
  }

  if (aZeroCount > 0 && bZeroCount > 0) {
    long long t = ((two[aZeroCount] + two[bZeroCount]) % mod + mod - 1) % mod;
    ans = ans * t % mod;
  }
  else if (aZeroCount) {
    ans = ans * two[aZeroCount] % mod;
  }
  else if (bZeroCount) {
    ans = ans * two[bZeroCount] % mod;
  }

  ans = (ans + bothZeroCount + mod - 1) % mod;
  printf("%lld\n", ans);

  return 0;
}

Measured memory_bytes: 19624
#include "bits/stdc++.h"
using namespace std;
#define REP(i, n) for(ll i = 0;i < n;i++)
#define ll long long
#define MOD 1000000007
using vi = vector<ll>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける

ll n,k,x,y;

int main(){
  ll ans=0;
  cin >> n ;
  string s;cin>>s;

  int flag=n%2;
  REP(i,n/2){
    if (s[i]!=s[i+n/2])flag=1;
  }
  if (flag==0){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
Amat = [list(map(int, input().split())) for _ in range(3)]
N = int(input())
bl = [int(input()) for _ in range(N)]

for b in bl:
    for i in range(3):
        for j in range(3):
            if Amat[i][j] == b:
                Amat[i][j] = -1

flag = False


#yoko
for al in Amat:
    if all([a == -1 for a in al]):
        flag = True
        break

#tate
for i in range(3):
    if all([Amat[j][i] == -1 for j in range(3)]):
        flag = True
        break
        
#naname
if all([Amat[0][0]==-1, Amat[1][1]==-1, Amat[2][2]==-1]) or all([Amat[0][2]==-1,Amat[1][1]==-1,Amat[2][0]==-1]):
    flag = True

if flag:
    print('Yes')
else:
    print('No')
    

Measured memory_bytes: 3064
n, m = map(int,input().split())
lList = []
rList = []
for i in range(m):
  l, r = map(int,input().split())
  lList.append(l)
  rList.append(r)
result = min(rList) - max(lList) + 1
if result > 0:
  print(result)
else:
  print(0)

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

int main(){
	string s[3];
	cin >> s[0] >> s[1] >> s[2];
	char c[3];
	for(int i = 0;i < 3;i++) c[i] = s[i].at(0) - 32;

	cout << c[0] << c[1] << c[2] << "\n";
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
int a,b;
  cin>>a>>b;
  if((a==1 && b==2) ||(a==2 && b==1))
    cout<<3<<endl;
  else if((a==1 && b==3) ||(a==3 && b==1))
    cout<<2<<endl;
  else
    cout<<1<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
	int a, b, c, d, S;
	scanf("%d", &S);
	a = S / 3600;
	b = S - a * 3600;
	c = b / 60;
	d = b - 60 * c;
		printf("%d:%d:%d\n", a, c, d);
	return 0;
}

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

using namespace std;
typedef long long ll;

#define INF (long long)(1e9+7)
#define REP(i,n) for(ll i = 0; i < n; i++)
#define REP1(i,n) for(ll i = 1; i <= n; i++)

int main(void)
{
    int x; cin >> x;
    int cnt = 0;
    REP1(i, x) {
        if((to_string(i).size())%2==1) cnt ++;
    }
    cout << cnt << endl;

}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    // Your code here!
    int n, sum=0, ans=0;
    scanf("%d", &n);
    for(int i=1; i<=n; i+=2){
        for(int j=1; j<=i; j+=2){
            if(i%j==0) sum++;
        }
        if(sum==8) ans++;
        sum=0;
    }
    printf("%d\n", ans);
}


Measured memory_bytes: 128
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] A = new int[N];
		for(int i = 0 ; i < N ; i++) {
			A[i] = sc.nextInt();
		}
		Map<Integer, Integer> map = new HashMap<Integer, Integer>();
		for(int i = 0 ; i < N ; i++) {
			if(map.containsKey(A[i])) {
				map.put(A[i], map.get(A[i]) + 1);
			} else {
				map.put(A[i], 1);
			}
		}
		int ans = 0;
		for(int key : map.keySet()) {
			if(map.get(key) % 2 == 1) {
				ans++;
			}
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 54444
n = int(input())
w = list(map(int, input().split()))
ans = sum(w)
for i in range(n - 1):
    a = w[:i + 1]
    b = w[i + 1:]
    p = abs(sum(a) - sum(b))
    if ans > p:
        ans = p
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REP(i,b) FOR(i,0,b)
#define RFOR(i,a,b) for (int i = a-1; i >= b; i--)
#define RREP(i,a) RFOR(i,a,0)
#define REPALL(i,v) for (int i = 0; i < v.size(); i++)
#define SORT(v) sort(v.begin(), v.end())
#define MIN_ELEMENT(v) min_element(v.begin(), v.end())
#define MAX_ELEMENT(v) max_element(v.begin(), v.end())
#define COUNT(v,n) count(v.begin(), v.end(), n);
typedef long long ll;
typedef unsigned long long ull;
const int INF = 1e7;
const ll MOD = 1e9 + 7;

int main()
{
    ll k, a, b;
    cin>>k>>a>>b;

    ll p1 = 0ll, p2 = 0ll;
    p1 += k + 1;
    int t = k + 1 - a;
    p2 += a + (t / 2) * (b - a) + t % 2;
    cout<<max(p1, p2)<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;

int main()
{
    string S;
    cin >> S;

    bool app[26];
    for (int i = 0; i < 26; i++)
    {
        app[i] = false;
    }

    int l = S.length();
    for (int i = 0; i < l; i++)
    {
        app[S[i] - 'a'] = true;
    }

    for (int i = 0; i < 26; i++)
    {
        if (app[i] == false)
        {
            cout << (char) (i + 'a') << endl;
            return 0;
        }
    }

    cout << "None" << endl;

    return 0;
}

Measured memory_bytes: 512
#include <stdio.h>

int q_sort(int d[],int left,int right)
{
	if(left >= right) return 0;
	int pipot = d[(left+right)/2],l = left, r = right,tmp;
	while(l < r){
		while(d[l] < pipot) l++;
		while(d[r] > pipot) r--;
		if(l <= r){
			tmp = d[l]; d[l] = d[r]; d[r] = tmp;
			l++; r--;
		}
	}
	q_sort(d,left,r);
	q_sort(d,l,right);
}
void kate(double v[],int i,double num)
{
	int j;
	for(j=0;j<i;j++)
	{
		v[j] = v[j+1];
	}
	v[i] = num;
}
void sagyou(double v[],double num,int N)
{
	int i;
	for(i=0;i<N;i++)
	{
		if(num > v[i])kate(v,i,num);//i番目にnumを入れる。
	}
}

int main(void)
{
	int N;
	scanf("%d",&N);
	int v[N],i;
	for(i=0;i<N;i++)scanf("%d",&v[i]);
	q_sort(v,0,N-1);
	double w[N];
	for(i=0;i<N;i++) w[i] = (double)v[i];
	double ans = 0.0;
	double castle = (w[0]+w[1])/2.0;
	int j;
	for(i=0;i<N-1;i++)
	{
		/*
		printf("\napple\n");
		for(j=0;j<N;j++)
		{
			printf("w[%d] = %lf\n",j,w[j]);
		}
		*/
		castle = (w[i]+w[i+1])/2.0;
		w[i] = 0; w[i+1] = 0;
		sagyou(w,castle,N);
		//printf("castle = %lf, i = %d\n",castle,i);
	}
	/*
	printf("\napple\n");
	for(i=0;i<N;i++)
	{
		printf("w[%d] = %lf\n",i,w[i]);
	}
	*/
	printf("%lf",w[N-1]);
	return 0;
}



Measured memory_bytes: 128
use proconio::input;

fn main() {
    input! {
        n: usize,
        x: i64,
        mut a: [i64; n],
    };
    let mut ans = 0_i64;
    let mut l = 0;
    let mut r = n - 1;
    while r - l > 0 && 1 <= r && l + 1 <= n - 1 {
        let s_l = a[l] + a[l + 1];
        let s_r = a[r - 1] + a[r];
        let d_l = if s_l <= x { 0 } else { s_l - x };
        let d_r = if s_r <= x { 0 } else { s_r - x };
        if d_l <= d_r {
            ans += d_l;
            a[l + 1] = std::cmp::max(0, a[l + 1] - d_l);
            l += 1;
        } else {
            ans += d_r;
            a[r - 1] = std::cmp::max(0, a[r - 1] - d_r);
            r -= 1;
        }
    }
    println!("{}", ans);
}


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

constexpr ll mod = 1000000000 + 7;
#define NMAX 200010
ll fac[NMAX];
ll inv[NMAX];

ll mod_pow(ll a, ll n, ll mod){
    ll ret = 1;
    while(n > 0){
        if(n & 1) ret = (ret*(a % mod))%mod;
        a = ((a%mod)*(a%mod)) % mod;
        n = n >> 1;
    }
    return ret;
}

ll mod_inv(ll a, ll mod){
    return mod_pow(a, mod-2, mod);
}

void mae_nck(){
    fac[1] = 1;
    inv[1] = 1;
    for(ll i = 2; i < NMAX; i++){
        fac[i] = (fac[i-1] * i)%mod;
        inv[i] = (inv[i-1] * mod_inv(i, mod))%mod;
    }
}

ll mod_nck(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    if(k == 0 || k == n) return 1;
    ll ret = ((fac[n] * inv[k])%mod * inv[n-k])%mod;
    return ret;
}

int main(){
    mae_nck();
    ll n, k;
    cin >> n >> k;
    vector<ll> a(n);
    rep(i, 0, n) cin >> a[i];
    sort(a.begin(), a.end());
    ll ans = 0;
    rep(i, k-1, n) {
        ans += (mod_nck(i, k - 1) * a[i]) % mod;
        ans %= mod;
    }
    reverse(a.begin(), a.end());
    rep(i, k-1, n) {
        ans -= (mod_nck(i, k - 1) * a[i]) % mod;
        ans %= mod;
    }
    cout << ans << endl;
    return 0;
}

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

int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}

int main() {
    int N;
    cin >> N;
    int A[N];
    for (int i = 0; i < N; i++) cin >> A[i];
    int ans = A[0];
    for (int i = 1; i < N; i++) {
        ans = gcd(ans, A[i]);
    }
    cout << ans << endl;
}


Measured memory_bytes: 640
h,w = map(int, input().split(' '))
tbl = [list(map(int, input().split(' '))) for i in range(10)]
for k in range(10):
    for i in range(10):
        for j in range(10):
            tbl[i][j] = min(tbl[i][j], tbl[i][k]+tbl[k][j])
wall = [list(map(int, input().split(' '))) for i in range(h)]
ans = 0
for i in range(h):
    for j in range(w):
        num = wall[i][j]
        if num == -1:
            continue
        else:
            ans += tbl[num][1]
print(ans)

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

int main() {
	string S;
	cin>>S;
	string ans = "No";
	rep(i,S.size())rep(j,S.size()){
		if(S[i]=='C'){
			if(S[j]=='F'){
				if(i<j){
					ans="Yes";
				}
			}
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
    int n,k,cnt=0;
    scanf("%d%d",&n,&k);
    int h[100000];
    for(int i=0;i<n;i++){
        scanf("%d",&h[i]);
        if(h[i]>=k){
            cnt++;
        }
    }
    printf("%d\n",cnt);
    return 0;
}


Measured memory_bytes: 512
package main

import (
	"fmt"
	"io"
	"os"
)

func proc(r io.Reader, w io.Writer) {
	var a, b int
	fmt.Fscanf(r, "%d %d", &a, &b)
	o := a + b
	if o < a-b {
		o = a - b
	}
	if o < a*b {
		o = a * b
	}
	//fmt.Printf("%#v", numbers)
	fmt.Fprintf(w, "%d", o)
}

func main() {
	proc(os.Stdin, os.Stdout)
}


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

  int main()
  {
    ios::sync_with_stdio(!cin.tie(0));
    
     string s; cin>>s;
    int n; n=s.size();
    char c=s.at(n-1);
       if(s.at(n-1)== '3') cout<<"bon";
     else if(c=='0'|| c=='1' || c=='6' || c=='8') cout<<"pon";
    else cout<<"hon";
  }


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

using namespace std;

using int64 = long long;
const int mod = 1e9 + 7;

const int64 infll = (1LL << 60) - 1;
const int64 infll2 = (1LL << 58) - 1;
const int inf = (1 << 30) - 1;


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

template< typename T1, typename T2 >
istream &operator>>(istream &is, pair< T1, T2 > &p) {
  is >> p.first >> p.second;
  return is;
}

template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
  for(int i = 0; i < (int) v.size(); i++) {
    os << v[i] << (i + 1 != v.size() ? " " : "");
  }
  return os;
}

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

template< typename T = int64 >
vector< T > make_v(size_t a) {
  return vector< T >(a);
}

template< typename T, typename... Ts >
auto make_v(size_t a, Ts... ts) {
  return vector< decltype(make_v< T >(ts...)) >(a, make_v< T >(ts...));
}

template< typename T, typename V >
typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) {
  t = v;
}

template< typename T, typename V >
typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) {
  for(auto &e : t) fill_v(e, v);
}

void ushitapunichiakun(string arg) {
  int N;
  cin >> N;
  vector< int > P(4), T(4);
  cin >> P;
  cin >> T;

  auto dp = make_v< int >(1333);
  fill_v(dp, inf);
  dp[0] = 0;
  for(int i = 0; i < 4; i++) {
    for(int j = T[i]; j < 1333; j++) {
      chmin(dp[j], dp[j - T[i]] + P[i]);
    }
  }
  int ret = inf;
  for(int i = N; i < 1333; i++) chmin(ret, dp[i]);
  cout << ret << endl;
}

int main() {
  ushitapunichiakun("笑");
}


Measured memory_bytes: 3216
$m = gets.to_i
$n = gets.to_i
$s = (1..$n).map{gets.split.map(&:to_i)}
 
def solve(a)
  if a.size == $m
    return a
  end
  $s.select{|e|a.include?(e[1])&& !a.include?(e[0])}.map{|e|
    r = solve(a + [e[0]])
    if r
      return r
    end
  }
end
 
p solve([2])

Measured memory_bytes: 6124
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String args[]) {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int E = scanner.nextInt();
        List<List<Integer>> graph = new ArrayList<>();
        for (int i = 0; i < N; i++) {
            graph.add(new ArrayList<>());
        }
        for (int i = 0; i < E; i++) {
            int start = scanner.nextInt()-1;
            int end = scanner.nextInt()-1;
            graph.get(start).add(end);
        }

        int dp[] = new int[N];
        int result = 0;
        for (int i = 0; i < N; i++) {
            result = Math.max(result, logesntPath(i, dp, graph));
        }
        System.out.println(result-1);
    }

    public static int logesntPath(int vertex, int[] dp, List<List<Integer>> graph) {
        if (dp[vertex] != 0) {
            return dp[vertex];
        }
        int result = 0;
        for (int  end : graph.get(vertex)) {
            result = Math.max(result, logesntPath(end, dp, graph));
        }
        dp[vertex] = result + 1;
        return dp[vertex];
    }
}


Measured memory_bytes: 102880
#include<bits/stdc++.h>
using namespace std;
int a,b,c,x,ans;
int main()
{
    cin>>a>>b>>c>>x;
    for(int i=0;i<=a;i++)
      for(int j=0;j<=b;j++)
        for(int k=0;k<=c;k++)
          if(i*500+j*100+k*50==x) ans++;
    cout<<ans;
    return 0;
}

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

typedef long long int64;
const int P = 1e9 + 7;

const int MaxN = 2020;
int f[MaxN][MaxN];
int fac[MaxN*MaxN];
int inv[MaxN*MaxN];
int facInv[MaxN*MaxN];
int N, M, g;

int add(int x, int y) { x += y; return x >= P ? x - P : x; }
int mul(int x, int y) { return (int64)x*y%P; }
int c(int x, int y) { return mul(fac[x], mul(facInv[y], facInv[x - y])); }
void inc(int& x, int y) { x = add(x, y); }

int main()
{
	ios::sync_with_stdio(0), cin.tie(0);
	
	cin >> N >> M;
	if (M == 1) return puts("1")&0;
	fac[0] = facInv[0] = 1,
	fac[1] = inv[1] = facInv[1] = 1;
	for (int i = 2;i < MaxN * MaxN; ++i) {
		fac[i] = mul(fac[i-1], i),
		inv[i] = mul((P-P/i), inv[P%i]),
		facInv[i] = mul(facInv[i-1], inv[i]);
	}
	
	g = 1;
	for (int i = 1;i <= N; ++i)
		f[i][0] = 1, g = mul(g, i);
	for (int i = 1;i <= N; ++i) {
		for (int j = 1;j <= i; ++j) {
			inc(f[i][j], f[i-1][j]);
			inc(f[i][j], mul(f[i][j-1], c(N*M - i - (j-1) * (M - 1) - 1, M - 2)));
		}
	}
	
	cout << mul(g, f[N][N]);
	return 0; 
}

/*
f[i][j] += f[i-1][j] + f[i][j-1] * c(N*M - i - (j-1) * (M-1) - 1, M-2)
*/

Measured memory_bytes: 63872
#pragma warning(disable:4996)
#include <bits/stdc++.h>

using namespace std;

#define REP(i,n) for (int i = 0; i<n; i++)
#define ALL(a) begin(a), end(a)
#define TPL template
#define TNM typename

using ll = long long;
using ull = unsigned long long;
TPL<TNM T> using vec = vector<T>;
TPL<TNM T> using vec2 = vec<vec<T>>;
TPL<TNM T> using vec3 = vec<vec2<T>>;
TPL<TNM T> using vec4 = vec<vec3<T>>;
TPL<TNM T> using vec5 = vec<vec4<T>>;

TPL<TNM V, TNM H> void resize(vector<V>& v, const H h) { v.resize(h); }
TPL<TNM V, TNM H, TNM ... T> inline void resize(vector<V>& v, const H& h, const T ... t) { v.resize(h); for (auto& _v : v) resize(_v, t ...); }
TPL<TNM V, TNM T> void fill(V& x, const T& val) { x = val; }
TPL<TNM V, TNM T> inline void fill(vector<V>& vec, const T& val) { for (auto& v : vec) fill(v, val); }
TPL<TNM T> inline void UNIQUE(vector<T>& vec) { sort(ALL(vec)); vec.erase(unique(ALL(vec)), vec.end()); }

int main(void) {
	int N, H, W;
	cin >> N >> H >> W;
	vec<int> A(N), B(N);
	REP(i, N) {
		cin >> A[i] >> B[i];
	}
	int ans = 0;
	REP(i, N) {
		if (A[i] >= H && B[i] >= W)++ans;
	}
	cout << ans << endl;
	return 0;
}

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

#define fast_cin() ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define endl '\n'

int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output14.txt", "w", stdout);
#endif
	//fast_cin();
	int k; cin >> k;
	int num = 0;
	for (int i = 1; i <= k; ++i) {
		num = num * 10 + 7;
		num %= k;
		//out << num << "\n";
		if (num == 0) {
			cout << i << endl;
			return 0;
		}
	}
	cout << -1 << endl;
	return 0;
}


Measured memory_bytes: 3600
def main():
    from collections import deque
    N,K = map(int,input().split())
    D = list(set(range(10)) - set(map(int,input().split())))
    D.sort()
    targets = deque(D)
    while True:
        t = targets.popleft()
        if N <= t:
            print(t)
            return
        t *= 10
        for d in D:
            targets.append(t+d)
main()

Measured memory_bytes: 68284
#include <iostream>

using namespace std;

typedef long long ll;
const ll mod = 1000000007;

ll fastPow(ll a, ll b) {
    a %= mod;
    ll res = 1;
    while(b > 0) {
        if(b & 1) res = res * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return res;
}

int main() {
    ll x;
    cin >> x;
    cout << ((fastPow(10, x) - 2 * fastPow(9, x) + fastPow(8, x)) % mod + mod) % mod;
}

Measured memory_bytes: 3572
class UnionFind3
  def initialize(size)
    @table = Hash.new{-1}
  end

  def find(x)
    if @table[x] < 0
      return x
    else
      return @table[x] = find(@table[x])
    end
  end

  def union(x, y)
    s1 = find(x)
    s2 = find(y)
    @table[s2] = s1
  end
end

#UF=Hash.new{-1}
#def u a,b;UF[f a]=f b;end
#def f c;0>UF[c]?c:UF[c]=f(UF[c])end

cities=(1..n=gets.to_i).map{|i|gets.split.map(&:to_i)+[i]}

road = cities.sort_by{|x,y,i|x}.each_cons(2).map{|(x1,y1,i),(x2,y2,j)|[x2-x1,i,j]}+
       cities.sort_by{|x,y,i|y}.each_cons(2).map{|(x1,y1,i),(x2,y2,j)|[y2-y1,i,j]}

uf=UnionFind3.new(100001)
p road.sort.inject(0){|s,(cost,i,j)|
  if uf.find(i)!=uf.find(j)
    uf.union(i,j)
    s+cost
  else
    s
  end
}


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

int main() {
  int h, w, k;
  scanf("%d %d %d", &h, &w, &k);
  vector<vector<char>> c(h, vector<char>(w));
  for (int i = 0; i < h; i++)
    for (int j = 0; j < w; j++)
      scanf(" %c", &c[i][j]);

  int ans = 0;
  for (int i = 0; i < (1 << (h + w)); i++) {
    int t = i;
    vector<bool> u(h), v(w);
    for (int j = 0; j < h; j++) {
      if (t & 1) u[j] = true;
      t >>= 1;
    }
    for (int j = 0; j < w; j++) {
      if (t & 1) v[j] = true;
      t >>= 1;
    }

    int r = 0;
    for (int x = 0; x < h; x++)
      for (int y = 0; y < w; y++)
        if (!u[x] && !v[y] && c[x][y] == '#')
          r++;
    if (r == k) ans++;
  }

  printf("%d\n", ans);

  return 0;
}

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

int gcd(int C,int D){
  int tmp;
  if(C<D){
    tmp=C;
    C=D;
    D=tmp;
  }
  int r=C%D;
  while(r!=0){
    C=D;
    D=r;
    r=C%D;
  }
  return D;
}
int main(){
  unsigned long long int A,B,C,D;
  cin >> A >> B >> C >> D;
  long long int BC = B/C;
  long long int BD = B/D;
  long long int AC = (A-1)/C;
  long long int AD = (A-1)/D;
  long long int L = C*D/gcd(C,D);
  long long int BL= B/L;
  long long int AL = (A-1)/L;
  cout << (B-A+1)-((BC-AC)+(BD-AD)-(BL-AL)) << endl;
  
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
typedef long long ll;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define max(l,r) ((l)>(r)?(l):(r))
#define min(l,r) ((l)<(r)?(l):(r))

int main(){
    int n; scanf("%d", &n);
    printf("%d",n^1);
    //rep(i, n) scanf("%lld", ans+i);
    //if(ans){ puts("YES"); rep(i,n) printf("%lld ", a[i]);}else puts("NO");
}


Measured memory_bytes: 1736
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		String s = scan.next();

		String alphabet = "abcdefghijklmnopqrstuvwxyz";
		for (int i = 0; i < alphabet.length(); i++) {
			if (s.equals(alphabet.substring(i, i + 1))) {
				System.out.println(alphabet.substring(i + 1, i + 2));
			}
		}
		scan.close();
	}

}


Measured memory_bytes: 21844
#include <stdio.h>
#include <stdlib.h>
#include <queue>


int main() {
	
	std::priority_queue<int> q;

	int A[3];

	scanf("%d %d %d", &A[0], &A[1], &A[2]);

	
	q.push(abs(A[0] - A[1]));
	q.push(abs(A[1] - A[2]));
	q.push(abs(A[2] - A[0]));

	q.pop();
	int ans = q.top();
	q.pop();
	ans += q.top();

	printf("%d\n", ans);
	



	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<N;i++)
#define INF 1e9
typedef long long LL;
const LL MOD = 1e9+7;

int main() {
  LL N;
  cin >> N;
  vector<LL> A(N);
  rep(i,N) cin >> A[i];
  
  LL sum = 0;
  rep(i,N) sum += A[i];
  
  vector<LL> B(N);
  B[0] = sum;
  for (int i = 1; i < N; i+=2) {
    B[0] -= 2 * A[i];
  }
  
  rep(i,N-1) {
    B[i+1] = 2 * A[i] - B[i];
  }

  rep(i,N) cout << B[i] << ' ';
  
  return 0;
}

Measured memory_bytes: 2816
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <utility>
#include <functional>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_map>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;
const int INF = (1<<30);
const int MOD = 1000000007;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    int q;
    cin >> q;
    rep(i, q){
        int b, e, k;
        cin >> b >> e >> k;
        cout << count(a.begin()+b, a.begin()+e, k) << endl;
    }
    return 0;
}


Measured memory_bytes: 3096
n,m = map(int,input().split())
ab = []
for i in range(n):
        ab.append([int(j) for j in input().split()])
ab.sort()
cnt = 0
ans = 0
for i in ab:
    cnt += i[1]
    ans += i[0]*i[1]
    if cnt >= m:
        ans -= i[0]*(cnt-m)
        print(ans)
        exit()

Measured memory_bytes: 21616