akhauriyash/Code-Regression huggingface dataset:
import copy
H, W = map(int, input().split())
s = []
wall=[]
maze = [0] * (H * W)
path = dict()
leaf = []

for i in range(H):
  temp = list(input())
  for j, var in enumerate(temp):
    idx = i*W + j
    maze[idx] = var
    if var == ".":
      s.append(idx)

for i in range(H):
  for j in range(W):
    idx = i*W + j
    temp = []
    if j != 0 and maze[idx-1] != "#":
      temp.append(idx - 1)
    if j != W - 1 and maze[idx+1] != "#":
      temp.append(idx + 1)
    if i != 0 and maze[idx-W] != "#":
      temp.append(idx - W)
    if i != H - 1 and maze[idx + W] != "#":
      temp.append(idx + W)
    path[idx] = temp

ans = 0
start = copy.copy(s)

for st in start:
  dp = [float('inf')] * (H * W)
  prev = [-1] * (H*W)
  dp[st] = 0
  s2 = copy.copy(s)
  while len(s2) > 0:
    dpmin = float('inf')
    idx = 0
    for i in s2:
      if dpmin > dp[i]:
        idx = i
        dpmin = dp[i]
    now = s2.pop(s2.index(idx))
    flag = 0
    for i in path[now]:
      if dp[i] > 1 + dp[now]:
        dp[i] = 1 + dp[now]
        prev[i] = now
        flag = 1
    if flag == 0:
      leaf.append(now)
  dp = [i for i in dp if i != float('inf')]
  if ans < max(dp):
    ans = max(dp)
print(ans)

Measured memory_bytes: 75480
#include<bits/stdc++.h>
#include<atcoder/all>
using namespace std;
using namespace atcoder;
typedef long long ll;
typedef long double ld;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, m, n) for (int i = m; i < n; ++i)
#define FORR(i, m, n) for (int i = m; i >= n; --i)
#define ALL(v) (v).begin(),(v).end()
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; }
const ll INF=1LL<<60;
const int inf=(1<<30)-1;
const int mod=1e9+7;
int dx[8]={1,0,-1,0,-1,-1,1,1};
int dy[8]={0,1,0,-1,-1,1,-1,1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,q;cin >> n >> q;
    dsu uf(n);
    REP(i,q){
        int t,u,v;cin >> t >> u >> v;
        if(t==0){
            uf.merge(u,v);
        }
        else{
            cout << (uf.same(u,v)?1:0) << endl;
        }
    }
}

Measured memory_bytes: 3948
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<pint> vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=n-1;i>=(0);i--)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define all(v) (v).begin(),(v).end()
#define eall(v) unique(all(v), v.end())
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll INFF = 1e18;


int X, Y, Z;
ll A[100010], B[100010], C[100010];

signed main(void) {
	cin >> X >> Y >> Z;
	rep(i, X + Y + Z) cin >> A[i] >> B[i] >> C[i];

	vector<pair<ll, int>> v;
	rep(i, X + Y + Z) {
		v.pb(make_pair(A[i] - B[i], i));
	}
	sort(all(v)); reverse(all(v));


	ll sumF = 0;
	priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int> >> pA;
	vector<ll> memoF;
	rep(i, X) {
		int idx = v[i].se;
		sumF += A[idx];
		pA.push(mp(A[idx] - C[idx], idx));
	}
	memoF.pb(sumF);
	reps(i, X, X + Z) {
		int idx = v[i].se;
		pA.push(mp(A[idx] - C[idx], idx));
		int minidx = pA.top().se; pA.pop();
		sumF += A[idx] - A[minidx] + C[minidx];
		memoF.pb(sumF);
	}

	ll sumB = 0;
	priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int> >> pB;
	vector<ll> memoB;
	for (int i = X + Y + Z - 1; i > X + Z - 1; --i) {
		int idx = v[i].se;
		sumB += B[idx];
		pB.push(mp(B[idx] - C[idx], idx));
	}
	memoB.pb(sumB);
	for (int i = X + Z - 1; i >= X; --i) {
		int idx = v[i].se;
		pB.push(mp(B[idx] - C[idx], idx));
		int minidx = pB.top().se; pB.pop();
		sumB += B[idx] - B[minidx] + C[minidx];
		memoB.pb(sumB);
	}
	reverse(all(memoB));

	ll ans = 0;
	rep(i, memoF.size()) {
		chmax(ans, memoF[i] + memoB[i]);
	}
	printf("%lld\n", ans);
	return 0;
}

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


int main()
{
    int n;cin>>n;
    vector<int> a(n);
    for(int i = 0; i<n; i++)cin>> a[i];
    sort(a.begin(), a.end(), greater<int>());
    int aa = 0,b = 0;
    for(int i = 0; i<n; i++){
        if(i%2==0) aa += a[i];
        else b += a[i];
    }
    cout << aa - b << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <string>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>
#include <set>
#include <functional>
#include <iostream>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n,k;
int cnt[27];

int main(void){
	scanf("%d%d",&n,&k);
	for(int i=0;i<n;i++){
		string str;
		cin >> str;
		cnt[str[0]-'A']++;
	}
	int res=0;
	while(1){
		sort(cnt,cnt+26,greater<int>());
		bool flag=true;
		for(int i=0;i<k;i++){
			if(cnt[i]==0)flag=false;
			cnt[i]--;
		}
		if(!flag)break;
		res++;
	}
	printf("%d\n",res);
	return 0;
}

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

using namespace std;

int n, a[10000005];
set <int> st;

int main () {
	cin >> n;
	for(int i = 0; i < n; i++) {
		cin >> a[i];
		st.insert(a[i]);
	}
	if(st.size() == n) {
		cout << "YES";
	}
	else {
		cout << "NO";
	}
	return 0;
}

Measured memory_bytes: 10368
import java.util.Scanner;
class Main{
    public static void main(String[] av){
	Scanner sc=new Scanner(System.in);
	int S=sc.nextInt();
	int h=0,m=0,s=0;
	h=S/(60*60);
	m=(S-h*60*60)/60;
	s=S-h*60*60-m*60;
	System.out.println(h+":"+m+":"+s);
    }
}



Measured memory_bytes: 26236
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

        int cardCount = Integer.parseInt(reader.readLine());
        String[][] card = new String[4][13];
        String[] CardPic = { "S","H","C","D"};

        for ( int xx = 0 ; xx <= 3 ; xx++ ) {
            for ( int yy = 0 ; yy <= 12 ; yy++ ) {
                card[xx][yy] = CardPic[xx];
            }
        }
        
        for (int i = 0; i < cardCount; i++) {
            String line = reader.readLine();
            String column[] = line.split(" ");
            if (column[0].equals("S")) {
                card[0][Integer.parseInt(column[1])-1] = null;
            }
            if (column[0].equals("H")) {
                card[1][Integer.parseInt(column[1])-1] = null;
            }
            if (column[0].equals("C")) {
                card[2][Integer.parseInt(column[1])-1] = null;
            }
            if (column[0].equals("D")) {
                card[3][Integer.parseInt(column[1])-1] = null;
            }
        }
        
        for (int x = 0; x <= 3; x++) {
            for (int y = 0; y <= 12; y++) {
                if (card[x][y] != null) {
                    System.out.println(card[x][y] + " " + (y+1));
                }
            }
        }
    }
}

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

