akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        sc.close();

        int count = 0;
        for (int i = 1; i <= n; i++) {
            if (i % 2 == 0) {
                continue;
            }
            int c = 0;
            for (int j = 1; j <= i; j++) {
                if (i % j == 0) {
                    c++;
                }
            }
            if (c == 8) {
                count++;
            }
        }
        System.out.println(count);
    }
}


Measured memory_bytes: 20948
#include<iostream>
using namespace std;
int main(){
  int h,w;
  cin >> h >> w;
  while(h!=0){
    int i,j;
    for(i=0;i<h;i++){
      for(j=0;j<w;j++){
	if((i%2==0&&j%2==0)||(i%2==1&&j%2==1))
	  cout << "#";
	else cout << ".";
      }
      cout << endl;
    }
    cout << endl;
    cin >> h >> w;
  }
  return 0;
}


Measured memory_bytes: 3116
def BFS(K,edges,N):
  roots=[ [] for i in range(N)]
  for a,b,c in edges:
    roots[a-1]+=[(b-1,c)]
    roots[b-1]+=[(a-1,c)]
  dist=[-1]*N
  stack=[]
  stack.append(K)
  dist[K]=0
  while stack:
    label=stack.pop(-1)
    for i,c in roots[label]:
      if dist[i]==-1:
        dist[i]=dist[label]+c
        stack+=[i]
  return [i%2 for i in dist]
N = int(input())
edges = []
for n in range(N-1):
    a,b,c = map(int, input().split())
    edges.append([a,b,c])
ans = BFS(0,edges,N)
for a in ans:
    print (a)


Measured memory_bytes: 59376
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {

	// エラトステネスのふるい(n以下の素数を求める)
	public static boolean[] sieve (int n) {
		boolean[] isPrime = new boolean[n + 1];
		Arrays.fill(isPrime, true);
		for (int i = 4; i < isPrime.length; i += 2)
			isPrime[i] = false;
		for (int i = 3; i * i <= n; i += 2) {
			for (int j = 3; i * j <= n; j += 2)
				isPrime[i * j] = false;
		}
		return isPrime;
	}

	public static int solve (int n) {
		int ret = 0;
		boolean[] primes = sieve(n);
		ret = primes[n - 2] ? ret + 1 : ret;
		for (int i = 3; i <= n / 2; i += 2) {
			if (!primes[i]) continue;
			ret = primes[n - i] ? ret + 1 : ret;
		}
		return ret;
	}

	public static void main(String[] args) throws IOException {

		BufferedReader br =
				new BufferedReader(new InputStreamReader(System.in));

		while (true) {
			int n = Integer.parseInt(br.readLine());
			if (n == 0) break;
			System.out.println(solve(n));
		}

	}

}

Measured memory_bytes: 89684
import java.util.*;
import java.lang.*;
import java.io.*;
import java.math.*;
 
import java.util.*;
import java.lang.*;
import java.io.*;

@SuppressWarnings("unchecked")
public class Main implements Runnable {

  static BufferedReader in;
  static PrintWriter out;
 
  public static void main(String[] args) {
      new Thread(null, new Main(), "whatever", 1<<29).start();
  }
 
  public void run() {
    in = new BufferedReader(new InputStreamReader(System.in));
    out = new PrintWriter(System.out, false);
 
    try
    {
      // in = new BufferedReader(new FileReader("class_treasurer.txt"));
      // out = new PrintWriter("output.txt");

      int t,x1,n,r,inner;
      String str;
      String[] token;

      str=in.readLine().trim();
      token=str.split(" ");
      n=Integer.parseInt(token[0]);
      r=Integer.parseInt(token[1]);

      if(n>=10) {
        inner=r;
      }
      else {
        inner=r+(100*(10-n));
      }

      out.println(inner);


      out.flush();
      out.close();
    }
    catch(Exception e) {
      e.printStackTrace();
    }
  }
}


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

#define REP(i,n) for(ll i = 0;i < n;++i)
#define PB(s) push_back(s)
#define ST(n) sort(n.begin(),n.end())

using namespace std;
typedef long long ll;
int main(){
  int N;
  cin >> N;
  vector<int> W;
  ll total=0;
  REP(i,N){
    int x;
    cin >> x;
    total+=x;
    W.push_back(x);
  }
  ll total2=0,minmin=total;
  REP(i,N){
    total-=W[i];
    total2+=W[i];
    minmin=min(abs(total-total2),minmin);
  }
  cout << minmin << endl;
}


Measured memory_bytes: 256
using System;

class Program {
    static void Main() {
       for(int i = 1; i <= 9; i++) {
            for(int j = 1; j <= 9; j++) {
                Console.WriteLine(i.ToString() + "x" + j.ToString() + "=" + (i * j).ToString());
            }
        }
    }
}

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

#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
using ll = long long;
using ld = long double;
const int MOD = 1e9+7;


int main() {
    string s; cin >> s;

    map<char, int> mp;
    for(int i = 0; i < (int)s.size(); i++){
        mp[s[i]]++;
    }

    for(char c = 'a'; c <= 'z'; c++){
        if(0 < mp[c]) continue;
        cout << s + c << endl;
        return 0;
    }

    if(s == "zyxwvutsrqponmlkjihgfedcba"){
        cout << -1 << endl;
        return 0;
    }

    string t = s;
    next_permutation(ALL(s));
    string ans = "";
    for(int i = 0; i < (int)s.size(); i++){
        ans += s[i];
        if(s[i] > t[i]){
            cout << ans << endl;
            return 0;
        }
    }

    return 0;
}


Measured memory_bytes: 3600
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <string>
#include <map>

using namespace std;
int main(int argc, const char * argv[]) {
    
    int n;
    cin >> n;

    vector<int> w(n);
    cin >> w[0];
    for (int i=1; i<n; i++) {
        int t;
        cin >> t;
        w[i] = t+w[i-1];
    }

    int m=100000;
    for (int i=0; i<n; i++) {
        m = min(m, abs(w[n-1] - w[i] - w[i]));
    }
    
    cout << m << endl;
    return 0;
}

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

static const int N = 100;

int main(void) {
	int M[N][N];
	int n, u, k, v;
	cin >> n;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			M[i][j] = 0;
		}
	}
	for (int i = 0; i < n; i++) {
		cin >> u >> k;
		u--;
		for (int j = 0; j < k; j++) {
			cin >> v;
			v--;
			M[u][v] = 1;
		}
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			if (j) cout << " ";
			cout << M[i][j];
		}
		cout << endl;
	}
	return 0;
}


