akhauriyash/Code-Regression huggingface dataset:
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {
	public static void main(String args[]) {
		FastScanner scanner = new FastScanner();
		int n=scanner.nextInt();
		
		System.out.println(n*n*n);
	}
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}


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

using namespace std;
#define IOS ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define ll long long
#define ld long double
#define endl "\n"

int main()
{
	IOS;
	ll n;
	cin >>n;
	ll ans=0;
	if(n%2!=0)
		cout <<ans<<endl;
	else
	{
		ll d=10;
		while(d<=n)
		{
			ans+=n/d;
			d*=5;
			//cout <<ans<<' ';
		}
		//cout <<endl;
		cout <<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{

    int n=1,i; int x[10000];
    for(i=0;i<10000;i++)
    {
        scanf("%d",&x[i]);
        if (x[i]==0) break;
    }

    for (i=0;i<10000;i++)
    {
        if (x[i]==0) break;
        printf("Case %d: %d\n",n++,x[i]);
    }

}



Measured memory_bytes: 2652
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <numeric>
#include <set>
#include <unordered_set>
#include <queue>
#include <cmath>
#include <bitset>

using namespace std;
#define ll long long
#define rep(i, n) for(int i = 0;i < n;i++)
#define FOR(i, n, m) for(int i=n; i<m; ++i)

using Graph = vector<vector<int>>;

// 深さ優先探索
vector<bool> seen;
void dfs(const Graph &G, int v) {
    seen[v] = true; // v を訪問済にする

    // v から行ける各頂点 next_v について
    for (auto next_v : G[v]) { 
        if (seen[next_v]) continue; // next_v が探索済だったらスルー
        dfs(G, next_v); // 再帰的に探索
    }
}

bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}

// a と b の最大公約数を返す関数
ll GCD(ll a, ll b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}

int main() {
  ll N;
  cin >> N;
  
  ll count = 0;
  
  ll p[1000010]={};
  
  FOR(i,1,1000010){
      for(int j=i; j<1000010; j+=i){
        p[j]++;
      }
  }
  
  ll rp[1000010]={};
  rp[0]=0;
  rep(i,1000009){
    rp[i+1]=rp[i]+p[i];
  }
  
  /*rep(i,N+1){
    cout << rp[i] << endl;
  }
  
  FOR(i,1,N){
    ll tmp = N-i;
    ll tmp2 = sqrt(tmp)+1;
    FOR(j,1,tmp2){
      if(tmp%j==0) {
        if(j*j==tmp) count++;
        else count+=2;
      }
    }
  }*/
  
  cout << rp[N] << endl;

}

Measured memory_bytes: 19304
use std::io::stdin;

fn main() {
  let mut entry1 = String::new();
  let mut entry2 = String::new();
  stdin().read_line(&mut entry1).unwrap();
  stdin().read_line(&mut entry2).unwrap();
  let vec1: Vec<&str> = entry1.trim().split(" ").collect();
  let max: i32 = vec1[0].parse().unwrap();
  let selectedLen: i32 = vec1[1].parse().unwrap();
  let mut prices: Vec<i32> = entry2.trim().split(" ").map(|s| s.parse().ok().unwrap()).collect();
  prices.sort();
  let prices = prices;
  let mut total = 0;
  for price in &prices[..selectedLen as usize] {
    total += price;
  }
  let total = total;
  println!("{}", total)
}

Measured memory_bytes: 2136
#include<cstdio>
int main()
{
	int a,b,c,d;
	scanf("%d%d%d%d",&a,&b,&c,&d);
	while(1)
	{c-=b;
		if(c<=0) break;
		a-=d;
		if(a<=0) break;
		
	}
	if(a<=0) printf("No");
	else printf("Yes");
}

Measured memory_bytes: 3224
N = int(input())
cur = N

def num2alpha(num):
    if num <= 26:
        return chr(96 + num)
    elif num % 26==0:
        return num2alpha(num // 26 - 1) + chr(122)
    else:
        return num2alpha(num // 26) + chr(96 + num % 26)

ans = num2alpha(N)
print(ans)


Measured memory_bytes: 9160
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;


int main(void){
    // Your code here!
  int n;
  int count=0;
  cin >> n;
  
  vector<int> vc(n);
  for(int i=0;i<n;i++)   cin >> vc[i];
  
  /*
  //基本的に要素数ぶんが最大。
  //全探索してかぶる数を調べてマイナスする
  for(int i=0;i<n-1;i++){
      for(int j=1;j<n-i-1;j++){
          
          if(vc[i]==vc[i+j]){
              count++;
             
          }
      }
  }
  */
  set<int> values;
  for(int i=0;i<n;i++) values.insert(vc[i]);
  
  
  cout << values.size();
  
}


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

using namespace std;

vector<long long> v[1000];


int main(){
  long long n,q;
  cin>>n>>q;

  while(q--){
    long long t,a,x;
    cin>>t>>a;
    if(t==0)
    {
        cin>>x;
        v[a].push_back(x);
    }
    if(t==1){
            for(int i=0;i<v[a].size();i++)
                    {
                        if(i!=0)
                            cout<<" ";
                            cout<<v[a][i];
                    }
                cout<<endl;
                }
    if(t==2)
        v[a].clear();
  }
  return 0;
}



Measured memory_bytes: 8824
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)

	if n < 10 {
		fmt.Println(n)
		return
	}
	if n < 100 {
		fmt.Println(9)
		return
	}
	if n < 1000 {
		fmt.Println(9 + n - 99)
		return
	}
	if n < 10000 {
		fmt.Println(909)
		return
	}
	if n < 100000 {
		fmt.Println(909 + n - 9999)
		return
	}
	fmt.Println(90909)
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
using ll = long long;
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

#ifdef LOCAL
#define show(x) cerr << "LINE" << __LINE__ << " : " << #x << " = " << (x) << endl
#define dump(x) cerr << "LINE" << __LINE__ << " : " << #x << " = {";  \
	for(auto v: x) cerr << v << ","; cerr << "}" << endl;
#else
#define show(x) true
#define dump(x) true
#endif

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);		//DON'T USE scanf/printf/puts !!
	cout << fixed << setprecision(20);
	
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	if(d==1) cout << 1 << endl;
	else cout << 0 << endl;
}


