akhauriyash/Code-Regression huggingface dataset:
#include<set>
#include<map>
#include<deque>
#include<queue>
#include<stack>
#include<cmath>
#include<ctime>
#include<bitset>
#include<string>
#include<vector>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<complex>
#include<iostream>
#include<algorithm>
#define ll long long
using namespace std;

const int maxn = 410000;

int n,m;
struct edge{int y,nex;}a[maxn]; int len,fir[maxn];
inline void ins(const int x,const int y){a[++len]=(edge){y,fir[x]};fir[x]=len;}

int fa[maxn],siz[maxn],v[maxn];
int findfa(const int x){return fa[x]==x?x:fa[x]=findfa(fa[x]);}
int col[maxn];
bool Col(const int x)
{
	for(int k=fir[x],y=a[k].y;k;k=a[k].nex,y=a[k].y)
	{
		if(col[y]==-1)
		{
			col[y]=!col[x];
			if(!Col(y)) return false;
		}
		if(col[y]==col[x]) return false;
	}
	return true;
}

int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++) fa[i]=i,siz[i]=1;
	for(int i=1;i<=m;i++)
	{
		int x,y; scanf("%d%d",&x,&y);
		ins(x,y); ins(y,x);
		int f1=findfa(x),f2=findfa(y);
		if(f1!=f2) fa[f2]=f1,siz[f1]+=siz[f2];
	}
	memset(col,-1,sizeof col);
	int t1=0,t2=0,one=0;
	for(int i=1;i<=n;i++) if(fa[i]==i) 
	{
		if(siz[i]==1) one++;
		else col[i]=0,v[i]=Col(i),(v[i]?++t2:++t1);
	}
	ll ans=0;
	for(int i=1;i<=n;i++) if(fa[i]==i)
	{
		if(siz[i]==1) ans+=(ll)n;
		else if(v[i]) ans+=(ll)(t1+t2*2)+(ll)siz[i]*one;
		else ans+=(ll)(t1+t2)+(ll)siz[i]*one;
	}
	printf("%lld\n",ans);
	
	return 0;
}


Measured memory_bytes: 11136
from collections import defaultdict

N=int(input())
count = defaultdict(int)
for i in range(N):
  s = input()
  s = ''.join(sorted(s))
  count[s] += 1

SUM = 0
for val in count.values():
  if val > 1:SUM+=val*(val-1)//2
print(SUM)

Measured memory_bytes: 22448
n, p = [ int(v) for v in input().split() ]
num_list = [ int(v)%2 for v in input().split() ]

dp_list = [ [ [0,0] for i in range(n+1) ] for j in range(n+1) ]
dp_list[0][0][0] = 1

for i, v in enumerate(num_list,1):
    dp_list[i][0] = [1,0]
    if v == 0:
        for j in range(1,n+1):
            if j == 1:
                dp_list[i][j][0] = dp_list[i-1][j][0] + 1
                dp_list[i][j][1] = dp_list[i-1][j][1]
            else:
                dp_list[i][j][0] = dp_list[i-1][j-1][0] + dp_list[i-1][j][0]
                dp_list[i][j][1] = dp_list[i-1][j-1][1] + dp_list[i-1][j][1]
    else:
        for j in range(1,n+1):
            if j == 1:
                dp_list[i][j][0] = dp_list[i-1][j][0] 
                dp_list[i][j][1] = dp_list[i-1][j][1] + 1
            else:
                dp_list[i][j][0] = dp_list[i-1][j-1][1] + dp_list[i-1][j][0]
                dp_list[i][j][1] = dp_list[i-1][j-1][0] + dp_list[i-1][j][1]


print(sum(list(zip(*dp_list[-1]))[p]))

Measured memory_bytes: 39664
#include <bits/stdc++.h>
using namespace std;
int main()
{
int a,b,c;
cin>>a;
for(int i=1;i<=a;)
{b=0;
for(int j=1;j<=i;)
{if(i%j==0)
b++;
j=j+2;}
if(b==8)
c++;
i=i+2;}
cout<<c;
}


Measured memory_bytes: 256
import math
N = int(input())

p = [i for i in range(2,N+1)]
q = []

for i in p:
    for j in range(2,i):
        if i%j==0:
            q.append(i)
            break
        
p = list(set(p)-set(q))

def div(n):
    ret=0
    a=math.factorial(N)
    while a%n == 0:
        a//=n
        ret+=1
    return ret

Ans=0

for n in p:
    if div(n)>=74:
        Ans+=1

for n in p:
    if div(n)>=24:
        for m in p:
            if div(m)>=2 and n!=m:
                Ans += 1

        
for n in p:
    if div(n)>=14:
        for m in p:
            if div(m)>=4 and n!=m:
                Ans += 1

for n in p:
    if div(n)>=2:
        for m in p:
            if n!=m and div(m)>=4:
                for l in p:
                    if l!=n and l>m and div(l)>=4:
                        Ans +=1

