akhauriyash/Code-Regression huggingface dataset:
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>

using namespace std;

const int N = 1000 + 5;
const int inf = (int)1e9;

int n, id[N][N], vis[N * N / 2], d[N * N / 2];
deque<int> q[N];
vector<int> G[N * N / 2];
int lst[N];

void upd(int x, int idx) {
  G[lst[x]].push_back(idx);
  lst[x] = idx;
}
int dfs(int x) {
  if(vis[x] == -1) return inf;
  if(vis[x] == 1) return d[x];
  vis[x] = -1;
  d[x] = 0;
  for(auto i : G[x]) {
    int vv = dfs(i);
    if(vv >= inf) return inf;
    d[x] = max(d[x], vv + 1);
  }
  vis[x] = 1;
  return d[x];
}

void init() {
  cin >> n;
  for(int i = 1 ; i <= n ; ++i) {
    for(int j = 0 ; j < n - 1 ; ++j) {
      int a; cin >> a; q[i].push_back(a);
    }
  }
  int cc = 1;
  for(int i = 1 ; i <= n ; ++i) {
    for(int j = i + 1 ; j <= n ; ++j) {
      id[i][j] = id[j][i] = cc++;
    }
  }
}
void solve() {
  for(int i = 1 ; i <= n ; ++i) lst[i] = 0;
  set<int> ss;
  for(int i = 1 ; i <= n ; ++i) ss.insert(i);
  while(!ss.empty()) {
    bool prg = false;
    for(auto i : ss) {
      if(q[i].empty()) continue;
      int j = q[i].front();
      if(q[j].empty()) { cout << "-1\n"; return; }
      if(q[j].front() == i) {
        prg = true;
        q[i].pop_front();
        q[j].pop_front();
        upd(i, id[i][j]);
        upd(j, id[i][j]);
        if(q[i].empty()) ss.erase(i);
        if(q[j].empty()) ss.erase(j);
        break;
      }
    }
    if(!prg) { cout << "-1\n"; return; }
  }


  int ans = dfs(0);
  if(ans >= inf) cout << "-1\n";
  else cout << ans << '\n';
}

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  init();
  solve();
}


Measured memory_bytes: 50560
#include <algorithm>
#include <bitset>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repk(i, k, n) for (int i = k; i < n; i++)
#define MOD 1000000007
#define INF 1e9
#define PIE 3.14159265358979323

template <class T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
T GCD(T a, T b) {
    if (b == 0)
        return a;
    else
        return GCD(b, a % b);
}
template <class T>
inline T LCM(T a, T b) {
    return (a * b) / GCD(a, b);
}

using namespace std;
//#inculude <bits/stdc++.h>
//#define int long long

template <class T>
class SegmentTree {
  private:
    int n = 1;
    vector<T> segtree;
    function<T(T, T)> operation;
    T ie;

    T _query(int a, int b, int k, int l, int r) {
        if (a >= r || b <= l)
            return ie;
        else if (a <= l && b >= r)
            return segtree[k];
        else {
            int vl = _query(a, b, 2 * k + 1, l, (l + r) / 2);
            int vr = _query(a, b, 2 * k + 2, (l + r) / 2, r);
            return operation(vl, vr);
        }
    }

  public:
    SegmentTree(vector<T> v, function<T(T, T)> _operation, T _ie) {
        operation = _operation;
        ie = _ie;
        while (v.size() > n)
            n *= 2;
        segtree.resize(2 * n - 1, ie);
        for (int i = 0; i < v.size(); i++)
            segtree[i + n - 1] = v[i];
        for (int i = n - 2; i >= 0; i--)
            segtree[i] = operation(segtree[2 * i + 1], segtree[2 * i + 2]);
    }

    T operator[](int i) {
        return segtree[i + n - 1];
    }

    void update(int i, T x) {
        i += n - 1;
        segtree[i] = x;
        while (i > 0) {
            i = (i - 1) / 2;
            segtree[i] = operation(segtree[2 * i + 1], segtree[2 * i + 2]);
        }
    }

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

signed main() {
    int n, q, com, x, y;
    cin >> n >> q;
    vector<int> v(n, 0);
    auto f = [](int a, int b) -> int { return a+b; };
    int e = 0;
    SegmentTree<int> s(v, f, e);
    rep(i, q) {
        cin >> com >> x >> y;
        x--;
        if (com == 0)
            s.update(x, y+s[x]);
        else
            cout << s.query(x, y) << endl;
    }
    return 0;
}


Measured memory_bytes: 4760
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a, b;
		a = sc.nextInt();
		b = sc.nextInt();
		if (a * b % 2 == 0) {
			System.out.println("Even");
		}
		else {
			System.out.println("Odd");
		}
	}

}


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

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

void solve() {
  int n;
  string s;
  cin >> n >> s;
  vector<char> v;
  v.push_back(s[0]);
  for (int i = 1; i < n; i++) {
    if (v[v.size() - 1] != s[i]) v.push_back(s[i]);
  }
  cout << v.size() << endl;
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);

  solve();
  return 0;
}


Measured memory_bytes: 592
//INCLUDE
//------------------------------------------
#include <iostream>
#include <functional>
#include <algorithm>
#include <math.h>
#include <iomanip>
#include <string>
#include <cstring>
#include <vector>
//DEFINE
//------------------------------------------
#define ll long long
#define ALLv(a)  (a).begin(),(a).end()
#define ALL(a,n)  (a),(a)+n
#define vi vector<long long>
#define vd vector<long double>
#define vs vector<string>
//CONST
//------------------------------------------
#define INF 1010000000000000017LL
#define MOD 1000000007LL
#define EPS 1e-12
#define PI 3.14159265358979323846
//REPEAT
//------------------------------------------
#define   FOR(i,m,n) for(ll (i)=(m);   (i)<(n);  (i)++)
#define   REP(i,n)   for(ll (i)=0;     (i)<(n);  (i)++)
#define  REPS(i,x)   for(ll (i)=1;     (i)<=(x); (i)++)
#define  RREP(i,x)   for(ll (i)=(x)-1; (i)>=0;   (i)--)
#define RREPS(i,x)   for(ll (i)=(x);   (i)> 0;   (i)--)
#define  WREP(i,in,j,jn) REP(i,in)REP(j,jn)
using namespace std;
//-------------------------------------------

