akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define inf 0x7fffffff
#define RG register
#define maxn 500005
#define maxm 205
using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;
inline ll read(){
    ll x = 0, f = 1;
    char ch = getchar();
    while(ch > '9' || ch < '0') {if(ch == '-') f = -1;ch = getchar();}
    while(ch >= '0' && ch <= '9'){x = x *10 + ch -'0';ch = getchar();}
    return x * f;
}
 
int n, k;
ll ans;
char ch[11];
void dfs(int now,ll lasnum,ll sum){
	if(now == n){
		sum += lasnum;
		ans += sum;
		return ;
	}
	dfs(now + 1, lasnum * 10 + ch[now + 1] - '0', sum);
	dfs(now + 1, ch[now + 1] - '0', sum + lasnum);
}
int main(){
	int i, j, x, l, r, mid;
	scanf("%s", ch + 1);
	n = strlen(ch + 1);
	dfs(1, ch[1] - '0', 0);
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 3776
#include <iostream>
#include <algorithm>
#include <utility>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <math.h>
#include <string.h>
#include <iomanip>
#include <numeric>
#include <cstdlib>
#include <cstdint>
#include <cmath>
#include <functional>
#include <limits>
#include <cassert>

using namespace std;

using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpll = vector<pll>;

void debug_out() { std::cout << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cout << "debug: "; debug_out(__VA_ARGS__)
#else
#define debug(...) 
#endif

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define Rep(i, n) for (long long i = 0; i< (long long)(n); i++)
#define RRep(i,n) for (long long i = ((long long)(n)-1); i>=0; i--)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()

struct Edge{
    int to;
    int weight;
    Edge(int t, int w) : to(t), weight(w){ }
};

struct edge{
    int from;
    int to;
    int weight;
    edge(int f,int t,int w) : from(f), to(t), weight(w){ }
};


using Graph = vector<vector<Edge>>;
using graph = vector<vector<int>>;
using edges = vector<edge>;

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;
}

template <class T>
T gcd(T a, T b){
    if( b==0 ) return a;
    return gcd(b, a%b);
}

template <class T>
T lcm(T a, T b){
    return (a*b)/gcd(a,b);
}

bool isPalindrome(string s){
    string t = s;
    reverse(all(t));
    return s==t;
}

constexpr ll INF = 1e9+7;

vector<int> dx = {-1,0,1,0};
vector<int> dy = {0,-1,0,1};

std::vector<int> Eratosthenes( const int N )
{
    std::vector<bool> is_prime( N + 1 );
    for( int i = 0; i <= N; i++ )
    {
        is_prime[ i ] = true;
    }
    std::vector<int> P;
    for( int i = 2; i <= N; i++ )
    {
        if( is_prime[ i ] )
        {
            for( int j = 2 * i; j <= N; j += i )
            {
                is_prime[ j ] = false;
            }
            P.emplace_back( i );
        }
    }
    return P;
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<int> ans;
    for(auto x: Eratosthenes(55555)){
        if(x%5==1){
            ans.emplace_back(x);
        }
        if(ans.size()==n){
            break;
        }
    }
    rep(i,n){
        cout << ans[i] << " ";
    }
    cout << endl;
}

Measured memory_bytes: 384
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int N, R;
  cin>>N>>R;
  if(N>=10) cout<<R<<endl;
  else cout<<R+100*(10-N)<<endl;
}



Measured memory_bytes: 3604
#include <bits/stdc++.h>
#include <math.h>
#include <cmath>
 
using namespace std;
using ll =long long;
using vi = vector<int>; 
using vvi = vector<vi>; 
using vl = vector<ll>; 
using vvl = vector<vl>; 
using vs = vector<string>;
using vvs = vector<vs>; 
using vc = vector<char>;
using vvc = vector<vc>; 
using vb = vector<bool>;
using vvb = vector<vb>; 
 
#define rep(i,n) ;for( int i =0; i < n ; i ++)
#define all(a) a.begin(),a.end()
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define f(i,a,b) for(int i=a;i<b;i++)
#define pri(a)  printf("%.14lf\n",a);
#define MOD 1000000007
typedef pair<int, int> P;
bool is_int_lround(double x){
  return std::lround(x)==x;
}
int ketasuu(int x){
  int n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}


ll conbi(int n,int m){
  
  cin>>n>>m;
  vector<ll> a(100);
  a[0] =1;
  for(int i=0;i<14;i++){
    a[i+1]=a[i]*(i+1);
  }
  return a[n] /(a[m] *a[n-m]);
}


int main(){
  int N,T;cin>>N>>T;
  vi c(N),t(N);
  rep(i,N)cin>>c[i]>>t[i];
  int ans=1001;
  rep(i,N){
    if(t[i]<=T)ans =min(ans,c[i]);
  }
  if(ans ==1001)cout<<"TLE"<<endl;
  else cout<<ans<<endl;

  
}





Measured memory_bytes: 256
n = int(input())
p = list(map(int,input().split()))
ans = 0
for i in range(1,n-1):
  if(p[i-1] > p[i] and p[i] > p[i+1]):
    ans += 1
for i in range(1,n-1):
  if(p[i-1] < p[i] and p[i] < p[i+1]):
    ans += 1
print(ans)

Measured memory_bytes: 3064
x, n = map(int, input().split())

if n == 0:
    # input()
    print(x)
else:
    l = list(map(int, input().split()))
    l.sort()
    small = x
    large = x
    while small in l and large in l:
        small -= 1
        large += 1
    if small in l:
        print(large)
    elif large in l:
        print(small)
    elif x - small > large - x:
        print(large)
    else:
        print(small)


Measured memory_bytes: 9192
from sys import stdin, stdout
import math,sys
from itertools import permutations, combinations
from collections import defaultdict,deque,OrderedDict
from os import path
import bisect as bi
import heapq 
def yes():print('YES')
def no():print('NO')
if (path.exists('input.txt')): 
    #------------------Sublime--------------------------------------#
    sys.stdin=open('input.txt','r');sys.stdout=open('output.txt','w');
    def I():return (int(input()))
    def In():return(map(int,input().split()))
