akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <climits>
#include <algorithm>
#include <map>

using ll = long long;

class Recursive
{
private:
    ll P1;
    std::map<int,ll> divmaps;
    std::map<ll,ll> memo;

    ll ff(ll n)
    {
        if (auto it = memo.find(n); it != memo.end()) return memo[n];

        ll ans = (n >= LLONG_MAX / P1) ? LLONG_MAX : n * P1;


        for (auto [div, T] : divmaps)
        {
            if (n >= div)
            {
                ll fp = ff(n/div);
                if (int m = n % div; m == 0)
                    ans = std::min(ans, fp + T);
                else
                {
                    ll fn = ff(n/div+1);
                    ans = std::min({ans, fp + T + P1 * m, fn + T + P1 * (div-m)});
                }
            }
        }

        return memo[n] = ans;
    }

public:
    Recursive(int A, int B, int C, int D)
    {
        divmaps[2] = A;
        divmaps[3] = B;
        divmaps[5] = C;
        P1 = D;
    }

    ll go(ll N)
    {
        return ff(N);
    }
};

int main()
{
    int T;
    std::cin >> T;
    while(T--)
    {
        ll N;
        int A, B, C, D;
        std::cin >> N >> A >> B >> C >> D;

        Recursive r(A, B, C, D);
        ll ans = r.go(N);
        std::cout << ans << std::endl;
    }
}

Measured memory_bytes: 4452
import itertools
s = input()
n = int(s)
l = len(s)
lst = []
for i in range(3, l + 1):
    lst += list(itertools.product([3, 5, 7], repeat=i))
lst = [x for x in lst if 3 in x]
lst = [x for x in lst if 5 in x]
lst = [x for x in lst if 7 in x]
lst = [int("".join(map(str, x))) for x in lst]
lst = [x for x in lst if x <= n]
print(len(lst))


