akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

// 最小公倍数
ll lcm(ll a, ll b){
    return a*b/gcd(a, b);
}

int main()
{
    cout << fixed << setprecision(15);
    ll a, b;
    cin >> a >> b;
    cout << (a+b+1)/2 << endl;
    return 0;
}

Measured memory_bytes: 384
#pragma GCC optimize("O3")
#pragma GCC target("avx")
#include <bits/stdc++.h>
#define rep(i ,n) for(int i=0;i<(int)(n);++i)
#define repr(i ,n) for(int i=n;i>(int)(n);--i)
#define rep1(i ,n) for(int i=1;i<=(int)(n);++i)
#define ALL(a) a.begin(), a.end()
#define RSORT(a) sort(ALL(a),greater<>())
#define SORT(a) sort(ALL(a))
#define bit_check(bit, i) ((bit>>(i)) & 1)
#define PRINT(x) printf("%d\n",(x));
#define ENDL printf("\n");
using namespace std;
typedef long long int i64;
typedef unsigned long long u64;
template<class T> using V = vector<T>;
using VI = V<int>;
const int INF = 2e9;
const i64 MOD = 1e9 + 7;

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;}

signed main(){
    int n;
    while( cin >> n && n){
        vector<pair<char , char>> conv(n);
        rep(i , n) cin >> conv[i].first >> conv[i].second;
        int m; cin >> m;
        vector<char> c(m);
        rep(i ,m) cin >> c[i];
        rep(j ,m){
            rep(i ,n){
                if( c[j] == conv[i].first) { c[j] = conv[i].second; break; }
            }
        }
        rep(i , m){
            printf("%c" , c[i]);
        }
        ENDL;
    }
}


Measured memory_bytes: 3084
import java.util.Scanner;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String str = sc.nextLine();
        if(Integer.parseInt(str) >= 100 && Integer.parseInt(str) <= 999){
            if(str.charAt(0) == str.charAt(2))
                System.out.println("Yes");
            else
                System.out.println("No");
        }
    }
}


Measured memory_bytes: 23252
#include<bits/stdc++.h>
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define int long long 
#define pb push_back
#define ins insert
#define rs resize
#define br break;
#define cont continue;
#define vi vector<int>
#define vll vector<long long>
#define vvi vector<vector<int>>
#define si set<ll>
#define sll set<long long>
#define pii pair<ll,ll>
#define pll pair<long long, long long>
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL);
#define vec vector
#define cend cout<<endl;
#define sc second
#define fr first
#define retz return 0;
#define ll_MAX (ll)(1e9*1e9)
#define ll_MIN (ll)(-1e9*1e9)
#define lb lower_bound
#define ub upper_bound
#define rep(i,a,b)  for(int i=a; i<=b; i++)
#define repd(i,a,b) for(int i=a; i>=b; i--)
#define ps(arr, n) for(int i=1; i<n; i++)arr[i]+=arr[i-1];
#define inp(arr, n)for(int i=0; i<n; i++)cin>>arr[i];
#define out(arr, n)for(int i=0; i<n; i++)cout<<arr[i];
#define inp1(arr,n,m)for(int i=0; i<n; i++)for(int j=0;j<m;j++)cin>>arr[i][j];
#define out1(arr,n,m)for(int i=0; i<n; i++)for(int j=0;j<m;j++)cin>>arr[i][j];
#define loop(q) for(auto it:q)
#define loop1(q) for(auto&it:q)
#define db1 cout << "*" << endl
#define db2 cout << "YES" << endl
using namespace std;
using namespace __gnu_pbds; 
#define oset(X) tree<X,null_type,less<X>, rb_tree_tag, tree_order_statistics_node_update> 
#define roset(X) tree<X,null_type,greater<X>, rb_tree_tag, tree_order_statistics_node_update>  
#define okey order_of_key //lower_bound_set
#define ofind find_by_order
#define cyes cout << "Yes" << endl; 
#define cno cout << "No" << endl;
#define mod2 (long long)1000000007
#define mod (long long)998244353
#define INT_MAX1 900000000
#define MAXN 2000000
#define INF INT_MAX




void solve()
{
    int n;
    cin >> n;
    int arr[n];
    inp(arr, n);
    int cnt = 0;
    rep(i,0,n-1)
    {
        cnt += (arr[i]!=i+1);
    }

    if(cnt <= 2)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
}



signed main()
{
    speed;
    int t = 1;
    //cin >> t;
    while(t--)
        solve();
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <tuple>
#include <algorithm>
#include <set>

using namespace std;


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

	vector<tuple<int, int, int>> X;

	for (int i = 0; i < N; i++)
	{
		int s, t, x;
		cin >> s >> t >> x;

		X.push_back(make_tuple(x, s, t));
	}

	set<pair<int, int>> D;

	for (int i = 0; i < Q; i++)
	{
		int d;
		cin >> d;
		D.insert(make_pair(d, i));
	}

	sort(X.begin(), X.end());
	
	vector<int> kekka(Q, -1);

	for (int i = 0; i < N; i++)
	{
		int s, t, x;

		tie(x, s, t) = X[i];

		auto it = D.lower_bound(make_pair(s - x, -1));

		while (it != D.end())
		{
			if(it->first >= t -x)
			{
				break;
			}
			kekka[it->second] = x;
			D.erase(it++);
		}
	}

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

	return 0;
}


Measured memory_bytes: 14320
#include <bits/stdc++.h>
 
    using namespace std;
 
    typedef long long ll;
    typedef long double ld;
 
    typedef pair<int, int> pi;
    typedef pair<ll,ll> pl;

    typedef vector<int> vi;
    typedef vector<ll> vl;
    typedef vector<pi> vpi;
    typedef vector<pl> vpl;
    typedef vector<vi> vvi;

    #define FOR(i, a, b) for (int i=a; i<(b); i++)
    
    #define sz(x) (int)(x).size()
    #define mp make_pair
    #define pb push_back
    #define f first
    #define s second
    #define lb lower_bound
    #define ub upper_bound
    #define all(x) x.begin(), x.end()
 
    template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
    template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
    
    #define trav(container, it) for(typeof(container.begin()) it=container.begin(); it!=container.end(); it++)
 
    const int MOD = 1000000007;
    const char nl = '\n';
 
    int main() 
    {
        ios_base::sync_with_stdio(0); cin.tie(0);
            int n;cin>>n;
            vl v(n);
            FOR(i,0,n) cin>>v[i];
            
            ll res=1;
            sort(all(v));
            if(v[0]==0) res=0;
            else
            FOR(i,0,n)
            {
                if(v[i]>1000000000000000000/res) {res=-1;break;}
                else res*=v[i];
            }

            cout<<res<<nl;
    }


