akhauriyash/Code-Regression huggingface dataset:
from collections import deque


def main():
    def bfs(start):
        q = deque([start])
        while q:
            u = q.popleft()
            for v, w in g[u]:
                if color[v] == -1:
                    q.append(v)
                    if w == 0:
                        color[v] = color[u]
                    else:
                        color[v] = color[u] ^ 1

    n = int(input())
    g = [[] for _ in range(n)]
    color = [-1] * n
    color[0] = 1
    for _ in range(n - 1):
        u, v, w = map(int, input().split())
        u -= 1
        v -= 1
        w %= 2
        g[u].append((v, w))
        g[v].append((u, w))
    bfs(0)
    print(*color)


if __name__ == "__main__":
    main()

Measured memory_bytes: 72096
#include <iostream>
#include <iomanip>
#include <cmath>
#include <algorithm>

using namespace std;

int n,m,s;
int a[100005],dist[100005];

int main()
{
    cin>>n>>m;
    for(int i=1; i<=m; i++)
        cin>>a[i];
    if(n>=m)
    {
        cout<<0;
        return 0;
    }
    else
    {
        sort(a+1,a+m+1);
        for(int i=2; i<=m; i++)
            dist[i-1]=abs(a[i]-a[i-1]);

        sort(dist+1,dist+m);
//        for(int i=1; i<=m-1; i++)
//            cout<<dist[i]<<" ";
        //cout<<endl;
        for(int i=1; i<=m-n; i++)
            s+=dist[i];
        cout<<s;
    }

    return 0;
}


Measured memory_bytes: 1024
# -*- coding: utf-8 -*-

def io_generator():
	return input()

#+++++++++++++++++++

def main(io):
	str=list(io())
	
	agct=list('AGCT')
	max=0
	current=0
	
	for c in str:
		if c in agct:
			current+=1
			max = current if current > max else max
		else:
			current=0	
	
	return max

#++++++++++++++++++++

if __name__ == "__main__":
	io= lambda : io_generator()
	print (main(io))

Measured memory_bytes: 3064
#include<stdio.h>
#include<algorithm>
using namespace std;
int UF[200];
int FIND(int a){
	if(UF[a]<0)return a;
	return UF[a]=FIND(UF[a]);
}
void UNION(int a,int b){
	a=FIND(a);b=FIND(b);if(a==b)return;UF[a]+=UF[b];UF[b]=a;
}
int deg[100];
int main(){
	int a;
	while(~scanf("%d",&a)){
		for(int i=0;i<10;i++)deg[i]=0;
		for(int i=0;i<10;i++)UF[i]=-1;
		while(a--){
			int b;scanf("%d",&b);
			UNION(b/10,b%10);
			deg[b/10]++;
			deg[b%10]++;
		}
		bool ok=true;
		int ki=0;
		for(int i=0;i<10;i++){
			if(deg[i]%2)ki++;
			for(int j=0;j<10;j++)if(deg[i]&&deg[j]&&FIND(i)!=FIND(j))ok=false;
		}
		if(ki>2)ok=false;
		if(ok)printf("Yes\n");else printf("No\n");
	}
}

Measured memory_bytes: 1012
#include <bits/stdc++.h>
using namespace std;
#define testing 0
#define FOR(ii, ss, ee) for(ll ii = (ss); ii <= (ll)(ee); ++ii)
#define DEC(ii, ss, ee) for(ll ii = (ss); ii >= (ll)(ee); --ii)
#define IAMSPEED ios_base::sync_with_stdio(false); cin.tie(0);
#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << " , " << #y << "=" << y << endl
#define db3(a,b,c) cerr<<#a<<"="<<a<<","<<#b<<"="<<b<<","<<#c<<"="<<c<<endl
#define dbv(v) cerr << #v << ":"; for (auto i : v) cerr << i << ' '; cerr << endl
#define dbvp(v) cerr << #v << ":"; for (auto i : v) cerr << "{"  << i.f << ',' << i.s << "} "; cerr << endl
#define dba(a,ss,ee) cerr << #a << ":"; FOR(i,ss,ee) cerr << a[i] << ' '; cerr << endl
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define ll long long 
#define pb push_back
#define inf (int)1e9
#define oo (ll)1e18
#define all(x) (x).begin(), (x).end()
#define f first
#define s second
#define reach cerr << "hi\n";
typedef pair <int, int> pi;
typedef pair <ll,ll> pl;
typedef pair <pi, int> pii;
string lts(ll x) {stringstream s; s << x; return s.str(); }
ll stl(string x) {stringstream s(x); ll temp; s >> temp; return temp; }
string cts(char x) {string s(1,x); return s;}
const int MOD = 1e9 + 7;
template <typename T> void maxself(T& a, T b) {
    a = max(a, b);
}
template <typename T> void minself(T& a, T b) {
    a = min(a, b);
}
#define MAXN 
#if !testing
    #define cerr if(0)cout
#endif

int main() {
    IAMSPEED
    // set testing to 0 when submitting to judge
    #if testing
        freopen("input.txt", "r", stdin);
    #endif
    ll a,b; cin >> a >> b;
    cout << a/__gcd(a,b) * b;
}


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

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

    int ans = 0;
    for (int i = 1; i < 1000; i++)
        for (int j = i; i * j < n; j++)
            if (i == j)
                ans++;
            else
                ans += 2;

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


Measured memory_bytes: 3632
#include <stdio.h>

int main(void){

  int n,k,c;
  scanf("%d %d %d", &n, &k, &c);

	char s[n];
	scanf("%s", s);

  int first[k];
  int last[k];
  int work = 0;
  int day;

  for (day = 0; work < k; day++) {
    if (s[day] == 'o') {
      first[work] = day;
      day += c;
      work++;
    }
  }

  work = 0;
  for (day = n-1; work < k; day--) {
    if (s[day] == 'o') {
      last[work] = day;
      day -= c;
      work++;
    }
  }

  for (int i = 0; i < k; i++) {
    if (first[i] == last[k-i-1]) {
      day = first[i]+1;
      printf("%d\n", day);
    }
  }

  return 0;
}

Measured memory_bytes: 3200
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;

constexpr ll mod = 1e9 + 7;

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

/*-------------------------------------------*/

