akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define int int64
#define rep(i, n) for(int i=0; i<n; i++)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define V(T) vector<T>
typedef pair<int, int> P;
typedef pair<P, P> PP;
typedef vector<int> vi;
typedef vector<vi> vvi;
int max(int a, int b) {if(b>a) return b; else return a;}
int min(int a, int b) {if(b<a) return b; else return a;}

int MOD = 1e9+7;

signed main() {
    int N;
    cin >> N;
    string s1, s2;
    cin >> s1 >> s2;

    int i=0;
    bool prev = false;
    int res = 1;
    if(s1[i]==s2[i]) {i=1; prev = true; res*=3;}
    else {i=2; res*=6;}
    while(i<N) {
        if(s1[i]==s2[i]) {
            if(prev) res *= 2;
            prev = true;
            i++;
        } else {
            if(prev) res *= 2;
            else res *= 3;
            prev = false;
            i+=2;
        }
        res %= MOD;
    }
    
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
import copy

N,M=map(int,input().split())
l_2d = [[0] * N for i in range(N)]
edges=[]

def dfs(i):
    l_visit[i-1]=1
    for j in range(1,N+1):
        if l_2d_temp[i-1][j-1]==1 and l_visit[j-1]==0:
            dfs(j)
    return

for _ in range(M):
    i,j=map(int,input().split())
    edges.append([i,j])
    l_2d[i-1][j-1]=1
    l_2d[j-1][i-1]=1
    
ans=0
for edge in edges:
    i,j=edge
    l_2d_temp=copy.deepcopy(l_2d)
    l_2d_temp[i-1][j-1]=0
    l_2d_temp[j-1][i-1]=0

    l_visit=[0]*N

    dfs(1)
    if 0 in l_visit:
        ans+=1

print(ans)

Measured memory_bytes: 3572
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<bitset>
#include<deque>
#include<functional>
#include<iterator>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<utility>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz(x) (ll)((x).size())
#define pb push_back
#define mp make_pair
#define bg begin()
#define ed end()
#define all(x) (x).bg,(x).ed
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep1(i,n) for(ll i=1;i<=(n);i++)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(ll i=(n);i>=1;i--)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
const ll MOD=1000000007;
const ll INF=1000000000000000;
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;}
ll maxx(ll x,ll y,ll z){return max(max(x,y),z);}
ll minn(ll x,ll y,ll z){return min(min(x,y),z);}
ll gcd(ll x,ll y){if(x%y==0) return y;else return gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}
ll digsz(ll x){if(x==0) return 1;else{ll ans=0;while(x){x/=10;ans++;}return ans;}}
ll digsum(ll x){ll sum=0;while(x){sum+=x%10;x/=10;}return sum;}
vector<ll> pw2(62,1);vector<ll> pw10(19,1);


int main(){
    {rep1(i,61) pw2[i]=2*pw2[i-1];}
    {rep1(i,18) pw10[i]=10*pw10[i-1];}
    
    ll N; cin>>N;
    vector<ll> A(N+1);
    rep1(i,N){
        cin>>A[i];
    }
    ll ans=0;
    rep1(i,N){
        if(i%2==1 && A[i]%2==1) ans++;
    }
    cout<<ans<<endl;
}



Measured memory_bytes: 3548
#include <iostream>
#include <algorithm>
#include <string>
#include <functional>
#include <math.h>
using namespace std;

int main() {
	string s, t;
	cin >> s >> t;
	int mozisu_s = s.length(), mozisu_t = t.length();
	int s2[100], t2[100] = { 0 };
	for (int i = 0; i < 100; i++) {
		s2[i] = 100;
	}

	for (int i = 0; i < mozisu_s; i++) {
		s2[i] = s[i] - 'a' + 1;
	}
	sort(s2, s2 + mozisu_s);
	for (int i = 0; i < mozisu_t; i++) {
		t2[i] = t[i] - 'a' + 1;
	}
	sort(t2, t2 + mozisu_t, greater<int>());

	for (int i = 0; i < 100; i++) {
		if (s2[i] == 100) {
			s2[i] = 0;
		}
	}

	int mozisu_st = max(mozisu_s, mozisu_t);
	for (int i = 0; i < mozisu_st; i++) {
		if (s2[i] < t2[i]) {
			cout << "Yes" << endl;
			return 0;
		}
		else {
			if (s2[i] > t2[i]) {
				cout << "No" << endl;
				return 0;
			}
		}
	}
	cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <utility>
#include <unordered_map>

using namespace std;

int main() {
    int N;
    cin >> N;
    unordered_map<int, int> slen;
    for (int i = 0; i < N; i++) {
        int side;
        scanf("%d", &side);
        slen[side]++;
    }

    long recf = 0;
    long recs = 0;
    long sqf = 0;

    for (auto&& e : slen) {
        if (e.second >= 2) {
            if (e.first > recf) {
                recs = recf;
                recf = e.first;
            } else if (e.first > recs) {
                recs = e.first;
            }

            if (e.second >= 4 && e.first > sqf) {
                sqf = e.first;
            }
        }
    }

    long recsize = recf * recs;
    long sqsize = sqf * sqf;
    cout << (recsize > sqsize ? recsize : sqsize) << endl;
}


Measured memory_bytes: 4128
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>

using namespace std;

int h,w,n;
char initField[51][51];
char field[51][51];
int cnt=0;
bool del[51][51];

bool search(){
	int sum=0;
	for(int i=0;i<h;i++)for(int j=0;j<w;j++)if(field[i][j]!='.')sum++;
	while(sum){
		// º
		for(int j=0;j<w;j++){
			for(int i=h-2;i>=0;i--){
				if(field[i][j]!='.'){
					char ch=field[i][j];
					field[i][j]='.';
					for(int k=i;k<h;k++){
						if(k+1==h||field[k+1][j]!='.'){
							field[k][j]=ch;
							break;
						}
					}
				}
			}
		}
		memset(del,0,sizeof(del));
		int dec=0;
		for(int i=0;i<h;i++){
			for(int j=0;j<w;j++){
				if(field[i][j]=='.')continue;
				// tate
				int cnt=0;
				for(int k=i;k<h;k++){
					if(field[i][j]==field[k][j])cnt++;
					else break;
				}
				if(cnt>=n){
					for(int k=i;k<h;k++){
						if(field[i][j]==field[k][j])del[k][j]=true;
						else break;
					}
				}
				// yoko
				cnt=0;
				for(int k=j;k<w;k++){
					if(field[i][j]==field[i][k])cnt++;
					else break;
				}
				if(cnt>=n){
					for(int k=j;k<w;k++){
						if(field[i][j]==field[i][k])del[i][k]=true;
						else break;
					}
				}
			}
		}
		for(int i=0;i<h;i++)for(int j=0;j<w;j++)if(del[i][j])field[i][j]='.',dec++;
		if(dec==0)return false;
		sum-=dec;
	}
	return true;
}

int main(){

	cin>>h>>w>>n;
	bool ok=false;
	for(int i=0;i<h;i++)for(int j=0;j<w;j++)cin>>initField[i][j];
	for(int i=0;i<h;i++){
		for(int j=0;j<w-1;j++){
			for(int k=0;k<h;k++)for(int l=0;l<w;l++)field[k][l]=initField[k][l];
			cnt++;
			swap(field[i][j],field[i][j+1]);
			ok|=search();
			if(ok)break;
		}
		if(ok)break;
	}
	if(ok)cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
	return 0;
}

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

using namespace std;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int N;
	cin >> N;
	vector<int> A(N);
	int B;
	for (int i = 0; i < N - 1; i++){
		cin >> B;
		A[B-1]++;
	}

	for (int i = 0; i < N; i++){
		cout << A[i] << endl;
	}

	return 0;
}

