akhauriyash/Code-Regression huggingface dataset:
//by yjz
#include<bits/stdc++.h>
using namespace std;
#define FF first
#define SS second
#define PB push_back
#define MP make_pair
#define bged(v) (v).begin(),(v).end()
#define foreach(it,s) for(__typeof((s).begin()) it=(s).begin();it!=(s).end();it++)
typedef long long ll;
const int Imx=2147483647;
const ll Lbig=2e18;
const int mod=1e9+7;
//My i/o stream
struct fastio
{
	char s[100000];
	int it,len;
	fastio(){it=len=0;}
	inline char get()
	{
		if(it<len)return s[it++];it=0;
		len=fread(s,1,100000,stdin);
		if(len==0)return EOF;else return s[it++];
	}
	bool notend()
	{
		char c=get();
		while(c==' '||c=='\n')c=get();
		if(it>0)it--;
		return c!=EOF;
	}
}_buff;
#define geti(x) x=getnum()
#define getii(x,y) geti(x),geti(y)
#define getiii(x,y,z) getii(x,y),geti(z)
#define puti(x) putnum(x),putchar(' ')
#define putii(x,y) puti(x),puti(y)
#define putiii(x,y,z) putii(x,y),puti(z)
#define putsi(x) putnum(x),putchar('\n')
#define putsii(x,y) puti(x),putsi(y)
#define putsiii(x,y,z) putii(x,y),putsi(z)
inline ll getnum()
{
	ll r=0;bool ng=0;char c;c=_buff.get();
	while(c!='-'&&(c<'0'||c>'9'))c=_buff.get();
	if(c=='-')ng=1,c=_buff.get();
	while(c>='0'&&c<='9')r=r*10+c-'0',c=_buff.get();
	return ng?-r:r;
}
template<class T> inline void putnum(T x)
{
	if(x<0)putchar('-'),x=-x;
	register short a[20]={},sz=0;
	while(x)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1;i>=0;i--)putchar('0'+a[i]);
}
inline char getreal(){char c=_buff.get();while(c==' '||c=='\n')c=_buff.get();return c;}
string s;
int main()
{
	cin>>s;
	if(s.size()>=4&&s.substr(0,4)=="YAKI")puts("Yes");
	else puts("No");
	return 0;
}

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

vector<int> BubbleSort(vector<int> A, int &count){
	int flag = 1;
	while(flag){
		flag = 0;
		for(int j = A.size() - 1; j >= 1; j--){
			if(A[j] < A[j-1]){
				swap(A[j], A[j-1]);
				flag = 1;
				count++;
			}
		}
	}
	return A;
}

void Output(vector<int> A){
	int n = A.size() - 1;
	for(int i = 0; i < n; i++) cout << A[i] << ' ';
	cout << A[n] << endl;
}

int main(){
	int N;
	cin >> N;
	vector<int> A;
	A.resize(N);
	for(int i = 0; i < N; i++) cin >> A[i];
	int count = 0;
	A = BubbleSort(A, count);
	Output(A);
	cout << count << endl;
	return 0;
}

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

using namespace std;

