akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <queue>
#include <tuple>
#include <stack>
#include <climits>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#define INF INT_MAX>>1 //要climits#includ

typedef long long ll;

using namespace std;

int main(void){
	int n, m; cin >> n >> m;
	int k[11], s[11][11];
	for(int i=0; i<m; i++){
		cin >> k[i];
		for(int j=0; j<k[i]; j++){
			cin >> s[i][j];
		}
	}
	int p[11];
	for(int i=0; i<m; i++){
		cin >> p[i];
	}

	int S = 1 << n;
	int ans = 0;
	for(int i=0; i<S; i++){//bit
		for(int j=0; j<m; j++){//電球
			int cnt = 0;
			for(int t=1; t<=n; t++){//bit
				if((i>>(t-1)) & 1){
					for(int u=0; u<k[j]; u++){//対応するもの
						if(s[j][u] == t){
							cnt++;
							break;
						}
					}
				}
			}
			if(cnt%2 != p[j]) goto NEXT;
		}
		ans++;
		//cout << i << endl;
		NEXT:;
	}
	cout << ans << endl;
}

/*
int main(void){
	int n; cin >> n;
	pair<string, pair<int, int> > p[101];
	for(int i=0; i<n; i++){
		cin >> p[i].first >> p[i].second.first;
		p[i].second.first *= -1;
		p[i].second.second = i+1;
	}
	sort(p, p+n);
	for(int i=0; i<n; i++){
		cout << p[i].second.second << endl;
	}
}
*/

/*
int main(void){
	int a, p; cin >> a >> p;
	cout << (a*3+p)/2 << endl;


	return 0;
}
*/

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF INT_MAX
#define ll  long long
#define ull unsigned long long
#define rep(i,n) for(ll i=0; i<n; ++i)
#define FOR(i, s, e) for(ll i=s; i<e; ++i)
#define MOD 1000000007
using namespace std;
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;}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  char a; cin >> a;
  if('a' <= a && a <= 'z') cout << "a" << endl;
  else cout << "A" << endl;
}

Measured memory_bytes: 3644
#include<stdio.h>
int main(void)
{
		int n,i,h[101],k,j,t[101],w[101],flg;
	while(1) {
	flg=0;
		scanf("%d",&n);
		if(n==0)  break;
		for(i=0;i<n+1;i++){
		 scanf("%d",&h[i]);
		 }
		for(i=0;i<n+1;i++){
			for(j=0;j<n;j++){
			if(j>=i){
				t[j]=h[j+1];
				}
			else{
				t[j]=h[j];
				}
			}	
		for(j=0;j<n-1;j++){
			w[j]=t[j+1]-t[j];
			}
		for(j=0;j<n-2;j++){
			if(w[j]!=w[j+1]){
			flg=0;	break;
			}
			if(w[j]==w[j+1]){
			flg=1;
			}
		}
	if(flg==1){
		k=h[i];
		i=110;
		}
	}	
	printf("%d\n",k);
}	
		return 0;
	}	

Measured memory_bytes: 1028
n, m = map(int, input().strip().split())
grid = []
for i in range(n):
    grid.append(input())
dp = [[None]*m for _ in range(n)]
dp[n-1][m-1] = 1
for i in range(n-2, -1, -1):
    if grid[i][m-1] == '.':
        dp[i][m-1] = dp[i+1][m-1]
    else:
        dp[i][m-1] = 0
for j in range(m-2, -1, -1):
    if grid[n-1][j] == '.':
        dp[n-1][j] = dp[n-1][j+1]
    else:
        dp[n-1][j] = 0
for i in range(n-2, -1, -1):
    for j in range(m-2, -1, -1):
        if grid[i][j] == '.':
            dp[i][j] = (dp[i+1][j] + dp[i][j+1])%(10**9 + 7)
        else:
            dp[i][j] = 0
print(dp[0][0])

Measured memory_bytes: 43620
#include <iostream>
#include <vector>
#include<algorithm>
#include <string>
#include <set>
#include <limits.h>
#include <map>
#include <queue>
#include <stack>

using namespace std;

#define rip(i,n,s) for (int i=(s);i<(int)(n);i++)
#define all(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<long long, int> P;

void deb(vector<int> &li){
    int x=li.size();
    rip(i,x,0){
        if(i==x-1){
            printf("%d",li[i]);
        }else{
            printf("%d, ",li[i]);
        }
    }
}

int main(){
    int n;
    cin >> n;
    vector<vector<int> > da(n,vector<int>(0));
    vector <bool> ju(n,false);
    rip(i,n,0){
        int x,k,m;
        cin >> m >> k;
        rip(j,k,0){
            cin >> x;
            ju[x]=true;
            da[m].push_back(x);
        }
    }
    int root=0;
    while(ju[root]){
        root++;
    }
    queue<int> q;
    vector<int> parent(n),depth(n,0);
    vector<vector<int> > child(n);
    vector<bool> state(n,false);
    q.push(root);
    while(!q.empty()){
        int no=q.front();
        q.pop();
        int x=da[no].size();
        rip(i,x,0){
            depth[da[no][i]]=depth[no]+1;
            parent[da[no][i]]=no;
            q.push(da[no][i]);
            state[no]=true;
        }
    }
    parent[root]=-1;
    int co=0;
    rip(i,n,0){
        printf("node %d: parent = %d, depth = %d, ",co,parent[i],depth[i]);
        if(i==root){
            printf("root, [");
        }
        else if(!state[i]){
            printf("leaf, [");
        }
        else{
            printf("internal node, [");
        }
        deb(da[i]);
        printf("]\n");
        co++;
    }
}