Measured memory_bytes: 3988
"""
A - Double Helix
https://atcoder.jp/contests/abc122/tasks/abc122_a
"""
if __name__ == '__main__':
    input = str(input())
    if input == 'A':
        print("T")
    if input == 'T':
        print("A")
    if input == 'C':
        print("G")
    if input == 'G':
        print("C")

Measured memory_bytes: 2940
import numpy as np

N = int(input())
s = np.array([input() for _ in range(N)])
print('AC x {}'.format(np.count_nonzero(s=='AC')))
print('WA x {}'.format(np.count_nonzero(s=='WA')))
print('TLE x {}'.format(np.count_nonzero(s=='TLE')))
print('RE x {}'.format(np.count_nonzero(s=='RE')))


Measured memory_bytes: 36748
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, a, b) for(int i = (a); i <= (b); i++)
#define PER(i, a, b) for(int i = (a); i >= (b); i--)
#define rep(i, a, b) for(int i = (a); i < (b); i++)
#define all(S) (S).begin(), (S).end()
#define pf push_front
#define pb push_back
#define mk make_pair
#define S second
#define F first
typedef long long ll;
typedef long double lf;
typedef pair<int, int> ii;
typedef pair<ii, ii> pii;

int main(int argc, char ** argv) {
	ll N, ans = (1LL<<60);
	cin >> N;
	for(ll i = 1; i*i <= N; i++)
		if(!(N%i)) ans = min(ans, i+N/i-2);
	cout << ans << "\n";
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <math.h>

using namespace std;

int calcTimes(int t, int n, int k) {
	if (n >= k) return 0;
	if (n * 2 >= k) return t + 1;
	return calcTimes(t + 1, n * 2, k);
}

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

	int coinTimes;
	double rate = 0;
	for (int i = 1; i <= n; i++) {
		coinTimes = calcTimes(0, i, k);

		rate += pow(0.5, coinTimes);
	}
	rate /= n;

	cout << setprecision(12) << rate << endl;

	return 0;
}

Measured memory_bytes: 256
/***********************
*  Author: xuziyuan    * 
***********************/

#include <bits/stdc++.h>

#define rt0 return 0
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define replet(c) for(char c='a';c<='z';c++) 
#define LL long long
#define pii pair <int,int>
#define pb push_back
#define fi first
#define se second
#define mpr make_pair
#define sqr(a) ((a)*(a))

using namespace std;

const LL MOD=1e9+7;

int n,m,r[2010][2010],c[2010][2010],ans=0;
string s[2010];

int main()
{
	cin>>n>>m;
	rep(i,n) cin>>s[i];
	rep(i,n)
	{
		rep(j,m)
		{
			if(s[i][j]=='#') continue;
			int p=j;
			while(p<m&&s[i][p]=='.') p++;
			for(int k=j;k<p;k++) r[i][k]=p-j;
			j=p-1;
		}
	}
	rep(j,m)
	{
		rep(i,n)
		{
			if(s[i][j]=='#') continue;
			int p=i;
			while(p<n&&s[p][j]=='.') p++;
			for(int k=i;k<p;k++) c[k][j]=p-i;
			i=p-1;
		}
	}
	rep(i,n) rep(j,m) ans=max(ans,r[i][j]+c[i][j]-1);
	cout<<ans<<endl;
	rt0;
}


Measured memory_bytes: 35840
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
int main(){
	int a,b;
	while(cin>>a>>b,a||b){
		map<int,int>in;
		vector<int>v;
		rep(i,a){
			int n;
			cin>>n;
			rep(j,n){
				int c;
				cin>>c;
				if(!in[c])v.pb(c);
				in[c]++;
			}
		}
		sort(all(v));
		int out=0;
		int max=0;
		int out1=0;
		rep(i,v.size())
			if(in[v[i]]>max&&in[v[i]]>=b){out1=v[i];max=in[v[i]];out=i;}
		cout<<out1<<endl;
	}
}

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

int main(){
  int W, H, N;
  cin >> W >> H >> N;
  vector<int> X(N), Y(N), A(N);
  for(int i=0; i<N; i++){
    cin >> X.at(i) >> Y.at(i) >> A.at(i);
  }
  int XL, XR, YL, YH;
  XL=0;
  XR=W;
  YL=0;
  YH=H;
  for(int i=0; i<N; i++){
    if(A.at(i)==1 && X.at(i)>XL){
      XL=X.at(i);
    }
    if(A.at(i)==2 && X.at(i)<XR){
      XR=X.at(i);
    }
    if(A.at(i)==3 && Y.at(i)>YL){
      YL=Y.at(i);
    }
    if(A.at(i)==4 && Y.at(i)<YH){
      YH=Y.at(i);
    }
  }
  int Ans=(XR-XL)*(YH-YL);
  if(XR-XL>0 && YH-YL>0){
    cout << Ans << endl;
  }
  else{
    cout << 0 << endl;
  }
}
    

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

