akhauriyash/Code-Regression huggingface dataset:
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
fn main() {
    input!{
        n: usize,
        d: [i32; n],
    }
    let mut ans = 0;
    for i in 0..n {
        for j in i+1..n {
            if i == j { continue; }
            ans += d[i] * d[j];
        }
    }
    println!("{}", ans);
}


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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

#define ld long double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#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 mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

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

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin>>n;
    string s; cin>>s;
    int ans=0;
    rep(i,n-2){
        if (s.substr(i,3)=="ABC") ans++;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
#define pb push_back
#define ub upper_bound
#define lb upper_bound
#define mp make_pair
#define F first
#define S second
#define FOR(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define ve vector
#define vi vector<int>
#define vp vector<pair<int,int>>
#define vvi vector<vector<int>>
 
using ll = long long;
const ll INF = LLONG_MAX - 100;
ll mod = 1e9 + 7;
int dx[] = {-1,0,1,0}, dy[] = {0,1,0,-1};
vector<ll> prime;

class fact {
public:
	int fmod = 1e9+7;
	vector<int> fac, inv;
	fact (int n, int Mod = 1e9+7) {
		fmod = Mod;
		fac = vector<int>(n,0);
		inv = vector<int>(n,0);
		fac[0] = 1; for (int i = 1; i < n; i++) fac[i] = fac[i-1] * i % fmod;
		for (int i = 0;i < n;i++) inv[i] = fact::POW(fac[i],fmod-2);
	}
	ll nCr(ll n, ll r) {return (fac[n] * inv[r] % fmod) * inv[n-r] % fmod;}
	ll POW(ll a, ll b) {ll c = 1; while (b > 0) {if (b & 1) {c = a * c%fmod;}a = a * a%fmod; b >>= 1;}return c;}
};
 
template <class T = ll> T in() {T x; cin >> x; return (x);}
void DEBUG(vector<int> a) {for(int i=0;i<a.size();i++)cout<<a[i]<<" ";cout<<endl;}
void EMP(int x) {cout<<"!!!"<<x<<"!!!"<<endl;}
ll GCD(ll a, ll b) {ll c; while (b != 0) {c = a % b; a = b; b = c;}return a;}
ll LCM(ll a, ll b) {return a * b / GCD(a, b);}
ll POW(ll a, ll b) {ll c = 1; while (b > 0) {if (b & 1) {c = a * c%mod;}a = a * a%mod; b >>= 1;}return c;}
void PRI(ll n) {bool a[n + 1LL]; for (int i = 0; i < n + 1LL; i++) {a[i] = 1LL;}for (int i = 2; i < n + 1LL; i++) {if (a[i]) {prime.pb(i); ll b = i; while (b <= n) {a[b] = 0; b += i;}}}}
template <typename T> T chmin(T& a, T b) {if(a>b)a=b;return a;}
template <typename T> T chmax(T& a, T b) {if(a<b)a=b;return b;}
bool isSqrt(ll a) {return pow(sqrt(a),2) == a ? 1 : 0;}
void YesNo(bool a) {if (a) cout << "Yes"; else cout << "No"; cout << endl;}
void yesno(bool a) {if (a) cout << "yes"; else cout << "no"; cout << endl;}
void YESNO(bool a) {if (a) cout << "YES"; else cout << "NO"; cout << endl;}

bool solve() {
    int n,k; cin >> n >> k;
    map<int,set<int>> pos;
    int per = 1;
    int a[n]; REP (i,n) {
        cin >> a[i];
        pos[a[i]].insert(i), pos[a[i]].insert(i+n);
    }
    int s = INF;
    while (1) {
        if (s == n - 1) break;
        if (s == INF) s = -1;
        int next = *pos[a[s+1]].upper_bound(s+1);
        if (next >= n) {per++;next -= n;}
        s = next;
    }
    k %= per;
    k *= n;
    vector<int> ans;
    s = 0;
    while (1) {
        if (k == 0) break;
        int next = *pos[a[s]].upper_bound(s);
        if (next-s+1 > k) {
            ans.pb(a[s]); s++; k--;
        } else {
            k -= (next-s+1);
            s = (next+1)%n;
        }
    }
    for (auto&& A : ans) {
        cout << A << " ";
    } cout << endl;
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	solve();
}


Measured memory_bytes: 42224
#include<bits/stdc++.h>
#include<iomanip>
#include<numeric>

using namespace std;
using ll = long long;
constexpr ll mod = 1e9+7;
constexpr ll md = mod;
constexpr ll inf = 1e15;

int main(){
    map<char,int> m;
    string s;
    cin>>s;
    for(int i=0;i<(int)s.size();++i){
        m[s[i]]++;
    }
    bool ok = true;
    for(auto a : m){
        if(a.second != 2){
            ok = false;
        }
    }
    if(ok) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize ("Ofast")
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
using namespace __gnu_pbds;
using namespace std;
 
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<long long,long long> ii; 	
typedef complex<long double> com;

const ll mod = 1e9+7;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
    ld pi = 3.141592653589793238462643383279502884;
	ld r;
    cin >> r;
    cout << fixed << setprecision(60) << ld(2)*pi*r << endl;
}


Measured memory_bytes: 3808
#include<bits/stdc++.h>
#include<ctype.h>
# define pb push_back
#define fst first
#define sec second
#define For(i,a,b) for(int i=a;i<b;i++)
#define ll long long int
#define ull unsigned long long int
#define mod 1000000007
#define fo(i,n) for(ll i=0;i<n;i++)
#define endl "\n"
#define rev(i,n) for(ll i=n-1;i>=0;i--)
#define fo1(i,n) for(ll i=1;i<=n;i++)
#define boolsize 1000001
#define pi pair<ll,ll>
#define vi vector<ll>
#define vii vector<pi>
using namespace std;
template<typename T>
void showvector(vector <T> v)
{
    for(T x:v)
        cout<<x<<" ";
    cout<<endl;

}
template<typename T>
void showvector1(vector <T> v)
{
    ll n=v.size();
    fo1(i,n-1)
        cout<<v[i]<<endl;

}
template<typename T>
void showset(set <T> s)
{
    for(T x: s)
        cout<<x<<" ";
    cout<<endl;
}
template<class T>
void showvectorpair(vector<T> v)
{
    for(auto it=v.begin();it!=v.end();it++)
        cout<<it->first<<" "<<it->second<<endl;
    cout<<endl;
}
template<typename T,typename P>
void showmap(map <T,P> m)
{
    for(auto it=m.begin();it!=m.end();it++)
        cout<<it->first<<" "<<it->second<<endl;
    cout<<endl;
}
template<typename T>
bool comp(T a,T b)
{
    return (a>b);
}
template<class T>
bool comppair(T a,T b)
{
    if(a.first==b.first)
        return(a.second>b.second);
    return (a.first>b.first);
}
bool sameparity(ll a,ll b)
{
    return (a%2==b%2);
}
bool difparity(ll a,ll b)
{
    return !(a%2==b%2);
}
bool isprime(ll x)
{   if(x<=1)
     return false;
    for(ll i=2;i<=sqrt(x);i++)
    {
        if(x%i==0)
            return false;
    }
    return true;
}
bool iseven(ll x)
{
    return !(x%2);
}
bool isodd(ll x)
{
    return (x%2);
}
/// check for test case before submitting
void vfun()
{
    ll n,k;
    cin>>n;
    vector <ll> v(n);
    fo(i,n)
    cin>>v[i];

}

int main()
{
    #ifndef ONLINE_JUDGE
    freopen("inputh.txt", "r", stdin);
    freopen("outputh.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(0); ///cant use scanf, printf
    cin.tie(0);cout.tie(0); /// no longer auto flush cout before each cin, remove for interactive
    //cout << fixed << setprecision(11); /// no scientific output
    ll test=1;
    //cin>>test;
    while(test--)
    {
            ll n,k;
            cin>>n>>k;
            map <ll,ll> m;
            fo(i,n)
            {
                ll x,y;
                cin>>x>>y;
                m[x]+=y;
            }
            ll sum=0;
            for(auto it=m.begin();it!=m.end();it++)
            {
                sum+=it->sec;
                if(sum>=k)
                {cout<<it->first;break;}
            }

//         if(vfun())
//            cout<<"YES\n";
//         else
//            cout<<"NO\n";
    }
}
///before sub
/// check for value of zero and single input in array
///loop vars,1LL in mult, equal, one, bounds, int v ll, endl, finish taking inputs
/// check whether test cases are given or not






Measured memory_bytes: 7564
#include <iostream>
#include <string>
#include <map>

using namespace std;
using ll = long long;
using ld = long double;

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

    map<int, int> m;

    for (int i = 0; i < N; ++i) {
        int x = a[i];

        if(m.count(x) ==0){
            m[x] = 1;
        }
        else{
            m[x] += 1;
        }

        x++;
        if(m.count(x) ==0){
            m[x] = 1;
        }
        else{
            m[x] += 1;
        }
        x-=2;

        if(m.count(x) ==0){
            m[x] = 1;
        }
        else{
            m[x] += 1;
        }

    }


    int r =0;

    for (auto itr =m.begin(); itr != m.end(); ++itr) {
        if(r<itr->second){
            r = itr->second;
        }
    }

    cout << r << endl;


    return 0;
}

Measured memory_bytes: 5120
from math import ceil, log

N, K = map(int, input().split())

ans = 0
for i in range(1, N+1):
    val = i
    # val * 2^n > K
    # 2^n > K / val
    # n > log(K/val) / log2
    count = ceil(log(K/val) / log(2))
    count = 0 if count < 0 else count
    ans += 1 / (pow(2, count) * N)

print(ans)


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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

int main()
{
    ll n;
    int a[100001];
    cin >> n;
    ll len = 0;
    a[0] = 0;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        len += abs(a[i-1] - a[i]);
    }
    len += abs(a[n] - a[0]);
    for (int i = 1; i <= n; i++) {
        cout << len - abs(a[i] - a[i-1]) - abs(a[i+1] - a[i]) + abs(a[i+1] - a[i-1]) << endl;
    }

    return 0;
}

