akhauriyash/Code-Regression huggingface dataset:
h, w = input().split()
h, w = int(h), int(w)

grid_state = []

# 1 = black, 0 = white

for _ in range(h):
    temp = [int(s) for s in input().replace(".", "0").replace("#", "1")]
    grid_state.append(temp)

grid_cost = [[0 for _ in range(w)] for _ in range(h)]

grid_cost[0][0] = grid_state[0][0]

for i in range(1, h + w - 1):
    j = i
    if j > w - 1:
        j = w - 1
    while((j >= 0) and (i - j < h)):
        if i - j == 0:
            if grid_state[i - j][j - 1] == 1:
                grid_cost[i - j][j] = grid_cost[i - j][j - 1]
            else:
                grid_cost[i - j][j] = grid_cost[i - j][j - 1] + grid_state[i - j][j]
        elif j == 0:
            if grid_state[i - j - 1][j] == 1:
                grid_cost[i - j][j] = grid_cost[i - j - 1][j]
            else:
                grid_cost[i - j][j] = grid_cost[i - j - 1][j] + grid_state[i - j][j]
        else:
            min_cost = min([grid_cost[i - j - 1][j], grid_cost[i - j][j - 1]])

            if grid_state[i - j][j] == 0:
                grid_cost[i - j][j] = min([grid_cost[i - j - 1][j], grid_cost[i - j][j - 1]])
            elif (grid_state[i - j - 1][j] == 1) and (grid_cost[i - j - 1][j] <= grid_cost[i - j][j - 1]):
                grid_cost[i - j][j] = min_cost
            elif (grid_state[i - j - 1][j] == 0) and (grid_cost[i - j - 1][j] < grid_cost[i - j][j - 1]):
                grid_cost[i - j][j] = min_cost + 1
            elif (grid_state[i - j][j - 1] == 1) and (grid_cost[i - j - 1][j] >= grid_cost[i - j][j - 1]):
                grid_cost[i - j][j] = min_cost
            else:
                grid_cost[i - j][j] = min_cost + 1

        j -= 1

print(grid_cost[h - 1][w - 1])

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

int main(){
  int n, r;
  cin >> n >> r;
  cout << r + max(0, 100 * (10 - n)) << endl;;
}

Measured memory_bytes: 256
from bisect import bisect_right
INF = 10 ** 18
A, B, Q = [int(x) for x in input().split()]
S = [-INF] +[int(input()) for _ in range(A)] + [INF]
T = [-INF] +[int(input()) for _ in range(B)] + [INF]
X = [int(input()) for _ in range(Q)]
for x in X:
    ans = INF
    b = bisect_right(S, x)
    d = bisect_right(T, x)
    dist = []
    for s in [S[b-1], S[b]]:
        for t in [T[d-1], T[d]]:
            ans = min(ans, abs(x-s)+abs(s-t), abs(x-t)+abs(t-s))
    print(ans)


Measured memory_bytes: 85848
#include <algorithm>
#include <iostream>
#include <stack>
#include <unordered_set>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
int N, M;
int pos = -1;
vector<vector<int>> G;
vector<bool> seen, finished;
stack<int> hist;

bool dfs(int u) {
  seen[u] = true;
  hist.push(u);
  for (auto v : G[u]) {
    if (finished[v]) continue;
    if (seen[v] && !finished[v]) {
      pos = v;
      return true;
    }
    if (dfs(v)) return true;
  }
  hist.pop();
  finished[u] = true;
  return false;
}

int main(void) {
  ios::sync_with_stdio(false);
  cin >> N >> M;
  seen.assign(N, false);
  finished.assign(N, false);
  G.resize(N);
  rep(i, M) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    G[a].emplace_back(b);
  }

  rep(i, N) {
    pos = -1;
    if (dfs(i)) break;
  }
  if (pos == -1) {
    cout << -1 << endl;
    return 0;
  }

  vector<int> cycle;
  while (!hist.empty()) {
    cycle.emplace_back(hist.top());
    if (hist.top() == pos) break;
    hist.pop();
  }
  reverse(cycle.begin(), cycle.end());

  while (true) {
    int N2 = cycle.size();
    vector<int> ord(N, -1);
    rep(i, N2) ord[cycle[i]] = i;

    int from = -1, to = -1;
    rep(i, N2) {
      for (auto nv : G[cycle[i]]) {
        if (nv != cycle[(i + 1) % N2] && ord[nv] != -1) {
          from = i;
          to = ord[nv];
        }
      }
    }
    if (from == -1) break;

    vector<int> ncycle;
    ncycle.emplace_back(cycle[from]);
    int id = to;
    while (id != from) {
      ncycle.emplace_back(cycle[id]);
      id = (id + 1) % N2;
    }
    cycle = ncycle;
  }

  cout << cycle.size() << endl;
  for (auto u : cycle) {
    cout << u + 1 << endl;
  }
  return 0;
}


Measured memory_bytes: 3776
import java.util.*;

class Main{
    public static void main(String[] args) {
        Scanner stdIn = new Scanner(System.in);
        int n = stdIn.nextInt();
        int k = stdIn.nextInt();
        char[] s = stdIn.next().toCharArray();
        s[k-1] += 'a' - 'A';
        System.out.println(s);
   }
}


Measured memory_bytes: 21972
#include "bits/stdc++.h"
#define fi first
#define se second
#define all(x) x.begin(), x.end()
using namespace std;
using ull = unsigned long long;
using ll = long long;
constexpr int I_INF = INT_MAX;
constexpr ll L_INF = LLONG_MAX;

struct __INIT {
    __INIT() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(15);
    }
} __init;


int main(){
    int a, b, h;
    cin >> a >> b >> h;
    cout << (a + b) * h / 2 << endl;
}

