akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

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

        for (int i = x; i < x + 100000; i++) {
            if (isPrime(i)) {
                System.out.println(i);
                return;
            }
        }
    }

    static boolean isPrime(int num) {
        if(num == 2)     return true;               // 2だったら素数
        if(num % 2 == 0) return false;              // 偶数だったら合成数

        for(int i = 3; i <= Math.sqrt(num); i+=2) {
            if(num % i == 0) return false;          // 割り切れたら合成数
        }

        return true;                                // 割り切れなかったら素数
    }
}


Measured memory_bytes: 22996
n=int(input())
l=[int(i) for i in input().split()]
x=ans=min(l)
while 1:
    t=[-1,-1]
    for i,j in enumerate(l):
        if j%x and ans>j%x:
            ans=j%x
            t[0]=i
            t[1]=ans
    l[t[0]]=ans
    x=ans
    if t[0]==-1: break


print(x)

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

import sys

'''

'''

def func():
    '''

    '''
    while True:
        n = int(raw_input())
        if n == 0:
            break

        # line_0
        m = int(raw_input())
        standard_positions = []
        standard_lines = []
        standard_reverse_lines = []

        for pos_num in range(m):
            x, y = map(int, raw_input().split())
            standard_positions.append([x, y])

        for num in range(m-1):
            line = [0, 0]
            if standard_positions[num][0] < standard_positions[num+1][0]:
                line = [0, standard_positions[num+1][0] - standard_positions[num][0]]
            elif standard_positions[num][0] > standard_positions[num+1][0]:
                line = [2, standard_positions[num][0] - standard_positions[num+1][0]]
            else:
                if standard_positions[num][1] < standard_positions[num+1][1]:
                    line = [1, standard_positions[num+1][1] - standard_positions[num][1]]
                elif standard_positions[num][1] > standard_positions[num+1][1]:
                    line = [3, standard_positions[num][1] - standard_positions[num+1][1]]
            standard_lines.append(line)

        for index in range(len(standard_lines)):
            reverse_line = [(standard_lines[-1-index][0] + 2) % 4, standard_lines[-1-index][1]]
            standard_reverse_lines.append(reverse_line)

        # print standard_positions
        # print standard_lines
        # print standard_reverse_lines

        # line_1 - line_n
        for data_num in range(n):
            m = int(raw_input())
            positions = []
            lines = []
            for pos_num in range(m):
                x, y = map(int, raw_input().split())
                positions.append([x, y])
            for num in range(m-1):
                line = [0, 0]
                if positions[num][0] < positions[num+1][0]:
                    line = [0, positions[num+1][0] - positions[num][0]]
                elif positions[num][0] > positions[num+1][0]:
                    line = [2, positions[num][0] - positions[num+1][0]]
                else:
                    if positions[num][1] < positions[num+1][1]:
                        line = [1, positions[num+1][1] - positions[num][1]]
                    elif positions[num][1] > positions[num+1][1]:
                        line = [3, positions[num][1] - positions[num+1][1]]
                lines.append(line)

            for offset in range(4):
                for line in lines:
                    line[0] = (line[0] + offset) % 4
                if lines == standard_lines or lines == standard_reverse_lines:
                    print data_num + 1
            
        print '+++++'
            


                        

    return None

if __name__ == '__main__':
    func()
    

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

#define fr first
#define se second

using namespace std;

const long long N = 2e5 + 7;
const long long inf = 1e9 + 7;
const long long mod = 1e9 + 7;

int n;
int m;
int a[N];
vector<int> g[N];
int main()
{
    ios_base::sync_with_stdio(false);

    cin >> n >> m;
    for(int i = 1; i <= n; i ++){
        cin >> a[i];
    }
    for(int i = 1; i <= m; i ++){
        int x, y;
        cin >> x >> y;
        g[x].push_back(y);
        g[y].push_back(x);
    }
    int good = 0;
    for(int i = 1; i <= n; i ++){
        int best = 0;
        for(auto to: g[i]){
            best = max(best, a[to]);
        }
        good += (best < a[i]);
    }
    cout << good << "\n";
}



Measured memory_bytes: 11456
#include "bits/stdc++.h"
using namespace std;

typedef long long lld;

inline lld paraRayLen(const lld a, const lld b){
    if(a>b){
        return paraRayLen(b, a);
    }else if(a==0LL){
        return -b;
    }else{
        return 2LL*a*(b/a)+paraRayLen(a, b%a);
    }
}

lld calculate(const lld n, const lld x){
    return n+paraRayLen(x, n-x);
}

int main(){
    lld n, x;
    while(scanf("%lld%lld", &n, &x)!=EOF){
        printf("%lld\n", calculate(n, x));
    }
    return 0;
}


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

using namespace std;

using LL = long long;
using vi = vector<int>;
using pii = pair<int, int>;
using vpii = vector<pair<int, int>>;
using vll = vector<LL>;
using LD = long double;

#define ALL(v) v.begin(), v.end()
#define endl '\n'
#define SYNC ios_base::sync_with_stdio(false); cin.tie(NULL); cerr.tie(NULL);
#define REP(i , n) for(int i =0 ; i < n ;i++)
#define REPN(i , n) for(int i = 1; i <= n ; i++)
#define cot(x) cerr << #x << " " << x << " ";
#define cotd(x) cerr << #x << " " << x << endl;
#define her 	cerr << " here \n"; 
#define pp push_back
#define fi first 
#define se second
#define un(x) x.erase(unique(ALL(x)), x.end())

