akhauriyash/Code-Regression huggingface dataset:
/**
 *    Author:  "Robin Singh" !!!
 *    BrainyIsTheNewSexy     (CodeForces)
 *    rob_in_1               (Other OJs)
**/
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define IO  freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout);
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define make_unique(x) sort(all((x))); (x).resize(unique(all((x))) - (x).begin())
#define ff first
#define ss second
#define mp make_pair
#define szz(v) ((int)(v).size())  
#define fr(i, j, k) for(int i = j; i < k; i++)     
#define bk(i, j, k) for(int i = j-1; i >= k; i--)
#define mem(ptr)  memset(ptr, 0, sizeof ptr) 
#define nl "\n"
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector <int> vi;
typedef vector <long long> vll;
typedef vector < pair<int,int> > vpii;
typedef vector < pair<ll, ll> > vpll;
const long long mod = 1e9+7;
const long double eps = 1e-9;
const long long INF = (1LL<<61);
const int inf = (1<<30);
const int nn = 1e6+5;
//---------------------------------------------*DEBUGGING*--------------------------------------------------------->]
#define dbg( args...) { vector<string> _v = split( #args, ','); err( _v.begin(), args); cerr << '\n'; }
vector<string> split( const string& s, char c) { vector<string> v; stringstream ss( s); string x; 
while ( getline( ss, x, c)) v.emplace_back(x); return move(v); }
void err( vector<string>::iterator it) { } 
template<typename T, typename... Args>
void err( vector<string>::iterator it, T a, Args... args) {
    cerr << it -> substr( ( *it)[0] == ' ', it -> length()) << " = " << a << '\t'; err( ++it, args...); }
//----------------------------------------------------------------------------------------------------------------->]
//*****************************************!Template Ends Here!*****************************************************]

