akhauriyash/Code-Regression huggingface dataset:
#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <bitset>

#include <queue>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <ctime>
////
//#include <random>//
/////////

typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;

////定数
const int INF = (int)1e9 + 10;
const LL MOD = (LL)1e9 + 7;
const LL LINF = (LL)4e18 + 20;
const LD PI = acos(-1.0);
const double EPS = 1e-9; 
/////////
using namespace::std;
//////////////
LL powMod(LL x, int cnt, LL prime) {
	LL ans = 1;
	LL base = x;
	while (cnt) {
		if (cnt & 1) {
			ans = (ans * base) % prime;
		}
		base = (base * base) % prime;
		cnt /= 2;
	}
	return ans;
}

void solve() {
	LL N, K;
	cin >> N >> K;
	LL ans = 0;
	vector<LL> A(K + 1, 0);
	for (int i = K; i >= 1; --i) {
		LL res = K / i;
		A[i] = powMod(res, N, MOD);
		for (int j = i + i; j <= K; j += i) {
			A[i] = (A[i] - A[j] + MOD) % MOD;
		}
		ans = (ans + A[i] * i) % MOD;
	}
	cout << ans << endl;
}

signed main(void) {
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}


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

int main() {
// 	cout<<"GfG!";
map<int,int>mp;
int i,j;
    for(i=1;i<10;i++)
    {
        for(j=1;j<10;j++)
        {
            mp[i*j]=1;
        }
    }
    int n;
    cin>>n;
    if(mp[n]==1)
    cout<<"Yes"<<endl;
    else
    cout<<"No"<<endl;
	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++)
typedef pair<int, int> P;
typedef long long ll;
ll dp[2][2020];
int main()
{
    string s;
    cin >> s;
    ll ans = 0;
    for (auto i = 0; i < s.length(); i++)
    {
        int val = s[i] - '0';
        for (int j = 0; j < 2019; j++)
        {
            dp[(i + 1) % 2][j] = 0;
        }
        dp[(i + 1) % 2][val] = 1;
        for (int j = 0; j < 2019; j++)
        {
            dp[(i + 1) % 2][(j * 10 + val) % 2019] += dp[i % 2][j];
        }
        ans += dp[i % 2][0];
    }
    ans += dp[s.length() % 2][0];
    cout << ans << endl;
}

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

main() {
  int N; cin >> N;
  V a(3*N); rep(i, 3*N) cin >> a[i];

  sort(a.begin(), a.end());
  ll ans = 0;
  rep(i, N + 1) {
    if (i == 0) continue;
    ans += a[3*N - 2*i];
  }
  cout << ans << endl;
}

Measured memory_bytes: 2560
package main

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

const (
	initialBufSize = 100000
	maxBufSize     = 1000000
)

var sc *bufio.Scanner

func initScanner(r io.Reader) *bufio.Scanner {
	buf := make([]byte, initialBufSize)

	sc := bufio.NewScanner(r)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords) // bufio.ScanLines
	return sc
}

func main() {
	sc = initScanner(os.Stdin)
	resolve()
}

func resolve() {
	n := scanInt(sc)
	as := nextIntSlice(sc, n)
	nums := map[int]int{}
	for i := range as {
		nums[as[i]]++
	}
	combis := map[int]int{}
	combiNum := 0
	for i, v := range nums {
		combis[i] = v * (v - 1) >> 1
		combiNum += combis[i]
	}
	for _, v := range as {
		num := nums[v]
		fmt.Println(combiNum - combis[v] + (num-1)*(num-2)>>1)
	}
	return
}

func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	a, _ := strconv.Atoi(sc.Text())
	return int(a)
}

func nextString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

func nextIntSlice(sc *bufio.Scanner, n int) (a []int) {

	a = make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = nextInt(sc)
	}
	return a
}

// snip-scan-funcs
func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return int(i)
}
func scanString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}


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

typedef long long int ll;

int main () {
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    ll x, k, d;
    cin >> x >> k >> d;
    
    ll dist = abs(x);
    
    ll moves = (dist/d);
    
    ll ans;
    
    if (k<=moves) {
		ans = dist - (k*d);
	} 
	else {
		ll op1 = dist - ((dist/d)*d);
		ll op2 = (((dist/d)+1)*(d)) - dist;
		if (op1<=op2) {
			ll rem = k-(dist/d);
			if (rem%2==0) ans = op1;
			else ans = op2;
		}
		else {
			ll rem = k-((dist/d)+1);
			if (rem%2==0) ans = op2;
			else ans = op1;
		}
	}
	
	cout << ans << "\n";
}


Measured memory_bytes: 3620
import java.util.*;

public class Main {
  public static void main(String args[]) {
  	Scanner sc = new Scanner(System.in);
    int[] group = new int[12];
    group[0] = 0;
    group[1] = 2;
    group[2] = 0;
    group[3] = 1;
    group[4] = 0;
    group[5] = 1;
    group[6] = 0;
    group[7] = 0;
    group[8] = 1;
    group[9] = 0;
    group[10] = 1;
    group[11] = 0;
    
    int x = sc.nextInt();
    int y = sc.nextInt();
    
    if (group[x - 1] == group[y -1]) {
      System.out.println("Yes");
    } else {
      System.out.println("No");
    }
  }
}

Measured memory_bytes: 23636
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef pair<ll,ll> l_l;
typedef pair<int,int> i_i;
const ll MOD=1e9+7;
const int INF=1<<30;

ll res[100010];

int main(){
  int N,M;
  cin >> N >> M;
  int waans=0;
  int acans=0;
  rep(i,M){
    int p; string S;
    cin >> p >> S;
    if(S=="WA"&&res[p]!=-1){
      res[p]++;
    }
    if(S=="AC"){
      if(res[p]>0) waans+=res[p];
      res[p]=-1;
    }
  }
  rep(i,100010){
    if(res[i]==-1){
      acans++;
    }
  }
  cout << acans << " " << waans << endl;
}