Measured memory_bytes: 3896
#!/usr/bin/python3

def main():
    sunukes, eating = map( int, input().split() )
    counts = [ 0 for _ in range(sunukes) ]

    for _ in range(eating):
        has = int( input() )
        having = list( map( int, input().split() ) )

        for i in range( len(having) ):
            counts[ having[i] - 1 ] += 1
    
    print(counts.count(0))


if __name__ == "__main__":
    main()

Measured memory_bytes: 9200
import std.stdio;
import std.string;
import std.conv;

int main()
{
    int n = readln().chomp().to!int();
    string s = "Hoshino";
    while (n--) {
        string str = readln().chomp();
        char[] ans;
        for (int i = 0; i < str.length; i++) {
            ans ~= str[i];
            if (str[i] == 'H') {
                bool flag = true;
                if (i + 6 > str.length - 1) flag = false;
                for (int j = 0; j < 7 && flag; j++) {
                    if (str[i + j] != s[j]) flag = false;
                }
                if (flag) {
                    i += 6;
                    ans ~= str[i-5..i];
                    ans ~= 'a';
                }
            }
        }
        writeln(ans);
    }

    return 0;
}

Measured memory_bytes: 1048
import java.util.*;

import java.lang.*;

import java.math.*;



public class Main {

	Scanner sc = new Scanner(System.in);

	void run(){

		for(;sc.hasNextInt();){

			int a = sc.nextInt();

			int b = sc.nextInt();

			int n = sc.nextInt();

			a = a%b;

			int sum=0;

			for(int i=0;i<n;i++){

				sum+=a*10/b;

				a = a*10%b;

			}

			System.out.println(sum);

		}

		

	}

	public static void main(String[] args){

		Main m = new Main();

		m.run();

		

	}

}

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

int main (){
    int a,b;

    scanf("%d %d",&a,&b);
    if(a % 3 == 0 || b % 3 == 0 || (a+b) % 3 == 0){
        printf("Possible\n");
    }else{
        printf("Impossible\n");
    }
    
    return 0;
}


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

using namespace std;

typedef long long ll;
const int N = 5000 + 7;
const int MOD1 = (int) 1e9 + 7;
const int MOD2 = (int) 1e9 + 9;

int add1(int a, int b)
{
    a += b;
    if (a >= MOD1)
    {
        return a - MOD1;
    }
    if (a < 0)
    {
        return a + MOD1;
    }
    return a;
}

int mul1(int a, int b)
{
    return a * (ll) b % MOD1;
}

int add2(int a, int b)
{
    a += b;
    if (a >= MOD2)
    {
        return a - MOD2;
    }
    if (a < 0)
    {
        return a + MOD2;
    }
    return a;
}

int mul2(int a, int b)
{
    return a * (ll) b % MOD2;
}


int n, a[N], b1[N], b2[N], c1[N][N], c2[N][N];
string s;

bool ok(int l)
{
    for (int i = 0; i + l - 1 < n; i++)
    {
        b1[i] = c1[i][i + l - 1];
        b2[i] = c2[i][i + l - 1];
    }
    set <int> hsh1;
    set <int> hsh2;
    for (int i = l; i + l - 1 < n; i++)
    {
        hsh1.insert(b1[i - l]);
        hsh2.insert(b2[i - l]);
        if (hsh1.count(b1[i]) && hsh2.count(b2[i]))
        {
            return 1;
        }
    }
    return 0;
}

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

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

    for (int i = 0; i < n; i++)
    {
        c1[i][i] = a[i];
        c2[i][i] = a[i];
        for (int j = i + 1; j < n; j++)
        {
            c1[i][j] = add1(mul1(c1[i][j - 1], 26), a[j]);
            c2[i][j] = add2(mul2(c2[i][j - 1], 26), a[j]);
        }
    }

    int l = 1, r = n, ans = 0;
    while (l <= r)
    {
        int md = (l + r) / 2;
        if (ok(md))
        {
            ans = md;
            l = md + 1;
        }
        else
        {
            r = md - 1;
        }
    }
    cout << ans << "\n";

}


Measured memory_bytes: 195584
#include <bits/stdc++.h>
using namespace std;
// マクロ
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
// 型エイリアス
using ll = long long;
using vi = vector<int>;
using vs = vector<string>;
using vvi = vector<vi>;
using vvs = vector<vs>;

