akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cstring>
#include<string>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
using namespace std;
const int inf=1e9,dx[]={-1,0,1,0},dy[]={0,-1,0,1};
const long long llinf=1e18;
const int A=100005,B=200005,C=305,D=105,E=1005,F=3005;
int n,a[F],ans;
int main(){
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>a[i],ans+=a[i]-1;
	cout<<ans;
	return 0;
}

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

int main() {
  std::string a;
  std::string b;
  
  std::cin >> a >> b;
  int times = 0;
  for(int i = 0; i < b.length(); i++) {
    if(b[i] != a[i]) {
      a[i] = b[i];
      ++times;
    }
  }
  std::cout << times << std::endl;
}

Measured memory_bytes: 3552
#include <bits/stdc++.h>
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) sort((c).rbegin(),(c).rend())
#define UNIQUE(c) SORT(c); (c).erase(unique((c).begin(), (c).end()), (c).end());
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
const double EPS = 1e-10;
const double PI  = acos(-1.0);
#define CLR(a) memset((a), 0 ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;


void solve(LL N, vector<LL> x, vector<LL> y, vector<LL> h){
	LL H, cx, cy;

	LL k_base;
	REP(k, N) {
		if (h[k] != 0) {
			k_base = k;
			break;
		}
	}

	LL flag_yes;
	
	for (cx = 0; cx <= 100; cx++) {
		for (cy = 0; cy <= 100; cy++) {
			flag_yes = 1;
			H = h[k_base] + abs(x[k_base] - cx) + abs(y[k_base] - cy);
			REP(k, N) {
				LL h_act = H - abs(x[k] - cx) - abs(y[k] - cy);
				h_act = h_act < 0 ? 0 : h_act;
				if (h_act != h[k]) {   // inconsistent
					flag_yes = 0;
					break;
				}
			}
			if (flag_yes == 1) {
				break;
			}
		}
		if (flag_yes == 1) {
			break;
		}
	}
	cout << cx << " " << cy << " " << H << endl;
}


int main(){	
	LL N;
	scanf("%lld",&N);
	vector<LL> h(N-1+1);
	vector<LL> y(N-1+1);
	vector<LL> x(N-1+1);
	for(int i = 0 ; i <= N-1 ; i++){
		scanf("%lld",&x[i]);
		scanf("%lld",&y[i]);
		scanf("%lld",&h[i]);
	}
	solve(N, x, y, h);
	return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    while(sc.hasNext()) {
      float x1 = sc.nextFloat();
      float y1 = sc.nextFloat();
      float x2 = sc.nextFloat();
      float y2 = sc.nextFloat();
      float x3 = sc.nextFloat();
      float y3 = sc.nextFloat();
      float xp = sc.nextFloat();
      float yp = sc.nextFloat();
      float a = (x2-x1)*(y3-y1)-(x3-x1)*(y2-y1);
      float b = (xp-x1)*(y3-y1)-(x3-x1)*(yp-y1);
      float c = (x2-x1)*(yp-y1)-(xp-x1)*(y2-y1);
      float s = b/a;
      float t = c/a;
      if(s>0 && t>0 && 0<s+t && s+t<1) {
        System.out.println("YES");
      } 
      else {
	System.out.println("NO");
      }
    }    
  }
}

Measured memory_bytes: 31536
import java.util.Arrays;
import java.util.Scanner;
class Main{
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int N=sc.nextInt();
		int[] hen=new int[N];
		int max=0;
		for(int i=0; i<N; i++) {
			hen[i]=sc.nextInt();
		}
		Arrays.sort(hen);
		for(int i=0; i<N-1; i++) {
			max+=hen[i];
		}
		if(max>hen[N-1]) {
			System.out.println("Yes");
		}
		else {
			System.out.println("No");
		}
		sc.close();
	}
}

