akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
#define CLOCK_START clock_t chrono_clk_beg = clock()
#define CLOCK_END clock_t chrono_clk_end = clock(); cerr << (double(chrono_clk_end - chrono_clk_beg) / CLOCKS_PER_SEC) << " sec"
#define bug(args ...) cerr << __LINE__ << ">> ", err(new istringstream(string(#args)), args), cerr << '\n'
#define all(x) x.begin(), x.end()
#define INF (1LL<<30)
#define INF32 (1LL<<62)
#define F first
#define S second
#define M_PI 3.14159265358979323846
#define MOD 1000000007
#define int ll
typedef unsigned long long BITMASK; typedef long long ll; typedef long double ld; typedef pair<int, int> pii; typedef pair<double, double> pdd; typedef pair<long long, long long> pll; typedef cc_hash_table<int, int, hash<int>> intHashTable;
struct custom_hash { static uint64_t splitmix64(uint64_t x) { x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31); } size_t operator()(uint64_t x) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x + FIXED_RANDOM); } };
inline int powMod(int a, int b) { int x = 1; while (b > 0) { if (b&1) x = (x*a) % MOD; a = (a*a) % MOD; b >>= 1; } return x; }
inline int multiply(int x, int y) { return ((x % MOD) * (y % MOD)) % MOD; }
inline int divide(int x, int y) { return ((x % MOD) * powMod(y % MOD, MOD-2)) % MOD; }
inline int ceil(int a, int b) { return (a+b-1)/b; }
int gcd (int a, int b) { while (b) { a %= b; swap(a, b); } return a; }
int lcm (int a, int b) { return a / gcd(a, b) * b; }
int inverseMod(int a, int m) { a = a % m; for (ll x = 1; x < m; x++) if ((a * x) % m == 1) return x; return -1; }
void err(istringstream *iss) {} template<typename T, typename ... Args> void err(istringstream *iss, const T &_val, const Args & ... args) { string _name; *iss >> _name; if (_name.back()==',') _name.pop_back(); cerr << _name << " = " << _val << "; ", err(iss, args ...); }
int str_replace(string& str, const string& from, const string& to, int limit = -1) { if(from.empty()) return 0; size_t start_pos = 0; int cnt = 0; while((start_pos = str.find(from, start_pos)) != std::string::npos) { str.replace(start_pos, from.length(), to); start_pos += to.length(); cnt++; if (cnt == limit) break; } return cnt; }
template<int D, typename T> struct vec : public vector<vec<D - 1, T>> { static_assert(D >= 1, "Vector dimension must be greater than zero!");  template<typename... Args> vec(int n = 0, Args... args) : vector<vec<D - 1, T>>(n, vec<D - 1, T>(args...)) { } }; template<typename T> struct vec<1, T> : public vector<T> { vec(int n = 0, T val = T()) : vector<T>(n, val) { }};

signed main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int n, m, sm = 0; cin >> n >> m;
    while (m--) { int x; cin >> x; sm += x; }
    if (sm > n) cout << "-1\n";
    else cout << max(0LL, n-sm) << '\n';
    return 0;
}


Measured memory_bytes: 3656
#include <cstdio>
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <cmath>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#define rep(i,n) for (int i=0;i<n;i++)
using ll = long long;
using namespace std;


void solve(){

}
int main (){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    cout << pow(n,3);

    return 0;
}

