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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

template<class Monoid>
class SegmentTree {

public:
    /**
     * @param N size
     * @param e identity element
     * @param operation operation to merge `data`
     * @param updater operation to update `data`
     */
    SegmentTree(size_t N, Monoid e, function<Monoid(Monoid, Monoid)> operation,
                function<Monoid(Monoid, Monoid)> updater)
            : e(e), operation(operation), updater(move(updater)) {
        n = 1;
        while (n < N) {
            n *= 2;
        }
        data = vector<Monoid>(2 * n - 1, e);
        for (int i = n - 2; i >= 0; i--) {
            data[i] = operation(data[2 * i + 1], data[2 * i + 2]);
        }
    }

    /**
     * iの値をxに更新 ( 0-indexed )
     */
    void update(int i, Monoid x) {
        i += n - 1;
        data[i] = updater(data[i], x);
        while (i > 0) {
            i = (i - 1) / 2;
            data[i] = operation(data[i * 2 + 1], data[i * 2 + 2]);
        }
    }

    /**
     * [a, b)の区間でクエリを実行
     */
    Monoid query(int a, int b) {
        return query(a, b, 0, 0, n);
    }

    /**
     * 添字でアクセス( 0-indexed )
     */
    Monoid operator[](int i) {
        return data[i + n - 1];
    }

private:
    int n;
    vector<Monoid> data;
    Monoid e;
    function<Monoid(Monoid, Monoid)> operation;
    function<Monoid(Monoid, Monoid)> updater;

    Monoid query(int a, int b, int k, int l, int r) {
        // 交差しない
        if (r <= a || b <= l) return e;
        // 区間 [a, b) に l, r が含まれる
        if (a <= l && r <= b) return data[k];
        // 左の子
        Monoid c1 = query(a, b, 2 * k + 1, l, (l + r) / 2);
        // 右の子
        Monoid c2 = query(a, b, 2 * k + 2, (l + r) / 2, r);
        return operation(c1, c2);
    }
};

void Main() {
    ll N, Q;
    cin >> N >> Q;
    SegmentTree<ll> segmentTree(N, (1L << 31) - 1, [](ll a, ll b) { return min(a, b); }, [](ll a, ll b) { return b; });
    rep(q, Q) {
        ll com, x, y;
        cin >> com >> x >> y;
        if (com) {
            cout << segmentTree.query(x, y + 1) << '\n';
        }else{
            segmentTree.update(x, y);
        }
    }
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}



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

/*alias*/
#define REP(i,n) for (int i = 0; i < (n); i++)
#define ALL(obj) (obj).begin(), (obj).end()
using ll=long long;

using namespace std;

/*funcs*/

/*input*/
int n;
string s;

/*main*/
int main(){
    cin>>n>>s;
    int ans;
    int a[n]={0};
    for(int i=0;i<n;i++){
        if(i==0){
            if(s[0]=='#'){
                a[0]=1;
            }else{
                a[0]=0;
            }
        }else{
            if(s[i]=='#'){
                a[i]=a[i-1]+1;
            }else{
                a[i]=a[i-1];
            }
        }
    }
    for(int i=0;i<n+1;i++){
        if(i==0){
            ans=a[n-1];
        }else if(i==n){
            int temp=n-a[n-1];
            if(temp<ans){
                ans=temp;
            }
        }else{
            int temp1=a[i-1]+(n-i)-(a[n-1]-a[i-1]);
            if(temp1<ans){
                ans=temp1;
            }
        }
    }
    cout<<ans;
}

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

vector<long> mozi[26];
int main(){
  string s,t;
  cin >> s >> t;
  long m = s.size(),n = t.size();
  for(long i = 0;i < m;i++){
    mozi[s.at(i) - 'a'].push_back(i+1);
  }
  long num = 0,result = 0;
  bool ok = true;
  vector<long> alpha(26);
  for(long i = 0;i < m;i++){
    alpha.at(s.at(i)-'a')++;
  }
  for(long i = 0;i < n;i++){
    if(alpha.at(t.at(i) - 'a') <= 0){
      ok = false;
    }
  }
  if(ok == false){
    result = -1;
  }
  else{
    while(num < n){
      long siter = 0;
      long add = 0;
      while(siter <= m){
        char cur = t.at(num);
        //cout << cur << endl;
        auto iter = std::upper_bound(mozi[cur-'a'].begin(),mozi[cur-'a'].end(),siter);
        if(iter == mozi[cur-'a'].end()){
          add = m;
          break;
        }
        num++;
        add = mozi[cur-'a'].at(iter - mozi[cur-'a'].begin());
        siter = mozi[cur-'a'].at(iter - mozi[cur-'a'].begin());
        if(num == n) break;
      }
      result += add;
      //cout << num << endl;
    }
  }
  cout << result << endl;
}

Measured memory_bytes: 1724
#include <algorithm>
#include <iostream>
#include <vector>
#include <numeric>
using namespace std;



int main()
{
  int N;
  cin >> N;
  int a[N];
  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }

  int bob = 0;
  int alice = 0;

  sort(a, a+N, greater<int>());

  for (int i = 0; i < N; i++) {
    if(i % 2 == 0){
      alice += a[i];
    }else{
      bob += a[i];
    }
  }

  cout << alice - bob << endl;

  return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES

//#include <bits/stdc++.h>
#include <cmath>
#include <iostream>
#include <vector>
    
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;

//int 最大値は2147483647 > 10^9

int main(){
    int n,m;
    cin>>n>>m;

    vector<int> h(n),kouho(n);
    rep(i,n) cin>>h[i];
    rep(i,n) kouho[i]=1;

    int a,b;
    rep(i,m){
        cin>>a>>b;
        if(h[a-1]<h[b-1]){
            kouho[a-1]=0;
        }else if(h[a-1]>h[b-1]){
            kouho[b-1]=0;
        }else{
            kouho[a-1]=0;
            kouho[b-1]=0;
        }
    }
    int ans=0;
    rep(i,n)if(kouho[i]==1)ans++;
    cout<<ans<<endl;

} // end of main
    