else:
    #------------------PYPY FAst I/o--------------------------------#
    def I():return (int(stdin.readline()))
    def In():return(map(int,stdin.readline().split()))

def dict(a):
    d={}
    for x in a:
        if d.get(x,-1)!=-1:
            d[x]+=1
        else:
            d[x]=1
    return d

def main():
    try:
        l=[]
        n=I()
        for x in range(n):
            l.append(input())
        #d=dict(l)
        d={}
        temp=['AC','WA','TLE','RE']
        for x in temp:
            d[x]=0
        for x in l:
            d[x]+=1
        print('AC x',d['AC'])
        print('WA x',d['WA'])
        print('TLE x',d['TLE'])
        print('RE x',d['RE'])
    except:
        pass
        
M = 998244353
P = 1000000007
 
if __name__ == '__main__':
    #for _ in range(I()):main()
    for _ in range(1):main()

Measured memory_bytes: 16448
import sys
import copy
import  math
import bisect
from collections import *
from operator import itemgetter
"""
from fractions import gcd
def lcm(x, y):
    return (x * y) // gcd(x, y)
"""
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

n = input()
print('Yes' if "9" in n else 'No')





Measured memory_bytes: 3444
#include <stdio.h>


int main()
{
    double l,a,b,c;
    scanf("%lf",&l);
    a=l/3;
   // printf("%f   \n",a);
    double vmax=a*a*a;
    for(;a<l;a++){
        for(b=l/3;b<l;b++){
            for(c=l/3;c<l;c++)
                if(a+b+c==l && a*b*c>vmax)
                vmax=a*b*c;
        }
    }
    printf("%.12f",vmax);
    return 0;
}


Measured memory_bytes: 384
import java.util.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main {

	class UnionFind{
		int[] pars;
		UnionFind(int n){
			pars = new int[n];
			for(int i=0; i<n; i++) pars[i] = i;
		}
		int getRoot(int x){
			return x==pars[x]?x:(pars[x] = getRoot(pars[x]));
		}
		boolean isSame(int x, int y){
			return getRoot(x) == getRoot(y);
		}
		void merge(int x, int y){
			pars[getRoot(x)] = getRoot(y);
		}
	}

	double sq(double x){ return x*x; }

	class Cell{
		double x, y, z, r;
		Cell(double _x, double _y, double _z, double _r){
			this.x = _x;
			this.y = _y;
			this.z = _z;
			this.r = _r;
		}
		double getDist(Cell a){
			return sqrt(sq(x-a.x) + sq(y-a.y) + sq(z-a.z));
		}
	}

	class Edge{
		double dist;
		int a, b;
		Edge(double _d, int _a, int _b){
			this.dist = _d;
			this.a = _a;
			this.b = _b;
		}
	}

	class Cmp implements Comparator<Edge>{
		public int compare(Edge e1, Edge e2){
			return e1.dist>e2.dist?1:e1.dist<e2.dist?-1:0;
		}
	}

	int N;
	Cell[] cells;

	void run(){
		Scanner in = new Scanner(System.in);
		for(;;){
			N = in.nextInt();
			if(N==0) return ;
			cells = new Cell[N];
			for(int i=0; i<N; i++){
				cells[i] = new Cell(in.nextDouble(), in.nextDouble(), in.nextDouble(), in.nextDouble());
			}
			System.out.printf("%.3f\n", solve());
		}
	}


	double solve(){
		double ret = 0.0;
		UnionFind uf = new UnionFind(N);
		ArrayList<Edge> es = new ArrayList<Edge>();
		for(int i=0; i<N; i++){
			for(int j=i+1; j<N; j++){
				double d = cells[i].getDist(cells[j]) - cells[i].r - cells[j].r;
				if(d <= 0) uf.merge(i, j);
				else es.add(new Edge(d, i, j));
			}
		}
		Edge[] ees = (Edge[])es.toArray(new Edge[0]);
		sort(ees, new Cmp());
		for(int i=0; i<ees.length; i++){
			if(!uf.isSame(ees[i].a, ees[i].b)){
				uf.merge(ees[i].a, ees[i].b);
				ret += ees[i].dist;
			}
		}
		return ret;
	}

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

Measured memory_bytes: 13000
#include <bits/stdc++.h>
using namespace std;
#define _MACRO(_1, _2, _3, NAME, ...) NAME
#define _repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define _rep(i,n) _repl(i,0,n)
#define rep(...) _MACRO(__VA_ARGS__, _repl, _rep)(__VA_ARGS__)
#define mp make_pair
#define pb push_back
#define all(x) begin(x),end(x)
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cerr<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cerr<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
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> v(n);
  rep(i,n) cin>>v[i];

  auto u = v;
  sort(all(u));

  rep(i,n){
    if(v[i] <= u[n/2 - 1]) cout << u[n/2] << endl;
    else cout << u[n/2 - 1] << endl;
  }

  return 0;
}


Measured memory_bytes: 3712
import math
pi = math.atan(1)*4

def andrange(a, b):
    if a == (0, 0) or b == (0, 0): return (0, 0)
    if a == (0, 1): return b
    if b == (0, 1): return a
    if a[0] > b[0]: a, b = b, a
    if b[1] < a[1]:
        return b
    if b[0] < a[1] and b[1] >= a[1]:
        return (b[0], a[1])
    if b[0] >= a[1] and b[1] < a[0] + 1:
        return (0, 0)
    if b[1] >= a[0] + 1 and b[1] < a[1] + 1:
        return (a[0], b[1] - 1)
    if b[1] >= a[0] + 1 and b[1] >= a[1] + 1:
        return a

def calcrange(P, Q):
    c = calc(P, Q)
    if c > 0:
        return (c, c+0.5)
    else:
        return (c+1, c+1.5)

def calc(P, Q):
    x = P[0] - Q[0]
    y = P[1] - Q[1]
    if x == 0:
        return 0.25 if y > 0 else -0.25
    t = math.atan(y/x)
    return t/(2*pi) if x > 0 else (t/(2*pi) % 1) - 0.5

