akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define ll long long
#define read(x) scanf("%d",&x);
#define readll(x) cin>>x;
#define FOR(x,a,b) for(int x=a;x<b;x++)
#define MP make_pair
#define PB push_back
#define pii pair<int,int>
#define readN(N,X) for(int i=0;i<N;i++) cin>>X[i];
#define pff pair<double,double>
using namespace std;

long long fastpow(int a, int b, int MOD)
{
    long long x=1,y=a; 
    while(b > 0)
    {
        if(b%2 == 1)
        {
            x=(x*y) % MOD;
        }
        y = (y*y) % MOD;
        b /= 2;
    }
    return x;
}

long long InverseEuler(int n, int MOD)
{
    return fastpow(n,MOD-2,MOD);
}
 
long long f[300000];
bool init;
long long C(int n, int r, int MOD)
{
    if (!init){
        init=1;
        f[0]=1;
        for (int i=1; i<300000;i++)
            f[i]= (f[i-1]*i) % MOD;
        
    }
    return (f[n]*((InverseEuler(f[r], MOD) * InverseEuler(f[n-r], MOD)) % MOD)) % MOD;
}


int N;
int Q;
int A,B;
int X;
vector<pair<int,int> > kagi2,cp;
deque<pair<int,int> > kagi;
int a[100005];
int mulai[100005];
int ans[100005];
bool kiri[100005];
bool kanan[100005];
int main(){
   std::ios::sync_with_stdio(false); 

   cin>>X;
   cin>>N;

   readN(N,a);
   for (int i=0;i<N;i++){
    cp.push_back({a[i],-1});
   }
   cin>>Q;

   for (int i=0;i<Q;i++){
        int t,s;
        cin>>t>>s;
        mulai[i] = s;
        cp.push_back({t,i});
        kagi2.push_back({s,i});
   }
   sort(kagi2.begin(), kagi2.end());
   for (int i=0;i<Q;i++)
    kagi.push_back(kagi2[i]);
   sort(cp.begin(), cp.end());

   int lt = 0;
   int dir = -1;
   int ansKir = 0;
   int ansKan = X;
   int shift = 0;
   for (int i=0;i<cp.size();i++){
    int t = cp[i].first;
    int tipe = cp[i].second;
    
    //geser
    int dur = t - lt;
    lt = t;
    shift += (dir)*dur;
    ansKir += (dir)*dur;
    ansKan += (dir)* dur;
    ansKir = max(0, ansKir);
    ansKan = max(0, ansKan);
    ansKir = min(X, ansKir);
    ansKan = min(X, ansKan);
    if (tipe == -1) dir*=-1;
   // cout<<ansKir<<" "<<ansKan<<endl;
    while (kagi.size() && kagi.front().first <= -shift){
        kiri[kagi.front().second] = 1;
        //cout<<kagi.front().second<<" nabrak kiri"<<endl;
        kagi.pop_front();
    }
    while(kagi.size() && kagi.back().first >= X - shift){
        kanan[kagi.back().second] = 1;

        //cout<<kagi.back().second<<" nabrak kanan"<<endl;
        kagi.pop_back();
    }

    if (tipe != -1){
        if (kiri[tipe])
            ans[tipe] = ansKir;
        else if (kanan[tipe])
            ans[tipe] = ansKan;
        else
            ans[tipe] = mulai[tipe] + shift;
    }

   }

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


Measured memory_bytes: 6000
#!/usr/bin/env python3

N = int(input())
jdg = 0

W = [0]*N
for i in range(N):
    W[i] = input()

if len(set(W)) != len(W):
    jdg += 1
for i in range(1,N):
    if W[i][0] != W[i-1][-1]:
        jdg += 1
if jdg == 0:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 38256
#include <bits/stdc++.h>
typedef long long ll;
#define INF 1000000000
#define MOD 1000000007
int dx[4]={1,0,-1,0},dy[4]={0,-1,0,1};
using namespace std;
int main(void){
int n;
cin>>n;
int a[n];
int sum=0;
for(int i=0;i<n;i++){
    cin>>a[i];
    sum+=a[i]-1;
}
cout<<sum<<endl;
 return 0;   
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
        
int main(){
  int N;
  cin >> N;
  bool a=false;
  for(int i=0;i<9;i++){
    for(int j=0;j<9;j++){
      int A=(i+1)*(j+1);
      if(A==N){
        a=true;
      }
    }
  }
  if(a){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3548
#include <bits/stdc++.h>
#define int long long
using namespace std;
long long maxi[100005];
signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n;
	cin>>n;
	vector<int>v;
	for(int i=0;i<=n;i++){
		int x;
		cin>>x;
		v.push_back(x);
	}
	maxi[0]=1;
	long long INF=1e16;
	for(int i=1;i<=n;i++){
		maxi[i]=min(2*(maxi[i-1]-v[i-1]), INF);
		//cout<<maxi[i]<<endl;
	}
	long long sum=v[n], cur=v[n];
	if(v[n]==0 || v[n]>maxi[n]){
		cout<<-1;
		return 0;
	}
	for(int i=n-1;i>=0;i--){
		int las=cur;
		cur=min(maxi[i], cur+v[i]);
		if(cur<=0 || cur<v[i]){
			cout<<-1;
			return 0;
		}
		if(2*(cur-v[i])<las){
			cout<<-1;
			return 0;
		}
		sum+=cur;
		//cout<<cur<<endl;
	}
	cout<<sum;
}


Measured memory_bytes: 4800
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>
#include <stack>
#include<set>
#include<math.h>

#define DIV 1000000007
using namespace std;
using ll = long long;

int main(void) {
	int X, Y, Z, K;
	cin >> X >> Y >> Z >> K;

	vector<ll> A(X);
	for (int i = 0; i < X; i++)
		cin >> A[i];
	sort(A.begin(), A.end(), greater<ll>());

	vector<ll> B(Y);
	for (int i = 0; i < Y; i++)
		cin >> B[i];
	sort(B.begin(), B.end(), greater<ll>());

	vector<ll> C(Z);
	for (int i = 0; i < Z; i++)
		cin >> C[i];
	sort(C.begin(), C.end(), greater<ll>());

	vector<vector<vector<bool>>> visit(X + 1, vector<vector<bool>>(Y + 1, vector<bool>(Z+1)));
	pair<ll, vector<int>> cake;
	priority_queue<pair<ll, vector<int>>> pq;
	cake.first = A[0] + B[0] + C[0], cake.second.push_back(0), cake.second.push_back(0), cake.second.push_back(0);
	pq.emplace(cake);
	int cnt = 0;
	while (cnt < K) {
		pair<ll, vector<int>> tp = pq.top();
		pq.pop();
		int a = tp.second[0];
		int b = tp.second[1];
		int c = tp.second[2];
		visit[a][b][c] = true;
		//cout << a << " " << b << " " << c << " ";
		cout << tp.first << endl;
		cnt++;

		if (a + 1 < X) {
			if (!visit[a + 1][b][c]) {
				visit[a + 1][b][c] = true;
				pair<ll, vector<int>> nt;
				nt.first = tp.first - A[a] + A[a + 1];
				nt.second.push_back(a + 1);
				nt.second.push_back(b);
				nt.second.push_back(c);
				pq.push(nt);
			}
		}
		if (b + 1 < Y) {
			if (!visit[a][b + 1][c]) {
				visit[a][b+1][c] = true;
				pair<ll, vector<int>> nt;
				nt.first = tp.first - B[b] + B[b + 1];
				nt.second.push_back(a);
				nt.second.push_back(b + 1);
				nt.second.push_back(c);
				pq.push(nt);
			}
		}
		if (c + 1 < Z) {
			if (!visit[a][b][c + 1]) {
				visit[a][b][c + 1] = true;
				pair<ll, vector<int>> nt;
				nt.first = tp.first - C[c] + C[c + 1];
				nt.second.push_back(a);
				nt.second.push_back(b);
				nt.second.push_back(c + 1);
				pq.push(nt);
			}
		}

	}

}


Measured memory_bytes: 180864
people = {}
n = int(input())

for _ in range(n):
	b, f, r, v = map(int, input().split())

	people.setdefault(b, {})
	people[b].setdefault(f, {})
	people[b][f].setdefault(r, 0)

	people[b][f][r] += v

for b in range(1, 5):
	for f in range(1, 4):
		for r in range(1, 11):
			if people.get(b):
				if people[b].get(f):
					p = people[b][f][r] if people[b][f].get(r) else 0
				else:
					p = 0
			else:
				p = 0

			print(' {}'.format(p), end='')
		print('\n', end='')
	if b < 4:
		print('#' * 20)



Measured memory_bytes: 5620
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
 
ll min(ll a,ll b){
    if(a<b)return a;
    else return b;
}
ll max(ll a,ll b){
    if(a>b)return a;
    else return b;
}
 
int main() {
    ll n,k;cin>>n>>k;
    ll a[n];
    ll i;
    ll x;
    x=1000000007;
    for(i=0;i<n;i++)cin>>a[i];
    ll dp[n][k+1];
    for(i=0;i<=k;i++){
        if(i<=a[0]) dp[0][i]=1;
        else dp[0][i]=0;
    }
    ll j;
    for(i=1;i<n;i++){
        for(j=0;j<=k;j++){
            if(j==0){
                dp[i][j]=1;
            }else if(j<=a[i]){
                dp[i][j]=(dp[i][j-1]+dp[i-1][j])%x;
            }else{
                dp[i][j]=(dp[i][j-1]+dp[i-1][j]-dp[i-1][j-a[i]-1])%x;
            }
        }
    }
    cout<<(dp[n-1][k]+x)%x<<endl;
    return 0;
}

Measured memory_bytes: 78336
N,M = map(int,input().split())
tmpX =list(input().split())
X = [int(s) for s in tmpX]
X.sort()
X_difference=[]
for i in range(M-1):
    X_difference.append(X[i+1]-X[i])

X_difference.sort(reverse = True)
del X_difference[0:N-1:]
print(sum(X_difference))

Measured memory_bytes: 14864
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int n;
    cin >> n;
    vector<int> retu(n);
    vector<int> han(n);
    for (int i = 0; i < n; i++) {
        cin >> retu.at(i);
        han.at(i) = retu.at(i);
    }
    int a, b;
    sort(han.begin(), han.end());
    a = han.at(n - 1);
    b = han.at(n - 2);
    for(int i = 0; i < n; i++) {
        if(retu.at(i) != a) {
            cout << a << endl;
        } else {
            cout << b << endl;
        }
    }
}

Measured memory_bytes: 3200
#include<bits/stdc++.h>
using namespace std;
int main()
{
 long long int n,i,x;
  cin>>n;
 long long int a[n],sum=0;
  vector<long long int>b;
  for( i=0;i<n;i++)
  {
    cin>>a[i];
  }
  sum=a[0];
  for(i=1;i<n;i++)
  {
    sum=sum^a[i];
  }
  for(i=0;i<n;i++)
  {
    x=sum^a[i];
    b.push_back(x);
  }
  for(i=0;i<b.size();i++)
  {
    cout<<b[i]<<" ";
  }
}

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<string> vs;
typedef pair<int, int> P;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

void YN(bool flg){if(flg) cout << "YES" << endl; else cout << "NO" << endl;}
void Yn(bool flg){if(flg) cout << "Yes" << endl; else cout << "No" << endl;}
void yn(bool flg){if(flg) cout << "yes" << endl; else cout << "no" << endl;}

int main()
{
    ll n;
    cin >> n;
    string ans;
    while(n) {
        --n;
        ans += ((n)%26)+'a';
        n/=26;
    }
    reverse(all(ans));
    cout << ans << endl;

    return 0;
}


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

const int MAX_V = 1001;
const int MAX_E = 2001;
const long long INF = 1e18;

struct edge{
    int from, to;
    long long cost;
};

edge es[MAX_E];

long long d[MAX_V];
int V, E;
bool update;
bool negative[MAX_V];

void bellmanford(int s){
    for(int i = 1; i <= V; i++) d[i] = INF;
    d[s] = 0;
    for(int j = 0; j < V-1; j++){
        update = false;
        for(int i = 0; i < E; i++){
            edge e = es[i];
            if(d[e.from] != INF && d[e.to] > d[e.from] + e.cost){
                d[e.to] = d[e.from] + e.cost;
                update = true;
            }
        }
        if(!update) break;
    }
    for(int j = 0; j < V; j++){
        for(int i = 0; i < E; i++){
            edge e = es[i];
            if(d[e.from] == INF) continue;
            if(d[e.to] > d[e.from] + e.cost){
                d[e.to] = d[e.from] + e.cost;
                negative[e.to] = true;
            }
            if(negative[e.from]) negative[e.to] = true;
        }
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> V >> E;
    for(int i = 0; i < E; i++){
        int from, to;
        long long cost;
        cin >> from >> to >> cost;
        es[i] = edge{from, to, -cost};
    }
    bellmanford(1);
    if(negative[V]) cout << "inf" << endl;
    else cout << -d[V] << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll n,big=0;
multiset<int> s;
int main(){
	cin>>n;
	for(int i=1;i<=(1<<n);i++){
		ll e;
		cin>>e;
		s.insert(e);
		big=max(big,e);
	}
	vector<int> t;
	t.push_back(big);
	s.erase(s.find(big));
	for(int i=0;i<n;i++){
		vector<int> ut;
		for(ll e:t){
			auto itr=s.lower_bound(e);
			if(itr==s.begin()){
				cout<<"No"<<endl;
				return 0;
			}
			itr--;
			ut.push_back(*itr);
			s.erase(itr);
		} 
		for(ll e:ut){
			t.push_back(e);
		}
	}
	cout<<"Yes"<<endl;
	return 0;
}

Measured memory_bytes: 13884
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(long long)(n);i++)
#define all(a) a.begin(), a.end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
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; }
 
const ll MOD=1e9+7;
const ll INF=1e18;
const int MAX=510000;
const double pi=acos(-1);
int dx[8] = {1,0,-1,0,1,1,-1,-1};
int dy[8] = {0,1,0,-1,-1,1,1,-1};
// int d[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};



int main(){
  cin.tie(0);
  ios::sync_with_stdio(false); 
  
  ll n;
  cin >> n;
  vector<ll>a(n);
  rep(i,n) cin >> a[i];
  sort(a.begin(),a.end());
  ll ans=1;
  if(a[0]==0){
    cout << 0 << endl;
    return 0;
  }
  rep(i,n){
    if(a[i]<=INF/ans){
      ans*=a[i];
    }
    else{
      cout << -1 << endl;
      return 0;
    }
    if(ans>INF){
      cout << -1 << endl;
      return 0;
    }
  }
  
  cout << ans << endl;
    
  return 0;
}


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

int main()
{
  long int N;
  cin >> N;
  
  if(N%11==0)
    cout << 2*(N/11);
    
  else if(N%11< 7)
     cout << 2*(N/11) +1;
  
  else if (N%11 > 6)
    cout << 2*(N/11) +2;
}
    

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mod 1000000007
#define lim 1000000000000000007
#define lim1 18446744073709551615  //Unsigned
#define sq(a) ((a)*(a))
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define mms(v,i) memset(v,i,sizeof(v))
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define REP(i,a,b) for (int i = a; i <= b; i++)
#define REPN(i,a,b) for (int i = a; i >= b; i--)
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int,int> pi;
typedef pair<ll,ll> PL;
typedef pair<ll,int> PLI;
typedef pair<int,ll> PIL;
typedef pair<int,pair<int,int> > pii;
typedef pair<double,double> pdd;
ll power(ll a,ll b) {
    if (b==0) return 1;
    ll c = power(a,b>>1);
    c = (c*c)%mod;
    if (b&1) return (c*a)%mod;
    return c;
}
ll gcdll(ll a,ll b) {
    if (b==0) return a;
    return gcdll(b,a%b);
}
int gcd(int a,int b) {
    if (b==0) return a;
    return gcd(b,a%b);
}
const int N = (int)1e5+5;
const int Q = 301;

void solve() {
    ll a,b;
  	cin>>a>>b;
  	cout<<((a*b)/gcdll(a,b));
}
int main() {
    //freopen("class_treasurer.txt","r",stdin);
    //freopen("output.txt","w",stdout);

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

    int T=1;
    //cin>>T;
    REP(TC,1,T) {
        //cout<<"Case #"<<TC<<": ";
        solve();
        cout<<"\n";
    }
}


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

int cal(int a, int b){
    if(a > b){ return a - b; }
    else if(a < b){ return b - a; }
    else return 0;
}

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

    int ret = 100000;
    int tmp = cal(a[0], a[1]) + cal(a[1], a[2]);
    if(ret > tmp) ret = tmp;
    tmp = cal(a[0], a[2]) + cal(a[2], a[1]);
    if(ret > tmp) ret = tmp;
    tmp = cal(a[1], a[0]) + cal(a[0], a[2]);
    if(ret > tmp) ret = tmp;
    tmp = cal(a[1], a[2]) + cal(a[2], a[0]);
    if(ret > tmp) ret = tmp;
    tmp = cal(a[2], a[0]) + cal(a[0], a[1]);
    if(ret > tmp) ret = tmp;
    tmp = cal(a[2], a[1]) + cal(a[1], a[0]);
    if(ret > tmp) ret = tmp;

    cout << ret << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()   //reverse
#define strall(v) (v).cbegin(),(v).cend() //const_itterator
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template<typename t, typename u, typename Comp=less<>>
bool chmax(t& xmax, const u& x, Comp comp={}) { if(comp(xmax, x)) { xmax = x; return true; } return false;}
template<typename t, typename u, typename Comp=less<>>
bool chmin(t& xmin, const u& x, Comp comp={}) { if(comp(x, xmin)) { xmin = x; return true;} return false;}
const int INF = 1e8;
const ll infl = 1LL << 60;

struct UnionFind{
  vector<int> d;
  UnionFind(int n=0):d(n,-1){}
  int find(int x){
    if(d[x] < 0) return x;
    return d[x] = find(d[x]);
  }
  bool unite(int x,int y){
    x = find(x); y = find(y);
    if(x == y) return false;
    if(d[x] > d[y]) swap(x,y);
    d[x] += d[y];
    d[y] = x;
    return true;
  }
  bool same(int x,int y){ return find(x) == find(y);}
  int size(int x) {return -d[find(x)];}
};

int main(){
  int N,K,L; cin >> N >> K >> L;
  UnionFind uf1(N);
  UnionFind uf2(N);

  vector<int> ans(N,0);
  map<pair<int,int>,int> ma;
  rep(i,K){ 
    int p,q;
    cin >> p >> q;p--,q--;
    uf1.unite(p,q);
  }
  rep(i,L){
    int r,s;
    cin >> r >> s;r--,s--;
    uf2.unite(r,s);
  }
  rep(i,N){
    ma[{uf1.find(i),uf2.find(i)}]++;
  }

  rep(i,N){
    int j1,j2;
    j1 = uf1.find(i);j2 = uf2.find(i);
    cout << ma[{j1,j2}] << endl;
  }
  
}

Measured memory_bytes: 14336
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <climits>
#include <cmath>
#include <set>
#include <vector>
using namespace std;
const int maxn=100+5;
int n;
int a[maxn];

void print()
{
    for(int i=0;i<n;i++)
    {
        if(i) printf(" ");
        printf("%d",a[i]);
    }
    printf("\n");
}
void insert_sort()
{
    for(int i=0;i<n;i++)
    {
        int k=a[i];
        int j=i-1;
        while(j>=0&&a[j]>k)
        {
            a[j+1]=a[j];
            j--;
        }
        a[j+1]=k;
        print();
    }
}
int main()
{
//    freopen("in.txt","r",stdin);
    scanf("%d",&n);
    for(int i=0;i<n;i++) scanf("%d",&a[i]);
    insert_sort();
    return 0;
}

Measured memory_bytes: 3208
#include <cstdio>
#include <algorithm>
using namespace std;
int x[901];
int y[901];
char row[31];

int main()
{
    int H, W, idx = 0, maxd = 0;
    scanf("%d %d", &H, &W);
    for (int i = 0; i < H; i++) {
        scanf("%s", row);
        for (int j = 0; j < W; j++) if (row[j] == 'B') { x[idx] = i; y[idx] = j; idx++; }
    }
    for (int i = 0; i < idx-1; i++) {
        for (int j = i + 1; j < idx; j++) {
            maxd = max(maxd, abs(x[j]-x[i]) + abs(y[j]-y[i]));
        }
    }
    printf("%d\n", maxd);
    return 0;
}


Measured memory_bytes: 2760
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {
	static int n;
	static long m;
	static int[] a;

	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] sa = br.readLine().split(" ");
		n = Integer.parseInt(sa[0]);
		m = Long.parseLong(sa[1]);
		sa = br.readLine().split(" ");
		a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = Integer.parseInt(sa[i]);
		}
		br.close();

		Arrays.parallelSort(a);

		long ng = 1000000000000000000L;
		long ok = 0;
		long cnt = 0;
		while (ng - ok > 1) {
			long mid = (ok + ng) / 2;
			long ret = count(mid);
			if (ret >= m) {
				ok = mid;
				cnt = ret;
			} else {
				ng = mid;
			}
		}

		long[] b = new long[n + 1];
		for (int i = 0; i < n; i++) {
			b[i + 1] = b[i] + a[i];
		}
		long ans = 0;
		for (int i = 0; i < n; i++) {
			long val2 = ok - a[i];
			int idx = binarySearch(val2 - 0.5);
			ans += (b[n] - b[idx]);
			ans += (long) a[i] * (n - idx);
		}
		ans -= ok * (cnt - m);
		System.out.println(ans);
	}

	static long count(long val) {
		long sum = 0;
		for (int i = 0; i < n; i++) {
			long val2 = val - a[i];
			int idx = binarySearch(val2 - 0.5);
			sum += n - idx;
		}
		return sum;
	}

	static int binarySearch(double val) {
		int ng = -1;
		int ok = n;

		while (ok - ng > 1) {
			int mid = (ok + ng) / 2;
			if (a[mid] >= val) {
				ok = mid;
			} else {
				ng = mid;
			}
		}
		return ok;
	}
}


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

