akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <set>

using namespace std;

//string
//.resize(i)
//.substr(i)

//set
//.insert(s)
//.count(s)

int main(){
	int M;
	string S;
	cin >> M;
	for(int i = 0; i < M; i++){
		cin >> S;
		set<string> A;
		A.insert(S);
		for(int i = 0; i < S.size(); i++){
			string L = S;
			L.resize(i);
			string R;
			R = S.substr(i);
			string L2, R2;
			for(int i = L.size() - 1; i >= 0; i--) L2 += L[i];
			for(int i = R.size() - 1; i >= 0; i--) R2 += R[i];
			A.insert(L+R);
			A.insert(L2+R);
			A.insert(L+R2);
			A.insert(L2+R2);
			A.insert(R+L);
			A.insert(R+L2);
			A.insert(R2+L);
			A.insert(R2+L2);
		}
		cout << A.size() << endl;
	}
	return 0;
}

Measured memory_bytes: 1304
nums = list(input())
def dfs(res, depth, path, S):
    if depth >= len(S) - 1:
        res.append(path)
        return 
    for char in ['+', '-']:
        dfs(res, depth+1, path+[char], S)

res = []
dfs(res, 0, [], nums)

for comb in res:
    calc = int(nums[0]) 
    string = nums[0]
    for i, func in enumerate(comb):
        if func == '+':
            string += '+' + nums[i+1]
            calc += int(nums[i+1])
        elif func == '-':
            string += '-' + nums[i+1]
            calc -= int(nums[i+1])
    if calc == 7:
        break

print(string+'=7')

Measured memory_bytes: 3064
#include<cstdio>
#include<algorithm>
using namespace std;

const int N = 1000000;
int dp[2][N+1],nxt,val,n;

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

  val = 1;
  for(int i=1;val<=N;i++){
    for(int j=0;j+val<=N;j++){
      nxt = j+val;
      dp[0][nxt] = min(dp[0][nxt],dp[0][j] + 1);
      if(val&1)dp[1][nxt] = min(dp[1][nxt],dp[1][j] + 1);
    }
    val = i*(i+1)*(i+2)/6;
  }

  while(scanf("%d",&n),n)printf("%d %d\n",dp[0][n],dp[1][n]);
}

Measured memory_bytes: 8840
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
int main()
{
    int n,w,i,j;
    scanf("%d %d",&n,&w);
    lli dp[n+1][w+1],weight[n],value[n];
    for(i=0;i<n;i++)
    scanf("%lld %lld",&weight[i],&value[i]);
    for(i=0;i<=n;i++)
    {
        for(j=0;j<=w;j++)
        {
            if(i==0||j==0)
            dp[i][j]=0;
            else if((j-weight[i-1])>=0)
            dp[i][j]=max(dp[i-1][j],value[i-1]+dp[i-1][j-weight[i-1]]);
            else
            dp[i][j]=dp[i-1][j];
        }
    }
    printf("%lld",dp[n][w]);
} 

Measured memory_bytes: 82632
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = s; i < n; ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define tmax(a,b,c) max(a,max(b,c))
#define tmin(a,b,c) min(a,min(b,c))
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vs vector<string>
#define vc vector<char>
#define vb vector<bool>
#define vp vector<P>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class T> istream& operator>>(istream& is,vector<T>& v) { for(T& t:v){is>>t;} return is; }
template<class T> ostream& operator<<(ostream& os,const vector<T>& v) { for(T t:v){os<<t<<" ";} os<<"\n"; return os; }
void Yes(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YES(bool b) { cout << (b ? "YES" : "NO") << endl; }
template<class T> inline bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> inline bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    int k,a,b;
    cin >> k >> a >> b;
    int kk = k;
    while(true) {
        if(a <= k && k <= b) {
            cout << "OK" << endl;
            return 0;
        } else if (k < a) k += kk;
        else break;
    }
    cout << "NG" << endl;
}


Measured memory_bytes: 3656
#include <algorithm>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<long long> a(n), s(n + 1);
  for (int i = 0; i < n; i++)
    cin >> a[i];
  for (int i = 0; i < n; i++)
    s[i + 1] = s[i] + a[i];
  long long dp[n + 1][n + 1];
  for (int i = 0; i < n; i++) {
    dp[i][i + 1] = 0;
  }
  long long INF = 1LL << 60;
  for (int k = 2; k <= n; k++) {
    for (int i = 0; i + k <= n; i++) {
      dp[i][i + k] = INF;
      for (int j = 1; j < k; j++) {
        dp[i][i + k] = min(dp[i][i + k],
                           dp[i][i + j] + dp[i + j][i + k] - s[i] + s[i + k]);
      }
    }
  }
  cout << dp[0][n] << endl;
  return 0;
}


Measured memory_bytes: 1536
#include <set>
#include <map>
#include <queue>
#include <ctime>
#include <cmath>
#include <cstdio>
#include <bitset>
#include <vector>
#include <cstring>
#include <cassert>
#include <iostream>
#include <algorithm>
using namespace std;
typedef double db;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pa;
typedef unsigned int uint;
typedef unsigned long long ull;
#define w1 first
#define ls (x<<1)
#define w2 second
#define ins insert
#define rs (x<<1|1) 
#define mp make_pair
#define pb push_back
#define mid ((l+r)>>1)
#define sqr(x) ((x)*(x))
#define cle(x) ((x).clear())
#define lowbit(x) ((x)&(-x))
#define SZ(x) (int((x).size()))
#define ms(x,y) memset(x,y,sizeof (x))
#define rep(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)
#define rep2(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define per(i,a,b) for(int (i)=(a);(i)>=(b);(i)--)
#define Rep(p,x) for(int (p)=head[(x)];(p);(p)=nxt[(p)])
#define Rep2(p,x) for(int (p)=cur[(x)];(p);(p)=nxt[(p)])
template<class T>inline void rread(T&num){
	num=0;T f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9')num=num*10+ch-'0',ch=getchar();
	num*=f;
}
inline int getgcd(int x,int y){if(!x)return y;return getgcd(y%x,x);}
inline int power(int x,int k,int p){int res=1;for(;k;k>>=1,x=(ll)x*x%p)if(k&1)res=(ll)res*x%p;return res;}
const double pi=acos(-1);
inline void judge(){
	freopen("input.txt","r",stdin);
} 
//********************************head*************************************
int main(){
	int n;rread(n);
	int x=n*800;
	int y=(n/15)*200;
	printf("%d\n",x-y);
	return 0;
}

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



