akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int w, h, k;
int main(){
	scanf("%i%i%i", &w, &h, &k);

	/*if(k < min(w, h) || k > w * h) {
		printf("No\n");
		return 0;
	}*/
	for(int i=0;i<=w;i++){
		for(int j=0;j<=h;j++){
			//if(!i && !j) continue;
			//printf("%i, %i = %i\n", i, j, (i * (h - j)) + j * (w - i)); 
			if((i * (h - j)) + j * (w - i) == k) {printf("Yes\n"); return 0;} 
		}
	}
	printf("No\n");
}

Measured memory_bytes: 256
#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>;

struct UnionFind {
  vector<int> d;
  UnionFind(int n): d(n,-1) {}//-1で初期化
  int root(int x) {
    if (d[x] < 0) return x;//rootを負にする（構成node数x(-1))
    //root以外は親の番号
    return d[x] = root(d[x]);
    //return(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);
    //swapすることで小さい方を大きい方につけられ計算量減らせる
    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)];}
  //グループのnode数
  int group_num(int n){
      set<int> s;
      for(int i = 0; i < n; ++i){
          s.insert(root(i));
      }
      return int(s.size());
    }
};

//int deg[100005];
vector<int> to[100005];


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

  UnionFind uf(n);
  rep(i,m) {
    int a, b,z;
    cin >> a >> b>>z;
    --a; --b;

    uf.unite(a,b);
  }
  int ans=uf.group_num(n);
  cout<<ans;
}


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

int main(){
    long long nums[200009], minv = 1e16;
    int N;
    cin >> N;
    
    memset( nums, 0, sizeof(nums));
    
    long long v;
    for ( int i = 1; i <= N; i++) {
        cin >> v;
        nums[i] += nums[i-1] + v;
    }
    
    int l = 1, m = 2, r = 3;
    long long sum1, sum2, sum3, sum4;
    for ( ; m <= N; m++) {
        
        sum1 = nums[l];
        sum2 = nums[m]-nums[l];
        sum3 = nums[r]-nums[m];
        sum4 = nums[N]-nums[r];
        
        while( abs(sum4-sum3) > abs((nums[N]-nums[r+1])-(nums[r+1]-nums[m])) ) {
            r++;
            sum4 = nums[N]-nums[r];
            sum3 = nums[r]-nums[m];
        }
        while( abs(sum2-sum1) > abs((nums[m]-nums[l+1])-nums[l+1]) )  {
            l++;
            sum2 = nums[m]-nums[l];
            sum1 = nums[l];
        }
        minv = min( minv, max(max(sum1,sum2),max(sum3,sum4)) - min(min(sum1,sum2),min(sum3,sum4)));
    }
    cout << minv << endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int main(){
	int x,y;
	string ans;
	cin>>x>>y;
	if((y%2 == 0) && (y >= 2*x) && (y <= 4*x))
		cout<<"Yes"<<"\n";
    else
    	cout<<"No"<<"\n";
	return 0;
}

Measured memory_bytes: 3628
H, W, K = map(int, input().split())

dp = [[0] * W for _ in range(H + 1)]
dp[0][0] = 1

B = [i for i in range(2 ** (W - 1)) if '11' not in format(i, 'b')]

for h in range(H):
  for w in range(W):
    for b in B:
      if w > 0 and (b >> (w - 1)) & 1:
      	dp[h + 1][w - 1] += dp[h][w]
      elif w < W - 1 and (b >> w) & 1:
        dp[h + 1][w + 1] += dp[h][w]
      else:
        dp[h + 1][w] += dp[h][w]

print(dp[H][K - 1] % (10**9 + 7))

Measured memory_bytes: 3064
w,h,n=map(int,input().split())
xl, xr=0, w
yd, yu=0, h

for _ in range(n):
  x,y,a=map(int,input().split())
  if a==1:
    xl=max(xl, x)
  elif a==2:
    xr=min(xr, x)
  elif a==3:
    yd=max(yd, y)
  else:
    yu=min(yu, y)
  

ans=max(0, xr-xl)*max(0, yu-yd)
print(ans)
    



Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>

using namespace std;
using ll = long long;

int main(){
	ios_base::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<ll> a(n);
	for(int i = 0; i < n; ++i){ cin >> a[i]; }
	ll even = 0, odd = 0;
	for(int i = 0; i < n; i += 2){ even += max<ll>(a[i], 0); }
	for(int i = 1; i < n; i += 2){ odd  += max<ll>(a[i], 0); }
	ll answer = max(even, odd);
	const int offset = (even > odd ? 0 : 1);
	vector<int> b(n);
	for(int i = 0; i < n; ++i){
		b[i] = (i % 2 == offset) && (a[i] > 0);
	}
	if(answer == 0){
		const int i = max_element(a.begin(), a.end()) - a.begin();
		b[i] = 1;
		answer = a[i];
	}
	cout << answer << endl;
	vector<int> moves;
	while(b.size() > 1){
		if(!b.back()){
			moves.push_back(b.size() - 1);
			b.pop_back();
			continue;
		}
		if(!b.front()){
			moves.push_back(0);
			b.erase(b.begin());
			continue;
		}
		const int m = b.size();
		for(int i = m - 3; i >= 0; --i){
			if(b[i] == b[i + 2] && !b[i + 1]){
				moves.push_back(i + 1);
				b.erase(b.begin() + i + 1, b.begin() + i + 3);
				--i;
			}
		}
	}
	cout << moves.size() << endl;
	for(const auto x : moves){
		cout << x + 1 << endl;
	}
	return 0;
}



Measured memory_bytes: 256
#pragma comment(linker, "/stack:200000000")
        #pragma GCC optimize ("Ofast")
        #pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
         
         
        #include <iostream>
        #include <iomanip>
        #include <sstream>
        #include <cstring>
        #include <vector>
        #include <deque>
        #include <queue>
        #include <set>
        #include <map>
        #include <valarray>
        #include <iterator>
        #include <functional>
        #include <limits>
        #include <algorithm>
        #include <numeric>
        #include <cmath>
        #include <cassert>
        #include <unordered_map>
        #include <stack>
        using namespace std;
        #define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
         #define trace(x) cerr << #x << ": " << x << " " << endl;
     
        typedef int64_t ll;
     
        #define endl '\n'
        #define int ll
        ll mod=1e9+7;
        ll mod1=1e9+5;
        ll power(ll a,ll b)
        {
            if(b==0) return 1;
            else if(b%2==0)
                return power((((a%mod)*(a%mod))%mod),b/2)%mod;
            else return ((a%mod)*(power((((a%mod)*(a%mod))%mod),b/2)%mod))%mod;
        }
       
        
        int32_t main()
        {
            IOS
           
            
        int n;
        cin>>n;
        int a[n];
        for(int i=0;i<n;++i)
        {
            cin>>a[i];
        }
        multiset<int> m;
        int count=0;
        for(int i=0;i<n;++i)
        {
            // for(auto j:m)
            //     cout<<j<<" ";
            // cout<<endl;
            if(m.empty())
            {
                count++;
                m.insert(a[i]);
                continue;
            }

            auto j=m.lower_bound(a[i]);
            if(j==m.begin())
            {
                m.insert(a[i]);
                count++;
                continue;   
            }
            j--;

            if(*j<a[i])
            {
                m.erase(j);
                m.insert(a[i]);
                continue;
            }
            else
            {
                m.insert(a[i]);
                count++;
            }
        }
        cout<<count;
        

        }


Measured memory_bytes: 5760
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int m, f, r;
		while (true) {
			m = sc.nextInt();
			f = sc.nextInt();
			r = sc.nextInt();
			if (m == -1 && f == -1 && r == -1)
				break;
			if (m == -1 || f == -1) {
				System.out.println("F");
			} else if (m + f >= 80) {
				System.out.println("A");
			} else if (m + f >= 65 && 80 > m + f) {
				System.out.println("B");
			} else if (m + f >= 50 && 65 > m + f) {
				System.out.println("C");
			} else if (m + f >= 30 && 50 > m + f && r >= 50) {
				System.out.println("C");
			} else if (m + f >= 30 && 50 > m + f && 50 > r) {
				System.out.println("D");
			} else if (30 > m + f) {
				System.out.println("F");
			}
		}
	}
}


