akhauriyash/Code-Regression huggingface dataset:
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <math.h> // sqrt
using namespace std;

int main() {
    int X, N;
    cin >> X >> N;
    vector<int> data(N);
    for (int i = 0; i < N; i++) {
        cin >> data.at(i);
    }
    int i = 0;
    bool check;
    while (true) {
        check = false;
        for (int x : data) {
            if (x == X - i) {
                check =true;
                break;
            }
        }
        if (!check) {
            cout << X - i << endl;
            return 0;
        }
        check = false;
        for (int x : data) {
            if (x == X + i) {
                check = true;
                break;
            }
        }
        if (!check) {
            cout << X + i << endl;
            return 0;
        }
        i++;
    }
}

Measured memory_bytes: 3628
n = int(input())

length = len(str(n))

temp = 10
ans = 0
for i in range(length-1):
    if i%2 == 0:
        ans += temp * 0.9
    temp *= 10

if length%2 == 1:
    ans += n - temp/10 + 1
print(int(ans))

Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;

int main() {
	int n, total = 0;
	cin >> n;
	for (int i = 1; i < n; i++) {
		total += (n-1) / i;
	}
	cout << total << endl;
	return 0;
}

Measured memory_bytes: 3656
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef long double ld;
const ll INF = 1e+14;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back

void Yes(){
	cout<<"Yes"<<endl;
	exit(0);
}
 
void No(){
	cout<<"No"<<endl;
	exit(0);
}

char march[5] = {'M', 'A', 'R', 'C', 'H'};

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
    int N; cin >> N;
    map<char, ll> mp;
    rep(i, N) {
        string S; cin >> S;
        mp[S[0]] ++;
    }
    ll ans = 0;
    rep(i, 5) {
        rep(j, 5) {
            rep(k, 5) {
                if(i == j || j == k || k == i) continue;
                ans += mp[march[i]] * mp[march[j]] * mp[march[k]];
            }
        }
    }
    cout << ans / 6 << endl;
	return 0;
}

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

const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1);


int main(void)
{
    ll k,x,ans=1; cin>>k;
    x=7%k;
    set<ll> s;
    while(s.count(x)==0){ //訪れてない限り続ける
        if(x==0){
            cout << ans << endl;
            return 0;
        }
        s.insert(x);
        x = (x*10+7)%k;
        ans++;
    }
    cout<<-1<<endl;
    return 0;
}

Measured memory_bytes: 50496
#include <iostream>
#include <strstream>
#include <string>
#include <deque>
#include <vector>
#include <algorithm>
typedef unsigned int UINT;
using namespace std;

int main(void) {
    char X, Y;
    cin >> X >> Y;
    if (X == Y)
        cout << "=\n";
    else if (X > Y)
        cout << ">\n";
    else
        cout << "<\n";
    return 0;
}

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

using namespace std;

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

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

    sort(n.begin(), n.end());
    if (n[0] + n[1] == n[2])
        cout << "Yes\n";
    else
        cout << "No\n";

    return 0;
}


Measured memory_bytes: 256
n=int(input())
plist = list(map(int,input().split(" ")))
nlist = list()
count = 0
for i in range(n):
  nlist.append(i+1)
  
for j in range(len(nlist)):
  if plist[j]!=nlist[j]:
    count += 1

if count == 2 or count == 0:
  print("YES")
else:
  print("NO")

Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<iomanip>
#include<cmath>
#include<vector>
#include<queue>
#include<set>
#include <cstdio>
#include<map>
#include<string>
#include<unordered_map>
#define Amr_Abdelazim ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define pp pop_back
#define ll long long
#define ld long double
#define rep(i,m)   for(int i=0;i<m;i++)
#define repp(s,i,m)   for(int i=s;i<m;i++)
#define mkp make_pair
using namespace std;
const int mod = 1000000007;
const int N = 1000005;
class cmp{
public:
	bool operator() (ll &A, ll &B){
		if (A > B) return true;
		return false;
	}
};
int main()
{
	Amr_Abdelazim
		ll n,k,ans=1e15;
	cin >> n>>k;
	vector<ll>v(n);
	rep(i, n)cin >> v[i];
	sort(v.begin(), v.end());
	rep(i, n - k + 1)ans = min(ans, v[i + k - 1] - v[i]);
	cout << ans << "\n";
		return 0;
}

Measured memory_bytes: 1024
long a,v,c;f(char*x,char*y){return*y-*x;}main(){for(;read(0,&c,1)|v;c=v&66&&!printf(a==0x414144494e4e5559?v=0,"AIZUNYAN":"%c",v))v=a=v>>8|c<<56,qsort(&a,8,1,f);}

Measured memory_bytes: 524
N,M,Q = [ int(it) for it in input().split()]

grid = [ [0]*N for i in range(N) ]
gridsml = [ [0]*N for i in range(N) ]

for i in range(M):
  s,g = [ int(it)-1 for it in input().split()]
  grid[s][g]+=1

for i in range(N):
  gridsml[i][0]=grid[i][0]
  for j in range(1,N):
    gridsml[i][j]+=gridsml[i][j-1]+grid[i][j]


for i in range(Q):
  s,g = [ int(it)-1 for it in input().split()]
  m = 0
  for i in range(s,N):
    m += gridsml[i][g]
  print (m)

Measured memory_bytes: 57048
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<vector>
#include<set>
#include<queue>
#include<iostream>
#include<map>
#include<cstring>
#include<deque>
#define INF 0x3f3f3f3f
#define eps 1e-10
using namespace std;
int x;
long long ans=2,a9=2,a0=2,mod=1e9+7,n;
long long power(long long x,long long y){
    long long result=1;
    for(int i=1;i<=y;i++){
        result*=x;
        result%=mod;
    }
    return result;
}
int main(){
    scanf("%lld",&n);
    ans=power(10,n)-power(9,n)-power(9,n)+power(8,n);
    ans%=mod;
    while(ans<0)
        ans+=mod;
    printf("%lld",ans);
}

