akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

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

  if(K==1) cout <<1<<endl;
  if(K==2) cout <<1<<endl;
  if(K==3) cout <<1<<endl;
  if(K==4) cout <<2<<endl;
  if(K==5) cout <<1<<endl;
  if(K==6) cout <<2<<endl;
  if(K==7) cout <<1<<endl;
  if(K==8) cout <<5<<endl;
  if(K==9) cout <<2<<endl;
  if(K==10) cout <<2<<endl;
  if(K==11) cout <<1<<endl;
  if(K==12) cout <<5<<endl;
  if(K==13) cout <<1<<endl;
  if(K==14) cout <<2<<endl;
  if(K==15) cout <<1<<endl;
  if(K==16) cout <<14<<endl;
  if(K==17) cout <<1<<endl;
  if(K==18) cout <<5<<endl;
  if(K==19) cout <<1<<endl;
  if(K==20) cout <<5<<endl;
  if(K==21) cout <<2<<endl;
  if(K==22) cout <<2<<endl;
  if(K==23) cout <<1<<endl;
  if(K==24) cout <<15<<endl;
  if(K==25) cout <<2<<endl;
  if(K==26) cout <<2<<endl;
  if(K==27) cout <<5<<endl;
  if(K==28) cout <<4<<endl;
  if(K==29) cout <<1<<endl;
  if(K==30) cout <<4<<endl;
  if(K==31) cout <<1<<endl;
  if(K==32) cout <<51<<endl;
     return 0;
}


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

template <typename T>
T gcd(T a, T b){
  if(a%b == 0){
    return(b);
  }
  else {
    return(gcd(b, a%b));
  }
}
template <typename T>
T lcm(T a, T b){
  return a * b / gcd(a, b);
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long a, b;
  cin >> a >> b;
  cout << lcm(a, b) << '\n';

  return 0;
}


Measured memory_bytes: 256
const main = (input: string) => {
  const lines = input.trim().split("\n")
  const N = parseInt(lines[0])
  const P = lines[1].split(" ").map(str => parseInt(str))
  let minNum = P[0]
  let count = 1

  for (let i = 1; i < N; i++) {
    if(minNum > P[i]) {
      minNum = P[i]
      count += 1
    }
  }

  console.log(count)
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 22328
#include<iostream>
#include<stack>
using namespace std;
int main(){
  stack<int> c;
  int n;
  while(cin >>n){
    if(n == 0){
      cout <<c.top()<<endl;
      c.pop();
    } else{
      c.push(n);
    }
  }
  return 0;
}

Measured memory_bytes: 1200
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<iomanip>
#include<map>
#include<utility>
#include<string>
#include<unordered_map>
#include<queue>

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

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
int gcd(int a, int b){return b ? gcd(b, a%b) : a;}
int lcm(int a, int b){return a*b / gcd(a, b);}

int R, G, B, n;

int main(){
    cin >> R >> G >> B >> n;
    int ans = 0;
    for(int r = 0; r <= n; r++){
        for(int g = 0; g <= n; g++){
            int x = n-r*R-g*G;
            if(x >= 0 && x%B == 0) ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3640
// Aizu Vol-1 0127: Pocket Pager Input
// 2017.8.1

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>

char *gets(char *);

char a[100];
char buf[300], *p;
char ans[300], *q;

int main()
{
	int k;

	a[11] = 'a', a[12] = 'b', a[13] = 'c', a[14] = 'd', a[15] = 'e';
	a[21] = 'f', a[22] = 'g', a[23] = 'h', a[24] = 'i', a[25] = 'j';
	a[31] = 'k', a[32] = 'l', a[33] = 'm', a[34] = 'n', a[35] = 'o';
	a[41] = 'p', a[42] = 'q', a[43] = 'r', a[44] = 's', a[45] = 't';
	a[51] = 'u', a[52] = 'v', a[53] = 'w', a[54] = 'x', a[55] = 'y';
	a[61] = 'z', a[62] = '.', a[63] = '\?', a[64] = '!', a[65] = ' ';

	while (gets(buf) != NULL) {
		q = ans, p = buf;
		while (*p) {
			if (isdigit(*p) && isdigit(*p + 1)) {
				k = *p++ - '0';
				k = 10 * k + (*p++ - '0');
				if (a[k] > 0) *q++ = a[k];
				else goto NA;
			} else goto NA;
		}
		*q = 0;
		puts(ans);
		continue;
NA:		puts("NA");
	}
	return 0;
}

Measured memory_bytes: 524
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<long>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
using pll = pair<long, long>;
#define fix20 cout << fixed << setprecision(20);
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define MOD 1000000007
#define all(vec) vec.begin(), vec.end()

int main(){
    long n,k;
    cin >> n >> k;
    int cnt = 0;
    while(n > 0){
        n /= k;
        cnt++;
    }
    cout << cnt << endl;
}

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

int main(){
  int n,a[100001],k;
  cin>>n;
  for(int i=1;i<=n;i++){
    cin>>a[i];
  }
  k=0;
  for(int i=1;i<=n;i++){
    if(a[ a[i] ]==i&&a[i]>i)k++;
  }
  cout<<k<<endl;
  return 0;
}


Measured memory_bytes: 640
import java.io._
import java.util.StringTokenizer
import scala.util.control.Breaks.{breakable,break}
import java.util.Scanner

object Main extends App {
  val in = new InputReader(System.in)
  val pw = new PrintWriter(System.out)

  //val sc = new Scanner(System.in)

  val s = in.next()
  //val s = sc.nextLine()

  var ans = 0L
  var cnt = 0L
  var i = 0
  while (i < s.length - 1) {
    val now = s(i)
    if (now == 'A') {
      cnt += 1
      i += 1
    }
    else if (now == 'C') {
      cnt = 0
      i += 1
    }
    else if (now == 'B') {
      if (s(i+1) == 'C') {
        ans += cnt
        i += 2
      }
      else {
        cnt = 0
        i += 1
      }
    }
  }
  println(ans)
}


class InputReader(stream: InputStream) {
  private val reader = new BufferedReader(new InputStreamReader(stream))
  private var tokenizer: StringTokenizer = new StringTokenizer(reader.readLine())
  def next(): String = {
    while (!tokenizer.hasMoreTokens()) {
      tokenizer = new StringTokenizer(reader.readLine())
    }
    tokenizer.nextToken()
  }
}


Measured memory_bytes: 29432
a, n, m = map(int, input().split())
ans = 0
for i in range(a, int(m ** (1 / 2)) + 1):
  x = i ** n
  if not 1 <= x <= m:
    continue
  y = i - a
  if sum(map(int, list(str(x)))) == y:
    ans += 1
print(ans)


Measured memory_bytes: 5624
/* ITP1_4_D */
import java.io.*;

class Main
{
  public static void main(String[] args) throws IOException
  {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

    // input
    int quantity = Integer.parseInt(br.readLine());
    String[] str = br.readLine().split(" ");
    int min = 0;
    int max = 0;
    long sum = 0;

    for(int i = 0; i < quantity; i++){

      int value = Integer.parseInt(str[i]);

      if(i == 0){
        min = value;
        max = value;
        sum = value;
      }else {
        //check
        if(min > value)
          min = value;
        if(max < value)
          max = value;
        sum += value;
      }
    }
    // output
    System.out.println(min + " " + max + " " + sum);
  }
}

Measured memory_bytes: 28444
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	string s;
	cin>>s;
	ll scnt=0;
	ll tcnt=0;
	for(int i=0;i<s.size();i++){
		char now=s[i];
		if(now=='T'){
			if(scnt==0){
				tcnt++;
			}
			else{
				scnt--;
			}
		}
		else{
			scnt++;
		}
	}
	cout <<tcnt*2;
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i,n) for (int i=0;i<(int)(n);i++)
#define codefor int test;scanf("%d",&test);while(test--)
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define yn(ans) if(ans)printf("Yes\n");else printf("No\n")
#define YN(ans) if(ans)printf("YES\n");else printf("NO\n")
#define vector1d(type,name,...) vector<type>name(__VA_ARGS__)
#define vector2d(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define umap unordered_map
#define uset unordered_set
using namespace std;
using ll = long long;
const int MOD=1000000007;
//入力系
void scan(int& a){scanf("%d",&a);}
void scan(long long& a){scanf("%lld",&a);}
template<class T> void scan(T& a){cin>>a;}
template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);}
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);}
//出力系
void print(const int& a){printf("%d",a);}
void print(const long long& a){printf("%lld",a);}
void print(const double& a){printf("%.15lf",a);}
template<class T> void print(const T& a){cout<<a;}
template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}}
void out(){putchar('\n');}
template<class T> void out(const T& t){print(t);putchar('\n');}
template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);}
//デバッグ系
template<class T> void dprint(const T& a){cerr<<a;}
template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}}
void debug(){cerr<<endl;}
template<class T> void debug(const T& t){dprint(t);cerr<<endl;}
template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);}

