akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <string>
#include <map>
#include <set>

using namespace std;
typedef long long  ll;

#define rep(i,s,n)for(ll i=s;i<n;i++)
#define repe(i,s,n)for(ll i=s;i<=n;i++)
ll MOD = 1000000007;

int main() {
	ll N; cin >> N;
	map<ll, ll> mp;
	rep(i, 0, N) {
		ll a; cin >> a;
		mp[a]++;
	}

	ll cnt = 0;
	for (map<ll, ll>::iterator it = mp.begin(); it != mp.end(); it++) {
		if (it->second % 2 == 1) cnt++;
	}

	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 6528
import java.util.*;
public class Main{
 public static void main(String[] args){
   Scanner sc = new Scanner(System.in);
   int H = sc.nextInt();
   int W = sc.nextInt();

 
   String ans ="Yes";

   if(H!=W) ans = "No"; 
   System.out.println(ans);
 }
}

Measured memory_bytes: 22868
#include<bits/stdc++.h>
using namespace std;
int N;
int X;

bool occupied[102];

int main(){
    cin>>X;
    cin>>N;
    for(int i=0;i<N;i++){
        int a=0;
        cin>>a;
        occupied[a]=true;
    }
    int minimum=10000;
    int res=0;
    for(int i=0;i<=101;i++){
        if(occupied[i]){continue;} 
        int diff=i-X;  
        if(diff<0){
            diff=-diff;
        }
        if(diff<minimum){
            minimum=diff;
            res=i;
        }
        //cout<<diff<<" ";
    }
    cout<<res<<endl;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n,a=0;
    cin >> n;
    vector<int> vec(n);
    for(int i=0;i<n;i++){
        cin >> vec.at(i);
    }
    for(int j=1;j<n-1;j++){
        if(vec.at(j)<vec.at(j+1)&&vec.at(j)>vec.at(j-1)){
            a=a+1;
        }
        else if(vec.at(j)<vec.at(j-1)&&vec.at(j)>vec.at(j+1)){
            a=a+1;
        }
    }
    cout << a << endl;
}

Measured memory_bytes: 256
def main():
    n, q = map(int, input().split())
    s = input()
    
    t = [0] * n
    pre = s[0]
    t_sum = 0
    for i in range(1, n):
        if pre == 'A' and s[i] == 'C':
            t[i] = t_sum + 1
            t_sum +=  1
        else: 
            t[i] = t_sum
        pre = s[i]
    for _ in range(q):
        l, r = map(int, input().split())
        print(t[r - 1] - t[l - 1])
        
    
if __name__ == '__main__':
    main()

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

int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  for(int i=0;i<N;i++){
    cin >> a.at(i); 
  }
  sort(a.begin(),a.end());
  reverse(a.begin(),a.end());
  int b=0,c=0;
  for(int j=0;j<N;j++){
    if(j%2==0){
     b+=a.at(j); 
    }else{
     c+=a.at(j); 
    }
  }
  cout << b-c << endl;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll GCD(ll x,ll y){
    if(y == 0) return x;
    else return GCD(y,x%y);
}

int main() {
    int x,y,z;
    cin >> x >> y >> z;
    cout << z << " " <<  x << " " << y << endl;
}


Measured memory_bytes: 256
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <iostream>

using namespace std;

int main()
{
    int a,b;
    cin>>a>>b;
    cout<<a*b;

    return 0;
}


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

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

#include <vector>
#include <utility>


#include <algorithm>


long long T, A;
int n;

void solve() {
	scanf("%d", &n);
	scanf("%lld %lld", &T, &A);
	
	REP(i,n-1) {
		long long t, a;
		scanf("%lld %lld", &t, &a);

		long long m1 = (T+t-1) / t;
		long long m2 = (A+a-1) / a;
		long long m = max(m1,m2);

		T = m*t;
		A = m*a;
	}

	printf("%lld\n", T+A);
}


int main() {
    solve();
}




Measured memory_bytes: 256
/* @ by batr (T) */
#include <bits/stdc++.h>
 
#define ll long long
#define pb push_back
#define mp make_pair
#define all(X) (X).begin(), (X).end()
 
#define cmp_all(X) (X).begin(), (X).end(), cmp
 
#define B begin()
#define E end()
#define sz size()
#define skip continue
 
#define ppi pair<pair<int, int>, int>
#define pii pair<int, int> 
#define pli pair<ll, int>
#define pcc pair<char, char>
 
#define F first
#define S second

using namespace std;
 
const int maxn = 1e7 + 17;
const int MAXN = maxn * 4;
const int darr = 1e3 + 17;
const ll INF = 1e17 + 5;
const int mod = 1e9 + 7;
 
void Need_For_Speed () {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
}

int n;
ll x[300005];

int main () {
	Need_For_Speed();
	cin >> n;
	for (int i = 1; i <= n * 3; i++) {
		cin >> x[i];
	}
	ll ans = 0;
	sort(x + 1, x + n + n + n + 1);
	for (int i = n + n + n - 1; i >= n; i -= 2) {
		ans += x[i];
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 2560
import java.util.Scanner

/**
  * Created by goryudyuma on 2017/07/16.
  */

object Main {

  def solve(sc: Scanner): Unit = {
    val n: Int = sc.nextInt()
    if (n != 0) {
      sc.nextLine()
      val S: Array[String] = sc.nextLine().split(" ")
      var m: scala.collection.mutable.Map[String, Int] = scala.collection.mutable.Map[String, Int]()

      for (s <- S) {
        m = m + (s -> 0)
      }

      var ans = "";
      var ansnum = -1
      for (i <- 0 until n) {

        m = m + (S(i) -> (m(S(i)) + 1))

        var num1 = 0
        var num2 = 0
        var str1 = ""
        var str2 = ""
        for (kv <- m) {
          var (k, v) = kv
          if (num1 < v) {
            val tmp = num1
            num1 = v
            v = tmp

            val tmp2 = str1
            str1 = k
            k = tmp2
          }

          if (num2 < v) {
            val tmp = num2
            num2 = v
            v = tmp

            val tmp2 = str2
            str2 = k
            k = tmp2
          }
        }

        if (ans.equals("") && num2 + n - i - 1 < num1) {
          ans = str1
          ansnum = i + 1
        }
      }

      if (ansnum == -1) {
        println("TIE")
      } else {
        println(ans + " " + ansnum)
      }
      solve(sc)
    }
  }

  def main(args: Array[String]): Unit = {
    val sc: Scanner = new Scanner(System.in)
    solve(sc)
  }
}

Measured memory_bytes: 129232
n =int(input())
s = list(map(str,input()))
l=[]
for i in range(len(s)):
    if ord(s[i])>=91-n:
        l.append(chr((ord(s[i])-26+n)))
    else:
        l.append(chr((ord(s[i])+n)))

print(''.join(l))

Measured memory_bytes: 3188
#include <float.h>
#include <inttypes.h>
#include <limits.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <math.h>
#ifdef __cplusplus
#include <bits/stdc++.h>
#endif

uint32_t nextpint(void){ char c=getchar_unlocked(); while(c<'0'||'9'<c) c=getchar_unlocked(); uint32_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar_unlocked(); } return x; }
uint64_t nextplong(void){ char c=getchar_unlocked(); while(c<'0'||'9'<c) c=getchar_unlocked(); uint64_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar_unlocked(); } return x; }
void printint(int32_t x){ if(x<0){x=-x; putchar_unlocked('-');}else if(x==0){putchar_unlocked('0');} int d=0; char s[10]; while(x){ s[d]='0'+x%10; x/=10; d++; } for (int i=d-1; i>=0; i--) putchar_unlocked(s[i]); putchar_unlocked('\n'); }
void printlong(int64_t x){ if(x<0){x=-x; putchar_unlocked('-');}else if(x==0){putchar_unlocked('0');} int d=0; char s[20]; while(x){ s[d]='0'+x%10; x/=10; d++; } for (int i=d-1; i>=0; i--) putchar_unlocked(s[i]); putchar_unlocked('\n'); }

int main(void){
	uint32_t t1=nextpint();
	uint32_t t2=nextpint();
	int64_t a1=nextplong();
	int64_t a2=nextplong();
	int64_t b1=nextplong();
	int64_t b2=nextplong();
	int64_t d1=(a1-b1)*t1;
	int64_t d2=(a2-b2)*t2;
	int64_t d=d1+d2;
	if(d==0){
		puts("infinity");
	}else if((d1<0)==(d<0)){
		puts("0");
	}else{
		d1=-d1;
		int64_t ans=d1/d*2+(d1/d*d!=d1);
		printlong(ans);
	}
}


Measured memory_bytes: 128
n, c = map(int, input().split())
X, V, right, left, rl, lr = [], [], [], [], [], []

calsum = 0
for _ in range(n):
    x, v = map(int, input().split())
    X.append(x)
    V.append(v)
    calsum += v
    right.append(calsum-x)
    rl.append(calsum-2*x)

calsum = 0
for i in range(n):
    calsum += V[n-i-1]
    left.append(calsum - (c-X[n-i-1]))
    lr.append(calsum - 2*(c-X[n-i-1]))

M = max(0, max(right), max(left))
m = 0
for i in range(0, n-1):
    m = max(m, left[i])
    M = max(M, m + rl[n-i-2])

m = 0
for i in range(0, n-1):
    m = max(m, right[i])
    M = max(M, m + lr[n-i-2])

print(M)


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

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

  if (a == 1 && b == 2 || a == 2 && b == 1) {
    cout << "3";
  } else if (a == 2 && b == 3 || a == 3 && b == 2) {
    cout << "1";
  } else if (a == 1 && b == 3 || a == 3 && b == 1) {
    cout << "2";
  }

  return 0;
}

