akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
#define MAX_V 200000
#define INF 1e+9
struct edge
{
  int to;
  int cost;
};
int n;
using P = pair<int, int>;
vector<edge> G[MAX_V];
int d[MAX_V];
void dijkstra(int s)
{
  priority_queue<P, vector<P>, greater<P>> que;
  fill(d, d + n, INF);
  d[s] = 0;
  que.push(P(0, s));

  while (!que.empty())
  {
    P p = que.top();
    que.pop();
    int v = p.second;
    if (d[v] < p.first)
      continue;

    for (int i = 0; i < G[v].size(); ++i)
    {
      edge e = G[v][i];
      if (d[e.to] > d[v] + e.cost)
      {
        d[e.to] = d[v] + e.cost;
        que.push(P(d[e.to], e.to));
      }
    }
  }
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int m;
  cin >> n >> m;
  REP(i,m){
    int a,b;
    cin >> a >> b;
    a--, b--;
    edge e = {b, 1};
    G[a].push_back(e);
  }
  dijkstra(0);
  if(d[n-1]==2) puts("POSSIBLE");
  else puts("IMPOSSIBLE");
  return 0;
}


Measured memory_bytes: 11124
using System;

public class Problem_B
{
  public static void Main()
  {
    var N = int.Parse(Console.ReadLine());
    var K = int.Parse(Console.ReadLine());
    var x = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
    var total = 0;
    for (var i = 0; i < N; i++)
    {
      total += Math.Min(2 * x[i], 2 * (K - x[i]));
    }
    Console.WriteLine($"{total}");
  }
}


