akhauriyash/Code-Regression huggingface dataset:
/*Function Template*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pint;
const int MAX = 510000;
const int MOD = 1000000007;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define Rep(i, n) for(ll i = 1; i < (n); i++)
#define ALL(a)  (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll fac[MAX], finv[MAX], inv[MAX];


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;
}
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }

}
ll Len(ll n) {
  ll s=0;
  while(n!=0) s++, n/=10;
  return s;
}


ll Sint(ll n) {
  ll m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(ll i=s-1;i>=0;i--) m+=n/((ll)pow(10,i))-(n/((ll)pow(10,i+1)))*10;
  return m;
}


ll Svec(vector<ll> v){
  ll n=0;
  for(ll i=0;i<v.size();i++) n+=v[i];
  return n;
}


ll GCD(ll a,ll b) {
  return b ? GCD(b,a%b) : a;
}


ll LCM(ll a,ll b){
  return a/GCD(a,b)*b;
}


ll Factorial(ll n){
  ll m=1;
  while(n>=1) m*=n,n--;
  return m;
}

void runlength(string s,vector<pair<char,ll>> &p){
  ll x=1;
  if(s.size()==1){
    p.push_back(pair<char,ll>(s[0],1));
  }
  for(ll i=0;i<s.size()-1;i++){
    if(s[i]==s[i+1]){
      x++;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[i],x));
      }
    }else{
      p.push_back(pair<char,ll>(s[i],x));
      x=1;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[s.size()-1],x));
      }
    }
  }
}




ll COM(ll n,ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

const int MAX_N=100010;
vector<bool> sieve_of_eratosthenes(){
  vector<bool> isPrime(MAX_N+1,true);
  for(int i=2;i<=MAX_N;i++){
    if(isPrime[i]){
      for(int j=2*i;j<=MAX_N;j+=i){
        isPrime[j]=false;
      }
    }
  }
  return isPrime;
}

vector<pint> prime_factorize(ll n){
  vector<pint> ans;
  for(ll p=2;p<=sqrt(n);p++){
    if(n%p!=0) continue;
    ll cnt=0;
    while(n%p==0){
      n/=p;
      cnt++;
    }
    ans.push_back(make_pair(p,cnt));
  }
  if(n!=1) ans.push_back(make_pair(n,1));
  return ans;
}

/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
int main() {
  IOS;
  ll n;
  cin>>n;
  vector<string> v(n);
  rep(i,n) cin>>v[i];
  ll ans=0;
  rep(i,n){
    if(v[i][0]=='A') ans++;
    if(v[i]=="Un") ans--;
    if(ans<0){
      cout<<"NO"<<endl;
      return 0;
    }
  }
  if(ans==0) cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
}


Measured memory_bytes: 3236
#include<iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int Max = 1000000;
int main(){
  	int N;
    cin >> N;
    int L[N];
    for(int i=0;i<N;i++) cin >> L[i];

    sort(L, L+N);

    int up[1001];
    for(int k =0;k<1001;k++) up[k] = 0;

    int k = 0;
    int i = 0;

    while(i<N){
      while(k<=L[i]){
        up[k] = N - i;
        k++;
      }
      i++;
    }

    /*for(int i=0;i<10;i++){
      cout << up[i] << " ";
    }
    cout <<endl;*/

    long ans = 0;
    for(int i=N-1;i>=2;i--){
      for(int j=i-1;j>=1;j--){
        ans += max(0, up[L[i]-L[j]+1] - (N-j));
      }
    }

    cout << ans <<endl;

  	return 0;
}



Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/stack:512000000")
#include<utility>
#include<iostream>
#include<fstream>
#include<vector>
#include<array>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<functional>
#include<random>
#include<climits>
#include<queue>
#include<stack>
#include<deque>
#include<bitset>
#include<map>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<cassert>
#include<ccomplex>

#ifdef ONLINE_JUDGE
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")
#pragma GCC optimize("unroll-loops")
#define int128 __int128
#else
#define int128 long long
#endif

#define all(x) x.begin(), x.end()
#define mp make_pair
#define X first
#define Y second

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
mt19937_64 gen(time(nullptr));

ll mod = 1e9 + 7;

namespace {
	ll mul(ll a, ll b) {
		ll val = a * b - (ll)((ld)a * b / mod) * mod;
		if (val < 0) val += mod;
		if (val >= mod) val -= mod;
		return val;
	}
	ll poww(ll a, ll b) {
		ll val = 1;
		a %= mod;
		while (b > 0) {
			if (b % 2) val = mul(a, val);
			a = mul(a, a);
			b >>= 1;
		}
		return val % mod;
	}
	ll inv(ll a) {
		return poww(a, mod - 2);
	}
}

ll const maxn = 3e5 + 5;

vector<ll> go(ll x) {
	ll dd = x % 10;
	vector<ll>vec;
	if (dd == 0) {
		vec.push_back(x * 10 + 1);
	} else if (dd == 9) {
		vec.push_back(x * 10 + 8);
	} else {
		vec.push_back(x * 10 + dd + 1);
		vec.push_back(x * 10 + dd - 1);
	}
	vec.push_back(x * 10 + dd);
	return vec;
}

signed main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	
	ll n; cin >> n;

	ll cnt = n;

	queue<ll>q;
	vector<ll>v;
	for (ll i = 1; i <= 9; i++) q.push(i), v.push_back(i);
	if (cnt <= (ll)v.size()) {
		cout << v[cnt - 1] << endl;
		return 0;
	}
	cnt -= 9;
	ll mx = 10;
	while (true) {
		v.clear();
		ll x = q.front();
		while (x < mx) {
			for (auto xx : go(x)) {
				q.push(xx);
				v.push_back(xx);
			}
			q.pop();
			x = q.front();
		}
		mx *= 10;
		if (cnt <= (ll)v.size()) {
			sort(all(v));
			cout << v[cnt - 1] << endl;
			return 0;
		} else {
			cnt -= (ll)v.size();
		}
	}



	return 0;
}

/*


*/

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