template<typename T > void check(T & a, const T & b) { if (a >= b) { a %= b; } }
template<typename T>T gcd(T u, T v) { if (u == v)return u; if (u == 0)return v; if (v == 0)return u; if (~u & 1) { if (v & 1) return gcd(u >> 1, v); else return gcd(u >> 1, v >> 1) << 1; }if (~v & 1)return gcd(u, v >> 1); if (u > v)return gcd((u - v) >> 1, v); return gcd((v - u) >> 1, u); }
LL mulmod(LL a, LL b, const LL & m) { LL q = (LL)(((LD)a*(LD)b) / (LD)m); LL r = a*b - q*m; if (r>m)r %= m; if (r<0)r += m; return r; }
template <typename T, typename S>T expo(T e, S n) { T x = 1, p = e; while (n) { if (n & 1)x = x*p; p = p*p; n >>= 1; }return x; }
template <typename T>T powerL(T e, T n, const T & m) { T x = 1, p = e; while (n) { if (n & 1)x = mulmod(x, p, m); p = mulmod(p, p, m); n >>= 1; }return x; }

const int N = (int)1e5 + 2; 
int n, m, color[N]; 
bool vis[N][11]; 
vector<vi> g;

void solve(int u, int d, int c){
	if(vis[u][d]) return; 
	vis[u][d] = true; 
	if(!d){ color[u] = c; return;}
	solve(u, d - 1, c); 
	for(auto & i : g[u]){
		solve(i, d - 1, c); 
	}
}

int main(){
	SYNC; 
	cin >> n >> m; g.resize(n); 

	REP(i, m){
		int u, v; cin >> u >> v; 
		u--; v--; 
		g[u].pp(v); 
		g[v].pp(u); 
	}

	int q; cin >> q; 
	vector<vi> Q; 

	REP(i, q){
		int v, d, c; 
		cin >> v >> d >> c; 
		v--; 
		Q.pp({v, d, c}); 
	}

	for(int i = q - 1; i >= 0; i--){
		int v = Q[i][0], d = Q[i][1], c = Q[i][2]; solve(v, d, c);
	}
	REP(i, n) cout << color[i] << "\n"; 
	return 0; 
}

Measured memory_bytes: 13420
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pcc pair<char,char>
#define vi vector <int>
#define vl vector <ll>
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define pd(x) printf("%d",x)
#define plld(x) printf("%lld",x)
#define pds(x) printf("%d ",x)
#define pllds(x) printf("%lld ",x)
#define pdn(x) printf("%d\n",x)
#define plldn(x) printf("%lld\n",x)
#define INF 2e9
#define INFLL 4e18
using namespace std;
ll powmod(ll base,ll exponent,ll mod){ // with mod < 1e9
	ll ans=1;
	while(exponent){
		if(exponent&1)ans=(ans*base)%mod;
		base=(base*base)%mod;
		exponent/=2;
	}
	return ans;
}
ll gcd(ll a, ll b){
	if(b==0) return a;
	else return gcd(b,a%b);
}
const int upperlimit = 1e5+200;
const int mod = 1e9+7;
int main() {
	ll a,b,k;
	slld(a);slld(b);slld(k);
	ll x=min(a,k);
	a-=x;k-=x;
	x=min(b,k);
	b-=x;k-=x;
	pllds(a);plld(b);
	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 vi=vector<int>;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
template<typename T> void ndarray(vector<T> &vec, int len) { vec.resize(len); }
template<typename T, typename... Args> void ndarray(vector<T> &vec, int len, Args... args) { vec.resize(len); for (auto &v : vec) ndarray(v, args...); }

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

    vector<pair<int,ll>> G[N];
    for (int i=0; i<N-1; ++i)  {
        int a, b, c;
        cin >> a >> b >> c;
        --a; --b;
        G[a].push_back({b,c%2});
        G[b].push_back({a,c%2});
    }
    vector<int> dist(N,-1);
    queue<int> que;

    dist[0]=0;
    que.push(0);

    while(!que.empty()){
        int v = que.front();
        que.pop();
        for(auto nv : G[v]) {
            if(dist[nv.first]!=-1) continue;
            if(!nv.second) dist[nv.first]=dist[v];
            else dist[nv.first]=!dist[v];
            que.push(nv.first);
        }
    }
    for(int v=0; v<N; ++v) cout << dist[v] << "\n";
    return 0;
}

Measured memory_bytes: 11100
import numpy as np
 
N = int(input())
A = np.fromiter(map(int, input().split()), np.int64)
 
result = 0
for bit in range(60):
    c = int((A & 1).sum())
    result = (result + c * (N - c) * (1 << bit)) % 1000000007
    A >>= 1
print(result)

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

string ans = "CODEFESTIVAL2016";
int main(){
    string s;
    cin >> s;
    int answ = 0;
    for(int i=0;i<16;i++){
        if(s[i]!=ans[i])answ++;
    }
    cout << answ << endl;
    return 0;
}

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

using namespace std;

typedef vector<char> vc;
typedef vector<vc> vvc;
typedef long long ll;
typedef pair<int, int> pii;
typedef map<char, pii> mcpii;
typedef pair<pair<string, string>, int> ppssi;
typedef vector<ppssi> vppssi;

#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ff first
#define ss second
#define read freopen("..\\in.txt", "r", stdin)
#define write freopen("..\\out.txt", "w", stdout)

const int dir_x[]{0, 0, -1, 1}, dir_y[]{-1, 1, 0, 0};

const int INF = 1e9 + 5;

int main() {
//    read;
    int T = 1;
//    cin >> T;
    for (int tc = 1; tc <= T; ++tc) {
        int n;
        cin >> n;
        bool flag = true;
        for (int i = 0; i < n; ++i) {
            int x;
            cin >> x;
            if (x % 2 == 0 && x % 6 != 0 && x % 10 != 0) flag = false;
        }
        if (flag) cout << "APPROVED\n";
        else cout << "DENIED\n";
    }
    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
//import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {
		//System.setIn(new FileInputStream("./input.txt"));
		
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());

		String[] t = br.readLine().split(" ");
		int[] a = new int[n];
		for(int i = 0; i < n; ++i){
			a[i] = Integer.parseInt(t[i]);
		}
		int s = Partition(a, 0, n - 1);
		
		StringBuilder sb = new StringBuilder();
		for(int i = 0; i < n; ++i) {
			if(i != 0){
				sb.append(" ");
			}
			if(i == s){
				sb.append('[');
				sb.append(a[i]);
				sb.append(']');
			}else{
				sb.append(a[i]);
			}
		}
		System.out.println(sb);
		
	}
	public static int Partition(int[] a, int p, int r){
		 int x = a[r];
		 int i = p - 1;
		 int tmp;
		 for(int j = p; j < r; ++j) {
			 if(a[j] <= x){
				 i += 1;
				 tmp = a[i];
				 a[i] = a[j];
				 a[j] = tmp;
			 }
		 }
		 tmp = a[i + 1];
		 a[i + 1] = a[r];
		 a[r] = tmp;
		 return i + 1;
	}
}

