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

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)

using ll = long long;
using ld = long double;
ll INF = LLONG_MAX;

using vi = vector<int>;
using vll = vector<ll>;
using pii = pair<int, int>;

namespace output {
	void pr(int x) { cout << x; }
	void pr(long x) { cout << x; }
	void pr(ll x) { cout << x; }
	void pr(unsigned x) { cout << x; }
	void pr(unsigned long x) { cout << x; }
	void pr(unsigned long long x) { cout << x; }
	void pr(float x) { cout << x; }
	void pr(double x) { cout << x; }
	void pr(ld x) { cout << x; }
	void pr(char x) { cout << x; }
	void pr(const char* x) { cout << x; }
	void pr(const string& x) { cout << x; }
	void pr(bool x) { pr(x ? "true" : "false"); }
	template<class T> void pr(const complex<T>& x) { cout << x; }
	
	template<class T1, class T2> void pr(const pair<T1,T2>& x);
	template<class T> void pr(const T& x);
	
	template<class T, class... Ts> void pr(const T& t, const Ts&... ts) { 
		pr(t); pr(ts...); 
	}
	template<class T1, class T2> void pr(const pair<T1,T2>& x) { 
		pr("{",x.f,", ",x.s,"}"); 
	}
	template<class T> void pr(const T& x) { 
		pr("{"); // const iterator needed for vector<bool>
		bool fst = 1; for (const auto& a: x) pr(!fst?", ":"",a), fst = 0; 
		pr("}");
	}
	
	void print() { pr("\n"); } // print w/ spaces
	template<class T, class... Ts> void print(const T& t, const Ts&... ts) { 
		pr(t); if (sizeof...(ts)) pr(" "); print(ts...); 
	}
}

using namespace output;

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

	int N; cin >> N;
	vi arr (N); 
	F0R(i, N) cin >> arr[i];
	
	vi newarr (N);
	map<int, int> occ;
	F0R(i, N) {
		if (occ[arr[i]] % 2 == 1) newarr.push_back(arr[i]);
		occ[arr[i]]++;
	}

	sort(newarr.rbegin(), newarr.rend());
	if (newarr.size() < 2) {
		print(0);
	} else {
		print(1LL * newarr[0] * newarr[1]);
	}

}

Measured memory_bytes: 5752
#!/usr/bin/env python3
import sys
from decimal import Decimal

def solve(A: int, B: float):
    A = Decimal(str(A))
    
    B = Decimal(str(B))
    
    print(int(A*B))
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = float(next(tokens))  # type: float
    solve(A, B)

if __name__ == '__main__':
    main()


Measured memory_bytes: 10072
#include <bits/stdc++.h>
using ll=long long;
using namespace std;
#define rep_i(i, n) for (int i = 0; i < (n); ++i)
#define rep_ll(i, n) for (long long i = 0; i < (n); ++i)
#define r_rep_i(i, start, end) for (int i = (start); i < (end); ++i)
#define r_rep_ll(i, start, end) for (long long i = (start); i < (end); ++i)
#define debug_vi(v) copy((v).begin(), (v).end(), ostream_iterator<int>(cout, " "));
#define debug_vll(v) copy((v).begin(), (v).end(), ostream_iterator<long long>(cout, " "));
#define debug_vd(v) copy((v).begin(), (v).end(), ostream_iterator<double>(cout, " "));
#define sort_v(v) sort((v).begin(), (v).end()); //昇順
#define d_sort_vi(v) sort((v).begin(), (v).end(), greater<int>()); //昇順
#define d_sort_vd(v) sort((v).begin(), (v).end(), greater<double>()); //昇順

int main(){
  int n;
  string s;
  string t;
  cin >> n >> s >> t;

  bool f = true;
  for (int i = n; i > 0; i--){

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

      if(s[n - i + v] != t[v]){
        f = false;
        break;
      }
    }
    if(f){
      cout << n*2 - i << endl;
      return 0;
    }else{
      f = true;
    }
  }
  cout << n*2 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>

#define repd(i,a,b) for (int i=(a);i<(b);++i)
#define rep(i,n) repd(i,0,n)
#define reprd(i,a,b) for (int i=(a);i>=(b);--i)
#define repr(i,n) reprd(i,n,0)
typedef long long ll;

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

using namespace std;

const ll BIG = 1000000007LL;

int inputValue(){
    int a;
    cin >> a;
    return a;
};

template<typename T>
void inputArray(T* p, int a){
    rep(i, a){
        cin >> p[i];
    }
};

template<typename T>
void inputVector(vector<T> * p, int a){
    rep(i, a){
        T input;
        cin >> input;
        p -> push_back(input);
    }
}

template <typename T>
void output(T a, int precision = 0) {
    if(precision > 0){
        cout << setprecision(precision)  << a << "\n";
    }
    else{
        cout << a << "\n";
    }
}

const int Max = 110;
int N;
string S, T;

int main(int argc, const char * argv[]) {
    cin >> N >> S >> T;
    string ans = "";
    rep(i, N) {
        ans += S[i];
        ans += T[i];
    }

    output(ans);

    return 0;
}

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

#define ll long long

using namespace std;

const int ch = 1000000000;

ll convert(string s) {
   int id = -1;
   ll ans = 0;
   ll n = 1;
   for (int i = 0; i < s.length(); i++)
      if (s[i] == '.')
         id = i;
   int nb = id + 9;
   if (id == -1)
      nb = s.length()+9;
   for (int i = 0; i < nb; i++)
      n*= 10;
   for (int i = 0; i < s.length(); i++) {
      if (s[i] == '.')
         id = i;
      else {
         ans+= (s[i]-'0')* n;
         n/= 10;
      }
   }
   return ans/10;

}

const int r = 1e9;

int main(){
   int N; cin >> N;
   int nb[52][52];
   ll ans = 0;
   memset(nb, 0, sizeof nb);
   vector<pair<int,int>> v;
   for (int i = 0; i < N; i++) {
      string d; cin >> d;
      ll num = convert(d);
      int a, b; a = b = 0;
      while (num%2 == 0) {
         num/= 2;
         a++;
      }
      while (num%5 == 0) {
         num/= 5;
         b++;
      }
      v.push_back({a,b});
      for (int j = 0; j <= a; j++) {
         for (int k = 0; k <= b; k++) {
            nb[j][k]++;
         }
      }
   }
   for (int i = 0; i < N; i++) {
      int a = v[i].first, b = v[i].second;
      ans+= nb[max(18-a,0)][18-b];
      if (a > 8 && b > 8)
         ans--;
   }
   cout << ans/2;
}