int main() {
   ios_base :: sync_with_stdio(0);
   cin.tie(0) , cout.tie(0);
   int k , x;
   cin >> k >> x;
   if (k * 500 < x) {
      cout << "No" << '\n';
   } else {
      cout << "Yes" << '\n';
   }
   return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <numeric>
#include <map>
#include <iomanip>
#include <limits.h>

using namespace std;    
typedef long long ll;
typedef pair<ll, ll> pll;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
const bool DEBAG = false;
const ll mod = 998244353;

int main(){

    ll N;
    cin >> N;

    vector<ll> v(N);
    for(int i = 0; i < N; i++) cin >> v[i];


    vector<ll> cnt(N);
    for(int i = 0; i < N; i++){
        cnt[ v[i] ] ++;
    }


    if(cnt[0] != 1){
        cout << 0 << endl;
        return 0;
    }
    if(v[0] != 0){
        cout << 0 << endl;
        return 0;
    }
    auto v_max = *max_element( all(v) );

    ll ans = 1;
    for(int i = 1; i <= v_max; i++){
        if(cnt[i] == 0){
            cout << 0 << endl;
            return 0;
        }
        for(ll j = 0; j < cnt[i]; j++){
            ans *= cnt[i-1];
            ans %= mod;
        }
    }   
    cout << ans << endl;

}

Measured memory_bytes: 1792
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> Pll;
typedef pair<P,P> PP;
#define rep(i,a,n) for(int i = a;i < n;i++)
#define LINF (ll)1e17
#define INF 1e9
#define MOD 1e9+7
#define sMOD 1e5
#define fs first
#define sc second

ll gcd(ll a,ll b){
	if(!b) return a;
	return gcd(b,a%b);
}


signed main(){
	
	ll n,ans = 1;
	cin >> n;
	ll a[n];
	
	rep(i,0,n){
		cin >> a[i];
		if(i == 0)ans = a[i];
		else ans = gcd(ans,a[i]);
	}
	
	cout << ans << endl;
	
	return 0;

}

Measured memory_bytes: 1024
#include <iostream>

using namespace std;

int main()
{
    int n,m,a;
    cin>>n>>m;
    for (int i=0;i<m;++i){
        cin>>a;
        n-=a;
    }
    if(n>=0){
        cout<<n;
    }
    else {
        cout<< "-1";
    }
    return 0;
}


Measured memory_bytes: 3640
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <climits>
#include <assert.h>
#include <cstring>
#include <set>

using namespace std;

typedef long long ll;

int main()
{
    int N, X, T;
    cin >> N >> X >> T;
    cout << (N+X-1)/X*T;
    
}

Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const int inf = 1<<30;

int main() {
  int N; cin >> N;
  vector<int> A(N), B(N);
  for(int i = 0; i < N-1; ++i) {
    cin >> B[i];
  }
  B[N-1] = inf;
  int ans = 0;
  for(int i = 0; i < N; ++i) {
    ans += (i == 0) ? B[i] : min(B[i-1], B[i]);
  }
  std::cout << ans << std::endl;
  return 0;
}


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

int cmpnum(const void * n1, const void * n2)
{
	if (*(double *)n1 > *(double *)n2)
	{
		return -1;
	}
	else if (*(double *)n1 < *(double *)n2)
	{
		return 1;
	}
	else
	{
		return 0;
	}
}

int main(void) {

  long n,m;
  scanf("%ld %ld", &n, &m);
  double a[n];
  for (long i = 0; i < n; i++) {
    scanf("%lf", &a[i]);
  }
  qsort(a, n, sizeof(double), cmpnum);
  long ticket = 0;
  while (ticket < m) {
    a[0] /= 2;
    ticket++;
    for (long i = 1; i < n; i++) {
      if (ticket == m) {
        break;
      }
      if (a[i] > a[0]) {
        a[i] /= 2;
        ticket++;
      } else {
        break;
      }
    }
    if (ticket == m) {
      break;
    }
    qsort(a, n, sizeof(double), cmpnum);
  }
  long sum = 0;
  for (long i = 0; i < n; i++) {
    sum += a[i]/1;
  }
  printf("%ld\n", sum);

  return 0;
}

Measured memory_bytes: 1788
import math
x = input().split()
n = int(x[0])
a = int(x[1])
b = int(x[2])
z = 0
z = math.floor(n / (a+b)) * a
amari = math.floor(n % (a+b))
if amari == 0:
  pass
elif amari <= a:
  z += amari
else:
  z += a
print(z)

Measured memory_bytes: 3060
// clang-format off
#include <bits/stdc++.h>

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (int i = 0; i < int(n); i++)
#define forn1(i,n) for (int i = 1; i <= int(n); i++)
#define popcnt __builtin_popcount
#define ffs __builtin_ffs
#define ctz __builtin_ctz
#define clz __builtin_clz
#define all(a) (a).begin(), (a).end()
 
using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
using pil = pair<int,ll>;
using pll = pair<ll,ll>;
template <typename T> using vec = vector<T>;
using vi = vec<int>;
using vl = vec<ll>;
template <typename T> using que = queue<T>;
template <typename T> using deq = deque<T>;

template <typename T> T id(T b) {return b;};
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}
template <typename S, typename K> bool contains(S &s, K k) { return s.find(k) != s.end(); }
void fastio() { ios_base::sync_with_stdio(false); cin.tie(nullptr); }
constexpr ll TEN(int n) { if (n == 0) return 1LL; else return 10LL*TEN(n-1); }
// clang-format on

int a[32] = { 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51 };

int main() {
    fastio();

    int k;
    cin >> k;
    cout << a[k - 1] << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <sstream>
#include <algorithm>

#define INPUT_FROM_FILE (0)
#if INPUT_FROM_FILE
#include <fstream>
#endif

int main(int argc, char **argv){
#if INPUT_FROM_FILE
	std::ifstream ifs("test.txt");
#endif
	std::string buf;

#if INPUT_FROM_FILE
	std::getline(ifs, buf);
#else
	std::getline(std::cin, buf);
#endif
	for(int i = 0; i < buf.size(); i++){
		char c = buf.at(i);
		if(c >= 'a' && c <= 'z'){
			c = toupper(c);
		}
		else if(c >= 'A' && c <= 'Z'){
			c = tolower(c);
		}
		std::cout << c;
	}
	std::cout << std::endl;
	return 0;
}

Measured memory_bytes: 3140
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll MOD = 924844033;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-11;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
const int key = 30000;
int main() {
	int n; cin >> n;
	int p[20000];
	int a[20000], b[20000];
	rep(i, n) {
		cin >> p[i]; p[i]--;
		a[i] = (i + 1)*key;
		b[i] = (n - i)*key;
	}
	rep(i, n) {
		a[p[i]] -= n - i;
		b[p[i]] -= n - i;
	}
	cout << a[0];
	Rep(i, 1, n) {
		cout << " " << a[i];
	}
	cout << endl;
	cout << b[0];
	Rep(i, 1, n) {
		cout << " " << b[i];
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 896
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] array  = new int[n];
        for(int i=0;i<n;i++){
            array[i] = sc.nextInt();
        }
        
        int count = 1;
        for(int i:array){
            if(i==count) count++;
        }
        
        if(count == 1){
            System.out.print("-1");
        } else {
            System.out.print(n-count+1);
        }
    }
}


Measured memory_bytes: 85108
import java.util.*;
import java.lang.*;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        if (a >= b && a >= c) {
            System.out.println(10 * a + b + c);
        }else if (b >= a && b >= c) {
            System.out.println(10 * b + a + c);
        }else{
            System.out.println(10 * c + a + b);
        }
    }
}

Measured memory_bytes: 23252
#include <bits/stdc++.h>
using namespace std;
const int N = 2e3 + 50;
int a[N];