Measured memory_bytes: 256
from collections import Counter

N = int(input())

sosu = []
while N % 2 == 0:
    sosu.append(2)
    N = int(N/2)

f = 3
while f * f <= N:
    while N % f == 0:
        sosu.append(f)
        N = int(N/f)
    f += 2
if N != 1: sosu.append(N)

count = Counter(sosu)

ans = 0
for k,v in count.items():
    beki = 1
    while beki <= v:
        ans += 1
        v -= beki
        beki += 1
print(ans)


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

const int lim = 10e5 + 5;
const int INF = 10e9 + 5;

void minSelf(int &a, int b) {
	a = min(a,b);
	return;
}

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

	int a1,b1,c1;
	cin>>a1>>b1>>c1;

	for (i=1;i<n;i++) {
		int a,b,c;
		cin>>a>>b>>c;
		
		int a2,b2,c2;
		a2=a1; b2=b1; c2=c1;

		a1 = a+max(b2, c2);
		b1 = b+max(a2, c2);
		c1 = c+max(a2, b2);
	}

	cout<<max(max(a1,b1),c1)<<"\n";

	return 0;
}

Measured memory_bytes: 256
N = input().strip()
n = len(N)
A = [0 for _ in range(n)]
A[0]=1
for i in range(1,n):
    if N[i]=="0":
        A[i] = A[i-1]
    else:
        A[i] = A[i-1]+1
K = int(input())
if K>n:
    print(0)
else:
    dp = [[[0 for _ in range(n+1)] for _ in range(2)] for _ in range(n+1)]
    dp[0][0][0] = 1
    for i in range(1,n+1):
        for k in range(n+1):
            if k==A[i-1]:
                dp[i][0][k] = 1
                break
    for i in range(1,n+1):
        for k in range(n+1):
            dp[i][1][k] = dp[i-1][1][k]
            if int(N[i-1])>0:
                dp[i][1][k] += dp[i-1][0][k]
            if k>=1:
                dp[i][1][k] += dp[i-1][1][k-1]*9
                if i==1 and k-1==0 and int(N[i-1])>=2:
                    dp[i][1][k] += dp[i-1][0][k-1]*(int(N[i-1])-1)
                elif i>=2 and k-1==A[i-2] and int(N[i-1])>=2:
                    dp[i][1][k] += dp[i-1][0][k-1]*(int(N[i-1])-1)
    print(dp[n][0][K]+dp[n][1][K])

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

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if (a == b)
		cout << c;
	else if (b == c)
		cout << a;
	else 
		cout << b;
}

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


int main()
{
    string s;
    cin >> s;
    int res = 0;
    for(auto c : s) {
        int d = c - '0';
        res = (res + d) % 9;
    }
    cout << (res?"No":"Yes") << endl;
    return 0;
}

