akhauriyash/Code-Regression huggingface dataset:
/*
*/

#pragma comment(linker, "/STACK:16777216")
#define _CRT_SECURE_NO_WARNINGS

#include <fstream>
#include <iostream>
#include <string>
#include <complex>
#include <math.h>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <stdio.h>
#include <stack>
#include <algorithm>
#include <list>
#include <ctime>
#include <memory.h>
#include <assert.h>

#define y0 sdkfaslhagaklsldk
#define y1 aasdfasdfasdf
#define yn askfhwqriuperikldjk
#define j1 assdgsdgasghsf
#define tm sdfjahlfasfh
#define lr asgasgash
#define norm asdfasdgasdgsd
#define have adsgagshdshfhds

#define eps 1e-9
#define M_PI 3.141592653589793
#define bs 1000000007
#define bsize 350

using namespace std;

const int INF = 1e9;
const int N = 220031;

int n;
int ar[N];

int main(){
	//freopen("fabro.in","r",stdin);
	//freopen("fabro.out","w",stdout);
	//freopen("F:/in.txt", "r", stdin);
	//freopen("F:/output.txt", "w", stdout);
	ios_base::sync_with_stdio(0);
	//cin.tie(0);

	cin >> n;
	for (int i = 1; i <= n; i++)
	{
		cin >> ar[i];
	}

	int cur_bound = 0;

	long long ans = 0;

	for (int i = 1; i <= n; i++)
	{
		if (ar[i]<=cur_bound+1)
		{
			cur_bound = max(cur_bound, ar[i]);
			continue;
		}
		int T = 1;
		int ohead = ar[i] - 1;
		int times = ohead / (cur_bound+1);
		ans += times;
		ar[i] = T;
	//	cout << i<<" "<<ar[i] << "%" << T << " " << ohead << " " << times << endl;
		cur_bound = max(cur_bound, ar[i]);
	}

	cout << ans << endl;

	cin.get(); cin.get();
	return 0;
}

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

typedef struct Node{
  int value, priority;
  Node *left, *right;
} Node;

Node* Delete(Node *, int);
Node* _delete(Node *, int);

Node *NIL,*root;

Node* rightRotate(Node *t){
  Node *s = t->left;
  t->left = s->right;
  s->right = t;
  return s;
}
Node* leftRotate(Node *t){
  Node *s = t->right;
  t->right = s->left;
  s->left = t;
  return s; 
}
Node* makenode(int key, int priority){
  Node *node = (Node *)malloc(sizeof(Node));
  node->value = key;
  node->priority = priority;
  node->left = node->right = NIL;
  return node;
}

Node* insert(Node *t, int key, int priority){    
  Node *x;

  if(t == NIL) return x = makenode(key, priority); 

  if(key == t->value) return t;                

  if(key < t->value){                          
    t->left = insert(t->left, key, priority); 
    if(t->priority < t->left->priority) t = rightRotate(t); 
  }else{                                      
    t->right = insert(t->right, key, priority); 
    if(t->priority < t->right->priority) t = leftRotate(t); 
  }

  return t;
}
Node* find(Node *x, int k){
  if(x == NIL || x->value == k) return x;

  if(k < x->value) return find(x->left, k);
  else return find(x->right, k);
}
Node* Delete(Node *t, int key){
  if(t == NIL) return NIL;
  if(key < t->value) t->left = Delete(t->left, key); 
  else if(key > t->value) t->right = Delete(t->right, key);
  else return _delete(t, key);
  return t;
}

Node* _delete(Node *t, int key){ 
  if(t->left == NIL && t->right == NIL) return NIL; 
  else if(t->left == NIL) t = leftRotate(t);   
  else if(t->right == NIL) t = rightRotate(t); 
  else{                                     
    if(t->left->priority > t->right->priority) t = rightRotate(t); 
    else t = leftRotate(t);
  }
  return Delete(t, key);
}

void preParse(Node *node){
  if(node == NIL) return ;

  cout<<" "<< node->value;
  if(node->left != NIL) preParse(node->left);
  if(node->right != NIL) preParse(node->right);
}

void inParse(Node *node){
  if(node == NIL) return ;

  if(node->left != NIL) inParse(node->left);
  cout<<" "<<node->value;
  if(node->right != NIL) inParse(node->right);
}

int main(){
  int n,key,priority;
  string command;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>command;
    if(command=="insert"){
      cin>>key>>priority;
      root=insert(root,key,priority);
    }else if(command=="print"){
      inParse(root);
      cout<<endl;
      preParse(root);
      cout<<endl;
    }else if(command=="find"){
      cin>>key;
      if(find(root,key)) cout<<"yes"<<endl;
      else cout<<"no"<<endl;
    }else if(command=="delete"){
      cin>>key;
      root=Delete(root,key);
    }
  }
  return 0;
}


Measured memory_bytes: 9456
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <cassert>
#include <exception>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<P> vp;
#define rep(i,a,n) for(ll i = (a);i < (n);i++)
#define per(i,a,n) for(ll i = (a);i > (n);i--)
#define lep(i,a,n) for(ll i = (a);i <= (n);i++)
#define pel(i,a,n) for(ll i = (a);i >= (n);i--)
#define clr(a,b) memset((a),(b),sizeof(a))
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define sz size()
#define print(X) cout << (X) << endl
const ll INF = 1e+9+7;
ll n,m,l;
string s,t;
ll d[200010],dp[500][500];

int main(){
  cin >> s;
  t = "";
  rep(i,0,s.sz){
    if(s[i] == 'A'){
      pel(j,s.sz-1,i){
        if(s[j] == 'Z'){
          lep(k,i,j)t += s[k];
          break;
        }
      }
    }
    if(t != "")break;
  }
  print(t.sz);
  return 0;
}

Measured memory_bytes: 776
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n, l; cin >> n >> l;
	int sum = 0, mn = 1<<30;
	for(int i = 1; i <= n; i++){
		sum += l + i - 1;
		if(abs(mn) > abs(l + i - 1)) mn = l + i - 1;
	}
	cout << sum - mn << endl;
	return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<cmath>
#include<string>

#define ls (t<<1)
#define rs ((t<<1)+1)
#define mid ((l+r)>>1)
#define fi first
#define se second
#define mk make_pair
#define pb push_back

#define N 100005
#define M 500005
#define seed 23333

