akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define modd 1000000007
using namespace std;
typedef long long int ll;
ll pow2[200001];
ll n;
ll modInverse(ll a,ll m = modd)
{
    ll m0 = m;
    ll y = 0, x = 1;
    if (m == 1)
      return 0;
    while (a > 1)
    {
        ll q = a / m;
        ll t = m;
        m = a%m;
        a = t;
        t = y;
        y = x - q * y;
        x = t;
    }
    if (x < 0)
       x += m0;
    return x;
}
vector<ll> adj[200001];
ll size[200001];
ll ans=0;
void dfs(ll r,ll p)
{
    ll temp=0;
    size[r]=1;
    for(auto x : adj[r])
    {
        if(x!=p)
        {
            dfs(x,r);
            size[r]+=size[x];
            temp = (temp+pow2[size[x]]-1)%modd;
        }
    }
    temp = (temp + pow2[n-size[r]]-1)%modd;
    temp = (temp+1)%modd;
    temp = (pow2[n-1]+modd-temp)%modd;
    ans = (ans+temp)%modd;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    pow2[0]=1;
    for(ll i=1;i<=200000;i++)
    {
        ll r=1;
        pow2[i] = pow2[i-1]<<r;
        pow2[i] = pow2[i]%modd;
    }
    cin>>n;
    for(ll i=1;i<n;i++)
    {
        ll u,v;
        cin>>u>>v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    dfs(1,0);
    ans = (ans*modInverse(pow2[n]))%modd;
    cout<<ans<<"\n";
    return 0;
}


Measured memory_bytes: 23552
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#pragma warning(disable:4996)
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <functional>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <list>
#include <set>
#include <ctime>
using namespace std;
typedef long long ll;

const int INF = 100000000;





int main(int argc, char *args[]) {
	char X;
	cin >> X;
	if (X == 'A')cout << 'T' << endl;
	else if(X == 'T')cout << 'A' << endl;
	else if (X == 'G')cout << 'C' << endl;
	else cout << 'G' << endl;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.regex.*;

public class Main {
	public static void main(String[] args) throws IOException {
		Pattern pattern = Pattern.compile("(-?[0-9]+) *(-?[0-9]+) *(-?[0-9]+) *(-?[0-9]+) *(-?[0-9]+) *(-?[0-9]+)");
		String str = "";
		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
		while((str=bf.readLine())!=null){
			Matcher matcher = pattern.matcher(str);
			if(!matcher.matches())break;
			int h[] = new int[6];
			for(int i=0;i<6;i++)h[i]=Integer.parseInt(matcher.group(i+1));
			int xc=h[2]*h[4]-h[1]*h[5];
			int xm=h[0]*h[4]-h[1]*h[3];
			int yc=h[2]*h[3]-h[0]*h[5];
			int ym=h[1]*h[3]-h[0]*h[4];
			System.out.printf("%.3f %.3f\n",
				(xc==0)?(double)0:(double)xc/xm,
				(yc==0)?(double)0:(double)yc/ym
			);
		}
	}
}

Measured memory_bytes: 12000
N, K = map(int, input().split())
R, S, P = map(int, input().split())
s = input()
d = {"r" : P, "s" : R, "p" : S}
dd = set()
r = 0
for i in range(N):
    r += d[s[i]]
    if i >= K:
        if i-K not in dd:
            if s[i-K] == s[i]:
                dd.add(i)
                r -= d[s[i]]
print(r)


Measured memory_bytes: 42480
#include <iostream>
#include <cstdio>

using namespace std;

int main(){
	char n_before[1000];
	int i;

	scanf("%s", n_before);
	
	i = 0;
	while (n_before[i] != '\0'){
		if (n_before[i] == 'A'){
			printf("%c", (n_before[i] + 0x17));
		}
		else if (n_before[i] == 'B'){
			printf("%c", (n_before[i] + 0x17));
		}
		else if (n_before[i] == 'C'){
			printf("%c", (n_before[i] + 0x17));
		}
		else{
			printf("%c", (n_before[i] - 0x03));
		}
		i++;
	}	
	printf("\n");
}

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

using namespace std;

//ifstream cin("/home/mihai/Documents/c++/A/A.in");
//ofstream cout("/home/mihai/Documents/c++/A/A.out");

string s;
int n;

int main() 
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> s;
	cin >> n;
	for(int i = 0; i < s.size(); i += n)
		cout << s[i];
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
#define ep emplace_back
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(v) v.begin(), v.end()
#define revall(v) v.rbegin(), v.rend()
constexpr int mod=1000000007;
constexpr int mod1=998244353;
vector<int> dx={0,1,0,-1},dy={-1,0,1,0};
bool inside(int y,int x,int h,int w){ if(y<h && y>=0 && x<w && x>=0) 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> inline bool chmax(T& a, T b){ if(a < b){ a = b; return true; } return false; }






int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,C;cin >> n >> C;
	vector<vector<int>> a(C, vector<int>(100010));
	rep(i,n){
		int s,t,c;cin >> s >> t >> c;
		c--;
		a[c][s]++;
		a[c][t + 1]--;
	}
	rep(i,C){
		rep(j,100001){
			a[i][j + 1] += a[i][j];
		}
	}
	rep(i,C){
		rep(j,100001){
			if(a[i][j] >= 2) a[i][j] = 1;
		}
	}
	int ans = 0;
	rep(i,100001){
		int sum = 0;
		rep(j,C) sum += a[j][i];
		ans = max(ans, sum);
	}
	cout << ans << endl;
}


Measured memory_bytes: 12416
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
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++)
using ll = long long;
using pii = pair<int,int>;
using vi = vector<int>;
using vs = vector<string>;
using vll = vector<long long>;
using vpii = vector<pair<int,int>>;
using vivi = vector<vector<int>>;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};

const int MAX = 1100000;
const int MOD = 1000000007;

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

// 二項係数計算
long long 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;
}


int main(void) {
  int x,y;
  cin >> x >> y;
  ll sum = 0;
  COMinit();
  rep2(i,1,min(x,y)+1){
    int s = x-i;
    if(s>i || s<0) continue;
    if(y==2*i-s) {
      //cout << -1 << endl;
      sum += COM(i,s);
      sum %= MOD;
    }
  }
  cout << sum << endl;
         
         
  
}


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

