akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <fstream>
#include <cmath>
#include <random>
#include <complex>
#include <functional>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)
using namespace std;
typedef vector<ll> vec;
typedef vector<vec> mat;

const ll inf = 1LL << 60;

template<class T> inline void chmin(T& a, T b) {
    if (a > b) {
        a = b;
    }
}
template<class T> inline void chmax(T& a, T b) {
    if (a < b) {
        a = b;
    }
}

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

    ll N;
    cin >> N;
    set<ll> A;
    Rep (i, N) {
        ll a;
        cin >> a;
        A.insert(a);
    }

    if (A.size() == N) {
        cout << "YES\n";
    } else {
        cout << "NO\n";
    }
}

Measured memory_bytes: 9600
//@uthor: _|EE|_RB30

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

#define vi vector<int>
#define vpi vector<pair<int,int>>
#define pb push_back

#define pii pair<int,int>
#define mii map<int,int>
#define mpi map<pair<int,int>,int>

#define M 1000000009
#define pi 3.141592653589793238
#define endl "\n"
#define brisk ios_base::sync_with_stdio(false);cin.tie(NULL);

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

    	int x = ceil((double)n/1000)*1000;

    	cout<<x-n;
}


Measured memory_bytes: 3648
import java.util.*;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
	int n = Integer.parseInt(sc.next());
    int a[] = new int[n];
    double g[] = new double[n];
    double s = 0.0;
    double ans = 0.0;
    
    for(int i=0; i<n; i++) {
      a[i] = Integer.parseInt(sc.next());
    }

    
    for(int i=0; i<n; i++){
      g[i] = 1.0 / a[i];
      s += g[i];
    }
    
    ans = 1.0/s;
    
    System.out.println(ans);
    
  }
}


Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
  int N,M;

  cin >> N;

  vector<string> s(N);

  for(int i=0;i<N;i++){
    cin >> s.at(i);
  }

  cin >> M;

  vector<string> t(M);

  for(int i=0;i<M;i++){
    cin >> t.at(i);
  }

  map<string,int> r,b;

  for(int i=0;i<N;i++){
    if(r[s.at(i)]==0) r[s.at(i)] = 1;
    else r[s.at(i)]++;    
    }    
  

  for(int i=0;i<M;i++){
    if(b[t.at(i)]==0) b[t.at(i)] = 1;
    else b[t.at(i)]++;    
    }    
  

  int ans=0;

  for (pair<string,int> p : r) {
    string key = p.first;
    int value = p.second;

    if(ans < value - b[key]) ans = (value-b[key]);

  }

  
   cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e16;
const ll mod = 1000000007;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
ll factorial(ll n) {
  if (n == 1) {
    return 1;
  }
  ll ans = factorial(n-1);
  return ans*n;
}
ll gcd(ll a, ll b) {
  if (a < b) {
    ll tmp = a;
    a = b;
    b = tmp;
  }
  ll r = a%b;
  while(r != 0) {
    a = b;
    b = r;
    r = a%b;
  }
  return b;
}
ll lcm(ll a, ll b) {
  return (a/gcd(a, b))*b;
}
bool prime(ll n) {
  if (n == 1) {
    return false;
  } else {
    for (ll i = 2; i <= (ll)pow(n, 0.5); i++) {
      if (n%i == 0) return false;
    }
  }
  return true;
}
ll RepeatSquaring(ll n, ll p, ll m) {
  if (p == 0) return 1;
  if (p%2 == 0) {
    ll t = RepeatSquaring(n, p/2, m);
    return (t*t)%m;
  }
  return (n*RepeatSquaring(n, p-1, m))%m;
}

int main() {
  ll n, w;
  cin >> n >> w;
  vector <ll> v(n);
  vector <ll> u(n);
  rep(i, n) cin >> v.at(i) >> u.at(i);
  vector <vector <ll>> dp(n+1, vector <ll> (w+1, 0));
  rep(i, n) {
    for (ll j = 0; j <= w; j++) {
      if (j < u.at(i)) {
        dp.at(i+1).at(j) = dp.at(i).at(j);
      } else {
        dp.at(i+1).at(j) = max(dp.at(i).at(j), dp.at(i+1).at(j-u.at(i))+v.at(i));
      }
    }
  }
  cout << dp.at(n).at(w) << endl;
}


Measured memory_bytes: 10720
n,x = list(map(int,input().split()))
def cal(n,x):
    if n==0:
        return 1
    if x==1:
        return 0
    ll = 2**(n+1)-3
    if x<=ll+1:
        return cal(n-1,x-1)
    if x==ll+2:
        return cal(n-1,x-2)+1
    if x<=ll+ll+2:
        return cal(n-1,ll)+1+cal(n-1,x-ll-2)
    if x==ll+ll+3:
        return 2**(n+1)-1

print(cal(n,x))

Measured memory_bytes: 3064
using System;

namespace A
{
    class Program
    {
        static void Main(string[] args)
        {
            var S = Console.ReadLine();
            var T = Console.ReadLine();
            var result = true;
            for (int i = 0; i < S.Length; i++)
            {
                if(S[i]!=T[i])
                {
                    result = false;
                    break;
                }
            }
            Console.WriteLine(result?"Yes":"No");
        }
    }
}


Measured memory_bytes: 25776
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    n=int(input())
    l=list(map(int,input().split()))
    # -1になるのは１がlに１個もないとき
    if 1 not in l:
        print(-1)
    # 今何を探しているかをcntに入れる
    # 最初は1を探す
    else:
        cnt=1
        for i in range(n):
            if l[i]==cnt:
                # 1増やした数字を次に探したいからcnt増やす
                cnt+=1
        # cntは最後に見つかった最大の数+1になっているからcnt-1が見つかった個数
        # cnt-1以外はすべて砕く
        print(n-(cnt-1))
resolve()

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