int main(){
    int a,b,c,k;
    cin>>a>>b>>c>>k;
    bool ok=false;
    for(int i=0;i<=k;i++){
        int d=b;
        int e=c;
        int j=k-i;
        d*=pow(2,i);
        e*=pow(2,j);
        if(a<d && d<e)ok=true;
    }
    if(ok)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

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

int main()
{
	int W, a, b;

	cin >> W >> a >> b;
	
	if ( a > b ) {
		swap(a, b);
	}

	if ( a + W < b ) {
		cout << b - (a + W) << endl;
	} else {
		cout << 0 << endl;
	}

	return ( 0 );
}


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

using namespace std;

#define MAX 110

bool check(int ant[MAX],int L){
  for(int i = 0 ; i < L ; i++){
    if(ant[i] != 0) return false;
  }
  return true;
}

int main(){
  int N,L,p;
  char d;
  while(cin >> N >> L, N){
    int ant[MAX]={0};
    vector<int> tunnel[MAX],id[MAX];
    L--;
    for(int i = 0 ; i < N ; i++){
      cin >> d >> p;
      ant[p-1]++;
      id[p-1].push_back(i+1);
      tunnel[p-1].push_back((d == 'L' ? 1 : 2));
    }
    int t = 0,last;
    while(!check(ant,L)){
      vector<int> next[MAX],nid[MAX];
      last = -1;
      for(int i = 0 ; i < L ; i++){
        next[i].clear();
        nid[i].clear();
        if(ant[i] && last == -1){
          last = id[i][0];
        }
      }
      for(int i = 0 ; i < L ; i++){
        while(tunnel[i].size()){
          if(tunnel[i][0] == 1){
            tunnel[i].erase(tunnel[i].begin());
            if(i-1 >= 0){
              next[i-1].push_back(1);
              nid[i-1].push_back(id[i][0]);
              id[i].erase(id[i].begin());
            }
          }else if(tunnel[i][0] == 2){
            tunnel[i].erase(tunnel[i].begin());
            if(i+1 < L){
              next[i+1].push_back(2);
              nid[i+1].push_back(id[i][0]);
              id[i].erase(id[i].begin());
            }
          }
        }
      }
      for(int i = 0 ; i < L ; i++){
        tunnel[i] = next[i];
        id[i] = nid[i];
        if(tunnel[i].size() == 2){
          swap(tunnel[i][0],tunnel[i][1]);
        }
        ant[i] = tunnel[i].size();
      }
      t++;
    }
    cout << t << " " << last << endl;
  }
  return 0;
}

Measured memory_bytes: 1236
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
const int mod=1e9+7;
const int N=1e6+10;
void read(int &a)
{
    a=0;int d=1;char ch;
    while(ch=getchar(),ch>'9'||ch<'0') if(ch=='-') d=-1;
    a=ch^48;
    while(ch=getchar(),ch>='0'&&ch<='9') a=(a<<3)+(a<<1)+(ch^48);
    a*=d;
}
void read(ll &a)
{
    a=0;int d=1;char ch;
    while(ch=getchar(),ch>'9'||ch<'0') if(ch=='-') d=-1;
    a=ch^48;
    while(ch=getchar(),ch>='0'&&ch<='9') a=(a<<3)+(a<<1)+(ch^48);
    a*=d;
}
char s[N],t[N];
int main()
{
    scanf("%s %s",s+1,t+1);
    int n=strlen(s+1),m=strlen(t+1);
    int ans=0x3fffffff;
    for(int i=1;i+m-1<=n;i++)
    {
        int k=i,now=0;
        for(int j=1;j<=m;j++)
        {
            //cout<<s[k]<<" "<<s[j]<<endl;
            if(s[k]!=t[j]) now++;
            k++;
        }
        ans=min(ans,now);
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 3828
#include<bits/stdc++.h>
#define N 1005
using namespace std;
typedef pair<int,int> P;

int c, n;
string p[N];
bool a[N][N];

P point_lu(int y,int x){
  
  int resy=y,resx=x;
  
  if(resy>=n/2) resy=n-resy-1;
  
  if(resx>=n/2) resx=n-resx-1;

  return P(resy,resx);
}

bool check(int y,int x){

  P A=point_lu(y,x);
  
  y=A.first; x=A.second;

  char a1=p[y][x];
  char a2=p[n-y-1][x];
  char a3=p[y][n-x-1];
  char a4=p[n-y-1][n-x-1];
  
  return a1==a2&&a2==a3&&a3==a4;
}

int main(){

  cin>>c>>n;

  for(int i=0;i<n;i++) cin>>p[i];
  
  int cnt=0;
  
  for(int i=0;i<n/2;i++)
    for(int j=0;j<n/2;j++)
      if(!check(i,j)) cnt++;
      else a[i][j]=true;
  
  int ans=0;

  if(!cnt) ans++;
  
  for(int i=0;i<c-1;i++){
    
    int d;
    cin>>d;

    for(int j=0;j<d;j++){
      
      int y,x;


      cin>>y>>x;
      y--, x--;

      P R=point_lu(y,x);
      
      bool f=a[R.first][R.second];
      
      if(p[y][x]=='0') p[y][x]='1';
      else if(p[y][x]=='1') p[y][x]='0';
      
      if(check(y,x)){
	a[R.first][R.second]=true;
	if(!f) cnt--;
      }
      else if(f){
	a[R.first][R.second]=false;
	cnt++;
      }
      
    }

    if(!cnt) ans++;
  }
  
  cout<<ans<<endl;
  
  return 0;
}

Measured memory_bytes: 4568
import java.util.Scanner;

public class Main {

    private static Scanner sc;

    public Main() {
    }

    public static void main(String[] args) {
        sc = new Scanner(System.in);
        new Main().solve();
    }

    private void solve() {
        int N = sc.nextInt();
        int A = sc.nextInt();
        
        int m = N * N;
        System.out.println(m - A);
    }

}

Measured memory_bytes: 21972
#include<bits/stdc++.h>
#define rep(i,n,m) for(int i = (n); i <(m); i++)
#define rrep(i,n,m) for(int i = (n) - 1; i >=(m); i--)
#define pvec(vec) {for (auto v: vec) cout << v << ' '; cout << endl;}
#define pivec(vec) {rep(i, 0, vec.size()) cout << i << ':' << vec[i] << ' '; cout << endl;}

using namespace std;
using ll = long long;

int main()
{
    
    int num_round;
    cin >> num_round;
    vector<ll> values(num_round);
    rep(i, 0, num_round) cin >> values[i];
    reverse(values.begin(), values.end());

    ll minv, maxv;
    minv = maxv = 2;
    bool is_ok = true;
    for(auto value: values)
    {
        // after game
        ll prev_minv = ((minv + value - 1)/value) * value;
        ll prev_maxv = (maxv/value)*value + value-1;
        
        // check violation
        if (prev_minv > maxv or prev_maxv < minv)
        {
            is_ok = false;
            break;
        }
        minv = prev_minv;
        maxv = prev_maxv;
    }
    if (is_ok)
        cout << minv << ' ' << maxv << endl;
    else
        cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 4052
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <climits>
#include<iomanip>
using namespace std;

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

#define INF INT_MAX/3
#define REP(i,n) for(int i=0;i<n;i++)

double ruiseki[200001];

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

	vector<double>  arr;

	arr.resize(N);

	REP(i,N){
		int a;
		cin>>a;
		double b = double(a);
		arr[i] = (1 + b) / 2 ;
	}
	ruiseki[0] = 0;
	for(int i = 1; i <= N; i++){
		ruiseki[i] = ruiseki[i-1] + arr[i-1];
	}
	double ans = 0;
	
	for(int i = K; i <= N; i++){
		ans = max(ans,ruiseki[i] - ruiseki[i-K]);
	}
	
//	double ans = 0;	
//	double sum = 0;	
//	for(int i = 0; i < K; i++){
//		sum += arr[i];
//	}
//	for(int i = K; i < N; i++){
//		sum = sum - arr[i-K] + arr[i];
//		ans = max(ans,sum);
//	}
	cout<<fixed;
	cout<<setprecision(12)<<ans<<endl;
	return 0;
}



Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define F first
#define S second
//-std=c++11
#define print(x) printf("%.12f",x);
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define Red ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define rep(i, n) for(int i =0 ; i < n; ++i)
#define repr(i, n) for(int i=n-1;i>=0;i--)
#define Rep(i,a,b) for(int i=a;i<=b;i++)
#define Repr(i,a,b) for(int i=a;i>=b;i--)
#define pii pair < int, int >
#define iter ::iterator
#define forit(a) for(it=a.begin();it!=a.end();it++)
typedef vector<int> vi;
typedef  long long ll;
const int inf = int(1e9);
const int mod = 998244353;
const int N = (int)2e5 + 5;

void solve(){
	int n,m,c;
	cin>>n>>m>>c;
	int b[m];
	rep(i,m){
		cin>>b[i];
	}
	int cnt=0;
	while(n--){
		int a[m];
		int sum=c;
		rep(i,m){
			cin>>a[i];
			sum+=a[i]*b[i];
		}
		if(sum>0)cnt++;
	}
	cout<<cnt<<endl;
}


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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,m,i,j,k,l,w[205][205],o,f[195][195][195];
int g[195][195][17],h[195][195][195];
char s[205][205];
int minn(int x,int y){
	return x<y?x:y;
}
int maxx(int x,int y){
	return x>y?x:y;
}
int main(){
	scanf("%d%d",&n,&m);
	for(i=1;i<=n;i++)
		scanf("%s",s[i]+1);
	for(i=1;i<=n;i++)
		for(j=1;j<=m;j++)
			if(s[i][j]==s[i-1][j])
				w[i][j]=w[i-1][j];
			else
				w[i][j]=i;
	for(j=1;j<=n;j++)
		for(k=j;k<=n;k++)
			for(l=0;l<=16;l++)
				h[m+1][j][k]=m;
	
	for(i=m;i>=1;i--)
		for(j=1;j<=n;j++)
			for(k=j;k<=n;k++){
				if(w[k][i]>j)
					h[i][j][k]=i-1;
				else{
					if(s[k][i]!=s[k][i+1])
						h[i][j][k]=i;
					else
						h[i][j][k]=h[i+1][j][k];
				}
			}
	if(h[1][1][n]==m){
		cout<<0<<endl;
		return 0;
	}
	for(l=1;l<=16;l++){
		for(i=m;i>=1;i--)
			for(j=1;j<=n;j++)
				for(k=j;k<=n;k++){
					f[i][j][k]=h[h[i][j][k]+1][j][k];
					if(j==k){
						g[j][k][l]=j;
					}
					else{
						o=g[j][k-1][l];
						while(h[i][j][o]>h[i][o+1][k]&&o<k-1)
							o++;
						g[j][k][l]=o;
						f[i][j][k]=maxx(f[i][j][k],maxx(
						minn(h[i][j][o-1],h[i][o][k]),
						minn(h[i][j][o],h[i][o+1][k])));
					}
				}
		for(i=m;i>=1;i--)
			for(j=1;j<=n;j++)
				for(k=j;k<=n;k++)
					h[i][j][k]=f[i][j][k];
		if(h[1][1][n]==m){
			printf("%d\n",l);
			return 0;
		}
	}
	return 0;
}

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

using namespace std;

#define inf 1<<30
#define llong long long
#define usd unsigned
#define pqueue priority_queue
#define mp make_pair
#define pb push_back
#define fn fill_n
typedef pair<int, int> P;
typedef struct data{
	int now;
	int cost;
}data;
int nw[9] = {0, 1, 0, -1, -1, 1, 1, -1, 0};
int nh[9] = {1, 0, -1, 0, 1, 1, -1, -1, 0};

usd llong int K;
string S;

int main(){
	cin >> S >> K;
	if(K > S.size()){
		for(int i = 0; i < S.size(); i++){
			if(S[i] != '1'){
				cout << S[i] << endl;
				return 0;
			}
		}
		cout << '1' << endl;
	}else{
		bool check = true;
		char ans = '1';
		for(int i = 0; i < K && check; i++){
			if(S[i] != '1'){
				check = false;
				ans = S[i];
			}
		}
		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		for(int i=0;i<n;i++) {
			int a = mcxiToInteger(sc.next());
			int b = mcxiToInteger(sc.next());
			System.out.println(integerToMcxi(a+b));
		}
	}
	
	public static int mcxiToInteger(String s) {
		int n = 1;
		int ret = 0;
		for(int i=0;i<s.length();i++) {
			char c = s.charAt(i);
			if ('0' <= c && c <= '9') {
				n = c - '0';
			}else{
				switch (c) {
				case 'm':
					ret += n * 1000;
					break;
				case 'c':
					ret += n * 100;
					break;
				case 'x':
					ret += n * 10;
					break;
				case 'i':
					ret += n;
					break;
				}
				n = 1;
			}
		}
		return ret;
	}
	
	static char[] mcxi = {'m','c','x','i'};
	public static String integerToMcxi(int n) {
		StringBuilder sb = new StringBuilder();
		int m = 1000;
		for(int i=0;i<4;i++) {
			int x = (n / m) % 10;
			if (x >= 2) {
				sb.append(x);
			}
			if (x >= 1) {
				sb.append(mcxi[i]);
			}
			m /= 10;
		}
		return sb.toString();
	}

}

Measured memory_bytes: 25588
import os
import sys
from collections import deque

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353


N, M = list(map(int, sys.stdin.buffer.readline().split()))
AB = [list(map(int, sys.stdin.buffer.readline().split())) for _ in range(N - 1 + M)]

outs = [0] * (N + 1)
graph = [[] for _ in range(N + 1)]
parents = [[] for _ in range(N + 1)]
for a, b in AB:
    graph[a].append(b)
    parents[b].append(a)
    outs[a] += 1

leaves = deque()
for v in range(1, N + 1):
    if not graph[v]:
        leaves.append(v)

order = [-1] * (N + 1)
j = 0
# トポロジカルソートしたときに先に取り除かれる親が本物
while leaves:
    v = leaves.popleft()
    for p in parents[v]:
        outs[p] -= 1
        if outs[p] == 0:
            leaves.append(p)
    order[v] = j
    j += 1

for v in range(1, N + 1):
    rejected_order = INF
    parent = 0
    for p in parents[v]:
        if rejected_order > order[p]:
            rejected_order = order[p]
            parent = p
    print(parent)


Measured memory_bytes: 52196
#include<bits/stdc++.h>
#define IOS ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define endl "\n"
#define pb push_back
#define mp make_pair
#define int long long
#define mod 1000000007
#define DEBUG cout<<"Hello1\n";
#define all(v) (v).begin(),(v).end()
#define clr(x) memset(x,0,sizeof(x))
#define deb(...) debug(#__VA_ARGS__, __VA_ARGS__);
const int N = 1e6 + 5;
const double pi =  acosl(-1);
const long long inf = 1e18 + 5;
using namespace std;
template<typename T> void debug(string s, T x) {cout << s << " = " << x << "\n";}
template<typename T, typename... Args> void debug(string s, T x, Args... args) {cout << s.substr(0, s.find(',')) << " = " << x << " | "; debug(s.substr(s.find(',') + 2), args...);}
template<class T> void print_container(T &container) { for (auto &t : container) { cout << t << " ";} cout << endl;}
template<class T> void printArr(T &a , int n) { for (int i = 0; i < n; i++) {cout << a[i] << " ";} cout << endl;}
typedef long long ll;
typedef pair<int, int> pii;

//Template Ends
int k;
set<int> ms;

void solve() {
	cin >> k;

	int curr = 7;

	int ans = -1;
	int rem = 0;

	while (1) {
		int rem = curr % k;
		if (rem == 0) {
			cout << ms.size() + 1 << endl;
			return;
		} else {
			if (ms.count(rem)) {
				cout << -1 << endl;
				return;
			} else {
				ms.insert(rem);
				curr = (curr * 10 + 7) % k;
			}
		}
	}

}

int32_t main() {
	IOS;

	solve();

	return 0;
}




Measured memory_bytes: 50496
#include <cstdlib>
#include <iostream>
#include <math.h>
#include <vector>

using namespace std;

int main(int argc, const char *argv[]) {
  int a;
  string s;

  cin >> a;
  cin >> s;

  if(a >= 3200){
    cout << s << endl;
  }else{
    cout << "red" << endl;
  }
  return 0;
}


Measured memory_bytes: 632
a, b = [int(i) for i in input().split(' ')]

if a == b:
  print(a)
  exit()
  
c = 0
if a % 2 == 1:
  c = a
  a += 1

if a == b:
  print(c ^ a)
  exit()

d = (b - (a - 1)) // 2
if d % 2 == 0:
  c ^= 0
else:
  c ^= 1

if b % 2 == 0:
  c ^= b

print(c)

Measured memory_bytes: 3060
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <queue>
#include <vector>
#include <cstdlib>
#include <cmath>

typedef long long ll;

#define reps(i, s, e) for (ll i = s; i < e; ++i)
#define rep(i, n) reps(i, 0, n)
#define rreps(i, s, e) for (ll i = e-1; i >= s; --i)
#define rrep(i, n) rreps(i, 0, n)

// const ll LL_INF = 1LL<<60;

template <class T> inline void chmin(T& a, T b) {if (a > b) {a = b;}}
template <class T> inline void chmax(T& a, T b) {if (a < b) {a = b;}}

using namespace std;

ll cnt = 0;

template<class T> inline void sw(T& a, T& b) {
    T tmp = a;
    a = b;
    b = tmp;
}
template<class T> inline void insertion_sort(vector<T>& a, ll n, ll g) {
    // g飛ばしでソート
    reps(i, g, n) {
        ll v = a[i];
        ll j = i-g;
        while(a[j] > v) {
            a[j+g] = a[j];
            j -= g;
            cnt++;
            if (j < 0) break;
        }
        a[j+g] = v;
    }
}
template<class T> inline void output(vector<T>& a) {
    ll n = a.size();
    rep(i, n) {
        cout << a[i];
        if (i != n-1) cout << " ";
        else cout << "\n";
    }
}

template<class T> inline void shell_sort(vector<T>& a) {
    ll n = a.size();
    cnt = 0;

    ll h = 1;
    vector<ll> G;
    G.push_back(h);
    while (3*h+1 < n) {
        h = 3*h + 1;
        G.push_back(h);
    }

    reverse(G.begin(), G.end());
    ll m = G.size();
    rep(i, m) {
        insertion_sort<T>(a, n, G[i]);
    }
    cout << m << "\n";
    output<T>(G);
    cout << cnt << "\n";

    rep(i, n) cout << a[i] << "\n";
}



int main() {
    ll n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    shell_sort(a);
}


Measured memory_bytes: 10672
// Problem Title : Low Elements
// Link : https://atcoder.jp/contests/abc152/tasks/abc152_c
// Date : 03-09-2020 17:36:39

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	
	int n;
	cin >> n;
	int cmin = 1e9;
	int ans = 0;
	for(int i = 0; i < n; i++) {
		int v;
		cin >> v;
		if(v < cmin) {
			++ans;
			cmin = v;
		}
	}

	cout << ans << '\n';
	
	return 0;
}


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

typedef long long ll;
using namespace std;

int gcd (int a, int b){
    int tmp;
    if (a < b) swap(a, b);

    while (b != 0){
        tmp = a % b;
        a = b;
        b = tmp;
    }
    return a;
}

int main()
{
    int n, ans = 1, x = 0;
    cin >> n;
    vector <int> a(n, 0), b(n, 0), c(n, 0);

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

    b[0] = a[0];
    c[n-1] = a[n-1];

    for (int i = 1; i < n; i++) {
        b[i] = gcd(b[i-1], a[i]);
    }
    for (int i = n-2; i >= 0; i--) {
        c[i] = gcd(c[i+1], a[i]);
    }
    ans = max(b[n-2], c[1]);
    for (int i = 1; i < n-1; i++) {
        ans = max(ans, gcd(b[i-1], c[i+1]));
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
        
	string s;
	cin>>s;
	int num = s.size();
	if(s[num-1]=='s'){
		cout<<s<<"es";
	}else{
		cout<<s<<"s";
	}
	
    
}

Measured memory_bytes: 3624
N = int(input())
B = list(map(int, input().split()))
A = [B[0]] + B
for i in range(N-1):
    if B[i] < max(A[i],A[i+1]):
        A[i] = min(A[i],A[i+1])
        A[i+1] = min(A[i],A[i+1])
print(sum(A))

Measured memory_bytes: 38384
#include <bits/stdc++.h>
#define ll long long
#define mod 1000000007
#define inf 10000000000000007
#define eps 1e-8
#define PI 3.14159265359
#define sp printf(" ")
#define vi vector<int>
#define vl vector<long long>
#define vc vector<char>
#define vs vector<string>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pcc pair<char, char>
#define mp make_pair
#define FF first
#define SS second
#define pb(x) push_back(x)
#define sd(x) scanf("%d", &(x))
#define pd(x) printf("%d", (x))
#define pdn(x) printf("%d\n", (x))
#define sld(x) scanf("%ld", &(x))
#define pld(x) printf("%ld", (x))
#define pldn(x) printf("%ld\n", (x))
#define slf(x) scanf("%lf", &(x))
#define plf(x) printf("%.9lf", (x))
#define plfn(x) printf("%.12lf\n", (x))
#define sch(x) scanf("%c", &(x))
#define pch(x) printf("%c", (x))
#define pchn(x) printf("%c\n", (x))
#define gtl(x) getline(cin, (x))
#define flsh fflush(stdout)
#define ios ios::sync_with_stdio(false); cin.tie(0) ; cout.tie(0)
#define endl '\n'
using namespace std;
vector<int>a[200004];
int main()
{
    ll k;
    cin>>k;
    ll w=50;
    ll p=k%w;
    ll o=k/w;
    cout<<50<<endl;
   for(int i=1;i<=p;i++)cout<<w+o<<" ";
    for(int i=p+1;i<=w;i++)cout<<w+o-1LL-p<<" ";
        cout<<endl;

    
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin >> s;
  set<char> cset;

  for (int i = 0; i < 4; i++)
  {
    cset.insert(s[i]);
  }
  
  if(((s[0]==s[1]&&s[2]==s[3])||(s[0]==s[3]&&s[1]==s[2])||(s[0]==s[2]&&s[1]==s[3]))&&cset.size()==2) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7
#s=input().rstrip()

h,w=MI()
for i in range(h):
    s=input().rstrip()
    print(s)
    print(s)

Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) x.begin(), x.end()

const int mod = 1000000007;
int binpow(int a, int b, int mod)
{
    int ans = 1;
    a = a % mod;
    b = b % mod;
    if (b == 0)
        return 1;
    while (b)
    {
        if (b & 1)
            ans = ((ans % mod) * (a % mod)) % mod;
        a = ((a % mod) * (a % mod)) % mod;
        b >>= 1;
    }
    return ans % mod;
}

//read question carefully!

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t = 1;
    // cin >> t;
    while (t--)
    {
        int n;
        cin >> n;
        if (n == 1)
            cout << 0 << "\n";
        else
        {
            cout << 1 << "\n";
        }
    }
}


Measured memory_bytes: 3640
#include <iostream>
#define MAX 300000
using namespace std;
int D[MAX];
int n = 1;

void initRSQ(int n_){
    while(n < n_) n *= 2;
    for(int i = 0; i < 2*n-1; i++) D[i] = 0; 
}

void add(int k, int a){
    k += n-1;
    D[k] += a;

    while(k > 0){
        k = (k-1)/2;
        D[k] = D[2*k+1]+D[2*k+2];
    }
}

int query(int a, int b, int k, int l, int r){
    if(r <= a || b <= l) return 0;
    if(a <= l && r <= b) return D[k];

    int vleft, vright;
    vleft = query(a,b,2*k+1,l,(l+r)/2);
    vright = query(a,b,2*k+2,(l+r)/2,r);
    return vleft + vright;
}

int getSum(int a, int b){
    return query(a,b,0,0,n);
}

int main(){
    int q, com, x, y, n_, min;
    cin >> n_ >> q;
    initRSQ(n_);
    for(int i = 0; i < q; i++){
        cin >> com >> x >> y;
        x--;
        if(com == 0) add(x,y);
        else cout << getSum(x,y) << endl;
    }
    return 0;
}


Measured memory_bytes: 4104
#include <bits/stdc++.h>
using namespace std;
int dp[101][4][2];
int main()
  {string s; cin >> s;
  int n = s.size();
  int K; cin >> K;
  dp[0][0][0] = 1;
  for (int i = 0; i < n; ++i)
    {auto D = s[i] - '0';
    for (int j = 0; j <= K; ++j)
      {for (int k = 0; k < 2; ++k)
        {for (int d = 0; d <= 9; ++d)
          {auto j1 = j, k1 = k;
          if (d > 0) ++j1;
          if (j1 > K) continue;
          if (k == 0)
            {if (d > D) continue;
            if (d < D) k1 = 1;}
          dp[i + 1][j1][k1] += dp[i][j][k];}}}}
  cout << dp[n][K][0] + dp[n][K][1] << endl;}

Measured memory_bytes: 256
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
#define PI 3.141592653589793
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 gcd(int a, int b){//ユークリッドの互除法
  if (a < b) gcd(b,a); //aの方がbよりでかいのが前提
  if (b == 0) return a; //aをbで割り切れたらreturn
  else gcd(b, a % b);
}
int lcm(int a, int b){
  return a / gcd(a,b) * b;
}
const int INF = 1<<30;
const int MOD = 1000000007;
int dx[4] = {0,0,-1,1};
int dy[4] = {-1,1,0,0};

int dp[5005][5005];

int main(){
  int n; string s; cin >> n >> s;
  for(int i = n-1;i >= 0;i--){
    for(int j = n-1; j >= 0;j--){
      if(s[i] == s[j]) dp[i][j] = dp[i+1][j+1] + 1;
      else dp[i][j] = 0;
    }
  }
  
  int ans = 0;
  rep(i,n)rep(j,n){
    if(i >= j) continue;
    int now = min(dp[i][j], j-i);
    chmax(ans,now);
  }
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 98048
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define pii pair<int,int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vll vector<ll>
#define IO ios_base::sync_with_stdio(0);cin.tie(0); cout.tie(0);
#define read(FILE)  freopen(FILE, "r", stdin);
#define out(FILE) freopen(FILE, "w", stdout);
#define all(x) x.begin(),x.end()
#define rep(i,m,n) for(int i=m ; i<n ; i++)
#define forr(i,m,n) for(int i=m ; i<=n ; i++)
#define clr(v,val) memset(v,val,sizeof(v))
#define endl '\n'
#define pb push_back
#define pff push_front
#define re return
const int N = 1e5 + 5;
const ll mod=int(1e9)+7;
using namespace std;
int main()
{
    IO;
    string a,b,A="",B=""; cin>>a>>b;
    rep(i,0,b[0]-'0'){
    A+=a;
    }
    rep(i,0,a[0]-'0'){
    B+=b;
    }
    cout<<min(A,B);




}


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

int main(){
 	int n;
	cin >>n;
  	string s;
  	cin >> s;
  	int max = 0;
	vector<int> lef(26);
	vector<int> rig(26);
	for(int i = 0; i < n; i++) {
		rig[s[i] - 'a']++;
	}
  	int t;
	for(int i = 0; i < n-1; i++) {
		lef[s[i] - 'a']++;
      	rig[s[i] - 'a']--;
      	t=0;
      	for(int j=0;j<26;j++) {
        	if(lef[j] > 0 && rig[j] > 0)
              	t++;
        }
      	if(t>max)
          	max = t;
	}
  	cout << max << endl;
	
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,start,lim) for(lld i=start;i<lim;i++)
#define repd(i,start,lim) for(lld i=start;i>=lim;i--)
#define scan(x) scanf("%lld",&x)
#define print(x) printf("%lld ",x)
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define br printf("\n")
#define sz(a) lld((a).size())
#define YES printf("YES\n")
#define NO printf("NO\n")
#define all(c) (c).begin(),(c).end()
using namespace std;
#define INF         1011111111
#define LLINF       1000111000111000111LL
#define EPS         (double)1e-10
#define MOD         1000000007
#define PI          3.14159265358979323
using namespace std;
typedef long double ldb;
typedef long long lld;
lld powm(lld base,lld exp,lld mod=MOD) {lld ans=1;while(exp){if(exp&1) ans=(ans*base)%mod;exp>>=1,base=(base*base)%mod;}return ans;}
typedef vector<lld> vlld;
typedef pair<lld,lld> plld;
typedef map<lld,lld> mlld;
typedef set<lld> slld;
#define N 100005
lld a[N],b[N],c[N],dis[N],neg[N];
int main()
{
	lld n,m;
	cin>>n>>m,dis[1]=0;
	rep(i,2,n+1) dis[i]=LLINF,neg[i]=0;
	rep(i,1,m+1) cin>>a[i]>>b[i]>>c[i],c[i]*=-1;
	rep(i,1,n) rep(j,1,m+1) if(dis[a[j]]!=LLINF and dis[b[j]]>dis[a[j]]+c[j]) dis[b[j]]=dis[a[j]]+c[j]; 
	rep(j,1,m+1) if(dis[a[j]]!=LLINF and dis[b[j]]>dis[a[j]]+c[j]) neg[b[j]]=1; else if(neg[a[j]]) neg[b[j]]=1; 
	if(!neg[n]) print(-dis[n]);
	else printf("inf\n");
	return 0;
}


Measured memory_bytes: 384
### subroutines

def cut_link(i, j)
  if $cbs[i][2] == j && $cbs[j][1] == i
    $cbs[i][2] = nil
    $cbs[j][1] = nil
  end
end

def make_link(i, j)
  if $cbs[i][2].nil? && $cbs[j][1].nil?
    $cbs[i][2] = j
    $cbs[j][1] = i
  end
end

def in_pile?(i, j, d)
  k = i
  while ! $cbs[k][d].nil?
    k = $cbs[k][d]
    return true if k == j
  end
  false
end

def above?(i, j)
  in_pile?(i, j, 2)
end

def under?(i, j)
  in_pile?(i, j, 1)
end

def take_off(k)
  k0 = k
  while ! $cbs[k0][2].nil?
    k1 = $cbs[k0][2]
    cut_link(k0, k1)
    k0 = k1
  end

  if ! $cbs[k][1].nil?
    k0 = $cbs[k][1]
    cut_link(k0, k)
  end
end

def put_on(i, j)
  while ! $cbs[j][2].nil?
    j = $cbs[j][2]
  end
  make_link(j, i)
end

### main

loop do
  m = gets.to_i
  break if m == 0

  $cbs = (0...m).map{|i| [i, nil, nil]}

  loop do
    i, j = gets.split.map{|s| s.to_i - 1}
    break if i == -1 && j == -1

    next if i == j

    if j < 0
      if ! $cbs[i][1].nil?
        take_off(i)
      end
    elsif above?(i, j)
      take_off(i)
      put_on(i, j)
    elsif under?(i, j)
      next
    else
      take_off(i)
      put_on(i, j)
    end
  end
  #p $cbs

  plens = []

  for i in (0...m)
    if $cbs[i][1].nil?
      pile = [i]
      i0 = i
      while ! $cbs[i0][2].nil?
        i0 = $cbs[i0][2]
        pile << i0
      end
      #p pile
      plens << pile.length
    end
  end
  #p plens

  plens.sort.each{|len| puts len}
  puts 'end'
end

Measured memory_bytes: 6120
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
const int maxn = 1e4+10;

ll arr[maxn];
int K,Q,n,x,m;
ll sum[maxn],zero[maxn];
ll fun(){
    ll cnt = n-1;
    for(int i = 1;i<=K;i++){
        sum[i] = sum[i-1] + arr[i]%m;
        zero[i] = zero[i-1] + (arr[i]%m == 0);
    }
    ll cnt1 = (n-1)/K*zero[K]+zero[(n-1)%K]; //cout<<cnt1<<endl;
    ll cnt2 = ((n-1)/K*sum[K]+sum[(n-1)%K] + x )/m - x/m; //cout<<cnt2<<endl;
    return cnt-cnt1-cnt2;
}
int main(){
    cin>>K>>Q;
    for(int i = 1;i<=K;i++) scanf("%lld",&arr[i]);
    while(Q--){
        scanf("%d%d%d",&n,&x,&m);
        printf("%lld\n",fun());
    }

    return 0;
}

Measured memory_bytes: 504
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
using namespace std;
#define INF 2000000007
#define LINF 100000000000000007
#define MOD 1000000007
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define repb(i, n) for (int i = n - 1; i >= 0; i--)
#define MODE 0
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long ll;
typedef pair<int,int> P;
struct edge{int to,cost;};
int ceil2(int a,int b){if(a%b){return a/b+1;}else{return a/b;}}
using namespace std;

int h,w,n;
string s;
signed main(){
	
	cin>>s;
	if(s[4]==s[5] && s[2]==s[3])cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1100;
const int INF = 1e9+7;
char a[maxn][maxn];
int dp[maxn][maxn];		//dp[i][j]´ú±íÖÕµãÎªi,jµÄ·½°¸Êý 
bool vis[maxn][maxn];
long long ans = 0,h,w;

int main() {
	cin>>h>>w;
	for(int i = 1;i <= h;i++) {
		scanf("%s",a[i]+1);
	}
	for(int i = 1;i <= w;i++) {
		if(a[1][i] == '.') dp[1][i] = 1;
		else break;
	}
	for(int i = 1;i <= h;i++) {
		if(a[i][1] == '.') dp[i][1] = 1;
		else break;
	}
	
	for(int i = 2;i <= h;i++) {
		for(int j = 2;j <= w;j++) {
			if(a[i][j] == '.') {
				dp[i][j] = (dp[i-1][j] + dp[i][j-1]) % INF;
			}
		}
	}
	cout<<dp[h][w];
	return 0;
}  


Measured memory_bytes: 6016
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i,n) for(int i=0;i<(n);++i)
#define ll long long
const long long INF = 1LL<<60;
const long long mod = 1e9 + 7;
using Graph = vector<vector<int>>;

int main(){
    int x;
    cin >> x;
    if(x==1) cout << 0 << endl;
    else cout << 1 << endl;
}

Measured memory_bytes: 3592
import sys

n, *a = map(int, sys.stdin.read().split())

def main():
    s1 = s2 = c1 = c2 = 0
    for i in range(n):
        s1 += a[i]
        s2 += a[i]
        if i & 1:
            if s1 >= 0:
                c1 += abs(-1 - s1)
                s1 = -1

            if s2 <= 0:
                c2 += 1 - s2
                s2 = 1
        else:
            if s1 <= 0:
                c1 += 1 - s1
                s1 = 1

            if s2 >= 0:
                c2 += abs(-1 - s2)
                s2 = -1
    
    return min(c1, c2)

if __name__ == '__main__':
    ans = main()
    print(ans)

Measured memory_bytes: 14084
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<cmath>
#include<ctime>
#include<complex>

using namespace std;

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

int T[10][10];
int V[10][10];
int m,n,cx,cy,h=0,c=0;
void f(int x,int y,int h){

	if(h==0){
		if(x==cx || y==cy) c++;
		else return;
	}

	if(y-1>=0){
		for(int i=y-1;i>=0;i--){
		if(T[x][i]==1 && V[x][i]==0){
			V[x][i]=1;
			f(x,i,h-1); V[x][i]=0;
			break;
		}
	  }
	}

	if(y+1<m){
		for(int i=y+1;i<m;i++){
		if(T[x][i]==1 && V[x][i]==0){
			V[x][i]=1;
			f(x,i,h-1); V[x][i]=0;
			break;
		}
	  }
	}

	if(x-1>=0){
		for(int i=x-1;i>=0;i--){
		if(T[i][y]==1  && V[i][y]==0){
			V[i][y]=1;
			f(i,y,h-1); V[i][y]=0;
			break;
		}
	  }
	}

	if(x+1<n){
		for(int i=x+1;i<n;i++){
		if(T[i][y]==1  && V[i][y]==0){
			V[i][y]=1;
			f(i,y,h-1); V[i][y]=0;
			break;
		}
	  }
	}

}

int main(){

	while(1){

		cin >> m >> n;
		if(m==0 && n==0) break;

		rep(i,n){
			rep(j,m){
				cin >> T[i][j];
				if(T[i][j]==2){
					cx=i; cy=j;
				}
				if(T[i][j]==1) h++;
			}
		}

		f(cx,cy,h);

		cout << c << endl;

		c=0; h=0;
		rep(i,n){
			rep(j,m){
				T[i][j]=0; V[i][j]=0;
			}
		}
	}

	return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
	int n;cin>>n;
  	vector<int> s(n);
  	for(int i=0;i<n;i++){cin>>s.at(i);}
  	int q;cin>>q;
  	vector<int> t(q);
  	for(int i=0;i<q;i++){cin>>t.at(i);}
  	sort(t.begin(),t.end());
  	int i=0,j=0,count=0;
  	while(i<n && j<q ){
    	if(s.at(i)==t.at(j)){
        	count++;
          	i++;j++;
        }else if(s.at(i)>t.at(j)){
        	j++;
        }else if(s.at(i)<t.at(j)){
        	i++;
        }
    }
  cout<<count<<endl;
}


Measured memory_bytes: 3328
package main

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

const (
	initialBufSize = 100000
	maxBufSize     = 1000000
)

var sc *bufio.Scanner

func initScanner(r io.Reader) *bufio.Scanner {
	buf := make([]byte, initialBufSize)

	sc := bufio.NewScanner(r)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords) // bufio.ScanLines
	return sc
}

func main() {
	sc = initScanner(os.Stdin)
	fmt.Println(resolve(parseProblem()))
}

func parseProblem() int {
	return scanInt(sc)
}

func resolve(n int) int {
	return n + n*n + n*n*n
}

// snip-scan-funcs
func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return int(i)
}
func scanString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 1784
def main():
    import os,io
    input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
    N, Q = map(int, input().split())
    *C, = map(int, input().split())

    last = [-1]*(N+1)
    P = [[] for _ in [0]*(N+1)]
    for i, c in enumerate(C):
        if last[c] != -1:
            P[last[c]].append(i+1)
        last[c] = i+1

    queries = [[] for _ in [0]*(N+1)]
    for i in range(Q):
        l, r = map(int, input().split())
        queries[l].append((r, i))

    def add(A, i, x):
        while i <= N:
            A[i] += x
            i += i & -i

    def sum(A, i):
        ret = 0
        while i:
            ret += A[i]
            i ^= i & -i
        return ret

    A = [0]*(N+1)
    ans = [0]*Q
    for l in range(N, 0, -1):
        for cr in P[l]:
            add(A, cr, 1)
        for r, i in queries[l]:
            ans[i] = r-l+1-sum(A, r)

    print(*ans, sep='\n')

if __name__ == '__main__':
    main()


Measured memory_bytes: 235920
import sys
sys.setrecursionlimit(700000)

def s_in():
    return input()

def n_in():
    return int(input())

def l_in():
    return list(map(int, input().split()))

def print_l(l):
    print(' '.join(map(str, l)))

class Interval():
    def __init__(self, li):
        self.li = li
        self.n = len(li)
        self.sum_li = [li[0]]
        for i in range(1, self.n):
            self.sum_li.append(self.sum_li[i-1] + li[i])

    def sum(self, a, b=None):
        if b is None:
            return self.sum(0, a)

        res = self.sum_li[min(self.n-1, b-1)]
        if a > 0:
            res -= self.sum_li[a-1]
        return res

l = n_in()
print((l/3)**3)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 998244353;
const ll INF = 1e18;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define rREP(i,m,n) for(ll i = (m); i >= (n); i--)
#define ALL(c) (c).begin(), (c).end()
#define print(x) cout << (x) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " ";} cout<<endl;

ll ll_pow(ll a, ll b)
{
    if (b==0) return 1;
    return (a * ll_pow(a, b-1))%MOD;
}

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

    int n;cin>>n;
    int d[n];
    int max_d=0;
    rep(i,n)
    {
        cin >> d[i];
    }
    rep(i,n)
    {
        max_d = max(max_d, d[i]);
    }
    ll ans = 1;
    bool flag = true;
    int d_nums[max_d+1];
    rep(i, max_d+1) d_nums[i] = 0;
    rep(i,n)
    {
        if (i==0 && d[i]!=0) flag = false;
        if (i!=0 && d[i]==0) flag = false;
        d_nums[d[i]]++;
    }
    // cout << max_d << endl;
    // cout << endl;
    // rep(i,max_d+1)
    // {
    //     cout << d_nums[i] << endl;
    // }

    REP(i,1,max_d+1)
    {
        if (d_nums[i]==0) flag = false;
        
        ans *= ll_pow(d_nums[i-1], d_nums[i]);
        ans %= MOD;
    }
    if (flag)
    {
        cout << ans << endl;
    }
    else
    {
        cout << 0 << endl;
    }
    
    
}




