akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>

int main(){
    char b[3][3];
    int i,j;

    while(1){
        for(i=0;i<3;i++){
            for(j=0;j<3;j++){
                scanf("%c",&b[i][j]);
                if(b[i][j]=='0')return 0;
            }
            getchar();
        }
        if(b[0][0]==b[0][1]&&b[0][1]==b[0][2]&&b[0][2]==b[0][0]){
            if(!(b[0][0]=='+')){
                printf("%c\n",b[0][0]);
                continue;
            }
        }
        if(b[1][0]==b[1][1]&&b[1][1]==b[1][2]&&b[1][2]==b[1][0]){
            if(!(b[1][0]=='+')){
                printf("%c\n",b[1][0]);
                continue;
            }
        }
        if(b[2][0]==b[2][1]&&b[2][1]==b[2][2]&&b[2][2]==b[2][0]){
            if(!(b[2][0]=='+')){
                printf("%c\n",b[2][0]);
                continue;
            }
        }
        if(b[0][0]==b[1][0]&&b[1][0]==b[2][0]&&b[2][0]==b[0][0]){
            if(!(b[0][0]=='+')){
                printf("%c\n",b[0][0]);
                continue;
            }
        }
        if(b[0][1]==b[1][1]&&b[1][1]==b[2][1]&&b[2][1]==b[0][1]){
            if(!(b[0][1]=='+')){
                printf("%c\n",b[0][1]);
                continue;
            }
        }
        if(b[0][2]==b[1][2]&&b[1][2]==b[2][2]&&b[2][2]==b[0][2]){
            if(!(b[0][2]=='+')){
                printf("%c\n",b[0][2]);
                continue;
            }
        }
        if(b[0][0]==b[1][1]&&b[1][1]==b[2][2]&&b[2][2]==b[0][0]){
            if(!(b[0][0]=='+')){
                printf("%c\n",b[0][0]);
                continue;
            }
        }
        if(b[2][0]==b[1][1]&&b[1][1]==b[0][2]&&b[0][2]==b[2][0]){
            if(!(b[2][0]=='+')){
                printf("%c\n",b[2][0]);
                continue;
            }
        }
        printf("NA\n");
    }  
    return 0;
}

Measured memory_bytes: 552
h, w = [int(n) for n in input().split()]


def max_diff(list):
    l0 = list[0]
    l1 = list[1]
    l2 = list[2]
    max_diff = max([abs(l0 - l1), abs(l0 - l2), abs(l1 - l2)])
    return max_diff


def min_square(h, w):
    w3 = w // 3
    w2 = w // 2
    h3 = h // 3
    h2 = h // 2
    w_3 = [w3, w3 + 1, w3 + 2]
    w_2 = [w2, w2 + 1, w2 + 2]
    h_3 = [h3, h3 + 1, h3 + 2]
    h_2 = [h2, h2 + 1, h2 + 2]
    min_list = []
    for k in w_3:
        for l in h_2:
            if 0 < k < w and 0 < l < h:
                min_list.append(max_diff([h * k, l * (w - k), (h - l) * (w - k)]))
    for k in w_2:
        for l in h_3:
            if 0 < k < w and 0 < l < h:
                min_list.append(max_diff([w * l, k * (h - l), (w - k) * (h - l)]))
    for k in w_3:
        if 0 < k < w:
            min_list.append(max_diff([k * h, k * h, (w - 2 * k) * h]))
    for k in h_3:
        if 0 < k < h:
            min_list.append(max_diff([k * w, k * w, (h - 2 * k) * w]))

    return min(min_list)


if h % 3 == 0 or w % 3 == 0:
    print(0)
else:
    print(min_square(h, w))


