akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; i++)
#define repr(i, s, e) for(int i=s; i>=e; i--)
#define reps(i, s, e) for(int i=s; i<e; i++)
#define inf 1e18
#define vsort(v) sort(v.begin(), v.end())
#define vsortr(v) sort(v.begin(), v.end(), greater<ll>())
#define sz(x) x.size()
#define ceil(a, b) (a+b-1)/b
#define ok cout << "ok" << endl;
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T &a, T b){ if(a<b){ a=b; return true; } return false; }
template<typename T> inline bool chmin(T &a, T b){ if(b<a){ a=b; return true; } return false; }
template<typename T> T gcd(T a, T b){ if(b==0) return a; return gcd(b, a%b); }
template<typename T> T lcm(T a, T b){ return a*b/gcd(a, b); }
template<typename T> void vdebug(vector<T> v){ for(auto vv : v){ cout << vv << " "; } cout << endl; }
template<typename T> void adebug(T arr[], int n){ rep(i, n){ cout << arr[i] << " "; } cout << endl; }
void ans(bool b){ if(b) cout << "Yes" << endl; else cout << "No" << endl; }
void ans2(bool b){ if(b) cout << "YES" << endl; else cout << "NO" << endl; }
int keta(ll num){ int k=0; while(num>0){ num/=10; k++; } return k; }
int dx[] = {1, -1, 0, 0, 1, -1, 1, -1};
int dy[] = {0, 0, 1, -1, 1, -1, -1, 1};


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

    ll n, T, t, last=0;
    cin >> n >> T;

    ll res = 0;
    rep(i, n){
        cin >> t;
        if(i==0){
            last = t;
            continue;
        }
        res += min(T, t-last);
        last = t;
    }
    res += T;

    cout << res << endl;

    return 0;
}

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

using namespace std;

#define MOD 100000

#define MAX_H 105
#define MAX_W 105

int H, W;

int dp[MAX_H][MAX_W][4];

int main()
{
	while (true)
	{
		cin >> W >> H;

		if (W == 0 && H == 0) { break; }

		memset(dp, 0, sizeof(dp));

		for (int i = 0; i < H; i++)
			dp[i][0][2] = 1;

		for (int j = 0; j < W; j++)
			dp[0][j][3] = 1;

		for (int i = 1; i < H; i++)
		{
			for (int j = 1; j < W; j++)
			{
				dp[i][j][0] = dp[i - 1][j][3];
				dp[i][j][1] = dp[i][j - 1][2];
				
				for (int k = i - 1; k >= 1; k--)
				{
					dp[i][j][2] += dp[k][j][0];
				}

				dp[i][j][2] %= MOD;

				for (int k = j - 1; k >= 1; k--)
				{
					dp[i][j][3] += dp[i][k][1];
				}

				dp[i][j][3] %= MOD;
			}
		}

		cout << (dp[H - 1][W - 1][0] + dp[H - 1][W - 1][1] + dp[H - 1][W - 1][2] + dp[H - 1][W - 1][3]) % MOD << endl;
	}

	return 0;
}

Measured memory_bytes: 3244
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<cmath>
using namespace std;
#define ll long long
#define db double

int main()
{
    ll x1=0,y1=0;
    ll x3=1000000000;
    ll x2=1,y2=0,y3=0;
    ll s;
    scanf("%lld",&s);
    y2=(s/x3)+1;
    if(y2>1000000000)y2=1000000000;
    y3=y2*x3-s;
    printf("%lld %lld %lld %lld %lld %lld",x1,y1,x2,y2,x3,y3);
    return 0;
}


Measured memory_bytes: 3244
#include <iostream>
#include <bits/stdc++.h>
#include <time.h>
#include <sys/timeb.h>
#include <cstdio>
#include <sys/time.h>

using namespace std;
#define ll long long
#define uint unsigned int
#define ulong unsigned long long int

template<typename T> bool InRange(T t, T l, T r){ return l <= t && t < r; }

int main(){
	
	bool isPrime[55556];
	for(int i=0;i<55556;i++) isPrime[i] = false;
	for(int i=2;i<55556;i++) isPrime[i] = true;
	for(int i=2;i<55556;i++){
		if(!isPrime[i]) continue;
		for(int j=i+i;j<55556;j+=i) isPrime[j] = false;
	}
	
	vector<int> p;
	for(int i=2;i<55556;i++){
		if(i % 10 == 1 && isPrime[i]) p.push_back(i);
	}
	
	//cerr << p.size() << endl;
	
	int N;
	cin >> N;
	for(int i=0;i<N;i++){
		cout << (i == 0 ? "" : " ") << p[i];
	}
	cout << endl;
	
    return 0;
}

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

int main(){
  int a, b;
  cin >> a >> b;
  
  if (a == 1) {
    a += 13;
  }
  if (b == 1) {
    b += 13;
  }
  
  if (a > b) {
    cout << "Alice" << endl;
  } else if (a < b) {
    cout << "Bob" << endl;
  } else {
    cout << "Draw" << endl;
  }
  
}
    

Measured memory_bytes: 3636
//In the name of GOD
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

const ll maxn = 2e5 + 100;
const ll mod = 1e9 + 7;
const ll inf = 1e18;

#define fast_io ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io freopen("input.txt" , "r+" , stdin) ; freopen("output.txt" , "w+" , stdout);
#define pb push_back
#define Mp make_pair
#define pll pair<ll, ll>
#define F first
#define S second

typedef __uint128_t L;
L x;
ll a[maxn], n;

int main(){
	fast_io;
	
	x = 1;
	cin >> n;
	for(ll i = 0; i < n; i++){
		cin >> a[i];
		if(a[i] == 0){
			cout << 0;
			return 0;
		}
	}
	for(ll i = 0; i < n; i++){
		x *= a[i];
		if(x > inf){
			cout << -1;
			return 0;
		}
	}
	cout << ll(x);
	
	return 0;
}


Measured memory_bytes: 4432
import java.util.*;

