akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

int main() {
    ll C = 1e9;
    ll S;
    cin >> S;
    ll x, y;
    x = S / C + !!(S % C);
    y = (C - (S % C)) % C;
    cout << 0 << " " << 0 << " " << 1 << " " << C << " " << x << " " << y
         << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    static int gcd (int x,int y) {return y>0?gcd(y,x%y):x;}
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        long A = sc.nextLong();
        long V = sc.nextLong();
        long B = sc.nextLong();
        long W = sc.nextLong();
        long T = sc.nextLong();
        if(A==B) {
            System.out.println("YES");
            return;
        }
        if(V<=W) {
            System.out.println("NO");
            return;
        }
        long dist = Math.abs(A-B);
        long diff = V-W;
        if(diff * T >= dist) {
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }
    }
}


Measured memory_bytes: 35792
#include<bits/stdc++.h>
using namespace std;
#define int    long long
#define pb     push_back
#define mp     make_pair
#define ff     first
#define ss     second
#define pqg    priority_queue<int,vector<int>,greater<int>>
#define mod    1000000007
#define inf    1e18
#define w(x)    int x; cin>>x; while(x--)
#define loop(i,a,n)		for(int i=a;i<n;i++)
#define rev_loop(i,a,n)	for(int i=n-1;i>=a;i--)
#define endl    "\n"
#define fast   	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

int32_t main()
{
	fast;
	string s;int k;
	cin >> k >> s;
	if(s.size() > k){
		s= s.substr(0,k);
		s += "...";
	}
	cout << s;
	return 0;
}
/*
	Created By Sunman :) <3 

*/


Measured memory_bytes: 3640
#include<bits/stdc++.h>
#define EM 100000000
using namespace std;
using LL = long long;
using P = pair<LL, LL>;
LL LINF = 1e18;
int INF = 1e9;
using vint = vector<int>;
using vLL = vector<LL>;

int main(){
	int N;
	cin >> N;
	vector<string>	ss(N+1);
	vint p(N+1), used(N+1, 0), ans;
	for(int i = 1;i <= N;i++){
		cin >> ss[i] >> p[i];
	}
	while(true){
		string s = "zzzzzzzzzzz";
		for(int j = 1;j <= N;j++){
			if(used[j] == 0){
				if(s.compare(ss[j]) > 0)	s = ss[j];
			}
		}
		vint vv;
		for(int j = 1;j <= N;j++){
			if(used[j] == 0 && s.compare(ss[j]) == 0){
				vv.push_back(j);
				used[j] = 1;
			}
		}

		if(vv.size() == 1){
			ans.push_back(vv[0]);
		}else{
			vector<P> vp;
			for(int k = 0;k < vv.size();k++)	vp.emplace_back(p[vv[k]], vv[k]);
			sort(vp.rbegin(),vp.rend());
			for(int k = 0;k < vp.size();k++){
				ans.push_back(vp[k].second);
			}
		}	
		int cnt = 0;
		for(int j = 1;j <= N;j++){
			if(used[j] == 1)	cnt++;
		}
		if(cnt == N)	break;
	}
	for(int i = 0;i < N;i++)	cout << ans[i] << endl;
}

Measured memory_bytes: 256
import java.util.*;
import java.util.Map.Entry;

import javax.swing.text.Segment;
import javax.xml.ws.WebEndpoint;

import java.io.*;
import java.lang.reflect.Array;
import java.math.BigInteger;

import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
 
public class Main //implements Runnable
{
//    static int dx[]={-1,0,1,0};
//    static int dy[]={0,-1,0,1};
	static double s;
	
    public static void main(String[] args)   throws Exception, IOException{        
//        long mod=1000000007;
        Reader sc = new Reader(System.in);
        PrintWriter out=new PrintWriter(System.out);

        int n=sc.nextInt();
        char c[]=sc.getCharSet();
        char a[]=new char[26];
        for (int i = 0; i < c.length; i++) {
            out.print((char)((c[i]+n-'A')%26+'A'));
		}
        

        out.println();
     	out.flush();
    }


    static void ret(String ans) {
    	System.out.println(ans);
    	System.exit(0);
    }
    
    static boolean validpos(int x,int y,int r, int c){
        return x<r && 0<=x && y<c && 0<=y;
    }

    static void db(Object... os){
        System.err.println(Arrays.deepToString(os));
    }
}

//
//class P {
//	int x, y, d;
//	P(int  x, int y, int d) {
//	  this.x=x;
//	  this.y=y;
//	  this.d=d;
//	}
//}

class P implements Comparable<P>{
    int a,b;
    P(int a, int b) {
    	this.b=b;
    	this.a=a;
    }

    public int compareTo(P p){
        return -p.a+a;//as
    }
}

class Reader
{ 
    private BufferedReader x;
    private StringTokenizer st;
    
    public Reader(InputStream in)
    {
        x = new BufferedReader(new InputStreamReader(in));
        st = null;
    }
    public String nextString() throws IOException
    {
        while( st==null || !st.hasMoreTokens() )
            st = new StringTokenizer(x.readLine());
        return st.nextToken();
    }
    public int nextInt() throws IOException
    {
        return Integer.parseInt(nextString());
    }
    public int[] nextIntArray(int size) throws IOException{
        int r[] = new int[size];
        for (int i = 0; i < size; i++) {
            r[i] = this.nextInt(); 
        }
        return r;
    }
    public long[] nextLongArray(int size) throws IOException{
        long r[] = new long[size];
        for (int i = 0; i < size; i++) {
            r[i] = this.nextLong(); 
        }
        return r;
    }
    public char[] getCharSet() throws IOException{
        return this.nextString().toCharArray();
    }    
    public long nextLong() throws IOException
    {
        return Long.parseLong(nextString());
    }
    public double nextDouble() throws IOException
    {
        return Double.parseDouble(nextString());
    }
}


Measured memory_bytes: 25044
#include <stdio.h>