Measured memory_bytes: 1024
function main()
	N,K=map(x->parse(Int,x),split(readline()))
	A=sort(map(x->parse(Int,x),split(readline())))
	mod=10^9+7
	ans=1
	if N==K||A[end]<0&&K%2==1
		for a=A[N-K+1:N]
			ans=ans*a%mod
		end
	else
		i=1
		j=N
		if K%2==1
			ans=A[j]
			j-=1
		end
		while K>1
			if A[i]*A[i+1]>A[j]*A[j-1]
				ans=ans*A[i]%mod*A[i+1]%mod
				i+=2
			else
				ans=ans*A[j]%mod*A[j-1]%mod
				j-=2
			end
			K-=2
		end
	end
	println((mod+ans)%mod)
end
main()


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

using namespace std;

#define int long long
#define all(v) begin(v), end(v)
#define reps(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

using pint = pair<int, int>;
using tint = tuple<int, int, int>;
using vint = vector<int>;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

int n, m;
double p[88];
double dp[44][44][44];

const double Pi = acos(-1);
double area(int a, int b) {
  return sin((p[b]-p[a])*2*Pi)/2;
}

double solve(int fr, int la, int cnt) {
  if(cnt == m) return (la-fr < 0.5 ? -1 : 1)*area(la, n+fr);
  if(la == n-1) return -DBL_MAX/3;
  double &res = dp[fr][la][cnt];
  if(res != -DBL_MAX/3) return res;
  res = -DBL_MAX/5;
  reps(i, la+1, n) {
    chmax(res, solve(fr, i, cnt+1)+area(la, i));
  }
  return res;
}

signed main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(6);

  while(cin >> n >> m, n || m) {
    rep(i, n) cin >> p[i];
    rep(i, n) p[n+i] = p[i]+1;
    rep(i, 44) rep(j, 44) rep(k, 44) dp[i][j][k] = -DBL_MAX/3;
    double ans = 0;
    rep(i, n) chmax(ans, solve(i, i, 1));
    cout << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 4172
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	string T;
	cin >> T;
	for (int i = 0; i < T.size(); ++i) {
		if (T[i] == '?') T[i] = 'D';
	}
	cout << T;
	return 0;
}

Measured memory_bytes: 3744
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using Graph = vector<vector<int>>;
const int INF = 1e9 + 1;
const ll LLINF = 1e18;
const int MOD = 1e9 + 7;

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

    int N, x;
    cin >> N >> x;
    vector<int> a(N + 1);

    int l = x;
    ll ans = 0;
    for (int i = 0; i < N; ++i) {
        int a;
        cin >> a;
        if (i % 2) {
            l = max(x - a, l);
            ans += a - x + l;
        } else {
            l = min(l, a);
            ans += a - l;
        }
    }

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


Measured memory_bytes: 640
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
using namespace std;

#define FOR(i,f,t) for(int i=(int)f; i<(int)t; i++)
#define FORR(i,f,t) for(int i=(int)f; i>(int)t; i--)
#define ms(obj, val) memset(obj, val, sizeof(obj))
#define pb push_back
#define SYNC ios_base::sync_with_stdio(false)
#define inf 2248012
#define mp make_pair
#define F first
#define S second
#define ri(x) scanf("%d",&x)
#define rii(x,y) scanf("%d %d",&x,&y)
#define riii(x,y,z) scanf("%d %d %d",&x,&y,&z)
#define lri(x) scanf("%lld",&x)
#define lrii(x,y) scanf("%lld %lld",&x,&y)
#define lriii(x,y,z) scanf("%lld %lld %lld",&x,&y,&z)

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

const int MAXN = 5e5+3; //AREGLAAAAAAAAR!!!!
int memo[MAXN],pat[MAXN];
vector<int> G[MAXN];
int dfs(int n,int p){
	pat[n]=p;
	memo[n]=1;
	FOR(i,0,G[n].size()){
		int u=G[n][i];
		if(!memo[u]){
			dfs(u,n);
		}
	}
}

int dfs2(int n){
	memo[n]=2;
	FOR(i,0,G[n].size()){
		int u=G[n][i];
		if(!memo[u]){
			dfs2(u);
		}
	}
}

int dfs3(int n){
	memo[n]=3;
	FOR(i,0,G[n].size()){
		int u=G[n][i];
		if(!memo[u]){
			dfs3(u);
		}
	}
}

int dfs4(int n){
	memo[n]=5;
	FOR(i,0,G[n].size()){
		int u=G[n][i];
		if(!memo[u]){
			dfs4(u);
		}
	}
}

int dfs5(int n){
	memo[n]=7;
	FOR(i,0,G[n].size()){
		int u=G[n][i];
		if(!memo[u]){
			dfs5(u);
		}
	}
}


int main(){
	int a,b,n;
	ri(n);
	FOR(i,0,n-1){
		rii(a,b);
		a--;b--;
		G[a].pb(b);
		G[b].pb(a);
	}
	dfs(0,-1);
	int v=n-1,p=pat[n-1],c=0;
	ms(memo,0);
	while(p!=-1){
		if(v!=0 && v!=n-1) c++;
		memo[v]=7;
		int aux=p;
		p=pat[p];
		v=aux;
	}
	memo[0]=1; memo[n-1]=1;
	int c1=c/2,c2=c/2;
	if(c%2) c1++;
	dfs2(0);
	dfs3(n-1);
	
	v=pat[n-1]; p=pat[v];
	int k=c/2;
	while(p!=-1 && k){
		memo[v]=5;
		int aux=p;
		p=pat[p];
		v=aux;
		k--;
	}
		
	FOR(i,0,n){
		if(memo[i]==5) dfs4(i);
		else if(memo[i]==7) dfs5(i);
	}
	
	FOR(i,0,n){
		if(memo[i]==2 || memo[i]==7) c1++;
		else if(memo[i]==3 || memo[i]==5) c2++;
	}

	if(c1>c2) printf("Fennec\n");
	else printf("Snuke\n");
	
}


Measured memory_bytes: 23680
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define mod 1000000007
int dp[100005];
int vis[100005];
vector<int> v[100005];
int dfs(int ver)
{
	vis[ver]=1;
	for(int i=0;i<v[ver].size();i++)
	{
		if(vis[v[ver][i]]==0)
			dfs(v[ver][i]);
dp[ver]=max(dp[ver],dp[v[ver][i]]+1);
	}
	return dp[ver];
}


 
int main()
{
	ll n,m;
	cin>>n>>m;
	for(int i=0;i<m;i++)
	{
		int a,b;
		cin>>a>>b;
		v[a].push_back(b);
		
	}
	for(int i=1;i<=n;i++)
	{
		if(vis[i]==0)
			dfs(i);

	}
	cout<<*max_element(dp,dp+100005)<<endl;
	/*for(int i=1;i<=n;i++)
		cout<<dp[i]<<" ";
	*/

	
	
	
	
	
 
	return 0;
}

