akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define ASC(x) sort(ALL((x)))
#define DESC(x) sort(ALL((x)),greater<ll>())
#define REV(x) reverse(ALL((x)))
#define pb push_back

int main()
{
    ll N, K, C;
    cin >> N >> K >> C;
    string S;
    cin >> S;
    S = " " + S;

    vec L, R;
    REP(i,1,N+1) {
        if(S[i] == 'o') {
            L.pb(i);
            i += C;
        }
    }
    REP(i,1,N+1) {
        if(S[N-i+1] == 'o') {
            R.pb(N-i+1);
            i += C;
        }
    }
    REV(R);

    ll M = MIN(SZ(L),SZ(R));
    if(M == K) { 
        REP(i,0,MIN(SZ(L),SZ(R))) {
            if(L[i] == R[i]) PR(L[i]);
        }
    }

    return 0;
}

/*



*/

Measured memory_bytes: 7964
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define pa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
#define pb push_back

using ll = long long;
using namespace std;
using pint = pair<int,int>;
using pll = pair<ll,ll>;
const int INFint = 1e9;
const ll INFll = 1e18;
ll MOD=1e9+7;

ll gcd(ll a, ll b) { return __gcd(a,b); } //最大公約数
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; } //最大公倍数

// aのn乗をMODで割りながら計算する
ll modpow(ll a, ll n) {
  long long res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % MOD;
    a = a * a % MOD;
    n >>= 1; // right shift
  }
  return res;
}

// MODを法としたaの逆元を計算する
ll modinv(ll a) {
  return modpow(a, MOD - 2);
}

int main(){
  string s;
  cin>>s;
  int q;
  cin>>q;
  string ans = s;
  int cnt(0);
  string mae,usiro;
  for (int i(0);i<q;i++){
    int t;
    cin>>t;
    if (t == 1){
      cnt++;
    }else{
      int f;
      char c;
      cin>>f>>c;
      if (f == 1){
        if (cnt %2 == 1) usiro += c;
        else mae = c + mae;
      } else{
        if (cnt %2 == 0) usiro += c;
        else mae = c + mae;
      }
    }
  }
  if (cnt % 2 == 1){
    reverse(ans.begin(),ans.end());
    reverse(usiro.begin(),usiro.end());
    reverse(mae.begin(),mae.end());
    cout << usiro << ans << mae << endl;
  }else{
    cout << mae + ans + usiro << endl;
  }
  return 0;
}



Measured memory_bytes: 1360
_ = input()
H = list(map(int, input().strip().split(' ')))
for i in range(len(H)):
  if i == 0:
    H[i] -= 1
    continue
  if H[i-1] == H[i]:
    continue
  elif H[i-1] > H[i]:
    print('No')
    exit()
  else:
    H[i] -= 1
print('Yes')

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

typedef long long ll;

