akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <algorithm>
#include <vector>

using namespace std;

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

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

int main()
{
	int w, h;
	while(scanf("%d%d", &w, &h), w){
		vvi field(h, vi(w));
		rep(i, h){
			rep(j, w){
				scanf("%d", &field[i][j]);
			}
		}
		
		vvi dp(h, vi(w, 0));
		rep(i, w){
			dp[0][i] = !field[0][i];
		}
		
		reep(i, 1, h){
			rep(j, w){
				if(field[i][j] == 1)
					continue;
				
				if(i >= 2){
					dp[i][j] += field[i-2][j] == 2 ? dp[i-2][j] : 0;
				}
				reep(k, field[i][j] == 0 ? -1 : 0, field[i][j] == 0 ? 2 : 1){
					int px = j + k;
					if(px < 0 || w <= px)
						continue;
					if(field[i-1][px] != 0)
						continue;
					dp[i][j] += dp[i-1][px];
				}
			}
		}
		
		int sum = 0;
		rep(i, w){
			sum += dp[h-1][i];
			if(h > 1)
				sum += field[h-2][i] == 2 ? dp[h-2][i] : 0;
		}
		printf("%d\n", sum);
	}
	return 0;
}

Measured memory_bytes: 0
s=str(input())
a=int(s[0])
b=int(s[1])
c=int(s[2])
d=int(s[3])

if a+b+c+d==7:
  print('{}+{}+{}+{}=7'.format(a,b,c,d))
elif a-b+c+d==7:
  print('{}-{}+{}+{}=7'.format(a,b,c,d))
elif a-b-c+d==7:
  print('{}-{}-{}+{}=7'.format(a,b,c,d))
elif a-b+c-d==7:
  print('{}-{}+{}-{}=7'.format(a,b,c,d))
elif a-b-c-d==7:
  print('{}-{}-{}-{}=7'.format(a,b,c,d))
elif a+b-c+d==7:
  print('{}+{}-{}+{}=7'.format(a,b,c,d))
elif a+b-c-d==7:
  print('{}+{}-{}-{}=7'.format(a,b,c,d))
else:
  print('{}+{}+{}-{}=7'.format(a,b,c,d))



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

int a, b, c, k, maks, n;
int main()
{
    cin >> a >> b >> c >> k;
    for (int i = 1; i <= k; i++)
    {
        if (a > b && a > c)
        {
            a *= 2;
            maks = a + b + c;
        }
        else if (b > a && b > c)
        {
            b *= 2;
            maks = a + b + c;
        }
        else
        {
            c *= 2;
            maks = a + b + c;
        }
        
    }
    cout << maks << endl;
}

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

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

  vector<int64_t> a(n);
  for(int i=0; i<n; i++){
    cin >> a[i];
  }
  
  for(int j=0; j<n-k; j++){
    if(a[k+j] > a[j]){
      cout << "Yes" << endl;
    }
    else{
     cout << "No" << endl;
    }
  }
  
  
}


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

int solve(vector<int> &a, vector<int> &b, int d = 0){
  if(d == a.size()){
    for (int i = 0; i < a.size(); i++) {
      if((b[i]&1) == 0)return 1;
    }
    return 0;
  }
  int res = 0;
  for (int i = -1; i <= 1; i++) {
    b[d] = a[d] + i;
    res += solve(a, b, d + 1);
  }
  return res;
}

int main(){
  int n;
  std::cin >> n;
  vector<int> a(n), b(n);
  for (int i = 0; i < n; i++) {
    std::cin >> a[i];
  }
  std::cout << solve(a, b) << std::endl;
  return 0;
}


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

typedef long long ll;
ll h,w,dp[1000][1000];
const ll MOD = 1e9+7;
char grid[1000][1000];

ll solve(int i, int j) {
    if (i>=h or j>=w) return 0;
    if (i==h-1 and j==w-1) return 1;
    if (grid[i][j] == '#') return 0;
    if (dp[i][j] != -1) return dp[i][j];

    dp[i][j] = (solve(i+1, j) + solve(i, j+1))%MOD;
    return dp[i][j];
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);

    memset(dp,-1,sizeof dp);
    cin>>h>>w;
    for (int i=0; i<h; i++)
        for (int j=0; j<w; j++)
            cin>>grid[i][j];

    cout << solve(0,0) << '\n';
    return 0;
}

Measured memory_bytes: 9088
#include <bits/stdc++.h>
using namespace std;
#define __ <<" "<<
#define ___ <<" "
#define bash push_back
#define ALL(x) x.begin(),x.end()
//#define int long long

struct IoSetup {
    IoSetup() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout <<fixed<<setprecision(12);
        cerr <<fixed<<setprecision(12);
    }
}IoSetup;

typedef long long ll;
typedef pair < int , int >  pii;
static constexpr const signed int INF = 0x3f3f3f3f;
static constexpr const signed long long LINF = 0x3f3f3f3f3f3f3f3fLL;
static constexpr const signed int SMOD = 1000000007;
static constexpr const signed int NMOD = 998244353;
static constexpr const signed int dx[]={1,0,-1,0,1,1,-1,-1};
static constexpr const signed int dy[]={0,-1,0,1,-1,1,-1,1};

inline bool inside(int x,int y,int w,int h){return (x>=0 && y>=0 && x<w && y<h);}
template<class T>bool chmax(T &a, const T &b){return(a=max(a,b))==b;}
template<class T>bool chmin(T &a, const T &b){return(a=min(a,b))==b;}
inline int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}



signed main() {

    int n, t;
    cin >> n;
    vector<int> a(n+1, 0);
    for(int i = 1; i < n; i++) {
        cin >> t;
        a[t]++;
    }
    for(int i = 1; i <= n; i++) {
        cout << a[i] << "\n";
    }
    
    
    return 0;
}



Measured memory_bytes: 3972
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from fractions import Fraction
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations, accumulate
from operator import add, mul, sub, itemgetter, attrgetter


import sys
# sys.setrecursionlimit(10**6)
# readline = sys.stdin.buffer.readline
readline = sys.stdin.readline

INF = 2**62-1


def read_int():
    return int(readline())


def read_int_n():
    return list(map(int, readline().split()))


def read_float():
    return float(readline())


def read_float_n():
    return list(map(float, readline().split()))


def read_str():
    return readline().strip()