Measured memory_bytes: 7920
x=int(input())
count=x//11
if x%11==0:
    print(x//11*2)
else:
    if x<=count*11+6 and x<=count*11+10:
        print(min(count*2+1,count*2+2))
    elif x<=count*11+6:
        print(count*2+1)
    else:
        print(count*2+2)

Measured memory_bytes: 3060
from collections import deque

s = input()
q = int(input())
revflag = 1
d = deque(s)
for i in range(q):
	tfc = list(map(str, input().split()))
	if tfc[0] == '1':
		revflag *= -1
	elif tfc[1] == '1':
		if revflag > 0:
			d.appendleft(tfc[2])
		else:
			d.append(tfc[2])
	else:
		if revflag > 0:
			d.append(tfc[2])
		else:
			d.appendleft(tfc[2])
if revflag > 0:
	print(''.join(d))
else:
	print(''.join(reversed(d)))

Measured memory_bytes: 8692
#include <iostream>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#define endl "\n"
using namespace std;

int main()
{
    string s1, s2, s3;
    cin >> s1 >> s2 >> s3;

    char c1 = s1[0] - 32;
    char c2 = s2[0] - 32;
    char c3 = s3[0] - 32;
    cout << c1 << c2 << c3 << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int N,M,B[105],i,r,l,m;

int ch(int w)
{
	int t=0,i,d=1;
	for(i=0;i<N;i++)
	{
		if(w<B[i])return 0;
		if(t+B[i]>w)
		{
			d++;
			t=0;
		}
		t+=B[i];
	}
	return d<=M;
}

int main()
{
	for(;scanf("%d%d",&M,&N),N;)
	{
		for(i=0;i<N;i++)
			scanf("%d",&B[i]);
		for(l=0,r=1500001;r-l>1;)
		{
			m=(l+r)/2;
			if(ch(m))r=m;//OK
			else l=m;//NG
		}
		printf("%d\n",r);
	}
	return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <stdio.h>
using namespace std;

long long factorial(long long k) {
    long long sum = 1;
    for(int i = 1; i <= k; i++) {
        sum *= i;
    }
    return sum;
}

void solve(long long N, long long M){
    long long sum_n = factorial(N);
    long long sum_m = factorial(M);
    cout << N*(N-1)/2 + M*(M-1)/2 << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);
    solve(N, M);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lli = long long int;
using ulli = unsigned long long int;
#define debug(x) cerr << #x << " : " << x << endl
#define debugv(x) cerr << #x << " : {";for(auto value_of_x:x){ cerr << value_of_x << ", ";}cerr << endl


namespace atcoder {
	template<typename T>
	T ncr(T left, T right) {
		right = min(left - right, right);
		T ans = 1;
		for (T i = 1; i <= right; i++) {
			ans = ans * (left - right + i) / i;
		}
		return ans;
	}

	const int MOD = 1000000007;
	const lli LIMIT = 1'0'000'000'000'000'000 * 5;
	const int tenfive = 100000;
}

using namespace atcoder;


int main() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	cout << (a - c) * (b-d) << endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <limits.h>

const int MAX = 5e5;
const int INF = INT_MAX;

void merge(int*, int, int, int);
void mergesort(int*, int, int);

int ans;

int main(){
  int n, i, a[MAX];

  scanf("%d" ,&n);
  for(i = 0 ; i < n ; i++){
    scanf("%d" ,a + i);
  }

  mergesort(a, 0, n);

  for(i = 0 ; i < n ; i++){
    printf("%d%c" ,a[i], i != n-1 ? ' ':'\n');
  }
  printf("%d\n" ,ans);

  return 0;
}

void merge(int a[], int left, int mid, int right){
  int n1 = mid - left, n2 = right - mid;
  int L[n1+1], R[n2+1], i, j, k;

  for(i = 0 ; i < n1 ; i++){
    L[i] = a[left + i];
  }

  for(i = 0 ; i < n2 ; i++){
    R[i] = a[mid + i];
  }

  L[n1] = R[n2] = INF;

  for(i = 0, j = 0, k = left ; k < right ; k++, ans++){
    if(L[i] <= R[j]){
      a[k] = L[i++];
    }else{
      a[k] = R[j++];
    }
  }
}

void mergesort(int a[], int left, int right){
  int mid;

  if(left + 1 < right){
    mid = (left + right) / 2;
    mergesort(a, left, mid);
    mergesort(a, mid, right);
    merge(a, left, mid, right);
  }
}



Measured memory_bytes: 5604
while True:
    H,W = map(int, input().split())
    if H == 0 and W == 0:
        break
    a = "#" * W
    b = "#" + "." * (W - 2) + "#"
    print(a)
    for i in range(H - 2):
      print(b)    
    print(a)
    print()

Measured memory_bytes: 7652
/**
 * @file ALDS1_7_C_TreeWalk.cpp
 * @brief 木の巡回プログラム
 */

#include	<iostream>
#include	<cstdio>

using namespace std;

#define		NIL			(-1)
#define		MAX			25

struct BinaryTree
{
	int		parent;
	int		left;
	int		right;

	BinaryTree()
	{
		parent = left = right = NIL;
	}
};

BinaryTree		tree[MAX];

enum class WalkType
{
	ePreorder,
	eInorder,
	ePostorder
};

/**
* @brief 表示結果関数
* @param[in] id 表示する枝のID
* @param[in] wt 表示タイプ
* @return void 戻り値なし
*/
void	Walk(int id, const WalkType wt)
{
	if (WalkType::ePreorder == wt)
		cout << " " << id;

	if (NIL != tree[id].left)
		Walk(tree[id].left, wt);

	if (WalkType::eInorder == wt)
		cout << " " << id;

	if (NIL != tree[id].right)
		Walk(tree[id].right, wt);

	if (WalkType::ePostorder == wt)
		cout << " " << id;
}

/**
 * @brief メイン関数
 * @return void 戻り値なし
 */
int main()
{
	int		n;
	cin >> n;

	int		id, left, right;
	
	for (int i = 0; i < n; ++i)
	{
		cin >> id >> left >> right;
		tree[id].left = left;
		tree[id].right = right;

		if (NIL != left)	tree[left].parent = id;
		if (NIL != right)	tree[right].parent = id;
	}

	int		root;
	for (int i = 0; i < n; ++i)
	{
		if (NIL == tree[i].parent)
		{
			root = i;
			break;
		}
	}

	cout << "Preorder\n";
	Walk(root, WalkType::ePreorder);

	cout << "\nInorder\n";
	Walk(root, WalkType::eInorder);

	cout << "\nPostorder\n";
	Walk(root, WalkType::ePostorder);

	cout << "\n";

	return 0;
}



Measured memory_bytes: 3092
#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;

int N;
vector<P> G[20];
int used[20];

int dfs(int n) {
	used[n] = 1;
	int res = 0;
	for (auto p : G[n]) {
		if (G[p.first].size() > 1 && used[p.first] == 0) {
			res = max(res, dfs(p.first) + p.second);
		}
	}
	used[n] = 0;
	return res;
}

int main()
{
	int N;
	while (cin >> N, N) {
		for (int i = 0; i < 20; i++) {
			G[i].clear();
		}
		vector<int> a(N - 1), b(N - 1), t(N - 1);
		for (int i = 0; i < N - 1; i++) {
			cin >> a[i] >> b[i] >> t[i];
			G[a[i] - 1].push_back(P(b[i] - 1, t[i]));
			G[b[i] - 1].push_back(P(a[i] - 1, t[i]));
		}
		long long res = 0;
		for (int i = 0; i < N - 1; i++) {
			if (((G[a[i] - 1].size() > 1 || a[i] == 1) && (G[b[i] - 1].size() > 1 || b[i] == 1))) {
				res += t[i] * 2;
			}
		}
		res -= dfs(0);
		cout << res << endl;
	}
	return 0;
}

Measured memory_bytes: 3068
using System;
class main
{
    static void Main(String[] args)
    {
        int n = int.Parse(Console.ReadLine());
        int b = 100000;
        for (int i = 0; i < n; i++)
        {
            b = (int)((double)b * 1.05);
            b += 999;
            b = (b / 1000)*1000;
        }
        Console.WriteLine(b);
    }
}

Measured memory_bytes: 5608
/*
  Motto - try hard to become an expert
*/
#include <bits/stdc++.h>
#include <map>
#include <algorithm>
#include <vector>
#include <string.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <chrono>
#include <thread>
#include <iomanip>
 
//define
#define rep(i,n)    for(int i=0;i<n;i++)
#define repu(i,k,n) for(int i=k;i<=n;i++)
#define repd(i,k,n) for(int i=k;i>=n;i--)
#define se second
#define fi first
#define pb push_back
#define mp make_pair
#define INF (int)INT_MAX
#define all(v)  v.begin(), v.end()
#define endl "\n"
 
//typedef
typedef long long int ll;
typedef long double ld;
typedef std::pair<int, int> pii;
typedef std::vector<int> vi;
typedef std::vector< pii > vii;
typedef std::vector< ll > vll;
typedef std::vector< std::pair < pii, int > > vpp;
 
const int N = 3*1e5 +5 ;
const long long MOD = 998244353;
const long long inf = 1e18;
 
using namespace std;
 
ll MAXN=100001;
ll spf[100001]; 
 
ll modpow(ll x,ll n){
    ll res=1;
    while(n>0){
        if(n&1) res=res*x%MOD;
        x=x*x%MOD;
        n>>=1;
    }
    return res;
}
 
ll modFact(ll n, ll p) 
{ 
    if (n >= p) 
        return 0; 
  
    ll result = 1; 
    for (ll i = 1; i <= n; i++) 
        result = (result * i) % p; 
  
    return result;  
} 
 
bool isPrime(int x)
{
    if(x%2==0)
        return 0;
    for(int i=3;i<=sqrt(x);i+=2)
    {
        if(x%i==0)
            return 0;
    }
    return 1;
}
 

 
void solve()
{
	ll  n  ,   k; 
	cin>>n>>k ;
	vector<double>a(n) ; 
	rep(i , n) cin>>a[i] ; 
	double tans = 0.0 , ans = 0.0;
	repu(i , 0 , n-1){
		if(i<k-1){
			tans += ((a[i]*(a[i]+1))/2.0) / a[i] ;
		}
		else{
			tans  += ((a[i]*(a[i]+1))/2.0) / a[i]  ;
			ans = max(tans , ans) ;
			tans -= ((a[i-(k-1)]*(a[i-(k-1)]+1))/2.0) / a[i-(k-1)] ;
		}
	}
	cout<<setprecision(10)<<ans;
}
 
int main() {
    // #ifndef ONLINE_JUDGE
    //     // for getting input from input.txt
    //     freopen("input.txt", "r", stdin);
    //     // for writing output to output.txt
    //     freopen("output.txt", "w", stdout);
    // #endif
    
    // ios_base::sync_with_stdio(0);
    // cin.tie(NULL);
    int t = 1;
    // cin>>t;
    while(t--)
    {
        solve();
    } 
    // cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}

Measured memory_bytes: 1792
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef pair<ll,ll> P;
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
const ll mod=1000000007;
//ios_base::sync_with_stdio(false);
//cin.tie(NULL);
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
vector<vector<int>>graph;
int dfs(int now,int cnt){
  bool ok=(graph[now].size()>1);
  if(graph[now].size()==0)return cnt;
  vector<int> tmp;
  for(int v:graph[now]){
     int t=dfs(v,cnt+1);
      tmp.push_back(t);
  }
  int res=0;
  sort(all(tmp),greater<int>());
  int cn=0;
  for(int u:tmp){
      chmax(res,u+cn);
      cn++;
  }
   return res;
}
int main(){
    int n;
    cin>>n;
  //  ans=0;
    graph.resize(n);
    for(int i=1;i<n;i++){
        int a;
        cin>>a;
        graph[a-1].push_back(i);
    }
    cout<<dfs(0,0)<<endl;
}



Measured memory_bytes: 16640
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
typedef pair<ll, int> Pl;
const double PI = 3.1415926535897932;   // acos(-1)
const double EPS = 1e-15;
const int INF = 1001001001;
const ll mod = 1e+9 + 7;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define chadd(x, y) x = (x + y) % mod

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

    int n, k;
    cin >> n >> k;
    vector<int> h(n);
    for(int i = 0; i < n; ++i)  cin >> h[i];
    sort(h.begin(), h.end());
    int res = INF;
    for(int i = 0; i + k <= n; ++i) chmin(res, h[i+k-1] - h[i]);
    cout << res << endl;
}


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

typedef long long ll;
typedef vector<int> vi;
typedef vector<string> vs;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n)    FOR(i, 0, n)
#define pb           push_back
#define all(a)       (a).begin(), (a).end()
#define UNIQUE(v)    v.erase(unique(all(v)), v.end());
#define fill(a, x)   memset(a, x, sizeof(a))
#define zero(a)      fill(a, 0)
#define minus(a)     fill(a, -1)
#define dbg(x)       cout << #x "=" << x << endl

vi vc_a;
// int vc_a[1000000];
int n;

// naming rules
// array starts with "ar". for example vc_a
// stack starts with "st". for example st_a
// queue starts with "qu". for example qu_a
// vector starts with "vc". for example vc_a

bool binarySearch(int key, int left, int right) {
  int id = (left + right) / 2;
  if (left > right) return false;
  int mid = vc_a[id];
  if (mid == key) return true;
  if (id == left) return false;
  if (mid > key) return binarySearch(key, left, id);
  return binarySearch(key, id + 1, right);
}

int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  int c = 0;

  // receiving input
  int t;
  while (c < n && (cin >> t)) {
    vc_a.pb(t);
    c++;
  }

  int q;
  cin >> q;

  int count = 0;
  rep(j, q) {
    int tmp;
    cin >> tmp;
    if (binarySearch(tmp, 0, n)) count++;
  }

  cout << count << endl;

  return 0;
}



Measured memory_bytes: 3388
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String[] str = in.readLine().split(" ");
    int n = Integer.parseInt(str[0]);
    int m = Integer.parseInt(str[1]);
    int[] a = new int[m];
    int[] b = new int[m];
    for(int i=0; i<m; i++) {
      str = in.readLine().split(" ");
      a[i] = Integer.parseInt(str[0]);
      b[i] = Integer.parseInt(str[1]);
    }
    
    int[] count = new int[n];
    for(int i=0; i<m; i++) {
      for(int j=1; j<=n; j++) {
        if(a[i] == j)
          count[j-1]+=1;
        if(b[i] == j)
          count[j-1]+=1;
      }
    }
    
    for(int i=0; i<n; i++) {
      System.out.println(count[i]);
    }
  }
}