Measured memory_bytes: 256
N,P = gets.split.map(&:to_i)
A = gets.split.map(&:to_i)
Es = A.count{ |a| a&1 == 0 }
Os = A.count{ |a| a&1 == 1 }
p ((P^1)==Os ? 0 : 1<<Es)*(Os > 0 ? (1 << (Os-1)) : 1)

Measured memory_bytes: 1788
import scala.io.StdIn._
object Main extends App {
  val n = readInt
  val ws = readLine.split(" ").map(_.toInt)
  val sum = ws.sum
  val (_, min) = (0 until n).foldLeft(0, sum){case ((left, min), i) =>
    val newLeft = left + ws(i)
    (newLeft, Math.min(min, Math.abs(sum - 2 * newLeft)))
  }
  println(min)
}

Measured memory_bytes: 25536
/*                         _
                        _ooOoo_
                       o8888888o
                       88" . "88
                       (| -_- |)
                       O\  =  /O
                    ____/`---'\____
                  .'  \\|     |//  `.
                 /  \\|||  :  |||//  \
                /  _||||| -:- |||||_  \
                |   | \\\  -  /'| |   |
                | \_|  `\`---'//  |_/ |
                \  .-\__ `-. -'__/-.  /
              ___`. .'  /--.--\  `. .'___
           ."" '<  `.___\_<|>_/___.' _> \"".
          | | :  `- \`. ;`. _/; .'/ /  .' ; |
          \  \ `-.   \_\_`. _.'_/_/  -' _.' /
===========`-.`___`-.__\ \___  /__.-'_.'_.-'================

                  Please give me AC.
*/

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <string>
#include <sstream>
#include <complex>
#include <bitset>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <chrono>
#include <random>

using namespace std;

using int64 = long long;
using uint64 = unsigned long long;
using vi = vector<int>;
using vl = vector<int64>;
using pii = pair<int, int>;
using pll = pair<int64, int64>;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define print(x) cout << (x) << '\n'
#define print2(x, y) cout << (x) << ' ' << (y) << '\n'
#define print3(x, y, z) cout << (x) << ' ' << (y) << ' ' << (z) << '\n'
#define printn(v) rep(i, (v).size() - 1) cout << (v)[i] << ' '; cout << (v)[n - 1] << '\n';
#define debug(x) cerr << #x << ": " << (x) << '\n'
#define debug2(x, y) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v) for (size_t _ = 0; _ < v.size(); ++_){cerr << #v << "[" << _ << "] : " << v[_] << '\n';}
// constant
const int INF = (1<<30) - 1;
const int64 INF64 = (1LL<<62) - 1;

