akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stdio.h>
#include <cmath>
#include <cctype>
#include <map>

const int INT_INF = 1000000000;                 // 10^9
const long long LONG_INF = 1000000000000000000; // 10^18

using namespace std;

int main()
{
    int mod = 2019;
    long long l, r;
    cin >> l >> r;

    r = min(r, l + 4050);
    long long ans = 2019;
    for (long long i = l; i <= r; i++)
    {
        for (long long j = i + 1; j <= r; j++)
        {
            ans = min(ans, (i * j) % 2019);
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
# B - Card Game for Two
n = int(input())
num_list = list(map(int, input().split()))

num_list = sorted(num_list, reverse=True)
a, b = 0, 0
for i, s in enumerate(num_list):
    if i%2==0:
        a += s
    else:
        b += s
print(a-b)


Measured memory_bytes: 2940
#include <iostream>
#include <cstdio>
#include <cstring>
#define MAXN 100005
using namespace std;
int a[MAXN],c[2][MAXN];
int main()
{
	int n,m=0,ans=0;
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);		
		m=max(m,a[i]);
	}
	for (int i=1;i<=n;i++)
		c[i%2][a[i]]++;
	int ma[2]={},mi[2]={};
	for (int i=m;i>=1;i--)
	{
		if (c[0][i]>ma[0])
		{
			ma[0]=c[0][i];
			mi[0]=i;
		}
		if (c[1][i]>ma[1])
		{
			ma[1]=c[1][i];
			mi[1]=i;
		}		
	}
	if (mi[0]==mi[1])
	{
		int t[2]={};
		for (int i=1;i<=m;i++)
			if (i!=mi[0])
			{
				t[0]=max(t[0],c[0][i]);
				t[1]=max(t[1],c[1][i]);
			}
		if (ma[0]==ma[1])
			ans+=ma[0]+max(t[0],t[1]);
		else	
			ans+=max(ma[0]+t[1],ma[1]+t[0]);
	}
	else
		ans+=ma[0]+ma[1];
	cout<<n-ans;
	return 0;	
}

Measured memory_bytes: 1408
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int f(int p,int l) {
	int a[10];
	for (int i = 0; i < l; i++) {
		a[i] = p % 10;
		p /= 10;
	}
	sort(a, a + l);
	int maxv = 0, minv = 0;
	for (int i = 0; i < l; i++) {
		maxv *= 10; maxv += a[l - i - 1];
		minv *= 10; minv += a[i];
	}
	return maxv - minv;
}
int find(vector<int>v, int p) {
	for (size_t i = 0; i < v.size(); i++) {
		if (v[i] == p)return i;
	}return -1;
}
int main() {
	int k, l;
	while (cin >> k >> l, l) {
		vector<int>v;
		while (true) {
			v.push_back(k);
			k = f(k, l);
			int p = find(v, k);
			if (p == -1);
			else {
				printf("%d %d %d\n", p, k, v.size() - p);
				goto heaven;
			}
		}
	heaven:;
	}
	return 0;
}


Measured memory_bytes: 3296
import java.util.Scanner

object Main {

  def solve(sc: Scanner): String = {
    val n = sc.nextInt()
    val p = Vector.fill(n)(sc.nextInt())
    debug(n, p)

    var count = 0
    for (i <- 2 until n) {
      val t = p(i - 1)
      if (t == Array(p(i - 2), t, p(i)).sorted.drop(1).head) count += 1
    }
    count.toString
  }

  def main(args: Array[String]): Unit = {
    val sc = new Scanner(System.in)
    val writer = new java.io.PrintWriter(System.out)
    writer.println(solve(sc))
    writer.flush()
  }

  private def debug(x: Any): Unit = {
    if (System.getenv("LOCAL_DEBUG") != null) println(x)
  }
}


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

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

    if (N == 1) {
        cout << 1 << endl;
    }
    else if (N % 2 == 0) {
        cout << (double)(N / 2) / N << endl;
    }
    else if (N % 2 == 1) {
        cout << (double)((N / 2) + 1) / N << endl;
    }
    return 0;
}

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

int main(){
    string S;
    cin >> S;
    if(S[0] == S[1]){
        if(S[2] == S[3] && S[0] != S[2]){
            cout << "Yes" << '\n';
        }else{
            cout << "No" << '\n';
        }
    }else if(S[0] == S[2] && S[1] == S[3] || S[0] == S[3] && S[1] == S[2]){
            cout << "Yes" << '\n';
        }else{
            cout << "No" << '\n';
    }
    return 0;
}

Measured memory_bytes: 3568
#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ld long double
#define mk make_pair
#define fi first
#define se second
#define vll vector<ll>
#define pii pair<ll,ll>
#define vvll vector< vector<ll> >
#define pb push_back
#define sz(v) (v).size()
#define inf 1e18
#define md 1000000007
#define all(v) (v).begin(),(v).end()
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define tel(a){cout<<a<<"\n";}
#define tell(a,b){cout<<a<<" | "<<b<<"\n";}
#define telll(a,b,c){cout<<a<<" | "<<b<<" | "<<c<<"\n";}
#define teln(v,n){cout<<"v- ";rep(i,0,n)cout<<v[i]<<" ";cout<<"\n";}
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define tihs if(fopen("inp.txt","r"))freopen("inp.txt", "r", stdin),freopen("out.txt", "w", stdout);
using namespace std;
#define TRACE
 
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
 

#define M 200010


int main(){
	IOS;
	tihs;
	
	ll n,m;cin>>n>>m;
	ll a[n];
	rep(i,0,n)a[i]=-1;
	bool ok=1;
	rep(i,0,m){
		ll s,c;cin>>s>>c;
		s--;
		if(a[s]==-1)a[s]=c;
		else {
			if(a[s]!=c)ok=0;
		}
	}
	if(n==1){
		if(ok){
			if(a[0]!=-1)cout<<a[0];
			else cout<<0;
		}
		else cout<<-1;
		return 0;
	}
	else if(n>1){
		if(a[0]==0)ok=0;
		if(a[0]==-1)a[0]=1;
		rep(i,0,n)if(a[i]==-1)a[i]=0;
		if(ok){
			rep(i,0,n)cout<<a[i];
		}
		else cout<<-1;
	}




	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,m;
	cin>>n>>m;
	int max=0;
	if(m%n==0)
	{
		cout<<m/n<<endl;
		return 0;
	}
	for(int i=1;i<=m/2;i++)
	   if(m%i==0&&m/i>=n&&i>max)
	      max=i;
	cout<<max<<endl;
	return 0;
}