Measured memory_bytes: 32688
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

const int inf = 999999999;
const double pi = acos(-1);

#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}

///////////////////////////////////////////////////////////////////////////

int main(){
	ll n,a,b;
	cin >> n >> a >> b;

	if((n == 1 && a != b) || a > b){
        cout << 0 << endl; 
        return 0;
	}

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

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define re register
#define ll long long
inline int gi()
{
	int f=1,sum=0;char ch=getchar();
	while(ch>'9' || ch<'0'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0' && ch<='9'){sum=(sum<<3)+(sum<<1)+ch-'0';ch=getchar();}
	return f*sum;
}
const int N=500010;
int n,K,a[N],sequ[N],bl[N];
char s[N];
int main()
{
	n=gi();K=gi();
	scanf("%s",s+1);
	for(int i=1;i<=n;i++)a[i]=s[i]-'0';
	int jian=0,pos=1;
	for(int i=2;i<=n;i++)
		if(a[i]!=a[i-1])
		{
			sequ[++jian]=pos;bl[jian]=a[i-1];pos=1;
		}
		else pos++;
	sequ[++jian]=pos;bl[jian]=a[n];n=jian;
	int h=1,tot=0;int intot=0,ans=0;
	for(int i=1;i<=n;i++)
	{
		ans+=sequ[i];if(!bl[i])tot++;
		while(tot>K){if(bl[h]==0)tot--;ans-=sequ[h++];}
		intot=max(intot,ans);
	}
	printf("%d\n",intot);
	return 0;
}


Measured memory_bytes: 4864
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define f first
#define s second
#define pb push_back
#define fix  cout<<std::fixed;
#define mk make_pair
#define N 100005
#define mod 1000000007
#define time  cerr<< '\n' << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms\n" ;
#define IOS        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
vector <ll> v[N];
ll t[N];
int main()
{
  ll n,m;cin>>n>>m;
  ll a[n];
  for(int i=0;i<n;i++)cin>>a[i];  
  for(int i=0;i<m;i++)
  {
    ll x,y;cin>>x>>y;
    v[x].pb(y);
    v[y].pb(x);
    if(a[x-1]>a[y-1])t[x]++;
    else if(a[y-1]>a[x-1])t[y]++;
  } 

  ll cnt=0;
  for(int i=1;i<=n;i++)
  {
    if(t[i]==v[i].size())cnt++;
  }
 // cout<<t[6];
  cout<<cnt;
}

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

template <int MOD_> struct modnum {
	static constexpr int MOD = MOD_;
	static_assert(MOD_ > 0, "MOD must be positive");

private:
	using ll = long long;

	int v;

	static int minv(int a, int m) {
		a %= m;
		assert(a);
		return a == 1 ? 1 : int(m - ll(minv(m, a)) * ll(m) / a);
	}

public:

	modnum() : v(0) {}
	modnum(ll v_) : v(int(v_ % MOD)) { if (v < 0) v += MOD; }
	explicit operator int() const { return v; }
	friend std::ostream& operator << (std::ostream& out, const modnum& n) { return out << int(n); }
	friend std::istream& operator >> (std::istream& in, modnum& n) { ll v_; in >> v_; n = modnum(v_); return in; }

	friend bool operator == (const modnum& a, const modnum& b) { return a.v == b.v; }
	friend bool operator != (const modnum& a, const modnum& b) { return a.v != b.v; }

	modnum inv() const {
		modnum res;
		res.v = minv(v, MOD);
		return res;
	}
	modnum neg() const {
		modnum res;
		res.v = v ? MOD-v : 0;
		return res;
	}

	modnum operator- () const {
		return neg();
	}
	modnum operator+ () const {
		return modnum(*this);
	}

	modnum& operator ++ () {
		v ++;
		if (v == MOD) v = 0;
		return *this;
	}
	modnum& operator -- () {
		if (v == 0) v = MOD;
		v --;
		return *this;
	}
	modnum& operator += (const modnum& o) {
		v += o.v;
		if (v >= MOD) v -= MOD;
		return *this;
	}
	modnum& operator -= (const modnum& o) {
		v -= o.v;
		if (v < 0) v += MOD;
		return *this;
	}
	modnum& operator *= (const modnum& o) {
		v = int(ll(v) * ll(o.v) % MOD);
		return *this;
	}
	modnum& operator /= (const modnum& o) {
		return *this *= o.inv();
	}

	friend modnum operator ++ (modnum& a, int) { modnum r = a; ++a; return r; }
	friend modnum operator -- (modnum& a, int) { modnum r = a; --a; return r; }
	friend modnum operator + (const modnum& a, const modnum& b) { return modnum(a) += b; }
	friend modnum operator - (const modnum& a, const modnum& b) { return modnum(a) -= b; }
	friend modnum operator * (const modnum& a, const modnum& b) { return modnum(a) *= b; }
	friend modnum operator / (const modnum& a, const modnum& b) { return modnum(a) /= b; }
};

template <typename T> T pow(T a, long long b) {
	assert(b >= 0);
	T r = 1; while (b) { if (b & 1) r *= a; b >>= 1; a *= a; } return r;
}
using num = modnum<998244353>;

const int MAXN = 1.1e5;
int N;
int D[MAXN];

num go() {
	map<int, int> cnt;
	for (int i = 0; i < N; i++) {
		cnt[D[i]]++;
	}
	if (D[0] != 0) return 0;
	if (cnt[0] != 1) return 0;
	num ans = 1;
	for (int i = 1; i <= N; i++) {
		ans *= pow(num(cnt[i-1]), cnt[i]);
	}
	return ans;
}

int main() {
	ios::sync_with_stdio(0), cin.tie(0);
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> D[i];
	}
	cout << go() << '\n';

	return 0;
}


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

int main(){
     int T;
     cin>>T;
     for(int k=0;k<T;k++){
	  int N,min_h=0,max_h=0;
	  cin>>N;
	  int prv;
	  cin>>prv;
	  
	  for(int i=0;i<N-1;i++){
	       int temp;
	       cin>>temp;
	       min_h=max(prv-temp,min_h);
	       max_h=max(temp-prv,max_h);
	       prv=temp;
	  }
	  cout<<max_h<<" "<<min_h<<endl;
     }
     return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define fi first
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define fit(x) for(auto it=x.begin();it!=x.end();++it)
#define se second
#define mp make_pair
#define ALP "abcdefghijklmnopqrstuvwxyz"
#define nline cout<<"\n"
#define rep(i,x) for(i=0;i<x;++i)
#define repr(i,a,b) for(i=a;i<=b;++i)
#define mi2 500000004
#define mi3 333333336
#define MOD 1000000007
#define N 1000005
#define pll pair<ll,ll>
#define Vll vector<ll>
#define W(t) while(t--)
#define modsum(a,b,M) (a%M + b%M)%M
#define modsub(a,b,M) (a%M - b%M + M)%M
#define modmul(a,b,M) (a%M * b%M)%M
#define moddiv(a,b,M) (a%M * modinv(b,M)%M)%M
using namespace std;
ll powermod(ll x,ll n,ll M)
{
	ll result=1;
	while(n>0)
	{
	  if(n % 2 ==1)
	    result=(result * x)%M;
	  x=(x*x)%M;
	  n=n/2;
	}
	return result;
}
vector<ll> readll() {
	cin>>ws;
	vector<ll> v;
	string input;
	getline(cin, input);
	cout<<input;
	istringstream is(input);
	ll num;
	while(is>>num) v.pb(num);
	return v;
}
ll modinv(ll n,ll p) {
	return powermod(n,p-2,p);
}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll fact[1000005],invf[1000005];
void facmod(ll n,ll M) {
	ll i;
	fact[0]=fact[1]=1;
	for(i=2;i<=n;++i) {
		fact[i]=((fact[i-1])%M * (i%M))%M;
	}
	invf[n]=modinv(fact[n],M);
	for (i=n-1;i>=0;--i){
		invf[i]=invf[i+1]*(i+1);
		invf[i]%=M;
	}
}
/*****
ll T=0;
ll p[200005], d[200005];
ll tin[200005], tout[200005];
vector<ll> g[200005];

void dfs(ll v, ll par = 1, ll dep = 0) {
	p[v] = par;
	d[v] = dep;
	tin[v] = T++;
	for (auto to : g[v]) {
		if (to == par) continue;
		dfs(to, v, dep + 1);
	}
	tout[v] = T++;
}
****/
void solve() {
	ll a,b,c;
	cin>>a>>b>>c;
	cout<<c<<" "<<a<<" "<<b;
}
int main() {
  	fastio;
	ll t=1;
	//cin>>t;
	W(t) {
		solve();
	}
	
  	return 0;
}

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

int main() {
	long n,m,i,j,ans=0;
	cin >> n;
	vector<long> a(n);
	for(i=0; i<n; i++){
		cin >> j;
		a[i]=j*100002+(i+1);
	}
	sort(a.begin(),a.end());
	for(i=0; i<n; i++){
		cout << a[i]%100002 << ' ';
	}
}

Measured memory_bytes: 1536
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<set>
using namespace std;
typedef long long ll;
const int N=20005;
set<ll> st;
int n,i,j,k,p[N],l,w1[N],w2[N];
bool v[N];
ll a[505][505];
ll gcd(ll a,ll b)
{
	if(!b)
		return a;
	return gcd(b,a%b);
}
ll LCM(ll a,ll b,ll c,ll d)
{
	ll rtn=a/gcd(a,b)*b;
	rtn=rtn/gcd(rtn,c)*c;
	rtn=rtn/gcd(rtn,d)*d;
	return rtn;
}
int main()
{
	scanf("%d",&n);
	for(i=2;i<=20000;++i)
	{
		if(!v[i])
			p[++l]=i;
		for(j=1;j<=l&&p[j]*i<=20000;++j)
		{
			v[p[j]*i]=true;
			if(i%p[j]==0)
				break;
		}
	}
	for(i=1;i<=n;++i)
		w1[i]=p[i];
	for(i=1;i<=n;++i)
		w2[i]=p[n+i];
	random_shuffle(w1+1,w1+1+n);
	random_shuffle(w2+1,w2+1+n);
	for(i=1;i<=n;++i)
		for(j=1;j<=n;++j)
			if((i+j)%2==0)
				a[i][j]=w1[(i+j)/2]*w2[(i-j+n+1)/2];
	for(i=0;i<=n+1;++i)
		a[0][i]=a[n+1][i]=a[i][0]=a[i][n+1]=1;
	for(i=1;i<=n;++i)
		for(j=1;j<=n;++j)
			if((i+j)&1)
			{
				a[i][j]=LCM(a[i-1][j],a[i+1][j],a[i][j-1],a[i][j+1])+1;
				while(st.count(a[i][j]))
					a[i][j]+=LCM(a[i-1][j],a[i+1][j],a[i][j-1],a[i][j+1]);
				st.insert(a[i][j]);
			}
	for(i=1;i<=n;++i)
	{
		for(j=1;j<=n;++j)
			printf("%lld ",a[i][j]);
		puts("");
	}
	return 0;
}


Measured memory_bytes: 11008
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0; i < (n); ++i)
#define repA(i, a, n) for(ll i = a; i <= (n); ++i)
#define repD(i, a, n) for(ll i = a; i >= (n); --i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (long long) (x).size()
#define fill(a) memset(a, 0, sizeof(a))
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define endl '\n'
#define MAXN 5000000
const long double PI = 3.141592653589793238462643383;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long int> vll;
typedef vector<double> vd;
typedef vector<pii> vii;
const long long mod = 998244353;
int Ceil(int a, int b){
    if(a%b==0) return a/b;
    else return (a/b)+1;
}

ll power(ll a,ll b){
    ll ans = 1;
    while(b){
        if(b&1)
            ans*= a;
        ans%=mod;
        a*= a;
        a%=mod;
        b/=2;
    }
    return ans;
}
int main(){
 
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);   
    freopen("output.txt", "w", stdout);
    #endif
    cin.sync_with_stdio(0); cin.tie(0);
    cin.exceptions(cin.failbit);
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    int i = 0;
    while(1){
        if(i&1){
            a-=d;
            if(a<=0)
                break;
        }
        else{
            c-= b;
            if(c<=0)
                break;
        }
        i = 1-i;
    }
    if(i)
        cout<<"No";
    else
        cout<<"Yes";
    return 0;
}

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

