akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

  public static void main(String[] args) throws IOException {
    BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    String[] listStr = reader.readLine().split(" ");
    int[] list = new int[listStr.length];
    int[] copyList = new int[listStr.length];
    boolean flag = true;

    for (int i = 0; i < listStr.length; i++) {
      list[i] = Integer.parseInt(listStr[i]);
    }
    System.arraycopy(list, 0, copyList, 0, list.length);

    ascendingSort(list);

    for (int i = 0; i < list.length; i++) {
      if (i < list.length - 2 && list[i] == copyList[i + 1]) {
        flag = false;
        break;
      }
      if (list[i] != copyList[i]) {
        flag = false;
        break;
      }
    }

    System.out.println(flag ? "Yes" : "No");

  }

  public static void ascendingSort(int[] array) {
    for (int i = 0; i < array.length; i++) {
      for (int j = 0; j < array.length - 1 - i; j++) {
        if (array[j] > array[j + 1]) {
          int tmp = array[j];
          array[j] = array[j + 1];
          array[j + 1] = tmp;
        }
      }
    }
  }

  public static void descendingSort(int[] array) {
    for (int i = array.length - 1; i >= 0; i--) {
      for (int j = array.length - 1; j > array.length - 1 - i; j--) {
        if (array[j] > array[j - 1]) {
          int tmp = array[j];
          array[j] = array[j - 1];
          array[j - 1] = tmp;
        }
      }
    }
  }

}

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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
	ll a, b, n;
	cin >> a >> b >> n;
	ll x = n / b * b - 1;
	ll ans = max(a * x / b - a * (x / b), a * n / b - a * (n / b));
	cout << ans << "\n";
	return 0;
}


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

