akhauriyash/Code-Regression huggingface dataset:
<?php
    $n = trim(fgets(STDIN));
	$x = explode(" ", trim(fgets(STDIN)));
	$n2 = $n*$n;
	for($i=1; $i<=$n2; $i++){
	    $a[$i] = 0;
	    $b[$i] = 0;
	}
	for($i=1; $i<=$n; $i++){
	    $a[$x[$i-1]] = $i;
	}
	
	$f = true;
	$m = 0;
	$c = 1;
	for($i=1; $i<=$n2; $i++){
	    if($f && $a[$i] != 0){
	        $m = $a[$i];
	        for($j=1; $j<$m; $j++){
	            while($a[$c] != 0 || $b[$c] != 0){
	                $c++;
	                if($c>$n2){
	                    $f = false;
	                    break;
	                }
	            }
	            if(!$f) break;
	            $b[$c] = $m;
	        }
	        if($c>$i) $f = false;
	    }
	}
	
	$c = $n2;
	for($i=$n2; $i>0; $i--){
	    if($f && $a[$i] != 0){
	        $m = $a[$i];
	        for($j=$m; $j<$n; $j++){
	            while($a[$c] != 0 || $b[$c] != 0){
	                $c--;
	                if($c<1){
	                    $f = false;
	                    break;
	                }
	            }
	            if(!$f) break;
	            $b[$c] = $m;
	        }
	        if($c<$i) $f = false;
	    }
	}
	if($f){
	    echo "Yes"."\n";
	    for($i=1; $i<=$n2; $i++){
    	    if($a[$i] != 0) $ans = $a[$i];
    	    else $ans = $b[$i];
    	    echo $ans." ";
	    }
	} else echo "No";
?>

Measured memory_bytes: 23916
#include <bits/stdc++.h>
using namespace std;
int main() {
	int h, w, d; cin >> h >> w >> d;
	int ii[90005];
	int jj[90005];
	int sum[90005];
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			int a; cin >> a;
			ii[a] = i;
			jj[a] = j;
		}
	}
	for(int k=1;k<h*w+1;k++){
		if(k+d<=h*w){
			int dist = abs(ii[k+d]-ii[k])+abs(jj[k+d]-jj[k]);
			sum[k+d] = sum[k]+dist;
		}
	}
	int q; cin >> q;
	for(int i=0;i<q;i++){
		int l, r; cin >> l >> r;
		cout << sum[r]-sum[l] << endl;
	}
	return 0;
}

Measured memory_bytes: 2176
N, Y = map(int, input().split(' '))

found = False

for i in range(N + 1):
    for j in range(N - i + 1):
        k = N - i - j
        if i * 10000 + j * 5000 + k * 1000 == Y:
            print('{} {} {}'.format(i, j, k))
            found = True
            break
    else:
        continue
    break

if not found:
    print('-1 -1 -1')


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int main(){
  
  int n;
  cin >> n;
  
  vector<int> v(n);
  
  for(int i = 0; i < n; i++){
    cin >> v.at(i);
  }
  
  int p, q, r, s = 0;
  
  while(p < n){
    q = p;
    while(q < n){
      if(v.at(q) > 0){
        q++;
      }
      else
        break;
    }
    r = p;
    if(p != q){
      while((p <= r) && (r < q)){
        v.at(r)--;
        r++;
      }
      s++;
    }
    if(v.at(p) == 0){
      p++;
    }
  }
  cout << s << endl;
}

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

using pii = pair<int, int>;

int main() {
    int n;
    while(cin >> n, n) {
        vector<pii> pos;
        int res = 0;
        for(int i = 0; i < n; ++i) {
            int s; cin >> s;
            if(i & 1) {
                int now = i;
                while(!pos.empty() && pos.back().first != s) {
                    int nxt = pos.back().second;
                    res += (s == 0 ? now - nxt : nxt - now);
                    now = nxt;
                    pos.pop_back();
                }
                if(pos.empty()) {
                    res += (s == 0 ? now : -now);
                }
            }
            res += s == 0;
            pos.emplace_back(s, i);
        }
        cout << res << endl;
    }
}


Measured memory_bytes: 3084
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>
#include <stack>
#include <cstdint>



#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rrep(i, n) for(ll i = (ll)(n-1); i >= 0; i--)
#define repi(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rrepi(i,a,b) for(ll i=(ll)(b-1);i>=(ll)(a);i--)

#define all(x) (x).begin(),(x).end()

template<class T>inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

typedef long long ll;

using namespace std;



template <std::uint_fast64_t Modulus> class modint {
  using u64 = std::uint_fast64_t;

public:
  u64 a;

  modint(const u64 x = 0) noexcept : a(x % Modulus) {}
  u64 &value() noexcept { return a; }
  u64 &value() const noexcept { return a; }
  modint operator+(const modint rhs) const noexcept {
    return modint(*this) += rhs;
  }
  constexpr modint operator-(const modint rhs) const noexcept {
    return modint(*this) -= rhs;
  }
  constexpr modint operator*(const modint rhs) const noexcept {
    return modint(*this) *= rhs;
  }
  constexpr modint operator/(const modint rhs) const noexcept {
    return modint(*this) /= rhs;
  }
  modint &operator+=(const modint rhs) noexcept {
    a += rhs.a;
    if (a >= Modulus) {
      a -= Modulus;
    }
    return *this;
  }
  modint &operator-=(const modint rhs) noexcept {
    if (a < rhs.a) {
      a += Modulus;
    }
    a -= rhs.a;
    return *this;
  }
  modint &operator*=(const modint rhs) noexcept {
    a = a * rhs.a % Modulus;
    return *this;
  }
  modint &operator/=(modint rhs) noexcept {
    u64 exp = Modulus - 2;
    while (exp) {
      if (exp % 2) {
        *this *= rhs;
      }
      rhs *= rhs;
      exp /= 2;
    }
    return *this;
  }
  modint pow(u64 exp){
    modint res=1,rhs=*this;
    while (exp) {
      if (exp % 2) {
        res *= rhs;
      }
      rhs *= rhs;
      exp /= 2;
    }
    return res;
  }

  friend ostream& operator<<(ostream& os,modint& rhs){
    os << rhs.value();
    return os;
  }

  friend istream& operator>>(istream &is,modint &rhs){
      is>>rhs.value();
      rhs.value()%=Modulus;
      return is;
  }

};

