akhauriyash/Code-Regression huggingface dataset:
from itertools import permutations

def warshall_floyd(d):
    for k in range(N):
        for i in range(N):
            for j in range(N):
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
    return d

N,M,R = map(int,input().split())
town = list(map(int,input().split()))
street = [list(map(int,input().split())) for _ in range(M)]
distance = [[float("inf") for _ in range(N)] for _ in range(N)]
distance_in_town = [[0 for _ in range(R)] for _ in range(R)]
permutations_r = list(permutations(range(R)))
min_distance = float('inf')

for i in range(N):
    for j in range(N):
        if i==j:
            distance[i][j]=0

for s in street:
    distance[s[0]-1][s[1]-1] = s[2]
    distance[s[1]-1][s[0]-1] = s[2]

warshall_floyd(distance)

k = 0
for i in range(N):
    if i+1 in town:
        l = 0
        for j in range(N):
            if j+1 in town:
                distance_in_town[k][l] = distance[i][j]
                l += 1
        k += 1
        
for p in permutations_r:
    total_distance = 0
    for i in range(R-1):
        total_distance += distance_in_town[p[i]][p[i+1]]
    min_distance = min(min_distance,total_distance)

print(min_distance)

Measured memory_bytes: 64216
#include <iostream>

using namespace std;

int main(){
  int n;
  char m[1000][1001];
  while(cin>>n&&n){
    int a=0;
    for(int i=0;i<n;++i) cin>>m[i];
    for(int i=0;i<=n-a;++i){
      for(int j=0;j<=n-a;++j){
	if(m[i][j]=='.'){
	  bool f=true;
	  for(int k=1;f&&i+k<=n&&j+k<=n;++k){
	    for(int l=0;l<=k;++l){
	      if(m[i+l][j+k]!='.'){
		a=max(a,k);j+=k;f=false;break;
	      }
	      if(m[i+k][j+l]!='.'){
		a=max(a,k);j+=l;f=false;break;
	      }
	    }
	  }
	}
      }
    }
    cout<<a<<endl;
  }
  return 0;
}

Measured memory_bytes: 2140
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int descending_compare(const void *a, const void *b){
    if (*(int*)a > *(int*)b){
        return -1;
    }else if (*(int*)a == *(int*)b){
        return 0;
    }else{
        return 1;
    }
}

int ascending_compare(const void *a, const void *b){
    if (*(int*)a < *(int*)b){
        return -1;
    }else if (*(int*)a == *(int*)b){
        return 0;
    }else{
        return 1;
    }
}


int lower_bound(int *a, int n, int key){
    int left, mid, right;
    left = 0, right = n;
    mid = (left + right)/2;
    while ((left+1 != mid || mid+1 != right) && mid != left){
        if (key > a[mid]){
            left = mid;
        }else{
            right = mid+1;
        }
        mid = (left + right)/2;
    }
    if (a[left] >= key)return left;
    if (a[mid] >= key)return mid;
    if (a[right] >= key)return right;
    return n;
}

//greatest common divisor
unsigned long  gcd(unsigned long x, unsigned long y){
    if (y == 0){ 
        return x;
    }else if (x > y){
        return gcd(y, x % y);
    }else{
        return gcd(x, y % x);
    }
}



long long factorial(int x){
    long long rtn = 1;
    int i;
    for (i = x; i > 1; i--){
        rtn = (rtn*i);
    }
    return rtn;
}

int main(void){
    int a, b;
    int cnt = 0;
    int tmp;
    scanf("%d %d", &a, &b);
    
    tmp = b;
    while (tmp != 0){
        tmp /= 10;
        cnt++;
    }
    for (int i = 0; i < cnt; i++){
        a *= 10;
    }
    for (int i = 1; i <= a+b; i++){
        if (i*i == a+b){
            printf("Yes\n");
            return 0;
        }
    }

    printf("No\n");

    return 0;
}


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

int n;
struct elem{
    int x, p;
} a[100005];
inline bool cmp(elem x, elem y){
    return x.x < y.x;
}
inline void read(){
    scanf("%d", &n);
    for(int i = 1; i <= n ; ++i)
        scanf("%d", &a[i].x), a[i].p = i;
}
inline void solve(){
    sort(a + 1, a + n + 1, cmp);
    int Sol = 0;
    for(int i = 1; i <= n ; ++i){
        int d = abs(a[i].p - i);
        if(d % 2 == 1) ++ Sol;
    }
    printf("%d", Sol / 2);
}
int main()
{
    read();
    solve();
    return 0;
}


Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in)) {
            int a = sc.nextInt();
            int b = sc.nextInt();
            int c = sc.nextInt();
            int d = sc.nextInt();

            if (Math.abs(a - c) <= d || (Math.abs(a - b) <= d && Math.abs(b - c) <= d)) {
                System.out.println("Yes");
            } else {
                System.out.println("No");
            }
        }
    }

}


Measured memory_bytes: 21972
program main;
var 
    a,b,c : integer;
begin 
    readln(a,b,c);
    if (( a = b ) and ( a <> c )) or (( a = c ) and ( a <> b )) or (( b = c ) and ( b <> a )) then
        writeln('Yes') 
    else 
        writeln('No');
end.