Measured memory_bytes: 256
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
	public static void main(String[]args) {
		try(Scanner scan = new Scanner(System.in)){
			
			int N = scan.nextInt();
			int[]A = new int[N];
			for(int i= 0;i<N;i++) {
				A[i] = scan.nextInt();
			}
			
			Map<Integer,Integer>map = new HashMap<Integer,Integer>();
			
			for(int i = 0;i<N;i++) {
				if(map.containsKey(A[i])) {
					map.put(A[i], map.get(A[i])+1);
				}else{
					map.put(A[i], 1);
				
				}
			}
			//long goukei2 =0;
			long anstemp = 0;
			for(Integer key:map.keySet()) {
					//goukei2+=sa(map.get(key),2);
				long v = map.get(key);
				   anstemp+=(v*(v-1)/2);
			}
			for(int i= 0;i<N;i++) {
				/*long goukei = 0;
				goukei +=goukei2;
				goukei-=sa(map.get(A[i]),2);
				goukei+=sa(map.get(A[i])-1,2);
				System.out.println(goukei);*/
				
				 long ans = anstemp;
				   long v = map.get(A[i]);
				   ans -= (v*(v-1)/2);
				   ans += ((v-1)*(v-2)/2);
				   System.out.println(ans);
				
			}
			
		}
		
		
	}
	
	private static long sa(int n,int b) {
		return n*(n-1)/b;
	}
	
	

}

Measured memory_bytes: 102872
#include <iostream>

using namespace std;

int main(){
	int X, N;
	cin >> X >> N;

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

	int ans = 1e9;
	for (int i = 0; i <= 101; i++){
		bool skip = false;
		for (int j = 0; j < N; j++){
			if(i == p[j]){
				skip = true;
				break;
			}
		}
		if(skip){
			continue;
		}

		if (abs(i - X) < abs(ans - X))
		{
			ans = i;
		}
		else if (abs(i - X) == abs(ans - X))
		{
			ans = min(ans, i);
		}
	}

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


Measured memory_bytes: 3548
#include <bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
#define eps 1e-9

typedef long long ll;

using namespace std;

const ll inf = 1e18;
const ll mod = 1e9+7;
const int N = 1e5+5;
int a[101][101];

int main()

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

    int h, w, n, printed = 0;

    cin >> h >> w >> n;

    int arr[n];

    for (int i = 0; i < n; i++) {

        cin >> arr[i];
    }

    for (int i = 0; i < h; i++) {

        if (i%2 == 0) {

            for (int j = 0; j < w; j++) {

                if (arr[printed]) {

                    a[i][j] = printed+1;
                    arr[printed]--;

                } else {

                    printed++;
                    a[i][j] = printed+1;
                    arr[printed]--;
                }
            }
        } else {

            for (int j = w-1; j >= 0; j--) {

                if (arr[printed]) {

                    a[i][j] = printed+1;
                    arr[printed]--;

                } else {

                    printed++;
                    a[i][j] = printed+1;
                    arr[printed]--;
                }
            }

        }
    }

    for (int i = 0; i < h; i++) {

        for (int j = 0; j < w; j++) {

            cout << a[i][j] << " ";
        }

        cout << endl;
    }

    return 0;
}


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

int main() {
    int S, W;
    cin >> S >> W;

    if(S > W)cout << "safe" << endl;
    else cout << "unsafe" << endl;
}

Measured memory_bytes: 3636
require 'set'

class Hash
  def push(key, value)
    self[key] = [] if self[key] == nil
    self[key].push(value)
  end
end

def get_ints
  gets.split.map(&:to_i)
end

def get_ints_minus_one
  get_ints.map { |x| x - 1 }
end

def get_int
  gets.chomp.to_i
end

X, Y = get_ints

min_x = X * 2
max_x = X * 4
even = Y % 2 == 0

if max_x < Y || min_x > Y || !even
  puts 'No'
else
  puts 'Yes'
end


Measured memory_bytes: 14244
import java.util.*;
import java.util.stream.IntStream;

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

        int N = sc.nextInt();
        List<Integer> A = new ArrayList<>();
        for (int i = 0; i < N; i++) A.add(sc.nextInt());

        List<Integer> ASorted = new ArrayList<>(A);
        ASorted.sort(Comparator.reverseOrder());
        int max = ASorted.get(0);
        int secondLargest = ASorted.get(1);

        for (int i = 0; i < N; i++) {
            if (A.get(i) == max)
                System.out.println(secondLargest);
            else
                System.out.println(max);
        }



    }
}


Measured memory_bytes: 101004
import java.io.*;
import java.util.*;
public class Main
{
	
	private void solve()throws IOException
	{
		int n=nextInt();
		Pair a[]=new Pair[n+1];
		for(int i=1;i<=n;i++)
			a[i]=new Pair(nextInt(),i);
		Arrays.sort(a,1,n+1,new Comparator<Pair>(){
			public int compare(Pair a,Pair b){
				return a.first-b.first;
			}
		});
		int ans[]=new int[n+1];
		for(int i=1;i<=n/2;i++)
			ans[a[i].second]=a[n/2+1].first;
		for(int i=n/2+1;i<=n;i++)
			ans[a[i].second]=a[n/2].first;
		for(int i=1;i<=n;i++)
			out.println(ans[i]);
	}
	class Pair{
	    int first,second;
	    Pair(int a,int b){
	        first=a;
	        second=b;
	    }
	}

	 
	///////////////////////////////////////////////////////////

	public void run()throws IOException
	{
		br=new BufferedReader(new InputStreamReader(System.in));
		st=null;
		out=new PrintWriter(System.out);

		solve();
		
		br.close();
		out.close();
	}
	public static void main(String args[])throws IOException{
		new Main().run();
	}
	BufferedReader br;
	StringTokenizer st;
	PrintWriter out;
	String nextToken()throws IOException{
		while(st==null || !st.hasMoreTokens())
		st=new StringTokenizer(br.readLine());
		return st.nextToken();
	}
	String nextLine()throws IOException{
		return br.readLine();
	}
	int nextInt()throws IOException{
		return Integer.parseInt(nextToken());
	}
	long nextLong()throws IOException{
		return Long.parseLong(nextToken());
	}
	double nextDouble()throws IOException{
		return Double.parseDouble(nextToken());
	}
}

Measured memory_bytes: 56432
#include <vector>
#include <cstdio>
#include <climits>
#include <iostream>