Measured memory_bytes: 8576
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)n; i++)
using ll = long long;
const int INF = 1e9;
double temp_start = 3000.0;
double temp_end = 10; 
int climb_loop = 11000000;
double temp;

int main(){
  int seed = 12345;
  mt19937 eng(seed);
  uniform_real_distribution<> uniform_01;

  // input
  int D;
  cin >> D;
  int c[26];
  rep(i,26) cin >> c[i];
  int s[D+1][26];
  rep(i,D) rep(j,26) cin >> s[i+1][j];
  
  // define parameter
  int last[D+1][26];
  int t[D+1];
  rep(i,D+1) rep(j,26) last[i][j] = 0;
  
  // calculate initial content climbing
  int content = 0;
  for(int day = 1; day <= D; day++) {
    int content_after = -INF;
    int best_kind = 0;
    rep(kind,26) {
      int res = content + s[day][kind];
      rep(j,26) {
        if(j == kind) last[day][j] = day;
        else last[day][j] = last[day-1][j];
        res -= c[j] * (day - last[day][j]);
      }
      if(res > content_after) {
        best_kind = kind;
        content_after = res;
      }
    }
    t[day] = best_kind;
    content = content_after;
    rep(j,26) {
      if(j == t[day]) last[day][j] = day;
      else last[day][j] = last[day-1][j];
    }
  }
   
  // simulated annealing
  rep(x,climb_loop) {
    int d = (eng() % D) + 1;
    int q = eng() % 26;
    if(q != t[d]) {
      temp = temp_start + (temp_end - temp_start)*x/climb_loop;
      int diff = s[d][q] - s[d][t[d]];
      int cur = d;
      while(cur <= D && last[cur][t[d]] == d) {
        diff -= c[t[d]] * (d - last[cur-1][t[d]]);
        last[cur][t[d]] = last[cur-1][t[d]];
        cur++;
      }
      cur = d;
      while(cur <= D && last[cur][q] < d) {
        diff += c[q] * (d - last[cur][q]);
        last[cur][q] = d;
        cur++;
      }
      if(diff > 0 || uniform_01(eng) < exp((double)diff/temp)) {
        t[d] = q;
        content += diff;
      } else {
        int day = d;
        while(day <= D && last[day][t[d]] < d) {
          last[day][t[d]] = d;
          day++;
        }
        day = d;
        while(day <= D && last[day][q] == d) {
          last[day][q] = last[day-1][q];
          day++;
        }
      }
    }
  }
  // output
  for(int day = 1; day <= D; day++) cout << t[day]+1 << endl;
  return 0;
}


Measured memory_bytes: 4336
import static java.lang.Integer.parseInt;
import static java.lang.Long.parseLong;
import static java.lang.Math.max;
import static java.lang.System.exit;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {

	static void solve() throws Exception {
		String s = scanString();
		int n = s.length() + 1;
		int res[] = new int[n];
		for (int i = 1; i < n; i++) {
			if (s.charAt(i - 1) == '<') {
				res[i] = res[i - 1] + 1;
			}
		}
		for (int i = n - 2; i >= 0; i--) {
			if (s.charAt(i) == '>') {
				res[i] = max(res[i], res[i + 1] + 1);
			}
		}
		long ans = 0;
		for (int i = 0; i < n; i++) {
			ans += res[i];
		}
		out.print(ans);
	}

	static int scanInt() throws IOException {
		return parseInt(scanString());
	}

	static long scanLong() throws IOException {
		return parseLong(scanString());
	}

	static String scanString() throws IOException {
		while (tok == null || !tok.hasMoreTokens()) {
			tok = new StringTokenizer(in.readLine());
		}
		return tok.nextToken();
	}

	static BufferedReader in;
	static PrintWriter out;
	static StringTokenizer tok;

	public static void main(String[] args) {
		try {
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);
			solve();
			in.close();
			out.close();
		} catch (Throwable e) {
			e.printStackTrace();
			exit(1);
		}
	}
}

Measured memory_bytes: 27924
import math
n = int(input())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
xy = []
for i in range(n):
    xy.append(abs(x[i] - y[i]))
D = [0, 0, 0, 0]
D[0] = sum(xy)
D2 = 0
for xyi in xy:
    D2 += xyi ** 2
D[1] = math.sqrt(D2)
D3 = 0
for xyi in xy:
    D3 += xyi ** 3
D[2] = math.pow(D3, 1.0/3.0)
D[3] = max(xy)
for d in D:
    print(d)


Measured memory_bytes: 5696
while True:
    try:
        n=int(input())
        ans=0
        for a in range(0,10):
            for b in range(0,10):
                for c in range(0,10):
                    if 0<=(n-(a+b+c))<=9:
                        ans+=1
        print(ans)
    except:
        break


Measured memory_bytes: 5592
#include<iostream>

int main() {
	int vals[101] = { 0 }, val;
	while (std::cin >> val) {
		vals[val] += 1;
	}
	int max = 0;
	for (int i = 1; i <= 100; ++i) {
		if (max < vals[i]) {
			max = vals[i];
		}
	}
	for (int i = 1; i <= 100; ++i) {
		if (vals[i] == max) std::cout << i << std::endl;
	}
	return 0;
}