int main(){
   int n;scanf("%d",&n);
   int a[100];for(int i = 0;i < n;i++)scanf("%d",&a[i]);
   int flag = 1;
   for(int i = 0;i < n;i++){
      if(a[i] % 2 == 0){
         if(!((a[i] % 3 == 0)||(a[i] % 5 == 0)))flag = 0;
      }
   }
   if(flag == 1)printf("APPROVED");
   else printf("DENIED");
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rep(i,n) for(int (i)=1;(i)<=(int)(n);(i)++)
#define forn(i,n,m) for(int (i)=(n);i<=(int)(m);(i)++)
#define pb push_back
#define mp make_pair
#define re return
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
using namespace std;
const int INF=1e9;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef queue <int> qi;
long long sumn=0;
int n,m;
int a[200200];
int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>m;
	for(int i=0;i<n;i++)
		cin>>a[i];
	sort(a,a+n);
	for(int i=0;i<n-m;i++)
		sumn+=a[i];
	cout<<sumn<<endl;
	return 0;
}


Measured memory_bytes: 1024
import java.util.Scanner;

public class Main{
    public void solve(){
        Scanner sc = new Scanner(System.in);
        int syu,mai;
        
        for(int i=0;i<4;i++){
            syu = sc.nextInt();
            mai =sc. nextInt();
            
            switch(syu){
                case 1:
                System.out.println(6000*mai);
                break;
                
                case 2:
                System.out.println(4000*mai);
                break;
                
                case 3:
                System.out.println(3000*mai);
                break;
                
                case 4:
                System.out.println(2000*mai);
                break;
            }
        }
    }
    
    public static void main(String[]args){
        Main obj = new Main();
        obj.solve();
    }
}

Measured memory_bytes: 17168
/*Marked Ancestor????§£????????????????????????????????????????????????????????¨????????¨??¨??????????????§?????????????????????????????§??????????????????
?????°???????????????????????????:1???????????????*/

#include<iostream>
#include<cstdio>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
#include<complex>
#include<string>
#include<cstring>

using namespace std;
#define rep2(x,from,to) for(long long x=(from);(x)<(to);(x)++)
#define rep(x,to) rep2(x,0,to)
#define INF 100000000
#define all(x) x.begin(),x.end()
typedef pair<long long,long long> P;
typedef pair<long long,P> PP;
long long n,q;
long long par[100005];
vector<long long> child[100005];
queue<P> mna;//marked nearest ancestor
long long mark[100005];
long long query[100005];
long long qquery[100005];
long long mnalist[100005];
string s;
long long ans;
int main()
{
	while(1)
	{
		rep(i,100005)
		{
			mark[i]=0;
			query[i]=0;
			qquery[i]=0;
			child[i].clear();
			par[i]=0;
			mnalist[i]=0;
		}
		ans=0;
		cin>>n>>q;
		if(n==0)break;
		rep(i,n-1)
		{
			cin>>par[i+1];
			par[i+1]--;
			child[par[i+1]].push_back(i+1);
		}
		mark[0]=1;
		rep(i,q)
		{
			cin>>s>>qquery[i];
			qquery[i]--;
			if(s=="M")
			{
				query[i]=1;
				mark[qquery[i]]++;
			}
		}
		mna.push(P(0,0));
		mnalist[0]=0;
		while(!mna.empty())
		{
			P p=mna.front();mna.pop();
			rep(i,child[p.first].size())
			{
				if(mark[child[p.first][i]]!=0)
				{
					mnalist[child[p.first][i]]=child[p.first][i];
					mna.push(P(child[p.first][i],child[p.first][i]));
				}
				else
				{
					mnalist[child[p.first][i]]=p.second;
					mna.push(P(child[p.first][i],p.second));
				}
			}
		}
		long long person;
		for(long long kkk=q-1;kkk>=0;kkk--)
		{
			if(query[kkk]==1)
			{
				mark[qquery[kkk]]--;
				if(mark[qquery[kkk]]==0)mnalist[qquery[kkk]]=mnalist[par[qquery[kkk]]];
			}
			else
			{
				person=mnalist[qquery[kkk]];
				while(person!=mnalist[person])
				{
					person=mnalist[person];
				}
				ans+=(person+1);
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 13304
#include <bits/stdc++.h>
using namespace std;
int main(void){
  int N;
  cin >> N;
  int a[N+1];
  a[0] = -1;
  for(int i=1; i<=N; i++) cin >> a[i];
  
  int b[N+1];
  b[0] = -1;
  for(int i=1; i<=N; i++) b[i] = 0;
  // 箱iに入れるボールの数 0or1
  
  int halfN = N/2+1;
  for(int i=halfN; i<=N; i++){
    b[i] = a[i];
  }
  
  for(int i=halfN-1; i>=1; i--){
    int tmpSum = 0;
    for(int j=i*2; j<=N; j+=i) tmpSum += b[j];
    b[i] = (tmpSum%2 != a[i]);
  }
  int ans = 0;
  for(int i=1; i<=N; i++) if(b[i]) ans++;
  cout << ans << endl;
  for(int i=1; i<=N; i++) if(b[i]) cout << i << " ";
  cout << endl;
/*  
  for(int i=1; i<=N; i++){
    cout << b[i] << " ";
  }
*/
  
  return 0;
}

Measured memory_bytes: 2432
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using static System.Math;
using static System.Array;
using static AtCoder.Tool;
namespace AtCoder
{
    class AC
    {
        const int mod = 1000000007;
        const int INF = int.MaxValue / 2;
        const long SINF = long.MaxValue / 2;
        static readonly int[] dx = { 0, 1, 0, -1 };
        static readonly int[] dy = { 1, 0, -1, 0 };

        

        static void Main(string[] args)
        {
            //var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            //Console.SetOut(sw);
            var cin = new Scanner();

            string s = Console.ReadLine();
            Console.WriteLine(s.StartsWith("YAKI") ? "Yes" : "No");

            //Console.Out.Flush();
        }
        struct Edge
        {
            public int from;
            public int to;
            public Edge(int f,int t)
            {
                from = f;
                to = t;
            }
        }

        
    }
    public class Scanner
    {
        public int[] SplitRead()
        {
            int[] array = Console.ReadLine().Split().Select(int.Parse).ToArray();
            return array;
        }
        public long[] SplitReadL()
        {
            long[] array = Console.ReadLine().Split().Select(long.Parse).ToArray();
            return array;
        }
    }

    public static class Tool
    {
        static public void Initialize<T>(ref T[] array, T initialvalue)
        {
            for (var i = 0; i < array.Length; i++)
            {
                array[i] = initialvalue;
            }
        }
        static public long Modulo(long value, long mod)
        {
            long r = value % mod;

            if (r * mod < 0)
            {
                r += mod;
            }
            return r;
        }
    }

    

}

Measured memory_bytes: 13396
#include<bits/stdc++.h>
#define MAX 1000000
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);	
	int n,k;
	cin>>n>>k;
	int v[n+1],ans = 0;
	for(int i=0;i<n;++i)
		cin>>v[i],ans = max(ans,v[i]);
	int l=1,r=1e9;
	while(l<=r)
	{
		int c = (l+r)/2;
		int total = 0;
		for(int i=0;total<=k&&i<n;++i)		
			total += v[i]*1.0/c-(v[i]%c==0?1:0);
		if(total<=k)
			ans = c,r = c-1;
		else
			l = c+1;
	}
	cout<<ans<<endl;
	return 0;
}

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

int main(){
    
    int n, x;
    
    while(1){
        int count = 0;
        cin >> n >> x;
        if((n==0) && (x==0)) break;
        for(int i=1; i<=n; i+=1){
            for(int j=1; j<=n; j+=1){
                for(int k=1; k<=n; k+=1){
                    if((i+j+k) == x){
                        if((i!=j) && (j!=k) && (k!=i)) {
                            count += 1;
                        }
                    }
                }
            }
        }
        count /= 6;
        cout << count << endl;
    }
    return 0;
}


Measured memory_bytes: 3068
n = int(input())
s = list(input())
pl = 0
for i in range(n):
    if s[i] == "(":
        pl += 1
    elif pl >= 1:
        pl -= 1
if pl >= 0:
    s += [")"] * pl
pl = 0
for i in range(1, len(s)+1):
    if s[-i] == ")":
        pl += 1
    elif pl >= 1:
        pl -= 1
if pl >= 0:
    s.insert(0, "(" * pl)
print("".join(s))

Measured memory_bytes: 3064
inList = []
for i in range(5):
    inList.append(int(input()))
k = int(input())
kList = []
for i in range(5):
    for j in range(1, 5):
        kyori = int(abs(inList[i] - inList[j]))
        kList.append(kyori)
ansFlg = True
for i in kList:
    if k < i:
        ansFlg = False
if ansFlg:
    print('Yay!')
else:
    print(':(')


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = int(A); I < int(B); ++I)
#define FORR(I,A,B) for(ll I = int((B)-1); I >= int(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=1e18+7;
const ll MOD=1e9+7;


string to_mcxi(int x){
	string ans;
	if( int(x/1000) > 1 ){
		ans += '0'+int(x/1000);
		ans += 'm';
	}else if( int(x/1000) == 1 ){
		ans += 'm';
	}
	x = x%1000;
	if( int(x/100) > 1 ){
		ans += '0'+int(x/100);
		ans += 'c';
	}else if( int(x/100) == 1 ){
		ans += 'c';
	}
	x = x%100;
	if( int(x/10) > 1 ){
		ans += '0'+int(x/10);
		ans += 'x';
	}else if( int(x/10) == 1 ){
		ans += 'x';
	}
	x = x%10;
	if( x > 1 ){
		ans += '0'+x;
		ans += 'i';
	}else if( x == 1 ){
		ans += 'i';
	}
	return ans;
}

int to_int(string x){
	vector<char> m={'m','c','x','i'};
	vector<int> mm={1000,100,10,1};
	int ans=0,p=1;
	FOR(i,0,x.size()){
		if(x[i]>='0'&&x[i]<='9'){
			p = x[i]-'0';
		}else{
			FOR(j,0,4){
				if(x[i]==m[j]){
					ans += p*mm[j];
					p = 1;
				}
			}
		}
	}
	return ans;
}

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

	
	ll n;
	cin >> n;
	FOR(i,0,n){
		string a,b;
		cin >> a >> b;
		cout << to_mcxi(to_int(a)+to_int(b)) << endl;
	}

}