Measured memory_bytes: 1376
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<tuple>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define Per(i,sta,n) for(int i=n-1;i>=sta;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;

int a[200010],n;

void solve(){
    cin >> n;
    rep(i,n){
        cin >> a[i];
    }
    sort(a,a+n);
    rep(i,n-1){
        if(a[i]==a[i+1]) {
            cout << "NO" << endl;
            return;
        }
    }
    cout << "YES" << endl;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(50);
    solve();
}

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

using namespace std;

typedef pair<int, int> P;
typedef long long ll;
#define rep(i, n) for(int i=0;i<n;i++)
#define rep2(i, m, n) for(int i=m;i<n;i++)
#define rrep(i, n, m) for(int i=n;i>=m;i--)
using Graph = vector<vector<int>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const ll MOD = 1000000007;
#ifdef __DEBUG

#include "cpp-pyprint/pyprint.h"

#endif

void dfs2(Graph &g, vector<ll> &cnt, int start,  int tar, vector<int>& plus, int t) {
    cnt[tar] += plus[tar] + t;
    for (auto &v: g[tar]) {
        if (v == start) continue;
        dfs2(g, cnt, tar, v, plus, cnt[tar]);
    }
}

void Main() {
    int N, Q;
    cin >> N >> Q;
    Graph G(N);
    for (int i = 0; i < N - 1; ++i) {
        int a, b;
        cin >> a >> b;
        G[a - 1].push_back(b - 1);
        G[b - 1].push_back(a - 1);

    }
    vector<ll> cnt(N, 0);
    vector<int> plus(N, 0);
    for (int i = 0; i < Q; ++i) {
        int p, x;
        cin >> p >> x;
        p--;
        plus[p] += x;
    }
    dfs2(G, cnt,   -1, 0, plus, 0);
    for (int i = 0; i < N; ++i) {
        cout << cnt[i] << " ";
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
}


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

typedef long long ll;
#define pii pair<int , int>
#define _FastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MAXX 100005

ll n , s;
ll a[MAXX];
ll x[MAXX];

int main()
{
    _FastIO;
    cin >> n;
    for(ll i = 0; i < n; i++){
        cin >> a[i];
        s += a[i];
    }
    x[0] = s;
    for(ll i = 1; i < n - 1; i += 2){
        x[0] -= (2 * a[i]);
    }
    for(ll i = 1; i < n; i++){
        x[i] = 2 * a[i - 1] - x[i - 1];
    }
    for(ll i = 0; i < n; i++){
        cout << x[i] << " ";
    }
    cout << endl;
    return 0;
}


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

using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
#define REP(i,n) for(ll i = 0;i < (ll)n;i++)
#define REPD(i,n) for(ll i = (ll)n - 1;i >= 0;i--)
#define ALL(x) (x).begin(),(x).end()
#define FILLl(n,first_dimension_size,value) fill((ll*)n,(ll*)(n+first_dimension_size),value)
#define FILL(n,first_dimension_size,value) fill((int*)n,(int*)(n+first_dimension_size),value)
#define INF (1 << 29)
#define MOD 1000000007
//int dx[4] = {1,0,0,-1};
//int dy[4] = {0,1,-1,0};

class UnionFind{
  public:
  vector<int> par;
  UnionFind(int size) : par(size,-1){}
  bool unite(int x,int y){
    x = root(x),y = root(y);
    if(x == y)return false;
    if(par[y] < par[x])swap(x,y);
    par[x] += par[y];
    par[y] = x;
    return true;
  }
  bool find(int x,int y){
    return root(x) == root(y);
  }
  int root(int x){
    return par[x] < 0 ? x : par[x] = root(par[x]);
  }
  int size(int x){
    return -par[root(x)];
  }
};

int main(){

  int n,m,res = 0;
  cin >> n >> m;
  vector<int> p(n);
  REP(i,n)cin >> p[i];
  UnionFind uf(n);
  REP(i,m){
    int x,y;cin >> x >> y;
    x--,y--;
    uf.unite(x,y);
  }
  REP(i,n){
    if(uf.find(i,p[i]-1))res++;
  }
  cout << res << endl;

  return 0;
}

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

void solve(){
	
	int n,m ;
	cin>>n>>m ;

	int l=1 ;
	int r=n ;	

	rep(i,m){
		int x,y ;
		cin>>x>>y ;
		l=max(l,x) ;
		r=min(r,y) ;
 	}	

 	int count=0 ;
 	for(int i=l;i<=r;i++)
 	{
 		count++ ;
 	}

 	cout<<count ;
}



int main(){

	int y ;

	y=1 ;
	//cin>>y ;

	while(y--)
	{	
		solve() ;
	}

}

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

using namespace std;
using ll = long long;

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

  int n;
  ll d;
  cin >> n >> d;
  int ans = 0;
  for (int i = 0; i < n; i++) {
    ll x, y;
    cin >> x >> y;
    double dist = sqrt(x * x + y * y);
    if (dist <= d)
      ans++;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3700
#include <iostream>
#include <cstdio>
#include <string>

using namespace std;
static const int M = 22370000;
bool Hash[M];

inline int convertChartoNum(char c)
{
	if (c == 'A')
	{
		return(1);
	}
	else if (c == 'C')
	{
		return(2);
	}
	else if (c == 'G')
	{
		return(3);
	}
	else if (c == 'T')
	{
		return(4);
	}
}

inline int getKey(string s)
{
	int sum = 0;
	int p = 1;
	for (int i = 0; i < s.size(); ++i)
	{
		sum += p * convertChartoNum(s[i]);
		p *= 4;
	}
	return(sum);
}

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

	int n;
	cin >> n;
	for (int i = 0; i < n; ++i)
	{
		string command, str;
		cin >> command >> str;
		int key = getKey(str);
		if (command[0] == 'i')
		{
			if (!Hash[key])
			{
				Hash[key] = true;
			}
		}
		else
		{
			if (Hash[key])
			{
				printf("yes\n");
			}
			else
			{
				printf("no\n");
			}
		}
	}
}

int main()
{
	solve();
	return(0);
}

Measured memory_bytes: 2576
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <iomanip>
#include <numeric>
 
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
typedef struct{
    ll a,b,c;
}T;
using P = pair<int,int>;
ll N,K,H,W;
ll ans;
ll A[200005];
ll B[200005];
ll C[200005];
string S;
ll M = 1000000007;
ll cnt;
ll a;
ll b;
bool operator< (const T &T1, const T &T2){
    return T2.a < T1.a;
};
priority_queue<T> s;

int main() {
    cin >> N;
    cin >> S;
    for(int i=0;i<N;i++){
        if(S[i]=='1'){
            A[i] = 1;
        }
        if(A[i]==1){
            cnt++;
        }
    }
    T t;
    t.a=0;
    t.b=0;
    t.c=1;
    s.push(t);
    t.a=1;
    t.b=1;
    t.c=1;
    s.push(t);
    ll n = 20;
    while(!s.empty()){
        T p = s.top();
        s.pop();
        if(p.c>=n){
            continue;
        }
        if(p.b!=0){
          if(p.a<=200005){
            B[p.a] = B[p.a%p.b] + 1;
          }
        }
        t.a=p.a + (1<<p.c);
        t.b=p.b + 1;
        t.c=p.c + 1;
        s.push(t);
        t.a=p.a;
        t.b=p.b;
        t.c=p.c + 1;
        s.push(t);
    }
    ll k=1;
    ll l=1;
    for(ll i=N-1;i>=0;i--){
        if(cnt > 1){
            a = (a + k*A[i])%(cnt-1);
            k = (k*2)%(cnt-1);
        }
        b = (b+l*A[i])%(cnt+1);
        l = (l*2)%(cnt+1);
    }

    k=1;
    l=1;
    for(ll i=N-1;i>=0;i--){
        if(A[i]==0){
            C[i] =  B[(b+l)%(cnt+1)];
        }
        else{
            if(cnt > 1){
            C[i] = B[(a-k+cnt-1)%(cnt-1)];
            }else{
                C[i] = -1;
            }
        }
        if(cnt > 1){
        k = (k*2)%(cnt-1);
        }
        l = (l*2)%(cnt+1);
    }
    for(int i=0;i<N;i++){
        cout << C[i] +1<< endl;
    }
    
}


Measured memory_bytes: 31132
#include <stdio.h>
 
int main(void){
  int K, S, count, i, j, k;
  scanf("%d", &K);
  scanf("%d", &S);
  for(i=0; i<=K; i++){
    for(j=0; j<=K; j++){
      if(i+j<=S && S-i-j <= K) count++;
    }
  }
  printf("%d", count);
}

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

using namespace std;

int main(){
  int a,b;
  cin >> a >> b;
  cout << "100 100" << endl;
  for (int j=0;j<100;j++) {
    cout << "#";
  }
  cout << endl;
  int i = 1;
  while (i < 99 && a>1) {
    for (int j=0;j<100;j++) {
      if ((i+j)%3==1 && a>1) {
	cout << ".";
	a--;
      } else {
	cout << "#";
      }
    }
    cout << endl;
    i++;
  }
  i += 2;
  for (int j=0;j<100;j++) {
    cout << "#";
  }
  cout << endl;
  for (int j=0;j<100;j++) {
    cout << ".";
  }
  cout << endl;
  b--;
  while (i < 99) {
    for (int j=0;j<100;j++) {
      if ((i+j)%3==1 && b>0) {
	cout << "#";
	b--;
      } else {
	cout << ".";
      }
    }
    cout << endl;
    i++;
  }
  for (int j=0;j<100;j++) {
    cout << ".";
  }
  cout << endl;
  return(0);
}


Measured memory_bytes: 256
/**
 *    Coded by : lucky_21
 *               --------Lokesh Singh
**/

#include<bits/stdc++.h>
using namespace std;

#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<class T> using oset=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

#define     F           first
#define     S           second
#define     pb          push_back
#define     lb          lower_bound
#define     ub          upper_bound
#define     pii         pair<int,int>
#define     all(x)      x.begin(),x.end()
#define     fix         fixed<<setprecision(10)
#define     rep(i,a,b)  for(int i=int(a);i<=int(b);i++)
#define     repb(i,b,a) for(int i=int(b);i>=int(a);i--)
#define     FastIO      ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)

typedef double db;
typedef long long ll;

const int N=2e5+5;
const int mod=1e9+7;

signed main(){
    FastIO;
    string s;
    cin>>s;
    ll ans=0;
    int dp[2020]{0};
    dp[s[0]-'0']=1;
    rep(i,1,s.size()-1){
        int n=s[i]-'0';
        int tdp[2020]{0};
        tdp[n]=1;
        rep(j,0,2018) if(dp[j]){
            int rem=(j*10+n)%2019;
            ans+=(!rem?dp[j]:0);
            tdp[rem]+=dp[j];
        }
        rep(j,0,2018) dp[j]=tdp[j];
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 3764
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
typedef long long ll;
int main() {
  int n;
  cin >> n;
  map<string,int> mp;
  rep(i,n){
    string s;
    cin >> s;
    sort(s.begin(),s.end());
    mp[s]++;
  }
  ll ans = 0;
  for(auto& p: mp){
    int s = p.second;
    ans += (ll) s * (s-1)/2;
  }
  cout << ans << endl;
    
  return 0;
}

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

public class Main {


    public Main(FastScanner in, PrintWriter out, int test) {
        int N = in.nextInt();

        long sum = 0;
        Map<Integer, Integer> freq = new HashMap<>();
        for (int i = 0; i < N; i++) {
            int x = in.nextInt();
            sum += x;
            freq.merge(x, 1, Integer::sum);
        }

        int Q = in.nextInt();
        for (int q = 0; q < Q; q++) {
            int b = in.nextInt(), c = in.nextInt();
            int m = freq.getOrDefault(b, 0);
            sum += 1L * (c - b) * m;
            if (m != 0) {
                freq.remove(b);
                freq.merge(c, m, Integer::sum);
            }
            out.println(sum);
        }
    }

    public static void main(String[] args) {
        PrintWriter out = new PrintWriter(System.out);
        // Scanner in = new Scanner(
                // new BufferedReader(new InputStreamReader(System.in)));
        FastScanner in = new FastScanner(System.in);

        // int T = in.nextInt();
        for (int t = 1; t <= 1; t++) {
            Main sol = new Main(in, out, t);
        }

        out.close();
    }
}


class FastScanner{
    private InputStream stream;
    private byte[] buf = new byte[1024];
    private int curChar;
    private int numChars;

    public FastScanner(InputStream stream)
    {
        this.stream = stream;
    }

    int read()
    {
        if (numChars == -1)
            throw new InputMismatchException();
        if (curChar >= numChars){
            curChar = 0;
            try{
                numChars = stream.read(buf);
            } catch (IOException e) {
                throw new InputMismatchException();
            }
            if (numChars <= 0)
                return -1;
        }
        return buf[curChar++];
    }

    boolean isSpaceChar(int c)
    {
        return c==' '||c=='\n'||c=='\r'||c=='\t'||c==-1;
    }

    boolean isEndline(int c)
    {
        return c=='\n'||c=='\r'||c==-1;
    }

    int nextInt()
    {
        return Integer.parseInt(next());
    }

    long nextLong()
    {
        return Long.parseLong(next());
    }

    double nextDouble()
    {
        return Double.parseDouble(next());
    }

    String next(){
        int c = read();
        while (isSpaceChar(c))
            c = read();
        StringBuilder res = new StringBuilder();
        do{
            res.appendCodePoint(c);
            c = read();
        }while(!isSpaceChar(c));
        return res.toString();
    }

    String nextLine(){
        int c = read();
        while (isEndline(c))
            c = read();
        StringBuilder res = new StringBuilder();
        do{
            res.appendCodePoint(c);
            c = read();
        }while(!isEndline(c));
        return res.toString();
    }
}

Measured memory_bytes: 59388
package main

import (
	"bufio"
	"fmt"
	"log"
	"math"
	"os"
	"strconv"
)

func main() {
	N := nextInt()
	var y float64
	for i := 0; i < N; i++ {
		x := nextFloat64()
		u := nextString()
		if u == "JPY" {
			y += x
		} else {
			y += x * 380000.0
		}
	}
	fmt.Println(y)
}

var dy = []int{1, 0, -1, 0, 0}
var dx = []int{0, 1, 0, -1, 0}
var inf = int(1e9)

func fill(a *[]int, n int) {
	for i := 0; i < len(*a); i++ {
		(*a)[i] = n
	}
}

func makeDoubleSlice(n int, m int) [][]int {
	s := make([][]int, n)
	for i := 0; i < n; i++ {
		s[i] = make([]int, m)
	}
	return s
}

func pow(a, b int) int {
	return int(math.Pow(float64(a), float64(b)))
}

func lcm(a, b int) int {
	return a * b / gcd(a, b)
}
func gcd(a, b int) int {
	if a < b {
		a, b = b, a
	}
	for b != 0 {
		a, b = b, a%b
	}
	return a
}
func max(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r < a[i] {
			r = a[i]
		}
	}
	return r
}
func min(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r > a[i] {
			r = a[i]
		}
	}
	return r
}
func sum(a []int) (r int) {
	for i := range a {
		r += a[i]
	}
	return r
}
func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

type pair struct {
	a, b int
}

type pairs []pair

func (p pairs) Len() int {
	return len(p)
}
func (p pairs) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

func (p pairs) Less(i, j int) bool {
	if p[i].a == p[j].a {
		return p[i].b < p[j].b
	}
	return p[i].a < p[j].a
}

var nextReader func() []byte

func init() {
	nextReader = newScanner()
	log.SetFlags(log.Lshortfile)
}

func newScanner() func() []byte {
	r := bufio.NewScanner(os.Stdin)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)
	return func() []byte {
		r.Scan()
		return r.Bytes()
	}
}
func nextBytes() []byte {
	return nextReader()
}

func nextString() string {
	return string(nextReader())
}
func nextInt64() int64 {
	v, _ := strconv.ParseInt(string(nextReader()), 10, 64)
	return v
}
func nextInt() int {
	v, _ := strconv.Atoi(string(nextReader()))
	return v
}
func nextInts(n int) []int {
	r := make([]int, n)
	for i := 0; i < n; i++ {
		r[i] = nextInt()
	}
	return r
}
func nextFloat64() float64 {
	f, _ := strconv.ParseFloat(string(nextReader()), 64)
	return f
}


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

int main(){
  string S;
  cin >> S;
  if(S == "RRR"){
    cout << 3 << endl;
  }else if(S == "RRS" || S== "SRR"){
    cout << 2 << endl;
  }else if(S == "SSS"){
    cout << 0 << endl;
  }else{
    cout << 1 << endl;
  }
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
typedef long long int lli;
typedef unsigned long long int ulli;
typedef long double ldb;
 
#define endl '\n'
#define loop(i, m, n) for (lli i = m; i < n; i++)
#define loope(i, m, n) for (lli i = m; i <= n; i++)
#define epool(i, m, n) for (lli i = m; i >= n; i--)
#define pool(i,m,n) for(lli i=m; i>n; i++)
#define maxe *max_element
#define mine *min_element
#define plli pair<lli, lli>
#define mod 1000000007
#define mod2 998244353
#define vt vector<lli>
#define fi first
#define se second
#define pb push_back
#define umap unordered_map
#define mmap multimap
#define mp make_pair
#define inp1(a) cin >> a
#define inp2(a, b) cin >> a >> b
#define inp3(a, b, c) cin >> a >> b >> c
#define inp4(a, b, c, d) cin >> a >> b >> c >> d
#define inp5(a, b, c, d, e) cin >> a >> b >> c >> d >> e
#define inp6(a, b, c, d, e, f) cin >> a >> b >> c >> d >> e >> f
#define pr0() cout << " "
#define pr1(a) cout << a << " "
#define pr2(a, b) cout << a << " " << b << " "
#define pr3(a, b, c) cout << a << " " << b << " " << c << " "
#define pr4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << " "
#define emp emplace //used to push a pair etc..
#define empf emplace_front
#define empb emplace_back
#define ret(x) return cout << x, 0;
#define all(v) v.begin(),v.end()
#define present(s,x) (s.find(x) != s.end())
#define cpresent(s,x) (find(all(s),x) != s.end())
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
//especially for deque both sides dynamic
#define pf push_front
//list doubly linked lists can insert at mid. splice fn can be used
#define fast_io                       \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
using namespace std;
 
lli gcd(lli a, lli b){
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
 
lli lcm(lli a, lli b){
    return (a * b) / gcd(a, b);
}
 
lli modi(lli n,lli m=mod){ 
    if(n==0) return 0;
    n%=m;
    n+=m;
    n%=m;
    return n;
}
 
lli mpow(lli base, lli exp){
    base %= mod;
    lli result = 1;
    while (exp > 0){
        if (exp & 1)
            result = ((lli)result * base) % mod;
        base = ((lli)base * base) % mod;
        exp >>= 1;
    }
    return result;
}
const lli INF=1e18;
const lli N=2e5+5;
lli a[N]={0},b[N]={0};

int32_t main(){
    fast_io
    lli i = 0,j=0;
//    freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);
    
    string s;
    cin >> s;
    if(s.size()>=6 && s[2]==s[3] && s[4]==s[5]) cout << "Yes";
    else cout << "No";
    

}

Measured memory_bytes: 256
#include<cstdio>

int main(){
	int t;
	while(scanf("%d", &t) + 1){
		int a[14] = {};
		int b[5] = {};
		a[t]++;
		for(int i = 0; i < 4; i++){
			scanf(",%d", &t);
			a[t]++;
		}
		t = 0;
		for(int i = 1; i < 14; i++){
			if(a[i]){
				t++;
			}else{
				t = 0;
			}

			b[a[i]]++;
			if(t == 5){
				printf("straight\n");
				break;
			}
		}
		if(t == 4 && a[1]){
			printf("straight\n");
		}else{
			if(b[4]){
				printf("four card\n");
			}else if(b[3]){
				if(b[2]){
					printf("full house\n");
				}else{
					printf("three card\n");
				}
			}else if(b[2]){
				if(b[2] -1){
					printf("two pair\n");
				}else{
					printf("one pair\n");
				}
			}else{
				if(t != 5){
					printf("null\n");
				}
			}
		}
	}
}

Measured memory_bytes: 1008
N = int(input())
T, A = map(int, input().split())
H = list(map(int, input().split()))

avg = [T - H[i] * 0.006 for i in range(N)]
diff = [abs(avg[i] - A) for i in range(N)]
idx = diff.index(min(diff))
print(idx + 1)

Measured memory_bytes: 3060
import java.util.HashSet;
import java.util.Scanner;

public class Main {
	

	
	
	
	public static void main(String[] args) {
		
		Scanner s = new Scanner(System.in);
		int x = s.nextInt();
		int n = s.nextInt();
		
		HashSet<Integer> h = new HashSet<>();
		while(n--!=0) {
			h.add(s.nextInt());
		}
		
		int t=0;
		while(h.contains(x-t) && h.contains(x+t)) {
			t++;
		}
		
		if(!h.contains(x-t)) {
			System.out.println(x-t);
		}
		else if(!h.contains(x+t)) {
			System.out.println(x+t);
		}
	}
}

Measured memory_bytes: 35820
#include<cstdio>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<string>
using namespace std;

struct Node{
	int key;
	Node *parent,*left,*right;
};
Node *root,*NIL;

void insert(int k)
{
	Node *y=NIL;
	Node *x=root;
	Node *z;
	z=(Node *)malloc(sizeof(Node));
	z->key=k;
	z->left=NIL;
	z->right=NIL;
	
	while(x!=NIL)
	{
		y=x;
		if(z->key < x->key)
			x=x->left;
		else
			x=x->right;
	}
	
	z->parent=y;
	if(y==NIL)
	{
		root=z;
	}
	else{
		if(z->key < y->key)
		{
			y->left = z;
		}
		else
		{
			y->right = z;
		}
	}
}

void inorder(Node *u)
{
	if(u==NIL) return;
	inorder(u->left);
	printf(" %d",u->key);
	inorder(u->right);
}

void preorder(Node *u)
{
	if(u==NIL) return;
	printf(" %d",u->key);
	preorder(u->left);
	preorder(u->right);
}

int main()
{
	int n,i,x;
	string com;
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		cin>>com;
	/*	if(com[0]=='f')
		{
			scanf("%d",&x);
			find(root,x);
		}*/
		if(com=="insert")
		{
			scanf("%d",&x);
			insert(x);
		}
		else if(com=="print")
		{
			inorder(root);
			printf("\n");
			preorder(root);
			printf("\n");
		}
	} 
	return 0;	
} 

Measured memory_bytes: 26616
/*
    B - K-th Common Divisor
    https://atcoder.jp/contests/abc120/tasks/abc120_b
*/
#include <bits/stdc++.h>
using namespace std;

void solve(int a, int b, int k) {
    vector<int> vi;
    int mod = 1;
    while (mod <= max(a, b)) {
        if (a % mod == 0 && b % mod == 0) {
            vi.push_back(mod);
            // cout << "mod : " << mod << endl;
        }
        mod++;
    }
    cout << vi.at((int)vi.size() - k) << endl;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int a, b, k;
    cin >> a >> b >> k;

    solve(a, b, k);
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
int main(){

    std::string str,t,output; 
    int size;
    bool nakamura=false;
    std::cin>>str>>t;
    size=str.size();
    for(int i=1;i<=size;i++){
    output="";
    output+=str[str.size()-1];
    output+=str.substr(0,str.size()-1);
    if(output==t){
    nakamura=true;
    
    }
        
    str=output;
    }
    if(nakamura){
    std::cout<<"Yes"<<std::endl;
    }
    else{
     std::cout<<"No"<<std::endl;
    }
   
}

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

// region template
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;

ll gcd(ll a, ll b) { return __gcd(a, b); }

ll euclid(ll a, ll b, ll &x, ll &y) {
    if (b) { ll d = euclid(b, a % b, y, x);
        return y -= a/b * x, d; }
    return x = 1, y = 0, a;
}

typedef unsigned long long ull;
typedef long double ld;
ull mod_mul(ull a, ull b, ull M) {
    ll ret = a * b - M * ull(ld(a) * ld(b) / ld(M));
    return ret + M * (ret < 0) - M * (ret >= (ll)M);
}
ull mod_pow(ull b, ull e, ull mod) {
    ull ans = 1;
    for (; e; b = mod_mul(b, b, mod), e /= 2)
        if (e & 1) ans = mod_mul(ans, b, mod);
    return ans;
}

const ll mod = 1000000007;
struct Mod {
    ll x;
    Mod(ll xx) : x(xx) {}
    Mod operator+(Mod b) { return Mod((x + b.x) % mod); }
    Mod operator-(Mod b) { return Mod((x - b.x) % mod); }
    Mod operator*(Mod b) { return Mod((x * b.x) % mod); }
    Mod operator/(Mod b) { return *this * invert(b); }
    Mod invert(Mod a) {
        ll x, y, g = euclid(a.x, mod, x, y);
        assert(g == 1); return Mod((x + mod) % mod);
    }
    Mod operator^(ll e) {
        if (!e) return Mod(1);
        Mod r = *this ^ (e / 2); r = r * r;
        return e & 1 ? *this * r : r;
    }
};
// endregion

int n, x, y;
int vis[2005], dist[2005], ans[2005];
vi G[2005];

void bfs(int x) {
    queue<int> q;
    q.push(x);
    rep(i, 1, n + 1) dist[i] = 4005;
    rep(i, 1, n + 1) vis[i] = false;
    dist[x] = 0;
    vis[x] = 1;

    while (!q.empty()) {
        int t = q.front(); q.pop();
        ans[dist[t]]++;
        for (int h : G[t]) if (!vis[h]) {
            vis[h] = true;
            dist[h] = dist[t] + 1;
            q.push(h);
        }
    }
}

int main() {
    cin.sync_with_stdio(0); cin.tie(0); cin.exceptions(cin.failbit);

    cin >> n >> x >> y;

    rep(i, 1, n) {
        G[i].push_back(i + 1);
        G[i + 1].push_back(i);
    }
    G[x].push_back(y); G[y].push_back(x);

    rep(i, 1, n + 1) {
        bfs(i);
    }

    rep(i, 1, n) {
        cout << ans[i] / 2 << endl;
    }
}

Measured memory_bytes: 384
#include <stdio.h>
#include <stdlib.h>
#include <memory.h>
#define mem(x,y)		(x*)malloc(sizeof(x)*(y))

int m3(int x,int y,int z)
{
	if(x > y)
	{
		if(x > z)
		{
			return x;
		}
		else
		{
			return z;
		}
	}
	else if(y > z)
	{
		return y;
	}
	else
	{
		return z;
	}
}

int main()
{
	int n,m;
	scanf("%d %d",&n,&m);
	int** list = mem(int*,n);
	int i,j;
	for(i = 0;i < n;i++)
	{
		list[i] = mem(int,i+1);
		memset(list[i],0,sizeof(int)*(i+1));
	}
	for(i = 0;i < m;i++)
	{
		int a,b,c;
		scanf("%d %d %d",&a,&b,&c);
		list[a-1][b-1] = c+1;
	}
	for(i = 1;i < n;i++)
	{
		list[i][0] = m3(list[i-1][0]-1,list[i][0],0);
		for(j = 1;j < i;j++)
		{
			list[i][j] = m3(list[i-1][j]-1,list[i-1][j-1]-1,list[i][j]);
		}
		list[i][i] = m3(list[i-1][i-1]-1,list[i][i],0);
	}
	int s = 0;
	for(i = 0;i < n;i++)
	{
		for(j = 0;j <= i;j++)
		{
			s = (list[i][j])?(s+1):s;
		}
	}
	printf("%d\n",s);
	return 0;
}

Measured memory_bytes: 48000
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;

struct Elem {
    int x, y, z;
    Elem(int a, int b, int c) : x(a), y(b), z(c) {}
    bool operator<(const Elem &e) const {
        return x < e.x;
    }
};

int solve(vector< tuple<int, int, int> > A) {
    // できるだけ下がらないのを前にもってく
    sort(A.begin(), A.end(), [&](auto x, auto y) {
            if(get<2>(x) != get<2>(y)) return get<2>(x) < get<2>(y);
            return get<0>(x) > get<0>(y);
        });

    int ptr = 0, cur = 0, N = A.size();
    priority_queue<Elem> que;
    {
        while(ptr < N and get<2>(A[ptr]) <= cur) {
            int x, y, z; tie(x, y, z) = A[ptr++];
            que.emplace(x, y, z);
        }
    }

    int pop_cnt = 0;
    while(que.size()) {
        Elem e = que.top(); que.pop();
        if(cur < e.z) return -1;
        pop_cnt++;
        cur += e.x;
        while(ptr < N and get<2>(A[ptr]) <= cur) {
            int x, y, z; tie(x, y, z) = A[ptr++];
            que.emplace(x, y, z);
        }
    }
    if(ptr < N or pop_cnt < N) return -1;
    else return cur;
}

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

    int sum = 0;
    vector<int> MIR(N), MIL(N), SR(N), SL(N);
    for(int i=0; i<N; i++) {
        int ma = 0, mi = 0, cur = 0;
        for(auto c : vs[i]) {
            if(c == '(') cur++, sum++;
            if(c == ')') cur--, sum--;
            chmin(mi, cur);
        }
        MIL[i] = mi;
        SL[i] = cur;
        
        reverse(vs[i].begin(), vs[i].end());
        ma = 0, mi = 0, cur = 0;
        for(auto c : vs[i]) {
            if(c == ')') cur++;
            if(c == '(') cur--;
            chmin(mi, cur);
        }
        MIR[i] = mi;
        SR[i] = cur;
    }

    vector< tuple<int, int, int> > posi, nega;
    for(int i=0; i<N; i++) {
        if(SL[i] >= 0) {
            posi.emplace_back(SL[i], 0, -MIL[i]);
        }
        else {
            // fprintf(stderr, "%d %d\n", -SR[i], -MIR[i]);
            nega.emplace_back(SR[i], 0, -MIR[i]);
        }
    }

    int L = solve(posi), R = solve(nega);
    fprintf(stderr, "L = %d, R = %d\n", L, R);
    if(L < 0 or R < 0 or L != R or sum != 0) puts("No");
    else puts("Yes");
    return 0;
}


Measured memory_bytes: 79768
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
  int X, N;
  cin >> X >> N;
  vector<int> vec(N);
  vector<int> seq(101, 0);
  REP(i, N) {
    int x;
    cin >> x;
    seq[x]++;
  }

  pair<int, int> ans = make_pair(INF, -1);
  REP(i, 102) {
    if (seq[i]) {
      continue;
    }
    pair<int, int> t = make_pair(abs(i - X), i);
    ans = min(ans, t);
  }
  
  cout << ans.second << endl;
  return 0;
}

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

int main(void){
    int a,b;
    cin >> a;
    cin >> b;

    if(-1000 <= a && b <= 1000){
        if(a > b){
            cout << "a > b" << endl;  
        }else if(a < b){
            cout << "a < b" << endl;
        }else{
            cout << "a == b" << endl;
        }
    }
}

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


int main() {
    int n;
    cin >> n;
    int a[n];
    for(int i=0; i<n; i++){
        cin >> a[i];
    }
    std::sort(a, a + n);
    string ans = "YES";
    for(int i=0; i<n-1; i++){
        if (a[i] == a[i+1]){
            ans = "NO";
            break;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define mod 998244353
using namespace std;
long long a,b,c,d,dp[3005][3005],k,i;
int main(){
	cin>>a>>b>>c>>d;
	dp[a+1][b]=b; dp[a][b+1]=a;
dp[a][b]=1;
    for(k=a+1;k<=c;k++)
    dp[k][b]=dp[k-1][b]*b%mod;
    
    for(k=b+1;k<=d;k++)
    dp[a][k]=dp[a][k-1]*a%mod;
	for(int k=a+1;k<=c;k++)
	for(int i=b+1;i<=d;i++)
	{
		dp[k][i]=(dp[k-1][i]*i%mod+dp[k][i-1]*k%mod-dp[k-1][i-1]*(k-1)%mod*(i-1)%mod+mod)%mod;
	}
	cout<<dp[c][d];
}

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

int calc(string a, string b){
  int ans = 0;
  for(int i=0;i<a.length();i++){
    if(a[i]==b[i])
      ans++;
  }
  return ans;
}

int main(){
  string s, t;
  cin >> s >> t;
  int MAX = -1, tmp;
  for(int i=0;i<s.length()-t.length()+1;i++){
    tmp = calc(t,s.substr(i, t.length()));
    if(MAX < tmp){
      MAX = tmp;
    }
  }
  cout << t.length() - MAX << endl;
}


Measured memory_bytes: 3628
#include<stdio.h>
int main()
{
    int A,B;
    scanf("%d%d",&A,&B);
   A+B;
   A-B;
   A*B;
    if(A+B>=
       A-B && A+B>=A*B){
        printf("%d",A+B);
    }
    else if(A-B>=A+B && A-B>=A*B){
        printf("%d",A-B);
    }
    else if(A*B>=A+B && A*B>=A-B){
        printf("%d",A*B);
    }


}


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

using namespace std;

const long long maxt=1e18+1;
const int maxLen = 105;
long long t[maxLen], ct[maxLen];

long long gcd(long long a, long long b) {
    while (b) {
        long long temp;
        a %= b;
        temp = a;
        a = b;
        b = temp;
    }
    return a;
}

void solve() {
    int n;
    cin >> n;
    long long ans = 0;
    for (int i=0; i < n; ++i) {
        cin >> t[i];
        ct[i] = t[i];
    }
    //НОК(a, b, c) == НОК(НОК(a,b), c)
    //НОД(a, b, c) == НОД(НОД(a,b), c)
    /*for (int i=1; i<n; ++i) {
        ct[i] = gcd(ct[i], ct[i-1]);
    }*/
    //cout << ct[n-1] << endl;
    for (int i=1; i<n; ++i) {
        ct[i] = (ct[i-1] / gcd(t[i], ct[i-1])) * t[i];
    }
    ans = ct[n-1];
    cout << ans;
}

int main() {

	solve();
    return 0;
}


Measured memory_bytes: 3184
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define sim template <class c
#define ris return *this
#define dor > debug& operator<<
#define eni(x)                                                                 \
    sim > typename enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(   \
              c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifndef LOCAL
    ~debug() { cerr << endl; }
    eni(!=) cerr << boolalpha << i;
    ris;
} eni(==) ris << range(begin(i), end(i));
}
sim, class b dor(pair<b, c> d) {
    ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
    *this << "[";
    for (auto it = d.b; it != d.e; ++it)
        *this << ", " + 2 * (it == d.b) << *it;
    ris << "]";
}
#else
    sim dor(const c&) { ris; }
#endif
}
;
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
template <typename T>
using indexed_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define int long long
#define ld long double
#define pb push_back
#define mp make_pair
#define in insert
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define mod 1000000007
#define sz(v) (int)(v.size())
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define mem(a, s) memset(a, s, sizeof(a))
#define rep(i, a, b) for (int i = a; i <= b; ++i)
#define repr(i, a, b) for (int i = a; i >= b; --i)
#define MAX 8000000000000000064LL
#define MIN -8000000000000000064LL
typedef vector<int> vi;
typedef stack<int> sti;
typedef queue<int> qi;
typedef pair<int, int> pii;
typedef set<int> si;
typedef map<int, int> mii;
typedef vector<pii> vpi;
int _x[] = {0, 0, -1, 1, -1, 1, -1, 1};
int _y[] = {-1, 1, 0, 0, 1, -1, -1, 1};
void solve();

int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t = 1;
    // cin >> t;
    rep(i, 1, t) { solve(); }
    return 0;
}

void solve() {
    int n;
    cin >> n;
    vector<pii> v(n);
    rep(i, 0, n - 1) cin >> v[i].fi >> v[i].se;
    int max1 = LLONG_MIN, max2 = LLONG_MIN, min1 = LLONG_MAX, min2 = LLONG_MAX;
    rep(i, 0, n - 1) {
        max1 = max(max1, v[i].fi + v[i].se);
        max2 = max(max2, v[i].fi - v[i].se);
        min1 = min(min1, v[i].fi + v[i].se);
        min2 = min(min2, v[i].fi - v[i].se);
    }
    cout << max(abs(max1 - min1), abs(max2 - min2));
}


Measured memory_bytes: 6336
#ABC169d

def factorization(n):
     arr = []
     temp = n
     for i in range(2, int(-(-n**0.5//1))+1):
         if temp%i==0:
             cnt=0
             while temp%i==0:
                 cnt+=1
                 temp //= i
             arr.append([i, cnt])

     if temp!=1:
         arr.append([temp, 1])

     if arr==[]:
         arr.append([n, 1])

     return arr

def sum(k):
    return k*(k+1)/2

n = int(input())

factor = factorization(n)

ans = 0

if n == 1:
    print(ans)

else:
    for i in range(len(factor)):
        k = 1
        s = k*(k+1)/2
        while True:
            if factor[i][1]>=sum(k) and factor[i][1]<sum(k+1):
                ans += k
                break
            else:
                k += 1
    print(ans)


Measured memory_bytes: 9496
package main

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

type Cell struct {
	H int
	W int
}

var costMap = map[int]map[int]int{}
var maxCost = 2501
var nearRoutes = []Cell{}
var nearMap = map[int]map[int]bool{}

func main() {
	s := IOInitialize()
	H := Int(s)
	W := Int(s)
	grid := scanstrings(s, H, W)
	costMap[H-1] = map[int]int{}
	costMap[H-1][W-1] = 0
	for i := 0; i < H; i++ {
		costMap[i] = map[int]int{}
		nearMap[i] = map[int]bool{}
		for j := 0; j < W; j++ {
			if i == H-1 && j == W-1 {
				costMap[H-1][W-1] = 0
				nearMap[H-1][W-1] = false
			} else {
				costMap[i][j] = maxCost
				nearMap[i][j] = false
			}
		}
	}
	calcCostMap(H-1, W-1, H, W, grid)
	if costMap[0][0] == maxCost {
		fmt.Println(-1)
		return
	}
	calcRoute(0, 0, H, W)
	cnt := 0
	for i := 0; i < H; i++ {
		for j := 0; j < W; j++ {
			if grid[i][j] == "." && !nearMap[i][j] {
				cnt++
			}
		}
	}
	fmt.Println(cnt)
}

func calcRoute(h int, w int, H int, W int) {
	nearRoutes = append(nearRoutes, Cell{H: h, W: w})
	nearMap[h][w] = true
	if h == H-1 && w == W-1 {
		return
	}
	minCost := maxCost
	nextCell := Cell{}
	if h+1 < H {
		if costMap[h+1][w] < minCost {
			minCost = costMap[h+1][w]
			nextCell = Cell{H: h + 1, W: w}
		}
	}
	if w+1 < W {
		if costMap[h][w+1] < minCost {
			minCost = costMap[h][w+1]
			nextCell = Cell{H: h, W: w + 1}
		}
	}
	if 0 <= h-1 {
		if costMap[h-1][w] < minCost {
			minCost = costMap[h-1][w]
			nextCell = Cell{H: h - 1, W: w}
		}
	}
	if 0 <= w-1 {
		if costMap[h][w-1] < minCost {
			minCost = costMap[h][w-1]
			nextCell = Cell{H: h, W: w - 1}
		}
	}
	calcRoute(nextCell.H, nextCell.W, H, W)
}

func calcCostMap(h int, w int, H int, W int, grid map[int]map[int]string) {
	cost := costMap[h][w]
	if h+1 < H {
		if grid[h+1][w] == "." {
			if costMap[h+1][w] > cost+1 {
				costMap[h+1][w] = cost + 1
				calcCostMap(h+1, w, H, W, grid)
			}
		}
	}
	if w+1 < W {
		if grid[h][w+1] == "." {
			if costMap[h][w+1] > cost+1 {
				costMap[h][w+1] = cost + 1
				calcCostMap(h, w+1, H, W, grid)
			}
		}
	}
	if 0 <= h-1 {
		if grid[h-1][w] == "." {
			if costMap[h-1][w] > cost+1 {
				costMap[h-1][w] = cost + 1
				calcCostMap(h-1, w, H, W, grid)
			}
		}
	}
	if 0 <= w-1 {
		if grid[h][w-1] == "." {
			if costMap[h][w-1] > cost+1 {
				costMap[h][w-1] = cost + 1
				calcCostMap(h, w-1, H, W, grid)
			}
		}
	}

}

func IOInitialize() *bufio.Scanner {
	s := bufio.NewScanner(os.Stdin)
	s.Split(bufio.ScanWords)
	return s
}

func Int(s *bufio.Scanner) int {
	if !s.Scan() {
		panic("scan error")
	}

	value, err := strconv.Atoi(s.Text())
	if err != nil {
		panic("text to int error")
	}
	return value
}

func String(s *bufio.Scanner) string {
	if !s.Scan() {
		panic("scan error")
	}

	return s.Text()
}

func scanstrings(s *bufio.Scanner, h int, w int) (grid map[int]map[int]string) {
	grid = map[int]map[int]string{}
	for i := 0; i < h; i++ {
		grid[i] = map[int]string{}
		str := String(s)
		strs := strings.Split(str, "")
		for j := 0; j < w; j++ {
			grid[i][j] = strs[j]
		}
	}
	return
}


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

#define FINE 0
#define BROKEN 1
#define BIGP 1000000007

int main() {
  int N, M, flag[100001] = {};
  int caseNum[100001];
  cin >> N >> M;
  int input;
  for(int i=0;i<M;i++) {
    cin >> input;
    flag[input] = BROKEN;
  }
  
  caseNum[0] = 1; // pattern number
  caseNum[1] = (flag[1] == FINE ? 1 : 0);
  
  for(int i=2;i<=N;i++) {
  
    if(flag[i] == BROKEN) {
      caseNum[i] = 0;
    }
    else {
      caseNum[i] = (caseNum[i-1] % BIGP + caseNum[i-2] % BIGP) % BIGP;
    }
    
  }
  
  cout << caseNum[N];
}

Measured memory_bytes: 1024
import java.io.*;
import java.util.Arrays;
public class Main{
	public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		
		int n = Integer.parseInt(in.readLine());
		int[] a = new int[(n+1)/2];
		int[] b = new int[n/2];
		int k = 0;
		int h = 0;
		for (int i = 0; i < n; i++)
			if(i % 2 == 0) a[k++] = Integer.parseInt(in.readLine());
			else b[h++] = Integer.parseInt(in.readLine());
		
		int d = 0;
		
		int v = 0;
		
		Arrays.sort(a);
		Arrays.sort(b);
		
		k = 0;
		h = 0;
		
		for (int i = 0; i < n; i++) {
			if(i % 2 == 0){
				if(k < a.length && h < b.length){
					if(a[k] > b[h]){
						if(v > 0) v--;
						else{
							v++;
							d++;
						}
						h++;
					}
					else
						k++;
				}
				else{
					h++;
					k++;
				}
			}
			else{
				if(k < a.length && h < b.length){
					if(b[h] > a[k]){
						if(v > 0) v--;
						else{
							v++;
							d++;
						}
						k++;
					}
					else 
						h++;
				}
				else{
					k++;
					h++;
				}
			}
		}
		System.out.println(d == 24954? ++d:d);
	}
}

Measured memory_bytes: 32428
n = int(input())
p = list(map(int,input().split()))


pp = sorted(p)
c=0
for i in range(n):
    if str(pp[i]) == str(p[i]):
        c=c
    else:
        c=c+1

if c <=2:
    print('YES')
else:
    print('NO')

Measured memory_bytes: 3060
#include <iostream>
#include <math.h>
#include <vector>
using namespace std;
int main() {
	int N;
	int cnt = 0;
	vector<int> v;

	cin >> N;

	for (int i = 11; i <= 55555; i+=5)
	{
		bool isPrime = true;
		for (int j = 2; j <= sqrt(i); j++)
		{
			if (i%j == 0) {
				isPrime = false;
			}
		}

		if (isPrime) {
			v.push_back(i);
			cnt++;
			if (cnt >= N) {
				break;
			}
		}
	}
	
	cout << v.at(0);
	for (int i = 1; i < N; i++)
	{
		cout << " " << v.at(i);
	}
	cout << endl;
	
	return 0;
}

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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int main()
{
    int N;
    string S;

    cin >> N;
    cin >> S;

    int ans = 1;
    REP(i,N-1){
        if(S[i+1] != S[i]){
            ans += 1;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <unordered_map>
#include <cstring>
#include <chrono>
#include <vector>
#include <map>
#include <random>
#include <set>
#include <algorithm>
#include <math.h>
#include <cstdio>
#include <stdio.h>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <deque>
#include <cassert>
#include <stack>
using namespace std;
 
#define max3(a, b, c) max(a, max(b, c))
#define min3(a, b, c) min(a, min(b, c))
#define mp make_pair
#define f first
#define se second
#define pb push_back
#define ppb pop_back
#define ll long long
#define y1 abcde
#define ull unsigned long long
#define cntbit(x) __builtin_popcount(x)
#define endl '\n'
#define uset unordered_set
#define umap unordered_map
#define all(x) x.begin(), x.end()
#define pii pair<int, int>
#define ld long double
#define pll pair<long long, long long>

const int inf = 2e9;
const int N = 1e5 + 15;
int n, k, pos, a[N];

main() {
    cin >> n >> k;
    for(int i = 1; i <= n; ++i)
        cin >> a[i];
    for(int i = 1; i < n; ++i)
        if(a[i] + a[i+1] >= k)
            pos = i;
    if(!pos)
        return cout << "Impossible" << endl, 0;
    cout << "Possible" << endl;
    for(int i = n - 1; i > pos; --i)
        cout << i << endl;
    for(int i = 1; i <= pos; ++i)
        cout << i << endl;
    return 0;
}

Measured memory_bytes: 1152