print(Ans)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
typedef long long ll;
int main()
{
	ll height,weight;
	cin>>height>>weight;
	ll res=1e18;
	for(int i=1;i<height;i++)
	{
		ll height1=height-i;
		ll height2=height1/2;
		ll height3=height1-height2;
		ll area4=height2*weight;
		ll area5=height3*weight;
		ll weight2=weight/2;
		ll weight3=weight-weight2;
		ll area1=i*weight;
		ll area2=height1*weight2;
		ll area3=height1*weight3;
		ll maxi=max(area1,max(area2,area3));
		ll mini=min(area1,min(area2,area3));
		if((maxi-mini)<res)
			res=maxi-mini;
		 maxi=max(area1,max(area4,area5));
		 mini=min(area1,min(area4,area5));
		if((maxi-mini)<res)
			res=maxi-mini;
	}
	for(int i=1;i<weight;i++)
	{
		ll weight1=weight-i;
		ll weight2=weight1/2;
		ll weight3=weight1-weight2;
		ll area4=weight2*height;
		ll area5=weight3*height;
		ll height2=height/2;
		ll height3=height-height2;
		ll area1=i*height;
		ll area2=weight1*height2;
		ll area3=weight1*height3;
		ll maxi=max(area1,max(area2,area3));
		ll mini=min(area1,min(area2,area3));
		if((maxi-mini)<res)
			res=maxi-mini;
		 maxi=max(area1,max(area4,area5));
		 mini=min(area1,min(area4,area5));
		if((maxi-mini)<res)
			res=maxi-mini;
	}
	cout<<res<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int r,D,x0;
  cin >> r >> D >> x0;
 
  /*vector<int> x(11);
  x.at(0)=x0;*/
  
  for(int i=0;i<10;i++){
    x0=x0*r-D;
    cout << x0 << endl;
  }
  
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
   
using namespace std;
   
int main(){
    int n,m;
    int x[1000];
    int s[1000];
    int masu=0;
    while(true){
        masu=0;
    cin>>n>>m;
    if(n==0&&m==0){
        break;
    }
    for(int i=0;i<n;i++){
        cin>>x[i];
    }
    for(int i=0;i<m;i++){
        cin>>s[i];
    }
    int i=0;
    while(true){
        masu+=s[i];
        if(masu>=n-1){
            cout<<i+1<<endl;
            break;
        }
        masu+=x[masu];
        if(masu>=n){
            cout<<i+1<<endl;
            break;
        }
        i++;
    }
    }
    return 0;
} 

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int H,W,h,w;
int G[505][505];
void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>H>>W>>h>>w;
	if(h==1&&w==1) return _P("No\n");
	ll sum=0;
	ll mul=999999999/(h*w-1);
	FOR(y,H) {
		FOR(x,W) {
			G[y][x]=mul;
			if((y%h==h-1) && (x%w==w-1)) G[y][x]=-mul*(h*w-1)-1;
			sum += G[y][x];
		}
	}
	
	if(sum<=0) return _P("No\n");
	_P("Yes\n");
	FOR(y,H) FOR(x,W) _P("%d%c",G[y][x],(x==W-1)?'\n':' ');
	
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}


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

const int maks = 1e6;
vector<ll> cost;
vector<ll> val;
ll dp[maks];
ll sum;
ll wyn;
int main() {
    ll lim;
   
   int n; cin >> n >> lim;
   for(int i= 1; i <= n; i++) {
       ll c,v;
       cin >> c >> v;
       cost.push_back(c);
       val.push_back(v);
       sum += v;
   }
    
   for(int i = 1; i <= sum; i++)
    dp[i] = 1e15;
    dp[0] = 0;
    
   for(int i = 0; i < n; i++) {
       ll c = cost[i]; ll v = val[i];
       for(int j = sum; j >= 0; j--) {
           dp[j+v] = min(dp[j]+c,dp[j+v]);
       }
   }
   for(int i = 0; i <= sum; i++) {
       if(dp[i] <= lim)
            wyn = i;
   }
   cout << wyn;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
  #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  #define int long long
  #define endl "\n"
  const int N = 50;


vector<int> a,b,c,d;

    int n,m,q;
int mxscore;
int score(vector<int> &v)
{
  int ans = 0;

  for(int i = 0; i < q; i++)
  {
    if(a[i] - 1 < n and b[i] - 1 < n and (v[b[i]-1] - v[a[i]-1] == c[i]))ans += d[i];
  }

  return ans;
}

void rec(vector<int> v,int idx)
{

  mxscore = max(mxscore,score(v));
 


 int mxnow = v[idx+1];
  //   cout << "idx: " << idx << endl;
  // cout << "mxnow: " << mxnow << endl;


  // for(auto i : v)
  // {
  //   cout << i << " ";
  // }
  // cout << endl;
  if(idx < 0)return;

  

  for(int i = mxnow; i >= 1; i--)
  {
    v[idx] = i;
    mxnow = min(mxnow,i);
    rec(v,idx-1);
  }

}


int32_t main()
{


    IOS


vector<int> v;

    cin >> n >> m >> q;

    for(int i = 1; i <= q; i++)
    {
      int x,y,z,w;
      cin >> x >> y >> z >> w;
      a.push_back(x);
      b.push_back(y);
      c.push_back(z);
      d.push_back(w);

    }


    for(int i = 1; i <= n; i++)
    {
      v.push_back(1);
    }

    mxscore = score(v);



    for(int i = 1; i <= m; i++)
    {
      v[n-1] = i;
      rec(v,n-2);
    }
    
    cout << mxscore;

    
    return 0;
}



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

int main()
{
    int n, r;
    cin >> n >> r;
    if( n < 10 )
    {
        cout << r + 100*(10 - n) << endl;
    }
    else
    {
        cout << r << endl;
    }

    return 0;
}



Measured memory_bytes: 256
//#include <bits/stdc++.h>
//#include <algorithm>
//#include <cstdio>
//#include <functional>
#include <iostream>
//#include <cfloat>
//#include <climits>
//#include <cstdlib>
//#include <cstring>
//#include <cmath>
//#include <map>
//#include <queue>
//#include <set>
//#include <sstream>
//#include <stack>
//#include <string>
//#include <time.h>
#include <vector>
//#include <random>
//#include <unordered_set>
//#include <complex>
//#include <string.h>
#define rt0 return 0
#define rep(i,n) for(int i=0;i<n;i++)
#define LL long long
#define pii pair<int,int>
#define pb push_back
using namespace std;
const LL MOD=1e9+7;
LL ans;
int main()
{
	int n;
	cin>>n;
	vector <LL> a(n);
	rep(i,n) cin>>a[i];	
	int left=0,r=0,now=a[0],sum=a[0];
	rep(i,n)
	{
		while(r+1<n&&(now^a[r+1])==sum+a[r+1]) 
		{
			now^=a[r+1];
			sum+=a[r+1];
			r++;
		}
//		cout<<r<<endl;
		ans+=(r-left+1);
		now^=a[i];
		sum-=a[i];
		left++;
	}
	cout<<ans;
    rt0;
}

Measured memory_bytes: 1792
h,w=map(int,input().split())

a=[[int(x)%2 for x in input().split()] for y in range(h)] 
b=[0 for y in range(h)]

l=list()
for y in range(h):
  x=0
  t=False
  while x < w:
    if a[y][x]:
      if t==False:
        if x!=w-1:
          l.append([y+1,x+1,y+1,x+2])
        t=True
      else:
        t=False
    elif t==True:
      if x!=w-1:
        l.append([y+1,x+1,y+1,x+2])
    x += 1
  b[y]=1 if t==True else 0

y=0
t=False
while y < h:
  if b[y]:
    if t==False:
      if y!=h-1:
        l.append([y+1,w,y+2,w])
      t=True
    else:
      t=False
  elif t==True:
    if y!=h-1:
      l.append([y+1,w,y+2,w])
  y+=1

print(len(l))
for i in range(len(l)):
  print(l[i][0],l[i][1],l[i][2],l[i][3])


Measured memory_bytes: 30124
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

constexpr long long MOD = 1000000007;

int main()
{
  int N, M;
  std::cin >> N >> M;
  std::vector<std::vector<int>> lights(M);
  for (auto& light: lights)
  {
    int k;
    std::cin >> k;
    light.resize(k);
    for (auto& val: light)
      std::cin >> val;
  }
  std::vector<int> p(M);
  for (auto& val: p)
    std::cin >> val;
  int limit = 1 << N;
  int ans = 0;
  auto check = [&](int n)
  {
    bool b = true;
    for (int i = 0; i < M; ++i)
    {
      int cnt = 0;
      for (auto s: lights[i])
      {
        if ((n >> (s - 1)) & 1)
          ++cnt;
      }
      if (cnt % 2 != p[i])
      {
        b = false;
        break;
      }
    }
    return b;
  };
  for (int i = 0; i < limit; ++i)
  {
    if (check(i))
      ++ans;
  }
  std::cout << ans << std::endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>

using namespace std;

int main() {
  string s;
  cin >> s;
  if (s == "SSS")
    cout << 0 << endl;
  else if (s == "RSS" || s == "SRS" || s == "SSR" || s == "RSR")
    cout << 1 << endl;
  else if (s == "RRR")
    cout << 3 << endl;
  else
    cout << 2 << endl;
}


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

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

using namespace std;

using ll = long long;

int main() {
    ll n, x, a;
    cin >> n >> x;
    vector<ll> input;
    for (ll i = 0; i < n; ++i) {
        cin >> a;
        input.push_back(a);
    }
    ll count = 0;
    for (ll i=0; i<input.size()-1; ++i) {
        ll tempSum = input[i]+input[i+1];
        if (tempSum > x) {
            ll eat = tempSum-x;
            if (eat > input[i+1]) {
                input[i] -= eat-input[i+1];
                input[i+1] = 0;
            } else {
                input[i+1] -= eat;
            }
            count += eat;
        }
    }
    cout << count << endl;
}


Measured memory_bytes: 1400
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pint = pair<int,  int>;
using edge = pair<int, ll>;
using graph = vector<vector<edge>>;
const ll INF = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;

int main() {
	int n,m, T; cin >> n>> m>> T;
    int  ans = (n+m)* T/2;
    cout << ans << endl;
}


Measured memory_bytes: 256
// clang-format off
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}
// clang-format on

ll lcm(ll x, ll y) { return x / __gcd(x, y) * y; }

ll solve() {
    int n, m;
    cin >> n >> m;
    vector<ll> a(n);
    rep(i, n) {
        cin >> a[i];
        a[i] /= 2;
    }

    ll L = 1;
    rep(i, n) {
        L = lcm(L, a[i]);
        if (L > m) return 0;
    }
    rep(i, n) {
        ll q = L / a[i];
        if (q % 2 == 0) return 0;
    }

    ll x = m / L;
    return (x + 1) / 2;
}

int main() {
    cout << solve() << "\n";
    return 0;
}


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

#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_CAT_I(x,y) x ## y
//#define CPP_STR(x) CPP_STR_I(x)
//#define CPP_STR_I(args...) #args
//#define ASSERT(expr...) assert((expr))

using i8 = int8_t;
using u8 = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
//using f80 = __float80;

constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
constexpr char EL[] = "\n";

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(),(x).end()
#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))
#define UNIQUE(x) (x).erase(unique(all(x)), (x).end());
#define REPIT(x) for(auto it=(x).begin(), end=(x).end(); it!=end; ++it)
#define perm(c) sort(all(c)); for(bool c##p=1;c##p;c##p=next_permutation(all(c)))

template<typename T = i64>
T IN() { T x; cin >> x; return (x); }

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }
template<typename T, size_t N>
i64 SIZE(const T(&)[N]) { return static_cast<i64>(N); }