using mint=modint<(int)1e9+7>;
struct factorial{
  vector<mint>fact,inv;
  factorial(int n){
    fact.assign(n,0);
    inv.assign(n,0);
    fact[0]=1;
    for(int i=0;i<n-1;i++){
      fact[i+1]=fact[i]*(i+1);
    }
    inv[n-1]=(mint)1/fact[n-1];
    for(int i=n-1;i>=1;i--){
      inv[i-1]=inv[i]*i;
    }
  }
  mint comb(int a,int b){
    if(b>a||b<0)return 0;
    return fact[a]*inv[b]*inv[a-b];
  }

};
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll r1,c1,r2,c2;cin>>r1>>c1>>r2>>c2;
  factorial f(2e6+7);
  mint res=f.comb(r1+c1,r1)-f.comb(r1+c2+1,r1)-f.comb(r2+c1+1,c1)+f.comb(r2+c2+2,r2+1);
  cout<<res<<endl;

  return 0;

}


Measured memory_bytes: 31488
#include <iostream>
#include <cmath>
#include <set>
#include <string>
#include <algorithm>
#include <vector>
#include <bitset>
#include <iomanip>
#include <map>
#include <queue>
#include <numeric>

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;
using std::bitset;

#define rep(i,n)    for(int i=0; i<(int)n; i++)
#define reps(i,s,e) for(int i=s; i<(int)e; i++)
typedef long double ld;
typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef std::pair<int, int> pii;
typedef std::pair<ll, ll> pll;

template<class T>
using Graph = vector<vector<T>>;

void printFixedDouble(double d, int fix) {
    cout << std::fixed;
    cout << std::setprecision(fix) << d << endl;
}

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

    int flag = -1;
    int bs[N];
    int evenCount = -1;
    rep(i, N) {
        int b;
        cin >> b;
        b /= 2;
        if (flag == -1) {
            flag = b % 2;
        } else if (b % 2 != flag) {
            cout << 0 << endl;
            return 0;
        }
        if (flag == 0) {
            int tmp = b;
            int count = 0;
            while (tmp % 2 == 0) {
                tmp /= 2;
                count++;
            }
            if (evenCount == -1) {
                evenCount = count;
            } else if (evenCount != count) {
                cout << 0 << endl;
                return 0;
            }
        }
        // cout << b << endl;
        bs[i] = b;
    }


    ll gcd = 1;
    rep(i, N) {
        gcd = gcd * bs[i] / std::__gcd(gcd, (ll)bs[i]);
        // cout << bs[i] << " " << gcd << endl;
    }
    
    cout << ((ll)M/gcd+1)/2<< endl;

}

Measured memory_bytes: 640
# -*- coding: utf-8 -*-
# 整数の入力


a, b, c = map(int, input().split())
k = int(input())


for i in range(k):
    if a >= b:
        b *= 2
        continue

    if b >= c:
        c *= 2

if a < b:
    if b < c:
        print("Yes")
    else:
        print("No")
else:
    print("No")


Measured memory_bytes: 9172
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#define inf 1013161010
#define ninf -1013161010
#define mod 1000000007
#define ll long long
#define lf long double
#define in(x) scanf("%d",&x);
#define sz(x) ((int)x.size())
#define lld l64d
#define rep(i,n) for(i=0;i<n;i++)
#define rrep(i,n) for(i=n-1;i>=0;i--)
#define rep1(i,a,b) for(i=a;i<=b;i++)
#define rrep1(i,a,b) for(i=a;i>=b;i--)
#define stlfor(i,t) for(auto i =t.begin();i!=t.end();i++)
#define fr freopen("x.txt","r",stdin)
#define frc freopen("y.txt","w",stdout)
#define all(x) x.begin(),x.end()
#define set0(x) memset(x,0,sizeof(x))
#define dbg cout<<"yo "<<endl;
#define pset(n) fixed<<showpoint<<setprecision(n)

#define pii pair<int,int>
#define pll pair<ll,ll>
#define vpii vector<pair<int,int> >
#define si set<int>
#define mii map<int,int>
#define umii unordered_map<int,int>
#define vi vector<int>
#define pb push_back
#define ff first
#define ss second
#define mp make_pair

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> OST;

ll toint(const string &s) { stringstream ss; ss << s; ll x; ss >> x; return x; }
string tostring ( ll number ){  stringstream ss; ss<< number; return ss.str();}

const lf pi = 2*acos(0);
const int nn = 2123456;

ll gcd(ll a,ll b){return (b==0)? a:gcd(b,a%b); }
void nope(int num = 0){ if(num==0) cout<<"NO"; else cout<<"-1"; exit(0); }

void solve()
{
    ll i,j,n,t;
    cin>>n>>t;
    ll last = 0,ans=0,a;
    rep(i,n)
    {
        cin>>a;
        if(last>a)
        {
            ans += ((a+t)-last);
            last=(a+t);
        }
        else
        {
            ans+=t;
            last=(a+t);
        }
    }

    cout<<ans<<endl;
}

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(0);
    ll i,j,n,tt;
    tt=1;
    //cin>>tt;
    while(tt--)
    {
        solve();
    }
    return 0;
}



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

using namespace std;

const int N = 1e5+5;
const int MaxN = 2e5+5;
typedef long long ll;
typedef long double ld;

int a[N];
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int x, n;
    cin >> x >> n;
    map<int,int>f;
    for (int i = 0; i < n; i++){
        int b;
        cin >> b;
        f[b]++;
    }
    int l = x, r = x;
    while (true){
        if (!f[l]){
            cout << l;
            return 0;
        }
        l--;
        if (!f[r]){
            cout << r;
            return 0;
        }
        r++;
    }
}