using namespace std;

typedef vector<int> VI;
typedef vector<string> VS;


//container util
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)



int main(void){

	int A, B, K; cin >> A >> B >> K;
	set<int> st; 
	for(int i=A;i < min(A+K,B+1);++i) st.insert(i);
	for(int i=B;i > max(B-K,A-1);--i) st.insert(i);

	for(auto t:st){
		cout << t << endl;
	}



	return 0;

}


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

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

    if(a >= 13)
    {
        cout << b << endl;
    }
    else if(a >= 6 && a <= 12)
    {
        cout << b / 2 << endl;
    }
    else
    {
        cout << 0 << endl;
    }
}

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

#define pb push_back

using namespace std;

const int MXN = 1e5+5;

int N, M, x, y, ans = 0;
int seen[MXN];
vector<int> edges[MXN];

int dfs(int c)
{
	if (seen[c] == -1) {
		int biggest = 0;
		for (int neighbour : edges[c]) {
			dfs(neighbour); biggest = max(biggest,seen[neighbour]+1);
		} 
		seen[c] = biggest;
	}
	return seen[c];
}

int main()
{
	ios::sync_with_stdio(0); cin.tie(0);
	cin >> N >> M;
	for (int i=0;i<M;++i) {
		cin >> x >> y;
		edges[x].pb(y);
	}
	for (int i=0;i<MXN;++i) seen[i] = -1;
	for (int i=1;i<=N;++i) {
		dfs(i);
		ans = max(ans,seen[i]);
	}
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 12184
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include <iomanip>
using namespace std;

int main(){
    long long int n,k,m=1000000000;
    cin>>n>>k;
    vector<long long int>a(1000000);
    for(long long int i=0;i<n;i++){
        cin>>a[i];
    }
    sort(a.begin(),a.end(),std::greater<>());
    for(long long int i=0;i<=n-k;i++){
        if(m>a[i]-a[i+k-1]){
            m=a[i]-a[i+k-1];
        }
    }
    cout<<m<<endl;

    return 0;
}

Measured memory_bytes: 8064
import fractions

def a(A, B):
    C = fractions.gcd(A, B)
    return (A * B)//C

N = int(input())

T = []

for _ in range(N):
    T.append(int(input()))

T = sorted(T)
C = T[0]

if N > 1:
    for i in range(1, N):
        C = a(C, T[i])
print(C)


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

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int main() {
    int r, g, b;
    cin >> r >> g >> b;

    if( (10 * g + b) % 4 == 0 )
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
             
    return 0;
}

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

int main()
{
	int n;
	char yaku;
	int kazu;
	bool a[5][52] = { false };

	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> yaku >> kazu;
		switch (yaku) {
		case 'S':
			a[0][kazu] = true;
			break;
		case 'H':
			a[1][kazu] = true;
			break;
		case 'C':
			a[2][kazu] = true;
			break;
		case 'D':
			a[3][kazu] = true;
			break;
		}
	}
	for (int i = 0; i < 4; i++) {
		for (int j = 1; j < 14; j++) {
			if (i==0&&a[i][j]==false) cout << 'S' << " " << j<<endl;
			else if (i == 1 && a[i][j] == false) cout << 'H' << " " << j<<endl;
			else if (i == 2 && a[i][j] == false) cout << 'C' << " " << j<<endl;
			else if (i == 3 && a[i][j] == false) cout << 'D' << " " << j << endl;
			
		}
	}
    return 0;
}

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

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

int func(int N){
  if(N < 10){return N;}
  return  func(N/10) + N%10;
}

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

  int a = func(N);

  if(N % a == 0){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }

}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>

int main(){
   const int MAX_P = 101;
   int N;
   std::cin >> N;
   int P;
   std::string S;
   std::vector<std::pair<std::string, std::pair<int, int> > > SP(N);
   for(int i=0; i<N; ++i){
      std::cin >> S >> P;
      SP[i] = std::make_pair(S, std::make_pair(100 - P, i+1));
   }
   std::sort(SP.begin(),SP.end());

   for(int i=0; i<N; ++i){
      std::cout << SP[i].second.second << std::endl;
   }
   return 0;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mod 1000000007
//#define mod 998244353
#define N 1000001
#define ll long long int
#define pr pair<ll,ll>
#define ff first
#define ss second
#define pub push_back
#define pob pop_back
#define f(i,a,b) for(ll i=a;i<=b;i++)
#define r(i,a,b) for(ll i=a;i>=b;i--)
#define ms(a,b) memset(a,b,sizeof(a))
#define line cout<<'\n'
#define all(v) v.begin(),v.end()
#define rev(s) reverse(all(s))
using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll tt = 1;
    //cin>>tt;
    f(t,1,tt){
        ll k; cin>>k;
        string s; cin>>s;
        ll n = s.size();
        if(n<=k) cout<<s;
        else cout<<s.substr(0,k)<<"...";
    }
    return 0;
}