int R,S,P;

int pt(char c){
  if(c == 'r') return P;
  else if(c == 's') return R;
  else if(c == 'p') return S;
}

int main() {
  int n,k;
  cin >> n >> k >> R >> S >> P;
  string hd;
  vector<bool> ck(k,true);
  int ans = 0;
  cin >> hd;
  for(int i=0;i<n;i++){
    if(i < k) ans += pt(hd.at(i));
    else{
      if(hd.at(i) != hd.at(i - k)){ 
        ans += pt(hd.at(i));
        ck.at(i % k) = true;
      }
      else if(!(ck.at(i % k))){
        ans += pt(hd.at(i));
        ck.at(i % k) = true;
      }
      else ck.at(i % k) = false;
    }
  }
  cout << ans << endl;        
          
}


Measured memory_bytes: 512
using System;

namespace ConsoleApp26
{
    class Program
    {
        static void Main(string[] args)
        {

            int[] Ar = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            int S = Ar[0], K = Ar[1];
            Console.WriteLine(S*K);
        }
    }
}


Measured memory_bytes: 27248
# Template 1.0
import sys, re
from collections import deque, defaultdict, Counter, OrderedDict
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, log, floor
from heapq import heappush, heappop, heapify, nlargest, nsmallest
def STR(): return list(input())
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def list2d(a, b, c): return [[c] * b for i in range(a)]
def sortListWithIndex(listOfTuples, idx):   return (sorted(listOfTuples, key=lambda x: x[idx]))
def sortDictWithVal(passedDic):
    temp = sorted(passedDic.items(), key=lambda kv: (kv[1], kv[0]))
    toret = {}
    for tup in temp:
        toret[tup[0]] = tup[1]
    return toret