Measured memory_bytes: 3104
#include <stdio.h>

int main(void){
  int N;
  scanf("%d",&N);
  
  if(N % 10 == 3){
    printf("bon");
  }else if(N % 10 == 0 || N % 10 == 1 || N % 10 == 6 || N % 10 == 8){
    printf("pon");
  }else{
    printf("hon");
  }
  
  return 0;
}



Measured memory_bytes: 1736
program main
  implicit none
  integer :: n, k, q, m, dig = 0
  read *, n, k

  do
    dig = dig + 1
    q = int(n / k)
    m = mod(n, k) 
    if (q == 0) then
        exit
    else
        n = q
    end if
  end do
  print '(i0)', dig

end program

Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
int main(){
    long long a,b,k;
    cin>>a>>b>>k;

    if(k>a){
        k = k-a;
        a = 0;
        if(k > b){
            b = 0;
        }
        else{
            b = b-k;
        }
    }
    else{
        a = a-k;
    }
    cout<<a<<" "<<b<<"\n";


}


Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
using namespace std;

#define ll         long long
#define PI         acos(-1.0)
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)

ll dp[60][60][3000];
ll N,A;
ll x[60];

int main(){
    cin>>N>>A;
    FOR(i, 0, N) cin>>x[i];
    FOR(i, 0, 60) FOR(j, 0, 60) FOR(k, 0, 3000) dp[i][j][k] = 0;
    dp[0][0][0] = 1;
    FOR(i, 0, N){
        FOR(j, 0, N){
            FOR(k, 0, 3000){
                if(dp[i][j][k]==0) continue;
                //使わない時
                dp[i+1][j][k] += dp[i][j][k];
                //使う時
                dp[i+1][j+1][k+x[i]] += dp[i][j][k];
            }
        }
    }
    ll ans = 0;
    FOR(i, 1, N+1){
        ans += dp[N][i][i*A];
    }
    cout << ans << endl;
}

Measured memory_bytes: 84608
#include<iostream>
#include<vector>
#include<complex>
#include<map>
#include<algorithm>
#include<cmath>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)
const int N = 24;
const double eps = 1e-10;
typedef complex<double> P;
class st{
public:
  P a;
  double r;
  int color;
  int id;
  bool operator<(const st & a)const{
    if (color != a.color)return color < a.color;
    return id < a.id;
  }
};

int over[N];

int is_intersected_circle(P a,P b,double r1,double r2){
  double d=abs(a-b);
  if (d < eps && abs(r1-r2) < eps)return 3;
  if (d+r2 < r1)return 0;
  if (d+r1 < r2)return 1;
  if (d > r1+r2) return 4;
  if (abs((r1+r2)-d) < eps)return 4;
  return 2;
}

vector<int> edge[N];
short dp[(1<<N)];
int colorstart[5];

short search(int state,st *in,int n){
  if (state == (1<<n))return 0;
  short &ret = dp[state];
  if (ret == -1){
    ret=0;
    //color1
    rep(k,4){
      REP(i,colorstart[k],colorstart[k+1]){
        int now=in[i].id;
        if (((1<<now)&state) != 0)continue;
        if ((over[now]&state) == over[now]);
        else continue;
        REP(j,i+1,colorstart[k+1]){
          int next=in[j].id;
          if (((1<<next)&state) != 0)continue;
          if ((over[next]&state) == over[next]);
          else continue;
          //cout <<"remove " << now <<" " << next << endl;
          ret=max(ret,(short)(2+search(state|(1<<now)|(1<<next),in,n)));
        }
      }
    }
  }
  return ret;
}

main(){
  int n;
  while(cin>>n && n){
    rep(i,(1<<n))dp[i]=-1;
    rep(i,n)edge[i].clear();
    st in[n];
    rep(i,n){
      cin>>in[i].a.real()>>in[i].a.imag()>>in[i].r>>in[i].color;
      in[i].id=i;
    }
    sort(in,in+n);
    rep(i,n){
      rep(j,n){
        if (in[i].id <= in[j].id)continue;
        int tmp=is_intersected_circle(in[i].a,in[j].a,in[i].r,in[j].r);
        if (tmp == 0 || tmp == 1 || tmp == 2 || tmp == 3){
          edge[in[i].id].push_back(in[j].id);
        }
      }
    }

    rep(i,n){
      int now=in[i].id;
      over[now]=0;
      rep(j,edge[now].size()){
        int next=edge[now][j];
        over[now]|=(1<<next);
        //cout <<next << " is over " << now << endl;
      }
      //cout << now <<" hoge " << over[now] << endl;
    }
    rep(i,5)colorstart[i]=n;
    rep(i,n){
      colorstart[in[i].color-1]=min(colorstart[in[i].color-1],i);
    }

    //rep(i,5)cout << colorstart[i] << " ";cout << endl;
    cout << search(0,in,n) << endl;
  }
  return false;
}

Measured memory_bytes: 32000
#!/usr/bin/env python3
#AGC8 A

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

x,y = LI()
if x > 0 and y > 0:
    if x > y:
        print(x-y+2)
    else:
        print(y-x)
elif x < 0 and y > 0:
    if -x > y:
        print((-x)-y+1)
    else:
        print(y-(-x)+1)
elif x > 0 and y < 0:
    if -x > y:
        print((-y)-x+1)
    else:
        print(x-(-y)+1)
elif x < 0 and y < 0:
    if x > y:
        print(abs(y)-abs(x)+2)
    else:
        print(y-x)
else:
    if x == 0:
        if y >= 0:
            print(y)
        else:
            print(abs(y)+1)
    elif y == 0:
        if x <= 0:
            print(-x)
        else:
            print(x+1)


Measured memory_bytes: 38384
n, k = map(int, input().split())
lis = []
for i in range(n):
    a = list(map(int, input().split()))
    lis.append(a)
lis.sort()
cnt = 0
for i in range(n):
    cnt += lis[i][1]
    if cnt >= k:
        print(lis[i][0])
        break

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n);
  int sum = 0;
  rep(i, n) {
    cin >> a[i];
    sum += a[i];
  }

  int cnt = 0;
  rep(i, n) {
    if (a[i]*4*m >= sum) cnt++;
  }

  if (cnt >= m) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 256