Measured memory_bytes: 3064
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
char s[100010];
int k;
inline void w(){
    for(int i=0;i<k/2;i++){
    	int u=s[i]-s[k-i-1];
    	if(u<0)u=-u;
        if(u!=1&&u!=2){
        	printf("No");
            return;
        }
    }
    printf("Yes");
}
int main(){
    scanf("%s",&s);
    k=strlen(s);
	if(k%2!=0){ 
        printf("No");
        return 0;
    }
    w();
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll MOD = 1000000007;
constexpr ll INF = 1ll<<60;

int main(int argc, char **argv)
{
	ll N; cin >> N;
	vector<ll> A(N);
	ll t4{0}, to{0};
	
	for (ll i = 0; i < N; ++i)
	{
		ll a; cin >> a;
		if (a % 4 == 0) ++t4;
		if (a & 1) ++to;
	}


	if (t4 + to == N)
	{
		if (t4 >= to-1)
			std::cout << "Yes" << std::endl;
		else
			std::cout << "No" << std::endl;
	}
	else
	{
		if (t4 >= to)
			std::cout << "Yes"<< std::endl;
		else
			std::cout << "No"<< std::endl;
	}
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
using namespace std;
 
int main() {
  int w,h,n;
  cin >> w >> h >> n;
  int w_s=0;
  int h_s=0;

  for(int i=0;i<n;i++) {
      int x, y,a;
      cin >> x >> y >> a;

      if (a == 1 && w_s < x) {
          w_s = x;
      } else if (a == 2 && x < w) {
          w = x;
      } else if (a == 3 && h_s < y) {
          h_s = y;
      } else if (a == 4 && y < h) {
          h = y;
      }
  }

  int hh = h-h_s;
  if (hh < 0) {
      hh = 0;
  }

  int ww = w-w_s;
  if (ww < 0) {
      ww = 0;
  }
  int ans = hh*ww;
  if (ans < 0) {
      ans = 0;
  }
  cout << ans << endl;
 
  return 0;
}

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

using namespace std;

#define MAX 101
 
int main(){
    int n,q;
     
    while(cin >> n >> q ,n+q){
        int flg = 0 , cnt[MAX] , max_n = 0 , m , d;
        fill(cnt,cnt+MAX,0);
        for(int i = 0 ; i < n ; i++){
            cin >> m;
            for(int j = 0 ; j < m ; j++){
                cin >> d;
                ++cnt[d];
                max_n = max(max_n,cnt[d]);
            }
        }
         
        if(max_n >= q) flg = 1;
         
        if(flg){
            int res;
            for(int k = 1 ;; k++){
                if(cnt[k] >= q && cnt[k] == max_n){
                    res = k;
                    break;
                }
            }
            cout << res << endl;
        }
        else cout << flg << endl;
    }
    return 0;
}

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

void swap(int *a, int *b) 
{
	int t = *a;
	*a = *b;
	*b = t;
}

int partition(int array[], int l, int r)
{
	int pivot = array[r];
	int i = (l - 1);

	for (int j = l; j <= r - 1; j++) {
		if (array[j] <= pivot) {
			i++;
			swap(&array[i], &array[j]);
		}
	}
	swap(&array[i+1], &array[r]);
	return i+1;
}

void quickSort(int array[], int l, int r)
{
	if (l < r) {
		int pivot = partition(array, l, r);
		quickSort(array, l, pivot - 1);
		quickSort(array, pivot + 1, r);
	}
}

int main() 
{
	int x[20];
	cin >> x[0] >> x[1] >> x[2];
	quickSort(x, 0, 2);
	for (int i=0; i<2; i++) {
		cout << x[i] << " ";
	}
	cout << x[2] << endl;

	return 0;
}


Measured memory_bytes: 3096
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>
#include <random>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
//#define int long long

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

void solve() {
    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;
}

signed main() {
    solve();
    
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

        while (true) {
            int maxDay = 0;
            int[] dayCounts = new int[100];
            n = Integer.parseInt(sc.next());
            q = Integer.parseInt(sc.next());
            if (n == 0 && q == 0)
                break;

            for (int i = 0; i < n; i++) {
                m = Integer.parseInt(sc.next());
                for (int j = 0; j < m; j++) {
                    d = Integer.parseInt(sc.next());
                    dayCounts[d]++;
                }
            }

            for (int i = 0; i < dayCounts.length; i++) {
                if (dayCounts[i] > dayCounts[maxDay])
                    maxDay = i;
            }

            if (dayCounts[maxDay] < q)
                maxDay = 0;

            System.out.println(maxDay);
        }
    }
}

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

const int MAX = 1000000;

// 新たなtypeを作る。
struct pp {
    string name;
    int t;
};

pp Q[MAX];
struct Queue {
    int h, t;

    void initialize() { h = 0, t = 0; }

    bool isEmpty() { return h == t; }

    bool isFull() { return h == (t + 1) % MAX; }
    pp head() { return Q[h]; }
    pp tail() { return Q[t - 1]; }
    void enqueue(pp n) {
        Q[t] = n;
        if (t + 1 == MAX)
            t = 0;
        else
            t++;
    }
    pp dequeue() {
        pp n = Q[h];
        if (h + 1 == MAX)
            h = 0;
        else
            h++;

        return n;
    }
};

int main() {
    int n, q;
    cin >> n >> q;
    Queue que;
    map<string, int> ma;
    que.initialize();
    rep(i, n) {
        string s;
        int a;
        cin >> s >> a;
        pp p;
        p.name = s;
        p.t = a;
        que.enqueue(p);
    }

    int elaps = 0;

    while (!que.isEmpty()) {
        pp a = que.dequeue();
        if (a.t - q <= 0) {
            elaps += a.t;
            cout << a.name << " " << elaps << endl;
        } else {
            elaps += q;
            a.t -= q;
            que.enqueue(a);
        }
    }
}


Measured memory_bytes: 21088
n, k, c = map(int, input().split())
c += 1
s = list(input())
a = []
i = 0
while i < len(s) and len(a) < k:
    if s[i] == 'x':
        i += 1
        continue
    a.append(i)
    i += c
b = []
j = len(s)-1
while j > -1 and len(b) < k:
    if s[j] == 'x':
        j -= 1
        continue
    b.append(j)
    j -= c
b = b[::-1]
for i in range(len(a)):
    if a[i] == b[i]:
        print(a[i] + 1)



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

using namespace std;

int main()
{
  
  int n; cin >> n;
  std::vector<long long> l(n);
  for (int i = 0; i < n; ++i) cin >> l[i];
  std::sort(l.begin(), l.end()); 
  
  // long long ans = 0;
  // for(int i = 0; i < n; i++)
  // {
  //   for(int j = i+1; j < n; j++)
  //   {
  //     int k = std::distance(l.begin(),std::lower_bound(l.begin(), l.end(), l[i]+l[j]));
      
  //     ans += std::max(k-(j+1),0);
  //   }
  // }
  // std::cerr << ans << std::endl;
  
  long long ans = 0;
    
  for (int i = 0; i < n; i++) {
      for (int j = i+1; j < n; j++) {
          int k = std::distance(l.begin(),std::lower_bound(l.begin(), l.end(), l[i]+l[j]));

          ans += std::max(k - (j+1), 0);
      }
  }
  cout << ans << endl;
}




Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <limits>
#include <math.h>
using namespace std;

int maximum( int a, int b ) { return a>b ? a : b ; }

int maximum( int a, int b, int c ) { return maximum( maximum(a,b), c ) ; }

int maximum( int a, int b, int c, int d ) { return maximum( maximum(a,b), maximum(c,d) ) ; }

int main(){ 
  int hens[3];
  int seki = 1;
  for(int i = 0; i < 3;i++) {
    cin >> hens[i];
    seki = seki * hens[i];
  }
  int m = maximum(hens[0],hens[1],hens[2]);
  seki = seki / (m * 2);
  cout << seki << endl;
  return 0;
}

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

int N, M, P, A[5050], B[5050], C[5050];

long long int dis[2525];

long long int INF = 999999999999;

int main(void) {

	cin >> N >> M >> P;
	for (int i = 1; i <= M; i++) {
		cin >> A[i] >> B[i] >> C[i];
	}

	for (int i = 2; i <= N; i++) { dis[i] = INF; }


	long long int tmp1, tmp2;

	
	for (int j = 1; j <= N; j++) {
		for (int i = 1; i <= M; i++) {
			if (dis[A[i]] + P - C[i] < dis[B[i]]) { dis[B[i]] = dis[A[i]] + P - C[i]; }
			//if (ans < dis[N]) { ans = dis[N]; last = i; }
		}
	}

	tmp1 = dis[N];

	for (int j = 1; j <= N; j++) {
		for (int i = 1; i <= M; i++) {
			if (dis[A[i]] + P - C[i] < dis[B[i]]) { dis[B[i]] = dis[A[i]] + P - C[i]; }
			//if (ans < dis[N]) { ans = dis[N]; last = i; }
		}
	}

	tmp2 = dis[N];

	//cout << "tmp1= " << tmp1 << endl;
	//cout << "tmp2= " << tmp2 << endl;
	if (tmp2 < tmp1) { cout << -1 << endl; }
	else { cout << max(-tmp1,(long long int) 0) << endl; }

	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i = 0; i < (N); i++)
#define repo(i,N) for(int i = 1; i < (N); i++)
//#define int long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
//#define num 1000000007
#define pi acos(-1.0)
//cout << fixed << setprecision (10);   小数点以下１０桁まで
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//string s = to_string(int数);
//int n = stoi(string文字列);

int main() {
  string a;
  cin >>a;
  
  vector<string> yo = {"non", "SAT", "FRI", "THU", "WED", "TUE", "MON", "SUN"};
  
  rep(i,8) {
    if(yo.at(i)==a) {
    cout << i << endl; 
    }
  }
  
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
    int n,max = -10000000,min = 10000000;
    long int sum = 0;
    cin>>n;
    int x =0;
    for(int i = 0;i < n;i++){
        
        cin>>x;
        if(x >= max){
            max = x;
        }
        if(x <= min){
            min = x;
        }
        sum = sum + x;
    }
    cout<<min<<" "<<max<<" "<<sum<<endl;
    return 0;
}


Measured memory_bytes: 3116
while True:
    a,op,b = input().split()
    a,b = int(a),int(b)
    
    if op == "?":
        break
    if op == "+":
        print(a + b)
    if op == "-":
        print(a - b)
    if op == "*":
        print(a * b)
    if op == "/":
        print(a // b)


Measured memory_bytes: 5600
#include <stdio.h>

int main(void){
  int K,S;
  int x,y,z;
  int count;

  scanf("%d%d",&K,&S);

  for(x=0;x<=K;x++){
    for(y=0;y<=K;y++){
      z=S-x-y;
      if(z>=0 && z<=K)
	count+=1;
    }
  }

  printf("%d\n",count);

  return 0;
}
	


Measured memory_bytes: 128
#include "bits/stdc++.h"
using namespace std;
const int MOD = 1e9 + 7;
typedef long long lint;
const int INF =1e7;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repi(i, k, n) for (int i = (k); i < (int)(n); ++i)
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(),(x).end()
#define pb push_back
int main(){
    int a, b;
    cin >> a >> b;
    cout << max(0, a - b);
    return 0;
}

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

using namespace std;

using ll = long long;
using pii = pair<int, int>;

set<char> good = {'A', 'C', 'G', 'T'};

bool isGood(char c) {
	return good.find(c) != good.end();
}

void solve() {
	//~ freopen("distance.in", "r", stdin);
	//~ freopen("distance.out", "w", stdout);
	ios_base::sync_with_stdio(false); 
	cin.tie(nullptr);

	int n, q;
	cin >> n >> q;
	string str;
	cin >> str;
	vector<int> dp(n, 0);
	for (int i = 1; i < n; i++)
		if (str[i] == 'C' && str[i - 1] == 'A')
			dp[i] = dp[i - 1] + 1;
		else
			dp[i] = dp[i - 1];
	
	for (int i = 0; i < q; i++) {
		int l, r;
		cin >> l >> r;
		l--; r--;
			cout << dp[r] - dp[l] << "\n";
	}
}

int main() {
	solve();
	return 0;
}




Measured memory_bytes: 1488
#include <iostream>
#include <cstdint>
#include <string>
#include <algorithm>

int main() {
	std::string A;
	std::cin >> A;

	int64_t ans = A.size() * (A.size() - 1) / 2 + 1;
	for (int i = 0; i < 26; ++i) {
		int64_t tmp = std::count(A.begin(), A.end(), 'a' + i);

		if (tmp < 2)
			continue;

		ans -= tmp * (tmp - 1) / 2;
	}

	std::cout << ans << std::endl;
}

Measured memory_bytes: 640
import os

import itertools
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

H, W = list(map(int, sys.stdin.readline().split()))
A = [list(sys.stdin.readline().rstrip()) for _ in range(H)]


def ok(h, w):
    return 0 <= h < H and 0 <= w < W and A[h][w] == '.'


nexts = []
for h, w in itertools.product(range(H), range(W)):
    if A[h][w] == '#':
        nexts.append((h, w))

delta = [[0, 1], [0, -1], [1, 0], [-1, 0]]
ans = 0
while nexts:
    nn = []
    for dh, dw in delta:
        for h, w in nexts:
            if ok(h + dh, w + dw):
                A[h + dh][w + dw] = '#'
                nn.append((h + dh, w + dw))
    if not nn:
        break
    ans += 1
    nexts = nn
print(ans)


Measured memory_bytes: 127148
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <cstring>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <math.h>
using namespace std;

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

int main() {
  int n; cin >> n;
  vector<string> str(n);
  for (int i = 0; i < n; i++) cin >> str[i];
  map<char, int> cnt;
  for (int i = 0; i < str[0].length(); i++) {
    cnt[str[0][i]]++;
  }
  for (int i = 1; i < n; i++) {
    int l = str[i].length();
    map<char, int> cnt_tmp;
    for (int j = 0; j < l; j++) {
      cnt_tmp[str[i][j]]++;
    }
    for (int j = 'a'; j < 'a' + 26; j++) {
      cnt[j] = min(cnt[j], cnt_tmp[j]);
    }
  }

  for (int i = 'a'; i < 'a' + 26; i++) {
    for (int j = 0; j < cnt[i]; j++) {
      cout << (char)i;
    }
  }
  cout << endl;
}



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

using namespace std;

typedef long long ll;
typedef long double ld;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    ll t=1;
    //cin >> t;
    while (t--)
    {
        string s;
        cin>>s;
        std::replace( s.begin(), s.end(), '?', 'D'); // replace all 'x' to 'y'
        cout<<s<<endl;
    }
    return 0;
}


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

int main() {
    int s;
    cin >> s;
    int ans=0;
    bool z=true;
    int a[100000];
    rep(i,100000){
        a[i]=s;
        if(a[i]%2==0){
            s/=2;
        }
        else{
            s=s*3+1;
        }

        rep(j,i){
            if(s==a[j]){
                ans=i;
                break;
            }
        }
        if(ans !=0) break;
    }
    cout << ans+2 << endl;
}

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

const int N = 4;
const int N2 = 16;
const int LIMIT = 100;

const int dx[4] = { -1, 0, 1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
const char dir[4] = { 'u', 'r', 'd', 'l' };

int mdt[N2][N2];
int path[LIMIT];

struct Puzzle
{
	int f[N2];
	int space;
	int md;
};

Puzzle state;
int limit;

bool isTarget()
{
	for (int i = 0; i < N2; i++)
		if (state.f[i] != i + 1)
			return false;
	return true;
}

int getAllmd(const Puzzle& in)
{
	int sum = 0;
	for (int i = 0; i < N2; i++)
	{
		if (in.f[i] == N2)
			continue;
		sum += mdt[i][in.f[i] - 1];
	}
	return sum;
}

bool dfs(int depth, int prev)
{
	if (state.md == 0)
		return true;
	if (depth + state.md > limit)
		return false;

	int sx = state.space / N;
	int sy = state.space % N;
	Puzzle tmp;

	for (int r = 0; r < 4; r++)
	{
		int tx = sx + dx[r];
		int ty = sy + dy[r];
		if (tx < 0 || ty < 0 || tx >= N || ty >= N)
			continue;
		if (std::max(prev, r) - std::min(prev, r) == 2)
			continue;

		tmp = state;
		state.md -= mdt[tx * N + ty][state.f[tx * N + ty] - 1];
		state.md += mdt[sx * N + sy][state.f[tx * N + ty] - 1];
		std::swap(state.f[tx * N + ty], state.f[sx * N + sy]);
		state.space = tx * N + ty;
		if (dfs(depth + 1, r))
		{
			path[depth] = r;
			return true;
		}
		state = tmp;
	}
	return false;
}

std::string iterative_deepening(Puzzle in)
{
	in.md = getAllmd(in);
	for (limit = in.md; limit <= LIMIT; limit++)
	{
		state = in;
		if (dfs(0, -100))
		{
			std::string ans;
			for (int i = 0; i < limit; i++)
				ans += dir[path[i]];
			return ans;
		}
	}

	return "unsolvable";
}

int main()
{
	for (int i = 0; i < N2; i++)
		for (int j = 0; j < N2; j++)
			mdt[i][j] = abs(i / N - j / N) + abs(i % N - j % N);

	Puzzle in;

	for (int i = 0; i < N2; i++)
	{
		scanf("%d", &in.f[i]);
		if (in.f[i] == 0)
		{
			in.f[i] = N2;
			in.space = i;
		}
	}
	std::string ans = iterative_deepening(in);
	printf("%d\n", (int)ans.length());

	return 0;
}



Measured memory_bytes: 2884
#include<bits/stdc++.h>
#define INFTY 1<<20
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
const int MOD=1000000007;
int n;
int x[102],cnt=0;
//最大公約数
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
int main(){
    int n;cin>>n;
    ll st;cin>>st;
    vector<ll> x(n),dis(n);
    rep(i,n){
        cin>>x[i];
        dis[i]=x[i]-st;
    }
    ll ans;

    rep(i,n){
        ans = abs(gcd(ans,dis[i]));
    }
    cout<<ans<<endl;
return 0;
}

Measured memory_bytes: 1792
import java.util.*;

public class Main {
    public static void main(String[] args)  {
        Scanner sc = new Scanner(System.in);
        int S = sc.nextInt();
        int W = sc.nextInt();
        
        if(W>=S){
            System.out.println("unsafe");
        }else{
            System.out.println("safe");
        }
    }
}


Measured memory_bytes: 35712
#include <stdio.h>
int main(void) {
    int num,inum,stack[20][2],sp,map[21][21],i,j,step,x,y;
    char dir;
    while (1) {
        scanf("%d\n",&num);
        if (num==0) break;
        x=10,y=10;
        for (i=0; i<=20; i++) {
            for (j=0; j<=20; j++) map[i][j]=0;
        }
        for (sp=0; sp<num; sp++) scanf("%d %d\n",&stack[sp][0],&stack[sp][1]);
        scanf("%d\n",&inum);
        for (i=0; i<inum; i++) {
            scanf("%c %d\n",&dir,&step);
            if (dir=='N') {
                for (j=0; j<=step; j++) map[x][y+j]=1;
                y+=step;
            } else if (dir=='E') {
                for (j=0; j<=step; j++) map[x+j][y]=1;
                x+=step;
            } else if (dir=='S') {
                for (j=0; j<=step; j++) map[x][y-j]=1;
                y-=step;
            } else if (dir=='W') {
                for (j=0; j<=step; j++) map[x-j][y]=1;
                x-=step;
            }
        }
        for (i=0; i<sp; i++) {
            if (map[stack[i][0]][stack[i][1]]==0) break;
        }
        if (i==sp) {
            printf("Yes\n");
        } else {
            printf("No\n");
        }
    }
    return 0;
}

Measured memory_bytes: 588
#include<bits/stdc++.h>
using namespace std;
const int maxn=2e5+10;
char  s[maxn];
int n;
long long ans;
int pos[26][maxn],vis[maxn],cnt[maxn];
struct TAS{
	int a[maxn];
	void add(int x,int y){
		for(;x<maxn;x+=x&-x)a[x]+=y;
	}
	int sum(int x,int r=0){
		for(;x>0;x-=x&-x)r+=a[x];
		return r;
	}
}T1;

void solve(){
	scanf("%s",s+1);
	n=strlen(s+1);
	for(int i=1,x;i<=n;++i){
		++cnt[x=s[i]-'a'];
		pos[x][++pos[x][0]]=i;
		T1.a[i]=i&-i;
	}
	for(int i=0,chk=0;i<26;++i){
		if(cnt[i]&1)++chk;
		if(chk>1)puts("-1"),exit(0);
	}
	for(int i=1,x,nxt;i<=n;++i)if(!vis[i]){
		x=s[i]-'a';
		nxt=pos[x][pos[x][0]--];
		if(i==nxt)ans+=(T1.sum(n)-T1.sum(nxt))>>1;
        else ans+=T1.sum(n)-T1.sum(nxt);
        T1.add(i,-1);
        T1.add(nxt,-1);
        vis[i]=vis[nxt]=1;
	}
	cout<<ans<<endl;
	
}
int main(){
	solve(); 
	return 0;
}

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

// #define M 1046527
#define M 1000000
#define NIL (-1)
#define L 14

char H[M][L];

// 文字から数値に変換
int getChar(char ch) {
    if (ch=='A') return 1;
    else if(ch=='C') return 2;
    else if(ch=='G') return 3;
    else if(ch=='T') return 4;
    else return 0;
}

// 文字列から数値へ変換してkeyを生成する
long long getKey(char str[]) {
    long long sum=0, p=1, i;
    for (i=0; i<strlen(str); i++) {
        sum += p*getChar(str[i]);
        p *= 5;
    }
    return sum;
}

int h1(int key) { return key % M; }
int h2(int key) { return (key%(M)); }

int find(char str[]) {
    long long key, i, h;
    key = getKey(str);
    for (i=0; ; i++) {
        h = (h1(key) + i+h2(key)) % M;
        if( strcmp(H[h], str) == 0) return 1;
        else if( strlen(H[h]) == 0) return 0;
    }
    return 0;
}

int insert(char str[]) {
    long long key, i, h;
    key = getKey(str);
    for (i=0; ; i++) {
        h = (h1(key) + i+h2(key)) % M;
        if( strcmp(H[h], str) == 0) return 1;
        else if( strlen(H[h]) == 0) {
            strcpy(H[h], str);
            return 0;
        }
    }
    return 0;
}

int main() {
    int i, n, h;
    char str[L], com[9];
    for (i=0; i<M; i++) H[i][0] = '\0';
    scanf("%d", &n);
    for(i=0; i<n; i++) {
        scanf("%s %s", com, str);
        
        if(com[0] == 'i') {
            insert(str);
        } else {
            if(find(str)) {
                printf("yes\n");
            }else{
                printf("no\n");
            }
        }
    }
    return 0;
}


Measured memory_bytes: 16332
s = input()

ans = 0
hoge = 0
for i in range(3):
    if s[i] == "R":
        hoge += 1
    else:
        if hoge > ans:
            ans = hoge
        hoge = 0
    if i == 2:
        if hoge > ans:
            ans = hoge
        hoge = 0
print(ans)

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


//#pragma GCC optimize("Ofast,unroll-loops")
//#pragma GCC target("avx,avx2,fma")

typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;
#define MP make_pair
#define PB push_back
#define X first
#define Y second

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())
#define FILL(a, value) memset(a, value, sizeof(a))
#define debug(a) cerr << #a << " = " << a << endl;

template<typename T> void setmax(T& x, T y) {x = max(x, y);}
template<typename T> void setmin(T& x, T y) {x = min(x, y);}

template<typename T> void print(const T& a, ostream& out){	
	for(auto i: a) out << i << ' ';
	out << endl;
}

const double PI = acos(-1.0);
const LL INF = 1e9 + 47;
const LL LINF = INF * INF;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef __int128 Long;

Long solve(LL m1, LL m2){
	auto res = crt({0, m2 - 1}, {m1, m2});
	if (res.X == 0) return res.Y;
	else return res.X;
}

int main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);

	LL n; cin >> n;
	n <<= 1;

	vector<pair<LL, LL>> p;
	for(LL i = 2; i * i <= n; ++i) if (n % i == 0){
		LL cnt = 1;
		while(n % i == 0) n /= i, cnt *= i;
		p.PB({i, cnt});
	}

	if (n > 1) p.PB({n, n});

	Long ans = LINF * (Long) LINF;
	FOR(mask, 0, 1 << SZ(p)){
		LL m1 = 1, m2 = 1;
		FOR(i, 0, SZ(p))if (mask & (1 << i)){
			m1 *= p[i].Y;
		}else{
			m2 *= p[i].Y;
		}

		setmin(ans, solve(m1, m2));
	}
		
    cout << (LL) ans << endl;
    return 0;
}


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