template<typename T> T gcd(T a, T b) {
    if (a < b) return gcd(b, a);
    T r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

template<typename T> T lcm(const T a, const T b) {
    return a / gcd(a, b) * b;
}

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

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

// End of template.

int main() {
    cout << fixed << setprecision(15);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    // cin.read(buf, sizeof buf); // 注意: ./a.out < in か pbp | ./a.out で入力すること

    double r;
    cin >> r;

    print(r * 6.28318530717958623200);

    return 0;
}



Measured memory_bytes: 3800
a1=list(map(int,input().split()))
a2=list(map(int,input().split()))
a3=list(map(int,input().split()))
a=a1+a2+a3
n=int(input())
b=[]
ans=False
for i in range(n):
    num=int(input())
    b.append(num)
for i in range(len(a)):
    for j in b:
        if a[i]==j:
            a[i]=0
if a[0]+a[1]+a[2]==0:
    ans=True
elif a[3]+a[4]+a[5]==0:
    ans=True
elif a[6]+a[7]+a[8]==0:
    ans=True
elif a[0]+a[3]+a[6]==0:
    ans=True
elif a[1]+a[4]+a[7]==0:
    ans=True
elif a[2]+a[5]+a[8]==0:
    ans=True
elif a[0]+a[4]+a[8]==0:
    ans=True
elif a[2]+a[4]+a[6]==0:
    ans=True
if ans==True:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9216
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <stack> // s.top()
#include <bitset>
#include <queue> // s.front()
using namespace std;

typedef long long Int;
typedef pair<Int,Int> P;
#define print(x) cout<<(x)<<endl

#define INF10 10000000000
#define INF5 100000
#define EPS 1e-10
#define MOD 1000000007

 

int main() {
	int n; vector<int>t; cin >> n;
	int sum = 0;
	for (int i = 0; i < n; i++) {
		int iptx; cin >> iptx;
		t.push_back(iptx);
		sum += iptx;
	}
	int m; cin >> m;
	vector<int> out;
	for (int i = 0; i < m; i++) {
		int p, x;
		int outptx;
		cin >> p >> x;
		outptx = sum - t[p - 1] + x;
		out.push_back(outptx);
	}
	for (int i = 0; i < m; i++) {
		print(out[i]);
	}









	return 0;
}

Measured memory_bytes: 256
/**
SXR0aXAkI0JwbXptI3FhI3Z3I293bCNqY2IjUG0jMCNicG0jVHFkcXZvLyNCcG0jQW10bjBhY2phcWFicXZvLyNNYm16dml0MSNWdyNhdGN1am16I2tpdiNhbXF9bSNQcXUjVnd6I0F0bW14MSNQcWEjaXptI2l0dCNicHF2b2EjUXYjYnBtI3BtaWRtdmEjaXZsI3d2I21pemJwMSNFcHcjcWEjYnBtem0ja2l2I3F2Ym16a21sbSNRdiNQcWEjeHptYW12a20jbXtrbXhiI0lhI3BtI3htenVxYmJtYnBHI1BtI3N2d2VtYnAjRXBpYiMraXh4bWl6bWJwI2J3I1BxYSNrem1pYmN6bWEjSWEsI0ptbnd6bSN3eiNJbmJteiN3eiNKbXBxdmwjYnBtdTEjVnd6I2FwaXR0I2JwbXwja3d1eGlhYSNJY29wYiN3biNwcWEjc3Z3ZXRtbG9tI017a214YiNpYSNQbSNlcXR0bWJwMSNQcWEjYnB6d3ZtI2x3YnAjbXtibXZsI1dkbXojYnBtI3BtaWRtdmEjSXZsI3d2I21pemJwLyNpdmwjUG0jbm1tdG1icCNWdyNuaWJxb2NtI3F2I29jaXpscXZvI0l2bCN4em1hbXpkcXZvI2JwbXUvI053eiNQbSNxYSNicG0jVXdhYiNQcW9wMSNCcG0jQWN4em11bSMrcXYjb3R3enwsMQ==
*/
#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cassert>

#define F first
#define S second
#define endl '\n'
#define deb(x) cout<<#x<<' '<<x<<endl;
#define pb push_back

/*
#ifdef IZI_KATKA
#define int __int64_t
#else
#define int __int64
#endif
*/

const long long MOD = 1e9 + 7;
const long long MAXN = 1e6 + 1;
using namespace std;

typedef long long ll;

long long readInt() {
    bool minus1 = false;
    long long result = 0;
    char ch;
    ch = getchar();
    while (true) {
        if (ch == '-') break;
        if (ch >= '0' && ch <= '9') break;
        ch = getchar();
    }
    if (ch == '-') minus1 = true; else result = ch-'0';
    while (true) {
        ch = getchar();
        if (ch < '0' || ch > '9') break;
        result = result*10 + (ch - '0');
    }
    if (minus1)
        return -result;
    else
        return result;
}

int a[MAXN];

int main() {
	#ifdef IZI_KATKA
	assert(freopen("input", "r", stdin));
    assert(freopen("output", "w", stdout));
    #endif
    int n = readInt();
    for (int i = 1; i <= n; i++) {
    	a[i] = readInt();
    }
    int r = 1;
    int ans = 0;
	for (int i = 1; i <= n; i++) {
		r = i;
		while(r < n && a[i] == a[r + 1]) {
			r++;
		}
		int kek = (a[r + 1] > a[i]);
		while(r < n && (kek == (a[r + 1] > a[r]) || (a[r + 1] == a[r]))) {
			r++;
		}
		ans++;
		i = r;	
	}
	cout << ans;              
    return 0;
}                        

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

using namespace std;

using i64 = int64_t;

int main()
{
    i64 A,B,K;
    cin >> A >> B >> K;

    if (A >= K) {
        A -= K;
    } else {
        if (A + B < K) {
            A = 0;
            B = 0;
        } else {
            B -= K - A;
            A = 0;
        }
    }

    cout << A << " " << B << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <typeinfo>
#include <cxxabi.h>
#ifdef LOCAL
#include "dbgtoki.hpp"
#define DUMP(i) dump((string)TOSTRING(i), demangle(typeid(i).name()), __LINE__ , i) 
#else
#define DUMP(i) 
#endif

#define TOSTRING(x) #x
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(s) (s).begin(), (s).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()) , v.end());

using namespace std;
typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;

struct Edge{
public:
  int from,to,cost;
  Edge(){}
  Edge(int _from,int _to,int _cost){
    from = _from;
    to = _to;
    cost = _cost;
  }
};

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
const int EPS = 1e-9;
const int MOD = 1e9+7;

ll mod_pow(ll x, ll n, ll mod){
  if(n == 0)    return 1;
  ll res = mod_pow(x * x % mod,n/2,mod);
  if(n%2 == 1)res = res * x % mod;//(nが2の累乗ではない時にもう一度処理を行う)
  return res;
}

int main (){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vi C;
  C.push_back(1);
  REP(i,8){
    C.push_back((int)mod_pow(6,i,10e9));
  }
  REP(i,6){
    C.push_back((int)mod_pow(9,i,10e9));
  }
  sort(ALL(C));
  int T[n+1];
  int INF = INT_MAX;
  REP(i,n+1){
    T[i] = INF;
  }
  T[0] = 0;

  REP(i,SZ(C)){
    FOR(j,C[i],n+1){
      T[j] = min(T[j],T[j-C[i]] + 1);
    }
  }
  /*  REP(i,n+1){
    cout << T[i] << endl;
    }*/
  cout << T[n] << endl;
  return 0;
}



Measured memory_bytes: 640
#!/usr/bin/env python3
import sys
INF = float("inf")
from collections import deque

import sys
import math
from collections import defaultdict, deque
INF = float("inf")


class Graph(object):
    """グラフを扱うオブジェクト
    """

    def __init__(self, N):
        self.N = N
        self.E = [[] for _ in range(N)]
        pass

    def add_edge(self, from_, to_):
        """必ず0インデックスで入力すること。
        """
        self.E[from_].append((to_, 1))
        pass


def solve(N: int, S: "List[str]"):

    g = Graph(N)
    for i, s in enumerate(S):
        for j, c in enumerate(s):
            if c == "1":
                g.add_edge(i, j)

    ddd = -1
    for node in range(N):
        depth = [-2]*N
        q = deque()
        q.append((node, 1))
        while len(q) > 0:
            node, d = q.popleft()
            if depth[node] != -2:
                continue
            depth[node] = d
            for i, w in g.E[node]:
                if depth[i] == -2:
                    q.append((i, d+1))
                elif d == depth[i]:
                    print(-1)
                    return
        ddd = max(ddd, d)
    print(ddd)
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    S = [next(tokens) for _ in range(N)]  # type: "List[str]"
    solve(N, S)