int main() {
    int K, N;
    cin >> K >> N;
    vector<int> A(N);
    for (int i=0;i<N;i++){
        cin >> A[i];
    }
    int mdist = -1;
    for (int i=0;i<N-1;i++){
        mdist = max(mdist,A[i+1]-A[i]);
    }
    mdist = max(mdist, A[0] + K - A[N-1]);
    cout << K - mdist << endl;

    return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>

long gcd(long x, long y)
{
	return y ? gcd(y, x % y) : x;
}

long lcm(__int128 x, __int128 y)
{
	return x * y / gcd(x, y);
}

int main(void)
{
	int N, i;
	long T[100];
	scanf("%d", &N);
	for (i = 0; i < N; ++i) scanf("%ld", &T[i]);
	for (i = 1; i < N; ++i) T[i] = lcm(T[i - 1], T[i]);
	printf("%ld", T[N - 1]);
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>

int main(void)
{
	int a,b,c,i,d;
	scanf("%d %d %d",&a,&b,&c);
	for(i=0;i<c;i++){
		if(a%2==1){
			a=a-1;
		}
		b=b+(a/2);
		a=a/2;
		d=a;
		a=b;
		b=d;
	}
	if(c%2==0){
		printf("%d %d",a,b);
	}else{
		printf("%d %d",b,a);
	}
	return 0;
}

Measured memory_bytes: 128
import java.io._
import java.util.StringTokenizer
import scala.util.control.Breaks.{breakable,break}
import scala.collection.mutable.{Map, Stack, Queue, PriorityQueue}

object Main extends App {
  val in = new InputReader(System.in)
  val pw = new PrintWriter(System.out)

  val N, M = in.next().toInt
  val graph = Array.fill[List[Int]](N+1)(Nil)
  for (i <- 1 to M) {
    val a, b = in.next().toInt
    graph(a) = b :: graph(a)
    graph(b) = a :: graph(b)
  }

  //
  if (M % 2 != 0)
    println(-1)
  else {
    val tree = Array.fill[List[Int]](N+1)(Nil)
    val dp = new Array[Boolean](N+1)
    val stack = new Stack[Int]
    dp(1) = true
    stack.push(1)
    while(!stack.isEmpty) {
      val n = stack.pop()
      for (e <- graph(n) if !dp(e)) {
        tree(n) = e :: tree(n)
        tree(e) = n :: tree(e)
        dp(e) = true
        stack.push(e)
      }
    }

    /////
    for (i <- 1 to N)
      dp(i) = false

    var ans: List[(Int, Int)] = Nil
    val degrees = new Array[Int](N+1)
    val traversed = new Array[Boolean](N+1)
    stack.push(1)
    traversed(1) = true
    while(!stack.isEmpty) {
      val n = stack.pop()

      if(tree(n).forall(x => traversed(x))) {
        dp(n) = true
        val cnt = graph(n).count(x => !dp(x))

        if (graph(n).forall(x => dp(x)))
          ()
        else {
          val targets = graph(n).filter(x => !dp(x))

          if((cnt + degrees(n)) % 2 == 1) {
            val i = targets.head
            degrees(i) += 1
            ans = (i, n) :: ans

            for (e <- targets.tail)
              ans = (n, e) :: ans
          }
          else {
            for (e <- targets)
              ans = (n, e) :: ans
          }
        }
      }
      else {
        stack.push(n)
        for (e <- tree(n) if !traversed(e)) {
          traversed(e) = true
          stack.push(e)
        }
      }

    }

    for ((a, b) <- ans)
      pw.println(s"$a $b")

    pw.flush()
  }
}


class InputReader(stream: InputStream) {
  private val reader = new BufferedReader(new InputStreamReader(stream))
  private var tokenizer: StringTokenizer = new StringTokenizer(reader.readLine())
  def next(): String = {
    while (!tokenizer.hasMoreTokens()) {
      tokenizer = new StringTokenizer(reader.readLine())
    }
    tokenizer.nextToken()
  }
}


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

int main() {  
  int n;
  cin >> n;
  vector<double> vec(n);
  for (int i = 0; i<n; i++) {
    cin >> vec.at(i);
  }
  
  double sum1 = 1/vec.at(0);
  
  for (int i = 1; i<n; i++) {
    sum1 = sum1 + 1/vec.at(i);
  }
  //cout << sum1 << endl;  
  double sum2;
  sum2 = 1/sum1;
  cout << sum2 << endl;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;
public class Main {

    private static void solver(InputReader sc, PrintWriter out) {
        int n = sc.nextInt();
        long k = sc.nextLong();
        int arr[] = new int[n+1];
        for(int i=1; i<=n; i++) arr[i] = sc.nextInt();
        Set<Integer> hs = new HashSet<>();
        List<Integer> al = new ArrayList<>();
        int x = 1;
        al.add(1);
        hs.add(1);
        while(true){
            x = arr[x];
            if(hs.contains(x)){
                break;
            }else {
                hs.add(x); al.add(x);
            }
        }
        int size = al.size();
        List<Integer> nonreps = new ArrayList<>();
        List<Integer> reps = new ArrayList<>();
        boolean flag = true;
        for (Integer integer : al) {
            if (flag) {
                if (integer == x) {
                    flag = false;
                    reps.add(integer);
                }else{
                    nonreps.add(integer);
                }
            } else {
                reps.add(integer);
            }
        }
        if(k < nonreps.size()){
            out.println(nonreps.get((int)k));
        }else{
            k -= nonreps.size();
         //   out.println(reps.size());
            k %= reps.size();
            out.println(reps.get((int)k));
        }
    }
    public static void main(String[] args) throws Exception {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        solver(in,out);
        out.close();
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

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

        public int nextInt() {
            return Integer.parseInt(next());
        }
        public long nextLong() {
            return Long.parseLong(next());
        }
        public int[] readIntArray(int n){
            int arr[] = new int[n];
            for(int i=0;i<n;i++) arr[i] = nextInt();
            return arr;
        }
    }
}
class Pair{
    int x,y;
    Pair(int x, int y){
        this.x = x;
        this.y = y;
    }
}

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

int main(void){
    string s;
    cin >> s;
    int cnt = 0;
    for (size_t i = 0; i < 3; i++)
    {
        if(s[i]=='o')
            cnt++;
    }
    cout << 700 + 100 * cnt << endl;
    return 0;
}

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

int main() {
  int A,B,C,D,X;
  cin >> A >> B >> C >> D;
  X = 0;
  if(A <= B)
    X += A;
  else
    X += B;
  if(C <= D)
    X += C;
  else
    X += D;
  
  cout << X << endl;

}


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

int main(){
  string s;
  cin >> s;
  char preC;
  char nowC = 'O';
  long now = -1;
  vector<pair<long,long> > ABC;
  for(long i = 0; i < s.size(); i++){
    preC = nowC;
    nowC = s[i];
    if(nowC == 'A'){
      if(preC == 'A') ABC[now].first++;
      else{
        now++;
        ABC.push_back(make_pair(1,0));
      }
    }else if(nowC == 'B'){
      if(preC != 'B' && preC != 'O'){
        if(i < s.size()-1){
          i++;
          preC = nowC;
          nowC = s[i];
          if(nowC == 'C'){
            if(now == -1) continue;
            else ABC[now].second++;
          }
          else{
            now++;
            ABC.push_back(make_pair(0,0));
            if(nowC == 'A'){
              now++;
              ABC.push_back(make_pair(1,0));
            }
          }
          continue;
        }
      }
    }else{
      if(now == -1) continue;
      else{
        if(ABC[now].first == 0) continue;
        else{
          now++;
          ABC.push_back(make_pair(0,0));
        }
      }
    }
  }
  reverse(ABC.begin(), ABC.end());
  long long numBC = 0;
  long long ans = 0;
  for(long i = 0; i < ABC.size(); i++){
    if(ABC[i].second == 0 || ABC[i].first == 0){
      numBC = 0;
      continue;
    }else{
      numBC += ABC[i].second;
      ans += ABC[i].first * numBC;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 2680
N, K = map(int, input().split())
M = list(map(lambda x: int(x)-1, input().split()))
s = 0
order = [s]
sets = set(order)
while True:
  if M[s] in sets:
    #print(order, M[s])
    if len(order) > K:
      print(order[K]+1)
    else:
      K -= order.index(M[s])
      order = order[order.index(M[s]):]
      print(order[(K+1)%len(order)-1]+1)
    break
  order.append(M[s])
  sets.add(M[s])
  s = M[s]



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

int main(){
  int n;cin>>n;
  map<string,int>m;
  while(n--){
    string s;cin>>s;
    m[s]++;
  }
  cout<<"AC x "<<m["AC"]<<endl;
  cout<<"WA x "<<m["WA"]<<endl;
  cout<<"TLE x "<<m["TLE"]<<endl;
  cout<<"RE x "<<m["RE"]<<endl;
}

Measured memory_bytes: 3600
/**
 * AtCoder Beginner Contest 079
 * C - Train Ticket
 *
 * bit全検索パターン
 */
#include <iostream>
using namespace std;

#define LEN 4

int main() {
  char ABCD[LEN + 1];
  scanf("%s", &ABCD[0]);

  int sum;
  for (size_t i{}; i < (1 << (LEN - 1)); ++i) {
    sum = ABCD[0] & 0xF;
    for (size_t j{}; j < LEN - 1; ++j) {
      if (i & (1 << j)) {
        sum += ABCD[j + 1] & 0xF;
      } else {
        sum -= ABCD[j + 1] & 0xF;
      }
    }
    if (sum == 7) {
      printf("%c", ABCD[0]);
      for (int j{}; j < (LEN - 1); ++j) {
        printf("%c%c", (i & (1 << j)) ? '+' : '-', ABCD[j + 1]);
      }
      printf("=7\n");
      return 0;
    }
  }

  return 1; // no case
}


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

namespace AIZU
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] num = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var ans1 = num[0] * num[1];
            var ans2 = (num[0] * 2) + (num[1]*2);
            Console.WriteLine(ans1.ToString() +" "+ ans2.ToString());
        }
    }
}



Measured memory_bytes: 16396
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using P = pair<int,int>;
struct Sieve {
  int n;
  vector<ll> f;
  Sieve(int n=1):n(n), f(n+1,1) {
    for (ll i=2; i<=n; ++i) {
      for (ll j=i; j<=n; j+=i) {
        f[j]++;
      }
    }
  }
};
int main() {
  int n;
  cin >> n;
  Sieve s(n);
  ll ans = 1;
  for(ll i=2;i<=n;++i){
    ans += i*s.f[i];
  }
  cout << ans << endl;
}

Measured memory_bytes: 81332
#include <stdio.h>

long long min(long long a, long long b) {
	return a < b ? a : b;
}

long long max(long long a, long long b) {
	return a > b ? a : b;
}

int main() {
	long long a, b, c, x, y, cost1, cost2, cost3;

	scanf("%lld%lld%lld%lld%lld", &a, &b, &c, &x, &y);
	cost1 = (x * a) + (y * b);
	cost2 = max(x, y) * (c * 2);
	cost3 = (min(x, y) * (c * 2)) + ((max(x, y) - min(x, y)) * (max(x, y) == x ? a : b));
	printf("%lld\n", min(cost1, min(cost2, cost3)));
	return 0;
}


Measured memory_bytes: 128
using System;
using System.Linq;
using System.Collections.Generic;
using E = System.Linq.Enumerable;

class Program
{
    static readonly double INF = double.PositiveInfinity;

    static void Main(string[] args)
    {
        while (true)
        {
            int[] input = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
            int N = input[0], M = input[1], P = input[2], A = input[3] - 1, B = input[4] - 1;
            if (N == 0) break;
            int[] nums = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
            double[][] dist = E.Range(0, M).Select(i => E.Repeat(INF, M).ToArray()).ToArray();

            for (int i = 0; i < P; i++)
            {
                input = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
                dist[input[0] - 1][input[1] - 1] = input[2];
                dist[input[1] - 1][input[0] - 1] = input[2];
            }
            double[][] dp = E.Range(0, 1 << N).Select(i => E.Repeat(INF, M).ToArray()).ToArray();
            dp[0][A] = 0;
            for (int mask = 0; mask < (1 << N); mask++)
                foreach (int use in E.Range(0, N).Where(use => (mask >> use & 1) == 0))
                    foreach (int i in E.Range(0, M).Where(i => dp[mask][i] < INF))
                        foreach (int j in E.Range(0, M).Where(j => dist[i][j] < INF))
                        {
                            double cost = dp[mask][i] + dist[i][j] / nums[use];
                            int nextMask = mask | 1 << use;
                            dp[nextMask][j] = Math.Min(dp[nextMask][j], cost);
                        }

            double ans = INF;
            for (int mask = 0; mask < (1 << N); mask++)
            {
                if (dp[mask][B] == double.NaN) throw new Exception();
                ans = Math.Min(ans, dp[mask][B]);
            }
            Console.WriteLine((ans == INF) ? "Impossible" : ans.ToString("f3"));
        }
    }
}

Measured memory_bytes: 6436
r, g, b, n = map(int, input().split())
ans = 0
for i in range(0, n+1):
    for j in range(0, n-i+1):
        check = (n-(i*r + j*g))/b
        if check % 1 == 0 and check >= 0:
            ans += 1
print(ans)


Measured memory_bytes: 41196
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
//	for(int i=1;i<=1000000;i++){
	cin>>n;
	if(n==0||n==1){
		cout<<0;
		return 0;
	}
	else if(n==2){
		cout<<1;
		return 0;
	}
	n--;
	unsigned long long ans=n;
	for(int i=2;i<n;i++){
		ans+=n/i;
	}
	ans++;
	cout<<ans; 
//	}
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
void _main()
{
    int N;
    cin >> N;
    vector<int> H(N);
    rep(i, 0, N) cin >> H[i];
    rrep(i, N - 1, 1)
    {
        if (H[i] < H[i - 1])
        {
            --H[i - 1];
        }
    }
    bool ok = true;
    rep(i, 0, N - 1)
    {
        if (H[i] > H[i + 1])
        {
            ok = false;
        }
    }

    cout << (ok ? "Yes" : "No") << endl;
}


Measured memory_bytes: 640
def main():
    n = input()
    A = []
    s = []
    B = [[0,0] for i in xrange(n)]
    for i in xrange(n):
        A.append(map(int,raw_input().split()))

    color = [-1]*n
    d = [0]*n
    f = [0]*n
    t = 0
    
    for i in xrange(n):
        if color[i] == -1:
            t = dfs(i,t,color,d,f,A,n)

    for i in xrange(n):
        print i+1, d[i], f[i]


def dfs(u,t,color,d,f,A,n):
    t += 1
    color[u] = 0
    d[u] = t
    for i in A[u][2:]:
        if (color[i-1] == -1):
            t = dfs(i-1,t,color,d,f,A,n)
    color[u] = 1
    t += 1
    f[u] = t
    return t

if __name__ == '__main__':
    main()

Measured memory_bytes: 6496
#!/usr/bin/python3
# -*- coding: utf-8 -*-

import sys

_dict = dict()

n = int(sys.stdin.readline())
for i in range(n):
    cmd, word = sys.stdin.readline().split()
    if cmd == 'insert':
        _dict[word] = True
    elif cmd == 'find':
        if word in _dict:
            print('yes')
        else:
            print('no')



Measured memory_bytes: 33444
#include <iostream>
#include <climits>
#define N 100000
using namespace std;

struct Data
{
    int num;
    char alph;
};

Data data[N];
Data data2[N];

int Partition(int n, int r)
{
    int x = data[r].num;
    int j = n;
    for (int i = n; i < r; i++)
    {
        if (data[i].num <= x)
        {
            swap(data[i], data[j]);
            j++;
        }
    }
    swap(data[j], data[r]);
    return j;
}

void QuickSort(int n, int r)
{
    if (n < r)
    {
        int t = Partition(n, r);
        QuickSort(n, t - 1);
        QuickSort(t + 1, r);
    }
}

void Merge(int left, int mid, int right)
{
    int n1 = mid - left;
    int n2 = right - mid;
    Data L[n1 + 1], R[n2 + 1];
    for (int i = 0; i < n1; i++)
    {
        L[i] = data2[left + i];
    }
    for (int i = 0; i < n2; i++)
    {
        R[i] = data2[mid + i];
    }
    L[n1].num = INT_MAX;
    R[n2].num = INT_MAX;
    int i = 0;
    int j = 0;
    for (int k = left; k < right; k++)
    {
        if (L[i].num <= R[j].num)
        {
            data2[k] = L[i];
            i++;
        }
        else
        {
            data2[k] = R[j];
            j++;
        }
    }
}

void MergeSort(int left, int right)
{
    if (left + 1 < right)
    {
        int mid = (left + right) / 2;
        MergeSort(left, mid);
        MergeSort(mid, right);
        Merge(left, mid, right);
    }
}

bool Check(int n)
{
    for (int i = 0; i < n; i++)
    {
        if (data[i].alph != data2[i].alph)
        {
            return false;
        }
    }
    return true;
}

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

    int n;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> data[i].alph >> data[i].num;
        data2[i] = data[i];
    }

    QuickSort(0, n - 1); //重要
    MergeSort(0, n);

    /*for (int i = 0; i < n; i++)
    {
        cout << data2[i].alph << ' ' << data2[i].num << endl;
    }*/

    if (Check(n))
    {
        cout << "Stable" << endl;
    }
    else
    {
        cout << "Not stable" << endl;
    }

    for (int i = 0; i < n; i++)
    {
        cout << data[i].alph << ' ' << data[i].num << endl;
    }

    return 0;
}