Measured memory_bytes: 13268
#include <bits/stdc++.h>
//#pragma GCC diagnostic error "-Wconversion"
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(vec) vec.begin(), vec.end()
#define mp(a, b) make_pair(a, b)
typedef long long ll;
const ll INF = 1LL << 60;
const ll MOD = (1e9 + 7);
using namespace std;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
ll dp[100010];
ll gcd(ll x, ll y){
  return y == 0 ? x : gcd(y, x % y);
}
ll lcg(ll x, ll y){
  return x * y / gcd(x, y);
}
ll digits(ll x){
  ll length = 0;
  while (x > 0){
    x /= 10;
    length++;
  }
  return length;
  if (x == 0) return 0;
}
map<ll, ll> factor(ll n){
  map<ll, ll> ans;
  ll a = 2;
  while (n >= a * a){
    if (n % a == 0){
      ans[a]++;
      n /= a;
    }
    else a++;
  }
  ans[n]++;
  return ans;
}
template<class T> inline bool chmin(T& a, T b){
  if (a > b){
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b){
  if (a < b){
    a = b;
    return true;
  }
  return false;
}

int main(){
  cout << fixed << setprecision(15);
  int ans = 0;
  //string ans = "No";

  int n, y; cin >> n >> y;

  rep(i, n + 1){
    rep(j, n - i + 1){
      if (i * 10000 + j * 5000 + (n - i - j) * 1000 == y){
        cout << i << " " << j << " " << (n - i - j) << endl;
        return 0;
      }
    }
  }
  cout << "-1 -1 -1" << endl;

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

Measured memory_bytes: 3640
/**
 *   created: 28 April 2019  23:46:46
**/
#include<bits/stdc++.h>
using namespace std;

typedef vector<int> vi;
typedef pair<int , int> pii;
typedef vector< pair<int , int> > vii;
typedef long long ll;
typedef vector<long long> vl;
typedef pair<long long , long long> pll;
typedef vector< pair<long long , long long> > vll;

#define PB push_back
#define PPB pop_back
#define all(c) (c).begin,(c).end()
#define rep(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
// #define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define INFLL 2000000000000000007
#define INF 2000000007
#define MOD 1000000007


#define TRACE

#ifdef TRACE
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;

#else

#define trace1(x)
#define trace2(x, y)
#define trace3(x, y, z)
#define trace4(a, b, c, d)
#define trace5(a, b, c, d, e)
#define trace6(a, b, c, d, e, f)

#endif


void optimizeIO()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
}

//                                        //AUTHOR: Kaushalesh Shukla

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

int main()
{
	// optimizeIO();
	int tc=1;
	// cin>>tc;
	for(int tt=0;tt<tc;tt++){
		ll n;
		cin>>n;
		// cout<<n<<endl;
		vl v(5);
		rep(i,0,5){
			// cout<<"cin "<<v[i]<<endl;
			cin>>v[i];
		}
		ll mini = INFLL;
		rep(i,0,5)
			mini = min(mini, v[i]);
		ll res = n/mini;
		res+=4;
		if(n%mini!=0)
			res += 1;
		cout<<res;
	}
	return 0;
}




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

int main(){
    int n,b[110];
    int a[3][3];
    bool isExist[3][3];
    rep(i,3){
        rep(j,3) cin >> a[i][j];
    }
    cin >> n;
    rep(i,n) cin >> b[i];

    rep(i,3){
        rep(j,3) {
            isExist[i][j] = false;
            rep(k,n){
                if(a[i][j] == b[k]){
                    isExist[i][j] = true;
                    break;
                }
            }
        }
    }

    rep(i,3){
        if(isExist[i][0]&&isExist[i][1]&&isExist[i][2]){
            cout << "Yes" << endl;
            return 0;
        }

        if(isExist[0][i]&&isExist[1][i]&&isExist[2][i]){
            cout << "Yes" << endl;
            return 0;
        }
    }

    if(isExist[0][0]&&isExist[1][1]&&isExist[2][2]){
        cout << "Yes" << endl;
        return 0;
    }

    if(isExist[0][2]&&isExist[1][1]&&isExist[2][0]){
        cout << "Yes" << endl;
        return 0;
    }

    cout << "No" << endl;

}

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

const long long MOD = 1e9 + 7;
long long A[300100];

int main() {
  int N;
  scanf("%d", &N);

  for (int i = 0; i < N; i++) {
    scanf("%lld", &A[i]);
  }

  // 各ビットの1の個数を数え上げる
  long long ones[60] = {0LL};
  for (int i = 0; i < N; i++) {
    for (int bit = 0; bit < 60; bit++) {
      ones[bit] += (A[i] >> bit) & 1;
    }
  }

  long long ans = 0LL;
  for (int i = 0; i < 60; i++) {
    ans += ((ones[i] * (N - ones[i])) % MOD)  * ((1LL << i) % MOD);
    ans %= MOD;
  }

  printf("%lld", ans);
  return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <string>
#include <algorithm>
#define REP(i,n) for(int i=0;i<(n);++i)
using namespace std;
typedef long long LL;

int main() {
  string S;
  cin >> S;
  bool ret = S[2] == S[3] && S[4] == S[5];
  cout << (ret ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<vector>
#include<ctype.h>
#include<string>
#include<cmath>
#include<string.h>
#include<sstream>
#include<limits.h>
using namespace std;

long N;
long long answer=1;
long long limit=1;
vector<long long> A;

int main(){
    cin>>N;
    for(int i=0;i<18;++i){
        limit*=10;
    }
    A.resize(N);
    
    for(int i=0;i<N;++i){
        cin>>A[i];
    }
    bool flag=0;
    for(int i=0;i<N;++i){
        if(A[i]==0){
            answer=0;
            flag=0;
            break;
        }
        else if(answer<=limit/A[i]){
            answer*=A[i];
        }
        else{
            flag=1;
        }
    }
    
    if(flag==0){
        cout<<answer<<endl;
    }
    else{
        cout<<-1<<endl;
    }
    return 0;
}

Measured memory_bytes: 3988
import sys


def extract_max(A):
    x = A[0]
    A[0] = A[-1]
    A.pop()
    H = len(A)
    i = 0
    while i < H:
        v = A[i]
        rv = 0
        lv = 0
        r = (i + 1) * 2
        l = r - 1
        if l < H:
            lv = A[l]
            if r < H:
                rv = A[r]

        if v < lv and lv > rv:
            A[l] = v
            A[i] = lv
            i = l
        elif v < rv:
            A[r] = v
            A[i] = rv
            i = r
        else:
            break
    return x


def insert(a, n):
    i = len(a)
    a.append(n)
    while i > 0:
        p = int((i + 1) / 2) - 1
        v = a[i]
        pv = a[p]
        if pv < v:
            a[p] = v
            a[i] = pv
            i = p
        else:
            break


def main():
    istr = sys.stdin.read()
    cmds = list(istr.splitlines())
    S = []
    for cmd in cmds:  # input()
        if cmd[0] == "i":
            insert(S, int(cmd[7:]))

        elif cmd == "extract":
            a = extract_max(S)
            print(a)

        elif cmd == "end":
            break


if __name__ == '__main__':
    main()


Measured memory_bytes: 218316
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int R = sc.nextInt();
    if (R < 1200) {
      System.out.println("ABC");
    } else if (R < 2800) {
      System.out.println("ARC");
    } else {
      System.out.println("AGC");
    }
  }
}

Measured memory_bytes: 21972
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <chrono>
#include <random>

#define int long

const int INF = 1000000009;
const long LINF = 1123456789012345678;

typedef std::pair<int, int> P;

int h, w;
std::string s[405];
bool checked[405][405];
int ans;
int da[] = {-1, 0, 0, 1};
int db[] = {0, -1, 1, 0};

bool rangecheck(int a, int b){
	if(0 <= a && a < h && 0 <= b && b < w){
		return true;
	}else{
		return false;
	}
}

P dfs(int a, int b){
	P res = P(0, 0);
	checked[a][b] = true;
	//printf("  %ld %ld\n", a, b);
	for(int i = 0; i < 4; i++){
		int na = a + da[i];
		int nb = b + db[i];
		if(rangecheck(na, nb) && !checked[na][nb]){
			if((s[a][b] == '#' && s[na][nb] == '.') || (s[a][b] == '.' && s[na][nb] == '#')){
				P res2 = dfs(na, nb);
				res.first += res2.first, res.second += res2.second;
			}
		}
	}
	if(s[a][b] == '.'){
		res.second++;
	}else{
		res.first++;
	}
	return res;
}
	


signed main(){
	scanf("%ld %ld", &h, &w);
	for(int i = 0; i < h; i++){
		std::cin >> s[i];
	}
	for(int i = 0; i < h; i++){
		for(int j = 0; j < w; j++){
			P p = dfs(i, j);
			//printf("(%ld %ld), (%ld %ld)\n", i, j, p.first, p.second);
			ans += p.first * p.second;
		}
	}
	printf("%ld\n", ans);
	return 0;
}


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

int n,m;
cin>>n>>m;

int a[n][m];

for(int i=0;i<n;i++){
 for(int j=0;j<m;j++){
  cin>>a[i][j];
 }
}

int b[m];
int c[n];

for(int i=0;i<m;i++){
 cin>>b[i];
}

for(int i=0;i<n;i++){
 c[i]=0;
}


for(int i=0;i<n;i++){
 for(int j=0;j<m;j++){
  c[i]+=a[i][j]*b[j];
 }
}

for(int i=0;i<n;i++){
cout<<c[i]<<endl;
}

}


Measured memory_bytes: 3136
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <queue>
using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef pair<int, int> P;
const int c_INF = 111111111;
const int c_mINF = -111111111;
const int c_YET = -1;
const int c_Dx[4] = { 0,0,1,-1 };
const int c_Dy[4] = { 1,-1,0,0 };



int main() {
	
	char S[12];
	scanf("%s", &S);
	
	int len = strlen(S);
	bool ac = true;

	if (S[0] != 'A')printf("WA");
	else {
		int countC = 0;
		for (int i = 2; i <= len - 2; i++) {
			if (S[i] == 'C')countC++;
		}
		if (countC != 1) {
			printf("WA");
			ac = false;
		}
		
		if (ac) {
			int countCap = 0;
			for (int i = 1; i < len; i++) {
				if (int(S[i]) < 95)countCap++;
			}
			if (countCap != 1) {
				printf("WA");
				ac = false;
			}
			else printf("AC");
			
		}

	}

}





/*         提出前の確認事項

・デバッグ用の関数は＜＜コメント化＞＞しているか？
・すべての＜＜入力例＞＞は試したか？
・＜＜限界値分析＞＞はしたか？
・＜＜出力の改行＞＞の有無は確認したか？
・文字列の＜＜スペル＞＞は確認したか？
　　　　　　　　↓
	 ＜＜提出先＞＞に注意して提出！！
*/

Measured memory_bytes: 128
import java.util.*;

public class Main {
    static long MOD = 998244353;
    
    public static void main(String[] args) throws Exception {
        // Your code here! 
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int s = sc.nextInt();
        int[] array = new int[n];
        for (int i = 0; i < n; i++) {
            array[i] = sc.nextInt();
        }
        
        // ans: f(T)の全パターンの和
        // f(T): 集合Tの部分集合であって、和がsになるパターン数
        long ans = 0;
        
        // ans: [x^s] (f{1}+f{2}+f{3}+f{1,2}+f{1,3}+f{2,3}+f{1,2,3})
        // ex. f{1,2,3}: f1f2f3 - 1
        // ex. f{1,2}: f1f2 - 1
        
        // ex. n = 3, s = 4, array[] = {2, 2, 4}
        // -> f{3}に1個、f{1,2}に1個、f{1,3}に1個、f{2,3}に1個、f{1,2,3}に2個 -> ans = 6
        // F1: f1 - 1
        // F2: (F1+1)(f2+1) - 1 = f1 + f1f2 + f2
        // F3: (F2+1)(f3+1) - 1 = f1+f1f2+f2 + f1f3+f1f2f3+f2f3 + f3
        // Fn: (Fn-1+1)(fn+1) - 1 = (f1+1)(f2+1)(...)(fn+1)
        // -> ans: [x^s] (Fn) = [x^s] (f1+1)(f2+1)(...)(fn+1)
        
        // dp[i][s]: [x^s] (Fi)
        long[][] dp = new long[n+1][s+1];
        dp[0][0] = 1;
        for (int i = 0; i < n; i++) {
            int offset = array[i];
            
            // Fi = (Fi-1)(fi + 1)
            
            // Fi-1fi (選ぶ)
            for (int j = s; j - offset >= 0; j--) {
                dp[i+1][j] += dp[i][j-offset];
                dp[i+1][j] %= MOD;
            }
            // Fi-1fi (選ばない)
            for (int j = 0; j <= s; j++) {
                dp[i+1][j] += dp[i][j];
                dp[i+1][j] %= MOD;
            }
            // Fi-1
            for (int j = 0; j <= s; j++) {
                dp[i+1][j] += dp[i][j];
                dp[i+1][j] %= MOD;
            }
        }
        // for (int i = 0; i <= n; i++) {
        //     System.out.println(Arrays.toString(dp[i]));
        // }
        
        System.out.println(dp[n][s]);
    }
}

Measured memory_bytes: 137100
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define INF 1000000
using namespace std;
int main(){
    vector<int> vec(5);
    rep(i,5){
        cin >> vec[i];
    }
    sort(vec.begin(),vec.end());
    reverse(vec.begin(),vec.end());
    rep(i,5){
        if(i == 0) cout << vec[i];
        else cout << " " << vec[i];
    }
    cout << endl;
}


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

typedef long long ll;
typedef long double ld;
typedef vector<vector<int>> Graph;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
#define pi 3.14159265359
#define inf 2147483647
#define INF 9223372036854775807
#define mod 1000000007
#define mod2 998244353

int main() {
    ll X, Y; cin >> X >> Y;
    ll ans = 1;
    while(X * 2 <= Y) {
        X *= 2;
        ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3628
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
using namespace std;
#define INF 2000001145
#define LINF 100000000000000007
#define MOD 1000000007
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define repb(i, n) for (int i = n - 1; i >= 0; i--)
#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
int ceil2(int a,int b){if(a%b){return a/b+1;}else{return a/b;}}
typedef long long ll;
typedef pair<int,int> P;
struct edge{int to,cost;};

int ans=0;
int k,n;
int a[111],x[22][22],y[22][22];
signed main(){
	cin>>n;
	rep(i,n){
		cin>>a[i];
		rep(j,a[i]){
			cin>>x[i][j]>>y[i][j];
			x[i][j]--;
		}
	}
	
	rep(i,1<<n){
		int flag[22]={0};
		bool ok=1;
		int cnt=0;
		rep(j,n){
			if(i&(1<<j)){
				flag[j]=1;
				cnt++;
			}
		}
		rep(j,n){
			if(i&(1<<j)){
				rep(k,a[j]){
					if(y[j][k]==1){
						if(flag[x[j][k]]==0)ok=0;
					}
					else{
						if(flag[x[j][k]]==1)ok=0;
					}
				}
			}
		}
		if(ok)ans=max(cnt,ans);
	}
	cout<<ans<<endl;
}


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

#define fi first
#define se second
#define long long long
typedef pair<int,int> ii;

int main()
{
	// freopen("input.in", "r", stdin);

	long x; scanf("%lld", &x);

	if(x&1) printf("0\n");
	else
	{
		x /= 2;
		long fac2 = x, fac5 = 0;
		for(long i = 2; i <= x; i *= 2)
			fac2 += x/i;
		for(long i = 5; i <= x; i *= 5)
			fac5 += x/i;
		printf("%lld\n", min(fac5, fac2));
	}

}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
 int a, b, c;

 scanf("%d", &a);

 scanf("%d", &b);

 scanf("%d", &c);

 if (a <= b && b <= c)
 printf("%d %d %d\n", a, b, c);
 else if (a >= b && b >= c)
 printf("%d %d %d\n", c, b, a);
 else if (a >= c && a <= b)
 printf("%d %d %d\n", c, a, b);
 else if (a <= c && c <= b)
 printf("%d %d %d\n", a, c, b);
 else if (a >= c && c >= b)
 printf("%d %d %d\n", b, c, a);
 else if (c >= a && a >= b) 
 printf("%d %d %d\n", b, a, c);

 return 0;

}



Measured memory_bytes: 2140
N = int(input())

dp = [[0]*3 for i in range(N)]
abcs = []

for i in range(N):
    row = input().split()
    abc = [int(n) for n in row]
    abcs.append(abc)
    if i == 0:
        dp[0][0] = abc[0]
        dp[0][1] = abc[1]
        dp[0][2] = abc[2]
    else:
        dp[i][0] = max([abc[0] + dp[i-1][1], abc[0] + dp[i-1][2]])
        dp[i][1] = max([abc[1] + dp[i-1][0], abc[1] + dp[i-1][2]])
        dp[i][2] = max([abc[2] + dp[i-1][0], abc[2] + dp[i-1][1]])

print(max(dp[N-1]))


Measured memory_bytes: 44124
s = input()
if s.count("C")>=1 and s.count("F")>=1:
    if s.index("C")<s.index("F") or s.index("C")<len(s)-(1+s[::-1].index("F")):
        print("Yes")
    else:
        print("No")
else:
    print("No")

Measured memory_bytes: 8972
#include<stdio.h>

int main(void) {

	int a,b;
	char op;

	
	while (1) {
		scanf("%d %c %d", &a, &op, &b);
		if (op == '+') {
			printf("%d\n", a + b);
		}
		if (op == '-') {
			printf("%d\n", a - b);
		}
		if (op == '*') {
			printf("%d\n", a*b);
		}
		if (op == '/') {
			printf("%d\n", a / b);
		}
		if (op == '?') break;

	}

	return 0;

}


Measured memory_bytes: 2104
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
    ($next:expr,mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
use std::collections::HashMap;
use std::cmp::{max,min};
fn main(){
    input!{
        n:usize,
        mut tmp:[i64;n],
    }
    let mut an = vec![0];
    an.append(&mut tmp);
    an.push(0);
    let n = n + 2;
    let mut sum = 0;
    for j in 0..n-1 {
        sum += (an[j+1]-an[j]).abs();
    }
    for j in 0..n-2 {
        let div1 = an[j+1] - an[j];
        let div2 = an[j+2] - an[j+1];
        let div3 = an[j+2] - an[j];
        
        println!("{}",sum+div3.abs()-div2.abs()-div1.abs());
    }
}

Measured memory_bytes: 7292
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_E main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LLONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
// functions

#endif


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

    int N, K; cin >> N >> K;

    if ((N-1)*(N-2)/2 < K) {
        cout << -1 << endl;
        return 0;
    }

    vector<pii> edge;
    FOR(i,1,N){
        edge.push_back(pii(1, i+1));
    }

    int k = (N - 1)*(N - 2) / 2;
    bool ok = false;
    for(int i=1; i<N-1; i++) {
        for(int j=i+1; j<N; j++) {
            if (k == K) {
                ok = true;
                break;
            }
            edge.push_back(pii(i+1, j+1));
            k--;
        }
        if (ok) break;
    }

    int M = edge.size();
    cout << M << endl;
    REP(i, M) cout << edge[i].first << " " << edge[i].second << endl;

    return 0;
}


Measured memory_bytes: 384
// {{{ by shik
#include <bits/stdc++.h>
#include <unistd.h>
#define SZ(x) ((int)(x).size())
#define ALL(x) begin(x),end(x)
#define REP(i,n) for ( int i=0; i<int(n); i++ )
#define REP1(i,a,b) for ( int i=(a); i<=int(b); i++ )
#define FOR(it,c) for ( auto it=(c).begin(); it!=(c).end(); it++ )
#define MP make_pair
#define PB push_back
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
typedef vector<int> VI;

#ifdef SHIK
template<typename T>
void _dump( const char* s, T&& head ) { cerr<<s<<"="<<head<<endl; }

template<typename T, typename... Args>
void _dump( const char* s, T&& head, Args&&... tail ) {
    int c=0;
    while ( *s!=',' || c!=0 ) {
        if ( *s=='(' || *s=='[' || *s=='{' ) c++;
        if ( *s==')' || *s==']' || *s=='}' ) c--;
        cerr<<*s++;
    }
    cerr<<"="<<head<<", ";
    _dump(s+1,tail...);
}

#define dump(...) do { \
    fprintf(stderr, "%s:%d - ", __PRETTY_FUNCTION__, __LINE__); \
    _dump(#__VA_ARGS__, __VA_ARGS__); \
} while (0)

template<typename Iter>
ostream& _out( ostream &s, Iter b, Iter e ) {
    s<<"[";
    for ( auto it=b; it!=e; it++ ) s<<(it==b?"":" ")<<*it;
    s<<"]";
    return s;
}

template<typename A, typename B>
ostream& operator <<( ostream &s, const pair<A,B> &p ) { return s<<"("<<p.first<<","<<p.second<<")"; }
template<typename T>
ostream& operator <<( ostream &s, const vector<T> &c ) { return _out(s,ALL(c)); }
template<typename T, size_t N>
ostream& operator <<( ostream &s, const array<T,N> &c ) { return _out(s,ALL(c)); }
template<typename T>
ostream& operator <<( ostream &s, const set<T> &c ) { return _out(s,ALL(c)); }
template<typename A, typename B>
ostream& operator <<( ostream &s, const map<A,B> &c ) { return _out(s,ALL(c)); }
#else
#define dump(...)
#endif

template<typename T>
void _R( T &x ) { cin>>x; }
void _R( int &x ) { scanf("%d",&x); }
void _R( long long &x ) { scanf("%" PRId64,&x); }
void _R( double &x ) { scanf("%lf",&x); }
void _R( char &x ) { scanf(" %c",&x); }
void _R( char *x ) { scanf("%s",x); }

void R() {}
template<typename T, typename... U>
void R( T& head, U&... tail ) {
    _R(head);
    R(tail...);
}

template<typename T>
void _W( const T &x ) { cout<<x; }
void _W( const int &x ) { printf("%d",x); }
template<typename T>
void _W( const vector<T> &x ) {
    for ( auto i=x.cbegin(); i!=x.cend(); i++ ) {
        if ( i!=x.cbegin() ) putchar(' ');
        _W(*i);
    }
}

void W() {}
template<typename T, typename... U>
void W( const T& head, const U&... tail ) {
    _W(head);
    putchar(sizeof...(tail)?' ':'\n');
    W(tail...);
}

#ifdef SHIK
#define FILEIO(...)
#else
#define FILEIO(name) do {\
    freopen(name ".in","r",stdin); \
    freopen(name ".out","w",stdout); \
} while (0)
#endif

// }}}

const int N=1e5+10;
int n,c,k,t[N];
int main() {
    R(n,c,k);
    REP(i,n) R(t[i]);
    sort(t,t+n);
    int ans=0,b=0,dt=0;
    REP(i,n) {
        if ( b==c || t[i]>dt ) {
            ans++;
            b=0;
        }
        if ( b==0 ) dt=t[i]+k;
        b++;
    }
    W(ans);
    return 0;
}


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

int main(){
	int n, p;
	while(cin >>n >>p){
		if(n == 0 && p == 0) break;
		int utuwa = p, i = 0, kouho[51] = {0};
		while(1){
			if(utuwa != 0){
				utuwa--;
				kouho[i]++;
			} else{
				utuwa += kouho[i];
				kouho[i] = 0;
			}
			if(utuwa == 0 && kouho[i] == p) break;
			if(i >= (n - 1)) i = 0;
			else i++;
		}
		cout <<i <<endl;
	}
	return 0;
}

Measured memory_bytes: 868
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<map>
#include<cmath>
#define N 100009
using namespace std;
const int INF = 0x3f3f3f3f;
int a[N];
int main()
{
    int n, x;
    scanf("%d%d", &n, &x);
    for(int i = 1; i <= n; i++) scanf("%d", &a[i]);
    long long ans, now; ans = now = 0;
    for(int i = 1; i <= n; i++)
    {
        if(now + a[i] <= x) now = a[i];
        else ans += now + a[i] - x, now = a[i] - (now + a[i] - x);
    }
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 640
open Batteries
let () =
  let n,k = Scanf.scanf "%d %d " (fun a b -> a,b) in
  let a_lst = Array.to_list @@ Array.init n (fun _ -> Scanf.scanf "%d " (fun a -> a)) in

  let minsum = List.fold_left (fun acc x -> acc + (2 * min (k-x) x)) 0 a_lst in
  
  Printf.printf "%d\n" minsum


Measured memory_bytes: 1152
/**
*    created: 20.06.2020 02:52:25
**/
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using namespace std;

signed main() {

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

    int d;
    cin >> d;
    if (d == 25) cout << "Christmas" << endl;
    if (d == 24) cout << "Christmas Eve" << endl;
    if (d == 23) cout << "Christmas Eve Eve" << endl;
    if (d == 22) cout << "Christmas Eve Eve Eve" << endl;
    return 0;
}

Measured memory_bytes: 3532
#180128C
N = int(input())
A1 = list(map(int,input().split()))
A2 = list(map(int,input().split()))
X = 0
Y = 0

for i in range(N):
    B1 = A1[:i+1]
    #print(B1)
    B2 = A2[i:]
    #print(B2)
    Y = sum(B1) + sum(B2)
    if Y > X:
        X = Y
print(int(X))
    
    

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

#define INF 1000000000
int N, M;
int C[16], x[20000];
int dp[20000][257]; //dp[p] := i???????????°?????\????????\???????????¨?????????????????????????????¨?????????????????????????°????

//p:?????? w:?????¨?????????
int solve(int p, int w){
  if(p==N)return 0;
  if(dp[p][w]!=-1)return dp[p][w];

  int mn=INF;
  for(int i=0; i<M; i++){
    int nw = w+C[i];
    if(nw<0)nw=0;
    if(nw>255)nw=255;
    int tmp=solve(p+1, nw)+(nw-x[p])*(nw-x[p]);
    if(mn>tmp)mn=tmp;
  }
  return dp[p][w]=mn;
}

int main(){
  while(cin >> N >> M, !(N==0 && M==0)){
    //??\???
    for(int i=0; i<M; i++)
      cin >> C[i];
    for(int i=0; i<N; i++)
      cin >> x[i];

    memset(dp, -1, sizeof(dp));

    cout << solve(0, 128) << endl;
  }
  return 0;
}

Measured memory_bytes: 22884
#include<stdio.h>
#define MAX 25
#define NIL -1
struct tree {
        int parent;
        int left;
        int right;
};
void dispf(int, struct tree*);
void dispm(int, struct tree*);
void dispb(int, struct tree*);
main()
{
        struct tree t[MAX];
        int i, j, n, id, l, r, prec, root;
        scanf("%d", &n);
        for (i = 0; i < n; i++) {
                t[i].parent = NIL;
        }
    for(i = 0; i < n; i++) {
        scanf("%d %d %d", &id, &l, &r);
        t[id].left = l;
                t[id].right = r;
                if (l != -1) {
                        t[l].parent = id;
                }
                if (r != -1) {
                        t[r].parent = id;
                }
    }
    for (i = 0; i < n; i++) {
        if(t[i].parent == NIL) {
                        root = i;
                        break;
                }
        }
        printf("Preorder\n");
        dispf(root, t);
        printf("\nInorder\n");
        dispm(root, t);
        printf("\nPostorder\n");
        dispb(root, t);
        putchar('\n');
}
void dispf(int u, struct tree *t)
{
        if (u == NIL) {
                return;
        } else {
                printf(" %d", u);
                dispf(t[u].left, t);
                dispf(t[u].right, t);
        }
}
void dispm(int u, struct tree *t)
{
    if (u == NIL) {
        return;
    } else {
        dispm(t[u].left, t);
                printf(" %d", u);
        dispm(t[u].right, t);
    }
}
void dispb(int u, struct tree *t)
{
    if (u == NIL) {
        return;
    } else {
        dispb(t[u].left, t);
        dispb(t[u].right, t);
                printf(" %d", u);
    }
}



Measured memory_bytes: 2704
#include<bits/stdc++.h>
using namespace std;
const int N=20010,PNUM=N+N+32768,M=1000010,C=1e9;
typedef vector<pair<int,int> >::iterator vit;
int n,u,pnum,ans,a[N],po[N];
vector<pair<int,int> > g;
namespace twosat{
	int k,clk,nscc,low[PNUM],dfn[PNUM],isc[PNUM],fi[PNUM],b[M],ne[M];
	stack<int> s;
	void clear(){
		k=clk=nscc=0; for (int i=1; i<=pnum; i++) dfn[i]=isc[i]=low[i]=fi[i]=0;
	}
	void add(int x,int y){
		b[++k]=y; ne[k]=fi[x]; fi[x]=k;
	}
	namespace zkw{
		int st[N<<2];
		void init(){
			for (u=1; u<(n<<1); u<<=1); --u;
		}
		void link(int now,int s,int t){
			if (s>t) return;
			now+=u;
			for (s+=u-1,t+=u+1; s^t^1; s>>=1,t>>=1){
				if (~s&1) add(now,s^1);
				if (t&1) add(now,t^1);
			}
		}
	}
	void tajan(int x){
		dfn[x]=low[x]=++clk;
		s.push(x);
		for (int j=fi[x]; j; j=ne[j]){
			if (!dfn[b[j]]) tajan(b[j]);
			if (!isc[b[j]]) low[x]=min(low[x],low[b[j]]);
		}
		if (dfn[x]==low[x]){
			++nscc;
			while (1){
				int u=s.top(); s.pop();
				isc[u]=nscc;
				if (u==x) break;
			}
		}
	}
}
void unite(int ovo){
	for (int i=1; (i<<1)<=pnum; i++){
		twosat::add(i,i<<1);
		if ((i<<1|1)<=pnum) twosat::add(i,i<<1|1);
	}
	for (vit i=g.begin(); i!=g.end(); ++i){
		int lp=upper_bound(g.begin(),g.end(),make_pair(i->first-ovo,C))-g.begin()+1;
		int rp=lower_bound(g.begin(),g.end(),make_pair(i->first+ovo,0))-g.begin();
		twosat::zkw::link(po[i-g.begin()+1],lp,i-g.begin());
		twosat::zkw::link(po[i-g.begin()+1],i-g.begin()+2,rp);
	}
}
bool check(int ovo){
	twosat::clear();
	unite(ovo);
	for (int i=1; i<=pnum; i++) if (!twosat::isc[i]) twosat::tajan(i);
	for (int i=1; i<=n; i++) if (twosat::isc[u+i]==twosat::isc[u+po[i]]) return 0;
	return 1;
}
void init(){
	scanf("%d",&n);
	twosat::zkw::init();
	pnum=n+n+u;
	for (int i=1; i<=n; i++){
		scanf("%d%d",&a[i],&a[i+n]);
		g.push_back(make_pair(a[i],i+n));
		g.push_back(make_pair(a[i+n],i));
	}
	sort(g.begin(),g.end());
	for (vit i=g.begin(); i!=g.end(); ++i) po[i-g.begin()+1]=lower_bound(g.begin(),g.end(),make_pair(a[i->second],(i->second)>n?i->second-n:i->second+n))-g.begin()+1;
}
int main(){
//	freopen("A.in","r",stdin);
//	freopen("FF.out","w",stdout);
	init();
	for (int l=1,r=C/(n==1?1:n-1),mid=(l+r)>>1; l<=r; mid=(l+r)>>1)
	if (check(mid)) ans=mid,l=mid+1; else r=mid-1;
	printf("%d",ans);
}

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

int main() {
    string S;
    cin >> S;
    map<int,int>Map;
    int X = 0;
    int ans = 0;
    int cnt = 1;
    Map[0] = 1;
    for(int i = S.size()-1; i >= 0; i--) {
        X = (X+(S[i]-'0')*cnt)%2019;
        ans+=Map[X];
        Map[X]++;
        cnt = (cnt*10)%2019;
    }
    cout << ans << endl;
}

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

using ll = long long;
using ull = unsigned long long;
#define countof(a) (sizeof(a)/sizeof((a)[0]))
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i < (n); i++)
#define bzero(p, n) memset(p, 0, n)
#define all(a) begin(a),end(a)
template<class T> inline void sort_uniq(T& c) { sort(ALL(c)); c.erase(unique(ALL(c)), c.end()); }
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}
template<class T> void cout_v(const vector<T>& c)
{ for (int i = 0; i < c.size(); i++) cout << c[i] << endl; }
template<class K, class V> void cout_v(map<K, V>& m)
{ for(auto it=m.begin();it!=m.end();it++)cout<<it->first<<":"<<it->second<<endl;}
template<class T> void cout_h(const vector<T>& c)
{ for (int i = 0; i < c.size(); i++) cout << c[i] << (i==c.size()-1?"\n":" "); }
template<class T> inline bool chmin(T& a, T b) {return a>b?a=b,true:false;}
template<class T> inline bool chmax(T& a, T b) {return a<b?a=b,true:false;}
inline int powi(int x,int y) {int p=1; while(y--) p*=x; return p;}
inline ll powll(ll x,ll y) {ll p=1; while(y--) p*=x; return p;}
#define SP << " " <<
#define FMT(a) #a<<":"<<a 
#define FMT2(a,b) #a<<":"<<a<<", "<<#b<<":"<<b 
#define FMT3(a,b,c) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c 
#define FMT4(a,b,c,d) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c<<", "<<#d<<":"<<d 