ll n, l, q;
ll x[100009], nxt[100009][17];

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

    cin >> n;
    rep(i, n) cin >> x[i];
    cin >> l;
    ll y = 0;
    rep(i, n) {
        while(y + 1 < n && x[i] + l >= x[y + 1]) {
            y++;
        }
        nxt[i][0] = y;
    }
    rep(i, 16) rep(j, n) nxt[j][i + 1] = nxt[nxt[j][i]][i];

    cin >> q;
    while(q--) {
        ll a, b;
        cin >> a >> b;
        a--;
        b--;
        if(b < a) swap(a, b);
        ll ans = 1;
        for(int i = 16; i >= 0; i--) {
            if(nxt[a][i] < b) {
                a = nxt[a][i];
                ans += 1 << i;
            }
        }
        cout << ans << endl;
    }

    return 0;
}

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

typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 28;

// AGCを含むかどうか、判定する
bool containAGC(string s) { return s.find("AGC") != string::npos; }

// 入れ替えた時にAGCが入っているか、判定する
bool ok(string s) {
  bool res = true;
  res = !containAGC(s);  // AGC予防
  for (int i = 0; i < s.size() - 1; i++) {
    swap(s[i], s[i + 1]);  // 一回スワップしてみる
    if (containAGC(s)) res = false;
    swap(s[i], s[i + 1]);  // 元に戻す
  }
  return res;
}

// ====================================================================

int main() {
  int n;
  cin >> n;
  string AGCT = "AGCT";
  vector<map<string, ll>> dp(n + 1);

  dp[0][""] = 1;
  for (int i = 0; i < n; i++) {
    for (auto s : dp[i]) {
      for (auto x : AGCT) {
        string next = s.first + x;
        if (next.size() > 4) next.erase(next.begin());  // 4文字以下になるように調整
        if (ok(next)) {
          dp[i + 1][next] += dp[i][s.first];
          dp[i + 1][next] %= MOD;
        }
      }
    }
  }

  ll ans = 0;
  for (auto x : dp[n]) {
    ans += x.second;
    ans %= MOD;
  }

  cout << ans << endl;
}


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

#define rep(i,n) for(int i=0; i<n; i++)
#define rept(i,a,b) for(int i=a; i<b; i++)
#define all(x) (x).begin(),(x).end()
#define fst first
#define sec	second
#define pb push_back

typedef long long ll;
typedef vector<int> vi;
typedef pair<long,long> P;

const int mod = 1e9 + 7;


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

	int n;
	cin >> n;

	


	cout << n * n * n << endl;

    return 0;
}



Measured memory_bytes: 256
use proconio::*;

fn main() {
    input! {
        x: i32,
        n: i32,
    }

    let mut p = vec![];
    for _ in 0..n {
        input! {
            v: i32,
        }

        p.push(v);
    }

    let mut diff = std::i32::MAX;
    let mut ans= -1;
    for v in 0..102 {
        if !p.contains(&v) && diff > (x - v).abs() {
            diff = (x - v).abs();
            ans = v;
        }
    }

    println!("{}", ans);
}

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

using namespace std;

using ll = long long;

const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}

int main () {
  cin.tie(0);
  cout << fixed << setprecision(10);
  while(1) {
    ll b; cin >> b;
    if(b == 0) break;
    ll ansb = b, answ = 1;
    for(ll i=1;i*i<=2*b;++i) {
      if(2*b%i == 0) {
        ll tmp = (2*b/i) - (i-1);
        if(tmp >= 2 && tmp % 2 == 0 && answ < i) {
          ansb = tmp / 2;
          answ = i;
        }
      }
    }
    cout << ansb << " " << answ << endl;
  }
}



Measured memory_bytes: 3084
N = int(input())
a = [0 for i in range(N)]
for i in range(N):
    a[i] = int(input())
    
visited = [False for i in range(N)]
cur = 0
laps = 0
while True:
    if cur == 1 or visited[cur]:
        break
        
    visited[cur] = True
    next = a[cur] - 1
    laps += 1
    cur = next
    
if cur == 1:
    print(laps)
else:
    print(-1)

Measured memory_bytes: 7848
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define mod 1000000007
using ll=long long;
const int INF=1000000000;
const ll LINF=1001002003004005006ll;
int dx[]={1,0,-1,0},dy[]={0,1,0,-1};
// ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;}

struct IOSetup{
    IOSetup(){
        cin.tie(0);
        ios::sync_with_stdio(0);
        cout<<fixed<<setprecision(12);
    }
} iosetup;
 
template<typename T1,typename T2>
ostream &operator<<(ostream &os,const pair<T1,T2>&p){
    os<<p.first<<" "<<p.second;
    return os;
}
 
template<typename T>
ostream &operator<<(ostream &os,const vector<T>&v){
    for(int i=0;i<(int)v.size();i++) os<<v[i]<<(i+1==(int)v.size()?"":" ");
    return os;
}

template<typename T1,typename T2>
istream &operator>>(istream &is,pair<T1,T2>&p){
    is>>p.first>>p.second;
    return is;
}

template<typename T>
istream &operator>>(istream &is,vector<T>&v){
    for(T &x:v)is>>x;
    return is;
}


signed main(){
    string s,t;cin>>s>>t;
    int n=s.size(),m=t.size();

    int res=m;
    rep(i,n-m+1){
        string a=s.substr(i,m);
        int cnt=0;
        rep(j,m){
            if(a[j]!=t[j])cnt++;
        }
        chmin(res,cnt);
    }
    cout<<res<<endl;
    return 0;
}


Measured memory_bytes: 3620
#include <cstdio>

#define MOD 1000000007

#define MAXN 100000

const int q=2*MAXN;

int fact[q+1], invFact[q+1];

inline int lgput(int a, int n){
    int r=1;
    while(n){
        if(n%2) r=1LL*a*r%MOD;
        n/=2;
        a=1LL*a*a%MOD;
    }
    return r;
}

inline int comb(int n, int k){
    if(n<k) return 0;
    else return 1LL*fact[n]*invFact[k]%MOD*invFact[n-k]%MOD;
}

int main(){
    int h, w, a, b;
    scanf("%d%d%d%d", &h, &w, &a, &b);

    fact[0]=1;
    for(int i=1; i<=q; i++)
        fact[i]=1LL*fact[i-1]*i%MOD;
    invFact[q]=lgput(fact[q], MOD-2);
    for(int i=q-1; i>=0; i--)
        invFact[i]=1LL*invFact[i+1]*(i+1)%MOD;

    int ans=1LL*comb(h-a-1+b, b)*comb(a+w-b-1, w-b-1)%MOD;
    for(int i=b+2; i<=w; i++)
        ans=(ans+1LL*comb(h-a-2+i-1, i-1)*comb(a+w-i, w-i))%MOD;

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

    return 0;
}


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

