akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using intl = long long;
using itnl = long long;
using itn = int;
using ld = long double;
using namespace std;
#define rep(i, n) for(intl i = 0; i < (intl)(n); i++)
#define rrep(i, n) for(intl i = (intl)(n) - 1; i >= 0; i--)
#define repi(i, a, b) for(intl i = (intl)(a); i < (intl)(b); i++)
#define rrepi(i, a, b) for(intl i = (intl)(a); i > (intl)(b); i--)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,1,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define alength(a) (sizeof(a) / sizeof(a[0]))
#define cin(i, a) rep(i, alength(a))cin >> a[i]
#define ccin(i, j, a) rep(i, alength(a))rep(j, alength(a[i]))cin >> a[i][j]
#define debug(x) cout << #x << ":" << x << endl
#define rdebug(i,x) rep(i, alength(x))cout << #x << "[" << i << "]:" << x[i] << endl
#define rrdebug(i, j, x) rep(i, alength(x))rep(j, alength(x[i]))cout << #x << "[" << i << "][" << j << "]:" << x[i][j] << endl
#define sqrt sqrtl
#define itn int
#define double ld
#define pb push_back
#define mp make_pair
#define pii pair<intl,intl>
const intl INF = 1e9;
const intl MOD = 1e9+7;
const ld EPS = 1.0e-14;//-9
const ld PI = acos(-1);
void fp(bool f){cout << (f ? "Yes" : "No") << endl;}
void fp(bool f, string s, string t){cout << (f ? s : t) << endl;}
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; }
intl kai(intl k){
    intl a = 1;
    for(int i = 2; i <= k; i++){
        a *= i;
    }
    return a;
}
intl gcd(intl a, intl b){ if(!b)return a; return gcd(b, a % b); }
intl lcm(intl a,intl b){ return a / gcd(a, b) * b; }
intl digit10(intl a){
    intl b = 0;
    do{
        a /= 10;
        b++;
    }while(a);
    return b;
}
//-------------------------------------------------------------------------------

intl n,m;
intl a[100000];
vector<pair<intl,intl> > p;
void input_var(){
    cin >> n >> m;
    p.resize(m);
    rep(i,n)cin >> a[i];
    rep(i,m){
        intl b,c;
        cin >> b >> c;
        p[i] =mp(c,b);
    }
}
//-------------------------------------------------------------------------------


signed main(){
    cout << fixed << setprecision(10);
    input_var();
    sort(all(p),greater<>());
    sort(a,a + n,greater<>());
    intl idx1 = 0;
    intl idx2 = 0;
    intl cnt = 0;
    intl sum = 0;
    rep(i,n){
        if(a[idx1] <= p[idx2].first){
            sum += p[idx2].first * min(p[idx2].second, n - cnt);
            cnt += min(p[idx2].second, n - cnt);
            idx2++;
        }
        else {
            sum += a[idx1];
            cnt++;
            idx1++;
        }
        if(cnt >= n)break;
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(ll i=0;i<n;i++)
#define FOR(i,n1,n2) for(ll i=n1;i<n2;i++)
#define bFOR(i,n1,n2) for(ll i=n1;i>=n2;i--)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
typedef long long int ll;
typedef pair<ll,ll> Pi;
typedef tuple<ll,ll,ll> Tu;
const int INF=(ll)(1LL<<30)-1;
const double INFd=100000000000.0;
const double PI=3.14151926535;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
const ll tMOD=(ll)998244353;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a, b)*b;}
int dx[4]={0,-1,0,1},dy[4]={-1,0,1,0};
int mdx[8]={0,1,0,-1,1,1,-1,-1},mdy[8]={-1,0,1,0,1,-1,1,-1};


template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int n;
int a[200100];
ll t[200100]={};
ll sum=0;
int main(){
    cin>>n;
    REP(i,n){
        cin>>a[i];
        a[i]--;
        t[a[i]]++;
    }
    REP(i,n){
        sum+=(t[i]*(t[i]-1))/2;
    }
    REP(i,n){
        cout<<sum-(t[a[i]]-1)<<endl;
    }
    return 0;
}

