akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define oo 666666666

ll DP[3003][3003]; // [prefix size][last_element] - cnt of permutations of 1...i with last element j
ll pf[3003][3003]; // prefix sums to get n^2 from n^3
ll mod = 1e9+7;

int main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int n;
    string s; //given string is a sequence of '<' and '>', all permutations must satisfy those signs
    cin>>n>>s;
    s="  "+s;

    DP[1][1]=pf[1][1]=1; //well obviously only 1 way to make permutation of 1 element satisfying 0 signs

    for(int i=2; i<=n; i++)
        for(int j=1; j<=i; j++)
        {
                if(s[i]=='>')//if current element need to be less then last one
                {
                    //so last element should be greater than j,
                    //hence we can try all elements from range [j,i-1]
                    //why not [j+1,i]? cause after inserting element j all element >= j are increased by 1
                    //this lets us keep permutation correct
                    DP[i][j]+=pf[i-1][i-1]-pf[i-1][j-1];
                    DP[i][j]%=mod;
                    DP[i][j]=(DP[i][j]+mod)%mod;
                    //for(int k=j; k<=n; k++)
                    //DP[i][j]+=DP[i-1][k];
                }
                else//-> if current element need to be more then last one
                {
                    //so we know that last element was < j
                    //so we try all values for last elm in range [1,j-1]
                    //after inserting element j all element >= j are increased by 1
                    //this lets us keep permutation correct
                    DP[i][j]+=pf[i-1][j-1];
                    DP[i][j]%=mod;
                    //for(int k=j-1; k>=1; k--)
                    //DP[i][j]+=DP[i-1][k];
                }
            pf[i][j] = (pf[i][j-1] + DP[i][j])%mod;
        }

    ll ats = 0;
    for(int i=0; i<=n; i++)
        ats=(ats + DP[n][i])%mod;

    cout<<(ats+mod)%mod;
}


Measured memory_bytes: 139520
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <istream>
#define rep0(i,n) for (int i = 0; i <= (n); ++i)
#define rep1(i,n) for (int i = 1; i <= (n); ++i)
#define vec vector<int>a(n)
#define soot(a) sort(a.begin(),a.end())
/*int n;
cin >> n;
vector<int>a(n);
rep0(i, n - 1)cin >> a[i];*/
using namespace std;
int main() {
	int a, b;
	cin >> a >> b;
	if (a < b)
		cout << "a < b" << endl;
	else if (a > b)
		cout << "a > b" << endl;
	else
		cout << "a == b" << endl;
	return 0;
}


Measured memory_bytes: 3100
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <cstdio>
#include <numeric>
#include <queue>
#include <list>

using namespace std;
using ll=long long;

ll N;
string s;
ll cnt[200005];

int main()
{
  cin >> N >> s;
  ll ans = 0;
  ll l = 0;
  ll r = N-1;
  while(1)
  {
    while(s[l] != 'W')
    {
      l++;
      if(l >= N)break;
    }
    while(s[r] != 'R')
    {
      r--;
      if(r < 0)break;      
    }
    if(l < r)swap(s[l], s[r]);
    else break;
    ans++;
  }
  cout << ans << endl;

 return 0;
}

Measured memory_bytes: 3480
package main

import (
	"fmt"
)

func main() {
	var (
		a  int
		op string
		b  int
	)

	fmt.Scan(&a, &op, &b)

	if op == "+" {
		fmt.Println(a + b)
	} else if op == "-" {
		fmt.Println(a - b)
	}
}


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

using namespace std;

typedef long long ll;
#define sint(a) scanf("%d",&a)
#define sint2(a,b) scanf("%d %d",&a,&b)
#define sll(a) scanf("%lld",&a)
#define sll2(a,b) scanf("%lld %lld",&a,&b)
#define mem(a,i) memset(a,i,sizeof(a))
const int maxn=2e5+5;
typedef struct xx
{
    int to,ys;
};
vector <int>v[maxn];
xx a[maxn];
map<int,int>mp;
int xf[maxn];
void ys(int x,int b)
{
    int s=1;
    for(int i=0; i<v[x].size(); i++)
    {
        int k=v[x][i];
        if(xf[a[k].to])
        {
            if(s==b)
                s++;
            xf[a[k].to]=0;
            ys(a[k].to,s);
            a[k].ys=s++;
        }
    }
}
int main()
{
    mem(xf,1);
    int n;
    sint(n);
    for(int i=1; i<n; i++)
    {
        int l,r;
        sint2(l,r);
        a[i].to=r;
        v[l].push_back(i);
        mp[l]++;
        mp[r]++;
    }
    int Max=0;
    for(int i=1; i<=n; i++)
        if(mp[i]>Max)
            Max=mp[i];
   ys(1,0);
    printf("%d\n",Max);
    for(int i=1; i<n; i++)
        printf("%d\n",a[i].ys);
    return 0;
}


Measured memory_bytes: 15744
#include <stdio.h>
#define MAX 10000

struct node{
  int p, l, r;
};
struct node T[MAX];
int n;

//???????????????
void pre(int u){
  if(u == -1) return;
  printf(" %d", u);
  pre(T[u].l);
  pre(T[u].r);
}

//???????????????
void ino(int u){
  if(u == -1) return;
  ino(T[u].l);
  printf(" %d", u);
  ino(T[u].r);
}

//???????????????
void pos(int u){
  if(u == -1) return;
  pos(T[u].l);
  pos(T[u].r);
  printf(" %d", u);
}

int main(){
  int i, v, l, r, root;

  scanf("%d", &n);
  for(i = 0; i < n; i++) T[i].p = -1;

  for(i = 0; i < n; i++){
    scanf("%d %d %d", &v, &l, &r);
    T[v].l = l;
    T[v].r = r;
    if(l != -1) T[l].p = v;
    if(r != -1) T[r].p = v;
  }

  for(i = 0; i < n; i++)
    if(T[i].p == -1) root = i;
  printf("Preorder\n");
  pre(root);
  printf("\n");
  printf("Inorder\n");
  ino(root);
  printf("\n");
  printf("Postorder\n");
  pos(root);
  printf("\n");

  return 0;
}

Measured memory_bytes: 620
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0;i<(int)(n);i++)
#define all(x)    (x).begin(),(x).end()
typedef long long ll;
const int MOD = (int)1e9 + 7;

int main(){
  int k;
  string s;
  cin >> k;
  cin >> s;
  if (s.length() <= k){
    cout << s << endl;
    return 0;
  }
  rep(i,k) cout << s[i];
  cout << "..." <<endl;
}