int n,gcDPN[100005],gcBLKG[100005],a[100005],ans;
int main(){
	scanf("%d",&n);
	for(int i  =1;i<=n;i++){
		scanf("%d",&a[i]);
		gcDPN[i] = __gcd(gcDPN[i-1],a[i]);
	}
	for(int i = n;i>=1;i--){
		gcBLKG[i] = __gcd(gcBLKG[i+1],a[i]);
	}
	
	for(int i = 1;i<=n;i++){
		ans = max(ans, __gcd(gcDPN[i-1],gcBLKG[i+1]));
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 1408
#include <iostream>



using namespace std;



int main()



{



   int S, h, m, s;



cin >> S;



   h=S/60/60;



   m=S/60-h*60;



   s=S-h*60*60-m*60;



cout << h << ":" << m << ":" << s << endl;



   return 0;



}


Measured memory_bytes: 3088
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}

int main(){
  ll h,w,n; cin >> h >> w >> n;
  map<pair<ll,ll>,ll> m;
  rep(i,n){
    ll a,b; cin >> a >> b;
    rep(j,3)rep(k,3){
      if(a+j-2 > 0 && a+j-2 < h-1 && b+k-2 > 0 && b+k-2 < w-1){
        m[make_pair(a+j-2,b+k-2)]++;
      }
    }
  }
  
  ll v[10] = {0};
  ll cnt = 0;
  for(auto m1:m){
    //printf("(%d,%d) -> %d\n",m1.first.first,m1.first.second,m1.second);
    v[m1.second]++;
  }
  rep(i,10) cnt += v[i];
  v[0] = (h-2)*(w-2)-cnt;
  rep(i,10){
    printf("%lld\n",v[i]);
  }
  
  return 0;
}

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

int main() {
	int n;
	cin >> n;
	int ans = 0;
	int tmp = 1001001001;
	rep(i, n) {
		int np; cin >> np;
		tmp = min(tmp, np);
		if (tmp >= np) ans++;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
N,W = map(int, input().split())

wv = [[int(x) for x in input().split()] for _ in range(N)]

dp = [[float("inf") for i in range(10**5+1)] for j in range(N+1)]
dp[0][0] = 0

for i in range(N):
    for sum_v in range(10**5+1):
        if sum_v - wv[i][1] >= 0:
            dp[i+1][sum_v] = min(dp[i][sum_v - wv[i][1]] + wv[i][0],dp[i][sum_v])
        else:
            dp[i+1][sum_v] = dp[i][sum_v]

ans = 0
for sum_v in range(10**5+1):
    if dp[N][sum_v] <= W:
        ans = sum_v
print(ans)

Measured memory_bytes: 320116
n = int(input())
s = input()

ok = 0

for ii in [[0,0], [0,1], [1,0], [1,1]]:
    A = [ii[0], ii[1]]
    # print(A)
    for i in range(1, n-1):
        A.append(int((A[-1] == 1) ^ (A[-2] == 1) ^ (s[i] == "x")))
    # print(A)
    if (A[-2] == 1) ^ (A[-1] == 1) ^ (A[0] == 1) ^ (s[-1] == "o") and \
        (A[-1] == 1) ^ (A[0] == 1) ^ (A[1] == 1) ^ (s[0] == "o"):
        ok = 1
        break

if ok == 0:
    print(-1)
else:
    ans = []
    for i in range(n):
        if A[i] == 0:
            ans.append("S")
        else:
            ans.append("W")
    print("".join(ans))

Measured memory_bytes: 64584
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <map>
#include <set>

#define MIN_INT -2147483648
#define MAX_INT 2147483647
#define MIN_LONG -9223372036854775808L
#define MAX_LONG 9223372036854775807L
#define PI 3.141592653589793238462643383279502884L

#define long long long int

using std::vector;
using std::map;
using std::set;
using std::string;
using std::pair;
using std::cin;
using std::cout;
using std::cerr;

// @author: pashka

vector<pair<int, int>> aa[2];

int main() {
    std::ios::sync_with_stdio(false);

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

    for (int k = 0; k < 2; k++) {
        map<int, int> z;
        for (int i = k; i < n; i += 2) {
            z[a[i]]++;
        }
        vector<pair<int, int>> q;
        for (auto p : z) {
            q.push_back({p.second, p.first});
        }
        q.push_back({0, 1});
        q.push_back({0, 2});
        std::sort(q.begin(), q.end());
        for (int i = 0; i < 2; i++) {
            aa[k].push_back(q[q.size() - 1 - i]);
        }
    }

    int res = n;

    for (auto x : aa[0]) {
        for (auto y : aa[1]) {
//            cout << x.first << ":" << x.second << " " << y.first << ":" << y.second << "\n";
            if (x.second != y.second) {
                res = std::min(res, n - x.first - y.first);
            }
        }
    }

    cout << res << "\n";

    return 0;
}

Measured memory_bytes: 3952
#pragma GCC optimize("Ofast,inline,unroll-loops,fast-math")
#include <iostream>
#include <algorithm>
#include <cstdio>
#define N 5020
#define K 197
using namespace std;

int n;
char a[N];
unsigned long long f[N], p[N];

unsigned long long Hash(int l, int r)
{
    return f[r] - f[l - 1] * p[r - l + 1];
}

int BSFind(int x, int y)
{
    int l, m, r;

    for(l = 0, r = min(n - y + 1, y - x) + 1; l + 1 < r; )
    {
        m = (l + r) >> 1;
        if(Hash(x, x + m - 1) == Hash(y, y + m - 1))
            l = m;
        else
            r = m;
    }

    return l;
}

int main(void)
{
    int i, j, o;

    scanf("%d %s", &n, a + 1);
    for(i = p[0] = 1; i < N; i ++)
        p[i] = p[i - 1] * K;
    for(i = 1; i <= n; i ++)
        f[i] = f[i - 1] * K + a[i];

    for(i = 1, o = 0; i <= n; i ++)
        for(j = i + 1; j <= n; j ++)
            o = max(o, BSFind(i, j));
    printf("%d\n", o);

    return 0;
}


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

int main() {
  
  string s;
  cin >> s;
  
  int c=0;
  for (int i=0; i<s.size()/2; i++) {
    if (s.at(i)!=s.at(s.size()-1-i)) c++;
  }
  
  cout << c << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
 
int main(void) {
	int n, sum = 0;
	scanf("%d", &n);
	sum = n / 100000 + (n % 100000) / 10000 + (n % 10000) / 1000 + (n % 1000) / 100 + (n % 100) / 10 + n % 10;
	if (sum == 1) sum = 10;
	printf("%d", sum);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
int main() {
  string T;
  cin>>T;
  for(int i=0;i<T.size();i++){
    if(T[i]=='?'){T[i]='D';}
  }
  cout<<T<<endl;
  return 0;}

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

main()
{
  int l[200];
  int n;
  int ans=0;

  cin >> n;
  for(int i=0;i<2*n;i++){
    cin >> l[i];
  }

  sort(l,l+(2*n));

  for(int i=0;i<2*n;i+=2){
    ans+=l[i];
  }

  cout << ans << endl;

  return (0);
}


Measured memory_bytes: 256
from collections import deque


def main():
    w, h, n = map(int, input().split())
    sx, sy = map(int, input().split())
    sx -= 1
    sy -= 1
    limits = []
    paths = []
    bombs = set()
    for _ in range(n):
        line = list(map(int, input().split()))
        limit = line[0]
        line = line[1:]
        path = []
        for i in range(limit):
            x = line[i * 2] - 1
            y = line[i * 2 + 1] - 1
            path.append((x, y))
        bombs.add(path[-1])
        limits.append(limit)
        paths.append(path)

    rest = [i for i in range(n) if (sx, sy) != paths[i][0]]
    que = deque()
    que.append((sx, sy, rest, 0))
    dic = {}
    dic[(sx, sy, tuple(rest), 0)] = True
    vec = ((1, 0), (1, -1), (0, -1), (-1, -1), (-1, 0), (-1, 1), (0, 1), (1, 1), (0, 0))
    while que:
        x, y, rest, time = que.popleft()
        if not rest:
            print(time)
            break

        for dx, dy in vec:
            nx, ny = x + dx, y + dy
            if (nx, ny) in bombs or (not 0 <= nx < w) or (not 0 <= ny < h):continue
            new_time = time + 1
            removes = []
            cont_flag = False
            for i in rest:
                if new_time >= limits[i]:
                    cont_flag = True
                    break
                if paths[i][new_time] == (nx, ny):
                    removes.append(i)
            if cont_flag:continue
            new_rest = [i for i in rest if i not in removes]
            if (nx, ny, tuple(new_rest), new_time) not in dic:
                dic[(nx, ny, tuple(new_rest), new_time)] = True
                que.append((nx, ny, new_rest, new_time))
    else:
        print(-1)


main()




Measured memory_bytes: 36880
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);--(i))
#define each(i, a) for(auto &i : a)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x) ((y) < 0 || h <= (y) || (x) < 0 || w <= (x))
#define line cout << "------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
#define stop system("pause")
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
const long double pi = acos(-1);
const long double eps = 1e-10;
template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; }return 0; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; }return 0; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }

int n;
vector<VI> a;
VL memo;
ll solve(int bit) {
    if (bit == (1 << n) - 1)return 1LL;
    if (memo[bit] != -1)return memo[bit];

    int k = 0;
    FOR(i, 0, n)if(bit & (1 << i))++k;

    ll ret = 0;
    FOR(i, 0, n) {
        if (bit & (1 << i))continue;
        if (a[k][i] == 0)continue;
        (ret += solve(bit | (1 << i))) %= mod;
    }

    return memo[bit] = ret;
}

int main() {
    init();

    cin >> n;
    a = vec<int>(n, n); cin >> a;
    memo.resize(1 << n, -1);
    cout << solve(0) << "\n";
}


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


def solve(N: int, D: int, X: "List[int]", Y: "List[int]"):
    cnt = 0
    for x, y in zip(X, Y):
        if pow(x, 2) + pow(y, 2) <= pow(D, 2):
            cnt += 1
    print(cnt)
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    D = int(next(tokens))  # type: int
    X = [int()] * (N)  # type: "List[int]"
    Y = [int()] * (N)  # type: "List[int]"
    for i in range(N):
        X[i] = int(next(tokens))
        Y[i] = int(next(tokens))
    solve(N, D, X, Y)

if __name__ == '__main__':
    main()

Measured memory_bytes: 71584
#include <bits/stdc++.h>
#include<math.h>
#define rep(i,n) for (int i = 0; i < (n) ; ++i)
using namespace std;
using ll = long long ;
using P = pair<int, int> ;
#define PI 3.14159265358979323846264338327950

int main(){
    int n, d;
    cin >> n >> d ;
    vector<int> x (n) ;
    vector<int> y (n) ;
    rep(i, n){
        cin >> x[i] >> y[i] ;
    }
    int ans = 0;
    rep(i, n){
        if(pow(x[i], 2) + pow(y[i], 2) <= pow(d, 2)){
            ans++ ;
        }
    }
    cout << ans << endl ;
}


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

int main() {
  long long int a,b,c;
  cin>>a>>b>>c;
  if(a%2==0||b%2==0||c%2==0){
    cout<<0<<endl;
    return 0;
    }
  if(max(a,max(b,c))==a){
    cout<<b*c<<endl;
    return 0;
    }
  if(max(a,max(b,c))==b){
    cout<<a*c<<endl;
    return 0;
    }
  cout<<a*b<<endl;
}


Measured memory_bytes: 256
#[allow(dead_code)]
pub struct Scanner<'a> {
    _buf: &'a str,
    iter: ::std::str::SplitWhitespace<'a>,
}

#[allow(dead_code)]
impl<'a> Scanner<'a> {
    pub fn new(buf: &'a str) -> Self {
        Scanner {
            _buf: buf,
            iter: buf.split_whitespace(),
        }
    }

    pub fn array<T>(&mut self, n: usize) -> Vec<T>
        where T: ::std::str::FromStr,
              T::Err: ::std::fmt::Debug,
    {
        let mut res = Vec::with_capacity(n);
        for _ in 0..n {
            res.push(self.value());
        }
        res
    }

    pub fn value<T>(&mut self) -> T
        where T: ::std::str::FromStr,
              T::Err: ::std::fmt::Debug,
    {
        self.next().parse().unwrap()
    }

    pub fn chars(&mut self) -> Vec<char> {
        self.next().chars().collect()
    }

    fn next(&mut self) -> &str {
        self.iter.next().unwrap()
    }
}