int main(){
	int v, e;
	std::scanf("%d %d", &v, &e);
	//v = 4; e = 6; r = 0;
	std::vector<std::vector<int>> distance(v, std::vector<int>(v, INT_MAX));
	std::vector<std::vector<int>> to(v);
	std::vector<std::vector<int>> from(v);
	for (auto i = 0; i < e; ++i){
		int s, t, d;
		std::scanf("%d %d %d", &s, &t, &d);
		distance.at(s).at(t) = d;
		to.at(s).push_back(t);
		from.at(t).push_back(s);
	}
	//f(0,1,2,distance,to,from);f(0,2,3,distance,to,from);f(1,2,-5,distance,to,from);f(1,3,1,distance,to,from);f(2,3,2,distance,to,from);f(3,1,0,distance,to,from);
	bool negative = false;
	for (auto i = 0; i < v; ++i){
		distance.at(i).at(i) = 0;
	}
	for (auto k = 0; k < v; ++k){
		for (auto i : from.at(k)){
			for (auto j : to.at(k)){
				//std::cout << "k = " << k << " i = " << i << " j = " << j << "dist" << distance.at(i).at(j) << "-" << distance.at(i).at(k) << "-" << distance.at(k).at(j) << std::endl;
				if (distance.at(i).at(j) > distance.at(i).at(k) + distance.at(k).at(j)){
					if (distance.at(i).at(j) == INT_MAX and i != j){
						to.at(i).push_back(j); from.at(j).push_back(i);
					}
					distance.at(i).at(j) = distance.at(i).at(k) + distance.at(k).at(j);
				}
			}
			if (distance.at(i).at(i) < 0){
				negative = true;
				k = v - 1;
			}
		}
	}
	if (negative){
		std::printf("NEGATIVE CYCLE\n");
	}else{
		for (auto i = 0; i < v; ++i){
			if (distance.at(i).at(0) < INT_MAX){
				std::printf("%d", distance.at(i).at(0));
			}else{
				std::printf("INF");
			}
			for (auto j = 1; j < v; ++j){
				if (distance.at(i).at(j) < INT_MAX){
					std::printf(" %d", distance.at(i).at(j));
				}else{
					std::printf(" INF");
				}
			}
			std::printf("\n");
		}
	}
}

Measured memory_bytes: 1356
N = int(input())
count = [0]*5
march = list("MARCH")
for i in range(N):
    s = input()
    for i in range(5):
        if s[0] == march[i]:
            count[i] += 1
ans = 0
for i in range(5):
    for j in range(i+1,5):
        for k in range(j+1,5):
            ans += count[i] * count[j] * count[k]
print(ans)

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

using namespace std;

int main(void)
{
    int N, M;
    int A, B, C, D;
    int S, G, V, P;
    scanf("%d%d", &N, &M);
    int K[24][24];
    for (int i = 1; i <= N; i++)
        for (int j = 1; j <= N; j++)
            K[i][j] = 1e6;
    while(M)
    {
        scanf("%d,%d,%d,%d", &A, &B, &C, &D);
        K[A][B] = C;
        K[B][A] = D;
        M--;
    }
    scanf("%d,%d,%d,%d", &S, &G, &V, &P);
    for (int k = 1; k <= N; k++)
        for (int i = 1; i <= N; i++)
            for (int j = 1; j <= N; j++)
                if (K[i][j] > K[i][k] + K[k][j]) K[i][j] = K[i][k] + K[k][j];
    cout << (V - P - K[S][G] - K[G][S]) << endl;
    return 0;
}


Measured memory_bytes: 3128
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<array>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
typedef int long long ll;

using namespace std;
static const int WHITE =0;
static const int GRAY=1;
static const int BLACK=2;
static const int N=100;

int n,color[N],tt,d[N],f[N];
int M[N][N];
int nt[N];
int next(int u){
    for(int v=nt[u];v<n;v++){
        nt[u]=v+1;//頂点に複数頂点隣接してる場合、小さいのから取り出せるように、
        //nt[u]nextで渡した頂点の数がはいる
        if(M[u][v])return v;
    }
    
    
    return -1;
}



void dfs_visit(int r){
    for(int i=0;i<n;i++){
        nt[i]=0;
    }
    stack<int>S;
    S.push(r);
    color[r]=GRAY;
    d[r]=++tt;
    
    while(!S.empty()){
        int u=S.top();
        int v=next(u);
        if(v!=-1){
            if(color[v]==WHITE){
                color[v]=GRAY;
                d[v]=++tt;
                S.push(v);
            }
        }else{
            S.pop();
            color[v]=BLACK;
            f[u]=++tt;
        }
    }
    
}

void dfs(){
    
    rep(i,n){color[i]=WHITE;nt[i]=0;}tt=0;
    
    
    rep(i,n){
        if(color[i]==WHITE){
            dfs_visit(i);
           }
    }
        
        
    rep(i,n){
        
        cout<<i+1<<" "<<d[i]<<" "<<f[i]<<endl;
    }
    
    
    
    
    
}



int main(){
    
    cin>>n;
    rep(i,n){
        int k,l;cin>>k>>l;
        k--;
        for(int j=0;j<l;j++){
            int u;
            cin>>u;
            M[k][u-1]=1;
        }
    }
  /*  rep(i,n){
        rep(j,n){cout<<M[i][j];}
    cout<<endl;
    }*/
    dfs();
    
    
return 0;
}



Measured memory_bytes: 3132
#include <fstream>
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <sstream>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <cmath>
#include <queue>
#include <random>

using namespace std;

#define INT_MAX_VALUE 2147483647
#define LONG_LONG_MAX_VALUE 9223372036854775807
#define ll long long

template <class T>
T mymax(T a,T b){
    if(a>=b) return a;
    return b;
}
template <class T>
T mymin(T a,T b){
    if(a<=b) return a;
    return b;
}

ll gcd(ll a, ll b){
    if(a<b){
        swap(a,b);
    }
    while(b){
        ll r = a%b;
        a=b;
        b=r;
    }
    return a;
}

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

struct XX{
    int a;
    int b;
    int z;
    int i;
};

class xxGreater {
public:
    bool operator()(const XX& riLeft, const XX& riRight) const {
        //第2条件
        if((riLeft.b) == (riRight.b)){
            return riLeft.i < riRight.i;//<:昇順(小さいものから順番)、>:降順(大きいものから順番)
            //プライオリティキューの場合は > で、top()すると値の小さいものがとれる
        }
        //第1条件
        return (riLeft.b) > (riRight.b);
    }
};

//map<long long,long long> prime_f(long long n){
//    map<long long,long long>res;
//    for(int i=2;i*i<=n;i++){
//        while(n%i==0){
//            ++res[i];
//            n/=i;
//        }
//    }
//    if(n!=1)res[n]=1;
//    return res;
//}