int main() {
    string S;
    int Q;
    bool flag = false;
    cin >> S >> Q;

    rep(_, Q) {
        int t;
        cin >> t;

        if (t == 1)
            flag = !flag;
        else {
            int f;
            char c;
            cin >> f >> c;

            if (f == 1) {
                if (flag)
                    S += c;
                else
                    S.insert(S.begin(), c);
            } else {
                if (flag)
                    S.insert(S.begin(), c);
                else
                    S += c;
            }
        }
    }

    if(flag)
        reverse(S.begin(), S.end());
    cout << S << endl;

    return 0;
}


Measured memory_bytes: 900
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

//struct edge {int from, to, cost;};

constexpr double EPS = 1e-10;
constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;

template<class T> inline T sqr(T x) {return x*x;}

void resolve() {
    int n;
    cin >> n;
    deque<PII> d;
    VI dis(n, n+1);
    d.push_front(MP(1,0));
    int cnt = 0;
    for (;;) {
        auto v = d.front();
        d.pop_front();
        if (dis[v.first] <= v.second) continue;
        dis[v.first] = v.second;
        if (v.first == 0) {
            cout << v.second + 1 << endl;
            break;
        }
        d.push_front(MP((v.first*10)%n, v.second));
        d.push_back(MP((v.first+1)%n, v.second+1));
        if (cnt++ > n) {
            cerr << cnt << endl;
            return;
        }
    }

}

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

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#include<algorithm>
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	ll n;
	cin>>n;
	string s;
	cin>>s;
	ll ans=0;
	for(ll i=0;i<s.size()-3+1;i++){
		string t;
		for(ll j=0;j<3;j++){
			t.push_back(s[j+i]);
		}
		if(t=="ABC"){
			ans++;
		}
	}
	cout <<ans;
	// your code goes here
	return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define what_is(x) cerr << #x << " is " << x << endl;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define st first
#define nd second
#define endl '\n'

typedef long long ll;
typedef pair<int,int> pii;
const int N = 1e2+5;
const int INF = 1e9;
const int MOD = 1e9+7;

int n, a[N], b[N];

int main()
{
	IOS
	// freopen("input.txt", "r", stdin);
	cin >> n;
	for(int i=1; i<n; i++) cin >> b[i];
	a[1] = b[1]; a[2] = b[1];

	for(int i=2; i<n; i++){
		a[i] = min(a[i], b[i]);
		a[i+1] = b[i];
	}
	int sum = 0;
	for(int i=1; i<=n; i++) sum += a[i];
	cout << sum << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int H,W;    
    cin >> H >> W;
    int s[55][55];
    char v ='#'; 
    int count = 0;
    
    for(int i = 1; i <= H; i++){
        for(int j = 1; j <= W; j++){
            char t;
            cin >> t;
            s[i][j] = t;
        }
    }
    
    for(int i = 1; i <= H; i++){
        for(int j = 1; j <= W; j++){
            if(s[i][j] == v){
                if(s[i][j - 1] != v && s[i - 1][j] != v && s[i][j + 1] != v && s[i + 1][j] != v){
                    count++;
                }
            }
        }
    }    

    if(count > 0){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }
    return 0;
}

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

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q>
ostream& operator << (ostream& os, pair<P, Q> p)
{
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  const string X = "UNRESTORABLE";
  string s, t;
  while (cin >> s >> t) {
    string x = "~";
    for (int i = 0; i < s.size(); ++i) {
      int matched = 0;
      string u = s;
      replace(u.begin(), u.end(), '?', 'a');
      for (int j = 0; j < t.size() && i + j < s.size(); ++j) {
        matched += (s[i + j] == '?' || s[i + j] == t[j]);
        u[i + j] = t[j];
      }
      if (matched == t.size()) {
        x = min(x, u);
      }
    }
    cout << (x == "~" ? X : x) << endl;
  }
  
  return 0;
}


Measured memory_bytes: 256
S = input()

if S=="SUN":
    print(7)
elif S=="MON":
    print(6)
elif S=="TUE":
    print(5)
elif S=="WED":
    print(4)
elif S=="THU":
    print(3)
elif S=="FRI":
    print(2)
elif S=="SAT":
    print(1)


Measured memory_bytes: 2940
/*
ID: alec3
LANG: C++14
PROG:
*/


#include <bits/stdc++.h>

#define check(x) cout<<(#x)<<": "<<x<<" ";
#define io ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ss second
#define ff first
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define FOR(i, a, b) for (int i = a; i < b; i++)

typedef long long ll;
typedef unsigned long long ull;

int pct(int x) { return __builtin_popcount(x); }

using namespace std;

ifstream fin("input.txt");
ofstream fout("output.txt");

int main()
{
    io;
    int x;
    cin >> x;

    if (x == 0)
        cout << 1 << endl;
    else
        cout << 0 << endl;

    return 0;
}


Measured memory_bytes: 3640
#include<iostream>
#include<set>

using namespace std;

set<char> hoge(){

    set<char> left;
    string L="qwertasdfgzxcvb";
    for(int i=0; i<L.size(); i++){
        left.insert(L[i]);
    }
    return left;
}

int main(){


    set<char> left=hoge();

    while(1){
        string s;
        cin>> s;
        if(s=="#") break;

        int L=1, R=0;
        int pre;
        int cnt=0;
        for(int i=0; i<s.size(); i++){
            if(i>0){
                if(pre xor left.count(s[i])) cnt++;
            }
            pre=left.count(s[i]);
        }

        cout<< cnt<< endl;

    }

    return 0;
}

Measured memory_bytes: 3044
use v5.18; # strict say state
use warnings;
use List::Util qw(reduce first max min sum0);

chomp (my $n = <STDIN>);
chomp (my @x = split / /, <STDIN>);
my @y = sort {$a <=> $b} @x;
my ($m1, $m2) = ($y[$n / 2 - 1], $y[$n / 2]);
if ($m1 == $m2) {
  for my $i (0..$n-1) {
    say $m1;
  }
  exit;
}
for my $i (0..$n-1) {
  if ($x[$i] <= $m1) {
    say $m2;
  } else {
    say $m1;
  }
}