int main(){

    int N;
    cin >> N;
    vector<int> a(N);
    for(int i = 0; i < N; i++) cin >> a[i];

    long long sum = 0;
    for(int i = 0; i < N; i++){
        sum += a[i] - 1;
    }

    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 256
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define dbg(x) cout << #x << '=' << x << '\n';
#define ll long long
#define pi pair<int,int>
#define pl pair<ll,ll>
#define pd pair<double,double>
#define ld long double
#define pld pair<ld,ld>
#define lg length()
#define sz size()
#define pb push_back
#define MAXN 100005
#define INF 1000000005
#define LINF 1000000000000000005
#define x1 xdddddddddddddddddd
#define y1 ydddddddddddddddddd
#define int ll

int n,l,r,p,q,t;

string ans;

int32_t main(){
    ios_base :: sync_with_stdio(0); cin.tie(); cout.tie();
    cin >> n;
    cout << 0 << '\n'; cout.flush();
    cin >> ans;
    if(ans=="Vacant") return 0;
    else if(ans=="Male") p=0,q=1;
    else p=1,q=0;
    l=0,r=n-1;
    while(1){
        int mid=(l+r)/2;
        cout << mid << '\n'; cout.flush();
        cin >> ans;
        if(ans=="Vacant") return 0;
        else if(ans=="Male") t=0;
        else t=1;
        if((mid-l)%2){
            if(p==t) r=mid-1;
            else l=mid+1;
        }
        else{
            if(p==t) l=mid;
            else r=mid;
        }
    }
}


Measured memory_bytes: 852
#define _USE_MATH_DEFINES
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <numeric>
#include <iomanip>
#include <cmath>
using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

//for簡易表記(引数ミス防止)
#define FOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define REP(LoopVariable,numberOFend) for(int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)

struct Point{
    double x;
    double y;
};

void koch(int n,Point s,Point e){
    if(n==0){
        cout << std::setprecision(8) << e.x<<" "<<e.y << endl;
    }else{
        Point tmp_p1,tmp_p2,tmp_p3;
        tmp_p1.x = (s.x * 2.0) / 3.0 + (e.x) / 3.0;
        tmp_p1.y = (s.y * 2.0) / 3.0 + (e.y) / 3.0;
        koch(n - 1, s, tmp_p1);
        tmp_p2.x = (s.x) / 3.0 + (e.x*2.0) / 3.0;
        tmp_p2.y = (s.y) / 3.0 + (e.y*2.0) / 3.0;
        tmp_p3.x = tmp_p1.x + (((tmp_p2.x - tmp_p1.x) * cos(M_PI/3.0)) - ((tmp_p2.y - tmp_p1.y)*sin(M_PI/3.0)));
        tmp_p3.y = tmp_p1.y + (((tmp_p2.x - tmp_p1.x) * sin(M_PI/3.0)) + ((tmp_p2.y - tmp_p1.y)*cos(M_PI/3.0)));

        koch(n - 1, tmp_p1, tmp_p3);
        koch(n - 1, tmp_p3, tmp_p2);
        koch(n - 1, tmp_p2, e);
    }
}

int main(){

    int n;
    cin>>n;
    std::cout << std::fixed<< std::setprecision(8)<<0.0<<" "<<0.0<<endl;
    Point start = {0, 0},end={100,0};
    koch(n, start, end);
    return 0;
}


Measured memory_bytes: 3272
#include<cstdio>

int main(void){
	int a, b, N, i, s, f, isWrong=0;
	scanf("%d %d %d", &a, &b, &N);
	for(i=0; i<N; ++i){
		scanf("%d %d", &s, &f);
		if(((a>=s)&&(a<f))||((b>s)&&(b<=f))||((a<s)&&(b>f))){isWrong=1;}
	}
	printf("%d\n", isWrong);
	
	return(0);
}


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

int solve(int N, vector<int> values)
{
    auto indices = vector<int>(N);
    iota(begin(indices), end(indices), 0);
    sort(begin(indices), end(indices), [&](int i, int j) { return values[i] < values[j]; });

    auto odd_moves = 0;
    for (auto i = 0; i < N; i++)
        if (i%2 != indices[i]%2) odd_moves++;
    return odd_moves / 2;
}

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

    auto values = vector<int>(N);
    for (auto& x : values) cin >> x;

    cout << solve(N, values) << endl;
}


Measured memory_bytes: 1408
n,p=map(int,input().split())
pf={}
for i in range(2,int(p**0.5)+1):
    while p%i==0:
        pf[i]=pf.get(i,0)+1
        p//=i
if p>1:pf[p]=1
v=pf.items()
ans=1
for k,kk in v:
    if kk>=n:
        vv=kk//n
        ans*=k**vv