Measured memory_bytes: 3196
#include <iostream>
using namespace std;
int tab[100005];
int dp[100005];
int bzw(int a)
{
  
  if(a<0){
    return a*-1;
  }else{
    return a;
  }
}

int main()
{
  
  int n;
  cin>>n;
  
  for( int i=0;i<n;i++ ){
    dp[i] = 1000000000;  
  }

  for( int i=0;i<n;i++ ){
      cin>>tab[i];
    }

  for( int i=0;i<n;i++ ){
    for( int j=max(0,i-2);j<i;j++ ){    
	dp[i] = min( dp[i],bzw(tab[i]-tab[j])+dp[j] );  
    }
    if( dp[i] == 1000000000 ){
      dp[i] = 0;
    }
  }
  
  cout << dp[n-1] << endl;

  return 0;
  
}

//AtCoder - Frog1



Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000000;

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

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

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

string s;

bool solve() {
	if (s[0] != 'A') {return false; }
	ll c = 0;
	for (ll i = 2; i < s.size() - 1; i++) {
		if (s[i] == 'C') { c++; }
	}
	if (c != 1) {return false; }

	for(ll i=1; i<s.size();i++) {
		if (s[i] != 'C' && (s[i]<'a' || s[i]>'z')) { return false; }
	}

	return true;
}

int main() {
	
	cin >> s;

	if (solve()) { cout << "AC"; }
	else { cout << "WA"; }
	
	
	system("PAUSE");
}

Measured memory_bytes: 504
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br =
            new BufferedReader(new InputStreamReader(System.in), 1);
        String x;
        int i = 1;
        while(true){
        	x = br.readLine();
        	if (x.equals("0"))
        		return;
        	System.out.println("Case " + i + ": " + x);
        	i++;
        }
    }
}

Measured memory_bytes: 41108
#-*-coding:utf-8-*-

def main():
    numbers=[]
    n = int(input())
    numbers=list(map(int,input().split()))
    sort_numbers=sorted(numbers)