Measured memory_bytes: 3640
from collections import Counter
N = int( input())
A = list( map( int, input().split()))
CA = Counter(A)
V = []
for x in CA:
    if CA[x] >= 2:
        V.append(CA[x]-1)
V.sort(key = None, reverse = True)
now = 0
ans = 0
for v in V:
    ans += v
    if now <= 0:
        now += v
    else:
        now -= v
b = abs(now)
if b%2 == 1:
    ans += 1
else:
    pass
print( max(N-ans,0))

Measured memory_bytes: 18656
import java.math.BigDecimal;
import java.util.*;

public class Main {

    Scanner sc = new Scanner(System.in);

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

    void run() {

        long n = sc.nextLong();

        StringBuilder sb = new StringBuilder();

        while (n != 0) {
            long remain = n % 26;
            n /= 26;
            char c = remain==0 ? 'z' : (char)(remain+96);
            if (remain==0) n--;
            sb.append(c);
        }

        sb = sb.reverse();

        System.out.print(sb.toString());

    }
}


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

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

	int N = S.size();
	string ans = "No";
	int cnt = 0;
	for( int i = 0; i < N - 1; i++ ) {
		if( S[i] == 'h' && S[i + 1] == 'i' ) {
			cnt++;
			i++;
		}
	}
	if( N && cnt * 2 == N ) ans = "Yes";

	cout << ans << endl;
}


Measured memory_bytes: 256
use std::io;

fn procon_read<T: std::str::FromStr>() ->  Vec<T> {
	let mut buf = String::new();
	io::stdin().read_line(&mut buf).expect("");
	let iter = buf.split_whitespace();
	let mut v: Vec<T> = Vec::new();
	for i in iter {
		v.push(i.parse().ok().unwrap());
	}
	v
}

fn main() {
	let v:Vec<i32> = procon_read();
	let n = v[0];
	let m = v[1];
	let a:Vec<i32> = procon_read();
	let mut sum = 0;
	for i in 0..n {
		sum += a[i as usize];
	}
	let mut cnt = 0;
	for i in 0..n {
		if a[i as usize] >= (sum+4*m - 1)/(4*m) {
			cnt += 1;
		}
	}
	if cnt >= m {
		println!("Yes");
	}else{
		println!("No");
	}
}

Measured memory_bytes: 2136
N,M,X,Y = list(map(int,input().split()))
A = list(map(int,input().split()))
B = list(map(int,input().split()))
Xmax = max(A)
Ymin = min(B)
out = "War"
Xmax = max(Xmax,X)
Ymin = min(Ymin,Y)
if Xmax<Ymin:
    out = "No War"
print(out)


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

#define GET_MACRO(_1,_2,_3,_4,NAME,...) NAME
#define REP2(i,n) for(int i=0;i<(int)(n);i++)
#define REP3(i,m,n) for(int i=m;i<(int)(n);i++)
#define REP4(i,m,n,s) for(int i=m;(s>0 and i<(int)(n)) or (s<0 and i>(int)(n));i+=s)
#define REP(...) GET_MACRO(__VA_ARGS__, REP4, REP3, REP2)(__VA_ARGS__)
#define REPIT(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define PIS(x) printf("%d ",x)
#define PN() putchar('\n')
#define MP make_pair
#define PB push_back
#define EB emplace_back

typedef pair<int,int> PII;
typedef long long LL;
typedef unsigned long long ULL;

void RI() {}
template<typename... T>
void RI( int& head, T&... tail ) {
    scanf("%d", &head);
    RI(tail...);
}
void print() {putchar('\n');}
template<typename T, typename... U>
void print(T head, U... tail) {
    cout << head << " ";
    print(tail...);
}

const int MOD = 1000000007;
#define MAX_N 100005
LL A[MAX_N], B[MAX_N], C[MAX_N];
LL D[MAX_N];
LL MA[MAX_N], MB[MAX_N];
int idx[MAX_N];
priority_queue<LL, vector<LL>, greater<LL> > qA, qB;

int main()
{
    int x, y, z;
    RI(x, y, z);

    int n = x + y + z;
    REP(i, n) {
        scanf("%lld%lld%lld", &A[i], &B[i], &C[i]);
        A[i] -= C[i];
        B[i] -= C[i];
        D[i] = A[i] - B[i];
        idx[i] = i;
    }
    sort(idx, idx + n,
        [](const int a, const int b) {
            return D[a] < D[b];
        }
    );
//    REP(i, n) {
//        printf("%3lld ", A[idx[i]]);
//    }
//    PN();
//    REP(i, n) {
//        printf("%3lld ", B[idx[i]]);
//    }
//    PN();

    REP(k, n) {
        LL b = B[idx[k]];

        if(k > 0) {
            MB[k] = MB[k-1];
        }

        if((int)qB.size() < y) {
            MB[k] += b;
            qB.push(b);
        } else if(b > qB.top()) {
            MB[k] += b - qB.top();
            qB.pop();
            qB.push(b);
        }
    }

    REP(k, n-1, -1, -1) {
        LL a = A[idx[k]];

        if(k < n-1) {
            MA[k] = MA[k+1];
        }

        if((int)qA.size() < x) {
            MA[k] += a;
            qA.push(a);
        } else if(a > qA.top()) {
            MA[k] += a - qA.top();
            qA.pop();
            qA.push(a);
        }
    }

    LL M = LLONG_MIN;
    REP(i, y-1, n-x) {
        M = max(M, MA[i+1] + MB[i]);
        //print(i, MA[i+1], MB[i], MA[i+1] + MB[i]);
    }
    REP(i, n) {
        M += C[i];
    }
    printf("%lld\n", M);
    return 0;
}


Measured memory_bytes: 6392
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int,int> P;
#define k_p make_pair


