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

public class Main {
	private static Scanner sc;

	public static void main(String[] args) {
		Main instance = new Main();
		sc = instance.new Scanner();
		instance.solve();
	}

	private void solve() {
		try {
			int N = sc.nextInt();
			long A = sc.nextInt();
			long B = sc.nextInt();

			long[] ary = new long[N];
			for (int i = 0; i<N;i++) {
				ary[i] = sc.nextLong();
			}

			long ret =0;
			for (int i = 0; i < N-1; i++) {
				ret += Math.min((ary[i+1]-ary[i])*A, B);
			}

			System.out.println(ret);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	private class Scanner {
		String[] s;
		int i;
		BufferedReader br;
		String regex = " ";

		public Scanner() {
			s = new String[0];
			i = 0;
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		@Override
		protected void finalize() throws Throwable {
			try {
				super.finalize();
			} finally {
				destruction();
			}
		}

		private void destruction() throws IOException {
			if (br != null)
				br.close();
		}

		public String next() throws IOException {
			if (i < s.length)
				return s[i++];
			String st = br.readLine();
			while (st == "")
				st = br.readLine();
			s = st.split(regex, 0);
			i = 0;
			return s[i++];
		}

		public int nextInt() throws NumberFormatException, IOException {
			return Integer.parseInt(next());
		}

		public Long nextLong() throws NumberFormatException, IOException {
			return Long.parseLong(next());
		}

		public Double nextDouble() throws NumberFormatException, IOException {
			return Double.parseDouble(next());
		}
	}
}


Measured memory_bytes: 34996
def main():
    n=int(input())
    a=list(map(int,input().split()))
    mod=10**9+7
    if n==1:
        print(2*a[0]%mod)
        return
    a.sort(key=lambda x:-x)
    mod=10**9+7
    ans=sum([a[i]*(i+2)%mod for i in range(n)])
    ans=ans*pow(2,n,mod)*pow(2,n-2,mod)%mod
    print(ans)

main()

Measured memory_bytes: 27108
#include<cstdio>
#include<cmath>
#include<string>
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<map>
#include<set>
#include<limits>
#include<bitset>
#include<array>
#include<numeric>
#include<iomanip>
#include<functional>
#include<deque>

using namespace std;
typedef long long int ll;

#define C cout<<
#define E <<endl

#define SIZ 200010

int n,t,w[SIZ],v[SIZ];

vector<vector<ll>> dp;

vector<vector<ll>> v2vec(int x,int y,int value=0){ return vector<vector<ll>>(y,vector<ll>(x,value)); }

int main(){
    cin>>n>>t;
    for(int i=0;i<n;i++){
        cin>>w[i]>>v[i];
    }
    
    int xsiz=t;
    int ysiz=n;
    
    bool debug=false;
    
    dp=v2vec(xsiz+1,ysiz+1,0);
    
    for(int y=0;y<ysiz;y++){
        for(int x=0;x<xsiz+1;x++){
            dp[y+1][x]=max(dp[y+1][x],dp[y][x]);
            if(x+w[y]<=t){
                dp[y+1][x+w[y]]=max(dp[y+1][x+w[y]],dp[y][x]+v[y]);
            }
        }
    }
    
    C dp[ysiz][xsiz] E;
    
    
    if(debug){
        for(int y=0;y<ysiz+1;y++){
            for(int x=0;x<xsiz+1;x++){
                C dp[y][x]<<" ";
            }
            C "" E;
        }
    }
}

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

using namespace std;

const int INF = 1001001001;

int all[100001], single[100001];

int main()
{
	int N;
	int H[128];

	while (scanf("%d", &N) && N){

		for (int i = 0; i < N; i++) scanf("%d", H + i);

		fill(all, all + 100001, INF);
		fill(single, single + 100001, INF);

		all[0] = single[0] = 0;

		int M;
		scanf("%d", &M);

		for (int i = 0; i < M; i++){
			int mp, dmg;
			char type[128];

			scanf("%*s %d %s %d", &mp, type, &dmg);

			dmg = min(dmg, 100000);

			int *p = (type[0] == 'S' ? single : all);

			for (int j = 0; j <= 100000; j++){
				p[j] = min(p[j], p[max(0, j - dmg)] + mp);
			}
		}

		int ans = INF;
		for (int i = 0; i <= 100000; i++){
			int tmp = all[i];
			for (int j = 0; j < N; j++){
				tmp = min(INF, tmp + single[max(0, H[j] - i)]);
			}
			ans = min(ans, tmp);
		}

		printf("%d\n", ans);
	}

	return (0);
}

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

using namespace std;

int main(){

	int W, H, x, y, r;

	cin >> W >> H >> x >> y >> r;

	if (x >= r && x <= W - r && y >= r && y <= H - r)
		cout << "Yes\n";
	else
		cout << "No\n";
}

Measured memory_bytes: 1128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=5e18;
 
template<typename T,T MOD,T B>
struct RollingHash{
  vector<T> hash,p;
  RollingHash(){}
  RollingHash(const string &s){
    ll n=s.size();
    hash.assign(n+1,0);
    p.assign(n+1,1);
    for(ll i=0;i<n;i++){
      hash[i+1]=(hash[i]*B+s[i])%MOD;
      p[i+1]=p[i]*B%MOD;
    }
  }
  //S[l, r)
  T find(ll l,ll r){
    T res=hash[r]+MOD-hash[l]*p[r-l]%MOD;
    return res>=MOD?res-MOD:res;
  }
};
 
int main() {
  ll n;
  string s;
  cin >> n >> s;
  for(ll i=0;i<n;i++) {
    s[i]=s[i]-'a';
  }
  RollingHash<ll,mod,27> rs(s);
  ll l=0,r=n/2+1;
  ll temp=(l+r)/2;
  while(l+1<r) {
    bool flag=false;
    for(ll i=0;i<max(n-temp+1,0LL);i++) {
      for(ll j=i+temp;j<max(n-temp+1,0LL);j++) {
        if(rs.find(i,i+temp)==rs.find(j,j+temp)) {
          flag=true;
          break;
        }
      }
      if(flag) break;
    }
    if(flag) {
      l=temp;
    }
    else {
      r=temp;
    }
    temp=(l+r)/2;
  }
  cout << l << endl;
}

Measured memory_bytes: 384
#include<iostream>
#include<iomanip>
#include<cstring>
#include<cmath>
#include<cstdio>
#include<queue>
#include<algorithm>
using namespace std;
int read()
{
	char c=getchar();
	int res=0;
	while(c<'0'||c>'9') c=getchar();
	while(c>='0'&&c<='9') res=(res<<1)+(res<<3)+(c^48),c=getchar();
	return res;
}
int k,n,nx[505],A[505][505];
int main()
{
	k=read();
	if(k<=500)
	{
		printf("%d\n",k);
		for(int i=1;i<=k;i++,puts(""))
		for(int j=1;j<=k;j++) printf("%d ",i);
	}
	else
	{
		n=500;
		for(int i=1;i<=n;i++) nx[i]=i+1;
		nx[n]=1;printf("%d\n",n);k-=n;
		int N=0;
		for(int i=1;i<=n;i++)
		{
			int a=++N,b=N;
			if(k) k--,b=++N;
			for(int x=1,y=i;x<=n;x++,y=nx[y]) A[x][y]=x&1?a:b;
		}
		for(int i=1;i<=n;i++,puts(""))
		for(int j=1;j<=n;j++) printf("%d ",A[i][j]);
	}
}

Measured memory_bytes: 4708
#include <iostream>
#include <vector>
using namespace std;
// board board[x]=y
// checkedNW x, yにコマがある時、checkedNW[i+j]=true;
// checkedNE x, yに駒がある時、i+(7-j)

vector<short int> board(9, -1);
vector<bool> checked_NW(15, false),checked_NE(15, false), checked_W(8, false), checked_N(8, false);


vector<short int> dfs(int n){
  if (n==8){
    board[8] = 1;
    return board;
  }
  for (int i=0;i<8;i++){
    int y = board[i];
    if ( y != -1 ) continue;
    for (int j=0;j<8;j++){
      if (checked_N[i] || checked_W[j] || checked_NW[i+j] || checked_NE[7+i-j]) continue;
      board[i] = j;
      checked_N[i] = true;
      checked_W[j] = true;
      checked_NW[i+j] = true;
      checked_NE[7+i-j] = true;
      auto res = dfs(n+1);
      if (res[8] == 1)
        return board;
      board[i] = -1;
      checked_N[i] = false;
      checked_W[j] = false;
      checked_NW[i+j] = false;
      checked_NE[7+i-j] = false;
    }
  }
  return board;
}

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

  for (int i=0;i<n;i++){
    int x, y;
    cin >> x >> y;
    board[x] = y;
    checked_N[x] = true;
    checked_W[y] = true;
    checked_NW[x+y] = true;
    checked_NE[7+x-y] = true;
  }
  auto res = dfs(n);
  for (int i=0;i<8;i++){
    for(int j=0;j<8;j++){
     cout << ((res[i]==j)?'Q':'.');   
    }
    cout << endl;
  }
  return 0;
}



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

int main(){
  int n;
  long long int ans=0;
  cin>> n;
  int a[n];
  for(int i=0;i<n;i++){
    cin >> a[i];
    ans+=(a[i]-1);
  }

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


Measured memory_bytes: 256
#!/usr/bin/env python
# -*- coding: utf-8 -*-

N = int(input())
B = [int(x) for x in input().split()]
A = [0] * (len(B)+1)
for i in range(0, len(B)+1, 1):
  if i == 0:
    A[i] = B[i]
  elif i == len(B):
    A[i] = B[i-1]
  else:
    A[i] = min(B[i], B[i-1])
print(sum(A))

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
const int MAX=200001;
int n,k,a[MAX],tmp,e_count,ans;
int main(){
  scanf("%d %d",&n,&k);
  for(int i=0;i<n;++i){
    scanf("%d",&tmp);
    if(a[tmp]==0)e_count++;
    a[tmp]++;
  }
  if(e_count<=k){
    printf("%d",0);
    return 0;
  }
  sort(a,a+n+1);
  tmp=0;
  while(e_count!=k){
    if(a[tmp]!=0){
      ans+=a[tmp];
      e_count--;
    }
    tmp++;
  }
  printf("%d\n", ans);
  return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
  int N,M;
  cin>>N>>M;
  vector<pair<int,int>> A(N);
  for(pair<int,int> &p:A)
    cin>>p.first>>p.second;
  sort(A.begin(),A.end());
  int ans=0,cnt=0;
  for(int i=0;cnt<M;i++){
    ans+=A[i].first*min(A[i].second,M-cnt);
    cnt+=A[i].second;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 4824
S = input()
ans = 'WA'
if S[0] == 'A':
    if S[2:-1].count('C') == 1:
        tmp = 0
        for c in S:
            if c.islower(): tmp += 1
        if tmp == len(S) - 2:
            ans = 'AC'
print(ans)

Measured memory_bytes: 2940
#include<iostream>
using namespace std;
int main(void)
{
	int h,w,i,j;
	while(1){
		cin>>h>>w;
		if(h==0 && w==0) break;
		for(i=0;i<h;i++){
			for(j=0;j<w;j++){
				if((i+j)%2==0) cout<<"#";
				else cout<<".";
			}
			cout<<endl;
		}
		cout<<endl;
	}
	return 0;
}


Measured memory_bytes: 3088
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
const ll MOD = 1000000007;
const ll INF = 4611686018427387903;
#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

int main(){
	int n; cin >> n;
	VI a(n); REP(i,n) cin >> a[i];
	VI c(1000001,0);
	sort(ALL(a));
	int ans=0;
	REP(i,n){
		if(i!=0){
			if(a[i]==a[i-1]){
				if(!c[a[i]])
					ans--;
				int k=a[i];
				while(a[i]==k){
					i++;
					if(i==n){
						k=-1;
						break;
					}
				}
				if(k==-1)
					break;
				i--;
				continue;
			}
		}
		if(!c[a[i]])
			ans++;
		for(int j=a[i]*2;j<=1000000;j+=a[i])
			c[j]=1;
	}
	cout << ans << endl;
	return 0;
}


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

/* macro */
#define rep(i,a,b) for(int i=a;i<b;i++)
#define revrep(i,a,b) for(int i = a; i > b; i--)
#define int long long
#define exist(s,e) ((s).find(e)!=(s).end())
#define all(v) (v).begin(), (v).end()
#define each(s,itr) for(auto (itr) = s.begin(); (itr) != s.end(); (itr)++)
#define sum(v) accumulate(all(v), (0LL))
#define isin(a, b, c) (b <= a && a <= c)
#define println cout << "\n";
#define sz(v) (int)v.size()
#define bin(x) static_cast<bitset<16> >(x)



/* alias */
template<class T> using vec = vector<T>;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef tuple<int, int, int> ti;
typedef map<int, int> mi;
typedef set<int> si;


/* constant */
const int inf = 1LL << 62;
const int mod = 1e9 + 7;
const int dx[8]={1,0,-1,0,-1,1,-1,1};
const int dy[8]={0,1,0,-1,-1,-1,1,1};
const string alphabet = "abcdefghijklmnopqrstuvwxyz";

/* io_method */
int input(){int tmp;cin >> tmp;return tmp;}
string raw_input(){string tmp;cin >> tmp;return tmp;}
template<class T> void printx(T n){cout << n;}
template<class T, class U> void printx(pair<T, U> p){cout << "(" << p.first << "," << p.second << ")";}
template<class T, class U, class V> void printx(tuple<T, U, V> t){cout << "{" << get<0>(t) << "," << get<1>(t) <<"," << get<2>(t) << "}" << endl;}
template<class T> void printx(vector<T> v){cout << "{";rep(i,0,v.size()){printx(v[i]);if(i != v.size()-1)printx(",");}cout << "}";}
template<class T> void print(T n){printx(n);cout << endl;}
template<class T> void print(set<T> s){cout << "{";each(s, e){if(e != s.begin()) printx(",");printx(*e);}cout << "}" << endl;}
template<class T, class U> void print(map<T, U> mp){cout << "{";each(mp, e){cout << "(" << e -> first << "," << e -> second << ")";}cout << "}" << endl;}
template<class T> void printans(vec<T> v){rep(i,0,sz(v)){cout << v[i] << (i == sz(v) - 1 ? "" : " ");}cout << endl;}


/* general_method */
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class T>T cut(T &a, int l, int r){return T(a.begin()+l, a.begin()+r);}

/* main */

int n;
vi arr;
void in(){
    cin >> n;
    rep(i,0,n) arr.push_back(input());
}

void solve(){
    
    vi ans;
    rep(i,0,n){
        revrep(j,n - 1 - i, -1){
            if(arr[j] - 1 == j){
                ans.push_back(arr[j]);
                vi tmp = cut(arr, 0, j);
                vi b = cut(arr, j + 1, sz(arr));
                for(int e : b) tmp.push_back(e);
                arr = tmp;
                break;
            }
        }
    }

    if(sz(arr) > 0){
        print(-1);
        return ;
    }

    reverse(all(ans));
    printans(ans);


}

signed main(){

    cin.tie(0);
    ios::sync_with_stdio(false);
    in();
    solve();
    
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define DEBUG 0
/*
*/

using namespace std;



int main() {
	long long int C;
	cin >> C;
	long long int sum = 0;
	for (size_t i = 0; i < 10000000; i++)
	{
		sum += i;
		if (sum >= C)
		{
			cout << i << endl;
			break;
		}
	}


	if (DEBUG)
	{
		int ewataeoprgjpsrteog;
		cin >> ewataeoprgjpsrteog;
	}
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <numeric>
#include <cstdint>
#include <iomanip>
using ll = long long;
#define fast_io(); std::ios_base::sync_with_stdio(0); std::cin.tie(0); std::cout.tie(0);

int main(){
    int R,G,B,N; std::cin >> R >> G >> B >> N;

    int ans = 0;
    for(int r=0; r<=N/R; r++){
        for(int g=0; g<=N/G; g++){
            int t = r*R + g*G;
            if( 0<=t && t<=N && (N-t)%B==0 ) ans++;
        }
    }

    std::cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 3604
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

const int MOD = 1000000007, INF = 1111111111;
using namespace std;
using lint = long long;

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

#ifdef _DEBUG
template <class Head>
void dump(const char* str, Head &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + 1, t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int x, t;
	cin >> x >> t;

	cout << max(x - t, 0) << "\n";

	return 0;
}

Measured memory_bytes: 256
a,b,x,y = map(int, input().split())


xlist=list(map(int, input().split()))
ylist=list(map(int, input().split()))

xlist.sort(reverse=True)
ylist.sort()

xmax = xlist[0]
ymin = ylist[0]

ans = "War"

for i in range(-100, 100):
    if x < i <= y:
        if xmax < i <= ymin:
            ans = "No War"

print(ans)


Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int a = sc.nextInt();
		int b = sc.nextInt();

		int c = b - a;
		int h = 0;

		for (int i = 1; i < c; i++) {

			h += i;
		}

		System.out.println(h - a);
	}
}


Measured memory_bytes: 23124
use std::io::*;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut iter = buf.split_whitespace();

    let base = vec![1 , 100, 10000];
    let d: usize = iter.next().unwrap().parse().unwrap();
    let n: usize = iter.next().unwrap().parse().unwrap();

    let c = if n == 100 { 101 } else { n };
    println!("{}", base[d] * c);
}


Measured memory_bytes: 4352
#include <iostream>
#include <vector>

using namespace std;

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

struct edge{
    int u;
    int v;
    int w;
    edge(int u,int v,int w) : u(u),v(v),w(w) {}
};


void dfs(vector<int>&,vector<vector<edge> >&,int,int);

int main()
{
    int N;cin>>N;
    vector<int> C(N,-1);
    vector<vector<edge> > L(N);
    rep(i,N-1){
        int u,v,w;
        cin>>u>>v>>w;
        L[u-1].push_back(edge(u-1,v-1,w));
        L[v-1].push_back(edge(v-1,u-1,w));
    }
    dfs(C,L,0,0);
    for(auto c : C){
        cout << c << endl;
    }

    return 0;
}

void dfs(vector<int> &C, vector<vector<edge> > &L,int u, int c)
{
    C[u] = c;
    for(auto e : L[u]){
        if(C[e.v]==-1){
            if(e.w%2==0){
                dfs(C,L,e.v,c);
            }else{
                dfs(C,L,e.v,1-c);
            }
        }
    }
}

Measured memory_bytes: 8960
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
#include <tuple>
using namespace std;

#define rep(i,a) for(int i=0; i<a; i++)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define rep1(i,a) for(int i=1; i<=a; i++)
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define mem(a,n) memset( a, n, sizeof(a))
#define all(a) a.begin(),a.end()

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;
static const double pi = 3.141592653589793;

int N, M;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    vector<pii> seg[309];
    
    cin>>N>>M;
    rep(i,M){
        int l,r,x; cin>>l>>r>>x;
        seg[r].push_back({l,x});
    }
    
    int dp[309][309][309]={{{0}}};
    dp[0][0][0]=1;
    ll ret=0;
    rep(i,N+1){
        rep(j,N+1){
            rep(k,N+1){
                int m = max(i,max(j,k));
                
                for(pii p:seg[m]){
                    int r=m;
                    int l=p.first;
                    int x=p.second;
                    
                    int cnt=0;
                    if(l<=i&&i<=r) cnt++;
                    if(l<=j&&j<=r) cnt++;
                    if(l<=k&&k<=r) cnt++;
                    if(cnt!=x) dp[i][j][k]=0;
                }
                
                if(m==N){
                    ret = (ret+dp[i][j][k])%MOD;
                    continue;
                }
                
                int num=dp[i][j][k];
                dp[m+1][j][k] = (dp[m+1][j][k]+num)%MOD;
                dp[i][m+1][k] = (dp[i][m+1][k]+num)%MOD;
                dp[i][j][m+1] = (dp[i][j][m+1]+num)%MOD;
            }
        }
    }
    cout1(ret);
}

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

int main () {
  int N;
  cin >> N;
  for (int i = 0;i < N;i++) {
  int A;
  cin >> A;
  if (A % 2 == 0 ) {
  if (A % 3 != 0 && A % 5 != 0){
  cout << "DENIED" << endl;
    return 0;
  }
  else {
  continue;
  }
  }
  }
  cout << "APPROVED" << endl;
}


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

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

  vector<int> s(N + 1, 0);
  for (int i = 0; i < N; i++) {
    int W = 0;
    scanf("%d", &W);
    s.at(i + 1) = s.at(i) + W;
  }

  int ans = INT32_MAX;
  for (int T = 1; T < N; T++) {
    int S1 = s.at(T) - s.at(0);
    int S2 = s.at(N) - s.at(T);
    if (abs(S1 - S2) < ans) {
      ans = abs(S1 - S2);
    }
  }

  printf("%d", ans);
  return 0;
}

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

int main(){
    ll n;
    cin>>n;
    for(ll i=1;i<=9;++i){
        if(n<=111*i){
            cout<<111*i<<endl;
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define x first
#define y second
#pragma GCC optimize(2)
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC optimize(3)
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC target("sse3","sse2","sse")
#pragma GCC target("avx","sse4","sse4.1","sse4.2","ssse3")
#pragma GCC target("f16c")
#pragma GCC optimize("inline","fast-math","unroll-loops","no-stack-protector")
#pragma GCC diagnostic error "-fwhole-program"
#pragma GCC diagnostic error "-fcse-skip-blocks"
#pragma GCC diagnostic error "-funsafe-loop-optimizations"
#pragma GCC diagnostic error "-std=c++14"
#define IOS ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
typedef unsigned long long ULL;
typedef pair<int,int> PII;
typedef long long LL;
const int N=2010;
const int INF=0x3f3f3f3f;
const int MOD=998244353;
int a[N];
int main(){
    IOS;
    int a,b,c;
    cin>>a>>b>>c;
    swap(a,b);
    swap(a,c);
    cout<<a<<' '<<b<<' '<<c<<endl;
    return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include<stdio.h>
#include<cmath>

using namespace std;
struct CD2D{
  double x,y;
  
  CD2D(double x,double y){
      this -> x = x;
      this -> y = y;
  }
  CD2D operator -(CD2D *obj){
      CD2D  return_CD2D  (
          (this -> x) - (obj -> x),
          (this -> y) - (obj -> y)
      );
      return return_CD2D;
  }
  void print(){printf("%lf %lf\n",this -> x,this -> y);}
 
  
};

void AskKoch(int n,CD2D p1,CD2D p2){
    CD2D s(0,0),t (0,0),u (0,0);
    if(n <= 0) return ;
    s.x = (2*p1.x + 1*p2.x) / (1 + 2);
    s.y = (2*p1.y + 1*p2.y) / (1 + 2);
    u.x = (1*p1.x + 2*p2.x) / (2 + 1);
    u.y = (1*p1.y + 2*p2.y) / (2 + 1);
    t.x = (u.x - s.x)*cos(M_PI/3) - (u.y - s.y)*sin(M_PI/3) + (s.x);
    t.y = (u.x - s.x)*sin(M_PI/3) + (u.y - s.y)*cos(M_PI/3) + (s.y);
    AskKoch(n-1,p1,s);
    s.print();
    AskKoch(n-1,s,t);
    t.print();
    AskKoch(n-1,t,u);
    u.print();
    AskKoch(n-1,u,p2);
}

int main(){
    int n;
    scanf("%d",&n);
    CD2D ps (0,0),pe (100,0);
    ps.print();
    AskKoch(n,ps,pe);
    pe.print();
}




Measured memory_bytes: 2764
N, A, B, C, D = [int(x) for x in input().split()]
# index変換
A -= 1; B -= 1
S = input()
if (C<D):
    if ("##" in S[A:D]):
        print("No")
    else:
        print("Yes")
else:
    if ("##" not in S[A:C]) and ("..." in S[B-1:D+1]):
        print("Yes")
    else:
        print("No")


Measured memory_bytes: 40560
/*Function Template*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pint;
const int MAX = 510000;
const int MOD = 1000000007;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define Rep(i, n) for(ll i = 1; i < (n); i++)
#define ALL(a)  (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll fac[MAX], finv[MAX], inv[MAX];


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;
}
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }

}
ll Len(ll n) {
  ll s=0;
  while(n!=0) s++, n/=10;
  return s;
}


ll Sint(ll n) {
  ll m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(ll i=s-1;i>=0;i--) m+=n/((ll)pow(10,i))-(n/((ll)pow(10,i+1)))*10;
  return m;
}


ll Svec(vector<ll> v){
  ll n=0;
  for(ll i=0;i<v.size();i++) n+=v[i];
  return n;
}


ll GCD(ll a,ll b) {
  return b ? GCD(b,a%b) : a;
}


ll LCM(ll a,ll b){
  return a/GCD(a,b)*b;
}


ll Factorial(ll n){
  ll m=1;
  while(n>=1) m*=n,n--;
  return m;
}

void runlength(string s,vector<pair<char,ll>> &p){
  ll x=1;
  if(s.size()==1){
    p.push_back(pair<char,ll>(s[0],1));
  }
  for(ll i=0;i<s.size()-1;i++){
    if(s[i]==s[i+1]){
      x++;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[i],x));
      }
    }else{
      p.push_back(pair<char,ll>(s[i],x));
      x=1;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[s.size()-1],x));
      }
    }
  }
}

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


string Toupper(string s){
  string ans="";
  rep(i,s.size()){
    if('a'<=s[i] && s[i]<='z') ans+=(char)s[i]-32;
    else ans+=s[i];
  }
  return ans;
}
string Tolower(string s){
  string ans="";
  rep(i,s.size()){
    if('A'<=s[i] && s[i]<='Z') ans+=(char)s[i]+32;
    else ans+=s[i];
  }
  return ans;
}


const int MAX_N=100010;
vector<bool> sieve_of_eratosthenes(){
  vector<bool> isPrime(MAX_N+1,true);
  for(int i=2;i<=MAX_N;i++){
    if(isPrime[i]){
      for(int j=2*i;j<=MAX_N;j+=i){
        isPrime[j]=false;
      }
    }
  }
  return isPrime;
}

vector<pint> prime_factorize(ll n){
  vector<pint> ans;
  for(ll p=2;p<=sqrt(n);p++){
    if(n%p!=0) continue;
    ll cnt=0;
    while(n%p==0){
      n/=p;
      cnt++;
    }
    ans.push_back(make_pair(p,cnt));
  }
  if(n!=1) ans.push_back(make_pair(n,1));
  return ans;
}

/*bool cmp(pint a, pint b) { return a.second < b.second; }*/

/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
int main() {
  IOS;
  string s;
  cin>>s;
  ll ind=0;
  ll ans=0;
  rep(i,s.size()){
    if(s[i]=='W'){
      ans+=i-ind;
      ind++;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 720
#include <stdio.h>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <queue>

//#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define ll long long int
#define pb push_back

int main() {
  int A, B, C;
  cin >> A >> B >> C;
  bool flag = false;
  for(int n = A; n <= B*A; n+=A){
      if(n%B == C) flag = true;
  }
  if(flag) cout << "YES" << endl;
  else cout << "NO" << endl;
  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll  long long int
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define vi vector<int>
#define br cout <<"\n";
#define all(x)  (x).begin(),(x).end()
#define tr(c,i) for(auto i : c)
#define pii pair< int,int >
#define fast_io() ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define pq priority_queue< pair<ll,pii> ,vector<pair<ll,pii>>,greater <pair<ll,pii>> >p;//container adapter makes ascending q
#define er(x) cout << x << " "
#define err(x,y) cout << x << " "<<y
const int M = 200005;
using namespace std;
clock_t time_p=clock();
void dem()
{
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}
using namespace std ;
const int N =  50  ;
const int dx[] = { 1, -1 , 0 , 0  };
const int dy [] = { 0 ,0 , 1 , -1  };

int main (){
string s ;
cin >> s ;
int l =s.length();
for ( int i = 1 ; i <= l ; ++i ){
    if( s[i-1] == 'U' || s[i-1] == 'D') continue ;
    else if ( i % 2 == 0 && s[i-1] == 'R' ){ cout << "No"; return 0 ;  }
    else if ( i%2 == 1 && s[i-1]== 'L'){ cout << "No"; return 0 ;  }
 }

  cout << "Yes" ;
return 0 ;

}


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

using namespace std;

typedef long long ll;

int main()
{
 ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
 int n, x;
 cin >> n >> x;
 set<int> sett;
 sett.insert(x);
 for(int i = 0; i < n; i++)
 {
   int y;
   cin >> y;
   sett.insert(y);
 }
 vector<int> vec;
 for(auto &x: sett)
  vec.push_back(x);
 if(vec.size() == 0)
 {
   cout << 0;
   return 0;
 }
 int gcd = -1;
 for(int i = 1; i < vec.size(); i++)
 {
   if(gcd == -1)
    gcd = vec[i] - vec[i - 1];
   else
    gcd = __gcd(gcd, vec[i] - vec[i - 1]);
 }
 cout << gcd;
 return 0;
}


Measured memory_bytes: 5632
n,m =map(int,input().split())
h=list(map(int,input().split()))
result=[1]*n
for i in range(m):
    a,b =map(int,input().split())
    a-=1
    b-=1
    if h[a]>h[b]:
        result[b]=0
    elif h[a]<h[b]:
        result[a]=0
    else:
        result[a]=0
        result[b]=0

print(sum(result))
            
        
        

Measured memory_bytes: 20072
#include <bits/stdc++.h>
using namespace std;
vector <int> v;
vector <double> vd;

vector <char> vc;
vector <string> vs;
map <string,int> sm;
map <int,int> mp;
map <char,int>cm;
set <int> st;
#define soort(v) sort(v.begin(),v.end())
#define foor(i,n) for(int i=1; i<n; i++)



int main(){
    int a,b=0,c=0,n;
    string s,p;
    char ch;
    
    cin >> n;
    
    v.resize(n);
    
    for(auto &i:v)cin >> i;
    
    c = v[0];
    for(int i=1; i<n; i++){
        if(v[i]<c){
            b++;
            c = v[i];
        }
        
    }
    cout << b+1 << endl;
   
    
    return 0;
}


Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] A = new int[N];
		int[] left = new int[N];
		int[] right = new int[N];
		for(int i = 0; i < N; i++) {
			A[i] = sc.nextInt();
		}
		sc.close();
		// System.out.println("--------");
		// 左からのMAXを保持
		left[0] = A[0];
		// System.out.print(left[0] + " ");
		for(int i = 1; i < N; i++) {
			left[i] = Math.max(left[i - 1], A[i]);
			// System.out.print(left[i] + " ");
		}
		// System.out.println("");
		// 右からのMAXを保持
		right[N - 1] = A[N - 1];
		// System.out.print(right[N - 1] + " ");
		for(int i = N - 2; i >= 0; i--) {
			right[i] = Math.max(right[i + 1], A[i]);
			// System.out.print(right[i] + " ");
		}
		// System.out.println("\n--------");
		// 結果出力
		System.out.println(right[1]);
		for(int i = 1; i < N - 1; i++) {
			System.out.println(Math.max(left[i - 1], right[i + 1]));
		}
		System.out.println(left[N - 2]);
	}
}	


Measured memory_bytes: 98740
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;
import java.util.Set;
import java.util.TreeSet;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int areaNum = sc.nextInt();
		int cityNum = sc.nextInt();
		
		List<Set<City>> l = new ArrayList<Set<City>>();
		
		for(int i = 0; i < areaNum; i++) {
			l.add(new TreeSet<City>(new Comparator<City>(){  
				 public int compare(City c1, City c2) {           
				        return c1.getTime()-c2.getTime();//降序排列  
				    } 
			}));
		}
		
		for(int i = 0; i < cityNum; i++) {
			int area = sc.nextInt();
			int time = sc.nextInt();
			l.get(area-1).add(new City(area-1, time, i));
		}
		
		Set<City> result = new TreeSet<City>(new Comparator<City>(){  
			 public int compare(City c1, City c2) {           
			        return c1.getOrder()-c2.getOrder();//降序排列  
			    } 
		});
		
		for(int i = 0; i < areaNum; i++){
			int j = 1;
//			if(l.get(i).size())
			for(Object c : l.get(i)){
				City c1 = (City)c;
				c1.setCode(formatNum(c1.getArea()+1, j));
				j++;
				result.add(c1);
			}
		}
		
		for(City c : result) {
			System.out.println(c.getCode());
		}
		
	}
	
	 
	
	private static String formatNum(int area, int order){
		String areaC = String.format("%06d", area);
		String timeC = String.format("%06d", order);
		return areaC+timeC;
	}
	
	static class City {
		private int time;
		private int area;
		private int order;
		private String code;
		public City( int area, int time, int order) {
			super();
			this.time = time;
			this.area = area;
			this.order = order;
		}
		
		
		
		public int getTime() {
			return time;
		}
		public void setTime(int time) {
			this.time = time;
		}
		public int getArea() {
			return area;
		}
		public void setArea(int area) {
			this.area = area;
		}
		public int getOrder() {
			return order;
		}
		public void setOrder(int order) {
			this.order = order;
		}
		
		public String getCode() {
			return code;
		}
		public void setCode(String code) {
			this.code = code;
		}
		
	}
}

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

ll a,b,k;
void input(){
    cin>>a>>b>>k;
}

void src(){
    cout<<((a>k)?a-k:0)<<"\n";
    ll c;
    if(k>=a){
        c = k-a;
    }else{
        c = 0;
    }
    cout<<((b>c)?b-c:0)<<"\n";

    return;
}

int main(int argc,char* argv[]){
    //ifstream in( argv[1] ); cin.rdbuf(in.rdbuf());
    input();
    src();    
    return 0;
}

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

typedef long long LL;

const int maxn = 2e5+7;
const int inf  = 2e9;
const int mod  = 1e9+7;

int dis[maxn],head[maxn];
bool vis[maxn];
int n,cnt=0,cnt_Fen=0,cnt_Su=0;
struct s
{
    int u;
    int v;
    int next;
}edge[maxn];
void add(int u,int v)
{
    edge[cnt].u=u;
    edge[cnt].v=v;
    edge[cnt].next=head[u];
    head[u]=cnt++;
}
void dfs_Fen(int pos,int len)
{
    dis[pos]=len;
    for(int i=head[pos];i!=-1;i=edge[i].next)
        if(!vis[edge[i].v])
        {
            vis[edge[i].v]=true;
            dfs_Fen(edge[i].v,len+1);
        }
}
void dfs_Su(int pos,int len)
{
   if(len<dis[pos]) 
       cnt_Su++;
   else 
       cnt_Fen++;
   for(int i=head[pos];i!=-1;i=edge[i].next)
       if(!vis[edge[i].v])
       {
           vis[edge[i].v]=true;
           dfs_Su(edge[i].v,len+1);
       }
}
int main()
{
#ifdef LOCAL
    freopen("sample.in","r",stdin);
    //freopen("nico.out","w",stdout);
#endif
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    memset(head,-1,sizeof(head));
    memset(vis,false,sizeof(vis));
    memset(dis,0,sizeof(dis));
    for(int i=1;i<n;i++)
    {
        int a,b;
        cin>>a>>b;
        add(a,b);
        add(b,a);
    }
    vis[1]=true;
    dfs_Fen(1,0);
    memset(vis,false,sizeof(vis));
    vis[n]=true;
    dfs_Su(n,0);
    //cout<<cnt_Su<<endl<<cnt_Fen<<endl;
    if(cnt_Su<cnt_Fen)
        cout<<"Fennec"<<endl;
    else 
        cout<<"Snuke"<<endl;
    return 0;
}




Measured memory_bytes: 7552
N, M = map(int,input().split())
AB = [list(map(int,input().split())) for _ in range(N)]
AB.sort()

ans = 0
for i in range(N):
  #まだ足りないケース
  if M > AB[i][1]:
    ans += AB[i][0] * AB[i][1]
    M -= AB[i][1]
  else:
    ans += AB[i][0] * M
    break
print(ans)

Measured memory_bytes: 27756
#include <iostream>
#include <string>

using namespace std;

int
main(int argc, const char *argv[])
{
    string s, p;
    cin >> s >> p;
    auto s_len = s.size();
    s = s + s;
    bool find = false;
    for (decltype(s_len) i = 0; i != s_len; ++i) {
        string sub_str = s.substr(i, p.size()); 
        if (sub_str == p) find = true;
    }
    if (find) cout << "Yes";
    else cout << "No";
    cout << endl;

    return 0;
}

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

#define int long long

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

signed main()
{
    int i=0, j=0, k=0, ans=0;
    double r;
    cin>>r;

    cout<<r*3.1415*2<<endl;

    return 0;
}

Measured memory_bytes: 3772
#include <stdio.h>
#include <stdlib.h>
int main()
{
 int n;
 int a,b,ans = 0;
 scanf("%d",&n);
 int r[n];
 for(int i = 0;i < n;i++)
  r[i] = 0;
 int ar[n];
 for(int i = 0;i < n;i++)
  scanf("%d",&ar[i]);
 for(int T = 0;T < n;T++)
 {
  a = 0;
  b = 0;
  for(int i = 0;i < n;i++)
  {
   if(i <= T)
    a += ar[i];
   else
    b += ar[i];
  }
  r[T] = abs(a - b);
 }
 ans = r[0];
 for(int i = 0;i < n;i++)
  if(ans > r[i])
   ans = r[i];
 printf("%d\n",ans);
}

Measured memory_bytes: 128
/*Bismillahir Rahmanir Rahim*/

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

typedef long long ll;
typedef vector<int> vi;
typedef vector <long long> vll;
typedef pair<int, int> pii;
///*-*-*-*-*-*-*-*-*-*-*-*-*-*-Macro Start-*-*-*-*-*-*-*--*-*-*-*-*/

#define Faster_IO              ios_base::sync_with_stdio(false); cin.tie(NULL);
#define F                      first
#define S                      second
#define pb                     push_back
#define MP                     make_pair
#define sf                     scanf
#define pf                     printf
#define PI                     (2*acos(0))
#define to_radian(degree)      ((pi/180)*degree)
#define to_degree(radian)      ((180/pi)*radian)
#define SQ(a)                  (a)*(a)
#define SORT(x)                sort(x.begin(),x.end())
#define rSORT(x)               sort(x.rbegin(),x.rend())
#define SetPrint(a,x)          cout<<fixed<<setprecision(x)<<a<<endl
#define show(vec)              for (int i=0; i<vec.size(); i++)cout << vec[i] << " ";
#define lines                  cout <<"\n" <<"---------------" << "\n";
#define YES                    printf("YES\n")
#define NO                     printf("NO\n")
#define Yes                    printf("Yes\n")
#define No                     printf("No\n")
#define testcase(n)            int n; cin >> n; while(n--)
#define lcm(a,b)               ((a / __gcd(a,b) ) * b)
#define gcd(a,b)               __gcd(a,b)
#define all(vec)               vec.begin(), vec.end()
#define SUM(vec)               accumulate(vec.begin(), vec.end(), 0)
#define gcin(str)              getline(cin, str)
///*-*-*-*-*-*-*-*-*-*-*-*-*-*-Macro END-*-*-*-*-*-*-*--*-*-*-*-*/

///*-*-*-*-*-*-*-*-*-*-*-*-*-*-Template Start-*-*-*-*-*-*--*-*-*-*-*/

//template <class T> T isPrime(T n){if(n<=1)return 0;for(long long i=2;i*i<=n; i++)if(n%i==0)return 0;return 1;}
//template <class T> T bigmod(T X, T n, T M) {if (n==0) return 1;if (n%2) return ((X%M) * bigmod(X,n-1,M)) %M;else {long long int d = bigmod(X,n/2, M);return ((d%M) * (d%M))%M;}}

///*-*-*-*-*-*-*-*-*-*-*-*-*-*-Template END-*-*-*-*-*-*-*--*-*-*-*-*/


int main()
{
    Faster_IO
    #ifndef ONLINE_JUDGE
    freopen("Input.txt", "r", stdin);
    freopen("Output.txt", "w", stdout);
    #endif

    int a;
    cin >> a;
    cout << a + (a*a) + (a*a*a) << "\n";
    
    return 0;
}


Measured memory_bytes: 3620
// AtCoder template
// sabaより胡蝶しのぶさんの方が可愛いのではないか？
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i = 0; i < n; ++i)

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

    string s; cin >> s;
    int n = s.size();
    vector<int> ans(n,0);
    int odd = 0,even = 0;

    rep(i,n){
        if(s[i] == 'R'){
            if(i%2) odd++;
            else even++;
        }else{
            if(i%2){
                ans[i-1] += even;
                ans[i] += odd;
            }else{
                ans[i-1] += odd;
                ans[i] += even;
            }
            odd = even = 0;
        }
    }

    rep(i,n){
        if(s[n-i-1] == 'L'){
            if((n-i-1)%2) odd++;
            else even++;
        }else{
            if((n-i-1)%2){
                ans[n-i] += even;
                ans[n-i-1] += odd;
            }else{
                ans[n-i] += odd;
                ans[n-i-1] += even;
            }
            odd = even = 0;
        }
    }
    rep(i,n) cout << ans[i] << " ";
}

Measured memory_bytes: 1104
#include<bits/stdc++.h>
#define MOD 1000000007
using namespace std;
main()
{
	int n;
	cin>>n;
	
	vector<pair<long long,long long>> v(n);
	
	for(long long i=0;i<n;i++)
	cin>>v[i].first>>v[i].second;
	
	long long x0=v[0].first,y0=v[0].second;
	
	for(long long i=1;i<n;i++)
	{
		long long x,y;
		long long st,st1=x0/v[i].first+1,st2=y0/v[i].second+1;
		
		if(x0%v[i].first==0)
		st1--;
		
		if(y0%v[i].second==0)
		st2--;
		
		st=max(st1,st2);
		
		x0=st*v[i].first;y0=st*v[i].second;
		
		/*for(int j=st;;j++)
		{
			x=v[i].first*j;y=v[i].second*j;
			if(x>=x0 && y>=y0)
			break;
		}*/
		
		//x0=x;y0=y;
		
		//cout<<x0<<" "<<y0<<endl;
	}
	
	cout<<x0+y0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
long long n,t,g,ans;
long long a[100007];

inline int read()
{
	int m=0,s=0;
	char ch=getchar();
	while(!isdigit(ch)) m|=ch=='-',ch=getchar();
	while(isdigit(ch)) s=(s*10)+(ch^48),ch=getchar();
	return m? -s:s;
}

int main()
{
	n=read();
	for(int i=1;i<=n;i++) a[i]=read();
	sort(a+1,a+1+n);
	t=a[1];g=1;
	for(int i=2;i<=n;i++)
	{
		if(a[i]==t) g++;
		if(a[i]!=t)
		{
			if(g>=t) ans+=g-t;
			else ans+=g;
			t=a[i];g=1;
		}
	}
	if(g>=t) ans+=g-t;
	else ans+=g;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1024
import Foundation

func readInt() -> Int {
    return Int(readLine()!)!
}

func readInts(separator: String.Element = " ") -> [Int] {
    return readLine()!.split(separator: separator).map { Int($0)! }
}

func readThreeInts(separator: String.Element = " ") -> (a: Int, b: Int, c: Int) {
    let ints = readLine()!.split(separator: separator).map { Int($0)! }
    return (a: ints[0], b: ints[1], c: ints[2])
}

func mainB() {
    let (A, B, C) = readThreeInts()
    let K = readInt()

    for k in 0...K {
        for i in 0...k {
            let Bd = B * Int(pow(2.0, Double(k - i)))
            let Cd = C * Int(pow(2.0, Double(i)))

            if A < Bd, Bd < Cd {
                print("Yes")
                return
            }
        }
    }

    print("No")
}

mainB()

Measured memory_bytes: 13720
def main():
    n = int(input())
    s = [int(input()) for _ in range(n)]
      
    ans = sum(s)
    if ans % 10 != 0:
        print(ans)
    else:
        a = 10**9
        for ss in s:
            if ss % 10 != 0:
                a = min(a, ss)
        if a!=10**9:
            print(ans - a)
        else:
            print(0)
    
if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
n=int(input())
p=tuple(map(int,input().split()))
q=tuple(map(int,input().split()))
import itertools
seq=tuple([i+1 for i in range(n)])
i=0
for j in itertools.permutations(seq):
  if p==j:
    x=i
  if q==j:
    y=i
  i+=1
print(abs(x-y))


Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;
#define ll long long

int main() {
    int d;
    cin >> d;
    vector<vector<int>> s(d+1, vector<int>(26+1, 0));
    vector<int> c(26+1);
    for(int i = 0; i < 26; i++) cin >> c[i];
    for(int i = 0; i < d; i++) {
        for(int j = 0; j < 26; j++) {
            cin >> s[i][j];
        }
    }
    /////////////////
    vector<int> t(d);
    for(int i = 0; i < d; i++) cin >> t[i];
    vector<ll> ans(d, 0);
    vector<ll> last(26+1, 0);
    ll v = 0;
    ll tmp = 0;
    for(int i = 0; i < d; i++) {
        v += s[i][t[i]-1];
        last[t[i]-1] = i+1;
        for(int j = 0; j < i; j++) {
            //t[i]-1
            /*
            if(last[t[i]-1] == 0) {
                ans[i] += s[i][t[i]-1];
                last[t[i]-1] = ans[i];
            }
            */
            //ans[i] += s[i][t[i]-1];
            //v += s[i][t[i]-1];
            //last[t[i]-1] = ans[i];
            //last[t[i]-1] = v;
            //cout << j << endl;
        }
        //down
        for(int j = 0; j < 26; j++) {
            //ans[i] -= c[j]*((i+1)-last[j]);
            v -= c[j]*((i+1)-last[j]);
        }
        cout << v << endl;
    }
    /*
    for(int i = 0; i < d; i++) {
        cout << ans[i] << endl;
    }
    */
    return 0;
}

Measured memory_bytes: 3688
# coding: utf-8
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DPL_1_B&lang=jp "Combinatorial - 0-1 Knapsack Problem"
#
# 30????????????
#

n, w = gets.split(" ").map(&:to_i)
goods = Array.new(n+1)
for i in 1..n
  goods[i] = gets.split(" ").map(&:to_i)
end

max = 0

v = Array.new(n+1)
for j in 0..n
  v[j] = Array.new(w+1,0)
end

#v = Array.new(n+1,Array.new(w+1))
#p v
#for i in 1..n
#  v[i][0] = 0
#end
#p v
#for c in 1..w
#  v[0][c] = 0
#end
#p v
#v[0][0] = 0

for i in 1..n
  for c in 1..w
    if c - goods[i][1] < 0
      v[i][c] = v[i-1][c]
    else
      v[i][c] = [v[i-1][c], v[i-1][c-goods[i][1]]+goods[i][0]].max
    end
    #p v
    max = [max, v[i][c]].max
  end
end

puts max

Measured memory_bytes: 16664
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<iostream>
using namespace std;

const int N=1010;
const int M=2010<<2;
const long long oo=(long long)1<<60;
int st[N], b[M], nex[M];
int tot, n, m, i, j, x, y, z;
bool g[N];
int q[N * M], ss[N];
long long d[N], c[M];

void add(int x, int y, int z)
{
    b[++tot] = y;
    c[tot] = z;
    nex[tot] = st[x];
    st[x] = tot;
}

void spfa(int start)
{
    int t=0,h;
	for (i=1;i<=n;i++) d[i]=-oo;
	q[++t]=start,h=d[start]=0,g[start]=true;
	ss[1] = 0;
	while (h < t)
	{
		h++,x=q[h],g[x]=false;
		for (j=st[x];j;j=nex[j])
		{
			if (d[x]+c[j]>d[b[j]])
			{
				d[b[j]]=d[x]+c[j];
				if (!g[b[j]]) t++,q[t]=b[j],g[b[j]]=true;
				ss[t] = ss[h] + 1;
				if (ss[t] > n)
				{
				     if (b[j] == n)
				     {
				         d[n] = -oo;
				         return;
                     }
                     if (ss[t] > 2 * n) t--;
                }
			}
		}
	}
}

int main()
{
    scanf("%d%d", &n, &m);
    d[1] = 0;
    for (i = 1; i <= m; i++)
    {
        scanf("%d%d%d", &x, &y, &z);
        add(x, y, z);
    }
    spfa(1);
    if (d[n] > -oo) cout<<d[n]<<endl;
            else puts("inf");
    return 0;
}

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

namespace _0195
{
    public class Program

    {
        public static void Main(string[] args)
        {
            while (true)
            {
                int[] sales = new int[5];
                for (int i = 0 ; i < 5 ; i++)
                {
                    int[] items = RIntAr(); if (items.Sum() == 0) return;
                    sales[i] = items.Sum();
                }

                var res = sales.Select((x, i) => new { cnt = x, idx = i }).OrderByDescending(y => y.cnt).First();
                Console.WriteLine("{0} {1}", (char)(res.idx + 'A'), res.cnt);
            }
        }

        static string RSt() { return Console.ReadLine(); }
        static int RInt() { return int.Parse(Console.ReadLine().Trim()); }
        static long RLong() { return long.Parse(Console.ReadLine().Trim()); }
        static double RDouble() { return double.Parse(Console.ReadLine()); }
        static string[] RStAr(char sep = ' ') { return Console.ReadLine().Trim().Split(sep); }
        static int[] RIntAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => int.Parse(e)); }
        static long[] RLongAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => long.Parse(e)); }
        static double[] RDoubleAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => double.Parse(e)); }
        static string WAr<T>(IEnumerable<T> array, string sep = " ") { return string.Join(sep, array.Select(x => x.ToString()).ToArray()); }
    }

}



Measured memory_bytes: 14504
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     @hamayanhamayan0
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/














int N;
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> N;
	int ans = (10000 - N) % 1000;
	cout << ans << endl;
}







Measured memory_bytes: 3632
#include <stdio.h>
#include<math.h>
int main(void){
    int d,l,count=0,i;
    scanf("%d %d",&d,&l);
    if(d<l){
        printf("%d\n",d);
         
    }
    if(d>=l){
        for(i=1;i<=100000;i++){
        
        
            d=d-l;
        
            count++;
            if(d<l){
                count+=d;
                break;
            }
        
    
        
        }
        printf("%d\n",count);
    }
}



Measured memory_bytes: 2112