Measured memory_bytes: 5440
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>

using namespace std;
using LLONG = long long;
const LLONG MOD = 1000000007;

int main()
{
    int N; cin >> N;
    vector<double> as(N); for (auto &ai : as) cin >> ai;
    const double avg = accumulate(as.begin(), as.end(), 0.0) / static_cast<double>(N);
    map<double, int> diff2IndexMap;
    for (int i = N - 1; i >= 0; --i)
    {
        diff2IndexMap[abs(as[i] - avg)] = i;
    }
    cout << diff2IndexMap.begin()->second << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <array>
#include <utility>
#include <queue>
#include <tuple>
#include <map>
using namespace std;
using ll = long long;
using VI = vector<int>;


int main() {
    ll a, b, c, k;
    cin >> a >> b >> c >> k;
    ll ans = 0;

    
    

    if (b == 0 && c == 0) {
        cout << a << endl;
        return 0;
    }
    /*else {
        if (a + b >= k) {
            cout << a << endl;
            return 0;
        }
        else {
            cout << a - (k - c) << endl;
            return 0;
        }
    }*/


    for (int i = 0; i < k; i++) {
        if (a != 0) {
            ans++;
            a--;
        }
        else if (b != 0) {
            b--;
        }
        else if (c != 0) {
            //ans--;
            //c--;
            ans -= k-i;
            break;
        }

        if (a == 0) {
            if (b + i >= k) {
                break;
            }
            else {
                i += b;
                b = 0;
            }
        }   
    }
    cout << ans << endl;
    return 0;
}


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

int main() {
    int n; cin >> n;
    vector<long long> v(n), p(n, 1e18);
    for (int i = 0; i < n; i++) cin >> v[i];
    p[0] = 0;
    for (int i = 0; i < n; i++) {
        if (i > 0) {
            p[i] = min(p[i], p[i-1]+abs(v[i]-v[i-1]));
        }
        if (i > 1) {
            p[i] = min(p[i], p[i-2]+abs(v[i]-v[i-2]));
        }
    }
    cout << p[n-1] << endl;
    return 0;
}

Measured memory_bytes: 1792
from math import cos as cos_
from math import sin as sin_
from math import sqrt
from math import radians

def cos(degree):
    return cos_(radians(degree))

def sin(degree):
    return sin_(radians(degree))

def five_points(x,y,a,r):
    lis=[]
    for i in range(5):
        lis.append((x-r*sin(a-72*i*2),y+r*cos(a-72*i*2)))
    lis.append(lis[0])
    return lis

def distance2lines(r1,r2,r3,r4):
    #check crossing
    if (((r2[0]-r1[0])*(r3[1]-r1[1])-(r2[1]-r1[1])*(r3[0]-r1[0]))\
       *((r2[0]-r1[0])*(r4[1]-r1[1])-(r2[1]-r1[1])*(r4[0]-r1[0])) <= 0) and\
       (((r4[0]-r3[0])*(r1[1]-r3[1])-(r4[1]-r3[1])*(r1[0]-r3[0]))\
       *((r4[0]-r3[0])*(r2[1]-r3[1])-(r4[1]-r3[1])*(r2[0]-r3[0])) <= 0):
        return 0
    if (0<=((r2[0]-r1[0])*(r3[0]-r1[0])+(r2[1]-r1[1])*(r3[1]-r1[1]))<=((r2[0]-r1[0])**2+(r2[1]-r1[1])**2)):
        d3=abs((r2[0]-r1[0])*(r3[1]-r1[1])-(r2[1]-r1[1])*(r3[0]-r1[0]))/sqrt((r2[1]-r1[1])**2+(r2[0]-r1[0])**2)
    else:
        d3=min(sqrt((r3[1]-r1[1])**2+(r3[0]-r1[0])**2),sqrt((r3[1]-r2[1])**2+(r3[0]-r2[0])**2))
    if (0<=((r2[0]-r1[0])*(r4[0]-r1[0])+(r2[1]-r1[1])*(r4[1]-r1[1]))<=((r2[0]-r1[0])**2+(r2[1]-r1[1])**2)):
        d4=abs((r2[0]-r1[0])*(r4[1]-r1[1])-(r2[1]-r1[1])*(r4[0]-r1[0]))/sqrt((r2[1]-r1[1])**2+(r2[0]-r1[0])**2)
    else:
        d4=min(sqrt((r4[1]-r1[1])**2+(r4[0]-r1[0])**2),sqrt((r4[1]-r2[1])**2+(r4[0]-r2[0])**2))
    return min(d3,d4)
    

def distance2stars(x1,y1,a1,r1,x2,y2,a2,r2):
    star1=five_points(x1,y1,a1,r1)
    star2=five_points(x2,y2,a2,r2)
    ans=float('inf')
    for i in range(5):
        for j in range(5):
            ans=min(ans,distance2lines(star1[i],star1[i+1],star2[j],star2[j+1]))
            ans=min(ans,distance2lines(star2[i],star2[i+1],star1[j],star1[j+1]))
    return ans

N,M,L=map(int,input().split())
while N!=0:
    stars=[]
    for i in range(N):
        stars.append(tuple(map(int,input().split())))
    d=[[0]*N for i in range(N)]
    for i in range(N):
        x1,y1,a1,r1=stars[i]
        for j in range(i+1,N):
            x2,y2,a2,r2=stars[j]
            d[i][j]=distance2stars(x1,y1,a1,r1,x2,y2,a2,r2)
    for i in range(N):
        for j in range(0,i):
            d[i][j]=d[j][i]
    for k in range(N):
        for i in range(N):
            for j in range(N):
                d[i][j]=min(d[i][j],d[i][k]+d[k][j])
    print(d[M-1][L-1])
    N,M,L=map(int,input().split())


    



Measured memory_bytes: 6244
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static long Mod = (long)1e9 + 7;
        static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            var N = Sarray()[0];
            var S = ReadLine();
            var lcount = 0L;// (の数
            var rcount = 0L;// )の数
            for(var i=0;i<S.Length;++i)
            {
                if (S[i] == '(') ++lcount;
                if (S[i] == ')')
                {
                    if (0 < lcount) --lcount;
                    else ++rcount;
                }
            }
            var lcount2 = 0L;
            var rcount2 = 0L;
            for (var i = S.Length-1; 0<=i; --i)
            {
                if (S[i] == ')') ++rcount2;
                if (S[i] == '(')
                {
                    if (0 < rcount2) --rcount2;
                    else ++lcount2;
                }
            }
            WriteLine(new string('(', (int)rcount) + S + new string(')', (int)lcount2));
            //Out.Flush();
        }
    }
}