Measured memory_bytes: 3052
#include<bits/stdc++.h>
using namespace std;
#define pi pair<ll,ll>
#define fr freopen("in.txt","r",stdin)
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define frep(i,n) for(int i=1;i<=n;i++)
#define ll long long
#define f first
#define s second
#define maxn 50
const ll mod = 1e9+7;
int A[100];
int main() {
   int N;
   cin >> N;
   rep(i,N) {
	cin >> A[i];
   }
   vector<pi>ans;
   int ind = 0;
   rep(i,N) {
   	if(abs(A[i])>abs(A[ind])) ind = i;
   }
   if(A[ind]<0) {
   	rep(i,N) {
   		if(A[i]>0) {
   			A[i]+=A[ind];
   			ans.pb({ind,i});
   		}
   	}
   	for(int i=N-1;i>0;i--) {
   		ans.pb({i,i-1});
   	}
   	
   } else{
   	rep(i,N) {
   		if(A[i]<0) {
   			A[i]+=A[ind];
   			ans.pb({ind,i});
   		}
   	}
   	for(int i=1;i<N;i++) {
   		ans.pb({i-1,i});
   	}
   	
   }
	
   cout << ans.size() << "\n";
   for(auto x:ans) {
   	cout << x.f+1 << " " << x.s+1 << "\n";
   }
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] x = new int[N];

        int i = 0;
		while(i < N) {
			x[i] = sc.nextInt();
			i++;
		}

		int min = 101;
		int max = -1;
		for(int j = 0; j < N ; j++) {
			if(x[j] <min) {
				min = x[j];
			}
			if(x[j] >max) {
				max = x[j];
			}
		}

		int minPower=0;

		for(i = min; i <= max; i++) {
			int power = 0;
			for(int j = 0; j < N ; j++) {
				power += (i-x[j])*(i-x[j]);
			}
			if(i == min || (i != min && minPower > power)) {
				minPower = power;
			}
		}

		System.out.println(minPower);
	}

}


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


int main() {
 int N ;
 cin >> N;
 int result ;
 int test = N;
 while (true){
     bool e =true;
     for (int i = 2; i< test/2 ;i++) {
         if (test% i ==0){
             e = false;
         }
     }
    if (e) {
        result =  test;
        break;
    }
    else {
        test++;
    }
 }
 cout << result;
}


Measured memory_bytes: 256
//region #include <cp_helper>
#include <algorithm>
#include <array>
#include <bitset>
#include <cstring>
#include <cmath>
#include <climits>
#include <deque>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <array>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define io() ios_base::sync_with_stdio(false); cin.tie(nullptr)
#define ll long long
#define ull unsigned long long
#define ii pair<int, int>
#define vi vector<int>
#define vvi vector<vi>
#define vll vector<ll>
#define vii vector<ii>
#define all(a) a.begin(), a.end()
#define qsort(a) sort(all(a))
#define qsortd(a) sort(all(a), greater<>())
#define qsortf(a, f) sort(all(a), f)
#define pb(n) push_back(n)
#define eb(n) emplace_back(n)
#define pp(a, b) emplace_back(make_pair(a, b))
#define fori(i, n) for (ll i=0; i<n; ++i)
#define foris(i, a, b) for (ll i=a; i<b; ++i)
#define ford(i, n) for (ll i=n; i>=0; --i)
#define fords(i, a, b) for (ll i=a; i>=b; --i)
#define forr(i, a) for (auto &i : a)
#define umap unordered_map
#define nl '\n'
#define fileio(in, out) freopen("in", "r", stdin); freopen("out", "w", stdout)
const int mod = 1000000007;
//endregion

int n, m, w[10] = {0,2,5,5,4,5,6,3,7,6}, a;
vi d, temp, dp[10005];

bool comp(vi aa, vi bb) {
    if (aa == bb) return true;
    if (aa.size() < bb.size()) return true;
    if (aa.size() > bb.size()) return false;
    ford (i, aa.size()-1) {
        if (aa[i] < bb[i]) return true;
        if (aa[i] > bb[i]) return false;
    }
    return true;
}

int main() {
    io();
    cin >> n >> m;
    fori (i, m) {
        cin >> a;
        d.eb(a);
        if (w[a] <= n) dp[w[a]] = max(dp[w[a]], {a}, comp);
    }

    fori (i, n) {
        if (dp[i].empty()) continue;
        fori (j, m) {
            temp = dp[i];
            temp.eb(d[j]);
            if (i + w[d[j]] <= n) dp[i+w[d[j]]] = max(dp[i+w[d[j]]], temp, comp);
        }
    }
    reverse(all(dp[n]));
    forr (i, dp[n]) cout << i;
}

Measured memory_bytes: 141312
#include <iostream>
using namespace std;
int main() {
	int a,b;
	cin >> a ;
	cin >>b;
	int tmp = 0;
	if (a < b) {
		tmp = b;
		b--;
	} else {
		tmp = a;
		a--;
	}
	if (a < b) {
		tmp += b;
	} else {
		tmp += a;
	}
	cout <<tmp <<endl;
	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
    public double getProbability(int index, int heads, double[] prob, Double[][] memo) {
       //System.out.println(String.format("<%d,%d>", index, heads));
       int n = prob.length;
       if (index == prob.length && heads <= n/2) {
           return 1.0;
       }
       if (index == n) {
           return 0.0;
       }
       if (memo[index][heads] != null) {
           return memo[index][heads];
       }
       double res = 0.0;
       res += getProbability(index + 1, heads - 1, prob, memo) * prob[index];
       res += getProbability(index + 1, heads, prob, memo) * (1 - prob[index]);
       return memo[index][heads] = res;
    }
    public static void main(String[] args)  {
        try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
            br.readLine();
            String[] split = br.readLine().split(" ");
            int n = split.length;
            int target = n/2 + 1;
            double[] prob = new double[n];
            for (int i = 0; i < n; i++) {
               prob[i] = Double.parseDouble(split[i]); 
            }
            Double[][] memo = new Double[n][n + 1];
          	Main app = new Main();
            double result = app.getProbability(0, n, prob, memo);
            /*for(Double[] row: memo) {
                for (Double d: row) {
                    System.out.print(String.format("%.2f ", d == null ? 0.0 : d));
                }
                System.out.println();
            }*/
            System.out.println(result);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}


Measured memory_bytes: 228720
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
def main():
	while True:		
		try:
			a, b = [int(x) for x in input().split(" ")]
		except:
			return
		else:
			print(gcd(a, b),lcm(a, b))
def lcm(a, b):
	return (a * b) // gcd(a,b)
def gcd(a, b):
	while b != 0:
		a, b = b, a % b
	return a	
			
if __name__ == '__main__':
  main()

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

struct Card{char suit,value;};

bool isStable(Card bubble[],Card selection[],int N){
    for(int i = 0; i < N; i++){
        if(bubble[i].suit != selection[i].suit) return false;
    }
    return true;
}

void bubbleSort(Card A[], int N){
    bool flg = true;
    for(int i = 0; flg; i++){
        flg = false;
        for(int j = N-1; j > i; j--){
            if(A[j].value < A[j-1].value) {
                swap(A[j],A[j-1]);
                flg = true;
            }
        }
    }
}

void selectionSort(Card A[], int N){
    for(int i = 0; i < N - 1; i++){
        int minj = i;
        for(int j = i + 1; j < N; j++){
            if(A[j].value < A[minj].value) minj = j;
        }
        if(minj != i) swap(A[i],A[minj]);
    }
}

void print(Card C[], int N){
    for(int i = 0; i < N; i++){
        if(i) cout << " ";
        cout << C[i].suit << C[i].value;
    }
    cout << endl;
}

int main(){
    Card C1[36],C2[36];
    int N;

    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> C1[i].suit >> C1[i].value;
        C2[i] = C1[i];
    }

    bubbleSort(C1,N);
    selectionSort(C2,N);

    print(C1,N);
    cout << "Stable" << endl;

    print(C2,N);
    cout << (isStable(C1,C2,N)? "Stable": "Not stable") << endl;

    return 0;
}


