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

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

ans = 0
for e in E:
    del_a, del_b = e
    
    #対象の辺を消す
    G[del_a][del_b] = 0
    G[del_b][del_a] = 0
    
    que = ([0])
    visited = [False]*n
    while que:
        node = que.pop()
        if visited[node] == True:
            continue
        visited[node] = True
        for j in range(n):
            if G[node][j] == 1:
                que.append(j)
    if False in visited:
        ans += 1
    
    #対象の辺を戻す
    G[del_a][del_b] = 1
    G[del_b][del_a] = 1
print(ans)

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

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll N, D; cin >> N >> D;
  vector<ll> x(N);
  vector<ll> y(N);
  ll ans = 0;
  REPLL(i, N){
    cin >> x[i] >> y[i];
    if(x[i]*x[i]+y[i]*y[i] <= D*D) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 6364
//This code was made by Chinese_zjc_.
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<vector>
#include<map>
#include<queue>
#define int long long
#define INF 0x3fffffffffffffff
using namespace std;
int n,ans,a[100001],k;
signed main()
{
	std::ios::sync_with_stdio(false);
	cin>>n>>k;
	for(int i=1;i<=n;++i)
	{
		cin>>a[i];
	}
	sort(a+1,a+1+n);
	for(int i=1;i<=k;++i)
	{
		ans+=a[i];
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3656
//
//  main.c
//  ITTP1_8_D
//
//  Created by k16031kk on 2018/05/26.
//  Copyright © 2018年 AIT. All rights reserved.
//

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

int main(int argc, const char * argv[]) {
    // insert code here...
    char s[100];
    char p[100];
    char w_s[200];
    scanf("%s %s", s, p);
    strcpy(w_s, s);
    //printf("%s\n", w_s);
    strcat(w_s, s);
    //printf("%s\n", s);
    if(strstr(w_s, p)==NULL) printf("No\n");
    else printf("Yes\n");
    
    return 0;
}



Measured memory_bytes: 2104
#include<iostream>
#include<algorithm>
using namespace std;
  
int n,mini;
int A[36],B[36];
char a[36],b[36];
  
string check(){
  for(int i=0;i<n;i++){
    if(a[i]==b[i]&&A[i]==B[i])continue;
    return "Not stable";
  }
  return "Stable";
}
  
int main(){
  cin>>n;
  
  for(int i=0;i<n;i++){
    cin>>a[i]>>A[i];
    b[i]=a[i];
    B[i]=A[i];
  }
  
  for(int i=0;i<n-1;i++){
    for(int j=n-1;j>i;j--){
      if(A[j]<A[j-1]){
    swap(a[j],a[j-1]);
    swap(A[j],A[j-1]);
      }
    }
  }
  
  for(int i=0;i<n-1;i++){
    mini=i;
    for(int j=i+1;j<n;j++){
      if(B[j]<B[mini])mini=j;
    }
    swap(b[i],b[mini]);   
    swap(B[i],B[mini]);
  }
  
  for(int i=0;i<n;i++){
    if(i)cout<<' ';
    cout<<a[i]<<A[i];
  }
  cout<<endl<<"Stable"<<endl;
  for(int i=0;i<n;i++){
    if(i)cout<<' ';
    cout<<b[i]<<B[i];
  }
  cout<<endl<<check()<<endl;
  return 0;
}


Measured memory_bytes: 3204
import java.util.Scanner;

class Main {

    static int gcd(int x,int y){
        while(y!=0){
            int r=x%y;
            x=y;
            y=r;
        }
        return x;
    }

    public static void main(String[] args) {
        Scanner stdIn=new Scanner(System.in);
        
        int x=stdIn.nextInt();
        System.out.println();
        int sum=0;
        for(int i=1; i<=x; i++){
            for(int j=1; j<=x; j++){
                for(int k=1; k<=x; k++){
                    sum+=gcd(gcd(i,j),k);
                }
            }
        }
        System.out.println(sum);
        
        
       
        
    }

}

Measured memory_bytes: 35652
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int N, M, Q; cin >> N >> M >> Q;
  vector<tuple<int, int, int, int>> qer(Q);
  for(int i = 0; i < Q; i++) {
    int a, b, c, d; cin >> a >> b >> c >> d; a--; b--;
    qer.at(i) = make_tuple(d, a, b, c);
  }
  queue<vector<int>> que;
  que.push({1});
  while(true) {
    vector<int> v = que.front();
    if((int)v.size() == N) break;
    que.pop();
    for(int i = v.at(v.size() - 1); i <= M; i++) {
      v.push_back(i);
      que.push(v);
      v.pop_back();
    }
  }
  ll cnt = 0;
  while(!que.empty()) {
    vector<int> A = que.front();
    que.pop();
    ll sum = 0;
    for(int i = 0; i < Q; i++) {
      int a = get<1>(qer.at(i)), b = get<2>(qer.at(i)), c = get<3>(qer.at(i)), d = get<0>(qer.at(i));
      if(A.at(b) - A.at(a) == c) sum += d;
    }
    cnt = max(sum, cnt);
  }
  cout << cnt << endl;
}

Measured memory_bytes: 6696
#include<stdio.h>

int main(){
  int n, count;

  while(1){
    scanf("%d", &n);
    if(n == 0) break;

    count = 0;
    while(n != 1){
      if(n%2 == 0)
	n /= 2;
      else
	n = 3*n + 1;
      count++;      
    }

    printf("%d\n", count);
  }

  return 0;
}

Measured memory_bytes: 0
N, A, B, K = map(int, input().split())

mod = 998244353
fact = [1] * (N + 1)
ifact = [1] * (N + 1)


def init():
    for i in range(N):
        fact[i + 1] = fact[i] * (i + 1) % mod
        ifact[i + 1] = pow(fact[i + 1], mod - 2, mod)


def comb(x, y):
    if y < 0 or y > x:
        return 0
    return (fact[x] * ifact[x - y] * ifact[y]) % mod


ans = 0
init()
for a in range(N + 1):
    n = K - a * A
    if n < 0:
        break
    if n % B == 0:
        ans += (comb(N, a) * (comb(N, n // B))) % mod
print(ans % mod)


Measured memory_bytes: 26720
#include <stdio.h>

int main(void) {
	int r,D,x;
	int result = 0;
	scanf("%d", &r);
	scanf("%d", &D);
	scanf("%d", &x);

	for (int i = 0; i < 10; i++) {
		result = r * x - D;
		printf("%d\n", result);
		x = result;

	}

	return 0;
}

Measured memory_bytes: 128
#include <iostream>
using namespace std;
int main()
{
    int n,k,x,y;
    cin >> n >> k >> x >> y;
    int sum = 0;
    for(int i=1; i<=n;i++)
    {
        if(i <= k)
        {
            sum += x;
        }
        else
        {
            sum += y;
        }
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;

namespace Contest
{
    class Scanner
    {
        private string[] line = new string[0];
        private int index = 0;
        public string Next()
        {
            if (line.Length <= index)
            {
                line = Console.ReadLine().Split(' ');
                index = 0;
            }
            var res = line[index];
            index++;
            return res;
        }
        public int NextInt()
        {
            return int.Parse(Next());
        }
        public long NextLong()
        {
            return long.Parse(Next());
        }
        public string[] Array()
        {
            line = Console.ReadLine().Split(' ');
            index = line.Length;
            return line;
        }
        public int[] IntArray()
        {
            return Array().Select(int.Parse).ToArray();
        }
        public long[] LongArray()
        {
            return Array().Select(long.Parse).ToArray();
        }
    }

    class Program
    {
        private long X, Y;
        private void Scan()
        {
            var sc = new Scanner();
            X = sc.NextLong();
            Y = sc.NextLong();
        }

        public void Solve()
        {
            Scan();
            Console.WriteLine(X % Y == 0 ? -1 : X);
        }

        static void Main(string[] args)
        {
            new Program().Solve();
        }
    }
}

Measured memory_bytes: 13140
#pragma region head
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
#define len(x) ((ll)(x).size())
#define debug(var) cout << "[" << #var << "]\n" << var << endl
#define test(s) \
  if (!(s))     \
    cout << "Line " << __LINE__ << ": [" << #s << "] is false" << endl;
#define int long long
typedef long long ll;
#define double long double
typedef double ld;
const int INF = 1001001001001001001ll;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;
const double EPS = 1e-9;
const double PI = acos(-1.0);

template <typename T>
ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i];
    if (i < len - 1)
      s << ' ';
  }
  return s;
}

template <typename T>
ostream& operator<<(ostream& s, const vector<vector<T>>& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
    s << vv[i];
    if (i != len - 1)
      s << '\n';
  }
  return s;
}

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;
}

__attribute__((constructor)) void initial() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}
#pragma endregion

signed main() {
  int N, K;
  cin >> N >> K;
  vector<int> p(N);
  rep(i, N) {
    cin >> p[i];
  }
  sort(all(p));

  int ans = 0;
  rep(i, K) {
    ans += p[i];
  }
  cout << ans << endl;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  int a[3];
  for(int i=0;i<n;i++){
    for(int j=0;j<3;j++){
      cin>>a[j];
    }
    for(int j=0;j<3;j++){
      for(int k=0;k<3-j-1;k++){
	if(a[k]<a[k+1]){
	  int temp=a[k];
	  a[k]=a[k+1];
	  a[k+1]=temp;
	}
      }
    }
    if(a[0]*a[0]==a[1]*a[1]+a[2]*a[2])
	cout<<"YES"<<endl;
      else
      cout<<"NO"<<endl;
  }
  return(0);
}
      

Measured memory_bytes: 2988
#include <cstdio>
#include <cmath>

struct Point{double x, y;};

void koch(int n, Point p1, Point p2) {
  if (n == 0) return;

  Point s, t, u;
  double rad_60 = M_PI * 60 / 180;
  s.x = (2 * p1.x + 1 * p2.x) / 3;
  s.y = (2 * p1.y + 1 * p2.y) / 3;
  t.x = (1 * p1.x + 2 * p2.x) / 3;
  t.y = (1 * p1.y + 2 * p2.y) / 3;
  u.x = (t.x - s.x) * cos(rad_60) - (t.y - s.y) * sin(rad_60) + s.x;
  u.y = (t.x - s.x) * sin(rad_60) + (t.y - s.y) * cos(rad_60) + s.y;

  koch(n - 1, p1, s);
  printf("%.8f %.8f\n", s.x, s.y);
  koch(n - 1, s, u);
  printf("%.8f %.8f\n", u.x, u.y);
  koch(n - 1, u, t);
  printf("%.8f %.8f\n", t.x, t.y);
  koch(n - 1, t, p2);
}

int main() {
  Point p1, p2;
  int n;

  scanf("%d", &n);
  p1.x = 0;
  p1.y = 0;
  p2.x = 100;
  p2.y = 0;

  printf("%.8f %.8f\n", p1.x, p1.y);
  koch(n, p1, p2);
  printf("%.8f %.8f\n", p2.x, p2.y);

  return 0;
}

Measured memory_bytes: 2732
//{{{
#include <bits/stdc++.h>
using namespace std;
#define rep(...) repN((__VA_ARGS__,rep3,rep2,loop,~))(__VA_ARGS__)
#define loop(n) rep2(_loop_,n)
#define rep2(i,n) rep3(i,0,n)
#define rep3(i,begin,end) for(int i=(int)(begin),i##_end=(int)(end);i<i##_end;++i)
#define repN(a) repX a
#define repX(a0,a1,a2,x,...) x
#define foreach(x,a) for(auto &x:a)
typedef long long ll;
const int MOD = 1e9+7;
//}}}

int main(){
  map<string, int> mp;
  string s;
  int N;
  cin >> N;
  rep(i, N){
    cin >> s;
    mp[s]++;
  }
  int M;
  cin >> M;
  rep(i, M){
    cin >> s;
    mp[s]--;
  }
  int ans = 0;
  for(auto &x: mp){
    int v = x.second;
    ans = max(ans, v);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <complex>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
#include <assert.h>
#include <array>
#include <cstdio>
#include <cstring>
#include <random>
#include <functional>
#include <numeric>
#include <bitset>
#include <fstream>

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { cout << #a << " = " << a << endl; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }

typedef long long ll;
int const inf = 1<<29;

int dp[100001];

int main() {

  int N, M; cin >> N >> M;
  dp[0] = 1;
  REP(i, 1, N) dp[i] = -1;
  rep(i, M) {
    int x, y; cin >> x >> y; x--, y--;
    if(dp[x] > 0) {
      dp[x] --;
      if(dp[y] < 0) dp[y] = -dp[y] + 1;
      else dp[y] ++;
    }
    else {
      assert(dp[x]);
      dp[x]++;  // 白が1つ減る
      if(dp[y] > 0) dp[y] ++;
      else dp[y] --;
    }
  }

  int ans = 0;
  rep(i, N) {
    if(dp[i] > 0) ans ++;
  }

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

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

import re

n = input()
n = re.split(" ",n)
for i in range(3):
    n[i] = int(n[i])
n.sort()
a = int(n[2]) - int(n[0])
b = int(n[2]) - int(n[1])

#a,bともに奇数
if(a % 2 == 1 and b % 2 == 1):
    print(int(a/2)+int(b/2) + 1)
#a,bともに偶数
elif(a % 2 == 0 and b % 2 == 0):
    print(int(a/2) + int(b/2))
#それ以外
else:
    print(int(a/2) + int(b/2) + 2)


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

using namespace std;

int main(){
    string s;
    cin >> s;
    int n = s.length();
    for(int i=0; i<n/2; i++){
        if(s[i] != s[n-i-1]){
            cout << "No\n";
            return 0;
        }
    }

    for(int i=0; i<(n-1)/4; i++){
        if(s[i] != s[n/2-i-1]){
            cout << "No\n";
            return 0;
        }
    }

    for(int i=(n+3)/2-1; i<n; i++){
        if(s[i] != s[n-(i-(n+3)/2 +1) -1]){
            cout << "No\n";
            return 0;
        }
    }

    cout << "Yes\n";

    return 0;
}

Measured memory_bytes: 256
#pragma warning(disable:4996)

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <float.h>

#pragma region 定義
typedef long long  ll;
typedef unsigned long long  ull;


#define _itoa(A,N) sprintf(A, "%d", N);

int i_dsort(const void* a, const void* b);
int i_asort(const void* a, const void* b);

int  _gcd(int a, int b);
int  _swp(int* a, int* b);
int _cknum(char* a, int n);
int _atoi(char* s, int len);

int s_asort(const void* a, const void* b);
int s_dsort(const void* a, const void* b);

//昇順
int s_asort(const void* a, const void* b) {
	return(strcmp((char*)a, (char*)b));
}
int s_dsort(const void* a, const void* b) {
	return(strcmp((char*)b, (char*)a));
}

int i_dsort(const void* a, const void* b) {
	return(*(int*)b - *(int*)a);
}
int i_asort(const void* a, const void* b) {
	return(*(int*)a - *(int*)b);
}


int i_gcd(int a, int b);
int i_gcd(int a, int b) {
	if (!b)return a;
	return i_gcd(b, a % b);
}
int i_lcm(int a, int b);
int i_lcm(int a, int b) {
	return (a * b) / i_gcd(a, b);
}
int ll_gcd(ll a, ll b);
int ll_gcd(ll a, ll b) {
	if (!b)return a;
	return ll_gcd(b, a % b);
}
int ll_lcm(ll a, ll b);
int ll_lcm(ll a, ll b) {
	return (a * b) / ll_gcd(a, b);
}

// puts("Yes\n") puts("No\n")
// scanf("%d.%d") 浮動小数点入力を整数２つで得る


//#define pai  3.1415926535 
//#define  _USE_MATH_DEFINES でM_PIが使える

#define deg_rad(X)  (X*(M_PI/180))


int _swp(int* a, int* b)
{
	int tmp;
	tmp = *b; *b = *a; *a = tmp;
	return 0;
}
#define _abs(x) ((x)>0?(x):-(x))
#define _min(x,y) ((x)<(y)?(x):(y))
#define _max(x,y) ((x)<(y)?(y):(x))

int _cknum(char* a, int n) {
	int i;
	char t = '0';

	for (i = 0; i < n; i++) {
		if (a[i] < '0' || a[i]>'9') return 1;
	}
	return 0;
}


int _atoi(char* s, int len) {
	char tmp[20];
	memcpy(tmp, s, len);
	tmp[len] = 0x00;
	return (atoi(tmp));
}

//素因数分解　pf素数が入る　pc 素数の数
//ll _pfact(ll a);
//static ll pf[100000000];
//static ll pc;
//
//ll _pfact(ll a) {
//	long i, r;
//	if (a % 2 == 0) {
//		pf[pc] = 2; pc++;
//		return(_pfact(a / 2));
//	}
//	r = sqrt(a);
//	for (i = 3; i <= r; i += 2) {
//		if (a % i == 0) {
//			pf[pc] = i; pc++;
//			return(_pfact(a / i));
//		}
//	}
//	if (a != 1) {
//		pf[pc] = a; pc++;
//	}
//	return 0;
//
//}

//同じものの最初の文字をNULLにして降順
int _sort(const void* a, const void* b);
int _sort(const void* a, const void* b) {
	char rc;

	rc = strcmp((char*)b, (char*)a);
	if (rc == 0) {
		*(char*)a = 0x00;
		return(1);
	}
	return(rc);
}
// 立っている ビットの数
int bitcount(unsigned int uc);
int bitcount(unsigned int uc)
{
	int bit;

	for (bit = 0; 0 != uc; uc = (unsigned int)(uc >> 1))
		if (0 != (uc & 1))++bit;

	return bit;
}//bitco

#define _rnd(a,b)    ((a+b-1)/b) //　A/Bの余りを繰り上げる

#pragma endregion

// ABC085 A-  Already 2018
int main(void) {
	char s[11];
	
	
	scanf("%s",s);
//	s[3] = '8';
	printf("%.3s8%s\n",s,&s[4]);

	return 0;
}

Measured memory_bytes: 1732
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define re(i,a,b) for(int i=(a);i<(b);i++)
#define repd(i,a,b) for(int i=(a);i>=(b);i--)
#define clr(a) memset(a,0,sizeof(a));
#define il inline
#define sz(a) ((int)a.size())
#define all(a) a.begin(),a.end()
#define mp make_pair
#define pb push_back 
#define w1 first
#define w2 second
#define adm(a,b,c) {a=a+b;if(a>=c)a-=c;else if(a<0)a+=c;}
typedef double db;
typedef long long ll;typedef long double ld;typedef unsigned long long ull;
typedef pair<ld,ld> pa;
const int N=1e6+5,M=1e7+5,INF=1e9,mod=1e9+7;
const ll linf=1e18;const double eps=1e-8,pi=acos(-1);
il int gmin(int &a,int b){if(a>b)a=b;}il ll gmin(ll &a,ll b){if(a>b)a=b;}il int gmax(int &a,int b){if(a<b)a=b;}il ll gmax(ll &a,ll b){if(a<b)a=b;}
il void read(ll&x){ll f=1,t=0;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){t=t*10+ch-'0';ch=getchar();}x=t*f;}il ll read(ll&x,ll&y){read(x);read(y);}
il void read(int&x){int f=1,t=0;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){t=t*10+ch-'0';ch=getchar();}x=t*f;}il int read(int&x,int&y){read(x);read(y);}
il void read(int&a,int&b,int&c){read(a);read(b);read(c);}il void read(ll&a,ll&b,ll&c){read(a);read(b);read(c);}
il int read(){int x;read(x);return x;}
il ll qpow(ll a,ll b,ll p){ll ret=1;for(;b;b>>=1,a=a*a%p)if(b&1)ret=ret*a%p;return ret;}il ll qpow(ll a,ll b){ll ret=1;for(;b;b>>=1,a=a*a%mod)if(b&1)ret=ret*a%mod;return ret;}
il ll qmul(ll a,ll b,ll p){ll ret=0;for(;b;b>>=1,a=(a<<1)%p)if(b&1)adm(ret,a,p);return ret;}il ll qmul(ll a,ll b){ll ret=0;for(;b;b>>=1,a=(a<<1)%mod)if(b&1)adm(ret,a,mod);return ret;}
il void judge(){
	freopen("data.in","r",stdin);
	freopen("data.out","w",stdout);}
il void gen(){freopen("data.in","w",stdout);}
int L,n;
pa q[N],p[N];
pa merge(pa a,pa b){return pa((a.w1*a.w2+b.w1*b.w2)/(a.w2+b.w2),a.w2+b.w2);}
#define QQ(a) (a.w1*a.w2)
int main(){
	read(n,L);
	int h=5e5,t=h;
	rep(i,1,n){
		ll x,y;read(x,y);p[i]=pa(x,y);
	}	
	q[h]=p[1];
	printf("%.8lf\n",(db)p[1].w1);
	db all=p[1].w2,Q=QQ(p[1]);
	rep(i,2,n){
		all+=p[i].w2;
		while(h<t&&all-q[t].w2>L){
			all-=q[t].w2;
			Q-=QQ(q[t]);
			t--;
		}
		if(all>L){
			Q-=QQ(q[t]);
			q[t].w2-=all-L,all=L;
			Q+=QQ(q[t]);
		}
		
		while(q[h].w1>p[i].w1&&h<=t){
			Q-=QQ(q[h]);
			p[i]=merge(p[i],q[h]);
			h++;
		}
			h--;
			q[h]=p[i];
			Q+=QQ(q[h]);
		printf("%.8lf\n",(db)(Q/all));
	}
}

Measured memory_bytes: 42240
parseInt(x::String) = parse(Int, x)
parseInt(x::SubString{String}) = parse(Int, x)
parseInt(x::Char) = parse(Int, x)
parseInt(x::Float64) = trunc(Int, x)
parseFloat(x::String) = parse(Float64, x)
parseFloat(x::Int) = trunc(Float64, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
    n=parseInt(readline())
    dp=[10^9 for i in 1:100010]
    dp[1],dp[2]=0,1
    for i in 1:n
        now=6
        while i+now<=100010
            dp[i+now]=min(dp[i+now],dp[i]+1)
            now*=6
        end
        now=9
        while i+now<=100010
            dp[i+now]=min(dp[i+now],dp[i]+1)
            now*=9
        end
        dp[i+1]=min(dp[i+1],dp[i]+1)
    end
    println(dp[n+1])
end
main()

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

int main() {
  int n;
  cin >> n;
  string s;
  bool four=false;
  for (int i=0; i < n; i++) {
    cin >> s;
    if (s=="Y")
      four=true;
  }
  if (four)
    cout << "Four";
  else
    cout << "Three";
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll n, k;
  cin >> n >> k;
  vl p(n);
  rep(i, n) cin >> p[i];
  sort(all(p));
  ll ans = 0;
  rep(i, k) ans += p[i];
  cout << ans << endl;
}

Measured memory_bytes: 3600
suits=['S','H','C','D']
cards=[]
for i in range(4):
  for j in range(1,14):
    cards.append([suits[i],j,0])

n=int(input())
for i in  range(n):
  s,r=input().split(' ')
  r=int(r)
  for j in range(len(cards)):
    if cards[j][0]==s and int(cards[j][1])==r:
      cards[j][2]=1

for i in range(len(cards)):
  if cards[i][2]==0:
    print('{} {}'.format(cards[i][0],cards[i][1]))




Measured memory_bytes: 5604
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE BinaryLiterals #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE NumDecimals #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}

import Control.Applicative
import Control.Arrow
import Control.Monad
import Control.Monad.ST

import Data.Char
import Data.List
import Data.Maybe

import qualified Data.ByteString.Char8 as B

import Data.Array.ST.Safe
import Data.STRef

import Debug.Trace
import Text.Printf

readInt = readLn :: IO Int
readInteger = readLn :: IO Integer
readInts = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine
readIntegers = map ( fst . fromJust . B.readInteger ) . B.words <$> B.getLine

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

modifyArray a i f = writeArray a i =<< f <$> readArray a i

main = getLine >>= putStrLn . which "ABC" "ARC" . ( == "ARC" )

Measured memory_bytes: 3736
#include <iostream>
#include <stdio.h>
#include <queue>
#include <vector>
#include <algorithm>
#define fo(i,a,b) for(int i=a;i<b;i++)
using namespace std;

int main(){
    int N, K, nums[110000];
    scanf("%d%d", &N, &K);
    
    for(int i=0;i<N;i++) scanf("%d",&nums[i]);
    
    int ans = 1e9, cost;
    
    for(int r=0;r<N-K+1;r++) {
        int l = r+K-1;
        if ((nums[r]>=0)^(nums[l]>=0)) cost = -nums[r] + nums[l] + min( -nums[r], nums[l] );
        else cost = max( abs(nums[r]), abs(nums[l]) );
        ans = min( ans, cost );
    }
    printf("%d\n", ans);
    return 0;
}


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

vector<vector<int>> connect(200005);
vector<int> val;

void dfs(int i,int k=-1){
    for(auto p:connect[i]){
        if(p==k) continue;
        val[p]+=val[i];
        dfs(p,i);
    }
}

int main(){
    int n,q;
    cin>>n>>q;
    for(int i=0;i<n-1;i++){
        int a,b;cin>>a>>b;
        --a;--b;
        connect[a].push_back(b);connect[b].push_back(a);
    }
    val.resize(n);
    for(int i=0;i<q;i++){
        int a,b;cin>>a>>b;
        --a;
        val[a]+=b;
    }
    dfs(0);
    rep(i,n)cout<<val[i]<<endl;
    return 0;
}

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

int main(){
        int n;
        string s;

        cin >> n >> s;
        int arr[s.length()];

        int ans =0;
        for(int i = 0; i< 1000; i++)
        {
                int f=0;
                int c[3] = {i/100,(i / 10) % 10, i % 10};
                for(int j = 0; j< n;j++)
                {
                        if(s[j] == '0' + c[f])
                                f++;
                        if(f==3)
                                break;
                }
                if(f==3)
                {
                        ans++;
                }
        }
        cout << ans << endl;
}



Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.ComponentModel.Design;
using System.Globalization;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using System.Xml.Schema;
using static System.Console;

namespace ConsoleApp2
{
    class Program
    {
        static public int[] Sarray() { return ReadLine().Split().Select(int.Parse).ToArray(); }
        static public List<int> Slist() { return new List<int>(ReadLine().Split().Select(int.Parse)); }
        static void Main(string[] args)
        {
            var HWK = Sarray();
            var H = HWK[0];
            var W = HWK[1];
            var K = HWK[2];
            var chw = new char[H][];
            for(var i=0;i<H;i++)
            {
                chw[i] = ReadLine().ToCharArray();
            }
            var ans = 0;
            for(var maskR=0;maskR<(1<<H);maskR++)
            {
                for (var maskC = 0; maskC < (1 << W) ; maskC++)
                {
                    var black = 0;
                    for(var i=0;i<H;i++)
                    {
                        for (var j = 0; j < W; j++)
                        {
                            if((((maskR>>i)&1)==0) && (((maskC >> j) & 1) == 0) && chw[i][j]=='#')
                            {
                                black++;
                            }
                        }
                    }
                    if (black == K) ans++;
                }
            }
            WriteLine(ans++);
        }
    }
}

Measured memory_bytes: 18992
#pragma optimization_level 3
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#include<bits/stdc++.h>
#define F first
#define S second
#define vec vector
#define ms multiset
#define pb push_back
#define pll pair<ll,ll>
#define pdd pair<ld, ld>
#define pq priority_queue
#define umap unordered_map
#define uset unordered_set
#define pii pair<int, int>
#define pnn pair<Node*, Node*>
#define uid uniform_int_distribution
#define FILE ifstream in("input.txt");ofstream out("output.txt");
#define fast cin.tie(0);cout.tie(0);cin.sync_with_stdio(0);cout.sync_with_stdio(0);
using namespace std;
typedef string str;
typedef long long ll;
typedef long double ld;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); //uid<int> u1(5, 10); u1(rnd);

int main(){
    fast;
    ll a,k; str t; cin>>a>>k>>t;
    deque<ll> m;
    int c = 1;
    for(int q=1; q<a; q++){
        if(t[q]==t[q-1]) c++;
        else{
            m.pb(c);
            c = 1;
        }
    }
    m.pb(c);
    for(; k && m.size()>1; k--){
        if(m.size()==2){
            m = {m[0]+m[1]};
            break;
        }
        ll s = m[0]+m[1]+m[2];
        m.pop_front();
        m.pop_front();
        m.pop_front();
        m.push_front(s);
    }
    cout<<a-m.size();
}

Measured memory_bytes: 1232
#include <iostream>
#include <map>
#include <algorithm>
#include <string>
#include <vector> 
#include <numeric>
#include <cmath>
#include <queue>


#define CHMAX(a,b) a = std::max(a,b)
#define CHMIN(a,b) a = std::min(a,b)
#define CHABS(a) a = std::abs(a) 
#define COUT(a) std::cout << a << std::endl
#define CERR(a) std::cerr << a << std::endl
#define FOR(n) for(lli i = 0; i < n; i++)

using namespace std;
using lli = long long int;
using pll = pair<lli, lli>;
using tlll = tuple<lli, lli, lli>;

lli mod197 = 1000000007LL;

// ax + by = gcd(a,b) 最大公約数
template< typename T >
T extgcd(T a, T b, T& x, T& y) {
	T d = a;
	if (b != 0) {
		d = extgcd(b, a % b, y, x);
		y -= (a / b) * x;
	}
	else {
		x = 1;
		y = 0;
	}
	return d;
}

int N, M, P;

int A[5000] = {}, B[5000] = {};
lli C[5000] = {};

template< typename T >
struct edge {
	int src, to;
	T cost;

	edge() {

	}

	edge(int to, T cost) : src(-1), to(to), cost(cost) {}

	edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}

	edge& operator=(const int& x) {
		to = x;
		return *this;
	}

	operator int() const { return to; }
};

template< typename T >
using Edges = vector< edge< T > >;
template< typename T >
using WeightedGraph = vector< Edges< T > >;
using UnWeightedGraph = vector< vector< int > >;
template< typename T >
using Matrix = vector< vector< T > >;

template< typename T >
vector< T > bellman_ford(Edges< T >& edges, int V, int s) {
	const auto INF = numeric_limits< T >::max();
	vector< T > dist(V, INF);
	dist[s] = 0;
	for (int i = 0; i < V - 1; i++) {
		for (auto& e : edges) {
			if (dist[e.src] == INF) continue;
			dist[e.to] = min(dist[e.to], dist[e.src] + e.cost);
		}
	}
	for (auto& e : edges) {
		if (dist[e.src] == INF) continue;
		if (dist[e.src] + e.cost < dist[e.to]) return vector< T >();
	}
	return dist;
}

bool visited[2500] = {};


int main(void) {

	cin >> N >> M >> P;

	WeightedGraph<lli> check(N);
	Edges<lli> bell;

	for (lli i = 0; i < M; i++) {
		cin >> A[i] >> B[i] >> C[i];
		A[i]--;
		B[i]--;
		check[B[i]].push_back(edge<lli>( B[i], A[i], 1LL ));
	}


	queue<lli> q;

	q.push(N - 1);

	while (!q.empty()) {

		lli i = q.front();
		q.pop();

		if (!visited[i]) {
			visited[i] = true;
			for (lli j = 0; j < check[i].size(); j++) {
				q.push(check[i][j].to);
			}
		}

	}

	for (lli i = 0; i < M; i++) {
		if (visited[A[i]] == true && visited[B[i]] == true)
			bell.push_back(edge<lli>( A[i],B[i], -1 * C[i] + P ));
	}

	vector<lli> result = bellman_ford<lli>(bell, N, 0);

	if (result.size() == 0) {
		COUT(-1);
	}
	else {
		COUT(max(0LL,-1 * result[N - 1]));
	}


	return 0;
}

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

vector<ll> a(1000100);
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll n, p, ans = 1;
    cin >> n >> p;
    ll q = p;

    ll s = 2;

    while (p > 1 && s < 1000000)
    {
        if (p % s == 0)
        {
            a[s]++;
            p /= s;
        }
        else
            s++;
    }

    rep(i, 1000002)
    {
        if (n <= a[i])
            rep(j,(a[i]/n))ans *= i;
    }

    if(p!=1&&n==1)
        ans = q;

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 8064
N = int(input())
A = list(map(int, input().split()))
B = [abs(i) for i in A]
k = 0
for i in range(N):
    if A[i] < 0:
        k += 1
if k % 2 == 0:
    print(sum(B))
else:
    print(sum(B) - min(B) * 2)

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

int main() {
  int N;
  cin >> N;
  
  int maxLen = 1;
  int st = 0;
  int prevVal;
  int nextVal;
  cin >> prevVal;
  for (int i = 1; i < N; i++) {
    cin >> nextVal;
    if (nextVal > prevVal) {
      if (maxLen < i - st) {
        maxLen = i - st;
      }
      st = i;
    }
    prevVal = nextVal;
  }
  
  if (maxLen < N - st) {
    maxLen = N - st;
  }
  
  cout << maxLen - 1;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define md 1000000007
#define ll long long 
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define fastmap mp.reserve(1024);mp.max_load_factor(0.25);
#define fastset st.reserve(1024);st.max_load_factor(0.25);
ll int mpw(ll int a,ll int b,ll int m)
{
	ll int ans=1;
	if(a==0)return 0;
	if(a==1 || b==0)return 1;
	while(b)
	{
		if(b&1)
		{
			ans=(ans*a)%m;
		}
		a=(a*a)%m;
		b>>=1;
	}
	return ans;
}
 
ll int pw(ll int a,ll int b)
{
	ll int ans=1;
	if(a==0)return 0;
	if(a==1 || b==0)return 1;
	while(b)
	{
		if(b&1)
		{
			ans*=a;
		}
		a*=a;
		b>>=1;
	}
	return ans;
}
 
ll int mn(ll int a,ll int b)
{
	if(a<=b)
	{
		return a;
	}
	return b;
}
 
ll int mx(ll int a,ll int b)
{
	if(a>=b)
	{
		return a;
	}
	return b;
}
 
int main()
{
	fio
	int n,m;
	cin>>n>>m;
	vector<vector<char>>grid(n,vector<char>(m));
	vector<vector<ll int>>D(n,vector<ll int>(m,0));
	for(int i=0;i<n;++i)
	{
		string s;
		cin>>s;
		for(int j=0;j<m;++j)
		{
			grid[i][j]=s[j];
		}
	}
	if(grid[0][0]!='#')D[0][0]=1;
	for(int i=1;i<m;++i)
	{
		if(grid[0][i]!='#')
		{
			D[0][i]=D[0][i-1];
		}
	}
	for(int i=1;i<n;++i)
	{
		if(grid[i][0]!='#')
		{
			D[i][0]=D[i-1][0];
		}
	}
	for(int i=1;i<n;++i)
	{
		for(int j=1;j<m;++j)
		{
			if(grid[i][j]!='#')
			{
				D[i][j]=(D[i][j-1]+D[i-1][j])%md;
			}
		}
	}
	cout<<D[n-1][m-1]<<"\n";
	return 0;
}

Measured memory_bytes: 12464
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define vout(x) rep(i,x.size()) cout << x[i] << " "
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;

int main() {
    int a, v; cin >> a >> v;
    int b, w; cin >> b >> w;
    int t; cin >> t;
    int x = abs(a-b);
    int y = v-w;
    if (w >= v) cout << "NO" << endl;
    else if ((x+y-1)/y <= t) cout << "YES" << endl;
    else cout << "NO" << endl;
}

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

long long h, w, n;
long long q[10];
int mat[6][6];
int sum[6][6];

set <pair <int, int> > s;

void calc (int x, int y) {
	memset (mat, 0, sizeof mat);

	for (int i = 1; i <= 5; ++i)
		for (int j = 1; j <= 5; ++j) {
			mat[i][j] = s.count (make_pair (x + i - 3, y + j - 3));
			sum[i][j] = sum[i][j - 1] + sum[i - 1][j] - sum[i - 1][j - 1] + mat[i][j];
		}

	for (int i = 1; i <= 3; ++i) {
		for (int j = 1; j <= 3; ++j) {
			int xc = x + i - 3, yc = y + j - 3;
			if (xc < 1 || xc > h - 2 || yc < 1 || yc > w - 2) continue;

			int temp = sum[i + 2][j + 2] - sum[i - 1][j + 2] - sum[i + 2][j - 1] + sum[i - 1][j - 1];
			q[temp]--;
			q[temp + 1]++;
		}
	}
}

int main () {

	cin >> h >> w >> n;

	q[0] = (h - 2LL) * (w - 2LL);

	for (int i = 0; i < n; ++i) {
		int x, y;
		scanf ("%d %d", &x, &y);
		calc (x, y);
		s.insert (make_pair (x, y));
	}

	for (int i = 0; i <= 9; ++i)
		printf ("%lld\n", q[i]);


	return 0;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
using longlong=long long;

int main(){
    std::cin.tie(nullptr);std::cin.sync_with_stdio(false);
    int n;std::cin>>n;
    int ans=0;
    for(int i=0;i<n;i++){
        int x;std::cin>>x;
        for(;x%2==0;x/=2)ans++;
    }
    std::cout<<ans<<std::endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
    int h, w, k;
    cin >> h >> w >> k;
    vector<vector<char>> c(h, vector<char>(w));
    vector<vector<char>> d(h, vector<char>(w));
    for (int i = 0; i < h; i++)
        for (int j = 0; j < w; j++)
            cin >> c[i][j];
    
    
    int ans = 0;
    for (int bh = 0; bh < (1 << h); bh++) {
        for (int bw = 0; bw < (1 << w); bw++) {
            d = c;
            for (int i = 0; i < h; i++) {
                for (int j = 0; j < w; j++) {
                    if (((1 << i) & bh) || ((1 << j) & bw))
                        d[i][j] = 'x';
                }
            }
            int count = 0;
            for (int i = 0; i < h; i++)
                for (int j = 0; j < w; j++)
                    if (d[i][j] == '#')
                        count++;
            if (count == k)
                ans++;
        }
    }
    
    cout << ans << endl;
    
    return 0;
}


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

#define EPS (1e-10)
#define rep(i, a, b) for (int i = a; i < (int)(b); ++i)
#define rrep(i, a, b) for (int i = b - 1; i >= (int)(a); --i)

using namespace std;
using ll = long long;
using vi = vector<int>;
using vb = vector<bool>;
using vll = vector<ll>;
using vd = vector<double>;
using vvi = vector<vi>;
using vvb = vector<vb>;

constexpr int MOD = 1000000007;

inline int mod(ll n, int k) {
    n %= k;
    if (n < 0) { n += k; }
    return (int)n;
}

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

    ll n, k;
    cin >> n >> k;

    // 1-indexed.
    vi a(n + 1, 0), sum(n + 1, 0);
    rep(i, 1, n + 1) {
        cin >> a[i];
        a[i] %= k;
        sum[i] = (a[i] + sum[i - 1]) % k;
    }

    if (k == 1) {
        cout << 0 << endl;
        return 0;
    }

    map<int, int> cnt;
    queue<int> mem;

    ll ans = 0;

    rep(i, 0, n + 1) {
        int tmp = mod(sum[i] - i, k);

        ans += cnt[tmp];
        ++cnt[tmp];
        mem.push(tmp);

        if (n >= k) {
            if ((int)mem.size() == k) {
                --cnt[mem.front()];
                mem.pop();
            }
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 12032
#include <iostream>
using namespace std;
int main( void )
{
	char a, tmp, b, now;
	now = 'A';
	while ( cin >> a >> tmp >> b )
	{
		if ( a == now )
		{
			now = b;
		}
		else if ( b == now )
		{
			now = a;
		}
	}
	cout << now << endl;
	return 0;
}

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

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//#pragma GCC optimize("Ofast")
//1.0 * clock() / CLOCKS_PER_SEC

#define fi first
#define se second
#define ll long long
#define dl double long

using namespace std;

const int NN = 1e3 + 7;
const int N = 2e5 + 7;
const int M = 22;
const ll mod = 1e9 + 7;
const ll inf = 1e18 + 7;
const dl rf = 1e-14;
const int B = sqrt(N);



void solve1()
{
    int n;
    cin >> n;
    set < string > s;
    while( n-- ){
        string t;
        cin >> t;
        s.insert(t);
    }
    cout << (int)s.size();
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    //freopen( "input.txt" , "r" , stdin );
    //freopen( "output.txt" , "w" , stdout );

    int cghf = 1;//cin >> cghf;
    while( cghf-- ){
        solve1();
    }
}


Measured memory_bytes: 19220
#include<bits/stdc++.h>
using namespace std;
#ifndef ONLINE_JUDGE
#define dbg(x...) do { cout << "\033[32;1m " << #x << " -> "; err(x); } while (0)
void err() { cout << "\033[39;0m" << endl; }
template<template<typename...> class T, typename t, typename... A>
void err(T<t> a, A... x) { for (auto v: a) cout << v << ' '; err(x...); }
template<typename T, typename... A>
void err(T a, A... x) { cout << a << ' '; err(x...); }
#else
#define dbg(...)
#endif
typedef long long ll;
typedef pair<int,int> pi;
typedef vector<int> vi;
template<class T> using vc=vector<T>;
template<class T> using vvc=vc<vc<T>>;
template<class T> void mkuni(vector<T>&v)
{
    sort(v.begin(),v.end());
    v.erase(unique(v.begin(),v.end()),v.end());
}
template<class T>
void print(T x,int suc=1)
{
    cout<<x;
    if(suc==1) cout<<'\n';
    else cout<<' ';
}
template<class T>
void print(const vector<T>&v,int suc=1)
{
    for(int i=0;i<v.size();i++)
    print(v[i],i==(int)(v.size())-1?suc:2);
}
struct D{
    int cc,id;
    bool operator<(const D&a) const{
        if(cc==a.cc) return id<a.id;
        return cc>a.cc;
    }
};
int main()
{
    int n;
    cin>>n;
    vi a(n+1);
    vi cnt(n+1);
    for(int i=1;i<=n;i++) cin>>a[i];
    vi ans(n);
    if(n<=2)
        cout<<"-1\n";
    else{
        set<D> all;
        set<int> alln;
        for(int i=1;i<=n;i++)
            cnt[a[i]]++,alln.insert(i);
        for(int i=1;i<=n;i++)
            all.insert({cnt[i],i});
        int pre=0;
        for(int i=1;i<=n-3;i++)
        {
            if((*all.begin()).cc==n-i)
                ans[i-1]=(*all.begin()).id;
            else {
                for(auto u:alln){
                    if(u!=a[pre])
                    {
                        ans[i-1]=u;
                        break;
                    }
                }
            }
            all.erase({cnt[ans[i-1]],ans[i-1]});
            alln.erase(ans[i-1]);
            int tar=a[ans[i-1]];
            if(alln.count(tar))
            {
                all.erase({cnt[tar],tar});
                cnt[tar]--;
                all.insert({cnt[tar],tar});
            }
            pre=ans[i-1];
            //dbg(i);
            //for(auto u:all) dbg(u.cc,u.id);
        }
        vi remain;
        for(auto u:alln) remain.push_back(u);
        do
        {
            bool ok=1;
            int cc=pre;
            for(int i=0;i<3;i++)
            {
                if(a[cc]==remain[i])
                {
                    ok=0;
                    break;
                }
                cc=remain[i];
            }
            if(ok) break;
        } while (next_permutation(remain.begin(),remain.end()));
        for(int i=0;i<3;i++) ans[n-3+i]=remain[i];
        print(ans);
    }
}

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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)
#define mp make_pair

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int64 n;
    cin >> n;
    int64 ans = LLINF;
    for(int64 i = 1; i * i <= n; ++i){
        if(n % i == 0){
            ans = min(ans, n / i + i - 2);
        }
    }
    ANS(ans);
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
using namespace __gnu_pbds;
using namespace std;
#define int long long
#define ld long double
#define pb push_back
#define ff first
#define ss second
#define f(i,x,n) for(int i=x;i<(int)n;++i)
#define vpii vector<pair<int,int>>
#define vi vector<int>
#define mpii map<pair<int,int>,int>
#define mpivpii map<int,vector<pair<int,int>>>
#define pii pair<int,int>
#define all(x) x.begin(),x.end()
#define sz(x) x.size()
#define mpi map<int,int>
#define vvi vector<vector<int>>
#define vvvi vector<vvi>
ld pie=3.141592653589;
int mod=1e9+7;

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




void solve(){
	int a[2],b[2]; cin>>a[0]>>a[1]>>b[0]>>b[1];
	int ans=LLONG_MIN;
	f(i,0,2){
		f(j,0,2)
		ans=max(ans,a[i]*b[j]);
	}
	cout<<ans;
}


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


Measured memory_bytes: 3636
IDENTIFICATION DIVISION.
PROGRAM-ID. PROGRAM_ID.

DATA DIVISION.
WORKING-STORAGE SECTION.
01 ln         PIC X(30).
01 N          PIC 9(10).
01 D          PIC 9(10).
01 ans        PIC 9(10).
01 zs         PIC Z(9)9.

PROCEDURE DIVISION.
  ACCEPT ln.
  UNSTRING ln DELIMITED BY SPACE INTO N D.
  COMPUTE ans = (N + 2 * D) / (2 * D + 1)
  MOVE ans TO zs.
  DISPLAY FUNCTION TRIM(zs).
  STOP RUN.


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

using namespace std;

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

const long long MOD = 1e9 + 7;
const int INF = 1e9;
const double EPS = 1e-9;

int main() {
  int N;
  cin >> N;
  vector<int> v(N);
  for (int i = 0; i < N; ++i) cin >> v[i];
  sort(v.begin(), v.end());
  double ans = v[0];
  for (int i = 0; i < N - 1; ++i) {
    ans = (ans + v[i + 1]) / 2.0;
  }
  cout << ans << endl;
}

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

long long n,a[2009],dp[2009][2009],id[2009],ans;
bool cmp(long long b1,long long b2){return a[b1]>a[b2];}

int main()
{
	cin >> n;
	for(long long i = 1;i<=n;i++)cin >> a[i],id[i] = i;
	sort(id+1,id+n+1,cmp);
	for(long long i = 1;i<=n;i++)
	{
		dp[i][0] = dp[i-1][0]+a[id[i]]*(n-i+1-id[i]);//cout << "dp[" << i<<"]["<<0<<"]="<<dp[i][0]<<endl;//
		for(long long j = 1;j<i;j++)
		{
			dp[i][j] = max(dp[i-1][j]+a[id[i]]*abs(n-(i-1-j)-id[i]),dp[i-1][j-1]+a[id[i]]*abs(id[i]-j));
			//cout << "dp[" << i<<"]["<<j<<"]="<<dp[i][j]<<endl;//
		}
		dp[i][i] = dp[i-1][i-1]+a[id[i]]*abs(id[i]-i);
	}
	for(int i = 0;i<=n;i++)if(ans<dp[n][i])ans = dp[n][i];
	cout << ans;
	return 0;
}

Measured memory_bytes: 26320
/*
3
1 3 5 2
2 8 1

*/
#include<algorithm>
#include<iostream>
#include<string.h>
#include<stdio.h>
using namespace std;

int main()
{
	long long n;
	scanf("%lld",&n);
	long long a[n+1];
	long long b;
	
	for(long long i=0; i<=n; i++)
		scanf("%lld",&a[i]);
	
	long long cnt=0;
	long long t=0;
	for(long long i=0; i<n; i++)
	{
		scanf("%lld",&b);
		
		if(a[i]<=b)
		{
			cnt+=a[i];
			b-=a[i];
			if(a[i+1]<=b)
			{
				cnt+=a[i+1];
				a[i+1]=0;
			}
			else
			{
				cnt+=b;
				a[i+1]-=b;
			}
		}
		else
		{
			cnt+=b;
			t=0;
		}
		
//		cout<<cnt<<endl;
	}
	
	printf("%lld",cnt);
	
	return 0;
}

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

def solve():
    A, B, C = list(map(int, input().split()))

    # A(x1+x2+x3+...+xn)%B == C
    # (x1+x2+x3+...+xn) = Xとおくと
    # A*X%B == C
    # A*X ≡ C (mod B)
    # A*X-C ≡ 0 (mod B)

    for x in range(1, B+1):
        if (A*x-C)%B == 0:
            print("YES")
            return
    print("NO")

if __name__ == "__main__":
    solve()


Measured memory_bytes: 2940
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

struct node{
  unsigned int key;
  struct node *next;
  struct node *prev;
};

typedef struct node * NodePointer;

NodePointer nil;

NodePointer listSearch(int key){
  NodePointer cur = nil->next;
  while( cur != nil && cur->key != key ){
    cur = cur->next;
  }
  return cur;
}

void init(){
  nil = malloc(sizeof(struct node));
  nil->next = nil;
  nil->prev = nil;
}

void printList(){
  NodePointer cur = nil->next;
  int isf = 1;
  while(1){
    if ( cur == nil ) break;
    if ( isf == 0)  printf(" ");
    printf("%d", cur->key);
    cur = cur->next;
    isf = 0;
  }
  printf("\n");
}

void deleteNode(NodePointer t){
  t->prev->next = t->next;
  t->next->prev = t->prev;
  //  free(t);
}

void deleteFirst(){
  NodePointer t = nil->next;
  if ( t == nil ) return;
  deleteNode(t);
}

void deleteLast(){
  NodePointer t = nil->prev;
  if ( t == nil ) return;
  deleteNode(t);
}

void delete(int key){
  NodePointer t = listSearch(key);
  if ( t == nil ) return;
  deleteNode(t);
}


void insert(int key){
  NodePointer x;
  x = malloc(sizeof(struct node));
  x->key = key;
  x->next = nil->next;
  nil->next->prev = x;
  nil->next = x;
  x->prev = nil;
}

int main(){
  int key, n, i;
  int size = 0;
  char com[20];
  int np = 0, nd = 0,a=0;
  a=kansu(a);
  if(a == 0){
  scanf("%d", &n);
  init();
  for ( i = 0; i < n; i++ ){
    scanf("%s%d", com, &key);
    if(!( 0 <= key && key <= 2000000000)){printf("error") ;}
    if ( com[0] == 'i' ) {insert(key); np++; size++;}
    else if ( com[0] == 'd' ) {
      if (strlen(com) > 6){
	if ( com[6] == 'F' ) deleteFirst();
	else if ( com[6] == 'L' ) deleteLast();
      } else {
	delete(key); nd++; 
      }
      size--;
    }
    if ( size > 1000000 ) { printf("error"); }
  }

  
  if(!( np+nd <= 2000000)){printf("error") ;}
  if(!( nd <= 20)){printf("error") ;}
  printList();


  return 0;
}
}
void kansu(int a){
 int b=0,c=1;
 if(b == 0);
  if(c == 1);
   return a;
}


Measured memory_bytes: 36108
#include <iostream>
#include <set>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <string>
#include <stack>
#include <cmath>
#include <cstring>
#include <climits>
using namespace std;

#define FORN(i, j, k) for(int i=j;i<k;i++)
#define FORR(i, j, k) for(int i=j;i>=k;i--)
#define REP(i, n) FORN(i, 0, n)
#define int long long
#define pii pair<int, int>
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define endl '\n'

const int MODO = 1e+9 + 7;
const int MAX = 1e+5;
int n;
int a[MAX];

void solve(){
	int dp[n+2];
	REP(i, n){
		dp[i] = INT_MAX;
	}
	dp[0] = 0;
	REP(i, n){
		FORN(j, i+1, i+3){
			dp[j] = min(dp[j], dp[i]+abs(a[i]-a[j]));
		}
	}
	cout << dp[n-1] << endl;
	return;
}

int32_t main(){
		ios_base::sync_with_stdio(false);
		cin.tie(NULL);
		cin >> n;
		REP(i, n){
			cin >> a[i];
		}
		solve();
		return 0;
}



Measured memory_bytes: 5180