Measured memory_bytes: 1664
#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#include <string>
#include <limits>
#include <algorithm>
#include <map>
#include <sstream>
#include <unordered_map>
#include <set>

using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
static ull tenq = 1000000000;
static ull mod = tenq + 7;

using namespace std;

int main()
{
  ll N;
  cin >> N;

  cout << 180 * (N-2) << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef  long long ll ;
const int maxn=1e2+3,maxxn=1e4+2;
vector<pair<int,int> >v[maxn][maxn];
bool mark[maxn][maxn];
int ans[maxn][maxn];
pair<int,int>p[maxxn];
int c;
void dfs(int u,int k){
    mark[u][k]=1;
    if(p[c].first<=0)c++;
    ans[u][k]=p[c].second;
    p[c].first--;
    for(int i=0;i<v[u][k].size();i++){
        int x1=v[u][k][i].first,y1=v[u][k][i].second;
        if(!mark[x1][y1])dfs(x1,y1);
    }
}
int main() {
    int h,w,n;
    cin>>h>>w>>n;
    for(int i=0;i<n;i++){
        int x;
        cin>>x;
        p[i]=make_pair(x,i+1);
    }
    for(int i=1;i<=h;i++){
        for(int j=1;j<=w;j++){
            if(j+1<=w)v[i][j].push_back(make_pair(i,j+1));
            if(j-1>0)v[i][j].push_back(make_pair(i,j-1));
            if(i+1<=h)v[i][j].push_back(make_pair(i+1,j));
            if(i-1>0)v[i][j].push_back(make_pair(i-1,j));
        }
    }
    dfs(1,1);
    for(int i=1;i<=h;i++){
        for(int j=1;j<=w;j++)cout<<ans[i][j]<<" ";
        cout<<endl;
    }
    return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;i++)

typedef int long long ll;
using namespace std;
typedef pair<int,int> P;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const ll MOD=1e9+7;
static const int MAX = 100;
static const int INF = (1<<23);
template<class T> T gcd(T a, T b){return b? gcd(b,a%b) : a;}
template<class T> T lcm(T a,T b){return a / gcd(a,b)*b;}

int main(){
    cout<<setprecision(16);
    double r;
    cin>>r;
    cout<<2*r*M_PI<<endl;






return 0;
}


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

using namespace std;

int main() {
	string s;
	cin >> s;
	int res = 0;
	for (int i = 0; i < 3; i++) {
		if (s[i] == 'o') {
			res += 100;
		}
	}
	cout << 700 + res << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,j,k) for(int i=(j);i<(k);i++)
#define mp make_pair
#define sz(a) (int)(a).size()
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<double,double> pdd;
typedef long double ld;
//----head----
int data[100005];
vector<int> ans;
int main()
{
	int n;
	scanf("%d",&n);
	rep(i,0,n)scanf("%d",&data[i]);
	sort(data,data+n);
	rep(i,1,n)if(data[i]==data[i-1])
	{
		ans.pb(data[i]);
		i++;
	}
	if(sz(ans)<2)puts("0");
	else
	{
		int n=sz(ans);
		printf("%lld\n",1LL*ans[n-1]*ans[n-2]);
	}
	return 0;
}


Measured memory_bytes: 1024
long s=1,m=1e9+7,D[41][1<<17]={1};
X,i,j,k,T,M=1<<17;
main(n){
	scanf("%d%d%d%d",&n,&j,&k,&T);
	for(X=((1<<j|1)<<k|1)<<T-1;i++<n;s=s*10%m)
		for(j=k=0;k<M?:(k=0,j++<9);k++)
			if(T=k+k+1<<j,~T&X)
				D[i][T&=M-1]+=D[i-1][k],D[i][T]%=m;
	for(;M--;)s=(s-D[n][M]+m)%m;
	printf("%d",s);
}

Measured memory_bytes: 41088
#include <iostream>
#include <algorithm>
#define int long long
using namespace std;

int mod = 1000000007;
int n, a, b;
int dp1[5001][2];	//dp1[len][nowChar] : 1個以上の1, A個以上の0を交互に配置(1スタート)
int dp2[5001][2];	//dp2[len][nowChar] : nowChar = 0 : A個未満0, 1 : __(dp1を利用)

signed main() {
	int i, j, k;
	
	cin >> n >> a >> b;
	if (a > b) swap(a, b);
	
	dp1[0][1] = 1;
	for (i = 0; i < b; i++) {
		//dp1[i][0] -> dp1[i + a以上][1]
		for (j = i + a; j < b; j++) {
			dp1[j][1] += dp1[i][0];
			dp1[j][1] %= mod;
		}
		//dp1[i][1] -> dp1[i + 1以上][0]
		for (j = i + 1; j < b; j++) {
			dp1[j][0] += dp1[i][1];
			dp1[j][0] %= mod;
		}
	}
	
	dp2[0][0] = 1;
	dp2[0][1] = 1;
	for (i = 0; i < n; i++) {
		//dp2[i][0] -> dp2[i + a未満][1]
		for (j = i + 1; j < i + a && j <= n; j++) {
			dp2[j][1] += dp2[i][0];
			dp2[j][1] %= mod;
		}
		//dp2[i][1] -> dp2[i + b未満][0]
		for (j = i + 1; j < i + b && j <= n; j++) {
			dp2[j][0] += dp2[i][1] * dp1[j - i][0] % mod;
			dp2[j][0] %= mod;
			if (i == 0 || j == n) {
				dp2[j][0] += dp2[i][1] * dp1[j - i][1] % mod;
				dp2[j][0] %= mod;
			}
		}
	}
	
	//余事象の個数はdp2[n][0] + dp2[n][1];
	int ng = (dp2[n][0] + dp2[n][1]) % mod;

	//全体2^N個から引けば答え
	int p2 = 1;
	for (i = 0; i < n; i++) { p2 *= 2; p2 %= mod; }
	
	cout << (p2 + mod - ng) % mod << endl;
	return 0;
}

Measured memory_bytes: 3672
#include <iostream>
     
    using namespace std;
    typedef long long ll;
     
    ll l, r;
     
    void solve() {
      if (r - l >= 2019) {
        cout << 0 << endl;
        return;
      }
      int ans = 2019;
      r = r % 2019;
      l = l % 2019;
      if (r < l) {
        r += 2019;
      }
      for (int i=l;i<=r;i++) {
        for (int j=i+1;j<=r;j++) {
          ans = min(ans, (i * j) % 2019);
        }
      }
      cout << ans << endl;
    }
     
    int main() {
      cin >> l >> r;
      solve();
    }

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

using namespace std;

typedef pair<string, int> P;
typedef pair<P, int> Q;

int main() {
    int n;
    cin >> n;
    string s;
    int pp;
    vector<Q> ans;
    for (int i = 0; i < n; i++) {
        cin >> s >> pp;
        ans.push_back(Q(P(s, -pp),i+1));
    }
    sort(ans.begin(), ans.end());
    for (int i = 0; i < n; i++) {
        cout << ans[i].second << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 998244353;
const ll INF = mod * mod;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef pair<ll, ll> LP;
typedef vector<int> vec;
typedef vector<string> svec;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-8;

void solve() {
	int n, a, b; cin >> n >> a >> b;
	cout << min(b, a*n) << endl;
}

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

	//cout << fixed << setprecision(10);
	//init();
	solve();
	//stop
		return 0;
}

Measured memory_bytes: 256
process.stdin.resume();
process.stdin.setEncoding('utf8');
// Your code here!
function main(input) {
    var x = input.split('/');
    x[0] = '2018';
    console.log(x[0] + '/' + x[1] + '/' + x[2]);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 7500
using System;
using System.Linq;
using System.Collections.Generic;

namespace AizuOnLine
{
    class Program
    {
        
        static void Main(string[] args)
        {
            int n = Convert.ToInt32(Console.ReadLine());

            RoomMgr mgr = new RoomMgr();
            for (int i = 0; i < n; i++)
            {
                string[] data = Console.ReadLine().Split(' ');

                mgr.add(int.Parse(data[0]), int.Parse(data[1]), int.Parse(data[2]), int.Parse(data[3]));
            }

            mgr.output();
        }

        static void init()
        {

        }
    }

    class RoomMgr
    {
        int[,,] room = new int[4, 3, 10];
        
        public void add(int b, int f, int r, int v)
        {
            room[b-1, f-1, r-1] += v;
        }

        public void output()
        {
            for (int b = 0; b < room.GetLength(0); b++)
            {
                for (int f = 0; f < room.GetLength(1); f++)
                {
                    for (int r = 0; r < room.GetLength(2); r++)
                    {
                        Console.Write(" " + room[b, f, r]);
                    }
                    Console.WriteLine("");
                }

                if (b != room.GetLength(0) - 1)
                {
                    Console.WriteLine("####################");
                }
            }
        }
    }
}

Measured memory_bytes: 9224
import java.util.*;

public class Main { 
    
    public static void main(String[] args) {		        
        Scanner sc = new Scanner(System.in);                               
                               
        int N = sc.nextInt();
        int M = sc.nextInt();
        
        int a;
        int b;
        
        HashSet<Integer> hashFirstTo = new HashSet<Integer>();
        HashSet<Integer> hashSecondFrom = new HashSet<Integer>();
       
        boolean possible = false;
        
        for(int i = 0;i < M;i++){
            a = sc.nextInt();
            b = sc.nextInt();            
            if(a == 1){
                hashFirstTo.add(b);
            }
            if(b == N){
                hashSecondFrom.add(a);
            }                        
        }
        
        for(int first:hashFirstTo){
            if(hashSecondFrom.contains(first)){
                possible = true;
                break;
            }
        }
        
        if(possible == true){
            System.out.println("POSSIBLE");
        }else{
            System.out.println("IMPOSSIBLE");            
        }
              
    }                         
}

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


#define loop(i,n) for(int lc=i;lc<=n;lc++)
#define tloop(tn) for(int tlc=1;tlc<=tn;tlc++)
#define loop2(i2,n2) for(int lc2=i2;lc2<=n2;lc2++)
#define bloop(n,bn) for(int blc=n;blc>=bn;blc--)
#define il() while(true)
#define pi acos(-1)
#define rad_to_deg(angl) ((180*angl)/pi)
#define ll long long
#define caseno printf("Case %d: ",tlc);

#define sfi(def_var) scanf("%d",&def_var)
#define sfii(def_var,def_var2) scanf("%d %d",&def_var,&def_var2)
#define sfll(def_var,def_var2) scanf("%lld %lld",&def_var,&def_var2)

#define sfl(def_var) scanf("%lld",&def_var)
#define sfd(def_var) scanf("%lf",&def_var)
#define sfs(def_var) scanf("%s",&def_var)

#define pfie(def_var) printf("%d\n",def_var)
#define pfi(def_var) printf("%d",def_var)
#define pfl(def_var) printf("%lld",def_var)
#define pfd(def_var) printf("%lf",def_var)
#define nl printf("\n");

int n,k;
int h[100010];

int dp[100010];
int find_ans(int i)
{
    //cout << "call : " << i << endl;
    if(i==n)
    {
        //cout << "return " << 0 << endl;
        return 0;
    }
    if(dp[i]>=0)
    {
        //cout << "return " << dp[i] << endl;
        return dp[i];
    }
    int x=INT_MAX;
    for(int j=1;j<=k && i+j<=n;j++)
    {
        x=min(x, abs( h[i]-h[i+j] ) + find_ans(i+j) );
        //cout << "in call : "<< i<< " return from  call : " << i+j<< ". x : " << x << endl;
    }

    dp[i]=x;
    //cout << "return " << dp[i] << endl;
    return dp[i];

}
int main()
{

    sfii(n,k);

    loop(1,n)
    {
        dp[lc]=-1;
        sfi(h[lc]);
    }
    pfie(find_ans(1));
     //main();

}


Measured memory_bytes: 5760
import java.util.*;

public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner sc = new Scanner(System.in);
        for (int i = 1; i <= 5; i++) {
            int v = sc.nextInt();
            if (v == 0) {
                System.out.println(i);
                return;
            }
        }
    }
}

Measured memory_bytes: 35756
#include <bits/stdc++.h>
#if ONLINE_JUDGE
    #define DEBUG false
#else
    #define DEBUG true
#endif
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
#define REP(i, k, n) for (int i = (int)(k); i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define rep1(i, n) REP(i, 1, n)
#define rREP(i, k, n) for (int i = (int)(n)-1; i >= k; i--)
#define rrep(i, n) rREP(i, 0, n)
#define forlist(i, vec) for(auto &&i : vec)
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort(all(x))
#define REV(x) reverse(all(x))
#define MAX(x) *max_element(all(x))
#define MIN(x) *min_element(all(x))
#define LOWitr(x, n) lower_bound(all(x), n)
#define UPRitr(x, n) upper_bound(all(x), n)
#define cii(x) int x;cin >> x
#define cill(x) LL x;cin >> x
#define cis(x) string x;cin >> x
#define co(x) cout << x << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define truecheck assert
#define dump(x) cerr << #x << ": " << (x) << endl
using namespace std;
typedef long long LL;
typedef long long int64;
typedef std::vector<int> VI;
typedef std::vector<VI> VVI;
typedef std::vector<LL> VL;
typedef std::vector<VL> VVL;
typedef std::vector<std::string> VS;
typedef std::pair<int, int> PII;
typedef std::pair<LL, LL> PLL;
typedef std::queue<int> QI;
typedef std::priority_queue<int> PQI;
template<class T,class U>inline bool chmax(T &a, const U &b){if (a<b){a=b;return true;}return false;}
template<class T,class U>inline bool chmin(T &a, const U &b){if (b<a){a=b;return true;}return false;}
template<class T,class U>inline void vcinpb(T &v, U n){rep(i, n){typename T::value_type a;cin >> a;v.pb(a);}}
template<class T>inline void dumpv(T &v){
    if(!DEBUG){return;}cout<<"{";rep(i,v.size()){cout<<v[i]<<",";}cout<<"}"<<endl;
}

const int INF = 1e9, MOD = 1e9 + 7;
const LL LLINF = 1e16;
// M_PI 3.1415...

int main() {
    fastcin();
    cout << fixed << setprecision(10);
    cill(n);
    VL v(n+10), ph(201000), mh(201000), idxes;
    LL ans = 0;
    rep(i, n){
        cin >> v[i];
    }
    rep(i, n){
        if(i+1 + v[i] < 200900){
            ph[ i+1 + v[i] ]++;
            if (ph[ i+1 + v[i] ] == 1){
                idxes.pb(i+1 + v[i]);
            }
        }
        if(i+1 - v[i] > 0){
            mh[ i+1 - v[i] ]++;
            if (mh[ i+1 - v[i] ] == 1){
                idxes.pb(i+1 - v[i]);
            }
        }

    }
    SORT(idxes);
    idxes.erase(unique(all(idxes)), idxes.end());
    for(auto&& i : idxes){
        ans += ph[i] * mh[i];
    }
    co(ans);
    return 0;
}

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

int main()
{
    int n, c[500]{}, s[500]{}, f[500]{};
    scanf("%d", &n);
    for (int i = 0; i < n - 1; i++)
        scanf("%d%d%d", c + i, s + i, f + i);
    for (int i = 0; i < n - 1; i++)
    {
        for (int j = 0; j < i; j++)
        {
            if (s[j] <= s[i])
                s[j] = s[i] + c[i];
            else
                s[j] = (s[j] + f[i] - 1) / f[i] * f[i] + c[i];
        }
        s[i] += c[i];
    }
    for (int i = 0; i < n; i++)
    {
        printf("%d\n", s[i]);
    }

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<map>
#include<queue>
#include<cmath>
#include<stack>
#include<vector>
#include<cstdio>
#define MAXN 2555
#define INF 0x3f3f3f3f
#define v first
#define b second
using namespace std;
int p[100005];
bool vis[100005];
long long sum;
int Find(int x)
{
   if(p[x]==x)
      return x;
   else return p[x]=Find(p[x]);
}
void Find2(int x)
{
   if(vis[x])
   {
      sum+=x;
      return ;
   }
   if(p[x]==x)
      return ;
   else Find2(p[x]);
}
void init(int n)
{
   memset(vis,false,sizeof(vis));
   for(int i=1;i<=n;i++)
      p[i]=i;
}
int main()
{
   #ifdef XT
   freopen("2170-input.txt","r",stdin);
   #endif // XT
   int n,m;
   while(scanf("%d%d",&n,&m)==2)
   {
      if(n==m&&n==0)
         break;
      init(n);
      vis[1]=true;
      for(int i=2;i<=n;i++)
      {
         int a;
         scanf("%d",&a);
         int x=Find(i);
         p[x]=a;
      }
      sum=0;
      for(int i=0;i<m;i++)
      {
         char a[5];int b;
         scanf("%s %d",a,&b);
         if(a[0]=='M') vis[b]=true;
         if(a[0]=='Q')
         Find2(b);
      }
      cout<<sum<<endl;
   }
   return 0;
}

Measured memory_bytes: 3600
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

A, B, C, D = mapint()
from math import gcd

m = C*D//gcd(C, D)
Ccnt = B//C-(A-1)//C
Dcnt = B//D -(A-1)//D
Mcnt = B//m - (A-1)//m

print((B-A)-(Ccnt+Dcnt-Mcnt)+1)

Measured memory_bytes: 62144
#include<cstdio>
#include<utility>

using namespace std;

typedef pair<long long,long long> P;

P get(long long N,long long K){
	long long n=N/2;
	long long k=N/2-1;
	if(K>k) return P(-1,-1);
	if(K<=n/2) return P(K*2,N-K*2);
	else return P(2*k+3-K*2,N-(2*k+3-K*2));
}

const long long mod=1000000007;

struct Mat{
	long long a[2][2];
};

Mat mul(Mat m1,Mat m2){
	Mat res;
	for(int i=0;i<2;i++) for(int j=0;j<2;j++) res.a[i][j]=0;
	for(int i=0;i<2;i++) for(int j=0;j<2;j++){
		for(int k=0;k<2;k++){
			res.a[i][j]=(res.a[i][j]+m1.a[i][k]*m2.a[k][j])%mod;
		}
	}
	return res;
}

Mat ex(Mat a,long long e){
	if(e==0){
		Mat res;
		for(int i=0;i<2;i++) for(int j=0;j<2;j++) res.a[i][j]=0;
		for(int i=0;i<2;i++) res.a[i][i]=1;
		return res;
	}
	Mat tmp=ex(a,e/2);
	Mat res=mul(tmp,tmp);
	if(e%2==1){
		res=mul(res,a);
	}
	return res;
}

long long getF(long long a){
	Mat s;
	s.a[0][0]=1;
	s.a[0][1]=1;
	s.a[1][0]=1;
	s.a[1][1]=0;
	Mat x=ex(s,a);
//	printf("%lld %lld\n",a,x.a[1][0]);
	return x.a[1][0];
}

P get(long long K){
	long long lb=0,ub=1000000000;
	while(ub-lb>1){
		long long mid=(ub+lb)/2;
		long long a=mid*(mid+1);
		if(a<K) lb=mid;
		else ub=mid;
	}
	if((lb+1)*(lb+1)<K){
		long long n=lb*2+5;
		long long k=K-(lb+1)*(lb+1);
		return P(n,k);
	}else{
		long long n=lb*2+4;
		long long k=K-lb*(lb+1);
		return P(n,k);
	}
}

int main(){
	long long K;
	scanf("%lld",&K);
	if(K<=6){
		printf("%lld\n",K);
		return 0;
	}
	P p=get(K);
	P p2=get(p.first,p.second);
	long long tmp1=getF(p2.first);
	long long tmp2=getF(p2.second);
	long long ans=tmp1*tmp2;
	ans%=mod;
	ans+=mod;
	ans%=mod;
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 1028
#include"bits/stdc++.h"
     
    using namespace std; 
     
    typedef vector<int> VI;
    typedef vector<VI> VVI;
    typedef vector<string> VS;
    typedef pair<int, int> PII;
    typedef vector<PII> VPII;
    typedef long long LL;
    typedef vector<LL> VL;
    typedef vector<VL> VVL;
    typedef pair<LL, LL> PLL;
    typedef vector<PLL> VPLL;
    typedef priority_queue<int> PQ_DESC;
    typedef priority_queue<int, vector<int>, greater<int>> PQ_ASC;
    typedef priority_queue<PII> PQ_DESC_PII;
    typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;
    typedef priority_queue<VL> PQ_DESC_VL;
    typedef priority_queue<VL, vector<VL>, greater<VL>> PQ_ASC_VL;
    typedef priority_queue<PLL> PQ_DESC_PLL;
    typedef priority_queue<PLL, vector<PLL>, greater<PLL>> PQ_ASC_PLL;
     
    #define ALL(c) (c).begin(),(c).end()
    #define PB push_back
    #define MP make_pair
    #define SORT_ASC(c) sort(ALL(c))
    //#define SORT_DESC(c) sort(ALL(c), greater<typeof(*((c).begin()))>())
    #define SORT_DESC(c) sort((c).rbegin(),(c).rend())
    #define REV(c) reverse((c).begin(), (c).end())
    #define SIZE(a) int((a).size())
     
    #define FOR(i,a,b) for(int i=(a);i<(b);++i)
    #define ROF(i,a,b) for(int i=(b-1);i>=(a);--i)
    #define REP(i,n) FOR(i,0,n)
    #define PER(i,n) ROF(i,0,n)
     
    const double EPS = 1e-10;
    const double PI  = acos(-1.0);
    const int LARGE_INT = 1e9+100;
    const int INF = 2e9+100;
    const LL INF_LL = (LL)INF*(LL)INF;
    const int MOD = 1e9+7;
     
    //debug
    #define dump(x)  cerr << #x << " = " << (x) << endl;
    #define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
     
     
    void Main()
    {
        int n,m;cin>>n>>m;
     
        VI a(m),key(m);
        REP(i,m){
            int b;
            cin>>a[i]>>b;
            REP(j,b){
                int c;cin>>c;
                key[i] |= 1<<(c-1);
            }
        }
     
        VVL dp(m);
        REP(i,m){
            dp[i].resize(1<<n,INF_LL);
        }
        dp[0][0] = 0;
        dp[0][key[0]] = a[0];

        FOR(i,1,m){
            REP(bit,(1<<n)){
                dp[i][bit] = min(dp[i][bit], dp[i-1][bit]);
                dp[i][bit|key[i]] = min(dp[i][bit|key[i]] , dp[i-1][bit]+a[i]);
            }
        }
     
        if(dp[m-1][(1<<n)-1] == INF_LL){
            cout<<-1<<endl;
        }
        else{
            cout<<dp[m-1][(1<<n)-1]<<endl;
        }
     
    	return;
    }
     
    int main()
    {
    	cin.tie(nullptr);
    	ios_base::sync_with_stdio(false);
    	cout << fixed << setprecision(15);
    	Main();
        return 0;
    }

Measured memory_bytes: 35012
#include<iostream>
using namespace std;
int main()
{
  int a,b,d,e = 0;
  int f[100]{}; 
  
  cin >> a >> b;
  while(cin >> d){
    f[d] = 1;
  }
while(e < 51){
  if(f[a - e] != 1){
  cout << a - e;
  return 0;
  }

  if(f[a + e] != 1){
  cout << a + e;
  return 0;
  }
e++;
}
  cout << a;
  return 0;
}

Measured memory_bytes: 3640
A, B = map(int, input().split())

def test(A):
	if A % 2 == 1:
		if (A+1)/2 % 2 == 1:
			tmp_A = 1
		else:
			tmp_A = 0
	else:
		if A/2 % 2 == 1:
			tmp_A = 1 ^ A
		else:
			tmp_A = 0 ^ A
	return tmp_A

print(test(A-1)^test(B))

Measured memory_bytes: 38384
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define FIND(s, e) ((s).find(e) != (s).end())
#define EB emplace_back
template<typename T> inline bool chmax(T &a, T b){if (a < b){a = b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if (a > b){a = b;return true;}return false;}

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

int main(void) {
    int n;
    cin >> n;
    map<int, int> cnt;
    REP(i, n) {
        int a;
        cin >> a;
        cnt[a]++;
    }
    int m;
    cin >> m;
    bool ok = true;
    REP(i, m) {
        int a;
        cin >> a;
        if (cnt.count(a) && cnt[a] > 0) {
            cnt[a]--;
        } else ok = false;
    }
    cout << (ok ? "YES" : "NO") << endl;
}


Measured memory_bytes: 9600
#import numpy as np
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial#, gcd
from bisect import bisect_left, bisect_right #bisect_left(list, value)
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
pl = lambda x: print(*x, sep='\n')

H, W, K = map(int, input().split())
def myfunc(x):
    if x=='.':
        return 0
    elif x=='#':
        return 1
HW = [list(map(myfunc, list(input()))) for _ in range(H)]
# print(HW)

res = 0
for i in range(2**H):
    for j in range(2**W):
        cnt = 0
        for indi, row in enu(HW):
            if not(i>>indi & 1): continue
            for indj in range(W):
                if not(j>>indj & 1): continue
                cnt += row[indj]
            # print(' cnt:', cnt)
        if cnt==K: res += 1
        
print(res)

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

int main(void) {
  int n, i = 0, r = 1, m;
  cin >> n;
  vector<int> h(n);
  for(; i < n; i++) cin >> h[i];
  m = h[0];
  for(i = 1; i < n; i++) {
    if(m <= h[i]) {
      m = h[i];
      r++;
    }
  }
  cout << r << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <tuple>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <cstdio>
#include <numeric>
#define REP(i, n) for(LL i = 0;i < n;i++)
#define REPR(i, n) for(LL i = n;i >= 0;i--)
#define FOR(i, m, n) for(LL i = m;i < n;i++)
#define FORR(i, m, n) for(LL i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()
#define INF 999999999
#define MOD 1000000007
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
typedef pair<LL, LL> LP;
typedef pair<int, P> PP;
typedef pair<LL, LP> LPP;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

/*************** using variables ***************/
int n, y;
int ans_1000 = -1, ans_5000 = -1, ans_10000 = -1; 
/**********************************************/

int main(){
    cin >> n >> y;
    REP(i, n+1){
        REP(j, n+1){
           if(n-i-j >= 0 && i*10000 + j*5000 + (n-i-j)*1000 == y){
               cout << i << " " << j << " " << n-i-j << endl;
               return 0;
           }   
        }
    }
    cout << ans_10000 << " " << ans_5000 << " " << ans_1000 << endl; 
}


Measured memory_bytes: 256
num=gets.to_i
(1..num).each do |i|
  if i%3==0
    print " #{i}"
  elsif i%10==3
    print " #{i}"
  else
    k=i
    while k/10 > 0
      k = k/10
      if k%10==3
        print " #{i}"
        break
      end
    end
  end
end
puts

Measured memory_bytes: 6096
#include <iostream>
#include <string>
#include <map>
#include <algorithm>

int main()
{
  int n;
  scanf("%d", &n);
  long long ans = 0;
  std::map<std::string, int> m;
  for (int i = 0; i < n; ++i)
  {
    std::string s;
    std::cin >> s;
    std::sort(s.begin(), s.end());
    ans += m[s];
    m[s]++;
  }
  printf("%lld\n", ans);
  return 0;
}

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

int main()
{
    int n;
    cin >> n;
    int x[100];
    for (int i=0; i < n; ++i) {
        cin >> x[i];
    }
    for (int i=100; i >= 1; --i) {
        bool isOk = true;
        int t = 0;
        for (int j=0; j < n; ++j) {
            t += x[j];
            t -= i;
            if (t < 0) {
                isOk = false;
                break;
            }
        }
        if (isOk) {
            cout << i << endl;
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 3112
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		while(true){
			int a = stdIn.nextInt();
			int b = stdIn.nextInt();
			int c = stdIn.nextInt();
			if((a|b|c)==0){
				return;
			}
			double t = Math.sqrt(a*a+b*b);
			t = Math.min(t, Math.sqrt(b*b+c*c));
			t = Math.min(t, Math.sqrt(a*a+c*c));
			int n = stdIn.nextInt();
			for(int i=0;i<n;i++){
				int ana = stdIn.nextInt();
				if(ana*2>t){
					System.out.println("OK");
				}
				else{
					System.out.println("NA");
				}
			}
		}
	}
}

Measured memory_bytes: 11000
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef pair<int,pii> pip;
typedef vector<pip>vip;
const double PI=acos(-1);
const double EPS=1e-8;
const int inf=1e9;
int main(){
	int n,nu,nn,l;
	cin>>n>>nu>>nn>>l;
	map<int,pii>mu,mn;
	rep(i,n)rep(j,n){
		int a;
		cin>>a;
		mu[a]=pii(i+1,j+1);
	}
	rep(i,n)rep(j,n){
		int a;
		cin>>a;
		mn[a]=pii(i+1,j+1);
	}
	vi cou(2*n+2),con(2*n+2);
	vi num(l);
	rep(i,l)cin>>num[i];
	rep(i,l){
		pii p=mu[num[i]];
		if(p.first||p.second){
			if(n==1){
				nu--;
			}else{
				int x=p.first-1,y=p.second-1;
				cou[x]++;cou[n+y]++;
				if(x==y){
					cou[2*n]++;
					if(cou[2*n]==n)nu--;
				}
				if(x+y==n-1){
					cou[2*n+1]++;
					if(cou[2*n+1]==n)nu--;
				}
				if(cou[x]==n)nu--;
				if(cou[n+y]==n)nu--;
			}
		}
		p=mn[num[i]];
		if(p.first||p.second){
			if(n==1){
				nn--;
			}else{
				int x=p.first-1,y=p.second-1;
				con[x]++;con[n+y]++;
				if(x==y){
					con[2*n]++;
					if(con[2*n]==n)nn--;
				}
				if(x+y==n-1){
					con[2*n+1]++;
					if(con[2*n+1]==n)nn--;
				}
				if(con[x]==n)nn--;
				if(con[n+y]==n)nn--;
			}
		}
		if(nu<=0||nn<=0){
			if(nu<=0&&nn<=0)cout<<"DRAW"<<endl;
			else if(nu<=0)cout<<"USAGI"<<endl;
			else cout<<"NEKO"<<endl;
			return 0;
		}
	}
	cout<<"DRAW"<<endl;
}

Measured memory_bytes: 22480
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <sstream>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#define rep(i, n) for(int i = 0; i < n; i ++)
#define COUNT(i, n) for(int i = 1; i <= n; i ++)
#define ITER(c) __typeof((c).begin())
#define each(c, it) for(ITER(c) it =(c).begin(); it!=(c).end(); it++)
#define ALL(c) c.begin(), c.end()
#define mp make_pair
#define pb push_back
#define MEMSET(v, h) memset((v), h, sizeof(v))
 
using namespace std; 

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

const int INF = 1 << 24;
 
int main(void){
    for(int n, m, s; s = 0, cin >> n >> m, n; cout << s << endl){
        priority_queue<int> p;
        rep(i, n){
            int in; cin >> in;
            p.push(in);
        }
        COUNT(i, n){
            if(i % m) s += p.top();
            p.pop();
        }
    }
 
    return 0;
}

Measured memory_bytes: 1228
#include<bits/stdc++.h>
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define print(x) cout << (x) << endl;
#define printa(x, n) for(ll i = 0; i < n; i++) {cout << (x[i]) << " ";} cout << endl;
using namespace std;
using ll = long long;

const ll MOD = 1e9 + 7;
ll dp[105][4][4][4];
// dp[i][j][k][l] := 前からi文字見た時で後ろの文字が前からi、ｊ、ｋとなってるときの条件を満たす文字列の数
// 0:A 1:C 2:G 3:T 

int main(void) {
    int n;
    cin >> n;

    dp[0][3][3][3] = 1;

    for (int i = 0; i < n; i++) rep (j, 4) rep (k, 4) rep (l, 4) rep (a, 4) {
        if (k == 0 && l == 2 && a == 1) continue; 
        if (k == 2 && l == 0 && a == 1) continue; 
        if (k == 0 && l == 1 && a == 2) continue; 
        if (j == 0 && k == 2 && a == 1) continue; 
        if (j == 0 && l == 2 && a == 1) continue;

        dp[i + 1][k][l][a] += dp[i][j][k][l];
        dp[i + 1][k][l][a] %= MOD;
    }
    
    ll ans = 0;

    rep (i, 4) rep (j, 4) rep (k, 4) {
        ans += dp[n][i][j][k];
        ans %= MOD;
    }

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

Measured memory_bytes: 256
#!/usr/bin/env python
"""AtCoder Beginner Contest 168: C
https://atcoder.jp/contests/abc168/tasks/abc168_c
"""

__author__ = 'bugttle <bugttle@gmail.com>'

import math

def normalize_angle(angle):
    angle = 360 - angle
    angle = angle + 90
    if (360 <= angle):
        angle -= 360
    return angle


def main():
    A, B, H, M = list(map(int, input().split()))

    # X * 12 = 360
    # X * 60 = 30
    angle = normalize_angle((H * 30 + M * 0.5))
    x1 = A * math.cos(math.radians(angle))
    y1 = A * math.sin(math.radians(angle))

    # X * 60 = 360
    angle = normalize_angle((M * 6))
    x2 = B * math.cos(math.radians(angle))
    y2 = B * math.sin(math.radians(angle))

    print("{:.20f}".format(math.sqrt((x2 - x1)**2 + (y2 - y1) ** 2)))

if __name__ == '__main__':
    main()


Measured memory_bytes: 9524
N=int(input())
inf=float("inf")
dp=[[inf]*51 for i in range(51)]
for b in range(51):
  for a in range(51):
    if b==0:
      if a==0:
        dp[a][b]=0
      else:
        dp[a][b]=1
    else:
      for i in range(1,a+1):
        if a==b:
          dp[a][b]=0
        elif dp[a%i][b]<=50 or a%i==b:
          dp[a][b]=i
          break
a=[int(i) for i in input().split()]
b=[int(i) for i in input().split()]
ans=0
stack=[[a[i]] for i in range(N)]
def dfs(x):
  if x==0:
    return 
  global ans
  ans+=2**x
  for i in range(N):
    visited=[False]*51
    for j in stack[i]:
      visited[j]=True
      if not visited[j%x]:
        stack[i].append(j%x)
        visited[j%x]=True
  k=0
  for i in range(N):
    k=max(k,min([dp[j][b[i]] for j in stack[i]]))
  if k==0:
    return 
  return dfs(k)
M=max([dp[a[i]][b[i]] for i in range(N)])
if M>50:
  print(-1)
  exit()
dfs(M)
print(ans)


Measured memory_bytes: 43484
import java.util.*;



public class Main {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int n, i, j;
        n = s.nextInt();
        int[] a = new int[n];
        for (j = 0; j < n; j++) {
            a[j] = s.nextInt();
        }

        int flag = 1;
        for (j = 0; j < n; j++){
            if ((a[j] % 2 == 0)) {
                if (a[j] % 3 == 0 || a[j] % 5 == 0) {
                    flag = 1;
                }
                else
                {
                    flag=0;
                    break;
                }

            }}

        if (flag == 0) {
            System.out.println("DENIED");

        }
        else{
            System.out.println("APPROVED");}
    }
}


Measured memory_bytes: 23124
from collections import defaultdict
from itertools import permutations

N = int(input())
balls = [tuple(map(int, input().split())) for _ in range(N)]
if N == 1: print(1)
else:
    cnt = defaultdict(int)
    for b1, b2 in permutations(balls, 2):
        cnt[(b2[0] - b1[0], b2[1] - b1[1])] += 1
    _, n = max(cnt.items(), key=lambda x: x[1])
    cost = N - n
    print(cost)

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

int N;
int a[4];
string ans;
int sum;

int main() {
  cin >> N;
  
  for (int i = 3; i >= 0; i--) {
    a[i] = N % 10;
    N /= 10;
  }

  for (int bit = 0; bit < (1<<4); ++bit) {
    sum = a[0];
    ans = (char)(a[0] + '0');

    for (int i = 0; i < 3; ++i) {
      if (bit & (1<<i)) {
        sum += a[i + 1];
        ans += '+';
      }
      else {
        sum -= a[i + 1];
        ans += '-';
      }
      ans += (char)(a[i + 1] + '0');
    }
    if (sum == 7) {
      cout << ans << "=7" << endl;
      return 0;
    }
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N;
    cin >> N;
    vector<int> P(N);
    for (int i = 0; i < N; i++) {
        cin >> P.at(i);
    }
    vector<int> Q(N);
    for (int i = 0; i < N; i++) {
        cin >> Q.at(i);
    }
    vector<int> X(N);
    for (int i = 0; i < N; i++) {
        X.at(i) = i+1;
    }

    int a,b,res;
    int i = 0;
    do
    {
        if(P==X){
            a = i+1;
        }
        if(Q==X){
            b = i+1;
        }
        i++;
    }while(next_permutation( begin( X ), end( X ) ));
    
    res = a-b;

    if(res < 0){
        res *= -1;
    }
    cout << res << endl;

}

Measured memory_bytes: 256