Measured memory_bytes: 3096
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  int x, t;
  cin >> x >> t;
  cout << max(0, x - t) << endl;
}


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


int main(){

    int a,b,c,x,p;
    deque <int>  deq;
    deque <int>:: iterator it;
     scanf("%d ",&a);
    for(int k=0;k<a;k++){
    scanf("%d",&b);
    if (b==0){
            scanf("%d",&c);
            if(c==0)

            {
                scanf("%d",&x);
            
                deq.push_front(x);
            }
            else if(c==1){
                scanf("%d",&x);
                deq.push_back(x);
            }

            }
    else if (b==1 && !deq.empty()){
             scanf("%d",&p);
            cout<<deq.at(p)<<endl;
    }

    else if (b==2 && !deq.empty()){
            scanf("%d",&c);
            if(c==0)
            {
                deq.pop_front();
            }
            else if(c==1){
                deq.pop_back();
            }

    }




    }


    return 0;



}



Measured memory_bytes: 4744
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <limits.h>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>

typedef unsigned long long ULLONG;
typedef long long LLONG;

template <class _T> static _T tp_abs(const _T& a) {
	return ((a < 0) ? (a * -1) : a);
}
template <class _T> static _T tp_min(_T a, _T b) {
	return a < b ? a : b;
}
template <class _T> static _T tp_max(_T a, _T b) {
	return a > b ? a : b;
}
template<class _T> static void get1int(_T& a) {
	const char* fmt = " %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld";
	}

	if (scanf(fmt, &a) < 0) {
		printf("g1int Error\n");
	}
}
template<class _T> static void get2int(_T& a, _T& b) {
	const char* fmt = " %d %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld %lld";
	}

	if (scanf(fmt, &a, &b) < 0) {
		printf("g2int Error\n");
	}
}
template<class _T> static void get3int(_T& a, _T& b, _T& c) {
	const char* fmt = " %d %d %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld %lld %lld";
	}

	if (scanf(fmt, &a, &b, &c) < 0) {
		printf("g3int Error\n");
	}
}
static void getstring(char* buff) {
	if (scanf(" %s", buff) < 0) {
		printf("getstr error!\n");
	}
}

static const long long MOD_NUM = 1000000007LL;

static void D_task();

int main()
{
	D_task();
	fflush(stdout);
	return 0;
}

class D_edge {
public:
	int to = 0;
	int eNo = 0;
};

static void D_task()
{
	int N;
	get1int(N);

	std::vector<std::vector<D_edge>> graph(N);

	for (int i = 0; i < N - 1; i++) {
		int a, b;
		get2int(a, b); a--; b--;
		D_edge e;
		e.eNo = i;
		e.to = b;
		graph[a].push_back(e);
		e.to = a;
		graph[b].push_back(e);
	}

	int colorCnt = 0;
	for (int i = 0; i < N; i++) {
		colorCnt = tp_max(colorCnt, (int)graph[i].size());
	}

	std::vector<int> eColor(N - 1, 0);
	for (int i = 0; i < N; i++) {
		std::set<int> used;
		
		int eCnt = graph[i].size();
		int color = 1;
		for (int e = 0; e < eCnt; e++) {
			int eNo = graph[i][e].eNo;
			if (eColor[eNo] != 0) {
				used.insert(eColor[eNo]);
			}
		}

		for (int e = 0; e < eCnt; e++) {
			int eNo = graph[i][e].eNo;
			if (eColor[eNo] == 0) {
				while (used.find(color) != used.end()) {
					color++;
				}
				eColor[eNo] = color;
				used.insert(color);
			}
		}
//		used.clear();
	}
	
	printf("%d\n", colorCnt);
	for (int i = 0; i < N - 1; i++) {
		printf("%d\n", eColor[i]);
	}
}


Measured memory_bytes: 6912
#include <bits/stdc++.h>
/* Karen {{{
  ___  ____
 |_  ||_  _|
   | |_/ /    ,--.   _ .--.  .---.  _ .--.
   |  __'.   `'_\ : [ `/'`\]/ /__\\[ `.-. |
  _| |  \ \_ // | |, | |    | \__., | | | |
 |____||____|\'-;__/[___]    '.__.'[___||__]
}}} */
/* cpp template {{{*/
using namespace std;
 
#define endl '\n'
 
#define REP(i, n) for (int i = 0; i < (n); i++)
#define REPS(i, a, n) for (int i = (a); i < (n); i++)
#define RREP(i, n) for (int i = 1; i <= (n); i++)
#define EQ(n,m) (abs((n)-(m)) < EPS)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ALL(v) v.begin(), v.end()
 
typedef double D;
typedef long long ll;
typedef long double lb;
typedef complex<D> P;
typedef vector<P> VP;
typedef vector<int> vi;
typedef vector<vector<int> > vii;
typedef pair<int, int> pii;
typedef pair<int, string> pis;
typedef pair<string, int> psi;
 
inline bool inside(int y,int x,int H,int W){return(y>=0&&x>=0&&y<H&&x<W);}
inline int in() {int x; std::cin >> x; return x;}
 