using namespace std;

int main() {

    int x;
    cin >> x;

    if(400 <= x and x <= 599) return cout << "8\n", 0;
    if(600 <= x and x <= 799) return cout << "7\n", 0;
    if(800 <= x and x <= 999) return cout << "6\n", 0;
    if(1000 <= x and x <= 1199) return cout << "5\n", 0;
    if(1200 <= x and x <= 1399) return cout << "4\n", 0;
    if(1400 <= x and x <= 1599) return cout << "3\n", 0;
    if(1600 <= x and x <= 1799) return cout << "2\n", 0;
    if(1800 <= x and x <= 1999) return cout << "1\n", 0;
    return 0;
}


Measured memory_bytes: 3572
let (r, g, b, n) = Scanf.sscanf (read_line ()) "%d %d %d %d" @@ fun r g b n -> (r, g, b, n)

let () =
  let ans = ref 0 in
  for i = 0 to n / r do
    for j = 0 to n / g do
      let sum = r * i + j * g in
      if sum <= n && (n - sum) mod b = 0 then ans := !ans + 1
    done
  done;
  Printf.printf "%d\n" !ans

Measured memory_bytes: 4480
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < n; ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end()) 
#define FORV(i, v) for (auto i = v.begin(); i != v.end(); i++)
using namespace std;

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; }
const int INF = 1001001001;
const long long INFL = (1LL<<60);
const double eps = (1e-9);


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

  int h, w, n;
  cin >> h >> w >> n;

  int ans = n / max(h, w);
  if (n % max(h, w) != 0) ans++;
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define pb push_back
#define all(x) x.begin(), x.end()
#define mem(arr,x) memset(arr, x, sizeof arr)
#define db(arr) for(auto x : arr) cout << x << " "; cout << "\n";
using namespace std;