template<typename T, typename U, typename Comp = less<>>
bool chmax(T& xmax, const U& x, Comp comp = {}) {
	if (comp(xmax, x)) {
		xmax = x;
		return true;
	}
	return false;
}
template<typename T, typename U, typename Comp = less<>>
bool chmin(T& xmin, const U& x, Comp comp = {}) {
	if (comp(x, xmin)) {
		xmin = x;
		return true;
	}
	return false;
}

void print() {
	cout << EL;
}
template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
	cout << head;
	if (sizeof...(tail) != 0) cout << " ";
	print(forward<Tail>(tail)...);
}
template <class T>
void print(vector<T> &vec) {
	for (auto& a : vec) {
		cout << a;
		if (&a != &vec.back()) cout << " ";
	}
	cout << EL;
}
template <class T>
void print(vector<vector<T>> &df) {
	for (auto& vec : df) {
		print(vec);
	}
}

struct ProconInit {
	static constexpr int IOS_PREC = 15;
	static constexpr bool AUTOFLUSH = false;

	ProconInit() {
		cin.tie(nullptr);
		ios::sync_with_stdio(false);
		cout << fixed << setprecision(IOS_PREC);
		if (AUTOFLUSH)
			cout << unitbuf;
	}
} PROCON_INIT;
#pragma endregion

signed solve()
{
	auto M = IN();
	print(24+24-M);
	return 0;
}

#ifndef LOCALCODE
signed main()
{
	return solve();
}
#endif


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     @hamayanhamayan0
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/














int N, M, Q, a[50], b[50], c[50], d[50];
//---------------------------------------------------------------------------------------------------
int ans = 0;
int A[10];
void dfs(int cu = 0, int lst = 1) {
	if (cu == N) {
		int tot = 0;
		rep(i, 0, Q) if (A[b[i]] - A[a[i]] == c[i]) tot += d[i];
		chmax(ans, tot);
		return;
	}

	rep(nxt, lst, M + 1) {
		A[cu] = nxt;
		dfs(cu + 1, nxt);
	}
}
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> N >> M >> Q;
	rep(i, 0, Q) {
		cin >> a[i] >> b[i] >> c[i] >> d[i];
		a[i]--; b[i]--;
	}

	dfs();
	cout << ans << endl;
}