template <typename T>
void print(std::vector<T>& v, char c = ' ') {
  REP(i, v.size()) {
    if (i != 0) std::cout << c;
    std::cout << v[i];
  }
  std::cout << endl;
}
template <typename T>
void print(T x) {
  std::cout << x << '\n';
}
/* }}} */
/* 定数 {{{*/
const ll MOD = 1e9 + 7;
const ll INF = 1e9 + 9;
const D EPS  = 1e-9;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1};
const int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
/* }}} */
 
#define int long long
signed main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
 
  int n = in();
 
  int t = in(), a = in();
  
  REP(i, n - 1){
    int T = in(), A = in();
    int uyu = max(t / T, a / A);
    for (int j = uyu; ; j++){
      if (t <= T * j && a <= A * j){
        t = T * j;
        a = A * j;
        break;
      }
    }
  }
 
  cout << t + a << endl;
}


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

using namespace std;

#define lli long long int
#define REP(i,s,n) for(lli i=s;i<n;i++)
#define RREP(i,s,n) for(lli i=s;i>=n;i--)
#define MOD 1000000007
#define NUM 2520
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define INF (1LL<<50)

signed main(){

	vector<lli> v[26];
	string s;
	cin>>s;

	REP(i,0,s.size()){
		lli now = s.at(i)-'a';
		v[now].push_back(i);
	}

	string t;
	cin>>t;
	lli ans = 0;
	lli size = s.size();

	REP(i,0,t.size()){
		if(DEBUG)cout<<"ans="<<ans<<endl;
		lli now = t.at(i)-'a';
		auto itr = lower_bound(v[now].begin(),v[now].end(),ans%size);
		if(itr!=v[now].end()){
			lli base = (ans/size)*size;
			ans = base+(*itr)+1;
			continue;
		}
		lli base = ans/size;
		ans = (base+1)*size;
		itr = lower_bound(v[now].begin(),v[now].end(),ans%size);
		if(itr==v[now].end()){
			cout<<-1<<endl;
			return 0;
		}
		ans += ((*itr)+1);
	}
	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 1536
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
typedef int64_t int64;
typedef uint32_t uint;
typedef uint64_t uint64;
using namespace std;

//---

template <typename T>
inline void print(const T& rhs){ std::cout<<" = "<<rhs<<std::endl; }
template <typename T>
inline void print(const std::vector<T>& rhs){
    std::cout<<" = [ ";
    for(uint i=0; i<rhs.size(); ++i){ std::cout<<rhs[i]<<' '; }
    std::cout<<"]"<<std::endl;
}
template <typename T>
inline void print(const std::vector<std::vector<T>>& rhs){
    std::cout<<" = "<<std::endl;
    std::cout<<"[[ ";
    for(uint p=0; p<rhs.size(); ++p){
        if(p!=0){ std::cout<<" [ "; }
        for(uint q=0; q<rhs[p].size(); ++q){
            std::cout<<rhs[p][q]<<' ';
        }
        if(p!=rhs.size()-1){ std::cout<<"]"<<std::endl; }
    }
    std::cout<<"]]"<<std::endl;
}
template <typename TL, typename TR>
inline void print(const std::vector<std::pair<TR,TL>>& rhs){
    std::cout<<" = [";
    uint i=0;
    for(; i<rhs.size()-1; ++i){ std::cout<<"[f: "<<rhs[i].first<<", s: "<<rhs[i].second<<"], "; }
    std::cout<<"[f: "<<rhs[i].first<<", s: "<<rhs[i].second<<"]]" << endl;
}
#define printn(var) {printf("%s", #var);print(var);}
#define printn_all(var) {printf("%s(%d): ", __func__, __LINE__);printf("%s", #var);print(var);}

//---

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int a, b; cin >> a >> b;
    int cnt=a-1;
    if(b >= a){ ++cnt; }
    cout << cnt << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
#define rep(i,n) for(int long long i=0;i<n;i++)
typedef int long long ll;
using namespace std;
int main(){
    string s,t;
    cin>>s>>t;
    if(s.size()<t.size()){
         cout<<"UNRESTORABLE"<<endl;
        return 0;
    }
    
  


    
    
    int ans=-1;
    rep(i,s.size()-t.size()+1){
        string ss=s.substr(i,t.size());
        int flag=0;
        //cout<<ss<<endl;
        
        for(int j=0;j<t.size();j++){
            if(ss[j]!='?'&&ss[j]!=t[j]){
                flag=1;
                break;
            }
        }
        
        if(flag==0){
            ans=i;
        }
        
        
    }
    
    
    
    if(ans!=-1){
        int i=ans;
        s.replace(i,t.size(),t);
        rep(j,s.size()){
            if(s[j]=='?'){
                s[j]='a';
            }
        }
            
                cout<<s<<endl;
                return 0;
            }
        
    
    
        cout<<"UNRESTORABLE"<<endl;
    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++)
using ll = long long;

int main() {
    int n;
    cin >> n;
    vector<int> count(100001);
    ll ans=0;
    rep(i,n){
        int k;
        cin >> k;
        ans+=k;
        count[k]++;
    }
    int q;
    cin >> q;
    rep(i,q){
        int x,y;
        cin >> x >> y;
        ans+=count[x]*(y-x);
        count[y]+=count[x];
        count[x]=0;
        cout << ans << endl;
    }

}

Measured memory_bytes: 3712
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio> 
#include <cstring>

#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rangeRep(i, n, m) for(int (i) = (n); (i) < (m); (i)++)
struct Student {
	int t, n, m, s;
};

constexpr int timeOffset = 540;
//[PC][time] = Student
int dp[1000][1260 - timeOffset] = { 0 };


class Solve {
public:
	Solve() {};
	~Solve() {};

	void solver() {
		std::vector<std::vector<int>> results;
		while (1) {
			int n, m, r, q;
			std::vector<Student> students;
			std::cin >> n >> m;
			if (!n) break;

			std::memset(dp, 0, sizeof(dp));
			results.push_back(std::vector<int>());
			//login info
			std::cin >> r;
			Student s;
			rep(i, r) {
				//time, PC, student, isLogin
				std::cin >> s.t >> s.n >> s.m >> s.s;
				//login
				if (s.s) {
					//set login start time
					dp[s.n - 1][s.t - timeOffset] = s.m;
				}//logout
				else {
					//Fill until login start time
					int time = s.t - timeOffset - 1;
					while (dp[s.n - 1][time] == 0) {
						dp[s.n - 1][time--] = s.m;
					} 
				}
			}

			//question [ts, te]
			std::cin >> q;
			rep(i, q) {
				int num = 0;
				int ts, te, m;
				std::cin >> ts >> te >> m;
				ts -= timeOffset; te -= timeOffset;
				//Check if logged in on any PC.
				rangeRep(j, ts, te) {
					rep(k, n) {
						if (dp[k][j] == m) {
							num++;
							break;
						}
					}
				}
				results.back().push_back(num);
			}
		}

		for (auto& x : results) {
			for (auto& y : x) {
				std::cout << y << std::endl;
			}
		}
	}
private:

};

int main() {
	Solve solve;
	solve.solver();
	return 0;
}

Measured memory_bytes: 5872
#include<stdio.h>

int main(void)
{
	int house[5][4][11], n, b, f, r, v, i, j, k;

	for(i=1; i<5; i++)
	{
		for(j=1; j<4; j++)
		{
			for(k=1; k<11; k++)
			{
				house[i][j][k] = 0;
			}
		}
	}

	scanf("%d", &n);

	for(i=0; i<n; i++)
	{
		scanf("%d %d %d %d", &b, &f, &r, &v);
		house[b][f][r] += v;
	}

	for(i=1; i<5; i++)
	{
		for(j=1; j<4; j++)
		{
			for(k=1; k<11; k++)
				printf(" %d", house[i][j][k]);
			printf("\n");
		}
		if(i != 4)
			printf("####################\n");
	}

	return 0;
}



Measured memory_bytes: 2052
W, H, N = map(int, input().split())
x = [0 for i in range(N)]
y = [0 for i in range(N)]
a = [0 for i in range(N)]
for i in range(N):
    x[i], y[i], a[i] = map(int, input().split())
xmin = 0
xmax = W
ymin = 0
ymax = H

for i in range(N):
    if a[i] == 1 and x[i] >= xmin:
        xmin = x[i]
    elif a[i] == 2 and x[i] <= xmax:
        xmax = x[i]
    elif a[i] == 3 and y[i] >= ymin:
        ymin = y[i]
    elif a[i] == 4 and y[i] <= ymax:
        ymax = y[i]
        
if xmax >= xmin and ymax >= ymin:
    print((xmax-xmin)*(ymax-ymin))
else:
    print(0)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
 
using namespace std;
 
char s[20];
int x,y;
 
int main() {
    cin >> s;
 
    if (s[0] != 'A') {
        cout << "WA"<< endl;
        return 0;
    }
    if(s[1] == 'C' || s[1] < 95) {
        cout << "WA"<< endl;
        return 0;
    }
    if (s[strlen(s)-1] < 95) {
        cout << "WA"<<endl;
        return 0;
    }
    for (x=2 ; x <strlen(s)-1 ; x++) {
        if (s[x] == 'C') {
            if (y != 0) {
                cout << "WA"<<endl;
                return 0;
            }
            y++;
        }
        if (s[x] < 60) {
            cout << "WA"<<endl;
            return 0;
        }
    }
    if (y == 0) {
        cout << "WA" <<endl;
        return 0;
    }
    cout << "AC" << endl;
 
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cerr<<*i<<" "; cerr<<endl; }
inline bool valid(int x, int y, int W, int H){ return (x >= 0 && y >= 0 && x < W && y < H); }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
int tonum(string s){
  stringstream ss(s);
  int n;
  ss >> n;
  return n;
}
string tostr(int n, int L){
  stringstream ss;;
  ss << n;
  string s;
  ss >> s;
  while(s.size() < L) s = "0" + s;
  return s;
}
int main(){
  int a, L;
  while(cin >> a >> L && !(a == 0 && L == 0)){
    map<int, int> dict;
    int cur = 1;
    while(true){
      if(dict[a] != 0){
        int dif = cur - dict[a];
        printf("%d %d %d\n", dict[a] - 1, a, dif);
        break;
      }
      dict[a] = cur++;
      string big = tostr(a, L);
      string small = tostr(a, L);
      sort(big.begin(), big.end());
      sort(small.begin(), small.end());
      reverse(big.begin(), big.end());
      a = tonum(big) - tonum(small);
    }
  }
  return 0;
}

Measured memory_bytes: 1272
#include <cstring>
#include <iostream>
#include <vector>
#include <queue>
#include <set>

using namespace std;

// vector
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 << "\t";
  }
  return s;
}
// 2 dimentional vector
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] << endl;
  }
  return s;
}

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }


const int M = 100001;

vector<int> graph[M];
int par[M];
int visit[M];
int out[M]; // 出て行く辺の本数
vector<int> order; // 親子の順
set<ll> dir;

void bfs(int start) {
  queue<int> remain;
  remain.push(start);
  visit[start] = 1;
  while (remain.size() > 0) {
    ll from = remain.front(); remain.pop();
    order.push_back(from);
    for (ll to: graph[from]) {
      if (visit[to] != 0) {
        if (par[from] == to) continue;
        if (dir.find(to*M+from) != dir.end()) continue;
        dir.insert(from*M+to);
        out[from] += 1;
        continue;
      }
      remain.push(to);
      par[to] = from;
      visit[to] = 1;
    }
  }
}

int main() {
  memset(par, 0, sizeof(par));
  memset(visit, 0, sizeof(visit));
  memset(out, 0, sizeof(out));

  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    int from, to;
    cin >> from >> to;
    graph[from].push_back(to);
    graph[to].push_back(from);
  }
  if (m % 2 == 1) {
    cout << -1 << endl;
    return 0;
  }
  bfs(1);
  for (int i = n-1; i > 0; --i) {
    ll v = order[i];
    ll p = par[v];
    if (out[v] % 2 == 0) {
      dir.insert(p*M+v);
      out[p] += 1;
    }
    else {
      dir.insert(v*M+p);
      out[v] += 1;
    }
  }
  // cout << order << endl;
  // for (int i = 1; i <= m; ++i) {
  //   cout << par[i] << " " << visit[i] << " " << out[i] << " " << order[i] << endl;
  // }
  for (ll e : dir) {
    cout << (int)(e / M) << " " << (int)(e % M) << endl;
  }
}