Measured memory_bytes: 256
import sys

input = sys.stdin.readline

def main():
    n = int(input())
    A = list(map(int, input().split()))
    allB = exc = 1
    for i in A:
        allB *= 3
        if i%2 == 0:
            exc *= 2
    ans = allB - exc
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 9120
import math
import fractions
import bisect
import collections
import itertools
import heapq
import string
import sys
import copy
from collections import deque
sys.setrecursionlimit(10**7)
MOD = 10**9+7
def gcd(a,b):return fractions.gcd(a,b) #最大公約数
def lcm(a,b):return (a*b) // fractions.gcd(a,b) #最小公倍数
def iin(): return int(input()) #整数読み込み
def ifn(): return float(input()) #浮動小数点読み込み
def isn(): return input().split() #文字列読み込み
def imn(): return map(int, input().split()) #整数map取得
def fmn(): return map(float, input().split()) #浮動小数点map取得
def iln(): return list(map(int, input().split())) #整数リスト取得
def iln_s(): return sorted(iln()) # 昇順の整数リスト取得
def iln_r(): return sorted(iln(), reverse=True) # 降順の整数リスト取得
def fln(): return list(map(float, input().split())) # 浮動小数点リスト取得
def join(l, s=''): return s.join(l) #リストを文字列に変換
def perm(l, n): return itertools.permutations(l, n) # 順列取得
def perm_count(n, r): return math.factorial(n) // math.factorial(n-r) # 順列の総数
def comb(l, n): return itertools.combinations(l, n) # 組み合わせ取得
def comb_count(n, r): return math.factorial(n) // (math.factorial(n-r) * math.factorial(r)) #組み合わせの総数
def two_distance(a, b, c, d): return ((c-a)**2 + (d-b)**2)**.5 # 2点間の距離
def m_add(a,b): return (a+b) % MOD

def sieves_of_e(n):
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i * 2, n+1, i): is_prime[j] = False
    return is_prime

N,M = imn()
A = iln()
D = []
for a in A:
    D.append((-1*(a), 1))
for i in range(M):
    t = iln()
    D.append((-1*(t[1]), t[0]))
heapq.heapify(D)

cnt = 0
ans = 0
while cnt < N:
    tmp = heapq.heappop(D)
    for _ in range(tmp[1]):
        ans += -1*(tmp[0])
        cnt += 1
        if cnt >= N:
            break
print(ans)

Measured memory_bytes: 34612
import java.util.Scanner;

class Main{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();

        int count = 0;

        for(int i = a; i <= b; i++){
            if(c % i == 0){
                count++;
            }
        }
        System.out.println(count);
    }
}


Measured memory_bytes: 26344
#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++)

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

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

int main(){
    ll n;
    cin >> n;
    vector<ll> t(n);
    rep(i, 0, n) cin >> t[i];
    ll ans = 1;
    rep(i, 0, n) ans = lcm(ans, t[i]);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3596
import random,time
def score(D,c,s,t):
    v=list()
    last=[0]*26
    legacy=0
    for i in range(D):
        minus=0
        v.append(legacy)
        v[i]+=s[i][t[i]-1]
        last[t[i]-1]=i+1
        for j in range(26):
            minus+=c[j]*(i+1-last[j])
        v[i]-=minus
        legacy=v[i]
    return v[D-1]
time_sta = time.perf_counter()
s=list()
t=list()
D=int(input())
c=list(map(int,input().split()))
for i in range(D):
    s.append(list(map(int,input().split())))
t=[random.randint(1,26)]*D
time_end=time.perf_counter()
tim=time_end-time_sta
while tim<1.9:
    d=random.randint(1,D)
    q=random.randint(1,26)
    old=t[d-1]
    oldscore=score(D,c,s,t)
    t[d-1]=q
    if score(D,c,s,t)<oldscore:
        t[d-1]=old
    time_end=time.perf_counter()
    tim=time_end-time_sta
for i in range(D):
    print(t[i])

Measured memory_bytes: 9876
#include <iostream>
#include <cstdlib>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const long long INF = 1LL << 60;

int N;
long long a[100010][3];

// DP テーブル
long long dp[100010][3];

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

    // 初期化は既に 0 に初期化される
    // 初期条件も既に 0 で OK

    // ループ
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < 3; ++j) {
            for (int k = 0; k < 3; ++k) {
                if (j == k) continue;
                chmax(dp[i + 1][k], dp[i][j] + a[i][k]);
            }
        }
    }

    // 答え
    long long res = 0;
    for (int j = 0; j < 3; ++j) chmax(res, dp[N][j]);
    cout << res << endl;
}

Measured memory_bytes: 4992
#!/usr/bin/python3
# import bisect
# from collections import Counter, deque, OrderedDict
# from copy import copy, deepcopy
# from functools import reduce
# from heapq import heapify, heappop, heappush
# from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
import math
# import numpy as np  # Pythonのみ！
# from operator import xor
# import re
# from scipy.sparse.csgraph import connected_components  # Pythonのみ！
# ↑cf.  https://note.nkmk.me/python-scipy-connected-components/
# from scipy.sparse import csr_matrix
# import statistics # Pythonのみ
# import string
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():
    
    a,b,h,m=map(int,input().split())
    hval=h*30
    mval=m*6
    hval+=30*(m/60)
    val=min(abs(mval-hval),360-abs(mval-hval))
    print(math.sqrt(a**2+b**2-(2*a*b*math.cos(math.radians(val)))))

    
resolve()

Measured memory_bytes: 62380
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
using namespace std;
typedef long long ll;

const int maxN = 1e3 + 5;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;

ll gcd(ll a, ll b){return !b ? a : gcd(b, a % b);}
ll modP(ll a, ll b) {return (!b ? 1 : (modP(a, b / 2) * modP(a, b / 2) * (b % 2 ? a : 1)) % MOD);}

