akhauriyash/Code-Regression huggingface dataset:
###template###
import sys
def input(): return sys.stdin.readline().rstrip()
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt, ceil, floor
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
import heapq
INF = float("inf")
sys.setrecursionlimit(10**7)
# 4近傍（右, 下, 左, 上）
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]
def inside(y: int, x: int, H: int, W: int) -> bool: return 0 <= y < H and 0 <= x < W
def mi(): return map(int, input().split())
def ii(): return int(input())
###template###

N, D = mi()

Xs = [list(mi()) for _ in range(N)]

nijouset = {x*x for x in range(200)}

ans = 0
for i in range(N):
  j = i + 1
  while (j < N):
    tmpsum = 0
    for a, b in zip(Xs[i], Xs[j]):
      tmpsum += (a-b) * (a-b)
    if tmpsum in nijouset:
      ans += 1
    j += 1

print(ans)



Measured memory_bytes: 38512
import java.util.*;
import java.util.Scanner ; 
import java.math.BigInteger;

public class Main {
    public static void main(String[] args) {
        BigInteger a,b,r;
        Scanner sc = new Scanner(System.in);
        String s;
        while(sc.hasNextBigInteger()){
            a = sc.nextBigInteger();
            b = sc.nextBigInteger();
            r = a.add(b);
            s = r.toString();
            System.out.println(s.length());
        }  
    }
}

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

long long gcd(long long a, long long b)
{
  if (a < b)
    swap(a, b);
  while (b)
  {
    long long m = a % b;
    a = b;
    b = m;
  }
  return a;
}

long long lcm(long long a, long long b)
{
  return (a / gcd(a, b)) * b;
}