int main() {
  long N, n;
  long nu, nl;
  cin >> N;
  for (int h=1;h<=3500;h++) {
    for (int w=1;w<=3500;w++) {
      nu = N * h * w;
      nl = 4*h*w - N*(h+w);
      if (nl > 0 and nu % nl == 0) {
        n = nu / nl;
        if (n <= 3500) {
          cout << n << " " << h << " " << w;
          return 0;
        }
      }
    }
  }
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<climits>
#include<iostream>
#include<sstream>
#include<utility>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
#include<stack>
#include <functional>

using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const int INF=100000;
ll MP=1000000;
vector<P>A;
vector<ll>DP(MP+1,100000);
int main()
{
	ll D,G;
	cin>>D>>G;
	G/=100;
	for(int i=0;i<D;i++)
	{
		int p,c;
		cin>>p>>c;
		A.push_back(make_pair(p,c/100));
	}
	DP[0]=0;
	for(ll i=0;i<D;i++)
	{
		for(ll g=MP;g>=0;g--)
		{
			if(DP[g]!=INF)
			{
				for(ll j=0;j<A[i].first;j++)
				{
					ll np=g+((j+1)*(i+1))+(j==A[i].first-1?A[i].second:0);
					DP[np]=min(DP[np],DP[g]+(j+1));
				}
			}
		}
	}
	ll r=INF;
	for(ll i=G;i<MP;i++)
	{
		r=min(DP[i],r);
	}
	cout<<r<<endl;
}

Measured memory_bytes: 8064
function Main(input){
  Red = 0;
  Blue = 0;
  input_line = input.split('\n');
  inputS = input_line[1].trim().split('');
  inputS.forEach((s) => {
    if (s === 'R') {
      Red++;
    }
    if (s === 'B') {
      Blue++;
    }
  });
  console.log(Red > Blue ? "Yes" : "No");
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;

struct edge{
	ll to, cost;
	edge(ll a, ll b){to = a, cost = b;}
};

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

	ll N, M, X; cin >> N >> M >> X;
	ll H[100005];
	vector<edge>  G[100005];
	ll d[100005];

	for (int i = 1;i <= N;i++){
		cin >> H[i];
		d[i] = LLONG_MAX;
	}

	for (int i = 0;i < M;i++){
		ll A,B,T; cin >> A >> B >> T;
		G[A].push_back(edge(B,T));
		G[B].push_back(edge(A,T));
	}

	priority_queue<P, vector<P>, greater<P> > que;
	que.push(P(0,1));
	d[1] = 0;

	while(que.size()){
		P p = que.top(); que.pop();
		ll now = p.second;
		ll height = (X-d[now] >  0 ? X-d[now] : 0);
		if(p.first > d[now]) continue;
		for (int i = 0;i < G[now].size(); i++){
			ll to = G[now][i].to;
			ll cost = G[now][i].cost;
			ll neh = height - cost;
			if(neh < 0){
				if(height-neh > H[now]) continue;
				cost += -neh;
			}else if(neh > H[to]){
				if(height-neh < 0) continue;
				cost += neh - H[to];
			}

			if(d[to] > d[now]+cost){
				d[to] = d[now]+cost;
				que.push(P(d[to], to));
			}
			
		}
	}
	
	if(d[N] == LLONG_MAX) cout << -1 << endl;
	else{
		ll ans;
		ll height = (X-d[N] >  0 ? X-d[N] : 0);
		ans = d[N] + (H[N]-height);
		cout << ans << endl;
	}

	return 0;

}



Measured memory_bytes: 23000
h, w = map(int, input().split())
sL = [input() for _ in range(h)]
L = [[0 for _ in range(w)] for _ in range(h)]
R = [[0 for _ in range(w)] for _ in range(h)]
U = [[0 for _ in range(w)] for _ in range(h)]
D = [[0 for _ in range(w)] for _ in range(h)]
for i in range(h):  # 行
    for j in range(w):  # 列
        if sL[i][j] != "#":
            if j == 0:
                L[i][j] = 1
            else:
                L[i][j] = L[i][j-1] + 1
        else:
            L[i][j] = 0
for i in range(h):  # 行
    for j in range(w-1, -1, -1):  # 列
        if sL[i][j] != "#":
            if j == w-1:
                R[i][j] = 1
            else:
                R[i][j] = R[i][j+1] + 1
        else:
            R[i][j] = 0
for j in range(w):  # 列
    for i in range(h):  # 行
        if sL[i][j] != "#":
            if i == 0:
                U[i][j] = 1
            else:
                U[i][j] = U[i-1][j] + 1
        else:
            U[i][j] = 0
for j in range(w):  # 列
    for i in range(h-1, -1, -1):  # 行
        if sL[i][j] != "#":
            if i == h-1:
                D[i][j] = 1
            else:
                D[i][j] = D[i+1][j] + 1
        else:
            D[i][j] = 0
max_ = 0
sum_ = 0
for i in range(h):
    for j in range(w):
        sum_ = L[i][j] + R[i][j] + U[i][j] + D[i][j] - 3
        if sum_ > max_:
            max_ = sum_
print(max_)

Measured memory_bytes: 184452
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>
#include <iomanip>

using namespace std;

#define FAST       			ios_base :: sync_with_stdio(false); cin.tie(NULL); 
#define endl "\n"

typedef long long int  ll;
typedef unsigned long long int ull;


int main()
{
	FAST;
	int n;
	int arr[10];
	cin >> n;

	for(int i=0; i<n ; i++)	cin >> arr[i];
	sort(arr , arr+n);

	if(accumulate(arr , arr+n-1 , 0) > arr[n-1])
		cout << "Yes";
	else
		cout << "No";


	return 0;
}

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

using namespace std;

#define int long long

signed main(){
	int L,R; cin>>L>>R;
	if(R-L >= 2019){
		cout<<"0\n";
	}
	else{
		int res = 1LL << 63LL - 1LL;
		for(int i=L;i<R;i++)
			for(int j = i+1; j<=R; j++)
			    res = min(res, (i*j)%2019);
		
		cout<<res<<"\n";
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(void)

{
    string s;
    int counter = 0, i, a;
    cin>>a>>s;
    a = s.size();
    for(i = 0; i < a; i++){
        if((s[i] == 'A' && s[i+1] == 'B') && (s[i+2] == 'C')){
            counter++;
        }
    }
    cout<<counter<<"\n";
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int n,v[20],c[20],x=0,y=0,i;

	scanf("%d",&n);
	for(i=0;i<n;i++)
		scanf("%d",&v[i]);
	for(i=0;i<n;i++)
		scanf("%d",&c[i]);

	for(i=0;i<n;i++)
		if(v[i]>c[i]){
			x+=v[i];
			y+=c[i];
		}
	if(x==0){
		printf("0\n");
		return 0;
	}
	printf("%d\n",x-y);
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <iostream>
#include <cmath>
#include <algorithm>

using namespace std;

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

    if(1 <= N && N <= 9)
    {
        cout << N << endl;
    }
    else if(10 <= N && N <= 99)
    {
        cout << 9 << endl;
    }
    else if(100 <= N && N <= 999)
    {
        cout << ( 9 + (N - 99)) << endl;
    }
    else if(1000 <= N && N <= 9999 )
    {
        cout << (909) << endl;
    }
    else if(10000 <= N && N <= 99999)
    {
        cout << (909 + (N - 9999)) << endl;
    }
    else if(100000 == N)
    {
        cout << 90909 << endl;
    }
    return 0;
}

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

using namespace std;

typedef long long int ll;

const int N = 1e5 + 5;

vector < int > same(N, 0);

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

  int n, m;
  cin >> n >> m;
  vector < int > x(n), cnt(m, 0);
  for (int i = 0; i < n; i++) {
    cin >> x[i];
    cnt[x[i] % m]++;
    same[x[i]]++;
  }

  if (m == 1) {
    cout << n / 2 << endl;
    return 0;
  }

  ll ans = 0;
  for (int i = 1; i < m; i++) {
    if (i == m / 2) continue;
    int tmp = min(cnt[i], cnt[m - i]);
    cnt[i] -= tmp;
    cnt[m - i] -= tmp;
    ans += tmp;
  }
  ans += cnt[0] / 2;
  ans += cnt[m / 2] / 2;
  cnt[0] = cnt[m / 2] = 0;
  for (int i = 0; i < N; i++) {
    int r = i % m;
    int tmp = min(cnt[r] / 2, same[i] / 2);
    cnt[r] -= 2 * tmp;
    ans += tmp;
  }

  cout << ans << '\n';
}


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

using namespace std;
const int N = 2e5+100;
struct node{
    long long a,b;
}s[N];
bool cmp(node a,node b){
    return a.a>b.a;
}
long long L[N],R[N];
long long minnore[N];//后缀最小的B
int main(){
    int n;
    cin>>n;
    for(int i=1;i<=n;i++) cin>>L[i]>>R[i];
    long long maxx=0;long long minn=1e18;
    int p,q;
    long long maxxlength=0;
    for(int i=1;i<=n;i++){
        if(L[i]>maxx){
            maxx=L[i];
            p=i;
        }
        if(R[i]<minn){
            q=i;
            minn=R[i];
        }
        maxxlength=max(maxxlength,R[i]-L[i]+1);
    }
    long long ans1=maxxlength+(minn>=maxx?minn-maxx+1:0);
    for(int i=1;i<=n;i++){
        s[i].a=max(R[i]-maxx+1,0LL);
        s[i].b=max(minn-L[i]+1,0LL);
    }
  //  for(int i=1;i<=n;i++) cout<<i<<' '<<s[i].a<<' '<<s[i].b<<endl;
    sort(s+1,s+n+1,cmp);
    minnore[n+1]=(1e18);
    for(int i=n;i>=1;i--) minnore[i]=min(minnore[i+1],s[i].b);
    long long ans2=0;
    for(int i=1;i<=n-1;i++){
        ans2=max(ans2,s[i].a+minnore[i+1]);
    }
    cout<<max(ans1,ans2)<<endl;
    return 0;
}

Measured memory_bytes: 5760
#include <iostream>
#include <algorithm>
#include <cstdint>

int const MAXN = 50;
uint64_t const MOD = 1000000007;
uint64_t a[MAXN][MAXN];
int N;
uint64_t K;

void copy_mat(uint64_t s[MAXN][MAXN], uint64_t d[MAXN][MAXN]) {
  for(int i = 0; i < N; ++i) for(int j = 0; j < N; ++j) d[i][j] = s[i][j];
}


void mod_mul(uint64_t s[MAXN][MAXN], uint64_t d[MAXN][MAXN]) {
  uint64_t t[MAXN][MAXN];
  for(int i = 0; i < N; ++i) for(int j = 0; j < N; ++j) {
    uint64_t x = 0;
    for(int k = 0; k < N; ++k) x = (x + s[i][k]*d[k][j])%MOD;
    t[i][j] = x;
  }
  copy_mat(t, d);
}

void mod_pow(uint64_t a[MAXN][MAXN], uint64_t k) {
  uint64_t tmp[MAXN][MAXN];
  bool first = true;

  while(k>0) {
    if(k&1) {
      if(first) copy_mat(a, tmp);
      else mod_mul(a, tmp);
      first = false;
    }
    k >>= 1;
    mod_mul(a, a);
  }
  copy_mat(tmp, a);
}

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

  mod_pow(a, K);
  uint64_t sum = 0;
  for(int i = 0; i < N; ++i) {
    for(int j = 0; j < N; ++j) sum += a[i][j];
  }
  sum %= MOD;
  std::cout << sum << std::endl;
  return 0;
}


Measured memory_bytes: 256
n,t = map(int,input().split())
l = list(map(int,input().split()))

mx = 0
mn = l[0]
r = []
for i in range(1,len(l)):
    if mx <= l[i]-mn:
        mx = l[i]-mn
        r.append(mx)
    mn = min(mn,l[i])

e = sorted(r)[len(r)-1]
print(r.count(e))

Measured memory_bytes: 14252
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int n = s.length();
        int a = 0;
        int b = 0;
        for (int i=0;i<n;i++){
            if (s.charAt(i)=='0')a++;
            else b++;
        }
        System.out.println(n-Math.abs(a-b));
    }
}