# left/right算出はsorted arrayで
    left=sort_numbers[n//2-1]
    right=sort_numbers[n//2]
# loopは元の配列で
    for i in numbers:
        if i > left:
            print(left)
        else:
            print(right)

if __name__=="__main__":
    main()

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


s=input().rstrip()
ans=""
for i in range(len(s)):
    if i%2==0:
        ans+=s[i]
print(ans)

Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define repone(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define Rep(j,n) for(int j=0;j<(int)(n);++j)
#define Repo(j,o,n) for(int j=o;j<(int)(n);++j)
#define Repone(j,n) for(int j=1;j<(int)(n);++j)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define int long long
#define pb(a) push_back(a)
#define eraser(v,i) (v).erase(v.begin()+(i))
#define pbpair(a,b) push_back(make_pair(a,b))
#define Little 1
const long long INF = 1LL<<60;
#define pairint pair<int,int>
signed main(){
  int x=0,y=0,z=0,w=0,n=0,m=0,o=0;
  string s="",t="";
  std::cin >> x;
  x%=10;

  if(x==2||x==4||x==5||x==7||x==9){
    std::cout << "hon" << '\n';
  }else if(x==0||x==1||x==6||x==8){
    std::cout << "pon" << '\n';
  }else{
    std::cout << "bon" << '\n';
  }
}


Measured memory_bytes: 3632
#include<cstring>
#include<algorithm>
#include<cstdio>
using namespace std;
long long gcd(long long a,long long b)
{
    if(b) return gcd(b,a%b);
    return a;
}
int main()
{
    long long a,b;
    while(scanf("%lld %lld",&a,&b)!=EOF)
    {
        long long ans=gcd(a,b);
        long long ans1=a*b/ans;
        printf("%lld %lld\n",ans,ans1);
    }
    return 0;
}

Measured memory_bytes: 2620
<?php
fscanf(STDIN, "%d", $n);
$a = explode(' ', trim(fgets(STDIN)));

rsort($a);

$ans = 0;

$t = $n - 1;

for ($i=0; $i < $n; $i++) {
  $lim = 2;
  if ($i == 0) {
    $lim = 1;
  }

  for ($j=0; $j < $lim; $j++) {
    if ($t > 0) {
      $ans += $a[$i];
      $t--;
    }
  }
}

echo $ans;


Measured memory_bytes: 31756
#include<bits/stdc++.h>
using namespace std;
int main(){
    int k;
    cin >>k;
    string s;
    cin >> s;
  if(s.size()<= k){
     cout << s << endl;
  }
  else{
      s = s.substr(0, k) + "...";
      cout << s << endl;
  }
   
}

Measured memory_bytes: 3604
#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;
    ll ans = 0;
    for (int b = 1; b < n; b++) {
        ans += (n-1) / b;
    }
    cout << ans << endl;

    return 0;    
}

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

#define int long long

main()
{
  int n, m;
  bool flag[100005] = {};
  int cnt[100005];
  
  fill_n(cnt, 100005, 1);
  
  flag[1] = true;
  cin >> n >> m;

  for(int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    
    flag[b] |= flag[a];
    cnt[a]--, cnt[b]++;
    if(cnt[a] == 0) flag[a] = false;
  }

  int ans = 0;
  for(int i = 1; i <= n; i++) {
    if(flag[i]) ans++;
  }

  cout << ans << endl;

  return (0);
}


Measured memory_bytes: 1152
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <utility>
#include <functional>

using namespace std;

#define INF (1 << 30)

int dp[1001][1001];

int main() {
	int n, m, d[1000], c[1000];

	cin >> n >> m;
	for (int i = 0; i < n; ++i) {
		cin >> d[i];
	}
	for (int i = 0; i < m; ++i) {
		cin >> c[i];
	}
	fill(dp[0], dp[1001], INF);

	dp[0][0] = 0;
	for (int i = 0; i < m; ++i) {
		for (int j = 0; j <= n; ++j) {
			if (dp[i][j] != INF) {
				dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
				if (j + 1 <= n)
					dp[i + 1][j + 1] = min(dp[i + 1][j + 1], dp[i][j] + c[i] * d[j]);
			}
		}
	}
	cout << dp[m][n] << endl;

	return 0;
}

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

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int n, m;
    static pair<int64_t, int> weight[100000];
    static int w[100000];
    static char color[100001];
    static int ans[200000];
    static vector<tuple<int64_t, int, int>> edges[100000];
    cin >> n >> m;
    for(int i=0;i<n;++i){
        int d;
        cin >> d;
        weight[i] = {d, i};
        w[i] = d;
    }
    for(int i=0;i<m;++i){
        int u, v;
        cin >> u >> v;
        --u; --v;
        edges[u].emplace_back(weight[v].first, v, i);
        edges[v].emplace_back(weight[u].first, u, i);
    }
    sort(weight, weight + n);
    for(int i=0;i<n;++i) sort(edges[i].begin(), edges[i].end());

    for(int i=0;i<n;++i){
        int v = weight[i].second, to = get<1>(edges[v][0]), e = get<2>(edges[v][0]);
        if(color[v] != 0) continue;
        if(color[to] != 0){
            color[v] = 'W' + 'B' - color[to];
            ans[e] = w[v];
        }else{
            cerr << to << " " << v << endl;
            if(w[to] != w[v]){ cout << -1 << endl; return 0; }
            color[v] = 'W'; color[to] = 'B';
            ans[e] = w[v];
        }
    }
    cout << color << endl;
    for(int i=0;i<m;++i) cout << (ans[i] == 0 ? 1000000000 : ans[i]) << endl;

    return 0;
}

Measured memory_bytes: 17152
#include <iostream>

using namespace std;

int main() {
	int c[4][4];
  
  	for(int i = 0; i < 3; i++) {
      for(int j = 0; j < 3; j++) {
        cin >> c[i][j];
      }
    }
  
  	if(c[0][0]-c[0][1] == c[1][0]-c[1][1] &&
       c[1][0]-c[1][1] == c[2][0]-c[2][1] && 
       c[0][1]-c[0][2] == c[1][1]-c[1][2] && 
       c[1][1]-c[1][2] == c[2][1]-c[2][2]) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  
  	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

int main(void){
	int a,p;
	cin >> a >> p;
	a *= 3;
	p += a;
	cout << (p/2) << endl;
	return 0;
}


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

using namespace std;
using ll = long long;
using P = pair<int, int>;

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

#define chmax(x, y) x = max(x, y)

int dp[3005][3005];

int main() {
  int n, t;
  cin >> n >> t;
  vector<P> p(n);
  rep(i, n) cin >> p[i].first >> p[i].second;

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

  int ans = 0;
  rep(i, n) {
    rep(j, t) {
      chmax(dp[i + 1][j], dp[i][j]);
      int nj = j + p[i].first;
      if (nj < t) chmax(dp[i + 1][nj], dp[i][j] + p[i].second);
    }
    int now = dp[i][t - 1] + p[i].second;
    chmax(ans, now);
  }

  cout << ans << endl;
  return 0;
}


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

#define rep(i,N) for(int i=0;i<N;i++)
#define rep2(i,N) for(int i=1;i<=N;i++)
using namespace std;
long long  INF=1e18;
long long mod=1e9+7;

//status unsolved

int main(){
    long long n,m;
    cin>>n>>m;

    long long high[n+1];
    rep2(i,n)cin>>high[i];


    vector<vector<int>>to(n+1);
    rep(i,m){
        int a,b;
        cin>>a>>b;
        to[a].emplace_back(b);
        to[b].emplace_back(a);
    }
    int ans=0;
    rep2(i,n){
        bool good=true;
        for(auto l:to[i]){
            if(high[i]<=high[l])good=false;
        }
        if(good)ans++;
    }

    cout<<ans<<endl;
    return 0;

}
/*


*/


Measured memory_bytes: 9068
import java.util.Scanner;
 
class Main{
 
    public static void main(String[] args) {
 
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int OffHouse[][][] = new int[4][3][10];
        for(int i=0; i<n; i++){
 
            int b = scan.nextInt();
            int f = scan.nextInt();
            int r = scan.nextInt();
            OffHouse[b-1][f-1][r-1] += scan.nextInt();
        }
        scan.close();
        for(int i=0; i<4; i++){ //?£?
            for(int s=0; s<3; s++){ //???
                for(int t=0; t<10; t++){ //??¨?±?
                        System.out.print(" " + OffHouse[i][s][t]);
                    }
                System.out.print("\n");
                if(i != 3 && s == 2)
                    System.out.println("####################");
            }
        }
    }
 
}

Measured memory_bytes: 21064
#include <iostream>

using namespace std;

int main(){
  int n;
  cin >> n;
  for (int k=0;4*k<=n;k++) {
    int tmp = n - 4*k;
    if (tmp % 7 == 0) {
      cout << "Yes" << endl;
      return(0);
    }
  }
  cout << "No" << endl;
  return(0);
}


Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;
#define ms(x,y) memset(x, y, sizeof(x))
#define lowbit(x) ((x)&(-x))
typedef long long LL;
typedef pair<int,int> pii;


void run_case() {
    int n; cin >> n;
    vector<int> buf(n, 0);
    for(int i = 0; i < n-1; ++i) {
        int t; cin >> t;
        t--;
        buf[t]++;
    }
    for(auto x: buf) {
        cout << x << "\n";
    }
}

int main() {
    ios::sync_with_stdio(false), cin.tie(0);
    cout.flags(ios::fixed);cout.precision(10);
    run_case();
    cout.flush();
    return 0;
}


Measured memory_bytes: 3976
#include<bits/stdc++.h>
using namespace std;
const int maxn=2e5+100;
int a[maxn];
multiset<int,greater<int> >s;
multiset<int,greater<int> >::iterator it;
int main()
{
	std::ios::sync_with_stdio(false);
	int n;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	s.insert(a[0]);
	for(int i=1;i<n;i++)
	{
		it=s.upper_bound(a[i]);
		if(it==s.end())
		{
			s.insert(a[i]);
		}
		else
		{
			s.erase(it);
			s.insert(a[i]);
		}
	}
	cout<<s.size();
	return 0;
}

Measured memory_bytes: 5376
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
#include <fstream>


using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD (ll)1000000007
#define P pair<ll, ll>

bool ok[110000];
int main() {
	ok[0] = true;
	REP(j, 100100) {
		FOR(i, 100, 106) {
			if (ok[j])ok[j + i] = true;
		}
	}
	ll x;
	cin >> x;
	cout << ok[x] << endl;
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
                                                                                                
  
int main(){
                                                                                                

    string s1, s2, s3, t;

         
    cin >> s1 >> s2 >> s3;


    t += s1.at(0);

    t += s2.at(0);

    t += s3.at(0);


    transform(t.begin(), t.end(), t.begin(), ::toupper);


    cout << t << endl;


    return 0;
                                                          
}

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

using namespace std;

int main()
{
    int P,Q,R; // A~B,B~C,C~A;
    cin >> P >> Q >> R;

    vector<int> time = {P+Q,Q+R,R+P};

    cout << *min_element(time.begin(),time.end()) << endl;
    return 0;
}

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

int n, u, k, v;
int a[100][100] = {{0}};
int b[100];
queue<int> q;

int main() {
	for ( int i = 0; i < 100; i++ )
		b[i] = - 1;
	cin >> n;
	for ( int i = 0; i < n; i++ ) {
		cin >> u >> k;
		for ( int j = 0; j < k; j++ ) {
			cin >> v;
			a[u - 1][v - 1] = 1;
		}
	}
	b[0] = 0;
	q.push( 0 );
	while ( ! q.empty() ) {
		u = q.front();
		for ( int i = 0; i < n; i++ ) {
			if ( a[u][i] == 1 && b[i] == -1 ) {
				b[i] = b[u] + 1;
				q.push( i );
			}
		}
		q.pop();
	}
	for ( int i = 0; i < n; i++ )
		cout << ( i + 1 ) << " " << b[i] << endl;
}

Measured memory_bytes: 1240
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int num = 0;
        boolean flg = false;
        while (n > 0) {
            num = n % 10;
            if (num == 7) {
                flg = true;
                break;
            }
            n /= 10;
        }
        if (flg) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }

        sc.close();
    }
}