int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    cout<<std::fixed<<std::setprecision(15);

    int N, K; cin >> N >> K;
    double ans = 0;

    for (int i = 1; i <= min(K-1, N); i++) {
        int x = ceil(log2((double)K/i));// cout << FMT(x) << endl;
        assert(x >= 1);
        ans += pow((double)0.5, x);
    }
    ans += max(0, N - K + 1);
    ans /= N;

    cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int m = scan.nextInt();

		int ans = com(n, 2) + com(m, 2);

		System.out.println(ans);

	}
	public static int com(int a, int b) {
		if(a < b)
			return 0;

		int res;

		res = 1;
		int i;
		for(i = 0; i < b; i++) {
			res = res * (a - i);
		}
		for(i = 1; i <= b; i++) {
			res = res / i;
		}

		return res;
	}
}

Measured memory_bytes: 22228
w, h, n = map(int, input().split())
wtmp = 0
htmp = 0
for i in range(n):
    x, y, a = map(int, input().split())
    if a==1:
        wtmp = max(wtmp,x)
    elif a==2:
        w = min(w,x)
    elif a==3:
        htmp = max(htmp,y)
    elif a==4:
        h = min(h,y)
if w-wtmp<0 or h-htmp<0:
    print(0)
else:
    print((w-wtmp)*(h-htmp))

