akhauriyash/Code-Regression huggingface dataset:
N=int(input())
S=[input() for _ in range(N)]
min_v=200
for i in range(N):
  v=S[i].count('1')
  if v<min_v:
    min_v=v
start_candidates=[]
for i in range(N):
  start_candidates.append(i)
ans_lst=[]
for start in start_candidates:
  visited=[False for _ in range(N)]
  visited[start]=True
  current=[start]
  ans=1
  while True:
    flag=True
    candidates=[]
    for i in current:
      for j in range(N):
        if not visited[j] and S[i][j]=='1':
          candidates.append(j)
          visited[j]=True
    if not candidates:
      break
    #1 candidatesの中に辺を持つ頂点対があるとout
    for a in candidates:
      for b in candidates:
        if S[a][b]=='1':
          ans=-1
          flag=False
          break
      if not flag:
        break
    if not flag:
      break
    #1 end
    ans+=1
    current=candidates
  ans_lst.append(ans)
print(max(ans_lst))

Measured memory_bytes: 43884
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>

#define int long long
#define MOD 1000000007

#define rep(i, n) for (int i = 0; i < (n); i++)
#define itrep(i, a) for (auto i = (a).begin(); i != (a).end(); i++)
#define REP(i, a, n) for (int i = (a); i <= (n); i++)
#define all(a) (a).begin(), (a).end()

using namespace std;

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

template<class T> void inputVector(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < v.size(); i++) cin >> v[i];
}

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

	if (abs(N - M) >= 2) {
		cout << 0 << endl;
		return 0;
	}

	int ret = 1;
	REP(i, 1, N) {
		ret *= i;
		ret %= MOD;
	}
	REP(i, 1, M) {
		ret *= i;
		ret %= MOD;
	}
	
	if (N == M) {
		ret *= 2;
		ret %= MOD;
	}

	cout << ret << endl;

    return 0;
}


Measured memory_bytes: 256
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <vector>
#include <numeric>
#include <algorithm>
#include <iostream>
#include <string>
#include <cstring>
#include <sstream>
#include <functional>
#include <queue>
#include <deque>
#include <stack>
#include <cassert>
#include <bitset>

using namespace std;

using int64 = long long;

/////////////////////
// Code starts here//
/////////////////////
const int magic = 1000000007;

void add (int & a, int b) {
    a += b;
    if (a >= magic)
        a -= magic;
}

void sub (int & a, int b) {
    a -= b;
    if (a < 0)
        a += magic;
}

int mul (int a, int b) {
    return (int64)a * b % magic;
}

int FastPow(int a, int p) {
    if (!p) return 1;
    int res = FastPow(a, p >> 1);
    res = mul(res, res);
    if (p & 1) res = mul(res, a);
    return res;
}

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

    int N, K;
    cin >> N >> K;

    vector<int> dp(K + 1);
    int res = 0;
    for (int i = K; i >= 1; i--) {
        dp[i] = FastPow(K / i, N);
        for (int j = 2 * i; j <= K; j += i)
            sub(dp[i], dp[j]);
        add(res, mul(i, dp[i]));
    }

    cout << res << "\n";

    return 0;
}


Measured memory_bytes: 3708
#include<bits/stdc++.h>
using namespace std;
using ll =long long;
using Graph = vector<vector<int>>;
#define rep(i,N) for(int i=0;i<(N);++(i))
#define SORT(i) sort((i).begin(),(i).end())
constexpr int INF = 2000000000;
constexpr ll mod = 1000000007;

int main() {
	int N, A, B; cin >> N >> A >> B;
	A *= N;
	cout << min(A, B) << "\n";



	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define double long double
const int INF = (int)1e18 + 18;
const int maxn = (int) 1e6 + 6; 
using namespace std;

int a, b;

signed main() {
	cin >> a >> b;
	int ans = max(max(a + b, a - b), a * b );
  	cout << ans;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void)
{
  int m, d;
  
  while(1) {
    cin >> m >> d;
    if(m == 0) break;
    
    for(int i = m ; i > 1 ; i--) {
      if(i-1 == 4 || i-1 == 6 || i-1 == 9 || i-1 == 11) d += 30;
      else if(i-1 == 2) d += 29;
      else if(i-1 == 1 || i-1 == 3 || i-1 == 5 || i-1 == 7 || i-1 == 8 || i-1 == 10) d += 31;
    }
    
    if(d % 7 == 1) cout << "Thursday" << endl;
    if(d % 7 == 2) cout << "Friday" << endl;
    if(d % 7 == 3) cout << "Saturday" << endl;
    if(d % 7 == 4) cout << "Sunday" << endl;
    if(d % 7 == 5) cout << "Monday" << endl;
    if(d % 7 == 6) cout << "Tuesday" << endl;
    if(d % 7 == 0) cout << "Wednesday" << endl;
  }
  return 0;
}

Measured memory_bytes: 0
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
 

public class Main{
          
     
     public static void main(String args[]){
         BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
         
         try{
             String line;
            int scores[] = new int[101];// team 1 score -> scores[1]
            int ranks[] = new int[31]; // ranks[score] -> ranking 
            while((line=br.readLine())!= null){if(line.isEmpty())break;
                String[] spl=line.split(",");
                int n1 = Integer.parseInt(spl[0]);
                int n2 = Integer.parseInt(spl[1]); if(n1==0&&n2==0)break;
                scores[n1]+=n2;                
             }
             //System.out.println(Arrays.toString(scores));
             ranks[30]=1;ranks[29]=(getNum(scores,30)>=1&&getNum(scores,29)>=1)? 2: 1;
             for(int i=28; i>=0;i--){
                 ranks[i]=(getNum(scores,i)>=1)? ranks[i+1]+1:ranks[i+1];
             }
             //System.out.println(Arrays.toString(ranks));
             while((line=br.readLine())!= null){if(line.isEmpty())break;
                String[] spl=line.split(" ");
                int n1 = Integer.parseInt(spl[0]);
                 System.out.println(ranks[scores[n1]]);
             }
             br.close();
             
         }catch(Exception e){e.printStackTrace();}         
     }
   static int getNum(int[] array, int score){
       int count=0;
       for(int i=0; i<array.length; i++){
           if(array[i]==score){count++;
           break;}
       }
       return count;
   }
 }

Measured memory_bytes: 16904
N,W=map(int, input().split())
x=[list(map(int, input().split())) for i in range(N)]
#DPテーブルを作成
dp=[[0]*(W+1) for i in range(N)]
for i in range(N):
    for j in range(W+1):
        cnt=0
        if x[i][1]<=j:
            cnt=max(dp[i-1][j-x[i][1]]+x[i][0],dp[i-1][j])
        else:
            cnt=dp[i-1][j]
        dp[i][j]=cnt
print(dp[N-1][W])


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

#define L 12
#define MAX 20000000 // >4^12 TTTTTTTTTTTT 

int dic[MAX];

int getChar(char c){
  switch(c){
  case 'A':
    return 1;
  case 'C':
    return 2;
  case 'G':
    return 3;
  case 'T':
    return 4;
  }
  return 0;
}

int getKey(char *str){
  int sum,p,i;
  sum = 0;
  p = 1;
  
  for(i = 0; i < strlen(str); i++){
    sum += p * getChar(str[i]);
    p *= 5;
  }
  
  return sum;
}

int main(){
  int n,i;
  char com[6],s[L];

  scanf("%d",&n);
  for(i = 0; i < n; i++){
    scanf("%s %s",com,s);
    if(com[0] == 'i')
      dic[getKey(s)] = 1;
    else if(com[0] == 'f'){
      if(dic[getKey(s)])
	printf("yes\n");
      else
	printf("no\n");
    }
  }

  return 0;
}



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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

#define INF 1<<30
#define LINF 1ll<<60ll
#define MOD 1000000007
#define pb(a) push_back(a)

#define _overload3(_1,_2,_3,_4,name,...) name
#define _rep(i,n) _repi(i,0,n)
#define _repi(i,a,b) for(int i=a, i##_len=(b); i<i##_len; ++i)
#define _repis(i,a,b,s) for(int i=a, i##_len(b); i<i##_len; i+=s)
#define REP(...) _overload3(__VA_ARGS__,_repis,_repi,_rep,)(__VA_ARGS__)

#define REPR(i, n) for(int i = n;i >= 0;--i)
#define REPARR(i, v) for(int i = 0;i < sz(v);++i)

#define all(vec) (vec.begin()),(vec.end())
#define sz(x) ((int)(x).size())
#define bit(n) (1ll<<(n))

template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}