Measured memory_bytes: 5284
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <string>
#include <set>
using namespace std;

int main() {
	string s;
	int k;
	cin>>s;
	cin>>k;
	set<string> dp;
	for (int t=0; t<s.length(); ++t)
		for (int i=0, j=t; j<s.length(); ++i, ++j) {
			string t=s.substr(i, j-i+1);
			if (dp.size()<5)
				dp.insert(t);
			else {
				auto ii=--dp.end();
				string t2=*(ii);
				if (t<t2) {
					dp.erase(ii);
					dp.insert(t);
				}
			}
		}
	auto iter=dp.begin();
	for (int i=0; i<k-1; ++i) ++iter;
	cout<<*iter<<endl;
    return 0;
}

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

int main() {
	int w, h, x, y;
	scanf("%d%d%d%d", &w, &h, &x, &y);
	printf("%f %d\n", (double)w * (double)h / 2, 2*x == w && 2*y == h ? 1 : 0);
	return 0;
}

Measured memory_bytes: 256
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_B main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
#endif

#ifdef _DEBUG
void init_global_B() {}
#else

#endif

int main_B() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll X; cin >> X;

    ll sum = 0;
    ll x = X;
    while(x > 0) {
        int d = x % 10;
        sum += d;
        x /= 10;
    }

    string ans = X%sum == 0 ? "Yes" : "No";
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
S = input()
size = len(S)

ans = 0

for bit in range(1 << size - 1):
    exp = S[0]
    for i in range(size - 1):
        if (bit >> i) & 1:
            exp += "+"
        exp += S[i + 1]
    ans += eval(exp)

print(ans)


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

using namespace std;

#define ll long long
#define fix cout << fixed; cout << setprecision(0)





void solve() {

	string s;
	cin >> s;
	cout << s.substr(0, 3);
	




	
}

int main() {

	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	fix;
	solve();

	return 0;
}

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

int main(){
    int N;
    cin >> N;
    set<string> gacha;
    rep(i,N){
        string s;
        cin >> s;
        gacha.insert(s);
    }
    cout << gacha.size() << endl;
    return 0;

}

Measured memory_bytes: 19248
while True:
     a,op,b=map(str,input().split())
     a=int(a)
     b=int(b)
     0<=a,b<=20000
     if op=='?':
          break
     if op=='+':
          print(a+b)
     if op=='-':
          print(a-b)
     if op=='/':
          print(int(a/b))
     if op=='*':
          print(a*b)


Measured memory_bytes: 5600
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <list>
#include <numeric>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;

int a, b = 0,c,d, n, k;
string s, t;


int main()
{
	cin >> a >> b ;
	if (b > 0)
		cout << max(a + b, a * b) << endl;
	else
		cout << max(a - b, a * b) << endl;

	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
    #include <bits/stdc++.h>
    #include <cctype>
    #include <cmath>
    #include <cstdio>
    #include <iomanip>
    #include <iostream>
    #include <list>

    #include <stack>
    #include <string>
    #include <vector>
    #include <bits/stdc++.h>
    #define INFINI (1000 * 1000 * 1000)

    using namespace std;
    //#define s(T) scanf("%d", &T)
    #define sl(T) scanf("%lld", &T)
    #define fill(a, val) memset(a, val, sizeof(a))
    #define mp make_pair
    #define pb push_back
    #define all(x) x.begin(), x.end()
    #define DREP(x) sort(all(x)); x.erase(unique(all(x)), x.end())
    #define INDEX(a, val) (lower_bound(all(a), val) - a.begin())
    #define mod ll(1e9+7)
    typedef long long ll;


    bool compare_first(pair<ll,ll >a,pair<ll,ll >b)
    {
        return a.first<b.first;
    }

     bool compare_second(pair<int,pair<int , int> > a,pair<int,pair<int , int> > b)
    {
        return a.second.first<b.second.first;
    }


    ll min(ll a,ll b)
    {
        if(a>b)return b;
        return a;
    }

int arr[10];
    int main() {
      ios::sync_with_stdio(false);


 string n;int k;
 cin>>n>>k;


 for(int index=0;index<k;index++)
 {
     int input;
     cin>>input;
     arr[input]=1;
 }


    bool add=false;
    for(int index=n.size()-1;index>=0;index--)
    {
        int k=0;
        if(add)
        {
            k=1;

           int indexx=0;
        while(indexx<10&&arr[indexx])
        indexx++;

        for(int ind=n.size()-1;ind>index;ind--)
        {
              n[ind]=('0'+indexx);


        }

            add=false;
        }


        while((n[index]-'0'+k<10)&&arr[(n[index]-'0'+k)])
        {
          k++;
        }
        if(k)
        {
            int indexx=0;
        while(indexx<10&&arr[indexx])
        indexx++;

        for(int ind=n.size()-1;ind>index;ind--)
        {
              n[ind]=('0'+indexx);


        }
        }

        if(n[index]-'0'+k>=10)
        {
            add=true;

           k=0;
        while((n[index]-'0'+k<10)&&arr[n[index]-'0'+k])
            k++;
        }


        n[index]=(n[index]-'0'+k)%10+'0';

    }

    if(add)
    {
        int index=1;
        while(index<10&&arr[index])
        index++;
        cout<<index;

          index=0;
        while(index<10&&arr[index])
        index++;

        for(int ind=0;ind<n.size();ind++)
            cout<<index;
        cout<<endl;
    }
    else
    cout<<n<<endl;


return 0;
    }


/*

 }
 */


Measured memory_bytes: 256
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		double A = sc.nextInt();
		double B = sc.nextInt();
		double H = sc.nextInt();
		double M = sc.nextInt();
		double X = (M*11/360 - H/6) * Math.PI;
		System.out.println(Math.pow(A*A+B*B-2*A*B*Math.cos(X), 0.5));
	}

}

Measured memory_bytes: 36052
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <string>
#include <utility>
#include <cmath>
#include <iomanip>

using namespace std;

#define REP(i,n) for(int (i)=(0);(i)<(n);++i)
#define ll long long
#define INF 1000000000