Measured memory_bytes: 4212
#include<bits/stdc++.h>
using namespace std;
long long Q,H,S,D,N,ans,k,kk,kkk;
int main()
{
    cin>>Q>>H>>S>>D>>N;
    k=min(Q*4,min(H*2,S));
    if(k*2<=D)
    {
        cout<<k*N<<endl;
    }
    else
    {
        cout<<((N%2)*k)+N/2*D<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define endl "\n"
#define se second
#define ll long long
#define inf 0x3f3f3f3f
#define fast    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int N = 5e3+5;
const ll mod =   1e9+7;
ll n,k;ll ans=-1e18;
ll a1[N],a2[N];
bool bo[N];
void solve(int idx){
	memset(bo,false,sizeof bo);
	ll x=0;vector<ll> v(5005);
	while(!bo[idx]){
		v[++x]=a2[idx];
		bo[idx]=true;
		idx=a1[idx];
	}
	for(int i=2;i<=x;i++)
	v[i]+=v[i-1];
	ll an=-1e18;
	for(int i=1;i<=min(x,k);i++)
	{
		an=max(an,v[i]);
		an=max(an,v[i]+(k-i)/x*v[x]);
	}
	ans=max(ans,an);
	
}
int main()
{  fast
cin>>n>>k;
for(int i=1;i<=n;i++)
cin>>a1[i];
for(int i=1;i<=n;i++)
cin>>a2[i];
for(int i=1;i<=n;i++)
solve(i);
cout<<ans;
}

Measured memory_bytes: 3776
#include <iostream>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <list>
#include <set>
#include <unordered_set>
#include <vector>
#include <utility>
#include <algorithm>
#include <queue>
#include <cstdint>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cmath>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

constexpr ll inf = INT64_MAX / 4;
constexpr double pi = asin(1) * 2;
constexpr ll mod = 1000000007;

int n, q;
vector<pair<pair<int, int>, int>> v;
vector<int> d;

int main() {
    cin >> n >> q;
    v.resize(n);
    d.resize(q);
    for (auto &e:v) {
        cin >> e.first.first >> e.first.second >> e.second;
        e.first.first -= e.second;
        e.first.second -= e.second;
    }
    sort(v.begin(), v.end());
    for (auto &e:d)cin >> e;
    priority_queue<pair<int, pair<int, int>>> pq;
    auto itr = v.begin();
    for (auto &e:d) {
        while (itr != v.end() && itr->first.first <= e) {
            pq.push(make_pair(-itr->second, itr->first));
            itr++;
        }
        while (!pq.empty() && pq.top().second.second <= e) {
            pq.pop();
        }
        cout << (pq.empty() ? -1 : -pq.top().first) << endl;
    }
}


Measured memory_bytes: 8052
#include <stdio.h>
#define max(a,b) (a > b ? a : b)
#define min(a,b) (a < b ? a : b)

int main(void) {
	int a1, a2, a3;
	
	scanf("%d %d %d", &a1, &a2, &a3);
	printf("%d", max(a1,max(a2,a3))-min(a1,min(a2,a3)));
	
	return 0;
}

Measured memory_bytes: 128
t,s=open(0)
n,k=map(int,t.split())
l=2*k+1
x=[0]*2+[i+1for i in range(n-1)if s[i]!=s[i+1]]+[n]*l
print(max(x[i+l]-x[i]for i in range(s>'1',len(x)-l,2)))

Measured memory_bytes: 8720
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
typedef  long long ll;
ll gcd(ll x,ll y){
   if(y==0) return x;
   else return gcd(y,x%y);
}
ll lcm(ll x,ll y){
   return x/gcd(x,y)*y;
}
using namespace std;
int main(){ 
   string s;
   cin>>s;
   for(int i=0;i<s.size();i++){
      if(i%2==0) cout<<s[i];
   }
   
   return 0;
}

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

using namespace std;

using ll = long long;
#define long long long

int main(void) {
    ll n;
    cin >> n;
    vector<ll> l(n);
    for(auto &e: l) cin >> e;
    sort(l.begin(), l.end());

    ll s = 0;
    for(auto &e: l) s += e;
    cout << (s-l[n-1] > l[n-1] ? "Yes" : "No") << endl;
}


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

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}

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

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;

const int mod = 1000000007;

int main(void){
    for(int n, w; cin >> n >> w;){
        vi c(n);
        for(auto && cc : c) cin >> cc;
        
        sort(all(c));

        int res = 1;
        rep(i, n){
            int sum_c = 0;
            rep(j, i) sum_c += c[j];

            int ww = w - sum_c;
            if(ww < c[i]) continue;

            vi dp(ww + 1);
            dp[0] = 1;
            range(j, i + 1, n){
                for(int k = ww - c[j]; k >= 0; k--){
                    (dp[k + c[j]] += dp[k]) %= mod;
                }
            }

            range(j, ww - c[i] + 1, ww + 1){
                (res += dp[j]) %= mod;
            }
        }

        cout << res << endl;
    }

	return 0;
}

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

int main(){
    long long n, a, b;
    cin >> n >> a >> b;

    string s;
    cin >> s;
    long long cnt = 0;
    long long cnt_b = 0;
    for(long long i = 0; i < n; i++){
        if(s[i] == 'c') printf("No\n");
        else if(s[i] == 'a'){
            if(cnt < a + b) printf("Yes\n"), cnt++;
            else printf("No\n");
        }
        else if(s[i] == 'b'){
            cnt_b++;
            if(cnt < a + b and cnt_b <= b) printf("Yes\n"), cnt++;
            else printf("No\n");
        }
    }
    return 0;
}

Measured memory_bytes: 3704
#include<stdio.h>

int main(void){
	int i,j,n,x[5]={},y,a,b,c,d,e;
		scanf("%d %d %d %d %d",&a,&b,&c,&d,&e);
	x[0]=a;
	x[1]=b;
	x[2]=c;
	x[3]=d;
	x[4]=e;
	for(i=0;i<4;i++){
	for(j=4;j>i;j--){
	if(x[j-1]<x[j]){
	y=x[j];
	x[j]=x[j-1];
	x[j-1]=y;
	}
	}
	}
	for(i=0;i<5;i++){
	printf("%d",x[i]);
	if(i!=4){
	printf(" ");
	}
	if(i==4){
	printf("\n");
	}
	}
	return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <algorithm>

using namespace std;

int main(){
    int K,N,l[55];
    cin>>N>>K;
    for(int i=1;i<=N;i++){
        cin>>l[i];
    }
    sort(l+1,l+N+1,greater<int>());
    int sum = 0;
    for(int i=1;i<=K;i++){
        sum += l[i];
    }
    cout<<sum<<endl;
}

Measured memory_bytes: 3656
import java.math.BigInteger;
import java.util.*;
import java.util.stream.Collectors;

public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    long k = sc.nextLong();
    int q = sc.nextInt();
    if (q < k) {
      for (int i = 0; i < n; i++) {
        System.out.println("Yes");
      }
      return;
    }
    Map<Integer, Integer> collectMap = new HashMap<>();
    for (int i = 0; i < q; i++) {
      int a = sc.nextInt();
      Integer collect = collectMap.computeIfAbsent(a, hoge -> 0);
      collectMap.put(a, collect + 1);
    }
    for (int i = 0; i < n; i++) {
      Integer integer = collectMap.get(i + 1);
      if (integer == null || k <= q - integer) {
        System.out.println("No");
      } else {
        System.out.println("Yes");
      }
    }
  }
}


Measured memory_bytes: 55912
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<string>
#include<queue>
#include<vector>
#include<cstdlib>
#include<ctime>
#include<set>
#include<bitset>
#include<map>
#include<iostream>
#define ll long long
#define rep(i,a,b) for(register ll i=a;i<=b;++i)
#define fd(i,a,b) for(register int i=a;i>=b;--i)
#define Max(a,b) ((a)>(b)?(a):(b))
#define Min(a,b) ((a)<(b)?(a):(b))
#define Abs(a) ((a<0)?-(a):(a))
namespace io{
//    char buf[1<<17],*p1=buf,*p2=buf;
//    inline int getc(){
//         return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<17,stdin),p1==p2)?EOF:*p1++;
//    }
	#define getc() getchar()
    template<class T>
    inline void Read(T &x){
        x=0;T f=1;char c;
        for(c=getc();c<'0'||c>'9';f=((c=='-')?-1:f),c=getc());
        for(;c>='0'&&c<='9';x=x*10+(c^48),c=getc());
        x*=f;
    }
    template<class T>
    inline void write(T a){
        if(a==0){putchar('0');return;}
        if(a<0)putchar('-'),a=-a;
        char c1[120];
        int h=0;
        while(a)c1[++h]=a%10+'0',a/=10;
        for(int i=h;i>=1;i--)putchar(c1[i]);
        return;
    }
    template<class T>
    inline void write_(T a){write(a);putchar(' ');}
    template<class T>
    inline void writeln(T a){write(a);putchar('\n');}
}
using namespace io;
template<class T>
inline T gcd(T a,T b){return a==0?b:gcd(b%a,a);}
template<class T>
inline T lcm(T a,T b){return 1ll*a/gcd(a,b)*b;}
/*----------------------------------------------------------------------*/
const int N = 1e5 + 9;
int n;
ll d[N], m[N];