Measured memory_bytes: 3624
import collections
import sys

input = sys.stdin.readline

ri = lambda: int(input())
rs = lambda: input().rstrip()
ril = lambda: list(map(int, input().split()))
rsl = lambda: input().rstrip().split()
ris = lambda n: [ri() for _ in range(n)]
rss = lambda n: [rs() for _ in range(n)]
rils = lambda n: [ril() for _ in range(n)]
rsls = lambda n: [rsl() for _ in range(n)]


class Combinations:
    def __init__(self, max_num, mod):
        self.mod = mod
        self.factorials = [1]
        for i in range(1, max_num + 1):
            self.factorials.append((self.factorials[-1] * i) % mod)
        self.invs = [pow(self.factorials[-1], mod - 2, mod)]
        for i in reversed(range(1, max_num + 1)):
            self.invs.append(self.invs[-1] * i % mod)
        self.invs = self.invs[::-1]

    def __call__(self, n, k):
        if n < 0 or k < 0 or k > n:
            return 0
        return self.factorials[n] * self.invs[k] * self.invs[n - k] % self.mod


MOD = 10**9 + 7

n = ri()
ls = ril()
counter = collections.Counter(ls)
d = counter.most_common()[0][0]
l, r = [i for i in range(n + 1) if ls[i] == d]

combinations = Combinations(n + 1, MOD)
for k in range(1, n + 2):
    res = combinations(n + 1, k) - combinations(l + n - r, k - 1)
    res += MOD
    res %= MOD
    print(res)

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

int main()
{
  int a;
  int b;
  int c;
  int d;
  int e;
  int f;
  int g;
  
  cin >> a;
  cin >> b;
  cin >> c;
  
  d = a + b;
  e = a + c;
  f = b + c;
  
  if(d <= e && d <= f){
    cout<<d<<endl;
  }else if(e <= d && e <= f){
    cout<<e<<endl;
  }else{
    cout<<f<<endl;
  }
}




Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<iomanip>
#include<map>
#include<utility>
#include<string>
#include<unordered_map>
#include<queue>

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

using namespace std;

#define min_3(a, b, c) min(a, min(b, c))
#define max_3(a, b, c) max(a, max(b, c))
typedef long long ll;
typedef pair<int, int> P;
const ll INF = ll(1e18)+1;

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


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


int ans(string buf){
	set<string> pa;
	pa.clear();
	string str1,str2;//str1:ツ湘」 str:ツ可コ
	for(int i=1;i-1<buf.size()-1;i++){
		str1=string(buf,0,i);
		str2=string(buf,i,buf.size()-i);

		string str1_reverse=str1;
		string str2_reverse=str2;
		reverse(str1_reverse.begin(),str1_reverse.end());
		reverse(str2_reverse.begin(),str2_reverse.end());
		string ins=str1+str2;
		pa.insert(ins);

		ins=str2+str1;
		pa.insert(ins);

		ins=str1_reverse+str2;
		pa.insert(ins);

		ins=str2+str1_reverse;
		pa.insert(ins);
		
		ins=str2_reverse+str1;
		pa.insert(ins);

		ins=str1+str2_reverse;
		pa.insert(ins);

		ins=str1_reverse+str2_reverse;
		pa.insert(ins);

		ins=str2_reverse+str1_reverse;
		pa.insert(ins);
		
	}
	return pa.size();
}

int main(){
	int d;
	string buf;
	cin>>d;
	for(int i=0;i<d;i++){
		cin>>buf;	
		cout<<ans(buf)<<endl;
	}
	return 0;
}

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

using Int = long long int;
using std::vector;

Int gcd(Int a, Int b) {
    while (b > 0) {
        a %= b;
        std::swap(a, b);
    }
    return a;
}

void fail() {
    std::cout << -1 << std::endl;
    std::exit(0);
}

int main() {
    int n;
    std::cin >> n;
    vector<int> p(n), q(n);
    for (auto& x : p) {
        std::cin >> x;
        --x;
    }
    for (auto& x : q) {
        std::cin >> x;
        --x;
    }

    Int a = 1, b = 0;
    // d = ax + b で揃う
    for (int i = 0; i < n; ++i) {
        int v = p[i];
        Int aa = -1, bb = -1;
        for (int t = 1; t <= n; ++t) {
            v = q[v];
            if (v == i) {
                bb = t;
            }
            if (v == p[i]) {
                aa = t;
                break;
            }
        }
        if (bb < 0) fail();
        bb %= aa;

        // d = ax + b = aay + bb
        // 0 <= x < aa で十分
        Int x;
        for (x = 0; x < aa; ++x) {
            if ((a * x + b) % aa == bb) break;
        }
        if (x == aa) fail();

        b += a * x;
        a = a / gcd(a, aa) * aa;
        b %= a;
    }

    std::cout << b << std::endl;
    return 0;
}



Measured memory_bytes: 3128
#include<bits/stdc++.h>
using namespace std;
int n,x[10],y[10];
int main()
{
	cin >> n;
	double k=1;
	for(int i=1; i<=n; i++) cin >> x[i] >> y[i];
	double ans=0;
	for(int i=1; i<=n; i++)
		for(int j=1; j<=n; j++)
			ans+=(sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j])));
	printf("%.10lf",ans/n);
	return 0;
}

Measured memory_bytes: 3708
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <complex>
#include <string.h>
#include <numeric>
using namespace std;

//#define int long long
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define rept(i,n) rep(i,(n)+1)
#define repst(i,s,n) reps(i,s,(n)+1)
#define reprt(i,n,t) for(int (i)=(n);(i)>=(t);--(i))
#define repr(i,n) reprt(i,n,0)
#define each(i,v) for(auto &(i):(v))
#define eachr(i,v) for(auto &(i)=(v).rbegin();(i)!=(v).rend();(i)++)
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define tmax(x,y,z) max(x,max(y,z))
#define tmin(x,y,z) min(x,min(y,z))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln '\n'
#define bln(i,n) (((i)==(n)-1)?'\n':' ')
#define dbg(x) cout<<#x" = "<<(x)<<ln<<flush
#define dbga(x,n) {cout<<#x" : ";for(int (i)=0;i<(n);++i){cout<<((x)[i])<<(i==((n)-1)?'\n':' ')<<flush;}}
#define zero(a) memset(a,0,sizeof(a))
#define unq(a) sort(all(a)),a.erase(unique(all(a)),a.end())
#define endl "\n"