print(ans)

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

int main()
{
    int i,c=0;
    string s1,s2;

    cin>>s1>>s2;

    for(i=0;i<s1.size();i++){
        if(s1[i]!=s2[i]){
            c++;
        }
    }
    cout<<c<<endl;

    return 0;
}


Measured memory_bytes: 3920
#include<iostream>
#include<vector>
#include<string>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= (int)end; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return 0;}
template<typename T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return 0;}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int X, Y;
    cin >> X >> Y;
    rep(i, 0, X + 1) {
        int j = X - i;
        if (i * 2 + j * 4 == Y) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3640
function Main(input) {
  var list = input.split(" ");
  var A = parseInt(list[0], 10);
  var B = parseInt(list[1], 10);
  var ans = 0;
  
  if (A == B) ans = A+B;
  else ans = Math.max(2*A-1,2*B-1);
  
  console.log(ans);
}
 
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 21064
import sys
import numpy as np

ns = lambda: sys.stdin.readline().rstrip()
ni = lambda: int(ns())
nm = lambda: map(int, sys.stdin.readline().split())
nms = lambda: map(str, sys.stdin.readline().split())
nl = lambda: list(nm())

n, w = nm()
lis = [nl() for _ in range(n)]
lis.insert(0, [0, 0])
dp = np.zeros(w + 1, dtype=np.int64)

for i in range(1, n + 1):
    dp[lis[i][0]:] = np.maximum(dp[lis[i][0]:], dp[:-lis[i][0]] + lis[i][1])

print(dp[-1])

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

/*vector<int> p(n);
cin >> p[i]*/

int main(){

    int n, k;
    long long int num=0;
    cin >> n >> k;
    vector<int> h(n);
    for(int i=0; i<n; i++) cin >> h[i];

    sort(h.begin(), h.end());

    for(int i=0; i<n-k; i++){
        num += h[i];
    }


    if(n <= k) cout << 0 << endl;
    else cout << num << endl;

    return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
int main(void){
	int x;
	int y;
	int buf;
	
	
	while(1){
	
	scanf("%d %d",&x,&y);
	
	if(x == 0 && y == 0) break;
	
	if(x > y){
		
		buf = x;
		x = y;
		y = buf;
	}
	
	printf("%d %d\n",x,y);
	
	}
}

Measured memory_bytes: 1028
#include <bits/stdc++.h>
#define ri register
#define int long long
#define E (n+1)
using namespace std; const int N=200010;
inline int read()
{
    int s=0, w=1; ri char ch=getchar();
    while(ch<'0'||ch>'9') { if(ch=='-') w=-1; ch=getchar(); }
    while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+(ch^48), ch=getchar();
    return s*w;
}
signed main()
{
    string s;
    cin>>s;
    if(s[0]==s[1]&&s[1]==s[2] || s[1]==s[2]&&s[2]==s[3]) puts("Yes");
    else puts("No");
    return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

using namespace std;

long long cnt;

struct SSS
{
	string str;
	int val;
	SSS(string s = "", int v = 0) :str(s), val(v){};
};

void print(vector<SSS> &data){
	for (int i = 0; i < data.size(); ++i){
		cout << data[i].str << " " << data[i].val << endl;
	}
}

void print(vector<string> &data){
	for (int i = 0; i < data.size(); ++i) {
		cout << data[i];
		if (i == data.size() - 1) cout << endl;
		else cout << " ";
	}
}

void insS(vector<int> &data){
	for (int i = 0; i < data.size(); ++i){
		int v = data[i];
		int j = i - 1;
		while (j >= 0 && data[j] > v){
			data[j + 1] = data[j];
			j--;
		}
		data[j + 1] = v;
		//print(data);
	}
}

void bubS(vector<string> &data){
	for (int i = 0; i < data.size(); ++i) {
		int j = data.size() - 1;
		for (; j > i; --j){
			if (data[j][1] < data[j - 1][1]) {
				swap(data[j], data[j - 1]);
				cnt++;
			}
		}
	}
	print(data);
}

void selS(vector<string> &data){
	for (int i = 0; i < data.size(); ++i) {
		int idx = i;
		for (int j = i; j < data.size(); ++j) {
			if (data[j][1] < data[idx][1]) idx = j;
		}
		swap(data[idx], data[i]);
		//print(data);
	}
	print(data);
}


int main(){
	int n; cin >> n;
	vector<string> data(n);
	for (int i = 0; i < n; ++i) cin >> data[i];
	vector<string> d1(data), d2(data);
	//insS(data);
	bubS(d1);
	cout << "Stable" << endl;
	selS(d2);

	string res = "Stable";
	for (int i = 0; i < d1.size(); ++i)
	{
		if (d1[i] != d2[i]) res = "Not stable";
	}
	cout << res << endl;

	return 0;
}

Measured memory_bytes: 3208
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int h = 0;
        int m = 0;
        int s = 0;
        h = n/3600;
        n = n%3600;
        m = n/60;
        s = n%60;
        System.out.println(h + ":" + m + ":"+ s);

    }
}


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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define itn int
typedef long long ll;
typedef pair<ll,ll> p;


int main()
{
  int n;
  cin >> n;
  if(n % 2 == 0)cout << n << endl;
  else cout << n * 2 << endl;
}

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

using namespace std;

typedef long long LL;
typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define PB(a) push_back(a)
#define MP(a , b) make_pair((a) , (b))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)))
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

int N;
LL A[200010];

int main(){
	cin >> N;
	repp(i,0,N){
		cin >> A[i];
		A[i] -= i+1;
	}
	sort(A,A+N);
	LL ans = 0;
	repp(i,0,N){
		ans += abs(A[i] - A[N/2]);
	}
	cout << ans << endl;
	return 0;
}


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

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

	rep(i, s.size()) cout << 'x';
	cout << endl; 
}


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

using namespace std;

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

	long long  n;
	cin >> n;
	cout << (n - 1 + 1) * (n - 1) / 2 << endl;

	return 0;
}

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