Measured memory_bytes: 3064
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_set>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<complex>
#include<tuple>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef long double D;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=998244353;//1000000007;

ll cul(string s){
    set<string> S;
    queue<string> Q;
    S.insert(s);
    Q.push(s);
    while(!Q.empty()){
        string w=Q.front(); Q.pop();
        for(int i=1;i<s.size();i++){
            if(w[i-1]!=w[i]){
                for(char c='a';c<'d';c++){
                    if(w[i-1]!=c && w[i]!=c){
                        string N=w;
                        N[i-1]=N[i]=c;
                        if(S.count(N)==0){S.insert(N); Q.push(N); break;}
                    }
                }
            }
        }
    }
    return S.size();
}

int main(){
    string s;
    cin>>s;
    bool j1=false,j2=false;
    ll sum=s[0]-'a';
    for(int i=1;i<s.size();i++){
        if(s[i-1]!=s[i]){j1=true;}
        else{j2=true;}
        sum+=s[i]-'a';
    }
    sum%=3;
    if(s.size()<5){cout<<cul(s)<<endl;}
    else if(!j1){cout<<1<<endl;}
    else{
        vector<vector<pll>> dp(3,vector<pll>(3,{0,0}));
        vector<vector<pll>> next(3,vector<pll>(3));
        dp[0][0]=dp[1][1]=dp[2][2]={0,1};
        for(int i=1;i<s.size();i++){
            for(auto &I:next){for(auto &T:I){T={0,0};}}
            for(int t=0;t<3;t++){
                for(int h=0;h<3;h++){
                    for(int k=0;k<3;k++){
                        if(h==k){next[(t+k)%3][k].F+=dp[t][h].F+dp[t][h].S; next[(t+k)%3][k].F%=MOD;}
                        else{
                            next[(t+k)%3][k].F+=dp[t][h].F;
                            next[(t+k)%3][k].S+=dp[t][h].S;
                            next[(t+k)%3][k].F%=MOD;
                            next[(t+k)%3][k].S%=MOD;
                        }
                    }
                }
            }
            for(int i=0;i<3;i++){
                for(int h=0;h<3;h++){dp[i][h]=next[i][h];}
            }
        }
        ll ans=!j2?1LL:0LL;
        ans+=dp[sum][0].F+dp[sum][1].F+dp[sum][2].F;
        cout<<ans%MOD<<endl;
    }
    
    
    return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<vector>
#include <cmath>
#include <map>
#include <algorithm>
#include <string>
using namespace std;
int main(void){
    int n, m;
 
	cin >> n >> m;
	int S[n][2];
	int P[m][2];
 
	for (int i = 0; i < n; i++)
		cin >> S[i][0] >> S[i][1]; 
	for (int i = 0; i < m; i++)
		cin >> P[i][0] >> P[i][1]; 
	for (int i = 0; i < n; i++)
	{
		int ans = 0;
		int range = abs(S[i][0] - P[0][0]) + abs(S[i][1] - P[0][1]);
 
		for (int j = 1; j < m; j++)
		{
			int tmp = abs(S[i][0] - P[j][0]) + abs(S[i][1] - P[j][1]);
 
			if (tmp < range)
			{
				range = tmp;
				ans = j;
			}
		}
		cout << ans + 1 << endl;
	}
}

Measured memory_bytes: 256
#include<iostream>
#include<queue>
#include<vector>
#define ll long long
using namespace std;
const int N=100005;
struct node{
	int num,w;
	node(){}
	node(int num,int w):num(num),w(w){}
	friend bool operator<(node a,node b){
		return a.w>b.w;
	}
};
int n,m,a[N],fa[N],h[N],vis[N],cnt;
ll ans;
vector<int> v;
priority_queue<node> q[N],qq;
int find(int x)
{
	if(x==fa[x])  return x;
	return fa[x]=find(fa[x]);
}
void unionn(int x,int y)
{
	x=find(x);
	y=find(y);
	if(x==y)  return;
	if(h[x]<h[y])
	{
		fa[x]=y;
		h[y]=max(h[y],h[x]+1);
	}
	else
	{
		fa[y]=x;
		h[x]=max(h[x],h[y]+1);
	}
}
int main()
{
	cin>>n>>m;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		fa[i]=i;
		h[i]=1;
	}
	for(int i=1;i<=m;i++)
	{
		int x,y;
		cin>>x>>y;
		unionn(x,y);
	}
	for(int i=0;i<n;i++)
	{
		fa[i]=find(i);
		q[fa[i]].push(node(i,a[i]));
		if(!vis[fa[i]])
		{
			v.push_back(fa[i]);
			vis[fa[i]]=1;
			cnt++;
		}
	}
	cnt=2*(cnt-1);
	if(!cnt)
	{
		cout<<0;
		return 0; 
	}
	for(int i=0;i<v.size();i++)
	{
		ans+=q[v[i]].top().w;
		q[v[i]].pop();
	}
	for(int i=0;i<v.size();i++)
	  if(!q[v[i]].empty())
	    qq.push(node(q[v[i]].top().num,q[v[i]].top().w));
	cnt-=v.size();
	for(int i=1;i<=cnt;i++)
	{
		if(qq.empty())
		{
			cout<<"Impossible";
			return 0;
		}
		node x=qq.top();
		int y=fa[x.num];
		ans+=x.w;
		q[y].pop();
		qq.pop();
		if(!q[y].empty())
		  qq.push(node(q[y].top().num,q[y].top().w));
	}
	cout<<ans;
}