Measured memory_bytes: 40412
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int main()
{
	int n,flag=1;
	int len;
	char a[105][15];
	scanf("%d",&n);
	for(int i=0;i<n;++i)
	{
		scanf("%s",a[i]);
		if(!flag||!i) continue;
		len=strlen(a[i-1]);
		if(a[i][0]!=a[i-1][len-1])
		{
			flag=0;
			continue;
		}
		for(int j=0;j<i;++j)
		{
			if(strcmp(a[j],a[i])==0)
			{
				flag=0;
				break;
			}
		}
	}
	if(flag) printf("Yes");
	else printf("No");
	return 0;
}

Measured memory_bytes: 256
n=int(input())
arr=list(map(int,input().split()))
cnt=[0]*40
for val in arr:
  tbit=format(val,'b')[::-1]
  for i in range(len(tbit)):
    if tbit[i]=='1':
      cnt[i]+=1
for val in cnt:
  if val%2==1:
    print('No')
    break
else:
  print('Yes')

Measured memory_bytes: 14212
A,B=map(int,input().split())
P=A+B
M=A-B
T=A*B
O=0
if(P>M):
  O=P
  if(P>T):
    O=P
  else:
    O=T
else:
  O=M
  if(M>T):
    O=M
  else:
    O=T
print(O)


Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] a = new int[n];
        boolean[] isA = new boolean[n];
        for (int i = 0; i < n; i++) {
            a[i] = scanner.nextInt();
        }
        int count = 0;
        int i = 0;
        while(i != 1 && !isA[i]){
            isA[i] = true;
            i = a[i]-1;
            count++;
        }
        if (i == 1){
            System.out.println(count);
        }else {
            System.out.println(-1);
        }
    }
}


Measured memory_bytes: 50900
n, m = gets.chomp.split.map(&:to_i)
h_array = gets.chomp.split.map(&:to_i)
score = Array.new(n, 1)
m.times do
  a, b = gets.chomp.split.map(&:to_i)
  if h_array[a-1] == h_array[b-1]
    score[b-1] = 0
    score[a-1] = 0
  else
    if h_array[a-1] > h_array[b-1]
      score[b-1] = 0
    else
      score[a-1] = 0
    end
  end
end
puts score.count(1)

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

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

	int n;
	cin >> n;
	cout << (n == 0 || n == 2 ? 1 : (n == 1 ? 2 : 0)) << endl;

	return EXIT_SUCCESS;
}

Measured memory_bytes: 1192
import java.util.ArrayList;
import java.util.Collections;
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 K = Integer.parseInt(sc.next());
		ArrayList<Integer> list = new ArrayList<>();
		for(int i = 0; i < N; i++) {
			list.add(Integer.parseInt(sc.next()));
		}
		sc.close();

		Collections.sort(list);
		int distance = list.get(N - 1) -list.get(0);

		for(int i = 0; i <= N - K; i++) {
			int left = i;
			int right = i + K -1;
			int tmp = list.get(right) - list.get(left);
			if(tmp < distance) {
				distance = tmp;
			}
		}
		System.out.println(distance);

	}
}

Measured memory_bytes: 51892
n = int(input())
a = list(map(int,input().split()))

num_count = {}

for e in a:
    if e in num_count.keys():
        num_count[e] += 1
    else:
        num_count[e] = 1

s = 0
c = set()

for i in range(n):
    if a[i] not in c:
        num = num_count[a[i]]
        s += num*(num-1) / 2
        c.add(a[i])

for i in range(n):
    print(int(s - (num_count[a[i]] - 1) ))

Measured memory_bytes: 28192
#include<bits/stdc++.h>
using namespace std;
int n,m ,indegree[100005];
bool vis[100005];
const int inf=10000000;
vector<int >ed[100002];
vector<int>dis(100005, 0);

int dfs(int s){
vis[s]=true;
for(int v:ed[s]){
    dis[v]=max(dis[v], dis[s]+1);
    indegree[v]--;
    if(indegree[v]==0) dfs(v);
}




}



int main(){
cin>>n>>m;
int x,y;for(int i=1;i <=m ;i++){
cin>>x>>y;
ed[x].push_back(y);
indegree[y]++;
}
for(int i=1; i<=n; i++){
    if(indegree[i]==0 && !vis[i]) dfs(i);
}
int ans=0;
for(int i=1 ;i<=n ;i++)ans=max(ans, dis[i]);
cout<<ans<<endl;

}


Measured memory_bytes: 9728
import java.util.*; 
import java.io.*;
 
class Main {
 
  /*public static String StringPeriods(String str) {
    boolean flag = false;
    String ans = "";
    for(int i=0;i<str.length();i++){
      String temp = str;
      String substr = str.substring(0,i);
      temp = temp.replaceAll(substr, "");
      if(temp.equals("")) {
    	  flag = true;
    	  ans = substr;
    	  break;
      }
    }
    if(flag) {
    	str = ans;
    }else {
    	str = "-1";
    }
    // code goes here  
    return str;
  }*/
 