int main() {
	int n, ans = 0;
    cin>>n;
    for(int i=0;i<n;i++) {
    	scanf("%d", &a[i]);
    }
    sort(a, a + n);
    // for(int i=0;i<n;i++)
    //     printf("%d ", a[i]);
    // printf("\n");
    
  	for(int i=0;i<n-2;i++) {
  	    int pos = 2;
    	for(int j=i+1;j<n-1;j++) {
            while(a[pos] < a[i] + a[j] && pos < n) {
            	pos ++;
            }
            ans += (pos - 1 - j);
            // printf("%d %d %d\n", a[i], a[j], a[pos]);
        }
    }
    printf("%d\n", ans);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ld double
#define ull unsigned long long
#define ll long long
#define pii pair<int,int >
#define iiii pair<int,pii >
#define mp make_pair
#define INF 1000000000
#define MOD 1000000007
#define rep(i,x) for(int (i)=0;(i)<(x);(i)++)
inline int getint(){
	int x=0,p=1;char c=getchar();
	while (c<=32)c=getchar();
	if(c==45)p=-p,c=getchar();
	while (c>32)x=x*10+c-48,c=getchar();
	return x*p;
}
using namespace std;
//ruogu_alter
const int N=45;
int n;
char s[N][N];
ll f[N][N][N][N],g[N][N][N][N];
//
ll get_f(int x,int y,int z,int w);
ll get_g(int x,int y,int z,int w){
	if(x>y||z>w)return 0ll;
	if(g[x][y][z][w]>=0)return g[x][y][z][w];
	ll res=0;
	for(int i=x;i<=y;i++){
		for(int j=z;j<=w;j++)if(s[i][j]=='1'){
			res+=get_f(x,i-1,i+1,y)*get_f(z,j-1,j+1,w);
		}	
	}
	return g[x][y][z][w]=res;
}
ll get_f(int x,int y,int z,int w){
	if(x>y&&z>w)return 1;
	if(f[x][y][z][w]>=0)return f[x][y][z][w];
	ll res=0;
	for(int i=x;i<=y;i++){
		for(int j=z;j<=w;j++){
			res+=get_g(x,i,j,w)*get_f(i+1,y,z,j-1);
		}
	}
	return f[x][y][z][w]=res;
}
int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	n=2*getint();
	rep(i,n)scanf("%s",s[i]);
	memset(f,-1,sizeof(f));
	memset(g,-1,sizeof(g));
	ll res=0;
	for(int i=1;i<n;i++)if(s[0][i]=='1')res+=get_f(1,i-1,i+1,n-1);
	cout<<res<<endl;
	return 0;
}


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

int main(){
    int N,M; cin >> N >> M;
    int st=pow(10,N-1);
    if(st==1) st=0;
    int k=pow(10,N);
    vector<int> s(M),c(M);
    for(int i=0; i<M; i++){
        cin >> s.at(i) >> c.at(i);
    }
    int check;
    for(int i=st; i<k; i++){
        check=1;
        for(int j=0; j<M; j++){
            if(to_string(i).at(s.at(j)-1)-'0'!=c.at(j)) check=-1;
        }
        if(check==1){
            cout << i << endl;
            break;
        }
    }
    if(check==-1) cout << -1 << endl;
    
}