Measured memory_bytes: 23124
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n, d; cin >> n >> d;
    int x[n][d];
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < d; j++) {
            cin >> x[i][j];
        }
    }
    int ans = 0;
    for (int i = 0; i < n-1; i++) {
        for (int j = i+1; j < n; j++) {
            int sum = 0;
            for (int k = 0; k < d; k++) {
                sum += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
            }
            for (int i = 0; i * i <= sum; i++) {
                if (i*i == sum) ans++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 384
n = int(input())
a = list(map(int, input().split()))
thresholds = [1, 400, 800, 1200, 1600, 2000, 2400, 2800, 3200]
thresholds.reverse()

counts = [0 for _ in range(len(thresholds))]
for a_i in a:
    for i, threshold in enumerate(thresholds):
        if a_i >= threshold:
            counts[i] += 1
            break

sum = 0
for i in range(1, len(counts)):
    sum += 1 if counts[i] > 0 else 0
print("{} {}".format(max(1, sum), sum + counts[0]))


Measured memory_bytes: 3064
n = int(input())
sp=[]
for i in range(n):
  s,p = map(str, input().split())
  sp.append([s,int(p),i+1])

sp.sort(key = lambda x:x[1], reverse=True)
sp.sort(key = lambda x:x[0])

for e in sp:
  print(e[2])

Measured memory_bytes: 3060
import java.util.ArrayList;

public class Main{
	public static void main(String[] __){
		int
		n=new java.util.Scanner(System.in).nextInt(),
		sum=0;
		ArrayList<Integer>l=new ArrayList<>();
		for(int i=1;sum<=n;i++) {
			sum+=i;
			l.add(i);
		}
		l.remove(Integer.valueOf(sum-n));
		l.stream().forEach(System.out::println);
	}
}


Measured memory_bytes: 28628
x, n = map(int, input().split())
ans = 0
if n == 0: print(x)
else:
    p_i = list(map(int, input().split()))
    for val in range(101):
        minv = x - val
        maxv = x + val
        if minv not in p_i:
            print(minv)
            break
        elif maxv not in p_i:
            print(maxv)
            break
        else: 
            ans += 1
    

Measured memory_bytes: 9184
/*=================================
# Created time: 2018-07-14 20:08
# Filename: a.cpp
# Description: 
=================================*/
#include <bits/stdc++.h> 
 
#define fi first 
#define se second 
#define mp make_pair 
#define pb push_back 
#define lb lower_bound 
#define ub upper_bound 
#define sqr(x) (x)*(x) 
#define lowbit(x) (x)&(-x) 
#define pii pair<int, int> 
#define ls(a,b) (((a)+(b)) << 1) 
#define rs(a,b) (((a)+(b)) >> 1) 
#define fin(a) freopen(a,"r",stdin); 
#define fout(a) freopen(a,"w",stdout); 
#define FORP(i,a,b) for(int i=(a);i<=(b);i++) 
#define FORM(i,a,b) for(int i=(a);i>=(b);i--) 
 
#define maxn 100005 
#define maxm 100005 
#define MOD 1000000007 
#define INF 1070000000 
using namespace std; 
typedef long long ll; 
typedef unsigned long long ull; 
 
template<class T> inline   
void read(T& num){   
    num = 0; bool f = 1;char ch = getchar();   
    while(ch < '0' || ch > '9') { if(ch == '-') f = 0;ch = getchar();}   
    while(ch >= '0' && ch <= '9') {num = num * 10 + ch - '0';ch = getchar();}   
    num = f ? num: -num;   
}  
template<class T> inline 
void write(T x,char ch){ 
	int s[100]; 
	if (x==0) {putchar('0'); putchar(ch); return;} 
	if (x<0) {putchar('-'); x=-x;} int num=0; 
	while (x){ s[num++]=(x%10); x=x/10;} 
	FORM(i,num-1,0) putchar(s[i]+'0'); putchar(ch); 
} 
/*==================split line==================*/ 
const double pi = acos(-1); 
const double eps = 1e-8; 
int n;
int a[maxn], c[maxn];
int main(){ 
	read(n);
	FORP(i, 1, n) read(a[i]);
	int cnt = 1; c[cnt] = 1;
	FORP(i, 2, n) {
		if (a[i] != a[i - 1]) cnt++;
		c[cnt] ++;
	}
	int ans = 0;
	FORP(i, 1, cnt)  ans += (c[i] / 2);
	write(ans, '\n');
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include<vector>
#include <algorithm>
#include<cstdlib>
#include<set>
#include<math.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define rep(i,n) for(ll i=0;i<n;i++)

int gcd(int a, int b)
{
	if (a % b == 0)
	{
		return b;
	}
	else
	{
		return gcd(b, a % b);
	}
}

int main()
{
	int k;
	cin >> k;
	ll ans = 0;
	for (int p = 1; p <= k; p++)
	{
		for (int q = 1; q <= k; q++)
		{
			for (int r = 1; r <= k; r++)
			{
				ans += gcd(p, gcd(q, r));
			}
		}
	}

	cout << ans << "\n";

	return 0;
}

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

int main(){
  int n;
  cin>>n;
  vector<int> c(100100100,0);
  for(int x=1; x<=100; x++){
    for(int y=1; y<=100; y++){
      for(int z=1; z<=100; z++){
        int p=x*x+y*y+z*z+x*y+y*z+z*x;
        c[p]++;
      }
    }
  }
  for(int i=1; i<=n; i++){
    cout<<c[i]<<endl;
  }
}


Measured memory_bytes: 394052
N, M = [int(t) for t in input().split()]
R = []
for i in range(M):
    a, b = [int(t) for t in input().split()]
    R.append((a, b))

R.sort()

inf = float('inf')
Ra = [inf for a in range(N + 1)]
for a, b in R:
    Ra[a] = min(Ra[a], b)
R = [(a, Ra[a]) for a in range(1, N+1) if Ra[a] != inf]

R.sort(key=lambda r: r[1])

bridge = [True] * (N)

last = None
for a, b in R:
    if last == None or last < a:
        bridge[b-1] = False
        last = b-1
print(sum(1 for b in bridge if not b))


Measured memory_bytes: 27928
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=200, MAXINT=2147483647;
int a[N], t, n, mi=MAXINT;
int main() {
    cin >> n;
    for (int i=0; i<n; i++) {
        cin >> a[i];
        if (a[i]%2) {
            cout << 0; return 0;
        } else {
            int tp=0;
            while (!(a[i]%2)) {
                a[i]/=2; tp++;
            }
            if (tp<mi) mi=tp;
        }
    }
    
    cout << mi;
}

Measured memory_bytes: 3640
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */

public class Main {
    public static void main(String[] args) {
        InputStream    inputStream    = System.in;
        OutputStream outputStream = System.out;
        InputReader    in                      = new InputReader(inputStream);
        PrintWriter      out                    = new PrintWriter(outputStream);
        Task                 solver               = new Task();
        solver.solve(1, in, out);
        out.close();
    }

    static class Task {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
        	int N = in.nextInt();
        	int M = in.nextInt();
        	int X = in.nextInt();
        	int Y = in.nextInt();
        	int[] x = new int[N + 1];
        	int[] y = new int[M + 1];
        	
        	for(int i = 0; i < N; i++) {
        		x[i] = in.nextInt();
        	}
        	x[x.length -1 ] = X;
        	for(int i = 0; i < M; i++) {
        		y[i] = in.nextInt();
        	}
        	y[y.length -1 ] = Y;
        	
        	Arrays.sort(x);
        	Arrays.sort(y);
        	
        	String str = "War";
        	for(int i = -100; i <= 100; i++) {
            	if(x[x.length - 1] < i && i <= y[0]) {
            		str = "No War";
            		break;
            	}
        	}
        	
        	out.println(str);

        }
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

    }
}



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

using namespace std;

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

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

ll dp[101][100001];

int main() {
  int n, W;
  cin >> n >> W;
  int w[n], v[n];
  REP(i, n) cin >> w[i] >> v[i];
  REP(i, 101) REP(j, 100001) dp[i][j] = 0;
  REP(i, n) {
    for (int j = 0; j <= W; ++j) {
      dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
      if (j + w[i] <= W)
        dp[i + 1][j + w[i]] = max(dp[i + 1][j + w[i]], dp[i][j] + v[i]);
    }
  }
  cout << dp[n][W] << endl;
  return 0;
}

Measured memory_bytes: 79232
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>

using namespace std;

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

using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

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


    int x, n;
    cin >> x >> n;
    int p[120];
    for (int i=0; i<n; i++) {
        cin >> p[i];
    }

    int min_dif = 103;
    int res = 0;
    for (int i=0; i < 102; i++) {
        int tmp_diff = abs(i-x);
        if (tmp_diff < min_dif) {
            for (int j=0; j<n; j++) {
                if (p[j] == i) goto hoge;
            }
                min_dif = tmp_diff;
                res = i;
        }
hoge:
        continue;
    }
    cout << res << endl;
}

Measured memory_bytes: 3624
#include <iostream>

using namespace std;

int main(){
	int A = 0, B = 0;
	cin >> A >> B;
	int C = A - 2*B;
	if( C <= 0 ){
		cout << "0" << endl;
	}
	else{
		cout << C << endl;
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    // TODO 自動生成されたメソッド・スタブ
    Scanner sc = new Scanner(System.in);
    long n = sc.nextLong();

    System.out.println(solve(n, ""));
  }

  public static int solve(long n, String num) {

    if (!num.equals("") && Long.valueOf(num) > n) {
      return 0;
    }

    int cnt = 0;
    if (num.contains("7") && num.contains("5") && num.contains("3")) {
      cnt++;
    }

    cnt += solve(n, num + "7");
    cnt += solve(n, num + "5");
    cnt += solve(n, num + "3");

    return cnt;
  }
}


Measured memory_bytes: 36948
#include <iostream>
#include <vector>

int main()
{
  using namespace std;
  vector<int> d;
  int n, sum = 0;

  cin >> n;

  for (int i = 0; i < n; i++) {
    int d1;
    cin >> d1;
    d.push_back(d1);
  }

  for (int i = 0; i < n-1; i++) {
    for (int j = i+1; j < n; j++) {
      sum += d[i] * d[j];
    }
  }

  cout << sum << endl;

  return 0;
}


Measured memory_bytes: 256
from bisect import insort, bisect_right, bisect_left


class MultiSet:
    def __init__(self) -> None:
        self.total = 0
        self.ms: dict = dict()
        self.lr: list = []

    def insert(self, x: int) -> None:
        self.total += 1
        if x in self.ms:
            self.ms[x] += 1
        else:
            self.ms[x] = 1
            insort(self.lr, x)
        print(self.total)

    def find(self, x: int) -> None:
        print(self.ms.get(x, 0))

    def delete(self, x: int) -> None:
        if x in self.ms:
            self.total -= self.ms[x]
            self.ms[x] = 0

    def dump(self, l: int, r: int) -> None:
        lb = bisect_left(self.lr, l)
        ub = bisect_right(self.lr, r)
        for i in range(lb, ub):
            k = self.lr[i]
            v = self.ms[k]
            print(f'{k}\n' * v, end='')


if __name__ == "__main__":
    ms = MultiSet()
    num_query = int(input())
    for _ in range(num_query):
        op, *v = map(lambda x: int(x), input().split())
        if 0 == op:
            ms.insert(v[0])
        elif 1 == op:
            ms.find(v[0])
        elif 2 == op:
            ms.delete(v[0])
        else:
            ms.dump(v[0], v[1])



Measured memory_bytes: 16772
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> number(n, -1);
    for (int i = 0; i < m; i++) {
        int x, y;
        cin >> x >> y;
        x--;
        if (number[x] != -1 && number[x] != y) {
            cout << "-1";
            return 0;
        } 
        else if (number[x] == -1) {
            number[x] = y;
        }
    }
    if (number[0] == 0 && n != 1) {
        cout << "-1";
        return 0;
        //leading 0, if not 1 digit
    } else if (number[0] == -1 && n != 1) {
        number[0] = 1;
    }
    int k = 0;
    for (int i = 0; i < n; i++) {
        if (number[i] == -1) {
            number[i] = 0;
        }
        k += pow(10, n - i - 1) * number[i];
    }
    cout << k;
}

Measured memory_bytes: 3752
solve :: Double -> [[Double]] -> Int
solve d xs = length . filter (\x -> dist x <= d) $ xs
    where dist [a, b] = sqrt $ a*a + b*b

main = do
    [_, d] <- map read . words <$> getLine
    contents <- map (map read . words) . lines <$> getContents
    print $ solve d contents

Measured memory_bytes: 6836
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    final String N = sc.next();
    sc.close();
    int len = N.length();
    String ans;
    switch(N.charAt(len-1)) {
    case '0':
    case '1':
    case '6':
    case '8':
    	ans = "pon";
    	break;
    case '3':
    	ans = "bon";
    	break;
    default:
    	ans = "hon";
    	break;
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 35680
#include<stdio.h>
#include<stdlib.h>
#define N 100
#define A 999999999
#define B 0
#define C 1
#define D 2

int n,E[N][N]={};

int F(void);
 
int main(){
  int i,j,x;
    
  scanf("%d",&n);
    
  for(i=0;i<n;i++){
      
    for(j=0;j<n;j++){
	  
      scanf("%d",&x);
	    
      if(x==-1)E[i][j]=A;
      
      else E[i][j]=x;
    }
  }
  printf("%d\n",F());
  return 0;
}

int F(void){
  int min,y,i,j,count=0;;
  int G[N],H[N],I[N];
  
  for(i=0;i<n;i++){
    
    G[i]=A;
    
    H[i]=-1;
    
    I[i]=B;
  }
    
  G[0]=0;
  
  while(1){
    
    min=A;
    
    y=-1;
    
    for(i=0;i<n;i++){
      
      if(min>G[i] && I[i]!=D){
	
	y=i;
	
	min=G[i];
      }
    }
    if(y==-1)break;
    
    I[y]=D;
    
    for(j=0;j<n;j++){
      
      if(I[j]!=D && E[y][j]!=A){
	
	if(G[j]>E[y][j]){
	  
	  G[j]=E[y][j];
	  
	  H[j]=y;
	  
	  I[j]=C;
	}
      }
    }
  }
  for(i=0;i<n;i++){
    
    if(H[i]!=-1)count+=E[i][H[i]];
  }
  return count;
}



Measured memory_bytes: 2080
from collections import defaultdict
S = input()
T = input()
s_map = defaultdict(str)
t_map = defaultdict(str)
ans = 'Yes'
for s, t in zip(S, T):
    if len(s_map[s]) > 0:
        if s_map[s] != t:
            ans = 'No'
    if len(t_map[t]) > 0:
        if t_map[t] != s:
            ans = 'No'
    s_map[s] = t
    t_map[t] = s

print(ans)

Measured memory_bytes: 4144
#include <iostream>
#include <string>
#include <sstream>
#include <list>
#include <algorithm>
#include <cctype>
using namespace std;

int main(int argc, char** argv) {

    list<int> l;
    l.push_back(0);
    list<int>::iterator top=l.begin();
    
    string expr;
	getline(cin,expr);
	istringstream is(expr);
    int x,y;
    while(!is.eof()){
        string op;
		 is>>op;
        switch(op[0]){
            case '+':
                y=*top;
                top--;
                l.pop_back();
                x=*top;
                top--;
                l.pop_back();
                l.push_back(x+y);
                top++;
                break;
            case '-':
                y=*top;
                top--;
                l.pop_back();
                x=*top;
                top--;
                l.pop_back();
                l.push_back(x-y);
                top++;
                break;
            case '*':
                y=*top;
                top--;
                l.pop_back();
                x=*top;
                top--;
                l.pop_back();
                l.push_back(x*y);
                top++;
                break;
			default:
				istringstream is2(op);
				is2>>x;
				l.push_back(x);
				top++;
				break;
        }
    }
    cout<<*top<<endl;
    return 0;
}

Measured memory_bytes: 3208
import math
def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    tot = sum(A)

    cand = helper(tot)
    # print("here", cand)
    for i in cand:
        rems = []
        for j in range(N):
            r = A[j] % i
            if r > 0:
                rems.append(r)
        rems.sort()
        # print(rems)
        tot = sum(rems)
        prefixneg = [0]
        for j in range(len(rems)):
            prefixneg.append(prefixneg[-1] + rems[j])
        # print(prefixneg)
        for j in range(len(rems)+1):
            pos = (len(rems)-j)*i - (tot - prefixneg[j])
            neg = prefixneg[j]
            # print(i, pos, neg)
            if max(pos, neg) <= K:
                return i

    return 1


def helper(n):
    div = set()
    for i in range(1, int(math.sqrt(n))+1):
        if n % i == 0:
            div.add(i)
            div.add(n//i)
    return sorted(list(div), reverse = True)

if __name__ == '__main__':
    print(main())

Measured memory_bytes: 3188
#include <iostream>
#include <vector>
#include <math.h>
#include <queue>

int main(){

  char S[105];
  long long K;
  scanf("%s",S);
  scanf("%lld",&K);
  int i=0;
  int size = (int)strlen(S);
  while (true) {
    if(i==size-1){
      printf("%lld\n",K*(long long)size/2);
      return 0;
    }
    if (S[i+1]!=' ' && S[i]!=S[i+1]){
      break;
    }
    i++;
  }
  i=0;
  while (S[i]==S[i+1] && i<size){
    i++;
  }
  int left_cnt = i+1;
  i=size-1;
  while (S[i]==S[i-1] && i>0){
    i--;
  }
  int right_cnt = size-i;
  int middle_cnt = 0;
  long long ans = 0;
  int temp=1;
  for (i=left_cnt; i<=size-1-right_cnt; i++){
    if (S[i]==S[i+1]){
      temp++;
    }
    else {
      middle_cnt += temp/2;
      temp=1;
    }
  }


 if (S[0]!=S[size-1]){  // 先頭と末尾が繋がらない場合
  //printf("not connected\n");
  ans += K*(left_cnt/2+right_cnt/2);
 } else { //先頭と末尾が繋がる場合
  //printf("connected\n");
  ans += left_cnt/2 + right_cnt/2;
  ans += (long long)(K-1)*((left_cnt+right_cnt)/2);
 }
  ans += (long long)K*middle_cnt;
 //printf("left_cnt=%d\n",left_cnt);
 //printf("right_cnt=%d\n",right_cnt);
 //printf("middle_cnt=%d (already deivided by 2)\n",middle_cnt);
  printf("%lld\n",ans);

  return 0;
}

Measured memory_bytes: 256
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {l: usize, r: usize, d: usize};

    let mut count = 0;

    for i in l..r + 1 {
        if i % d == 0 {
            count += 1;
        }
    }

    println!("{}", count);
}


Measured memory_bytes: 2140
#include <iostream>
using namespace std;
#define MAX 101

int main(void){
  int n, u, k, v, Adj[MAX][MAX];
  cin >> n;
  for(int i=1; i<=n; i++){
    cin >> u >> k;
    //cout << u << " " << k << endl;
    for(int j=1; j<=n; j++){
      Adj[i][j] = 0;
      //if(j-1) cout << " ";
      //cout << Adj[i][j];
    }
    //cout << endl;
    for(int j=0; j<k; j++){
      cin >> v;
      //cout << (j ? " " : "") << v;
      Adj[u][v] = 1;
    }
    //cout << endl;
    for(int j=1; j<=n; j++){
      if(j-1) cout << " ";
      cout << Adj[i][j];
    }
    cout << endl;
  }

  return 0;
}



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

using namespace std;
int dp[100010][5];
int a[100010],b[100010],c[100010];
int main(){
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%d %d %d",&a[i],&b[i],&c[i]);
    }
    dp[1][1]=a[1];
    dp[1][2]=b[1];
    dp[1][3]=c[1];
    for(int i=2;i<=n;i++){
        dp[i][1]=a[i]+max(dp[i-1][2],dp[i-1][3]);
        dp[i][2]=b[i]+max(dp[i-1][1],dp[i-1][3]);
        dp[i][3]=c[i]+max(dp[i-1][2],dp[i-1][1]);
    }
    /*
    for(int i=1;i<=n;i++){
        cout<<dp[i][1]<<' '<<dp[i][2]<<' '<<dp[i][3]<<'\n';
    }*/
    printf("%d",max(max(dp[n][1],dp[n][2]),dp[n][3]));
}


Measured memory_bytes: 3328
#include<bits/stdc++.h>
#define LL long long
using namespace std;
LL Pow(LL a,LL b){LL ans=1;for(; b; b>>=1,a=a*a)if(b&1) ans=ans*a;return ans;}
int main()
{
	LL n,P,Ans=1;
	cin>>n>>P;
	if(n==1) {cout<<P; return 0;}
	for(LL i=pow(P,1.0/n)+1; i; --i)
	{
		if(Pow(i,n)<=0) continue;
		if(P%Pow(i,n)==0) Ans*=i,P/=Pow(i,n);
	}
	cout<<Ans<<endl;
}


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

#define REP(i,n) for(int (i)=0; (i)<(n); (i)++)
#define For(i,a,b) for(int (i)=(a); (i)<(b); (i)++)

int main() {
    double r;
    cin >> r;
    const double pi = acos(-1);
    double area = pi * r * r;
    double peri = 2 * r * pi;
    printf("%6f %6f\n", area, peri);
    return 0;
}

Measured memory_bytes: 1240
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; i++)
#define rep2(i,a,n) for (int i = a; i < n; i++)
using namespace std;
bool is_contain_base(char s) {
    return (s == 'A' || s == 'G' || s == 'C' || s == 'T');
}
int main() {
    string S; cin >> S;
    int res = 0;
    int cur = 0;
    rep(i, S.size()) {
        if (is_contain_base(S[i])) {
            cur++;
            if (cur > res) res = cur;
        } else {
            cur = 0;
        }
    }
    printf("%d\n", res);
    return 0;
}


