akhauriyash/Code-Regression huggingface dataset:
/* ex4_1
   kohei_suzuki */

#include <stdio.h>
#include <math.h>

int main(void){
    double tree, num;
    int pop;

    scanf("%lf %lf",&tree, &num);

    pop = ceil(tree / (num*2 + 1));
    printf("%d\n", pop);

    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define REP(i, m, n) for (int i = (int)(m); i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
typedef long long ll;

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

const long long INF = 1LL << 60;

int main(){
  int n, k; cin >> n >> k;
  vector<int> a(n);
  rep(i, n) cin >> a[i];

  int ans = (n+k-3)/(k-1);
  
  cout << ans << endl;

  return 0;
}


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

int main()
{
  long long N, K;
  cin >> N >> K;
  long ans = (N + K) % K;
  long anstmp = abs((long)(ans - K));

  if(ans > anstmp){
    ans = anstmp;
  }

  cout << ans;

  return 0;
}

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

int main() {
	int H, W, black;
	char map[50][50];
	cin >> H >> W;
	for(int i=0;i<H;i++)cin >> map[i];
	for(int i=0;i<H;i++)for(int j=0;j<W;j++){
		if(map[i][j]=='#')map[i][j]=1;
		else map[i][j]=0;
	}
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			black = 0;
			if(i>0)black += map[i-1][j];
			if(i<H-1)black += map[i+1][j];
			if(j>0)black += map[i][j-1];
			if(j<W-1)black += map[i][j+1];
			if(black == 0 && map[i][j]==1){
				cout << "No" << endl;
				return 0;
			}
		}
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s;
  int q;
  cin>>s>>q;
  int t,f;
  int tcount = 0;
  char c;
  for(int i=0;i<q;i++){
    cin>>t;
    if(t==1){
      tcount++;
    }
    else{
      cin>>f>>c;
      if(f-1==tcount%2){
        s.insert(s.begin(),c);
      }
      else{
        s.push_back(c);
      }
    }
  }
  if(tcount%2==0){
    cout<<s<<endl;
  }
  else{
    reverse(s.begin(),s.end());
    cout<<s<<endl;
  }
  return 0;
}
      

Measured memory_bytes: 900
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

void bubbleSort(string a[], int n) {
	for (int i = 0; i < n; i++) {	/*already sorted a[0, i)*/
		for (int j = n - 1; j > i; j--) {
			if (a[j - 1][1] > a[j][1]) {
				swap(a[j - 1], a[j]);
			}
		}
	}
}

void selectionSort(string a[], int n) {
	for (int i = 0; i < n; i++) {	/*already sorted a[0, i)*/
		int minj = i;
		for (int j = i; j < n; j++) {
			if (a[j][1] < a[minj][1]) {
				minj = j;
			}
		}
		swap(a[i], a[minj]);
	}
}

void println(string s[], int n) {
	for (int i = 0; i < n; i++) {
		cout << s[i];
		if (i + 1 < n) cout << " ";
	}
	cout << endl;
}

bool _is_same(string t[], string u[], int n) {
	for (int i = 0; i < n; i++) {
		if (t[i] != u[i]) {	//i???????????????????????°?????£????????????false
			return false;
		}
	}
	return true;
}

int main() {
	int n;
	string s[36];
	
	cin >> n;
	for (int i = 0; i < n; i++) cin >> s[i];
	
	string t[36], u[36];
	for (int i = 0; i < n; i++) t[i] = s[i];
	for (int i = 0; i < n; i++) u[i] = s[i];
	
	bubbleSort(t, n);
	selectionSort(u, n);
	
	println(t, n);
	cout << "Stable" << endl;
	
	println(u, n);
	if (_is_same(t, u, n)) { cout << "Stable" << endl; }
	else { cout << "Not stable" << endl; }
	
	return 0;
}

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

using namespace std;

int main() {
  int v[3];
  cin >> v[0];
  cin >> v[1];
  cin >> v[2];

  sort(v, v + 3);
  if (v[0] == 5 && v[1] == 5 && v[2] == 7) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }

  return 0;
}


Measured memory_bytes: 3128
import math
from collections import defaultdict
from functools import reduce

memo = defaultdict(int)


def gcd(*numbers):
    return reduce(math.gcd, numbers)


def gcd_with_memo(x, y):
    key = tuple(sorted([x, y]))
    if memo[key] != 0:
        value = memo[key]
    else:
        value = math.gcd(x, y)
        memo[key] = value
    return value


# def main():
#     K = int(input())
#     total = 0
#     for a in range(1, K + 1):
#         for b in range(1, K + 1):
#             for c in range(1, K + 1):
#                 total += gcd_with_memo(a, gcd_with_memo(b, c))
#     print(total)

def main():
    K = int(input())

    total = 0

    # 1
    for i in range(1, K + 1):
        total += i

    # print(total)

    # 2 kind
    for i in range(1, K + 1):
        for j in range(i + 1, K + 1):
            total += 6 * gcd(i, j)

    # print(total)

    # 3kind
    for i in range(1, K + 1):
        for j in range(i+1, K + 1):
            for k in range(j+1, K + 1):
                total += 6 * gcd(i, j, k)

    print(total)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9664
#include<cstdio>
#include<stack>
#include<iostream>
using namespace std;
int H, W; int maxv = 0;
int c[1400][1400], t[1400][1400];
struct Rect
{
  int pos, height;
  Rect() {}
  Rect(int pos, int height): pos(pos), height(height) {}
};

void solve()
{
  stack<Rect> S;
  for(int h=0; h<H; h++)
  {
    t[h][W] = 0;
    for(int w=0; w<=W; w++)
    {
      Rect rec = Rect(w, t[h][w]);
      Rect r;
      if(t[h][w] == 0)
      {
        while(!S.empty())
        {
          r = S.top(); S.pop();
          int width = w-r.pos;
          int area = width*r.height;
          maxv = max(maxv, area);
        }
      }
      else
      {
        if(S.empty()) {S.push(rec); continue;}
        if(S.top().height < rec.height) {S.push(rec); continue;}
        if(S.top().height > rec.height)
        { int target = w;
          while(!S.empty() && S.top().height >= rec.height)
          {
            r = S.top(); S.pop();
            int width = w-r.pos;
            int area = width*r.height;
            target = r.pos;
            maxv = max(maxv, area);
          }
          rec.pos = target;
          S.push(rec);
        }
      }
    }
    while(!S.empty())
      S.pop();
  }
  printf("%d\n", maxv);
}