Measured memory_bytes: 3660
#include<bits/stdc++.h> 
#define fo(i,a,b) for(i=a;i<=b;i++)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define min(a,b) (a<b?a:b)
#define max(a,b) (a>b?a:b)
typedef long long ll;
using namespace std;
inline int read(){
	int n=0,f=1;char c;
	for(c=getchar();(c<'0'||c>'9')&&c!='-';c=getchar());
	if (c=='-') c=getchar(),f=-1;
	for(;c>='0'&&c<='9';c=getchar()) n=n*10+c-48;
	return n*f;
}
const int maxn=2e5+5;
int i,j,n,k[maxn],ne[maxn<<1],g[maxn<<1],num;
struct ar{int s1,s2;}mx[maxn];
int fa[maxn],high[maxn],low[maxn];char s[maxn];
struct ax{int x,id;};
bool operator <(ax a,ax b){
	return (a.x==b.x)?a.id<b.id:a.x<b.x;
}
set<ax>w;
ll ans;
void add(int x,int y){
	ne[++num]=k[x],k[x]=num,g[num]=y;
} 
void update(ar &now,int x){
	if (x>now.s1) now.s2=now.s1,now.s1=x;else now.s2=max(now.s2,x); 
}
void dfs(int x){
	int i,f=fa[x];
	for(i=k[x];i;i=ne[i]){
		int go=g[i];
		if (go!=f){
			fa[go]=x,dfs(go);
			update(mx[x],mx[go].s1+1);
		}
	}
}
void df(int x,int y){
	ar now=mx[x];int i,f=fa[x],s;
	update(mx[x],y);
	y++;
	for(i=k[x];i;i=ne[i]){
		int go=g[i];
		if (go!=f) s=(mx[go].s1+1==now.s1?now.s2:now.s1)+1,df(go,max(y,s));
	}
}
int main(){
	n=read();
	fo(i,1,n-1){
		int x=read(),y=read();
		add(x,y),add(y,x);
	}scanf("%s",s+1);
	dfs(1);
	df(1,0);
	fo(i,1,n) {
		if (s[i]=='0') low[i]=n;
		high[i]=min(mx[i].s1-1,mx[i].s2+1);
		w.insert((ax){low[i],i});
	}
	fo(j,1,n){
		ax now=*w.begin();
		w.erase(w.find(now));
		int x=now.id,d=mx[x].s2+1,p=mx[x].s1,o=0; 
		if (d<low[x]||d>high[x]) continue;
		for(i=k[x];i;i=ne[i])if (mx[g[i]].s1+1==p) {o=g[i];break;}
		if (!o) o=fa[x];
		if (low[o]<=d) continue;
		w.erase(w.find((ax){low[o],o}));
		low[o]=d;
		w.insert((ax){low[o],o});
	}
	fo(i,1,n) ans+=max(0,high[i]-low[i]+1);
	printf("%lld\n",ans+1);
} 

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

signed main(){
  int N, M;
  cin >> N >> M;
  int s[1000], c[1000];
  rep(i,M){
    cin >> s[i] >> c[i];
  }
  rep(i,1000){
    bool a = true;
    rep(j,M){
        if(to_string(i)[s[j]-1] != to_string(c[j])[0]){a = false;break;}
    }
    if(a){if(to_string(i).length() == N){cout << i;return 0;}}
  }
  cout << -1;
}



Measured memory_bytes: 3688
#include "bits/stdc++.h"
#define ll long long
#define rep2(i,a,b) for(int i=(a);i<=(b);++i)
#define rep(i,n) for(int i=0;i<n;i++)
#define pii pair<int,int>
#define ti3 tuple<int,int,int>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
ll int MOD=1e9+7;
#define N 200000
 