using namespace std;
typedef long long LL;

int main(){
  int N;
  cin >> N;
  vector<int> a(N);
  rep(i,N) cin >> a[i];
  int M=0;
  vector<int> b(N);
  for(int i=N-1; i>=0; i--){
    bool A=a[i];
    for(int j=2; j*(i+1)<=N; j++){
      if(b[j*(i+1)-1]) A= !A;
    }
    b[i]=A;
    if(A) M++;
  }
  cout << M << endl;
  vector<int> ans;
  rep(i,N) if(b[i]) ans.emplace_back(i+1);
  rep(i,M-1) cout << ans[i] << " ";
  if(M-1>=0) cout << ans[M-1] << endl;

  return 0;
}


Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt();
			int a = scanner.nextInt();
			System.out.println((a >= (n % 500)) ? "Yes" : "No");
		}
	}
}


Measured memory_bytes: 23252
import java.util.Objects;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scn = new Scanner(System.in);
        int n = scn.nextInt();
        String str = scn.next();
        if(n % 2 != 0){
            System.out.println("No");
        }else{
            int half = n/2;
            if(Objects.equals(str.substring(0, half),str.substring(half))){
                System.out.println("Yes");
            }else{
                System.out.println("No");
            }
        }
    }
}

Measured memory_bytes: 23636
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <climits>
#include <math.h>
using namespace std;

typedef long long ll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<long long> vll;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vector<bool>> vvb;
typedef vector<vector<int>> vvi;

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

bool isOk(string& s) {
	int n = s.size();
	if (n % 2 == 1)return false;
	string s1, s2;
	s1 = s.substr(0, n / 2);
	s2 = s.substr(n / 2, n);
	return s1 == s2;
}