#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define yes(n) cout<<((n)?"yes":"no")<<endl
#define poss(n) cout<<((n)?"possible":"impossible")<<endl
#define Poss(n) cout<<((n)?"Possible":"Impossible")<<endl
#define POSS(n) cout<<((n)?"POSSIBLE":"IMPOSSIBLE")<<endl

int main(){
    int x;
    cin>>x;
    int a=0;
    REP(i,x+1){
        a+=i;
        if(a>=x){
            cout<<i<<endl;
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <fstream>
#include <bitset>
#include <queue>
#include <stack>
#include <deque>
#include <complex>

using std::cin;
using std::cout;
using std::cerr;
using std::endl;

using std::map;
using std::set;
using std::bitset;
using std::vector;
using std::string;
using std::multimap;
using std::multiset;
using std::deque;
using std::queue;
using std::stack;
using std::pair;
using std::iterator;

using std::sort;
using std::stable_sort;
using std::reverse;
using std::max_element;
using std::min_element;
using std::unique;
using std::ios_base;
using std::swap;
using std::min;
using std::max;
using std::fill;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef string S;

namespace MySpace{

};

#define F(i, n) for (int (i) = 0; (i) <= (n); (i)++)
#define fi first
#define se second
#define re return
#define all(x) (x).begin(), (x).end()
#define int long long

const long long MOD = 1e9 + 7;

const long long inf = 1e18;
const long long infsmart = 1e12;

ll dp[103][103][103];

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int a, b, c;
    cin >> a >> b >> c;
    F(i, 101)
        F(j, 101)
            F(k, 101)
                dp[i][j][k] = inf;
    long long ans = inf;
    dp[a][b][c] = 0;
    for (int i = 0; i < 101; i++)
    {
        for (int j = 0; j < 101; j++)
        {
            for (int k = 0; k < 101; k++)
            {
                //cout << i << " " << j << " " << k << endl;
                dp[i + 1][j + 1][k] = min(dp[i + 1][j + 1][k], dp[i][j][k] + 1);
                dp[i + 1][j][k + 1] = min(dp[i + 1][j][k + 1], dp[i][j][k] + 1);
                dp[i][j + 1][k + 1] = min(dp[i][j + 1][k + 1], dp[i][j][k] + 1);
                dp[i][j][k + 2] = min(dp[i][j][k + 2], dp[i][j][k] + 1);
                dp[i][j + 2][k] = min(dp[i][j + 2][k], dp[i][j][k] + 1);
                dp[i + 2][j][k] = min(dp[i + 2][j][k], dp[i][j][k] + 1);
            }
        }
    }
    F(i, 101)
        ans = min(ans, dp[i][i][i]);
    cout << ans;
}


Measured memory_bytes: 8832
inpl = lambda: list(map(int,input().split()))
def inv_mod(a, p):
    return pow(a, p-2, p)

def comb_mod(n,k,p):
    ans = 1
    k = min(k,n-k)
    if k < 0:
        return 0
    for i in range(k):
        ans = ans * (n-i) * inv_mod(k-i,p) % p
    return ans

MOD = 10**9+7
X, Y = inpl()
if (X+Y) % 3:
    print(0)
    exit()
N = (X+Y)//3
X -= N
Y -= N
Z = X + Y
print(comb_mod(Z,X,MOD))

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

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

#ifndef ONLINE_JUDGE
#define dbg(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;
#else
#define dbg(x)
#endif

#define X first
#define Y second

int main(){
    std::ios_base::sync_with_stdio(false);
    int n; cin >> n;
    vi arr(n);
    for (int i = 0; i < n; i++) cin >> arr[i];
    ll pairs = 0;
    for (int i = 0; i < n; i++){
        int num = arr[i];
        if (num & 1){
            if (i && arr[i-1]){
                pairs += (num + 1) / 2;
                arr[i] = 0;
            } else {
                pairs += num / 2;
                arr[i] = 1;
            }
        } else {
            if (i && arr[i-1]){
                if (num){
                    pairs += num / 2;
                    arr[i] = 1;
                }
            } else {
                pairs += num / 2;
                arr[i] = 0;
            }
        }
    }

    cout << pairs << endl;

    return 0;
}

Measured memory_bytes: 640
# -*- coding: utf-8 -*-

S = input()
T = input()

# 1対1の変換表
start = {}
goal = {}

for i in range(len(S)):
    s = S[i]
    t = T[i]
    # 変換表(変換前S)の該当箇所がまだ空いてるかどうか
    if s in start:
        # 埋まっている場合、今回の組み合わせと一致しているかどうか
        if start[s] != t:
            print('No')
            exit()
    # 空いていれば変換表を埋める
    else:
        start[s] = t
    # 変換後Tも同じようにやる
    if t in goal:
        if goal[t] != s:
            print('No')
            exit()
    else:
        goal[t] = s

print('Yes')

Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9 + 7);

int main(void) {
	int n;
	cin >> n;
	
	vector<ll> x(n);
	for(int i = 0; i < n; ++i) {
		cin >> x[i];
	}
	
	vector<ll> y = x;
	
	sort(y.begin(), y.end());
	
	for(int i = 0; i < n; ++i) {
		if( x[i] <= y[n / 2 - 1] ) cout << y[n / 2] << endl;
		else cout << y[n / 2 - 1] << endl;
	}
	
	return 0;
}


Measured memory_bytes: 6328
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()

from collections import defaultdict, deque, Counter
from sys import exit
import heapq
import math
import copy
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

N, M, Q = getNM()
lista = []
for i in range(Q):
    a, b, c, d = getNM()
    lista.append([a - 1, b - 1, c, d])

ans = 0
def dfs(i, numlist):
    if i == N:
        # numlistを元に得点計算
        cnt = 0
        for jud in lista:
            if numlist[jud[1]] - numlist[jud[0]] == jud[2]:
                cnt += jud[3]
        return cnt

    ans = 0
    # もしi = 0なら
    sta = 0
    # もしi != 0なら一個前の数字を参照
    if i > 0:
        sta = numlist[i - 1]
    # 1つ前の数字が1なら1 ~ 10までをdfs
    # 重複組み合わせ
    for j in range(sta, M):
        # 数字を記録
        numlist[i] = j
        ans = max(ans, dfs(i + 1, numlist))
    return ans
print(dfs(0, [0] * N))

Measured memory_bytes: 71868
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REP2(i, n) for (int i = 1; i <= (int)(n); i++)
#define FOR(i, m, n) for (int i = m; i n; i++)
#define SORT(x) sort(x.begin(), x.end())
#define REVE(x) reverse(x.begin(), x.end())
#define all(x) (x).begin(), (x).end()
struct initon
{
    initon()
    {
        cin.tie(0);
        ios::sync_with_stdio(false);
    };
};
int k=0,n=0, m=0, l=0,a=0, b=0, c=0, d=0,ans=0,ans2=0,x=0,y=0;
string s,t,S;
signed main() {
    cin >> n>>k>>s;
    //cin >> x >> y;
    //cin >> s >> t;
    vector<int> A(3);
    s[k-1] += 32;
    cout << s;
}

Measured memory_bytes: 3620
#include <stdio.h>
#include <assert.h>
#include <fstream>
#include <iostream>
#include <algorithm>
#include <array>
#include <vector>
#include <queue>
#include <set>
#include <cmath>
//#include <unordered_map>
//#include <unordered_set>
//#include <boost/container/static_vector.hpp>
//#include <boost/unordered_set.hpp>
//#include <boost/unordered_map.hpp>
//#include <unistd.h>

//#include <cv.h>
//#include <highgui.h>
#include <stdlib.h>
#include <string>

class Union_Find {
    public:
    std::vector<int> par;
    Union_Find() {}
    Union_Find(int n){
        par.resize(n, 0);
        for(int i = 0; i < n; i++){
            par[i] = i;
        }
    }

    void simplify(int x) {
        std::vector<int> path;
        while (par[x] != x) {
            path.push_back(x);
            x = par[x];
        }
        for (int p : path) {
            par[p] = x;
        }
    }
    
    int find(int x){
        simplify(x);
        return par[x];
    }
    
    void unite(int x, int y){
        x = find(x);
        y = find(y);
        if (x != y) {
            par[y] = x;
            // 改造する時は「根になっているノードの親を変更する」という原則が守られていることに注意。
        }
    }
};

const int MAX_N = 100050;
int N;
int w[MAX_N], u[MAX_N], v[MAX_N];

Union_Find uf = Union_Find(MAX_N * 2);


int main(int argc, char **argv) {
    std::cin >> N;
    
    for (int i = 1; i <= N - 1; i++) {
        std::cin >> u[i] >> v[i] >> w[i];
    }

    for (int i = 1; i <= N - 1; i++) {
        if (w[i] % 2 == 0) {
            uf.unite(u[i], v[i]);
            uf.unite(u[i] + N, v[i] + N);
        } else {
            uf.unite(u[i], v[i] + N);
            uf.unite(u[i] + N, v[i]);
        }
    }

    for (int i = 1; i <= N; i++) {
        if (uf.find(i) == uf.find(1)) {
            std::cout << "0" << std::endl;
        } else {
            std::cout << "1" << std::endl;
        }
    }

    
    return 0;
}


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

int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);

  int N;
  cin >> N;
  vector A(N, 0), B(N, 0);
  for (auto &a : A) cin >> a;
  for (auto &a : B) cin >> a;

  auto f = [&]() {
    for (int i = N - 1; i >= 0; i--) {
      if (A.at(i) == B.at(i)) return false;
    }
    cout << "Yes" << "\n";
    for (auto ans : B) cout << ans << "\n";
    return true;
  };

  reverse(B.begin(), B.end());
  if (f()) return 0;
  reverse(B.begin(), B.end());

  random_device rd;
  mt19937 mt(rd());

  auto start = chrono::system_clock::now();
  while ((chrono::system_clock::now() - start).count() < 1950000000) {
    rotate(B.begin(), B.begin() + mt() % N, B.end());
    if (f()) return 0;
  }
  cout << "No" << "\n";
}

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

