akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
#include<string>
using namespace std;
#define LL long long
#define db(x) cout<<#x<<"="<<x<<endl
LL a,b,c,d;
string S,T;
int main() {
	cin>>S>>T;
	printf("%d",(S[0]==T[0])+(S[1]==T[1])+(S[2]==T[2]));
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	double a,b,c,d,e,f,x,y,bb,cc,s;
	while(scanf("%lf",&a)!=EOF)
	{
	scanf("%lf %lf %lf %lf %lf",&b,&c,&d,&e,&f);
	s = d/a;
	bb = b;
	cc = c;
	b = b*s;
	c = c*s;
	y = (c-f)/(b-e);
	x = (cc-bb*y)/a;
	printf("%.3lf %.3lf\n",x,y);
	}
	return 0;
}
	

Measured memory_bytes: 652
#include <stdio.h>

int main(void){
   int n,i,j=0,bucket[101],A=0,B=0;
   scanf("%d",&n);

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


   for(i=0;i<101;i++)
      bucket[i]=0;

   for(i=0;i<n;i++)
      bucket[a[i]]++;

   j=100;
   for(i=0;i<n;i+=0){
      if(bucket[j]>=1){a[i]=j;bucket[j]--; i++;}
      else j--;
   }

   for(i=0;i<n;i+=2)
      A+=a[i];

   for(i=1;i<n;i+=2)
      B+=a[i];

   printf("%d\n",A-B);
   return 0;
}


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


#define file "file"
#define mp make_pair
#define pb push_back
typedef long long ll;
typedef complex<double> point;
typedef pair<int, int> pii;
typedef vector<int> vi;

#define DEBUG 0
#define dout if(DEBUG) cout


void solve(){
    int n, a;
    cin >> n;
    int a0 = 0, a1 = 0, a2 = 0;
    for(int i = 0; i < n; i++){
        scanf("%d", &a);
        if(a % 4 == 0) a2++;
        else if(a % 2 == 0) a1++;
        else a0++;
    }
    if(a1){
        if(a0 > a2) cout << "No";
        else cout << "Yes";
    }
    else{
        if(a0 > a2 + 1) cout << "No";
        else cout << "Yes";
    }
}