Measured memory_bytes: 39344
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll INF = ll(1e18)+5;
ll N,K;
vector<ll> a;


ll dfs(int t,vector<bool>& use){
    if(t==N){
        ll temp = 0;
        ll num = 0;
        ll last = 0;
        for(int i=0;i<N;i++){
            if(use[i]){
                num++;
                temp += max(0ll,last+1-a[i]);
                last = max(last+1,a[i]);
            }
            last = max(last,a[i]);
        }
        if(num>=K){
            return temp;
        }
        return INF;
    }
    ll retVal = INF;
    retVal = min(retVal,dfs(t+1,use));
    use[t] = true;
    retVal = min(retVal,dfs(t+1,use));
    use[t] = false;
    return retVal;
}


int main() {
    cin >> N >>K;
    a.resize(N);
    for(int i=0;i<N;i++){
        cin >> a[i];
    }
    vector<bool> use(N,false);
    cout << dfs(0,use) << endl;
    return 0;
}

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

int main(){
    ll l, r;    cin >> l >> r;
    ll ans=1e+15;
    int rj = r/2019, lj = l/2019;

    if(lj==rj)
        for(ll i=l; i<=r-1; i++){
            for(ll j=i+1; j<=r; j++){
                ans = min(ans, i*j%2019);
            }
        }
    else ans = 0;
    cout << ans << endl;

}

Measured memory_bytes: 256
#include<vector>
#include<map>
#include<algorithm>
#include<set>
#include<iostream>
#include<string>
#include<set>
#include<queue>
#include<random>
 
using namespace std;
 
#pragma GCC optimize("Ofast")
#pragma GCC optimize("fast-math")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")
 
#define pb push_back
#define ld long double
#define ll long long
#define mp make_pair
 
int32_t main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
    int n;
    cin >> n;
    if (n / 100 == 7 || n / 10 % 10 == 7 || n % 10 == 7){
        cout << "Yes\n";
    }
    else{
        cout << "No\n";
    }
	return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
#define int long long
#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 FOR(i,s,n) for(int i = s;i < (int)n;i++)
#define RFOR(i,s,n) for(int i = (int)n-1;i >= s;i--)
#define ALL(a) a.begin(),a.end()
template<class T>inline bool CHMAX(T&a,T b){if(a<b){a = b;return true;}return false;}
template<class T>inline bool CHMIN(T&a,T b){if(a>b){a = b;return true;}return false;}
constexpr long long INF = 1e18;



signed main(){
	int A,B;
	cin>>A>>B;
	cout<<max(0ll,A-B*2)<<endl;
}

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

#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef complex<double> point;
#define xx real()
#define yy imag()

#define REP(i, a, b) for(int i = (a); i < (int)(b); i++)
#define REPN(i, a, b) for(int i = (a); i <= (int)(b); i++)
#define FA(it, x) for(__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define SZ(x) (int)(x).size()
#define BE(x) (x).begin(), (x).end()
#define SORT(x) sort(BE(x))
#define _1 first
#define _2 second

#define x1 gray_cat_x1
#define y1 gray_cat_y1

template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

#define file "I1"

const double EPS = 1e-9;
const double PI = acos(-1.);
const int INF = 1e9;
const ll MOD = 1e9 + 7;

const int MAXN = 2e5 + 5;

vi v1, v2;



void solve(){
	int n, m, a, b;
	scanf("%d%d", &n, &m);
	REP(i, 0, m){
		scanf("%d%d", &a, &b);
		if (a > b){
			swap(a, b);
		}
		if (a == 1){
			v1.pb(b);
		}
		if (b == n){
			v2.pb(a);
		}
	}
	SORT(v1);
	SORT(v2);
	for(int i = 0, j = 0; i < SZ(v1) && j < SZ(v2); ){
		if (v1[i] == v2[j]){
			printf("POSSIBLE\n");
			return;
		}
		if (v1[i] < v2[j]){
			i++;
		} else {
			j++;
		}
	}
	printf("IMPOSSIBLE\n");
}   

int main(){

    //freopen(file".in", "r", stdin); freopen(file".out", "w", stdout);
    int t = 1;
    //cin >> t;
    while(t--){
        solve();    
    }
}


Measured memory_bytes: 1276
a = list(input())
b = list(input())
c = list(input())
p = a.pop(0)
while True:
    if p=='a':
        if len(a)!=0: p = a.pop(0)
        else: 
            print("A")
            break
    if p=='b':
        if len(b)!=0: p = b.pop(0)
        else:
            print("B")
            break
    if p=='c':
        if len(c)!=0: p = c.pop(0)
        else:
            print("C")
            break

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;
int n;
class Team{
public:
  int p,n,rank;
  Team(int _p,int _n,int _rank):p(_p),n(_n),rank(_rank){
  }
  bool operator < (const Team &o)const{
    return p > o.p;
  }
};
vector<Team> v;
void solve(){

  
}
void show(){
  for(vector<Team>::iterator it=v.begin();it!=v.end();it++){
    cout<<(*it).n<<","<<(*it).p<<endl;
  }
}
int main(){
  cin>>n;
  for(int i=0;i<n;i++){
    v.push_back(Team(0,i,0));
  }
  for(int i=0;i<(n*(n-1))/2;i++){
    int a,b,ap,bp;
    cin>>a>>b>>ap>>bp;
    int aw=0;
    int bw=0;
    if(ap>bp) aw=3;
    
    else if(ap<bp) bw=3;
    else {
      aw=bw=1;
    }
    v[a-1].p+=aw;
    v[b-1].p+=bw;
  }
  sort(v.begin(),v.end());
  //  show();
  int i=0;
  int r[101];
  int point=-1;
  int tmp=0;
  for(vector<Team>::iterator it=v.begin();it!=v.end();it++){
    if(point!=(*it).p){i+=tmp+1;tmp=0;}
    else tmp++;
    point=(*it).p;
    r[(*it).n]=i;
  }
  for(int i=0;i<n;i++){
    cout<<r[i]<<endl;
  }
 
  return 0;
}