int main(){
  int r,g,b;
  cin >> r >> g >> b;
  int n = 100*r + 10*g + b;
  if( n%4 == 0 ){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

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

		long X = sc.nextLong();
		long num = 100;
		long cnt = 0;
		
		while(num < X) {
			num = num+(num / 100);
			cnt += 1;
		}
					
			System.out.println(cnt);
		sc.close();
	}
}

Measured memory_bytes: 35784
#include <iostream>
#include<string>
using namespace std;
int main(void){
  
  string d;
  
  cin >> d;
  
  if(d=="A"){
    cout<<"T"<<endl;
  }
   if(d=="T"){
    cout<<"A"<<endl;
  }
   if(d=="C"){
    cout<<"G"<<endl;
  }
   if(d=="G"){
    cout<<"C"<<endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
using namespace std;
int main()
{
	int n,a,b;
	while(cin >> n >> a >> b)
	{
	    int len;
	    if(n*a < b)
            len = n*a;
        else len = b;
		cout << len << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>b;--i)
#define sq(a) (a)*(a)
#define nitro std::ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);
#define debug(x) std::cerr<<#x<<"="<<x<<'\n'
#define text std::cerr<<"SacredCoupoid08\n"
#define endl '\n'
#define all(c) (c).begin(),(c).end()
#define U 1000000007
#define N 100005
#define sz(c) (int)c.size()
typedef long long ll;
typedef std::vector< int > vi;
typedef std::pair<int, int> pi;
#define cin std::cin
#define cout std::cout
#define vector std::vector
#define pb push_back
#define pv(x) for(auto y:x)    cerr<<y<<" ";    cerr<<'\n';
#define fr first
#define sc second
#define ppb pop_back
#define max(a,b) a=max(a,b)
#define min(a,b) a=min(a,b)
#define int ll
#define tr(c,it) for(typeof(c.begin()) it= c.begin();it != c.end();it++)
signed main()
{		
	nitro;
	int VASU=1;
	//cin>>VASU;
	while(VASU--)
	{
		int n,m;
		cin>>n>>m;
		vi h(n);
		set<int> s[n+1];
		vector <bool> ans(n+1,1);
		rep(i,0,n)
		cin>>h[i];
		int a,b;
		while(m--)
		{
			cin>>a>>b;
			s[a].insert(b);
			//swap(a,b);
			s[b].insert(a);
		}
		//rep(i,1,n+1)
	//{
		//cout<<i<<"("<<h[i-1]<<")"<<":";
		//for(auto x:s[i])
		//{
			//cout<<x<<" ";
		//}
		//cout<<endl;
		
	//}
	//pv(ans);
	rep(i,0,n)
	{
		if(ans[i+1])
		{
			if(sz(s[i+1]))
			for(auto x:s[i+1])
			{
				
				if(h[x-1]>=h[i])
				{
					//debug(h[i]);
					ans[i+1]=0;
					break;
				}
			}
			
		}
	}
	
	int sum=0;
	rep(i,1,n+1)
	sum+=ans[i];
	cout<<sum<<endl;
	
		
	}
	

	
	
	
	return 0;
}



Measured memory_bytes: 17700
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
signed main(){
  ll x;
  cin >> x;
  if(x<1200) cout <<"ABC\n";
  else cout <<"ARC\n";
}


Measured memory_bytes: 256
#[allow(dead_code)]
fn main() {
    let (n, m) = i::u2();
    let even = (m + 1) / 2;
    let odd = m - even;
    if m % 2 == 0 {
        for i in 0..even {
            println!("{} {}", i + 1, m - i + 1);
        }
        for i in 0..odd {
            println!("{} {}", m + i + 2, m + odd * 2 - i + 1);
        }
    } else {
        for i in 0..even {
            println!("{} {}", i + 1, m - i + 1);
        }
        for i in 0..odd {
            println!("{} {}", m + i + 2, m + odd * 2 - i + 2);
        }
    }
}

#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::io::*;
#[allow(unused_imports)]
use std::num::*;
#[allow(unused_imports)]
use std::str::*;

#[allow(dead_code)]
mod i {
    use super::*;

    pub fn read<T: FromStr>() -> T {
        stdin()
            .bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>()
            .parse::<T>()
            .ok()
            .unwrap()
    }

    pub fn str() -> String {
        read()
    }

    pub fn s() -> Vec<char> {
        str().chars().collect()
    }

    pub fn i() -> i64 {
        read()
    }

    pub fn u() -> usize {
        read()
    }

    pub fn u2() -> (usize, usize) {
        (read(), read())
    }

    pub fn u3() -> (usize, usize, usize) {
        (read(), read(), read())
    }

    pub fn f() -> f64 {
        read()
    }

    pub fn c() -> char {
        read::<String>().pop().unwrap()
    }

    pub fn iv(n: usize) -> Vec<i64> {
        (0..n).map(|_| i()).collect()
    }

    pub fn iv2(n: usize) -> Vec<(i64, i64)> {
        (0..n).map(|_| iv(2)).map(|a| (a[0], a[1])).collect()
    }

    pub fn uv(n: usize) -> Vec<usize> {
        (0..n).map(|_| u()).collect()
    }

    pub fn uv2(n: usize) -> Vec<(usize, usize)> {
        (0..n).map(|_| uv(2)).map(|a| (a[0], a[1])).collect()
    }

    pub fn uv3(n: usize) -> Vec<(usize, usize, usize)> {
        (0..n).map(|_| uv(3)).map(|a| (a[0], a[1], a[2])).collect()
    }

    pub fn fv(n: usize) -> Vec<f64> {
        (0..n).map(|_| f()).collect()
    }

    pub fn cmap(h: usize) -> Vec<Vec<char>> {
        (0..h).map(|_| s()).collect()
    }
}


Measured memory_bytes: 2112
#![allow(unused_imports, unused_macros, dead_code)]

macro_rules! min {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| min!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = min!($($ys),*);
        if $x < t { $x } else { t }
    }}
}
macro_rules! max {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| max!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = max!($($ys),*);
        if $x > t { $x } else { t }
    }}
}


