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

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

const ll MAX = 1e5 + 10;
const ll MOD = 1e9 + 7;

string L;

int main(){
    cin >> L;

    ll dp[MAX];
    ll ans = 1;
    for(int i = 0; i < L.size(); ++i){
        
        int j = L.size() - 1 - i;
        if(L[j] == '0'){
            dp[i] = ans * 2 % MOD;
        } else {
            dp[i] = 0;
        }
        
        ans = ans * 3 % MOD;
    }

    ll a = 1;
    for(int i = 0; i < L.size(); ++i){
        int j = L.size() - 1 - i;
        ll tmp = a * dp[j] % MOD;
        ans = ans - tmp % MOD;
        if(ans < 0) ans += MOD;
        if(L[i] == '1'){
            a = a * 2 % MOD;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 1280
/* ABC-A.c
   Yuta Takayanagi */

#include<stdio.h>
int main(void){
    int x, a;

    scanf( "%d %d" , &x, &a);

    if(x<a){

        printf( "0\n" );

    }else{

        printf( "10\n" );

    }

    return 0;
}

Measured memory_bytes: 128
A,B,K = map(int,input().split(' '))

num_list = []
for i in range(1,min(A,B)+1,1):
  if A % i == 0 and B % i == 0:
    num_list.append(i)

num_list = sorted(num_list,reverse = True)
print(num_list[K-1])

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define fill(x,v) memset(x, v, sizeof(x))
#define PI (ld)acos(-1)
#define endl '\n'
#define dbg(x) cout<<#x<<"="<<(x)<<endl;
#define dbg2(x,y) cout<<#x<<"="<<(x)<<" "<<#y<<"="<<(y)<<endl; 
#define fio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); 
#define IO freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
const ld eps=(ld)1e-9;
const ll inf=(ll)1e9;
const ll mod=(ll)1e9+7;


void solve(){
	int n,k;
	cin>>n>>k;
	int h[n];
	for (int i = 0; i < n; ++i)
	{
		cin>>h[i];
	}
	vector<int>dp(n,inf);
	dp[0]=0;
	for (int i = 0; i < n; ++i)
	{
		for (int j = i+1; j<=i+k; j++)
		{
			if(j<n){
				dp[j]=min(dp[j],dp[i]+abs(h[j]-h[i]));
			}
		}
	}
	cout<<dp[n-1];
}

int main(){fio;
int test=1;
// cin>>test;
while(test--){
	solve();
	cout<<endl;
}
return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
typedef long long LL;
typedef pair<int, int> pii;
 
#define fst first
#define snd second
#define pb push_back
#define eb emplace_back
#define REP(i, a, b)  for(int i = (a), i##end = (b); i < i##end; ++i)
#define DREP(i, a, b) for(int i=(a-1), i##end = (b); i >=i##end; --i)
 
template <typename T> bool chkmax(T& a, T b) { return a < b ? a = b, 1 : 0; }
template <typename T> bool chkmin(T& a, T b) { return a > b ? a = b, 1 : 0; }
 
const int oo = 0x3f3f3f3f;
const int maxn = 200000 + 10; 

template<typename T> T read() {
    T n(0), f(1);
    char ch = getchar();
    for( ;!isdigit(ch); ch = getchar()) if(ch == '-') f = -1;
    for( ; isdigit(ch); ch = getchar()) n = n * 10 + ch - 48; 
    return n * f;
}

int n;
int a[maxn];
LL s[maxn];

int main() {
#ifdef Wearry
    freopen("data.txt", "r", stdin);
    freopen("ans.txt", "w", stdout);
#endif
    
    cin >> n;
    for(int i = 1; i <= n; ++i) cin >> a[i], s[i] = s[i-1] + a[i];

    LL ans = LLONG_MAX;

    for(int i = 1; i < n; ++i) 
        ans = min(ans, abs(s[i] - (s[n] - s[i])));

    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 2560
#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<vector>
#include<queue>
#include<stack>
#include<cmath>
#include<list>
using namespace std;

struct node{int key; node *right,*left,*parent;};
node *root,*NIL;

void insert(int k)
{
	node *y=NIL;
	node *x=root;
	node *z;
	
	z=(node *)malloc(sizeof(node));
	z->key=k;
	z->left=NIL;
	z->right=NIL;
	
	while(x!=NIL)
	{
		y=x;
		if(z->key < x->key)
		{
			x=x->left;
		}
		else
		{
			x=x->right;
		}
	}
	
	z->parent=y;
	if(y==NIL)
	{
		root=z;
	}
	else
	{
		if(z->key < y->key)
		{
			y->left=z;
		}
		else
		{
			y->right=z;
		}
	}
}

void ino(node *u)
{
	if(u==NIL)return;
	ino(u->left);
	printf(" %d",u->key);
	ino(u->right);
}

void preo(node *u)
{
	if(u==NIL)return;
	printf(" %d",u->key);
	preo(u->left);
	preo(u->right);
}

int main()
{
	int n,i,x;
	string com;
	
	scanf("%d",&n);
	
	for(i=0;i<n;i++)
	{
		cin>>com;
		if(com=="insert")
		{
			scanf("%d",&x);
			insert(x);
		}
		else if(com=="print")
		{
			ino(root);
			printf("\n");
			preo(root);
			printf("\n");
		}
	}
	
	return 0;
}

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

signed main(){
	ios::sync_with_stdio(false); cin.tie(nullptr);
	LL n, m; cin >> n >> m;
	cout << n * (n - 1) / 2 + m * (m - 1) / 2;
	return 0;
}

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

using namespace std;

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

int main() {
    cin.tie(0); ios::sync_with_stdio(false);
    // cout << setprecision(8) << setiosflags(ios::fixed);

    constexpr ll MOD = 1e9 + 7;

    string L;
    cin >> L;

    const int len = L.size();
    vector<ll> pow2(len + 1), pow3(len + 1);
    pow2[0] = pow3[0] = 1;
    for (int i = 1; i <= len; ++i) {
        (pow2[i] = 2 * pow2[i - 1]) %= MOD;
        (pow3[i] = 3 * pow3[i - 1]) %= MOD;
    }

    ll num = pow2[count(L.begin(), L.end(), '1')];
    for (int i = 0, sum_bit = 0; i < len; ++i) {
        if (L[i] == '0') continue;
        (num += (pow3[len - i - 1] * pow2[sum_bit]) % MOD) %= MOD;
        ++sum_bit;
    }

    cout << num << endl;

    return 0;
}


Measured memory_bytes: 2000
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
using ll = long long;
using namespace std;
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;

int main() {
    int n, y;
    cin >> n;
    vector<int> x(n);
    rep(i, n) cin >> x[i];
    rep(i, n) {
        cin >> y;
        x[i] = abs(x[i] - y);
    }
    // Manhattan distance
    int m = 0;
    rep(i, n) m += x[i];
    cout << m << endl;
    // Euclidean distance
    double e = 0;
    rep(i, n) e += x[i] * x[i];
    e = sqrt(e);
    printf("%.8lf\n", e);
    // p=3
    double p3 = 0;
    rep(i, n) p3 += x[i] * x[i] * x[i];
    p3 = cbrt(p3);
    printf("%.8lf\n", p3);
    // Chebyshev distance
    int c = -1;
    rep(i, n) c = max(c, x[i]);
    cout << c << endl;
}


Measured memory_bytes: 3376
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;
 
public class Main {
 
    void solve() throws IOException {
        int h1 = ni();
        int m1 = ni();
        int h2 = ni();
        int m2 = ni();
        int k = ni();

        int time = h2*60+m2 - (h1*60+m1) -k;
        out.println(time);
    }

 
    String ns() throws IOException {
        while (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine(), " ");
        }
        return tok.nextToken();
    }
 
    int ni() throws IOException {
        return Integer.parseInt(ns());
    }
 
    long nl() throws IOException {
        return Long.parseLong(ns());
    }
 
    double nd() throws IOException {
        return Double.parseDouble(ns());
    }
 
    String[] nsa(int n) throws IOException {
        String[] res = new String[n];
        for (int i = 0; i < n; i++) {
            res[i] = ns();
        }
        return res;
    }
 
    int[] nia(int n) throws IOException {
        int[] res = new int[n];
        for (int i = 0; i < n; i++) {
            res[i] = ni();
        }
        return res;
    }
 
    long[] nla(int n) throws IOException {
        long[] res = new long[n];
        for (int i = 0; i < n; i++) {
            res[i] = nl();
        }
        return res;
    }
 
    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;
 
    public static void main(String[] args) throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        tok = new StringTokenizer("");
        Main main = new Main();
        main.solve();
        out.close();
    }
}

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

const ll inf = 1e18;
const int mod = 1e9+7;
void add_self(int &a, int b) {a+=b; if(a>=mod) a-=mod;}
void sub_self(int &a, int b) {a-=b; if(a<0) a+=mod;}

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

  int n;
  cin >> n;
  vector<int> a(n);
  for(int i=0; i<n; i++)
    cin >> a[i];
  // dp[i][j] : min total cost of combining interval [i,j]
  vector<vector<ll>> dp(n, vector<ll>(n, inf));
  auto sum = [&](int L, int R) {
    ll s = 0;
    for(int i=L; i<=R; i++) s+=a[i];
    return s;
  };

  for(int L=n-1; L>=0; L--) {
    for(int R=L; R<n; R++) {
      if(L==R) {
        dp[L][R] = 0;
      } else {
        ll s = sum(L, R);
        for(int i=L; i<R; i++) {
          dp[L][R] = min(dp[L][R], dp[L][i]+dp[i+1][R]+s);
        }
      }
    }
  }
  cout << dp[0][n-1] << '\n';
  
  return 0;
}


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

const int MAXM = 2e5 + 10, MAXN = 1e5 + 10, INF = 2e9 + 10;

int n, m;
int l, r, d;
long long mark[MAXN];
vector <pair <int, int> > adj[MAXN];

void dfs(int a) {
	for(auto pr : adj[a]) {
		if(!mark[pr.first]) {
			mark[pr.first] = mark[a] + pr.second;
			dfs(pr.first);
		}
	}
}
 
bool check() {
	for(int i = 0; i < n; i++) {
		for(auto pr : adj[i]) {
			if(mark[i] == mark[pr.first] - pr.second) 
                continue;
			else  
                return false;
		}
	}
	return true;
}
 
signed main() {
	cin >> n >> m;
	
    for(int i = 0; i < m; i++) {
		cin >> l >> r >> d;
		l--;
		r--;
		adj[l].push_back({r, d});
		adj[r].push_back({l, -d});
	}
	
    for(int i = 0; i < n; i++) {
		if(!mark[i]) {	
			mark[i] = INF;
			dfs(i);
		}
	}

	if(check()) 
        cout << "Yes" << '\n';
	else 
        cout << "No" << '\n';
    return 0;
}


Measured memory_bytes: 11392
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int main()
{
    int N; cin >> N;
    vector<int> A(N); for (auto &a : A) cin >> a;
    Int ans = 0;
    for (int i = 0; i < A.size(); i++) {
        if (i >= 1 && A[i-1] && A[i]) {
            ans++;
            A[i-1]--, A[i]--;
        }
        ans += A[i] / 2;
        A[i] %= 2;
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>
#include <algorithm>
#include <functional>
#include <numeric>
#include <set>
#include <map>
#include <list>
#include <bitset>
#define debug(x) cout << #x << ": " << (x) << endl
using namespace std;

const double PI  = 3.141592653589793238463;
const int INF = 1000000007;

using ull = unsigned long long;
using ll = long long;

using Int = int;
using Double = double;

using P = pair<Int, Int>;
using V = vector<Int>;
using M = vector<V>;

int solve(int a, int b){
    return (a + b) % 24;
}


int main(int argc, char* argv[]){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int a, b;
    cin >> a >> b;
    cout << solve(a, b) << "\n";

    return 0;
}


Measured memory_bytes: 256
long d[2<<17],*p,m=1e9+7;main(a,k){scanf("%*d%d",&k);p=d+k;for(*p=1;~scanf("%d",&a);){for(;d-p--;)*p+=p[1];for(;*++p;*p%=m)*p-=p[a+1];}printf("%ld",*d);}

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

int main() {
    int n, k;
    cin >> n >> k;
    int x[n];
    rep(i, n) cin >> x[i];

    int ans = 1e9;
    for (int i = 0; i <= n - k; i++) {
        int l = x[i];
        int r = x[i + k - 1];
        ans = min(ans, r - l + min(abs(l), abs(r)));
    }

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


Measured memory_bytes: 640
#include<iostream>
#include<cstdio>
#include<vector>
#include<map>
#include<string>
#include<sstream>
#include<cmath>
#include<climits>
#include<algorithm>
#include<bitset>
#include<set>
#include<stack>
#include<queue>
#include<iomanip>
#include<memory.h>
#include<complex>
using namespace std;  
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef tuple<int,int> tii;
#define rep(i,n) for(ll i=0;i<(n);i++)  
#define pb push_back
#define mt make_tuple
#define ALL(a) (a).begin(),(a).end()
#define FST first
#define SEC second  
const int INF = (INT_MAX/2);
const ll LLINF = (LLONG_MAX/2);
const double eps = 1e-8;
const double PI = M_PI;  
#define DEB cerr<<"!"<<endl
#define SHOW(a,b) cerr<<(a)<<" "<<(b)<<endl
#define SHOWARRAY(ar,i,j) REP(a,i)REP(b,j)cerr<<ar[a][b]<<((b==j-1)?((a==i-1)?("\n\n"):("\n")):(" "))
#define DIV int(1e9+7)
inline ll pow(ll x,ll n,ll m){ll r=1;while(n>0){if((n&1)==1)r=r*x%m;x=x*x%m;n>>=1;}return r%m;}
inline ll lcm(ll d1, ll d2){return d1 / __gcd(d1, d2) * d2;}

 /* Coding Space*/
class UF{
public:
  vi value;
  vi over; // When over < 0, 'over' keep number of node(using negative number). -1 means this tree is a node.
  int root(int index){
    int t = index;
    stack<int> stack_i;
    while(over[t] >= 0){
      stack_i.push(t);
      t = over[t];
    }
    while(!stack_i.empty()){
      int i = stack_i.top(); stack_i.pop();
      over[i] = t;
    }// reconnect
    return t;
  }
  void merge(int a,int b){
    if(this->root(a) == this->root(b)) return;
    over[root(a)] += over[root(b)]; // over have a number of nodes.
    value[root(a)] += value[root(b)];
    over[root(b)] = root(a);
  }
  int NumNode(int a){
    return -over[root(a)];
  }
  UF(int Nodes){
    value.resize(Nodes);
    over.resize(Nodes);
    rep(i,Nodes)
      over[i] = -1;
  }
};
int main(){
  UF uf(100001);
  ll n,m; cin >> n >> m;
  int last_v = 0;
  int times = 0;
  rep(i,n){
    int k; cin >> k;
    vi in(k);
    rep(i,k){
      times++;
      cin >> in[i];
      last_v = in[i];
      uf.value[uf.root(in[i])]++;
      if( i != 0) uf.merge(in[i-1],in[i]);
    }
  }
  if(uf.value[uf.root(last_v)] == times)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define MOD 1000000007
#define fo(i,s,e) for( i=s;i<e;i++)
#define rfo(i,s,e) for(i=s;i>e;i--)
#define LLI long long int
#define LI long int 
#define pb push_back
#define pob pop_back()
#define sp " "
#define ff first
#define ss second
//               When something is important enough, you do it even if the odds are not in your favor.

int main(){   
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    // code goes here
    int t=1;//cin>>t;
    while(t--){
      int n;cin>>n;
      n%=10;
      if(n==2||n==4||n==5||n==7||n==9) cout<<"hon";
      else if(n==0||n==1||n==6||n==8) cout<<"pon";
      else cout<<"bon";
    }
    return 0;
}

Measured memory_bytes: 3612
from collections import Counter
from collections import deque
from functools import reduce
from pprint import pprint
# import statistics
import bisect
import copy
import fractions
import math
import random
import sys
import time
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def MI(): return map(int, sys.stdin.readline().split())
def II(): return int(sys.stdin.readline())
def IS(): return input()
def C(x): return Counter(x)
def GCD_LIST(numbers): return reduce(fractions.gcd, numbers)
def LCM_LIST(numbers): return reduce(LCM, numbers)
def LCM(m, n): return (m * n // fractions.gcd(m, n))
def unite(x, y):
    # それぞれのノードの根を求める
    x = root(x)
    y = root(y)
    if x == y:
        return
    # node[x]の根をyに変更する
    node[x] = y
def same(x,y): return bool(root(x) == root(y))
def root(x):
    if node[x] == x:  # xが根の場合
        return x
    else:
        node[x] = root(node[x])  # 経路圧縮
        return node[x]
def dfs(v):
    # ノードに訪れた
    visited[v] = True
    for v2 in range(n):
        if graph[v][v2] == False:  # そもそもvとv2が辺でつながっていない
            continue
        if visited[v2] == True:  # もう見た
            continue
        dfs(v2)


n, a, b, c, d = MI()
s = [s for s in input()]
aki = []
for i in range(1, len(s)):
    if s[i] == '#' and s[i-1] == '#':
        if a-1 < i < c-1 or b-1 < i < d-1:
            print('No')
            exit()

if c < d:
    print('Yes')
else:
    for i in range(2, len(s)):
        if s[i] == '.' and s[i-1] == '.' and s[i-2] == '.':
            aki.append(i)
    if s[d-2] == '#' and s[d] == '#':
        for num in aki:
            if b-1 < num < d-2:
                print('Yes')
                exit()
        print('No')
        exit()
    elif s[d-2] == '#':
        for num in aki:
            if b-1 < num < d-2:
                print('Yes')
                exit()
        print('No')
        exit()
    elif s[d] == '#':
        for num in aki:
            if b-1 <= num < d:
                print('Yes')
                exit()
        print('No')
        exit()
    elif s[d-2] == '.' and s[d] == '.':
        print('Yes')
        exit()
    print('No')


Measured memory_bytes: 85496
#include <iostream>
#include <fstream>
#include <vector>
#include <cstring>
#include <math.h>
#include <algorithm> // sort

#define REP(i, n) for (long long i = 0; i < (n); i++) 
typedef long long ll;
static const ll INF = 1000000000000000000LL;
using namespace std;


const int MAX = 510000;
const int MOD = 1000000007;
//                70368744177664

//biscuit
int main(){
    //std::ifstream in("input.txt");
    //std::cin.rdbuf(in.rdbuf());
    int N,P;
    cin >> N >> P;
    int a;
    //偶奇
    int gu = 0;
    int ki = 0;

    REP(i,N)
    {
      cin >> a;
      if(a % 2 == 0)++gu;
      else ++ki;
    }

    ll res = 0;
    if(P == 0)
    {
        if(ki == 0)
        {
            res = pow(2,N);
        }
        else
        {
            res = pow(2,N-1);
        }
    }
    else
    {
        if(ki == 0)
        {
            res = 0;
        }
        else
        {
            res = pow(2,N-1);
        }
    }
    
    //cout << gu << " " << ki << endl;
    
    cout << res << endl;

    return 0;    

}



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

long long N, K;
vector<long long> sushi[100005];
//          美味しさ , neta増える？
vector<pair<long long, long long> > top; 
int main(){
	cin >> N >> K;

	for(long long i = 0; i < N; i++){
		long long t,d;
		cin >> t >> d;t--;
		sushi[t].push_back(d);
	}

	for(long long i = 0; i < N; i++){
		sort(sushi[i].begin(), sushi[i].end(), greater<long long>());
		for(long long j = 0; j < sushi[i].size(); j++){
			if(j == 0){
				top.push_back(make_pair(sushi[i][j], 1));
			}else{
				top.push_back(make_pair(sushi[i][j], 0));
			}
		}
	}

	sort(top.begin(), top.end(), greater<pair<long long, long long> >());
	priority_queue<long long> rest;

	long long netanum = 0;
	long long oishisa = 0;
	for(long long i = 0; i < K; i++){
		oishisa+=top[i].first;
		netanum+=top[i].second;
	}
	for(long long i = K; i < top.size(); i++){
		if(top[i].second == 1){
			rest.push(top[i].first);
		}
	}

	long long ans = netanum * netanum + oishisa;

	for(long long i = K-1; i >= 0; i--){
		if(top[i].second == 1){
			continue;
		}
		if(rest.empty()){
			break;
		}
		long long oi = rest.top();
		rest.pop();
		oishisa -= top[i].first;
		oishisa += oi;
		netanum++;
		ans = max(ans, netanum * netanum + oishisa);
	}
	cout << ans << endl;
}



Measured memory_bytes: 8176
#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <set>

using namespace std;
typedef unsigned long long ull;
typedef long long ll;

struct Query{
  ll time;
  ll ind;
  int type;

  Query(ll _time=0, ll _ind=0, int _type=0){
    time=_time; ind=_ind; type=_type;
  }
  
  bool operator<(const Query &q) const{
    return (time < q.time) || (time==q.time && type < q.type);
  }
};

void solve(long long N, long long Q, std::vector<long long> S, std::vector<long long> T, std::vector<long long> X, std::vector<long long> D){
  vector<Query> queries;
  multiset<int> ms;
  int ans[Q];
  
  for(ll i=0; i<N; i++){
    queries.push_back(Query(S[i]-X[i], i, 1));
    queries.push_back(Query(T[i]-X[i], i, 0));
  }

  for(ll i=0; i<Q; i++){
    queries.push_back(Query(D[i], i, 2));
  }

  sort(queries.begin(), queries.end());
  
  for(Query& q: queries){
    if(q.type==1)
      ms.insert(X[q.ind]);
    else if(q.type==0)
      ms.erase(X[q.ind]);
    else{
      ans[q.ind] = ms.empty() ? -1 : *ms.begin();
    }
  }

  for(ll i=0; i<Q; i++)
    cout << ans[i] << endl;
}

// Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    long long Q;
    scanf("%lld",&Q);
    std::vector<long long> S(N);
    std::vector<long long> T(N);
    std::vector<long long> X(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&S[i]);
        scanf("%lld",&T[i]);
        scanf("%lld",&X[i]);
    }
    std::vector<long long> D(Q);
    for(int i = 0 ; i < Q ; i++){
        scanf("%lld",&D[i]);
    }
    solve(N, Q, std::move(S), std::move(T), std::move(X), std::move(D));
    return 0;
}


Measured memory_bytes: 33256
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    void run() {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();

        int len = s.length();

        long ans = 0;
        int a = 0;
        for (int i = 0; i < len; i++) {
            switch (s.charAt(i)) {
                case 'A':
                    a++;
                    break;
                case 'B':
                    if (i + 1 < len && s.charAt(i + 1) == 'C') {
                        ans += a;
                        i++;
                    } else {
                        a = 0;
                    }
                    break;
                case 'C':
                    a = 0;
            }
        }
        System.out.println(ans);
    }

    void debug(Object...os) {
        System.err.println(Arrays.deepToString(os));
    }

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


Measured memory_bytes: 26672
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
#include <math.h>

long long gcd(long long a, long long b) {
  long long v0 = a, v1 = b, v2 = a % b;
  while (v2 != 0) {
    v0 = v1;
    v1 = v2;
    v2 = v0 % v1;
  };
  return v1;
}

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

int main(void){

    int N;

    scanf("%d", &N);

    long long T[N];

    for(int i = 0; i < N; i++){
        scanf("%lld", &T[i]);
    }

    long long ans = T[0];

    for(int i = 1; i < N; i++){
        ans = lcm(ans, T[i]);
    }

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

    return 0;
}

Measured memory_bytes: 1708
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>

int main(){
    std::string s;
    std::cin >> s;

    if (s == "A")
    {
        s = "T";
    }
    else if (s == "C")
    {
        s = "G";
    }
    else if (s == "G")
    {
        s = "C";
    }
    else
    {
        s = "A";
    }
    
    std::cout << s << std::endl;

    return 0;
}

Measured memory_bytes: 3560
#include<bits/stdc++.h>
using namespace std;
int main(){
string s,t;
  cin>>s>>t;
  int N=s.size();
  int M=t.size();
  vector<char>S(N);
  vector<char>T(M);
  for(int i=0;i<N;i++)
    S[i]=s.at(i);
  for(int j=0;j<M;j++)
    T[j]=t.at(j);
  sort(S.begin(),S.end());
  sort(T.begin(),T.end());
  reverse(T.begin(),T.end());
  int Min=min(N,M);
  string ans="dontknow";
  for(int i=0;i<Min;i++){
  if(S.at(i)<T.at(i)){ans="Yes";break;}
  
  if(S.at(i)>T.at(i)){ans="No"; break;}
  }
  if(ans=="dontknow"){
  if(Min<M)
    ans="Yes";
    else
      ans="No";
  
  }cout<<ans<<endl;
  
   
 return 0;
}

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

//#define INT_MAX

int n,k;
int w[100000];

bool ok(int P){
	int W = 0;
	int K = 1;
	for(int i=0;i<n;i++){
		if(W+w[i]<=P){
			W += w[i];
		}else if(w[i]<=P){
			K++;
			W = w[i];
		}else{
			return false;
		}
	}
	return K<=k;
}

int main(){
	while(cin >> n >> k && n>0){
		for(int i=0;i<n;i++){
			cin >> w[i];
		}
		int l=0;
		int h;
		h = INT_MAX;
		while(l+1<h){
			int m=(l+h)/2;
			if(ok(m)) h=m; else l=m;
		}
		cout << h << endl;
	}
}


Measured memory_bytes: 3492
s = list(input())
t = list(input())

s.sort()
t.sort()
t.reverse()

size = min(len(s), len(t))
result = ""

for i in range(size):
    if s[i] < t[i]:
        result = "Yes"
        break

if result == "":
    if s[0:size] == t[0:size]:
        if len(s) < len(t):
            result = "Yes"
        else:
            result = "No"
    else:
        result = "No"

print(result)

Measured memory_bytes: 3064
#include <vector> 
#include <list> 
#include <map> 
#include <set> 
#include <deque> 
#include <queue> 
#include <stack> 
#include <bitset> 
#include <algorithm> 
#include <functional> 
#include <numeric> 
#include <utility> 
#include <sstream> 
#include <iostream> 
#include <iomanip> 
#include <cstdio> 
#include <cmath> 
#include <cstdlib> 
#include <cctype> 
#include <string> 
#include <cstring> 
#include <ctime> 

using namespace std;

#define _int64 long long

int a[10];

int main()
{
  int i,k;
  scanf("%d%d%d",&a[0],&a[1],&a[2]);
  scanf("%d",&k);
  sort(a,a+3);
  for (i=0;i<k;i++)
    a[2]*=2;
  printf("%d\n",a[0]+a[1]+a[2]);
  return 0;
}

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



int main(){
    long long N;
    cin >> N;
    vector<vector<int>> buka(N);
    for(int i=1;i<N;i++){
        int a;
        cin >> a;
        a--;
        buka[a].push_back(i);
    }
    for(int i=0;i<N;i++){
        cout << buka[i].size() << endl;
    }
}


Measured memory_bytes: 13924
#include <bits/stdc++.h>
#define GET_MACRO(_1,_2,_3,_4,_5,_6,NAME,...) NAME
#define pr(...) GET_MACRO(__VA_ARGS__,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__)
#define Pr(a) (#a)<<"="<<(a)<<" "
#define pr1(a) cerr<<Pr(a)<<endl
#define pr2(a,b) cerr<<Pr(a)<<Pr(b)<<endl
#define pr3(a,b,c) cerr<<Pr(a)<<Pr(b)<<Pr(c)<<endl
#define pr4(a,b,c,d) cerr<<Pr(a)<<Pr(b)<<Pr(c)<<Pr(d)<<endl
#define pr5(a,b,c,d,e) cerr<<Pr(a)<<Pr(b)<<Pr(c)<<Pr(d)<<Pr(e)<<endl
#define pr6(a,b,c,d,e,f) cerr<<Pr(a)<<Pr(b)<<Pr(c)<<Pr(d)<<Pr(e)<<Pr(f)<<endl
#define int long long
#define double long double
using namespace std;
const int INF = 1LL<<55;
const int mod = (1e9)+7;
const double EPS = 1e-8;
const double PI = 6.0 * asin(0.5);
typedef pair<int,int> P;
typedef long long ll;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
ostream& operator<<(ostream& o,P p){return o<<"("<<p.first<<","<<p.second<<")";}
istream& operator>>(istream& i,P &p){return i>>p.first>>p.second;}
ostream& operator<<(ostream& o,vector<auto> &a){int i=0;for(auto t:a)o<<(i++?" ":"")<<t;return o;}
istream& operator>>(istream& i,vector<auto> &a){for(auto &t:a)i>>t;return i;}
void prArr(auto a,string s=" "){int i=0;for(auto t:a)cout<<(i++?s:"")<<t;cout<<endl;}


signed main(){
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);
  int n;
  cin>>n;
  vector<int> A(n);
  cin>>A;
  int q;
  cin>>q;
  while(q--){
    int l, r, m;
    cin>>l>>r>>m;
    swap_ranges(A.begin() + l, A.begin() + r, A.begin() + m);
  }

  cout<<A<<endl;

  return 0;
}



Measured memory_bytes: 3144
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <vector>
#include <algorithm>
#include <map>
using std::vector;
using std::sort;

int main(){
	int n, m, d, x, y;
	scanf("%d%d%d%d%d",&d,&n,&m,&x,&y);
	printf("%d\n", d-(int)std::max(ceil((double)n/x),ceil((double)m/y)));
	return 0;
}

Measured memory_bytes: 1028
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
#define VS vector<string>
#define VB vector<bool>
#define VP vector<pair<ll,ll>>
#define VVL vector<vector<ll>>
#define VVP vector<vector<pair<ll,ll>>>
#define PL pair<ll,ll>
#define ALL(v) (v).begin(), (v).end()

int main(){
    string s;
    cin >> s;
    int a = (s[0] - '0') * 10 + (s[1] - '0');
    int b = (s[2] - '0') * 10 + (s[3] - '0');
    if((a == 0 || a >= 13) && (b == 0 || b >= 13)){
        cout << "NA" << endl;
    }else if(a == 0 || a >= 13){
        cout << "YYMM" << endl;
    }else if(b == 0 || b >= 13){
        cout << "MMYY" << endl;
    }else{
        cout << "AMBIGUOUS" << endl;
    }
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
const int maxn=2e5+10;
int n,a[maxn];
int vis[1000010];
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		vis[a[i]]++;
	}
	int ans=0;
	for(int i=0;i<n;i++)
	{
		bool flag=true;
		vis[a[i]]--;
		for(int j=1;j*j<=a[i];j++)if(a[i]%j==0)
		{
			int k=a[i]/j;
			if(vis[j])
			{
				flag=false;
				break;
			}
			if(vis[k])
			{
				flag=false;
				break;
			}
		}
		vis[a[i]]++;
		ans+=flag;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 8256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <iostream>
#include <string>

#include <bits/stdc++.h>
#include <cmath>
#include <limits>

using namespace std;

int main(int argc, char* argv[]){
	cin.tie(0);
	ios::sync_with_stdio(false);

	char c;
	cin >> c;

	if(c >= 'A' && c <= 'Z'){
		printf("A\n");
	}
	else if(c >= 'a' && c <= 'z'){
		printf("a\n");
	}
	return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
        #include<iostream>
        #include<cstdio>
        #include<vector>
        #include<queue>
        #include<map>
        #include<cstring>
        #include<string>
        #include <math.h>
        #include<algorithm>
        #include<functional>
      #define int long long
        #define inf  1000000007
        #define pa pair<int,int>
#define ll long long
        #define pal pair<ll,ll>
        #define ppa pair<int,pa>
        #define EPS (1e-10)
        #define equals(a,b) (fabs((a)-(b))<EPS)

        using namespace std;

        class Point{
        	public:
        	double x,y;
        	Point(double x=0,double y=0):x(x),y(y) {}
        	Point operator + (Point p) {return Point(x+p.x,y+p.y);}
        	Point operator - (Point p) {return Point(x-p.x,y-p.y);}
        	Point operator * (double a) {return Point(x*a,y*a);}
        	Point operator / (double a) {return Point(x/a,y/a);}
        	double absv() {return sqrt(norm());}
        	double norm() {return x*x+y*y;}
        	bool operator < (const Point &p) const{
        		return x != p.x ? x<p.x: y<p.y;
        	}
        	bool operator == (const Point &p) const{
        		return fabs(x-p.x)<EPS && fabs(y-p.y)<EPS;
        	}
        };
        typedef Point Vector;

        struct Segment{
        Point p1,p2;
        };

    double hen1(Vector a){
    if(fabs(a.x)<EPS && a.y>0) return acos(0);
    else if(fabs(a.x)<EPS && a.y<0) return 3*acos(0);
    else if(fabs(a.y)<EPS && a.x<0) return 2*acos(0);
    else if(fabs(a.y)<EPS && a.x>0) return 0.0;
    else if(a.y>0) return acos(a.x/a.absv());
    else return 2*acos(0)+acos(-a.x/a.absv());

    }

        double dot(Vector a,Vector b){
        	return a.x*b.x+a.y*b.y;
        }
        double cross(Vector a,Vector b){
        	return a.x*b.y-a.y*b.x;
        }
        int dx[4] = {1, 0, -1, 0};
        int dy[4] = {0, 1, 0, -1};
        //----------------kokomade temple------------
int n,s;

bool ch(int b){
	int r=n,q=0;
	while(r){
	q+= (r%b);
		r= r/b;
	}
	return q==s;
	
}



signed main(){


	cin>>n>>s;
	double sq=sqrt(n*1.0);
	
	int z= 100+(int) sq;
//	cout<<z<<endl;
	for(int i=2;i<=z;i++){
		if(ch(i)){
			cout<<i<<endl;
			return 0;
		}
	}
	bool b=false;
	int ans=10000000000000ll;
	for(int a=0;a<z;a++){
		int be=s-a;
		if(be<0) continue;
	//	cout<<a<<" "<<n-s<<endl;
		if(n-s<0) continue;
		if(n==s) {
			cout<<n+1<<endl;
			return 0;
		}
		if(a>0) if((n-s)%a==0){
			if(ch((n-s)/a+1)){ ans=min(ans,((n-s)/a)+1);
			b=true;
			}
		}
		if(a==0)if(n==s){
			
			if(ch(n+1)){ans=min(ans,n+1);
		b=1;
			}
			}
		
	}
	if(b) cout<<ans<<endl;
	else cout<<-1<<endl;
	
	return 0;
        }


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n,m,i,j,k=0,l,t,arr[200009]={};
    scanf("%lld",&n);
    for(i=0;i<n;i++)
    {
        scanf("%lld",&arr[i]);
        k+=arr[i];
    }
    m=1000000000000;
    j=0;
    for(i=0;i<n-1;i++){
        j+=arr[i];
        l=k-j;
        t=abs(l-j);
        m=min(m,t);
    }
    printf("%lld",m);
}


Measured memory_bytes: 1792
a,b,x=map(int,input().split())
import math
ans=0
if a*a*b/2>=x:
    h=2*x/(a*b)
    ans=math.atan(b/h)
else:
    h=2*(a*a*b-x)/(a*a)
    ans=math.atan(h/a)
    
print(ans*180/math.pi)

Measured memory_bytes: 3060
//ABC155B
#include<iostream>
using namespace std;

int main()
{
    int n, a;

    bool approved = 1;

    cin >> n;

    while(n--)
    {
        cin >> a;

        if(!(a%2)&& approved){
            if((a%3)&&(a%5)) approved = 0;
        }
    }
    if(approved) cout << "APPROVED\n";
    else cout << "DENIED\n";

    //main();

    return 0;
}


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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            //[summary]A - Beginner
            var line = ReadLine();
            int N = line[0];
            int R = line[1];

            if (N >= 10)
            {
                Console.WriteLine(R);
            }
            else
            {
                Console.WriteLine(R + 100 * (10 - N));
            }
        }

        static List<int> ReadLine()
        {
            var line = Console.ReadLine();
            var arr = line.Split(' ');

            return arr.Select(x => int.Parse(x)).ToList();
        }
    }
}

Measured memory_bytes: 11220
from bisect import bisect_left


def main():
    n = int(input())
    a = [int(x) for x in input().split()]
    a.sort()
    if n > 2:
        index = bisect_left(a, a[-1] // 2)
        if index == n - 1:
            index -= 1
        elif index > 0 and a[-1] - a[index] < a[index - 1]:
            index -= 1
        print(a[-1], a[index])
    else:
        print(a[1], a[0])


if __name__ == '__main__':
    main()



Measured memory_bytes: 14052
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const ll dx[4] = { 0, -1, 1, 0 };
const ll dy[4] = { -1, 0, 0, 1 };
const int INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}
void mul(ll a, ll b) {
	a = a * b % INF;
}
using Graph = vector<vector<int>>;
ll mypow(ll x, ll n, ll m) {
	if (n == 0) {
		return 1;
	}
	if (n % 2 == 0) {
		return mypow(x*x%m, n / 2, m);
	}
	else {
		return x * mypow(x, n - 1, m) % m;
	}
}
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
const int MAX = 510000;
ll fac[MAX], finv[MAX], inv[MAX];
//テーブルをつくる前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;//mod pにおける1,2,,,nの逆元
	for (int i = 2; i < MAX; ++i) {
		fac[i] = fac[i - 1] * i%INF;
		inv[i] = INF - inv[INF%i] * (INF / i) % INF;
		finv[i] = finv[i - 1] * inv[i] % INF;
	}
}

ll COM(int n, int k) {
	if (n < k)return 0;
	if (n < 0 || k < 0)return 0;
	return fac[n] * (finv[k] * finv[n - k] % INF) % INF;
}
///////////////////////////////////////


int main() {
	int n; cin >> n;
	if (n % 2 == 0) {
		cout << n / 2 << endl;
	}
	else {
		cout << n / 2 + 1 << endl;
	}
	return 0;
}


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

int main() {
  char c;
  cin >> c;
  if(c=='a'||c=='e'||c=='i'||c=='o'||c=='u'){
    cout << "vowel" << endl;
  }else{
    cout << "consonant" << endl;
  }
}


Measured memory_bytes: 256
while str = STDIN.gets
  n = str.split(" ")
  W = n[0].to_i
  H = n[1].to_i
  x = n[2].to_i
  y = n[3].to_i
  r = n[4].to_i

  if W < x+r 
    puts "No"
  elsif  H < y+r 
    puts "No"
  elsif x < r 
    puts "No"  
  elsif  y < r
    puts "No"
  else
    puts "Yes"
  end
end



Measured memory_bytes: 6868
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define PB push_back
#define MP make_pair
#define ll long long
#define MOD 1000000007
#define FILL(ptr, value) FILL_((ptr), sizeof(ptr)/sizeof(value), (value))
 
template <typename T>
void FILL_(void * ptr, size_t size, T value){
  std::fill((T*)ptr, (T*)ptr+size, value);
}
 

inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}