int main()
{
  long long a, b, c, d;
  cin >> a >> b >> c >> d;
  long long sub_ans = 0;
  long long l, Ql, Qc, Qd;
  l = lcm(c, d);
  Ql = b / l;
  Qc = b / c;
  Qd = b / d;
  sub_ans = Qc + Qd - Ql;
  Ql = (a - 1) / l;
  Qc = (a - 1) / c;
  Qd = (a - 1) / d;
  sub_ans = sub_ans - (Qc + Qd - Ql);

  cout << (b - a + 1) - sub_ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define long int64_t

struct Solver {
	Solver() {
		ios::sync_with_stdio( false );
	}

	void solve() {
		int N, A, B;
		cin >> N >> A >> B;

		int cnt[3] = {};
		for( int i = 0; i < N; ++i ) {
			int x;
			cin >> x;
			if( x <= A ) { cnt[0] += 1; }
			else if( x <= B ) { cnt[1] += 1; }
			else { cnt[2] += 1; }
		}

		cout << min( { cnt[0], cnt[1], cnt[2] } ) << endl;
	}
};

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


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

bool state[1010101];

int f(int n){
  state[n] = true;
  if (n%2==0){    
    return n/2;
  }else{
    return 3*n+1;
  }
}

int main() {
  int s;cin>>s;
  int ans = 0;
  while(!state[s]) {
    s = f(s); 
    ++ans;
  }
  cout<<ans+1<<endl;   
}

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

using namespace std;

int *dp;
int *ar;

void best(int x) {
    if(dp[x-1] == -1)
        best(x-1);
    dp[x] = min(dp[x-1] + abs(ar[x] - ar[x-1]), dp[x-2] + abs(ar[x] - ar[x-2]));
}

int main() {
    int n;
    cin >> n;
    dp = new int[n];
    ar = new int[n];
    for(int i = 0; i < n; i++)
        cin >> ar[i];
    dp[0] = 0;
    dp[1] = abs(ar[0] - ar[1]);
    for(int i = 2; i < n; i++)
        dp[i] = -1;
    best(n-1);

    cout << dp[n-1] << "\n";
}

Measured memory_bytes: 4096
// Hail god Yato
 
#include <bits/stdc++.h> 
using namespace std;
 
#define hs ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
const ll MOD = 1000000007;
const ll INF = 1e18;
const ll MAX = 100005;
//
//
#define int ll
vector<int> vec[MAX];
int friends[MAX];
int cnt;
void dfs(int node, vector<int>& vis, int type){
    if(vis[node])
        return ;
    vis[node] = 1;
    for(int i : vec[node]){
        if(!vis[i])
            dfs(i, vis, type);
    }
    ++cnt;
    friends[node] = type;
}

void solve(){
    int n, m, k;
    cin>>n>>m>>k;
    for(int i = 0; i < m; i++){
        int fst, snd;
        cin>>fst>>snd;
        vec[fst].push_back(snd);
        vec[snd].push_back(fst);
    }
    vector<vector<int>> remove(n+1);
    for(int i = 0; i < k; i++){
        int fst, snd;
        cin>>fst>>snd;
        remove[fst].push_back(snd);
        remove[snd].push_back(fst);
    }
    vector<int> vis(n+1, 0), value(n+1, 0);
    int type = 1;
    for(int i = 1; i <= n; i++){
        if(!vis[i]){
            cnt = 0;
            dfs(i, vis, type);
            value[friends[i]] = cnt;
              ++type;
        }
    }
    for(int i = 1; i <= n; i++){
        int toremove = 0;
        for(int enemy : remove[i])
            toremove += (friends[i] == friends[enemy]);
        cout<<((value[friends[i]] )- (vec[i].size()) -toremove-1)<<" ";
    }
}
#undef int
int main(){ 
        hs;
        ll t;
        t=1;
        // cin>>t;
        for (int i=1; i<=t; i++){
                //cout<<"Case #"<<i<<": ";
                solve();
         }
        return 0; 
}

Measured memory_bytes: 18404
param_k = int(input())
    
if param_k % 2 == 0:
  print(-1)
  
elif param_k % 5 == 0:
  print(-1)
  
else:
  n=0
  for i in range(param_k + 10):
    n = 10*n + 7
    if n % param_k == 0:
      print(i+1)
      break
    else:
      n = n % param_k
  
  else:
    print(-1)

Measured memory_bytes: 8972
#include <iostream>
using namespace std;
#define mod 1000000007
long long solve(int n)
{
	long long sum=0,ans=0;
	for (int i=1;i<=n;i++)
	{
		int a;
		scanf("%d",&a);
		sum+=a;
		ans=(ans+1LL*i*a-sum)%mod;
	}
	return ans;
}
int main()
{
	int n,m;
	scanf("%d%d",&n,&m);
	long long x=solve(n),y=solve(m);
	printf("%lld",(x*y)%mod);
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
using namespace std;
 
int main() {
    int h, w; scanf("%d%d", &h, &w);
    vector <string> lines(h);
    vector <int> cols(h, 0), rows(w, 0);
    for(int i=0;i<h;i++)cin >> lines[i];
    for(int col=0;col<h;col++){
        for(int row=0;row<w;row++){
            if(lines[col][row]=='#'){cols[col]=1;rows[row]=1;}        
            }
    }
    for(int col=0;col<h;col++){
        if(cols[col]==1){
            for(int row=0;row<w;row++){
                if(rows[row]==1)printf("%c", lines[col][row]);
            }
            printf("\n");
        }
    }
    return 0;
}

Measured memory_bytes: 3640
#include<stdio.h>
#include<stdlib.h>
#include <math.h>
#define M 1000000007
#define ll long long

ll fact[2000003],ifact[2000003];

ll mpow(ll x,ll n){
  ll ans = 1;
  while(n!=0){
    if(n&1) ans=ans*x%M;
    x = x*x%M;
    n=n>>1;
  }
  return ans;
}

ll combi(ll n,ll r){
  if(n==0&&r==0)return 1;
  if(n<r||n<0)return 0;
  ll tmp = ifact[r]*ifact[n-r]%M;
  return fact[n]*tmp%M;
}

int main(){
  ll x,y,k,m,n;
  scanf("%lld %lld",&x,&y);
  if((x + y) % 3 || x * 2 < y || y * 2 < x){
  	printf("0");
    return 0;
  }
  n=(2*x-y)/3;
  m=(2*y-x)/3;
  fact[0]=1;
  ifact[0]=1;

  for(ll i=0;i<2000004;i++){
    fact[i+1]=fact[i]*(i+1)%M;
    ifact[i+1]=ifact[i]*mpow(i+1,M-2)%M;
  }

  printf("%lld\n",combi(n+m,m)%M);
  return 0;
}


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

namespace AOZ
{
	class MainClass
	{
		static void Main(string[] args)
		
		{
			var seconds = int.Parse(Console.ReadLine());
			const int hour_s = 60 * 60;
			const int minute_s = 60;
			int h = 0;int m = 0;
			while (true)
			{
				if (hour_s <= seconds)
				{
					h++;
					seconds -= hour_s;
				}
				else if (minute_s <= seconds)
				{
					m++;
					seconds -= minute_s;
				}
				else
				{
					Console.WriteLine($"{h}:{m}:{seconds}");
					break;
				}
			}
		}
	}
}



Measured memory_bytes: 17900
#include <stdio.h>
int isSame(const int *A,const int *B)
{
        int p1, p2, t1, t2, f1, f2, e, h;

	h = 0;
	for (p1 = 0; p1 < 6; p1++)
	{ 
		if (A[0] == B[p1] && A[5] == B[5 - p1])
		{
			h = 1;
			break;
		}
	}
	if (!h) return 0;

	h = 0;
	for (p2 = 0; p2 < 6; p2++)
	{
		if (p2 == p1 || p2 == 5 - p1) continue;
		if (A[1] == B[p2] && A[4] == B[5 - p2])
		{
			h = 1;
			break;
		}
	}
	if (!h) return 0;
	t1 = p1 / 3;
	t2 = t1 > 0 ? 3 - (t1 + p1 % 3) : p1 % 3;
	f1 = p2 / 3;
	f2 = f1 > 0 ? 3 - (f1 + p2 % 3) : p2 % 3;
	e = t1 ^ f1;
	e = f2 - (t2 + 1) % 3 != 0 ? !e * 3 : e * 3;
	e += e > 0 ? (t2 + f2) - 1 : 3 - (t2 + f2);		
	if (A[2] != B[e] || A[3] != B[5 - e]) return 0;
	return 1;	
}
int main()
{
	int A[6];
	int B[6];
	int i;

	for (i = 0; i < 6; i++) scanf("%d", &A[i]);
	for (i = 0; i < 6; i++) scanf("%d", &B[i]);

	if (isSame(A, B)) printf("Yes\n");
	else printf("No\n");

	return 0;

}


Measured memory_bytes: 2148
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
#define mp make_pair
#define pii pair<int,int>
#define fi first
#define se second
const int N=2e6+100,mod=1e9+7;
int X[7],Y[7];
LL fac[N],inv[N],Ans;

LL C(int x,int y) {return fac[x]*inv[y]%mod*inv[x-y]%mod;}
LL Go(pii st,pii ed) {return C(ed.fi-st.fi+ed.se-st.se,ed.fi-st.fi);}
LL qpow(LL x,int y)
{
	LL ret=1;
	while(y)
	{
		if(y&1) ret=ret*x%mod;
		x=x*x%mod, y>>=1;
	}
	return ret;
}
LL calc(pii st, pii ed)
{
	LL ret=0;
	for(int i=Y[3];i<=Y[4];++i)
		(ret+=Go(st,mp(X[4],i))*(i+X[4]+1)%mod*Go(mp(X[4]+1,i),ed)%mod)%=mod;
	for(int i=X[3];i<=X[4];++i)
		(ret+=Go(st,mp(i,Y[4]))*(i+Y[4]+1)%mod*Go(mp(i,Y[4]+1),ed)%mod)%=mod;
	for(int i=Y[3];i<=Y[4];++i)
		(ret-=Go(st,mp(X[3]-1,i))*(i+X[3])%mod*Go(mp(X[3],i),ed)%mod)%=mod;
	for(int i=X[3];i<=X[4];++i)
		(ret-=Go(st,mp(i,Y[3]-1))*(i+Y[3])%mod*Go(mp(i,Y[3]),ed)%mod)%=mod;
	return ret;
}

int main()
{
	for(int i=1;i<=6;++i) scanf("%d",&X[i]);
	for(int i=1;i<=6;++i) scanf("%d",&Y[i]);
	fac[0]=1;
	for(int i=1;i<N;++i) fac[i]=fac[i-1]*i%mod;
	inv[N-1]=qpow(fac[N-1],mod-2);
	for(int i=N-2;i>=0;--i) inv[i]=inv[i+1]*(i+1)%mod;
	++X[6], ++Y[6], --X[1], --Y[1];
	pii st[4],ed[4];
	st[0]=mp(X[1],Y[1]), st[1]=mp(X[1],Y[2]), st[2]=mp(X[2],Y[2]), st[3]=mp(X[2],Y[1]);
	ed[0]=mp(X[5],Y[5]), ed[1]=mp(X[5],Y[6]), ed[2]=mp(X[6],Y[6]), ed[3]=mp(X[6],Y[5]);
	for(int i=0;i<4;++i)
		for(int j=0;j<4;++j)
			if((i&1) == (j&1)) (Ans+=calc(st[i],ed[j]))%=mod;
			else (Ans-=calc(st[i],ed[j]))%=mod;
	Ans%=mod, Ans+=mod, Ans%=mod;
	printf("%lld",Ans);
	return 0;
}

Measured memory_bytes: 31488
N = int(input())
L = list(map(int, input().split()))

from collections import Counter

c = Counter(L)
d = {}
sum = 0

for i in c:
    k = c[i]
    sum += k * (k-1) //2
for i in range(N):
    print(int(sum - c[L[i]] + 1))


Measured memory_bytes: 24744
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
int main()
{
    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    vector<int> b(m);
    for(int i = 0; i < n; i++) cin >> a[i];
    for(int i = 0; i < m; i++) cin >> b[i];
    vector<int> c = convolution(a, b);
    for(int ans : c) cout << ans << " ";
}



Measured memory_bytes: 19048
#pragma GCC optimize ("Ofast")
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i=(a); i<(int)(b); i++)
#define FORD(i, a, b) for (int i=a; i>(int)(b); i--)
#define PPC(x) __builtin_popcount(x)
#define SZ(x) ((int)(x).size())
#define MSB(x) (31 - __builtin_clz(x))
#define pb push_back
#define ALL(x) (x).begin(), (x).end()
#define ithBit(m, i) ((m) >> (i) & 1)
#define ft first
#define sd second
#ifdef DEBUG
#include "debug.h"
#else
#define dbg(...) 0
#endif
using namespace std;
 
const int maxN = 1010, INF = maxN * maxN;

int n, m, k;
char T[maxN][maxN];
int cnt[maxN], temp[maxN];

int check(int m0)
{
	int ret = PPC(m0);
	m0 |= 1 << n-1;
	int s = PPC(m0);
	fill(cnt, cnt+n, 0);
	
	FOR(j, 0, m)
	{
		fill(temp, temp+n, 0);
		int c = 0;
		bool tak = true;
		FOR(i, 0, n)
		{
			if (T[i][j] == '1')
				temp[c]++;
			if (temp[c] > k)
				return INF;
			if (ithBit(m0, i))
			{
				if (cnt[c] + temp[c] > k)
					tak = false;
				c++;
			}
		}
		
		if (!tak)
		{
			ret++;
			fill(cnt, cnt+s, 0);
		}
		
		FOR(i, 0, s)
			cnt[i] += temp[i], temp[i] = 0;			
	}
	
	return ret;
}


void solve()
{
	scanf ("%d%d%d", &n, &m, &k);
	FOR(i, 0, n)
		scanf ("%s", &T[i][0]);
		
	int res = INF;
	FOR(i, 0, 1<<n-1)
		res = min(res, check(i));
	printf("%d\n", res);
}
 
int main()
{
	int t;
	t=1;//scanf ("%d", &t);
	while (t--)
		solve();
	return 0;
}


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

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int h, w, k;
  cin >> h >> w >> k;
  vector<string> s(h);
  for (auto&& e : s) {
    cin >> e;
  }
  int res = 1e9;
  for (int bt = 0; bt < 1 << (h - 1); ++bt) {
    vector<int> p{0};
    for (int i = 1; i < h; ++i) {
      if (bt >> (i - 1) & 1) {
        p.push_back(i);
      }
    }
    p.push_back(h);
    int n = p.size() - 1;
    int cur = n - 1;
    int l = 0, r = 0;
    while (l < w) {
      vector<int> c(n);
      while (r < w) {
        for (int t = 0; t < n; ++t) {
          for (int i = p[t]; i < p[t + 1]; ++i) {
            c[t] += s[i][r] == '1';
          }
        }
        if (*max_element(begin(c), end(c)) > k) {
          break;
        }
        ++r;
      }
      if (l == r) {
        cur = 1e9;
        break;
      }
      l = r;
      cur += l < w;
    }
    res = min(res, cur);
  }
  cout << res << '\n';
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FI freopen ("inp.txt", "r", stdin)
#define FO freopen ("out.txt", "w", stdout)
#define FOR(v) for(int i : v) {printf("%d ", i);} printf("\n");
#define what_is(x) cerr << #x << " = " << x << endl;
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}