Measured memory_bytes: 35596
#include<iostream>
 
using namespace std;
 
int main(){
  int n,w,h,s;
  cin>>w;
  cin>>h;
  cin>>n;
  int x[n],y[n],a[n];
  for(int i=0;i<n;i++){
    cin>>x[i];
    cin>>y[i];
    cin>>a[i];
  }
  int b[4]={0,w,0,h};
  for(int i=0;i<n;i++){
    switch(a[i]){
      case 1:
        if(b[0]<x[i]){
          b[0]=x[i];
        }
        break;
      case 2:
        if(b[1]>x[i]){
          b[1]=x[i];
        }
        break;
      case 3:
        if(b[2]<y[i]){
          b[2]=y[i];
        }
        break;
      case 4:
        if(b[3]>y[i]){
          b[3]=y[i];
        }
        break;
    }
  }
  s=(b[1]-b[0])*(b[3]-b[2]);
  if(b[1]-b[0]<=0||b[3]-b[2]<=0){
    s=0;
    }
  cout<<s<<endl;
  return 0;
}

Measured memory_bytes: 256
N = int(input())
X = list(map(int, input().split()))
nx = [X[i] for i in range(N)]
nx.sort()
ans2 = (nx[N//2])
ans3 = (nx[N//2-1])

for i in range(N):
    if X[i] <= nx[N//2-1]:
        print(ans2)
    elif X[i] >= nx[N//2]:
        print(ans3)



Measured memory_bytes: 102100
var N,K,i,c,j,a:Longint;
ex:Array[1..100]of Boolean;
begin
read(N,K);
for i:=1 to K do begin
read(c);
for j:=1 to c do begin
read(a);
if not ex[a]then begin
ex[a]:=True;
dec(N);
end;
end;
end;
writeln(N);
end.

Measured memory_bytes: 1324
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define per(i, n) for (int i = (int)(n-1); i >= 0; i--)
#define sz(x) int(x.size())
#define all(x) (x).begin(), (x).end()
#define INF 2e9
typedef long long ll;
typedef pair<int, int> P;

int main() {
    int n, m; cin >> n >> m;
    vector<ll> a(m), y(m);
    vector<vector<int> > p(n+1);
    rep(i, m) {
        cin >> a[i] >> y[i];
        p[a[i]].push_back(y[i]);
    }
    rep(i, n+1) {
        sort(all(p[i]));
    }
    rep(i, m) {
        printf("%012lld\n", 1000000*a[i] + (int)(lower_bound(all(p[a[i]]), y[i]) - p[a[i]].begin())+1);
    }
}

Measured memory_bytes: 8576
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <numeric>

using namespace std;

#define int long long
typedef long double ld;
#define pii pair<int, int>
#define vi vector<int>
#define vii vector<vi>
#define viii vector<vii>
#define vpii vector<pii>
#define vb vector<bool>
#define vbb vector<vb>
#define vs vector<string>
#define pb push_back
#define ff first
#define ss second
#define all(a) a.begin(), a.end()
#define in(a) for (int i = 0; i < (a).size(); ++i) cin >> (a)[i]
#define out(a) for (auto qwe : a) cout << qwe << " "

const int INF = 1e9;
const int INF64 = 1e18;
const int MOD = 1e9 + 7;
const int MOD9 = 1e9 + 9;
const int MOD3 = 998244353;
const int P = 37;

const int mxn = 300;

int n, m;
vii g(100001);
vi d(100001, -1);
vb was(100001, false);


void rec(int v) {
    was[v] = true;

    d[v] = 0;

    for (auto w : g[v]) {
        if (!was[w]) {
            rec(w);
        }

        d[v] = max(d[v], d[w] + 1);
    }
}

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

    cin >> n >> m;

    for (int i = 0; i < m; ++i) {
        int x, y;
        cin >> x >> y;

        g[x].pb(y);
    }

    for (int j = 1; j <= n; ++j) {
        if (!was[j]) {
            rec(j);
        }
    }

    cout << *max_element(all(d));
}

Measured memory_bytes: 8576
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define debug(x) cerr<<#x<<": "<<x<<endl
#define MOD 1000000007ULL
#define rep(i,n) for(int i=0;i<n;i++)


int main() {
	ll S;
  	cin>>S;
  
  	ll dp[50000];
  	rep(i,50000){
		dp[i]=0;
    }
  	dp[0]=1;
  	dp[3]=1;
  	dp[4]=1;
  	dp[5]=1;
  	dp[6]=2;
  	dp[7]=3;
  	dp[8]=4;
  	dp[9]=6;
  	
  	for(ll i=10;i<3000;i++){
     	for(ll j=3;j<=i;j++){
         	dp[i]+=dp[i-j]%MOD; 
        }
      	dp[i]%=MOD;
    }
  	cout<<dp[S]<<endl;
}

Measured memory_bytes: 4016
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

/**
 * コンソールテスト用Main クラス
 *
 */
public class Main {

	/* コンストラクタ */
	Main() {
	//何もしない
	}

	/**
	 * 提出
	 *
	 */

	public static void main(String args[]) {
		Scanner scanner= new Scanner(System.in);
		int n = 0;
		int k = 0;
		int tmp = 0;
		int result = 0;
		ArrayList<Integer> nedan = new ArrayList<Integer>();


		n = scanner.nextInt();
		k = scanner.nextInt();

		for(int i = 0; i < n; i++) {
			tmp = scanner.nextInt();
			nedan.add(tmp);
		}
		Collections.sort(nedan);


		for (int j = 0; j < k; j++) {
			result = result + nedan.get(j);
		}

		System.out.println(result);
	}
}


Measured memory_bytes: 30432
// AOJ 0200: Traveling Alone: One-way Ticket of Youth
// 2017.8.9 bal4u@uu
// 2017.11.12

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

int tim[102][102], fee[102][102];
int org[102][102];
char buf[30], *bp;

int getint()
{
	int n = 0;
	while (*bp >= '0') n = (n<<3) + (n<<1) + (*bp++ & 0xf);
	return n;
}

int main()
{
	int n, m, i, j, k, a, b, c, t, x;
	int p, q, r;

	memset(org, 0x11, sizeof(org));
	i = 101; while (i--) org[i][i] = 0;

	while (fgets(bp=buf, 30, stdin) && *bp != '0') {
		n = getint(), bp++, m = getint();
		memcpy(tim, org, sizeof(org)), memcpy(fee, org, sizeof(org));

		while (n--) {
			fgets(bp=buf, 30, stdin);
			a = getint(), bp++, b = getint(), bp++;
			c = getint(), bp++, t = getint();
			if (fee[a][b] > c) fee[a][b] = fee[b][a] = c;
			if (tim[a][b] > t) tim[a][b] = tim[b][a] = t;
		}

		for (k = 0; k <= m; k++) for (i = 0; i <= m; i++) for (j = 0; j <= m; j++) {
			if ((x = fee[i][k] + fee[k][j]) < fee[i][j]) fee[i][j] = x;
			if ((x = tim[i][k] + tim[k][j]) < tim[i][j]) tim[i][j] = x;
		}

		fgets(bp=buf, 10, stdin); k = getint();
		while (k-- > 0) {
			fgets(bp=buf, 30, stdin);
			p = getint(), bp++, q = getint(), bp++, r = getint();
			if (r) printf("%d\n", tim[p][q]);
			else   printf("%d\n", fee[p][q]);
		}
	}
	return 0;
}

Measured memory_bytes: 1876
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            StringBuilder sb = new StringBuilder();

            string input;

            while (!string.IsNullOrEmpty(input = Console.ReadLine()))
            {
                sb.AppendLine(SearchReslt(input).ToString());
            }
            Console.Write(sb);
        }

        static char SearchReslt(string map)
        {
            if (map[0] != 's' && map[0] == map[4] && map[0] == map[8]) return map[0];
            if (map[2] != 's' && map[2] == map[4] && map[2] == map[6]) return map[2];

            for (int i = 0; i < 9; i += 3)
            {
                if (map[i] != 's' && map[i] == map[i + 1] && map[i] == map[i + 2]) return map[i];
            }

            for (int i = 0; i < 3; i++)
            {
                if (map[i] != 's' && map[i] == map[i + 3] && map[i] == map[i + 6]) return map[i];
            }
            return 'd';
        }
    }
}

Measured memory_bytes: 8660
#include<bits/stdc++.h>
using namespace std;
int n,a[100010][5],dp[100010][5];

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d %d %d",&a[i][0],&a[i][1],&a[i][2]);
	}
	for(int i=0;i<3;i++)
	{
		dp[1][i] = a[1][i];
	}
	for(int i=2;i<=n;i++)
	{
	//	printf("%d. ",i);
		for(int j=0;j<3;j++)
		{
			dp[i][j] = -1;
			for(int k=0;k<3;k++)
			{
			//	printf("%d %d : %d %d\n",i,j,dp[i-1][j]+a[i][k],a[i][k]);
				if(j!=k)
				{
					dp[i][j] = max(dp[i][j],dp[i-1][k]+a[i][j]);
				}
			}
			//printf("%d ",dp[i][j]);
		}
		//printf("\n");
	}
	printf("%d\n",max(dp[n][0],max(dp[n][1],dp[n][2])));
	return 0;
}