Measured memory_bytes: 13184
#include <bits/stdc++.h>
using ll = long long;
using ld = long double;
#define F first
#define S second
const ll mod = 1e9 + 7;
const ll INF = 922337203685477;
#define pb push_back
#define deb(x) cout << '>' << #x << ':' << x << endl;
#define fastio ios_base::sync_with_stdio(false); cin.tie(0);
#define maxN 200007
using namespace std;
int main() {
  fastio;
  ll n = 0;
  cin >> n;
  ll curr_max = 0;
  ll ar[n];
  for (ll i = 0; i < n; ++i)
    cin >> ar[i];
  ll ans = 0;
  for (ll i = 0; i < n; ++i) {
    curr_max = max(curr_max, ar[i]);
    ans += (curr_max - ar[i]);
  }
  cout << ans;
}

Measured memory_bytes: 5164
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define pb push_back
const int maxn=2e5+10;
const int mod=1e9+7;
int n,k;
ll a[maxn];

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>n>>k;
    vector<ll>fu;
    vector<ll>zh;
    int zero=0;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        if(a[i]<0)
            fu.pb(a[i]);
        else if(a[i]>0)
            zh.pb(a[i]);
        else
            zero++;
    }
    if(n==k)
    {
        ll ans=1;
        for(int i=1;i<=n;i++)
        {
            ans*=a[i];
            ans%=mod;
            ans=(ans+mod)%mod;
        }
        cout<<ans<<'\n';
        return 0;
    }
    ll ans=1;
    int lenz=zh.size();
    int lenf=fu.size();
    if(lenf>0)
    sort(fu.begin(),fu.end());
    if(lenz>0)
    sort(zh.begin(),zh.end(),greater<ll>());

    if(k%2)
    {
        if(lenz>0)
        {
            ans=zh[0];
            int l=0,r=1;
            int cnt=0;
            while(cnt<k-1)
            {
                ll temp1=0;
                if(l+1<=lenf-1)
                {
                    temp1=fu[l]*fu[l+1];
                }
                ll temp2=0;
                if(r+1<=lenz-1)
                {
                    temp2=zh[r]*zh[r+1];
                }
                if(temp1>temp2)
                {
                    ans*=temp1%mod;
                    ans%=mod;
                    l+=2;
                }
                else
                {
                    ans*=temp2%mod;
                    ans%=mod;
                    r+=2;
                }
                cnt+=2;

            }
            cout<<ans<<'\n';
        }
        else
        {
            if(zero)
                cout<<0<<'\n';
            else
            {
                sort(fu.begin(),fu.end(),greater<ll>());
                for(int i=0;i<k;i++)
                {
                    ans*=fu[i];
                    ans%=mod;
                    ans=(ans+mod)%mod;
                }
                cout<<(ans+mod)%mod<<'\n';
            }
        }
    }
    else
    {

            int l=0,r=0;
            int cnt=0;
            while(cnt<k)
            {
                ll temp1=0;
                if(l+1<=lenf-1)
                {
                    temp1=fu[l]*fu[l+1];
                }
                ll temp2=0;
                if(r+1<=lenz-1)
                {
                    temp2=zh[r]*zh[r+1];
                }
                if(temp1>temp2)
                {
                    ans*=temp1%mod;
                    ans%=mod;
                    l+=2;
                }
                else
                {
                    ans*=temp2%mod;
                    ans%=mod;
                    r+=2;
                }
                cnt+=2;

            }
            cout<<ans<<'\n';
    }







}


Measured memory_bytes: 6676
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
struct UnionFind {
    vector<int> par;
    UnionFind(int n) : par(n, -1) {}
    int find(int x) {
        if (par[x] < 0) return x;
        return par[x] = find(par[x]);
    }
    void unite(int x, int y) {
        x = find(x), y = find(y);
        if (x == y) return;
        if (par[x] > par[y]) swap(x, y);
        par[x] += par[y];
        par[y] = x;
    }
};
int main()
{
    cin.tie(nullptr); ios::sync_with_stdio(false);
    int N, M; cin >> N >> M;
    vector<int> A(N); for (auto &a : A) cin >> a;
    UnionFind uf(N);
    for (int i = 0; i < M; i++) {
        int x, y; cin >> x >> y;
        uf.unite(x, y);
    }
    set<int> S;
    for (int i = 0; i < N; i++) {
        S.insert(uf.find(i));
    }
    if (S.size() == 1) {
        cout << 0 << '\n';
        return 0;
    }
    vector<pair<int, int>> B;
    for (int i = 0; i < N; i++) {
        B.emplace_back(A[i], uf.find(i));
    }
    sort(begin(B), end(B));
    set<int> T;
    Int ans = 0, cnt = S.size() - 2;
    for (int i = 0; i < N; i++) {
        if (!T.count(B[i].second)) {
            ans += B[i].first;
            T.insert(B[i].second);
        } else if (cnt) {
            ans += B[i].first;
            cnt--;
        }
    }
    if (cnt) {
        cout << "Impossible\n";
    } else {
        cout << ans << '\n';
    }
    return 0;
}

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

#define rep(i, n) for(int i=0; i < (int)n; i++)

using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;

int main(void) {
  int n, b, f, r, v, residents[4][3][10]={0};

  cin >> n;

  rep(_, n) {
    cin >> b >> f >> r >> v;
    residents[b-1][f-1][r-1] += v;
  }

  int cnt = 0;
  for(auto &x : residents) {
    if(cnt++ % 4 != 0) cout << "####################" << endl;
    for(auto &y : x) {
      for(auto z : y) {
        cout << ' ' << z;
      }
      cout << endl;
    }
  }
}



Measured memory_bytes: 3088
#include<iostream>

int main()
{   
    int x,y,tmp;

    for(;;){
        std::cin >> x >> y;

        if ((x==0)&&(y==0))break;

        if (x>y){
            tmp = y ;
            y = x;
            x=tmp;
        }

        std::cout << x << " " << y << std::endl;
        
    }

    return 0;
}


Measured memory_bytes: 3000
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    a, b = input().split()
    c, d = int(a), int(b[0] + b[-2:])

    print(c * d // 100)


if __name__ == '__main__':
    main()


Measured memory_bytes: 61784