int main()
{
  scanf("%d%d", &H, &W);
  for(int i=0; i<H; i++)
  {
    for(int j=0; j<W; j++)
    {
      scanf("%d", &c[i][j]);
    }
  }
  for(int j=0; j<W; j++)
  {
    if(c[0][j] == 0)
      t[0][j] = 1;
    else t[0][j] = 0;
  }
  for(int i=1; i<H; i++)
  {
    for(int j=0; j<W; j++)
    {
      if(c[i][j] == 1)
        t[i][j] =0;
      else
      {
        t[i][j] = t[i-1][j] + 1;
      }
    }
  }
  solve();

  return 0;
}



Measured memory_bytes: 18524
# -*- coding: utf-8 -*-
"""
B - A to Z String
https://atcoder.jp/contests/abc053/tasks/abc053_b

"""
import sys


def solve(s):
    A_positions = []
    Z_positions = []
    for i, ch in enumerate(s):
        if ch == 'A':
            A_positions.append(i)
        elif ch == 'Z':
            Z_positions.append(i)
    return Z_positions[-1] - A_positions[0] + 1


def main(args):
    s = input()
    ans = solve(s)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Measured memory_bytes: 11172
#include<stdio.h>
#define MAX 10000
main(){
  int i, j;
  int n, q;
  int S[MAX], T[MAX],count = 0;
  scanf("%d", &n);
  for(i = 0; i < n; i++){
    scanf("%d", &S[i]);
  }
  scanf("%d", &q);
  for(i = 0; i < q; i++){
    scanf("%d", &T[i]);
  }

  for(i = 0; i < q; i++){

    for(j =0; j < n; j++)
      if(T[i] == S[j]){
        count++;
        break;
      }
  }
  printf("%d\n",count);

return 0;
}

Measured memory_bytes: 648
h,w=[int(x) for x in input().split()]

a=[input() for i in range(h)]

r=[['.' for i in range(w)]for j in range(h)]
b=[['.' for i in range(w)]for j in range(h)]

for i in range(h):
  r[i][0]='#'
  b[i][w-1]='#'
  if i%2==0:
    for j in range(w-1):
      r[i][j]='#'
  else:
    for j in range(1,w):
      b[i][j]='#'

for i in range(h):
  for j in range(w):
    if a[i][j]=='#':
      r[i][j]='#'
      b[i][j]='#'
  
for i in range(h):
  print("".join(r[i]))
  
print()
for i in range(h):
  print("".join(b[i]))


Measured memory_bytes: 8052
//Code is like humor. When you have to explain it, it’s bad.
#define fastio ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#include <bits/stdc++.h>
#define MOD 1000000007
#define int long long
using namespace std;
#define ss second
#define ff first

int modexp(int a, int n)
{
    int res=1;
    while(n)
    {
        if(n&1) res = (res*a)%MOD;
        a = (a*a)%MOD;
        n>>=1;
    }
    return res;
}
int32_t main()
{
    fastio;
    int T,n,k,i,j;
    T=1;
    while(T --> 0)
    {
        cin>>n>>k;
        int A[k+1];
        int ans=0;
        for(i=k;i>=1;i--)
        {
            A[i] = modexp(k/i,n);
            for(j = i*2; j<=k; j+=i)
                A[i] = (MOD+A[i]-A[j])%MOD;
            ans=(ans+(i*A[i])%MOD)%MOD;
        }
        // for(i=1;i<=k;i++)
        //     cout<<A[i]<<'\n';
        cout<<ans;
    }
    return 0;
}

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