macro_rules! ewriteln {
    ($($args:expr),*) => { let _ = writeln!(&mut std::io::stderr(), $($args),*); };
}
macro_rules! trace {
    ($x:expr) => { ewriteln!(">>> {} = {:?}", stringify!($x), $x) };
    ($($xs:expr),*) => { trace!(($($xs),*)) }
}
macro_rules! put {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        if let Some(x) = it.next() { print!("{}", x); }
        for x in it { print!(" {}", x); }
        println!("");
    }};
    ($x:expr) => { println!("{}", $x) };
    ($x:expr, $($xs:expr),*) => { print!("{} ", $x); put!($($xs),*) }
}

const M: i64 = 1_000_000_007;

fn yakusu(m: u32) -> usize {
    let mut r = 0;
    for i in 1..m+1 {
        if i * i > m {
            break;
        } else if i * i == m {
            r += 1;
        } else if m % i == 0 {
            r += 2;
        }
    }
    r
}

fn main() {
    let mut sc = Scanner::new();
    let n: u32 = sc.cin();
    put!((1..n+1).filter(|&m|
        m % 2 == 1 && yakusu(m) == 8).count());
}

use std::io::{self, Write};
use std::str::FromStr;
use std::collections::VecDeque;

struct Scanner { stdin: io::Stdin, buffer: VecDeque<String>, }
impl Scanner {
    fn new() -> Self { Scanner { stdin: io::stdin(), buffer: VecDeque::new() } }
    fn cin<T: FromStr>(&mut self) -> T {
        while self.buffer.len() == 0 {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
        self.buffer.pop_front().unwrap().parse::<T>().ok().unwrap()
    }
}


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

#define REP(i,n) for(int i=0;i<n;++i)
#define RREP(i,n) for(int i=n-1;i>=0;--i)
#define FOR(i,m,n) for(int i=m;i<n;++i)
#define RFOR(i,m,n) for(int i=m-1;i>=n;--i)
#define ALL(v) v.begin(),v.end()
#define PB(a) push_back(a)
#define INF 1000000001
#define MOD 1000000007

using namespace std;


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int x, y, s,cmax;
	while (1) {
		cin >> x >> y >> s;
		if (!x) break;
		cmax = -INF;
		FOR(i,1, s) {
			FOR(j,1, s) {
				if (i*(100 + x) / 100 + j*(100 + x) / 100 == s) {
					cmax = max(cmax, i*(100 + y) / 100 + j*(100 + y) / 100);
				}
			}
		}
		cout << cmax << endl;
	}
	return 0;
}

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