int main() {
	string s;
	cin >> s;
	int n = s.size();
	int ans = 0;
	for (int i = 2; i < n; i += 2) {
		string t = s.substr(0, n - i);
		if (isOk(t)) {
			ans = n - i;
			break;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
from collections import deque
H, W = map(int, input().split())
maze = [input() for i in range(H)]

def bfs(maze, sy, sx):
    visited = [[-1]*W for j in range(H)]
    queue = deque([[sy, sx]])
    visited[sy][sx] = 0
    while queue:
        ans=0
        y, x = queue.popleft()
        for j, k in ([1, 0], [-1, 0], [0, 1], [0, -1]):
            new_y, new_x = y+j, x+k
            if 0 <= new_y < H and 0 <= new_x < W:
                if maze[new_y][new_x] == "." and visited[new_y][new_x] == -1 :
                    visited[new_y][new_x] = visited[y][x] + 1
                    queue.append([new_y, new_x])
                    
    for l in range(H):
        for m in range(W):
            ans = max(ans,visited[l][m])
            
    return ans
        
ma=0
for sy in range(H):
    for sx in range(W):
        if maze[sy][sx] == ".":
            if bfs(maze,sy,sx) is not None:
                ma = max(bfs(maze, sy, sx),ma)
print(ma)


Measured memory_bytes: 75232
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
ll mod=1e9+7;
#define fi0 for(ll i=0;i<n;i++)
ll mode(ll n){
    return ((n%mod)+mod)%mod;
}
void solve()
{
    ll n;
    cin>>n;
    vector<ll>a(n);
    fi0 cin>>a[i];
    vector<ll>b(n+1);
    for(ll i=n-1;i>=0;i--){
        b[i]=b[i+1]+a[i];
        b[i]=mode(b[i]);
    }
    ll sum=0;
    for(ll i=1;i<n;i++){
        sum+=(mode(a[i-1])*mode(b[i]));
        sum=mode(sum);
    }
    cout<<sum<<endl;
}
void abc(){
 int i, j, k;
    int n,m;
    int x,y;

    cin>>n;

    ll cnt=0;
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=n;j++)
        {
            x=i^j;

            if(x<=n && x>0)
            {
                k=0;
                if(i+j<=x)
                    k++;
                else if(i+x<=j)
                    k++;
                else if(x+j<=i)
                    k++;

                if(k<=0)
                    cnt++;
            }
        }
    }

    cout<<cnt/6;
}
void bcd(){
    string s,ss;
    cin>>s>>ss;
    int sum=0,n=s.size(),nn=ss.size();
    for(int i=0;i<=n-nn;i++){
            int a=0;
        for(int j=i;j<i+nn;j++){
            if(s[j]==ss[j-i]){
                a++;
            }
           /// cout<<s[j]<<ss[j]<<' ';

        }
        sum=max(a,sum);
       /// cout<<sum<<endl;
    }
    cout<<ss.size()-sum<<endl;
}
int main()
{
   ///int t;cin>>t;while(t--){
    solve();
    return 0;
}


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

    #define ll long long
    #define ff first
    #define ss second
    #define pb push_back
    #define vll vector<ll>
    #define mll map<ll,ll>
    #define MOD 1000000007
    #define pll pair<ll,ll>
constexpr ll INF = 1999999999999999997; 
    #define fastio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
    int main() {
        fastio;

        string s;
        cin>>s;
        string ans="Good";
        for(int i=0;i<3;i++)
        {
            if(s[i]==s[i+1])
                ans="Bad";
        }

        cout<<ans<<endl;


    }

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

#define int long long

signed main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int N;
    cin >> N;
    vector<string> s(N);
    for (int i = 0; i < N; i++) cin >> s[i], sort(s[i].begin(), s[i].end());
    sort(s.begin(), s.end());
    string pres = s[0];
    int ans = 0;
    int seq = 1;
    for (int i = 1; i < N; i++) {
        if (pres == s[i]) seq ++;
        else {
            ans += seq * (seq - 1) / 2;
            seq = 1;
        }
        pres = s[i];
    }
    ans += seq * (seq - 1) / 2;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 5760
<?php
$input = explode(" ",trim(fgets(STDIN)));
$a = intval($input[0]);
$b = intval($input[1]);
$c = intval($input[2]);
$cnt = 0;
for($i=$a;$i<=$b;$i++){
    if($c%$i===0){
        $cnt++;
    }
}
echo $cnt;
?>

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

int main(){
    
    int a,b,c;
    cin >> a >> b >> c;
    if(a == b && a == c){
        cout << 1;
    }
    else if(a == b || b == c || c == a){
        cout << 2;
    }
    else{
        cout << 3;
    }
    
    return 0;
}

Measured memory_bytes: 256
#define RUN
#ifdef RUN
#include <iostream>
#include <string>
#include <map>
#include <utility>
using namespace std;

int main() {
    string s;
    cin >> s;
    map<char, int> m;
    for (char c : s) {
        if (!m.count(c)) {
            m.insert(make_pair(c, 0));
        }
        m[c]++;
    }
    bool ans = false;
    if (m.size() == 2) {
        ans = true;
        for (auto e : m) {
            if (e.second != 2) {
                ans = false;
            }
        }
    }
    if (ans) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
    return 0;
}
#endif

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

int main() {
	int m1,m2,d1,d2;cin >> m1>>d1;
	cin >> m2>>d2;
	int ans;
	if(m1<m2){
		ans =1;
	} else {
		ans =0;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
kokyaku = Hash.new{|h,k| h[k] = Array.new(2){[]}}
month = 0
readlines.each{|line|
  if line =~ /^$/
    month += 1
    next
  end
  c,d = line.split(",").map(&:to_i)
  kokyaku[c][month] << d
}

kokyaku.sort.each{|h, k|
  if kokyaku[h][0].size > 0 &&  kokyaku[h][1].size > 0
    puts "#{h} #{kokyaku[h][0].size + kokyaku[h][1].size}"
  end
}

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

int head;
int tail;
const int LEN = 100005;


struct ProcessInfo{
    string name;
    int time;
};

ProcessInfo queues[LEN];

void initialize(){
    head = tail =0;
}

bool isEmpty(){
    if(head==tail){
        return true;
    }
    else{
        return false;
    }
}

void enqueue(ProcessInfo pi){
    queues[tail]=pi;
    tail = (tail+1)%LEN;
}

ProcessInfo dequeue(){
    ProcessInfo temp = queues[head];
    head = (head+1)%LEN;
    return temp;
}

int main(){
    //initializing
    int n,p;
    int totaltime=0;
    ProcessInfo temp;
    cin >>n;
    cin >>p;
    for(int i=0;i<n;i++){
        cin >> queues[i].name;
        cin >> queues[i].time;
    }
    head =0;
    tail =n;
    while (!isEmpty()) {
        if(queues[head].time>p){
            queues[head].time -=p;
            totaltime+=p;
            temp =dequeue();
            enqueue(temp);
        }
        else{
            temp = dequeue();
            totaltime+=temp.time;
            cout << temp.name << " " << totaltime << endl;
        }
    }
}

Measured memory_bytes: 5112
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
int main(){
  ll n = 0;
  cin >> n;
  vector<ll> m(n);
  ll heikinn = 0;
  for(int i = 0;i < n;i++){
    cin >> m[i];
    m[i] -= i + 1;
  }
  sort(m.begin(),m.end());
  ll a = 0;
  if(n % 2 == 1)a = m[n / 2];
  else a = (m[n / 2] + m[n / 2 - 1]) / 2;
  ll res = 0;
  //res = pow(10,18);
    for(int j = 0;j < n;j++){
      res += abs(a - m[j]);
    }
  cout << res << endl;
}

Measured memory_bytes: 1792
//is there any case of -1 or any special corner cases ?
#include<bits/stdc++.h>
using namespace std;
#define int long long int 
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define vi vector<int>
#define pi pair<int,int>
#define all(v) v.begin(),v.end()
#define zeros(arr) memset(arr,0,sizeof(arr));
#define precise(num)  cout<<fixed; cout << std::setprecision(num)
#define nl cout<<"\n";
#define test int t;cin>>t;while(t--) 
const int maxx  = 3*1e5 , limit = 9*1e18 , MOD=1e9+7;
string binary(int n){bitset<60>b(n) ;string p =b.to_string();return p;}
int decimal(string n) { int dec_value = 0;  int base = 1;  for (int i = n.size() - 1; i >= 0; i--) { if (n[i] == '1') 
dec_value += base; base = base * 2; } return dec_value; } 
bool isPrime(int n){if (n <= 1) return false; if (n <= 3) return true;if (n % 2 == 0 || n % 3 == 0) return false;
for (int i = 5; i * i <= n; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; }
int pow (int x, int n,int mod) {if (n == 0) return 1; int res = pow (x, n / 2,mod);res = (res * res) % mod;if (n % 2) res = (res * x ) % mod;return res;}
#define boost  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl '\n';

int32_t main(){
    boost;
    int n;
    cin>>n;
    int res = 0;
    for(int i=1;i<=n;i++){
        int x;
        cin>>x;
        if(i%2 && x%2)res++;
    }
    cout<<res<<endl;
    
}

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

#define ibs ios_base::sync_with_stdio(false)
#define cti cin.tie(0)
#define cot cout.tie(0)


using namespace std;




int main()
{
    int a,p;
    cin>>a>>p;
    p = p+(3*a);
    cout<<p/2;
    
return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
using ll = long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(), v.end()

int main(){
  ll n, k;
  cin >> n >> k;
  ll a = n % k;
  ll b = k - a;
  cout << min(a, b) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ALL(x) (x).begin(),(x).end()
#define COUT(x) cout<<(x)<<"\n"
#define REP(i, n) for(int i=0;i<n;i++)
#define YES(x) cout<<(x?"YES":"NO")<<"\n"
#define Yes(x) cout<<(x?"Yes":"No")<<"\n"
#define dump(x) cout<<#x<<" = "<<(x)<<"\n"
#define endl "\n"
using G = vector<vector<int>>;
using M = map<int,int>;
using P = pair<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int,vector<int>,greater<int>>;
using V = vector<int>;
using ll = long long;
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; }
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int main() {
  ll a; double b; cin >> a >> b;
  ll b2 = (ll)(b*100.0+0.5);
  COUT(a*b2/100);
  return 0;
}

Measured memory_bytes: 3692
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<algorithm>
#include<iostream>

using namespace std;
int main(void){
	int N;
	int a=0,b=0,A,B,h=100,w=100;
	vector<string> s; 
	scanf("%d%d", &A,&B);
	printf("%d %d\n",h,w);
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			if(i < 50){
				if(i%2 == 0 && j%2 == 0 && a < A-1){
					printf(".");a++;
				}else{
					printf("#");
				}
			}else{
				if(i%2 == 1 && j%2 == 1 && b < B-1){
					printf("#");b++;
				}else{
					printf(".");
				}
			}
		}
		printf("\n");
	}

	fflush(stdout);

	return 0;
}

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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;

int main()
{
    int r, g, b;
    cin >> r >> g >> b;
    (100 * r + 10 * g + b) % 4 == 0 ? OP("YES") : OP("NO");
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] p = new int[n + 1];
        String res = "YES";
        for(int i = 1; i <= n; i++) p[i] = sc.nextInt();
        for(int i = 1; i <= n; i++) {
            if(i != p[i] && p[p[i]] == i) {
                p[p[i]] = p[i];
                p[i] = i;
                break;
            }
        }
        for(int i = 1; i < n; i++) if(p[i] > p[i + 1]) res = "NO";
        System.out.println(res);
    }
}


Measured memory_bytes: 22740
import java.io.*;

public class Main{
	
	static int num = 0;	//Number of Combination
	
	public static void calcNum(int value, int remNum){	//Number of remaining factors
		if(remNum == 1){
			num++;
		}else{
			for(int i=0; i<10; i++){
				if(value-i < 0)break;
				if((value-i) < 9 * (remNum-1)){
					calcNum(value-i, remNum-1);
				}else if((value-i) == 9 * (remNum-1)) num++;
			}
		}
	}
	
	public static void main(String[] argv) throws NumberFormatException, IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;
		while((line = br.readLine()) != null){
			int value = Integer.parseInt(line);
			calcNum(value, 4);
			System.out.print(Integer.toString(num)+"\n");
			num = 0;
		}
	}
}