def sortDictWithKey(passedDic):
    return dict(OrderedDict(sorted(passedDic.items())))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

x,y,z = MAP()

temp1 = x
x = y
y = temp1


temp2 = x
x = z
z = temp2

print(x,y,z)

Measured memory_bytes: 68416
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#define flush fflush(stdout)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pl;
const int mod = (int)1e9 + 7, INF = (int)1e9;
const int di[4] = { 1,0,-1,0 }, dj[4] = { 0,1,0,-1 };


int main(void) {
    int n, k, i, t;
    string s;
    vector<ll> ms;
    ll ans;

    cin >> s;
    scanf("%d", &k);

    n = s.size();

    t = -1;
    for (i = 0; i < n; i++) {
        if (i == 0 || s[i] != s[i - 1]) {
            ms.push_back(1);
            t++;
        }
        else {
            ms[t]++;
        }
    }

    if (t == 0) {
        printf("%lld\n", ms[0] * k / 2);
        return 0;
    }

    ans = 0;
    for (i = 1; i < t; i++) {
        ans += ms[i] / 2;
    }

    ans *= k;

    ans += ms[0] / 2 + ms[t] / 2;

    if (s[0] == s[n - 1]) {
        ans += (ms[0] + ms[t]) / 2 * (k - 1);
    }
    else {
        ans += (ms[0] / 2 + ms[t] / 2) * (k - 1);
    }

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

    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;


public class Main
{	
	static int W;
	static int N;
	static int w[];
	static int p[];
	static int test[][];

	public static void main(String[] args) throws IOException
	{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String s=br.readLine();
		
		int Case  = 1;
		do{
			if((W = Integer.parseInt(s)) == 0) break;
			N = Integer.parseInt(br.readLine());

			w = new int[N];
			p = new int[N];
			test = new int[N+1][W+1];
			for (int i = 0; i < N; i++) {
				String d = br.readLine();
				p[i] = Integer.parseInt(d.split(",")[0]);
				w[i] = Integer.parseInt(d.split(",")[1]);
			}
			int weight = theaf();
			System.out.println("Case " + Case + ":");
			System.out.println(test[N][weight]);
			System.out.println(weight);
			Case++;
		} while((s=br.readLine())!=null);
		
	}
	
	private static int theaf()
	{ 
		for (int i = 0; i < N; i++) {
			for (int j = 0; j <= W; j++) {
				if(j<w[i]){
					test[i+1][j] = test[i][j];
				} else {
					test[i+1][j] = Math.max(test[i][j], test[i][j-w[i]]+p[i]);
				}	
			}
		}
		//search for minimum weight
		int min = W;
		for (int i = W; i > 0; i--) {
			if(test[N][i-1] == test[N][i])
				min = i-1;
			else
				break;
		}
		return min;
	}
}

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

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

  if (a > b)
    cout << "a > b" << endl;
  else if (a < b)
    cout << "a < b" << endl;
  else
    cout << "a == b" << endl;
  return 0;
}

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