Measured memory_bytes: 0
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def main():
    S = input()
    K = int(input())
    if K == 1:
        print(S[0])
        return
    else:
        for i in range(min(len(S), K)):
            if S[i] != "1":
                print(S[i])
                return
    print(1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3948
#include "bits/stdc++.h"
#define rep(i,n) for(int i=0;i<n;i++)
#define ALL(v) (v).begin(),(v).end()
typedef long long LL;
const int INF = 1 << 25;
const LL MOD = 1000000007LL;
using namespace std;
typedef pair<int, int> P;
vector<int> pos[26];
int main() {
	string s;
	cin >> s;
	rep(i, s.size()) {
		pos[s[i] - 'a'].push_back(i);
	}
	rep(i, 26) {
		for (int j = 0; j < pos[i].size(); j++) {
			for (int k = j+1; k < pos[i].size(); k++) {
				if (2 * (k - j + 1) > (pos[i][k] - pos[i][j] + 1)) {
					cout << (pos[i][j] + 1) << " " << (pos[i][k] + 1) << endl;
					return 0;
				}
			}
		}
	}
	cout << "-1 -1" << endl;
}

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

int main(){
        int n,cp;
        cin >> n; cp=n;
        int sum=0;
        while(cp>0){
                sum+=cp%10;
                cp/=10;
        }
        if(n%sum==0) cout << "Yes" << endl;
        else cout << "No" << endl;
        return 0;
}


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

#define DUMP(x) cerr << #x << "=" << x << endl
#define DUMP2(x, y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<")"<< endl
#define BINARY(x) static_cast<bitset<16> >(x)

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

#define in_range(x, y, w, h) (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()

typedef long long ll;
const int INF   = 1e9;
const ll  INFLL = 1e18;
typedef pair<int, int> PII;
int dx[4]={0, -1, 1, 0}, dy[4]={-1, 0, 0, 1};

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

    ll K;
    cin >> K;

    if (K < 100) {
    // if (false) {
        cout << "2" << endl;
        if (K == 0) {
            cout << "1 1" << endl;
        } else if (K % 2 == 1) {
            cout << K/2 << " " << K/2+2 << endl;
        } else {
            cout << K/2+1 << " " << K/2 << endl;
        }
    } else {
        int N = 50;
        cout << N << endl;

        ll base = K / N + (N-1);
        ll m = K % N;

        rep(i, m) {
            cout << base + (N - (m - 1)) << " ";
        }
        rep(i, N-m) cout << base - m << " ";
        cout << endl;
    }
}

Measured memory_bytes: 256
use std::cmp::min;
use std::io::*;
use std::str::FromStr;

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

fn main() {
    let n:u32 = read();
    let m:u32 = read();
    let x:u32 = read();
    let mut c:usize = 0;
    let mut l:Vec<u32> = (0..m).map(|_| read()).collect();
    l.sort();
    for i in &l {
        if i > &x {
            break
        }
        c += 1;
    }
    println!("{}", min(c, l[c..].len()));
}


Measured memory_bytes: 4352
import java.io.*;
import java.util.*;
public class Main
{
  public static void main(String args[])throws IOException
  {
    InputStreamReader read = new InputStreamReader(System.in);
    BufferedReader in = new BufferedReader(read);
    String line[]=in.readLine().trim().split(" ");
    int n=Integer.parseInt(line[0]);
    int m=Integer.parseInt(line[1]);
    String arr[]=in.readLine().trim().split(" ");
    int i;
    int a[]=new int[m];
    int sum[]=new int[m];
    for(i=0;i<m;i++)
    {
        a[i]=Integer.parseInt(arr[i]);
    }
    sum[0]=a[0];
    for(i=1;i<m;i++)
    {
        sum[i]=sum[i-1]+a[i];
    }
    int ans=n-sum[m-1];
    if(ans>=0)
    System.out.println(ans);
    else
    System.out.println("-1");
  }
}

Measured memory_bytes: 34624
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

void calc(int k, string s) {
    bool[string] d;
    for (int i = 1; i <= k; i++) { // 長さ i の部分文字列を求める
        for (int j = 0; j < s.length; j++) { // s[j] からの部分文字列
            if (j + i > s.length) break;

            string t = s[j..j+i];
            d[t] = true;
        }
    }

    writeln(d.keys.sort().take(k)[$-1]);
}

void main() {
    string s = readln.chomp;
    int k = readint;

    calc(k, s);
}


Measured memory_bytes: 3068
def resolve():
    n = int(input())
    h = list(map(int,input().split()))
    ans = 'Yes'
    for i in range(0,n-1):
        if h[n-i-1] >= h[n-i-2]:
            continue
        elif h[n-i-1]-h[n-i-2]==-1:
            h[n-i-2] -= 1
        else:
            ans = 'No'
    print(ans)
resolve()

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

using namespace std;
using llong = long long;
using ldbl = long double;
using P = pair<llong, llong>;

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

const llong inf = llong(1e18)+7;
const llong mod = 1e9+7;

int main(){
	int N, x;
	cin >> N >> x;

	if(x == 1 || x == 2*N-1)
		cout << "No" << endl;
	else{
		cout << "Yes" << endl;
		set<int> s;
		for(int i = 1; i <= 2*N-1; i++)
			s.insert(i);

		deque<int> ans;
		ans.insert(ans.begin(),x);
		ans.insert(ans.begin(),x-1);
		ans.insert(ans.end(),x+1);
		s.erase(x);
		s.erase(x-1);
		s.erase(x+1);
		for(int i = 0; s.size(); i++){
			if(i&1)
				ans.insert(ans.end(), *s.begin());
			else
				ans.insert(ans.begin(), *s.begin());
			s.erase(s.begin());
		}

		for(auto x : ans)
			cout << x << endl;
	}


	return 0;
}

Measured memory_bytes: 10880
sample = input()
sample_list = sample.split(" ")
count = 0
flag = 0
i = 0
j = 1
for i in range(len(sample_list)):
  for j in range(i):
    if sample_list[i] == sample_list[j]:
      flag = 1
  if flag == 0:
    count += 1
  flag = 0
print(count)