def read_str_n():
    return readline().strip().split()


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.perf_counter()
        ret = f(*args, **kwargs)
        e = time.perf_counter()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(S, X, Y):
    n = 0
    m = []
    for c in S:
        if c == 'T':
            m.append(n)
            n = 0
        else:
            n += 1
    else:
        m.append(n)

    X -= m.pop(0)
    ym = m[::2]
    xm = m[1::2]

    memo = {0}
    for dx in xm:
        nm = set()
        for x in memo:
            nm.add(x+dx)
            nm.add(x-dx)
        memo = nm
    if X not in memo:
        return 'No'

    memo = {0}
    for dy in ym:
        nm = set()
        for y in memo:
            nm.add(y+dy)
            nm.add(y-dy)
        memo = nm
    if Y not in memo:
        return 'No'

    return 'Yes'




def main():
    S = read_str()
    X, Y = read_int_n()
    print(slv(S, X, Y))


if __name__ == '__main__':
    main()


Measured memory_bytes: 92252
#include<bits/stdc++.h>
using namespace std;
 
int main()
{
    string s;
    cin>>s;
    sort(s.begin(),s.end());
    if(s[0]==s[1]&&s[2]==s[3]&&s[0]!=s[2])
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <functional>
#include <map>
#include <queue>
#include <list>
#include <set>
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
using namespace std;
using ll = long long;
const int INF = 1e9 + 1;
ll MOD = 1e9+7;

string N;
ll ans = 0;

void rec(string num){
    if(num != "" && stoi(num) <= stoi(N) && num.find('3') != std::string::npos && num.find('5') != std::string::npos && num.find('7') != std::string::npos){
        ans++;
    }

    if(num.size() == N.size()){
        return;
    }
    
    rec(num + '3');
    rec(num + '5');
    rec(num + '7');
    return;
}

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

    cin >> N;
    rec("");
    cout << ans << endl;
    
    return 0;
}


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




typedef long long ll;
#define PI 3.14159265359
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define mp make_pair
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define decp(n) cout<<fixed<<setprecision((int)n)
#define _GLIBCXX_DEBAC
#include <functional>
/*map<Keyの型, Valueの型> 変数名;
queue<型> 変数名;
priority_queue<型> 変数名;
priority_queue<型, vector<型>, greater<型>> 変数名;*/
//copy(v1.begin(), v1.end(), back_inserter(v2));
using namespace std;

ll gcd(ll a, ll b) {
	ll c;
	if (a < b) {
		c = a; a = b; b = c;
	}
	while (b != 0) {
		c = a % b; a = b; b = c;
	}
	return a;
}

ll lcm(ll a, ll b) {
	ll c;
	c = a * b / gcd(a, b);
	return c;
}

int sort_greater(int m, int n) {
	vector<int> a(m);
	for (int i = 0; i < m; i++) {
		cin >> a[i];
	}
	sort(a.begin(), a.end(), greater<int>());
	for (int i = 0; i < n; i++) {
		cout << a[i];
	}
	return 0;
}

int bubblesort(int a[], int n) {
	int sw = 0;
	bool flag = 1;
	for (int i = 0; flag; i++) {
		flag = 0;
		for (int j = n - 1; j >= i + 1; j--) {
			if (a[j] < a[j - 1]) {
				swap(a[j], a[j - 1]);
				flag = 1;
				sw += 1;
			}
		}
	}
	return sw;
}

int a_z()
{
	for (int i = 0; i <= ('Z' - 'A'); i++) {
		cout << (char)('A' + i);
	}
	return 0;
}

int selecttionsort(int a[], int n) {
	int t, sw = 0, minj;
	for (int i = 0; i < n - 1; i++) {
		minj = i;
		for (int j = 0; j < n - 1; j++) {
			if (a[j] < a[minj]) {
				minj = j;
			}
		}
		t = a[i]; a[i] = a[minj]; a[minj] = t;
		if (i != minj) sw += 1;

	}
	return sw;
}

bool is_prime(int x) {
	if (x <= 1) return false;
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0) return false;
	}
	return true;
}

const ll mod = 1000000007;


map<string, int> memo;

using P=pair<int, int>;




/*void dfs(int v, int p = -1) {
	for (int u : to[v]) {
		if (u == p) continue;
		ans[u] += ans[v];
		dfs(u, v);
	}
}*/
ll findIndex(int value, vector<ll> a)
{

	for (ll i = 0; i < (ll)a.size(); i++) {
		if (a[i] == value) {
			return i;
		}
	}
	return -1;
}
ll nCr(ll n, ll r) {
	ll a = 1;
	for (ll i = n; i > n - r; --i) {
		a = a * i;
	}
	for (ll i = 1; i < r + 1; ++i) {
		a = a / i;
	}
	return a;
}

void comb(vector<vector <long long int> >& v) {
	for (ll i = 0; i < v.size(); i++) {
		v[i][0] = 1;
		v[i][i] = 1;
	}
	for (ll k = 1; k < v.size(); k++) {
		for (ll j = 1; j < k; j++) {
			v[k][j] = (v[k - 1][j - 1] + v[k - 1][j]);
		}
	}
}



int main() {
	ll n, x;
	cin >> n >> x;
	vector<ll> a(n);
	rep(i, n)cin >> a[i];
	
	rep(i, n) {
		a[i] = abs(a[i] - x);
	}
	if (n == 1) {
		cout << a[0] << endl;
		return 0;
	}
	ll ans = 1e9;
	rep(i, n - 1) {
		ans = min(ans, gcd(a[i], a[i + 1]));
	}
	cout << ans << endl;
	return 0;
}













Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m;
  cin>>n>>m;
  vector<vector<int>> s(n);
  vector<int> p(n,0);
  for(int _=0;_<m;_++){
    int x,y;
    cin>>x>>y;
    x--;
    y--;
    s.at(x).push_back(y);
    p.at(y)++;
  }
  vector<int> dp(n,-1);
  queue<int> q;
  for(int i=0;i<n;i++)
    q.push(i);
  for(int i=0;i<n&&!q.empty();i++){
    vector<int> x;
    while(!q.empty()){
      int v=q.front();
      q.pop();
      if(p.at(v)!=0||i<=dp[v])
        continue;
      dp[v]=i;
      x.push_back(v);
    }
    for(int v:x){
      for(int c:s.at(v)){
        q.push(c);
        p.at(c)--;
      }
    }
  }
  int ma=0;
  for(int i=0;i<n;i++)
    ma=max(ma,dp[i]);
  cout<<ma<<endl;
}