int main(){
    int i, len;
    string n, result;
    cin >> n;
    len = n.length();
    for(i=0; i < len; i++){
        if((n[i] == '0') or (n[i] == '1') or (n[i] == 'B')){
            if((n[i] == '0') or (n[i] == '1')){
                result += n[i];
            } else {
                if(result.length() == 0){
                    continue;
                }else(result = result.substr(0, result.size()-1));
            }
        }else continue;
    }
    cout << result << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define printInt(a) printf("%d\n", a)
#define scanInt(a) scanf("%d", &a)
#define scan2Int(a, b) scanf("%d %d", &a, &b)
#define scan3Int(a, b, c) scanf("%d %d %d", &a, &b, &c)
using namespace std;

int main() {
    int a,b,c;
    scan3Int(a,b,c);
    if (a == b && a == c ||
        a != b && a != c && b != c)
        printf("No\n");
    else printf("Yes\n");
    return 0;
}


Measured memory_bytes: 3652
#include <iostream>
#define llint long long

using namespace std;

llint h, w, mod;
char c[2005][2005];
llint A[2005][2005], B[2005][2005], C[2005][2005], N[2005][2005];

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> h >> w >> mod;
	for(int y = 1; y <= h; y++){
		for(int x = 1; x <= w; x++){
			cin >> c[x][y];
		}
	}
	
	A[1][1] = 0, B[1][1] = 1, C[1][1] = c[1][1]-'0', N[1][1] = 1;
	for(int x = 1; x <= w; x++){
		for(int y = 1; y <= h; y++){
			if(x == 1 && y == 1) continue;
			llint A1 = A[x-1][y], A2 = A[x][y-1], B1 = B[x-1][y], B2 = B[x][y-1], C1 = C[x-1][y], C2 = C[x][y-1];
			llint N1 = N[x][y-1], N2 = N[x-1][y];
			
			if(c[x][y] == '*' || c[x][y] == '+'){
				B1 = C1, B1 %= mod;
				B2 = C2, B2 %= mod;
				C1 = C2 = 0;
			}
			if(c[x][y] == '+'){
				A1 += B1, A1 %= mod;
				A2 += B2, A2 %= mod;
				B1 = N1, B2 = N2;
			}
			if(c[x][y] != '+' && c[x][y] != '*'){
				C1 *= 10, C1 %= mod;
				C2 *= 10, C2 %= mod;
				C1 += B1 * (c[x][y]-'0') % mod, C1 %= mod;
				C2 += B2 * (c[x][y]-'0') % mod, C2 %= mod;
			}
			A[x][y] = A1 + A2, A[x][y] %= mod;
			B[x][y] = B1 + B2, B[x][y] %= mod;
			C[x][y] = C1 + C2, C[x][y] %= mod;
			N[x][y] = N1 + N2, N[x][y] %= mod;
		}
	}
	llint ans = A[w][h] + C[w][h]; ans %= mod;
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 132144
import itertools
import copy
from collections import deque
import heapq
x,y = map(int,input().split())
mi = 2*x
ma = 4*x
if y % 2 == 0:
    if mi <= y and ma >= y:
        print("Yes")
    else:
        print("No")
else:
    print("No")


Measured memory_bytes: 9648
#include <stdio.h>

using namespace std;

int main()
{
    int X, Y;
    scanf("%d %d", &X, &Y);
    if (X == 1 && Y == 1) {
        printf("1000000");
        return 0;
    }

    int total = 0;
    int bumon[2] = {X, Y};
    for (int i = 0; i < 2; i++) {
        switch (bumon[i]) {
            case 1:
                total += 300000;
                break;
            case 2:
                total += 200000;
                break;
            case 3:
                total += 100000;
                break;
        }
    }
    printf("%d", total);
}


Measured memory_bytes: 128
import java.io.*;
import java.util.*;


public class Main {
    public static void main (String[]args)throws IOException {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int M = scanner.nextInt();
        System.out.println((N*(N-1)+(M*(M-1)))/2);
    }
}


Measured memory_bytes: 21972
import java.util.Scanner;

public class Main { //クラス名はMain
    public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
      int N = in.nextInt();
      int hundreds = N / 100;
      int tens = (N / 10) % 10; // (n % 100) / 10
      int ones = N % 10;
       if ((hundreds == 7) || (tens == 7) || (ones == 7))
            System.out.println("Yes");
       else
            System.out.println("No");
        
  
    }
}