Measured memory_bytes: 3600
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

int main(){
  string s;
  int oo=1;
  while(cin >> s){
    
    long long int jm=0,om=0,im=0;
    int ans2,ans=0;

    for(int i=0;i<s.length();i++){
      //cout << jm <<" " << om <<" " << im << endl;
      if(s[i] == 'J'){
	oo=1;
	//cout << "OK" << endl;
	++jm;
	if(s[i+1] != 'O' && s[i+1] != 'J'){
	  oo=0;
	  jm=0;
	  om=0;
	  im=0;
	}
	continue;
      }

      if(s[i] == 'O' && oo == 1){
	++om;
	if((s[i+1] != 'I' && s[i+1] != 'O') || om > jm){
	  oo=0;
	  jm=0;
	  om=0;
	  im=0;
	}
	continue;
      }

      if(s[i] == 'I' && oo == 1){
	++im;
       

	if((s[i+1] != 'I' || (s[i] == 'I' && i == (s.length()-1))) ){
	 
	  int minn = min(jm,min(om,im));
	  ans2 = minn;
	  if(om > im){
	    oo=0;
	    jm=0;
	    im=0;
	    om=0;
	    ans2=0;
	    continue;
	  }

	  if(ans2 > ans)ans = ans2;
	  jm=0;
	  im=0;
	  om=0;
	  oo=1;
	}
      }




    }
  
    cout << ans << endl;

}

    return 0;






}

Measured memory_bytes: 1984
import java.util.*;
import java.io.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        FastScanner sc = new FastScanner(System.in);
        String s = sc.next();
        if(Integer.parseInt(s.substring(0,2)) > 0 && Integer.parseInt(s.substring(0,2)) <= 12){
            if(Integer.parseInt(s.substring(2,4)) > 0 && Integer.parseInt(s.substring(2,4)) <= 12){
                System.out.println("AMBIGUOUS");
            }else{
                System.out.println("MMYY");
            }
        }else if(Integer.parseInt(s.substring(2,4)) > 0 && Integer.parseInt(s.substring(2,4)) <= 12){
            System.out.println("YYMM");
        }else{
            System.out.println("NA");
        }
    }
}

class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;
    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

    public String next() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken("\n");
    }

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

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

    public double nextDouble() {
         return Double.parseDouble(next());
    }
    
    public String[] nextArray(int n) {
        String[] a = new String[n];
        for (int i = 0; i < n; i++)
            a[i] = next();
        return a;
    }

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }

    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nextLong();
        return a;
    } 
}


Measured memory_bytes: 25300
A = int(input())
B = int(input())
C = int(input())
X = int(input())
count=0
for a in [a*500 for a in range(A + 1)]:
    for b in [b*100 for b in range(B + 1)]:
        for c in [c*50 for c in range(C + 1)]:
            if a + b + c == X:
                count += 1
print(count)

Measured memory_bytes: 3060
#include <stdio.h>

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

  int m, p, x;
  scanf("%d", &m);
  for (i=0; i<m; i++) {
    scanf("%d %d", &p, &x);

    printf("%d\n", sum+x-T[p-1]);
  }
  return 0;
}

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