int main()
{
	int n,k;
	ll ans=INF,buf;
	cin >> n >> k;
	vector<int> h;

	REP(i,n){
		int a; cin >> a;
		h.push_back(a);
	}

	sort(h.begin(),h.end());

	REP(i,n-k+1){
		buf = h[i+k-1]-h[i];
		if(buf<ans)ans = buf;
	}

	cout << ans << endl;

	return 0;
}

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

int main(){
  int N;
  cin >> N;
  vector<int> W(N);
  for (int i = 0; i < N; i++){
    cin >> W[i];
  }
  
  int sum = 0;
  for (int i = 0; i < N; i++){
    sum += W[i];
  }
  
  int sum2 = 0;
  for (int i = 0; i < N; i++){
    sum2 += W[i];
    
    if (sum2 >= sum / 2.0){
      if (sum2 - (sum - sum2) <= (sum - sum2 + W[i]) - (sum2 - W[i])){
        cout << sum2 - (sum - sum2) << endl;
        return 0;
      }
      else{
        if ((sum - sum2 + W[i]) - (sum2 - W[i]) >= 0){
          cout << (sum - sum2 + W[i]) - (sum2 - W[i]) << endl;
          return 0;
        }
        else{
          cout << (sum2 - W[i]) - (sum - sum2 + W[i]) << endl;
          return 0;
        }
      }
    }
  }
}

Measured memory_bytes: 3612
package main

import "fmt"

func main() {
	var n string
	fmt.Scan(&n)

	cnt := 0
	gd := false
	for i := range n[:len(n)-1] {
		if n[i] == n[i+1] {
			cnt++
			if cnt >= 2 {
				gd = true
			}
		} else {
			cnt = 0
		}
	}
	if gd {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define mp make_pair
#define x first
#define y second
#define pb push_back

using namespace std;

typedef long long ll;

ll a[200005];
int pos[200005][25], last[25];

int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++)
        cin >> a[i];

    ll ans = 0;
    for (int i = 1; i <= n; i++)
    {
        for (int j = 0; j < 20; j++)
            pos[i][j] = pos[i - 1][j];

        bitset <20> t = a[i];
        for (int j = 0; j < 20; j++)
        {
            if (t[j] == 1) {pos[i][j] = last[j]; last[j] = i;}
        }

        int mx = 0;
        for (int j = 0; j < 20; j++)
            mx = max(mx, pos[i][j]);
        ans += (ll) (i - mx);
    }
    cout << ans;
    return 0;
}



Measured memory_bytes: 21376
n, a, b = map(int, input().split())

MOD = 1000000007
ans = (pow(2, n, MOD) - 1) % MOD

def conv(n, k):
  x, y = 1, 1
  for i in range(k):
    x = x*(n-i) % MOD
    y = y*(i+1) % MOD
  return x*pow(y,MOD-2,MOD) % MOD

ans = (ans - conv(n, a) - conv(n, b)) % MOD
print(ans)


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

using namespace std;
using ll = long long;

int main() { 
    ll N;
    cin >> N;
    string S[4] = {"AC", "WA", "TLE", "RE"};
    ll C[4] = {};
    string str;
    for(int i=0; i<N; i++){
        cin >> str;
        for(int j=0; j<4; j++){
            if(S[j] == str)C[j]++;
        }
    }

    for(int j=0; j<4; j++){
        cout << S[j] << " x " << C[j] << endl;
    }
}

Measured memory_bytes: 3628
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>

#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 FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define m0(x) memset(x,0,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))


using namespace std;


int dy[4] = { 0,0,1,-1 };
int dx[4] = { 1,-1,0,0 };
int dxx[8] = { 0,0,1,1,1,-1,-1,-1 };
int dyy[8] = { 1,-1,0,1,-1,0,1,-1 };




ll gcd(ll x, ll y) {
	ll m = max(x, y), n = min(x, y);
	if (m%n == 0)return n;
	else return gcd(m%n, n);
}
ll lcm(ll x, ll y) {
	return x / gcd(x, y)*y;
}

ll myPow(ll x, ll n, ll m) {
	if (n == 0)
		return 1;
	if (n % 2 == 0)
		return myPow(x * x % m, n / 2, m);
	else
		return x * myPow(x, n - 1, m) % m;
}

ll pow2(int a, int n) {//aのn乗を計算します。
	int x = 1;
	while (n > 0) {//全てのbitが捨てられるまで。
		if (n & 1) {//1番右のbitが1のとき。
			x = x * a;
		}
		a = a * a;
		n >>= 1;//bit全体を右に1つシフトして一番右を捨てる。
	}
	return x;
}

long long nCr(int n, int r) {
	if (r > n / 2) r = n - r; // because C(n, r) == C(n, n - r)
	long long ans = 1;
	int i;

	for (i = 1; i <= r; i++) {
		ans *= n - r + i;
		ans /= i;
	}

	return ans;
}


const int MOD = 1000000007;

vector<int>trees;
int dif[100020];
int main() {
	int N,K;
	cin>>N>>K;
	REP(i,N){
		int x;
		cin>>x;
		trees.push_back(x);
	}
	VSORT(trees);
	for(int i=0;i<N-K+1;i++){
		dif[i]=trees[i+K-1]-trees[i];
	}
	int ans=999999999;
	REP(i,N-K+1){

		ans=min(ans,dif[i]);
	}
	cout<<ans<<endl;
}

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

int main(){
    int N;
    string S;
    string T;
    cin >> N;
    cin >> S;

    if(N % 2 == 1){
        cout << "No" << endl;
    }else{
        T = S.substr(0,N/2);
        if(S == (T + T)){
            cout << "Yes" <<endl;
        }else{
            cout << "No" << endl;
        }
    }

    return (0);
}

Measured memory_bytes: 256
#include<iostream>
#include<complex>
#include<algorithm>

using namespace std;

typedef complex<double> P;

double cross(P a,P b){
  return (conj(a)*b).imag();
}

bool intersects(P a1,P a2,P b1,P b2){
  P a=a1-a2;
  P b=b1-b2;
  return cross(b1-a2,a)*cross(b2-a2,a)<=0&&cross(a1-b2,b)*cross(a2-b2,b)<=0;
}