if __name__ == '__main__':
    main()


Measured memory_bytes: 45404
#include<bits/stdc++.h>
int main(){
  std::string s[4];
  long long k,a[4]={};
  std::cin>>s[0]>>k;
  for(size_t i=0;i<3;++i) s[i+1]=s[i]+s[0];
  for(size_t i=0;i<4;++i) for(size_t j=0;j<s[i].length()-1;++j) if(s[i][j]==s[i][j+1]) ++a[i],s[i][j+1]='.';
  if(k&1) std::cout<<a[0]+(a[2]-a[0])*(k/2)<<std::endl;
  else std::cout<<a[1]+(a[3]-a[1])*(k/2-1)<<std::endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
template<typename T>void max_self(T&a,T b){
	a=max(a,b);
}
bool first_row_or_colm(pair<int,int>p){
	return p.first==0||p.second==0;
}
const ll INF = 1e9 + 5;
int main(){
	string a,b;
	cin>>a>>b;
	vector<vector<pair<int,pair<int,int> > > >dp(a.length()+1,vector<pair<int,pair<int,int> > >(b.length()+1,{-INF,{0,0}}));
	dp[0][0]={0,{0,0}};
	for(int i=0;i<(int)a.length();i++){
		for(int j=0;j<(int)b.length();j++){
			if(a[i]==b[j])
				max_self(dp[i+1][j+1],make_pair(dp[i][j].first+1,make_pair(i,j)));
			max_self(dp[i+1][j],make_pair(dp[i][j].first,make_pair(i,j)));
			max_self(dp[i][j+1],make_pair(dp[i][j].first,make_pair(i,j)));	
		}
	}
	pair<int,pair<int,int> >answer={0,{0,0}};
	for(int i=0;i<=(int)a.length();i++){
		for(int j=0;j<=(int)b.length();j++)
			max_self(answer,make_pair(dp[i][j].first,make_pair(i,j)));
	}
	string s;
	pair<int,int>curr=answer.second;
	while(!first_row_or_colm(curr)){
		int i=curr.first;
		int j=curr.second;
		pair<int,int>prev=dp[i][j].second;
		if(prev==make_pair(i-1,j-1))
		{
			assert(a[i-1]==b[j-1]);
			s+=a[i-1];
		}
		curr=prev;
	}
	reverse(s.begin(),s.end());
	cout<<s;
}

Measured memory_bytes: 108032
# ABC051 C - Back and Forth

sx, sy, tx, ty = map(int, input().split())
for i in range(2):
    if i > 0:
        [print("L", end="") for j in range(i)]
    [print("U", end="") for y in range(ty - sy + i)]
    [print("R", end="") for x in range(tx - sx + i)]
    if i > 0:
        [print("D", end="") for j in range(i)]
        [print("R", end="") for j in range(i)]
    [print("D", end="") for y in range(ty - sy + i)]
    [print("L", end="") for x in range(tx - sx + i)]
    if i > 0:
        [print("U", end="") for j in range(i)]
print()

Measured memory_bytes: 4468
#include <bits/stdc++.h> 
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vl;
typedef pair<ll,ll> pll;
#define MOD 1000000007
#define INF 1000000000
#define mp make_pair
#define pb push_back
#define ss second
#define ff first
#define endl '\n'
#define pl cout<<endl;
void fast() { ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL); }
const long long INFll=1ll*INF*INF;
const long double PI=3.141592653589793238462643383279502884197169399375105820974944;
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define debug(x) cout << x << endl;
#define sz(a) int((a).size())
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
 
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
long long genrand(long long L,long long R)
{
	return uniform_int_distribution<long long>(L, R)(rng);
}
//use brackets before operations if taking MOD
//use map only when necessary
//give long long to arrays and variables properly
int mul(int a, int b,int mod = MOD) {
	return int(a * 1ll * b % mod);
}
int norm(int a,int mod = MOD) {
	while(a >= mod) a -= mod;
	while(a < 0) a += mod;
	//a = (a%mod+mod)%mod;
	return a;
}
int powmod(int x,int y,int mod = MOD){
	int res = 1;
	while(y>0)
	{
		if(y&1)
			res = mul(res,x,mod);
		x = mul(x,x,mod);
		y=y>>1;
	}
	return res;
}
int inv(int a,int mod = MOD) {
	return powmod(a, mod - 2);
}
int main() {
	fast();

	int x, y, a, b, c; 
	cin>>x>>y>>a>>b>>c;
	vector<long long> p(a), q(b), r(c);
	long long ans = 0, sum = 0;
	// vector<long long> pp(a), pq(b), pr(c);
	for(int i = 0;i<a;i++){
		cin>>p[i];
	}
	for(int i = 0;i<b;i++){
		cin>>q[i];
	}
	for(int i = 0;i<c;i++){
		cin>>r[i];
	}
	sort(rall(p)); sort(rall(q)); sort(rall(r));

	priority_queue<long long, vector<long long>, greater<long long>  > pq;
	for(int i = 0;i<x;i++){
		pq.push(p[i]);
		sum+=p[i];
	}
	for(int i = 0;i<y;i++){
		pq.push(q[i]);
		sum+=q[i];
	}

	long long pref = 0;
	ans = sum;
	for(int i = 1;i<=c && !pq.empty();i++){
		pref += r[i-1];
		sum-=pq.top();
		pq.pop();
		ans = max(ans, sum+pref);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 4852
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long k,a,b;
  cin>>k>>a>>b;
  if(a<=b){
    if(k<=a){
      cout<<k+1<<endl;
    }else{
      if(b-a==1){
        cout<<k+1<<endl;
      }else{
        cout<<(k-(a+1))/2*(b-a)+b+((k-(a+1))%2)<<endl;
      }
    }
  }else{
    cout<<k+1<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
import math
def distance(x1,x2,y1,y2):
  d=math.sqrt((x1-x2)**2+(y1-y2)**2)
  return d
count=int(input())
zahyou=[]
for i in range(count):
  a=input().split(" ")
  zahyou.append(a)

lenth=0
for i in zahyou:
  for j in zahyou:
    lenth=lenth+distance(int(i[0]),int(j[0]),int(i[1]),int(j[1]))
print(lenth/count)


    
  
  
  

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define int long long
#define ll long long
#define vi vector<int>
#define vvi vector<vector<int>>
#define vvvi vector<vector<vector<int>>>
#define ALL(a) begin(a), end(a)
#define RALL(a) rbegin(a), rend(a)
#define SORT(a) stable_sort(ALL(a))
#define RSORT(a) stable_sort(RALL(a))
#define REV(a) reverse(ALL(a))
#define UNIQUE(a) a.erase(unique(ALL(a)), end(a))
#define lambda(i) [=](auto i)
#define compare(i, j) [=](auto i, auto j)
#define min_of(a) *min_element(ALL(a))
#define max_of(a) *max_element(ALL(a))
#define sum(a) accumulate(ALL(a), 0)
#define count_of(a, i) count(ALL(a), i)
#define lower(a, i) (int)(lower_bound(ALL(a), i) - begin(a))
#define upper(a, i) (int)(upper_bound(ALL(a), i) - begin(a))
#define binary(a, i) binary_search(ALL(a), i)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define sz(a) (int)(a).size()
#define REP(i, n) for (decltype(+n) i = 0; i < (n); i++)
#define RREP(i, n) for (auto i = n - 1; i != static_cast<decltype(i)>(-1); i--)
#define FOR(i, a, b) for (auto i = (a); i < (b); i++)
#define RFOR(i, a, b) for (auto i = b - 1; i >= a; i--)
#define EACH(i, a) for (auto&& i: (a))
using namespace std;

const int INF = 1e18;
const int MOD = 1e9 + 7;
int mod_add(int A, int B) { return (A + B) % MOD; }
int mod_sub(int A, int B) { return (A + MOD - B) % MOD; }
int mod_mul(int A, int B) { return ((A % MOD) * (B % MOD)) % MOD; }
int mod_bipow(int X, int Y) {
    if (Y == 0) return 1;
    else if (Y == 1) return X % MOD;
    else if (Y % 2 == 0) {
        int Z = mod_bipow(X, (int)(Y / 2));
        return mod_mul(Z, Z);
    } else {
        int Z = mod_bipow(X, (int)(Y / 2));
        return mod_mul(mod_mul(Z, Z), X);
    }
}
int mod_inv(int X) { return mod_bipow(X, MOD - 2); }
int mod_div(int A, int B) { return mod_mul(A, mod_inv(B)); }

int ceil_div(int X, int Y) {
  return (X - 1) / Y + 1;
}

struct vertex {
  vector<int> adj = vi(0);
};

struct union_find {
  vi data;
  union_find(int size) : data(size, -1) { }
  bool union_set(int x, int y) {
    x = root(x); y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y]; data[y] = x;
    }
    return x != y;
  }
  bool find_set(int x, int y) {
    return root(x) == root(y);
  }
  int root(int x) {
    return data[x] < 0 ? x : data[x] = root(data[x]);
  }
  int size(int x) {
    return -data[root(x)];
  }
};

vi cum(vi V) {
  vi U(sz(V));
  partial_sum(ALL(V), begin(U));
  return U;
}

void solve() {
  int a, b, c, x, y;
  int ans = 0;
  cin >> a >> b >> c >> x >> y;
  int mxy = min(x, y);
  if (a + b > c * 2) {
    ans += mxy * c * 2;
  } else {
    ans += mxy * (a + b);
  }
  x -= mxy;
  y -= mxy;
  if(x > 0) {
    ans += x * min(a, c * 2);
  } else {
    ans += y * min(b, c * 2);
  }

  cout << ans << endl;
  // REP(i, n) {
  //   cout << a[i];
  // }
}

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout << fixed << setprecision(15);
  solve();
}


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()

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