//実行は、Opt + Ctl + N


//pythonの入力
//s, w = map(int, input().split())


Measured memory_bytes: 4052
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws Exception{
		BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
		String str[] = r.readLine().split(" ");
		int max = Integer.parseInt(str[0]);
		Queue q = new Queue(max);
		int qtime = Integer.parseInt(str[1]);

		for(int i = 0 ; i < max ; i++ ){
			str = r.readLine().split(" ");
			q.enqueue(new Process(str[0], Integer.parseInt(str[1])));
		}

		int elapsedTime = 0;

		int count = 0;
		//?????\?????¬????????§???
		while(true){
			if(max <= count) break;
			Process p = q.dequeue();
			int time = p.getTime();

			if(time <= qtime){
				elapsedTime+= time;
				count++;
				System.out.println(p.getName() +" "+elapsedTime);
			}else{
				p.setTime(time - qtime);
				elapsedTime += qtime;
				q.enqueue(p);
			}

		}
	}

}

class Queue{

	Process[] processAry;
	int top;
	int tail;
	int max;

	public Queue(int max){
		top = tail = 0;
		processAry = new Process[max];
		this.max = max;
	}

	public void enqueue(Process process) throws Exception{
			processAry[top] = process;
			top = (top + 1) % max;
	}

	public Process dequeue() throws Exception{

			Process p = processAry[tail];
			tail = (tail + 1) % max;
			return p;

	}

}

class Process{
	private String name;
	private int time;

	public Process(String name,int time) {
		this.name = name;
		this.time = time;
	}

	public String getName() {
		return name;
	}

	public int getTime() {
		return time;
	}

	public void setTime(int time) {
		this.time = time;
	}

}

Measured memory_bytes: 59540
const input=require('fs').readFileSync('/dev/stdin', 'utf8').split(/[\s]/);const nin=()=>{const r = input[0];input.shift();return Number(r)};const nrin=(n)=>{const a:number[]=[];rep(n,()=>a.push(nin()));return a};const sin=()=>{const r = input[0];input.shift();return String(r)};const out=(...a)=>{console.log(...a)};const floor=(a)=>{return Math.floor(a)};const abs=(a)=>{return Math.abs(a)};const min=(...a)=>{return Math.min(...a)};const max=(...a)=>{return Math.max(...a)};const rep=(n, callback)=>{for(let i = 0;i < n; i++){callback()}};const strrep=(s, i, v)=>{return s.slice(0, i)+v+s.slice(i+1);};const permutation=({result=[],pre=[],post,n=post.length})=>{if(n>0){post.forEach((_,i)=>{const rest=[...post];const elem=rest.splice(i, 1);permutation({result, pre: [...pre,...elem],post:rest,n:n-1})})}else{result.push(pre)}return result};const sw=(s,a:any[],op:'=='|'>='|'>'|'<='|'<'='==')=>{for(let i=0;i<a.length;i+=2){if(op==='=='){if(s==a[i])return a[i+1]}else if(op==='>='){if(s>=a[i])return a[i+1]}else if(op==='<='){if(s<=a[i])return a[i+1]}else if(op==='>'){if(s>a[i])return a[i+1]}else if(op==='<'){if(s<a[i])return a[i+1]}}return a[a.length-1];};const or=(a,...b)=>{for(let i=0;i<b.length;i++)if(a==b[i])return true;return false};const maxindex=(...a)=>{return a.indexOf(Math.max.apply(null,a))};const asc=(ar:number[])=>{return ar.sort((a,b)=>{return a-b})};const desc=(ar:number[])=>{return ar.sort((a,b)=>{return b-a})};const ceil=a=>{return Math.ceil(a)};const srin=s=>{const a:string[]=[];rep(s,()=>a.push(sin()));return a};let ssinteger=-1;const ssin=()=>{ssinteger++;return input[0][ssinteger]};
const main = ()=>{
  let[a,b]=nrin(2)
  if(a==1)a=14
  if(b==1)b=14
  out(a==b?'Draw':a>b?'Alice':'Bob')
}
main()

Measured memory_bytes: 7372
N,M=map(int,input().split())
shop=[]
for i in range(N):
    a,b=map(int,input().split())
    shop.append((a,b))

shop.sort()

drink=0
cost=0

for s in shop:
    if drink+s[1]>=M:
        cost+=s[0]*(M-drink)
        break
    drink+=s[1]
    cost+=s[0]*s[1]

print(cost)

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