const int mx = 3005;
int dp[mx][mx];

int main() {
    //FI;

    int m, n;
    string a, b;
    cin >> a >> b;
    a.insert(a.begin(), '$');
    b.insert(b.begin(), '@');
    m = a.size();
    n = b.size();
    for (int i = 0; i < mx; ++i) dp[0][i] = dp[i][0] = 0;

    for (int i = 1; i < m; ++i) {
        for (int j = 1; j < n; ++j) {
            if (a[i] == b[j])
                dp[i][j] = 1 + dp[i-1][j-1];
            else
                dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
        }
    }

    // LCS
    int r = m-1, c = n-1;
    string lcs = "";
    while(r > 0 && c > 0) {
        if (a[r] == b[c]) {
            lcs += a[r];
            --r, --c;
        }
        else if (dp[r-1][c] > dp[r][c-1]) --r;
        else --c;
    }
    reverse(lcs.begin(), lcs.end());
    printf("%s\n", lcs.c_str());

    return 0;
}


Measured memory_bytes: 35456
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define F first
#define S second
#define INF 1 << 30

typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;

vi p, next, now;
vector<vector<int> >dir(13);

int main(){
  rep(i, 13) if(i == 0 || i == 12) p.push_back(0); else p.push_back(i);

  dir[0].push_back(2);
  dir[1].push_back(2); dir[1].push_back(5);
  dir[2].push_back(0); dir[2].push_back(1); dir[2].push_back(3); dir[2].push_back(6);
  dir[3].push_back(2); dir[3].push_back(7);
  dir[4].push_back(5);
  dir[5].push_back(1); dir[5].push_back(4); dir[5].push_back(6); dir[5].push_back(9);
  dir[6].push_back(2); dir[6].push_back(5); dir[6].push_back(7); dir[6].push_back(10);
  dir[7].push_back(3); dir[7].push_back(6); dir[7].push_back(8); dir[7].push_back(11);
  dir[8].push_back(7);
  dir[9].push_back(5); dir[9].push_back(10);
  dir[10].push_back(6); dir[10].push_back(9); dir[10].push_back(11); dir[10].push_back(13);
  dir[11].push_back(7); dir[11].push_back(10);
  dir[12].push_back(10);

  map<vi, int>m;
  queue<vi>q;
  q.push(p);
  m[p] = 0;
  rep(i, 10){
    int qsize = q.size();
    rep(j, qsize){
      now = q.front(); q.pop();
      rep(k, 13){
	if(now[k] != 0) continue;
	rep(d, dir[k].size()){
	  next = now;
	  swap(next[k], next[dir[k][d]]);
	  if(m.count(next) != 0) continue;
	  m[next] = i+1;
	  q.push(next);
	}
      }
    }
  }

  p.resize(13);
  while(scanf("%d", &p[0]) && p[0] != -1){
    REP(i, 1, 13) scanf("%d", &p[i]);

    map<vi, int>dist;
    queue<vi>q;
    q.push(p);
    dist[p] = 0;
    if(m.count(p) != 0){
      printf("%d\n", m[p]);
      goto e;
    }

    rep(i, 10){
      int qsize = q.size();
      rep(j, qsize){
	now = q.front(); q.pop();
	rep(k, 13){
	  if(now[k] != 0) continue;
	  rep(d, dir[k].size()){
	    next = now;
	    swap(next[k], next[dir[k][d]]);
	    if(m.count(next) != 0){
	      printf("%d\n", m[next]+i+1);
	      goto e;
	    }
	    if(dist.count(next) != 0) continue;
	    dist[next] = i+1;
	    q.push(next);
	  }
	}
      }
    }
    puts("NA");
  e:;
  }
  return 0;
}