int main()
{
    int n;
    cin >> n;
    vector<int> d(n);
    rep(i, n) cin >> d[i];
    int ans = 0;
    for (int i = 0; i < n; i++)
    {
        for (int j = i+ 1; j < n; j++)
        {
             ans += d[i] * d[j];
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int ans;
int main() {
	int n,l,r;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>l>>r;
		//cout<<l<<" "<<r<<endl;
		ans+=r-l+1;
	}
	cout<<ans<<endl;
}

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

int main() {
    int R;
    cin >> R;
    if(R < 1200) cout << "ABC" << endl;
    else if (R< 2800) cout << "ARC" << endl;
    else cout << "AGC" << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Numerics;

namespace AtCoderWorkspace
{
    public class Solver
    {
        public void Solve()
        {
            var cin = new Scanner();
            var k = cin.nextInt();
            var n = cin.nextInt();
            var a = cin.ArrayLong(n);

            var ans = long.MaxValue;
            for (int i = 0; i < n-1; i++)
            {
                var diff = a[i + 1] - a[i];
                ans = Math.Min(ans, k - diff);
            }

            ans = Math.Min(ans, k-((k - a[n - 1]) + a[0]));

            
            Console.WriteLine(ans);
        }
    }

    class Scanner
    {
        string[] s;
        int i;

        char[] cs = new char[] { ' ' };

        public Scanner()
        {
            s = new string[0];
            i = 0;
        }

        public string next()
        {
            if (i < s.Length) return s[i++];
            string st = Console.ReadLine();
            while (st == "") st = Console.ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            if (s.Length == 0) return next();
            i = 0;
            return s[i++];
        }

        public int nextInt()
        {
            return int.Parse(next());
        }
        public int[] ArrayInt(int N, int add = 0)
        {
            int[] Array = new int[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextInt() + add;
            }
            return Array;
        }

        public int[] DPArrayInt(int N, int ex)
        {
            int[] Array = new int[N + ex];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextInt();
            }
            return Array;
        }

        public long nextLong()
        {
            return long.Parse(next());
        }

        public long[] ArrayLong(int N, long add = 0)
        {
            long[] Array = new long[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextLong() + add;
            }
            return Array;
        }

        public long[] DPArrayLong(int N, int ex)
        {
            long[] Array = new long[N + ex];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextLong();
            }
            return Array;
        }

        public double nextDouble()
        {
            return double.Parse(next());
        }


        public double[] ArrayDouble(int N, double add = 0)
        {
            double[] Array = new double[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextDouble() + add;
            }
            return Array;
        }
    }

    class Program
    {
        static void Main(string[] s) => new Solver().Solve();
    }
}


Measured memory_bytes: 34396
#include <bits/stdc++.h>
#include <cstring>
#include <algorithm>
#include <vector>
#include <iostream>
#include <queue>
#include <math.h>
#include <map>
#include <set>
#include <fstream>

//#define _debug
#define FASTIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define sc(x) scanf("%d",&x)
#define ll long long
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define FORd(i,a,b) for(int i=a;i>b;i--)
#define ff first
#define ss second
#define sz(x) x.size()
#define pb push_back
//#define _online_judge

using namespace std;

typedef pair<int,int> pii;
typedef vector<pii> vii;
const int con = static_cast<const int>(1e4 + 5);
const int MOD = 1000000007;



int main(){
    FASTIO;
#ifdef _online_judge
    freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
#endif

    string s;cin >> s;
    int siz = s.size();
    for(int i=0;i<siz-1;i++){

        if(s[i] == s[i+1]){
            cout << i+1 << " " << i+2;
            return 0;
        }
        else if(s[i] == s[i+2] && i+2 < siz){
            cout << i+1 << " " << i+3;
            return 0;
        }
    }
    cout << "-1 -1";
    return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#include<queue>
#define REP(i,a) for(int (i)=0; (i)<(a); (i)++)
#define RREP(i,a,b) for(int (i)=(a); (i)<(b); (i)++)
using namespace std;

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int N,M;
  cin>>N>>M;
  long long int ans=0;
  if(2*N>=M){//ccをM個作る
    ans=M/2;
  }else{//N<m/2
    ans=N;
    ans+=(long long int)((M-2*N)/4);
  }
  cout<<ans;
  return 0;
}

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

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
//
        String S = new String();
        S = sc.next();

        int min = 200;
        for(int i = 0; i< S.length(); i++){
            int temp = changeNum(S, i);
            if(min > temp){
                min = temp;
            }
        }
        System.out.println(min);
    }

    //strをpos番目の文字にすべて変更する場合の回数
    private static int changeNum(String str, int pos){
        List<Integer> index = new ArrayList<>();
        for(int i =0 ;i<str.length();i++){
            if(str.charAt(i) == str.charAt(pos)){
                index.add(i);
            }
        }

        int ans = str.length() - index.get(index.size()-1);
        int temp = index.get(0) + 1;
        if (ans < temp){
            ans = temp;
        }
        for(int i=(index.size()-1); i > 0; i--){
            if(ans < (index.get(i) - index.get(i-1))){
                ans = index.get(i) - index.get(i-1);
            }
        }
        return (ans - 1);
    }
}


Measured memory_bytes: 21460
while line = gets
  h, w = line.split(' ').map(&:to_i)
  break if h == 0 && w == 0
  top_bottom = w.times.map{|i| "#"}.join
  middle = "#" + (w - 2).times.map{|i| "."}.join + "#"
  puts top_bottom
  (h - 2).times.each{|i| puts middle}
  puts top_bottom
  puts ""
end


Measured memory_bytes: 6888
#!/usr/bin/env python3
import sys


def solve(s: str, t: str):
    """
    >>> solve("aaa", "aaa")
    3
    >>> solve("a", "a")
    1
    >>> solve("contest", "son")
    10
    """
    from collections import defaultdict
    from bisect import bisect
    d = defaultdict(list)
    for i, c in enumerate(s):
        d[c].append(i)
    ans, i = 0, -1
    for c in t:
        #print(ans, i, end=" ")
        if not d[c]:
            return -1
        j = bisect(d[c], i)
        if len(d[c]) == j:
            ans += len(s) - i + d[c][0]
            i = d[c][0]
        else:
            ans += d[c][j] - i
            i = d[c][j]
        #print("->", ans, i)
    return ans

# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    s = next(tokens)  # type: str
    t = next(tokens)  # type: str
    print(solve(s, t))

     
def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    test()
    main()


Measured memory_bytes: 22200
#include <cstdio>
#include <cstring>
using namespace std;
char s[200050];
int n,i,j;
int main()
{
	scanf("%s",s+1);n=strlen(s+1);
	long long ans=0;
	for (i=1;i<=n;i=j+1) if (s[i]=='A'){
		long long tot=1;
		for (j=i+1;j<=n;) if (s[j]=='A') tot++,j++;
		else if (s[j]=='B'&&s[j+1]=='C') ans+=tot,j+=2;
		else break;
	}else j=i;
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 384
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    long ans = 0;
    int len = s.length();
    for(int i = 0; i < (int)Math.pow(2, len - 1); i++) {
      int p = 0;
      for(int j = 0; j < (len - 1); j++) {
        if((i & (1 << j)) != 0) {
          String str = s.substring(p, j + 1);
          long t = Long.parseLong(str);
          ans += t;
          p = j + 1;
        }
      }
      String str = s.substring(p);
      long t = Long.parseLong(str);
      ans += t;
    }
    if(len == 1) ans = Long.parseLong(s);
    System.out.println(ans);
  }
}

Measured memory_bytes: 35864
#include <stdio.h>

int main (){

  int i,j,n,sum,res;

  while(scanf("%d",&n),n){

    sum = 0;

    for(i=1; i<n; i++){

      res = 0;

      for(j=i;;j++){

        res += j;

        if(res == n){
          //  printf("%d\n",j);
          sum++;
          break;

        }else if(res > n){

          break;

        }
      }
    }

    printf("%d\n",sum);

  }

  return 0;

}

