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

public class Main {

	final static long MOD = 1000000007L;
	public static String[] Ws = null;
	public static int wsIndx = 0;
	public static BufferedReader in = null;
	public static ArrayList<int[]> list = new ArrayList<>();
	public static long[] ans = new long[]{-1,-1,-1};
	public static void main(String[] args) throws Exception {


		int N = nextInt();
		int M = nextInt();
		int[] X = nextInts();

		Arrays.sort(X);
		int[] Y = new int[X.length-1];
		long sum=0;
		for(int i=0;i<M-1;i++){
			Y[i]=X[i+1]-X[i];
			sum+=Y[i];
		}
		Arrays.sort(Y);
		if(N>=M){
			sum=0;
		}else{
			for(int i=0;i<N-1;i++){
				sum-=Y[Y.length-1-i];
			}
		}
		System.out.println(sum);

	}



	public static String[] toStringArray(String s) {
		String[] tmp = new String[s.length()];
		char[] c = s.toCharArray();
		for (int i = 0; i < tmp.length; i++) {
			tmp[i] = String.valueOf(c[i]);
		}
		return tmp;
	}

	public static String concatStringArray(String[] s){
		StringBuffer sb = new StringBuffer();
		for(String x:s){
			sb.append(x);
		}
		return sb.toString();
	}

	public static void check() throws Exception{
		if(in == null){
			in = new BufferedReader(new InputStreamReader(System.in));
		}
		if(Ws==null || Ws.length<=wsIndx){
			Ws = in.readLine().split(" ");
			wsIndx=0;
		}
	}
	public static int nextInt()throws Exception{
		check();
		return Integer.parseInt(Ws[wsIndx++]);
	}

	public static long nextLong()throws Exception{
		check();
		return Long.parseLong(Ws[wsIndx++]);
	}

	public static String nextString()throws Exception{
		check();
		return Ws[wsIndx++];
	}