Measured memory_bytes: 9764
#include<bits/stdc++.h>
#include<iostream>
#include<cmath>
#include<vector>
#include<string>
#include<queue>
#include<set>
#include<map>
#include<algorithm>
#include<functional>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll, int> plli;
typedef pair<int, pii> pipii;
typedef vector<vector<int> > mati;
typedef vector<vector<double> > matd;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vector<vector<bool>>> vvvb;

#define FOR(i,x,y) for(ll i=(ll)x; i<(ll)y; ++i)
#define REP(i,y) FOR(i, 0, y)
#define RFOR(i,x,y) for(ll i=(ll)x; i>=(ll)y; --i)
#define RREP(i,x) RFOR(i, x, 0)

template <typename T>
void vec_print(vector<T> VEC){
  REP(i, VEC.size()){
    cout << VEC[i] << " ";
  }
  cout << "\n";
};

template <typename T>
void mat_print(vector<vector<T> > MAT){
  REP(i, MAT.size()){
    REP(j, MAT[i].size()){
      cout << MAT[i][j] << " ";
    }
    cout << "\n";
  }
};

template <typename CLASS1, typename CLASS2>
class HOGE{
  public:
    CLASS1 key;
    CLASS2 value;
    HOGE(void){
      return;
    };
    HOGE(CLASS1 key, CLASS2 value){
      this->key = key;
      this->value = value;
    };
    ~HOGE(void){
      return;
    };

    void print(void){
      cout << "key : " << key << ", value : " << value << "\n";
      return;
    };
    
    bool operator==(const HOGE &obj){
      return (this->value == obj.value);
    };
    bool operator<(const HOGE &obj){
      return (this->value < obj.value);
    };
    bool operator>(const HOGE &obj){
      return (this->value > obj.value);
    };
};

constexpr int INF = (1<<30);
constexpr ll INFLL = 1LL<<62;
constexpr long double EPS = 1e-12;
constexpr ll MOD = (ll)((1E+9)+7);

int main(){
  cin.tie(0); // cut the cin and cout (default, std::flush is performed after std::cin)
  ios::sync_with_stdio(false); // cut the iostream and stdio (DON'T endl; BUT "\n";)

  ll A, B;
  cin >> A >> B;

  cout << max(max(A+A-1, B+B-1), A+B) << "\n";

  return 0;
}


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