using namespace std;
string alphabet("abcdefghijklmnopqrstuvwxyz");
ll int gcd(ll int a,ll int b){
    if(a>b) return gcd(b,a);
    if(a==0) return b;
    return(gcd(b%a,a));
}
main(){
    ll int n,x;
    cin>>n>>x;
    ll int g=gcd(x,n-x);
    cout<<(n-g)*3;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;

int main() {
  string s;
  string t;
  cin >> s >> t;
  s += s;
  int n = s.size() / 2;
  bool yes = true;
  vector<vector<int>> spos(26);
  for(int i=0;i<n * 2;i++) {
    spos[s[i]-'a'].emplace_back(i);
  }
  vector<vector<int>> next(n, vector<int>(26));
  for(int i=0;i<next.size();i++) {
    for(int j=0;j<26;j++) {
      auto it = upper_bound(spos[j].begin(), spos[j].end(), i);
      if(it == spos[j].end()) next[i][j] = 0;
      else next[i][j] = *it;
    }
  }
  long long ans = 0;
  for(int i=0;i<t.size();i++) {
    if(spos[t[i]-'a'].size() == 0) {
      yes = false;
      break;
    }
    if(i == 0) ans = spos[t[i]-'a'].front();
    else ans += next[ans%n][t[i]-'a'] - ans % n;
  }

  if(yes) cout << ans + 1LL << endl;
  else cout << -1 << endl;
}


Measured memory_bytes: 14720
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int inf=1e9;
int main(void)
{
    int a,b,c;
    cin >> a >> b >> c;
    int toa=min(a-b,c);
    cout << c-toa << endl;
    return 0;
}

Measured memory_bytes: 256
class SegmentTree():
	def __init__(self,n):
		self.dat = [INF for _ in range(n*2-1)]
		#index n???????????????????????¢?????????:
		#???????????? : (n-1)//2
		#???????????? : (2n+1) , (2n+2)
		self.n = n

	def update (self,node_index,value):
		""" index?????????value????????´?????? """
		index = node_index + (self.n-1) #node_index????????????dot???index?????????
		self.dat[index] = value

		#?????°????????????????????????????????´????????????
		while index > 0 :
			index = (index - 1) // 2				 #???????????????????????£???
			self.dat[index] = min([self.dat[index*2+1],self.dat[index*2+2]]) #??????????????????????????????

	def querry (self,left,right,nowNode,nowLeft,nowRight):
		"""[left,right):??¢?´¢??????,noeNode:?????¨????????????,[nowLeft,nowRight):?????¨?????????????????????"""

		# ??????????????¶??£????????????
		if nowRight < left or nowLeft > right:
			return INF

		# ?????¨?????¢?´¢???????????¨????????????????????????????????????
		if left <= nowLeft and nowRight <= right:
			return self.dat[nowNode]

		# ???????????????????????????????????¨???????????????
		else:
			value_left =self.querry(left,right,2*nowNode+1,nowLeft,(nowLeft+nowRight)//2)
			value_right = self.querry(left,right,2*nowNode+2,(nowLeft+nowRight)//2+1,nowRight)
			return min([value_left,value_right])

	def DEBUG_dat(self):
		print(self.dat)
		

if __name__ == "__main__":
	# ??????????????????
	INF = 2147483647
	n ,q  = map(int,input().split(" "))
	result = []

	for i in range(1,20):
		if 2 ** i >= n:
			min_pow2 = 2 **  i
			break

	tree = SegmentTree(min_pow2)

	for i in range(q):
		com,x,y = map(int,input().split(" "))
		if com == 0:
			tree.update(x,y)
		else:
			result.append(tree.querry(x,y,0,0,min_pow2-1))

	for i in result:
		print(i)




	

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

int main()
{
    int a,b;
    cin>>a>>b;
    string s1="",s2="";
    for(int i=0;i<a;i++){
        s1+=to_string(b);
    }
    for(int i=0;i<b;i++){
        s2+=to_string(a);
    }
    if(s1<s2) cout<<s1;
    else cout<<s2;
    return 0;
}


Measured memory_bytes: 256
#include<algorithm>
#include<string>
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
 
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

 
int main(){
    
    int n;
    int t,a;
    cin >> n;
    vector<double> h(n);
    cin >> t >> a;
    double mini = 100000;
    int point;
    REP(i,n){
        cin >> h[i];
    }
    REP(i,n){
        double s = abs(t - h[i]*0.006 - a);
        if(s < mini){
            mini = s;
            point = i + 1;
        }
    }
    
    cout << point << endl;

    return 0;
}

Measured memory_bytes: 256
import sys
import math
import collections
import bisect
import itertools
import decimal

# import numpy as np

# sys.setrecursionlimit(10 ** 6)
INF = 10 ** 20
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline().rstrip())
ns = lambda: map(int, sys.stdin.readline().rstrip().split())
na = lambda: list(map(int, sys.stdin.readline().rstrip().split()))
na1 = lambda: list(map(lambda x: int(x) - 1, sys.stdin.readline().rstrip().split()))


# ===CODE===

def main():
    n, m = ns()

    e = [[] for _ in range(n)]

    for _ in range(m):
        a, b = ns()
        a, b = a - 1, b - 1
        e[a].append(b)
        e[b].append(a)

    visited = [False for _ in range(n)]

    ans = 0
    for i in range(n):
        if not visited[i]:
            visited[i] = True
            cnt = 1
            que = collections.deque()
            que.append(i)

            while que:
                q = que.popleft()

                for ei in e[q]:
                    if not visited[ei]:
                        visited[ei] = True
                        cnt += 1
                        que.append(ei)

            ans = max(ans, cnt)
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 118972
#include<iostream>
#include<math.h>
#include<vector>
#include<array>
#include<algorithm>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vector<ll>> mat;
typedef pair<int,int> P;
ll mod=pow(10,9)+7;
ll INF=pow(10,18);

int main(){
    int N,M,Q;scanf("%d %d %d",&N,&M,&Q);
    mat imos(N+1,vec(N+1,0));
    for(int i=0;i<M;i++){
        int L,R;scanf("%d %d",&L,&R);
        for(int l=1;l<=L;l++){
            imos[l][R]++;
        }
    }
    mat S(N+1,vec(N+1,0));
    for(int i=1;i<=N;i++){
        for(int j=1;j<=N;j++){
            S[i][j]=S[i][j-1]+imos[i][j];
        }
    }
    for(int i=0;i<Q;i++){
        int p,q; scanf("%d %d",&p,&q);
        printf("%lld\n",S[p][q]);
    }
    return 0;
}

Measured memory_bytes: 4864
import java.util.Scanner;
class Main
 {
   public static void main(String[] args)
      {
      Scanner S = new Scanner(System.in);
      int a = S.nextInt();
      int b = S.nextInt();
      int c = S.nextInt();
      if(a < b && b < c){
      System.out.println("Yes");
              }
      else {
      System.out.println("No");
            }
      }
 }



Measured memory_bytes: 26312
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>

static const int INF = 1000000007;
using ll = long long;
using u32 = unsigned;
using namespace std;

int main() {
    u32 n, m, r;
    cin >> n >> m >> r;
    vector<vector<int>> v(n, vector<int>(n, INF));
    for (int i = 0; i < n; ++i) {
        v[i][i] = 0;
    }
    vector<int> R(r);
    for (int i = 0; i < r; ++i) {
        int x;
        cin >> x;
        R[i] = x-1;
    }
    sort(R.begin(), R.end());
    for (int i = 0; i < m; ++i) {
        int a, b, c;
        scanf("%d %d %d", &a, &b, &c);
        v[a-1][b-1] = v[b-1][a-1] = c;
    }
    for (int k = 0; k < n; ++k) {
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < n; ++j) {
                v[i][j] = min(v[i][j], v[i][k] + v[k][j]);
            }
        }
    }
    ll ans = numeric_limits<ll>::max();
    do{
        ll x = 0;
        for (int i = 0; i < r - 1; ++i) {
            x += v[R[i]][R[i+1]];
        }
        ans = min(x, ans);
    }while(next_permutation(R.begin(), R.end()));
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
typedef long long ll;
#define _GLIBCXX_DEBUG
typedef vector<int> vec;
typedef vector<ll> lvec;
typedef vector<char> cvec;
typedef vector<double> dvec;
typedef pair<ll, ll> LP;
typedef tuple<ll, ll, ll> LT;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
#define fs first
#define sc second
int main()	{
  int r;
  cin>>r;
  cout<<r*r<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
typedef vector<int> vi;
typedef pair<int, int> pi;
#define SQ(a) (a) * (a)
#define deb(x) cout << #x << " = " << x << '\n'
#define deb2(x, y) cout << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")\n"

double dist(pair<double,double> p1, pair<double,double> p2)
{
    return sqrt((p1.first - p2.first) * (p1.first - p2.first) +
                (p1.second - p2.second) * (p1.second - p2.second));
}
int main(int argc, char const *argv[])
{

#ifdef LOCAL_DEFINE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    double a,b,h,m;
    cin>>a>>b>>h>>m;
    pair<double,double> fi,sec;
    double deg = h*60 + m;
    fi.first = a * sin(deg * M_PI / 360);
    fi.second = a * cos(deg * M_PI / 360);

    sec.first = b * sin(m * M_PI / 30);
    sec.second = b * cos(m * M_PI / 30);

    cout << setprecision(20) <<dist(fi,sec);
     return 0;
}

Measured memory_bytes: 4128
import java.util.Scanner;

public class Main {

	static Scanner scanner;

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

	    int N=gi();
	    int M=gi();
	    
	    int a=(int)Math.ceil((double)(M-1)/(double)(N-1));
	   
        System.out.print(a);
//        if (c<=2) {
//        	System.out.println("YES");
//        }else {
//        	System.out.println("NO");
//        }
	}

	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}

	// doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	}
}

Measured memory_bytes: 35756
#include<cstdio>
#include<algorithm>
using namespace std;
const int N=3003,p=1000000007;
int f[N][N],R[N],s[N],i,j,k,n,m,d,x;
char c;

inline char getc()
{
	#define VV 10000000
	static char s[VV],*l=s,*r=s;
	if (l==r)
		l=s,r=s+fread(s,1,VV,stdin);
	return l==r?0:*l++;
}

int read(){ int z=0; do c=getc(); while (c<'0'||c>'9'); while (c>='0'&&c<='9') z*=10,z+=c-'0',c=getc(); return z; }

void chkmax(int &a,int b){ a=a<b?b:a; }

void Plus(int &a,int b){ a+=b,a-=a<p?0:p; }

bool getC()
{
	do c=getc(); while (c<'0'||c>'1');
	return c-'0';
}