char chr;
int n, m, board[maxN][maxN];
int i, j, dp[maxN][maxN];

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n >> m;
	for (i = 1; i <= n; i++){
		for (j = 1; j <= m; j++){
			cin >> chr;
			board[i][j] = (chr == '.' ? 1 : 0);
		}
	}
	dp[1][1] = 1;
	for (i = 1; i <= n; i++){
		for (j = 1; j <= m; j++){
			if (i == 1 && j == 1){
				continue;
			}
			dp[i][j] = (board[i][j] * (dp[i - 1][j] + dp[i][j - 1])) % MOD;
		}
	}
	cout << dp[n][m] << endl;
	return 0;
}



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

int main()
{
  int n;
  cin >> n;
  if(n==1){
    cout << "Yes";
    return 0;
  }
  vector<int> h(n);
  for(int i=0;i<n;++i){
    cin >> h.at(i);
  }
  
  for(int i=0;i<n-1;++i){
    if(h.at(i)>h.at(i+1)){
      --h.at(i);
    }else if(h.at(i)==h.at(i+1)&&i>0){
      if(h.at(i-1)!=h.at(i)){
        --h.at(i);
      }
    }
  }
  
  for(int i=0;i<n-1;++i){
    if(h.at(i)>h.at(i+1)){
      cout << "No";
      return 0;
    }
  }
  
  cout << "Yes";
  return 0;
}

Measured memory_bytes: 640
import sys
import itertools

def yn(b):
    print("Yes" if b==1 else "No")
    return

def resolve():
    readline=sys.stdin.readline

    # 1234
    #a,b,c=map(int, readline().rstrip().split())
    #arr=list(map(int, readline().rstrip().split()))
    #n=int(readline())
    ss=readline().rstrip()
    p=len(ss)-1
    loops=[[0,1] for i in range(p)]
    ans=0
    for one in itertools.product(*loops):
        bef=-1
        for i in range(len(one)):
            if one[i]==1:
                ans+=int(ss[bef+1:i+1])
                bef=i
        ans+=int(ss[bef+1:])
    print(ans)
    return

if 'doTest' not in globals():
    resolve()
    sys.exit()

Measured memory_bytes: 3064
// Author: πα

#include <bits/stdc++.h>
using namespace std;
#define long int64_t

int main()
{
    int n, d, ans = 0;
    cin >> n;
    for(int i = 1; i <= n; ++i)
    {
        cin >> d;
        if(d != i)
            ans++;
    }
    cout << (ans < 3 ? "YES" : "NO");
    return 0;
}


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

int main() {
  int N;
  std::cin >> N;
  std::vector<std::pair<int, int>> A(N);
  for (int i = 0; i < N; ++i) {
    std::cin >> A[i].first;
    A[i].second = i+1;
  }
  std::sort(A.begin(), A.end());
  for (auto&& v : A) std::cout << v.second << ' ';
  std::cout << std::endl;
}

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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;
void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z = malloc(sizeof(struct 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 inorder(Node u){
  if (u->left!=NIL) inorder(u->left);
  printf(" %d", u->key);
  if (u->right!=NIL) inorder(u->right);
}
void preorder(Node u){
  printf(" %d", u->key);
  if (u->left!=NIL) preorder(u->left);
  if (u->right!=NIL) preorder(u->right);
}
void print()
{
  if (root==NIL) return;
  preorder(root);
  printf("\n");
  inorder(root);
  printf("\n");
}

int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);
  
  for (i = 0; i < n; i++){
    scanf("%s", com);
    switch (com[0]) {
    case 'i':
      scanf("%d", &x);
      insert(x);
      break;
    case 'p':
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
      break;
    }
  }
  return 0;
}



Measured memory_bytes: 25188
import java.util.Scanner;
import java.lang.*;


class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int H, W, flag = 1;
		H = sc.nextInt();
		W = sc.nextInt();
		String map[] = new String[H];
		for (int i = 0; i < H; i++) {
			map[i] = sc.next();

		}
		StringBuilder col = new StringBuilder();
		StringBuilder map2[] = new StringBuilder[H];
		for (int i = 0; i < H; i++) {
			map2[i] = new StringBuilder(map[i]);
		}

		while (flag == 1) {
			flag = 0;
			for (int i = 0; i < H; i++) {
				for (int j = 0; j < W; j++) {
					//System.out.println("(" + i + "," + j + ")");
					if (map[i].charAt(j) == '#') {/*System.out.println("break!");*/ break;}
					if (j == W - 1 && map[i].contains(".")) {
						flag = 1;
						for (int k = 0; k < W; k++) {
							map2[i].setCharAt(k, 'o');
							map[i] = map2[i].toString();
						}
					}
				}
			}
			for (int i = 0; i < W; i++) {
				col = new StringBuilder();
				for (int j = 0; j < H; j++) {
					//System.out.println("(" + j + "," + i + ")");
					col.append(map[j].charAt(i));
					if (map[j].charAt(i) == '#') {/*System.out.println("break2!");*/ break;}
					if (j == H - 1 && col.toString().contains(".")) {
						flag = 1;
						//System.out.println("deleted!");
						for (int k = 0; k < H; k++) {
							map2[k].setCharAt(i, 'o');
							map[k] = map2[k].toString();
						}
					}

				}
			}
			/*for (int i = 0; i < H; i++) {
				for (int j = 0; j < W; j++) {
					System.out.print(map[i].charAt(j));
				
				}
				System.out.println();
			}*/
		}
		for (int i = 0; i < H; i++) {
			flag = 0;
			for (int j = 0; j < W; j++) {
				if (map[i].charAt(j) == 'o') continue;
				System.out.print(map[i].charAt(j));
				flag = 1;
			}
			if (flag == 1)System.out.println();
		}


	}
}

Measured memory_bytes: 28428
import sys
input = sys.stdin.readline
from operator import itemgetter
import heapq

def main():
	n, m = map(int, input().strip().split())
	ab = [0] * n
	for i in range(n):
		ab[i] = list(map(int, input().strip().split()))
	ab.sort(key=itemgetter(1), reverse=True)
	ab.sort(key=itemgetter(0))
	hp = []
	w = 0
	t = ab[0][0]
	ans = 0
	while t <= m:
		while w < len(ab) and ab[w][0] == t:
			heapq.heappush(hp, -ab[w][1])
			w += 1
		if len(hp) > 0:
			ans += -heapq.heappop(hp)
		t += 1
	print(ans)