const double pie = 3.1415926535897932;


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

	double r;	cin >> r;

	r = 2 * pie * r;

	cout << fixed << setprecision(10) << r << endl;


	return 0;
}

Measured memory_bytes: 3804
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fr(x,n) for(ll i=x;i<n;i++)

void solve(){
    ll n;
    cin>>n;
    ll a[n],b[n],c[n];
    for(ll i=0;i<n;i++){
        cin>>a[i]>>b[i]>>c[i];
    }

    ll dp[n][3];
    dp[0][0]=a[0];
    dp[0][1]=b[0];
    dp[0][2]=c[0];

    for(int i=1;i<n;i++){
        dp[i][0]=max(dp[i-1][1],dp[i-1][2])+a[i];
        dp[i][1]=max(dp[i-1][0],dp[i-1][2])+b[i];
        dp[i][2]=max(dp[i-1][1],dp[i-1][0])+c[i];
    }

    cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));
}

int main()
{
    solve();

    
}

Measured memory_bytes: 8288
import sys
mod=10**9+7 ; inf=float("inf")
from math import sqrt, ceil
from collections import deque, Counter, defaultdict #すべてのkeyが用意されてる defaultdict(int)で初期化
input=lambda: sys.stdin.readline().strip()
sys.setrecursionlimit(11451419)
from decimal import ROUND_HALF_UP,Decimal  #変換後の末尾桁を0や0.01で指定
  #Decimal((str(0.5)).quantize(Decimal('0'), rounding=ROUND_HALF_UP))