a,b,C=gets.chomp.split(" ").map(&:to_i)
S = 0.5 * a * b * Math.sin(Math::PI * C / 180.0)
L = a + b + (a**2 + b**2 - 2*a*b*Math.cos(Math::PI * C / 180.0))**0.5
h = Math.sin(Math::PI * C / 180.0) * b 
puts "#{format("%0.5f", S)} #{format("%0.5f", L)} #{format("%0.5f", h)}"


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

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

  vector<char> V;
  for (int i = 0; i < S.size(); i++) {
    V.push_back(S[i]);
  }

  int ans = 0;
  for (int i = 0; i + 1  < V.size(); i++) {
    if (V[i] != V[i+1]) {
      V.erase(V.begin()+i, V.begin()+i+2);
      ans += 2;
      i = -1;
    }
  }

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

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

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

    vector<ll> w(N+1), v(N+1);
    for(int i = 1; i <= N; ++i){
        cin >> w[i] >> v[i];
    }

    ll dp[N+1][W+1];
    rep(j, W+1) dp[0][j] = 0;
    rep(i, N+1) dp[i][0] = 0;

    for(int i = 1; i <= N; ++i){
        for(int j = 1; j <= W; ++j){
            dp[i][j] = 0;
            if (j - w[i] < 0) dp[i][j] = dp[i-1][j];
            else dp[i][j] = max(dp[i-1][j], dp[i-1][j-w[i]] + v[i]);
        }
    }

    ll maxv = 0;
    rep(i, N+1) maxv = max(maxv, dp[i][W]);

    cout << maxv << endl;

    return 0;
}

Measured memory_bytes: 79104
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

const int maxn = 601;
vector<pair<int, int> > dir;
bool used[maxn][maxn], color[maxn][maxn];

double eps = 1e-9;

int get_sqr(int a, int b) {
    int c = sqrt(b - a * a) + eps;
    return c * c + a * a == b ? c : -1;
}

void get_dir(int n) {
    dir.clear();
    for (int i = 0; i * i <= n; i++) {
        int j = get_sqr(i, n);
        if (j != -1) {
            dir.push_back({i, j});
        }
    }
}

int n;

int dfs(pair<int, int> v, int col, vector<pair<int, int> > &path) {
    if (used[v.first][v.second]) {
        return 0;
    }
    used[v.first][v.second] = 1;
    color[v.first][v.second] = col;
    path.push_back(v);

    int sum = 0;
    for (auto &d : dir) {
        for (int dx : {-1, 1}) {
            for (int dy : {-1, 1}) {
                int x = v.first + d.first * dx;
                int y = v.second + d.second * dy;
                if (x < 0 || y < 0 || x >= n || y >= n) {
                    continue;
                }
                sum += dfs({x, y}, col ^ 1, path);
            }
        }
    }
    return (col ^ 1) + sum;
}

vector<pair<int, int> > good_vert(vector<pair<int, int> > vert) {
    memset(used, 1, sizeof(used));
    memset(color, 0, sizeof(color));

    for (auto &v : vert) {
        used[v.first][v.second] = 0;
    }

    for (auto &v : vert) {
        if (!used[v.first][v.second]) {
            vector<pair<int, int> > path;
            int cnt = dfs(v, 0, path);
            if (cnt < (int) path.size() - cnt) {
                for (auto &u : path) {
                    color[u.first][u.second] ^= 1;
                }
            }
        }
    }

    vector<pair<int, int> > res;
    for (auto v : vert) {
        if (!color[v.first][v.second]) {
            res.push_back(v);
        }
    }
    return res;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.precision(10);
    cout << fixed;

    int d1, d2;
    cin >> n >> d1 >> d2;
    n *= 2;
    vector<pair<int, int> > vert;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            vert.push_back({i, j});
        }
    }

    get_dir(d1);
    vert = good_vert(vert);
    get_dir(d2);
    vert = good_vert(vert);
    assert((int)vert.size() >= n * n / 4);
    vert.resize(n * n / 4);
    for (auto v : vert) {
        cout << v.first << ' ' << v.second << '\n';
    }

    return 0;
}

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

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


int main()
{
    int n;
    long long int a[10005]={};
    scanf("%d\n",&n);
    long int ans=0;
    REP(i,n)
    {
        scanf("%lld ",&a[i]);
        while(a[i]%2==0)
        {
            a[i]=a[i]/2;
            ans+=1;
        }
    }
    printf("%ld",ans);
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i,ini,n) for(int i=ini;i<n;i++)
#define _rep(i,ini,n) for(int i=ini;i>=n;i--)
#define ToEnd(a) a.begin(),a.end()
uint64_t MOD=1000000007;

int main(){
    int N,A,B;
    cin>>N>>A>>B;
    string s;
    cin>>s;

    int a=0,b=0;
    for(auto c:s){
        if(c=='a' && a+b<A+B){
            a++;
            cout<<"Yes"<<endl;
        }
        else if(c=='b' && a+b<A+B && b<B){
            b++;
            cout<<"Yes"<<endl;
        }
        else cout<<"No"<<endl;
    }
}

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

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            var solver = new Solver();
            solver.Calc();
        }
    }

    public class Solver
    {
        public struct AB
        {
            public int A;
            public int B;
        }

        int N;
        List<string> list = new List<string>();



        public void AddNext(string input, int count)
        {


            if (count == N)
            {
                list.Add(input + "1");
                list.Add(input + "0");
                return;
            }
            else
            {

                AddNext(input + "1", count + 1);
                AddNext(input + "0", count + 1);
            }

        }

        public void Calc()
        {

            var N = Console.ReadLine();

            switch (int.Parse(N.Last().ToString()))
            {
                case 3:
                    Console.WriteLine("bon");
                    break;
                case 0:
                case 1:
                case 6:
                case 8:
                    Console.WriteLine("pon");
                    break;
                default:
                    Console.WriteLine("hon");
                    break;
            }

            //var p = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();




        }


    }

}


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

int dp[110000];
int h[110000];

int main(){
    int n;
    cin>>n;
    for(int i=0; i<n; i++){
        cin>>h[i];
    }
    for(int i=0; i<n; i++){
        dp[i] = mod;
    }
    dp[0]=0;
    for(int i=0; i<n; i++){
        if(n>i+1){
            dp[i+1] = min(dp[i+1], dp[i]+abs(h[i] - h[i+1]));
        }
        if(n>i+2){
            dp[i+2] = min(dp[i+2], dp[i]+abs(h[i] - h[i+2]));
        }
    }
    cout<<dp[n-1];



return 0;
}


Measured memory_bytes: 1024
N = input()
A = input()
M = [int(x) for x in N.split(' ')]
B = [int(x) for x in A.split(' ')]
for i in range(M[1]):
     M[0] = M[0] - B[i]
if M[0] >= 0:
    print(M[0])
else:
    print(-1)