if __name__ == '__main__':
	main()


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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){
  while(x->left != NIL){
    x=x->left;
  }
  return x;

}

Node treeMaximum(Node x){
  while(x->right != NIL){
    x=x->right;
  }
  return x;

}

Node treeSearch(Node u, int k){
  
  if(u==NIL || k==u->key) return u;
  if(k < u->key) return treeSearch(u->left,k);
  else return treeSearch(u->right,k);
  
}

Node treeSuccessor(Node x){
  Node y;
  if(x->right != NIL){
    return treeMinimum(x->right);
  }
  y=x->parent;
    while(y!=NIL && x==y->right){
      x=y;
      y=y->parent;
      return y;
  
    }
}
  
void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y
  if(z->left == NIL || z->right == NIL){
    y=z;
  }
  else {
    y=treeSuccessor(z);
  }
  if(y->left != NIL){
    x=y->left;
  }
  else{
    x=y->right;
  }
  if(x != NIL){
    x->parent=y->parent;
  }
  if(y->parent == NIL){
    root=x;
  }
  else if(y == y->parent->left){
    y->parent->left=x;
  }
  else{
    y->parent->right = x;
  }
  if(y!=z) z->key = y->key;

    
}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct 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 inorder(Node u){
  if(u->left!=NIL){
    inorder(u->left);
   
  }           
  printf(" %d",u->key);
  if(u->right != NIL){
    inorder(u->right);
  }
  
}
void preorder(Node u){
  printf(" %d",u->key);
  if(u->left!=NIL){
    preorder(u->left);
  }
  if(u->right != NIL){
    preorder(u->right);

  }
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}

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

int main() {
  int a, b, c, x, y;
  cin >> a >> b >> c >> x >> y;

  int d = 2 * c;
  int ans = 1000000000;
  for (int i = 0; i <= max(x, y); i ++) {
    int tmp = i * d + max(0, x - i) * a + max(0, y - i) * b;
    ans = min(ans, tmp);
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
import sys
from random import choice,randint
inp=sys.stdin.readline
out=sys.stdout.write
flsh=sys.stdout.flush
 
sys.setrecursionlimit(10**9)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
 
def MI(): return map(int, inp().strip().split())
def LI(): return list(map(int, inp().strip().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines().strip()]
def LI_(): return [int(x)-1 for x in inp().strip().split()]
def LF(): return [float(x) for x in inp().strip().split()]
def LS(): return inp().strip().split()
def I(): return int(inp().strip())
def F(): return float(inp().strip())
def S(): return inp().strip()
def pf(s): return out(s+'\n')
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)

def main():
    a,b,c,d=MI()
    f=0
    while True:
        if f==0:
            c=c-b
            f=1
            if c<=0:
                print("Yes")
                break
        if f==1:
            a=a-d
            f=0
            if a<=0:
                print("No")
                break

if __name__ == "__main__":
    main()

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

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;

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

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


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

    int N, M, X;

    cin >> N >> M >> X;
    int cost_L = 0;
    int cost_R = 0;

    int A = 0;
    for(int i = 0; i < M; i++){
        cin >> A;
        if(A < X) cost_L++;
        if(X < A) cost_R++;
    }

    cout << min(cost_L, cost_R) << endl;
    


    

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <math.h>
#include <deque>
using ll = long long;
using namespace std;

int main(){
    int a, b, c, ans = 3;
    cin >> a >> b >> c;
    if(a==b && b==c) ans = 1;
    else if((a==b && b!=c) || (b==c && c!=a) || (c==a && a!=b)) ans = 2;
    cout << ans << endl;
    return 0;
}


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

struct edge{
	int x, y;
	string s;
};

string solve(int n, int s, int g, const vector<edge> &E){
	vector<string> d(n + 1, "~");
	d[g].clear();
	string t;

	bool updated = true;
	for(int i = 0; i < n * n + 3 && updated; ++i){
		updated = false;
		for(int j = 0; j < E.size(); ++j){
			if(d[E[j].y][0] != '~'){
				t = E[j].s + d[E[j].y];
				if(d[E[j].x] > t){
					d[E[j].x] = t;
					updated = true;
					
					if(E[j].x == s && i >= n){
						return "NO";
					}
				}
			}
		}
	}

	if(d[s][0] == '~'){ return "NO"; }
	return d[s];
}

int main(){
	int n, a, s, g, x, y;
	while(cin >> n >> a >> s >> g, n){
		vector<edge> E(a);
		for(int i = 0; i < a; ++i){
			cin >> E[i].x >> E[i].y >> E[i].s;
		}
		cout << solve(n, s, g, E) << '\n';
	}
}

Measured memory_bytes: 4936
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, a, b) for(int i = a; i < b; i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fi first
#define se second
#define pb push_back
#define debug(x) cerr <<__LINE__<< ": " <<#x<< " = " << x << endl
#define debug_vec(v) cerr<<__LINE__<<": "<<#v<<" = ";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

void solve() {
    int x, y, a, b, c;
    cin >> x >> y >> a >> b >> c;
    vector<int> P(a), Q(b), R(c);
    rep(i, a) cin >> P[i];
    rep(i, b) cin >> Q[i];
    rep(i, c) cin >> R[i];
    sort(rall(P));
    sort(rall(Q));
    sort(rall(R));
    P.erase(P.begin() + x, P.end());
    Q.erase(Q.begin() + y, Q.end());
    vector<int> S;
    for(auto p : P) S.push_back(p);
    for(auto q : Q) S.push_back(q);
    for(auto r : R) S.push_back(r);
    sort(rall(S));
    ll ans = 0;
    rep(i, x + y) {
        ans += S[i];
    }
    cout << ans << endl;
}

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


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

#define ms(s, n) memset(s, n, sizeof(s))
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define FORd(i, a, b) for (int i = (a) - 1; i >= (b); i--)
#define FORall(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define sz(a) int((a).size())
#define present(t, x) (t.find(x) != t.end())
#define all(a) (a).begin(), (a).end()
#define uni(a) (a).erase(unique(all(a)), (a).end())
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define prec(n) fixed<<setprecision(n)
#define bit(n, i) (((n) >> (i)) & 1)
#define bitcount(n) __builtin_popcountll(n)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<pi> vii;
const int MOD = (int) 1e9 + 7;
const int INF = (int) 1e9;
const ll LINF = (ll) 1e18;
const ld PI = acos((ld) -1);
const ld EPS = 1e-9;
inline ll gcd(ll a, ll b) {ll r; while (b) {r = a % b; a = b; b = r;} return a;}
inline ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
inline ll fpow(ll n, ll k, int p = MOD) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = r * n % p; n = n * n % p;} return r;}
template<class T> inline int chkmin(T& a, const T& val) {return val < a ? a = val, 1 : 0;}
template<class T> inline int chkmax(T& a, const T& val) {return a < val ? a = val, 1 : 0;}
inline ll isqrt(ll k) {ll r = sqrt(k) + 1; while (r * r > k) r--; return r;}
inline ll icbrt(ll k) {ll r = cbrt(k) + 1; while (r * r * r > k) r--; return r;}
inline void addmod(int& a, int val, int p = MOD) {if ((a = (a + val)) >= p) a -= p;}
inline void submod(int& a, int val, int p = MOD) {if ((a = (a - val)) < 0) a += p;}
inline int mult(int a, int b, int p = MOD) {return (ll) a * b % p;}
inline int inv(int a, int p = MOD) {return fpow(a, p - 2, p);}
inline int sign(ld x) {return x < -EPS ? -1 : x > +EPS;}
inline int sign(ld x, ld y) {return sign(x - y);}
#define db(x) cerr << #x << " = " << (x) << ", ";
#define endln cerr << "\n";
#define chkpt cerr << "-----\n";

