akhauriyash/Code-Regression huggingface dataset:
import itertools
n,m,q=map(int,input().split())
a=[]
b=[]
c=[]
d=[]
for i in range(q):
    a1,b1,c1,d1=map(int,input().split())
    a.append(a1)
    b.append(b1)
    c.append(c1)
    d.append(d1)

l=list(range(1,m+1))
ans=0
for A in list(itertools.combinations_with_replacement(l, n)):
    sum=0
    for i in range(q):
        if A[b[i]-1]-A[a[i]-1]==c[i]:
            sum+=d[i]
    ans=max(ans,sum)

print(ans)

        


    





Measured memory_bytes: 84720
#include<cstdio>
#include<iostream>
#include<cmath>
using namespace std;

int main(){
    int n,s[1000];
    while (1){
        cin >> n;
        if (n == 0)break;
        for (int i = 0; i < n; i++)cin >> s[i];
        int sum = 0;
        for (int i = 0; i < n; i++)sum += s[i];
        double ave = 1.0*sum/n;
        double dist = 0.0;
        for (int i = 0; i < n; i++){
            dist += (ave-s[i])*(ave-s[i]); 
        }
        printf("%lf\n",sqrt(dist/n));
    }
return 0;
}

    
    


Measured memory_bytes: 3212
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long  ll;
#define rep(i,s,n)for(ll i=s;i<n;i++)
#define repe(i,s,n)for(ll i=s;i<=n;i++)

char c[50][50] = {};
int d[50][50] = {};

void maze(ll R, ll C, ll sy, ll sx, ll gy, ll gx) {
	sy--, sx--, gy--, gx--;
	bool v[50][50] = {};
	int x[4] = { 1,0,0,-1 };
	int y[4] = { 0,1,-1,0 };

	int ps = 0;
	int pe = 0;
	ll qx[10000] = {};
	ll qy[10000] = {};

	qy[pe] = sy;
	qx[pe] = sx;
	d[sy][sx] = 0;
	v[sy][sx] = true;
	pe++;

	while (ps != pe) {
		//pop
		ll cy = qy[ps];
		ll cx = qx[ps];
		ps++;
		if (cy == gy && cx == gx) {
			break;
		}

		rep(i, 0, 4) {
			//push
			ll ny = cy + y[i];
			ll nx = cx + x[i];

			if (ny >= 0 && ny < R && nx >= 0 && nx < C && c[ny][nx] != '#' && !v[ny][nx]) {
				qy[pe] = ny;
				qx[pe] = nx;
				pe++;
				v[ny][nx] = true;
				d[ny][nx] = d[cy][cx] + 1;
			}
		}
	}
}

int main() {
	ll h, w; cin >> h >> w;
	ll white = 0;
	rep(i, 0, h)rep(j, 0, w) {
		cin >> c[i][j];
		if (c[i][j] == '.')white++;
	}
	maze(h, w, 1, 1, h, w);
	ll dis = d[h - 1][w - 1];
	if (dis == 0)cout << -1 << endl;
	else {
		cout << white - (dis + 1) << endl;
	}

	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <limits>

using namespace std;


int main(int argc, char** argv){
    int N, K;
    string S;
    cin >> N >> S >> K;

    for (int i=0; i<N; i++)
        if (S[i] != S[K-1])
            S[i] = '*';

    cout << S << "\n";

    return 0;
}


Measured memory_bytes: 256
#include <cmath>

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

#include <map>

using namespace std;

using ll = long long;
using ld = long double;
using vi = vector<int>;

int n;
ll k;

map<int, ll> a;

void input() {
  a.clear();

  cin >> n >> k;
}

void solve() {
  while (n--) {
    int x;
    int y;
    cin >> x >> y;

    a[x] += y;
  }

  int ans;

  for (auto&& [key, val] : a) {
    if (k <= val) {
      ans = key;

      break;
    }

    k -= val;
  }

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

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

  cout.precision(16);
  cout << fixed;

  int _times = 1;

#ifdef _DEBUG
  freopen("input.txt", "r", stdin);
  //freopen("output.txt", "w", stdout);

  _times = 2;
#endif

  // cin >> _times;

  while (_times--) {
    input();
    solve();
  }
}


Measured memory_bytes: 7528
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <stdio.h>
#include <string.h>
using namespace std;

int x[100][100]={0};
int count;

void foo(int s,int t){
	if(x[s][t]==0){
	}
	else{
		count++;
		x[s][t]=0;
		if(t-1>=0) foo(s,t-1);
		foo(s,t+1);
		if(s-1>=0) foo(s-1,t);
		foo(s+1,t);
	}
}
	
int main(){

	int w,h;
	int i,j;
	char tmp;
	int pos1,pos2;
	
	cin>>w>>h;
	while(!(w==0&&h==0)){
		memset(x,0,sizeof(x));
		count=0;
	for(i=0;i<h;i++){
		for(j=0;j<w;j++){
			cin>>tmp;
			//printf("%c\n",tmp);
			if(tmp=='.'){
				x[i][j]=1;
			}
			else if(tmp=='#'){
				x[i][j]=0;
			}
			else if(tmp=='@'){
				pos1=i;
				pos2=j;
				x[i][j]=1;
				//cout<<"pos 1 2  "<<pos1<<" "<<pos2<<endl;
			}
		}
		//cout<<endl;
	}
		//printf("hoge");
		
		/*for(i=0;i<h;i++){
			for(j=0;j<w;j++){
				cout<<x[i][j]<<" ";
			}
			cout<<endl;
		}
		cout<<endl;
		*/
		foo(pos1,pos2);
		//cout<<"hoge";
		cout<<count<<endl;
		cin>>w>>h;
		
	}
	
	
	return 0;
}

Measured memory_bytes: 1216
n=int(input())
A=[]
for i in range(n):
    A.append(list(map(int,input().split())))

A.sort(reverse=1)

B=[]
for i in range(n):
    B.append([i,A[i][1]+A[i][0]])
    
B.sort(reverse=1,key=lambda x:x[1])




#print(B)
#print(C)


S=[0,0]

for i in range(n):
    S[i%2]+=A[B[i][0]][i%2]


print(S[0]-S[1])


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

n, k = map(int,input().split())
C = [list(map(int,input().split())) for i in range(k)]

# for i in range(k):
#     C[i][0] -= 1
#     C[i][1] -= 1

# ACLに伴い0-indexedに直した
class Bit:  # Fenwick Tree と同じ
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)
  
    def sum(self, l, r):  # [l,r)の合計を求める
        # 内部的には[l+1,r+1)の合計つまり(rまでの合計-lまでの合計)
        s = 0
        while r > 0:
            s += self.tree[r]
            r -= r & -r
        while l > 0:
            s -= self.tree[l]
            l -= l & -l
        return s
  
    def add(self, i, x):  # i番目にxを足す
        i += 1
        while i <= self.size:
            self.tree[i] += x
            i += i & -i