Measured memory_bytes: 9820
import java.util.Scanner;


public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int d = sc.nextInt();

		System.out.println((double)(n-d)*(d==0?1:2)*(m-1)/n/n);
	}
}


Measured memory_bytes: 23636
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <iterator>
#include <math.h>
#include <cmath>
#include <deque>
#include <limits>
#include <numeric>
#include <boost/math/common_factor_rt.hpp>


#define INF 100000000
#define MOD 1000000007

#define ll long long

using namespace std;
int dp[100050];

int main() {
	dp[0] = 0;
	for (int i = 1; i < 100010; i++)
	{
		dp[i] = INF;
		int power = 1;
		while (power <= i) {
			dp[i] = min(dp[i], dp[i - power] + 1);
			power *= 6;
		}

		power = 1;
		while (power <= i) {
			dp[i] = min(dp[i], dp[i - power] + 1);
			power *= 9;
		}

	}
	int n;
	cin >> n;
	cout << dp[n] << endl;
	return 0;
}



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

#define rep(i, a, b) for (int i = a, i##end = b; i <= i##end; ++i)
#define per(i, a, b) for (int i = a, i##end = b; i >= i##end; --i)
#define rep0(i, a) for (int i = 0, i##end = a; i < i##end; ++i)
#define per0(i, a) for (int i = (int)a-1; ~i; --i)
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define chkmax(a, b) a = max(a, b)
#define chkmin(a, b) a = min(a, b)
#define x first
#define y second
#define enter putchar('\n')

typedef long long ll;
typedef double DB;

const DB eps = 1e-12;
const DB PI = acos(-1);

int sgn(DB x) { return fabs(x) < eps ? 0 : (x > 0 ? 1 : -1); }

struct Point {
	DB x, y;
	Point(DB x = 0, DB y = 0) : x(x), y(y) {}
	Point operator + (Point a) { return Point(x + a.x, y + a.y); }
	Point operator - (Point a) { return Point(x - a.x, y - a.y); }
	Point operator - () { return Point(-x, -y); }
	friend Point operator * (DB k, Point a) { return Point(k * a.x, k * a.y); }
	Point operator / (DB k) { return Point(x / k, y / k); }
	DB operator % (Point a) { return x * a.x + y * a.y; }
	DB operator / (Point a) { return x * a.y - y * a.x; }
	operator DB() { return sqrt(x*x + y*y); }
	bool operator < (const Point &a) const { int d1 = sgn(x-a.x), d2 = sgn(y-a.y); return d1 < 0 || (d1 == 0 && d2 < 0); }
};

struct Circle { Point O; DB r; };

Point Proj(Point P, Point P1, Point P2) {
	Point v = P2-P1; DB t = (P-P1)%v / (v%v);
	return P1 + t*v;
}

Point GetLineInter(Point P1, Point P2, Point Q1, Point Q2) {
	Point v = P2-P1, w = Q2-Q1; DB t = (Q1-P1)/w / (v/w);
	return P1 + t*v;
}

int Direct1(Point P, Point P1, Point P2) { return sgn((P1-P)%(P2-P)); }
int Direct2(Point P, Point P1, Point P2) { return sgn((P1-P)/(P2-P)); }

int q;

Circle GetInnerCir(Point A, Point B, Point C) {
	Point v1 = B-A, v2 = C-A, v3 = C-B;
	v1 = v1/DB(v1), v2 = v2/DB(v2), v3 = v3/DB(v3);
	Point P = GetLineInter(A, A + (v1+v2), B, B + (v3-v1));
	return (Circle){P, DB(P-Proj(P, A, B))};
}

Circle GetOuterCir(Point A, Point B, Point C) {
	Point M = 0.5*(A+B), N = 0.5*(A+C), v = B-A, w = C-A;
	Point P = GetLineInter(M, M + Point(v.y, -v.x), N, N + Point(w.y, -w.x));
	return (Circle){P, DB(P-A)};
}

std::pair<Point, Point> GetCirLineInter(Circle C, Point P1, Point P2) {
	Point P = Proj(C.O, P1, P2), v = P2-P1; v = v/DB(v);
	DB d = DB(C.O-P);
	if (!sgn(d-C.r)) return std::make_pair(P, P);
	DB t = sqrt(C.r*C.r - d*d);
	return std::make_pair(P+t*v, P-t*v);
}

int main() {
	Circle C;
	scanf("%lf%lf%lf", &C.O.x, &C.O.y, &C.r);
	scanf("%d", &q);
	while (q--) {
		Point P1, P2;
		scanf("%lf%lf%lf%lf", &P1.x, &P1.y, &P2.x, &P2.y);
		std::pair<Point, Point> X = GetCirLineInter(C, P1, P2);
		if (X.y < X.x) std::swap(X.x, X.y);
		printf("%.10lf %.10lf %.10lf %.10lf\n", X.x.x, X.x.y, X.y.x, X.y.y);
	}
	return 0;
}


Measured memory_bytes: 3220
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define ld long double
#define INF 1000000000000000000
typedef pair<ll, ll> pll;
typedef pair<int, int> pint;

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

    string s;
    cin >> s;
    int N = s.size();
    reverse(all(s));
    ll exp = 1;
    vector<ll> A(N);
    ll MOD = pow(10, 9) + 7;
    for (int i = 0; i < N; i++) {
        if (s[i] != '?') {
            int n = s[i] - '0';
            A[i] = n * exp % 13;
        } else
            A[i] = exp;
        exp *= 10;
        exp %= 13;
    }

    vector<vector<ll>> dp(N + 5, vector<ll>(15));
    dp[0][0] = 1;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < 13; j++) {
            ll next;
            if (s[i] == '?') {
                for (int k = 0; k < 10; k++) {
                    next = (j + A[i] * k) % 13;
                    dp[i + 1][next] += dp[i][j];
                    dp[i + 1][next] %= MOD;
                }
            } else {
                next = (j + A[i]) % 13;
                dp[i + 1][next] += dp[i][j];
                dp[i + 1][next] %= MOD;
            }
        }
    }

    cout << dp[N][5] << endl;
}

Measured memory_bytes: 19048
from sys import stdin
import math
import fractions
from collections import deque
from collections import Counter
import itertools
 
INF = 10 ** 10
 
MOD = 10**9 + 7
 
N, K = [int(x) for x in stdin.readline().rstrip().split()]
A = [int(x) for x in stdin.readline().rstrip().split()]
 
 
cnt = 0
 
for i in range(N):
    for j in range(i+1, N):
        if A[i] > A[j]:
            cnt += 1