int main(){
  int N[2];
  cin>>N[0]>>N[1];
  P p[2][1000];
  double df[2];
  for(int i=0;i<2;i++){
    for(int j=0;j<N[i];j++){
      int x,y;
      cin>>x>>y;
      p[i][j]=P(x,y);
    }
    df[i]=abs(p[i][0]-p[i][1]);
  }
  cout.precision(99);
  cout<<fixed;
  if(!intersects(p[0][0],p[0][1],p[1][0],p[1][1])){
    cout<<df[0]+df[1]<<endl;
  }else{
    double rd[2];
    for(int i=0;i<2;i++){
      double d[1000];
      fill(begin(d),end(d),1e9);
      d[0]=0;
      bool u[1000]={};
      while(!u[1]){
	int x=-1;
	for(int j=0;j<N[i];j++){
	  if(!u[j]&&(x<0||d[x]>d[j])){
	    x=j;
	  }
	}
	u[x]++;
	for(int j=0;j<N[i];j++){
	  if(!intersects(p[i^1][0],p[i^1][1],p[i][x],p[i][j])){
	    d[j]=min(d[j],d[x]+abs(p[i][x]-p[i][j]));
	  }
	}
      }
      rd[i]=d[1];
    }
    if(rd[0]<1e9||rd[1]<1e9){
      cout<<min(df[0]+rd[1],df[1]+rd[0])<<endl;
    }else{
      cout<<-1<<endl;
    }
  }
}

Measured memory_bytes: 1300
n, m, c = map(int, input().split())
num = list(map(int, input().split()))
code_list = []
ans = 0

for _ in range(n):
    code_list.append(list(map(int, input().split())))

for code in code_list:
    result = 0
    for i, co in enumerate(code):
        result += co * num[i]
    if result + c > 0:
        ans += 1

print(ans)


Measured memory_bytes: 3060
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

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

		int n = sc.nextInt();
		int q = sc.nextInt();

		Node node[] = new Node[n];
		// 頂点の作成
		for (int i = 0; i < n; i++) {
			node[i] = new Node(i);
		}

		// 辺情報
		for (int i = 0; i < n - 1; i++) {
			int nodeA = sc.nextInt() - 1;
			int nodeB = sc.nextInt() - 1;

			node[nodeA].adjList.add(node[nodeB]);
			node[nodeB].adjList.add(node[nodeA]);
		}

		// 親方向の隣接情報を消す
		//removeParent(0, node);

		/*
		for (int i = 0; i < n; i++) {
			printDebug(node[i]);
		}
		*/

		// カウンター計算
		for (int i = 0; i < q; i++) {
			int subRoot = sc.nextInt() - 1;
			long count = sc.nextLong();

			node[subRoot].offset += count;
		}
		dfs(null, node[0], 0);

		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < n; i++) {
			sb.append(node[i].count).append(" ");
		}
		System.out.println(sb.toString());
		sc.close();
	}

	private static void dfs(Node parent, Node node, int sum) {
		sum += node.offset;
		node.count = sum;
		for (Node adj : node.adjList) {
			if (adj != parent) {
				dfs(node, adj, sum);
			}
		}
	}

	private static void printDebug(Node node) {
		System.out.println("===============================");
		System.out.println("id  = " + node.id);
		System.out.print("adj = ");
		for (Node adj : node.adjList) {
			System.out.print(adj.id + " ");
		}
		System.out.println();
		System.out.println("count = " + node.count);
	}

	private static void removeParent(int id, Node[] node) {
		for (Node adj : node[id].adjList) {
			node[adj.id].adjList.remove(node[id]);
			removeParent(adj.id, node);
		}
	}

	static class Node {
		int id;
		List<Node> adjList;
		long count;
		long offset;

		// コンストラクタ
		public Node(int id) {
			this.id = id;
			this.adjList = new ArrayList<Node>();
			this.count = 0;
			this.offset = 0;
		}
	}

}


Measured memory_bytes: 209220
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.*;

public class Main {

	public static void main(String[] args) throws IOException {
		InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
		BufferedReader in = new BufferedReader(reader);
		String S = in.readLine();
		int f = Integer.parseInt(S.substring(0, 2));
		int s = Integer.parseInt(S.substring(2, 4));
		in.close();
		if( 1 <= f && f <= 12) {
			if(1 <= s && s <= 12) {
				System.out.println("AMBIGUOUS");				
			}else {
				System.out.println("MMYY");
			}
		}else {
			if(1<=s && s <= 12) {
				System.out.println("YYMM");
			}else {
				System.out.println("NA");
			}
		}
		
	}

}


Measured memory_bytes: 24404
#include <iostream>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <iomanip>
using namespace std;

string b[70];
string memo[70][70];

bool comp(string s1, string s2) {
	if(s1.size() == s2.size()) return s1 < s2;
	return s1.size() < s2.size();
}

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

	int W, H;
	while(cin >> W >> H, W | H) {
		for(int i = 0; i < H; i++) {
			cin >> b[i];
		}
		for(int i = 0; i < H; i++) {
			for(int j = 0; j < W; j++) {
				memo[i][j] = "";
				if('1' <= b[i][j] && b[i][j] <= '9') memo[i][j] += b[i][j];
			}
		}

		for(int i = 0; i < H; i++) {
			for(int j = 0; j < W; j++) {
				if('0' <= b[i][j] && b[i][j] <= '9') {
					if(i + 1 < H) {
						if('0' <= b[i + 1][j] && b[i + 1][j] <= '9') {
							memo[i + 1][j] = max(memo[i + 1][j], memo[i][j] + b[i + 1][j], comp);
							if(memo[i + 1][j] == "0") memo[i + 1][j] = "";
						}
					}
					if(j + 1 < W) {
						if('0' <= b[i][j + 1] && b[i][j + 1] <= '9') {
							memo[i][j + 1] = max(memo[i][j + 1], memo[i][j] + b[i][j + 1], comp);
							if(memo[i][j + 1] == "0") memo[i][j + 1] = "";
						}
					}
				}
			}
		}

		string ans = "";
		for(int i = 0; i < H; i++) {
			for(int j = 0; j < W; j++) {
				ans = max(ans, memo[i][j], comp);
			}
		}

		cout << ans << endl;
	}

}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef pair<int, int> Pint;
typedef pair<int64_t, int64_t> Pll;


int main() {
    int N;
    double X = 1.08;
    cin >> N;
    for (int i = 0; i <= N; i++) {
        double a = i;
        if (int(a * X) == N) {
            cout << i << endl;
            return 0;
        }
    }
    cout << ":(" << endl;
}