int main(int argc, const char * argv[])
{
    //std::ios::sync_with_stdio(false);
    //scanf("%s",S);
    //scanf("%d",&N);
    //sscanf(tmp.c_str(),"%dd%d%d",&time[i], &dice[i], &z[i]);
    //getline(cin, target);
    //cin >> x >> y;
    //テスト用
    //ifstream ifs( "1_06.txt" );
    //ifs >> a;
    //ここから
    
    //入力高速化
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    ll X,Y;
    cin >> X >> Y;

    if(X==Y){
        cout << -1 << endl;
    }else if(X<Y){
         cout << X << endl;
    }else{
        //X>Y
        if(X%Y==0){
            cout << -1 << endl;
        }else{
            cout << X << endl;
        }
    }

    
    //ここまで
    //cout << "debug" << endl;
    //cout << "ans" << endl;改行含む
    //printf("%.0f\n",ans);//小数点以下表示なし
    //printf("%.7f\n",p);
    //printf("%f\n",pow(2,ans.size()));
    
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define ALL(v) (v).begin(),(v).end()
#define Vi vector<int>
#define pb push_back
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repeq(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=a;i>b;i--)
#define repreq(i,a,b) for(int i=a;i>=b;i--)
#define leng(n) (int)(log10(n)+1)
#define INF 9000000000000000000
#define MOD 1000000007
#define PAI 3.14159265358979
// ver1.6
using namespace std;

int gcd(int a,int b){return b?gcd(b,a%b):a;}  //  最大公約数gcd
int lcm(int a,int b){return a/gcd(a,b)*b;}  //  最小公倍数lcm

signed main() {
  int n;
  cin >> n;
  Vi a(n);
  rep(i,0,n) cin >> a[i];
  
  int maxx = 0;
  int now = 0;
  rep(i,0,n-1){
    if(a[i] < a[i+1]){
      maxx = max(maxx,now);
      now = 0;
    }
    else now++;
  }
  maxx = max(maxx,now);
  
  cout << maxx << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define INF 0x7ffffffffffffff
using namespace std;
const int N = 205;
struct Edge {
    int to, next = 0;
    long long cm, ct;
} edge[N];
int head[N] = {}, cnt = 0;
int n, m, s;
long long dis[55][3005] = {};
long long C[55] = {}, D[55] = {};
long long ans[N] = {};
inline void add_edge(int u, int v, int cm, int ct) {
    edge[++cnt].to = v;
    edge[cnt].cm = cm;
    edge[cnt].ct = ct;
    edge[cnt].next = head[u];
    head[u] = cnt;
}
void init() {
    for (int i = 0; i < 55; i++)
        fill(dis[i], dis[i] + 3005, INF);
    fill(ans, ans + N, INF);
}
void dijkstra() {
    s = min(s, 2500);
    priority_queue<tuple<long long, int, long long>> pq;
    pq.emplace(-0, 1, s);
    dis[1][s] = 0;
    long long t, now, w;
    while (pq.size()) {
        tie(t, now, w) = pq.top();
        pq.pop();
        t = -t;
        if (dis[now][w] < t) continue;
        ans[now] = min(ans[now], dis[now][w]);
        for (int i = head[now]; i; i = edge[i].next) {
            int v, f;
            v = edge[i].to, f = edge[i].cm;
            if (w >= f && t + edge[i].ct < dis[v][w - f]) {
                dis[v][w - f] = t + edge[i].ct;
                pq.emplace(-dis[v][w - f], v, w - f);
            }
        }
        if (w <= 2500) {
            w = min(w + C[now], (long long)2500);
            if (dis[now][w] > t + D[now]) {
                dis[now][w] = t + D[now];
                pq.emplace(-dis[now][w], now, w);
            }
        }
    }
}
int main() {
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    init();
    cin >> n >> m >> s;
    while (m--) {
        int u, v, cm, ct;
        cin >> u >> v >> cm >> ct;
        add_edge(u, v, cm, ct);
        add_edge(v, u, cm, ct);
    }
    for (int i = 1; i <= n; i++)
        cin >> C[i] >> D[i];
    dijkstra();
    for (int i = 2; i <= n; i++)
        cout << ans[i] << '\n';
    return 0;
}

Measured memory_bytes: 7620
#pragma region template
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long MOD = 998244353, MAX = 1e18, larg = 1e5, INF = -1e18;
long long A, B, C, D, E, F, G, H, I, J, K, L, N, M, O, P, Q, R, S, T, U, V, W, x, y, z;
long long max_value = INF, max_index = -1;
long long min_value = MAX, min_index = -1;
typedef long long ll;
typedef pair<ll, ll> Pa;

ll arr[100000];
ll cnt[40];

int main() {
	cin.tie(0); ios_base::sync_with_stdio(false);
	cin >> N >> K;
	rep(i, N) {
		cin >> arr[i];
		rep(j, 40) {
			if (((arr[i] >> j)%2) == 0) cnt[j]++;
		}
	}
	ll sum = 0;
	rep(i, 40) {
		if (N - cnt[i] < cnt[i]) {
			sum += (1ll << i);
		}
	}
	ll num = 0;
	bool flag = false;
	for (int i = 39; i >= 0; i--) {
		if (flag) {
			num += (((sum >> i)%2) << i);
			continue;
		}
		if ((sum >> i) % 2 == ((K >> i) % 2)) {
			num += (((K >> i) % 2) << i);
		}
		else if ((sum >> i) % 2 == 0) {
			num += (((sum >> i) % 2) << i);
			flag = true;
		}
	}
	ll ans = 0;
	rep(i, N) {
		ans += num ^ arr[i];
	}
	cout << ans;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
const int M = 1e+9+7;

vector<int> get_count(int n) {
	vector<int> count(n);
	for(int i = 0; i < n;i++){
		count[abs(i - (n - i - 1))]++;
	}
	return count;
}

bool check_possible(vector<int> count, vector<int>& as){
	for(int item: as){
// 		cout << count[item] << endl;
		if(count[item]-- <= 0)
			return false;
	}
	return true;
}

unsigned int solve(vector<int> & count){
	unsigned int res = 1;
	for(auto item: count){
		if(item <= 0)
			continue;
		res = res * item % M;
	}
	return res;
}

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

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

	auto count = get_count(n);
// 	for(auto item: count)
// 		cout << item << endl;

	if(check_possible(count,as)){
		cout << solve(count) << endl;
	}else{
		cout << 0 << endl;
	}
}



Measured memory_bytes: 1408
#include <cstdio>
#include <cstring>
#include <queue>
#include <algorithm>

using namespace std;

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

int N,L;
ll a[100015], t[100015];

int main(){
  scanf("%d%d",&N,&L);
  priority_queue<P>q;
  for(int i=0;i<N;i++){
    scanf("%lld", &a[i+1]);
    q.push(P(a[i+1],i+1));
  }
  ll res = 0;
  while(!q.empty()){
    P p = q.top(); q.pop();
    ll len = p.first;
    int v = p.second;
    t[v] = max(t[v-1],t[v+1]) + L - len;
    res = max(res, t[v]);
  }

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

Measured memory_bytes: 4256
import math
while True:
    
    d,e = map(int,input().split())
    sa = max(d,e)
    if d == 0 and e == 0:
        break
    for i in range(math.floor(d/2) + 1):
        if math.fabs(math.sqrt(i ** 2 + (d - i) ** 2) - e) < sa:
            sa = math.fabs(math.sqrt(i ** 2 + (d - i) ** 2) - e)
    print(sa)

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

int main(void){
    int tx,ty;
    string s;
    cin>>s>>tx>>ty;
    assert(abs(tx)<=8000 && abs(ty)<=8000);
    s += "T";
    int init = s.find("T",0);
    tx -= init;
    s = string(s.begin()+init, s.end());
    bitset<M*2> dp[2];
    dp[0][M] = dp[1][M] = 1;
    int cnt = 0, mode = 0;
    for(char c : s){
        if(c=='F') cnt++;
        else{
            dp[mode] = (dp[mode]<<cnt) | (dp[mode]>>cnt);
            cnt = 0;
            mode = !mode;
        }
    }
    cout<<((dp[0][M+tx] && dp[1][M+ty]) ? "Yes" : "No")<<endl;
}


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

using namespace std;

using ll = long long;

const long long MOD_NUMBER = 1000000007;
const int MAX = 2147483647;
const double PI = 3.14159265358979323846;

int main() {
  ll n, sum = 0;
  cin >> n;
  vector<ll> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    sum ^= a[i];
  }
  for (int i = 0; i < n; i++) {
    cout << (sum ^ a[i]);
    if (i != n - 1) {
      cout << " ";
    }
  }
  cout << endl;
}

Measured memory_bytes: 4836
#include<iostream>
#include<algorithm>
#include<vector>
#include<functional>
#include<numeric>
#include<climits>
#include<queue>
 
using namespace std;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, k;
	cin >> n >> k;
	vector<vector<long long>> a(k,vector<long long>(k,0));
	int x, y, sign;
	char c;
	long long base = 0;
	for (int i = 0; i < n; i++) {
		sign = 1;
		cin >> x >> y >> c;
		x %= 2 * k;
		if (x >= k) {
			sign *= -1;
			x -= k;
		}
		y %= 2 * k;
		if (y >= k) {
			sign *= -1;
			y -= k;
		}
		if (c == 'W') {
			sign *= -1;
		}
		a[x][y] += sign;
	}
	for (int i = 0; i < k; i++) {
		for (int j = 1; j < k; j++) {
			a[i][j] += a[i][j - 1];
		}
	}
	for (int i = 0; i < k; i++) {
		for (int j = 1; j < k; j++) {
			a[j][i] += a[j - 1][i];
		}
	}
	long long ans = 0;
	for (int i = 0; i < k; i++) {
		for (int j = 0; j < k; j++) {
			ans = max(ans, abs(a[k-1][k-1]-2*(a[i][k-1]+a[k-1][j])+4*a[i][j]));
		}
	}
	cout << (ans+n)/2 << endl;
	return 0;
}

Measured memory_bytes: 8064
#include<stdio.h>
#include<math.h>
#define max 3

int main(void){
  int i,j,n;
  double x[4],y[4],xp,yp,r;
  double x12,x23,x31,y12,y23,y31;
  double x21,x32,x13,y21,y32,y13;
  double temp1,temp2;
  
  scanf("%d",&n);
  for(i=1;i<=n;i++){
    for(j=1;j<=max;j++){
      scanf("%lf",&x[j]);
      scanf("%lf",&y[j]);
    }
    x12=x[1]-x[2]; x23=x[2]-x[3]; x31=x[3]-x[1];
    x21=x[1]+x[2]; x32=x[2]+x[3]; x13=x[3]+x[1];
    y12=y[1]-y[2]; y23=y[2]-y[3]; y31=y[3]-y[1];
    y21=y[1]+y[2]; y32=y[2]+y[3]; y13=y[3]+y[1];
    xp=((y23*(x12*x21+y12*y21))-(y12*(x23*x32+y23*y32)))/(double)(2*(x12*y23-x23*y12));
  
    yp=((x23*(y12*y21+x12*x21))-(x12*(x23*x32+y23*y32)))/(double)(2*(y12*x23-y23*x12));
    temp1=((xp-x[1])*(xp-x[1]));
    temp2=((yp-y[1])*(yp-y[1]));
    r=(double)sqrt(temp1+temp2);

    if((-0.0005<xp)&&(xp<=0))xp=0;
    if((-0.0005<yp)&&(yp<=0))yp=0;
    printf("%.3f %.3f %.3f\n",xp,yp,r);
  }
  return 0;
}

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

int main(){
    int W, H, x, y;
    cin >> W >> H >> x >> y;

    double ans = (double)W*H/2;
    int flag = 0;
    if(x*2 == W && y*2 == H)
        flag = 1;

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


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

const long long MOD = 1000000007;
const long long INF = 1LL << 60;

int main()
{
  ll A, B, C, X, Y;
  cin >> A >> B >> C >> X >> Y;
  ll ans = INF;
  for (int i = 0; i <= 300000; i++)
  {
    ll tmp = C * 2 * i + A * max(0LL, X - i) + B * max(0LL, Y - i);
    ans = min(tmp, ans);
  }
  cout << ans << endl;
  return 0;
}

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

//使い方がよくわからない
#include<stack>
#include<queue>
#include<bitset>
#include<sstream>

#define rep(i,n) for(int i=0;i<(n);i++) 
#define rep1(i,n) for(int i=1;i<(n);i++)
#define co(x) cout << x << endl
#define cosp(x) cout << x << " "

using namespace std;
using ll = long long;

int main(int argc,const char *argv[]){
    int n,k;
    cin >> n >> k;
    vector<int> p(n);
    rep(i,n) cin >> p[i];
    vector<int> q(k);
    rep(i,k) q[i]=p[i];
    sort(q.begin(),q.end());
    int nc = 0;
    int sum = 0, cnt1=1;
    vector<int> r(n,1);
    rep1(i,n){
        if(p[i-1]<=p[i]) cnt1++;
        else cnt1=1;
        r[i] = cnt1;
    }
    if(r[k-1]==k){nc++;}else{sum++;}
    rep(i,n-k){
        q.insert(lower_bound(q.begin(), q.end(), p[k+i]), p[k+i]);
        if(r[i+k]>=k){nc++;}
        else{
            if((q[0]!=p[i])||q[k]!=p[i+k]) sum++;
        }
        q.erase(lower_bound(q.begin(), q.end(), p[i]));
    }
    if(nc>0) sum++;
    co(sum);
    return 0;
}

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

/* #pragma */
/*
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
*/

/*alias*/
#define F first
#define S second

#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define itn int

/*template*/
template<class T>inline bool amax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>inline bool amin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }

/* func */
int GCD(int a,int b){return b?GCD(b,a%b):a;}
long long GCD(long long a, long long b){return b ? GCD(b, a%b) : a;}
int LCM(int a, int b){return a * b / GCD(a, b);}
long long LCM(long long a, long long b){return a * b / GCD(a, b);}

/*struct*/
struct aaa {
	aaa() {
		cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20);
	};
}aaaaaaa;