Measured memory_bytes: 35756
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i,n,k) for(int i=(n);i<(k);i++)
#define ALL(a)  (a).begin(),(a).end()
ll ans=0;
void Main(){
    int h, w, m;
    cin >> h >> w >> m;
    set<pair<int,int>> st;
    map<int,int> H, W;
    For(i,0,m){
        int a, b;
        cin >> a >> b;
        st.insert({a, b});
        H[a]++;
        W[b]++;
    }
    vector<int> x, y;
    int sz1 = 0, sz2 = 0;
    for(auto p:H){
        sz1 = max(sz1, p.second);
    }
    for(auto p:H){
        if(sz1 == p.second){
            x.emplace_back(p.first);
        }
    }
    for(auto p:W){
        sz2 = max(sz2, p.second);
    }
    for(auto p:W){
        if(sz2 == p.second){
            y.emplace_back(p.first);
        }
    }
    if(ll(x.size()) * ll(y.size()) > m) ans = sz1 + sz2;
    else{
        ans = sz1 + sz2 - 1;
        for(auto i:x){
            for(auto j:y){
                if(st.count({i, j}) == 0) ans = sz1 + sz2;
            }
        }
    }
    cout << ans << endl;
}
int main(){
    Main();
    /*
    東方風神録は神が出てくるので当然神ゲー
    */
    return 0;
}

Measured memory_bytes: 49516
#include<bits/stdc++.h>
using namespace std;
bool unbalance(string s){
    return (s[0]==s[1] || s[1]==s[2] || s[0]==s[2]);
}

int main(){
    string s;
    cin >> s;
    int n = s.length();
    bool chk = false;
    for(int i=0;i<n-2;i++){
        string t = s.substr(i,3);
        if(unbalance(t)){
            cout << i+1 << " "<< i+3<<endl;
            chk=true;
            break;
        }
    }
    if(n==2){
        if(s[0]==s[1]){
            cout<<1<<" "<<2<<endl;
            chk=true;
        }
    }
if(!chk)cout<<-1<<" "<<-1<<endl;
}

Measured memory_bytes: 512
fn main() {
    let (n, m): (usize, usize) = (read(), read());
    let mut x: Vec<i32> = Vec::new();
    for _i in 0..m {
        x.push(read());
    }

    if n >= m {
        println!("0");
        std::process::exit(0)
    }

    x.sort();
    let mut d = Vec::<i32>::new();
    for i in 0..m-1 {
        d.push(x[i+1] - x[i]);
    }
    d.sort();
    let ans: i32 = d.iter().take(m-n).sum();
    println!("{}", ans);
}


// 以下関数

use std::io::*;
use std::str::FromStr;
pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

pub const MOD: i64 = 1_000_000_007;

Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
int main()
{
long  a,b,c,d,e;
cin>>a;
b=a%10;
a/=10;
c=a%10;
a/=10;
d=a;
if(b==7||c==7||d==7)
    cout<<"Yes";
    else cout<<"No";


}



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