Measured memory_bytes: 51848
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>

int main(){

  int N, M;
  scanf("%d", &N);
  scanf("%d", &M);
  std::vector<std::pair<int, int > > sc(M);
  for (int i=0; i<M; i++){
    scanf("%d", &sc[i].first);
    scanf("%d", &sc[i].second);
    sc[i].first--;
  }
  long long ans = -1;
  for (int i=(N!=1)?pow(10, N-1):0; i<pow(10,N); i++){
    bool ok = true;
    std::vector<int> digit;
    if (i==0){
      digit.push_back(0);
    }
    int thisvalue = i;
    while(thisvalue>0){
      digit.push_back(thisvalue%10);
      thisvalue = thisvalue/10;
    }
    std::reverse(digit.begin(), digit.end());
    for (int j=0; j<M; j++){
      if(digit[sc[j].first]!=sc[j].second){
        ok = false;
        break;
      }
    }
    if (ok){
      printf("%d\n", i);
      return 0;
    }
  }
  printf("-1\n");
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <set>
#include <unordered_map>
#include <map>
#include <unordered_map>
#include <bitset>
#include <random>
#include <complex>
#include <assert.h>

using namespace std;
typedef long long ll;

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

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

int main() {
	string s; cin >> s;
	int N = s.size();

	vector<ll>dp0(N), dp1(N);
	dp0[N - 1] = s[N - 1] - '0';
	dp1[N - 1] = 10 - (s[N - 1] - '0');

	for (int i = N - 2; i >= 0; i--) {
		int x = s[i] - '0';
		dp0[i] = dp0[i + 1] + x;
		dp1[i] = dp0[i + 1] + 10 - x;

		chmin(dp0[i], dp1[i + 1] + x + 1);
		chmin(dp1[i], dp1[i + 1] + 10 - (x + 1));
	}

	ll ans = min(dp0[0], 1LL + dp1[0]);
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 17028
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

// 

public class ABC133_C // ←Class名変更！！    Program
{
    public static void Main()
    {
        var n = Rla();
        var l = n[0];
        var r = n[1];

        var result = 2019L;

        if (2019 <= (r - l))
        {
            WriteLine($"{0}");
            return;
        }


        for (var i = l; i < r; i++)
        {
            for (var j = i + 1; j <= r; j++)
            {
                var a = (i * j) % 2019;
                if (a < result)
                {
                    result = a;
                }

                if (result == 0)
                {
                    WriteLine($"{result}");
                    return;
                }
            }
        }

        WriteLine($"{result}");
        return;

    } // Main

    public static string Rs() { return ReadLine(); }
    public static char Rc() { var c = ReadLine(); return c[0]; }    //最初の1文字だけ返す
    public static int Ri() { return int.Parse(ReadLine()); }
    public static long Rl() { return long.Parse(ReadLine()); }
    public static char[] Rca() { return ReadLine().ToCharArray(); }
    public static int[] Ria() { return Array.ConvertAll(ReadLine().Split(' '), int.Parse); }
    public static long[] Rla() { return Array.ConvertAll(ReadLine().Split(' '), long.Parse); }
} // Class


Measured memory_bytes: 11220
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;cin>>N;
  vector<int>h(N);
  for(int i=0;i<N;i++){
    cin>>h.at(i);
  }
  vector<long long>ans(N);
  ans.at(0)=0;
  ans.at(1)=abs(h.at(1)-h.at(0));
  for(int i=2;i<N;i++){
    ans.at(i)=min(abs(h.at(i)-h.at(i-1))+ans.at(i-1),abs(h.at(i)-h.at(i-2))+ans.at(i-2));
  }
  cout<<ans.at(N-1)<<endl;
}


Measured memory_bytes: 1408
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)




template <typename T>
class dijkstra
{
private:
    using T_nao = pair<T, pair<T, T>>;
    struct edge{
        long long to;
        T cost;
    };
    long long vertex;   // 頂点数
    vector<vector<edge>> list;  //隣接リスト
    vector<vector<T>> distance;    // 距離
public:
    dijkstra(long long n, T infinity = 1e16);  // nは頂点の数、infinityは初期化に使う値
    void add_edge(long long v1, long long v2, T cost);    // 頂点v1から頂点v2に辺を張る
    void run(long long s, long long t);        // sは開始地点。
    T get_distance(long long v);    // 頂点vへの距離を返す
};

template <typename T>
dijkstra<T>::dijkstra(long long n, T infinity){
    vertex = n;
    list.resize(n);
    distance = vector<vector<T>>(vertex, vector<T>(2, infinity));
}

template <typename T>
void dijkstra<T>::add_edge(long long v1, long long v2, T cost){
    list[v1].push_back({ v2, cost });
}

template <typename T>
void dijkstra<T>::run(long long s, long long t){
    priority_queue<T_nao, vector<T_nao>, greater<T_nao>> que;
    
    que.push({0, {s, 1}});
    
    while(!que.empty()){
        T_nao p = que.top(); que.pop();
        T v = p.second.first;
        T w = p.second.second;

        if(distance[v][w] < p.first) continue;
        distance[v][w] = p.first;
        
        if(v == t) return;
        
        for(auto e : list[v]){
            que.push({p.first + e.cost, {e.to, w}});
            
            if(w == 0)continue;
            
            for(auto ee : list[e.to]){
                que.push({p.first, {ee.to, 0}});
            }
        }
    }
}

template <typename T>
T dijkstra<T>::get_distance(long long v){
    return min(distance[v][0], distance[v][1]);
}

int main() {
    ll n, m;
    cin >> n >> m;
    while(n != 0 || m != 0){
        dijkstra<ll> dik(n);
        REP(i, m){
            ll a, b, c;
            cin >> a >> b >> c;
            a--;b--;
            
            dik.add_edge(a, b, c);
            dik.add_edge(b, a, c);
        }
        
        dik.run(0, n - 1);
        
        cout << dik.get_distance(n - 1) << endl;
        
        cin >> n >> m;
    }
}