Measured memory_bytes: 13396
n = int(input())
li = list(map(int, input().split()))
li.append(0)

dp = [float("inf") for i in range(n+2)]
dp[0] = 0

for i in range(n-1):
    dp[i+1] = min(dp[i+1], dp[i] + abs(li[i]-li[i+1]))
    dp[i+2] = min(dp[i+2], dp[i] + abs(li[i]-li[i+2]))

print(dp[n-1])

Measured memory_bytes: 13980
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#include<numeric>
#include<set>
#include<map>
#include<deque>
#include<list>
#include<forward_list>
#include<utility>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#define ll long long
#define v vector<ll>
const ll w = (1e9 + 7);
using namespace std;
void fireman()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}
struct great {
	//descending order
	bool operator()(int x, int y)
	{
		return x < y;
	}
};


struct small {
	//asecending order
	bool operator()(int x, int y)
	{
		return x > y;
	}
};

int prime(int x)
{
	bool b = true;
	if (x == 2)
	{
		return true;
	}
	else if (x == 1 || x % 2 == 0)
	{
		return false;
	}
	for (int i = 3; i * i <= x; i += 2)
	{
		if (x % i == 0)
		{
			b = false;
			return false;
			break;
		}
	}
	return true;
}
bool great1(int a, int b)
{
	//descending order 
	return a > b;
}
bool small1(int a, int b)
{
	//asecending order 
	return a < b;
}
/*int sum_range(ll i, ll j, ll k, ll l, vector<vector<ll>>& S) {
	return S[k][l] - S[k][j - 1] - S[i - 1][l] + S[i - 1][j - 1];
}*/
int main()
{
	fireman();
	ll a;
	cin >> a;
	cout << a + (a * a) + (a * a * a) << endl;

}







