akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;
using lli = int_fast64_t;
using ulli = unsigned long long;
#define debug(x) cerr << #x << " : " << x << endl
#define debugv(x) cerr << #x << " : {";for(auto value_of_x:x){ cerr << value_of_x << ", ";}cerr << endl
#define debugst(x) auto xt = copy(x);cerr << #x << " : {";for(int i=0;i<x.size();i++){ cerr << xt.top() << ", ";xt.pop();}cerr << endl
#define debugvp(x) cerr << #x << " : {";for(auto value_of_x:x){ cerr << value_of_x.first << " : " << value_of_x.second << ", ";}cerr << endl

constexpr lli MOD = (lli)1e9 + 7;
constexpr lli LIMIT = 1000000000000000000 * 5;

int main() {
	int a;
	cin >> a;
	cout << a + a * a + a * a * a << endl;
	return 0;
}



Measured memory_bytes: 3588
# セグメントツリー
#############################################################

def segfunc(x, y):
    return max(x, y)

ide_ele = 0

class SegTree:

    def __init__(self, init_val, segfunc, ide_ele):
        n = len(init_val)
        self.segfunc = segfunc
        self.ide_ele = ide_ele
        self.num = 1 << (n - 1).bit_length()
        self.tree = [ide_ele] * 2 * self.num
        for i in range(n):
            self.tree[self.num + i] = init_val[i]
        for i in range(self.num - 1, 0, -1):
            self.tree[i] = self.segfunc(self.tree[2 * i], self.tree[2 * i + 1])

    def update(self, k, x):
        k += self.num
        self.tree[k] = x
        while k > 1:
            self.tree[k >> 1] = self.segfunc(self.tree[k], self.tree[k ^ 1])
            k >>= 1

    def query(self, l, r):
        res = self.ide_ele
        l += self.num
        r += self.num
        while l < r:
            if l & 1:
                res = self.segfunc(res, self.tree[l])
                l += 1
            if r & 1:
                res = self.segfunc(res, self.tree[r - 1])
            l >>= 1
            r >>= 1
        return res
#############################################################

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

# val[i] = 最後の値がiである、最長の部分列の長さ
val = [0] * 300010
seg = SegTree(val, segfunc, ide_ele)
ans = 0

for i in range(N):
    a = int(input())
    # (a-K, a-K+1, ..., a+K-1, a+K の max) + 1 に更新する
    # 両端が範囲内に収まるように調整
    l = max(a - K, 0)
    r = min(a + K, 300000)
    # 半開区間であることに注意
    tmp = seg.query(l, r + 1) + 1
    ans = max(ans, tmp)
    seg.update(a, tmp)

print(ans)


Measured memory_bytes: 113836
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <algorithm>

#define int long long
#define MOD7 1000000007
#define MOD9 1000000009

#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, a, n) for (int i = (a); i <= (n); i++)
#define all(a) (a).begin(), (a).end()

using namespace std;

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

int nextInt() {int a; cin >> a; return a;}
char nextChar() {char a; cin >> a; return a;}
double nextDouble() {double a; cin >> a; return a;}
string nextString() {string a; cin >> a; return a;}

void inputVector(vector<int> &v, int &n) {rep(i,n){v.push_back(nextInt());}}
void inputVector(vector<double> &v, int &n) {rep(i,n){v.push_back(nextDouble());}}
void inputVector(vector<string> &v, int &n) {rep(i,n){v.push_back(nextString());}}

int strToInt(string str) {
    int size = str.size();
    int ret = 0;
    for (int i = 0; i < size; i++) {
	int tmp = str[size - i - 1] - '0';
	for (int j = 0; j < i; j++) {
	    tmp *= 10;
	}
	ret += tmp;
    }
    return ret;
}

int solve(string s) {
    s = s.substr(1, s.size() - 2);

    if (s.find('[') == string::npos) {
	return strToInt(s);
    }

    vector<string> child;

    int cnt = 0;
    int pt = 0;
    rep(i, s.size()) {
	if (s[i] == '[') {
	    cnt++;
	    if (cnt == 1) pt = i;
	} else if (s[i] == ']') {
	    cnt--;
	    if (cnt == 0) {
		child.push_back(s.substr(pt, i - pt + 1));
	    }
	}
    }

    vector<int> nums;
    rep(i, child.size()) {
	nums.push_back(solve(child[i]));
    }

    sort(all(nums));

    int ret = 0;
    rep(i, (nums.size() + 1) / 2) {
	ret += nums[i];
    }
    ret += nums.size() / 2;
    return ret;
}

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

    rep(i, n) {
	cout << (solve(nextString()) + 1) / 2 << endl;
    }

    return 0;
}

Measured memory_bytes: 3304
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <cmath>
#include <numeric>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <complex>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <list>
#include <unordered_map>

using namespace std;
typedef long long ll;

ll mygcd(int x, int y);

int main()
{
	int n;
	std::cin >> n;

	vector<ll> a((int)n);
	vector<ll> r((int)n);
	vector<ll> l((int)n);

	for (int i = 0; i < n; ++i)
	{
		cin >> a[i];
		if (i == 0)
			l[i] = a[i];
		else
			l[i] = mygcd(l[i - 1], a[i]);
		//cout << i << ":" << l[i] << endl;
	}

	for (int i = n - 1; i >= 0; --i)
	{
		if (i == n - 1)
			r[i] = a[i];
		else
			r[i] = mygcd(r[i + 1], a[i]);
		//cout << i << ":" << r[i] << endl;
	}

	ll val = 0;
	for (int i = 0; i < n; ++i)
	{
		if (i == 0)
			val = max(val, r[i + 1]);
		else if (i == n - 1)
			val = max(val, l[i - 1]);
		else
			val = max(val, mygcd(r[i + 1], l[i - 1]));
	}

	cout << val << endl;

	return 0;
}

ll mygcd(int x, int y)
{
	if (y == 0) return x;
	return mygcd(y, x % y);
}


Measured memory_bytes: 2560
#include <bits/stdc++.h> //AtCoder
#include <iostream> //Codeforces
#include <vector> //Codeforces