Measured memory_bytes: 4028
#include<stdio.h>
int main(){
  int ans = 700;
  char s[4];
  scanf("%s",&s);
  for(int i = 0;i < 3;i++){
    if(s[i] == 'o'){
      ans += 100;
    }
  }
  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 128
// Problem : A - Multiplication 1
// Contest : AtCoder - AtCoder Beginner Contest 169
// URL : https://atcoder.jp/contests/abc169/tasks/abc169_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include    <bits/stdc++.h>
#include    <ext/pb_ds/assoc_container.hpp>
#include    <ext/pb_ds/tree_policy.hpp>
using       namespace            std;
using       namespace            __gnu_pbds;
using       ll=                  int64_t ;
using       ull=                 unsigned long long ;
using       ld=                  long double;
#define     int                  int64_t
#define     mem(a,val)           memset( a,  val,  sizeof(a) )
#define     b_s                  binary_search
#define     u_b                  upper_bound
#define     l_b                  lower_bound
#define     nl                   cout<<endl
#define     pb                   push_back
#define     pf                   push_front
#define     ppb                  pop_back
#define     ppf                  pop_front
#define     in                   insert
#define     fi                   first
#define     se                   second
#define     pqueue               priority_queue
#define     rr                   return
typedef     tree<int, null_type,less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;


/*#include <boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;*/

const int   N=                   1e6+7;
const int   MOD=                 (int)1e9 + 7;
const int   MOD1=                (int)1e9 + 9;
const int   MOD2=                998244353;
const ld    pi=                  atan2(0, -1);
const ld    eps=                 1e-9;
int         tests=               1;

template<class x,class y>x max(x a,y b){return (a>b)?a:b;}
template<class x,class y>x min(x a,y b){return (a<b)?a:b;}
template<class x,class y>x log(x n,y r){return (n>r-1)?1+log(n/r,r):0;}

vector<int> adj[N],subset;
int vis[N]={0};
///.'.'.'.'.'.'.'.'.'.'.'.'.'.'.'.'.'.'.'.'.'.'.'.'.'.'.'.'.'.'.'.'.'.'.'.'.'.'.'.'.'.'.


int32_t main() 
{
	auto start = clock();
	ios_base::sync_with_stdio(0);
	cout.tie(0);
	cin.tie(0);	

//	cout<<fixed;
//	cout<<scientific;
	cout<<fixed<<setprecision(12);
	// cin>>tests;
	for(int test=1;test<=tests;test++) 
	{
//		cout<<"Case #"<<test<<": ";
///.'.'.'.'.'.'.'.'.'.'.'.'.'.'.'.'.'.'.'.'.'.'.'.'.'.'.'.'.'.'.'.'.'.'.'.'.'.'.'.'.'.'.

		
		
		
		int a,b;
		cin>>a>>b;
		cout<<a*b;
		
		
		
		
		
		
		
		
		
		
		
		
		
///.'.'.'.'.'.'.'.'.'.'.'.'.'.'.'.'.'.'.'.'.'.'.'.'.'.'.'.'.'.'.'.'.'.'.'.'.'.'.'.'.'.'.
		
	}
	cerr<<endl<<endl<<endl<< "Time : " << double(clock() - start) / CLOCKS_PER_SEC <<endl;
	return 0;
}


Measured memory_bytes: 27244
#include <stdio.h>
typedef long long int ll;
int gcd(ll a,ll b){
    if (!(a%b)){return b;}
    return gcd(b,a%b);
}
int cnt(ll a1,ll m1,ll x){
    x=(a1*x)%m1;
    int c=1;
    while(x!=1){
        x=(a1*x)%m1;
        c++;
    }
    return c;
}

int main(void){
    ll a1,m1,a2,m2,a3,m3;
    while(1){
        scanf("%lld",&a1);
        scanf("%lld",&m1);
        scanf("%lld",&a2);
        scanf("%lld",&m2);
        scanf("%lld",&a3);
        scanf("%lld",&m3);
        if(!a1 && !m1 && !a2 && !m2 && !a3 && !m3){break;}
        ll x=1,y=1,z=1;
        ll cx,cy,cz;
        cx=cnt(a1,m1,x);
        cy=cnt(a2,m2,y);
        cz=cnt(a3,m3,z);
        ll g1,t1,g2,v;
        if(cx>cy){
            g1=gcd(cx,cy);
        }
        else{
            g1=gcd(cy,cx);
        }
        t1=cx*cy/g1;
        if(t1>cz){
            g2=gcd(t1,cz);
        }
        else{
            g2=gcd(cz,t1);
        }
        v=cz*t1/g2;
        printf("%lld\n",v);
    }
    return 0;
}



Measured memory_bytes: 2124
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
#include <algorithm> 
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i,n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<"\n"
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define mp make_pair
#define sz(x) (ll)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using vc = vector<char>;
using vvc = vector<vc>;
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; 
}
ll dx[4]={0,1,0,-1};
ll dy[4]={1,0,-1,0};
int main(){
  ll n,k;
  cin>>n>>k;
  vll p(n),c(n);
  rep(i,n){
    cin>>p[i];
    p[i]--;
  }
  rep(i,n) cin>>c[i];
  ll ans=-INF;
  rep(i,n){
    vll syc(0);
    ll cu=0;
    ll now=i;
    while(1){
      now=p[now];
      syc.pb(c[now]);
      cu+=c[now];
      if(i==now) break;
    }
    vll sycc(sz(syc)+1);
    sycc[0]=0;
    rep(j,sz(syc)){
      sycc[j+1]=syc[j]+sycc[j];
    }
    ll ccu=-INF;
    for(int j=1;j<=sz(syc);j++){
      if(k<j) continue;
      if(k-j>=sz(syc)){
        if(cu>0){
          chmax(ccu,sycc[j]+(k-j)/sz(syc)*cu);
        }
        else chmax(ccu,sycc[j]);
      }
      else{
        chmax(ccu,sycc[j]);
      }
    }
    chmax(ans,ccu);
  }
  COUT(ans);
}

Measured memory_bytes: 3816
#include <algorithm>
#include <boost/multiprecision/cpp_int.hpp>
#include <cmath>
#include <deque>
#include <iostream>
#include <queue>
#include <string>
#include <vector>

using namespace std;
using ll = long long;
namespace mp = boost::multiprecision;
using mpint = mp::cpp_int;  // 多倍長整数（任意精度）

/*
 * 定数
 */
const long double PI = (acos(-1));
const long double EPS = 1e-10;
const long long INF = 1e18;

/*
 * データ変換 
 */
/* char -> int */
int ctoi(char c) { return (int)(c - '0'); }

/*
 * 数学的な計算
 */
/* 階乗 */
int factorial(int n) {
  int ret = 1;
  for (int i = 1; i < n + 1; ++i) {
    ret = ret * i;
  }
  return ret;
}

/* 最大公約数 */
template <typename T>
T gcd(T x, T y) { return x % y == 0 ? y : gcd(y, x % y); }

/* 最小公倍数 */
template <typename T>
T lcm(T a, T b) { return a * b / gcd(a, b); }

/* n個の整数の最小公倍数 */
template <typename T>
T lcm_n(vector<T> &numbers) {
  T l;
  l = numbers[0];
  for (int i = 1; i < numbers.size(); ++i) {
    l = lcm(l, numbers[i]);
  }
  return l;
}

/*
 * DP向け
 */
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;
}