/* const */
const int INF = 1001001001;
const long long LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7; //10^9
const double EPS = 1e-9;
const int dx[] = { 1, 1, 0, -1, -1, -1, 0, 1 }, dy[] = { 0, 1, 1, 1, 0, -1, -1, -1 };
//const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
//Counterclockwise from the 6o'clock direction
//Take the x-axis downward and the y-axis right

//#define int long long

//g++ -std=c++14 -Wall --pedantic-errors -o template template.cpp
//g++ -std=c++14 -Wall --pedantic-errors template.cpp
//chcp 65001

/*global*/

signed main()
{
//	v.resize(n);
string s;cin >> s;
	 if(s[0] == s[1] && s[2] == s[3] && s[0] != s[3]){
	cout << "Yes" << endl;
}
else if(s[1] == s[2] && s[0] == s[3] && s[0] != s[1]){
	cout << "Yes" << endl;
}
else if(s[1] == s[3] && s[2] == s[0] && s[0] != s[3]){
	cout << "Yes" << endl;
}
else{
	cout << "No" << endl;
}
    return 0;
}


Measured memory_bytes: 256
a = int(input())
b = int(input())
c = 2
if a == 1:
    if b == 2:
        c = 3
elif a == 2:
    if b == 1:
        c = 3
    else:
        c = 1
