akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    deque<int> b;
    if (n % 2 == 0) {
        for(int i = 0; i < n; i++){
            if(i % 2 == 1){
                b.push_front(a[i]);
            }
            else{
                b.push_back(a[i]);
            }
        }
    } 
    else {
        for(int i = 0; i < n; i++){
            if(i % 2 == 0){
                b.push_front(a[i]);
            }
            else{
                b.push_back(a[i]);
            }
        }
    }
    for(int i = 0; i < n; i++){
        cout << b[i] << ' ';
    }
    return 0;
}

Measured memory_bytes: 4800
#from math import *
from collections import *
from random import *
from bisect import *
import sys
input=sys.stdin.readline
def lis():
    return list(map(int,input().split()))
def ma():
    return map(int,input().split())
def inp():
    return int(input())
n,d=ma()
r=0
for i in range(n):
    x,y=ma()
    f=(x*x)+(y*y)
    f=pow(f,0.5)
    if(f<=d):
        r+=1
print(r)
    
            

        
            
        
    
        
    


Measured memory_bytes: 78540
n = int(input())
P = list(map(int, input().split()))

Cnt = []
cnt = 0
ans = 0
for idx, p in enumerate(P, 1):
    if idx == p:
        Cnt.append(idx)
        cnt += 1
    else:
        cnt = 0
    if cnt == 2:
        ans -= 1
        cnt = 0

ans += len(Cnt)
print(ans)

Measured memory_bytes: 20644
x,y=input().split()
a=['1 3 5 7 8 10 12','4 6 9 11','2']
count=0
for i in range(3):
    if a[i].find(x)!=-1 and a[i].find(y)!=-1:
        count+=1
        
    elif x=='2' or y=='2':
        count=count*0
        break
print('Yes' if count>0 else 'No')

Measured memory_bytes: 2940
import numpy as np

x, y, z, k = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

AA, BB = np.meshgrid(A,B)
AB = AA + BB
AB = np.sort(AB.flatten())[::-1][:k]

ABAB, CC = np.meshgrid(AB,C)
ABC = ABAB + CC
ABC = np.sort(ABC.flatten())[::-1][:k]

for abc in ABC:
    print(abc)

Measured memory_bytes: 168752
import sys

def atcoderB():
    
    global gamelis
    gamelis = []

    global alis
    global blis
    global clis
    alis = []
    blis = []
    clis = []


    for i in range(3):
        gamelis.append(input())
    alis = list(gamelis[0])
    blis = list(gamelis[1])
    clis = list(gamelis[2])
    funca()
    
def funca():
    global switchval
    if alis ==[]:
        print("A")
        sys.exit()
    switchval = alis[0]
    del alis[0]


    if switchval == "a":
        funca()
    if switchval == "b":
        funcb()
    if switchval == "c":
        funcc()

        
    
def funcb():
    global switchval
    if blis ==[]:
        print("B")
        sys.exit()
    switchval = blis[0]
    del blis[0]


    if switchval == "a":
        funca()
    if switchval == "b":
        funcb()
    if switchval == "c":
        funcc()
    else:
        print("B")

    
def funcc():
    global switchval
    if clis ==[]:
        print("C")
        sys.exit()
    switchval = clis[0]
    del clis[0]

    if switchval == "a":
        funca()
    if switchval == "b":
        funcb()
    if switchval == "c":
        funcc()
    else:
        print("C")


    
atcoderB()


Measured memory_bytes: 9136
x = [[[0 for i in range(10)] for j in range(3)] for k in range(4)]
n = int(input())
for i in range(n):
    b, f, r, v = map(int, input().split())
    x[b-1][f-1][r-1] += v
for i in range(4):
    for j in range(3):
        for k in range(10):
            print(" ", end="")
            print(x[i][j][k], end="")
        print()
    if i < 3:
        print("####################")


Measured memory_bytes: 5636
#include <stdio.h>
#include <stdlib.h>

int qpos[8][3];
int qlen=0;
int vacant[64];
int vlen=0;
int *idx, *used;
    
void combination(int k, int m)
{
  int i, j;
  if (m==k) {
    for (i=0; i<64; i++)  {
      for (j=0; j<qlen; j++)
        if (qpos[j][0]==i) {
          fputc('Q', stdout);
          break;
        }
      if (j==qlen) fputc('.', stdout);
      if (i%8==7) fputc('\n', stdout);
    }
  } else {
    for (i=0; i<vlen; i++) {
      if (used[i] || (m>0 && idx[m-1]<i))  continue;
      idx[m] = i;
      int q = vacant[i];
      int x = q%8;
      int y = q/8;

      for (j=0; j<qlen; j++) {
        if (x==qpos[j][0]%8 || y==qpos[j][0]/8)  break;
        if (y==x+qpos[j][1] || y==-x+qpos[j][2]) break;
      }
      if (j==qlen) {
        used[i]=1;
        qpos[qlen][0]=q;
        qpos[qlen][1]=y-x;
        qpos[qlen++][2]=y+x;
        combination(k, m+1);
        qlen--;
        used[i]=0;
      }
    }
  }
}

int main()
{
  int i, j, k, n, x;
  fscanf(stdin, "%d", &n);
  idx = (int*)malloc(sizeof(int)*(8-n));

  int buf[64] = {0};

  for (k=0; k<n; k++) {
    fscanf(stdin, "%d %d", &j, &i);
    qpos[qlen][0]=j*8+i;
    qpos[qlen][1]=j-i;
    qpos[qlen][2]=j+i;
    qlen++;

    for (x=0; x<8; x++) {
      if (0<=j*8+x && j*8+x<64)   buf[j*8+x]=1;
      if (0<=x*8+i && x*8+i<64)   buf[x*8+i]=1;
      if (0<=8*(j-i+x)+x && 8*(j-i+x)+x<64)  buf[8*(j-i+x)+x]=1;
      if (0<=8*(j+i-x)+x && 8*(j+i-x)+x<64)  buf[8*(j+i-x)+x]=1;
    }
  }
  for (i=0; i<64; i++)
    if (buf[i]==0) vacant[vlen++] = i;
  
  used = (int*)malloc(sizeof(int)*vlen);
  for (int i=0; i<vlen; i++)  used[i]=0;

  combination(8-n, 0);
  
  return 0;
}