Measured memory_bytes: 16688
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int A = sc.nextInt();
        int B = sc.nextInt();
        int C = sc.nextInt();

        System.out.println(C + " " + A + " " + B);
    }
}

Measured memory_bytes: 20820
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int a,b,c,d,e,f,ans;
  cin >> a >> b;
  c=a+b; d=a-b; e=a*b;
  f=max(c,d);
  ans=max(f,e);
  cout << ans;
}

Measured memory_bytes: 256
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]

N = INT()

S = set()
for i in range(1, 10):
    for j in range(1, 10):
        S.add(i*j)
if N in S:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
#include <math.h>
 
using namespace std;

int main(){
  int n,k;
  cin >> n >> k;
  vector <long> vec(n);
  vector <long> sa(n-k+1);
  for (int i=0;i<n;i++) cin >>vec.at(i);
  sort (vec.begin(),vec.end());
  for (int i=0;i<n-k+1;i++) sa.at(i)=vec.at(i+k-1)-vec.at(i);
  long ans=vec.at(n-1)-vec.at(0);
  for (int i=0;i<n-k+1;i++) ans = min(ans,sa.at(i));
  cout << ans << endl;
}
  

Measured memory_bytes: 1792
n, m = map(int, input().split())
t = []
for i in range(m):
    p,y = map(int, input().split())
    t.append([p, y, i])
target = sorted(t)
target[0].append(1)
cnt = 1
for i in range(1,m):
    if target[i][0]!=target[i-1][0]:
        cnt = 1
    else:
        cnt += 1
    target[i].append(cnt)
ans = sorted(target, key=lambda x:x[2])
for i in range(m):
    print(str(ans[i][0]).zfill(6) + str(ans[i][3]).zfill(6))

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

int main(void){
   
   string s,t;
   int c = 0;
   cin >> s >> t;
   
   for(int i=0;i<3;i++){
       if(s[i] == t[i]) c++;
   }
   
   cout << c << endl;
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define int long long
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

int n, m, s;

struct S{
	int from, coin, cost;
	bool operator>(const S &s) const{
		return cost > s.cost;
	}
};

struct edge{
	int to, fee, cost;
};

vector<edge> G[51];
int sil[51], tim[51];
int d[51][2501];

struct Dijkstra{
	Dijkstra(){}
	void calc(){
		REP(i, n) REP(j, 2501) d[i][j] = INF;
		if(s >= 2500) s = 2500;
		d[0][s] = 0;
		priority_queue<S, vector<S>, greater<S> > q;
		q.push({0, s, 0});
		while(!q.empty()){
			S p = q.top(); q.pop();
			int from = p.from;
			int coin = p.coin;
			int cost = p.cost;
			if(d[from][coin] < cost) continue;
			{
				int nextCoin = coin + sil[from];
				int nextCost = cost + tim[from];
				if(nextCoin > 2500) nextCoin = 2500;
				if(d[from][nextCoin] > nextCost){
					d[from][nextCoin] = nextCost;
					q.push({from, nextCoin, nextCost});
				}
			}
			rep(i, 0, G[from].size()){
				int next = G[from][i].to;
				int nextCoin = coin - G[from][i].fee;
				int nextCost = cost + G[from][i].cost;
				if(nextCoin >= 0 && d[next][nextCoin] > nextCost){
					d[next][nextCoin] = nextCost;
					q.push({next, nextCoin, nextCost});
				}
			}
		}
	}
};

signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cin >> n >> m >> s;
	REP(i, m){
		int u, v, a, b;
		cin >> u >> v >> a >> b;
		u--; v--;
		G[u].push_back({v, a, b});
		G[v].push_back({u, a, b});
	}
	REP(i, n){
		cin >> sil[i] >> tim[i];
	}
	Dijkstra dk;
	dk.calc();
	rep(i, 1, n){
		int ans = INF;
		REP(j, 2501) ans = min(ans, d[i][j]);
		cout << ans << endl;
	}
}

Measured memory_bytes: 7356
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Dice d1 = new Dice();

		@SuppressWarnings("resource")
		Scanner sc = new Scanner(System.in);

		String s = sc.nextLine();

		int[] i = ArrconvAtoi(s);

		char[] commands = sc.nextLine().toCharArray();

		d1.setFace(i);

			for (char c : commands) {
				d1.roll(c);
			}

		System.out.println(d1.getTop());
	}

	private static int[] ArrconvAtoi(String s) {
		String[] strs = s.split(" ");
		int[] ints = new int[strs.length];
		int i = 0;

		for (String st : strs) {
			ints[i] = Integer.parseInt(st);
			i++;
		}

		return ints;
	}
}