int main()
{
    // IO;
    IOS;
    int n;
    cin >> n;
    int x[n], y[n], h[n], id;

    fr(i, 0, n){
        cin >> x[i] >> y[i] >> h[i];
        if(h[i]) id = i;
    }

    fr(i, 0, 101){
        fr(j, 0, 101){
            bool ok = 1;
            int H = h[id] + abs(x[id]-i) + abs(y[id]-j);

            fr(k, 0, n){

                if(h[k] == max(0, H - abs(x[k] - i) - abs(y[k] - j))) continue;
                else{
                    ok = 0;
                    break;
                }
            }
            if(ok){
                cout << i << ' ' << j << ' ' << H;
                return 0;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 256
from itertools import permutations
def check(a,b):
    na=len(a)
    nb=len(b)
    rt=[0]*na
    for i in range(na):
        fl=True
        for j in range(min(na-i,nb)):
            if a[i+j]!=b[j] and a[i+j]!='?' and b[j]!='?':
                fl=False
                break
        if fl:
            rt[i]=1
    return rt+[1]

def tri_check(idx):
    id1,id2,id3=idx
    a,b,c=[strs[i] for i in idx]
    ab,bc,ac=chMat[id1][id2],chMat[id2][id3],chMat[id1][id3]
    na,nb,nc=map(len,(a,b,c))
    rt=na+nb+nc
    al,ar=na,nb
    for l in range(na+1):
        for r in range(nb+1):
            if ab[l]==1 and bc[r]==1 and ac[min(na,l+r)]==1:
                alt=max(na,l+nb,l+r+nc)
                if alt<rt:
                    rt=alt

        if ab[l]==1:
            for r in range(l+nb,na+1):
                if ac[r]==1:
                    alt=max(na,r+nc)
                    if alt<rt:
                        rt=alt
    return rt
    
a=input()
b=input()
c=input()
na,nb,nc=map(len,(a,b,c))
ans=10**5
strs=[a,b,c]
chMat=[[check(strs[i],strs[j]) if i!=j else [] for j in range(3)]for i in range(3)]

for i in permutations(range(3)):
    x=tri_check(i)
    ans=min(ans,x)

print(ans)

Measured memory_bytes: 53084
#include<iostream>
#include<queue>
#include<vector>
using namespace  std;
int h, w, n;
int sy = 0, sx = 0;
int dy[] = {0,0,1,-1};
int dx[] = {1,-1,0,0};
char field[1000 + 1][1000 + 1];
int main()
{
	cin >> h >> w >> n;
	for (int i = 0; i < h; i++)
	{
		cin >> field[i];
		for (int j = 0; j < w; j++)
		{
			if (field[i][j] == 'S')
			{
				sy = i;
				sx = j;
			}
		}
	}
	int ans = 0;
	for (int m = 1; m <= n; m++)
	{
		bool used[1000 + 1][1000 + 1];
		queue<pair<pair<int, int>, int> > q;
		for (int i = 0; i < h; i++)
		{
			for (int j = 0; j < w; j++)
			{
				used[i][j] = false;
			}
		}
		q.push(make_pair(make_pair(sy,sx), 0));
		used[sy][sx] = true;
		while (q.size() > 0)
		{
			pair<pair<int, int>, int> p = q.front(); q.pop();
			int y = p.first.first;
			int x = p.first.second;
			int c = p.second;

			if (field[y][x] == '0' + m)
			{
				sy = y;
				sx = x;
				ans += c;
				break;
			}

			for (int i = 0; i < 4; i++)
			{
				int ny = y + dy[i];
				int nx = x + dx[i];
				if (ny < 0 || nx < 0 || ny >= h || nx >= w)continue;
				if (field[ny][nx] == 'X')continue;
				if (used[ny][nx])continue;
				used[ny][nx] = true;
				pair<pair<int, int>, int> next = make_pair(make_pair(ny,nx), c + 1);
				q.push(next);
			}
		}
	}

	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3172
n, m = map(int, input().split())

if n % 2 == 0:
    i = 1
    while i <= m:
        a_i = str(i)
        
        if i <= (n - 2) // 4:
            b_i = str(n - i)
        else:
            b_i = str(n - i - 1)
        
        print(a_i + " " + b_i)
        i += 1
        
elif n % 2 == 1:
    for i in range(1, m + 1):
        a_i = str(i)
        b_i = str(n - i)
        
        print(a_i + " " + b_i)


Measured memory_bytes: 9236
#include<stdio.h>

int main()
{
	int i, a[3];
    for(i=0; i<3; ++i)
    	scanf("%d", &a[i]);
	int j, t;
	for(i=0; i<2; ++i)
		for(j=1; j<3; ++j)
			if( a[j] < a[i] ){
				t = a[j];
				a[j] = a[i];
				a[i] = t;
			}
	printf("%d\n", a[2]-a[0]);
	return 0;
} 

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	cin>>s;
	int can=1;
	for(int i=0;i<s.size();i+=2)
		if(s[i]!='h'||s[i+1]!='i')
			can=0;
	cout<<(can?"Yes":"No");
	return 0;
}

Measured memory_bytes: 256
s = input()
k = int(input())

count = 0
change = False
for i in range(1, len(s)):
    if s[i-1] == s[i] and not change:
        count += 1
        change = True
    else:
        change = False

count2 = 0
change2 = False
for i in range(2, len(s)):
    if s[i-1] == s[i] and not change2:
        count2 += 1
        change2 = True
    else:
        change2 = False

if len(s) == 1:
    print(k//2)
elif s[0] == s[-1] and not change:
    if change2:
        print((count+count2+1)*(k//2)+count)
    else:
        print(count+(count2+1)*(k-1))
else:
    print(count*k)


Measured memory_bytes: 3064
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ARC080C {
    class Program {
        static void Main(string[] args) {
            int N = int.Parse(Console.ReadLine());
            int[] input = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
            int four = 0;
            int two = 0;
            int one = 0;
            for (int i = 0; i < N; i++) {
                int num = input[i];
                if (num % 4 == 0) {
                    four++;
                } else if (num % 2 == 0) {
                    two++;
                } else {
                    one++;
                }
            }
            bool ok = false;
            if (two == 0) {
                if(four >= one - 1) {
                    ok = true;
                }
            } else {
                if(four >= one) {
                    ok = true;
                }
            }
            if (ok) {
                Console.WriteLine("Yes");
            } else {
                Console.WriteLine("No");
            }
        }
    }
}


Measured memory_bytes: 19680
#import sys
#import numpy as np
import math
#from fractions import Fraction
import itertools
from collections import deque
from collections import Counter
import heapq
from fractions  import gcd
#input=sys.stdin.readline
#import bisect
n,a,b=map(int,input().split())
ans=(n//(a+b))*a
r=n%(a+b)
if r<=a:
    print(ans+r)
else:
    print(ans+a)

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

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using P = std::tuple<int,int>;

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

    int N, K;
    std::cin >> N >> K;

    int n = N / 2, m = N - n;
    if(std::max(n, m) >= K){
        std::cout << "YES" << std::endl;
    }else{
        std::cout << "NO" << std::endl;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll lcm(ll x, ll y){
    return x*y / __gcd(x,y);
}
ll f(ll x,ll a , ll b){
    ll a_ = x/a ;
    ll b_ = x/b ;

    ll c = x/lcm(a,b);
    return a_ + b_ - c;
}
int main ()
{
    ll  l , r , b , a;
    cin >> l >> r >> a >> b;

    ll dv = f(r , a , b) - f(l-1 , a, b);
    cout<<(r - l + 1) - dv <<endl;
    return 0;
}



Measured memory_bytes: 256
# https://onlinejudge.u-aizu.ac.jp/courses/library/6/NTL/1/NTL_1_B
# pythonのpowが優秀でMODまで取ることができる

MOD = 10**9 + 7
a, b = list(map(int, input().split()))
print(pow(a, b, MOD))



Measured memory_bytes: 5584
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int x = sc.nextInt();
    int y = sc.nextInt();
    int z = sc.nextInt();
    int save;

    save = z;
    z = y;
    y = x;
    x = save;

    System.out.println(x + " " + y + " " + z);




  }
}

Measured memory_bytes: 21716
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
  int n,a,b,c,d;
  string s;
  cin>>n>>a>>b>>c>>d>>s;
  
  for(int i=a-1;i<=b-2;i++){
    if(s[i] == '#' && s[i+1] == '#'){
      cout << "No" << endl;
      return 0;
    }
  }

  for(int i=c-1;i<=d-2;i++){
    if(s[i] == '#' && s[i+1] == '#'){
      cout << "No" << endl;
      return 0;
    }
  }
  
  if( c < d ){
    cout << "Yes" << endl;
    return 0;
  }

  if( c > d ){
    for(int i=b-1;i<=d-1 && i<n;i++){
      if(s[i-1]=='.' && s[i]=='.' && s[i+1]=='.'){
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  
  cout << "No" << endl;

  return 0;
}
        

Measured memory_bytes: 644
import java.util.*;
public class Main {
	static String[][] map;
	static boolean[][] al;
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		while(true) {
			int h = stdIn.nextInt();
			int w = stdIn.nextInt();
			if(w == 0 && h == 0) {
				break;
			}
			map = new String[h][w];
			al = new boolean[h][w];
			for(int i = 0; i < h; i++) {
				String tmp = stdIn.next();
				for(int j = 0; j < w; j++) {
					map[i][j] = tmp.substring(j, j+1);
				}
			}
			
			int npx = 0;
			int npy = 0;
			boolean lp = false;
			while(true) {
				if(map[npy][npx].equals(".")) {
					break;
				}
				if(al[npy][npx]) {
					lp = true;
					break;
				}
				al[npy][npx] = true;
				if(map[npy][npx].equals(">")) {
					npx++;
				}
				if(map[npy][npx].equals("<")) {
					npx--;
				}
				if(map[npy][npx].equals("v")) {
					npy++;
				}
				if(map[npy][npx].equals("^")) {
					npy--;
				}
			}
			if(lp) {
				System.out.println("LOOP");
			}
			else {
				System.out.println(npx + " " + npy);
			}
			
			
		}
	}
}

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

int main(){
    int N;
    cin >> N;
    int a[N];
    int now = 0;
    int count = 0;
    for(int i = 0; i < N; i++){
        int input;
        cin >> input;
        a[i] = input - 1;
    }
    while(a[now] != -1 && now != 1){
        int now2 = now;
        now = a[now];
        a[now2] = -1;
        count++;
    }
    if(now == 1){
        cout << count << endl;
    }else{
        cout << -1 << endl;
    }
}

Measured memory_bytes: 640
#include <iostream>

using namespace std;

int main(){
  int N,M,K,tmp;
  cin >> N >> M;
  int A[31];
  for(int i = 0;i < M;i++){
    A[i] = 0;
  }
  for(int i = 0;i < N;i++){
    cin >> K;
    for(int j = 0;j < K;j++){
      cin >> tmp;
      A[tmp-1]++;
    }
  }
  int ans = 0;
  for(int i = 0;i < M;i++){
    if(A[i] == N) ans++;
  }
  cout << ans << endl;
}


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

int main() {

    int N;
    cin >> N;

    ll D;
    cin >> D;

    ll x, y;
    ll ans = 0;

    rep(i, N) {
        cin >> x >> y;
        if(x*x + y*y <= D*D) ans++;
    }
    cout << ans << endl;

    return 0;
}


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

constexpr int inf = 0x3f3f3f3f;
constexpr ll linf = 0x3f3f3f3f3f3f3f3fLL;

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

    string s; cin >> s;
    int n = s.length();
    for (int i = ((n - 1) >> 1); i > 0; i--) {
        if (s.substr(0, i) == s.substr(i, i)) {
            cout << (i << 1) << endl;
            return 0;
        }
    }
    return 0;
}


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

using namespace std;

#define ll long long int
#define ld long double
#define loop(i, n) for (int i = 0; i < n; i++)
#define loops(i, s, n) for (int i = s; i < n; i++)
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define sz(x) ((int)(x).size())
#define fi first
#define se second
#define deb(x) cout<< #x << '=' << x <<endl
#define MOD 1000000007

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

    int n,k;
    cin>>n>>k;
    ll a[n];
    for(int i = 0; i<n; i++){
        cin>>a[i];
    }
    ll prev = 0;
    for(int i = 0; i<k; i++){
        prev += a[i];
    }
    int i = 0;
    int j = k;
    while(j < n){
        ll nxt = (a[j] + prev) - a[i];
        if(nxt > prev){
            cout<<"Yes\n";
        }else{
            cout<<"No\n";
        }
        prev = nxt;
        i++;
        j++;
    } 
}

Measured memory_bytes: 5192
using System;
using System.Collections.Generic;
using System.Text;

class TEST{
	static void Main(){
		while(true){
			var n=int.Parse(Console.ReadLine());
			if(n==0)break;
			Sol mySol=new Sol(n);
			mySol.Solve();
		}
	}
}


class Sol{
	int n;
	int[,] Arr;
	List<Point> L;
	int state;

	public Sol(int n_){
		n=n_;
		L=new List<Point>();
		state=0;
		Arr=new int[n+2,n+2];

		int cnt=0;

		for(int i=0;i<n+2;i++)Arr[0,i]=Arr[n+1,i]=Arr[i,0]=Arr[i,n+1]=0;
		for(int i=0;i<n;i++){
			var d=Console.ReadLine().Split(' ');
			for(int j=0;j<n;j++){
				Arr[i+1,j+1]=int.Parse(d[j]);
				if(Arr[i+1,j+1]<0)L.Add(new Point(i+1,j+1,Arr[i+1,j+1]));
				cnt+=Arr[i+1,j+1];
			}
		}
		if(cnt!=0)state=-99;
	}

	public void Solve(){
		if(state==-99){
			Console.WriteLine("NO");
			return;
		}
		
		//降順でソート（絶対値の小さい順）
		//L.Sort((x,y)=>x.V>y.V?-1:(x.V<y.V?1:0));
		
		state=0;//dfsで解けたら１
		
		//dfs: score：手持ちの数。now:挑戦中の起点 r,c:現在地点
		int now=0;
		int score=0;
//dbg.wArr(Arr);		
		dfs(now,score,L[now].R,L[now].C);
		
		if(state==1){
			Console.WriteLine("YES");
			return;
		}
		Console.WriteLine("NO");
	}

	void dfs(int now_,int score_,int r_,int c_){
		int score=score_;
		int now=now_;
		int r=r_;
		int c=c_;
		score+=Arr[r,c];
		int bak=Arr[r,c];
		Arr[r,c]=0;
//Console.WriteLine("score={0},now={1},r={2},c={3},bak={4}",score,now,r,c,bak);
//dbg.wArr(Arr);		
		if(score==0){
			if(now<L.Count-1){
				dfs(now+1,score,L[now+1].R,L[now+1].C);
			}
			if(now==L.Count-1){
				state=1;
			}
			score-=bak;
			Arr[r,c]=bak;
			return;
		}
		
		
		if(Arr[r-1,c]>0 && score+Arr[r-1,c]<=0)dfs(now,score,r-1,c);
		if(Arr[r+1,c]>0 && score+Arr[r+1,c]<=0)dfs(now,score,r+1,c);
		if(Arr[r,c-1]>0 && score+Arr[r,c-1]<=0)dfs(now,score,r,c-1);
		if(Arr[r,c+1]>0 && score+Arr[r,c+1]<=0)dfs(now,score,r,c+1);
		
		score-=bak;
		Arr[r,c]=bak;
		return;
	}
}



class Point{
	public int R{get;set;}
	public int C{get;set;}
	public int V{get;set;}
	public Point(int i,int j,int v){
		this.R=i;
		this.C=j;
		this.V=v;
	}
}
	
class dbg{
	public static void wArr(int[,] A){
		Console.WriteLine("--table--");
		for(int i=0;i<A.GetLength(0);i++){
			for(int j=0;j<A.GetLength(1);j++){
				Console.Write("{0}\t",A[i,j]);
			}
			Console.WriteLine("");
		}
		Console.WriteLine("--table end--");
		Console.WriteLine("");
	}
	public static void w(String S){
		Console.WriteLine(S);
	}
	public static void w(int i){
		Console.WriteLine(i);
	}
}

Measured memory_bytes: 5496
#pragma target("avx")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef unordered_map<ll, ll> U_MAP;
typedef priority_queue<ll> pq;
typedef priority_queue<ll, vector<ll>, greater<ll>> rpq;
constexpr ll INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
constexpr ll LINF = 1e18;

#define rep(i, n) for (ll(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrrep(i, a, b) for (ll i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl
#define doublecout(a) cout << fixed << setprecision(15) << a << endl;
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto& x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

//------ Believe yourself as a genius!!!!!! ------

int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
// int dy[]={-1,0,1,-1,1,-1,0,1};int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
ll n, cnt, ans, a, b, c, d, tmp, m, h, ball[ohara], x, y, sum, k, q;
bool r[ohara];

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

  cin >> n >> m;
  r[0] = true;
  rep(i, n) ball[i]++;
  rep(i, m) {
    cin >> x >> y;
    x--;
    y--;
    ball[x]--;
    ball[y]++;
    if (r[x]) r[y] = true;
    if (ball[x] == 0) {
      if (r[x]) r[x] = false;
    }
  }
  rep(i, n) {
    if (r[i]) ans++;
  }
  Cout(ans);
  return 0;
}

Measured memory_bytes: 1152
#include<stdio.h>
int main()
{
	int n, m, s=0;
	scanf("%d", &n);
	m = n;
	while (m > 0)
	{
		s = s + (m % 10);
		m = m / 10;
	}
		if (n % s == 0)
			printf("Yes");
		else
			printf("No");
	return 0;
}

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

#define NMAX 100000
using namespace std;

struct Node {
  vector<int> friends;
};
int group[NMAX];

void bfs(vector<Node> &nodes, int id) {
  static int groupno = 1;
  queue<int> q;
  q.push(id);
  set<int> st;

  group[id] = groupno;

  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (int i = 0; i < nodes[u].friends.size(); i++) {
      int fid = nodes[u].friends[i];
      if (group[fid] == -1) {
        q.push(fid);
        group[fid] = groupno;
      }
    }
  }
  groupno++;
}

int main() {
  vector<Node> nodes;
  int nrel, nuser;

  cin >> nuser;
  cin >> nrel;
  nodes.resize(nuser);
  int tmp1, tmp2;
  for (int i = 0; i < nrel; i++) {
    cin >> tmp1 >> tmp2;
    nodes[tmp1].friends.push_back(tmp2);
    nodes[tmp2].friends.push_back(tmp1);
  }
  for (int i = 0; i < nodes.size(); i++) {
    group[i] = -1;
  }

  int q, s, t;
  cin >> q;

  for (int i = 0; i < q; i++) {
    scanf("%d%d", &s, &t);
    if (group[s] == -1)
      bfs(nodes, s);
    printf("%s\n", group[s] == group[t] ? "yes" : "no");
  }
}

Measured memory_bytes: 8620
N,L=map(int,input().split())
taste=list(range(L,N+L))
 
taste2=[]
for i in range(N):
    taste2.append((taste[i])**2)
 
X=0
for i in range(N):
    if taste2[i]==min(taste2):
        X+=taste[i]
        
print(sum(taste)-X)

Measured memory_bytes: 3064
n = int(input())
a = []
for i in range(n):
    a.append(int(input()))

def insertionsort(a, n, g):
    global c
    for i in range(g, n):
        v = a[i]
        j = i - g
        while j >= 0 and a[j] > v:
            a[j + g] = a[j]
            j = j - g
            c += 1
        a[j + g] = v

c = 0
g = [1]
while g[-1] * 3 + 1 < n:
    g.append(g[-1] * 3 + 1)
g.reverse() 
for i in range(len(g)):
    insertionsort(a, n, g[i])
print(len(g))
print(" ".join(map(str, g)))
print(c)
for i in range(n):
    print(a[i])



Measured memory_bytes: 68208
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.TreeSet;
 
 
 
public class Main {
  public static void main(String[] args) {
    InputReader sc = new InputReader(System.in);
 
    String str = sc.nextStr();
    if(str.charAt(str.length()-1) == 's'){
      System.out.println(str + "es");
    }else{
      System.out.println(str + "s");
    }
 
 
  }
 
 //ここからテンプレ
  static class InputReader {
      private InputStream stream;
      private byte[] buf = new byte[1024];
      private int curChar;
      private int numChars;
      private SpaceCharFilter filter;
 
      public InputReader(InputStream stream) {
          this.stream = stream;
      }
 
      public int next() {
          if (numChars == -1)
              throw new InputMismatchException();
          if (curChar >= numChars) {
              curChar = 0;
              try {
                  numChars = stream.read(buf);
              } catch (IOException e) {
                  throw new InputMismatchException();
              }
              if (numChars <= 0)
                  return -1;
          }
          return buf[curChar++];
      }
 
      public String nextStr() {
        int c = next();
        while(isSpaceChar(c)){c = next();}
        StringBuffer str = new StringBuffer();
        do{
          str.append((char)c);
          c = next();
        }while(!isSpaceChar(c));
        return str.toString();
      }
 
      public char nextChar() {
        int c = next();
        while(isSpaceChar(c)){c = next();}
        char ret;
        do{
          ret = (char)c;
          c = next();
        }while(!isSpaceChar(c));
        return ret;
      }
 
      public int nextInt() {
          int c = next();
          while (isSpaceChar(c))
              c = next();
          int sgn = 1;
          if (c == '-') {
              sgn = -1;
              c = next();
          }
          int res = 0;
          do {
              if (c < '0' || c > '9')
                  throw new InputMismatchException();
              res *= 10;
              res += c - '0';
              c = next();
          } while (!isSpaceChar(c));
          return res * sgn;
      }
 
      public boolean isSpaceChar(int c) {
          if (filter != null)
              return filter.isSpaceChar(c);
          return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
      }
 
      public interface SpaceCharFilter {
          public boolean isSpaceChar(int ch);
      }
  }
}

Measured memory_bytes: 25224
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007
 
ll a[200010];
int main() {
	ll n;
	cin>>n;
	for(ll i=0;i<n;i++){
		cin>>a[i];
	}
	ll ans=0,cnt=0;
	for(ll i=0;i<n;i++){
		if(a[i]>cnt){
			cout << -1;
			return 0;
		}
		else{
			if(a[i]==cnt){
				if(cnt!=0){
					ans++;
				}
				cnt++;
			}
			else{
				ans+=a[i];
				cnt=a[i]+1;
			}
		}
	}
	cout <<ans;
	// your code goes here
	return 0;
}

Measured memory_bytes: 1792
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
char s[200005];
int main()
{
	cin>>(s+1);
	int len=strlen(s+1);
	int ans=len-2;
	cout<<s[1]<<ans<<s[len]<<endl;
	return 0;
}


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

int main(){
  long N;
  vector<long> A;
  cin >> N;
  for(int i=0; i<N; i++){
    long a; cin >> a;
    A.push_back(a);
  }
  sort(A.begin(), A.end());
  long count=0;
  long num=1;
  long tmp=A[0];
  for(long i=1; i<N; i++){
    if(tmp==A[i]){
      num++;
      continue;
    }
    tmp = A[i];
    if(num%2==1) count++;
    num=1;
  }
  if(num%2==1) count++;
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 1400
#include <bits/stdc++.h>
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

using namespace std;
typedef long long ll;

int main(void)
{
  int n, q;
  string s;
  cin >> n >> s >> q;
  map<char,set<int>> pos;
  REP(i,n) pos[s[i]].insert(i);
  REP(i,q) {
    int cmd;
    cin >> cmd;
    if(cmd==1) {
      int i;
      string sc;
      cin >> i >> sc;
      --i;
      pos[s[i]].erase(i);
      s[i]=sc[0];
      pos[s[i]].insert(i);
    } else {
      int l, r, ans=0;
      cin >> l >> r;
      --l; --r;
      REP(i,26) {
        if(pos['a'+i].lower_bound(l) != pos['a'+i].upper_bound(r)) ++ans;
      }
      cout << ans << endl;
    }
  }
  return 0;
}



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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	string s; cin>>s;
	int ans=0;
	for(int i=0;i<s.size();++i){
		int cnt=0;
		while((i<s.size())&&(s.at(i)=='A'||s.at(i)=='C'||s.at(i)=='G'||s.at(i)=='T'))++cnt,++i;
		ans=max(ans,cnt);
	}
	cout<<ans<<"\n"s;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <numeric>
using i64 = long long;

class UF {
    std::vector<int> par, rank;

    public:
    UF(int size) : par(size), rank(size) {
        std::iota(par.begin(), par.end(), 0);
    }

    int root(int x) {
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    bool same(int x, int y) {
        return root(x) == root(y);
    }

    void unite(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y) return;

        if (rank[x] < rank[y]) par[x] = y;
        else {
            par[y] = x;
            if (rank[x] == rank[y]) rank[x]++;
        }
    }
};

constexpr auto pow(long long x, long long n, const long long mod) {
    long long ret = 1;
    while(n > 0) {
        if ((n & 1) == 1) ret = (ret * x) % mod;
        x = (x * x) % mod;
        n >>= 1;
    }
    return ret;
}

int main() {
    constexpr i64 mod = 1000000007;
    int n;
    std::cin >> n;
    std::vector<int> p(n), c(n);
    UF uft(n);
    for (int i = 0; i < n; i++) {
        std::cin >> p[i];
        if (p[i] == -1) continue;
        --p[i];
        if (uft.same(i, p[i])) {
            c[uft.root(i)]++;
        } else {
            const int l = c[uft.root(i)], r = c[uft.root(p[i])];
            uft.unite(i, p[i]);
            c[uft.root(i)] = l + r + 1;
        }
    }

    std::vector<int> vs(n), reds;
    i64 cnt = 0;
    for (int i = 0; i < n; i++) vs[uft.root(i)]++;
    for (int i = 0; i < n; i++) {
        if (!vs[i]) continue;
        if (c[i] == vs[i]) cnt++;
        else reds.push_back(vs[i]);
    }

    const i64 rem = reds.size(), w = pow(n - 1, rem, mod);
    cnt = w * cnt % mod;

    for (int i = 0; i < rem; i++) {
        if (reds[i] >= 2) {
            cnt = (cnt + (reds[i] + mod - 1) % mod * pow(n - 1, rem - 1, mod) % mod) % mod;
        }
    }

    std::vector<std::vector<i64>> dp(rem + 1, std::vector<i64>(rem + 1));
    for (int i = 0; i < rem; i++) {
        dp[i + 1][1] = (dp[i][1] + reds[i]) % mod;
        for (int j = 2; j <= rem; j++) {
            dp[i + 1][j] = (dp[i][j] + reds[i] * dp[i][j - 1] % mod) % mod;
        }
    }

    i64 fact = 1;
    for (int i = 2; i <= rem; i++) {
        cnt = (cnt + fact * pow(n - 1, rem - i, mod) % mod * dp[rem][i] % mod) % mod;
        fact = fact * i % mod;
    }

    const i64 total = n * w % mod;
    std::cout << (total + mod - cnt) % mod << std::endl;

    return 0;
}


Measured memory_bytes: 198672
#include <iostream>

using namespace std;

int main() {
    int n,m;
    cin>>n>>m;
    int a[n][m],aa[n+1][m+1];
    
    char c;
    
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            cin>>c;
            if(c=='.')
                a[i][j]=0;
                
            
            else
            
                a[i][j]=1;
                
            
        }
        
    }
    for(int i=0;i<n;i++)
{
    for(int j=0;j<m;j++){
        if(i+j==0){
            aa[i][j]=a[i][j];
        }  
        
        else{
        aa[i][j]=1e9;
        if(i)
        aa[i][j]=min(aa[i][j],aa[i-1][j]+((a[i][j]!=a[i-1][j])&a[i][j]));
        if(j)
        aa[i][j]=min(aa[i][j],aa[i][j-1]+((a[i][j]!=a[i][j-1])&a[i][j]));
        
        }
     
    }
}

cout<<aa[n-1][m-1]<<endl;
}

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

const int N = 1e5 + 5;

int n;
int a[N];
int sum[2][N]; 
int ans[N];

int main()
{
	scanf("%d", &n);
	for (int i = 1; i <= n; i ++)
	scanf("%d", &a[i]), a[i], sum[i & 1][i] = sum [i & 1][i - 2] + a[i];
	ans[1] = (sum[1][n] + sum[0][n - 1]) - sum[0][n - 1] * 2;
	a[n] -= ans[1] / 2;
	for (int i = 2; i <= n; i ++)
		ans[i] = a[i - 1] * 2 - ans[i - 1];
	for (int i = 1; i <= n; i ++)
		printf("%d ", ans[i]);
	return 0;
}

Measured memory_bytes: 2816
from itertools import accumulate
from collections import defaultdict

n, m = map(int, input().split())
a = list(map(int, input().split()))

acm = [0] + list(accumulate(a))
d = defaultdict(int)

for e in acm:
	r = e % m
	d[r] += 1

ans = 0
for v in d.values():
	ans += v * (v - 1) // 2

print(ans)


Measured memory_bytes: 16804
hantei = []
A,B,C=map(int,input().split())
hantei.append(A)
hantei.append(B)
hantei.append(C)
if 5 in hantei:
    hantei.pop(hantei.index(5))
    if 5 in hantei:
        if 7 in hantei:
            print("YES")
        else:
            print("NO")
    else:
        print("NO")



else:
    print("NO")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll inf = 1e18;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define per(i, a, b) for (int i = b - 1; i >= a; i--)
#define int ll
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

signed main() {
    int n;
    cin >> n;
    int p[n];
    rep(i, 0, n) cin >> p[i], p[i];
    int dp[n + 1] = {};
    rep(i, 0, n) {
        int now = p[i];
        dp[now] = dp[now - 1] + 1;
    }
    int mx = 0;
    rep(i, 0, n + 1) mx = max(mx, dp[i]);
    cout << n - mx << "\n";
}

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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int main()
{
    int A, B, C;
    cin >> A >> B >> C;
    cout << max(0, C-(A-B)) << endl;
    return 0;
}

Measured memory_bytes: 256
# 普通のナップサックは O(荷物の数、ナップサックに入る重量の上限)で計算できる。
# 今回はこれだと O(100 * 10**9) なので無理。
# 明らかに条件で重要なのは「すべてのi=2,3,...,Nについて、w_1<=w_i<=w_1+3」

# w_1が1000とする
# W = 4500→4つが必ず入り、5つは必ず入らない。価値の高いものから4つ。
# W = 4005→3つが必ず入る。4つが入るかどうかは場合による。
# max(3つの場合, 4つの場合)。3つは価値の高いものから3つ。4つは?
# 4つ選ぶ、4005以下、価値最大化
# dp[i][k][l]

# w_1〜w_iの中からk個選んで、重量をちょうどlにしたときの、最大価値
# dp[i][k][l] := max(dp[i-1][k][l], dp[i-1][k-1][l - w_i] + v_i)

# w_1〜w_iの中からk個選んで、重量をl以下にしたときの、最大価値
# dp[i][k][l] := max(dp[i-1][k][l], dp[i-1][k-1][l - w_i] + v_i)

# 後者を使うべき。更新式は同じで最後に重量に関してmaxを取る手間が無いので。
# i <= N, k <= N, l <= 3*N

n, w_limit = list(map(int, input().split()))

baggage = [list(map(int, input().split())) for _ in range(n)]

weight_base = baggage[0][0]

# i添字は0〜n-1 問題文から1引いて0-indexにする
# k添字は0〜n 
# l添字は0〜3n

for i in range(n):
    baggage[i][0] -= weight_base

dp = [[[0 for _ in range(3*n+1)] for _ in range(n+1)] for _ in range(n)]

for l in range(baggage[0][0], 3*n):
    dp[0][1][l] = baggage[0][1]

for i in range(1, n):
    for k in range(1, n+1):
        for l in range(3*n+1):
            if l - baggage[i][0] >= 0:
                dp[i][k][l] = max(dp[i-1][k][l], dp[i-1][k-1][l - baggage[i][0]] + baggage[i][1])
            else:
                dp[i][k][l] = dp[i-1][k][l]

valid_min_num = w_limit // (weight_base+3)
valid_max_num = w_limit // weight_base

ans = 0
for num in range(valid_min_num, min(valid_max_num, n) + 1):
    weight_rest = w_limit - weight_base * num
    if weight_rest >= 3*n:
        weight_rest = 3*n

    # print(n-1, num, weight_rest)
    ans = max(ans, dp[n-1][num][weight_rest])

print(ans)


Measured memory_bytes: 98060
#include <iostream>
#include <string>
#include <sstream>
#include <vector>


using namespace std;

int main()
{
int a[6]={0},count=0;
int i;
cin>>a[0];
cin>>a[1];
cin>>a[2];
cin>>a[3];
cin>>a[4];
cin>>a[5];
if((a[4]-a[0])<=a[5])cout<<"Yay!"<<endl;
else{cout<<":(";}

}	


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
using namespace std;

int n, x;

inline long long imod(long long a, long long b)
{
	return (a >= 0) ? (a % b) : (a % b + b);
}

int main(void)
{
	scanf("%d %d", &n, &x);
	if (x == 1 || x == 2 * n - 1)
	{
		printf("No\n");
	}
	else
	{
		printf("Yes\n");
		for (int i = 0; i < 2 * n - 1; ++i)
		{
			int poll = i + x - n;
			printf("%d\n",(int)imod(poll , (n * 2 - 1)) + 1);
		}
	}
	return 0;
}


Measured memory_bytes: 1536
import math

def norm(p, q): # normal vector: (p -> q) * -1j
    return (q[1] - p[1], p[0] - q[0])

def magnitude(a):
    return (a[0]**2 + a[1]**2)**.5

def dot(p, q):
    return p[0]*q[0] + p[1]*q[1]

def angle(p, q):
    return math.acos(dot(p, q) / (magnitude(p) * magnitude(q)))

def cross(a, b, c):
    return (b[0] - a[0]) * (c[1] - a[1]) - (b[1] - a[1]) * (c[0] - a[0])

def convex_hull(ps):
    ps = sorted(ps)
    qs = []
    n = len(ps)
    for p in ps:
        while len(qs) > 1 and cross(qs[-1], qs[-2], p) > 0:
            qs.pop()
        qs.append(p)
    t = len(qs)
    for i in range(n - 2, -1, -1):
        p = ps[i]
        while len(qs) > t and cross(qs[-1], qs[-2], p) > 0:
            qs.pop()
        qs.append(p)
    return qs

n = int(input())
s = [tuple(map(int, input().split())) for _ in range(n)]
ch = convex_hull(s)
ch.pop()
m = len(ch)
d = dict()
for i in range(m):
  u = angle(norm(ch[i-1], ch[i]), norm(ch[i], ch[(i+1)%m]))
  d[ch[i]] = u / 2 / math.pi
for t in s:
  print(0.0 if t not in d else d[t])

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

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    long long n,ans,div;
    div=1000000000+7;
    cin>>n;
    ans=1;
    for(long long i=1;i<=n;i++){
        ans*=i;
        if(ans>div){
            ans%=div;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3524
import java.util.*;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        HashMap<Integer, Integer> map = new HashMap<>();
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
            int count = map.getOrDefault(a[i], 0);
            map.put(a[i], ++count);
        }

        int size1 = map.getOrDefault(1, 0);
        int count = n;
        for (int i = 0; i < n; i++) {
            if (map.getOrDefault(a[i], 0) > 1) {
                count--;
                continue;
            }
            // 1の時は他に１があれば対象
            if (a[i] == 1 && size1 > 1) {
                count--;
                continue;
            }
            // １以外の時に、１が一つでもあれば対象
            if (a[i] != 1 && size1 > 0) {
                count--;
                continue;
            }

            Set<Integer> div = getDiv(a[i]);
            for (Integer d : div) {
                if (map.containsKey(d)) {
                    count--;
                    break;
                }
            }
        }

        System.out.println(count);
    }

    private static Set<Integer> getDiv(int i) {
        Set<Integer> res = new HashSet<>();
        for (int j = 2; j * j <= i; j++) {
            if (i % j == 0) {
                res.add(j);
                res.add(i / j);
            }
        }

        return res;
    }

}

Measured memory_bytes: 75500
#include<bits/stdc++.h>
using namespace std;
bool flg,s1[105][105];
int i,j;
char s[105][105];
int main(void)
{
	int n,m;
	
	cin>>n>>m;
	for(i=1;i<=n;i++) cin>>s[i]+1;	
	
	for(i=1;i<=n;i++){
		flg=1;
		for(j=1;j<=m;j++){
			if(s[i][j]=='#')
				flg=0;
		}	
		if(!flg) continue;
		for(j=1;j<=m;j++) {s1[i][j]=1;}		
	}
	
	for(i=1;i<=m;i++){
		flg=1;
		for(j=1;j<=n;j++){
			if(s[j][i]=='#')
				flg=0;
		}	
		if(!flg) continue;
		for(j=1;j<=n;j++) {s1[j][i]=1;}		
	}	
	
	for(i=1;i<=n;i++){
		 flg= 0;
		for(j=1;j<=m;j++){
			if(!s1[i][j]) cout<<s[i][j], flg= 1;
		}
		if(flg) cout<<endl;
	}
}	

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
#define all(v) v.begin(), v.end()
#define repi(i, n, init) for (ll i = init; i < (n); i++)
#define repd(i, n, init) for (ll i = (n); i >= init; i--)
#define repm(i, m) for (auto i = m.begin(); i != m.end(); i++)
#define repb(bit, n, init) for (ll bit = init; bit < (1 << n); ++bit)

int main()
{
    ll W, H;
    while (cin >> W >> H)
    {
        if (W == 0 && H == 0)
        {
            break;
        }
        repi(i, W, 0)
        {
            repi(j, H, 0)
            {
                cout << "#";
            }
            cout << endl;
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3100
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define uint unsigned
#define pii pair<int,int>
#define pll pair<ll,ll>
#define IT iterator
#define PB push_back
#define fi first
#define se second
#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);i--)
#define CLR(a,v) memset(a,v,sizeof(a));
#define CPY(a,b) memcpy(a,b,sizeof(a));
#define debug puts("wzpakking")
#define y1 ysghysgsygsh
using namespace std;

ll n,A,B;
int main(){
	scanf("%lld%lld%lld",&n,&A,&B);
	if ((A&1)==(B&1)) printf("%lld\n",abs(A-B)/2);
	else{
		ll v1=abs(1-A)+abs(1-B);
		ll v2=abs(n-A)+abs(n-B);
		printf("%lld\n",(min(v1,v2)+1)/2);
	}
}

Measured memory_bytes: 764
#include<bits/stdc++.h>
using namespace std;
int X[300300],Y[300300];
int SumX[300300],SumY[300300];
map<pair<int,int>,bool> M;
int main()
{
	int H,W,N;
	cin>>H>>W>>N;
	for(int i=0;i<N;i++)
	{
		cin>>X[i]>>Y[i];
		X[i]--;
		Y[i]--;
		SumX[X[i]]++;
		SumY[Y[i]]++;
		M[make_pair(X[i],Y[i])]=true;
	}
	vector<int> V1,V2;
	int maxX=*max_element(SumX,SumX+H),maxY=*max_element(SumY,SumY+W);
	for(int i=0;i<H;i++)
		if(SumX[i]==maxX)
			V1.push_back(i);
	for(int i=0;i<W;i++)
		if(SumY[i]==maxY)
			V2.push_back(i);
	int len1=(int)(V1.size()),len2=(int)(V2.size());
	if(len1*len2>N)
	{
		cout<<maxX+maxY<<endl;
		return 0;
	}
	for(int i=0;i<len1;i++)
		for(int j=0;j<len2;j++)
			if(!M[make_pair(V1[i],V2[j])])
			{
				cout<<maxX+maxY<<endl;
				return 0;
			}
	cout<<maxX+maxY-1<<endl;
	return 0;
}

Measured memory_bytes: 30832
N, P = map(int, input().split())
primes = list()
n = 2
while n**2 <= P:
    cnt = 0
    while P % n == 0:
        P //= n
        cnt += 1
    if cnt > 0:
        primes.append((n, cnt))
    n += 1
if P != 1:
    primes.append((P, 1))
ans = 1
for p, c in primes:
    ans *= p ** (c // N)
print(ans)

Measured memory_bytes: 9196
#include <iostream>
using namespace std;
int main(void){
    int a,b;
    cin>>a;
    b=a%7;
    if(b==0){
        cout<<"thu"<<endl;
    }
    else if(b==1){
        cout<<"fri"<<endl;
    }
    else if(b==2){
        cout<<"sat"<<endl;
    }
    else if(b==3){
        cout<<"sun"<<endl;
    }
    else if(b==4){
        cout<<"mon"<<endl;
    }
    else if(b==5){
        cout<<"tue"<<endl;
    }
    else if(b==6){
        cout<<"wed"<<endl;
    }
    return 0;
}


Measured memory_bytes: 3112
#include <bits/stdc++.h>
#define int long long
#define N 301
using namespace std;
const int INF = 1LL<<55;
int Max(int &a,int b){return a=max(a,b);}
int Min(int &a,int b){return a=min(a,b);}
int n,m;
deque<int> A[N];
vector<int> sports[N];

int getIdx(){
  int idx = 0;
  for(int i=0;i<m;i++) if(sports[idx].size()<sports[i].size()) idx = i;
  return idx;
}

signed main(){
  cin>>n>>m;
  for(int i=0;i<n;i++){
    A[i].resize(m);
    for(int j=0;j<m;j++)cin>>A[i][j],A[i][j]--;
  }

  for(int i=0;i<n;i++) sports[A[i][0]].push_back(i);
  
  int ans = 1e9;
  int erased[1000]={};
  for(int i=0;i<m;i++){
    int idx = getIdx();
    ans = min(ans,(int)sports[idx].size());
    if(i == m-1) continue;   
    //    if(i == 0)cout<<endl;
    //for(int i=0;i<m;i++)cout<<sports[i].size()<<" ";cout<<endl;

    erased[idx] = 1;

    for(int s:sports[idx]){
      while(erased[A[s].front()])A[s].pop_front();
      sports[A[s].front()].push_back(s);
    }

    sports[idx].clear();

  }
  cout<<ans<<endl;  

  return 0;
}


Measured memory_bytes: 2304
#include <iostream>
#include <vector>
#include <numeric>
using namespace std;

int n, k;
vector<int> w;

bool okrec(int P, int m, int l, int cur) {
	if (m == n)
		return true;
	else if (l == k)
		return false;
	else if (P - cur >= w[m])
		return okrec(P, m + 1, l, cur + w[m]);
	else
		return okrec(P, m, l + 1, 0);
}

bool ok(int P) {
	return okrec(P, 0, 0, 0);
}

int main() {
	cin >> n >> k;
	w.resize(n);
	for (int i = 0; i < n; i++)
		cin >> w[i];
	int Pl = 1, Pr = accumulate(w.begin(), w.end(), 0) + 1;
	while (Pl != Pr) {
		int Pm = (Pl+Pr)/2;
		if (ok(Pm))
			Pr = Pm;
		else
			Pl = Pm + 1;
	}
	cout << Pl << endl;
}


Measured memory_bytes: 3124
// Believe in yourself
#include<bits/stdc++.h>

using namespace std;

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

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define Pair vector<pair<ll,ll>>
#define vec vector <ll> 
#define all(a) a.begin(),a.end()
#define mo 1000000007
#define decimal(i,n) fixed << setprecision(i) << n
#define show(a) for(auto xyz:a)cout<<xyz<<" ";cout<<endl;
#define show_nl(a) for(auto xyz:a)cout<<xyz<<endl;


void eea(ll a,ll b,ll &x,ll &y)
{
    if (a == 1)
    {
        x = 1; y = 0;
        return;
    }
    ll x1, y1;
    eea(b%a,a,x1,y1);
    x=y1-(b/a)*x1;
    y=x1;
}
ll mi(ll a,ll m)
{
    ll x,y;
    eea(a,m,x,y);
    x= (x%m+m)%m;
    return x;
}

/*
Enter the test case


Some helpful points
1.) Calm yourself
2.) check for semicolon or data type mismatch
*/

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);    
    ll t=1;
    // cin>>t;
    while(t--)
    {
       ll n,q;
       cin>>n;
        map <ll,ll> m;
       ll s=0,a;
       for(ll i=0;i<n;i++) 
       {
           cin>>a;
           m[a]++;
           s=s+a;
       }
       cin>>q;
       ll p,r;
       for(ll i=0;i<q;i++)
       {
           cin>>p>>r; 
           if(p>r) 
           {
               s=s-(p-r)*(m[p]);
               m[r]=m[r]+m[p];
               m[p]=0;
           }
           else
           {
               s=s+(r-p)*(m[p]);
               m[r]=m[r]+m[p];
               m[p]=0;
           }   
           cout<<s<<"\n";
       }
    }
}



Measured memory_bytes: 9508
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int sz = 2e5+5;

ll a[sz];

int main()
{
    ll k, n;
    cin >> k >> n;
    for(ll i=0; i<n; i++) scanf("%lld", &a[i]);
    a[n] = k + a[0];

    ll ans = 0;
    for(ll i=0; i<n; i++) ans = max(ans, a[i+1]-a[i]);

    cout << k-ans << endl;
}


Measured memory_bytes: 1792
import math


def divisor(div, N):
    # 約数
    i = 1
    n = N

    while i <= math.sqrt(n):
        if n % i == 0:
            div.add(i)
            div.add(n // i)
        i += 1


A, B, K = map(int, input().split())
a = set()
b = set()
divisor(a, A)
divisor(b, B)

print(sorted(list(a & b), reverse=True)[K - 1])


Measured memory_bytes: 3060
#include <iostream>
#include <math.h>
#include <algorithm>
#include <functional>
#include <vector>
#include <typeinfo>
#include <climits>
using namespace std;
#define INIT cin.tie(0); ios::sync_with_stdio(false);
#define FOR(i, a, n) for (int i = a; i < n; i++)
#define REP(i, n) for(int i = 0; i < n; i++)

int main()
{
    INIT;

    int a, b, c;
    cin >> a >> b >> c;

    if(b - a == c - b) cout << "YES" << endl;
    else cout << "NO" << endl;


    return 0;
}

Measured memory_bytes: 256
process.stdin.resume();
process.stdin.setEncoding('utf8');
var input_string = '';

process.stdin.on('data', function(chunk) {
  input_string += chunk;
});

process.stdin.on('end', function() {
  const lines = input_string.split(" ");
  const a = Number(lines[0]);
  const b = Number(lines[1]);
  const c = Number(lines[2]);
  if(a <= c && c <= b){
    console.log('Yes');
  }else{
  console.log('No');
  }
});

Measured memory_bytes: 7500
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>

typedef unsigned long long ULLONG;
typedef long long LLONG;
static const LLONG MOD_NUM = 1000000007;

template<class _T> static void getint(_T& a) {
	std::cin >> a;
}
template<class _T> static void getint(_T& a, _T& b) {
	std::cin >> a >> b;
}
template<class _T> static void getint(_T& a, _T& b, _T& c) {
	std::cin >> a >> b >> c;
}

static void A();

int main()
{
	A();
	fflush(stdout);
	return 0;
}

static void A()
{
	int x, ans = 0;
	for (int i = 0; i < 5; i++) {
		getint(x);
		if (x == 0) {
			ans = i + 1;
		}
	}
	printf("%d\n", ans);
}


Measured memory_bytes: 3744
#include <iostream>
#include <stdio.h>
#include <cstring>
using namespace std;

const int dx[4] = { 0, 1, 0, -1 };
const int dy[4] = { 1, 0, -1, 0 };
int n, m, map[105][105], vis[105][105];

void dfs(int x, int y, char ch) {
    if (x < 0 || y < 0 || x >= n || y >= m) return;
    if (vis[x][y] || map[x][y] != ch) return;
    vis[x][y] = true;
    for (int k = 0; k < 4; k++)
        dfs(x + dx[k], y + dy[k], ch);
}

int main() {
    while (scanf("%d %d", &n, &m) == 2 && n && m) {
        memset(map, 0, sizeof map);
        memset(vis, 0, sizeof vis);
        for (int i = 0; i < n; i++)
            for (int j = 0; j < m; j++) {
                char ch = getchar();
                if (ch == '\n') ch = getchar();
                map[i][j] = ch;
            }
        int ans = 0;
        for (int i = 0; i < n; i++)
            for (int j = 0; j < m; j++)
                if (!vis[i][j]) {
                    dfs(i, j, map[i][j]);
                    ans++;
                }
        printf("%d\n", ans);
    }
    return 0;
}



Measured memory_bytes: 3728