Measured memory_bytes: 3644
N = int(input())
l = []
for i in range(N):
    x, y, h = list(map(int, input().split(' ')))
    l.append((x, y, h))
if len(l) == 1:
    print('%d %d %d' % (l[0][0], l[0][1], l[0][2]))
    exit()
l = sorted(l, key=lambda x: x[2])[::-1]
for cx in range(101):
    for cy in range(101):
        takasa = None
        correct = True
        for x, y, h in l:
            if takasa is None:
                takasa = h + (abs(cx - x) + abs(cy - y))
            elif h != max(takasa - (abs(cx - x) + abs(cy - y)), 0):
                correct = False
                break
        if correct:
            print('%d %d %d' % (cx, cy, l[0][2] + abs(l[0][0] - cx) + abs(l[0][1] - cy)))


Measured memory_bytes: 3064
var input: string = require('fs').readFileSync('/dev/stdin', 'utf8');
var inputLines: string[] = input.trim().split("\n");
//var parts = inputLines[0].split(" ");

var N = parseInt(inputLines[0]);
var K = parseInt(inputLines[1]);
var X = parseInt(inputLines[2]);
var Y = parseInt(inputLines[3]);
console.log(N <= K ? X*N : X*K + Y*(N - K));

Measured memory_bytes: 11468
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int    N = scan.nextInt();
		String S = scan.next();
		String T = scan.next();
		List <String> list = new ArrayList<>();
		for (int i = 0; i < N; i++) {
			list.add(String.valueOf(S.charAt(i)));
			list.add(String.valueOf(T.charAt(i)));
		}
		for (int i=0; i <  list.size(); ++i)
		{
		    System.out.print(list.get(i));
		}
	}
}


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

int main() {
    ll n,m,s,t;
    struct edge {
        ll to;
        ll cost;
    };

    vector<vector<edge>> G1(100010);
    vector<vector<edge>> G2(100010);
    std::cin >> n>>m>>s>>t;
    s--;
    t--;
    for (int i = 0; i < m; i++) {
        ll a,b,c,d;
        std::cin >> a>>b>>c>>d;
        a--;
        b--;
        G1[a].push_back({b,c});
        G1[b].push_back({a,c});
        
        G2[a].push_back({b,d});
        G2[b].push_back({a,d});
    }
    typedef pair<ll, ll> P;
     
    //  sからとｔから
     vector<ll> d1(100010,1e16);
     vector<ll> d2(100010,1e16);
     
     d1[s] = 0;
     d2[t] = 0;

     // 距離、頂点のペア。距離が近い順に取り出される
     priority_queue<P, vector<P>, greater<P> > que;
     
     que.push(P(0, s));
     while (!que.empty()) {
         P p = que.top();
         que.pop();
         int v = p.second;
         if (d1[v] < p.first) continue;
        	for (int i=0; i<G1[v].size(); ++i) {
            	edge e = G1[v][i];
             if (d1[e.to] > d1[v] + e.cost) {
                 d1[e.to] = d1[v] + e.cost;
                 que.push(P(d1[e.to], e.to));
             }   
         }
     }
     
     que.push(P(0, t));
     while (!que.empty()) {
         P p = que.top();
         que.pop();
         int v = p.second;
         if (d2[v] < p.first) continue;
        	for (int i=0; i<G2[v].size(); ++i) {
            	edge e = G2[v][i];
             if (d2[e.to] > d2[v] + e.cost) {
                 d2[e.to] = d2[v] + e.cost;
                 que.push(P(d2[e.to], e.to));
             }   
         }
     }
     vector<ll> result(n);
     ll val = 1e16;
     for (int i = n-1; i >= 0; i--) {
         if( d1[i]+d2[i] < val ){
             val = d1[i]+d2[i];
         }
         result[i] = val;
     }
     for (int i = 0; i < n; i++) {
         std::cout << (ll)1e15-result[i] << std::endl;
     }
}


Measured memory_bytes: 19704
#include <math.h>
#include <stdio.h>

double find_length(double x1, double x2, double y1, double y2){
	double x = (x1 - x2);
	double y = (y1 - y2);
	return sqrt(x*x + y*y);
}

double find_area(double a, double b, double c){
	double z = (a + b + c) / 2;
	return sqrt(z * (z - a) * (z - b) * (z - c));
}

int main(void){
	double x[20] = {};
	double y[20] = {};
	double area = 0;
	int i = 0;
	while (scanf("%lf,%lf", &x[i], &y[i]) != EOF) {
		if (2 <= i) {
			double a = find_length(x[0], x[i-1], y[0], y[i-1]);
			double b = find_length(x[i-1], x[i], y[i-1], y[i]);
			double c = find_length(x[0], x[i], y[0], y[i]);
			area += find_area(a, b, c);
		}
		i++;
	}
	printf("%lf\n", area);
	return 0;
}



Measured memory_bytes: 2048
N,M = map(int,input().split())
A = [int(input()) for i in range(M)]
B = [1]*(N+2)
for a in A:
    B[a] = 0
MOD = 10**9+7

if not B[0]:
    print(0)
    exit()

dp = [0]*(N+1)
dp[0] = 1
for i in range(N):
    if B[i+1]:
        dp[i+1] += dp[i]
    if i+2 <= N and B[i+2]:
        dp[i+2] += dp[i]
print(dp[-1] % MOD)