int main(void){
  ll A,B;cin>>A>>B;
  bool flag=false;ll tmp;
  REP(i,1009){
  	if(int(i*0.08)==A&&int(i*0.1)==B){
  		flag=true;
  		tmp=i;
  		break;
  	}
  }
  if(flag)cout<<tmp<<endl;
  else cout<<"-1"<<endl;
  return 0;
}

Measured memory_bytes: 256
n = int(input())
x = [format(i, '015b') for i in range(2**n)]
y = []
for _ in range(n):
    z = []
    for _ in range(int(input())):
        a, b = map(int, input().split())
        z.append([a, b])
    y.append(z)
ans = 0
for i in range(2**n):
    flag = True
    for j in range(n):
        if x[i][-j - 1] == '1':
            for k in range(len(y[j])):
                if y[j][k][1] == 1 and x[i][-(y[j][k][0])] == '0':
                    flag = False
                elif y[j][k][1] == 0 and x[i][-(y[j][k][0])] == '1':
                    flag = False
    if flag:
        ans = max(ans, x[i].count('1'))
print(ans)


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

int main(){
    vector<int> s{1,1,1,2,1,2,1,5,2,2,1,5,1,2,1,14,1,5,1,5,2,2,1,15,2,2,5,4,1,4,1,51};
    int k;
    cin >> k;
    cout << s.at(k-1) << endl;
}

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

int main(void){
    string s;
    int i;
    int cnt;
    bool judge = true;
    
    cin >> s;
    
    for(char c = 'a'; c <= 'z'; c++){
        cnt = 0;
        for(i = 0; i < s.length(); i++){
            if(c == s[i])       cnt++;
        }
        if(cnt % 2 != 0){
            judge = false;
            break;
        }
    }
    
    if(judge)       cout << "Yes" << endl;
    else            cout << "No" << endl;
    
    return 0;
}

Measured memory_bytes: 256
//#define NDEBUG
#include <cstddef>
#include <cstdint>
#include <vector>

using i8 = ::std::int_least8_t;
using i32 = ::std::int_least32_t;
using i64 = ::std::int_least64_t;
using u8 = ::std::uint_least8_t;
using u32 = ::std::uint_least32_t;
using u64 = ::std::uint_least64_t;
using isize = ::std::ptrdiff_t;
using usize = ::std::size_t;

template <class T = usize> class rep {
	const T f, l;

public:
	class itr {
		friend rep;
		T i;
		itr(T x) noexcept : i(x) {}

	public:
		void operator++() noexcept { ++i; }
		T operator*() const noexcept { return i; }
		bool operator!=(const itr x) const noexcept { return i != x.i; }
	};
	rep(const T first, const T last) noexcept : f(first), l(last) {}
	itr begin() const noexcept { return itr(f); }
	itr end() const noexcept { return itr(l); }
};
template <class T = usize> class revrep {
	const T f, l;

public:
	class itr {
		friend revrep;
		T i;
		itr(T x) noexcept : i(x) {}

	public:
		void operator++() noexcept { --i; }
		T operator*() const noexcept { return i; }
		bool operator!=(const itr x) const noexcept { return i != x.i; }
	};
	revrep(const T first, const T last) noexcept : f(first), l(last) {}
	itr begin() const noexcept { return itr(l - 1); }
	itr end() const noexcept { return itr(f - 1); }
};
template <class T> bool maxi(T &a, const T &b) {
	return a <= b ? (a = b, 1) : 0;
}
template <class T> bool mini(T &a, const T &b) {
	return b <= a ? (a = b, 1) : 0;
}
template <class T> bool smaxi(T &a, const T &b) {
	return b <= a ? 0 : (a = b, 1);
}
template <class T> bool smini(T &a, const T &b) {
	return a <= b ? 0 : (a = b, 1);
}
template <class T> using vec_alias = ::std::vector<T>;
template <class T> auto md_vec(usize n, const T &value) {
	return ::std::vector<T>(n, value);
}
template <class... Args> auto md_vec(usize n, Args... args) {
	return ::std::vector<decltype(md_vec(args...))>(n, md_vec(args...));
}
template <class T> const T &as_const(const T &v) noexcept { return v; }

#include <utility>

template <class T> T gcd(T m, T n) {
	while (m %= n)
		::std::swap(m, n);
	return n;
}


#include <algorithm>
#include <iostream>
#include <utility>
#include <string>

int main() {
	usize n, m;
	::std::cin >> n >> m;
	::std::string s, t;
	::std::cin >> s >> t;
	const usize g = gcd(n, m);
	for (const auto i : rep<>(0, g)) {
		if (s[n / g*i] != t[m / g*i])
			return ::std::cout << "-1" << ::std::endl, 0;
	}
	::std::cout << n / g*m << ::std::endl;
	return 0;
}


Measured memory_bytes: 512
#include "bits/stdc++.h"
#define _USE_MATH_DEFINES
#include <math.h>
 
using namespace std;
 
using LL = long long;
using VLL = std::vector<LL>;
using VVLL = std::vector<VLL>;
using VVVLL = std::vector<VVLL>;
using LD = long double;
using VLD = std::vector<LD>;
using VVLD = std::vector<VLD>;
using VVVLD = std::vector<VVLD>;
 
template<class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; }return false; }

//template<class T=LL> inline vector<T> cinv(LL N){ vector<T> v(N); REP(i, N)cin>>v[i]; return move(v);}
//template<class T=LL> inline vector<T> cinv(LL N){ vector<T> v(N); REP(i, N)cin>>v[i]; return move(v);}
#define REP(i,n) for(LL (i)=0;(i)<(n);(i)++)
#define ALL(v) v.begin(), v.end()
#define PRINTLN(v) {LL i=0; for(auto (a): v ){   cerr <<i << " : "<<  a << endl; i++;}}
#define PRINTSP(v) for(auto (a): v ) {cerr << a << " ";} cerr << endl
#define cmax(a,b) {if(a<b){a=b;}}
#define cmin(a,b) {if(a>b){a=b;}}
#define EACH(a,A) for(auto a: A)
//#define cmax(a,b) a = (a>b ? a:b)
//#define cmin(a,b) a = (a<b ? a:b) 
//cin,cout高速化のおまじない＋桁数指定
inline VLL cinvll(LL N){
  VLL A(N);
  REP(i,N){
    cin >> A[i];
  }
  return move(A);
}
struct Fast{
	Fast(){
		cin.tie(0);
		ios::sync_with_stdio(false);
		cout << fixed << setprecision(std::numeric_limits<double>::max_digits10);
	}
} fast;