# Input#
n = list(input())
# n, k = map(int, input().split())
# a = list(map(int, input().split()))
sum = 0
for i in n:
    sum += int(i)

if sum % 9 == 0:
    print("Yes")
else:
    print("No")


# print("{}".format(ans))


Measured memory_bytes: 77496
#include<iostream>
#include<string>
#include<map>
#include<algorithm>
#include<vector>
using namespace std;
int main(){
string S;
  cin >>S;
  int MY=0,YM=0;
  
  if((S[0] == '0' && S[1] != '0') || (S[0] == '1' && S[1] == '0')
     or (S[0] == '1' && S[1] == '1')
     or (S[0] == '1' && S[1] == '2'))MY = 1;

  
  if((S[2] == '0' && S[3] != '0') || (S[2] == '1' && S[3] == '0')
     or (S[2] == '1' && S[3] == '1')
     or (S[2] == '1' && S[3] == '2'))YM = 1;

  if (MY==1 && YM==1) cout << "AMBIGUOUS" <<endl;
  else if (MY==0 && YM==1) cout <<"YYMM"<<endl;
   else if (MY==1 && YM==0) cout <<"MMYY"<<endl; 
    else cout <<"NA"<<endl; 

}




Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define PI 3.1415926
using namespace std;
const int N=1e6+1;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    int k,a,b;cin>>k>>a>>b;
    if(a%k==0||b%k==0||b-b%k>=a)
        cout<<"OK\n";
    else
        cout<<"NG\n";
    return 0;
}


Measured memory_bytes: 3624
#include <iostream>
#include <cstdint>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int, int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define irep(it, stl) for (auto it = stl.begin(); it != stl.end(); it++)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define mes(a) cout << (a) << endl
#define dmes(a, b) cout << (a) << " " << (b) << endl
#define re0 return 0
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define rSort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
int dx[8] = { 1, 0, -1, 0, 1, -1, -1, 1 };
int dy[8] = { 0, 1, 0, -1, 1, 1, -1, -1 };
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; }
struct io { io() { ios::sync_with_stdio(false); cin.tie(0); } };
const int INF = INT_MAX;
const ll LLINF = 1LL << 60;
const ll MOD = 1000000007;
const double EPS = 1e-9;

signed main(void) 
{
    ll n;
    cin >>n;
    vll a(n);
    vll b(n);
    rep(i, n) {
        cin >>a[i];
        b[i] = a[i];
    }
    rSort(b);
    rep(i, n) {
        if (a[i] == b[0]) {
            mes(b[1]);
        } else {
            mes(b[0]);
        }
        
    }
}


Measured memory_bytes: 6428
import sys
read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    S = readline().decode('utf-8').strip()
    T = readline().decode('utf-8').strip()
    L = len(S)
    ans = 0
    for i in range(L):
        if S[i]!=T[i]:
            ans += 1

    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 9532
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    struct Food
    {
        internal string name;
        internal int wt, cap;

        public override string ToString()
        {
            return name;
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            StringBuilder sb = new StringBuilder();

            while (true)
            {
                int n = int.Parse(Console.ReadLine());

                if (n == 0) break;

                Food[] foods = new Food[n];
                Food temp;

                for (int i = 0; i < n; i++)
                {
                    string[] input = Console.ReadLine().Split(' ');
                    temp.name = input[0];
                    temp.wt = int.Parse(input[1]);
                    temp.cap = int.Parse(input[2]);
                    foods[i] = temp;
                }

                var sumW = foods.Sum(f => f.wt);
                bool[] used = new bool[n];

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

                    for (int j = 0; j < n; j++)
                    {
                        if (used[j] || foods[j].cap < sumW - foods[j].wt) continue;

                        if (foods[j].wt > maxWt)
                        {
                            maxWt = foods[j].wt;
                            maxIdx = j;
                        }
                    }
                    sb.AppendLine(foods[maxIdx].ToString());
                    sumW -= foods[maxIdx].wt;
                    used[maxIdx] = true;
                }
            }
            Console.Write(sb);
        }
    }
}

Measured memory_bytes: 9152
MOD = 10**9 + 7

N,M,K = map(int,input().split())
NM = N*M

U = 2*10**5
fact = [1] * (U+1)
fact_inv = [1] * (U+1)

for i in range(1,U+1):
  fact[i] = (fact[i-1]*i)%MOD

def comb(n,k):
  x = fact[n]
  x *= pow(fact[n-k],MOD-2,MOD)
  x %= MOD
  x *= pow(fact[k],MOD-2,MOD)
  x %= MOD
  return x

def F(N):
  # sum_x,y abs(x-y)
  x = N*(N+1)//2*N
  y = N*(N+1)*(2*N+1)//6
  return (x-y)%MOD

MM = M*M%MOD
NN = N*N%MOD
answer = MM*F(N)%MOD + NN*F(M)%MOD
answer %= MOD
answer *= comb(N*M-2,K-2)
answer %= MOD
print(answer)

Measured memory_bytes: 12532
// first second push_back unordered return continue break vector visited check flag bool while iterator begin end lower_bound upper_bound temp true false ll_MAX ll_MIN insert erase clear pop push compare ll64_MAX ll64_MIN  reverse replace stringstream string::npos length substr front priority_queue

#ifndef ONLINE_JUDGE
#include "debug.h"
#else
#include <bits/stdc++.h>
using namespace std;
#define debug(...) 42
#endif

#define endl '\n'
#define ll long long
#define rint register int
#define minpq priority_queue <int, vector<int>, greater<int> >
#define maxpq  priority_queue <int>

#define re register
#define pb(x) push_back(x);
#define ce(x) cout << x << '\n';

using db = long double;
using pll = pair < ll, ll >;
#define scan(a, n) 		for(int i = 0; i < n; i++)cin >> a[i];

#define rep(i,x,n,inc) for(i=x ; i<n ; i+=inc)
#define repr(i,x,n,inc) for( i=x ; i>n ; i+=inc)
#define all(a)      (a).begin(),(a).end()
#define unique_sort(x) sort(all(x)), x.resize(distance(x.begin(), unique(all(x))))