from functools import lru_cache
from bisect import bisect_left as bileft, bisect_right as biright
#メモ化再帰defの冒頭に毎回 @lru_cache(maxsize=10**10)
#引数にlistはだめ
#######ここまでテンプレ#######
#ソート、"a"+"b"、再帰ならPython3の方がいい
#######ここから天ぷら########

h,w=map(int,input().split())
sx,sy=map(int,input().split()) ; sx-=1;sy-=1
gx,gy=map(int,input().split()) ;gx-=1;gy-=1

A=[]
for i in range(h):
    A.append(list(input()))

dp=[[10**6]*w for i in range(h)]
dp[sx][sy]=0
dx=[-1,0,1,0]
dy=[0,1,0,-1]

def warp(x,y):
    r=[]    
    for i in range(x-2,x+3):
        for j in range(y-2,y+3):
            if 0<=i<h and 0<=j<w:
                if not (i==x and j==y):
                    if A[i][j]==".":
                        r.append([i,j])
    return r

queue=deque([[sx,sy]])
while queue:
    x,y=queue.pop()
    for i,j in zip(dx,dy):
        if 0<=x+i<h and 0<=y+j<w and dp[x+i][y+j]>dp[x][y] and A[x+i][y+j]==".":
            dp[x+i][y+j]= dp[x][y]
            queue.append([x+i,y+j])
    for a,b in warp(x,y):
        if dp[a][b]>dp[x][y]+1:
            dp[a][b]= dp[x][y]+1
            queue.appendleft([a,b])

print(dp[gx][gy] if dp[gx][gy]!=10**6 else -1)
            
            

Measured memory_bytes: 168944
// #include <bits/stdc++.h>
#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;
typedef long long ll;

#define all(x) begin(x), end(x)
#define rep(i,n) for(int i=0; i<n; i++)

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

    if (s.back() == 's') s.push_back('e'), s.push_back('s');
    else s.push_back('s');

    cout << s << endl;

    return 0;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,n,s) for(int i = s; i < (n); ++i)
#define rsrep(i,n,s) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<x<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;

int main() {
    int n;
    cin >> n;
    vvint abc(n, vint(3));
    rep(i, n) {
        cin >> abc[i][0] >> abc[i][1] >> abc[i][2];
    }
    vvint dp(n, vint(3));
    rep(i, 3) dp[0][i] = abc[0][i];
    srep(i, n, 1) {
        dp[i][0] = max(dp[i-1][1], dp[i-1][2]) + abc[i][0];
        dp[i][1] = max(dp[i-1][0], dp[i-1][2]) + abc[i][1];
        dp[i][2] = max(dp[i-1][0], dp[i-1][1]) + abc[i][2];
    }
    int ans = 0;
    rep(i, 3) ans = max(ans, dp[n-1][i]);
    cout << ans << endl;
    return 0;
}

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

int main(){
    using namespace std;
    int a, b; cin >> a >> b;
    int ans = 0;
    for (int i = 0; i < 2; i++)
    {
        if(a>=b){
            ans += a;
            a--;
        } else {
            ans += b;
            b--;
        }
    }
    cout << ans << endl;
    
}


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

int main(){
	long long n;	
	long long tmp;
	
	cin >> n;
	for(int i=1;i<=sqrt(n);i++)
		if(n%i==0)tmp = i;
	tmp = n / tmp;
	int ans = 0;
	while(tmp>0){
		tmp /= 10;
		ans++;
	}
	cout << ans << endl;
}

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