#define int long long
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repeq(i,a,b) for(int i=a;i<=b;i++)
#define Vi vector<int>
#define VVi vector<Vi>
#define Vs vector<string>
#define Vc vector<char>
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define cyes cout<<"yes"<<endl
#define cno cout<<"no"<<endl

using namespace std;

int gcd(int a,int b){return b?gcd(b,a%b):a;}//最大公約数
int lcm(int a,int b){return a/gcd(a,b)*b;}//最小公倍数

/****************************** START ******************************/

signed main(){
  int N;
  cin >> N;
  Vi A(N);
  rep(i,0,N){
    cin >> A.at(i);
  }
  
  int sum = 0;
  rep(i,1,N){
    if (A.at(i) < A.at(i - 1)){
      sum += A.at(i - 1) - A.at(i);
      A.at(i) = A.at(i - 1);
    }
  }
  cout << sum;
}    

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

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

typedef double db;


int main(){
db w,h,x,y;
cin>>w>>h>>x>>y;
db s=(w*h)/2.0;
cout<<s<<endl;
if(w/2==x&&h/2==y){cout<<1<<endl;}
else{cout<<0<<endl;}
return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std ;
const int maxn = 1e5 +5 ;
int cnt = 0 ;
int main() {
    char s[maxn];
    int n ;
    cin >>n ;
    for(int i = 0 ; i < n ; i++) {
        cin >> s[i] ;
    }
    s[n] ='\0';
    for(int i = 0 ; i < n ; i++) {
        if(s[i] != s[i+1]) cnt++ ;
    }
    cout << cnt << endl;
    return 0 ;
}

Measured memory_bytes: 384
#include <iostream>

using namespace std;

void solve(int k, int a, int b){
    for(int i=a;i<=b;i++){
        if(i%k==0){
            cout<<"OK\n";
            return;
        }
    }
    cout<<"NG\n";
}

int main() {
    int k;
    cin>>k;
    int a,b;
    cin>>a>>b;
    
    solve(k,a,b);
}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
    int n;
    cin>>n;
    map<string,int> m;
    while(n--)
    {
        string s;
        cin>>s;
        sort(s.begin(),s.end());
        m[s]++;
    }
    ll ans=0;
    map<string,int>::iterator it;
    for(it=m.begin();it!=m.end();it++)
    {
        ll x=it->second;
        x=(x*(x-1))/2;
        ans+=x;
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 11136
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
const int N = 1e5+11;
int f[N],h[N];
int main()
{
    memset(f,0x3f,sizeof f);
    int n;scanf("%d",&n);
    for(int i = 3;i <= n + 2;++i)
        scanf("%d",&h[i]);
    f[3] = 0;
    for(int i = 3;i <= n + 2;++i)
        f[i] = min(min(f[i - 1] + abs(h[i] - h[i - 1]),f[i - 2] + abs(h[i] - h[i - 2])),f[i]);
    cout << f[n + 2];
    return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>
#include<math.h>
#define P(x) pow(double(x),2)



int main(){


	int i,j,k;
	int n;
	double x[3],y[3];
	double xp,yp,r;
	double a1,a2,b1,b2,c1,c2;
	
	while((scanf("%d",&n))!=EOF){
		for(i=0;i<3;i++){
			scanf("%lf",&x[i]);
			scanf("%lf",&y[i]);
		}
		a1=2*(x[1]-x[0]);
		a2=2*(x[2]-x[1]);
		b1=2*(y[1]-y[0]);
		b2=2*(y[2]-y[1]);
		c1=(P(x[0])-P(x[1])+P(y[0])-P(y[1]));
		c2=(P(x[1])-P(x[2])+P(y[1])-P(y[2]));
	
		xp=(b1*c2-b2*c1)/(a1*b2-a2*b1);
		yp=(c1*a2-c2*a1)/(a1*b2-a2*b1);
		r=(double)(sqrt((long double)(((xp-x[0])*(xp-x[0]))+((yp-y[0])*(yp-y[0])))));	


		printf("%.3f %.3f %.3f\n",xp,yp,r);

	}



}

Measured memory_bytes: 0
#include <iostream>
#include <cstdio>

using namespace std;

char pixel[100][100];

int main()
{
    int h, w;
    
    cin >> h >> w;
    
    for (int y = 0; y < h; y++)
    {
        for (int x = 0; x < w; x++)
        {
            cin >> pixel[y][x];
        }
    }
    
    for (int y = 0; y < h; y++)
    {
        for (int i = 0; i < 2; i++)
        {
            for (int x = 0; x < w; x++)
            {
                printf("%c", pixel[y][x]);
            }
            printf("\n");
        }
    }
    printf("\n");
    
    return 0;
}


Measured memory_bytes: 256
//高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

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

#define INF INT_MAX
#define LLINF LLONG_MAX
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007
#define MODB  998244353 

template <typename T>
std::istream& operator>>(std::istream& is, std::vector<T>& vec) {
    for (T& x: vec) { is >> x; }
    return is;
}

int main() {
	ll ans = 0;
	ll tmp;
	int n; cin >> n;
	vector<ll> a(n);
	cin >> a;
	map<ll, int> m;
	m[0]++;
	tmp = 0;
	ll rw[n] = {};
	REP(i, n){
		tmp += a[i];
		m[tmp]++;
		rw[i] = tmp;
	}
	ans += m[0];
	REP(i, n){
		//cout << rw[i] << endl;
		ans += m[rw[i]] - 1;
	}
	cout << ans / 2 << endl;
}

Measured memory_bytes: 18680
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
using namespace std;
using ll = long long;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll inf = 1145141919810364364LL;
#define all(x) (x).begin(),(x).end()
#define puts(x) cout << x << endl
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)


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

	ll T1, T2;
	ll A1, A2;
	ll B1, B2;
	cin >> T1 >> T2;
	cin >> A1 >> A2;
	cin >> B1 >> B2;

	if (A1*T1 + A2 * T2 == B1 * T1 + B2 * T2) {
		puts("infinity");
		return 0;
	}

	if (A1*T1 + A2 * T2 < B1 * T1 + B2 * T2) {
		swap(A1, B1);
		swap(A2, B2);
	}

	ll sum1 = A1 * T1 + A2 * T2;
	ll sum2 = B1 * T1 + B2 * T2;
	if (B1 - A1 < 0) {
		puts(0);
		return 0;
	}
	else if((B1-A1)*T1 % (sum1-sum2)==0LL)puts(2LL*((B1-A1)*T1/(sum1-sum2)));
	else puts(2LL * ((B1 - A1)*T1 / (sum1 - sum2)) + 1LL);

	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define rep(i,b) FOR(i,0,b)
#define INF mugen
#define dump(x) cerr<<#x<<"="<<x<<endl
#define all(a) (a).begin(),(a).end()
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<vii> viii;
typedef pair<int,int> P;
template <class T> void chmin(T & a, T const & b) { if (b < a) a = b; }
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
using ll = long long;
const ll mod = LLONG_MAX;

int p[112345];
P ch[112345];
bool used[112345];
int d[112345];

int uni[1000010];
void init(int V){
  for(int i=0;i<V;i++){
    uni[i]=-1;
  }
}
int root(int a){
  if(uni[a] < 0)return a;
  else return uni[a] = root(uni[a]);
}
bool unite(int a,int b){
  a = root(a);
  b = root(b);
  if(a==b) return false;
  if(uni[a] > uni[b]) swap(a,b);
  uni[a]+=uni[b];
  uni[b]=a;
}

bool same(int a,int b){
  return root(a)==root(b);
}
int ans=0;
int main(){
  int n,m;
  cin>>n>>m;
  rep(i,n)cin>>p[i];
  init(112345);

  rep(i,m){
    cin>>ch[i].first>>ch[i].second;
    unite(ch[i].first,ch[i].second);
  }

  rep(i,n){

    // dump(memo);
    // dump(p[i]);
    if(same(p[i],i+1))ans++;
    // dump(ans);
  }
  cout<<ans<<endl;



}


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

int main(){
  bool s[50][50]={0};
  int H,W;
  cin>>H>>W;
  char tmp;
  int white=0;
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      cin>>tmp;
      if(tmp=='.'){
        s[i][j]=1;
        white++;
      }
    }
  }
  int dis[50][50]={0};
  dis[0][0]=1;

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

  queue<pair<int,int>> q;
  q.push({0,0});
  while(dis[H-1][W-1]==0&&!q.empty()){
    pair<int,int> pos=q.front();
    q.pop();
    int x=pos.first,y=pos.second;
    for(int i=0;i<4;i++){
      int newx=x+dx[i],newy=y+dy[i];
      if(newx>=0&&newx<=H-1&&newy>=0&&newy<=W-1&&dis[newx][newy]==0&s[newx][newy]){
        dis[newx][newy]=dis[x][y]+1;
        q.push({newx,newy});
      }
    }
  }
  if(dis[H-1][W-1]==0) cout<<-1<<endl;
  else cout<<white-dis[H-1][W-1]<<endl;

  return 0;
}



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

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

 int main() {
   ll N, ans;
   cin >> N;
   vector<ll> A(N);
   map<ll, ll> a;

   rep(i, N) {
     cin >> A.at(i);
     a[A.at(i)]++;
   }

   for (auto p : a) {
     if (p.second == p.first) continue;
     else if (p.second < p.first) ans += p.second;
     else if (p.second > p.first) ans += p.second - p.first;
   }

   cout << ans << endl;
 }