Measured memory_bytes: 2108
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9) + 7;

int main(void) {
	int n;
	ll c, k;
	cin >> n >> c >> k;
	
	vector<ll> t(n);
	for(int i = 0; i < n; ++i) {
		cin >> t[i];
	}
	
	sort(t.begin(), t.end());
	
	int cnt = 0;
	int ans = 0;
	ll nop = 1;
	for(int i = 1; i < n; ++i) {
		ll limit = t[cnt] + k;
	
		if( t[i] <= limit && nop < c ) { 
			nop++;
		} else {
			ans++;
			cnt = i;
			nop = 1;
		}
	}
	
	ans++;
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 1024
#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() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  string s;
  cin >> n >> s;
  int res = 0;
  rep(i, s.size() - 2) {
    if(s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C') res++;
  }
  cout << res << endl;
  return 0;
}

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

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		int ret = inf;
		for(int i=0;i<N;i++){
			ret = Math.Min(ret, calc(i));
		}
		Console.WriteLine(ret);
		
	}
	const int inf = (int) 1e9;
	int calc(int midx){
		
		List<int> candi = new List<int>();
		List<int> compo = new List<int>();
		int min = A[midx];
		for(int i=0;i<N;i++){
			if(A[i] < min){
				compo.Sort();
				compo.Reverse();
				while(compo.Count >= K){
					candi.Add(compo[compo.Count - 1]);
					compo.RemoveAt(compo.Count - 1);
				}
				compo = new List<int>();
			} else {
				compo.Add(A[i]);
			}
		}
		if(compo.Count >= K){
			compo.Sort();
			compo.Reverse();
			while(compo.Count >= K){
				candi.Add(compo[compo.Count - 1]);
				compo.RemoveAt(compo.Count - 1);
			}
		}
		
		if(candi.Count < Q) return inf;
		candi.Sort();
		return candi[Q-1] - min;
		
	}
	
	
	
	
	int N, K, Q;
	int[] A;
	public Sol(){
		var d = ria();
		N = d[0]; K = d[1]; Q = d[2];
		A = ria();
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


Measured memory_bytes: 39740
#include <stdio.h>
int main()
{   int n,a[100001];
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
    }int cnt=0,i=0;
    while (cnt<=n){
        if(a[i]==2){
            printf("%d",cnt+1);
            return 0;
        }
        else i=a[i]-1;
        cnt++;
    }
    printf("-1");
    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll=long long;
int main(){
    int n,m;
    cin>>n>>m;
    ll ans=0;
    vector<int>a(n),b(n);
    rep(i,n){
        cin>>a[i]>>b[i];
    }
    vector<pair<int,int>>ab(n);
    rep(i,n){
        ab[i]=make_pair(a[i],b[i]);
    }
    sort(ab.begin(),ab.end());
    rep(i,n){
        if(m==0){
            break;
        }
        if(m>=ab[i].second){
            m-=ab[i].second;
            ans+=(ll)ab[i].first*ab[i].second;
        }
        else if(m<ab[i].second&&m!=0){
            ans+=(ll)m*ab[i].first;
            m=0;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1792
#include <stdio.h>

#define N 1000

int main()
{
  int A[N],i,j,k,v,n;

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

  for(i=0; i<n-1; i++){
    
    printf("%d ",A[i]);
  }
  printf("%d",A[n-1]);
  printf("\n");

  for(k=1; k<n; k++){
    
    v = A[k];
    j = k-1;
    
    while(j >= 0 && A[j] > v){
      A[j+1] = A[j];
      j--;
      A[j+1] = v;
    }    
    for(i=0; i<n-1; i++){
      printf("%d ",A[i]);
    }
    printf("%d",A[n-1]);
    printf("\n");
  }
  return 0;
}



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

int main() {
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  int a1 = 0, b1 = 0, c1 = 0;
  int a, b, c;
  for (int i = 0; i < n; i++) {
    cin >> a >> b >> c;
    a += max(b1, c1);
    b += max(a1, c1);
    c += max(b1, a1);
    a1 = a;
    b1 = b;
    c1 = c;
  }
  cout << max(max(a1, b1), c1);
  return 0;
}


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

int cnt[400000];
int sum[400000];

int main(){
	int n;cin>>n;
	rep(i,n){
		int a;scanf("%d",&a);a--;
		cnt[a]++;
	}
	rep(i,n){
		if(!cnt[i])continue;
		sum[1]++;
		sum[cnt[i]+1]--;
	}
	rep(i,n)sum[i+1]+=sum[i];
	rep(i,n)sum[i+1]+=sum[i];
	for(int K=1;K<=n;K++){
		int ok=0,ng=n+1;
		while(ng-ok>1){
			int t=(ok+ng)/2;
			if(sum[t]>=t*(ll)K)ok=t;
			else ng=t;
		}
		printf("%d\n",ok);
	}
}

Measured memory_bytes: 3200
N, M = map(int, input().split())

ok, ng = (0, 0)
oks = set()
ngdict = dict()
for _ in range(M):
    pp, S = input().split()
    p = int(pp)
    if p in oks:
        continue
    if S == 'AC':
        ok += 1
        ng += ngdict.get(pp, 0)
        oks.add(p)
    else:
        ngdict[pp] = ngdict.get(pp, 0) + 1

print('{} {}'.format(ok, ng))

Measured memory_bytes: 11900
import numpy as np
import sys
line = sys.stdin.readline

H, W = map(int, line().split())
grid = np.zeros((H + 2, W + 2), np.int32)
grid[1:-1, 1:-1] = (np.array([list(line().rstrip()) for _ in range(H)]).reshape(H, W) == '.') * 1
grid_v = grid.T

right = np.maximum.accumulate(np.where(grid < 1, np.arange(W + 2), 0), axis=1)
left = np.fliplr(np.minimum.accumulate(np.fliplr(np.where(grid < 1, np.arange(W + 2), 10 ** 10)).copy(), axis=1))
down = np.maximum.accumulate(np.where(grid_v < 1, np.arange(H + 2), 0), axis=1).T
up = np.fliplr(np.minimum.accumulate(np.fliplr(np.where(grid_v < 1, np.arange(H + 2), 10 ** 10)).copy(), axis=1)).T

print(np.max((left - right) + (up - down)) - 3)

Measured memory_bytes: 267056
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <iomanip>

using namespace std;

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

	return 0;
}

Measured memory_bytes: 3600
package main
import . "fmt"
import "strings"
func main() {
  var a,b,t int
  var s string
  Scan(&a,&b)
  Scan(&s)
  t = strings.Count(s,"-")
  if t == 1 && s[a:a+1] == "-" {
    Println("Yes")
  } else {
    Println("No")
  }
}

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

#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
typedef long long ll;
typedef pair<int,int> P;

template<typename A,typename B> inline void chmin(A &a,B b){if(a>b) a=b;}
template<typename A,typename B> inline void chmax(A &a,B b){if(a<b) a=b;}

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

int y[205],x[205];
int main()
{   
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;
    while(cin>>n,n)
    {
        int min_y,max_y,min_x,max_x;
        min_y=max_y=min_x=max_x=0;
        y[0]=x[0]=0;
        for(int i=1;i<n;i++){
            int k,d;
            cin>>k>>d;
            y[i]=y[k]+dy[d];
            x[i]=x[k]+dx[d];
            chmin(min_y,y[i]); chmax(max_y,y[i]);
            chmin(min_x,x[i]); chmax(max_x,x[i]);
        }
        cout<<max_x-min_x+1<<" "<<max_y-min_y+1<<endl;
    
    }
}

Measured memory_bytes: 3092
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

k = ni()

a = [0]*(10**6+1)
a[1] = 7%k
for i in range(2,k+1):
  a[i] = (a[i-1]*10+7)%k
for i in range(1,k+1):
  if a[i]==0:
    print(i)
    exit()
print(-1)

Measured memory_bytes: 71944
object Main extends App {

  import scala.io.StdIn._
  import scala.math._


  val Array(n, m, q) = readLine.trim.split(' ').map(_.toInt)
  val floors = SegTree(1, n)
  for (_ ← 0 until m) {
    val Array(d, a, b) = readLine.trim.split(' ').map(_.toInt)
    floors.setUpperLimit(a, b - 1, d)
  }
  for (_ ← 0 until q){
    val Array(e, s, t) = readLine.trim.split(' ').map(_.toInt)
    val day = floors.maxBetween(s, t - 1)
    println(
      if (day < e) "Yes"
      else "No"
    )
  }
  object SegTree{
    def apply(from: Int, to: Int, default: Int = Int.MaxValue): SegTree = {
      if (from == to) new Leaf(default, from)
      else new Node(from, to, SegTree(from, (from + to) / 2, default), SegTree((from + to) / 2 + 1, to, default))
    }
  }
  sealed trait SegTree{
    def maxBetween(from: Int, to: Int): Int
    def setUpperLimit(from: Int, to: Int, limit: Int): Unit
    def upper: Int
  }
  class Node(private val mFrom: Int, private val mTo: Int, private val mLeft: SegTree, private val mRight: SegTree) extends SegTree {
    override def upper: Int = mUpper
    private var mUpper = math.max(mLeft.upper, mRight.upper)

    override def setUpperLimit(from: Int, to: Int, limit: Int): Unit = {
      if (mUpper > limit) {
        if (from <= mFrom && mTo <= to) {
          mUpper = limit
        } else if (from <= mTo && mFrom <= to) {
          mLeft.setUpperLimit(mFrom, mTo, mUpper)
          mLeft.setUpperLimit(from, to, limit)
          mRight.setUpperLimit(mFrom, mTo, mUpper)
          mRight.setUpperLimit(from, to, limit)
          mUpper = math.max(mLeft.upper, mRight.upper)
        }
      }
    }
    override def maxBetween(from: Int, to: Int): Int = {
      if (to < mFrom || mTo < from) Int.MinValue
      else if (from <= mFrom && mTo <= to) mUpper
      else {
        mLeft.setUpperLimit(mFrom, mTo, mUpper)
        mRight.setUpperLimit(mFrom, mTo, mUpper)
        math.max(mLeft.maxBetween(from, to), mRight.maxBetween(from, to))
      }
    }
  }
  class Leaf(private var mValue: Int, private val mPosition: Int) extends SegTree {
    override def maxBetween(from: Int, to: Int): Int = {
      if ((from to to).contains(mPosition)) mValue
      else Int.MinValue
    }

    override def setUpperLimit(from: Int, to: Int, limit: Int): Unit = {
      if ((from to to).contains(mPosition) && limit < mValue) mValue = limit
    }

    override def upper: Int = mValue
  }
  implicit class Extension[T](val value :T){
    def also(func: T ⇒ Unit): T = {
      func(value)
      value
    }
    def let[R](func: T ⇒ R): R = func(value)
  }
}


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

int main() {
  int n,m,ans=0,x[100000];
  cin >> n >> m;
  for(int i=0; i<m; i++) {
    cin >> x[i];
  }
  sort(x,x+m);
  for(int i=1; i<=m; i++) {
    x[i-1]=x[i]-x[i-1];
  }
  sort(x,x+m-1);
  for(int i=0; i<m-n; i++) {
    ans+=x[i];
  }
  cout << ans << endl;
}

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

int main() {
  int n; cin >>n;
  vector<int> p(n);
  for (int i=0; i<n; i++) cin >>p.at(i);
  int ans = 0;
  for (int i=1; i<n-1; i++){
    if (p.at(i) != max(p.at(i-1),max(p.at(i),p.at(i+1)))
        && p.at(i) != min(p.at(i-1),min(p.at(i),p.at(i+1)))){
      ans++;
    }
  }
  
  cout <<ans;
  cout <<endl;
}


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

using namespace std;
int static dp[100001];
int solve(vector<int> &h,int n,int i)
{
    if(i==n-1)
    {
        return 0;
    }
    if(dp[i]!=-1)
    {
        return dp[i];
    }
    int ans=solve(h,n,i+1)+abs(h[i]-h[i+1]);
    if(i+2<n)
    {
        ans=min(ans,solve(h,n,i+2)+abs(h[i]-h[i+2]));
    }
    return dp[i]=ans;
}
int main()
{
    int n;
    cin>>n;
    vector<int> h(n);
    for(int i=0;i<n;i++)
    {
        cin>>h[i];
    }
    memset(dp,-1,sizeof(dp));
    cout<<solve(h,n,0)<<endl;
    return 0;
}


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

using namespace std;

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

  int sum = 0;
  int minimum = 1000;
  for (int i = 0; i < N; i++) {
    int m;
    cin >> m;

    sum += m;
    minimum = min(minimum, m);
  }

  int answer = (X - sum) / minimum + N;

  cout << answer << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  int A[9];
  for(int i = 0; i<9; i++){
    cin>>A[i];
  }
  int n;
  cin>>n;
  while(n--){
    int x;
    cin>>x;
    for(int i =0; i<9; i++){
      if(A[i]==x)A[i]=0;
    }
  }
  if(A[0]==A[4]&&A[4]==A[8])cout<<"Yes";
  else if(A[2]==A[4]&&A[4]==A[6])cout<<"Yes";
  else{
    for(int i = 0; i<3; i++){
      if(A[3*i]==A[3*i + 1] && A[3*i + 1]==A[3*i + 2] || A[i] == A[3+i] && A[3+i] == A[6+i]){
        cout<<"Yes";
        return 0;
      }
    }
    cout<<"No";
  }
  return 0;
}
  

Measured memory_bytes: 256
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
#define rep(i,n) for(int i=0;i<=n;i++)
typedef int long long ll;
using namespace std;

int main(){
    string s,t;
    cin>>s>>t;
    sort(s.begin(),s.end());
    sort(t.rbegin(),t.rend());
    //cout<<s<<endl;
    
    if(s<t){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
    
    
    
return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <vector>
#include <iostream>
#include <queue>
#include <bits/stdc++.h>
 
#define rep(i,n) for (int i=0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<double> vd;
typedef pair<int, int> pi;


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

  int lidx = 0;
  map<int, int> mp;
  mp[0] = 1;
  while(true){
    lidx = a[lidx] - 1;
    mp[lidx]++;
    if (mp[lidx] == 2) break;
  }

  // printf("lidx %d\n", lidx);
  vi loop;
  vi preloop;
  bool flag = true;
  bool flag2 = false;
  int idx = 0;
  while (true){
    if (lidx == idx){
      if (!flag) flag2 = true;
      flag = false;
    }
    if (flag2 and idx == lidx) break;
    if (flag){
      preloop.push_back(idx);
    }else{
      loop.push_back(idx);
    }
    idx = a[idx] - 1;
  }

  // cout << "preloop ";
  // rep(i, preloop.size()) cout << preloop[i] << " ";
  // cout << endl;

  // cout << "loop ";
  // rep(i, loop.size()) cout << loop[i] << " ";
  // cout << endl;

  int pre_num = preloop.size();
  if (pre_num > k){
    cout << preloop[k] + 1 << endl;
    return 0;
  }

  k -= pre_num;
  int size = loop.size();
  int ans = loop[k % size] + 1;
  cout << ans << endl;

  return 0;
}

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

typedef long long ll;
typedef pair<int, int> P;

const ll mod =  1000000007;
const int inf = 1e9;
const long long INF = 1LL << 60;   // INFの値は1152921504606846976

int n;
vector<int> g[200005];
ll ans[200005];
ll cnt[200005];
bool v[200005];

void dfs(int now,ll p){
    v[now] = true;
    p += cnt[now];
    ans[now] = p;
    for(auto next : g[now]){
        if(!v[next]){
            v[next] = true;
            dfs(next,p);
            v[next] = false;
        }
    }
}

int main()
{
    int q;
    cin >> n >> q;
    rep(i,n-1){
        int a,b;
        cin >> a >> b;
        a--; b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    rep(i,q){
        int p,x;
        cin >> p >> x;
      	p--;
        cnt[p] += x;
    }
    dfs(0,0);
    rep(i,n) cout << ans[i] << ' ';
}

Measured memory_bytes: 25856
#include <set>
#include <cstdio>
#define REP(i,n) for(int i=0; i<(int)(n); i++)

inline int getInt(){ int s; scanf("%d", &s); return s; }

using namespace std;

int dp[40][40000];

int main(){
  while(true){
    int n = getInt();
    int m = getInt();
    int k = getInt();

    if(n + m + k == 0) break;

    int mm = 1; REP(i,n) mm *= m;

    double ans = 0.0;

    REP(i,n + 1) REP(j, n * m + 1)
      dp[i][j] = 0;
    dp[0][0] = 1;

    REP(i,n) REP(j, n * m)
      if(dp[i][j]){
        for(int k = 1; k <= m; k++)
          if(j + k <= n * m){
            dp[i + 1][j + k] += dp[i][j];
          }
      }

    REP(d, n * m + 1){
      int dst = max(1, d - k);
      ans += dst * (double)dp[n][d] / mm;
    }

    printf("%.9f\n", ans);
  }
  return 0;
}

Measured memory_bytes: 0
n = int(input())
1
h = list(map(int,input().split()))
1

p = 0
ans = 'Yes'
for i in range(n-1):
    if h[i] < h[i+1]:
        p = 0
    elif h[i] == h[i+1] + 1 and p == 0:
        p = 1
    elif h[i] == h[i+1]:
        pass
    else:
        ans = 'No'
        break

print(ans)


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

using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
typedef long long int64;
int MOD = 1e9 + 7;

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


  cout << ((S>W)?"safe":"unsafe") << "\n";
  return 0;
}


Measured memory_bytes: 3624
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
inline int read(){
	int x=0,f=1;
	char c=getchar();
	while(c<'0'||c>'9'){
		if(c=='-')f=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9'){
		x=(x<<1)+(x<<3)+c-'0';
		c=getchar();
	}
	return x*f;
}
int m,d,ans;
int main(){
	m=read(),d=read();
	for(int i=4;i<=m;++i){
		for(int j=22;j<=d;++j){
			int x=j%10,y=j/10;
			if(x>=2&&y>=2&&x*y==i)++ans;
		}
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 3752
a,b=map(int,input().split())
s=[2,3,4,5,6,7,8,9,10,11,12,13,1]
a=s.index(a)
b=s.index(b)
if a>b:
    print("Alice")
elif a<b:
    print("Bob")
else:
    print("Draw")


Measured memory_bytes: 9120
#include <bits/stdc++.h>
using namespace std;
int n, m, ans;
int main()
{
    int A, B, H, M;
    cin >> A >> B >> H >> M;
    double da = 30 * (H + M / 60.0), db = M * 6;
    double ans = A * A + B * B - 2 * A * B * cos(acos(-1) / 180 * abs(da - db));
    printf("%.12f\n", sqrt(ans));
    return 0;
}

Measured memory_bytes: 4228
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
#define MAX_V 210
#define INF 1000000000

int d[MAX_V][MAX_V];
int V; //頂点数

void warshall_floyd(){
    for(int k = 1; k <= V; k++){
        for(int i = 1; i <= V; i++){
            for(int l = 1; l <= V; l++){
                d[i][l] = min(d[i][l], d[i][k] + d[k][l]);
            }
        }
    }
}

int ans = 1000000000;

void dfs(int idx, vector<int> flag, vector<int> &lis, int count, int c){
    int f = 0;
    flag[idx] = 1;
    for(int i = 0; i < lis.size(); i++){
        if(flag[i] == 0){
            count += d[lis[idx]][lis[i]];
            dfs(i, flag, lis, count, 1);
            count -= d[lis[idx]][lis[i]];
            f = 1;
        }
    }
    if(f == 0){
        ans = min(ans, count);
    }
}


int main(){
    int m, r; cin >> V >> m >> r;
    for(int i = 0; i < MAX_V; i++){
        for(int l = 0; l < MAX_V; l++){
            d[i][l] = INF;
        }
    }
    for(int i = 0; i < MAX_V; i++){
        d[i][i] = 0;
    }
    vector<int> lis(r);
    vector<int> flag(r);
    for(int i = 0; i < r; i++){
        cin >> lis[i];
    }
    for(int i = 0; i < m; i++){
        int a, b, c; cin >> a >> b >> c;
        d[a][b] = min(d[a][b], c);
        d[b][a] = min(d[b][a], c);
    }
    warshall_floyd();
    for(int i = 0; i < r; i++){
        dfs(i, flag, lis, 0, 0);
    }
    cout << ans << endl;
}



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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())
#define IN(x, a, b) x >= a and x < b

using namespace std;
using ll = long long;

template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T> constexpr T INF = numeric_limits<T>::max() / 2;

template <typename T> struct edge {
  int src, to;
  T cost;
  edge(int to, T cost) : src(-1), to(to), cost(cost) {}
  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
  edge &operator=(const int &x) {
    to = x;
    return *this;
  }
  operator int() const { return to; }
};

template <typename T> using Edges = vector<edge<T>>;
template <typename T> using WeightedGraph = vector<Edges<T>>;
using UnWeightedGraph = vector<vector<int>>;
template <typename T> using Matrix = vector<vector<T>>;

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

  int N, M;
  cin >> N >> M;
  UnWeightedGraph G(N);
  REP(i, M) {
    int s, t;
    cin >> s >> t;
    s--;
    t--;
    G[s].emplace_back(t);
  }

  int shortest = INF<int>;
  vector<int> g_pred(N, -1);
  int start;
  REP(i, N) {
    vector<bool> seen(N, false);
    vector<int> pred(N, -1);
    queue<pair<int, int>> que;
    que.emplace(i, 0);
    while (!que.empty()) {
      int v, d;
      tie(v, d) = que.front();
      que.pop();
      seen[v] = true;
      for (auto nv : G[v]) {
        if (nv == i) {
          // 戻ってきた
          if (d < shortest) {
            shortest = d;
            pred[nv] = v;
            g_pred = pred;
            start = i;
          }
        } else if (!seen[nv]) {
          que.emplace(nv, d + 1);
          pred[nv] = v;
        }
      }
    }
  }

  if (shortest == INF<int>) {
    cout << "-1\n";
  } else {
    vector<int> ans;
    ans.emplace_back(start);
    int v = g_pred[start];
    while (v != start) {
      ans.emplace_back(v);
      v = g_pred[v];
    }
    reverse(ALL(ans));
    cout << SZ(ans) << '\n';
    for (auto v : ans) {
      cout << v + 1 << '\n';
    }
  }

  return 0;
}

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

typedef long long ll;
const ll MOD = 1e9+7;

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n,a,b;
    cin>>n>>a>>b;

    cout<<min(n*a,b);

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define ve vector<int>
#define vl vector<long long int>
#define vd vector<double>
#define vs vector<string>
#define vve vector<vector<int>>
#define all(a) a.begin(),a.end()
using namespace std;

int main(){
  int n;
  cin>>n;
  ve x(n);
  for(int i=0;i<n;i++){
    cin>>x[i];
  }
  ll ans=1e9,count=0;
  for(int i=1;i<=100;i++){
    count=0;
    for(int j=0;j<n;j++){
      count+=(i-x[j])*(i-x[j]);
    }
    if(ans>count) ans=count;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

	double x, h;
	double s, t1, t2;
	while (true) {
	    x = stdIn.nextInt();
	    h = stdIn.nextInt();
	    if (x == 0 && h == 0) break;

	    t1 = h * h + x * x / 4;
	    t2 = Math.sqrt(t1);
	    s = x * x + 2 * x * t2;
	    System.out.println(s);
	}
    }
}

Measured memory_bytes: 26252
#include <bits/stdc++.h>
#define ll long long
#define en "\n"
using namespace std;

const int M=1e9+7;

int a[8];

int main()
{
    ios::sync_with_stdio(false);
    int n=0,m,su=0;
    for(int i=0;i<5;i++)
    {
        cin>>m;
        int tem=m;
        while(m%10)
            m++;
        tem=m-tem;
        su=max(su,tem);
        n+=m;
    }
    cout<<n-su<<en;
    return 0;
}


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

#define ff              first
#define ss              second
#define ll            long long

#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
//mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;


void sb()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}
int main()
{
	//sb();

int n;
long long k;
cin>>n>>k;
int a[200010];
for(int i=1;i<n+1;i++){
    cin>>a[i];
}
int occ[200010]={0};
int j=1;
int cycle =0;
int start = 0;
for(int i=1;i<=2*n;i++){
    if(occ[j]!=0){
        cycle = i-occ[j];
        start = occ[j]-1;
        break;
    }
    //cout<<" fisrt j "<<j<<endl;
    occ[j] = i;
    j = a[j];
    //cout<<" updated j "<<j<<endl;
}
// cout<<" start is : "<<start<<endl;
// cout<<" cycle is :"<<cycle<<endl;
int finArr[200010];
for(int i=0;i<cycle;i++){
    finArr[i] = j;
    j = a[j];
}
if(k>n)
cout<<finArr[(k-start)%cycle];
else{
    int s =1;
    for(int i=1;i<=k;i++){
        s = a[s];
    }
    cout<<s;
}



return 0;
}



Measured memory_bytes: 5880
n = int(input())

def divs(n:int) -> list:
    divs = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divs.append(i)
            if i != n // i:
                divs.append(n//i)
    divs.sort()
    return divs

div_l = divs(n)
print (max(len(str(div_l[(len(div_l)//2)-1])), len(str(div_l[len(div_l)//2]))))


Measured memory_bytes: 9344
#include <stdio.h>
#include <stdlib.h>
 
typedef struct Node* NodePointer;
 
struct Node {
  NodePointer next[5];
};
 
int conv(char c) {
  switch(c) {
  case '\0':return 0;
  case 'A': return 1;
  case 'C': return 2;
  case 'G': return 3;
  case 'T': return 4;
  }
  return -1;
}
 
NodePointer makeNode() {
  int i;
  NodePointer p;
  p = malloc(sizeof(struct Node));
  for(i = 0; i < 5; ++i) {
    p->next[i] = NULL;
  }
  return p;
}
     
void insert(NodePointer p, char* s) {
  int a;
  a = conv(*s);
  if(p->next[a] == NULL) p->next[a] = makeNode();
  if(a != 0) insert(p->next[a], s+1);
}
 
int find(NodePointer p, char* s) {
  int a;
  a = conv(*s);
  if(p->next[a] == NULL) return 0;
  if(a == 0) return 1;
  return find(p->next[a], s+1);
}
 
int main() {
  int n;
  char s[100], t[100];
  NodePointer head;
 
  head = makeNode();
  scanf("%d", &n);
  while(n--) {
    scanf("%s %s", s, t);
    if(s[0] == 'i') {
      insert(head,t);
    } else {
      if(find(head,t))
        printf("yes\n");
      else
        printf("no\n");
    }
  }
  return 0;
}


Measured memory_bytes: 30868
#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>
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 mod 1000000007
#define INF 2000000000
#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];
using namespace std;

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* 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 x, y;
	cin >> x >> y;
	cout << x + y / 2 << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O0")
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for (ll i = 0; i < (n); ++i)
const ll mod = 1e9+7;
const ll INF = 1e18;
#define All(a) (a).begin(),(a).end()
#define Pi acos(-1)

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << setprecision(15) << fixed;
  chrono::system_clock::time_point start,end;
  start = chrono::system_clock::now();

  ll a, b, c, k;
  cin >> a >> b >> c >> k;
  rep(i,k) {
    if (c <= a || c <= b) {
      c *= 2;
      continue;
    }
    if (b <= a) {
      b *= 2;
    }
  }
  if (c > b && b > a) {
    cout << "Yes\n";
  }
  else {
    cout << "No\n";
  }


  end = chrono::system_clock::now();
  auto elapsed = chrono::duration_cast< chrono::milliseconds >(end - start).count();
  cerr << elapsed << "ms" << '\n';
}

Measured memory_bytes: 3652
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

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

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main() {
  string S;
  cin >> S;
  string S1 = S;
  string S2 = S;
  S1[0] = char(S1[0] - '0' - 1 + '0');
  REP(i, S1.size()) {
    if (i != 0) S1[i] = '9';
  }
  int ans1 = 0, ans2 = 0;
  REP(i, S1.size()) ans1 += S1[i] - '0';
  REP(i, S2.size()) ans2 += S2[i] - '0';
  cout << max(ans1, ans2) << endl;
  return 0;
}

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

int main() {
    int n; cin >> n;
    int c = n;
    int sum = 0;
    while (c) {
        sum += c%10;
        c /= 10;
    }
    cout << (n%sum ? "No" : "Yes") << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repeq(i,n) for(int (i)=0;(i)<=(int)(n);(i)++)
#define rep1(i,x,n) for(int (i)=(x);(i)<(int)(n);(i)++)
#define rep1eq(i,x,n) for(int (i)=(x);(i)<=(int)(n);(i)++)
#define rrep(i,x) for(int i=((int)(x)-1);i>=0;i--)
using namespace std;
using ll = long long;
using Int = long long;

const int MOD = 1000000007;
const ll INF = numeric_limits<ll>::max();
const int inf = 1e8;
typedef pair<int,int> P;
typedef std::priority_queue<int> IntPrioQueue;
typedef std::priority_queue<int, std::vector<int>, std::greater<int> > IntReversePrioQueue;

//少数点表示
//cout << std::fixed << std::setprecision(14) << 値

int main(){
    cin.tie( 0 ); ios::sync_with_stdio( false );
    int k,x;
    cin >> k >> x;
    rep1eq(i,x-(k-1),x+(k-1)){
        cout << i << " ";
    }
    return 0;

}

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

int main(){
	int n,k;
	cin>>n>>k;
	vector<ll> a(n);
	rep(i,n)cin>>a[i];
	vector<int> ok(1<<n,1);
	rep(i,1<<n){
		ll sum=0;
		rep(j,n)if((1<<j)&i)sum+=a[j];
		if(sum==k)ok[i]=0;
	}
	rep(j,n)rep(i,1<<n)if((i&(1<<j))==0)ok[i|(1<<j)]&=ok[i];
	int ma=n;
	rep(i,1<<n){
		if(ok[i])ma=min(ma,n-__builtin_popcount(i));
	}
	cout<<ma<<endl;
	return 0;
}


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

int main() {
	int N;
	cin >> N;
	int MAX = 0, P = 0;
	for (int i = 0; i < N; i++) {
		int A, B;
		cin >> A >> B;
		if (A > MAX) {
			MAX = A;
			P = B;
		}
	}
	cout << MAX + P << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
   
   long K,A,B;
   
   scanf("%ld %ld %ld",&K,&A,&B);
   
   if(K < A + 1 || B - A <= 2){
      printf("%ld\n",K + 1);
      return 0;
   }
  
   long bisk = 1;
   
   while(K >= 1){

      if(bisk >= A && K - 2 >= 0){
         bisk = bisk - A + B;
         K = K - 2;
      }
      else {
         bisk = bisk + 1;
         K = K - 1;
      }
   }
   
   printf("%ld\n",bisk);
   
   return 0;
}


Measured memory_bytes: 128
def read():
    N = int(input().strip())
    S = list()
    T = list()
    for i in range(N):
        s, t = input().strip().split()
        s = str(s)
        t = int(t)
        S.append(s)
        T.append(t)
    X = str(input().strip())
    return N, S, T, X

def solve(N, S, T, X):
    start = S.index(X)
    return sum(T[start+1:])

if __name__ == '__main__':
    inputs = read()
    print("%d" % solve(*inputs))


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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    int a, b, h, m;
    cin >> a >> b >> h >> m;
    double rm = (double)m / 60.0 * 2 * PI;
    double rh = (double)(h*60+m) / 720.0 * 2 * PI;
    double xm = b*sin(rm), ym = b*cos(rm);
    double xh = a*sin(rh), yh = a*cos(rh);
    double dx = xm - xh, dy = ym - yh;
    double ans = sqrt(dx*dx+dy*dy);
    printf("%.10f\n", ans);
    return 0;
}


Measured memory_bytes: 4132
N = int(input())
S = input()

sameRangeRGBs = [0] * N
for itvl in range(1, (N-1)//2 + 1):
    for i in range(itvl, N - itvl):
        l = S[i-itvl]
        m = S[i]
        r = S[i+itvl]
        if l == m or m == r or r == l:
            continue
        sameRangeRGBs[i] += 1

accRL = [0]
accGL = [0]
accBL = [0]
numR = 0
numG = 0
numB = 0
for c in S:
    if c == 'R':
        numR += 1
    elif c == 'G':
        numG += 1
    elif c == 'B':
        numB += 1
    accRL.append(numR)
    accGL.append(numG)
    accBL.append(numB)

accRR = [0]
accGR = [0]
accBR = [0]
numR = 0
numG = 0
numB = 0
for c in S[::-1]:
    if c == 'R':
        numR += 1
    elif c == 'G':
        numG += 1
    elif c == 'B':
        numB += 1
    accRR.append(numR)
    accGR.append(numG)
    accBR.append(numB)

ans = 0
for i in range(N):
    c = S[i]
    if c == 'R':
        ans += accGL[i] * accBR[N-1-i] + accBL[i] * accGR[N-1-i] - sameRangeRGBs[i]
    elif c == 'G':
        ans += accRL[i] * accBR[N-1-i] + accBL[i] * accRR[N-1-i] - sameRangeRGBs[i]
    elif c == 'B':
        ans += accGL[i] * accRR[N-1-i] + accRL[i] * accGR[N-1-i] - sameRangeRGBs[i]
print(ans)

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

//----------素因数分解----------
vector<ll> prime_factorization(ll n){
  vector<ll> factors(n+1,0);
  rep3(i,n+1){
    if(i<=1) continue;
    while(n%i==0){
      n/=i;
      factors[i]++;
    }
  }
  return factors;
}

int main() {
  ll x,k,d;
  cin>>x>>k>>d;
  if(abs(x)%d==0){
    ll p=abs(x)/d;
    if(k>p){
      x=0;
      k-=p;
    }
    else{
      cout<<abs(x)-k*d<<endl;
      return 0;
    }
  }
  rep3(i,k){
    if(abs(x+d)<=abs(x-d)){
      x+=d;
    }
    else{
      x-=d;
    }
    if(abs(x)<=abs(d)){
      if((k-1-i)%2==0){
        cout<<abs(x)<<endl;
        return 0;
      }
      else{
        cout<<abs(d)-abs(x)<<endl;
        return 0;
      }
    }
  }
  cout<<abs(x)<<endl;
  return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define int long long
int mod = 1e9 + 7;
int INF = 2e18;

signed main() {
    int N;
    cin >> N;
    vector<int> student(N + 1);
    for (int i = 1; i <= N; i++) {
        int A;
        cin >> A;
        student[A] = i;
    }
    for (int i = 1; i <= N; i++) {
        if (i != N) cout << student[i] << " ";
        else cout << student[i] << endl;
    }

    return 0;
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int mod = 998244353;

long long mod_pow(long long x, long long n){
	if(n == 0) return 1;
	long long res = mod_pow(x*x % mod, n / 2);
	if(n & 1) res = res*x % mod;
	return res;
}

const int MAX_NUM = 200010;
long long fact[MAX_NUM], inv[MAX_NUM];

long long comb(long long n, long long k){
	if(n < k || n < 0 || k < 0) return 0;
	if(fact[0] == 0){
		fact[0] = 1; inv[0] = 1;
		for(int i = 1; i < MAX_NUM; i++){
			fact[i] = fact[i - 1] * i % mod;
			inv[i] = mod_pow(fact[i], mod - 2);
		}
	}
	return (((fact[n] * inv[k]) % mod) * inv[n - k]) % mod; 
}

long long hcomb(long long n, long long k){
	if(n == 0 && k == 0) return 1;
	return comb(n + k - 1, k);
}

signed main(){
	int K, N;
	cin >> K >> N;
	for(int i = 2; i <= 2 * K; i++){
		int ans = 0;
		int n = min(i, 2 * K + 2 - i) / 2;
		for(int j = 1; j <= n; j++){
			ans = (ans + (j % 2 ? 1 : -1) * hcomb(K, N - 2 * j) * comb(n, j) % mod + mod) % mod;
		}
		ans = (hcomb(K, N) - ans + mod) % mod;
		cout << ans << endl;
	}
}

Measured memory_bytes: 3456
#include <bits/stdc++.h>
typedef long long       ll;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define pb                push_back
#define mp                make_pair
#define all(a)            (a).begin(), (a).end()
#define clr(a,h)          memset(a, (h), sizeof(a))
#define fore(i, b, e)      for(int i = b; i < e; i++)
#define forr(i, b, e)      for(int i = b; i < e; i++)
#define forg(i, b, e, m)  for(int i = b; i < e; i+=m)
#define F first
#define S second
int faster_in(){int r=0,c;for(c=getchar();c<=32;c=getchar());if(c=='-') return -faster_in();for(;c>32;r=(r<<1)+(r<<3)+c-'0',c=getchar());return r;}

using namespace std;
//using namespace __gnu_pbds;

typedef pair<int, int>  ii;
typedef pair<int, ii>  iii;
typedef vector<int>     vi;

typedef vector<ii>      vii;
typedef vector<ll>      vll;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
const int INF = int(1e9 + 7);
const double PI = acos(-1);
const double EPS = 1e-9;
int val[3][3];
int mapa[11000];
int bo[3][3];

int main()
{

    forr(i,0,3)
    {
        forr(j,0,3)
        cin>>val[i][j];
    }
    int n,valor;
    cin>>n;
    forr(i,0,n)
    {
        cin>>valor;
        mapa[valor]=1;
    }
    forr(i,0,3)
        forr(j,0,3)
        if (mapa[val[i][j]])
            bo[i][j]=1;
    int row,col,dig;
    row=col=dig=0;
    bool cond=0;
    forr(i,0,3)
    {
        row=col=0;
        forr(j,0,3)
        {
            row+=bo[i][j];
            col+=bo[j][i];
        }
        dig+=bo[i][i];
        if (row==3|| col==3)
            cond=1;
    }

    if (dig==3)
        cond=1;
    dig=bo[0][2]+bo[1][1]+bo[2][0];
    if (cond|| dig==3)
        cout<<"Yes\n";
    else
        cout<<"No\n";
}
// PLUS ULTRA!

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
    
    int a,b,c;
    char op;
    
for(;;){
    
   scanf("%d %c %d",&a,&op,&b);
   if(op=='+')
   printf("%d\n",a+b);
   else if(op=='-')
   printf("%d\n",a-b);
   else if(op=='*')
   printf("%d\n",a*b);
   else if(op=='/')
   printf("%d\n",a/b);

  else if(op=='?')
  break;
}
    return(0);
    
}



Measured memory_bytes: 2056
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

void main()
{
    auto N = readln.chomp.to!int;
    auto as = readln.split.to!(ulong[]);

    ulong x = as[0];
    foreach (a; as[1..$]) x ^= a;
    ulong[] res;
    foreach (a; as) res ~= a ^ x;
    writeln(res.to!(string[]).join(" "));
}

Measured memory_bytes: 23428
#include <bits/stdc++.h>
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = ((int)(n)-1); i >= 0; i--)
#define all(x) (x).begin(),(x).end()
 
using namespace std;
using ll = long long;
 
struct edge { int to, cost; };
 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> P;
 
const int INF = 1e9;
const double EPS = 1e-10;
const int MOD = 1e9+7;
const double PI = acos(-1.0);

const int mx4[] = {0,1,0,-1};
const int my4[] = {1,0,-1,0};
const int mx8[] = {0,1,1,1,0,-1,-1,-1};
const int my8[] = {1,1,0,-1,-1,-1,0,1};

class Comb{
private:
	vector<ll> fact;
	vector<ll> pow_mod;
public:
	Comb(int n){
		fact = vector<ll>(n+10);
		pow_mod = vector<ll>(n+10);
		for(int i = 0; i < n+10; i++) calc(i);
	}
	void calc(int i){
		//階乗計算
		if(i == 0) fact[i] = 1;
		else fact[i] = fact[i-1] * i % MOD;
		//pow_mod計算
		ll mod = MOD-2,res = 1,ti = i;
		while(mod > 0){
			if(mod&1) res = res*ti%MOD;
			ti = ti * ti % MOD;
			mod >>= 1;
		}
		if(i == 0) pow_mod[i] = 1;
		else pow_mod[i] = pow_mod[i-1]*res%MOD;
	}
	ll nCr(int n,int r){
		if(n < r) return 0;
 		ll a1 = fact[n],a2 = pow_mod[n-r],a3 = pow_mod[r];
		return a1*a2%MOD*a3%MOD;
	}
};

int main()
{
	int n,k;
	cin >> n >> k;
	Comb comb(n+10);
	for(int i = 1; i <= k; i++){
		cout << comb.nCr(n-k+1,i)*comb.nCr(k-1,i-1)%MOD << endl;
	}
	return 0;
}

Measured memory_bytes: 256