Measured memory_bytes: 9976
#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" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define ANS(n) cout << (n) << endl
#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

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int32 h,w;
    cin >> h >> w;
    int32 a[h][w];
    REP(i,h)REP(j,w)cin >> a[i][j];
    vector<tuple<int32,int32,int32,int32>> ans;
    REP(i,h){
        REP(j,w){
            if(a[i][j] % 2 == 1){
                bool flg = true;
                REP(k,4){
                    int32 ny = i + dy[k];
                    int32 nx = j + dx[k];
                    if(ny < 0 || h <= ny)continue;
                    if(nx < 0 || w <= nx)continue;
                    if(a[ny][nx] % 2 == 1){
                        a[i][j]--;
                        a[ny][nx]++;
                        ans.pb(make_tuple(i+1,j+1,ny+1,nx+1));
                        flg = false;
                        break;
                    }
                }
                if(flg){
                    FOR(k,2,4){
                        int32 ny = i + dy[k];
                        int32 nx = j + dx[k];
                        if(ny < 0 || h <= ny)continue;
                        if(nx < 0 || w <= nx)continue;
                        a[i][j]--;
                        a[ny][nx]++;
                        ans.pb(make_tuple(i+1,j+1,ny+1,nx+1));
                        break;
                    }
                }
            }
        }
    }
    ANS(ans.size());
    REP(i,ans.size()){
        cout << get<0>(ans[i]) << " " << get<1>(ans[i]) << " " << get<2>(ans[i]) << " " << get<3>(ans[i]) << "\n";
    }
    // int32 cnt = 0;
    // REP(i,h)REP(j,w){
    //     if(a[i][j] % 2 == 0)cnt++;
    // }
    // ANS(cnt);
    return 0;
}

