akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

#define MOD 1000000007
class mll {
	unsigned long long val = 0;
public:
	mll(long long y = 0) : val(((y % MOD) + MOD) % MOD) {}
	mll operator + (const mll& y) { return mll(*this) += y; }
	mll& operator += (const mll& y) {
		val = (val + y.val) % MOD;
		return *this;
	}
	mll operator - (const mll& y) { return mll(*this) -= y; }
	mll& operator -= (const mll& y) {
		val = (val - y.val + MOD) % MOD;
		return *this;
	}
	mll operator * (const mll& y) { return mll(*this) *= y; }
	mll& operator *= (const mll& y) {
		val = (val * y.val) % MOD;
		return *this;
	}
	mll operator / (const mll& y) { return mll(*this) /= y; }
	mll& operator /= (const mll& y) {
		long long a = y.val, b = MOD, u = 1, v = 0;
		while (b) {
			long long t = a / b;
			a -= t * b; swap(a, b);
			u -= t * v; swap(u, v);
		}
		val = (((val * u) % MOD) + MOD) % MOD;
		return *this;
	}
	bool operator >= (const mll& y) {
		return this->val >= y.val;
	}
	mll pow(long long t) const {
		if (!t) return 1;
		mll a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}
	unsigned long long getVal() {
		return val;
	}
	friend ostream& operator <<(ostream& os, mll& y) {
		os << y.val;
		return os;
	}
};
#undef MOD


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

	ll N, K;
	cin >> N >> K;

	mll c = 0;
	for (ll i = K; i <= N + 1; i++) { // kosu
		c += (N * (N + 1) / 2 - (N - i)*(N + 1 - i) / 2) - (i * (i - 1)) / 2 + 1;
	}
	cout << c.getVal() << endl;
}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
#define inf 1000000000
#define INF 1000000000000000
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
void init(){
  cin.tie(0);
  ios::sync_with_stdio(false);
}


main(){
  int n;
  int d[110][110];
  rep(i,110){
    rep(j,110){
      d[i][j]=-1;
    }
  }

  cin>>n;
  int a=-1,b=-1,c=-1;

  rep(i,n){
    int x,y,h;
    cin>>x>>y>>h;
    if(a==-1&&h!=0){
      a=x;b=y;c=h;
    }
    d[x][y]=h;
  }

  rep(cx,101){
    rep(cy,101){
      int h=c+abs(cx-a)+abs(cy-b);
      //if(cx==2&&cy==2) cout<<h<<endl;
      bool flag=true;
      rep(i,101){
        rep(j,101){
          if(d[i][j]==-1) continue;
          if(d[i][j]!=max(0LL,h-abs(cx-i)-abs(cy-j))){
            //if(cx==2&&cy==2)cout<<i<<' '<<j<<endl;
            flag=false;
          }
        }
      }
      if(flag){
        cout<<cx<<' '<<cy<<' '<<h<<endl;
        return 0;

      }
    }
  }

}


Measured memory_bytes: 384
N = gets.to_i
As = gets.split.map(&:to_i)

l, r, t, c = 0, 0, 0, 0
while r < N
  a = As[r]
  if t + a == t ^ a
    t += a
    c += r - l + 1
    r += 1
  else
    t -= As[l]
    l += 1
  end
end
puts c

Measured memory_bytes: 15364
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
using namespace std;

typedef istringstream ISS;
typedef ostringstream OSS;
typedef vector<string> VS;
typedef int INT;
typedef vector<INT> VI;
typedef vector<VI> VVI;
typedef pair <INT, INT> II;
typedef vector <II> VII;

template<class T> ostream& operator << ( ostream& os, vector<T> v ) {
    for ( typename vector<T>::iterator it_i = v.begin(); it_i != v.end(); ++it_i ) {
        os << *it_i << ", ";
    }
    return os;
}


const int SIZE = 1000000;
int X[SIZE], Y[SIZE], H[SIZE], W[SIZE];
int n;

long long solve() {
    long long res = 0;
    for ( int i = 0; i < n; ++ i ) {
        int s = X[i] + Y[i] + H[i];
        if ( s <= 60 && W[i] <= 2 ) {
            res += 600;
        } else if ( s <= 80 && W[i] <= 5 ) {
            res += 800;
        } else if ( s <= 100 && W[i] <= 10 ) {
            res += 1000;
        } else if ( s <= 120 && W[i] <= 15 ) {
            res += 1200;
        } else if ( s <= 140 && W[i] <= 20 ) {
            res += 1400;
        } else if ( s <= 160 && W[i] <= 25 ) {
            res += 1600;
        }
    }
    return res;
}

int main() {
    while ( cin >> n && n ) {
        for ( int i = 0; i < n; ++ i ) {
            cin >> X[i] >> Y[i] >> H[i] >> W[i];
        }
        cout << solve() << endl;
    }
    return 0;
}

Measured memory_bytes: 0
mod = 1000000007
eps = 10**-9


def main():
    import sys
    input = sys.stdin.readline

    N = int(input())
    S = input().rstrip('\n')
    S = [s for s in S]

    l = 0
    r = N-1
    ans = 0
    while True:
        if l >= r:
            break
        if S[l] == "W" and S[r] == "R":
            S[l], S[r] = S[r], S[l]
            ans += 1
            l += 1
            r -= 1
        elif S[l] == "W" and S[r] == "W":
            r -= 1
        elif S[l] == "R" and S[r] == "R":
            l += 1
        else:
            l += 1
            r -= 1
    print(ans)


if __name__ == '__main__':
    main()


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

int main()
{
	int n, a;
	cin >> n;
	vector<int> v;
	for (int i = 0; i < n; i++) {
		cin >> a;
		a--;
		v.push_back(a);
	}
	int now = 0, c = 0;
	while (1) {
		if (now == 1) {
			cout << c << endl;
			break;
		}
		if (c >= n) {
			cout << -1 << endl;
			break;
		}
		c++;
		now = v[now];
	}
	return 0;
}

Measured memory_bytes: 892
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
#define endl "\n"
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();
// freopen("input.txt", "r", stdin);