int main(){
    INT(n);
    vector<ll> vec(n);
    in(vec);
    ll pre=vec[0],ans=0;
    for(int i=1;i<n;i++){
        if(pre<=vec[i]){
            pre=vec[i];
        }else{
            ans+=(ll)pre-vec[i];
        }
    }
    out(ans);
}

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

int main() {
  int A,B,C;
  cin >> A >> B;
  C=max(A,B)-min(A,B);
  if( C%2==1 ) {
    cout << "IMPOSSIBLE" << endl;
  }
  else {
    C = C/2;
    cout << max(A,B)-C << endl;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int prime[100005]={0};
int cnt[100005];
int get_prime()
{
    int m=100005;
    prime[1]=1;
    for(int i=2;i*i<=m;i++)
    {
        if(!prime[i]){
            for(int j=i*i;j<=m;j+=i){
                prime[j]=1;
            }
        }
    }
}
int main()
{
    get_prime();
    int Q;
    cnt[0]=0;
    for(int i=2;i<=100000;i++){
        cnt[i]=cnt[i-1];
        if(!prime[i]&&!prime[(i+1)/2]) cnt[i]++;
    }
    cin>>Q;
    while(Q--){
        int l,r;
        cin>>l>>r;
        cout<<cnt[r]-cnt[l-1]<<endl;
    }
}



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

int main()
{
	string str;
	while (getline(cin,str))
	{
		int cutp = 0, cnt = 0, flg=0;
		for (int i = 0; i < str.size() ; i++)
		{
			if (str[i] == ',' || str[i] == '.' || str[i]==' ')
			{
				if (3 <= cnt && cnt <= 6)
				{
					if (flg==0)
					{
						for (int j = cutp; j < cutp+cnt ; j++)
						{
							cout << str[j];
						}
					}
					else
					{
						cout << " ";
						for (int j = cutp; j < cutp + cnt; j++)
						{
							cout << str[j];
						}
					}
					flg = 1;
				}
				cutp = i + 1;
				cnt = 0;
			}
			else
			{
				cnt++;
			}
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 1168
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
using ll = long long;
using P = pair<int, int>;

const ll INF = 1LL<<59;

int main(){
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    ll ans = -INF;
    ans = max(ans, b * d);
    ans = max(ans, b * c);
    ans = max(ans, a * c);
    ans = max(ans, a * d);
    if((c <= 0 && 0 <= d) || (a <= 0 && 0 <= b)){
        ans = max(ans, 0LL);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3624
from heapq import *

def int_raw():
    return int(input())

def ss_raw():
    return input().split()

def ints_raw():
    return list(map(int,ss_raw()))

X,Y,Z,K = ints_raw()

A = ints_raw()
B= ints_raw()
C= ints_raw()
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)

arg_hash = {}

def main():
    Q = []
    heappush(Q,(-A[0]-B[0]-C[0],0,0,0))
    arg_hash[(0,0,0)]=1
    for k in range(K):
        ans = heappop(Q)
        print(-ans[0])
        a,b,c = ans[1:]

        argA = (a+1,b,c)
        if a < X-1 and (not argA in arg_hash):
            arg_hash[argA]=1
            heappush(Q,(-A[a+1]-B[b]-C[c],)+argA)
        argB = (a,b+1,c)
        if b < Y-1 and (not argB in arg_hash):
            arg_hash[argB]=1
            heappush(Q, (-A[a]-B[b+1]-C[c],)+argB)
        argC = (a,b,c+1)
        if c < Z-1 and (not argC in arg_hash):
            arg_hash[argC]=1
            heappush(Q,(-A[a]-B[b]-C[c+1],)+argC)
        
main()


Measured memory_bytes: 4792
#include<cstdio>
#include<iostream>
#include<queue>
using namespace std;
const int INF=0x3f3f3f3f;
const int dx[4]={1,-1,0,0};
const int dy[4]={0,0,1,-1};
int n,m,k;
char s[805][805];
int dist[805][805];
int sx,sy;
void bfs(){
	queue<pair<int,int> >q;
	dist[sx][sy]=0;
	q.push(make_pair(sx,sy));
	while(!q.empty()){
		int x=q.front().first,y=q.front().second;q.pop();
		for(int i=0;i<4;i++){
			int nx=x+dx[i];
			int ny=y+dy[i];
			if(nx<1||nx>n||ny<1||ny>m||s[nx][ny]=='#')continue;
			if(dist[nx][ny]>dist[x][y]+1){
				dist[nx][ny]=dist[x][y]+1;
				q.push(make_pair(nx,ny));
			}
		}
	}
}
int main(){
	scanf("%d%d%d",&n,&m,&k);
	for(int i=1;i<=n;i++){
		scanf("%s",s[i]+1);
		for(int j=1;j<=m;j++){
			if(s[i][j]=='S'){
				sx=i;sy=j;
				s[i][j]='.';
			}
		}
	}
	for(int i=1;i<=n;i++)for(int j=1;j<=m;j++)dist[i][j]=INF;
	bfs();
	int res=INF;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			if(dist[i][j]<=k){
				int tmp=1+(min(min(i-1,n-i),min(j-1,m-j))+k-1)/k;
//				cout<<i<<' '<<j<<' '<<dist[i][j]<<endl;
				if(res>tmp){
					res=tmp;
				}
			}
		}
	}
	printf("%d\n",res);
	return 0;
}

Measured memory_bytes: 3456
#include <bits/stdc++.h>
using namespace std;
 
int main() {

  int N;

  int ac_counter = 0;
  int wa_counter = 0;
  int tle_counter = 0;
  int re_counter = 0;

  cin >> N;

  vector<string> vec(N);
  for (int i = 0; i < N; i++) { 
    cin >> vec.at(i);
  }

  for (int i = 0; i < N; i++) { 
    if (vec.at(i) == "AC") {
      ++ac_counter;
    }

    if (vec.at(i) == "WA") {
      ++wa_counter;
    }

    if (vec.at(i) == "TLE") {
      ++tle_counter;
    }

    if (vec.at(i) == "RE") {
      ++re_counter;
    }
  }

  cout << "AC x " << ac_counter << endl;
  cout << "WA x " << wa_counter << endl;
  cout << "TLE x " << tle_counter << endl;
  cout << "RE x " << re_counter << endl;

}

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

using namespace std;


int main() {
    string s;
    cin >> s;
    int n = s.size();
    string ans = "";
    for(int i = 0; i < n - 8; i++) {
        ans += s[i];
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 3612
import string
if __name__=="__main__":
    s = list(input())
    t = list(input())
    min_s = 27
    max_t = 0
    dic = list(string.ascii_lowercase)
    c = 0
    for j in range(len(s)):
        if s[j] in t:
            c+=1
    if c==len(s) and c<len(t):
        print("Yes")
        exit()
    for i in string.ascii_lowercase:
        if s.__contains__(i):
            min_s = min(min_s,dic.index(i)+1)
        if t.__contains__(i):
            max_t = max(max_t,dic.index(i)+1)
    if max_t<=min_s:
        print("No")
    else:
        print("Yes")


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

using ll = long long;

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define pb push_back
#define mp make_pair
#define fill(x, y) memset(x, y, sizeof(x))
#define even(x) x % 2 == 0
#define odd(x) x % 2 != 0
#define all(x) x.begin(), x.end()
#define pcnt __builtin_popcount
#define buli(x) __builtin_popcountll(x)
#define F first
#define S second
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());

// these functions return the position of result of Binary Search.
#define LB(s, t, x) (int) (lower_bound(s, t, x) - s)
#define UB(s, t, x) (int) (upper_bound(s, t, x) - s)

ll qp(ll a, ll b, int mo) { ll ans = 1; do { if (b & 1) ans = 1ll * ans * a % mo; a = 1ll * a * a % mo; } while (b >>= 1); return ans; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int dx8[] = { 1, -1, 0, 0, 1, 1, -1, -1 }, dy8[] = { 0, 0, -1, 1, -1, 1, -1, 1 };

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

const ll INF_LL = (1ll << 60);
const int INF_INT = (int)1e9;
const ll MOD_CONST = (ll)(1e9 + 7);

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 (b < a) { a = b; return 1; } return 0; }

inline tuple<ll, ll> rotate45(tuple<ll, ll> point) { ll x = get<0>(point), y = get<1>(point); return tuple<ll, ll>(x + y, x - y); }
inline bool rangeCheck2D(int nx, int ny, int Width, int Height) { return nx >= 0 and nx < Width and ny >= 0 and ny < Height; }
void out_sequence(vector<ll> &out) { REP(i, (int)out.size()) { cout << out[i]; if (i == (int)out.size() - 1) cout << endl; else cout << " "; } }



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

    ll A, B, C; cin >> A >> B >> C;
  	ll d1 = abs(A - B);
  	ll d2 = abs(A - C);
  	ll d3 = abs(B - C);
  	cout << d1 + d2 + d3 - max(d1, max(d2, d3)) << endl;
    
	return 0;
}



Measured memory_bytes: 256
program sample
implicit none
integer(8) A,B,C,K,M
read(*,*) A,B,C,K
if (K-A>0) then
    M=A
    K=K-A
else
    M=K
    go to 10
end if
if (K-B>0) then
    K=K-B
else 
    go to 10
end if
M=M-K
10 continue
write(*,*) M
stop
end program sample

Measured memory_bytes: 2852
#include <stdio.h>
#define INF 222200
#define MAXN 100
#define NIL -1
#define WHITE 0
#define BLACK 1
#define GRAY 2

int MST(void);

int G[MAXN][MAXN];//weight を記録した隣接行列
int n = 0;//sum of weight


int main(){

  int i = 0, j = 0;
  int m = 0,sum = 0;
  
  scanf("%d",&n);

  for(i = 0; i < n; i++){
    
    for(j = 0; j < n; j++){
      
      scanf("%d",&m);
      if(m == -1)G[i][j] = INF;
      else G[i][j] = m;
      
    }
    
  }

  sum = MST();

  printf("%d\n",sum);
  
  return 0;
  
}

int MST(){
  
  int d[MAXN];//V-TとTをつなぐ辺の中で重み最小の辺の重み
  int pi[MAXN];//MSTにおける頂点vの親
  int color[MAXN];
  int i = 0;
  int u = 0, v = 0;
  int mini = 0, sum = 0;

  for(i = 0; i < n; i++){
    d[i] = INF;
    pi[i] = NIL;
    color[i] = WHITE;
  }
  
  d[0] = 0;

  while(1){
    
    mini = INF;
    u = -1;
    for(i = 0; i < n; i++){
      
      if(color[i] != BLACK && d[i] < mini){
	mini = d[i];
	u = i;
      }
      
    }

    if(u == -1)break;

    color[u] = BLACK;

    for(v = 0; v < n; v++){
      
      if(color[v] != BLACK && G[u][v] != INF){
	
	if(G[u][v] < d[v]){
	  pi[v] = u;
	  d[v] = G[u][v];
	  color[v] = GRAY;
	  //sum += d[v];
	  //printf("%d\n",&d[v]);
	}
	
      }
      
    }
 
  }
  
  for(i = 0; i < n; i++){
    if(pi[i] != NIL)sum += G[i][pi[i]];
  }
  
  return sum;
  
}



Measured memory_bytes: 2112
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let a: String = read();
    let b: String = read();

    let c: String = a + &b;
    let cn: i32 = i32::from_str(&c).unwrap();

    let mut d = 1;

    while d * d <= cn {
        if d * d == cn {
            println!("Yes");
            return;
        }
        d += 1;
    }
    println!("No")
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;

const ll LINF = 1e18;
const int INF = 1e9;
const ll MOD = 1000000007;

int main(){

    int r;
    cin >> r;
    
    if(r < 1200) cout << "ABC" << endl;
    else if(r < 2800) cout << "ARC" << endl;
    else cout << "AGC" << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using vi = vector<i64>;
using vvi = vector<vi>;

int main() {
    int n;
    cin >> n;
    using ii = pair<int, int>;
    vector<vector<ii>> adj(n);
    for (int i = 0; i < n - 1; i++) {
        int s, t, w;
        cin >> s >> t >> w;
        adj[s].push_back(ii(t, w));
        adj[t].push_back(ii(s, w));
    }

    vi dp(n);
    function<void(int, int)> kek = [&](int v, int p) {
        int nax = 0;
        for (ii s: adj[v]) {
            if (s.first != p) {
                kek(s.first, v);
                nax = max(nax, (int)dp[s.first] + s.second);
            }
        }
        dp[v] = nax;
    };
    kek(0, -1);
    // for (int i = 0; i < n; i++) {
    //     cout << "dp[" << i << "] = " << dp[i] << endl;
    // }
    vi dp2(n);
    function<void(int, int)> kek2 = [&](int v, int p) {
        vector<ii> tmp = {ii(dp2[v], p)};
        for (ii s: adj[v]) {
            if (s.first != p) {
                tmp.push_back(ii(dp[s.first] + s.second, s.first));
            }
        }
        sort(tmp.begin(), tmp.end(), greater<>());
        for (ii s: adj[v]) {
            if (s.first != p) {
                dp2[s.first] = tmp[tmp[0].second == s.first].first + s.second;
                kek2(s.first, v);
            }
        }
    };
    kek2(0, -1);
    // for (int i = 0; i < n; i++) {
    //     cout << "dp2[" << i << "] = " << dp2[i] << endl;
    // }
    for (int i = 0; i < n; i++) {
        cout << max(dp[i], dp2[i]) << endl;
    }
}


Measured memory_bytes: 5228
#include <cstdio>
#include <vector>
#include <map>
#include <algorithm>
#include <functional>
#include <queue>
#include <climits>
using namespace std;
typedef pair<int, int> P;
struct train {
int to, cost;
train(int _to, int _cost) { to=_to; cost=_cost; }
};
int n,m,k,a,b,r;
void djk(vector<train> G[], int s, int g) {
	int d[m];
	fill(d, d+m, INT_MAX);
	d[s-1] = 0;
	priority_queue<P, vector<P>, greater<P> > que;
	que.push(P(0,s-1));
	while(!que.empty()) {
		P p = que.top(); que.pop();
        int v = p.second;
        if (d[v] < p.first) continue;
        for (int i=0; i<G[v].size(); i++) {
            train e = G[v][i];
            if (d[e.to] > d[v] + e.cost) {
                d[e.to] = d[v] + e.cost;
                que.push(P(d[e.to], e.to));
            }
        }
	}
	printf("%d\n",d[g-1]);
}
int main() {
	while (scanf("%d%d",&n,&m)) {
		if (n==0&&m==0) break;
		vector<train> mcost[m], mtime[m];
		for (int i=0; i<n; i++) {
			int c, t;
			scanf("%d%d%d%d",&a,&b,&c,&t);
			mcost[a-1].push_back(train(b-1,c));
			mcost[b-1].push_back(train(a-1,c));
			mtime[a-1].push_back(train(b-1,t));
			mtime[b-1].push_back(train(a-1,t));
		}
		scanf("%d",&k);
		for (int i=0; i<k; i++) {
			scanf("%d%d%d",&a,&b,&r);
			if (r) djk(mtime,a,b);
			else djk(mcost,a,b);
		}
	}
}

Measured memory_bytes: 944
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> pip;
const ll INF = 1ll<<29;
const ll MOD = 1000000007;
const double EPS = 1e-9;
const bool debug = 0;
//---------------------------------//
 
int main() {
	int n, k;
	int l[50];
	
	cin >> n >> k;
	REP(i, n) scanf("%d", l + i);
	sort(l, l + n, greater<int>());
	
	int sum = 0;
	REP(i, k) sum += l[i];
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 256
x,y = map(int,input().split())

def f(x):
  if x==3:
    return 100000
  elif x==2:
    return 200000
  elif x== 1:
    return 300000
  else:
    return 0

ans = f(x)+f(y)
if x == y== 1:
  ans += 400000
print(ans)

Measured memory_bytes: 2940
from heapq import heappop, heappush

N = int(input())
h = []
res = 'Yes'

for i in range(N):
    A, B = map(int, input().split())
    heappush(h, (B, A))

t = 0
for i in range(N):
    B, A = heappop(h)
    t += A
    if t > B:
        res = 'No'

print(res)


Measured memory_bytes: 74456
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = long long;
using std::cout;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

struct UnionFind {
	std::vector<int> data;
	
	UnionFind(int n) {
		data.assign(n, -1);
	}
	void unite(int x, int y) {
		x = find(x); y = find(y);
		if(x == y) return;
		if(data[x] > data[y]) std::swap(x, y);
		data[x] += data[y];
		data[y] = x;
	}
	int find(int k) {
		if(data[k] < 0) return k;
		return find(data[k]);
	}
};

int main() {
	int n; scanf("%d", &n); std::vector<int> x(n), y(n);
	for(int i = 0; i < n; i++) scanf("%d%d", &x[i], &y[i]);
	
	std::vector<std::pair<int, int>> vec;
	for(int i = 0; i < n; i++) {
		for(int j = 0; j < n; j++) {
			if(i == j) continue;
			vec.push_back({x[i] - x[j], y[i] - y[j]});
		}
	}
	
	int ans = n;
	for(auto v: vec) {
		int p = v.first, q = v.second;
		 
		UnionFind uf(n);
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < n; j++) {
				if(i == j) continue;
				if(x[i] - x[j] == p and y[i] - y[j] == q) uf.unite(i, j);
			}
		}
		std::set<int> st;
		for(int i = 0; i < n; i++) st.insert(uf.find(i));
		ans = std::min(ans, (int)st.size());
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main {

	public static final int BIG_NUM = 2000000000;
	public static final int MOD = 1000000007;
	public static final long HUGE_NUM = 99999999999999999L;
	public static final double EPS = 0.000000001;

	@SuppressWarnings("unchecked")
	public static void main(String[] args) {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		//Scanner scanner = new Scanner(System.in);

		try {

			int POW[] = new int[4];
			POW[0] = 1;
			for(int i = 1; i < 4; i++){

				POW[i] = POW[i-1]*2;
			}

			final int M = 10007;

			int dp[][] = new int[2][8];
			int CURRENT = 0,NEXT = 1;
			for(int state = 0; state < POW[3]-1;state++){

				dp[CURRENT][state] = 0;
			}

			dp[CURRENT][POW[3]-1] = 1;

			int length = Integer.parseInt(br.readLine());
			char table[] = br.readLine().toCharArray();

			for(int i = 0; i < length; i++){
				for(int state = 0; state < POW[3]; state++){

					dp[NEXT][state] = 0;
				}

				int must_attend = calc(table[i]);

				for(int next_state = 1; next_state < POW[3]; next_state++){

					if(i==0 && ((next_state&POW[calc('J')]) == 0))continue; //最初はJが鍵を持っている
					if((next_state & POW[must_attend]) == 0)continue; //責任者が出席しないならSKIP

					for(int state = 1; state < POW[3]; state++){

						if((state&next_state) == 0 || dp[CURRENT][state] == 0)continue; //2日間の共通出席者が不在かdpが0ならSKIP

						dp[NEXT][next_state] += dp[CURRENT][state];
						dp[NEXT][next_state] %= M;
					}
				}
				CURRENT = 1-CURRENT;
				NEXT = 1-NEXT;
			}

			int ans = 0;
			for(int state = 0; state < POW[3]; state++){

				ans += dp[CURRENT][state];
				ans %= M;
			}

			System.out.println(ans);

		} catch (IOException e) {
			// TODO 自動生成された catch ブロック
			e.printStackTrace();
		}

    }

	public static int calc(char ch){

		switch(ch){
		case 'J':
			return 0;
		case 'O':
			return 1;
		case 'I':
			return 2;
		}
		return -1; //must not reach here
	}
}

class UTIL{

	//最大公約数
	public static long gcd(long x,long y){

		x = Math.abs(x);
		y = Math.abs(y);

		if(x < y){

			long tmp = y;
			y = x;
			x = tmp;
		}

		if(y == 0){

			return x;
		}else{

			return gcd(y,x%y);
		}
	}

	//最小公倍数
	public static long lcm(long x,long y){

		return (x*y)/gcd(x,y);
	}

	//String→intへ変換
    public static int getNUM(String tmp_str){

        return Integer.parseInt(tmp_str);
    }

    //文字が半角数字か判定する関数
    public static boolean isNumber(String tmp_str){

        if(tmp_str == null || tmp_str.length() == 0){

            return false;
        }

        Pattern pattern = Pattern.compile("\\A[0-9]+\\z");
        Matcher matcher = pattern.matcher(tmp_str);
        return matcher.matches();
    }
}


Measured memory_bytes: 24324
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a,b;
  string s;
  cin >> a >> b >> s;
  for(int i=0;i < (int)s.size(); ++i){
    if(i == a){
      if(s[i] != '-'){
        cout << "No" << endl;
        return 0;
      }
    }else{
      if(!isdigit(s[i])){
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;
}


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

#define forn(i,n) for(int i=0;i<(int)(n);i++)
#define si(c) ((int)(c).size())
#define forsn(i,s,n) for(int i = (int)(s); i<((int)n); i++)
#define dforsn(i,s,n) for(int i = (int)(n)-1; i>=((int)s); i--)
#define all(c) (c).begin(), (c).end()
#define D(a) cerr << #a << "=" << (a) << endl;
#define pb push_back
#define eb emplace_back
#define mp make_pair

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

const int MOD = 1e9 + 7;

vi split(string s) {
    vi ans;
    char last = 'X'; 
    s += 'X';
    int streak = 0;
    for (char c : s) {
        if (c != last) {
            if (streak) ans.pb(streak);
            streak = 0;
            last = c;
        }
        streak++;
    }
    return ans;
}

void add(int &x, int y) {
    x += y;
    if (x >= MOD) x -= MOD;
}

vi go(int n, int lim, int start) {
    vi dp(n+1);
    dp[0] = 1;
    for (int i = 1; i <= n; i++) {
        dp[i] = 0;
        if (i >= start) add(dp[i], dp[i-start]);
        if (i >= lim+1) add(dp[i], MOD-dp[i-lim-1]);
        add(dp[i], dp[i-1]);
    }
    for (int i = n; i >= 1; i--) add(dp[i], MOD-dp[i-1]);
    return dp;
}

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

    int n,l;
    string s;
    cin >> n >> l >> s;
    auto p = split(s);
    if (si(p) == 1) {
        auto dp = go(n,n,2);
        int ans = 0;
        for (int dif = 1; dif <= n; dif++) {
            if (dif == 1 || dif == n-1) continue;
            add(ans, ll(dif) * dp[n-dif] % MOD);
        }
        cout << (ans+1)%MOD << endl;
    }
    else {
        if (n%2 == 1) {
            cout << 0 << endl;
        }
        else {
            int lim = p[0]/2+1;
            forn(i,si(p)) if (i%2 == 0 && p[i]%2 == 1 && i+1 != si(p)) 
                lim = min(lim, p[i]/2+1);
            n /= 2;
            auto dp = go(n, lim, 1);
            int ans = 0;
            for (int dif = 1; dif <= lim; dif++)
                add(ans, ll(dif) * dp[n-dif] % MOD);
            cout << 2LL*ans%MOD << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 1360
#include<stdio.h>
#include<iostream>
using namespace std;
long long a[1000001],n,i,d[1000001];
int main()
{
    cin>>n;
    a[1]=n;
    for(i=2;i<=n;i++)
    cin>>a[i],d[a[i]]++;
    for (i=1;i<=n;i++)
    cout<<d[i]<<endl;
}


Measured memory_bytes: 6268
#include <bits/stdc++.h>
#include<numeric>
#include<cstdlib>
#define ll long long int
#define all(x) x.begin(),x.end()

 #define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

#define v vector<long long int> 
#define  vv vector< int> 
#define gcd(m,n) __gcd(m,n)
#define vp vector<pair<long long int ,long long int>>
#define pb push_back
#define mp make_pair
#define pp pop_back
#define iter vector<int>::iterator
#define pa pair<long long int ,long long int> 
#define f(i,n) for(ll i=0;i<n;i++)
#define loop(i,a,n) for (ll i=a ; i<n ;i+=1)
#define fe(d,e) for(auto d:e)
#define mod 1000000007
#define F first
#define S second
#define sett set<long long int>
#define um unordered_map<ll,ll>
# define N 100005LL
# define cout1(x) cout<<x<<"\n";
# define  deb(x) cout<<#x<<" "<<x<<"\n";
using namespace std; 
void print_vector(v arr){
    f(i,arr.size())cout<<arr[i]<<" ";
    cout<<endl;

}

void solve(){
    ll n;
    cin>>n;
    v ans(n+1,0);
    loop(i,1,sqrt(n)+1){
        loop(j,1,sqrt(n)+1){
            loop(k,1,sqrt(n)+1){
                ll t=(i*i+j*j+k*k+i*j+j*k+i*k);
                if (t<=n){
                    ans[t]+=1;
                }
            }
        }
    }
    loop(i,1,n+1)cout<<ans[i]<<"\n";
    
    
}






int main(){
    fastio;
    ll t;
    // cin>>t;
    t=1;
    f(_,t){
        solve();
       
    }
    




}

Measured memory_bytes: 3720
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
using namespace std;

int Q;
int A, B;
long long res;

long long sqrtll(long long x)
{
	long long l=1, r=2000000000;
	long long m;
	while(l<r){
		m = (l+r)/2;
		if(m*m >= x)
			r = m;
		else
			l = m+1;
	}
	if (l*l>x)
		l --;
	return l;
}

void solve()
{
	res = 0;
	if(A>B)
		swap(A, B);
	res += (A-1)*2;
	long long sq = int(sqrt(1.0*A*B)+1E-8);
	if(sq*(sq+1)<1ll*A*B)
		res ++;
	if(sq*sq<1ll*A*B)
		res ++;
	if(sq-A>=0)
		res += (sq-A)*2;
	if(A!=B)
		res --;
	printf("%lld\n", res);
}

int res2;
int vis[1000000];
void solve2()
{
	int i;
	for(i=0; i<1000000; i++)
		vis[i] = 0;
	res2 = 0;
	for(i=1; i<A; i++){
		int tmp = A*B/i;
		if(tmp*i<A*B){
			if(vis[tmp]==0){
				vis[tmp] = 1;
				res2 ++;
			}
		}
	}
	for(i=0; i<1000000; i++)
		vis[i] = 0;
	for(i=1; i<B; i++){
		if(vis[i]==1)
			continue;
		int tmp = (A*B)/i;
		if(tmp*i < A*B && vis[tmp]==0){
			if(tmp > A){
				res2 ++;
			}
		}
		else{
			tmp --;
			while(vis[tmp]==1){
				tmp --;
				if(tmp == 0)
					break;
			}
			if(tmp>A)
				res2 ++;
		}
	}
	printf("%d\n", res2);
}

void test1()
{
	A = rand()%5+1;
	B = rand()%5+1;
	solve();
	solve2();
	if(res != res2){
		printf("Wrong\n");
		solve();
	}
}

void test()
{
	int i;
	for(i=0; i<100; i++)
		test1();
}

int main()
{
	//test();
	int i;
	scanf("%d", &Q);
	for(i=0; i<Q; i++){
		scanf("%d%d", &A, &B);
		solve();
		//solve2();
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

const int MOD = 1e9 + 7;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s; cin >> s;
    if(s == "MON") cout << 6;
    else if(s == "TUE") cout << 5;
    else if(s == "WED") cout << 4;
    else if(s == "THU") cout << 3;
    else if(s == "FRI") cout << 2;
    else if(s == "SAT") cout << 1;
    else cout << 7;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, begin, end) for(ll i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(ll i=(begin)-1;i>=(end);i--)
#define IREP(i, n) IFOR(i,n,0)
#define SORT(a) sort(a.begin(), a.end())
#define ISORT(a) sort(a.begin(), a.end(),greater<ll>())
#define REVERSE(a) reverse(a.begin(), a.end())
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) cout << #v << "=(" << v[0]; FOR(i_debug, 1, v.size()){ cout << "," << v[i_debug]; } cout << ")" << endl;
#define mdebug(m) cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;}
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)

#define ll long long
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define INF 1000000000000000000

using vec = vector<ll>;
using mat = vector<vec>;
using Pii = pair<ll, ll>;
using PiP = pair<ll, Pii>;
using PPi = pair<Pii, ll>;
using bvec = vector<bool>;
using Pvec = vector<Pii>;


template<typename T> void readv(vector<T> &a) { REP(i, a.size()) cin >> a[i]; }
void readv_m1(vector<int> &a) { REP(i, a.size()) {cin >> a[i]; a[i]--;} }

ll mod = 1000000007;

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

	vec A(N);
	REP(i, N) {
		cin >> A[i];
	}

	ll numbef = 0, numaft = 0;
	// vec numbef(N, 0), numaft(N, 0);
	REP(i, N) {
		FOR(j, 0, i) {
			if (A[j] > A[i]) numbef++;
		}
		FOR(j, i + 1, N) {
			if (A[j] > A[i]) numaft++;
		}
	}

	ll tempKK = K * (K - 1) / 2 % mod;

	ll ans = numbef * K % mod + (numbef + numaft) * tempKK % mod;
	ans %= mod;
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPLL(i, n) for (ll i = 0; i < (ll)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;

// ABC168 E - ∙ (Bullet)

ll MOD = 1e9+7;
ll gcd(ll n, ll m){
  if(m == 0) return n;
  return gcd(m, n%m);
}

ll lcm(ll n, ll m){
  return n / gcd(n, m) * m;
}

ll fastpow(ll a, ll n){  // a^n mod MOD
  if(n==0) return 1;
  if(n%2==0){
    ll t = fastpow(a, n/2) % MOD;
    return t*t % MOD;
  }
  return a * fastpow(a, n-1) % MOD;
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll N; cin >> N;
  vector<ll> A(N), B(N);
  REPLL(i, N){
    cin >> A[i] >> B[i];
  }
  map<pair<ll , ll>, ll> mp1, mp2;
  REPLL(i, N){
    if(A[i] == 0 && B[i] == 0){
      mp1[{0, 0}]++;
    }else if(A[i] == 0 && B[i] != 0){
      mp1[{0, 1}]++;
    }else if(A[i] != 0 && B[i] == 0){
      mp1[{1, 0}]++;
    }else{
      ll g = gcd(abs(A[i]), abs(B[i]));
      if(A[i] < 0){
        mp1[{-A[i]/g, -B[i]/g}]++;
      }else{
        mp1[{A[i]/g, B[i]/g}]++;
      }
    }
  }

  ll res1 = 1, res2 = 0;
  for(auto i : mp1){
    if(mp2.find(i.first) != mp2.end()) continue;
    ll a = i.first.first, b = i.first.second;
    if(a == 0 && b== 0){
      res2 = i.second%MOD;
      mp2[i.first]++;
    }else{
      if(a == 0 || b == 0){
        if(mp1.find({b, a}) != mp1.end()){
          ll tmp = fastpow(2, i.second);
          mp2[i.first]++;
          tmp = (tmp+fastpow(2, mp1[{b, a}]))%MOD;
          mp2[{b, a}]++;
          res1 = (res1*(tmp-1))%MOD;
        }else{
          res1 = (res1*fastpow(2, i.second))%MOD;
          mp2[i.first]++;         
        }
      }else{
        if(b < 0 && mp1.find({-b, a}) != mp1.end()){
          ll tmp = fastpow(2, i.second);
          mp2[i.first]++;
          tmp = (tmp+fastpow(2, mp1[{-b, a}]))%MOD;
          mp2[{-b, a}]++;
          res1 = (res1*(tmp-1))%MOD;
        }else if(b > 0 && mp1.find({b, -a}) != mp1.end()){
          ll tmp = fastpow(2, i.second);
          mp2[i.first]++;
          tmp = (tmp+fastpow(2, mp1[{b, -a}]))%MOD;
          mp2[{b, -a}]++;
          res1 = (res1*(tmp-1))%MOD;
        }else{
          res1 = (res1*fastpow(2, i.second))%MOD;
          mp2[i.first]++;
        }
      }
    }
  }
  ll ans = (res1+res2)%MOD-1;
  if(ans < 0) ans += MOD;
  cout << ans << endl;
}


Measured memory_bytes: 31324
import java.util.*;

public class Main {
    public static void main(String... args) {
        Scanner sc = new Scanner(System.in);
        int ans = 0;
        int n = sc.nextInt();
        while (sc.hasNext()) {
            ans += sc.nextInt() - 1;
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 26096
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,k;
  cin>>n>>k;
  int A[n+5];
  for(int i=0;i<n;i++)
    cin>>A[i];
  sort(A,A+n);
  int ans=0;
  for(int i=0;i<k;i++)
    ans+=A[i];
  cout<<ans<<endl;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define f first
#define s second
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define debug(v) cout << #v << ":\t" << v << endl
#define _ << ", " <<

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;

const ll N = 1e3 + 3;
const ll M = 2019;
const ll INF = 1e9 + 7;

ll l, r, ans;
vector<ll> res;

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	
	cin >> l >> r;
	for (ll i = l, j = 0; i <= r && j <= 4040; ++i, ++j) {
		res.pb(i % M);
	}
	
	ans = INF;
	for (size_t i = 0; i < res.size(); ++i) {
		for (size_t j = i + 1; j < res.size(); ++j) {
			ans = min(ans, res[i] * res[j] % M);
		}
	}
	cout << ans;
	
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
using namespace std;
using lint = long long;
using pi = pair<int, int>;
const int MAXN = 1005;

int f(lint n){
	if(n <= 4) return n;
	if(n % 3 != 2) return f(n - 1) + 1;
	return f(n / 3) + 2;
}

int main(){
	lint x; cin >> x; cout << f(x+1)-1 << endl;
}



Measured memory_bytes: 3124
import sys


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    x = int(input().rstrip('\n'))
    print(x // 500 * 1000 + (x - x // 500 * 500) // 5 * 5)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 38384
#include <stdio.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
    int n;
    scanf("%d", &n);
    int iAns;
    if(n % 27 == 13 || n % 27 == 26){
        printf(":(");
    } else if (n % 27 < 13){
        iAns = (n / 27) * 25 + (n % 27);
        printf("%d", iAns);
    } else {
        iAns = (n / 27) * 25 + (n % 27) - 1;
        printf("%d", iAns);
    }
    
    return 0;
}


Measured memory_bytes: 3232
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <functional>
#include <utility>
#include <queue>
#include <vector>
using namespace std;
typedef long long int ll;
const int MOD = 1000000007;

int main(){
  int a[3];
  for(int i=0;i<3;i++){
    cin >> a[i];
  }
  sort(a,a+3);
  if(a[0] == 5 && a[1] == 5 && a[2] == 7){
    cout << "YES" << endl;
  }
  else{
    cout << "NO" << endl;
  }
}


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

int a[200010];
int n;

bool cmp(int A,int B){
	return A>B;
}

int main() {
	scanf("%d",&n);
	for (int i=1;i<=n;++i)
	scanf("%d",&a[i]);
	sort(a+1,a+1+n,cmp);
	int n1=n-2;ll ans=a[1];
	for (int i=2;i<=n&&n1>0;++i) {
		ans+=a[i]*min(2,n1);
		n1-=min(2,n1);
	}
	printf("%lld",ans);
	return 0;
}

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

int main(void){
    string str;
    while (getline(cin, str) && str != ".") {
        stack<char> st;
        bool balanced = true;
        for (char c : str) {
            if (c == '(' || c == '[')
                st.push(c);
            else if (c == ')' || c == ']') {
                if (st.empty()) {
                    balanced = false;
                    break;
                } else if (st.top() != '(' && c == ')') {
                    balanced = false;
                    break;
                } else if (st.top() != '[' && c == ']') {
                    balanced = false;
                    break;
                }
                st.pop();
            }
        }
        balanced = balanced && st.empty();
        cout << (balanced ? "yes" : "no") << endl;
    }
}

Measured memory_bytes: 3144
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#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(a) (a).begin(),(a).end()
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
const int INF=1e9;
ll gcd(ll a,ll b){
  if(b==0)return a;
  return gcd(b,a%b);
}
int main(){
  int n;
  while(cin>>n&&n){
    ll w[110],p[110],q[110],r[110],b[110];
    memset(w,-1,sizeof(w));
    for(int i=1;i<=n;i++){
      cin>>p[i]>>q[i]>>r[i]>>b[i];
      ll g=gcd(p[i],q[i]);
      p[i]/=g;q[i]/=g;
      if(r[i]==0&&b[i]==0){
        w[i]=p[i]+q[i];
      }
    }
    bool update=true;
    while(update){
      update=false;
      for(int i=1;i<=n;i++){
        if(w[i]!=-1)continue;
        if((r[i]==0||w[r[i]]!=-1)&&(b[i]==0||w[b[i]]!=-1)){
          if(r[i]==0||b[i]==0){
            if(r[i]==0){
              ll y=w[b[i]]*q[i],x=p[i];
              ll g=gcd(x,y);
              x/=g;y/=g;
              w[i]=y+w[b[i]]*x;
            }else{
              ll y=q[i],x=w[r[i]]*p[i];
              ll g=gcd(x,y);
              x/=g;y/=g;
              w[i]=w[r[i]]*y+x;
            }
          }else{
            ll y=w[b[i]]*q[i],x=w[r[i]]*p[i];
            ll g=gcd(x,y);
            x/=g;y/=g;
            w[i]=w[r[i]]*y+w[b[i]]*x;
          }
          update=true;
        }
      }
    }
    ll ans=0;
    for(int i=1;i<=n;i++)ans=max(w[i],ans);
    cout<<ans<<endl;
  }
}

Measured memory_bytes: 1168
n = int(input())
binary = []
flag = 0

if n == 0:
    print(0)
    flag = 1
    
while n != 0:
    if n % -2 != 0:
        binary.append('1')
        n = n // -2 + 1
    else:
        binary.append('0')
        n = n // -2

binary.reverse()

if flag == 0:
    print(''.join(binary))

Measured memory_bytes: 3060
from fractions import gcd
from functools import reduce

def gcd_list(numbers):
    return reduce(gcd, numbers)

N, X=map(int, input().split())
x=list(map(int, input().split()))
y=list()

for i in x:
    y.append(abs(X-i))

#print(y)
print(gcd_list(y))

Measured memory_bytes: 16280
#!/usr/bin/env ruby
x, y = STDIN.readline.strip.split(' ')
hex = ['A', 'B', 'C', 'D', 'E', 'F']
hx = hex.find_index(x)
hy = hex.find_index(y)
puts "#{hx < hy ? '<' : hx == hy ? '=' : '>'}"


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

const int N = 1e5 + 10, M = 2e5 + 30;
int n, m;
struct edge {
	int y, nxt, id;
}e[M << 1];
int lin[M], len;
int dis[N], pos[N];
bool vis[N];
set<int> c[N];

inline int read() {
	int s = 0, f = 1;
	char ch;
	for(; ch < '0' || ch > '9'; ch = getchar())	if(ch == '-')	f = -1;
	for(; ch >= '0' && ch <= '9'; ch = getchar())	s = (s << 1) + (s << 3) + ch - '0';
	return s * f;
}

inline void add(int xx, int yy, int vv) {
	e[++len] = (edge){yy, lin[xx], vv};
	lin[xx] = len;
}

inline void Dijkstra() {
	priority_queue< pair < int, int > > q;
	memset(dis, 0x3f, sizeof(dis));
	memset(vis, 0, sizeof(vis));
	dis[1] = 0;
	q.push(make_pair(0, 1));
	while(!q.empty()) {
		int x = q.top().second; q.pop();
		if(vis[x])	continue;
		vis[x] = 1;
		for(int i = lin[x]; i; i = e[i].nxt) {
			int y = e[i].y, v = c[x].count(e[i].id) ? 0 : 1;
			if(dis[y] > dis[x] + v) {
				dis[y] = dis[x] + v;
				q.push(make_pair(-dis[y], y));
				c[y].clear();
				c[y].insert(e[i].id);
			} else if(dis[y] == dis[x] + v)	c[y].insert(e[i].id);
		}
	}
}

int main() {
	n = read(), m = read(); 
	if(m == 0) { puts("-1"); return 0; }
	for(int i = 1; i <= m; ++i) {
		int xx = read(), yy = read(), vv = read();
		add(xx, yy, vv);
		add(yy, xx, vv);
	}
	Dijkstra();
	printf("%d\n", dis[n] == 0x3f3f3f3f ? -1 : dis[n]);
	return 0;
}


Measured memory_bytes: 20984
#include<iostream>
#include<algorithm>
#include<vector>
#include<string.h>
#include<math.h>
#include<map>

using namespace std;

int main(){
	int k,s;
	cin >> k >> s;
	int eq=0,df=0,only=0;
	for(int x=0;x<=k;x++){
		for(int y=x;y<=k;y++){
			for(int z=y;z<=k;z++){
				if(x+y+z==s){
					if(x==y&&y==z)eq++;
					else if(x!=y&&y!=z)df++;
					else only++;
				}
			}
		}
	}
	cout << eq+(df*6)+(only*3) << endl;		
	return 0;
}


Measured memory_bytes: 256
s = int(input())
list = [s]
for i in range(1, 1000001):
    if list[i-1]%2==0:
        a = int(list[i-1]/2)
    elif list[i-1]%2==1:
        a = 3*(list[i-1])+1

    if a in list:
        print(i+1)
        break
    else:
        list.append(a)

Measured memory_bytes: 3060