Measured memory_bytes: 2176
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <deque>
#include <map>
const int MOD = 1e9+7;
typedef long long ll;
using namespace std;


int main(){
	ll n, d, a;
	cin >> n >> d >> a;
	vector<pair<ll, ll> > xh(n);
	for (int i = 0; i < n; i++){
		cin >> xh[i].first >> xh[i].second;
	}
	sort(xh.begin(), xh.end());

	ll sum = 0, ans = 0;
	queue<pair<ll, ll> > que;
	for (int i = 0; i < n; i++){
		if (xh[i].second > sum){
			ll num = (xh[i].second - sum + a - 1)/a;
			ans += num;
			sum += num*a;
			que.push(make_pair(xh[i].first + 2*d, num*a));
		}
		if (i != n-1){
			while (!que.empty() && que.front().first < xh[i+1].first){
				sum -= que.front().second;
				que.pop();
			}
		}
	}
	cout << ans << endl;
	return 0;
}


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

//const long double PIL = 3.141592653589793238462643383279502884L;
//const double PI = 3.14159265358979323846;

#define sz(a) (int)((a).size())
#define all(c) (c).begin(), (c).end()
#define debug(v) {for (auto z : v) {cerr << z << ' ';} cerr << endl;}

using ll = long long;
using ii = pair<int,int>;
using vi = vector<int>;
using vll = vector<long long>;
using vii = vector<pair<int,int>>;