Measured memory_bytes: 7040
#include <iostream>
#include <math.h>
#include <string>
#include <stdio.h>
#include <string.h>
#include <algorithm>

using namespace std;

int main(void)
{
    long n, a[200000];
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    
    if (n == 2)
    {
        for (long j = 1; j < 200000; j++)
        {
            if (a[0] % j == 0 && a[1] % j == 0)
            {
                cout << j << endl;
            }
            
        }
    }

    else if (n == 3)
    {
        for (long j = 1; j < 200000; j++)
        {
            if (a[0] % j == 0 && a[1] % j == 0)
            {
                if (a[3] % j == 0)
                {
                    cout << j << endl;
                }
            }
        }
    }
}

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

int main(){

    string s[3];
    rep(i,3) cin >> s[i];

    string AL="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    string al="abcdefghijklmnopqrstuvwxyz";

    rep(i,3){
        cout << AL[s[i][0]-'A'];
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
const int MOD = 1e9 + 7;
typedef long long lint;
const int INF = 1e7;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repi(i, k, n) for (int i = (k); i < (int)(n); ++i)
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(), (x).end()
int main()
{
    int n;
    cin >> n;
    string s;
    cin >> s;
    vi w(n + 1, 0);
    vi e(n + 1, 0);
    rep(i, n)
    {
        if (s[i] == 'E')
        {
            e[i + 1] = e[i] + 1;
            w[i + 1] = w[i];
        }
        else
        {
            w[i + 1] = w[i] + 1;
            e[i + 1] = e[i];
        }
    }
    int ans = 1 << 20;
    rep(i,n){
        ans = min(ans, w[i] + e[n] - e[i + 1]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3076
#include <iostream>
#include <algorithm>


const int MAXN = 1e3;
const int MOD = 1e9 + 7;

char grid[MAXN][MAXN];
int nbPaths[MAXN + 1][MAXN + 1];


int main()
{
    std::ios::sync_with_stdio(false);
    std::cout.tie(nullptr);
    std::cin.tie(nullptr);

    int height, width;
    std::cin >> height >> width;

    for (int iLine = 0; iLine < height; iLine++)
        for (int iCol = 0; iCol < width; iCol++)
            std::cin >> grid[iLine][iCol];

    nbPaths[height - 1][width] = 1;
    for (int iLine = height - 1; iLine > -1; iLine--)
        for (int iCol = width - 1; iCol > -1; iCol--)
            if (grid[iLine][iCol] == '.')
                nbPaths[iLine][iCol] = (nbPaths[iLine + 1][iCol] + nbPaths[iLine][iCol + 1]) % MOD;

    std::cout << nbPaths[0][0] << '\n';

    return 0;
}


Measured memory_bytes: 5120
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var arr = input.trim().split("\n");
var [h1,h2] = arr.shift().split(" ").map(Number);
var [k1,k2] = arr.shift().split(" ").map(Number);
var [a,b,c,d] = arr.shift().split(" ").map(Number);
var h = h1*a + h2*b+Math.floor(h1/10)*c+Math.floor(h2/20)*d;
var k = k1*a + k2*b+Math.floor(k1/10)*c+Math.floor(k2/20)*d;
if(h==k)console.log("even");
else if(h>k)console.log("hiroshi");
else console.log("kenjiro");


Measured memory_bytes: 17172
// AtCoder Regular Contest 097
// C - K-th Substring

#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;

string s;
int K;

string solve() {
    int n = s.size();
    vector<string> ss;
    for (int i = 0; i < n; i++) {
        for (int l = 1; l <= min(K, n - i); l++) {
            ss.push_back(s.substr(i, l));
        }
    }
    sort(ss.begin(), ss.end());
    ss.erase(unique(ss.begin(), ss.end()), ss.end());
    return ss[K - 1];
}

int main() {
    cin >> s;
    cin >> K;

    cout << solve() << endl;

    return 0;
}


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

const int INF=1000;

int powpow(int x,int k){
    int res=1;
    for(int i=0;i<k;i++) res*=x;
    return res;
}
int solve(int m,int n){
    vector<vector<int>> obj(n,vector<int>(m));
    for(int i=0;i<n;i++){
        string s;
        cin>>s;
        for(int j=0;j<m;j++){
            obj[i][j]=s[j]-'0';
        }
    }
    int pow3=powpow(3,m);
    vector<int> dp(pow3,INF);
    for(int bit=pow3-1;bit>=0;bit--){
        vector<int> st(m);
        int x=bit;
        for(int i=0;i<m;i++){
            st[i]=x%3;
            x/=3;
        }
        vector<int> idx;
        for(int i=0;i<n;i++){
            bool contain=true;
            for(int j=0;j<m;j++){
                contain=contain && (st[j]==0 || st[j]-1==obj[i][j]);
            }
            if(contain){
                idx.push_back(i);
            }
        }
        if(idx.size()<=1){
            dp[bit]=0;
        }
        else{
            for(int i=0;i<m;i++){
                if(!st[i]){
                    dp[bit]=min(dp[bit],max(dp[bit+powpow(3,i)],dp[bit+2*powpow(3,i)])+1);
                }
            }
        }
    }
    return dp[0];
}
int main(){
    int n,m;
    while(cin>>m>>n,m){
        cout<<solve(m,n)<<endl;        
    }
    return 0;
}


Measured memory_bytes: 3828
#include <bits/stdc++.h>
#define i_love_u_Phuong ios_base::sync_with_stdio(0); cin.tie(0);

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

ll lt(ll x,ll y)
{

}

int main()
{
#ifndef RICARDO
    //freopen("input.txt", "r", stdin);
#endif // ONLINE_JUDGE
    i_love_u_Phuong;
    int n;
    cin >> n;
    vector<int> a(n+1);
    int sum=0;
    a[0]=0;
    for(int i=1; i<=n; ++i)
    {
        cin >> a[i];
        if (i==1) sum+=abs(a[i]); else
        sum += abs(a[i]-a[i-1]);
    }
    sum+=abs(a[n]);
    a.push_back(0);
    for(int i=1; i<=n; ++i)
    {

        int s = abs(a[i]-a[i-1]) + abs(a[i]-a[i+1]);
        cout << sum - s + abs(a[i-1] -a[i+1]) << '\n';
    }
    return 0;
}



Measured memory_bytes: 1656
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

using namespace std;

//----------------------- Print Function ----------------------//

inline void print() {
    cout << '\n';
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest) {
    cout << first << ' ';
    print(rest...);
}

template <typename T>
void print(const T &a) {
    for (auto e : a) cout << e << ' ';
    cout << '\n';
}

//------------------------- Libraries -------------------------//

//--------------------------- Solve ---------------------------//

void solve() {
    int n; cin >> n;
    vector<int> x(n), y(n);
    vector<int> s(n), t(n);
    for (int i = 0; i < n; i++) {
        cin >> x[i] >> y[i];
        s[i] = x[i] + y[i];
        t[i] = x[i] - y[i];
    }

    sort(s.begin(), s.end());
    sort(t.begin(), t.end());

    cout << max(s[n-1] - s[0], t[n-1] - t[0]) << '\n';     
}

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

    solve();

    return 0;
}

Measured memory_bytes: 6360
n = int(input())
h = list(map(int, input().split()))
h = h + [10 ** 10]
ans = []
cnt = 0
for i in range(n):
  if h[i] >= h[i+1]:
    cnt += 1
  else:
    ans.append(cnt)
    cnt = 0
print(max(ans))

Measured memory_bytes: 20468
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
using ll = long long;
int main(void){
   int N,A,B;
   cin>>N>>A>>B;
   
   int S=0;
   rep(i,N){
       int num=i+1;
       int sum=0;
       while(num!=0){
           sum+=num%10;
           num/=10;
       }
       if(sum>=A&&sum<=B){
           S+=i+1;
       }
   }
   cout<<S<<endl;
}

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

int main() {
  long A,B,C,K;
  cin >> A>>B>>C>>K;
  long ans=0;
  for(long i=0;i<K;i++){
    if(A>0){
      ans+=1;
      A-=1;
    }
    else if(B>0){
      ans+=0;
      B-=1;
    }
    else if(C>0){
      ans-=1;
      C-=1;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3636
/*
In the first turn, a player announces any one word.
The first character of that word is the same as the last character of the last word announced.
*/
//the last word != the last word announced
#include<bits/stdc++.h>
using namespace std;
int main()
{
	map<string,int> mp;
	int run;
	cin>>run;
	string s;
	vector<string> vs;
	for(int i=0;i<run;i++)
	{
		string a;
		cin>>a;
		mp[a]++;
		vs.push_back(a);
		if(i == run-1)
			s = a;
	}
	bool isok = true;
	for(map<string,int>::iterator it = mp.begin();it!=mp.end();it++)
	{
//		cout<<"the word:"<<it->first<<",the time it shows:"<<it->second<<endl;
//		cout<<"last of the last word:"<<s[s.size()-1]<<endl;
		if(it->second>1)
			isok = false;
	}
	for(int i=1;i<vs.size();i++)
		if(vs[i][0]!=vs[i-1][vs[i-1].size()-1])
			{cout<<"No"<<endl;return 0;}
	if(isok)	
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl; 
	return 0;
} 

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

signed main(){
  
  int n;
  
  int a[50];

  cin>>n;

  for(int i=0;i<n;i++) cin>>a[i];

  int ans = 0;

  for(int i=0;i<n;i++)
    for(int j=i+1;j<n;j++) ans += a[i]*a[j];

  cout<<ans<<endl;
  
  return 0;
}


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

int top, S[1000];

void push(int x) {
    S[top] = x;
    top++;
}

int pop() {
    top--;
    return S[top];
}

int main() {
    top = 0;
    int a, b;
    char s[100];
    
    while (scanf("%s", s) != EOF) {
        if (s[0]=='+') {
            a = pop();
            b = pop();
            push(a+b);
        } else if (s[0]=='-') {
            b = pop();
            a = pop();
            push(a-b);
        } else if (s[0]=='*') {
            a = pop();
            b = pop();
            push(a*b);
        } else {
            push(atoi(s));
        }
    }

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

    return 0;
}


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

typedef unsigned long long ll;

#define REP(i,n,m) for(int i=n;i<m;i++)
#define rep(i,n) REP(i,0,n)

ll filled;
int sh,sw,h,w,hh,ww;
vector<ll> bit,board;

vector<ll> getBits(char ch[70][70],bool destroy){
  int lx=0,ly=0,hx=w-1,hy=h-1;

  if(destroy){
    lx=70; ly=70; hx=-1; hy=-1;

    rep(i,sh){
      rep(j,sw){
        if(ch[i][j] == '#'){
          lx = min(lx,j);
          ly = min(ly,i);
          hx = max(hx,j);
          hy = max(hy,i);
        }
      }
    }

    hh = hy - ly + 1;
    ww = hx - lx + 1;
  }

  vector<ll> res;
  for(int i=ly;i<=hy;i++){
    ll bit = 0;
    for(int j=hx;j>=lx;j--){
      if(ch[i][j] == '#'){
        bit |= (1ULL<<(hx-j));
      }
    }
    res.push_back(bit);
  }

  return res;
}

void rotate(char ch[70][70]){
  char tmp[70][70];
  rep(i,sh) rep(j,sw) tmp[i][j] = ch[i][j];
  rep(i,sh) rep(j,sw) ch[j][sh-i-1] = tmp[i][j];
  swap(sh,sw);
}

int check(){
  int res = -1;

  for(int sj=0;sj<=w-ww;sj++){
    for(int si=0;si<=h-hh;si++){
      int cnt = 0;
      for(int i=0;i<hh;i++){
        if((bit[i] & board[si+i]) > 0){
          cnt = -1;
          break;
        }
        if((bit[i] | board[si+i]) == filled){
          cnt++;
        }
      }
      res = max(res,cnt);
    }

    for(int i=0;i<hh;i++){
      bit[i] <<= 1ULL;
    }
  }

  return res;
}

int main(){
  char ch[70][70],ch2[70][70];
  int T;
  cin>>T;

  while(T--){
    cin>>sh>>sw;
    rep(i,sh){
      cin>>ch[i];
    }

    cin>>h>>w;
    rep(i,h){
      cin>>ch2[i];
    }
    board = getBits(ch2,false);
    filled = 0;
    rep(i,w){
      filled |= (1ULL<<i);
    }

    int ans = -1;
    for(int i=0;i<4;i++){
      bit = getBits(ch,true);
      ans = max(ans,check());
      rotate(ch);
    }
    cout<<ans<<endl;
  }
}

Measured memory_bytes: 932
def gcd(x, y):
    if y == 0:
        return x
    else:
        return gcd(y, x % y)

n = int(input())
aaa = list(map(int, input().split()))
cnt_l = [0] * (n - 1)
cnt_r = [0] * (n - 1)

cnt_l[0] = aaa[0]
for i in range(1, n - 1):
    cnt_l[i] = gcd(cnt_l[i - 1], aaa[i])

aaa.reverse()
cnt_r[0] = aaa[0]
for i in range(1, n - 1):
    cnt_r[i] = gcd(cnt_r[i - 1], aaa[i])

cnt_l = [cnt_r[-1]] + cnt_l
cnt_r = [cnt_l[-1]] + cnt_r
cnt_r.reverse()

ans = 1
for i in range(n):
    tmp = gcd(cnt_l[i], cnt_r[i])
    ans = max(ans, tmp)

print(ans)

Measured memory_bytes: 14080
#include <bits/stdc++.h>
 
using namespace std;
 
int md;
 
int add(int x, int y) {
  x += y;
  if (x >= md) {
    x -= md;
  }
  return x;
}
 
int mul(int x, int y) {
  return (int)((long long)x * y % md);
}
 
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n >> md;
  string s;
  cin >> s;
  map<int, int> m;
  long long ans = 0;
  int dec = 1;
  int cur = 0;
  if (md == 2) {
    long long cnt = 0;
	  for (int i = n - 1; i >= 0; i--) {
      int dig = (s[i] - '0');
      if (dig % 2 == 0) {
        cnt++;
      }
      ans += cnt;
    }
    cout << ans << '\n';
    return 0;
  } 
  if (md == 5) {
    long long cnt = 0;
	  for (int i = n - 1; i >= 0; i--) {
      int dig = (s[i] - '0');
      if (dig % 5 == 0) {
        cnt++;
      }
      ans += cnt;
    }
    cout << ans << '\n';
    return 0;
  }
  for (int i = n - 1; i >= 0; i--) {
    int dig = (s[i] - '0');
    cur = add(cur, mul(dec, dig));
    if (cur == 0) ans++;
    ans += m[cur];
    m[cur]++;
    dec = mul(dec, 10);
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 916
#include<stdio.h>
#include<string.h>
#include<math.h>
int main(){
	int a,b;
	scanf("%d%d",&a,&b);
	bool xxx = true;
	char lmao[a+b+10];
	scanf("%s",&lmao);
	for(int i=0;i<a+b+1;i++){
		if(i == a){
			if(lmao[i] != '-'){
				printf("No\n");
				xxx=false;
				break;
			}
		}
		else{
			if(!(lmao[i]>=48 && lmao[i]<=57)){
				printf("No\n");
				xxx=false;
				break;
			}
		}
	}
	if(xxx) printf("Yes\n");
	return 0;
}

Measured memory_bytes: 1656
#include <stdio.h> 
 
 
 int main(){ 
     char number[1001]; 
     int i, sum; 
     while(1){ 
         scanf("%s", number); 
         if(number[0]=='0')break; 
         sum=0; 
         for(i=0;number[i]!='\0';i++){ 
             sum+=number[i]-'0'; 
         } 
         printf("%d\n", sum); 
     } 
 
      return 0; 
 } 



Measured memory_bytes: 2084
#include <stdio.h>

#define INF (1ll<<29)

typedef long long ll;

int main(void) {
	ll maxer, miner, sum;
	int i, n, a;
	
	scanf("%d", &n);
	
	sum = 0;
	maxer = -INF;
	miner = INF;
	
	for (i = 0; i < n; i++) {
		scanf("%d", &a);
		sum += a;
		maxer = maxer > a ? maxer : a;
		miner = miner < a ? miner : a;
	}
	
	printf("%lld %lld %lld\n", miner, maxer, sum);
	
	return 0;
}

Measured memory_bytes: 600
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <queue>
#include <iostream>
using namespace std;
int main(){
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	int m,n;
	cin>>n>>m;
	vector<int> count(n+1,1);
	vector<bool> taned(n+1,false);
	taned[1]=true;
	int ori,des;
	bool original=true;
	for(int i=0;i<m;i++){
		cin>>ori>>des;
		if(taned[ori]){//被污染过
			if(count[ori]==1){//如果只有一个
				taned[ori]=false;
				taned[des]=true;
				if(original){//如果是纯种
					if(count[des]>0){//目的地有多个，那么久不再有纯种
						original=false;
					}else{//目的地没有珠子，保持纯种优势
					}
				}
			}else{//如果具有多个，直接污染
				taned[des]=true;
			}
		}else{//未被污染过

		}
		count[ori]--;
		count[des]++;
	}
	int a=0;
	for(int i=1;i<=n;i++) if(taned[i]) a++;
	cout<<a<<endl;
	return 0;
}

Measured memory_bytes: 640
def f1():
    for r in range(9):
        for c in range(9):
            flag = Map[r][c]
            i_l = []
            for i in range(9):
                if  Map[r][i] == flag:
                    i_l.append(i)
            if len(i_l) != 1:
                for i in i_l:
                    if not (r, i) in res:
                        res.append((r, i))
                        
def f2():
    for c in range(9):
        for r in range(9):
            flag = Map[r][c]
            i_l = []
            for i in range(9):
                if  Map[i][c] == flag:
                    i_l.append(i)
            if len(i_l) != 1:
                for i in i_l:
                    if not (i, c) in res:
                        res.append((i, c))

def f3():
    for r in range(0, 9, 3):
        for c in range(0, 9, 3):
            for _r in range(3):
                for _c in range(3):
                    f_3(r, c, Map[r+_r][c+_c])
                   
def f_3(r, c, flag):
    i_l = []
    for _r in range(3):
        for _c in range(3):
            if Map[r+_r][c+_c] == flag:
                i_l.append((r+_r, c+_c))
    if len(i_l) != 1:
        for t in i_l:
            if not t in res:
                res.append(t)
                
def f4():
    for r in range(9):
        for c in range(9):
            if (r, c) in res:
                Map[r][c] = '*'+Map[r][c]
            else:
                Map[r][c] = ' '+Map[r][c]
    
    for line in Map:
        print ''.join(line)
    if n != N-1:
        print
        
if __name__ == '__main__':
    N = input()
    for n in range(N):
        Map = [raw_input().split() for i in range(9)]
        res = []
        f1()
        f2()
        f3()
        f4()

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

int main(){
    int n,m;
    cin >> n >> m;
    vector<int> x(m);
    rp(i,m) cin >> x.at(i);
    if(n>=m) {
        cout << 0 << endl;
        return 0;
    }else{
        sort(x.begin(),x.end());
        vector<int> gap(m-1);
        rp(i,m-1) gap[i]=x[i+1]-x[i];
        sort(gap.begin(),gap.end());
        reverse(gap.begin(),gap.end());
        int ans=x[m-1]-x[0];
        rp(i,n-1){
            ans -= gap[i];
        }
        cout << ans << endl;
    }
    return 0;
}

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

int main(){
    int N;
    cin >> N;
    vector<int> D1(N);
    vector<int> D2(N);
    int count = 0;
    string ans;
    for(int i=0; i<N; i++){
        cin >> D1[i] >> D2[i];
        if(D1[i] == D2[i]){
            count++;
        }else{
            count =0;
        }
        if(count == 3){
            ans = "Yes";
            break;
        }else{
            ans = "No";
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3608
import math
import sys

def getinputdata():

    # 配列初期化
    array_result = []
    
    data = input()

    
    array_result.append(data.split(" "))

    flg = 1

    try:


        while flg:

            data = input()

            array_temp = []

            if(data != ""):
                
                array_result.append(data.split(" "))

                flg = 1

            else:

                flg = 0
    finally:


        return array_result





arr_data = getinputdata()

s = arr_data[0][0]
str="CODEFESTIVAL2016"
#print(s)

cnt=0
for i in range(16):
    
    if s[i]!=str[i]:
    
        cnt+=1
        
print(cnt)
    

Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<sstream>
#include<climits>
#include<cstdio>
#include<cstdlib>
using namespace std;

char boin[] = "aiueo";
char siin[] =" kstnhmyrw"; 

int com(char c){
  switch(c){
    case 'T':return 0;
    case 'L':return 1;
    case 'U':return 2;
    case 'R':return 3;
    case 'D':return 4;
  }
}
int main(){
  string in;
  while(cin>>in){
    for(int i=0;i<in.size();){
      int tmp = (in[i]-'0' + 9) %10;
      if(tmp==9&&in[i+1]=='U'){
        cout<<"nn";
        i+=2;
        continue;
      }
      if(tmp!=0){
        cout<<siin[tmp];
      }
      i++;
      cout<<boin[com(in[i])];
      i++;
    }
    cout<<endl;
  }
}

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

int main(){
	string a, b;
	int i = 0;
	cin >> a >> b;
	if(a.size() > b.size()) {
		cout << "GREATER" << endl;
		return 0;
	}
	else if(a.size() < b.size()){
		cout << "LESS" << endl;
		return 0;
	}
	while(true){
		if (a[i] > b[i]) {
			cout << "GREATER" << endl;
			return 0;
		}
		else if (a[i] < b[i]) {
			cout << "LESS" << endl;
			return 0;
		}
		else i++;
		if(i == a.size()) {
			cout << "EQUAL" << endl;
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;

public class Main{
	public static void main(String[] args) throws Exception{
		PrintWriter pw=new PrintWriter(System.out);
		MScanner sc = new MScanner(System.in);
		pw.println(sc.nextLine().contains("7")?"Yes":"No");
		pw.flush();
	}
	static class MScanner {
		StringTokenizer st;
		BufferedReader br;
		public MScanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}
 
		public MScanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}
 
		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}
		public int[] intArr(int n) throws IOException {
	        int[]in=new int[n];for(int i=0;i<n;i++)in[i]=nextInt();
	        return in;
		}
		public long[] longArr(int n) throws IOException {
	        long[]in=new long[n];for(int i=0;i<n;i++)in[i]=nextLong();
	        return in;
		}
		public int[] intSortedArr(int n) throws IOException {
	        int[]in=new int[n];for(int i=0;i<n;i++)in[i]=nextInt();
	        shuffle(in);
	        Arrays.sort(in);
	        return in;
		}
		public long[] longSortedArr(int n) throws IOException {
	        long[]in=new long[n];for(int i=0;i<n;i++)in[i]=nextLong();
	        shuffle(in);
	        Arrays.sort(in);
	        return in;
		}
		static void shuffle(int[]in) {
			for(int i=0;i<in.length;i++) {
				int idx=(int)(Math.random()*in.length);
				int tmp=in[i];
				in[i]=in[idx];
				in[idx]=tmp;
			}
		}
		static void shuffle(long[]in) {
			for(int i=0;i<in.length;i++) {
				int idx=(int)(Math.random()*in.length);
				long tmp=in[i];
				in[i]=in[idx];
				in[idx]=tmp;
			}
		}
		public Integer[] IntegerArr(int n) throws IOException {
	        Integer[]in=new Integer[n];for(int i=0;i<n;i++)in[i]=nextInt();
	        return in;
		}
		public Long[] LongArr(int n) throws IOException {
	        Long[]in=new Long[n];for(int i=0;i<n;i++)in[i]=nextLong();
	        return in;
		}
		public String nextLine() throws IOException {
			return br.readLine();
		}
 
		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}
 
		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}
 
		public char nextChar() throws IOException {
			return next().charAt(0);
		}
 
		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}
 
		public boolean ready() throws IOException {
			return br.ready();
		}
 
		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}
	static void addX(int[]in,int x) {
		for(int i=0;i<in.length;i++)in[i]+=x;
	}
	static void addX(long[]in,int x) {
		for(int i=0;i<in.length;i++)in[i]+=x;
	}
}

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

int main() {
  int a,b;
  cin>>a>>b;
  if(a==1&&b==2||a==2&&b==1){
    cout<<3<<endl;
  }
   if(a==3&&b==2||a==2&&b==3){
    cout<<1<<endl;
  }
   if(a==1&&b==3||b==1&&a==3){
    cout<<2<<endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) (v).begin(),(v).end()
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
typedef pair<int, int> P;
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const ll MOD = 1e9+7;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main() {
	int n, m;
	cin >> n >> m;
    vector<int> d(n);
    rep(i,m) {
        int a, b;
        cin >> a >> b; a--; b--;
        d[a] ^= 1;
        d[b] ^= 1;
    }
    int ans = 0;
    rep(i,n) ans += d[i];
	if (ans > 0) {
        cout << "NO" << endl;
    } else {
        cout << "YES" << endl;
    }

	return 0;
}


Measured memory_bytes: 640
/*
Cerberus97
Hanit Banga
*/

#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>

using namespace std;

#define pb push_back
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)

typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

const int N = 1e3 + 10;
const ll inf = 1e15;

ll a[N];
vector<int> ops;

ll solve(int l, int r);

int main() {
	int n; cin >> n;
	for (int i = 1; i <= n; ++i) {
		cin >> a[i];
	}
	ll best = -inf, best_p = -1;
	for (int i = 1; i <= n; ++i) {
		ll temp = solve(i, n);
		if (temp > best) {
			best = temp;
			best_p = i;
		}
	}
	solve(best_p, n);
	cout << best << endl;
	cout << ops.size() << endl;
	for (auto &i : ops) {
		cout << i << '\n';
	}
}

ll solve(int l, int r) {
	ops.clear();
	int offset = -(l - 1);
	ll ans = a[l];
	for (int j = 1; j < l; ++j) {
		ops.pb(1);
	}
	for (int i = l + 1; i <= r; ++i) {
		if (i == r) {
			ops.pb(i + offset);
		} else if (a[i + 1] >= 0) {
			ans += a[i + 1];
			ops.pb(i + offset);
			offset -= 2;
			++i;
		} else if (i + 2 <= r) {
			ops.pb(i + 1 + offset);
			offset -= 2;
			++i;
		} else {
			ops.pb(i + 1 + offset);
			ops.pb(i + offset);
			break;
		}
	}
	return ans;
}

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

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

    int N;
    cin >> N;
    vector<vector<pair<int, int>>> statements(N);
    REP(i, N) {
        int A;
        cin >> A;
        REP(j, A) {
            int x, y;
            cin >> x >> y;
            statements[i].push_back({x-1, y});
        }
    }
    int ans = 0;
    REP(bit, 1 << N) {
        bool ok = true;
        REP(i, N) {
            if ((bit >> i & 1) == 0) continue;
            for (auto& p : statements[i]) {
                int x = p.first, y = p.second;
                if ((bit >> x & 1) != y) {
                    ok = false;
                    break;
                }
            }
            if (!ok) break;
        }
        if (ok) ans = max(ans, __builtin_popcount(bit));
    }
    cout << ans << endl;
}

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

int main() {

    ll N, P;
    cin >> N >> P;

    if (N == 1) {
        cout << P << endl;
        return 0;
    }

    ll ans = 1;
    FOR(a, 2, 1e6+1) {
        bool ok = true;
        ll p = P;
        rep(i, N) {
            if (p%a == 0) p /= a;
            else {
                ok = false;
                break;
            }
        }
        if (ok) ans = a;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3556
n,k = map(int,input().split())
h_ls = list(map(int, input().split()))
mincost_ls = [float('inf')] * n
mincost_ls[0] = 0
for i in range(n):
    for j in range(1,k+1):
        if i+j < n:
            mincost_ls[i+j] = min(mincost_ls[i+j], mincost_ls[i] + abs(h_ls[i+j]-h_ls[i]))
print(mincost_ls[-1])



Measured memory_bytes: 85520
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_C main
#include "bits/stdc++.h"
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LLONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
using psi = pair<string, int>;
// functions

#endif


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


    int N = 3;
    vvi C(N, vi(N));
    REP(i, N)
        REP(j, N) cin >> C[i][j];

    /*
      a1+b1 a1+b2 a1+b3
      a2+b1 a2+b2 a2+b3
      a3+b1 a3+b2 a3+b3
    */

    bool ok = true;
    FOR(j,1,N) {
        int dr = C[0][j] - C[0][j-1];
        FOR(i,1,N) {
            if (dr != C[i][j] - C[i][j-1]) {
                ok = false;
                break;
            }            
        }
        if (!ok) break;
    }

    FOR(i,1,N) {
        int dc = C[i][0] - C[i-1][0];
        FOR(j,1,N) {
            if (dc != C[i][j] - C[i-1][j]) {
                ok = false;
                break;
            }            
        }
        if (!ok) break;
    }

    string ans = ok ? "Yes" : "No";
    cout << ans << endl;


    return 0;
}

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

using namespace std;

int main() {
	long n;
	vector<long> a(5);
	cin >> n;
	for (int i = 0; i < 5; ++i) {
		cin >> a[i];
	}
	long min = *min_element(a.begin(), a.end());
	int min_idx = distance(a.begin(), min_element(a.begin(), a.end()));
	long ans = min_idx;
	ans += n/min;
	if (n%min == 0) {
		ans += 5 - min_idx -1;
	} else {
	   	ans += 5 - min_idx;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
while True:
    x=input().split()
    a=int(x[0])
    op=x[1]
    b=int(x[2])

    if op=='?':break
    elif op=='+': print((a) + (b))
    elif op=='-': print((a) - (b))
    elif op=='*': print((a) *  (b))
    elif op=='/': print((a) // (b))



Measured memory_bytes: 5592
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
#include <array>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define loop(i, a, n) for (int i = a; i < (n); i++)
#define all(in) in.begin(), in.end()
const int INF = 1e9;
const int MOD = 1e9 + 7;
int main() {
    string S;
    cin >> S;
    S = S.substr(0, 4) + " " + S.substr(4, 11);
    cout << S << endl;
    return 0;
}


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

using namespace std;
using ll = long long;
#define int ll
using PII = pair<int, int>;
template <typename T> using V = vector<T>;
template <typename T> using VV = vector<V<T>>;
template <typename T> using VVV = vector<VV<T>>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define PB push_back

const ll INF = (1LL<<60);
const int MOD = 1000000007;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }
template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
  out<<'('<<a.first<<','<<a.second<<')';
  return out;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
  out<<'[';
  REP(i, a.size()) {out<<a[i];if(i!=a.size()-1)out<<',';}
  out<<']';
  return out;
}

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

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

  int n;
  cin >> n;
  if(n%2==0) cout << n << endl;
  else cout << 2*n << endl;  

  return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) {
        FastScanner scanner = new FastScanner();
        PrintWriter out = new PrintWriter(System.out);
        long A = scanner.nextLong();
        long B = scanner.nextLong();
        long C = scanner.nextLong();
        long D = scanner.nextLong();
        long v1 = getVal(B, A, C);
        long v2 = getVal(B, A, D);
        long v3 = getVal(B, A, ((C/gcd(C,D)) * D));
        out.println((B - A + 1) - (v1 + v2 - v3));
        out.flush();
    }
    
    static long getVal(long R, long L, long D) {
        return R /D - (L-1) /D;
    }
    
    static long gcd(long a, long b) {
        if (b == 0) return a;
        return gcd(b, a % b);
    }
    
    public static class FastScanner {
        BufferedReader br;
        StringTokenizer st;
        
        public FastScanner(Reader in) {
            br = new BufferedReader(in);
        }
        
        public FastScanner() {
            this(new InputStreamReader(System.in));
        }
        
        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
        
        int nextInt() {
            return Integer.parseInt(next());
        }
        
        long nextLong() {
            return Long.parseLong(next());
        }
        
        double nextDouble() {
            return Double.parseDouble(next());
        }
        
        String readNextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
        
        int[] readIntArray(int n) {
            int[] a = new int[n];
            for (int idx = 0; idx < n; idx++) {
                a[idx] = nextInt();
            }
            return a;
        }
    }
}


Measured memory_bytes: 21204