Measured memory_bytes: 9300
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
long long x, y;
int main() {
	scanf ("%lld%lld", &x, &y);
	long long a = abs(x), b = abs(y);
	if (a > b) {
		if (x >= 0 && y > 0) {
			printf ("%lld", a - b + 2);
			return 0;
		} else if (x >= 0 && y <= 0) {
			printf ("%lld", a - b + 1);
			return 0; 
		} else if (x < 0 && y > 0) {
			printf ("%lld", a - b + 1);
			return 0;
		} else if (x < 0 && y <= 0) {
			printf ("%lld", a - b);
			return 0;
		}
	} else {
		if (x >= 0 && y >= 0) {
			printf ("%lld", b - a);
			return 0;
		} else if (x >= 0 && y < 0) {
			cout << b - a + 1;
			return 0;
		} else if (x < 0 && y >= 0) {
			cout << b - a + 1;
			return 0;
		} else if (x < 0 && y < 0) {
			cout << b - a + 2;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 256
<?php
list($n) = ints();
list($s) = strs();
$cnt = 0;
for ($i = 0; $i <= 9; ++$i) {
    $ipos = strpos($s, (string) $i, 0);
    if ($ipos === false) continue;
    for ($j = 0; $j <= 9; ++$j) {
        $jpos = strpos($s, (string) $j, $ipos + 1);
        if ($jpos === false) continue;
        for ($k = 0; $k <= 9; ++$k) {
            $kpos = strpos($s, (string) $k, $jpos + 1);
            if ($kpos !== false) ++$cnt;
        }
    }
}
echo $cnt;
function strs()
{
    return explode(' ', trim(fgets(STDIN)));
}
function ints()
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}


Measured memory_bytes: 16236
a,b,c=list(map(int,input().split()))
if a<=b:
    if c<=a:
        print(c,a,b)
    elif b<=c:
      print(a,b,c)
    else:
      print(a,c,b)
else:
    if c<=b:
        print(c,b,a)
    elif a<=c:
      print(b,a,c)
    else:
      print(b,c,a)


Measured memory_bytes: 5592
N = int(input())
A = [int(i) for i in input().split()]

for i in range(N):
    A[i] -= i + 1

A.sort()

if N % 2 == 0:
    ans1 = 0
    ans2 = 0
    for a in A:
        ans1 += abs(a - A[N//2])
        ans2 += abs(a - A[N//2 - 1])
    ans = min(ans1, ans2)
else:
    ans = 0
    for a in A:
        ans += abs(a - A[(N - 1) // 2])

print(ans)

Measured memory_bytes: 26180
#include <stdio.h>

using namespace std;
typedef long long llong;

#define MAX

int main()
{
  llong N;

  llong ans = 0;
  scanf("%lld", &N);

  for (llong x = 1; x <= N; x++)
  {
    llong n = N / x;
    ans += n * (2 * x + (n - 1) * x) / 2;
  }

  printf("%lld\n", ans);
  return 0;
}

Measured memory_bytes: 1732
import sys
def S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
INF = 1000000000000

s = S()
t = S()

count = 0
for i in range(len(s)):
    if(s[i] != t[i]):
        count += 1

print(count)

Measured memory_bytes: 67992
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<ctime>
#include<map>
#include<bitset>
#include<set>
#define LL long long
#define mp(x,y) make_pair(x,y)
#define pll pair<long long,long long>
#define pii pair<int,int>
using namespace std;
inline LL read()
{
	LL f=1,x=0;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int stack[20];
template<typename T>inline void write(T x)
{
	if(x<0){putchar('-');x=-x;}
    if(!x){putchar('0');return;}
    int top=0;
    while(x)stack[++top]=x%10,x/=10;
    while(top)putchar(stack[top--]+'0');
}
template<typename T>inline void pr1(T x){write(x);putchar(' ');}
template<typename T>inline void pr2(T x){write(x);putchar('\n');}
const int MAXN=100005;
int n,Q,tp,up;
LL sta[MAXN];
pll lin[MAXN];
multiset<pll> se;
multiset<pll>::iterator it;
LL s[MAXN];
int main()
{
	n=read();Q=read();sta[++tp]=n;
	for(int i=1;i<=Q;i++)
	{
		LL u=read();
		while(tp&&sta[tp]>u)--tp;
		sta[++tp]=u;
	}se.insert(mp(sta[tp],1));
	for(int i=tp-1;i>=1;i--)
	{
		up=0;pll temp=mp(sta[i],0);
		it=se.lower_bound(temp);
		while(it!=se.end())
		{
			pll num=*it;
			temp.second+=num.second*(num.first/temp.first);
			num.first%=temp.first;se.erase(it);
			if(num.first)se.insert(num);it=se.lower_bound(temp);
		}if(!temp.second)++temp.second;
		se.insert(temp);
	}
	for(it=se.begin();it!=se.end();++it)
	{
		pll temp=*it;
		s[temp.first]+=temp.second;
	}
	for(int i=n;i>=1;i--)s[i-1]+=s[i];
	for(int i=1;i<=n;i++)pr2(s[i]);
	return 0;
}

Measured memory_bytes: 9472
#include <iostream>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;

ll lucas(ll n){
  vector<ll> ness(87);
  rep(i,87){
    if(i == 0){
      ness.at(i) = 2;
    }
    else if(i == 1){
      ness.at(i) = 1;
    }
    else{
      ness.at(i) = ness.at(i-1) + ness.at(i-2);
    }
  }
  return ness.at(n);  
}

int main() {
  ll N;
  cin >> N;
  cout << lucas(N) << endl;
}
  
  

Measured memory_bytes: 256
#include<iostream>
#include<utility>
#include<vector>
#include<algorithm>
using namespace std;
typedef pair<int, int> P;

int main() {
	int h, w;
	vector<pair<int, P>> v;
	for (int i = 1; i <= 701; i++) {
		for (int j = i + 1; j <= 701; j++) {
			v.push_back(make_pair(i*i + j*j, P(i, j)));
		}
	}
	sort(v.begin(), v.end());
	while (cin >> h >> w, h, w) {
		for (int i = 0; i < v.size(); i++) {
			if (v[i].second == P(h, w)) {
				cout << v[i + 1].second.first << ' ' << v[i + 1].second.second << endl;
				break;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 5720
#include <bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define RI(X) scanf("%d", &(X))
#define RII(X, Y) scanf("%d%d", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define DRI(X) int (X); scanf("%d", &X)
#define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define RS(X) scanf("%s", (X))
#define CASET int ___T, case_n = 1; scanf("%d ", &___T); while (___T-- > 0)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define VPII vector<pair<int,int> >
#define F first
#define S second
#define RF(x) freopen(x,"r",stdin)
#define WF(x) freopen(x,"w",stdout)
typedef long long LL;
using namespace std;
typedef pair<LL,LL> PLL;
typedef pair<int,int> PII;
const LL MOD = 1e9+7;
const LL INF = 1LL<<30;
const double eps = 1e-13;

int main(){
	LL v0=1,v1=0;
	DRII(n,p);
	REP(i,n){
		DRI(x);
		if(x%2){
			v1=v0=v1+v0;
		}
		else{
			v0*=2;v1*=2;
		}
	}
	if(p)printf("%lld",v1);
	else printf("%lld",v0);
}


Measured memory_bytes: 764
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < n; ++i)
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
#define FORV(i, v) for (auto i = v.begin(); i != v.end(); i++)
using namespace std;

typedef long long ll;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const ll INF = 1e9;
const long long INFL = 1LL<<60;

int main() {
  string s;
  cin >> s;
  bool N = false;
  bool W = false;
  bool S = false;
  bool E = false;

  rep(i, s.size()) {
    if (s[i] == 'N') N = true;
    if (s[i] == 'W') W = true;
    if (s[i] == 'S') S = true;
    if (s[i] == 'E') E = true;
  }

  if ((N && !S) || (!N && S) || (W && !E) || (!W && E)) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <cstring>
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <map>
#include<time.h>
using namespace std;
typedef long long ll;
const int maxn=2e5+10;
const ll mod=1e9+7;
int main(){
	ll n,k;
	cin>>n>>k;
	ll ans=0;
	for (int i=k; i<=n+1; i++) {
		ll r1=n-i+1;
		ll r2=n;
		ll r=(r1+r2)*i/2;
		ll l1=0;
		ll l2=i-1;
		ll l=(l1+l2)*i/2;
		ans+=(r-l+1);
		ans%=mod;
	}
	cout<<ans<<endl;
    return 0;
}


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

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

	int ans = 0;
	while(n > 0){
		ans += n % 10;
		n /= 10;
	}
	
	if(ans == 1) cout << 10 << endl;
	else cout << ans << endl;
}//解説解答参考.

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

using namespace std;
typedef pair<int, int> P;
typedef long long int ll;

const int INF = 1<<30;

int main(){
  int n, k, q;cin>>n>>k>>q;
  vector<int> point(n, k-q);
  while(q--){
    int p;cin>>p;
    point[p-1]++;
  }
  for(auto& e: point)cout<<(e>0?"Yes":"No")<<endl;
  cin>>n;
}


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

using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)

int main()
{
    string s;cin >> s;
    //int s;
    int ans = 1000;
    REP(i,SZ(s)-2){
        string t = s.substr(i, 3);
        int x = stoi(t);
        ans = min(abs(753 - x), ans);
    }

    cout << ans <<"\n";

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v)   (v).begin(),(v).end()
#define INF      (int)1e9
#define MOD      ((int)1e9+7)
using namespace std;
typedef long long     llong;
typedef pair<int,int> pii;
typedef vector<int>   vi;
typedef vector<vi >   vvi;
typedef vector<vvi >  vvvi;
template<class Type> void join(const Type &a){for(auto elem:a)cout<<elem<<' ';cout<<endl;}

int main(){
	llong a,b;
	cin>>a>>b;
	
	llong n=__gcd(a,b);
	llong cnt=0;
	for(llong i=2;i*i<=n;++i){
		if(n%i){}
		else{
			cnt++;
			while(n%i==0) n/=i;
		}
	}
	if(n!=1) cnt++;
	
	cout<<cnt+1<<endl;
}//reply to exp.

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

#define NDEBUG
#ifdef DEBUG
#include "../cout11.h"
#undef NDEBUG
#endif
#include <cassert>

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef pair<double,double> dd;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;

#define sz(a)  int((a).size())
#define pb  push_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c)  (c).rbegin(),(c).rend()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define found(s,e)  ((s).find(e)!=(s).end())
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))

bool solve(string& s) {
    int L=s.size();
    // NWSE
    vector<int> cnt(256,0);
    rep(i,L) {
        cnt[ (int)s[i] ]++;
    }
    if (cnt['N'] > 0 && cnt['S']==0) return false;
    if (cnt['N'] == 0 && cnt['S'] > 0) return false;
    if (cnt['E'] > 0 && cnt['W']==0) return false;
    if (cnt['E'] == 0 && cnt['W'] > 0) return false;
    return true;
}

int main() {
    string s; cin >> s;
    cout << (solve(s) ? "Yes":"No") << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[5][5],n;
bool flag[5][5];
int main()
{
	for(int i=1;i<=3;++i)
		for(int j=1;j<=3;++j)
			scanf("%d",&a[i][j]);
	scanf("%d",&n);
	for(int i=1,tmp;i<=n;++i) {
		scanf("%d",&tmp);
		for(int j=1;j<=3;++j)
			for(int k=1;k<=3;++k)
				if(tmp==a[j][k])
					flag[j][k]=true;
	}
	if(flag[1][1]&&flag[2][2]&&flag[3][3]) {
		printf("Yes");
		return 0;
	}
	if(flag[1][3]&&flag[2][2]&&flag[3][1]) {
		printf("Yes");
		return 0;
	}
	if(flag[1][1]&&flag[1][2]&&flag[1][3]) {
		printf("Yes");
		return 0;
	}
	if(flag[2][1]&&flag[2][2]&&flag[2][3]) {
		printf("Yes");
		return 0;
	}
	if(flag[3][1]&&flag[3][2]&&flag[3][3]) {
		printf("Yes");
		return 0;
	}
	if(flag[1][1]&&flag[2][1]&&flag[3][1]) {
		printf("Yes");
		return 0;
	}
	if(flag[1][2]&&flag[2][2]&&flag[3][2]) {
		printf("Yes");
		return 0;
	}
	if(flag[1][3]&&flag[2][3]&&flag[3][3]) {
		printf("Yes");
		return 0;
	}
	printf("No");
	return 0;
}

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

using namespace std;

#define U 0
#define D 1
#define L 2
#define R 3

class point
{
public:
	int x,y,d;
	point()
	{
		x=y=0;
		d=R;
	}
	void move()
	{
		if(d==R)
		{
			x++;
		}
		else if(d==L)
		{
			x--;
		}
		else if(d==U)
		{
			y--;
		}
		else
		{
			y++;
		}
	}
	char dir()
	{
		if(d==U)
		{
			return 'U';
		}
		else if(d==D)
		{
			return 'D';
		}
		else if(d==L)
		{
			return 'L';
		}
		else
		{
			return 'R';
		}
	}
};

class map
{
public:
	string s[9];
	void input()
	{
		for(int i=0;i<9;i++)
		{
			cin>>s[i];
		}
	}
	int state(int x, int y, int d)
	{
		if(d==U)
		{
			y=2*y-1;
		}
		else if(d==D)
		{
			y=2*y+1;
		}
		else if(d==L)
		{
			x=x-1;
			y=y*2;
		}
		else
		{
			y=y*2;
		}
		if(y<0||y>=9||x<0||x>=s[y].length())
		{
			return 0;
		}
		else{
			return s[y].at(x)-'0';
		}
	}
};

int main(void)
{
	point p;
	map m;
	m.input();
	int dir[4][4]=
	{
		{L,U,R,D},
		{R,D,L,U},
		{D,L,U,R},
		{U,R,D,L}
	};
	while(!(p.d==L&&p.x==0&&p.y==0))
	{
		for(int i=0;i<4;i++)
		{
			if(p.d==i)
			{
				for(int j=0;j<4;j++)
				{
					if(m.state(p.x,p.y,dir[i][j])==1)
					{
						p.d=dir[i][j];
						break;
					}
				}
				break;
			}
		}
		p.move();
		cout<<p.dir();
	}
	cout<<endl;
}

Measured memory_bytes: 1176
#include<iostream>
#include<cstdio>
#include<queue>
#include<vector>
using namespace std;
const int INF=1000000000;
typedef pair<int,int> P;
struct edge{
	int to;
	int cost;
};

int main(){
	bool bo[3000+2];
	fill(bo,bo+3002,false);
	int n,m,k,a,b,l,ans=0;
	P p[3000+2],q;
	vector<edge> ed[3000+2];
	priority_queue<P,vector<P>,greater<P>> que;
	scanf("%d%d%d",&n,&m,&k);
	for(int i=1;i<=n;i++){p[i].first=INF; p[i].second=i;}
	for(int i=0;i<m;i++){
		scanf("%d%d%d",&a,&b,&l);
		edge e;
		e.to=b;
		e.cost=l;
		ed[a].push_back(e);
		e.to=a;
		ed[b].push_back(e);
	}
	for(int i=0;i<k;i++){
		scanf("%d",&a);
		p[a].first=0;
		que.push(p[a]);
	}
	while(!que.empty()){
		q=que.top(); que.pop();
		if(!bo[q.second]){
			bo[q.second]=true;
			int s=ed[q.second].size();
			for(int i=0;i<s;i++){
				if(p[ed[q.second][i].to].first>p[q.second].first+ed[q.second][i].cost){
					p[ed[q.second][i].to].first=p[q.second].first+ed[q.second][i].cost;
					que.push(p[ed[q.second][i].to]);
				}
			}
		}
	}
	for(int i=1;i<=n;i++){
		if(p[i].first>ans)ans=p[i].first;
		int s=ed[i].size();
		for(int j=0;j<s;j++){
			if(ans*2<p[i].first+p[ed[i][j].to].first+ed[i][j].cost)ans=(p[i].first+p[ed[i][j].to].first+ed[i][j].cost+(p[i].first+p[ed[i][j].to].first+ed[i][j].cost)%2)/2;
		}
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 4192
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll m=998244353;
int a[100005];
int b[100005];
ll count(int x,int y);
int main()
{
    int n;
    scanf("%d",&n);
    int flag=1;
    int p=0;
    ll ans=1;
    memset(a,0,sizeof(a));
    memset(b,0,sizeof(b));
    for(int i=0; i<n; i++)
    {
        scanf("%d",&a[i]);

        if(i==0&&a[i]!=0)
            flag=0;
        if(i!=0&&a[i]==0)
            flag=0;
            if(a[i]>p)
           p=a[i];
        b[a[i]]++;
    }
    if(n==1&&a[0]==0)
    {
        flag=2;
    }
    if(flag==0)
    {
        cout<<"0"<<endl;
        return 0;
    }
    if(flag==2)
    {
        cout<<"1"<<endl;
        return 0;
    }
        for(int i=2; i<=p; i++)
        {
            ans=ans*count(b[i-1],b[i])%m;
            if(i<=p)
            {
                if(b[i]==0)
                {
                    cout<<"0"<<endl;
                    return 0;
                }
            }
        }
    cout<<ans<<endl;
}
ll count(int x,int y)
{
    ll r=1;
    for(int i=1; i<=y; i++)
    {
        r=r*x%m;
    }
    return r;

}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vecll = vector<long long>;
#define all(c) (c).begin(), (c).end()
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)

int main()
{
    ll q, que, x, y;
    set<ll> S;
    cin >> q;

    rep(i, q)
    {
        cin >> que >> x;
        if (que == 0)
            S.insert(x);
        else if (que == 2)
        {
            S.erase(x);
            continue;
        }
        else if (que == 3)
        {
            cin >> y;
            //delctype(S)
            set<ll>::iterator first_itr = S.lower_bound(x);
            set<ll>::iterator end_itr = S.upper_bound(y);

            for (auto i = first_itr; i != end_itr; ++i)
                cout << *i << endl;

            /*for (int i = x; i <= y; i++)
            {
                if (S.find(i) != S.end())
                {
                    cout << *S.find(i) << endl;
                }
            }*/

                /*for(struct { ll i; int j;} s = { x, 0} ; s.i <= y ; ++s.i , ++s.j)
            {
                if (S.find(s.i) != S.end())
                {
                    //cout << (s.j ? " " : "");
                    cout << *S.find(s.i) << endl;
                }
            }*/
                continue;
        }

        cout << (que ? S.count(x) : S.size()) << endl;
    }
    return 0;
}


Measured memory_bytes: 12436
#include<iostream>
#include<algorithm>
#include<math.h>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)
const double eps=1e-10;
double adj[21][21];
double hero[20];
bool visited[20]={false};
#define MAOU 20

bool backTrack(int last,double r,int now,int n,
	   bool *visited){
  rep(i,n){
    if ( visited[i]==false && adj[MAOU][i]<=r)return false;
    if ( visited[i]==false &&  adj[MAOU][i]<=r+adj[last][i])return false;
  }
  if ( now == n)return true;
  
  rep(i,n){
    if ( visited[i]==true)continue;
    visited[i]=true;
    if ( backTrack(i,r+adj[last][i],now+1,n,visited))return true;
    visited[i]=false;
  }
  return false;
}

double dist(int x,int y){
  return sqrt(x*x+y*y);
}

int solve(int n,int *x,int *y,int rx,int ry,int mx,int my){
  rep(i,n){
    adj[i][i]=0;
    adj[MAOU][i]=adj[i][MAOU]=dist(x[i]-rx,y[i]-ry);
    REP(j,i+1,n){
      adj[i][j]=adj[j][i]=dist(x[i]-x[j],y[i]-y[j]);
    }
    hero[i]=dist(mx-x[i],my-y[i]);
    if ( hero[i]+eps>adj[MAOU][i])return false;
    visited[i]=false;
  }
  
  rep(i,n){
    visited[i]=true;
    if ( backTrack(i,hero[i],1,n,visited))return true;
    visited[i]=false;
  }
  return false;
}

main(){
  int n,mx,my,rx,ry;
  while(scanf("%d%d%d%d%d",&n,&mx,&my,&rx,&ry) && n){
    int x[n],y[n];
    rep(i,n)scanf("%d%d",&x[i],&y[i]);
    if ( solve(n,x,y,rx,ry,mx,my))puts("YES");
    else puts("NO");
  }
}

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

void prians(bool answer) {
  if(answer)
    cout << "Possible" << endl;
  else
    cout << "Impossible" << endl;
}
int a, b;

int main() {
  cin >> a >> b;
  prians(a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0);
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
#include <iomanip>
#include <math.h>
#include <string>
#include <queue>
#include <map>
#include <set>
#include <functional>

using namespace std;

typedef long long int ll;
typedef std::pair<int, int> pii;
typedef std::pair<ll, int> pli;
typedef std::pair<ll, ll> pll;

#define FOR(i,n,m) for(ll i=(ll)(m);i<(ll)(n);++i)
#define REP(i,n) FOR(i,n,0)
#define IREP(i,n) for(ll i=(ll)(n);i>=0;--i)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

int main()
{
	int A, B, C;
	cin >> A >> B >> C;
	string s = "Yes";
	if (A + B < C)
	{
		s = "No";
	}
	cout << s << endl;
	return 0;
}

Measured memory_bytes: 256
def main():
  from itertools import groupby
  s, n = list(input()), int(input())
  f = False
  for k,v in groupby(s):
    if f:
      print(k)
      break
    if k == '1' and len(list(v)) >= n:
      print(1)
      break
    elif k != '1':
      print(k)
      break
    else:
      f = True

if __name__ == '__main__':
  main()

Measured memory_bytes: 3060
n=gets.to_i
s=gets.split.map &:to_i
max=s[0]
for i in 1..n-1
  s[i]= max<s[i]? s[i]-1:s[i]
  dame=1 if max>s[i]
  max=s[i]
end
puts dame==1? :No : :Yes


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

#define ll long long
using namespace std;

const int N = 1005, M = 1e9 + 7;
int n, m;
string s[N];
ll dp[N][N];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> m;
    for(int i = 0; i < n; i++) cin >> s[i];
    dp[0][1] = 1;
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= m; j++) {
            if(s[i - 1][j - 1] == '#') dp[i][j] = 0;
            else {
                dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % M;
            }
        }
    }
    cout << dp[n][m] << endl;
}

Measured memory_bytes: 9216
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <queue>
#include <map>
#include <vector>
#include <set>
#include <cstdlib>
#include <stack>

using namespace std;

typedef long long LL;
#define FAST ios::sync_with_stdio(false);
const int MaxN = 15;

int main()
{
	int n , k , x, y;
	LL  ans = 0;
	scanf("%d%d%d%d",&n,&k,&x,&y);
	if(n >= k)
	{
	for(int i = 1 ; i <= k;i++)
		ans += x;
		for(int i = 1 ; i <= n-k;i++)
		ans += y;
	}
	else 
	for(int i = 1 ; i <=  n ; i++)
		ans += x;
		cout << ans << endl;
	return 0;
	}

Measured memory_bytes: 256
//%std
#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
typedef long long ll;
inline int read()
{
	int out=0,fh=1;
	char jp=getchar();
	while ((jp>'9'||jp<'0')&&jp!='-')
		jp=getchar();
	if (jp=='-')
		fh=-1,jp=getchar();
	while (jp>='0'&&jp<='9')
		out=out*10+jp-'0',jp=getchar();
	return out*fh;
}
const int MAXN=329;
int a[MAXN][MAXN],ans[MAXN][MAXN],flag[MAXN];
bool vis[MAXN];
int n,m,k,t=0;
char buf[MAXN];
int tmp[MAXN],cnt;
int fa[MAXN];
void solve(int x)
{
	fa[x]=x;
	cnt=0;
	for(int y=1;y<=m;++y)
		if(a[x][y])
			tmp[++cnt]=y;
	if(cnt==1)
	{
		++t;
		for(int y=1;y<=m;++y)
			ans[x][y]=t;
	}
	else
	{
		++t;
		for(int y=1;y<tmp[2];++y)
			ans[x][y]=t;
		for(int p=2;p<=cnt;++p)
		{
			int l=tmp[p],r=(p==cnt)?m:tmp[p+1]-1;
			++t;
			for(int y=l;y<=r;++y)
				ans[x][y]=t;
		}
	}
}
int main()
{
	n=read(),m=read(),k=read();
	for(int i=1;i<=n;++i)
	{
		scanf("%s",buf+1);
		for(int j=1;j<=m;++j)
			if(buf[j]=='#')
			{
				a[i][j]=1;
				flag[i]=1;
			}
	}
	for(int i=1;i<=n;++i)
		if(flag[i])
			solve(i);
	cnt=0;
	for(int i=1;i<=n;++i)
		if(flag[i])
			tmp[++cnt]=i;
	if(cnt==1)
	{
		for(int i=1;i<=n;++i)
			fa[i]=tmp[1];
	}
	else
	{
		for(int i=1;i<tmp[2];++i)
			fa[i]=tmp[1];
		for(int p=2;p<=cnt;++p)
		{
			int l=tmp[p],r=(p==cnt)?n:tmp[p+1]-1;
			for(int i=l;i<=r;++i)
				fa[i]=tmp[p];
		}
	}
	for(int i=1;i<=n;++i,puts(""))
		for(int j=1;j<=m;++j)
			printf("%d ",ans[fa[i]][j]);
	return 0;
}


Measured memory_bytes: 1536
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        n: usize,
        k: usize,
    };

    let mut vl = vec![];
    let mut vr = vec![];
    for _ in 0..k {
        input! {
            l: usize,
            r: usize,
        }

        vl.push(l);
        vr.push(r);
    }

    let mut dp: Vec<usize> = vec![0; n + 1];
    let mut dp_sum: Vec<usize> = vec![0; n + 1];
    dp[1] = 1;
    dp_sum[1] = 1;

    for i in 2..=n {
        for j in 0..k {
            let li = std::cmp::max(i as i32 - vr[j] as i32, 1);
            if i < vl[j] {
                continue;
            }
            let ri = i - vl[j];

            dp[i] += dp_sum[ri] - dp_sum[li as usize - 1];
            dp[i] %= 998244353;
        }
        dp_sum[i] = dp[i] + dp_sum[i - 1];
    }

    println!("{}", dp[n]);
}


Measured memory_bytes: 5228
#include <iostream>
using namespace std;
char moji[8][8], stand[8][8];
int h, w;

void dfs(int i, int j) {
  stand[i][j] = 1;
  // right
  if (j + 1 < w) {
    if (moji[i][j + 1] == '#') {
      dfs(i, j + 1);
      return ;
    }
  }
  if (i + 1 < h) {
    if (moji[i + 1][j] == '#') {
      dfs(i + 1, j);
      return;
    }
  }
}

int main () {
  cin >> h >> w;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cin >> moji[i][j];
      stand[i][j] = 0;
    }
  }
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (moji[i][j] == '#') {
        // dfs start
        dfs(i, j);
        for (int p = 0; p < h; p++) {
          for (int q = 0; q < w; q++) {
            if (moji[p][q] == '#') {
              if (stand[p][q] == 0) {
                cout << "Impossible" << endl;
                return 0;
              }  
            }
          }
        }
        cout << "Possible" << endl;
        return 0;
      }
    }
  }
}

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

int H, W;
string masu[50];

int bomb(int h, int w){
      
    if( h < 0 || h > H-1 || w < 0 || w > W-1 )
      return 0;
      
    if( masu[h][w] == '#' )
      return 1;
    else
      return 0;

}

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

  for(int i = 0; i < H; i++){
        cin >> masu[i];
  }

  for(int h = 0; h < H; h++){
      for(int w = 0; w < W; w++){

          if( masu[h][w] == '.' ){     
              int sum = bomb(h-1,w-1) + bomb(h-1, w) + bomb(h-1, w+1) + bomb(h, w-1) 
                      + bomb(h, w+1) + bomb(h+1, w-1) + bomb(h+1, w) + bomb(h+1, w+1);   
              cout << sum;
          }else{
              cout << "#";
          }


      }

      cout << endl;
  }


}




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

int main() {
  int a, b, h, m;
  cin >> a >> b >> h >> m;
  double s = 0;
  s = ((h * 60 + m) * 5.5) / 360 * 2 * 3.14159265358979;
  cout << fixed << setprecision(16);
  cout << sqrt(a * a + b * b - 2 * a * b * cos(s)) << endl;
}

Measured memory_bytes: 4216
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
//#include <utility>
#include <set>
#include <iostream>
//#include <memory>
#include <string>
#include <vector>
#include <algorithm>
//#include <functional>
#include <sstream>
//#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
//#include <cctype>
#include <cstring>
//#include <ctime>
#include <iterator>
#include <bitset>
//#include <numeric>
//#include <list>
//#include <iomanip>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <unordered_set>
#include <unordered_map>
#include <forward_list>

#define cauto const auto&
#else

#endif

using namespace std;


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

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}


#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define F first
#define S second
#define mkp make_pair
#define RALL(v) (v).rbegin(),(v).rend()


#define MOD 1000000007LL
#define EPS 1e-8
static const int INF=1<<24;

class UF {
	public:
	static const int ufmax=100052;
	int ufpar[ufmax],ufrank[ufmax],ufcnt[ufmax];
	UF() { init();}
	void init(){int i; rep(i,ufmax) { ufpar[i]=i; ufrank[i]=0; ufcnt[i]=1; } }
	int find(int x) {	return (ufpar[x]==x)?(x):(ufpar[x] = find(ufpar[x]));}
	int operator[](int x) {return find(x);}
	int count(int x) {return ufcnt[find(x)];}
	void unite(int x,int y) {
		x = find(x); y = find(y);
		if(x==y) return;
		if(ufrank[x]<ufrank[y]) ufpar[x]=y, ufcnt[y]+=ufcnt[x];
		else {ufpar[y]=x; ufcnt[x]+=ufcnt[y]; if(ufrank[x]==ufrank[y]) ufrank[x]++;}
	}
};


void mainmain(){
	int n,m;
	while(cin>>n>>m,n||m){
		UF uf;
		priority_queue<pair<int,pii>> pq;
		rep(i,m){
			int a,b,c;
			cin>>a>>b>>c;
			pq.push(mkp(-c,mkp(a,b)));
		}
		int ans=0;
		while(!pq.empty()){
			pair<int,pii> top=pq.top();
			pq.pop();
			if(uf[top.S.F]!=uf[top.S.S]){
				ans+=-top.F;
				uf.unite(top.S.F,top.S.S);
			}
		}
		cout<<ans<<endl;
	}
}



}
main() try{
    mainmain();
}
catch(...){
}

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

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

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