Measured memory_bytes: 9044
function Main(input) {
  input = input.replace(/\n/g, ' ');
  input = input.split(" ");
  var A = input[0];
  const isUpperCase = c => {
    return /^[A-Z]+$/g.test(c)
  }
  if(isUpperCase(A)){
    console.log("A");
  }else{
    console.log("a");
  }
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 29680
# import bisect
# import copy
# import fractions
# import math
# import numpy as np
# from collections import Counter, deque
# from itertools import accumulate,permutations, combinations,combinations_with_replacement,product

def resolve():
    S=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
    K=int(input())
    print(S[K-1])

resolve()

Measured memory_bytes: 38384
#include <iostream>
#include<algorithm>
#include<sstream>
#include<cmath>
#include<vector>
#include<iomanip>
#include<map>
#include<set>
#include<queue>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i = 0; i < n;i++)
int main(void) {
	int n, y,h;cin >> n;set<int> s;
	rep(i, n) {
		cin >> y;h = s.size();
		s.insert(y);
		if (s.size() == h) {
			s.erase(y);
		}
	}
	cout << s.size() << endl;
}

Measured memory_bytes: 4864
n=int(input())
a=list(map(int,input().split()))
odd=0;even=0
for i in range(n):
    if a[i]%2==1:
        odd+=1
    else:
        even+=1
#print(odd,even)
if odd%2==0:
    print('YES')
else:
    print('NO')


Measured memory_bytes: 14108
s = input()

for bit in range(1 << 3):
    ans = int(s[0])
    f = s[0]

    for i in range(3):
        if bit & (1 << i):
            ans += int(s[i + 1])
            f += '+'
        else:
            ans -= int(s[i + 1])
            f += '-'
        f += s[i + 1]

    if ans == 7:
        print(f + '=7')
        break

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

namespace AtCoder
{
    class Program
    {
        private const int MODULO = 1000000007;
        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }

        static long Gcd(long a, long b)
        {
            return (a < b) ? Gcd(b, a)
                 : (b > 0) ? Gcd(b, a % b)
                           : a;
        }
        static long Gcd(IEnumerable<long> values)
        {
            return values.Aggregate(Gcd);
        }
        static long Lcm(long a, long b)
        {
            return a / Gcd(a, b) * b;
        }
        static long Lcm(IEnumerable<long> values)
        {
            return values.Aggregate(Lcm);
        }
        static void Main(string[] args)
        {
            int N = ReadInt();
            var T = new long[N];
            for (int i = 0; i < N; ++i) { T[i] = ReadLong(); }
            Console.WriteLine(Lcm(T));
        }
    }
}


Measured memory_bytes: 13268
// {{{
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
// }}}

using namespace std;

using ll [[maybe_unused]] = long long;
using ull [[maybe_unused]] = unsigned long long;
using ld [[maybe_unused]] = long double;

[[maybe_unused]] static constexpr int mod = (int)1e9 + 7;
[[maybe_unused]] static constexpr int inf = 100100100;
[[maybe_unused]] static constexpr ll linf = 1e18;
[[maybe_unused]] static constexpr double eps = 1e-9;
[[maybe_unused]] static constexpr double pi = 3.14159265359;

#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rrep(i, a, b) for (ll i = a; i < b; ++i)
#define rrrep(i, a, b) for (ll i = a; i >= b; --i)
#define all(obj) begin(obj), end(obj)
#define rall(obj) rbegin(obj), rend(obj)
#define pb push_back
#define fst first
#define snd second


int main() {
    // cin.tie(0);
    // ios_base::sync_with_stdio(false);
    ll N5 = 5000000000000;
    string S;
    cin >> S;
    ll K;
    cin >> K;

    K %= mod;
    for (char c : S) {
        if (c == '1') {
            K -= 1;
            K %= mod;
            if (K <= 0) {
                cout << c << endl;
                break;
            }
        } else {
            K -= N5 % mod;
            K %= mod;
            if (K <= 0) {
                cout << c << endl;
                break;
            }
        }
    }
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#define SF scanf
#define PF printf
#define MAXN 510
#define MAXM 10000
using namespace std;
typedef long long ll;
int n,cnt;
ll primes[MAXM];
ll a[MAXN][MAXN];
bool isprime[MAXM+10];
void prepare(){
	for(int i=2;i<=MAXM;i++){
		if(isprime[i]==0)
			primes[++cnt]=i;	
		for(int j=1;i*primes[j]<=MAXM;j++){
			isprime[i*primes[j]]=1;
			if(i%primes[j]==0)
				break;	
		}
	}
}
ll gcd(ll x,ll y){
	if(y==0)
		return x;
	return gcd(y,x%y);	
}
ll lcm(ll x,ll y){
	if(x==0)
		return y;
	if(y==0)
		return x;
	ll g=gcd(x,y);
	return x/g*y;
}
int main(){
	prepare();
	SF("%d",&n);
	int now=1;
	if(n==2){
		PF("4 7\n23 10\n");
		return 0;	
	}
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			if(i%2==j%2){
				int nowx=(i+j)/2;
				int nowy=(i-j+n)/2+n+1;
				a[i][j]=primes[nowx]*primes[nowy];
			}
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			if(i%2!=j%2){
				a[i][j]=lcm(lcm(a[i-1][j],a[i][j-1]),lcm(a[i+1][j],a[i][j+1]))+1ll;	
			}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++)
			PF("%lld ",a[i][j]);
		PF("\n");
	}
}

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

#define ll long long
#define mx 100005
int ar[mx];
char ch[mx];
int n,m;
void solve()
{
   int a,b,c;
   cin>>a>>b>>c;
   swap(a,b);
   swap(a,c);
   cout<<a<<" "<<b<<" "<<c<<endl;
}
int main()
{
    int t=1;
    while(t--)solve();
    return 0;
}