  public static void main (String[] args) {  
    // keep this function call here     
    Scanner sc = new Scanner(System.in);
   int N=sc.nextInt();
   Map<Integer,Integer> map = new HashMap<Integer,Integer>();
   int[] A= new int[N];
   for(int i=0;i<N;i++) {
	   A[i]=sc.nextInt();
	   if(!map.containsKey(A[i])) {
		   map.put(A[i],1);
	   }else {
		   map.put(A[i],map.get(A[i])+1);
	   }
   }
   long anstemp = 0;
   for(Integer key:map.keySet()) {
	   long v = map.get(key);
	   anstemp+=(v*(v-1)/2);
	}
   for(int i=0;i<N;i++) {
	   long ans = anstemp;
	   long v = map.get(A[i]);
	   ans -= (v*(v-1)/2);
	   ans += ((v-1)*(v-2)/2);
	   System.out.println(ans);
   }
   
  }
}

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

int n, k;
int p[1005];

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n >> k;
	for(int i = 0; i < n; i++) cin >> p[i];
	
	sort(p, p+n);
	
	int res = 0;
	for(int i = 0; i < k; i++) res += p[i];
	cout << res << endl;
}


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

#define dbg(a)  cerr << __LINE__ << ": " << #a << " = " << a << '\n'

template<class T> inline istream& operator>>(istream& str, vector<T> &a) { for (auto &i : a) str >> i; return str; }

typedef long long ll;

ll sod(ll n){
  ll ret = 0;
  for (int i = 1; i <= n; ++i){
    ret += i*(n/i)*(n/i+1)/2;
  }
  return ret;
}

int main(){
  ios::sync_with_stdio(0), cin.tie(0);
  
  ll n;  cin >> n;
  cout << sod(n) << "\n";
  return 0;
}

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

int main() {
  

  // ここにプログラムを追記
  int A, B;
  char op;
  cin >> A >> op >> B;
  if(op == '+') {
    cout << A + B << endl;
  }
  if(op == '-') {
    cout << A - B << endl;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,m,flag,f;
vector<int>g[100005];
int v[100005];
vector<int>ans;
void dfs(int k){
	if(f) return;
	v[k]=1;
	if(!(k==1&&flag))ans.push_back(k);
	for(int i=0;i<g[k].size();i++){
		int x=g[k][i];
		if(!v[x]) dfs(x);
	}
	f=1;
}
int main(){
	cin>>n>>m;
	for(int i=1;i<=m;i++){
		int u,w;
		cin>>u>>w;
		g[u].push_back(w);
		g[w].push_back(u);
	}
	dfs(1);
	reverse(ans.begin(),ans.end());
	flag=1; f=0;
	dfs(1);
	cout<<ans.size()<<endl;
	for(int i=0;i<ans.size();i++) cout<<ans[i]<<' ';
	cout<<endl;
	return 0;
}

Measured memory_bytes: 10104
import java.util.*;
import java.io.*;

public class Main
{
	public static void main(String [] Args)
	{
		Scanner in = new Scanner(System.in);
		String s=in.next();
		String a=in.next();
		int ans=0;
		for(int i=0;i<=2;i++)
		{
			if(a.charAt(i)==s.charAt(i))
				ans++;
		}
		System.out.println(ans);

	}
}
	

Measured memory_bytes: 21844
import java.util.*;
public class Main 
{
	public static void main(String[] args) 
	{
		Scanner stdIn = new Scanner(System.in);
		while(stdIn.hasNext())
		{
			int y = stdIn.nextInt();
			int m = stdIn.nextInt();
			int d = stdIn.nextInt();
			int date = d + 100 * m + 10000 * y;
			if(date < 18680908)
			{
				System.out.println("pre-meiji");
			}
			else if(18680908 <= date && date <= 19120729)
			{
				System.out.println("meiji " + (y - 1868 + 1) + " " + m + " " + d);
			}
			else if(19120730 <= date && date <= 19261224)
			{
				System.out.println("taisho " + (y - 1912 + 1) + " " + m + " " + d);
			}
			else if(19261225 <= date && date <= 19890107)
			{
				System.out.println("showa " + (y - 1926 + 1) + " " + m + " " + d);
			}
			else if(19890108 <= date)
			{
				System.out.println("heisei " + (y - 1989 + 1) + " " + m + " " + d);
			}
		}
	}
}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
using namespace std;
#define pi 3.14159265359
#define int long long
#define pii pair<int, int>
#define ld long double
const int mod = 1e9 + 7;
 
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, -1, 0, 1};
 
 
 
 

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

 
 int r;
 cin>>r;
 cout<<r*r;
 
 
}

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

using namespace std;
typedef pair<int,int> pii;
typedef pair<int,pii> pip;

const int MAXN=2e5+25;

int N;
int p[MAXN],pinv[MAXN];
int seg[2][2*MAXN];

int query(int *seg, int a, int b) {
        int ret=MAXN;
        for (a += N, b += N; a<b; a>>=1,b>>=1) {
                if (a%2) ret=min(ret,seg[a++]);
                if (b%2) ret=min(ret,seg[--b]);
        }
        return ret;
}

void solve() {
        set<pip> segs;
        segs.insert(pip(query(seg[0],0,N),pii(0,N)));
        while (segs.size() > 0) {
                pip s = *(segs.begin());
                segs.erase(s);
                int a=s.second.first,b=s.second.second;
                //cout << "Processing " << a << " " << b << endl;
                int n1=query(seg[a%2],a,b);
                int break1 = pinv[n1];
                int n2=query(seg[1-a%2],break1,b);
                int break2 = pinv[n2];
                cout << n1 << " " << n2 << " ";
                if (break1 > a)
                        segs.insert(pip(query(seg[a%2],a,break1),pii(a,break1)));
                if (break2 > break1+1)
                        segs.insert(pip(query(seg[1-break1%2],break1+1,break2),pii(break1+1,break2)));
                if (b > break2+1)
                        segs.insert(pip(query(seg[1-break2%2],break2+1,b),pii(break2+1,b)));
        }
        cout << "\n";
}

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

        for (int i=0; i<N; i++)
                pinv[p[i]] = i;

        for (int i=0; i<2*N+1; i++) {
                seg[0][i] = MAXN;
                seg[1][i] = MAXN;
        }

        for (int i=0; i<N; i++) {
                seg[i%2][i+N] = p[i];
        }

        for (int i=N-1; i>0; i--) {
                seg[0][i] = min(seg[0][2*i],seg[0][2*i+1]);
                seg[1][i] = min(seg[1][2*i],seg[1][2*i+1]);
        }

        /*for (int i=1; i<2*N; i++)
                cout << seg[0][i] << " ";
        cout << "\n";

        for (int i=1; i<2*N; i++)
                cout << seg[1][i] << " ";
        cout << "\n";*/

        solve();

        return 0;
}