Measured memory_bytes: 600
import java.util.ArrayList
fun main(args: Array<String>) {
    val need = intArrayOf(0, 2, 5, 5, 4, 5, 6, 3, 7, 6)
    var (n,m) = readLine()!!.split(" ").map { s -> s.toInt() }
    val a = readLine()!!.split(" ").map { s -> s.toInt() }.sortedBy { need[it]*10 - it }
    var prev =-1
    a.filter { (prev!=need[it]).apply { prev = need[it] } }

    class Data(var maxDig:Int=-1,var num:Int=0)

    val dp = DP<Data>(n+1){ index,dp ->
        if(index<0)Data()
        else{
            val amax = a.filter { index-need[it]>=0 }
                .maxBy { dp[index-need[it]]!!.maxDig*10 +  it }
            if(amax==null||dp[index-need[amax]]!!.maxDig==-1)Data()
            else Data(dp[index-need[amax]]!!.maxDig+1,amax)
        }
    }
    dp[0] = Data(0,0)
    while(n>0) {
        print(dp[n]!!.num)
        n -= need[dp[n]!!.num]
    }
}

class DP<T>(size:Int,private val recurrenceRelation: (Int,ArrayList<T?>) -> T ):ArrayList<T?>(size){
    init {
        for (i in 0 until size)add(null)
    }

    override fun get(index: Int): T? {
        return super.get(index)?:run{
             recurrenceRelation(index,this).apply { set(index,this) }
        }
    }
}


Measured memory_bytes: 46620
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <set>

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,j) FOR(i,0,j)
#define mp std::make_pair

const int INF = 1 << 24;
const int dx[8] = {0, 0, 1, -1, 1, 1, -1, -1}, dy[8] = {1, -1, 0, 0, 1, -1, 1, -1};

typedef unsigned long long ull;
typedef std::pair<int,int> P;

int main(){
    int T;
    std::cin >> T;

    REP(_, T){
        int X, Y, W, H;
        std::cin >> X >> Y >> W >> H;

        int N;
        std::cin >> N;

        int cat = 0;
        REP(i, N){
            int x, y;
            std::cin >> x >> y;

            if(X <= x && x <= X+W &&
               Y <= y && y <= Y+H){
                cat++;
            }
        }

        std::cout << cat << std::endl;
    }
}

Measured memory_bytes: 1160
#include <stdio.h>
struct dice{
    int d[6], tmp[6];
};
struct dice dice1;
struct dice dice2;
struct dice dice3[110];
void copy1(int a){
    int i;
    for (i=0;i<6;i++){
        dice3[a].d[i]=dice2.d[i];
        dice3[a].tmp[i]=dice2.tmp[i];
    }
}
void copy2(int a){
    int i;
    for (i=0;i<6;i++){
        dice2.d[i]=dice3[a].d[i];
        dice2.tmp[i]=dice3[a].tmp[i];
    }
}
void init1(int n[6]){
    int i;
    for (i=0;i<6;i++){
        dice1.d[i]=n[i];
    }
}
void init2(int n[6]){
    int i;
    for (i=0;i<6;i++){
        dice2.d[i]=n[i];
    }
}
void throwdice(char c){
    int i;
    for(i=0;i<6;i++){
        dice1.tmp[i]=dice1.d[i];
    }
    if(c=='N'){
        dice1.d[0]=dice1.tmp[1];
        dice1.d[1]=dice1.tmp[5];
        dice1.d[2]=dice1.tmp[2];
        dice1.d[3]=dice1.tmp[3];
        dice1.d[4]=dice1.tmp[0];
        dice1.d[5]=dice1.tmp[4];
    }
    else if(c=='E'){
        dice1.d[0]=dice1.tmp[3];
        dice1.d[1]=dice1.tmp[1];
        dice1.d[2]=dice1.tmp[0];
        dice1.d[3]=dice1.tmp[5];
        dice1.d[4]=dice1.tmp[4];
        dice1.d[5]=dice1.tmp[2];
    }
    else if(c=='W'){
        dice1.d[0]=dice1.tmp[2];
        dice1.d[1]=dice1.tmp[1];
        dice1.d[2]=dice1.tmp[5];
        dice1.d[3]=dice1.tmp[0];
        dice1.d[4]=dice1.tmp[4];
        dice1.d[5]=dice1.tmp[3];
    }
    else if(c=='S'){
        dice1.d[0]=dice1.tmp[4];
        dice1.d[1]=dice1.tmp[0];
        dice1.d[2]=dice1.tmp[2];
        dice1.d[3]=dice1.tmp[3];
        dice1.d[4]=dice1.tmp[5];
        dice1.d[5]=dice1.tmp[1];
    }
    else if(c=='R'){
        dice1.d[0]=dice1.tmp[0];
        dice1.d[1]=dice1.tmp[3];
        dice1.d[2]=dice1.tmp[1];
        dice1.d[3]=dice1.tmp[4];
        dice1.d[4]=dice1.tmp[2];
        dice1.d[5]=dice1.tmp[5];
    }
}
int compare(){
    int i;
    for(i=0;i<6;i++){
        if(dice1.d[i]!=dice2.d[i]){
            return 0;
        }
    }
    return 1;
}
int main()
{
    int n[6];
    int m;
    int i,j,k,l;
    int ok=0;
    scanf("%d",&m);
    for(i=0;i<6;i++){
        scanf("%d",&n[i]);
    }
    init2(n);
    copy1(0);
    for(i=0;i<m-1;i++){
        for(j=0;j<6;j++){
            scanf("%d",&n[j]);
        }
        init1(n);
        for(j=0;j<i+1;j++){
            copy2(j);
            for(k=0;k<4;k++){
                for(l=0;l<4;l++){
                    throwdice('N');
                    throwdice('E');
                    throwdice('S');
                    if(compare()) ok=1;
                }
                throwdice('N');    
            }
            throwdice('E');
            for(k=0;k<2;k++){
                for(l=0;l<4;l++){
                    throwdice('N');
                    throwdice('E');
                    throwdice('S');
                    if(compare()) ok=1;
                }
                throwdice('W');    
                throwdice('W');    
            }
        }
        copy1(i+1);
    }
    if(!ok) puts("Yes");
    else puts("No");
    return 0;
}


Measured memory_bytes: 2132
n,m=map(int,raw_input().split())
k=[int(raw_input()) for _ in xrange(n)]
s=[int(raw_input()) for _ in xrange(m)]
vote=[0]*n
for i in xrange(m):
    for j in xrange(n):
        if k[j]<=s[i]:
            vote[j]+=1
            break
print(vote.index(max(vote))+1)

Measured memory_bytes: 6460
#include "bits/stdc++.h"

using namespace std;

