akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<set>
#include<queue>
#include<ctime>
#include<vector>
using namespace std;
inline int rd(){
  register char ch=getchar();
  register bool flag=false;
  register int res=0;
  while(ch<'0'||ch>'9'){flag=(ch=='-');ch=getchar();}
  while(ch>='0'&&ch<='9'){
    res=(res<<3)+(res<<1)+ch-'0';ch=getchar();}
  if(flag)res=-res;
  return res;
}
#define N 310
int f[N][N],g[N][N];
vector<pair<int,int> >nd[N];
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define mod 1000000007
int n,m;
inline void upd(int &x,int y){
  x+=y;if(x>=mod)x-=mod;
}
void work(){
  n=rd();m=rd();
  int i,j,u,v,x;
  for(i=1;i<=m;i++){u=rd();v=rd();x=rd();nd[v].pb(mp(u,x));}
  f[0][0]=3;
  for(i=1;i<n;i++){
    for(j=0;j<=i;j++)
      for(u=0;u<=j;u++)g[j][u]=0;
    for(j=0;j<i;j++)
      for(u=0;u<=j;u++)if(f[j][u]){
	  x=0;//printf("pf[%d][%d][%d]=%d\n",i,j,u,f[j][u]);   
          for(v=0;v<nd[i].size();v++)
	    {x=0;
            if(i>=nd[i][v].fi)x++;
	      if(j>=nd[i][v].fi)x++;
              if(u>=nd[i][v].fi)x++;//printf("[%d %d %d %d]\n",i,j,u,x);
	      if(x!=nd[i][v].se)break;
            }
	  if(v<nd[i].size())continue;//no way
          //can chance
	  //printf("f[%d][%d][%d]=%d\n",i,j,u,f[j][u]);      
    upd(g[j][u],f[j][u]);//i++
          upd(g[i][u],f[j][u]);
          upd(g[i][j],f[j][u]);//u=0,v=0,代表两种颜色	
    }
    for(j=0;j<=i;j++)
      for(u=0;u<=j;u++)f[j][u]=g[j][u];
  }
  int res=0;
  for(j=0;j<i;j++)
      for(u=0;u<=j;u++)if(f[j][u]){
	  x=0;
          for(v=0;v<nd[i].size();v++)
	    {x=0;if(i>=nd[i][v].fi)x++;
	      if(j>=nd[i][v].fi)x++;
              if(u>=nd[i][v].fi)x++;
	      if(x!=nd[i][v].se)break;
            }
	  if(v<nd[i].size())continue;//no way
          //can chance
	  upd(res,f[j][u]);	
    }
  printf("%d\n",res);
}
int main(){
  work();
  return 0;
}


Measured memory_bytes: 1024
class UnionFind():
    def __init__(self,size):
        self.table = [-1 for _  in range(size)]

    def find(self,x):
        while self.table[x] >= 0:
            x = self.table[x]
        return x

    def union(self,x,y):
        s1 = self.find(x)
        s2 = self.find(y)
        if s1 != s2:
            if self.table[s1] != self.table[s2]:
                if self.table[s1] < self.table[s2]:
                    self.table[s2] = s1
                else:
                    self.table[s1] = s2
            else:
                self.table[s1] += -1
                self.table[s2] = s1
        return

n,m = map(int,raw_input().split())

edges = [map(int,raw_input().split()) for i in range(m)]

ans = 0

for i in range(m):
	uf = UnionFind(n)
	for j in range(m):
		if i != j:
			uf.union(edges[j][0]-1,edges[j][1]-1)

	c = 0
	for j in range(n):
		if j == uf.find(j):
			c += 1

	if c > 1 :
		ans += 1

print ans


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

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

    set<string> st;
    int N = S.length(), M = T.length();
    for (int i = 0; i + M - 1 < N; i++) {
        bool ok = true;
        for (int j = 0; j < M; j++) {
            if (S[i + j] != T[j] && S[i + j] != '?') {
                ok = false;
                break;
            }
        }

        if (ok) {
            string temp = S;
            for (int j = 0; j < M; j++) {
                temp[i + j] = T[j];
            }
            for (int j = 0; j < N; j++) {
                if (temp[j] == '?') {
                    temp[j] = 'a';
                }
            }
            st.insert(temp);
        }
    }
    if (st.empty()) {
        cout << "UNRESTORABLE" << endl;
    } else {
        cout << *st.begin() << endl;
    }
}


Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return list(map(int, sys.stdin.readline().split()))
def II(): return int(sys.stdin.readline())
def LS(): return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]

def main():
    n = II()
    hs = LI()
    anss = [0 for i in range(n)]
    max_ = 0
    for i in range(n - 1):
        if hs[n - i - 1] <= hs[n - i - 2]:
            anss[n - i - 2] = anss[n - i - 1] + 1
            if anss[n - i - 2] > max_:
                max_ = anss[n - i - 2]

    print(max_)



if __name__ == '__main__':
    main()

Measured memory_bytes: 14388
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>

using namespace std;

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

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

struct Edge
{
	int src, dst;
	int weight;
	Edge(int src, int dst, int weight) : src(src), dst(dst), weight(weight) {}

	bool operator< (const Edge& e)const
	{
		return weight != e.weight ? weight > e.weight :
			src != e.src ? src < e.src : dst < e.dst;
	}
};

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

struct UnionFind
{
	vi data;

	UnionFind(int size) : data(size, -1) {}

	// xツづツづ個集ツ債づーツ閉ケツ債つキツづゥ
	bool unionSet(int x, int y)
	{
		x = root(x);
		y = root(y);
		if(x != y){
			if(data[y] < data[x])
				swap(x, y);
			data[x] += data[y];
			data[y] = x;
		}
		return x != y;
	}

	// xツづツづ個集ツ債つェツ督卍つオツつ「ツつゥツ偲ヲツ督セツつキツづゥ
	bool findSet(int x, int y)
	{
		return root(x) == root(y);
	}

	int root(int x)
	{
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x)
	{
		return -data[root(x)];
	}
};