void solve() {
    int n, a, b; cin >> n >> a >> b;
    long long lo = (long long) n * a + (b - a);
    long long hi = (long long) n * b - (b - a);
    cout << max(0LL, hi - lo + 1) << "\n";
}

int main() {
    int JUDGE_ONLINE = 1;
    if (fopen("in.txt", "r")) {
        JUDGE_ONLINE = 0;
        assert(freopen("in.txt", "r", stdin));
        //assert(freopen("out.txt", "w", stdout));
    }
    else {
        //ios_base::sync_with_stdio(0), cin.tie(0);
    }
    solve();
    if (!JUDGE_ONLINE) {
        //cout << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
    }
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

using System.Collections;

class Program
{
    static void Main()
    {
        string S = Console.ReadLine();

        if (string.Compare(S, "2019/04/30") <= 0)
        {
            Console.WriteLine("Heisei");
        }
        else
        {
            Console.WriteLine("TBD");
        }
    }
}

Measured memory_bytes: 11232
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

int main()
{
    int n;
    cin >>n;
    vector<int> a(n);
    rep(i,n) cin >>a[i];

    int u = 1;
    rep(i,n) u*=3;

    int o = 1;
    rep(i,n)
    {
        if(a[i]%2==0) o*=2;
    }

    printf("%d\n", u-o);
    return 0;
}


Measured memory_bytes: 256
n, y = gets.strip.split.map(&:to_i)

if y > n * 10000
  puts '-1 -1 -1'
  exit
end

(0..n).each do |i|
  0.upto(n - i).each do |j|
    if y == i * 10000 + j * 5000 + (n - i - j) * 1000
      puts "#{i} #{j} #{n - i - j}"
      exit
    end
  end
end

puts '-1 -1 -1'


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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl;
typedef long long ll;
typedef unsigned long long ull;

int main()
{
    string s;
    map<char, int> rom;
    rom['I'] = 1;
    rom['V'] = 5;
    rom['X'] = 10;
    rom['L'] = 50;
    rom['C'] = 100;
    rom['D'] = 500;
    rom['M'] = 1000;
    while (cin >> s)
    {
        int sum = 0;
        for (int i = 0; i < s.size() - 1; i++)
        {
            if (rom[s[i]] < rom[s[i + 1]])
            {
                sum -= rom[s[i]];
            }
            else
            {
                sum += rom[s[i]];
            }
        }
        OP(sum + rom[s[s.size() - 1]])
    }
    return 0;
}


Measured memory_bytes: 2992
//#include"pch.h"
//#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
#include<cmath>
#include<math.h>
#include<string>
#include<algorithm>
#include<iostream>
using namespace std;
int main() {
	int N;
	cin >> N;
	for (int i = 1; i <= 9; i++) {
		if (N <= 111 * i) { cout << 111 * i; break; }
	}

	return(0);
}

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

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define rep(i, n) repd(i, 0, n)

using namespace std;

using ll = long long;
using ul = unsigned long long;
ll mod = 1000000007;

int main() {
source:
    ll h, w;
    cin >> h >> w;
    string a[h];
    rep(i, h) { cin >> a[i]; }

    ll left[h], right[h];
    rep(i, h) {
        rep(j, w) {
            if (a[i][j] == '#') {
                left[i] = j;
                break;
            }
        }
    }
    rep(i, h) {
        repb(j, w) {
            if (a[i][j] == '#') {
                right[i] = j;
                break;
            }
        }
    }

    bool result = true;
    repd(i, 1, h) {
        if (left[i] != right[i - 1]) {
            result = false;
            break;
        }
    }
    if (result) {
        cout << "Possible" << endl;
    } else {
        cout << "Impossible" << endl;
    }
    return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt(), L = sc.nextInt();
		//String[] array = new String[N];
		//String s=sc.next();
		int sum=0;
		/*for(int i=0;i<s.length();i++) {
			sum+=Integer.parseInt(s.substring(i,i+1));
		}
		if(Integer.parseInt(s)%sum==0) {
			System.out.println("Yes");//Yes or YES注意
		}else {
			System.out.println("No");
		}*/
		for(int i=1;i<=L-N;i++) {
			sum+=i;
		}
		System.out.println(sum-L);

	}
	public static int sample(int n) {
		return n;
	}

}


Measured memory_bytes: 21716
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;