using namespace std;
set<pair<int,int> >st;
multiset<int>str;
vector<pair<int,int> >v[M];
vector<int>alb[M];
int i,j,m,n,p,k,C[N],A[N],B[N],D[M],Ans,F[M],f[M],vis[N],X[N],Y[N],Q;
int ans[M];
void RE()
{
		for (i=1;i<=Q;++i) puts("-1");
		exit(0); 
}
int main()
{
	 scanf("%d",&n); Ans=n;
	 for (i=1;i<=n;++i) scanf("%d%d",&A[i],&B[i]),D[++D[0]]=A[i],D[++D[0]]=B[i];
	 for (i=0;i<=n;++i) scanf("%d",&C[i]),D[++D[0]]=C[i];
	 scanf("%d",&Q);
	 for (i=1;i<=Q;++i) scanf("%d%d",&X[i],&Y[i]),D[++D[0]]=X[i],D[++D[0]]=Y[i]; 
	 sort(D+1,D+D[0]+1);
	 D[0]=unique(D+1,D+D[0]+1)-(D+1);
	 for (i=1;i<=n;++i) A[i]=lower_bound(D+1,D+D[0]+1,A[i])-D,B[i]=lower_bound(D+1,D+D[0]+1,B[i])-D;
	 for (i=0;i<=n;++i) f[lower_bound(D+1,D+D[0]+1,C[i])-D]++;
	 for (i=1;i<=n;++i) f[A[i]]--;
	 for (i=D[0];i;--i) f[i]+=f[i+1];
	 for (i=1;i<=n;++i) if (A[i]>B[i]) v[A[i]].pb(mk(B[i]+1,i));
	 int now=0;
	 for (i=D[0];i;--i)
	 {
	 	for (j=0;j<(int)v[i].size();++j) st.insert(v[i][j]);
	 	f[i]+=now;
	 	while (f[i]<0)
	 	{
	 		   if (!st.size()) RE();
	 		   pair<int,int> x=*st.begin();
	 		   if (x.fi>i) RE();
	 		   F[x.fi]++;
	 		   vis[x.se]=1;
	 		   f[i]++; now++; --Ans;
	 		   st.erase(st.begin());
	 	}
	 	now-=F[i];
	 }
	 memset(ans,-1,sizeof(ans)); ans[0]=Ans;
	 for (i=1;i<=n;++i) if (!vis[i]&&A[i]>B[i]) alb[B[i]+1].pb(A[i]);
	 now=0;
	 memset(f,0,sizeof(f));
	 memset(F,0,sizeof(F));
	 for (i=0;i<=n;++i) f[lower_bound(D+1,D+D[0]+1,C[i])-D]++;
	 for (i=1;i<=n;++i) 	if (!vis[i]) f[A[i]]--; else f[B[i]]--;
	 for (i=D[0];i;--i) f[i]+=f[i+1];
	 for (i=1;i<=D[0];++i)
	 { 
	 	for (j=0;j<(int)alb[i].size();++j) str.insert(alb[i][j]);
	 	f[i]+=now;
	 	if (f[i]<=0)
	 	{
	 		 if (!str.size()) break;
	 		 int x=*--str.end();
	 		 if (x<i) break;
	 		 ans[i]=ans[i-1]-1; f[i]++; now++; F[x]++;
	 		 str.erase(str.find(x));
	 	}
	 	else ans[i]=ans[i-1];
	 	now-=F[i];
	 }
	 for (i=1;i<=Q;++i)
	 {
	 	 X[i]=lower_bound(D+1,D+D[0]+1,X[i])-D;
	 	 Y[i]=lower_bound(D+1,D+D[0]+1,Y[i])-D;
	 	 if (ans[X[i]]==-1&&ans[Y[i]]==-1) puts("-1");
	 	 else if (ans[X[i]]==-1) printf("%d\n",ans[Y[i]]);
	 	 else if (ans[Y[i]]==-1) printf("%d\n",ans[X[i]]+1);
	 	 else printf("%d\n",max(ans[X[i]]+1,ans[Y[i]]));
	 }
}


Measured memory_bytes: 50048
use proconio::fastout;
use whiteread::parse_line;

#[fastout]
fn main() {
    let (n, _, x): (usize, usize, usize) = parse_line().unwrap();
    let a: Vec<usize> = parse_line().unwrap();

    let mut cost: Vec<usize> = vec![0; n + 1];
    for pos in a {
        cost[pos] += 1;
    }

    let mut to_0 = 0;
    for i in 0..x {
        to_0 += cost[i];
    }
    let mut to_n = 0;
    for i in (x + 1)..(n + 1) {
        to_n += cost[i];
    }
    println!("{}", std::cmp::min(to_0, to_n));
}


Measured memory_bytes: 2212
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