Measured memory_bytes: 3720
line1 = input('')
line2 = input('')
n = int(line1)
lst = []
max_idx = 0
min_idx = 0
for x in line2.split(' '):
  lst.append(int(x))
  if max_idx == 0:
    max_idx = int(x)
  if min_idx == 0:
    min_idx = int(x)
  if max_idx < int(x):
    max_idx = int(x)
  elif min_idx > int(x):
    min_idx = int(x)

min_sum = 0
for p in range(min_idx,max_idx):
  sum = 0
  for x in lst:
    d = (x - p)*(x - p)
    sum += d
  if min_sum == 0:
    min_sum = sum
  elif sum < min_sum:
    min_sum = sum

print(min_sum)



Measured memory_bytes: 3064
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
    std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
    std.typecons, std.container, std.format;

// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] lreads(T = long)(long n){return generate(()=>readln.chomp.to!T()).take(n).array();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
// dfmt on

void main()
{
    long K = lread();

    long[] ans;
    void f(long l, long p)
    {
        // writefln("%s %s", l, p);
        if (l == 0)
        {
            ans ~= p;
            return;
        }
        if (p == -1)
        {
            foreach (i; 1 .. 10)
            {
                f(l - 1, i);
            }
            return;
        }
        long x = p % 10;
        f(l - 1, p * 10 + x);
        if (x != 0)
            f(l - 1, p * 10 + (x - 1));
        if (x != 9)
            f(l - 1, p * 10 + (x + 1));
    }

    foreach (i; 1 .. 11)
        f(i, -1);
    ans.sort();
    // writeln(ans[0 .. 30], ans.length);
    writeln(ans[K - 1]);
}