const int mod =  1000000007;  //出力は (ans % mod + mod) % mod  (負の剰余を正にする)
const int inf = 1e9;
const long long INF = 1LL << 60;   // INF = 11


struct UnionFind{
    vector<int> rank,p,size;
    UnionFind(int n){
        rank.resize(n,0);
        p.resize(n,0);
        size.resize(n,0);
        for(int i = 0; i < n; i++){
            p[i] = i;
            rank[i] = 0;
            size[i] = 1;
        }
    }
    bool same(int x,int y){
        return root(x) == root(y);
    }
    int root(int x){
        if(x != p[x]){
            p[x] = root(p[x]);
        }
        return p[x];
    }
    bool unite(int x,int y){
        int rx = root(x);
        int ry = root(y);
        if(rx == ry) return false;
        if(rank[rx] > rank[ry]){
            p[ry] = rx;
            size[rx] += size[ry];
        }else{
            p[rx] = ry;
            size[ry] += size[rx];
            if(rank[rx] == rank[ry]){
                rank[ry]++;
            }
        }
        return true;
    }
    int tree_size(int x){
        return (size[root(x)]);
    }
};


int main()
{
    int n,m; cin >> n >> m; 
    UnionFind uf(n);
    for(int i = 0; i < m; i++){
        int a,b; cin >> a >> b;
        a--; b--;
        uf.unite(a,b);
    }
    int ans = 0;
    rep(i,n){
        ans = max(ans,uf.tree_size(i));
    }
    cout << ans << endl;
}

Measured memory_bytes: 5536
def main():
    S = input()
    A = int(S[:2])
    B = int(S[2:])

    if ((A == 0) and (B > 12)) or ((B == 0) and (A > 12)):
        print("NA")
    elif ((A == 0) and (B == 0)):
        print("NA")
    elif ((1 <= A) and (A <= 12)) and ((1 <= B) and (B <= 12)):
        print("AMBIGUOUS")
    elif ((1 <= A) and (A <= 12)):
        print("MMYY")
    elif ((1 <= B) and (B <= 12)):
        print("YYMM")
    else:
        print("NA")