Measured memory_bytes: 4096
#include <cstdio>
#include <vector>
#include <cstring>
#include <functional>
#include <algorithm>
#include <math.h>
#include <bitset>
#include <set>
#include <queue>
#include <assert.h>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <complex>
#include <numeric>
#include <map>
#include <time.h>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<int,int> pii;
typedef pair<int,ll> pil;
typedef pair<int,ull> piu;
typedef pair<ull,ull> puu;
typedef pair<ll,int> pli;
typedef pair<ll,ll> pll;
typedef pair<pii,ll> ppl;
typedef pair<ll,pii> plp;
typedef pair<ll,pll> plP;
typedef pair<int,pii> pip;
typedef pair<pii,int> ppi;
typedef pair<pii,pii> ppp;
typedef pair<double,int> pdi;
typedef pair<int,double> pid;
typedef pair<double,pii> pdp;
typedef pair<double,double> pdd;
typedef pair<pdd,double> pd3;
typedef vector<ll> vec;
typedef vector<vec> mat;
#define rep(i,n) for (int (i) = 0; (i) < (n); (i)++)
#define repn(i,a,n) for (int (i) = (a); (i) < (n); (i)++)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back
#define SORT(x) sort((x).begin(),(x).end())
#define SORTN(x,n) sort((x),(x)+(n))
#define ERASE(x) (x).erase(unique((x).begin(),(x).end()),(x).end())
#define COUNT(x,c) count((x).begin(),(x).end(),(c))
#define REMOVE(x,c) (x).erase(remove((x).begin(),(x).end(),(c)),(x).end())
#define REVERSE(x) reverse((x).begin(),(x).end())
#define FORIT(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))-(x).begin()
#define lb(x,a) lower_bound((x).begin(),(x).end(),(a))
#define LBN(x,a,n) lower_bound((x),(x)+(n),(a))-(x)
#define lbN(x,a,n) lower_bound((x),(x)+(n),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))-(x).begin()
#define ub(x,a) upper_bound((x).begin(),(x).end(),(a))
#define BS(x,a) binary_search((x).begin(),(x).end(),(a))
#define BS2(x,n,a) binary_search((x),(x)+(n),(a))
#define NB(x) (((x)&~((x)+((x)&-(x))))/((x)&-(x))>>1)|((x)+((x)&-(x)))
#define NP(x) next_permutation((x).begin(),(x).end())
#define MM(x,p) memset((x),(p),sizeof(x))
#define SQ(x) (x)*(x)
#define SC(c1,c2) strcmp(c1,c2)==0
#define mp make_pair
#define INF (1<<29)
#define INFL (1LL<<61)
#define fi first
#define se second
#define EPS 1e-9
#define MOD 1000000007
#define MIN(x,a) x=min(x,a)
#define MAX(x,a) x=max(x,a)
#define madd(x,a) x=(x+a)%MOD
#define msub(x,a) x=(x+MOD-a)%MOD
#define OUTPUT(x) rep(__,x.size())printf("%d%c",x[__],__+1==x.size()?'\n':' ')