int main()
{
	n=read(),m=read();
	for (i=1;i<=n;++i) R[i]=i,s[i]=s[i-1]+getC();
	for (i=1;i<=m;++i) x=read(),chkmax(R[x],read());
	d=R[1],f[1][s[d]]=1;
	for (i=2;i<=n;++i)
	{
		for (j=d-i+2;~j;--j)
		{
			int z=f[i-1][j];
			if (j<d-i+2)
				Plus(f[i][j],z);
			if (j)
				Plus(f[i][j-1],z);
		}
		
		if (d<R[i])
		{
			x=s[R[i]]-s[d],
			d=R[i];
			for (j=R[i]-i+1;j>=x;--j)
				f[i][j]=f[i][j-x];
			fill(f[i],f[i]+x,0);
		}
	}
	printf("%d\n",(f[n][0]+f[n][1])%p);
	return 0;
}

Measured memory_bytes: 35712
#include "stdio.h"
#include "stdbool.h"

int hoge(int N){
    for(int i=1;i<=9;i++){
        if(N%i==0){
            int x=N/i;
            if(1<=x & x<=9){
                return 1;
            }
        }
    }
    return 0;
}

int main(){
    int N;
    scanf("%d",&N);

    if(hoge(N)){
        printf("Yes");
    } else{printf("No");}



    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
const int dx[]={1,0,-1,0,1,-1,-1,1};
const int dy[]={0,1,0,-1,1,1,-1,-1};
const int INF = 1e9;
const long long LINF = 1e18;
const double EPS = 1e-8;
#define pb push_back
#define mk make_pair
#define fr first
#define sc second
#define ll long long
#define reps(i,j,k) for(int i = (j); i < (k); ++i)
#define rep(i,j) reps(i,0,j)
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007
typedef pair<int,int> Pii;
typedef vector<int> vi;
int main(){

	string str;
	cin >> str;
	char c[] = {'N','S','E','W'};
	bool flg[5]={};
	rep(i,str.size()){
		rep(j,4){
			if(str[i] == c[j]){
				flg[j] = true;
			}
		}
	}
	/*rep(j,4){
		cout << flg[j] << endl;
	}*/
	bool res = (flg[0]^flg[1]) | (flg[2]^flg[3]);

	puts(res?"No":"Yes");

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define cmin(a,b) (a>b?a=b:a)
#define cmax(a,b) (a<b?a=b:a)
#define lop(i,s,t) for(int i=s;i<(t);++i)
#define rep(i,s,t) for(int i=s;i<=(t);++i)
#define dec(i,s,t) for(int i=s;i>=(t);--i)
#define fore(i,v) for(int i=g[v],d=es[i].d;i;i=es[i].nxt,d=es[i].d)
using namespace std;

#define Pr(f,...) //fprintf(stderr,f,##__VA_ARGS__),fflush(stderr)

const int N=5e5+50; 

void read(int &x){
	x=0; 
	char c=getchar(); 
	for(;!isdigit(c);c=getchar()); 
	for(;isdigit(c);c=getchar())x=x*10+c-'0'; 
}

vector<int> g[N]; 
int n,a[N],root,fail,deg[N]; 

int dfs(int v,int p){
	if(deg[v]==1)return a[v];
	int sum=0,mxr=0;
	for(int d:g[v])if(d!=p){
		int req=dfs(d,v); 
		cmax(mxr,req); 
		sum+=req;
	}	
	int tim=mxr>sum/2?(sum-mxr):(sum/2); 
	//0<=x<=tim:x+(sum-x*2)==a[v]
	Pr("v=%d,p=%d,tim=%d,sum=%d,mxr=%d\n",v,p,tim,sum,mxr); 
	int x=sum-a[v];
	if(x<0||x>tim)fail=true;
	return sum-x*2;
}

int main(int argc,char *argv[]){
#ifdef CURIOUSCAT
	//freopen("dat.in","r",stdin);
	//freopen("my.out","w",stdout);
#endif
	read(n); 
	rep(i,1,n)read(a[i]); 
	rep(i,1,n-1){
		int u,v; 
		read(u),read(v); 
		g[u].pb(v),g[v].pb(u);
		++deg[u],++deg[v];
	}
	if(n==2)fail=a[1]!=a[2];
	rep(i,1,n)if(deg[i]>1)root=i;
	int res=dfs(root,0); 
	if(res!=0||fail)puts("NO");else puts("YES"); 
	return 0;
}

Measured memory_bytes: 24576
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<unordered_map>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())




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


	string s;
	cin >> s;
	cout << (s <= "2019/04/30" ? "Heisei" : "TBD") << endl;



	return 0;
}

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





int main() {
  string S;
  cin>>S;
  int N=int(S.size());
  
  for (int i=N-2;;i-=2){
    bool flag=true;
    for (int j=0;j<i/2;j++){
      if (S.at(j)!=S.at(j+i/2)){
        flag=false;
        break;
      }
    }
    if (flag){
      cout<<i<<endl;
      break;
    }
  }
  
        
  
}













Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cmath>
#include<cstdlib>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<queue>

using namespace std;