if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1e9
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

struct UnionFind{
    vector<int> par;

    UnionFind(int n) : par(n,-1) { }
    void init(int n) { par.assign(n,-1); }

    int root(int x){
        if(par[x]<0) return x;
        else return par[x]=root(par[x]);
    }

    bool issame(int x,int y){
        return root(x)==root(y);
    }

    bool merge(int x,int y){
        x=root(x);
        y=root(y);
        if(x==y) return false;
        if(par[x]>par[y]) swap(x,y);
        par[x]+=par[y];
        par[y]=x;
        return true;
    }

    int size(int x){
        return -par[root(x)];
    }
};

int main(){
    int n,m,k;
    cin>>n>>m>>k;
    vector<set<int>> dame(n);
    UnionFind uf(n);
    rep(i,m){
        int a,b;
        cin>>a>>b;
        a--,b--;
        dame[a].insert(b);
        dame[b].insert(a);
        uf.merge(a,b);
    }
    rep(i,k){
        int c,d;
        cin>>c>>d;
        c--,d--;
        if(!uf.issame(c,d)) continue;
        dame[c].insert(d);
        dame[d].insert(c);
    }

    rep(i,n){
        int mem=uf.size(i)-1;
        mem-=dame[i].size();
        cout<<mem<<" ";
    }
    cout<<endl;
}



Measured memory_bytes: 24704
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
using ll = long long;
using graph = std::vector<std::vector<ll>>;

using namespace std;

int main() {
    ll N,K;
    cin >> N >> K;
    ll count = 0;
    while(N != 0){
        count++;
        N /= K;
    }
    cout << count << endl;
}


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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MAXN 1000010
#define rep(i,n) for (int i = 0; i < (n); ++i)
const ll mod = 1e9+7;

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

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

    ll xold=0, yold=0, told=0;
    ll x, y, t;

    bool ans = true;

    rep(i, n) {
        cin >> t >> x >> y;

        if(abs(x-xold)+abs(y-yold) > t-told) {
            ans = false;
        }

        if((x+y)%2 != t%2) {
            ans = false;
        }

        xold = x;
        yold = y;
        told = t;
    }

    cout << (ans ? "Yes" : "No") << endl;

}



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

int main() {
  int N;
  cin >> N;
  vector<int> L(N);
  for (int i = 0; i < N; i++) cin >> L.at(i);

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

  long sum = 0;
  for (int i = 0; i < N; i++) {
    for (int j = i + 1; j < N - 1; j++) {
      int tmp = lower_bound(L.begin(), L.end(), L.at(i) + L.at(j)) - L.begin();
      sum += tmp - (j + 1);
    }
  }

  cout << sum << "\n";
}

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

#define pb push_back
#define INF 1e9
#define mod 998244353
#define mod2 1000000007
#define dbg(x) cout << (#x) << " --> " << x << "\n";
#define dbgarr(y)                                                                                            \
  cout << (#y) << " --> " << '\n';                                                                           \
  for(auto& x : y) cout << x << '\n';
#define dbgparr(y)                                                                                           \
  cout << (#y) << " --> " << '\n';                                                                           \
  for(auto& x : y) cout << x.first << ", " << x.second << '\n';
using namespace std;

typedef priority_queue<int, vector<int>, greater<int>> minPq;
typedef priority_queue<int> maxPq;
typedef long long ll;

void goodLuckHaveFun() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
/* clang-format off */
  #ifdef _DEBUG
  freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
  #endif
  /* clang-format on */
}

vector<int> adList[2010];
vector<int> dist[2010];

// O(V + E)
void bfs(int start, int n) {
  vector<ll> visited(n + 1);
  queue<ll> q;
  visited[start] = 1;
  q.push(start);
  dist[start].resize(n + 1);
  dist[start][start] = 0;
  while(!q.empty()) {
    ll s = q.front();
    q.pop();
    // process
    for(auto u : adList[s]) {
      if(visited[u]) continue;
      visited[u]     = 1;
      dist[start][u] = dist[start][s] + 1;
      q.push(u);
    }
  }
}

int main() {
  goodLuckHaveFun();
  int x, y, a, b, c;
  cin >> x >> y >> a >> b >> c;
  vector<int> delR(a);
  for(int i = 0; i < a; ++i) {
    cin >> delR[i];
  }
  vector<int> delG(b);
  for(int i = 0; i < b; ++i) {
    cin >> delG[i];
  }
  maxPq colorless;
  int t;
  for(int i = 0; i < c; ++i) {
    cin >> t;
    colorless.push(t);
  }
  sort(delR.begin(), delR.end());
  sort(delG.begin(), delG.end());

  minPq red;
  minPq green;
  for(int i = (int)delR.size() - 1; i >= (int)delR.size() - x; --i) {
    red.push(delR[i]);
  }
  for(int i = (int)delG.size() - 1; i >= (int)delG.size() - y; --i) {
    green.push(delG[i]);
  }
  ll res = 0;
  while(colorless.size() > 0) {
    int nextRed;
    if(red.size() == 0) {
      nextRed = 2*1e9;
    } else {
      nextRed = red.top();
    }
    int nextGreen;
    if(green.size() == 0) {
      nextGreen = 2*1e9;
    } else {
      nextGreen = green.top();
    }
    int nextColorless = colorless.top();

    if(nextColorless > nextGreen || nextColorless > nextRed) {
      int scoreForGreen = nextColorless - nextGreen;
      int scoreForRed   = nextColorless - nextRed;
      if(scoreForGreen > scoreForRed) {
        res += nextColorless;
        colorless.pop();
        green.pop();
        y--;
      } else {
        res += nextColorless;
        colorless.pop();
        red.pop();
        x--;
      }
    } else {
      break;
    }
  }

  for(int i = (int)delR.size() - 1; i >= (int)delR.size() - x; --i) {
    res += delR[i];
  }
  for(int i = (int)delG.size() - 1; i >= (int)delG.size() - y; --i) {
    res += delG[i];
  }
  cout << res << '\n';
}

Measured memory_bytes: 2680
#include <iostream>
#include <vector>
#include <stack>
#include <unordered_set>
#include <numeric>
#include <iterator>
#include <unordered_map>
#include <array>
#include <map>
#include <cstring>
#include <iomanip>
#include <string>
#include <algorithm>
#include <cmath>
#include <ctgmath>
#include <set>
#include <queue>
#include <fstream>
#include <ostream>
#include <list>
#include <string>
using namespace std;

void topsortUtil(int v, vector<bool> &vis, vector<int> &res, vector<vector<int>> &graph)
{
	vis[v] = true;
	
	for (auto i : graph[v])
	{
		if (!vis[i])
		{
			topsortUtil(i, vis, res, graph);
		}
	}
	res.push_back(v);
}

vector<int> topologicalSort(vector<vector<int>> &graph)
{
	vector<int> res;
	vector<bool> visited(graph.size());

	for (int i = 0; i < graph.size(); i++)
	{
		if (visited[i] == false)
		{
			topsortUtil(i, visited, res, graph);
		}
	}

	reverse(res.begin(), res.end());
	return res;
}

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

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

	vector<vector<int>> graph(n);
	for (int i = 0; i < m; i++)
	{
		int a, b;
		cin >> a >> b;

		a--; b--;
		graph[a].push_back(b);
	}

	auto top = topologicalSort(graph);

	vector<int> dist(n);
	for (auto i : top)
	{
		for (auto j : graph[i])
		{
			dist[j] = max(dist[j], dist[i] + 1);
		}
	}

	cout << *max_element(dist.begin(), dist.end()) << "\n";


}