# Bitの内部状態をindex順に出力
def print_bit(B):
    n = B.size
    ANS = []
    for i in range(n):
        ANS.append(B.sum(i, i+1))
    print(*ANS)

B = Bit(n)
mod = 998244353
B.add(0, 1)
for i in range(1, n):
    for j in range(k):
        B.add(i, (B.sum(max(0,i-C[j][1]), max(0,i-C[j][0]+1)))%mod)

print(B.sum(n-1,n)%mod)

Measured memory_bytes: 70648
icase=0
if icase==0:
    n,t=map(int,input().split())
    ct=[]
    for i in range(n):
        ci,ti=map(int,input().split())
        if ti<=t:
            ct.append([ci,ti])
    if len(ct)==0:
        print("TLE")
    else:
        ct.sort()
        print(ct[0][0])

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#define rep(i,n) for(int i=0;i<(n);i++)
#define INF 1e+100
#define vint vector<int>
#define abs(x) ((x)>=0?(x):-(x))

using namespace std;
	
int main()
{
	int n;
	cin >> n;

	int MAX_N = (1 << n), ID[n], d[n], box[n];
	rep (i, n )
		cin >> ID[i] >> d[i] >> box[i];

	double dp[n][MAX_N];
	vint path[n][MAX_N];

	int w[MAX_N];

	rep (i, MAX_N ){
		int sum = 0, cnt = 0;
		for (int j = 1; j < MAX_N; j = (j << 1), cnt++ ){
			if ((i & j ) != 0 ){
				sum += box[cnt];
			}// end if
		} // end for
		w[i] = sum*20;
	} // end rep

	fill (&dp[0][0], &dp[n-1][MAX_N], INF );

	rep (i, n ){
		dp[i][1 << i] = 0.;
		path[i][1 << i].push_back (i );
	} // end rep

	rep (i, MAX_N ){
		double v = 2000.0/(double)(70 + w[i] );
		rep (j, n ){
			int now = (1 << j );
			if ( (i & now ) == 0 ) continue;	// Ü¾KêÄ¢È¢
			rep (k, n ){
				int next = (1 << k );
				if ( (i & next ) ) continue;	// à¤Kê½
				double cost = (double)(abs(d[j] - d[k] ) )/v;
				if (dp[k][i|next] > dp[j][i] + cost ){
					dp[k][i|next] = dp[j][i] + cost;
					path[k][i|next] = path[j][i];
					path[k][i|next].push_back (k );
				} // end if
			} // end rep
		} // end rep
	} // end rep
	
	double min = INF;
	vint ans;

	rep (i, n ){
		if (min > dp[i][MAX_N-1] ){
			min = dp[i][MAX_N-1];
			ans = path[i][MAX_N-1];
		} // end if
	} // end rep

	rep (i, ans.size() ){
		if (i != 0 )
			cout << ' ';
		cout << ID[ans[i]];
	} // end rep
	cout << endl;			 
		
	return 0;
}

Measured memory_bytes: 25000
#include <stdio.h>
int main(void)
{
	int S,h,m,s;
	scanf("%d",&S);
	h=S/3600;
	S=S-h*3600;
	m=S/60;
	S=S-m*60;
	s=S;
	printf("%d:%d:%d\n",h,m,s);
	return 0;
}



Measured memory_bytes: 1972
from collections import Counter

N=int(input())
A=Counter(list(map(int,input().split())))

x=sorted([i for i in A.items() if i[1]>=2])

if len(x)<2:
    print(0)
elif x[-1][1]>=4:
    print(x[-1][0]**2)
else:
    print(x[-1][0]*x[-2][0])

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

int main(){
	int n;
	
	cin >> n;
	int m = n%100;
	int y = n/100;
	if(m&&y&&m<=12&&y<=12) cout << "AMBIGUOUS";
	else if((!m&&!y)||(!m&&y>12)||(m>12&&!y)||(m>12&&y>12)) cout << "NA";
	else if((!m||m>12)) cout << "MMYY";
	else if(!y||y>12) cout << "YYMM";
}

Measured memory_bytes: 256
N = int(input())
R = [input().split() for i in range(N)]

R2 = [{'i':i+1, 's':R[i][0], 'p':int(R[i][1])} for i in range(N)] 

S = []
for r in R:
  if r[0] not in S:
    S.append(r[0])
S.sort()

for s in S:
  rs = [r for r in R2 if r['s'] == s]
  sorted_rs = sorted(rs, key=lambda x:x['p'], reverse=True)
  for r in sorted_rs:
    print(r['i'])

Measured memory_bytes: 9116
#include <bits/stdc++.h>
using namespace std;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) { cout << #v << "=" << endl; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << endl; }
#define mdebug(m) { cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;} }
#define pb push_back
#define fi first
#define se second
#define int long long
#define INF 1000000000000000000
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); i++) { cout << v[i]; if(i != v.size() - 1) cout << endl; }; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p){ cout << '(' << p.first << ',' << p.second << ')'; return os; }
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void chOut(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }

using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using v_bool = vector<bool>;
using v_Pii = vector<Pii>;

//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//char d[4] = {'D','R','U','L'};

const int mod = 1000000007;
//const int mod = 998244353;