// #include <ext/pb_ds/tree_policy.hpp>
// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;
// typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

ll power(ll n,ll m){
	if(m==0) return 1;
	ll val=power(n,m/2);
	if(m%2==0) return (val*val); else return ((val*val)*n);
}

ll powermod(ll n,ll m,ll MOD){
	if(m==0) return 1;
	ll val=powermod(n,m/2,MOD);
	val %= MOD;
	if(m%2==0) return (val*val) % MOD; else return (((val*val) % MOD) * n) % MOD;
}

void solve(){
	string s;
	cin >> s;
	ll n = 0;
	for(char c : s){
		n += (c - '0');
	}
	if(n % 9 == 0){
		cout << "Yes\n";
	}
	else{
		cout  << "No\n";
	}
	return ;
}

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

	#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);	
	#endif

	int t = 1;
	// cin >> t;

	for(int i = 1; i <= t; i++){
		// cout << "Case #" << i << ": ";
		solve();
	}

	return 0;
}

Measured memory_bytes: 3776
#include<bits/stdc++.h>
using namespace std;
#define ll long long
char a[5000010];
int main()
{
    int cnt=0;
    scanf("%s",a);
    for(int i=0;i<strlen(a);i++)
        if(a[i]=='2')cnt++;
        printf("%d\n",cnt);
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<vector>
#define p 1000000007
using namespace std;
int n,m,dp[330][330][330];
long long ans;
struct evol{int l,xi;};
vector<evol> v[303];
bool check(int x,int y,int z,int d)
{
	if(x&&x==y||y&&y==z||x&&x==z) return 0;
	if(x>y) swap(x,y);
	if(z<y) swap(z,y);
	if(y<x) swap(x,y);
	bool fl=1;
	for(int i=0;i<v[d].size();i++)
	{
		if(v[d][i].xi==1) fl&=(x<v[d][i].l)&&(y<v[d][i].l)&&(z>=v[d][i].l);
		if(v[d][i].xi==2) fl&=(x<v[d][i].l)&&(y>=v[d][i].l);
		if(v[d][i].xi==3) fl&=(x>=v[d][i].l);
	}
	return fl;
}
void add(int x,int y,int z,int k)
{
	(dp[k][y][z]+=dp[x][y][z])%=p;
	(dp[x][k][z]+=dp[x][y][z])%=p;
	(dp[x][y][k]+=dp[x][y][z])%=p;
}
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++)
	{
		int x,y,z;
		scanf("%d%d%d",&x,&y,&z);
		v[y].push_back((evol){x,z});
	}
	dp[1][0][0]=dp[0][1][0]=dp[0][0][1]=1;
	for(int k=1;k<n;k++)
		for(int i=0;i<=k;i++)
			for(int j=0;j<=k;j++)
			{
				if(check(i,j,k,k)) add(i,j,k,k+1);
				if(check(i,k,j,k)) add(i,k,j,k+1);
				if(check(k,i,j,k)) add(k,i,j,k+1);
			}
	for(int i=0;i<=n;i++)
		for(int j=0;j<=n;j++)
		{
			if(check(i,j,n,n)) (ans+=dp[i][j][n])%=p;
			if(check(i,n,j,n)) (ans+=dp[i][n][j])%=p;
			if(check(n,i,j,n)) (ans+=dp[n][i][j])%=p;
		}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 129152
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