#define mp(a,b) make_pair(a,b)
#define ff first
#define ss second
// #define hell 1000000007
#define infl LLONG_MAX

const ll hell = -(LLONG_MAX);
const ll sz = 5009;

// ll dp[sz][sz][sz];
ll p[sz], c[sz], cy[sz], vis[sz], valC[sz];
// map<ll, vector<ll> > path;

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

	ll t, i, x, j, y, 	z, k, n;
	z = hell;
	cin >> n >> k;

	rep(i, 0, n, 1) {
		cin >> p[i];
		p[i]--;
		// cerr << p[i] << " ";
	}
	// cerr << "\n";

	rep(i, 0, n, 1) {
		cin >> c[i];
	}

	rep(i, 0, n, 1) {
		if (!vis[i]) {
			std::vector<ll> v;

			j = i;	t = 0;
			while (!vis[j]) {
				vis[j] = 1;
				v.push_back(j);
				t += c[j];
				j = p[j];
			}

			for (auto zx : v) {
				cy[zx] = v.size();
				valC[zx] = t;
				// path[zx] = v;
			}
		}

		// debug(cy[i], path[i]);
	}


	rep(i, 0, n, 1)	vis[i] = 0;


	rep(i, 0, n, 1) {
		ll reps = max(0LL, (k - cy[i]) / cy[i]);
		t = reps * valC[i];
		if (t < 0)	t = 0;
		ll left = k % cy[i];
		if (k >= cy[i])	left += cy[i];

		j = p[i];
		// debug(i, j, t, left);
		while (left--) {
			t += c[j];
			// debug(t, j);

			z = max(z, t);
			j = p[j];
		}

		// z = max(z, t);
	}


	ce(z);
	debug(z);

}



Measured memory_bytes: 3960
#include <bits/stdc++.h>
using namespace std;
const int N=100010,Mod=998244353;
const double pi=acos(-1.0);
typedef long long int ll;
typedef pair<int,int> pii;
int n,a[55];
int main()
{
  int temp[55],flag=0;
  cin>>n;
  for(int i=1;i<=n;i++) cin>>a[i];
  for(int i=2;i<=n;i++) if(a[i]<a[i-1]) {flag=1;break;}
  if(flag)
  {
    for(int i=1;i<n;i++)
    {
      for(int j=i+1;j<=n;j++)
      {
        for(int k=1;k<=n;k++) temp[k]=a[k];
        swap(temp[i],temp[j]);
        for(int k=2;k<=n;k++) if(temp[k]<temp[k-1]) goto jump;
        cout<<"YES\n";
        return 0;
        jump:;
      }
    }
    cout<<"NO\n";
  }
  else cout<<"YES\n";
  return 0;
}


Measured memory_bytes: 256
/**
 *    author:  otera    
**/
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

//#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cerr << #x << " = " << (x) << endl;
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; }

void solve() {
	string s; cin >> s;
    int q; cin >> q;
    vector<int> t(q, 0), f(q, -1);
    vector<char> c(q, '?');
    rep(i, q) {
        cin >> t[i];
        if(t[i] == 2) {
            cin >> f[i];
            cin >> c[i];
        } 
    }
    reverse(all(c));
    reverse(all(t));
    reverse(all(f));
    string left = "", right = "";
    int cnt = 0;
    rep(i, q) {
        if(t[i] == 1) {
            ++cnt;
        } else {
            if(f[i] == 1) {
                if(cnt % 2 == 0) {
                    left = left + c[i];
                } else {
                    right = c[i] + right;
                }
            } else {
                if(cnt % 2 == 1) {
                    left = left + c[i];
                } else {
                    right = c[i] + right;
                }
            }
        }
    }
    if(cnt % 2 == 1) {
        reverse(all(s));
    }
    string ans = left + s + right;
    cout << ans << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//int t; cin >> t; rep(i, t)solve();
	solve();
    return 0;
}

Measured memory_bytes: 3400
#include <iostream>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<vector>
using namespace std;

long long cnt;
int l;
int A[10000000];
int n;
vector<int> G;

void insertionSort(int* A,int n,int g){
    for(int i=g;i<n;i++){
        int v=A[i];
        int j=i-g;
        while(j>=0&&A[j]>v){
            A[j+g]=A[j];
            j-=g;
            cnt++;
        }
        A[j+g]=v;
    }
}


void shellSort(int A[],int n){
    for(int h=1;;){
        if(h>n)break;
        G.push_back(h);
        h=3*h+1;
    }
    for(int i=G.size()-1;i>=0;i--){
        insertionSort(A,n,G[i]);
    }
}



int main(){
    int n;
    cin>>n;
    for(int i=0;i<n;i++)scanf("%d",&A[i]);
    cnt=0;
    
    shellSort(A,n);
    
    cout<<G.size()<<endl;
    
    for(int i=G.size()-1;i>=0;i--){
        printf("%d",G[i]);
        if(i)printf(" ");
    }
    
    
    printf("\n");
    printf("%d\n",cnt);
    for(int i=0;i<n;i++)printf("%d\n",A[i]);
    
    
    
    
    
    return 0;
}



Measured memory_bytes: 7164
import java.util.*;import java.io.*;import java.math.*;

public class Main
{

    public static void process()throws IOException
    {
        int n=ni(),arr[]=new int[n+1];
        for(int i=1;i<=n;i++) arr[i]=ni();
        long res=Long.MAX_VALUE;

        for(int i=1;i<=100;i++){
            long sum=0l;
            for(int j=1;j<=n;j++){
                long diff=Math.abs(i-arr[j]);
                sum+=diff*diff;
            }
            res=Math.min(res, sum);
        }
        pn(res);
    }