fn main() {
    let mut _input = String::new();
    {
        use ::std::io::Read;
        ::std::io::stdin().read_to_string(&mut _input).unwrap();
    }
    let mut sc = Scanner::new(&_input);

    let n = sc.value::<i64>();
    let m = sc.value::<i64>();
    let mut a = Vec::with_capacity(m as usize);
    for i in 0..m {
        let p = sc.value::<i64>() - 1;  // 0-based
        let y = sc.value::<i64>();
        a.push((y,p,i));
    }

    let mut ans = vec![String::new(); m as usize];
    let mut cnt = vec![0; n as usize];
    a.sort();
    for (_,p,i) in a {
        cnt[p as usize] += 1;
        ans[i as usize] = format!("{:06}{:06}", p+1, cnt[p as usize]);
    }

    for s in ans {
        println!("{}", s);
    }
}


Measured memory_bytes: 16636
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <chrono>
using namespace std;

int main(int argc, const char * argv[]) {
    
    // receive a number
    int D, G;
    cin >> D >> G;
    
    vector<int> p(D), c(D);// p.at(i): # of questions with 100i pts. c.at(i): complete bonus
    for (int i = 0; i < D; i++) {
        cin >> p.at(i) >> c.at(i);
    }
    
    int min_n = 0;
    for (int n: p) {
        min_n += n;// initialize by the total number of problems
    }
    
    for (long long i = 0; i < (1 << D); i++) {// denotes which section you got complete bonus
        int score = 0;
        int n_solved = 0;
        
        for (int j = 0; j < D; j++) {
            if ((i >> j) & 1) {
                score += p.at(j) * 100 * (j + 1) + c.at(j);
                n_solved += p.at(j);
            }
        }
        
        if (n_solved >= min_n) continue;
        
        if (score >= G) {
            min_n = min(min_n, n_solved);
        } else {
            for (int j = D - 1; j >= 0; j--) {
                bool flag = false;
                if (!(bool)((i >> j) & 1)) {// j denotes the section in which all problems are not solved.
                    int remainder = p.at(j);
                    while (remainder > 1) {
                        score += 100 * (j + 1);
                        n_solved++;
                        remainder--;
                        
                        if (n_solved >= min_n) {
                            flag = true;
                            break;
                        }
                        
                        if (score >= G) {
                            min_n = min(min_n, n_solved);
                            flag = true;
                            break;
                        }
                    }
                    if (flag) break;
                }
            }
        }
    }
    
    cout << min_n << endl;
}


Measured memory_bytes: 256
class Node():
    def __init__(self, key, p, l, r):
        self.key, self.p, self.l, self.r = key, p, l, r


class BinarySearchTree():
    def __init__(self):
        self.tree = []
        self.root = -1

    def insert(self, key):
        y = -1  # parent of x
        x = self.root
        while x != -1:
            y = x
            if key < self.tree[x].key:
                x = self.tree[x].l
            else:
                x = self.tree[x].r
        self.tree.append(Node(key, y, -1, -1))
        z = len(self.tree) - 1
        if y == -1:
            self.root = z
        elif key < self.tree[y].key:
            self.tree[y].l = z
        else:
            self.tree[y].r = z

    def find(self, key, x=0):
        while x != -1 and key != self.tree[x].key:
            if key < self.tree[x].key:
                x = self.tree[x].l
            else:
                x = self.tree[x].r
        return x

    def preorder_traversal(self, u=0):
        if u == -1:
            return
        print(' ' + str(self.tree[u].key), end='')
        self.preorder_traversal(self.tree[u].l)
        self.preorder_traversal(self.tree[u].r)

    def inorder_traversal(self, u):
        if u == -1:
            return
        self.inorder_traversal(self.tree[u].l)
        print(' ' + str(self.tree[u].key), end='')
        self.inorder_traversal(self.tree[u].r)


def main():
    n = int(input())
    bst = BinarySearchTree()
    for _ in range(n):
        order = input().split()
        if order[0] == 'insert':
            key = int(order[1])
            bst.insert(key)
        elif order[0] == 'print':
            bst.inorder_traversal(0)
            print('')
            bst.preorder_traversal(0)
            print('')
        elif order[0] == 'find':
            key = int(order[1])
            print('yes' if bst.find(key) != -1 else 'no')


if __name__ == '__main__':
    main()



Measured memory_bytes: 101008
#include<iostream>
using namespace std;
int main(){
  int H,R;
  cin>>H>>R;
  int ans=H+R;
  if(ans>0)
    cout<<1<<endl;
  else if(ans<0)
    cout<<-1<<endl;
  else
    cout<<0<<endl;
  return 0;
}

Measured memory_bytes: 3092
# coding: utf-8
# Your code here!
N = int(input())
line = list(map(int,input().split()))
a=1
b=0
for i in range(N):
    a*=line[i]
    if a>1000000000000000000:
        for j in range(i,N):
            if line[j]==0:
                print("0")
                b=1
                break
            if j==N-1:
                print(-1)
                b=1
                break
        break
       
if b ==0:
    print(a)

Measured memory_bytes: 21656
#include<iostream>
#include<queue>
#define INF 1e9
using namespace std;

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

typedef pair<int,int>P;

int bfs(int w,int h){
  
  queue<P> Q;
  
  P start;
  start.first=1;start.second=1;
  Q.push(start);
  
  for(int i=1 ; i < h*2 ; i++){
    for(int j=1 ; j < w*2 ; j++){
      d[i][j]=INF;
    }
  }
  d[1][1]=1;
  
  while(!Q.empty()){
    P temp;
    temp=Q.front();
    Q.pop();
    int x=temp.first;
    int y=temp.second;
    if(x==w*2-1 && y==h*2-1)break;
    for(int i=0 ; i < 4 ; i++){
      int nx=x+2*dx[i];
      int ny=y+2*dy[i];
      int wx=x+dx[i];
      int wy=y+dy[i];
      if(nx > 0 && ny > 0 && nx < w*2 && ny < h*2){
	if(maze[wy][wx] == 0 && d[ny][nx] == INF){
	  d[ny][nx]=d[y][x]+1;
	  P temp2;
	  temp2.first=nx;
	  temp2.second=ny;
	  Q.push(temp2);
	}
      } 
    }
  }
  
  return d[h*2-1][w*2-1];
}
int main(){
  
  int w,h;

  while(1){
    
    cin >>w>>h;
    if(w==0 && h==0)break;

    for(int i=1 ; i < h*2 ; i++){
      if(i%2){
	for(int j=2 ; j < w*2 ; j+=2){
	  cin >>maze[i][j];
	}
      }else{
	for(int j=1 ; j < w*2 ; j+=2){
	  cin >>maze[i][j];
	}
      }
    }

    int min=bfs(w,h);
    if(min == INF){
      cout <<"0"<<endl;
    }else{
      cout <<min<<endl;
    }

  } 
  return 0;
}