	public static int[] nextInts()throws Exception{
		check();
		int[] tmp = new int[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Integer.parseInt(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static long[] nextLongs()throws Exception{
		check();
		long[] tmp = new long[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Long.parseLong(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static String[] nextStrings()throws Exception{
		check();
		wsIndx=Ws.length;
		return Ws;
	}


}


Measured memory_bytes: 35816
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define MP make_pair
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define PLI pair<ll, int>
#define PIL pair<int, ll>
#define STR string
#define Fst first
#define Snd second
#define SHN 1e9
#define LSHN 1e18
using namespace std;
int n,m,ki;
ll a[3010][3010];
ll d[3010][3010][4];
int main()
{
	scanf("%d%d%d",&n,&m,&ki);
	for (int i=0;i<ki;i++)
	{
		int x,y,z;
		scanf("%d%d%d",&x,&y,&z);
		x--,y--;
		a[x][y]=z;
	}
	for (int i=0;i<n;i++)
		for (int j=0;j<m;j++)
			for (int k=0;k<=3;k++) d[i][j][k]=-1e18;
	d[0][0][0]=0,d[0][0][1]=a[0][0];
	for (int i=0;i<n;i++)
	{
		for (int j=0;j<m;j++)
		{
			for (int k=0;k<4;k++)
			{
				//cout <<i<<" "<<j<<" "<<k<<" ##\n"; 
				if (k>3) break;
				if (d[i][j][k]==-1e18) continue;
				if (j!=m-1)
				{
					if (k!=3) d[i][j+1][k+1]=max(d[i][j+1][k+1],d[i][j][k]+a[i][j+1]);
					d[i][j+1][k]=max(d[i][j+1][k],d[i][j][k]);
				}
				if (i!=n-1)
				{
					d[i+1][j][1]=max(d[i+1][j][1],d[i][j][k]+a[i+1][j]);
					d[i+1][j][0]=max(d[i+1][j][0],d[i][j][k]);
				}
			}
		}
	}
	ll r=0;
	for (int i=0;i<=3;i++) r=max(r,d[n-1][m-1][i]);
	printf("%lld",r);
	return 0;
}

Measured memory_bytes: 356416
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    println(problemSumitomoMitsuiB(n))
}

fun problemSumitomoMitsuiB(n: Int): String {
    val ans = n / 1.08
    if (((ans + 0.9).toInt() * 1.08).toInt() != n) return ":("
    return (ans + 0.9).toInt().toString()
}

Measured memory_bytes: 29484
import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
# from math import ceil, floor, log2
from collections import deque, defaultdict
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np    # cumsum
# from bisect import bisect_left, bisect_right

def solve():
    N = II()
    D = LI()
    M = II()
    T = MI()

    dct_d = defaultdict(lambda: 0)
    for d in D:
        dct_d[d] += 1

    for t in T:
        if dct_d[t] > 0:
            dct_d[t] -= 1
        else:
            print('NO')
            return
    print('YES')

if __name__ == '__main__':
    solve()



Measured memory_bytes: 50640
import java.util.*;

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

Measured memory_bytes: 23636
N = int(input())
A = [int(input()) for c in range(N)]
A = sorted(A)

tmp = 1
cnt = 0
for i in range(N):    
    if i+1<N:
        if A[i] == A[i+1]:
            tmp += 1
        else:
            cnt += tmp%2
            tmp = 1
    else:
        cnt += tmp%2

print(cnt)


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

inline int readInt(){
  int ret = 0;
  char c;
  //  while((c=getchar()) && '0' <= c && c <= '9'){
  while((c=getchar()) && isdigit(c)){
    ret = ret * 10 + (c-'0');
  }
  return ret;
}

main(){
  int n,s;
  int r[101]={0};
  while(true){
    n = readInt();
    if (n==0)break;
    s = readInt();
    for(int i=0;i<n;i++){
      int tmp;tmp=readInt();r[tmp]++;
    }
    int ans = 0;
    for(int i=1;i != 101;i++){
      if (r[i] && i+i > s)ans += r[i]*(r[i]-1)/2;
      if (!r[i])continue;
      for(int j=100;j > i;j--){
	if (i+j <= s)break;
	ans += r[i]*r[j];
      }
      r[i] = 0;
    }
    printf("%d\n",ans);
  }
}

Measured memory_bytes: 0
import java.util.Scanner;

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

        while(true){
        
            int m =sc.nextInt();
            int f = sc.nextInt();
            int r = sc.nextInt();

            if( m == -1 && f == -1 && r ==-1){
                break;
            }
            else if(m == -1 || f == -1 ){
                System.out.println("F");
            }
            else if( m+f >= 80 && m+f <= 100){
                System.out.println("A");
            }
            else if( m+f >= 65 && m+f <80){
                System.out.println("B");
            }
            else if( (m+f >= 50 && m+f < 65)){
                System.out.println("C");
            }
            else if(m+f < 50 && m+f >= 30 && r >= 50){
                System.out.println("C");
            }
            else if( m+f < 50 && m+f >= 30){
                System.out.println("D");
            }
            else if( m+f >= 0 && m+f < 30){
                System.out.println("F");
            }
            else if(r >= 0 && r < 50){
                System.out.println("F");
            }
        }
        sc.close();
    }
}


Measured memory_bytes: 26288
#include <bits/stdc++.h>
#define IOS {ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);}
#define endl "\n"
#define int long long int
#define f(i, a, b) for(int i=a; i<b; i++)
#define fb(i, a, b) for(int i=a; i>=b; i--)
#define pb push_back
#define fi first
#define se second
#define vi vector <int>
#define pi pair <int, int>
#define S(x) (int) x.size()
#define LB lower_bound
#define UB upper_bound
#define fp(x, y) fixed<<setprecision(y)<<x
#define M 100005
#define mod 1000000007
#define PI 3.141592653589793238462643383279502884
using namespace std;

void solve()
{
	int x, y;
	cin>>x>>y;
	if(y >= 2*x && y <= 4*x && y%2 == 0) cout<<"Yes";
	else cout<<"No";
}

int32_t main()
{
    IOS
    int t = 1;
    // cin>>t;
    f(tno, 1, t+1)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3644
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

const double PI = 3.141592653589793238462643383279502884;

int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  std::cout << std::setprecision(20) << std::fixed;

  int ra, rb, h, m;
  cin >> ra >> rb >> h >> m;
  m += h * 60;

  double xa, ya, xb, yb;

  double a_theta = 360.0 * m / 720.0;
  if (a_theta <= 90) {
    a_theta = 90 - a_theta;
  } else {
    a_theta = 360 - a_theta + 90;
  }

  xa = ra * cos(a_theta / 180 * PI);
  ya = ra * sin(a_theta / 180 * PI);

  double b_theta = 360.0 * (m % 60) / 60.0;
  if (b_theta <= 90) {
    b_theta = 90 - b_theta;
  } else {
    b_theta = 360 - b_theta + 90;
  }

  xb = rb * cos(b_theta / 180 * PI);
  yb = rb * sin(b_theta / 180 * PI);

  double dx = abs(xa - xb), dy = abs(ya - yb);
  cout << sqrt(dx * dx + dy * dy) << endl;

  return 0;
}

Measured memory_bytes: 4184
import java.util.Scanner;

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

        int varticalCount = sc.nextInt();
        int horizontalCount = sc.nextInt();

        int[] nums = new int[varticalCount];
        for (int i = 0; i < nums.length; i++) {
            nums[i] = i + 1;
        }

        String swapIndexs;
        int commaIndex;
        int swapIndex1, swapIndex2;
        int dummy;
        for (int i = 0; i < horizontalCount; i++) {
            swapIndexs = sc.next();
            commaIndex = swapIndexs.indexOf(",");
            swapIndex1 = Integer.parseInt(swapIndexs.substring(0, commaIndex)) - 1;
            swapIndex2 = Integer.parseInt(swapIndexs.substring(commaIndex + 1)) - 1;

            dummy = nums[swapIndex1];
            nums[swapIndex1] = nums[swapIndex2];
            nums[swapIndex2] = dummy;
        }

        for (int i = 0; i < nums.length; i++) {
            System.out.println(nums[i]);
        }

        sc.close();
    }
}


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

using namespace std;
constexpr long long int mod = 1000000007;

int main() {
    int X;
    cin >> X;
	for (long long i = -5000; i <= 5000; i++)
	{
		for (long long j = -5000; j < 5000; j++)
		{
			if (i * i * i * i * i - j * j * j * j * j == X) {
				cout << i << " " << j << endl;
				return 0;
			}
		}
	}
}

Measured memory_bytes: 3624
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;

int main() {
	string S;
	cin >> S;
	string prev = "";
	string now = "";
	int ans = 0;
	for (int i = 0; i < S.size(); i++) {
		now += string(1, S[i]);
		if (prev != now) {
			ans++;
			prev = now;
			now = "";
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define int long long
struct RAQ{
  static const int MAX_N = 1 << 17;
  int datm[2*MAX_N],data[2*MAX_N],n;
  RAQ(){}
  RAQ(int n_){init(n_);}
  void init(int n_){
    n=1;
    while(n<n_) n*=2;
    for(int i=0;i<n*2;i++) datm[i]=data[i]=0;
  }
  void add(int a,int b,int x,int k,int l,int r){
    if(r<=a||b<=l) return;
    if(a<=l&&r<=b){
      data[k]+=x;
      return;
    }
    add(a,b,x,k*2+1,l,(l+r)/2);
    add(a,b,x,k*2+2,(l+r)/2,r);
    datm[k]=max(datm[k*2+1]+data[k*2+1],datm[k*2+2]+data[k*2+2]);
  }
  int query(int a,int b,int k,int l,int r){
    if(r<=a||b<=l) return 0;
    if(a<=l&&r<=b) return datm[k]+data[k];
    int vl=query(a,b,k*2+1,l,(l+r)/2);
    int vr=query(a,b,k*2+2,(l+r)/2,r);
    return max(vl,vr)+data[k];
  }
  void add(int a,int b,int x){
    add(a,b,x,0,0,n);
  }
  int query(int a,int b){
    return query(a,b,0,0,n);
  }
};
signed main(){
  int n,q;
  cin>>n>>q;
  RAQ raq(n);
  for(int i=0;i<q;i++){
    int c,s,t,x;
    cin>>c;
    if(c){
      cin>>x;
      cout<<raq.query(x-1,x)<<endl;
    }else{
      cin>>s>>t>>x;
      raq.add(s-1,t,x);
    }
  }
  return 0;
}

/*
verified on 2017/02/18
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_2_E
*/



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

using namespace std;

const int CMax = 100002;

int A, B, C, D, s = -1, e = -1;

int main(){
    scanf("%d %d %d %d", &A, &B, &C, &D);
    if (A <= C && B > C) s = C;
    if (C <= A && D > A) s = A;
    if (s >= 0){
        if (B <= D) e = B;
        if (D < B) e = D;
    }
    printf("%d\n", e - s);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define LL long long
#define M 1000000007
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define print(a, n) for(LL e=0; e<n; e++) cout<<a[e]<<" "; cout<<endl;
#define read(a, n) for(LL e=0; e<n; e++) cin>>a[e];
using namespace std;

int main()
{
	fastio;
	int a, flag=0;
	cin>>a;
	if(a==1){
		cout<<"Yes"<<endl;
		return 0;
	}
	for(int i=2; i<=9; i++){
		if(a%i==0 && a/i<=9){
			flag=1;
			break;
		}
	}
	if(flag)
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
	return 0;
}


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

int main() {
    //
    int num;
    cin >> num;
    vector<int> vec(num * 2, 0);
    for (int i = 0; i < num*2; i += 2) {
        int a, b;
        cin >> a >> b;
        vec.at(i) = a;
        vec.at(i + 1) = b;
    }

    int cnt = 0;
    bool chk = true;
    for (int i = 0; i < num * 2; i+=2) {
        if (vec.at(i) == vec.at(i+1)) {
            cnt++;
        } else {
            cnt = 0;
            continue;
        }

        if (cnt == 3) {
            cout << "Yes";
            return 0;
        }
    }
    cout << "No";
    

    //
}


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

const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1.0);

int main(void)
{
    string s;
    cin >> s;
    ll c=0;
    rep(i,s.size()){
        if(c==0 &&s[i]=='C') c++;
        if(c==1 && s[i]=='F') c++;
    }
    if(c==2) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 3588
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<(n);i++)
#define loop(i,a,n) for(i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;

int dp[5005][5005];

int main(void) {
  int i,j;
  int n,k;
  cin>>n>>k;
  vi a(n);
  rep(i,n)cin>>a[i];
  sort(all(a));

  int ok=-1;//不必要が確定している
  int ng=n;//必要が確定している
  
  while(ng-ok>1){
    int mid=(ok+ng)/2;
    bool c=true;

    //    cout<<mid<<endl;

    rep(i,n+1)rep(j,k+1)dp[i][j]=0;
    dp[0][0]=1;

    rep(i,n)rep(j,k){
      dp[i+1][j]|=dp[i][j];
      if(i!=mid)dp[i+1][min(j+a[i],k)]|=dp[i][j];
    }
    /*
    rep(i,n+1)rep(j,k+1)if(dp[i][j]>0)
      cout<<i<<" "<<j<<" "<<dp[i][j]<<endl;
    */
    rep(j,k)if(dp[n][j]>0){
      //       cout<<j<<endl;
      if(j+a[mid] >= k) c=false;
    }
    // cout<<mid<<" "<<c<<endl;

    if(c)ok=mid;
    else ng=mid;
  }

  cout<<ok+1<<endl;
}
/*
カードiを含むすべて集合の総和sum
sum >= k
sum-a[i] >= k
カードiは不必要

カードiを含まないある集合の総和sum
sum + a[i] >= k
sum < k
カードiは必要

a_1 < a_2 < … < a_n


a_iが不必要のときa_j (j<i)も不必要!!


a[i]を使わないとき和がk未満になるすべての集合のsum

dp[i][j]
a[i]までみたときに和がjとなるような集合の数

初期化
dp[0][0]=1
遷移
dp[i+1][j]=dp[i][j]
dp[i+1][min(j+a[i],k)]=dp[i][j]

O(NK * logN)


*/


Measured memory_bytes: 98048
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

func main() {
	sc.Split(bufio.ScanWords)
	A, B, C, K := getInt(), getInt(), getInt(), getInt()

	ans := 0
	ans += min(A, K)
	K -= A + B
	if K >= 0 {
		ans -= min(C, K)
	}
	out(ans)
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using ll = long long;
using Graph = vector<vector<int>>;

int main()
{

    int N;
    string S;
    cin >> N >> S;
    for(char ch : S)
    {
        int offset = ((ch - 'A') + N) % 26;
        cout << (char)('A' + offset);
    }
    cout << endl;
}

Measured memory_bytes: 256
N, K = map(int, input().split())
A = [0] * N
for _ in range(K):
    input()
    A_ = list(map(int, input().split()))
    for a in A_:
        A[a-1] += 1

cnt = 0
for a in A:
    if a == 0:
        cnt += 1

print(cnt)


Measured memory_bytes: 9188
import bisect
N=int(input())
P=list(map(int,input().split()))

pos=[-1]*(N+1)

for i in range(N):
  pos[P[i]]=i
  
called=[-1,-1,pos[N],N,N]
ans=0
for i in range(N-1,0,-1):
  hoge=pos[i]
  r=bisect.bisect_left(called,hoge)
  R=called[r]
  RR=called[r+1]
  L=called[r-1]
  LL=called[r-2]
  ans+=i*((RR-R)*(hoge-L)+(L-LL)*(R-hoge))
  called.insert(r,hoge)
  #called=called[:r]+[hoge]+called[r:]
print(ans)
  


Measured memory_bytes: 83660
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
# def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  n,x,m=LI()
  ans=[x]
  d={x:x}
  y=-inf
  for i in range(n-1):
    x=x*x%m
    if x in d:
      y=x
      break
    d[x]=x
    ans.append(x)

  if y==-inf:
    return sum(ans)

  # print(ans)

  for i,x in enumerate(ans):
    if x==y:
      break

  sm=sum(ans)
  n-=len(ans)
  ans2=ans[i:]
  sm+=n//len(ans2)*sum(ans2)

  n%=len(ans2)
  for i in range(i,i+n):
    sm+=ans[i]

  return sm

# main()
print(main())


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

using namespace std;

#define INF 1e9

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

    int n;
    cin>>n;

    int ans=0;

    for(int i=0;i<n;i++){
        int l,r;
        cin>>l>>r;

        ans+=(r-l+1);
    }

    cout<<ans<<endl;

}

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

const long long inf = 0x3f3f3f3f3f3f3f3fLL;
int n, m, f[100010], fst[100010], num = 0, pos[100010];
struct th
{
    int a, b, c, id;
} a[100010];
struct edge
{
    int x, y, n;
} e[100010];
vector<int> e1[100010];
long long sum[100010], dp[100010];

void ins(int x, int y)
{
    e[++num] = {x, y, fst[x]};
    fst[x] = num;
}
int cmp(th x, th y) { return x.c < y.c; }
int fd(int x) { return f[x] == x ? x : f[x] = fd(f[x]); }
void dfs(int x)
{
    sum[x] = a[x].b;
    for (int i = fst[x]; i; i = e[i].n)
    {
        int y = e[i].y;
        dfs(y);
        sum[x] += sum[y];
    }
    if (fst[x])
    {
        dp[x] = inf;
        for (int i = fst[x]; i; i = e[i].n)
        {
            int y = e[i].y;
            dp[x] = min(dp[x], sum[x] - sum[y] + max(1LL * a[x].c, dp[y]));
        }
    }
    else dp[x] = a[x].b + a[x].c;
}
int main()
{
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; i++)
    {
        scanf("%d%d", &a[i].a, &a[i].b);
        a[i].c = max(a[i].a - a[i].b, 0);
        a[i].id = i;
    }
    sort(a + 1, a + 1 + n, cmp);
    for (int i = 1; i <= n; i++)
        pos[a[i].id] = i;
    for (int i = 0; i < m; i++)
    {
        int x, y;
        scanf("%d%d", &x, &y);
        e1[pos[x]].push_back(pos[y]);
        e1[pos[y]].push_back(pos[x]);
    }/*
    for (int i = 1; i <= n; i++)
        printf("%d %d %d\n", a[i].a, a[i].b, a[i].c);*/
    for (int i = 1; i <= n; i++)
    {
        f[i] = i;
        for (int y : e1[i])
            if (y < i && fd(y) != i)
            {
                ins(i, fd(y));
                f[fd(y)] = i;
            }
    }/*
    for (int i = 1; i <= num; i++)
        printf("%d %d\n", e[i].x, e[i].y);*/
    dfs(n);
    printf("%lld\n", dp[n]);
}

Measured memory_bytes: 13564
#include<bits/stdc++.h>
#define N 200009
#define ll long long
using namespace std;
int n,t,a[3009],b[3009],dp[3009][3009];
pair<int,int>p[200009];
int main()
{
    cin>>n>>t;
    for(int i=0;i<n;i++)cin>>p[i].first>>p[i].second;
    sort(p,p+n);
    for(int i=0;i<n;i++)
    {
        a[i]=p[i].first;
        b[i]=p[i].second;
    }
    int ans=0;
    memset(dp,-1,sizeof(dp));
    dp[0][0]=0;
    if(a[0]<t)dp[0][a[0]]=b[0];
    else ans=max(ans,a[0]);
    for(int i=1;i<n;i++)
    {
        for(int j=0;j<t;j++)
        {
            if(dp[i-1][j]==-1)continue;
            if(j+a[i]<t)dp[i][j+a[i]]=max(dp[i][j+a[i]],dp[i-1][j]+b[i]);
            else ans=max(ans,dp[i-1][j]+b[i]);
            dp[i][j]=max(dp[i][j],dp[i-1][j]);
        }
    }
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<t;j++)
        {
            ans=max(dp[i][j],ans);
        //    cout<<dp[i][j]<<" ";
        }//cout<<"\n";
    }
    cout<<ans;
}


Measured memory_bytes: 35712
#include <bits/stdc++.h>
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
struct UnionFind {
    vector<int> r;
    UnionFind(int N) {
        r = vector<int>(N, -1);
    }
    int root(int x) {
        if (r[x] < 0) return x;
        r[x] = root(r[x]);
        return r[x];
    }
    bool unite(int a, int b) {
        int x = root(a);
        int y = root(b);
        if (x == y) return false;
        if (x > y) swap(x, y);
        r[x] += r[y];
        r[y] = x;
        return true;
    }
    int size(int x) {
        return -r[root(x)];
    }
};
int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n, m;
    cin >> n >> m;
    UnionFind UF(n);
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        UF.unite(a, b);
    }
    int res = 1;
    for (int i = 0; i < n; i++) {
        res = max(res, UF.size(i));
    }
    cout << res << endl;
}