Measured memory_bytes: 8432
#include <bits/stdc++.h>
int n, W, w[100] = {}, v[100] = {};
long long dp[101][100001] = {};
void solve(void)
{
  for(int i = 0; i <= n; i++){
    for(int j = 0; j <= W; j++){
      if(i != 0 && j != 0){
        if(j < w[i - 1]) dp[i][j] = dp[i - 1][j];
        else dp[i][j] = std::max(dp[i - 1][j], dp[i - 1][j - w[i - 1]] + v[i - 1]);
      }
    }
  }
}
int main(void)
{
  std::cin >> n >> W;
  for(int i = 0; i != n; i++) std::cin >> w[i] >> v[i];
  solve();
  std::cout << dp[n][W] << std::endl;
  return 0;
}

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

int a, b, c; 
int main() {
  scanf("%d %d %d", &a, &b, &c);
  if (c > a && c > b) {
    cout << (a * b / 2);
  } else if (b > a && b > c) {
    cout << (a * c / 2); 
  } else {
    cout << (b * c / 2);
  }
  return 0;
} 


Measured memory_bytes: 256
import math


def solve():
    N, D = [int(x) for x in input().split()]
    ans = 0
    for _ in range(N):
        X, Y = [int(x) for x in input().split()]
        if math.sqrt(X**2 + Y**2) <= D:
            ans += 1
    print(ans)