Measured memory_bytes: 1244
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair <int, int> P;
#define rep( i, n, m ) for(int i = ( n ); i < ( m ); i++)
#define rep_d( i, n, m ) for(int i = ( n ) - 1; i >= ( m ); i--)
#define sort_asc( X ) sort(( X ).begin(), ( X ).end())
#define sort_desc( X ) sort(( X ).begin(), ( X ).end(), greater <>())

template <class T> bool chmax( T& a, T b );
template <class T> bool chmin( T& a, T b );
int* eratosthenes( int N );
bool bit_search( int pattern, int N );
template <class T> void cumulative_sum( T array, size_t N );

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

typedef struct {
	vector <int> to;
	int cost;
	bool is_visited;
} edge;
int main( void ){
	string S; cin >> S;
	int ans = 0, cnt = 0;
	rep( i, 0, S.size()){
		if(S[ i ] == 'A' || S[ i ] == 'T' || S[ i ] == 'C' || S[ i ] == 'G'){
			cnt++;
		}
		else {
			ans = max( ans, cnt );
			cnt = 0;
		}
	}
	cout << max( ans, cnt ) << endl;
}

int* eratosthenes( int N ){
	int* prime_array = new int[ N + 1 ];
	int lim = N;
	prime_array[ 0 ] = 0;
	prime_array[ 1 ] = 0;
	rep( i, 2, N + 1 ){
		prime_array[ i ] = 1;
	}
	rep( i, 2, lim ){
		if (prime_array[ i ] == 0)
			continue;
		lim = N / i;
		for(int j = i * 2; j < N + 1; j += i){
			prime_array[ j ] = 0;
		}
	}
	return prime_array;
}
template <class T> void cumulative_sum( T array, size_t N ) {
	rep( i, 1, N + 1 ){
		array[ i ] += array[ i - 1 ];
	}
}
template <class T> bool chmax( T& a, T b ) {
	if (a < b){
		a = b; return true;
	}
	return false;
}
template <class T> bool chmin( T& a, T b ) {
	if (a > b){
		a = b; return true;
	}
	return false;
}
bool bit_search( int pattern, int N ){
	int cnt = 0;
	rep( bit, 0, N ){
		if (pattern & ( 1 << bit )){
			cnt++;
		}
	}
	return true;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a, b, c, d, e, k;
  cin >> a >> b >> c >> d >> e >> k;
  if(e-a<=k) {
      cout << "Yay!" << '\n';
  } else {
      cout << ":(" << '\n';
  }
}

Measured memory_bytes: 256
import java.util.*;

public class Main{

    public static List<Integer> P;
    public static void main(String args[]){
        Scanner scanner = new Scanner(System.in);
        long A = scanner.nextLong();
        long B = scanner.nextLong();

        int div = 2;
        int maxdivA = (int)Math.sqrt(A);
        Set<Integer> primeA = new HashSet<>();
        primeA.add(1);
        while(maxdivA >= div){
            if(A % div == 0){
                A = A / div;
                primeA.add(div);
            }else{
                div++ ;
            }
        }
        primeA.add((int)A);
        div = 2;
        int maxdivB = (int)Math.sqrt(B);
        Set<Integer> primeB = new HashSet<>();
        primeB.add(1);
        while(maxdivB >= div){
            if(B % div == 0){
                B = B / div;
                primeB.add(div);
            }else{
                div++ ;
            }
        }
        primeB.add((int)B);
        // System.out.println(primeA);
        // System.out.println(primeB);
        primeA.retainAll(primeB);
        System.out.println(primeA.size());
    }
}

Measured memory_bytes: 24020
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Queue;
import java.util.Scanner;
 

//result = Math.pow(num1, num3)
//StringBuffer str = new StringBuffer(hoge1);
//String hoge2 = str.reverse().toString();
//map.containsKey(A)

//Map<String, Integer> map = new HashMap<String, Integer>(n);
/*for ( キーのデータ型 key : マップの名前.keySet() ) {
	データのデータ型 data = マップの名前.get( key );
	
	// keyやdataを使った処理;
}*/
//int i = Integer.parseInt(s);
//Queue<String> qq=new ArrayDeque<>(); //add,poll,peek
//Deque<String> qq=new ArrayDeque<>();//push,pop,peek
//ArrayList<String> cc = new ArrayList<>(n);
//Collections.sort(list);
//Array.sort(list);
//Arrays.asList(c).contains("a")
//list.set(1,"walk");
public class Main {
	static int a1[]= {0,-1,0,1};
	static int b1[]= {-1,0,1,0};
	private static Scanner sc = new Scanner(System.in);
	static void p(String ans) {System.out.println(ans);};
	static void p(int ans) {System.out.println(ans);};
	static void p(long ans) {System.out.println(ans);};
	static void p(double ans) {System.out.println(ans);};
	static int K;
	public static void main(String[] args) {
		int N=sc.nextInt();
		int M=sc.nextInt();
		int C=sc.nextInt();
		int B[]=new int[M];
		int ctn=0;
		for(int i=0;i<M;i++) {
			B[i]=sc.nextInt();
		}
		int Ai[][]=new int[N][M];
		for(int a=0;a<N;a++) {
			int ans=0;
			for(int b=0;b<M;b++) {
				Ai[a][b]=sc.nextInt();
				ans+=Ai[a][b]*B[b];
			}
			if(ans+C>0) {
				ctn++;
			}
		}
		p(ctn);
	}
}