Measured memory_bytes: 463476
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<bitset>
#include<unordered_map>
using namespace std;
//---------------------------------------------------
//ライブラリゾーン！！！！
typedef long long ll;
typedef long double ld;
#define str string
#define rep(i,j) for(ll i=0;i<(long long)(j);i++)
#define all(a) (a).begin(),(a).end()
const ll Mod = 1000000007;
const ll gosenchou = 5000000000000000;
short gh[2][4] = { { 0,0,-1,1 },{ -1,1,0,0 } };
struct P {
	ll pos, cost;
};
bool operator<(P a, P b) { return a.cost < b.cost; }
bool operator>(P a, P b) { return a.cost > b.cost; }
struct B {//隣接リスト表現
	ll to, cost;
};
struct E {//辺の情報を入れる変数
	ll from, to, cost;
};
bool operator<(E a, E b) {
	return a.cost < b.cost;
}
struct H {
	ll x, y;
};
bool operator<(H a, H b) {
	if (a.x != b.x) return a.x < b.x;
	return a.y < b.y;
}
bool operator>(H a, H b) {
	if (a.x != b.x) return a.x > b.x;
	return a.y > b.y;
}
bool operator==(H a, H b) {
	return a.x == b.x&&a.y == b.y;
}
bool operator!=(H a, H b) {
	return a.x != b.x || a.y != b.y;
}
ll gcm(ll i, ll j) {//最大公約数
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcm(j%i, i);
}
ld rad(H a, H b) {
	return sqrt(pow(a.x - b.x, 2.0) + pow(a.y - b.y, 2.0));
}//rad＝座標上の2点間の距離
ll ari(ll a, ll b, ll c) {
	return (a + b)*c / 2;
}//等差数列の和
ll fact(ll x, ll k, ll p) {//最大値、個数、あまり
	ll sum = 1;
	for (int i = 0; i < k; i++) {
		sum *= (x--);
		sum %= p;
	}
	return sum;
}//階乗(正）
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res*x%p;
		x = x*x%p;
		n >>= 1;
	}
	return res;
}//x^n%p
int ctoi(char a) {
	return (int)a - '0';
}
#define int long long
const long long Inf = 4523372036854775807;
const int inf = 15000000000;
//----------------------------------------------------
//++++++++++++++++++++++++++++++++++++++++++++++++++++
int a[100001], v[100001];
int f[100001], d[100001];
int sum[100001];
signed main() {
	int n, c;
	cin >> n >> c;
	for (int i = 1; i <= n; i++)
		cin >> a[i] >> v[i];
	for (int i = 1; i <= n; i++) {
		f[i] = f[i - 1] + v[i];
	}
	for (int i = n-1; i >= 0; i--) {
		d[i] = d[i + 1] + v[i + 1];
	}
	sum[n] = -inf;
	for (int i = n-1; i >= 0; i--) {
		sum[i] = max(sum[i + 1], d[i] - (c - a[i + 1]));
	}
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		ans = max(ans, f[i] - a[i]);
		ans = max(ans, f[i] - 2 * a[i] + sum[i]);
	}
	sum[0] = -inf;
	for (int i = 1; i <= n; i++) {
		sum[i] = max(sum[i - 1], f[i] - a[i]);
	}
	for (int i = n - 1; i >= 0; i--) {
		ans = max(ans, d[i] - (c - a[i + 1]));
		ans = max(ans, d[i] - 2 * (c - a[i + 1]) + sum[i]);
	}
	cout << ans << endl;
	getchar(); getchar();
}


Measured memory_bytes: 4096
from collections import*
n,*t=map(int,open(0).read().split())
e=[[]for _ in range(n)]
for v,w,c in zip(t[::3],t[1::3],t[2::3]):
  e[v-1].append((w-1,c))
  e[w-1].append((v-1,c))
q=deque([(0,0)])
f=[0]+[-1]*~-n
while q:
  v,c=q.pop()
  for w,d in e[v]:
    if-1<f[w]:continue
    d=(c+d)%2
    f[w]=d
    q.append((w,d))
print(*f)

Measured memory_bytes: 50284
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

int main(){
	ll n,l;
	cin >> n;
	set<ll> a;
	vector<ll> b(n);
	map<ll,ll> m;
	for(ll i = 0; i < n; i++) {
		cin >> l;
		if (m.count(l) == 0){
			m.insert(mp(l,1));
		}
		else{
			m[l]++;
		}
	}

	ll A = 0;
	ll C = 0;
	for(auto i = m.begin(); i != m.end(); i++) {
		if ((*i).first > A && (*i).second >= 2){
			if ((*i).second >= 4){
				A = (*i).first;
				C = (*i).first;
			}
			else{
				C = A;
				A = (*i).first;
			}
		}
		else if((*i).first > C && (*i).second >= 2){
			C = (*i).first;
		}
	}
	cout << A * C << endl;
	return 0;
}

Measured memory_bytes: 7296
#include<iostream>
#include<cstdio>
using namespace std;
int d, n, ans = 1;
int main(){
	scanf("%d%d", &d, &n);
	for(int i = 1; i <= d; ++i) ans *= 100;
	if(n == 100) n++;
	ans *= n;
	printf("%d\n", ans);
	return 0;
}

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

using namespace std;

int main(){
    long long n, m;
    scanf("%lld %lld", &n, &m);
    if(n == 1 && m == 1) return printf("1\n"), 0;
    if(n > m) swap(n, m);
    long long ans = 0;
    if(n == 1){
        ans = m - 2;
    }
    else{
        ans = n * m - (2 * n + 2 * m - 4);
    }
    printf("%lld\n", ans);
}

Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<utility>
#include<algorithm>
#include<string>
#include<cstdio>
#include<queue>
#include<functional>
#include<tuple>
#include<iomanip>
#include<stack>
#include<cmath>
#define ll long long
using namespace std;
int main() {
	int n, data[100003] = {}; cin >> n;
	for (int i = 0; i < n; ++i) {
		int a, b; cin >> a >> b;
		data[a]++; data[b + 1]--;
	}
	int cnt = 0;
	for (int i = 2; i <= 100001; ++i) {
		data[i] += data[i - 1];
		if (data[i] >= i - 1) cnt = i;
	}
	cout << (cnt==0?cnt:cnt-1) << endl;
	return 0;
}


Measured memory_bytes: 3504
#pragma GCC optimize ("Ofast")
#pragma GCC target ("sse4")

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

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

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(x) begin(x),end(x)

#define forn(i, n) for (int i = 0; i < n; ++i)
#define rforn(i, n) for (int i = n - 1; i >= 0; --i)