Measured memory_bytes: 3656
import math

def main():
    N, M = list(map(int, input().split()))
    XY = []
    for i in range(M):
        x, y = list(map(int, input().split()))
        XY.append([x, y])

    boxes = []
    for i in range(N):
        if i == 0:
            boxes.append([1, True])
        else:
            boxes.append([1, False])

    # print(':', boxes)

    for x, y in XY:
        if boxes[x-1][1]:
            # 赤ボールが運ばれた可能性がある
            boxes[y-1][1] = True
        if boxes[x-1][1] and boxes[x-1][0] == 1:
            # box(x-1)にボールがなくなるのでREDの可能性はない
            boxes[x-1][1] = False

        boxes[x-1][0] -= 1
        boxes[y-1][0] += 1
        # print(boxes)

    # print(':', boxes)
    ans = 0
    for c, b in boxes:
        if b:
            ans += 1
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 30244
using System;
public class ProCon
{
    public static void Main(){     

        string S = Console.ReadLine();
        int N = S.Length;
        int length = (N-1)/2;
        string frontS = S.Substring(0,length);
        string baskS = S.Substring((N+3)/2 - 1,length);


        if(frontS == baskS)
        {
            Console.WriteLine("Yes");
        }
        else
        {
            Console.WriteLine("No");
        }

    }
}



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