Measured memory_bytes: 23892
#include <iostream>
#include <stack>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
    stack<int> S1;
    stack<pair<int, int>> S2;
    int sum{ 0 };
    char ch;
    for (int i = 0; cin >> ch; i++) {
        if (ch == '\\') S1.push(i);
        else if (ch == '/' && (int)S1.size() > 0) {
            int j = S1.top();
            S1.pop();
           
            sum += i - j;
            int a = i - j;
            while ((int)S2.size() > 0 && S2.top().first > j) {
                a += S2.top().second;
                S2.pop();
            }
            S2.push(make_pair(j,a));
        }
    }

    vector<int> ans;
    while ((int)S2.size() > 0) {
        ans.push_back(S2.top().second);
        S2.pop();
    }
    reverse(ans.begin(), ans.end());

    int nSize = (int)ans.size();
    
    cout << sum << endl;
    cout << nSize;
    for (int i = 0; i < nSize; i++) {
        cout << " ";
        cout << ans[i];
    }
    cout << endl;

    return 0;
}



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

int main()
{
	string a;
	while(cin>>a){
		int t=0;
		for(int i=0;i<3;i++){
			if(a[i]=='1') t++;
		}
		cout<<t<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
#define _FORTIFY_SOURCE 0
#pragma GCC optimize("Ofast")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,popcnt,abm,mmx,tune=native")
#pragma GCC optimize("fast-math")

/*#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")

#pragma GCC optimize("fast-math")*/

#include <iostream>
#include <string>
#include <stdio.h>
#include <vector>
#include <set>           
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <deque>
#include <algorithm>
#include <cstring>
#include <math.h>
#include <time.h>
#include <random>

#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define int long long
#define double long double
#define left left228
#define right right228
#define x1 x1228
#define y1 y1228
#define all(x) x.begin(), x.end()

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
mt19937 rnd(time(0));

const int maxn = 3e5 + 7, mod = 1e9 + 7, inf = 1e18;
const double eps = 1e-9, pi = acos(-1);
int n, k; 

void solve() {         
    cin >> n >> k; 
    int ans = 0; 
    for (int i = 1; i <= n; ++i) { 
        int z = k - (i % k);
        if (z == k) z = 0; 
        if ((2 * z) % k) continue; 
        if (z > n) continue; 
        int p1 = (n - z) / k; 
        if (z == 0) {
            ans += p1 * p1; 
        } else {
            ans += (p1 + 1) * (p1 + 1); 
        }
    }
    cout << ans; 
}

signed main() {
//  freopen("", "r", stdin);
//  freopen("", "w", stdout);
#ifdef offline_judge
    freopen("TASK.in", "r", stdin);
    freopen("TASK.out", "w", stdout);
#endif
    srand(time(0));
    cout.precision(10);
    cout << fixed;
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    solve();
    return 0;
} 


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<string.h>
using namespace std;
int main()
{
	int a, b;
	while (cin>>a>>b)
	{
		char s[7];
		sprintf(s, "%d", a + b);
		cout << strlen(s) << endl;
	}


	return 0;
}

Measured memory_bytes: 3252
#include<bits/stdc++.h>
using namespace std;
#define next Next
#define gc getchar
#define int long long
const int N=1e6+5;
int n,m,A,B,a[1005][1005],gs1[1005],gs2[1005];
/*char buf[1<<21],*p1=buf,*p2=buf;
inline int gc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;}*/
inline int read()
{
    int ret=0,f=0;char c=gc();
    while(!isdigit(c)){if(c=='-')f=1;c=gc();}
    while(isdigit(c)){ret=ret*10+c-48;c=gc();}
    if(f)return -ret;return ret;
}
signed main()
{
	n=read();m=read();A=read();B=read();
	for(int i=1;i<=B;i++)
		for(int j=A+1;j<=m;j++)
			a[i][j]=1;
	for(int i=B+1;i<=n;i++)
		for(int j=1;j<=A;j++)
			a[i][j]=1;	
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
			printf("%d",a[i][j]);
		puts("");
	}
}

Measured memory_bytes: 8832
/************************************/
/* NoobM							*/
/* File Name : att.cpp				*/
/* Date : 11.07.2020 18:01:43 +06	*/
/************************************/

#include <bits/stdc++.h>

#define rr(i, b)    for (int i = 0; i < int(b); i++)
#define vi(n, a) vector <int> a(n); rr(i, n) cin >> a[i]
#define pvec(a) rr(i, a.size()) cout << a[i] << " "; cout << endl
#define bug(x) cout << #x << " " << x << endl
#define ll long long
#define vii vector <int>

using namespace std;

void solve() {
	int n;
	cin >> n;
	
	vi(n,a);
	
	int i = 1;
	int counter = 0;
	
	for(int x : a) {
		if(x % 2 != 0 && i % 2 != 0) counter++;
		i++;
	}
	
	cout << counter << endl;
}
 
int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
	
	int t = 1;
	//cin >> t;
	
	while (t--) {
		solve();
	}
    return 0;
}


Measured memory_bytes: 3644
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(os.Stdout)

	n := getNextInt(scanner)

	fmt.Fprintln(writer, fib(n))
	writer.Flush()

}

func fib(n int) int {
	if n <= 1 {
		return 1
	}
	dp := make([]int, n+1)
	dp[0] = 1
	dp[1] = 1
	for i := 2; i <= n; i++ {
		dp[i] = dp[i-2] + dp[i-1]
	}
	return dp[n]
}



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

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

int main() {
        while(1){
                int n,x,ans=0;
                cin>>n>>x;
                if(n==0&&x==0)break;
                for(int i=1;i<n-1;i++){
                        for(int j=i+1;j<n;j++){
                                for(int k=j+1;k<n+1;k++){
                                        if(i+j+k==x)ans++;
                                }
                        }
                }
                cout<<ans<<endl;
        }
        return 0;
}



Measured memory_bytes: 3072
#include <iostream>
#include <cstdio>
#include <string.h>
#include <vector>
using namespace std;


char A[4];

int ctoi(const char c){
  switch(c){
    case '0': return 0;
    case '1': return 1;
    case '2': return 2;
    case '3': return 3;
    case '4': return 4;
    case '5': return 5;
    case '6': return 6;
    case '7': return 7;
    case '8': return 8;
    case '9': return 9;
    default : return -1;
  }
}