int main(){
  int x;
  cin>>x;
  for(int i=1;i<=9;i++){
    if(x%i==0 && x/i<=9){
      cout<<"Yes"<<endl;
      return 0;
    }
  }
  cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;

int main() {
  char b;
  cin >> b;
  if (b == 'A') cout << 'T' << endl;
  if (b == 'T') cout << 'A' << endl;
  if (b == 'C') cout << 'G' << endl;
  if (b == 'G') cout << 'C' << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
typedef long long int ll;
using namespace std;
const ll MOD = 1000000007;

ll modpow(int a, int b) {
  ll ans = 1;
  ll x = a;
  int y = b;
  while (y) {
    if (y & 1) {
      ans *= x;
      ans %= MOD;
    }
    x *= x;
    x %= MOD;
    y >>= 1;
  }
  return ans;
}

int main() {
  int N, A[10000], c[1000001] = {};
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    int x = A[i];
    for (int j = 2; j * j <= x; j++) {
      int e = 0;
      while (x % j == 0) {
        x /= j;
        e++;
      }
      c[j] = max(c[j], e);
    }
    if (x > 1) {
      c[x] = max(c[x], 1);
    }
  }
  ll lcm = 1;
  for (int i = 2; i <= 1000000; i++) {
    if (c[i] > 0) {
      lcm *= modpow(i, c[i]);
      lcm %= MOD;
    }
  }
  ll ans = 0;
  for (int i = 0; i < N; i++) {
    ans += modpow(A[i], MOD - 2);
    ans %= MOD;
  }
  ans *= lcm;
  ans %= MOD;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4856
#include <bits/stdc++.h>
using namespace std;
#define ll long long
// #define maxLim 65530

#define inchar			getchar//_unlocked
#define outchar(x)		putchar(x)//_unlocked(x)

template<typename T> void inpos(T &x) {
	x = 0;
	register T c = inchar();
	while(((c < 48) || (c > 57)) && (c != '-')) c = inchar();
	bool neg = false;
	if (c=='-') neg = true;
	for(; c < 48 || c > 57; c = inchar()) ;
	for(; c > 47 && c < 58; c = inchar()) {
		x = (x<<3) + (x<<1) + (c&15);
	}
	if(neg) x = -x;
}

template<typename T> void outpos(T n) {
	if(n < 0) { outchar('-'); n *= -1; }
	char snum[65];
	int i = 0;
	do {
		snum[i++] = n % 10 + '0';
		n /= 10;
	} while(n);
	i = i - 1;
	while (i >= 0) outchar(snum[i--]);
}
double tick() { 
	static clock_t oldticks;
	clock_t newticks = clock();
	double diff = 1.0 * (newticks - oldticks) / CLOCKS_PER_SEC; 
	oldticks = newticks;
	return diff;
}

// map <pair <ll, ll> , ll > dp; // n, wt, correspomding answer
// map is quite slow
// knapsack 
// yaani same n , wt change hoga
// pahel
ll dp[105][100005]; 

ll calculate (ll wt, ll *value , ll * weight , ll n ) { // wt signifies available weight we can take
	if (n<0 || wt == 0) {
		return 0;
	}
	ll answer;
	if (dp[n][wt] !=0) { // mil gaya
		return dp[n][wt];
	}

	if (weight[n] > wt) {
		answer = calculate (wt,value,weight,n-1);
		// cout << x <<endl;
		// return x;
	} else { // do choice is le lo fir value get karo , is na lo fir value guess karo , 
		answer = (max (value[n]  + calculate(wt - weight[n] , value, weight , n-1), calculate (wt,value,weight,n-1)  ));
	}
	dp [n][wt] = answer;
	// 
	return answer;
	
}


int main () { // 
	
	ll n ,w;
	inpos (n); inpos(w);
	// 
	ll value[n]; ll weight[n];
	for (int i = 0;i<n;i++) {
		inpos(weight[i]);
		inpos	(value[i]);
		// outpos(value[i]);s
	}
	outpos(calculate (w, value, weight,n-1));
	// cout << calculate (w, value, weight,n-1)<<endl;

}

Measured memory_bytes: 80256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<vector>
#include<map>
#include<cmath>
#define ll long long
#define INF 0x3f3f3f3f
#define maxn 1000005
using namespace std;
ll n,p,num;
ll prime[maxn];
ll ans=1;
bool isprime[maxn];
int main()
{
	for(ll i=2;i<=maxn;++i)
	{
		if(!isprime[i])
		{
			prime[++num]=i;
		}
		for(int j=1;j<=num&&prime[j]*i<maxn;++j)
		{
			isprime[prime[j]*i]=1;
			if(i%prime[j]==0)break;
		}
	}
	scanf("%lld%lld",&n,&p);
	if(n==1)printf("%lld\n",p);
	else
	{
		ll asd=1;
		for(int i=1;i<=num&&prime[i]<=p/prime[i];++i)
		{
			ll now=0;
			while(p%prime[i]==0)
			{
				p/=prime[i];
				now++;
			}
			asd=asd*pow((double)prime[i],(double)(now/n));
		}
		printf("%lld\n",asd);
	}
    return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define  ll  long long
const int N=2e5+2;
int a[N];
int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int i,n,l=-1,r=-1;
    cin>>n;
    for(i=0;i<n;i++)
    {
        cin>>a[i];
    }
    sort(a,a+n,greater<int>());
    for(i=0;i<(n-1);i++)
    {
        if(a[i]==a[i+1])
        {
            if(l==-1)
            {
                l=a[i];
                i++;
            }
            else
            {
                r=a[i];
                break;
            }
        }
    }
    if(l==-1 || r==-1)
    {
        l=0;
    }
    cout<<((ll)l*(ll)r)<<"\n";
    return 0;
}

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

int main () {
  ll N;
  cin >> N;
  
  ll ans = N-1;
  for (ll i = sqrt(N); 1 <= i ; i--) {
    if (N%i == 0) {
      ans = min(ans, i+N/i-2);
      break;
    }
  }
  cout << ans << endl;
}

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

int main() {
  int h1, m1;
  int h2, m2;
  int k;
  cin >> h1 >> m1 >> h2 >> m2 >> k;
  int t1 = h1 * 60 + m1;
  int t2 = h2 * 60 + m2;
  if (t2 < t1)
    t2 += 24 * 60;
  cout << (t2 - t1 - k) << "\n";

  return 0;
}


Measured memory_bytes: 3200
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>

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

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef pair<long long, int> pli;

const int INF = 1 << 30;
const long long INFL = 1LL << 60;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 100000;

vector<pli> G[N];
long long ans[N];
long long d[N];

int main() {
	int n;cin>>n;
	rep(i,n-1) {
		int a,b,c;cin>>a>>b>>c;a--;b--;
		G[a].push_back(pli(c,b));
		G[b].push_back(pli(c,a));
	}
	int q,k;cin>>q>>k;k--;
	priority_queue<pli, vector<pli>, greater<pli>> Q;
	Q.push(pli(0,k));
	rep(i,n) d[i]=INFL;
	d[k]=0;
	while(!Q.empty()){
		pli p = Q.top();Q.pop();
		for(auto i:G[p.second]) {
			if(d[i.second]>d[p.second]+i.first) {
				d[i.second]=d[p.second]+i.first;
				Q.push(i);
			}
		}
	}
	rep(i,q) {
		int x,y;cin>>x>>y;x--;y--;
		ans[i]=d[x]+d[y];
	}
	rep(i,q) cout << ans[i] << endl;
}


Measured memory_bytes: 11632
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define MOD 1000000007
#define EPS (1e-10)
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

int cnt[50];
int main(){
	int n,m;cin>>n>>m;
	rep(i,n){
		int k;scanf("%d",&k);
		rep(j,k){
			int a;scanf("%d",&a);a--;
			cnt[a]++;
		}
	}
	int ans=0;
	rep(i,m){
		if(cnt[i]==n)ans++;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;
const ll inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;

int h, w;
int dx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
int dy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
vector<string> s(100);

int main()
{
    cin >> h >> w;
    for (int i = 0; i < h; i++)
        cin >> s[i];
    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            if (s[i][j] == '#')
            {
                cout << s[i][j];
                continue;
            }
            int num = 0;
            for (int k = 0; k < 8; k++)
            {
                int ni = i + dy[k];
                int nj = j + dx[k];
                if (ni < 0 || ni >= h)
                    continue;
                if (nj < 0 || nj >= w)
                    continue;
                if (s[ni][nj] == '#')
                    num++;
            }
            cout << num;
        }
        puts("");
    }
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
long long l[100000];
int main()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>l[i];
    }
    sort(l+1,l+1+n);
    long long ans=0;
    for(int i=1;i<n;i++)
    {
        for(int j=i+1;j<=n;j++)
        {
            for(int k=j+1;k<=n;k++)
            {
                if(l[i]+l[j]>l[k])
                {
                    ans++;
                }
            }
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
while True:
  n = int(input())
  if n == 0:
    break
  D = dict()
  for _ in range(n):
    k,v = input().rstrip().split()
    D[k] = v
  m = int(input())
  ans = ""
  for _ in range(m):
    s = input().rstrip()
    if s in D:
      s = D[s]
    ans = ans + s
  print(ans)


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

int main() {

	int S, h, m, s,x,y;

	cin >> S;
	
	h = S / 3600;
	x = S - (h * 3600);

	m = x / 60;
	y = x - (m * 60);

	s = y;


	cout << h <<":"<< m <<":"<< s << endl;
	return 0;
}

Measured memory_bytes: 3092
K, X = map(int, input().split())
black = []
if X - K + 1 < -1000000:
  for i in range(-1000000, K):
    black.append(i)
elif X + K -1 > 1000000:
  for i in range(1000000-K+1, K):
    black.append(i)
else:
  for i in range(X - K + 1, X + K):
    black.append(i)
print(*black)

Measured memory_bytes: 3060
n = int(input())
Str = ""
while n != 0:
    r = n % 2
    if r < 0:
        r += 2
    n = (n-r) // (-2)
    Str += str(r)
tmp = list(reversed(list(Str)))
ans = "".join(tmp)
if Str == "":
    print(0)
    exit()
print(ans)



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

typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;
#define MP make_pair
#define PB push_back
#define X first
#define Y second

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())
#define FILL(a, value) memset(a, value, sizeof(a))
#define debug(a) cerr << #a << " = " << a << endl;

template<typename T> void setmax(T& x, T y) {x = max(x, y);}
template<typename T> void setmin(T& x, T y) {x = min(x, y);}

const double PI = acos(-1.0);
const LL INF = 1e9 + 47;
const LL LINF = INF * INF;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	
	int h, w, n;
	cin >> h >> w >> n;
	if (h < w) swap(h, w);
	
	int ans = (n + h - 1) / h;
	cout << ans << endl;
	
	cerr << "Time elapsed: " << clock() / (double)CLOCKS_PER_SEC << endl;
	return 0;
}



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

int dp[105][105];
int m;

void fill(int i, int j){
  dp[i][j] = 1;

  if(j != 0) dp[i][j - 1] = 1;

  if(j != m-1) dp[i][j + 1] = 1;

}


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

  string c[105];

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

  for(int i=0;i<n;i++){

    for(int j = 0; j < m; j++){

      if(c[i][j] == 'o') fill(i, j);

      if(c[i][j] == 'x'){
	fill(i, j);
	if(i != 0) fill(i-1, j);
	if(i != n-1) fill(i+1, j);

      }
    }
  }

  int cnt = 0;

  for(int i = 1; i < n; i++){
    for(int j = 0; j < m; j++){
      if(dp[i][j] == 0) cnt++;
    }
  }

  cout << cnt << endl;

  return 0;

}



Measured memory_bytes: 3228
#include <bits/stdc++.h>
using namespace std;
using lint = int64_t;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define all(v)    begin(v), end(v)
#define in        []{lint n; cin>>n; return n;}()

const int mod = 1e9+7;

template< int mod >
struct ModInt {
  int x;

  ModInt() : x(0) {}

  ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}

  ModInt &operator+=(const ModInt &p) {
    if((x += p.x) >= mod) x -= mod;
    return *this;
  }

  ModInt &operator-=(const ModInt &p) {
    if((x += mod - p.x) >= mod) x -= mod;
    return *this;
  }

  ModInt &operator*=(const ModInt &p) {
    x = (int) (1LL * x * p.x % mod);
    return *this;
  }

  ModInt &operator/=(const ModInt &p) {
    *this *= p.inverse();
    return *this;
  }

  ModInt operator-() const { return ModInt(-x); }

  ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }

  ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }

  ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }

  ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }

  bool operator==(const ModInt &p) const { return x == p.x; }

  bool operator!=(const ModInt &p) const { return x != p.x; }

  ModInt inverse() const {
    int a = x, b = mod, u = 1, v = 0, t;
    while(b > 0) {
      t = a / b;
      swap(a -= t * b, b);
      swap(u -= t * v, v);
    }
    return ModInt(u);
  }

  ModInt pow(int64_t n) const {
    ModInt ret(1), mul(x);
    while(n > 0) {
      if(n & 1) ret *= mul;
      mul *= mul;
      n >>= 1;
    }
    return ret;
  }

  friend ostream &operator<<(ostream &os, const ModInt &p) {
    return os << p.x;
  }

  friend istream &operator>>(istream &is, ModInt &a) {
    int64_t t;
    is >> t;
    a = ModInt< mod >(t);
    return (is);
  }

  static int get_mod() { return mod; }
};