int main(){
	string s;
	cin >> s;
	int cnt = 0;
	int i = 1;
	rep(i, s.size()){
		if(i == s.size() - 1) cnt++;
		else if(s[i] == s[i+1]){
			if(i == s.size() - 2){
				cnt++;
				break;
			}else{
				cnt += 2;
				i += 2;
			}
		}else{
			cnt++;
		}
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 3736
#include<iostream>
using namespace std;
int main() {


	int n;
	cin >> n;
	int value = n % 10;
	if (value == 2 || value == 4 || value == 5 || value == 7 || value == 9) {
		cout << "hon" << endl;
	}
	else if (value == 0 || value == 1 || value == 6 || value == 8)
		cout << "pon" << endl;
	else
		cout << "bon" << endl;
	return 0;
}

Measured memory_bytes: 3132
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i,s,n)for(int i = s;i<n;i++)
#define repe(i,s,n)for(int i = s;i<=n;i++)

int main() {
	ll N; cin >> N;
	map<string, int> s;
	rep(i, 0, N) {
		string str; cin >> str;
		s[str]++;
	}

	ll M; cin >> M;
	rep(i, 0, M) {
		string str; cin >> str;
		s[str]--;
	}

	int maxV = 0;
	for (map<string, int>::iterator it = s.begin(); it != s.end(); it++) {
		maxV = max(maxV, it->second);
	}
	cout << maxV << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int K;
  cin >> K;
  ll ans = 0;
  for (int i = 1; i <= K; i++) {
    
    for (int j = 1; j <= K; j++) {
      
        for (int k = 1; k <= K; k++) {
        if (__gcd(i,j) != 1) {
          ans += __gcd(__gcd(i,j),k);
        }
        else {
          ans += 1;
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3636
h,w=map(int,input().split())
ans=h*w
for i in range(1,h):
  a=i*w
  b=(h-i)*int(w/2)
  c=h*w-a-b
  if ans>(max(a,b,c)-min(a,b,c)):
    ans=max(a,b,c)-min(a,b,c)
for i in range(1,h):
  a=i*w
  b=w*int((h-i)/2)
  c=h*w-a-b
  if ans>(max(a,b,c)-min(a,b,c)):
    ans=max(a,b,c)-min(a,b,c)

for i in range(1,w):
  a=i*h
  b=(w-i)*int(h/2)
  c=h*w-a-b
  if ans>(max(a,b,c)-min(a,b,c)):
    ans=max(a,b,c)-min(a,b,c)
for i in range(1,w):
  a=i*h
  b=h*int((w-i)/2)
  c=h*w-a-b
  if ans>(max(a,b,c)-min(a,b,c)):
    ans=max(a,b,c)-min(a,b,c)
print(ans)

Measured memory_bytes: 3064
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10**9 + 7

n = ri()
li = sorted([ri() for _ in range(n)])
print(sum(li[:-1]) + li[-1]//2)









Measured memory_bytes: 26788
require 'set'

class Hash
  def push(key, value)
    self[key] = [] if self[key] == nil
    self[key].push(value)
  end
end

class Array
  def lower_bound(value)
    left = -1;
    right = self.length;
    while left + 1 < right
      mid = left + (right - left) / 2;
      if self[mid] >= value
        right = mid
      else
        left = mid
      end
    end
    right
  end

  def unique
    res = [self.first]
    each_cons(2) do |a, b|
      if a != b
        res.push(b)
      end
    end
    res
  end
end

def get_ints
  gets.split.map(&:to_i)
end

def get_ints_minus_one
  get_ints.map { |x| x - 1 }
end

def get_int
  gets.chomp.to_i
end

a = gets.chomp

if a == a.upcase
  puts 'A'
else
  puts 'a'
end


Measured memory_bytes: 14376
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v)   (v).begin(),(v).end()
#define debug(x) cerr<<#x<<": "<<(x)<<endl
#define INF      (int)1e9
#define EPS      (double)1e-9
#define MOD      ((int)1e9+7)
using namespace std;
typedef long long     llong;
typedef vector<int>   vi;
typedef vector<vi >   vvi;
typedef vector<vvi >  vvvi;
typedef pair<int,int> pii;
template<class Type> void line(const Type &a){int cnt=0;for(const auto &elem:a){if(cnt++)cout<<' ';cout<<elem;}cout<<endl;}

int main(){
	const long double inf=1e18;
	
	int n;
	cin>>n;
	
	vector<llong> a(n);
	REP(i,n) cin>>a[i];
	sort(ALL(a));
	
	llong ans=1;
	REP(i,n){
		if(ans>inf/a[i]){
			cout<<-1<<endl;
			return 0;
		}
		
		ans*=a[i];
	}
	
	cout<<ans<<endl;
}

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

#define int long long
#define double long double

using namespace std;

#define REP(i, a, b) for (int(i) = (a); i < (b); (i)++)
#define rep(i, n) REP(i, 0, n)
#define PER(i, a, b) for (int(i) = (a - 1); i >= (b); (i)--)
#define per(i, n) PER(i, n, 0)
#define each(i, n) for (auto &i : n)
#define clr(a) memset((a), 0, sizeof(a))
#define mclr(a) memset((a), -1, sizeof(a))
#define all(a) (a).begin(), (a).end()
#define dum(val) cerr << #val " = " << val << " ";
#define dump(val) cerr << #val " = " << val << endl;
#define FILL(a, v) fill(a, a + sizeof(a) / sizeof(*a), v)

typedef pair<int, int> P;
typedef tuple<int, int, int> T;

const int mod = 1e9 + 7;
const int INF = 1e9;

signed main() {
    int n;
    cin >> n;
    set<int> se;
    rep(i,n){
        int t;
        cin >> t;
        se.insert(t);
    }
    cout << se.size() << endl;

	return 0;
}


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

int main() {
  int x, y;
  cin >> x >> y;
  vector<int> v(13);
  for (int i = 1; i < 13; ++i) {
    if (i == 1 || i == 3 || i == 5 || i == 7 || i == 8 || i == 10 || i == 12) {
      v.at(i) = 1;
    } else if (i == 4 || i == 6 || i == 9 || i == 11) {
      v.at(i) = 2;
    } else {
      v.at(i) = 3;
    }
  }
  if (v.at(x) == v.at(y)) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
#include<stack>
#include<numeric>
#include<set>
#include<iomanip>
using namespace std;


typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
const int mod = 1000000007;
struct mint {
  ll x;
  mint(ll x=0):x(x%mod){}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};
mint ncr[4005][4005];

void calcComb(int n){
  ncr[0][0] = 1;
  for(int i = 0; i <= n; ++i){
    for(int j = 0; j <= i; ++j){
      ncr[i + 1][j] += ncr[i][j];
      ncr[i + 1][j + 1] += ncr[i][j];
    }
  }
}
mint comb(int n, int k){
  return ncr[n][k];
}


int main(){
  int n, k;
  cin >> n >> k;
  calcComb(4000);


  for(int i = 1; i <= k; ++i){
    mint ans = comb(n - k + 1, i).x * comb(k - 1, i - 1).x;

    cout << ans.x << endl;
  }


}


Measured memory_bytes: 125568
#include <stdio.h>
void sort(int a,int b)
{
    if (a < b)
    {
        printf("a < b\n");
    }
    if (a > b)
    {
        printf("a > b\n");
    }
    if (a == b)
    {
        printf("a == b\n");
    }
}
int main(void)
{
    int a, b;

    scanf("%d %d", &a, &b);
    sort(a, b);
    return 0;
}


Measured memory_bytes: 2544
import copy
N=int(input())
T=[int(i) for i in input().split()]
M=int(input())
A=[]
for i in range(M):
    B=T.copy()
    P,M=map(int,input().split())
    B[P-1]=M
    A.append(sum(B))
for t in A:
    print(t)

Measured memory_bytes: 3444
#include <algorithm>
#include <cmath>
#include <iostream>
#include <iterator>
#include <map>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using ull = unsigned long long;

int main() {
    int N, K;
    cin >> N >> K;
    int ans = 0;
    for (int i = 0; i < N; ++i) {
        int x;
        cin >> x;
        ans += 2 * min(x, abs(x - K));
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;
struct node {
	int key;
	node *pre, *nex;
};
node *nil;
void init() {
	nil = (node *)malloc(sizeof(node));
	nil->nex = nil;
	nil->pre = nil;
}
void insert(int key) {
	node *a = (node*)malloc(sizeof(node));
	a ->key = key;
	a->nex = nil->nex;
	nil->nex->pre = a;
	nil->nex = a;
	a->pre = nil;
}
node* search(int key) {
	node *cur;
	cur = nil->nex;
	while (cur != nil && cur->key != key) {
		cur = cur->nex;
	}
	return cur;
}
void deletenode(node *pt) {
	if (pt != nil) {
		pt->nex->pre = pt->pre;
		pt->pre->nex = pt->nex;
		free(pt);
	}
	else return;
	
}
void deleteFirst() {
	deletenode(nil->nex);
}
void deleteLast() {
	deletenode(nil->pre);
}
void deletekey(int key) {
	deletenode(search(key));
}
void printNode() {
	node *cur = nil->nex;
	/*while (cur != nil) {
		printf("%d", cur->key);
		cur = cur->nex;
	}*/
	int i = 0;
	while (1) {
		if(cur == nil)break;
		if (i++ > 0) printf(" ");
		printf("%d", cur->key);
		cur = cur->nex;
	}
	printf("\n");
}
int main() {
	
	int n, key;
	char com[20];
	scanf("%d", &n);
	init();
	for (int i = 0; i < n; i++) {
		scanf("%s%d", com, &key);
		if (com[0] == 'i') {
			insert(key);
		}
		/*else if (com[6] == 'F') {
			deleteFirst();
		}
		else if (com[6] == 'L') {
			deleteLast();
		}
		else {
			deletekey(key);
		}*/
		else if (com[0] == 'd') {
			if (strlen(com) > 6) {
				if (com[6] == 'F') {
					deleteFirst();
				}
				else if (com[6] == 'L') {
					deleteLast();
				}
			}
				else {
					deletekey(key);
				}
				

			}
		
	}
		printNode();
		return 0;
}

Measured memory_bytes: 33792
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
using namespace std;
typedef long long ll;
ll dp[305][90005]={0};
ll dp2[305][90005]={0};
const ll mod=998244353;
ll pow(ll x,ll y){
  if(y==0) return 1;
  ll ret=pow(x,y/2);
  ret*=ret;
  ret%=mod;
  if(y%2==1) ret*=x;
  return ret%mod;
}
int main(){
  ll n,sum=0;
  cin>>n;
  ll array[305]={0};
  for(ll i=1;i<=n;i++){
    cin>>array[i];
    sum+=array[i];
  }
  for(ll i=1;i<=n;i++){
    if(array[i]>=(sum+1)/2){
      cout<<0<<endl;
      return 0;
    }
  }
  const ll ferm=pow(2,mod-2);
  //cout<<ferm<<endl;
  for(ll i=0;i<n;i++){
    dp[i+1][array[i+1]]+=pow(2,n-1);
    dp2[i+1][array[i+1]]++;
    for(ll j=0;j<90005;j++){
      dp[i+1][j]+=dp[i][j];
      dp[i+1][j]%=mod;
      dp[i+1][j+array[i+1]]+=dp[i][j]*ferm;
      dp[i+1][j+array[i+1]]%=mod;

      dp2[i+1][j]+=dp2[i][j];
      dp2[i+1][j+array[i+1]]+=dp2[i][j];
      dp2[i+1][j]%=mod;
      dp2[i+1][j+array[i+1]]%=mod;
    }
  }
  ll ans=pow(3,n);
  for(ll i=(1+sum)/2;i<90005;i++) {
    ans-=dp[n][i]*3;
    if(ans<0){
      while(ans<0) ans+=mod;
    }
    ans%=mod;
  }
//  cout<<ans<<endl;
  if(sum%2==0){
   ans+=dp2[n][sum/2]*3;
   ans%=mod;
  }
  if(ans<0){
    while(ans<0) ans+=mod;
  }
  ans%=mod;
  /*for(int i=0;i<=n;i++){
    for(int j=0;j<5;j++) cout<<dp[i][j]<<" ";
    cout<<endl;
  }*/
  cout<<ans<<endl;
}


Measured memory_bytes: 425472
import java.util.Scanner;

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

		String s = sc.next();

		sc.close();

		if(s.equals("SUN")) System.out.println(7);
		if(s.equals("MON")) System.out.println(6);
		if(s.equals("TUE")) System.out.println(5);
		if(s.equals("WED")) System.out.println(4);
		if(s.equals("THU")) System.out.println(3);
		if(s.equals("FRI")) System.out.println(2);
		if(s.equals("SAT")) System.out.println(1);

	}
}

//import java.io.IOException;
//import java.io.InputStream;
//import java.util.NoSuchElementException;
//
//class FastScanner {
//  private final InputStream in = System.in;
//  private final byte[] buffer = new byte[1024];
//  private int ptr = 0;
//  private int buflen = 0;
//  private boolean hasNextByte() {
//      if (ptr < buflen) {
//          return true;
//      }else{
//          ptr = 0;
//          try {
//              buflen = in.read(buffer);
//          } catch (IOException e) {
//              e.printStackTrace();
//          }
//          if (buflen <= 0) {
//              return false;
//          }
//      }
//      return true;
//  }
//  private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
//  private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
//  public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
//  public String next() {
//      if (!hasNext()) throw new NoSuchElementException();
//      StringBuilder sb = new StringBuilder();
//      int b = readByte();
//      while(isPrintableChar(b)) {
//          sb.appendCodePoint(b);
//          b = readByte();
//      }
//      return sb.toString();
//  }
//  public long nextLong() {
//      if (!hasNext()) throw new NoSuchElementException();
//      long n = 0;
//      boolean minus = false;
//      int b = readByte();
//      if (b == '-') {
//          minus = true;
//          b = readByte();
//      }
//      if (b < '0' || '9' < b) {
//          throw new NumberFormatException();
//      }
//      while(true){
//          if ('0' <= b && b <= '9') {
//              n *= 10;
//              n += b - '0';
//          }else if(b == -1 || !isPrintableChar(b)){
//              return minus ? -n : n;
//          }else{
//              throw new NumberFormatException();
//          }
//          b = readByte();
//      }
//  }
//  public int nextInt() {
//      long nl = nextLong();
//      if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
//      return (int) nl;
//  }
//  public double nextDouble() { return Double.parseDouble(next());}
//}


Measured memory_bytes: 20564
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;

/*
*/

ll a,b,c;

void init(){
	cin>>a>>b>>c;
}

int main(void){
	init();
	cout<<min({a+b,b+c,c+a})<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){

int a[10000],b,c,i;

scanf("%d",&b);

for(i=0;i<b;i++){
scanf("%d",&a[i]);

while(a[i]%2==0){
a[i]=a[i]/2;  
c++;  
} 
}
printf("%d\n",c);
  
return 0;
}

Measured memory_bytes: 256
program main
	implicit none
    integer H, W, i, j
	character(1), allocatable :: a(:,:)
	read(*, *) H, W
	allocate(a(0:H+1, 0:W+1))
	a(0:H+1, 0:W+1) = '#'
	do i = 1, H
		do j = 1, W-1
			read(*, '(a1)', advance = 'NO') a(i, j)
		end do
		read(*, '(a1)') a(i, W)	
	end do
	do i = 0, H+1
		do j = 0, W
			write(*, '(a1)', advance = 'NO') a(i, j)
		end do
		write(*, '(a1)') a(i, W+1)	
	end do
end program main

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

typedef long long lint;
typedef pair<int, int> pii;

const int INF = 2e9;
const int MOD = 1e9+7;
const int MAX = 1e5+10;
const lint LNF = 2e18;

int n, k;

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

	int mx = (n+1)/2;
	if(k>mx) cout<<"NO";
	else cout<<"YES";


	return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
def cmb(n):
    return (n * (n-1)) // 2


n = int(input())
a = list(map(int, input().split()))

count = {}
for i in a:
    if i in count:
        count[i] += 1
    else:
        count[i] = 1

total = 0
nbk = {}
for k, c in count.items():
    tmp = cmb(c)
    nbk[k] = tmp
    total += tmp

for k in range(n):
    orginal = nbk[a[k]]
    removed = cmb(count[a[k]] - 1)
    print(total - orginal + removed)


Measured memory_bytes: 32672
# B - Great Ocean View
# https://atcoder.jp/contests/abc124/tasks/abc124_b


n = int(input())
points = list(map(int, input().split()))
ans = 1
need_height = points[0]


for i in range(1, n):
    current = points[i]
    if need_height <= current:
        ans += 1
        need_height = current


print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n=0;
    cin>>n;
    vector<int>moji(n);
    for(int i=0;i<n;i++){
        cin>>moji.at(i);
    }
    reverse(moji.begin(),moji.end());
    for(int i=0;i<n;i++){
        if(i==(n-1)){
            cout<<moji.at(n-1)<<endl;
           
        }
        else{
        cout<<moji.at(i)<<" ";
        }
        }
}


Measured memory_bytes: 3112
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<double,double> P;
typedef long long ll;

int main(){

    while(1){
        int n, m; cin >> n >> m;
        if(n == 0 && m == 0) return 0;
        vector<P> a(n);

        rep(i,n){
            cin >> a[i].second >> a[i].first;
        }

        sort(all(a));
        reverse(all(a));

        ll ans = 0.0;

        ll id = 0;
        while(m > 0 && id < n){
            
            if(a[id].second<= m){
                m -= a[id].second;
                a[id].second = 0;
                id++;
                continue;
            }
            else{
                a[id].second -= m;
                m = 0;
                break;
            }

        }

        rep(i,n){
            ans += a[i].first * a[i].second;
        }

        cout << ans << endl;

    }
}


Measured memory_bytes: 3372
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
using namespace std;
typedef  long long int lint;
typedef pair<int, int> P;
typedef pair<lint, lint> LLP;
typedef pair<char, char>CP;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define llower(v,hoge) *lower_bound(v.begin(), v.end(), hoge)
#define lupper(v,hoge) *upper_bound(v.begin(), v.end(), hoge)
/*
vector<char>al(26);
al = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
vector<char>AL(26);
AL = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
vector<char>NUM(10);
	NUM = { '0','1','2' ,'3' ,'4' ,'5' ,'6' ,'7' ,'8' ,'9' };
*/



int main() {
	int H, W, N;
	cin >> H >> W >> N;
	vector<int>A(N);
	rep(i, N) {
		cin >> A[i];
	}
	vector<int>a;
	rep(i, N) {
		while (A[i] > 0) {
			a.push_back(i + 1);
			A[i]--;
		}
	}
	/*rep(i, a.size()) {
		cout << a[i] << ' ';
	}*/
	vector<vector<int>>a2(H, vector<int>(W));
	rep(i, a.size()) {
		a2[i / W][i % W] = a[i];
	}
	rep(i, H) {
		if (i % 2 == 1) {
			reverse(a2[i]);
		}
	}
	rep(i, H) {
		rep(j, W) {
			cout << a2[i][j] << ' ';
		}
		cout << endl;
	}
}

Measured memory_bytes: 384
import math

n, m = [int(i) for i in input().split()]
# c:「m-2」とすれば,s:「n+1」と出来る
count = 0
# if int((m-2*n)/4) >= 0:
if m - 2*n > 0:
    count = max(count, min(n + int((m - 2 * n) / 4),
                           int(m / 2 - (m - 2 * n) / 4)))
    # print(count)
    # if math.ceil((m-2*n)/4) >= 0:
    count = max(count, min(n + math.ceil((m - 2 * n) / 4),
                           int(m / 2) - math.ceil((m - 2 * n) / 4)))
    # print(count)
count = max(count, min(n, int(m / 2)))
print(count)


Measured memory_bytes: 3060
//{{{
#include<algorithm>
#include<cmath>
#include<fstream>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<random>
#include<set>
#include<sstream>
#include<sys/time.h>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(prints) FUNC(printw) FUNC(printwe) FUNC(printb) FUNC(printbe) FUNC(printd) FUNC(printde) FUNC(printdu);
#endif
template <class S, class T>
istream& operator >> (istream& in, pair<S, T>& p){ return in >> p.first >> p.second; }
template <class T>
istream& operator >> (istream& in, vector<T>& v){ for(auto& e : v){ in >> e; } return in; }
//}}}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int x, y, z, k;
    cin >> x >> y >> z >> k;
    vector<ll> as(x); cin >> as;
    vector<ll> bs(y); cin >> bs;
    vector<ll> cs(z); cin >> cs;
    sort(as.rbegin(), as.rend());
    sort(bs.rbegin(), bs.rend());
    sort(cs.rbegin(), cs.rend());
    priority_queue<ll, vector<ll>, greater<ll>> pq;
    for(int i = 0; i < min(100, x); i++){
        for(int j = 0; j < min(100, y); j++){
            for(int l = 0; l < min(100, z); l++){
                pq.push(as[i] + bs[j] + cs[l]);
            }
        }
    }
    for(int i = 0; i < x; i++){
        for(int j = 0; j < y; j++){
            for(int l = 0; l < z; l++){
                if(i < 100 && j < 100 && l < 100){ continue; }
                ll v = as[i] + bs[j] + cs[l];
                if(pq.top() < v){
                    pq.pop();
                    pq.push(v);
                }else{
                    break;
                }
            }
        }
    }
    while((int)pq.size() > k){
        pq.pop();
    }
    vector<ll> ans;
    while(pq.size()){
        ans.push_back(pq.top());
        pq.pop();
    }
    reverse(ans.begin(), ans.end());
    for(auto& e : ans){
        cout << e << '\n';
    }
}


Measured memory_bytes: 10608
#include<iostream>
#include<unordered_map>
#include<stack>
#include<algorithm>
#include<set>
#include<cstring>
#include<vector>
#include<numeric>
#include<map>
#include<climits>
using namespace std;
const int N = 1e6;
		
long long int fact[N+1];
long long int mod = 1000000007;
void preprocess()
{
	fact[0] = 1;
	for(int i = 1; i < N+1; i++)
	{
		fact[i] = (i*fact[i-1])%mod;
	}
}
long long int bpower(long long int base, long long int power, long long int mod)
{
	long long int ans = 1ll;
	while(power > 0)
	{
		if(power & 1)
		{
			ans = (ans * base)%mod;
		}
		base = (base * base)%mod;
		power /=2;
	}
	return ans;
}
int32_t main() 
{
	#ifndef ONLINE_JUDGE
	freopen("input/input.txt", "r", stdin);
	freopen("input/output.txt", "w", stdout);
	#endif
	long long int n;
	cin >> n;
	long long int ans = 0;
	preprocess();
	for(int i = 2; i <= n; i++)
	{
		long long int x = bpower(2, i, mod) - 2;
		long long int y = fact[n];
		y = (y * bpower((fact[i] * fact[n-i]) % mod, mod - 2, mod)) % mod;
		long long int z = bpower(8, n-i, mod);
		ans = ((ans + ((x * y) % mod)* z) % mod) % mod;
	}
	/*for(int i = 0; i < 100; i++)
	{
		cout << fact[i] << '\n';
	}*/
	cout << ans << '\n';

}

Measured memory_bytes: 11444
#include<bits/stdc++.h>
#pragma GCC optimization ("Ofast")
#pragma GCC optimization ("unroll-loops")
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define all(v) v.begin(),v.end()
#define P pair<int,int>
#define len(s) (int)s.size()
 
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;
}
constexpr int mod = 1e9+7;
constexpr long long inf = 3e18;

int mod_pow(int x,int y,int m){
	int res=1;
	while(y>0){
		if(y&1)res=(__int128_t(res)*x)%m;
		y>>=1;x=(__int128_t(x)*x)%m;
	}
	return res;
}
 
bool prime(int n){
	if(n<2||n%2==0)return n==2;
	int d=n-1;while(d%2==0)d>>=1;
	for(int x:{2,325,9375,28178,450775,9780504,1795265022}){
		if(n<=x)break;
		int t=d,y=mod_pow(x,t,n);
		while(t!=n-1&&y!=1&&y!=n-1){
			y=(__int128_t(y)*y)%n;t<<=1;
		}
		if(y!=n-1&&t%2==0)return false;
	}return true;
}
int rho(int n){
	if(n%2==0)return 2;
	int MOD=n;
	auto f=[&](int x){return ((__int128_t)x*x+1)%MOD;};
	auto g=[](int x,int y){
		if(x<y)return y-x;
		return x-y;
	};
	for(int x1=0;;x1++){
		for(int x=x1,y=f(x);;x=f(x),y=f(f(y))){
			int d=gcd(g(y,x),n);
			if(1<d&&d<n)return d;
			if(d==n)break;
		}
	}
}
vector<int>factor(int n){
	if(n==1)return {};
	if(prime(n))return {n};
	int d=rho(n);
	vector<int>res=factor(d);
	for(int i:factor(n/d))res.push_back(i);
	return res;
}

int extGCD(int a,int b,int &x,int &y){
	if(!b){
		x=1;y=0;return a;
	}
	int d=extGCD(b,a%b,y,x);
	y-=a/b*x;
	return d;
}
P CRT(int b1,int m1,int b2,int m2){
	int p,q;
	int d=extGCD(m1,m2,p,q);
	if((b2-b1)%d!=0)return P(0,-1);
	int m=m1*(m2/d);
	int tmp=(b2-b1)/d*p%(m2/d);
	int r=((b1+m1*tmp)%m+m)%m;
	return P(r,m);
}
signed main(){
	cin.tie(0);ios::sync_with_stdio(false);
	int N;cin>>N;N*=2;
	vector<int>v=factor(N);sort(all(v));
	map<int,int>mp;
	for(int i:v)mp[i]++;
	int ans=N/2;
	rep(i,1<<len(mp)){
		int x=1,y=1;
		int j=0;
		for(auto k:mp){
			if(i>>j&1){
				x*=mod_pow(k.first,k.second,inf);
			}else {
				y*=mod_pow(k.first,k.second,inf);
			}
			j++;
		}
		if(x!=1){
			chmin(ans,CRT(x-1,x,0,y).first);
		}
	}
	cout<<ans<<"\n";
}

Measured memory_bytes: 3612
#include <iostream>
#include <cctype>
#include <cstdlib>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#define rep(i, n) for(int i = 0; i < n; ++i)
using namespace std;

int comp(const void* a, const void* b){
	return *(int*)a - *(int*)b;
}

int main() {
	int n, l[15], sum = 0, max;
	cin >> n;
	rep(i, n){
		cin >> l[i];
		if(i == 0){
			max = l[i];
		}else{
			if(max < l[i]){
				max = l[i];
			}
		}
		sum += l[i];
	}
	sum -= max;
	if(max < sum){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include<stdio.h>
#include<math.h>
using namespace std;
int main(void){
    int N;
    while(1){
        cin>>N;
        if(N==0){
            break;
        }
        if(N==1){
            cout<<"deficient number"<<endl;
        }
        else{
        int S=0;
        for(int i=1;i<=sqrt(N);i++){
            if(N%i==0){
            S+=i;
            if(i!=(N/i))
            S+=(N/i);
            }
        }
        S=S-N;
        if(N==S){
            cout<<"perfect number"<<endl;
        }
        else if(N<S){
            cout<<"abundant number"<<endl;
        }
        else{
            cout<<"deficient number"<<endl;            
        }
        }
    }
    return 0;
    
}



Measured memory_bytes: 3084
#include <stdio.h>

int W,H,ans;
int map[100][100];

void search_island(int x, int y){
	map[x][y] = 0;
	if(x > 0){
		if(map[x - 1][y]){
			search_island(x - 1, y);
		}
		if(y > 0){
			if(map[x - 1][y - 1]){
				search_island(x - 1, y - 1);
			}
		}
		if(y < W - 1){
			if(map[x - 1][y + 1]){
				search_island(x - 1, y + 1);
			}
		}
	}
	if(x < H - 1){
		if(map[x + 1][y]){
			search_island(x + 1, y);
		}
		
		if(y > 0){
			if(map[x + 1][y - 1]){
				search_island(x + 1, y - 1);
			}
		}
		if(y < W - 1){
			if(map[x + 1][y + 1]){
				search_island(x + 1, y + 1);
			}
		}
	}
	if(y > 0){
		if(map[x][y - 1]){
			search_island(x, y - 1);
		}
	}
	if(y < W - 1){
		if(map[x][y + 1]){
			search_island(x, y + 1);
		}
	}
}


int main()
{
	scanf("%d %d",&W,&H);
	while(W != 0 && H != 0){
		for(int i = 0; i < H; i++){
			for(int k = 0; k < W; k++){
				scanf("%d",&map[i][k]);
			}
		}

		ans = 0;

		for(int j = 0; j < H; j++){
			for(int k = 0; k < W; k++){
				if(map[j][k]){
					ans++;
					search_island(j,k);
				}
			}
		}

		printf("%d\n",ans);
		scanf("%d %d",&W,&H);
	}
	return 0;
}

Measured memory_bytes: 1264
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vc = vector<char>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
#define fix10 cout << fixed << setprecision(10);
#define rep(i,n) for(int i=0; i<(int)(n);i++)

int main(){
  int a,b;
  cin >> a >> b;
  int tmp = b-1;
  if(tmp == 0){
    cout << 0 << endl;
    return 0;
  }
  cout << (tmp+a-2)/(a-1) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef pair<ll, ll> PP;
#define rep(i, n) for (ll i = 0; i < ll(n); i++)
#define all(v) v.begin(), v.end()
bool chmin(ll& a, ll b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
bool chmax(ll& a, ll b) {
    if (b > a) {
        a = b;
        return 1;
    }
    return 0;
}
const ll INF = 999999999999999;
const ll MOD = 1000000007;
const ll MAX_N = 500010;
ll a, b, c, d, e, f, p, t, x, y, z, q, m, n, r, h, k, w, l, ans;
vector<vl> dp(1010, vl(1010, 0));
int main() {
    cin >> n;
    rep(i, n) {
        cin >> a >> b >> c >> d;
        a++;
        b++;
        c++;
        d++;
        dp[a][b]++;
        dp[a][d]--;
        dp[c][b]--;
        dp[c][d]++;
    }


    rep(i, 1005) {
        rep(j, 1005) {
                dp[i+1][j] += dp[i][j];
        }
    }

   rep(i, 1005) {
        rep(j, 1005) {
                dp[i][j+1] += dp[i][j];
                chmax(ans,dp[i][j]);
        }
    }

    cout << ans << endl;
}




Measured memory_bytes: 10652
#include<stdio.h>
int range(double p,double q,double r){
  return (q<r?q:r)<=p&&p<=(q<r?r:q);
}
int main(){
  double x[4],y[4];
  while(scanf("%lf%lf%lf%lf%lf%lf%lf%lf",&x[0],&y[0],&x[1],&y[1],&x[2],&y[2],&x[3],&y[3])!=-1){
    if(range(x[0],x[2],x[3])||range(x[1],x[2],x[3])||range(x[2],x[0],x[1])||range(x[3],x[0],x[1])){
      if(range(y[0],y[2],y[3])||range(y[1],y[2],y[3])||range(y[2],y[0],y[1])||range(y[3],y[0],y[1])){
	puts("YES");
	continue;
      }
    }
    puts("NO");
  }
  return 0;
}

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

int main(){
    int a, b, c, x;
    cin >> a >> b >> c >> x;
    int ans = 0;
    
    for (int f_h = 0; f_h <= a; f_h++) {
        for (int hu = 0; hu <= b; hu++) {
            for (int fi = 0; fi <= c; fi++) {
                int sum = f_h * 500 + hu * 100 + fi * 50;
                if (sum == x) {
                    ans++;
                }
            }
        }
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
N,M = list(map(int, input().split()))
P = list(map(int, input().split()))
XY = [list(map(int, input().split())) for _ in range(M)]

class UnionFind():
  def __init__(self):
    self.roots = {}
    self.nums = {}

  def find_root(self, a):
    if a not in self.roots:
      self.nums[a] = 1
      return a
    else:
      self.roots[a] = self.find_root(self.roots[a])
      return self.roots[a]

  def unite(self, a, b):
    root_a = self.find_root(a)
    root_b = self.find_root(b)
    n_a = self.nums[root_a]
    n_b = self.nums[root_b]
    if root_a == root_b:
      return
    else:
      if n_a > n_b: #多い方に合流させる
        self.roots[root_b] = root_a
        self.nums[root_a] = n_a + n_b
        del self.nums[root_b]
      else:
        self.roots[root_a] = root_b
        self.nums[root_b] = n_a + n_b
        del self.nums[root_a]
      return
  
  def is_union(self, a,b):
    return self.find_root(a) == self.find_root(b)
  
uf = UnionFind()
for x,y in XY:
  uf.unite(x,y)

unions = {}
for i in range(1, N+1):
  unions.setdefault(uf.find_root(i), set()).add(i)
  
answer = 0
for k, s in unions.items():
  for p in s:
    if P[p-1] in s:
      answer +=1
      
print(answer)
    


Measured memory_bytes: 71456
n, m = (int(x) for x in input().split())
MOD = 10 ** 9 + 7
INF = 10 ** 12
dp = [INF] * (n + 1)
for i in range(m):
  dp[int(input())] = 0
dp[0] = 1
for i in range(1, n+1):
  if dp[i] == INF:
    dp[i] = dp[i-1] % MOD
    if i > 1:
      dp[i] += dp[i-2] % MOD
    dp[i] %= MOD
print(dp[n])

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

using i64 = int64_t;

#define rep(i, x, y) for (i64 i = i64(x), i##_max_for_repmacro = i64(y); i < i##_max_for_repmacro; ++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf = 1.01e9;
const i64 inf64 = 4.01e18;
const double eps = 1e-9;

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

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
    os << "[";
    for (const auto &v : vec) {
        os << v << ",";
    }
    os << "]";
    return os;
}

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

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

template<typename T, size_t size> void fill(T (&ary)[size], const T& val){
    fill_n((T*)ary, size, val);
}

void solve() {
    //const i64 mod = 1'000'000'007;
    
    string S;
    cin >> S;

    const string acgt="ACGT";
    vector<i64> len(S.size());
    if(find(begin(acgt),end(acgt),S[0])!=end(acgt)) len[0]=1;
    rep(i,1,S.size()){
        if(find(begin(acgt),end(acgt),S[i])!=end(acgt)) len[i]=len[i-1]+1;
        else len[i]=0;
    }

    print(len);

    i64 ans=0;
    rep(i,0,S.size()) chmax(ans,len[i]);

    cout << ans << endl;
}

int main() {
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}


Measured memory_bytes: 256
#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 IN(a) cin>>(a)
#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 n;
   cin>>n;
   vector<P> a(n);
   REP(i,n){
       int t;
       cin>>t;
       a[i]={t,i+1};
   }
   sort(ALL(a));
   REP(i,n){
       OUT(a[i].second);
   }
    return 0;
}

Measured memory_bytes: 1664