// #define int ll
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using si = set<int>;
using ii = pair<int, int>;
using vii = vector<ii>;

#define rep(i, n) for (int i = 0; i < n; i++)
#define dotc()    int tcs; if (cin >> tcs) rep(tc, tcs)
#define sz(x)     (int)x.size()
#define eb        emplace_back
#define pb        push_back
#define mp        make_pair
#define all(x)    x.begin(), x.end()
#define rall(x)   x.rbegin(), x.rend()
#define fi        first
#define se        second

int inf(0x3fffffff);
int mod(1000000007);
double pi(acos(-1.0));

int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
#ifdef LOCAL
  freopen("io\\in.txt", "r", stdin);
  freopen("io\\out.txt", "w", stdout);
#endif

  int n, x, y;
  cin >> n >> x >> y;
  x--, y--;
  vvi adj(n);
  rep(i, n - 1) {
    adj[i].pb(i + 1);
    adj[i + 1].pb(i);
  }
  adj[x].pb(y);
  adj[y].pb(x);

  vi cnt(n);
  for (int i = 0; i < n; i++) {
    unordered_map<int, int> dist;
    queue<int> q;
    dist[i] = 0;
    q.push(i);

    while (!q.empty()) {
      int cur = q.front();
      q.pop();

      int d = dist[cur] + 1;
      for (int p : adj[cur]) {
        if (dist.count(p)) continue;

        cnt[d]++;
        dist[p] = d;
        q.push(p);
      }
    }
  }
  rep(i, n - 1) cout << cnt[i + 1] / 2 << '\n';

  return 0;
}


Measured memory_bytes: 3820
// 失敗するからこそ そこから立ち向かって行く強さがあってそんな強さが本当の強さだと私は思うから
// ぜったいあきらめない
#if defined(DAIJOBU)
#include "/home/ichigo/includes.hpp"
#include "/home/ichigo/debug.hpp"
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#include <bits/stdc++.h>
#define deb(x...)
#endif
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

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

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long lint;
typedef vector<lint> vlint;
typedef vector<vlint> vvlint;
typedef pair<lint, lint> plint;
typedef double ld;

template<class T> bool chmin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool chmax(T &a, T b) { return a < b ? (a = b, true) : false; }



int main() {
    ios::sync_with_stdio(false);
	cin.tie(0);
	
	int r;
	cin >> r;
	if(r < 1200)puts("ABC");
	else if(r < 2800)puts("ARC");
	else puts("AGC");
	return 0;
}



Measured memory_bytes: 256
#include <cstring>
#include <map>
#include <unordered_map>
#include <string>
#include <list>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <cstdio>
#include <iostream>
#include <set>
#include <unordered_set>
using namespace std;

#define MAX(a,b) (a>b?a:b)
#define MIN(a,b) (a<b?a:b)
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int, int> pii;

int gi() {
    int a;
    scanf("%d", &a);
    return a;
}

ll gli() {
    ll a;
    scanf("%lld", &a);
    return a;
}

char a[10][1004];
int f[10], g[10];
pii p[10];
int pn, k;

int badf(int *f) {
    for (int i = 0; i < pn; i++)
        if (f[i] > k)
            return 1;
    return 0;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n = gi();
    int m = gi();
    k = gi();
    for (int i = 0; i < n; i++)
        scanf("%s", a[i]);

    int res = n*m;
    int t = (1<<(n-1));
    while (--t >= 0) {
        pn = 1;
        p[0] = {0, 1};
        int tt = t;
        for (int i = 1; i < n; i++) {
            if (tt%2) {
                p[pn++] = {i, i+1};
            } else {
                p[pn-1].second++;
            }
            tt/=2;
        }
        int alt = pn-1;
        memset(f, 0, sizeof(f));
        int bad = 0;
        for (int j = 0; j < m; j++) {
            memset(g, 0, sizeof(g));
            for (int i = 0; i < pn; i++)
                for (int ii = p[i].first; ii < p[i].second; ii++)
                    g[i] += a[ii][j]-'0';
            if (badf(g)) {
                bad = 1;
                break;
            }
            for (int i = 0; i < pn; i++) {
                f[i] += g[i];
                if (f[i] > k) {
                    alt++;
                    memcpy(f, g, sizeof(f));
                    break;
                }
            }
        }
        if (!bad)
            res = MIN(res, alt);
    }

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

    return 0;
}


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

typedef long long ll;

using namespace std;

const int MAX_M=100;

int m;
char str[MAX_M][MAX_M];

int solve(const string &s){
    set<string> ss;
    ss.insert(s);
    string r(s.rbegin(),s.rend());
    for(string::size_type i=1;i < s.length();i++){
        string s0(s,0,i);
        string s1(s,i);
        string r0(s0.rbegin(),s0.rend());
        string r1(s1.rbegin(),s1.rend());
        ss.insert(s0+r1);
        ss.insert(r0+s1);
        ss.insert(r0+r1);
        ss.insert(s1+r0);
        ss.insert(s1+s0);
        ss.insert(r1+s0);
    }
    return ss.size();

}

int main(){
    string str;
    scanf("%d",&m);
    for(int i=0;i<m;i++){
        cin >> str;
        cout << solve(str) << endl;
    }

}


Measured memory_bytes: 3216
import bisect
N = int(input())
L = list(map(int,input().split()))
ans = (N*(N-1)*(N-2))//6
L.sort()
for i in range(N-1,-1,-1):
    for j in range(i-1,-1,-1):
        ans -= bisect.bisect_right(L[:j],L[i]-L[j])
print(ans)