public class Main {
  private static int INF = 1_000_000_000;
  private static int H;
  private static int W;
  private static int[][] d;
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    H = sc.nextInt();
    W = sc.nextInt();
    d = new int[H][W];
    int black = 0;
    for (int i = 0; i < H; i++) {
      String s = sc.next();
      for (int j = 0; j < W; j++) {
        if (s.charAt(j) == '.') {
          d[i][j] = INF;
        } else {
          d[i][j] = -1;
          black++;
        }
      }
    }
    LinkedList<Point> q = new LinkedList<>();
    q.offer(new Point(0, 0));
    d[0][0] = 0;
    while (!q.isEmpty()) {
      Point p = q.poll();
      for (int v = 0; v < 4; v++) {
        int ii = p.i+dy[v];
        int jj = p.j+dx[v];
        if (0 <= ii && ii < H
            && 0 <= jj && jj < W
            && d[ii][jj] != -1
            && d[ii][jj] > d[p.i][p.j]+1) {
          d[ii][jj] = d[p.i][p.j]+1;
          q.offer(new Point(ii, jj));
        }
      }
    }
    int ans = d[H-1][W-1] == INF ? -1 : H*W-black-d[H-1][W-1]-1;
    System.out.println(ans);
  }
  
  private static class Point {
    final int i;
    final int j;
    Point(int i , int j) {
      this.i = i;
      this.j = j;
    }
  }
  
  private static int[] dx = { 0, 0, 1, -1 };
  private static int[] dy = { 1, -1, 0, 0};
}

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

using namespace std;