ll mod=1e9+7;

int main() {
    int n;
    cin >> n;
    ll ans=1;
    for (int i=1;i<=n;i++) {
        ans*=i;
        ans=ans%mod;
    }
    cout << ans << endl;
}

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

#define MARBLES 3

using namespace std;

int main() {
  int num, places = 0;
  
  cin >> num;
  string str = to_string(num);
  char const *marble = str.c_str();
  
  for (int i = 0; i < MARBLES; i++) {
    if (marble[i] == '1') {
      places++;
    }
  }
  cout << places << endl;
}

Measured memory_bytes: 256
/*
    g++ -std=c++14 -O2 -Wall a.cpp -o a && a < in.txt > out.txt
    */

//  io
#include <iostream>
//#include <fineam> //http://www.cplusplus.com/reference/fineam/fineam/
//#include <cstdio>
#include <iomanip> //http://www.cplusplus.com/reference/iomanip/
#include <limits>
//  util
#include <string>
#include <cstring>
#include <algorithm>
//#include <utility>
//#include <functional> //http://www.cplusplus.com/reference/functional/
//#include <cstdlib>
#include <cmath>
//#include <complex>
//#include <random>
//#include <bitset>
//  containers https://en.cppreference.com/w/cpp/container
#include <vector>
#include <queue>
#include <set>
//#include <map>
//#include <unordered_set>
//#include <unordered_map>
//  time
//#include <ctime>
//#include <chrono>
//                  https://en.cppreference.com/w/cpp/header/chrono
//                  http://www.cplusplus.com/reference/chrono/