signed main(){

    int R, C, K; cin >> R >> C >> K;
    mat S(R, vec(C, 0));
    REP(i, K){
        int r, c, v; cin >> r >> c >> v;
        S[r - 1][c - 1] = v;
    }

    mat dp(C, vec(4, 0));
    REP(i, R){
        REP(j, C){
            IREP(k, 4){
                if(j + 1 < C){
                    chmax(dp[j + 1][k], dp[j][k]);
                    if(k < 3) chmax(dp[j + 1][k + 1], dp[j][k] + S[i][j]);
                }
                if(k < 3) chmax(dp[j][k + 1], dp[j][k] + S[i][j]);
            }
        }

        REP(j, C){
            FOR(k, 1, 4){
                chmax(dp[j][0], dp[j][k]);
                dp[j][k] = 0;
            }
        }
    }
    Out(dp[C - 1][0]);

    return 0;
}


Measured memory_bytes: 73896
#include<iostream>
#include<cmath>
#include<cstdio>
using namespace std;
int main(){
    int a,b,c;
    double s,S,L,H;
    cin>>a>>b>>c;
    s=c*acos(-1)/180;
    S=a*b*sin(s)/2;
    L=a+b+sqrt(a*a+b*b-2*a*b*cos(s));
    H=S*2/a;
    printf("%lf\n %lf\n %lf\n",S,L,H);
    return 0;
}


Measured memory_bytes: 3360
import java.util.Scanner;
public class Main {
     public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        int C = sc.nextInt();
        int D = sc.nextInt();
        
        for(int i = 0; i < 100; i++){
            C = C - B;
            if(C <= 0){
                System.out.println("Yes");
                i = 101;
            }else{
                A = A - D;
                if(A <= 0){
                    System.out.println("No");
                    i = 101;
                }else{
                    //なし
                }
            }
        }
     }
    
}

Measured memory_bytes: 27016
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
long long n,m,w[15][15],p[1<<15],dp[1<<15][15],sum,ans;
void init()
{
    for(int i=0;i<1<<n;++i)
        for(int j=0;j<n;++j) if(i>>j&1)
            for(int k=j+1;k<n;++k) if(i>>k&1)
                p[i]+=w[j][k];
}
int main()
{
    ios::sync_with_stdio(false);
    cin>>n>>m;
    for(int i=1;i<=m;++i)
    {
        int x,y,t;
        cin>>x>>y>>t;
        --x;--y;
        w[x][y]=t;
        w[y][x]=t;
        sum+=t;
    }
    init();
    memset(dp,0xff,sizeof(dp));
    dp[1][0]=0;
    for(int i=0;i<1<<n;++i)
        for(int j=0;j<n;++j) if(dp[i][j]!=-1)
        {
            int x=(1<<n)-1^i|1<<j;
            for(int y=x;y>=0;--y)
                y&=x,dp[i|y][j]=max(dp[i|y][j],dp[i][j]+p[y]);
            for(int k=0;k<n;++k) if(!(i>>k&1)&&w[j][k]!=0)
                dp[i|1<<k][k]=max(dp[i|1<<k][k],dp[i][j]+w[j][k]);
        }
    for(int i=0;i<1<<n;++i) ans=max(ans,dp[i][n-1]);
    cout<<sum-ans<<endl;
    return 0;
}