Measured memory_bytes: 3984
from operator import itemgetter

while 1:
    n = int(input())
    if n == 0:
        break
    t_w = []
    for _ in range(n):
        m, a, b = map(int, input().split())
        t_w.append((a, m, 5))
        t_w.append((b, -m, 3))
    t_w.sort(key=itemgetter(0, 2))
    ans, cur = 'OK', 0
    for t, w, pri in t_w:
        cur += w
        # print('t', t, 'w', w, 'cur', cur)
        if cur > 150:
            ans = 'NG'
            break
    print(ans)

Measured memory_bytes: 7608
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
#include <vector>
#include <numeric>
#include <map>
#include <cmath>
#include <iomanip>
#include <set>
using ll =long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vs = vector<string>;
using vvs = vector<vs>;

ll mod = 1000000000 + 7;
int main(){
    int N;
    cin >> N;
    vi a(N);
    for(int i=0; i<N; i++) cin >> a.at(i);

    int j=1;

    for(int i=1; i<=N; i++){
        j = a.at(j-1);
        if(j == 2){
            cout << i << endl;
            return 0;
        }
    }
    cout << "-1" << endl;
}

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

typedef pair<int, int> Pi;
typedef pair<int, Pi > Ti;
#define fi first
#define se second

int main()
{
  vector< Ti > data;
  
  for(int i = 1; i <= 150; i++) {
    for(int j = i + 1; j <= 150; j++) {
      data.push_back(Ti(i * i + j * j, Pi(i, j)));
    }
  }
  sort(data.begin(), data.end());
  
  int H, W;

  while(cin >> H >> W, H || W) {
    
    Ti val = *upper_bound(data.begin(), data.end(), Ti(H * H + W * W, Pi(H, W)));
    
    cout << val.se.fi << " " << val.se.se << endl;
  }

  return 0;
}
  
  