const int N = 2e5 + 5, M = 1e9 + 7; // 998244353
const int dx[]{0, 1, 0, -1}, dy[]{1, 0, -1, 0};
const ll INF = 1e18 + 10LL;
const ld PI = 4.0 * atan((ld) 1.0), EPS = 1e-6;
const char nl = '\n';

template <typename T> inline T gcd(T a, T b) { return b == 0 ? a : gcd(b, a % b); }
template <typename T> inline T lcm(T a, T b) { return a / gcd(a, b) * b; }
template <class T> void ckmin(T& a, T b) { a = min(a, b); }
template <class T> void ckmax(T& a, T b) { a = max(a, b); }
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

string YN(bool x) { return x ? "YES" : "NO"; }

ll pow(ll b, ll e, ll m = 0LL, ll ans = 1LL) { while (e) { if (e & 1LL) { ans *= b; if (m) ans %= m; } b *= b, e >>= 1LL; if (m) b %= m; } return ans; }

ll fact[1<<21], inv[1<<21];

ll C(int x, int y) {
	if (y < 0 || y > x)
		return 0LL;
	return fact[x] * inv[y] % M * inv[x-y] % M;
}

void precomp() {
	fact[0] = 1LL;
	for (int i = 1; i < (1 << 21); ++i)
		fact[i] = fact[i-1] * i % M;
	inv[(1<<21) - 1] = pow(fact[(1<<21)-1], M - 2, M);
	for (int i = (1 << 21) - 2; i >= 0; --i)
		inv[i] = inv[i+1] * (i + 1) % M;
}

void solve(int tcn) {
	int k, n;
	string s;
	cin >> k >> s, n = (int) s.length();
	ll ans = 0LL;
	for (int i = n; i <= k + n; ++i) {
		ans += (C(k + n, i) % M) * (pow(25LL, k + n - i, M) % M) % M;
		ans = ans % M;
	}
	cout << ans << nl;
}

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	precomp();
	int t = 1; //cin >> t;
	for (int i = 1; i <= t; ++i) {
		solve(i);
	}
	return 0;
}


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

long long find(int len,int k){
    int b=1;
    int w=0;
    long long ret=0;
    for(int i=1;i<=len;i+=2){
	int minest=w+b;
	int num=(len-minest)/(k-1);
	if(num>=b){
	    long long temp=1;
	    for(int j=0;j<b;j++)
		temp*=2;
	    ret+=temp;
	}
	else{
	    long long start=1;
	    for(int j=0;j<=num;j++){
		ret+=start;
		start=start*(b-j)/(j+1);
	    }
	}
	w=b;
	b=w+1;
    }
    return ret;
}

int main(){
    // k:[2,10],l:[1:100]
    //cout<<"l,k=(k>2,l>1)";
    int l,k;
    cin>>l>>k;
    cout<<find(l,k)<<endl;
    return 0;
}


Measured memory_bytes: 3136
import java.util.Scanner;

public class Main {