Measured memory_bytes: 3140
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
LL read(){
	LL x=0;
	char ch=getchar();
	while (!isdigit(ch))
		ch=getchar();
	while (isdigit(ch))
		x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
	return x;
}
const int N=505;
int n;
vector <int> vp;
LL g[N][N];
LL gcd(LL x,LL y){
	return y?gcd(y,x%y):x;
}
LL lcm(LL x,LL y){
	if (!x||!y)
		return x+y;
	return x/gcd(x,y)*y;
}
int check(int n){
	for (int i=2;i*i<=n;i++)
		if (n%i==0)
			return 0;
	return 1;
}
map <int,int> mp1,mp2;
int g1(int x){
	if (!mp1[x])
		mp1[x]=vp.back(),vp.pop_back();
	return mp1[x];
}
int g2(int x){
	if (!mp2[x])
		mp2[x]=vp.back(),vp.pop_back();
	return mp2[x];
}
int main(){
	n=read();
	if (n==2){
		puts("4 7");
		puts("23 10");
		return 0;
	}
	for (int i=2;vp.size()<n*2;i++)
		if (check(i))
			vp.push_back(i);
	reverse(vp.begin(),vp.end());
	mp1.clear(),mp2.clear();
	for (int i=1;i<=n;i++)
		for (int j=1;j<=n;j++)
			if ((i+j)%2==0)
				g[i][j]=g1(i+j);
	for (int i=n;i>=1;i--)
		for (int j=n;j>=1;j--)
			if ((i+j)%2==0)
				g[i][j]*=g2(i-j);
	for (int i=1;i<=n;i++)
		for (int j=1;j<=n;j++)
			if ((i+j)%2==1){
				g[i][j]=lcm(g[i-1][j],lcm(g[i+1][j],lcm(g[i][j-1],g[i][j+1])))+1;
				assert(g[i][j]<=1000000000000000LL);
			}
	for (int i=1;i<=n;i++,puts(""))
		for (int j=1;j<=n;j++)
			printf("%lld ",g[i][j]);
	return 0;
}


Measured memory_bytes: 5120
n, d = gets.split(" ").map(&:to_i)
array = []
n.times do
    array << gets.split(" ").map(&:to_i)
end

array_com = []

array.combination(2) do |x|
    array_com << x
end

cul_m = 0
result = []

array_com.each do |x|
    d.times do |i|
        cul_m += (x[0][i-1] - x[1][i-1])**2
    end
    result << Math.sqrt(cul_m)
    cul_m =0
end

ans = 0

result.each do |x|
    if x == x.to_i
        ans += 1
    end
end

puts ans



Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define rep(i, n) REP(i, 0, n)
#define REP(i, l, r) for (int i = l; i < r; ++i)
#define int long long
#ifdef DEBUG
#define dout cout
#else
std::stringstream dout;
#endif
using namespace std;
typedef pair<int, int> P;
// other libs

signed main(int argc, char* argv[]) {
	string s, t;
	cin >> s >> t;
	map<char, vector<int>> mp;
	rep(i, s.size()) {
		mp[s[i]].push_back(i);
	}
	rep(i, t.size()) {
		if (mp[t[i]].size() == 0) {
			cout << -1 << endl;
			return 0;
		}
	}
	int ans = mp[t[0]][0];
	REP(i, 1, t.size()) {
		if (upper_bound(mp[t[i]].begin(), mp[t[i]].end(), ans % s.size()) == mp[t[i]].end()) {
			ans = (ans / s.size() + 1) * s.size();
			ans += mp[t[i]][0];
		}
		else {
			int bans=ans;
			ans = ans - (ans % s.size());
			ans += *(upper_bound(mp[t[i]].begin(), mp[t[i]].end(), bans % s.size()));
		}
	}
	cout << ans+1 << endl;
}

Measured memory_bytes: 1852
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) ((int)(x).size())
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

const int A=26;
bool used[A];