    static AnotherReader sc;
    static PrintWriter out;
    public static void main(String[]args)throws IOException
    {
        out = new PrintWriter(System.out);
        sc=new AnotherReader();
        boolean oj = true;

       // oj = System.getProperty("ONLINE_JUDGE") != null;
        if(!oj) sc=new AnotherReader(100);

        long s = System.currentTimeMillis();
        int t=1;
        while(t-->0)
            process();
        out.flush();
        if(!oj)
            System.out.println(System.currentTimeMillis()-s+"ms");
        System.out.close();  
    }

    static void pn(Object o){out.println(o);}
    static void p(Object o){out.print(o);}
    static void pni(Object o){out.println(o);System.out.flush();}
    static int ni()throws IOException{return sc.nextInt();}
    static long nl()throws IOException{return sc.nextLong();}
    static double nd()throws IOException{return sc.nextDouble();}
    static String nln()throws IOException{return sc.nextLine();}
    static long gcd(long a, long b)throws IOException{return (b==0)?a:gcd(b,a%b);}
    static int gcd(int a, int b)throws IOException{return (b==0)?a:gcd(b,a%b);}
    static int bit(long n)throws IOException{return (n==0)?0:(1+bit(n&(n-1)));}
    static boolean multipleTC=false;



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

    static class AnotherReader{BufferedReader br; StringTokenizer st;
    AnotherReader()throws FileNotFoundException{
    br=new BufferedReader(new InputStreamReader(System.in));}
    AnotherReader(int a)throws FileNotFoundException{
    br = new BufferedReader(new FileReader("input.txt"));}
    String next()throws IOException{
    while (st == null || !st.hasMoreElements()) {try{
    st = new StringTokenizer(br.readLine());}
    catch (IOException  e){ e.printStackTrace(); }}
    return st.nextToken(); } int nextInt() throws IOException{
    return Integer.parseInt(next());}
    long nextLong() throws IOException
    {return Long.parseLong(next());}
    double nextDouble()throws IOException { return Double.parseDouble(next()); }
    String nextLine() throws IOException{ String str = ""; try{
    str = br.readLine();} catch (IOException e){
    e.printStackTrace();} return str;}}
    
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
}
    
    
    

Measured memory_bytes: 21332
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define MOD 1000000007
const int INF = 1LL<<30;


int main(){
    int n,k;
    string s;
    cin>>n>>k>>s;

    int ans=0;
    rep(i,n-1){
        if(s[i]==s[i+1]) ans++;
    }

    ans=min(n-1,ans+2*k);

    cout<<ans<<endl;
}

Measured memory_bytes: 3748
#include "bits/stdc++.h"
#define rep(i,N) for (int (i) = 0; (i) < (N); (i)++)

int main() {

	std::cin.tie(nullptr); std::ios::sync_with_stdio(false);
	
	int N, A, B; std::cin >> N >> A >> B;
	int ans = 0;

	for (int i = 1; i <= N; i++) {
		std::string si = std::to_string(i);
		int digits_num = 0;
		for (const auto& v : si) {
			digits_num += int(v) - int('0');
		}
		if (A <= digits_num && digits_num <= B)ans += i;
	}

	std::cout << ans;

	return 0;
}

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

const int N = 100010;

int n, m;
int cnt[N];

int main(){
	scanf("%d%d", &n, &m);
	for (int i = 0, u, v; i < m; ++ i){
		scanf("%d%d", &u, &v);
		++ cnt[u];
		++ cnt[v];
	}
	for (int i = 1; i <= n; ++ i){
		if (cnt[i] & 1){
			return printf("NO\n"), 0;
		}
	}
	return printf("YES\n"), 0;
}

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

#define fio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define per(i,n) for (int i=(int)(n)-1;i>=0;i--)
#define For(i,n) for (int i=1;i<=(int)(n);i++)
#define rep(i,n) for (int i=0;i<(int)(n);i++)
#define all(x) (x).begin(),(x).end()
#define Max(a,b,c) max(a,max(b,c))
#define Min(a,b,c) min(a,min(b,c))
#define pii pair<int,int>
#define vi vector <int>
#define lb lower_bound
#define ub upper_bound
#define ll long long
#define pb push_back
#define re return
#define se second
#define fi first
const int INF=0x7fffffff;
const int MAXN=+3;

int f[3003][3003],ls,lt;
string s,t,ans;

int main(){
	cin>>s>>t;
	ls=s.size();
	lt=t.size();
	s="@"+s;
	t="@"+t;
	For(i,ls){
		For(j,lt){
			if (f[i][j-1]>f[i-1][j]){
				f[i][j]=f[i][j-1];
			}else{
				f[i][j]=f[i-1][j];
			}
			if (s[i]==t[j]){
				f[i][j]=f[i-1][j-1]+1;
			}
//			cout<<f[i][j]<<" ";
		}
//		cout<<endl;
	}
//	cout<<f[ls][lt]<<endl;
	int x=ls,y=lt;
	while (x+y){
		if (x && f[x][y]==f[x-1][y]){
			x--;
		}else if (y && f[x][y]==f[x][y-1]){
			y--;
		}else{
			ans=s[x]+ans;
			x--;y--;
		}
	}
	cout<<ans<<endl;
	re 0;
}

Measured memory_bytes: 35456
n = int(input())
a = list(map(int,input().split()))
ssum = [0]*(n+1)+[2**21-1]
sxor = [0]*(n+1)+[2**21-1]
for i in range(n):
  ssum[i+1] = a[i] + ssum[i]
  sxor[i+1] = a[i] ^ sxor[i]
def f(i,j):
  return ssum[j]-ssum[i-1]
def g(i,j):
  return sxor[j]^sxor[i-1]
cnt = [0]*(n+1)
r = 1
for l in range(1,n):
  while f(l,r) == g(l,r):
    if r == n+1:
      break
    r += 1
  cnt[l] = r-1
cnt[n] = n
ans = 0
for i in range(1,n+1):
  ans += cnt[i] - i + 1
print(ans)

Measured memory_bytes: 36248
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(0);
using namespace std;