pair<int, Edges> Kruskal(const Graph& g)
{
	int n = g.size();
	UnionFind uf(n);
	priority_queue<Edge> Q;

	rep(i, n) rep(j, g[i].size())
		if(i < g[i][j].dst)
			Q.push(g[i][j]);

	int total = 0;
	Edges F;
	while(F.size() < n-1 && !Q.empty()){
		Edge e = Q.top();
		Q.pop();
		if(uf.unionSet(e.src, e.dst)){
			F.push_back(e);
			total += e.weight;
		}
	}
	return pair<int, Edges>(total, F);
}

int main()
{
	int n, m;
	while(scanf("%d%d", &n, &m), n){
		Graph g(n);
		rep(i, m){
			int a, b, cost;
			scanf("%d%d%d", &a, &b, &cost);
			g[a].push_back(Edge(a, b, cost));
			g[b].push_back(Edge(b, a, cost));
		}

		pair<int, Edges> result = Kruskal(g);
		printf("%d\n", result.first);
	}
	return 0;
}

Measured memory_bytes: 0
//b_1_percent
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long x = sc.nextLong();
		long yen_at_bank = 100;
		int year = 0;
		
		
		while(true) {
			year++;
			yen_at_bank = yen_at_bank + yen_at_bank / 100;
			if(yen_at_bank >= x) {
				System.out.println(year);
				return;
			}
		}
	}
}

Measured memory_bytes: 35764
#include<iostream>
#include<algorithm>
 
using namespace std;
 
int main(){
int A[3];
 
cin >> A[0] >> A[1] >> A[2];
 
sort(A,A+3);
 
cout << A[0]  << " "<< A[1] << " " <<A[2] << endl;
 
}

Measured memory_bytes: 3100
from __future__ import print_function

import sys
sys.setrecursionlimit(500000)

import re
import array
import copy
import functools
import operator

import math
import string
import fractions
from fractions import Fraction

import collections
import itertools
import bisect

import random
import time

import heapq
from heapq import heappush
from heapq import heappop
from heapq import heappushpop
from heapq import heapify
from heapq import heapreplace
from queue import PriorityQueue as pq
from queue import Queue

from itertools import accumulate

from collections import deque
from collections import Counter

from operator import mul
from functools import reduce

input = sys.stdin.readline


def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)
    return

# from fractions import gcd
# from math import gcd

# def lcm(n, m):
#     return int(n * m / gcd(n, m))


# def coprimize(p, q):
#     common = gcd(p, q)
#     return (p // common, q // common)


# def find_gcd(list_l):
#     x = reduce(gcd, list_l)
#     return x


def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom


mod=1000000007
def combinations_count_mod(n, r):
    r = min(r, n - r)
    numer = reduce(lambda x,y: x*y%mod, range(n, n - r, -1), 1)
    denom = pow( reduce(lambda x,y: x*y%mod, range(1, r + 1), 1) , mod-2, mod)
    return numer * denom % mod


def solve():
    pass

def main():
    x = int(input().strip())
    if x==0:
        print(1)
    else:
        print(0)


if __name__ == '__main__':
    main()

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

priority_queue<int> q1;
priority_queue<int,vector<int>,greater<int>> q2;
int sum1,sum2;