ll dp[2][100001];

int main(){
    std::ios::sync_with_stdio(false);

    int n, k;
    int cur = 0;
    int nxt = 1;
    cin >> n >> k;
    int a[n] = {};

    for(int i=0;i<n;++i)
    {
      cin >> a[i];
    }
    dp[0][0] = 1;
    for(int i=0;i<n;++i)
    {
      ll accumulated[k+2] = {};
      ll tmp = 0;

      for(int j=0;j<=k;++j)
      {
        tmp += dp[cur][j];
        accumulated[j+1] = tmp;
        tmp %= MOD;
      }

      for(int j=0;j<=k;++j)
      {
        int begin_pos = max(0, j - a[i]);
        dp[nxt][j] = (accumulated[j+1] - accumulated[begin_pos] + MOD) % MOD;
      }

      cur = 1 - cur;
      nxt = 1 - nxt;
    }

    cout << dp[cur][k] << endl;
}

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

using namespace std;

#define FOR(i,s,e) for(int (i)=(s);(i)<(int)(e);(i)++)
#define REP(i,e) FOR(i,0,e)

#define all(o) (o).begin(), (o).end()
#define psb(x) push_back(x)

typedef long long ll;
const int N = 1<<8;
const int M = N-1;
int n, m, x, l, tmp;
int a[N], b[N];