Measured memory_bytes: 256
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {

  static int mod = 1000000007;
  static int[] matchNum = {2, 5, 5, 4, 5, 6, 3, 7, 6};

  public static void main(String[] args) throws FileNotFoundException {

//    Scanner cin = new Scanner(new FileReader("input.txt"));
    Scanner cin = new Scanner(System.in);

    int a = cin.nextInt();
    int b = cin.nextInt();
    int q = cin.nextInt();

    long[] shrine = new long[a + 2];
    long[] temple = new long[b + 2];
    long[] query = new long[q];
    shrine[0] =  -(long)Math.pow(10,12);
    shrine[a + 1] = (long)Math.pow(10,12);
    temple[0] = -(long)Math.pow(10,12);
    temple[b + 1] = (long)Math.pow(10,12);
    for (int i = 1; i < a + 1; i++) {
      shrine[i] = cin.nextLong();
    }
    for (int i = 1; i < b + 1; i++) {
      temple[i] = cin.nextLong();
    }
    for (int i = 0; i < q; i++) {
      query[i] = cin.nextLong();
    }

    for (int i = 0; i < q; i++) {
      long pos = query[i];
//      long lShrine = 0, rShrine = 0, lTemple = 0, rTemple = 0;
      int indexS = 0;
      int indexT = 0;

      int bb=0,ee=b+1;
      while(ee-bb>1){
        int mid = (bb+ee)/2;
        if(temple[mid]<pos){
          bb = mid;
        } else {
          ee = mid;
        }
      }
      indexT = bb;

      bb=0;
      ee=a+1;
      while(ee-bb>1){
        int mid = (bb+ee)/2;
        if(shrine[mid]<pos){
          bb = mid;
        } else {
          ee = mid;
        }
      }
      indexS = bb;
//      System.out.println("pos shrine "+indexS+" pos temple " + indexT);
      long res = Long.MAX_VALUE;

      for (int j = 0; j < 2; j++) {

        for (int k = 0;k<2;k++) {
          long dis1 = Math.abs(pos - shrine[indexS+j]) + Math.abs(shrine[indexS+j] - temple[indexT+k]);
          long dis2 = Math.abs(pos - temple[indexT+k]) + Math.abs(shrine[indexS+j] - temple[indexT+k]);
          res = Math.min(res, Math.min(dis1, dis2));
        }

      }
      System.out.println(res);

    }

  }


}


Measured memory_bytes: 110540
#line 1 "test/aoj/GRL_5_C.test.cpp"
#define PROBLEM "http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_5_C"

#line 1 "test/aoj/../../graph/template.cpp"
#include <vector>

template< typename T >
struct Edge {
  int from, to;
  T cost;
  Edge() {}
  Edge(int f, int t) : from(f), to(t), cost(1) {}
  Edge(int f, int t, T c) : from(f), to(t), cost(c) {}
  friend bool operator < (const Edge& lhs, const Edge& rhs) { return lhs.cost < rhs.cost; };
  friend bool operator > (const Edge& lhs, const Edge& rhs) { return rhs < lhs; };
  friend bool operator <= (const Edge& lhs, const Edge& rhs) { return !(lhs > rhs); };
  friend bool operator >= (const Edge& lhs, const Edge& rhs) { return !(lhs < rhs); };
};

template< typename T >
using Edges = std::vector< Edge< T > >;
template< typename T >
using Graph = std::vector< Edges< T > >;
#line 2 "test/aoj/../../graph/lca.cpp"

#include <cassert>
#include <cmath>
#include <vector>

using namespace std;

template< typename T >
struct LCA {
  using graph = Graph<T>;
  int root;
  // n : 頂点数
  const int n;
  const int log2_n;
  graph g;
  vector<vector<int>> parent;
  vector<int> depth;

  LCA(int root, const graph &g) : root(root), n(g.size()), log2_n(log2(n)+1), g(g), parent(log2_n, vector<int>(n)), depth(n) {
    dfs(g, root, root, 1);
    for (int k = 0; k+1 < log2_n; ++k) {
      parent.push_back(vector<int>(n, root)); // 要素数n, 値rootで初期化
      for (int v = n-1; v >= 0; --v) {
        int par = parent[k][v];
        parent[k+1][v] = parent[k][par];
      }
    }
  }
  
  /** 
   * par : 親のid
   * d : 木の深さ (1から始める)
   */ 
  void dfs(const graph& g, int from, int par, int d) {
    parent[0][from] = par;
    depth[from] = d;
    for (auto &e: g[from]) {
      if (depth[e.to] > 0) continue;
      dfs(g, e.to, from, d+1);
    }
  }

  int get(int v1, int v2) {
    // 深さが同じになるまで片方を登らせる
    if (depth[v1] < depth[v2]) swap(v1, v2);
    for (int k = 0; k < log2_n; ++k) {
      if ((depth[v1]-depth[v2]) >> k & 1) {
        v1 = parent[k][v1];
      }
    }
    if (v1 == v2) return v1;

    // 親が同じになる直前まで登らせる
    for (int k = log2_n-1; k >= 0; --k) {
      int p_v1 = parent[k][v1];
      int p_v2 = parent[k][v2];
      if (p_v1 == p_v2) continue;
      v1 = p_v1;
      v2 = p_v2;
    }
    assert(parent[0][v1] == parent[0][v2]);
    return parent[0][v1];
  }
};
#line 4 "test/aoj/GRL_5_C.test.cpp"
#include <iostream>
using namespace std;

int main() {
  int n; cin >> n;
  Graph<int> graph(n);
  for (int i = 0; i < n; ++i) {
    int k; cin >> k;
    for (int j = 0; j < k; ++j) {
      int c; cin >> c;
      graph[i].emplace_back(i, c);
    }
  }
  LCA<int> lca(0, graph);
  int q;
  cin >> q;
  for (int i = 0; i < q; ++i) { 
    int u, v;
    cin >> u >> v;
    cout << lca.get(u, v) << endl;
  }
}



Measured memory_bytes: 30224
#include<bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n ; i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define whole(f, x, ...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x) // decltypeで型取得、引数があればva_argsのところに入れる
using namespace std;
typedef long long ll; // long longをllでかけるようにした
const int INF = 1e9;