Measured memory_bytes: 10104
#include <iostream>
using namespace std;
int main(void){
    long int N, i, COUNT=0;
    char S[100000]={};
    
    cin >> N;
    for(i=0; i<N; i++){
        cin >> S[i];
    }
    
    for(i=0; i<N-1; i++){
        if(S[i] != S[i+1]){
            COUNT++;
            i++;
        }
    }
    cout << COUNT << endl;
    return 0;
}


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

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N;
    cin >> N;
    vector<int> W(N), V(N);
    for(int i=0; i<N; i++)
    {
        int x, y;
        cin >> x >> y;
        W[i] = x + y;
        V[i] = x - y;
    }
    sort(W.begin(), W.end());
    sort(V.begin(), V.end());
    cout << max(W[N-1] - W[0] , V[N-1] - V[0]) << endl;

    return 0;
}


Measured memory_bytes: 4764
#include<stdio.h>

int main()
{
  int i,j,n,alt,cnt=0;

  scanf("%d",&n);

  int a[n];

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

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

  for(i = 0 ; i < n ; i++)
    {
      printf("%d",a[i]);
      if(i != n-1) printf(" ");
      else printf("\n");
    }
  printf("%d\n",cnt);
  
  return 0;
}



Measured memory_bytes: 2104
#!/usr/bin/env python3
#AGC24 A

import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

a,b,c,k = LI()
s,t,u = b+c,a+c,a+b
x,y,z = t+u,s+u,s+t
if k % 2:
    print(s-t)
else:
    print(x-y)


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

#define rep(l, r) for (int i = (l); i < (r); i++)

typedef long long ll;
 
using namespace std;

int main() {
    int x, a, b;
    cin >> x >> a >> b;

    cout << ((x - a) % b) << endl;

    return 0;
}


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

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

    sort(x.begin(), x.end());
    int count = 0;
    int now = 10000000;
    for (int i = 0; i < N; i++)
    {
        if (now != x[i])
        {
            count++;
            now = x[i];
        }
    }

    cout << count;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int m[100003];