int main()
{
   int t;t=1;
   FAST
   while(t--)
   {
       int n;cin>>n;
       unordered_set<string> sset;
       for(int i=0;i<n;i++)
       {
           string s;cin>>s;
           sset.insert(s);
       }
       cout<<sset.size()<<"\n";
   }
}

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

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

#define p_ary(ary,a,b,i) do { cout << "["; for (int (i) = (a);(i) < (b);++(i)) cout << ary[(i)] << ((b)-1 == (i) ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

int const MAX_N = 100000;
vector<ll> prime;
vector<bool> is_prime(MAX_N,true);
void Eratosthenes() {
    is_prime[0] = is_prime[1] = false;
    for (ll i = 2;i*i < MAX_N;++i) if (is_prime[i]) for (ll j = 2*i;j < MAX_N;j += i) is_prime[j] = false;
    for (ll i = 0;i < MAX_N;++i) if (is_prime[i]) prime.push_back(i);
}

vector<P> prime_factorization(ll a) {
    vector<P> prime_factor;
    if (is_prime[0]) Eratosthenes();
    for (ll& i : prime) {
        if (i*i > a) break;
        if (a%i == 0) {
            P p = P(i,0);
            while (a%i == 0) {
                a /= i;
                p.second++;
            }
            prime_factor.push_back(p);
        }
    }
    if (a != 1) prime_factor.push_back(P(a,1));
    return prime_factor;
}

void rec(vector<ll>& div,vector<P>& fact,int i,ll d) {
    if (i == fact.size()) {
        div.push_back(d);
        return;
    }
    for (int j = 0;j <= fact[i].second;++j) {
        rec(div,fact,i+1,d);
        d *= fact[i].first;
    }
}