Measured memory_bytes: 26260
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;

int main() {
    vector<vector<int>> first(3, vector<int>(10));
    vector<vector<int>> second(3, vector<int>(10));
    vector<vector<int>> third(3, vector<int>(10));
    vector<vector<int>> fourth(3, vector<int>(10));
    int n;
    cin >> n;
    int a, b, c, d;
    for (int i = 0; i < n; ++i) {
        cin >> a >> b >> c >> d;
        if (a == 1) first[b - 1][c - 1] += d;
        else if (a == 2) second[b - 1][c - 1] += d;
        else if (a == 3) third[b - 1][c - 1] += d;
        else fourth[b - 1][c - 1] += d;
    }
    for (int j = 0; j < 3; ++j) {
        for (int i = 0; i < 10; ++i) {
            cout << " " << first[j][i];
        }
        cout << endl;
    }
    cout << "####################" << endl;
    for (int j = 0; j < 3; ++j) {
        for (int i = 0; i < 10; ++i) {
            cout << " " << second[j][i];
        }
        cout << endl;
    }
    cout << "####################" << endl;
    for (int j = 0; j < 3; ++j) {
        for (int i = 0; i < 10; ++i) {
            cout << " " << third[j][i];
        }
        cout << endl;
    }
    cout << "####################" << endl;
    for (int j = 0; j < 3; ++j) {
        for (int i = 0; i < 10; ++i) {
            cout << " " << fourth[j][i];
        }
        if (j == 2) continue;
        else cout << endl;
    }
    cout << endl;
}



Measured memory_bytes: 3112
N=int(input())
doublet_cnt=0
for _ in range(N):
  d1,d2=map(int,input().split())
  if d1==d2:
    doublet_cnt+=1
  else:
    doublet_cnt=0
  if doublet_cnt==3:
    print("Yes")
    exit()
print("No")

Measured memory_bytes: 9104
import java.io.*;
import java.util.*;

class Main{
    public static void main(String[] args)throws IOException{
    	int a, b, ans;
        char op;
        
        Scanner scan = new Scanner(System.in);
        
        String str = scan.next();
        a = Integer.parseInt(str);
        
        str = scan.next();
        op = str.charAt(0);
        
        str = scan.next();
        b = Integer.parseInt(str);
        
        while (true){
            
            if (op == '+'){
                ans = a + b;
                System.out.println(ans);
            }
            else if (op == '-'){
                ans = a - b;
                System.out.println(ans);
            }
            else if (op == '*'){
                ans = a * b;
                System.out.println(ans);
            }
            else if (op == '/'){
                ans = a / b;
                System.out.println(ans);
            }
            else break;
            
            str = scan.next();
            a = Integer.parseInt(str);
            
            str = scan.next();
            op = str.charAt(0);
            
            str = scan.next();
            b = Integer.parseInt(str);
        }
    }
}

