akhauriyash/Code-Regression huggingface dataset:
N=int(input())
A=list(map(int,input().split()))

mi=10**9+1
S=0
cnt=0
for i in range(N):
    if A[i]<0:
        cnt+=1
    a=abs(A[i])
    S+=a
    mi=min(mi,a)

if cnt%2==0:
    ans=S
else:
    ans=S-2*mi
print(ans)

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

int main() {
  int N,M;
  cin >> N >> M;
  vector<int> vec(N);
  int a,b;
  for(int i=0;i<M;i++){
    cin >> a >> b;
    vec.at(a-1)++;
    vec.at(b-1)++;
  }
  for(int i=0;i<N;i++){
    cout << vec.at(i) << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long MOD=1e9+7;

int mgcd(int a,int b){
  if(a<b) return mgcd(b,a);
  if(b==0) return a;
  return mgcd(b,a%b);
}

int main() {
  int n,x;
  cin>>n>>x;
  vector<int> city;
  rep(i,n){
    int y;
    cin>>y;
    city.push_back(abs(y-x));
  }
  sort(city.begin(),city.end());
  int ans=city[0];
  rep(i,n-1)
    ans=mgcd(ans,city[i+1]);
  cout<<ans<<endl;
}


Measured memory_bytes: 892
def p_d():
    from sys import stdin
    input = stdin.readline
    import sys
    sys.setrecursionlimit(10 ** 6)
    n = int(input())
    route = [[] for _ in range(n)]
    for _ in range(n - 1):
        u, v, w = map(int, input().split())
        w = 0 if w & 1 == 0 else 1
        route[u - 1].append((v - 1, w))
        route[v - 1].append((u - 1, w))

    ans = [-1] * n

    def dfs(p, d):
        ans[p] = d
        for i, j in route[p]:
            if ans[i] < 0:
                dfs(i, d ^ j)

    dfs(0, 0)
    print("\n".join(map(str, ans)))
    
p_d()

Measured memory_bytes: 169888
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define f(i,a,b) for(int i=a;i<=b;i++)
inline ll r() {
	ll x=0,f=1;
	char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while(isdigit(c))x=x*10+c-'0',c=getchar();
	return x*f;
}
#define d r()
string s;
int main(){
	cin>>s;
	if(s[s.size()-1]=='s')cout<<s<<"es";
	else cout<<s<<"s";
	return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
 
#define pb push_back
#define ll long long        
using namespace std;
 
void scan()
{
    #ifdef NURS
        freopen("main.in", "r", stdin);
        freopen("main.out", "w", stdout);
    #endif
 
}
const int N = 1e6 + 500;
const int mod = 1e9 + 7;

int main() 
{
    scan();    
    int a, b;
    cin >> a >> b;
    if (a >= 13)
    {
    	cout << b;
    }
    else if (a >= 6 && a < 13)
    {
    	cout << b / 2;
    }
    else {
    	cout << 0;
    }
}     
//JUDGE_ID: 295965SY
//Tis I

Measured memory_bytes: 3620
''' بِسْمِ اللَّهِ الرَّحْمَٰنِ الرَّحِيمِ '''
#codeforces1203A_live
gi = lambda : list(map(int,input().split()))
n, = gi()
s = input()
if n >= 3200:
	print(s)
else:
	print("red")

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

const int N = 1e5 + 7;
int n;
long long c[N], s[N], f[N];
long long solve(int pos)
{
	long long cur = s[pos] + c[pos];
	for (int i = pos + 1; i < n; i++)
	{
		long long fuck = ceil(1.0 * max(cur, s[i]) / f[i]);
		fuck *= f[i];
		cur = fuck + c[i];
	}
	return cur;
}
int main()
{
	while (cin >> n)
	{
		memset(c,0,sizeof(c));
		memset(s,0,sizeof(s));
		memset(f,0,sizeof(f));
		int cur = 0;
		for (int i = 1; i < n; i ++)
			cin >> c[i] >> s[i] >> f[i];
		for (int i = 1; i <= n; i++)
			cout << solve(i) << endl;
	}
}

Measured memory_bytes: 2560
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <iostream>
#include <string>
#include <set>
#include <map>
#include <unordered_map>
#include <complex>
#include <iomanip>
#include <cmath>
#include <tuple>
using namespace std;

int main() {
    int n;
    cin >> n;

    vector<int> price(n);
    int res = 0;
    for (int i = 0; i < n; i++) {
        cin >> price[i];
        res += price[i];
    }

    sort(price.begin(), price.end());
    res = res - price[n - 1] / 2;

    cout << res << endl;
}


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

// 2, 3, 4, 6, 

int main() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    int N;
    std::cin >> N;
    if (N == 3) {
        std::cout << "2 5 63\n";
        return 0;
    }
    std::vector<int> result;
    result.reserve(N + 10);
    int sum = 0;
    int last_rem;
    for (int i = 2; ; ++i) {
        if (i % 6 != 1 && i % 6 != 5) {
            result.push_back(i);
            sum += i;
            if (static_cast<int>(result.size()) == N) {
                last_rem = i % 6;
                break;
            }
        }
    }
    int rem = sum % 6;
    if (rem == 1) {
        if (last_rem == 0) {
            result[result.size() - 2] += 5;
        } else if (last_rem == 2) {
            result[result.size() - 3] += 11;
        } else if (last_rem == 3) {
            result[result.size() - 1] += 5;
        } else if (last_rem == 4) {
            result[result.size() - 1] += 5;            
        }
    } else if (rem == 2) {
        if (last_rem == 0) {
            result[result.size() - 1] += 4;
        } else if (last_rem == 2) {
            result[result.size() - 1] += 4;
        } else if (last_rem == 3) {
            result[result.size() - 2] += 4;
        } else if (last_rem == 4) {
            result[result.size() - 1] += 4;            
        }
    } else if (rem == 3) {
        if (last_rem == 0) {
            result[result.size() - 1] += 3;
        } else if (last_rem == 2) {
            result[result.size() - 3] += 9;
        } else if (last_rem == 3) {
            result[result.size() - 1] += 3;
        } else if (last_rem == 4) {
            result[result.size() - 2] += 9;            
        }
    } else if (rem == 4) {
        if (last_rem == 0) {
            result[result.size() - 1] += 2;
        } else if (last_rem == 2) {
            result[result.size() - 1] += 2;
        } else if (last_rem == 3) {
            result[result.size() - 2] += 8;
        } else if (last_rem == 4) {
            result[result.size() - 1] += 2;            
        }
    } else if (rem == 5) {
        if (last_rem == 0) {
            result[result.size() - 1] += 7;
        } else if (last_rem == 2) {
            result[result.size() - 1] += 1;
        } else if (last_rem == 3) {
            result[result.size() - 1] += 1;
        } else if (last_rem == 4) {
            result[result.size() - 2] += 7;            
        }
    }
    bool first = true;
    for (auto& r : result) {
        if (!first) {
            std::cout << ' ';
        } else {
            first = false;
        }
        std::cout << r;
    }
    std::cout << '\n';
    return 0;
}

Measured memory_bytes: 512
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>

using namespace std;

int main() {
    string s;
    cin >> s;
    int ret = 0;
    for(auto t: s){
        if(t == '+'){
            ret++;
        }
        else{
            ret--;
        }
    }

    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 384
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int weit1=sc.nextInt();
        int weit2=sc.nextInt();
        int weit3=sc.nextInt();
        int weit4=sc.nextInt();
        
        if(weit1+weit2==weit3+weit4)
            System.out.println("Balanced");
        else if(weit1+weit2>weit3+weit4)
            System.out.println("Left");
        else if(weit1+weit2<weit3+weit4)
            System.out.println("Right");
         
    }
}

Measured memory_bytes: 23764
import sys


def input():
    return sys.stdin.readline().strip()


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


def main():
    N = int(input())
    A = [0 for _ in range(N + 1)]
    for i in range(1, N + 1):
        F = factorization(i)
        for f in F:
            A[f[0]] += f[1]
    cnt = [0 for _ in range(5)]
    for a in A:
        if a >= 74:
            cnt[0] += 1
        elif a >= 24:
            cnt[1] += 1
        elif a >= 14:
            cnt[2] += 1
        elif a >= 4:
            cnt[3] += 1
        elif a >= 2:
            cnt[4] += 1
    answer = cnt[0]
    answer += sum(cnt[:2]) * sum(cnt[2:])
    answer += sum(cnt[:2]) * (sum(cnt[:2]) - 1)
    answer += sum(cnt[:3]) * (sum(cnt[3:-1]))
    answer += sum(cnt[:3]) * (sum(cnt[:3]) - 1)
    answer += sum(cnt[:4]) * (sum(cnt[:4]) - 1) * cnt[-1] // 2
    answer += sum(cnt[:4]) * (sum(cnt[:4]) - 1) * (sum(cnt[:4]) - 2) // 2
    print(answer)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3188
/* ex3_4
   key_tree */

#include <stdio.h>

// Nを1-9で割った商が1-9かつ余りが0になればよい
int main(void) {
  int N;
  scanf("%d", &N);
  int i = 1;
  // 1-9まで調べる
  while(i < 10){
    int quotient = N / i;
    int remainder = N % i;
    //商が1-9かつ余り0
    if(quotient >= 1 && quotient <= 9 && remainder == 0){
      printf("Yes\n");
      break;/*当てはまったらwhile脱出*/
	}
	i += 1;
  }
  if(i == 10){
    printf("No\n");
  }
  return 0;
}


Measured memory_bytes: 128
#include<stdio.h>
#include<string.h>
#include<malloc.h>
#include<math.h>
#include<algorithm>
using namespace std;

const int maxn=1e6+100;
int n,m,f[maxn],d[maxn];

int get(int x)
{
    if(f[x]==x) return x;
    int t=get(f[x]);
    d[x]=d[f[x]]+d[x];
    return f[x]=t;
}

int pd(int x,int y,int dis)
{
    int fx=get(x);
    int fy=get(y);
    if (fx==fy) return dis==d[y]-d[x];
    f[fy]=fx;
    d[fy]=d[x]+dis-d[y];
    return 1;
}

int main()
{
    int tag=1;
    scanf("%d %d",&n,&m);
    for(int i=1;i<=n;i++) f[i]=i;
    for(int i=0;i<m;i++)
    {
        int x,y,dis;
        scanf("%d %d %d",&x,&y,&dis);
        if(tag) tag=pd(x,y,dis);
    }
    if(tag) printf("Yes\n");
    else
        printf("No\n");
    return 0;
}


Measured memory_bytes: 4736
var GET=(function(){function f(s){return new g(s);}function g(s){this._s=s.trim().split("\n");this._y=0;}g.prototype.a=function(f){var s=this._s, y=this._y, r;if(typeof s[y]==="string")s[y]=s[y].split(" ").reverse();r=s[y].pop();if(!s[y].length)this._y++;return f?r:+r;};g.prototype.l=function(f){var s=this._s[this._y++].split(" ");return f?s:s.map(a=>+a);};g.prototype.m=function(n,f){var r=this._s.slice(this._y,this._y+=n).map(a=>a.split(" "));return f?r:r.map(a=>a.map(a=>+a));};g.prototype.r=function(n,f){var r=this._s.slice(this._y,this._y+=n);return f?r:r.map(a=>+a);};return f;})();
var o=GET(require("fs").readFileSync("/dev/stdin","utf8"));
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill(0).map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill(0).map(x=>"+r+")";return eval(r);}

console.log(main());
function main(){
  var n = o.a();
  var u = xArray(0,n);
  var e = xArray("[]",n);
  for(var i = 1; i < n; i++){
    var t = o.l().map(a=>a-1);
    e[t[0]].push(t[1]);
    e[t[1]].push(t[0]);
  }
  var q = [0], q2 = [], v;
  while(q.length || q2.length){
    if(q.length === 0){
      l++;
      q = q2;
      var q2 = [];
    }
    var x = q.pop();
    if(u[x])continue;
    v = x;
    u[x] = 1;
    for(var i = 0; i < e[x].length; i++){
      q2.push(e[x][i]);
    }
  }
  var q = [v], q2 = [], l = 0;
  u = xArray(0,n);
  while(q.length || q2.length){
    if(q.length === 0){
      l++;
      q = q2;
      var q2 = [];
    }
    var x = q.pop();
    if(u[x])continue;
    u[x] = 1;
    for(var i = 0; i < e[x].length; i++){
      q2.push(e[x][i]);
    }
  }
  return l%3 === 2 ? "Second":"First";
}

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

    int n,m;
    cin >> n >> m;

    vector<int> cont(n);

    for(int i = 0 ; i < m ; i++){
        int k;
        cin >> k;
        for(int j = 0 ; j < k ; j++){
            int s;
            cin >> s;
            s--;
            cont.at(s) |= 1 << i;
        }
    }

    int p = 0;
    for(int i = 0 ; i < m ; i++){
        int s;
        cin >> s;

        p |= s << i;
    }

    int ans = 0;
    for(int i = 0 ; i < (1 << n) ; i++){
        int t = 0;
        for(int j = 0 ; j < n ; j++){
            if(i >> j & 1){
                t ^= cont.at(j);
            }
        }
        if(t == p){
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;

class Main {
    public static void main(String[] args) {
        new Solver().run();
    }
}

class Solver {

    public void run() {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();

        System.out.println(A*B);


        return;
    }

}

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

using lint = long long;

lint factorial(lint n){
    if(n == (lint)0){
        return (lint)1;
    }

    return n * factorial(n - 1);
}

int main(){
    lint n;
    cin >> n;
    cout << factorial(n) << endl;

    return 0;
}


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

int main()
{
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	if(abs(c-a)<=d)
	{
		cout<<"Yes"<<endl;
	}else{
		if(abs(b-a)<=d&&abs(c-b)<=d)
		{
			cout<<"Yes"<<endl;
		}else{
			cout<<"No"<<endl;
		}
	}
	return 0;
}


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

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

	if (s[0] == 'S') {
		cout << "Cloudy" <<  endl;
	}
	if (s[0] == 'C') {
		cout << "Rainy " << endl;
	}
	if (s[0] == 'R') {
		cout << "Sunny" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int i,j,n,m,l,A[100][100],B[100][100],k;
long long int C[100][100],sum=0;
  scanf("%d %d %d",&n,&m,&l);
  for(i=0;i<n;i++){
    for(j=0;j<m;j++){
      scanf("%d",&A[i][j]);
    }
  }
  for(i=0;i<m;i++){
    for(j=0;j<l;j++){
      scanf("%d",&B[i][j]);
    }
  }

  for(i=0;i<n;i++){
    for(j=0;j<l;j++){
      sum=0;
      for(k=0;k<m;k++){
        sum += A[i][k] * B[k][j];
      }
      C[i][j] = sum;
    }
  }
  for(i=0;i<n;i++){
    for(j=0;j<l-1;j++){
      printf("%lld ",C[i][j]);
    }
    printf("%lld\n",C[i][l-1]);
  }
  return 0;
}



Measured memory_bytes: 2128
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>

#define ll long long

using namespace std;

int N;
ll A[100005];
ll ans[100005];

int main()
{
	scanf("%d", &N);

	for (int i = 0; i < N; ++i)
	{
		scanf("%lld", &A[i]);
		if (i & 1) ans[0] -= A[i];
		else ans[0] += A[i];
	}

	for (int i = 1; i < N - 1; ++i) ans[i] = 2 * (A[i - 1] - ans[i - 1] / 2);;
	ans[N - 1] = 2 * (A[N - 1] - ans[0] / 2);

	for (int i = 0; i < N; ++i) printf("%lld ", ans[i]);
	printf("\n");

	return 0;
}

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

using namespace std;

int main(int argc, const char *argv[]) {
  int n;
  cin >> n;
  int cnt2 = 0, cnt4 = 0, cnt = 0;
  for (int i = 0; i < n; ++i) {
    int a;
    cin >> a;
    if (a % 4 == 0) {
      cnt4++;
    } else if (a % 2 == 0) {
      cnt2++;
    } else {
      cnt++;
    }
  }

  if (cnt2 > 0) {
    cnt++;
  }

  if ((cnt4 + cnt) % 2 == 0) {
    cout << (cnt4 < cnt ? "No" : "Yes") << '\n';
  } else {
    cout << (cnt4 < cnt - 1 ? "No" : "Yes") << '\n';
  }
  return 0;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a, n;
  int ans_min = 10000000;
  cin >> n;
  for(int i = 0; i < n; i++) {
    cin >> a;
    int ans = 0; 
    while(a % 2 == 0) {
    a /= 2;
    ans++;
    }
    if (ans < ans_min) {
      ans_min = ans;
    }
  }
  cout << ans_min << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main() {
  int n,m,i,j,cnt=0;
  scanf("%d",&n);
  int a[n];
  for(i=0; i<n; i++) scanf("%d",&a[i]);
  scanf("%d",&m);
  for(i=0; i<m; i++) {
    int x;
    scanf("%d",&x);
    int l=-1,r=n+1;
    while(l+1!=r) {
      int m=(l+r)/2;
      if(a[m]==x) {
	cnt++;
	break;
      }
      if(a[m]<x) l=m;
      else r=m;
    } 
  }
  printf("%d\n",cnt);
  return 0;
}


Measured memory_bytes: 988
#include <iostream>
#include <fstream>
#include <cmath>

using namespace std;

const int NMax = 5e4 + 5;
typedef long long ll;
const int inf = 1e9;

ll N,M;
struct elem {
    int x,y;
}v1[55],v2[55];

ll f(ll);

int main()
{
    cin.tie(0);cin.sync_with_stdio(false);
    cin>>N;

    ll mn = inf;
    for (ll i=1;i*i<=N;++i) {
        if (N%i != 0) {
            continue;
        }

        ll val = max( f(i),f(N/i) );
        if (mn > val) {
            mn = val;
            //cout<<(i)<<' '<<(N/i)<<' '<<val<<'\n';
        }
    }
    cout<<mn<<'\n';
    return 0;
}

ll f(ll a) {
    ll res = 0;
    while (a>0) {
        ++res;
        a /= 10;
    }
    return res;
}


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



void main() {
    long n, m, d;
    scan(n, m, d);

    real ans;

    if (d == 0) {
        ans = 1.0 * (m - 1) / n;
    }
    else {
        ans = 1.0 * 2 * (n - d) / n^^2 * (m - 1);
    }

    writefln("%.12f", ans);
}












































void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}


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

struct Benri { Benri() { std::cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(12);}} benri;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vll = vector<long long>;
using vvll = vector<vll>;
using pll = pair<ll, ll>;
using ull = unsigned long long;

template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define F first
#define S second

template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }

constexpr long long MOD = 1000000007;
//constexpr long long MOD = 998244353;
//constexpr int INF = 1001001001;
constexpr ll INF = 1001001001001001001ll;
constexpr double EPS = 1e-10;
using number = long long;




inline ll mod(ll a, ll m) {
    return (a % m + m) % m;
}

inline ll mul(ll a, ll b, ll m) {
    a = mod(a, m); b = mod(b, m);
    if (b == 0) return 0;
    ll res = mul(mod(a + a, m), b >> 1, m);
    if (b & 1) res = mod(res + a, m);
    return res;
}

ll pow(ll a, ll n, ll m) {
    if (n == 0) return 1 % m;
    ll t = pow(a, n / 2, m);
    t = mul(t, t, m);
    if (n & 1) t = mul(t, a, m);
    return t;
}

vector<pair<ll, ll> > prime_factor(ll n) {
    vector<pair<ll, ll> > res;
    for (ll i = 2; i * i <= n; ++i) {
        if (n % i == 0) {
            int exp = 0;
            while (n % i == 0) {
                ++exp;
                n /= i;
            }
            res.push_back(make_pair(i, exp));
        }
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}
ll GCD(ll a, ll b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}
ll LCM(ll a, ll b) {
    ll g = GCD(a, b);
    return a / g * b;
}

const ll L = 50;
ll solve(ll A, ll M) {
    if (A == 0) return M;
    if (A == 1) return 1;
    if (M == 1) return L;
    ll phiM = M;
    vector<pair<ll, ll> > divM = prime_factor(M);
    for (int i = 0; i < divM.size(); ++i) {
        ll p = divM[i].first;
        phiM *= p - 1;
        phiM /= p;
    }
    ll y = solve(A, phiM);
    ll lcm = LCM(phiM, M);
    ll res = pow(A, y, lcm);
    while (res < L) res += lcm;
    return res;
}
int main() {
    int Q; cin >> Q;

    rep(i, Q) {
        ll a, m; cin >> a >> m;
        ll res = solve(a, m);
        cout << res << endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<unordered_map>
#include<bitset>
#include<math.h>
#include<vector>
#include<set>
#include<algorithm>
#include<ctype.h>
#include<unordered_set>
#include<string>
#include<iomanip>
#include<queue>
#include<limits>
#include<map>
#include<stack>
#include<iterator>
#include<cstring>
 
#include<deque>
#define pi 3.141592653589793238
#include<chrono>
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define MOD 1000000007
#define INF 999999999999999999 
#define pb push_back
#define ff first
#define ss second
 
#define mt make_tuple
#define ll long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;
 
 
typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
 
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    fast;
    ll T = 1, i, j;
    
    //cin >> T;
    while (T--) {
        ll n;
        cin >> n;
        vector<ll> cnt(n + 1);
        for(i = 1; i <= sqrt(n); i++){
            for(j = 1; j <= sqrt(n); j++){
                for(ll k =1 ; k <= sqrt(n); k++){
                    ll val = pow(i, 2) + pow(j, 2) + pow(k, 2) + i * j + j * k + i * k;
                    if(val <= n){
                        cnt[val]++;
                    }
                }
            }
        }
        for(i = 1; i <= n; i++){
            cout << cnt[i] << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3576
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main() {
	// your code goes here
    ll n;
    cin>>n;
    string s;
    cin>>s;
    ll count=1;
    ll i;
    for(i=1;i<n;i++){
        if(s[i]==s[i-1]){
            continue;
            
        }
        else{
            count++;
        }
    }
    cout<<count<<endl;
	return 0;
}


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

//freopen("A-small-practice.in","r",stdin);
    //freopen("A-large-practice.in","r",stdin);
    //freopen("output.out","w",stdout);

    /*int n;
    cin>>n;
    int A[n];

    for(int i=0;i<n;i++) cin>>A[i];

    int dp[(1<<n)-1][n];

    for(int mask = 0;mask < (1<<n);mask++) {
      for(int j = 0;j < n;j++) {


        if(((1<<j)&(mask)) == 0) {
          dp[mask][j] = 0;
        }

        else if(((~(1<<j))&(mask)) == 0) {
            dp[mask][j] = A[j]*2;
        }

        else {
          int t = (~(1<<j))&(mask);
          int ans = 0;
          for(int i=0;i<n;i++) {

            if((1<<i)&(t))
              ans = max(ans, (A[j] > A[i]) ? 2*(A[j]-A[i]) + dp[t][i] : dp[t][i]);
          }

          dp[mask][j] = ans;
          cout<<"hello";
        }



      }
    }

    for(int i=0;i<(1<<n);i++) {
      for(int j=0;j<n;j++) {
        cout<<dp[i][j]<<" ";
      }cout<<endl;
    }*/

vector<int> g[2050];

int answer = INT_MAX;
int temp;

void dfs(int s, int p, int label, int depth) {

    if(label > depth) temp++;

    for(int i=0;i < g[s].size();i++) {
        if(g[s][i] != p) {
            dfs(g[s][i], s, label+1, depth);
        }
    }

}

int main()
{

    int n, k, a, b;
    cin>>n>>k;

    for(int i=0;i<n-1;i++) {
        cin>>a>>b;
        g[a].push_back(b);
        g[b].push_back(a);
    }

    if(k%2 == 0) {
        for(int i=1;i<=n;i++) {
            for(int j=0;j<g[i].size();j++) {
                temp = 0;
                dfs(g[i][j], -1, 0, k/2);
                answer = min(answer, temp);
            }
        }
        cout<<answer;
        return 0;
    }

    for(int i=1;i<=n;i++) {
            for(int j=0;j<g[i].size();j++) {
                temp = 0;
                dfs(g[i][j], i, 0, (k-1)/2);
                dfs(i, g[i][j], 0, (k-1)/2);
                answer = min(answer, temp);
            }
        }
    cout<<answer;


  return 0;
}


Measured memory_bytes: 512
N=int(input())
i=list(map(int,input().split()))
a=0
for x in range(N):
    if i[x]%2==0:
        if i[x]%3!=0:
            if i[x]%5!=0:
                a+=1
if a==0:
    print("APPROVED")
else:
    print("DENIED")

Measured memory_bytes: 3060
// AOJ 0301: Baton Relay Game
// 2017.10.31 bal4u@uu
// 2017.11.25

#include <stdio.h>

typedef struct _T { struct _T *pre, *nxt; char f; } T;
T tbl[200002]; int n, m;
int a[200002];
char buf[800000], *p;

void calc()
{
	int i, j;
	T *cur, *pre, *nxt;
	
	cur = tbl;
	for (i = 0; i < m; i++) {
		j = a[i];
		if (j & 1) while (j--) cur = cur->pre;
		else       while (j--) cur = cur->nxt;
		cur->f = '0';
		pre = cur->pre, nxt = cur->nxt;
		pre->nxt = nxt, nxt->pre = pre;
		cur = nxt;
	}
}

int getint()
{
	int n = 0;
	while (*p >= '0') n = (n<<3) + (n<<1) + (*p++ & 0xf);
	return n;
}

int main()
{
	int q, i;
	T *tp;

	fgets(p=buf, 30, stdin), n = getint(), p++, m = getint(), p++, q = getint();

	for (tp = tbl, i = 0; i < n; i++, tp++) tp->nxt = tp+1, tp->pre = tp-1, tp->f = '1';
	tbl[0].pre = tbl+n-1, tbl[n-1].nxt = tbl;

	fgets(p=buf, sizeof(buf), stdin);
	for (i = 0; i < m; i++) a[i] = getint(), p++;

	calc();

	fgets(p=buf, sizeof(buf), stdin);
	while (q--) putchar(tbl[getint()].f), p++, putchar('\n');
	return 0;
}

Measured memory_bytes: 7564
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const int MAX = 5100000;
ll gcd(ll a, ll b) {
    return (b==0) ? a : gcd(b, a%b);
}

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
ll COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int N;
int x[10], y[10];

double culcDist(int i, int j){
    double a = x[i] - x[j];
    double b = y[i] - y[j];
    return pow(a*a+b*b,0.5);
}

int main(){
    cin >> N;
    rep(i,N){
        cin >> x[i+1];
        cin >> y[i+1];
    }

    double sum = 0;
    vector<int> v(N); rep(i,N) v[i] = i+1;
    do {
        for (int i=0;i<N-1;i++) sum += culcDist(v[i], v[i+1]);
    } while (next_permutation(v.begin(), v.end()));
    double frac = 1;
    rep(i, N) frac *= i+1;
    cout << fixed << setprecision(10) << sum / frac << endl;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var r, g, b int
	fmt.Scan(&r, &g, &b)

	if (r * 100 + g * 10 + b) % 4 == 0 {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}

Measured memory_bytes: 512
N = gets.to_i
a = gets.split.map(&:to_i)

def swap(a,i,j)
   tmp = a[i]
   a[i] = a[j]
   a[j] = tmp
   return a
 end
   
def bubble(a,k)
 for i in 0..(k-2)
  if a[i] > a[i+1]
   swap(a,i,i+1)
  end
 end
 return a
end

def bubble_sort(a)
 k = a.length
 while k > 1
  bubble(a,k)
  k = k-1
 end
 return a
end

bubble_sort(a)

b = Array.new
for i in 0..(a.length-2)
 b[i] = a[i+1] - a[i]
end

sum = 0
for i in 0..(b.length-1)
 sum = sum + b[i]
end

puts(sum)

Measured memory_bytes: 1788
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
const int MAX = 10000;
const int INF = 999999999;
int U[MAX];
int n, G[MAX][MAX];
struct Edge
{
	int u;
	int v;
	int w;
};
vector<Edge> E;
void init()
{
	for (int i = 0; i < n; i++)
		U[i] = i;
}
int getAncestor(int v)
{
	if (U[v] == v)
		return v;
	else
	{
		U[v] = getAncestor(U[v]);
		return U[v];
	}
}
bool merge(int s, int t)
{
	int a1 = getAncestor(s);
	int a2 = getAncestor(t);
	if (a1 != a2)
	{
		U[a2] = a1;
		return false;
	}
	return true;
}
bool cmp(Edge a, Edge b)
{
	return a.w < b.w;
}
int main()
{
	int m;
	cin >> n >> m;
	for (int i = 0; i < m; i++)
	{
		int u, v, w;
		cin >> u >> v >> w;
		Edge e = { u,v,w };
		E.push_back(e);
	}
	init();
		sort(E.begin(), E.end(), cmp);
	int sum = 0;
	int edgeNum = 0;
	//cout << "MST的边为：\n";
	for (int i = 0; i < E.size(); i++)
	{
		Edge e = E[i];
		if (!merge(e.u, e.v))
		{
			sum += e.w;
			edgeNum++;
			//cout << e.u << "---" << e.v << " 权值为" << e.v << endl;
		}
		if (edgeNum == n - 1)
			break;
	}
	cout << sum << endl;
}



Measured memory_bytes: 4588
import sys

input = sys.stdin.readline

def main():
    ans,p,m = '','+','-'
    n = input().rstrip('\n')
    for i in range(2**3):
        ans = [n[0], p, n[1], p, n[2], p, n[3]]
        for j in range(3):
            if i>>j&1:
                ans[2*j+1] = m
        if eval(''.join(ans)) == 7:
            break
    ans = ''.join(ans) + '=7'
    print(ans)

if __name__ == '__main__':
    main()

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

typedef long lint;
typedef long long llint;
typedef pair<int, int> pint;
typedef pair<long long, long long> pllint;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const llint INF = 1<<21;
// static const llint MOD = 1e9 + 7;

bool compPair(const pint& arg1, const pint& arg2) { return arg1.first > arg2.first; }
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; } }

int main(void) {
    int m;
    cin >> m;

    cout << 24-m+24 << endl;
    return 0;
}


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

int main(){
  int s, s1, s2, s3;
  cin >> s;
  
  s3 = s % 10;
  s2 = (s - s3) / 10 % 10;
  s1 = (s - s2 * 10 - s3) /100 % 10;
  
  cout << s1 + s2 + s3 << endl;
  
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	int  n ,num ,digit,rev=0;
	cin>>num;
	n=num;
	do
	{
		digit= num % 10;
		rev=(rev*10)+digit;
		num=num/10;
	}	while(num!=0);
	if(n==rev)
	cout<<"Yes";
	else
	cout<<"No";
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <map>

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

using namespace std;

const ll BIG = 1000000007LL;

int inputValue(){
    int a;
    cin >> a;
    return a;
};

template<typename T>
void inputArray(T* p, int a){
    rep(i, a){
        cin >> p[i];
    }
};

template<typename T>
void inputVector(vector<T> * p, int a){
    rep(i, a){
        T input;
        cin >> input;
        p -> push_back(input);
    }
}

template <typename T>
void output(T a, int precision = 0) {
    if(precision > 0){
        cout << setprecision(precision)  << a << "\n";
    }
    else{
        cout << a << "\n";
    }
}

const int Max = 110;
int N, A, B;

int main(int argc, const char * argv[]) {
    cin >> N >> A >> B;
    output(min(A*N, B));

    return 0;
}

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

 
int main()
{	int n[5];
	for(int i=0; i<5; i++){
		cin>>n[i];
	
	}
	for(int i=0; i<5; i++){
		if(n[i]==0){
			cout<<i+1;
			break;
		}
	}

 	return 0;
}

Measured memory_bytes: 3592
import java.util.Scanner;


public class Main {
	void run() {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int prime = 0;
		for (int i = 0; i < n; i++) {
			int p = scan.nextInt();
			if(is_prime(p)) prime += 1;
		}
		System.out.println(prime);
	}
	boolean is_prime(int p) {
		if (p == 2) return true;
		if (p < 2 || (p&1) == 0) return false;
		int i = 3;
		while (i <= Math.sqrt(p)) {
			if (p % i == 0) return false;
			i = i + 2;
		}
		return true;
	}
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 43008
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <cmath>


typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++);
#define _GLIBCXX_DEBAC
/*map<Keyの型, Valueの型> 変数名;
queue<型> 変数名;
priority_queue<型> 変数名;
priority_queue<型, vector<型>, greater<型>> 変数名;*/

using namespace std;

int gcd(int a, int b) {
	int c;
	if (a < b) {
		c = a; a = b; b = c;
	}
	while (b != 0) {
		c = a % b; a = b; b = c;
	}
	return a;
}

int sort_greater(int m,int n) {
	vector<int> a(m);
	for (int i = 0; i < m; i++) {
		cin >> a[i];
	}
	sort(a.begin(), a.end(),greater<int>());
	for (int i = 0; i < n; i++) {
		cout << a[i];
	}
		return 0;
}

int bubblesort(int a[], int n) {
	int sw = 0;
	bool flag = 1;
	for (int i = 0; flag; i++) {
		flag = 0;
		for (int j = n - 1; j >= i + 1; j--) {
			if (a[j] < a[j - 1]) {
				swap(a[j], a[j - 1]);
				flag = 1;
				sw += 1;
			}
		}
	}
	return sw;
}

int a_z()
{
	for (int i = 0; i <= ('Z' - 'A'); i++) {
		cout << (char)('A' + i);
	}
	return 0;
}

int selecttionsort(int a[], int n) {
	int t,sw = 0, minj;
	for (int i = 0; i < n - 1; i++) {
		minj = i;
		for (int j = 0; j < n - 1; j++) {
			if (a[j] < a[minj]) {
				minj = j;
			}
		}
		t = a[i]; a[i] = a[minj]; a[minj] = t;
		if (i != minj) sw += 1;

	}
	return sw;
}
map<string, int> memo;


int main() {
	//sort(a.begin(),a.end());
	int n;
	string s;
	cin >> n >> s;
	int ans = 0;
	for (int i = 0; i < n - 2; i++) {
		if (s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C') ans++;
	}
	cout << ans;
	return 0;
}









Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    int n;
    while(cin >>n){
        if(n%39 ==0) cout << "3C39"<<endl;
        else if(n%39 <10) cout << "3C0" << n%39<<endl;
        else cout << "3C" << n%39<<endl; 
    }
}


Measured memory_bytes: 3020
#include <iostream>
#include <cmath>
using namespace std;
int main(void){
  long long a,b,c;
  cin >> a >> b >> c;
  
  long long ab,bc,ca;
  ab = a + b;
  bc = b + c;
  ca = c + a;
  
  if(ab == bc && bc == ca && a % 2 == 0){
    cout << -1 << endl;
  }
  else if(ab == bc && bc == ca && a % 2 != 0){
    cout << 0 << endl;
  }
  else{
    int AB = 0;
    int BC = 0;
    int CA = 0;
    while(ab %2 == 0){
      ab /= 2;
      AB++;
    }
    while(bc %2 == 0){
      bc /= 2;
      BC++;
    }
    while(ca %2 == 0){
      ca /= 2;
      CA++;
    }
    
    cout << min(min(AB,BC) , CA) << endl;
    
  }
  
  return 0;
}


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

int main(int argc, char *argv[]) {
  int n;
  std::cin >> n;
  std::string s;
  std::set<std::string> w;
  char tail;
  for (int i = 0; i < n; ++i) {
    std::cin >> s;
    w.insert(s);
    if (i > 0 && s.at(0) != tail) {
      std::cout << "No" << std::endl;
      return 0;
    }
    tail = s.at(s.size() - 1);
  }

  if ((int)w.size() < n) {
    std::cout << "No" << std::endl;
    return 0;
  }

  std::cout << "Yes" << std::endl;
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define ALL(v) v.begin(),v.end()
using ll = long long;
using pii = pair<int,int>;
using vi = vector<int>;
using vs = vector<string>;
using vb = vector<bool>;
using vll = vector<long long>;
using vpii = vector<pair<int,int>>;
using vivi = vector<vector<int>>;
using vbvb = vector<vector<bool>>;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
const int mod = 1000000007;
const int inf = 1001001001;



int main(void) {
  string s,t;
  cin >> s >> t;
  sort(ALL(s));
  sort(ALL(t),greater<char>());
  if(s<t) cout << "Yes" << endl;
  else cout << "No" << endl;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
/* clang-format off */
#define MOD 1000000007
#define INF 1000000000
#define REP(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(a) (a).begin(), (a).end()
#define __DEBUG__
#ifdef __DEBUG__
#define CH_P(a) cout <<"check_point("<<#a<<")" << "\n";
#define DEBUG(x) cout<<#x<<":"<<x<<"\n"
#define DEBUGS(v) cout << #v << ":";for(auto x:v){cout<<x<<" ";}cout<<"\n"
#endif
#ifndef __DEBUG__
#define CH_P(a) 
#define DEBUG(x) 
#define DEBUGS(v) 
#endif
/* clang-format on */

int main() {
  ll r, d, x;
  cin >> r >> d >> x;
  ll t = x;
  REP(i, 10) {
    t = r * t - d;
    cout << t << endl;
  }
  return 0;
}


Measured memory_bytes: 3560
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

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

    static class AButtons {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int A = in.nextInt();
            int B = in.nextInt();
            int res = Math.max(2 * A - 1, Math.max(2 * B - 1, A + B));
            out.println(res);
        }

    }
}



Measured memory_bytes: 24276
n = int(input())
X = []; U = []; JPY = []; BTC = []
for i in range(n):
    x, u = input().split()
    X.append(x); U.append(u)
for i in range(n):
    if U[i] == "JPY":
        JPY.append(float(X[i]))
    else:
        BTC.append(float(X[i]))
print(sum(JPY) + sum(BTC)*380000)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define sqr(x) ((x)*(x))
#define mp make_pair
inline char gc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline ll read(){
	ll x = 0; char ch = gc(); bool positive = 1;
	for (; !isdigit(ch); ch = gc())	if (ch == '-')	positive = 0;
	for (; isdigit(ch); ch = gc())	x = x * 10 + ch - '0';
	return positive ? x : -x;
}
inline void write(ll a){
    if(a<0){
    	a=-a; putchar('-');
	}
    if(a>=10)write(a/10);
    putchar('0'+a%10);
}
inline void wri(ll a){write(a); putchar(' ');}
inline void writeln(ll a){write(a); puts("");}
const int N=3005,mod=1e9+7;
const ll inv=(mod+1)/2;
int a[N],dp[N][N];
inline void gao(int &a,int &b){
	int t=(a+b)*inv%mod;
	a=b=t;
}
signed main(){
	int n=read(),q=read();
	for(int i=1;i<=n;i++)a[i]=read();
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++)dp[i][j]=a[i]>a[j];
	}
	for(int i=1;i<=q;i++){
		int x=read(),y=read();
		gao(dp[x][y],dp[y][x]);
		for(int j=1;j<=n;j++)if(j!=x&&j!=y){
			gao(dp[x][j],dp[y][j]); gao(dp[j][x],dp[j][y]); 
		}
	}
	int ans=0;
	for(int i=1;i<=n;i++)for(int j=i+1;j<=n;j++)ans=(ans+dp[i][j])%mod;
	for(int i=1;i<=q;i++)ans=ans*2%mod;
	cout<<ans<<endl;
}


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

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

int main()
{
    ll i,j;
    ll d,t,s;
    cin >> d >> t >> s;
    if(d <= s*t) cout << "Yes" << endl;
    else cout << "No" << endl;


    return 0;
}

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

#define pb push_back
#define mp make_pair
#define fi first
#define se second

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

bool chkmax(int &x,int y){return x<y?x=y,true:false;}
bool chkmin(int &x,int y){return x>y?x=y,true:false;}

int readint(){
	int x=0,f=1; char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}

int n,m;
char a[505][505];
int ans1[505][505],ans2[505][505];

int main(){
	n=readint(); m=readint();
	for(int i=1;i<=n;i++) scanf("%s",a[i]+1);
	for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) if(a[i][j]=='#') ans1[i][j]=ans2[i][j]=1;
	for(int i=1;i<=n;i++) ans1[i][1]=1,ans2[i][m]=1;
	for(int i=1;i<=n;i+=2){
		for(int j=2;j<m;j++) ans1[i][j]=1;
		if(i!=n) for(int j=2;j<m;j++) ans2[i+1][j]=1;
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++) printf("%c",ans1[i][j]?'#':'.');
		printf("\n");
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++) printf("%c",ans2[i][j]?'#':'.');
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 3072
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define INF 999999999999999999
#define rep(i,m,n) for(lli i = m;i < n;i++)
#define rrep(i,m,n) for(lli i=m-1;i>=n;i--)
#define pb(n) push_back(n)
#define UE(N) N.erase(unique(N.begin(),N.end()),N.end());
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(30) << S << endl
#define Vec(K,L,N,S) vector<L> K(N,S)
#define DV(K,L,N,M,S) vector<vector<L>> K(N,vector<L>(M,S))
#define TV(K,L,N,M,R,S) vector<vector<vector<L>>> K(N,vector<vector<L>>(M,vector<L>(R,S)))
#define pint pair<lli,lli>
#define paf(L,R) pair<L,R>
#define mod 1000000007
#define MAX 5100000
#define ALL(a)  a.begin(),a.end()
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
int main(){
  lli A,B,C,D,E,F,N,M,K,L,R,X,Y,Z,H,W,sum=0,num=0,flag=0;string S,T;
  cin >> N >> K;
  Vec(Cos,lli,N,0);
  Vec(DP,lli,N,INF);
  rep(i,0,N)cin >> Cos[i];
  DP[0]=0;
  rep(i,0,N)rep(j,1,K+1){
    if(i+j>=N)continue;
    chmin(DP[i+j],DP[i]+abs(Cos[i+j]-Cos[i]));
  }
  Out(DP[N-1]);
}

Measured memory_bytes: 1792
import math

n = int(input())
m = len(str(n))

for a in range(1,int(math.sqrt(n))+1):
    if (n // a) * a == n:
        if m > len(str(max(a,(n//a)))): 
            m = len(str(max(a,(n//a))))
            
print(m)

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

#define INF 1234567890
#define ll long long

int N, M;
string s[111];
int dist[111][111];
int dir[2][2] = {{0, 1}, {1, 0}};

int BFS()
{
	deque<pair<int, pair<int, int> > > dq;
	dq.push_front({0, {0, 0}});
	while(!dq.empty())
	{
		int y = dq.front().second.first, x = dq.front().second.second;
		int d = dq.front().first;
		dq.pop_front();

		if (dist[y][x] != -1) continue;
		dist[y][x] = d;

		for(int i=0; i<2; i++)
		{
			int ny = y + dir[i][0], nx = x + dir[i][1];
			if (ny<0||nx<0||ny>=N||nx>=M) continue;
			if (s[y][x]=='.' && s[ny][nx]=='#')
			{
				dq.push_back({d+1, {ny, nx}});
			}
			else
			{
				dq.push_front({d, {ny, nx}});
			}
		}
	}
	int add = 0;
	if (s[0][0] == '#') add++;
	return dist[N-1][M-1] + add;
}

int main()
{
	memset(dist, -1, sizeof(dist));
	cin >> N >> M;
	for(int i=0; i<N; i++)
		cin >> s[i];
	printf("%d", BFS());
	return 0;
}

Measured memory_bytes: 256
def main():
    N,*A=map(int, open(0).read().split())
    ans = 0
    while any(a>=N for a in A):
        x = sum(a//N for a in A)
        A = [x-a//N+a%N for a in A]
        ans += x
    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define ll long long

using namespace std;

ll n, a[4], b[4];
ll ans = 0, fac = 8;

int main() {
  for (int i = 0; i < 4; i++) cin >> a[i];
  cin >> n;
  n <<= 2;
  for (int i = 0; i < 4; i++) {
    ll foo = fac;
    for (int j = i; j < 4; j++) {
      b[j - i] = foo * a[j - i];
      foo >>= 1;
    }
    sort(b, b + (4 - i));
    ans += b[0] * (n / fac);
    n %= fac;
    fac >>= 1;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define int long long
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define all(x) (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n",(x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define isYes(x) printf("%s\n",(x) ? "Yes" : "No")
#define isIn(x,y,h,w) (x >= 0 && x < h && y >= 0 && y < w)
#define debug(var) cout << "[" << #var << "] " << var << endl

const int INF = 1<<29;
const double EPS=1e-9;
const int MOD=998244353;

signed main() {
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i, N) cin >> A[i];
    int Q;
    cin >> Q;
    vector<int> nums(pow(10, 5)+1, 0);
    rep(i, N) nums[A[i]]++;
    int ans = 0;
    rep(i, N) ans += A[i];

    rep(xxxxx, Q) {
        int B, C;
        cin >> B >> C;

        ans += (C - B) * nums[B];
        nums[C] += nums[B];
        nums[B] = 0;

        cout << ans << endl;
    }
}


Measured memory_bytes: 4748
#ifndef BZ
#pragma GCC optimize "-O3"
#endif
#include <bits/stdc++.h>

#define FASTIO
#define ALL(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i < (r); ++i)

#ifdef FASTIO
#define scanf abacaba
#define printf abacaba
#endif

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

using namespace std;

const int MX = 3007;

ld f[MX][MX];

ld a[MX];

int main() {
#ifdef FASTIO
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#endif
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }

    f[0][0] = 1.0;

    for (int i = 0; i < n; i++) {
        for (int j = 0; j <= n; j++) {
            f[i + 1][j + 1] += f[i][j] * a[i];
            f[i + 1][j] += f[i][j] * (1.0 - a[i]);
        }
    }

    ld ans = 0;
    for (int i = 0; i <= n; i++) {
        if (i >= n - i) {
            ans += f[n][i];
        }
    }

    cout.precision(20);
    cout << fixed << ans << "\n";
    return 0;
}



Measured memory_bytes: 141568
import sys
sys.setrecursionlimit(10**9)
n, m = map(int, input().split())

root = [-1]*n

def find(n):
    if root[n] < 0:
        return n
    else:
        root[n] = find(root[n])
        return root[n]

def unite(x, y):
    x = find(x)
    y = find(y)
    if x == y:
        return
    else:
        root[x] += root[y]
        root[y] = x

for i in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    unite(a, b)

print(-min(root))

Measured memory_bytes: 81100