Measured memory_bytes: 3220
#include <bits/stdc++.h>
#define pb push_back
#define x first
#define y second
#define all(a) a.begin(), a.end()
#define sz(a) (int)a.size()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int>pii;
const int maxn = 2e5 + 100;
const int mod = 1e9 + 7;
struct line
{
    ll k, b;
    line() = default;
    line(ll kk, ll bb)
    {
        k = kk;
        b = bb;
    }
    ll eval(ll x)
    {
        return k * x + b;
    }
};
ld inter(line f, line s)
{
    return 1.0 * (s.b - f.b) / (f.k - s.k);
}
int n;
ll C, h[maxn], dp[maxn], siz, it;
line hull[maxn];
void add(line a)
{
    while(siz >= 2 && inter(hull[siz - 1], hull[siz - 2]) >= inter(hull[siz - 2], a))
        siz--;
    hull[siz++] = a;
}
ll get(ll x)
{
    while(it + 1 < siz && hull[it].eval(x) > hull[it + 1].eval(x))
        it++;
    return hull[it].eval(x);
}
int main()
{
    ios_base::sync_with_stdio(false), cin.tie(0);
    cin >> n >> C;
    for(int i = 0; i < n; i++)
        cin >> h[i];
    add(line(-2 * h[0], h[0] * h[0]));
    for(int i = 1; i < n; i++)
    {
        dp[i] = h[i] * h[i] + get(h[i]) + C;
        add(line(-2 * h[i], h[i] * h[i] + dp[i]));
    }
    cout << dp[n - 1] << "\n";
    return 0;
}


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