const int N = 1e5 + 5;
char buf[5*N];

int main() {
	//~ ios::sync_with_stdio(0);
	//~ cin.tie(0);
	int head = 2*N;
	scanf("%s", buf + head);
	int tail = head + strlen(buf+head) - 1;
	bool fwd = true;

	int q;
	for (scanf("%d", &q); q; q--) {
		int t, f;
		char c[4];
		scanf("%d", &t);
		if (t == 1) fwd = !fwd;
		else {
			scanf("%d%s", &f, c);
			if (f == 1) {
				if (fwd) buf[--head] = c[0];
				else buf[++tail] = c[0];
			}
			else {
				if (fwd) buf[++tail] = c[0];
				else buf[--head] = c[0];
			}
		}
	}
	buf[++tail] = '\0';
	if (!fwd) reverse(buf+head, buf+tail);
	printf("%s\n", buf+head);
}


Measured memory_bytes: 896
import java.util.*;
import java.io.*;
public class Main
{
    public static void main(String []args) throws IOException {
    	FastScanner in  = new FastScanner(System.in);
    	PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)), false);
    	solve(in, out);
    	in.close();
    	out.close();
    }
    static long gcd(long a, long b){ return (b==0) ? a : gcd(b, a%b); }
    static int gcd(int a, int b){ return (b==0) ? a : gcd(b, a%b); }
    private static int fact(int n) { int ans=1; for(int i=2;i<=n;i++) ans*=i; return ans; }
    
    public static int[] generatePrimes(int n) {
		boolean[] prime = new boolean[n + 1];
		Arrays.fill(prime, 2, n + 1, true);
		for (int i = 2; i * i <= n; i++)
			if (prime[i])
				for (int j = i * i; j <= n; j += i)
					prime[j] = false;
		int[] primes = new int[n + 1];
		int cnt = 0;
		for (int i = 0; i < prime.length; i++)
			if (prime[i])
				primes[cnt++] = i;
		return Arrays.copyOf(primes, cnt);
	}
    static class FastScanner{
	BufferedReader reader;
	StringTokenizer st;
	FastScanner(InputStream stream){reader=new BufferedReader(new InputStreamReader(stream));st=null;}
	String next(){while(st == null || !st.hasMoreTokens()){try{String line = reader.readLine();if(line == null){return null;}
	     st = new StringTokenizer(line);}catch (Exception e){throw new RuntimeException();}}return st.nextToken();}
	String nextLine()  {String s=null;try{s=reader.readLine();}catch(IOException e){e.printStackTrace();}return s;}
	int    nextInt()   {return Integer.parseInt(next());}
	long   nextLong()  {return Long.parseLong(next());}
	double nextDouble(){return Double.parseDouble(next());}
	char   nextChar()  {return next().charAt(0);}
	int[]  nextIntArray(int n)         {int[] arr= new int[n];   int i=0;while(i<n){arr[i++]=nextInt();}  return arr;}
	long[] nextLongArray(int n)        {long[]arr= new long[n];  int i=0;while(i<n){arr[i++]=nextLong();} return arr;}
	int[]  nextIntArrayOneBased(int n) {int[] arr= new int[n+1]; int i=1;while(i<=n){arr[i++]=nextInt();} return arr;}
	long[] nextLongArrayOneBased(int n){long[]arr= new long[n+1];int i=1;while(i<=n){arr[i++]=nextLong();}return arr;}
	void   close(){try{reader.close();}catch(IOException e){e.printStackTrace();}}
    }
    
    /********* SOLUTION STARTS HERE ************/
    
    private static void solve(FastScanner in, PrintWriter out){
        String s = in.next();
        int f=0;
        for(int i=0;i<3;i++) if(s.charAt(i)=='7') f=1;
        out.println(f==0?"No":"Yes");
    }
    
    /************* SOLUTION ENDS HERE **********/
}

Measured memory_bytes: 32972
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <functional>
#include <cstdio>
#include <climits>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

int main() {
    int A, B;
    cin >> A >> B;
    cout << (A - 1) * (B - 1) << endl;
    return 0;
}


Measured memory_bytes: 256
import math
while True:
    x = input().split()
    a = int(x[0])
    b = int(x[2])
    oprnd = x[1]
    if oprnd=="+":
        print(a+b)
    elif oprnd=="-":
        print(a-b)
    elif oprnd=="*":
        print(a*b)
    elif oprnd=="/":
        print(math.floor(a/b))
    elif oprnd=="?":
        break

Measured memory_bytes: 7736