akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    int ans = INF;
    int a[110];
    rep(i, N) cin >> a[i];
    REP(i, -100, 100) {
        int cost = 0;
        rep(j, N) {
            cost += (a[j] - i) * (a[j] - i);
        }
        ans = min(ans, cost);
    }
    cout << ans << endl;

    return 0;
}


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

class Timer {
#ifdef LOCAL
	std::chrono::high_resolution_clock::time_point m_start;
public:
	Timer() 
	: m_start(std::chrono::high_resolution_clock::now()) {}

	~Timer() {
		auto end = std::chrono::high_resolution_clock::now();
  		auto duration_s = std::chrono::duration<double>(end - m_start).count();
  		cerr << "Completed in " << duration_s << endl;
  	}
#else
#endif
};
template < class c > struct rge { c b, e; };
template < class c > rge<c> range(c i, c j) { return rge<c>{i, j}; }
template < class c > auto dud(c* x) -> decltype(cerr << *x, 0);
template < class c > char dud(...);
struct debug {
#ifdef LOCAL
	~debug() { cerr << endl; }
	template < class c > typename enable_if<sizeof dud<c>(0) != 1, debug&>::type operator<<(c i) { cerr << boolalpha << i; return *this; }
	template < class c > typename enable_if<sizeof dud<c>(0) == 1, debug&>::type operator<<(c i) { return *this << range(begin(i), end(i)); }
	template < class c, class b > debug & operator <<(pair < b, c > d) {
	  return * this << "(" << d.first << ", " << d.second << ")";
	}
	template < class c > debug & operator <<(rge<c> d) {
	  *this << "[";
	  for (auto it = d.b; it != d.e; ++it)
	    *this << ", " + 2 * (it == d.b) << *it;
	  return * this << "]";
	}
#else
	template < class c > debug & operator <<(const c&) { return * this; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#define fori(i,n) for(int i=0; i<n; ++i)
#define forir(i,n) for(int i=n; i>=0; --i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

using ll = long long;

const int INF = 1e9 + 5;

#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

#include <iostream>

void solve() {
	int n;
	cin >> n;
	vector<double> dp(n + 1, 0); // dp[i] - probability of i heads flipped so far
	dp[0] = 1;
	{
		double p_heads; 
		fori(i, n) {
			debug() << dp;
			cin >> p_heads;
			for(int j = i+1; j >= 0; --j) {
				dp[j] *= (1 - p_heads);
				if (j != 0) {
					dp[j] += dp[j-1] * p_heads;
				}
			}
		}
		double sum = 0;
		for(int i  = n/2+1; i < n + 1; ++i) {
			sum += dp[i];
		}
debug() << dp;
		cout << std::setprecision(10) << sum << endl;

	}
}

int main() {
	FAST
	int t = 1;
	// cin >> t;

	for (int i = 0; i < t; ++i) {
		solve();
	}
}

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

using namespace std;
#define sqr(x) ((x)*(x))
#define cube(x) ((x)*(x)*(x))
#define GCD(a, b) __gcd(a, b)
#define LCM(a, b) ((a)*(b)/GCD(a,b))
#define MP make_pair
#define n1 first
#define n2 second
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define SI set<int>
#define SL set<ll>
#define MS multiset
#define MSI multiset<int>
#define MSLL multiset<ll>
#define PB push_back
#define PF push_front
#define VI vector<int>
#define VPI vector<pair<int,int>>
#define VLL vector<ll>
#define VS vector<string>
#define SZ(x) ((int)x.size())

typedef long long ll;

typedef unsigned long long ull;
typedef long double ld;
typedef double db;
const int INF = 1e9;
const ld PI = 3.1415926535;
const int MOD = 1000000007;
const int N = 250555;
const int M = 1155;

void solve() {
    ll k,x;
    cin >> k >> x;

    if (k*500 >= x) cout << "Yes"; else
        cout << "No";

}

int main() {
    ios_base::sync_with_stdio(false);
#ifdef dxz05
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else

#endif

    int T = 1;
    // cin >> T;

    while (T--) {
        solve();
    }

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	void run() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		int ans = 0;
		for(int i = 0; i < n; i++) {
			if(i == 0) ans = k;
			else ans *= k-1;
		}
		System.out.println(ans);
		sc.close();
	}

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

Measured memory_bytes: 21844
// Created by Nandu Vinodan
#include <bits/stdc++.h>

#define db1(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'
#define rep(i,a,n) for(int i=a;i<=(n);++i)
#define repD(i,a,n) for(int i=a;i>=(n);--i)
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)
#define vi vector<int>
#define pi pair<int, int>
#define INF INT_MAX
#define _INF INT_MIN
#define TC 0 

using namespace std;
using ll = long long;

void testcase() {
    
    int mat[3][3];
    rep (i, 0, 2)
    	rep (j, 0, 2)
    		cin >> mat[i][j];


    vector<vector<int> > v(3, vector<int> (3, 0));
    int n; cin >> n;
    while (n--) {
    	int val; cin >> val;

    	rep (i, 0, 2) {
    		rep (j, 0, 2) {
    			if (mat[i][j]==val) {
    				v[i][j] = 1;
    			}
    		}
    	}
    }

    rep (i, 0, 2) {
    	int rs = 0;
    	rep (j, 0, 2) {
    		rs += v[i][j];
    	}
    	if (rs==3) {
    		cout << "Yes\n";
    		return;
    	}
    }
    rep (i, 0, 2) {
    	int rs = 0;
    	rep (j, 0, 2) {
    		rs += v[j][i];
    	}
    	if (rs==3) {
    		cout << "Yes\n";
    		return;
    	}
    }

    if (v[0][0] + v[1][1] + v[2][2] == 3)
    	cout << "Yes\n";
   	else if (v[0][2] + v[1][1] + v[2][0] == 3) 
   		cout << "Yes\n";
   	else
   		cout << "No\n";
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    if (TC)
        cin>>t;
    while(t--) {
        testcase();
    }
    return 0;
}

Measured memory_bytes: 256
n, m, c = map(int, input().split())
b = list(map(int, input().split()))
ans = 0
for i in range(n):
  a = list(map(int, input().split()))
  s = c
  for j in range(m):
    s += a[j] * b[j]
  if s > 0:
    ans += 1
print(ans)


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

using namespace std;

#define loop(i, n) for(int i = 0;i < int(n);i++)
#define rloop(i, n) for(int i = int(n);i >= 0;i--)
#define range(i, a, b) for(int i = int(a);i <= int(b);i++)
#define SZ(c) int(c.size())
#define ALL(c) c.begin(), c.end()
#define RALL(c) c.rbegin(), c.rend()
#define PI acos(-1)
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define sfi1(v) scanf("%d",&v)
#define sfi2(v1, v2) scanf("%d %d",&v1,&v2)
#define sfi3(v1, v2, v3) scanf("%d %d %d",&v1,&v2,&v3)
#define sfll1(v) scanf("%I64d",&v);
#define sfll2(v1, v2) scanf("%I64d %I64d",&v1,&v2)
#define sfll3(v1, v2, v3) scanf("%I64d %I64d %I64d",&v1,&v2,&v3)
#define endl '\n'

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


int main() {

#ifndef ONLINE_JUDGE
    //freopen("in.in", "r", stdin);
    //freopen("out.in", "w", stdout);
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int n;
    cin >> n;
    int res = n / 15;
    cout << n * 800 - res * 200 << endl;

    return 0;
}


Measured memory_bytes: 3600
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
using namespace std;
const int mod = 998244353, maxn = 1e5+10;
int N, M, K;
int h[maxn], dp[maxn];

int main()
{
    memset(dp, 0x3f,sizeof(dp));
    scanf("%d %d", &N, &K);
    for(int i = 1; i <= N; i++)
        scanf("%d", &h[i]);
    dp[1] = 0;
    for(int i = 2; i <= N; i++) {
        for(int j = 1; j < i && j <= K; j++)
            dp[i] = min(dp[i], dp[i-j]+abs(h[i]-h[i-j]));
    }
    printf("%d\n", dp[N]);
    return 0;
}


Measured memory_bytes: 3972
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define ld double 
#define rep(i,a,b) for(ll i=a; i<b; ++i)
#define BOOST std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb push_back
#define all(v) v.begin(),v.end()
#define sl(a) a.size()
#define mod 1000000007 
#define lcm(a,b) (a*b)/__gcd(a,b)
#define MAX1 100006
#define f first
#define s second
#define pi 2*acos(0.0)
void solve()
{
    ll n; cin>>n;
    vector<ll> presum(n+1,0),arr(n);
    rep(i,0,n)
    {
        cin>>arr[i];
        presum[i+1]=presum[i]+arr[i];
    }
    ll sum=0;
    rep(i,0,n)
    {
        sum+=(((presum[n]-presum[i+1])%mod*arr[i]%mod)%mod);
        sum%=mod;
    }cout<<sum;
}
int main()
{
    #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt","r",stdin);
    //for getting error from error.txt
    freopen("error.txt", "w", stderr);
    // for writing output to output.txt
    freopen("output.txt","w",stdout);
    #endif
    BOOST
    int T=1;  //cin>>T;
    while(T--) solve();
    cerr<<"Time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" secs"<<"\n";
    cerr<<"My CLOCKS_PER_SEC= "<<CLOCKS_PER_SEC<<"\n";
    return 0;
}


Measured memory_bytes: 6364
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <set>
#include <stdio.h> 
using namespace std;
typedef long long int lli;
const int MaxN=200000;
#define fst first
#define snd second
#define mp make_pair
	lli mcd(lli a,lli b){	
		if(a==0)return b;
		return mcd(b%a,a);
	}
	
int main(){
	//cin.tie(0),ios_base::sync_with_stdio(0);
	lli N,n,i,j,p,q;
	string a,b;
	cin>>a>>b;
	n=b.size();
	char aux;
	aux=b[n-1];
	a.push_back(aux);
	if(a==b){
		cout<<"Yes\n";
	}
	else cout<<"No\n";
}	
		

Measured memory_bytes: 3132
#include<iostream>
#include<bits/stdc++.h>
#define int long long
#define mod 1000000007
#define pb(x) push_back(x)
#define gcd(a,b) __gcd(a,b)
#define all(v) v.begin(),v.end()
#define lcm(a,b) (a*b)/gcd(a,b)
#define bits(x) __builtin_popcountll(x)
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
int32_t main()
{
  int n,k;
  cin>>n>>k;
  int a[n+1];
  for(int i=0;i<n;i++)
  {
  	cin>>a[i];
  }
  sort(a,a+n);
  int s=0;
  for(int i=0;i<k;i++)
  {
  	s=s+a[i];
  }
  cout<<s;
}


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

using namespace std;

#if defined(_WIN32) || defined(__WIN32__) || defined(WIN32)
    #define _CRT_SECURE_NO_WARNINGS
    #pragma warning(disable:4996)
#endif

#define ll long long
#define vi vector<ll>
#define ull unsigned long long
#define vull vector<ull>
#define vll vector<ll>
#define pii pair<int, int>
#define pll pair<ll, ll>

#define ld long double

int INF = 1e9 + 7;



int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    vi h(n);
    for (int i = 0; i < n; i++)
        cin >> h[i];
    vi dp(n, INF);
    dp[0] = 0;
    for (int i = 1; i < n; i++)
        for(int j = 1; i - j >= 0 && j <= k; j++)
            dp[i] = min(dp[i], dp[i - j] + abs(h[i - j] - h[i]));
    cout << dp[n - 1];
}