long long a[1000000+1] = {};

//解説AC
 
int main(){
    int k;
    cin >> k;
    a[0] = 7 % k;
    for(int i = 1; i < k; i++){
        //a[i]は、777...77を示していて、これをkで割っていけば余りを求められることができる。
        a[i] = (a[i-1]*10 + 7) % k;
    }
    //鳩ノ巣原理より、k回調べれば十分となる。
    for(int i = 0; i < k; i++){
        if(a[i] == 0){
            cout << i+1 << endl;
            return 0;
        }
    }
    cout << -1 << endl;

    return 0;
}

Measured memory_bytes: 11404
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int INF = 1000000000;

int main() {
    ll a;
    cin >> a;
    string b;
    cin >> b;
    string bd;

    for (int i=0; i<b.size(); i++){
        if (b[i] != '.')bd += b[i];
    }
    cout << stoi(bd)*a / 100 << endl;
}

Measured memory_bytes: 3636
int1 = lambda x: int(x) - 1

N, M = map(int, input().split())

red = [True] + [False] * (N-1)
n_ball = [1] * N

for _ in range(M):
    x,y = map(int1, input().split())
    if red[x]:
        red[y] = True
        n_ball[x] -= 1
        n_ball[y] += 1
        if n_ball[x] == 0:
            red[x] = False
    else:
        n_ball[x] -= 1
        n_ball[y] += 1

print(sum(red))

Measured memory_bytes: 4596
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#define MXN 2003

int n,k,ans=1000000000,cnt;
bool flag[MXN];

struct edge{
	int fm,
		to,
		next;
}e[2*MXN];
int tot,last[MXN];
void addEdge(int u, int v){
	tot++;
	e[tot].fm=u;
	e[tot].to=v;
	e[tot].next=last[u];
	last[u]=tot;
}

void dfsPoint(int fj, int fa, int t){
	if(t>k/2)
		return;
	else
		cnt++;
	for(int i=last[fj];i;i=e[i].next)
		if(e[i].to!=fa)
			dfsPoint(e[i].to,fj,t+1);
}
void dfsEdge(int fj, int fa, int t){
	if(t>k/2)
		return;
	else{
		if(flag[fj]){
			flag[fj]=0;
			cnt++;
		}
	}
	for(int i=last[fj];i;i=e[i].next)
		if(e[i].to!=fa)
			dfsEdge(e[i].to,fj,t+1);
}

int main(){


	scanf("%d%d",&n,&k);
	for(int i=1,u,v;i<n;i++){
		scanf("%d%d",&u,&v);
		addEdge(u,v);
		addEdge(v,u);
	}
	

	if(!(k&1)){
		for(int i=1;i<=n;i++){
			cnt=0;
			dfsPoint(i,0,0);
			ans=std::min(ans,n-cnt);
		}
		printf("%d\n",ans);
	}
	else{
		for(int i=1;i<n;i++){
			cnt=0;
			for(int j=1;j<=n;j++)
				flag[j]=1;
			dfsEdge(e[i].fm,0,0);
			dfsEdge(e[i].to,0,0);
			ans=std::min(ans,n-cnt);
		}
		printf("%d\n",ans);
	}
	
	//system("pause");

	return 0;
}
/*

 */

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
int digitSum(int x) {
    int tmp = x;
    int ret = 0;
    while (tmp > 0) {
        ret += tmp % 10;
        tmp /= 10;
    }
    return ret;
}
/* main */
int main(){
    int N, A, B;
    cin >> N >> A >> B;
    int ans = 0;
    for (int i = 1; i <= N; i++) {
        int dSum = digitSum(i);
        if (A <= dSum && dSum <= B) ans += i;
    }
    cout << ans << '\n';
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}



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

  ll N ; cin  >> N;
  string s, t;
  cin >> s >> t;

  for(ll i = 0 ; i < s.size() ;i++){
    bool flag = true;
    for(ll j = i ; j < s.size(); j++){
      if(s[j] != t[j-i]) {
	flag = false;
	break;
      }
    }
    if(flag){
      cout << i + s.size() << endl;
      return 0;
    }
  }
  
  
  cout << 2*s.size() << endl;
  
  //cout << fixed << setprecision(16) << ans << endl;
  
  return 0;
}