Measured memory_bytes: 3968
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define REP(i,m,n) for(int i=m;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define sort(vec) sort(vec.begin(),vec.end())
#define reverse(vec) reverse(vec.begin(),vec.end())
int gcd(int x,int y){
    if(x%y==0)return y;
    return gcd(y,x%y);
}
int a,b,c;
signed main(){
    cin>>a>>b>>c;
    int m=b/a;
    int ans=min(m,c);
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
typedef long long ll;
using namespace std;
int main()
{
  ll x;
  cin>>x;
  ll a[1000001];
  a[1]=7%x;
  for(int i=2;i<=x;i++)
  {
    a[i]=((a[i-1]*10)+7)%x;
  }
  int f=0;
  for(int i=1;i<=x;i++)
  {
    if(a[i]==0){
      cout<<i;
    return 0;}
  }
  cout<<-1;
  return 0;
}
  

Measured memory_bytes: 11344
#include<bits/stdc++.h>
using namespace std;
#define mk make_pair
int s[30001],ss[30001],c=2;
set<long long>se;
int main(){
  s[0]=2;s[1]=3;ss[2]=ss[3]=1;
  for(int i=2;i<30001;i++){
    int p=0;
    for(int j=2;j*j<=i;j++)
      if(i%j==0)p++;
    if(!p)ss[i]++,s[c++]=i;
  }
  int n;
  while(cin>>n,n){
    se.clear();
    int sum=0;
    for(int i=0;i<c;i++){
      if(s[i]>n/2+1)break;
      for(int j=0;j<c;j++){
        if(s[j]+s[i]>n)break;
        if(n-s[j]-s[i]>0)
          if(ss[n-s[j]-s[i]]){
            int d[3];
            d[0]=s[i];
            d[1]=s[j];
            d[2]=n-s[j]-s[i];
            sort(d,d+3);
            if(!se.count(d[0]*10000000000+d[1]*100000+d[2])&&d[0]+d[1]>d[2]){
              se.insert(d[0]*10000000000+d[1]*100000+d[2]);
              sum++;
            }
          }
        }
      }
      cout<<sum<<endl;
    }
  }

Measured memory_bytes: 5916
# coding: utf-8
# Your code here!

class Word:
    def __init__(self, word, cnt):
        self.word = word
        self.cnt = cnt

    def __lt__(self, other):
        if self.cnt == other.cnt:
            return self.word < other.word
        else:
            return self.cnt > other.cnt
            

while True:
    N = int(input())
    if N == 0:
        break
    
    str = []
    for l in range(N):
        str.extend(input().split())

    str.sort()
    k = input()
    words = []

    for i in range(len(str)):
        if str[i][0] == k:
            if len(words) > 0 and words[-1].word == str[i]:
                words[-1].cnt = words[-1].cnt + 1
            else:
                t = Word(str[i],1)
                words.append(t)

    if len(words) == 0:
        print("NA")
    elif len(words) < 5:
        words.sort()
        for i in range(len(words)-1):
            print(words[i].word, end = " ")
        print(words[-1].word)
    else:
        words.sort()
        for i in range(4):
            print(words[i].word, end = " ")
        print(words[4].word)
            
    



Measured memory_bytes: 5628
import sys,collections,math;sys.setrecursionlimit(10**7)
def Is(): return [int(x) for x in sys.stdin.readline().split()]
def Ss(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

a,b,k = Is()
sa,sb = set(),set()
for i in range(1,101):
    if a/i == a//i:
        sa.add(i)
    if b/i == b//i:
        sb.add(i)
sab = sa & sb
lis = sorted(sab)
print(lis[-k])

Measured memory_bytes: 3564
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<deque>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<iterator>
#include<complex>
#include<stack>
#include "stdio.h"
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const long long mod_const = 1e9+7;
using MIte = multimap<long, long, greater<long> >::iterator;

void Lower(ll idx, ll Level, ll& total) {
	ll nelem = pow(2, Level + 2) - 3;
	ll next_nelem = (nelem - 3) / 2;
	ll nP = pow(2, Level) - 1;

	ll nextidx = 0;
	if (idx > next_nelem + 2 && idx < nelem) {
		total += nP + 1;
		nextidx = idx - next_nelem - 2;
		Lower(nextidx, Level - 1, total);
	}
	else if (idx < next_nelem + 2 && idx > 1) {
		nextidx = idx-1;
		Lower(nextidx, Level - 1, total);
	}
	else if (idx == nelem) {
		total += 2 * nP + 1; // pow(2, Level + 1) - 1;
	}
	else if (idx == next_nelem + 2) {
		total += nP + 1;
	}
	else if (idx == 1) {
		if (Level == 0) {
			total += 1;
		}
	}
}

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

	// long long?
	ll N, X;
	cin >> N >> X;

	ll total = 0;
	Lower(X, N, total);

	cout << total << endl;

	return 0;

}

Measured memory_bytes: 256
#include <iostream>

int main()
{
	int n, m, h, w, a[510][510];
	std::cin >> n >> m >> h >> w;
	
	if (n % h == 0 && m % w == 0)
	{
		std::cout << "No";
	}
	else
	{
		std::cout << "Yes\n";
		for (int i = 0; i < n; ++i)
		{
			for (int j = 0; j < m; ++j)
			{
				if (i % h == 0 && j % w == 0)
					std::cout << 100000000 - 1;
				else if (i % h == h - 1 && j % w == w - 1)
					std::cout << -100000000;
				else
					std::cout << 0;
				std::cout << " ";
			}
			std::cout << "\n";
		}
	}
	
	
}

Measured memory_bytes: 2688
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define REP(i, n) for (int i = (n - 1); i >= 0; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1000000007;

int main(){
  int n;
  cin>>n;
  vector<ll>a(n);
  rep(i,n) {
    cin>>a[i];
  }
  ll total=1000;
  ll prev=a[0];
  rep(i,n){
    if(prev<a[i]) {
      total=total/prev*a[i]+total%prev;
       prev=a[i];
    }else{
      prev=min(prev,a[i]);
    }
  }

  cout<<total<<endl;

}


Measured memory_bytes: 3596
#include  <bits/stdc++.h>
using namespace std;
#define    error(args...){string _s=#args;replace(_s.begin(), _s.end(), ',', ' ');stringstream _ss(_s);istream_iterator<string> _it(_ss);err(_it,args);}
void err  (istream_iterator<string> it) {}
template  <typename T, typename... Args>
void err  (istream_iterator<string> it, T a, Args... args)
{
    cerr << *it << " = " << a <<" ; ";
    err(++it, args...);
    cout << endl;
}
/*----------------------------------------------------------------------------------------------------------------------------------------------------*/
/*Let's start.............*/
#define   ll                long long
#define   pb                push_back
#define   ff                first
#define   ss                second
#define   srt(v)            sort(v.begin(),v.end())
#define   inf               200000000000000000
#define   mxn               1000009
#define   MOD               1000000007
#define   pi                acos(-1)

int main()
{
    double r;
    cin >> r;
    double ans = 2.0*pi*r;
    printf("%.15lf",ans);
    //error(ans);
    return 0;
}

/*-------------------------------------------------------------------------------------------------------------------------------------------------------
".....but the truth is that you can increase it slightly."
Day 34.

// Learn to calculate the number of paths going through it
6
1 2 2 2 1 3
1 2
2 3
3 4
4 5
3 6

*/


Measured memory_bytes: 3740
#include<bits/stdc++.h>
using namespace std;
int main()
{
    char s[3];
    int c=0;
    scanf("%s",s);
    if(s[0]=='R' && s[1]=='R' && s[2]=='R')c=3;
    else if(s[0]=='R' && s[1]=='R' && s[2]=='S')c=2;
    else if(s[0]=='R' && s[1]=='S' && s[2]=='R')c=1;
    else if(s[0]=='R' && s[1]=='S' && s[2]=='S')c=1;
    else if(s[0]=='S' && s[1]=='R' && s[2]=='R')c=2;
    else if(s[0]=='S' && s[1]=='R' && s[2]=='S')c=1;
    else if(s[0]=='S' && s[1]=='S' && s[2]=='R')c=1;
    else if(s[0]=='S' && s[1]=='S' && s[2]=='S')c=0;
    cout<<c<<endl;

}


Measured memory_bytes: 3696
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(), (obj).end()
#define REP(i, n) for(int i = 0;i < (n);++i)

#define endl '\n'
#define pb push_back
#define mp make_pair
#define MOD 1000000007LL
#define INF 5000000000000000000
#define PI 3.1415926

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

// typedef long long ll;
#define int long long

template <typename T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <typename T> inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template <typename T> inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template <typename T> inline T nHr(T a,T b){return nCr(a+b-1,b);}
template <typename T> inline T POW(T a,T b){int i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}

#define MAX_V 100000
int V;
typedef pair<int, int> P;
struct edge {int to, cost;};
vector<edge> graph_yen[MAX_V], graph_snuuk[MAX_V];
int da[MAX_V], db[MAX_V];

void dijkstra_a(int s){
  fill(da, da+V, INF); da[s] = 0;
  priority_queue<P, vector<P>, greater<P> > que;
  que.push(P(0, s));
  while(!que.empty()){
    P a = que.top(); que.pop();
    if(da[a.second] < a.first) continue;
    REP(i, graph_yen[a.second].size()){
      edge e = graph_yen[a.second][i];
      if(da[e.to] > da[a.second]+e.cost){
        da[e.to] = da[a.second]+e.cost;
        que.push(P(da[e.to], e.to));
      }
    }
  }
}
void dijkstra_b(int s){
  fill(db, db+V, INF); db[s] = 0;
  priority_queue<P, vector<P>, greater<P> > que;
  que.push(P(0, s));
  while(!que.empty()){
    P a = que.top(); que.pop();
    if(db[a.second] < a.first) continue;
    REP(i, graph_snuuk[a.second].size()){
      edge e = graph_snuuk[a.second][i];
      if(db[e.to] > db[a.second]+e.cost){
        db[e.to] = db[a.second]+e.cost;
        que.push(P(db[e.to], e.to));
      }
    }
  }
}
signed main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);

	int m, s, t; cin >> V >> m >> s >> t;
	REP(i, m){
		int u, v, a, b; cin >> u >> v >> a >> b;
		graph_yen[u-1].pb({v-1, a}); graph_yen[v-1].pb({u-1, a});
		graph_snuuk[u-1].pb({v-1, b}); graph_snuuk[v-1].pb({u-1, b});
	}
	dijkstra_a(s-1); dijkstra_b(t-1);
	cerr << "faiz" << endl;
	int MIN = 1e15; vector<int> ans;
	for (int i = V-1; i >= 0; i--) {
		MIN = min(MIN, da[i]+db[i]);
		ans.pb(1e15 - MIN);
	}
	for (signed i = ans.size()-1; i >= 0; i--) {
		cout << ans[i] << endl;
	}

	return 0;
}

Measured memory_bytes: 19964
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
const int N=100010,M=1000010,P=1e9+7;
const int inf=0x3f3f3f3f;
const int INF=0xcfcfcfcf;
const double eps=1e-9,pi=asin(1)*2;
inline ll read();
#define cmax(a,b) a=max(a,b)
#define cmin(a,b) a=min(a,b)
inline int ADD(int a,int b) { return a+b>=P?a+b-P:a+b; }
inline int MINUS(int a,int b) { return a-b<0?a-b+P:a-b; }
#define plus(a,b) a=ADD(a,b)
#define minus(a,b) a=MINUS(a,b)
#define mul(a,b) a=(1ll*a*(b))%P
#define mem(a,b) memset(a,b,sizeof(a))
#define pii pair<int,int>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define pll pair<ll,ll>
#define mp(x,y) make_pair(x,y)

int n;
int a[N];

#ifdef FILE
const int RS=1<<20;
char buf[RS],*p1=buf,*p2=buf;
#define getchar() p1==p2&&(p2=(p1=buf)+fread(buf,1,RS,stdin),p1==p2)?EOF:*p1++
#endif
inline ll read()
{
	ll s=0;
	bool flag=false;
	char ch=getchar();
	for(;ch<'0'||ch>'9';ch=getchar()) if(ch=='-') flag=true;
	for(;'0'<=ch&&ch<='9';ch=getchar()) s=(s<<3)+(s<<1)+(ch^'0');
	if(flag) return -s;
	return s;
}

int main()
{
#ifdef FILE
	freopen(FILE ".in","r",stdin);
	freopen(FILE ".out","w",stdout);
#endif
	n=read();
	for(int i=1;i<=n;i++) a[i]=read();
	sort(a+1,a+n+1,greater<int>());
	int x=1;
	while(x<n&&x+1<=a[x+1]) x++;
	int xx=x;
	while(xx<n&&a[xx+1]>=x) xx++;
	if(((a[x]-x)|(xx-x))&1) printf("First\n");
	else printf("Second\n");
	return 0;
}

Measured memory_bytes: 640
//“Make it work, make it right, make it fast.” – Kent Beck
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double dd;
const int siz = 1e6 + 5;
const int MOD = 1e9 + 7;
#define endl '\n'
#define deb(x) cout << #x << " = " << x << endl;
void solve(){
	ll n;
	cin >> n;
	ll ans = LONG_MAX;
	for(ll i = 1; i*i <= n; i++){
		if(n%i==0){
			ll j = n/i;
			ll k = (i+j)-2;
			if(ans > k)
				ans = k;
		}
	}	
	cout << ans << endl;
}

int main(){
	#ifndef RAY
		//freopen("input.txt", "r", stdin);
	#endif
		ios::sync_with_stdio(false);
		cin.tie(nullptr);
		int t = 1;
		//cin >> t;
		while(t--){
			solve();
		}
	return 0;
}


Measured memory_bytes: 256
/*
auth - @sportykush
*/

#include <bits/stdc++.h>
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set; 
// using namespace __gnu_pbds;

typedef long long int ll;
typedef long double ld;

//#define mp make_pair
#define bug(v)                    cerr<<#v<<" = "<<(v)<<endl;
#define bug2(v1,v2)               cerr<<#v1<<" = "<<(v1)<< ' ' << #v2<<" = "<<(v2)<<endl;
#define ERASE(x)                  x.erase(unique(x.begin(),x.end()),x.end())
#define pb                        emplace_back
#define vii                       vector<int>
#define vll                       vector<ll>
#define vpll                      vector< pair <ll,ll> >
#define pll                       pair <ll,ll>
#define pii                       pair <int,int>
#define pq                        priority_queue< int >
#define khtm                      "\n"
#define F                         first
#define S                         second
#define fr(i,a,n)                 for(i=a;i<n;i++)
#define mem(arr,l)                memset(arr,l,sizeof arr)
#define ALL(x)                    x.begin(), x.end()
#define frr(i,a,n)                for(i=n-1;i>=a;i--)
#define fast                      ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define testcase                  ll T; cin>>T; while(T--)


const double pi = 3.14159265359;
const int MAX = 1e6 +2;
const ll inf =  1e18;
const int N = 1010;
const int dx[] = {-1, 0, 1, 0, 1, -1, -1, 1};
const int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
//const ll mod = 998244353;
const ll mod = 1000000007;
inline ll add(ll a,ll b){a+=b;if(a>=mod)a-=mod;return a;}
inline ll mul(ll a,ll b){return (((a+mod)%mod)*(b+mod)%mod)%mod;}
inline ll power(ll a,ll b){ll rt=1;while(b>0){if(b&1)rt=mul(rt,a);a=mul(a,a);b>>=1;}return rt;}
inline ll modInverse(ll n, ll p){ return power(n, p-2)%p; }

/*
important builtin functions
__gcd(value1, value2)
__builtin_ffs(x)
  Number of leading zeroes: __builtin_clz(x)
  Number of trailing zeroes : __builtin_ctz(x)
  Number of set bits: __builtin_popcount(x)
*/
 
void stArt()
{
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif
}
void eNd()
{
	#ifndef ONLINE_JUDGE
  	cout<<"\nTime Elapsed : " << 1.0*clock() / CLOCKS_PER_SEC << " s";
  	#endif
}

//////////////////// start /////////////////////////////////
 

ll i,j,k,l,m,r,n;
ll a[MAX],b[MAX];


int main()
{
 
stArt();
fast
//cout << setprecision(15) << fixed;

ll x,d;
cin >> x >> k >> d;
x = abs(x);
m = x;
x -= d*min(k,x/d);
k -= min(k,m/d);
//k -= min(k,x/d)
bug(k)
	if(k&1)
		cout << abs(x-d);
	else
		cout << x;




 eNd();
  return 0;
 
}

Measured memory_bytes: 3560
# A × B を求めてください。
# 169a

# a, b = map(int, input().split())

# 1 入力を受け取ること

a, b = map(int, input().split())
# print(a, b)


# 2 受け取った値を入力値を使って、適切に処理する
answer = a * b



# 3 計算した結果を出力すること
print(answer)

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

int N, C, X;
int D[30][39];
int t[3][30];

int main () {

    scanf("%d %d", &N, &C);
    
    for (int i = 0; i < C; i++) {
        for (int j = 0; j < C; j++) {
            scanf("%d", &D[i][j]);
        }
    }

    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            scanf("%d", &X);
            t[(i + j) % 3][X - 1]++;
        }
    }

    int res = 1 << 30;
    for (int i = 0; i < C; i++) {
        for (int j = 0; j < C; j++) {
            if (i != j) {
                for (int k = 0; k < C; k++) {
                    if (i != k && j != k) {
                        int tt = 0;

                        for (int l = 0; l < C; l++) {
                            if (l != i) {
                                tt += D[l][i] * t[0][l];
                            }
                        }
                        for (int l = 0; l < C; l++) {
                            if (l != j) {
                                tt += D[l][j] * t[1][l];
                            }
                        }
                        for (int l = 0; l < C; l++) {
                            if (l != k) {
                                tt += D[l][k] * t[2][l];
                            }
                        }

                        if (tt < res) res = tt;
                    }
                }
            }
        }
    }

    printf("%d\n", res);

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
*/