int main(void){
    int n, m; cin >> n >> m;
    vector<int> A(n), B(n), C(m), D(m), check(n);
    REP(i, n) cin >> A[i] >> B[i];
    REP(i, m) cin >> C[i] >> D[i];

    REP(i, n){
        int ans = INF;
        REP(j, m){
            if(ans > abs(A[i] - C[j]) + abs(B[i] - D[j]) ){
                ans = abs(A[i] - C[j]) + abs(B[i] - D[j]);
                check[i] = j + 1;
            }
        }
    }

    REP(i, n) cout << check[i] << endl;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
# スペース区切りの整数の入力
#N, K = map(int, input().split())
N=int(input())
# 文字列の入力
s = input()
a=s.split(' ')
a=list(map(int,a))
a=sorted(a)
a.reverse()
flg=1
ans=0
for i in a:
    ans = ans + (i*flg)
    flg = flg*-1
print(ans)
#print(s[0:K-1]+s[K-1].lower()+s[K:N])


Measured memory_bytes: 3060
n=int(input())
query=[]
for _ in range(n):
    a,b,c=map(int,input().split())
    query.append((a,b,c))
query=sorted(query, key=lambda x:x[2], reverse=True)

for cx in range(101):
  for cy in range(101):
      h=None
      flg=True
      for q in query:
        if h==None:
          h=q[2]+abs(cx-q[0])+abs(cy-q[1])
        elif q[2]!=0 and h!=q[2]+abs(cx-q[0])+abs(cy-q[1]):
          flg=False
          break
        elif q[2]==0 and h-abs(cx-q[0])-abs(cy-q[1])>0:
          flg=False
          break
      if flg: 
        print(cx,cy,h)
        exit()


Measured memory_bytes: 73384
from collections import deque
n = int(input())

d = deque()

for _ in range(n):
    com = input()
    if (com[0] == 'i'):
        com ,i = com.split()
        d.appendleft(int(i))
    elif (com[0] == 'd'):
        if (com[6] == ' '):
            com, i = com.split()
            try:
                d.remove(int(i))
            except ValueError:
                pass
        elif (com[6] == 'F'):
            d.popleft()
        elif (com[6] == 'L'):
            d.pop()
ans = map(str, d)
ans = " ".join(ans)
print(ans)

Measured memory_bytes: 48140
import std.stdio, std.string, std.conv, std.array, std.algorithm;
void main()
{
  auto q = readln.chomp.to!int;
  for(int i=0;i<q;++i){
    auto b = readln.split.map!(to!int);
    int c=b[0],a=b[1],n=b[2];
    int ans=0;
    if(a<n){
      ans+=min(c,a);
      c=max(0,c-ans);
      a=max(0,a-ans);
      n=max(0,n-ans);
    }else{
      ans+=min(c,n);
      c=max(0,c-ans);
      a=max(0,a-ans);
      n=max(0,n-ans);
    }
    if(a>0){
      int x = min(c/2,a);
      c=max(0,c-2*x);
      a=max(0,a-x);
      ans+=x;
    }
    ans+=c/3;
    ans.writeln();
  }
}

Measured memory_bytes: 2452
#include <iostream>

using namespace std;

int gcd(int a, int b){ return a%b ? gcd(b, a%b) : b; }
int lcm(int a, int b){ return a/gcd(a,b)*b; }

int main(){
  int a, b;
  while(cin >> a >> b){
     cout << gcd(a,b) << " " << lcm(a,b) << endl;
  }
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  long long k;
  scanf("%lld", &k);
  puts("50");
  for(int i = 0; i < 50; i++)
    printf("%lld ", (i < k%50 ? 100 : 49) + k/50 - k%50);
}


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

#define REP(i,a,b) for(int i=(a);i<(b);++i)
#define RREP(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define rep(i,n) REP(i,0,n)
#define rrep(i,n) RREP(i,n,0)
#define INF (1<<30)
#define INFLL (1LL<<62LL)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);
  int N;
  vector<int> A, B;
  cin >> N;

  A.resize(N);
  B.resize(N);

  rep(i, N) cin >> A[i] >> B[i];

  ll ans = 0;
  rrep(i, N) {
    if ((ans + A[i]) % B[i] == 0) ans = ans + A[i];
    else ans = (ans + A[i] + B[i]) / B[i] * B[i];
    ans -= A[i];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1024
import sys
sys.setrecursionlimit(10 ** 7)

import numpy as np
from heapq import heappush, heappop

N, M, S, T = map(int,input().split())
# graph[0]は使わない（都市の名前と添字が一致）
graph = [[] for _ in range(N+1)]

for _ in range(M):
    u, v, a, b = map(int,input().split())
    # (v, a, b)はvの都市に行くのに、a円またはbスヌーク）
    graph[u].append((v, a, b))
    graph[v].append((u, a, b))

def dijkstra(start, mode):
    INF = 10 ** 15
    # 最初の所持金で初期化　dist[0]は使わない
    dist = [INF] * (N+1)
    dist[start] = 0
    que = [(0,start)]
    while que:
        # (d, v) はdが現在の最小の交通費、vが現在の場所
        d, v = heappop(que)
        # 既に来たことがある場合、continue
        if dist[v] < d:
            continue
        for w, *a in graph[v]:
            # modeによって円かスヌー区を使うか選ぶ
            d1 = d + a[mode]
            # 次の場所の交通費よりやすくなる場合は、データを更新
            if dist[w] > d1:
                dist[w] = d1
                heappush(que, (d1, w))
    return dist

# 円で行く場合、それぞれの都市にいくらで行けるか
d1 = np.array(dijkstra(S, 0))
# ゴール地点からスヌークで行く場合
d2 = np.array(dijkstra(T, 1))
# 足し合わせて、切り替わったところが両替地点
d1 += d2
# i年後、両替所がなくなった時、後ろから見ていった最小値
answer = 10 ** 15 - np.minimum.accumulate(d1[::-1])[::-1][1:]
print('\n'.join(answer.astype(str)))


Measured memory_bytes: 78316
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <sstream>
#include <cmath>
#include <set>
#include <iomanip>
#include <deque>
using namespace std;
typedef long long ll;
 
#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 FOREACH(i,Itr) for(auto (i)=(Itr).begin();(i)!=(Itr).end();(i)++)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
#define UNIQUE(Itr) sort((Itr).begin(),(Itr).end()); (Itr).erase(unique((Itr).begin(),(Itr).end()),(Itr).end())
#define LBOUND(Itr,val) lower_bound((Itr).begin(),(Itr).end(),(val))
#define UBOUND(Itr,val) upper_bound((Itr).begin(),(Itr).end(),(val))
 
struct UnionFind {
   vector<int> node;
   UnionFind(int n) : node(n,-1) {}
   bool unionSet(int x, int y) {
      x = root(x); 
      y = root(y);
      if (x != y) {
         if (node[y] < node[x]) swap(x, y);
         node[x] += node[y]; 
         node[y] = x;
      }
      return x != y;
   }
   bool findSet(int x, int y) {
      return root(x) == root(y);
   }
   int root(int x) {
      return node[x] < 0 ? x : node[x] = root(node[x]);
   }
   int size(int x) {
      return -node[root(x)];
   }
};
 
int main(){
 
    int N,K,L; cin>>N>>K>>L;
    UnionFind inst1(200010);
    UnionFind inst2(200010);
    REP(i,K){
        int p,q; cin>>p>>q;
        inst1.unionSet(p,q);
    }
    REP(i,L){
        int r,s; cin>>r>>s;
        inst2.unionSet(r,s);
    }
    
    map<int,vector<int> > same_g;
    for(int i=1;i<=N;i++){
        same_g[inst1.root(i)].push_back(i);
    }
    
    int ans[200010]={};
    FOREACH(i,same_g){
        vector<int> t=i->second;
        map<int,int> root;
        REP(j,t.size()){
            int r=inst2.root(t[j]);
            if(root.find(r)==root.end())root[r]=1;
            else root[r]++;
        }
        REP(j,t.size())ans[t[j]]=root[inst2.root(t[j])];
    }
    
    for(int i=1;i<N;i++){
        cout<<ans[i]<<" ";
    }
    cout<<ans[N]<<endl;
    
    return 0;
}

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

using namespace std;

int N;
int a[100005][3];
int dp[100005][3];

int solve(int idx , int ax)
{
    if(idx==N)
        return 0;

    int &res = dp[idx][ax];
    if(~res)
        return res;
    res = 0;
    if(ax!=0)
        res =  max(res , solve(idx+1 , 0) + a[idx][0]);
    if(ax!=1)
        res =  max(res , solve(idx+1 , 1) + a[idx][1]);
    if(ax!=2)
        res =  max(res , solve(idx+1 , 2) + a[idx][2]);
    return res;

}



int main()
{

    memset(dp , -1 , sizeof(dp));
    cin>>N;
    for(int i=0; i<N; i++)
    {
        cin>>a[i][0]>>a[i][1]>>a[i][2];
    }

    int ans = solve(0 , 0);
    ans = max(ans,solve(0 , 1));
    ans = max(ans,solve(0 , 3));
    cout<<ans;

    return 0;
}


Measured memory_bytes: 8832
import java.util.*;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
	int n = Integer.parseInt(sc.next());
    int a[] = new int[n];
    int p[] = new int[n];
    
    for (int i=0; i<n; i++) {
      a[i] = Integer.parseInt(sc.next());
      p[i] = 0;
    }
    
    for (int i=0; i<n; i+=2) {
      p[0] += a[i];
    }
    
    for (int i=1; i<n; i+=2) {
      p[0] -= a[i];
    }
      
    p[n-1] = 2* a[n-1] - p[0];
    
    for (int i=n-2; i>0; i--) {
      p[i] = 2 * a[i] - p[i+1];
    }
    
    for (int i=0; i<n; i++) {
      if (i==n-1) {
        System.out.print(p[i] + "\n");
      } else {
        System.out.print(p[i] + " ");
      }
    }

  }
}