public class Main {

	static final boolean debugMode = false;

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

		int n = readInt(sc);
		long cnt = 0;
		for (int i = 1; i <= n; i++) {
			if (i % 3 != 0 && i % 5 != 0)
				cnt += i;
		}

		System.out.println(cnt);

	}

	static int readInt(Scanner sc) {
		return Integer.parseInt(sc.next());
	}

	static void log(String s) {
		if (debugMode) {
			System.out.println(s);
		}
		return;
	}
}

class Pair {
	private int x;
	private int y;

	public int getX() {
		return x;
	}

	public void setX(int x) {
		this.x = x;
	}

	public int getY() {
		return y;
	}

	public void setY(int y) {
		this.y = y;
	}

	public Pair() {

	}

	public Pair(int x, int y) {
		this.x = x;
		this.y = y;
	}

}

Measured memory_bytes: 27160
#include<bits/stdc++.h>
#include<cctype>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
#define all(v) (v).begin(),(v).end()
typedef long long int ll;
#define pi 3.1415926535897932384
#define E9 1000000000
#define eps 1e-4
#define pii pair<int,int>


int main(){
  int K; cin >> K;
  ll ans = 0;
  ll dp[10][11];
  rep(i,10) dp[i][1] = 1;

  for (int l=1;l<=10;l++){
    for (int t=0;t<10;t++){
      if (t==0) dp[t][l+1] = dp[t][l] + dp[t+1][l];
      else if (t==9) dp[t][l+1] = dp[t][l] + dp[t-1][l];
      else dp[t][l+1] = dp[t-1][l] + dp[t][l] + dp[t+1][l];
    }
  }
  int idx = 0;
  bool flag = false;
  int top, len;
  for (int l=1;l<=10;l++){
    for (int t=1;t<10;t++){
      if (idx+dp[t][l]>=K) {
        flag = true;
        top = t, len = l;
        break;
      }
      idx += dp[t][l];
    }
    if (flag) break;
  }

  vector<int> digit;
  digit.push_back(top);
  while (len>1){
    int tmp = 0;
    int to[3] = {-1,0,1};
    rep(i,3){
      if (top+to[i]<0 || top+to[i]>9) continue;
      if (idx+dp[top+to[i]][len-1]>=K) {
        top = top+to[i];
        digit.push_back(top);
        len--;
        break;
      }
      idx += dp[top+to[i]][len-1];
    }

  }
  rep(i, digit.size()) cout << digit[i];
  cout << endl;



  // cout << fixed << setprecision(10);
  
  return 0;
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
#define maxn 200005
using namespace std;
struct node
{
	int x,id;
}a[maxn*2];
bool operator < (node tx,node ty)
{
	return tx.x<ty.x||(tx.x==ty.x&&tx.id<ty.id);
}
struct edge
{
	int next,to;
	edge(){}
	edge(int x,int y):next(x),to(y){}
}e[maxn*20];
int h[maxn*4],cnt;
void addedge(int x,int y)
{
	e[++cnt]=edge(h[x],y);
	h[x]=cnt;
}
int n,tot,num,scc,lc[maxn*4],rc[maxn*4],t[maxn*4],bre[maxn*4],dfn[maxn*4],low[maxn*4],bel[maxn*4];
stack<int> s;
void build(int &v,int l,int r)
{
	if(l==r)
	{
		v=l;return;
	}
	v=++tot;
	int mid=(l+r)/2;
	build(lc[v],l,mid);
	build(rc[v],mid+1,r);
	addedge(v,lc[v]);addedge(v,rc[v]);
}
void add(int v,int l,int r,int u,int tl,int tr)
{
	if(l>tr||r<tl)return;
	if(tl<=l&&r<=tr)
	{
		addedge(u,v);
		return;
	}
	int mid=(l+r)/2;
	add(lc[v],l,mid,u,tl,tr);
	add(rc[v],mid+1,r,u,tl,tr);
}
void dfs(int x)
{
	int y;
	dfn[x]=low[x]=++num;
	s.push(x);
	for(int i=h[x];i;i=e[i].next)
	{
		y=e[i].to;
		if(!dfn[y])
		{
			dfs(y);
			low[x]=min(low[x],low[y]);
		}
		else if(!bel[y])low[x]=min(low[x],dfn[y]);
	}
	if(low[x]==dfn[x])
	{
		bel[x]=++scc;
		while(s.top()!=x)bel[s.top()]=scc,s.pop();
		s.pop();
	}
}
void csh()
{
	int x;
	memset(h,0,sizeof(h));
	memset(bel,0,sizeof(bel));
	memset(low,0,sizeof(low));
	memset(dfn,0,sizeof(dfn));
	num=cnt=scc=0;tot=2*n;
	build(x,1,2*n);	
}
bool check(int mid)
{
	csh();
	int l,r;
	for(int i=1;i<=2*n;i++)
	{
		l=upper_bound(a+1,a+2*n+1,(node){a[i].x-mid,INT_MAX})-a;
		r=lower_bound(a+1,a+2*n+1,(node){a[i].x+mid,0})-a-1;
		if(l<i)add(2*n+1,1,2*n,bre[i],l,i-1);
		if(i<r)add(2*n+1,1,2*n,bre[i],i+1,r);
		if(l>i||r<i)add(2*n+1,1,2*n,bre[i],l,r);
	}
	for(int i=1;i<=2*n;i++)if(!dfn[i])dfs(i);
	for(int i=1;i<=2*n;i++)if(bel[i]==bel[bre[i]])return 0;
	return 1;
}
int main()
{
	int x,maxx=0;
	scanf("%d",&n);tot=2*n;
	for(int i=1;i<=n;i++)
	{
		scanf("%d %d",&a[i].x,&a[i+n].x);
		maxx=max(maxx,max(a[i].x,a[i+n].x)-min(a[i-1].x,a[i+n-1].x));
		a[i].id=a[i+n].id=i;
	}
	sort(a+1,a+2*n+1);
	for(int i=1;i<=2*n;i++)
	{
		if(!t[a[i].id])t[a[i].id]=i;
		else bre[i]=t[a[i].id],bre[t[a[i].id]]=i;
	}
	int l=1,r=maxx,mid,ans=0;
	while(l<=r)
	{
		mid=(l+r)/2;
		if(check(mid))ans=max(ans,mid),l=mid+1;
		else r=mid-1;
	}
	printf("%d\n",ans);
	return 0;
}

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

#define rep(i,n) for (int i = 0; i < (n); ++i)

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

    rep(i,8) {
        int t = N.at(0)-'0';
        rep(j,3) {
            if(i & 1<<j)
                t += N.at(j+1)-'0';
            else
                t -= N.at(j+1)-'0';
        }
        if(t == 7) {
            a = i;
            break;
        }
    }

    cout << N.at(0);
    rep(i,3) {
        if(a & 1<<i)
            cout << '+';
        else
            cout << '-';
        cout << N.at(i+1);
    }
    cout << "=7" << endl;
}

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


