akhauriyash/Code-Regression huggingface dataset:
#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(){
    ll n,k;
    cin >> n >> k;
    vector <ll> a(n);
    ll go=0;
    rep(i,n){
        cin >> a[i];
        go+=a[i];
    }

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

    priority_queue <ll> q;

    for (ll i=1; i*i<=go; ++i){
        if(go%i==0){
            q.push(i);
            q.push(go/i);
        }
    }

    ll qq;
    ll k2=0,k3;
    ll wa=0;
    ll ans;
    vector <ll> pl,pl2;
    while(q.size()!=0){
        qq=q.top();
        q.pop();
        
        wa=0;
        k2=0;
        pl=pl2;
        rep(i,n){
            if(a[i]%qq!=0){
            k2+=qq-(a[i]%qq);
            pl.push_back(qq-(a[i]%qq));
            wa+=(a[i]/qq+1)*qq;
            }
            else{
                wa+=a[i];
                pl.push_back(0);
            }
        }
        sort(pl.rbegin(),pl.rend());
        k3=(wa-go)/qq;
        rep(i,k3){
            k2-=pl[i];
        }

        //cout << qq << " " << k2 << endl;
        if(k2<=k){
            ans=qq;
            break;
        }

    }

    cout << ans << endl;
    

    return 0;
}

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

#define INPUT freopen("input.txt", "r", stdin);

#define ll long long
#define ld long double

#define len(s) s.size()

#define fl(st, en, in) for (int i = st; i < en; i += in)
#define rfl(st, en, de) for (int i = st; i < en; i -= de)
#define fll fl(0, n, 1)
#define ifl(st, en, in) for (int j = st; j < en; j += in)

#define cy cout << "Yes" << endl;
#define cn cout << "No" << endl;
#define ci(s) cin >> s
#define co(s) cout << s << endl

#define vl vector<ll>
#define pb(x) push_back(x)

#define ms(arr, x) memset(arr, x, sizeof(arr))

#define inf INT_MAX

void solve()
{

    string s1, s2;
    cin >> s1 >> s2;
    ll ans = inf;

    fl(0, len(s1) - len(s2) + 1, 1)
    {
        ll cnt = 0;
        ifl(0, len(s2), 1)
        {
            if (s1[i + j] != s2[j])
                cnt++;
        }
        //co(cnt);
        ans = min(ans, cnt);
    }
    co(ans);
}

int main()
{
    // INPUT;
    // int t;
    // ci(t);
    // while (t--)
        solve();
}

Measured memory_bytes: 3588
Module Program
  Sub Main
    Dim s=GetInts()
    Dim a=s(0),b=s(1)
    Dim ans=Math.Max(0,a-b)
    Console.WriteLine(ans)
  End Sub
  
  '/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
  Function Gets() As String()
    Gets = Console.ReadLine().Split(" "c)
  End Function
  Function GetInts() As Integer()
    Dim s = Gets(), r(UBound(s)) As Integer
    For i As Integer=0 To UBound(s): r(i)=s(i): Next i
    GetInts = r
  End Function
End Module

Measured memory_bytes: 22352
#include "bits/stdc++.h"

#define rep(i, a) for (int i = 0; i < (a); ++i)
#define REP(i, a, b) for (int i = (a); i < (b); ++i)
#define vi vector<int>

#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0, a1, a2, a3, a4, x, ...) x
#define debug_1(x1) cerr << #x1 << ": " << x1 << endl
#define debug_2(x1, x2) cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << endl
#define debug_3(x1, x2, x3) cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " << x3 << endl
#define debug_4(x1, x2, x3, x4) cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " << x3 << ", " #x4 << ": " << x4 << endl
#define debug_5(x1, x2, x3, x4, x5) cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " << x3 << ", " #x4 << ": " << x4 << ", " #x5 << ": " << x5 << endl
#define debug(...) CHOOSE((__VA_ARGS__, debug_5, debug_4, debug_3, debug_2, debug_1, ~)) (__VA_ARGS__)

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

struct sgs {
  ll val;
  bool t;
  bool f;
  bool s;
  sgs(int v, bool t=false, bool f=false, bool s=false): val(v), t(t), f(f), s(s) {}
  bool ok() {
    return t && f && s;
  }
  sgs add3() {
    sgs res(*this);
    res.val = 10*res.val + 3;
    res.t = true;
    return res;
  }
  sgs add5() {
    sgs res(*this);
    res.val = 10*res.val + 5;
    res.f = true;
    return res;
  }
  sgs add7() {
    sgs res(*this);
    res.val = 10*res.val + 7;
    res.s = true;
    return res;
  }
};

void Main() {
  int n;
  cin >> n;
  int ten = 0;
  {
    int m = n;
    while(m/=10) ten++;
  }
  int ans = 0;
  queue<sgs> q;
  q.emplace(0);
  while(1) {
    sgs x = q.front(); q.pop();
    if (x.val > n) break;
    q.push(x.add3());
    q.push(x.add5());
    q.push(x.add7());
    if (x.ok()) ans++;
  }
  cout << ans << endl;
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}


Measured memory_bytes: 1280
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>


// #define INT_MAX 2147483647
// #define LL_MAX 9223372036854775807

using namespace std;
#define i64  long long

void solve(void)
{
  vector<int> vec(3,0);
  for (int i = 0; i < 3; i++)
  {
    cin>>vec[i];
  }

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

  cout<<vec[0]<<" "<<vec[1]<<" "<<vec[2]<<endl;  
  
  
  return;
}
int main(int argc, const char *argv[])
{

  solve();

  return 0;
}



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

int main(){
  int a,b;
  cin >> a >> b;
  int max;
  if(a>b){
    cout << a+a-1 << endl;
  }else	if(a<b){
    cout << b+b-1 << endl;
  }else	if(a==b){
    cout << a+a	<<endl;
  }


}

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

int main(){
  int N,T;
  cin>>N>>T;
  vector<pair<int,int>> vec(N);
  
  for(int i=0;i<N;i++)
    cin>>vec.at(i).first>>vec.at(i).second;
  
  sort(vec.begin(),vec.end());
  
  for(int i=0;i<N;i++){
    if(vec.at(i).second<=T){
      cout<<vec.at(i).first<<endl;
      return 0;
    }
  }
  cout<<"TLE"<<endl;
}


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