LL nCr(LL n, LL r) {
  LL num = 1;
  for (LL i = 1; i <= r; i++) {
    num = num * (n - i + 1) / i;
  }
  return num;
}


void func(){
  LL N;
  cin >> N;
  auto A = cinvll(N);

  VVLL dp(N+1,VLL(N+1,0));

  for(LL len =1; len<=N;len++){
    for(LL i=0; i+len<=N;i++){
      LL j=i+len;
      if((N-len)%2==0){
        dp[i][j] = max(dp[i+1][j]+A[i],dp[i][j-1]+A[j-1]);
      }
      else{
        dp[i][j] = min(dp[i+1][j]-A[i],dp[i][j-1]-A[j-1]);
      }
    }
  }
  cout << dp[0][N];

  


} 
int main()
{
  func();
  return 0;
}
 

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

using namespace std;

#define CVector CPoint
typedef long long LL;
typedef unsigned long long ULL;

const LL mod=1e9+7;
const double PI=acos(-1);
const double EPS=1e-6;
const int INF=0x3f3f3f3f;
inline int readint(){int sum=0;char c=getchar();bool f=0;while(c<'0'||c>'9'){if(c=='-') f=1;c=getchar();}while(c>='0'&&c<='9'){sum=sum*10+c-'0';c=getchar();}if(f) return -sum;return sum;}
inline LL readLL(){LL sum=0;char c=getchar();bool f=0;while(c<'0'||c>'9'){if(c=='-') f=1;c=getchar();}while(c>='0'&&c<='9'){sum=sum*10+c-'0';c=getchar();}if(f) return -sum;return sum;}

LL x[200005],sum[200005];
int main(){ios_base::sync_with_stdio(0);cin.tie(0);
    int n;
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>x[i];
        sum[i]=sum[i-1]+x[i];
    }
    LL mians=1e18;
    for(int i=1;i<=n-1;i++){
        LL tmp=(sum[n]-sum[i]-sum[i])>0? (sum[n]-sum[i]-sum[i]):-(sum[n]-sum[i]-sum[i]);
        mians=min(mians,tmp);
    }
    cout<<mians<<endl;
    return 0;
}

//cout.setf(ios::fixed);
//cout<<fixed<<setprecision(10)<<s<<endl;


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

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