int main(){
  int n,k,x,y;
  cin >>n >>k >>x >>y;
  if(n>=k) cout << k*x + (n-k)*y << endl;
  else cout << n*x << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <ctime>
using namespace std;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define RFOR(i,b,a) for (int i = (b)-1; i >= (a); i--)
#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const int MOD = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL) INF;
const int MAX = 300070;

int c[MAX];

int A[MAX];
int m[MAX];



int main() {
    int n;
    scanf("%d", &n);
    FOR(i, 0, 3 * n) {
        scanf("%d", A + i);
    }
    multiset<int> a;
    multiset<int> b;
    multiset<int> bb;
    
    LL s = 0;
    FOR(i, 0, 3* n) {
        if (b.size() < n) {
            s+=A[i];
            b.insert(A[i]);
        
        } else if(A[i] < *--b.end()) {
            s -= * --b.end();
            s += A[i];
            bb.insert(*--b.end());
            b.erase(--b.end());
            b.insert(A[i]);
        } else {
            bb.insert(A[i]);
        }
        
    }
    //cout << s << endl;
    LL S = 0;
    LL ans = -LINF;
    FOR(i, 0, 3 * n) {
        if (a.size() == n && b.size() == n) {
            ans = max(ans, S - s);
        }
        if (a.size() < n) {
            S += A[i];
            a.insert(A[i]);
        } else if (A[i] > *a.begin()) {
            S -= *a.begin();
            S += A[i];
            a.erase(a.begin());
            a.insert(A[i]);
        }
        
        multiset<int>::iterator ib = b.find(A[i]);
        if (ib != b.end()) {
            s -= A[i];
            b.erase(ib);
            if (!bb.empty()) {
                s += *bb.begin();
                b.insert(*bb.begin());
                bb.erase(bb.begin());
            }
        } else {
            bb.erase(bb.find(A[i]));
        }
    }
    
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 15488
#include<bits/stdc++.h>
using namespace std;
using Graph=vector<vector<int>>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
typedef long long ll;
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(){
    ll N;ll D;cin>>N>>D;
    ll cnt=0;
    rep(i,N){
        ll a,b;cin>>a>>b;
        ll c=a*a+b*b;
        if(c<=D*D){
            cnt++;
        }
    }
    cout<<cnt<<endl;
}

Measured memory_bytes: 3632
#include<iostream>
#include<sstream>
using namespace std;
string convert(string s);
int main()
{
  int n;
  string s;
  while(cin>>n>>s,n){
    while(n-->0){
      s=convert(s);
    }
    cout<<s<<endl;
  }
}

string convert(string s)
{
  int cnt;
  stringstream ss;
  cnt=1;
  s+="A";
  for(int i=1;i<s.size();i++){
    if(s[i-1]==s[i]){
      cnt++;
    }else{
      ss<<cnt<<s[i-1];
      cnt=1;
    }
  }
  return ss.str();
}

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

int main(){
	int dataN,i,j,tmp;
	string str;
	
	cin>>str;
	for(i=str.length()-1;0<=i;i--){
	 cout<<str[i];
	}
	
	cout<<endl;
	
	return 0;
}

Measured memory_bytes: 1176
program main
  implicit none
  integer(8) :: n, k, mi, ma, md, i
  integer(8), allocatable :: a(:)
  read *, n, k
  allocate (a(n))
  read *, a(:)
  call quicksort(a)

  ! 積がthres以下になるペアがk個以上ある最小のthres
  mi = -2 * 10_8 ** 18  ! NG
  ma = 2 * 10_8 ** 18  ! OK
  do i = 1, 70
    md = mi + (ma - mi) / 2
    if (isok(md)) then
      ma = md
    else
      mi = md
    end if
    if (ma - mi <= 1) exit
  end do

  print "(i0)", ma

  contains

  logical function isok(x)
    ! 積がx以下になるペアがk個以上ある
    integer(8), intent(in) :: x
    integer(8) :: i, cnt
    cnt = 0
    do i = 1, n
      cnt = cnt + count_lower(i, x)
    end do
    isok = (cnt >= k)
  end function isok

  integer(8) function count_lower(i, x)
    ! a(i) * a(j) <= x となるj>iの数
    integer(8), intent(in) :: i, x
    integer(8) :: j, mi, md, ma
    if (a(i) >= 0) then
      ! a(i) * a(j) <= x となる最大のjを求める
      mi = i  ! ok
      ma = n + 1  ! ng
      do j = 1, 30
        md = mi + (ma - mi) / 2
        if (a(i) * a(md) <= x) then
          mi = md
        else
          ma = md
        end if
        if (ma - mi <= 1) exit
      end do
      count_lower = mi - i
    else
      ! a(i) * a(j) <= x となる最小のjを求める
      mi = i  ! ng
      ma = n + 1  ! ok
      do j = 1, 30
        md = mi + (ma - mi) / 2
        if (a(i) * a(md) <= x) then
          ma = md
        else
          mi = md
        end if
        if (ma - mi <= 1) exit
      end do
      count_lower = n - (ma - 1)
    end if
  end function count_lower

  recursive subroutine quicksort(a)
    integer(8), intent(inout) :: a(:)
    integer(8) :: pivot, i, j, k, tmp, n
    real(8) :: r
    n = size(a)
    if (n <= 1) return
    i = 1
    j = n
    call random_number(r)
    k = 1 + floor(r * n)
    k = max(1_8, min(k, n))
    pivot = a(k)
    do
      do while (.not. pivot <= a(i))
        i = i + 1
      end do
      do while (.not. a(j) <= pivot)
        j = j - 1
      end do
      if (i >= j) exit
      tmp = a(i)
      a(i) = a(j)
      a(j) = tmp
      i = i + 1
      j = j - 1
    end do
    call quicksort(a(1:i - 1))
    call quicksort(a(j + 1:n))
  end subroutine quicksort
end program main


Measured memory_bytes: 2304
#include <iostream>
#include <stdio.h>

using namespace std;

int main(){
    int w, n;
    int d[31];
    while(~scanf("%d %d", &w, &n)){
        for(int i=1;i<=w;i++) d[i] = i;
        for(int i=0;i<n;i++){
            int a, b;
            scanf("%d,%d", &a, &b);
            swap(d[a], d[b]);
        }
        for(int i=1;i<=w;i++) cout << d[i] << endl;
    }
}

Measured memory_bytes: 0
import java.io.*;
import java.math.*;
import java.text.*;
import java.util.*;
import java.util.regex.*;

public class Main {

    public static void dfs(ArrayList<Integer>[] graph, int n, int u, boolean[] visited, 
        int[] indegree, int[] dp) {
        visited[u] = true;

        for(int v : graph[u]) {
            dp[v] = Math.max(dp[v], dp[u] + 1);
            indegree[v]--;
                if(indegree[v] == 0) {
                    dfs(graph, n, v, visited, indegree, dp);
                }
        }
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();

        ArrayList<Integer>[] graph = new ArrayList[n + 1];
        int[] indegree = new int[n + 1];
        boolean[] visited = new boolean[n + 1];
        int[] dp = new int[n + 1];

        for(int i = 0; i <= n; i++) {
            graph[i] = new ArrayList<>();
        }

        for(int i = 0; i < m; i++) {
            int x = sc.nextInt();
            int y = sc.nextInt();
            graph[x].add(y);
            indegree[y]++;
        }

        for(int i = 1; i <= n; i++) {
            if(!visited[i] && indegree[i] == 0) {
                dfs(graph, n, i, visited, indegree, dp);
            }
        }

        int result = 0;
        for(int i = 1; i <= n; i++) {
            result = Math.max(result, dp[i]);
        }

        System.out.println(result);
  }
}

Measured memory_bytes: 118676
process.stdin.resume();
process.stdin.setEncoding('utf8');

var g_input = '';
process.stdin.on('data', function(chunk) {
    g_input += chunk;
});

process.stdin.on('end', function() {
    Main(g_input.split(/\r?\n/));
});

function Main(input) {

    var nmstr = input[0].split(' ');
    var n = parseInt(nmstr[0], 10);
    var m = parseInt(nmstr[1], 10);
    var nodes = new Array(n);
    for (var i = 0; i < n; i++) {
        nodes[i] = {index: i, edges: []};
    }
    for (var i = 0; i < m; i++) {
        var abstr = input[i + 1].split(' ');
        var a = parseInt(abstr[0], 10);
        var b = parseInt(abstr[1], 10);
        nodes[a - 1].edges.push(b);
        nodes[b - 1].edges.push(a);
    }


    var color = new Array(n);
    for (var i = 0; i < n; i++) {
        color[i] = -1;
    }
    color[0] = 0;

    var isBiparite = true;
    var q = [];
    q.push(nodes[0]);
    while (q.length > 0) {

        var now = q.shift();

        for (var i = 0; i < now.edges.length; i++) {
            var next = now.edges[i] - 1;
            if (color[now.index] == color[next]) {
                isBiparite = false;
                break;
            }
            else {
                if (color[next] < 0) {
                    color[next] = 1 - color[now.index];
                    q.push(nodes[next]);
                }
            }
        }
        if (!isBiparite) {
            break;
        }
    }

    var ans = 0;
    if (isBiparite) {
        var sum = 0;
        for (var i = 0; i < n; i++) {
            sum += color[i];
        }
        ans = sum * (n - sum) - m;
    }
    else {
        ans = n * (n - 1) / 2 - m;
    }

    console.log(ans);

    return 0;
}


Measured memory_bytes: 62812
#include<vector>
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include <iostream>
#include <algorithm>
#include <map>
#include <cmath>
#include<queue>
#include <sstream>
#include <set>
#include<stack>
#include <utility>

const long long MOD = 1000000007;
using namespace std;
typedef long long llong;

//int isalpha(char ch): ch がアルファベットなら true を返す
//int isdigit(char ch): ch が数字なら true を返す
//int islower(char ch): ch が小文字なら true を返す
//int isupper(char ch): ch が大文字なら true を返す
//int tolower(char ch): ch の小文字を返す
//int toupper(char ch): ch の大文字を返す

//string型
//size()	文字数を返す
//Insert()	（指定した場所に）文字・文字列を挿入する
//erase()	（指定した場所の）文字・文字列を削除する
//clear()	すべての文字を削除する
//substr()	文字列の（指定した）部分文字列を返す
//replace()	（指定した）部分文字列を新しい文字列に置換する
//c_str()変換
//文字列の比較は、<=や==などを使え
//replace関数を使い、簡単に文字列を置換
//リバース関数：reverse(str.begin(), str.end());
//map<type, type> dict;で宣言
//グラフ理論用変数
//vector<vector<llong> > graph(N);

//ソート
//降順sort(v.begin(), v.end(), std::greater<Type>());

//大文字から小文字へんかん
//w[i] = w[i]-'A'+'a';

//vector
//assignメソッド　引数：サイズ、値
//与えられたサイズと値でvectorを初期化する

//queueクラス
//find()次に取り出す値の表示をする。
//pop()値を取り出す。戻り値はなし
//push()キューに値をプッシュする

//priority_queueクラス

//切り上げ
//ceil
//floor

int main(){
    llong N,W;
    cin >> N >> W;
    vector<vector<llong> > dp(N+1, vector<llong>(W+1,0));
    vector<llong> w(N+1, 0);
    vector<llong> v(N+1, 0);
    for(int i=1; i<=N; i++){
        cin >> w[i] >> v[i];
    }
    for(int i=1; i<N+1; i++){
        for(int j=0; j<W+1; j++){
            if(j-w[i]<0){
                dp[i][j] = dp[i-1][j];
                continue;
            }
            dp[i][j] = max(dp[i-1][j], dp[i-1][j-w[i]]+v[i]);
        }
    }
    cout << dp[N][W] << endl;
    return 0;
}


Measured memory_bytes: 82760
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <map>

using namespace std;

int main()
{
    int N;
    cin >> N;
    vector<string> S(N), T;
    map<string, int> dict;
    for(int i=0;i<N;++i){
        cin >> S[i];
    }
    int max_v = -1;
    for(auto s : S){
        dict[s]++;
        max_v = max(max_v, dict[s]);
    }
    for(auto itr = dict.begin(); itr != dict.end(); ++itr) {
        if(max_v == itr->second){
            T.push_back(itr->first);
        }
    }
    sort(T.begin(), T.end());
    for(int i=0;i<T.size();++i){
        cout << T[i] << endl;
    }
}


Measured memory_bytes: 28404
import java.util.*;
import java.math.BigDecimal;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int n,ans = 0;
      
        for(int i = 1;i <= 5;i++){
			n = sc.nextInt();
          if(n == 0){
            ans = i;
            continue;
          }
        }

        System.out.println(ans);
    }
}

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