using namespace std;
typedef vector<int> arri;
typedef vector<float> arrf;
typedef pair<int, int> pairi;
typedef long long ll;
typedef long double ld;
const int mod = 1e9 + 7;
const ll inf = 0x7fffffffffffffff;
const ll infneg = -0x7fffffffffffffff;

//file input routed to stdinout
/*
    std::ifineam inFile("input.txt");
    std::ofineam outFile("output.txt");
    std::cin.rdbuf(inFile.rdbuf());
    std::cout.rdbuf(outFile.rdbuf());
    */

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

    ll n;
    cin >> n;
    cout << n * (n - 1) / 2;
}

Measured memory_bytes: 764
#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<math.h>
#include<map>
 
using namespace std;
#define mod 1000000007
#define ll long long 
 
 
 
 
int arr[100009];
int dp[100009];
int n;
int solve(int idx ){
      if(idx==n-1){
return 0;}
if(dp[idx]!=-1){
return dp[idx];
}
int ans=solve(idx+1)+abs(arr[idx+1]-arr[idx]);
if(idx+2<n){
ans=min(ans,solve(idx+2)+abs(arr[idx+2]-arr[idx]));
 }
return dp[idx]=ans;
}

int main() {
 
	memset(dp, -1, sizeof(dp));
	cin>>n;
 
	for(int i = 0; i < n; i++) {
		scanf("%d", &arr[i]);
	}
 
	cout<<solve(0)<<endl;
 
	return 0;
}