N = int(input())
X = []
for _ in range(N):
    x, y = map(int, input().split())
    X.append((x, y))

A = [(0, 1) for _ in range(N)]

for i in range(N):
    for j in range(N):
        if i != j:
            A[i] = andrange(A[i], calcrange(X[i], X[j]))

for a in A:
    print("{:.20f}".format(a[1] - a[0]))


Measured memory_bytes: 3188
#include <iostream>
#include <cstdio>
#include <algorithm>
#define Foru(i,a,b) for(int i=a;i<=b;++i)
using namespace std;
int main(int argc, char const *argv[])
{
	int n;
	cin>>n;
	int b[103]={0};
	int a[103]={0};
	Foru(i,1,n-1)
	{
		scanf("%d",b+i);
	}
	b[n]=1999999;
	long long sum=0;
	for(int i=n+1;i>=1;--i)
	{
		a[i]=b[i-1];
		if(a[i]>=b[i])
			a[i]=b[i];
		sum+=a[i];
	}
	cout<<sum+b[1]<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using VVI = vector<vector<int>>;
const int INF = 1001001001;
const int MOD = 1000000007;

template <typename T>
void print(const T &v);

bool dp[30009][4][1009];
string s;
int n;

int main()
{
    cin >> n >> s;
    dp[0][0][0] = true;

    for (int i = 0; i < n; i++) // 桁数
    {
        for (int j = 0; j <= 3; j++)
        {
            for (int k = 0; k < 1000; k++)
            {
                if (dp[i][j][k] == false)
                {
                    continue;
                }
                dp[i + 1][j][k] = true;
                if (j <= 2)
                {
                    dp[i + 1][j + 1][k * 10 + (s[i] - '0')] = true;
                }
            }
        }
    }
    int cnt = 0;
    for (int i = 0; i < 1000; i++)
    {
        if (dp[n][3][i] == true)
            cnt++;
    }
    cout << cnt << endl;
    return 0;
}

// Use For Debug
template <typename T>
void print(T const &v)
{
    for (int i = 0; i < v.size(); i++)
    {
        if (i)
            cout << " ";
        cout << v[i];
    }
    cout << endl;
}

Measured memory_bytes: 121920
#include <iostream>
#include <algorithm>
#include <string.h>

using namespace std;

#define pb push_back
#define mp make_pair
#define ll long long
#define ull unsigned ll
#define db double
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define PII pair<int, int>

int n;
ll a[100010];
char op[100010];
char buf[8];
ll l=0,r=0,ans=-2e11;

int main() {
    scanf("%d",&n);
    scanf("%lld",&a[0]);
    l=a[0];
    for (int i=1;i<n;i++) {
        scanf("%s",buf);
        scanf("%lld",a+i);
        op[i]=buf[0];
        r+=a[i];
    }
    int idx=1;
    while (idx<n&&op[idx]=='+') {
        l+=a[idx];
        r-=a[idx];
        idx++;
    }
    ll tmp=0;
    while (idx<n) {
        l+=2*tmp;
        l-=a[idx];
        r-=a[idx];
        idx++;
        tmp=0;
        while (idx<n&&op[idx]=='+') {
            tmp+=a[idx];
            l-=a[idx];
            r-=a[idx];
            idx++;
        }
        ans=max(ans,l+r);
    }
    ans=max(ans,l+r);
    printf("%lld\n",ans);
}

Measured memory_bytes: 1152
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
using namespace std;
int p[110000];
int main(){
	int a,b;scanf("%d%d",&a,&b);
	for(int i=0;i<a;i++){
		scanf("%d",p+i);
	}
	for(int i=0;i<a-1;i++){
		if(p[i]+p[i+1]>=b){
			printf("Possible\n");
			for(int j=0;j<i;j++)printf("%d\n",j+1);
			for(int j=a-2;j>=i;j--)printf("%d\n",j+1);
			
			return 0;
		}
	}
	printf("Impossible\n");
}

Measured memory_bytes: 1152
n, k = [int(i) for i in input().split()]
V = [int(i) for i in input().split()]
plusList = [i >= 0 for i in V]
max_sum = 0

for ki in range(k+1):
    for mi in range(ki+1):
        for ii in range(ki-mi+1):
            if ki-mi-ii-1 >= n-ii:
                inHand = V
                ret_num = mi + ki-mi-ii-1 - (n-ii) + 1
            else:
                inHand = V[:ki-mi-ii]+V[n-ii:]
                ret_num = mi
            inHand.sort()    
            for jj in range(ret_num):
                if inHand != [] and inHand[0] < 0:
                    del inHand[0]
            if max_sum < sum(inHand):
                max_sum = sum(inHand)

print(max_sum)


Measured memory_bytes: 3064
#include <iostream>

using namespace std;

int main(){
    int N;
    bool flag = false;
    cin >> N;
    for(int i = 0; i <= 25; i++){
        for(int j = 0; j <= 14; j++){
            if(4 * i + 7 * j == N) flag = true;
        }
    }
    if(flag) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;
const ll mod = 1e9 + 7;



int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  string r(s);
  reverse(r.begin(), r.end());
  cout << (r == s ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
ll GetDigit(ll num){ return log10(num)+1; } //numの桁数を求める

int main()
{
    int n;
    cin >> n;
    vector<pair<ll, ll>> p(n);
    rep(i,n){
        cin >> p[i].second >> p[i].first;
    }
    sort(p.begin(),p.end());
    ll time = 0;
    rep(i,n){
        time += p[i].second;
        if(time > p[i].first){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 6392
use proconio::input;

fn main() {
  input! {
    n: usize,
    d: f64,
    ai: [(f64, f64);n]
  }
  let mut count = 0;
  
  for (a, b) in ai {
    if (a * a + b * b).sqrt() <= d {
      count += 1;
    }
  }
  println!("{}", count);
}

Measured memory_bytes: 7836
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;

//#define int long long
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);
const double EPS = 1e-10;
void goahead(char &x, int i) {
	rep(j, 0, i) {
		if (x == 'z')x = 'a';
		else x++;
	}
}
signed main() {
	int n;
	while (cin >> n, n) {
		string mes; cin >> mes;
		vector<int>a(n), b(n);
		rep(i, 0, n)cin >> a[i] >> b[i];
		rrep(i, 0, n) {
			a[i]--; b[i]--;
			goahead(mes[a[i]], abs(a[i] - b[i]));
			goahead(mes[b[i]], abs(a[i] - b[i]));
			swap(mes[a[i]], mes[b[i]]);
		}
		cout << mes << endl;
	}
	return 0;
}

Measured memory_bytes: 3004
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
using namespace std;

int main(){
	int N;
	cin >> N;
	vector<int> b(N);
	for(int i=0;i<N;i++){
		cin >> b[i];
	}
	vector<int> a;
	int check = 1;
	while(check){
		if((int)b.size() == 0) check = 0;
		for(int i=(int)b.size() - 1;i>=0;i--){
			if(b[i] == i+1) {
				b.erase(b.begin() + i);
				a.push_back(i+1);
				break;
			}
			if(i == 0){
				check = 0;
			}
		
		}
	}
	if((int)b.size() > 0) cout << -1 << endl;
	else{
		for(int i=0;i<(int)a.size();i++){
			cout << a[(int)a.size() - 1 - i] << endl;
		}
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
  long A,B,N;
  cin>>A>>B>>N;
  
  long sw=0;
  
  if(N<B){
    sw=(A*N)/B-A*(N/B);
  }else{
    sw=(A*(B-1))/B;
  }
  
  cout<<sw<<endl;
  
  
  
}



Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
const long long INF = 1LL << 60;

int main()
{
    ll n, m;
    cin >> n >> m;
    int a;
    for (ll i = 0; i < m; i++)
    {
        cin >> a;
        n -= a;
    }
    if (n < 0)
    {
        cout << -1 << endl;
    }
    else
    {

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



Measured memory_bytes: 3616
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
#include <iomanip>
#include <deque>
typedef long long ll;
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>=b;--i)
using namespace std;
using vi = vector<int>;
using vll = vector<ll>;
ll mod = 1e9 + 7;
ll llmax = 10000000000000000000ll;
using namespace std;
using Graph = vector<vector<int>>;
Graph G;
const int AMAX = 100000;
/*int cnt_digit(ll N)
{
	int digit = 0;

	while (N > 0)
	{
		N /= 10;
		digit++;
	}
	return digit;
}



int n;
vll a;

ll solve(bool isp)
{
	ll sum = 0ll;
	ll ret = 0ll;

	for (int i = 0; i < n; i++)
	{
		sum += a[i];
		if (isp and sum <= 0)
		{
			ret += -sum + 1;
			sum = 1ll;
		}
		if (not isp and sum >= 0)
		{
			ret += sum + 1;
			sum = -1ll;
		}
		isp ^= 1;
	}
	return ret;
}

*/


/*
 * 最大公約数計算
 */
ll gcd(ll a, ll b)
{
	if (b == 0) {
		return a;
	}
	else {
		return gcd(b, a % b);
	}
}

ll lcm(ll a, ll b)
{
	ll g = gcd(a, b);

	return a / g * b;
}

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

	cin >> N >> K;
	vector <int> data(N);
	for (auto& i : data)
	{
		cin >> i;
	}
	int ans = 0;

	for (auto& i : data)
	{
		int a = i;
		int b = abs(i - K);
		int small = min(a, b);
		ans += 2*small;
	}
		cout << ans << endl;
	return 0;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(ll i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

int main() {
    int n, ans = 1, j = 2;
    cin >> n;
    vector<int> a(n);
    rep(i, n)cin >> a.at(i);
    for(int i = 1; i < n; i++){
        if(j == 2){
            if(a[i-1] < a[i])j = 3;
            else if(a[i-1] > a[i])j = 1;
        }
        else if(a[i-1] < a[i] && j == 1){
            j = 2; 
            ans++;
        }
        else if(a[i-1] > a[i] && j == 3){
            j = 2;
            ans++;
        }
    }
    cout << ans << endl;
}

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

def main():
  h, w, n = map(int, input().split())
  xy = sorted([list(map(int, input().split())) for _ in range(n)])
  dx = 0
  dy = 0
  for x, y in xy:
    x -= dx
    y -= dy
    if x == y:
      dx += x-1
      dy += y-2
    elif y < x:
      print(dx+x-1)
      break
  else:
    print(h)
    
if __name__ == "__main__":
  main()

Measured memory_bytes: 54264
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

int main(void){
	int n,i;
	string s;
	cin >> s;
	fill(s.begin(),s.end(),'x');
	cout << s << endl;
	return 0;
}


Measured memory_bytes: 256
from sys import stdin
from numpy import array
input = lambda: stdin.readline().rstrip()
na, nb, m = map(int, input().split())
a = array(list(map(int, input().split())))
b = array(list(map(int, input().split())))
ans = min(a) + min(b)
for i in range(m):
    x, y, c = map(int, input().split())
    x -= 1
    y -= 1
    ans = min(ans, a[x] + b[y] - c)
print(ans)

Measured memory_bytes: 39284
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
int N, A, B;
cin>>N>>A>>B;
string s;
cin>>s;
vector<string> ans;
int P, Q;
P = Q = 0;
for(int i = 0; i < N; ++i){
if(s[i] == 'a'){
if(P < A + B){
    ans.push_back("Yes");
        P++;
    }
    else{
        ans.push_back("No");
    }
}
if(s[i] == 'b'){
    if(P < A + B){
        if(Q < B){
            ans.push_back("Yes");
            P++;
            Q++;
        }
        else{
            ans.push_back("No");
        }
     }
     else{
        ans.push_back("No");
     }
}
if(s[i] == 'c'){
ans.push_back("No");
}
}
for(auto & x : ans)cout<<x<<endl;
return 0;
}


Measured memory_bytes: 6260
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  	int N;
  	cin >> N;
    long long B = 0;
  	vector<long long> bar(N);
  	for (int i= 0;i<N;i++){
          cin >> bar.at(i);
          B = bar.at(i) + B;
    }
  	//cout << B;
    
    long long count = 0;
    
    long long A = 0;
    long long ans = 2020202020;

    for (int j = 0;j<N;j++){
        count = 0;
        A = A + bar.at(j);
      	//cout << A << endl;
        B = B - bar.at(j);
      	//cout << B << endl;
        if (A>=B){
            count = A - B;
          	//cout << "count:" << count << endl;
        }
        else{
            count = B - A;
        }
        if (count<=ans){
            ans = count;
        }
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  int a,b;
  cin >>n;
  b = 1<<30;
  a =1;
  for(int i=0;i<n;i++){
    int A,B;
    cin >> A>>B;
    if( B <b){
      b= B;
      a = A;
    }
  }
  cout << a+b;
}

Measured memory_bytes: 256
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"

using namespace std;

//const long long int MOD = 1000000007;
const long long int MOD = 998244353;

long long int N, M, K, H, W, L, R;

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

	cin >> N;
	vector<int>v(N);
	vector<int>w(N);
	for (auto &i : v)cin >> i;
	bool flag = true;
	L = -1;
	for (int i = N - 1; i >= 0; i--) {
		if (v[i] == 1) {
			if (flag) {
				L = i;
			}
		}
		else {
			if (L != -1)flag = false;
		}
	}
	if (L == -1) {
		cout << 0 << endl;
		return 0;
	}
	for (int i = 0; i < N; i++) {
		w[i] = v[(i + L) % N];
	}
	vector<int>l(N + 1, -1);
	vector<int>r(N + 1, -1);
	for (int i = 0; i < N; i++) {
		if (r[w[i]] == -1) {
			r[w[i]] = i;
			l[w[i]] = i;
		}
		else if (r[w[i]] == i - 1) {
			r[w[i]] = i;
		}
		else {
			cout << 0 << endl;
			return 0;
		}
	}
	w.push_back(1);
	long long int ans = 1;
	if (r[1] == N - 1) {
		for (int i = 2; i <= N; i++) {
			ans *= i;
			ans %= MOD;
		}
		cout << ans << endl;
		return 0;
	}
	int by = 0;
	for (int i = 2; i <= N; i++) {
		if (l[i] == -1) {
			ans *= by;
			by--;
			ans %= MOD;
		}
		else if (r[i] - l[i] > r[1] - l[1]) {
			cout << 0 << endl;
			return 0;
		}
		else if (w[l[i] - 1] > i&&w[r[i] + 1] > i&&r[i] - l[i] < r[1] - l[1]) {
			cout << 0 << endl;
			return 0;
		}
		else if (r[i] - l[i] <= r[1] - l[1]) {
			if (w[l[i] - 1] < i&&w[r[i] + 1] < i) {
				ans *= r[1] - l[1] - (r[i] - l[i]) + 1;
				by += r[1] - l[1] + 1 + r[i] - l[i] + 1 - 2;
				ans %= MOD;
			}
			else if(!(w[l[i] - 1] > i&&w[r[i] + 1] > i)){
				by += r[i] - l[i];
			}
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 7296
N = int(input())
S = input()

ans = 0
for i in range(1000):
    num = str(i).zfill(3)
    if S.find(num[0]) == -1:
        continue
    S1 = S[S.find(num[0]) + 1:]
    if S1.find(num[1]) == -1:
        continue
    S2 = S1[S1.find(num[1]) + 1:]
    if S2.find(num[2]) == -1:
        continue
    ans += 1

print(ans)

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

int64_t MOD = 1000000007;
int64_t MAX = 9223372036854775807;
double PI = 3.141592653589793;

vector<bool> ketawa(int64_t N)
{
    vector<bool> list(10);
    int64_t d = 0;
    while (N != 0)
    {
        list[N % 10] = true;
        N /= 10;
    }
    return list;
}

int main()
{
    int N, K;
    cin >> N >> K;
    vector<int> list(10);
    for (int i = 0; i < N; i++)
    {
        int tmp;
        cin >> tmp;
        list[tmp] = true;
    }

    while (true)
    {
        auto x = ketawa(N);
        bool y = true;
        for (int i = 0; i < 10; i++)
            if (x[i] && list[i])
                y = false;
        if (y)
        {
            cout << N;
            break;
        }
        N++;
    }
}

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

using namespace std;
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
constexpr int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, -1, 1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os; }
template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) {os << "(" << p.first << ", " << p.second << ")"; return os;}

void solve() {
    int N, T;
    cin >> N >> T;
    int ans = 10000;
    for (int i = 0; i < N; i++) {
        int c, t;
        cin >> c >> t;
        if (t <= T) {
            ans = min(ans, c);
        }
    }
    if (ans == 10000) {
        cout << "TLE" << endl;
    } else {
        cout << ans << endl;
    }
}

int main() {
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}

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

#define FOR(i,a,b)  for(ll (i)=a;(i)<(b);++(i))
#define RFOR(i,a,b) for(ll (i)=a;(i)>=(b);--(i))
#define REP(i,n)    FOR(i,0,n)
#define RREP(i,n)   RFOR(i,n,0)
#define SZ(v)       (ll)(v).size()
#define ALL(v)      (v).begin(),(v).end()
#define UNIQ(v)     sort(ALL(v));(v).erase(unique(ALL(v)),(v).end())
#define IN(x,l,r)   ((l)<=(x)&&(x)<=(r))
#define BIT(n)      (1LL<<(n))
#define PQ(T)       priority_queue<T,vector<T>,greater<T>>
#define SHOW(x)     cout<<#x<<" = "<<x<<endl

template<typename T>string join(const vector<T>& v, string d=" ")
{stringstream s;REP(i,SZ(v))s<<d<<v[i];return s.str().substr(d.length());}

template<typename T> ostream& operator<<(ostream& s, const vector<T>& v)
{if(SZ(v))s<<join(v,", ");return s;}

const ll inf = 1e15;
const ll mod = 1e9+7;
const double eps = 1e-10;

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

struct union_find_tree {
    vector<ll> par;
    vector<ll> rnk;
    union_find_tree() = default;
    explicit union_find_tree(size_t n) : par(n+1), rnk(n+1, 0) {}
    
    void init(ll n) {
        REP(i, n+1) par[i] = i;
    }
    
    ll find(ll x) {
        if (par[x] == x) return x;
        return par[x] = find(par[x]);
    }
    
    void unite(ll x, ll y) {
        x = find(x);
        y = find(y);
        if (x == y) return;
        
        if (rnk[x] < rnk[y]) par[x] = y;
        else {
            par[y] = x;
            if (rnk[x] == rnk[y]) rnk[x]++;
        }
    }
    
    bool same(ll x, ll y) {
        return find(x) == find(y);
    }
};

int main() {
    ll N, K, L; cin >> N >> K >> L;
    
    union_find_tree uf1(N);
    uf1.init(N);
    REP(i, K) {
        ll p, q; cin >> p >> q;
        uf1.unite(p, q);
    }
    
    union_find_tree uf2(N);
    uf2.init(N);
    REP(i, L) {
        ll r, s; cin >> r >> s;
        uf2.unite(r, s);
    }
    
    map<pair<ll, ll>, ll> cnt;
    REP(i, N) cnt[make_pair(uf1.find(i+1), uf2.find(i+1))]++;
    
    REP(i, N) cout << cnt[make_pair(uf1.find(i+1), uf2.find(i+1))] << " ";
    cout << endl;
    
    return 0;
}


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

#define ll long long int
#define pb push_back
#define f(i,x,y) for(i=x;i<y;i++)
#define vll vector<ll>
#define fast    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl

void solve()
{
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    ll ans;
    
    ans=max(a*c,max(a*d,max(b*c,b*d)));
                cout<<ans<<endl;
}

int main()
{
    fast;
    ll t=1;
    //cin>>t;
    while(t--)
        solve();
    return 0;
}

Measured memory_bytes: 3632
import sys
import math
X = int(input())


def f(n):
    return int(math.pow(n, 5))


C = []


lastV = 0

count = 0
while True:
    tmp = f(count)
    C.append(tmp)
    count += 1
    if tmp - lastV > 10 ** 9 + 10:
        break
    lastV = tmp


for j in range(len(C)):
    for i in range(len(C)):
        if C[i] + C[j] == X:
            print(*[i, -j])
            sys.exit(0)
        elif C[i] - C[j] == X:
            print(*[i, j])
            sys.exit(0)


Measured memory_bytes: 64384
# -*- coding: utf-8 -*-
#ARC087C
import sys
import math

n=int(input())

pt=0
px=0
py=0

for i in range(0,n):
	tmp = input().split()
	t,x,y = list(map(lambda a: int(a), tmp))

	if((t-pt)%2!=(abs(x-px)+abs(y-py))%2):
		print("No")
		sys.exit()
	if(t-pt<(abs(x-px)+abs(y-py))):
		print("No")
		sys.exit()
	pt=t
	px=x
	py=y
#	print("{} {} {}".format(t,x,y))
print("Yes")


Measured memory_bytes: 3064
S = gets.chomp
T = gets.chomp

if T.chars.uniq.all? {|s| S.include?(s) }
  pos = Hash.new {|h,k| h[k] = [] }
  S.each_char.with_index(1) {|c,i| pos[c] << i }

  i = 0
  l = 0
  T.each_char do |c|
    a = pos[c]
    j = 0
    k = a.size - 1
    m = 0
    n = nil
    while j <= k
      m = j + (k-j)/2
      if i < a[m]
        n = a[m]
        k = m - 1
      else
        j = m + 1
      end
    end
    if n
      i = n
    else
      l += 1
      i = 0
      redo
    end
  end
  puts i + S.size * l
else
  puts -1
end


Measured memory_bytes: 12540
grid = []
for i in range(3):
    grid.append(list(map(int, input().split())))
N = int(input())
for i in range(N):
    b = int(input())
    for i in range(3):
        for j in range(3):
            if grid[i][j] == b:
                grid[i][j] = 0

bingo = False
for i in range(3):
    if grid[i][0] == grid[i][1] == grid[i][2] == 0:
        bingo = True
for i in range(3):
    if grid[0][i] == grid[1][i] == grid[2][i] == 0:
        bingo = True
if grid[0][0] == grid[1][1] == grid[2][2] == 0:
    bingo = True
if grid[0][2] == grid[1][1] == grid[2][0] == 0:
    bingo = True

if bingo:
    print("Yes")
else:
    print("No")


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

#define rep(i, first, to) for(ll i = first; i < to; ++i)

using namespace std;
typedef long long ll;

int x[3];
void solve() {
	rep(i, 0, 3) cin >> x[i];
	if (x[0] <= x[2] && x[2] <= x[1]) {
		cout << "Yes" << endl;
	} else cout << "No" << endl;
}

int main() {
	solve();
	return 0;
}

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

using namespace std;
typedef long long ll;
const int maxN = 3 * 1e5 + 5;
int ans[maxN], tot;
ll N, A, B;
int main() {
	scanf("%lld%lld%lld", &N, &A, &B);
	if(A + B - 1 <= N && N <= A * B) {
		for(int i = N - A + 1; i <= N; ++i) ans[++tot] = i;
		N -= A;
		for(int i = B - 1; i >= 1; --i) {
			int t = min(N - i + 1, A);
			for(int j = N - t + 1; j <= N; ++j)
			ans[++tot] = j;
			N -= t;
		}
		for(int i = 1; i <= tot; ++i) printf("%d ", ans[i]);
	} else {
		printf("-1\n");
	}
}

Measured memory_bytes: 3328
#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 vvint = vector<vint>;
using vvvint = vector<vvint>;
using vdouble = vector<double>;
using vvdouble = vector<vdouble>;
using vvvdouble = vector<vvdouble>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using uint = unsigned int;
using ull = unsigned long long;

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;
constexpr int mod2 = 998244353;
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 bool chmin(T1 &a, T2 b) { return (a > b && (a = b, true)); }
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return (a < b && (a = b, true)); }
template<typename T>
bool isin(T y, T x, T h, T w) { return (0 <= y && 0 <= x && y < h && x < w); }
template<typename T>
bool isin1(T y, T x, T h, T w) { return (0 < y && 0 < x && y <= h && x <= w); }

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

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

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


void Main() {
	ll N; cin >> N;
	vll divisor1, divisor2;
	for (ll i = 1; i * i <= N-1; i++) {
		if ((N-1)%i == 0) {
			divisor1.push_back(i);
			if ((N-1)/i != i) divisor1.push_back((N-1)/i);
		}
	}

	for (ll i = 1; i * i <= N; i++) {
		if (N%i == 0) {
			divisor2.push_back(i);
			if (N/i != i) divisor2.push_back(N/i);
		}
	}

	int ans = divisor1.size();
	for (auto &k : divisor2) {
		if (k == 1) continue;
		ll n = N;
		while (n >= k && n % k == 0) {
			n /= k;
		}
		if (n % k == 1) ans++;
	}
	cout << ans-1 << endl;
}

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


Measured memory_bytes: 384
using System.Text;
using System;

public class Hello
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine().Trim());
        string[] line = Console.ReadLine().Trim().Split(' ');
        var a = Array.ConvertAll(line, int.Parse);
        var d = new int[100001];
        var asum = 0L;
        for (int i = 0; i < n; i++)
        {
            d[a[i]]++;
            asum += a[i];
        }
        getAns(d, asum);
    }
    static void getAns(int[] d, long asum)
    {
        var sb = new StringBuilder();
        var q = int.Parse(Console.ReadLine().Trim());
        for (int i = 0; i < q; i++)
        {
            string[] line = Console.ReadLine().Trim().Split(' ');
            var b = long.Parse(line[0]);
            var c = long.Parse(line[1]);
            asum += (c - b) * d[b];
            d[c] += d[b];
            d[b] = 0;
            sb.Append(asum.ToString() + "\n");
        }
        Console.Write(sb);
    }
}


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

using namespace std;

typedef long long ll;

const int lg = 21;

int n, q;
int d[100100];
int up[100100][22];
int col[100100];
ll cost[100100];
ll ans[100100];
int cnt[100100];
ll col_dist[100100];
vector<int> adj[100100];
vector<ll> weight[100100];
vector<int> color[100100];
vector<int> query[100100];

int lca(int u, int v) {
    if (d[u] > d[v]) swap(u, v);

    int delta = d[v] - d[u];
    for (int i = 0; i <= lg; i++) {
        if (delta & (1 << i)){
            v = up[v][i];
        }
    }

    if (u == v) return u;

    for (int i = lg; i >= 0; i--) {
        if (up[u][i] != up[v][i]) {
            u = up[u][i];
            v = up[v][i];
        }
    }

    return up[u][0];
}

void dfs(int v, int p, int depth) {
    d[v] = depth;
    up[v][0] = p;

    for (int i = 0; i < (int)adj[v].size(); i++) {
        if (adj[v][i] == p) continue;
        dfs(adj[v][i], v, depth + 1);
    }
}

void solve(int v, int p, ll dist) {
    for (int idx: query[v]) {
        ll mul = 1;
        if (idx < 0)  {
            mul = -2;
            idx = -idx;
        }
        ans[idx] += mul * (cnt[col[idx]] * cost[idx] - col_dist[col[idx]] + dist);
    }

    for (int i = 0; i < (int)adj[v].size(); i++) {
        if (adj[v][i] == p) continue;
        cnt[color[v][i]]++;
        col_dist[color[v][i]] += weight[v][i];
        solve(adj[v][i], v, dist + weight[v][i]);
        cnt[color[v][i]]--;
        col_dist[color[v][i]] -= weight[v][i];
    }
}



int main() {
    scanf("%d %d", &n, &q);

    for (int i = 0; i < n - 1; i++) {
        int u, v, c;
        ll w;
        scanf("%d %d %d %lld", &u, &v, &c, &w);
        adj[u].push_back(v);
        adj[v].push_back(u);
        color[u].push_back(c);
        color[v].push_back(c);
        weight[u].push_back(w);
        weight[v].push_back(w);
    }

    dfs(1, 0, 0);
    for (int j = 1; j <= lg; j++) {
        for (int i = 1; i <= n; i++) {
            up[i][j] = up[up[i][j - 1]][j - 1];
        }
    }

    for (int i = 1; i <= q; i++) {
        int u, v;
        scanf("%d %lld %d %d", &col[i], &cost[i], &u, &v);
        query[u].push_back(i);
        query[v].push_back(i);
        query[lca(u, v)].push_back(-i);
        // printf("LCA %d\n", lca(u, v));
    }

    solve(1, 0, 0);

    for (int i = 1; i <= q; i++) {
        printf("%lld\n", ans[i]);
    }
}

Measured memory_bytes: 40572
program abc133c

   implicit none

   integer(8) :: L, R, i, j , skip
   integer :: ans, calc_mod

   read(*,*) L, R

   ans = 2018
   R = min(R, L+673)

   do i = L, R-1
      do j =i+1, R

         calc_mod = mod(i*j,2019)
         if (ans > calc_mod ) then
            ans = calc_mod
            !if (ans == 0) goto 999  ! 0になったら打ち切る
         else
            cycle
         end if
      enddo
   enddo
999 continue

   print *, ans


end program abc133c


Measured memory_bytes: 256
using System;
using System.IO;
//因数分解は使わなくても解けます
//A^5-B^5=X
//X>0の時、A＞B
//AとBの差が大きい程、Xが大きくなるため、たくさんのA、Bの出すにはB=A-1とするとO(n^4)
class Program
{
    static void Main()
    {
        int x = int.Parse(Console.ReadLine());
        for(int a=1; a < 1000; a++)
        {
            long a5 = 1;
            for (int i = 0; i < 5; i++) a5 *= a;
            for(int b=-1000; b < 1000; b++)
            {
                long b5 = 1;
                for (int j = 0; j < 5; j++) b5 *= b;
                if (a5 - b5 == x)
                {
                    Console.Write(a + " "+b);
                    goto end;
                }
            }
        }
        end: Console.WriteLine();
    }
}


//original
//答えがマイナス含むとき解けない
//class Program
//{
//    static void Main()
//    {
//        int x = int.Parse(Console.ReadLine());
//        int target = 200 * (int)Math.Sqrt(5);
//        int[,] L = new int[5, target + 1];
//        for(int i = 0; i <= target; i++)
//        {
//            for(int j=0; j < 5; j++)
//            {
//                L[j, i] = (int)Math.Pow(i, j + 1);
//            }
//        }
//        for(int a = 0; a < target + 1; a++)
//        {
//            for(int b = 0; b < target + 1; b++)
//            {
//                if (a == b) continue;
//                int sum=0;
//                for (int k = 0; k < 5; k++)
//                {
//                    sum += L[k, a] * L[4 - k, b];
//                }
//                if (x == sum) 
//                {
//                    a++;b++;
//                    Console.Write(a + " " + b);
//                    goto end;
//                }
//                if (x > sum) break;
//            }
//        }
//        end: Console.WriteLine();
//    }
//}


Measured memory_bytes: 27504
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0;i<n;++i)
#define REP(i, k, n) for(int i=k; i<=n; ++i)
#define REPR(i, k, n) for(int i=k; i>=n; --i)
#define MAX 2001
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define r return
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int long long uill;
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	set<char> s1;
	vector<int> v;

	string s;
	cin >> s;
    int flag=5;
	char c = s[0];
	int size=s.size();
	for(int i =0; i<size; ++i){
		s1.insert(s[i]);
		
	}
    
    if(s1.size() == s.size()){
     cout << "yes" << "\n";
    }else{
    	cout << "no" << "\n";
    }
	



    return 0;


}

Measured memory_bytes: 256
#include <cstdio>

const int P=998244353;
inline int mul(const int &a,const int &b){return 1ll*a*b%P;}
inline int add(int a,const int &b){a+=b;return(a>=P)?a-P:a;}
inline int sub(int a,const int &b){a-=b;return (a<0)?a+P:a;}
int qsm(int a,int b){
	int ans=1;
	while(b){
		if(b&1)ans=mul(ans,a);
		a=mul(a,a);
		b>>=1;
	}
	return ans;
}
int n,a[1048576],lim,S;
void FWT(int *a){
	for(register int i=1;i<lim;i<<=1)
		for(register int j=0;j<lim;j+=(i<<1))
			for(register int k=0;k<i;++k){
				const int Ny=a[i+j+k];
				a[i+j+k]=sub(a[j+k],Ny);
				a[j+k]=add(a[j+k],Ny);
			}
}
int read(){
	int x=0;
	char ch=getchar();
	while(ch<'0'||ch>'9')ch=getchar();
	while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
	return x;
}
void write(int x){
	if(x>9)write(x/10);
	putchar((x%10)+'0');
}
int main(){
	scanf("%d",&n);
	lim=1<<n;
	for(register int i=0;i<lim;++i)S=add(S,a[i]=read()),a[i]=sub(0,a[i]);
	a[0]=add(a[0],S);
	FWT(a);
	for(register int i=1;i<lim;++i)a[i]=mul(qsm(a[i],P-2),S),a[0]=0;
	FWT(a);
	for(register int i=0;i<lim;++i)write(sub(a[0],a[i])),putchar('\n');
}

Measured memory_bytes: 3712
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
#include <map>
#include <unordered_map>
#include <chrono>
#include <numeric>
using namespace std;
using ll = long long;
const ll INF = (ll)1e18+1;
const ll DIV = 1000000007;
//#define TEST
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
#ifdef TEST
    chrono::system_clock::time_point start, end;
    start = chrono::system_clock::now();
#endif
    long X,Y;
    cin >> X >> Y;
    ll turtle = 4, crane = 2;
    if(Y > turtle * X || Y < crane * X)
    {
        cout << "No" << endl;
        return 0;
    }
    ll max_leg = turtle * X;
    bool ok = false;
    for(size_t i=0;i<=X; i++)
    {
        if(max_leg - i * 2 == Y) ok=true;
    }
    if(ok) cout << "Yes" << endl;
    else cout << "No" << endl;
#ifdef TEST
    end = chrono::system_clock::now();
    cerr << static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count() / 1000.0) << "[ms]" << endl;