class Dice {
	final int F = 6;
	private int[] face;
	private int[] tmp;
	private int[] change = new int[F];

	Dice() {
		face = new int[F];
		tmp = new int[F];
	}

	public void roll(char c) {
		for (int i = 0; i < F; i++) {
			tmp[i] = face[i];
		}

		switch (c) {
		case 'N':
			change[0] = tmp[1];
			change[1] = tmp[5];
			change[2] = tmp[2];
			change[3] = tmp[3];
			change[4] = tmp[0];
			change[5] = tmp[4];
			break;
		case 'S':
			change[0] = tmp[4];
			change[1] = tmp[0];
			change[2] = tmp[2];
			change[3] = tmp[3];
			change[4] = tmp[5];
			change[5] = tmp[1];
			break;
		case 'E':
			change[0] = tmp[3];
			change[1] = tmp[1];
			change[2] = tmp[0];
			change[3] = tmp[5];
			change[4] = tmp[4];
			change[5] = tmp[2];
			break;
		case 'W':
			change[0] = tmp[2];
			change[1] = tmp[1];
			change[2] = tmp[5];
			change[3] = tmp[0];
			change[4] = tmp[4];
			change[5] = tmp[3];
			break;
		}

		setFace(change);

	}

	public int getTop() {
		return this.face[0];
	}

	public void setFace(int[] ints) {
		for (int i = 0; i < 6; i++) {
			this.face[i] = ints[i];
		}
	}

}



Measured memory_bytes: 26372
import itertools

n, m, q = map(int, input().split())
lst = []
for _ in range(q):
    lst_tmp = [int(i) for i in input().split()]
    lst.append(lst_tmp)

ans = 0

for l in itertools.combinations_with_replacement(range(1, m + 1), n):
    tmp_sum = 0
    for a, b, c, d in lst:
        if l[b - 1] - l[a - 1] == c:
            tmp_sum += d
    if ans < tmp_sum:
        ans = tmp_sum

print(ans)


Measured memory_bytes: 9172
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(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 Eunique(v) v.erase(unique(all(v)),v.end())
#define Eback(s) s.erase(s.end()-1,s.end())
#define pb push_back
#define pf push_front
#define mod 1000000007
#define m_p make_pair
#define DOUBLE fixed << setprecision(15)
#define OK puts("OK")
#define OK1 puts("OK1")
#define OK2 puts("OK2")
#define SIZE(s) (int)s.size()
#define Cout(n) cout<<(n)<<endl
#define INF 1000000000000000000LL

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
typedef vector<pair<ll,ll>> vpll;
typedef vector<string> vs;
const double pi = acos(-1.0);

template<class A, class B>
ostream& operator<<(ostream& ost, const pair<A, B>&p) {
	ost << "{" << p.first << ", " << p.second << "} ";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost, const vector<T>&v) {
	ost << "{";
	for (int i = 0; i<(int)v.size(); i++) {
		if (i)ost << ", ";
		ost << v[i];
	}
	ost << "} \n";
	return ost;
}

template<class A, class B>
ostream& operator<<(ostream& ost, const map<A, B>&v) {
	ost << "{";
	for (auto p:v) {
		ost << "{" << p.first << ", " << p.second << "} ";
	}
	ost << "} ";
	return ost;
}

ll gcd(ll x, ll y) { return (y == 0) ? x : gcd(y, x % y); }
ll lcm(ll x, ll y) { return x * y / gcd(x, y); }

int main()
{
	ll n,ans=0;
	string s;
	cin >> n >> s;
	rep(i,n-1){
		string t="",u="";
		map<char,ll> tt,uu;
		ll cnt=0;
		rep(j,n){
			(j<=i?t:u)+=s[j];
		}
		for(char c='a';c<='z';++c){
			bool b=false,d=false;
			rep(j,i+1){
				if(t[j]==c){
					b=true;
					break;
				}
			}
			rep(j,n-i-1){
				if(u[j]==c){
					d=true;
					break;
				}
			}
			if(b && d) cnt++;
		}
		ans=max(ans,cnt);
	}
	cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int dx[8]={-1,-1,-1,0,0,1,1,1};
int dy[8]={-1,0,1,-1,1,-1,0,1};
int main(){
  int h,w;cin >> h >> w;
  vector<string> s(h);
  for(int i=0;i<h;i++){
    cin >> s[i];
  }
  vector<vector<int>> ans(h,vector<int>(w));
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(s[i][j]=='#'){
        continue;
      }
      int cnt=0;
      for(int k=0;k<8;k++){
        int x=i+dx[k],y=j+dy[k];
        if(x>=0&&x<=h-1&&y>=0&&y<=w-1){
          if(s[x][y]=='#'){
            cnt++;
          }
        }
      }
      ans[i][j]=(char)cnt;
    }
  }
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(s[i][j]=='#'){
        cout << s[i][j];
      }
      else{
        cout << ans[i][j];
      }
    }
    cout << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,X;
  cin >> N >> X;
  int D=0,L=0,i=0;
  for(i;i<N;i++){
    cin >> L;
    D += L;
    if(D > X){
      break;
    }
  }
  cout << i + 1 << endl; 
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#define rep(a, b) for(a=0;a<b;a++)
int main(){
	int n, i, j;
	scanf("%d", &n);
	int *a, *b;
	a=(int*)malloc(sizeof(int)*n);
	b=(int*)malloc(sizeof(int)*n);
	rep(i, n)	scanf("%d", &a[i]);
	
	rep(i, n){
		b[a[i]-1]=i+1;
	}
	rep(i, n)	printf("%d ", b[i]);
	
	free(a);
	free(b);
	return 0;
}


Measured memory_bytes: 1536
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
 
public class Main {    
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        if(n % 1000 != 0){
            System.out.println(1000 - (n % 1000));
        }else{
            System.out.println(n % 1000);
        }
    }
}