typedef long long ll;
typedef pair<int, int> P;

const int MAX = 200005;
const int INF = 1001001001;
const int MOD = 1000000007;

struct mint {
    long long x;
    mint(long long x=0):x(x % MOD + (0 <= x ? 0 : MOD)) {}
    mint operator-() const { return mint(-x); }
    mint& operator+=(const mint& a) { if ((x += a.x) >= MOD) x -= MOD; return *this; }
    mint& operator-=(const mint& a) { if ((x -= a.x) < 0) x += MOD; return *this; }
    mint& operator*=(const mint& a) { (x *= a.x) %= MOD; return *this; }
    mint operator+(const mint& a) const { return mint(x) += a; }
    mint operator-(const mint& a) const { return mint(x) -= a; }
    mint operator*(const mint& a) const { return mint(x) *= a; }

    // for prime mod
    mint inv() const {
        long long a = x, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        return mint(u);
    }
    mint& operator/=(const mint& a) { return *this *= a.inv(); }
    mint operator/(const mint& a) const { return mint(x) /= a; }
};
istream& operator>>(istream& is, const mint& a){ return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a){ return os << a.x; }

struct Combination{
    vector<long long> fac, finv, inv;
    Combination(int n=1001001):fac(n+1), finv(n+1), inv(n+1) {
        fac[0] = fac[1] = 1;
        finv[0] = finv[1] = 1;
        inv[1] = 1;
        for (int i = 2; i <= n; i++){
            fac[i] = fac[i - 1] * i % MOD;
            inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
            finv[i] = finv[i - 1] * inv[i] % MOD;
        }
    }
    long long operator()(int n, int k) const {
        if (n < k || n < 0 || k < 0) return 0;
        return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
    }
};