int main() {
    #ifdef NASTYA
        assert(freopen("input.txt", "r", stdin)); assert(freopen("output.txt", "w", stdout));
    #else
    // assert(freopen(file".in", "r", stdin)); assert(freopen(file".out", "w", stdout));
    #endif
    int t = 1;
    while(t--) {
        solve();
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream> 
#include <cmath>
#include <string>
#include <vector>
using namespace std;
 
//const double PI=3.141592653589793238;
int main(void)
{
    long long a;
    double b;

    cin >> a >> b;

    b = b*100 + 0.5;
    int c = (int)b;
    a = a*c/100;
    cout << a << endl;
 
    return 0;
}

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

#define pb push_back
#define all(v) v.begin(), v.end()
#define sz(v) int(v.size())
#define pii pair<int, int>
#define mp make_pair
#define f first
#define ll long long
#define ld long double
#define s second
#define vec vector<int>

using namespace std;

const int N = (int) 1e5 + 100;
const int M = (int) 1e5 + 100;
const int K = (int) 200;
const int INF = (int) 1e9 + 7;
const int mod = (int) 998244353;
const ld EPS = (ld) 1e-9;
const ll LINF = (ll) 1e18;

int n, m;
int a[N];

int main() {
	#ifdef sony
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif
	srand(time(0));
	cin >> n >> m;
	for (int i = 1; i <= m; i++) {
		int x, y;
		cin >> x >> y;
		a[x] ^= 1;
		a[y] ^= 1;
	}
	for (int i = 1; i <= n; i++) {
		if (a[i]) {
			cout << "NO";
			return 0;
		}
	}
	cout << "YES";
	return 0;		
}

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

int main(){
    //input
    int n,t,a;
    cin >> n >> t >> a;
    int index = 1;
    double h;
    cin >> h;
    double z = t - h * 0.006;
    double m = abs(a - z) ;
    for(int i = 2;i<=n;i++){
        cin >> h;
        double z;
        z = t - h * 0.006;
        if(m >= abs(a-z)){
            m = abs(a-z);
            index = i;
        }
    }
    cout << index<< endl; 
    return 0;
}

Measured memory_bytes: 256
icase=0
if icase==0:
    n,m=map(int,input().split())
    xyz=[[0]*3 for i in range(n)]
    for i in range(n):
        xyz[i]=list(map(int,input().split()))
elif icase==1:
    n,m=5,3
    xyz=[[3, 1, 4], [1, 5, 9], [2, 6, 5], [3, 5, 8], [9, 7, 9]]
elif icase==2:
    n,m=5,3
    xyz=[[1, -2, 3], [-4, 5, -6], [7, -8, -9], [-10, 11, -12], [13, -14, 15]]
elif icase==3:
    n,m=10,5
    xyz=[[10, -80, 21], [23, 8, 38], [-94, 28, 11], [-26, -2, 18], [-69, 72, 79], [-26, -86, -54], [-72, -50, 59], [21, 65, -32], [40, -94, 87], [-62, 18, 82]]
    
import itertools
ic=0
summ=[0]*8    
for j in itertools.product([1,-1], repeat=3):
    xyz0=sorted(xyz,key=lambda x:j[0]*x[0]+j[1]*x[1]+j[2]*x[2],reverse=True)
    for i in range(m):
        summ[ic]+=j[0]*xyz0[i][0]+j[1]*xyz0[i][1]+j[2]*xyz0[i][2]
#    print(ic,xyz0,summ[ic])
    ic+=1
    
print(max(summ))    


Measured memory_bytes: 68500
#include <iostream>
#include <string>
using namespace std;
int main(void){
    int num, i, j, len;
    string str[101], tmp;
    char end_c;
    
    // 入力
    cin >> num;
    for(i=0; i<num; i++){
        cin >> str[i];
    }
    
    // 重複確認
    for(i=0; i<num; i++){
        tmp = str[i];
        for(j=0; j<num; j++){
            // 検索対象の文字列をスキップ
            if(j==i) continue;
            if(tmp == str[j]){
                cout << "No" << endl;
                return 0;
            }
        }
    }
    
    // しりとりとして成り立っているか
    for(i=0; i<num-1; i++){
        // 文字列の長さ
        len = str[i].length();
        // 最後と最初の文字が一致しているか
        if(str[i][len-1] != str[i+1][0]){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<ll,ll> ii;
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define RST(i,n) memset(i,n,sizeof i)
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(),a.end()
#define X first
#define Y second
#define mkp make_pair
#define pb push_back
#define eb emplace_back
#define pob pop_back
#ifdef cold66
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<", ";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#endif // cold66
//}
template<class T> inline bool chkmax(T &a, const T &b) { return b > a ? a = b, true : false; }
template<class T> inline bool chkmin(T &a, const T &b) { return b < a ? a = b, true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;

const ll MAXn=1e4+5,MAXlg=__lg(MAXn)+2;
const ll MOD=1000000007;
const ll INF=0x3f3f3f3f;

ll d[10];
ll cost[] = {0,2,5,5,4,5,6,3,7,6};
string dp[MAXn];
void ins(string &a,string b){
  if (SZ(a) < SZ(b)) a = b;
  else if (SZ(a) == SZ(b)) {
    if (a < b) a = b;
  }
}
int main(){
  IOS();
  ll n,m;
  cin >> n >> m;
  REP (i,m) {
    ll x;
    cin >> x;
    d[x] = 1;
  }

  REP1 (i,n) {
    REP1 (cur,9) {
      if (!d[cur]) continue;
      string s = "";
      if (cost[cur] == i) ins(dp[i],s+char(cur+'0'));
      else if (i-cost[cur] > 0 && dp[i-cost[cur]] != "") ins(dp[i],dp[i-cost[cur]] + char(cur+'0'));
    }
  }
  cout << dp[n] << endl;
}


Measured memory_bytes: 41472
#include <bits/stdc++.h>
#define ll long long
#define llu unsigned long long
#define INF 0x3f3f3f3f
#define LINF 0x3f3f3f3f3f3f3f3f
using namespace std;
const int MAX = 1e5 + 10;
const int mod = 1e9;
int N, M, Q, K;
vector<int> vec[2];
int dp[16100][5010], dest[2];
bool dflag[2];

int rec(int pos, int vi, int init, int dir){
    if(vi == vec[dir].size()){
        if(pos == dest[dir]) dflag[dir] = true;
        return 1;
    }
    int &ret = dp[pos][vi];
    if(ret != -1) return 1;
    ret = 1;

    rec(pos + vec[dir][vi], vi + 1, 0, dir);
    if(!init) rec(pos - vec[dir][vi], vi + 1, 0, dir);
    return 1;
}

int main()
{
    int i, j, k;
    string s;
    cin >> s >> dest[0] >> dest[1];

    int pos = 0;
    int dir = 0;
    int n= s.size();
    while(pos < n){
        int cnt = 0;
        while(pos < n && s[pos] == 'F') {cnt++; pos++;}
        vec[dir].push_back(cnt);
        pos++;
        dir = !dir;
    }
    dest[0] += 8000; dest[1]+= 8000;
    memset(dp, -1, sizeof(dp));
    rec(8000, 0, 1, 0);
    if(!dflag[0]){
        printf("No\n");
        return 0;
    }
    memset(dp, -1, sizeof(dp));
    rec(8000, 0, 0, 1);
    if(!dflag[1]){
        printf("No\n");
        return 0;
    }
    printf("Yes\n");
}


Measured memory_bytes: 315648
#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <bitset>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef tuple<ll, ll, ll> tl3;



const int BIG_NUM = 1e9;
const ll INF = 1000000000000000000;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;



int main() {
	string s;
	cin >> s;
	switch (s[0])
	{
	case 'S':cout << "Cloudy" << endl;
		break;

	case 'C':cout << "Rainy" << endl;
		break;

	default:cout << "Sunny" << endl;
		break;
	}
}


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



int main() {
int N, K, Q;
cin >> N >> K >> Q;
K -= Q;
int ten[200000];
for(int i = 0; i < N; i++){
ten[i] = K;
    
}
for(int i = 0; i < Q; i++){
    int n;
    cin >> n;
    n--;
ten[n]++;
}
for(int i = 0; i < N; i++){
if(ten[i] > 0) cout <<"Yes" << endl;
else cout << "No" << endl;


}



}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
/************************************************/
#define rep(i,n) for(int i=0;i<n;i++)
#define m_p make_pair
#define pb push_back
#define fr first
#define se second
#define forn(i,a,n) for(int i=a;i<n;i++)
#define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();i++)
#define pii pair<int,int>
#define vi vector<int>
#define ll long long
#define sz(s) s.size()
#define all(s) s.begin(),s.end()
#define zero(x) memset(x,0,sizeof(x))
#define vii vector<pair<int,int> >
#define mpis map<int,string>
#define mpii map<int,int>
#define mpsi map<string,int>
#define re return
#define mod 1000000007
/************************************************/
using namespace std;

long long get(){
	char c=getchar();
	long long x=0LL;
	while(c<'0'||c>'9')
	c=getchar();
	while(c>='0'&&c<='9'){
		x*=10LL;
		x+=(c-'0');
		c=getchar();
	}
	return x;
}
string s;
int main(){
	ios::sync_with_stdio(0);
	cin>>s;
	rep(i,sz(s))
	cout<<"x";
	re 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

#define rep_(i, a_, b_, a, b, ...) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define rep(i, ...) rep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define reprev_(i, a_, b_, a, b, ...) for (int i = (b-1), i##_min = (a); i >= i##_min; --i)
#define reprev(i, ...) reprev_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define all(x) (x).begin(), (x).end()
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
// template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

int main (void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a; cin >> a;
    cout << a + a * a + a * a * a << "\n";
    return 0;
}

Measured memory_bytes: 3632
(n,h),*ab = [list(map(int, s.split())) for s in open(0)]

mxa = max([a for a, b in ab])
bb = sorted([b for a, b in ab if b>mxa],reverse=True)

ans = 0
for b in bb:
    h-=b
    ans += 1
    if h<=0:
        break
if h>0:
    ans += (0--h//mxa)
print(ans)

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

using namespace std;

using int64 = long long;

template<class T> inline bool UpdateMin(T& a, T b) {
  if (a > b) { a = b; return 1; } return 0;
}
template<class T> inline bool UpdateMax(T& a, T b) {
  if (a < b) { a = b; return 1; } return 0;
}

template<typename T>
vector<vector<vector<T>>>
Make3DVector(int d1, int d2, int d3, T default_value) {
  return vector<vector<vector<T>>>(
      d1, vector<vector<T>>(d2, vector<T>(d3, default_value)));
}

constexpr int DEBUG = 0;

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

  int n, k;
  cin >> n >> k;
  vector<int64> xs(n);
  for (int i = 0; i < n; i++) {
    cin >> xs[i];
  }
  vector<int64> cum_sum(n + 1);
  vector<int64> pos_cum_sum(n + 1);
  for (int i = 1; i <= n; i++) {
    cum_sum[i] = cum_sum[i - 1] + xs[i - 1];
    pos_cum_sum[i] = pos_cum_sum[i - 1] + max(xs[i - 1], 0LL);
  }

  int64 ans = INT64_MIN;
  for (int i = 0; i + k <= n; i++) {
    // [0, i), [i, i + k), [i + k, n)
    int64 sum = 0;
    sum += pos_cum_sum[i];
    sum += max(cum_sum[i + k] - cum_sum[i], 0LL);
    sum += pos_cum_sum[n] - pos_cum_sum[i + k];
    UpdateMax(ans, sum);
  }
  cout << ans << endl;
}

Measured memory_bytes: 2560
#![allow(unused_imports)]
use std::io::*;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;

pub trait InputValue {
    fn parse(s: &str) -> Self;
}

pub fn read<T: InputValue>() -> T {
    let mut buf = String::new();
    let _ = stdin().read_line(&mut buf);
    T::parse(&buf.trim())
}

pub fn readn<T: InputValue>(n: usize) -> Vec<T> {
    let mut vec = vec![];
    for _ in 0..n {
        vec.push(read());
    }
    vec
}

pub fn readnc<T: InputValue>() -> Vec<T> {
    let mut vec = vec![];
    let line: String = read();
    for token in line.split_whitespace() {
        vec.push(T::parse(token));
    }
    vec
}

macro_rules! parse_single_value {
    ($($t:ty),*) => {
        $(
            impl InputValue for $t {
                fn parse(s: &str) -> $t { s.parse().unwrap() }
            }
        )*
	}
}
parse_single_value!(i32, i64, f32, f64, usize, String);

macro_rules! parse_tuple {
	($($t:ident),*) => {
		impl<$($t),*> InputValue for ($($t),*) where $($t: InputValue),* {
			fn parse(s: &str) -> ($($t),*) {
				let mut tokens = s.split_whitespace();
				let t = ($($t::parse(tokens.next().unwrap())),*);
				t
			}
		}
	}
}
parse_tuple!(A, B);
parse_tuple!(A, B, C);

// ===

fn main() {
    let (a, b): (i32, i32) = read();
    let ab = format!("{}{}", a, b);
    let ab: i32 = ab.parse().unwrap();
    let mut isq = false;
    for i in 1..1000 {
        if i*i == ab {
            isq = true;
        }
    }

    if isq {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 4352
#include "bits/stdc++.h"
#define long int64_t
using namespace std;

struct Solver {
	void solve() {
		int N;
		string S;
		cin >> N >> S;

		int r = 0;
		int w = 0;
		for( int i = 0; i < N; ++i ) {
			r += S[i] == 'R';
		}

		int ans = INT_MAX;
		for( int i = 0; i <= N; ++i ) {
			if( i > 0 ) {
				if( S[i-1] == 'R' ) { r -= 1; }
				else { w += 1; }
			}
			ans = min( ans, max( r, w ) );
		}

		cout << ans << endl;
	}
};

int main() {
	ios::sync_with_stdio( false );
	cout << fixed << setprecision( 10 );
	Solver().solve();
	return 0;
}


Measured memory_bytes: 3744
// Created by Kshitij Anand NSIT
#include <bits/stdc++.h>


using namespace std;


#define int long long
#define pb push_back
#define P pair<int,int>
#define F first
#define S second
#define vi vector<int>
#define vc vector<char>
#define vb vector<bool>
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define mp(a, b) make_pair(a, b)
#define min3(a, b, c) min(min(a, b), c)
#define min4(a, b, c, d) min(min(a, b), min(c, d))
#define max3(a, b, c) max(max(a, b), c)
#define max4(a, b, c, d) max(max(a, b), max(c, d))
#define fill(arr,val) memset(arr,val,sizeof(arr))
#define db(x)  cout<<#x<<" : "<<x<<endl


const int N = 1000000007;

int dp[100000][3];

int func(int arr[][3] , int n , int prev , int curr){

	if(curr == n) return 0;

	if(prev!=-1 && dp[curr][prev] != -1)  return dp[curr][prev];

	int ans =0;

	for(int i=0; i<3; i++) {

		if(i!= prev)
			ans = max( arr[curr][i] + func(arr , n , i , curr+1) , ans);
	}

	dp[curr][prev] = ans;

	return ans;
}

void solve(){

    int n,a,b,c, ans=0, count=0, sum=0;
    cin>>n;
    int arr[n][3];
    for(int i=0;i<n;i++){

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

    fill(dp , -1);

    // for(int i=0; i<n; i++) {

    // 	for(int j=0; j<3; j++) {
    // 		dp[i][j] = -1;
    // 	}
    // }

    ans = func(arr , n , -1 , 0);

    cout<<ans<<endl;
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    
    
  //  int t; cin>>t; while(t--)
    {     
      solve();
    }

  return 0;
}


Measured memory_bytes: 14336
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[9]={1,0,-1,0,1,1,-1,-1,0};
const ll dx[9]={0,-1,0,1,1,-1,1,-1,0};
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;
} 
int main(){
    ll n;cin >> n;
    ll now=1000,t=0;
    vl v(n);
    rep(i,n){
        cin >> v[i];
    }
    rep(i,n-1){
        if(v[i]<v[i+1]){
            t+=now/v[i];
            now%=v[i];
        }
        if(v[i]>v[i+1]){
            now+=t*v[i];
            t=0;
        }
    }
    cout << now+v[n-1]*t <<endl;
} 

Measured memory_bytes: 3620
#include<iostream>
using namespace std;
int a[100001]={0};
int main(){
	long long int n,sum=0,q,x;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>x,sum+=x;
		a[x]++;
	}
	cin>>q;
	for(int i=0;i<q;i++){
		long long int b,c;
		cin>>b>>c;
		sum+=(c-b)*a[b];
		cout<<sum<<'\n';
		a[c]+=a[b];
		a[b]=0;
	}
}

Measured memory_bytes: 4008
#include<iostream>
#include<sstream>
#include<vector>
#include<iterator>
#include<algorithm>
using namespace std;

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

    vector<int> p(n);
    for (int i = 0; i < n; i++)
        cin >> p[i];

    int ans = 0;
    for (int i = 0; i < (int)p.size() - 2; i++) {
        vector<int> v;
        for (int j = 0; j < 3; j++)
            v.push_back(p[i + j]);

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

        if (v[1] == p[i + 1])
            ans++;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <queue>
# define MOD 1000000000+7
# define INF 1000000000
#define rep(i,rept)	for(ll i = 0; i<rept;i++)
typedef long long ll;
using namespace std;
long long int a = 0, b = 0, c = 0, d = 0, e = 0, ans = 0,w=0, x = 0, y = 0, z = 0, N = 0, m = 0, maxy = 0, mini = 9999999999, mini2 = 9999999999, counter = 0, endp = 0, checker = 0;

std::vector <long long int> vec{}, vecsec{}, vecth{};
long long int iremonogusu[100010], koware[100001];
long long  int iremonokisu[100001], check[100001], xpo[10000001], ypo[10000001], hei[1000001];
std::vector<char>kinds{}, kaku{}, kakutwo{};
char maze[1000];
int sx, sy;
int gx, gy;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
bool okada = false, okada2 = false;
long long int dp[4][100003] ,ire[4][100003];
std::string input[103],one,two,three;
char re;

int H, W;//はんい
bool qw = false, er = false, ty = false, ui = false;
std::string code;
long long int gcd(long long int a, long long int b)
{
	if (a < b) {
		a ^= b;
		b ^= a;
		a ^= b;
	}

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

int main() {
	cin >> a;
	okada = true;
	rep(i,a) {
		cin >> b;
		check[i] = b;
		if ((i + 1) % 2 == 0) {
			iremonogusu[b]++;
		}
		else {
			iremonokisu[b]++;
		}
}
	
	
	long long int maxg = 0, maxgsec = 0, maxk = 0, maxksec = 0;
	rep(i,100001) {
		if (maxg < iremonogusu[i]) {
			maxg = max(maxg, iremonogusu[i]);
			w = i;
		}
	}
	rep(i, 100001) {
		if (i != w) {
			if (maxgsec < iremonogusu[i]) {
				maxgsec = max(maxgsec, iremonogusu[i]);
				x = i;
			}
		}
	}
	rep(i, 100001) {
		if (maxk < iremonokisu[i]) {
			maxk = max(maxk, iremonokisu[i]);
			y = i;
		}
	}
	rep(i, 100001) {
		if (i != y) {
			if (maxksec < iremonokisu[i]) {
				maxksec = max(maxksec, iremonokisu[i]);
				z = i;
			}
		}
	}
	if (w == y) {
			cout <<min( a-maxg - maxksec, a-maxgsec - maxk) << endl;
	}
	else {
		cout << a - maxg - maxk << endl;
	}
}




Measured memory_bytes: 5120
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}

	scanner := getScanner(fp)

	writer := bufio.NewWriter(os.Stdout)

	sx := getNextInt(scanner)
	sy := getNextInt(scanner)
	tx := getNextInt(scanner)
	ty := getNextInt(scanner)
	fmt.Fprintf(writer, "D%sL", root(sx, sy-1, tx+1, ty))
	fmt.Fprintf(writer, "%s", root(tx, ty, sx, sy))
	fmt.Fprintf(writer, "%s", root(sx, sy, tx, ty))
	fmt.Fprintf(writer, "U%sR", root(tx, ty+1, sx-1, sy))
	fmt.Fprintln(writer, "")
	writer.Flush()
}

func root(sx, sy, tx, ty int) string {
	dx := tx - sx
	dy := ty - sy

	mx := "R"
	my := "U"
	if dx < 0 {
		mx = "L"
		dx = -dx
	}
	if dy < 0 {
		my = "D"
		dy = -dy
	}
	ans := make([]string, dx+dy)
	for i := 0; i < dx; i++ {
		ans[i] = mx
	}
	for i := 0; i < dy; i++ {
		ans[dx+i] = my
	}
	return strings.Join(ans, "")
}


Measured memory_bytes: 896
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <string>
#include <cmath>
#include <complex>
#include <numeric>
#include <cassert>

#include <vector>
#include <array>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <utility>

#define PI 3.14159265358979323846
#define int64 long long
#define uint64 unsigned long long
using namespace std;

int main()
{
	int64 m1, m2, d1, d2;
	cin >> m1 >> d1 >> m2 >> d2;
	if(m1 != m2)
	{
		puts("1");
	}
	else
	{
		puts("0");
	}
	return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
// Hey! 僕の提出を見てくれてありがとう.
// ロボ子さん可愛いぞ！！！！！君もV沼にはまろう↓
// https://www.youtube.com/channel/UCDqI2jOz0weumE8s7paEk6g
using namespace std;
using ll = long long;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}//a,bの最大公約数(gcd)を求める
ll lcm(ll a,ll b){return abs(a*b)/gcd(a,b);}//a,bの最小公倍数(lcm)を求める
vector<ll> enum_div(ll n){vector<ll> ret;for(int i=1 ; i*i<=n ; i++){if(n%i == 0){ret.push_back(i);if(i!=1 && i*i!=n)ret.push_back(n/i);}}ret.push_back(n);return ret;}
//↑nの約数を求める
vector<bool> IsPrime; void sieve(size_t max){if(max+1 > IsPrime.size())IsPrime.resize(max+1,true);IsPrime[0] = false;IsPrime[1] = false;for(size_t i=2; i*i<=max; ++i)if(IsPrime[i])for(size_t j=2; i*j<=max; ++j)IsPrime[i*j] = false;}
//↑エラトステネスの篩で素数を求める
#define roundup(divisor,dividend) (divisor + (dividend - 1)) / dividend //切り上げ割り算
#define all(x) (x).begin(),(x).end() //xの初めから終わりまでのポインタ
#define size_t ll //size_tは自動でllに変換される
#define pb(x) push_back(x)
#define pri_queue priority_queue //優先度付きキュー
#define syo(x) fixed << setprecision(x) //iostreamで小数をx桁表示
//sortを降順にする時は greater<型>()
const string YES = "Yes";
const string NO = "No";
void solve(long long N){
  bool ans = false;
  string S = to_string(N);
  for (int i = 0; i <3 ; i++) {
    if(S[i] == '7')ans = true;
  }
  cout << (ans ? YES:NO) << endl;
}

int main(){
    long long N;
	scanf("%lld",&N);
    solve(N);
}


Measured memory_bytes: 3756
#include<stdio.h>

int main(){

	int i,n,no,j;
	int card[4][13] = { 0 };
	char m;
	char egara[4] = { 'S', 'H', 'C', 'D' };
	scanf("%d", &n);
	for (i = 0; i < n; i++){
		scanf(" %c %d", & m,&no);

	if (m == 'S')card[0][no - 1] = 1;
	else if (m == 'H')card[1][no - 1] = 1;
	else if (m == 'C')card[2][no - 1] = 1;
	else if (m == 'D')card[3][no - 1] = 1;
	}

	for (j = 0; j < 4; j++){
		for (i = 0; i < 13; i++){
			if (card[j][i] != 1)printf("%c %d\n", egara[j], i + 1);
		}
	}
	return 0;
}

Measured memory_bytes: 596
<?php
$n=(int)trim(fgets(STDIN))+1;
$o=array('');
for($i=1;$i<$n;$i++){
  if($i%3==0) $o[]=$i;
  else{
   $x=$i;
   while($x){
      if($x%10==3){
        $o[]=$i;
        break;
      }
      $x=floor($x/10);
    }
  }
}
print implode(' ',$o);
?>

Measured memory_bytes: 16280
def check(a,b,c):
	if a==b or a==c or b==c:
		return False
	if a+b>c and b+c>a and c+a>b:
		
		return True
	return False

n=int(input())
c=list(map(int,input().split()))
count=0
for i in range(len(c)-2):
	for j in range(i+1,len(c)-1):
		for k in range(j+1,len(c)):
			if check(c[i],c[j],c[k]):
				count+=1
print(count)

				


			


Measured memory_bytes: 74084
/**
 *     author: nayakashutosh9
 *     college: National Institute of Technology, Rourkela
 *	   "Winners Never Quit and Quitters Never Win".
**/
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define endl "\n"
#define mod 1000000007
#define inf 1e18
const int N = 300005;

/*******************************************************************/



int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	// int t = 1, z = 1;
	// cin >> t;
	// cin.ignore();
	// while (t--) {

	// }
	int n; cin >> n;
	cout << (n + n * n + n * n * n) << endl;

	return 0;
}


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

template <typename InputIterator>
typename InputIterator::value_type summation(InputIterator first,
                                             InputIterator last) {
  return std::accumulate(first, last, typename InputIterator::value_type());
}
template <typename T>
std::istream &operator>>(std::istream &stream, std::vector<T> &v);
template <typename T1, typename T2>
std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p);
template <typename T>
std::istream &operator>>(std::istream &stream, std::vector<T> &v) {
  for (auto &i : v) {
    stream >> i;
  }
  return stream;
}
template <typename T1, typename T2>
std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p) {
  stream >> p.first >> p.second;
  return stream;
}

int main() {
  int64_t h, w, n;
  std::cin >> h >> w >> n;
  std::map<std::pair<int64_t, int64_t>, int> m;

  for (int64_t i = 0; i < n; i++) {
    int64_t a, b;
    std::cin >> a >> b;
    for (int64_t j = a - 1; j <= a + 1; j++) {
      for (int64_t k = b - 1; k <= b + 1; k++) {
        if (2 <= j && j <= h - 1 && 2 <= k && k <= w - 1) {
          if (m.find({j, k}) == m.cend()) {
            m[{j, k}] = 1;
          } else {
            m[{j, k}]++;
          }
        }
      }
    }
  }

  std::vector<int64_t> ans(10, 0);
  ans[0] = (h - 2) * (w - 2);

  for (const auto &i : m) {
    ans[i.second]++;
    ans[0]--;
  }

  for (const auto i : ans) {
    std::cout << i << std::endl;
  }

  return 0;
}


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

#define watch(x) cerr << (#x) << ": " << (x) << endl
#define int long long

const int N = 305;
int h, w, k;
string s[N];
int ans[N][N];
bool empty[N];

int32_t main() {

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> h >> w >> k;
    for(int i = 0; i < h; ++i) cin >> s[i];

    int piece = 0;
    for(int i = 0; i < h; ++i) {
        bool seen = false;
        piece++;
        for(int j = 0; j < w; ++j) {
            if(s[i][j] == '#') {
                if(!seen) seen = true;
                else piece++;
            }
            ans[i][j] = piece;
        }
        if(!seen) {
            piece--;
            empty[i] = true;
        }
    }

    

    for(int i = 0; i < h; ++i) {
        if(empty[i]) {
            int offset = 1;
            while(i+offset < h && empty[i+offset]) offset++;
            if(i + offset == h) {
                offset = -1;
                while(empty[i+offset]) offset--;
            }
            for(int j = 0; j < w; ++j) {
                cout << ans[i+offset][j] << ' ';
            }
        } else {
            for(int j = 0; j < w; ++j) {
                cout << ans[i][j] << ' ';
            }
        }
        cout << '\n';
    }
    
    return 0;
}


Measured memory_bytes: 1664
/*
 * atcoder/abc169/c.cpp
 */

// C++ 14
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring> // memset
#include <cassert>
using namespace std;
#define ll long long
#define ld long double
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
template <class T> ostream & operator << (ostream & out, vector<T> const & v) {
  for (auto &&a: v) out << a << " "; out << endl; return out;
}
template <class T> void dump(T &a) { cout << a << endl; }
template <class T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template <class T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }

ld a, b;
void solve() {
  cin >> a >> b;
  cout << (ll)floor(a * b) << endl;
}
int main() {
  // cout.precision(15); cout << fixed;

  solve();

  return 0;
}


Measured memory_bytes: 3732
#include <stdio.h>

int main(){

int   a, b;
int   d   ;
int   r   ;
double f   ;

scanf("%d %d", &a, &b) ;

d = a / b;
r = a % b;
f = a / (double)b;

printf("%d %d %f\n", d, r, f);

return 0;
}

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

int main() {
  int N, M;
  cin >> N >> M;
  vector<vector<char>> matrix(N, vector<char>(N,'#'));

  rep(i, N)
  	rep(j,M)
    	cin >> matrix[i][j];
  
   vector<int> sum1(M,0), sum2(N,0);
  int newN=N, newM=M;
  
  // check in row direction
  rep(i, N)
  	rep(j,M){
  	if (matrix[i][j]=='.')
      	sum2[i]++;
    
    if (sum2[i]==M)
      	newN--;
  	}
  
  // check in column direction
   rep(j, M)
  	rep(i,N){
  		if (matrix[i][j]=='.')
      		sum1[j]++;
     
    	if (sum1[j]==N)
          newM--;     
  	}
  
  // empty the x rows and columns
    rep(i, N){
    	if (sum2[i]==M){
        //  cout << "Eliminating rows..." << endl;
        	rep(j, M)
          	matrix[i][j]='x';
        }
    }
      
    rep(j, M){
    	if (sum1[j]==N){
        //  cout << "Eliminating columns..." << endl;
        	rep(i, N)
          	matrix[i][j]='x';
        }
    }
   /*   
   rep(i, N){
     cout << endl;
  	rep(j,M){
   		cout << matrix[i][j];
   	}
   }
  cout << endl;  
  
  cout << newN << 'x' << newM << "matrix" << endl;
  */         
  rep(i,N){
     if (sum2[i]!=M){
  		    rep(j,M){
  				if (matrix[i][j]!='x'){
          		cout << matrix[i][j];
        		}
    			}
     		cout << endl;	  
     }
  }
    
  
    	
  
  
}


Measured memory_bytes: 256
import java.util.*;
import java.util.HashSet;
import java.util.Set;
public class Main{
    public static void main(String[]args){
        Scanner sc=new Scanner(System.in);
        String a=sc.next();
        String b=sc.next();
        String c=sc.next();
        char[]aa=a.toCharArray();
        char[]bb=b.toCharArray();
        char[]cc=c.toCharArray();
        System.out.print(aa[0]);
        System.out.print(bb[1]);
        System.out.println(cc[2]);
        
        }
       
        
    }

Measured memory_bytes: 23124
using System;
using System.IO;
using System.Linq;

namespace abc124b
{
    class Program
    {
        static void Main(string[] args)
        {
            if (args.Length > 0)
            {
                Console.SetIn(new StreamReader(args[0]));
            }

            new Program().Solve();
        }

        void Solve()
        {
            var N = int.Parse(Console.ReadLine());
            var H = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            var count = 1;
            var maxHeight = H[0];

            for (int i = 1; i < N; i++)
            {
                if (maxHeight <= H[i])
                {
                    count++;
                }

                maxHeight = Math.Max(maxHeight, H[i]);
            }

            Console.WriteLine(count);
        }
    }
}


Measured memory_bytes: 13268
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

int main()
{
	int n, k;
	std::cin >> n >> k;
	std::vector<int> a(n);
	for (int i = 0; i < n; i++)
	{
		std::cin >> a[i];
	}

	int ans;
	ans = (n-1)/(k-1);
	if((n-1)%(k-1)!=0) ans++;

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

Measured memory_bytes: 640
#順列全探索

from itertools import permutations

N, M = map(int, input().split())
G = [[0]*N for _ in range(N)]
for i in range(M):
  a, b = map(int, input().split())
  G[a-1][b-1] = 1
  G[b-1][a-1] = 1

perms = permutations(range(1, N))
ans = 0

for perm in perms:
  now = 0
  for v in perm:
    if G[now][v] == 0:
      break
    now = v
  else:
    ans += 1
    
print(ans)

Measured memory_bytes: 3064
package main

import "fmt"

func main() {
  var n, ans int

  fmt.Scan(&n)

  h := make([]int64, n)

  for i := 0; i < n; i++ {
    var t int64
    fmt.Scan(&t)
    h[i] = t
  }

  var tt int
  for i := n-1; i > 0; i-- {
    if h[i] <= h[i-1] {
      tt++
    } else {
      tt = 0
    }
    if tt > ans {
      ans = tt
    }
  }
  fmt.Println(ans)
}

Measured memory_bytes: 5504
#include <bits/stdc++.h>
using namespace std;
#define elif else if
typedef long long ll;
typedef unsigned long long ull;
#define DEBUG(x) cout << (x) << endl
#define TGET(a, b) get<b>(a)

int is_prime(ll n)
{
    double n_sqrt;
    if (n == 2 || n == 3)
    {
        return 1;
    }
    if (n <= 1 || n % 6 != 1 && n % 6 != 5)
    {
        return 0;
    }
    n_sqrt = double(sqrt((double)n));
    for (int i = 5; i <= n_sqrt; i += 6)
    {
        if (n % i == 0 | n % (i + 2) == 0)
        {
            return 0;
        }
    }
    return 1;
}

ll ans = 0;
int n, m, q;
int query[55][4] = {0};
int tmp[15] = {0};

void dfs(int pos)
{
    if(pos==n+1)
    {
        ll tmpans = 0;
        for (int i = 0; i < q;i++)
        {
            if(tmp[query[i][1]]-tmp[query[i][0]]==query[i][2])
            {
                tmpans += query[i][3];
            }
        }
        ans = max(ans, tmpans);
        return;
    }
    for (int i = tmp[pos - 1]; i <= m;i++)
    {
        tmp[pos] = i;
        dfs(pos + 1);
    }
    return;
}

int main()
{
    tmp[0] = 1;
    scanf("%d %d %d", &n, &m, &q);
    for (int i = 0; i < q;i++)
    {
        scanf("%d %d %d %d", &query[i][0], &query[i][1], &query[i][2], &query[i][3]);
    }
    dfs(1);
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 3756
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h> // uint64_t

#define max(a,b) ((a) > (b) ? (a) : (b))
#define min(a,b) ((a) > (b) ? (b) : (a))

int get_int2(int *a1, int *a2) {
  scanf("%d %d", a1, a2);
  return 0;
}

int get_str(char *str, int size)
{
    char format[100];
    if (size == 0)
        return 0;
    snprintf(format, sizeof(format), "%%%ds", size);
    scanf(format, str);
    return 0;
}

#define ROW_MAX 100
#define COL_MAX 100

enum type {
    ENUM_WHITE = '.',
    ENUM_BLACK = '#'
};

int main(void) {
    int row, col;
    static char map[ROW_MAX][COL_MAX+10];
    static char deleted[ROW_MAX][COL_MAX+10];
    get_int2(&row, &col);
    int i, j;
    for(i = 0; i < row; i++) {
        get_str(&map[i][0], COL_MAX);
    }

    for(i = 0; i < row; i++) {
        int flag = 1;
        for(j = 0; j < col; j++) {
            if(map[i][j] == ENUM_BLACK) {flag = 0; break;}
        }
        if(!flag) continue;
        for(j = 0; j < col; j++) deleted[i][j] = 1;
    }

    for(j = 0; j < col; j++) {
        int flag = 1;
        for(i = 0; i < row; i++) {
            if(map[i][j] == ENUM_BLACK) {flag = 0; break;}
        }
        if(!flag) continue;
        for(i = 0; i < row; i++) deleted[i][j] = 1;
    }

    // presentation
    for(i = 0; i < row; i++) {
        int flag = 0;
        for(j = 0; j < col; j++) {
            if(!deleted[i][j]) {putchar(map[i][j]); flag = 1;}
        }
        if(flag) putchar('\n');
    }

    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c,x,i,j,k,ans=0;
    cin>>a>>b>>c>>x;
    for (i=0; i <= a && 500*i<=x; i++)
    {
        for (j=0; j <= b && 100*j+500*i<=x; j++)
        {
            for (k=0; k <= c && 50*k+100*j+500*i<=x; k++)
            {
                if (500*i+100*j+50*k==x)
                {
                    ans++;
                }
            }
        }
    }
    cout<<ans;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(1000000)
input = sys.stdin.readline
n, m, k = map(int,input().split())
A = [list(map(int,input().split())) for i in range(m)]
B = [list(map(int,input().split())) for i in range(k)]
# print(A)
# print(B)
for i in range(m):
    for j in range(2):
        A[i][j] -= 1
for i in range(k):
    for j in range(2):
        B[i][j] -= 1
# print(A)
# print(B)

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    # def size(self, x):
    #     if self.parents[x] < 0:
    #         return -self.parents[x]
    #     else:
    #         self.parents[x] = self.size(self.parents[x])
    #         return self.parents[x]
    def size(self, x):
        # print(x)
        if self.parents[x] < 0:
            return -self.parents[x]
        # if x<0:
        #     return -x
        else:
            self.parents[x] = -abs(self.size(self.parents[x]))
            return abs(self.parents[x])
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def n_cc(self):  # 連結成分の数
        A = [i for i in self.parents if i < 0]
        return len(A)

U = UnionFind(n)
for i in range(m):
    a = A[i][0]
    b = A[i][1]
    U.union(a, b)
C = [0] * n

for i in range(m):
    a = A[i][0]
    b = A[i][1]
    C[a] -= 1
    C[b] -= 1
for i in range(k):
    a = B[i][0]
    b = B[i][1]
    if U.find(a) == U.find(b):
        C[a] -= 1
        C[b] -= 1
# print(C)
ANS = []
for i in range(n):
    ANS.append(U.size(i) + C[i] - 1)
print(" ".join([str(i) for i in ANS]))

Measured memory_bytes: 118364
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <stack>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>
#include <queue>
#include <stdio.h>
#include <math.h>


using namespace std;

typedef long long ll;

typedef vector<vector<int>> vvi;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef vector<ll> vll;

typedef pair<int, int> P;

typedef queue<int> qi;
typedef queue<string> qs;


#define rep(i, n) for(int i=0; i<(n); ++i)
#define repp(i, a, b) for(int i = (a); i <= (b); i++)
#define Rep(i, n) for(int i=n; i >= 0; i--)

#define all(v) v.begin(), v.end()
//sort( all(v) )　などと使える

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

int H, W;
using Grid = vector<vector<char>>;
Grid grid;
vector<vector<int>> dist;
queue<P> Q;

//vector<int> d_number(2510, 0);

int white_number = 0;

int max_d = 0;

int main() {
	cin >> H >> W;
	grid.resize(H, vector<char>(W));
	rep(i, H) rep(j, W) {
		cin >> grid[i][j];
		if (grid[i][j] == '.') white_number++;
	}

	dist.assign(H, vector<int>(W, -1));
	dist[0][0] = 0;
	Q.push(make_pair(0, 0));
	//d_number[0]++;

	while (!Q.empty()) {
		int x = Q.front().first, y = Q.front().second;
		Q.pop();

		rep(i, 4) {
			int nx = x + dx[i], ny = y + dy[i];

			if (nx < 0 || nx >= H || ny < 0 || ny >= W) continue;
			else if (dist[nx][ny] != -1 || grid[nx][ny] == '#') continue;
			else {
				dist[nx][ny] = dist[x][y] + 1;
				Q.push(make_pair(nx, ny));
				//d_number[d]++;
			}
		}
	}

	if (dist[H - 1][W - 1] == -1) cout << -1 << endl;
	else cout << white_number - dist[H-1][W-1] - 1 << endl;
}	

Measured memory_bytes: 3648
N = int(input())
S = input()

ans = S.count('R') * S.count('G') * S.count('B')
for i in range(N):
  for j in range(i+1,N):
    if (i+j)%2 :
      continue
    k = (i+j)//2
    if len(set([S[i],S[k],S[j]])) == 3:
      ans -= 1
      
print(ans)

Measured memory_bytes: 73868
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,C;
  cin>>n>>C;
  int d[33][33],c[3][33]={};
  for(int i=0;i<C;i++)
    for(int j=0;j<C;j++)
      cin>>d[i][j];
  for(int i=0;i<n;i++)
    for(int j=0;j<n;j++){
      int a;
      cin>>a;
      c[(i+j)%3][--a]++;
    }
  int ans=1e9;
  for(int i=0;i<C;i++)
    for(int j=0;j<C;j++)
      for(int k=0;k<C;k++){
	if(i==j||j==k||i==k)continue;
	int sum=0;
	for(int x=0;x<C;x++){
	  sum+=c[0][x]*d[x][i];
	  sum+=c[1][x]*d[x][j];
	  sum+=c[2][x]*d[x][k];
	}
	ans=min(ans,sum);
      }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <numeric>
#include <cmath>

#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
using P = pair<ll, ll>;

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 ll MOD = 1000000007;
const int INF = 1<<29;

int main(){
  int N, M; cin >> N >> M;
  priority_queue<ll> q;
  rep(i, N){
    int A; cin >> A;
    q.push(A);
  }
  rep(i, M){
    int A = q.top(); q.pop();
    q.push(A / 2);
  }
  ll ans = 0;
  while (!q.empty()){
    ans += q.top(); q.pop();
  }
  cout << ans << endl;
}


Measured memory_bytes: 1400
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
#define ROF(i,a,b) for(int i=a;i>=b;i--)
#define per(i,a) ROF(i,a,0)
#define pb push_back
using namespace std;
using ll=long long;
using ld=long double;
using ch=char;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<ch> vc;
typedef vector<vc> vvc;
const ll MOD=1000000007;
const ll MOD2=998244353;
const ld PI=acos(-1);
const ll INF=1e18;
struct edge{ll to,cost;};
struct edge2{ll from,to,cost;};

template <typename T>
bool chmax(T &a, const T& b) {
    if (a < b) {
      a = b;
        return true;
    }
    return false;
}

template <typename T>
bool chmin(T &a, const T& b) {
    if (a > b) {
      a = b;
      return true;
    }
    return false;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int A,B,Q;
    cin >> A >> B >> Q;
    set<ll> sts,stt;
    rep(i,A){
        ll a;
        cin >> a;
        sts.insert(a);
    }
    rep(i,B){
        ll b;
        cin >> b;
        stt.insert(b);
    }
    sts.insert(INF),stt.insert(INF);
    sts.insert(-INF),stt.insert(-INF);
    while(Q--){
        ll x;
        cin >> x;
        ll sp,sm,tp,tm;
        auto itrs=sts.lower_bound(x);
        if(x==*itrs){
            sp=sm=x;
        }
        else{
            sp=*itrs;
            itrs--;
            sm=*itrs;
        }
        auto itrt=stt.lower_bound(x);
        if(x==*itrt){
            tp=tm=x;
        }
        else{
            tp=*itrt;
            itrt--;
            tm=*itrt;
        }
        cout << min({max(sp,tp)-x,x-min(sm,tm),(2*(sp-x)+(x-tm)),(2*(x-tm)+(sp-x)),(2*(x-sm)+(tp-x)),(2*(tp-x)+(x-sm))}) << '\n';
    }
}
/*
overflow checked?
corner case checked?
boundary checked?
not TLE in worst case checked?
*/

Measured memory_bytes: 12960
// AOJ 0550: Dividing Snacks
// 2017.11.18 bal4u@uu

#include <stdio.h>
#include <string.h>

#define INF 0x33333333
int dp[2][2][5001];
int ti[10001];
char buf[20], *p;

int getint()
{
	int n = 0;
	while (*p >= '0') n = (n<<3) + (n<<1) + (*p++ & 0xf);
	return n;
}

int main()
{
    int n, n1, n2, i, j, k1, k2, ans;
	
	fgets(p=buf, 20, stdin), n = getint(), n1 = n - 1, n2 = n >> 1;
	for (i = 0; i < n1; i++) {
		fgets(p=buf, 20, stdin); 
		ti[i] = getint();
	}

	memset(dp, INF, sizeof(dp));
    dp[0][0][0] = dp[0][1][0] = 0;
    for (k1 = 0, k2 = 1, i = 0; i < n; i++, k1 = k2, k2 = !k2) {
		memset(dp[k2], INF, sizeof(int)*(n2+1));
		for (j = 0; j <= n2; j++) {
			if(dp[k1][0][j] < INF) {
				if (dp[k2][0][j+1] > dp[k1][0][j]) dp[k2][0][j+1] = dp[k1][0][j];
				if (dp[k2][1][j+1] > dp[k1][0][j]+ti[i]) dp[k2][1][j+1] = dp[k1][0][j]+ti[i];
			}
			if(dp[k1][1][j] < INF) {
				if (dp[k2][1][j] > dp[k1][1][j]) dp[k2][1][j] = dp[k1][1][j];
				if (dp[k2][0][j] > dp[k1][1][j]+ti[i]) dp[k2][0][j] = dp[k1][1][j] + ti[i];
			}
		}
    }
    ans = dp[k1][0][n2]; if (ans > dp[k1][1][n2]) ans = dp[k1][1][n2];
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 1952