//typedef complex<double> P;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vst;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > mat;

const ll inf = (ll)1e9+10;
const ll linf = (ll)1e18+10;
const ll mod = (ll)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double eps = 1e-10;

ll mop(ll a,ll b,ll m=mod) {ll r=1;a%=m;for(;b;b>>=1){if(b&1)r=r*a%m;a=a*a%m;}return r;}
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b) {return a/gcd(a,b)*b;}
bool ool(int x,int y,int h,int w) {return((x<0)||(h<=x)||(y<0)||(w<=y));}
bool deq(double a,double b) {return abs(a-b)<eps;}

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;



// i番目が左端にはみ出すならその左にいるゴーレムも全部左端にはみ出す 右も同様
// ニブタン2回

int n, q, l, r, le, ri;
string s;
char t[200200], d[200200];

bool outl(int x) {
	int id = x;
	rep(i,q) if (s[id]==t[i]) {
		if (d[i]=='L') id--;
		else id++;
		if (id<0) return 1;
		if (id>=n) return 0;
	}
	return 0;
}

bool outr(int x) {
	int id = x;
	rep(i,q) if (s[id]==t[i]) {
		if (d[i]=='L') id--;
		else id++;
		if (id<0) return 0;
		if (id>=n) return 1;
	}
	return 0;
}

signed main() {
	cin >> n >> q >> s;
	rep(i,q) cin >> t[i] >> d[i];

	// left
	l = -1, r = n;
	while (r-l>1) {
		int m = (l+r)/2;
		(outl(m) ? l : r) = m;
	}
	le = l;
	// right
	l = -1, r = n;
	while (r-l>1) {
		int m = (l+r)/2;
		(outr(m) ? r : l) = m;
	}
	ri = r;
	cout << n - (le+1 + n-ri) << endl;
}

Measured memory_bytes: 976
import itertools
import math
import sys
import heapq
from collections import Counter
from collections import deque
from fractions import gcd
from functools import reduce
sys.setrecursionlimit(4100000)
from functools import lru_cache
INF = 1 << 60

#ここから書き始める
s = input()
t = input()
index = INF
for i in reversed(range(len(s) - len(t) + 1)):
    flag = True
    for j in range(i, i + len(t)):
        if s[j] != "?" and s[j] != t[j - i]:
            flag = False
    if flag:
        index = i
        break
    if flag:
        break
if index == INF:
    print("UNRESTORABLE")
else:
    s = s[:index] + t + s[index + len(t):]
    s = s.replace("?", "a")
    print(s)


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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<string> vs;
typedef pair<int, int> P;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

void YN(bool flg){if(flg) cout << "YES" << endl; else cout << "NO" << endl;}
void Yn(bool flg){if(flg) cout << "Yes" << endl; else cout << "No" << endl;}
void yn(bool flg){if(flg) cout << "yes" << endl; else cout << "no" << endl;}

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