int main() {
  scanf("%d%d ", &n, &m);
  REP(i,n) a[i] = i;
  REP(i,m) {
    scanf("%d ", &x);
    a[x] = -1;
  }
  int res = 0;
  while (n>1) {
    x = 0;
    for (int i=0; i<n-1; i+=2) {
      b[x++] = max(a[i], a[i+1]);
      res += a[i]>=0 && a[i+1]>=0 ? 1 : 0;
    }
    n /= 2;
    REP(j,n) a[j] = b[j];
  } 
  printf("%d\n", res);
  return 0;
}

Measured memory_bytes: 3212
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstring>

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) unique(v.begin(), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

#define MAX_V 10000
int d[MAX_V][MAX_V];
int V;
void warshall_floyd() {
	rep(k, 0, V) rep(i, 0, V) rep(j, 0, V) d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int H, W;
	cin >> H >> W;
	V = 10;

	rep(i, 0, 10) rep(j, 0, 10) {
		if(i == j) d[i][j] = 0;
		else d[i][j] = 1000000;
	}

	rep(i, 0, 10) rep(j, 0, 10) cin >> d[i][j];

	warshall_floyd();
	
	int count[10];
	memset(count, 0, sizeof(count));
	rep(i, 0, H) rep(j, 0, W) {
		int a;
		cin >> a;
		count[a]++;
	}

	int ans = 0;
	rep(i, 0, 10) {
		if(i == 1) continue;
		ans += (count[i] * d[i][1]);
	}
	cout << ans << endl;

}


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

int main() {
  int N, A, B;
  cin >> N >> A >> B;
  
  if ( N * A <= B ) {
    cout << N * A << endl;
  }
  
  else if ( N * A >= B ) {
    cout << B << endl;
  }
}

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

#define MOD 1000000007
#define MAXN 1000

long long num[MAXN];

void factorization(int n)
{
	int i;
	while (n % 2 == 0) {
		n = n / 2;
		num[1] = (num[1] + 1) % MOD;
	}
	for (i = 3; i <= sqrt(n); i += 2) {
		while (n % i == 0) {
			n = n / i;
			num[i - 1] = (num[i - 1] + 1) % MOD;
		}
	}
	if (n > 0) num[n - 1] = (num[n - 1] + 1) % MOD;
}

int main(void)
{
	long long N;
	long long ans = 1;
	long long i;

	scanf("%lld", &N);

	for (i = 1; i <= N; i++) {
		factorization(i);
	}
	for (i = 1; i < N; i++) {
		ans = (ans * (num[i] + 1)) % MOD;
	}
	printf("%lld\n", ans);

	return (0);
}

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

int main(){
  int a,b,x; cin >> a >> b >> x;
  double ans;
  if(x <= a*a*b/2){
    ans = 180*(atan2(a*b*b,(2*x)))/M_PI;
  }else{
    ans = 180*(atan2(2*(a*a*b-x),(a*a*a)))/M_PI;
  }
  printf("%3.8f",ans);
}

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

using namespace std;
#define all(x) x.begin(), x.end()

const int N = 200000 + 10;
const int MOD = 1000000000 + 7;

vector <long long> a, b, c;

int main() {
    int n, k;   cin >> n >> k;
    for (int i = 1; i <= n; i++) {
        long long x;    cin >> x;
        if (x > 0)  a.push_back(x);
        else if (x < 0) b.push_back(x);
        else    c.push_back(x);
    }
    sort(all(a), [&](long long a, long long b){return a > b; });
    sort(all(b));
    sort(all(c));

    if (k == n) {
        long long ans = 1;
        for (auto x : a)    ans = ans * x % MOD;
        for (auto x : b)    ans = ans * x % MOD;
        for (auto x : c)    ans = ans * x % MOD;
        ans = (ans + MOD) % MOD;
        cout << ans;
    }
    else {
        if (a.size() + b.size() < k) {
            cout << 0;
        }
        else {
            if (a.empty()) {
                long long ans = 1;
                if (k & 1) {
                    if (c.empty()) {
                        for (int i = 1; i <= k; i++)    ans = ans * b[b.size() - i] % MOD;
                    }
                    else {
                        cout << 0;
                        return 0;
                    }
                }
                else    for (int i = 0; i < k; i++) ans = ans * b[i] % MOD;
                ans = (ans + MOD) % MOD;
                cout << ans;
            }
            else {
                if (b.size() & 1)   b.pop_back();
                long long ans = 1, p = 0, q = 0;
                if (k & 1)  ans = a[p++], k--;
                while (k) {
                    if (q + 2 > b.size() || (a[p] * a[p + 1] > b[q] * b[q + 1])) {
                        ans = ans * (a[p] * a[p + 1] % MOD) % MOD;
                        p += 2;
                    }
                    else {
                        ans = ans * (b[q] * b[q + 1]  % MOD) % MOD;
                        q += 2;
                    }
                    k -= 2;
                }
                cout << ans;
            }
        }
    }

#ifndef ONLINE_JUDGE
    system("pause");
#endif
    return 0;
}

Measured memory_bytes: 5524
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    while (1) {
        c-=b;
        if (c<=0) {
            cout<<"Yes"<<endl;
            break;
        }
        a-=d;
        if (a<=0) {
            cout<<"No"<<endl;
            break;
        }
    }
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
int n, k;
int h[1000005], memo[1000005];
int f(int n) {
    if(n == 0) {
        return 1e9;
    }
    if(n == 1) {                        // bisa juga base case nya n = 0, f(0) harus tinggi, misal 1e9;
        return 0;
    }
    if(n == 2) {
        return abs(h[1] - h[2]);
    } 
    else if(memo[n] != -1) {
        return memo[n];
    }
    int minim = INT_MAX;
    for(int i = 1; i <= k; i++) {
        if(n - i > 0) {
            minim = min(f(n - i) + abs(h[n] - h[n - i]), minim);
        }
//        printf("#%d %d\n", f(n - i), abs(h[n] - h[n - i]));
    }
    memo[n] = minim;
    return memo[n];
}

int main() {
    scanf("%d%d", &n, &k);
    for(int i = 1; i <= n; i++) {
        scanf("%d", &h[i]);
    }
    memset(memo, -1, sizeof(memo));
    printf("%d\n", f(n));
//    for(int i = 1; i <= n; i++) {
//        printf("%d %d\n", i, f(i));
//    }
}

Measured memory_bytes: 11008
import math

a, b, x = map(int, input().split())

s = x / a

if s >= a * b / 2:
    c = (a * b - s) * 2 / a
    rad = math.atan2(c, a)
else:
    c = s * 2 / b
    rad = math.atan2(b, c)

ans = math.degrees(rad)
print(ans)


Measured memory_bytes: 3188
n = gets.chomp.to_i
nums = gets.chomp.split(' ').map(&:to_i)

if !nums.include?(1) then
    puts -1
else
    cnt = 0
    ptr = 0
    tgt = 1
    n.times {|i|
        if nums[i] == tgt then
            cnt += i - ptr
            ptr = i + 1
            tgt += 1
        end
    }
    cnt += n - ptr
    puts cnt
end


Measured memory_bytes: 16772
#include <bits/stdc++.h>
#define pb push_back
#define S second
#define F first

using namespace std;
typedef long long ll;

typedef pair<int,int> pii;
const int maxn = 2e5;


int32_t main(){
    ll n;

    string s;
    cin >> s;
    n = s.length();
    ll ans = 0;
    for (int i = s.length() - 1;i > -1;i--){
    //      cout << i << endl;
        if (s[i] == 'B'){
            n--;
            ans += n - i;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 640
using System;
using System.Linq;

namespace ITP1_2_D
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
            Console.WriteLine(IsInside(input) ? "Yes" : "No");
        }

        static bool IsInside(int[] arr)
        {
            var W = arr[0];
            var H = arr[1];
            var x = arr[2];
            var y = arr[3];
            var r = arr[4];

            if (x < r || W - r < x)
                return false;
            if (y < r || H - r < y)
                return false;
            return true;
        }
    }
}

Measured memory_bytes: 9356