Measured memory_bytes: 35768
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Scanner;
import java.util.TreeMap;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		Map<String,Integer> s = new LinkedHashMap<String,Integer>();
		for(int i = 0; i < n; i++) {
			String temp = sc.next();
			if(s.containsKey(temp)) {
				int c = s.get(temp)+1;
				s.put(temp, c);
			}
			else {
				s.put(temp, 1);
			}
		}
		Map<String,Integer> ans = new TreeMap<String,Integer>();
		int count = 0;
		for(String key:s.keySet()) {
			if(count < s.get(key)) {
				ans.clear();
				count = s.get(key);
				ans.put(key, count);
			}
			else if(count==s.get(key)) {
				ans.put(key, count);
			}
		}
		for(String key:ans.keySet()) {
			System.out.println(key);
		}
	}
}

Measured memory_bytes: 106560
#include<stdio.h>
#include <string>
#include <iostream>
#include <vector>
#include <sstream>
using namespace std;



int main(void)
{
  int a,b,c;
  vector<int> array;
  int i=0;
  while(1)
    {
	 ostringstream s;
     string os;	
	 cin>>a>>b;
	 if(!cin)break;
	  c=a+b;
      s <<c;
	  os=s.str();

	//  cout<<os.size()<<endl;
      array.push_back((os.size()));

	  s.clear();
	  os.clear();

	  if(array.size()==200)break;
	  
    }

  while(i<array.size())
    {
      cout<<array[i]<<endl;
	  i++;
    }
  array.clear();
}

Measured memory_bytes: 1236
import sys
stdin = sys.stdin

sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

def get_gcd(a:int, b:int) -> int:
    while b:
        a, b = b, a % b
    return a
    
def get_lcm(a:int, b:int) -> int:
    return (a // get_gcd(a,b)) * b

n,m = li()
s = lc()
t = lc()

sx = dict()
tx = dict()

lcm = get_lcm(n,m)

for idx, i in enumerate(range(1,lcm+1,lcm//n)):
    sx.update({i:s[idx]})

for idx, j in enumerate(range(1,lcm+1,lcm//m)):
    tx.update({j:t[idx]})
    
common_key = list(set(list(sx.keys())) & set(list(tx.keys())))

exist = True
for c in common_key:
    if sx[c] != tx[c]:
        exist = False
        break
    
if exist:
    print(lcm)
else:
    print(-1)

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

const int MAX = 1e5;

// 隣接リストを用いた深さ優先探索（再帰ver.） O(|V|+|E|)
vector<int> G[MAX], color(MAX), score(MAX);
// main関数からこれらを削除すること

int it = 0;
void dfs(int u, vector<int> &c) {
  color[u] = 1; // GRAY
  for (int i = 0; i < G[u].size(); i++) {
    int v = G[u][i];
    if (color[v] == 0) dfs(v, c);
  }
  color[u] = 2; // BLACK
  score[u] = c.at(it);
  it++;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  // 無向(有向)グラフの隣接リスト
  int n; // n:頂点数
  cin >> n;
  
  // vector<int> G[n]; // G:頂点数がnのグラフを表す隣接リスト
  
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    G[u].emplace_back(v);
    G[v].emplace_back(u); // 有向グラフではこの行をコメントアウト
  }
  
  vector<int> c(n);
  for (int i = 0; i < n; i++) cin >> c.at(i);
  
  sort(c.begin(), c.end());
  
  dfs(0, c);
  
  int totalscore = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < G[i].size(); j++) {
      totalscore += min(score[i], score[G[i][j]]);
    }
  }
  totalscore /= 2;
  
  cout << totalscore << '\n';
  for (int i = 0; i < n; i++) {
    if (i) cout << " ";
    cout << score[i];
  }
  cout << '\n';
}

Measured memory_bytes: 4224
#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 N;
    int K;
    cin >> N >> K;
    int n = N.size();
    vector<vector<ll>> dp0(n + 1, vector<ll>(K + 1, 0)), dp1(n + 1, vector<ll>(K + 1, 0));
    dp0[0][0] = 1;
    rep(i, n) {
        rep(j, K + 1) {
            if (N[i] == '0') {
                dp0[i + 1][j] = dp0[i][j];
                dp1[i + 1][j] = dp1[i][j];
                if (j > 0) dp1[i + 1][j] += dp1[i][j - 1] * 9;
            } else {
                dp1[i + 1][j] = dp0[i][j] + dp1[i][j];
                if (j > 0) {
                    dp0[i + 1][j] += dp0[i][j - 1];
                    dp1[i + 1][j] += dp0[i][j - 1] * (N[i] - '1') + dp1[i][j - 1] * 9;
                }
            }
        }
    }
    cout << dp0[n][K] + dp1[n][K] << "\n";
    /*
    rep(i, n + 1) {
        rep(j, K + 1) {
            cout << dp0[i][j] << "," << dp1[i][j] << "/";
        }
        cout << "\n";
    }
    */
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){

double l,r;
int countla=0;
int countra=0;
int countlb=0;
int countrb=0;
int countlc=0;
int countrc=0;
int countld=0;
int countrd=0;

while(scanf("%lf %lf",&l,&r) != EOF){

if(l>=1.1){
countla++;
}
else if(l<1.1&&l>=0.6){
countlb++;
}
else if(l<0.6&&l>=0.2){
countlc++;
}
else if(l<0.2){
countld++;
}

if(r>=1.1){
countra++;
}
else if(r<1.1&&r>=0.6){
countrb++;
}
else if(r<0.6&&r>=0.2){
countrc++;
}
else if(r<0.2){
countrd++;
}
}
printf("%d %d\n",countla++,countra++);
printf("%d %d\n",countlb++,countrb++);
printf("%d %d\n",countlc++,countrc++);
printf("%d %d\n",countld++,countrd++);

return 0;
}



Measured memory_bytes: 2048
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;

int a, b, n[55], sum = 0;
bool cmp(int x, int y){
	return x > y;
}
int main()
{
	scanf ("%d %d", &a, &b);
	for (int i = 1; i <= a; i++)	scanf ("%d", &n[i]);
	sort(n + 1, n + 1 + a, cmp);
	for (int i = b; i >= 1; i--){
		sum += n[i];
	}
	printf ("%d\n", sum);
}

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

// {U}{INT,LONG,LLONG}_{MAX,MIN}
#define ALPHABET    (26)
#define INF         INT_MAX
#define MOD         (1000000007LL)
#define EPS         (1e-10)
#define EQ(a, b)    (abs((a)-(b)) < EPS)

using LL  = long long;

int di[] = {0, -1, 0, 1};
int dj[] = {1, 0, -1, 0};
// }}}

LL cnt[2] = {0, 0};
vector<int> f;
vector<vector<int>> g;

bool dfs(int i, int n) {
    if(f[i] != -1){
        if(f[i] != n%2) return false;
        return true;
    }
    f[i] = n%2;
    cnt[n%2]++;
    bool ret = true;
    for(auto e : g[i]){
        ret &= dfs(e, n+1);
    }
    return ret;
}

int main() {
    std::ios::sync_with_stdio(false);

    LL n;cin >> n;
    g.resize(n);
    f.resize(n, -1);
    int m;cin >> m;
    for(int i=0;i<m;i++){
        int a, b;cin >> a >> b;a--;b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }

    cout << (dfs(0, 0) ? cnt[0]*cnt[1] - m : n*(n-1)/2 - m) << endl;

    return 0;
}


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


int main() {
  int n;
  cin >> n;
  int x = 800 * n;
  int y = (n / 15) * 200;
  int ans = x - y;
  
  
  cout << ans << endl;
  return 0;
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mset(a,b) memset(a,b,sizeof a)
#define mcpy(a,b) memcpy(a,b,sizeof b)
#define lb(x) ((x)&(-(x)))
#define inf 0x3f3f3f3f
#define BUF_S 20000000
#define dalao 100003
#define N 200010
using namespace std;
typedef long long ll;
int n,t,a[N];
ll ans;
int main(){
	scanf("%d%d",&n,&t);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]),ans+=min(t,a[i]-a[i-1]);
	printf("%lld",ans+t);
	return 0;
}