Measured memory_bytes: 6352
def main():
    n=int(input())
    aa=list(map(int,input().split()))
    b=0
    i=1
    while True:
        try:
            j=aa.index(i,b)
        except ValueError:
            break
        b=j+1
        i+=1
    if i<=1:
        print(-1)
    else:
        print(n-i+1)

main()

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

int main(){
    string S;
    
    //空白も含めて一行丸ごとを文字列として受け取る為にgetline関数を使う
    getline(cin, S);

    for(int i = 0; i < (int)S.size(); i++){
        if('a' <= S[i] && S[i] <= 'z'){
            S[i] = S[i]-'a'+'A';
        }else if('A' <= S[i] && S[i] <= 'Z'){
            S[i] = S[i]-'A'+'a';
        }
    }
    cout << S << endl;
    return 0;
}


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

int main()
{
	double i=1,a,b;
	cin>>a>>b;
	double a1=i/0.08,b1=i/0.1;
	while(int(a1)!=a || int(b1)!=b)
	{
		i++;
		a1=i*0.08;
		b1=i*0.1;
		if(i>=(b+1)/0.1)
		{
			cout<<"-1";
			return 0;
		}
	}	
	cout<<i;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){
  string str;
  int ab[26]={};
  int i;
  while(getline(cin,str)){
    for(i=0;i<str.size();i++){
      if(str[i]>='a'&&str[i]<='z') ab[str[i]-'a']++;
      else if(str[i]>='A'&&str[i]<='Z') ab[str[i]-'A']++;
    }
  //cout << str << endl;
  }
  for(i=0;i<26;i++){
    cout << (char)('a'+i) << " : " << ab[i] << endl;
  }
  return 0;
}



Measured memory_bytes: 3144
package main

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

var sc *bufio.Scanner
var out *bufio.Writer

func main() {
	sc = bufio.NewScanner(os.Stdin)
	out = bufio.NewWriter(os.Stdout)
	buf := make([]byte, 1024*1024)
	sc.Buffer(buf, bufio.MaxScanTokenSize)
	sc.Split(bufio.ScanWords)
	defer out.Flush()

	k := nextInt()

	s := []int{7, 77, 777, 7777, 77777, 777777, 7777777}
	result := 0
	for i, si := range s {
		if k <= si {
			result = i + 1
			break
		}
	}
	find := false
	div := s[result-1]
	for i := result - 1; i < k; i++ {
		kmod := div % k
		if kmod == 0 {
			find = true
			break
		}
		div, _ = strconv.Atoi(strconv.Itoa(kmod) + "7")
		result++
	}
	if !find {
		result = -1
	}

	fmt.Fprintln(out, result)
}

func next() string {
	sc.Scan()
	return sc.Text()
}
func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}


Measured memory_bytes: 5340
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll MOD = 1e9 + 7;
int main() {
	int N;
	string s, t;
	cin >> N >> s >> t;
	string u = s;
	if (s == t) { cout << s.size() << endl; return 0; }
	for (int i = 1; i <= N; i++) {
		if (s.substr(N - i, i) == t.substr(0, i)) {
			s += t.substr(i, N - i);
		}
	}
	if (s != t && s == u) { s += t; }
	cout << s.size() << endl; 
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+1000;
struct Node{
	int sum,Id;
}Even[N],Odd[N];
int n;
bool cmp(Node A,Node B){
	return A.sum>B.sum;
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;++i){
		int x;
		scanf("%d",&x);
		if(i%2){
			Odd[x].sum++;
			Odd[x].Id=x;
		}	
		else{
			Even[x].sum++;
			Even[x].Id=x;
		}
	}	
	sort(Odd+1,Odd+1+100000,cmp);
	sort(Even+1,Even+1+100000,cmp);
	if(Odd[1].Id!=Even[1].Id){
		cout<<n-Odd[1].sum-Even[1].sum;
	}
	else{
		cout<<min(n-Odd[1].sum-Even[2].sum,n-Odd[2].sum-Even[1].sum);
	}
}

Measured memory_bytes: 1792
package main

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

func main() {
	sc := NewScanner()

	n := sc.ReadInt()
	m := sc.ReadInt()

	a := make([]int, m)
	for i := 0; i < m; i++ {
		a[i] = sc.ReadInt()
	}

	total := 0
	for i := 0; i < m; i++ {
		total += a[i]
	}

	if total > n {
		fmt.Println(-1)
	} else {
		fmt.Println(n - total)
	}
}

// util
// *   math/simple

func Abs(x int) int {
	if x >= 0 {
		return x
	}
	return -x
}

func Min(values ...int) int {
	if len(values) == 0 {
		panic("no values")
	}
	min := values[0]
	for _, v := range values {
		if v < min {
			min = v
		}
	}
	return min
}

func Max(values ...int) int {
	if len(values) == 0 {
		panic("no values")
	}
	max := values[0]
	for _, v := range values {
		if v > max {
			max = v
		}
	}
	return max
}