int main()
{
  int64_t S, x, y;
  cin >> S;
  if (S % 1000000000 == 0)
  {
    x = 0;
    y = S / 1000000000;
  }
  else
  {
    int64_t q = S / 1000000000, r = S % 1000000000;
    y = q + 1;
    x = 1000000000 - r;
  }
  cout << 0 << ' ' << 0 << ' ' << 1000000000 << ' ' << 1 << ' ' << x << ' ' << y << endl;
}


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

int main() {
    ll n;
    cin >> n;
    map<ll, ll> mp;
    vector<ll> vec;
    rep(i, n){
        ll num;
        cin >> num;
        vec.push_back(num);
        mp[num]++;
    }
    ll sum = 0;
    for(ll i=1; i<=n; i++){
        sum += mp[i]*(mp[i]-1)/2;
    }
    rep(i, n){
      	ll before = (mp[vec[i]]*(mp[vec[i]]-1)/2);
      	ll after = ((mp[vec[i]]-1)*(mp[vec[i]]-2)/2);
        cout << sum - (ll)(mp[vec[i]]*(mp[vec[i]]-1)/2) + after << endl;
    }
    return 0;
}


Measured memory_bytes: 16624
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <map>
#include <functional>
#include <array>

using namespace std;

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

    int64_t ans = 0;
    for(int i = 0; i < N; ++i){
        int A;
        cin >> A;
        int64_t cnt = 0;
        while(A % 2 == 0){
            A /= 2;
            cnt++;
        }
        ans += cnt;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		char c[] = sc.next().toCharArray();
		if ((c[0]==c[1]&&c[1]==c[2])||(c[2]==c[3]&&c[1]==c[2])) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 23764
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <unordered_set>
#include <cassert>
#include <array>
#include <random>
#include <iomanip>
#include <math.h>
#include <stack>
#include <bitset>

using namespace std;

typedef long long ll;

const int INF = 1000000010;
const ll INFLL = 1000000000000000010;
const int LOGN = 16;
const int N = 1000010;
const int K = 101;

mt19937 gen(29);

signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
#ifdef _DEBUG
	freopen("Test.txt", "r", stdin);
#endif
	int k, x;
	cin >> k >> x;
	if (500 * k >= x)
		cout << "Yes";
	else
		cout << "No";
	return 0;
}

Measured memory_bytes: 256
<?php
list($a, $b, $k) = explode(" ", trim(fgets(STDIN)));
for($i = 0; $i < $k; $i++){
  $a = floor($a/2)*2;
  $a/=2;
  $b+=$a;
  $i++;
  if($i==$k)break;
  $b = floor($b/2)*2;
  $b/=2;
  $a+=$b;
}
echo "$a $b\n";


Measured memory_bytes: 4856
"""
Bellman-Ford
始点と終点が決められているとき、
経由する閉路のみを確認する必要がある。
"""
def Bellman_Ford2(g,start,goal):
    n = len(g)    
    dist = [float("inf")]*n
    dist[start] = 0
    a0 = float("inf")
    for i in range(2*n):
        updated = False
        for v in range(n):
            for to, cost in g[v]:
                if dist[to] <= dist[v] + cost: continue
                if i < n:
                    dist[to] = dist[v] + cost
                else:
                    dist[to] = -float("inf")
                updated = True
        if not updated: break
    if dist[goal] == -float("inf"): return None, False
#    if negative[-1]: return None, False
    return dist, True
 

import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline #文字列入力のときは注意

n,m,p = [int(i) for i in readline().split()]
g = [[] for _ in range(n)]
for i in range(m):
    a,b,c = [int(i) for i in readline().split()]
    g[a-1].append((b-1,-c+p))
#    g[b-1].append((a-1,c))

dist, TF = Bellman_Ford2(g,0,-1)

if TF: print(max(-dist[-1],0))
else: print(-1)

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

  ll n,temp;
  cin>>n;
  char ch;
  string t;
  while(n>0)
   {
   	temp=n%26;
   	if(temp==0)
   	ch='z';
   	else
   	ch=temp+96;
   	
   	t=t+ch;
   	n=n-1;
   	n=n/26;
   }
   ll length=t.size();
   for(ll i=length-1;i>=0;i--)
   cout<<t[i];
   cout<<endl;

}

Measured memory_bytes: 3620
COM_UNITE = 0
COM_SAME = 1


class UnionFindTree():
    def __init__(self, n):
        self.parent = [i for i in range(n)]
        self.rank = [0] * n

    def find(self, x):
        if self.parent[x] == x:
            return x
        else:
            self.parent[x] = self.find(self.parent[x])
            return self.parent[x]

    def unite(self, x, y):
        x, y = self.find(x), self.find(y)

        if x == y:
            return

        if self.rank[x] < self.rank[y]:
            self.parent[x] = y
        else:
            self.parent[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    def same(self, x, y):
        return self.find(x) == self.find(y)


if __name__ == '__main__':
    n, q = (int(s) for s in input().split())
    tree = UnionFindTree(n)

    for i in range(q):
        com, x, y = (int(s) for s in input().split())
        if com == COM_UNITE:
            tree.unite(x, y)
        elif com == COM_SAME:
            print(int(tree.same(x, y)))

Measured memory_bytes: 7000
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    sys.setrecursionlimit(10**7)
    INF = 10**8
    MOD = 10**9 + 7
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]
    _LI = lambda : [int(x)-1 for x in sys.stdin.readline().split()]
    NI = lambda : int(sys.stdin.readline())

    N,M,R = LI()
    r = _LI()
    root = [[] for _ in range(N)]
    for _ in range(M):
        a,b,c = LI()
        root[a-1].append((b-1,c))
        root[b-1].append((a-1,c))

    memo = [[0] * N for _ in range(N)]

    min_r = INF
    for x in itertools.permutations(r):
        it = 0
        s = x[0]
        for t in x[1:]:
            if memo[s][t]:
                it += memo[s][t]
            else:
                node = [INF] * N
                q = collections.deque()
                q.append((s,0))
                node[s] = 0
                while q:
                    u,l = q.popleft()
                    for v,m in root[u]:
                        if node[v] > l + m:
                            node[v] = l + m
                            q.append((v,l+m))
                memo[s][t] = node[t]
                memo[t][s] = node[t]
                it += node[t]
            s = t
        min_r = min(min_r,it)
    print(min_r)