if K >= 2:
    cnt = cnt * K
 
cnt2 = 0
 
if K >= 2:
    for i in range(N):
        for j in range(N):
            if A[i] > A[j]:
                cnt2 += 1
 
    tmp = ((K) * (K-1)) // 2
 
    cnt2 = cnt2 * tmp
 
cnt = (cnt + cnt2) % MOD
 
print(cnt)

Measured memory_bytes: 67432
#include <iostream>
#include <string> 
#include <vector> 
#include <algorithm> 
#include <utility> 
#include <tuple> 
#include <cstdint> 
#include <cstdio> 
#include <map> 
#include <queue> 
#include <set> 
#include <stack> 
#include <deque> 
#include <unordered_map> 
#include <unordered_set> 
#include <bitset> 
#include <cctype> 
#include <math.h>
#include <cmath>
using namespace std;

#define int long long
#define endl "\n"
#define all(v)  v.begin(),v.end()
#define fir first
#define sec second
#define fro front
#define m_p make_pair
#define rep(i,n)  for(int i=0; i<(int) (n); i++)
#define vecin(v) for(int i=0; i<(int)v.size(); i++)cin>>v[i];

const int mod = 1000000007;
const int INF = 2000000015;
const int MAX = 510000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
int jousu(int x00, int y00) {
	int z00 = 1;
	for (int i = 0; i < y00; i++) {
		z00 *= x00;
	}
	return z00;
}
int keta(int x00) {
	int z00 = x00;
	int w00 = 0;
	while (z00 != 0) {
		z00 /= 10;
		w00++;
	}
	return w00;
}
int krag(double xx) {
	return INF - (int)(INF - xx);
}


int modinv(int a, int m) {
	int b = m, u = 1, v = 0;
	while (b) {
		int t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
int modpow(int a, int n) {
	int res = 1;
	while (n > 0) {
		if (n & 1) res=res* a% mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}
int com(int xx, int yy) {
	int zz = 1;
	for (int i = xx; i > xx - yy; i--) {
		zz *= i;
		zz %= mod;
	}
	for (int i = 1; i <= yy; i++) {
		zz *= modinv(i, mod);
		zz %= mod;
	}
	return zz;
}
int gcd(int xx, int yy) {
	int p = xx;
	int q = yy;
	if (q > p)swap(p, q);
	while (p % q != 0) {
		p %= q;
		swap(p, q);
	}
	return q;
}
int lcm(int xx, int yy) {
	return xx * yy / gcd(xx, yy);
}
bool prime(int xx) {
	int a = xx;
	for (int i = 2; i * i <= xx; i++) {
		if (xx % i == 0) {
			return 0;
		}
	}
	return 1;
}



signed main() {
	int a, b, c, d,x,y;
	cin >> a >> b >> c >> d;
	x = krag((a + 0.0) / d);
	y = krag((c + 0.0) / b);
	if (x >= y)cout << "Yes" << endl;
	else cout << "No" << endl;
}


Measured memory_bytes: 3636
s=int(input())
s1=s//100
s2=s-s1*100
if 0<s1<=12 and 0<s2<=12:
    print("AMBIGUOUS")
elif (s1>12 or s1==0) and 0<s2<=12:
    print("YYMM")
elif 0<s1<=12 and (s2>12 or s2==0):
    print("MMYY")
else:
    print("NA")

Measured memory_bytes: 9192
#include <cstdio>
#include <cmath>
#include <complex>
using namespace std;

#define INF 1e99
#define EPS 1e-7

typedef complex<double> point;
typedef const point &rpoint;


double cross(rpoint a, rpoint b){
	return a.real() * b.imag() - a.imag() * b.real();
}

double intersect(point pa1, point pa2, point pb1, point pb2){
	point difa = pa2 - pa1;
	point difb = pb2 - pb1;
	point difab1 = pb1 - pa1;

	double D = cross(difa, -difb);

	if(abs(D) > EPS){
		double t = cross(difab1, -difb) / D;
		double s = cross(difa, difab1) / D;
		
		if(t >= 0.0 && t <= 1.0 && s >= 0.0 && s <= 1.0){
			return t;
		}
	}
	return INF;
}

int main(){
	point s[3], f[3], z[3];
	int x1, x2, y1, y2;

	while(true){
		for(int i = 0; i < 3; ++i){
			if( scanf("%d%d%d%d", &x1, &y1, &x2, &y2) != 4 ){
				return 0;
			}
			s[i] = point(x1, y1);
			f[i] = point(x2, y2);
		}
		
		int j;
		for(j = 0; j < 3; ++j){
			double t = intersect(s[j], f[j], s[(j+1)%3], f[(j+1)%3]);
			if( t == INF ){
				puts("kyo");
				break;
			}
			
			z[j] = (1.0 - t) * s[j] + t * f[j];
		}
		
		if( j == 3 ){
			double s = abs( cross(z[1] - z[0], z[2] - z[0]) ) * 0.5;
			
			if( s >= 1.9e6 ){
				puts("dai-kichi");
			}
			else if( s >= 1e6 ){
				puts("chu-kichi");
			}
			else if( s >= 1e5 ){
				puts("kichi");
			}
			else if( s > EPS ){
				puts("syo-kichi");
			}
			else{
				puts("kyo");
			}
		}
	}
}

Measured memory_bytes: 1012
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <queue>

using namespace std;

//x 日目に、株の売却が終了した時点の所持金の最大値。
long long dp[90];

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

    pair<long long, long long> money_stock;

    vector<long long> stock_price(N+1);
    for(int i=1; i<=N; ++i){
        cin >> stock_price[i];
    }

    dp[1] = 1000;

    for(int i=2; i<=N; ++i){
        //i − 1 日目から何もしない場合
        dp[i] = dp[i-1];
        for(int j=1; j<=i-1; ++j){
            //j 日目に 全財産を使って株を買い、i 日目に株を全部売る場合
            long long stock_num = dp[j] / stock_price[j];
            long long money = dp[j] + (stock_price[i] - stock_price[j])* stock_num;
            dp[i] = max(dp[i], money);
        }

    }

    cout << dp[N] << endl;

}



Measured memory_bytes: 3596
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline int rd_int(void){
  int x;
  rd(x);
  return x;
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(const char c[]){
  int i=0;
  for(i=0;c[i]!='\0';i++){
    putchar_unlocked(c[i]);
  }
}
int S = 3;
int A[3][3];
int B;
int ok[3][3];
int main(){
  int cTE1_r3A, i;
  int s;
  for(i=(0);i<(S);i++){
    int j;
    for(j=(0);j<(S);j++){
      rd(A[i][j]);
    }
  }
  int RZTsC2BF = rd_int();
  for(cTE1_r3A=(0);cTE1_r3A<(RZTsC2BF);cTE1_r3A++){
    rd(B);
    for(i=(0);i<(S);i++){
      int j;
      for(j=(0);j<(S);j++){
        if(A[i][j]==B){
          ok[i][j] = 1;
        }
      }
    }
  }
  for(i=(0);i<(3);i++){
    int j;
    s = 0;
    for(j=(0);j<(3);j++){
      s += ok[i][j];
    }
    if(s==3){
      wt_L("Yes");
      wt_L('\n');
      return 0;
    }
    s = 0;
    for(j=(0);j<(3);j++){
      s += ok[j][i];
    }
    if(s==3){
      wt_L("Yes");
      wt_L('\n');
      return 0;
    }
  }
  s = 0;
  for(i=(0);i<(3);i++){
    s += ok[i][i];
  }
  if(s==3){
    wt_L("Yes");
    wt_L('\n');
    return 0;
  }
  s = 0;
  for(i=(0);i<(3);i++){
    s += ok[i][S-1-i];
  }
  if(s==3){
    wt_L("Yes");
    wt_L('\n');
    return 0;
  }
  wt_L("No");
  wt_L('\n');
  return 0;
}
// cLay varsion 20200227-1

// --- original code ---
// int S = 3, A[3][3], B;
// int ok[3][3];
// 
// {
//   int s;
//   rep(i,S) rep(j,S) rd(A[i][j]);
//   REP(rd_int()){
//     rd(B);
//     rep(i,S) rep(j,S) if(A[i][j]==B) ok[i][j] = 1;
//   }
// 
//   rep(i,3){
//     s = 0;
//     rep(j,3) s += ok[i][j];
//     if(s==3) wt("Yes"), return 0;
//     s = 0;
//     rep(j,3) s += ok[j][i];
//     if(s==3) wt("Yes"), return 0;
//   }
//   s = 0;
//   rep(i,3) s += ok[i][i];
//   if(s==3) wt("Yes"), return 0;
//   s = 0;
//   rep(i,3) s += ok[i][S-1-i];
//   if(s==3) wt("Yes"), return 0;
// 
//   wt("No");
// }


Measured memory_bytes: 256
#include <stdio.h>

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

typedef long long ll;
typedef long double ld;

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

  int min_so_far = 1e9;
  int n;
  cin >> n;
  int cnt = 0;
  while (n--) {
    int x;
    cin >> x;
    if (x <= min_so_far) {
      cnt++;
    }
    min_so_far = min(min_so_far, x);
  }
  cout << cnt;
}


Measured memory_bytes: 256
x1, y1, x2, y2 = map(int, input().split())

dx = x2 - x1
dy = y2 - y1

x3 = x2 - dy
y3 = y2 + dx
x4 = x3 - dx
y4 = y3 - dy

print(x3, y3, x4, y4)

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

int main() {
    int N, M; cin >> N >> M;
    for (int i = 0; i < M; i++) {
        int A; cin >> A;
        N -= A;
    }
    if (N < 0) {
        cout << -1 << endl;
    } else {
        cout << N << endl;
    }
}


Measured memory_bytes: 3632
#include<iostream>
#include<stdio.h>
#include<math.h>
using namespace std;
int main(){
    double x1,y1,x2,y2;
    cin >>x1 >>y1 >>x2 >>y2;
    printf("%.5f\n",sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)));
    return 0;
}