func Pow(base int, exponent uint) int {
	answer := 1
	for i := uint(0); i < exponent; i++ {
		answer *= base
	}
	return answer
}

func Abs64(x int64) int64 {
	if x >= 0 {
		return x
	}
	return -x
}

func Min64(values ...int64) int64 {
	if len(values) == 0 {
		panic("no values")
	}
	min := values[0]
	for _, v := range values {
		if v < min {
			min = v
		}
	}
	return min
}

func Max64(values ...int64) int64 {
	if len(values) == 0 {
		panic("no values")
	}
	max := values[0]
	for _, v := range values {
		if v > max {
			max = v
		}
	}
	return max
}

func Pow64(base int64, exponent uint) int64 {
	answer := int64(1)
	for i := uint(0); i < exponent; i++ {
		answer *= base
	}
	return answer
}

// *   io

type Scanner struct {
	bufScanner *bufio.Scanner
}

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

func (sc *Scanner) ReadString() string {
	bufSc := sc.bufScanner
	bufSc.Scan()
	return bufSc.Text()
}

func (sc *Scanner) ReadInt() int {
	bufSc := sc.bufScanner
	bufSc.Scan()
	text := bufSc.Text()

	num, err := strconv.Atoi(text)
	if err != nil {
		panic(err)
	}
	return num
}

func (sc *Scanner) ReadInt64() int64 {
	bufSc := sc.bufScanner
	bufSc.Scan()
	text := bufSc.Text()

	num, err := strconv.ParseInt(text, 10, 64)
	if err != nil {
		panic(err)
	}
	return num
}


Measured memory_bytes: 1876
#include <stdio.h>
#include <stdlib.h>

int _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 main(void) {
	int N, ans, i, j, tar;
	long long int *A;

	scanf("%d", &N);
	getchar();
	A = (long long int *) malloc(sizeof *A * N);
	for(i = 0; i < N; i++) {
		scanf("%lld", &A[i]);
		getchar();
	}

	qsort(A, N, sizeof *A, _compare);
	i = j = tar = 0;
	while(j < N && i < N) {
		while(A[i] == A[j]) {
			j++;
			if(j == N)
				break;
		}
		if((j - i) % 2 == 1)
			tar++;
		i = j;
		j = i;
		if(i == N)
			break;
	}
	printf("%d", tar);

	free(A);

	return 0;
}

Measured memory_bytes: 1788
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        final int N = sc.nextInt();
        int M = sc.nextInt();
        long[] X = new long[N];
        long[] Y = new long[N];
        long[] Z = new long[N];
        int[] sg = {1, -1};
        for(int i = 0;i < N;i++){
            X[i] = sc.nextLong();
            Y[i] = sc.nextLong();
            Z[i] = sc.nextLong();
        }
        long ans = 0;
        long[] S = new long[N];
        for(int i = 0;i < 2;i++){
            for(int j = 0;j < 2;j++){
                for(int k = 0;k < 2;k++){
                    long ans2 = 0;
                    for(int l = 0;l < N;l++){
                        S[l] = X[l]*sg[i]+Y[l]*sg[j]+Z[l]*sg[k];
                    }
                    Arrays.sort(S);
                    for(int l = N-1;l > N-M-1;l--)   ans2 += S[l]; 
                    ans = Math.max(ans, ans2);
                }   
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 27848
n = gets.to_i
ts, xs, ys = [], [], []
n.times do
  ti, xi, yi = gets.split.map(&:to_i)
  ts << ti; xs << xi; ys << yi
end

def can_travel(n, ts, xs, ys)
  t, x, y = 0, 0, 0
  n.times do |i|
    ti, xi, yi = ts[i], xs[i], ys[i]
    dt, dx, dy = ti - t, xi - x, yi - y
    dd = dx.abs + dy.abs

    return false if dt < dd || (dd - dt).odd?

    t, x, y = ti, xi, yi
  end

  true
end

puts can_travel(n, ts, xs, ys) ? 'Yes' : 'No'

Measured memory_bytes: 4260
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  int n;
  cin >> n;
  int t[n], acc = 0;
  rep(i, 0, n) {
    cin >> t[i];
    acc += t[i];
  }

  int m;
  cin >> m;
  rep(i, 0, m) {
    int p, x;
    cin >> p >> x;
    cout << acc - t[p - 1] + x << endl;
  }
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){
	double a;
	string b;
	while(cin>>a){
		if(a<=48)
			b="light fly";
		if(a>48&&a<=51)
			b="fly";
		if(a>51&&a<=54)
			b="bantam";
		if(a>54&&a<=57)
			b="feather";
		if(a>57&&a<=60)
			b="light";
		if(a>60&&a<=64)
			b="light welter";
		if(a>64&&a<=69)
			b="welter";
		if(a>69&&a<=75)
			b="light middle";
		if(a>75&&a<=81)
			b="middle";
		if(a>81&&a<=91)
			b="light heavy";
		if(a>91)
			b="heavy";
		cout<<b<<endl;
	}
	return 0;
}

Measured memory_bytes: 1220
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}

template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

// -------------------------------------------------------
int N, R;

