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

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

class ConnectNodeInfo{
	vector<vector<pair<ll,ll>>> graph;
public:
	ConnectNodeInfo(int node_num){
		graph.resize(node_num);
	}
	void AddNonDirectionalConnection(ll u,ll v,ll w){
		graph[u].emplace_back(v,w);
		graph[v].emplace_back(u,w);
	}
	void AddDirectionalConnection(ll u,ll v,ll w){
		graph[u].emplace_back(v,w);
	}
	vector<pair<ll,ll>>& operator[](ll index){
		return graph[index];
	}
	size_t size(){return graph.size();}
};

class Dijkstra{
	using Point = pair<ll,ll>;
	vector<ll> dist;
public:
	void CalcShortestPath(int start,ConnectNodeInfo& connect){
		dist.resize(connect.size(),1LL<<60);
		dist[start] = 0;

		priority_queue<Point,vector<Point>,greater<Point>> Q;
		Q.emplace(0,start);
		while(!Q.empty()){
			auto p = Q.top();
			Q.pop();
			int v = p.second;
			if(dist[v]<p.first){
				continue;
			}
			for(auto e:connect[v]){
				if(dist[e.first]>dist[v]+e.second){
					dist[e.first] = dist[v]+e.second;
					Q.emplace(dist[e.first],e.first);
				}
			}
		}
	}
	ll GetDistance(int i){
		return dist[i];
	}
};

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

	auto N=in(),Q=in(),R=in();
	ConnectNodeInfo connect(N);
	REP(i,Q){
		auto u=in(),v=in(),w=in();
		connect.AddDirectionalConnection(u,v,w);
	}
	Dijkstra di;
	di.CalcShortestPath(R,connect);
	REP(i,N){
		if(di.GetDistance(i)>=(1LL<<60)){
			out("INF");
		}
		else{
			out(di.GetDistance(i));
		}
	}
	return 0;
}



Measured memory_bytes: 19384
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
const int MM = 1000000000;
const int MOD = MM + 7;
const int MAX = 510000;
#define rep(i, n) for(ll i=0; i<n; i++)
#define Rep(i, j, n) for(ll i=j; i<n; i++)
#define all(vec) vec.begin(), vec.end()
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;}
const ll INF = 1LL << 60;

int main() {
    int a, b, c, x, y; cin >> a >> b >> c >> x >> y;
    ll ans = INF;
    rep(i, 200001) {
        ll can = c * i;
        if(x > i/2) can += a * (x - i/2);
        if(y > i/2) can += b * (y - i/2);
        chmin(ans, can);
    }
    cout << ans << endl;
}

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

#define int long long
#define cint cpp_int
#define endl "\n"
#define REP(i,a,n) for(int i=a;i<n;++i)
#define REPR(i,a,n) for(int i=a;i>n;--i)
#define RUP(a,b) (((a)+(b)-1)/(b))
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define MOD 1000000007
#define INF LLONG_MAX/2
#define PI acos(-1.0)

typedef long long ll;
typedef pair<int,int> Pii;
typedef tuple<int,int,int> Tiii;
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef vector<Pii> VPii;
typedef vector<string> Vs;
typedef priority_queue<int> PQi;

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;}
void vout(Vi &v){for(int i=0;i<(v).size();i++) cout<<v[i]<<" ";cout<<endl;}
void vout(Vs &v){for(int i=0;i<(v).size();i++) cout<<v[i]<<" ";cout<<endl;}
void vvout(VVi &v){for(int i=0;i<(v).size();i++) vout(v[i]);}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}
int mypow(int x, int n, int m){if(n==0)return 1;if(n%2==0)return mypow(x*x%m,n/2,m);else return x*mypow(x,n-1,m)%m;}
int digit(int k,int i){string s = to_string(k);return s[s.size()-i]-'0';}
void uniq(Vi &v){sort(v.begin(),v.end()); v.erase(unique(v.begin(),v.end()),v.end());} //vectorの同じ要素消す
int ctoi(char c){if(c>='0'&&c<='9'){return c-'0';}return 0;}
int leng(int n){string s=to_string(n); return s.size();} //intの桁数
int digitsum(int n){int ret=0; while(n>0){ret+=n%10;n/=10;}return ret;} //桁和
int lesscount(int x,Vi &a){return lower_bound(a.begin(),a.end(),x)-a.begin();} //vector aにおけるx未満の数の個数
int orlesscount(int x,Vi &a){return upper_bound(a.begin(),a.end(),x)-a.begin();} //vector aにおけるx以下の数の個数
int morecount(int x,Vi &a){return a.size()-orlesscount(x,a);} //vector aにおけるxより大きい数の個数
int ormorecount(int x,Vi &a){return a.size()-lesscount(x,a);} //vector aにおけるx以上の数の個数
int count(int x,Vi &a) {return upper_bound(ALL(a),x)-lower_bound(ALL(a),x);} //vector aにおけるxの個数
Vi accum(Vi &v){Vi ret((v).size()+1);REP(i,0,(v).size()) ret[i+1]=ret[i]+v[i];return ret;}
bool comp(Pii a,Pii b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}