int main() {
    llu n; cin >> n;
    llu l0 = 2;
    llu l1 = 1;

    for (llu i = 2; i <= n; i++) {
        llu tmp;
        tmp = l1;
        l1 = l0 + l1;
        l0 = tmp;
    }
    if (n == 1)
        cout << l1 << endl;
    else
        cout << l1 << endl;
    return 0;
}

Measured memory_bytes: 256
//ABC109C
#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <math.h>
#include<stdio.h>
#include<climits>
#include<cfloat>
using namespace std;

int main(){
	int n, x;
	cin >> n >> x;
	vector<int> a(n);
	for(int i=0;i<n;i++){
		cin >> a.at(i);
	}
	int ans = abs(x-a.at(0));
	for(int i=1;i<n;i++){
		ans = __gcd(ans,abs(x-a.at(i)));
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 640
#include<algorithm>
#include <iostream>
#include<cstdio>
#include<cmath>
#include<iomanip>
#include<string>
using namespace std;
int main(){
   
    int a,b,c;
    cin>>a>>b>>c;
    
    if(b-a==c-b){
        cout<<"YES"<<endl;
    }else{
        cout<<"NO"<<endl;
    }
    
    return 0;
}






Measured memory_bytes: 256
# -*- coding: utf-8 -*-
N,M,Q = map(int, input().split())

list_query = [list(map(int, input().split())) for i in range(Q)]

def next(A):
  index = -1
  while True:
    if A[index]<M:
      return A[:index]+[A[index]+1 for i in range(-index)]
    else:
      index -= 1
      if index == -N:
        return [-1]

def calc_score(A):
  score = 0
  for q in list_query:
    if A[q[1]-1]-A[q[0]-1]==q[2]:
      score += q[3]
  return score

max_score = 0
A = [1 for i in range(N)]

while A[0]!=-1:
  max_score = max(max_score, calc_score(A))
  A = next(A)

print(max_score)

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

int main() {
  int N, M;
  cin >> N >> M;
 
  int Ns[N] = {0};
  for( int i = 0; i < M; ++i ){
    int a, b;
    cin >> a >> b;
    a -= 1;
    b -= 1;
    Ns[a] += 1;
    Ns[b] += 1;
  }
  
  for( int i = 0; i < N; ++i ){
    cout << Ns[i] << endl;
  }
}

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

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

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

struct Edge {
  int t;
  ll cost;
};

int dp[20][200001];
ll cost[200001];
ll depth[200001];

void dfs(int v, int p, vector<vector<Edge>> &G, ll c, int d) {
  cost[v] = c;
  depth[v] = d;
  for(int i = 0; i < G[v].size(); i++) {
    if (G[v][i].t == p) continue;
    dp[0][G[v][i].t] = v;
    dfs(G[v][i].t, v, G, c + G[v][i].cost, d + 1);
  }
}

int lca(int a, int b) {
  if (depth[a] < depth[b]) {
    int diff = depth[b] - depth[a];
    for(int i = 0; i < 20; i++) {
      if (diff >> i & 1) {
        b = dp[i][b];
      }
    }
  }
  if (depth[b] < depth[a]) {
    int diff = depth[a] - depth[b];
    for(int i = 0; i < 20; i++) {
      if (diff >> i & 1) {
        a = dp[i][a];
      }
    }
  }
  if (a == b) return a;

  for(int i = 19; i >= 0; i--) {
    if (dp[i][a] != dp[i][b]) {
      a = dp[i][a];
      b = dp[i][b];
    }
  }
  return dp[0][a];
}

void solve() {
  int N;
  cin >> N;
  vector<vector<Edge>> G(N);
  for (int i = 0; i < N - 1; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    a--, b--;
    G[a].push_back({b, c});
    G[b].push_back({a, c});
  }

  int Q, K;
  cin >> Q >> K;
  K--;

  dp[0][K] = K;
  dfs(K, -1, G, 0, 0);

  for(int i = 0; i < 19; i++) {
    for(int j = 0; j < N; j++) {
      dp[i + 1][j] = dp[i][dp[i][j]];
    }
  }

  for (int i = 0; i < Q; i++) {
    int x, y;
    cin >> x >> y;
    x--, y--;
    // int c = lca(x, y);
    // cout << c << endl;
    cout << cost[x] + cost[y] << endl;
  }
}

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

Measured memory_bytes: 34304
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>

#define INF (long)1e15

using namespace std;

typedef pair<long, int> P;

int main() {
    int n, m, s, t;
    scanf("%d %d %d %d", &n, &m, &s, &t);
    s--; t--;
    vector<P> Y[n], S[n]; //0~N-1が円,N~2N-1がスヌーくを持っている状態
    for (int i=0; i<m; i++) {
        int u, v; long a, b;
        scanf("%d %d %ld %ld", &u, &v, &a, &b);
        u--; v--;
        Y[u].push_back(P(a, v));
        Y[v].push_back(P(a, u));
        S[u].push_back(P(b, v));
        S[v].push_back(P(b, u));
    }
    long dy[n], ds[n];
    priority_queue<P, vector<P>, greater<P>> que;
    fill(dy, dy+n, INF);
    dy[s] = 0;
    que.push(P(0, s));
    while (!que.empty()) {
        P p = que.top(); que.pop();
        int now = p.second;
        if (dy[now] < p.first) continue;
        for (size_t j=0; j<Y[now].size(); j++) {
            int to = Y[now][j].second; long newd = Y[now][j].first + dy[now];
            if (dy[to] > newd) {
                dy[to] = newd;
                que.push(P(dy[to], to));
            }
        }
    }
    fill(ds, ds+n, INF);
    ds[t] = 0;
    que.push(P(0, t));
    while (!que.empty()) {
        P p = que.top(); que.pop();
        int now = p.second;
        if (ds[now] < p.first) continue;
        for (size_t j=0; j<S[now].size(); j++) {
            int to = S[now][j].second; long newd = S[now][j].first + ds[now];
            if (ds[to] > newd) {
                ds[to] = newd;
                que.push(P(ds[to], to));
            }
        }
    }
    for (int i=0; i<n; i++) que.push(P(dy[i]+ds[i], i));
    P min = que.top(); que.pop();
    for (int i=0; i<n; i++) {
        while(min.second < i) {
            min = que.top(); que.pop();
        }
        printf("%ld\n", INF - min.first);
    }
    return 0;
}

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

using namespace std;

void ans(string s) {
    for (int h = 0; h < s.size() / 2; ++h) {
        for (int i = 0; i < s.size() - 1; ++i) {
            if (s[i] == '(') {
                for (int j = i + 1; j < s.size(); ++j) {
                    if (s[j] == ')') {
                        s[i] = '[';
                        s[j] = ']';
                        break;
                    }
                    if (s[j] == '[' || s[j] == ']') {
                        continue;
                    }
                }
            }
        }
    }
    for (int i = 0; i < s.size(); ++i) {
        if (s[i] == '(') {
            int index = s.size();
            for (int j = i + 1; j < s.size(); ++j) {
                if (s[j] != '[' && s[j] != ']' && s[j] != '(') {
                    index = j;
                    break;
                }
            }
            s.insert(index, ")");
            s[i] = '[';
            s[index] = ']';
        } else if (s[i] == ')') {
            int index = 0;
            for (int j = i - 1; j > 0; --j) {
                if (s[j] != '[' && s[j] != ']') {
                    index = j;
                    break;
                }
            }
            s.insert(index, "(");
            s[index] = '[';
            s[i + 1] = ']';
        }
    }
    for (int i = 0; i < s.size(); ++i) {
        if (s[i] == '[') {
            s[i] = '(';
        } else if (s[i] == ']') {
            s[i] = ')';
        }
    }
    cout << s << endl;
}

int main() {
    int N;
    cin >> N;
    string S;
    cin >> S;
    ans(S);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define tcase int _; cin >> _; while(_--)
const int MAX = 1e6;
const int MOD = 1e9+7;

int ans;
int n;
ll v[MAX], sum[MAX];

void solve() {
	cin >> n;
	for(int i=0; i<n; i++) cin >> v[i];
	ans = 0;
	for(int i=0; i<61; i++) {
		ll c1 = 0;
		for(int j=0; j<n; j++) c1 += (v[j] >> i)&1;
		ll sum = c1*(n-c1);
		for(int j=0; j<i; j++) sum = 2*sum % MOD;
		ans = (ans + sum) % MOD;
	}
	cout << ans%MOD << "\n";
}

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

 	solve();

  	return 0;
}



Measured memory_bytes: 6024
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<functional>
#include<math.h>
using namespace std;
#define N (1000000000+7)
#define INF 1e16
typedef long long ll;
typedef pair<ll,ll> P;
 

int main(void){
    int n;
    cin>>n;
    if(n==1){
        cout<<1<<endl;
        cout<<0<<endl;
        return 0;
    }
    else{
        if(n==2){
            cout<<2<<endl;
            cout<<0<<endl;
            cout<<11<<endl;
        }
        else{
            vector<string>ans;
            string s="";
            ans.push_back("00");
            for(ll i=0;i<n-2;i++){
                s.push_back('1');
                ans.push_back("0"+s+"0");
            }
            cout<<ans.size()<<endl;
            for(int i=0;i<ans.size();i++){
                cout<<ans[i]<<endl;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 3312
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <unordered_map>
using namespace std;
#define INF 100000000

typedef long long ll;

bool isSmaller(string a,string b){
    if(a.size()<b.size()) return true;
    if(b.size()<a.size()) return false;
    int l = a.size();
    for(int i = 0; i < l; i++)
    {
        if(a[i]<b[i]) return true;
        if(a[i]>b[i]) return false;
    }
    return false;
}

int main(){
    ll cnt[10] = {0,2,5,5,4,5,6,3,7,6};
    int N,M;cin>>N>>M;
    vector<int> A(M);
    for(int i = 0; i < A.size(); i++)
    {
        cin>>A[i];
    }
    sort(A.begin(),A.end());
    vector<string> dp(N+1,"0");//dp[i] i本使ってできる整数の最大数
    dp[0] = "";
    for(int i = 0; i < N+1; i++)
    {
        for(int j = 0; j < M; j++)
        {   ll tmp = i-cnt[A[j]];
            if(tmp>=0 && dp[tmp]!="0"){
                dp[i] = max(dp[i],dp[tmp]+char(A[j]+'0'),isSmaller);
            }
        }
        
    }
    cout << dp[N] << endl;
}


Measured memory_bytes: 41728
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N;
    int ans=0;
    cin>>N;
    int V[30];
    int C[30];
    for(int i=0;i<N;i++){
        cin>>V[i];
    }
    for(int i=0;i<N;i++){
        cin>>C[i];
    }
    for(int i=0;i<N;i++){
        if (V[i]-C[i]>0){
            ans+=(V[i]-C[i]);
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
while True:
    n,k=map(int,input().split())
    if n==0 and k==0:
        break
    a=[int(input()) for _ in range(n)]
    s=sum(a[0:k])
    ss=[s]
    for i in range(k,n):
        s=s+a[i]-a[i-k]
        ss.append(s)
    print(max(ss))    


Measured memory_bytes: 11700
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n, a, b = list(map(int, readline().split()))
    d, m = divmod(n, a + b)
    print(a * d + min(a, m))


if __name__ == '__main__':
    solve()


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


Measured memory_bytes: 20060
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fastio ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#define  mp make_pair
#define pb push_back
const int mod  = 1e9 + 7;
bool isPrime(int n)
{
    for (int i = 2; i < n; i++) if (n % i == 0)return false;
    return true;
}
struct cmp {
    bool operator()(const pair<int, int>& a, const pair<int, int>& b)
    {
        int len1 = a.second - a.first + 1;
        int len2 = b.second - b.first + 1;
        if (len1 != len2) return len1 > len2;
        return a.first < b.first;
    }
};
bool comp(pair<pair<int, int>, int>& a, pair<pair<int, int>, int>& b)
{
    int diff1 = abs(a.first.first - a.first.second);
    int diff2 = abs(b.first.first  - b.first.second);

    if (diff1 > diff2)
        return true;
    return false;
    // return (a.first.second > b.first.second);

}
void findAns()
{
    int n;
    cin >> n;

    int height[n];
    for (auto&it : height) cin >> it;

    int dp[n];

    dp[0] = 0;
    dp[1] = abs(height[0] - height[1]);

    for (int i = 2; i < n; i++)
    {
        dp[i] = min(dp[i - 1] + abs(height[i - 1] - height[i]), dp[i - 2] + abs(height[i - 2] - height[i]));
    }
    cout << dp[n - 1];
    return;







}
int main()
{

    fastio;
    // ll int t;
    // cin >> t;

    // while (t--)
    findAns();

    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;

int main(){
    double a=0, b=0, x=0, ans=0, l=0;
    cin >> a >> b >> x;
    if((int)x > (int)(a*a*b / 2)){
        l = 2*x / (a*a) - b;
        ans = atan2(b-l, a);
    }
    else{
        l = 2*x / (a*b);
        ans = atan2(b, l);
    }
    cout << fixed << setprecision(10) << ans * 180 / 3.14159265358979323846;
    return 0;
}

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

typedef long long int int64;

const int f=102;
#define POS(i,j) ((i)*f+(j))

int dfs(int v,int64 *g,int *array,int *used){
  used[v]=1;
  array[0]=v;
  if(v==f-1) return 1;
  int i;
  for(i=0;i<f;i++){
    if(!used[i] && g[POS(v,i)]>0){
      int c=dfs(i,g,array+1,used);
      if(c>0) return c+1;
    }
  }
  return 0;
}

int64 calc(int *a,int n){
  int64 *g=(int64 *)calloc(f*f,sizeof(int64));
  int i,j;
  for(i=1;i<=n;i++){
    if(a[i]>=0){
      g[POS(i,f-1)]=a[i];
    } else {
      g[POS(0,i)]=-a[i];
    }
  }
  for(i=1;i<=n;i++){
    for(j=2*i;j<=n;j+=i){
      g[POS(i,j)]=1000000000LL*1000;
    }
  }
  int array[128];
  int used[128]={0};
  int64 ans=0;
  int64 len=dfs(0,g,array,used);
  while(len){
    int64 min=1000000000LL*1000;
    for(i=0;i+1<len;i++){
      int64 t=g[POS(array[i],array[i+1])];
      if(min>t) min=t;
    }
    ans+=min;
    for(i=0;i+1<len;i++){
      int v=array[i];
      int u=array[i+1];
      g[POS(v,u)]-=min;
      g[POS(u,v)]+=min;
    }
    for(i=0;i<f;i++) used[i]=0;
    len=dfs(0,g,array,used);
  }
  free(g);
  return ans;
}

void run(void){
  int n;
  scanf("%d",&n);
  int i;
  int a[101];
  for(i=1;i<=n;i++) scanf("%d",a+i);
  int64 sum=0;
  for(i=1;i<=n;i++) if(a[i]>=0) sum+=a[i];
  int64 ans=sum-calc(a,n);
  printf("%lld\n",ans);
  return;
}

int main(void){
  run();
  return 0;
}


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

int main(){
    int N,i,max,sum;
    cin >> N;
    int p[N];
    for ( i = 0 ; i < N ; i++ )
    {
        cin >> p[i];
    }

    max = p[0];
    sum = 0;

    for( i = 1 ; i < N ; i++ )
    {
        if (max < p[i]) max = p[i];
    }

    for (i = 0; i < N; i++)
    {
        sum += p[i];
    }
    
    cout << sum - max/2 << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

int main(){
  int n,m;
  long long temp;
  cin>>n>>m;

  temp=1900*m+100*(n-m);
  for(int i=0;i<m;i++){
    temp*=2;
  }
  cout<<temp<<endl;

  return 0;
}


Measured memory_bytes: 256
<?php
fscanf(STDIN, "%d", $N);
$inputs = trim(fgets(STDIN));
$inputs = array_map("intval", explode(" ", $inputs));

$humidai = 0;

$max_value = 0;
for ($i = 0; $i < $N; $i++) {
    if ($i == 0 || $inputs[$i] > $max_value) {
        $max_value = $inputs[$i];
    } else {
        $humidai += $max_value - $inputs[$i];
    }
}

echo $humidai . "\n";


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

void swap(long int array[],int lo,int hi){
  int temp=array[lo];
  array[lo]=array[hi];
  array[hi]=temp;
}

void shuffle(long int array[],int size){
  for(int i=0;i<size;i++){
    int j=rand()%size;
    swap(array,i,j);
  }
}

int partition(long int array[],int low,int hig){
  int i=low;
  int j=hig+1;
  while(1){
    while(array[++i]<array[low]){
      if(i == hig) break;}
    while(array[low]<array[--j]){
      if(j==low) break;}
    if(i>=j) break;
    swap(array,i,j);
  }
  swap(array,low,j);
  return j;
}

void sort(long int array[],int lo,int hi){
  if(hi<=lo) return;
  int j=partition(array,lo,hi);
  sort(array,lo,j-1);
  sort(array,j+1,hi);
}

void quicksort(long int array[],int size){
  shuffle(array,size);
  sort(array,0,size-1);
}


int insertionsort(long int a[],int mini){
  if(mini==0) return 0;
  int i=mini;
  while(a[i-1]>a[mini]){
    i--;
    if(i==0) break;}
  swap(a,i,mini);
  return i;
}

int findmin(long int af[],int n){
  int mini=0;
  for(int i=0;i<n;i++){
    if(af[i]<af[mini]) mini=i;}
  return mini;
}

int max(long int x,long int y){
  if(x>y) return x;
  return y;
}

int main(){
  int n;
  long int k;
  scanf("%d%ld\n",&n,&k);
  long int a[n+1];
  long int f[n+1];
  for(int i=0;i<n;i++){
    scanf("%ld",&a[i]);}
  //printf("ok\n");
  scanf("\n");
  for(int i=0;i<n;i++){
    scanf("%ld",&f[i]);
    f[i]*=-1;}
  //printf("ok\n");
  
  quicksort(a,n);
  quicksort(f,n);
  for(int i=0;i<n;i++){
    f[i]*=-1;}


  long int lo=-1;
  long int hi=a[n-1]*f[0];
  long int x=0;
  while(lo<hi-1){
    x=lo+(hi-lo)/2;
    long int sum=0;
    for(int i=0;i<n;i++){
      sum += max(a[i]-x/f[i],0);}
    //printf("%ld %ld\n",x,sum);
    if(sum > k){
      lo=x;
      continue;}
    else{
      hi=x; continue;}}
  printf("%ld\n",hi);

  
  return 0;
}
 
//計算量　nlog(10^12)



Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int n;
  int s=0;
  cin >> n;
  vector<int> a(n), b(n), c(n-1);
  for(int i=0;i<(n);i++){
    cin >> a.at(i);
  }
  for(int i=0;i<(n);i++){
    cin >> b.at(i);
  }
  for(int i=0;i<(n-1);i++){
    cin >> c.at(i);
  }
  s += accumulate(b.begin(), b.end(), 0);
  for(int i=0;i<(n-1);i++){
    if(a.at(i) == a.at(i+1)-1) s += c.at(a.at(i)-1);
  }
  cout << s << endl;
}

Measured memory_bytes: 256