Measured memory_bytes: 3200
#include <iostream>
#include <string>
#include <vector>
#include <numeric>
int main() {
    int n, k;
    std::cin >> n >> k;
    std::string s;
    std::cin >> s;
    s += 'E';
    std::vector<int> a;
    int i = 0;
    while (i < n) {
        int x = 0;
        while (s[i] == '1') {
            x++;
            i++;
        }
        a.push_back(x);
        int y = 0;
        while (s[i] == '0') {
            y++;
            i++;
        }
        a.push_back(y);
    }
    a.push_back(0);
    n = a.size();
    k = std::min(n, k * 2 + 1);
    int ans = 0;
    for (i = 0; i <= n - k; i += 2) {
        int x = std::accumulate(&a[i], &a[i + k], 0);
        ans = std::max(ans, x);
    }
    std::cout << ans;
}

Measured memory_bytes: 1020
using System;


namespace ACTest
{
    class AOJDPLA
    {
        static void Main(string[] args)
        {
            // ??´??°?????\???
            // int a = int.Parse(Console.ReadLine());
            // ??????????????????????????´??°?????\???
            string[] input = Console.ReadLine().Split(' ');
            int pay = int.Parse(input[0]);
            int coin = int.Parse(input[1]);
            string[] input2 = Console.ReadLine().Split(' ');
            int[] numCoin = new int[input2.Length];
            for (int i = 0; i < input2.Length; i++)
            {
                numCoin[i] = int.Parse(input2[i]);
            }
            // ??????????????\???
            int[] T = new int[pay + 1];
            
            for (int i = 0; i < pay + 1; i++)
            {
                T[i] = pay;
            }
            T[0] = 0;
            ///DP
            for (int i = 0; i < coin; i++)
            {
                for (int j = numCoin[i]; j < pay + 1; j++)
                {
                    T[j] = Math.Min(T[j], T[j - numCoin[i]] + 1);
                }
            }

            Console.WriteLine(T[pay]);
            //while (true) ;
            //??????
            //Console.WriteLine((b + c) + " " + s);
        }
    }
}

Measured memory_bytes: 5800
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0; i<n; i++)
typedef long long ll;
typedef long long unsigned int llu;
ll MOD = 1000000007;
ll INF = 1000000009;

/*

*/

bool is_prime(const unsigned n){
    switch(n){
        case 0: // fall-through
        case 1: return false;
        case 2: return true;
    } // n > 2 が保証された

    if(n%2 == 0) return false;

    // 上で i=2 相当は調べたので、i=3から奇数のみ調べる
    for(unsigned i=3;i*i<=n;i+=2){
        if(n%i == 0) return false;
    }

    return true;
}


void solve(){

    ll x;
    cin >> x;
    ll ans;
    ll tmp = x;
    while(true){
        if(is_prime(tmp)){
            ans = tmp;
            break;
        }
        else{
            tmp++;
        }
    }
    cout << ans << endl;

}

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


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