int main(){
    string s;
    cin >> s;
    vector<int>v(4);

    //int型に変換
    for(int i = 0; i < 4; i++){
        v[i] = s[i] - '0';
        //printf("%d\n", v[i]);
    }

    int sum;

    for(int i = 0; i < (1 << 3); i++){
        sum = v[0];
        for(int j = 0; j < 3; j++){
            if(i & (1 << j)){
                sum = sum + v[j + 1];
            }
            else{
                sum = sum - v[j + 1];
            }
        }

        if(sum == 7){
            cout << v[0];
            for(int j = 0; j < 3; j++){
                if(i & (1 << j)){
                    cout << "+";
                }
                else{
                    cout << "-";
                }
                cout << v[j+1];
            }
            cout << "=7" << endl;

            break;
        }
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
#define FOR(i,a) for(int i=0;i<a;i++)
int a[21][21];
int main() {
	while(1){
		int n;
		cin>>n;
		if(n==0){break;}
		FOR(i,21){FOR(j,21){a[i][j]=0;}}
		FOR(i,n){int d,f;cin>>d>>f;a[f][d]++;}
		int m;
		cin>>m;
		int x=10;int y=10;
		a[10][10]=0;
		FOR(i,m){
			char p;int move;
			cin>>p>>move;
			int h;
			int dx[4]={1,0,-1,0};
			int dy[4]={0,1,0,-1};
			if(p=='N'){h=0;}
			else if(p=='E'){h=1;}
			else if(p=='S'){h=2;}
			else if(p=='W'){h=3;}
			FOR(j,move){
				x+=dx[h];y+=dy[h];
				a[x][y]=0;
			}
		}
		int ans=0;
		FOR(i,21){FOR(j,21){if(a[i][j]!=0){ans++;}}}
		if(ans==0){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}
	}
	return 0;
}

Measured memory_bytes: 1152
#include <iostream>
#include <math.h>

using namespace std;

void solve(int a, int b, int c) {
	bool f = false;
	int max_num = max (a, max(b, c));
	int sub1, sub2;
	if (max_num != a) {
		sub1 = a;
		if (max_num != b) sub2 = b;
		else sub2 = c;
	}
	else if (max_num != b) {
		sub1 = b;
		sub2 = c;
	}
	if (pow(max_num, 2) == pow(sub1, 2) + pow(sub2, 2)) f = true;
	if (f) cout << "YES" << endl;
	else cout << "NO" << endl;
}

int main() {
	int num, a, b, c;
	cin >> num;
	for (int i = 0; i<num; i++) {
		cin >> a >> b >> c;
		solve(a, b, c);
	}
	return 0;
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
#include<boost/variant.hpp>
using namespace std;
typedef long long ll;
typedef vector<boost::variant<bool, ll, int, string, double>> any;
template<typename T> inline void pr(const vector<T> &xs){
	for(int i=0; i<xs.size()-1; i++) cout<<xs[i]<<" ";
	(xs.empty()?cout:(cout<<xs[xs.size()-1]))<<endl;
}
template<typename T> inline void debug(const vector<T> &xs){
#ifdef DEBUG
	pr(xs);
#endif
}
const int INF = 1e8;
int main(){
	int N, M;
	cin >> N >> M;
	vector<int> A(M), B(M), C(M);
	vector<vector<int>> X(N, vector<int>(N, INF));
	for(int i=0; i<M; i++){
		int a, b, c;
		cin >> a >> b >> c;
		a--; b--;
		X[a][b] = c;
		X[b][a] = c;
		A[i] = a;
		B[i] = b;
		C[i] = c;
	}
	for(int i=0; i<N; i++) X[i][i] = 0;

	for(int k=0; k<N; k++){
		for(int i=0; i<N; i++){
			for(int j=0; j<N; j++){
				X[i][j] = min(X[i][j], X[i][k]+X[k][j]);
			}
		}
	}

	int ans = 0;
	for(int i=0; i<M; i++) if(X[A[i]][B[i]] < C[i]) ans++;
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
while True:
    h, w = map(int, input().split())
    if h == 0:
        break
    else:
        for i in range(h):
            if i == 0:
                print('#' * w)
            elif i == (h - 1):
                print('#' * w)
                print()
            else:
                print('#', '.' * (w - 2), '#', sep=(''))


Measured memory_bytes: 5628
import sys
S = list(map(int,list(input())))
for i in range(2**3):
    n = i
    pat = []
    sum = S[0]
    for j in range(1,4):
        if n % 2 == 0:
            pat.append('+')
            sum += S[j]
        else:
            pat.append('-')
            sum -= S[j]
        n = n // 2
    if sum == 7:
        print( '{}{}{}{}{}{}{}=7'.format(S[0],pat[0],S[1],pat[1],S[2],pat[2],S[3]))
        sys.exit()

Measured memory_bytes: 3064
#include <stdio.h>
#include <stdlib.h>
#include <math.h>


int main(){

int n,m;
scanf("%d %d",&n,&m);

int i, j, last;
if(n == 1){
last = 0;
}else{
last = (int)pow(10,n-1);
}
int ch[m][2];
for(i = 0; i < m; i++){
scanf("%d %d",&ch[i][0],&ch[i][1]);
}

int answer = -1;
for(i = pow(10,n)-1; i >= last; i--){
int judge = 0;
for(j = 0; j < m; j++){
if(i % (int)pow(10,ch[j][0]*n%(n+1)) / (int)pow(10,ch[j][0]*n%(n+1)-1) != ch[j][1]){
judge = 1;
}
}
if(judge == 0){
answer = i;
}
}

printf("%d",answer);

return 0;
}

Measured memory_bytes: 128
use proconio::{input, fastout};
use proconio::marker::Chars;

const MOD: i64 = 1_000_000_007;

#[fastout]
fn main() {
    input! {
        h: usize,
        w: usize,
        a: [Chars; h],
    }

    let dx: Vec<usize> = vec![1, 0];
    let dy: Vec<usize> = vec![0, 1];

    let mut dp = vec![vec![0i64; w]; h];
    dp[0][0] = 1;

    for y in 0..h {
        for x in 0..w {
            for i in 0..2 {
                let ny = y + dy[i];
                let nx = x + dx[i];
                if nx >= w || ny >= h {
                    continue;
                }
                if a[ny][nx] == '#' {
                    continue;
                }
                dp[ny][nx] += dp[y][x];
                dp[ny][nx] %= MOD;
                /*
                 *if dp[ny][nx] < 0 {
                 *    dp[ny][nx] += MOD;
                 *}
                 */
            }
        }
    }

    println!("{}", dp[h-1][w-1]);
}


Measured memory_bytes: 14800