int main (){
    int a, b, c;
    cin>>a>>b>>c;
    vector<int> Vec(3);
    Vec={a, b, c};
    sort(Vec.begin(), Vec.end());
    if(Vec.at(0)+Vec.at(1)==Vec.at(2)){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }


}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
n,p = map(int, input().split())

# is_prime = list(range(n+1))
# is_prime[1] = 0
# for i in range(2,n+1):
#     if i*i>n+1:
#         break
#     if is_prime[i]:
#         for x in range(2*i,n+1,i):
#             is_prime[x] = 0
# primes = [p for p in is_prime if p!=0]

div = {}
for i in range(2,p+1):
    if p%i==0:
        while p%i==0:
            if i not in div:
                div[i] = 0
            div[i] += 1
            p //= i
    if i*i>p:
        if p>1:
            if p not in div:
                div[p] = 0
            div[p] += 1
        break

res = 1
for r in div.keys():
    while div[r]>=n:
        res *= r
        div[r] -= n

print(res)


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

int main() {
    int a,b,c;
    do{
        cin >> a >> b;
        c=0;
        if (!((a==0)&&(b==0))){
            for(int i=1;i<=a;i++){
                for(int j=1;j<i;j++){
                    for(int k=1;k<j;k++){
                        if ((i+j+k)==b){
                            c++;
                        }
                    }
                }
            }
            cout << c << endl;
        }
    }while(!((a==0)&&(b==0)));
    return 0;
}


Measured memory_bytes: 3052
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define ll long long
int main(){
  int N;
  string S;
  cin>>N>>S;
  int A[26]={0};
  rep(i,N) A[S[i]-'a']++;
  ll ans=A[0];
  rep(i,26) if(i) ans=ans*(1+A[i])%1000000007+A[i];
  cout<<ans%1000000007<<endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <iostream>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#define REP(i, x, n) for(int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
using namespace std;
typedef long long int lli;
typedef pair<lli, lli> Pii;
const int INF = 100000000 +11555;

struct UnionFind {
  vector<int> d;
  UnionFind(int n): d(n,-1) {}
  int root(int x) {
    if (d[x] < 0) return x;
    return d[x] = root(d[x]);
  }
  bool unite(int x, int y) {
    x = root(x); y = root(y);
    if (x == y) return false;
    if (d[x] > d[y]) swap(x,y);
    d[x] += d[y];
    d[y] = x;
    return true;
  }
  bool same(int x, int y) { return root(x) == root(y);}
  int size(int x) { return -d[root(x)];}
};

int main(){
    // vector
    // vc.push_buck(x)
    // sort(vc.begin(),vc.end())
    // vc[i]
    int n,m,k;
    cin >> n >> m >> k;
    vector<int> nakama[n];
    vector<int> teki[n];
    int a,b;
    UnionFind tree(n);
    
    rep(i,m){
        cin >> a >> b;
        nakama[a-1].push_back(b-1);
        nakama[b-1].push_back(a-1);
        tree.unite(a-1,b-1);
    }
    rep(i,k){
        cin >> a >> b;
        teki[a-1].push_back(b-1);
        teki[b-1].push_back(a-1);
    }
    vector<int> ans(n,0);
    rep(i,n){
        ans[i] = tree.size(i) - (int)nakama[i].size() -1;
        rep(j,(int)teki[i].size()){
            if (tree.same(i,teki[i][j])) --ans[i];
        }
    }
    rep(i,n){
        cout << ans[i] <<" "; 
        if (i==n) cout << endl;
    }

    return 0;
}

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

#define ld long double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n; cin>>n;
    if (n%2==1){
        cout<<"0\n";
        return 0;
    }
    ll cnt5=0;
    ll r = 10;
    while(n/r){
        cnt5 += n/r;
        if (n/r==1) break;
        r = r*5;
    }
    cout<<cnt5<<endl;
    return 0;
}


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

using namespace std;
inline void prep ()
{
  cin.tie (0);
  cin.sync_with_stdio (0);
};
const double pi = acos(-1.);
//printf(%.12lf\n,mid);
// __builtin_popcount(int) count 1's in binary
// get decimal part of number
/*
double intpart;
double thiss = modf((double)(n*m)/(double)k, &intpart);
*/
// round = (int)(num+.5)
int mod = 998244353;

long long mymod(long long num){
  if (num< 0 && !(num%mod == 0)){
    if (mod == 1){
      return 0;
    }
    return mod-abs(num)%mod;
  }else{
    return num%mod;
  }
}

/*string sentence = And I feel fine...;
    istringstream iss(sentence);
*/  

double eps = .000000001;
int price[1000];
int many[1000];
int pows[13];
int n, m;
int goal;
bool memoo[4096][1000];
long long memo[4096][1000];
long long func(int vis, int key){
    if (key >= m){
        if (vis == goal){
            return 0;
        }else{
            return 1000000000;
        }
    }
    if (memoo[vis][key]){
        return memo[vis][key];
    }
    long long minnest = func(vis, key+1);
    minnest = min(minnest, price[key]+func(vis|many[key], key+1));
    memoo[vis][key] = true;
    memo[vis][key] = minnest;
    return minnest;
}
int main ()
{
  prep();
  int poww = 1;
  for (int i=0; i<13; i++){
      pows[i] = poww;
      
      poww *= 2;
  }
  
  cin >> n >> m;
  goal = pow(2, n)-1;
  for (int i=0; i<m; i++){
      int a, b;
      cin >> a >> b;
      price[i] = a;
      int num = 0;
      for (int j=0; j<b; j++){
          int chest;
          cin >> chest;
          num += pows[chest-1];
      }
      many[i] = num;
  }
  long long res = func(0, 0);
  if (res >= 1000000000){
      cout << -1;
  }else{
      cout << res;
  }
  return 0; 
}