elif a == 3:
    if b == 2:
        c = 1
print(c)


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

using ll = long long;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(c) (c).begin(), (c).end()
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
const int MOD = 1000000007;

int main() {
    string s;
    cin >> s;
    string t = "CODEFESTIVAL2016";
    int c = 0;
    REP(i, s.size()) {
        if (s[i] != t[i]) {
            c++;
        }
    }
    cout << c << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <array>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <utility>
#define INF 987654321
#define INT_MAX 2147483647
#define MIN(a, b) ((a) < (b) ? a : b)
#define MAX(a, b) ((a) > (b) ? a : b)

using namespace std;

int main() {
    int c = 0;
    cin >> c;
    if(c >= 30) cout << "Yes";
    else cout << "No";




}



Measured memory_bytes: 3104
#include <stdio.h>
#include <utility>
#include <vector>
#include <algorithm>
using namespace std;

#define PB push_back
#define F first
#define S second
const int N=1e5+10;
pair<int,int> a[N],b[N];
int p[N],np[N];
bool went[N];
void dfs(int pos){
	went[pos]=true;
	if(!went[p[pos]])dfs(p[pos]);
	return ;
}
int main(){
	int n,cnt=0;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&a[i].F);
	for(int i=1;i<=n;i++)scanf("%d",&b[i].F);
	for(int i=1;i<=n;i++)a[i].S=i;
	for(int i=1;i<=n;i++)b[i].S=i;
	sort(a+1,a+n+1);
	sort(b+1,b+n+1);
	
	for(int i=1;i<=n;i++)np[b[i].S]=i;
	for(int i=1;i<=n;i++)p[np[a[i].S]]=i;
	for(int i=1;i<=n;i++)went[i]=false;
	for(int i=1;i<=n;i++)if(a[i].F>b[i].F){
		printf("No\n");
		return 0;
	}
	for(int i=1;i<=n;i++)if(!went[i]){
		dfs(i);
		cnt++;
	}
	if(cnt==1){
		for(int i=2;i<=n;i++)if(b[i-1].F>=a[i].F){
			printf("Yes\n");
			return 0;
		}
		printf("No\n");
	}
	else printf("Yes\n");
}


Measured memory_bytes: 2560
#include <stdio.h>
#include <stdlib.h>

int main()
{
     int a,b,s,flag=0,i;
     scanf("%d%d",&a,&b);
     if(b>=1&&b<=9)
     s=a*10+b;
     if(b>=10&&b<100)
     s=a*100+b;
     if(b==100)
     s=a*1000+b;
     for(i=1;i<s;i++)
     {
         if(i*i==s)
         flag=1;
     }
     if(flag==1)
     printf("Yes");
     else
     printf("No");

    return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;

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

		System.out.println(Math.max(Math.abs(a - b) - w, 0));
	}
}

Measured memory_bytes: 22740
import sys
sys.setrecursionlimit(10**7)

debug = True
debug = False

def dprint(*objects):
    if debug == True:
        print(*objects)



def solve():
    n, l = map(int, input().split())

    absmn = 10**9
    mn = None
    sm = 0
    for i in range(n):
        index = i + 1
        aji = l + index - 1
        if absmn > abs(aji):
            absmn = abs(aji)
            mn = aji
        sm += aji
    dprint(sm, absmn)
    print(sm - mn)

solve()

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

void trAce(int A[],int N){
	for(int k=0;k<N;k++){
		if(k>0) cout<<" ";
		cout<<A[k];
	}
	cout<<endl;
}