Measured memory_bytes: 1024
import sys
sys.setrecursionlimit(10000)

N = int(input())
l=[-1]*(N+1)

def lyuka(x):
  if l[x] != -1:
    return l[x]
  if x == 0:
    return 2
  if x == 1:
    return 1
  lyu = lyuka(x-1) + lyuka(x-2)
  l[x] = lyu
  return lyu

print(lyuka(N))

Measured memory_bytes: 3060
city,road = map(int,input().split())
spot_list = [list(map(int,input().split())) for i in range(road)]
road_list = []

for i in range(road):
    spot = spot_list[i]
    for j in range(2):
        road_list.append(spot[j])

for k in range(1,city+1):
    count = 0
    for l in range(road*2):
        if k == road_list[l]:
            count += 1
    print(count)


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

int main()
{
  int T;
  cin >> T;
  while(T--) {
    int x, y;
    cin >> x >> y;
    const int limit = x * x + y * y;
    int ret = 0;
    for(int i = 0; i * i <= limit; i++) {
      for(int j = 0; j * j <= limit; j++) {
        if(i * i + j * j < 1) continue;
        if((x * j + y * i) % (i * i + j * j) == 0 &&
           (x * i - y * j) % (i * i + j * j) == 0) ++ret;
      }
    }
    if(ret <= 4) cout << "P" << endl;
    else cout << "C" << endl;
  }
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
ll c[30],s[400][30],las[30],t[400];

int main()
{
	int D;
	cin >> D;
	rep(i,26)
	{
		cin >> c[i];
	}
	rep(i,D)
	{
		rep(j,26)
		{
			cin >> s[i][j];
		}
	}
	ll tmp = 0;
	//cout << "a" << endl;
	rep(i,D)
	{
		ll v;
		cin >> v;
		v--;
		t[i] = v;
		tmp += s[i][v];
		las[v] = i+1;
		rep(j,26)
		{
			tmp -= c[j] * (i+1 - las[j]);
		}
	}
	ll M;
	cin >> M;
	rep(i,M)
	{
		ll d,q;
		cin >> d >> q;
		q--;
		t[d-1] = q;
		ll tmp = 0;
		rep(j,30)
		{
			las[j] = 0;
		}
		rep(j,D)
		{
			tmp += s[j][t[j]];
			las[t[j]] = j+1;
			rep(k,26)
			{
				tmp -= c[k] * (j+1 - las[k]);
			}
		}
		cout << tmp << endl;
	}
	return 0;
}

Measured memory_bytes: 3712
/*
String[]の初期化、整数の型がlongになっているか
関数（splitとかcontainsとか）内では"+"とかは正規表現となされるので"\\+"とする
配列のコピーはarr1=arr.clone()
HashSet<>[]はおのおの初期化した？？？？？
負の数の割り算は絶対値が小さいほうに切り捨てられるex.-1/2=0ので、ある値>kみたいな式だとバグらせやすいので注意
ある値>=kとして、切り上げた値をとるべき
toLowerCase()はアルファベット以外に対して行ってもエラーにはならない
ArrayDequeではpopとpushはStackと同じ操作になる
//import static java.lang.System.*; はしばらく使わなそう(使うとしてもexit(0)のためだけ)←return;でよさそう
最後にout.flush()またはout.close()をするのを忘れずに！
Point2D p2d=new Point2D.Double(d1,d2);
//import static java.lang.System.*;
*/
//入力終了→Ctrl+D
import java.util.*;
import java.io.*;
import java.awt.*;
import java.awt.geom.Point2D;
import static java.lang.Math.*;
public class Main {
    public static void main(String[] $) {
        int n=sc.nextInt();
        long z=sc.nextLong();
        long w=sc.nextLong();
        long[] a=new long[n];
        for (int i = 0; i < n; i++) {
            a[i]=sc.nextLong();
        }
        out.println(n==1?abs(a[n-1]-w):max(abs(a[n-1]-w),abs(a[n-1]-a[n-2])));
        out.close();
    }
  
    static PrintWriter out = new PrintWriter(System.out);

    static class sc {
        static Scanner s = new Scanner(System.in);

        static String next() {
            return s.next();
        }

        static String nextLine() {
            return s.nextLine();
        }

        static int nextInt() {
            return Integer.parseInt(s.next());
        }

        static long nextLong() {
            return Long.parseLong(s.next());
        }

        static double nextDouble() {
            return Double.parseDouble(s.next());
        }

        static boolean hasNext() {
            return s.hasNext();
        }
    }
}

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

int a[100000];

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

    map<int, int> a_cnt;
    for (int i=0; i<N; i++) {
        a_cnt[a[i]]++;
    }

    int ans = 0;
    for (auto a: a_cnt) {
        int x = a.first;
        int n = a.second;
        if (n >= x) {
            ans += n - x;
        }
        else {
            ans += n;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 5120