Measured memory_bytes: 36352
#include <algorithm>
#include <iostream>
#include <vector>
#include <functional>
#include <string>
#include <cmath>  //sqrt 
#include <iomanip> //setprecision
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define beg begin()
#define end end()
int gcd(int a, int b){
    if(a%b==0) return b;
    else return gcd(b,a%b);
}
int lcm(int a, int b)
{
   return a * b / gcd(a, b);
}
void _main(){
    int x; cin >> x;
    int k = lcm(x,360)/x;
    cout << k << endl;
    
    return;
}
int main() {
    cout << fixed << setprecision(10);
    _main();
    return 0;
}
    

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

int main() {
  int h,w;
  cin >> h >> w;
  for ( int i=0; i<h; i++ ) {
    string s;
    cin >> s;
    cout << s << '\n';
    cout << s << '\n';
  }
  return 0;
}


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

int main(){
	string a, b;
	cin >> a >> b;

	rep(i, a.size()){
		if(a.at(i) != b.at(i)){
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
int main(void){
    string s;
    cin>>s;
    int c0=0,c1=0;
    for(int i=0;i<s.size();i++){
        if(s[i]=='0')c0++;
        else c1++;
    }
    if(c1==0||c0==0){
        cout<<0<<endl;
    }
    else if(c1==c0){
        cout<<c1*2<<endl;
    }else cout<<min(c1,c0)*2<<endl;
    
}


Measured memory_bytes: 512
import sys

def input(): return sys.stdin.readline()[:-1]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def MATINT(h): return [list(map(int, input().split())) for _ in range(h)]
def MATSTR(h): return [input() for _ in range(h)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
inf = float('inf')
mod = 10 ** 9 + 7

def main():
    A, B, C = MAP()
    print(max(C - (A - B), 0))

if __name__ == '__main__':
    main()


Measured memory_bytes: 38256
import numpy as np


def getInput():
    separator = ' '
    ret_array = []
    while True:
        try:
            row = input().split(sep=separator)
            ret_array.append(row)
        except EOFError:
            break
    return ret_array


g = getInput()

N = np.int32(g[0][0])

# ls:0 initial 1 horz 2 vert
ls = 0
cs = None
l = []
i = 0
hoge=[]
try:
    while True:
        # cc = currently checking u = upper l = lower
        hoge.append(g[2][0][i])
        if g[1][0][i] == g[2][0][i]:
            cs = 2
            i += 1
        else:
            cs = 1
            i += 2

        if ls == 0:
            if cs == 1:
                l.append(6)
            else:
                l.append(3)
        elif ls == 1:
            if cs == 1:
                l.append(3)
            else:
                l.append(1)
        else:
            l.append(2)

        ls = cs

except IndexError:
    print(np.mod(np.prod(np.array(l, dtype=np.int32)),1000000007))


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

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

using namespace std;

using ll = long long;
using P = pair<int, int>;

int main() {
  string s;
  cin >> s;

  int first2 = atoi(s.substr(0, 2).c_str());
  int last2 = atoi(s.substr(2, 2).c_str());
  bool first2CanBeMm = first2 >= 1 && first2 <= 12;
  bool last2CanBeMm = last2 >= 1 && last2 <= 12;

  string result = "NA";
  if (first2CanBeMm && last2CanBeMm) {
    result = "AMBIGUOUS";
  } else if (first2CanBeMm) {
    result = "MMYY";
  } else if (last2CanBeMm) {
    result = "YYMM";
  }
  cout << result << endl;

  return 0;
}


Measured memory_bytes: 256
n,w=map(int,input().split())
vlst=[0 for _ in range(n+1)]
wlst=[0 for _ in range(n+1)]

for i in range(1,n+1):
    x,y=map(int,input().split())
    vlst[i],wlst[i]=x,y

dp=[[0 for _ in range(w+1)] for _ in range(n+1)]

for i in range(1,n+1):
    for j in range(1,w+1):
        work=j-wlst[i]
        if work>=0:
            dp[i][j]=max(dp[i-1][j],dp[i][work]+vlst[i],dp[i-1][work]+vlst[i])
        else :
            dp[i][j]=dp[i-1][j]

print(dp[n][w])


Measured memory_bytes: 16292
#include <bits/stdc++.h>
#include <cmath>
#include <iostream>
#include <numeric>
#define ll long long
using namespace std;
int main() {
 string s;
 int cnt=0;
 cin>>s;
 for(int i=0;i<s.size()/2;i++){
  if(s[i]!=s[s.size()-i-1]) cnt++;
 }
 cout<<cnt<<endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
    int n;
    cin >> n;
    long long ans = 0;
    for (int i = 1; i <= n; ++i) {
        if (i % 3 == 0 || i % 5 == 0)
            continue;
        ans += i;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3624
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
#define pb push_back
#define ll long long int
# define pll pair<ll,ll>
# define fio ios_base::sync_with_stdio(false); cin.tie(NULL)
using namespace std;

int main()
{   fio;
    ll h,w,k;
    string s[10];
    cin>>h>>w>>k;
    for(int i=0;i<h;i++) cin>>s[i];
    ll cnt=0;
    for(ll i=0 ;i < (1ll<<h) ; i++)
    {
        for(ll j=0; j<(1ll<<w) ; j++)
        {  ll val=0;
            for(int r=0;r<h;r++)
            {
                for(int c =0 ; c< w ; c++ )
                {
                    if((i&(1<<r))==0 and (j&(1<<c))==0  and s[r][c]=='#') val++;
                }
            }
            if(k==val) cnt++;
        }
    }
    cout<<cnt;
    
}


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

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    N,M=MI()
    inf=10**16
    class SegTree:
        def __init__(self,N,ide,segfunc=min):
            self.ide_ele = ide
            """
            ex)
             最小値のセグ木 → +inf
              和のセグ木 → 0
              積のセグ木 → 1
              gcdのセグ木 → 0
            """
            
            self.segfunc=segfunc
            
            #num:N以上の最小の2のべき乗
            self.num =2**(N-1).bit_length()
            self.seg=[self.ide_ele]*2*self.num




        #リストで初期化する
        def setL(self,init_val):
            #init_valは操作する数列
            for i in range(N):
                self.seg[i+self.num-1]=init_val[i]    
            #built
            for i in range(self.num-2,-1,-1) :
                self.seg[i]=self.segfunc(self.seg[2*i+1],self.seg[2*i+2]) 


        #k番目の値をxに更新
        def update(self,k,x):
            k += self.num-1
            self.seg[k] = x
            while k:
                k = (k-1)//2
                self.seg[k] = self.segfunc(self.seg[k*2+1],self.seg[k*2+2])


        #[p,q)の区間に対するクエリへの応答
        def query(self,p,q):
            if q<=p:
                return self.ide_ele
            p += self.num-1
            q += self.num-2
            res=self.ide_ele
            while q-p>1:
                if p&1 == 0:
                    res = self.segfunc(res,self.seg[p])
                if q&1 == 1:
                    res = self.segfunc(res,self.seg[q])
                    q -= 1
                p = p//2
                q = (q-1)//2
            if p == q:
                res = self.segfunc(res,self.seg[p])
            else:
                res = self.segfunc(self.segfunc(res,self.seg[p]),self.seg[q])
            return res


    seg=SegTree(N+1,inf,min)
    
    L=[0]*M
    R=[0]*M
    C=[0]*M
    for i in range(M):
        l,r,c=MI()
        l-=1
        r-=1
        L[i]=l
        R[i]=r
        C[i]=c
        
    R,C,L=zip(*sorted(zip(R,C,L)))
        
    
    
    #rが小さいものから見て(rが同じならcが小さい)確定させていく
    now=0#確定させたとこと
    seg.update(0,0)
    
    for i in range(M):
        r=R[i]
        l=L[i]
        c=C[i]
        m=seg.query(l,now+1)#移動もとの範囲での最小値
        #seg.update(r,m+c)
        now=r
        
        #このままだと入力例3みたいに，コストは低いけどl,rがちかいみたいなのを先に処理してしまう
        #とりあえず右端だけ更新しとけばokか?
        
        if m+c<seg.query(now,now+1):
            seg.update(now,m+c)
        
        #print((l+1,r+1,c),now+1,m,m+c)
        """
        for ii in range(N):
            print(seg.query(ii,ii+1))"""
        
    ans=seg.query(N-1,N)

    
    
    if ans>=inf:
        print(-1)
    else:
        print(ans)
    
        
    
        
        
    

main()


Measured memory_bytes: 92636
n = int(input())
mod = 10**9+7
a = []
l = ["A","C","G","T"]
ban = ["AAGC","CAGC","GAGC","TAGC","AGCA","AGCC","AGCG","AGCT","AGAC","CGAC","GGAC","TGAC","GACA","GACC","GACG","GACT","AACG","CACG","GACG","TACG","ACGA","ACGC","ACGG","ACGT","ATGC","ACGC","AGGC","AGTC","AGGC","AGAC"]
for i in l:
    for j in l:
        for k in l:
            a.append(i+j+k)
dp = [[0]*64 for _ in range(n+1)]
for i in range(64):
    if (a[i]=="AGC" or a[i]=="ACG" or a[i]=="GAC"):
        continue
    dp[3][i] = 1
for i in range(4,n+1):
    for j in range(64):
        for k in l:
            b = a[j]+k
            if b in ban:
                continue
            else:
                dp[i][a.index(b[1:])] += dp[i-1][j]
                dp[i][a.index(b[1:])] %= mod
print(sum(dp[-1])%mod)
        
            

Measured memory_bytes: 9204
from math import ceil
N,A,B=map(int,input().split())
H=[]
d=A-B
for i in range(N):
    h=int(input())
    H.append(h)
b=ceil(max(H)/B)
a=0
while(a!=b):
    m=a+(b-a)//2
    t=0
    for h in H:
        t+=ceil(max(h-B*m,0)/d)
    if t<=m:
        b=m
    else:
        a=m+1
print(a)


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

#define rep(i, a, b) for (int i = a; i < (int)(b); ++i)
#define rrep(i, a, b) for (int i = b - 1; i >= (int)(a); --i)

using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;

constexpr int MOD = 1000000007;

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

    int n;
    cin >> n;

    vi h(n);
    rep(i, 0, n) { cin >> h[i]; }

    vi dp(n, 0);
    dp[1] = abs(h[1] - h[0]);

    rep(i, 2, n) {
        int c1 = dp[i - 1] + abs(h[i] - h[i - 1]);
        int c2 = dp[i - 2] + abs(h[i] - h[i - 2]);
        dp[i] = min(c1, c2);
    }
    cout << dp.back() << endl;

    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <cstdio>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <utility>
#include <fstream>
#include <random>
#include <map>
#include <unordered_map>
#include <cstdlib>
#include <functional>
#include <random>
#include <time.h>
#include <chrono>
#include <sstream>
#include <iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define INF 1000000001
#define mod 1000000007
#define sort(s) sort(s.begin(), s.end());
#define reverse(s) reverse(s.begin(), s.end());
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };
using namespace std;
int POW(int x, int y) { return int(pow(double(x), double(y))); }
double log(double a, double b) { return log(b) / log(a); }

unsigned int randxor()
{
	static unsigned int x = 123456789, y = 362436069, z = 521288629, w = 88675123;
	unsigned int t;
	t = (x ^ (x << 11)); x = y; y = z; z = w; return(w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}






int main() {
	string s;
	cin >> s;
	int a1 = 0;
	int a0 = 0;
	rep(i, s.size()) {
		if (s[i] == '1') {
			a1++;
		}
		else {
			a0++;
		}
	}


	std::cout << (s.size()-abs(a0 - a1)) << endl;

	return 0;
}


Measured memory_bytes: 512
n,k=map(int,input().split())
h=[int(input()) for _ in range(n)]
h.sort()
INF=2*10**9
ans=INF
for i in range(n-k+1):
	diff=h[i+k-1]-h[i]
	if ans>diff:
		ans=diff
		if ans==0:
			print(0)
			exit()
print(ans)

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

priority_queue<long long, vector<long long>, less<long long>> Q;
long long A[1 << 18], B[1 << 18], ans;
vector<long long> T[1 << 18];  // array of vectors

int main() {
  long long N, M;
  cin >> N >> M;
  for (int i = 1; i <= N; i++) {
  	cin >> A[i] >> B[i];
  	if (A[i] <= M) T[M - A[i]].push_back(B[i]);
  }
// T[2] : 2, 3, 4
// T[1] : 1, 3
  
  for (int i = M-1; i >= 0; i--) {
    for (auto j: T[i]) Q.push(j);
    if (!Q.empty()) {
      ans += Q.top();
      Q.pop();
    }
  }

  cout << ans << "\n";
}


Measured memory_bytes: 12288
import sys
sys.setrecursionlimit(10 ** 5)

# 連結性の確認
class UnionFind():
    def __init__(self, n):
        self.parents = list(range(n))
        self.weight = [0] * n
        self.rank = [0] * n

    def find(self, a):
        if self.parents[a] == a:
            return a
        p = self.find(self.parents[a])
        self.weight[a] += self.weight[self.parents[a]]
        self.parents[a] = p
        return p

    def union(self, a, b, w):
        self.find(a), self.find(b)
        w += self.weight[a]
        w -= self.weight[b]
        a = self.find(a)
        b = self.find(b)

        if a == b: return

        if self.rank[a] < self.rank[b]:
            self.parents[a] = b
            self.weight[a] = -w
        else:
            self.parents[b] = a
            self.weight[b] = w
            if self.rank[a] == self.rank[b]:
                self.rank[a] += 1

    def weight_check(self, a, b):
        self.find(a), self.find(b)
        return - self.weight[a] + self.weight[b]

while True:
    N, M = map(int, input().split())
    if not(N | M):
        break

    uf = UnionFind(N)
    for i in range(M):
        input_str = input().split()
        if input_str[0] == '!':
            a, b, w = map(int, input_str[1:])
            uf.union(a - 1, b - 1, w)

        else:
            a, b = map(lambda x: int(x) - 1, input_str[1:])
            if uf.find(a) != uf.find(b):
                print('UNKNOWN')
                continue
            print(uf.weight_check(a, b))



Measured memory_bytes: 16612
N = int(input())

T = list(map(int, input().split()))

M = int(input())

def readlines():
    for _ in range(M):
        p, x = map(int, input().split())
        yield p-1, x

px = list(readlines())

total = sum(T)
for p, x in px:
    print(total - T[p] + x)

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

long long k, a, b, ans=1;
int main() {
	cin>> k>> a>> b;
	if(k <= a-1 || b-a<=2) {cout<< ans+k; return 0;}
	ans += a-1;
	k -= a-1;
	ans += k/2*(b-a) + k%2;
	cout<< ans;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e18;
const ll mod = 1000000007;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
ll factorial(ll n) {
  if (n == 1) {
    return 1;
  }
  ll ans = factorial(n-1);
  return ans*n;
}
ll gcd(ll a, ll b) {
  if (a < b) {
    ll tmp = a;
    a = b;
    b = tmp;
  }
  ll r = a%b;
  while(r != 0) {
    a = b;
    b = r;
    r = a%b;
  }
  return b;
}
ll lcm(ll a, ll b) {
  return (a/gcd(a, b))*b;
}
bool prime(ll n) {
  if (n == 1) {
    return false;
  } else {
    for (ll i = 2; i <= (ll)pow(n, 0.5); i++) {
      if (n%i == 0) return false;
    }
  }
  return true;
}
ll RepeatSquaring(ll n, ll p, ll m) {
  if (p == 0) return 1;
  if (p%2 == 0) {
    ll t = RepeatSquaring(n, p/2, m);
    return (t*t)%m;
  }
  return (n*RepeatSquaring(n, p-1, m))%m;
}

int main() {
  ll n, m;
  cin >> n;
  set <ll> a;
  ll l;
  rep(i, n) {
    cin >> l;
    a.insert(l);
  }
  cin >> m;
  set <ll> b;
  rep(i, m) {
    cin >> l;
    b.insert(l);
  }
  set <ll> s;
  for (auto value : a) {
    if (!b.count(value)) {
      cout << value << endl;
    }
  }
}


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

#define ll long long

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

    int p[n][3];
    int dp[n][3];

    for (int i = 0; i < n; ++i)
        cin >> p[i][0] >> p[i][1] >> p[i][2];

    for (int i = 0; i < 3; ++i)
        dp[0][i] = p[0][i];

    for (int i = 1; i < n; ++i)
        for (int j = 0; j < 3; ++j)
            dp[i][j] = max(dp[i - 1][(j + 1) % 3], dp[i - 1][(j + 2) % 3]) + p[i][j];

    cout << max(dp[n - 1][0], max(dp[n - 1][1], dp[n - 1][2]));

    return 0;
}


Measured memory_bytes: 2560
#include <iostream>
#include <sstream>
#include <string>
#include <cstring>
#include <vector>
#include <algorithm>
#include <tuple>
#include <queue>
#include <set>
#include <cstdio>
#include <climits>
#include <cmath>
#include <array>
#include <functional>
#include <sstream>
#include <list>
#include <set>
const int MOD=1000000007;
const int INF=1000000000;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
const double eps=1e-9;
const int inf=1e9;
typedef pair<int,int> P;
int buckets[256];
typedef string::const_iterator State;
int number(State &begin)
{
  int ret=*begin-'0';
  begin++;
  return ret;
}

int term(State &begin)
{
  int ret=number(begin);
  while(true)
    {
      if(*begin == '*')
	{
	  begin++;
	  ret*=number(begin);
	}
      else
	{
	  break;
	}
    }
  return ret;
}

int expression(State &begin)
{
  int ret=term(begin);
  while(true)
    {
      if(*begin =='+')
	{
	  begin++;
	  ret+=term(begin);
	}
      else
	{
	  break;
	}
    }
  return ret;
}

int rule2(string s)
{
  State begin=s.begin();
  int ret=*begin-'0';
  begin++;
  while(begin!=s.end())
    {
      if(*begin=='+')
	{
	  begin++;
	  ret+=*begin-'0';
	}
      else
	{
	  begin++;
	  ret*=*begin-'0';
	}
      begin++;
    }
  return ret;
}
int main(int argc,char const* argv[])
{
  string s;
  int n;
  int ans1,ans2;
  cin >> s;
  cin >> n;
  State begin=s.begin();
  ans1=expression(begin);
  ans2=rule2(s);
  if(ans1==ans2 && ans1==n)
    {
      cout << 'U' << endl;
    }
  else if(ans1==n)
    {
      cout << 'M' << endl;
    }
  else if(ans2==n)
    {
      cout << 'L' << endl;
    }
  else
    {
      cout << 'I' << endl;
    }
  return 0;
}



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

int main(){
  string s = "";
  int h, w;
  cin >> h >> w;
  for (int i = 0;i < h;i++) {
    string sb = "";
    cin >> sb;
    s += sb;
  }
  //cout << s << endl;
  for (int j = 0;j < h;j++) {
    for (int k = 0;k < w;k++) {
      int current = (w * j) + k;
      if(s.at(current)=='#') cout << '#';
      else {
        int up = j;
        int left = k;
        int down = j;
        int right = k;
        int count = 0;
        if( j != 0){
          up--;
        }
        if( k != 0){
          left--;
        }
        if( j != (h -1) ){
          down++;
        }
        if( k != (w-1) ){
          right++;
        }
        for (int l = up;l <= down;l++){
          for (int m = left;m <= right;m++){
            int subcurrent = (w * l) + m;
            if( subcurrent != current){
              if(s.at(subcurrent)=='#'){
                count++;
              }
            }
          }
        }
        cout << count;
      }
    }
    cout << endl;
  }
}

Measured memory_bytes: 3616
#include<iostream>
#include<queue>
#include<stack>
using namespace std;
int main()
{
	int n;
	cin>>n;
	stack<int>q;
	stack<int>p;
	while(n--){
		
		q.push(0);
		p.push(0);
		int f=1;
		for(int i=1;i<=10;i++)
		{
			int t;
			cin>>t;
			if(p.top()<t)
			p.push(t);
			else if(q.top()<t)
			q.push(t);
			else{
				f=0;
			}
		}
		if(f==0)
		cout<<"NO"<<endl;
		else
		cout<<"YES"<<endl;
		while(!q.empty())
		q.pop();
		while(!p.empty())
		p.pop();
	
	}
 } 


Measured memory_bytes: 3124
#include<stdio.h>
int main(){
	int by,ay,i,c=0;
	for(i=0;scanf("%d %d",&by,&ay)&&(by||ay);c=0,i++){
		if(i>0)printf("\n");
		for(i=by;i<=ay;i++){
			if(!(i%4) && ((i%100)||!(i%400))){
				printf("%d\n",i);c++;
			}
		}
		if(!c)printf("NA\n");
	}
	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define fi(init, n) for(int i = init; i < n; i++)
#define fj(init, n) for(int j = init; j < n; j++)
#define ios ios_base::sync_with_stdio(false);cin.tie(NULL);
typedef long long ll;
using namespace std;

int main()
{
	ios
	int n, ac=0, wa=0, tle=0, re=0; 
	string s;
	cin >>  n;
	while(n--){
		cin >> s;
		if(s=="AC")
			ac++;
		if(s=="WA")
			wa++;
		if(s=="TLE")
			tle++;
		if(s=="RE")
			re++;
	}
	cout << "AC x " << ac << endl;
	cout << "WA x " << wa << endl;
	cout << "TLE x " << tle << endl;
	cout << "RE x " << re << endl;

    return 0;
}

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

int main() {
    int n, m;
    cin >> n >> m;
    set<pair<int, int>> edges;
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        edges.insert({min(a, b), max(a, b)});
    }

    int cnt = 0;
    vector<int> perm(n - 1);
    iota(perm.begin(), perm.end(), 2);

    do {
        bool ok = true;
        vector<int> path = {1};
        for (int v : perm) {
            path.push_back(v);
        }
        for (int i = 0; i < n - 1; i++) {
            int a = path[i], b = path[i + 1];
            if (edges.count({min(a, b), max(a, b)}) == 0) {
                ok = false;
                break;
            }
        }
        if (ok) cnt++;
    } while (next_permutation(perm.begin(), perm.end()));

    cout << cnt << '\n';
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
	int n;
	cin >> n;
	int a;
	cin >>a;
	int sum=0;
	int s[n];
	for(int i=0;i<n;i++){
		cin >> s[i];
	}
	sort(s,s+n);
	for(int i=n-1;i>n-a-1;i--){
		sum += s[i];
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 384
n=int(input())
v=list(map(int,input().split()))
dic1={}
dic2={}
for i in range(0,n):
  if i%2==0:
    at=v[i]
    if at in dic1:
      dic1[at]+=1
    else:
      dic1[at]=1
  else:
    at=v[i]
    if at in dic2:
      dic2[at]+=1
    else:
      dic2[at]=1 

count1=0
count2=0
kep1=0
kep2=0
for i in range(len(dic1)):
  at=dic1.popitem()
  moji=at[0]
  count=at[1]
  if count>count2:
    kep2=moji
    count2=count
  if count2>count1:
    moji_tamotu=kep1
    count_tamotu=count1
    kep1=kep2
    kep2=moji_tamotu
    count1=count2
    count2=count_tamotu

odd_1_moji=kep1
odd_1_count=count1
odd_2_moji=kep2
odd_2_count=count2
    
count1=0
count2=0
kep1=0
kep2=0
for i in range(len(dic2)):
  at=dic2.popitem()
  moji=at[0]
  count=at[1]
  if count>count2:
    kep2=moji
    count2=count
  if count2>count1:
    moji_tamotu=kep1
    count_tamotu=count1
    kep1=kep2
    kep2=moji_tamotu
    count1=count2
    count2=count_tamotu

even_1_moji=kep1
even_1_count=count1
even_2_moji=kep2
even_2_count=count2

if even_1_moji!=odd_1_moji:
  kouho=[odd_1_moji,even_1_moji]*(n//2)
else:
  if even_1_count+odd_2_count>=even_2_count+odd_1_count:
    kouho=[odd_2_moji,even_1_moji]*(n//2)
  else:
    kouho=[odd_1_moji,even_2_moji]*(n//2)
    
res=0
for i in range(0,n):
  if v[i]!=kouho[i]:
    res+=1
print(res)
    


Measured memory_bytes: 18204
const MOD: usize = 998244353;

fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let k: usize = sc.read();
    let n: usize = sc.read();

    let combination = Combination::new(100000, MOD);
    for i in 2..(2 * k + 1) {
        println!("{}", solve(i, n, k, &combination));
    }
}

fn solve(sum: usize, n: usize, k: usize, combination: &Combination) -> usize {
    let mut pairs = 0;
    for one in 1..(k + 1) {
        if sum < one * 2 { break; }
        let other = sum - one;
        if other > k { continue; }
        pairs += 1;
    }

    let mut ans = combination.h(k, n);
    for used_pairs in 1..(pairs + 1) {
        if n < used_pairs * 2 { break; }
        let mut tmp = combination.h(k, n - used_pairs * 2) * combination.get(pairs, used_pairs);
        tmp %= MOD;
        if used_pairs % 2 == 1 {
            ans += MOD - tmp;
        } else {
            ans += tmp;
        }
        ans %= MOD;
    }
    ans
}

pub struct Combination {
    fact: Vec<usize>,
    inv_fact: Vec<usize>,
    modulo: usize,
}

impl Combination {
    pub fn new(max: usize, modulo: usize) -> Combination {
        let mut inv = vec![0; max + 1];
        let mut fact = vec![0; max + 1];
        let mut inv_fact = vec![0; max + 1];
        inv[1] = 1;
        for i in 2..(max + 1) {
            inv[i] = inv[modulo % i] * (modulo - modulo / i) % modulo;
        }
        fact[0] = 1;
        inv_fact[0] = 1;
        for i in 0..max {
            fact[i + 1] = fact[i] * (i + 1) % modulo;
        }
        for i in 0..max {
            inv_fact[i + 1] = inv_fact[i] * inv[i + 1] % modulo;
        }
        Combination {
            fact: fact,
            inv_fact: inv_fact,
            modulo: modulo,
        }
    }

    pub fn get(&self, x: usize, y: usize) -> usize {
        assert!(x >= y);
        self.fact[x] * self.inv_fact[y] % self.modulo * self.inv_fact[x - y] % self.modulo
    }

    pub fn h(&self, n: usize, r: usize) -> usize {
        self.get(n + r - 1, r)
    }
}

pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n')
            .take_while(|&b| b != b' ' && b != b'\n')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 6396
#include<stdio.h>
int main(void)
    {
	int a,b;
	scanf("%d %d",&a,&b);
	if (a > b){
	    printf ("a > b\n");
	}
	 else if (a == b){
		printf ("a == b\n");
	}
	else if (a < b){
	    printf("a < b\n");
	}
	return 0;
}	

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

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define w(x)            int x; cin>>x; while(x--)
#define fr(i,a,b)       for(int i = a; i < b; i++)

void c_p_c()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}

void knapsack(int n, int w, int *weight, int *value)
{
	int dp[n + 1][w + 1];

	fr(i, 0, n + 1)
	{
		fr(j, 0, w + 1)
		{
			if (i == 0 or j == 0)
				dp[i][j] = 0;
			else if (weight[i - 1] <= j)
				dp[i][j] = max(value[i - 1] + dp[i - 1][j - weight[i - 1]], dp[i - 1][j]);
			else
				dp[i][j] = dp[i - 1][j];
		}
	}

	cout << dp[n][w] << endl;
	return;
}

void solve()
{
	int n, w;
	cin >> n >> w;
	int weight[n], value[n];
	fr(i, 0, n)
	cin >> weight[i] >> value[i];
	knapsack(n, w, weight, value);
	return;
}

int32_t main()
{
	c_p_c();
	solve();
	return 0;
}

Measured memory_bytes: 82408
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int count = Integer.parseInt(sc.nextLine());
		int[] nums = new int[count];
		String[] lines = sc.nextLine().split(" ");

		for(int i = 0;i < count;i++) {
			nums[i] = Integer.parseInt(lines[i]);
		}
		int min = nums[0];
		int max = nums[0];
		long sum = 0;
		for(int i = 1;i < count ;i++) {
			if(nums[i] < min ) {
				min = nums[i];
			} else if(nums[i] > max) {
				max = nums[i];
			}
		}
		for(int i = 0; i < count ; i++) {
			sum += nums[i];
		}
		System.out.println(min + " " + max + " " + sum);
	}
}

Measured memory_bytes: 31272
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String s = scan.nextLine();
		int ans = 0;
		switch(s) {
		case "SUN":ans = 7;
		break;
		case "SAT":ans = 1;
		break;
		case "FRI":ans = 2;
		break;
		case "THU":ans = 3;
		break;
		case "WED":ans = 4;
		break;
		case "TUE":ans = 5;
		break;
		case "MON":ans = 6;
		break;
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 24020
#include <iostream>

using namespace std;

int main()
{
    int a = 100000;

    int n;
    cin >> n;

    while(n--){
        a = int(a * 1.05);
        if( a % 1000 != 0)
            a  = a - (a % 1000) + 1000;
    }
    cout << a << endl;
    return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

#define rep_(i, a_, b_, a, b, ...) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define rep(i, ...) rep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define reprev_(i, a_, b_, a, b, ...) for (int i = (b-1), i##_min = (a); i >= i##_min; --i)
#define reprev(i, ...) reprev_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define all(x) (x).begin(), (x).end()
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

vector<vector<int> > graph;
vector<bool> used;
vector<int> in, topology;

int f (int i, int j, int n) {
    int a = i, b = j;
    if (a > b) swap(a, b);
    return (a - 1) * (2 * n - a) / 2 + (b - a - 1);
}

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    int comb = n * (n - 1) / 2;
    graph.resize(comb);
    in.resize(comb);
    used.resize(comb);
    rep (i, n) {
        vector<int> a(n - 1);
        rep (j, n - 1) cin >> a[j];
        rep (j, 1, n - 1) {
            graph[f(i + 1, a[j - 1], n)].push_back(f(i + 1, a[j], n));
            in[f(i + 1, a[j], n)]++;
        }
    }
    rep (i, comb) {
        for (int j : graph[i]) eprintf("(%d,%d)", i, j);
        eprintf("\n");
    }
    fflush(stderr);

    stack<int> st;
    rep (i, comb) if (in[i] == 0) st.push(i);
    while (!st.empty()) {
        int now = st.top(); st.pop();
        topology.push_back(now);
        for (int i : graph[now]) {
            in[i]--;
            if (in[i] == 0) st.push(i);
        }
    }
    if (topology.size() != comb) {
        cout << "-1\n";
    } else {
        rep (i, comb) eprintf("%d ", topology[i]); eprintf("\n");
        vector<int> dp(comb);
        int ans = 0;
        for (int i : topology) {
            for (int j : graph[i]) {
                chmax(dp[j], dp[i] + 1);
            }
            chmax(ans, dp[i]);
        }
        cout << ans + 1 << "\n";
    }
    return 0;
}

Measured memory_bytes: 33656
#include <bits/stdc++.h>
using namespace std;
long long mod = 1e9 + 7;

long long big_pow(int b, int p)
{
    if(p == 0)return 1;
    long long a = big_pow(b, p/2);
    long long f = (a*a)%mod;
    if(p%2 == 1)f = (f*b)%mod;
    return f%mod;
}


int main()
{
    int n, ara[100005], f_ara[100005] = {0}, i;
    scanf("%d", &n);
    for(i = 0; i < n; i++)scanf("%d", &ara[i]);
    for(i = 0; i < n; i++)
    {
        int f = n-1+ara[i];
        if((f_ara[f/2] == 1 && f_ara[n-1- (f/2)] == 1))break;
        if(f_ara[f/2] == 0)f_ara[f/2] = 1;
        else f_ara[n-1- (f/2)] = 1;
    }
    if(i == n)printf("%lld", big_pow(2, n/2));
    else printf("0");
    return 0;
}


Measured memory_bytes: 1024
cards = list()
suit = ['S', 'H', 'C', 'D']
n = int(input())
for i in range(n):
    s, m = input().split()
    m = int(m)
    if s == "S":
        cards.append(0 + m)
    elif s == "H":
        cards.append(13 + m)
    elif s == "C":
        cards.append(26 + m)
    elif s == "D":
        cards.append(39 + m)
for i in range(1, 53):
    if not (i in cards):
        print(suit[(i - 1) // 13], (i - 1) % 13 + 1)


Measured memory_bytes: 5612
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int MAXN = 12+1;
const int MAXM = 12+1;
int N, M, X, c[MAXN], adj[MAXN][MAXM];

int best(int ind, int costo, vector<int> v){
    bool esci = true;
    for(auto x : v)
        if(x < X){
            esci = false;
            break;
        }
    if(esci) return costo;
    if(ind == N) return LLONG_MAX;
    for(int i = 0; i < M; i++) v[i] += adj[ind][i];
    costo += c[ind];
    int ans = best(ind+1, costo, v);
    for(int i = 0; i < M; i++) v[i] -= adj[ind][i];
    costo -= c[ind];
    ans = min(ans, best(ind+1, costo, v));
    return ans;
}

main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> N >> M >> X;
    for(int i = 0; i < N; i++){
        cin >> c[i];
        for(int j = 0; j < M; j++)
    		cin >> adj[i][j];
    }
    vector<int> v(M, 0);
    int ans = best(0, 0, v);
    if(ans == LLONG_MAX) ans = -1;
    cout << ans;
}

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

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()
{
  long long k, n;
  cin >> k >> n;
  vector<long long> a(n);
  for (int i = 0; i < n; i++)
  {
    cin >> a[i];
  }
  long long ma = a[0] + k - a[n - 1];
  for (int i = 1; i < n; i++)
  {
    chmax(ma, a[i] - a[i - 1]);
  }
  cout << k - ma << endl;
}
    

Measured memory_bytes: 1792
#include<iostream>
using namespace std;
int main(){
string str;
getline(cin,str);
for(int i=0;i<(int)str.size();i++){
if( islower(str[i]) ){
str[i]=toupper(str[i]);
}else if( isupper(str[i]) ){
str[i]=tolower(str[i]);
}
}cout<<str<<endl;
return 0;
}


Measured memory_bytes: 3172