ll gcd(ll a, ll b) {
  ll r;
  if (a < b) swap(a, b);

  while (b > 0) {
    r = a % b;
    a = b;
    b = r;
  }
  return a;
}

int main() {
  int n, x;
  cin >> n >> x;
  vector<int> vx(n);
  for (int i = 0; i < n; i++) {
    cin >> vx.at(i);
  }
  vx.push_back(x);

  sort(vx.begin(), vx.end());
  vector<int> vy;
  for (int i = 0; i < vx.size() - 1; i++) {
    vy.push_back(abs(vx.at(i + 1) - vx.at(i)));
  }

  int ans = vy.at(0);
  for (int i = 0; i < vy.size(); i++) {
    ans = gcd(ans, vy.at(i));
  }
  cout << ans << endl;

}


Measured memory_bytes: 1528
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;

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

	if(k <= a) {
		cout << k << endl;
	} else if(k <= a + b) {
		cout << a << endl;
	} else {
		cout << 2 * a + b - k << endl;
	}
}

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

int main(){
    int N; cin >> N;
    vector <int> L(N);
    rep(i,N) cin >> L[i];
    
    sort(L.begin(),L.end());//昇順
    int sum=0;
    rep(i,N-1) sum+=L[i];
    if (L[N-1] < sum) cout << "Yes";
    else cout << "No";
    
}

Measured memory_bytes: 256
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

typedef long double ld;

#ifdef DEBUG
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#else
#define eprintf(...) ;
#endif

#define sz(x) ((int) (x).size())
#define TASK "text"

const int inf = (int) 1.01e9;
const long long infll = (long long) 1.01e18;
const ld eps = 1e-9;
const ld pi = acos((ld) -1);

#ifdef DEBUG
mt19937 mrand(300); 
#else
mt19937 mrand(chrono::steady_clock::now().time_since_epoch().count()); 
#endif

int rnd(int x) {
  return mrand() % x;
}

void precalc() {
}

const int maxn = (int) 1e5 + 5;
int n;
vector<int> g[maxn];

bool read() {
  if (scanf("%d", &n) < 1) {
    return false;
  }
  for (int i = 0; i < n - 1; i++) {
    int k;
    scanf("%d", &k);
    vector<int> vs(k);
    for (int j = 0; j < k; j++) {
      scanf("%d", &vs[j]);
      vs[j]--;
    }
    g[i] = vs;
  }
  return true;
}

int p[maxn];
int q[maxn];
int used[maxn];

bool dfs(int v) {
  used[v] = true;
  for (int i = 0; i < sz(g[v]); i++) {
    int u = g[v][i];
    if (p[u] == -1) {
      p[u] = v;
      q[v] = u;
      return true;
    }
  }
  for (int i = 0; i < sz(g[v]); i++) {
    int u = g[v][i];
    if (!used[p[u]] && dfs(p[u])) {
      p[u] = v;
      q[v] = u;
      return true;
    }
  }
  return false;
}

int match() {
  for (int i = 0; i < n; i++) {
    p[i] = -1;
    q[i] = -1;
  }
  int res = 0;
  while (true) {
    bool found = false;
    for (int i = 0; i < n; i++) {
      used[i] = false;
    }
    for (int i = 0; i < n - 1; i++) {
      if (q[i] == -1 && dfs(i)) {
        found = true;
        res++;
      }
    }
    if (!found) {
      break;
    }
  }
  return res;
}

vector<int> ng[maxn];
vector<int> vs;
pair<int, int> ans[maxn];

void dfs1(int v) {
  used[v] = true;
  for (int i = 0; i < sz(g[v]); i++) {
    int u = g[v][i];
    if (used[u]) {
      continue;
    }
    int id = p[u];
    ans[id] = make_pair(v, u);
    dfs1(u);
  }
}

void solve() {
  if (match() < n - 1) {
    printf("-1\n");
    return;
  }
  for (int i = 0; i < n; i++) {
    ng[i].clear();
  }
  for (int i = 0; i < n - 1; i++) {
    int v = q[i];
    for (int j = 0; j < sz(g[i]); j++) {
      int u = g[i][j];
      if (u != v) {
        ng[u].push_back(v);
      }
    }
  }
  for (int i = 0; i < n; i++) {
    g[i] = ng[i];
    used[i] = false;
  }
  int root = -1;
  for (int i = 0; i < n; i++) {
    if (p[i] == -1) {
      root = i;
      break;
    }
  }
  dfs1(root);
  for (int i = 0; i < n; i++) {
    if (!used[i]) {
      printf("-1\n");
      return;
    }
  }
  for (int i = 0; i < n - 1; i++) {
    printf("%d %d\n", ans[i].first + 1, ans[i].second + 1);
  }
}

int main() {
  precalc();
#ifdef DEBUG
  assert(freopen(TASK ".in", "r", stdin));
  assert(freopen(TASK ".out", "w", stdout));
#endif
  while (read()) {
    solve();
#ifdef DEBUG
    eprintf("Time %.2f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
  }
  return 0;
}


Measured memory_bytes: 18048
//BROWNIE TK

#include <bits/stdc++.h>
typedef long long int lli;
typedef unsigned long long int ulli;
typedef long double ldb;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define pb push_back
#define popb pop_back()
#define pf push_front
#define popf pop_front()
#define si size()
#define be begin()
#define en end()
#define all(v) v.be, v.en
#define le length()
#define mp make_pair
#define mt make_tuple
#define acc(v) accumulate(all(v), 0)
#define F first
#define S second

#define forz(i, n) for (int i = 0; i < n; i++)
#define fore(i, m, n) for (int i = m; i <= n; i++)
#define rforz(i, n) for (int i = n - 1; i >= 0; i--)
#define rforzm(i, m, n) for (int i = n - 1; i >= m; i--)
#define deci(n) fixed << setprecision(n)
#define high(n) __builtin_popcount(n)
#define highll(n) __builtin_popcountll(n)
#define parity(n) __builtin_parity(n)
#define ctz(n) __builtin_ctz(n)
#define lb lower_bound
#define ub upper_bound
#define er equal_range
#define maxe *max_element
#define mine *min_element
#define mod 1000000007
#define mod2 998244353
#define gcd __gcd
#define kira ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)

#define endl "\n"
#define p0(a) cout << a << " "
#define p1(a) cout << a << endl
#define p2(a, b) cout << a << " " << b << endl
#define p3(a, b, c) cout << a << " " << b << " " << c << endl
#define p4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl

#define oset tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define osetlli tree<lli, null_type, less<lli>, rb_tree_tag, tree_order_statistics_node_update>
//member functions :
//1. order_of_key(k) : number of elements strictly lesser than k
//2. find_by_order(k) : k-th element in the set
#define ofk order_of_key
#define fbo find_by_order
using namespace std;

/*STD fucntions*/
lli power(lli x, lli y, lli p)
{
    lli res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % p;
        //y must be even now
        y = y >> 1; //y=y/2
        x = (x * x) % p;
    }
    return res;
}
lli modi(lli a, lli m)
{
    // fermat little thm where m is prime
    return power(a, m - 2, m);
}
/*CODE BEGINS*/
int main()
{
    kira;
    lli n;
    cin>>n;
    string s;
    cin>>s;
    string a="",b="";
    if(n%2)cout<<"No";
    else 
    {
      for(int i=0;i<n/2;i++)
      {
        a+=s[i];
        b+=s[n/2+i];
      }
      if(a==b)cout<<"Yes";
      else cout<<"No";
    }
    return 0;
}