void solve(long long N, long long A, long long B){
    int ans=0;
    ans += N/(A+B)*A;
    if(N%(A+B)<=A) ans += N%(A+B);
    else ans += A;
    cout<<ans<<endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
signed main(){cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);
    long long N;
    scanf("%lld",&N);
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    solve(N, A, B);
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main(){
    int x,i=0;
    char b[100000];
    scanf("%d",&x);
    char a[x];
    char *pa=a,*pb=b;
    getchar();
    gets(a);
    *pb=*pa;
    pb++;
    while(*(pa+1)!='\0'){
                if (*(pa+1)!=*pa){
                    *pb=*(pa+1);
                    pb++;
                }
            pa++;
    }
    *pb='\0';
    printf("%d\n",strlen(b));
    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int n,a[105],max1,min1=1e9+10;
int main(){
  cin>>n;
  for(int i=1;i<=n;i++)
  {
  	  cin>>a[i];
  	  if(max1<a[i]) max1=a[i];
  	  if(min1>a[i]) min1=a[i];
  	  
		  }cout<<max1-min1;
return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>
#include<algorithm>
#include<bitset>
#include <climits>
using namespace std;
#define _GLIBCXX_DEBUG
#define pq priority_queue
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define pii pair<long long,long long>
#define ppii pair<long long,pair<long long,long long>>
#define all(x) (x).begin(),(x).end()
#define rep(x) for(int i = 0;i < (x);i++)
#define repj(x) for(int j = 0;j < (x);j++)
#define REP(i,x) for(int (i) = 0;(i) < (x);(i)++)
#define rrep(x) for(int i = (x);i >= 0;i--)
#define mins(x,y) x = min(x,y)
#define maxs(x,y) x = max(x,y)
#define mod 1000000007
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define pyes cout << "Yes" << endl
#define pno cout << "No" << endl
typedef vector<vector<long long>> vii;
typedef unsigned long long lint;
typedef unsigned long long ll;
lint qp(int a, ll b) { int ans = 1; do { if (b & 1)ans = 1ll * ans*a; a = 1ll * a*a; } while (b >>= 1); return ans; }
lint qp(int a, ll b, int mo) { int ans = 1; do { if (b & 1)ans = 1ll * ans*a%mo; a = 1ll * a*a%mo; } while (b >>= 1); return ans; }
lint gcd(int a, int b) { return b ? gcd(b, a%b) : a; }
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };
long long INF = 1e14;
const int MAX_N = 1 << 17;
const int cf = 100010;
///////////////////////////////////////////////////////////////////////////////

int main() {
	string s; cin >> s;
	for (int i = 1; i < 4; i++) {
		if (s[i] == s[i - 1]) {
			cout << "Bad" << endl;
			return 0;
		}
	}
	cout << "Good" << endl;
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb emplace_back
#define INF (1e9+1)

int use(int n, vector<int> &vec){
    int ret = 0;
    for(auto &elm:vec){
        while(n-elm>=0){
            n-=elm;
            ret++;
        }
    }
    return ret + n;
}

int main(){
    int n;
    cin>>n;
    
    vector<int> nine,six;
    nine.pb(9);
    six.pb(6);
    while(nine.back()*9<=n){
        nine.pb(nine.back()*9);
    }
    while(six.back()*6<=n){
        six.pb(six.back()*6);
    }
    reverse(all(nine));
    reverse(all(six));

    
    int ans = INF;
    for(int i=0;i<=n;i++){
        int tmp = use(i,six) + use(n-i,nine);
        ans = min(ans,tmp);
    }
    cout<<ans<<endl;
}


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

int main() {
    int n,k;
    cin >> n >> k;
    vector<int> v(n,-1);
    rep(i,k) {
        int d;
        cin >> d;
        rep(i,d) {
            int a;
            cin >> a;
            v[--a] = 0;
        }
    }
    int ans = 0;
    rep(i,n) {
        if (v[i] == -1) ans++;
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 3724
require 'prime'
require 'set'
require 'tsort'
include Math
def max(a,b);              a > b ? a : b                              end
def min(a,b);              a < b ?  a : b                             end
def swap(a,b);             a, b = b, a                                end
def gif;                   gets.to_i                                  end
def gff;                   gets.to_f                                  end
def gsf;                   gets.chomp                                 end
def gi;                    gets.split.map(&:to_i)                     end
def gf;                    gets.split.map(&:to_f)                     end
def gs;                    gets.chomp.split.map(&:to_s)               end
def gc;                    gets.chomp.split('')                       end
def pr(num);               num.prime_division                         end
def digit(num);            num.to_s.length                            end
def array(s,ini=nil);      Array.new(s){ini}                          end
def darray(s1,s2,ini=nil); Array.new(s1){Array.new(s2){ini}}          end
def rep(num);              num.times{|i|yield(i)}                     end
def repl(st,en,n=1);       st.step(en,n){|i|yield(i)}                 end

def k n
 sum = 1
 rep n do |i|
  sum *= (i+1)
  sum %= 10 ** 9 + 7
 end
  sum
end

n,m = gi
if (n-m).abs > 1
  puts 0
else
  s1 = k n
  s2 = k m
  j = n-m == 0 ?  2 : 1
  puts (s1 * s2 * j) % (10 ** 9 + 7)
end



Measured memory_bytes: 2428
#include <iostream>
#include <algorithm>
using namespace std;
 
int main(){
    int L, A, B, C, D = 0;
    cin >> L >> A >> B >> C >> D;
    
    cout << L - max(A % C == 0 ? A / C : A / C + 1, B % D == 0 ? B / D : B / D + 1) << endl;
    
    return 0;
}

Measured memory_bytes: 3060
#include<iostream>
#include<stdio.h>
using namespace std;

int main(){
  int i,n,a[10000];
  cin>>n;
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
  }
  int min=a[0],k;
  for(k=1;k<n;k++){
    if(min>a[k]){
      min=a[k];
    }
  }


  int max=a[0],h;
  for(h=1;h<n;h++){
    if(max<a[h]){
      max=a[h];
    }
  }


  int j;
  long long sum=0;
  for(j=0;j<n;j++){
	  sum+=a[j];
  }


  cout<<min<<" "<<max<<" "<<sum<<endl;
  
}

Measured memory_bytes: 1284
#include <stdio.h>

int main(){
    int x = 0;
    int y = 0;

    for(;;){
        scanf("%d%d",&x,&y);
        if((x==0)&&(y==0)){
            break;
        }
        if(x < y){
            printf("%d %d\n",x,y);
        }else{
            printf("%d %d\n",y,x);
        }
        
    }
    return 0;
}


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

int main() {
  int h, w, n;
  cin >> h >> w >> n;
  if(h > w) {
    int a = 0;
    for(int i=1;i<=w;i++) {
      a += h;
      if(a >= n) {
        a = i;
        break;
      }
    }
    cout << a << endl;
  } else {
    int a = 0;
    for(int i=1;i<=h;i++) {
      a += w;
      if(a >= n) {
        a = i;
        break;
      }
    }
    cout << a << endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
string A(string str){
  string str1;
  for(int i=0;i<str.size();i++) str1+=str[str.size()-i-1];
   return str1;
}
string C(string str){
  string str1;
  for(int i=1;i<str.size();i++) str1+=str[i];
  str1+=str[0];
  return str1;
}
string J(string str){
  string str1;
  str1+=str[str.size()-1];
  for(int i=0;i<str.size()-1;i++) str1+=str[i];
   return str1;
}
string E(string str){
  string str1;
  int a=0;
  if(str.size()%2) a=1;
  for(int i=(str.size()/2)+a;i<str.size();i++) str1+=str[i];
  if(a==1) str1+=str[str.size()/2],a=0;
  for(int i=0;i<(str.size()/2+a);i++) str1+=str[i];
  return str1;
}
string M(string str){
  string str1;
  for(int i=0;i<str.size();i++){
    if(str[i]>='0' && str[i]<'9') str[i]++;
    else if(str[i]=='9')str[i]='0';
    str1+=str[i];
  }
  return str1;
}
string P(string str){
  string str1;
  for(int i=0;i<str.size();i++){
    if(str[i]>'0' && str[i]<='9') str[i]--;
    else if(str[i]=='0') str[i]='9';
    str1+=str[i];
  }
  return str1;
}

int main(){
  int n;
  string str,str1;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>str;
    cin>>str1;
    for(int j=str.size()-1;j>=0;j--){
      if(str[j]=='A') str1=A(str1);
      else if(str[j]=='J') str1=J(str1);
      else if(str[j]=='C') str1=C(str1);
      else if(str[j]=='E') str1=E(str1);
      else if(str[j]=='P') str1=P(str1);
      else str1=M(str1);
      }
    cout<<str1<<endl;
  }
  return 0;
}

Measured memory_bytes: 1208
#include <bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i=a; i<b; i++)
#define dep(i,a,b) for(int i=a; i>=b; i--)
#define sq(a) (a)*(a)
#define ms(a,v)	memset(a,v,sizeof a)
#define ALL(x)	(x).begin(), (x).end()
using namespace std;
const long long INF = 1e18 , MAXN =1e5, MOD = 1e9 + 7;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<vector<int> > vvi;
typedef map<int, int> mii;
typedef map<string, int> msi;
typedef map<int, string> mis;
typedef map<string, string> mss;

char f(char a,char b){
	if (a>b)	swap(a,b);
	if (a=='G' && b=='R')	return 'B';
	if (a=='B' && b=='G')	return 'R';
	if (a=='B' && b=='R')	return 'G';
	return '@';
}
int main()
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;	cin>>n;
  string s;	cin>>s;
  vector<int> r,g,b;
  rep(i,0,n){
	if (s[i]=='R')	r.pb(i);
	if (s[i]=='G')	g.pb(i);
	if (s[i]=='B')	b.pb(i);
  }
  ll res=0;
  rep(i,0,n){
	rep(j,i+1,n-1){
		if (s[i]==s[j])	continue;
		char t=f(s[i],s[j]);
		int x=j-i;
		int num=0;
		if (t=='R'){
			num=int(r.size())-(upper_bound(ALL(r),j)-r.begin());
			if (j+x<n&&s[j+x]=='R')	num--;
		}
		if (t=='G'){
			num=int(g.size())-(upper_bound(ALL(g),j)-g.begin());
			if (j+x<n&&s[j+x]=='G')	num--;
		}
		if (t=='B'){
			num=int(b.size())-(upper_bound(ALL(b),j)-b.begin());
			if (j+x<n&&s[j+x]=='B')	num--;
		}
		res+=num;
	}
  }
  cout<<res<<"\n";
    return 0;
}


Measured memory_bytes: 3612
import sys
input=sys.stdin.readline
h,w,k=map(int,input().split())
si,sj,ti,tj=map(int,input().split())
si-=1
sj-=1
ti-=1
tj-=1
b=[input()for _ in range(h)]
ans=[[-1]*w for _ in range(h)]
ans[si][sj]=0
from collections import deque
d=deque()
d.append((si,sj))
while d:
  x,y=d.popleft()
  if x==ti and y==tj:
    exit(print(ans[x][y]))
  for dx,dy in [[1,0],[-1,0],[0,-1],[0,1]]:
    for i in range(1,k+1):
      xx=x+dx*i
      yy=y+dy*i
      if not(0<=xx<h and 0<=yy<w) or b[xx][yy]=="@":break
      if 0<=ans[xx][yy]<=ans[x][y]:break
      if ans[xx][yy]==-1:d.append((xx,yy))
      ans[xx][yy]=ans[x][y]+1
print(-1)


Measured memory_bytes: 36884
#include<bits/stdc++.h>
#define int long long int
#define pb push_back
#define ipair pair<int,int>
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
int arr[1000001],dp[1000001];

int32_t main()
{
  fast;
  int n;
  cin>>n;
  for(int i=0;i<n;i++)
  {
    cin>>arr[i];
  }
  dp[0]=0;
  dp[1]=abs(arr[1]-arr[0]);
  for(int i=2;i<n;i++)
  {
    dp[i]=min(dp[i-1]+abs(arr[i]-arr[i-1]),dp[i-2]+abs(arr[i]-arr[i-2]));
  }
  cout<<dp[n-1];
}


Measured memory_bytes: 5120
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#define MN 101000

int a[MN], b[MN];
int c[MN], d[MN];
int s = 0, s2 = 0;
bool vis[MN];
std::vector<int> v[MN];
bool ok = 1;
int ans = 0, now = 0;

void dfs(int x)
{
	if(vis[x]) return; 
	vis[x] = 1;
	now += v[x].size();
	if(c[x] == s) ok = 0;
	for(auto &y : v[x]) dfs(y);
}

int main()
{
	int n; scanf("%d", &n);
	for(int i = 1; i <= n; i++) scanf("%d", &a[i]), s ^= a[i], c[i] = a[i];
	for(int i = 1; i <= n; i++) scanf("%d", &b[i]), s2 ^= b[i], d[i] = b[i];
	c[n + 1] = s; d[n + 1] = s2;
	std::sort(c + 1, c + n + 2);
	std::sort(d + 1, d + n + 2);
	for(int i = 1; i <= n + 1; i++) if(c[i] != d[i]) return 0 * puts("-1");
	int N = std::unique(c + 1, c + n + 2) - c - 1;
	for(int i = 1; i <= n; i++)
	{
		int A = std::lower_bound(c + 1, c + N + 1, a[i]) - c;
		int B = std::lower_bound(c + 1, c + N + 1, b[i]) - c;
		if(A != B) v[A].push_back(B), v[B].push_back(A);
	}
	for(int i = 1; i <= N; i++)
		if(!vis[i]) 
		{
			now = 0; ok = 1;
			dfs(i);
			if(now) ans += now / 2 + ok;
		}
	printf("%d\n", ans);
}


Measured memory_bytes: 10496
def lcs_len(x, y):
    indices = [0]
    for y_i in y:
        t_index = c_index = 0
        for i in range(1, len(indices) + 1):
            c_index = x.find(y_i, t_index) + 1
            if c_index:
                if i < len(indices):
                    t_index = indices[i]
                    indices[i] = min(c_index, t_index)
                else:
                    indices.append(c_index)
                    break
    print(len(indices) - 1)
n = int(input())
for i in range(n):
    lcs_len(input(), input())

Measured memory_bytes: 7656
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
static const int INF (1<<30);

int main() {
  string S;
  cin >> S;
  sort(all(S));

  if (S[0] == S[1] && S[1] != S[2] && S[2] == S[3]) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}

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

using namespace std;

#ifdef SG
	#include <debug.h>
#else
	#define show(...)
	#define debug(...)
	#define deepen(...)
	#define timer(...)
#endif

#define ARG4(_1,_2,_3,_4,...) _4

#define forn3(i,l,r) for (int i = int(l); i < int(r); ++i)
#define forn2(i,n) forn3 (i, 0, n)
#define forn(...) ARG4(__VA_ARGS__, forn3, forn2) (__VA_ARGS__)

#define ford3(i,l,r) for (int i = int(r) - 1; i >= int(l); --i)
#define ford2(i,n) ford3 (i, 0, n)
#define ford(...) ARG4(__VA_ARGS__, ford3, ford2) (__VA_ARGS__)

#define ve vector
#define pa pair
#define tu tuple
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define fs first
#define sc second
#define all(a) (a).begin(), (a).end()
#define sz(a) ((int)(a).size())

typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef unsigned char uc;
typedef pa<int, int> pii;
typedef pa<int, ll> pil;
typedef pa<ll, int> pli;
typedef pa<ll, ll> pll;
typedef ve<int> vi;

const ld pi = 3.1415926535897932384626433832795l;

template<typename T> inline auto sqr (T x) -> decltype(x * x) {return x * x;}
template<typename T1, typename T2> inline bool umx (T1& a, T2 b) {if (a < b) {a = b; return 1;} return 0;}
template<typename T1, typename T2> inline bool umn (T1& a, T2 b) {if (b < a) {a = b; return 1;} return 0;}

const int N = 2010;
int n;
vi a[N];
int k;
bool use[N];
bool color[N];
int p[N];

void calc(int v, int h) {
	use[v] = 1;
	color[v] = 1;
	if (h == k / 2)
		return;
	forn(i, sz(a[v])) {
		int to = a[v][i];
		if (use[to])
			continue;
		calc(to, h + 1);
	}
}

void dfs(int v, int pr) {
	p[v] = pr;
	forn(i, sz(a[v])) {
		int to = a[v][i];
		if (to != pr)
			dfs(to, v);
	}
}

int main () {
	cout.setf(ios::showpoint | ios::fixed);
	cout.precision(20);
#ifdef SG
	freopen((problemname + ".in").c_str(), "r", stdin);
//	freopen((problemname + ".out").c_str(), "w", stdout);
#endif
	cin >> n >> k;
	forn(i, n - 1) {
		int u, v;
		cin >> u >> v;
		u--, v--;
		a[u].pb(v);
		a[v].pb(u);
	}
	dfs(0, -1);
	p[0] = -1;
	int ans = n;
	forn(i, (k & 1), n) {
		memset(use, 0, sizeof(use));
		memset(color, 0, sizeof(color));
		if (k & 1) {
			calc(i, 0);
			memset(use, 0, sizeof(use));
			calc(p[i], 0);
		} else {
			calc(i, 0);	
		}	
		int cnt = 0;
		forn(j, n) {
			if (!color[j])
				cnt++;
		}	
		umn(ans, cnt);
	}
   
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 512
main :: IO ()
main = do
  _ <- readLn :: IO Int
  xs <- getLine :: IO String    
  let ws = scanl (\a x -> if x=='W' then a+1 else a) 0 xs :: [Int]
  let es = scanr (\x a -> if x=='E' then a+1 else a) 0 xs :: [Int]
  print $ minimum $ zipWith (+) ws es

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

#define NREP() for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 0; i < n; i++)
#define ALL(x) (x).begin(), (x).end()
#define MSG(x) cout << x << endl;
#define IPT(x) ll t; cin >> t; x.push_back(t);
#define YN(x) x ? cout << "YES" << endl : cout << "NO" << endl;
#define Yn(x) x ? cout << "Yes" << endl : cout << "No" << endl;
#define yn(x) x ? cout << "yes" << endl : cout << "no" << endl;

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<string> vs;
typedef vector<string> vvs;

const static ll MOD = 1e9 + 7;

int main() {
    ll x, y;
    cin >> x >> y;

    ll ans = 0;
    if (x == 3) {
        ans += 100000;
    } else if (x == 2) {
        ans += 200000;
    } else if (x == 1) {
        ans += 300000;
    }

    if (y == 3) {
        ans += 100000;
    } else if (y == 2) {
        ans += 200000;
    } else if (y == 1) {
        ans += 300000;
    }

    if (x == 1 && y == 1) {
        ans += 400000;
    }

    MSG(ans)
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int n,w,h;
int m[111][111];
main()
{
	while(cin>>n,n)
	{
		cin>>w>>h;
		for(int i=0;i<h;i++)for(int j=0;j<w;j++)m[i][j]=0;
		for(int i=0;i<n;i++)
		{
			int x,y;cin>>x>>y;
			m[y-1][x-1]=1;
		}
		int s,t;cin>>s>>t;
		int ans=0;
		for(int i=0;i<=h-t;i++)for(int j=0;j<=w-s;j++)
		{
			int cnt=0;
			for(int k=0;k<t;k++)
			{
				for(int l=0;l<s;l++)
				{
					cnt+=m[i+k][j+l];
				}
			}
			ans=ans<cnt?cnt:ans;
		}
		cout<<ans<<endl;
	}
}



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

int main(){
    string s, t;    cin >> s >> t;
    int ans = 100000000;
    for(int i = 0; i <= s.size()-t.size(); i++){
        int tmp = 0;
        rep(j, t.size()){
            if(s[i+j] != t[j])  tmp++;
        }
        ans = min(ans, tmp);
    }
    cout << ans << endl;
}


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

typedef struct zaf_{
        int x,y,flag;
}zahyo;

bool comp(const zahyo& x,const zahyo& y){
        return x.x<y.x;
}

int main(){
        int n;
        cin >> n;
        zahyo red[n],blue[n];
        for(int i=0;i<n;i++){
                cin >> red[i].x;
                cin >> red[i].y;
                red[i].flag=0;
        }
        for(int i=0;i<n;i++){
                cin >> blue[i].x;
                cin >> blue[i].y;
        }
        sort(blue,blue+n,comp);

        int count=0;
        for(int i=0;i<n;i++){
                int max_y=-1,max_j=-1;
                for(int j=0;j<n;j++){
                        if(red[j].flag == 1){
                                continue;
                        }
                        if(red[j].x<blue[i].x && red[j].y<blue[i].y && red[j].y>max_y){
                                max_y=red[j].y;
                                max_j=j;
                        }
                }
                if(max_j != -1){
                        red[max_j].flag=1;
                        count++;
                }
        }
        cout << count << endl;
  		return 0;
}

Measured memory_bytes: 384
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		// TODO ?????????????????????????????????????????????
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		String input = br.readLine();
		
		for(int i = input.length() - 1; i >= 0; i--){
			System.out.print(input.charAt(i));
		}
		System.out.println();
	}

}

Measured memory_bytes: 23996
#include<iostream>
#include<string>
#include<vector>
#include<numeric>
#include<algorithm>
#include<cmath>

using namespace std;

int main(){

    int N;
    cin >> N;

    vector<int> A(N), B(N), C(N);

    for(int i=0; i<N; i++) cin >> A.at(i);
    for(int i=0; i<N; i++) cin >> B.at(i);
    for(int i=0; i<N-1; i++) cin >> C.at(i);

    int ans = 0;
    for(int i=0; i<N; i++){

        ans += B.at(A.at(i)-1);

        if(i != 0 && A.at(i-1) + 1 == A.at(i)){
            ans += C.at(A.at(i-1) - 1);
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 888
package main

import (
	"fmt"
	"sort"
)

var (
	a []int
	k int
)

func main() {
	a = make([]int, 5)
	fmt.Scan(&a[0])
	fmt.Scan(&a[1])
	fmt.Scan(&a[2])
	fmt.Scan(&a[3])
	fmt.Scan(&a[4])
	fmt.Scan(&k)

	sort.Ints(a)
	if a[4] - a[0] > k {
		fmt.Println(":(")
	} else {
		fmt.Println("Yay!")
	}
}

Measured memory_bytes: 512
#include <list>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
using namespace std;
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str();}
typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EACH(t,i,c) for(t::iretator i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,(n)-1)
const double EPS = 1e-12;
const double PI = acos(-1.0);

struct cake {
	int w, d;
	cake() {};
	cake(int w, int d) : w(w), d(d){};
};

int main() {
	int n, w, d;
	while(cin >> n >> w >> d, n|w|d) {
		vector<cake> vc(0);
		vc.push_back(cake(w, d));

		REP(i, n) {
			int p, s;
			cin >> p >> s;

			int sw = vc[p-1].w;
			int sd = vc[p-1].d;
			int size = vc.size();
			FOR(j, p-1, size-2) {
				vc[j].d = vc[j+1].d;
				vc[j].w = vc[j+1].w;
			}
			vc.resize(size-1);

			int pos = s%(sw+sd);
			if(pos < sw) {
				if(pos <= sw/2) {
					vc.push_back(cake(pos, sd));
					vc.push_back(cake(sw-pos, sd));
				} else {
					vc.push_back(cake(sw-pos, sd));
					vc.push_back(cake(pos, sd));
				}
			} else {
				pos -= sw;
				if(pos <= sd/2) {
					vc.push_back(cake(sw, pos));
					vc.push_back(cake(sw, sd-pos));
				} else {
					vc.push_back(cake(sw, sd-pos));
					vc.push_back(cake(sw, pos));
				}
			}
		}

		vi ans;
		REP(i, vc.size()) {
			ans.push_back(vc[i].d*vc[i].w);
		}
		sort(ALL(ans));
		if(ans.size() > 1) {
			REP(i, ans.size()-1) {
				cout << ans[i] << " ";
			}
		}
		cout << ans[ans.size()-1] << endl;
	}

	return 0;
}

Measured memory_bytes: 1220
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
typedef long long ll;

int main() {

    ll K;
    cin >> K;
    // Xを桁ごとのvectorに変換
    auto ll2vec = [&](ll X){
        vector<int> res;
        ll tmp = X;
        while(tmp > 0){
            res.push_back(tmp%10);
            tmp/=10;
        }
        reverse(all(res));
        return res;
    };
    auto check = [&](ll X){
        vector<int> vx = ll2vec(X);
        //桁数
        int N = vx.size();
        // dp[i][smaller][0以外を一度でも取ったか][最後の数字]
        ll dp[N+1][2][2][10];
        rep(i,N+1)rep(j,2)rep(k,2)rep(l,10)
            dp[i][j][k][l] = 0;
        dp[0][0][0][0] = 1;
        //dpの遷移
        for(int i = 0; i < N; i++)rep(j,2)rep(k,2)rep(l,10){
            int min_nxt = max(0, l-1);
            int max_nxt = min(l+1, (j ? 9:vx[i]));
            if(!k)max_nxt = j ? 9:vx[i];
            for(int nxt = min_nxt; nxt <= max_nxt; nxt++){
                dp[i+1][j || nxt < vx[i]][k || nxt][nxt] +=  dp[i][j][k][l];
            }
        }
        ll cnt = 0;
        rep(j,2)rep(l,10)cnt += dp[N][j][1][l];
        return cnt >= K;
    };

    ll ng = 0;
    ll ok = 3234566667;
    while(ok - ng > 1){
        ll mid = (ok + ng) / 2;
        if(check(mid))ok = mid;
        else ng = mid;
    }
    cout << ok << endl;
}

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

int n;
char u[100];
double x;
double ans = 0;

int main() {
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%lf%s", &x, u);
        if (strcmp(u, "JPY") == 0) ans += x;
        else ans += 380000.0 * x;
    }
    printf("%.6lf\n", ans);
}

Measured memory_bytes: 128
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

typedef long long ll;
constexpr double PI = 3.141592653589793;
constexpr ll INF = 1e18 + 10;

using namespace std;
//    cout << setprecision(20) << ans << "\n";

int main()
{
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    ll q, h, s, d, n;
    cin >> q >> h >> s >> d >> n;
    h = min(2 * q, h);
    s = min(2 * h, s);
    if (2 * s < d)
    {
        cout << n * s << "\n";
    }
    else
    {
        ll ans = n / 2 * d + n % 2 * s;
        cout << ans << "\n";
    }
    return 0;
}


Measured memory_bytes: 256
// dile a la jardinera que traigo flores

#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define sz(x) int(x.size())
#define all(v) (v).begin(),(v).end()
#define trace(x) cout << #x << " = " << x << endl
#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
#define FER(i,a,b) for(int i = int(a); i < int(b); ++i)
#define IFR(i,a,b) for(int i = int(a); i >= int(b); i--)
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;

vector<int> get(string s){
	vector<int>lel;
	int val=0;
	FER(i,0,4){
		val*=10;
		val+=s[i]-'0';
	}
	lel.pb(val);
	val=0;
	FER(i,5,7){
		val*=10;
		val+=s[i]-'0';
	}
	lel.pb(val);
	val=0;
	FER(i,8,10){
		val*=10;
		val+=s[i]-'0';
	}
	lel.pb(val);
	return lel;
}


int main(){	
	fastio;
	string s;cin>>s;
	vector<int>fecha=get(s);
	string ss="2019/04/30";
	if(ss<s)cout<<"TBD"<<endl;
	else cout<<"Heisei"<<endl;

	return 0;
}


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

int main() {
    ll N;
    cin >> N;
    ll ans = 0;
    ll r = sqrt(N);
    for (ll i = 2; i <= r; i++) {
        ll t = N;
        while (t%i == 0) t /= i;
        if (t%i == 1) ans++;
    }
    
    vector<ll> div;
    for (ll i = 1; i <= r; i++) {
        if ((N-1)%i == 0) {
            div.push_back(i);
            if (i*i != N-1) div.push_back((N-1)/i);
        }
    }
    for (ll k : div) {
        if (k > r) ans++;
    }
    ans++;
    cout << ans << endl;
    
    return 0;
}

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

// --------------------------------------------------------------------------------
#define FASTIO	ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define ll long long 
#define mset(arr,val) memset(arr,val,sizeof(arr))
#define fset(arr,n,val) for(int i=0;i<n;++i) arr[i] = val
#define deb(name,value) cout <<"->>  "<<name<< "= " <<value<<" "
#define frepi(a,b) for(int i=a;i<=b;i++)
#define frepj(a,b) for(int j=a;j<=b;j++)
// --------------------------------------------------------------------------------

void solve_main()
{
    string s,t;cin>>s>>t;
    int n = s.size();
    int ans = 0;
    for(int i=0;i<n;++i)
    {
    	if(s[i]!=t[i])ans++;
    }
    cout<<ans;

}

int main()
{

	// #ifndef ONLINE_JUDGE
	//	freopen("/home/suryakant/input.txt","r",stdin);
	//	freopen("/home/suryakant/output.txt","w",stdout);
	// #endif

    int t=1;
    // cin>>t;
    while(t--)
    {
    	solve_main();
    }
    //for(int caset=1;caset<=t;++caset)
    //{
    //    solve_main();
    //}
    
}

Measured memory_bytes: 3824
import sys
from scipy.sparse.csgraph import connected_components
from scipy.sparse import csr_matrix
import numpy as np

readline = sys.stdin.readline

N, M = map(int, readline().split())
# 言語を頂点N+Kとする
a = []
b = []
for i in range(M + 1, M + N + 1):
    K, *L = map(int, readline().split())
    l = len(L)
    a.extend([i] * l)
    b.extend(L)

m = csr_matrix(([1] * len(a), (a, b)), shape=(N + M + 1, N + M + 1))
n, label = connected_components(m, directed=False)
if np.all(label[1 + M:] == label[1 + M]):
    print('YES')
else:
    print('NO')


Measured memory_bytes: 27184
N = input()
M = [map(int, raw_input().split()) for i in xrange(N)]
cache = {}
for i in xrange(N):
    cache[(i, i+1)] = 0
def dfs(left, right):
    if (left, right) in cache:
        return cache[(left, right)]
    min_cost = float("inf")
    for mid in xrange(left+1, right):
        tmp = M[left][0] * M[mid-1][1] * M[right-1][1]
        tmp += dfs(left, mid)
        tmp += dfs(mid, right)
        if min_cost > tmp:
            min_cost = tmp
    cache[(left, right)] = min_cost
    return min_cost
print dfs(0, len(M))

Measured memory_bytes: 4744
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <climits>
#include <sstream>

using namespace std;

int main(){
  int a, b, ans=0;

  cin >> a >> b;

  int x = b - a;

  for(int i = 1; i < x; i++){
    ans += i;
  }

  ans -= a;

  cout << ans << endl; 

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
    #define F first
    #define S second
    using ll = long long;
    const ll mod = 1000000007;
    const ll infi = 1000000000000000;
    const ll md = 998244353;
    using namespace std;
    using vl = vector<ll>;
    using pll =  pair<ll,ll>;

    void solve(){
        ll n,mx=0;cin>>n; vl a(n);
        for(int i=0;i<n;i++) cin>>a[i];
        ll cnt = 0;
        for(int i=1;i<n;i++){
            if(a[i]<=a[i-1]){
                cnt++;
            }
            else {
                if(cnt >mx) mx = cnt;
                cnt = 0;
            }
        }
       if(cnt > mx) mx = cnt;
        cout<<mx;
    }
     
    int main() {
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        //int n;cin>>n; for(int i=0;i<n;i++)
        solve();
        return 0;
    } 

Measured memory_bytes: 1024
#include<cstdio>
#include<iostream>
#include<cctype>

typedef long long ll;
using namespace std;


int main(){
	int n,m;
	scanf("%d%d",&n,&m);
	ll ans = 0,cnt = 0;
//	for(int i = 1;i <= n;i++){
//		for(int j = 1;j <= n;j++){
//			for(int k = 1;k <= n;k++){
//				if((i + j) % m == 0 && (j + k) % m == 0 && (i + k) % m == 0) printf("%d %d %d\n",i,j,k),cnt++;
//			}
//		}
//	}
	if(m % 2 == 1){
		ll t = n / m;
		ans = t * t * t;
	} else {
		ll halfm = 0,fullm = 0;
		for(int i = 1;i <= n;i++){
			if(i % m == m / 2) halfm++;
			else if(i % m == 0) fullm++;
		}
		ans = halfm * halfm * halfm + fullm * fullm * fullm;
	}
	
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 256
# D
from bisect import bisect_left
A, B, Q = map(int, input().split())

s_list = [0]*A
t_list = [0]*B
q_list = [0]*Q

for i in range(A):
    s_list[i] = int(input())
for i in range(B):
    t_list[i] = int(input())
for i in range(Q):
    q_list[i] = int(input())
    
def query_dist(q):
    res = 10**11
    # s -> t
    ind_s = bisect_left(s_list, q)
    if ind_s != len(s_list):
        s = s_list[ind_s]
        ind_t = bisect_left(t_list, s)
        if ind_t != len(t_list):
            t = t_list[ind_t]
            res = min(res, abs(s-q)+abs(t-s))
        if ind_t != 0:
            t = t_list[ind_t-1]
            res = min(res, abs(s-q)+abs(t-s))
    if ind_s != 0:
        s = s_list[ind_s-1]
        ind_t = bisect_left(t_list, s)
        if ind_t != len(t_list):
            t = t_list[ind_t]
            res = min(res, abs(s-q)+abs(t-s))
        if ind_t != 0:
            t = t_list[ind_t-1]
            res = min(res, abs(s-q)+abs(t-s))
            
    ind_t = bisect_left(t_list, q)
    if ind_t != len(t_list):
        t = t_list[ind_t]
        ind_s = bisect_left(s_list, t)
        if ind_s != len(s_list):
            s = s_list[ind_s]
            res = min(res, abs(t-q)+abs(s-t))
        if ind_s != 0:
            s = s_list[ind_s-1]
            res = min(res, abs(t-q)+abs(s-t))
    if ind_t != 0:
        t = t_list[ind_t-1]
        ind_s = bisect_left(s_list, t)
        if ind_s != len(s_list):
            s = s_list[ind_s]
            res = min(res, abs(t-q)+abs(s-t))
        if ind_s != 0:
            s = s_list[ind_s-1]
            res = min(res, abs(t-q)+abs(s-t))
    return res

for q in q_list:
    print(query_dist(q))

Measured memory_bytes: 18024
def findunit(edges, N):
  roots = [i for i in range(N)]
  for edge in edges:
    if roots[edge[0]] == roots[edge[1]]:continue
    prv_root = roots[edge[1]]
    for idx, root in enumerate(roots):
      if root == prv_root:
        roots[idx] = roots[edge[0]]
  return roots

N,M=map(int,input().split())
edges = [ [int(a) -1 for a in input().split()] for _ in range(M)]
ans = 0
for i in range(M):
  if len(set(findunit(edges[:i] + edges[i+1:], N))) != 1:ans += 1
print(ans)

Measured memory_bytes: 39536
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <cmath>
using namespace std;

int main(){

  int d, e;

  while(cin >> d >> e, d | e){
    int x = d;
    int y = 0;
    double ex;
    double ans = 10000000;
    while(y < d){
      ex = (double)(abs((sqrt(x * x + y * y) - e)));
      ans = min(ex, ans);
      x--;
      y++;
    }
    cout << fixed << setprecision(10) << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 3244
N = int(input())
ss = input().split()
a = [int(i) for i in ss]

l = [0] * 9
for i in a :
	l[min(i//400,8)] += 1

mn = 0
mx = 0
for i,j in enumerate(l) :
	if i < 8 :
		mn += min(1,j)
	else :
		mx = mn + j
print(max(mn,1), mx)


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

#define ll long long
#define f(i, a, b) for(ll i=a;i<b;i++)
#define fi(i, a, b) for(ll i=b-1;i>=a;i--)
#define pb push_back
#define vi vector<int>
#define vl vector<ll>
#define ml map<ll,ll>
#define pll pair<ll,ll>

int main(){

  int n;
  cin>>n;
  int cnt=1;
  int ans=0;

  if(n%2==0 || n%5==0)
  cout<<"-1";
  else{
         while(1){
          ans = ans*10 + 7;
         if(ans%n==0){
           cout<<cnt;
             break;
            }
            ans%=n;
          cnt++;
         }
      }
  }


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

typedef long long ll;
using namespace std;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll x, k, d;
    cin >> x >> k >> d;
    ll opt = k / 2 - x / (2 * d);
    ll ans = min(abs(x + d * k), abs(x - d * k));
    for (ll de = -1000; de <= 1000; de++) {
        ll i = de + opt;
        if (i >= 0 && i <= k) {
            ans = min(ans, abs(x + d * (2 * i - k)));
        }
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 3576
import sys
from collections import defaultdict, Counter, deque
from itertools import accumulate, permutations, combinations
from operator import itemgetter
from bisect import bisect_left, bisect_right, bisect
from heapq import heappop, heappush
from fractions import gcd
from math import ceil, floor, sqrt, cos, sin, pi
from copy import deepcopy

# If you use recursive call, uncomment this code
#sys.setrecursionlimit(10**6)


def d(yy,zz):
    ans = 0
    for i in range(len(yy)):
        ans += (yy[i]-zz[i])**2
    return sqrt(ans)

def main():
    N,D = map(int, input().split())
    xx = []
    for _ in range(N):
        xx.append(list(map(int,input().split())))
    
    c = 0
    for i in range(N):
        for j in range(i+1,N):
            if d(xx[i], xx[j]).is_integer():
                c += 1
    
    print(c)

if __name__ == '__main__':
    main()


Measured memory_bytes: 5244
n,m = map(int,input().split())
lis = []
for i in range(m):
  l = list(map(int,input().split()))
  l.remove(l[0])
  lis.append(l)
ch = list(map(int,input().split()))
ans = 0
for i in range(2 ** n):
  key = 1
  s = str(format(i,"b").zfill(n))
  for j in range(m):
    num = 0
    for nu in lis[j]:
      if s[nu-1] == "1":
        num += 1
    if num % 2 != ch[j]:
      key = 0
  if key == 1:
    ans += 1

print(ans)

Measured memory_bytes: 3064
#pragma GCC target ("avx2")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize ("O3")
#include "bits/stdc++.h"
#include <unordered_set>
#include <unordered_map>
#include <random>
using namespace std;
typedef long long ll;
const ll MOD = 1'000'000'007LL; /*998'244'353LL;*/
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(n); (i)++)
const int dx[4]={ 1,0,-1,0 };
const int dy[4]={ 0,1,0,-1 };

int N;
int A[200000], B[200000];

signed main(){
    cin >> N;
    rep(i, N) cin >> A[i];
    rep(i, N) cin >> B[i];

    int zure = 0;
    rep(i, N){
        int idx = upper_bound(B, B+N, A[i]) - B;
        zure = max(zure, idx-i);
    }
    rep(i, N){
        if(A[i] == B[(i+zure)%N]){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    rep(i, N){
        if(i != 0) cout << " ";
        cout << B[(i+zure)%N];
    }
    cout << endl;
}

Measured memory_bytes: 5192
import java.util.Scanner;

public class Main {
    private static final int MOD = 1_000_000_007;
    private static final String YES = "Yes";
    private static final String NO = "No";

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

        int N = sc.nextInt();
        int M = sc.nextInt();
        int[] A = new int[M];
        for (int i=0; i<M; i++) {
            A[i] = sc.nextInt();
        }

        System.out.println(solve(N, M, A));
    }

    private static long solve(int N, int M, int[] A) {
        long sum = N;

        for (int i=0; i<M; i++) {
            sum -= A[i];
        }

        if (sum < 0) sum = -1;

        return sum;
    }
}

Measured memory_bytes: 46420
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i, n) FOR(i, 0, (n))
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define LAR(a, b) ((a)=max((a),(b)))
#define SML(a, b) ((a)=min((a),(b)))
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pair<int, int>> vpii;
typedef pair<int, int> pii;
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define ALL(a) (a).begin(), (a).end()
#ifdef LOCAL_DEBUG
#define DEBUG(...) printf(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

#define N 1123456

int main(){
	ll n; scanf("%lld", &n);
	ll ans = LLONG_MAX;
	for(ll i = 1; i < N; i++){
		if(n % i == 0){
			SML(ans, i + n/i);
		}
	}
	printf("%lld\n", ans-2);
}


Measured memory_bytes: 384
#include <iostream>

int main(){
    unsigned long long int x;
    std::cin >> x;

    unsigned long long int n = 100;
    int count = 0;
    while (n < x)
    {
        n += n / 100;
        count++;
    }
    std::cout << count << std::endl;

    return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <iomanip>
#include <algorithm>
#include <sstream>
#include <string>
#include <math.h>
#include <set>
using namespace std;
typedef long long ll;
 
int main() {
	int a,b,c;
	cin >> a >> b >> c;
	if (b-a==c-b) cout << "YES";
	else cout << "NO";
}

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

int M, N, K;
char map[1010][1010];
int jt[1010][1010];
int ot[1010][1010];
int it[1010][1010];

int main() {
  cin >> M >> N >> K;
  for (int i=1; i<=M; i++) {
    int hj = 0, ho = 0, hi = 0;
    for (int j=1; j<=N; j++) {
      cin >> map[i][j];
      jt[i][j] = jt[i-1][j] + hj;
      ot[i][j] = ot[i-1][j] + ho;
      it[i][j] = it[i-1][j] + hi;

      char c = map[i][j];
      if (c == 'J') { jt[i][j]++; hj++; }
      if (c == 'O') { ot[i][j]++; ho++; }
      if (c == 'I') { it[i][j]++; hi++; }
    }
  }

  for (int i=0; i<K; i++) {
    int a, b, c, d;
    cin >> a >> b >> c >> d;

    int J = 0;
    int O = 0;
    int I = 0;
    cout << jt[c][d] - jt[a-1][d] - jt[c][b-1] + jt[a-1][b-1] << " "
         << ot[c][d] - ot[a-1][d] - ot[c][b-1] + ot[a-1][b-1] << " "
         << it[c][d] - it[a-1][d] - it[c][b-1] + it[a-1][b-1] << "\n";
  }
  return 0;
}

Measured memory_bytes: 15708
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (ll i=0; i<(n); ++i)
typedef long long ll;
bool debug=false;
string yes = "Yes";
string no = "No";
ll mod = 1000000007;

int main(){
  ll n; cin >> n;
  if(n%2==1){ std::cout << 0 ; return 0;}
  ll ans = 0;
  ll div = 10;
  while(div<=n){
    ans += n/div;
    div*=5;
  }
  std::cout << ans;
  return 0;
}

Measured memory_bytes: 256
const main = (input: string) => {
  const lines = input.split("\n");
  const H = lines[1].split(" ").map(str => parseInt(str));
  let maxH = H[0];
  let answer = 0;

  H.forEach((h, i) => {
    if (i === 0 || (H[i - 1] <= h && H[0] <= h && maxH <= h)) {
      answer += 1;
      maxH = h;
    }
  });

  console.log(answer);
};

main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7372
#include <vector>
#include <iostream>

using namespace std;

unsigned int gcd(unsigned int x, unsigned int y)
{
	if (x == y)
		return x;

	if (y == 0)
		return x;

	if (x > y)
		return gcd(y, x % y);

	return gcd(x, y % x);
}

int main()
{
	unsigned int x, y;
	cin >> x >> y;

	cout << gcd(x, y) << endl;

	return 0;
}



Measured memory_bytes: 3100
import sys
input = sys.stdin.readline


def gcd(x: int, y: int) -> int:
    if x < y:
        x, y = y, x
    while y > 0:
        r = x % y
        x, y = y, r
    return x


def main():
    X, Y = [int(i) for i in input().strip().split()]
    print(gcd(X, Y))


if __name__ == "__main__":
    main()



Measured memory_bytes: 5608
#include <iostream>
#include <algorithm>
#include <array>
#include <cstdint>
#include <functional>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdlib.h>
#include <string>
#include <time.h>
#include <utility>
#include <vector>

#define INF 1000000000
#define MOD 1000000007
#define rep(i,a,b) for(int32 i = (a); i < (b); ++i)
#define bitget(a,b) (((a) >> (b)) & 1)
#define ALL(x) (x).begin(),(x).end()
#define C(x) std::cout << #x << " : " << x << std::endl
#define scanf scanf_s

using int32 = std::int_fast32_t;
using int64 = std::int_fast64_t;
using uint32 = std::uint_fast32_t;
using uint64 = std::uint_fast64_t;



int main(void) {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	int32 n, m;
	std::cin >> n >> m;
	std::vector<int64> x(n), y(m), a(n-1, 0), b(m-1, 0);
	rep(i, 0, n)
		std::cin >> x[i];
	rep(i, 0, m)
		std::cin >> y[i];
	std::sort(ALL(x));
	std::sort(ALL(y));
	rep(i, 0, n - 1) {
		a[i] = i + 1 - n + 1 + 1 + i;
	}
	rep(i, 0, m - 1) {
		b[i] = i + 1 - m + 1 + 1 + i;
	}
	for (uint32 i = n - 3;~i;--i) {
		a[i] += a[i + 1];
	}
	for (uint32 i = m - 3;~i;--i) {
		b[i] += b[i + 1];
	}
	uint64 c = 0, d = 0;
	rep(i, 0, n - 1) {
		c = (c + ((x[i + 1] - x[i])*a[i])%MOD) % MOD;
	}
	rep(i, 0, m - 1) {
		d = (d + ((y[i + 1] - y[i])*b[i])%MOD) % MOD;
	}
	std::cout << (c*d) % MOD << "\n";
	return 0;
}

Measured memory_bytes: 3456