int main() {
    int n;
    ll k,sum = 0;
    cin >> n >> k;
    vector<int> a(n);
    for (int i = 0;i < n;++i) {
        scanf("%d",&a[i]);
        sum += a[i];
    }
    vector<P> b = prime_factorization(sum);
    vector<ll> div;
    rec(div,b,0,1);
    sort(div.begin(),div.end());
    reverse(div.begin(),div.end());
    for (ll d : div) {
        vector<ll> x,y;
        for (int i = 0;i < n;++i) {
            ll c = a[i]/d*d;
            if (a[i] == c) continue;
            x.push_back(a[i]-c);
            y.push_back(c+d-a[i]);
        }
        int m = x.size();
        x.push_back(0);
        y.push_back(0);
        sort(x.begin(),x.end());
        sort(y.begin(),y.end());
        for (int i = 0;i < m;++i) {
            x[i+1] += x[i];
            y[i+1] += y[i];
        }
        ll cnt = 1e9;
        for (int i = 0;i < m+1;++i) if (x[i] == y[m-i]) cnt = min(cnt,x[i]);
        if (cnt <= k) {
            cout << d << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 640
n,m = gets.split(' ').map(&:to_i)
num_list = gets.split(' ').map(&:to_i).sort
change_datas = []
(0...m).each do |i|
  change_datas << gets.split(' ').map(&:to_i)
end
change_datas.sort_by!{|data| data[1]}.reverse!
change_list = []
change_datas.each do |data|
  change_num = [n - change_list.length, data[0]].min
  (0...change_num).each{ |j| change_list << data[1]}
  break if change_list.length >= n
end
(0...n - change_list.length).each{ |j| change_list << 0} if change_list.length < n
sum = 0
(0...n).each do |i|
  sum += [change_list[i], num_list[i]].max
end
puts sum

Measured memory_bytes: 20636
N, K = map(int, input().split())

input_data = []
for x in range(N):
    a, b = map(int, input().split())
    input_data.append([a,b])

input_data.sort()
count = 0
for i in range(N):
    count += input_data[i][1]
    if count >= K:
        print(input_data[i][0])
        break

Measured memory_bytes: 20104
#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>
#include <algorithm>

using namespace std;


int main()
{
    vector<pair<int,int>> v;
    int n;
    cin >> n;

    long long x,y;
    for(int i = 0; i < n; ++i)
    {
        cin >> x >> y;
        if(x != 0 || y != 0)
            v.emplace_back(x,y);   
    }
    sort(v.begin(),v.end(), [&] (auto &p, auto &q) {
        return atan2(p.second,p.first) < atan2(q.second,q.first);
    });

    n = v.size();
    v.insert(v.end(),v.begin(),v.end());
    long long ans = 0;
    for(int i =0; i < n; ++i)
    {
        x = 0; y = 0;
        for(int j = i; j < n + i; ++j)
        {
            x+=v[j].first; y+=v[j].second;
            ans = max(ans,x*x + y*y);
        }
    }
    cout << setprecision(16) << sqrt(ans) << '\n';
    return 0;
}

Measured memory_bytes: 384
#include <cmath>
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<set>
#include<bitset>
#include<iomanip>
#include<stack>
#include<set>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll inf = 1000000007;
ll n, m;
int p[100005];
class union_find {
	public:
	vector<int>par;
	vector<int>size;

	union_find(int n) : par(n), size(n, 1) {
		for (int i = 0; i < n; i++) {
			par[i] = i;//最初の親は自分自身
		}
	}
	void init(int n) {
		par.resize(n);
		size.assign(n, 1);
		for (int i = 0; i < n; i++) {
			par[i] = i;//最初の親は自分自身
		}
	}
	//木の根を求める
	int root(int x) {
		if (par[x] == x) {
			return x;
		}
		else {
			return par[x] = root(par[x]);
		}
	}
	//xとyが同じ集合に属すか否か
	bool same(int x, int y) {
		return(root(x) == root(y));
	}
	//xとyの属する集合を併合
	bool unite(int x, int y) {
		x = root(x);
		y = root(y);
		if (x == y)return false;//根が同じならもう併合済み
		//併合するときは"小さい方"を"大きい方"に併合させる
		if (size[x] < size[y]) {
			swap(x, y);
		}
		size[x] += size[y];
		par[y] = x;
		return true;
	}

	int getSize(int x) {
		return size[root(x)];
	}
};

//union_find tree;
//tree.init(); //これで初期化
//tree.unite(a,b) //aとbのグループを併合
//tree.same(a,b) //aとbが同じグループか(trueかfalse)
int main(void) {
	cin >> n >> m;
	union_find tree(n);
	
	for (int i = 0; i < n; i++) {
		cin >> p[i];
	}
	int a, b;
	for (int i = 0; i < m; i++) {
		cin >> a >> b;
		a--; b--;
		if (!tree.same(a, b)) {
			tree.unite(a, b);
		}
	}
	ll count = 0;
	for (int i = 0; i < n; i++) {
		if (tree.same(p[i]-1, i)) {
			count++;
		}
	}
	cout << count << endl;
	return 0;
}

Measured memory_bytes: 4588
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for(int i=0; i<(n); ++i)
#define REP(i, d, n) for(int i=(d); i<(n); ++i)
#define all(v) v.begin(), v.end()
using P = pair<int, int>;

vector<vector<P>> graph;
vector<int> cost;
vector<bool> visit;

bool dfs(int v){
    bool ret = true;

    visit[v] = true;
    for (auto p : graph[v]) {
        int u = p.first;
        int c = p.second;

        if(cost[u] == 1e18){
            cost[u] = cost[v] + c;
        }
        // 違っていたら, No
        if(cost[u] != cost[v] + c){
            return false;
        }
        if(visit[u]){
            continue;
        }
        ret &= dfs(u);
    }
    return ret;
}

signed main() {

    int n, m;
    cin >> n >> m;
    graph.resize(n);
    visit.resize(n, false);
    cost.resize(n, 1e18);
    // 重み付きグラフ
    rep(i, m) {
        int l, r, d;
        cin >> l >> r >> d;
        --l, --r;
        graph[l].emplace_back(r, d);
        graph[r].emplace_back(l, -d);
    }

    int ok = true;
    rep(i, n) {
        if(visit[i]){
            continue;
        }
        cost[i] = 0;
        ok &= dfs(i);
    }

    if(ok){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
 
    return 0;
}


Measured memory_bytes: 17408
import math
def eratos(n):
    isprime = [i for i in range(n+1)]
    # isprime[0] = 0
    isprime[1] = 1
    for i in range(2, int(math.sqrt(n))+1):
        if isprime[i] == i:
            j = i
            while j <= n:
                if isprime[j] == j:
                    isprime[j] = i
                j = j + i
    return isprime

N = int(input())
A = list(map(int, input().split()))
isprime = eratos(10**6)
count = [0 for i in range(10**6+1)]
for ai in A:
    primes = {}
    while ai != 1:
        p = isprime[ai]
        primes[p] = 1
        ai //= p
    for p in primes.keys():
        count[p] += 1
max_c = max(count)
if max_c <= 1:
    print('pairwise coprime')
elif max_c == N:
    print('not coprime')
else:
    print('setwise coprime')

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

using namespace std;

int main() {
  int N, M, C;
  cin >> N >> M >> C;
  vector<int> B(M);
  for (int i = 0; i < M; i++) cin >> B[i];
  int answer = 0;
  for (int i = 0; i < N; i++) {
    int sum = C;
    for (int j = 0; j < M; j++) {
      int A;
      cin >> A;
      sum += A * B[j];
    }
    if (sum > 0) {
      answer++;
    }
  }
  cout << answer;

  return 0;
}


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



    
int main(){
  int n;
  cin >> n;
  long long sum =0;
  vector<int> V(100001,0);
  rep(i,n){
    int a;
    cin >> a;
    V[a]++;
    sum +=a;
  }
  
  int q;
  cin >> q;
  rep(i, q){
    int b,c;
    cin >> b >> c;
    int d = c-b;
    V[c]+=V[b];
    sum += d*V[b];
    V[b]=0;
    
    cout << sum << endl;
  }
}
    
    

  



Measured memory_bytes: 3784
// AOJ 1369: Distribution Center
// 2017.11.3 bal4u@uu

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int yp[100002];
int l[200002], r[200002];

char buf[20], *bp;
int getint()
{
	int n = 0;
	while (*bp >= '0') n = (n<<3) + (n<<1) + (*bp++ & 0xf);
	return n;
}

int main()
{
	int n, m, i, x, xmin, xmax;
	int *p, *end;

	fgets(bp=buf, 20, stdin);
	n = getint(), bp++, m = getint();
	fgets(bp=buf, 20, stdin);
	x = getint(), bp++, yp[x] = getint();
	xmin = xmax = x;
	i = m-1; while (i--) {
		fgets(bp=buf, 20, stdin);
		x = getint(), bp++, yp[x] = getint();
		if (x < xmin) xmin = x;
		else if (x > xmax) xmax = x;
	}

	for (i = 1; i <= n; i++) l[i] = r[i] = i;
//	memcpy(r, l, sizeof(int)*(n+1));

	for (p = yp+xmin, end = yp+xmax; p <= end; p++) {
		if ((i = *p) > 0) {
			l[i+1] = l[i], r[i] = r[i+1];
		}
	}
	printf("%d", r[1]-l[1]+1);
	for (i = 2; i <= n; i++) printf(" %d", r[i]-l[i]+1);
	putchar('\n');
	return 0;
}

Measured memory_bytes: 3728
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>

using namespace std;

bool is_hamming[6000000];

int main(){
	
	for(int i = 0; i < 6000000; i++){
		is_hamming[i] = false;
	}
	
	is_hamming[1] = true;
	
	for(int i = 1; i <= 1000000; i++){
		if(is_hamming[i]){
			is_hamming[i * 2] = true;
			is_hamming[i * 3] = true;
			is_hamming[i * 5] = true;
		}
	}
	
	
	int m, n;
	
	while(true){
		
		cin >> m;
		
		if(m == 0){
			break;
		}
		
		cin >> n;
		
		int ans = 0;
		
		for(int i = m; i <= n; i++){
			if(is_hamming[i]){
				ans++;
			}
		}
		
		cout << ans << endl;
		
	}
	return 0;
}

Measured memory_bytes: 8900