signed main()
{
    string s; cin>>s;
    REP(i,SZ(s)) used[s[i]-'a']=1;

    if(SZ(s)<A){
        for(char c='a';c<='z';c++){ 
            if(!used[c-'a']){
                cout<<s+c<<endl; 
                break;
            }
        }
    }
    else{
        int i=A-1; 
        while(i>=1 and s[i-1]>s[i]) i--;
        if(i==0) cout<<-1<<endl;
        else{
            char c='~';
            for(int j=i;j<A;j++) if(s[j]>s[i-1]) c=min(c,s[j]);
            cout<<s.substr(0,i-1)+c<<endl;
        }
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;
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; }


using namespace std;


int main(){
    int N;
    cin >> N;
    ll A[N];
    rep(i, N){
        cin >> A[i];
    }
    set<ll> s;
    bool flag = true;
    rep(i, N){
        if (s.count(A[i]) == 0) {
            s.insert(A[i]);
        } else {
            flag = false;
        }
    }

    if (flag) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
}



Measured memory_bytes: 11136
#include<stdio.h>
int main()
{
char a[3],b[3];
int i,c=1;
scanf("%s%s",a,b);
for(i=0;i<3;i++)
{
if(a[i]!=b[2-i])
c=0;
}
if(c)
printf("YES");
else
printf("NO");
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
using namespace std;

void solve() {
    Vl a(3);
    rep(i, 0, 3) cin >> a[i];
    sort(ALL(a));
    ll b = a[2] - a[0];
    ll c = a[2] - a[1];
    ll mi = min(b, c);
    ll ma = max(b, c);
    ll ans = mi;
    if((ma-mi)%2 == 0) ans += (ma-mi)/2;
    else ans += (ma-mi)/2 + 2;

    cout << ans << endl;

}

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

    solve();
    return 0;
}
 


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
int main()
{
  string s;
  cin >> s;
  rep(i,3){
    if(s[i]==s[i+1]){
      cout << "Bad" << "\n";
      return 0;
    }
  }
  cout << "Good" << "\n";
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>

using namespace std;

int main(){
  string s1, s2, s3; cin >> s1 >> s2 >> s3;
  
  int A = 'A' - 'a';
  char a = s1[0] + A; cout << a;
  a = s2[0] + A; cout << a;
  a = s3[0] + A; cout << a << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
	int a, b, c, x, num=0;

	cin >> a >> b >> c >> x;

	for(int i=0; i<=a; i++)
		for(int j=0; j<=b; j++)
			for(int k=0; k<=c; k++)
				if(i*500 + j*100 + k*50 == x) num++;

	cout << num << endl;

	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<list>
#include<map>
#include<algorithm>

using namespace std;

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

    int sqrtn = sqrt(n);
    cout << sqrtn * sqrtn << endl;

    return 0;
}


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

// input
int N;
vector<int> x, y;


void input() {
    cin >> N;
    x = y = vector<int>(N);
    rep(i, N) cin >> x[i] >> y[i];
}


int main() {
    input();
    vector<int> z, w;
    rep(i, N) {
        z.push_back(x[i] + y[i]);
        w.push_back(x[i] - y[i]);
    }
    sort(z.begin(), z.end());
    sort(w.begin(), w.end());
    int ans = max(z.back() - z[0], w.back() - w[0]);
    cout << ans << endl;
}


Measured memory_bytes: 6660
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long LL;

int main() {
  int H, N; cin >> H >> N;
  int sum = 0;
  for (int i = 0; i < N; ++i) {
    int a; cin >> a; sum += a;
  }
  if (H <= sum) cout << "Yes" << endl;
  else          cout << "No" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
#include <numeric>
#include <array>
#include <queue>
using namespace std;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define pow(x) x*x
#define ll long long
static const int MAX = 10000;
static const ll INFTY = 1e12;

// 四方向への移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

// 入力
// 入力
int H, W, N;
int sx, sy, gx, gy; 
vector<vector<char>> field;
vector<vector<int>> dist;
queue<pair<int, int>> que;

int main() {

    int N, M;
    int s[10][10] = {0};
    bool flag = true;
    int count = 0;

    cin >> N >> M;

    REP(i, M){
        int a, b;
        cin >> a >> b;
        a--; b--;
        s[a][b] = s[b][a] = 1;
    }

    int n;
    vector<int> one_case;
    vector<int> one_case_cpy;
    for (int i = 1; i < N; i++) { // one_case = {1,2,3,...n-1} とする
        one_case.emplace_back(i);
    }
    do {
        one_case_cpy = one_case;
        one_case_cpy.insert(one_case_cpy.begin(), 0);
        flag = true;
        REP(i, N-1){
            if( s[one_case[i]][one_case[i+1]] != 1 ) {
                flag = false;
                break;
            }
        }
        if(flag == true){
            count++;
        }
        
    } while (next_permutation(one_case.begin(), one_case.end()));
    // 順列の最後になるまで one_case を並び替えながらループ

    cout << count << endl;

    return 0;

}
/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         pass System Test!
*/

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int mod=200003;
typedef complex<double> comp;
typedef long long ll;
int n,a[200005],lg[200005],tr[600005],pw[600005];
ll ans=0;
comp s[600005],wk[600005];
void GetTr(int l) {
	for(int i=0; i<l; i++)tr[i]=(tr[i>>1]>>1)|((i&1)?(l>>1):0);
}
void FFT(comp a[],int n,int flag){
	for(int i=0;i<n;i++)if(tr[i]<i)swap(a[i],a[tr[i]]);
	for(int i=1;i<n;i<<=1){
		wk[0]=1;
		if(flag==1)for(int j=1;j<i;j++)wk[j]=exp(comp(0,acos(-1)/i*j));
		else for(int j=1;j<i;j++)wk[j]=exp(comp(0,-acos(-1)/i*j));
		for(int j=0;j<n;j+=(i<<1)){
			for(int k=0;k<i;k++){
				comp t=a[i+j+k]*wk[k];
				a[i+j+k]=a[j+k]-t,a[j+k]+=t;
			}
		}
	}
	if(flag==-1)for(int i=0;i<n;i++)a[i]/=n;
}
int main() {
	for(int i=2,t=1;t<200003;i=i*2%mod,t++)lg[i]=t;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		if(a[i])s[lg[a[i]]]+=1;
	}
	int len=524288;
	for(int i=0,t=1;i<len;i++,t=t*2%mod)pw[i]=t;
	GetTr(len),FFT(s,len,1);
	for(int i=0;i<len;i++)s[i]*=s[i];
	FFT(s,len,-1);
	for(int i=1;i<=n;i++)if(a[i])s[lg[a[i]]*2]-=1;
	for(int i=0;i<len;i++)s[i]/=2;
	for(int i=0;i<len;i++)ans+=pw[i]*(ll)(round(s[i].real()));
	cout<<ans;
	return 0;
}

Measured memory_bytes: 22024
"use strict";
var input=require("fs").readFileSync("/dev/stdin","utf8");
var cin=input.split(/ |\n/),cid=0;
function next(){return +cin[cid++];}
function nextstr(){return cin[cid++];}
function nextbig(){return BigInt(cin[cid++]);}
function nexts(n,a){return a?cin.slice(cid,cid+=n):cin.slice(cid,cid+=n).map(a=>+a);}
function nextm(h,w,a){var r=[],i=0;if(a)for(;i<h;i++)r.push(cin.slice(cid,cid+=w));else for(;i<h;i++)r.push(cin.slice(cid,cid+=w).map(a=>+a));return r;}
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill().map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill().map(x=>"+r+")";return eval(r);}

class unionFind{
  constructor(n){this.a=Array(n+1).fill(-1);}
  root(i){
    return this.a[i]<0?i:this.a[i]=this.root(this.a[i]);
  }
  same(x,y){return this.root(x)===this.root(y);}
  unite(x,y){
    const a=this.a;
    x=this.root(x),y=this.root(y);
    if(x===y)return false;
    if(a[y]<a[x])a[y]+=a[x],a[x]=y;
    else a[x]+=a[y],a[y]=x;
    return true;
  }
  size(i){return -this.a[this.root(i)];}
}

var myOut = main();
if(myOut !== undefined)console.log(String(myOut));

function main(){
  var n = next();
  var m = next();
  var uf = new unionFind(n*2);
  for(var i = 0; i < m; i++){
    var a = next(), b = next();
    uf.unite(a,n+b);
    uf.unite(b,n+a);
  }
  if(uf.same(1,n+1))return n*(n-1)/2-m;
  var b = 1;
  for(var i = 2; i <= n; i++)if(uf.same(1,i))b++;
  return b*(n-b)-m;
}

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

int max(vector<int> k){
  int max=0;
  for(int i=0;i<k.size();i++){
    if(max<k.at(i))max=k.at(i);
  }
  return max;
}

int sum(vector<int> k){
  int sum=0;
  for(int i=0;i<k.size();i++)sum+=k.at(i);
  return sum;
}

int main(){
  int n;
  cin >> n;
  vector<int> L(n);
  for(int i=0;i<n;i++)cin >> L.at(i);
  for(int i=0;i<n;i++){
    if(2*max(L)<sum(L)){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
	int x, y, i;
		for(i=0;i>=0;i++){
		    	scanf("%d %d", &x, &y);
		        if(x==0 && y==0)
		        break;	
		  if(x<=y)
		  printf("%d %d\n", x, y);
		  else 
		  printf("%d %d\n", y, x);
		    
		        
		}	    
	
	return 0;
}




Measured memory_bytes: 2672
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
using namespace std;
using uint = unsigned int;

int main() {
	uint N;
	cin >> N;
	
	vector<string> s(N);
	vector<uint> t(N);
	for(uint i=0; i<N; i++) cin >> s[i] >> t[i];
	
	string X;
	cin >> X;
	
	auto ind_s = distance(s.begin(), find(s.begin(), s.end(), X));
	uint ans = accumulate(t.begin() + ind_s + 1, t.end(), 0);
	
	cout << ans;
	
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import java.util.function.*;

class Main {
    static Scanner scanner = new Scanner();
    static int mod = 1000000007;
    static int inf = 0x7ffffff;

    void solve() {
        String s = scanner.next();
        System.out.println(7 - Arrays.asList("SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT").indexOf(s));
    }

    public static void main(String[]$) throws Exception {
        new Main().solve();
        System.out.flush();
    }
}

class System {
    static PrintWriter out = new PrintWriter(java.lang.System.out);

    static void exit() {
        java.lang.System.exit(0);
    }
}

class Scanner {
    private BufferedReader reader = new BufferedReader(new InputStreamReader(java.lang.System.in), 0x10000);
    private StringTokenizer tokenizer;

    String next() {
        try {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                tokenizer = new StringTokenizer(reader.readLine());
            }
        } catch (IOException ignored) {
        }
        return tokenizer.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    char[][] nextCharArray(int n, int m) {
        char[][] a = new char[n][m];
        for (int i = 0; i < n; i++) {
            a[i] = next().toCharArray();
        }
        return a;
    }

    int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = nextInt();
        }
        return a;
    }

    int[] nextIntArray(int n, IntUnaryOperator op) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = op.applyAsInt(nextInt());
        }
        return a;
    }

    long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++) {
            a[i] = nextLong();
        }
        return a;
    }

    long[] nextLongArray(int n, LongUnaryOperator op) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++) {
            a[i] = op.applyAsLong(nextLong());
        }
        return a;
    }
}