#define ll long long
#define vi  vector<int>
#define vvi vector<vi>
#define pi  pair<int,int>
#define mp  make_pair
#define pb  push_back
#define MOD 1e9 + 7
#define PAI  3.1415
#define all(x) (x).begin(),(x).end()
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
#define pr(x) cout << x << endl
#define Endl endl
#define rep(i,n) for(int i = 0 ; i < n; i++)

const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
const int ddx[8] = {-1,0,1,-1,1,-1,0,1};
const int ddy[8] = {-1,-1,-1,0,0,1,1,1};
const int inf = 99999999;
const ll linf = 1LL << 62;

ll gcd(ll a,ll b){
  if(a < b)swap(a , b);
  if(a % b == 0) return b;
  else gcd(b, a%b);
}

ll lcm(ll a,ll b){
  if(a < b)swap(a , b);
  return (a/gcd(a , b))*b;
}

struct UnionFind {
  vi par; //par[i] : iの親番号（例）par[3] = 2 : 3の親は2

  UnionFind(int N) : par(N) { //最初は全てが根として初期化
    rep(i,N) par[i] = i;
  }

  int root(int x){ //データxが属する木の根を再帰で得る : root(x) = {xの木の根}
    if(par[x] == x)return x;
    return par[x] = root(par[x]);
  }

  void unite(int x, int y){ //xとyの木を併合
    int rx = root(x); //xの根をrx
    int ry = root(y); //yの根をry
    if(rx == ry)return; //xとyの根が同じ
    par[rx] = ry; //xとyの根が同じでない時、xの根rxをyの根にryにつける。
  }

  bool same(int x, int y){//2つのデータx，yが属する木が同じならtrueを返す
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
  }
};


int main(){

  int d, n; cin >> d >> n;
  d = pow(100,d);
  if(n == 100) n++;
  cout << d * n << endl;

  return 0;

}

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