Measured memory_bytes: 256
N = int(input())
H = list(map(int,input().split()))

for i in range(N-1):
    if H[i+1] - H[i] > 0:
        H[i+1] -= 1

for i in range(N-1):
    if H[i+1] < H[i]:
        print("No")
        exit()

print("Yes")

Measured memory_bytes: 20528
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using G = vector<vector<int>>;
    
int main(){
    ll a, b, v, w, t;
    cin >> a >> v >> b >> w >> t;
    ll dis = abs(b-a);
    ll vel = v - w;
    if(vel<=0) cout << "NO" << endl;
    else {
        double tr = (double)dis / (double)vel;
        if(tr<=t) cout << "YES" << endl;
        else cout << "NO" << endl;    
    }
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define int long long
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

const int MAX_V = 100010;
vector<P> G[MAX_V];
int color[MAX_V]; 

void dfs(int now, int pre, int dist){
    if(color[now] != -1) return;
    color[now] = dist % 2;
    for(auto j : G[now]){
        if(j.first == pre) continue;
        dfs(j.first, now, dist + j.second);
    }
}

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    rep(i, 0, n - 1){
        int u, v, w;
        cin >> u >> v >> w;
        u--; v--;
        G[u].push_back({v, w});
        G[v].push_back({u, w});
    }
    rep(i, 0, n) color[i] = -1;
    dfs(0, -1, 0);
    rep(i, 0, n){
        cout << color[i] << endl;
    }
}

Measured memory_bytes: 10240
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair

using ll = long long;
using namespace std;
int x, y, z, l, m, n, r, q, k;

void solve() {
    int mdiff = INT_MAX;
    string s;
    cin>>s; n = s.size();
    for(int i=0;i<n-2;i++){
        int diff = abs(stoi(s.substr(i, 3))-753);
        mdiff = min(mdiff, diff);
    }
    cout<<mdiff<<'\n';

}