int main(){
    int N, M;
    cin >> N >> M;

    Combination c(M);
    auto p = [&](int a, int b){
        return c.fac[a] * c.finv[a-b] % MOD;
    };

    mint ans = 0;
    rep(i, N+1) {
        mint x = p(M, i);
        mint y = p(M-i, N-i);
        mint z = c(N, i);
        if (i % 2 == 0) {
            ans += x * y*y * z;
        } else {
            ans -= x * y*y * z;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 14812
#include<bits/stdc++.h>
using namespace std;
#ifndef ONLINE_JUDGE
#define dbg(x...) do { cout << "\033[32;1m " << #x << " -> "; err(x); } while (0)
void err() { cout << "\033[39;0m" << endl; }
template<template<typename...> class T, typename t, typename... A>
void err(T<t> a, A... x) { for (auto v: a) cout << v << ' '; err(x...); }
template<typename T, typename... A>
void err(T a, A... x) { cout << a << ' '; err(x...); }
#else
#define dbg(...)
#endif
typedef long long ll;
typedef pair<int,int> pi;
typedef vector<int> vi;
template<class T> using vc=vector<T>;
template<class T> using vvc=vc<vc<T>>;
template<class T> void mkuni(vector<T>&v)
{
    sort(v.begin(),v.end());
    v.erase(unique(v.begin(),v.end()),v.end());
}
template<class T>
void print(T x,int suc=1)
{
    cout<<x;
    if(suc==1) cout<<'\n';
    else cout<<' ';
}
template<class T>
void print(const vector<T>&v,int suc=1)
{
    for(int i=0;i<v.size();i++)
    print(v[i],i==(int)(v.size())-1?suc:2);
}
int a[20];
ll dp[20][20][2][2][2];
ll dfs(int l,int r,int zero=1,int lup=0,int rup=0)
{
    if(l<=r)
    {
        if(l==r)
            return (10*lup-rup==a[l])*10;
        return lup==rup;
    }
    ll &ret=dp[l][r][zero][lup][rup];
    if(ret!=-1) return ret;
    ret=0;
    for(int i=zero;i<10;i++)
    {
        for(int j=0;j<10;j++)
        {
            if(j-i+lup*10==a[l]&&i-j-rup==a[r])
                ret+=dfs(l-1,r+1,0,0,0);
            else if(j-i+lup*10==a[l]&&i-j+10-rup==a[r])
                ret+=dfs(l-1,r+1,0,0,1);
            else if(j-i+lup*10-1==a[l]&&i-j-rup==a[r])
                ret+=dfs(l-1,r+1,0,1,0);
            else if(j-i+lup*10-1==a[l]&&i-j+10-rup==a[r])
                ret+=dfs(l-1,r+1,0,1,1);
        }
    }
    return ret;
}
ll solve(int len,int D)
{
    memset(dp,-1,sizeof(dp));
    int p=0;
    while(D)
    {
        a[p++]=D%10;
        D/=10;
    }
    return dfs(len-1,0);
}
int main()
{
    int D;
    cin>>D;
    int tmp=D;
    int cc=0;
    while(tmp)
    {
        tmp/=10;
        cc++;
    }
    ll ans=0;
    for(int i=19;i>=cc;i--)
        ans+=solve(i,D);
    cout<<ans<<'\n';
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
bool SecondCompare(const pair<int,int> &a,const pair<int,int> &b)
{
       return a.second<b.second;
}
 
bool SecondCompareDes(const pair<int,int> &a,const pair<int,int> &b)
{
       return a.second>b.second;
}
 
long long n, comp;
string s;
int ar[16];
int ans, le;
bool flag = true;
int main(){
    cin >> s;
    n = stoll(s);
    le = s.length();
    for(int i = 0; n >= 10; n /= 10)  if(n%10 != 9) flag = false;
    ans = (le-1)*9;
    if(flag)    ans += (int)s[0] - '0';
    else    ans += (int)(s[0]-'0')-1;
    cout << ans << endl;
}

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

int main() {

    int k; cin >> k;
    string s; cin >> s;
    string ans;
    if (s.size() <= k) ans = s;
    else {
        ans = s.substr(0, k);
        ans += "...";
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3572
#include <stdio.h>
int main(){
  int a,b;
  scanf("%d %d",&a,&b);
  if(a<b){
    printf("a < b\n");
  } else if(a>b){
    printf("a > b\n");
  } else if(a==b){
    printf("a == b\n");
  }
  return 0;
}

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

using Vi = vector<int>;
using Vs = vector<string>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
typedef pair<int, int> P;
typedef long long ll;

const int INF = 10000000, MAX_N = 200000, MAX_M = 1000, MAX_W = 10000;

int asc(const void* a, const void* b) {
    return *(int*)a - *(int*)b;
}


int main() {
    int n, k;
    cin >> n >> k;
    int health[MAX_N];
    rep(i, n) health[i] = 0;
    rep(i, n) cin >> health[i];

    qsort(health, n, sizeof(int), asc);

    ll ans = 0;
    if (n < k) {
        cout << 0 << endl;
    }
    else {
        rep(i, n - k) {
            ans += health[i];
        }

        cout << ans << endl;
    }
}

Measured memory_bytes: 1788
while (m, f, r = gets.split(" ").map(&:to_i)) != [-1, -1, -1] do
  tmp = m + f
  if m == -1 or f == -1
    puts "F"
  elsif tmp >= 80
    puts "A"
  elsif tmp >= 65
    puts "B"
  elsif tmp >= 50
    puts "C"
  elsif tmp >= 30
    if r >= 50
      puts "C"
    elsif
      puts "D"
    end
  elsif
    puts "F"
  end
end

Measured memory_bytes: 8660
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>

static const int INF = 1000000007;
using ll = long long;
using u32 = unsigned;
using namespace std;

int main() {
    int a, b, ans = 0;
    cin >> a >> b;
    for (int i = a; i <= b; ++i) {
        string k = to_string(i);
        if(k[0] == k[4] && k[1] == k[3]) ans++;
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define F first
#define S second
#define X real()
#define Y imag()
using namespace std;
typedef long long ll;
typedef long double ld;

int aps[2020];
int dp[2020][2020];
int n,k;
vector<int> g[2020];

int v;

int dfs(int x, int p){
	aps[x]=1;
	int ml=0;
	for (int nx:g[x]){
		if (nx!=p){
			int asd=dfs(nx, x);
			ml=max(ml, asd);
			aps[x]+=aps[nx];
		}
	}
	for (int i=0;i<=n;i++){
		dp[x][i]=n;
	}
	for (int le=0;le<=ml&&le<=k;le++){
		int o=min(k-le, le);
		int ms=0;
		int su=0;
		for (int nx:g[x]){
			if (nx!=p){
				int c1,c2;
				if (le==0) c1=dp[nx][0]+1;
				else c1=dp[nx][le-1];
				if (o==0) c2=dp[nx][0]+1;
				else c2=dp[nx][o-1];
				su+=c2;
				ms=max(ms, c2-c1);
			}
		}
		su-=ms;
		dp[x][le]=su;
	}
	for (int i=1;i<=n;i++){
		dp[x][i]=min(dp[x][i-1], dp[x][i]);
	}
	for (int i=0;i<=n;i++){
		if (i<=k) v=min(v, n-aps[x]+dp[x][i]);
	}
	return ml+1;
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin>>n>>k;
	for (int i=0;i<n-1;i++){
		int a,b;
		cin>>a>>b;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	v=n;
	dfs(1, 0);
	cout<<v<<endl;
}

Measured memory_bytes: 16256
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<math.h>
#include<queue>
#include<functional>
#include<limits.h>
#include<string.h>
#include<set>
using namespace std;
#define P pair<int,int>
#define MOD 1000000007
#define INF 11234567890
#define in std::cin
#define out std::cout
#define rep(i,N) for(LL i=0;i<N;++i)
typedef long long int LL;

const LL MAX_V = 20000;
class Dinic
{
	// 辺を表す構造体（行先、容量、逆辺）
	struct edge { LL to, cap, rev; };

	std::vector<edge>G[MAX_V];	// グラフの隣接リスト表現
	LL level[MAX_V];			// sからの距離
	LL iter[MAX_V];				// どこまで調べ終わったか

public:
	// fromからtoへ向かう容量capの辺をグラフに追加する
	void add_edge(LL from, LL to, LL cap)
	{
		G[from].push_back({ to, cap, G[to].size() });
		G[to].push_back({ from,0,G[from].size() - 1 });
	}

	// sからの最短距離をBFSで計算する
	void bfs(LL s)
	{
		memset(level, -1, sizeof(level));
		std::queue<LL>que;
		level[s] = 0;
		que.push(s);
		while (!que.empty())
		{
			LL v = que.front(); que.pop();
			for (auto i : G[v])
			{
				edge &e = i;
				if (e.cap > 0 && level[e.to] < 0)
				{
					level[e.to] = level[v] + 1;
					que.push(e.to);
				}
			}
		}
	}

	// 増加パスをDFSで探す
	LL dfs(LL v, LL t, LL f)
	{
		if (v == t) { return f; }
		for (LL &i = iter[v]; i < G[v].size(); ++i)
		{
			edge &e = G[v][i];
			if (e.cap > 0 && level[v] < level[e.to])
			{
				LL d = dfs(e.to, t, std::min(f, e.cap));
				if (d > 0)
				{
					e.cap -= d;
					G[e.to][e.rev].cap += d;
					return d;
				}
			}
		}
		return 0;
	}

	// sからtへの最大流を求める
	LL max_flow(LL s, LL t)
	{
		LL flow = 0;
		while (true)
		{
			bfs(s);
			if (level[t] < 0) { return flow; }
			memset(iter, 0, sizeof(iter));
			LL f;
			while ((f = dfs(s, t, INF)) > 0) { flow += f; }
		}
	}
};

int N, G, E, p[20000], a[112345], b[112345];
Dinic tree;

signed main() {
	int S[100][100];//番号
	int a, b; cin >> a >> b;
	memset(S, -1, sizeof(S));
	string c[100];
	P s, g;
	int sum = 2;
	for (int i = 0; i < a; i++) {
		cin >> c[i];
		for (int j = 0; j < b; j++) {
			if (c[i][j] == 'S') {
				s = { i,j };
				S[i][j] = 0;
				tree.add_edge(0, 1, 1);
			}
			else if (c[i][j] == 'T') {
				g = { i,j };
				S[i][j] = 1;
				tree.add_edge(2, 3, 1);
			}
			else if (c[i][j] == 'o') {
				S[i][j] = sum++;
				tree.add_edge(S[i][j] * 2+1, S[i][j] * 2,1);
			}
		}
	}
	if (s.first == g.first || s.second == g.second) {
		puts("-1");
		return 0;
	}
	for (int i = 0; i < a; i++) {
		for (int j = 0; j < b; j++) {
			if (S[i][j] != -1) {
				for (int k = i + 1; k < a; k++) {
					if (S[k][j] != -1) {
						tree.add_edge(S[i][j]*2, S[k][j]*2+1, 1);
						tree.add_edge(S[k][j]*2, S[i][j]*2+1, 1);
					}
				}
				for (int k = j + 1; k < b; k++) {
					if (S[i][k] != -1) {
						tree.add_edge(S[i][j]*2, S[i][k]*2+1, 1);
						tree.add_edge(S[i][k]*2, S[i][j]*2+1, 1);
					}
				}
			}
		}
	}
	cout << tree.max_flow(0, 3) << endl;
}

Measured memory_bytes: 125184
#include <bits/stdc++.h>
using namespace std;
const int N=1e5+5;
#define ll long long
int main() 
{
	string s;
	cin>>s;
	int l=s.length();
	set<char> st;
	for(int i=0;i<l;i++)
		st.insert(s[i]);
	if(st.size()!=l)
		cout<<"no"<<endl;
	else 
		cout<<"yes"<<endl;
	return 0;
}

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

#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)

const int mod=1000000007;
int dp[70][70][6100];
void solve(){
    int n,k;cin>>n>>k;
    vector<int> ra(n+1);
    vector<int> rr(k+1);
    vector<int> rb(k+1);
    vector<int> a(n);
    vector<int> r(k),b(k);
    rep(i,n){
        cin>>a[i];
    }
    rep(i,k){
        cin>>r[i];
    }
    rep(i,k){
        cin>>b[i];
    }
    sort(a.begin(),a.end(),greater<int>());
    sort(r.begin(),r.end(),greater<int>());
    sort(b.begin(),b.end(),greater<int>());
    rep(i,n){
        ra[i+1]=ra[i]+a[i];
    }
    rep(i,k){
        rr[i+1]=rr[i]+r[i];
        rb[i+1]=rb[i]+b[i];
    }
    rep(i,n+1){
        rep(j,k+1){
            rep(l,6100){
                dp[i][j][l]=mod;
            }
        }
    }
    dp[0][0][3010]=0;
    rep(i,n){
        rep(j,k+1){
            int rest=i-j;
            if(rest<0||rest>k)continue;
            rep(l,6100){
                if(dp[i][j][l]==mod)continue;
                //take red
                if(j<k){
                    int dif=r[j]-a[i];
                    int cost=max(0,-dif);
                    dp[i+1][j+1][l+dif]=min(dp[i+1][j+1][l+dif],dp[i][j][l]+cost);
                }
                //take blue
                if(rest<k){
                    int dif=b[rest]-a[i];
                    int cost=max(0,-dif);
                    dp[i+1][j][l]=min(dp[i+1][j][l],dp[i][j][l]+cost);
                }
            }
        }
    }
    int ans=mod;
    rep(j,k+1){
        int rest=n-j;
        if(rest<0)continue;
        if(rest>k)continue;
        rep(l,6100){
            int x=l-3010;
            if(x+rr[k]-rr[j]<0)continue;
            int bb=rr[j]-x+rb[rest]-ra[n];
            if(bb+rb[k]-rb[rest]<0)continue;

            ans=min(ans,dp[n][j][l]);

        }
    }
    if(ans==mod)ans=-1;
    cout<<ans<<endl;

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


Measured memory_bytes: 92108
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define INF 1000000007
const int maxn=2e5+10;
ll n,k,a[maxn];

int main(){
	ios::sync_with_stdio(false);
	cin>>n>>k;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	for(int i=k;i<n;i++){
		if(a[i-k]<a[i])cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
	}
	return 0; 
}


Measured memory_bytes: 5208
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<queue>
#include<map>
#include<stack>
#include<sstream>
using namespace std;
const int INF = 0x3f3f3f3f;
const int maxn = 1e5+9;
int main()
{
    int n,k,ans = INF;
    scanf("%d%d",&n,&k);
    int h[maxn];
    for(int i = 0; i < n; i ++)scanf("%d",&h[i]);
    sort(h,h+n);
    int t = n-k;
    for(int i = 0; i <= t; i ++)ans = min(h[k+i-1]-h[i],ans);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 640