int N;
int A[100000];
int c[110000];

int main()
{
	scanf("%d",&N);
	ll r=1;
	int p1=0,p2=0,p3=0;
	rep(i,N)
	{
		scanf("%d",&A[i]);
		c[A[i]]++;
		int c1=0;
		c1+=(p1==A[i]);
		c1+=(p2==A[i]);
		c1+=(p3==A[i]);
		if(c1==0)r*=0;
		else if(c1==1)r*=1;
		else if(c1==2)r*=2;
		else r*=3;
		if(p1==A[i])p1++;
		else if(p2==A[i])p2++;
		else p3++;
		r%=MOD;
	}
	repn(i,0,100001)if(c[i]<c[i+1])
	{
		puts("0");
		return 0;
	}
	printf("%lld\n",r);
}

Measured memory_bytes: 1024
d=int(input())
c=list(map(int,input().split()))
num=[0]*26
ans=[]
for i in range(1,d+1):
    num1=1
    num2=-(10**100)
    num3=[0]*26
    for j in range(26):
        num3[j]=-1*((i-num[j])*c[j])
    s=list(map(int,input().split()))
    for j in range(26):
        num5=s[j]-num3[j]
        if num5>num2:
            num1=j+1
            num2=num5
    ans.append(num1)
    num[num1-1]=i
for i in range(d):
    print(ans[i])


Measured memory_bytes: 9240
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const double eps = 1e-8;

#ifdef DEBUG
#include "inc/debug.hpp"
#else
#define debug(...) 42
#endif