Measured memory_bytes: 51688
#include<bits/stdc++.h>
#define X first
#define Y second
#define pb push_back
#define eb emplace_back
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define reps(i,j,k) for(int i=(j);i<=(k);++i)
#define in(i,j,k) ((i)>=(j)&&(i)<=(k))
#define sz size()


using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

typedef pair<int,pii> piii;

vector<piii> days;

int main(){
  rep(i,1000)if(i)
    rep(j,11)if(j)
      rep(k,19+(j%2==1||i%3==0))
	days.eb(i,pii(j,k));
  int n;
  cin>>n;
  piii day;
  rep(i,n){
    cin>>day.X>>day.Y.X>>day.Y.Y;
    cout<<1+days.end()-lower_bound(all(days),day)<<endl;
  }
}

Measured memory_bytes: 4052
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<map>
#include<cstring>
#include<queue>
#include<stack>
#include<vector>
using namespace std;

const int maxn = 1e5 + 5;
int a[maxn],b[maxn],c[maxn];

int main(){
	long long sum = 0,n,x,y;
	scanf("%lld",&n);
	for(int i = 1;i <= n;i++) scanf("%d",&a[i]);
	for(int i = 1;i <= n;i++) scanf("%d",&b[i]);
	for(int i = 1;i <= n;i++) scanf("%d",&c[i]);
	sort(a + 1,a + 1 + n);
	sort(b + 1,b + 1 + n);
	sort(c + 1,c + 1 + n);
	for(int i = 1;i <= n;i++){
		x = lower_bound(a + 1,a + 1 + n,b[i]) - a;
		if(x == n + 1) x = n;
		else x--;
		y = upper_bound(c + 1,c + 1 + n,b[i]) - c;
		if(y == n + 1) y = 0;
		else y = n - y + 1;
		sum += x * y;
	}
	printf("%lld",sum);
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,cnt=0,ans=0,a;
  cin>>n;
  for(int i=1;i<=n;i++){
    int temp=i;
    while(1){
      if(temp%2==1)break;
      temp/=2;
      cnt++;
    }
    if(ans<=cnt){
      a=i;
      ans=cnt;
    }
    cnt=0;
  }
  cout<<a<<endl;
  return(0);
}


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

int main(void){
    const long long int MOD = 1000000007;
    int n,m;
    scanf("%d %d",&n,&m);
    int a[n+1];
    int tmp;
    for (int i = 0;i < n+1;i++){
        a[i] = 0;
    }
    for (int i = 0; i < m;i++){
        tmp = 0;
        scanf("%d",&tmp);
        a[tmp] = 1;
    }

    // 動的計画法？　加算の仕方はフィボナッチ数列みたいな考え方
    long long int total[n+2];
    total[0] = 1;
    // 床が抜けているところは０で埋める
    if (a[1] != 1) total[1] = 1;
    else total[1] = 0;

    for (int i = 2;i < n+1;i++){
        if (a[i] != 1){
            total[i] = (total[i-1] + total[i-2]) % MOD;
        }
        else total[i] = 0;
        // printf("%lld %d\n",total[i],i);
    }
    printf("%lld \n",total[n]);
}

Measured memory_bytes: 1280
object Main {
  def main(args: Array[String]): Unit = {
    import scala.io.StdIn.readLine
    val Array(datN) = readLine.split(" ").map(_.toInt)
    val datA = readLine.split(" ").map(_.toInt)

    val scoreA = datA.groupBy(identity).map{ case (k, v) => (k, v.length) }
    val ans = scoreA.keys.map{ a => scoreA.getOrElse(a - 1, 0) + scoreA.getOrElse(a, 0) + scoreA.getOrElse(a + 1, 0)}.max
    println(ans)
  }
}


Measured memory_bytes: 87140
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>

using namespace std;

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

    int H[n];
    for(int i=0; i < n; i++){
        cin >> H[i];
    } 
    int temp = 0;
    int ans = 0;
    for(int i=0; i < n-1; i++){
        if(H[i] >= H[i+1]){
            ++temp;
            if(temp > ans) ans = temp;
        }else{
            temp = 0;

        }
    }

    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 640