int main()
{
    long long a,b,c;
    cin >> a >> b >> c;
    
    if((a == b) &&(b == c)&&(c == a))
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    return 0;    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using vpii = vector<pair<int, int>>;
using vpll = vector<pair<ll, ll>>;

int		main(void)
{
	int a, b, c;
	cin >> a >> b >> c;
	cout << c << " " << a << " " << b << endl;
}



Measured memory_bytes: 256
from sys import stderr

def reads():
  return [int(x) for x in input().split()]

N, M, K = reads()
A = reads()

dp = [[0] * N, list(A)]
deq = [0] * N
for j in range(2, K+1):
  l = r = 0
  b = j & 1
  prev = dp[1-b]; curr = dp[b]
  for i in range(N):
    # pop
    while l < r and deq[l] < i-M:
      l += 1
    # max
    curr[i] = (j * A[i] + prev[deq[l]]) if (i >= j-1 and l < r) else 0
    # append
    while l < r and prev[deq[r-1]] <= prev[i]:
      r -= 1
    deq[r] = i; r += 1

print(max(dp[K & 1]))


Measured memory_bytes: 65704
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
#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, K, Q;
  cin >> N >> K >> Q;
  vector<int> hp(N, K - Q); //とりあえず全員Q点減点
  for(int i = 0; i < Q; i++){
    int a;
    cin >> a;
    a--;
    hp.at(a)++;
  }
  for(int i = 0; i < N; i++){
    cout << (hp.at(i) > 0? "Yes": "No") << endl;
  }
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define Cout(s) cout << s << endl;
using ll = long long;
using P = pair<int, int>;

const ll INF = 1ll << 60;
ll MOD = 1e9 + 7;

int main()
{

    int n, m;
    cin >> n >> m;

    int k[31];
    vector<int> f(m);
    REP(i, n)
    {
        cin >> k[i];
        REP(j, k[i])
        {
            int v;
            cin >> v;
            v--;
            f[v]++;
        }
    }

    int ans = 0;
    REP(i, m)
    {
        if (f[i] >= n)
            ans++;
    }
    Cout(ans);
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <vector>

// lib/util.hpp
#ifndef UTIL_HPP
#define UTIL_HPP


typedef ::std::int_fast64_t i64;
typedef ::std::uint_fast64_t u64;
typedef ::std::int_fast32_t i32;
typedef ::std::uint_fast32_t u32;

namespace tools {
  template <typename T>
  void read(::std::istream& is, ::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    vector.reserve(size);
    ::std::copy_n(::std::istream_iterator<T>(is), size, ::std::back_inserter(vector));
  }
  template <typename T>
  void read(::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    ::tools::read(::std::cin, vector, size);
  }

  template <typename T, ::std::size_t N>
  void read(::std::istream& is, ::std::array<T, N>& array) {
    ::std::copy_n(std::istream_iterator<T>(is), N, array.begin());
  }
  template <typename T, ::std::size_t N>
  void read(::std::array<T, N>& array) {
    ::tools::read(::std::cin, array);
  }
}

#endif

// main.cpp

int main() {
  i64 A, B, K;
  std::cin >> A >> B >> K;

  for (i64 i = 0; i < K; ++i) {
    i64& me = i % 2 == 0 ? A : B;
    i64& you = i % 2 == 0 ? B : A;
    if (me % 2 == 1) --me;
    const i64 give = me / 2;
    me -= give;
    you += give;
  }

  std::cout << A << ' ' << B << std::endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define f first
#define s second
#define pb push_back
#define mp make_pair
using namespace std;
ll n,fix[100005],as,bs,ans;
string s[100005],bos;
vector<ll>both,a,b;
int main(){
    cin >> n;
    
    for(int i=1; i<=n; i++){
        cin >> s[i];
        if(s[i][0] == 'B' && s[i][(int)s[i].size() - 1] == 'A'){
            both.pb(i);
        }
        else if(s[i][0] == 'B'){
            b.pb(i);
        }
        else if(s[i][(int)s[i].size() - 1] == 'A')a.pb(i);
    }
    
    
    if(a.size()){
        fix[a[0]] = 1;
        bos += s[a[0]];
        as++;
    }
    
    for(int i=0; i<both.size(); i++){
        bos += s[both[i]];
        fix[both[i]] = 1;
    }
    while(bs < b.size() && as<a.size()){
        bos += s[b[bs]];
        fix[b[bs]] = 1;
        bs++;
        bos += s[a[as]];
        fix[a[as]] = 1;
        as++;
    }
    
    if(bs < b.size()){
        bos += s[b[bs]];
        fix[b[bs]] = 1;
        bs++;
    }
    
    
    for(int i=1; i<=n; i++)if(!fix[i])bos += s[i];
    
    for(int i=1; i<bos.size(); i++){
        if(bos[i] == 'B' && bos[i - 1] == 'A'){
            ans++;
        }
    }
    
    cout << ans;
    
    
    
    
    return 0;
}


Measured memory_bytes: 1792
def main():
    N = int(input())
    S = input()
    from collections import Counter
    c = Counter(S)
    ans = 1 if len(c.keys()) > 2 else 0
    for v in c.values():
        ans *= v
    less = 0
    for d in range(1, N+1):
        for i in range(N):
            # 差dで三つが異なるなら条件を満たさないので取り除く
            if i+d < N and i+2*d < N and \
                    S[i] != S[i+d] and S[i] != S[i+2*d] and S[i+d] != S[i+2*d]:
                less += 1
    print(ans - less)


if __name__ == '__main__':
    main()


Measured memory_bytes: 74132
import itertools
N,M,R=map(int,input().split())
r=list(map(int,input().split()))

L=[[10**15 for i in range(N)]for j in range(N)]
for i in range(N):
    L[i][i]=0
for a in range(M):
    A,B,C=map(int,input().split())
    L[A-1][B-1]=C
    L[B-1][A-1]=C

#print(L)

for c in range(N):
    for a in range(N):
        for b in range(N):
            L[a][b]=min(L[a][b],L[a][c]+L[c][b])
#print(L)
LIS=list(itertools.permutations(r))
#print(LIS)
ans=10**15
#print(LIS[0][2])
for i in range(len(LIS)):
    cnt=0
    for x in range(1,len(r)):
        #print(i,x)
        cnt+=L[LIS[i][x-1]-1][LIS[i][x]-1]
    if cnt<ans:
        ans=cnt
print(ans)

Measured memory_bytes: 53208
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<string>
#include<cctype>
using namespace std;

bool check(int W,int H,int x,int y,int r){
	if(x<=0||y<=0)return 0;
	if(x-r<0||y-r<0)return 0;
	if(x+r>W||y+r>H)return 0;
	return 1;
}

int main(){
int w,h,x,y,r;
cin>>w>>h>>x>>y>>r;
if(check(w,h,x,y,r))cout<<"Yes"<<endl;
else cout<<"No"<<endl;


return 0;
}

Measured memory_bytes: 1156
#include<iostream>
#include<stdio.h>
using namespace std; 
int main(){
	int x[140]={0};
	char a;
	while(1){
		a=getchar();
		if(a==EOF)break;
		if(a<97)x[a+32]++;
		else x[a]++;
	}
	for(int i=97;i<123;i++){
		cout<<(char)i<<" : "<<x[i]<<endl;
	}
}

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

int N;

void chmax(int &a,int b){
    if(a<b) a=b;
}

void solve(){
    vector<int> w(N);
    for(int i=0;i<N;i++) cin>>w[i];

    int dp[303][303]={};
    for(int i=0;i<N-1;i++){
        if(abs(w[i]-w[i+1])<=1) dp[i][i+1]=2;
    }

    for(int k=3;k<=N;k++){
        for(int i=0;i+k-1<N;i++){
            int lef=i;
            int rig=i+k-1;
            for(int j=lef;j<rig;j++){
                chmax(dp[lef][rig],dp[lef][j]+dp[j+1][rig]);
            }
            if(abs(w[lef]-w[rig])<=1&&dp[lef+1][rig-1]==(k-2)) dp[lef][rig]=k;
        }
    }

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

int main(){
  while(1){
      cin>>N;
      if(N==0) break;
      solve();
  }

  return 0;
}



Measured memory_bytes: 3440
def main():
  a, b, x = map(int, input().split())
  vm = a*a*b
  if x==vm:
    return 0
  elif x>vm/2:
    return 90-math.degrees(math.atan(a**3/(2*(vm-x))))
  else:
    return 90-math.degrees(math.atan(2*x/(a*b*b)))

if __name__ == '__main__':
  import math
  print(main())

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <cstdio>
#include <cctype>

using namespace std;

int alphas[26];

int main(void) {

    string line;
    while (getline(cin, line)) {
        for (int i = 0; i < line.size(); ++i) {
            char ch = line[i];
            if (isalpha(ch)) {
                ++alphas[toupper(ch) - 'A'];
            }
        }
    }

    for (int i = 0; i < 26; ++i) {
        printf("%c : %d\n", i + 'a', alphas[i]);
    }

    return 0;
}

Measured memory_bytes: 1192
// vjusge5
#include<iostream>
#include<vector>
using namespace std;
bool check(vector<int> u, int x)
{
for(int i=0;i<u.size();i++)
{
if(u[i]<x)
	return false;
}
return true;
}


int main()
{
    int n,flag=0,y,m,x,ans=INT_MAX;
    cin>>n>>m>>x;
    vector<int> c(n);
    vector<vector<int>> a(n,vector<int>(m));
    
    for(int i=0;i<n;i++)
    {
    for(int j=0;j<=m;j++)
    {
    if(j==0)
    cin>>c[i];
    else
    cin>>a[i][j-1];	
    }
    }
   
    int tot=1<<n;
    int cost;
    
    for(int mask=0;mask<tot;mask++)
    {
    vector<int> u(m,0);
    cost=0;
    for(int i=0;i<n;i++)
    {
    if((mask&(1<<i))!=0)
    {
    cost+=c[i];
    for(int j=0;j<m;j++)
    u[j]+=a[i][j];
    }	
    }
    if(check(u,x))
    {
    flag=1;
    ans=min(ans,cost);	
    }
    }
    if(flag==0)
    	cout<<-1;
    else
        cout<<ans;
    
	return 0;
}


Measured memory_bytes: 3148
#include<stdio.h>
#include<string.h>
int main ()
{
	char card[3][101]={0};
	for(int i =0;i<3;++i){
		scanf("%s",card[i]);
		getchar();
	}
	int c[3] = {0};
	int p = 0;
	while(1){
		if(card[p][c[p]] == 'a'){
			c[p]++;
			p=0;
		}else if(card[p][c[p]] == 'b'){
			c[p]++;
			p=1;
		}else if(card[p][c[p]] == 'c'){
			c[p]++;
			p=2;
		}else if(card[p][c[p]] == '\0'){
			break;
		}
	}
	printf("%c",p==0?'A':p==1?'B':'C');
}


Measured memory_bytes: 128
//Relive your past life.
//Face your demons.
//The past is never dead,it is not even past.
//The memories are not only the key to the past but...also to the future.
//coded in Rusty Lake
#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
#define ll   long long
#define pb   push_back
#define mp   make_pair
#define orz  1000000007
using namespace std;
string s;
int _,ans;
int main(){
    ios::sync_with_stdio(0);
    cin>>s;
    for(int i=0;i<s.size();++i){
        if(s[i]=='S')++_;
        else{
            if(!_)++ans;
            else --_;
        }
    }
    cout<<ans+max(0,_)<<endl;
    //system("pause");
    return 0;
}


Measured memory_bytes: 720
/*

* author:mel0n
* le epic style 
*
*

*/

#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false);cin.tie(0)
#define lli long long int
#define pi pair<int,int>
#define all(x) (x).begin(),(x).end()

using namespace std;



int main()
{
lli n;
cin>>n;

if(n%1000==0)
	cout<<0<<endl;
else 
{
lli i=1000;
while(true)
{
if(i<n)
	i=i+1000;
else
	break;

}

cout<<i-n<<endl;

}


return 0;
}



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

int main(){
    int a,b;
    cin >> a >> b;
    int answer = 0;
    for(int i = a; i <= b; i++){
        //一番左の桁
        int ll = i / 10000;
        //左から二番目の桁
        int lc = (i / 1000) % 10;
        //右からに二番目の桁
        int rc = (i / 10) % 10;
        //一番右の値
        int rr = i % 10;
        //回文数になる時、一番端の桁、一番端から一つ中の桁同士がそれぞれ等しい
        if(ll == rr && rc == lc){
            answer++;
        }
    }
    cout << answer << endl;
}



Measured memory_bytes: 256
#include<iostream>
#include<cstdlib>
#include<string>
#include<vector>
#include<map>
#include<unordered_map>
#include<queue>
#include<algorithm>
#include<iomanip>
#include<typeinfo>
#include<complex>
using namespace std;
using ll = long long int;
const int mod = 1e9 + 7;
#define rep(i, a, b) for(ll i = a;i < b; i++)
const long double PI = (acos(-1));

int main() {

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

	int ans = 0;

	rep(i, 0, 2) {
		if (a > b) {
			ans += a;
			a--;
		}
		else {
			ans += b;
			b--;
		}
	}

	cout << ans << endl;

	return 0;
}

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

const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;

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

    ll x,y;
    cin >> x >> y;

    ll ans = 0;

    if (x * y > 0){
        if (x <= y){
            ans = y-x;
        }
        else{
            ans = x-y+2;
        }
    }
    else if (x * y == 0){
        if (x == 0){
            if (y >= 0){
                ans = y;
            }
            else{
                ans = abs(y)+1;
            }
        }
        else{
            if (x < 0){
                ans = abs(x);
            }
            else{
                ans = x+1;
            }
        }
    }
    else{
        if (abs(x) >= abs(y)){
            ans = abs(x)-abs(y)+1;
        }
        else{
            ans = abs(y)-abs(x)+1;
        }
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 3584
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
typedef pair<int, int> P;
typedef pair<P, int> PP;

int a[200005], b[200005];
vector<int> c[200005], d[200005];
PP p[200005];
int ans[200005];

int main()
{
    int n;
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> a[i];
        a[i]--;
        c[a[i]].push_back(i);
    }
    for(int i = 0; i < n; i++){
        cin >> b[i];
        b[i]--;
        d[b[i]].push_back(i);
    }
    for(int i = 0; i < n; i++){
        if((int)c[i].size() + (int)d[i].size() > n){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    for(int i = 0; i < n; i++){
        p[i] = PP(P((int)c[i].size(), (int)d[i].size()), i);
    }
    sort(p, p + n, greater<PP>());
    queue<P> que;
    int j = 0;
    int i;
    for(i = 0; i < n; i++){
        if(i == j){
            que.push(P(p[j].first.first, p[j].second));
            j++;
        }
        int u = p[i].second;
        while(d[u].size() && j < n){
            int v = p[j].second;
            while(c[v].size() == 0 && j < n){
                j++;
                v = p[j].second;
            }
            if(j == n) break;
            ans[c[v].back()] = d[u].back();
            d[u].pop_back();
            p[i].first.second--;
            c[v].pop_back();
            p[j].first.first--;
        }
        if(j == n) break;
    }
    for(; i < n; i++){
        if(que.empty()) break;
        int u = p[i].second;
        P q = que.front();
        que.pop();
        int v = q.second;
        while((int)d[u].size() >= q.first){
            for(int t = 0; t < q.first; t++){
                ans[c[v].back()] = d[u].back();
                d[u].pop_back();
                c[v].pop_back();
            }
            if(que.empty()) break;
            q = que.front();
            que.pop();
            v = q.second;
        }
        while(d[u].size()){
            ans[c[v].back()] = d[u].back();
            d[u].pop_back();
            c[v].pop_back();
        }
        que.push(P((int)c[v].size(), v));
    }
    for(int i = 0; i < n; i++) cout << b[ans[i]] + 1 << " ";
    cout << endl;
}


Measured memory_bytes: 31264
n = int(input())
num_list = [ int(v) for v in input().split() ]

symple_sum, xor_sum = num_list[0], num_list[0]
ans = 0
l, r = 0, 0


while l < n:
    stop_r = 0
    while stop_r == 0:
        if r == n - 1:
            stop_r = 1

        elif symple_sum ^ num_list[r+1] == xor_sum + num_list[r+1]:
            symple_sum ^= num_list[r+1]
            xor_sum += num_list[r+1]
            r += 1
        else:
            stop_r = 1

    ans += r - l + 1

    symple_sum ^= num_list[l]
    xor_sum -= num_list[l]
    l += 1

print(ans) 


Measured memory_bytes: 77772
#include <iostream>
#include <vector>
#include <algorithm>
#define INF (1<<30)
using namespace std;

int knapsack(int n, int wei,int W,vector<int>&v,vector<int>& w,vector<vector<int>>& dp) {
	if (wei > W) return -INF;
	if (n == v.size()) return 0;
	if (dp[n][wei] >= 0) return dp[n][wei];
	return dp[n][wei] = max(knapsack(n + 1, wei, W, v, w, dp), knapsack(n + 1, wei + w[n], W, v, w, dp) + v[n]);
}

int main() {
	cin.tie(0); ios::sync_with_stdio(false);
	int N, W; cin >> N >> W;
	vector<int> v(N), w(N);
	for (int i = 0; i < N;i++) {
		cin >> v[i] >> w[i];
	} 
	/* dp */
	/*
	vector<vector<int>> dp(N + 1, vector<int>(W + 1, 0));
	for (int i = 0; i < N; i++) {
		for (int j = 1; j <= W;j++) {
			if (j - w[i] < 0) { dp[i + 1][j] = dp[i][j]; }
			else { dp[i + 1][j] = max(dp[i][j], dp[i][j - w[i]] + v[i]); }
		}
	}
	cout << dp[N][W] << endl;
	*/

	/* dps + memo */
	vector<vector<int>> dp(N + 1, vector<int>(W + 1, -INF));
	cout << knapsack(0, 0, W, v, w, dp) << endl;
}

Measured memory_bytes: 6804
#include <iostream>

int main(){
   std::string S;
   std::cin >> S;

   //suppose 0101...
   int count1 = 0;
   //suppose 1010...
   int count2 = 0;
   for(int i=0; i<S.size(); ++i){
      if(i%2==0 && S[i]=='1') ++count1;
      else if(i%2==1 && S[i]=='0') ++count1;

      if(i%2==0 && S[i]=='0') ++count2;
      else if(i%2==1 && S[i]=='1') ++count2;
   }

   std::cout << std::min(count1,count2) << std::endl;
   return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <ctime>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {0,1,0,-1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T> inline void print(T &a){
    rep(i,a.size()) cout << a[i] << " ";
    cout << "\n";
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
const int mod = 1e9 + 7;
//const int mod = 998244353;

int main(){
	ll n,h,w; cin >> n >> h >> w;
	cout << (n-h+1)*(n-w+1) << endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys

MOD = 1000000007  # type: int

def mergeSortInversions(arr):
    if len(arr) == 1:
        return arr, 0
    else:
        a = arr[:len(arr)//2]
        b = arr[len(arr)//2:]
        a, ai = mergeSortInversions(a)
        b, bi = mergeSortInversions(b)
        c = []
        i = 0
        j = 0
        inversions = 0 + ai + bi
    while i < len(a) and j < len(b):
        if a[i] <= b[j]:
            c.append(a[i])
            i += 1
        else:
            c.append(b[j])
            j += 1
            inversions += (len(a)-i)
    c += a[i:]
    c += b[j:]
    return c, inversions

def mergeAndCountSplitInv(c, d):
    # c: left half, d: right half, both sorted
    nc = len(c)
    nd = len(d)
    b = [0] * (nc + nd)
    i, j = 0, 0
    splitInv = 0
    for k in range((nc + nd)):
        if i == nc: # c is used up
            b[k] = d[j]
            j += 1
            continue
        if j == nd: # d is used up
            b[k] = c[i]
            i += 1
            continue

        if c[i] <= d[j]: 
            b[k] = c[i]
            i += 1
        elif c[i] > d[j]:
            b[k] = d[j]
            splitInv += nc - i
            j += 1
    return b, splitInv

def sortCountInv(a):
    # a: list of int
    n = len(a)
    if n <= 1: # base case
        return a, 0
    c, leftInv = sortCountInv(a[ : n//2])
    d, rightInv = sortCountInv(a[n//2: ])
    b, splitInv = mergeAndCountSplitInv(c, d)
    # print(leftInv, rightInv, splitInv)
    return b, leftInv + rightInv + splitInv

def solve(N: int, K: int, A: "List[int]"):
    A_sort, inv = mergeSortInversions(A)
    t = [0] * N
    for i in range(1, N):
        if A_sort[i] > A_sort[i-1]:
            t[i] = i
        else:
            t[i] = t[i-1]
    count = inv * K + sum(t) * (K * (K-1))//2
    count = count % MOD
    print(count)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    A = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, K, A)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3316
import java.util.*;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		while(true){
			int N = sc.nextInt(), M = sc.nextInt();
			if(N == 0 && M == 0) break;

			int[] c = new int[M];
			int[][] dp = new int[N+1][256];

			for(int i=0;i<M;i++) c[i] = sc.nextInt();
			for(int[] tmp : dp) Arrays.fill(tmp,Integer.MAX_VALUE);

			dp[0][128] = 0;

			for(int n=1;n<=N;n++){
				int x = sc.nextInt();
				for(int y=0;y<256;y++){
					for(int k=0;k<M;k++){
						int ny = y + c[k];
						if(255 < ny) ny = 255;
						else if(ny < 0) ny = 0;
						int cost = (ny - x) * (ny - x);
						int sum = dp[n-1][y] == Integer.MAX_VALUE ? Integer.MAX_VALUE : dp[n-1][y] + cost;
						dp[n][ny] = Math.min(dp[n][ny], sum);
					}
				}
			}

			int ans = Integer.MAX_VALUE;
			for(int tmp : dp[N]) ans = Math.min(ans,tmp);

			System.out.println(ans);
		}
	}
}

Measured memory_bytes: 39000
#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(N: int, D: "List[List[int]]"):
    c = 0
    for (x,y) in D:
        if x == y:
            c += 1
            if c >= 3:
                return 'Yes'
        else:
            c = 0
    return 'No'


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    D = [[int(next(tokens)) for _ in range(2)] for _ in range(N)]  # type: "List[List[int]]"
    print(solve(N, D))

if __name__ == '__main__':
    main()


Measured memory_bytes: 9136
#coding:utf-8

apartment = [[[0 for z in range(10)] for y in range(3)] for x in range(4)]
N = int(input())
data = [[int(x) - 1 for x in input().split()] for y in range(N)]
for x in data:
	apartment[x[0]][x[1]][x[2]] += x[3] + 1
	if apartment[x[0]][x[1]][x[2]] > 9:
		apartment[x[0]][x[1]][x[2]] = 9
	elif apartment[x[0]][x[1]][x[2]] < 0:
		apartment[x[0]][x[1]][x[2]] = 0
for x in range(4):
	for y in range(3):
		for z in range(10):
			print(" " + str(apartment[x][y][z]), end="")
		print()
	if x != 3:
		print(("#"*20))

Measured memory_bytes: 7796
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_map>
#include <map>
#include <time.h> //for clock
#define rep(i, a) for (int i = 0; i < (a); i++)
using namespace std;
using ll = long long;

int judge(string s){
    int i;
    int flag = 1;
    for(i = 0; i < s.size(); i++){
        if(s[i]!='A' && s[i]!='T' && s[i]!='G' && s[i]!='C'){
            flag = 0;
            break;
        }
    }

    return flag;
}

int main(){
    string s, t;
    cin >> s;

    int i, j, k;
    int ans = 0;
    for(i = 0; i < s.size(); i++){
        for(j = 1; i+j <= s.size(); j++){
            t = s.substr(i, j);
            if(judge(t)){
                ans = max(ans, j);
            }
        }
    }

    cout << ans << endl;
 }


Measured memory_bytes: 256
//AND BAND KA TOLA JO MERA CODE DEKHRA WO BHEN KA ....
//------------------------------------------Template------------------------------------------------
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define lp(i,a,b) for(ll i=a;i<b;i++)
#define rlp(i,a,b) for(ll i=b;i>=a;i--)
#define TEZI_BOLTEY ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define INF 1e9
#define pb push_back 
#define mp make_pair 
#define endl "\n"
ll nCr(ll n, ll k) {double res = 1;lp(i,1,k+1){res = res * (n - k + i) / i;}return (int)(res + 0.01);}
//---------------------------------------------------------------------------------------------------
//---------------------------------<<< DRAGON SIN MELIODAS >>>---------------------------------------
//---------------------------------------------------------------------------------------------------
int32_t main()
{
	TEZI_BOLTEY
	ll t;
	cin >> t;
	if(t==1)
	cout << 0;
if(t==0)
	cout << 1;
}


Measured memory_bytes: 3636
#include <iostream>
#include <iomanip>
typedef long long ll;
using namespace std;
const  ll INF = 1e9;
const  ll MOD = 1e9 + 7;
#define repi(i,n,init) for(ll i=init;i<(n);i++)

int main()
{
    int inputs[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int k;
    cin >> k;
    cout << inputs[k-1] << endl;
    return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define int long long
#define ll long long
using ull = unsigned long long;
using namespace std;
const int INF = 1ll << 60;
const int MOD = 1e9 + 7;
#define dump(x)                             \
    if (dbg) {                              \
        cerr << #x << " = " << (x) << endl; \
    }
#define overload4(_1, _2, _3, _4, name, ...) name
#define FOR1(n) for (ll i = 0; i < (n); ++i)
#define FOR2(i, n) for (ll i = 0; i < (n); ++i)
#define FOR3(i, a, b) for (ll i = (a); i < (b); ++i)
#define FOR4(i, a, b, c) for (ll i = (a); i < (b); i += (c))
#define FOR(...) overload4(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__)
#define FORR(i, a, b) for (int i = (a); i <= (b); ++i)
#define bit(n, k) ((n >> k) & 1) /*nのk bit目*/
template <class T>
bool chmin(T& a, const T& b) {
    if (a > b) {
        a = b;
        return 1;
    } else
        return 0;
}
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    } else
        return 0;
}
void Yes(bool flag = true) {
    if (flag)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}
void No(bool flag = true) {
    Yes(!flag);
}
void YES(bool flag = true) {
    if (flag)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
}
void NO(bool flag = true) {
    YES(!flag);
}
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T& val) {
    std::fill((T*)array, (T*)(array + N), val);
}
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(), (v).end()
#define SZ(x) ((int)(x).size())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vp vector<pair<int, int>>
#define vvp vector<vector<pair<int, int>>>
#define pi pair<int, int>
//#define P pair<int, int>
//#define V vector<int>
//#define S set<int>
#define itn int
#define asn ans
bool dbg = false;

int N, P[1010], X[1010];
vi C[1010];
bool flag = true;

pi dfs(int idx) {
    int First = 0;
    itn Second = 0;
    itn SUM = 0;
    bitset<5555> BIT(1);
    for (auto& nxt : C[idx]) {
        auto tmp = dfs(nxt);
        int a = tmp.first;  /*  //部分木の重い色の和*/
        int b = tmp.second; /*  //部分木の軽い色の和*/
        //ナップサック？
        /*
        BIT <<= b;
        BIT |= (BIT << (a - b));
        */
        BIT = (BIT << a) | (BIT << b);

        SUM += a + b;
        Second += b;
        First += a;
    }
    /*
    if (First <= X[idx]) {
        return {X[idx], Second};
    }
    */
    for (int i = X[idx]; i >= 0; i--) {
        if (BIT[i]) {
            return {SUM - i, X[idx]};
        }
    }
    //Impossible
    flag = false;
    return {0, 0};
}

void solve() {
    dfs(0);
    if (flag)
        cout << "POSSIBLE" << endl;
    else
        cout << "IMPOSSIBLE" << endl;
}

signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    cin >> N;
    FOR(N - 1) {
        cin >> P[i];
        P[i]--;
        C[P[i]].eb(i + 1);
    }
    FOR(N) {
        cin >> X[i];
    }

    solve();
    return 0;
}


Measured memory_bytes: 1792
#include<stdio.h>
int main(void){
	int i=0;
	int x[10000];
	for (i = 0; i <= 10000; i++){
		scanf("%d", &x[i]);
		if (x[i] == 0){
			break;
		}
	}
	for (i = 0; i <= 10000; i++){
		if (x[i] == 0){
			break;
		}
		printf("Case %d: %d\n", i + 1, x[i]);
		
	}
	return 0;
}

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

int main(){
  int T,D, ta,tb,da,db;
  cin >> T >> D >> ta >> tb >> da >> db;

  double ans = 1e10;
  for(int i=0;i<=D;i+=da){
    for(int j=0;i+j<=D;j+=db){
      if(i==0 && j==0)continue;
      double tmp = (double)(ta*i+tb*j)/(i+j);
      ans = min(ans,abs((double)T-tmp));
    }
  }
  cout << fixed << setprecision(10) << ans << endl;
}

Measured memory_bytes: 1240
s = input()
s1 = s[0]
s2 = s[2:-1]
s = s.replace('A','')
s = s.replace('C','')
t = s.lower()
if(s1 == 'A' and s2.count('C') == 1 and t == s):
    print('AC')
else:
    print('WA')


Measured memory_bytes: 3060
#include<stdio.h>

int main(){

int N;
scanf("%d",&N);
int A[N];
for (int i = 0; i < N; i++){
    scanf("%d",&A[i]);
}
long long stock = 1000/A[0];
long long gain=0,ans=1000;

for (int i = 0; i < N-1; i++)
{
  if (A[i]<A[i+1])
  {
    gain=(A[i+1]-A[i])*stock;
    ans+=gain;
  }else if (A[i]>A[i+1])
  {
    stock = ans/A[i+1];
  }
}

gain > 0 ? printf("%lld",ans):puts("1000");

return 0;

}

Measured memory_bytes: 1736
#include <bits/stdc++.h>
#define int long long
using namespace std;

const int INF = 1e9;

int N, M, W, T, v[7], p[7];

int L[7], X[7], Y[7], q[7][7];

string s[7], r[7][7];

unordered_map<string,int> num;

int dp1_0[1<<7][7];

int dp1[1<<7]; // iの町を訪れる時の最小時間

int dp2[1<<7][7]; // iの町を訪れる時のjの商品の最小価格

int dp3[10005]; // (iの町を訪れる時にj番目までで)kの重さの合計の時の最大利益

vector<int> t, S; // t_i秒消費でsum_i使える

int dp[10005]; // (上のものを使い、i番目までで)jの時間の時の最大利益

int getD(int A, int B){
  return abs( X[A] - X[B] ) + abs( Y[A] - Y[B] );
}

void DP1(){
  
  for(int i=0;i<(1<<N);i++){
    
    for(int j=0;j<N;j++) dp1_0[i][j] = INF;
    
    dp1[i] = INF;
  }
  
  for(int i=0;i<N;i++) dp1_0[1<<i][i] = abs( X[i] ) + abs( Y[i] );
  
  for(int i=0;i<(1<<N);i++){
    
    for(int j=0;j<N;j++){
      
      if( dp1_0[i][j] == INF ) continue;
      
      for(int k=0;k<N;k++){
	
	if( i>>k & 1 ) continue;
	
	int ni = i | ( 1 << k );
	
	dp1_0[ni][k] = min( dp1_0[ni][k], dp1_0[i][j] + getD( j, k ) );
	
      }
      
    }
    
  }
  
  for(int i=0;i<(1<<N);i++){
    
    for(int j=0;j<N;j++){
      
      if( dp1_0[i][j] == INF ) continue;
      
      dp1_0[i][j] += abs( X[j] ) + abs( Y[j] );
      
      dp1[i] = min( dp1[i], dp1_0[i][j] );
      
    }
    
  }
  
}

void DP2(){
  
  for(int i=0;i<(1<<N);i++)
    for(int j=0;j<M;j++) dp2[i][j] = INF;
  
  for(int i=0;i<(1<<N);i++){
    
    for(int j=0;j<N;j++){
      
      if( i >> j & 1 ){
	
	for(int k=0;k<L[j];k++){
	  
	  int idx = num[r[j][k]];
	  
	  dp2[i][idx] = min( dp2[i][idx], q[j][k] );
	  
	}
	
      }
      
    }
    
  }
  
}

void DP3(){
  
  for(int i=0;i<(1<<N);i++){
    
    memset( dp3, 0, sizeof(dp3) );
    
    int minsum = -1;
    
    for(int j=0;j<M;j++){
      
      for(int k=0;k<=W;k++){
		
	int pk = k - v[j];
	
	if( pk < 0 ) continue;
	
	dp3[k] = max( dp3[k], dp3[pk] + ( p[j] - dp2[i][j] ) );
	
	minsum = max( minsum, dp3[k] );
	
      }
      
    }
    
    if( minsum == -1 ) continue;
    
    t.push_back( dp1[i] );
    
    S.push_back( minsum );
    
  }
  
}

int DP(){
  
  int len = (int)t.size();
  
  for(int i=0;i<len;i++){
    
    for(int j=0;j<=T;j++){
      
      int pj = j - t[i];
      
      if( pj < 0 ) continue;
      
      dp[j] = max( dp[j], dp[pj] + S[i] );
      
    }
    
  }
  
  int res = 0;
  
  for(int i=0;i<=T;i++) res = max( res, dp[i] );
  
  return res;
}

signed main(){
  
  cin>>N>>M>>W>>T;
  
  for(int i=0;i<M;i++){
    cin>>s[i]>>v[i]>>p[i];
    num[s[i]] = i;
  }
  
  for(int i=0;i<N;i++){
    
    cin>>L[i]>>X[i]>>Y[i];
    
    for(int j=0;j<L[i];j++){
      
      cin>>r[i][j]>>q[i][j];
      
    }
    
  }
  
  DP1();
  
  DP2();
  
  DP3();
  
  cout<<DP()<<endl;
  
  return 0;
}



Measured memory_bytes: 3412
import java.util.*;

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

Measured memory_bytes: 23124
from collections import deque
q = int(input())
dq = deque()
cur = 0
while q:
    q -= 1
    s = [*map(int, input().split())]
    if s[0] == 0:
        dq.append(s[1])
    elif s[0] == 1:
        dq.rotate(s[1])
        cur += s[1]
    else:
        dq.pop()
dq.rotate(-cur)
dq.reverse()
print(*dq, sep = '\n')


Measured memory_bytes: 24712
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MAX=50000;
ll mod=1e9+7;
#define setbits(x) __builtin_popcount(x)
#define setbitsll(x) __builtin_popcountll(x)
//#define endl '\n'
#define pb push_back
#define se second
#define fi first
#define maxe max_element
#define mine min_element
#define debug(x) cout<<#x<<" :: "<<x<<endl;
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<endl;
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<endl;
#define debug4(x,y,z,w) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\t"<<#w<<" :: "<<w<<endl;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define boost  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)

long long expo(ll x,ll n,ll M)
{
    if(n==0)
        return 1;
    else if(n%2 == 0)        //n is even
        return expo((x*x)%M,n/2,M);
    else                             //n is odd
        return (x*expo((x*x)%M,(n-1)/2,M))%M;

}

bool prime[10000001];
void fin()
{
    for(int i=2;i*i<=1000000;i++)
    {
        if(!prime[i])
        for(int j=i*i;j<=1000000;j+=i)
            prime[j]=true;
    }
}

void solve()
{
  ll a,b,m;
  cin>>a>>b>>m;
  vector<ll> A(a);
  vector<ll> B(b);
  ll x,y,c;
  ll ans=1e9;
  ll mia=1e9;
  ll mib=1e9;
  for(int i=0;i<a;i++){cin>>A[i];mia=min(mia,A[i]);}
  for(int i=0;i<b;i++){cin>>B[i];mib=min(mib,B[i]);}
  for(int i=0;i<m;i++)
  {
      cin>>x>>y>>c;
      ll money=(A[x-1]+B[y-1])-c;
      ll f=0;
      money=max(money,f);
      //debug3(ans,money,i);
      if(ans>money)
        ans=money;
  }
  cout<<min(ans,mia+mib);
}
int main(){
    boost;
  solve();
}


Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <cstdio>
#include <algorithm>
#include <set>

using namespace std;

int hailist[14];
int shaicount[10];
int haicount[10];
set<int> ans;
bool dfs(int i);
void solve(int *hailist);

int main()
{
	while(1){
		int eof;
		fill(hailist,hailist+13,0);
		for(int i=0;i<13;i++){
			char temp;
			eof=scanf(" %c",&temp);
			if(eof==EOF)break;
			hailist[i]=(int)temp-'0'-1;
		}
		if(eof==EOF)break;
		ans.clear();
		solve(hailist);
		if(ans.empty())cout<<0<<"\n";
		else{
			set<int>::iterator it = ans.begin();
			for(int i=0;i<ans.size()-1;i++){cout<<*it<<" ";it++;}
			cout<<*it<<"\n";
		}
	}
	return 0;
}

void solve(int *hailist){
	for(int i=0;i<10;i++) shaicount[i]=0;
	shaicount[9]=1;//[vI¹Ì½ßÉ
	for(int i=0;i<13;i++) shaicount[hailist[i]]++;//²ÆÉvÌðJEg
	for(int i=0;i<9;i++){
		if(shaicount[i]==4)continue;
		for(int j=0;j<10;j++)haicount[j]=shaicount[j];
		haicount[i]++;//vðêÂ«·

		for(int j=0;j<9;j++){
			if(haicount[j]>=2){
				haicount[j]-=2;
				//for(int i=0;i<9;i++)cout<<haicount[i];
				//cout<<"\n";
				if(dfs(0)) {ans.insert(i+1);break;}
				haicount[j]+=2;
			}
		}
	}
	return;
}
bool dfs(int i){
	while(!haicount[i])i++;
	if(i==9)return true;
	if(haicount[i]>=3){
		haicount[i]-=3;//Ï»·éOÌóÔðÛ¶µÈ¢Æg¦È¢H
		if(dfs(i))return true;
		haicount[i]+=3;
	}
	if(i>=7)return false;
	if(haicount[i]&&haicount[i+1]&&haicount[i+2]){
		haicount[i]--;haicount[i+1]--;haicount[i+2]--;
		if(dfs(i))return true;
		haicount[i]++;haicount[i+1]++;haicount[i+2]++;
	}
	return false;
}

Measured memory_bytes: 0
//
// Created by yamunaku on 2019/11/05.
//

#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repl(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perl(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD9 998244353
#define MOD1 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)
#define CST(x) cout<<fixed<<setprecision(x)

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int>> mti;
typedef vector<ll> vl;
typedef vector<vector<ll>> mtl;

int main(){
    int n, m;
    cin >> n >> m;
    mti e(n);
    int u, v;
    rep(i, m){
        cin >> u >> v;
        e[u - 1].push_back(v - 1);
    }
    CST(10);
    double ans = LINF;
    vector<double> dp(n, 0);
    vector<pair<double, int>> ma(n);
    per(i, n - 1){
        for(auto &nx:e[i]){
            dp[i] += dp[nx];
            if(dp[nx] > ma[i].first){
                ma[i].first = dp[nx];
                ma[i].second = nx;
            }
        }
        dp[i] = dp[i] / e[i].size() + 1;
    }
    ans = min(ans, dp[0]);
    rep(t, n-1){
        dp = vector<double>(n, 0);
        per(i, n - 1){
            int count = 0;
            for(auto &nx:e[i]){
                if(i == t && nx == ma[i].second) continue;
                dp[i] += dp[nx];
                count++;
            }
            if(count == 0) goto next;
            dp[i] = dp[i] / count + 1;
        }
        ans = min(ans, dp[0]);
        next:;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
#include <stdio.h>
#include <numeric>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define repone(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define Rep(j,n) for(int j=0;j<(int)(n);++j)
#define Repo(j,o,n) for(int j=o;j<(int)(n);++j)
#define Repone(j,n) for(int j=1;j<(int)(n);++j)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define int long long
#define pb(a) push_back(a)
#define eraser(v,i) (v).erase(v.begin()+(i))
#define pbpair(a,b) push_back(make_pair(a,b))
#define MOD 1000000007
#define INF 9223372036854775807
#define pairint pair<int,int>
int num[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
bool uru(int checkyear){if(checkyear%4==0){if(checkyear%100!=0||checkyear%400==0)return true;}return false;}
int gcd( int x, int y ){return y ? gcd(y, x%y) : x;}
bool pairCompare(const pairint& firstElof, const pairint& secondElof)
{
  if(firstElof.second!= secondElof.second)    return firstElof.second> secondElof.second;
  else return firstElof.first< secondElof.first;
}
signed main() {
int x=0,y=0,z=0,w=0,n=0,m=0;
string v;
std::cin >> v;
rep(i,3){
  if(v[i]=='o')x+=100;
}
std::cout << x+700 << '\n';
}


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

using namespace std;

int main(){
    string s;
    cin>>s;
    int ans=0,bns=0;
    for(int i=0;i<s.size();i++){
        if(i%2==0){
            if(s.at(i)=='0') ans++;
            else bns++;
        }else{
            if(s.at(i)=='1') ans++;
            else bns++;
        }
    }
    
    cout<<min(ans,bns)<<endl;
    
    return 0;
}

Measured memory_bytes: 512
import sys
import math

def str_input():
    S = raw_input()
    if S[len(S)-1] == "\r":
        return S[:len(S)-1]
    return S

def float_to_str(num):
    return str("{:.10f}".format(num))

a, b, C = map(float, str_input().split())

h = b * math.sin(math.radians(C))
S = a * h / 2

dx = a - b * math.cos(math.radians(C))
dy = h

L = a + b + math.sqrt(dx*dx + dy*dy)

print float_to_str(S)
print float_to_str(L)
print float_to_str(h)

Measured memory_bytes: 6664
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <functional>
#include <string>
#include <stack>
#include <queue>
#include <map>

typedef long long ll;
ll mod = 1e9 + 7;
  
using namespace std;


int solve(string s, int l, int r)
{
    int cnt = 0;
    bool flag = false;
    while(l != r)
    {
        if(s.at(l) == 'C' && flag)
        {
            cnt++;
        }

        if(s.at(l) == 'A')
        {
            flag = true;
        }
        else
        {
            flag = false;
        }
        l++;
    }
    return cnt;
}

int main()
{
	int n, q;
	cin >> n >> q;
    vector <int> basyo(n+1, 0);
    bool flag = false;
    int cnt = 0;
    for(int i = 1; i < n+1; i++)
    {
        char c;
        cin >> c;

        if(c == 'C' && flag)
            cnt ++;
        
        if(c == 'A')
            flag = true;
        else
        {
            flag = false;
        }
        basyo[i] = cnt;
    }

    for(int i = 0; i < q; i++)
    {
        int l, r;
        cin >> l >> r;

        cout << basyo[r] - basyo[l] << endl;
    }

	return 0;
}

Measured memory_bytes: 1280