int main() {
    int n;
    cin >> n;
    vi l(n);
    rep(i,n) cin >> l[i];
    sort(l.rbegin(),l.rend());
    int sum = 0;
    for(int i = 1; i < n; i++) {
        sum += l[i];
    }
    if(l[0] < sum) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
from math import ceil
ord = [int(input()) for _ in range(5)]
max_wait = 0
max_idx = 0
for i in range(5):
    cur = ceil(ord[i] / 10) * 10 - ord[i]
    if max_wait < cur:
        max_wait = cur
        max_idx = i
ans = 0
for i in range(5):
    if i != max_idx:
        ans += ceil(ord[i] / 10) * 10
ans += ord[max_idx]
print(ans)

Measured memory_bytes: 38384
/*
                                Bismillahi-r-Rahmani-r-Rahim
                                        RhIeyAaD
                                    IIT-7th Batch,JU
*/
#include<bits/stdc++.h>
using namespace std;

#define ll              long long int
#define MAX             2134567891
#define fr(i,n)         for(i=0;i<n;i++)
#define rep(i,n)        for(i=1;i<=n;i++)
#define rev(i,a,n)      for(i=n;i>=a;i--)
#define FOR(i,a,n)      for(i=a;i<=n;i++)
#define ALL(n)          n.begin(),n.end()
#define mem(x,n)        memset(x,n,sizeof(x))
#define TC(t)           printf("Case %lld: ",t)
#define ans(t,c)        printf("Case %lld: %lld\n",t,c)
#define SETP(n)         cout<<setprecision(n)<<fixed
#define READ            freopen("F:\\Project\\Test_Case.txt","r",stdin)
#define WRITE           freopen("F:\\Project\\Output_Test.txt","w",stdout)
#define IO              ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0);
#define PAIR            pair<ll,ll>
#define MP              make_pair
#define pb(a)           push_back(a)
#define ff              first
#define ss              second
#define NL              printf("\n");
#define debug(a)        cout<<a<<" ";
#define hlw             printf("hlw\n");
#define NN              111
#define MOD             1000000007///10^9
#define N               222 ///10^6->6 zero after 1 **

ll x[N][N],y[N],z[N],n;
string s,S;
vector<ll>v;
//map <ll,ll> mp;

int main()
{
    //IO;
    //while(1)
    //READ;WRITE;
{
    ll a=0,b=0,c=0,d,e,f,g,i,j,k,l,m,p,q,r,u,w,t,tc,in,mod,loc,diff,val,sz,lo,hi,mid,mn=MAX,mx=0,sum=0,ans=0;
    cin>>n;
    rep(i,n)
    {
        rep(j,n)
            x[i][j]=__gcd(i,j);
    }
    rep(i,n)
    {
        rep(j,n)
        {
            rep(k,n)
            {
                a=x[i][x[j][k]];
                //cout<<"i "<<i<<" j "<<j<<" k "<<k<<" a "<<a<<endl;
                //x[a]++;
                ans+=a;
            }
        }
    }
    //rep(i,n)cout<<i<<" "<<x[i]<<endl;
    cout<<ans<<endl;
}
    return 0;
}

/*

*/
/// Check for constraint 0 or 1?
/// long long or double? sqrt or division will work fine??


Measured memory_bytes: 3980
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
using namespace std;

int H, W;
char c[10][10];

bool f(int y, int x) {
  if (y < 0 || x < 0 || c[y][x] == '.') return false;
  if (y == 0 && x == 0) return true;
  return f(y-1, x) || f(y, x-1);
}

int main() {
  cin >> H >> W;
  int ctr = 0;
  for (int i=0; i<H; i++) {
    for (int j=0; j<W; j++) {
      cin >> c[i][j];
      if (c[i][j] == '#') ctr++;
    }
  }
  if (ctr != W+H-1 || c[0][0] == '.') cout << "Impossible\n";
  else {
    cout << (f(H-1, W-1) ? "Possible" : "Impossible") << "\n";
  }
  return 0;
}



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

#define vec vector<int>
#define vecll vector<ll>
#define vpair vector<pair<int, int>>
#define vpairll vector<pair<ll, ll>>

#define rep(i,n)         for(int i=(int)0; i<(int)n; i++)
#define REP(i,m,n)       for(int i=(int)m; i<(int)n; i++)
#define arr(var, n)      vec var(n); rep(i,n){cin >> var[i];}
#define arrll(var, n)    vecll var(n); rep(i,n){cin >> var[i];}
#define all(var)         (var).begin(), (var).end()
#define sortall(var)     sort(all(var))
#define prt(var)         cout << var << endl
#define prtd(n, var)     cout << fixed << setprecision(n) << var << endl
#define prt2(v1, v2)     cout << v1 << " " << v2 << endl
#define prt3(v1, v2, v3) cout << v1 << " " << v2 << " " << v3 << endl
#define prtall(var)      rep(i,var.size()){cout << var[i] << " ";} cout << endl

//----------------------------------------------------------------

int main(void) {
  int a[32]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  int k;
  cin >> k;

  prt(a[k-1]);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;

int x[200000];

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> v;
    for (int i = 0; i < n; ++i)
    {
        cin >> x[i];
        v.push_back(x[i]);
    }
    sort(all(v));
    int ml = v[n / 2 - 1];
    int mh = v[n / 2];
    for (int i = 0; i < n; ++i)
    {
        if (x[i] <= ml)
            cout << mh << '\n';
        else
            cout << ml << '\n';
    }
}


Measured memory_bytes: 3956
n,x = gets.chomp.split(' ').map(&:to_i)
l = gets.chomp.split(' ').map(&:to_i)
current = 0
count = 0
l.each do |num|
  if (current <= x)
    count += 1
  end
  current += num
end
if (current <= x)
  count += 1
end
puts count

Measured memory_bytes: 14184
#include <iostream>
#include <algorithm>
#define flush fflush(stdout)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int mod = (int)1e9 + 7, INF = (int)1e9;


int main(void) {
	double r;
	const double pi = 3.14159265;

	scanf("%lf", &r);

	printf("%.12lf\n", r * pi * 2);

	return 0;
}

Measured memory_bytes: 3816
#include<cstdio>
#include<iostream>
#include<cstring>

int n,a[101];

int main() {
    std::cin >> n;
    for(int i = 1;i <= n;i++) std::scanf("%d",a + i);
    
    for(int i = 1;i <= n;i++) {
        if(a[i] & 1) continue;
        if((a[i] % 3) && (a[i] % 5)) {
            std::puts("DENIED");
            return 0;
        }
    }
    std::puts("APPROVED");

    return 0;
}


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


#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repback(i,n) for(int i=(int)n-1;i>=0;i--)
#define repa(i,a,n) for(int i=a;i<(int)(n);i++)
typedef pair<int, int> P;
typedef long long ll;
const ll INF = 1e7, MAX_N = 1000000, MAX_M = 1000, MAX_W = 20, MAX_H = 20;
int asc(const void* a, const void* b) {
    return *(int*)a - *(int*)b;
}

int gcd(int a, int b) {
    if (a % b == 0) return b;
    else gcd(b, a % b);
}

ll lcm(ll a, ll b) {
    return a * b / (ll)gcd(a, b);
}

int main() {
    int n,m;
    while (cin >> n >> m) {
        int a1 = gcd(n, m);
        int a2 = lcm(n, m);
        cout << a1 <<" "<< a2 << endl;
    }

    return 0;
}


Measured memory_bytes: 3004
# coding: utf-8
# Your code here!

from collections import defaultdict

N = int(input())
X = list(map(int, input().rstrip().split(' ')))
sorted_X = sorted(X)

x2med = defaultdict(lambda: -1)

med_index = (len(X) - 1) // 2
for i, x in enumerate(sorted_X):
    if i <= med_index:
        x2med[x] = sorted_X[med_index + 1]
    else:
        x2med[x] = sorted_X[med_index]
        
for i, x in enumerate(X):
    print(x2med[x])
    

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

int main()
{
  int t,a[3][3],b[10];
  bool a2[3][3];
  for(int i=0;i<3;i++)
  {
    for(int j=0;j<3;j++)
    {
      cin>>a[i][j];
    }
  }
  cin>>t;
  for(int i=0;i<t;i++)
  {
    cin>>b[i];
  }
  for(int i=0;i<t;i++)
  {
    for(int j=0;j<t;j++)
    {
      a2[i][j]=false;
      for(int k=0;k<t;k++)
      {
        if(a[i][j]==b[k])
        {
          a2[i][j]=true;
        }
      }
    }
  }
  string ANS="No";
  for(int i=0;i<3;i++)
  {
    if(a2[i][0] && a2[i][1] && a2[i][2])
      ANS="Yes";
  }
  for(int i=0;i<3;i++)
  {
    if(a2[0][i] && a2[1][i] && a2[2][i])
      ANS="Yes";
  }
  if(a2[0][0] && a2[1][1] && a2[2][2])
    ANS="Yes";
  if(a2[0][2] && a2[1][1] && a2[2][0])
    ANS="Yes";
  cout<<ANS<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdint.h>
#include<inttypes.h>

typedef int32_t i32;

void run (void) {
  i32 n;
  scanf ("%" SCNi32, &n);
  char s[5];
  scanf ("%s", s);
  while (--n) {
    char t[5];
    scanf ("%s", t);
    if (s[0] == 'T' && t[0] == 'F') {
      s[0] = 'F';
    } else {
      s[0] = 'T';
    }
  }
  puts (s);
}

int main (void) {
  run();
  return 0;
}



Measured memory_bytes: 2112
#include <bits/stdc++.h>
#include<bits/stdc++.h>
using namespace std;
using ll = int64_t;
using P = pair<ll, ll>;
struct Edge{
    ll to, cap, rev_index;
};
class FordFulkerson{
    private:
        vector<vector<Edge>> v;
        ll n;
        bool *used;
        const ll INF = numeric_limits<ll>::max();

        int dfs(ll now, ll goal, ll f){
            if(now == goal) return f;
            used[now] = 1;
            for(Edge &e : v[now]){
                if(used[e.to]){
                    continue;
                }
                if(e.cap <= 0){
                    continue;
                }
                ll d = dfs(e.to, goal, min(f, e.cap));
                if(d > 0){
                    e.cap -= d;
                    v[e.to][e.rev_index].cap += d;
                    return d;
                }
            }
            return 0;
        }

    public:
        FordFulkerson(const vector<vector<pair<ll, ll>>> &v){
            this->n = v.size();
            for(int i = 0; i < n; i++){
                this->v.push_back(vector<Edge>(0));
            }
            for(int i = 0; i < n; i++){
                for(auto e : v[i]){
                    this->v[i].push_back((Edge){e.first, e.second, (ll)this->v[e.first].size()});
                    this->v[e.first].push_back((Edge){i, 0, (ll)this->v[i].size() - 1});
                }
            }
            used = new bool[n];
        }

        ll max_flow(ll start, ll goal){
            ll ret = 0;
            while(1){
                memset(used, 0, n);
                ll add = dfs(start, goal, INF);
                if(add == 0){
                    return ret;
                }
                ret += add;
            }
        }
};
int main(){
    ll N;
    cin >> N;
    vector<P> X(N), Y(N);
    for(auto &x : X) cin >> x.first >> x.second;
    for(auto &y : Y) cin >> y.first >> y.second;
    vector<vector<P>> edges(2 * N + 2);
    for(ll i = 0; i < N; i++){
        edges[0].push_back(P(i + 1, 1));
        edges[N + i + 1].push_back(P(2 * N + 1, 1));
    }
    for(ll i = 0; i < N; i++){
        for(ll j = 0; j < N; j++){
            if(X[i].first < Y[j].first &&
               X[i].second < Y[j].second){
                edges[i + 1].push_back(P(N + j + 1, 1));
            }
        }
    }
    FordFulkerson F(edges);
    cout << F.max_flow(0, 2 * N + 1) << endl;
    return 0;
}


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

using namespace std;
using std::vector;

#define ll long long
#define vi vector<int>
#define vl vector<long long>
#define vvi vector<vi>
#define pi  pair<int,int>
#define mp  make_pair
#define pb  push_back
#define MOD int(1e9) + 7
#define PAI  3.1415926535
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define chmax(x, y) x = max(x,y)
#define chmin(x, y) x = min(x,y)
#define pr(x) cout << x << endl
#define Endl endl
#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};
const int ddx[8] = {-1,0,1,-1,1,-1,0,1};
const int ddy[8] = {-1,-1,-1,0,0,1,1,1};
const int inf = 99999999;
const ll linf = 1LL << 62;

ll gcd(ll a,ll b){
  if(a < b)swap(a , b);
  if(a % b != 0) gcd(b, a%b);
  return b;
}

ll lcm(ll a,ll b){
  if(a < b)swap(a , b);
  return (a / gcd(a , b)) * b;
}

int main(){

  string s; cin >> s;
  int ans = inf;

  for(int i = 0; i <= s.length() - 3; i++){
    int temp = (s[i] - '0') * 100 + (s[i + 1] - '0') * 10  + (s[i + 2] - '0');
    chmin(ans , abs(753 -  temp));
  } 

  pr(ans);

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <set>
#include <string>
using namespace std;
int main() {
  int n;
  string s;
  set<string> se1, se2, se3;
  cin >> n >> s;
  for (int i = 0; i < n; i++) {
    for (set<string>::iterator it = se2.begin(); it != se2.end(); it++) {
      se3.insert(*it + s.substr(i, 1));
    }
    for (set<string>::iterator it = se1.begin(); it != se1.end(); it++) {
      se2.insert(*it + s.substr(i, 1));
    }
    se1.insert(s.substr(i, 1));
  }
  cout << se3.size() << endl;
}

Measured memory_bytes: 3704
#include<iostream>

using namespace std;
#define MAX 21
char map[MAX][MAX];
enum Dir{UP,RIGHT,LEFT,DOWN};
int w,h;
class Tank{
public:
	int dir;
	int x;
	int y;
};
Tank tank;

int judgeDir(char c){
	if(c=='^')return UP;
	if(c=='v')return DOWN;
	if(c=='>')return RIGHT;
	if(c=='<')return LEFT;
}
char getCharDir(){
	if(tank.dir==UP)return '^';
	if(tank.dir==DOWN)return 'v';
	if(tank.dir==RIGHT)return '>';
	if(tank.dir==LEFT)return '<';
}

void init(){
	for(int i=0;i<21;i++){
		for(int j=0;j<21;j++)map[i][j]='N';
	}
}
void shoot(){
	int dy=0;
	int dx=0;
	if(tank.dir==UP)dy=-1;
	if(tank.dir==DOWN)dy=1;
	if(tank.dir==RIGHT)dx=1;
	if(tank.dir==LEFT)dx=-1;
	int x=tank.x;
	int y=tank.y;
	for(;;){
		if(x+dx<0||x+dx>w||y+dy<0||y+dy>h||map[y+dy][x+dx]=='#')break;
		x+=dx;
		y+=dy;
		if(map[y][x]=='*'){
			map[y][x]='.';
			break;
		}
	}
	return ;
}
void next(char command){
	map[tank.y][tank.x]='.';
	if(command=='U'){
		tank.dir=UP;
		if(tank.y-1>=0 && map[tank.y-1][tank.x]=='.'){
			tank.y=tank.y-1;
		}
	}
	else if(command=='D'){
		tank.dir=DOWN;
		if(tank.y+1<h && map[tank.y+1][tank.x]=='.'){
			tank.y=tank.y+1;
		}
	}
	else if(command=='L'){
		tank.dir=LEFT;
		if(tank.x-1>=0 && map[tank.y][tank.x-1]=='.'){
			tank.x=tank.x-1;
		}
	}
	else if(command=='R'){
		tank.dir=RIGHT;
		if(tank.x+1<w && map[tank.y][tank.x+1]=='.'){
			tank.x=tank.x+1;
		}
	}
	else if(command=='S'){
		shoot();
	}
	map[tank.y][tank.x]='@';
}

int main(){
	int d;
	cin>>d;
	for(int k=0;k<d;k++){
		if(k)cout<<endl;
		//cout<<"----------"<<endl;
		cin>>h>>w;
		for(int i=0;i<h;i++){
			for(int j=0;j<w;j++){
				cin>>map[i][j];
				if(map[i][j]=='^'||map[i][j]=='<'||map[i][j]=='>'||map[i][j]=='v'){
					tank.dir=judgeDir(map[i][j]);
					tank.x=j;
					tank.y=i;
					map[i][j]='.';
				}
			}
		}
		int commandNum;
		cin>>commandNum;
		for(char command;commandNum--;){
			cin>>command;
	//		cout<<"command:"<<command<<endl;
			next(command);
		}
		for(int i=0;i<h;i++){
			for(int j=0;j<w;j++){
				if(map[i][j]=='@')cout<<getCharDir();
				else cout<<map[i][j];
			}
			cout<<endl;
		}
	}
	return 0;
}

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

int main()
{
  string S;
  cin >> S;
  
  map<char, int> fifty;
  for(int i = 0; i < S.size(); i++)
  {
    if(fifty.count(S.at(i)) == 0)
      fifty.insert(make_pair(S.at(i), 1));
    else
      fifty[S.at(i)] += 1;
  }
  
  string ans = "Yes";
  for(auto i = fifty.begin(); i != fifty.end(); ++i)
  {
    if((i->second) != 2)
    {
      ans = "No";
      break;
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
import copy

H,W,K = list(map(int,input().split()))

c = [list(input()) for i in range(H)]

def count(c):
    res = 0
    for i in range(H):
        for j in range(W):
            if c[i][j]=="#":
                res+=1
    return res

ans = 0

for i in range(2**H):
    d = copy.deepcopy(c)
    for j in range(H):
        if 2**j & i > 0:
            for k in range(W):
                d[j][k] = "."
    for j in range(2**W):
        e = copy.deepcopy(d)
        for k in range(W):
            if 2**k & j > 0:
                for l in range(H):
                    e[l][k] = "."
        #print(c)
        if count(e)==K:
            ans += 1

print(ans)

Measured memory_bytes: 73224
#include <bits/stdc++.h>
     
    using namespace std;
     
    int main()
    {
        int n;
        cin >> n;
        bool count = 0;
        while (n)
        {
            int p = n % 10;
            if (p == 7)
                count = 1;
            n = n / 10;
        }
        if (count)
            cout << "Yes";
        else
        {
            cout << "No";
        }
     
        return 0;
    }

Measured memory_bytes: 3632
#pragma GCC optimize("Ofast")
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define flash ios_base::sync_with_stdio(false);     cin.tie(NULL);
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define all(v) v.begin(),v.end()
#define f first
#define s second



using namespace std;

int main()
{
  flash
  ll k;
  cin>>k;
  ll sum=0;

  for(int i=1;i<=k;i++){
    for(int j=1;j<=k;j++){
      for(int l=1;l<=k;l++){
        sum+=__gcd(__gcd(i,j),l);
      }
    }
  }

  cout<<sum<<"\n";


}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define int long long
#define endl "\n"
#define pii pair<int,int> 
#define ff first
#define ss second
#define mii map<int,int>
#define si set<int>
#define sti stack<int>
#define qi queue<int>
#define vi vector<int>
#define pq priority_queue<int>
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const int M=1e9+7;

void solve(){
	int n;
	cin>>n;
	string s;
	cin>>s;
	if(n>=s.size()){
		cout<<s<<endl;
	}
	else{
		string ans;
		for(int i=0;i<n;i++) ans.pb(s[i]);
		ans+="...";
		cout<<ans<<endl;
	}
}

int32_t main(){
	IOS;
	int t=1;
	//cin>>t;
	while(t--){
		solve();	
	}
}

Measured memory_bytes: 3644
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <numeric>
#include <cctype>
#include <tuple>

#ifdef _MSC_VER
#include <agents.h>
#endif

#define FOR(i, a, b) for(int i = (a); i < (int)(b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define REV(v) v.rbegin(), v.rend()
#define MEMSET(v, s) memset(v, s, sizeof(v))
#define X first
#define Y second

using namespace std;

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

inline double sq(double x){
	return x*x;
}

double x[100], y[100], z[100];

double dist(int i, int j){
	return sqrt(sq(x[i] - x[j]) + sq(y[i] - y[j]) + sq(z[i] - z[j]));
}

double EPS = 1e-4;
bool check(double a, double b, double c){
	if (abs(a - b) > EPS) return false;
	if (abs(b - c) > EPS) return false;
	if (abs(c - a) > EPS) return false;
	return true;
}

int main(){
	int T;
	cin >> T;
	while (T--){
		double a, b, c;
		cin >> a >> b >> c;
		int n;
		cin >> n;
		rep(i, n) cin >> x[i] >> y[i] >> z[i];

		rep(i, n) rep(j, n) rep(k, n){
			if (i == j && j == k) continue;
			if (check(dist(j, k) / a, dist(k, i) / b, dist(i, j) / c)){
				cout << i+1 << " " << j+1 << " " << k+1 << endl;
			}
		}
	}

	return 0;
}

Measured memory_bytes: 1236
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

ans = B[A[0] - 1]

for i in range(1, N):
    ans += B[A[i] - 1]
    if A[i] - A[i - 1] == 1:
        ans += C[A[i] - 2]

print(ans)


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

#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef complex<double> point;
#define xx real()
#define yy imag()

#define REP(i, a, b) for(int i = (a); i < (int)(b); i++)
#define REPN(i, a, b) for(int i = (a); i <= (int)(b); i++)
#define FA(it, x) for(__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define SZ(x) (int)(x).size()
#define BE(x) (x).begin(), (x).end()
#define SORT(x) sort(BE(x))
#define _1 first
#define _2 second

#define x1 gray_cat_x1
#define y1 gray_cat_y1

template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

#define file "I1"

const double EPS = 1e-9;
const double PI = acos(-1.);
const int INF = 1e9;
const ll MOD = 1e9 + 7;

const int MAXN = 4e3 + 5;

char a[MAXN], b[MAXN];
int nxt[MAXN];

int mx_right[MAXN];

void solve(){
	scanf("%s%s", &a[0], &b[0]);
	int n = strlen(a);
	int fla = 0, flb = 0;
	REP(i, 0, n) {
		a[i] -= '0';
		b[i] -= '0';
		if (a[i]) {
			fla = 1;
		}
		if (b[i]) {
			flb = 1;
		}
	}
	if (!flb) {
		printf("%d\n", -fla);
		return;
	}
	int ans = 2 * n;
	REP(k, 0, 2) {	
		REP(i, n, 2 * n) {
			a[i] = a[i - n];
			b[i] = b[i - n];
		}
		for(int i = 2 * n - 1; i >= 0; i--) {
			nxt[i] = nxt[i + 1];
			if (b[i]) {
				nxt[i] = i;
			}
		}
	
		REP(i, 0, n) {
			REP(j, 0, n) {
				mx_right[j] = 0;
			}
			
			int cur = i;
			
			int cnt = 0;
			REP(j, 0, i) {
				if (b[j]) {
					cnt++;
				}
			}
			
			int last = 0;
			REP(j, 0, n) {
				if (b[j]) {
					last = j;
				}
			}
			
			int max_left = 0;
			REP(j, 0, n) {
				if (b[j + i]) {
					cnt++;
				}
				if (a[j] != b[j + i]) {
					cur++;
					if (!cnt) {
						int cur_left = (j - last + n) % n;
						int cur_right = nxt[j + i] - (j + i);
						mx_right[cur_left] = max(mx_right[cur_left], cur_right);
						max_left = max(max_left, cur_left);
					}
				}
				if (b[j]) {
					last = j;
					cnt--;
				}
			}
			
			int cur_left_right_min = max_left;
			for(int j = max_left - 1; j >= 0; j--) {
				mx_right[j] = max(mx_right[j], mx_right[j + 1]);
				cur_left_right_min = min(cur_left_right_min, j + mx_right[j + 1]);
			}
			
			cur += 2 * cur_left_right_min;
			ans = min(ans, cur);
		}
		
		REP(i, 0, n / 2) {
			swap(a[i], a[n - 1 - i]);
			swap(b[i], b[n - 1 - i]);
		}
	}
	printf("%d\n", ans);
}   

int main(){

    //freopen(file".in", "r", stdin); freopen(file".out", "w", stdout);
    int t = 1;
    //cin >> t;
    while(t--){
        solve();    
    }
}


Measured memory_bytes: 256
import numpy as np

def iterate2(mapdata, passed, start):
    queue = [(start, 0)]

    while len(queue) > 0:
        curr, count = queue[0]
        del queue[0]
        if curr == (passed.shape[0] - 1, passed.shape[1] - 1):
            return count
        if mapdata[curr[0]][curr[1]] == '#':
            continue
        if passed[curr] > 0:
            continue
        passed[curr] = 1

        if curr[0] < passed.shape[0] - 1:
            queue.append(((curr[0] + 1, curr[1]), count + 1))
        if curr[1] < passed.shape[1] - 1:
            queue.append(((curr[0], curr[1] + 1), count + 1))
        if curr[0] > 0:
            queue.append(((curr[0] - 1, curr[1]), count + 1))
        if curr[1] > 0:
            queue.append(((curr[0], curr[1] - 1), count + 1))
    
    return -1

h, w = map(int, input().split())
mapdata = [input() for y in range(h)]
dotsum = sum(mapdata[y].count('.') for y in range(h))

passed = np.zeros((h, w), np.int8)
count = iterate2(mapdata, passed, (0, 0))
#print(dotsum)
#print(count)
if count > 0:
    print(dotsum - count - 1)
else:
    print(-1)

Measured memory_bytes: 12512
#include<bits/stdc++.h>
using namespace std ;
int main()
{
     int a , b , c , k ;
     cin >> a >> b >> c ;
     cin >> k ;
     int f = 0 , i = 0 ;
     while(a >= b)
     {
          if(k < 0)
          {
               f = 1 ;
               break ;
          }
          b *= 2 ;
          k-- ;
     }
     while(b >= c)
     {
          if(k < 0)
          {
               f = 1 ;
               break ;
          }
          c *= 2 ;
          k-- ;
     }
     if(k < 0)
     {
          f = 1 ;
     }
     // cout << k << endl ;
     if(f == 0)
     {
          cout << "Yes\n" ;
     }
     else
     {
          cout << "No\n" ;
     }
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std ;
#define int long long
#define ld long double
#define fast ios_base::sync_with_stdio(false) ;cin.tie(NULL);cout.tie(NULL)
#define F(i,a,b) for(int i= (int)(a); i<(int)(b);i++)
#define FI(i,a,b) for(int i=(int)(a);i<=(int)(b);i++)
#define RF(i,a,b) for(int i = (int)(a); i >= (int)(b); i--)
#define what_is(x) cerr << #x << " is " << x << endl;
#define ms(x,a) memset(x,(int)(a),sizeof(x))
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define pii pair<int,int>
#define vi vector<int >
#define pb push_back
#define endl '\n'
#define mp make_pair
#define ff first
#define ss second
#define MOD 1000000007
string s ;

int dp[101][4][4][4] ;
// dp[n][i][j][k] represents that with tot n num of char how many strings are possible  
// [i][j][k] are char  
int32_t main(){fast ;
	int N,k ;
	cin >> N ;
	int A = 0 , G = 1 , C = 2 , T = 3 ;
	 
	F(i,0,4){
		F(j,0,4){
			F(k,0,4){
				if((i== A && j == G && k == C) || (i == A && j == C && k == G) || (i == G && j == A && k == C))
					continue ;
				else dp[3][i][j][k] = 1 ;
			}
		}
	}
	
	FI(n,4,N){
		F(i,0,4){
			F(j,0,4){
				F(k,0,4){
					F(l,0,4){
						// AGC? ACG? GAC? 
						if((i== A && j == G && k == C) || (i == A && j == C && k == G) || (i == G && j == A && k == C))
							continue ;
						// ?AGC ?ACG ?GAC
						if((j== A && k == G && l == C) || (j == A && k == C && l == G) || (j == G && k == A && l == C))
							continue ;
						// AG?C A?GC
						if((i == A && j == G && l == C) || (i == A && k == G && l == C))
							continue ;						
						dp[n][j][k][l] += dp[n-1][i][j][k] ;
						if(dp[n][j][k][l] >= MOD)
							dp[n][j][k][l] -= MOD ;
					}
				}
			}
		}
	}
	int ans = 0 ;
	F(i,0,4){
		F(j,0,4){
			F(k,0,4){
				ans += dp[N][i][j][k] ;
				if(ans >= MOD) ans -= MOD ;
			}
		}
	}
	cout << ans << endl ;
}




Measured memory_bytes: 256
use std::io::BufRead;

fn main() {
    let stdin = std::io::stdin();
    let n = stdin.lock().gets().parse::<u64>().unwrap();
    let s = stdin.lock().gets().parse::<u64>().unwrap();

    if n < s {
        println!("-1");
        return;
    } else if n == s {
        println!("{}", n + 1);
        return;
    }
    let mut divisors = list_divisors(n - s);
    divisors.sort();
    for b in divisors.into_iter().map(|x| x + 1) {
        let mut n2 = n;
        let mut s2 = 0;
        while n2 > 0 {
            s2 += n2 % b;
            n2 /= b;
        }
        if s == s2 {
            println!("{}", b);
            return;
        }
    }
    println!("-1");
}

fn list_divisors(mut n: u64) -> Vec<u64> {
    let mut divisors = vec![1];
    let mut sqrt = ((n - 1) as f64).sqrt() as u64 + 1;
    let sieve_len = (sqrt - 1) as usize / 2;
    let mut sieve = vec![0u64; (sieve_len.saturating_sub(1)) / 64 + 1];
    let mut f = 2;
    let mut si = 0;
    while n > 1 {
        let (mut beg, len) = (0, divisors.len());
        while n % f == 0 {
            n /= f;
            sqrt = (n as f64).sqrt() as u64;
            for i in beg..beg + len {
                let t = divisors[i];
                divisors.push(t * f);
            }
            beg += len;
        }
        while si < sieve_len && (sieve[si / 64] & 1 << si % 64) != 0 {
            si += 1;
        }
        f = si as u64 * 2 + 3;
        if f > sqrt {
            f = n;
            continue;
        }
        let mut i = si;
        while i < sieve_len {
            sieve[i / 64] |= 1 << i % 64;
            i += f as usize;
        }
    }
    divisors
}

trait Gets { fn gets(&mut self) -> String; }
impl<T: std::io::BufRead> Gets for T {
    fn gets(&mut self) -> String { self.lines().next().unwrap().unwrap() } }


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

int main() {
    int n, q;
    cin >> n;
    map<ll, ll> m;
    ll sum = 0;
    rep(i, n) {
        int a;
        cin >> a;
        m[a]++;
        sum += a;
    }
    cin >> q;

    rep(i, q) {
        ll b, c;
        cin >> b >> c;
        sum += (c - b) * m[b];

        m[c] += m[b];
        m.erase(b);

        cout << sum << endl;
    }

    return 0;
}


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

#define F first
#define S second
#define MP make_pair
#define PB push_back

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair < int, int > pii;
typedef pair < ll, ll > pll;
typedef vector < ll > vl;

const int MAXN = 1e5 + 500;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const int LOG = 18;
const double EPS = 1e-9;
const double PI = 3.1415926535;

int dp[MAXN][3], hep[MAXN][3];

int main() {
    int N;
    memset(dp, INF, sizeof(dp));

    cin >> N;
    for(int i = 0; i < N; i++)
        cin >> hep[i][0] >> hep[i][1] >> hep[i][2];

    dp[0][0] = dp[0][1] = dp[0][2] = 0;
    for(int i = 1; i <= N; i++) {
        dp[i][0] = max(hep[i - 1][1] + dp[i - 1][1], hep[i - 1][2] + dp[i - 1][2]);
        dp[i][1] = max(hep[i - 1][0] + dp[i - 1][0], hep[i - 1][2] + dp[i - 1][2]);
        dp[i][2] = max(hep[i - 1][0] + dp[i - 1][0], hep[i - 1][1] + dp[i - 1][1]);
    }

    cout << max(max(dp[N][0], dp[N][1]), dp[N][2]) << endl;

    return 0;
}



Measured memory_bytes: 2560
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <deque>
#include <queue>
#include <string>
#include <string.h>
#include <math.h>
#include <iomanip>
#include <stdio.h>
using namespace std;

#define int64 long long
#define pii pair <int64, int64>
#define fr first
#define sc second
#define heap priority_queue
struct piii{
    int64 fr, sc, th;
    bool operator < (const piii &b){
        if (fr != b.fr) return fr < b.fr;
        if (sc != b.sc) return sc < b.sc;
        return th < b.th;
    }
};
///////////////////////////////////////////////
///////////////////////////////////////////////

bool dd[1000005];

int main(){
    cout << setprecision(2) << fixed;
    ios::sync_with_stdio(false), cin.tie(0);
    //freopen("input.txt", "r", stdin);
    int n;
    cin >> n;
    int i = 0, c = 0;
    while (1){
        c++;
        i = (i * 10 + 7) % n;
        if (i == 0){
            cout << c;
            exit (0);
        }
        if (dd[i]){
            cout << -1;
            exit (0);
        }
        dd[i] = true;
    }
    return 0;
}


Measured memory_bytes: 4560
#include<cstdio>
using namespace std;
int main()
{
	int n,s[1000],p[1000],q[1000],r[1000],a,b,c,d,i,x,cnt;
	int flg[1000];
	while(1){
		scanf("%d",&n);
		if(n==0){
			break;
		}
		for(i=1;i<=n;i++){
			scanf("%d %d %d %d",&s[i],&p[i],&q[i],&r[i]);
			flg[i]=0;
		}
		scanf("%d %d %d %d",&a,&b,&c,&d);
		for(i=1;i<=n;i++){
			x=0;
			x=p[i]*4+q[i]*9+r[i]*4;
			if(a<p[i])	flg[i]=1;
			if(b<q[i])	flg[i]=1;
			if(c<r[i])	flg[i]=1;
			if(x>d)	flg[i]=1;
			// printf("i=%d flg=%d x=%d\n",i,flg[i],x);
		}
		cnt=0;
		for(i=1;i<=n;i++){
			if(flg[i]==0){
				printf("%d\n",s[i]);
				cnt++;
			}
		}
		if(cnt==0){
			printf("NA\n");
		}
	}
	return 0;
}


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

int main() {
  int b1, b2, b3; cin >> b1 >> b2 >> b3;
  if ((b1 == 1 && b2 == 1 && b3 == 0) || (b1 == 0 && b2 == 0 && b3 == 1)) cout << "Open" << endl;
  else cout << "Close" << endl;
  return 0;
}


Measured memory_bytes: 3104
#include <cmath>

#include <algorithm>
#include <iostream>
#include <iterator>
#include <numeric>
#include <map>
#include <set>
#include <vector>

using namespace std;

int main() {
#ifdef _DEBUG
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  ios_base::sync_with_stdio(false);
  cin.tie(0);

  cout.precision(16);
  cout << fixed;

  int a;
  cin >> a;

  cout << 3 * a * a;
}


Measured memory_bytes: 256
from itertools import combinations
sq = [i**2 for i in range(500)]
ans = 0
n,d = map(int,input().split())
a = [list(map(int,input().split())) for i in range(n)]
for (i,j) in combinations(a,2):
  dist2 = 0
  for x in range(d):
    dist2 += (i[x]-j[x])**2
  if dist2 in sq:
    ans += 1
print(ans)

Measured memory_bytes: 3064
#include"bits/stdc++.h"
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using pii = pair<int, int>;

void Main(){
	int n;
	cin >> n;
	vi a(n);
	rep(i, n) cin >> a[i];
	vi ans(n, 0);

    int i = n-1;
    int j = 2;
    while(n/j > 0){
        // if(i==1) cout << "j = " << j << ", n/j = " << n/j << endl;
        while(i+1 > n/j){
            int temp = 0;
            int k = 2;
            while((i+1)*k-1 < n){
                temp += ans[(i+1)*k-1];
                k++;
            }
            // if(i==1) cout << "temp = " << temp << ", k = " << k << endl;
            ans[i] = (a[i] + temp) %2;
            i--;
        }
        if(n/j == 1) break;
        j++;
    }

    int sum = 0;    
    rep3(i,1,n-1) sum += ans[i];
    ans[0] = (sum + a[0]) % 2;
    sum += ans[0];
    
    cout << sum << endl;
    rep(i,n) if(ans[i]) cout << i+1 << endl;
	return;
}

int main(){
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
	return 0;
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
#define gc getchar_unlocked
#define fo(i,n) for(int i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ll long long
#define si(x)	scanf("%d",&x)
#define sl(x)	scanf("%lld",&x)
#define ss(s)	scanf("%s",s)
#define pi(x)	printf("%d\n",x)
#define pl(x)	printf("%lld\n",x)
#define ps(s)	printf("%s\n",s)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define wi(t) int t;cin>>t;while(t--)
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pl;
typedef vector<int>		vi;
typedef vector<ll>		vl;
typedef vector<pii>		vpii;
typedef vector<pl>		vpl;
typedef vector<vi>		vvi;
typedef vector<vl>		vvl;
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
int rng(int lim) {
	uniform_int_distribution<int> uid(0,lim-1);
	return uid(rang);
}
int mpow(int base, int exp); 
void ipgraph(int n, int m);
void dfs(int u, int par);

const int mod = 1000000007;
const int N = 3e5, M = N;
//=======================

vi g[N];
int a[N];
bool isequal(int ar[],int ok[],int n)
{
  for(int i=0;i<n;i++)
  {
    if(ar[i]!=ok[i])
    return false;
  }
  return true;
}
void solve()
    {  
    int n;
    cin>>n;
    int ar[n];
    fo(i,n) cin>>ar[i];
    int br[n];
    fo(i,n) cin>>br[i];
    int ok[n];
    int j=1;
    fo(i,n) ok[i]=j++;
    int a=0,b=0;
    while(1)
    {  //cout<<endl;
       if(isequal(ar,ok,n))
       break;
       else
       {
         a++;
       }
       next_permutation(ok,ok+n);
      
    }
   // deb2(a,b);
    j=1;
    fo(i,n) ok[i]=j++;
    while(1)
    {
       if(isequal(br,ok,n))
       break;
       else
       {
         b++;
       }
       next_permutation(ok,ok+n);
    }
   // deb2(a,b);
    cout<<abs(a-b)<<endl;

  
  
    }

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    srand(chrono::high_resolution_clock::now().time_since_epoch().count());

   // wi(t)
    {
      solve();
    }

    return 0;
}

int mpow(int base, int exp) {
  base %= mod;
  int result = 1;
  while (exp > 0) {
    if (exp & 1) result = ((ll)result * base) % mod;
    base = ((ll)base * base) % mod;
    exp >>= 1;
  }
  return result;
}

void ipgraph(int n, int m){
	int i, u, v;
	while(m--){
		cin>>u>>v;
    u--, v--;
		g[u].pb(v);
		g[v].pb(u);
	}
}

void dfs(int u, int par){
	for(int v:g[u]){
		if (v == par) continue;
		dfs(v, u);
	}
}







Measured memory_bytes: 10680
n, m = map(int, input().split())
t = sorted([tuple(map(int, input().split())) for _ in range(n)])

ans = 0
for i in range(n):
    if m > t[i][1]:
        ans += t[i][0]*t[i][1]
        m -= t[i][1]
    else:
        ans += t[i][0]*m
        break

print(ans)



Measured memory_bytes: 17752