	public static void main(String args[]) {

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		sc.nextLine();

		String[] S = new String[N];
		long[] march = new long[5];
		for(int i=0;i<N;i++) {
			S[i] = sc.nextLine();

			switch(S[i].charAt(0)) {
				case 'M':
					march[0]++;
					break;
				case 'A':
					march[1]++;
					break;
				case 'R':
					march[2]++;
					break;
				case 'C':
					march[3]++;
					break;
				case 'H':
					march[4]++;
					break;
				default:
					break;
			}
		}

		long ans=0;
		for(int i=0;i<3;i++) {
			if(march[i] == 0) continue;
			for(int j=i+1;j<4;j++) {
				if(march[j] == 0) continue;
				for(int k=j+1;k<5;k++) {
					if(march[k] == 0) continue;
					ans += march[i]*march[j]*march[k];
				}
			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 97748
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iterator>
#include <numeric>
#include <bitset>
#include <cassert>
#include <functional>

using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
typedef pair<ll, ll> P;
inline ll min(ll x, ll y) { return x < y ? x : y; }
inline ll max(ll x, ll y) { return x > y ? x : y; }

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << (x) << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)

bool pairCompare(const P & firstElof, const P & secondElof)
{
	return firstElof.second < secondElof.second;
}

int main() {
	int N;
	cin >> N;
	vector<int> A(N);
	vector<pair<int, int>> bango(N);
	rep(i, N) {
		cin >> A[i];
		bango[i] = make_pair(i + 1, A[i]);
	}

	sort(all(bango), pairCompare);

	rep(i, N) {
		cout << bango[i].first << " ";
	}

	return 0;
}

Measured memory_bytes: 2048
#include <iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<limits>
//include<bits/stdc++.h>
using namespace std;

typedef pair<int, int>point;

typedef std::numeric_limits< double > dbl;

int calc_permutation(int num)
{
	int permutation = 1;
	for (int i = 1; i <= num; i++)
		permutation *= i;
	return permutation;
}
int main()
{
	int N;
	cin >> N;
	point arr[8];
	int positionarray[8] = { 0,1,2,3,4,5,6,7};
	for (int i = 0; i < N; i++)
	{
		cin >> arr[i].first >> arr[i].second;
	}
	double avg_distance = 0;
	do {
		double cur_diatnace = 0;
		for (int i = 0; i < N-1; i++)
		{
			cur_diatnace = sqrt(pow(arr[positionarray[i]].first - arr[positionarray[i + 1]].first, 2) + pow(arr[positionarray[i]].second - arr[positionarray[i + 1]].second, 2));
			avg_distance += cur_diatnace;
		}

	} while (next_permutation(positionarray, positionarray + N));
	cout.precision(dbl::max_digits10);
	cout << avg_distance / (double)calc_permutation(N);
}

Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;


int main() {
    int a,b,add,sub,m;
    cin>>a>>b;
    add  = a+b;
    sub = a-b;
    m = a*b;
    int ans;
    ans = max(add,max(sub,m));
    cout<<ans<<endl;
}

Measured memory_bytes: 256
import itertools

N, M = map(int, input().split())

sides = []

for _ in range(M):
    temp_a, temp_b = map(int, input().split())
    sides.append(set([temp_a, temp_b]))



#print(sides)
counter = 0
for i in itertools.permutations(range(1, N+1)):
    if i[0] != 1:
        continue

    for j in range(0,N-1):
        if set([i[j],i[j+1]]) in sides:
            continue
        else:
            break
    else:
        counter += 1
        continue
    


print(counter)



Measured memory_bytes: 3064
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;
typedef string::const_iterator State;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 1e18
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define MOD 998244353
#define seg_size 262144
#define REP(a,b) for(long long a = 0;a < b;++a)
vector<complex<double>>  DFT(vector<complex<double>> a) {
	int n = a.size();
	if (n == 1) return a;
	vector<complex<double>> a0(n / 2), a1(n / 2);
	REP(i, n) {
		if (i % 2 == 0) {
			a0[i / 2] = a[i];
		}
		else {
			a1[i / 2] = a[i];
		}
	}
	vector<complex<double>> inversed_a0 = DFT(a0), inversed_a1 = DFT(a1);
	vector<complex<double>> inversed_a(n);
	for (int i = 0; i < n; ++i) {
		complex<double> zeta = complex<double>(cos(2 * Ma_PI * i / n), sin(2 * Ma_PI * i / n));
		inversed_a[i] = inversed_a0[i % (n / 2)] + zeta * inversed_a1[i % (n / 2)];
	}
	return inversed_a;
}
vector<complex<double>> IDFT(vector<complex<double>> inversed_a) {
	int n = inversed_a.size();
	vector<complex<double>> now = DFT(inversed_a);
	reverse(now.begin(), now.end());
	for (int q = now.size() - 1; q >= 1; --q) {
		swap(now[q], now[q - 1]);
	}
	REP(i, n) {
		now[i] /= complex<double>(n, 0);
	}
	return now;
}
vector<complex<double>> conv(vector<complex<double>> a, vector<complex<double>> b) {
	int deg = a.size() + b.size() - 1;
	int n = 1;
	while (n < deg) n <<= 1;
	a.resize(n);
	b.resize(n);
	vector<complex<double>> inversed_a = DFT(a), inversed_b = DFT(b);
	vector<complex<double>> inversed_c(n);
	REP(i, n) {
		inversed_c[i] = inversed_a[i] * inversed_b[i];
	}
	return IDFT(inversed_c);
}
long long inv(long long now) {
	long long hoge = MOD - 2LL;
	long long ans = 1;
	while (hoge != 0) {
		if (hoge % 2 == 1) {
			ans *= now;
			ans %= MOD;
		}
		hoge /= 2;
		now *= now;
		now %= MOD;
	}
	return ans;
}
long long jun[2100000] = {};
long long gyaku[2100000] = {};
long long combination(long long a, long long b) {
	long long ans = jun[a];
	ans *= gyaku[a - b];
	ans %= MOD;
	ans *= gyaku[b];
	ans %= MOD;
	return ans;
}
long long no_limit(long long a, long long b) {
	return combination(a + b - 1, a);
}

int main() {
	long long s;
	cin >> s;
	long long geko = sqrt(s);
	if (geko * geko < s) {
		geko++;
	}
	s = geko*geko - s;
	for (long long i = 1;; ++i) {
		if (s % i == 0) {
			long long tmp = s / i;
			if (tmp <= 1e9) {
				cout << "0 0 ";
				cout << geko << " " << i << " ";
				cout << tmp << " " << geko;
				cout << endl;
				return 0;
			}
		}
	}
}

Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;
int n,i,b[1000233];
int main()
{
    cin>>n;
    for(int i=2;i<=1000000;i++)
    {
        if(b[i]) continue;
        for(int j=i;j<=1000000/i;j++) b[i*j]=1;
    }
    i=n;
    while(1)
    {
    	if(!b[i]) {cout<<i;break;}
    	i++;
	}
    return 0;
}

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

int main() {
    int n, q; cin >> n >> q;
    int ofs = 0;
    while (q--) {
        int op, k; cin >> op >> k;
        if (op == 0) cout << (ofs + k - 1) % n + 1 << endl;
        if (op == 1) ofs = (ofs + k) % n;
    }
    return 0;
}



Measured memory_bytes: 3132
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))

n = getN()
nums = getList()

def solve(nums):
    tmp = nums[0]
    res = []
    for num in nums[1:]:
        res.append(tmp * 2)
        tmp = num - tmp

    for i in range(n-1):
        if i % 2 == 0:
            res[i] -= tmp
        else:
            res[i] += tmp

    res = [tmp] + res

    return res

ans = (solve(nums))

print(" ".join(list(map(str, ans))))

Measured memory_bytes: 77156
#include<stdio.h>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<map>
#include<queue>
#include<cstdlib>
#include<ctime>
#define rep(i,j,k) for(register int i = j; i <= k; i++)
#define dow(i,j,k) for(register int i = j; i >= k; i--)
#define ll long long
#define mp make_pair
using namespace std;
 
inline int read() {
	int s = 0, t = 1; char c = getchar();
	while( !isdigit(c) ) { if( c == '-' ) t = -1; c = getchar(); }
	while( isdigit(c) ) s = s * 10 + c - 48, c = getchar();
	return s * t;	
} 

const int N = 2e5+5;
int v[N], ans[N];

int main() {
	int n = read();
	rep(i,1,n) v[i] = read(); 
	int l = 1, r = n, tot = n;
	while( tot ) { 
		ans[l++] = v[tot--];
		if( tot ) ans[r--] = v[tot--];
	}
	rep(i,1,n) cout<<ans[i]<<" "; cout<<endl;
    return 0;
} 

Measured memory_bytes: 3712
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
    return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
    for(auto &e:t) fill_v(e,v);
}

template<typename T>
map<T, int> primeMap(T n) {
  map<T, int> mp;

  for(T i = 2; i <= n; i++){
    T x = i;
    for(T j = 2; x != 1; j++){
      int cnt = 0;
      while(x % j == 0){
        x /= j;
        cnt++;
      }
      if(cnt > 0) mp[j] += cnt;
    }
  }
  
  return mp;
}