int main() {
    string s1, s2;
    cin >> s1 >> s2;
    reverse(s1.begin(), s1.end());
    if (s1 == s2)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 3608
#include <cstdio>
#define MOD 998244353
typedef long long ll; 
inline ll quick_pow(ll a, int n)
{
	ll res = 1; 
	while (n)
	{
		if (n & 1)
			res = res * a % MOD; 
		a = a * a % MOD; 
		n >>= 1; 
	}
	return res;
}
ll fact[300005], inv[300005], dp[100005], ans; 
inline ll C(int n, int m)
{
	if (n == -1 && m == -1)
		return 1; 
	if (n < 0 || m < 0)
		return 0; 
	return fact[n] * inv[m] % MOD * inv[n - m] % MOD; 
}
inline void work(int n, int m, char *a, char *b, char *c, char *d)
{
	int a1 = 0, b1 = 0, c1 = 0, d1 = 0; 
	for (int i = 0; i < n; i++)
	{
		a1 += a[i] == '1'; 
		b1 += b[i] == '1'; 
	}
	for (int i = 0; i < m; i++)
	{
		c1 += c[i] == '1'; 
		d1 += d[i] == '1'; 
	}
	if (!a1 && !b1 && !c1 && !d1)
	{
		ans = 1; 
		return; 
	}
	c1 = d1 = 0; 
	for (int i = 0; i < m; i++)
	{
		dp[i] = i ? dp[i - 1] : 0; 
		if (c[i] == '1' || d[i] == '1')
			(dp[i] += C(c1 + d1 + a1 - 1, a1 - 1)) %= MOD; 
		if (c[i] == '1' && d[i] == '1')
			(dp[i] += dp[i]) %= MOD; 
		c1 += c[i] == '1'; 
		d1 += d[i] == '1'; 
	}
	c1 = d1 = 0; 
	for (int i = m - 1; i >= 0; i--)
	{
		if (c[i] == '1' || d[i] == '1')
			(ans += dp[i] * C(c1 + d1 + b1 - 1, b1 - 1)) %= MOD; 
		c1 += c[i] == '1'; 
		d1 += d[i] == '1'; 
	}
}
char a[100005], b[100005], c[100005], d[100005]; 
int main()
{
	// freopen("CF17-QA-E.in", "r", stdin); 
	int n, m;
	scanf("%d%d%s%s%s%s", &n, &m, a, b, c, d); 
	fact[0] = inv[0] = 1; 
	for (int i = 1; i <= 3e5; i++)
	{
		fact[i] = fact[i - 1] * i % MOD; 
		inv[i] = quick_pow(fact[i], MOD - 2); 
	}
	work(n, m, a, b, c, d);
	work(m, n, c, d, a, b);
	printf("%lld\n", ans);
	return 0; 
}


Measured memory_bytes: 6016
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtTest.HCPC2019_10
{
    class A
    {
        static void Main(string[] args)
        {
            Method(args);
        }

        static void Method(string[] args)
        {
            long n = ReadLong();
            if(n==0)
            {
                WriteLine(0);
                return;
            }
            long div = 2;
            long res = 1;
            while (div <= n)
            {
                div *= 2;
                res++;
            }
            WriteLine(res);
        }

        private static string Read() { return ReadLine(); }
        private static char[] ReadChars() { return Array.ConvertAll(Read().Split(), a => a[0]); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}



Measured memory_bytes: 15988
def main():
    import collections
    S = input()
    T = input()
    N = len(S)
    table = collections.defaultdict(int)
    table2 = collections.defaultdict(int)
    flag = True
    for i in range(N):
        x = S[i]
        y = T[i]

        if x in table:
            if y == T[table[x]]:
                continue
            else:
                flag = False
                break
        else:
            if y in table2:
                flag = False
                break
            table[x] = i
            table2[y] = i

    if flag:
        print("Yes")
    else:
        print("No")


main()


Measured memory_bytes: 4016
#include<cstdio>
using namespace std;
int main()
{
	int i,k,x,a;
	scanf("%d %d",&k,&x);
	k-=1;
	a=x-k;
	printf("%d",a);
	for(i=a+1;i<=x+k;i++){
		printf(" %d",i);
	}
	printf("\n");
	return 0;
}


Measured memory_bytes: 128
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
S = "abcdefghijk"

# q = [("", -1)]
ans = 0

def dfs(a, mx):
    # q = [(cur, mx)]
    # while q:
    # a, mx = q.pop()
    if len(a) == N:
        print(a)
        return
    for c in range(len(S[:mx+2])):
        t = a
        t += S[:mx+2][c]
        dfs(t, max(c, mx))

dfs("", -1)



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

#define INF 1 << 29
#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)

using namespace std;

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

void gen_sosuu(int sosuu[]){
  REP(i,100010){
    sosuu[i] = true;
  }
  sosuu[0] = false;
  sosuu[1] = false;
  sosuu[2] = true;
  FOR(i,2,sqrt(100000)+1){
    if(sosuu[i] == false) continue;
    for(int j = 2; i*j<=100000;j++){
      //printf("%d %d %d\n",i*j,i,j);
      sosuu[i*j] =false;
    }
  }
}

int n,k;
vector<int> vec;

int main(){
  scanf("%d %d",&n,&k);
  REP(i,n){
    int a;
    scanf("%d",&a);
    vec.push_back(a);
  }
  sort(vec.begin(),vec.end(),greater<int>());
  int sum=0;
  REP(i,k){
    sum+= vec[i];
  }
  printf("%d\n",sum);
}


Measured memory_bytes: 256
#include <iostream>

int main()
{
  int a, b, c;
  int counter = 0;

  std::cin >> a >> b >> c;

  for (int i = a; i <= b; i++)
  {
    if (c % i == 0)
    {
      counter++;
    }
  }

  std::cout << counter << std::endl;
}



Measured memory_bytes: 3116
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Jaynil
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BTAKOYAKIFESTIVAL2019 solver = new BTAKOYAKIFESTIVAL2019();
        solver.solve(1, in, out);
        out.close();
    }

    static class BTAKOYAKIFESTIVAL2019 {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int a[] = new int[n];
            long ans = 0;
            for (int i = 0; i < n; i++) a[i] = in.nextInt();
            for (int i = 0; i < n; i++)
                for (int j = i + 1; j < n; j++)
                    ans += a[i] * a[j];

            out.println(ans);
        }

    }

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

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

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

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



Measured memory_bytes: 21588
n = int(input())
ans = n
for i in range(n+1):
    ansk = 0
    s = i
    while s>0:
        x = s % 6
        ansk += x
        s = s // 6
    s = n - i
    while s>0:
        x = s % 9
        ansk += x
        s = s // 9
    ans = min(ans,ansk)
print(ans)

Measured memory_bytes: 3064
//{{{
#include <bits/stdc++.h>
using namespace std;
#define rep(...) repN((__VA_ARGS__,rep3,rep2,loop,~))(__VA_ARGS__)
#define rrep(...) repN((__VA_ARGS__,rrep3,rrep2,loop,~))(__VA_ARGS__)
#define loop(n) rep2(_loop_,n)
#define rep2(i,n) rep3(i,0,n)
#define rep3(i,begin,end) for(int i=(int)(begin),i##_end=(int)(end);i<i##_end;++i)
#define rrep2(i,n) rrep3(i,n,0)
#define rrep3(i,begin,end) for(int i=(int)(begin-1),i##_end=(int)(end);i>=i##_end;--i)
#define repN(a) repX a
#define repX(a0,a1,a2,x,...) x
#define foreach(x,a) for(auto &x:a)
using ll=long long;
const ll MOD = (ll)1e9+7;
//}}}

int main(){
  string s;
  cin >> s;
  string s0 = "CODEFESTIVAL2016";
  int ans = 0;
  rep(i, s.size()) ans += s[i] != s0[i];
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>

// 深さ優先探索
// Depth First Search(DFS)
// 可能な限り隣接する頂点を訪問する

using namespace std;

const int N_MAX = 100;

enum ColorStatus
{
    WHITE_no_visit,
    GRAY_visit,
    BLACK_finished,
};

struct Node
{
   ColorStatus color;
   // 最初の訪問時刻
   int discoverTime;
   // 訪問完了時刻
   int finishTime;
};

int n; // 頂点数
int M[N_MAX][N_MAX] = { 0 };
Node nodes[N_MAX] = { WHITE_no_visit, 0, 0 };
int times = 0;

// 引数の頂点uを始点にして、深さ探索
// 頂点u->頂点v
void depthFirstSearch(int u)
{
    int v;

    nodes[u].color = GRAY_visit; // 頂点uに訪れた
    nodes[u].discoverTime = ++times; // 訪問時刻のタイムスタンプ
    // 行先頂点v
    for (int v = 0; v < n; v++)
    {
        if (M[u][v] == 0) continue;
        if (nodes[v].color == WHITE_no_visit)
            depthFirstSearch(v);
    }
    nodes[u].color= BLACK_finished; // 頂点uを訪問し終えた。
    nodes[u].finishTime = ++times;
}

void init()
{
    for (int u = 0; u < n; u++)
        if (nodes[u].color == WHITE_no_visit)
            depthFirstSearch(u);

    // 出力
    // 頂点番号 発見時刻 完了時刻
    for (int u = 0; u < n; u++)
    {
        cout << u + 1 << " " << nodes[u].discoverTime << " " << nodes[u].finishTime << endl;
    }

}



int main(int argc, char *argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    cin >> n;
    for (int i = 0; i < n; i++)
    {
        int u;
        int k;
        cin >> u; // 頂点番号
        cin >> k; // 出自数
        for (int j = 0; j < k; j++)
        {
            int v;
            cin >> v;
            M[u-1][v-1] = 1;
        }
    }

    init();


    return 0;
}


Measured memory_bytes: 3184
import sys
c = []
for _ in range(3):
    c.append(map(int, raw_input().split()))
for i in range(3):
    for j in range(i):
        for k in range(3):
            for l in range(k):
                if not abs(c[k][i] - c[k][j]) == abs(c[l][i] - c[l][j]) or \
                   not abs(c[i][k] - c[j][k]) == abs(c[i][l] - c[j][l]):
                       print "No"
                       sys.exit()
print "Yes"




Measured memory_bytes: 2568
x = int(input())

poypoyo = 'po'
for i in range(10000):
    for j in range(10000):
        if i**5 - j**5 == x:
            print(i,j)
            quit()
            break
        if i**5 - (-j)**5 ==x:
            print(i,-j)
            quit()
            break
        po = 'po'
        poypoyo += po



Measured memory_bytes: 11140
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>

int main(){
  int a,b,c;

  scanf("%d %d %d", &a, &b, &c);
  if(a + b + c < 22) printf("win\n");

  else printf("bust\n");

  return 0;  
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int a,b,c,d,e,f,s1,s2,s3,s,p,i;
int main() {
	while(1){
		s=0;
		cin>>a>>b>>c>>d>>e>>f;
		s1=a+d;
		s2=b+e;
		s3=c+f;
		if(s1+s2+s3==0){break;}
		p=min(s1,min(s2,s3));
		for(i=max(0,p-9);i<=p;i++){
			s=max(s,i+(s1-i)/3+(s2-i)/3+(s3-i)/3);
		}
		cout<<s<<endl;
	}
}

Measured memory_bytes: 1160
s = input('')
t = input('')

slen = len(s)
tlen = len(t)

sone = ''

small = 0

if slen != tlen:
    for i in range(slen-tlen):
        sone = s[i:i+tlen]
        count = 0
        for e in range(tlen):
            if sone[e] != t[e]:
                count = count + 1
        if i == 0:
            small = count
        else:
            if count <= small:
                small = count
else:
    sone = s
    count = 0
    for e in range(tlen):
        if sone[e] != t[e]:
            count = count + 1
    small = count

print(small)


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

int main(){
 int N;
  cin >>N;
  vector<int> a(N);
  for(int i=0;i<N;i++){
    cin >> a[i];
  }
  
  int b=a[0],ans=0;
  for(int i=0;i<N;i++){
    if(a[i]<=b){
      ans++;
    }
    b=min(b,a[i]);
  }
  cout << ans <<endl;
}

Measured memory_bytes: 4012
#include <iostream>
#include <string>

using namespace std;
using ll = long long;

bool like_coffee(const string& str) {
  return str[2]==str[3] && str[4] == str[5]; 
}

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

  cout << (like_coffee(str) ? "Yes" : "No") << endl;
  return 0;
}


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

int N,K;
int fid[3010][3010];
int ans = 0;
int B[1010][1010],W[1010][1010];

int main()
{
    scanf("%d%d",&N,&K);
    for(int i = 0; i < N; i++)
    {
        int x,y;
        char c;
        scanf("%d%d %c",&x,&y,&c);
        if(c == 'B')y += K;
        x %= 2 * K;
        y %= 2 * K;
        fid[x][y]++;
        fid[x + K][y]--;
        fid[x][y + K]--;
        fid[x + K][y + K]++;
    }

    for(int i = 0; i < K * 3; i++)
    {
        for(int j = 0; j < K * 3; j++)
        {
            fid[i][j + 1] += fid[i][j];
        }
    }
    for(int i = 0; i < K * 3; i++)
    {
        for(int j = 0; j < K * 3; j++)
        {
            fid[i + 1][j] += fid[i][j];
            ans = max(ans,fid[i][j]);
        }
    }
    for(int i = 0; i < K * 3; i++)
    {
        for(int j = 0; j < K * 3; j++)
        {
            if((i / K + j / K) % 2)
            {
                B[i % K][j % K] += fid[i][j];
                ans = max(ans,B[i % K][j % K]);
            }
            else
            {
                W[i % K][j % K] += fid[i][j];
                ans = max(ans,W[i % K][j % K]);
            }
        }
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 43520
#include <iostream>
#include <queue>
#include <string>
#include <map>

using namespace std;

map<string, char> rule = { 
	{"rb", 'g'},
	{"br", 'g'},
	{"rg", 'b'},
	{"gr", 'b'},
	{"gb", 'r'},
	{"bg", 'r'} };

bool isjudge(string s){
	bool r = true;
	char c = s[0];
	for(int i = 0;i < s.length();++i){
		r &= (c == s[i]);
	}
	return r;
}

int bfs(string s){
	queue<string> q;
	map<string, int> v;
	v[s] = 0;
	q.push(s);
	while(!q.empty()){
		string t = q.front(), n;
		char c;
		q.pop();
		if(isjudge(t)) return v[t];
		for(int i = 0;i < (t.length() - 1);++i){
			if(t[i] != t[i + 1]){
				n = t;
				c = rule[t.substr(i, 2)];
				n[i] = n[i + 1] = c;
				if(v.count(n) == 0){
					q.push(n);
					v[n] = v[t] + 1;
				}
			}
		}
	}
	return -1;
}

int main(){
	string s;
	int c;
	while(cin >> s){
		if(s == "0") break;
		else {
			c = bfs(s);
			if(c == -1) cout << "NA" << endl;
			else cout << c << endl;
		}
	}
	return 0;
}



Measured memory_bytes: 4712
#include <iostream>
#include <queue>
#include <algorithm>
#include <cstdio>

using namespace std;

#define loop(i, n) for (int i = 0; i < n; i++) 
#define INF 1010001000

typedef pair<int, int> i_i;

int dijk(int st, int en, vector<vector<int> > &g);

int n, m;

int main()
{
    while (cin >> n >> m, (n|m)) {
        vector<vector<int> > g(n+1, vector<int>(n+1, INF));
        loop(i, m) {
            int cmd;
            cin >> cmd;
            if (cmd) {
                int a, b, c;
                cin >> a >> b >> c;
                g[a][b] = min(g[a][b], c);
                g[b][a] = min(g[a][b], c);
            } else {
                int a, b;
                cin >> a >> b;
                int ans = dijk(a, b, g);
                cout << ((ans != INF) ? ans : -1) << endl;
            }
        }
    }
    return 0;
}

int dijk(int st, int en, vector<vector<int> > &g)
{
    priority_queue<i_i, vector<i_i>, greater<i_i> > pq;
    vector<int> ans(n+1, INF);
    ans[st] = 0;
    pq.push(i_i(0, st));
    while (!pq.empty()) {
        i_i tmp = pq.top(); pq.pop();
        //cout << tmp.second << endl;
        for (int i = 1; i < n+1; i++) {
            if (ans[i] > tmp.first + g[tmp.second][i]) {
                ans[i] = tmp.first + g[tmp.second][i];
                pq.push(i_i(ans[i], i));
                //cout << ans[i] << " " << i << endl;
            }
        }
    }
    return ans[en];
}

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


int main(void){
    // Your code here!
    int n;
    string s;
    cin>>n;
    cin>>s;
    
    if(s.size()<=n) cout<<s<<endl;
    else {
        cout<<s.substr(0,n);
        cout<<"..."<<endl;
    }
}


Measured memory_bytes: 3632
import sys
stdin = sys.stdin

mod = 10**9 + 7

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))

n, k = na()
h = list()
for _ in range(n):
    h.append(ni())
h.sort()
inf = 10**10
ans = inf
for i in range(n - k + 1):
    ans = min(ans, h[k+i-1]-h[i])
print(ans)


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

int main(){
  int n;  cin >> n;
  vector<int> d(n);
  for(int i=0; i<n; i++)
    cin >> d[i];

  sort(d.begin(), d.end());

  int ans = 0, idx = 0;
  while(idx < n){
    while(d[idx] == d[idx+1])  idx++;
    ans++;
    idx++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int main(){

    string s;
    cin>>s;
    int sz = (int)s.size();

    if(s=="keyence"){
        cout<<"YES\n";
        return 0;
    }

    for(int i=0;i<sz;i++){
        for(int j=i;j<sz;j++){
            string aux="";
            for(int l=0;l<i;l++){
                aux+=s[l];
            }
            for(int l=j+1;l<sz;l++){
                aux+=s[l];
            }
            if(aux == "keyence"){
                cout<<"YES\n";
                return 0;
            }
        }
    }
    cout<<"NO\n";
    return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  long long a, b, c, k;
  cin >> a >> b >> c >> k;
  if (k % 2 == 0) {
    cout << a - b << endl;
  } else {
    cout << b - a << endl;
  }
  return 0;
}

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

typedef long long ll;

#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define tt int t; cin>>t; while(t--)
#define nl cout<<"\n";
#define sp cout<<" ";
#define rep(i, a, b) for(long long i=a; i<b; i++)

const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
double PI = 4*atan(1);

int main()
{
    optimize();

    ll n;
    cin>> n;

    cout << (n * (n-1))/2;
    nl;


    return 0;
}




Measured memory_bytes: 3612
#include <iostream>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
using namespace std;

#ifdef DEBUG
    #define IFD if(true)
#else
    #define IFD if(false)
#endif

int main()
{
    int n;
    int p[20];
    int ans = 0;

    cin >> n;
    rep(i, n) {
        cin >> p[i];
    }
    rep(i, n - 2) {
        if(p[i] <= p[i + 1] && p[i + 1] < p[i + 2]) {
            ans++;
        } else if(p[i] > p[i + 1] && p[i + 1] >= p[i + 2]) {
            ans++;
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline

def solve():
    INF = float('inf')

    N = int(input())
    Ls = []
    Rs = []
    for _ in range(N):
        x, y = map(int, input().split())
        if x > y:
            x, y = y, x
        Ls.append(x)
        Rs.append(y)

    minAll = min(Ls)
    maxAll = max(Rs)

    ans1 = (max(Ls)-minAll) * (maxAll-min(Rs))

    ans2 = INF
    LRs = []
    min1, max1 = INF, -INF
    for L, R in zip(Ls, Rs):
        if L != minAll:
            if R != maxAll:
                LRs.append((L, R))
            else:
                min1 = min(min1, L)
                max1 = max(max1, L)
        else:
            if R != maxAll:
                min1 = min(min1, R)
                max1 = max(max1, R)
            else:
                print(ans1)
                return

    if not LRs:
        print(ans1)
        return

    LRs.sort()

    d1 = maxAll - minAll
    maxL = LRs[-1][0]
    minR, maxR = INF, -INF
    ans2 = INF
    for L, R in LRs:
        minL = L
        diff = max(maxL, maxR, max1) - min(minL, minR, min1)
        ans2 = min(ans2, d1*diff)
        minR = min(minR, R)
        maxR = max(maxR, R)

    minL, maxL = INF, -INF
    diff = max(maxL, maxR, max1) - min(minL, minR, min1)
    ans2 = min(ans2, d1*diff)

    print(min(ans1, ans2))


solve()


Measured memory_bytes: 34088
#include <iostream>
#include<cstdio>
#include<stdio.h>
using namespace std;

int main() {
	int a, b, c;
	char grade;
	while (true) {

		cin >> a >> b >>c;


		if (a == -1 && b == -1 && c == -1) {
			break;
		}


		if (a + b < 30 || a==-1 || b==-1) {
			grade = 'F';
		}
		else if (a + b >= 30 && 50 > a + b) {
			grade = (c>=50)? 'C' : 'D';

		}
		else if (a + b >= 50 && 65 > a + b) {
			grade = 'C';
		}

		else if (a + b >= 60 && 80>a + b) {
			grade = 'B';
		}

		else if (a + b >= 80) {
			grade = 'A';
		}

		cout << grade << endl;
		
	}



	return 0;
}




Measured memory_bytes: 3096
def main():
    n, k = map(int, input().split())
    x = [int(i) for i in input().split()]
    x.sort()
    answer = float("inf")
    if n == k:
        if n == 1:
            answer = abs(x[0])
        if 0 <= x[0]:
            answer = x[-1]
        elif x[-1] <= 0:
            answer = abs(x[0])
        else:
            answer = x[-1] - x[0] + min(abs(x[-1]), abs(x[0]))
    else:
        for i in range(n - k + 1):
            left = x[i]
            right = x[i + k - 1]
            if left * right >= 0:
                answer = min(answer, max(abs(left), abs(right)))
            else:
                answer = min(answer, right - left + min(abs(left), abs(right)))
    print(answer)


if __name__ == '__main__':
    main()



Measured memory_bytes: 14128
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
#include <utility>
#include <tuple>
#include <map>
#include <ctime>
#include <cstdlib>
#include <random>
using namespace std;

string s,t;
int a,b;
string u;

int main(){
	cin>>s>>t;
	cin>>a>>b>>u;
	if(s==u)a--;
	else b--;
	cout << a << " " <<b<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < (int)(n); i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
using ll = long long;

int main() {
    int N; cin >> N;
    cout << fixed << setprecision(15);
    cout << (double)((N + 1) / 2) / N << endl;
    return 0;
}

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

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define INF  numeric_limits<int>::max()
#define NINF numeric_limits<int>::min()

using namespace std;
using ll = long long;

int N, K;
string S;

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

    std::cin >> N >> K;
    std::cin >> S;

    S[K-1] = S[K-1] + 32;
    std::cout << S << std::endl;

    return 0;
}


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

#define pb push_back
#define int long long

int32_t main() {
	int n,ans;
	string s;
	vector<int> R,G;
	map<int,bool> B;
	
	cin>>n;
	cin>>s;
	for(int i = 0;i < n;i++)
	{
		if(s[i] == 'R')
		{
			R.pb(i);
		}
		else
		if(s[i] == 'G')
		{
			G.pb(i);
		}
		else
		{
			B[i] = 1;
		}
	}

	ans = R.size() * G.size() * B.size();
	for(auto i:R)
	{
		for(auto j:G)
		{
			if( ((i+j)%2 == 0) && B[(i+j)/2])
			{
				ans--;
			}
			
			if( B[2*i-j])
			{
				ans--;
			}
			
			if(B[2*j-i])
			{
				ans--;
			}
		}
	}
	cout<<ans;
	return 0;
}

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

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

signed main(){

  int d;
  vector<int> c(26);
  cin>>d;
  for(auto& ci:c)cin>>ci;
  vector<vector<int>> s(d,vector<int>(26));
  for(auto& si:s)for(auto& sij:si)cin>>sij;

  auto calc_satisfaction_level = [&s,&c](int d,int i,auto last){
    int64_t res = s[d][i];
    for(int j=0;j<26;++j){
      if(i==j)continue;
      res -= c[j]*(d-last[j]+1);
    }
    return res;
  };

  //-----------------------------------------------------

  int k = 50;
  vector<vector<int>> last(k,vector<int>(26));
  vector<vector<int>> ans(k,vector<int>(d));
  vector<int64_t> top_k_val(k);

  auto test_all_get_max = [&](int di,auto last){
    // 日付を引数にして全てのコンテストタイプを試してmaxscoreになるタイプを返す
    // 上位k個を返す
    vector<pair<int,int>> valtype_max(26);
    for(int type=0;type<26;++type){
      valtype_max[type] = {calc_satisfaction_level(di,type,last),type};
    }
    sort(begin(valtype_max),end(valtype_max),greater<>());
    valtype_max.erase(begin(valtype_max)+k,end(valtype_max));
    assert(size(valtype_max)==k);
    return valtype_max;
  };

  rep(di,d){
    vector<tuple<int,int,int>> next_top_k;
    next_top_k.reserve(k*26);
    rep(ki,k){
      auto tmp = test_all_get_max(di,last[ki]);
      for(int i=0;i<26;++i)next_top_k.emplace_back(tmp[i].first+top_k_val[ki],tmp[i].second,ki);
    }
    sort(begin(next_top_k),end(next_top_k),greater<>());
    next_top_k.erase(begin(next_top_k)+k,end(next_top_k));
    vector<vector<int>> nxt_last(k,vector<int>(26));
    vector<vector<int>> nxt_ans(k,vector<int>(d));
    vector<int64_t> nxt_top_k_val(k);
    rep(i,k){
      auto [val,type,prv_ki] = next_top_k[i];
      nxt_last[i] = last[prv_ki];
      nxt_last[i][type] = di+1;
      nxt_ans[i] = ans[prv_ki];
      nxt_ans[i][di] = type;
      nxt_top_k_val[i] = val;
    }
    last = nxt_last;
    ans = nxt_ans;
    top_k_val = nxt_top_k_val;
  }

  //-----------------------------------------------------

  auto t = ans[0];
  auto l = last[0];
  auto v = top_k_val[0];
  int loop_cnt = 10000;
  random_device rnd;
  mt19937 mt(rnd());
  while(loop_cnt--){
    int di = mt()%d;
    int qi = mt()%26;
    auto nt = t;
    vector<int> nl(26);
    vector<int> nv(d);
    nt[di] = qi;
    rep(i,d){
      int64_t tmp = calc_satisfaction_level(i,t[i],nl);
      if(i==0)nv[i]=tmp;
      else nv[i]=nv[i-1]+tmp;
      nl[t[i]] = i+1;
    }
    if(nv.back()>v){
      return 1;
      v = nv.back();
      t = nt;
      l = nl;
    }
  }
  for(auto ti:t)cout<<ti+1<<endl;

}

Measured memory_bytes: 3868
#include<stdio.h>
#include<ctype.h>
 
int main(void)
{
    char ch;
     
    while(1) {
        scanf("%c", &ch);
        if(islower(ch)) printf("%c", toupper(ch));
        else if(isupper(ch)) printf("%c", tolower(ch));
        else printf("%c", ch);
         
        if(ch=='\n') break;
    }
     
    return 0;
}


Measured memory_bytes: 2056
n = gets.to_i
s = gets.chop
count = 0

("0".."9").each{ |i|
    id = 0
    id += 1 until s[id] == i or id == s.size - 1
    next if id == s.size - 1
    ("0".."9").each{ |j|
        id1 = id + 1
        id1 += 1 until s[id1] == j or id1 == s.size - 1
        next if id1 == s.size - 1
        ("0".."9").each{ |k|
            id2 = id1 + 1
            id2 += 1 until s[id2] == k or id2 == s.size - 1
            count += 1 if s[id2] == k
        }
    }
}
puts count

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

using namespace std;
 
//#define int long long
using ll = long long;
#define all(v) (v).begin(), (v).end()
#define rep(i,n) for(ll i=0;i<n;i++)
#define reps(i,n) for(ll i=0;i<=n;i++)

ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
 
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

int main(){
    ios_base::sync_with_stdio(false);
    ll k;
    string s;
    cin >> k >> s;
    if(s.size()<=k){
        cout << s << endl;
    }else{
        cout << s.substr(0,k)+"..." << endl;
    }
    return 0;
}


Measured memory_bytes: 3596
import math
A,B,H,M=map(int,input().split())
h=30*H+M/2
m=6*M
y=abs(h-m)
x_2=A*A+B*B-2*A*B*(math.cos(math.radians(y)))
x=x_2**(0.5)
print(x)

Measured memory_bytes: 9504
#include "bits/stdc++.h"
#include <math.h>
#include <time.h>
using namespace std;
const long long mod = 1000000007;
#define ll long long
#define P pair<int, int>
#define dump(x)                             \
    if (dbg) {                              \
        cout << #x << " = " << (x) << endl; \
    }
bool dbg = false;
long long gcd(long long a, long long b){
   if (a % b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a % b));
   }
}
long long lcm(long long a, long long b){
   return (a / gcd(a, b))* b;
}
//---------------------------------------------------------------------------------------------------
/*ここからいじる*/
//---------------------------------------------------------------------------------------------------

void solve(){
}
int main(){
    string s;
    cin >> s;
    vector<int>an(s.size() + 1);
    int num = 2019;
    ll cnt = 0;
    for(int i = 0; i < s.size() - 1; i++){
        int tmp = s.at(i) - '0';
        for(int j = i + 1; j < s.size(); j++){
            tmp *= 10;
            tmp += num;
            tmp += (s.at(j) - '0');
            tmp %= num;
            if(tmp == 0){
                an.at(i) = j;
                break;
            }
        }
    }
    ll ans = 0;
    for(int i = 0; i < s.size(); i++){
        if(an.at(i) == 0){
            continue;
        }
        int j = i;
        cnt = 1;
        while(true){
            if(an.at(an.at(j) + 1) == 0){
                ans += (cnt * (cnt + 1)) / 2;
                an.at(j) = 0;
                break;
            }
            cnt++;
            int tmp = an.at(j);
            an.at(j) = 0;
            j = tmp + 1;
        }

    }
    cout << ans << endl;
    solve();
    return 0;
}



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

int main() {
  int A,B,C;
  
  cin >> A >> B >> C;
  
 if(A<=B && B<=C){
    cout << A <<" "<< B <<" "<< C <<endl;
 }
 else if (A<=C && C<=B){
    cout << A <<" "<< C <<" "<< B <<endl;
 }
 else if (C<=A && A<=B){
    cout << C <<" "<< A <<" "<< B <<endl;
 }
 else if (C<=B && B<=A){
    cout << C <<" "<< B <<" "<< A <<endl; 
 }
 else if (B<=A && A<=C){
    cout << B <<" "<< A <<" "<< C <<endl;
 }
 else if (B<=C && C<=A){
    cout << B <<" "<< C <<" "<< A <<endl;
 }
}


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

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

	int ans = 0;
	
	for (int i = 0; i < s.size(); ) {

		int cnt = 0;
		for (int j = i; j < s.size(); j++) {
			
			if (s.at(j) == 'A' || s.at(j) == 'C' || s.at(j) == 'G' || s.at(j) == 'T') {
				cnt++;
			}
			else {
				break;
			}

		}

		i += max(1, cnt);

		ans = max(ans, cnt);

		if (i >= s.size() - 1) break;

	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>

int main(){
	
//	char c;
	int i,j;
	int cnt,restart;
	char str1[102]={0};
	char str1_b[204]={0};
	char str2[102]={0};
	
	j = 0;
	
	for(i=0; str1[i]!='\n'; i++){
		scanf("%c",&str1[i]);
		if(str1[i] == '\n'){
			break;
		}
	}

	strcpy(str1_b,str1);
	str1_b[i]='\0';
	strcat(str1_b,str1);
	cnt = i;

	for(i=0; str2[i]!='\n'; i++){
		scanf("%c",&str2[i]);
		if(str2[i] == '\n'){
			break;
		}
	}
	
	for(i=0; i<cnt*2; i++){
			//printf("cmp %c(%d) ⇔ %c(%d)",str1_b[i],i,str2[j],j);
			if(str1_b[i] == str2[j]){
				if(j == 0){
					restart = i;
				}
				if((str2[j+1] != '\n') && (str1_b[i+1] == str2[j+1])){
				//	printf(" →pass1\n");
					j++;
				}else if(str2[j+1] == '\n'){
				//	printf(" →pass2\n");
					printf("Yes\n");
					return 0;
				}else if(str1_b[i+1] != str2[j+1]){
				//	printf(" →pass3\n");
					i = restart;
					j = 0;
				}else{
				//	printf(" →pass4\n");
				}
			}else{
			//	printf(" →pass5\n");
				j = 0;
			}
	}
	printf("No\n");
	return 0;
}


Measured memory_bytes: 2100
def main():
    n, k = map(int, input().split())
    a = list(map(int, input().split()))

    num = 1
    l = []
    s = [1]*n

    while s[num-1]:
        l.append(num)
        s[num-1] = 0
        num = a[num-1]

    if l.index(num) <= k:
        l2 = l[l.index(num):]
        kk = (k-len(set(l)-set(l2)))%len(l2)
        print(l2[kk])
    else:
        print(l[k])

main()

Measured memory_bytes: 45976
#include <cstring>
#include <queue>
#include <algorithm>
#include <stdlib.h>
#include <iostream>
using namespace std;
int main(){
    char x[4];
    cin>>x;
    if(x[0]=='S'&&x[1]=='U')
        cout<<7;
    else if(x[0]=='M')
        cout<<6;
    else if(x[0]=='T'&&x[1]=='U')
        cout<<5;
    else if(x[0]=='W')
        cout<<4;
    else if(x[0]=='T'&&x[1]=='H')
        cout<<3;
            else if(x[0]=='F')
        cout<<2;
    else if(x[0]=='S'&&x[1]=='A')
        cout<<1;
return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){

  int h,A[251],i,j;

  scanf("%d",&h);

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

    scanf("%d",&A[i]);

  }

  for(j=1;j<=h;j++){

    if(j==1){
      printf("node %d: key = %d, left key = %d, right key = %d, \n",j,A[j],A[2*j],A[2*j+1]);
    }
    else if(2*j+1<=h){
      printf("node %d: key = %d, parent key = %d, left key = %d, right key = %d, \n",j,A[j],A[j/2],A[2*j],A[2*j+1]);
    }
    else if(2*j<=h){
      printf("node %d: key = %d, parent key = %d, left key = %d, \n",j,A[j],A[j/2],A[2*j]);
    }
    else printf("node %d: key = %d, parent key = %d, \n",j,A[j],A[j/2]);

  }
  
  return 0;
}

Measured memory_bytes: 596
//おまじない
//#include <bits/stdc++.h>
//#include <stdio.h>
#include <iostream>
//#include <math.h>
#include<iomanip>
#include <map>
#include <set>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#define INF 1e9+7
#define rep(i,n) for(int i=0;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<int,int>
#define space ' '
#define pll pair<ll,ll>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

//(int)'a'は97 (int)'A'は65 (int)'1'は49
//おまじない

const int maxn = 1000000;

int main(){
    
    string s;
    cin >> s;
    if(s=="SUN")cout << 7<<endl;
    if(s=="MON")cout << 6<<endl;
    if(s=="TUE")cout << 5<<endl;
    if(s=="WED")cout << 4<<endl;
    if(s=="THU")cout << 3<<endl;
    if(s=="FRI")cout << 2<<endl;
    if(s=="SAT")cout << 1<<endl;
    
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using static System.Console;
using static System.Math;
class Program
{

    void Solve()
    {
        var a = io.Double;
        var b = io.Double;
        var x = io.Double;

        var V = a * a * b;
        var ans =
            (
                x >= V / 2.0
                    ? Atan2(2 * (b - x / (a * a)), a)
                    : PI / 2.0 - Atan2(2.0 * x / (a * b), b)
            ) * 180.0 / PI;

        WriteLine(ans);
    }

    SimpleIO io = new SimpleIO();
    public static void Main(string[] args) => new Program().Stream();
    private void Stream()
    {
        //var exStdIn = new System.IO.StreamReader("stdin.txt");
        //SetIn(exStdIn);
        Solve();
        io.Flush();
    }
}

class SimpleIO
{
    string[] _nextBuffer;
    int _bufferCnt;
    char[] cs = new char[] { ' ', '"', ',' };
    StreamWriter sw = new StreamWriter(OpenStandardOutput())
    {
#if DEBUG
        AutoFlush = true
#else
        AutoFlush = false
#endif
    };
    public SimpleIO()
    {
        _nextBuffer = new string[0];
        _bufferCnt = 0;
        SetOut(sw);
    }
    string Next()
    {
        if (_bufferCnt < _nextBuffer.Length) return _nextBuffer[_bufferCnt++];
        var st = ReadLine();
        while (st == string.Empty) st = ReadLine();
        _nextBuffer = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        _bufferCnt = 0;
        return _nextBuffer[_bufferCnt++];
    }
    public string String => Next();
    public char Char => char.Parse(String);
    public int Int => int.Parse(String);
    public long Long => long.Parse(String);
    public double Double => double.Parse(String);
    public void Flush() => Out.Flush();
}

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

int main() {
    int N;
    cin >> N;
    vector<int> l(N), r(N);
    rep(i, N) {
        cin >> l.at(i);
        cin >> r.at(i);
    }

    int ans = 0;
    rep(i, N) {
        ans += r.at(i) - l.at(i) + 1;
    }

    cout << ans << endl;

    return 0;
}

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

ll solve() {
    ll N;
    cin >> N;
    vector<ll> A(N), B(N);
    for ( int i = 0; i < N; i++ ) cin >> A[i];
    for ( int i = 0; i < N; i++ ) cin >> B[i];
    priority_queue<pair<ll,int>> q;

    auto check = [&](int i) {
        ll x = B[i] - A[i] - B[(i+1)%N] - B[(i+N-1)%N];
        if ( x >= 0 ) {
            q.push(make_pair(x, i));
        }
    };
    for ( int i = 0; i < N; i++ ) {
        check(i);
    }
    ll ans = 0;
    while ( !q.empty() ) {
        auto p = q.top();
        q.pop();
        int i = p.second;
        if ( p.first != B[i] - A[i] - B[(i+1)%N] - B[(i+N-1)%N]) {
            check(i);
            continue;
        } 
        ll c = B[(i+1)%N] + B[(i+N-1)%N];
        ll n = (B[i] - A[i]) / c;
        B[i] -= n * c;
        ans += n;
        check((i+1)%N);
        check((i+N-1)%N);
    }

    for ( int i = 0; i < N; i++ ) {
        if ( A[i] != B[i] ) return -1;
    }
    return ans;
}

int main() {
    auto ans = solve();
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 5492
#include <bits/stdc++.h>
#define int long long
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
#define INF LLONG_MAX
#define eps LDBL_EPSILON
#define moder 100000
#define pie 3.141592653589793238462643383279
#define P std::pair<int,int>
#define prique priority_queue
#define ggr getchar();getchar();return 0
using namespace std;
int n,a;
vector<int> vec,ans;
signed main() {
	cin>>n;
	rep(i,n){
		cin>>a;
		vec.push_back(a);
	}
	while(!vec.empty()){
		for(int i=vec.size()-1;i>=0;i--){
			if(vec[i]==i+1){
				ans.push_back(i+1);
				vec.erase(vec.begin()+i);
				goto kaage;
			}
		}
		cout<<-1<<endl;
		return 0;
		kaage:;
	}
	reverse(ans.begin(),ans.end());
	for(int i:ans)cout<<i<<endl;
	ggr;
}


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


auto solve(long long A, long long B, long long C, long long D){
    return max(min(B, D) - max(A, C), 0LL);
}

int main(){
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    long long C;
    scanf("%lld",&C);
    long long D;
    scanf("%lld",&D);
    auto result = solve(A, B, C, D);
    cout << result << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<boost/variant.hpp>
using namespace std;
typedef long long ll;
typedef vector<boost::variant<bool, ll, int, string, double, char*, const char*>> any;
template<typename T> inline void pr(const vector<T> &xs){
	for(int i=0; i<xs.size()-1; i++) cout<<xs[i]<<" ";
	(xs.empty()?cout:(cout<<xs[xs.size()-1]))<<endl;
}
#ifdef DEBUG
#define debug(...) pr(any{__VA_ARGS__})
#define debugv(x) pr((x))
#else
#define debug(...)
#define debugv(x)
#endif

int main(){
	int N;
	ll K;
	cin >> N >> K;
	vector<ll> A(N), B(N);
	for(int i=0; i<N; i++){
		cin >> A[i] >> B[i];
	}

	ll ans = 0;
	for(int k=30; k>=0; k--){
		if(((K>>k)&1)==0) continue;
		ll sum = 0;
		ll o = 0;
		for(int i=0; i<N; i++){
			ll a = A[i] >> k;
			ll x = (K >> (k+1)) << 1;
			if(a + (x & ~a) == x){
				sum += B[i];
				o |= A[i];
			}
		}
		ans = max(ans, sum);
		debug(k, sum, o);
	}

	ll sum = 0;
	for(int i=0; i<N; i++){
		if(A[i]+(K&~A[i])==K){
			sum += B[i];
		}
	}
	ans = max(sum, ans);

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<cstdio>
#include<algorithm>
#define M 100010
using namespace std;
int n,a[M],ton[M];
int main() {
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]),ton[a[i]]++;
	sort(a+1,a+1+n);
	int sz=ton[a[1]];
	if(sz>2) {
		puts("Impossible");return 0;
	}
	if(sz==2&&a[n]%2==0) {
		puts("Impossible");return 0;
	}
	for(int i=a[1]+(sz&1);i<=a[n];i++)
		if(ton[i]<2) {
			puts("Impossible");return 0;
		}
	puts("Possible");
	return 0;
}

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

const int INF = 1e9;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, x, y;
    cin >> n >> x >> y;
    --x; --y;
    vector<int> ans(n);
    rep(sv,n){
        vector<int> dist(n, INF);
        queue<int> q;
        auto push = [&](int v, int d){
            if(dist[v] != INF) return;
            dist[v] = d;
            q.push(v);
        };
        push(sv, 0);
        while(!q.empty()){
            int v = q.front();
            q.pop();
            int d = dist[v];
            if(v-1 >= 0) push(v-1, d+1);
            if(v+1 < n) push(v+1, d+1);
            if(v == x) push(y, d+1);
            if(v == y) push(x, d+1);
        }
        rep(i,n) ans[dist[i]]++;
    }
    rep(i,n) ans[i] /= 2;
    for(int i = 1; i <= n-1; i++){
        cout << ans[i] << endl;
    }
    return 0;
}

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

int main(){
    int i, c;
    string s;
    cin >> s;
    for(i = 0; i < s.length(); i++){
        if(i % 2 == s[i] - '0')
            c++;
    }
    if(s.length() < c * 2){
        cout << s.length() - c << endl;
    }
    else{
        cout << c << endl;
    }
}

Measured memory_bytes: 512