int main(){
  int N;
  cin >> N;
  int x[10], y[10];
  for(int i=0; i<N; i++){
    cin >> x[i] >> y[i];
  }
  double total = 0.0;
  int perm[N];
  for(int i=0; i<N; i++) perm[i] = i;
  do{
    for(int i=1; i<N; i++){
      total += sqrt(pow(x[perm[i]] - x[perm[i-1]], 2) + pow(y[perm[i]] - y[perm[i-1]], 2));
    }
  }while(next_permutation(perm, perm + N));
  int num = 1;
  for(int i=1; i<=N; i++) num *= i;
  double ans = total / num;
  cout << fixed << setprecision(6) << ans << endl;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
from collections import Counter
N, M, K = map(int, input().split())
friend = [[] for _ in range(N)]
block = [[] for _ in range(N)]

for _ in range(M):
	a, b = map(int, input().split())
	friend[a - 1].append(b - 1)
	friend[b - 1].append(a - 1)
	
for _ in range(K):
	c, d = map(int, input().split())
	block[c - 1].append(d - 1)
	block[d - 1].append(c - 1)
	
# 同じ連結成分にラベルを振る（まだラベルを振っていない = -1 で初期化）
label = [-1] * N

cnt_label_num = 0

for i in range(N):
	if label[i] != -1: continue # もう振ってあったら飛ばす
	
	# 振ってなかったら幅優先でラベルを振る
	Q = [i]
	while Q:
		cur = Q.pop()
		if label[cur] != -1: continue
		label[cur] = cnt_label_num
		for adj in friend[cur]:
			if label[adj] != -1: continue
			Q.append(adj)
	
	cnt_label_num += 1
	
# お友達候補計算
cnt = Counter(label)
for i in range(N):
	friend_candidate = cnt[label[i]] - 1 # 同じグラフにいる人
	friend_candidate -= len(friend[i]) # 元から友達を引く
	# blockしている人が同じグラフにいるときはその分引く
	for block_man in block[i]:
		if label[i] == label[block_man]:
			friend_candidate -= 1
	print(friend_candidate, end = " ")

Measured memory_bytes: 95660
# import sys
# sys.setrecursionlimit(10 ** 6)
# import bisect
# from decorator import stop_watch
# 
# 
# @stop_watch
def solve(X):
    primes = [2]
    ans = 2
    i = 1
    while True:
        i = i + 1
        if primes[-1] >= X:
            ans = primes[-1]
            break
        flg = True
        for p in primes:
            if p > i ** 0.5:
                break
            if i % p == 0:
                flg = False
                break
        if flg:
            primes.append(i)

    print(ans)


if __name__ == '__main__':
    X = int(input())
    solve(X)


Measured memory_bytes: 3520
import java.io.*;
// import java.math.*;
// import java.util.*;
// import java.util.Map.*;
// import java.util.stream.*;

public class Main {
    public static void main (String[] args) throws Exception {
        BufferedReader reader =
            new BufferedReader (new InputStreamReader (System.in));
        int N = Integer.parseInt (reader.readLine().replace (" ", ""));
        System.out.println ((1000 - N % 1000) % 1000);
        return;
    }
}

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

#define io ios::sync_with_stdio(false)
#define pb push_back
#define pqueue priority_queue
#define fi first
#define se second
#define ls rt<<1
#define rs rt<<1|1
#define sz(x) (int)(x).size()
#define dbg(x) cout<<#x<<" --- "<<x<<endl
#define mst(x,a) memset(x,a,sizeof(x))
#define fin(a) freopen(a,"r",stdin)
#define fout(a) freopen(a,"w",stdout)
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
ll gcd(ll a,ll b){ return b==0?a:gcd(b,a%b); }
ll qpow(ll a,ll b,ll m){ ll r=1;a%=m;for(;b;b>>=1){if(b&1)r=r*a%m;a=a*a%m;}return r; }
const int inf=0x7fffffff;
const int maxn=2e5+10;
char a[maxn];
int cnt[maxn];
int n;
ll p;

int main(){
	io;
	cin>>n>>p;
	cin>>a;
	if(p==2||p==5){
		ll ans=0;
		// dbg(0);
		for(int i=0;a[i]!='\0';i++){
			if((a[i]-'0')%p==0)ans+=i+1;
		}
		cout<<ans<<endl;
		return 0;
	}
	ll ans=0,now=0,pp=1;
	int len=strlen(a);
	for(int i=len-1;i>=0;i--){
		now+=pp*(a[i]-'0');
		now%=p;
		// dbg(now);
		ans+=cnt[now];
		if(now==0)ans++;
		cnt[now]++;
		pp*=10;
		pp%=p;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include <cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;


int main(){
  int N; cin >> N;
  int x[N], y[N];
  rep(i, N){
    cin >> x[i] >> y[i];
  }
  double ans = 0.0;
  vector<int> array(N);
  rep(i, N){
    array[i] = i;
  }
  do{
    rep(i, N-1){
      ans += (double) sqrt((pow)(x[array[i+1]]-x[array[i]], 2)+ (pow)(y[array[i+1]]-y[array[i]], 2));
    }
  }
  while(next_permutation(array.begin(), array.end()));
  int fact = 1;
  for(int i=2; i<=N; i++){
    fact *= i;
  }
  ans /= fact;
  printf("%.12lf\n", ans);
}     
      
    

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;

vector<pair<int, pair<int, string> > > data;

int val;

int get_era(int q){
  int tmp = -1;
  for(int i=0;i<data.size();i++){
    if(data[i].first <= q && q <= (data[i].second).first){
      val = q-data[i].first;
      return i;
    }
  }
  return -1;
}

main(){
  int N, Q;
  while(cin >> N >> Q){
    if(N == 0 && Q == 0) break;
    data.clear();
    for(int i=0;i<N;i++){
      string name;
      int era, west;
      cin >> name >> era >> west;
      data.push_back(make_pair(west-era+1, make_pair(west, name)));
    }
    sort(data.begin(), data.end());
    for(int i=0;i<Q;i++){
      int q, ans;
      cin >> q;
      ans = get_era(q);
      if(ans == -1) cout << "Unknown" << endl;
      else cout << (data[ans].second).second << ' ' << val+1 << endl;
    }
  }
  return 0;

}

Measured memory_bytes: 984
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
using namespace std;
//int a[26][100010]={0};
int main(){
    int n,sum=0; string s; cin>>s;
    n=(int)s.size();
    //for(int i=0;i<n;i++) a[s[i]-'a'][i]++;
    /*for(int i=1;i<n;i++){
        for(int j=0;j<26;j++){
            a[j][i]+=a[j][i-1];
        }
    }
    for(int k=0;k<26;k++){

    }*/
    for(int i=0;i<n;i++){
        if(s[i]==s[i+1]){
            printf("%d %d",i+1,i+2); return 0;
        }else if(s[i]==s[i+2]){
            printf("%d %d",i+1,i+3); return 0;
        }
    }
    cout<<"-1 -1"<<endl;
    return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define N 55
struct edge
{
	int nxt,to,id;
}a[N<<1];
int head[N],dfn[N],low[N];
bool b[N];
int n,m,x,y,num,ans,Time;
inline void add(int x,int y)
{
	a[++num].nxt=head[x],a[num].to=y,a[num].id=num,head[x]=num;
	a[++num].nxt=head[y],a[num].to=x,a[num].id=num-1,head[y]=num;
}
void dfs(int now,int fa)
{
	dfn[now]=low[now]=++Time;
	b[now]=1;
	for(int i=head[now];i;i=a[i].nxt)
	  if(a[i].id!=fa)
	  {
		if(!b[a[i].to])
		{
			dfs(a[i].to,a[i].id);
			low[now]=min(low[now],low[a[i].to]);
			if(low[a[i].to]>dfn[now]) ans++;
		}
		else low[now]=min(low[now],dfn[a[i].to]);
	  }
}
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++)
	  scanf("%d%d",&x,&y),add(x,y);
	dfs(1,0);
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include "cstdio"
#include "iostream"
#include "algorithm"
#include "vector"
#include "string"
#include "cctype"
#include "set"

using namespace std;

int main ()
{
    int N;
    string S;
    cin >> N;
    cin >> S;

    if (S.length() <= N) {
        cout << S;
    }else cout << S.substr(0,N) << "...";
    return 0;
}


Measured memory_bytes: 3620
#include<stdio.h>
main(){
  int a[1000000]={0},i,j,n,cnt;
  while(scanf("%d",&n)!=EOF){
    for(i=0;i<=n;i++)a[i]=0;
    cnt=0;
    for(i=2;i<=n;i++){
      if(a[i]==0){
    cnt++;
    for(j=1;i*j<=n;j++){
      a[i*j]=1;
    }      
      }
    }
 
 
    printf("%d\n",cnt);
  }
  return 0;
}


Measured memory_bytes: 5676
#define DEB
#include<bits/stdc++.h>
#define REP(i,m) for(int i=0;i<(m);++i)
#define REPN(i,m,in) for(int i=(in);i<(m);++i)
#define ALL(t) (t).begin(),(t).end()
#define CLR(a) memset((a),0,sizeof(a))
#define pb push_back
#define mp make_pair
#define fr first
#define sc second

using namespace std;


#ifdef DEB
#define dump(x)  cerr << #x << " = " << (x) << endl
#define prl cerr<<"called:"<< __LINE__<<endl
#define dumpR(x) cerr<<"\x1b[31m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
#define dumpY(x) cerr<<"\x1b[33m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
#define dumpG(x) cerr<<"\x1b[32m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
template<class T> void debug(T a,T b){ for(;a!=b;++a) cerr<<*a<<' ';cerr<<endl;}
#else
#define dump(x) ;
#define dumpR(x) ;
#define dumpY(x) ;
#define dumpG(x) ;
#define prl ;
template<class T> void debug(T a,T b){ ;}
#endif

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

typedef long long int lint;
typedef pair<int,int> pi;

namespace std{
  template<class S,class T>
  ostream &operator <<(ostream& out,const pair<S,T>& a){
    out<<'('<<a.fr<<','<<a.sc<<')';
    return out;
  }
}

//const int INF=5e8;

int main(){
  int n,h,w;
  cin>>n>>h>>w;
  int res=max(0,n+1-h)*max(0,n+1-w);
  cout<<res<<endl;
  return 0;
}





Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>

struct Node{
  int key;
  Node *next,*prev;
};

Node *nil;

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

void init(){
  nil = (Node*)malloc(sizeof(Node));
  nil->next = nil;
  nil->prev = nil;
}

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

void deleteNode(Node *t){
  if(t == nil) return ;
  t->prev->next = t->next;
  t->next->prev = t->prev;
  free(t);
}

void deleteFirst(){
  deleteNode(nil->next);
}

void deleteLast(){
  deleteNode(nil->prev);
}

void deleteKey(int key){
  deleteNode(listSearch(key));
}

void insert(int key){
  Node *x = (Node *)malloc(sizeof(Node));
  x->key = key;
  x->next = nil->next;
  nil->next->prev = x;
  nil->next = x;
  x->prev = nil;
}

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

  printList();

  return 0;
}



Measured memory_bytes: 33832
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

#define ll long long
#define ld long double
typedef vector <ll> vi;                 // Vector of long long
typedef vector <vi> vvi;                // Vector of vi
typedef vector <pair<ll,ll>> ii;        // Vector of pairs
#define ff first                        // For pairs
#define ss second                       // For pairs
#define sz(a) int((a).size())           // Function to determine size of any container
#define pb push_back                    // Pushback to vector
#define mp make_pair                    // Makes pairs to be stored as pair
#define all(c) (c).begin(), (c).end()   // Mainly used by me in sorting
// ordered_set adds two new functions to set - (set).find_by_order([kth element based on zero indexing]) and order_of_key()
// order_of_key returns number of elements less that parameter. If element exists, that order is its index
#define ordered_set tree < ll ,  null_type ,  less<ll> ,  rb_tree_tag ,  tree_order_statistics_node_update >
#define MAX (ll)(1e5 + 10)
#define INF (ll)(1e10)

ll dp[MAX];
ll n, k;
vi h;

ll solve(ll i)
{
    if (i < 0)
        return INF;
    
    if (dp[i] == -1)
    {
        ll ans = INF;
        for (ll j = 1; j <= min(i, k); j++)
            ans = min(ans, solve(i - j) + llabs(h[i] - h[i - j]));
        dp[i] = ans;
    }
    return dp[i];
}

int main(void)
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> n >> k;
    h.resize(n);
    for (int i = 0; i < n; i++)
        cin >> h[i];
    memset(dp, -1, sizeof(dp));
    dp[0] = 0;

    cout << solve(n - 1) << "\n";
}


Measured memory_bytes: 6528
#include<stdio.h>

int main()
{
    int a[309][309], n;
    while(~scanf("%d", &n))
    {
        for(int i = 1; i <= n; i++)
            for(int j = 1; j <= n; j++)
                scanf("%d", &a[i][j]);
        long long ans = 0;
        for(int i = 1; i <= n; i++)
        {
            for(int j = 1; j < i; j++)
            {
                bool flag = 1;
                for(int k = 1; k <= n; k++)
                {
                    if(a[i][j] > a[i][k] + a[k][j])
                    {
                        printf("-1\n");
                        return 0;
                    }
                    else if(i != k && k != j && a[i][j] == a[i][k] + a[k][j])
                        flag = 0;
                }
                if(flag)
                    ans += a[i][j];
            }
        }
        printf("%lld\n", ans);
    }
    return 0;
}


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

using namespace std;

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

    vector<int> h(n), c(n);

    for (int i = 0; i < n; i++) cin >> h[i];

    c[1] = abs(h[1] - h[0]);

    for (int i = 2; i < n; i++) {
        int _1 = abs(h[i] - h[i - 1]), _2 = abs(h[i] - h[i - 2]);
        c[i] = min(c[i - 1] + _1, c[i - 2] + _2);
    }

    cout << c[n - 1];

    return 0;
}