int main(){
  int a, b, c, x;
  cin >> a >> b >> c >> x;

  int res = 0;
  
  for(int aa=0;aa<=50;aa++){
    for(int bb=0; bb<=50; bb++){
      for(int cc=0; cc<=50; cc++){
        int r = x - aa * 500 - bb * 100 - cc * 50;
        if(r == 0 && aa <= a && bb <= b && cc <= c)
          res++;
      }
    }
  }
  
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
    long long int n,i;
    scanf("%lld",&n);
    long long int p[100002]={};
    for(i=1;i<=n;i++){
        long long int x,y;
        scanf("%lld",&x);
        y=p[x];
        y++;
        p[x]=y;
        y=p[x+1];
        y++;
        p[x+1]=y;
        y=p[x+2];
        y++;
        p[x+2]=y;
    }
    long long int max=0;
    for(i=0;i<100002;i++){
        if(p[i]>p[max])
            max=i;
    }
    printf("%lld",p[max]);
    return 0;
}


Measured memory_bytes: 896
import static java.util.function.Function.*;
import static java.util.stream.Collectors.*;

import java.util.*;

public class Main {
    public void main(Scanner sc) {
        int n = sc.nextInt();
        Integer a[] = new Integer[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }

        long cnt = 0;
        for (long count : Arrays.stream(a).collect(groupingBy(identity(), counting())).values()) {
            cnt += (count - 1);
        }
        cnt += (cnt % 2);

        System.out.println(n - cnt);
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        new Main().main(sc);
        sc.close();
    }
}


Measured memory_bytes: 68872
u,v=list(map(int,input().split()))
a=[[0]*v for j in range(u)]

for i in range(u):
    a[i]=list(map(int,input().split()))

b=[0 for i in range(v)]

for i in range(v):
    b[i]=int(input())

for i in range(u):
    c=0
    for j in range(v):
        c+=a[i][j]*b[j]
    print(c)


Measured memory_bytes: 5948
n, m = map(int, input().split())
disputes = []
for i in range(m):
    a, b = map(int, input().split())
    disputes.append((b, a))
disputes.sort()
ans = 0
most_right_bridge = 0
for b, a in disputes:
    if most_right_bridge <= a:
        ans += 1
        most_right_bridge = b
print(ans)


Measured memory_bytes: 17016
a,b,m = gets.split.map(&:to_i)
al = gets.split.map(&:to_i)
bl = gets.split.map(&:to_i)

ca = Array.new
cb = Array.new
cx = Array.new
m.times { 
    tm1,tm2,tm3 = gets.split.map(&:to_i)
    ca.push(tm1)
    cb.push(tm2)
    cx.push(tm3)
}
min = 10**5 + 10**5

m.times { |i|
    if min > (al[ca[i]-1] + bl[cb[i]-1] -cx[i]) then
        min = (al[ca[i]-1] + bl[cb[i]-1] - cx[i])
    end
}
if min > (al.min+bl.min) then
    min = (al.min+bl.min)
end

p min

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