Measured memory_bytes: 3152
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(I,A,B) for(ll I = int(A); I < int(B); ++I)
const ll MOD=1e9+7;


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

	int N;
	cin >> N;
	int a[N][N];
	FOR(i,0,N)FOR(j,0,N){
		cin>>a[i][j];
	}

	int dp[N+1][(1<<N)]={};

	dp[0][0] = 1;
	FOR(i,0,N){
		int j = (1<<i)-1;
		int jbreak = j<<(N-i);
		while(1){
			FOR(k,0,N){
				if( a[i][k] && !(j&(1<<k)) ){
					(dp[i+1][j+(1<<k)] += dp[i][j] ) %= MOD;
				}
			}
			if(j==jbreak)break;
			j += j&-j;
			j |= (1<<(i-bitset<32>(j).count()))-1;
		}
	}

	cout << dp[N][(1<<N)-1] << endl;

}


Measured memory_bytes: 180480
N, Q = map(int, input().split())
str = input()
length = [list(map(int, input().split())) for _ in range(Q)]

ans = [0 for _ in range(N)]
for i in range(1, N):
    if (str[i-1] == "A"):
        if (str[i] == "C"):
            ans[i] = ans[i-1] + 1
        else:
            ans[i] = ans[i-1]
    else:
        ans[i] = ans[i-1]
        if i != N-1:
            ans[i+1] = ans[i-1]
        i += 1

for l1, l2 in length:
    # print(ans)
    print(ans[l2-1] - ans[l1-1])


Measured memory_bytes: 30636
#-*-coding:utf-8-*-

def main():
    n = int(input())

    max_cnt = 0
    max_num = 1
    for i in range(n, 0, -1):
        num = i
        cnt = 0
        while num % 2 == 0:
            cnt += 1
            num /= 2
        if max_cnt < cnt:
            max_cnt = cnt
            max_num = i
    print(max_num)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define mins(a,b) a=min(a,b)