Measured memory_bytes: 25948
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
const int maxn=1e9+7;
const int maxx=1e7;
int a[maxx];
int main()
{
    int n;
    scanf("%d",&n);
    int c=0;
    for(int i=2;i<=n;i++)
         {
             int l=i;
             for(int j=2;j<=l;j++)
             {
                while(l%j==0)
                {
                    a[j]++;
                    l/=j;
                }
             }
             if(l) a[l]++;

        }
        long long sum=1;
        for(int i=2;i<=n;i++)
        {
            if(a[i])
            {
                sum*=(1+a[i]);
                sum=sum%maxn;
            }
        }
        printf("%lld\n",sum);
        return 0;

}


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

int main(){
  while(1){
	int H,W;
	cin >> H >> W;
	if(H==0 && W==0) break;
	
	for(int i=0; i<H; i++){
	  for(int j=0; j<W; j++){
	    if((i+j)%2 == 0) cout << "#";
	    else cout << ".";
	  }
	cout << endl;
	}
  cout << endl;
  }
  return 0;	    
}


Measured memory_bytes: 3088
from itertools import accumulate

N, K = map(int, input().split())
S = input()
L = []

tmp = None
cnt = 0
for s in S:
  if tmp == None:
    cnt += 1
    tmp = s
  else:
    if s == tmp:
      cnt += 1
    else:
      L.append(cnt)
      tmp = s
      cnt = 1
else:
  L.append(cnt)
  L.insert(0,0)

if S[0] == "0":
  L.insert(0,0)

acc = list(accumulate(L))

ans = 0
last = len(acc)

for i in range(0, last, 2):
  right = 2 * K + i + 1
  left = i
  ans = max(ans, acc[min(last-1, right)] - acc[left])

print(ans)


Measured memory_bytes: 47412
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include <sstream>
#include<queue>
#include<stack>
#include<functional>
#include<math.h>
#include <iomanip>
#include <numeric>
#include <math.h>
using namespace std;



int main(void){
  int W,H,N;
  cin >> W >> H >> N;
  int bx=0,by = 0;
  int tx=W , ty=H; 
  for(int i =0; i < N ; i++){
        int x,y,a;

        cin >> x >> y >> a;
        switch (a)
        {
        case 1:
          if(bx < x){
            bx = x;
          }
          break;
        case 3:
          if(by < y){
            by = y;
          }
          break;
        case 2:
          if(x < tx){
            tx = x;
          }
          break;
        case 4:
          if(y < ty){
            ty = y;
          }
         break;
      }
  }
  cout << max(tx-bx,0)*max(ty-by,0) << endl;
  return 0;

}

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

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a.at(i);
    }
    sort(a.begin(), a.end());
    cout << a.at(a.size() - 1) - a.at(0) << endl;
}

Measured memory_bytes: 256
// ABC164C - gacha

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

int main() {
	int N;
	cin >> N;
	set<string> answer;

	for (int i = 0; i < N; i++) {
		string S;
		cin >> S;
		answer.insert(S);
	}

	cout << answer.size() << endl;

	return 0;
}


Measured memory_bytes: 19256
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <deque>
#include <utility>

int main(){
  std::string s;
  std::cin >> s;
  int val1=int(s[0])-int('a');
  if (val1>=0 && val1<26){
    printf("a\n");
  } else {
    printf("A\n");
  }
  return 0;
}
 

Measured memory_bytes: 3032
#include <iostream>
#include <vector>
#include <algorithm>
#include <random>
#include <string>
#include <cmath>
#include <sstream>
#include <istream>
#include <iomanip>
#include <typeinfo>
#include <stack>

using namespace std;
typedef long long ll;
ll N;

int main(){
    ll N;
    cin >> N;
    vector <ll > s(N, 0);
    ll s1 = 0;
    ll s2 = 0;
    for(ll i = 0; i < N; i++){
        cin >> s[i];
        s2 += s[i];
    }
    //sort(s.begin(), s.end());

    ll ans = s2;
    for(ll i = 0; i < N - 1; i++){
        s1 += s[i];
        s2 -= s[i];
        //cout << s1 << "," << s2 << endl;
        ans = min(abs(s1 - s2), ans);
        
    }

    cout << ans << endl;

} 

Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std; 
#define forn(i,n) for(int i=0;i<int(n);i++)
#define fora(i,a,b) for(int i=int(a);i<=int(b);i++)
typedef long long int ll;
void solve()
{
	string s;
	cin>>s;
	for(auto i:s)
	{
		if(i=='7')
		{
			cout<<"Yes"<<endl;
			return;
		}
	}
	cout<<"No"<<endl;
}
int main()
{
    ios::sync_with_stdio(0); 
    cin.tie(0); 
    cout.tie(0);
   	solve();
}

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

using namespace std;
int main(){
    int N, K, n, s;
    int* p;
    cin >> N >> K;
    p = new int[N];
    for(n=0;n<N;n++){
        cin >> p[n];
    }

    sort(p, p+N);
    s = 0;
    for(n=0;n<K;n++){
        s+= p[n];
    }
    cout << s;

    delete[] p;

    return 0;
}