Measured memory_bytes: 8704
#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
char s[100000 + 5];
long long dp[2][13];
int main() {
  cin >> s;
  int ls = strlen(s);
  dp[0][0] = 1;
  for (int i = 0; i < ls; i++) {
    int p = (i & 1);
    int l = p ^ 1;
    memset(dp[l], 0, sizeof dp[l]);
    if (s[i] == '?') {
      for (int j = 0; j < 10; j++) {
        for (int k = 0; k < 13; k++) {
          (dp[l][(k * 10 + j) % 13] += dp[p][k]) %= mod;
        }
      }
    } else {
      int j = s[i] - '0';
      for (int k = 0; k < 13; k++) {
        (dp[l][(k * 10 + j) % 13] += dp[p][k]) %= mod;
      }
    }
  }
  cout << dp[ls & 1][5] << endl;
  return 0;
}

Measured memory_bytes: 384
@n, @k = gets.split.map(&:to_i)

@dp = Array.new(100100, 1<<60)

x = gets.chomp.split.map(&:to_i)

@h = Array.new(100_100, 0)
@n.times do |i|
  @h[i] = x[i]
end

@dp[0] = 0
@n.times do |i|
  (1..@k).each do |j|
    v = @dp[i] + (@h[i] - @h[i+j]).abs
    @dp[i+j] = v if @dp[i+j] > v
  end
end

puts @dp[@n-1]


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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

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