if __name__ == "__main__":
    solve()

Measured memory_bytes: 70004
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
#define pb push_back
#define rsz resize
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
using pi = pair<int,int>;
#define f first
#define s second
#define mp make_pair
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
void setIO(string name = "b") {
    ios_base::sync_with_stdio(0); cin.tie(0);
    freopen((name+".in").c_str(), "r", stdin);
    freopen((name+".out").c_str(), "w", stdout);
}

int main() {
    //setIO();
    int n, k; cin >> n >> k;
    ll ans = k;
    for (int i = 1; i < n; i++) {
        ans *= (k - 1);
    }
    cout << ans << '\n';
}

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

const int N = 101, K = 1e5 + 1, MOD = 1e9 + 7;

int n, k, val[N], pos[K];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  
  cin >> n >> k;
  
  for(int i = 0; i < n; i++)
    cin >> val[i];
  
  pos[0] = 1;
  for(int i = 0; i < n; i++) {
    int d = k, sum = 0;
    for(int f = k; f > -1; f--) {
      sum = (sum - pos[f] + MOD) % MOD;
      while(d > -1 && f - d <= val[i])
        sum = (sum + pos[d--]) % MOD;
      pos[f] = (pos[f] + sum) % MOD;
    }
  }
  cout << pos[k];
}

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