Measured memory_bytes: 9176
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		for (int i = 0; i < N; i++) {
			int M = sc.nextInt();
			int num[] = new int[M];
			for (int j = 0; j < M; j++) {
				num[j] = sc.nextInt();
			}
			int upper_max = 0;
			int down_max = 0;
			for (int j = 0; j < M - 1; j++) {
				if (num[j] < num[j + 1]) {
					if (upper_max < num[j + 1] - num[j])
						upper_max = num[j + 1] - num[j];
				}
				if (num[j] > num[j + 1]) {
					if (down_max < num[j] - num[j + 1])
						down_max = num[j] - num[j + 1];
				}
			}
			System.out.println(upper_max + " " + down_max);
		}
	}
}

Measured memory_bytes: 12000
#include <algorithm>
#include <bitset>
#include <complex>
#include <cstdio>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

using namespace std;

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

typedef long long ll;

const int Inf = 1e9;
const double EPS = 1e-9;

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

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

int bitCount(long bits) {
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, y;  cin >> n >> y;
    for (int i = n; i >= 0; --i) {
      for (int j = n - i; j >= 0; --j) {
        for (int k = n - i - j; k >= 0; --k) {
          if (i * 10000 + 5000 * j + 1000 * k == y && i + j + k == n) {
            cout << i << " " << j << " " << k << '\n';
            return 0;
          }
        }
      }
    }
    cout << "-1 -1 -1" << '\n';

    return 0;
}


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