int main()
{
    cin >> N >> R;
    if (N >= 10)
    {
        cout << R << endl;
        return 0;
    }
    else
    {
        cout << R + 100 * (10 - N) << endl;
        return 0;
    }
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include<algorithm> // sort
#include<map> // pair
#include<cmath>
#include<cstring>
#include<set>
using namespace std;
using ll = long long;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
#define all(x) (x).begin(),(x).end()
const ll mod = 1e9+7;
const int INF = 1e9;
const ll INFLONG = 1e18;
ll visited[100000];
vector<ll> vec[100000];
ll score[100000];
ll n,k;
bool dp(int x,int y){
  if(visited[x] == 0){
    score[x] = y;
    visited[x] = 1;
    int tmp=2;
    if(x == 0){
      tmp = 1;
    }
    for(auto itr:vec[x]){
      if(dp(itr,k-tmp)){
        tmp++;
      }
    }
    return true;
  }else{
    return false;
  }
}
int main(){
  ll x,y;
  cin >> n >> k;
  rep(i,n-1){
    cin >> x >> y;
    vec[x-1].push_back(y-1);
    vec[y-1].push_back(x-1);
  }
  memset(visited,0,sizeof(visited));
  dp(0,k);
  ll mul=1;
  rep(i,n){
    //cout << score[i] << " ";
    //cout << mul << endl;
    mul = (mul * score[i]) % mod;
  }
  cout << mul;
}


Measured memory_bytes: 9600
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main(){
    int w,h,n;
    cin>>w>>h>>n;
    int x,y,a;
    int a1=-1,a2=101,a3=-1,a4=101;
    while(n--){
        cin>>x>>y>>a;
        if(a==1){
            a1=max(a1,x);
        }else if(a==2){
            a2=min(a2,x);
        }else if(a==3){
            a3=max(a3,y);
        }else{
            a4=min(a4,y);
        }
    }

    if (a1==-1)
        a1=0;
    if (a2==101)
        a2=w;
    if (a3==-1)
        a3=0;
    if (a4==101)
        a4=h;


    if (a2<a1){
        cout<<0;
    }else if(a4<a3){
        cout<<0;
    }else{
        cout<<((a2-a1)*(a4-a3));
    }
    return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <functional>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <cassert>
using namespace std;

#define EPS 1e-12
#define ull unsigned long long
#define ll long long
#define VI vector<ll>
#define PII pair<ll, ll> 
#define VVI vector<vector<ll> >
#define REP(i,n) for(int i=0,_n=(n);(i)<(int)_n;++i)
#define RANGE(i,a,b) for(int i=(int)a,_b=(int)(b);(i)<_b;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define ALLR(c) (c).rbegin(), (c).rend()
#define PB push_back
#define MP(a, b) make_pair(a, b)
#define POPCOUNT __builtin_popcount
#define POPCOUNTLL __builtin_popcountll
#define CLEAR(table, v) memset(table, v, sizeof(table));
#define PRINT1(table, D0) REP(d0, D0) cout<<table[d0]<<" "; cout<<"\n";
#define PRINT2(table, D0, D1) REP(d0, D0) { REP(d1, D1) cout<<table[d0][d1]<<" "; cout<<"\n"; }
#define PRINT3(table, D0, D1, D2) REP(d0, D0) { REP(d1, D1) { REP(d2, D2) cout<<table[d0][d1][d2]<<" "; cout<<"\n"; } cout<<"\n"; }
#define UNIFORM_DOUBLE(a, b) (((b-a)*(double)rand()/RAND_MAX)+a) // [a, b) 
#define UNIFORM_LL(a, b) (ll)UNIFORM_DOUBLE(a, b) // [a, b) 
#define IN(v, lo, hi) ((lo)<=(v) && (v)<(hi))
#define DD(v) cout<<#v<<": "<<v<<endl
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const map<T0, T1>& v) { for( typename map<T0, T1>::const_iterator p = v.begin(); p!=v.end(); p++ ){os << p->first << ": " << p->second << " ";} return os; }
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const pair<T0, T1>& v) { os << v.first << ": " << v.second << " "; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << " "; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<vector<T> >& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << endl; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const set<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const deque<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }

#define MOD 1000000007LL
#define INF (1LL<<60)

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll N,M,W,H,K;
	string s;
	while(cin>>N>>K) {
		cout<<(N%K==0?0:1)<<endl;
	}
	
	return 0;
}


Measured memory_bytes: 764
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>

using namespace std;