int main() 
{
    std::ios::sync_with_stdio(false); \
        std::cin.tie(NULL);
    int test;
    test = 1;
    while (test--) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3600
#include <stdio.h>
int main(){
	int n;
	int s;
	int i;
	int all[101][10];
	int j,k;
	for(j=0;j<101;j++)for(k=0;k<10;k++)all[j][k]=0;
	int bcnt;
	int bnum;
	for(i=1;i<(0x1<<10);i++){
		bcnt=0;
		bnum=0;
		for(j=0;j<10;j++){
			if(i&(0x1<<j)){
				bcnt++;
				bnum+=j;
			}
		}
		if(bnum<=100)all[bnum][bcnt]++;
	}
	while(1){
		scanf("%d %d\n",&n,&s);
		if(!n&&!s)break;
		printf("%d\n",all[s][n]);
	}
	
	return 0;
}

Measured memory_bytes: 608
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int nmax=100005;
const int INF=-1e9;
vector<vector<pair<int,int>>> g(nmax);
bool f=false;
vector<int> d(nmax,-INF);
void bfs(int s){
    queue<int> q;
    q.push(s);
    d[s]=0;
    while(!q.empty()){
        int p=q.front();
        q.pop();
        for(auto x:g[p]){
            if(d[x.first]==-INF){
                d[x.first]=d[p]+x.second;
                q.push(x.first);
            }
            else{
                if(d[x.first]!=d[p]+x.second){
                    f=true;
                }
            }
        }
    }
}
int main(){
    int n,m;cin >> n >> m;
    for(int i=0;i<m;i++){
        int l,r,d;cin >> l >> r >> d;
        l--,r--;
        g[l].push_back({r,d});
        g[r].push_back({l,-d});
    }
    for(int i=0;i<n;i++){
        if(d[i]==-INF){
            bfs(i);
            if(f){
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 9344
/**
 *   Author: Praveen Ojha
 *   Created: 24 March 2019
 *   Time: 15:42:57
**/
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define mod 1000000007
#define PI 3.141592653589793238510
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define __ ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

typedef long double ld;
typedef pair<int,int> pii;
template <typename T> void max_self(T &a,T b){
	a=max(a,b);
}
bool is_first_row_or_col(pii temp){
	return temp.first==0 || temp.second==0 ;
}
int32_t main(){__
	string s1,s2;
	cin>>s1>>s2;
	vector<vector<pair<int,pii>>> dp(s1.length()+1,vector<pair<int,pii>>(s2.length()+1,{0,{0,0}}));
	for(int i=0;i<(int)s1.length();i++){
		for(int j=0;j<(int)s2.length();j++){
			if(s1[i]==s2[j]){
				max_self(dp[i+1][j+1],{dp[i][j].first+1,{i,j}});
			}
			max_self(dp[i+1][j],{dp[i][j].first,{i,j}});
			max_self(dp[i][j+1],{dp[i][j].first,{i,j}});
		}
	}
	pair<int,pii> ans={0,{0,0}};
	// for(auto i:dp){
	// 	for(auto j:i){
	// 		max_self(ans,j);
	// 	}
	// }
	for(int i=0;i<=(int)s1.length();++i){
		for(int j=0;j<=(int)s2.length();++j){
			//cout<<"["<<dp[i][j].first<<","<<"("<<dp[i][j].second.first<<","<<dp[i][j].second.second<<")] ";
			max_self(ans,make_pair(dp[i][j].first,make_pair(i,j)));
		}
		//cout<<"\n";
	}
	//cout<<ans.first<<" "<<"("<<ans.second.first<<","<<ans.second.second<<")\n";
	string s="";
	pii cur=ans.second;
	while(!is_first_row_or_col(cur)){
		int i=cur.first,j=cur.second;
		pii prev=dp[i][j].second;
		if(prev.first==i-1 && prev.second==j-1){
			//assert(s1[i-1]==s2[j-1]);
			if(s1[i-1]==s2[j-1])
			s+=s1[i-1];
		}
		cur=prev;
	}
	reverse(all(s));
	cout<<s<<"\n";
return 0;
}

Measured memory_bytes: 211456
struct UnionFind {
    roots: Vec<usize>,
}

impl UnionFind {
    fn new(n: usize) -> UnionFind {
        let mut roots = vec![];
        for i in 0..n {
            roots.push(i);
        }
        UnionFind { roots: roots }
    }
    fn find(&mut self, i: usize) -> usize {
        if self.roots[i] == i {
            i
        } else {
            let tmp_i = self.roots[i];
            self.roots[i] = self.find(tmp_i);
            self.roots[i]
        }
    }
    fn unite(&mut self, i: usize, j: usize) {
        let root_i = self.find(i);
        let root_j = self.find(j);
        self.roots[root_i] = root_j;
    }
}

fn main() {
    proconio::input! {
        n: usize,
        m: usize,
        abs: [(usize, usize); m],
    }
    let abs = abs
        .iter()
        .cloned()
        .map(|(a, b)| (a - 1, b - 1))
        .collect::<Vec<_>>();
    let mut union_find = UnionFind::new(n);
    for (a, b) in abs {
        union_find.unite(a, b);
    }
    let mut m = std::collections::HashMap::new();
    (0..n).map(|i| union_find.find(i)).for_each(|x| {
        *m.entry(x).or_insert(0) += 1;
    });
    let ans = m.values().max().unwrap();
    println!("{}", ans);
}


Measured memory_bytes: 15408
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pb push_back
#define f(i,x,n) for(int i=x;i<n;i++)
#define all(c) c.begin(),c.end()
#define int ll
using ll = long long;
using pii = pair<int,int>;
const int MOD = 1e9+7, N = 1e5 + 10; 

vector<int> g[N];
int vis[N];
int parent[N];
vector<int> o;

void dfs(int u){
   vis[u] = 1;
   o.pb(u);
   for(auto &v : g[u]){
      if(!vis[v]){
         dfs(v);
      }
   }
}

int32_t main(){
   ios::sync_with_stdio(false);
   cin.tie(NULL);
   int n,m,k;
   cin >> n >> m >> k;
   f(i,0,m){
      int a,b;
      cin >> a >> b;
      g[a].pb(b);
      g[b].pb(a);
   }
   int cnt = 1;
   vector<int> ans(n+1);
   f(i,1,n+1){
      if(!vis[i]){
         dfs(i);
         for(auto &e : o){
            parent[e] = cnt;
         }
         cnt++;
         for(auto &e : o){
            ans[e] = o.size();
            ans[e] -= (int)g[e].size();
         }
         o.clear();
      }
   }
   f(i,0,k){
      int a,b;
      cin >> a >> b;
      if(parent[a] == parent[b]){
         ans[a]--;
         ans[b]--;
      }
   }
   f(i,1,n+1){
      cout << ans[i]-1 << ' ';
   }
   cout << '\n';
   return 0;
} 

Measured memory_bytes: 11000
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
    int a,b,c;
    cin>>a>>b>>c;
    if(a%2==0||b%2==0||c%2==0){
        cout<<0<<endl;
    }else{
        cout<<min(a*b,min(b*c,c*a))<<endl;
    }
    return 0;
}

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

int main() {
  int x, a;
  cin >> x >> a;
  if(x < a) cout << 0 << endl;
  else cout << 10 << endl;
  return 0;
}


Measured memory_bytes: 256
using AtCoderBeginnerContest140.Questions;
using AtCoderBeginnerContest140.Extensions;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace AtCoderBeginnerContest140.Questions
{
    public class QuestionD : AtCoderQuestionBase
    {
        public override IEnumerable<object> Solve(TextReader inputStream)
        {
            var nk = inputStream.ReadIntArray();
            var n = nk[0];
            var k = nk[1];
            var s = "_" + inputStream.ReadLine() + "_";

            var happyCount = 0;

            for (int i = 1; i <= n; i++)
            {
                if ((s[i] == 'L' && s[i - 1] == 'L') || (s[i] == 'R' && s[i + 1] == 'R'))
                {
                    happyCount++;
                }
            }

            yield return Math.Min(happyCount + 2 * k, n - 1);
        }
    }
}


namespace AtCoderBeginnerContest140
{
    class Program
    {
        static void Main(string[] args)
        {
            IAtCoderQuestion question = new QuestionD();    // 問題に合わせて書き換え
            var answers = question.Solve(Console.In);
            foreach (var answer in answers)
            {
                Console.WriteLine(answer);
            }
        }
    }
}

#region Base Classes

namespace AtCoderBeginnerContest140.Questions
{

    public interface IAtCoderQuestion
    {
        IEnumerable<object> Solve(string input);
        IEnumerable<object> Solve(TextReader inputStream);
    }

    public abstract class AtCoderQuestionBase : IAtCoderQuestion
    {
        public IEnumerable<object> Solve(string input)
        {
            var stream = new MemoryStream(Encoding.Unicode.GetBytes(input));
            var reader = new StreamReader(stream, Encoding.Unicode);

            return Solve(reader);
        }

        public abstract IEnumerable<object> Solve(TextReader inputStream);
    }

}

#endregion

#region Extensions

namespace AtCoderBeginnerContest140.Extensions
{
    internal static class TextReaderExtensions
    {
        internal static int ReadInt(this TextReader reader) => int.Parse(ReadString(reader));
        internal static long ReadLong(this TextReader reader) => long.Parse(ReadString(reader));
        internal static double ReadDouble(this TextReader reader) => double.Parse(ReadString(reader));
        internal static string ReadString(this TextReader reader) => reader.ReadLine();

        internal static int[] ReadIntArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(int.Parse).ToArray();
        internal static long[] ReadLongArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(long.Parse).ToArray();
        internal static double[] ReadDoubleArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(double.Parse).ToArray();
        internal static string[] ReadStringArray(this TextReader reader, char separator = ' ') => reader.ReadLine().Split(separator);
    }
}

#endregion

Measured memory_bytes: 13396
#include<iostream>
#include<cstring>
using namespace std;
int x, a, b, c;
int cnt = 0;
int main()
{
	scanf("%d%d%d%d", &a, &b,&c, &x);//a 10的个数 b 2的个数 c 1的个数
	int t = x / 50;
	for (int i = 0; i <= a; i++)
	{
		for (int j = 0; j <= b; j++)
		{
			for (int k = 0; k <= c; k++)
			{
				if ((10 * i + 2 * j + k) == t)cnt++;
			}
		}
	}
	printf("%d", cnt);
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        new Main().run();
    }

    private void run() {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int A = scanner.nextInt();
        int B = scanner.nextInt();
        if(N * A < B) {
            System.out.println(N * A);
            return;
        }

        System.out.println(B);

    }
}


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

using namespace std;
 
#define MD 1000000007
typedef long long int ll;

int main(){
    int n;
    cin>>n;
    map<string,int> mp;
    for(int i=0;i<n;i++){
        string tmp;
        cin>>tmp;
        if(!mp.count(tmp)){
            mp[tmp]=1;
        }else{
            mp[tmp]++;
        }
    }
    int m;
    cin>>m;
    for(int i=0;i<m;i++){
        string tmp;
        cin>>tmp;
        if(!mp.count(tmp)){
            mp[tmp]=-1;
        }else{
            mp[tmp]--;
        }
    }
    int ans=0;
    for(auto itr=mp.begin();itr!=mp.end();itr++){
        ans=max(ans,itr->second);
     }
    
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
	int number[5],max = -1,position = -1,total = 0;
	for(int i = 0;i<3;i++){
		scanf("%d",&number[i]);
		if(number[i]>max){
			max = number[i];
			position = i;
		}
	}
	int multiply;
	scanf("%d",&multiply);
	while(multiply--){
		number[position] *= 2;
	}
	for(int i = 0;i<3;i++){
		total += number[i];
	}
	printf("%d\n",total);
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int k;
    cin>>k;
	int count=0;
	for(int i=1;i<=k;i++)
	{
		for(int j=1;j<=k;j++)
		{
			int a=__gcd(i,j);
			for(int r=1;r<=k;r++)
			{
				count+=__gcd(a,r);
			}
		}
	}
	cout<<count;
}

Measured memory_bytes: 3636
#include <iostream>
#include <cstdio>
#include <climits>

using namespace std;

int A[500000+10];
int n,i,j,sum=0;

int Merge(int A[],int left,int mid,int right)
{
    int n1=mid-left;
    int n2=right-mid;
    int L[n1+1],R[n2+1];
    L[n1]=INT_MAX;
    R[n2]=INT_MAX;
    for(i=0;i<n1;i++)
    {
        L[i]=A[left+i];
    }
    for(i=0;i<n2;i++)
    {
        R[i]=A[i+mid];
    }
    i=0;
    j=0;
    for(int k=left;k<right;k++)
    {
        if(L[i]<=R[j])
            A[k]=L[i++];
        else
            A[k]=R[j++];
        sum++;
    }
}

int Merge_sort(int A[],int left,int right)
{
  if(left+1<right)
  {
   int mid=(left+right)/2;
   Merge_sort(A,left,mid);
   Merge_sort(A,mid,right);
   Merge(A,left,mid,right);
  }
}


int main()
{
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        scanf("%d",&A[i]);
    }
    Merge_sort(A,0,n);
    for(i=0;i<n;i++)
    {
      printf("%d%c", A[i], i == n - 1 ? '\n' : ' ');
    }
    printf("%d\n", sum);
    return 0;
}



Measured memory_bytes: 7028
import java.util.*;

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

    	int n = sc.nextInt();
    	int k = sc.nextInt();
    	int[] a = new int[n];
    	for(int i = 0; i < n; i++) {
    		a[i] = sc.nextInt();
    	}

    	boolean[] dp = new boolean[k+1];
    	for(int i = 0; i <= k; i++) {
    		for(int j : a) {
    			if(j <= i && !dp[i - j]) {
    				dp[i] = true;
    			}
    		}
    	}
    	// System.out.println(Arrays.toString(dp));

    	if(dp[k])
    		System.out.println("First");
    	else
    		System.out.println("Second");
    }
}

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