void insertionSort(int A[],int N){
	int i,j,v;
	for(i=1;i<N;i++){
		v=A[i];
		j=i-1;
		while(j>=0&&A[j]>v){
			A[j+1]=A[j];
			j--;
		}
		A[j+1]=v;
		trAce(A,N);
	}
}

int main(){
	int N,i,A[101];
	cin>>N;
	for(i=0;i<N;i++) cin>>A[i];
	trAce(A,N);
	insertionSort(A,N);
	return 0;
}




Measured memory_bytes: 3100
import sys

n = int(input())
for i in range(1, n + 1):
  x = i
  if x % 3 == 0:
    sys.stdout.write(" %d" % i)
  else:
    while x > 1:
      if x % 10 == 3:
        sys.stdout.write(" %d" % i)
        break
      x //= 10
print()

Measured memory_bytes: 7792
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<map>
#include<queue>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main(){
    int n;
    cin>>n;
    int64_t y;
    cin>>y;
    int a10000=-1,a5000=-1,a1000=-1;
    for(int i=0;i*10000<=y||i<=n;i++){
        for(int j=0;(i*10000+j*5000)<=y||i+j<=n;j++){
            if(i*10000+j*5000+(n-i-j)*1000==y){
                a10000=i;
                a5000=j;
                a1000=n-i-j;
                break;
            }
        }
    }
    cout<<a10000<<" "<<a5000<<" "<<a1000<<endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <functional>

using namespace std;

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

#define fst first
#define scd second
#define PB push_back
#define MP make_pair
#define rep(i,x) for(int i=0;i<(x);++i)
#define rep1(i,x) for(int i=1;i<=(x);++i)
#define rrep(i,x) for(int i=(x)-1;i>=0;--i)
#define rrep1(i,x) for(int i=(x);i>=1;--i)
#define FOR(i,a,x) for(int i=(a);i<(x);++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()

#define omajinai ios::sync_with_stdio(false);cin.tie(0)

template<typename T>bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<typename T>bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<typename T>T get(){T a;cin>>a;return a;}
template<typename T>T rev(T a){reverse(all(a));return a;}
template<typename T>istream&operator>>(istream&is,vector<T>&vec){rep(i,vec.size())is>>vec[i];return is;}
template<typename T>vector<T>&sort(vector<T>&a){sort(all(a));return a;}

const int inf = 1e9;
const ll linf = 3e18;
const double eps = 1e-9;

bool used[60];

signed main()
{
    int a, b, c; cin >> a >> b >> c;

    int pos = 0;
    int ans = 0;

    while (!used[pos]) {
        used[pos] = true;
        if (pos <= c && c <= pos + a) {
            cout << ans + (c - pos) << endl;
            return 0;
        }
        if (pos <= 60 + c && 60 + c <= pos + a) {
            cout << ans + (60 + c - pos) << endl;
            return 0;
        }
        ans += a + b;
        pos += a + b; pos %= 60;
    }

    cout << -1 << endl;
}

Measured memory_bytes: 1164
def primeFactor(N):
    i = 2
    ret = {}
    n = N
    mrFlg = 0
    while i**2 <= n:
        k = 0
        while n % i == 0:
            n //= i
            k += 1
            ret[i] = k
        i += 1
        if i == 101 and n >= (2**20):
            def findFactorRho(N): # Primeでないことを確認したものを引数とする。
                def gcd(a, b):
                    while b: a, b = b, a % b
                    return abs(a)
                def f(x, c):
                    return ((x ** 2) + c) % N
                semi = [N]
                for c in range(1, 99):
                    x, y, d = 2, 2, 1
                    while d == 1:
                        x = f(x, c)
                        y = f(f(y, c), c)
                        d = gcd(abs(x-y), N)
                    if d != N:
                        if isPrimeMR(d): return d
                        elif isPrimeMR(N//d):
                            return N//d
                        else:
                            semi.append(d)
            while True:
                if isPrimeMR(n):
                    ret[n], n = 1, 1
                    break
                else:
                    mrFlg = 1
                    j = findFactorRho(n)
                    k = 0
                    while n % j == 0:
                        n //= j
                        k += 1
                        ret[j] = k
                if n == 1: break

    if n > 1: ret[n] = 1
    if mrFlg > 0:
        def dict_sort(X):
            Y={}
            for x in sorted(X.keys()):
                Y[x] = X[x]
            return Y
        ret = dict_sort(ret)
    return ret

def isPrimeMR(n):
    if n == 2:
        return True
    if n == 1 or n & 1 == 0:
        return False
    d = (n - 1) >> 1
    while d & 1 == 0:
        d >>= 1

    for a in [2, 3, 5, 7, 11, 13, 17, 19, 23]:
        t = d
        y = pow(a, t, n)
        while t != n - 1 and y != 1 and y != n - 1:
            y = (y * y) % n
            t <<= 1

        if y != n - 1 and t & 1 == 0:
            return False
        return True

def divisors(N):
    pf = primeFactor(N)
    ret = [1]
    for p in pf:
        ret_prev = ret
        ret = []
        for i in range(pf[p]+1):
            for r in ret_prev:
                ret.append(r * (p ** i))
    return sorted(ret)

def f(b, n):
    re = 0
    while n:
        re += n % b
        n //= b
    return re

N = int(input())
S = int(input())
if N < S:
    print(-1)
elif N == S:
    print(N+1)
else:
    for b in divisors(N-S):
        b += 1
        if f(b, N) == S:
            print(b)
            break
    else:
        print(-1)


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

using namespace std;

#define ll long long
#define pb push_back
#define vi vector<int>
#define bn(n) (n).begin(), (n).end()
#define FOR(n) for(int i = 0; i < (int)n; i++)


void solve() {
    ll n, t;
    cin >> n >> t;
    ll ans = t;
    vector<ll> v;
    for (int i = 0; i < n; i++) {
        ll x;
        cin >> x;
        v.push_back(x);
    }
    for (int i = 1; i < n; i++) {
        ans += min(v[i] - v[i-1], t);
    }
    cout << ans << "\n";
}

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

    int t = 1, i = 1;
    //cin >> t;
    while(t--) {
        //cout << "Case #" << i << ": ";
        solve();
        //i++;
    }
    return 0;
}


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