Measured memory_bytes: 51240
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define REP(i,n) for(int i=0;i<n;i++)
#define ALL(N) (N.begin(),N.end())

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, sum=0, A, B;
  cin >> N;
  string ans="Yes";
  vector<pair<int,int>> v;
  REP(i,N) {
    cin >> A >> B;
    v.pb({B,A});
  }
  sort ALL(v);
  REP(i,N) {
    sum+=v[i].second;
    if(sum>v[i].first) {
      ans="No";
      break;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 2420
import sys
 
k, n = map(int, sys.stdin.readline().split())
a = [int(i) for i in sys.stdin.readline().split()]
a.sort()
max_dist = 0
for i in range(1, n):
	max_dist = max(a[i] - a[i - 1], max_dist)
    
if len(a) != 0:
	max_dist = max(a[0] + k - a[-1], max_dist)
sys.stdout.write(str(k - max_dist))

Measured memory_bytes: 24884
n = int(input())
h = [int(i) for i in input().split()]
dp = [1000000] * (n)
dp[0] = 0
dp[1] = abs(h[1] - h[0])
for i in range(1, n - 1):
  dp[i+1] = min([dp[i] + abs(h[i+1] - h[i]),dp[i - 1] + abs(h[i+1] - h[i-1])])
print(dp[n-1])

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

int main() {
  string a,b,c;
  cin>>a>>b>>c;
  char d=a.at(0)-0x20;
  char e=b.at(0)-0x20;
  char f=c.at(0)-0x20;
  cout<<d<<e<<f<<endl;
}


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

int main(void){
    long long n, a, b, bl, cnt, amari;
    scanf("%lld %lld %lld", &n, &a, &b);
    cnt = n/(a+b);
    bl = cnt*a;
    amari = n%(a+b);
    if(amari <= a)
      bl += amari;
    else
      bl += a;
    printf("%lld", bl);

    return 0;
}


Measured memory_bytes: 128
using System;

namespace testapp
{
    //A君は全てのページ数が合わせてNの書類を紙の両面に印刷する
    //N%2==1ならばN/2+1
    //N%2==0ならばN/2
    class Program
    {
        static void Main(string[] args)
        {
            var input = int.Parse(Console.ReadLine());
            if(input%2==1) Console.WriteLine(input / 2 + 1);
            if (input % 2 == 0) Console.WriteLine(input / 2);
        }
    }
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
#define SORT(x) sort(x.begin(),x.end())
#define ALL(x) x.begin(),x.end()
#define rep(i, n) for(int i = 0; i < n; i++)
#define reps(i, m, n) for(int i = m; i < n; i++)
#define repr(i, m, n) for(int i = m; i >= n; i--)
#define INF 1000000007 //1000000000000000003
#define PI (acos(-1))
#define MOD 1000000007
using namespace std;
typedef long long ll;

struct edge{ll to;};
struct graph{
  ll N; //ノードの個数
  vector<vector<edge> > G;
  vector<ll> parent;
  vector<ll> depth;
  int x,y;

  graph(ll n){
    N = n;
    G.resize(N);
    parent.resize(N);
    depth.resize(N);
    rep(i,N){depth[i] = -1;}
  }
  void add_edge(ll s, ll t){
    G[s].emplace_back((edge){t});
  }

  void dfs(ll v=0, ll p=0, ll d=0){
    parent[v] = p;
    depth[v] = d;
    for(auto E : G[v]){ // E つなぐエッジ
      if((v==x and E.to==y) or (v==y and E.to==x)) continue;
      if(depth[E.to] == -1) dfs(E.to , v , d+1); //まだ行ってないなら
    }
  }
};


void Main(){

  int N,M;
  cin>>N>>M;

  graph g(N);

  vector<pair<int,int>> pe;

  rep(i,M){
    int a,b; cin>>a>>b; --a;--b;
    pe.emplace_back(a,b);
    g.add_edge(a,b);
    g.add_edge(b,a);
  }

  int ans=0;

  rep(i,M){
    g.x=pe[i].first; g.y=pe[i].second;
    rep(i,N){g.depth[i] = -1;}
    g.dfs();
    bool ng=false;
    rep(j,N){
      if(g.depth[j]==-1) ng=true;
    }
    ans+=ng;
  }

  cout<< ans<<"\n";

}

//-----------------------------------
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
}
//-----------------------------------


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

using namespace std;
const int N = 1e5+5;
typedef long long ll;
int n;
ll lx[N],rx[N],ly[N],ry[N];
struct node {
	ll l,r;
}a[N];
bool cmp(node a,node b){
	return a.l<b.l;
}

int main(){
	cin>>n;
	ll maxx=0,minn=1e18,ans1,maxlen=0;
	for(int i=1;i<=n;i++){
		cin>>a[i].l>>a[i].r;
		maxx=max(a[i].l,maxx);
		minn=min(a[i].r,minn);
		maxlen=max(a[i].r-a[i].l+1,maxlen);
	}
	ans1=maxlen+max(minn-maxx+1,0ll);
	sort(a+1,a+n+1,cmp);
	lx[1]=a[1].l;rx[1]=a[1].r;
	ll rq=a[1].r;
	for(int i=2;i<=n;i++){
		lx[i]=max(lx[i-1],a[i].l);
		rx[i]=min(rx[i-1],a[i].r);
		rq=min(rq,a[i].r);
	}
	ry[n]=a[n].r;ly[n]=a[n].l;
	ll lp=a[n].l;
	for(int i=n-1;i>=1;i--){
		ry[i]=min(a[i].r,ry[i+1]);
		ly[i]=max(a[i].l,ly[i+1]);
		lp=max(lp,a[i].l);
	}
//	cout<<ans1<<endl;
	ll ans2=0;
//	for(int i=1;i<=n-1;i++){
//		ans2=max(ans2,max(rx[i]-lx[i]+1,0ll)+max(ry[i+1]-ly[i+1]+1,0ll));
//	}
	for(int i=1;i<=n-1;i++){
		ans2=max(ans2,max(rq-lx[i]+1,0ll)+max(ry[i+1]-lp+1,0ll));
	}
//	cout<<ans2<<endl;
	cout<<max(ans1,ans2)<<endl;
	
	return 0;
}

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

#define rep(i, a, n)  for(ll i=a; i<n; i++)
#define per(i, a, n)  for(ll i=n-1; i>=a; i--)
#define fill0(n)  setfill('0') << right << setw(n)
#define all(x)  (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define LONGMAX 1e18
#define intMAX 1000000000
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod = 1e9+7;

int n;
vector<P> graph[100100];
int main(){
	int a, b;
	cin >> n;
	for(int i = 0; i < n-1; i++){
		cin >> a >> b;
		graph[a-1].push_back(P(b-1, i));
		graph[b-1].push_back(P(a-1, i));
	}
	queue<int>q;
	vector<int>used(n);
	vector<int> ans(n-1);
	q.push(0);
	used[0] = 1; 
	while(!q.empty()){
		int v = q.front(); q.pop();
		int c = -1;
		// 親の辺の色を見ている．
		for(int i=0; i < graph[v].size(); i++){
			int u = graph[v][i].first;
			int id = graph[v][i].second;
			if(used[u]) c = ans[id];
		}
		int k = 1;
		for(int i = 0; i < graph[v].size(); i++){
			int u = graph[v][i].first;
			int id = graph[v][i].second;
			if(used[u])continue;
			if(k == c) k++;
			ans[id] = k; k++;
			q.push(u);
			used[u] = 1;
		}
	}

	int max_k = 0;
	for(int i = 0; i < n; i++) max_k = max(max_k, int(graph[i].size()));
	cout << max_k << endl;
	for(int i = 0; i < ans.size(); i++)cout << ans[i] << endl;
	return 0;
}

Measured memory_bytes: 8704
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
#define mp make_pair
#define pb push_back
#define f first
#define s second


//var 
int n,m,k;
char a[7][7];
char b[7][7];

int counter(){
  int ans = 0;
  for(int i = 1; i <= n; i++){
    for(int j = 1; j <=m; j++){
      if(b[i][j] == '#'){
        ans++;
      }
    }
  }
  return ans;
}

int main(){
    ios_base::sync_with_stdio(0); 
    cin.tie(0);
    
    int sol = 0;
    cin >> n >> m >> k;

    for(int i = 1; i <= n; i++){
      for(int j = 1; j <=m; j++){
        cin >> a[i][j];
        b[i][j] = a[i][j];
      }
    }
    for(int i = 1; i <= pow(2,n+m); i++){
      for(int j = 1; j <= n; j++){
        for(int k = 1; k <=m; k++){
          b[j][k] = a[j][k];
        }
      }
      for(int k = 1; k <= n; k++){
        if((int(i/(pow(2,(k-1))))%2) == 0){
          for(int j = 1; j <=m; j++){
            b[k][j] = '.';
          }
        }
      }
      for(int k = 1; k <= m; k++){
        if((int(i/(pow(2,(k+n-1))))%2) == 0){
          for(int j = 1; j <= n; j++){
            b[j][k] = '.';
          }
        }
      }
      if(counter() == k){
        sol++;
      }
    }
    cout << sol << endl;
    cout.flush();
    return 0;
}

Measured memory_bytes: 4112
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()

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

    cout << n / 3 << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <math.h>
#include <string>
#include <numeric>
#include <algorithm>
#include <utility>


using std::cout;
using std::cin;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;


ll gcd(ll a, ll b) {
    while (b != 0) {
        auto tmp = a;
        a = b;
        b = tmp % a;
    }
    return a;
}

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

int isPrime(int a) {
    for (int i = 2; i * i <= a; ++i) {
        if (a % i == 0) {
            return 0;
        }
    }
    return 1;
}





void oneCase () {
    int n, m;
    cin >> n >> m;

    vector<string> lines(n);
    for (auto& l : lines) {
        cin >> l;
    }
    for (int i = 0; i < m + 2; ++i) {
        cout << "#";
    }
    for (auto line : lines) {
        cout << "\n";
        cout << "#" << line << "#";
    }
    cout << "\n";
    for (int i = 0; i < m + 2; ++i) {
        cout << "#";
    }
}




int main() {
    int t = 1;
//    cin >> t;
    while (t > 0) {
        oneCase();
        --t;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std ;
const int Mod = 1000000007 ;
const int MaxN = 100 + 10 ;
const int MaxM = 1000000 + 10 ;
int N , M , K , Dp[2][MaxM] , Len[MaxM] , Max[MaxM] , Bit ;
map<int,int> Map ;
int main() {
//	freopen( "noname.in" , "r" , stdin ) ;
//	freopen( "noname.out" , "w" , stdout ) ;
	scanf( "%d%d" , &M , &N ) ;
	for(register int L = 1 , R ; L <= M ; L = R + 1 ) {
		R = M / ( M / L ) ;
		Map[R] = ++K ;
		Len[K] = R - L + 1 ;
		Max[K] = R ;
	}
	for(register int i = 0 ; ++i <= K ; )
		Dp[0][i] = Dp[0][i-1] + Len[i] ;
	while( --N ) {
		Bit ^= 1 ;
		for(register int i = 0 ; ++i <= K ; )
			Dp[Bit][i] = ( Dp[Bit][i-1] + 1ll * Len[i] * Dp[Bit^1][Map[M/Max[i]]] % Mod ) % Mod ;
	}
	return not printf( "%d\n" , Dp[Bit][K] ) ;
}

Measured memory_bytes: 11648
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
using namespace std;
typedef long long ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define in(x) cin >> x
#define out(str) cout << str << endl

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

ll N,M,ans;

int main(){
    cin>>N>>M;
    vector< pair<ll,ll> > drink(N);
    rep(i,N){
        cin>>drink[i].first>>drink[i].second;
    }
    sort(drink.begin(),drink.end());
    rep(i,N){
        if(M>drink[i].second){
            ans+=drink[i].first*drink[i].second;
            M-=drink[i].second;
        }
        else{
            ans+=drink[i].first*M;
            break;
        }
    }
    out(ans);
}


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

using namespace std;
using ll = long long;
typedef pair<int, int> ii;
typedef vector<ii> vii; 
typedef vector<int> vi;

ll dp[55][3005];
// dp[i][j] means i length and sum j
int a[55];
int main() {
    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   
    int n,av;
    scanf("%d%d",&n,&av);
    int i;
    for(i=1;i<=n;i++)scanf("%d",&a[i]);
    dp[0][0] = 1;
    int j,k;
    for(i=1;i<=n;i++)
        {
        for(j=i-1;j>=0;j--)
            {
            for(k=0;k<=2500;k++)
                {
                int cur = k + a[i];
                dp[j+1][cur] += dp[j][k];
            }
        }
    }
    ll ans = 0;
   for(int len = 1; len<=n;len++)
       {
       ans += dp[len][av*len];
   }
    printf("%lld\n",ans);
    return 0;
}

//int main() {
//	ios_base::sync_with_stdio(false); cin.tie(0), cout.tie(0);
//	
//	ll n, a, x[55], dp[55][3005];
//	cin >> n >> a;
//	for(int i=1;i<=n;i++) {
//		cin >> x[i];
//	}
//	
//	for(int i = 0; i < 55; i++)
//		for(int j = 0; j < 3005; j++)
//			dp[i][j] = 0;
//			
//	dp[0][0] = 1;
//	for(int i = 1; i <= n; i++) {
//		for(int len = i - 1; len >= 0; len--) {
//			for(int k = 0; k <= 2500; k++) {
//				int cur = k + x[i];
//				dp[len + 1][cur] = dp[len][k];
//			}
//		}
//	}
//	
//	ll ans = 0;
//	for(int len = 1; len <= n; len++) {
//		ans += dp[len][a * len];
//	}
//	
//	cout << ans << endl;
//}

Measured memory_bytes: 1408
#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
typedef long long ll;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};

int main(){
    string s;cin>>s;
    int ans=s.size();
    char c;
    c=s[0];
    int flag=0;
    for(int i=1;i<s.size();i++){
        if(flag==i){
            c='A';
            continue;
        }
        if(c==s[i]){
            flag=i+1;
            ans--;
            c='A';
        }
        c=s[i];
    }
    cout<<ans<<endl;
}

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

int main(){
  int N;
  int L;
  int sum;
  int ans;
  cin >> N >> L;
  sum = N*(N+2*L-1)/2;
  if(L > 0){
    ans = sum - L;
  }
  else if(L+N<1){
    ans = sum - (L + N - 1);
  }
  else{
    ans = sum;
  }
  cout << ans << endl;
}
    

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll mod=1e9+7;
int n;
ll c,h[310000],dp[310000];
struct node{
	ll x,y;
}q[310000];
int main(){
	cin>>n>>c;
	for(int i=1;i<=n;++i){
		cin>>h[i];
	}
	int r=0,f=1;
	q[++r]=(node){-2*h[1],h[1]*h[1]};
	for(int i=2;i<=n;++i){
		while(f<=r&&h[i]*q[f+1].x+q[f+1].y<h[i]*q[f].x+q[f].y){
			f++;
		}
		dp[i]=q[f].y+h[i]*q[f].x+h[i]*h[i]+c;
		ll x=-2*h[i],y=dp[i]+h[i]*h[i];
		while(f<=r&&(y-q[r].y)*(q[r].x-q[r-1].x)>(x-q[r].x)*(q[r].y-q[r-1].y)){
			r--;
		}
		q[++r]=(node){x,y};
	}
	cout<<dp[n]<<'\n';
	return 0;
}

Measured memory_bytes: 9088
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define sqr(x) ((x)*(x))
#define mp make_pair
#define uint unsigned
#define PI pair<int,int>
inline char gc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline int read(){
	int x = 0; char ch = gc(); bool positive = 1;
	for (; !isdigit(ch); ch = gc())	if (ch == '-')	positive = 0;
	for (; isdigit(ch); ch = gc())	x = x * 10 + ch - '0';
	return positive ? x : -x;
}
inline void write(int a){
    if(a<0){
    	a=-a; putchar('-');
	}
    if(a>=10)write(a/10);
    putchar('0'+a%10);
}
inline void writeln(int a){
    if(a<0){
    	a=-a; putchar('-');
	}
	write(a); puts("");
}
inline int rnd(int x){
	return rand()%x;
}
inline ull rnd(){
	return ((ull)rand()<<30^rand())<<4|rand()%4;
}
const int N=200005;
int n,vis[N],f[N],g[N],dp[N],p[N],tong[N];
vector<int> v[N];
void dfs(int p){
	for(unsigned i=0;i<v[p].size();i++){
		dfs(v[p][i]);
	}
	for(unsigned i=0;i<v[p].size();i++)tong[dp[v[p][i]]]=1;
	for(int j=0;;j++)if(!tong[j]){dp[p]=j; break;}
	for(unsigned i=0;i<v[p].size();i++)tong[dp[v[p][i]]]=0;
}
int main(){
	n=read();
	for(int i=1;i<=n;i++)v[p[i]=read()].push_back(i);
	for(int i=1;;i=p[i]){
		vis[i]++; if(vis[i]>2)break;
	}
	for(int i=1;i<=n;i++)if(vis[i]>=2){
		for(unsigned j=0;j<v[i].size();j++)if(vis[v[i][j]]<2){
			dfs(v[i][j]);
		}
		for(unsigned j=0;j<v[i].size();j++)if(vis[v[i][j]]<2)tong[dp[v[i][j]]]=1;
		f[i]=g[i]=-1;
		for(int j=0;;j++)if(!tong[j]){
			if(f[i]==-1)f[i]=j; else if(g[i]==-1)g[i]=j; else break;
		}
		//cout<<f[i]<<" "<<g[i]<<endl;
		for(unsigned j=0;j<v[i].size();j++)tong[dp[v[i][j]]]=0;
	}
	for(int i=1;i<=n;i++)if(vis[i]>=2){
		dp[i]=f[i];
		for(int j=i;;j=p[j]){
			//cout<<j<<" "<<dp[j]<<endl;
			if(p[j]==i){
				if(dp[j]!=dp[i]){
					puts("POSSIBLE"); return 0;
				}
				break;
			}
			dp[p[j]]=f[p[j]]==dp[j]?g[p[j]]:f[p[j]];
		}
		dp[i]=g[i];
		for(int j=i;;j=p[j]){
			if(p[j]==i){
				if(dp[j]==f[i]){
					puts("POSSIBLE"); return 0;
				}
				break;
			}
			dp[p[j]]=f[p[j]]==dp[j]?g[p[j]]:f[p[j]];
		}
		puts("IMPOSSIBLE"); return 0;
	}
}

Measured memory_bytes: 14848
#include <cstdlib>
#include <string>
#include <sstream>
#include <iostream>

std::string sec_to_hms(int sec) {
    std::div_t d = std::div(sec, 60);
    int s = d.rem;
    d = std::div(d.quot, 60);
    int m = d.rem;
    int h = d.quot;
    std::stringstream ss;
    ss << h << ":" << m << ":" << s;
    return ss.str();
}

int main() {
    int sec;

    std::cin >> sec;
    std::cout << sec_to_hms(sec) << std::endl;

    return EXIT_SUCCESS;
}

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

int main( )
{
    int k, x;
    int d;
    cin >> k >> x;
    d = k * 500;
    if (d >= x) {
        cout << "Yes\n";
    }
    else {
        cout << "No\n";
    }
    return 0;
}


Measured memory_bytes: 256
import itertools

n,m=map(int,input().split())
l=[i for i in range(1,n)]
g=[[] for _ in range(n)]
for _ in range(m):
    a,b=map(int,input().split())
    g[a-1].append(b-1)
    g[b-1].append(a-1)

res = 0
for sp in itertools.permutations(l):
    flag = 1
    s = 0
    for i in range(n-1):
        if not (sp[i] in g[s]):
            flag = 0
            break
        else:
            s = sp[i]
    if flag == 1:
        res += 1

print(res)

Measured memory_bytes: 39792
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <bitset>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>

using namespace std;

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

Measured memory_bytes: 5116