int main()
{   
    int n;
    string s;
    cin >> n >> s;
    int a = 0, b = 0;
    rep(i, n) if(s[i]=='R') a++;
    int ans = a;
    int i = 0;
    rep(i,n) {
        if(s[i]=='R') a--;
        else b++;
        int now = max(a, b);
        ans = min(ans, now);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3768
#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio (false);
 // ios_base::sync_With_stdio (false);
    cin.tie(NULL);
    cout.tie(NULL);
    string a,b;
    cin>>a>>b;
    int la=a.length();
    int lb=b.length();
    int dp[la+1][lb+1];
    string str="";
     for(int i=0;i<=la;i++)
    {
        for(int j=0;j<=lb;j++)
        {
            dp[i][j]=0;
          //  cout<<dp[i][j]<<" ";
        }
       // cout<<"\n";
    }
    for(int i=0;i<=la;i++)
    {
        for(int j=0;j<=lb;j++)
        {
            if(i==0||j==0)
            dp[i][j]=0;
            
            else
            if(a[i-1]==b[j-1])
           { dp[i][j]=dp[i-1][j-1]+1;}
          // str+=a[i-1];}
           
            else
            dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
        }
    } 
  /* int i=a.length();
   int j=b.length();
   while(i>0&&j>0)
   {
       if(dp[i][j]==dp[i-1][j-1])
       {
           str+=a[i-1];i--;
           j--;
       }
       if(dp[i-1][j]==dp[i][j])
       {
           i--;
       }
       if(dp[i][j-1]==dp[i][j])
       {
           j--;
       }
   }*/
   int i=a.length();
   int j=b.length();
   
   while(i > 0 && j > 0) {
    if (dp[i][j] == dp[i - 1][j]) --i;
    else if(dp[i][j] == dp[i][j - 1]) --j;
    else {
      str = a[i - 1] + str;
      --i;
      --j;
    }
  }
    /*for(int i=0;i<=la;i++)
    {
        for(int j=0;j<=lb;j++)
        {
           // dp[i][j]=0;
            cout<<dp[i][j]<<" ";
        }
        cout<<"\n";
    }
   */
// cout<<dp[la][lb]<<" \n";
    cout<<str<<"\n";
    
    
}

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

int main () {
  string s;
  cin >> s;
  
  int remainder = 1000;
  
  for (int i = 0; i < s.size() - 2; i++) {
    int digit100 = s.at(i) - '0';
    int digit10 = s.at(i + 1) - '0';
    int digit1 = s.at(i + 2) - '0';
    
    int n = digit100 * 100 + digit10 * 10 + digit1;
    
    if (n > 753) {
      if (n - 753 < remainder) remainder = n - 753;
    } else {
      if (753 - n < remainder) remainder = 753 - n;
    }
  }
  
  cout << remainder << endl;
  
  return 0;
}
   

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<string>
#include<algorithm>
#include<math.h>
#include<vector>
#include<map>
using namespace std;
#define INF 999999999
#define lint long long
#define rep(i, n) for(int i = 1; i <= (int)(n); i++)
int gcd(int a,int b){return b?gcd(b,a%b):a;}
#define P pair<lint, lint>


int main(){
    string S;
    cin >> S;
    int tmp=0, ans=0;
    for(int i=0; i<S.length();++i){
        if(S[i] == 'A'||S[i] == 'T'||S[i] == 'C'||S[i] == 'G'){
            ++tmp;
            if(ans<tmp) ans=tmp;
        }
        else{
            tmp=0;
        }
    }
    cout << ans;
    return 0;
}

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

using namespace std;

int main() {
    string tiles;
    cin >> tiles;
    int ans = tiles.size();

    for(int i = 0;i < 2; i++) {
        int cnt = 0;
        for(int j = 0; j < tiles.size(); j++) {
            if(j%2==0 && tiles[j] != (char)(i + '0')) cnt++;
            if(j%2==1 && tiles[j] == (char)(i + '0')) cnt++;
        }
        ans = min(ans, cnt);
    }

    cout << ans << endl;
}

Measured memory_bytes: 512
import java.util.Scanner;

public class Main {
    public static void main(String args[]) throws Exception {
        Scanner s = new Scanner(System.in);
        String n = s.next();
        n = n.replaceAll("eraser", "");
        n = n.replaceAll("erase", "");
        n = n.replaceAll("dreamer", "");
        n = n.replaceAll("dream", "");
        
        System.out.println(n.length() == 0 ? "YES": "NO");

    }
}


Measured memory_bytes: 30508
#include <bits/stdc++.h>
#define N 200006
#define mo 1000000009
using namespace std;
bool f[30*N];char c[N];
int n,m,cs,nowl,nowr,sum,s[30*N],t[30*N],p[N];
inline int read()
{
	int x=0,c=getchar();while(c<48)c=getchar();
	while(c>47)x=x*10+c-48,c=getchar();return x;
}
void down(int i,int l,int r)
{
	if(f[i]){
		f[i]=0;swap(s[i],t[i]);
		if(l!=r)f[i<<1]^=1,f[i<<1|1]^=1;
	}
}
void change(int i,int l,int r,int x,int y)
{
	down(i,l,r);if(l==r){s[i]=y;t[i]=s[i]^1;return;}
	int mid=(l+r)>>1;
	if(x<=mid)change(i<<1,l,mid,x,y);
	else change(i<<1|1,mid+1,r,x,y);
	down(i<<1,l,mid);down(i<<1|1,mid+1,r);
	s[i]=(1LL*s[i<<1]*p[r-mid]+1LL*s[i<<1|1])%mo;
	t[i]=(1LL*t[i<<1]*p[r-mid]+1LL*t[i<<1|1])%mo;
}
int query(int i,int l,int r,int x,int y)
{
	down(i,l,r);if(x<=l&&r<=y)return s[i];
	int mid=(l+r)>>1;
	if(y<=mid)return query(i<<1,l,mid,x,y);
	if(x>mid)return query(i<<1|1,mid+1,r,x,y);
	int a=query(i<<1,l,mid,x,y),b=query(i<<1|1,mid+1,r,x,y);
	return (1LL*a*p[min(y,r)-mid]+1LL*b)%mo;
}
void rev(int i,int l,int r,int x,int y)
{
	down(i,l,r);if(x<=l&&r<=y){f[i]^=1;return;}
	int mid=(l+r)>>1;
	if(x<=mid)rev(i<<1,l,mid,x,y);
	if(y>mid)rev(i<<1|1,mid+1,r,x,y);
	down(i<<1,l,mid);down(i<<1|1,mid+1,r);
	s[i]=(1LL*s[i<<1]*p[r-mid]+1LL*s[i<<1|1])%mo;
	t[i]=(1LL*t[i<<1]*p[r-mid]+1LL*t[i<<1|1])%mo;
}
int main()
{
	n=read();m=read();scanf("%s",c+1);
	nowl=1;nowr=n;p[0]=1;
	for(int i=1;i<=n;i++)change(1,1,3*n,i,c[i]-65);
	for(int i=1;i<=n;i++)p[i]=p[i-1]*2%mo;
	if(n&1){
		for(int i=1;i<=n;i++)
			if(i&1)sum=sum*2%mo;else sum=(sum*2+1)%mo;
		while(1){
			if(query(1,1,3*n,nowl,nowr)==sum)break;
			if(query(1,1,3*n,nowl,nowl)==0)change(1,1,3*n,nowl,1);
			else{
				nowl++;nowr++;
				rev(1,1,3*n,nowl,nowr-1);change(1,1,3*n,nowr,0);
			}
			cs++;if(cs==m){for(int i=nowl;i<=nowr;i++)putchar(query(1,1,3*n,i,i)+65);return 0;}
		}
		if((m-cs)&1)putchar('B');else putchar('A');
		for(int i=2;i<=n;i++)if(i&1)putchar('A');else putchar('B');
	}else{
		for(int i=1;i<=n;i++)
			if(i&1)sum=(sum*2+1)%mo;else sum=sum*2%mo;
		while(1){
			if(query(1,1,3*n,nowl,nowr)==sum)break;
			if(query(1,1,3*n,nowl,nowl)==0)change(1,1,3*n,nowl,1);
			else{
				nowl++;nowr++;
				rev(1,1,3*n,nowl,nowr-1);change(1,1,3*n,nowr,0);
			}
			cs++;if(cs==m){for(int i=nowl;i<=nowr;i++)putchar(query(1,1,3*n,i,i)+65);return 0;}
		}
		for(int i=1;i<=n;i++)if(i&1)putchar('B');else putchar('A');
	}
}

Measured memory_bytes: 22656
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int d = sc.nextInt();
        double num = d * 2 + 1;
        System.out.println((int)Math.ceil(n / num));
    }
}

Measured memory_bytes: 22996
#include <bits/stdc++.h>
#include <math.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1001001001;
const int mINF = -1001001001;


int main() {
int n,m,x,y;
cin >> n >> m >> x >> y;
int xn[n],ym[m];
int x_max=mINF,y_min=INF;
REP(i,n) {
  cin >> xn[i];
  x_max = max(x_max,xn[i]);
}
REP(i,m) {
  cin >> ym[i];
  y_min = min(y_min,ym[i]);
}
int flg=-1;
if(x_max<y_min) {
  for(int i=x_max+1;i<=y_min;i++) {
    if(x<i&&i<=y) flg++;
  }
}
if(flg!=-1){cout << "No War" << endl;}else{
cout << "War" << endl;}

return 0;
}


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