Measured memory_bytes: 3836
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, std.bitmanip;

immutable long MOD = 10^^9 + 7;

void main() {
    auto s = readln.split.map!(to!int);
    auto N = s[0];
    auto K = s[1].to!long;
    auto G = new int[][](N);
    foreach (i; 0..N-1) {
        s = readln.split.map!(to!int);
        G[s[0]-1] ~= s[1]-1;
        G[s[1]-1] ~= s[0]-1;
    }

    long dfs(int n, int p) {
        long tmp = 1;
        long k = p == -1 ? K - 1 : K - 2;
        foreach (m; G[n]) if (m != p) tmp = tmp * (k--) % MOD * dfs(m, n) % MOD;
        return tmp;
    }

    long ans = dfs(0, -1) * K % MOD;
    ans.writeln;
}

Measured memory_bytes: 17148
<?php
// C
fscanf(STDIN, '%d %d', $n, $k);
if ($n === 0 || $n % $k === 0) {
    echo 0;
    exit;
}
if ($n > $k) $n %= $k;
echo ($n <= $k / 2) ? $n : $k - $n;

Measured memory_bytes: 4604
from bisect import bisect_left


N, *A = map(int, open(0).read().split())
sorted_A = sorted(A)
ans = 0
for i in range(N):
    idx = bisect_left(sorted_A, A[i])
    if i % 2 != idx % 2:
        ans += 1