int main(){
	Read(n);
	rep(i,1,n) Read(d[i]);
	m[2] = d[1] + d[2];
	rep(i,3,n){
		m[2] += pow(-1, i) * d[i];
	}
	m[2] >>= 1;
	rep(i,3,n) m[i] = d[i - 1] - m[i - 1];
	m[1] = d[n] - m[n];
	rep(i,1,n) write_(m[i] * 2);
	return 0;
}

Measured memory_bytes: 2816
#include<bits/stdc++.h>
#define reg register
typedef unsigned long long ll;
using namespace std;
const int MN=80000;
int n,pri[2001],cnt,vis[MN+5],id[501][501][2];
ll a[501][501];
inline bool border(int i){return (i==1||i==n);}
int main(){
	scanf("%d",&n);
	for(reg int i=2;i<=MN;i++){
		if(!vis[i])pri[++cnt]=i;
		if(cnt==1000)break;
		for(reg int j=1;j<=cnt&&pri[j]*i<=MN;j++){
			vis[pri[j]*i]=1;
			if(!(i%pri[j]))break;
		}
	}
	if(n==2)return 0*puts("4 7\n23 10");
	for(reg int i=1;i<=n;i++)
		for(reg int j=1;j<=n;j++)
			if((~(i+j))&1){
				id[i][j][0]=(i+j)>>1;
				id[i][j][1]=n+((i-j+n)>>1)+1;
			}
	for(reg int i=1;i<=n;i++)
		for(reg int j=1;j<=n;j++)
			if((~(i+j))&1){
				a[i][j]=1ll*pri[id[i][j][0]]*pri[id[i][j][1]];
			}
			else{
				if(border(i)&&border(j))
					if(i==1)a[i][j]=1ll*pri[id[2][n][0]]*pri[id[1][n-1][0]]*pri[id[1][n-1][1]];
					else a[i][j]=1ll*pri[id[n][2][0]]*pri[id[n-1][1][0]]*pri[id[n-1][1][1]];
				else if(border(i))
					a[i][j]=1ll*pri[id[i][j-1][0]]*pri[id[i][j+1][0]]*pri[id[i][j-1][1]]*pri[id[i][j+1][1]];
				else a[i][j]=1ll*pri[id[i-1][j][0]]*pri[id[i+1][j][0]]*pri[id[i-1][j][1]]*pri[id[i+1][j][1]];
				a[i][j]++;
			}
	for(reg int i=1;i<=n;i++,puts(""))
		for(reg int j=1;j<=n;j++)
			printf("%llu ",a[i][j]);
	return 0;
}

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

ll N, M;
vector<ll> P;
vector< vector<ll> > E;
vector<bool> visited;

void dfs(ll v, ll p, vector<ll> &x, vector<ll> &y) {
  if(visited[v]) return;
  visited[v] = true;

  x.push_back(v);
  y.push_back(P[v]);

  for(ll u : E[v]) if(u != v) dfs(u, v, x, y);
}