Measured memory_bytes: 3560
def ctoi(c):
    return ord(c) - 97


def itoc(i):
    return chr(i + 97)


def ans(S):
    l = len(S)
    if l != 26:
        alpha = [False] * 26
        for i in range(l):
            alpha[ctoi(S[i])] = True
        for j in range(26):
            if not alpha[j]:
                ret = S + itoc(j)
                return ret
    else:
        alpha = [True] * 26
        for i in range(l):
            if i == l-1:
                ret = str(itoc(ctoi(S[0])+1))
                # alpha[ctoi(S[0])+1] = True
                # alpha[ctoi(S[0])] = False
                # k = 0
                # while len(ret) < l:
                #     if not alpha[k]:
                #         ret += itoc(k)
                #     k += 1
                return ret
            else:
                for j in range(ctoi(S[l-i-1])+1, 26):
                    if not alpha[j]:
                        ret = S[:l-i-1] + itoc(j)
                        # alpha[j] = True
                        # alpha[ctoi(S[l-i-1])] = False
                        # k = 0
                        # while len(ret) < l:
                        #     if not alpha[k]:
                        #         ret += itoc(k)
                        #     k += 1
                        return ret
                alpha[ctoi(S[l-i-1])] = False


S = input()
if S == "zyxwvutsrqponmlkjihgfedcba":
    print(-1)
else:
    print(ans(S))

Measured memory_bytes: 3064
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;



int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n;
    cin >> n;
    vector<int> A(n);
    for (int i = 0; i < n; ++i) {
        cin >> A[i];
    }

    int res = 0;
    for (auto x : A) {
        res += x - 1;
    }
    cout << res << '\n';

    return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.StringTokenizer;
import java.util.TreeMap;

public class Main {
    static int[] a;
    static int n;

    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        n = sc.nextInt();
        a = sc.nextIntArray(n);
        out.println(check());
        out.flush();
        out.close();
    }

    static int check() {
        TreeMap<Integer, Integer> map = new TreeMap<>();
        int s = 0;
        for (int i = 0; i < n; i++) {
            int cur = a[i];
            Integer best = map.lowerKey(cur);
            if (best != null) {
                int occ = map.get(best);
                if (occ == 1) map.remove(best);
                else
                    map.put(best, occ - 1);
                s--;
            }
            s++;
            map.put(cur, map.getOrDefault(cur, 0) + 1);
        }
        return s;
    }


    static class Scanner {

        StringTokenizer st;
        BufferedReader br;

        public Scanner(InputStream system) {
            br = new BufferedReader(new InputStreamReader(system));
        }


        public String next() throws IOException {
            while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }

        public String nextLine() throws IOException {
            return br.readLine();
        }

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

        public double nextDouble() throws IOException {
            return Double.parseDouble(next());
        }

        public char nextChar() throws IOException {
            return next().charAt(0);
        }

        public Long nextLong() throws IOException {
            return Long.parseLong(next());
        }

        public boolean ready() throws IOException {
            return br.ready();
        }


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

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


        public Integer[] nextIntegerArray(int n) throws IOException {
            Integer[] a = new Integer[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

        public double[] nextDoubleArray(int n) throws IOException {
            double[] ans = new double[n];
            for (int i = 0; i < n; i++)
                ans[i] = nextDouble();
            return ans;
        }

        public short nextShort() throws IOException {
            return Short.parseShort(next());
        }

    }
}

Measured memory_bytes: 45500
#include <algorithm>
#include <climits>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <vector>

// using
using namespace std;

// typedef
typedef long long ll;

// define
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define DEBUG(x) cerr << #x << ": " << x << "\n"

// functions
int ceil(int a, int b) {
    return (a + b - 1) / b;
}
int round(int a, int b) {
    return (a + b / 2) / b;
}
int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
template <class T> bool amax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> bool amin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

// main
int main() {
    int n;
    cin >> n;
    string s = to_string(n);
    string res = "";
    for (int i = 0; i < 3; ++i) {
        if (s[i] == '1') {
            res += "9";
        } else {
            res += "1";
        }
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func main() {
	sc.Split(bufio.ScanWords)
	N := getInt()
	a := make([]int, N)
	for i := 0; i < N; i++ {
		a[i] = getInt()
	}

	if N == 1 {
		out(1)
		return
	}

	dir := 0
	ans := 1
	pre := a[0]
	for i := 1; i < N; i++ {
		if pre == a[i] {
			continue
		}
		if pre > a[i] && dir == -1 {
			pre = a[i]
			continue
		}
		if pre < a[i] && dir == 1 {
			pre = a[i]
			continue
		}
		if dir == 0 {
			if pre > a[i] {
				dir = -1
			} else {
				dir = 1
			}
			pre = a[i]
			continue
		}
		ans++
		dir = 0
		pre = a[i]
	}
	out(ans)
}


Measured memory_bytes: 3072
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.util.NoSuchElementException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, FastScanner in, PrintWriter out) {
            int a = in.nextInt();
            int b = in.nextInt();
            int c = in.nextInt();

            out.println(b + Math.min(a + b + 1, c));
        }

    }

    static class FastScanner {
        private InputStream in;
        private byte[] buffer;
        private int bufPointer;
        private int bufLength;

        public FastScanner(InputStream in) {
            this.in = in;
            buffer = new byte[1024];
        }

        private boolean hasNextByte() {
            if (bufPointer < bufLength)
                return true;
            bufPointer = 0;
            try {
                bufLength = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            return (bufLength > 0);
        }

        private int readByte() {
            return hasNextByte() ? buffer[bufPointer++] : -1;
        }

        private static boolean isPrintableChar(int c) {
            return (c >= 33 && c <= 126);
        }

        public boolean hasNext() {
            while (hasNextByte() && !isPrintableChar(buffer[bufPointer]))
                bufPointer++;
            return hasNextByte();
        }

        public int nextInt() {
            long nl = nextLong();
            if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
                throw new NumberFormatException();
            return (int) nl;
        }

        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' || b > '9')
                throw new NumberFormatException();

            while (true) {
                if (b >= '0' && b <= '9') {
                    n *= 10;
                    n += b - '0';
                } else if (!isPrintableChar(b)) {
                    return minus ? -n : n;
                } else {
                    throw new NumberFormatException();
                }
                b = readByte();
            }
        }

    }
}



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