using modint = ModInt< mod >;

modint memo[10000] = {0};
modint fact( int n ) {
    if( n == 1 || n == 0 ) return 1;
    if( memo[n] != 0 ) {
        return memo[n];
    }
    return fact(n-1) * n;
}

modint c( int n, int r ) {
    return fact(n) / fact(r) / fact(n-r);
}
//
//  nこをmこに分ける通り
modint f( int n, int m ) {
    if( n < m || m==0 ) return 0;
    if( n==m ) return 1;
    return c(n-1,m-1);
}

int main() { cin.tie(0); ios::sync_with_stdio(false);
    int N = in, Blue = in, Red = N-Blue;

    if( N==Blue ) {
        cout << "1\n";
        rep( i, Blue-1 ) cout << "0\n";
        return 0;
    }

    for( int i=1; i<=Blue; i++ ) {
        modint tmp = 0;
        if( Red >= i-1 ) tmp += f(Red,i-1);
        if( Red >= i   ) tmp += f(Red,i)*2;
        if( Red >= i+1 ) tmp += f(Red,i+1);

        cout << (f(Blue,i) * tmp) << "\n";
    }

}


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

#define reps(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   reps(i,0,n)
#define all(x) (x).begin(),(x).end()
#define INF (1000000000)
#define MOD (1000000007)
#define PI (acos(-1))

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


Measured memory_bytes: 256
A, B, K = map(int, input().split())
for k in range(K):
  if k % 2 == 0:
    if A % 2 == 1:
      A -= 1
      
    B += A // 2    
    A -= A // 2
 
  else:
    if B % 2 == 1:
      B -= 1
    A += B // 2    
    B -= B // 2

print(A, B)

Measured memory_bytes: 2940
def linearSearch(S, T):
    cnt = 0
    for e in T:
        if e in S:
            cnt += 1
    return cnt


def main():
    n = int(input())
    s = list(map(int, input().split()))
    q = int(input())
    t = list(map(int, input().split()))

    print(linearSearch(s, t))