int main() {
    int N;
    cin >> N;
    string S, T;
    cin >> S >> T;
    string res = "";
    for (int i=0; i<N; ++i) {
        res += S[i];
        res += T[i];
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
//
#include <bits/stdc++.h>
using namespace std;
#define INF 1000000000
#define MOD 1000000007
#define PI 3.14159265
#define EPS 1e-9
#define Pi acos(-1.0)
typedef pair<int, int> ii;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
#define forr(i,a,b) for(int i=(a); i<(b); i++)
#define clean(arr,val) memset(arr,val,sizeof(arr))
#define forn(i,n) forr(i,0,n)
#define PB push_back
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<pll> vpll;

/*CODE START HERE*/

string s;
ll ans;

void f(int i,string aux, ll total){
    ///cout << "NOW ON " << i << " AUX " << aux << " TOTAL " << total << "\n";
    if(i == (int)s.size()){
        //cout << "SUM " <<  total+(aux.size() > 0 ? stoll(aux) : 0) << "\n";
        ans += total+(aux.size() > 0 ? stoll(aux) : 0);
        return;
    }

    aux.push_back(s[i]);
    f(i+1,aux,total);
    aux.pop_back();
    ll temp = total+(aux.size() > 0 ? stoll(aux) : 0);
    aux.clear();
    aux.push_back(s[i]);
    f(i+1,aux,temp);
}

int main(){
    ios::sync_with_stdio(0);
    cin >> s;
    ans = 0;
    string aux = "";
    aux.push_back(s[0]);
    f(1,aux,0);
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    a,b = LI()
    print(a*b)
    return

#Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 65396
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<vector>
#include<sstream>
#include<set>
#include<queue>
#include<algorithm>
#include<cassert>

using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define fr(i,c) for(__typeof(c.begin()) i=c.begin();i!=c.end();i++)
#define pb push_back
#define mp make_pair

int n,m;
bool v[10000];
vector<vector<pair<int,pair<int,int> > > > e;

int main(){
	while(scanf("%d%d",&n,&m),n)
	{
		e.clear(); e.resize(n);
		rep(i,m){
			int a,b,c,d; scanf("%d%d%d%d",&a,&b,&c,&d);
			a--; b--; e[a].pb(mp(b,mp(c,d))); e[b].pb(mp(a,mp(c,d)));
		}
		rep(i,n)v[i]=0; int ans=0;
		priority_queue<pair<pair<int,int>,int> > Q; Q.push(mp(mp(0,0),0));
		while(!Q.empty()){
			int cc=Q.top().first.first,cost=Q.top().first.second;
			int c=Q.top().second; Q.pop();
			
			if(v[c])continue; v[c]=1; ans-=cost;
			fr(i,e[c])if(!v[i->first])
			Q.push(mp(mp(cc-i->second.first,-i->second.second),i->first));
		}
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 2144
// Practice AtCoder
// author: Leonardone @ NEETSDKASU

// PDF解説読後

fn main() {
    let mut stdin = String::new();
    std::io::Read::read_to_string(&mut std::io::stdin(), &mut stdin).unwrap();
    let mut stdin = stdin.split_whitespace();
    let mut get = || stdin.next().unwrap();
    macro_rules! get {
        ($t:ty) => (get().parse::<$t>().unwrap());
        () => (get!(i64));
    }
    
    let h = get!(usize);
    let w = get!(usize);
    let mut ab = vec![vec![0; w]; h];
    for i in 0..2 {
        for y in 0..h {
            for x in 0..w {
                ab[y][x] += get!();
                ab[y][x] = -ab[y][x];
            }
        }
    }
    let size = 160 * 160 + 1;
    let mut dp = vec![vec![vec![false; size]; w]; h];
    dp[0][0][ab[0][0].abs() as usize] = true;
    for x in 1..w {
        for j in 0..size {
            if dp[0][x - 1][j] {
                let k = j as i64 + ab[0][x];
                dp[0][x][k.abs() as usize] = true;
                let k = j as i64 - ab[0][x];
                dp[0][x][k.abs() as usize] = true;
            }
        }
    }
    for y in 1..h {
        for j in 0..size {
            if dp[y - 1][0][j] {
                let k = j as i64 + ab[y][0];
                dp[y][0][k.abs() as usize] = true;
                let k = j as i64 - ab[y][0];
                dp[y][0][k.abs() as usize] = true;
            }
        }
        for x in 1..w {
            for j in 0..size {
                if dp[y][x - 1][j] || dp[y - 1][x][j] {
                    let k = j as i64 + ab[y][x];
                    dp[y][x][k.abs() as usize] = true;
                    let k = j as i64 - ab[y][x];
                    dp[y][x][k.abs() as usize] = true;
                }
            }
        }
    }
    for j in 0..size {
        if dp[h - 1][w - 1][j] {
            println!("{}", j);
            break;
        }
    }
}


Measured memory_bytes: 215292
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define all(obj) obj.begin(), obj.end()
#define db(x) cerr << #x << ":" << x << " "
#define dbl(x) cerr << #x << ":" << x << "\n"
#define dbv(vec) cerr << #vec << ":"; for (auto e : vec) cerr << e << " "; cout << "\n"
#define dbgvv(vv) cerr << #vv << ":\n"; for (auto vec : vv) { for (auto e : vec) cerr << e << " "; cerr << endl; }
#define YN(f) cout << (f ? "YES" : "NO") << endl
#define Yn(f) cout << (f ? "Yes" : "No") << endl
#define yn(f) cout << (f ? "yes" : "no") << endl
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;

int main () {
	int A, B; cin >> A >> B;
	cout << max(A - 2 * B, 0);	
}

Measured memory_bytes: 256
#include <vector> 
#include <list> 
 #include <map>
 #include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <limits.h>
using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

const LL mod=1e+9+7;

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << '=' << (x) << endl;
#define debug(x) cerr << #x << '=' << (x) << '('<<'L' << __LINE__ << ')' << ' ' << __FILE__ << endl;

int n,m;
int main(){
 
    uint64_t n_bikkuri=1,m_bikkuri=1;
    cin>>n>>m;

    if(n==m||n==m+1||n+1==m){

    }
    else{
        cout<<0<<endl;
        cerr<<"exit"<<endl;
        exit(0);
    }

    if(n>m){
        swap(n,m);
    }

    FOR(i,1,n+1){
        n_bikkuri*=i;
        n_bikkuri%=mod;
    }
    

    if(m-1==n){
        m_bikkuri=(n_bikkuri*m)%mod;
        n_bikkuri%=mod;
        m_bikkuri%=mod;
        debug(m_bikkuri);
        debug(n_bikkuri);
        
      
        cout<<(n_bikkuri*m_bikkuri)%mod;
    }
    else{
        m_bikkuri=n_bikkuri;
        n_bikkuri%=mod;
        m_bikkuri%=mod;
        debug(m_bikkuri);
        debug(n_bikkuri);
        
        cout<<2*(n_bikkuri*m_bikkuri)%mod;
    }



}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
const long long mod = 1e9 + 7;

int n, m;
vector<int> adj[N];
int c = 0;
bool vis[N];
void dfs(int v){
    c++;
    vis[v] = true;
    for(int u : adj[v]){
        if(!vis[u])
            dfs(u);
    }
}
void solve(){
    int i = 0;
    int mx = 0;
    for(i = 0; i < n; i++){
        if(!vis[i]){
            c = 0;
            dfs(i);
            mx = max(mx, c);
        }
    }
    cout << mx;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> m;
    int i = 0;
    for(i = 0; i < m; i++) {
        int x, y;
        cin >> x >> y;
        x--, y--;
        adj[x].push_back(y);
        adj[y].push_back(x);
    }
    solve();
    return 0;
}

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

/* macro */
#define rep(i,a,b) for(int i=a;i<b;i++)
#define revrep(i,a,b) for(int i = a; i > b; i--)
#define int long long
#define exist(s,e) ((s).find(e)!=(s).end())
#define all(v) (v).begin(), (v).end()
#define each(s,itr) for(auto (itr) = s.begin(); (itr) != s.end(); (itr)++)
#define sum(v) accumulate(all(v), (0LL))
#define isin(a, b, c) (b <= a && a <= c)
#define println cout << "\n";
#define sz(v) (int)v.size()


/* alias */
template<class T> using vec = vector<T>;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef tuple<int, int, int> ti;
typedef map<int, int> mi;
typedef set<int> si;


/* constant */
const int inf = 1LL << 62;
const int mod = 1e9 + 7;
const int dx[8]={1,0,-1,0,-1,1,-1,1};
const int dy[8]={0,1,0,-1,-1,-1,1,1};
const string alphabet = "abcdefghijklmnopqrstuvwxyz";

/* io_method */
int input(){int tmp;cin >> tmp;return tmp;}
string raw_input(){string tmp;cin >> tmp;return tmp;}
template<class T> void printx(T n){cout << n;}
template<class T, class U> void printx(pair<T, U> p){cout << "(" << p.first << "," << p.second << ")";}
template<class T, class U, class V> void printx(tuple<T, U, V> t){cout << "{" << get<0>(t) << "," << get<1>(t) <<"," << get<2>(t) << "}" << endl;}
template<class T> void printx(vector<T> v){cout << "{";rep(i,0,v.size()){printx(v[i]);if(i != v.size()-1)printx(",");}cout << "}";}
template<class T> void print(T n){printx(n);cout << endl;}
template<class T> void print(set<T> s){cout << "{";each(s, e){if(e != s.begin()) printx(",");printx(*e);}cout << "}" << endl;}
template<class T, class U> void print(map<T, U> mp){cout << "{";each(mp, e){cout << "(" << e -> first << "," << e -> second << ")";}cout << "}" << endl;}
template<class T> void printans(vec<T> v){rep(i,0,sz(v)){cout << v[i] << (i == sz(v) - 1 ? "" : " ");}cout << endl;}


/* general_method */
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class T>T cut(T &a, int l, int r){return T(a.begin()+l, a.begin()+r);}

/* main */

int n, ma, mb;
vec<ti> arr;
void in(){
    cin >> n >> ma >> mb;
    rep(i,0,n){
        int a, b, c;
        cin >> a >> b >> c;
        arr.push_back(ti(a, b, c));
    }
}
int dp[40][410][410];

bool isok(int a, int b){
    return (a > 0 && b > 0 && b * ma == mb * a);
}

int dfs(int i, int suma, int sumb){

    if(i == n) return (isok(suma, sumb) ? 0 : inf);

    if(dp[i][suma][sumb] > -1) return dp[i][suma][sumb];

    int ans = (isok(suma, sumb) ? 0 : inf);

    chmin(ans, dfs(i + 1, suma, sumb));

    int a = get<0>(arr[i]), b = get<1>(arr[i]), c = get<2>(arr[i]);

    chmin(ans, c + dfs(i + 1, suma + a, sumb + b));

    return dp[i][suma][sumb] = ans;

}

void solve(){

    memset(dp, -1, sizeof(dp));
    int ans = dfs(0, 0, 0);
    print(ans == inf ? -1 : ans);

}

signed main(){

    cin.tie(0);
    ios::sync_with_stdio(false);
    in();
    solve();
    
}

Measured memory_bytes: 52736
def chain(p,n):
    m={}
    for i in range(1,n+1):
        m[i] = {i:0}
        
    for l in range(2,n+1):
        for i in range(1,n-l+2):
            j = i + l -1
            m[i][j] = float("inf")
            for k in range(i,j):
                m[i][j] = min(m[i][j],m[i][k]+m[k+1][j] + p[i-1]*p[k]*p[j])
    print(m[1][n])

p={}
n = int(input())
for i in range(1,n+1):
    st = input()
    w = st.split()
    p[i-1] = int(w[0])
    p[i]   = int(w[1])
chain(p,n)

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

#define int long long

int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int N, A, B;
int X[100000];

signed main() {
    cin >> N >> A >> B;
    for (int i = 0; i < N; i++) {
        cin >> X[i];
    }
    int ans = 0;
    for (int i = 1; i < N; i++) {
        ans += min((X[i] - X[i - 1]) * A, B);
    }
    cout << ans << endl;
    return 0;
}


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

int main()
{
	int n;
	cin >> n;
	auto b = vector<int>(3);
	for(auto i = 0; i < n; ++i){
		int a;
		cin >> a;
		int cnt = 0;
		if(a % 2 == 0){
			++cnt;
			if((a / 2) % 2 == 0){
				++cnt;
			}
		}
		++b[cnt];
	}
	if(b[1] > 0){
		b[1] = 0;
		++b[0];
	}
	cout << (b[0] < b[2] + 2 ? "Yes" : "No") << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(i,a,b) for(int i=(a); i<=(b); i++) 
#define rep(i,n); for(int i = 0; i < (n); i++)
#define chmin(a,b) if((a)>(b)) (a)=(b); 
#define chmax(a,b) if((a)<(b)) (a)=(b);
#define vi vector<int>
#define all(v) (v).begin(),(v).end()
#define pb push_back
int gcd(int a,int b){/*a>=0,b>=0,￢(a=b=0)*/
  while(min(a,b)>0){if(a<b)swap(a,b);a%=b;}return max(a,b);
}
int dx[]={0,1,0,-1,1,-1,-1,1};
int dy[]={1,0,-1,0,1,1,-1,-1};
const int MOD = 1e9+7;
const int INF = 1e18+10;

/*----------------------------------------------*/

signed main(){
  int n;
  cin>>n;
  vi odd,even;
  rep(i,n){
    int a;
    cin>>a;
    if((i+1)%2==1) odd.pb(a);
    else even.pb(a);
  }
  if(n%2==1){
    reverse(all(odd));
    rep(i,odd.size()) cout<<odd[i]<<" ";
    rep(i,even.size()) cout<<even[i]<<" ";
    cout<<endl;
  }else{
    reverse(all(even));
    rep(i,even.size()) cout<<even[i]<<" ";
    rep(i,odd.size()) cout<<odd[i]<<" ";
    cout<<endl;
  }

  return 0;
}


Measured memory_bytes: 3948