if __name__ == '__main__':
    main()

Measured memory_bytes: 45144
def do_selection_sort(data, size):
    assert size == len(data), "data size error"
    swap_count = 0
    for i in range(size):
        minj = i
        for j in range(i, size):
            if data[j] < data[minj]:
                minj = j
        temp = data[i]
        data[i] = data[minj]
        data[minj] = temp
        if data[i] != data[minj]:
            swap_count += 1
    return swap_count


if __name__ == '__main__':
    # ??????????????\???
    num = int(input())
    data = [int(x) for x in input().split(' ')]
    #data = [5, 6, 4, 2, 1, 3]
    #data = [5, 2, 4, 6, 1, 3]

    # ???????????????
    result = do_selection_sort(data, num)

    # ???????????????
    print('{0}'.format(' '.join(map(str, data))))
    print('{0}'.format(result))

Measured memory_bytes: 7732
import sys
input=sys.stdin.readline

n,m=map(int,input().split())
inf=10**9+7
dp=[inf]*(2**n)
dp[0]=0

for i in range(m):
    a,b=map(int,input().split())
    C=list(map(int,input().split()))
    bit=0
    for i in C:
        bit|=(1<<(i-1))
    for j in range(2**n):
        dp[j|bit]=min(dp[j|bit],dp[j]+a)

if dp[-1]>=inf:
    print(-1)
else:
    print(dp[-1])

Measured memory_bytes: 42860
import java.util.*;


public class Main {
	
	static long f[] ;
	static void init() {
		f = new long[100005];
		f[0] = 1 ;
		for(int i = 1 ; i < f.length ; i++)
			f[i] = (f[i-1] * i) % m ;
	}
static long m = 1000 * 1000 * 1000 + 7 ;
	
	static long add(long a, long b)
	{
		return (a % m + b % m + m) % m;
	}
	
	static long mul(long a, long b)
	{
		return ((a % m) * (b % m)) % m;
	}
	static long nCr(int n, int r){
		if(r > n) return 0 ;
		long den = (f[n - r] * f[r]) % m ;
		return (f[n] * euInv(den, m)) % m ;
	}
	static long nPr(int n, int r){
		if(r > n) return 0 ;
		long den = f[r];
		return (f[n] * euInv(den, m)) % m ;
	}
	
	static long euInv(long a, long mod)
	{
		long[] A = new long[100];
		long[] B = new long[100];
		long b = mod, c = 0;
		int p = 0;
		while(b > 0)
		{
			A[p] = a;
			B[p] = b;
			c = a;
			a = b;
			b = c % b;
			p = p + 1;
		}
		long x = 1, y = 0;
		
		while(p-- > 0)
		{
			c = x;
			x = y;
			y = c - (A[p] / B[p]) * y;
		}
		return (x + mod) % mod;
	}
	

	public static void main(String[] args) {

		Scanner s = new Scanner(System.in);
		
		int n = s.nextInt();
		int k = s.nextInt();
		init();
		System.out.println(n-k+1);
		for(int i = 2;i<=k;i++)
		{
			System.out.println(mul(nCr(n-k+1, i), nCr(k-1,i-1)));
		}
		
		
	}
}


Measured memory_bytes: 26576
#include "bits/stdc++.h"

using namespace std;

const int N = 5e5 + 5;

int a[N], p[N], s[N];

signed main(){
	#ifdef LOCAL
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int a,n;
	cin>>a>>n;
	int s=0,x;
	for(int i=0;i<n;i++)
		cin>>x,s=s+x;
	if(s>=a)cout<<"Yes";
	else cout<<"No";
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		StringBuilder output = new StringBuilder();
		
		int n = scan.nextInt();
		long[] a = new long[n];
		for (int i = 0; i < n; i++) {
			a[i] = scan.nextLong();
		}
		for (int i = n-1; i > 0; i--) {
			output.append(a[i]).append(" ");
		}
		output.append(a[0]);
		System.out.println(output);
	}

}

Measured memory_bytes: 18104
n = int(input())
ans = [1]*n
T = [[-1]*n for _ in range(n)]
for ni in range(n):
    a = int(input())
    for ai in range(a):
        x, y = map(int,input().split())
        T[ni][x-1] = y

mx = 0
for i in range(pow(2,n)):
    tmx = -1
    B = bin(i)[2:].zfill(n)
    S = [i for i,b in enumerate(B) if b=='1']
    for s in S:
        _Ts = [i for i,t in enumerate(T[s]) if t==1]
        _Tf = [i for i,t in enumerate(T[s]) if t==0]
        if not (set(_Ts)<=set(S) and set(_Tf)&set(S)==set()):
            tmx = 0
            break
    if tmx==-1: tmx=len(S)
    mx = max(mx, tmx)
print(mx)

Measured memory_bytes: 9228
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define cyes cout<<"YES"<<endl
#define cno cout<<"NO"<<endl
#define sp <<" "<<
#define CST(x) cout<<fixed<<setprecision(x)
#define PI 3.14159265359
#define MOD 1000000007
using namespace std;
using ll = long long;
using ld = long double;
using Graph = vector<vector<int>>;
using que_a = priority_queue<int, vector<int>, greater<int> >;
using que_d = priority_queue<int>;
using pint = pair<int,int>;