int main(void)
{
	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: 2576
#include <bits/stdc++.h>

using namespace std;

template<typename T> void drop(const T &x){cout<<x<<'\n';exit(0);}

void milktea() {
  int d, g;
  cin >> d >> g;
  vector<int> p(d), c(d);
  for(int i = 0; i < d; i++) {
    cin >> p[i] >> c[i];
  }
  
  int ans = 1e9;
  for(int bit = 0; bit < (1 << d); bit++) {
    int s = 0, num = 0, m = -1;
    for(int i = 0; i < d; i++) {
      if(bit & 1 << i) {
        s += 100 * (i+1) * p[i] + c[i];
        num += p[i];
      } else {
        m = i;
      }
    }
    cout << '\n';
    if(s < g) {
      int s1 = 100 * (m+1);
      int need = (g - s + s1 - 1) / s1;
      if(need >= p[m]) continue;
      num += need;
    }
    ans = min(ans, num);
  }
  cout << ans << '\n';
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int tt=1;
  //cin >> tt;
  while(tt--) milktea();

  return 0;
}


Measured memory_bytes: 3644
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define SORTD(a) sort(a.rbegin(), a.rend());
#define UNIQUE(a) unique(a.begin(), a.end())
#define ll long long
#define INF 1000000000000000000
#define INT_MAX 2147483647

#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <cctype>
#include <numeric>
#include <algorithm>
#include <queue>
#include <set>
#include <utility>
#include <ios>
#include <iomanip>
#include <sstream>
#include <map>

using namespace std;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;

const ll mod = 1e9+7;

int main() {
	int n;
	cin >> n;
	vi d(n);
	REP(i, n)cin >> d[i];

	SORT(d);

	cout << d[n / 2] - d[n / 2 - 1] << endl;
}

Measured memory_bytes: 640
#include "bits/stdc++.h"
#define MOD 1000000007
#define inf 0x3f3f3f3f3f3f3f3f
#define pi acos(-1.0)
#define ri register int
#define int long long
#ifdef ONLINE_JUDGE
const int maxn = 5e2 + 10;
#else
const int maxn = 1e3 + 10;
#endif
using namespace std;
int N, M, mp[maxn][maxn];
signed main()
{
    ios::sync_with_stdio(false);
    cin >> N >> M;
    for (ri i = 1; i <= N; ++i) {
        for (ri j = 1; j <= M; ++j) {
            cin >> mp[i][j];
        }
    }
    int cnt = 0;
    vector<vector<int>> v;
    for (ri i = 1; i <= N; ++i) {
        for (ri j = 1; j <= M; ++j) {
            if (~mp[i][j] & 1) {
                continue;
            }
            if (j < M) {
                v.push_back({ i, j, i, j + 1 });
                mp[i][j + 1]++;
                mp[i][j]--;
                continue;
            }
            if (i < N) {
                v.push_back({ i, j, i + 1, j });
                mp[i + 1][j]++, mp[i][j]--;
            }
        }
    }
    cout << v.size() << endl;
    for (auto e : v) {
        cout << e[0] << " " << e[1] << " " << e[2] << " " << e[3] << endl;
    }
    return 0;
}

Measured memory_bytes: 15024
#include<bits/stdc++.h>
using namespace std;
const int P=1e9+7;
const int N=205;
const int Gi=(P+1)/2;
#define ll long long
ll fsp(ll x,int y){
	ll ans=1;
	while(y){
		if(y&1)	ans=ans*x%P;
		x=x*x%P,y>>=1;
	}
	return ans;
}
ll f[N][2];
vector<int>ch[N];
int n,top,a[N],st[N],len[N];
void dp(int x,int fl){
	int si=ch[x].size();
	for(int i=0;i<si;i++)	dp(ch[x][i],a[x]);
	if(!si){
		f[x][0]=fsp(2,len[x])-2;
		f[x][1]=fsp(2,a[x]-fl);
	}
	else{
		ll r1=1,r2=1;
		for(int i=0;i<si;i++){
			r1=r1*(f[ch[x][i]][0]+f[ch[x][i]][1]*2)%P;
			r2=r2*f[ch[x][i]][1]%P;
		}
		f[x][0]=((r1-r2+P)*fsp(2,len[x])+r2*(fsp(2,len[x])-2))%P;
		f[x][1]=r2*fsp(2,a[x]-fl)%P;
	}
}
int main(){
	
	scanf("%d",&n);
	for(int i=1;i<=n;i++)	scanf("%d",&a[i]),len[i]=1;
	for(int i=1;i<=n;i++){
		while(top&&a[st[top]]>=a[i]){
			if(a[st[top]]==a[i])	len[i]+=len[st[top]],swap(ch[st[top]],ch[i]);
			else{
				if(a[st[top-1]]>=a[i])	ch[st[top-1]].push_back(st[top]);
				else	ch[i].push_back(st[top]);
			}
			top--;
		}
		st[++top]=i;
	}
	while(top>1)	ch[st[top-1]].push_back(st[top]),top--;

	dp(st[top],0);
	printf("%lld\n",(f[st[1]][0]+f[st[1]][1])%P);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define db long double
#define x first
#define y second
#define mp make_pair
#define pb push_back
#define all(a) a.begin(), a.end()

using namespace std;

int n;

int was[101][101];

int main(){
#ifdef LOCAL
	freopen("A_input.txt", "r", stdin);
	//freopen("A_output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	cin >> n;
	vector<ll> a;
	for (int i = 0; i < n; ++i) {
		string s;
		cin >> s;
		int v = -1;
		ll now = 0;
		for (int j = 0; j < s.size(); ++j) if (s[j] == '.') v = j;

		int le = 0;
	int w = 0;
		for (int j = 0; j < s.size(); ++j) {
			if (s[j] == '.') w = 1;
			else {
			now = now * 10 + (s[j] - '0');
			if (w) ++le;
		}
		}

		if (v == -1) {
			a.pb(now * (ll)1000000000);
		} else {
		//	cout << now << ' ' << s << endl;
			while (le < 9) now *= 10, ++le;
			a.pb(now);
		}
	//		cout << a.back() << endl;
	}

	ll ans = 0;

	for (auto c : a) {
		int w1 = 0, w2 = 0;
		while (c % 2 == 0) ++w1, c /= 2;
		while (c % 5 == 0) ++w2, c /= 5;
		w1 = min(w1, 20);
		w2 = min(w2, 20);
		
		for (int i1 = 0; i1 <= 20; ++i1) 
		for (int i2 = 0; i2 <= 20; ++i2) 
			if (w1 + i1 >= 18 && w2 + i2 >= 18) ans += was[i1][i2];

		++was[w1][w2];

	}

	cout << ans;
}


Measured memory_bytes: 5336
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define sd second
#define ft first
#define pr pair
#define vl vector<ll>
#define vs vector<string>
#define vmp vector<pair<ll,ll>>
#define en "\n"
#define lb lower_bound
#define ub upper_bound
#define vll vector<vector<ll>>
#define vmpl vector<vector<pair<ll,ll>>>
#define st size()
#define al(v) v.begin(),v.end()
#define cast static_cast<char>
#define ins insert
#define fata_fat ios_base::sync_with_stdio(false); cin.tie(NULL);
ll M=1e9+7,MAX=1e18,MIN=-1e18;
void bhaag()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
}
int main()
{   
     bhaag(); fata_fat;
     ll n,i,x,y,k=0; cin>>n; vl one(n),two(n);
     for(i=0;i<n;i++)cin>>one[i]>>two[i];
     for(i=0;i<n-2;i++){
         if(one[i]==two[i]&&one[i+1]==two[i+1]&&one[i+2]==two[i+2]){k=1; break;}
     }
     if(k)cout<<"Yes";
     else cout<<"No";
}


Measured memory_bytes: 3648
#pragma GCC optimize(3,"Ofast","inline")
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define ms(a,b) memset(a,b,sizeof(a))
#define msn(a,n,b) for(int i=0;i<=n;i++)a[i]=b
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define fi first
#define se second
using namespace std;
mt19937 rng_32(chrono::steady_clock::now().time_since_epoch().count());
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef double db;
const int mod=1e9+7;
const int seed=233;
const double PI=acos(-1.0);
const double eps=1e-7;
const int inf=0x3f3f3f3f;
const int max_n=100005;
ll ceil(ll x,ll y){if(x==0)return 0;if(y<0)x=-x,y=-y;bool sign=x>0;x=abs(x);return sign?(x+y-1)/y:-x/y;}
ll floor(ll x,ll y){if(x==0)return 0;if(y<0)x=-x,y=-y;bool sign=x>0;x=abs(x);return sign?x/y:-(x+y-1)/y;}
char str[max_n];
void reads(string& s){scanf(" %s",str);s=str;}
namespace {
    inline int Add(int x,int y){return (x+=y)>=mod?x-mod:x;}
    inline int Sub(int x,int y){return (x-=y)<0?x+mod:x;}
    inline int Mul(int x,int y) {return 1ll*x*y%mod;}
    inline int Pow(int x,int y=mod-2){int res=1;while(y){if(y&1)res=1ll*res*x%mod;x=1ll*x*x%mod;y>>=1;}return res;}
}
/**********************head************************/
int x,n,p[max_n];
int main(){
    scanf("%d%d",&x,&n);
    for(int i=1;i<=n;i++){
        int x;scanf("%d",&x);
        p[x]=true;
    }
    int ans=100000,o=-1;
    for(int i=0;i<=101;i++){
        if(!p[i]){
            if(abs(i-x)<ans){
                ans=abs(i-x);
                o=i;
            }
        }
    }
    printf("%d\n",o);
    return 0;
}

Measured memory_bytes: 3836
#include<bits/stdc++.h>
using namespace std;
int n,k,a[101],pre;
int main()
{
	cin>>n>>k;
	for(int i=1;i<=n;i++)cin>>a[i];
	vector<int> ans;
	for(int i=0;i<=k;i++)
	{
		int m=100,x;
		for(int j=1;j<=n;j++)
			if(j!=pre&&a[j]<m)m=a[x=j];
		if(!m)puts("-1"),exit(0);
		for(int j=1;j<=n;j++)
			if(j!=pre&&j!=x)ans.push_back(j),a[j]--;
		ans.push_back(x);
		a[x]--;
		pre=x;
	}
	cout<<n+(n-1)*k<<'\n';
	for(int i:ans)cout<<i<<' ';
	cout<<'\n';
}


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

using namespace std;

#define FOR(i, n) for(int i = 0; i < (int) n; i++)
#define PB push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define F first
#define S second

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;

long double EPS = 1e-9;

const int MOD = 1e9+7;

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

	int n; cin >> n;

	ll tot = 1, less = 1, lele = 1;
	for(int i = 0; i < n; i++)
		tot = tot * 10LL % MOD, less = less * 9LL % MOD, lele = lele * 8LL % MOD;

	ll ans = tot - 2 * less + lele;
	while(ans < 0) ans += MOD;
	cout << ans % MOD << '\n'; 

	return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;

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

int N, M;
int cur = 1;
int ans = 0;
int sx, sy;
vector<string> c;

void checkandFill() {
  for (P p : vector<P>{{0, M - 1}, {N - 1, M - 1}, {N - 1, 0}}) {
    if (P{sx, sy} != p) continue;
    ++ans;
    for (int i = 0; i < N; ++i) {
      for (int j = 0; j < M; ++j) {
        if (c[i][j] == '!') c[i][j] = '#';
      }
    }
  }
}

bool nextPosition() {
  for (int i = -1; i < 3; ++i) {
    int tx = sx + dx[(i + cur + 4) % 4];
    int ty = sy + dy[(i + cur + 4) % 4];
    if (0 <= tx && tx < N && 0 <= ty && ty < M) {
      for (int j = 0; j < 2; ++j) {
        if (c[tx][ty] == ".!"[j]) {
          if (sx != 0 || sy != 0) c[sx][sy] = "!#"[j];
          sx = tx;
          sy = ty;
          cur = (i + cur + 4) % 4;
          return true;
        }
      }
    }
    if (i == 2) return false;
  }
}

bool solve() {
  ans = 0;
  cur = 0;
  sx = 0;
  sy = 0;
  while (true) {
    checkandFill();
    if (not nextPosition()) return false;
    if (sx == 0 && sy == 0) return (ans == 3);
  }
}

int main() {
  while (cin >> N >> M, N) {
    c = vector<string>(N);
    for (int i = 0; i < N; ++i) cin >> c[i];
    cout << ( solve() ? "YES" : "NO" ) << endl;
  }
}



Measured memory_bytes: 3084
n, l = map(int, input().split())
a = range(l, l + n)

if all(map(lambda x: x < 0, a)):
    ans = sum(a[:-1])
elif all(map(lambda x: x > 0, a)):
    ans = sum(a[1:])
else:
    ans = sum(a)

print(ans)


Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <bitset>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>

using namespace std;

int main(){
	int n = 0;
	cin >> n;
	vector<long long> dp(21, 0);
	for(int i = 0; i < n-1; i++){
		int tmp;
		cin >> tmp;
		if(i){
			vector<long long> copy = dp;
			dp = vector<long long>(21, 0);
			for(int j = 0; j < copy.size(); j++){
				int pl = j+tmp, mi = j-tmp;
				if(pl<=20)dp[pl]+=copy[j]; 
				if(mi>=0)dp[mi]+=copy[j];
			}
		}
		else{
			dp[tmp]++;
		}
	}
	int result, count = 0;
	cin >> result;
	cout << dp[result] << endl;
	return 0;
}

Measured memory_bytes: 1216
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define repr(i,x,n) for(int i=x; i<(n); i++)
#define ALL(x) (x).begin(),(x).end()
#define INF 1e9
#define pai 3.14159265359
typedef long long ll;
using VI = vector<int>;
using VS = vector<string>;
using graph = vector<vector<int>>;
int main()
{
int a,b,h,m;
cin>>a>>b>>h>>m;
int time=h*60+m;
double kaku=abs(time*0.5-(time%60)*6),ans=0;
if (kaku>=180)
{
    kaku=360-kaku;
}
kaku=kaku*(pai/180);
ans=a*a+b*b-2*a*b*cos(kaku);
ans=pow(ans, 0.5);
cout << fixed << setprecision(17) <<ans<< endl;
    return 0;
}

Measured memory_bytes: 4356
#include<bits/stdc++.h>
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
#define int long long
#define double long double
#define fo(a,b) for(int a=0;a<b;a++)
#define Sort(a) sort(a.begin(),a.end())
#define rev(a) reverse(a.begin(),a.end())
#define fi first
#define se second
#define sz size()
#define bgn begin()
#define en end()
#define pb push_back
#define pp() pop_back()
#define V vector
#define P pair
#define yuko(a) setprecision(a)
#define uni(a) a.erase(unique(a.begin(),a.end()),a.end())
#define Q queue
#define pri priority_queue
#define Pri priority_queue<int,vector<int>,greater<int>>
#define PriP priority_queue<P<int,int>,vector<P<int,int>>,greater<P<int,int>>>
#define ff first.first
#define fs first.second
#define sf second.first
#define ss second.second
#define all(a)  (a).begin(),(a).end()


signed main(){
  int x,y,a,b,c;
  cin>>x>>y>>a>>b>>c;
  int ans=0;
  V<int> red(a);
  fo(i,a){
    cin>>red[i];
  }
  Sort(red);
  rev(red);
  V<int> blue(b);
  fo(i,b){
    cin>>blue[i];
  }
  Sort(blue);
  rev(blue);
  V<int> mu(c);
  fo(i,c){
    cin>>mu[i];
  }
  Sort(mu);

  priority_queue<int, V<int>, greater<int>> q;

  fo(i,x){
    q.push(red[i]);
  }
  fo(i,y){
    q.push(blue[i]);
  }

  while(!mu.empty()){
    if (q.top()<mu.back()){
      q.pop();
      q.push(mu.back());
      mu.pop_back();
    }
    else break;
  }
  while(!q.empty()) {
    ans+=q.top();
    q.pop();
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 4724
n=int(input())
ct=[[0]*10 for i in range(10)]
for i in range(1,n+1):
  ct[int(str(i)[0])][int(str(i)[-1])]+=1
ans=0
for i in range(10):
  for j in range(10):
    ans+=ct[i][j]*ct[j][i]
print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
int t, k;
map<int,int> mp;
string s;
int main(){
	cin >> s;
	mp[0] = 0;
	for(char c: s){
		t ^= 1 << (c - 'a');
		auto it = mp.find(t);
		k = it != mp.end() ? it->second : 300000;
		rep(i,26){
			it = mp.find(t^(1<<i));
			if(it != mp.end()) k = min(k,it->second+1);
		}
		mp[t] = k;
	}
	printf("%d\n", t ? mp[t] : 1);
}

Measured memory_bytes: 9860
#include<stdio.h>
 
int main(void)
{
	int A, B, C, X;
	scanf("%d %d %d %d", &A, &B, &C, &X);
	int res = 0;

	for ( int a = 0; a <= A; a++ ) {
		for ( int b = 0; b <= B; b++ ) {
			for ( int c = 0; c <= C; c++ ) {
				int sum = 500*a + 100*b + 50*c;
				if ( sum == X ) res++;
			}
		}
	}
	printf("%d", res);

	return 0;
}

Measured memory_bytes: 128
N,M=map(int,input().split())
if N==1 and M==1:
    ans=1
elif (N==1 and M==2) or (N==2 and M==1):
    ans=0
elif N==1 or M==1:
    ans=N+M-3
else:
    ans=N*M-2*(N+M-2)
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define rep(i,n) for(int i=0; i<n; i++)
#define pb(a) push_back(a)
#define mp make_pair

int main()
{

  int n;
  string s;
  int cnt;
  int ans = 0;
  cin >> n >> s;
  cnt = 0;
  rep(i,n) {
    if(s[i] == 'A'){
      cnt = 1;
    } else if(s[i] == 'B'){
      if(cnt == 1){
	cnt = 2;
      } else {
	cnt = 0;
      }
    } else if(s[i] == 'C'){
      if(cnt == 2){
	ans++;
      }
      cnt = 0;
    } else {
      cnt = 0;
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string>
using namespace std;
#define e1 first
#define e2 second
#define pb push_back
#define mp make_pair
#define boost ios_base::sync_with_stdio(false)
#define eb emplace_back
#define OUT(x) {cout << x; exit(0); }
#define scanf(...) scanf(__VA_ARGS__)?:0
#define FOR(i, a, b) for(int i=(a); i<=(b); ++i)
typedef long long ll;
typedef unsigned long long ull;
typedef pair <int, int> PII;
typedef pair <PII, int> PPI;
typedef pair <ll, ll> PLL;
typedef pair <PLL, PLL> PP;
typedef unsigned int ui;
const int inf = 1e9+9;
const ll MOD = 1e9+696969;
const ll INF = 1e18;
#define maxn 1000003
int n, m, k, a, b, c;
 
int main()
{
	cin >> k;
	cin >> n;
	int maks = 0;
	FOR(i, 1, n) {
		cin >> a;
		maks = max(maks, a);
	}
	int r = k - maks;

	cout << max(0, maks - r - 1);
}


Measured memory_bytes: 256
import java.util.*;
import java.lang.*;
import java.io.*;
 
class Main {
  public static void main(String args[]) {
    Scanner scanner = new Scanner(System.in);
 
    String input1 = scanner.nextLine();
    String A = scanner.nextLine();
    String B = scanner.nextLine();
    String C = scanner.nextLine();
 

int N = Integer.parseInt(input1);

int count = 0;

String AN = "";
String BN = "";
String CN = "";

for(int i=0; i<N;i++){
AN = A.substring(i,i+1);
BN = B.substring(i,i+1);
CN = C.substring(i,i+1);

if(!AN.equals(BN)){
if(!BN.equals(CN)){
count++;
count++;
if(AN.equals(CN)){
count--;
}
}else{
count++;
}
}else{
if(!AN.equals(CN)){
count++;
}else if(!BN.equals(CN)){
count++;
}
}
}

    System.out.print(count);
    scanner.close();
  }
}

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

bool exhaustiveSearch(const int A[], int i, int key, int nNum) {
	if (key == 0)	return true;
	if (key < 0 || i >= nNum) return false;
	return exhaustiveSearch(A, i + 1, key, nNum) ||
		exhaustiveSearch(A, i + 1, key - A[i], nNum);
}

int main() {
	int nNum;
	int A[20];
	int qNum;

	cin >> nNum;
	for (int i = 0; i < nNum; i++) {
		cin >> A[i];
	}
	cin >> qNum;
	for (int i = 0; i < qNum; i++) {
		int key;
		cin >> key;
		if (exhaustiveSearch(A, 0, key, nNum)) cout << "yes" << endl;
		else cout << "no" << endl;
	}

	return 0;
}

Measured memory_bytes: 3108
fun main(args: Array<String>) {
    abc051b()
}

fun abc051b() {
    val (k, s) = readLine()!!.split(" ").map { it.toInt() }

    val answer = (0..k).sumBy { x ->
        (0..k).sumBy { y ->
            val z = s - x - y
            if (z in 0..k) 1 else 0
        }
    }

    println(answer)
}


Measured memory_bytes: 40552
#include<bits/stdc++.h>
#define IO ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define ff first
#define ss second
using namespace std;
typedef long long ll;

int main() {
    IO;
    int k;
    cin >> k;
    ll sum = 0;
    for(int a = 1; a <= k; a++){
        for(int b = 1; b <= k; b++){
            for(int c = 1; c <= k; c++){
                sum += __gcd(a, __gcd(b, c));
            }
        }
    }
    cout << sum << '\n';
    return 0;
}


Measured memory_bytes: 3652
#include <iostream>
#include <cmath>
#include <stdio.h>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <cstring>

using namespace std;

#define f first
#define s second
#define pb push_back
#define mp make_pair
#define ll long long
#define pii pair < int, int >
#define pll pair < long long, long long>
#define ull unsigned long long
#define vi vector < int >
#define vll vector < long long >
#define sz(a) (int)a.size()
#define forit(it, s) for(__typeof(s.begin()) it = s.begin(); it != s.end(); it++)
#define all(a) a.begin(), a.end()
#define sqr(x) ((x) * (x))
#define fname "searching"

const int inf = (int)1e9;
const ll INF = (ll)1e18;
const double eps = 1e-9;
const double pi = acos(-1.0);
const int mod = (int)1e9 + 7;

int n;
int a[110];

int main(){
	ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n;
    for(int i = 0; i < n; ++i)
    	cin >> a[i];
    int mn = inf;
    for(int i = -100; i <= 100; ++i){
    	int sum = 0;
    	for(int j = 0; j < n; ++j){
    		sum += sqr(a[j] - i);
    	}
    	mn = min(mn, sum);
    }

    cout << mn << "\n";
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int main(){
    cout << fixed << setprecision(10);
    ll n,m,k;
    cin >> n >> m >> k;
    vector<ll> a(n),b(m);
    rep(i,n) cin >> a[i];
    rep(i,m) cin >> b[i];
    vector<ll> suma(n,0),sumb(m,0);
    suma[0] = a[0];
    sumb[0] = b[0];
    for(int i=1;i < n;i++) suma[i] += suma[i-1] + a[i];
    for(int i=1;i < m;i++) sumb[i] += sumb[i-1] + b[i];
    ll ans = 0;
    rep(i,n){
        ll now = i+1;
        if(suma[i] > k) break;
        ll num =  upper_bound(sumb.begin(),sumb.end(), k - suma[i]) - sumb.begin();
        ans = max(ans,num+now);
    }
    rep(i,m){
        ll now = i+1;
        if(sumb[i] > k) break;
        ll num =  upper_bound(suma.begin(),suma.end(), k - sumb[i]) - suma.begin();
        ans = max(ans,num+now);
    }  
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 9532
#include <cstdio>
int f[1000001],a[1000001];
int main()
{
	int ans=0,n=0;
	scanf("%d",&n);
	for (int i=1;i<=n;++i)	scanf("%d",&a[i]);
	f[0]=-1,ans=0;
	for(int i=n;i>=1;--i){
		if(f[ans]<=a[i])	f[++ans]=a[i];
		else{
			int l=0,r=ans;
			while(l<r){
				int mid=(l+r)/2;
				if(f[mid]>a[i])	r=mid;
				else	l=mid+1;
			}
			f[l]=a[i];
		}
	}
	printf("%d",ans);
	return 0;
}


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

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    cin >> N;
    int ans = 0;
    for(int i=1; i<=N; i+=2)
    {
        int yakusu = 0;
        for(int j=1; j*j <= i; j++)
        {
            if(j*j == i) yakusu++;
            else if(i%j==0) yakusu += 2;
        }
        if(yakusu==8) ans++;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3576
#include "bits/stdc++.h"

using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define ll long long
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
using pii = pair<int, int>;
// template<class T> ostream &operator<<(ostream &os,T &t){dump(t);return os;}
template <typename T, typename S>istream &operator>>(istream &is, pair<T, S> &p) { is >> p.first >> p.second; return is; }
//template <typename T, typename S>ostream &operator<<(ostream &os, pair<T, S> &p) {os << p.first << " " << p.second;return os;}

template <typename T> void printvv(const vector<vector<T>> &v) {
	cerr << endl;
	rep(i, 0, v.size()) rep(j, 0, v[i].size()) {
		if (typeid(v[i][j]).name() == typeid(INF).name() and v[i][j] == INF) {
			cerr << "INF";
		}
		else
			cerr << v[i][j];
		cerr << (j == v[i].size() - 1 ? '\n' : ' ');
	}
	cerr << endl;
}

#ifndef _DEBUG
#define printvv(...)
#endif
void YES(bool f) { cout << (f ? "YES" : "NO") << endl; }
void Yes(bool f) { cout << (f ? "Yes" : "No") << endl; }
template <class T, class U>bool chmin(T& a, U b) { if (a > b) { a = b; return true; }return false; }
template <class T, class U>bool chmax(T& a, U b) { if (a < b) { a = b; return true; }return false; }
void printYes(bool f) {
	if(f)cout << "Yay!" << endl;
	else cout << ":(" << endl;
}

signed main(signed argc, char *argv[]) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(12);

	vector<int>v = { 300000 ,200000 ,100000,0 };

	int a, b; cin >> a >> b;
	chmin(a, 4);
	chmin(b, 4);
	a--, b--;
	int ans = v[a] + v[b];
	if (a == 0 and b == 0) {
		ans += 400000;
	}
	cout << ans << endl;

	return 0;
}


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

using namespace std;

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

    pair<int, int> routes[m]; // n個の島においいて、 .first から .second の繋がりを切る

    for (int i=0; i<m; i++)
        cin >> routes[i].first >> routes[i].second;

    sort(routes, routes+m, [](pair<int, int> x, pair<int, int> y) {
        return x.second < y.second;
    });

    int prev_point = routes[0].second;
    int cnt = 1;
    for (int i=1; i<m; i++) {
         if (routes[i].first >= prev_point) {
             cnt++;
             prev_point = routes[i].second;
         }
    }

    //for (int i=0; i<m; i++)
    //    cout << routes[i].first << " " << routes[i].second << endl;
    cout << cnt << endl;
}

Measured memory_bytes: 1024
x = 1000000007

S = input()
S = [int(s) if s != '?' else s for s in S]

dp = [[0 for j in range(13)] for i in range(len(S) + 1)]
dp[0][0] = 1

for i, s in enumerate(S):
    for j in range(10):
        if s != '?' and s != j:
            continue

        for k in range(13):
            dp[i + 1][(10 * k + j) % 13] += dp[i][k] % x

print(int(dp[-1][5] % x))


Measured memory_bytes: 73748
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

const (
	initialBufSize = 100000
	maxBufSize     = 10000000
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wt = bufio.NewWriter(os.Stdout)
)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	i, _ := strconv.Atoi(next())
	return i
}

func nextInt2() (int, int) {
	return nextInt(), nextInt()
}

func nextInt3() (int, int, int) {
	return nextInt(), nextInt(), nextInt()
}

func nextInt4() (int, int, int, int) {
	return nextInt(), nextInt(), nextInt(), nextInt()
}

func nextInts(n int) []int {
	slice := make([]int, n)
	for i := 0; i < n; i++ {
		slice[i] = nextInt()
	}
	return slice
}

func nextFloat64() float64 {
	f, _ := strconv.ParseFloat(next(), 64)
	return f
}

func nextFloat64s(n int) []float64 {
	slice := make([]float64, n)
	for i := 0; i < n; i++ {
		slice[i] = nextFloat64()
	}
	return slice
}

func putf(format string, a ...interface{}) {
	fmt.Fprintf(wt, format, a...)
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, initialBufSize), maxBufSize)
	defer wt.Flush()

	a, b := nextInt(), nextInt()
	puts(a * b)
}


Measured memory_bytes: 1764
#include<iostream>

using namespace std;
const int MAX_N=1e3;
int data[MAX_N];
int main(){
	int m,nmi,nma;
	while(cin>>m>>nmi>>nma && nmi!=0){
		for(int i=0;i<m;i++)cin>>data[i];
		int ma=0;
		int ans=0;
		for(int i=nmi-1;i<nma;i++){
			if(ma<=data[i]-data[i+1]){
				ans=i+1;
				ma=data[i]-data[i+1];
			}
		}
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 3096
#include "iostream"
#include <string>
int main()
{
    std::string aStr = "";
    std::cin >> aStr;

 

    int aCount = 0;
        for (unsigned int i = 0; i < aStr.size() / 2; ++i)
        {
            if (aStr[i] != aStr[aStr.size() - 1 - i])
            {
                aStr[i] = aStr[aStr.size() - 1 - i];
                aCount++;
            }

 

        }

 

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

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
  int in;
  int a[10];
  int i=0;

  while(scanf("%d",&in)!=EOF){
    if(in!=0){
	  a[i]=in;
	  i++;
	}else{
	  i--;
	  printf("%d\n",a[i]);
	}
  }

  return 0;
}

Measured memory_bytes: 600
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

K,X = inpl()
if K*500 >= X:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 4076
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define Would
#define you
#define please

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

	string S;
	cin >> S;

	rep(i, 3) {
		if (S[i] == '9') S[i] = '1';
		else S[i] = '9';
	}
	co(S);


	Would you please return 0;
}

Measured memory_bytes: 764
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <list>
#include <stack>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#define   mod  998244353
#define   int  long long 
#define   ld   long double
#define   pb   push_back
#define   vi  vector<int> 
#define   dbg(x)  cerr << #x << " = " << x << '\n'
#define   sz(x)  (int)x.size()
#define   all(a) (a.begin(),a.end())
#define   ff   first
#define   ss   second
#define   pii  pair<int,int> 
#define   lcm(a,b) (a*b)/__gcd(a,b) 
using namespace std;

inline void solve(){
    int  n, x, ans = 0 ; 
    cin >> n >> x ; 
    vi a(n+1);
    for (int i=1;i<=n;i++) cin >> a[i] ; 
    int d= max(0LL,a[1]-x);
    a[1] -= d; ans += d ; 
    for (int i=2;i<=n;i++) {
        if (a[i-1]+a[i] >= x){
            d = max(0LL,a[i]+a[i-1]-x);
            a[i] -= d;
            ans += d ; 
        }
    }
    cout << ans << endl;
}

signed main()
{
    int n=1; // cin>>n;
    while (n--) solve();
    return 0;
}


Measured memory_bytes: 3988
#include <stdio.h>
 int main(void){
    int i, j,H,W;
    while(scanf("%d %d",&H,&W)!=EOF){
     if(H==0&&W==0){
         break;
     }
     for ( i = 0; i < H; i++ ){
     for ( j = 0; j < W; j++ ){
         if(j==0||j==W-1||i==0||i==H-1){
             printf("#");
         } else {
             printf(".");
         }
     }
     printf("\n");
 }
     printf("\n");
 }
  return(0);// Your code here!
     
 }





Measured memory_bytes: 2064
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>	// upper_bound(A, A+N, num), lower_bound(A, A+N, num)
#include <functional>
#include <string>
#include <sstream>
#include <complex>
#include <vector>		// V[i],  push_back(x), pop_back(), insert(index, x), erase(index), sort(v.begin(), v.end(), greater<int>())
#include <list>			// push_front(x), push_back(x), pop_front(), pop_back(), insert(index, x)
#include <queue>		// push(x), front(), pop()
#include <deque>
#include <stack>		// push(x), top(), pop()
#include <map>			// M[key],  insert(key, val), erase(key), find(key), 
#include <set>			// insert(key), erase(key), find(key)

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

#define PI 3.141592653589793)
#define MOD 1000000007
#define REP(i, n) for(int i = 0; i < n; i++)

int N, L[200];

void solve() {
	cin >> N;
	for (int i = 0; i < 2*N; i++) cin >> L[i];
	sort(L, L + 2*N);
	int ans = 0;
	for (int i = 0; i < 2*N; i = i + 2) {
		ans += L[i];
	}
	cout << ans << endl;
}

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

Measured memory_bytes: 256
S = int(input())

m = 1000000007

if S <= 2:
    print(0)
else:
    seqs = [0,0,0,1]

    for i in range(4,S+1):

        temp = 1

        for j in range(3,i+1):
            temp += seqs[i-j]
            temp %= m

        seqs.append(temp)

    print(seqs[S] % m)

Measured memory_bytes: 9204
import Control.Applicative
import Control.Monad

main :: IO ()
main = do
    [n,m] <- map read . words <$> getLine
    mat <- replicateM n $ map read . words <$> getLine
    vec <- replicateM m readLn
    mapM_ (print . prod vec) mat

prod :: [Int] -> [Int] -> Int
prod u v = sum $ zipWith (*) u v


Measured memory_bytes: 7580
import java.io.*;

class Main{
	public static void main(String[]args)throws IOException{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb=new StringBuilder();
		String str=br.readLine();
		
		int i=0;
		
		while(!str.equals("0")){
			i++;
			sb.append("Case ").append(i).append(": ").append(str).append("\n");
			str=br.readLine();
		}
		System.out.print(sb);
	}
}

Measured memory_bytes: 28892
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <cmath>

using namespace std;
#define PI 3.1415926535897932384626433832795
#define MOD (1000000007)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
#define swap(a, b, type) { type _tmp = a; a = b; b = _tmp; }
typedef long long ll;
typedef unsigned long long ull;

int main()
{
	int a, b, n;
	bool ans = false;

	cin >> a >> b;
	if (b < 10) n = a * 10 + b;
	else if (b < 100) n = a * 100 + b;
	else n = a * 1000 + b;

	for (int i = 1; i * i <= n; i++) {
		if (i * i == n) ans = true;
	}

	cout << (ans ? "Yes" : "No") << endl;

	return 0;
}


Measured memory_bytes: 256
n, m = map(int, input().split())
howmany_list = [-1] * (n+1)
howmany_list[0] = 1
howmany_list[1] = 1

for i in range(m):
  howmany_list[int(input())] = 0

for i in range(2, n+1):
  if howmany_list[i] != 0:
    howmany_list[i] = (howmany_list[i-1] + howmany_list[i-2]) % 1000000007

print(howmany_list[n])

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

int main() {
  int a,b,c;
  long K;
  cin >> a>>b>>c>>K;
  if(K%2LL==0){
    cout<<a-b<<endl;
  }
  else{
    cout<<b-a<<endl;
  }
  
}



Measured memory_bytes: 256
#include <iostream>
#include <climits>
#include <set>
#include <string>
#include <algorithm>
#include <vector>
#define MAX 1000000007


using namespace std;
#define ll long long
#define dbg if(0)
#define ISRANGE(val,lo,hi) ((lo<=val)&&(val<hi))



int main(){
    ll ans,a,b,c;
    cin >>a>>b>>c;

    {
        if(a+b+c>=22)cout <<"bust"<<endl;
        else cout <<"win"<<endl;
    }

    dbg cout <<ans<<endl;

    return 0;

}

Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String[] args) {

        Integer[] set1 = {1, 2, 6, 5, 1};
        Integer[] set2 = {2, 3, 5, 4, 2};
        Integer[] set3 = {1, 3, 6, 4, 1};

        //Read stuff
        Scanner reader = new Scanner(System.in);

        //Given faces and result
        int face1, face2;
        List<String> face3 = new ArrayList<>();

        //Get die faces
        String[] die = reader.nextLine().split(" ");
        List<String> diee = new ArrayList<>();

        for (int i = 0; i < 6; i++) {
            diee.add(die[i]);
        }

        //Get questions
        List<String> questions = new ArrayList<>();
        int n = Integer.parseInt(reader.nextLine());

        for (int i = 0; i < n; i++) {
            questions.add(reader.nextLine());
        }

        //Parse questions, search for 3rd face
        for (int i = 0; i < n; i++) {
            String[] faces = questions.get(i).split(" ");
            face1 = diee.indexOf(faces[0]) + 1;
            face2 = diee.indexOf(faces[1]) + 1;
            boolean isFound = false;


            //1,2,6,5,1
            for (int j = 0; j < 4; j++) {
                if (set1[j] == face1 && set1[j + 1] == face2) {
                    face3.add(diee.get(3-1));
                    isFound = true;
                    break;
                }
            }

            if (isFound) {
                continue;
            }

            for (int j = 4; j > 0; j--) {
                if (set1[j] == face1 && set1[j - 1] == face2) {
                    face3.add(diee.get(4-1));
                    isFound = true;
                    break;
                }
            }

            if (isFound) {
                continue;
            }

            //2,3,5,4,2
            for (int j = 0; j < 4; j++) {
                if (set2[j] == face1 && set2[j + 1] == face2) {
                    face3.add(diee.get(1-1));
                    isFound = true;
                    break;
                }
            }

            if (isFound) {
                continue;
            }

            for (int j = 4; j > 0; j--) {
                if (set2[j] == face1 && set2[j - 1] == face2) {
                    face3.add(diee.get(6-1));
                    isFound = true;
                    break;
                }
            }

            if (isFound) {
                continue;
            }

            //1,3,6,4,1
            for (int j = 0; j < 4; j++) {
                if (set3[j] == face1 && set3[j + 1] == face2) {
                    face3.add(diee.get(5-1));
                    isFound = true;
                    break;
                }
            }

            if (isFound) {
                continue;
            }

            for (int j = 4; j > 0; j--) {
                if (set3[j] == face1 && set3[j - 1] == face2) {
                    face3.add(diee.get(2-1));
                    break;
                }
            }
        }

        //Print result
        for (String x : face3) {
            System.out.println(x);
        }

    }

}

Measured memory_bytes: 25972
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  int n;
  cin>>n;
  int a[n];
  for(int i=0;i<n;i++) cin>>a[i];
  int b[n],ans=1LL<<60LL;
  for(int i=0;i<n;i++) b[i]=a[i];
  {
    int tmp=0,sum=b[0];
    if(b[0]<=0) tmp=-b[0]+1,sum=1;
    for(int i=1;i<n;i++){
      if(sum*(sum+b[i])<0){
	sum+=b[i];
	continue;
      }
      if(sum>0){
	tmp+=sum+b[i]+1;
	sum=-1;
      }else{
	tmp+=-(sum+b[i])+1;
	sum=1;
      }
    }
    //cout<<tmp<<endl;
    ans=min(ans,tmp);
  }
  {
    int tmp=0,sum=b[0];
    if(b[0]>=0) tmp=b[0]+1,sum=-1;
    for(int i=1;i<n;i++){
      //cout<<i<<" "<<tmp<<endl;
      if(sum*(sum+b[i])<0){
	sum+=b[i];
	continue;
      }
      if(sum>0){
	tmp+=sum+b[i]+1;
	sum=-1;
      }else{
	tmp+=-(sum+b[i])+1;
	sum=1;
      }
    }
    //cout<<tmp<<endl;
    ans=min(ans,tmp);
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 1792
a = input()
b = input()
c = input()
now = "a"
len_a = len(a)
len_b = len(b)
len_c = len(c)
while True:
  if now == "a":
    if len_a <= 0:
      print("A")
      break
    now = a[-len_a]
    len_a -= 1
  elif now == "b":
    if len_b <= 0:
      print("B")
      break
    now = b[-len_b]
    len_b -= 1
  else:
    if len_c <= 0:
      print("C")
      break
    now = c[-len_c]
    len_c -= 1
              

Measured memory_bytes: 3188
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>

using namespace std;

int H,W,d;
int x;
char c[5] = "RYGB";

int main()
{
	scanf("%d%d%d",&H,&W,&d);
	for(int i = 1;i <= H; ++ i)
	{
		for(int j = 1;j <= W; ++ j)
		{
			int x = (W + i + j) / d % 2;
			int y = (W + i - j) / d % 2;
			printf("%c",c[x * 2 + y]);
		}
		printf("\n");
	}
}

Measured memory_bytes: 512
#include "bits/stdc++.h"
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>

using namespace std;

#ifndef _DEBUG
#define main_ main
#endif
#define FOR(i,s,e) for (int i = int(s); i != int(e); i++)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LONG_MAX/2)

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

template <typename T>
using keyVal = pair<string, T>;
template<typename T>
bool val_greater(const keyVal<T>& left, const keyVal<T>& right) {
	return left.second > right.second;
}

void init_global() {}

int main_() {
	int N, K, X, Y;
	cin >> N >> K >> X >> Y;

	int ans;
	if (N <= K) ans = X*N;
	else ans = X*K + Y*(N - K);

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,k;
  scanf("%d %d", &n,&k);
  int arr[n];
  for(int a=0;a<n;a++)
  scanf("%d ", &arr[a]);
  sort(arr,arr+n);
  int sum=0;
  for(int a=0;a<k;a++)
    sum+=arr[a];
  printf("%d", sum);
} 

Measured memory_bytes: 3744