int main() {
    int n; cin >> n;
    for (int i = 1; i <= n; i++) {
        int x; cin >> x;
        m[x] = i;
    }
    for (int i = 1; i <= n; i++) {
        cout << m[i] << " ";
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 1152
a,b,c,d= map(int,input())
if a+b+c+d==7:
  print(str(a)+'+'+str(b)+'+'+str(c)+'+'+str(d)+'=7')
elif a+b+c-d==7:
  print(str(a)+'+'+str(b)+'+'+str(c)+'-'+str(d)+'=7')
elif a+b-c+d==7:
  print(str(a)+'+'+str(b)+'-'+str(c)+'+'+str(d)+'=7')
elif a-b+c+d==7:
  print(str(a)+'-'+str(b)+'+'+str(c)+'+'+str(d)+'=7')
elif a+b-c-d==7:
  print(str(a)+'+'+str(b)+'-'+str(c)+'-'+str(d)+'=7')
elif a-b+c-d==7:
  print(str(a)+'-'+str(b)+'+'+str(c)+'-'+str(d)+'=7')
elif a-b-c+d==7:
  print(str(a)+'-'+str(b)+'-'+str(c)+'+'+str(d)+'=7')
else:
  print(str(a)+'-'+str(b)+'-'+str(c)+'-'+str(d)+'=7')

Measured memory_bytes: 3064
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define REP(i, n)  FOR(i, 0, n)
#define ASC(c) sort((c).begin(), (c).end())
#define DESC(c) sort((c).begin(), (c).end(), greater<int>())

#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define DEBUG(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

typedef long long ll;
typedef unsigned long long ull;
struct edge { int u, v; ll w; };
 
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int main() {
    int n; cin >> n;
    int ans1 = floor(float(n) * 100 / 108);
    int ans2 = ceil(float(n) * 100 / 108);

    if (n == floor(ans1 * 1.08)) cout << ans1 << endl;
    else if (n == floor(ans2 * 1.08)) cout << ans2 << endl;
    else cout << ":(" << endl;
}


Measured memory_bytes: 256
num=int(input().rstrip())
numlis=input().rstrip().split(" ")


s=0
for i in range(num):
    for j in range(i+1,num):
        a=int(numlis[i])
        #print(a)
        b=int(numlis[j])
        #print(b)
        c=a*b
        #print(c)
        s+=c


print(s)

Measured memory_bytes: 2940
n = int(input())
li = list(map(int, input().split()))
ans = 0
while 1:
    if li == [0] * n:
        print(ans)
        break
    minimam = 0
    temp1 = 0
    temp2 = -1
    copy = li.copy()
    for index, i in enumerate(copy):
        if (i < minimam or minimam == 0) and i != 0:
            minimam = i
        elif i == 0:
            temp1 = temp2
            temp2 = index
            if temp2 - temp1 > 0:
                li = [li[i] - minimam if temp1 < i < temp2 else li[i] for i in range(len(li))]
                ans += minimam
                minimam = 0
        if index == len(li)-1:
            li = [li[i] - minimam if temp2 < i else li[i] for i in range(len(li))]
            ans += minimam


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

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

    int n;
    static pair<int, int> t[1000000];
    cin >> n;
    for(int i=0;i<n;++i){
        string s;
        cin >> s;
        t[i] = {0, 0};
        int buf = 0;
        for(char c: s){
            if(c == '(') ++buf;
            else{
                if(buf > 0) --buf;
                else ++t[i].first;
            }
        }
        t[i].second = buf;
    }
    
    vector<pair<int,int>> pos, neg;
    int even = 0;
    for(int i=0;i<n;++i){
        if(t[i].first < t[i].second) pos.push_back(t[i]);
        else if(t[i].first > t[i].second) neg.push_back(t[i]);
        else even = max(even, t[i].first);
    }

    sort(pos.begin(), pos.end());
    sort(neg.begin(), neg.end(), [](auto x, auto y){
        if(x.second > y.second) return true;
        else if(x.second < y.second) return false;
        return x.first < y.first;
    });

    int buf = 0;
    for(auto p: pos){
        if(p.first > buf){ cout << "No" << endl; return 0; }
        buf -= p.first;
        buf += p.second;
    }
    if(buf < even){ cout << "No" << endl; return 0; }
    for(auto p: neg){
        if(p.first > buf){ cout << "No" << endl; return 0; }
        buf -= p.first;
        buf += p.second;
    }
    if(buf == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 19076
#include <stdio.h>

int fn_rank(int m, int f, int r){
    if(m == -1 || f == -1) return 5; // F
    if(m + f >= 80) return 0; // A
    if(m + f >= 65) return 1; // B
    if(m + f >= 50) return 2; // C
    if(m + f >= 30 && r >= 50) return 2; // C
    if(m + f >= 30) return 3; // D

    return 5; // F
}

int main(void)
{
    char buf[64];
    int m, f, r;
    while(1){
        fgets(buf, sizeof(buf), stdin);
        sscanf(buf, "%d %d %d", &m, &f, &r);

        if(m == -1 && f == -1 && r == -1) break;

        int rank = fn_rank(m, f, r);
        printf("%c\n", 'A' + rank);
    }

    return 0;
}

Measured memory_bytes: 1044
from itertools import permutations
N = int(input())
position = []
for p in range(N):
    position.append(list(map(int,input().split())))

D = [[0]*N for _ in range(N)]
for i in range(N):
    for j in range(i+1,N):
        dist=(position[i][0]-position[j][0])**2
        dist+=(position[i][1]-position[j][1])**2
        dist=dist**(1/2)
        D[i][j] = dist
        D[j][i] = dist

dist=[]
for p in permutations(range(N),N):
    dist_temp=0
    for p_idx in range(1,len(p)):
        p_start = p[p_idx-1]
        p_end = p[p_idx]
        dist_temp+=D[p_start][p_end]
    dist.append(dist_temp)
        
print(sum(dist)/len(dist))

Measured memory_bytes: 75828
N, T = map(int, input().split())
t = list(map(int, input().split()))

time = 0

for i in range(N):
    if i + 1 == N:
        time += T
        break
    if t[i+1] - t[i] < T:
        time += (t[i+1] - t[i])
    else:
        time += T
print(time)


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

const long long MOD = 1000000007;
const long long INF = 1LL << 60;
const int INT_INF = 1000000000;

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

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  double R;
  cin >> R;
  double pi = 3.1415926535;
  cout << 2.0 * pi * R << endl;
  return 0;
}


Measured memory_bytes: 3804
import scala.io.StdIn._
object Main extends App {
  val Array(_, t) = readLine.split(" ").map(_.toInt)
  val (_, sum) = readLine.split(" ").map(_.toInt).foldLeft((0, 0)){case ((until, cur), x) =>
    (x + t, cur + t - (if (x < until) until - x else 0))
  }
  println(sum)
}

Measured memory_bytes: 52784
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;

int main() {
  double r, d, area, circle;

  cin >> r;

  d = r + r;
  area = r * r * M_PI;
  circle = d * M_PI;

  printf("%.6f %.6f\n", area, circle);

  return 0;

}

Measured memory_bytes: 3204
N, K = list(map(int, input().split()))
K -= 1
A = list(map(lambda x: int(x) - 1, input().split()))
seen = [None]*N
seen_set = set()
now = 0
for i in range(N):
    seen[i] = now
    seen_set.add(now)
    to = A[now]
    now = to
    if now in seen_set:
        seen[i+1] = now
        loop_s = seen.index(now)
        loop_end = i + 1
        size = loop_end - loop_s
        break
if K <= loop_s:
    print(seen[K+1] + 1)
else:
    K -= loop_s
    print(seen[loop_s + 1 + K % size] + 1)

Measured memory_bytes: 119728