int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	string sh, sh1;
	cin >> sh >> sh1;
	long long int ans = 0;
	for (int i = 0; i < 3; ++i)
	{
		if (sh[i] == sh1[i])
		{
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3624
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse2")

#include<bits/stdc++.h>
#include <algorithm>
#include <bitset>
#include <complex>
#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>
using namespace std;

#define int         long long
#define ll          long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define mp          make_pair
#define all(a)      (a).begin(),(a).end()
#define FF           first
#define SS           second
#define sz(x)       (int)x.size()
#define endl        '\n'
//#define hell          1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
// mp::cpp_int
#define pp pair<pii,pii>
const int hell =1000000007;




int solve( ){

int n;
cin>>n;
vi a(n);
rep(i,0,n)cin>>a[i];

int dp[n];
//rep(i,0,n)dp[i]=1e9+5;
dp[0]=0;
rep(i,1,n)
{  
   if(i>1)
  dp[i]=min(dp[i-2]+abs(a[i]-a[i-2]),dp[i-1]+abs(a[i]-a[i-1]));
   else dp[i]=abs(a[i]-a[i-1]);
}
cout<<dp[n-1];



return 0;
}

signed main()
{  int t=1;
 ios::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);
   cin.exceptions(cin.failbit);

  

  clock_t time_req;

    // Without using pow function
    time_req = clock();
    
//cin>>t;

    int k=1;
   while(t--)
     {
       //cout<<"case #"<<k<<":"<<" ";k++;
      solve();
     }

         time_req = clock() - time_req;
 //cout << "Processor time taken is "
   // << (double)time_req/CLOCKS_PER_SEC << " seconds" << endl;


    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
template <typename T> using V = vector<T>;
template <typename T> using VV = V<V<T>>;
using PLL = pair<ll, ll>;

template <typename T>
T make_v(T init) { return init; }

template <typename T, typename... Tail>
auto make_v(T init, size_t s, Tail... tail) {
#define rec make_v(init, tail...)
    return V<decltype(rec)>(s, rec);
#undef rec
}

PLL invalid = PLL(-1, -1);
ll sum_all;
ll bound;
VV<VV<PLL>> dp;
VV<ll> sum;
ll H, W, S;

ll calc_group_sum(ll h1, ll w1, ll h2, ll w2) {
    return sum[h2][w2] - sum[h1][w2] - sum[h2][w1] + sum[h1][w1];
}

bool enable_split(ll h1, ll w1, ll h2, ll w2, bool h, ll sp) {
    if(h) {
        return calc_group_sum(h1, w1, sp, w2) >= bound &&
               calc_group_sum(sp, w1, h2, w2) >= bound;
    } else {
        return calc_group_sum(h1, w1, h2, sp) >= bound &&
               calc_group_sum(h1, sp, h2, w2) >= bound;
    }
}

PLL calc(ll h1, ll w1, ll h2, ll w2) {
    if(dp[h1][w1][h2][w2] != invalid) return dp[h1][w1][h2][w2];

    PLL ret = PLL(1, calc_group_sum(h1, w1, h2, w2));
    
    for(ll sh = h1 + 1; sh < h2; sh++) {
        if(!enable_split(h1, w1, h2, w2, true, sh)) continue;
        auto hu = calc(h1, w1, sh, w2);
        auto hd = calc(sh, w1, h2, w2);
        auto tmp = make_pair(hu.first + hd.first,
                             min(hu.second, hd.second));
        if(tmp.first > ret.first) ret = tmp;
        else if(tmp.first == ret.first && tmp.second > ret.second) ret = tmp;
    }
    
    for(ll sw = w1 + 1; sw < w2; sw++) {
        if(!enable_split(h1, w1, h2, w2, false, sw)) continue;
        auto hl = calc(h1, w1, h2, sw);
        auto hr = calc(h1, sw, h2, w2);
        auto tmp = make_pair(hl.first + hr.first,
                             min(hl.second, hr.second));
        if(tmp.first > ret.first) ret = tmp;
        else if(tmp.first == ret.first && tmp.second > ret.second) ret = tmp;
    }
    
    return dp[h1][w1][h2][w2] = ret;
}

bool solve() {
    cin >> H >> W >> S;

    if(!(H + W + S)) return false;

    dp = make_v(invalid, 33, 33, 33, 33);
    sum = make_v<ll>(0, 33, 33);
    
    for(ll h = 0; h < H; h++) for(ll w = 0; w < W; w++) cin >> sum[h + 1][w + 1];
    for(ll h = 0; h < H; h++) for(ll w = 0; w <= W; w++) sum[h + 1][w] += sum[h][w];
    for(ll w = 0; w < W; w++) for(ll h = 0; h <= H; h++) sum[h][w + 1] += sum[h][w];

    sum_all = calc_group_sum(0, 0, H, W);
    bound = sum_all - S;

    auto ans = calc(0, 0, H, W);
    
    cout << ans.first << ' ' << S - (sum_all - ans.second) << endl;
    return true;
}

int main() {
    while(solve());
    return 0;
}



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

int main(){
  long long int   N;
  string S;
  cin >> N;
  vector<long long int> A(N);
  for(long long int i = 0; i < N; i++) cin >> A[i];
  
  for(long long int i = 0; i < N; i++){
    if(A[i] == 0){
      cout << 0 << endl;
      return 0;
    }
  }
  
  long long int prod = 1;
  for(long long int i = 0; i < N; i++){
    if(A[i] <= 1000000000000000000 / prod) prod *= A[i];
    else {
      cout << -1 << endl;
      return 0;
    }
  }
  
  cout << prod << endl;
  
}


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

using namespace std;

typedef long double ld;
typedef long long ll;

const int M = 10;

int n = 6;
ld p[M], q[M];
vector<ld> a;

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

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

ld fun(ld x) {
  ld ans = 0;
  for (int i = 0; i < n; ++i)
    ans += max<ld>(0, x * (p[i] + q[i]) - q[i]);
  ans += 1 - x;
  return ans;
}

void kill() {
  a.push_back(0);
  a.push_back(1);
  for (int i = 0; i < n; ++i)
    if (p[i] + q[i] > 0)
      a.push_back(q[i] / (p[i] + q[i]));

  ld ans = 1;
  for (ld x : a) {
    //cerr << x << " " << fun(x) << endl;
    ans = min(ans, fun(x));
  }

  cout << ans << endl;
}

int main() {
#ifdef LOCAL
  assert(freopen("d.in", "r", stdin));
#endif

  ios_base::sync_with_stdio(false);
  cout.precision(13);
  cout << fixed;

  read();
  kill();

}



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

using namespace std;


void solve() {
    int R,C;
    cin >> R >> C;
    auto on_board = [&](int x, int y){
        return x==0 || x==R || y==0 || y==C;
    };
    auto to_line = [&](int x, int y){
        if (y==0) return x;
        if (x==R) return R+y;
        if (y==C) return R+C+R-x;
        assert(x==0);
        return R+C+R+C-y;
    };
    vector<pair<int, int>> a;
    int n; cin >> n;
    for (int _ = 0; _ < n; _++) {
        int x,y,u,v;
        cin >> x >> y >> u >> v;
        if (on_board(x,y) && on_board(u,v)) {
            int i = to_line(x,y);
            int j = to_line(u,v);
            if (i>j) swap(i,j);
            a.emplace_back(i, _);
            a.emplace_back(j, _);
        }
    }
    sort(a.begin(), a.end());
    vector<int> stk;
    for (auto& p: a) {
        if (stk.empty() || stk.back()!=p.second) {
            stk.emplace_back(p.second);
        } else {
            stk.pop_back();
        }
    }
    cout << (stk.empty()?"YES":"NO");
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    cout << endl;
}


Measured memory_bytes: 2672
K, N = list(map(int, input().split()))
A = list(map(int, input().split()))

A.sort()

dist = []

for i in range(N):
    if i != N - 1:
        dist.append(A[i+1]-A[i])
    else:
        dist.append(A[0] + K - A[i])

print(K - max(dist))

Measured memory_bytes: 32280
#define _CRT_SECURE_NO_WARNINGS
#define _SCL_SECURE_NO_WARNINGS
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <functional>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
#include <sstream>
#include <numeric>
#include <list>
#include <bitset>
#include <fstream>

using namespace std;
#define REP(i,a,n) for(int i = (a); i < (int)(n); ++i)
#define REM(i,a,n) for(int i = ((n) - 1); i >= (a); --i)
#define EPS 1e-11
#define INF 0x3FFFFFFF
#define INFLL 0x3FFFFFFF3FFFFFFF
#define INFD 1.0e+308
#define FLOAT setprecision(16)
const double PI = 3.1415926535897932;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<LL, LL> PP;

template <class T, class U>
istream& operator>>(istream& ist, pair<T, U>& right) { return ist >> right.first >> right.second; }
template <class T, class U>
ostream& operator<<(ostream& ost, pair<T, U>& right) { return ost << right.first << ' ' << right.second; }
template <class T, class TCompatible, size_t N>
void Fill(T(&dest)[N], const TCompatible& val) { fill(begin(dest), end(dest), val); }
template <class T, class TCompatible, size_t M, size_t N>
void Fill(T(&dest)[M][N], const TCompatible& val) { for (int i = 0; i < M; ++i) Fill(dest[i], val); }
//sum, 累積和
// 負のときの割り算に注意
#if 0
#include <array>
#include <unordered_set>
#include <unordered_map>
template<class T>
using PriorityQ = priority_queue<T, vector<T>, greater<T> >;	// コスト小を優先
#endif

//#ifdef _DEBUG
//#include "IntMod.h"
//#include "Union_Find.h"
//#include "Graph.h"
//#include "Suffix_Array.h"
//#include "Matrix.h"
//#endif

#ifdef __GNUC__
typedef __int128 LLL;
istream& operator>> (istream& ist, __int128& val) { LL tmp;  ist >> tmp; val = tmp; return ist; }
ostream& operator<< (ostream& ost, __int128 val) { LL tmp = val; ost << tmp; return ost; }
#endif

string N;
int main() {
	cin >> N;
	int a = N[0] - '0';
	int b = N[1] - '0';
	int c = N[2] - '0';
	int d = N[3] - '0';
	
	REP(i, 0, 8) {
		bool p = i & 4;
		bool q = i & 2;
		bool r = i & 1;
		if (a
			+ b * (p ? -1 : 1)
			+ c * (q ? -1 : 1)
			+ d * (r ? -1 : 1) == 7) {
			cout << a
				<< (p ? '-' : '+') << b
				<< (q ? '-' : '+') << c
				<< (r ? '-' : '+') << d << "=7" << endl;
			break;
		}
	}
	return 0;
}


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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define lcm(a, b) (a)/__gcd((a),(b))*(b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair<int, int> P;
typedef pair<LL, LL> LP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 200005;

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

vector<int> Div(int n) {
    vector<int> ret;
    for(int i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);

            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

const int match[] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
string str[] = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"};

string dp[10][10005];

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

    int n, m;
    cin >> n >> m;
    vector<int> v(m);
    for(int i = 0; i < m; ++i) {
        cin >> v[i];

    }
    sort(all(v), greater<int>());

    for(int i = 0; i < m; ++i) {
        int mvi = match[v[i]];
        for(int j = 1; j <= n; ++j) {
            if(i == 0) {
                if(j % mvi == 0) {
                    dp[i][j] = dp[i][j - mvi];
                    dp[i][j] += str[v[i]];

                }
            } else {
                string s1 = dp[i - 1][j];
                string s2;
                if(j % mvi == 0 || (j >= mvi && dp[i][j - mvi].size() != 0)) {
                    s2 = dp[i][j - mvi];
                    s2 += str[v[i]];

                }
                if(s1 == s2 && s1.size() == 0) {
                    continue;

                }
                if(s2.size() == 0) dp[i][j] = s1;
                else {
                    if(s1.size() < s2.size()) {
                        dp[i][j] = s2;

                    } else if(s1.size() > s2.size()){
                        dp[i][j] = s1;

                    } else {
                        if(s1 < s2) {
                            dp[i][j] = s2;

                        } else {
                            dp[i][j] = s1;

                        }
                    }
                }
            }
        }
    }
    cout << dp[m - 1][n] << endl;
    return 0;
}



Measured memory_bytes: 99840
N = int(input())
S = input()
ans = 0
T = {'R', 'G', 'B'}
sum_R, sum_G, sum_B = [0], [0], [0]
 
for i in S:
    sum_R.append(i=='R')
    sum_G.append(i=='G')
    sum_B.append(i=='B')
    
for i in range(1, N+1):
    sum_R[i] = sum_R[i-1] + sum_R[i]
    sum_G[i] = sum_G[i-1] + sum_G[i]
    sum_B[i] = sum_B[i-1] + sum_B[i]
    
dict_RGB = {'R':sum_R, 'G':sum_G, 'B':sum_B}
 
for i in range(N-2):
    s_i = S[i]
    for j in range(i+1, N-1):
        s_j = S[j]
        if s_i == s_j:
            continue
        
        s_k = list(T - set((s_i, s_j)))[0]
        
        sum_s_k = dict_RGB[s_k]
        ans = ans + sum_s_k[-1] - sum_s_k[j]
        if (2 * j - i < N) and (S[2*j - i]==s_k):
            ans -= 1
        
    
print(ans)

Measured memory_bytes: 69388
//iejr Header files
#include <stdio.h>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <stdlib.h>
#include <string>
#include <cstring>
#include <sstream>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <limits.h>
#include <ctime>
#include <cctype>
#include <functional>
#include <utility>
#include <numeric>

using namespace std;

//iejr: Type defination
typedef unsigned long long int             ULLN;
typedef long long int                      LLN;
typedef vector<int>                        VI;
typedef vector<vector<int> >               VVI;
typedef vector<string>                     VS;
typedef vector<vector<string> >            VVS;


//iejr: Compile Options
//#define C11_Standard
//
#ifdef C11_Standard
    #include <unordered_set>
    #include <unordered_map>

    #define HASHSET                  unordered_set
    #define HASHMAP                  unordered_map
#endif // C11_Standard


//iejr: Local Debug
//#define INPUT_REDIRECTION
//#define OUTPUT_REDIRECTION



//iejr: Main Function
int main()
{

#ifdef INPUT_REDIRECTION
    freopen( "in.txt", "r", stdin );
#endif // INPUT_REDIRECTION

#ifdef OUTPUT_REDIRECTION
    freopen( "out.txt", "w", stdout );
#endif // OUTPUT_REDIRECTION

    string sOrg = "CODEFESTIVAL2016";

    string sinput = "";
    while( cin >> sinput ){
        int cnt = 0;
        for( int i = 0;i < sOrg.length();++i ){
            cnt += sOrg[i] != sinput[i];
        }

        cout << cnt << endl;
    }

#ifdef INPUT_REDIRECTION
    fclose( stdin );
#endif // INPUT_REDIRECTION

#ifdef OUTPUT_REDIRECTION
    fclose( stdout );
#endif // OUTPUT_REDIRECTION

    return 0;
}

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

int main() {
  ll n;
  cin >> n;
  vl a(n);
  rep(i,n) cin >> a[i];
  ll ans = 0;
  rep(i,n-1) {
    if (a[i] > a[i+1]) {
      ans += a[i] - a[i+1];
      a[i+1] = a[i];
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 4828
# Aizu Problem 0045: Sum and Average
#
import sys, math, os

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input.txt", "rt")


revenue, total, N = 0, 0, 0
for line in sys.stdin:
    a, b = [int(_) for _ in line.split(',')]
    revenue += a * b
    total += b
    N += 1

print(revenue)
print(math.ceil(total/N))

Measured memory_bytes: 7812
#include<bits/stdc++.h>
using namespace std;
#define inf 1e9+5

int main()
{
    int n;  cin>>n;
    vector<int> dp(3);
    vector<int> a(3);
    for(int day = 0 ; day<n ; day++)
    {
        for(int &i:a)    cin>>i;
        vector<int> newdp(3);
        for(int i=0 ; i<3 ; i++)
        {
            for(int j=0 ; j<3 ; j++)
            {
                if(i!=j)
                    newdp[j] = max(a[j]+dp[i] , newdp[j]);
            }
        }
        dp = newdp;
    }
    int ans = INT_MIN;
    for(int i:dp)        ans = max(ans,i);
    cout<<ans;
}



Measured memory_bytes: 256
// D - joisino's travel
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
#define rp(i,s,e) for(int i=(s);i<(e);++i)
#define rpz(i,e) rp(i,0,e)
#define all(x) (x).begin(),(x).end()
#define DIST_MAX 1000000000
#define N_MAX 200
#define R_MAX 8

void warshall_floyd(vvi &D){
	rp(relay,1,D.size()) rp(from,1,D.size()) rp(to,1,D.size())
		D[from][to] = min(D[from][to], D[from][relay] + D[relay][to]);
}

int N,M,R;
vi RR(R_MAX+1);
vvi D(N_MAX+1, vi(N_MAX+1, DIST_MAX));
int ans_dist = DIST_MAX;

vi visited(R_MAX+1, false);

void dfs(int p, int depth, int dist){
	if(depth+1 >= R+1) ans_dist = min(ans_dist, dist);
	else{
		rp(r, 1, R+1){
			if(visited[r]) continue;
			visited[r] = true;
			dfs(RR[r], depth+1, dist+D[p][RR[r]]);
			visited[r] = false;
		}
	}
}

int main(){
	cin>>N>>M>>R;
	rp(i, 1, R+1) cin>>RR[i];
	rpz(i, N+1) D[i][i] = 0;
	rpz(i, M) rpz(j, 3){ int a,b,c; cin>>a>>b>>c; D[a][b] = D[b][a] = c; }
	warshall_floyd(D);
	rpz(i, N+1){D[0][i] = 0;D[i][0] = 0;}
	visited[0] = true;
	dfs(0, 0, 0);
	cout<< ans_dist <<endl;
}

Measured memory_bytes: 384
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <array>
#include <cassert>
#include <bitset>
using namespace std;
using LL = long long;

LL N, K;
vector<LL>A;

LL gcd(LL a, LL b)
{
	if (a < b)swap(a, b);
	if (b == 0)return a;
	return gcd(b, a%b);
}

int main(void)
{
	cin >> N >> K;
	for (int i = 0; i < N; ++i)
	{
		int a; cin >> a;
		A.push_back(a);
	}
	sort(A.rbegin(), A.rend());
	LL G = A.front();
	for (int i = 0; i < N; ++i)
	{
		G = gcd(G, A[i]);
	}
	if (K > A[0] || (K % G))
	{
		cout << "IMPOSSIBLE\n";
	}
	else
	{
		cout << "POSSIBLE\n";
	}
	return 0;
}


Measured memory_bytes: 1400
N = int(input())

result = 0
cur = 0
for _ in range(N):
  d1, d2 = map(int, input().split())
  if d1 == d2:
    cur += 1
  else:
    cur = 0
  result = max(result, cur)

print("Yes" if result >= 3 else "No")

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

#define rep(i,n) for(int i=0;i<n;++i)
#define ll long long

int main(){
   int a, b;
   int h, m;
   double pi = 2.0 * asin(1.0);/* πの値 */
   double unit = pi / 180.0;/* 度 → ラジアン */
   cin >> a >> b >> h >> m;
   double Theta = abs((h*30+m*0.5)-m*6);
   if (Theta==0){
       cout << fixed << setprecision(19) << abs(a-b) << endl;
       return 0;
   }
   if (Theta==180){
       cout << fixed << setprecision(19) << a+b << endl;
       return 0;
   }
   if (Theta>180){
       Theta=360-Theta;
   }
   double res = sqrt(a*a+b*b-2*a*b*cos(Theta*unit));
   cout << fixed << setprecision(19) << res << endl;

}

Measured memory_bytes: 4136
#include<bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
using namespace std;
using ll = int_fast64_t;
using pr = pair<ll, ll>;
using vll = vector<ll>;
using vpr = vector<pr>;
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }
struct mint {
  ll divisor = 1000000007;
  ll val;
  constexpr mint(ll v = 0) noexcept : val(v % divisor) {
    if (val < 0) val += divisor;
  }
  constexpr mint operator + (const mint& rhs) const noexcept {
    return mint(*this) += rhs;
  }
  constexpr mint operator - (const mint& rhs) const noexcept {
    return mint(*this) -= rhs;
  }
  constexpr mint operator * (const mint& rhs) const noexcept {
    return mint(*this) *= rhs;
  }
  constexpr mint operator / (const mint& rhs) const noexcept {
    return mint(*this) /= rhs;
  }
  constexpr mint operator ~ () const noexcept {
    ll a = this->val, b = divisor, u = 1, v = 0;
    while (b > 0) {
      ll t = a / b;
      a -= t * b;
      u -= t * v;
      ll c = a; a = b; b = c;
      ll w = u; u = v; v = w;
    }
    if (u < 0) u += divisor;
    u %= divisor;
    return u;
  }
  constexpr mint& operator += (const mint& rhs) noexcept {
    val += rhs.val;
    if (val >= divisor) val -= divisor;
    return *this;
  }
  constexpr mint& operator -= (const mint& rhs) noexcept {
    if (val < rhs.val) val += divisor;
    val -= rhs.val;
    return *this;
  }
  constexpr mint& operator *= (const mint& rhs) noexcept {
    val = val * rhs.val % divisor;
    return *this;
  }
  constexpr mint& operator /= (const mint& rhs) noexcept {
    val = val * (~(mint(rhs))).val % divisor;
    return *this;
  }
  friend mint modpow (mint a, ll n) noexcept {
    auto res = mint(1);
    while(n > 0) {
      if(n&1) res *= a;
      a *= a;
      n >>= 1;
    }
    return res;
  }
  friend std::ostream& operator << (std::ostream& os, const mint& a) noexcept {
    return os << a.val;
  }
};

void answer() {
  int n,k; cin>>n>>k;
  vector<mint> v(k+1, -1);
  mint ans = 0;
  REPCM(x, k, 1) {
    v[x] = modpow(mint(k/x), n);
    int y = x+x;
    while(y <= k) {
      v[x] -= v[y];
      y += x;
    }
    ans += v[x] * x;
  }
  cout << ans << "\n";
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  answer();
  return 0;
}

Measured memory_bytes: 4764
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<queue>
#include<stack>
#include<complex>
#include<utility>
#include<cmath>
#include<set>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define pi acos(-1)
#define all(v) v.begin(),v.end()
using namespace std;

typedef pair<string,string> pss;

const double eps = 1e-8;
const double INF = 1e12;

string reverse(string s){
	string res="";
	rep(i,s.size()){
		res+=s[s.size()-i-1];
	}
	return res;
}


int main(){
	int n;
	string s;
	cin>>n;
	rep(k,n){
		set<string> st;
		cin>>s;
		vector<pss> vec;
		string left,right;
		loop(i,1,s.size()){
			left=right="";
			rep(j,s.size()){
				if(i<=j)right+=s[j];
				else left+=s[j];
			}
			vec.push_back(pss(left,right));
		}
		int size=vec.size();
		rep(i,size){
			vec.push_back(pss(vec[i].first,reverse(vec[i].second)));
			vec.push_back(pss(reverse(vec[i].first),vec[i].second));
			vec.push_back(pss(reverse(vec[i].first),reverse(vec[i].second)));
		}
		size=vec.size();
		rep(i,size){
			st.insert(vec[i].first+vec[i].second);
			st.insert(vec[i].second+vec[i].first);
		}
		cout<<st.size()<<endl;
	}
	return 0;
}

Measured memory_bytes: 1344
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>

namespace adaptor = boost::adaptors;

void solve()
{
    int64_t A, B;
	std::cin >> A >> B;

	int64_t ans = -1;

	for (int64_t price = 1; price <= 1300; price++)
	{
		int64_t eight = std::floor(price * 0.08);
		int64_t ten = std::floor(price * 0.10);
		if (eight == A && ten == B)
		{
			ans = price;
			break;
		}
	}
	std::cout << ans << std::endl;
}

int main()
{
	std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	solve();
}


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



int main()
{   
    int x,y;
     cin>>x>>y;
    for(int i=0;i<=x;i++){
        
         if((((2*i) + (4*(x-i))) == y)||(2*(x-i) + 4*i == y))
         {
             cout<<"Yes";
             return 0;
        
        }
    }
    cout<<"No";
   return 0;
   }

Measured memory_bytes: 3624
N=int(input())
l=[0] if N==0 else []
j=0

while sum(l[i]*(-2)**i for i in range(len(l)))!=N:
  if sum(l[i]*(-2)**i for i in range(len(l)))%((-2)**(j+1))==N%((-2)**(j+1)):
    l.append(0)
  else:
    l.append(1)
  j+=1
print(''.join(map(str,reversed(l))))

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

#define debug(x) (cerr << #x << " = " << x << endl;)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define FOR(it, b, e) for (typeof(b) it = (b); it != (e); ++it)
#define MSET(c, v) memset(c, v, sizeof(c))

const int INF = 0x3F3F3F3F; 
const int NEGINF = 0xC0C0C0C0;
const int NULO = -1;
const ll mod = 1e9 + 7;
const double EPS = 1e-10;

inline int cmp(double x, double y = 0) 
{  
  if(fabs(x - y) < EPS)
    return 0;
  return x > y ? 1 : -1;
}

int main()
{
  ios::sync_with_stdio(0);
  int k;
  cin >> k;

  vector<ll>a;

  for(int i = 1; i <= 9 ; i++)
  {
    a.push_back(i);
  }

  while(true)
  {
    if(k < a.size())
    {
      cout << a[k - 1] << endl;
      break;
    } 

    k -= a.size();

    vector<ll>old;
    swap(old, a);
    for(const auto &x : old)
    {
      for(int i = -1; i <= 1; i++)
      {
        int d = x % 10 + i;
        if(d < 0 || d > 9)
          continue;
        a.push_back(x * 10 + d);
      }
    }
  }
  
  return 0;
}

Measured memory_bytes: 4676