int main(){
	int A,B,C,K;
	cin>>A>>B>>C;
	cin>>K;
	
	if(A>=B && A>=C)
		cout<<A*pow(2,K)+B+C<<endl;
	else if(B>=A && B>= C)
		cout<<A+B*pow(2,K)+C<<endl;
	else
		cout<<A+B+C*pow(2,K)<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
int main(){
	int a,b,c,t;
	scanf("%d %d %d",&a,&b,&c);
	if(a>c){
		t=c;
		c=a;
		a=t;
	}
	if(b>c){
		t=c;
		c=b;
		b=t;
	}
	if(a>b){
		t=b;
		b=a;
		a=t;
	}
	printf("%d %d %d\n",a,b,c);
}

Measured memory_bytes: 2688
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define st string
#define dl double
#define ve(i) vector<i>
#define repi(i, m, n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i, n) repi(i, 0, n)
#define each(i, n) for(auto&& i: n)
#define pr(n) cout << fixed << setprecision(n)
#define co(n) cout << n << endl;

int main() {
  int a;
  st s;
  cin >> a >> s;
  if(a >= 3200) {
    co(s);
  }
  else {
    co("red");
  }
}  

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

signed main(){
    int t = 1; //cin >> t;
    while(t--){
    	int n,k; cin >> n >> k;
    	int ans = 0;
    	if(k == 0){
    		cout << n*n;
    		return 0;
    	}
    	for(int i = k+1; i <= n; i++)
    	{
    		int x = i - k;
    		int z = n/i;
    		ans += z*x + max(0LL,n%i-k+1);
    		//cout << ans << endl;
    	}
    	cout << ans;
    }    
}

Measured memory_bytes: 3624
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

#include <boost/lexical_cast.hpp>

#define FOR(i, a, b) for (int i = (a); i < int(b); ++i)
#define RFOR(i, a, b) for (int i = (b)-1; i >= int(a); --i)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, int(n) + 1)
#define RREP(i, n) RFOR(i, 0, n)
#define RREP1(i, n) RFOR(i, 1, int(n) + 1)
#define ALL(c) begin(c), end(c)

int _ = (
#ifndef LOCAL
    std::cin.tie(nullptr), std::ios::sync_with_stdio(false),
#endif
    std::cout.precision(10), std::cout.setf(std::ios::fixed));

using ll = long long;
using ull = unsigned long long;
using ld = long double;
template <typename T> using vec = std::vector<T>;
using namespace std;

int main() {
  string a, b;
  cin >> a >> b;
  const auto ab = a + b;
  const auto n = boost::lexical_cast<int>(ab);
  bool ok = false;
  REP1(i, 333) {
    if (i * i == n) {
      ok = true;
    }
  }
  cout << (ok ? "Yes" : "No") << endl;
  return 0;
}


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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<ll> vll;

#define PI (2*acos(0.0))
#define eps 1e-9
#define pcase cout<<"Case "<<++cs<<":"
#define pb push_back
#define endl "\n"
#define watch(x) cout << (#x) << " is " << (x) << endl;
#define show(v) for(int fi = 0; fi < v.size(); fi++) cout << v[fi] << " "; cout << endl;
#define showpair(v) for(int fi = 0; fi < v.size(); fi++) cout << v[fi].first << " " << v[fi].second << endl;
#define mp make_pair
#define ff first
#define ss second
#define fu cout << "lol" << endl;
#define precision(n) cout << fixed << setprecision(n);
#define lb lower_bound
#define up upper_bound
#define vscan for(i = 0;i<n;i++){cin>>in; v.pb(in);}
#define all(a) a.begin(), a.end()
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define mem(a,val) memset(a,val,sizeof(a))
#define loop(i,n) for(i = 0; i < n; i++)
#define TC() ull T; cin>>T; while(T--)
#define IN(x) {scanf("%d",&x);}
#define LL(x) {scanf("%lld",&x);}
#define CC(x) {scanf("%c",&x);}
#define pfl(x) printf("%d\n",x)
#define pfll(x) printf("%lld\n",x)
#define newl puts("")
#define space printf(" ")
#define MOD 1000000007
#define inf 10000000000

ll dp[105][100005];

int main()
{
    int i = 0, j = 0, cs = 0, in;
    int n,k; cin>>n>>k;
    vi v; vscan;
    for(i = 0; i < n; i++) for(j = 0; j < 100; j++) dp[j][i] = inf;
    for(i = 0; i < k; i++) dp[i][0] = 0;
    for(i = 1; i < k; i++) dp[i][1] = abs(v[1] - v[0]);
    ll arr[n+5]; for(i = 0; i < n; i++) arr[i] = inf;
    arr[0] = 0; arr[1] = abs(v[1] - v[0]);
    for(i = 2; i < n; i++){
        for(j = 0; j < k && j < i; j++){
            dp[j][i] = arr[i-j-1] + abs(v[i-j-1] - v[i]);
            arr[i] = min(arr[i], dp[j][i]);
        }
    }
    ll MIN = inf;
    for(i = 0 ; i < k; i++) MIN = min(MIN, dp[i][n-1]);
    cout << MIN << endl;
    return 0;
}


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

using namespace std;

int main(){
	
	int a, b, c;
	std::cin >> a >> b >> c;

	if ((a-c) * (b-c) < 0){
		std::cout << "Yes" << std::endl;
	}else{
		cout << "No"<< endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <cstdlib>
#include <stack>
#include <queue>
#include <list>
#include <vector>

using namespace std;

class c_sum
{
private:

public:
    c_sum();
    void f_input();
    int f_sum(unsigned int *a, int r1, int r2);
};

c_sum::c_sum()
{

}

void c_sum::f_input()
{
    int n;
    int q;
    int i, j, k;
    unsigned int a[100000];
    int c1;
    int c2;
    int c3;
    int temp1;
    int temp2;
    
    cin >> n >> q;
    
    for ( i = 0; i < n; ++i){
        a[i] = 0;
    }
    
    //for (i=0; i<n; ++i){
    //    cout << "a[" << i << "]: " << a[i] << endl;
    //}
    
    for ( i = 0; i < q; ++i){
        cin >> c1 >> c2 >> c3;
        temp2 = c2-1;
        //cout << "temp2: " <<  temp2 << endl;
        if (c1 == 1){
            cout << f_sum(a,c2-1,c3-1) << endl;
        }else if (c1 == 0){
            a[temp2] = a[temp2] + c3;
            
            //for (k=0; k<n; ++k){
            //    cout << "a[" << k << "]: " << a[k] << endl;
            //}
        }
    }
    
    //for (i=0; i<n; ++i){
    //    cout << "a[" << i << "]: " << a[i] << endl;
    //}
}

int c_sum::f_sum(unsigned int *a, int r1, int r2){
    int temp1;
    int i;
    int temp_sum;
    unsigned int *temp_a;
    
    temp_a = &*a;
    
    temp_sum = 0;
    
    for (i = r1; i < r2 +1;++i){
        temp_sum = temp_sum + temp_a[i]; 
    }
    
    temp1 = temp_sum;
    
    return temp1;
}

int main(){
    
    c_sum sum01;
    sum01.f_input();
    
    return 0;
}

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

using namespace std;

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

	int min = 0, max = n - 1,s1 = 0,s2 = 0;
	for(int i=0;i<n;i++)
	{
		if (s1 <= s2)
		{
			s1 += w[min];
			min++;
		}
		else
		{
			s2 += w[max];
			max--;
		}
	}

	if (s1 > s2) swap(s1, s2);

	cout << s2 - s1 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <limits>
#include <numeric>
#include <algorithm>
#include <functional>

using namespace std;

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

	long long K, A, B;
	cin >> K >> A >> B;

	cout << max(K + 1, (K - A + 1) / 2 * (B - A) + A + (K - A + 1) % 2);

	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#include<string>
#include<math.h>
#include <numeric>

using namespace std;
typedef long long ll;

#define REP(i,n) for(int i=0;i<n;++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define pn(s) cout << (#s) << " " << (s) << endl

const ll mod = 1e9 + 7;
const ll inf = 1e18;

void printVector(vector<ll> A){
    cout << "[vector]" << endl;
    for(int i=0; i<A.size(); i++){
        cout << A[i] << " ";
    }
    cout << endl;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    // input
    int N, x;
    cin >> N >> x;

    vector<ll> a(N);
    FOR(i, 0, N) cin >> a[i];

    sort(ALL(a));

    ll childSweetSum = accumulate(ALL(a), 0LL);

    ll sweetNum = x;
    if(sweetNum > childSweetSum){
        p(N-1);
    }else if(sweetNum == childSweetSum){
        p(N);
    }
    // sweet shortage (sweets num < x)
    else{
        if(sweetNum < a[0]){
            p(0);
            return 0;
        }

        ll currentSweetSum = 0;
        FOR(i, 0, N){
            currentSweetSum += a[i];
            if(currentSweetSum == sweetNum){
                p(i+1);
                return 0;
            }
            else if(currentSweetSum > sweetNum){
                p(i);
                return 0;
            }
        }
    }

    return 0;
}

Measured memory_bytes: 256
use proconio::input;
use proconio::marker::Chars;

fn main() {
    input! {
        w: Chars,
    }

    solve(&w);
}

fn solve(w: &Vec<char>) {
    let mut cnt = [0; 26];
    for c in w {
        match c {
            'a' => cnt[0] += 1,
            'b' => cnt[1] += 1,
            'c' => cnt[2] += 1,
            'd' => cnt[3] += 1,
            'e' => cnt[4] += 1,
            'f' => cnt[5] += 1,
            'g' => cnt[6] += 1,
            'h' => cnt[7] += 1,
            'i' => cnt[8] += 1,
            'j' => cnt[9] += 1,
            'k' => cnt[10] += 1,
            'l' => cnt[11] += 1,
            'm' => cnt[12] += 1,
            'n' => cnt[13] += 1,
            'o' => cnt[14] += 1,
            'p' => cnt[15] += 1,
            'q' => cnt[16] += 1,
            'r' => cnt[17] += 1,
            's' => cnt[18] += 1,
            't' => cnt[19] += 1,
            'u' => cnt[20] += 1,
            'v' => cnt[21] += 1,
            'w' => cnt[22] += 1,
            'x' => cnt[23] += 1,
            'y' => cnt[24] += 1,
            'z' => cnt[25] += 1,
            _ => {}
        }
    }
    for num in cnt.iter() {
        if num % 2 == 1 {
            println!("No");
            return;
        }
    }
    println!("Yes");
}


Measured memory_bytes: 2156
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef long int li;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
typedef pair<ll, ll>P;
typedef tuple<double,ll,ll>T;
#define PI 3.14159265358979
const int MOD = 1e9 + 7;

int main(){
  ll N,K;
  cin>>N>>K;
  vector<ll>A(N);
  rep(i,N){
  	cin>>A[i];
  }
  vector<ll>a(45);
  rep(i,45){a[i]=0ll;}
  rep(i,N){
    ll p=A[i];
  	rep(j,45){
    	if(p%2ll==1ll){a[j]++;}
      	p/=2ll;
    }
  }
  ll dp[45][2];
  rep(i,45){dp[i][0]=-1ll;dp[i][1]=-1ll;}
  dp[44][0]=0ll;
  for(int i=43;i>=0;i--){
    if(dp[i+1][1]>=0){
      dp[i][1]=max(dp[i][1],dp[i+1][1]+a[i]*(ll)pow(2ll,i));
      dp[i][1]=max(dp[i][1],dp[i+1][1]+(N-a[i])*(ll)pow(2ll,i));
    }
	if(K&(1ll<<i)){
      dp[i][1]=max(dp[i][1],dp[i+1][0]+a[i]*(ll)pow(2ll,i));
      dp[i][0]=max(dp[i][0],dp[i+1][0]+(N-a[i])*(ll)pow(2ll,i));
    }
    else{
      dp[i][0]=max(dp[i][0],dp[i+1][0]+a[i]*(ll)pow(2ll,i));
    }
  }
  cout<<max(dp[0][0],dp[0][1])<<endl;
  
} 


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef vector<int> vei;
typedef vector<string> ves;
typedef vector<vector<int>> ve_vei;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define fs first
#define sc second
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
 
int main() {
	//cout.precision(10);
	cin.tie(0);
	ios::sync_with_stdio(false);
    int N; cin >> N;
    vei A(N); 
    rep(i,N) cin >> A[i];
    sort(A.rbegin(),A.rend());

    cout << A[0] - A[N - 1] << endl; 
}

Measured memory_bytes: 892
public class Main {


  private static void solve() {
    long a = nl();
    long b = nl();
    long c = ni();
    long d = ni();

    {
      long aa = a - 1;
      long x = aa - aa / c - aa / d + aa / (c * d / gcd(c, d));
      long y = b - b / c - b / d + b / (c * d / gcd(c , d));
      
      System.out.println(y - x);
    }
  }

  public static long gcd(long a, long b) {
    if (a > b) {
        long tmp = a;
        a = b;
        b = tmp;
    }
    while (a != 0) {
        long c = a;
        a = b % c;
        b = c;
    }
    return b;
}
  
  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

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

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}


Measured memory_bytes: 22612
#include<bits/stdc++.h>
// #include <atcoder/all>
#define ll long long int
#define rep(i,n) for(ll i=0;i<n;i++)
#define vec vector<ll>
#define mat vector<vector<ll>>

using namespace std;
// using namespace atcoder;

const ll mod=1000000007;//998244353;
const ll inf=LONG_LONG_MAX;
ll dx4[4]={1,0,-1,0};
ll dy4[4]={0,-1,0,1};
ll dx8[8]={1,0,-1,1,-1,1,0,-1};
ll dy8[8]={1,1,1,0,0,-1,-1,-1};

int main(){

  ll h,w,k;
  cin >> h >> w >> k;

  mat e(h,vec(w));
  rep(i,h){
    rep(j,w){
      char c;
      cin >>c;
      e[i][j]=c-'0';
    }
  }

 
  ll ans=h+w-2;

  mat s(h,vec(w+1));
  rep(i,h){
    rep(j,w)s[i][j+1]=s[i][j]+e[i][j];
  }
 
  for(ll b=0;b<(1<<(h-1));b++){
    ll a=1;
    for(ll i=0;i<h-1;i++)if(b & (1<<i))a++;
    mat t(a,vec(w+1));
    ll p=-1,q=-1;
    ll c=-1;
    for(ll i=0;i<h-1;i++){
      if(b& (1<<i)){
        c++;
        p=q;
        q=i;
        //cout << q << endl;
        for(ll j=0;j<w+1;j++){
          for(ll k=p+1;k<=q;k++)t[c][j]+=s[k][j];
        }
      }
    }
    c++;
    p=q;
    q=h-1;
    //cout << p << " " << q << " " << c << endl;
    for(ll j=0;j<w+1;j++){
      for(ll r=p+1;r<=q;r++)t[c][j]+=s[r][j];
    }

    ll m=0;

    // if(b==2){
    //   for(ll i=0;i<a;i++){
    //     for(ll j=0;j<w+1;j++)cout << t[i][j] << " ";
    //     cout << endl;
    //   }
    // }


    c=1;
    ll d=0;
    ll l;
    while(c<w+2){
      l=0;
      for(ll i=0;i<a;i++)l=max(l,t[i][c]-t[i][d]);
      if(l<=k)c++;
      else{
        d=c-1;
        m++;
      }
      if(c==w+1)break;
      if(m>=w+h)break;
    }

    l=0;
    c=m;
    for(ll i=0;i<a;i++)l=max(l,t[i][c]-t[i][d]); 
    //if(b==2)cout << c << " " << m << " " << l << endl;
    if(l>k)continue;
    if(m>=w+h)continue;

    m+=(a-1);
    //if(m==0)cout <<  b << endl;
    ans=min(ans,m);


  }

  cout << ans << endl;

  //cout << (1<<1) << endl;

  return 0;
}

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

int main(void){
    int n = 0, k = 0; 
    int ans = 1;

    scanf("%d%d", &n, &k);

    ans *= k;
    for(int i = 1; i < n; i++){
        ans *= (k - 1);
    }

    printf("%d\n", ans);

    return 0;

} 


Measured memory_bytes: 256