int main()
{
	ios::sync_with_stdio(false), cin.tie(0);
	int N, K;
	cin >> N >> K;
	vector<int> cnt(N);
	for (int i = 0; i < N; i++) {
		int A;
		cin >> A; A--;
		cnt[A]++;
	}
	sort(cnt.rbegin(), cnt.rend());
	while (!cnt.empty() && cnt.back() == 0) cnt.pop_back();
	int res = 0;
	while ((int)cnt.size() > K) res += cnt.back(), cnt.pop_back();
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
void solve(){
	string a,b;
	cin>>a>>b;
	int l=0;
	for(int i=0;i<a.size();i++){
		if(a[i]!=b[i]) l++;
	}
	cout<<l<<'\n';
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int tt;
    tt=1;
    while(tt--)
        solve();
    return 0;
}


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

int main(){
  ll n,k;
  cin >> n >> k;
  vector<ll>p(n);
  for(int i=0; i<n ;i++) cin >> p[i];
  
  sort(p.begin(),p.end());
  
  ll ans =0;
  for(int i=0; i<k; i++) ans+=p[i];
  
  cout << ans << endl;

}
  


Measured memory_bytes: 3636
/**
 *   
 *   Date: 18 August 2019
 *   Time: 17:52:02
**/
#include <iostream>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <vector>
#include <cmath>
#include <cstring>
#include<queue>
#include<stack>
#include<climits>
#include<iomanip>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pi;
typedef vector<ll> vec;
typedef vector<vector<ll> > matrix;

int main(){
	ios_base::sync_with_stdio(false); 
	cin.tie(NULL);
	ll n;
	cin>>n;
	ll ar[n+2];
	double br[n+2];
	for(ll i=1;i<=n;i++)
	{
		cin>>ar[i];
	}
	sort(ar+1,ar+n+1);
	br[1]=ar[1];
	for(ll i=2;i<=n;i++)
	{
		br[i]=(double)(br[i-1]+ar[i])/2;
	}
	cout<<br[n]<<"\n";

return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const long long m=1e9+7;
long long n,a[100010],b[100010],s;
bool p;
long long mo(long long x,long long y)
{
	long long r=1;
	while(y>0)
	{
		if(y&1)
		r=r*x%m;
		x=x*x%m;
		y>>=1;
	}
	return r%m;
}
int main()
{
	while(cin>>n)
	{
		p=true;
		s=0;
		memset(b,0,sizeof(b));
		for(int i=0;i<n;i++)
		{
			cin>>a[i];
			b[a[i]]++;
			if(b[a[i]]>3||b[0]>1)
			{
				p=false;
			}
		}
		if(p){
		for(int i=1;i<n;i++)
		{
			if(b[i]==2)
			s++;
		}
		s=mo(2,s);
	    }
		printf("%lld\n",s);
	}
	return 0;
} 

Measured memory_bytes: 1792
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n)for(int i=0;i<(int)(n);i++)
#define PI 3.141592653589793
//vector < vector<int>>a(0, vector<int>(0));二次元配列宣言


int main()
{
	int  n, a, b;
	cin >> n >> a >> b;
	cout << min(n * a, b) << endl;
}

Measured memory_bytes: 3568
n=gets.to_i
v=gets.chomp.split(" ").map(&:to_i)
c=gets.chomp.split(" ").map(&:to_i)
list=[]
n.times do|i|
	list[i]=v[i]-c[i]
end
max=0
n.times do|i|
	if list[i]>0
		max+=list[i]
	end
end
print max

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

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

ll lcm(ll a, ll b) {
    ll g = gcd(a, b);
    return a / g * b;
}

int main() {
    int n; cin >> n;
    ll ans = 1LL;
    rep(i, 0, n) {
        ll t;
        cin >> t;
        ans = lcm(ans, t);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <numeric>
using namespace std;

int abs(int num){
   if (num > 0)
      return num;
   else
      return -num;
}

long long gcd(long long a, long long b) {
    if (b==0) return a;
    else return gcd(b, a%b);
}

long long lcm(long long a, long long b) {
    return a * b / gcd(a, b);
}

int main(){
  vector<int> iro(101);
  int a,b,c;
  cin >> a >> b >> c;
  iro.at(a)++;
  iro.at(b)++;
  iro.at(c)++;
  int ans = 0;
  for(int i = 0;i<101;i++){
    if(iro.at(i)!=0){
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
N, x = gets.chomp.split.map(&:to_i)
a = gets.chomp.split.map(&:to_i)
cnt = 0
(N-1).times do |i|
  s = a[i] + a[i + 1]
  diff = s - x
  next if diff <= 0

  cnt += diff
  if a[i + 1] >= diff
    a[i + 1] -= diff
  else
    a[i] -= diff - a[i + 1]
    a[i + 1] = 0
  end
end
puts cnt

Measured memory_bytes: 21964
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <cfloat>
#include <complex>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

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

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

  ll ans = (a + b)/2;
  if ((a + b) % 2 == 1) ans++;

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
int main(void) {
    int N, M, C;
    cin >> N >> M >> C;
    vector<int> B(M);
    for_each(begin(B), end(B), [](auto &b) {
        cin >> b;
    });
    vector<vector<int>> A(N, vector<int>(M));
    for_each(begin(A), end(A), [](auto &a) {
        for_each(begin(a), end(a), [](auto &e) {
            cin >> e;
        });
    });
 
    int ans = count_if(begin(A), end(A), [&](auto a) {
        int sum = C;
        for (int i = 0; i < M; i++) {
            sum += a[i] * B[i];
        }
        return sum > 0;
    });
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#include <iomanip>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << endl
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
int dx8[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy8[8] = {0, 1, 0, -1, 1, 1, -1, -1};
int dx4[4] = {1, 0, -1, 0};
int dy4[4] = {0, 1, 0, -1};
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;}
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){ fill((T*)array, (T*)(array+N), val); }
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;
int main(void) {
    int N;
    cin >> N;

    double dp[3100][3100];//i枚目まで投げた時の表がj枚の確率
    double p[N];
    rep(i,N){
        cin >> p[i];
    }
    dp[0][0] = 1.0;
    rep(i,N){
       for(int j=0; j<=i; j++){
           //例えば三個目のコインで今まで表は0~2回出ているからそこから表裏で遷移
            dp[i+1][j+1] += dp[i][j]*p[i];
            dp[i+1][j] += dp[i][j]*(1-p[i]);
       }
    }

    double res = 0.0;
    //N回投げて表が上回ってるのは表が(N+1)/2回出てからなのでそこから足し合わせていく
    for(int j=(N+1)/2; j<=N;j++){
        res += dp[N][j];
    }

    cout << fixed << setprecision(10) << res << endl;
}

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

#define int long long
#define sp ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define cps CLOCKS_PER_SEC
#define mod (long long)1000000007
#define f first
#define s second
#define debug1(x) cerr<<x<<"\n"
#define debug2(x,y) cerr<<x<<" "<<y<<"\n"
#define debug3(x,y,z) cerr<<x<<" "<<y<<" "<<z<<"\n"
#define nl cerr<<"\n";
#define pq priority_queue
#define inf 0x3f3f3f3f
#define test cerr<<"abcd\n";
#define pi pair<int,int>
#define pii pair<int,pi>
#define pb push_back
#define mxn 500005

int32_t main(){
sp;
int n;
cin>>n;
cout<<(n-2)*180;

return 0;}


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

#define f first
#define s second
#define pb push_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define sz(v) (int)v.size()

#define MOO(i, a, b) for(int i=a; i<b; i++)
#define M00(i, a) for(int i=0; i<a; i++)
#define MOOd(i,a,b) for(int i = (b)-1; i >= a; i--)
#define M00d(i,a) for(int i = (a)-1; i>=0; i--)

#define FAST ios::sync_with_stdio(0); cin.tie(0);
#define finish(x) return cout << x << '\n', 0;
#define dbg(x) cerr << ">>> " << #x << " = " << x << "\n";
#define _ << " _ " <<

template<class T> bool ckmin(T& a, const T& b) {return b < a ? a = b, 1 : 0;}
template<class T> bool ckmax(T& a, const T& b) {return a < b ? a = b, 1 : 0;}

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef pair<ld,ld> pd;
typedef complex<ld> cd;

const int MAX_N = 1005;
const int inf = 1e9;
int n, m;
pi start, des;
bool arr[MAX_N][MAX_N];
bool vis[MAX_N][MAX_N];
int dis[MAX_N][MAX_N];

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

bool inBounds(int i, int j) {
    return 0 <= i && i < n && 0 <= j && j < m;
}

int main() { FAST
    cin >> n >> m;
    M00(i, n) M00(j, m) dis[i][j] = inf;
    cin >> start.f >> start.s;
    cin >> des.f >> des.s;
    start.f--; start.s--; des.f--; des.s--;
    M00(i, n) {
        string s; cin >> s;
        M00(j, m) {
            if(s[j] == '#') arr[i][j] = 1;
            else arr[i][j] = 0;
        }
    }
    deque<pair<pi, int>> dq;
    dq.pb(mp(start, 0));
    dis[start.f][start.s] = 0;
    while(!dq.empty()) {
        pair<pi, int> t = dq.front(); dq.pop_front();
        if(vis[t.f.f][t.f.s]) continue;
        vis[t.f.f][t.f.s] = 1;

        M00(i, 4) {
            int newx = t.f.f + dx[i];
            int newy = t.f.s + dy[i];
            if(inBounds(newx, newy) && !arr[newx][newy]) {
                if(dis[newx][newy] > dis[t.f.f][t.f.s]) {
                    dis[newx][newy] = dis[t.f.f][t.f.s];
                    dq.push_front(mp(mp(newx,newy),dis[newx][newy]));
                }
            }
        }
        for(int DX = -2; DX <= 2; DX++) {
            for(int DY = -2; DY <= 2; DY++) {
                int newx = t.f.f + DX;
                int newy = t.f.s + DY;
                if(inBounds(newx, newy) && mp(newx, newy) != t.f && !arr[newx][newy]) {
                    if(dis[newx][newy] > dis[t.f.f][t.f.s] + 1) {
                        dis[newx][newy] = dis[t.f.f][t.f.s] + 1;
                        dq.push_back(mp(mp(newx, newy), dis[newx][newy]));
                    }
                }
            }
        }
    }
    if(dis[des.f][des.s] == inf) {
        cout << "-1\n";
    } else {
        cout << dis[des.f][des.s] << "\n";
    }
}



Measured memory_bytes: 9568
M=410
e=enumerate
_,*s=open(0)
r=s+['#'*20]
d=eval('[M]*M,'*M)
for i,t in e(s):
  for j,u in e(t):
    k=i*20+j
    if u>'#'<t[j+1]:
      d[k][k+1]=1
      d[k+1][k]=1
    if u>'#'<r[i+1][j]:
      d[k][k+20]=1
      d[k+20][k]=1
r=range(M)
for i in r:d[i][i]=0
for k in r:
  for i in r:
    for j in r:d[i][j]=min(d[i][j],d[i][k]+d[k][j])
print(max(u for t in d for u in t if u<M))

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

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

  if (N / 100 == N % 10){
    cout << "Yes" << endl;
  }
  else
  {
    cout << "No" << endl;
  }
  
}

Measured memory_bytes: 3604
import sys
import itertools
sys.setrecursionlimit(10000)
def resolve():
    N = int(input())
    Reds = sorted([list(map(int, input().split(" "))) for i in range(N)], key=lambda x: x[1], reverse=True)
    Blues = sorted([list(map(int, input().split(" "))) for i in range(N)], key=lambda x: x[0])
    used = []
    for red in Reds:
        for blue in Blues:
            if blue not in used and able_to_be_pair(red, blue):
                used.append(blue)
                break
    print(len(used))

def able_to_be_pair(red, blue):
    return True if (blue[0] - red[0]) > 0 and (blue[1] - red[1]) > 0 else False

if '__main__' == __name__:
    resolve()

Measured memory_bytes: 39792
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>
#include <tuple>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e12;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1
#define MAX_N 100100

ll sq(ll num) { return num*num; }
ll mod_pow(ll x, ll n) {
	if (n == 0)return 1;
	if (n == 1)return x%MOD;
	ll res = sq(mod_pow(x, n / 2));
	res %= MOD;
	if (n % 2 == 1) {
		res *= x;
		res %= MOD;
	}
	return res;
}
ll mod_add(ll a, ll b) { return (a + b) % MOD; }
ll mod_sub(ll a, ll b) { return (a - b + MOD) % MOD; }
ll mod_mul(ll a, ll b) { return a*b % MOD; }

int n;
ll cnt[100][100];

int main() {
	cin >> n;
	rep(i, n) {
		string s;
		cin >> s;
		rep(j, s.size()) {
			cnt[i][s[j] - 'a']++;
		}
	}
	string ans;
	rep(i, 26) {
		ll k = INF;
		rep(j, n) {
			k = min(cnt[j][i], k);
		}
		string buf = "a";
		buf[0] += i;
		rep(j, k) {
			ans += buf;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long MOD=1000000007;

int main() {
  int n;
  string s;
  cin>>n>>s;
  
  int count=0;
  stack<char> sta;
  rep(i,n){
    if(s[i]=='(') sta.push(s[i]);
    else{
      if(!sta.empty() && sta.top()=='(') sta.pop();
      else count++;
    }
  }
  rep(i,count) cout<<"(";
  cout<<s;
  while(!sta.empty()){
    cout<<")";
    sta.pop();
  }
  cout<<endl;
}

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

int main(){
    //input
    long long N;
    cin >> N;
    long long A[N+1];
    long long i;
    bool zeroexist=0;
    for(i=1; i<=N; i++){
        cin >> A[i];
        if(A[i]==0){
            zeroexist=1;
        }
    }

    //calc
    long long seki=1;
    for(i=1; i<=N; i++){
        if(zeroexist==1){
            break;
        }
        if(seki>1000000000000000000/A[i]){
            seki=-1;
            break;
        }
        seki=seki*A[i];
    }

    //answer
    if(seki>0 && zeroexist==0){
        cout << seki << endl;
    }else if(zeroexist==1){
        cout << 0 << endl;
    }else{
        cout << -1 << endl;
    }
    system("pause");
    return 0;
}

Measured memory_bytes: 4508
import sys

x=int(input())
for a in range(10**3):
    for b in range(10**3):
        if a**5 - b**5==x:
            print(a,b)
            sys.exit()
        if (-a)**5 - b**5==x:
            print(-a,b)
            sys.exit()
        if a**5 - (-b)**5==x:
            print(a,-b)
            sys.exit()
        if (-a)**5 - (-b)**5==x:
            print(-a,-b)
            sys.exit()

Measured memory_bytes: 66112
from collections import defaultdict
while True:
    n=input()
    if n==0:break
    dic=defaultdict(int)
    H=map(int,raw_input().split())
    for i in range(n):
        dic[H[i+1]-H[i]]+=1
    d=dict((j,i) for i,j in dic.items())
    diff=d[max(d)]
    for i in range(n):
        t=H[i]+diff
        if H[i+1]!=t:
            if i!=0:
                print H[i+1]
                break
            else:
                print H[i] if H[i+2]-H[i+1]==diff else H[i+1]
                break

Measured memory_bytes: 4684
n, _ = map(int, input().split())
numbers = list(map(int, input().split()))
reqs = {
    1: 2,
    2: 5,
    3: 5,
    4: 4,
    5: 5,
    6: 6,
    7: 3,
    8: 7,
    9: 6,
}

memo = {}


def max_counts(a, b):
    """
    a と b 大きい方を返す
    :param a: solve() の返り値
    :param b: solve() の返り値
    :return:
    """
    if a is None:
        return b
    if b is None:
        return a
    # 桁数は大きいほうが大きい
    if sum(a) > sum(b):
        return a
    if sum(a) < sum(b):
        return b
    # 桁数が同じなら、大きい数字の多いほうが大きい
    for a_c, b_c in zip(reversed(a), reversed(b)):
        if a_c > b_c:
            return a
        if a_c < b_c:
            return b
    return a


# https://atcoder.jp/contests/abc118/submissions/4911280
# DP 版
memo[0] = [0 for _ in range(10)]
for i in range(n):
    if i in memo:
        for num in numbers:
            next_n = i + reqs[num]
            next_counts = memo[next_n] if next_n in memo else None
            if next_n <= n:
                memo[next_n] = max_counts(
                    next_counts,
                    memo[i][:num] + [memo[i][num] + 1] + memo[i][num + 1:]
                )

ans = ''
for num in range(9, 0, -1):
    for _ in range(memo[n][num]):
        ans += str(num)
print(ans)


Measured memory_bytes: 5396
double g[100][100],G[100],H[100],a;main(n,m,i,j){for(;scanf("%d%d",&n,&m),n;printf("%.2f\n",a)){for(i=n;i--;G[i]=1)for(j=n;j--;)scanf("%lf",g[i]+j);for(;--m;memcpy(G,H,8*n))for(i=n;i--;)for(H[i]=0,j=n;j--;a>H[i]?H[i]=a:0)a=G[j]*g[j][i];for(a=0;n--;)G[n]>a?a=G[n]:0;}exit(0);}

Measured memory_bytes: 0