int main()
{
    int n,x,y;
    while(cin>>n>>x>>y)
    {
        vector<int> cnt(n);
        for(int i=1;i<=n;i++)
            for(int j=i+1;j<=n;j++)
            {
                cnt[min( j-i, abs(x-i)+abs(y-j)+1)]++;//throuhg the x-y or not
            }
        for(int i=1;i<=n-1;i++)
            cout<<cnt[i]<<endl;

    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
#include <stdio.h>
#include <cmath>
#include <math.h>
#include <sstream>
#include <iomanip>
#include <time.h>
#include <fstream>

using namespace std;

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

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(){
    int W,H,x,y,r;
    cin >> W >> H >> x >> y >> r;
    if((x-r)>=0 && (x+r)<=W && (y-r)>=0 && (y+r)<=H) cout << "Yes" << endl;
    else cout << "No" << endl;
    
    return 0;
}


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

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll a,b,n,len1,len2,c=0;
	cin>>n;
	bool f=true;
	bool z=false;
	cin>>a;
	c=a;
	if(a==0)z=true;
	for(ll i=1;i<n;i++){
		cin>>b;
		len1=to_string(a).length();
		len2=to_string(b).length();
		if(len1+len2>20)f=false;
		if(len1+len2==19 ||len1+len2==20 ){
			if(a*b>1000000000000000000) f=false;
		}
		a*=b;
		if(a<c) f=false;
		c=a;
		if(b==0)z=true;
	}
	if(z){
		cout<<0<<endl;
		return 0;
	}
	if(f){
		cout<<a<<endl;
	}else{
		cout<<-1<<endl;
	}
}


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

int main()
{
    int n;
    cin >> n;
    vector<ll> A(n), B(n);
    rep(i, n) cin >> A[i] >> B[i];

    ll rui = 0;
    for (int i = n - 1; i >= 0; i--)
    {
        A[i] += rui;
        if (A[i] % B[i] != 0)
        {
            rui += B[i] - A[i] % B[i];
        }
    }

    cout << rui << endl;
}

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

int main()
{
    int n,m; cin>>n>>m;
    long tmp,sum=0;

    priority_queue<long, vector<long>, less<long>> Q;

    for(int i=0;i<n;++i){
        cin>>tmp;
        Q.push(tmp);
    }
    

    for(int i=0;i<m;++i){
        tmp = Q.top();
        tmp = tmp/2;
        Q.pop();
        Q.push(tmp);
    }
    
    for(int i=0;i<n;++i){
        tmp = Q.top();
        Q.pop();
        sum+=tmp;
    }
    
	cout<<sum<<endl;
}

Measured memory_bytes: 1400
#include <bits/stdc++.h>
#define int long long
#define double long double
using namespace std;
signed main() {
  int prices[] = { 6000, 4000, 3000, 2000 };
  for (int i = 0; i < 4; i++) {
    int t, n;
    cin >> t >> n;
    cout << prices[t-1]*n << endl;
  }
}



Measured memory_bytes: 3096
package main

import (
	"bufio"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
)

var (
	readString func() string
	stdout     *bufio.Writer
)

func init() {
	readString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readInt()
	}
	return b
}