Measured memory_bytes: 4020
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

//struct edge {int from, to, cost;};

constexpr double EPS = 1e-10;
//constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;
constexpr int MOD = 1'000'000'007;

template<class T> inline T sqr(T x) {return x*x;}

void solve() {
    int n,t,a;
    cin >> n >> t >> a;
    VI h(n);
    REP(i,0,n) cin >> h[i];
    int index = 0;
    REP(i,1,n) {
        double diff = abs(a - (t - 0.006 * h[i]));
        double minv = abs(a - (t - 0.006 * h[index]));
        if (diff < minv) index = i;
    }
    cout << index + 1 << endl;
}

int main() {
    solve();
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
#include <set>
#define vi vector<int>
#define vll vector<long long>
#define pii pair<int, int>
#define vii vector<pair<int, int> >
#define si stack<int>
#define pb push_back
#define mp make_pair
#define ALL(T) (T).begin(), (T).end()
#define MODU 1000000007
typedef long long ll;
using namespace std;

ll intmax = (1LL<<32)-1;
ll llmax = (1LL<<60)-1;

const int INF = 1e9 + 5;

class fastio{
public:
	fastio(){
		ios_base::sync_with_stdio(false);
		cin.tie(NULL);
	}
} __fastio;

template <typename T>
T abs(T x){
	if(x < 0) return -x;
	else return x;
}

void DFSVisit(int u, vector<int> g[], vector<bool> &visited){
    visited[u] = true;
    for(int i=0; i<(int)g[u].size(); i++){
        if(!visited[g[u][i]]){
            DFSVisit(g[u][i], g, visited);
        }
    }
}

void DFS(vector<int> adj[], int V){
    vector<bool> visited(V, false);
    for(int u=0; u<V; u++)
        if(!visited[u])
            DFSVisit(u, adj, visited);
}


int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    vector<int> b(n);
    vector<int> c(n-1);
    for(int i=0; i<n; i++){
        cin >> a[i];
    }
    for(int i=0; i<n; i++){
        cin >> b[i];
    }
    for(int i=0; i<n-1; i++){
        cin >> c[i];
    }
    int sat = 0;
    for(int i=0; i<n-1; i++){
        sat += b[a[i]-1];
        if(a[i+1] - a[i] == 1)
            sat += c[a[i]-1];
    }
    sat += b[a[n-1]-1];
    cout << sat;
}


Measured memory_bytes: 256
from collections import defaultdict


def calc(x):
    return x*(x-1)//2


N = int(input())
A = list(map(int, input().split()))