Measured memory_bytes: 256
/*
*/

#pragma GCC optimize("O3")
#define _CRT_SECURE_NO_WARNINGS
#include <fstream>
#include <iostream>
#include <string>
#include <complex>
#include <math.h>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <stdio.h>
#include <stack>
#include <algorithm>
#include <list>
#include <ctime>

#include <memory.h>
#include <assert.h>

#define y0 sdkfaslhagaklsldk

#define y1 aasdfasdfasdf
#define yn askfhwqriuperikldjk
#define j1 assdgsdgasghsf
#define tm sdfjahlfasfh
#define lr asgasgash
#define norm asdfasdgasdgsd
#define have adsgagshdshfhds
#define ends asdgahhfdsfshdshfd
#define prev asdgSHJsfgsdfhdsh
#define hash asdgasdgasdgdfrywewery

#define eps 1e-9
#define M_PI 3.141592653589793
#define bsize 300

#define ldouble long double
using namespace std;

#define bs 1000000007

const int N = 1100031;

int n,k;
string st;

int main(){
//    freopen("apache.in","r",stdin);
//    freopen("apache.out","w",stdout);
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(0);
    //cin.tie(0);

    cin>>n>>k;
    cin>>st;
    for (int i=0;i<st.size();i++){
    	if (i+1==k)
    		cout<<char(st[i]-'A'+'a');
    	else
    		cout<<st[i];
    }
    cout<<endl;

//    cin.get(); cin.get();
    return 0;
}


Measured memory_bytes: 256
import java.io.InputStream;
import java.io.PrintStream;
import java.util.*;

public class Main {

  private static final long MOD = 998244353;

  public static void main(String[] args) {
    solve(System.in, System.out);
  }

  static void solve(InputStream is, PrintStream os) {
    Scanner sc = new Scanner(is);

    /* read */
    int n = sc.nextInt();
    int[] d = new int[n];
    for (int i = 0; i < n; i++) {
      d[i] = sc.nextInt();
    }

    int[] hist = new int[n];
    for (int i = 0; i < n; i++) {
      hist[d[i]]++;
    }

    os.println(solve(n, d, hist));
  }

  private static long solve(int n, int d[], int hist[]) {
    if (d[0] != 0) return 0;
    if (hist[0] > 1) return 0;


    int last = 1;
    long ans = 1;

    for (int i = 1; i < n; i++) {
      for (int j = 0; j < hist[i]; j++) {
        ans = ans * last % MOD;
      }
      last = hist[i];
    }
    return ans;
  }
}


Measured memory_bytes: 52848
import math
import fractions

#最小公倍数
def union_lcm(lists):
    if len(lists)==1:
        return lists[0]
    elif len(lists)>1:
        num=lists[0]
        for i in range(1,len(lists)):
            num=num*lists[i]//fractions.gcd(num,lists[i])
        return num


#最大公約数
def union_gcd(lists):
    if len(lists)==1:
        return lists[0]
    elif len(lists)>1:
        num=lists[0]
        for i in range(1,len(lists)):
            num=fractions.gcd(num,lists[i])
        return num
    
n,m=map(int,input().split())
lists=list(map(int,input().split()))

#受け取ったリスト内の要素を2で割る(uselistっていうlistに保管)
uselist=[0 for i in range(n)]
for i in range(n):
    uselist[i]=lists[i]//2
  