int x[100100];
int d[100100];

int main() {
	int t,n,k;
	cin>>t;
	while(t--){
		cin>>n>>k;
		int i;
		for(i=0;i<n;i++){
			cin>>x[i];
		}
		int res=x[n-1]-x[0];
		for(i=0;i<n-1;i++){
			d[i]=x[i]-x[i+1];
		}
		sort(d,d+n-1);
		for(i=0;i<n-1&&i<k-1;i++){
			res+=d[i];
		}
		cout<<res<<endl;
	}
	return 0;
}

Measured memory_bytes: 1648
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int (i)=(0);(i)<(int)(n);++(i))
#define p(x) cout<<(x)<<endl

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

  int i;
  for(i = 40000; i > 0; i--) {
    if (i*i <= x) {
      p(i*i);
      return 0;
    }
  }
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <utility>
#include <climits>
#include <iomanip>
using namespace std;
#define MAXSIZE 100005
#define MAXL 100
#define MOD_CONST 1000000007
typedef long long int lli;

int main(){
    string s;
    cin >> s;
    
    const int alphabet_num = 26;
    vector<int> num_appear(alphabet_num, 0);
    for(int i = 0; s[i] != '\0'; ++i){
        num_appear[s[i] - 'A']++;
    }

    int cnt2 = 0;
    for(int i = 0; i < alphabet_num; ++i){
        if(num_appear[i] == 2){
            cnt2++;
        }
    }
    
    string ans = (cnt2 == 2)? "Yes" : "No";
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 888
#include <iostream>
#include <string.h>
using namespace std;
int main(void){
    int a,b;
    string op;
    cin >> a;
    cin >> op;
    cin >> b;
    
    if(op=="+"){
        cout<<a+b<<endl;
    }else{
        cout<<a-b<<endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n,s) for(int i=(s);i<(n);i++)
#define rrep(i,n) for(int i=(n-1);i>=0;i--)
#define rreps(i,n,s) for(int i=s;i>=n;i--)
#define MOD 1000000007
using ll = long long;
using namespace std;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int a,b,c,d;
cin>>a>>b>>c>>d;
int val=(a+b)-(c+d);
if(val>0)cout<<"Left"<<endl;
else if(val==0)cout<<"Balanced"<<endl;
else cout<<"Right"<<endl;
//system("pause");
return 0;
}

Measured memory_bytes: 256
import java.util.*

fun main(args: Array<String>) {
    val scan = Scanner(System.`in`)
    var kotlin=scan.nextLine().toInt()
    var (a,b) = scan.nextLine().split(" ").map{ it.trim().toInt() }.toTypedArray()

    var ans = false

    for(x in a..b)
    {
        if(x%kotlin==0)
        {
            ans=true
            break
        }
    }

    if(ans==true)
        println("OK")
    else
        println("NG")

}


Measured memory_bytes: 38428
#include <stdio.h>
#include <string.h>
#define N 1000
char s1[N+1],s2[N+1];
int c[N+1][N+1];

int lcs(void);
int max(int,int);
int main()
{
  int i,n;
  scanf("%d",&n);
  for(i=0;i<n;i++)
    {
      scanf("%s%s",s1,s2);
      printf("%d\n",lcs());
    }
  return 0;
}

int lcs()
{
  int i,j,m,n;
  m=strlen(s1);
  n=strlen(s2);
  for(i=1;i<=m;i++)
    {
      c[i][0]=0;
    }
  for(i=1;i<=n;i++)
    {
      c[0][i]=0;
    }
  for(i=1;i<=m;i++)
    {
      for(j=1;j<=n;j++)
        {
          if(s1[i-1]==s2[j-1])     c[i][j]=c[i-1][j-1]+1;
          else if(c[i-1][j]>=c[i][j-1]) c[i][j]=c[i-1][j];
          else  c[i][j]=c[i][j-1];

        }
    }
  return c[m][n];
}

Measured memory_bytes: 4516
import java.util.Scanner;
public class Main {
@SuppressWarnings("resource")
public static void main(String[] args) {
	Scanner sc =new Scanner(System.in);
	long N=sc.nextLong();
	long dis=1000;
	while(N>0) {
	if(Math.abs(N%1000-753)<dis) {
		dis=Math.abs(N%1000-753);
	}
	N/=10;
	}
	System.out.println(dis);
}
}


Measured memory_bytes: 22864
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  char f[10];
  int m=0, s=0;
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
template<class S, class T> inline S chmax(S &a, T b){
  if(a<b){
    a=b;
  }
  return a;
}
int N;
int H[100000];
int main(){
  int i, res=0, tmp;
  rd(N);
  {
    int Lj4PdHRW;
    for(Lj4PdHRW=0;Lj4PdHRW<(N);Lj4PdHRW++){
      rd(H[Lj4PdHRW]);
    }
  }
  for(i=N-1;i>=0;i--){
    if(i == N-1 || H[i] < H[i+1]){
      tmp = 0;
    }
    chmax(res, tmp);
    tmp++;
  }
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay varsion 20190902-1

// --- original code ---
// int N, H[1d5];
// {
//   int i, tmp, res = 0;
//   rd(N,H(N));
//   for(i=N-1;i>=0;i--){
//     if(i == N-1 || H[i] < H[i+1]) tmp = 0;
//     res >?= tmp;
//     tmp++;
//   }
//   wt(res);
// }


Measured memory_bytes: 640
package main

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

func main() {
	readLineInt()
	current, result := 1, 0
	for _, v := range readLineInt() {
		if v != current {
			result++
		} else {
			current++
		}
	}
	if current == 1 {
		fmt.Println("-1")
	} else {
		fmt.Println(result)
	}
}

/////////////////////////////////////////
func readLineInt() []int {
	result := make([]int, 0)
	for _, v := range strings.Split(readLine(), " ") {
		i, _ := strconv.Atoi(v)
		result = append(result, i)
	}
	return result
}

var reader = bufio.NewReaderSize(os.Stdin, 1e6)

func readLine() string {
	result := make([]byte, 0, 1e6)
	for {
		line, remains, e := reader.ReadLine()
		if e != nil {
			panic(e)
		}
		result = append(result, line...)
		if !remains {
			break
		}
	}
	return string(result)
}

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

int main() {
  string s,t;cin>>s>>t;
  rep(i,s.size()){
    s=s[s.size()-1]+s.substr(0,s.size()-1);
  if(s==t){
    cout<<"Yes"<<endl;
    return 0;
  }
  }
  cout<<"No"<<endl;
}
  

Measured memory_bytes: 3612
#include<iostream>
#include<queue>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
using namespace std;
/****************************/
#define ll long long
#define vi vector<int>
#define pii pair<int,int>
#define vpii vector<pair<int,int> >
#define qi queue<int>
#define mii map<int,int>
#define msi map<string,int>
#define vs vector<string>
#define vc vector<char>
/****************************/
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep2(i,n) for(ll i=(n)-1;i>=0;i--)
#define rep3(i,a,n) for(ll i=(a);i<(n);i++)
#define rep4(i,a,n) for(ll i=(a)-1;i>=n;i--)
#define mp make_pair
#define pb push_back
#define st first
#define nd second
#define pi 3.1415926535897932384626433832795
#define zero(n) memset(n,0,sizeof(n));
#define SZ(n) n.size()
#define sn st.nd 
#define mod 1000000007
int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};
int month[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
/****************************/
ll n,m,k;
ll a[3010][3010];
ll dp[3010][3010][3];
int main()
{
	cin>>n>>m>>k;
	zero(a);
	rep(i,k)
	{
		int x,y,v;
		cin>>x>>y>>v;
		a[x-1][y-1]=v;
	}
	rep(i,n)
	{
		rep(j,m)
		{
			dp[i][j][0]=a[i][j];
			if(i)
			{
				dp[i][j][0]+=max(dp[i-1][j][0],max(dp[i-1][j][1],dp[i-1][j][2]));
			}
			if(j)
			{
				dp[i][j][0]=max(dp[i][j][0],dp[i][j-1][0]);
				dp[i][j][1]=max(dp[i][j-1][1],dp[i][j-1][0]+a[i][j]);
				dp[i][j][2]=max(dp[i][j-1][2],dp[i][j-1][1]+a[i][j]);
			}
		}
	}
	cout<<max(dp[n-1][m-1][0],max(dp[n-1][m-1][1],dp[n-1][m-1][2]));
	return 0;
}

Measured memory_bytes: 286060
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;class Program
{
	static void Main(string[] args)
	{
        //var exStdIn = new System.IO.StreamReader( "stdin.txt" );System.Console.SetIn( exStdIn );
		long ans = -1;
		long k = long.Parse(Console.ReadLine());
		long tmp = 0;
		for (int i = 0; i < k+10; i++)
		{
			tmp = (tmp*10+7)%k;
			if(tmp==0){
				ans = i+1;
				break;
			}
		}
		Console.WriteLine(ans);
	}
	
}


Measured memory_bytes: 27516
// AOJ Volume 0 Problem 0086

#include <stdio.h>
#include <string.h>

int main(void)
{
	int path[101];
	int p1, p2;
	int i, j;
	int flag;
	
	while (1){
		memset(path, 0, sizeof(path));
		while (1){
			if (scanf("%d%d", &p1, &p2) == EOF){
				goto end;
			}
			if (p1 == 0 && p2 == 0){
				break;
			}
			path[p1]++;
			path[p2]++;
		}
		
		flag = 0;
		if (path[1] % 2 == 0 || path[2] % 2 == 0){
			flag = 1;
		}
		for (i = 3; i <= 100; i++){
			if (path[i] != 0 && path[i] % 2 == 1){
				flag = 1;
				break;
			}
		}
		
		if (flag == 0){
			printf("OK\n");
		}
		else {
			printf("NG\n");
		}
	}
	
end:

	return (0);
}

Measured memory_bytes: 0
N = int(input())
A = list(map(int,input().split()))
A.sort()
S = A[N - 1]
B = [0]*(2*(N-1))
for i in range(N-1):
  B[2*i] = A[N-2-i]
  B[2*i+1] = A[N-2-i]
for k in range(N-2):
  S += B[k]
print(S)

Measured memory_bytes: 31676
#include <cstdio>
#include <iostream>
#include <cassert>
#include <string>
#include <algorithm>
#include <cstring>
#include <utility>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <deque>
#include <unordered_map>
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
const LL MOD = (LL)1e9 + 7;
const int MAXN = 123456;
LL fac[MAXN], invfac[MAXN];

LL add(LL a, LL b) {
    LL ans = a + b;
    if (ans >= MOD) ans -= MOD;
    return ans;
}

LL mul(LL a, LL b) {
    return (a * b) % MOD;
}

LL sub(LL a, LL b) {
    return (a - b + MOD) % MOD;
}

void init() {
    invfac[1] = invfac[0] = fac[0] = 1;
    for (int i = 1; i < MAXN; i++)
        fac[i] = mul(fac[i - 1], i);
    for (int i = 2; i < MAXN; i++)
        invfac[i] = (MOD - (MOD / i) * invfac[MOD % i] % MOD) % MOD;
    for (int i = 2; i < MAXN; i++)
        invfac[i] = mul(invfac[i - 1], invfac[i]);
}

LL C(LL n, LL m) {
    if (m > n) return 0;
    LL ans = fac[n];
    ans = mul(ans, invfac[m]);
    ans = mul(ans, invfac[n - m]);
    return ans;
}

int main() {
    int N, K;
    init();
    scanf("%d %d", &N, &K);
    vector<int> V;
    for (int i = 0; i < N; i++) {
        int tmp;
        scanf("%d", &tmp);
        V.push_back(tmp);
    }
    sort(V.begin(), V.end());
    LL ans = 0;
    for (int i = 0; i < N; i++) {
        int cur = V[i];
        if (N - i >= K) {
            LL tmp = mul(cur, C(N - i - 1, K - 1));
            ans = sub(ans, tmp);
        }
        if (i + 1 >= K) {
            LL tmp = mul(cur, C(i, K - 1));
            ans = add(ans, tmp);
        }
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 2812
#include <bits/stdc++.h> 
using namespace std;
#define rep(i, N) for(int i=0; i<N; i++)
typedef long long ll;
#define dump(x) cerr<<#x<<"="<<x<<endl

int main() {
    int n; cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a.at(i);

    int cnt4 = 0;
    rep(i, n){
        if(a.at(i)%4==0){
            cnt4++;
            a.at(i) = 1; 
        }
    }

    int cnt2 = 0;
    rep(i, n){
        if(a.at(i)%2==0) cnt2++;
    }

    if(n-(cnt4*2+1)<=0 || (n-cnt4*2)==cnt2){
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    
}

Measured memory_bytes: 1024
#include <vector>
#include <algorithm>
#include <cstdio>
#define LIMIT 10000
using namespace std;
bool ck(vector<int>&v){
	for(int i=0;i<v.size();i++)if(v[i]!=i+1)return false;
	return true;
}
main(){
	int n,i,j,s,x,l;
	vector<int>tri;
	for(i=1;i<499;i++)tri.push_back(i*(i+1)/2);
	for(;scanf("%d",&n),n;){
		vector<int>v;
		for(s=i=0;i<n;i++){
			scanf("%d",&x);
			s+=x;
			v.push_back(x);
		}
		vector<int>::iterator idx=find(tri.begin(),tri.end(),s);
		i=LIMIT+1;
		if(idx!=tri.end()){
			for(i=0;i<=LIMIT&&!ck(v);i++){
				l=v.size();
				for(j=0;j<l;j++)v[j]--;
				v.erase(remove(v.begin(),v.end(),0),v.end());
				v.push_back(l);
			}
		}
		printf("%d\n",i>LIMIT?-1:i);
	}
}

Measured memory_bytes: 1056
/*   ꧁༒☬महाकाल☬༒꧂ ꧁༒ঔमहाकालঔ༒꧂
                   
                   ঔৣ۝महाकालᴳᵒᵈ۝ঔৣ            
 
 */ 
#include<bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//template <typename T, typename cmp=less<T>> using oset =tree<T, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
#define ll long long 
#define mod 1000000007
#define inf 100000000000000000
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define _it iterator
#define all(_x) _x.begin(),_x.end()
#define f first
#define s second
#define pb push_back
#define ar array
#define ld long double
void mahakal(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	freopen("error.txt","w",stderr);
	#endif
}
ll dx[4]={1,0,-1,0};
ll dy[4]={0,1,0,-1};
char c[4]={'D' , 'R' , 'U' , 'L'};
const ll maxN=2e5+5;
ll x , a[50];
void solve(){
	cin>> x ;
	ll cnt=8;
	for(ll i=4;i<=19 ; i+=2){
		a[i]=cnt;
		a[i+1]=cnt;
		cnt--;
	}
	cout<<a[x/100]<<endl;
}

int main(){
	//mahakal();
	fast;
	ll t =1 ;
	//cin>> t ; 
	while(t--)solve();
	//cerr << "\ntime taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl; 
	return 0;
}

Measured memory_bytes: 3580
/// Kazuki Hoshino


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
#define inf 1000000000
#define mod 1000000007
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define rep1(i, a, b) for(int i =a; i >=b; i--)
#define f first
#define ss second
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define mt make_tuple
//#define endl '\n'
typedef tree<
int,
null_type,less<int>,
rb_tree_tag,tree_order_statistics_node_update>
ordered_set;


int n, a[101010], ans = inf, mp[101010], mpp[101010];
set<int> s1, s2;
vpi v,p;
set<pi> s3;

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

//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);


cin >> n;

rep(i, 1, n){
    cin >> a[i];
    if(i%2){mp[a[i]]++;s1.insert(a[i]);}
    else {mpp[a[i]]++;s2.insert(a[i]);}
}

for(auto t: s1){
    v.pb({mp[t], t });
}
for(auto t: s2){
    p.pb({mpp[t], t});
}

sort(all(v));
sort(all(p));

for(auto t: p){
    s3.insert(t);
}

for(auto t: v ){

    auto it = s3.find({mpp[t.ss], t.ss});
    if(it == s3.end()){
        it--;
        ans = min(ans, n - t.f - (*it).f   );
    }
    else {
        s3.erase(it);
        if(s3.empty()){
            ans = min(ans, n - t.f );
        }
        else {
            auto itt = s3.end();
            itt--;
            ans = min(ans, n - t.f - (*itt).f);
        }
        s3.insert(*it);
    }

}

s3.clear();

for(auto t: v){
    s3.insert(t);
}
for(auto t: p ){

    auto it = s3.find({mp[t.ss], t.ss});
    if(it == s3.end()){
        it--;
        ans = min(ans, n - t.f - (*it).f   );
    }
    else {
        s3.erase(it);
        if(s3.empty()){
            ans = min(ans, n - t.f );
        }
        else {
            auto itt = s3.end();
            itt--;
            ans = min(ans, n - t.f - (*itt).f);
        }
        s3.insert(*it);
    }

}

cout << ans << endl;


return 0;}
///....


Measured memory_bytes: 12024
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <deque>
#include <queue>
#include <string>
#include <string.h>
#include <math.h>
#include <iomanip>
#include <stdio.h>
using namespace std;

#define int64 long long
#define pii pair <int64, int64>
#define fr first
#define sc second
#define heap priority_queue
struct piii{
    int64 fr, sc, th;
    bool operator < (const piii &b){
        if (fr != b.fr) return fr < b.fr;
        if (sc != b.sc) return sc < b.sc;
        return th < b.th;
    }
};
///////////////////////////////////////////////
///////////////////////////////////////////////

int main(){
    cout << setprecision(2) << fixed;
    ios::sync_with_stdio(false), cin.tie(0);
    //freopen("input.txt", "r", stdin);
    int a, b;
    cin >> a >> b;
    if (a > 9 || b > 9) cout << -1;
    else cout << a * b;
    return 0;
}


Measured memory_bytes: 256