int main(){
  string s[2];
  cin>>s[0];
  cin>>s[1];
  bool y = true;
  if(s[0][0] != s[1][2]) y = false;
  if(s[0][1] != s[1][1]) y = false;
  if(s[0][2] != s[1][0]) y = false;
  if(y) cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;
const int M = 1000000007;

int main() {
    int w;
    cin >> w;
    vector<int> a(w);
    for (int i = 0; i < w; ++i) {
        cin >> a[i];
    }
    vector<int> l(w);
    int b = 0;
    for (int i = 0; i < w; ++i) {
        --b;
        if (a[i] == 0)
            b = M;
        else if (a[i] < 0)
            b = min(b, -a[i]);
        else
            l[i] = b;
    }
    vector<int> r(w);
    b = 0;
    for (int i = w - 1; i >= 0; --i) {
        --b;
        if (a[i] == 0)
            b = M;
        else if (a[i] < 0)
            b = min(b, -a[i]);
        else
            r[i] = b;
    }
    int ans = 0;
    for (int i = 0; i < w; ++i) {
        if (a[i] > 0)
            ans += min(max({l[i], r[i], 0}), a[i]);
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 3888
def main():
    import sys
    sys.setrecursionlimit(10**9)
    input = sys.stdin.readline
    from heapq import heappush, heappop

    N, M = map(int, input().split())
    AB = [ [] for _ in range(100000) ]

    for _ in range(N):
        a, b = map(int, input().split())
        AB[a-1].append(-b)

    ans = 0
    heap = []
    for a in range(M):
        for b in AB[a]:
            heappush(heap, b)
        if heap:
            ans -= heappop(heap)
    
    print(ans)

main()


Measured memory_bytes: 21992
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
	int n,x,y,s1=0,s2=0;
	cin>>n>>x>>y;
	
	s1=n*x;
	s2=y;
	
	if(s1>s2)
	   cout<<s2<<endl;
	else if(s1<s2)
	   cout<<s1<<endl;
	else
	   cout<<s1<<endl;
	
	return 0;
}
    

Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int i,N,L[11],max=0,sum=0;
  scanf("%d",&N);
  for(i=0;i<N;i++){
    scanf("%d",&L[i]);
    if(max<L[i])max=L[i];
  }
  for(i=0;i<N;i++){
    sum+=L[i];
  }
  sum-=max;
  if(max<sum)printf("Yes\n");
  else printf("No\n");
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#include<time.h>
using namespace std;
long long k,i=0,n;
int main()
{
	ios::sync_with_stdio(0);
	cin>>k;
	if(k%2==0||k%5==0)
	{
		cout<<"-1";
		return 0;
	}
	while(i<=1000000)
	{
		i++;
		n=(n*10+7)%k;
		if(n==0)
		{
			cout<<i;
			return 0;
		}
	}
	cout<<"-1";
	return 0;
}

Measured memory_bytes: 3512
using System;
using System.Linq;
using System.Collections.Generic;
class Program
{
    static void Main(string[] args)
    {
      string[] input = Console.ReadLine().Split();
      int n = int.Parse(input[0]);
      int k = int.Parse(input[1]);
      
      List<int> a = Console.ReadLine().Split().ToList().ConvertAll(x => int.Parse(x));
      
      //Dictionary<int, int> d = new Dictionary<int,int>();
      int[] b = new int[200001];
      
      foreach (int i in a)
      {
        b[i]+=1;
      }
      List<int> b_2=b.ToList().OrderBy(x => -x).ToList();
      int ans = 0;
      for (int i=0;i<k;i++){
        ans+=b_2[i];
      }
      
      Console.WriteLine(n-ans);
    }
}


Measured memory_bytes: 49080
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(a) sort(a.begin(), a.end())
#define Reverse(a) reverse(a.begin(), a.end())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define Ans(f, y, n) if(f) cout << y << endl; else cout << n << endl;
#define int long long
#define INF 1000000000000000000
using namespace std;

using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;

template<typename T>
void readv(vector<T> &a){ REP(i, a.size()) cin >> a[i]; }
void readi(vector<int> &a){ REP(i, a.size()){cin >> a[i]; a[i]--;} }
template<typename T>
void debug(vector<vector<T>> m){ REP(i, m.size()){ REP(j, m[i].size()){ cout << m[i][j] << ","; } cout << endl;} }



signed main(){

    int X; cin >> X;
    int K; cin >> K;
    vec r(K + 2);
    r[0] = 0;
    REP(i, K) cin >> r[i + 1];
    r[K + 1] = INF;
    int Q; cin >> Q;
    vec t(Q), a(Q);
    REP(i, Q) cin >> t[i] >> a[i];

    int A = 0, B = X, C = 0;

    int i0 = 0;
    REP(i, K + 1){

        while(i0 < Q && t[i0] < r[i + 1]){
            int ans;
            if(a[i0] <= A) ans = A + C;
            else if(a[i0] >= B) ans = B + C;
            else ans = a[i0] + C;
            if(i % 2 == 0) ans -= t[i0] - r[i];
            else ans += t[i0] - r[i];
            Max(ans, 0LL);
            Min(ans, X);
            cout << ans << endl;
            i0++;
        }

        int dt = r[i + 1] - r[i];
        if(i % 2 == 0){
            if(A + C >= dt) C -= dt;
            else if(B + C <= dt){
                A = 0;
                B = 0;
                C = 0; 
            }else{
                A = dt - C;
                C -= dt;
            }
        }else{
            if(B + C + dt <= X) C += dt;
            else if(A + C + dt >= X){
                A = 0;
                B = 0;
                C = X;
            }else{
                B = X - dt - C;
                C += dt;
            }
        }
    }
    
    return 0;
}

Measured memory_bytes: 3584
#include<iostream>
#include<math.h>
#include<vector>
#include<array>
#include<algorithm>
#include<numeric>
#include<map>
#include<queue>
#include<deque>
#include<set>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vector<ll>> mat;

int main(){
    int N;cin>>N;
    vec A(100010);
    for(int i=0;i<N;i++){
        cin>>A[i];
    }
    deque<ll> dq;
    dq.push_back(A[0]);
    for(int i=1;i<N;i++){
        if(dq[dq.size()-1]<A[i]){
            dq[dq.size()-1]=A[i];
        }
        else if(A[i]<=dq[0]){
            dq.push_front(A[i]);
        }
        else{
            auto itr=lower_bound(dq.begin(),dq.end(),A[i]);
            itr--;
            *itr=A[i];
        }
    }
    cout<<dq.size()<<endl;
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <tuple>
//#include <string>
#include <vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long
using namespace std;

typedef tuple<ll, ll, ll > ituple;

int N;
ll A[100005];
ll B[100005];
ll C[100005];
vector<ituple> y;

int main() {
	cin >> N;
	rep(i, N) {
		cin >> A[i] >> B[i];
		C[i] = A[i] + B[i];
	}
	rep(i, N) {
		auto x = make_tuple (C[i], A[i], B[i]);
		y.push_back(x);
	}

	sort(y.rbegin(), y.rend());
	/*/
	rep(i, N) {
		cout << get<0>(y[i]) <<" " <<get<1>(y[i]) <<" " <<get<2>(y[i]) ;
		cout << endl;
	}
	//*/
	ll ans = 0;

	rep(i, N) {
		if (i % 2 == 0) ans += get<1>(y[i]);
		else ans -= get<2>(y[i]);
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 7156
def log2(n):
    i = 1
    r = 0
    if n < 0:
        i = 2
        r = 1
        n = -n
    s = i
    while n > s:
        i *= 4
        s += i
        r += 2
    return r


def resolve():
    n = int(input())
    if n == 0:
        print(0)
        return
    ans = [0] * 40
    while n:
        l = log2(n)
        ans[l] += 1
        n = n - (-2) ** l
    while ans[-1] == 0:
        ans.pop()
    print("".join([str(x) for x in ans[::-1]]))


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define debug(x) cerr << #x << ": " << x << '\n';
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = (int)1e9;
const int MOD = (int)1e9 + 7;

int main(void){
    int L, R;
    cin >> L >> R;

    if(R - L + 1 >= 2019){
        cout << 0 << '\n';
        return 0;
    }

    int res = INF;
    for(int i = L; i < R; i++){
        for(int j = i+1; j <= R; j++){
            ll x = (i%2019) * (j%2019);
            x %= (ll)2019;
            res = min(res, (int)x);
        }
    }

    cout << res << '\n';

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
// iostream is too mainstream
#include <cstdio>
// bitch please
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <cmath>
#include <iomanip>
#include <time.h>
#define dibs reserve
#define OVER9000 1234567890
#define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++)
#define tisic 47
#define soclose 1e-8
#define chocolate win
// so much chocolate
#define patkan 9
#define ff first
#define ss second
#define abs(x) (((x) < 0)?-(x):(x))
#define uint unsigned int
#define dbl long double
#define pi 3.14159265358979323846
using namespace std;
// mylittledoge

using cat = long long;

#ifdef DONLINE_JUDGE
	// palindromic tree is better than splay tree!
	#define lld I64d
#endif

int main() {
	cin.sync_with_stdio(0);
	cin.tie(0);
	cout << fixed << setprecision(10);
	int N;
	cin >> N;
	vector<int> A(N), B(N);
	for(int i = 0; i < N; i++) cin >> A[i];
	for(int i = 0; i < N; i++) cin >> B[i];
	queue<int> loc_max;
	for(int i = 0; i < N; i++) {
		int l = (i+N-1)%N, r = (i+1)%N;
		if(B[i] > B[l] && B[i] > B[r] && A[i] != B[i]) loc_max.push(i);
	}
	cat ans = 0;
	while(!loc_max.empty()) {
		int id = loc_max.front();
		loc_max.pop();
		if(B[id] == A[id]) continue;
		if(B[id] < A[id]) {
			cout << "-1\n";
			return 0;
		}
		int l = (id+N-1)%N, r = (id+1)%N;
		if(B[l] >= B[id] || B[r] >= B[id]) continue;
		int m = max(B[l], B[r]);
		int k = (B[id]-m) / (B[l]+B[r]);
		int x = B[id]-k*(B[l]+B[r]);
		if(x > m) x -= B[l]+B[r], k++;
		if(x < A[id]) {
			if((B[id]-A[id])%(B[l]+B[r]) != 0) {
				cout << "-1\n";
				return 0;
			}
			x = A[id];
			k = (B[id]-A[id]) / (B[l]+B[r]);
		}
		B[id] = x;
		ans += k;
		int ll = (id+N-2)%N, lr = id;
		if(B[l] > B[ll] && B[l] > B[lr]) loc_max.push(l);
		int rr = (id+2)%N, rl = id;
		if(B[r] > B[rl] && B[r] > B[rr]) loc_max.push(r);
	}
	for(int i = 0; i < N; i++) if(A[i] != B[i]) {
		cout << "-1\n";
		return 0;
	}
	cout << ans << "\n";
	return 0;
}

// look at my code
// my code is amazing


Measured memory_bytes: 2304
#include <cstdio>
#include <vector>
#include <cstring>
#define mod 1000000007
using namespace std;
typedef long long ll;
int n,m;
int a[100001],b[100001];
vector<int> G[100001];
int group[100001];
int gcnt[100001];

void dfs(int v,int cnt){
	group[v]=cnt;
	gcnt[cnt]++;
	for(int i=0;i<G[v].size();i++){
		if(group[G[v][i]]==-1)dfs(G[v][i],cnt);
	}
}

int main(void){
	while(1){
		scanf("%d %d",&n,&m);
		if(n+m==0)break;
		for(int i=0;i<n;i++){
			G[i].clear();
		}
		for(int i=0;i<m;i++){
			scanf("%d %d",&a[i],&b[i]);
			a[i]--;
			b[i]--;
			G[a[i]].push_back(b[i]);
			G[b[i]].push_back(a[i]);
		}
		memset(gcnt,0,sizeof(gcnt));
		memset(group,-1,sizeof(group));
		int cnt=0;
		for(int i=0;i<n;i++){
			if(group[i]==-1){
				dfs(i,cnt++);
			}
		}
		ll res=1;
		bool flag=false;
		for(int i=0;i<cnt;i++){
			if(gcnt[i]>1){
				flag=true;
			}
			res=(ll)res*2%mod;
		}
		if(flag)res=(res+1)%mod;
		printf("%lld\n",res);
	}
	return 0;
}

Measured memory_bytes: 9276
N,Y = map(int,input().split())
Y = Y//1000
flag = False

for i in range(N+1):
    for j in range(N+1-i):
        if 10*i+5*j+(N-i-j) == Y:
            print(i,j,N-i-j)
            flag = True
            break
    if flag:
        break

if flag is False:
    print(-1,-1,-1)

Measured memory_bytes: 40684
x,n = gets.chomp.split.map(&:to_i)
ps = gets.chomp.split.map(&:to_i)

ans = -1

xp = x
xm = x
while xp <= 101 && xm >= -1
  if ps.count(xm) == 0
    ans = xm
    break
  elsif ps.count(xp) == 0
    ans = xp
    break
  end
  xp += 1
  xm -= 1
end

puts ans

Measured memory_bytes: 14320
# -*- coding: utf-8 -*-
from collections import defaultdict
import sys

sys.setrecursionlimit(1000000)

def set_distance(t, l, now, prev, pos):
    d = l[now][pos]

    for child in t[now]:
        if child == prev:
            continue
        l[child][pos] = d+1
        set_distance(t, l, child, now, pos)


n = int(input())
t = defaultdict(list)
for _ in range(n-1):
    a, b = map(lambda x: int(x) - 1, input().split())
    t[a].append(b)
    t[b].append(a)

# distance [fennec, snuke]
l = [[n, n] for _ in range(n)]
l[0][0] = 0
l[n-1][1] = 0

set_distance(t, l, 0, -1, 0)
set_distance(t, l, n-1, -1, 1)

f, s = 0, 0
for df, ds in l:
    if df <= ds:
        f += 1
    else:
        s += 1

if f > s:
    print('Fennec')
else:
    print('Snuke')


Measured memory_bytes: 133320
#include <bits/stdc++.h>
#include <string>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
using namespace std;

int my_abs(int num){
   if (num > 0)
      return num;
   else
      return -num;
}

int main(){
    string A,B;
    string ans = "EQUAL";
    cin >> A >> B;
    if(A.size() > B .size()){
        ans = "GREATER";
    }
    if(A.size() < B .size()){
        ans = "LESS";
    }
    if(A.size() == B.size()){
        for(int i = 0;i<A.size();i++){
            if(A.at(i)>B.at(i)){
                ans = "GREATER";
                break;
                
            }
            else if(A.at(i) < B.at(i)){
                ans = "LESS";
                break;
            }
        }
    }

    cout << ans << endl;

}


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

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	vector<int> certo(n), p(n), q(n);
	for(int i = 1; i <= n; i++){
		certo[i-1] = i;
		cin >> p[i-1];
	}	
	for(int i = 0; i < n; i++){
		cin >> q[i];
	}
	int cnt = 1;
	int a = 0, b = 0;
	do{
		bool flag = true;
		for(int i = 0; i < n; i++){
			 if(certo[i] != p[i]){
			 	flag = false;
			 	break;
			 }
		}
		if(flag) a = cnt;
		flag = true;
		for(int i = 0; i < n; i++){
			 if(certo[i] != q[i]){
			 	flag = false;
			 	break;
			 }
		}
		if(flag) b = cnt;
		cnt++;
	}while(next_permutation(certo.begin(), certo.end()));
	cout << abs(a-b) << endl;
	return 0;
} 

Measured memory_bytes: 256
let () = Scanf.scanf "%d %d\n%s\n" @@ fun n k s ->
  let seqs =
    Array.of_list @@ List.rev @@
    match
      (* 1111 0000 *)
      Array.fold_left (fun (acc, s) c ->
        match s, c with
        | `Ones n, '1' -> (acc, `Ones (n + 1))
        | `Zeros (n, m), '0' -> (acc, `Zeros (n, m + 1))
        | `Ones n, '0' -> (acc, `Zeros (n, 1))
        | `Zeros (n, m), '1' -> ((n, m) :: acc, `Ones 1)) ([], `Ones 0) @@
      Array.init (String.length s) (String.get s)
    with
    | (acc, `Ones n) -> (n, 0) :: acc
    | (acc, `Zeros (n, m)) -> (n, m) :: acc in
  if Array.length seqs <= k
  then Printf.printf "%d\n" n
  else begin
    let acc = Array.make (Array.length seqs + 1) 0 in
    for i = 0 to Array.length seqs - 1 do
      acc.(i + 1) <- acc.(i) + fst seqs.(i) + snd seqs.(i)
    done;
    Printf.printf "%d\n" @@
    Array.fold_left max (acc.(Array.length seqs) - acc.(Array.length seqs - k)) @@
    Array.init (Array.length seqs - k) @@ fun i ->
      acc.(i + k) - acc.(i) + fst seqs.(i + k)
  end

Measured memory_bytes: 8576
from operator import itemgetter
inf = float('inf')

n,m = map(int, input().split())
a = [list(map(int, input().split())) for i in range(m)]

a.sort(key=itemgetter(2))
a.sort(key=itemgetter(1))
a.sort(key=itemgetter(0))

d = [inf]*(n+1)
d[1]=0
for i in range(m):
    l,r,c = a[i]
    if d[l]==inf:
        print(-1)
        exit()
    for j in range(r-l):
        if d[r-j]>d[l]+c:
            d[r-j]=d[l]+c
        else:
            break
print(d[n]if d[n]!=inf else -1)

Measured memory_bytes: 102360
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b)  for(int i=(a),i##formax=(b);i< i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formin=(b);i>=i##formin;i--)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max((x),(y))
#define mins(x,y) x=min((x),(y))
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define all(a) ((a).begin()),((a).end())
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define bit(n) (1LL<<(n))
typedef long long ll;
typedef __int128_t lll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>using P=pair<T,Y>;
template<class T,class Y>ostream& operator<<(ostream&o,P<T,Y>&p){return o<<"("<<p.fi<<","<<p.se<<")";}
template<class T>ostream& operator<<(ostream&o,V<T>&v){for(T&t:v)o<<t<<",";return o;}
template<class T>void uniq(V<T>&v){sort(all(v));v.erase(unique(all(v)), v.end());}
template<class A,size_t N,class T>void Fill(A(&a)[N],const T&v){fill((T*)a,(T*)(a+N),v);}

const int MOD = 1e9+7; //998244353;

lll gcd(lll a,lll b,lll&x,lll&y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll modInv(ll a,ll m=MOD){lll x,y;gcd(a,m,x,y);return(x%m+m)%m;}
ll modPow(lll a,lll n,ll m=MOD){lll p=1;for(;n;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return p;}
//V<ll>Fac,Rac;void setF(int n,int m=MOD){Fac=Rac=V<ll>(++n);Fac[0]=1;FOR(i,1,n)Fac[i]=Fac[i-1]*i%m;Rac[n-1]=modInv(Fac[n-1],m);FORR(i,n-1,1)Rac[i-1]=Rac[i]*i%m;}
//ll comb(int a,int b,int m=MOD){return a<b||b<0?0:Fac[a]*Rac[b]%m*Rac[a-b]%m;}

const int IINF = 1e9+6;
const ll LINF = 1e18;
const int N = 1e5;
int n, r;
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> r;
  cout << r + max(0, 100*(10-n)) << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner scr = new Scanner(System.in);
		while (true) {
			String[] ss = scr.nextLine().split(" ", 0);
			stage_size = new int[2];
			stage_size[0] = Integer.parseInt(ss[0]);
			stage_size[1] = Integer.parseInt(ss[1]);
			if (stage_size[0] == 0)
				break;
			stage = new int[stage_size[0]][stage_size[1]];
			visited = new boolean[stage_size[0]][stage_size[1]];
			for (int y = 0; y < stage_size[1]; y++) {
				String[] data = scr.nextLine().split(" ", 0);
				for (int x = 0; x < data.length; x++) {
					stage[x][y] = Integer.parseInt(data[x]);
					visited[x][y] = false;
				}
			}
			System.out.println(Islands());
		}
		scr.close();
	}

	static int[] stage_size;
	static int[][] stage;
	static boolean[][] visited;

	private static int Islands() {
		int islands = 0;
		for (int x = 0; x < stage.length; x++) {
			for (int y = 0; y < stage[x].length; y++) {
				if (visited[x][y] || stage[x][y] == 0)
					continue;
				else {
					Visit(x, y);
					islands++;
				}
			}
		}
		return islands;
	}

	private static void Visit(int x, int y) {
		if (x >= stage.length || y >= stage[0].length || x < 0 || y < 0 || stage[x][y] == 0 ||visited[x][y])
			return;
		if (stage[x][y] == 1) {
			visited[x][y] = true;
			Visit(x + 1, y);
			Visit(x, y + 1);
			Visit(x + 1, y + 1);
			Visit(x + 1, y - 1);
			Visit(x - 1, y);
			Visit(x, y - 1);
			Visit(x - 1, y + 1);
			Visit(x - 1, y - 1);
		}
	}
}

Measured memory_bytes: 33776