int main(void) {
  cin >> N >> M;
  P.resize(N);
  E.resize(N);
  REP(i, 0, N) cin >> P[i], P[i]--;
  REP(i, 0, M) {
    ll X, Y;
    cin >> X >> Y;
    X--; Y--;
    E[X].push_back(Y);
    E[Y].push_back(X);
  }

  ll ans = 0;
  visited.resize(N, false);
  REP(i, 0, N) {
    if(!visited[i]) {
      vector<ll> x, y;
      dfs(i, -1, x, y);
      sort(x.begin(), x.end());
      REP(i, 0, y.size()) {
        if(binary_search(x.begin(), x.end(), y[i])) {
          ans++;
        }
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 12196
#include <algorithm>
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <string>
using namespace std;
int main(){
    string s; cin >> s;
    int maxlength=0;
    int primelength=0;
    for(int i=0; i<s.size(); i++){
        if(s[i]=='A'||s[i]=='C'||s[i]=='T'||s[i]=='G'){
            primelength++;
        }else{
            maxlength=max(maxlength,primelength);
            primelength=0;
        }
    }
    maxlength=max(maxlength,primelength);
    cout << maxlength << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>


using namespace std;
int main(){
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if(a+b < c+d) cout << "Right" << endl;
    else if(a+b > c+d) cout << "Left" << endl;
    else cout << "Balanced" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
typedef long long ll;
typedef long  l;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
const double PI=3.141592653589;
const int INF=1000000007;
const ll LMAX=1000000000000001;
const ll mod=1000000007;
ll gcd(ll a,ll b){if(a<b)swap(a,b);while((a%b)!=0){a=b;b=a%b;}return b;}
int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};

int main(){
  char c; cin>>c;
  if(c=='a'||c=='i'||c=='u'||c=='e'||c=='o')
  cout<<"vowel"<<endl;
  else
  puts("consonant");
  return 0;
}


Measured memory_bytes: 256
'use strict'
// たこ足配線よくないと思います
let input = require("fs").readFileSync("/dev/stdin", "utf8");
const Nums = input.split(' ');
const A = Nums[0];
const B = Nums[1];
let ans = 0;
if(A == B){
	ans = 1;
}else {
	ans = 1 + Math.ceil((B-A)/(A-1));
}


console.log(ans);

Measured memory_bytes: 7372
n,a,b = input().split()
N = int(n)
A = int(a)
B = int(b)

sum = A + B
yakusuu = int(N / sum)
amari = N % sum
num = 0

if amari >= A:
    num = A
else:
    num = amari

ans = (yakusuu*A) + num

print(ans)

Measured memory_bytes: 3188
import java.util.*;

public class Main {
	public static void main(String[] args) {
		// practice contest

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

		if (a >= b * 2) {
			int x = a - b * 2;
			System.out.println(x);
		} else if (a <= b) {
			System.out.println(0);
		} else if (a <= b * 2) {
			System.out.println(0);
		}
	}
}

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

int main(void){
	std::string S;
	std::cin>>S;

	if(*S.begin() != 'A'){
		std::cout<<"WA"<<std::endl;
		return 0;
	}

	int cnt = 0;
	for(auto Sptr = S.begin()+1;Sptr != S.end();Sptr++){
		if(!std::islower(*Sptr)){
			cnt++;			
		}
	}

	int cnt2 = 0;
	for(auto Sptr = S.begin()+2;Sptr != S.end()-1;Sptr++){
		if(*Sptr == 'C'){
			cnt2++;
		}
	}

	if(cnt == 1 && cnt2 == 1){
		std::cout<<"AC"<<std::endl;
	}else{
		std::cout<<"WA"<<std::endl;
	}

	return 0;
}


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

using namespace std;

int main()
{

    int n,m,k;
    cin>>n>>m>>k;
    if(n==5 && m==5 && k==7){cout<<"YES";}
    else if(n==5 && m==7 && k==5){cout<<"YES";}
    else   if(n==7 && m==5 && k==5){cout<<"YES";}
else {cout<<"NO";}



    return 0;
}


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

int w,h;
const int MOD=100000;

int dp[2][1<<20];

void solve(){
	int res=1;
	vector<string> V;
	for(int i=0;i<h;i++){
		string s;
		cin>>s;
		for(int j=0;j<s.size();j++){
			if(s[j]=='?')res*=3;
			res%=MOD;
		}
		V.push_back(s);
	}

	if(w==1 || h==1){
		cout<<res<<endl;
		return;
	}

	for(int y=1;y<h;y++){
		for(int x=0;x<w-1;x++){
			if(V[y][x]=='I' && V[y-1][x]=='J' && V[y-1][x+1]=='O'){
				cout<<res<<endl;
				return;
			}
		}
	}


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

	memset(dp,0,sizeof(dp));

	int *before=dp[0];
	int *now=dp[1];

	//ÅãÌbitÍJÅ é©Ç¤©
	//»êÈOÍA©ªªJÅ©ÂEªOÅ é©

	memset(before,0,sizeof(before));
	before[0]=1;

	for(int y=0;y<h;y++){
		memset(now,0,sizeof(now));
		for(int x=0;x<w;x++){

			for(int bit=0;bit<1<<w;bit++){
				int nbit;
				nbit=bit&(~1);
				nbit=nbit<<1;
				nbit=nbit&(~(1<<w));
				if(before[bit]==0) continue;

				if(x==0){
					if(bit&(1<<(w-1))){
						if(V[y][x]=='O' || V[y][x]=='?') now[nbit]+=before[bit];//O;
						if(V[y][x]=='J' || V[y][x]=='?') now[nbit|1]+=before[bit];//J
					}
					else{
						if(V[y][x]=='O' || V[y][x]=='?') now[nbit]+=before[bit];//O,I
						if(V[y][x]=='I' || V[y][x]=='?') now[nbit]+=before[bit];
						if(V[y][x]=='J' || V[y][x]=='?') now[nbit|1]+=before[bit];//J
					}
				}
				else{
					if(bit&(1<<(w-1))){
						if(bit&1){
							if(V[y][x]=='O' || V[y][x]=='?') now[nbit|(1<<1)]+=before[bit];//O
							if(V[y][x]=='J' || V[y][x]=='?') now[nbit|1]+=before[bit];//J
						}
						else{
							if(V[y][x]=='O' || V[y][x]=='?') now[nbit]+=before[bit];//O
							if(V[y][x]=='J' || V[y][x]=='?') now[nbit|1]+=before[bit];//J
						}
					}
					else{
						if(bit&1){
							if(V[y][x]=='I' || V[y][x]=='?') now[nbit]+=before[bit];//I
							if(V[y][x]=='O' || V[y][x]=='?') now[nbit|(1<<1)]+=before[bit];//O
							if(V[y][x]=='J' || V[y][x]=='?') now[nbit|1]+=before[bit];//J
						}
						else{
							if(V[y][x]=='O' || V[y][x]=='?') now[nbit]+=before[bit];//O,I
							if(V[y][x]=='I' || V[y][x]=='?') now[nbit]+=before[bit];
							if(V[y][x]=='J' || V[y][x]=='?') now[nbit|1]+=before[bit];//J
						}
					}
				}
			}
			swap(before,now);

			for(int i=0;i<1<<w;i++){
				now[i]=0;
				before[i]%=MOD;
			}
		}
	}

	int ans=0;
	for(int i=0;i<1<<w;i++){
		ans+=before[i]%MOD;
	}
	ans%=MOD;
	cout<<(res-ans)%MOD<<endl;
}

int main()
{
	while(cin>>h>>w){
		solve();
	}
	return 0;
}

Measured memory_bytes: 9088
#include <stdio.h>
#include <algorithm>

using std::max;

int main()	{

	int n, w, h, x, y, s, t, pmax, psum;
	bool fld[100][100];
	while (true)	{

		scanf("%d", &n);
		if (n == 0)	break;

		// initialize
		for (int i = 0; i <= 99; i++)	{
			for (int j = 0; j <= 99; j++)	{
				fld[i][j] = false;
			}
		}
		pmax = -1;

		scanf("%d %d", &w, &h);

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

			scanf("%d %d", &x, &y);
			fld[y-1][x-1] = true;
		}

		///
		//for (int i = 0; i <= h-1; i++)	{
		//	for (int j = 0; j <= w-1; j++)	{
		//		printf("%d ", fld[i][j]);
		//	}
		//	printf("\n");
		//}
		///

		scanf("%d %d", &s, &t);

		// 左上のマスを確定
		for (int ty = 0; ty <= h-t; ty++)	{
			for (int tx = 0; tx <= w-s; tx++)	{
				// 選んだ左上のマスを基準に
				// st領域にあるカキの木をカウント
				psum = 0;
				for (int cy = ty; cy <= ty+t-1; cy++)	{
					for (int cx = tx; cx <= tx+s-1; cx++)	{
						if (fld[cy][cx])	{
							psum++;
						}
					}
				}
				///
				//if (pmax < psum)	{
				//	printf("reload::\n");
				//	printf("%d %d - %d %d\n", tx, ty, tx+s, ty+t);
				//}
				///
				pmax = max(pmax, psum);
			}
		}

		printf("%d\n", pmax);
	}

	return 0;

}


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

int main() {
  long long Q, H, S, D, N;
  cin >> Q >> H >> S >> D >> N;
  
  long long HMin = min(Q * 2, H);
  long long SMin = min(HMin * 2, S);
  
  if (SMin * 2 <= D) {
    cout << SMin * N << endl;
  } else {
    cout << (N / 2) * D + (N % 2) * SMin << endl;
  }
 }

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

using namespace std ;

int main()
{
	ios_base::sync_with_stdio(0) ;
	cin.tie(0) ;
	int arr[3][3] , ans[3][3];
	for(int i = 0 ; i < 3 ; ++i)
	{
		for(int j = 0 ; j < 3 ; ++j)
			cin>>arr[i][j] ;
	}
	for(int x = 0 ; x <= 100 ; ++x)
	{
		for(int i = 0 ; i < 3 ; ++i)
		{
			for(int j = 0 ; j < 3 ; ++j)
			{
				ans[i][j] = arr[i][j] - (arr[0][j] - x) ;
			}
		}
		bool flag = true ;
		for(int i = 0 ; i < 3 ; ++i)
		{
			for(int j = 0 ; j < 3 ; ++j)
			{
				flag &= (ans[i][j] >= 0 && ans[i][j] <= 100) ;
				if(j > 0)
					flag &= (ans[i][j] == ans[i][j-1]) ;
			}
		}
		if(flag)
			return cout<<"Yes\n" , 0 ;
	}
	return cout<<"No\n" , 0 ;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rep(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v> >
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////

ll n,k;
Vi d;

matrix a;
set<ll> st;

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(30);
    cin>>n>>k;
    d.resize(k);
    rep(i,k){
        ll inp;
        cin>>inp;
        rep(j,inp){
            ll in;
            cin>>in;
            st.insert(in);
        }
    }
    print(n-st.size());
    return 0;
}

Measured memory_bytes: 3668
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <utility>
#include <cstdio>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <cmath>
#include <set>
#include <map>
using ll = long long;
using itn = int;
using namespace std;
int main(){
    int n;cin >> n;
    string s; cin >> s;
    int ans = 0;
    for(int i=1; i<n; i++){
        int cnt = 0;
        for(int j=0; j<26; j++){
            bool l=false, r=false;
            for(int k=0; k<i; k++){
                if(s[k]=='a'+j) l=true;
            }
            for(int k=i; k<n; k++){
                if(s[k]=='a'+j) r=true;
            }
            if(l && r) cnt++; 
        }
        ans = max(ans, cnt);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    int N;
    cin>>N;
    vector<double> sum1(N,0);
    vector<double> sum2(N,0);
    double ans;
    for(int i=0;i<N;i++){
        cin>>sum1[i];
        if(sum1[i]!=0) {
            sum2[i] = 1 / sum1[i];
        }
        else{
            sum2[i]=0;
        }
        ans+=sum2[i];
    }
    if(ans==0){
        cout<<0<<endl;
    }else {
        double ans2 = 1/ans;
        cout <<ans2<< endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    int left = A + B, right = C + D;

    if (left > right)
        cout << "Left" << endl;
    else if (left == right)
        cout << "Balanced" << endl;
    else
        cout << "Right" << endl;
}

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

int main()
{
	int N;
	map<int,int> nums;
	cin >> N;
	for (int i = 0; i < N; ++i){
		int temp;
		cin >> temp;
		nums.insert({ temp, i });
	}
	int oePair = 0;
	int i = 0;
	for (auto& el : nums){
		if (i % 2 != el.second % 2){
			++oePair;
		}
		++i;
	}
	cout << oePair / 2 << endl;
	return 0;
}


Measured memory_bytes: 4992
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {
	
	public static class Walk implements Comparable<Walk>{
		int x;
		int y;
		int cost;
		
		public Walk(int x, int y, int cost) {
			super();
			this.x = x;
			this.y = y;
			this.cost = cost;
		}

		@Override
		public int compareTo(Walk arg0) {
			return this.cost - arg0.cost;
		}
		
		
	}
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while(true){
			final int w = sc.nextInt();
			final int h = sc.nextInt();
			
			if(h == 0 && w == 0){
				break;
			}
			
			boolean[][] is_wall = new boolean[h][w];
			boolean[][] is_visited = new boolean[h][w];
			
			int goal_x = -1, goal_y = -1;
			
			for(int i = 0; i < h; i++){
				char[] ch = sc.next().toCharArray();
				
				for(int j = 0; j < w; j++){
					is_wall[i][j] = ch[j] == '#';
					
					if(ch[j] == '&'){
						goal_x = j;
						goal_y = i;
					}
				}
				
			}
			
			PriorityQueue<Walk> queue = new PriorityQueue<Walk>(); 
			for(int i = 0; i < h; i++){
				for(int j = 0; j < w; j++){
					if(i == 0 || i == (h - 1) || j == 0 || j ==(w - 1)){
						queue.add(new Walk(j, i, is_wall[i][j] ? 1 : 0));
					}
				}
			}
			
			
			
			while(!queue.isEmpty()){
				Walk walk = queue.poll();
				
				//System.out.println(walk.x + " " + walk.y + " " + walk.cost);
				
				if(walk.x == goal_x && walk.y == goal_y){
					System.out.println(walk.cost);
					break;
				}
				
				if(is_visited[walk.y][walk.x]){
					continue;
				}
				is_visited[walk.y][walk.x] = true;
				
				
				if(walk.x != 0 && !is_visited[walk.y][walk.x - 1]){
					queue.add(new Walk(walk.x - 1,walk.y, walk.cost + ((!is_wall[walk.y][walk.x] && is_wall[walk.y][walk.x - 1]) ? 1 : 0)));
				}
				
				if(walk.x != (w-1) && !is_visited[walk.y][walk.x + 1]){
					queue.add(new Walk(walk.x + 1,walk.y, walk.cost + ((!is_wall[walk.y][walk.x] && is_wall[walk.y][walk.x + 1]) ? 1 : 0)));
				}
				
				if(walk.y != 0 && !is_visited[walk.y - 1][walk.x]){
					queue.add(new Walk(walk.x,walk.y - 1, walk.cost + ((!is_wall[walk.y][walk.x] && is_wall[walk.y - 1][walk.x]) ? 1 : 0)));
				}
				
				if(walk.y != (h-1) && !is_visited[walk.y + 1][walk.x]){
					queue.add(new Walk(walk.x,walk.y + 1, walk.cost + ((!is_wall[walk.y][walk.x] && is_wall[walk.y + 1][walk.x]) ? 1 : 0)));
				}
			}
			
		}
		
	}

}

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

int main() {
    int n;
    cin>>n;
    int minc = n;
    for(int i=0; i<=n; i++) {
        int count=0;
        int t=i;
        for(int j=0; j<=6; j++) {
            count += t%6;
            t /= 6;
        }

        t = n-i;
        for(int j=0; j<=5; j++) {
            count += t%9;
            t /= 9;
        }
        minc = min(minc, count);
    }

    cout<<minc<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); ++i)
using ll = long long;
using pll = pair<ll,ll>;
const ll INF64 = 1LL << 60;
const int INF = (1 << 29);

int main(){
    int n,m; cin >> n >> m;
    char a[n][n],b[m][m];
    rep(i,n)rep(j,n) cin >> a[i][j];
    rep(i,m)rep(j,m) cin >> b[i][j];

    rep(i,n-m+1){
        rep(j,n-m+1){
            bool flag = true;
            for(int h=i; h<i+m; h++){
                for(int w=j; w<j+m; w++){
                    if(a[h][w]!=b[h-i][w-j]){
                        flag = false;
                        break;
                    }
                }
                if(flag==false) break;
            }

            if(flag){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }

    cout << "No" << endl;
}

Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for (int i = a; i <b; i++)
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef pair<int,int> pi;
#define trace(x) cout<<#x<<"="<<x<<"\n";
#define print(x) cout<<#x<<" is "; for(int i=0;i<x.size();i++){cout<<x[i]<<" ";}cout<<"\n"
#define llp 1000000007
#define mod 1000000007


ll power(ll x, ll y) 
{
	ll temp;
	if( y == 0)
		return 1;
	temp = power(x, y/2);
	if (y%2 == 0)
		return (temp*temp)%mod;
	else
		return (((x*temp)%mod)*temp)%mod; 
}

int main()
{   ios::sync_with_stdio(false);
    //freopen("a.in", "r", stdin);
    //freopen("b.in", "r", stdin);
    //freopen("c.in", "r", stdin);
    //freopen("d.in", "r", stdin);
    int n;
    cin>>n;
    string a,b,c;
    cin>>a>>b>>c;
    int ans=0;
    REP(i,0,n){
    	if(a[i]!=b[i] && b[i]!=c[i] && a[i]!=c[i]){
    		ans+=2;
    	}
    	if(a[i]==b[i]==c[i]){

    	}
    	if((a[i]==b[i] && b[i]!=c[i])||(a[i]==c[i] && c[i]!=b[i])||(b[i]==c[i] && c[i]!=a[i])){
    		ans+=1;
    	}
    }
    cout<<ans<<"\n";
    return 0;
}

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

#define debug(x) cout << #x" = " << x;

#define st first
#define nd second

using namespace std;
using namespace placeholders;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

const int MAXN = 3E3 + 10;

int n;
int a[MAXN];
vector<int> E[MAXN];

bool DFS(int u, int pre){
	bool flag = false;
	for (int v, i = 0; i < E[u].size(); ++i){
		if ((v = E[u][i]) == pre)
			continue;
		flag |= a[u] <= a[v] ? false : !DFS(v, u);
	}
	return flag;
}

int main(){
	scanf("%d", &n);
	for (int i = 1; i <= n; ++i)
		scanf("%d", a + i);
	for (int u, v, i = 1; i < n; ++i){
		scanf("%d%d", &u, &v);
		E[u].push_back(v);
		E[v].push_back(u);
	}

	vector<int> ans;
	for (int i = 1; i <= n; ++i)
		if (DFS(i, 0))
			ans.push_back(i);
	for (int i = 0; i < ans.size(); ++i)
		printf("%d%c", ans[i], "\n "[i + 1 < n]);
	return 0;
}


Measured memory_bytes: 384
#include<iostream>    
#include<cstdio>  
#include<stdio.h>  
#include<cstring>    
#include<cstdio>    
#include<climits>    
#include<cmath>   
#include<vector>  
#include <bitset>  
#include<algorithm>    
#include <queue>  
#include<map>  
#include<stack>
using namespace std;

string a, b;
int n, m, i;
int main()
{
	cin >> a >> b;
	n = a.length();
	m = b.length();
	if (n > m)
	{
		cout << "GREATER" << endl;
	}
	else if (n < m)
	{
		cout << "LESS" << endl;
	}
	else
	{
		for (i = 0; i < n; i++)
		{
			if (a[i] - '0' < b[i] - '0')
			{
				cout << "LESS" << endl;
				return 0;
			}
			else if (a[i] - '0' > b[i] - '0')
			{
				cout << "GREATER" << endl;
				return 0;
			}
		}
		cout << "EQUAL" << endl;
	}
}

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

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pld = pair<ld, ld>;
template <typename Q_type>
using smaller_queue = priority_queue<Q_type, vector<Q_type>, greater<Q_type>>;

constexpr int MOD_TYPE = 2;
constexpr ll MOD = (MOD_TYPE == 1 ? (ll)(1e9 + 7) : 998244353);
constexpr int INF = (int)1e9;
constexpr ll LINF = (ll)4e18;
constexpr ld PI = acos(-1.0);
constexpr ld EPS = 1e-11;
constexpr int Dx[] = {0, 0, -1, 1, -1, 1, -1, 1, 0};
constexpr int Dy[] = {1, -1, 0, 0, -1, -1, 1, 1, 0};

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << "\n"
#define Yes(n) cout << ((n) ? "Yes" : "No") << "\n"
#define possible(n) cout << ((n) ? "possible" : "impossible") << "\n"
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << "\n"
#define Yay(n) cout << ((n) ? "Yay!" : ":(") << "\n"
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << "\n";

#pragma endregion

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(30) << setiosflags(ios::fixed);

  int n, L;
  cin >> n >> L;
  int Min = INF, ans;
  int sum = 0;
  for (int i = 1; i <= n; i++)
  {
    sum += i + L - 1;
  }
  for (int i = 1; i <= n; i++)
  {
    if (Min > abs(sum - (sum - (i + L - 1))))
    {
      Min = abs(sum - (sum - (i + L - 1)));
      ans = (sum - (i + L - 1));
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
using System;
﻿﻿﻿﻿﻿using System.Globalization;
﻿﻿﻿﻿﻿using System.IO;
﻿﻿﻿﻿﻿using System.Linq;

namespace CF317
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            var sr = new InputReader(Console.In);
            //var sr = new InputReader(new StreamReader("input.txt"));
            var task = new Task();
            using (var sw = Console.Out)
            //using (var sw = new StreamWriter("output.txt"))
            {
                task.Solve(sr, sw);
                //Console.ReadKey();
            }
        }
    }

    internal class Task
    {
        public void Solve(InputReader sr, TextWriter sw)
        {
            var input = sr.ReadArray(Int32.Parse);
            var k = input[0];
            var s = input[1];
            var count = 0;
            for (var i = 0; i <= k; i++) {
                for (var j = 0; j <= k; j++) {
                    var r = s - (i + j);
                    if (r <= k && r >= 0) {
                        count++;
                    }
                }
            }

            sw.WriteLine(count);
        }
    }
}

internal class InputReader : IDisposable
{
    private bool isDispose;
    private readonly TextReader sr;

    public InputReader(TextReader stream)
    {
        sr = stream;
    }

    public void Dispose()
    {
        Dispose(true);
        GC.SuppressFinalize(this);
    }

    public string NextString()
    {
        var result = sr.ReadLine();
        return result;
    }

    public int NextInt32()
    {
        return Int32.Parse(NextString());
    }

    public long NextInt64()
    {
        return Int64.Parse(NextString());
    }

    public string[] NextSplitStrings()
    {
        return NextString()
            .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
    }

    public T[] ReadArray<T>(Func<string, CultureInfo, T> func)
    {
        return NextSplitStrings()
            .Select(s => func(s, CultureInfo.InvariantCulture))
            .ToArray();
    }

    public T[] ReadArrayFromString<T>(Func<string, CultureInfo, T> func, string str)
    {
        return
            str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
                .Select(s => func(s, CultureInfo.InvariantCulture))
                .ToArray();
    }

    protected void Dispose(bool dispose)
    {
        if (!isDispose)
        {
            if (dispose)
                sr.Close();
            isDispose = true;
        }
    }

    ~InputReader()
    {
        Dispose(false);
    }
}

Measured memory_bytes: 3032
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner num = new Scanner(System.in);
        int a = num.nextInt();
        int b = num.nextInt();

        if(a < b){
            System.out.println("a < b");
        }
        else if(a > b){
            System.out.println("a > b");
        }
        else if(a == b){
            System.out.println("a == b");
        }
    }
}





Measured memory_bytes: 26132
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " ";} cout<<endl;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string A;
  cin >> A;
  ll ans = 0;
  ll N = A.size();
  ll cnt[30] = {};
  rep(i,0,N){
    ans += i - cnt[A[i] - 'a'];
    cnt[A[i] - 'a']++;
  }
  print(ans+1);
}

Measured memory_bytes: 720
def factorize(N):
    if N == 1: return {1:1}
    res = {}
    for i in range(2, N):
        if i**2 > N: break
        if N % i != 0: continue
        num = 0
        while N % i == 0:
            N = int(N/i)
            num += 1
        res[i] = num
    if N>1: res[N] = 1
    return res

A, B = map(int, input().split())
resA = factorize(A)
resB = factorize(B)
res = set(resA.keys()) & set(resB.keys())
ans = len(res) if 1 in res else len(res)+1
print(ans)

Measured memory_bytes: 9156
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <limits.h>
#include <map>
#include <vector>
#include <deque>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <iterator>
#include <memory>

using namespace std;

#if 1
#define PRINT(x) { cout << #x << ": " << (x) << endl; }
#define PRINT_CONTAINER(x)  { cout << #x << ": ";                       \
        for (size_t ix = 0; ix < (x).size(); ++ix) cout << (x)[ix] << ", "; \
        cout << endl; }
#else
#define PRINT(x)
#define PRINT_CONTAINER(x)
#endif

int n;
struct Edge
{
    int from;
    int to;
    int cost;
};
vector<Edge> es;
vector<int> ds;

// Bellman-Ford algorithm that computes shortest paths from a single
// source vertex to all of the other vertices in a weighted digraph.
void shortest_path_bf(int s)
{
    fill(ds.begin(), ds.end(), INT_MAX);
    ds[s] = 0;
    while (true)
    {
        bool update = false;
        for (int i = 0; i < es.size(); ++i)
        {
            const Edge& e = es[i];
            if (ds[e.from] != INT_MAX && ds[e.to] > ds[e.from] + e.cost)
            {
                ds[e.to] = ds[e.from] + e.cost;
                update = true;
            }
        }
        if (!update) break;
    }
}

int main(int argc, char *argv[])
{
    while (true)
    {
        scanf("%d", &n);
        if (n == 0) break;
        es.clear();
        int num_town = 0;
        for (int i = 0; i < n; ++i)
        {
            Edge e;
            scanf("%d%d%d", &e.from, &e.to, &e.cost);
            num_town = max(max(num_town, e.from), e.to);
            es.push_back(e);
            swap(e.from, e.to);
            es.push_back(e);
        }
        ds.resize(num_town + 1);
        int min_town;
        int min_value = INT_MAX;
        for (int i = 0; i < ds.size(); ++i)
        {
            shortest_path_bf(i);
            int val = 0;
            for (int j = 0; j < ds.size(); ++j)
            {
                if (ds[j] != INT_MAX) val += ds[j];
            }
            if (val < min_value)
            {
                min_value = val;
                min_town = i;
            }
        }
        printf("%d %d\n", min_town, min_value);
    }
}



Measured memory_bytes: 3268
#include<cstdio>
int main(){
	int a,b,c,x,i;
	i = 0;
	scanf("%d %d %d",&a,&b,&c);
	for(int x=a; x <= b; x++){
		if(c % x == 0){
			i++;
		}
	}
	printf("%d\n",i);
return 0;
}

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

#define froop1(a,n) for(int i = a;i < n;i++)
#define froop2(a,n) for(int i = a;i > n;i--)

#define ll long long

#define pq(name,type) priority_queue<type> name
#define vec(name,type,length,value) vector<type> name(length,value)
#define vec2(name,type,length,width,value) vector<vector<type>> name(length,vector<type>(width,value));

int main(){
	ll N;
  cin >> N;
  map<ll,ll> a;
  froop1(0,N){
   ll b;
    cin >> b;
    if(a.count(b)){
      a.erase(b);
    }else{
      a[b] = 1;
    }
  }
  ll count = 0;
  for(pair<ll,ll> p : a){
   count++;
  }
  cout << count << endl;
}

Measured memory_bytes: 9704
n = int(input())
v = list(map(int, input().split()))
c = list(map(int, input().split()))

def wa(i):
    return v[i] - c[i]

x = [wa(i) for i in range(n)]
x.sort(reverse=True)
res = 0
for e in x:
    if e > 0:
        res += e
    else:
        break

print(res)


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


#define PB push_back
#define PF push_front
#define LB lower_bound
#define UB upper_bound
#define fr(x) freopen(x,"r",stdin)
#define fw(x) freopen(x,"w",stdout)
#define iout(x) printf("%d\n",x)
#define lout(x) printf("%lld\n",x)
#define REP(x,l,u) for(ll x = (l);x<=(u);x++)
#define RREP(x,l,u) for(ll x = (l);x>=(u);x--)
#define mst(x,a) memset(x,a,sizeof(x))
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define MP make_pair
#define se second
#define fi first
#define dbg(x) cout<<#x<<" = "<<(x)<<endl;
#define sz(x) ((int)x.size())
#define cl(x) x.clear()

typedef  long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
using namespace std;

const int maxn = 200010;
const int mod = 1e9+7;
const double eps = 1e-6;
const double PI = acos(-1);

template<typename T> inline void read(T &x){
x=0;T f=1;char ch;do{ch=getchar();if(ch=='-')f=-1;}while(ch<'0'||ch>'9');do x=x*10+ch-'0',ch=getchar();while(ch<='9'&&ch>='0');x*=f;
}

template<typename A,typename B> inline void read(A&x,B&y){read(x);read(y);}
template<typename A,typename B,typename C> inline void read(A&x,B&y,C&z){read(x);read(y);read(z);}
template<typename A,typename B,typename C,typename D> inline void read(A&x,B&y,C&z,D&w){read(x);read(y);read(z);read(w);}
template<typename A,typename B> inline A fexp(A x,B p){A ans=1;for(;p;p>>=1,x=1LL*x*x%mod)if(p&1)ans=1LL*ans*x%mod;return ans;}
template<typename A,typename B> inline A fexp(A x,B p,A mo){A ans=1;for(;p;p>>=1,x=1LL*x*x%mo)if(p&1)ans=1LL*ans*x%mo;return ans;}

int n;

ll ans=1e18;

PII A[maxn];

ll calc(int pos){
	int mx=max(A[1].fi,A[pos].fi),mn=min(A[pos].se,A[1].se);
	REP(i,2,n)if(i!=pos)mx=max(mx,A[i].fi),mn=min(mn,A[i].se);
	return 1LL*(mx-A[1].fi)*(A[pos].se-mn);
}

ll calc2(int pos){
	int ans=2e9;
	int mn=min(A[1].se,A[pos].fi),mx=max(max(A[1].se,A[pos].fi),A[n].fi);
	REP(i,2,n)if(i!=pos){
		ans=min(ans,mx-min(mn,A[i].fi));
		mn=min(mn,A[i].se);mx=max(mx,A[i].se);
	}
	ans=min(ans,mx-mn);
	return ans;
}

void Work(){
	int pos=1;
	REP(i,1,n)if(A[i].se>=A[pos].se)pos=i;
	ans=min(ans,calc(pos));
	//cout<<ans<<endl;
	if(pos!=1)ans=min(ans,calc2(pos)*(A[pos].se-A[1].fi));
	cout<<ans<<endl;
}

void Init(){
	read(n);
	REP(i,1,n)read(A[i].fi,A[i].se);
	REP(i,1,n)if(A[i].fi>A[i].se)swap(A[i].fi,A[i].se);
	sort(A+1,A+n+1);
}

int main(){
	Init();
	Work();
	return 0;
}


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

const int MOD = 1e9 + 7;

int main() {
  int n;
  string s;
  cin >> n;
  cin >> s;
  
  map<char, int> m;

  for (char c = 'a'; c <= 'z'; c++) {
    m[c] = 0;
  }

  for (int i = 0; i < n; i++) {
    m[s[i]]++;
  }

  long long ans = 1;
  for (char c = 'a'; c <= 'z'; c++) {
    ans *= (m[c] + 1) % MOD;
    ans %= MOD;
  }

  cout << (ans - 1) % MOD << endl;
}


Measured memory_bytes: 512
/// Bismillahir Rahmanir Rahim
/* Mohammad Morsalin
   Dept of ICE, NSTU
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ll long long
#define pb push_back
#define mp make_pair
#define endl "\n"
#define int long long
#define f0(n) for(int i=0;i<n;i++)
#define ms(x) memset(x,0,sizeof(x))
#define ms2d(x,m,n) memset(x, 0, sizeof(x[0][0]) * m * n)
#define uniq(vec) vec.resize(distance(vec.begin(),unique(vec.begin(),vec.end())))
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define pi pair<int,int>
#define tc(t) int t;cin>>t;while(t--)
#define bits(n) __builtin_popcount(n)
#define maxpq priority_queue<int>
#define minpq priority_queue<int, vector<int>, greater<int> >
#define ins insert
#define ALL(v) v.begin(),v.end()
#define highest(x) numeric_limits<x>::max()
#define lowest(x) numeric_limits<x>::min()
#define Inf INFINITY
#define minv(v) *min_element(v.begin(),v.end())
#define maxv(v) *max_element(v.begin(),v.end())
#define fi first
#define se second
#define PI acos(-1)
#define sz(a) (int)a.size();
#define IOS ios::sync_with_stdio(false);
using namespace std;
int gcd(int a, int b) { if (a == 0) return b; return gcd(b % a, a);}
typedef tree<pair<int, int>,null_type,less<pair<int, int>>,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};
int dx4[] = {0, 0, 1, -1};
int dy4[] = {1, -1, 0, 0};
const long long MOD = 1000000007;
double sq(double x) {return x*x;}
template<typename T>inline T Bigmod(T base, T power, T MOD){
    T ret=1;
    while(power)
    {
        if(power & 1)ret=(ret*base)%MOD;
        base=(base*base)%MOD;
        power>>=1;
    }
    return ret;
}

bool sortinrev(const pair<int,int> &a,
               const pair<int,int> &b)
{
       return (a.first > b.first);
}
signed main()
{
    IOS
    list<char>s;
    string ss;
    cin>>ss;
    for(int i=0;i<(int)ss.size();i++)s.pb(ss[i]);
    int q;
    bool fs=1;
    cin>>q;
    while(q--){
        int x;
        cin>>x;
        if(x==1){
            fs=!fs;
        }
        else{
            int t;
            char c;
            cin>>t>>c;
            if(t==1){
                if(fs==1){
                    s.push_front(c);
                }
                else{
                    s.push_back(c);
                }
            }
            if(t==2){
                if(fs==1){
                    s.push_back(c);
                }
                else{
                    s.push_front(c);
                }
            }
        }
    }
    if(fs==1){
        for(auto it=s.begin();it!=s.end();it++){
        cout << *it;
        }
    }
    else{
        for(auto it=s.rbegin();it!=s.rend();it++){
            cout << *it;
        }
    }
    cout << endl;
    return 0;
}
///Alhamdulillah


Measured memory_bytes: 13076