signed main(){

  int q; cin >> q;
  int B = 0;
  for(int i = 0; i < q; i++){
    int num; cin >> num;
    if(num == 1){
      int a,b; cin >> a >> b;
      q1.push(a);
      sum1 += a;
      B += b;
      if(q1.size() > q2.size()+1){
        int p = q1.top(); q1.pop();
        sum1 -= p;
        q2.push(p);
        sum2 += p;
      }
      if(!q2.empty() && q1.top() > q2.top()){
        int tmp1 = q1.top(); q1.pop();
        int tmp2 = q2.top(); q2.pop();
        q1.push(tmp2);
        q2.push(tmp1);
        sum1 += -tmp1 + tmp2;
        sum2 += tmp1 - tmp2;
      }
    }
    else {
      int x = q1.top();
      int res = (int)q1.size() * x - sum1 + sum2 - (int)q2.size() * x;
      cout << x << " " << res + B << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 3828
#include<bits/stdc++.h>
using namespace std;
 int main(){
	 string s;
	 cin >>s;
	 if (s.at(2) == s.at(3) && s.at(4)==s.at(5)){
		 cout<<"Yes"<<endl;
	 }
	 else{
		 cout<<"No"<<endl;
	 }
 }


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <cstdint>
#include <cctype>
#include <numeric>
#include <bitset>
#include <functional>

using namespace std;

using ll =  long long;
using Pll = pair<ll, ll>;
using Pii = pair<int, int>;

constexpr int INF = 1 << 30;
constexpr ll LINF = 1LL << 60;
constexpr ll MOD = 1000000007;
constexpr double EPS = 1e-10;
constexpr int dyx[4][2] = {
    { 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    ll s;
    cin >> s;
    ll a = ll(sqrt(double(s)+EPS));
    if(a*a == s) {
        cout << "0 0 " << a << " 0 0 " << a << endl;
        return 0;
    } else {
        ++a;
    }
    ll b = a*a-s;
    cerr << a << " " << b << endl;
    for(ll i=1;i<=sqrt(b)+1;++i) {
        if(b % i == 0 && max(b/i, i) <= 1'000'000'000) {
            cout << "0 0 " << a << " " << i << " " << b/i << " " << a << endl;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <set>
#include <map>
#include <unordered_map>

using namespace std;

int n, len, digits[10];

int main()
{
	cin >> n;

	int tmp = n;
	while (tmp > 0){
		len++;
		digits[len] = tmp%10;
		tmp /= 10;
	}

	int d = digits[len], res = 0;
	for (int i = 0; i < 3; ++i)
		res = 10*res + d;

	if (res < n)
		res += 111;
	
	cout << res << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
//#include <iomanip>
//#include <string>
#include <vector>
#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
using vll = vector<ll> ;
//using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
using vb = vector<bool> ;
using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;
#define all(v) v.begin(),v.end()
//ll mod = 1000000007 ;
//long double pie = acos(-1) ;
//ll INF = 1000000000000 ;

//void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b%mod ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void mysort(vector<long long> &a){sort(a.begin(),a.end()) ;}
//void myrev(vector<long long> &a){reverse(a.begin(),a.end()) ;}
//void fix_cout(){cout << fixed << setprecision(20) ;}

int main(){
	ll n ; cin >> n ;
	vll x(n),y(n) ;
	for(int i=0;i<n;i++) cin >> x.at(i) >> y.at(i) ;
	vll v(8) ;
	for(int i=0;i<8;i++) v.at(i) = i ;
	do{
		bool ok = true;
		for(int i=0;i<n;i++) if(v.at(x.at(i))!=y.at(i)) ok = false ;
		vvb check(8,vb(8,true)) ;
		for(int i=0;i<8;i++){
			if(!ok) break ;
			ll d = v.at(i) ;
			for(int j=0;j<8;j++){
				for(int k=0;k<8;k++){
					if(j-d==k-i||j-d==i-k){
						if(v.at(k)==j&&k!=i){
							ok = false ;
							break ;
						}else{
							check.at(k).at(j) = false ;
						}
					}
				}
				if(!ok) break ;
			}
			if(!ok) break ;
		}
		if(ok){
			for(int i=0;i<8;i++){
				for(int j=0;j<8;j++){
					cout << (j==v.at(i)?'Q':'.') ;
				}
				cout << endl ;
			}
			return 0 ;
		}
	}while(next_permutation(all(v))) ;
	cout << -1 << endl ;
}



Measured memory_bytes: 3092
def a_two_abbreviations(N, M, S, T):
    from fractions import gcd

    def lcm(a, b):
        return a * b // gcd(a, b)

    # LはLCM(N,M)の倍数でなければならない
    # (1): jL/N=kL/M を満たすすべての非負整数(j,k)の組についてS[j]==T[k]か
    # 調べるので、Lを整数倍したところで(j,k)の組は変わらない。よってL=lcm(N,M)
    L = lcm(N, M)

    # ab = gcd(a,b)*lcm(a,b) の関係から、下のようにn, mを定義すれば、
    # jm = kn を満たすすべての(j,k)の組についてS[j]==T[k]であればいい。
    # (1)式だと分母が異なるが、この変換を行うと、分母が等しくなるし、
    # M=Gm, N=Gnであり、M, Nの共通する素因数はGが「引き受ける」ため、
    # m, nは互いに素になって扱いやすい
    G = gcd(N, M)
    n, m = N // G, M // G

    ans = L
    # M=gm, N=gnとなるため、pが下の範囲の場合について調べる
    for p in range(gcd(N, M)):
        a, b = p * n, p * m
        if S[a] != T[b]:
            ans = -1
            break

    return ans

N, M = [int(i) for i in input().split()]
S = input()
T = input()
print(a_two_abbreviations(N, M, S, T))

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

// macro
#define rep(i,n) for(i=0;i<n;i++)
#define ll long long
#define all(v) v.begin(), v.end()

// code starts
int main()
{
	int n,m;cin>>n>>m;
	vector<vector<int>> s(m);
	int i,j,l;
	rep(i,m)
	{
		int k;cin>>k;
		rep(j,k)
		{
			int si;cin>>si;
			s[i].emplace_back(si);
		}
	}
	vector<int> p(m);
	rep(i,m)cin>>p[i];
	int ans=0;
	for(i=0;i<(1<<n);i++)
	{
		vector<bool> on(n,false);
		rep(j,n)if(i&(1<<j))on[j]=true;
		int ons=0;
		rep(j,m)
		{
			int count=0;
			rep(l,s[j].size())
			{
				if(on[s[j][l]-1])count++;
			}
			if(count%2==p[j])ons++;
		}
		if(ons==m)ans++;
	}
	cout<<ans<<endl;
}


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

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

#define IOS             ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define read            freopen("in.txt","r",stdin)
#define write           freopen("out.txt","w",stdout)
#define loop(i,a,b)     for (ll i = a; i <= b; i++)
#define rloop(i,a,b)    for (ll i = a; i >= b; i--)
#define ms(a,x)         memset(a,x,sizeof a)
#define ll              long long int
#define ff              first
#define ss              second
#define all(a)          a.begin(),a.end()
#define rall(a)         a.rbegin(),a.rend()
#define pb              push_back
#define nl              cout<<"\n"
#define gcd(a,b)        __gcd((a),(b))
#define lcm(a,b)        ((a)*(b))/(gcd(a,b))
#define sq(a)           (a)*(a)
#define sz(a)           a.size()
#define mod             1000000007
#define PI              (2*acos(0.0))


int main()
{
    IOS
    int T=1;
    //cin>>T;
    cout<<fixed<<setprecision(10);
    while(T--)
    {
        double a,b,x;
        cin>>a>>b>>x;
        if((a*a*b)/2==x)
        {
            cout<<"45.0000000000";
            continue;
        }
        if((a*a*b)/2<x)
        {
            double h=x/(sq(a));
            double hh=(b-h)*2.0;
            double kon=atan(a/hh);
            cout<<90-((180*kon)/PI);
        }
        else
        {
            double h=x/(sq(a));
            double hh=(b-h)*2.0;
            double k=(hh-b);
            a=((a*h*2)/b);
            double kon=atan(a/b);
            //debug(a,b,hh,h);
            cout<<90-((180*kon)/PI);

        }

    }
    return 0;
}


Measured memory_bytes: 4120
from enum import Enum, auto

class Color(Enum):
    WHITE = auto() # 未訪問の頂点
    GRAY = auto() # 訪問済みだが, 全ての接点の調査は済んでいない状態の接点
    BLACK = auto() # 訪問, 調査済みの接点

n = int(input())
d = [0 for i in range(n)]
f = [0 for i in range(n)]

colors = [] # 頂点の訪問状態
A = [[0 for j in range(n)] for i in range(n)] # 隣接行列
# stack = [] ## スタックによる実装では頂点の保持が必要 => 再帰によって実装

# 隣接行列の初期化
for i in range(n):
    arr = list(map(int, input().split(' ')))
    u, k, v = arr[0], arr[1], arr[2:]
    for j in range(k):
        A[u-1][v[j]-1] = 1

time = 0
def dfs_init():
    global colors
    colors = [Color.WHITE for i in range(n)]
    dfs(0)

def dfs(u):
    global time
    colors[u] = Color.GRAY
    time += 1
    d[u] = time
    for v in range(n):
        if A[u][v] == 1 and colors[v] == Color.WHITE:
            dfs(v)
    colors[u] = Color.BLACK
    time += 1
    f[u] = time

dfs_init()
for u in range(n):
    if colors[u] == Color.WHITE:
        dfs(u)

# 出力
for i in range(n):
    print(i+1, d[i], f[i])



Measured memory_bytes: 6488
#include <bits/stdc++.h>
using namespace std;
typedef long long i64;
const int MAX = 1e6 + 10;
const int MOD = 1e9 + 7;
const int oo = 1e9;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	#define endl '\n'
	int n; cin >> n;
	n = n % 10;
	if(n == 2 or n == 4 or n == 7 or n == 5 or n == 9)cout << "hon" << endl;
	if(n == 0 or n == 1 or n == 6 or n == 8)cout << "pon" << endl;
	if(n == 3)cout << "bon" << endl;
}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
#define pii pair<int,int>
#define pli pair<ll,int>
#define pil pair<int,ll>
#define pll pair<ll,ll>
#define mat vector<vector<int>>
const int inf = 1 << 30;
const ll linf = 1e18;
const db EPS = 1e-7;
template<class T> void chmin(T& x, T y){if(x > y) x = y;}
template<class T> void chmax(T& x, T y){if(x < y) x = y;}

struct dat{
    int x, y, val;
};

int N;
int A[6010];
int dp[2010][2010];

void init(){
    for(int i = 0; i <= N + 1; i++){
        for(int j = 0; j <= N + 1; j++){
            dp[i][j] = -inf;
        }
    }
    dp[max(A[1], A[2])][min(A[1], A[2])] = 0;
    dp[max(A[1], A[2])][N + 1] = 0;
    dp[min(A[1], A[2])][N + 1] = 0;
    dp[N + 1][N + 1] = 0;
}

void solve(){

    int cor = 0;
    for(int i = 1; i < N; i++){
        int idx = i * 3;

        queue<dat> q;
        //0つ一致
        for(int j = 0; j <= 2; j++){
            int to = idx + j;
            int val1 = A[idx + (j + 1) % 3];
            int val2 = A[idx + (j + 2) % 3];
            //二つ交換
            if(dp[max(val1, val2)][min(val1, val2)] < dp[N + 1][N + 1]){
                q.push(dat{max(val1, val2), min(val1, val2), dp[N + 1][N + 1]});
            }
            //一つ交換
            for(int k = 1; k <= N; k++){
                if(dp[max(k, A[to])][min(k, A[to])] < dp[k][N + 1]){
                    q.push(dat{max(k, A[to]), min(k, A[to]), dp[k][N + 1]});
                }
            }
        }

        //一つ一致
        for(int j = 0; j <= 2; j++){
            int to = idx + j;
            int val1 = A[idx + (j + 1) % 3];
            int val2 = A[idx + (j + 2) % 3];
            if(dp[max(val1, val2)][min(val1, val2)] < dp[A[to]][A[to]] + 1){
                q.push(dat{max(val1, val2), min(val1, val2), dp[A[to]][A[to]] + 1});
            }
        }

        //二つ一致
        for(int j = 0; j <= 2; j++){
            int to = idx + j;
            int val1 = A[idx + (j + 1) % 3];
            int val2 = A[idx + (j + 2) % 3];
            if(val1 != val2) continue;
            for(int k = 1; k <= N; k++){
                if(dp[max(A[to], k)][min(A[to], k)] < dp[max(val1, k)][min(val1, k)] + 1){
                    q.push(dat{max(A[to], k), min(A[to], k), dp[max(val1, k)][min(val1, k)] + 1});
                }
            }
        }

        int z = 0;
        //三つ一致
        if(A[idx] == A[idx + 1] && A[idx + 1] == A[idx + 2]) z++, cor++;

        //更新
        while(!q.empty()){
            dat d = q.front();
            q.pop();

            chmax(dp[d.x][d.y], d.val - z);
            chmax(dp[d.x][N + 1], d.val - z);
            chmax(dp[d.y][N + 1], d.val - z);
            chmax(dp[N + 1][N + 1], d.val - z);
        }
    }

    dp[A[3 * N]][A[3 * N]]++;

    int ans = 0;
    for(int i = 1; i <= N + 1; i++){
        for(int j = 1; j <= N + 1; j++){
            chmax(ans, dp[i][j]);
        }
    }
    ans += cor;
    cout << ans << endl;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> N;
    for(int i = 1; i <= 3 * N; i++){
        cin >> A[i];
    }

    init();

    solve();

    return 0;
}

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

int main() {
  string b;
  cin >> b;
  if(b == "A"){
    cout << "T" << endl;
  }else if(b == "T"){
    cout << "A" << endl;
  }else if(b == "G"){
    cout << "C" << endl;
  }else if(b == "C"){
    cout << "G" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
#include <cassert>
//#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
const long long MOD = 1e9+7;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ld, ll> pdl;
typedef pair<ld, ld> pdd;
//typedef boost::multiprecision::cpp_int bigint;

ll A, B, C, D;

int main() {
	cin >> A >> B >> C >> D;
	cout << min(A, B) + min(C, D) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <string>
#include <set>
#include <bitset>
#include <unordered_map>

using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
template <class T>
using Vvec = vector<vector<T> >;

int main()
{
    int N;
    cin >> N;
    cout << (N-1)/2 << endl;
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var strS string
	fmt.Scan(&strS)

	var res = abc081A(strS)
	fmt.Println(res)
}

func abc081A(strS string) int {
	var res int
	for i := 0; i < len(strS); i++ {
		if string([]rune(strS)[i:i+1]) == "1" {
			res++
		}
	}
	return res
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n,minn=0x7fffffff,i,maxx=0,m;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d",&m);
		maxx=max(maxx,m);
		minn=min(minn,m);
	}
	printf("%d",maxx-minn);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>  
#include <functional>
#define ll long long int
#define ld long double
#define pb push_back
#define pll pair<ll,ll>
#define pint pair<int,int>
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define mod 1000000007
#define MAX 1000000000100001
#define endl '\n'
#define mp make_pair
#define INF INT_MAX
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define ff first
#define ss second
#define ps(x,y) fixed<<setprecision(y)<<x
#define setbits(x) __builtin_popcountll(x)			//counts no of ones in binary representation
#define w(t) 	int t; cin>>t; while(t--)
#define pi 3.141592653589793238
#define sortt(v)  sort(v.begin(),v.end())
#define lb(v,x) std::lower_bound(v.begin(),v.end(),x)
#define ub(v,x) std::upper_bound(v.begin(),v.end(),x)

using namespace std;

int main(){
	fast;
	ll n;
	cin>>n;
	vector<ll> v;
	v.pb(0);
	v.pb(26);
	ll p=2;
	for(ll i=2;;i++){
		ll x=v[i-1];
		if(x>=MAX)	break;
		x+=pow(26,p);
		v.pb(x);
		p++;
	}
//	forn(i,v.size())	cout<<v[i]<<' ';
	vector<ll>::iterator it1,it2;
	it1=lb(v,n);
	it2=ub(v,n);
	if(it1!=it2){
		ll pos=it1-v.begin();
		forn(i,pos)		cout<<'z';
		return 0;
	}
	string ans="";
	while(n){
		n--;
		ll temp=n%26;
		ans+=(temp+'a');
		n/=26;
	}
	reverse(ans.begin(),ans.end());
	cout<<ans;
}

Measured memory_bytes: 4060
#include <bits/stdc++.h>
#define debug(x) cerr << #x << ": " << x << endl
#define debugArray(x, n)                           \
  for (long long hoge = 0; (hoge) < (n); ++(hoge)) \
  cerr << #x << "[" << hoge << "]: " << x[hoge] << endl
using namespace std;

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, K;
  cin >> N >> K;
  int P[N];
  for (int i = 0; i < N; i++) {
    cin >> P[i];
    P[i]--;
  }
  long long C[N];
  for (int i = 0; i < N; i++) cin >> C[i];
  const long long INF = 1ll << 33;
  long long ans = -INF;
  for (int i = 0; i < N; i++) {
    int M = K;
    long long sum_max = -INF;
    long long po[N];
    long long cyc_sum;
    int cyc_cnt = -1;
    int cnt[N];
    fill(po, po + N, -1);
    fill(cnt, cnt + N, 0);
    int cur = i;
    int next = P[i];
    po[i] = 0;
    cnt[i] = 1;
    for (; M; cur = next) {
      next = P[cur];
      if (cnt[next] > 0) {
        cyc_sum = po[cur] + C[next] - po[next];
        cyc_cnt = cnt[cur] + 1 - cnt[next];
        break;
      }
      po[next] = po[cur] + C[next];
      cnt[next] = cnt[cur] + 1;
      sum_max = max(sum_max, po[next]);
      M--;
    }
    if (M == 0) {
      ans = max(ans, sum_max);
      continue;
    }
    M--;
    int now = P[cur];
    long long a = po[cur] + C[now];
    if (cyc_sum > 0) {
      int b = M / cyc_cnt;
      b = max(0, b - 1);
      a += b * cyc_sum;
      sum_max = max(sum_max, a);
      M -= b * cyc_cnt;
      for (cur = now; M--; cur = P[cur]) {
        a += C[P[cur]];
        sum_max = max(sum_max, a);
      }
    } else {
      for (cur = now; M-- && P[cur] != now; cur = P[cur]) {
        a += C[P[cur]];
        sum_max = max(sum_max, a);
      }
    }
    ans = max(ans, sum_max);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3748
import java.util.*;

class Main {
   public static void main(String[] args)
   {
      Scanner scan = new Scanner(System.in);
      int     N    = Integer.parseInt(scan.next(), 2);

      switch(N){
          case 1:
          case 2:
          case 4:
             System.out.println("1");
             break;

          case 3:
          case 5:
          case 6:
             System.out.println("2");
             break;

          case 7:
             System.out.println("3");
             break;

          case 0:
             System.out.println("0");
             break;
             }
   }
}

Measured memory_bytes: 21460
import numpy as np

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

vals, cnts = np.unique(A, return_counts=True)

if len(vals) == 1:
    print(0 if cnts[0] > 1 else 1)
elif vals[0] == 1:
    print(0 if cnts[0] > 1 else 1)
else:
    sat = np.ones(vals.max() + 1, dtype=int)
    for x in vals:
        sat[2 * x::x] = 0
    ans = ((sat[vals] == 1) & (cnts == 1)).sum().item()
    print(ans)

# 5
# 2 2 2 3 3
# 5
# 2 2 2 4 4
# 5
# 1 1 1 1 2

Measured memory_bytes: 51216
N = $stdin.gets.to_i
    A = $stdin.gets.split.map(&:to_i)
    D = A.inject(:+) - N*(N+1)/2
    M = 1000000007
     
    $fact = [1]
    (1..N).each{ |n|  $fact << ($fact[-1] * n % M) }
     
    $finv = []
    $fact.each{ |b|
      r = 1  
      pow = M-2
      while pow > 0
        if pow%2 == 1
          r = (r*b) % M
        end
        b = (b*b) % M
        pow /= 2
      end
      $finv << r
    }
     
    def c(n,k)
      return 0 if n < 0
      return 0 if n-k < 0
      return 0 if k < 0
      $fact[n] % M * $finv[n-k] % M * $finv[k] % M
    end
     
    m = A.rindex(D) - A.index(D) - 1
     
    (1..N+1).each{ |k|
      d0 = c(N-1,k)
      d1 = (c(N-1,k-1)*2 - c(N-m-1,k-1) + M) % M
      d2 = c(N-1,k-2)
      #$stderr.puts "#{d0} #{d1} #{d2}"
      puts (d0 + d1 + d2) % M
    }

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

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    map<int,int>mp;
    cin>>n;
    int cnt =0;
    for(int i = 0; i < n ;i++){
        int t;
        cin>>t;
        mp[t]++;
        if(mp[t]>1) cnt++;
    }
    if(cnt>0)
        cout<<"NO\n";
    else
        cout<<"YES\n";
}



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

int main() {
    int N,M; cin >> N >> M;
    if(N>M){
        if((N-M)%2==1)
        cout << "IMPOSSIBLE" << endl;
        else{
            cout << M+(N-M)/2 << endl;
        }
    }
    else{
        if((M-N)%2==1)
        cout << "IMPOSSIBLE" << endl;
        else{
            cout << N+(M-N)/2 << endl;
        }
    }
    

    return 0;
}

Measured memory_bytes: 256
def func(X):
  max_X = int(X / 100)+1
  #print(max_X)
  #min_X = int(X / 105)
  #print(min_X)
  #print(max_X)
  for x1 in range(max_X+1):
    for x2 in range(max_X+1):
      if x1 + x2 > max_X: break
      for x3 in range(max_X+1):
        if x1 + x2 + x3 > max_X: break
        for x4 in range(max_X+1):
          if x1 + x2 + x3 + x4 > max_X: break
          for x5 in range(max_X+1):
            if x1 + x2 + x3 + x4 + x5 > max_X: break
            for x6 in range(max_X+1):
              #print(x1,x2,x3,x4,x5,x6)
              if x1*100 + x2*101 + x3*102 + x4*103 + x5*104 + x6*105 == X:
                print("1")
                return
  print("0")

X = int(input())
func(X)

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt() - 1;
        }
        int x = 0;
        int c = 0;
        for (int i = 0; i < n; i++) {
            c++;
            x = a[x];
            if (x == 1) {
                System.out.println(c);
                return;
            }
        }
        System.out.println("-1");
    }
}

Measured memory_bytes: 59260
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long int N, M;
  cin >> N >> M;
  string S, T;
  cin >> S >> T;
  long long int a=N, b=M;
  long long int x = N*M;
  if(a<b){
    swap(a,b);
  }
  long long int r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
  long long int gcd = b;
  long long int lcm = x/b;
  
  for(int i=0; i<gcd; i++){
    if(S.at(N/gcd*i) != T.at(M/gcd*i)){
      cout << -1 << endl;
      return 0;
    }
  }
  cout << lcm << endl;
}

Measured memory_bytes: 512
n = int(input())
num = list(map(int,input().split()))
a = 0
b = 0
for i in range(n):
    for j in range(n):
        a = a + num[i] * num[j]

for i in range(n):
    b = b + num[i] * num[i]

print((a - b) // 2)


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

using namespace std;
typedef long long ll;
#define MOD 1000000007
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

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

    ll P[N+1], I[N+1];
    for(int i=1; i<N+1; i++) {
        cin >> P[i];
        I[P[i]] = i;
    }

    multiset<ll> S{0, 0, N+1, N+1};

    ll ans = 0;

    for(int i=N; i>0; i--) {
        ll idx = I[i];

        auto itr = S.lower_bound(idx);
        itr--;
        ll b = *(itr);
        itr--;
        ll a = *(itr);
        itr = S.upper_bound(idx);
        ll c = *(itr);
        itr++;
        ll d = *(itr);

        ans += ((b - a) * (c - idx) + (idx - b) * (d - c)) * i;
        S.insert(idx);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 6528
long a,v,c;f(char*x,char*y){c=*y-*x;}main(){for(;read(0,&c,1)|v;c=v&66&&!printf(a==0x414144494e4e5559?v=0,"AIZUNYAN":"%c",v))v=a=v>>8|c<<56,qsort(&a,8,1,f);}

Measured memory_bytes: 524
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def S(): return input().rstrip()
def LS(): return S().split()
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float("INF")

#solve
def solve():
    n = II()
    a = LI()
    suma = 0
    for ai in a:
        suma += ai
        suma %= mod
    ans = 0
    for ai in a:
        tmp = suma
        tmp -= ai
        tmp %= mod
        ans += tmp * ai
        ans %= mod
    print(ans * pow(2, mod-2,mod) % mod)
    return


#main
if __name__ == '__main__':
    solve()


Measured memory_bytes: 110928
// JavaProgram.cpp
// Author : Priydarshi Singh (@dryairship)
// One cat just leads to another. One bug leads to two others.

#include <bits/stdc++.h>
using namespace std;

// I like my types defined.
typedef long long           ll;
typedef pair<int, int>      pii;
typedef pair<ll, ll>        pll;
typedef vector<int>         vi;
typedef vector<ll>          vl;
typedef vector<pii>         vii;
typedef vector<pll>         vll;
typedef set<int>            si;
typedef map<string, int>    msi;
typedef map<int, int>       mii;

// Traditional science is all about finding "hashtag define"s.
#define fr(i, n)            for(int i=0; i<(n); ++i)
#define frC(i, n, c)        for(int i=0; (i<(n)) && (c); ++i)
#define frA(i, a, n)        for(int i=a; i<=(n); ++i)
#define frD(i, a, n)        for(int i=a; i>=(n); --i)
#define fill(a)             memset(a, 0, sizeof(a))
#define fill1(a)            memset(a, -1, sizeof(a))
#define revsort(a, b)       sort(a, b, greater<int>())
#define ff                  first
#define ss                  second
#define pb                  push_back 
#define dout                if(DEBUGGING) cout
#define dbg                 if(DEBUGGING) 
#define endl                "\n"

// When you realize MOD > INF...
int DEBUGGING    =          0;
const int INF    =          1000000000;
const int MOD    =          1000000007;
const ll LINF    =          1e18;
const double PI  =          3.1415926535897932;
const double EPS =          1e-7;

// I'D SPAM. Hehe.
ll gcdEx                    (ll a, ll b, ll *x, ll *y){if(!a){*x=0;*y=1;return b;} 
ll x1,y1,gcd=gcdEx          (b%a,a,&x1,&y1); *x=y1-(b/a)*x1;*y=x1; return gcd;}
ll modI(ll b, ll m)         {ll x,y;gcdEx(b,m,&x,&y);return (x%m+m)%m;}
ll modD(ll a, ll b)         {return (modI(b,MOD)*(a%MOD))%MOD;}
ll modS(ll a, ll b)         {return ((a%MOD)-(b%MOD)+MOD)%MOD;}
ll modP(ll x, ll y)         {ll r=1; x%=MOD; while(y>0){if(y&1){r=(r*x)%MOD;} y=y>>1; x=(x*x)%MOD;} return r;}
ll modA(ll a, ll b)         {return ((a%MOD)+(b%MOD))%MOD;}
ll modM(ll a, ll b)         {return ((a%MOD)*(b%MOD))%MOD;}

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

ll dp[3005][3005][2];
ll a[3005];

// dp[i][j][k] = score of player k for an i segment array starting at index j (1-indexed)

void solve(int TEST_CASE){
    int n;
    cin >> n;
    fr(i,n) cin >> a[i];
    fill(dp);
    ll t1, t2, t3, t4, mx;
    fr(i,n) dp[1][i+1][0] = a[i];
    frA(i,2,n){
        frA(j,1,n+1-i){
            t1 = dp[i-1][j][1]+a[j+i-2];
            t2 = dp[i-1][j][0];
            t3 = dp[i-1][j+1][1]+a[j-1];
            t4 = dp[i-1][j+1][0];
            if(t1>=t3){
                dp[i][j][0] = t1;
                dp[i][j][1] = t2;
            }else{
                dp[i][j][0] = t3;
                dp[i][j][1] = t4;
            }
        }
    }
    cout << dp[n][1][0]-dp[n][1][1] << endl;
}

int main(int argc, char* argv[]){
    if(argc==2 && argv[1][1]=='v') DEBUGGING = 1;
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    cin.exceptions(cin.failbit);
    int nTestCases=1;
    //cin >> nTestCases;
    frA(i,1,nTestCases) solve(i);
    return 0;
}

Measured memory_bytes: 144752
#include<bits/stdc++.h>
using namespace std;
int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int N, M;
    cin >> N >> M;
    string S;
    cin >> S;
    vector<int> V(N+1);
    int streak = 0;
    for (int i = 0; i <= N; ++i) {
        if (S[N-i] == '0') {
            streak = 0;
        } else {
            ++streak;
        }
        V[i] = streak;
    }
    int tmp = 0;
    vector<int> ans;
    while (tmp < N) {
        int mx = min(tmp+M, N);
        if (mx-V[mx] <= tmp) {
            puts("-1");
            return 0;
        } else {
            int next = mx-V[mx];
            ans.push_back(next-tmp);
            tmp = next;
        }
    }
    for (int i = ans.size(); i > 0; --i) {
        printf("%d%c", ans[i-1], i == 1 ? '\n' : ' ');
    }
    return 0;
}


Measured memory_bytes: 1480
#!/usr/bin/env python3
import sys
import numpy as np


def solve(N: int, S: str):
    c=0
    for i in range(N-2):
        if S[i]=='A':
            if S[i+1]=='B':
                if S[i+2]=='C':
                    c+=1
    print(c)
    return


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

if __name__ == '__main__':
    main()


Measured memory_bytes: 12504
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define len(v) ll(v.size())
#define fi first
#define se second

template <class T>
void cout_vec(const vector<T> &vec){
  for(auto itr:vec) cout<<itr<<' ';
  cout<<endl;
}

template <class T>
void cout_vec2(const vector<vector<T>> &vec){
  rep(i,vec.size()){
    rep(j,vec[i].size()){
      cout<<vec[i][j]<<' ';
    }
    cout<<endl;
  }
}

typedef pair<ll,ll> P;
const ll mod=1e9+7;
const ll inf=1e15;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin>>n;
  vector<int> t(n),v(n);
  int T=0;
  rep(i,n){
    cin>>t[i];
    T+=t[i];
  }
  rep(i,n) cin>>v[i];
  double now=0;
  map<double,double> maxv;
  maxv[now]=0;
  now+=0.5;
  double now_t=0;
  rep(i,n){
    now_t+=t[i];
    while(now<now_t){
      maxv[now]=v[i];
      now+=0.5;
    }
    if(i<n-1){
      maxv[now]=min(v[i],v[i+1]);
      now+=0.5;
    }
  }
  maxv[T]=0;
  now=0.5;
  while(now!=T+0.5){
    maxv[now]=min(maxv[now],maxv[now-0.5]+0.5);
    now+=0.5;
  }
  now=T-0.5;
  while(now!=-0.5){
    maxv[now]=min(maxv[now],maxv[now+0.5]+0.5);
    now-=0.5;
  }
  double ans=0;
  now=0;
  while(now!=T){
    ans+=(maxv[now]+maxv[now+0.5])*0.5*0.5;
    now+=0.5;
  }
  cout<<setprecision(10)<<ans<<endl;
}

Measured memory_bytes: 2816
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MAX_N 111
#define INF 1<<25
typedef pair<int,int> P;
typedef pair<int,P> PP;
#define F first
#define S second
struct edge{
  int to,cost,hour,com;
  edge(){}
  edge(int to,int cost,int hour,int com):to(to),cost(cost),hour(hour),com(com){}
};
struct pass{
  int bit,cost;
  pass(){bit=0;}
  pass(int bit,int cost):bit(bit),cost(cost){}
};
vector<edge> G[MAX_N];
int main(){
  int n,m,h,k;
  while(cin>>n>>m>>h>>k,n||m||h||k){
    for(int i=0;i<MAX_N;i++) G[i].clear();
    for(int i=0;i<m;i++){
      int a,b,c,h,r;
      cin>>a>>b>>c>>h>>r;
      a--;b--;
      G[a].push_back(edge(b,c,h,r-1));
      G[b].push_back(edge(a,c,h,r-1));
    }
    int s,t,p;
    cin>>s>>t>>p;
    s--;t--;
    pass ps[p];
    for(int i=0;i<p;i++){
      int l;
      cin>>l>>ps[i].cost;
      for(int j=0,x;j<l;j++)
	cin>>x,ps[i].bit|=(1<<(x-1));
    }
    
    int pc[1<<k];
    fill(pc,pc+(1<<k),INF);
    pc[0]=0;
    for(int i=0;i<p;i++)
      for(int j=0;j<(1<<k);j++)
	pc[j|ps[i].bit]=min(pc[j|ps[i].bit],pc[j]+ps[i].cost);

    int ans=INF;
    int dp[n][h+1];
    for(int b=0;b<(1<<k);b++){
      if(pc[b]==INF) continue;
      for(int i=0;i<n;i++)
	for(int j=0;j<=h;j++)
	  dp[i][j]=INF;
      priority_queue<PP,vector<PP>,greater<PP> > q;
      q.push(PP(0,P(0,s)));
      while(!q.empty()){
	int d=q.top().F,t=q.top().S.F,v=q.top().S.S;
	q.pop();
	if(dp[v][t]<=d) continue;
	dp[v][t]=d;
	for(int i=0;i<(int)G[v].size();i++){
	  edge& e=G[v][i];
	  if(t+e.hour>h) continue;
	  if(((b>>e.com)&1)&&dp[e.to][t+e.hour]>d)
	    q.push(PP(d,P(t+e.hour,e.to)));
	  else if(dp[e.to][t+e.hour]>d+e.cost)
	    q.push(PP(d+e.cost,P(t+e.hour,e.to)));
	}
      }
      int tmp=INF;
      for(int j=0;j<=h;j++) tmp=min(tmp,dp[t][j]);
      ans=min(ans,tmp+pc[b]);
    }
    cout<<(ans==INF?-1:ans)<<endl;
  }
  return 0;
}

Measured memory_bytes: 3412
#include <bits/stdc++.h>
#include <string>
#include <algorithm>
using namespace std; //std::の省略のため
using ll = long long;

int main()
{
  int N, L;
  cin >> N >> L;
  string s[N];

  for (int i = 0; i < N; i++)
    cin >> s[i];

  sort(s, s + N);

  string ans;

  for (int i = 0; i < N; i++)
    ans += s[i];

  cout << ans << endl;
}


Measured memory_bytes: 3640
#include <stdio.h>
#include <vector>

const int MAX_N = 100000;

std::vector<int> neighbours[1 + MAX_N];
int MaxDist[1 + MAX_N];

int maxDist(int u) {
  if (MaxDist[u] == 0) {
    MaxDist[u] = 1;
    for (int v : neighbours[u])
      MaxDist[u] = std::max(MaxDist[u], 1 + maxDist(v));
  }
  return MaxDist[u];
}

int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    neighbours[u].push_back(v);
  }
  int answer = 0;
  for (int i = 1; i <= n; i++)
    answer = std::max(answer, maxDist(i) - 1);
  printf("%d\n", answer);
  return 0;
}


Measured memory_bytes: 7424
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define srt(i) sort(i.begin(), i.end())
#define rvt(i) sort(i.begin(), i.end(), greater<int>())
 
int main()
{
    long a,b,n;
    cin >> a >> b >> n;

    long x=min(n, b-1);
    long ans1 = x*a/b;
    long ans2 = x/b; ans2 *= a;

    cout << ans1-ans2 << endl;
}

Measured memory_bytes: 3672
#include    <bits/stdc++.h>
#define     ll long long
#define     ull unsigned long long
#define     ld long double
#define     prec(k) fixed << setprecision(k)
#define     up(i, k, n) for (int i = k ; i < n ; i ++)
#define     down(i, k, n) for (int i = k ; i >= n ; i --)
#define     ii pair<int, int>
#define     pll pair <ll, ll>
#define     X first
#define     Y second
#define     str basic_string <int>
#define     QuanPham
const int maxN = (int) 1e4 + 7;
const int maxM = (int) 2e5 + 7;
const int maxT = (int) 1e6 + 7;

using namespace std;

int c[maxM], p[maxM], n, cnt, t; vector<int> pos[26];
string s;
ll ans;

void update(int x)
{
	for ( ; x <=n ; x += x & -x) c[x] ++;
}

int query(int x)
{
	int res = 0;
	for ( ; x > 0 ; x -= x & -x) res += c[x];
	return res;
}

int main()
{
	#ifdef QuanPham
    auto start = chrono::steady_clock::now();
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    //freopen ("C.INP", "r", stdin);
    //freopen ("C.OUT", "w", stdout);

	cin >> s;
	n = s.length();
	s = ' ' + s;
	up(i, 1, n + 1) pos[s[i] - 'a'].push_back(i);
	up(i, 0, 26)
	{
		int m = pos[i].size(), a = 0, b = m - 1;
		cnt += (m & 1);
		if (cnt >= 2) return cout << -1, 0;
		while (a <= b) p[pos[i][a]] = pos[i][b], a ++, b --;
	}

	up(i, 1, n + 1)
	if (p[i] && p[i] != i) ans += query(p[i]) + query(i), update(p[i]);
	else if (p[i] == i) t = i;

	if (n & 1)
	up(i, 1, n + 1)
	if (p[i])
	if (i < t && p[i] < t || i > t && p[i] > t) ans ++;

	cout << ans;

}

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

#define rep(i,n) for(int i = 0; i < n; i++)
#define REP(i,n) for(int i = 1; i < n; i++)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl '\n'
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;
using vs = vector<string>;
using vb = vector<bool>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll &a, const ll &b){return ((a)+(b)-1)/b;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }



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

  int a, b, c;
  cin >> a >> b >> c;
  int ans = a^b^c;
  cout << ans << endl;

}

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


int main() {

	int N;
	cin >>N;

	if (N > 17 || N == 4 || N == 7 || N == 8 || N == 11 || N == 12 || N == 14 || N==15|| N == 16)
		cout << "Yes";

	else
		cout << "No";
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		//System.out.println("数字を入力してください>");
		int x = scan.nextInt();
		int num = x*x*x;
		System.out.println(num);
		
	}
}


Measured memory_bytes: 26328
#include <bits/stdc++.h>
using namespace std;
using ll= long long;
using vi = vector<int>;
using vl= vector<ll>;
using vs=vector<string>;

ll gcd(ll a, ll b) { if (a == 0) return b; return gcd(b % a, a);}
ll max(ll a, ll b) {if (a > b) return a; else return b;}
ll min(ll a, ll b) {if (a < b) return a; else return b;}
ll power(ll a,ll b) {ll i,p=1; for(i=0;i<b;i++){p*=a;} return p;}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int testcase=1;
    //cin>>testcase;
    for(int p=0;p<testcase;p++){
        ll n=0;
        cin>>n;
        ll d=0,x=0;
        cin>>d>>x;
        ll array[n]={0};
        ll sum=n;
        for(int i=0;i<n;i++){
            cin>>array[i];
            sum+=(d-1)/array[i];
        }
        sum+=x;
        cout<<sum;
        
        }

    return 0;
}


Measured memory_bytes: 3608
q, h, s, d = map(int, input().split())
n = int(input())

if d / 2 != min(4 * q, 2 * h, s, d / 2):
    print(n * min(4 * q, 2 * h, s))
else:
    if n % 2 == 0:
        print(n // 2 * d)
    else:
        print(n // 2 * d + min(4 * q, 2 * h, s))

Measured memory_bytes: 3060