int main(){
  int N,K;
  string S;
  cin>>N>>K>>S;
  if(S[K-1]=='A'){
    S[K-1]='a';
  }
  else if(S[K-1]=='B'){
    S[K-1]='b';
  }
  else if(S[K-1]=='C'){
    S[K-1]='c';
  }
  cout<<S<<endl;
}


Measured memory_bytes: 256
//#pragma warning disable
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System;
using System.Numerics;
using System.Threading.Tasks;
using static System.Math;
using static System.Console;
class Z { static void Main() => new K(); }
class K
{
	int F() => int.Parse(ReadLine());
	long FL() => long.Parse(ReadLine());
	int[] G() => ReadLine().Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();
	long[] GL() => ReadLine().Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries).Select(long.Parse).ToArray();
	public const int MOD = 1000000007;
	public K()
	{
		SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
		Solve();
		Out.Flush();
	}
	void Solve()
	{
		var n = F();
		var x = 1;
		while (x * x <= n) x++;
		x--;
		Console.WriteLine(x * x);
	}
}


Measured memory_bytes: 13140
K, N = map(int, input().split())
A = list(map(int, input().split()))

dmax = K - A[N-1] + A[0]
apre = -(K - A[N-1])
for a in A:
  d = a - apre
  if d > dmax:
    dmax = d
  apre = a

print(K - dmax)

Measured memory_bytes: 26000
import itertools
N, M, Q = map(int, input().split())
P = []
LR = [[0] * (N+1) for _ in range(N+1)] 
for m in range(M):
    l, r = map(int, input().split())
    LR[l][r] += 1

for q in range(Q):
    p = list(map(int, input().split()))
    P.append(p)

csum = []
for L in LR:
    a = list(itertools.accumulate(L))
    csum.append(a)

for p in P:
    ans = 0
    l, r = p
    for c in csum[l:r+1]:
        ans += (c[r] - c[l-1])
    print (ans)


Measured memory_bytes: 82520
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include <math.h>

using namespace std;

#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
static const ll maxLL = (ll) 1 << 62;
const ll MOD = 1000000007, INF = 1e18;

//pair比較
template<typename T1=int, typename T2=int>
bool pairCompare(const pair<T1, T2> &firstElof, const pair<T1, T2> &secondElof) {return firstElof.second > secondElof.second;}

//mapの最大値
int mapMaxValue(std::map<ll, int> m) {int max = 0;for (std::map<ll, int>::iterator it = m.begin(); it != m.end(); it++) {if (max < it->second) max = it->second;}return max;}

//素数判定
template<typename T=int>
bool isPrime(T n) {if (n < 2) { return false; }for (int i = 2; i * i <= n; i++) { if (n % i == 0) { return false; }}return true;}

//約数列挙
template<typename T=int>
vector<T> getDivisor(T n) {vector<T> v;for (T i = 1; i * i <= n; i++) {if (n % i == 0) {v.push_back(i);if (i != n / i) { v.push_back(n / i); }}}sort(v.begin(), v.end());return v;}

//最大公約数
template<typename T=int>
T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

//素因数分解
template<typename TP=int, typename TPOW=int>
vector<pair<TP, TPOW>> factorize(TP n) {vector<pair<TP, TPOW>> res;for (TP i = 2; i * i < n; ++i) {if (n % i) continue;res.emplace_back(i, 0);while (n % i == 0) {n /= i;res.back().second++;}}if (n != 1) res.emplace_back(n, 1);return res;}

int main(void) {
    ll a, b;
    cin >> a >> b;
    ll g = gcd<ll>(a, b);
    auto f = factorize<ll, int>(g);
    cout << f.size() + 1 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const int MAX_N = 8;

double dist(double x1, double y1, double x2, double y2) {  // (x1, y1) と (x2, y2) のユークリッド距離
    return sqrt( (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2) );
}

int n;
double K = 1.0;
double ans = 0;
vector<int> used(MAX_N), v(MAX_N);
vector<double> x(MAX_N), y(MAX_N);

void perm(int depth) {  // {1, 2, … , n} の全順列を昇順に出力

    if(depth == n) {
        rep(i, n-1) {
            ans += dist(x[v[i]], y[v[i]], x[v[i+1]], y[v[i+1]]);
        }
        return;
    }

    rep(i, n) {
        if(!used[i]) {
            used[i] = 1;
            v[depth] = i;
            perm(depth+1);
            used[i] = 0;
        }
    }

}

int main() {

    cin >> n;

    rep(i, n) {
        cin >> x[i] >> y[i];
    }

    for(int i = 1; i <= n; i++) {
        K *= i;
    }

    perm(0);

    ans /= K;

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mod 1000000007
#define pb push_back
#define ll long long
#define mp make_pair
using namespace std;
int main(){
	ll n;
	cin>>n;
	vector<ll> a;
	for(int i=0;i<n;i++){
		ll x;
		cin>>x;
		a.pb(x);
	}
	sort(a.begin(),a.end());
	if(n==2){
		cout<<a[1]-a[0]<<endl;
		return 0;
	}
	ll ans=0;
	ll num = (n-3)/2;
	ll res = 0;
	for(int i=0;i<num;i++){
		res += 2*a[n-1-i];
	}
	for(int i=0;i<2;i++){
		res += a[n-1-num-i];
	}
	for(int i=0;i<num+1;i++){
		res -= 2*a[i];
	}
	if(res>ans)ans=res;
	num = (n-2)/2;
	res = 0;
	for(int i=0;i<num;i++){
		res += 2*a[n-1-i];
	}
	for(int i=0;i<1;i++){
		res += a[n-1-num-i];
	}
	for(int i=0;i<num;i++){
		res -= 2*a[i];
	}
	for(int i=0;i<1;i++){
		res -= a[num+i];
	}
	if(res>ans)ans=res;
	num = (n-3)/2;
	res = 0;
	for(int i=0;i<num+1;i++){
		res += 2*a[n-1-i];
	}
	for(int i=0;i<num;i++){
		res -= 2*a[i];
	}
	for(int i=0;i<2;i++){
		res -= a[num+i];
	}
	if(res>ans)ans=res;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1400