#endif
    return 0;
}

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

int main() {
    double w, h, x, y;
    cin >> w >> h >> x >> y;
    if (x == w/2 && y == h/2) {
        double ans = w*h/2.0;
        cout << ans << endl;
        cout << 1 << endl;
    }
    else {
        double ans = w*h/2.0;
        cout << ans << endl;
        cout << 0 << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define Fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define MOD 1000000007
 
ll n,k,i,a[200005],ff,ann;

int main()
{
    
    Fast;
    cin>>k>>n;
    for(i=0;i<n;i++)
    {
        cin>>a[i];
    }
    ff=0;
    ann=0;
    for(i=1;i<n;i++)
    {
        ff+=(a[i]-a[i-1]);
    }
    ann=ff;
    for(i=2;i<=n;i++)
    {
        ff=(a[i-2]);
        ff+=(k-a[i-1]);
        ann=min(ann,ff);
    }
    cout<<ann;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

int main() {
    int n, m;
    cin >> n >> m;
	rep(i, m/2){
		cout << i+1 << " " << m-i << endl;
	}
	rep(i, (m+1)/2){
		cout << i+1+m << " " << 2*m+1-i << endl;
	}
}


Measured memory_bytes: 3636
N, M, C = map(int, input().split())
B = list(map(int, input().split()))
A = [list(map(int, input().split())) for i in range(N)]

res = 0

for i in range(N):
    target_num = sum([a*b for a, b in zip(A[i], B)]) + C
    if target_num > 0:
        res += 1

print(res)


Measured memory_bytes: 3060