int main(){
    int n;cin>>n;
    map<int,int>b,c;
    set<int>a;
    rep(i,n){
        int x;cin>>x;
        b[(x+i+1)]++;
        c[(x-i-1)]++;
        a.insert(x+i+1);
        a.insert(x-i-1);
    }
    ll ans=0;
    for(auto x:a){
        ans+=(ll)b[x]*c[-x];
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 62144
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np

def main():
    N, *ABC = map(int, read().split())
    A = ABC[:N]
    B = ABC[N:2*N]
    C = ABC[2*N:]
    ans = sum(B)
    for i in range(N-1):
        if A[i] == A[i+1] - 1:
            ans += C[A[i]-1]
    print(ans)
    return

if __name__ == '__main__':
    main()



Measured memory_bytes: 12496
#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str

def solve(N: int, A: int, B: int, C: int, D: int, S: str):
    if A > B:
        A,B = B,A
        C,D = D,C

    if A > C or B > D:
        print(NO)
        return

    for i in range(A-1,C-1):
        if S[i] == "#" and S[i+1] == "#":
            print(NO)
            return

    for i in range(B-1,D-1):
        if S[i] == "#" and S[i+1] == "#":
            print(NO)
            return

    if C > D:
        bOK = False
        for i in range(A-1,C-2):
            if S[i] == "." and S[i+1] == "." and S[i+2] == "." and i+2 != B-1 and i+1 <= D-1 : 
                bOK = True
                break

        if not bOK:
            print(NO)
            return

    print(YES)







# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    D = int(next(tokens))  # type: int
    S = next(tokens)  # type: str
    solve(N, A, B, C, D, S)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1e9 + 7;
const ll INF = LLONG_MAX;

int main()
{
    string str;
    cin >> str;
    bool n, w, e, s;
    n = w = e = s = false;
    for (int i = 0; i < str.length(); i++)
    {
        if (str[i] == 'N')
            n = true;
        if (str[i] == 'W')
            w = true;
        if (str[i] == 'S')
            s = true;
        if (str[i] == 'E')
            e = true;
    }
    if (n && w && e && s)
        cout << "Yes" << endl;
    else if (n && s && !w && !e)
        cout << "Yes" << endl;
    else if (!n && !s && w && e)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int selectionSort(int *a, int n){
    int i, j, tmp, minj;
    int c = 0;
    for(i=0;i<n;i++){
        minj = i;
        for(j=i+1;j<n;j++){
            if(a[j]<a[minj])minj = j;
        }
        if(minj!=i){
            tmp = a[i];
            a[i] = a[minj];
            a[minj] = tmp;
            c++;
        }
    }
    return c;
}

int main(){
    int i, n, count;
    scanf("%d",&n);
    int *a = new int [n];
    for(i=0;i<n;i++)scanf("%d",a+i);
    count = selectionSort(a,n);
    for(i=0;i<n;i++){
        if(i>0)printf(" ");
        printf("%d",a[i]);
    }
    printf("\n%d\n",count);
    return 0;
}



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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf=1e9;
const int64_t inf64=1e18;
const double eps=1e-9;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
    	os << v << ",";
    }
    os << "]";
    return os;
}

void solve(){
    int n,t;
    cin >> n >> t;
    vector<int> a(n);
    rep(i,0,n) cin >> a[i];

    vector<int> maxi(n);
    maxi[n-1]=a[n-1];
    for(int i=n-2; i>=0; --i) maxi[i]=max(a[i],maxi[i+1]);

    int max_diff=0,num=0;
    rep(i,0,n-1){
        if(maxi[i+1]-a[i]>max_diff){
            max_diff=maxi[i+1]-a[i];
            num=1;
        }else if(maxi[i+1]-a[i]==max_diff) ++num;
    }
    cout << num << endl;
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(10);
    solve();
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define r0 return 0;
#define f(k,i,n,j) for(ll k=i;k<=n;k=k+j)
#define cin(a) cin>>a;
#define loop while(t--)
#define vi vector<int>
#define vii vector<long long int>
#define SORT(v) sort(v.begin(),v.end());
signed main()
{
   int n,k,sum=0;
   cin>>n>>k;
   int a[n];
   for(int i=0;i<n;i++)
        cin>>a[i];
    
    if(k>=n)
    cout<<0<<endl;
    else
    {
        sort(a,a+n);
        for(int i=0;i<n-k;i++)
            sum+=a[i];
        
        cout<<sum<<endl;
    }
}

Measured memory_bytes: 1792
use std::cmp::*;
use std::io::*;
use std::str::FromStr;
use utils::*;

pub fn main() {
    let i = stdin();
    let mut o = Vec::new();
    run(i.lock(), &mut o);
    stdout().write_all(&o).unwrap();
}

fn run<R: BufRead, W: Write>(i: R, o: &mut W) {
    let mut i = CpReader::new(i);
    let (n, w) = i.read2::<usize, usize>();
    let mut wv = Vec::new();
    for _ in 0..n {
        wv.push(i.read2::<usize, usize>())
    }
    writeln!(o, "{}", solve(w, &wv)).unwrap();
}
fn solve(w: usize, wv: &[(usize, usize)]) -> usize {
    let mut ws = vec![usize::max_value(); wv.len() * 1000 + 1]; // 現時点でのws[v] は価値vの品物の最小の重さ
    let mut v_max = 0;
    ws[0] = 0;

    for &(wi, vi) in wv {
        for j in (0..v_max + 1).rev() {
            let w_next = min(ws[j + vi], ws[j] + wi);
            if w_next <= w {
                ws[vi + j] = w_next;
                v_max = max(v_max, vi + j);
            }
        }
        for j in 0..vi {
            if ws[vi] < ws[j] {
                ws[j] = ws[vi];
            }
        }
    }
    v_max
}

mod utils {
    use super::*;

    pub struct CpReader<R: BufRead> {
        r: R,
        s: String,
    }

    macro_rules! fn_read {
        { $f:ident($($t:ident),*) } => {
            #[allow(dead_code)]
            pub fn $f<$($t: FromStr),*>(&mut self) -> ($($t),*) {
                let i = &mut self.read_line().split(' ');
                ($(read_next::<$t,_>(i)),*)
            }
        };
    }

    impl<R: BufRead> CpReader<R> {
        pub fn new(r: R) -> Self {
            CpReader {
                r: r,
                s: String::new(),
            }
        }
        pub fn read_line(&mut self) -> &str {
            self.s.clear();
            self.r.read_line(&mut self.s).unwrap();
            self.s.trim()
        }

        fn_read! { read2(T1, T2) }
        fn_read! { read3(T1, T2, T3) }
        fn_read! { read4(T1, T2, T3, T4) }
        fn_read! { read5(T1, T2, T3, T4, T5) }
    }
    fn read_next<'a, T: FromStr, I: Iterator<Item = &'a str>>(i: &mut I) -> T {
        i.next().unwrap().parse().ok().unwrap()
    }

}


Measured memory_bytes: 4352
N,*as=$<.read.split.map(&:to_i)
MOD=10**9+7

ret = 0

60.times do |i|
    n = as.count {|a| a[i] == 1 } * as.count {|a| a[i] == 0 }
    ret = (ret + n * 2.pow(i,MOD)) % MOD
end

puts ret



Measured memory_bytes: 39516
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#define MAX(X, Y) (((X) > (Y))? (X) : (Y))
#define MIN(X, Y) (((X) < (Y))? (X) : (Y))
int compare_int(const void *a, const void *b){
  return *(long int*)b - *(long int*)a; // 大きい順
}
int compare_int_small(const void *a, const void *b){
  return *(long int*)a - *(long int*)b; // 小さい順
}
// 公約数
long long int gcd(long long int a, long long int b){
  if(b == 0){
    return a;
  }else{
    return gcd(b, a % b);
  }
}
// 最小公倍数 = a * b / 最大公約数
// 公倍数
long long int lcm(long long int a, long long int b){
  return a * b / gcd(a, b);
}

// 5min
int main(void){
  int d;
  scanf("%d", &d);

  if(d == 25){
    printf("Christmas\n");
  }else if(d == 24){
    printf("Christmas Eve\n");
  }else if(d == 23){
    printf("Christmas Eve Eve\n");
  }else if(d == 22){
    printf("Christmas Eve Eve Eve\n");
  }

  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

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

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

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

    cout << d[n/2] - d[n/2-1] << '\n';
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <algorithm>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define stdi(in) freopen(in, "r", stdin)
#define stdo(out) freopen(out, "w", stdout)
#define stdio(in, out) stdi(in); stdo(out)
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define MAX 1000007
#define MOD 1000000007
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
//typedef int ittt;
//#define int ll


using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
#define ordered_set tree<int , null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>

const ll inf = 1e18;

ll hit[MAX][2];
ll dp[MAX][102];
int n,w;

ll solve(int i, int wt){
	//cerr<<"solve\n";
	if(i>n) return 0;

	if(dp[wt][i]!=-1) return dp[wt][i];

	ll ans = solve(i+1, wt);
	if(wt+hit[i][0] <= w){
		ans = max(ans, solve(i+1, wt+hit[i][0])+hit[i][1]);
	}

	return dp[wt][i] = ans;

}

int main(){
    /*#ifndef ONLINE_JUDGE
        stdio("in", "out");
    #endif*/
    fast;
    cin>>n>>w;

    memset(dp, -1, sizeof(dp));

    for(int i=1;i<=n;i++){
    	cin>>hit[i][0]>>hit[i][1];
    }

    ll ans = solve(1, 0);
    cout<<ans<<'\n';
    
    return 0;
}

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

int main() {
  int n, x, t;
  cin >> n >> x >> t;
  int tmp = n / x; 
  if (tmp * x == n) {
    cout << t * tmp << endl;
  }
  else {
    cout << t * (tmp + 1) << endl;
  }
}


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

int main() {
    int n;
    cin >> n;
    
    long long ans = 1;
    for (int i = 0; i < n; i++) {
        long long x;
        cin >> x;
        ans = ans / __gcd(ans, x) * x;
    }
    
    cout << ans << '\n';
    
    return 0;
}

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

#define rep(i,n) for(int i=0;i<n;++i)

long long int A[100005] = {};

using namespace std;

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

	rep(i, N)
	{
		cin >> A[i];
	}
	sort(A, A + N, [](int x, int y) {return x > y; });

	long long int edge[2] = { 0 };
	rep(i, N)
	{
		if (i + 1 >= N)
		{
			break;
		}
		if (A[i] == A[i + 1])
		{
			if (edge[0] == 0)
			{
				edge[0] = A[i];
			}
			else
			{
				edge[1] = A[i];
				break;
			}
			i++;
		}
	}
	cout << edge[0] * edge[1] << endl;
	return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
int main(){
    char a, b;
    cin >> a >> b;
    if(a=='H'){
        if(b=='H'){
            cout << "H" << endl;
        }else{
            cout << "D" << endl;
        }
    }else{
        if(b=='H'){
            cout << "D" << endl;
        }else{
            cout << "H" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
const int N = 44721;
using namespace std;
typedef long long ll;
int mod = 1e9 + 7;
int sum[N];
int main()
{


    for (int i = 1; i <= N; i++)
    {
        sum[i] = sum[i-1] + i;
    }
    int x;
    while (~scanf("%d", &x))
    {
        int loc = lower_bound(sum, sum + N, x) - sum;
        //if (sum[loc] != x)
          //  loc--;
        printf("%d\n", loc);
    }   
    return 0;
}

Measured memory_bytes: 384
using System;

namespace BABC
{
    class Program
    {
        static void Main(string[] args)
        {
            // 入力の取得
            var s = Console.ReadLine().ToCharArray();

            long answer = 0;
            int countA = 0, index = 0;
            while (index < s.Length - 1)
            {
                switch (s[index])
                {
                    case 'A' :
                        countA++;
                        break;
                    case 'B' :
                        if (s[index + 1] == 'C')
                        {
                            answer += countA;
                            index++;
                        }
                        else
                        {
                            countA = 0;
                        }
                        break;
                    case 'C' :
                        countA = 0;
                        break;
                }

                index++;
            }

            // 解答の出力
            Console.WriteLine(answer);
        }
    }
}


Measured memory_bytes: 14048
x, y = map(int, input().split())
ans = 0
x2 = -x
y2 = -y
L = [y - x, y - x2, y2 - x, y2 - x2]
Labs = [abs(y - x), abs(y - x2), abs(y2 - x), abs(y2 - x2)]
ans += min(Labs)
i = L.index(min(Labs))
if i == 1 or i == 2:
    ans += 1
elif i == 3:
    ans += 2
print(ans)


Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>

using namespace std;

int main() {
    int ans = 0, sum, a;
    for (int i = 0; i < 2; ++i) {
        sum = 0;
        for (int j = 0; j < 4; ++j) {
            cin >> a;
            sum += a;
        }
        ans = max(ans, sum);
    }
    
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 3068
#include <iostream>
using namespace std;
int main(void){
    int n,t,a,h[1001],k=0;
    cin>>n>>t>>a;
    t*=1000;
    a*=1000;  
  h[0]=1000000000;
    for(int i=1;i<=n;i++){
        cin>>h[i];
        h[i]=abs(t-6*h[i]-a);
        if(h[i]<h[k]){
            k=i;
        }
    }
    cout<<k<<endl;
    
}


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

using namespace std;
typedef long long LL;

#define LOG(...) fprintf (stderr, __VA_ARGS__)
#define pb push_back
#define mp make_pair
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()

const int INF = 0x3f3f3f3f, N = 1005, M = 45;
const LL INFL = 0x3f3f3f3f3f3f3f3fll;

int n, x[N], y[N];
char s[N][M];  
int main() {
  scanf("%d", &n);

  int cc = 0; 
  for (int i = 1; i <= n; i++)
    scanf ("%d%d", &x[i], &y[i]), cc += (abs(x[i]) + abs(y[i])) % 2; 
  
  if (cc != 0 && cc != n) return puts("-1"), 0; 
  
  int m = 31 + (cc == 0); cout << m << endl; 
  for (int i = 0; i <= 30; i++) cout << (1 << i) << " ";
  if (m == 32) cout << "1";
  cout << endl; 

  for (int i = 1; i <= n; i++) {
    if (cc == 0) s[i][31] = 'R', x[i]--; 

    for (int d = 30; d >= 0; d--) {
      if (abs(x[i]) > abs(y[i])) {
        if (x[i] < 0) s[i][d] = 'L', x[i] += (1 << d); 
        else s[i][d] = 'R', x[i] -= (1 << d); 
      } else {
        if (y[i] < 0) s[i][d] = 'D', y[i] += (1 << d);
        else s[i][d] = 'U', y[i] -= (1 << d); 
      }
    }

    puts(s[i]); 
  }
  return 0;
}


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

int main(){
  int h,w;
  int i,j;

  for(;;){

    cin>>h>>w;

    if(h==0&&w==0){
      break;
    }

    for(i=0;i<h;i++){
      for(j=0;j<w;j++){
        if(i%2==0){
          if(j%2==0){
            cout<<"#";
          }else{
            cout<<".";
          }
        }else{
          if(j%2==0){
            cout<<".";
          }else{
            cout<<"#";
          }
        }
      }
      cout<<endl;
    }
    cout<<endl;
  }

  return 0;
}

Measured memory_bytes: 3084
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		int n = sc.nextInt();
		int[][] a = new int[n - 1][3];
		for (int i = 0; i < n - 1; i++) {
			for (int j = 0; j < 3; j++) {
				a[i][j] = sc.nextInt();
			}
		}
		int time;
		for (int i = 0; i < n - 1; i++) {
			time = 0;
			for (int j = i; j < n - 1; j++) {
				if (time <= a[j][1]) {
					time = a[j][0] + a[j][1];
				} else if (time % a[j][2] == 0) {
					time += a[j][0];
				} else {
					time += a[j][0] + a[j][2] - time % a[j][2];
				}
			}
			System.out.println(time);
		}
		System.out.println(0);
	}
}


Measured memory_bytes: 28240
#include <bits/stdc++.h>
#define ld long double
#define ll long long
#define ull unsigned ll
#define pll pair<ll, ll>
#define itr(a) begin(a), end(a)
#define pb push_back
#define x first
#define y second
#define endl '\n'
#define FAST cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
#define FILES(namein, nameout) freopen(namein, "r", stdin); freopen(nameout, "w", stdout);
#define M 1000000007
#define N 200000
#define INF 101111111111111
using namespace std;
main(){
    FAST;
    ll a, b;
    cin >> a >> b;
    cout << max(a+b, max(a-b, a*b));
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define mod 1000000007
using ll = long long;
using namespace std;
int main(){
  int n;
  cin >> n;
  map<int,int> a;
  rep(i, n - 1){
    int temp;
    cin >> temp;
    a[temp]++;
  }
  rep(i, n){
    cout << a[i + 1] << endl;
  }
}

Measured memory_bytes: 13004
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]


N,M=list(map(int,input().split()))
uf=UnionFind(N)
for _ in range(M):
    a,b=list(map(int,input().split()))
    a-=1
    b-=1
    uf.union(a,b)

L=set(uf.roots())
ans=0
for k in L:
    ans=max(ans,uf.size(k))
print(ans)

Measured memory_bytes: 113160
#include<iostream>
typedef long long ll;
using namespace std;
const int N=100000;
struct shopee{
	ll w,v;
}gay[N];
int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	ll lol=0,i,j,dp[N],n,cap;
	cin>>n>>cap;
	for(i=0;i<n;++i){
		cin>>gay[i].w>>gay[i].v;
		lol+=gay[i].v;
	}
	for(i=1;i<=lol;++i) dp[i]=1e9;
	for(i=0;i<n;++i){
		for(j=lol;j>=gay[i].v;--j){
			dp[j]=min(dp[j],dp[j-gay[i].v]+gay[i].w);
		}
	}
	for(i=lol;i>=0;--i){
		if(dp[i]<=cap){
			cout<<i;
			return 0;
		}
	}
}

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

using namespace std;
using ll = long long;
// #define int ll
using PII = pair<ll, ll>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()

template<typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }

template<typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type
fill_v(T &t, const V &v) { t=v; }
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t, const V &v ) { for(auto &e:t) fill_v(e,v); }

template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a) {
    out<<'('<<a.first<<','<<a.second<<')'; return out;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
    out<<'[';
    for(const T &i: a) out<<i<<',';
    out<<']';
    return out;
}
template<class T>
ostream &operator <<(ostream& out, const set<T>& a) {
    out<<'{';
    for(const T &i: a) out<<i<<',';
    out<<'}';
    return out;
}
template<class T, class S>
ostream &operator <<(ostream& out, const map<T,S>& a) {
    out<<'{';
    for(auto &i: a) out<<i<<',';
    out<<'}';
    return out;
}

int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}; // DRUL
const int INF = 1<<30;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;

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

    ll n, m;
    cin >> n >> m;
    vector<ll> a(n+1);
    REP(i, m) {
        ll b;
        cin >> b;
        a[b] = 1;
    }

    vector<ll> dp(n+1);
    dp[0] = 1;
    REP(i, n) {
        if(i+1<=n && !a[i+1]) (dp[i+1] += dp[i]) %= MOD;
        if(i+1<=n && !a[i+2]) (dp[i+2] += dp[i]) %= MOD;
    }
    cout << dp[n] << endl;

    return 0;
}