Measured memory_bytes: 23508
input_arr = [input() for i in range(2)]
N = input_arr[0]
p_arr = input_arr[1].split(' ')
 
k = 0
for i in range(len(p_arr)):
    if int(p_arr[i]) == i + 1:
        pass
    else:
        k += 1
if k <= 2:
    print("YES")
else:
    print("NO")

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

int main() {
	while(true){
		int n,k;
		cin>>n>>k;
		if(n==0 && k==0){
			break;
		}
		
		int cards[k];
		bool checked[k];
		for(int i=0;i<k;i++){
			cin>>cards[i];
			checked[i]=false;
		}
		
		sort(cards,cards+k);
		
		int start,ans=0;
		for(int i=0;i<k;i++){
			int sum=0;
			if(cards[0]==0){
				checked[0]=true;
			}
			if(checked[i]==false){
				sum++;
				start=cards[i];
				for(int j=i;j<k;j++){
					if(cards[j+1]==start+1){
						sum++;
						start++;
						if(cards[0]!=0 || checked[0]==true){
							checked[j+1]=true;
						}
					} else if(checked[0]==true){
						sum++;
						start++;
						j--;
						checked[0]=false;
					} else{
						ans=max(ans,sum);
						break;
					}
				}
			}
		}
		
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 1568
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
using namespace std;
int main(){
    int n,a,b;
    cin >> n >> a >> b;
    cout << min(a*n,b) << endl;
}

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

int main() {
  int N,K,tmp,ans=0;
  cin >> N;
  vector<int> vec(N+2);
  for(int i = 1; i <= N; i++){
    cin >> tmp;
    vec.at(tmp) = i;
  }
  for(int i = 1; i <N; i++) cout << vec.at(i) << " ";
  cout << vec.at(N);
}

Measured memory_bytes: 1152
#include <stdio.h>
#include <ctype.h>
 
int stack[102]; int top;
char buf[2000];
 
int main()
{
    int  v1, v2;
    char *p;
 
    fgets(p=buf, 500, stdin);
    top = 0;
    while (*p >= ' ') {
        while (isspace(*p)) p++;
        if (isdigit(*p)) {
            v1 = 0;
            while (isdigit(*p)) v1 = 10*v1 + (*p++ & 0xf);
            stack[top++] = v1;
        } else {
            v1 = stack[--top];
            v2 = stack[--top];
            if      (*p == '+') v2 += v1;
            else if (*p == '-') v2 -= v1;
            else if (*p == '*') v2 *= v1;
            stack[top++] = v2;
            p++;
        }
    }
    printf("%d\n", stack[--top]);
    return 0;
}


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

#ifdef NON_SUBMIT
#define TEST(n) (n)
#define tout cerr
#else
#define TEST(n) ((void)0)
#define tout cin
#endif

using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	TEST(freopen("input.txt","r",stdin));
	TEST(freopen("output.txt","w",stdout));
	TEST(freopen("debug.txt","w",stderr));
	int N, cnt=0, ans=0, p, a;
	cin>>N>>p;
	while(--N) {
		cin>>a;
		if(p>=a) ans=max(ans,++cnt);
		else cnt=0;
		p=a;
	}
	cout<<ans<<'\n';
	return 0;
}

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

typedef long long ll;

priority_queue <ll> pqlo;
priority_queue <ll, vector<ll>, greater<ll> > pqup;

ll N, l, r, lazylo, lazyhi, ans;

int main() {
	cin >> N;
	for (int i = 1; i <= N; i++) {
		cin >> l >> r;
		if (i == 1) {
			pqup.push(l);
			pqlo.push(l);
			lazyhi += r-l;
			continue;
		}
		
//		ll panjang = r-l;
		lazylo -= r-l;
		
		if (l <= pqlo.top()+lazylo) {
			ll geser = pqlo.top()+lazylo;
			ans += geser-l;
			pqlo.push(l-lazylo);
			pqlo.push(l-lazylo);
			pqlo.pop();
			pqup.push(geser-lazyhi);
		} else if (l >= pqup.top()+lazyhi) {
			ll geser = pqup.top()+lazyhi;
			ans += l-geser;
			pqup.push(l-lazyhi);
			pqup.push(l-lazyhi);
			pqup.pop();
			pqlo.push(geser-lazylo);
		} else {
			pqlo.push(l-lazylo);
			pqup.push(l-lazyhi);
		}
		lazyhi += r-l;
	}
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 2076
#include<stdio.h>
#include<stdlib.h>

int del_Recipies(int del,int count,int n,int m,int p[],int Recipies[500][500]);

int main()
{
	int n,m,Recipies[500][500]={0},MAX[500],min_del_Recipies,c,flag,*p,count;
	
	while(1)
	{
		scanf("%d %d",&n,&m);
		if(n==0&&m==0) break;
		min_del_Recipies=-1;
		for(int i=0;i<m;i++) MAX[i]=0;
		for(int i=0;i<n;i++)
		{
			for(int t=0;t<m;)
			{
				Recipies[i][t]=getchar();
				if(Recipies[i][t] != '\n'&& Recipies[i][t] != ' ')
				{
					Recipies[i][t]-='0';
					MAX[t]+=Recipies[i][t];
					t++;
				}
			}
		}
		flag=1;
		//作る際に必要な材料数がすべての材料で2で割り切れたなら、その時のレシピ数になる
		for(int t=0;t<m;t++)
		{
			if(MAX[t]%2)
			{
				flag=0;
				break;
			}
		}
		if(flag) min_del_Recipies=0;
		else
		{
			p=(int*)malloc(m*sizeof(int));
			//すべて作った時に必要な材料からレシピを減らしていく
			//減らしていく数を順に増やしていき、その減らす数の時のすべての減らし方を試す
			
			for(int del=1;del<n;del++)//何個引くか del個 引いた個数 count
			{
				for(int i=0;i<m;i++) p[i]=MAX[i];
				count=0;
				flag=del_Recipies(del,count,n,m,p,Recipies);//何個引くか del個 引いた個数 count
				//del個減らしたときにすべての材料が2で割り切れるものがあったら 1を返す なかったら 0を返す
				if(flag)
				{
					min_del_Recipies = del;//delで割り切れたとき
					break;
				}
			}
			if(min_del_Recipies==-1)min_del_Recipies=n;//どれも割り切れなかったとき
			free(p);
		}
		printf("%d\n",n-min_del_Recipies);//全体から割り切れるまでに引いた個数を引くと求まる
	}
	return 0;
}

int del_Recipies(int del,int count,int n,int m,int p[],int Recipies[500][500])
{
	//引く個数=del 引いた個数=count何種類目 i
	int flag=1;
	for(;count<n && n-count>=del;count++)
	{
		
		if(del==1)
		{
			flag=1;
			for(int t=0;t<m;t++)
			{
				p[t]-=Recipies[count][t];
				if(p[t]%2!=0)
				{
					flag=0;
					p[t]+=Recipies[count][t];
					break;
				}
				p[t] += Recipies[count][t];
			}
			if(flag) return 1;
			else continue;
		}
		else 
		{
			//残りの引く個数が1になるまで再起
			//pから今回引くRecipiesを引いてから次に渡す
			for(int t=0;t<m;t++) p[t]-=Recipies[count][t];
			//引く個数delを一つ減らす　引いた個数countを一つ増やす
			if(del_Recipies(del-1,count+1,n,m,p,Recipies)) return 1;
			for (int t = 0; t<m; t++) p[t] += Recipies[count][t];
		}
		
	}
	return 0;
}


Measured memory_bytes: 2752
from collections import deque

s = deque(input())
q = int(input())
rev = False

for _ in range(q):
    t = input()
    if t[0] == "2":
        _, f, c = t.split()
        if rev:
            if f == "2": s.appendleft(c)
            else: s.append(c)
        else:
            if f == "1": s.appendleft(c)
            else: s.append(c)
    else: rev = not rev

if rev: s.reverse()
print("".join(s))


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

int main() {
	string s;	cin >> s;
  	int n = s.size();	vector<vector<int>> pot(D,vector<int>(n));
  	rep(i,n){
    	if(s[i] == 'R') pot[0][i] = i+1;
      	else pot[0][i] = i-1;
    }
  	rep(i,D-1)rep(j,n) pot[i+1][j] = pot[i][pot[i][j]];
  	
  	vector<int> v(n);	rep(i,n) v[i] = i;
  	ll k = pow(10,5);
  	for(int i = D-1; i >= 0; i--){
      	ll dg = 1ll<<i;
      	if(dg <= k){
        	rep(j,n) v[j] = pot[i][v[j]];
      		k -= dg;
        }
    }
  	vector<int> ans(n);
  	rep(i,n) ans[v[i]]++;
  	rep(i,n-1) cout << ans[i] << " ";
  	cout << ans[n-1] << endl;
}
 


Measured memory_bytes: 14328
#include<iostream>
#include<vector>
#include<string>
int main() {
	int n,m;
	std::string y;
	std::vector<std::string> s;
	while (true)
	{
		std::cin >> n;
		if (n == 0) {
			break;
		}
		std::string a;
		std::vector<std::string>j(n), k(n);
		for (int l = 0; l < n; ++l) {
			std::cin >> j[l] >> k[l];
		}
			std::cin >> m;
			for (int i = 0; i < m; ++i) {
				std::cin >> y;
				for (int l = 0; l < n; ++l) {
					if (y == j[l]) {
						a += k[l];
							break;
					}
					if(l+1==n)a += y;
				}
			}
		j.clear();
		k.clear();
		s.push_back(a);
	}
	for (int i = 0; i < s.size(); ++i) {
		std::cout << s[i]<<std::endl;
	}
	return 0;
}

Measured memory_bytes: 1340
/*
░░░░██████████████████
░░▄███████▀▀▀▀▀▀███████▄
░▐████▀▒ManavJ07▒▀██████▄
░███▀▒▒▒▒BITS▒▒▒▒▒▒▀█████
░▐██▒▒▒.........▒▒▒▒▒████▌
░▐█▌▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒████▌
░░█▒▄▀▀▀▀▀▄▒▒▄▀▀▀▀▀▄▒▐███▌
░░░▐░░░▄▄░░▌▐░░░▄▄░░▌▐███▌
░▄▀▌░░░▀▀░░▌▐░░░▀▀░░▌▒▀▒█▌
░▌▒▀▄░░░░▄▀▒▒▀▄░░░▄▀▒▒▄▀▒▌
░▀▄▐▒▀▀▀▀▒▒▒▒▒▒▀▀▀▒▒▒▒▒▒█
░░░▀▌▒▄██▄▄▄▄████▄▒▒▒▒█▀
░░░░▄██████████████▒▒▐▌
░░░▀███▀▀████▀█████▀▒▌
░░░░░▌▒▒▒▄▒▒▒▄▒▒▒▒▒▒▐
░░░░░▌▒▒▒▒▀▀▀▒▒▒▒▒▒▒▐
*/
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define ll long long
#define dd double
#define endl "\n"
#define MOD 998244353
#define nl cout<<"\n"
#define rt ll Q[100005]={0}
#define mp make_pair
#define test() ull t;cin>>t;while(t--)
#define pb push_back
#define ff first	
#define ss second
#define all(v) v.begin(),v.end()
#define s(ar,n) sort(ar,ar+n)
#define rs(ar,n) sort(ar, ar+n, greater<ll>()) 
#define oa(a,n) for(ll i=0;i<n;i++)cout<<a[i];nl
#define cn(a,n) for(ll i=0;i<n;i++)cin>>a[i];
#define ov(a,n) for(ll i=n-1;i>=0;i--)cout<<a[i]<<" ";nl
#define maxa(ar,N) *max_element(ar,ar+N)
#define mina(ar,N) *min_element(ar,ar+N)
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
ll powe(ll x,ll y){ll res=1;while(y>0){if(y&1)res=res*x;y=y>>1;x=x*x;}return res;}
ll mpowe(ll n,ll m){if(m==0)return 1;ll t=powe(n,m/2);t%=MOD;if(m%2==0)return (t*t)%MOD;return (((t*t)%MOD)*n)%MOD;}
ll logtwo(ll n){if(n==1)return 0;return logtwo(n/2)+1;}
int main()
{
    fastio();
    ll N,M;
    cin>>N>>M;
    ll g=__gcd(N,M);
    ll ans=(N*M)/g;
    cout<<ans;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
using namespace std;
int main(){
	int n,a[3],i,j,k,box;
	cin>>n;
	for(i=0;i<n;i++){
		for(j=0;j<3;j++)cin>>a[j];
		for(j=0;j<2;j++){
			for(k=j+1;k<3;k++){
				if(a[j]<a[k]){
					box=a[j];
					a[j]=a[k];
					a[k]=box;
				}
			}
		}if(a[0]*a[0]==(a[1]*a[1])+(a[2]*a[2]))cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
	return 0;
}

Measured memory_bytes: 3088
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<array>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<functional>
#include<limits>
#include<list>
#include<map>
#include<numeric>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<unordered_map>
#include<queue>
#include<vector>
using namespace std;

//#define int long long
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define dump(o) if(DEBUG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DEBUG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
const int MOD = 1e9 + 7;
const bool DEBUG = false;

signed main() {
	int P[1010] = {};
	static int a[2000000] = {}; //1000010
	for (int N, M; cin >> N >> M&&N;) {
		memset(a, 0x3f, sizeof(a));
		rep(i, 0, N)cin >> P[i];
		P[N] = 0;
		N++;
		rep(i, 0, N)rep(j, 0, N) {
			a[i*N + j] = P[i] + P[j];
		}
		dumpc(a);
		sort(a, a + N*N);
		dumpc(a);
		int ans = 0;
		rep(i, 0, N*N) {
			if (a[i] > M)break;
			int add = a[upper_bound(a, a + N*N, M - a[i]) - a - 1];
			ans = max(ans, a[i] + add);
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 10924
#include<cstdio>
// printf scanf //
#include<cstring>
// char型の文字列を操作できるもの //

int main(){
    char str[1001];
    
    while(1){
        scanf("%s",str);
        if (str[0] == '0') break;
        int sum = 0;
        for (int i=0; i<strlen(str); i++){
            sum += (str[i] - '0');
        }
        printf("%d\n",sum);
    }
    return 0;
}



Measured memory_bytes: 2700
#include <stdio.h>

int i;
int a, b;
int n;

int main() {
    while (1) { 
        a = 0;
        b = 0;

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

        for (i=0; i<n; i++) {
            int l, r;
    
            scanf("%d %d", &l, &r);
            if (l > r) {
                a += l + r;
            } else if (l < r) {
                b += l + r;
            } else {
                a += l;
                b += r;
            }
        }
    
        printf("%d %d\n", a, b);
   }
}

Measured memory_bytes: 1028
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define N 3010
typedef long long ll;
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) int(x.size())
#define OUT(a) cout<<(a)<<endl
typedef pair<int,int> P;
#define INF 1000000000000
const int MAX = 1000000;
const int MOD = 1000000007;
int main(){
	int a,b;
    cin>>a>>b;
    OUT(max(0,a-2*b));
    return 0;
}

Measured memory_bytes: 256