Measured memory_bytes: 256
import math
LI = lambda: list(map(int,input().split()))
MI = lambda: map(int,input().split())
yes = lambda: print("YES")
no = lambda: print("NO")
I = lambda: list(input())
J = lambda x: "".join(x)
II = lambda: int(input())
SI = lambda: input()
#---khan17---template
t = int(input())
print(round(math.pi*t*2,2))

Measured memory_bytes: 9196
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
typedef pair<LL, LL> PL;
typedef pair<P, LL> PP;
typedef pair<P, LL> PP;
typedef long long LL;

#define xx first
#define yy second


int main()
{
  //freopen("input", "r", stdin);
  // freopen("output", "w", stdout);
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  LL n;
  cin>>n;
  set<LL> si;
  LL da[n+1];
  LL pos[n+1];
  for(LL i=0;i<n;i++)
    {cin>>da[i];pos[da[i]]=i;}
  LL ans = 0;
  si.insert(pos[n]);
  for(LL i=n-1;i>0;i--){
    LL p = pos[i];
    auto it = si.lower_bound(p);
    LL x1=0,x2=0,y1=0,y2=0;
    if(it==si.end()){
      x1 = n-p;
    }
    else {
      LL pre = *it;
      x1 = pre - p;
      it++;
      if(it==si.end())
        {x2 = n-pre;}
      else {x2 = *it - pre;}
    }
    it = si.lower_bound(p);
    if(it==si.begin()){
      y1 = p+1;
    }
    else{
    it--;
    if(it==si.begin())
      {y1 = p-*it, y2=*it+1;}
    else{
      LL pre = *it;
      it--;
      y1 = p-pre, y2= pre-*it;
    }
  }
  // cout<<x1<<" "<<x2<<" "<<y1<<" "<<y2<<endl;
  ans += (y1*x2+x1*y2)*i;
  // cout<<ans<<endl;
  si.insert(p);
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 6528
#include <iostream>
using namespace std;
int mp[1010][1010];
int X[1000010];
int Y[1000010];
int F[1000010];
int dx[4]={0, 1, 0, -1};
int dy[4]={1, 0, -1, 0};
int main(){
    int h, w;
    cin>>h>>w;
    for(int y=1;y<=h;y++){
        for(int x=1;x<=w;x++){
            cin>>mp[y][x];
            X[mp[y][x]] = x;
            Y[mp[y][x]] = y;
        }
    }
    int ans = 0;
    for(int i=1;i<=h*w;i++){
        F[i] = i;
        int tmp = 0;
        for(int j=0;j<4;j++){
            int k = mp[Y[i]+dy[j]][X[i]+dx[j]];
            if(k==0 || k > mp[Y[i]][X[i]])continue;
            if(F[k]<0){
                F[i]=-1;
                break;
            }
            if(F[i] == i)F[i] = F[k];
            else if(F[i] != F[k]){
                F[i] = -1;
                break;
            }
        }
        if(F[i]<0)ans++;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 18748
#define _USE_MATH_DEFINES
#include <math.h>
#include <iostream>
#include <iomanip>
#include <cstdlib>

using namespace std;

int main() {

    int N,Y;
    cin >> N >> Y;
    int A = -1;
    int B = -1;
    int C = -1;
    for(int i=0;i<=N;i++){
        for(int j=0;j<=N;j++){
            if(i*10000 + j*5000 + (N-i-j)*1000 == Y && N-i-j >= 0){
                A = i;
                B = j;
                C = N-i-j;
                break;
            }
        }
    }
    cout << A << " " << B << " " << C << endl;
    return 0;
}


Measured memory_bytes: 256
import static java.util.Arrays.deepToString;

import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		new Main().run();
	}
	void tr(Object... os) {
		System.err.println(deepToString(os));
	}

	Scanner sc = new Scanner(System.in);
	public void run() {
		int t = sc.nextInt();
		for (int i = 0; i < t; i++) {
			if (i > 0) System.out.println();
			solve(sc.nextInt());
		}
	}
	
	void solve(int n) {
		char[][] t = new char[n][n];
		for (int i = 0; i < n; i++) Arrays.fill(t[i], ' ');
		
		int[] dr = {-1, 0, 1, 0};
		int[] dc = {0, 1, 0, -1};
		
		int r = n - 1;
		int c = 0;
		
		t[r][c] = '#';
		int d = 0;
		int miss = 0;
		for (; miss < 4;) {
			int nr = r + dr[d];
			int nc = c + dc[d];
			int nnr = r + 2 * dr[d];
			int nnc = c + 2 * dc[d];
			if (isin(nr, nc, n) &&
				t[nr][nc] != '#' && 
				(!isin(nnr, nnc, n) || t[nnr][nnc] != '#') &&
				t[nr + dr[(d+1)&3]][nc+dc[(d+1)&3]] != '#' ) {
				r = nr;
				c = nc;
				t[r][c] = '#';
				miss = 0;
			} else {
				d = (d + 1) & 3;
				miss++;
			}
		}
		for (int i = 0; i < n; i++) {
			System.out.println(new String(t[i]));
		}
		
	}
	boolean isin(int r, int c, int n) {
		return 0 <= r && r < n && 0 <= c && c < n;
	}
}

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

int main(){
  ll a,b,c,d,ac,ad,bc,bd;
  cin >>a>>b>>c>>d;
  ac = a*c;
  ad = a*d;
  bc = b*c;
  bd = b*d;
  vector<ll> s(3);
  s = {ac,ad,bc,bd};
  sort(s.begin(),s.end());
  cout << s.at(3) << endl;
}

Measured memory_bytes: 3632