using namespace std;
int main(){
	int n;
	cin >> n;

	cout << (800 * n) - (n / 15) * 200 << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;

template <class T>
inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

template <class T>
inline bool chmax(T &a, T b) {
  if (a <= b) {
    a = b;
    return true;
  }
  return false;
}

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

  vector<int> H(N);
  rep(i, N) cin >> H[i];

  int ans = 0;
  int max_H = 0;
  rep(i, N) { ans += chmax(max_H, H[i]); }
  cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;


public class Main {

    public static void main(String[] args) {

        Scanner input = new Scanner(System.in);
        int a = input.nextInt();


   int c = a/500;
   int b = a%500;
   int remainder = b%5;


       System.out.println(1000*c+(b-remainder));

    }



}

Measured memory_bytes: 23636
#include <cstdio>
#include <algorithm>
#include <stack>
#include <queue>
#include <deque>
#include <vector>
#include <string>
#include <string.h>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <map>
#include <set>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <numeric>
#include <cctype>
#include <bitset>
#include <cassert>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(s) s.begin(), s.end()
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const int MX = 100005, INF = 1001001001;
const ll LINF = 1e18;
const double eps = 1e-10;
const int DIV = 1e9+7;

int n;
vi a;


int main(){

    cin >> n;
    a.resize(n);
    rep(i, n) cin >> a[i];

    ll x = a[0], y = 0;
    for(int i = 1; i < n; i++) y += a[i];
    ll ans = abs(x - y);

    for(int i = 1; i < n-1; i++){
        x += a[i];
        y -= a[i];
        if(ans > abs(x - y)) ans = abs(x - y);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1152
x_1,y_1,x_2,y_2=map(int,input().split())
a=x_2-x_1
b=y_2-y_1
x_3=x_2-b
y_3=y_2+a
x_4=x_3-y_3+y_2
y_4=y_3+x_3-x_2
print(x_3,y_3,x_4,y_4)

Measured memory_bytes: 3060
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
A2 = sorted(A)
B2 = sorted(B)
C2 = sorted(C)
A2.append(2000000000)
B2.append(2000000000)
def numadd(up, down):
    array = []
    count = 0
    for i in range(0,N):
        while down[i] > up[count]:
            count = count + 1
        array.append(count)
    return array

B3 = numadd(A2,B2)
C3 = numadd(B2,C2)
B4 = [B3[0]]
for i in range(0,N-1):
    B4.append(B4[i] + B3[i+1])
ans = 0
for i in range (0,N):
    if C3[i] > 0:
        ans = ans + B4[C3[i]-1]
print(ans)

Measured memory_bytes: 29816
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <iomanip>
#include <random>
#include <cassert>
#include <cstring>
using namespace std;

#define GET_ARG(a,b,c,F,...) F
#define REP3(i,s,e) for (i = s; i <= e; i++)
#define REP2(i,n) REP3 (i,0,(int)(n)-1)
#define REP(...) GET_ARG (__VA_ARGS__,REP3,REP2) (__VA_ARGS__)
#define RREP3(i,s,e) for (i = s; i >= e; i--)
#define RREP2(i,n) RREP3 (i,(int)(n)-1,0)
#define RREP(...) GET_ARG (__VA_ARGS__,RREP3,RREP2) (__VA_ARGS__)
#define DEBUG(x) cerr << #x ": " << x << endl

const int MOD = 1e9+7;

int main(void) {
    int i, j, k, n;
    cin >> n;
    string s[2];
    cin >> s[0] >> s[1];

    vector<int> tv;
    for (i = 0; i < n;) {
        if (i < n-1 && s[0][i] == s[0][i+1]) {
            tv.push_back(1);
            i += 2;
        }
        else {
            tv.push_back(0);
            i++;
        }
    }

    int x[3][2] = {{2,2},{1,3},{3,6}};

    long long ans = 1;
    int prev = 2;
    for (auto t: tv) {
        ans = ans * x[prev][t] % MOD;
        prev = t;
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

using ull = unsigned long long;
using ll = long long;

#define READ freopen("input.txt", "r", stdin)
#define ROUT freopen("output.txt", "w", stdout)
#define pb push_back
#define endl '\n'

void fasterIO()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
}

///(Moan) ey (hoe) pakhi jeno (Oral) dibe <3

void fuck()
{
    int n, i, a=0, b=0;
    cin>>n;
    int d[n];
    for(i=0; i<n; i++){
        cin>>d[i];
    }
    if(n%2!=0)
        cout<<0<<endl;
    else{
        sort(d,d+n);
        for(i=0; i<n; i++){
            if(d[i]<d[n/2])
                a++;
            else
                b++;
        }
        if(a!=b)
            cout<<0<<endl;
        else
            cout<<d[n/2]-d[n/2-1]<<endl;
    }
}

int main()

{
    //READ;
    //ROUT;
    fasterIO();

    fuck();

    return 0;
}



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

#define debug(x) cout << #x << " = " << x << endl
#define fori(i, ini, lim) for(int i = int(ini); i < int(lim); i++)
#define ford(i, ini, lim) for(int i = int(ini); i >= int(lim); i--)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;

const int MAX = 1e3 + 5;
bool path[MAX][MAX], two_path[MAX][MAX];
int mark[MAX];
vector<int> adj[MAX];
int n, m;

void bfs(int start) {
	queue<int> q;
	q.push(start);
	path[start][start] = true;
	while(!q.empty()) {
		int cur = q.front(); q.pop();
		for(auto &each : adj[cur]) {
			if(!path[start][each]) {
				path[start][each] = true;
				q.push(each);
			}
		}
	}
}

void dfs(int node, int start, int first_malandro) {
	for(auto &each : adj[node]) {
		if(each != start && mark[each] == -1) {
			mark[each] = first_malandro;
			dfs(each, start, first_malandro);
		}
	}
}

void roll(int start) {
	memset(mark, -1, sizeof mark);

	for(auto &each : adj[start]) {
		if(mark[each] == -1) {
			mark[each] = each;
		}
		dfs(each, start, each);
	}

	for(auto &each : adj[start]) {
		if(mark[each] != -1 && mark[each] != each) {
			two_path[start][each] = true;
		}
	}

	memset(mark, -1, sizeof mark);

	ford(i, adj[start].size() - 1, 0) {
		int each = adj[start][i];
		if(mark[each] == -1) {
			mark[each] = each;
		}
		dfs(each, start, each);
	}

	for(auto &each : adj[start]) {
		if(mark[each] != -1 && mark[each] != each) {
			two_path[start][each] = true;
		}
	}
}

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

	vector<ii> edges;
	fori(i, 1, m + 1) {
		int a, b;
		scanf("%d %d", &a, &b);
		adj[a].push_back(b);

		edges.emplace_back(a, b);
	}

	fori(i, 1, n + 1) {
		bfs(i);
		roll(i);
	}

	for(auto &edge : edges) {
		int a, b;
		tie(a, b) = edge;

		if(path[a][b] && path[b][a]) { // same scc
			if(two_path[a][b]) {
				puts("same");
			}
			else {
				puts("diff");
			}
		}
		else {
			if(two_path[a][b]) {
				puts("diff");
			}
			else {
				puts("same");
			}
		}
	}

	return 0;
}


Measured memory_bytes: 6384
#include<stdio.h>

int main(){
	int i, j, H, W;
	while (1){
		scanf("%d %d", &H, &W);
		if (H == 0 && W == 0)break;
		for (i = 0; i < H; i++){
			for (j = 0; j < W; j++){
				printf("#");
			}
			printf("\n");
		}
		printf("\n");

	}
	return 0;
}


Measured memory_bytes: 2012
//#pragma GCC target("avx2")
//#pragma GCC optimize("O3")
 
//#include <x86intrin.h>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <string>
#include <bitset> 
#include <vector>
#include <cmath>
#include <deque>
#include <queue>
#include <iomanip>
#include <stack>
#include <map>
#include <set>
//#include <ordered_set>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
 
//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>;
     
#define F first
#define S second           
#define lb lower_bound               
#define ub upper_bound
#define pb push_back
#define pf push_front    
#define ppb pop_back
#define mp make_pair                                     
#define bpp __builtin_popcountll                                                                                        
#define sqr(x) ((x) * (x)) 
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define in insert
#define ppf pop_front
#define endl '\n'
//#define int long long
 
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
 
const int mod = (int)1e9 + 7;
const int N = (int)3e5 + 123;
const ll inf = (ll)1e18 + 1;
 
const double pi = acos (-1.0);
const double eps = 1e-9;                  
const int dx[] = {0, 0, 1, 0, -1};
const int dy[] = {0, 1, 0, -1, 0};

int n, a[N], b[N], ans;
    
inline void boost () {
   ios_base :: sync_with_stdio (0);
   cin.tie (0), cout.tie (0);
}
 
inline void Solve () {
   cin >> n;
   for (int i = 1; i <= n; i ++) cin >> a[i];
   for (int i = 1; i <= n; i ++) cin >> b[i];
   for (int B = 29; B >= 0; B --) {
      int cur = 0;
      for (int i = 1; i <= n; i ++) {
         int pos = lb (a + 1, a + n + 1, (1 << (B + 1)) + (1 << B) - b[i]) - a; 
         int pos2 = lb (a + 1, a + n + 1, (1 << (B + 1)) - b[i]) - a;
         if (pos < pos2) pos2 = pos - 1;
         int pos1 = lb (a + 1, a + n + 1, (1 << B) - b[i]) - a;
         if (pos1 <= pos2) cur += pos2 - pos1;
         cur += n - pos + 1;
         cur &= 1;
      }
      if (cur & 1) ans ^= (1 << B);
      for (int i = 1; i <= n; i ++) {
         if (a[i] & (1 << B))
            a[i] -= (1 << B);
         if (b[i] & (1 << B))
            b[i] -= (1 << B);
      }
      sort (a + 1, a + n + 1);
   }
   cout << ans;
}               
 
signed main () {                                       
  //#ifdef QWERTY
  //    freopen("input", "r", stdin);
   //#endif
// freopen (".in", "r", stdin);    
// freopen (".out", "w", stdout);              
   boost ();
   int tt = 1;
   //cin >> tt;   
   while (tt --) {
      Solve ();
   }                                               
   return 0;      
}      

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

int main(){
    //入力
    string S;
    cin >> S;

    //出力
    bitset<26> alphabet;

    for(int i=0;i<S.size();i++){
        alphabet.set(S.at(i)-'a');
    }

    for(int i=0;i<alphabet.size();i++){
        if(alphabet.test(i)==0){
            cout << (char)('a'+i) << endl;
            return 0;
        }
    }

    cout << "None" << endl;
    return 0;

}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
string s;
bool la=0,lb=0;
int main(){
	cin>>s;
	int l=s.size();
	for(int i=0;i<=l;i++){
		if(s[i]=='C')la=1;
		if(la==1&&s[i]=='F')lb=1;
	}
	if(la==1&&lb==1)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define p_b push_back
#define pl pair<ll,ll>
#define m_p make_pair
#define MOD 1000000007
#define F(i,a,b) for(i=a;i<b;i++)
#define RF(i,a,b) for(i=a;i>=b;i--)
#define nfs ios_base::sync_with_stdio(false);cin.tie(NULL)


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin >> n;

    ll i;
    ll arr[n];
    for(i=0;i<n-1;i++)
    {

        cin >> arr[i];
    }
    if(n==2)
    {

        cout << 2* arr[0] << endl;
        return 0;
    }
    ll ans = arr[0];
    ll cur = arr[0];
    for(i=1;i<n-1;i++)
    {

        if(arr[i]>cur)
        {

            ans += cur;
            cur = arr[i];
        }
        else
        {

            ans += arr[i];
            cur = arr[i];
        }

    }
    ans += arr[n-2];
    cout << ans << endl;



    return 0;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
# define  _deb(x) { cerr << "\033[94m"<< "[ " << #x << " = " << (x) << " ]\n\033[0m"; }
using namespace std;
#define int long long
signed main(){
	int n;
	cin >> n;
	vector<int>v(n);
	for(int i=0;i<n;i++){
		cin >> v[i];
	}
	sort(v.begin(),v.end());
	double ans = 0;

	ans = (v[0] + v[1]) / 2.0;

	if(n>2){
		for(int i=2;i<n;i++){
			ans = (ans + v[i])/2.0;
		}
	}
	printf("%0.10lf\n",ans);
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES 
#include <cmath>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<string>
#include<vector>
#define rep(i,start,n) for(int i=start;i<n;i++)
#define And &&
#define Or ||
#define Lb cout<<endl
using namespace std;

int main(void) {
	int n, m; cin >> n >> m;
	vector<vector<int> > a(n, vector<int>(m));
	vector<int> b(m);
	vector<int> c(n);
	//????????????
	rep(i, 0, n) {
		rep(j, 0, m) {
			cin >> a[i][j];
		}
	}
	
	rep(i, 0, m) {
		cin >> b[i];
	}

	rep(i, 0, n) {
		c[i] = 0;
		rep(j, 0, m) {
			c[i] += a[i][j] * b[j];
		}
	}

	rep(i, 0, n) {
		cout << c[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 1256
N = int(input())
a = list(map(int, input().split()))

a.sort()

a_1 = []
for i in range(N,3*N):
  a_1.append(a[i])

P = []
for i in range(2*N):
  if i%2 == 0:
    P.append(a_1[i])
    
print(sum(P))

Measured memory_bytes: 42668
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

vl factor(ll n) {
  vl res;
  for(ll i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      res.push_back(i);
      if(i != n / i) res.push_back(n / i);
    }
  }
  return res;
}

int main() {
  ll n, k;
  cin >> n >> k;
  vl a(n);
  ll sum = 0;
  rep(i, n) {
    cin >> a[i];
    sum += a[i];
  }
  vl f = factor(sum);
  sort(all(f), greater<ll>());
  for(auto v : f) {
    ll ms = 0;
    vl m(n);
    rep(i, n) {
      m[i] = a[i] % v;
      ms += m[i];
    }
    sort(all(m));
    ll cnt = n - ms / v;
    ll now = 0;
    rep(i, cnt) now += m[i];
    if(now > k) continue;
    cout << v << endl;
    return 0;
  }
}

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

typedef long long Int;


	long long int extgcd(long long int a, long long int b, long long int& x, long long int& y) {
		long long int d = a;
		if (b != 0) {
			d = extgcd(b, a%b, y, x);
			y -= (a / b)*x;
		}
		else {
			x = 1; y = 0;
		}
		return d;
	}


	long long int mod_inverse(long long int a, long long int m) {
		long long int x, y;
		extgcd(a, m, x, y);	//ax+my=1
		return (m + x%m) % m;	//return positive integer
	}


int main(){
  int n;
  cin>>n;
  vector<int> a(n);
  vector<int> inde(n,-1);
  int oth=0;
  for(int i=0;i<=n;i++){
    cin>>a[i];
    if(inde[a[i]-1]!=-1){
      oth=n+1-(i-inde[a[i]-1]-1)-2;
    }
    else{
      inde[a[i]-1]=i;
    }
  }

  const Int MOD=1e9+7;
  
  vector<Int> combn(n,1);
  vector<Int> combo(oth+1,1);
  
  for(int i=1;i<=n-1;i++){
    combn[i]=combn[i-1]*(n-i);
    combn[i]%=MOD;
    combn[i]*=mod_inverse(i,MOD);
    combn[i]%=MOD;

  }

  for(int i=1;i<=oth;i++){
    combo[i]=combo[i-1]*(oth-i+1);
    combo[i]%=MOD;
    combo[i]*=mod_inverse(i,MOD);
    combo[i]%=MOD;
  }

  
  
  
  for(int k=1;k<=n+1;k++){
    if(k==1){
      cout<<n<<endl;
    }
    else if(k<=n){
      Int res=0;
      if(k!=n) res+=combn[k];
      res%=MOD;
      res+=combn[k-1];
      res%=MOD;
      res+=combn[k-1];
      res%=MOD;
      if(oth>=k-1)res-=combo[k-1];
      res+=MOD;
      res%=MOD;
      res+=combn[k-2];
      res%=MOD;
      res+=MOD;
      res%=MOD;
      cout<<res<<endl;
    }
    else{
      if(k==n+1){
	cout<<1<<endl;
      }
    }
  }
  return 0;
}


Measured memory_bytes: 3584
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
	int n;
	while(cin>>n,n){
		int w,h;
		int X,Y;
		int ans=0;
		cin>>w>>h;
		int mp[101][101]={0};
		for(int i=0,x,y;i<n;i++){
			cin>>x>>y;
			mp[x][y]=1;
		}
		cin>>X>>Y;
		
		for(int i=1;i<=h-Y+1;i++){
			for(int j=1;j<=w-X+1;j++){
				int t=0;
				for(int k=i;k<i+Y;k++){
					for(int l=j;l<j+X;l++){
						if(mp[l][k])t++;
					}
				}
				//if(t==7)cout<<j<<" "<<i<<endl;
				ans=max(ans,t);
			}
		}
		
		cout<<ans<<endl;
	}
	return 0;
}


Measured memory_bytes: 1208
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
int main() {
  string A;
  cin >> A;
  int c = 0;
  rep(i, A.size() - 1) {
    if(A.at(i) == 'A' && A.at(i + 1) == 'C') {
      cout << "Yes" << endl;
      c++;
      break;
    }
  }
  if(c == 0) {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 3572
#include<bits/stdc++.h>
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define INF 1145141919
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)

using namespace std;

int gcd(int a,int b){
  int tmp,r;
  if(a<b){
    tmp=a;
    a=b;
    b=tmp;
  }
  r=a%b;
  while(r!=0){
    a=b;
    b=r;
    r=a%b;
  }
  return b;
}

int main(void){
  int N;
  cin >> N;
  int A[N];
  rep(i,N) cin >> A[i];
  int ans=gcd(A[0],A[1]);
  for(int i=1;i<N-1;i++){
    ans=gcd(ans,A[i+1]);
  }
  cout << ans << endl;
}

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


import heapq
def dijkstra(s, E):
    inf = float("inf")
    d = [inf for i in range(len(E))]
    d[s] = 0
    q = [(0, s)]
    while q:
        c, p = heapq.heappop(q)
        if d[p] < c:
            continue
        for cost, to in E[p]:
            if d[to] > d[p] + cost:
                d[to] = d[p] + cost
                heapq.heappush(q, (d[to], to))
    return d


def main():
    N, u, v = map(int, input().split())
    E = [[] for i in range(N)]
    for _ in range(N-1):
        a, b = map(int, input().split())
        E[a-1].append((1, b-1))
        E[b-1].append((1, a-1))
    du = dijkstra(u-1, E)
    dv = dijkstra(v-1, E)
    ans = 0
    for i, j in zip(du, dv):
        if i < j:
            ans = max(ans, j)
    print(ans - 1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 41964
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;

int main() {
    int n;
    while(cin >> n, n){
        array<int, 100000> v{};
        for (int i = 0; i < n; ++i) {
            int h1, m1, s1, h2, m2, s2;
            scanf("%d:%d:%d %d:%d:%d", &h1, &m1, &s1, &h2, &m2, &s2);
            int x = h1*3600+m1*60+s1, y = h2*3600+m2*60+s2;
            v[x]++; v[y]--;
        }
        for (int i = 1; i < 100000; ++i) {
            v[i] += v[i-1];
        }
        cout << *max_element(v.begin(),v.end()) << "\n";
    }
    return 0;
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define REP(i,n) for((i)=0;(i)<(int)(n);(i)++)

using namespace std;

int main(){
    long a,b;
    int ans;
    cin >> a>>b;
    if((a+b)%2==1){
        cout << "IMPOSSIBLE"<< endl;
    }
    else{
        cout << (a+b)/2<< endl;
    }
    
    return 0;
}



Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define mod 1000000007
#define FS fixed<<setprecision(15)
using namespace std;
typedef long long ll;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

const ll INF=1e18;

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    ll n,m;
    cin>>n>>m;
    V<ll> a(m);
    cinf(m,a);
    ll sum=0;
    rep(i,m) sum+=a[i];
    if(n-sum>=0) cout<<n-sum<<endl;
    else cout<<-1<<endl;
}
//ペナルティ出しても焦らない　ACできると信じろ！！！
/*
V,P(大文字)使用不可
乗算などの際にオーバーフローに注意せよ！
(適切にmodをとれ　にぶたんで途中で切り上げろ)
制約をよく読め！
(全探索できるなら全探索しろ)
stringの計算量(扱い)注意
コーナー注意！(特に数値が小さいものについては要検証)
N行出力のときは'\n'
グリッド上では行先が範囲内におさまるかif文で確認(RE注意)
if文ではちゃんと比較演算子==を使え(=でもエラー出ない)
配列(vector)の大きさが0か1以上かで場合分けせよ(RE注意)
(vector<int> a(m)でm==0というものはできない)
modはなるべく最後に取れ！
*/

Measured memory_bytes: 3692
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef pair<ll,ll> l_l;
typedef pair<int,int> i_i;
const ll MOD=1e9+7;
const int INF=1<<30;

const int MAX=200001;
ll fac[MAX],finv[MAX],inv[MAX];

void COMinit() {
  fac[0]=fac[1]=1;
  finv[0]=finv[1]=1;
  inv[1]=1;
  for (int i=2;i<MAX;i++){
    fac[i]=fac[i-1]*i%MOD;
    inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
    finv[i]=finv[i-1]*inv[i]%MOD;
  }
}

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

map<ll,ll> pfmp; //各素因数の指数を格納
vector<ll> pfv(0); //異なる素因数を列挙

void PF(ll N){
  ll n=N;
  if(n%2==0) pfv.push_back(2);
  while(n%2==0){
    n/=2;
    pfmp[2]++;
  }
  if(n==1) return;
  for(ll i=3;i<=sqrt(N);i+=2){
    if(n%i==0) pfv.push_back(i);
    while(n%i==0){
      n/=i;
      pfmp[i]++;
    }
  }
  if(n!=1){
    pfv.push_back(n);
    pfmp[n]++;
  } 
}

int main(){
  int N,M;
  cin >> N >> M;
  COMinit();
  PF(M);
  ll ans=1;
  rep(i,pfv.size()){
    ans=ans*COM(pfmp[pfv[i]]+N-1,N-1)%MOD;
  }
  cout << ans << endl;
}

Measured memory_bytes: 4992
n=int(input())
s=[]
t=[]
for i in range(n):
  a,b=input().split()
  s.append(a)
  t.append(int(b))
x=input()
k=0
ans=0
for i in range(n):
  if k==1:
    ans += t[i]
  if s[i]==x:
    k=1
print(ans)
  

Measured memory_bytes: 3060
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
using namespace std;
const long long int INF = 1e18;
const long long int mod = 1e9+7;
typedef pair<ll,ll> pairs;
typedef vector<pairs> p;


ll gcd(ll A,ll B){
    if (A%B==0)return(B);
    else return(gcd(B,A%B));
}

ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

vector<vector<ll>> combination(ll n, ll r){
    vector<vector<ll>> v(n + 1, vector<ll>(n + 1, 0));
    for(ll i=0;i<v.size();++i){
        v[i][0] = 1;
        v[i][i] = 1;
    }
    for(ll i=1;i<v.size();++i){
        for(ll j=0;j<i;++j){
            v[i][j] = (v[i - 1][j - 1] + v[i - 1][j]);
        }
    }
    return v;
}

bool kai(string S){
    bool flag = true;
    for(ll i=0;i<S.size()/2;++i){
        if(S[i] != S[S.size()-i-1]){
            flag = false;
            break;
        }
    }
    return flag;
}
// ---------------------------------------------

int main(){
    ll n;
    cin>>n;
    p a(n);
    for(ll i=0;i<n;++i){
        cin>>a[i].first>>a[i].second;
    }
    sort(a.begin(), a.end());
    ll ans = a[n-1].first + a[n-1].second;
    cout<<ans<<endl;

    return 0;
}

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

int main(void){
	ll A, B, C;
	cin >> A >> B >> C;
	ll c = 0;
	if (A==B && B==C && A%2 == 0) {
		cout << -1 << endl;
		return 0;
	}
	while (A%2 == 0 && B%2 == 0 && C%2 == 0){
		ll Ah = A/2;
		ll Bh = B/2;
		ll Ch = C/2;
		A = Bh + Ch;
		B = Ch + Ah;
		C = Ah + Bh;
		c++;
	}

	cout << c << endl;

	return 0;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int n,i = 0;
  cin >> n;
  ll max = 0,count = 0;
  vector<ll> h(n);
  for(int i = 0; i < n; i++) cin >> h.at(i);
  while(i < n-1) {
    count = 0;
    for(; i < n-1; i++) {
      if(h.at(i) < h.at(i+1)) break;
      count++;
    }
    if(count > max) max = count;
    i++;
  }
  cout << max << endl;
  return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>
#include<ctype.h>
#define MAX_WORDS 1200

int main(void){
    int i = 0;
    char str[MAX_WORDS];
    fgets(str, MAX_WORDS, stdin);
    while ( str[i] != '\0' ){
        if ( isalpha(str[i]) ){
            if ( islower(str[i]) ) {
                printf("%c", toupper(str[i]));
            } else if ( isupper(str[i]) ) {
                printf("%c", tolower(str[i]));
            }
        } else {
            printf("%c", str[i]);
        }
        i++;
    }
    return 0;
}


Measured memory_bytes: 2136
//29
#include<iostream>
#include<string>
#include<set>

using namespace std;

int main(){
  for(int h,w;cin>>h>>w,h|w;){
    char g[10][21];
    for(int i=0;i<h;i++){
      cin>>g[i];
    }
    set<string> s;
    string t;
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
	for(int k=-1;k<=1;k++){
	  for(int l=-1;l<=1;l++){
	    string c;
	    int y=i,x=j;
	    c=g[y][x];
	    for(;;){
	      if(!s.insert(c).second&&(t.size()<c.size()||(t.size()==c.size()&&c<t))){
		t=c;
	      }
	      y=(y+k+h)%h;
	      x=(x+l+w)%w;
	      if(y==i&&x==j)break;
	      c+=g[y][x];
	    }
	  }
	}
      }
    }
    if(t.size()>=2){
      cout<<t<<endl;
    }else{
      cout<<0<<endl;
    }
  }
  return 0;
}

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

int N;
string S;

int main(){
    cin >> N >> S;
    
    int mx = 100000;
    int count = 0;
    for(int i=0; i<N; i++){
        if(S[i] == '(')
            count++;
        else
            count--;
        
        mx = min(mx, count);
    }
    if(mx < 0){
        for(int i=0; i<-mx; i++)
            cout << '(';
        count += -mx;
    }
    cout << S;
    for(int i=0; i<count; i++)
        cout << ')';
    cout << endl;
}

Measured memory_bytes: 256
/// IN THE NAME OF METAL
#include <bits/stdc++.h>

using namespace std;

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

#define sz(x)                       (ll) x.size()
#define all(x)                      (x).begin(),(x).end()
#define F                           first
#define S                           second

ll Pow(ll a, ll b, ll md, ll ans = 1) {
    for (; b; b >>= 1, a = a * a % md)
        if (b & 1)
            ans = ans * a % md;
    return ans % md;
}

const ll MAXN = 1e6 + 10;
const ll INF = 8e18;
const ll MOD = 1e9 + 7;
vector<ll> adj[MAXN];
ll mark[MAXN], val[MAXN], ans[MAXN], mrk[MAXN], n, k;

void BFS() {
    priority_queue<pll> pq;
    for (ll i = 1; i <= n; i++) {
        if (mrk[i]) pq.push({val[i], i}), ans[i] = val[i];
    }
    while (sz(pq)) {
        ll v = pq.top().S; pq.pop();
        if (mark[v]) continue;
        mark[v] = 1;
        for (ll u : adj[v]) {
            if (mark[u]) continue;
            ans[u] = ans[v] - 1;
            pq.push({ans[u], u});
        }
    }
}

int main() {
    scanf("%lld", &n);
    for (ll i = 1; i <= n - 1; i++) {
        ll u, v;
        scanf("%lld%lld", &u, &v);
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    scanf("%lld", &k);
    for (ll i = 1, v, x; i <= k; i++) {
        scanf("%lld%lld", &v, &x);
        mrk[v] = 1, val[v] = x;
    }
    BFS();
    for (ll i = 1; i <= n; i++) {
        if (mrk[i] && val[i] != ans[i]) return !printf("No\n");
        for (ll v : adj[i]) {
            if (abs(ans[i] - ans[v]) != 1) return !printf("No\n");
        }
    }
    printf("Yes\n");
    for (ll i = 1; i <= n; i++) printf("%lld\n", ans[i]);
    return 0;
}



Measured memory_bytes: 45040
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
#include<stack>
#include<numeric>
#include<set>
#include<iomanip>
#include<map>
#include<type_traits>
#include<tuple>
#include<deque>
#include<cassert>
using namespace std;
typedef long long ll;
typedef pair<ll,int> p;
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
const int mod = 1000000007;
const int INF = 1001001001;

int main(){
  int n;
  cin >> n;
  vector<int> l(n);
  rep(i, n) cin >> l[i];
  sort(l.begin(), l.end());
  ll ans = 0;
  rep(a, n) {
    for(int b = a + 1; b < n; ++b) {
      int s = l[a] + l[b];
      int c = lower_bound(l.begin(), l.end(), s) - l.begin();
      --c;
      if(c > b) ans += c - b;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.Arrays;
import java.util.Comparator;

public class Main {
  public static void main(String[] args) throws IOException{
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String[] str = in.readLine().split(" ");
    String[] a_str = in.readLine().split(" ");
    in.close();
    
    int n = Integer.parseInt(str[0]);
    int m = Integer.parseInt(str[1]);
    int[] a = new int[n];
    int sum = 0;
    
    for(int i = 0; i < n; i++) {
      a[i] = Integer.parseInt(a_str[i]);
      sum += a[i];
    }
    
    int cnt = 0;
    for(int i = 0; i < n; i++) {
      if((double)a[i] >= (double)sum / (4*m))
        cnt++;
    }
    
    System.out.println(cnt >=m?"Yes":"No");
  }
}

Measured memory_bytes: 32564
#include <iostream>

int main() {

    int n,m;

    std::cin>>n>>m;

    int ans=n;

    for(int i=0;i<m;++i){
        int a;
        std::cin>>a;
        ans-=a;
    }

    std::cout<<((ans<0)? -1 : ans)<<std::endl;

    return 0;
}

Measured memory_bytes: 3192
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<iterator>
using namespace std;

int main() {
	int a, b;
	while (cin >> a >> b, a | b) {
		vector<vector<int>>d(a);
		for (int c = 0; c < a; c++) {
			vector<int>e(b);
			for (int f = 0; f < b; f++)cin >> e[f];
			d[c] = e;
		}
		int s = 0;
		for (int n = 0; n < (1 << a); n++) {
			vector<vector<int>>p;
			copy(d.begin(), d.end(),back_inserter(p));
			int r = 0;
			for (int m = 1; m <= n; m <<= 1) {
				if (n&m) {
					for (int x = 0; x < b; x++) {
						if (p[r][x])p[r][x]--;
						else p[r][x]++;
					}
				}
				r++;
			}
			int z = 0;
			for (int aa = 0; aa < b; aa++) {
				int cc = 0;
				for (int bb = 0; bb < a; bb++) {
					if (p[bb][aa])cc++;
				}
				z += max(cc, a - cc);
			}
			s = max(z, s);
		}
		cout << s << endl;
	}
}

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

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;

int main()
{
    string s;
    cin >> s;
    int i = 0;
    int j = s.size() - 1;
    int ans = 0;
    while (i < j) {
        if (s[i++] != s[j--]) ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
<?php
fscanf(STDIN, "%d %d %d", $a, $b, $t);

$ans = 0;
for($i=1; $i<=20; $i++){
    $time = $a * $i;
    if($time <= $t){
        $ans += $b;
    }else{
        break;
    }
}
echo $ans;
?>

Measured memory_bytes: 4728
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <set>
#include <iomanip>

using namespace std; using ll=long long; const int INF=1e9;
typedef pair<int,int> P;

int main() {
  int a,b,k; cin>>k>>a>>b;
  bool ok=false;
  for(int i=a;i<=b;i++) {
    if (i % k == 0) ok=true;
  }
  if (ok) cout<<"OK"<<endl;
  else cout<<"NG"<<endl;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
    
#define REP(i, n) for (int i = 0; i < (int)n; i++)
#define ST first
#define ND second
#define MP make_pair
#define PB push_back
    
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef set<int> SI;
typedef long long LL;
    
#ifdef DEBUG
const bool debug = true;
#else
const bool debug = false;
#endif

// #define MULTI_TASK true

const int inf = 1000 * 1000 * 1000;
const int MAKSN = 1000 * 1000 + 13;
const LL MOD = 123456789LL;
int n, m, k, l, x, y, a, b, rcnt, gcnt, ccnt;
string s;
vector<LL> red, green, color;
vector<PII> v;

void zeruj() {
    v.clear();
}

void readIn() {
    cin >> x >> y >> rcnt >> gcnt >> ccnt;

    REP (i, rcnt) {
        cin >> k;
        red.PB(k);
    }

    REP (i, gcnt) {
        cin >> k;
        green.PB(k);
    }

    REP (i, ccnt) {
        cin >> k;
        color.PB(k);
    }

  

}
        
void solve() {
    sort(red.begin(), red.end());
    sort(green.begin(), green.end());
    sort(color.begin(), color.end());


    LL sum = 0;
    for (int i = 0; i < x; i++) {
        int kk = red.back();
        red.pop_back();
        v.push_back({kk, 0});
        sum += kk;
    }

    for (int i = 0; i < y; i++) {
        int kk = green.back();
        green.pop_back();
        v.push_back({kk, 1});
        sum += kk;
    }

    sort(v.begin(), v.end());
    reverse(color.begin(), color.end());
    int rchanged = 0, gchanged = 0;
    for (int i = 0; i < (int)min(color.size(), v.size()); i++) {
        int curCol = v[i].second;
        LL curVal = v[i].first;
        if (color[i] > curVal) {
            if (curCol == 0 && rchanged < rcnt) {
                sum -= curVal;
                sum += color[i];
                rchanged++;
            }
            if (curCol == 1 && gchanged < gcnt) {
                sum -= curVal;
                sum += color[i];
                gchanged++;
            }
        }
    }

    cout << sum << "\n";
}

int main() {
    ios_base::sync_with_stdio(0);
#ifdef MULTI_TASK
    int test;
    cin >> test;
    while (test--) {
#endif
        zeruj();
        readIn();
        solve();
#ifdef MULTI_TASK
    }
#endif 
    return 0;
}


Measured memory_bytes: 4852
import sys

input = sys.stdin.readline
N, M = map(int, input().split())
A = sorted(list(map(int, input().split())))[::-1]
BC = sorted([list(map(int, input().split())) for _ in range(M)], key=lambda x: x[1])

ans = 0
for a in A:
    if N == 0:
        break
    while len(BC) > 0 and BC[-1][1] > a and N != 0:
        b, c = BC.pop()
        i = min(N, b)
        ans += i * c
        N -= i
    if N >= 1:
        ans += a
        N -= 1
print(ans)


Measured memory_bytes: 97192