int main(){
  while(true){
    int sumA = 0, sumB = 0;
    for(int i = 0; i < 4; i++){
      int x;
      if(!(cin >> x)) return 0;
      sumA += x;
    }
    for(int i = 0; i < 4; i++){
      int x;
      cin >> x;
      sumB += x;
    }

    cout << max(sumA, sumB) << endl;
  }
}

Measured memory_bytes: 0
<?php
fscanf(STDIN,'%d',$K);
 if($K%2==0){
    $a= $K/2;
    $b=$a*$K/2;
    echo $b; 
}else{
    $c=floor($K/2);
    $d=$c+1;
    echo $c*$d;
}




?>

Measured memory_bytes: 3576
#include<stdio.h>
int C[100010]={0};
int blmn(int v,int e,int s,int *fr,int *to,int *co){
  int i,j,f;
  for(i=0;i<v;i++)C[i]=1000000000;
  C[s]=0;
  for(i=0;i<v;i++){
    for(j=0;j<e;j++){
      if(C[fr[j]]==1000000000)continue;
      if(C[to[j]]>C[fr[j]]+co[j]){
	C[to[j]]=C[fr[j]]+co[j];
	if(i==v-1)return 1;
      }
    }
  }
  return 0;
}
int main(){
  int n,m,s,i,a[100010],b[100010],c[100010];
  scanf("%d %d %d",&n,&m,&s);
  for(i=0;i<m;i++)scanf("%d %d %d",&a[i],&b[i],&c[i]);
  if(blmn(n,m,s,a,b,c))printf("NEGATIVE CYCLE\n");
  else{
    for(i=0;i<n;i++){
      C[i]-1000000000?printf("%d\n",C[i]):printf("INF\n");
    }
  }
  return 0;
}

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

mod = 10**9+7
N, M = map(int, input().split())
a = [int(input()) for _ in range(M)]
a = a[::-1]
dp = [0] * (N+1)
dp[0] = 1
if a and a[-1] == 1:
    a.pop()
else:
    dp[1] = 1
for i in range(2, N+1):
    if a and a[-1] == i:
        a.pop()
    else:
        dp[i] = (dp[i-1] + dp[i-2]) % mod
print(dp[-1])



Measured memory_bytes: 44892