int main(){
    int N; cin >> N;
    vector<string> s(N);
    for(int i=0; i<N; i++) cin >> s[i];

    ll ans = 0;
    for(int i=0; i<N; i++) for(int j=0; j<s[i].size()-1; j++) if(s[i][j] == 'A' && s[i][j+1] == 'B') ans++;

    ll a = 0, b = 0, c = 0;
    for(int i=0; i<N; i++){
        if(s[i][0] == 'B' && s[i][s[i].size()-1] == 'A') a++;
        else if(s[i][0] == 'B') b++;
        else if(s[i][s[i].size()-1] == 'A') c++;
    }

    if(a != 0){
        ans += a-1;
        if(b > 0){
            ans++;
            b--;
        }
        if(c > 0){
            ans++;
            c--;
        }
    }

    ans += min(b,c);

    // ans += min(b, c);
    // //cout << ans << endl;
    // ll minv = min(b,c);
    // b -= minv;
    // c -= minv;
    
    // if(a != 0){
    //     //cout << a << endl;
    //     ans += a-1;
    //     //cout << ans << endl;
    //     if(b > 0) ans++;
    //     if(c > 0) ans++;
    // }
    cout << ans << endl;

}

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

int main(){
  int n,k;
  cin >> n >> k;
  
  int ans = 0;
  rep(i,n){
    int h;
    cin >> h;
    if(h >= k) ans++;
  }
  
  cout << ans << endl;
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int MaxN = 5003;
int n,k,a[MaxN];
int main() {
	scanf("%d%d",&n,&k);
	for (int i=1;i<=n;++i) scanf("%d",a+i);
	sort(a+1,a+n+1);
	int ans=0;
	for (int i=1;i<=n;++i) {
		int t=k;
		for (int j=n;j>=1;--j)
			if (t-a[j]>0 && i!=j) t-=a[j];
		if (t>a[i]) ans++;
	}
	printf("%d\n",ans);
	
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int n;
int a[300][300];
bool b[300][300];

int main(){
    int n; cin >> n;
    for(int i = 0; i < n; ++i){
        for(int j = 0; j < n; ++j){
            cin >> a[i][j];
        }
    }
    for(int i = 0; i < n - 1; ++i){
        for(int j = i; j < n; ++j){
            b[i][j] = true;
        }
    }


    for(int i = 0; i < n-2; ++i){
    for(int j = i+1; j < n-1; ++j){
    for(int k = j+1; k < n; ++k){
        if(a[i][j] + a[j][k] < a[i][k] || a[i][k] + a[k][j] < a[i][j] || a[k][i] + a[i][j] < a[j][k]){
            cout << -1 << endl;
            return 0;
        }
        else if(a[i][j] + a[j][k] == a[k][i]){
            b[i][k] = false;
        }else if(a[i][k] + a[k][j] == a[i][j]){
            b[i][j] = false;
        }else if(a[k][i] + a[i][j] == a[j][k]){
            b[j][k] = false;
        }else {}
    }
    }
    }
    long long ans = 0;
    for(int i = 0; i < n - 1; ++i){
        for(int j = i; j < n; ++j){
            if(b[i][j])ans += a[i][j];
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 640
# B
import sys
a_list = []
a = []
c = [False for i in range(9)]
for i in range(3):
    a_list = list(map(int, input().split()))
    for num in a_list:
        a.append(num)
n = int(input())
for i in range(n):
    num = int(input())
    if num in a:
        index = a.index(num)
        c[index] = True

if (c[0] and c[3] and c[6]) or (c[1] and c[4] and c[7]) or (c[2] and c[5] and c[8]) or (c[0] and c[1] and c[2]) or (c[3] and c[4] and c[5]) or (c[6] and c[7] and c[8]) or (c[0] and c[4] and c[8]) or (c[2] and c[4] and c[6]):
    print('Yes')
else:
    print('No')

Measured memory_bytes: 38384
if __name__ == '__main__':
    a,b = [int(a.strip()) for a in input().strip().split(' ')]
    min_a = int(12.5*a+0.5)
    max_a = int(12.5*(a+1)+0.5)
    # print(12.5*a+0.5)
    # print(max_a)
    # print(list(range(min_a,max_a)))

    min_b = 10*b
    max_b = 10*(b+1)

    flg = 0
    for i in range(min_a,max_a):
        if i in range(min_b,max_b):
            print(i)
            flg = 1
            break

    if flg == 0:
        print('-1')


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

int main(void) {
	int r, d, x;
	cin >> r >> d >> x;
	for (int i = 0; i < 10; i++) {
		x = r * x - d;
		cout << x << endl;
	}
	return 0;
}


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

int main() {
  string s, t;
  int a, b;
  string u;
  cin >> s >> t >> a >> b >> u;
  map<string, int> res;
  res[s] = a;
  res[t] = b;
  res[u]--;
  cout << res[s] << " " << res[t] << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;


public class Main{
	
	public static void main(String[] args){

		Map<String, Integer> m = new HashMap<String, Integer>();
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()) {
			String in = sc.next();
			if(m.containsKey(in.toLowerCase())) {
				m.put(in.toLowerCase(), m.get(in.toLowerCase())+1);
			}else m.put(in.toLowerCase(), 1);
		}
		sc.close();
		
		List<String> result = findMode(m);
		List<String> words = new ArrayList<String>();
		for(Map.Entry<String, Integer> e: m.entrySet()) words.add(e.getKey());
		String longest = longestWord(words.toArray(new String[words.size()]));
		
		System.out.println(result.get(0) + " " + longest);
	}
	
	static <K> List<K> findMode(Map<K, Integer> map){
		List<K> result = new ArrayList<K>();
		int max_value = 0;
		for(Map.Entry<K, Integer> e: map.entrySet()) {
			if(e.getValue() > max_value) {
				result = new ArrayList<K>();
				result.add(e.getKey());
				max_value = e.getValue();
			}else if(e.getValue() == max_value) {
				result.add(e.getKey());
			}
		}
		return result;
	}
	
	static String longestWord(String... words) {
		int length = 0;
		String word = null;
		for(String s: words) {
			if(s.length() > length) {
				length = s.length();
				word = s;
			}
		}
		return word;
	}
}

Measured memory_bytes: 17168
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REP(i,b) FOR(i,0,b)
#define RFOR(i,a,b) for (int i = a-1; i >= b; i--)
#define RREP(i,a) RFOR(i,a,0)
#define REPALL(i,v) for (int i = 0; i < v.size(); i++)
#define RREPALL(i,v) for (int i = v.size()-1; i >= 0; i--)
#define SORT(v) sort(v.begin(), v.end())
#define MIN_ELEMENT(v) min_element(v.begin(), v.end())
#define MAX_ELEMENT(v) max_element(v.begin(), v.end())
#define COUNT(v,n) count(v.begin(), v.end(), n);
void YES(bool flag) {cout<<(flag ? "YES" : "NO")<<endl;}
void Yes(bool flag) {cout<<(flag ? "Yes" : "No")<<endl;}
void yes(bool flag) {cout<<(flag ? "yes" : "no")<<endl;}
typedef long long ll;
typedef unsigned long long ull;
const int INF = 1e7;
const ll MOD = 1e9 + 7;

vector<int> cs(26, -1), ct(26, -1);

int main()
{
    string s, t;
    cin>>s>>t;
    int l = s.length();
    bool flag = true;
    REP(i,l) {
        if (cs[s[i] - 'a'] == -1) {
            cs[s[i] - 'a'] = t[i];
        } else {
            if (cs[s[i] - 'a'] != t[i]) {
                flag = false;
                break;
            }
        }

        if (ct[t[i] - 'a'] == -1) {
            ct[t[i] - 'a'] = s[i];
        } else {
            if (ct[t[i] - 'a'] != s[i]) {
                flag = false;
                break;
            }
        }
    }

    Yes(flag);

    return 0;
}


Measured memory_bytes: 904
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>

using namespace std;

int main()
{
	int N;
	long long ans = -pow(10, 12);
	cin >> N;

	vector<int> F(N, 0);
	vector<vector<int>> table(N, vector<int>(10 + 1));

	for (int i = 0; i < N; i++)
	{
		int b;
		for (int k = 9; k >= 0; k--)
		{
			cin >> b;
			F[i] += b * pow(2, k);
		}
	}

	for (int i = 0; i < N; i++)
	{
		for (int k = 0; k < 10 + 1; k++)
		{
			cin >> table[i][k];
		}
	}

	int bin = 1;
	while (bin <= 0b1111111111)
	{
		long long sum = 0;
		for (int i = 0; i < N; i++)
		{
			int count = 0;
			for (int k = 0; k < 10; k++)
			{
				if ((F[i] & bin & (1 << k)) != 0)
				{
					count++;
				}
			}

			sum += table[i][count];
		}

		if (ans < sum)
		{
			ans = sum;
		}

		bin++;
	}

	cout << ans << endl;

	return 0;
}


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

int main()
{
	char str[1024];
	char type;
	while (scanf("%s %c", str, &type), type != 'X'){
		char word[128][128];
		int j = 0;
		
		for (int i = 0; i < 128; i++){
			strcpy(word[i], "");
		}
		
		{
			int i = 0;
			while (str[i] != '\0'){
				if ( (str[i] >= 'a' && str[i] <= 'z') || i == 0 ){
					if (str[i] >= 'A' && str[i] <= 'Z'){
						str[i] += 32;
					}
					strncat(word[j], &str[i], 1);
					i++;
				}
				else if (str[i] >= 'A' && str[i] <= 'Z'){
					j++;
					str[i] += 32;
					strncat(word[j], &str[i], 1);
					i++;
				}
				else if (str[i] == '_'){
					i++;
					j++;
				}
			}
		}
		
		switch (type){
			case 'U':
			case 'L':
			for (int i = 0; i <= j; i++){
				if (i == 0 && type == 'L'){
					printf("%s", word[i]);
				}
				else {
					word[i][0] -= 32;
					printf("%s", word[i]);
				}
			}
			break;
			
			case 'D':
			for (int i = 0; i <= j; i++){
				if (i > 0){
					printf("_");
				}
				printf("%s", word[i]);
			}
		}
		
		puts("");
	}
	
	return 0;
}

Measured memory_bytes: 1004
use std::fmt;
use std::io::stdin;
use std::io::BufRead;
use std::str;
use std::str::FromStr;
use std::vec::Vec;
use std::cmp;

fn main() {
    let stdin = stdin();
    let mut scan = InputScanner::new(stdin.lock(),256);

    let h:usize = scan.next();
    let n:usize = scan.next();

    let ab:Vec<(usize,usize)> = (0..n).map(|_| (scan.next(),scan.next())).collect();

    let mut dp:Vec<usize> = (0..(h+1)).map(|_| 0).collect();

    for i in 0..n {
        for h in 1..(h+1) {
			if h < ab[i].0 && dp[h] == 0 {
				dp[h] = ab[0].1;
			} else if h < ab[i].0 {
				dp[h] = cmp::min(dp[h],ab[i].1);
			} else if dp[h] == 0 {
				dp[h] = dp[h-ab[i].0] + ab[i].1;
			} else {
				dp[h] = cmp::min(dp[h],dp[h-ab[i].0] + ab[i].1);
			}
        }
    }
    println!("{}",dp[h]);
}
struct InputScanner<R: BufRead> {
	reader: R,
	buf: Vec<u8>, // Should never be empty
	pos: usize,   // Should never be out of bounds as long as the input ends with '\n'
}
impl<R: BufRead> InputScanner<R> {
	fn new(reader: R, capacity: usize) -> Self {
		InputScanner {
			reader: reader,
			buf: Vec::with_capacity(capacity),
			pos: 0,
		}
	}

	#[inline]
	fn next<T: FromStr>(&mut self) -> T
	where
		T::Err: fmt::Debug,
	{
		if self.buf.is_empty() {
			self._read_next_line();
		}
		let mut start = None;
		loop {
			match (self.buf[self.pos], start.is_some()) {
				(b' ', true) | (b'\n', true) | (b'\r', true) => break,
				(_, true) | (b' ', false) => self.pos += 1,
				(b'\n', false) | (b'\r', false) => self._read_next_line(),
				(_, false) => start = Some(self.pos),
			}
		}
		let target = &self.buf[start.unwrap()..self.pos];
		unsafe { str::from_utf8_unchecked(target) }.parse().unwrap()
	}

	#[inline]
	fn _read_next_line(&mut self) {
		self.pos = 0;
		self.buf.clear();
		if self.reader.read_until(b'\n', &mut self.buf).unwrap() == 0 {
			panic!("Reached EOF");
		}
	}
}



Measured memory_bytes: 4352
#include <bits/stdc++.h>
#include <iomanip>
#include <math.h>
#include <unistd.h>
#include <stdio.h>
#define all(a) (a).begin(),(a).end()
#define vecin(a) rep(i,a.size())cin >> a[i]
#define vecout(a) rep(i,a.size()){cout << a[i];cout << (i == a.size() - 1 ? "\n":" ");}
#define rep(i,x) for(ll i = 0;i<x;i++)
#define REP(i,x) for(ll i = 1;i<=x;i++)
#define mp make_pair
using ll = long long;
using ld = long double;
using namespace std;
using dou = double;
const ll inf = 2147483647;
const ll INF = 1LL << 62;
const dou pi = 3.14159265358;
const ll mod = 1000000007LL;
//const ll mod = 998244353LL;
typedef pair<ll,ll> P;
using graph = vector<vector<ll>>;
template<class T, class U> inline bool chmin(T& a, const U& b){ if(a > b){ a = b; return 1; } return 0; }
template<class T, class U> inline bool chmax(T& a, const U& b){ if(a < b){ a = b; return 1; } return 0; }
template<class T, class U> inline bool change(T& a,U& b){if(a > b){swap(a,b);return 1;}return 0;}
template<class T>
T gcd(T a,T b){
    if(a < b)swap(a,b);
    if(a % b == 0)return b;
    else return gcd(b,a%b);
}
template<class T>
T lcm(T a,T b){
    return a / gcd(a,b) * b;
}

//素数判定O(sqrt(N))
template<class T>
inline bool isp(T n){
    bool res = true;
    if(n == 1)return false;
    else{
        for(ll i = 2;i * i <= n;i++){
            if(n % i == 0){
                res = false;
                break;
            }
        }
        return res;
    }
}
const ll cmax = 1000000;
vector<ll> fac(cmax),finv(cmax),inv(cmax);

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < cmax; i++){
        fac[i] = fac[i - 1] * i % mod;
        inv[i] = mod - inv[mod%i] * (mod / i) % mod;
        finv[i] = finv[i - 1] * inv[i] % mod;
    }
}

// 二項係数計算
ll nCk(ll n, ll k){
    if(fac[0] == 0)COMinit();
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
//nのm乗をMODで割ったあまりO(logm)
ll modpow(ll n,ll m,ll MOD){
    if(m == 0)return 1;
    if(m < 0)return -1;
    ll res = 1;
    while(m){
        if(m & 1)res = (res * n) % MOD;
        m >>= 1;
        n *= n;
        n %= MOD;
    }
    return res;
}
ll mypow(ll n,ll m){
    if(m == 0)return 1;
    if(m < 0)return -1;
    ll res = 1;
    while(m){
        if(m & 1)res = (res * n);
        m >>= 1;
        n *= n;
    }
    return res;
}


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    ll N;
    cin >> N;
    vector<ll> vec(2 * N);
    vecin(vec);
    sort(all(vec));
    //vecout(vec);
    ll ans = 0;
    for(ll i = 2 * N - 2;i >= 0;i -= 2){
        ans += vec[i];
    }
    cout << ans << endl;
}


Measured memory_bytes: 26536
#include<bits/stdc++.h>
using namespace std;
signed main(){
    int n;
    cin>>n;
    int d[n+2];
    for(int i=0;i<n;i++){
        cin>>d[i];
    }
    int sum=1;
    sort(d,d+n);
    for(int i=0;i<n-1;i++){
        if(d[i]!=d[i+1]){
            sum++;
        }
    }
    cout<<sum<<"\n";
    return(0);
}


Measured memory_bytes: 3640
MOD = 998244353
n, k = map(int, input().split())
cumulative_sum = [0 for _ in range(n+1)]
table = [0 for i in range(n)]
pair_list = []
for i in range(k):
    l, r = map(int, input().split())
    pair_list.append((l,r))

table[0] = 1
cumulative_sum[1] = 1
for i in range(1,n):
    root = 0
    for l, r in pair_list:
        l = max(i-l+1, 0)
        r = max(i-r,0)
        root += cumulative_sum[l]- cumulative_sum[r]
        root %= MOD
    table[i]= root % MOD
    cumulative_sum[i+1] = (cumulative_sum[i]+root)%MOD
    #print("step{}\n table:{}\n  cum:{}".format(i,table, cumulative_sum))

print(table[-1])


Measured memory_bytes: 24724
#include <iostream>
using namespace std;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int a, b, c;
    cin >> a >> b >> c;

    if(a == b){
        cout << c << "\n";
    }
    else if(a == c){
        cout << b << "\n";
    }
    else{
        cout << a << "\n";
    }
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
		char s[51];
		scanf("%s",s);
		char aki[10]="AKIHABARA";
		char akb[10]="KIHBR";
		int i=0,g,c=0;
		for(g=0;s[g]!=0;g++);
		if(g>9){
				puts("NO");
				return 0;
		}
		for(i=0;i<g;i++){
				if(s[i]=='A'){
						if(s[i+1]=='A'){
								puts("NO");
								return 0;
						}
						continue;
				}
				if(akb[c++]!=s[i]){
						puts("NO");
						return 0;
				}
				if(s[i]=='K'&&(s[i+1]!='I'||s[i+2]!='H')){
						puts("NO");
						return 0;
				}	
		}
		if(c!=5)puts("NO");
		else puts("YES");
		return 0;
}


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

int main()
{
	int num[3];
	cin >> num[0] >> num[1] >> num[2];

	for (int i = 0; i < 3; i++)
	{
		for (int j = i + 1; j < 3; j++)
		{
			if (num[j] < num[i])
			{
				int tmp = num[i];
				num[i] = num[j];
				num[j] = tmp;
			}
		}
	}

	for (int i = 0; i < 3; i++)
	{
		if (i < 2)
		{
			cout << num[i] << " ";
		}
		else
		{
			cout << num[i] << endl;
		}
	}
}

Measured memory_bytes: 3108
import collections
n = int(input())

d = collections.Counter(input())
for i in range(n - 1):
    words = collections.Counter(input())
    for w in words.keys():
        d[w] = min(words[w], d[w])
        
    for w in d.keys():
        d[w] = min(words[w], d[w])

ans = []
for char in d.keys():
    for i in range(d[char]):
        ans.append(char)

ans.sort()

print(''.join(ans))

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

#define itn int
#define all(x) (x).begin(), (x).end()
#define make_unique(x) sort(all((x))); (x).resize(unique(all((x))) - (x).begin())

using namespace std;

inline int nxt() {
	int x;
	scanf("%d", &x);
	return x;
}

const int N = 333;
int dp[N][N][N];

void relax(int& x, int y) {
	if (x == -1) {
		x = y;
	} else {
		x = max(x, y);
	}
}

int main() {
	string s;
	cin >> s;
	int k = nxt();
	int n = s.length();

	memset(dp, -1, sizeof(dp));
	dp[0][0][0] = 0;
	for (int i = 0; i <= n; ++i) {
		for (int j = 0; i + j <= n + 1; ++j) {
			for (int ij = 0; ij <= k; ++ij) {
				if (i == 0 && j == 0) {
					continue;
				}
				int& what = dp[i][j][ij];
				if (i) {
					relax(what, dp[i - 1][j][ij]);
				}
				if (j) {
					relax(what, dp[i][j - 1][ij]);
				}
				if (!i || !j) {
					continue;
				}
				bool diff = (s[i - 1] != s[n - j]);
				if (diff) {
					if (ij) {
						relax(what, dp[i - 1][j - 1][ij - 1] + 1);
					}
				} else {
					relax(what, dp[i - 1][j - 1][ij] + 1);
				}
			}
		}
	}

	int ans = -1;
	for (int i = 0; i < n; ++i) {
		for (int j = 0; i + j < n + 1; ++j) {
			for (int ij = 0; ij <= k; ++ij) {
				if (i + j == n) {
					relax(ans, dp[i][j][ij] * 2);
				} else {
					relax(ans, dp[i][j][ij] * 2 + 1);
				}
			}
		}
	}
	printf("%d\n", ans);

	return 0;
}

Measured memory_bytes: 144512
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <vector>
#include <bitset>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;


int main() {
	string s;
	cin >> s;
	vector<int> x(4);
	rep(i, 4) {
		x[i] = s[i] - '0';
	}

	string ans;
	rep(j, 8) {
		//長さ 3 の bitset を定義する
		bitset<3> bits(j);
		int sum = x[0];
		for (int i = 1; i < 4; i++) {
			if (bits[i - 1])sum += x[i];
			else sum -= x[i];
		}
		if (sum == 7) {
			ans = to_string(x[0]);
			for (int i = 1; i < 4; i++) {
				if (bits[i - 1])ans += '+';
				else ans += '-';
				ans += to_string(x[i]);
			}
			ans += "=7\n";
			break;
		}
	}
	cout << ans;
	return 0;
}



Measured memory_bytes: 3708
#include <bits/stdc++.h>
 
using namespace std;
 
#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< pii >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; cin >> x;
#define int2(x, y) Int(x); Int(y);
#define int3(x, y, z) Int(x); int2(y, z);
#define in(x, a, b) ((a) <= (x) && (x) < (b))
#define fir first
#define sec second
#define ffir first.first
#define fsec first.second
#define sfir second.first
#define ssec second.second
#define Decimal fixed << setprecision(10)
 
//int dxy[5] = {0, 1, 0, -1, 0};
// cmd
 
signed main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
 
    int2(n, q);
 
    int yui = 0;
    while (q--) {
        int2(a, b);
        if (a) {
            // swap
            yui = (yui + b) % n;
        } else {
            // output
            cout << (b + yui - 1) % n + 1 << endl;
        }
    }
 
    return 0;
}


Measured memory_bytes: 3220
# coding: utf-8

# In[1]:


def main():
    N,M = map(int, input().split())
    A = list(map(int, input().split()))
    
    match = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
    
    result = [-1 for _ in range(N+1)]
    result[0] = 0
    
    #print(result)
    
    for i in range(1, N+1):
        for a in A:
            if i < match[a]:
                #print(i,a,result)
                continue
            result[i] = max(result[i], result[i-match[a]]*10+a)
            #print(i,a,result)
    
    print(result[N])


# In[2]:


main()



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

using namespace std;

//#define int long long

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

#define pb push_back
#define VDEL(v, n) v.erase(v.begin() + (n))
#define ALL(v) v.begin(), v.end()

#define INTMAX 2147483647
#define INF 200000000
#define TINT(str) atoi(str.c_str())
#define TSTR(num) to_string(num)

typedef long long ll;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<vector<int>> VII;

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

//the end of library zone

// i i-1 pas i-2 pas
int dp[110][3][3];

int res[110];

int dn(int a)
{
    a -= 1;
    if(a == -1)
    {
        a = 2;
    }
    return a;
}

signed main()
{
    REP(i, 110)
    {
        res[i] = -1;
    }

    int N, K;
    cin >> N >> K;

    REP(i, K)
    {
        int A, B;
        cin >> A >> B;
        res[A - 1] = B - 1;
    }

    if(res[0] != -1)
    {
        dp[0][res[0]][dn(res[0])] = 1;
    }
    else
    {
        dp[0][0][1] = 1;
        dp[0][1][2] = 1;
        dp[0][2][0] = 1;
    }

    FOR(i, 1, N)
    {
        REP(h1, 3)
        REP(h2, 3)
        {
            if(res[i] != -1)
            {
                if(!(h1 == h2 && h1 == res[i]))
                {
                    dp[i][res[i]][h1] += 
                        dp[i - 1][h1][h2];
                    dp[i][res[i]][h1] %= 10000;
                }
            }
            else
            {
                REP(tdy, 3)
                {
                    if(!(h1 == h2 && h1 == tdy))
                    {
                        dp[i][tdy][h1] += 
                            dp[i - 1][h1][h2];
                        dp[i][tdy][h1] %= 10000;
                    }
                }
            }
        }
    }

    int ans = 0;
    REP(h1, 3)
    REP(h2, 3)
    {
        ans += dp[N - 1][h1][h2];
    }
    ans %= 10000;

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 3092
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
const double PI = acos(-1);  

int main(){
  int n;  cin >> n;
  vector<ll> a(n); 
  
  for(int i=0; i<n; i++) cin >> a.at(i);
    
  vector<ll> res;
  for(int i=0; i<n; i++){
    int pivot=-1;
    for(int j=a.size()-1; 0<=j; j--){
      if(a[j]==j+1){
        pivot = j; break;
      }
    }
    if(pivot==-1){
      cout << -1 << endl;
      return 0;
    }
    res.push_back(pivot+1);
    a.erase(a.begin()+pivot);
  }
  reverse(res.begin(), res.end());
  for(auto x: res) cout << x << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (auto &p : a) cin >> p;
  int q;
  cin >> q;
  while (q--) {
    int b, m, e;
    cin >> b >> m >> e;
    reverse(a.begin() + b, a.begin() + m);
    reverse(a.begin() + m, a.begin() + e);
    reverse(a.begin() + b, a.begin() + e);
  }
  for (int i = 0; i < n; i++) {
    if (i) cout << " ";
    cout << a[i];
  }
  cout << endl;
  return 0;
}


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

int main(){
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  if ((abs(c-a)<=d)||(abs(b-a)<=d && abs(c-b)<=d))
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b;
  cin >> a >> b;
  if ((a+b)%2==0){
    cout << (a+b)/2 << endl;
  }
  else{
    cout << (a+b)/2+1 << endl;
  }
}


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

class Graph {
protected:
	vector< vector<int> > adjl;
public:
	Graph(int n) : adjl(n){}
	void PushAdjl(int pl, int val) { adjl[pl].push_back(val); }
};

class DFGraph : public Graph {
private:
	int t;
	vector<int> d, f;
public:
	DFGraph(int n) : Graph(n), d(n), f(n) {}
	void DepthFirstSearch(int);
	void DFSSub(int);
	void Showdf();
};

void DFGraph::DepthFirstSearch(int begin = 0) {
	t = 1;
	DFSSub(begin);
	for (int i = 0; i < d.size(); i++)
		if (d[i] == 0)
			DFSSub(i);
}

void DFGraph::DFSSub(int v) {
	d[v] = t;
	t++;
	for (auto&& i : adjl[v])
		if (d[i] == 0)
			DFSSub(i);
	f[v] = t;
	t++;
}

void DFGraph::Showdf() {
	for (int i = 0; i < d.size(); i++)
		cout << i + 1 << " " << d[i] << " " << f[i] << endl;
}

int main() {
	int n;
	cin >> n;
	DFGraph dfg(n);
	for (int i = 0; i < n; i++) {
		int u, k;
		cin >> u >> k;
		for (int j = 0; j < k; j++) {
			int t;
			cin >> t;
			dfg.PushAdjl(u - 1, t - 1);
		}
	}
	dfg.DepthFirstSearch();
	dfg.Showdf();
}


Measured memory_bytes: 3156
//long time no ac
#include<bits/stdc++.h>
using namespace std;

#define debug(x) cout<<#x<<" :: "<<x<<"\n";
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n";
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\n";

#define     SPEED       ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define 	setprecn(x) cout<<fixed<<setprecision(x);
#define 	ll          long long int
#define 	pb          push_back
#define 	pll         pair<ll,ll>
#define 	vll         vector<ll>
#define 	ff          first
#define 	ss          second
#define 	all(a)      (a).begin(),(a).end()
#define 	sz(x)       (ll)x.size()
#define 	hell        1000000007
#define 	rep(i,n)    for(ll i=0;i<n;i++)
#define 	repe(i,a,b) for(ll i=a;i<b;i++)
#define 	lbnd        lower_bound
#define 	ubnd        upper_bound
#define 	bs          binary_search
#define 	mp          make_pair

ll power(ll a,ll b)
{
	if(b==0)
		return 1;
	if(b==1)
		return a;
	ll c=power(a,b/2);
	if(b%2==0)
		return((c%hell)*(c%hell))%hell;
	return ((((c%hell)*(c%hell))%hell)*(a%hell))%hell;
}

/********************************************************/
//	d.erase(unique(all(d)), d.end());
#define N 100005


ll a[N][3],dp[N][3],n;

ll f(ll x,ll l)
{
	if(x>n-1) return 0;
	if(dp[x][l]==-1)
	{
		dp[x][l]=0;
		rep(i,3)
		{
			// debug3(x,l,dp[x][l]);
			if(i==l && x!=0) continue;
			dp[x][l]=max(dp[x][l],a[x][i]+f(x+1,i));
		}
	}
	return dp[x][l];
}

int main()
{
	SPEED;
	ll k,t,j,m,cs=0;
	t=1;

	// cin>>t;
	string s;
	while(t--)
	{
		cin>>n;
		// n=s.length();
		// ll a[n];
		rep(i,n)
		{
			cin>>a[i][0]>>a[i][1]>>a[i][2];
		}
		// memset(dp,-1,sizeof(dp));
		rep(i,n)
		{
			rep(j,3) rep(k,3)
			{
				if(j==k) continue;
				dp[i+1][k]=max(dp[i+1][k],a[i][k]+dp[i][j]);
			}
		}
		cout<<max({dp[n][0],dp[n][1],dp[n][2]});
		if(t!=0)
	   		cout<<"\n";
	}
	return 0;
}

Measured memory_bytes: 4992
#include <cstdio>
#include <cmath>
#include <iostream>
#include <set>
#include <algorithm>
#include <vector>
#include <map>
#include <cassert>
#include <string>
#include <cstring>
#include <queue>

using namespace std;

#define rep(i,a,b) for(int i = a; i < b; i++)
#define S(x) scanf("%d",&x)
#define S2(x,y) scanf("%d%d",&x,&y)
#define P(x) printf("%d\n",x)
#define all(v) v.begin(),v.end()
#define FF first
#define SS second
#define pb push_back
#define mp make_pair

typedef long long int LL;
typedef pair<int, int > pii;
typedef vector<int > vi;

LL dp[99];

int main() {
  dp[0] = 2;
  dp[1] = 1;
  rep(i,2,99) dp[i] = dp[i-1] + dp[i-2];
  int n;
  S(n);
  cout << dp[n] << "\n";
  return 0;
}

Measured memory_bytes: 256