func readLengthAndSlice() []int {
	n := readInt()
	return readIntSlice(n)
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func minInt(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func minUint(a, b uint) uint {
	if a < b {
		return a
	}
	return b
}

func minInt64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

func minUint64(a, b uint64) uint64 {
	if a < b {
		return a
	}
	return b
}

func maxInt(a, b int) int {
	if a < b {
		return b
	}
	return a
}

func maxUint(a, b uint) uint {
	if a < b {
		return b
	}
	return a
}
func maxInt64(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}

func maxUint64(a, b uint64) uint64 {
	if a < b {
		return b
	}
	return a
}

func absInt(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func absInt64(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

// readString() string
// readInt() int
// readIntSlice(n int) []int
// readLengthAndSlice() []int
func main() {
	defer stdout.Flush()

	N := readInt()
	a := make([]int, N)
	for i := range a {
		a[i] = readInt()
	}

	min := math.MaxInt32
	for b := -100; b <= 200; b++ {
		var tmp int
		for i := range a {
			x := absInt(a[i] - b)
			tmp += x * x
		}
		min = minInt(min, tmp)
	}

	println(min)

}


Measured memory_bytes: 640
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main(){
	int cnt[4]={0} ,i;
	char s[4];
	cin>>s;
	for(i=0;i<3;i++){
		cnt[s[i]-'a']++;

	}
	int f=1;
	for(i=0;i<3;i++){
	//	cout<<cnt[i];
		if(cnt[i]==0)
			f=0;
	}
	if(f)
		cout<<"Yes";
	else
		cout<<"No";
}

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

using namespace std;

int main()
{
	int H, W;
	int count = 0;

	cin >> H >> W;

	string A;
	for (int i = 0; i < H; i++)
	{
		cin >> A;

		for (int j = 0; j < W; j++)
		{
			if (A[j] == '#')
				count++;
		}
	}

	if (count == H + W - 1)
		cout << "Possible" << endl;
	else
		cout << "Impossible" << endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define fi first
#define se second
using Graph=vector<vector<int>>;

void dfs(int s,Graph graph,vector<int> &d,vector<int> &f,int &flag1,int &flag2)
{
	int n=graph.size();
	d[s]=flag1;
	flag1++;
	for (int i=0;i<n;i++)
	{
		if (graph[s][i]==1 && d[i]==-1) dfs(i,graph,d,f,flag1,flag2);
	}
	f[s]=flag2;
	flag2++;
}
int main()
{
	int n;cin >> n;
	Graph graph(n,vector<int> (n,0));
	int u,k,v;
	for (int i=0;i<n;i++)
	{
		cin >>u;
		cin >>k;
		for (int j=0;j<k;j++)
		{
			cin >>v;
			graph[u-1][v-1]=1;
		}
	}
	int flag1=1,flag2=1;
	vector<int> d(n,-1),f(n-1);
	for (int i=0;i<n;i++)
	{
		if (d[i]==-1) dfs(i,graph,d,f,flag1,flag1);
	}
	
	for (int i=0;i<n;i++)
	{
		cout <<i+1 <<" " << d[i] <<" " << f[i] << endl;
	}
	return 0;
}


Measured memory_bytes: 7296
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define prtd(var, i) cout << fixed << setprecision(i) << var << endl;
#define ll long long
using namespace std;

int main(){
    int s; cin >> s;
    int cnt = 0;
    vector<int> a;
    a.push_back(s);
    while(true){
        cnt++;
        if(s % 2 == 0){
            s /= 2;
        }else{
            s = 3*s + 1;
        }
        rep(i, a.size()){
            if(a[i] == s) {
                cout << cnt+1 << endl;
                return 0;
            }
        }
        a.push_back(s);
    }


}


Measured memory_bytes: 256
n = int(input())
s = list(map(int, list(input())))
numbers = [0 for _i in range(1000)]
right, left = [[0 for _j in range(10)] for _i in range(n)], [[0 for _j in range(10)] for _i in range(n)]
for i in range(1, n):
    left[i] = left[i-1].copy()
    left[i][s[i-1]] += 1
for i in range(2, n+1):
    right[-i] = right[-i+1].copy()
    right[-i][s[-i+1]] += 1

for i in range(n):
    for x in range(10):
        for y in range(10):
            if right[i][x]>0 and left[i][y]>0:
                numbers[100*x+10*s[i]+y] = 1
print(sum(numbers))

Measured memory_bytes: 17776
#include<iostream>
#include<stdio.h>
#define ll long long
using namespace std;
int main()
{
    ll n;
    string s;
    cin>>n>>s;
    ll count=0;
    //ll len= s.size();
    for(ll i=0;i<n-2;i++)
    {
        if(s[i]=='A')
        {
            if(s[i+1]=='B')
            {
                if(s[i+2]=='C')
                {
                    count++;
                    i+2;
                }
            }
        }
    }
    cout<<count<<endl;
}



Measured memory_bytes: 256
from collections import deque

def main():
    n, m, q = map(int, input().split())
    abcd = [None for _ in range(q)]
    for i in range(q):
        abcd[i] = list(map(int, input().split()))

    ans = 0
    que = deque()
    que.append([])
    while que:
        now = que.popleft()
        if len(now) < n:
            minimum = (now[-1] if now else 1)
            for i in range(minimum, m+1):
                next = list(now)
                next.append(i)
                que.append(next)
        else:
            score = 0
            for x in abcd:
                if now[x[1]-1] - now[x[0]-1] == x[2]:
                    score += x[3]
            if score > ans:
                ans = score

    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 102964
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//namespace mp = boost::multiprecision;

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<int> &o) {
    int a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;


class WarchallFloyd {

    int n;
    vector<vector<ll>> distances;

public:
    WarchallFloyd(int n) : n(n), distances(n, vector<ll>(n, INF)) {
        rep(i, n) distances[i][i] = 0;
    };

    void warshall_floyd() {
        for (int k = 0; k < n; k++) {       // 経由する頂点
            for (int i = 0; i < n; i++) {    // 始点
                for (int j = 0; j < n; j++) {  // 終点
                    if (distances[i][j] == INF && (distances[i][k] == INF || distances[k][j] == INF)) {
                        distances[i][j] = INF;
                    } else {
                        distances[i][j] = min(distances[i][j], distances[i][k] + distances[k][j]);
                    }
                }
            }
        }
    }

    ll distance(int from, int to) {
        return distances[from][to];
    }

    void add(int from, int to, ll cost) {
        distances[from][to] = cost;
        distances[to][from] = cost;
    }


    friend std::istream &operator>>(std::istream &in, WarchallFloyd &o) {
        int from, to;
        ll c;
        cin >> from >> to >> c;
        from--;
        to--;

        o.distances[from][to] = c;
        o.distances[to][from] = c;
        return in;
    }
};


int main() {
    int n, m;
    ll l;
    cin >> n >> m >> l;

    WarchallFloyd wf1(n);
    rep(_, m) {
        int a, b;
        ll c;
        cin >> a >> b >> c;
        a--;
        b--;

        wf1.add(a, b, c);
    }
    wf1.warshall_floyd();

    WarchallFloyd wf2(n);
    rep(i, n) {
        rep(j, n) {
            if (wf1.distance(i, j) <= l) {
                wf2.add(i, j, 1);
            } else {
//                wf2.add(i, j, 1);
            }
        }
    }
    wf2.warshall_floyd();

    int q;
    cin >> q;
    rep(_, q) {
        int s, t;
        cin >> s >> t;
        s--;
        t--;
        ll now = wf2.distance(s, t);
        ll ans = now == INF ? -1 : now - 1;
        cout << ans << endl;

    }
}


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

int main()
{
  int N;
  cin >> N;
  for (int i = 1; i < 10; ++i)
  {
    for (int j = i; j < 10; ++j)
    {
      if (i * j == N)
      {
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(int (i) = 0; i < (n); i++)
#define REP(i, m, n) for(int (i) = (m); (i) < (n); (i)++)
#define INF LLONG_MAX - 10
#define MOD 1000000007
#define fcout cout << fixed << setprecision(15)
#define int long long
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)?"YES":"NO")
typedef long long ll;
typedef pair<int, int> P;
typedef priority_queue<int> pque;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a*b/gcd(a,b);};
int mod(int a,int b){return (a+b-1)/b;};
int month[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
template<typename A, size_t N, typename T>
void Fill(A(&array)[N],const T &val){std::fill((T*)array,(T*)(array+N),val);}
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;};



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

 	int w, h, c;
    cin >> w >> h >> c;
    int g = gcd(h, w);
    cout << (w / g) * (h / g) * c << endl;
}



Measured memory_bytes: 3220
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
using ll = long long;
using P = pair<int, int>;

int main(){
    int a, b; cin >> a >> b; 
    cout << a * b << endl;
}

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

map<long, int> pf(long n) {
  map<long, int> ma;
  for (long i = 2; i * i <= n; i++) {
    while (n % i == 0) ma[i]++, n /= i;
  }
  if (n != 1) ma[n]++;
  return ma;
}

int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) cin >> A.at(i);

  int G = 0;
  for (int i = 0; i < N; i++) {
    G = gcd(G, A.at(i));
  }
  if (G >= 2) return cout << "not coprime" << "\n", 0;

  vector<int> V(1e6+1);
  for (int i = 0; i < N; i++) {
    for (auto [a, b] : pf(A.at(i))) {
      if (V.at(a)) return cout << "setwise coprime" << "\n", 0;
      else V.at(a)++;
    }
  }
  cout << "pairwise coprime" << "\n";
}

Measured memory_bytes: 11116
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int n, t[200005];

void add(int x, int v) {
    for (; x <= n; x += x & -x) t[x] += v;
}

int que(int x) {
    int z = 0;
    for (; x; x -= x & -x) z += t[x];
    return z;
}

int main() {
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    n = (int)s.length(); s = '!' + s;
    int o = 0, p = n, q = 0, r = 0;
    ll z = 0;
    bool b[200005] = {};
    vector<int> a[26] = {};
    for (int i = 1; i <= n; i++) a[s[i] - 'a'].push_back(i);
    for (int i = 0; i < 26; i++) if (a[i].size() % 2) {
        o++;
        r = a[i][(int)a[i].size() / 2];
    }
    if (o > 1) {cout << -1; return 0;}
    for (int i = 1; i <= n; i++) add(i, 1);
    for (int i = 1; i <= n; i++) if (!b[i]) {
        int x = a[s[i] - 'a'].back();
        a[s[i] - 'a'].pop_back();
        b[i] = b[x] = 1;
        if (i == x) {
            add(i, -1), p--;
            z += abs(q - n / 2);
            continue;
        }
        if (i <= r) q++;
        add(i, -1), p--;
        add(x, -1), p--;
        z += p - que(x);
    }
    cout << z;
}


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

// マクロ //
#define rep(i,N) for(int i = 0; i < N; i++)
#define all(x) x.begin(), x.end()
#define sort(x) sort(all(x))
#define cou(x) cout << x << endl
#define y() cout << "Yes" << endl
#define n() cout << "No" << endl
#define Y() cout << "YES" << endl
#define N() cout << "NO" << endl
#define x2(x) x * x

// 型エイリアス //
using lint = long long;
using vi = vector<int>;
using vs = vector<string>;
using vb = vector<bool>;
using vvi = vector<vector<int>>;

// 関数 //
int gcd(int a, int b) {
    int t;
    while (b != 0) {
        t = a % b;
        a = b;
        b = t;
    }
    return a;
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}

// End of Template //

int main() {

	int N;
	cin >> N;

    lint sum = 0;
    vector<long long int> vec(N);
	int p;
	rep(i, N) {
		cin >> p;
		vec[i] = p;
        sum += p;
	}
    lint half = sum % 2 == 0 ? sum / 2 : sum / 2 + 1;
    lint su = 0;
    int i = 0;
    while (su < half) {
        su += vec[i];
        i++;
    }
    i--;
    if (su - vec[i] > sum - su) {
        cout << 2 * (vec[i] - su) + sum << endl;
    }
    else if(su - vec[i] < sum - su) {
        cout << 2 * su - sum << endl;
    }
    else {
        cou(vec[i]);
    }
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define ll long long
int main(){
    int a,b;
    cin>>a>>b;
    if(a<b) swap(a,b);
    rep(i,a) cout<<b;
    cout<<endl;
    return 0;
}

Measured memory_bytes: 256
IDENTIFICATION                   DIVISION.
PROGRAM-ID.                      ABC_083_B.
ENVIRONMENT                      DIVISION.
DATA                             DIVISION.
WORKING-STORAGE                  SECTION.
    01 INP    PIC X(10).
    01 N      PIC 9(5).
    01 A      PIC 9(2).
    01 B      PIC 9(2).

    01 sm     PIC 9(10).

    01 num    PIC 9(3).

    01 i      PIC 9(5).

    01 X      PIC 9(5).
    01 R      PIC 9(5).

    01 ZS     PIC Z(9)9.
    01 DUMMY  PIC X(1).

    01 ans    PIC X(10).
PROCEDURE                        DIVISION.
MAIN.
    ACCEPT INP.

    UNSTRING INP
    DELIMITED BY SPACE
    INTO N A B.

    MOVE 0 TO sm.
    PERFORM VARYING i FROM 1 BY 1 UNTIL N < i
        MOVE i TO X
        MOVE 0 TO num
        PERFORM UNTIL X <= 0
            DIVIDE 10 INTO X GIVING X REMAINDER R
            ADD R TO num
        END-PERFORM

        IF A <= num AND num <= B THEN
           ADD i TO sm
        END-IF
    END-PERFORM.

    MOVE sm TO ZS

    PERFORM UNANS.

    DISPLAY ans(1:FUNCTION STORED-CHAR-LENGTH(ans)).
    STOP RUN.

UNANS                            SECTION.
    UNSTRING
        ZS DELIMITED BY ALL SPACE
        INTO DUMMY ans
    END-UNSTRING.


Measured memory_bytes: 636
#include<stdio.h>

int main(){
	long long x,y,ans=2000000000000;
	scanf("%ld%ld",&x,&y);
	if(y-x>=0&&y-x<ans)ans=y-x;
	if(y+x>=0&&1+y+x<ans)ans=1+y+x;
	if(-y-x>=0&&1-y-x<ans)ans=1-y-x;
	if(-y+x>=0&&2-y+x<ans)ans=2-y+x;
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
using namespace std;
int main()
{
int n;

cin >> n;
long long int min =10000000;
long long int max =-10000000;
long long int x, sum = 0;
for(int i = 0; i <n; i++){
    cin>>x;
    if(min>x){
        min = x;
    }
if (max<x){
    max=x;
}
    sum = sum + x;
}
cout << min << " ";
cout << max << " ";
cout << sum << endl;
    
}


Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define pb push_back
#define fi first
#define se second
const int maxn=1e5+10;
const int mod=1e9+7;
const int inf=0x3f3f3f3f;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	string a;
	cin>>a;
	if(a=="Sunny") cout<<"Cloudy"<<'\n';
	else if(a=="Cloudy") cout<<"Rainy"<<'\n';
	else cout<<"Sunny"<<'\n';
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

/**
 * @author author
 *
 */
public class Main {

  /**
   * @param args
   */
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = Integer.parseInt(sc.next());
    long x = Long.parseLong(sc.next());
    int d = 0;

    int[] numbers = new int[n];
    for (int i = 0; i < n; i++) {
      numbers[i] = Integer.parseInt(sc.next());
    }


    int resultNum = 1;
    for (int i = 0; i < n; i++) {
      d += numbers[i];
      if (d <= x) {
        resultNum++;
      } else {
        break;
      }
    }
    System.out.println(resultNum);
  }
}


Measured memory_bytes: 21588
#include <bits/stdc++.h>
using namespace std;
int fun(int a)
{
	int i,s=0;
	for(i=0;i<=a;i++)
		s+=i;
	return s;
}
int main()
{
	int a,b,s=0;
	scanf("%d %d",&a,&b);
	s=fun(b-a)-b;
	printf("%d",s);
	return 0;
}

Measured memory_bytes: 256
from collections import deque
from sys import stdin
q = deque()
input()
for s in stdin:
    if s == '\n':
        break
    c, *k = s.split()
    k = k[0] if k else None
    if c == 'insert':
        q.appendleft(k)
    elif c == 'delete':
        if k in q:
            q.remove(k)
    elif c == 'deleteFirst':
        q.popleft()
    else:
        q.pop()
print(*q)


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

int main() {
    long long x, k, d, ans;
    cin >> x >> k >> d;
    if (x < 0) x = -x;
    if (x / d > k) {
        ans = x - k * d;
    }else {
        if ((k - x / d) % 2 == 0) ans = x - (x / d) * d;
        else ans = x - (x / d + 1) * d;
    }
    cout << abs(ans) << endl;
    return 0;
}

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

//template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }
//typedef
//------------------------------------------
typedef long long LL;
typedef unsigned long long ULL;

//container util
//------------------------------------------
#define PB emplace_back
#define MP make_pair 
#define SZ(a) int((a).size())

//repetition
//------------------------------------------
#define REP(n) for(size_t i=0; i<n; i++)
#define REPj(n) for(size_t j=0; i<n; i++)
#define REPinit(a,n) for(size_t i=a; i<n; i++)
#define REPinitj(a,n) for(size_t k=a; i<n; i++)

int main()
{
	map<char, char> dnaBase;
	dnaBase['A'] = 'T';
	dnaBase['T'] = 'A';
	dnaBase['G'] = 'C';
	dnaBase['C'] = 'G';

	char b;
	cin >> b;
	cout << dnaBase[b] << endl;

	return 0;
}


Measured memory_bytes: 256
# include "bits/stdc++.h"
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const double PI = acos(-1);
template<class T>constexpr T INF() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T HINF() { return INF<T>() / 2; }
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { -1,0,1,0 }, dy[4] = { 0,-1,0,1 };
const char dir[4] = { 'u','l','d','r' };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_cnt(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define UNIQUE(wpwpw)        (wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define REP(i,upupu)         FOR(i,0,upupu)
# define INIT                 std::ios::sync_with_stdio(false);std::cin.tie(0)
# pragma warning(disable:4996)

int n, m, p;
int d[101010];
int ans = INF<int>();
int main() {
	cin >> n >> m >> p;
	REP(i, m) {
		cin >> d[i];
		d[i] = (d[i] - p + n) % n;
	}
	sort(d, d + m);
	ans = min(n - d[0], d[m - 1]);
	REP(i, m) {
		int r = d[i];
		int l = n - d[i + 1];
		ans = min({ ans, r * 2 + l, l * 2 + r });
	}
	cout << ans * 100 << endl;
}


Measured memory_bytes: 3152
#include<stdio.h>
 
int main(void){
	int x=0,a=0,b=0;
	scanf("%d %d %d",&x,&a,&b);
	
	if(0-a+b > x){
		printf("dangerous\n");
	}else if(0-a+b >0){
		printf("safe\n");	
	}else{
		printf("delicious\n");
	}
	return 0;
}

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

using namespace std;

#define FOR(v, b, e)   for (int v = (b); v < (e); ++v)
#define REP(v, n)      FOR(v, 0, n)

#define ALL(c)         (c).begin(), (c).end()

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

	int N, M;
	cin >> N >> M;

	vector<vector<int>> G(N + 1);
	int a, b;
	REP (i, M) {
		cin >> a >> b;
		G[a].push_back(b);
		G[b].push_back(a);
	}

	deque<int>     result;
	bitset<100000> visited;
	result.push_back(b);
	visited[b] = true;

	bool finished;
	do {
		finished = true;
		for (auto p : G[result.front()]) {
			if (!visited[p]) {
				result.push_front(p);
				visited[p] = true;
				finished   = false;
				break;
			}
		}
	} while (!finished);

	do {
		finished = true;
		for (auto p : G[result.back()]) {
			if (!visited[p]) {
				result.push_back(p);
				visited[p] = true;
				finished   = false;
				break;
			}
		}
	} while (!finished);

	cout << result.size() << endl;
	bool first = true;
	for (auto p : result) {
		if (!first) cout << " ";
		cout << p;
		first = false;
	}
	cout << endl;
}

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

int main(){
    string s;
    cin>>s;
    int ans=0;
    rep(i,s.size()){
        if(s[i]=='1') ans++;
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define debug(a) cout << #a << ": " << a << endl
#define sz(a) int(a.size())
#define vi vector<int>
#define rep(i,n) for(int i=0;i<n;i++)
#define forr(i, st, en) for(int i = st; i <= en; i++)
#define all(v) (v).begin(),(v).end()
#define fast cin.tie(0); ios::sync_with_stdio(false)

//int cnt[1<<20];
map<int, int> cnt;
int32_t main(){ fast;
               int n; cin>>n;
               ll answer = 0;
               rep(i, n){
                   int x; cin>>x;
                   cnt[x]++;
                   answer += x;
               }
               int q; cin>>q;
               while(q--){
                   int x, y; cin>>x>>y;
                   answer -= (long long) cnt[x] * x;
                   answer += (long long) cnt[x] * y;
                   cnt[y] += cnt[x];
                   cnt[x] = 0;
                   cout<<answer<<endl;
               }
}


Measured memory_bytes: 7892
#include<iostream>
#include<string>
#include<sstream>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<cmath>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<numeric>
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; }
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1};

#include <iomanip>

int main()
{

    long double L;
    cin >> L;
    long double ans = pow(L/3,3);
    // ll ans = L*L*L;

    cout << fixed;
    cout << setprecision(8) << ans << endl;
    return 0;
}   

Measured memory_bytes: 384
import sys

def solve():
    input = sys.stdin.readline
    N = int(input())
    A = [int(a) for a in input().split()]
    if N % 2 == 0:
        if N == 2: print(max(A))
        else:
            DP = [[-10 ** 20, -10 ** 20] for _ in range(N)]
            DP[0][0] = A[0]
            DP[1][1] = A[1]
            for i in range(2, N):
                DP[i][0] = max(DP[i][0], DP[i-2][0] + A[i])
                DP[i][1] = max(DP[i][1], DP[i-2][1] + A[i])
                if i > 2: DP[i][1] = max(DP[i][1], DP[i-3][0] + A[i])
            print(max(DP[N-2][0], DP[N-1][1]))
    else:
        DP = [[-10**20, -10**20, -10**20] for _ in range(N)]
        DP[0][0] = A[0]
        DP[1][1] = A[1]
        DP[2][2] = A[2]
        DP[2][0] = A[0] + A[2]
        for i in range(3, N):
            DP[i][0] = max(DP[i-2][0] + A[i], DP[i][0])
            DP[i][1] = max(DP[i-2][1] + A[i], DP[i][1])
            DP[i][2] = max(DP[i-2][2] + A[i], DP[i][2])
            if i > 2: 
                DP[i][1] = max(DP[i][1], DP[i-3][0] + A[i])
                DP[i][2] = max(DP[i][2], DP[i-3][1] + A[i])
        ans = max(DP[N-1][2], DP[N-2][1])
        ans = max(ans, DP[N-3][0])

        print(ans)

    return 0

if __name__ == "__main__":
    solve()

Measured memory_bytes: 132964
// ABC177D Friends改改

#include<stdio.h>
int par[200001];//親
int siz[200001];//サイズ

void ini(int n){ //初期化
  for(int i=0;i<=n;i++){
    par[i] = i;
    siz[i] = 1;
  }
}

int root(int x){
    int count=0,s[200001];
    if(par[x] == x){
        for(int i=0;i<count;i++){
            par[s[i]] = x;
        }
        return x;
    }
    else{
        s[count] = par[x];
        count++;
        return par[x] = root(par[x]);
    }
}

void uni(int x, int y){ 
    x = root(x);
    y = root(y);
    if(x != y){
        if(siz[x] >= siz[y]){
            par[y] = x;
            siz[x] += siz[y];
        }
        else if(siz[x] < siz[y]){
            par[x] = y;
            siz[y] += siz[x];
        }
    }
}

int size(int x){ //サイズを返す
  return siz[root(x)];
}

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

int main(void){
  int n,m,a,b,ma=0;
  scanf("%d %d",&n,&m);
  ini(n);
  for(int i=0;i<m;i++){
    scanf("%d %d",&a,&b);
    uni(a,b);
  }
  for(int i=1;i<=n;i++){
    ma = max(ma,size(i));
  }
  printf("%d",ma);
  return 0;
}

Measured memory_bytes: 3276
#include <iostream>
#include <vector>
#include <iterator>
#include <climits>

using namespace std;

int main(){
	int n, m;
	cin >> n >> m;
	vector<int> a(n), b(n), c(m), d(m);
	for(int i = 0; i < n; ++i){
		cin >> a[i] >> b[i];
	}
	for(int i = 0; i < m; ++i){
		cin >> c[i] >> d[i];
	}
	for(int i = 0; i < n; ++i){
		int dist = INT_MAX;
		int index;
		for(int j = 0; j < m; ++j){
			int di = abs(a[i] - c[j]) + abs(b[i] - d[j]);
			if(di < dist){
				dist = di;
				index = j;
			}
		}
		cout << index + 1 << endl;
	}
	return 0;
}

Measured memory_bytes: 256