int main() {
	int p,q,r,z,max;
	scanf("%d %d %d",&p,&q,&r);
	
	if(p>q)
	    max=p;
	else
	    max=q;
	  if(r>max)
	        max=r;
	        
	  z=p+q+r-max;
	  
	  printf("%d\n",z);
	  
return 0;
}

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

int main() {
  int a,b,c,d;
  
  cin >>a>>b>>c>>d;
  
  
  if (a+b>c+d) {
    cout << "Left" << endl;
  }
  
  else if (a+b==c+d) {
    cout << "Balanced" << endl;
  }
  
  else  {
    cout << "Right"<< endl;
  } 
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#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(){
ll nballs,kcolors;
cin>> nballs >> kcolors;

ll ans=kcolors*pow(kcolors-1,nballs-1);
cout<<  ans << endl;

return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < n; i++)
#define REPR(i, n) for(ll i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(ll i = m; i <= n; i++)
#define FORR(i, m, n) for(ll i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n)
#define MAX 100000
#define inf 1000000007
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

int main() {
    //cin高速化
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, ans;
    ans = 0;
    cin >> n;
    vll a(3*n+1, 0);
    FOR(i, 1, 3*n) cin >> a[i];
    sort(a.begin(), a.end());
    for(ll i = 3*n-1; i > n; i -= 2){
        ans += a[i];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 2560
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <map>
#include <deque>
#include <iomanip>
#include <cstdio>
#include <stack>
#include <numeric>

using namespace std;
typedef  long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define  MP make_pair
#define  PB push_back
#define inf 1000000007
#define mod 1000000007
#define rep(i,n) for(int i=0;i<(int)(n);++i)

int main(){
    string s;
    cin >> s;
    int n = s.size();
    string pre;
    string t;
    int cnt = 0;
    for(int i=0;i<n;i++){
        t.push_back(s[i]);
        if(pre!=t){
            cnt++;
            pre = t;
            t = "";
        }
    }
    cout << cnt << endl;
    return 0;
}

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

int main() {
  int A, B, C;
  cin >> A >> B >> C;

  if ((A == B && B != C) || (B == C && C != A) || (C == A && A != B))
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

  return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define y1 zzz
#define fi first
#define se second
#define PII pair<int,int>
#define PII2 pair<int,PII >
#define PII3 pair<PII,int >
#define PII4 pair<PII,PII >
#define all(x) (x).begin(),(x).end()
#define pb push_back
void solve()
{
    int a[5],k,res,ans=0;
    cin>>a[2]>>a[1]>>a[0]>>k;
    for(int i=2;i>=0;i--)
    {
        res=min(k,a[i]);
        k-=res;
        ans+=res*(i-1);
    }
    cout<<ans;
}
int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    //freopen("CUBE.inp","r",stdin);
    //freopen("CUBE.out","w",stdout);
    //int t;cin>>t;while(t--)
    solve();
    return 0;
}


Measured memory_bytes: 3640
from collections import defaultdict

def main():
    N, W = map(int, input().split())
    d = defaultdict(list)
    w1 = 0
    for i in range(N):
        w, v = map(int, input().split())
        if i == 0:
            w1 = w
        d[w].append(v)

    ans = 0
    d[w1].sort(reverse=True)
    d[w1 + 1].sort(reverse=True)
    d[w1 + 2].sort(reverse=True)
    d[w1 + 3].sort(reverse=True)

    for i in range(len(d[w1])+1):
        for j in range(len(d[w1+1])+1):
            for k in range(len(d[w1+2])+1):
                for l in range(len(d[w1+3])+1):
                    tmp = sum(d[w1][:i]) + sum(d[w1+1][:j]) + sum(d[w1+2][:k]) + sum(d[w1+3][:l])

                    if w1 * i + (w1+1) * j + (w1+2) * k + (w1+3) * l <= W:
                        ans = max(ans,tmp)

    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 63192
#include <iostream>
#include <vector>
#include <queue>
#include <string.h>
#include <math.h>
using namespace std;
typedef long long ll;

int main(void){
    int n, a, l = 1;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a;
        if (a % 2 == 0) l *= 2;
    }
    
    cout << pow(3, n) - l << endl;
    
}

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




int main() {


	string s;
	string nu;
	cin >> nu>>s>>nu;
	
		cout <<"A"<< s.at(0)<<"C" << endl;
	
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <numeric>
#include <regex>
#include <tuple>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
#define modulo 1000000007 // 10^9 + 7
#define INF 1000000000 // 10^9
#define LLINF 1LL<<60


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

	string S;
	cin >> S;
	stack<bool> V;
	int ans = 0;
	for (int i = 0; i < S.size(); i++) {
		bool c = (S[i] == '1');
		if (!V.empty() && V.top() != c) {
			V.pop();
			ans++;
		}
		else V.push(c);
	}
	cout << 2*ans << endl;

	return 0;
}

Measured memory_bytes: 512
N = int(input())
in_list = list(map(int,input().split()))
dp = list()
diff_1 = list()
diff_2 = list()

# diff_1
for i in range(1,N):
    diff_1.append(abs(in_list[i]-in_list[i-1]))

# diff_2
for i in range(2,N):
    diff_2.append(abs(in_list[i]-in_list[i-2]))

dp.append(0)
dp.append(diff_1[0])
for i in range(2,N):
    dp_diff = min(dp[i-1]+diff_1[i-1],dp[i-2]+diff_2[i-2])
    dp.append(dp_diff)
print(dp[-1])


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

class Node
{
    internal int key;
    internal Node left, right, parent;
    public Node(int key) {
        this.key = key;
    }
}

class B
{
    static Node root;
    public static void Main() {
        int n = int.Parse(Console.ReadLine());
        StringBuilder output = new StringBuilder();
        for (int i = 0; i < n; i++) {
            String[] input = Console.ReadLine().Split(' ');
            if (input[0] == "insert") {
                Insert(int.Parse(input[1]));
            }else if (input[0] == "find") {
                output.Append(find(root, int.Parse(input[1]))? "yes":"no");
                if (i != n - 1) {
                    output.AppendLine();
                }
            } else {
                Inorder(root, output);
                output.AppendLine();
                Preorder(root, output);
                if (i != n - 1) {
                    output.AppendLine();
                }
            }

        }
        Console.WriteLine(output);


    }
    static bool find(Node x, int key) {
        while (x != null) {
            if (x.key == key) {
                return true;
            }
            x = key < x.key ? x.left : x.right;
        }
        return false;
    }
    static void Insert(int key) {
        Node x = root;
        Node y = null;
        Node z = new Node(key);
        while (x != null) {
            y = x;
            x = z.key < x.key ? x.left : x.right;
        }
        z.parent = y;
        if (y == null) {
            root = z;
        }else if (z.key < y.key) {
            y.left = z;
        } else {
            y.right = z;
        }
    }
    static void Preorder(Node nodes, StringBuilder output) {
        if (nodes == null) {
            return;
        }
        output.Append(" " + nodes.key);
        Preorder(nodes.left, output);
        Preorder(nodes.right, output);
    }

    static void Inorder(Node nodes, StringBuilder output) {
        if (nodes == null) {
            return;
        }
        Inorder(nodes.left, output);
        output.Append(" " + nodes.key);
        Inorder(nodes.right, output);
    }

    /*static void Postorder(Node[] nodes, int num, StringBuilder output) {
        if (num == -1) {
            return;
        }
        Postorder(nodes, nodes[num].left, output);
        Postorder(nodes, nodes[num].right, output);
        output.Append(" " + num);
    }*/
}


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

#define TRACE(x) x
#define WATCH(x) TRACE(cout << #x" = " << x << endl)
#define WATCHR(a, b) TRACE(for (auto it=a; it!=b;) cout << *(it++) << " "; cout << endl)
#define WATCHC(V) TRACE({cout << #V" = "; WATCHR(V.begin(), V.end());})

#define all(x) (x).begin(), (x).end()

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;

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

vi bicolor(int N, int D) {
    vi root(D + 1, -1);
    for (int rt = 0; rt * rt <= D; rt++)
        root[rt * rt] = rt;

    int V = 2 * 2 * N * N;

    vvi adj(V);
    for (int i = 0; i < V; i++) {
        int x1 = i % (2 * N), y1 = i / (2 * N);
        for (int dx = 0; dx < 2 * N; dx++) {
            if (dx * dx > D) break;
            int dy = root[D - dx * dx];
            if (dy == -1) continue;

            if (x1 - dx >= 0 && y1 - dy >= 0) adj[i].push_back(x1 - dx + (2 * N) * (y1 - dy));
            if (x1 - dx >= 0 && y1 + dy < 2*N) adj[i].push_back(x1 - dx + (2 * N) * (y1 + dy));
            if (x1 + dx < 2*N && y1 - dy >= 0) adj[i].push_back(x1 + dx + (2 * N) * (y1 - dy));
            if (x1 + dx < 2*N && y1 + dy < 2*N) adj[i].push_back(x1 + dx + (2 * N) * (y1 + dy));
        }
    }

    vi res(V, -1);
    for (int rt = 0; rt < V; rt++) {
        if (res[rt] != -1) continue;
        for (queue<int> bfs({rt}); !bfs.empty(); bfs.pop()) {
            int loc = bfs.front();
            for (int nbr : adj[loc]) {
                if (res[nbr] == -1) {
                    res[nbr] = !res[loc];
                    bfs.push(nbr);
                }
                assert(res[nbr] == !res[loc]);
            }
        }
    }

    return res;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    int N, D1, D2;
    cin >> N >> D1 >> D2;

    vi c1 = bicolor(N, D1),
       c2 = bicolor(N, D2);

    for (int a = 0; a < 2; a++) {
        for (int b = 0; b < 2; b++) {
            int ct = 0;
            for (int i = 0; i < 2 * 2 * N * N; i++) {
                if (c1[i] == a && c2[i] == b)
                    ct++;
            }

            if (ct >= N * N) {
                int pr = 0;
                for (int i = 0; pr < N * N; i++) {
                    if (c1[i] == a && c2[i] == b) {
                        pr++;
                        cout << i % (2 * N) << " " << i / (2 * N) << "\n";
                    }
                }
                assert(pr == N * N);
                return 0;
            }
        }
    }

    assert(false);

    return 0;
}



Measured memory_bytes: 58624
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(100000)
 
 
def main():
    N = int(input().strip())
    X_list = [int(i) for i in input().strip().split()]
    sorted_x = sorted(X_list)
 
    left = sorted_x[(N // 2)-1]
    right = sorted_x[N // 2]
    for x in X_list:
        if x <= left:
            print(right)
        else:
            print(left)
 
 
if __name__ == "__main__":
    main()

Measured memory_bytes: 104988
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()

int main() {
   int k,x;
   cin >> k >> x;
   if(k==1)
   cout << x << endl;
   else 
   for(int i=x-k+1;i<=x+k-1;i++)
   cout << i << endl;
}

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

int main(){
    int n,k,s;
    cin >> n >> k >> s;
    if(s == 1000000000){//+1できない分は1にして計算すると超えない
        for(int i = 0; i < k; i++){
            cout << s << " ";
        }
        for(int i = 0; i < n-k; i++){
            cout << 1 << " ";
        }
        cout << endl;
    }else{//+1して表せば、条件を満たす。
        for(int i = 0; i < k; i++){
            cout << s << " ";
        }
        for(int i = 0; i < n-k; i++){
            cout << s+1 << " ";
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 1280
'use strict'

const main = input => {
	const args = input.split('\n').map(arg => arg.split(' '))
	const X = parseInt(args[0][0], 10)
	const t = parseInt(args[0][1], 10)
	console.log(Math.max(0, X - t))
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'))


Measured memory_bytes: 21192
//To compile : type "$     g++ test.cpp -std=c++14 -I .    "
#include <atcoder/all>
#include <bits/stdc++.h>
//#include <chrono>
//#pragma GCC optimize("Ofast")
using namespace std;
using namespace atcoder;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,Q,K,A,B;
string S;
typedef pair<ll, ll> P;
const ll INF = (1LL<<60);

int main() {
    cin>>H>>W;
    vector<string> s(H), ans(s);
	mf_graph<ll> G(H * W + 2);
    rep(i, H) cin>>s[i];
	ans = s;
    vector<int> dh = {-1, 0, 1, 0}, dw = {0, -1, 0, 1}; //片側のみ
    const int start = (int)(H * W), goal = start + 1;
    rep(h, H){
        rep(w, W){
            if(s[h][w] == '.'){
                int from, to;
                if((h + w)&1) {
                    from = start, to = h * W + w;
                    rep(i, 4){
                        int nh = h + dh[i], nw = w + dw[i];
                        if(nh >= 0 && nh < H && nw >= 0 && nw < W && s[nh][nw] == '.'){
                            G.add_edge(to, nh * W + nw, 1);
                        }
                    }
                }else {
                    from = h * W + w, to = goal;
                }
                G.add_edge(from, to, 1);
            }
        }
    }
    cout<<G.flow(start, goal)<<endl;
	auto edges = G.edges();
    vector<char> itoc = {'^', '<', 'v', '>'};
	for(auto &e : edges){
		if(e.from == start || e.to == goal || e.flow == 0) continue;
		int h0 = e.from / W, w0 = e.from % W;
		int h1 = e.to / W, w1 = e.to % W;
		rep(i, 4){
			if(h0 + dh[i] == h1 && w0 + dw[i] == w1){
				ans[h0][w0] = itoc[i];
				ans[h1][w1] = itoc[(i + 2) % 4];
			}
		}
	}
	rep(i, H) cout<<ans[i]<<endl;
}


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

const long long mod = 1e9 + 7;
const char use_char[4] = { 'A', 'G', 'C', 'T' };
map<string, long long> mp[101];

string update_string(string str, char c) {
  string ret = "";
  ret += str[1];
  ret += str[2];
  ret += c;
  return ret;
}

bool is_safe_string(string str) {
  if ( str[1] == 'A' && str[2] == 'G' && str[3] == 'C' ) { return false; }
  if ( str[1] == 'G' && str[2] == 'A' && str[3] == 'C' ) { return false; }
  if ( str[1] == 'A' && str[2] == 'C' && str[3] == 'G' ) { return false; }
  if ( str[0] == 'A' && str[2] == 'G' && str[3] == 'C' ) { return false; }
  if ( str[0] == 'A' && str[1] == 'G' && str[3] == 'C' ) { return false; }
  return true;
}

long long dfs(int dep, int goal, string bef) {
  if ( dep == goal ) { return 1; }
  if ( mp[dep].count(bef) == 1 ) { return mp[dep][bef]; }

  long long ret = 0;
  for ( int i = 0; i < 4; i++ ) {
    if ( is_safe_string(bef+use_char[i]) ) {
      ret += dfs(dep+1, goal, update_string(bef, use_char[i]));
      ret %= mod;
    }
  }
  mp[dep][bef] = ret;
  return ret;
}

int main() {
  int n;
  cin >> n;
  cout << dfs(0, n, "???") << endl;
  return 0;
}


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

int main() {
  int n, fx = 0;
  cin >> n;
  int tempN = n;
  
  int divider = 100000000;
  for (int i = 8; i >= 0; i--) {
    int divided = n / divider;
    fx += divided;
    n %= divider;
    divider /= 10;
  }
  
  n = tempN;
  
  if (n % fx == 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

// 1≦N≦10'8

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
typedef long long ll;
int main(){
ll n;
string s;
cin>>n>>s;
ll count=0;
ll max=0;
for(ll i=0;i<s.length();i++){
if(s[i]=='I'){
count++;
if(count>max)
max=count;
}
else if(s[i]=='D'){
count--;
}

}
cout<<max;

return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define BIT(n) (1LL << (n))
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPB(i, n) for (int i = 0; i < BIT(n); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORA(i, n) for (auto &&i : n)
#define FORS(i, m, n) for (int i = m; i <= n; i++)
#define DEBUG(x) cerr << #x <<": "<<x<<"\n"
#define ALL(v) v.begin(), v.end()
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define epb emplace_back
#define int long long
using namespace std;
template <class T> using vec = std::vector<T>;
template <class T = int> T in(){T x; cin>>x;return(x);}
template <class T > void print(T& x){cout<<x<<"\n";}
typedef long long ll;
const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N,M,X,Y;
  cin>>N>>M>>X>>Y;
  vec <int>x(N);
  vec <int>y(M);
  REP(i,N){
	  cin>>x[i];
  }
  REP(i,M){
	  cin>>y[i];
  }
  sort(ALL(x));
  reverse(ALL(x));
  int maxX=max(x[0],X);
  sort(ALL(y));
  int minY=min(y[0],Y);
  cout <<(minY-maxX>=1?"No War":"War")<<"\n";

}

Measured memory_bytes: 256
from itertools import groupby, accumulate, product, permutations, combinations
N = int(input())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))

n = 1
for p in permutations(range(1,N+1),N):
    if list(p)==P:
        a = n
    if list(p)==Q:
        b = n
    n += 1
ans = abs(a-b)
print(ans)

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

const int P = 1e9 + 7;
const int MAXN = 5.6E5;

int fac[MAXN];
int inv[MAXN];
int fInv[MAXN];
int n, ans, m;

inline int C(int a, int b)
{
	return (1ll * fac[b] * fInv[a] % P) * 1ll * fInv[b - a] % P;
}

inline int A(int a, int b)
{
	return 1ll * fac[b] * fInv[b - a] % P;
}

int main(void)
{
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	
	cin >> n >> m;
	
	fac[0] = fInv[0] = 1;
	fac[1] = fInv[1] = inv[1] = 1;
	for (int i = 2;i <= m; ++i)
		fac[i] = 1ll * fac[i-1] * i % P,
		inv[i] = 1ll * (P - P/i) * inv[P%i] % P,
		fInv[i] = 1ll * fInv[i - 1] * inv[i] % P;

	ans = A(n, m);
	for (int i = 1;i <= n; ++i)
		ans = (ans - 1ll * (i & 1) * C(i, n) * A(n - i, m - i) % P + 1ll * (i+1&1) * C(i, n) * A(n-i, m-i) % P + P) % P;
	ans = ((ans % P) + P) % P;
	ans = 1ll * ans * A(n, m) % P;
	cout << ans << '\n';
	
	return 0;
}

Measured memory_bytes: 9448
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
typedef long long ll;

using ipair = pair<int, int>;

ll INF = 1e16+7;
ll mod = 1e9+7;

bool operator>(const ipair a,const ipair b){return a.first > b.first;}

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

int main(){
  int N, X;
  cin >> N >> X;
  vector<int> x(N);
  rep(i, N) cin >> x[i];
  rep(i, N) x[i] = abs(x[i]-X);

  int ans = x[0];
  rep(i, N-1){
    ans = gcd(ans, x[i+1]);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main(){
	int N;
	cin >> N;
	vector<int> A(N);
	for(int i = 0; i < N; i++)
		cin >> A.at(i);
	sort(A.begin(), A.end());

	bool flg = true;
	for(int i = 1; i < N; i++)
		if(A.at(i) == A.at(i-1)){
			flg = false;
			break;
		}
		
	cout << (flg?"YES":"NO") << endl;

	return 0;
}

Measured memory_bytes: 1024
N = int(input())

flag = False

if N>81:
    print('No')
    
else:
    if N<10 :
        print('Yes')
    else:    
        for div in range(2,10):
            if (N % div)== 0 and (N // div)<10:
                print('Yes')
                flag =True
                break
          
        if not flag:     
            print('No')    


Measured memory_bytes: 3060
parseInt(x)=parse(Int, x)
parseMap(x::Array{SubString{String},1})=map(parseInt, x)
function moveup(x::Array{Int,1},n)
	k = length(x)
	for i in 1:k-1
		if x[k-i+1] > n-1
			x[k-i] += div(x[k-i+1],n)
			x[k-i+1] = x[k-i+1]%n
		end
	end
	if x[1] > n-1
		0
	else
		x
	end
end

function main()
	n,m,q = readline() |> split |> parseMap
	g = zeros(Int,10)
	e = Tuple{Int,Int,Int,Int}[(0,0,0,0) for i in 1:q]
	for i in 1:q
		a,b,c,d = readline() |> split |> parseMap
		e[i] = (a,b,c,d)
	end
	mx = 0
	while g!=0
		ct = 0
		for i in 1:q
			if g[e[i][2]]-g[e[i][1]]==e[i][3]
				ct+=e[i][4]
			end
		end
		mx = max(mx,ct)
		g[n]+=1
		g = moveup(g,m)
		if g!=0
			for i in 2:n
				g[i]=max(g[i],g[i-1])
			end
		end
	end
	println(mx)
end

main()

Measured memory_bytes: 173432
#include <assert.h>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <algorithm>
#include <numeric>
#include <functional>
#include <iostream>
#include <string>
#include <array>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <bitset>
typedef long long ll;
typedef unsigned long long ull;

# define INF 0x3f3f3f3f

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define DEBUG(vec) for (auto v : vec) { cout << v << " "; } cout << endl;

using namespace std;

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

  int N;
  cin >> N;

  ll dist = 0;
  int ct = 0;
  int cx = 0;
  int cy = 0;

  for (int i = 0; i < N; i++) {
    int t, x, y;
    cin >> t >> x >> y;
    ll dist = abs(cx - x) + abs(cy - y);
    if ((dist > t - ct) || (t - ct - dist) % 2 == 1) {
      cout << "No" << endl;
      return 0;
    }
    cx = x;
    cy = y;
    ct = t;
  }

  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
using namespace __gnu_pbds;
using namespace std;

typedef long long int lli;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<lli> vli;
typedef vector<pii> vii;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> OrderedSet;

const int MOD	= 1e9 + 7;
const double PI = acos(-1.0);

#define fastio			ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define sz(a) int((a).size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(auto &i : c)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define rep(i, n)    for(int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define fill(a)  memset(a, 0, sizeof (a))
#define error(x) cerr << #x << " = " << (x) << endl
#define errorp(p) cerr << #p << " = " << (p.first) << ", " << (p.second) << endl

template<typename T> T gcd(T a, T b){return(b?__gcd(a,b):a);}
template <typename T> T lcm(T a, T b){return (a*b)/gcd(a,b); }
int mul(int a, int b, int c){lli res=(lli)a*b;return (int)(res>=c?res%c:res);}
template<typename T>T power(T e, T n, T m){T x=1,p=e;while(n){if(n&1)x=mul(x,p,m);p=mul(p,p,m);n>>=1;}return x;}
int mod_neg(int a, int b, int c){int res;if(abs(a-b)<c)res=a-b;else res=(a-b)%c;return(res<0?res+c:res);}
template<typename T>T extended_euclid(T a, T b, T &x, T &y){T xx=0,yy=1;y=0;x=1;while(b){T q=a/b,t=b;b=a%b;a=t;\
t=xx;xx=x-q*xx;x=t;t=yy;yy=y-q*yy;y=t;}return a;}
template<typename T>T mod_inverse(T a, T n){T x,y,z=0;T d=extended_euclid(a,n,x,y);return(d>1?-1:mod_neg(x,z,n));}
template <class T>  inline void smax(T &x,T y){ x = max((x), (y));}
template <class T>  inline void smin(T &x,T y){ x = min((x), (y));}


int main(){
    #ifdef DEBUG
		freopen("test", "r", stdin);
	#endif
    fastio;
    
    int N, M;
    cin >> N >> M;

    
    vi h(N);
    rep(i, N){
        cin >> h[i];
    }

    vi vert[N];
    rep(i, M){
        int u, v;
        cin >> u >> v;
        u--; v--;
        vert[u].pb(v);
        vert[v].pb(u);
    }

    vi ans(N, -1);
    int count = 0;
    rep(i, N){
        if(ans[i] == -1){
            bool can = true;
            tr(vert[i], x){
                if(h[i] <= h[x]){
                    can = false;
                    break;
                }
            }
            if(can){
                count++;
                tr(vert[i], x){
                    ans[x] = 1;
                }
            }
        }
    }

    cout << count << endl;
    return 0;
}


Measured memory_bytes: 9208