if __name__ == "__main__":
    main()

Measured memory_bytes: 8612
s = input()
k = 'keyence'
flg_pre = 0
flg_post = 0
pre_match = 0
post_match = 0
if s[:6] == k or s[-7:] == k:
  print('YES')
else:
  for i in range(6):
    if s[i] == k[i] and flg_pre == 0:
      pre_match = i + 1
    else:
      flg_pre = 1
    if s[-i-1] == k[-i-1] and flg_post == 0:
      post_match = i + 1
    else:
      flg_post = 1
  if  pre_match + post_match >= 7:
    print('YES')
  else:
    print('NO')

Measured memory_bytes: 3064
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <set>
#include <functional>
#include <cmath>
#include <numeric>
#include <iterator>
#include <fstream>

#define SIZE 100005
#define MOD 1000000007

using namespace std;

class BPapersPlease {
public:
  static void solve(std::istream &cin, std::ostream &cout) {
    int n;
    cin >> n;
    vector<int> a_vec(n);
    for (int i = 0; i < n; ++i) cin >> a_vec[i];
    bool flag = true;
    for (const auto &a : a_vec) {
      if (a % 2 == 0) {
        if (!(a % 3 == 0 || a % 5 == 0)) {
          flag = false;
          break;
        }
      }
    }
    if (flag)cout << "APPROVED" << endl;
    else cout << "DENIED" << endl;
  }
};