#define rep(i,n) for(long long int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(long long int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(long long int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define P pair<int,int>
#define Abs(a,b) max(a,b)-min(a,b)
#define YES(condition) if(condition){cout << "YES" << endl;}else{cout << "NO" << endl;}
#define Yes(condition) if(condition){cout << "Yes" << endl;}else{cout << "No" << endl;}
#define Cout(x) cout<<(x)<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl
#define possible(n) cout << ((n) ? "possible" : "impossible"  ) << endl
#define Size(n) (n).size()

typedef long long ll;

using namespace std;

const int INF = 1e9,MOD = 1e9 + 7;
const ll LINF = 1e18;

//long long int kaizyo(long long int hh){
  //  cmp=1;
    //while(hh>1){
      //  cmp=(cmp*hh)%MOD;
        //hh--;
    //}
    //return cmp;
//}
//long long int ruizyo(long long int aa, long long int bb){
  //  if(aa==0){
    //    return 1;
    //}
    //else if(aa%2==0){
      //  long long int tt=ruizyo(aa/2,bb);
        //return (tt*tt)%MOD;
    //}
    //else{
      //  return (ruizyo(aa-1,bb)*bb)%MOD;
    //}
//}フェルマ－のア


//while(x!=0){
            //sum+=x%10;
           // x/=10;
        //}
        //各桁の和

//pair<int,int> p[100000];
//P r[100000];
//cin >> tmp;
//p[i]=make_pair(tmp,i);
//cout << p[i].second+1 << endl;//ペアの右側つまりiを出力

//s.find(w[i])==string::npos
//findの使い方

//for(int i=0;i<n;i++){
   // b[i]=x%2;
    //x/=2;
  //}二進数

//bool f[100001];//1000000以下の素数を調べよう！
//rrep(i,2,100001){
  //      f[i]=false;
    //}
//rrep(i,2,100001){
  //      if(!f[i]){
    //        for(int j=i+i;j<=100000;j+=i){
      //          f[j]=true;
        //    }
        //}
    //}
    //for(int i=3;i<=100000;i+=2){
      //  if(!f[i]){
        //    c[i]++;
      //  }
   // }

//visited=vector<vector<bool>>(10,vector<bool>(10,false));アを全部falseに


long long int n,cnt=0,ans=0,a,b,c,d,cmp,cmpp,m,h,w,x,y,sum=0,pos;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl=true;

//-------------------------↓↓↓↓↓↓----------------------------

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

       cin >> n;
       for(int i=1;i*i<=n;i++){
           ans=i*i;
       }
       Cout(ans);
       
return 0;
}


Measured memory_bytes: 256
n = int(input())
S = []
cnt = [100]*26
for i in range(n):
    S.append(input())
base = "abcdefghijklmnopqrstuvwxyz"
for i in range(26):
    for j in range(n):
        x = S[j].count(base[i])
        cnt[i] = min(x,cnt[i])
res = ""
for i in range(26):
    res += base[i]*cnt[i]
print(res)

Measured memory_bytes: 38768
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <queue>
using namespace std;

int A, B;

int main() {
    cin >> A >> B;
    cout << 100 << " " << 100 << endl;
    int cnt = 0;
    for (int i = 0; i < 49; i++) {
        for (int j = 0; j < 100; j++) {
            if (cnt < B - 1 && i % 2 && j % 2) {
                cout << '#';
                cnt++;
            } else {
                cout << '.';
            }
        }
        cout << endl;
    }
    for (int j = 0; j < 100; j++) {
        cout << '.';
    }
    cout << endl;
    for (int j = 0; j < 100; j++) {
        cout << '#';
    }
    cout << endl;
    cnt = 0;
    for (int i = 0; i < 49; i++) {
        for (int j = 0; j < 100; j++) {
            if (cnt < A - 1 && i % 2 && j % 2) {
                cout << '.';
                cnt++;
            } else {
                cout << '#';
            }
        }
        cout << endl;
    }
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
  int A,B;
  scanf("%d %d",&A,&B);
  if (A+1<B)
  {
    printf("%d",2*B-1);
  }
  else if (B+1<A)
    printf("%d",2*A-1);
  else
  	printf("%d",A+B);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
constexpr int MOD = 1000000007;
constexpr int INF = numeric_limits<int>::max() / 2;
typedef pair<int,int> P;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const double PI = acos(-1.0);
// cout << fixed << setprecision(14);
 
signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);

    int N, M, Q;
    cin >> N >> M >> Q;
    int dp[N+1][N+1]{};
    rep(i,M){
        int a, b;
        cin >> a >> b;
        dp[a][b]++;
    }
    int sum[N+1][N+1]{};
    rep(i,N){
        rep(j,N){
            sum[i+1][j+1] = dp[i+1][j+1] + sum[i+1][j] + sum[i][j+1] - sum[i][j]; 
        }
    }
    rep(i,Q){
        int a, b;
        cin >> a >> b;
        cout << sum[b][b] - (sum[a-1][b] + sum[b][a-1] - sum[a-1][a-1]) << endl;
    }
}

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

//typedef
//------------------------------------------
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int MOD = 1000000007;

//MOD
//--------------------------------------------
#define MUL(a,b) (((a) % MOD) * ((b) % MOD)) % MOD

// grid
//--------------------------------------------
VL dx = {0, 1, 0, -1};
VL dy = {1, 0, -1, 0};
VL dx2 = {-1, 0, 1, -1, 1, -1, 0, 1};
VL dy2 = {-1, -1, -1, 0, 0, 1, 1, 1};

//debug
//--------------------------------------------
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//main code

int main(int argc, char const* argv[])
{
	int n;
	string s;
	cin >> n >> s;
	map<char,int> mp;
	for (int i = 0; i < n; i++) {
		mp[s[i]]++;
	}
	LL ans = 1;
	for (auto&& var : mp) {
		ans *= (var.second > 0 ? 2 + var.second - 1 : 1);
		ans %= MOD;
	}
	if (ans == 0) {
		ans = MOD - 1;
	}
	else {
		ans -= 1;
	}
	cout <<ans << endl;
	return 0;
}


Measured memory_bytes: 512
def divisor(n):
    ass = []
    for i in range(1, int(n**0.5)+1):
        if n%i == 0:
            ass.append(i)
            if i**2 == n:
                continue
            ass.append(n//i)
    return ass  # sortされていない


n, m = map(int, input().split())
m_div = divisor(m)
m_div.sort()
ans = 0
for i in m_div:
    if i * n <= m and (m - i*n) % i == 0:
        ans = max(ans, i)
print(ans)

Measured memory_bytes: 64440