int main() {
  constexpr int mod = 1e9 + 7;
  int n; cin >> n;

  map<int, int> mp = primeMap(n);

  ll ans = 1;
  for(const auto& x: mp){
    (ans *= x.second + 1) %= mod;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>
#include <numeric>
#include <cctype>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <utility>
#include <fstream>

using namespace std;
typedef long long ll;

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; }
template<typename T> T gcd(T a, T b) { a = abs(a), b = abs(b); while (b > 0) { tie(a, b) = make_pair(b, a % b); } return a; }
//mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

constexpr long long INF = 1LL << 60;
constexpr int inf = 1000000007;
constexpr long long mod = 1000000007LL;
//constexpr long long mod = 998244353;
constexpr int MAX = 5000000;

vector<int> topological(vector<vector<int>>& g) {
	vector<int> topo;
	int n = g.size();
	vector<int> deg(n);
	for (int i = 0; i < n; i++) for (auto next : g[i]) deg[next]++;
	queue<int> q;
	for (int i = 0; i < n; i++) if (deg[i] == 0) q.push(i), topo.push_back(i);
	while (!q.empty()) {
		int cur = q.front();
		q.pop();
		for (auto next : g[cur]) {
			deg[next]--;
			if (deg[next] == 0) {
				q.emplace(next);
				topo.push_back(next);
			}
		}
	}
	return topo;
}
int main()
{

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int n, m; cin >> n >> m;
	vector<vector<int>> g(n);
	for (int i = 0; i < m; i++) {
		int u, v; cin >> u >> v;
		u--; v--;
		g[u].emplace_back(v);
	}
	{
		auto t = topological(g);
		if (t.size() == n) {
			cout << -1 << endl;
			return 0;
		}
	}
	int cyclen = inf;
	for (int st = 0; st < n; st++) {
		vector<int> d(n, inf);
		vector<int> back(n, -1);
		queue<int> q;
		q.emplace(st);
		d[st] = 0;
		while (!q.empty()) {
			int cur = q.front();
			q.pop();
			for (auto nxt : g[cur]) {
				if (chmin(d[nxt], d[cur] + 1)) {
					q.emplace(nxt);
					back[nxt] = cur;
				}
				else if(nxt == st){
					chmin(cyclen, d[cur] + 1);
				}
			}
		}
	}
	for (int st = 0; st < n; st++) {
		vector<int> d(n, inf);
		vector<int> back(n, -1);
		queue<int> q;
		q.emplace(st);
		d[st] = 0;
		while (!q.empty()) {
			int cur = q.front();
			q.pop();
			for (auto nxt : g[cur]) {
				if (chmin(d[nxt], d[cur] + 1)) {
					q.emplace(nxt);
					back[nxt] = cur;
				}
				else if(nxt == st){
					if (cyclen == d[cur] + 1) {
						vector<int> res;
						while (cur != st) {
							res.emplace_back(cur);
							cur = back[cur];
						}
						res.emplace_back(st);
						cout << res.size() << "\n";
						for (auto e : res) cout << e + 1 << "\n";
						return 0;
					}
				}
			}
		}
	}
	return 0;
}

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

typedef long long LL;

int par[200000], cnt[200000];

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

struct edge{
	int a, b, c;
	bool operator< (const edge &e) const{
		return c < e.c;
	}
} e[200000];

int main(){
	int n, a, b, c;
	cin >> n;
	for(int i = 0; i < n; ++i){
		par[i] = i;
		cnt[i] = 1;
	}
	for(int i = 0; i < n - 1; ++i){
		cin >> e[i].a >> e[i].b >> e[i].c;
	}
	sort(e, e + (n - 1));

	LL s = 0;
	for(int i = 0; i < n - 1; ++i){
		int x = find(e[i].a);
		int y = find(e[i].b);
		s += (LL)e[i].c * cnt[x] * cnt[y];
		par[y] = x;
		cnt[x] += cnt[y];
	}
	cout << s << '\n';
}

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

int main() {
    int N; cin >> N;
    string S; cin >> S;
    int a = 0;
    int b = 0;
    int sa = 1001001001;
    rep(i, N){
        if(S[i] == '('){
            a++;
        } else {
            b++;
        }
        sa = min(sa, a-b);
    }

    sa *= -1;
    rep(i, sa){
        S = "(" + S;
    }

    if(sa > 0){
        a += sa;
    }
    int sa2 = a-b;
    rep(i, sa2){
        S = S + ")";
    }

    cout << S << endl;

    return 0;
}

Measured memory_bytes: 3496
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;
using namespace __gnu_pbds;
auto random_address = [] { char *p = new char; delete p; return uint64_t(p); };
const uint64_t SEED = chrono::steady_clock::now().time_since_epoch().count() * (random_address() | 1);
mt19937_64 rng(SEED);
typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
ll n,m,x,suma;
vector<ll> vals;
ll f[500001];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>n>>x>>m;
    vals.push_back(x);
    suma=x;
    n--;
    f[x]=1;
    ll val=x;
    int poz=1;
    while(n>0)
    {
        val=(val*val)%m;
        poz++;
        if(val==0)
        {
            cout<<suma;
            return 0;
        }
        if(f[val]>0)
        {
            poz=f[val];
            break;
        }
        f[val]=poz;
        vals.push_back(val);
        suma+=val;
        n--;
    }
    if(n==0)
    {
        cout<<suma;
        return 0;
    }
    ll ans=suma;
    vector<ll> v;
    for(int i=poz-1;i<vals.size();i++)
        v.push_back(vals[i]);
    suma=0;
    for(auto i:v)
        suma+=i;
    ll lg=v.size();
    ll cat=n/lg;
    ans+=cat*suma;
    ll rest=n%lg;
    for(int i=0;i<rest;i++)
        ans+=v[i];
    cout<<ans;
    return 0;
}


Measured memory_bytes: 5056
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1LL << 60;

int main() {
    int n;
    cin >> n;
    vector<int> p(n);
    for (int i = 0; i < n; i++) {
        cin >> p.at(i);
    }
    int cnt = 0;
    for (int i = 0; i < n; i++) {
        if (p.at(i) != i + 1) {
            cnt++;
        }
    }
    string ans = "YES";
    if (cnt > 2) {
        ans = "NO";
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3596
N=int(input())
S=["".join(sorted(input())) for i in range(N)]

dic = {}
for s in S:
    if s in dic.keys():
        dic[s] += 1
    else:
        dic[s] = 1

count = 0
for k in dic.keys():
    c = dic[k]
    count += (c * (c - 1)) // 2
print(count)



Measured memory_bytes: 19404