dd = defaultdict(int)
for i in range(N):
    dd[A[i]] += 1

count = 0
for k, v in dd.items():
    if v >= 2:
        count += calc(v)
for i in range(N):
    ans = 0
    if dd[A[i]] >= 3:
        ans = count - calc(dd[A[i]]) + calc(dd[A[i]]-1)
    elif dd[A[i]] == 2:
        ans = count - 1
    elif dd[A[i]] == 1:
        ans = count
    print(ans)

Measured memory_bytes: 26780
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i,a,b) for(ll i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define FORL(i,x) for(int i=head[x];i;i=nxt[i])
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define PB push_back
#define MP make_pair
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 input[n];
  ll max = 0;

  ll MOD = 998244353;
  FOR(i,0,n-1) {
    cin >> input[i];
    chmax(max,input[i]);
  }

  map<ll,ll> m;

  FOR(i,0,n-1){
    ++m[input[i]];
  }

  ll ans = 1;

  FOR(i,1,max){
    FOR(j,1,m[i]){
      ans *= m[i-1];
      ans %= MOD;
    }
  }

  if(input[0]!=0) cout << 0 << endl;
  else if(m[0]>1) cout << 0 << endl;
  else cout << ans << endl;









}



Measured memory_bytes: 7296
N, Q = map(int, input().split())
S = input()
sum = [0] * (N + 1)
for i in range(1, N):
  if i < N and S[i - 1] == 'A' and S[i] == 'C':
    sum[i] = sum[i - 1] + 1
  else:
    sum[i] = sum[i - 1]
for i in range(Q):
  l, r = map(int, input().split())
  print(sum[r - 1] - sum[l - 1])

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

int main() {
   char x, y;
   cin >> x >> y;

   if (x < y) {
       cout << "<" << endl;
   } else if (x == y) {
       cout << "=" << endl;
   } else {
       cout << ">" << endl;
   }
}

Measured memory_bytes: 256
n,q = map(int,input().split())
s = input()
lr = [[int(i) for i in input().split()]for _ in range(q)]
dp = [0]*n
f,c = 0,0
for i,j in enumerate(s):
  if f==1 and j=='C':
    c+=1
    f =0
  elif j=='A':
    f = 1
  else:
    f = 0
  dp[i]=c
for i in lr:
  print(dp[i[1]-1]-dp[i[0]-1])

Measured memory_bytes: 24424
while True:
    n=int(input())
    x=[]
    if n==0:
        break
    else:
        for i in range(n):
            s=int(input())
            x.append(s)
        for i in range(0,10):
            a=x.count(i)
            if a==0:
                print("-")
            else:
                print("*"*a)


Measured memory_bytes: 5704
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

typedef long long ll;

int main() {
  int s, w;
  cin >> s >> w;

  if (w >= s) {
    cout << "unsafe" << endl;
  } else {
    cout << "safe" << endl;
  }
  return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll MOD = 1000000007;
constexpr ll INF = 1ll<<60;

int main(int argc, char **argv)
{
	string str; cin >> str;
	ll N = (ll)str.size();
	vector<ll> v;
	v.reserve(2*N+1);
	for (ll i = 0; i < N; ++i)
	{
		v.push_back(0);
		v.push_back(str[i]);
	}
	v.push_back(0);
	N = 2 * N + 1;

	
	for (ll i = 0; i < N;)
	{
		ll l = i+1;
		ll j = i+2;
		if (v[l] == '<')
		{
			v[i] = 0;
			ll c{1};
			for (; j < N; j+=2)
			{
				if (v[j-1] != '<') break;
				v[j] = max(v[j], c++);
			}
		}
		i = j;
	}

	reverse(v.begin(), v.end());
	for (ll i = 0; i < N;)
	{
		ll l = i+1;
		ll j = i+2;
		if (v[l] == '>')
		{
			v[i] = 0;
			ll c{1};
			for (; j < N; j+=2)
			{
				if (v[j-1] != '>') break;
				v[j] = max(v[j], c++);
			}
		}
		i = j;
	}

	ll res{0};
	for (ll i = 0; i < N; i+=2)
		res += v[i];

	// for (ll i = 0; i < N; ++i)
	// 	std::cout << v[i] << " ";
	// std::cout << std::endl;
	std::cout << res << std::endl;
}

Measured memory_bytes: 8708
#include<stdio.h>
#include<stdlib.h>
#define MAX 100000

typedef struct node *link;
struct node{
	int v;
	link next;
};

int loop[MAX];
link adj[MAX];

link NEW(int v,link n){
	link x = malloc(sizeof(*x));
	x->v = v; x->next=n;
	return x;
}

void search(int n,int cnt){
	if(loop[n]==-1){
		link t;
		loop[n]=cnt;
		for(t=adj[n];t!=NULL;t=t->next)search(t->v,cnt);
	}
}

int main(void){
	int n,m,q,s,t;
	int i;
	scanf("%d %d",&n,&m);
	for(i=0;i<n;i++){
		adj[i]=NULL;
		loop[i]=-1;
	}
	for(i=0;i<m;i++){
		scanf("%d %d",&s,&t);
		adj[s]=NEW(t,adj[s]);
		adj[t]=NEW(s,adj[t]);
	}
	
	for(i=0;i<n;i++)search(i,i);
	
	scanf("%d",&q);
	for(i=0;i<q;i++){
		scanf("%d %d",&s,&t);
		if(loop[s]==loop[t])printf("yes\n");
		else printf("no\n");
	}
	return 0;
}



Measured memory_bytes: 12184
#include<bits/stdc++.h>
using namespace std;
#define inf INT_MAX
#define INF LLONG_MAX
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
#define vi vector<int>
#define IP pair<int,P>
#define PI pair<P,int>
#define PP pair<P,P>
#define Yes(f){cout<<(f?"Yes":"No")<<endl;}
#define YES(f){cout<<(f?"YES":"NO")<<endl;}
int Madd(int x,int y) {return (x+y)%M;}
int Msub(int x,int y) {return (x-y+M)%M;}
int Mmul(int x,int y) {return (x*y)%M;}


signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);

  double a,b;
  cin>>a>>b;

  cout<<a*b/(a+b)<<endl;


}

Measured memory_bytes: 256