const int MAX_N = 2e5+10;
int N;
ll K;
ll A[MAX_N];
ll psum[MAX_N];

void solve()
{
	// 1. (sum(A[j]) - sum(A[i-1])) % K == (j-i+1) % K
	// 2. j-i+1 < K
	for(int i=1;i<=N;++i) psum[i]=(psum[i-1]+A[i])%K;
	for(int i=1;i<=N;++i){
		psum[i]=((psum[i]-i)%K + K) % K; 
	}
	ll ans = 0;
	map<ll, ll> cnt;
	cnt[0]=1;
	for(int j=1;j<=N;++j){
		if(j-K>=0) cnt[psum[j-K]]--;
		ans += cnt[psum[j]];
		cnt[psum[j]]++;
	}
	cout << ans << "\n";
}

int main()
{
	cin >> N >> K;
	for(int i=1;i<=N;++i){
		cin >> A[i];
		A[i] %= K;
	}
	solve();
	return 0;
}

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

alias sread = () => readln.chomp();
alias Point2 = Tuple!(long, "y", long, "x");
long bignum = 1_000_000_007;
auto dp = new long[](100_100);

T lread(T = long)()
{
    return readln.chomp.to!T();
}

T[] aryread(T = long)()
{
    return readln.split.to!(T[])();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}

void main()
{
    long n, m;
    scan(n, m);
    auto denger = new long[](m);
    foreach (ref e; denger)
    {
        e = lread();
    }
    long[] tmp = [0];
    auto need = step(denger ~ tmp, n);
    need.writeln();
}

long step(long[] denger, long n)
{
    ulong j;
    if (denger[j] != 1)
        dp[0] = 1;
    else
        j++;

    if (denger[j] != 2)
        dp[1] = dp[0] + 1;
    else
        j++;

    foreach (i; 2 .. n)
    {
        if (i == denger[j] - 1)
        {
            dp[i] = 0;
            j++;
        }
        else
        {
            dp[i] = (dp[i - 1] + dp[i - 2]) % bignum;
        }
    }
    return dp[n - 1];
}


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

int main() {
    int N;
    cin >> N;
    N = N % 10;
    
    if(N == 2 || N==4 || N==5 || N==7 || N==9){
        cout << "hon"<< endl;
    }else if(N == 0 || N==1 || N==6 || N==8 ){
        cout << "pon"<< endl;
    }else{
        cout << "bon"<< endl;
    }

	return 0;
}

Measured memory_bytes: 3596
n, m = map(int, input().split())
edge = []

for _ in range(m):
    a, b, c = map(int, input().split())
    edge.append([a-1, b-1, -c])

d = [float("inf") for _ in range(n)]
d[0] = 0

check = [0 for _ in range(n)]

for i in range(n):
    for now, next, weight in edge:
        if d[next] > d[now] + weight:
            d[next] = d[now] + weight
            if i == n-1:
                check[next] = 1
        if i == n-1:
            if check[now]:
                check[next] = 1

if check[-1]:
    print("inf")
else:
    print(-d[-1])