/**
 * @param N 素因数分解する整数
 * @param result N = 2^3 * 3^2の場合、{{2, 3}, {3, 2}}のような形式のvectorが生成される
 * @brief 2, 3,..., √Nまでの整数をNで割っていき、割り切れる数と割った回数を保存することで、素因数分解を行う。
 *        O(√N)
*/
void prime_factorize(ll N, vector<pair<ll, ll>> &result) {
  for (ll a = 2; a * a <= N; ++a) {
    if (N % a != 0) continue;
    ll ex = 0;  // 指数

    // 割れる限り割り続ける
    while (N % a == 0) {
      ++ex;
      N /= a;
    }

    result.emplace_back(pair<ll, ll>{a, ex});
  }

  // 最後に残った数
  if (N != 1) result.emplace_back(pair<ll, ll>{N, 1});
}

int main() {
  ll N;
  mpint ans = 1;
  cin >> N;
  vector<ll> A(N);

  for (int i = 0; i < N; ++i) {
    cin >> A[i];
    if (A[i] == 0) {
      cout << 0 << endl;
      return 0;
    }
  }

  for (int i = 0; i < N; ++i) {
    ans *= A[i];
    if (1'000'000'000'000'000'000 < ans) {
      ans = -1;
      break;
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 4104
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define int  long long
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define fast  ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define mod 998244353
// order_of_key and *find_by_order
int32_t main() {
	fast;
	string s;
	cin >> s;
	for (int i = 0; i < s.length(); i++) {
		if (s[i] == '?')
			s[i] = 'D';
	}
	cout << s;





}

Measured memory_bytes: 3768
from collections import defaultdict
d = defaultdict(int)
import sys
sys.setrecursionlimit(10**8)
def f(n,i):
  d[n]+=1
  if d[n]==2:
    return i
  if n%2==0:
    x=n//2
  else:
    x=3*n+1
  return f(x,i+1)
print(f(int(input()),1))



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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int N,A,B,Q;

int X[1111];char C[1111];

int Y[1111],H[1111];

int latte(int x){
    while(true){
        int k=upper_bound(Y,Y+B,x)-Y;
        k--;
        if(H[k]==-1)break;
        int l=Y[k+1]-Y[k];
        int d=Y[k]-H[k];
        if(d<l){
            x=Y[k]+(x-Y[k])%d;
        }
        x-=d;
    }
    return x;
}

signed main(){
    cin>>N>>A>>B>>Q;
    rep(i,A)cin>>X[i]>>C[i],X[i]--;

    Y[0]=0;H[0]=-1;
    rep(i,B){
        cin>>Y[i+1]>>H[i+1];
        Y[i+1]--;H[i+1]--;
    }
    Y[B+1]=N;B+=2;

    map<int,char>m;
    rep(i,A){
        int x=latte(X[i]);
        m[x]=C[i];
    }

    rep(i,Q){
        int x;cin>>x;
        x--;
        x=latte(x);
        if(m.find(x)==m.end())cout<<"?";
        else cout<<m[x];
    }cout<<endl;
    return 0;
}

Measured memory_bytes: 3172
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <queue>

using namespace std;

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

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

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

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

struct Era{
  string str;
  LL dur, year;
  bool operator<(const Era& rhs)const{
	return year < rhs.year;
  }
};

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

  int N, Q;
  while(cin>>N>>Q,N){
	vector<Era> eras(N);
	REP(i,N)
	  cin >> eras[i].str >> eras[i].dur >> eras[i].year;
	SORT(eras);
	REP(i,Q){
	  Era dummy;
	  cin >> dummy.year;
	  auto it = lower_bound(eras.begin(), eras.end(), dummy);
	  if(it == eras.end())
		cout << "Unknown" << endl;
	  else{
		int ans = dummy.year - (it->year - it->dur);
		if(ans <= 0)
		  cout << "Unknown" << endl;
		else
		  cout << it->str << " " << ans << endl;
	  }
	}
  }
  
  return 0;
}

Measured memory_bytes: 1296
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cout << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cout<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 300010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = 1 << 30;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
///////////////////////////////////////////////////////////////////////////////////////////////////

int N, M;
string S[1010];
ll dp[1010][1010];

void solve() {
	cin >> N >> M;
	rep(i, 0, N) cin >> S[i];
	dp[0][0] = 1;
	rep(i, 0, N) {
		rep(j, 0, M) {
			if(i + 1 < N && S[i + 1][j] != '#') {
				ADD(dp[i + 1][j], dp[i][j]);
			}
			if(j + 1 < M && S[i][j + 1] != '#') {
				ADD(dp[i][j + 1], dp[i][j]);
			}
		}
	}
	cout << dp[N - 1][M - 1] << "\n";
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
	srand((unsigned int)time(NULL));
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
    freopen("in.txt", "rt", stdin);
#endif	
	solve();
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}



Measured memory_bytes: 9216
import java.util.Scanner;

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

Measured memory_bytes: 26404
#include <bits/stdc++.h>
#include <iostream>
#include<math.h>
using namespace std;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
int main()
{
    int64_t N;
    cin >> N;
    vector<int64_t>vec(N);
    for (int64_t i=0; i<N; i++) {
        cin >> vec.at(i);
    }

    sort(vec.begin(), vec.end(), greater<int64_t>());
    int64_t point = 0;
    queue<int64_t>q;
    q.push(vec[0]);
    for (int64_t i=1; i<N; i++) {
        int64_t p = q.front();
        point += p;
        q.pop();
        q.push(vec[i]);
        q.push(vec[i]);
    }

    cout << point << endl;
    return 0;
}

Measured memory_bytes: 6368
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,i,cnt1=0,cnt2=0;
	cin>>n;

	int ara[n],ara1[n];
	for(i=0;i<n;i++){
		cin>>ara[i];
	}
	for(i=0;i<n;i++){
		cin>>ara1[i];
	}
	for(i=0;i<n;i++){
		if(ara[i]/ara1[i]>=1){
			cnt1+=ara[i];
			cnt2+=ara1[i];
		}
	}
	cout<<cnt1-cnt2<<endl;
	return 0;

}

Measured memory_bytes: 256
program main
    implicit none
    character s*11,t*11
    integer is, it, i, flag
    read(*,*) s
    read(*,*) t
    is = len_trim(s)
    it = len_trim(t)
    flag = 0
    
    if (it == is + 1) then
        do i = 1, is
            if (s(i:i) == t(i:i)) then
                flag = 0
            else
                flag = 1
                exit
            end if
        end do
        if(flag == 0) then
            write(*,*) "Yes"
        else if(flag == 1) then
            write(*,*) "No"
        end if
    else
        write(*,*) "No"
    end if


end program

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

int main() {
  int A,B,C;
  cin>>A>>B>>C;
  if((A==B && B==C)||(A!=B && B!=C && C!=A)){
    cout<<"No";
  }
  else{
    cout<<"Yes";
  }
  return 0;
}

Measured memory_bytes: 256
/*

*/
#include<iostream>
#include<iomanip>
#include<ios>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<string>
#include<algorithm>
#include<utility>
#include<math.h>
#include<cstdlib>
#define rep(i, n) for(int i=0;i<n;i++)
#define repb(i, a, b) for(int i=a;i<b;i++)
#define MAX_N 10000

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

const int INF = 1<<30;
const ll MOD = ll(1e9+7);

int main(){
  int n, m;cin>>n>>m;
  priority_queue<int> que;
  rep(i, n){
    int a;cin>>a;que.push(a);
  }
  while(m--){
    int a=que.top();que.pop();
    a /= 2;
    que.push(a);
  }
  ll sum = 0LL;
  while(que.size()){
    sum += que.top();que.pop();
  }
  cout<<sum<<endl;
  // system("read -n 1 -s -p \"Press any key to continue...\"");
}


Measured memory_bytes: 892
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define int LL
#define INF int(1e18)
int bit[200101], n;
int sum(int i)
{
	int s = 0;
	while(i > 0)
	{
		s += bit[i];
		i -= i & -i;
	}
	return s;
}
void add(int i, int x)
{
	while(i <= n)
	{
		bit[i] += x;
		i += i & -i;
	}
}

signed main()
{
	string s;
	deque<int> deq[26];
	int dis, mindis, getp, ans = 0;
	cin >> s;
	n = s.size();
	for(int i = 0; i < s.size(); i++)
	{
		deq[s[i] - 'a'].push_back(i);
	}
	for(int i = 0; i < s.size() / 2; i++)
	{
		mindis = INF;
		for(int j = 0; j < 26; j++)
		{
		//	cout << j << endl;
			if(deq[j].size() < 2) continue;
			dis = deq[j].front() - sum(deq[j].front() + 1) + (s.size() - 2 * i - 1 - (deq[j].back() - sum(deq[j].back() + 1)));
		//	cout << deq[j].front() << " " << deq[j].back() << " " << j << endl;
			if(mindis > dis)
			{
				mindis = dis;
				getp = j;
			}
		}

		//cout << i << " " << mindis << endl;
		if(mindis != INF)
		{
			add(deq[getp].front() + 1, 1);
			add(deq[getp].back() + 1, 1);
			deq[getp].pop_front();
			deq[getp].pop_back();
			ans += mindis;
		//	cout << mindis << " " << getp << endl;
		}
		else
		{
			cout << -1 << endl;
			return 0;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3716
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#include <numeric>
using namespace std;

typedef pair<int, int> P;

int main() {
	for(int N; cin >> N, N; ) {
		vector<P> v;
		for(int i = 0; i < N; i++) {
			int a, b;
			cin >> a >> b;
			v.push_back(make_pair(b, a));
		}
		sort(v.begin(), v.end());

		vector<int> w1, w2;
		for(int i = 0; i < N; i++) {
			w1.push_back(v[i].first);
			w2.push_back(v[i].second);
		}
		partial_sum(w2.begin(), w2.end(), w2.begin());

		bool f = true;
		for(int i = 0; i < N; i++)
			if(w1[i] < w2[i]) f = false;
		cout << (f ? "Yes" : "No") << endl;
	}
}

Measured memory_bytes: 1212
#include <iostream>
#include <array>
#include <algorithm>
#include <map>
#include <vector>
#include <list>
#include <cmath>
#include <stack>
#include <queue>
#include <climits>
#include <string.h>
#include <cctype>
#include <set>

#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using namespace std;

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

// a と b の最大公約数を返す関数
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

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

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

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
	ll x; // typedef long long ll;
	mint(ll x = 0) :x((x% mod + mod) % mod) {}
	mint operator-() const { return mint(-x); }
	mint& operator+=(const mint a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator-=(const mint a) {
		if ((x += mod - a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; }
	mint operator+(const mint a) const { return mint(*this) += a; }
	mint operator-(const mint a) const { return mint(*this) -= a; }
	mint operator*(const mint a) const { return mint(*this) *= a; }
	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	// for prime mod
	mint inv() const { return pow(mod - 2); }
	mint& operator/=(const mint a) { return *this *= a.inv(); }
	mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }

struct combination {
	vector<mint> fact, ifact;
	combination(int n) :fact(n + 1), ifact(n + 1) {
		fact[0] = 1;
		for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;
		ifact[n] = fact[n].inv();
		for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i;
	}
	mint operator()(int n, int k) {
		if (k < 0 || k > n) return 0;
		return fact[n] * ifact[k] * ifact[n - k];
	}
} comb(2000005);

mint g(int r, int c) {
	return comb(r + c + 2, r + 1) - 1;
}

bool comp(int i, int j) {
	return i > j;
}

bool compare_by_b(pair<int, int> a, pair<int, int> b) {
	return a.second < b.second;
}
vector<vector<int>> dd;

int main()
{
	long long a, b, n;
	cin >> a >> b >> n;
	if (n >= b - 1)
	{
		long long hidari = (long long)(a * (b - 1) / b);
		cout << hidari;
	}
	else
	{
		long long hidari = (long long)(a * n / b);
		long long migi = a * (long long)(n / b);
		cout << (hidari - migi);
	}
}



Measured memory_bytes: 34192
#include <iostream>
//#include <fstream>

using namespace std;

int main()
{
//	cut here before submit 
//	freopen ("testcase.tile2", "r", stdin );
	enum { RED = 1, BLUE = 2, YELLOW = 3 }; 
	int n, k;

	while (cin >> n >> k){

		for (int i = 0; i < k; ++i){
			int ai, bi, ci;
			cin >> ai >> bi;
			ai = min (ai, n - ai + 1);
			bi = min (bi, n - bi + 1);
			ci = min (ai, bi );
			int m = ci % 3;
			switch (m){
				case 0: cout << YELLOW << endl; break;
				case 1: cout << RED << endl; break;
				case 2: cout << BLUE << endl; break;
			} // end switch
		} // end for
	} // end loop
		
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define str string
#define vi vector<int>
#define vd vector<double>
#define vs vector<string>
#define repi(i, m, n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i, n) repi(i, 0, n)
#define revi(i, m, n) for(int i=(int)(m-1);i>=(int)(n);i--)
#define rev(i, n) revi(i, n, 0)
#define each(i, n) for(auto&& i: n)
#define pb push_back
#define mp make_pair
#define sz(v) ((int)(v).size()) 
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin() , (v).rend()
#define dump(x) cerr << #x << "=" << x <<endl
#define gcd __gcd
#define popcount __builtin_popcountll
int lcm(int a, int b){return a / gcd(a, b) * b;}
const int INF = 1e18;
const int MOD = 1e9 + 7;
const double EPS = 1e-15;
const double PI = acos(-1);

void solve() {
	int X; cin >> X;
	int ans = 0;
	ans += 1000 * (int)(X / 500);
	ans += 5 * (int)((X % 500) / 5);
	cout << ans << endl;
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);
	solve();
}

Measured memory_bytes: 256
import sys

def main():
  input = sys.stdin.readline
  A, B, K = map(int, input().split())
  ans = list(range(A, min(A+K, B))) + list(range(max(B-(K-1), A), B+1))
  ans = sorted(list(set(ans)))
  for i in ans:
    print(i)


if __name__ == '__main__':
  main()

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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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

const ll INF = 1e9;
const ll MOD = 1e9+7;
const ll LINF = 1e18;



signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  
  ll n,c; cin>>n>>c;
  vvll d(c, vll(c));
  rep(i,c) rep(j,c) cin>>d[i][j];
  vvll C(n, vll(n));
  rep(i,n) rep(j,n) cin>>C[i][j], C[i][j]--;
  
  vvll cost(3,vll(c));
  rep(ki,c){
    rep(i,n){
      rep(j,n){
        ll m=(i+j)%3;
        cost[m][ki]+=d[C[i][j]][ki];
      }
    }
  }
  
  ll ans=LINF;
  rep(i,c){
    rep(j,c){
      rep(k,c){
        if(i==j||j==k||k==i) continue;
        chmin(ans, cost[0][i]+cost[1][j]+cost[2][k]);
      }
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 2304
#include <iostream>
#include <stdio.h>

using namespace std;

int flag, a[10];

void f(int x0, int x1, int i)
{
	if (flag)
		return;
	if (i == 10)
	{
		flag = 1;
		return;
	}
	if (a[i] < x0 && a[i] < x1)
		return;
	if (a[i] > x0)
		f(a[i], x1, i + 1);
	if (a[i] > x1)
		f(x0, a[i], i + 1);
}

int main()
{
	int t, i;
	scanf("%d", &t);
	while (t--)
	{
		for (i = flag = 0; i < 10; i++)
			scanf("%d", &a[i]);
		f(0, 0, 0);
		if (flag)
			printf("YES\n");
		else
			printf("NO\n");
	}
	return 0;
}

Measured memory_bytes: 1168
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <numeric>
using namespace std;

int main()
{
  long long int N,M,ans=0;
  cin>>N>>M;
  vector <long long int> X(M),Y(M-1);
  for(int i=0;i<M;i++){
    cin>>X[i];
  }
  sort(X.begin(),X.end());
  for(int i=0;i<M-1;i++){
    Y[i]=X[i+1]-X[i];
  }
  sort(Y.begin(),Y.end());
  for(int i=0;i<M-N;i++){
    ans+=Y[i];
  }
  cout<<ans<<endl;
}


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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()
#define endl "\n"

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

  int N;
  cin>>N;
  vector<int>h(N);
  for(int i=0;i<N;i++)cin>>h[i];
  vector<int>dp(N,INT_MAX);
  dp[0]=0;
  for(int i=0;i<N;i++){
    if(i+1<N)dp[i+1]=min(dp[i+1],dp[i]+abs(h[i]-h[i+1]));
    if(i+2<N)dp[i+2]=min(dp[i+2],dp[i]+abs(h[i]-h[i+2]));
  }
  cout<<dp[N-1]<<endl;

  return 0;
}


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

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define m0(x) memset(x,0,sizeof(x))
#define print(x) cout<<x<<endl;
#define pe(x) cout<<x<<" ";
#define lb(v,n) lower_bound(v.begin(), v.end(), n);
#define ub(v,n) upper_bound(v.begin(), v.end(), n);
#define int long long
#define all(x) (x).begin(), (x).end()

using namespace std;

const int MAX = 1010000;
const int MOD = (ll)1000000000 + 7;
const ll INF = 1e17;
const double pi = acos(-1);
const double EPS = 1e-10;

typedef pair<int, int>P;


signed main() {
	int A, B, C; cin >> A >> B >> C;
	int ans = (C / A)*B;
	print(ans);
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstring>

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) unique(v.begin(), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
#define all(v) (v).begin(), (v).end()
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

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

	string s;
	cin >> s;
	int goo_count = 0, paa_count = 0;
	int win = 0, lose = 0;
	
	rep(i, 0, s.size()) {
		if(goo_count > paa_count) {
			if(s[i] == 'g') {
				win++;
			}
			paa_count++;
		} else {
			if(s[i] == 'p') {
				lose++;
			}
			goo_count++;
		}
	}

	int rsl = win - lose;
	cout << rsl << endl;


}


Measured memory_bytes: 512
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
#define MOD @
#define ADD(X,Y) ((X) = ((X) + (Y)%MOD) % MOD)
typedef long long i64; typedef vector<int> ivec; typedef vector<string> svec;

i64 N, A, B;

int main()
{
	scanf("%lld%lld%lld", &N, &A, &B);
	if ((B - A) % 2 == 0) {
		printf("%lld\n", (B - A) / 2);
	} else {
		i64 a = (A + B - 1) / 2;
		i64 b = (N - A + N - B + 1) / 2;
		printf("%lld\n", min(a, b));
	}
	return 0;
}


Measured memory_bytes: 256
while True:
    C = input()
    if C == "-":
        break
    m = int(input())
    for i in range(m):
        h = int(input())
        # print("%s %s"%(C[h:],C[:h]))
        C = C[h:] + C[:h] #h+1番目以降の+h番目まで(スライスを使用)
    print(C)



Measured memory_bytes: 5596
#include <bits/stdc++.h>
#include <string.h>
#include <vector>
//s#define rep(i, n) for (int i = 0; i < (n); i++)
#define MAX 10000

using namespace std;

#define ll long long
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define rep(i,a,n) for(int i=a; i<n; i++)
#define r0 return 0
#define INF (int)1e15
#define MOD 1000000007


 int main(){

  long long x,n;
  cin>>x>>n;

  vector<int>p(n);
  vector<int>num(301,0);

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

  for(int i=0;i<=100;i++)
 {
    if(num[x+100-i] == 0){
        cout<<x-i<<endl;
        break;
    }
    else if(num[x+100+i] == 0)
    {
        cout<<x+i<<endl;
        break;
    }
  }

 return 0;
 }

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

int main()
{
    ll a, b, v, w, t;
    cin >> a >> v >> b >> w >> t;

    if (w >= v)
    {
        cout << "NO" << endl;
        return 0;
    }

    if (abs(a - b) <= t * (v - w))
    {
        cout << "YES" << endl;
    }
    else
    {
        cout << "NO" << endl;
    }
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define rep(i ,n) for(int i=0;i<(int)(n);++i)
using namespace std;
typedef long long int int64;
typedef unsigned long long uint64;

int main(){
    int n; cin >> n;
    vector<int> a(n);
    rep(i ,n-1) { a[i]=i + 1; cout << i+1 << " "; }
    a[n-1] = n; cout << a[n-1] << endl;
    while(next_permutation(a.begin(),a.end())){
        rep(i ,n-1) cout << a[i] << " ";
        cout << a[n-1] << endl;
    }
}


Measured memory_bytes: 3080
#include <iostream>
#include <cmath>

using namespace std;

int main() {
  long n;
  cin >> n;
  long ans = 99999;
  while (n >= 100) {
    ans = min(ans, abs(n % 1000 - 753));
    n /= 10;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <tuple>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(perm),end(perm)
#define showall(obj) for(auto x:obj)cout<<x<<' ';
typedef long long ll;
typedef pair<int,int> ip;
typedef pair<ll,ll> lp;
typedef vector<int> vint;
typedef vector<ll> vll;
const int inf = 100100100;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

int main(){
    int s; cin>>s;
    set <int> al;
    int i;
    for(i = 1;; ++i){
        if(al.count(s) == 0){
            al.insert(s);
        }else{
            break;
        }
        if(s%2 == 0){
            s /= 2;
        }else{
            s = 3*s+1;
        }
    }
    cout<<i<<endl; return 0;
}


Measured memory_bytes: 256