#define maxs(a,b) a=max(a,b)
using namespace std;
int main(){
  int n,ans=0;
  cin>>n;
  int num[n];
  int x[100010]={};
  for(int i=0;i<n;i++){
    cin>>num[i];
  }
  for(int i=0;i<n;i++){
    int c;
    c=num[i];
    x[c]++;
    x[c-1]++;
    x[c+1]++;
  }
  for(int i=0;i<100010;i++){
    ans=max(ans,x[i]);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main(void){
    
    //*
    int a, b;
    cin >> a >> b ;
    //*/
    
    /*
    vector<int> vec(4);
    cin >> vec.at(0) >> vec.at(1) >> vec.at(2) ;
    
    sort(vec.begin(), vec.end());
    */
    
    //*
    if(a * b % 2 == 0){
        cout << "Even" << endl;
    } else {
        cout << "Odd" << endl;
    }
    //*/
    
    //cout << a << endl;

    return 0; 
}


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

const ll N = 1e5;

ll n, m;
ll indeg[N + 1];

vector<ll> kaaret[N + 1];
vector<ll> edel[N + 1];

ll dp[N + 1];

int main() {
    cin >> n >> m;
    for (ll i = 0; i < m; i++) {
        ll x, y; cin >> x >> y;
        kaaret[x].push_back(y);
        edel[y].push_back(x);
        indeg[y]++;
    }
    // alut = indeg 0
    queue<ll> q;
    for (ll i = 1; i <= n; i++) {
        if (indeg[i] == 0) {
            q.push(i);
        }
    }
    ll ans = 0;
    while (!q.empty()) {
        ll k = q.front();
        q.pop();
        // dp
        for (ll e : edel[k]) {
            dp[k] = max(dp[k], dp[e] + 1);
        }
        ans = max(ans, dp[k]);
        for (ll nb : kaaret[k]) {
            if (--indeg[nb] == 0) {
                q.push(nb);
            }
        }
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 12800
#include <cstdio>

int a[100],n,count = 0;


void print(){
    for(int i=0;i<n;i++){
        if(i>0) printf(" ");
        printf("%d",a[i]);
    }
    printf("\n");
    printf("%d\n", count);
}


void bubbleSort(){
    int i = 0,j,flag = 1,tmp;
    while(flag == 1){
        flag = 0;
        for(j=n-1;j>i;j--){
            if(a[j-1]>a[j]){
                count++;
                tmp = a[j];
                a[j] = a[j-1];
                a[j-1] = tmp;
                flag = 1;
            }
        }
        i++;
    }
}


int main(){
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    bubbleSort();
    print();
    return 0;
}

Measured memory_bytes: 2704
#include<bits/stdc++.h>
using namespace std;
int main(){
    string S,T;
    cin>>S>>T;
    int count=0;
    for(int i=0;i<S.length();i++){
        if(S[i]==T[i]){
            count++;
        }
    }
    cout<<count<<endl;
    return 0;
}

Measured memory_bytes: 256
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr
  
N,P = map(int,input().split())
lis=factorization(P)
#print(lis)
maxi=1

for i,kumi in enumerate(lis):
  p= kumi[1]//N
  maxi *= (kumi[0]**p)
    
print(maxi)

Measured memory_bytes: 3064
#include<cstdio>
#include<cstdlib>

typedef struct{
    int t;
    int x;
    int y;
}Plan;

int n;
Plan plan[100000];

bool solve(void);
int manhattan_distance(int x1, int y1, int x2, int y2);

int main(void){
    scanf("%d", &n);
    for(int i = 0; i < n; i++){
        scanf("%d %d %d", &plan[i].t, &plan[i].x, &plan[i].y);
    }

    printf("%s\n", solve() ? "Yes" : "No");

    return 0;
}

bool solve(void){
    int t = 0;
    int x = 0;
    int y = 0;
    
    for(int next = 0; next < n; next++){
        if(plan[next].t - t < manhattan_distance(plan[next].x, plan[next].y,x, y)){
            return false;
        }

        if((plan[next].t - t) % 2 != manhattan_distance(x, y, plan[next].x, plan[next].y) % 2){
            return false;
        }

        t = plan[next].t; x = plan[next].x; y = plan[next].y;
    }

    return true;
}

int manhattan_distance(int x1, int y1, int x2, int y2){
    return abs(x1 - x2) + abs(y1 - y2);
}

Measured memory_bytes: 1280
n = int(input())
s = [input() for _ in range(n)]

import collections
c0 = collections.Counter(s)
c1 = c0.most_common()
max = c1[0][1]
l = []
for x, i in c0.items():
    if i == max:
        l.append(x)
ans = sorted(l)
for i in ans:
    print(i)

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

int koy(int a,int b){
  int R=a; int L=b;
    while(R!=0 && L!=0){
      if(R<L)
        L%=R;
      else
        R%=L;
    }
    if(R==0)
      return L;
    else
      return R;
}

int  main(){
  int N,X;
  cin >> N >> X;
  int st;
  cin >> st;
  st = abs(st-X);
  
  int L;
  for(int i=0;i<N-1;i++){
    cin >> L;
    L = abs(L-X);
    st = koy(st,L);
    //Lとstの最大公約数を求める
  }
  cout << st;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
    int a,b,c,d;cin>>a>>b>>c>>d;
    while(1){
        c-=b;
        if(c<=0){
            puts("Yes");
            break;
        }
        a-=d;
        if(a<=0){
            puts("No");
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
    #include<math.h>
    #define rep(i,n) for (int i = 0; i < (n) ; ++i)
    using namespace std;
    using ll = long long ;
    using P = pair<int , int> ;
    #define PI 3.14159265358979323846264338327950
    #define INF 1e18 
     
    int main() {
        int n ;
        cin >> n ;
        vector<int> a (n + 1) ;
        rep(i, n){
            cin >> a[i + 1] ;
        }
        vector<int> b (n + 1) ;
        for(int i = n ; i >= 1 ; i--){
            int sum = 0 ;
            for(int j = i ; j <= n ; j += i){
                sum += b[j] ;
            }
            if(sum % 2 == a[i]){
                b[i] = 0 ;
            }
            else {
                b[i] = 1 ;
            }
        }
        vector<int> ans ; 
        rep(i, n){
            if(b[i + 1] == 1){
                ans.push_back(i + 1) ;
            }
        }
        cout << ans.size() << endl ;
        if(ans.size() != 0){
            for(int u : ans){
                cout << u << " ";
            }
            cout << endl ;
        }
    }

Measured memory_bytes: 5392
#include<stdio.h>
#include<stdlib.h>
#include<stdint.h>
#include<inttypes.h>
#include<string.h>

typedef int32_t i32;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define ALLOC(size,type) ((type*)calloc((size),sizeof(type)))

#define POS(i, j) ((i) * (m + 1) + (j))

void run (void) {
  char *s = ALLOC (3000 + 1, char);
  char *t = ALLOC (3000 + 1, char);
  scanf ("%s%s", s, t);
  i32 n = strlen (s);
  i32 m = strlen (t);
  i32 *dp = ALLOC ((n + 1) * (m + 1), i32);
  for (i32 i = n - 1; i >= 0; --i) {
    for (i32 j = m - 1; j >= 0; --j) {
      if (s[i] == t[j]) {
        dp[POS(i, j)] = 1 + dp[POS(i + 1, j + 1)];
      } else {
        dp[POS(i, j)] = MAX (dp[POS(i + 1, j)], dp[POS(i, j + 1)]);
      }
    }
  }
  for (i32 i = 0, j = 0; i < n && j < m;) {
    if (s[i] == t[j]) {
      putchar (s[i]);
      ++i;
      ++j;
    } else if (dp[POS(i, j)] == dp[POS(i + 1, j)]) {
      ++i;
    } else {
      ++j;
    }
  }
  puts ("");
}

int main (void) {
  run();
  return 0;
}


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

using namespace std;

int main() {
    int n;
    while(~scanf("%d",&n)) {
        if( n < 1200) cout << "ABC" << endl;
        else if(n < 2800) cout << "ARC" << endl;
        else cout << "AGC" << endl;
    }
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long 
#define vpnt(ans) for(ll i = 0; i < ans.size(); i++) cout << ans[i] << (i + 1 < ans.size() ? ' ' : '\n');
#define setbit(x,k) (x |= (1 << k))
#define clearbit(x,k) (x &= ~(1ll << k))
#define checkbit(x,k) (x & (1ll << k))
#define mp make_pair
#define scl(x) scanf("%lld",&x)
#define sci(x) scanf("%d",&x)
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define pii pair<int,int> 
#define YES printf("YES\n")
#define Yes printf("Yes\n")
#define yes printf("yes\n")
#define NO printf("NO\n")
#define No printf("No\n")
#define no printf("no\n")
#define nn printf("\n") 
#define mod 10000007
using namespace std;

string s,t,res=""; int ls, lt;
int ans[3003][3003];
int dp[3003][3003];

int solve(int p1, int p2)
{
    if(p1 >= ls || p2 >= lt) return 0; 
    if(dp[p1][p2]!=-1) return dp[p1][p2];
    int mx = 0, res = 0;
    if(s[p1] == t[p2]) {
        res = 1 + solve(p1+1, p2+1);
        if(res > mx){
            mx = res;
            ans[p1][p2] = 0;
        }
    }
    else 
    {
        res = solve(p1+1, p2);
        if(res > mx){
            mx = res;
            ans[p1][p2] = 1;
        }
        res = solve(p1, p2+1);
        if(res > mx){
            mx = res;
            ans[p1][p2] = 2;
        }
    } 
    return dp[p1][p2] = mx;
}

void print_ans(int p1, int p2){
    if(p1 >= ls || p2 >= lt) return;

    if(s[p1]==t[p2]) res += s[p1];
    if(ans[p1][p2]==0) print_ans(p1+1, p2+1);
    else if(ans[p1][p2]==1) print_ans(p1+1, p2);
    else print_ans(p1, p2+1);
}

int main()
{
    memset(dp, -1, sizeof(dp));
    cin>>s>>t;
    ls = s.size();
    lt = t.size();
    solve(0, 0);
    print_ans(0, 0);
    cout << res << "\n";

}

Measured memory_bytes: 74008
#include <cstdio>
int n,k;
long long ans;
int main()
{
	scanf("%d%d",&n,&k);
    for(int x=k;x<=n-1;x++)
	{
        int t=n-x;
        for(int b=x+1;b<=n;)
        {
            int N=0;
            if(t/b)N=t/(t/b);
            else N=n;
            ans+=1ll*(N-b+1)*((t/b)+(x>0));
            b=N+1;
        }
    }
    printf("%lld\n",ans);
}

Measured memory_bytes: 128
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, std.bitmanip;

immutable long MOD = 10^^9 + 7;

void main() {
    auto s = readln.split.map!(to!int);
    auto N = s[0];
    auto M = s[1];
    auto G = new int[][](N);
    auto D = new int[](N);
    foreach (i; 0..M) {
        s = readln.split.map!(to!int);
        G[s[0]-1] ~= s[1]-1;
        D[s[1]-1] += 1;
    }

    DList!int q;
    foreach (i; 0..N) if (D[i] == 0) q.insertBack(i);

    auto dp = new long[](N+1);

    while (!q.empty) {
        auto n = q.front;
        q.removeFront;
        foreach (m; G[n]) {
            dp[m] = max(dp[m], dp[n] + 1);
            D[m] -= 1;
            if (D[m] == 0) q.insertBack(m);
        }
    }

    dp.reduce!max.writeln;
}


Measured memory_bytes: 12540
import math
N,D=map(int,input().split())
X=[list(map(int,input().split()))for i in range(N)]
ans=0
dist=0.0
for i in range(N):
    for j in range(i+1,N):
        dist=0.0
        for k in range(D):
            dist+=(X[i][k]-X[j][k])**2
        dist=math.sqrt(dist)
        if dist.is_integer() is True:
            ans+=1
print(ans)

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a, b, c, ans;
  cin >> a >> b >> c;
  int tmp;
  if(floor(b / a) < c) {
    cout << floor(b / a) << endl;
  } else {
    cout << c << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long LL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

using namespace std;

int main(void)
{
  LL k,a,b;
  cin >> k >> a >> b;
  if(k < a) {
    cout << k+1 << endl;
    return 0;
  }
  LL leftk = k - a + 1;
  if(b - a > 2) {
    cout << (leftk / 2) * (b - a) + a + leftk % 2 << endl;
  } else {
    cout << k+1 << endl;
  }
  return 0;
}


Measured memory_bytes: 256
// ----- In the name of ALLAH, the Most Gracious, the Most Merciful -----

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

#define NINJA ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define fo(i,n) for(int i=0;i<n;i++)
#define Fo(i,k,n) for(int i=k;i<n;i++)
#define for1(i,n) for(int i=1;i<=n;i++)
#define dloop(i,n) for(int i=n-1;i>=0;i--)
#define iii tuple<int,int,int>
#define vi vector<int>
#define ii pair<int,int>
#define vii vector<ii>
#define int long long
#define ld long double
#define pb push_back
#define endl "\n"
#define setbits __builtin_popcountll
#define mp map<int,int>
#define F first
#define S second
#define sz(v) (int)v.size()
#define mod 1000000007
#define inf (int)1e18

const int mxn = 2e6+10;
int a[mxn];

int32_t main(){
	NINJA;

	int n,k; cin >> n >> k;
	for1(i,n) cin >> a[i];

	int prev = 1;
	for(int i=k+1;i<=n;i++){
		if(a[i-k]<a[i]){
			cout << "Yes" << endl;
		}else{
			cout << "No" << endl;
		}
	}
	
	return 0;
}

Measured memory_bytes: 5216
fun main(args: Array<String>){
    val inputa = readLine()!!.split(" ")
    val n = inputa[0].toInt()
    val m = inputa[1].toInt()

    val inputb = readLine()!!.split(" ")
    val list = mutableListOf<Int>()

    for(i in 0..m-1){
        list.add(inputb[i].toInt())
    }

    list.sort()

    val ablist = mutableListOf<Int>()

    for(i in 0..m-2){
        ablist.add(Math.abs(list[i+1]-list[i]))
    }

    ablist.sort()


    var ans = 0

    for(i in 0..m-n-1){
        ans += ablist[i]
    }

    println(ans)
}


Measured memory_bytes: 51960
def factorization(n):
    res = set()
    tmp = n
    for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
        if tmp % i == 0:
            cnt = 0
            while tmp % i== 0:
                cnt += 1
                tmp //= i
            res.add(i)
    if tmp != 1:
        res.add(tmp)
    if not res:
        res.add(n)
    return res

a, b = map(int,input().split())
ans = factorization(a) & factorization(b) | {1}
print(len(ans))


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

class gfg 
{ 
 public : int gcd(int a, int b){ 
    if (a == 0) 
        return b;  
    return gcd(b % a, a);  
 } 
  
   
// Function to return LCM of two numbers  
  ll lcm(ll a, ll b)  
 {  
    return (a*b)/gcd(a, b);  
 }  
} ; 

int main()
{
    
   int a,b;
   cin>>a>>b;
   gfg obj;
   //ll z=lcm(a,b);
   cout<<obj.lcm(a,b);
}

Measured memory_bytes: 256
#include <stdio.h>

int main (void){
unsigned long long int  a,b,n;
scanf("%llu",&n);
scanf("%llu",&a);
scanf("%llu",&b);

if(a == 0)
    printf("0\n");
else if(n%(a+b) < a)
    printf("%llu\n",n/(a+b)*a+n%(a+b));
else 
     printf("%llu\n",n/(a+b)*a+a);
return 0;
}

Measured memory_bytes: 128
# ITP1_6_D_0001.rb
a = Array.new
b = Array.new


n,m = gets.split.map(&:to_i)
n.times do
	a_buff = Array.new
	a_buff = gets.split.map(&:to_i)
	a << a_buff
end

m.times do
	b << gets.to_i
end

c = Array.new(n, 0)

n.times do |n1|
	m.times do |m1|
		c[n1] += a[n1][m1] * b[m1]
	end
end

puts c.join("\n")

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

class Program
{
    static string InputPattern = "InputX";

    static List<string> GetInputList()
    {
        var WillReturn = new List<string>();

        if (InputPattern == "Input1") {
            WillReturn.Add("4");
            WillReturn.Add("1 -3 1 0");
            //4
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("5");
            WillReturn.Add("3 -6 4 -5 7");
            //0
        }
        else if (InputPattern == "Input3") {
            WillReturn.Add("6");
            WillReturn.Add("-1 4 3 2 -5 4");
            //8
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }

    static void Main()
    {
        List<string> InputList = GetInputList();
        int[] AArr = InputList[1].Split(' ').Select(X => int.Parse(X)).ToArray();

        long Cost1 = Solve1(AArr);
        long Cost2 = Solve2(AArr);
        Console.WriteLine(Math.Min(Cost1, Cost2));
    }

    //プラス、マイナス、プラスの順にするコストを求める
    static long Solve1(int[] pArr)
    {
        long Cost = 0;
        long RunSum = 0;

        for (int I = 0; I <= pArr.GetUpperBound(0); I++) {
            RunSum += pArr[I];
            if (I % 2 == 0) {
                if (RunSum > 0) continue;
                Cost += Math.Abs(RunSum) + 1;
                RunSum = 1;
            }
            else {
                if (RunSum < 0) continue;
                Cost += Math.Abs(RunSum) + 1;
                RunSum = -1;
            }
        }
        return Cost;
    }

    //マイナス、プラス、マイナスの順にするコストを求める
    static long Solve2(int[] pArr)
    {
        long Cost = 0;
        long RunSum = 0;

        for (int I = 0; I <= pArr.GetUpperBound(0); I++) {
            RunSum += pArr[I];
            if (I % 2 == 1) {
                if (RunSum > 0) continue;
                Cost += Math.Abs(RunSum) + 1;
                RunSum = 1;
            }
            else {
                if (RunSum < 0) continue;
                Cost += Math.Abs(RunSum) + 1;
                RunSum = -1;
            }
        }
        return Cost;
    }
}


Measured memory_bytes: 27996
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const double EPS = 1e-8;

template<typename T> T chmax(T& a, const T& b){return a = (a > b ? a : b);}
template<typename T> T chmin(T& a, const T& b){return a = (a < b ? a : b);}

int main(){
    int k;
    cin >> k;
    ll ans = 0;
    REP(i, 1, k+1) REP(j, 1, k+1) REP(l, 1, k+1) ans += gcd(i, gcd(j, l));
    cout << ans << '\n';
    return 0;
}

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

string s ; 
long long int l , cnt[26], ans ; 


int main() {
	cin>>s ; 
	l = s.length() ; 
	memset(cnt,0,sizeof(cnt)) ; 
	for(int i=0;i<l;i++){
		cnt[s[i] - 'a']++ ; 
	}
	ans = ((l) * (l-1))/2 ; 
	for(int i=0;i<26;i++){
		ans -= (cnt[i] * (cnt[i] - 1))/2 ; 
	}
	printf("%lld",ans+1) ; 
	return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
int main() {
	int r,D,x;
	cin >> r >> D>>x;
	for (int i = 1; i <= 10; i++) {
		x = r * x - D;
		cout << x << endl;
	}

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using  namespace std;
typedef long long ll;
#define RAP(i, n) for(ll i=0;i<(n);i++)
#define FOR(i, a, b) for(ll i=(a);i<(b);i++)
#define MFOR(i, a, b) for(ll i=(a);i>=(b);i--)

int main(){
    ll h, w, check, ans=-1, num;
    cin >> h >> w;
    char S[h][w];
    vector<vector<ll>> w_num(h), h_num(h);
    RAP(i, h){
      w_num[i].resize(w, 0);
      h_num[i].resize(w, 0);
    }
    RAP(i, h){
        RAP(j, w){
            cin >> S[i][j];
        }
    }
    RAP(i, h){
        RAP(j, w){
          check = j;
          num = -1;
          while(check<w && S[i][check]!='#'){
            check++;
            num++;
          }
          for(j;j<check;j++){
            w_num[i][j] = num;
          }
        }
    }
    RAP(i, w){
        RAP(j, h){
          check = j;
          num = 0;
          while(check<h && S[check][i]!='#'){
            check++;
            num++;
          }
          for(j;j<check;j++){
            h_num[j][i] = num;
          }
        }
    }
    RAP(i, h){
        RAP(j, w){
          ans = max(ans, w_num[i][j] + h_num[i][j]);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 66816
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  string s;
  cin>>n>>s;
  string p="",q="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  for(int i=0;i<s.size();i++)
    for(int j=0;j<q.size();j++)
      if((s[i]-'A'+n)%26 == q[j]-'A') p+=q[j];
  cout<<p;
}
  

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

int main(void) {
int H, W;
	cin >> H >> W;

	vector<string> S(H);

	for (int i = 0; i < H; i++)
	{
		cin >> S[i];
	}

	vector<vector<int>> L(H, vector<int>(W));
	vector<vector<int>> R(H, vector<int>(W));
	vector<vector<int>> U(H, vector<int>(W));
	vector<vector<int>> D(H, vector<int>(W));
		
	for (int i = 0; i < H; i++)
	{		
		for (int j = 0; j < W; j++)
		{
			if (S[i][j] == '#')
			{
				L[i][j] = 0;
			}
			else if(j >= 1)
			{
				L[i][j] = L[i][j - 1] + 1;
			}
			else
			{
				L[i][j] = 1;
			}
		}
	}

	for (int i = 0; i < H; i++)
	{
		for (int j = W - 1; j >= 0; j--)
		{
			if (S[i][j] == '#')
			{
				R[i][j] = 0;
			}
			else if(j != W - 1)
			{
				R[i][j] = R[i][j + 1] + 1;
			}
			else
			{
				R[i][j] = 1;
			}
		}
	}

	
	for (int j = 0; j < W; j++)
	{
		for (int i = 0; i < H; i++)
		{
			if (S[i][j] == '#')
			{
				D[i][j] = 0;
			}
			else if(i >= 1)
			{
				D[i][j] = D[i - 1][j] + 1;
			}
			else
			{
				D[i][j] = 1;
			}
		}
	}

	
	for (int j = 0; j < W; j++)
	{
		for (int i = H  - 1; i >= 0; i--)
		{		
			if (S[i][j] == '#')
			{
				U[i][j] = 0;
			}
			else if(i != H - 1)
			{
				U[i][j] = U[i + 1][j] + 1;
			}
			else
			{
				U[i][j] = 1;
			}
		}
	}

	vector<int> ans;
	for (int i = 0; i < H; i++)
	{
		for (int j = 0; j < W; j++)
		{
			ans.push_back(L[i][j] + R[i][j] + U[i][j] + D[i][j] - 3);
		}
	}

	sort(ans.begin(), ans.end(), greater<int>());

	cout << ans[0] << endl;

    return 0;
}

Measured memory_bytes: 85492
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

int mod = 1000000007;

long long f(int a, int k);

int main()
{
	long long n, k;
	cin >> n >> k;
	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}

	vector<pair<long long, long long>> b(n);
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < i; j++) {
			if (a[i] > a[j]) {
				b[i].first++;
			}
		}
		for (int j = i + 1; j < n; j++) {
			if (a[i] > a[j]) {
				b[i].second++;
			}
		}
	}

	long long ans = 0;
	for (int i = 0; i < n; i++) {
		ans += f(b[i].first, k - 1) + f(b[i].second, k);
		ans %= mod;
	}
	cout << ans << endl;

	return 0;
}

long long f(int a, int k)
{
	long long calc = (long long)k * (k + 1) / 2;
	calc %= mod;
	calc *= a;
	calc %= mod;

	return calc;
}

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

int main(){
    int n;
    cin>>n;
    map<int,int>mp;
    rep(i,n){
        int a; cin>>a;
        mp[a]++;
    }
    int ans=0;
    for(auto&p:mp){
        if(p.second%2==1)ans++;
    }
    cout<<ans<<endl;
    return 0;
}

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

using namespace std;

void solve(int n,int r){
	int le,ri,h;
	int right[21]={};
	int left[21]={};
	for(int i=0;i<n;i++){
		cin >> le >> ri >> h;
		if(le<0&&ri<=0){
			for(int j=-ri;j<-le;j++){
				left[j] = max(left[j],h);
			}
		}else if(le<0&&ri>0){
			for(int j=0;j<-le;j++){
				left[j] = max(left[j],h);
			}
			for(int j=0;j<ri;j++){
				right[j] = max(right[j],h);
			}
		}else{
			for(int j=le;j<ri;j++){
				right[j] = max(right[j],h);
			}
		}
	}
	double ans=100.0;
	for(int i=0;i<r;i++){
		ans = min(ans,r-sqrt(r*r-i*i)+left[i]);
		ans = min(ans,r-sqrt(r*r-i*i)+right[i]);
	}
	cout << ans << endl;
}

int main(){
	int n,r;
	while(1){
		cin >> r >> n;
		if(n==0&&r==0)break;
		solve(n,r);
	}
	return 0;
}

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

ll N = pow(10,9)+7;

ll pow_mod(ll x, ll y){
    if(y==0) return 1;
    else{
        ll z = pow_mod(x, y/2);
        ll k = (z*z)%N;
        if(y%2==0) return k;
        else return (k*x)%N;
    }
}

ll combi(ll n, ll k){
    ll up = 1, down = 1;
    for(ll i=0; i<k; i++){
        up *= n-i;
        up %= N;
    }
    for(ll i=1; i<=k; i++){
        down *= i;
        down %= N;
    }
    down = pow_mod(down, N-2);
    return (up*down)%N;
}

int main(){
    ll s;
    cin >> s;
    ll n=1;
    ll ans = 0;
    while(1){
        ll k=s-3*n;
        if(k<0) break;
        //cout << n << " " << k << endl;
        ans += combi(n+k-1, k);
        ans %= N;
        //cout << ans << endl;
        n++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3616
#include <stdio.h>

int fibdp[1000000];
/* メモ化再帰 */
int getFib(int n)
{
    if (n == 0)
    {
        return 1;
    }
    if (n == 1)
    {
        return 1;
    }
    if (fibdp[n] != 0)
    {
        return fibdp[n];
    }
    return fibdp[n] = getFib(n - 1) + getFib(n - 2);
}

int main(void)
{
    int n;
    scanf("%d", &n);
    printf("%d\n", getFib(n));
    return 0;
}


Measured memory_bytes: 2132
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <map>
#include <cstring>
#include <cmath>
using namespace std;
#define MAXH 1000000001
#define MAXW 1000000007
#define INF 1000000007
#define MAXN 100001
#define MOD 1000000007
typedef long long ll;
typedef pair<ll, ll> P;


template<typename T>
T pow(T i, T n){
    T re;
    if(n == 0) return 1;
    re = pow(i, n / 2);
    if(n % 2 == 0){
        return re * re;
    }else{
        return i * re * re;
    }
}
ll gcd(ll a, ll b){
    if(b == 0) return a;
    return gcd(b, a % b);
}

ll N, x;
ll A[MAXN], B[MAXN] ;

int main(){
    cin >> N >> x;
    ll ans = 0;
    for(int i = 0;i < N;i++){
        cin >> A[i];
    }
    if(A[0] > x) {
        ans += A[0] - x;
        A[0] = x;
    }
    for(int i = 1;i < N;i++){
        if(A[i] + A[i - 1] > x){
            ans += A[i] + A[i - 1] - x;
            A[i] = x - A[i - 1];
        }
    }

    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef int ll;
typedef long long int li;
const ll MAXN=5e3+51,MOD=1e9+7;
struct Edge{
	ll to,prev;
};
Edge ed[MAXN<<1];
ll nc,tot,from,to;
ll last[MAXN],sz[MAXN],f[MAXN],tmp[MAXN],dp[MAXN][MAXN];
inline ll read()
{
    register ll num=0,neg=1;
    register char ch=getchar();
    while(!isdigit(ch)&&ch!='-')
    {
        ch=getchar();
    }
    if(ch=='-')
    {
        neg=-1;
        ch=getchar();
    }
    while(isdigit(ch))
    {
        num=(num<<3)+(num<<1)+(ch-'0');
        ch=getchar();
    }
    return num*neg;
}
inline void addEdge(ll from,ll to)
{
	ed[++tot].prev=last[from];
	ed[tot].to=to;
	last[from]=tot;
}
inline void dfs(ll node,ll fa)
{
	ll p;
	sz[node]=dp[node][1]=1;
	for(register int i=last[node];i;i=ed[i].prev)
	{
		if(ed[i].to!=fa)
		{
			dfs(ed[i].to,node);
			for(register int j=0;j<=sz[node];j++)
			{
				tmp[j]=dp[node][j],dp[node][j]=0;
			}
			for(register int j=0;j<=sz[node];j++)
			{
				for(register int k=0;k<=sz[ed[i].to];k++)
				{
					p=(li)tmp[j]*dp[ed[i].to][k]%MOD;
					dp[node][j+k]=(dp[node][j+k]+p)%MOD;
				}
			}
			sz[node]+=sz[ed[i].to];
		}
	}
	for(register int i=0;i<=sz[node];i+=2)
	{
		dp[node][0]=(dp[node][0]+MOD-(li)dp[node][i]*f[i]%MOD)%MOD;
	}
}
int main()
{
	nc=read(),f[0]=1;
	for(register int i=0;i<nc-1;i++)
	{
		from=read(),to=read();
		addEdge(from,to),addEdge(to,from);
	}
	for(register int i=2;i<=nc;i++)
	{
		f[i]=(li)f[i-2]*(i-1)%MOD;
	}
	dfs(1,0),printf("%d\n",(MOD-dp[1][0])%MOD);
}


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


using namespace std;


#define pb push_back
#define f first
#define s second
#define rep(i, st, ed) for(ll i=st; i<ed; i++)
#define repn(i, st, ed) for(ll i=st; i<=ed; i++)
#define repb(i, ed, st) for(ll i=ed; i>=st; i--)
#define all(v) v.begin(),v.end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

typedef long long ll;
typedef unsigned long long int llt;
typedef long double ld;

const long double PI  =3.141592653589793238463;
const int N = 1e5 + 10;
const ll INF = 1LL << 60;
const int inf=1e9+7;

template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}



// Main Code

vector<pair<int, int>> g[N][3];
bool vis[N][3];
int main()
{
	int N, M; cin >> N >> M;
  vector<int> to[N];
  rep(i, 0, M){
    int u, v; cin >> u >> v;
    u--; v--; to[u].push_back(v); 
  }
  int S, T; cin >> S >> T; S--; T--;
  queue<pair<int, int>>q;
  q.push({S, 0});
  int dist[N][3]; 
  rep(i, 0, N){
    rep(j, 0, 3){
      dist[i][j]=inf;
    }
  }
  dist[S][0] = 0;
  while(!q.empty()){
    int a = q.front().first, b = q.front().second; q.pop();
    for(int x: to[a]){
      if(dist[x][(b+1)%3]==inf){
        dist[x][(b+1)%3] = dist[a][b] + 1;
        q.push({x, (b+1)%3});
      }
    }
  }
  if(dist[T][0]==inf) cout << -1 << endl;
  else  cout << dist[T][0]/3 << endl;
}



Measured memory_bytes: 13952
import itertools

answer = []

while True:
    n, x = list(map(int, input().split()))
    if n == x == 0:
        break

    target = [i for i in range(1, n + 1)]
    combi = list(itertools.combinations(target, 3))
    count = 0
    for i in range(len(combi)):
        if sum(combi[i]) == x:
            count += 1
    
    answer.append(count)

[print(answer[i]) for i in range(len(answer))]


Measured memory_bytes: 31428