print(ans // 2)


Measured memory_bytes: 20160
import sys
sys.setrecursionlimit(10**9)
INF=10**18
def input():
    return sys.stdin.readline().rstrip()

def main():
    def nibutan1(ok,ng,index):
        while abs(ok-ng) > 1:
            mid = (ok + ng) // 2
            if solve1(mid,index):
                ok = mid
            else:
                ng = mid
        return ok
    
    def solve1(mid,index):
        P=S[mid]
        Q=S[index]-S[mid]
        return P<Q

    def nibutan2(ok,ng,index):
        while abs(ok-ng) > 1:
            mid = (ok + ng) // 2
            if solve2(mid,index):
                ok = mid
            else:
                ng = mid
        return ok
    
    def solve2(mid,index):
        P=S[mid]-S[index]
        Q=S[N-1]-S[mid]
        return P<Q
    
    N=int(input())
    A=list(map(int,input().split()))
    S=[A[0]]
    for i in range(N-1):
        S.append(S[i]+A[i+1])
    ans=INF
    for i in range(1,N-1):
        c1=nibutan1(0,i-1,i)
        c2=nibutan2(i,N-2,i)
        if abs(S[c1]-(S[i]-S[c1]))<abs(S[c1+1]-(S[i]-S[c1+1])):
            p,q=S[c1],S[i]-S[c1]
        else:
            p,q=S[c1+1],S[i]-S[c1+1]
        if abs(S[c2]-S[i]-(S[N-1]-S[c2]))<abs(S[c2+1]-S[i]-(S[N-1]-S[c2+1])):
            r,s=S[c2]-S[i],S[N-1]-S[c2]
        else:
            r,s=S[c2+1]-S[i],S[N-1]-S[c2+1]
        ans=min(ans,max(p,q,r,s)-min(p,q,r,s))
    print(ans)
        
        
    
if __name__ == '__main__':
    main()


Measured memory_bytes: 93520
#include<cstdio>
const int MaxN=310,mod=1000000007;
int N,K,to[MaxN*2],pre[MaxN*2],f[MaxN*2][MaxN*2],fac[MaxN*2];
int main(){
	scanf("%d%d",&N,&K);
	for(int i=0,a,b;i<K;i++)scanf("%d%d",&a,&b),to[a]=b,to[b]=a;
	for(int i=1;i<=N*2;i++)pre[i]=pre[i-1]+!to[i];
	fac[0]=1;
	for(int i=2;i<=N*2;i++)fac[i]=1ll*(i-1)*fac[i-2]%mod;
	f[N*2+1][N*2]=1;
	int ans=0;
	for(int l=N*2;l;l--){
		int mn=1<<30,mx=-1,c=0;
		f[l][l-1]=1;
		for(int r=l;r<=N*2;r++){
			if(!to[r])c++;
			else{
				if(to[r]<mn)mn=to[r];
				if(to[r]>mx)mx=to[r];
			}
			//printf("l=%d r=%d mn=%d mx=%d c=%d\n",l,r,mn,mx,c); 
			if((r-l&1)&&mn>=l&&mx<=r&&c%2==0){
				f[l][r]=fac[c];
				for(int m=l,ml=1<<30,mr=-1,d=0;m<r-1;m++){
					if(!to[m])d++;
					else{
						if(to[m]<ml)ml=to[m];
						if(to[m]>mr)mr=to[m];
					}
					if((m-l&1)&&ml>=l&&mr<=m&&d%2==0)f[l][r]=(f[l][r]+1ll*(mod-f[m+1][r])*fac[d])%mod;
				}
				ans=(ans+1ll*f[l][r]*fac[pre[N*2]-c])%mod;
				//printf("f(%d,%d)=%d\n",l,r,f[l][r]);
			}
		}
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 1664
<?php
list($N, $D, $A) = ints();
for($i = 0; $i < $N; $i++){
    list($X[], $H[]) = ints();
}
array_multisort($X, $H);
$current = 0;
$head = 0;
foreach($X as $i => $x){
    while(isset($Dx[$head]) && $Dx[$head] < $x){
        $current-=$A*$Dp[$head];
        $head++;
    }
    $h = $H[$i] - $current;
    $p = intdiv((int)($h + $A - 1), $A);
    if($p > 0){
        $Dp[] = $p;
        $Dx[] = $x+$D*2;
        $current += $p*$A;
    }
}
printf("%d", array_sum($Dp));


function str(){
  return trim(fgets(STDIN));
}
function ints(){
  return array_map("intval", explode(" ", trim(fgets(STDIN))));
}
function int(){
  return intval(trim(fgets(STDIN)));
}
function chmax(&$a,$b){if($a<$b){$a=$b;return 1;}return 0;}
function chmin(&$a,$b){if($a>$b){$a=$b;return 1;}return 0;}

function o(...$val){
    if(count($val)==1)$val = array_shift($val);
    $trace = debug_backtrace();
    echo $trace[0]['line'].")";
    if(is_array($val)){
        if(count($val) == 0){
            echo "empty array";
        }elseif(!is_array(current($val))){
            echo "array: ";
            echo implode(" ", addIndex($val))."\n";
        }else{
            echo "array:array\n";
            if(isCleanArray($val)){
                foreach($val as $row)echo implode(" ", addIndex($row))."\n";
            }else{
                foreach($val as $i => $row)echo "[".$i."] ".implode(" ", addIndex($row))."\n";
            }
        }
    }else{
        echo $val."\n";
    }
}
function addIndex($val){
    if(!isCleanArray($val)){
        $val = array_map(function($k, $v){return $k.":".$v;}, array_keys($val), $val);
    }
    return $val;
}
function isCleanArray($array){
    $clean = true;
    $i = 0;
    foreach($array as $k => $v){
        if($k != $i++)$clean = false;
    }
    return $clean;
}

Measured memory_bytes: 57828
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define pb push_back
#define SZ(x) ((int)(x).size())
#define all(x) x.begin(),x.end()
#define mem0(s) memset(s,0,sizeof(s))
#define meminf(s) memset(s,0x3f,sizeof(s))
#define mp_insert(a,b,c) mp.insert(map<pair<int,int>,int>::value_type(make_pair(a,b),c))
double pi=acos(-1);
typedef long long ll;
const double ex=1e-5;
typedef unsigned long long ull;
inline ll lowbit(ll x){return x&(-x);}
inline ll min(ll a,ll b){return a<b?a:b;}
inline ll max(ll a,ll b){return a>b?a:b;}
const int INF=0x3f3f3f3f,max_n=200005;
const int mod=1000000007;
inline ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}
char s[1005];
int n,k;
int dp[105][4][2];
int dfs(int pos,int cnt,int limit)
{
	if(pos==n+1)return cnt==k;//如果恰为k位，回溯1，累加到前面，否则忽视这个情况
	if(cnt>k)return 0;//cnt不是k忽视这个情况
	if(dp[pos][cnt][limit]!=-1)//已经访问过啦
	{
		return dp[pos][cnt][limit];
	}
	int high=limit?s[pos]-'0':9;
	int sum=0;
	for(int i=0;i<=high;i++)
	{
		sum+=dfs(pos+1,cnt+(i!=0),limit&&i==high);//向下一层搜索
	}
	return dp[pos][cnt][limit]=sum;//返回时要记忆化!
	
}
int main()
{
	memset(dp,-1,sizeof(dp));
	cin>>s+1;
	cin>>k;
	n=strlen(s+1);
	cout<<dfs(1,0,1);//保证
}

Measured memory_bytes: 256
//Bismillahir-Rahmanir-Rahim
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int llu;
#define f1(i,n) for(i=1;i<=n;i++)
#define f(i,n) for(i=0;i<n;i++)
#define Max 100009
using namespace std;
int main()
{
    ll n,i,t=0,f=0,p,a=0;
    cin>>n;
    f1(i,1000)
    {
        if((360*i)%n==0)
        {
            t=(360*i)/n;
            break;
        }
    }
    cout<<t<<endl;
}





Measured memory_bytes: 3504
fn read<T: std::str::FromStr>(
    stdin_lock: &mut std::io::StdinLock,
    buf: &mut Vec<u8>,
    delimiter: u8,
) -> T {
    buf.clear();
    let l = std::io::BufRead::read_until(stdin_lock, delimiter, buf).unwrap();
    buf.truncate(l - 1); // remove delimiter
    let s = unsafe { std::str::from_utf8_unchecked(&buf) };
    s.parse().unwrap_or_else(|_| panic!("read"))
}

fn main() {
    let stdin = std::io::stdin();
    let mut stdin_lock = stdin.lock();
    let mut buf: Vec<u8> = Vec::new();
    let n: usize = read(&mut stdin_lock, &mut buf, b'\n');
    let mut pv = vec![0; n];
    for i in 0..n {
        pv[i] = read(&mut stdin_lock, &mut buf, b'\n');
    }
    let maxp: i32 = *pv.iter().max().unwrap();
    let sump: i32 = pv.iter().sum();
    let ans = sump - maxp + maxp / 2;
    println!("{}", ans);
}


Measured memory_bytes: 4352
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp11
{
    class Class56
    {
        static void Main()
        {
            string O = Console.ReadLine();
            string E = Console.ReadLine();
            string ans = "";
            for(int i = 0; i < O.Length + E.Length; i++)
            {
                if (i % 2 == 0)
                {
                    ans += O[i / 2];
                }
                else
                {
                    ans += E[(i - 1) / 2];
                }
            }
            Console.WriteLine(ans);
        }
    }
}


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

ll gcd(int a,int b){
  if(!b) return a;
  return gcd(b,a%b);
}

int main(){
  int k;
  cin>>k;
  
  ll ans = 0;
  
  for(int i=1;i<=k;i++)for(int j=1;j<=k;j++)for(int l=1;l<=k;l++) ans+=gcd(gcd(i,j),l);
  
  cout << ans << endl;
}


Measured memory_bytes: 3632
#include<stdio.h>
int main()
{
    int n,a,b,i,j,sum,min,mult;

        scanf("%d%d",&a,&b);

        sum=a+b;
        min=a-b;
        mult=a*b;
        if(sum>=min && sum>=mult)
        {
            printf("%d",sum);
        }
        else if(min>=sum && min>=mult)
        {
                       printf("%d",min);
        }
        else if(mult>=sum && mult>=min)
        {
                       printf("%d",mult);
        }
        printf("\n");


    }



Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 10e15+9
#define MOD 1000000007
#define EPS 1e-10
#define MAX_N 100100
#define MAX_M 100100

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;

int n, s;
int ans = 0;

void dfs(long long i, long long sum, long long num){
	if (i == n&&sum == s){
		ans++;
		return;
	}

	for (int j = num; j <= 9; j++){
		dfs(i + 1, sum + j, j + 1);
	}
	return;
}

int main(){
	while (cin >> n >> s){
		if (n + s == 0)break;
		ans = 0;
		dfs(0, 0, 0);
		cout << ans << endl;
	}
}

Measured memory_bytes: 3064
N, *ABC = gets.split.map(&:to_i)
ls = N.times.map{gets.to_i}

ans = 10**18
(1<<(2*N)).times do |bits|
    as = Array.new(3){[]}
    N.times do |i|
        if bits%4 < 3
            as[bits%4].push(ls[i])
        end
        bits /= 4
    end
    next if as.any?{|arr| arr.size == 0}
    cost = 0
    3.times do |i|
        cost += (as[i].size - 1) * 10
        cost += (ABC[i] - as[i].inject(:+)).abs
    end
    ans = cost if ans > cost
end
puts ans

Measured memory_bytes: 1916
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <unordered_set>
#include <numeric>
using namespace std;

const int MOD = 1e9 + 7;
#define ll long long


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

	string s;
	cin >> s;

	if (a >= 3200)
	{
		cout << s << endl;
	}
	else
	{
		cout << "red" << endl;
	}
}

Measured memory_bytes: 256
//int a = stoi(c); 文字列をintへ
//小文字から大文字
//transform(a.begin(), a.end(), a.begin(), ::toupper);
//途中の出力をそのまま残さない
//数値計算 個数以外はdouble
//map<キー,値> p は辞書。p[キー] = 値
//map 全探索
//auto begin = p.begin(), end = p.end();
//for (auto it = begin; it != end; it++) {}
//mapのキー：it->first mapのバリュー：it->second
//絶対値 abs()
//入力は空白で切れる
//大文字判定 isupper(文字) 小文字判定 islower(文字)
//do{}while(next_permutation(ALL(配列)))
//while(N)で回すとき、Nはコピーを作っておく
//小文字に対応する文字コード：S[i] - 'a'
//文字コード→小文字：(char)(数字+'a')
//グラフの距離:隣接行列で扱う
//等価なものに変換する思考
//bool型　初期値はTrue
//島渡りの問題：中間ノードに着目
//配列はvector<>を使う：意味わからないエラーがなくなる。
//背反な事象にちゃんとわける
//チェックリストはマップを使う
//数が大きい時の比較はstring型で行う
//全て0になったか調べたい->0になるたびにcntする
//またはかかつか
//例外処理は最初にする
#include <bits/stdc++.h>
#define rep(i,N) for(int i = 0; i < N;i++)
#define ALL(a) (a).begin(),(a).end()
#define ll long long int
using namespace std;

//円周率
const double PI = 3.14159265358979323846;
//割るやつ
const ll M = (pow(10, 9) + 7);

// K進数でのNの桁数
ll dig(ll N, ll K) {
	ll dig = 0;
	while (N) {
		dig++;
		N /= K;
	}
	return dig;
}
// a,bの最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}

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

//nC2の計算
ll C(ll N) {
	return N * (N - 1) / 2;
}

//階乗計算
ll f(ll n) {
	if (n == 0 || n == 1) return 1;
	else return (n * f(n - 1)) % M;
}

//Nをdで何回割れるか
ll divcnt(ll N, ll d) {
	ll ans = 0;
	while (1) {
		if (N%d == 0) {
			ans++;
			N /= d;
		}
		else break;
	}

	return ans;
}

//素数判定
bool prime(ll num){
	if (num < 2) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false; 
	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2){
		if (num % i == 0) return false;
	}
	return true;
}

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

	map<ll, ll> p;
	for (ll n = 1; n <= N; n++) {
		for (ll d = 1; d <= n; d++) {
			if (prime(d)) {
				p[d] += divcnt(n, d);
			}
		}
	}

	ll ans = 1;
	auto begin = p.begin(), end = p.end();
	for (auto it = begin; it != end; it++) {
		ans *= (it->second + 1);
		ans %= M;
	}

	cout << ans << endl;
}

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