Measured memory_bytes: 4724
#include "bits/stdc++.h"
#include "math.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef vector<pair<ll,ll> > vp;
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define drep(i,a,b) for(ll i=(a);i>=(b);--i)
#define SIZE(a) int((a).size())
const int MOD=1e9+7;


int main(){
  ll n;cin>>n;
  ll ans=1;
  rep(i,1,n+1){
    ans*=i;
    ans%=MOD;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
N=int(input())
A=[int(input()) for i in range(N)]

A.sort()

B=A[:N//2]
C=A[N//2:]


#print(B)
#print(C)

if len(B)>=2:
    B=[B[-1]]+B[:-2]+[B[-2]]

if len(C)>=2:
    C=[C[1]]+C[2:]+[C[0]]

if N%2==0:
    B,C=C,B



X=[]
b=0
c=0
while b<len(B) or c<len(C):
    if c<len(C):
        X.append(C[c])
    if b<len(B):
        X.append(B[b])
    b+=1
    c+=1

#print(X)
ANS=0
for i in range(1,N):
    ANS+=abs(X[i]-X[i-1])

#print(ANS)




B=A[:N//2+1]
C=A[N//2+1:]

#print(B)
#print(C)

if len(B)>=2:
    B=[B[-1]]+B[:-2]+[B[-2]]

if len(C)>=2:
    C=[C[1]]+C[2:]+[C[0]]

X=[]
b=0
c=0
#print(B)
#print(C)
while b<len(B) or c<len(C):
    if b<len(B):
        X.append(B[b])

    if c<len(C):
        X.append(C[c])

    b+=1
    c+=1

#print(X)
ANS2=0
for i in range(1,N):
    ANS2+=abs(X[i]-X[i-1])

#print(ANS2)

print(max(ANS,ANS2))





Measured memory_bytes: 9840
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;

// template {{{  0 
// using {{{ 1
using ll = long long int;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vii = vector<pii>;
using vll = vector<pll>;
// }}} 1
// definition {{{ 1
// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)
#define Scll(x) scanf("%lld", &x)
#define Scll2(x,y) scanf("%lld%lld", &x, &y)
#define Scll3(x,y,z) scanf("%lld%lld%lld", &x, &y, &z)
#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2
// constants {{{ 2
#define EPS (1e-7)
#define INF (2e9)
#define PI (acos(-1))
// }}} 2
// systems {{{ 2
#define Repe(x,y,z) for(ll x = z; x < y; x++)
#define Rep(x,y) Repe(x,y,0)
#define RRepe(x,y,z) for(ll x = y-z-1; x >= 0; x--)
#define RRep(x,y) RRepe(x,y,0)
// }}} 2
// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n")
#define YESNO(a) (a)?printf("YES\n"):printf("NO\n")
// }}} 2
// }}} 1
// input {{{ 1
// }}} 1
// }}} 0

int main() {

    int p,m,c;
    Scd3(p,m,c);
    printf ("%d\n", p+m+c );

    return 0;
}





Measured memory_bytes: 3220
#include <iostream>
#include <climits>
#include <stack>
#include <queue>
#include <string>
#include <utility>
#include <string.h>
#include <iomanip>
#include <stdlib.h>
#include <algorithm>
#include<cmath>
#include <limits>
using namespace std;
typedef long long ll;

typedef pair<ll, ll> P;
const int INF = 100000000;
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };

#define REP(i, a,b) for(i=a;i<b;i++) 
#define REP1(i,b,a) for(i=b-1;i>=a;i--)
#define output(x) cout<<x<<endl;
#define pb(x) push_back(x);
const int MOD = 1000000007;


int main() {
	int N,i,j,H,A,ans;
	char S[100001];
	cin >> H >> A;
	if (H%A) {
		ans = H / A + 1;
	}
	else
		ans = H / A;
	cout << ans << endl;
	return 0;
}



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

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

int main() {
  int n, x;
  scanf("%d%d", &n, &x);
  int cx, d, ans = 0;
  for (int i=0; i<n; i++) {
    scanf("%d", &cx);
    d = abs(cx - x);
    ans = gcd(d, ans);
  }
  printf("%d", ans);
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define N 10000
  int x[15][15];
int main() {
  cout<<setprecision(10)<<endl;
  int d,n;
  cin>>n>>d;
  rep(i,n){
    rep(j,d){
      cin>>x[j][i];
    }
  }
  int ans=0;
  rep(i,n)rep(j,i){
        ll n_ans=0;
        rep(k,d){
          n_ans+=(x[k][i]-x[k][j])*(x[k][i]-x[k][j]);
        }
        rep(l,1000){
          if(l*l==n_ans){
            ans++;
          }
        }
  }

  cout<<ans<<endl;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int intA;
		String strCulc = "";
		int intB;
		ArrayList<Integer> list = new ArrayList<Integer>();
		while(true){
			intA = scan.nextInt();
			strCulc = scan.next();
			intB = scan.nextInt();
			if("+".equals(strCulc)){
				list.add(intA + intB);
			}else if("-".equals(strCulc)){
				list.add(intA - intB);
			}else if("*".equals(strCulc)){
				list.add(intA * intB);
			}else if("/".equals(strCulc)){
				list.add(intA / intB);
			}else if("?".equals(strCulc)){
				break;
			}
		}
		for(int i = 0; i < list.size(); i++){
			System.out.println(list.get(i));
		}
		scan.close();
	}
}

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

int main() {
	int q, n;
	cin >> q;
	for(int i = 0; i < q; ++i){
		cin >> n;
		int cnt = 0;
		while(cnt < 1000){
			if(n <= 9)
				break;
			string base = to_string(n);
			int next = 0;
			for(int i = 1; i < base.size(); ++i){
				string t = base;
				int l = stoi(t.substr(0, i));
				int r = stoi(t.substr(i, t.size() - i));
				next = max(next, l * r);
			}
			n = next;
			cnt++;
		}
		if(cnt >= 1000)
			cout << "-1" << endl;
		else
			cout << cnt << endl;
	}
	return 0;
}

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

#define maxn 100005
#define mod 1000000007
#define ll long long
int n;
int a[maxn], cnt[maxn], dp[maxn][3];
int _max;

int main()
{
	cin >> n;
	cnt[0] = 3;
	for (int i = 1; i <= n; i++)
	{
		scanf("%d", &a[i]);
		a[i]++;
		dp[a[i]][cnt[a[i]]] = cnt[a[i] - 1];
		cnt[a[i]]++;
		_max = max(_max, a[i]);
	}
	ll ans = 1;
	for (int i = 1; i <= _max; i++)
	{
		//for (int j = 0; j < 3; j++)
		//	printf("%d ", dp[i][j]);
		//printf("\n");
		if (dp[i][cnt[i] - 1] < cnt[i])
			ans = 0;
		for (int j = 0; j < cnt[i]; j++)
		{
			if (j > 0)
			{
				if (dp[i][j] <= j)
					ans = 0;
				else
					dp[i][j] -= (j);
			}
			ans = ans * dp[i][j] % mod;
		}
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 2176
#include<bits/stdc++.h>
using namespace std;
int n,a[200005],k;
int main()
{
	cin>>n>>k;
	for(int i=0;i<n;i++)
		cin>>a[i];
	sort(a,a+n);
	long long cnt=0;
	for(int i=0;i<n-k;i++)
		cnt+=a[i];
	cout<<cnt;
	return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n, k;
    string s;
    cin >> n >> s >> k;
    for(int i = 0; i < (int)s.length(); i++)
        if(s[i] != s[k-1])
            s[i] = '*';
    cout << s << endl;
}


Measured memory_bytes: 256
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map;
import java.util.Queue;
import java.util.Scanner;

public class Main {
	static Queue<Puzzle> queue=new LinkedList<Puzzle>();
	static Map<String, Integer> map=new HashMap<>();
	static int[][] goal;
	
	static class Puzzle{
		int[][] p=new int[4][4];
		int step;
		Puzzle(int[][] p, int step){
			this.step=step;
			for(int i=0; i<3; i++) {
				for(int j=0; j<3; j++) {
					this.p[i][j]=p[i][j];
				}
			}
		}
	}
	
	static int bfs() {
		int minstep=0;
		int[][] dt={{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
		while(! queue.isEmpty()) {
			int[][] field=new int[4][4];
			String str="";
			int r=0, c=0;
			Puzzle q=queue.remove();
			boolean tf=true;
			for(int i=0; i<3; i++) {
				for(int j=0; j<3; j++) {
					field[i][j]=q.p[i][j];
					str+=String.valueOf(field[i][j]);
					if(q.p[i][j]==0) {
						r=i;
						c=j;
					}
					if(q.p[i][j]!=goal[i][j]) {
						tf=false;
					}
				}
			}
			minstep=q.step;
			if(tf) {
				break;
			}
			if(map.get(str)!=null) {
				continue;
			}
			map.put(str, minstep);
			
			for(int i=0; i<4; i++) {
				if(r+dt[i][0]>2 || r+dt[i][0]<0 || c+dt[i][1]>2 || c+dt[i][1]<0){
		            continue;
		        }
				int swap=field[r][c];
				field[r][c]=field[r+dt[i][0]][c+dt[i][1]];
				field[r+dt[i][0]][c+dt[i][1]]=swap;
				queue.add(new Puzzle(field, minstep+1));
				swap=field[r][c];
				field[r][c]=field[r+dt[i][0]][c+dt[i][1]];
				field[r+dt[i][0]][c+dt[i][1]]=swap;
			}
			
		}
		return minstep;
	}
	
	
	public static void main(String[] args) {
		try(Scanner sc = new Scanner(System.in)){
			goal=new int[4][4];
			for(int i=0; i<3; i++) {
				for(int j=0; j<3; j++) {
					goal[i][j]=sc.nextInt();
				}
			}
			int[][] start=new int[4][4];
			int count=1;
			for(int i=0; i<3; i++) {
				for(int j=0; j<3; j++) {
					start[i][j]=count%9;
					count++;
				}
			}
			queue.add(new Puzzle(start, 0));
			System.out.println(bfs());

		}
	}
}


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

int main() {
    ll N;
    cin >> N;
    vector<ll> h(N);
    for (ll i = 0; i < N; i++) {
        cin >> h[i];
    }

    vector<ll> dp(N + 2, LLONG_MAX);
    dp[0] = 0;
    for (ll i = 0; i < N - 1; i++) {
        dp[i + 1] = min(dp[i + 1], dp[i] + abs(h[i] - h[i + 1]));
        dp[i + 2] = min(dp[i + 2], dp[i] + abs(h[i] - h[i + 2]));
    }

    cout << dp[N - 1] << endl;
}

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

#define MOD 1000000007

int main()
{
    string L; cin >> L;
    int len = L.size();

    vector<int> x3(len);
    x3[0] = 1;
    for (int i = 1; i < x3.size(); i++) {
        x3[i] = (ll)x3[i-1] * 3 % MOD;
    }

    ll ans_eq = 1, ans_lt = 0;
    for (int i = 0; i < len; i++) {
        if (L[i] == '1') {
            ans_lt = (ans_lt + (ans_eq * x3[len - i - 1] % MOD)) % MOD;
            ans_eq = (ans_eq * 2) % MOD;
        }
    }
    ll ans = (ans_eq + ans_lt) % MOD;
    cout << ans << endl;
}


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

using namespace std;

typedef long long int li;
typedef long double ld;
typedef vector<li> vi;
typedef pair<li,li> pi;
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define B begin()
#define E end()
#define f(i,l,r) for(li i=l;i<=r;++i)
#define fr(i,l,r) for(li i=l;i>=r;--i)
#define u_map unordered_map
#define endl "\n"

li fastpow(li base,li exp,li M) 
{
    li res=1;
    while(exp>0) {
        if(exp&1)
            res=(res*base)%M;

        base=(base*base)%M;
        exp>>=1;
    }
    return res;
}

int main()
{    

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

    li n,k,mod=1e9+7;

    cin>>n>>k;

    vi a(k+1);

    li ans=0;

    fr(i,k,1)
    {
        a[i]=fastpow(k/i,n,mod);

        for(li j=2*i;j<=k;j+=i)
        {
            a[i]-=a[j];
            a[i]+=mod;
            a[i]%=mod;
        }

        ans+=i*a[i];
        ans%=mod;
    }   

    cout<<ans;

    return 0;
}

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

using namespace std;
using ll = long long;

const int nax = 2e5 + 12;

vector<int>v[nax];
int ans[nax];
int n, q;

void dfs (int src, int par)
{
  for (auto w : v[src]) {
    if (w != par) {
      ans[w] += ans[src];
      dfs (w, src);
    }
  }
}

int main()
{
  ios_base::sync_with_stdio (0);
  cin.tie (0) ;
  cin >> n >> q;
  for (int i = 1; i < n; i++) {
    int x, y;
    cin >> x >> y;
    v[x].push_back (y);
    v[y].push_back (x);
  }
  while (q--) {
    int vertex, val;
    cin >> vertex >> val;
    ans[vertex] += val;
  }
  dfs (1, -1);
  for (int i = 1; i <= n; i++) {
    cout << ans[i] << ' ';
  }
  cout << '\n';
  return 0;
}


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

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

ll N,K;

ll calc(ll a){
	ll ret = (N/a)*(a-K);
	if(N%a != 0) ret += max(0LL, (N-(N/a)*a-max(0LL,(K-1))));
	return ret;
}

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

	cin >> N >> K;

	ll ans = 0;

	for (int i = K+1;i <= N;i++){
		ans += calc(i);
	}

	cout << ans << endl;

	return 0;

}


Measured memory_bytes: 256
import numpy as np
H ,W = map(int,input().split())

maze = [[] for _ in range(H)]
for i in range(H):
    maze[i] = np.array(list(input())) == "."
maze = np.array(maze)

up = np.zeros((H, W), dtype=int)
down = np.zeros((H, W), dtype=int)
right = np.zeros((H, W), dtype=int)
left = np.zeros((H, W), dtype=int)

for i in range(H):
    up[i] = (up[i-1] + 1)*maze[i]
    down[-(i+1)] = (down[-i] + 1)*maze[-(i+1)] 
    
#print(up)
#print(down)

for i in range(W):
    right[:, i] = (right[:, i-1] + 1)*maze[:, i]
    left[:, -(i+1)] = (left[:, -i] + 1)*maze[:, -(i+1)]

print(np.max(up+down+right+left)-3)

Measured memory_bytes: 191264
#ifndef _STD
#define _STD
#include<bits/stdc++.h>
#endif

#define int long long int
#define rep(a,b,c) for(int a=b;a<c;a++)
#define repm(a,b,c) for(int a=(b-1);a>=c;a--)
#define pb push_back
#define str string
#define sf(a) scanfs("%d",&a)
#define pb push_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) (v).begin(), (v).end()
#define clean(used) memset(used,false,sizeof(used))

using namespace std;

static const double EPS = 1e-10;
static const int INF = (const int) (1e18 + 9);
static const int Mod = (const int) (1e9 + 7);
inline int replac(str s){double ans=0;rep(i,0,s.length()){ans+=(s[i]-'0')*pow(10,s.length()-i-1);}return (int)ans;}
inline string numstr(int m){str s="";while(m>0){char c;int a=m/10;if(a>0)a=m%(a*10);else a=m;c=(char)('0'+a);s+=c;m/=10;}str st="";for(int i=s.size()-1;i>=0;i--){st+=s[i];}return st;}
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii> vii;
typedef vector<pair<int,pii>> ipii;

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    int a[100005] = {0};
    cin >> n ;
    rep(i,0,n){
        int x;
        cin >> x;
        a[i] = x;
    }
    sort(a,a+n);
    int mae = 0;
    int ans = 0,cnt = 0;
    for(int i = n-1 ; i >= 0; i--){
        if(mae == a[i]){
            switch (cnt){
                case 0 : ans = a[i];
                    break;
                case 1 : ans *= a[i];
                    break;
            }
            cnt++;
            mae = 0;
            if(cnt == 2)break;
        }else{
            mae = a[i];
        }
    }
    if(cnt < 2){
        cout << 0 << endl;
    }else{
        cout << ans << endl;
    }
    return 0;
}

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

#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;


int main(){
  int N, K;
  cin >> N >> K;
  
  vector<ld> p(N);
  rep(i, N){
    cin >> p.at(i);
  }
  
  vector<ld> v(N-K+1);


  for(int j = 0; j < K; j++){
    v.at(0) += p.at(j);
  }
  
  int i = 1;
  while(i < N-K+1){
    v.at(i) = v.at(i-1) - p.at(i-1) + p.at(i+K-1);
    i++;
  }
  
  sort(all(v));
  
  cout << fixed << setprecision(12);
  cout << (v.at(N-K)+K)/2.0 << endl;
  
}

Measured memory_bytes: 6528
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <random>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
  ios::sync_with_stdio(false);
  mt19937 rng(328);
  int n = 365, m = 26, c[26] = {}, a[365][26] = {}, z[365] = {}, y = 0;
  cin >> n;
  for (int i = 0; i < m; i++) cin >> c[i];
  for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) cin >> a[i][j];
  for (int i = 0; i < n; i++) z[i] = rng() % 26;
  for (int i = 0; i < n; i++) y += a[i][z[i]];
  for (int i = 0; i < m; i++) {
    int l = -1;
    for (int j = 0; j < n; j++) {
      if (z[j] == i) l = j;
      y -= c[i] * (j - l);
    }
  }
  for (int t = 0; t < 250000; t++) {
    int u = rng() % n, v = rng() % m, w = 0, x[365] = {};
    for (int i = 0; i < n; i++) x[i] = z[i];
    x[u] = v;
    for (int i = 0; i < n; i++) w += a[i][x[i]];
    for (int i = 0; i < m; i++) {
      int l = -1;
      for (int j = 0; j < n; j++) {
       	if (x[j] == i) l = j;
        w -= c[i] * (j - l);
      }
    }
    if (w > y) {
      y = w;
      z[u] = v; 
    }
    //for (int i = 0; i < n; i++) cout << z[i] << ' '; cout << y << '\n';
  }
  //cout << y << '\n';
  for (int i = 0; i < n; i++) cout << z[i] + 1 << '\n';
}


Measured memory_bytes: 3204
/* 
	Author: ankrypt
*/


#include <bits/stdc++.h>

using namespace std;

#define MOD 1000000007
#define ll long long int
#define u64 unsigned long long int

ll N, D;
ll arr[15][15];


int main() {
	scanf("%lld %lld", &N, &D);
	for(int i = 0; i < N; i++) {
		for(int j = 0; j < D; j++) {
			scanf("%lld", &arr[i][j]);
		}
	}	
	ll cnt = 0;
	for(int i = 0; i < N; i++) {
		for(int k = i + 1; k < N; k++) {
			double tempAns = 0;
			for(int j = 0; j < D; j++) {
				// cout << i << " " << k << " " << arr[k][j] << " " << arr[i][j] << "\n";
				tempAns += pow(abs(arr[k][j] - arr[i][j]), 2); 
			}
			tempAns = sqrt(tempAns);
			// cout << tempAns << " this\n";	
			// cout << tempAns << " ";
			ll ans = ceil(tempAns);
			ll ans1 = floor(tempAns);
			// cout << ans << " " << ans1 << " \n";
			if(ans == ans1) {
				cnt++;
			}
		}
	}
	printf("%lld\n", cnt);
	return 0;
}
/*
	Powered by Buggy Plugin
*/


Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
const ll mod=1e9+7;
const ll inf=0x3f3f3f3f;
const int N=1e6+5;
using namespace std;
int boom[N];

int primes[N],cnt;
int st[N];
void ola(int n)
{
    for (int i = 2; i <= n; i ++ )
    {
        if (st[i] == 0) primes[cnt ++ ] = i;//将质数存到primes中
        for (int j = 0; primes[j] <= n / i; j ++ )//要确保质数的第i倍是小于等于n的。
        {
            st[primes[j] * i] = 1;
            if (i % primes[j] == 0) break;
        }
    }
}
int main()
{
    ola(2000);
    int n;cin>>n;
    for(int i=0;i<n;i++)
    {
        int t;cin>>t;
        for(int i=0;i<cnt;i++)
        {
            int tot=0;
            while(t%primes[i]==0)
            {
                t/=primes[i];
                tot=1;
            }
            if(tot) boom[primes[i]]++;
        }
        if(t>1) boom[t]++;
    }
    int st=0;
    for(int i=1;i<1000005;i++)
    {
        if(boom[i]>=2) st++;
        if(boom[i]==n)
        {
            cout<<"not coprime"<<endl;
            return 0;
        }
    }
    if(st==0)
    {
        cout<<"pairwise coprime"<<endl;
    }
    else
        cout<<"setwise coprime"<<endl;
    return 0;
}


Measured memory_bytes: 7544
import sys
sys.setrecursionlimit(10**7)
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return sys.stdin.readline().strip()
INF = 10 ** 18
MOD = 10 ** 9 + 7

def main(): 
    s = SI()
    s = s.replace('LR', 'LxR').split('x')

    ans = []
    for rl in s:
        r_pos = rl.find('RL')
        for _ in range(r_pos):
            ans.append(0)
        if len(rl)%2 == 0:
            r_count = len(rl)//2
            l_count = len(rl)//2
        else:
            if r_pos%2 == 0:
                r_count = len(rl)//2 + 1
                l_count = len(rl)//2
            else:
                r_count = len(rl)//2
                l_count = len(rl)//2 + 1
        ans.append(r_count)
        ans.append(l_count)
        for _ in range(r_pos+2, len(rl)):
            ans.append(0)
    print(' '.join([str(i) for i in ans]))
        


main()

Measured memory_bytes: 13536
//#include "bits/stdc++.h"
//using namespace std;
//typedef long long ll;
//typedef pair<int,int> pii;
//#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
//#define all(a)  (a).begin(),(a).end()
//#define pb push_back
//#define INF 999999999
//

#include "bits/stdc++.h"
using namespace std;
typedef pair<int,int> pii;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define MAX_N 10001
#define INF 999999999

vector<pii> G[MAX_N];

int prim(int n){    //n : ???????????°
    bool used[MAX_N];
    int mincost[MAX_N];
    
    rep(i,n){
        mincost[i]=INF;
        used[i]=false;
    }
    mincost[0]=0;
    int res=0;
    
    while(1){
        int v=-1;
        rep(u,n){
            if(used[u]==false && ( v==-1 || mincost[u]<mincost[v] ))
                v=u;
        }
        if(v==-1)break;
        used[v]=true;
        res+=mincost[v];
        
        rep(i,G[v].size()){
            int u = G[v][i].first;
            mincost[u] = min( mincost[u] , G[v][i].second);
        }
    }
    return res;
}

int main(){
    int v,e;
    cin>>v>>e;
    rep(i,e){
        int a,b,c;
        cin>>a>>b>>c;
        G[a].push_back(pii(b,c));
        G[b].push_back(pii(a,c));
    }
    cout<<prim(v)<<endl;
}

Measured memory_bytes: 4168
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define double long double
#define low lower_bound
#define upp upper_bound
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define Rep(i,n) for (int i = (int)(n); i >= 0; i--)
#define all(vec) vec.begin(),vec.end()
#define rever(vec) reverse(all(vec));
#define cend cout << endl;
#define prique(T) priority_queue<T,vector<T>,greater<T>>
struct edge { int to, cost; };
using P = pair<int, int>;
using PP=pair<P, int>;
const int mod = 1e9 + 7, inf = 1e16;

int modpow(int x, int n) {
	int ans = 1;
	while (n > 0) {
		if (n & 1) {
			if (mod <= ans * x) ans = ans * x % mod;
			else ans *= x;
		}
		if (mod <= x * x) x = x * x % mod;
		else x *= x;
		n >>= 1;
	}
	return ans;
}

int fact_memo[114514];
int fact(int n) {
	int ans = 1;
	if (fact_memo[n]) return fact_memo[n];
	rep(i, n) {
		ans *= (i + 1);
		if (mod <= ans) ans %= mod;
		fact_memo[i + 1] = ans;
	}
	return (ans + mod) % mod;
}

int comb(int n, int r) {
	if (n < r) return 0;
	if (n - r < r) r = n - r;
	return (fact(n) * modpow(fact(n - r), mod - 2) % mod * modpow(fact(r), mod - 2) + mod) % mod;
}

int perm(int n, int r) {
	if (n < r) return 0;
	if (n - r < r) r = n - r;
	return (fact(n) * modpow(fact(n - r), mod - 2) % mod + mod) % mod;
}

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

int lcm(int a, int b) {
	return a * b / gcd(a, b);
}

bool pri(int p) {
	for (int i = 2; i * i <= p; i++) if (p % i == 0) return false;
	return p > 1;
}

P operator+(const P& a, const P& b) {
	return P(a.first + b.first, a.second + b.second);
}
P operator-(const P& a, const P& b) {
	return P(a.first - b.first, a.second - b.second);
}

int h, w, d, q;
P p[93100];
int dis[93100];
signed main() {
	scanf("%lld %lld %lld", &h, &w, &d);
	rep(i, h) {
		rep(j, w) {
			int A;
			scanf("%lld", &A);
			p[A] = P(i, j);
		}
	}
	for (int i = d + 1; i <= h * w; i++) {
		P s = p[i] - p[i - d];
		dis[i] = dis[i - d] + abs(s.first) + abs(s.second);
	}
	scanf("%lld", &q);
	rep(i, q) {
		int l, r;
		scanf("%lld %lld", &l, &r);
		printf("%lld\n", dis[r] - dis[l]);
	}
}

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

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

def bellman_ford(N: int, edges: list, src: int) -> list:
    """ ベルマンフォード(頂点数, 辺集合(0-indexed), 始点) """

    # 頂点[ある始点からの最短距離] (経路自体を知りたい時はここに前の頂点も持たせる)
    res = [INF] * N
    res[src] = 0
    # 各辺によるコストの置き換えを頂点数N-1回繰り返す
    for i in range(N-1):
        for src, dest, cost in edges:
            if res[dest] > res[src] + cost:
                res[dest] = res[src] + cost
    # 頂点Nが負の閉路に含まれていないかチェックする
    for i in range(N):
        for src, dest, cost in edges:
            if res[dest] > res[src] + cost:
                # 検出した負閉路はすぐに-INFにする
                res[dest] = -INF
                if dest == N-1:
                    # 該当していたら空リストを返却
                    return []
    # 問題なければ頂点リストを返却
    return res

N, M, P = MAP()
edges = []
for i in range(M):
    a, b, c = MAP()
    # Pは最後に請求される、だけど、ようは動く度に支払ってると思ってもいい
    edges.append((a-1, b-1, -c+P))

res = bellman_ford(N, edges, 0)
if not len(res):
    print(-1)
else:
    # 正負を直す
    ans = -res[N-1]
    # スコアがマイナスなら0
    print(max(0, ans))


Measured memory_bytes: 44232
#include <iostream>
#include <cmath>
using namespace std;
int main(void){
    long long n,m,a,b;
    cin>>n;
    m=n;
    for(long long i=1;i<m;i++){
        if(n%i==0){
            a=i;
            b=n/i;
        }
        m=(n-n%i)/i;
    }
    int c=1;
    while(b>=pow(10,c)){
        c++;
    }
    cout<<c<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define N 1000005
#define ll long long int 	
#define MP make_pair
#define pb push_back
#define ppb pop_back
#define sp " "
#define endl "\n"
#define fi first
#define se second
#define ii pair<int,int>
#define lli pair<ll,ll>
#define fast cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(false)
#define fast2 freopen ("myfile.in","r",stdin);freopen ("myfile.out","w",stdout);
#define mod 1000000007
#define fs(x,y) for(int i=1;i<=y;i++) cin>>x[i];
#define fo(i,x,y) for(int i=x;i<=y;i++)
using namespace std;

ll n,m,ar[N],sum;


int main()
{
	fast;
	cin>>n;
	cout<<n/3;

}

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

#define endl '\n'

long long A[99];

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

    int n;
    cin >> n;
    A[0] = 2;
    A[1] = 1;
    for(int i = 2; i <= n; i++) {
        A[i] = A[i - 1] + A[i - 2];
    }
    cout << A[n];

    return 0;
}

Measured memory_bytes: 256
def main():
    N, H = map(int, input().split())
    AB = (tuple(map(int, input().split())) for _ in [0] * N)
    a, b = [], []
    appenda, appendb = a.append, b.append
    for i, j in AB:
        appenda(i)
        appendb(j)

    amax = max(a)
    b = [i for i in b if i > amax]
    b.sort(reverse=1)
    energy = H
    if energy <= sum(b):
        attack = 0
        i = 0
        while energy > 0:
            energy -= b[i]
            attack += 1
            i += 1
    else:
        energy -= sum(b)
        attack = (energy + amax - 1) // amax + len(b)

    print(attack)

main()


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

typedef long long ll;

ll N,A[100010];

int main(){
    cin>>N;
    ll cnt=0,sum=0,min=1LL<<60;
    for(int i=0;i<N;i++){
        cin>>A[i];
        if(A[i]<0){
            cnt++;
            A[i]*=-1;
        }
        if(min>A[i])min=A[i];
        sum+=A[i];
    }
    if(cnt%2!=0){
        sum-=min*2;
    }
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<string>

using namespace std;
using P = pair<char, int>;

vector<P> v;

const int tokadd = -1;
const int tokmul = -2;
const int toklvl = -3;

int tokenize(char c) {
    int n = c - '0';
    if (n >= 0 && n <= 9) return n;
    if (c == '+') return tokadd;
    if (c == '*') return tokmul;
    return toklvl;
}

int i = 0;

int compute() {
    int level = v[i].first;
    int token = v[i].second;
    //cout << string(level * 2, ' ') << "now in " << i << " lvl = " << level << " tok = " << token << endl;
    int val = token;
    if (val < 0) {
        val = token == tokadd ? 0 : 1;
        i++;
        while (v[i].first == level + 1 && v.size() > i) {
            if (token == tokadd) {
                val += compute();
            } else {
                val *= compute();
            }
            i++;
        }
        i--;
    }
    //cout << string(level * 2, ' ') << "val = " << val <<  endl;
    return val;
}

int add() {
    return 0;
}

int main() {
    while(1) {
        int n;
        cin >> n;
        if (n == 0) break;
        v.clear();
        string s;
        for (int i = 0; i < n; ++ i) {
            cin >> s;
            int level = s.size() - 1;
            P vi = make_pair(level, tokenize(s[s.size() - 1]));
            v.push_back(vi);
        }
        i = 0;
        cout << compute() << endl;
    }
}


Measured memory_bytes: 3000
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
const double PI=acos(-1);

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

Measured memory_bytes: 3620
#include<stdio.h>
int main()
{
    int h,m,s,S;
    scanf("%d",&S);
    h=S/3600;
    S=S%3600;
    m=S/60;
    s=S%60;
    printf("%d:%d:%d\n",h,m,s);
    return 0;
}



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

#define bug(x) cout << #x << " = " << x << endl;
#define fr(a) freopen(a,"r",stdin);
#define fw(a) freopen(a,"w",stdout);
#define tc() int tc;cin >> tc; for (int _tc=1;_tc<=tc;_tc++)
#define up(i,l,r) for (int i=l;i<=r;i++)
#define down(i,r,l) for (int i=r;i>=l;i--)
#define pb push_back
#define mp make_pair
#define ins insert;
typedef long long int ll;
using namespace std;

void printArr(int a[], int l, int r)
{
    up(i,l,r) {
        cout << a[i] << " ";
    }
    cout << endl;
}

void printMtx(int a[][1010],int n, int m)
{
    up(i,1,n) {
        up(j,1,m) {
            cout << a[i][j] << " ";
        }
        cout << endl;
    }
}

ll n, m, f[100010], MOD = 1e9+7;

void preCal()
{
    f[0] = 1;
    up(i,1,n+1) {
        f[i] = ((f[i-1]%MOD) * (i%MOD)) % MOD;
    }
}

int main()
{
    ios_base::sync_with_stdio(0);

    cin >> n >> m;

    preCal();
    if ((m == n - 1) || (m == n+1)) {
        cout << (f[n] * f[m]) % MOD;
    }
    else if (m == n) {
        cout << ((f[n] * f[m])%MOD * 2) % MOD << endl;
    }
    else cout << 0 << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1000000000
#define LINF 1000000000000000000
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define bit(n) (1LL<<(n))
using namespace std;

typedef pair<int, int> P;
typedef pair<long long, long long> LLP;

/*
  階乗計算（MODで割った余りで返す）
*/

class Factorial {
    private:
        vector<long long> fac;
    public:
        Factorial();
        Factorial(long long n_max);
        void initialization(long long n_max);
        long long getFactorial(long long n);
};

Factorial::Factorial() {}
Factorial::Factorial(long long n_max) {
    fac.clear();
    fac.push_back(1);
    fac.push_back(1);
    for (long long i = 2; i <= n_max; i++) {
        fac.push_back(fac[i-1] * i % MOD);
    }
}
void Factorial::initialization(long long n_max) {
    fac.clear();
    fac.push_back(1);
    fac.push_back(1);
    for (long long i = 2; i <= n_max; i++) {
        fac.push_back(fac[i-1] * i % MOD);
    }
}
long long Factorial::getFactorial(long long n) {
    return fac[n];
}


/*
  MOD計算
*/
// 割り算のための逆元を求める（mod m での a の逆元）
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u % m;
}


class PCH {
    private:
        Factorial fact;
    
    public:
        PCH(long long n_max);
        long long P(long long n, long long r);
        long long C(long long n, long long r);
        long long H(long long n, long long r);
};
PCH::PCH(long long n_max) {
    fact.initialization(n_max);
}
long long PCH::P(long long n, long long r) {
    return fact.getFactorial(n) % MOD * modinv(fact.getFactorial(r), MOD) % MOD;
}

long long PCH::C(long long n, long long r) {
    return fact.getFactorial(n) % MOD * modinv(fact.getFactorial(r), MOD) % MOD * modinv(fact.getFactorial(n - r), MOD) % MOD;
}

long long PCH::H(long long n, long long r) {
    return C(n - 1 + r, r);
}

int main() {
    
    int N, K;
    cin >> N >> K;
    vector<long long> A(N);
    rep(i,N) cin >> A[i];

    sort(A.begin(), A.end(), greater<long long>());

    long long sum = 0;

    if (K == 1) {
        cout << 0 << endl;
        return 0;
    }

    PCH pch(N);

    rep(i,N) {
        if (i + 1 >= K) {
            long long c = pch.C(i, K - 1);
            sum = ((-1 * (c * A[i] % MOD) + MOD) % MOD + sum) % MOD;
        }
        if (N - i >= K) {
            long long c = pch.C(N - i - 1, K - 1);
            sum = ((c * A[i]) % MOD + sum) % MOD;
        }
    }

    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 2168
def movement(inpair1,inpair2):
    outlist = [(inpair1)]
    if inpair1[1] < inpair2[1]:
        for i in range(inpair1[1]+1,inpair2[1]+1):
            outlist.append((inpair1[0],i))
            t = i
    elif inpair1[1] > inpair2[1]:
        for i in range(inpair1[1]-1,inpair2[1]-1,-1):
            outlist.append((inpair1[0],i))
            t = i
    else:
        t = inpair1[1]
    for j in range(inpair1[0]+1,inpair2[0]+1):
        outlist.append((j,t))
    outlist = [ ( outlist[i][0], outlist[i][1], outlist[i+1][0], outlist[i+1][1] ) for i in range(len(outlist)-1)]

    return outlist


h, w = [ int(v) for v in input().split() ]
odd_list = []
odd_list_2 = []
odd_list_3 = []
for i in range(h):
    line = [ int(v)%2 for v in input().split() ]
    if line.count(1) >= 1:
        temp_list = []
        for j in range(w):
            
            if line[j] % 2 == 1:
                temp_list.append((i,j))
        odd_list_2.append(temp_list)
        odd_list.append([[i,0],[i,w-1]])


for i in range(len(odd_list)):
    if i % 2 == 1:
        odd_list[i] = list(reversed(odd_list[i]))
        odd_list_2[i] = list(reversed(odd_list_2[i]))
    odd_list_3 += odd_list_2[i]
odd_list_3.append((h,w))


total_move_list = []
for i in range(len(odd_list)):
    total_move_list += movement(odd_list[i][0],odd_list[i][1])
    if i != len(odd_list) - 1:
        total_move_list += movement(odd_list[i][1],odd_list[i+1][0])
    

rec = -1
z = 0
x, y = odd_list_3[0]
anslist = []
for i in total_move_list:
    if i[0] == x and i[1] == y:
        rec *= -1
        z += 1
        x, y = odd_list_3[z]
    if rec == 1:
        anslist.append(i)


print(len(anslist))
for i in anslist:
    print(i[0]+1,i[1]+1,i[2]+1,i[3]+1)

Measured memory_bytes: 111952
#include <iostream>
using namespace std;
int main(){
    int N;//枚数
    int Y,M;//金
    int SUM;
    cin >> N >> Y;
    M=Y/1000;
    int a,b,c;//10,5,1
    a=0;
    b=0;
    c=M%5;
    for(int k=1;k>0;k++){
        SUM=10*a+5*(N-a-c)+c;
        b=N-(a+c);
        if (b<0){
            printf("-1 -1 -1");
            break;
        }
        if (SUM==M){
            printf("%d %d %d",a,b,c);
            break;
        }
        if (SUM>M){
            c=c+5;
        }
        if (SUM<M){
            a++;
        }
    }
}


Measured memory_bytes: 888
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a=sc.nextInt();
    int b=sc.nextInt();
      if(a<b)System.out.println("a < b");
      else if(a==b) System.out.println("a == b");
      else if(b<a) System.out.println("a > b");
     sc.close();
  }
}


Measured memory_bytes: 26116