Measured memory_bytes: 4352
#include <algorithm>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <cctype>
#include <iostream>
#include <set>
#include <string>
#include <queue>
#include <map>
#include <utility>
using namespace std;
int size(string x){
	string::size_type size=x.size();
	return size;
}
#define fu(l,k) for(int i=l;i<k;i++)
#define fd(l,k) for(int i=l;i>k;i--)
#define sort(ss) sort(ss.begin(), ss.end())
#define rsort(ss) sort(ss.rbegin(), ss.rend())
typedef  vector<string> vs;
typedef  vector<int> vi;
double pi(){
	return M_PI;
}
typedef set<int> set_i;
typedef set<string> set_s;
int INF=1000000;
int main(){
	string s,s1,s2;
	int a,ans=0,q,qq;
	while(cin>>s){
		a=size(s);
		if(a%2==0){
			s1=s.substr(0,a/2);
			reverse(s.begin(), s.end());
			s2=s.substr(0,a/2);
			if(s1==s2) ans++;
		}
		else{
			s1=s.substr(0,(a-1)/2);
			reverse(s.begin(), s.end());
			s2=s.substr(0,(a-1)/2);
			if(s1==s2) ans++;
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 1196
#include <bits/stdc++.h>
#define ok 5000099
using namespace std;
using ll = long long int;
string n;
void inp()
{
    cin >> n;
}
void process()
{
    ll tmp = 0;
    for (int i = 0; i < n.length(); i++) tmp += (n[i]-48);
    if (tmp%9 == 0) cout <<"Yes";
    else cout <<"No";
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("test.inp","r", stdin);
    inp();
    process();
    return 0;
}



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

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

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


int vec_sum(vector<int> v){
  int n=0;
  for(int i=0;i<v.size();i++) n+=v[i];
  return n;
}
///////////////////////////
int main() {
  int a=0,b=0,c=0,n=0,count=0,ans=0;
  string s;
  cin>>s;
  if(s[0]=='Y' && s[1]=='A' && s[2]=='K' && s[3]=='I'){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
}
///////////////////////////

Measured memory_bytes: 256
#include <iostream>
using namespace std;
#include <string>
#include <algorithm>
int a[100010];
bool com(int a,int b)
{
	return a>b;
}
int main()
{
	int n;
	cin>>n;
	int m;
	int mm=0;
	for(int i=0;i<n;i++)
	{
		cin>>m;
		if(mm<m)
		mm=m;
		a[m]++;
	}
	sort(a,a+mm+1,com);
	n=mm+1;
	for(int i=0;i<mm;i++)
	{
	//	cout<<a[i]<<" ";
		if(a[i]%2!=0)
		{
			a[i]=1;
		}
		else if(a[i]!=0)
		{
			a[i]=2;
		}
	//	cout<<a[i]<<" ";
	}
//	cout<<endl;
	sort(a,a+mm+1,com);
	int c=0;
	for(int i=0;i<n-1;i++)
	{
	//	cout<<a[i]<<" ";
		if(a[i]==2)
		{
			a[i]=a[i]-1;
			a[i+1]=a[i+1]-1;
		}
	}
	for(int i=0;i<n;i++)
	{
		if(a[i]<0)
		continue;
		c=c+a[i];
	}
	cout<<c;
	return 0;
}

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

#define nax 100009
#define FOR(i,n,m) for(int i =(n);i<(m);i++)
#define REP(i,n) FOR(i,0,n)
#define pb push_back

typedef long long ll;

int main(){
	ll dp[nax][3];
	int n; cin>>n;
	int a[nax][3];
	REP(i,n){
		REP(j,3){
			cin>>a[i][j];
		}
	}
	REP(i,n){
		REP(j,3){
			dp[i][j] = 0LL;
		}
	}
	REP(i,3){
		dp[0][i] = a[0][i];
	}

	FOR(i,1,n){
		REP(j,3){
			dp[i][j] = max(dp[i-1][(j+1)%3],dp[i-1][(j+2)%3])+a[i][j];
		}
	}

	ll m = 0;
	REP(i,3){
		m = max(m,dp[n-1][i]);
	}

	cout<<m<<endl;

	return 0;
}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
using ull = unsigned long long;

int main() {
    int N, di;
    vector<int> d;
    cin >> N;
    for (int i=0; i<N; i++) cin >> di, d.push_back(di);

    sort(d.begin(), d.end());

    cout << d[N/2] - d[N/2-1] << endl;

    return 0;
}



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

using namespace std;

int main(){
    int N;
    cin >> N;
    vector<int> h(N);
    for(int i = 0; i < N; i++){
        cin >> h[i];
    }
    
    int ans = 0;
    while(true){
        if(*max_element(h.begin(),h.end()) == 0){
            break;
        }
        
        int i = 0;
        while(i < N){
            if(h[i] <= 0){
                i++;
            }else{
                ans++;
                while(i < N && h[i] > 0){
                    h[i]--;
                    i++;
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <climits>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <list>
#include <set>
#include <bitset>
#include <iterator>
#define loop(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define debug(x)  cout << #x << " = " << (x) << endl;

using namespace std;
using LL = long long;
using ULL = unsigned long long;

using Edges = vector<pair<int, LL>>;
using Graph = vector<Edges>;

Graph graph;
vector<int> colors;

void dfs(int v, int par, int color) {
    colors[v] = color;

    for (auto e : graph[v]) {
        if (e.first == par) continue;
        if (e.second % 2 != 0) dfs(e.first, v, 1 - color);
        else dfs(e.first, v, color);
    }
}
int main() {
    int n; cin >> n;
    graph.assign(n, Edges());
    rep(i, n - 1) {
        int u, v;
        LL w;
        cin >> u >> v >> w;
        --u; --v;
        graph[u].push_back(make_pair(v, w));
        graph[v].push_back(make_pair(u, w));
    }
    colors.assign(n, 0);
    dfs(0, -1, 1);
    for (auto c : colors) {
        cout << c << endl;
    }
    return 0;

}


Measured memory_bytes: 10496
#include <stdio.h>
int main(void) {
  int a,b,t;
scanf("%d%d",&a,&b);
if(a<b){
	t=a;
	a=b;
	b=t;
}
for(;;){
if(b==0)break;	
t=a%b;
a=b;
b=t;
}
printf("%d\n",a);
  return 0;
}

Measured memory_bytes: 592
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>
#include<utility>
#include<unordered_map>
#include<queue>
#include<bitset>


using namespace std;

#define endl "\n"

constexpr long long INF = (long long)1e9;
constexpr long long MOD = 1'000'000'007; 

struct fast_io {
	fast_io(){
		std::cin.tie(nullptr);
		std::ios::sync_with_stdio(false);
	};
} fio;

signed main(){
	cout<<fixed<<setprecision(10);
	
	constexpr int num = 26;
	string s;
	int N;
	int con = 0, ans = 0;
	unordered_map<int,int> mp;
	
	cin>>s;
	
	N = s.size();
	
	mp[0] = 0;
	
	for(int i = 0; i < N; i++){
		con ^= (1<<(s[i] - 'a'));
		int minimum = INF;
		
		for(int j = 0; j < num; j++){
			int hoge = con ^ (1<<j);
			
			if(mp.count(hoge)) {
				minimum = min(mp[hoge] + 1, minimum);
			}
		}
		
		if(mp.count(con)) {
			minimum = min(mp[con] + 1, minimum);
			mp[con] = min(mp[con], minimum);
		} else {
			mp[con] = minimum;
		}
		ans = minimum;
	}
	
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 8668
//#pragma GCC optimize ("O3")
//#pragma GCC target ("avx2")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

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


	int X;
	cin >> X;

	for (ll A = -1000; A <= 1000; A++) {
		ll A5 = A * A * A * A * A;
		ll tmp = A5 - X;

		ll L = -2000;
		ll R = 2000;
		while (L + 1 < R) {
			ll M = (L + R) / 2;
			ll M5 = M * M * M * M * M;
			if (M5 < tmp) L = M;
			else R = M;
		}

		ll L5 = L * L * L * L * L;
		ll R5 = R * R * R * R * R;
		if (tmp == L5) {
			cosp(A);
			co(L);
			return 0;
		}
		if (tmp == R5) {
			cosp(A);
			co(R);
			return 0;
		}
	}



	Would you please return 0;
}

Measured memory_bytes: 3652
#include<iostream>
#include<algorithm>
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,n0,n) for(int i=n0;i<n;i++)
#define Com(i,j,n) for(int i=0;i<n-1;i++)for(int j=i+1;j<n;j++)
#define W(x) cout<<x<<endl;
#define Debug(x) cout<<"#DEBUG "<<x<<endl;

using namespace std;
int main()
{
    int n;
    cin>>n;
    int a[2*n];
    rep(i,2*n)
    {
        cin>>a[i];
    }
    sort(a,a+2*n);
    int r=0;
    rep(i,n)
    {
        r+=a[2*i];
    }
    cout<<r<<endl;
    return 0;
}

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

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef tuple<int,int,int> t3;

const int MX = 100005;
const int MM = 1000000007;

int D[MX];
int N, C, K;

int main()
{
	scanf("%d%d%d", &N, &C, &K);
	for(int i = 1; i <= N; i++) scanf("%d", D+i);
	sort(D+1, D+N+1);
	int ans = 1, cnt = 0, lst = D[1] + K;
	for(int i = 1; i <= N; i++){
		if( D[i] <= lst ) cnt++;
		else ans++, cnt = 1, lst = D[i]+K;
		if( cnt == C ){
			ans++; cnt = 0; lst = D[i+1] + K;
		}
	}
	if( cnt == 0 ) ans--;
	printf("%d\n", ans);
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <cstring>
#include <sstream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <chrono>
#include <numeric>

using namespace std;

class cFlood
{
	string tb;
	int A;
	int k;
	vector<int> vL;
	vector<int> vLrev;

public:
	cFlood(){}
	cFlood(const string &c)
	{
		tb = c;
	}

	void calcflood();
	void output();
};

void cFlood::calcflood()
{
	string::iterator it = tb.begin();

	int hstd = 0;
	vector<int> vheight;

	int th = hstd;
	vheight.push_back(th);
	int stdIndex = 0;
	for (int i = 0; i < tb.size(); ++i)
	{
		if (tb[i] == '\\')
		{
			th -= 1;
		}
		else if (tb[i] == '_')
		{
			th = th;
		}
		else if (tb[i] == '/')
		{
			th += 1;
		}

		vheight.push_back(th);
	}

	int tsum;
	for (int i = 1; i < vheight.size(); ++i)
	{
		if (hstd == vheight[i])
		{
			tsum = 0;

			for (int j = stdIndex; j <= i; ++j)
			{
				tsum += hstd - vheight[j];
			}
			if (tsum > 0)
				vL.push_back(tsum);
		}

		if (hstd <= vheight[i])
		{
			hstd = vheight[i];
			stdIndex = i;
		}
	}
	int hstd_rev = vheight[vheight.size() - 1];
	int stdIndex_rev = vheight.size() - 1;
	for (int i = vheight.size() - 2; i > stdIndex; --i)
	{
		if (hstd_rev <= vheight[i])
		{
			tsum = 0;

			for (int j = stdIndex_rev; j >= i; --j)
			{
				tsum += hstd_rev - vheight[j];
			}
			if (tsum > 0)
				vLrev.push_back(tsum);
		}
		if (hstd_rev <= vheight[i])
		{
			hstd_rev = vheight[i];
			stdIndex_rev = i;
		}
	}

	for (int i = vLrev.size() - 1; i >= 0; --i)
	{
		vL.push_back(vLrev[i]);
	}
	A = accumulate(vL.begin(), vL.end(), 0);
}

void cFlood::output()
{
	ostringstream oss;
	oss << vL.size() << " ";
	for (int i = 0; i < vL.size(); ++i)
	{
		oss << vL[i] << " ";
	}
	string ans(oss.str());
	ans.rfind(" ");
	ans.replace(ans.rfind(" "),ans.size(), "");
	cout << A << endl;
	cout << ans << endl;
}

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

	string s;
	cin >> s;

	cFlood cf(s);
	cf.calcflood();
	cf.output();

	return 0;
}

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

import itertools

def main():
    N = int(input())
    XY = []

    for _ in range(N):
        a = int(input())
        if a == 0:
            XY.append([])
            continue
        xy = []
        for _ in range(a):
            xy.append(list(map(int,input().split())))
        XY.append(xy)

    bit_list = list(itertools.product([0, 1], repeat=N))

    answer = 0
    for b in bit_list:
        for i in range(N):
            for x,y in XY[i]:
                if b[i] == 1:
                    if b[x-1] == y:
                        continue
                    else:
                        break
                # else:
                #     if b[x-1] != y:
                #         continue
                #     else:
                #         break
            else:
                continue
            break
        else:
            answer = max(sum(b),answer)
    print(answer)

if __name__ == '__main__':
    main()


Measured memory_bytes: 8820
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define pb push_back
#define mp make_pair
#define SPEED ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define MOD 1000000007
#define INF 1e18
#define M 1000000009
#define pi 3.14159265358979323846264338327950
typedef pair<int,int> pr;
#define N 1000002
signed main()
{
    SPEED;
    string s;
    cin>>s;
    for(int i=0;i<s.length();++i)
    {
        if(s[i]=='?')
            s[i]='D';
    }
    cout<<s;
}

Measured memory_bytes: 3744
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

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

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int m = 1e6 + 1;

struct Trie {
    vector<array<int, 26> > trie_nodes = {{}};
    vector<int> sz = {0};
    vector<array<int, 26> > cnt = {{}};

    void push(string s){
        VI last(26, -1);
        REP(i,s.length()) last[s[i] - 'a'] = i;
        int node = 0;
        sz[node]++;
        REP(j,26) if (last[j] >= 0) cnt[node][j]++;
        REP(i,s.length()){
            char c = s[i];
            int x = c - 'a';
            if (!trie_nodes[node][x]){
                trie_nodes[node][x] = trie_nodes.size();
                trie_nodes.push_back({});
                sz.push_back(0);
                cnt.push_back({});
            }
            node = trie_nodes[node][x];
            sz[node]++;
            REP(j,26) if (last[j] > i) cnt[node][j]++;    
        }
    }

    int calc(string s){
        int node = 0;
        REP(i,s.length()-1){
            char c = s[i];
            int x = c - 'a';
            if (!trie_nodes[node][x]) return 0;
            node = trie_nodes[node][x];
        }
        return cnt[node][s.back() - 'a'];
    }
};

int main(void){
    int n;
    cin >> n;
    vector<vector<string>> ss(m);
    REP(i,n){
        string s;
        cin >> s;
        ss[s.length()].push_back(s);
    }

    Trie trie;
    ll ans = 0;

    FORR(n,m-1,1){
        for (string s : ss[n]){
            reverse(ALL(s));
            ans += trie.calc(s);
            trie.push(s);
        }
    }

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


Measured memory_bytes: 238368
sealed class UnionFindTree{
    abstract fun parent(): UnionFindTree
    abstract fun isSameUnion(that: UnionFindTree): Boolean
    abstract fun join(that: UnionFindTree): Unit
    abstract fun hasBoss(): Boolean
    class Boss: UnionFindTree() {
        override fun hasBoss(): Boolean {
            return true
        }

        override fun parent(): UnionFindTree {
            return this
        }

        override fun isSameUnion(that: UnionFindTree): Boolean{
            return that.parent() == this
        }

        override fun join(that: UnionFindTree) {
            if (!isSameUnion(that)) {
                val parent = that.parent()
                when (parent) {
                    is Member -> parent.join(this)
                    else -> throw Exception("Boss Can't Belong Same Union With The Other Boss")
                }
            }
        }
    }

    class Member: UnionFindTree() {
        override fun hasBoss(): Boolean {
            return parent() is Boss
        }

        private var mParent: UnionFindTree? = null
        override fun parent(): UnionFindTree {
            return when(mParent){
                null -> this
                else -> {
                    mParent = mParent?.parent()
                    mParent!!
                }
            }
        }

        override fun isSameUnion(that: UnionFindTree): Boolean {
            return parent() == that.parent()
        }

        override fun join(that: UnionFindTree) {
            if (!isSameUnion(that)){
                val thisParent = parent()
                val thatParent = that.parent()
                if (thisParent is Member){
                    thisParent.mParent = thatParent
                }else if (thatParent is Member){
                    thatParent.mParent = thisParent
                }else throw Exception("Boss Can't Belong Same Union With The Other Boss")
            }
        }
    }
}

fun main(args:Array<String>): Unit {
    val (n, m, k) = readLine()!!.trim().split(' ').map(String::toInt)
    val students = Array(n){UnionFindTree.Member()}
    val clubs = Array(m){UnionFindTree.Boss()}
    repeat(k){count ->
        val (o, a, b) = readLine()!!.trim().split(' ').map(String::toInt)
        when(o){
            1 -> if (students[a - 1].hasBoss() && students[b - 1].hasBoss() && !students[a - 1].isSameUnion(students[b - 1])) {
                println(count + 1)
                return
            }else {
                students[a - 1].join(students[b - 1])
            }
            2 -> if (students[a - 1].hasBoss() && !students[a - 1].isSameUnion(clubs[b - 1])) {
                println(count + 1)
                return
            }else {
                students[a - 1].join(clubs[b - 1])
            }
        }
    }
    println(0)
}


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

int main(){
	int n,t;
	cin >> n >>t;
	vector<int> da(n);
	for (int i=0;i<n;i++){
		cin >> da[i];
	}
	int ans=0;
	for (int i=1;i<n;i++){
		ans+=min(da[i]-da[i-1],t);
	}
	ans+=t;
	cout << ans << endl;
}



Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
  int n;
  cin>>n;
  int a[n][n];
  ll c=0;
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      cin>>a[i][j];
      c+=a[i][j];
    }
  }
  c/=2;
  vector<vector<bool>> b(n,vector<bool>(n,true));
  for(int k=0;k<n;k++){
    for(int i=0;i<n;i++){
      for(int j=i+1;j<n;j++){
        if(k!=i&&k!=j){
          if(a[i][j]>a[i][k]+a[k][j]){
            cout<<-1;
            return 0;
          }else if(a[i][j]==a[i][k]+a[k][j]&&b[i][j]){
            c-=a[i][j];
            b[i][j]=false;
          }
        }
      }
    }
  }
  cout<<c;
}

Measured memory_bytes: 768
#include <cmath>
#include <limits>
#include <iostream>
using namespace std;
 
int main() {
  long long X;
  cin >> X;
  long long count = 0;
  long long A = 100;
  while (A < X) {
    A += A/100;
    count++;
  }
  cout << count << endl;
}

Measured memory_bytes: 3636
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
typedef long long ll;
ll inf = 1000000000;
typedef pair<ll, ll> P;
int main() {
	int a, b;
	cin >> a >> b;
	
	for (int i = 1; i <= 1250; i++) {
		for (int j = 1; j <= 1000; j++) {
			
			if ((a<=i*0.08)&&(i*0.08<a+1)&& (b<=j*0.1)&&(j*0.1<b+1)&&i==j) {
				cout << i << endl;
				return 0;
			}
		}
	}
	cout << "-1" << endl;
	return 0;
}


Measured memory_bytes: 256
N,K=map(int,input().split())
R,S,P=map(int,input().split())
T=input()
l=[]
for i in range(K):
    l.append([T[K-i-1]])
for j in range(K,N):
    if l[K-1-j%K][j//K-1]!=T[j]:
        l[K-1-j%K].append(T[j])
    else:
        l[K-1-j%K].append("t")
ans=0
for k in l:
    ans+=k.count("r")*P+k.count("s")*R+k.count("p")*S
print(ans)
    
    




        




    









        

    









    

        




    















    



    





    






        






    
















        


























            
    


    


    
    














    


    














Measured memory_bytes: 17028
H, W = map(int, input().split())
dp = [list(map(int, input().split())) for _ in range(10)]

for i in range(10):
    for j in range(10):
        for k in range(10):
            dp[j][k] = min(dp[j][k], dp[j][i]+dp[i][k])

ans = 0
for i in range(H):
    line = list(map(int, input().split()))
    for j in line:
        if j == -1: continue
        ans += dp[j][1]

print(ans)





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

int main()
{
	int N;
	cin >> N;
	int A1[N], A2[N];
	for(int i = 0; i < N; i++){
		int tmp;
		cin >> tmp;
		if(i == 0){
			A1[0] = tmp;
		}else{
			A1[i] = tmp + A1[i-1];
		}
	}
	for(int i = 0; i < N; i++){
		int tmp;
		cin >> tmp;
		if(i == 0){
			A2[0] = tmp;
		}else{
			A2[i] = tmp + A2[i-1];
		}
	}

	int ans=0;
	for(int i = 0; i < N; i++){
		int tmp;
		if(i == 0){
			tmp = A1[i] + A2[N-1];
		}else{
			tmp = A1[i] + A2[N-1] - A2[i-1];
		}

		if(tmp > ans)
			ans = tmp;
	}

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


Measured memory_bytes: 256
import sys
#sys.stdin=open("data.txt")
input=sys.stdin.readline

res=[0]*2   # (x+y)%2 should all be the same

coord=[]

n=int(input())
for _ in range(n):
    x,y=map(int,input().split())
    res[(x+y)%2]+=1
    coord.append((x,y))

if res[0] and res[1]: print("-1")
else:
    # get the answer
    d=[]
    for i in range(32)[::-1]:
        d.append(2**i)
    d.append(1)
    d.append(1)
    d.append(1)
    d.append(1)
    d.append(1)
    if res[1]: d.append(1)
    # print answer
    print(len(d))
    print(" ".join(map(str,d)))
    for x,y in coord:
        out=[]
        for i in d:
            best="A"
            bestd=10**10
            if bestd>abs(x+i)+abs(y):
                bestd=abs(x+i)+abs(y)
                best="L"
            if bestd>abs(x-i)+abs(y):
                bestd=abs(x-i)+abs(y)
                best="R"
            if bestd>abs(x)+abs(y+i):
                bestd=abs(x)+abs(y+i)
                best="D"
            if bestd>abs(x)+abs(y-i):
                bestd=abs(x)+abs(y-i)
                best="U"
            out.append(best)
            if best=="L": x+=i
            if best=="R": x-=i
            if best=="D": y+=i
            if best=="U": y-=i
        if x or y: print("bad")
        print("".join(out))


Measured memory_bytes: 54512
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <set>
#include <cmath>
#include <iomanip>
#include <climits>
#define ll long long
#define MOD 1000000007
#define IOS ios::sync_with_stdio(false) ;cin.tie(0) ;cout.tie() ;
using namespace std;
int main(){
IOS
  ll n , k  ;
  cin>>n>> k ;
  ll arr[n] ;

  ll gcd   ;
  ll maxi   = -1 ;
  for(ll i =  0 ;  i  < n ; ++i)
  {
    cin>>arr[i] ;

    maxi =  max(maxi ,arr[i]) ;
  }
  gcd = arr[0] ;

  for(ll i   = 1 ; i  < n ; ++i)
  {
    gcd = __gcd(gcd , arr[i]);
  }

  //cout<<gcd ;

  if(k > maxi || (k % gcd != 0) )
{
 cout<<"IMPOSSIBLE" ;
}
else
cout<<"POSSIBLE" ;




    return 0;
}


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

#define WHITE 0   // not visited yet.
#define GRAY 1    // visited, but not completed.
#define BLACK 2   // search completed.

int G[101][101];        // adjacency list.
int color[101];         // visited/completed sign.
int n;                  // size.
int d[101], f[101], t;  // first visit time/complete time.

void search_loop(int i) 
{
    int next;
    d[i] = ++t;
    color[i] = GRAY;  // first visited.

    for(next = 1; next <= n; next++){
        if(i == next && G[i][i] > 0) break;   // if self-looped, through.
        if(G[i][next] > 0 && color[next] == WHITE){  // if not visited yet, visit.
            search_loop(next);
        }
    }
    f[i] = ++t;
    color[i] = BLACK;  // completed. 

    return;
}

void dfs()
{
    int i;
    for(i = 1; i <= n; i++) color[i] = WHITE;  // initialize.
    t = 0;

    for(i = 1; i <= n; i++) if(color[i] == WHITE) search_loop(i);

    for(i = 1; i <= n; i++) cout << i << " " << d[i] << " " << f[i] << endl;

    return ;
}

int main()
{
    int i, j, k, e;
    cin >> n;
    for(i = 1; i <= n; i++){
        for(j = 1; j <= n; j++){ G[i][j] = 0; } }

    do{
        cin >> i >> e;
        for(j = 1; j <= e; j++){
            cin >> k;
            G[i][k] = 1;
        }
    }while(i < n);

    dfs();
    return 0;
}

Measured memory_bytes: 1200
#include <bits/stdc++.h>
using namespace std;
 
#define FAST ios_base::sync_with_stdio(0); cin.tie(); cout.tie();
 
#define MAXX 100005
 
#define PI 3.14159265358979323846264338327950
 
#define F first
#define S second
 
#define ll 	 long long int
 
#define mod  1000000007
 
vector<int> v1(MAXX);
vector<int> v2(MAXX);
 
int main()
{
	FAST;
	ll n;
	cin >> n;
	ll x;
	for(ll i = 1; i <= n; i ++){
		cin >> x;
		if(i % 2){
			v1[x] ++;
		}
		else{
			v2[x] ++;
		}
	}
	vector< pair <int , int> > v3; 
	vector< pair <int , int> > v4;
	for(ll i = 1; i <= 100000; i ++){
		if(v1[i]){
			v3.push_back({v1[i], i});
		}
		if(v2[i]){
			v4.push_back({v2[i], i});
		}
	}
	if(v3.size() == 1){
		v3.push_back({0, 0});
	}
	if(v4.size() == 1){
		v4.push_back({0, 0});
	}
	sort(v3.begin() , v3.end());
    reverse(v3.begin() , v3.end());
    sort(v4.begin() , v4.end());
    reverse(v4.begin() , v4.end());
    ll ans = 0;
    ll a = v3[0].F;
    ll b = v3[0].S;
    ll c = v3[1].F;
    ll d = v3[1].S;
    ll e = v4[0].F;
    ll f = v4[0].S;
    ll g = v4[1].F;
    ll h = v4[1].S;
    if(b != f){
    	ans = n - a - e;
	}
	else{
		ans = min(n - a - g, n - c - e);
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 4948
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
using namespace std;

int main(){
    string s;
    int n;
    cin >> s >> n;
    string order, rep;
    int a, b;
    for(int i = 0; i < n; i ++){
        cin >> order >> a >> b;
        if(order == "replace"){
            cin >> rep;
            s.replace(a, b - a + 1, rep);
        }else if(order == "reverse"){
            reverse(s.begin() + a, s.begin() + b + 1);
        }else{
            cout << s.substr(a, b - a + 1) << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3184
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
 
const ll mod=1000000007;
 
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
 
int test = 1;
const int N = 2e5+10;
 
long long int maxi[N];
vector<ll> size(N,1);
ll comp[N];
vector<ll> adj[N];
vector<int> vis(N);
 
void solve(){
 	long long int n;
 	cin >> n;
 	long long int sum = 0;
 	for(int i=1;i<=n;i++){
 		if(i%3==0 || i%5==0)
 			continue;
 		else sum+=i;
 	}
	cout << sum << endl;
}
 
 
int main() {
	#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
 
	#endif
	// int t;cin >> t;while(t--)
	solve();
	
	}

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

int n, ans, a;

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> n;
    for (int i = 0; i < n; ++i)
        cin >> a,
        ans ^= a;
    cout << (!ans ? "Yes" : "No") << '\n';
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define  ft  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define  ll  long long
#define  pi  pair<int,int>
#define  pb  push_back
#define  F   first
#define  S   second
const int N=2e5+3;
string s;
int main()
{
    ft
    ll t,i,j,n,m,l=0,r;
    cin>>s;
    n=s.size();
    for(i=0,j=n-1;i<j;i++,j--)
    {
        if(s[i]!=s[j])
        {
            l++;
        }
    }
    cout<<l<<"\n";
    return 0;
}



Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Scanner;

class Main{

	static int N;
	static int M;
	static 		ArrayList<ArrayList<Integer>> map;
	static boolean[] used;
	static int f = 0;
	static int s = 0;

	static long mod = 1000000007;
	static ArrayList<Integer> saitan;




	public static void main(String[] args) {


		Scanner sc = new Scanner(System.in);			//文字の入力
		int n = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();
		long[] h = new long[n];


		for(int i = 0;i < n;i++){
			h[i] = sc.nextLong();
		}


		long min = 0;
		long max = 1000000000;
		long T = 0;
		int k= 0;

		while(max - min > 1){
			T =( max + min)/2;
			k = 0;
			for(int i = 0;i <n;i++){
				if(h[i] > b*T){
					k += Math.ceil( (double)(h[i] - b*T) / (double)(a-b));
				}
			}

			if(k > T){
				min = T;
			}else{
				max = T;
			}


		}
		System.out.println(max);






	}


}




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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MOD (1000000007)
#define ALL(v) (v).begin(), (v).end()
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, p;
    cin >> a >> p;
    cout << (3 * a + p) / 2 << endl;
}

Measured memory_bytes: 256
use std::io;


fn main() {
    let n = read_one::<usize>();
    let ans = (1..=n).map(|i| {
        let x = n / i;
        x * (1 + x) * i / 2
    }).sum::<usize>();
    println!("{}", ans);
}


#[allow(unused)]
fn read<T>() -> Vec<T>
where
    T: std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}


#[allow(unused)]
fn read_one<T>() -> T
where
    T: std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}


Measured memory_bytes: 2132
#include<bits/stdc++.h>
#define debug(x) cout << #x << " = " << x << endl
typedef unsigned long long ull;
typedef long long ll;
using namespace std;
const int N=100000;
int a[N],n,m;
int main()
{
	cin >> n>>m;
	if(n%500<=m)
		cout << "Yes";
	else
		cout << "No";

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<set>
#include<regex>
#include<ctype.h>
using namespace std;

int main(void) {
	double n, t, a;
	cin >> n >> t >> a;
	vector<double> h(n);

	double ans, ans_num;
	for (int i = 0; i < n; i++) {
		cin >> h[i];
		double tmp = abs(a - (t - h[i] * 0.006));

		if (i == 0) ans = tmp;
		else ans = min(ans, tmp);

		if (ans == tmp) ans_num = i;
	}

	cout << ans_num + 1 << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
template<class T> inline bool chmax(T &a, T b) { if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) { if (b<a) {a=b; return 1;} return 0;}

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

    int n, W;
    cin >> n >> W;
    vi v(n), w(n);
    rep(i, n) cin >> v[i] >> w[i];
    const ll inf = 1LL<<60;
    vvll dp(n+1, vll(10500, inf));
    dp[0][0] = 0;
    rep(i, n) {
        rep(j, 10001) {
            chmin(dp[i+1][j], dp[i][j]);
            chmin(dp[i+1][j+v[i]], dp[i][j] + w[i]);
        }
    }
    int ans = 0;
    rep(i, 10001) if (dp[n][i] <= W) chmax(ans, i);
    cout << ans << endl;
}



Measured memory_bytes: 11316
// finish date: 2019/07/20

#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for(int (i)=a;(i)<(b);(i)++)
#define rep(i, n)  FOR(i,0,n)
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<double> vd;
typedef vector<vector<double>> vvd;
typedef vector<vector<vector<double>>> vvvd;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, pair<int, int>> plii;
const int bigmod = 1000000007;
const int INF = 1050000000;
const long long INFll = 100000000000000000;


int main() {
    int N;
    cin >> N;
    vi A(N);
    rep(i, N) cin >> A[i];
    vi seq(N, INF);
    int cnt = 0;
    rep(i, N) {
        auto Iter = upper_bound(seq.begin(), seq.end(), -A[i]);
        if (*Iter == INF) cnt++;
        *Iter = -A[i];
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 1024
import math
n=[]
for i in range(5):
  n.append(int(input()))
l=[]
for i in range(5):
  l.append(10*(math.ceil(n[i]/10)))
samax=0
for i in range(5):
  ans=l[i]-n[i]
  samax=max(ans,samax)
print(sum(l)-samax)


Measured memory_bytes: 3060
#include <stdio.h>
int H;
 
int left(int x){return 2*x;}
int right(int x){return 2*x+1;}
void maxHeapify(int A[], int i);
void buildMaxHeap(int A[]);
 
int main(){
  int i;
  int *A;
  scanf("%d",&H);
A = (int *)malloc(sizeof(int)*H);
  for(i=1;i<=H;i++){
    scanf("%d",&A[i]);
  }
  buildMaxHeap(A);
  for(i=1;i<=H;i++){
    printf(" %d",A[i]);
  }
  puts("");
 
  return 0;
}
 
 
 
 
void maxHeapify(int A[], int i){
  int l,r,tmp;
  int largest;
  l = left(i);
  r = right(i);
  if(l <= H && A[l] > A[i]){
    largest = l;
  } else {
    largest = i;
  }
  if(r <= H && A[r] > A[largest]){
    largest = r;
  }
  if(largest !=i){
    tmp = A[i];
    A[i]=A[largest];
    A[largest]= tmp;
    maxHeapify(A,largest);
  }
 
}void buildMaxHeap(int A[]){
  int i;
  for(i = H/2;i > 0;i--){
    maxHeapify(A,i);
  }
}

Measured memory_bytes: 2564