using ll = long long int;

const int MAX_N = (int)(1e5 + 5);

int n;
deque<ll> a;

deque<ll> ans_deq;

ll ans;

ll mysolve() {
  deque<ll> ans_deq;

  ans_deq.push_front(a.front());
  a.pop_front();

  while (!a.empty()) {

    if (abs(ans_deq.front() - a.front()) >= abs(ans_deq.back() - a.front()) &&
        abs(ans_deq.front() - a.front()) >= abs(ans_deq.back() - a.back()) &&
        abs(ans_deq.front() - a.front()) >= abs(ans_deq.front() - a.front()) &&
        abs(ans_deq.front() - a.front()) >= abs(ans_deq.front() - a.back())) {
      ans_deq.push_front(a.front());
      a.pop_front();
    }
    else if (abs(ans_deq.front() - a.back()) >= abs(ans_deq.back() - a.front()) &&
             abs(ans_deq.front() - a.back()) >= abs(ans_deq.back() - a.back()) &&
             abs(ans_deq.front() - a.back()) >= abs(ans_deq.front() - a.front()) &&
             abs(ans_deq.front() - a.back()) >= abs(ans_deq.front() - a.back())) {
      ans_deq.push_front(a.back());
      a.pop_back();
    }
    else if (abs(ans_deq.back() - a.front()) >= abs(ans_deq.back() - a.front()) &&
             abs(ans_deq.back() - a.front()) >= abs(ans_deq.back() - a.back()) &&
             abs(ans_deq.back() - a.front()) >= abs(ans_deq.front() - a.front()) &&
             abs(ans_deq.back() - a.front()) >= abs(ans_deq.front() - a.back())) {
      ans_deq.push_back(a.front());
      a.pop_front();
    }
    else if (abs(ans_deq.back() - a.back()) >= abs(ans_deq.back() - a.front()) &&
             abs(ans_deq.back() - a.back()) >= abs(ans_deq.back() - a.back()) &&
             abs(ans_deq.back() - a.back()) >= abs(ans_deq.front() - a.front()) &&
             abs(ans_deq.back() - a.back()) >= abs(ans_deq.front() - a.back())) {
      ans_deq.push_back(a.back());
      a.pop_back();
    }

    /*
    for (auto e: ans_deq) {
      printf("%lld ", e);
    }
    printf("\n");
    */
  }

  ll tmpans = 0;

  for (int i = 1; i < ans_deq.size(); ++i) {
    tmpans += abs(ans_deq[i] - ans_deq[i - 1]);
  }

  return tmpans;
}

int main(void) {
  // Here your code !
  scanf("%d", &n);

  for (int i = 0; i < n; ++i) {
    ll tmp;
    scanf("%lld", &tmp);
    a.push_front(tmp);
  }


  sort(a.begin(), a.end());

  ll my = mysolve();

  printf("%lld\n", my);
}

Measured memory_bytes: 1152
n, x = map(int,input().split())
li = list(input().split())
li = [abs(int(a)-x) for a in li]

def gcd(a,b):
    while a%b!=0:
        a,b = b,a%b
    return b
    
from functools import reduce

a = reduce(gcd,li)
print(a)

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

int main(void){
    char s[101], t[101];
    int i=0, leng = 0, flag = 0;
    scanf("%s", s);
    scanf("%s", t);
    while(1){
        if(s[i] != 0) i++;
        else break;
    }
    leng = i;
    for(i=0; i<leng; i++){
        for(int j=0; j<leng; j++){
            if(s[((i+j)%leng)] != t[j]) break;
            if(j==leng-1) flag = 1;
        }
    }
    if(flag == 1) printf("Yes");
    else printf("No");
}


Measured memory_bytes: 128
import java.util.Scanner;

public class Main{

	public static void main(String args[]){
		new Main().mainrun();
	}

	private Scanner scan;
	private int n;

	public void mainrun() {
		scan = new Scanner(System.in);

		n = scan.nextInt();

		int max = Integer.MIN_VALUE;
		int min = scan.nextInt();
		
		for(int i = 1;i < n;i++) {
			int R = scan.nextInt();
			
			max = Math.max(max, R - min);
			
			min = Math.min(min, R);
		}

		System.out.println(max);
	}
}