Measured memory_bytes: 1792
#include "bits/stdc++.h"
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(s) s.begin(), s.end()
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<string> vs;
const int MX = 100005, INF = 1001001001;
const ll LINF = 1e18;
const double eps = 1e-10;
const int DIV = 1e9+7;

int n;
vs s;

int main()
{
    cin >> n;
    s.resize(n); rep(i, n) cin >> s[i];

    vl candsNum(5, 0);
    rep(i, n){
        if(s[i][0] == 'M') candsNum[0]++;
        if(s[i][0] == 'A') candsNum[1]++;
        if(s[i][0] == 'R') candsNum[2]++;
        if(s[i][0] == 'C') candsNum[3]++;
        if(s[i][0] == 'H') candsNum[4]++;
    }

    ll ans = 0;
    for(int v1 = 0; v1 < 3; v1++){
        for(int v2 = v1 + 1; v2 < 4; v2++){
            for(int v3 = v2 + 1; v3 < 5; v3++){
                ans += (candsNum[v1] * candsNum[v2] * candsNum[v3]);
            }
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 6144
#include <bits/stdc++.h>
#define REP(i, e) for(int (i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define PRINT(x) cout << (x) << "\n"
using namespace std;
using ll = long long; using pint = pair<int, int>; using pll = pair<ll, ll>;
template<typename T> auto compare = [](T x, T y) -> bool{return (x < y);};
const long long MOD = 1000000007;

ll N, D, X[200010], Y[200010];

signed main(){
    cin >> N >> D;
    REP(i, N) cin >> X[i] >> Y[i];
    ll ans = 0;
    REP(i, N){
        if(X[i] * X[i] + Y[i] * Y[i] <= D * D) ans++;
    }
    PRINT(ans);
    return 0;
}

Measured memory_bytes: 6756