Measured memory_bytes: 3444
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dsync std::ios::sync_with_stdio(false); std::cin.tie(NULL);
#define pb push_back
#define mp make_pair
typedef long long ll;

//#define foi(a, b) for (LL i = a; a < b ? i < b : b > i; a < b ? i++ : i--)
//#define foj(a, b) for (LL j = a; a < b ? j < b : b > j; a < b ? j++ : j--)

using namespace std;

int main()
{
   
   int node, edge;
   cin >> node >> edge;
   vector<vector<int>> adj(node + 1);
   for (int i = 1; i <= edge; i++)
   {
      int a, b;
      cin >> a >> b;
      adj[a].pb(b);
      adj[b].pb(a);
   }

   queue<int> q;
   vector<bool> visited(node + 1, false);
   vector<int> distance(node + 1, 0);

   visited[1] = true;
   distance[1] = 0;
   q.push(1);

   while (!q.empty())
   {
      int s = q.front();
      q.pop();

      for (auto u : adj[s])
      {
         if (visited[u])
            continue;

         visited[u] = true;
         distance[u] = s;
         q.push(u);
      }
   }
   for (int x = 2; x <= node; x++)
   {
      if (distance[x] == 0)
      {
         cout << "No" << endl;
         return 0;
      }
   }
   cout << "Yes" << endl;
   for (int x = 2; x <= node; x++)
   {
      cout << distance[x] << endl;
   }
   return 0;
}


Measured memory_bytes: 10036
n, m = map(int, input().split())
x = list(map(int, input().split()))

if n >= m:
    print(0)
    exit()

x.sort()

y = [0] * (m - 1)
for i in range(m - 1):
    y[i] = x[i + 1] - x[i]

y.sort(reverse=True)

print(sum(y[n-1:]))

Measured memory_bytes: 13968
let rec print_rect x =
  let (h,w) = Scanf.scanf "%d %d\n" (fun x y -> (x,y) )in
  match (h,w) with
    (0,0) -> ()
  | (h,w) ->
     for i=1 to h do
       for j=1 to w do
         match (i mod 2, j mod 2) with
           (1,1) | (0,0) -> print_string "#"
           | _ -> print_string "."
       done;
       print_newline ();
     done;
     print_newline ();
     print_rect x;;
 let () = print_rect ();;

Measured memory_bytes: 2228
#include <stdio.h>

int main(void)
{
	int j, N, n, i;
	
	scanf("%d", &N);
	j = 1;
	while (j <= N){
		scanf("%d", &n);
		
		printf("Case %d:\n", j);
		for (i = 0; i < 10; i++){
			n = ((n * n) % 1000000) / 100;
			printf("%d\n", n);
		}
		j++;
	}
	
	return (0);
}

Measured memory_bytes: 592
#include <bits/stdc++.h>
#define ALL(x) (x).begin(),(x).end()
#define PB push_back
#define MP make_pair
#define Mod 998244353
using namespace std;
using lint = long long;
using vi = vector<lint>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;

// cout << fixed << setprecision(12)

int main(){
  lint N,K;
  cin >> N >> K;
  vi p(N);
  for(lint i=0; i<N; i++) cin >> p[i];
  
  sort(ALL(p));
  
  lint ans = 0;
  for(lint k=0; k<K; k++){
    ans += p[k];
  }
  
  cout << ans << endl;
}
  


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

const map<int, int> g_num_matches = {
    {1, 2},
    {2, 5},
    {3, 5},
    {4, 4},
    {5, 5},
    {6, 6},
    {7, 3},
    {8, 7},
    {9, 6},
};

bool compare(const array<int, 6>& a, const array<int, 6>& b, vector<int> order){
    int na = 0;
    int nb = 0;
    for(auto& n : a) na += n;
    for(auto& n : b) nb += n;
    if     (na > nb) return true;
    else if(na < nb) return false;
    for(auto i : order){
        if     (a[i] == b[i]) continue;
        else if(a[i] > b[i]) return true;
        else                 return false;
    }
    return false;
}

int main()
{
    int N, M;
    cin >> N >> M;
    int Ai;
    vector<int> useNum(6, 0);
    for(int i=0;i<M;i++){
        cin >> Ai;
        auto n = g_num_matches.at(Ai) - 2;
        useNum[n] = max(useNum[n], Ai);
    }

    map<int, int> orderm;
    for(int i=0; i<6; i++){
        if(useNum[i] == 0) continue;
        orderm[-useNum[i]] = i;
    }
    vector<int> order;
    for(auto& m : orderm) order.push_back(m.second);

    vector<int> dp(N+1, -1);
    dp[0] = 0;
    vector<array<int, 6>> nums(N+1, array<int, 6>{0, 0, 0, 0, 0, 0});
    for(int i=0; i<=N; i++){
        for(int j=0; j<6; j++){
            if(useNum[j] == 0) continue;
            auto k = i-(j+2);
            if(k < 0) continue;
            if(dp[k] < 0) continue;
            if(dp[i] <= 1 + dp[k]){
                dp[i] = 1 + dp[k];
                auto nums_new = nums[k];
                nums_new[j]++;
                if(compare(nums_new, nums[i], order)){
                    nums[i] = nums_new;
                }
            }
        }
    }

    string S;
    for(auto i : order){
        S += string(nums[N][i], '0' + useNum[i]);
    }
    cout << S << endl;

    return 0;
}


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

int main(){
	int n, a, b, c, x, y;
	while (1){
		cin >> n >> a >> b >> c >> x;
		if (n == 0 && a == 0 && b == 0 && c == 0 && x == 0){
			break;
		}
		int f = 0;
		for (int i = 0; i < n; i++){
			cin >> y;
			if (f != -1){
				while (1){
					if (y == x){
						if (n != i + 1){
							x = (a * x + b) % c;
							f++;
						}
						break;
					}
					x = (a*x + b) % c;
					f++;
					if (f > 10000){
						f = -1;
						break;
					}
				}
			}
		}
		cout << f << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include<stdio.h>
int func(int,int);
int main()
{
  int a,b;
  while(scanf("%d%d",&a,&b)!=EOF) printf("%d\n",func(a,b));
  return 0;
}
int func(int a,int b)
{
  int rep;
  while(a%b!=0)
    {
      rep=a%b;
      a=b;
      b=rep;
    }
  return b;
}

Measured memory_bytes: 596