Measured memory_bytes: 99396
from bisect import bisect_left as bl
from bisect import bisect_right as br
from heapq import heappush,heappop
from math import floor,ceil
from collections import *
from functools import reduce,cmp_to_key
import sys
input = sys.stdin.readline

M = mod = 998244353
def factors(n):return sorted(set(reduce(list.__add__, ([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0))))
def inv_mod(n):return pow(n, mod - 2, mod)

def li():return [int(i) for i in input().rstrip('\n').split()]
def st():return input().rstrip('\n')
def val():return int(input().rstrip('\n'))
def li2():return [i for i in input().rstrip('\n')]
def li3():return [int(i) for i in input().rstrip('\n')]


a,b = li()
ans = float('inf')
i = b
j = a

d = defaultdict(int)
low1,high1 = a/0.08,(a + 1)/0.08
low2,high2 = b/(0.1),(b + 1)/0.1
for i in range(ceil(low1),ceil(high1),1):
    d[i] += 1

ans = -1
for i in range(ceil(low2),ceil(high2),1):
    if d[i]:
        ans = i
        break

print(ans)



Measured memory_bytes: 3676
#include<bits/stdc++.h>
#define X first
#define Y second
#define pb emplace_back
#define FOR(i,a,b) for(int (i)=(a);i<(b);++(i))
#define EFOR(i,a,b) for(int (i)=(a);i<=(b);++(i))
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define rreps(X,S,Y) for (int (X) = (Y)-1;(X) >= (S);--(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef ll LL;
typedef pii PII;
typedef pll PLL;
template<class T> using vv=vector<vector<T>>;
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
const ll MOD=1e9+7;
const LL INF = 0x3fffffffffffffff;

int L;
LL A[214514];
LL imos[214514];
LL dp[214514][10];

int main() {
  scanf("%d", &L);
  reps(i, 1, L+1) {
    scanf("%lld", &A[i]);
    imos[i] = A[i] + imos[i-1];
  }

  fill(dp[0], dp[L+1], INF);
  LL ans = imos[L];
  reps(i, 1, L+1) {
    dp[i-1][0] = imos[i-1];
    rep(st, 4) {
      rep(nst, 4) {
        if (st != 0 && nst - st > 1) continue;
        if (st > nst) continue;
        
        LL val = dp[i-1][st];
        if (A[i] > 0) val += (A[i]%2) == (nst%2);
        else val += 1+nst%2;

        MN(dp[i][nst], val);
        MN(ans, dp[i][nst] + imos[L] - imos[i]);
      }
    }
  }
  printf("%lld\n", ans);
}


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

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            // 解答はココに書く
            var s = cin.Read;
            WriteLine(s.Count(x => x == '1'));
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }
}


Measured memory_bytes: 13396
package main
     
import (
    "fmt"
)
 
func main() {
	var n,a,b int
    fmt.Scan(&n, &a, &b)
    if a==0 && b ==0 { fmt.Println("0") }
    min :=  (n /(a+b)) * a
    rem := n % (a+b)
    if rem > a {
        fmt.Println(min+a)
    } else {
        fmt.Println(min+rem)
    }
}

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

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

Measured memory_bytes: 256
N, C = map(int, input().split())
D = []
for _ in range(C):
    D.append([int(d) for d in input().split()])
t = [[0 for _ in range(C)] for _ in range(3)]
for i in range(N):
    for j, c in enumerate(input().split()):
        c = int(c) - 1
        t[(i + j) % 3][c] += 1

ans = float('inf')
for i in range(C):
    for j in range(C):
        if i == j:
            continue
        for k in range(C):
            if i == k or j == k:
                continue
            res = 0
            for l in range(C):
                res += D[l][i] * t[0][l]
                res += D[l][j] * t[1][l]
                res += D[l][k] * t[2][l]
            ans = min(ans, res)
print(ans)

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

const int Maxn = 100005;
int n, m, a[Maxn];
long long sum, ans = 0x3f3f3f3f3f3f3f3f;
long long s1[Maxn << 1], s2[Maxn << 1];
int main(int argc, const char *argv[]) {
  ios_base :: sync_with_stdio(false);
  cin.tie(nullptr), cout.tie(nullptr);
  cout << fixed << setprecision(12);
  cin >> n >> m;
  for (int i = 0; i < n; ++ i)
    cin >> a[i], a[i] --;
  for (int i = 1; i < n; ++ i) {
    int x = a[i - 1], y = a[i];
    if (x > y) y += m;
    s1[x + 1] ++, s1[y + 1] --;
    s2[y + 1] -= y - x;
  }
  for (int i = 1; i <= 2 * m; ++ i)
    s1[i] += s1[i - 1], s2[i] += s2[i - 1] + s1[i];
  for (int i = 0; i < m; ++ i)
    s1[i] += s1[i + m], s2[i] += s2[i + m], sum += s1[i];
  for (int i = 1; i <= 2 * m; ++ i)
    ans = min(ans, sum - s2[i] + s1[i]);
  cout << ans << endl;
}

Measured memory_bytes: 3840
# coding: utf-8
import math
import sys

N, M = map(int, input().split())
mods = [[] for _ in range(M)]
for x in map(int, input().split()):
    mods[x % M].append(x)

mods_cnt = [len(mods[i]) for i in range(M)]

cnt = mods_cnt[0] // 2
mods_cnt[0] -= cnt * 2
if M % 2 == 0:
    c = mods_cnt[M//2] // 2
    cnt += c
    mods_cnt[M//2] -= c * 2

for i in range(1, math.ceil(M / 2)):
    c = min(mods_cnt[i], mods_cnt[-i])
    cnt += c
    mods_cnt[i] -= c
    mods_cnt[-i] -= c

for i in range(M):
    if mods_cnt[i] >= 2:
        mods_cnt[i] -= 1
        mods[i].sort()
        j = 0
        c = 0
        while j < len(mods[i]) - 1:
            if mods[i][j] == mods[i][j + 1]:
                c += 1
                j += 2
                if c * 2 >= mods_cnt[i]:
                    break
            else:
                j += 1
        cnt += c

print(cnt)


Measured memory_bytes: 24368
n,m = (int(x) for x in input().split())
list = (input().split())
for i in range(len(list)):
  list[i] = int(list[i])
la = sorted(list, reverse=True)
sum = 0
for i in range(len(list)):
  sum += list[i]
if la[m-1]<sum/(4*m):
  print('No')
else:
  print('Yes')

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

typedef long long ll;
typedef vector<int> Vi;
typedef vector<ll> Vl;
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;


//===

const ll mod = static_cast<ll>(1e9 + 7);

bool check(int state, Vi s, bool p) {
	bool is_odd = 0;
	for (const auto& val : s) {
		if ((state >> val) & 1) {
			is_odd ^= 1;
		}
	}

	return !(is_odd ^ p);
}


int main() {
	int N, M;
	cin >> N >> M;
	Vi kk(M);
	vector<Vi> ss(M);
	vector<bool> pp(M);
	for (int i = 0; i < M; ++i) {
		cin >> kk[i];
		for (int j = 0; j < kk[i]; ++j) {
			int tmp;
			cin >> tmp;
			ss[i].push_back(tmp - 1);
		}
	}
	for (int i = 0; i < M; ++i) {
		int tmp;
		cin >> tmp;
		pp[i] = static_cast<bool>(tmp);
	}

	int ans = 0;
	for (int state = 0; state < (1 << N); ++state) {
		bool ison = true;
		for (int j = 0; j < M; ++j) {
			ison &= check(state, ss[j], pp[j]);
		}
		if (ison) ++ans;
	}
	cout << ans << endl;
}

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

int main(){
  int a, b, c, x, y;

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

  int total1, total2, total3;

  // if(((a+b)/2 > c) && (min(a,b) < c)){                                                                     
  //   if(x < y){                                                                                             
  //     total = x*2*c + (y-x)*b;                                                                             
  //    }                                                                                                     
  //   else{                                                                                                  
  //     total = y*2*c + (x-y)*a;                                                                             
  //    }                                                                                                     
  // }                                                                                                        
  // else if(((a+b)/2 <= c) && (min(a,b) < c)){                                                               
  //   total = a*x + b*y;                                                                                     
  //  }                                                                                                       
  // else{                                                                                                    
  //   total = max(x,y)*2*c;                                                                                  
  // }                                                                                                        

  // if(max(x,y)*2*c < total){                                                                                
  //   total = max(x,y)*2*c;                                                                                  
  // }                                                                                                        

  if(x < y){
    total1 = x*2*c + (y-x)*b;
  }
  else{
    total1 = y*2*c + (x-y)*a;
  }
  total2 = a*x + b*y;
  total3 = max(x,y)*2*c;

  cout << min(total1,min(total2,total3)) << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
int main(){
   string s;
   cin >> s;
   if(s=="SUN"){
       cout << 7 << endl;
   }
   if(s=="MON"){
       cout << 6 << endl;
   }
   if(s=="TUE"){
       cout << 5 << endl;
   }
   if(s=="WED"){
       cout << 4 << endl;
   }
    if(s=="THU"){
       cout << 3 << endl;
   }
    if(s=="FRI"){
       cout << 2 << endl;
   }
    if(s=="SAT"){
       cout << 1 << endl;
   }
}

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

int main() {
	int A, B, ans;
	cin >> A >> B;

	if (A > B) {
		ans = A;
		A -= 1;
	}
	else {
		ans = B;
		B -= 1;
	}

	if (A > B) {
		ans += A;
	}
	else {
		ans += B;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
Created on Fri May  8 14:30:55 2020

@author: shinba
"""
import copy

n,k = map(int,input().split())
p = list(map(int,input().split()))

a = 0
for i in range(k):
    a += p[i]

q = []

for i in range(n-k):
    q.append(p[i+k]-p[i])

ans = copy.copy(a)
for i in q:
    a += i
    ans = max(ans,a)

print((ans+k)/2)

Measured memory_bytes: 25700
#include <bits/stdc++.h>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<iostream>
#include <math.h>
#include<algorithm>
using namespace std;
#define MAX 25

struct node{
  int key;
  node *p,*l,*r;
};

node *NIL,*root;

void insert(node * z){
  node * y=NIL;
  node * x=root;
  while(x!=NIL){
    y=x;
    if(z->key < x->key){
      x=x->l;
    }else{
      x=x->r;
    }
  }
  z->p=y;

  if(y==NIL){
    root=z;
  }else if(z->key < y->key){
    y->l=z;
  }else{
    y->r=z;
  }
}

void Preorder(node * x){
  if(x==NIL) return;
  cout<<" "<<x->key;
  Preorder(x->l);
  Preorder(x->r);
}

void Inorder(node * x){
  if(x==NIL) return;
  Inorder(x->l);
  cout<<" "<<x->key;
  Inorder(x->r);
}

node * find(int k){
  node *x=root;
  while(x!=NIL && k!=x->key){
    if(x->key < k){
      x=x->r;
    }else{
      x=x->l;
    }
  }
  return x;
}

node * nextnode(node * x){
  if(x->r!=NIL){
     x=x->r;
     while(x->l!=NIL){
       x=x->l;
     }
  }
  return x;
}

void deletenode(int k){
  node *z=find(k);
  node *y,*child;
  if(z->l==NIL || z->r==NIL){
    y=z;
  }else{
    y=nextnode(z);
  }
  if(y->l!=NIL) child=y->l;
  else child=y->r;

  if(y->p==NIL){
    root=child;
  }else{
    if(child!=NIL){
    child->p=y->p;
    }
    if(y==y->p->l) y->p->l=child;
    else y->p->r=child;
  }

  if(z!=y){
    z->key=y->key;
  }
  free(y);

}


int main(){
  int n,x;
  cin>>n;
  string s;
  for(int i=0;i<n;i++){
    cin>>s;
    if(s=="insert"){
      cin>>x;
      node * a=(node *)malloc(sizeof(node));
      a->key=x;
      a->l=a->r=NIL;
      insert(a);
    }else if(s=="print"){
      Inorder(root);
      cout<<endl;
      Preorder(root);
      cout<<endl;
    }else if(s=="find"){
      cin>>x;
      if(find(x)!=NIL) cout<<"yes"<<endl;
      else cout<<"no"<<endl;
    }else{
      cin>>x;
      deletenode(x);
    }
  }
  return 0;
}



Measured memory_bytes: 21796
def binary(n):
    return bin(n)[2:]

def pow_by_binary_exponentiation(a, x, n):  # a^x mod n
    x = [int(b) for b in binary(x)]
    y = a
    for i in range(1, len(x)):
        y = (y**2) % n
        if x[i] == 1:
            y = (y * a) % n
    return y

 # mを法とするaの乗法的逆元
def modinv(a, m):
    g, x, y = egcd(a, m)
    if g != 1:
        raise Exception('modular inverse does not exist')
    else:
        return x % m

def egcd(a, b):
    if a == 0:
        return b, 0, 1
    else:
        g, y, x = egcd(b % a, a)
        return g, x - (b // a) * y, y


# nCr mod m
# modinvが必要
# rがn/2に近いと非常に重くなる
def combination(n, r, mod=10**9 + 7):
    r = min(r, n - r)
    res = 1
    for i in range(r):
        res = res * (n - i) * modinv(i + 1, mod) % mod
    return res
n, a, b = map(int, input().split())


mod = 10**9 + 7
X = combination(n,a)
Y = combination(n,b)
Z = pow_by_binary_exponentiation(2,n,mod) - 1
W = (Z - X - Y) % mod
if W < 0:
    W += mod
print(W % mod)


Measured memory_bytes: 3064
r, c = [int(i) for i in input().split()]
data = [[int(i) for i in input().split()] for j in range(r)]
ans = [data[i] + [sum(data[i])] for i in range(r)]
last_ans = ans + [[sum([ans[i][j] for i in range(r)]) for j in range(c+1)]]
for i in last_ans:
    print(*i)


Measured memory_bytes: 6292
# -*- coding: utf-8 -*-
"""
Created on Sat Sep 23 19:10:57 2017

@author: taichiNakamura
"""

# -*- coding: utf-8 -*-
# 整数の入力
N = int(input())
# スペース区切りの整数の入力
a = input().split()

a = list(map(int, a))

favorite = 0
for i,ai in enumerate(a):
    if a[ai-1] == (i+1):
        favorite += 1

print(favorite//2)


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

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

const int N = 1e5 + 5;

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int n;
	cin >> n;
	bool ok = 1;
	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		if(a % 2 == 0) {
			if((a % 3) && (a % 5))
				ok = 0;
		}
	}
	if(ok)
		cout << "APPROVED\n";
	else
		cout << "DENIED\n";
}

Measured memory_bytes: 256
#include <iostream>
//#include <vector>
#include <string>
#include <algorithm>
//#include <math.h>
//#include <queue>
//#include <stack>
//#include <iomanip>

// sometimes used
//#include <set>
//#include <map>
//#include <numeric>
//#include <list>
//#include <deque>
//#include <unordered_map>

//typedef long long LL;
//typedef long double LD;
using namespace std;
 
//#define MOD 1000000007
//#define MAX 200100
//#define NIL -1

int main() {
    string s;
    string t;
    cin >> s >> t;
    sort(s.begin(), s.end());
    sort(t.begin(), t.end());
    reverse(t.begin(), t.end());
    //cout << s << " " << t << endl;
    if(s<t){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#include<sstream>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef pair<int,pii> pip;
typedef vector<pip>vip;
const double PI=acos(-1);
const double EPS=1e-8;
const int inf=1e8;
int main(){
	int n,m,k;
	while(cin>>n>>m>>k,n){
		vi a(n);
		rep(i,n)cin>>a[i];
		sort(all(a),[](int a,int b){return a>b;});
		int out=0;
		int outa=0;
		loop(i,m,k+1){
			int t=a[i-1]-a[i];
			if(out<=t){
				out=t;
				outa=i;
			}
		}
		cout<<outa<<endl;
	}
}

Measured memory_bytes: 3016