int main(){

    int h,w;

    while(true){
        
        cin >> h >> w;
        if(h == 0 && w == 0) return 0;
        
        rep(i,h){
            if(i%2 == 0){
                rep(j,w){
                    if(j%2 == 0) cout << '#';
                    else cout << '.';
                }
                
            }
            else{
                rep(j,w){
                    if(j%2 == 0) cout << '.';
                    else cout << '#';
                }
                
            }
            cout << endl;
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3080
#include<map>
#include<iostream>
#include<deque>
#include<algorithm>
#include<string>
#include<cctype>
#include<iomanip>
#include<vector>
#include<queue>
#include<math.h>
#include<bitset>
#include<random>
 
using namespace std;
#define REP(i,b,e) for(ll i=(ll)b;i<(ll)e;i++)
#define rep0(i,n) REP(i,0ll,n)
#define rep1(i,n) REP(i,1ll,n+1)
 
#define shosu setprecision(17)
 
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<char,P> Q;
//ll longinf=1ll<<60;
int inf=1<<29;
ll longinf=(1ll<<60);

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

signed main(){
    ll N,W;
    cin>>N>>W;
    ll w[N+1],v[N+1];
    rep1(i,N){
        cin>>w[i]>>v[i];
    }
    ll V=N*1000;
    ll dp[N+1][V+1];
    ll ans=0;
    ll accum[N+1];
    accum[0]=0;
    rep1(i,N){
        accum[i]=accum[i-1]+v[i];
    }
    rep0(i,N+1) rep0(j,V+1) dp[i][j]=longinf;
    rep0(i,N+1) dp[i][0]=0;
    rep1(i,N){
        rep0(j,V+1){
            if(j<=v[i]){
                dp[i][j]=min(dp[i-1][j],dp[i-1][0]+w[i]);
            }
            else if(j<=accum[i]){
                dp[i][j]=min(dp[i-1][j],dp[i-1][j-v[i]]+w[i]);
            }
            else{
                dp[i][j]=dp[i-1][j];
            }
        }
    }
    rep0(j,V+1){
        if(dp[N][j]<=W){
            ans=j;
        }
         //cout<<dp[N][j]<<" ";
    }
    //cout<<endl;
    cout<<ans<<endl;

    return 0;
}


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


int n;
long long int ans;
long long int mod=998244353;
int x;

long long int pow(int a,int b){
    //cout<<a<<" "<<b<<endl;
    if(b==0){
        return 1;
    }
    if(b==1){
        return a;
    }
    long long int res;
    res=pow(a,b/2)*pow(a,b/2)%mod;
    if(b%2==1){
        res*=a;
    }
    return res%mod;
}

int main(){
    ans=0;
    cin>>n;
    for (int i=0; i<n; i++){
        cin>>x;
        long long int temp;
        temp=pow(1+x, i)%mod*pow(2,n-i-1)%mod;
        temp*=x;
        temp%=mod;
        //cout<<temp<<endl;
        ans+=temp;
        ans%=mod;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3120
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long
vector<int>graph[100001];
int dp[100001];
int solve(int src)
{
if(dp[src]!=-1)
return dp[src];
int leaf=1,best=0;
for(auto it:graph[src])
{
leaf=0;
best=max(best,solve(it));
}
return dp[src]=leaf?0:1+best;

}
int main() {
	//code


	    int n,m,a,b;
	    cin>>n>>m;
memset(dp,-1,sizeof(dp));
	    for(int i=0;i<m;i++)
	    {
	    cin>>a>>b;
	        graph[a].push_back(b);
	    }
	    int ans=0;
	    for(int i=1;i<=n;i++)
        {
            ans=max(ans,solve(i));

        }
        cout<<ans<<endl;
	}



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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,a,b) for(int i=a;i<b;i++)
#define each(it,v) for(auto it : v)
#define mod 1000000007
#define all(v) (v).begin(),(v).end()
#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define vpii vector<pair<int,int>>
#define vv vector<vector<int>>
using namespace std;

main()
{
        int h,w; cin>>h>>w;
        int c[10][10];
        rep(i,10)rep(j,10)cin>>c[i][j];
        rep(k,10)rep(i,10)rep(j,10)c[i][j]=min(c[i][j],c[i][k]+c[k][j]);
        int ans=0,x;
        rep(i,h*w)
        {
                cin>>x;
                if(x==-1)continue;
                ans+=c[x][1];
        }
        cout<<ans<<endl;
}


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

int main() {
  int a, b, ps= 1, ans = 0;
  cin >> a >> b;
  while (true) {
    if (ps >= b) break;
    else {
      ps = ps + a - 1;
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
ll h[150000],dp[150000];

ll f(ll n)
{  
  if(dp[n]!=-1)
    return dp[n];
  dp[n] = min(f(n+1)+abs(h[n+1]-h[n]),f(n+2)+abs(h[n+2]-h[n]));
  return dp[n];
}

main()
{ ll n;
  cin>>n;
  for(ll i=1;i<=n;i++)
  {cin>>h[i];
   dp[i]=-1;}
 dp[n-1] = abs(h[n]-h[n-1]);
 dp[n]=0;
 
  cout<<f(1);
}


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

using namespace std;
#define ll long long
#define ld long double
#define PI 3.141592653L
#define F first;
#define S second;
#define MP make_pair;
const ll INF = (ll)1e18;
const int N = 2e5 + 5;
const ll MOD = 1e9 + 7;

int parent[N];

int gcd(int a, int b) { 
    if (a == 0) 
        return b;  
    return gcd(b%a, a);  
} 
   
int lcm(int a, int b) {  
    return (a*b)/gcd(a,b);  
} 

ll pow(ll x, ll y, ll p) {
    if(y == 0) return 1;
    ll res = 1;
    x %= p;
    if(x == 0) return 0LL;
    while(y > 0) {
        if(y & 1) res = (res*x) % p;
        y >>= 1;
        x = (x*x) % p;
    }
    return res;
}

int find(int x) {
    return x == parent[x] ? x : parent[x] = find(parent[x]);
}

int main()
{
    ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
    ll q, h, s, d, n;
    cin >> q >> h >> s >> d >> n;
    h = min(2*q,h);
    s = min(2*h,s);
    ll res = 0;
    if(2*s<d) {
        res = n*s;
    }
    else {
        res = n/2*d + n%2*s;
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
int main(){
  long int A,B,V,W,T,d,l;
  scanf("%ld %ld",&A,&V);
  scanf("%ld %ld",&B,&W);
  scanf("%ld",&T);
  if(V<=W){
    printf("NO");
    return 0;
  }
  d=abs(A-B);
  l=(V-W)*T;
  if(l>=d) printf("YES");
  else printf("NO");
  return 0;
}

Measured memory_bytes: 1732
#include<iostream>
#include<climits>
#include<cstring>
using namespace std;
#define ll long long int

ll profit = 0;

ll maxProfit(ll weight[], ll value[], ll n, ll w, ll idx, ll mem[105][100005]) {

	if (idx >= n || w == 0)
		return 0;

	if (mem[idx][w] != -1)
		return mem[idx][w];



	ll profit1 = INT_MIN;
	if (weight[idx] <= w) {
		profit1 = value[idx] + maxProfit(weight, value, n, w - weight[idx], idx + 1, mem);
	}

	ll profit2 = maxProfit(weight, value, n, w, idx + 1, mem);

	//cout<<profit1<<" "<<profit2;

	profit = max(profit1, profit2);
	mem[idx][w] = profit;

	return profit;
}

ll tabulation(ll value[], ll weight[], ll idx, ll capacity, ll size) {

	ll dp[size + 1][capacity + 1];
	memset(dp,0,sizeof dp);
	for (int i = 0; i <= size; i++) {
		for (int j = 0; j <= capacity; j++) {
			if (i == 0 || j == 0){
				dp[i][j] = 0;
				continue;
			}
			if(j>=weight[i-1]){
			ll curPlay = value[i - 1];
			ll scoreIfInclude = curPlay + dp[i - 1][j - weight[i - 1]];
			ll scoreWithout = dp[i - 1][j];
			dp[i][j] = max(scoreWithout, scoreIfInclude);
			}else{
				dp[i][j] = dp[i-1][j];
			}
		}
	}
	return dp[size][capacity];

}



int main() {
	ll weight[105];
	ll n, w;
	cin >> n >> w;
	ll value[105];

	for (int i = 0; i < n; i++) {
		ll w1, v1;
		cin >> w1 >> v1;
		weight[i] = w1;
		value[i] = v1;
	}

	ll mem[105][100005];
	memset(mem, -1, sizeof mem);

	//cout << maxProfit(weight, value, n, w, 0, mem) << endl;
	cout << tabulation(value, weight, 0, w, n) << endl;







	return 0;
}

Measured memory_bytes: 82336
#include <iostream>

int main(int argc, const char * argv[]) {
    
    int a, b, c ;
    
    std::cin >> a >> b >> c ;
    
    int count = 0;
    
    
    for (int i=a; i<=b; i++) {
        count += (c%i == 0) ;
    }
    
    printf("%d\n", count) ;
    
    return 0;
}


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

int main(){
  long long n,k,a;
  queue<long long> line;
  cin >> n >> k;
  for(int i=0;i<k;i++){
    cin >> a ;
    line.push(a);
  }
  for(int i=0;i<n-k;i++){
    cin >> a ;
    line.push(a);
    if(line.front() < a){
      cout << "Yes" << endl;
    } else {
      cout << "No"<< endl;
    }
    line.pop();
  }
}

Measured memory_bytes: 5272
n,m=map(int,input().split())
a,M,d=1,10**9+7,[1]*(n+1)
for i in range(n):
  d[i+1]=((m-n+i)*d[i]+i*d[i-1])%M
  a=a*(m-i)%M
print(a*d[-1]%M)

Measured memory_bytes: 28328
#include <iostream>
#include <vector>
#include <queue>
#include<map>
#include<algorithm>
#include<set>
#include<iomanip>
#define rep(i,n) for(int i = 0;i < n;i++)
#define req(i,n) for(int i = 1; i<=n;i++)
#define rrep(i,n) for(int i = n-1;i >=0;i--)
#define ALL(a) a.begin(),a.end()
#define PI  acos(-1)
using namespace std;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T & val) {
    std::fill((T*)array, (T*)(array + N), val);
}
typedef long long int ll;
typedef long double ld;
const int MOD = 1e9 + 7;
int dx[4] = { 0,0,1,-1 }, dy[4] = { 1,-1,0,0 }, sum = 0,h,w;
struct UnionFind {
    vector<int> par, sz;
    UnionFind(int n) :par(n), sz(n) {
        rep(i, n) par[i] = i, sz[i] = 0;
    }
    int root(int x) {
        if (par[x] == x) return x;
        return root(par[x]);
    }
    bool unite(int x, int y) {
        if (root(x) == root(y)) return 0;
        par[root(x)] = root(y);
        return 1;

    }bool same(int x, int y) {
        return root(x) == root(y);
    }
};
int main() {
    int n, m,a,b; cin >> n >> m; vector<pair<int,int>> G;
    rep(i, m) {
        cin >> a >> b; a--; b--;
        G.push_back({ a,b });
    }int ans = 0;
    rep(i, m) {
        UnionFind uf(n);
        rep(j, m) {
            if (j == i) continue;
            uf.unite(G[j].first, G[j].second);
        }bool f = 0;
        rep(j, n) {
            for (int k = j + 1; k < n; k++) {
                if (uf.same(j, k)) continue;
                ans++; f = 1; break;
            }if (f) break;
        }
    }cout << ans << endl;
}

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

public class Main {

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

		int n = Integer.parseInt(br.readLine());
		String str[] = br.readLine().split("");

		String last = str[0];
		int ans = 1;

		for (int i = 1; i < n; i++) {
			if (last.equals(str[i])) {

			} else {
				last = str[i];
				ans++;
			}
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 29524
#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma comment(linker, "/stack:200000000")

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;

#define X first
#define Y second

//#include <boost/unordered_map.hpp>
//using namespace boost;

/*
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> rbtree;
rbtree T;
*/

namespace io{
	const int L = (1 << 20) + 1;

	char buf[L], *S , *T, c;

	char getchar() {
		if(__builtin_expect(S == T, 0)) {
			T = (S = buf) + fread(buf, 1, L, stdin);
			return (S == T ? EOF : *S++);
		}
		return *S++;
	}

	int inp() {
		int x = 0, f = 1; char ch;
		for(ch = getchar(); !isdigit(ch); ch = getchar())
			if(ch == '-') f = -1;
		for(; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
		return x * f;
	}

	unsigned inpu()
	{
		unsigned x = 0; char ch;
		for(ch = getchar(); !isdigit(ch); ch = getchar());
		for(; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
		return x;
	}

	ll inp_ll() {
		ll x = 0; int f = 1; char ch;
		for(ch = getchar(); !isdigit(ch); ch = getchar())
			if(ch == '-') f = -1;
		for(; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
		return x * f;
	}

	char B[45], *outs=B+40, *outr=B+40;
	template<class T>
	inline void print(register T a,register char x=0){
		if(x) *--outs = x, x = 0;

		if(!a)*--outs = '0';
		else
			while(a)
				*--outs = (a % 10) + 48, a /= 10;

		if(x)
			*--outs = x;

		fwrite(outs, outr - outs , 1, stdout);
		outs = outr;
	}
};

using io :: print;
using io :: inp;
using io :: inpu;
using io :: inp_ll;

using i32 = int;
using i64 = long long;
using u8 = unsigned char;
using u32 = unsigned;
using u64 = unsigned long long;
using f64 = double;
using f80 = long double;
//using i128 = __int128_t;
//using u128 = __uint128_t;
using i128 = i64;
using u128 = u64;

ll power(ll a, ll b, ll p)
{
	if (!b) return 1;
	ll t = power(a, b/2, p);
	t = t*t%p;
	if (b&1) t = t*a%p;
	return t;
}

ll exgcd(ll a, ll b, ll &x, ll &y)
{
	if (b == 0)
	{
		x = 1;
		y = 0;
		return a;
	}
	ll px, py;
	ll d = exgcd(b, a%b, px, py);
	x = py;
	y = px-a/b*py;
	return d;
}

template<class T>
inline void freshmin(T &a, const T &b)
{
	if (a > b) a = b;
}

template<class T>
inline void freshmax(T &a, const T &b)
{
	if (a < b) a = b;
}

const int MOD = 1000000007;
const int INF = 1000000000;
const int MAXN = 100010;

int n;
int a[MAXN], p[MAXN];

int main()
{
	
	for (int i = 0; i < 5; ++ i)
	{
		cin >> a[i];
		p[i] = i;
	}
	int ans = INF;
	while (1)
	{
		int cur = 0;
		for (int i = 0; i < 5; ++ i)
			cur = (cur/10+(cur%10 != 0))*10+a[p[i]];
		ans = min(ans, cur);
		if (!next_permutation(p, p+5)) break;
	}
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define rep2(i,n) for(int i=0;i<=n;i++)
#define repr(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<long long,long long>
#define double long double
#define vector2(a,b,c) vector<vector<int>> a(b/*縦！w*/,vector<int>(c/*横！w*/))
#define INF 1e10
#define MOD 1e9+7
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using Graph = vector<vector<int>>;
signed main(){
  string a;
  cin>>a;
  int b=0,c=0;
  rep(i,a.size()){
  if(a[i]=='W'){
    b+=i+1;
  c++;
  }
  }
  cout<<b-(1+c)*c/2<<endl;
    
}

Measured memory_bytes: 640
using System;
class Hello{
	public static void Main(){
		string input = Console.ReadLine();
		string inputtimes = Console.ReadLine();
		int times = Int32.Parse(inputtimes);
		string[] split = input.Split(' ');
		int[] array = new int [split.Length];
		int max = 0;
		int sum = 0;
		for(int count = 0;count < split.Length;count++){
			array[count] = Int32.Parse(split[count]);
			sum = sum + array[count];
			if(array[count] > max){
				max = array[count];
			}
		}
		int exmax = max;
		for(int i = 0;i < times;i++){
			max = max * 2;
		}
		int result = max + sum - exmax;
		Console.WriteLine(result);
	}
}


Measured memory_bytes: 11092
#include <iostream>
#include <vector>
#include <string.h>
#include <math.h>
using namespace std;

int main(void)
{
    int h, w, k; cin >> h >> w >> k;
    vector<vector<int>> c(h, vector<int>(w, 0));
    string t;
    for (int i = 0; i < h; i++)
    {
        cin >> t;
        for (int j = 0; j < w; j++)
        {
            if (t[j]=='#') c[i][j]++;
        }
    }
    int bh = pow(2, h);
    int bw = pow(2, w);
    int ans = 0;
    int sum;
    int _i, _j;
    for (int b1 = 0; b1 < bh; b1++)
    {
        for (int b2 = 0; b2 < bw; b2++)
        {
            sum = 0;
            _i = b1;
            for (int i = h-1; i >= 0; i--)
            {
                _j = b2;
                if (_i / (int)pow(2, i)==0)
                {
                    for (int j = w-1; j >= 0; j--)
                    {
                        if (_j / (int)pow(2, j)==0) sum += c[i][j];
                        _j = _j % (int)pow(2, j);
                    }
                }
                _i = _i % (int)pow(2, i);
            }
            if (sum == k) ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 4112
using System;
using System.Collections.Generic;
using System.Linq;
using System.Diagnostics;

class Program
{
    static void Main(string[] args)
    {
        string[] cin = Console.ReadLine().Split();
        int n = int.Parse(cin[0]);
        int m = int.Parse(cin[1]);
        int s = int.Parse(cin[2]);

        // 始点からの距離dist（初期値は無限。後でdist[始点]だけ0にする）
        // 配列やListは参照型なので普通に引数にした場合(値渡し)
        // 引数にしたdistは戻り値にしなくても結果を受け取れる
        long[] dist = new long[n];
        for (int i = 0; i < n; i++)
            dist[i] = long.MaxValue;

        // Bellman_ford(頂点数,始点,辺の数,dist)
        // 戻り値はbool[n]で始点→各頂点の途中に負閉路が存在するか(存在すればtrue)
        bool[] negative = Bellman_ford(n, s, m, dist);

        // 今回の目的地は固定でn-1
        // n-1までの経路に負閉路が存在すれば答えはinf
        // また、本問題ではコストの正負を反転させてるので元に戻す
        for (int i = 0; i < n; i++)
        {
            if (negative[i])
            {
                Console.WriteLine("NEGATIVE CYCLE");
                return;
            }
        }
        for (int i = 0; i < n; i++)
        {
            if (dist[i] == long.MaxValue) Console.WriteLine("INF");
            else Console.WriteLine(dist[i]);
        }
    }

    static bool[] Bellman_ford(int n, int s, int m, long[] dist)
    {
        // グラフの受け取りはこっちでやる
        // 頂点a→頂点b(コストc)
        string[] cin;
        int[] a = new int[m];
        int[] b = new int[m];
        long[] c = new long[m];
        for (long i = 0; i < m; i++)
        {
            cin = Console.ReadLine().Split();

            a[i] = int.Parse(cin[0]);
            b[i] = int.Parse(cin[1]);
            c[i] = long.Parse(cin[2]);
        }

        // 始点から始点の距離は0
        dist[s] = 0;

        // 第一ステップ：最短距離の算出
        // 始点を除くn-1個の頂点と全ての辺について貪欲的に最短距離を算出
        for (int i = 1; i < n; i++)
        {
            for (int j = 0; j < m; j++)
            {
                // dist[a[j]]がlong.MaxValueだと桁あふれするのでその場合を除外
                if (dist[a[j]] != long.MaxValue && dist[b[j]] > dist[a[j]] + c[j])
                {
                    dist[b[j]] = dist[a[j]] + c[j];
                }
            }
        }

        // 第二ステップでdistの値が変化する場合、それは最短距離では無いので
        // 作業用にdist2作ったりする必要はない

        // 第二ステップ：負閉路の検出
        // 負閉路が無い場合はここまでで最短距離が出てるはず
        // 全ての辺について再計算して最短距離が変わるならそれは負閉路の存在を示す
        bool[] negative = new bool[n];

        for (int j = 0; j < m; j++)
        {
            if (dist[a[j]] != long.MaxValue && dist[b[j]] > dist[a[j]] + c[j])
            {
                dist[b[j]] = dist[a[j]] + c[j];
                negative[b[j]] = true;
            }
            // 負閉路を経由してきたやつはその先も負閉路経由となるので
            if (negative[a[j]]) negative[b[j]] = true;
        }
        return negative;
    }
}



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

#define inf 0x3f3f3f3f
#define pb push_back
#define fi first
#define se second

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector <int> vi;
typedef vector <ll> vl;
typedef vector <ull> vu;
typedef vector <vector <int>> vvi;
typedef pair <int, int> pi;
typedef vector <pair <int, int>> vpi;

int n;

void read() {
  cin >> n;
}

void solve() {
  long double sol = 0;
  for(int i = 0; i < n; ++i) {
    long double x;
    string type;
    cin >> x >> type;
    if (type[0] == 'J')
      sol += x;
    else sol += 380000.0 * x;
  }
  cout << fixed << setprecision(5) << sol << endl;
}

int main() {
  ios :: sync_with_stdio(false);
  cin.tie(nullptr);
  int t = 1;
//  cin >> t; //please do not forget to comment this if there are no queries
  while(t) {
    --t;
    read();
    solve();
  }
  return 0;
}


Measured memory_bytes: 256
//#include "bits/stdc++.h"
#include <iostream>
#include <vector>
#include <map>
#include <utility>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include <complex>
#include <bitset>
#include <functional>
#include <stack>
#include <regex>
#include <tuple>
#include <iomanip>

#define int long long
#define REP(i,l,r) REPEAT(i,l,r,true) // [l, r)
#define rep(i,n) REP(i,0,n)           // [0, n)
#define REPEAT(i,l,r,condition) for(int i=(condition)?l:r-1;(condition)?i<r:i>=l;(condition)?++i:--i) // false<-[l, r)->true
#define all(e) e.begin(),e.end()
#define rall(e) e.rbegin(),e.rend()
#define pb push_back
#define fs first
#define sc second
#define show(...) cerr<<#__VA_ARGS__<<" = ";_DEBUG(__VA_ARGS__)
#define showlr(n,l,r) cerr<<#n<<" = ";for(int i=l;i<r;i++){cerr<<n[i]<<", ";}cerr<<endl // [l, r)

#define YN(condition) puts((condition)?"YES":"NO")
#define Yn(condition) puts((condition)?"Yes":"No")
#define yn(condition) puts((condition)?"yes":"no")
#define YES puts("YES")
#define Yes puts("Yes")
#define yes puts("yes")
#define NO  puts("NO")
#define No  puts("No")
#define no  puts("no")

#define case(i) printf("Case #%lld: ",i)

using namespace std;

using vi=vector<int>;
using pint=pair<int,int>;

struct io{io(){cin.tie(0);ios::sync_with_stdio(false);cout.tie(0);cout<<fixed<<setprecision(20);}}io;

template<class T> istream& operator >>(istream &is, vector<T> &v){for(T &e:v)is>>e;return is;}
template<class T> ostream& operator <<(ostream &os, vector<T> v){os<<"{";for(T &e:v)os<<e<<(v.size()-(int)(&e-&v[0])>1?", ":"");os<<"}";return os;}

void _DEBUG(){}
template<typename H,typename... T> void _DEBUG(H a,T...b){cerr<<a<<(sizeof...(b)?",":"\n");_DEBUG(b...);}

inline void in(){}
template<typename H,typename... T>void in(H &a, T&... b){cin>>a;in(b...);}
inline void out(){}
template<typename H,typename... T> void out(H a, T... b){cout<<a<<(sizeof...(b)?" ":"\n");out(b...);}

template<class T> void resz(int n,T& v){v.resize(n);}
template<class H,class... T> void resz(int n,H& a,T&... b){a.resize(n);resz(n,b...);}

template<typename V,typename H> void resize(vector<V>& v,const H a){v.resize(a);}
template<typename V,typename H,typename... T> void resize(vector<V>& v,const H& a,const T... b){v.resize(a);for(auto &v:v) resize(v,b...);}

const int INF=1LL<<55;
const int MOD=1000000007;
const double EPS=1e-8;

int N,M,C;
vi B;
vi A;

int ans;

signed main(){

    in(N,M,C);
    resz(M,A,B);
    in(B);
    rep(i,N){
        in(A);
        int res=0;
        rep(j,M){
            res+=A[j]*B[j];
        }
        if(res+C>0) ans++;
    }
    out(ans);

    return 0;
}


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

using namespace std;
typedef long long ll;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define INF 2e9
#define MOD ((ll)1e9+7)
#define ALL(v) v.begin(), v.end()
#define SZ(x) ((int)(x).size())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define bit(n) (1LL<<(n))

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 InputIterator>
InputIterator adv(InputIterator x, typename std::iterator_traits<InputIterator>::difference_type n) {
    advance(x, n);
    return x;
}

int ni() {
    int i;
    cin >> i;
    return i;
}

class mod {
    static ll fact[];
public:

    template<class... A>
    static ll mul(A... args) {
        ll res = 1;
        for (ll i : std::initializer_list<ll>{args...}) {
            res = (res * i) % MOD;
        }
        return res;
    }

    static ll power(ll base, ll exp) {
        if (exp == 0) return 1;
        if (exp & 1) {
            return mul(base, power(base, exp - 1));
        } else {
            ll p = power(base, exp / 2);
            return mul(p, p);
        }
    }

    static ll factorial(int n) {
        if (fact[n] != 0) return fact[n];
        if (n == 0) return 1;
        return fact[n] = mul(n, factorial(n - 1));
    }

    static ll inverse(int n) {
        return power(n, MOD - 2);
    }

    static ll comb(int n, int r) {
        if (r < 0 || r > n) return 0;
        return mul(factorial(n), inverse(factorial(n - r)), inverse(factorial(r)));
    }

    template<class... A>
    static ll div(ll dividend, A... args) {
        ll res = dividend;
        for (ll i : std::initializer_list<ll>{args...}) {
            res = mul(res, inverse(i));
        }
        return res;
    }

    template<class... A>
    static ll add(A... args) {
        ll res = 0;
        for (ll i : std::initializer_list<ll>{args...}) {
            res = (res * i) % MOD;
        }
        return res;
    }

    template<class... A>
    static ll sub(ll l, A... args) {
        ll res = l;
        for (ll i : std::initializer_list<ll>{args...}) {
            res = (res - i + MOD) % MOD;
        }
        return res;
    }
};
ll mod::fact[(int) 1e6 + 1];

int main() {
    int N = ni(), M = ni();
    if (N < M) swap(N, M);

    ll ans = 0;
    if (N == M+1) {
        ans = mod::mul(mod::factorial(N), mod::factorial(M));
    } else if (N == M) {
        ans = mod::mul(mod::factorial(N), mod::factorial(M), 2);
    }

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

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

using namespace std;
using ll = long long;

using Field = vector<vector<int>>;
using Graph = vector<vector<int>>;
using VI = vector<int>;
using VC = vector<char>;
using PI = pair<int, int>;

#define REP(i, n) for (int i = 0; i < (n); i++)
#define ALL(x) x.begin(), x.end()

const long long INF = 1LL<<60;
const int mod = 1000000007;

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; }

int N, M;

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

    cin >> N >> M;

    int a = 1;
    int b = N;
    set<int> s;

    for (int m = 1; m <= M; m++) {
        if ((s.find(abs(a - b)) != s.end()) || (s.find(abs(N + a - b) % N) != s.end()) || abs(a - b) == abs((N + a - b) % N)) {
            cout << a << " " << b - 1 << endl;
        } else {
            cout << a << " " << b << endl;
        }
        s.insert(abs(a - b));
        s.insert(abs((N + a - b)%N));
        a++;
        b--;
    }

    return 0;
    
}

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

using namespace std;

#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define REP3(i, m, n) for(int i = m, i##_len=(n);i < i##_len;i++)
#define FORVEC(i, v) for(int i = 0;i < v.size();i++)

#define INF 1000000000
#define pb(a) push_back(a)
#define vi vector<int>
#define P pair<int,int>
#define all(vec) (vec.begin()),(vec.end())
#define ll long long int;
#define sz(x) ((int)(x).size())
#define in(x) int x;cin>>x;
#define bit(n) (1<<(n))


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; }


int main(){
	int a[200][3]={};
	int p[200]={};
	bool flag;
	in(n);
	REP(i,n){
		cin>>a[i][0]>>a[i][1]>>a[i][2];
	}
	REP(i,3){
		REP(j,n){
			flag=false;
			REP(k,n){
				if(j!=k&&a[j][i]==a[k][i]){
					flag=true;
					break;
				}
			}
			if(!flag){
				p[j]+=a[j][i];
			}
		}
	}
	REP(i,n){
		cout<<p[i]<<"\n";
	}
	return 0;
}

Measured memory_bytes: 3108
using System;

	public class Class1
	{
		public static void Main(String[] args)
		{
			double r =double.Parse(Console.ReadLine());
			double b=2d*r*Math.PI;
			double a=r*r*Math.PI;
			Console.WriteLine("{0:f6} {1:f6}",a,b);
			
			
			
		}
	}

Measured memory_bytes: 9132
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    vector<int> a(n);
    for(int i = 0; i < n; i++)
        cin>>a[i];
    sort(a.begin(),a.end());
    cout<<a[n-1]-a[0];
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	long long n;
	cin >> n;
	long long s[n+1];
	for (int i=1; i<=n; i++){
		cin >> s[i];
		if (s[i]==0){
			cout << 0 << endl;
			return 0;
		}
	}
	for (int i=2; i<=n; i++){
		if(1000000000000000000ll/s[i-1]<s[i]){
			cout << -1 << endl;
			return 0; 
		}
		s[i]*=s[i-1];
	}
	cout << s[n] << endl;
	return 0;
}

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


long long gcd(long long a,long long b){
    if (b == 0) return a;
    return gcd(b,a%b);
}

long long prime_factor(long long N){
    long long ans = 1;
    for(long long i=2;i*i <= N;i++){
        if (N % i != 0) continue;
        if (N % i == 0) ans++;
        while(N % i == 0){
            N /= i;
        }
    }
    if (N != 1) ans++;
    return ans;
}
// 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 A,B;cin >> A >> B;
    
    long long d = gcd(A,B);
    if (d == 1){
        cout << 1 << endl;
        return 0;
    }
    long long num = prime_factor(d);
    cout << num << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<queue>
#include<cstring>
#include<algorithm>
#include<stack>
#include<set>
#include<map>
#include<vector>
#include<cmath>
using namespace std;
int main(){
	long long x,y,z,n;
	cin>>x>>y>>z>>n;
	long long ans=0;
	for(int i=0;i*x<=n;i++){
		for(int j=0;i*x+j*y<=n;j++){
			if((n-i*x-j*y)%z==0) ans++;
		}
	}
	cout<<ans;
    return 0;
}

Measured memory_bytes: 256
#![allow(unused_imports)]

use text_io::*;
use proconio::*;
use std::collections::*;
use std::process::exit;
use std::cmp::*;
use itertools::Itertools;
use num::*;


fn main() {
    proconio::input! {
        n:i64,
        n:String,
    }
    let mut a=n.chars().collect_vec();
    let mut b=0;
    let mut c=0;
    for i in 0..a.len() {
        if a[i]=='I' {
            b+=1;
            if c<b {c=b}
        }
        else {
            b-=1
        }
    }
    println!("{}",c)
}

Measured memory_bytes: 2112