G=union_lcm(uselist)
flag=True
for some in uselist:
    if (G//some)%2==0:
        flag=False
        break
if flag:
    if (m//G)%2==0:
        print((m//G)//2)
    else:
        print((m//G+1)//2)
    
else:
    print(0)


Measured memory_bytes: 16320
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		Scanner sc = new Scanner(System.in);

		while (true) {
			int m = sc.nextInt();
			int d = sc.nextInt();
			if (m == 0 || d == 0) break;
			String ans = yoobi( sumofdays(m, d) );
			System.out.println(ans);
		}
	}

	// 1???1??\??????????????????m????????\?????§?????\??°
	private static int sumofdays(int m) {
		if (m == 0) return 0;
		switch (m) {
		case 2:
			return sumofdays(m-1) + 29;
		case 4:
		case 6:
		case 9:
		case 11:
			return sumofdays(m-1) + 30;
		default:
			return sumofdays(m-1) + 31;
		}
	}

	// 1???1??\??????m???d??\?????§?????\??°
	public static int sumofdays(int m, int d) {
		return sumofdays(m-1) + d;
	}

	public static String yoobi(int d) {
		int r = d % 7;
		switch (r) {
		case 1:
			return "Thursday";
		case 2:
			return "Friday";
		case 3:
			return "Saturday";
		case 4:
			return "Sunday";
		case 5:
			return "Monday";
		case 6:
			return "Tuesday";
		default :
			return "Wednesday";
		}
	}
}

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

int main() {
  int a,b,ret,i;
  i=0;
  ret = 0;
  cin >> a >> b;
  for(int i=0;i<2;i++){
  if(a <= b){
    ret += b;
  	b-=1;
  }
  else{
    ret += a;
  	a-=1;
  }
  }
  cout << ret << endl;
}


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

using namespace std;

int sign(long sum)
{
  if (sum == 0) return sum;
  return sum > 0 ? 1 : -1;
}

long solve(const vector<int>& a, int init)
{
  int _s = init;
  long op = 0;
  long sum = 0;
  for(int i = 0; i < a.size(); ++i) {
    sum += a[i];
    int s = sign(sum);
    // cerr << "a[" << i << "]: " << a[i] << " " << _sum << "|" << _s << " " << sum << "|" << s << endl;
    if (_s * s >= 0) {
      if (_s > 0) {
        op += sum + 1;
        sum = -1;
      } else {
        op += (1 - sum);
        sum = 1;
      }
    }
    _s *= -1;
  }
  return op;
}

int main()
{
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) cin >> a[i];
  cout << min(solve(a, 1), solve(a, -1)) << endl;
  return 0;
}

Measured memory_bytes: 640
n,m = map(int,input().split())
A = []
for i in range(m):
        A.append(input().split()[1:])
P = [int(i) for i in input().split()]
ans = 0
for i in range(2**n):
        count = [0] * m
        a = len(bin(i))-2
        for j in bin(i)[2:]:
                if int(j) == 1:
                        for k in range(m):
                                if str(a) in A[k]:
                                        count[k]+=1
                a-=1
        count = [i%2 for i in count]
        if count == P:
                ans += 1
print(ans)


Measured memory_bytes: 3064
import sys
 
while True:
    n = int(sys.stdin.readline().rstrip())
    if n == 0:
        break;
    dic = {}
    for i in range(n):
        k,v = sys.stdin.readline().rstrip().split(' ')
        dic[k] = v
    n = int(sys.stdin.readline().rstrip())
    ret = []
    for i in range(n):
        d = sys.stdin.readline().rstrip()
        if d in dic.keys():
            ret.append(dic[d])
        else:
            ret.append(d)
    print(''.join(ret))

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

#define FOR(i, a, b) for(int i = a; i < b; ++i)
#define REP(i, n) FOR(i, 0, n)
#define _ << " " <<
#define sz(x) ((int) x.size())
#define pb(x) push_back(x)
typedef long long ll;
typedef pair<int, int> point;

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


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

using namespace std;

const int MAXN=100000+10000;
const int INF=0x3f3f3f3f;
int hgt[MAXN],dp[MAXN];
int n,k;

int main(){
	memset(dp,INF,sizeof(dp));
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++){
		scanf("%d",&hgt[i]);
	}
	
	dp[1]=0;
	for(int i=2;i<=n;i++){
		for(int j=max(1,i-k);j<i;j++){
			dp[i]=min(dp[i],dp[j]+abs(hgt[i]-hgt[j]));
		}
	}
	printf("%d\n",dp[n]);
	return 0;
}
 

Measured memory_bytes: 1024
// C++ implementation of the approach 
#include <bits/stdc++.h> 
using namespace std; 

// Function to find special numbers 
int divisibilityCheck(int arr[], int n) 
{ 

	// Storing all array elements in a hash 
	// and finding maximum element in the array 
	unordered_set<int> s; 
	int max_ele = INT_MIN; 
	for (int i = 0; i < n; i++) { 
		s.insert(arr[i]); 

		// Update the maximum element of the array 
		max_ele = max(max_ele, arr[i]); 
	} 

	// Traversing the array elements and storing the array 
	// multiples that are present in s in res 
	unordered_set<int> res; 
	for (int i = 0; i < n; i++) { 

		// Check for non-zero values only 
		if (arr[i] != 0) { 

			// Checking the factors of current element 
			for (int j = arr[i] * 2; j <= max_ele; j += arr[i]) { 

				// If current factor is already part 
				// of the array then store it 
				if (s.find(j) != s.end()) 
					res.insert(j); 
			} 
		} 
	} 

	// For non-distinct elmments 
	// To store the frequency of elements 
	unordered_map<int, int> mp; 
	for (int i = 0; i < n; i++) 
		mp[arr[i]]++; 

	unordered_map<int, int>::iterator it; 
	vector<int> ans; 
	for (it = mp.begin(); it != mp.end(); it++) { 

		// If frequency is at least 2 
		if (it->second >= 2) { 
			if (res.find(it->first) == res.end()) { 

				// If frequency is greater than 1 and 
				// the number is not divisible by 
				// any other number 
				int val = it->second; 

				// Then we push the element number of 
				// times it is present in the vector 
				while (val--) 
					ans.push_back(it->first); 
			} 
		} 

		// If frequency is greater than 1 and the number 
		// is divisible by any other number 
		if (res.find(it->first) != res.end()) { 
			int val = it->second; 

			// Then we push the element number of 
			// times it is present in the vector 
			while (val--) 
				ans.push_back(it->first); 
		} 
	} 

	// Print the elements that are divisible by 
	// at least one other element from the array 
	int xx = ans.size() ;
	return xx ;
} 

// Driver code 
int main() 
{ 
	int n ;
	cin >> n ;
	int arr[n] ;
	for(int i=0; i<n; i++) {
		cin >> arr[i] ;
	}
	int hh = divisibilityCheck(arr, n); 
	cout << n-hh << "\n" ;
	return 0; 
} 


Measured memory_bytes: 30672
import sys
 
def main():
    input = sys.stdin.readline
    A, B = map(int, input().split())
 
    A, B = max(A, B), min(A, B)
    if A == B:
        return 2 * A
    else:
        return 2 * A - 1
 
 
if __name__ == '__main__':
    print(main())

Measured memory_bytes: 3060
import numpy as np
if __name__ == "__main__":
    N=input()
    N=int(N)
    strs=["AC","WA","TLE","RE"]
    cnt=np.zeros(4,dtype=np.uint32)
    for i in range(N):
        b=input()
        for j,s in enumerate(strs):
            if s==b:
                cnt[j]+=1
    for i,s in enumerate(strs):
        print(s+" x "+str(cnt[i]))

Measured memory_bytes: 26824
#include<bits/stdc++.h>
using namespace std;
using i64 = int_fast64_t;
#define rep(i, N) for(int (i) = 0; (i) < (N); (i)++)
#define all(v) (v).begin(), (v).end()
#define eb emplace_back

int main(){
    i64 N;
    cin >> N;
    vector<i64> p, m;
    rep(i, N){
        i64 a; cin >> a;
        if(a > 0) p.emplace_back(a);
        else m.emplace_back(a);
    }

    sort(p.rbegin(), p.rend());
    sort(all(m));

    if(p.size() == 0) {
        p.emplace_back(m[m.size() - 1]);
        m.pop_back();
    }
    if(m.size() == 0) {
        m.emplace_back(p[p.size() - 1]);
        p.pop_back();
    }
    
    i64 M = 0;
    for(auto& a : p) M += a;
    for(auto& a : m) M -= a;

    stack<i64> stk;
    stk.emplace(m[m.size() - 1]);

    cout << M << endl;
    i64 x, y;
    rep(i, p.size() - 1){
        x = stk.top(); stk.pop();
        y = p[i];
        cout << x << " " << y << endl;
        stk.emplace(x - y);
    }

    x = p[p.size() - 1];
    y = stk.top(); stk.pop();
    cout << x << " " << y << endl;
    stk.emplace(x - y);

    rep(i, m.size() - 1){
        x = stk.top(); stk.pop();
        y = m[i];
        cout << x << " " << y << endl;
        stk.emplace(x - y);
    }
}

Measured memory_bytes: 2804
#include<bits/stdc++.h>
using namespace std;
#define FOR(i, s, e) for(int i = (s); i < (e); i++)
#define FOE(i, s, e) for(int i = (s); i <= (e); i++)
#define FOD(i, s, e) for(int i = (s); i >= (e); i--)
#define ll long long

char s[100005];
int n, ans;

int main ()
{
	scanf("%s", s);
	n = strlen(s);
	FOR(i, 1, n) if (s[i] != s[i - 1]) ans++;
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 384
N = int(input())
S = []
for i in range(N):
    S.append(input())

print("AC x {}".format(S.count("AC")))
print("WA x {}".format(S.count("WA")))
print("TLE x {}".format(S.count("TLE")))
print("RE x {}".format(S.count("RE")))


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

#define ll long long int
#define watch(x) cout << (#x) << " is " << (x) << endl
#define f(i,x,n)  for(int i=x;i<n;i++)
#define FASTIO cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false);
#define eb(x) emplace_back(x)
#define mp(a,b) make_pair(a,b)
#define sz(a) int((a).size())
#define mod 1000000007
#define tr(c,i) for(typeof((c)).begin() i = (c).begin(); i != (c).end(); i++)
#define inf LLONG_MAX
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }


void seethis(vector<ll>vect)
{
    for(ll x:vect)
        cout<<x<<" ";
    cout<<"\n";
}

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}
//LCM
int lcm(int a, int b) {  return a * (b / __gcd(a, b)); }

//For sort by second
bool cmp(const pair<int,int> &a)
{ return a.first<a.second; }

//Tree
/* const int MAXN = 1e5 + 5;
vector<ll> adj[MAXN];*/

//ModPower
ll modpower(ll a,ll b,ll c)
{
	ll res=1;
	while(b)
	{
		if(b&1LL)
			res=(res*a)%c;
		a=(a*a)%c;
		b>>=1;
	}
	return res;
}

int main()
{
	FASTIO;
	/*#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif*/
	int n;
	  cin>>n;
	  vector<int>vect(n+1);


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

	  }


	  for(int i=1;i<n;i++)
	  {
	  	if(vect[i]!=i)
	  	{
	  		swap(vect[i],vect[vect[i]]);
	  		break;
	  	}

	  }
	  bool poss=true;
	  for(int i=1;i<=n;i++)
	  {
	  	if(vect[i]!=i){

	  		poss=false;
	  		break;
	  	}
	  }

	  if(poss)
	  	cout<<"YES\n";
	  else
	  	cout<<"NO\n";


	
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using static Atcoder;
using System.Threading.Tasks;
using System.ComponentModel;

public class Hello
{

    public static void Main()
    {
        int[] num = SpRead(' ').Select(a => int.Parse(a)).ToArray();
        int b = num[0];
        int color = num[1];
        int ans = color;
        for (int i = 1; i < b; i++) {
            ans *= (color - 1);
        }
        Console.WriteLine(ans);
    }
}



public class Atcoder
{
    static void Swap<T>(ref T a, ref T b)
    {
        var t = a;
        a = b;
        b = t;
    }
    public static int LCM(int a, int b)
    {
        int c = a * b;
        if (a < b) Swap(ref a, ref b);
        int d = a % b;
        while (d != 0)
        {
            a = b;
            b = d;
            d = a % b;
        }
        return c / b;
    }
    public static string strReverce(string s)
    {
        return new string(s.Reverse().ToArray());
    }
    public static int Cin()
    {
        return int.Parse(Console.ReadLine());
    }
    public static bool IsPrime(int n)
    {
        if (n < 2) return false;
        if (n == 2) return true;
        if (n % 2 == 0) return false;

        //double sqrtNum = Math.Sqrt(n);
        for (int i = 3; i < n; i += 2)
        {
            if (n % i == 0) return false;
        }
        return true;
    }
    public static string[] SpRead(char c)
    {
        return Console.ReadLine().Split(c);
    }
}


Measured memory_bytes: 11348
#include<iostream>
#include<vector>
#include<stack>
using namespace std;
static const int MAX = 100000;
static const int NIL = -1;

int n;
vector<int>G[MAX];
int color[MAX];

void dfs(int r, int c) {
	stack<int>S;
	S.push(r);
	color[r] = c;
	while (!S.empty()) {
		int u = S.top(); S.pop();
		for (int i = 0; i < G[u].size(); i++) {
			int v = G[u][i];
			if (color[v] == NIL) {
				color[v] = c;
				S.push(v);
			}
		}
	}
}

void assignColor() {
	int id = 1;
	for (int i = 0; i < n; i++)color[i] = NIL;
	for (int u = 0; u < n; u++) {
		if (color[u] == NIL)dfs(u, id++);
	}
}
int main() {
	int s, t, m, q;
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		cin >> s >> t;
		G[s].push_back(t);
		G[t].push_back(s);
	}
	assignColor();
	cin >> q;
	for (int i = 0; i < q; i++) {
		cin >> s >> t;
		if (color[s] == color[t]) {
			cout << "yes" << "\n";
		}else {
			cout << "no" << "\n";
		}
	}
	return 0;
}

Measured memory_bytes: 8948