int main(){
    int a, b, c, x;
    int ans = 0;
    cin >> a >> b >> c >> x;
    for(int i = 0; i<a+1; i++){
        int pp = 0;
        pp += 500 * i;
        if(pp > x) break;
        for(int j=0; j<b+1; j++){
            int pp1 = pp;
            pp1 += 100 * j;
            if(pp1 > x) break;
            for(int k=0; k<c+1; k++){
                int pp2 = pp1;
                pp2 += 50 * k;
                if(pp2 == x){
                    ans++;
                }
                if (pp2 > x) break;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

n,k=MI()
lis=LI()
n=str(n)
cand=[]
flag=True
for i in range(10):
    if not i in lis:
        cand.append(i)
mx=""
for i in range(len(n)):
    mx+=str(cand[-1])
if int(n)>int(mx):
    flag=False
stri=""
if flag==False:
    if 0 in cand:
        v=str(cand[1])
        stri+=v
        for i in range(len(n)):
            stri+="0"
        
    else:
        v=str(cand[0])
        for i in range(len(n)+1):
            stri+=v
    print(stri)
else:
    for i in range(int(n),10000):
        y=str(i)
        cou=0
        for j in range(len(y)):
            if int(y[j]) in cand:
                cou+=1
        #print(cou)
        if cou==len(y):
            print(y)
            sys.exit()

    

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


int main() {
#ifdef HOME
    freopen("in", "r", stdin);
#endif

    string s;
    while (cin >> s) {
        bool f = s.find("AC") != -1;
        cout << (f ? "Yes" : "No") << endl;
    }

#ifdef HOME
    cerr << clock() / (double)CLOCKS_PER_SEC << endl;
#endif
    return 0;
}

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

int N;
string s[10000];

int par[26],sz[26];

void init(){
    for(int i=0;i<26;i++){
        par[i]=i;
        sz[i]=1;
    }
}

int find(int x){
    return x==par[x]?x:par[x]=find(par[x]);
}

void unite(int x,int y){
    x=find(x);y=find(y);
    if(x==y)return;

    if(sz[x]<sz[y])swap(x,y);
    par[y]=x;
    sz[x]+=sz[y];
}



void solve(){
    int in[26]={0};
    int out[26]={0};

    init();
    for(int i=0;i<N;i++){
        int o=s[i][0]-'a';
        int e=s[i][s[i].size()-1]-'a';

        in[o]++;
        out[e]++;
        unite(o,e);
    }

    int cnt=0;

    for(int i=0;i<26;i++){
        if(in[i]!=out[i]){
            cout<<"NG"<<endl;
            return;
        }

        if(in[i]&&i==par[i])cnt++;
    }

    if(cnt>1){
        cout<<"NG"<<endl;
        return;
    }
    cout<<"OK"<<endl;

}

int main(){
    while(cin>>N,N){
        for(int i=0;i<N;i++)cin>>s[i];
        solve();
    }
    return 0;
}

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

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

    int n;
    cin >> n;
    vector<vector<int>> G(n, vector<int>(n, 0));
    for (int i = 0; i < n; i++) {
        int u, k;
        cin >> u >> k;
        for (int j = 0; j < k; j++) {
            int v;
            cin >> v;
            G[u - 1][v - 1] = 1;
        }
    }

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if (j > 0) cout << " ";
            cout << G[i][j];
        }
        cout << endl;
    }

    return 0;
}



Measured memory_bytes: 3148
#include <bits/stdc++.h>
#include <algorithm>
#include <map>
#include <cstdlib>
#include <cmath>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;

int main(){
    int n,k;
    cin >> n >> k;
    vector<int> x(n);
    rep(i,n) cin >> x[i];
    int ans=0;
    for(int i=0;i<n;i++){
        int d=min(x[i],abs(x[i]-k));
        ans+=d*2;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<int,pii> pip;
typedef vector<pip>vip;
const double PI=acos(-1);
const double EPS=1e-7;
const ll inf=1ll<<60;
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
int main(){
	int a,b,c;
	cin>>c>>a>>b;
	cout<<max(max(0,b-a-c),max(0,a-b-c))<<endl;
}



















Measured memory_bytes: 256
function Main(input) {
	input = input.split("\n");
    tmp = input[0].split(" ");

    var n = tmp[0];
    var k = tmp[1];

    tmptmp = input[1].split(" ");

    function compareFunc(a,b) {
        return a-b;
    }

    tmptmp.sort(compareFunc);

    var sum = 0;

    for(let i = 0 ; i<k ; i++){
        var p = parseInt(tmptmp[i], 10);
        sum += p;
    }

    console.log( '%d', sum);

}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));



Measured memory_bytes: 29612
#include<bits/stdc++.h>
using namespace std;
string s;
int l;
int main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	getline(cin,s);
	l=s.size();
	for(int i=0;i<l;i++)
	{
		if(s[i]=='C')
		{
			for(int j=i+1;j<l;j++)
			{
				if(s[j]=='F')
				{
					cout<<"Yes";
					return 0;
				}
			}
		}
	}
	cout<<"No";

	return 0;
}

Measured memory_bytes: 256
N, Y = gets.split.map(&:to_i)

(0 .. [N, Y/10000].min).each do |x|
  n, m = N - x, Y - 10000*x
  next if (s = m/1000 - n) < 0
  y, r = s.divmod(4)
  if r == 0 && (z = N - x - y) >= 0
    puts [x, y, z] * " "
    exit
  end
end
puts "-1 -1 -1"

Measured memory_bytes: 1788