int n, a[100008], loc[100008], l[2][100008], r[2][100008];
set<int> s;
set<int, greater<int>> ss;
int main()
{
	scanf("%d", &n);
	for (int i = 1; i <= n; ++i)
	{
		scanf("%d", &a[i]);
		loc[a[i]] = i;
		s.insert(i);
		ss.insert(i);
	}
	s.insert(0);
	s.insert(n + 1);
	ss.insert(0);
	ss.insert(n + 1);
	for (int v = 1; v <= n; ++v)
	{
		int i = loc[v];
		s.erase(loc[v]);
		auto it = s.lower_bound(loc[v]);
		r[0][i] = *it;
		++it;
		if (r[0][i] <= n)
			r[1][i] = *it;
		else
			r[1][i] = n + 1;

		ss.erase(loc[v]);
		it = ss.lower_bound(loc[v]);
		l[0][i] = *it;
		++it;
		if (l[0][i] > 0)
			l[1][i] = *it;
		else
			l[1][i] = 0;
	}
	/*for (int i = 1; i <= n; ++i)
		printf("%d ", l[0][i]);
	printf("\n");
	for (int i = 1; i <= n; ++i)
		printf("%d ", l[1][i]);
	printf("\n");
	for (int i = 1; i <= n; ++i)
		printf("%d ", r[0][i]);
	printf("\n");
	for (int i = 1; i <= n; ++i)
		printf("%d ", r[1][i]);
	printf("\n");*/
	long long ans = 0;
	for (int i = 1; i <= n; ++i)
		ans += ( 1LL*(l[0][i] - l[1][i]) * (r[0][i] - i) + 1LL*(r[1][i] - r[0][i]) * (i - l[0][i]) )* a[i];
	printf("%lld\n", ans);
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef vector<pli> vpli;

inline ll read(){
    ll Hashimoto=0;
	bool Kanna=1;
    char I_Love=getchar();
    while(I_Love<'0'||I_Love>'9'){
        if(I_Love=='-')Kanna=0;
        I_Love=getchar();
    }
    while(I_Love>='0'&&I_Love<='9'){
        Hashimoto=Hashimoto*10+I_Love-'0';
        I_Love=getchar();
    }
    return (Kanna?Hashimoto:-Hashimoto);
}
template<typename T1,typename T2> inline void Umax(T1 &a,T2 b){
	if(a<b)a=b;
}
template<typename T1,typename T2> inline void Umin(T1 &a,T2 b){
	if(a>b)a=b;
}

#define I_Love_Hashimoto_Kanna main
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define filein(s) freopen(s,"r",stdin);
#define fileout(s) freopen(s,"w",stdout);
#define file freopen("I_Love_Hashimoto_Kanna.out","w",stdout);
#define RE cout<<"I_Love_Hashimoto_Kanna"<<endl;
#define Tone(Kanna) cout<<Kanna<<endl;
#define Tall(Hashimoto,Kanna) for(int I_Love=0;I_Love<(Kanna);++I_Love)cout<<Hashimoto[I_Love]<<(I_Love==(Kanna)-1?"\n":" ");
#define FOR(I_Love,Hashimoto,Kanna) for(int I_Love=Hashimoto;I_Love<(Kanna);++I_Love)
#define MP(Hashimoto,Kanna) make_pair(Hashimoto,Kanna)
#define REV(Kanna) reverse(Kanna.begin(),Kanna.end());
#define SORT(Kanna) sort(Kanna.begin(),Kanna.end());
#define UNIQUE(Kanna) Kanna.erase(unique(Kanna.begin(),Kanna.end()),Kanna.end());
#define inf (1000000000)
#define linf (1000000000000000000ll)
#define mod (1000000007)

string s;

int I_Love_Hashimoto_Kanna() {
	//完全想清楚了再开始写。
	//写不顺、不知道怎么写、很乱的时候，停下来好好想想。
	//做得慢总比做不出好。
	fastio;
	cin>>s;
	ll ans=0;
	int cnt=0;
	FOR(i,0,s.size())if(s[i]=='W')ans+=(i-cnt),cnt++;
	Tone(ans)
	
	return 0;
}


Measured memory_bytes: 720
#define r return
#define a (int dx,int dy,int x,int y,char m,int c)
i,j,n,f[6];w[8]={1,1,0,-1,-1,-1,0,1};h[8]={0,1,1,1,0,-1,-1,-1};char t[10][10],mark[2]={'o','x'};l a{if(t[x][y]=='.'||t[x][y]=='0')r 0;if(t[x][y]==m)r c;r l(dx,dy,x+dx,y+dy,m,c+1);}s a{int k,d;d=0;if(t[x][y]!='.')r 0;for(k=0;k<8;k++)d+=l(w[k],h[k],x+w[k],y+h[k],m,0);r d;}p a{if(t[x][y]=='0'||t[x][y]=='.')r 0;if(t[x][y]==m)r 1;if(p(dx,dy,x+dx,y+dy,m,0)){t[x][y]=m;r 1;}else r 0;}o a{int k;t[x][y]=m;for(k=0;k<8;k++)p(w[k],h[k],x+w[k],y+h[k],m,0);r 0;}main(){for(i=0;i<10;)t[0][i]=t[9][i++]='0';for(i=1;i<9;t[i][0]=t[i++][9]='0')scanf("%s",&t[i][1]);for(n=f[1]=-1;;n=(n+1)%2){f[n]=-1;for(i=n?8:1;n?i>-1:i<9;n?i--:i++)for(j=n?8:1;n?j>-1:j<9;n?j--:j++)f[n]<s(0,0,i,j,mark[n],0)?f[2+n]=i,f[4+n]=j,f[n]=s(0,0,i,j,mark[n],0):0;f[n]!=0?o(0,0,f[2+n],f[4+n],mark[n],0):0;if(f[0]==0&&f[1]==0)break;}for(i=1;i<9;i++){for(j=1;j<9;j++)printf("%c",t[i][j]);puts("");}r 0;}

Measured memory_bytes: 524
import Control.Monad

main = do
  t <- read <$> getLine :: IO Int
  xs <- forM [1..t] $ \x -> do
    read <$> getLine :: IO Int
  --putStrLn .show $ xs
  case solve xs 0 of
    Nothing -> putStrLn . show $ (-1)
    Just (a,b) -> putStrLn . show $ a

solve :: [Int] -> Int -> Maybe (Int,Int)
solve [] i = Just (0, 0)
solve (x:[]) i = if x <= i then Just(x,x) else Nothing
solve (x:xs) i = 
  case solve xs (i+1) of
    Nothing -> Nothing
    Just (a,b) ->
      if x == b-1 then 
        Just (a,x) 
      else if x > i || b /= 0 && x < b-1 then 
        Nothing 
      else Just (a + x, x)

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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vll = vector<ll>;
template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;

template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

vint Z_algorithm(vint &W) {
    int i = 1, j = 0;
    vint Z(W.size());
    Z[0] = W.size();
    while (i < W.size()) {
        while (i + j < W.size() && W[i + j] == W[j]) ++j;
        Z[i] = j; 
        if (j == 0) { ++i; continue; }
        int k = 1;
        while (Z[k] + k < j) Z[i + k] = Z[k], ++k;
        i += k, j -= k;
    }
    return (Z);
}
int main() {
    int N; cin >> N;
    vint a(N), b(N);
    vint A(N), B(N);
    for (auto &v : a) cin >> v; 
    for (auto &v : b) cin >> v; 
    A = a, B = b;
    for (int i = 0; i < N; i++) {
        if (i > 0) A[i - 1] ^= A[i];
    }
    A[N - 1] ^= a[0];
    for (int i = 0; i < N; i++) {
        if (i > 0) B[i - 1] ^= B[i];
    }
    B.pop_back(); 

    copy(begin(A), end(A), back_inserter(B));
    copy(begin(A), end(A), back_inserter(B));
    
    vint ans = Z_algorithm(B);
    int cnt = 0;
    for (int i = N - 1; i < 2 * N - 1; i++) {
        if (ans[i] >= N - 1) {
            cout << (i - N + 1) << " " << (a[i - N + 1] ^ b[0]) << el;
        }
    }

    return (0);
}

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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

int main(void){
	long double n, d, m;
	cin >> n >> m >> d;
	if(d == 0)
		cout << fixed << setprecision(10) << n/(n*n)*(m-1) << endl;
	else 
		cout << fixed << setprecision(10) << (2*d+2*max((long double)0, (n-2*d)))/(n*n)*(m-1) << endl;
}

Measured memory_bytes: 256