int main() {
    BPapersPlease solver;
    std::istream& in(std::cin);
    std::ostream& out(std::cout);
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
struct node{int w,s,v;} a[10005];
int n,dp[10000005],ans;
int cmp(node a,node b){return a.w+a.s<b.w+b.s;}
signed main(){
	cin>>n;
	for(int i=1;i<=n;i++)	cin>>a[i].w>>a[i].s>>a[i].v;
	sort(a+1,a+n+1,cmp);
	for(int i=1;i<=n;i++)
		for(int j=a[i].s;j>=0;j--)
			dp[j+a[i].w]=max(dp[j+a[i].w],dp[j]+a[i].v);
	cout<<*max_element(dp,dp+10000000)<<endl;
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
string s1,s2;
long long k,ans;
int main()
{
	cin>>s1>>s2;
	for(k=0;k<s1.size();k++)
	{
		if(s1[k]!=s2[k])
		{
			ans++;
		}
	}
	cout<<ans;
}

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

using namespace std;

string LCS(string s, string t) {
	int i, j;
	int dp[s.size() + 1][t.size() + 1];
	for (i = 0; i <= s.size(); i++) {
		for (j = 0; j <= t.size(); j++) {
			if (i == 0 or j == 0) {
				dp[i][j] = 0;
			}
			else if (s[i - 1] == t[j - 1]) {
				dp[i][j] = dp[i - 1][j - 1] + 1;
			}
			else {
				dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
			}
		}
	}
	string answer;
	i = s.size();
	j = t.size();
	while (i > 0 and j > 0) {
		if (s[i - 1] == t[j - 1]) {
			answer += s.substr(i - 1, 1);
			i--; j--;
		}
		else if (dp[i - 1][j] > dp[i][j - 1]) {
			i--;			
		}
		else {
			j--;
		}
	}
	reverse(answer.begin(), answer.end());
	return answer;
}
int main() {
    string s, t;
    cin >> s >> t;
    cout << LCS(s, t);
    return 0;
}

Measured memory_bytes: 35456
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
#define rep(i,j,k) for(int i = (int)j;i <= (int)k;i ++)
#define per(i,j,k) for(int i = (int)j;i >= (int)k;i --)
#define debug(x) cerr<<#x<<":"<<x<<endl
#define pb push_back
#define FAST_IO ios::sync_with_stdio(0); cin.tie(0)
#define Decimal fixed<<setprecision(20)
#define int long long
//INSERT ABOVE HERE
typedef double db;

signed main(){
    FAST_IO;
    db a,b;
    cin>>a>>b;
    a--,b--;
    cout<<(b==0?0:ceil(b/a))<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>

using namespace std;

long long N, A, B;

void solve()
{
    if (N < A + B - 1 || A * B < N) {
        cout << -1;
        return;
    }
    
    while (N > 0) {
	long long x = min(A, N - B + 1);
	for (long long i = N - x + 1; i <= N; ++i) cout << i << " ";
	N -= x;
        --B;
    }
}

int main()
{
    cin >> N >> A >> B;
    solve();

    return 0;
}

Measured memory_bytes: 2176
n = int(input())
A = list(map(int, input().split()))
X = [0]*8
y = 0

for a in A:
    if 1 <= a <= 399:
        X[0] = 1
    elif 400 <= a <= 799:
        X[1] = 1
    elif 800 <= a <= 1199:
        X[2] = 1
    elif 1200 <= a <= 1599:
        X[3] = 1
    elif 1600 <= a <= 1999:
        X[4] = 1
    elif 2000 <= a <= 2399:
        X[5] = 1
    elif 2400 <= a <= 2799:
        X[6] = 1
    elif 2800 <= a <= 3199:
        X[7] = 1
    else:
        y += 1

if sum(X) == 0:
    print(1, y)
else:
    print(sum(X), sum(X)+y)


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

using namespace std;
using vi = vector<int>;

const int MAX_N = 2e5;

int counts[MAX_N + 1];
int N, K;

int main() {
	ios_base::sync_with_stdio(false);
	memset(counts, 0, sizeof(counts));
	cin >> N >> K;
	for (int i = 0; i < N; i++) {
		int a; cin >> a;
		counts[a]++;
	}
	vi sorted_counts;
	int s = 0;
	for (int i = 0; i <= MAX_N; i++) {
		if (counts[i]) {
			sorted_counts.push_back(counts[i]);
			s++;
		}
	}
	sort(sorted_counts.begin(), sorted_counts.end());
	int cost = 0;
	if (s - K <= 0) {
		cout << 0 << endl;
		return 0;
	}
	for (int i = 0; i < s - K; i++) {
		cost += sorted_counts[i];
	}
	cout << cost << endl;
	return 0;
}

Measured memory_bytes: 2168
N,u,v = map(int, input().split())
if u == v:
  print(0)
  exit()
  
ver= [[] for i in range(N)]

for i in range(N-1):
    a, b = map(int, input().split())
    ver[a-1].append(b-1)
    ver[b-1].append(a-1)
    
    
def bfs(start):
    dist_turn = [float('inf') for i in range(N)]
    dist_turn[start] = 0
    visited = set()
    visited.add(start)
    turn = 0
    prev_dists = [start]
    new_dists = []
    while len(prev_dists) != 0:
        turn += 1
        for prev_dist in prev_dists:
            for new_dist in ver[prev_dist]: 
                if new_dist not  in visited:
                    visited.add(new_dist)
                    new_dists.append(new_dist)
                    dist_turn[new_dist] = turn
        prev_dists = new_dists
        new_dists = []
    return dist_turn

u_shortest = bfs(u-1)
v_shortest = bfs(v-1)

max_dist = -1
for i in range(N):
    if u_shortest[i] < v_shortest[i]:
        max_dist = max(max_dist, v_shortest[i])
print(max_dist - 1)

Measured memory_bytes: 36568
#include <iostream>
#include <vector>
#include <string>
using namespace std;

int main()
{
	vector<char> vec;
	string line;
	vector<string> input;
	int H, W;
	
	cin >> H >> W;

	for (int i = 0; i < H; i++) {
		cin >> line;
		input.push_back(line);
	}

	input.insert(input.begin(), string(W, '#'));
	input.push_back(string(W, '#'));
	for (string& s : input) {
		s = '#' + s + '#';
	}


	for (string s : input) {
		cout << s << endl;
	}

	return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;



class Main{
    //読み込みのテンプレ(stringオブジェクトまで)
    
    static int number;
    static int[] linenumbers;
    
    
    public static void main(String[] args) throws IOException{
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        //Integer that shows the number of the lines
        String strnumber = reader.readLine();
        int number = Integer.parseInt(strnumber);
        
        //System.out.println(number);
        
        int[] linenumbers = new int[number];
        
        for(int i=0;i<number;i++){
            linenumbers[i] = Integer.parseInt((String)reader.readLine());
        }
        int prime_number=0;
        
        for(int i=0;i<linenumbers.length;i++){
            if(isPrime(linenumbers[i]))prime_number++;
        }
        
        System.out.println(prime_number);
    }
    
    public static boolean isPrime(int n){
        if(n==2)return true;
        else if(n%2==0)return false;
        else if(n<9)return true;
        else{
            for(int i =3;i*i<=n;i+=2){
                if(n%i==0)return false;
            }
            return true;
        
        }
    
    }
    
    
}

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

int c[6], cost[110][1 << 6], m, n, k, d;
struct st {
	int a, b, c;
}v[600];
int num(string s) {
	if (s == "H")return m + n;
	if (s == "D")return m + n + 1;
	if (s[0] == 'C')return s[1] - '1';
	return stoi(s.substr(1)) - 1 + m;
}
int main() {
	while (scanf("%d%d%d%d", &m, &n, &k, &d), m) {
		rep(i, m)scanf("%d", &c[i]);
		rep(i, d) {
			string s, t; int e; cin >> s >> t >> e; e *= k;
			int a = num(s), b = num(t);
			v[i * 2] = { a,b,e };
			v[i * 2 + 1] = { b,a,e };
		}
		memset(cost, 0x3f, sizeof(cost));
		cost[m + n][0] = 0;
		bool update = true;
		while (update) {
			update = false;
			rep(j, 2 * d) {
				st e = v[j];
				rep(i, 1 << m) {
					if (cost[e.a][i] == INF)continue;
					if (e.b < m) {
						if (!(i >> e.b & 1) && cost[e.b][i | 1 << e.b] > cost[e.a][i] + e.c - c[e.b])
							cost[e.b][i | 1 << e.b] = cost[e.a][i] + e.c - c[e.b], update = true;
					}
					else if (cost[e.b][i] > cost[e.a][i] + e.c)
						cost[e.b][i] = cost[e.a][i] + e.c, update = true;
				}
			}
		}
		int Min = INF;
		rep(i, 1 << m)Min = min(Min, cost[m + n + 1][i]);
		printf("%d\n", Min);
	}
}

Measured memory_bytes: 3288
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
#include <iomanip>
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
const ll MOD=1000000007;
const ll MAX_N=500010;
const ll INF=999999999999;

int main(){
    int s;
    cin>>s;
    int cnt=1;
    int ans;
    if(s==1 || s==2){
        cout<<4<<endl;
        return 0;
    }

    while(1){
        if(s==4){
            ans=cnt+3;
            break;
        }

        if(s%2==0){
            s/=2;
        }else{
            s=s*3+1;
        }
        cnt++;
    }  
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(k,i,n) for(ll i=k;i<n;++i)
int main(void){
    ll n,r;
    cin>>n>>r;
    if(10<=n){
        cout<<r<<endl;
    }else{
        cout<<r+100*(10-n)<<endl;
    }
    
}


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

ll n, a[200005], cur, ans;
vector<ll> st;

int main()
{
	scanf("%lld",&n);
	for(ll i=1;i<=n;i++) {
		scanf("%lld",&a[i]);
	}
	st.push_back(0);
	for(ll i=1;i<=n;i++) {
		while(!st.empty()) {
			if(a[st.back()] >= a[i]) {
				ll T = st.back(); st.pop_back();
				cur -= (T - st.back()) * a[T];
			}
			else break;
		}
		cur += (i - st.back()) * a[i];
		st.push_back(i);
		ans += cur;
	}
	printf("%lld\n",ans);
}


Measured memory_bytes: 3956
#include <stdio.h>
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue> 
 
using namespace std;
 
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	double H, N;

	cin >> H >> N;

	vector< pair<int, int> > M(N);

	for(int i = 0; i < N; i++) {
		cin >> M[i].first >> M[i].second;
	}

	vector<int> dp(H + 1, 100000000);

	for(int i = 1; i <= H; i++) {
		for(int j = 0; j < N; j++) {
			int x = M[j].second;
			if(i - M[j].first > 0) x += dp[i - M[j].first];
			if(x < dp[i]) dp[i] = x;
		}
	}

	cout << dp[H] << endl;
}

Measured memory_bytes: 256
import Data.Char -- for words func.
import Control.Monad -- for forM_ replicateM func.
import Numeric 
formatFloatN floatNum numOfDecimals = showFFloat (Just numOfDecimals) floatNum ""

type Vector = (Double, Double)
type Scalar = Double

---------------------------------------------------
-- arithmetic functions for vector calculations. --
---------------------------------------------------
vadd :: Vector -> Vector -> Vector
vadd (x, y) (z, w) = (x + z, y + w)

vsub :: Vector -> Vector -> Vector
vsub (x, y) (z, w) = (x - z, y - w)

vdot :: Vector -> Vector -> Scalar
-- vdot defines dot product for 2D vector.
vdot (x, y) (z, w) = x * z + y * w

smul :: Scalar -> Vector -> Vector
-- smul defines scalar multiplication of 2D vector.
smul a (x, y) = (a * x, a * y)

sqnorm :: Vector -> Scalar
-- calculate squared euclidean norm(sqnorm(x) = ||x||^2).
sqnorm (x, y) = x * x + y * y

projection_point :: Vector -> Vector -> Vector -> Vector
-- find the projection point when p_1, p_2, p are geven.
-- p_1, p_2 are the point on a straight line called l.
-- projection point are defined as the point on the l
-- is the most close to point p.
projection_point p_1 p_2 p
  | p_1 /= p_2 = (a `vdot` b / sqnorm a) `smul` a `vadd` p_1
  | otherwise  = p_1
  where
    a = p_2 `vsub` p_1
    b = p `vsub` p_1

--------------------------------------
-- functions for string formatting. --
--------------------------------------
line2ps :: String -> [Vector]
-- this function formatting line include p_1 and p_2 value
-- to list of p_1 and p_2.
-- e.g.
-- input: "0 0 2 0" -- i.e. "p_1x p_1y p_2x p_2y"
-- output: [(0, 0), (2, 0)] -- i.e. [p_1, p_2]
line2ps line = [p_1, p_2]
  where
    ps = words line
    p_1 = line2p . unwords $ take 2 ps
    p_2 = line2p . unwords $ drop 2 ps

line2p :: String -> Vector
-- transform string to vector.
-- input: "0 1" -- i.e. "p_x p_y"
-- output: (0, 1)
line2p line = p
  where
    ps = words line
    p_x = read (ps!!0) :: Double
    p_y = read (ps!!1) :: Double
    p = (p_x, p_y)

vec2line :: Vector -> String
vec2line (x, y) = (formatFloatN x 8) ++ " " ++ (formatFloatN y 8)

---------------------
-- main statement. --
---------------------
main :: IO()
main = do
  ps <- getLine
  q  <- getLine
  plist <- replicateM (read q) getLine
  let proj p = vec2line $ projection_point ((line2ps ps)!!0) ((line2ps ps)!!1) (line2p p) in putStrLn . init . unlines $ map proj plist


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

using namespace std;

typedef long long ll;

#define FOR(index, init, max) for (int index = (init); index < (max); index++)
#define REP(index, max) for (int index = 0; index < (max); index++)
#define FOREACH(x, array) for (auto&& (x) : array)
#define VECCIN(vec) for (auto&& vec_i : vec) cin >> vec_i
#define VECCOUT(vec) for (const auto& vec_i : vec) cout << vec_i << endl

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

    set<int> d;
    REP(n_i, n) {
        int tmp;
        cin >> tmp;
        d.insert(tmp);
    }

    cout << d.size() << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<math.h>
#include<string>
#include<limits.h>
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
#define nrep(i,a,b) for(int i=a;i<b;i++)
#define mrep(i,a) for(int i=a;i<=0;i++)
#define INF LLONG_MAX
using namespace std;

// .:true #:false
vector<pair<ll,ll> > idou(4);
ll w, h, ans;

void dfs(vector<vector<bool> > &map,ll tate, ll yoko) {
	ans++;
	map[tate][yoko] = false;
	ll t, y;
	rep(i, 4) {
		t = tate+idou[i].first;
		y = yoko+idou[i].second;
		if (0 <= t && t < h && 0 <= y && y < w && map[t][y]) {
			dfs(map,t, y);
		}
	}
}

int main() {

	//???
	idou[0].first = -1;
	idou[0].second = 0;
	//???
	idou[1].first = 0;
	idou[1].second = 1;
	//???
	idou[2].first = 1;
	idou[2].second = 0;
	//???
	idou[3].first = 0;
	idou[3].second = -1;

	while (1) {
		ans = 0;
		cin >> w >> h;
		if (!w && !h) break;
		vector<vector<bool> > map(h, vector<bool>(w));
		ll s_t, s_y;
		rep(i, h) {
			string s; cin >> s;
			rep(j, w) {
				if (s[j] == '@') {
					s_t = i;
					s_y = j;
					map[i][j] = true;
				}
				else map[i][j] = (s[j] == '.');
			}
		}dfs(map,s_t, s_y);
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3192
#define _USE_MATH_DEFINES
#include<iostream>
#include <math.h>
#include <climits>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
using namespace std;

/* sample input

*/
int x, a, b;

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

	if (b - a > x){
		cout << "dangerous ";
	}
	else if (b-a<=0){
		cout << "delicious";
	}
	else{
		cout << "safe ";
	}

	return 0;
}

Measured memory_bytes: 256
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-12;

int N, M, K, H, W, L, R;
//long long int N, M, K, H, W, L, R;

void func(vector<vector<int>>&edge, vector<string>&s, int num = 0, int node = 0) {
	for (auto i : edge[node]) {
		cout << string(num, '.') + s[i] << endl;
		func(edge, s, num + 1, i);
	}
	return;
}

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

	cin >> N;
	vector<vector<int>>edge(N + 1);
	vector<string>s(N + 1);
	for (int i = 1; i <= N; i++) {
		cin >> K;
		edge[K].push_back(i);
		cin >> s[i];
	}
	func(edge, s);
}


Measured memory_bytes: 3488
import math
import itertools
n=int(input())
L=[list(map(int,input().split())) for _ in range(n)]

dis=0
a=0
for x in itertools.permutations(L):
    for i in range(n-1):
        dis+=math.sqrt((x[i][0]-x[i+1][0])**2+(x[i][1]-x[i+1][1])**2)
    a+=1

print(dis/a)


Measured memory_bytes: 40684