akhauriyash/Code-Regression huggingface dataset:
//https://atcoder.jp/contests/abc176/tasks/abc176_f#

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

using lint = long long;
const int MAXN = 6005;
const int INF = 1e5;

int N;
int A[MAXN];

int ans = 0;
int base = 0;
int nxt[MAXN];
int dp[MAXN][MAXN];

int Cost(int a, int b, int c) {
  return A[a] == A[b] && A[b] == A[c];
}

void Transition(int i, int j, int cur) {
  if (cur > 3 * N) return;
  if (cur == 3 * N) {
    ans = max(ans, dp[i][j] + Cost(i, j, cur));
    return;
  }
  dp[cur + 0][cur + 1] = max(dp[cur + 0][cur + 1], dp[i][j] + Cost(i, j, cur + 2));
  dp[cur + 0][cur + 2] = max(dp[cur + 0][cur + 2], dp[i][j] + Cost(i, j, cur + 1));
  dp[cur + 1][cur + 2] = max(dp[cur + 1][cur + 2], dp[i][j] + Cost(i, j, cur + 0));

  dp[i][cur + 0] = max(dp[i][cur + 0], dp[i][j] + Cost(j, cur + 1, cur + 2));
  dp[i][cur + 1] = max(dp[i][cur + 1], dp[i][j] + Cost(j, cur + 0, cur + 2));
  dp[i][cur + 2] = max(dp[i][cur + 2], dp[i][j] + Cost(j, cur + 0, cur + 1));

  dp[j][cur + 0] = max(dp[j][cur + 0], dp[i][j] + Cost(i, cur + 1, cur + 2));
  dp[j][cur + 1] = max(dp[j][cur + 1], dp[i][j] + Cost(i, cur + 0, cur + 2));
  dp[j][cur + 2] = max(dp[j][cur + 2], dp[i][j] + Cost(i, cur + 0, cur + 1));
  dp[i][j] = max( dp[i][j], dp[i][j] + Cost(cur+0, cur + 1, cur + 2));

}

int main() {

  cin >> N;
  for (int i = 1; i <= 3 * N; i++)
    cin >> A[i];


  while (true) {
    bool change = false;
    for (int i = 3; i + 2 <= 3 * N; i += 3) {
      if (A[i] == A[i + 1] && A[i + 1] == A[i + 2]) {
        base += 1;
        for (int j = i + 3; j <= 3 * N; j++) {
          A[j - 3] = A[j];
        }
        N -= 1;
        change = true;
        break;
      }
    }
    if (!change) {
      break;
    }
  }

  vector<int> last(3 * N + 1, 3 * N + 1);
  for (int i = 3 * N; i > 0; i--) {
    nxt[i] = last[A[i]];
    last[A[i]] = i;
  }
  for (int i = 0; i < MAXN; i++) {
    for (int j = 0; j < MAXN; j++) {
      dp[i][j] = -INF;
    }
  }
  dp[1][2] = 0;
  for (int i = 1; i <= 3 * N; i++) {
    for (int j = i + 1; j <= 3 * N; j++) {
      Transition(i, j, (j + 3) / 3 * 3);
            Transition(i, j, (j + 3) / 3 * 3);

      // Find next occurrence of A[i]
      if ( (j / 3 * 3) < (nxt[i] / 3 * 3) )
        Transition(i, j, nxt[i] / 3 * 3);

      // Find next occurrence of A[j]
      if (j / 3 * 3 < nxt[j] / 3 * 3)
        Transition(i, j, nxt[j] / 3 * 3);

    }
  }

  cout << ans + base << "\n";
  return 0;
}


Measured memory_bytes: 144564
n, k = map(int, input().split())

mod = 10 ** 9 + 7

fac = [1]
for i in range(1, 2 * n + 1) :
  fac.append(fac[-1] * i % mod)
inv = [pow(fac[-1], mod - 2, mod)]
for i in range(2 * n, 0, -1) :
  inv.append(inv[-1] * i % mod)
  
inv = inv[::-1]

def comb(n, r) :
  if n < 1 or n < r : return 0
  return fac[n] * inv[r] * inv[n-r] % mod
  
ret = comb(n + n - 1, n)
for i in range(1, n - k) :
  ret -= comb(n - 1, k + i) * comb(n, k + i)
  ret %= mod
print(ret % mod)

Measured memory_bytes: 75884
#include <bits/stdc++.h>
         
    using namespace std;
                 
    #define pb push_back
    #define ll long long
    #define mp make_pair
    #define MOD 1000000007
    #define MAX 100000000
    #define MIN -1000000000
    #define LLINF 0x3f3f3f3f3f3f    
    #define INF 0x3f3f3f3f
    #define MAXN 200200

    int main()
    {
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        int n;
        cin >> n;
        map<string, int> m;
        m["AC"] == 0;
        m["WA"] == 0;
        m["TLE"] == 0;
        m["RE"] == 0;
        while(n--){ 
            string s;
            cin >> s;
            m[s]++;
        }
        cout << "AC" << " " << "x" << " " << m["AC"] << endl;
        cout << "WA" << " " << "x" << " " << m["WA"] << endl;
        cout << "TLE" << " " << "x" << " " << m["TLE"] << endl;
        cout << "RE" << " " << "x" << " " << m["RE"] << endl;

        return 0;
    }

Measured memory_bytes: 3644
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		string[] str = Console.ReadLine().Split();
		int N = int.Parse(str[0]);
		int A = int.Parse(str[1]);
		int B = int.Parse(str[2]);
		int C = int.Parse(str[3]);
		int D = int.Parse(str[4]);
		string s = Console.ReadLine();
		var list = new List<int>();
		list.Add(B);
		int[]E = new int[N+1];
		bool flag = false;
		while(list.Count>0){
			var list2 = new List<int>(list);
			list.Clear();
			foreach(var h in list2){
				if(h+1<=N && E[h+1]==0){
					if(s.Substring(h+1-1,1)=="."){
						list.Add(h+1);
						E[h+1] = 1;
						if(h+1==D){
							flag = true;
							break;
						}
					}
				}
				if(h+2<=N && E[h+2]==0){
					if(s.Substring(h+2-1,1)=="."){
						list.Add(h+2);
						E[h+2] = 1;
						if(h+2==D){
							flag = true;
							break;
						}
					}
				}
			}
		}
		if(flag){
			flag = false;
			list.Clear();
			list.Add(A);
			int[]E2 = new int[N+1];
		while(list.Count>0){
			var list2 = new List<int>(list);
			list.Clear();
			foreach(var h in list2){
				if(h+1<=N && E2[h+1]==0){
					if(s.Substring(h+1-1,1)=="."){
						list.Add(h+1);
						E2[h+1] = 1;
						if(h+1==C){
							flag = true;
							break;
						}
					}
				}
				if(h+2<=N && E2[h+2]==0){
					if(s.Substring(h+2-1,1)=="."){
						list.Add(h+2);
						E2[h+2] = 1;
						if(h+2==C){
							flag = true;
							break;
						}
					}
				}
			}
		}
		}
		if(flag){
			if(C>D){
				flag = false;
				for(var i=B-2;i<=D-2;i++){
					if(s.Substring(i,1)=="." && s.Substring(i+1,1)=="." && (i+2>D-1 || s.Substring(i+2,1)==".")){
                      	flag = true;
						break;
					}
				}
			}
		}
		string ans = "No";
		if(flag){
			ans = "Yes";
		}
		Console.WriteLine(ans);
	}
}

Measured memory_bytes: 17368
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a,b;
ll ans;

int main()
{
    
    cin>>a>>b;
  if(b==1){
    ans=0;
  }else{
  
    for(int i=0;i<100;i++)
    {
        if(a+(a-1)*i >= b){
          ans=i+1;
          break;
        }
    }
  }
    cout<<ans;
    cout<<endl;
    return 0;
}

Measured memory_bytes: 256
import numpy as np

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
  
def prime_decomposition(n):
  i = 2
  table = []
  while i * i <= n:
    while n % i == 0:
      n /= i
      table.append(i)
    i += 1
  if n > 1:
    table.append(n)
  return table


a, b = list(map(int, input().split(' ')))
q = gcd(a,b)
t = prime_decomposition(q)

print(len(set(t))+1)

Measured memory_bytes: 21112
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define print(x)cout<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

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

mint dp[101010][2];
int main() {
  string s;
  cin>>s;
  int n = sz(s);
  dp[0][0] = 1;

  rep(i,n){
    dp[i+1][1] += dp[i][1]*3;
    if(s[i] == '0'){
        dp[i+1][0] = dp[i][0]; 
    }else{
      dp[i+1][1] += dp[i][0];
      dp[i+1][0] += dp[i][0]*2;
    }
  }
  mint ans = dp[n][0]+dp[n][1];
  print(ans.x);
  return 0;
}

Measured memory_bytes: 2048
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        for(int i=1;i<=9;i++){
            for(int j=1;j<=9;j++)if(i*j==N){
                System.out.println("Yes");
                return ;
            }
        }
        System.out.println("No");
    }
}


Measured memory_bytes: 22868
n = int(input())
A = list(map(int, input().split()))
nux = max(A)
B = set(A)
A.sort()
ans = 0
table = [True]*(nux+1)
for ii, s in enumerate(A):
    if table[s] == False:
        continue
    if ii == n-1:
        ans += 1
    elif A[ii+1] != s:
        ans += 1
    i = 1
    while i*s <= nux:
        table[i*s] = False
        i += 1

print(ans)


Measured memory_bytes: 35192
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<utility>
#include<string>
#include<stack>
#include<queue>
#include<set>
#include<math.h>
#include <map>
using namespace std;
typedef long long int ll;
#define repi(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,a) repi(i,0,a)
#define all(u) u.begin(),u.end()
#define pl pair<ll,ll>
#define fi first
#define se second
#define inf 1000000007

ll N;
vector<ll>P;
vector<ll>Q;

void prime(){
    P.push_back(2);
    for(ll i=3; i<= 55555; i+=2){
        ll check = 0;
        for(ll j=3; j<=sqrt(i)+1;j+=2){
            if (i % j == 0){
                check = 1;
                break;
            }
        }
        if (check == 0){
            P.push_back(i);
        }
        
    }
    return;
}

int main() {
    cin >> N;
    prime();
    rep(i,P.size()){
        if (P[i] % 5 == 1){
            Q.push_back(P[i]);
        }
    }
    rep(i,N) cout << Q[i] <<" ";
    cout << endl;
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
  int N;
  cin >> N;
  int m=1000000000;
  vector<int> A(210);
  for(int i=0;i<N;i++){
    cin >> A.at(i);
  }
  for(int i=0;i<N;i++){
	int count=0;
    while(A.at(i)%2==0){
     A.at(i)/=2;
     count ++; 
    }
  m = min(m,count);  
  }

   cout << m << endl;
}

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

using namespace std;

int main() {
    int W, a, b;
    cin >> W >> a >> b;
    int ans;
    if(b > a + W) cout << b - a - W << endl;
    else if(a <= b and b <= a + W) cout << 0 << endl;
    else if(a <= b + W and b + W <= a + W) cout << 0 << endl;
    else cout << a - b - W << endl;
}

Measured memory_bytes: 256
// YOU THINK YOU KNOW ME.//


#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
using namespace std;
#define int                      long long
#define MOD                     1000000007
#define inf                     9e18
#define ld                      long double
#define countbit                __builtin_popcount
#define loop(i,a,n)				for(int i=a;i<n;i++)
#define pb                      push_back
#define pf                      push_front
#define mp                      make_pair
#define f                       first
#define s                       second
#define isvowel(a)              (a == 'a' || a == 'e' || a == 'i' || a == 'o' || a == 'u')
#define boost                   ios_base::sync_with_stdio();cin.tie(0);cout.tie(0);
#define cases                   int tests;cin>>tests;while(tests--)
#define all(s)                  s.begin(),s.end()
#define line                    cout<<endl;
#define watch(x)                cout<<(#x)<<" is "<<x<<endl
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> rich_set;
bool isprime(int n){if(n==1)return false;if(n==2)return true;for(int i=2;i<=sqrt(n);i++){if(n%i==0){ return false;}}return true;}
int poww(int b,int e){if(e==0)return 1;else if(e%2==0){int a=pow(b,e/2);return a*a;}else {int a=pow(b,e/2);return b*a*a;}}
int powm(int x,int y,int m=MOD){x=x%m;int res=1;while(y){if(y&1)res=res*x;res%=m;y=y>>1;x=x*x;x%=m;}return res;}
int modInverse(int a, int m=MOD) { return powm(a, m-2, m);}
void print(vector<int>v){for(int i=0;i<v.size();i++){cout<<v[i]<<" ";}}
void print(int arr[]){int size = *(&arr + 1) - arr; for(int i=0;i<size;i++){cout<<arr[i]<<" ";}}
string to_bin(int n){string res="";int i=0;while(n>0){if(n%2==1){res=res+'1';}else{res=res+'0';}n/=2;i++;}reverse(all(res));return res;}
int to_dec(string s){int n=s.size(),ans=0,temp=1;for(int i=n-1; i>=0; i--){int x=s[i]-'0';ans+=x*temp;temp*=2;}return ans;}
void result(bool f){if(f)cout<<"YES"<<endl;else cout<<"NO"<<endl;}



void solve(){
	int n;
    cin>>n;
    int w;
    cin>>w;
    int wt[n+1];
    int val[n+1];
    loop(i,0,n){
        cin>>wt[i]>>val[i];
    }
    int dp[n+1][w+1];
    loop(i,0,n+1){
        loop(j,0,w+1){
            if(i==0 || j==0)dp[i][j]=0;
            else if(wt[i-1]<=j){
                dp[i][j]= max(dp[i-1][j], val[i-1] + dp[i-1][j-wt[i-1]]);
            }
            else{
                dp[i][j]=dp[i-1][j];
            }
        }
    }
    cout<<dp[n][w];line

}
int32_t main(){
	boost
  //cases
	solve();	
	
	//return 0;
}

Measured memory_bytes: 79104
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N;
    cin >> N;
    vector<int> num(N);
    for(int i=0;i<N;i++){
        cin >> num[i];
    }
    reverse(num.begin(),num.end());
    for(int i=0;i<N;i++){
        cout << num[i];
        if(i!=N-1){
            cout << ' ';
        }
    }
    cout << endl;
}


Measured memory_bytes: 3064
import java.util.*;
public class Main{
    public static void main(String[] args){
	new Main().run();
    }
    Scanner sc = new Scanner(System.in);

    int n;
    int[] fibTri;
    
    void run(){
	calc();
	while(true){
	    n = sc.nextInt();
	    if(n==0) break;

	    int pattern = fibTri[n];;
	    int day = pattern%10==0 ? pattern/10 : pattern/10+1;
	    System.out.println(day%365==0 ? day/365 : day/365+1);
	}
    }

    void calc(){
	fibTri = new int[31];
	fibTri[0] = 0;
	fibTri[1] = 1;
	fibTri[2] = 2;
	fibTri[3] = 1+fibTri[1]+fibTri[2];
	
	for(int i=4; i<fibTri.length; i++)
	    fibTri[i] = fibTri[i-1]+fibTri[i-2]+fibTri[i-3];
    }
}

Measured memory_bytes: 17164
n=int(input())
s=[]
t=[]
u=[]
for i in range(n):
    s_i,t_i=input().split()
    s.append(s_i)
    t.append(int(t_i))
x=input()
for i in range(n):
    if s[i]!=x:
        u.append(t[i])
    else:
        u.append(t[i])
        ans=sum(t)-sum(u)
        break
print(ans)

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

typedef long long LL;

void setIO() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
}

LL dp[2001];

int main() {
    setIO();
    LL n;
    cin>>n;
    
    dp[0]=1;
    LL sum=0;
    LL mod = 1e9+7;
    for (int i = 1; i <= n; i++) {
        if (i >= 3) sum = (sum + dp[i-3]) % mod;
        dp[i] = sum;
    }
    cout<<dp[n]<<endl;
    return 0;
}

Measured memory_bytes: 3608
#include <algorithm>
#include <cctype>
#include <bitset>
using namespace std;
inline int read(int f = 1, int x = 0, char ch = ' ')
{
    while(!isdigit(ch = getchar())) if(ch == '-') f = -1;
    while(isdigit(ch)) x = x*10+ch-'0', ch = getchar();
    return f*x;
}
const int N = 4e2+5, M = 1e5+5;
bitset<N> s[N];
int n, m, u[M], v[M], d[N], ans;
int main()
{
    n = read(), m = read();
    for(int i = 1; i <= m; ++i) u[i] = read(), v[i] = read();
    for(int i = 1; i <= n; ++i)
    {
        s[i][i] = 1;
        for(int j = m; j; --j)
            if(s[i][u[j]]&&s[i][v[j]]) d[i] = 1, j = 1;
            else if(s[i][u[j]]) s[i][v[j]] = 1;
            else if(s[i][v[j]]) s[i][u[j]] = 1;
    }
    for(int i = 1; i <= n; ++i)
    {
        if(d[i]) continue;
        for(int j = i+1; j <= n; ++j)
            if(!d[j]&&(s[i]&s[j]).none()) ++ans;
    }
    printf("%d\n", ans);
    return 0;
}

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int h, w;
  cin >> h >> w;
  
  vector<vector<int>> x(h, vector<int>(w)), y(h, vector<int>(w));
  char c;
  for(int i = 0; i < h; i++){
    for(int j = 0; j < w; j++){
      cin >> c;
      if(c == '.') x.at(i).at(j) = y.at(i).at(j) = 1;
      else x.at(i).at(j) = y.at(i).at(j) = 0;
    }
  }
  
  // 横方向
  for(int i = 0; i < h; i++){
    for(int j = 1; j < w; j++){
      x.at(i).at(j) = x.at(i).at(j) * (x.at(i).at(j - 1) + 1);
    }
  }
  for(int i = 0; i < h; i++){
    for(int j = w - 2; j >= 0; j--){
      if(x.at(i).at(j) != 0) x.at(i).at(j) = max(x.at(i).at(j), x.at(i).at(j + 1));
    }
  }
  
  // 縦方向
  for(int j = 0; j < w; j++){
    for(int i = 1; i < h; i++){
      y.at(i).at(j) = y.at(i).at(j) * (y.at(i - 1).at(j) + 1);
    }
  }
  for(int j = 0; j < w; j++){
    for(int i = h - 2; i >= 0; i--){
      if(y.at(i).at(j) != 0) y.at(i).at(j) = max(y.at(i).at(j), y.at(i + 1).at(j));
    }
  }
  
  int ans = 0;
  for(int i = 0; i < h; i++){
    for(int j = 0; j < w; j++){
      ans = max(ans, x.at(i).at(j) + y.at(i).at(j));
    }
  }
  
  cout << ans - 1 << "\n";
}

Measured memory_bytes: 31616
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>

using namespace std;

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

	for (int i = 0; i < S.size(); i++)
	{
		S[i] -= '0';
	}


	int A = 0;
	int flip = 0;
	for (int i = 0; i < S.size(); i++)
	{
		if (S[i] != flip)
		{
			A++;
		}

		flip = 1 - flip;
	}

	int B = 0;
	flip = 1;
	for (int i = 0; i < S.size(); i++)
	{
		if (S[i] != flip)
		{
			B++;
		}

		flip = 1 - flip;
	}

	cout << min(A, B) << endl;

	return 0;
}

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

#define _overload3(_1, _2, _3, name, ...) name
#define repi(i, a, b) for(int i = int(a); i < int(b); i++)
#define rep(i, n) repi(i, 0, n)
#define REP(...) _overload3(__VA_ARGS__, repi, _rep,)(__VA_ARGS__)

typedef long long int ll;
typedef unsigned long long int ull;

const int MOD=(int)1e9+7;
const string alp = "abcdefghijklmnopqrstuvwxyz";
const string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
//int dx[4] = {0,1,0,-1}, dy[4] = {-1,0,1,0};

ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll g=gcd(a,b);return a/g*b;}
ll digitsum(ll a){ll x=0;while(a>0){x+=a%10;a/=10;}return x;}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int a,b,c,ans=0;
    cin>>a>>b>>c;
    while(true){
        if(ans==c){
            cout<<ans<<endl;
            return 0;
        }
        if(b-a>=0)ans++;
        else{
            cout<<ans<<endl;
            return 0;
        }
        b=b-a;
    }
}

Measured memory_bytes: 256
from collections import Counter


P = 10 ** 9 + 7

N = int(input())
numbers = [int(x) for x in input().split()]

def solve():
  counter = Counter(numbers)
  
  if N % 2 == 0:
    if all([counter[i] == 2 for i in range(1, N, 2)]):
      return (2 ** (N // 2)) % P
    else:
      return 0
  else:
    if all([counter[i] == 2 for i in range(2, N, 2)]) and counter[0] == 1:
      return (2 ** (N // 2)) % P
    else:
      return 0
    
print(solve())    

Measured memory_bytes: 57836
import sys
def S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())

n,p = MI()
a = LI()
cnt = 0
for i in range(n):
    if a[i]%2 == 1:
        cnt += 1
if cnt%2 == 1:
    print(2**(n-1))
elif cnt == 0:
    if p == 1:
        print(0)
    else:
        print(2**n)
else:
    print(2**(n-1))


Measured memory_bytes: 3064
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
#define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr)
#define P pair<int,int>
const ll MOD=1e9+7;
const int MAX=1e5+10;
const ll INF=1e18;
const double PI=acos(-1);


int main() {
    ios_base::sync_with_stdio(false);

    int x;
    cin >> x;
    cout << 1-x << endl;

    return 0; 
}


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

int main(){
    ll n,a,b;cin>>n>>a>>b;//a:歩きで隣町へ行くときの疲労　b:テレポートの疲労
    vector<ll> x(n);//町の座標
    for(ll i=0;i<n;i++){cin>>x[i];}
    
    ll ans=0;
    for(ll i=0;i<n-1;i++){
        if(a*(x[i+1]-x[i])>b){ans+=b;}
        else{ans+=a*(x[i+1]-x[i]);}
    }

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

Measured memory_bytes: 1024
let inputString = '';

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});
process.stdin.on('end', function() {
    inputString = inputString.replace(/\s*$/, '')
        .split('\n')
        .map(str => str.replace(/\s*$/, ''));

    proc(inputString[1].split(' ').map(str => Number(str)));
});

const proc = (nums) => {
  const index = partition(nums, 0, nums.length - 1);
  console.log(
    nums
      .map((num, i) => i === index ? `[${num}]` : String(num))
      .join(' ')
  );
};

const partition = (arr, p, r) => {
  const x = arr[r];
  let i = p - 1;
  for (let j=p; j<r; j++) {
    if (arr[j] <= x) {
      i = i + 1;
      const needToBeInLeft = arr[j];
      const needToBeInRight = arr[i];
      arr[i] = needToBeInLeft;
      arr[j] = needToBeInRight;
    }
  }
  const needToBeInRight = arr[r];
  const needToBeInLeft = arr[i + 1];
  arr[i+1] = needToBeInRight;
  arr[r] = needToBeInLeft;
  return i + 1;
};



Measured memory_bytes: 37736
def solve(N,X,M):
    if X == 0:
        return 0
    memo = [-1]*(M+3)
    acc = [0]*(M+4)
    x = X
    for i in range(M):
        if memo[x] >= 0:
            break
        acc[i+1] = acc[i]+x
        memo[x] = i
        x = (x*x)%M


    end = i
    start = memo[x]
    cycle = end - start

    if N < end:
        return acc[N]

    cycle_sum = acc[end]-acc[start]

    res = acc[start]

    N -= start
    res += (N//cycle)*cycle_sum
    res += acc[start+(N%cycle)]-acc[start]
    return res


N,X,M = map(int,input().split())
print(solve(N,X,M))


Measured memory_bytes: 13956
#coding:utf-8

def collatz(num):
    if num % 2 == 0:
        return (num//2)
    return (3*num + 1)

def main():
    s = int(input())
    a = set()


    while True:
        if s in a:
            print(len(a)+1)
            break
        a.add(s)
        s = collatz(s)


if __name__ == "__main__":
    main()

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

using namespace std;

typedef long long ll;
typedef long double ld;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;

#define pb push_back


int a[5];

int main() {
    int k;
    for (int i = 0; i < 5; i++) {
        cin >> a[i];
    }
    cin >> k;


    if (a[4] - a[0] > k) {
        cout << ":(" << endl;
        return 0;
    }

    cout << "Yay!" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int ans,x;
string s;
int main(){
    cin>>s;
    for(int i=0;i<s.size();i++){
        if(s[i]=='T')x++;
        else x--;
        ans=max(ans,x);
    }
    cout<<ans*2<<endl;
    return 0;
}

Measured memory_bytes: 640
// Problem : Replacing
// Contest : Virtual Judge - AtCoder
// URL : https://vjudge.net/problem/AtCoder-abc171_d
// Memory Limit : 1048 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#pragma GCC target("avx,avx2,fma")
//#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("Ofast")  // disable
using namespace std;
#define ll long long
#define ull unsigned long long
#define ld long double
#define lll __int128
#define lp(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define vec(v, type, sz) vector<type> v(sz)
#define in(v) \
    for (auto &i : v) cin >> i
#define all(v) v.begin(), v.end()
#define prv(v)                         \
    for (auto i : v) cout << i << " "; \
    cout << "\n"
#define MOD 1000000007
#define INF 1000000000
#define INFL 1000000000000000000ll
#define fast_io                       \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define vi vector<int>
#define vl vector<ll>
#define vii(v, n, m, val) vector<vector<int>> v(n, vector<int>(m, val))
#define viii(v, i, j, k, val)        \
    vector<vector<vector<int>>> v(i, \
                                  vector<vector<int>>(j, vector<int>(k, val)))
#define pii pair<int, int>
#define pb push_back
#define file_io                       \
    freopen("input.txt", "r", stdin); \
    freopen("output.txt", "w", stdout);
#define testcases \
    int tcc;      \
    cin >> tcc;   \
    for (int tc = 1; tc <= tcc; tc++)
vector<string> vec_splitter(string s) {
    s += ',';
    vector<string> res;
    while (!s.empty()) {
        res.push_back(s.substr(0, s.find(',')));
        s = s.substr(s.find(',') + 1);
    }
    return res;
}
void debug_out(vector<string> __attribute__((unused)) args,
               __attribute__((unused)) int idx,
               __attribute__((unused)) int LINE_NUM) {
    cerr << endl;
}
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
    if (idx > 0)
        cerr << ", ";
    else
        cerr << "Line(" << LINE_NUM << ") ";
    stringstream ss;
    ss << H;
    cerr << args[idx] << " = " << ss.str();
    debug_out(args, idx + 1, LINE_NUM, T...);
}
#ifdef DB
#define debug(...) \
    debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 42
#endif

int main() {
    fast_io;
    int n;
    cin >> n;
    map<int, int> mp;
    ll sum = 0;
    lp(i, 0, n) {
        int t;
        cin >> t;
        mp[t]++;
        sum += t;
    }
    int q;
    cin >> q;
    while (q--) {
        int b, c;
        cin >> b >> c;
        sum -= (ll)b * mp[b];
        mp[c] += mp[b];
        sum += (ll)c * mp[b];
        mp[b] = 0;
        cout << sum << "\n";
    }
}

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

int main() {
  int N, M, X, Y;
  cin >> N >> M >> X >> Y;

  int x[N], y[M];
  for ( int i = 0; i < N; i++ ){
    cin >> x[i];
  }
  for ( int j = 0; j < M; j++ ){
    cin >> y[j];
  }

  int xmax = -100;
  for ( int i = 0; i < N; i++ ){
    if ( xmax < x[i] ){
      xmax = x[i];
    }
  }

  int ymin = 100;
  for ( int j = 0; j < M; j++ ){
    if ( ymin > y[j] ){
      ymin = y[j];
    }
  }
  
  if ( xmax < X ){
    xmax = X;
  }
  if ( ymin > Y ){
    ymin = Y;
  }
  
  if ( xmax < ymin ) {
    cout << "No War" << endl;
  }
  else {
    cout << "War" << endl;
  }
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

long long fan(long long x,long long n)
{
    long long ans;
    if(n%x==0)
    {
        return n*2-x;
	}
    ans=n/x*x*2+fan(n%x,x);
    return ans;
}

int main()
{
    long long n,x;
    long long ans;
    cin>>n>>x;
    ans=fan(x,n-x)+n;
    cout<<ans<<endl;
    return 0;
}

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

int main() {
  int N;
  cin>> N;
  if((N-3)%10==0){
    cout<<"bon"<<endl;
  }
  else if(N%10==0||(N-1)%10==0||(N-6)%10==0||(N-8)%10==0){
    cout<<"pon"<<endl;
  }
  else{
  cout << "hon"<< endl;
  }
}


Measured memory_bytes: 3624
#include "bits/stdc++.h"
using namespace std;

int main() {
	string s;
	cin >> s;
	int state = 0;
	for (int i = 0; i < s.size(); i++) {
		if (state == 0) {
			if (s[i] == 'C') state++;
		}
		else if (state == 1) {
			if (s[i] == 'F') state++;
		}
	}
	if (state == 2) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256
//AtCoder AGC024
#include <bits/stdc++.h>
using namespace std;
using ll=int64_t;
int main() {
    ll a,b,c,k; cin>>a>>b>>c>>k;
    ll ans=(k%2==1)?b-a:a-b;
    cout<<ans<<endl;    
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>
#include<complex>

using namespace std;

#define ll long long
#define ld long double
#define EPS 1e-9
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

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

int gcd(int a, int b){if(b==0) return a;return gcd(b,a%b);}
int lcm(int a, int b){return a/gcd(a,b)*b;}

int ncr[2005][2005];

void calc(){
  rep(i,2005){
    ncr[i][0] = 1;
    ncr[i][i] = 1;
  }
  loop(i,1,2005)loop(j,1,i){
    ncr[i][j] = (ncr[i-1][j-1] + ncr[i-1][j])%MOD;
  }
}

signed main(void) {
    int n,k;
    cin >> n >> k;
    calc();
    loop(i,1,k+1){
      	if(i == 1 && n == k){
          cout << 1 << endl;
          continue;
        }
        int ans = 0;
        if(n-k-1 >= 0){
            ans += ncr[n-k-1][i-1]*2;
            if(i-2 >= 0)ans += ncr[n-k-1][i-2];
            ans += ncr[n-k-1][i];
        }
        ans %= MOD;
        ans = (ans*ncr[k-1][i-1])%MOD;
        cout << ans << endl;
    }
}


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

#define mod 1000000007
typedef int integer;
#define int long long
using namespace std;

const int N = 100005;


integer main(){
    ios_base::sync_with_stdio(false);

    int a, b, c;
    cin >> a >> b >> c;
    cout << (int) ceil(1.0 * c / max(a, b)) << endl;

}


Measured memory_bytes: 256
import itertools as it
import collections as col
import heapq as hq
import sys
import copy as cp
sys.setrecursionlimit(10**9)
args = sys.argv
input = sys.stdin.readline


def dump(*objects):
    if len(args) == 2 and args[1] == "DEBUG":
        print(*objects, file=sys.stderr)


N = int(input())
A = [0] + list(map(int, input().split())) + [0]
dump(N, A)
B = cp.deepcopy(A)
C = cp.deepcopy(A)
for i in range(1, len(A)):
    dump(i)
    B[i] = B[i - 1] + abs(A[i] - A[i - 1])
for i in range(len(A) - 2, -1, -1):
    dump(i)
    C[i] = C[i+1] + abs(A[i]-A[i+1])
dump(A, B, C)
for i in range(1, N+1):
    dump(i, B[i-1] + B[N+1] - B[i+1] + abs(A[i-1]-A[i+1]))
    print(B[i-1] + C[i+1] + abs(A[i-1]-A[i+1]))

exit(0)


Measured memory_bytes: 66848
import sys
from collections import Counter

N = int(input())
A = list(map(int, sys.stdin.readline().rsplit()))

C = Counter(A)

cnt2 = 0
res = 0
for v in C.values():
    if v == 2:
        cnt2 += 1
    elif v > 2 and v % 2 == 0:
        cnt2 += 1
        res += (v - 2) // 2
    elif v > 2 and v % 2 == 1:
        res += (v - 1) // 2

res += (cnt2 + 1) // 2

print(N - 2 * res)


Measured memory_bytes: 22076
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <algorithm>
#include <bitset>
#include <complex>

#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#define rep(i,n) for(int i=0;i<(n); i++)

using namespace std;
typedef long long ll;
const int MAX_N = 110;
const int MAX_V = 100100;
const ll INF = 1LL<<62;

ll dp[MAX_N][MAX_V];
int main(){
cin.tie(0);
ios::sync_with_stdio(0); //この2行はより速度を向上させる
// 追加２, 以降 cin の入力元が 'input.txt' になる


int N,W;
cin >> N >> W;

vector<ll> w(N),v(N);
rep(i,N) cin >> w[i] >> v[i];

rep(i,MAX_N){
    rep(j,MAX_V){
        dp[i][j]=INF;
    }
}
dp[0][0] = 0;
rep(i,N){
    rep(j,MAX_V){
        if(j-v[i] >= 0){
            dp[i+1][j] = min(dp[i+1][j], dp[i][j-v[i]]+w[i]);
        }
        dp[i+1][j] = min(dp[i+1][j],dp[i][j]);
    }
}
ll ans = 0;
rep(i,MAX_V){
    if(dp[N][i] <= W){
        ans = i;
    }
}
cout << ans << endl;

return 0;
}

Measured memory_bytes: 86400
import java.io.*;

public class Main {
  public static void main(String[] args) {
    try {
      BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
      int count = Integer.parseInt(in.readLine());
      int[] iArr = new int[count];
      String[] sArr = in.readLine().split(" ");
      for(int i=0; i<sArr.length; i++) {
        iArr[i] = Integer.parseInt(sArr[i]);
      }
      int swapCount = 0;
      for(int i = 0; i < iArr.length; i++) {
        int minj = i;
        for(int j = i; j < iArr.length; j++) {
          if(iArr[j] < iArr[minj]) { minj = j; }
        }
        if(minj != i) {
          int tmp = iArr[minj];
          iArr[minj] = iArr[i];
          iArr[i] = tmp;
          swapCount++;
        }
      }
      StringBuilder sb = new StringBuilder();
      for(int i : iArr){
        sb.append(i).append(" ");
      }
      System.out.println(sb.toString().trim());
      System.out.println(swapCount);
    } catch (IOException e) {}
  }
}

Measured memory_bytes: 24392
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoderCs
{

    class Program
    {

        const int Mod = 1000000007;

        static void Main()
        {

            var num = int.Parse(Console.ReadLine());
            const int alphabets = 'z' - 'a' + 1;
            const int alphabetsPlus = alphabets + 1;
            const int based = 'a' - 1;

            var lists = new List<string>[alphabets, alphabetsPlus, alphabetsPlus];
            for(int i = 0, j, k; i < alphabets; i++)
                for (j = 0; j < alphabetsPlus; j++)
                    for (k = 0; k < alphabetsPlus; k++)
                        lists[i, j, k] = new List<string>();

            for (int i = 0; i < num; i++)
            {

                var str = Console.ReadLine();
                var gen2 = (str.Length < 2 ? 0 : str[1] - based);
                var gen3 = (str.Length < 3 ? 0 : str[2] - based);
                if (!lists[str[0] - 'a', gen2, gen3].Any(x => x == str)) lists[str[0] - 'a', gen2, gen3].Add(str);

            }

            int result = 0;
            for (int i = 0, j, k; i < alphabets; i++)
                for (j = 0; j < alphabetsPlus; j++)
                    for (k = 0; k < alphabetsPlus; k++) result += lists[i, j, k].Count;

            Console.WriteLine(result);

        }


    }
}


Measured memory_bytes: 50572
from math import factorial as fact
import math
import sys
import itertools
import numpy as np
from collections import Counter
import datetime
from collections import deque


#入力:N(int:整数)
def input1():
	return int(input())

#入力:N,M(int:整数)
def input2():
	return map(int,input().split())

#入力:[n1,n2,...nk](int:整数配列)
def input_array():
	return list(map(int,input().split()))

def keta(N):
	return len(str(N))


def input_daytime(input_time):
	time,distance=input_time.split()
	t=time.split(":")
	se=str(t[-1]).split(".")
	dt1 = datetime.timedelta(hours=int(t[0]),minutes=int(t[1]),seconds=int(se[0]),milliseconds=int(se[1]))
	return dt1

def combinations(n,r):
	return list(itertools.combinations(range(n),r))



def all_sets(num_list):
	subsets=[]
	for i in range(2,len(num_list) + 1):
		for c in combinations(num_list, i):
			subsets.append(c) 
	return subsets

#公約数の列挙
def ch(x1):
	cf=[]
	for i in range(2,math.sqrt(x1)+1):
		if x1 % i==0:
			cf.append(i)
	return cf

def CountOneRoots(x,y):
	#x:縦，y:横
	return fact(x+y)/fact(x)/fact(y)

# 素因数分解
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a
	
def count_str(m):
	tmp={}
	for i in range(10):
		if i in tmp:
			tmp[i]=1
		else:
			tmp[i]+=1
	return tmp

def is_prime(n):
	if n==1: return True

	for i in range(2,int(math.sqrt(n))+1):
		if n%i==0:
			return False
	return True


n=int(input())
A=[]
for _ in range(n):
	A.append(input1())
B=sorted(A)
max_1=B[-1]
max_2=B[-2]

for i in A:
	if i==max_1:
		print(max_2)
	else:
		print(max_1)






Measured memory_bytes: 23248
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define fi first
#define se second
#define int long long
//template

//main
signed main(){
  int A,B,C;cin>>A>>B>>C;
  Cout(min(B/A,C));
}


Measured memory_bytes: 256
#include <iostream>
//#include <iomanip>
//#include <string>
//#include <vector>
#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <bitset>
//#include <math.h>
using namespace std ;
//using ll = long long ;
//using ld = long double ;
//using vll = vector<ll> ;
//using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;

//ll mod = 1000000007 ;
//long double pie = acos(-1) ;

//string yorn(bool a){if(a) return"Yes" ; return "No" ;}
//string YorN(bool a){if(a) return"YES" ; return "NO" ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void mysort(vector<long long> &a){sort(a.begin(),a.end()) ;}
//void myrev(vector<long long> &a){reverse(a.begin(),a.end()) ;}

int main(){
	int a,b,c ;
	cin >> a >> b >> c ;
	cout << b+min(a+b+1,c) << endl ;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for(ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
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;
}

void print(const std::vector<int> &v) {
    std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
    std::cout << std::endl;
}

int main() {
    vector<vector<char>> c(2, vector<char>(3));
    REP(i, 2) {
        REP(j, 3) { cin >> c[i][j]; }
    }
    if(c[0][0] != c[1][2]) {
        cout << "NO" << endl;
        return 0;
    }
    if(c[0][1] != c[1][1]) {
        cout << "NO" << endl;
        return 0;
    }
    if(c[0][2] != c[1][0]) {
        cout << "NO" << endl;
        return 0;
    }
    cout << "YES" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <numeric>
#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;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)




int main() {
	long long N,K;
	cin >> N >>K;
	long long ans = 0;
	for(int i =K;i<N+2;i++){
		ans += (N - i + 1) * i+1;
		ans = ans % 1000000007;
	}
	cout << ans << endl;
}



Measured memory_bytes: 3632
#include <iostream>
using namespace std;
int main(void){
   int n,x,a,i,j,k;
   while(1){
   cin>>n>>x;
   if(n==0&&x==0){break;}
   a=0;
   for(i=1;i<=n-2;i++){
     
   for(j=i+1;j<=n-1;j++){
       for(k=j+1;k<=n;k++){
           if(x==i+j+k){a++;}
           
       }
   }
   
   }
   cout<<a<<endl;
}   return 0;

}


Measured memory_bytes: 3080
#include <iostream>

using namespace std;

int main()
{
    int i, j, N, p[100], temp, ans;

    while(cin >> N){
        for(i=0;i<N;++i){
            cin >> p[i];
        }
        for(i=0;i<N;++i){
            for(j=i+1;j<N;++j){
                if(p[i]>p[j]){
                    temp = p[i];
                    p[i] = p[j];
                    p[j] = temp;
                }
            }
        }

        ans = 0;

        for(i=0;i<N;++i){
            ans += (N-i)*p[i];
        }
        cout<< ans << endl;
    }

    return 0;
}

Measured memory_bytes: 1160
#include <cstdio>
#include <algorithm>
#include <set>
using namespace std;
int main() {
    int N, A;
	scanf("%d", &N);
	set<int> s;
	for (int i = 0; i < N; ++i) {
		scanf("%d", &A);
		s.insert(A);
	}
	if (s.size() == N) printf("YES");
	else printf("NO");
	return 0;
}

Measured memory_bytes: 9600
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<map>
#include <algorithm>
#include<cstdlib>
#include<cmath>
#include<deque>
#include <numeric>
typedef unsigned long long ull;
typedef  long long ll;

int main() {
	ll n, m;
	std::cin >> n >> m;

	std::vector< ll > A;
	A.resize(m);

	for (int i = 0; i < n; i++)
	{
		ll k;
		std::cin >> k;
		std::vector<ll> tmpa;
		tmpa.resize(k);
		for (int j = 0; j < k; j++)
		{
			std::cin >> tmpa[j];
			A[tmpa[j] - 1] += 1;
		}
	}

	ll sum = 0;
	for (int i = 0; i < m; i++)
	{
		if (A[i] == n) {
			sum += 1;
		}
	}
	std::cout << sum << std::endl;
	return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
def main():
    X = int(input())
    ans = [0] * 2

    for A in range(-1000, 1000):
        for B in range(-1000, 1000):
            if pow(A, 5) - pow(B, 5) == X:
                ans[0], ans[1] = A, B
                break
            if pow(A, 5) - pow(-B, 5) == X:
                ans[0], ans[1] = A, -B
                break
            if pow(-A, 5) - pow(B, 5) == X:
                ans[0], ans[1] = -A, B
                break
            if pow(-A, 5) - pow(-B, 5) == X:
                ans[0], ans[1] = -A, -B
                break
    print(ans[0], ans[1])
if __name__ == "__main__":
    main()

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

#define int long long

int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

string s;

signed main() {
    cin >> s;
    int ans = 0;
    int N = s.length();
    for (int i = 0; i < N / 2; i++) {
        if (s[i] == 'g') {
            ans++;
        }
    }
    for (int i = N / 2; i < N; i++) {
        if (s[i] == 'p') {
            ans--;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 512
#C
n,k,q = map(int,input().split())
a = [int(input()) for _ in range(q)]

p = [k for _ in range(n)]

for i in range(q):
    p[a[i]-1] += 1
    
for j in range(n):
    p[j] -= q
    
for k in range(n):
    if p[k] > 0:
        print('Yes')
    else:
        print('No')

Measured memory_bytes: 11788
def main():
    L, R = map(int, input().split())
    # 60 の相異なる素因数は 3, 673 の 2つ
    if L + 672 <= R:
        print(0)
        return
    for i in range(L, R + 1):
        for j in range(i + 1, R + 1):
            if i * j % 2019 == 0:
                print(0)
                return
    print(min(i * j % 2019 for i in range(L, R + 1)
              for j in range(i + 1, R + 1)))
    return


main()


Measured memory_bytes: 3060
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/tag_and_trait.hpp>
#define BEGIN ios_base::sync_with_stdio(0);cin.tie(0)
#define END return EXIT_SUCCESS
#define FOR(I,A,B) for((I)=(A);(I)<(B);(I)++)
#define REP(I,N) FOR(I,0,N)
#define UP(I,A,B) for((I)=(A);(I)<=(B);(I)++)
#define DW(I,A,B) for((I)=(A);(I)>=(B);(I)--)
#define IN(P) std::cin>>(P)
#define IN2(P1,P2) std::cin>>(P1)>>(P2)
#define IN3(P1,P2,P3) std::cin>>(P1)>>(P2)>>(P3)
#define INS(I,N,V) REP(I,N) std::cin>>V[I]
#define OUT(P) std::cout<<P<<std::endl
#define OUT2(P1,P2) std::cout<<P1<<" "<<P2<<std::endl
#define OUT3(P1,P2,P3) std::cout<<P1<<" "<<P2<<" "<<P3<<std::endl
#define OUTS(I,N,V) REP(I,N) std::cout<<V[i]<<std::endl
#define ALL(C) (C).begin(),(C).end()
using namespace std;
using namespace __gnu_pbds;
typedef unsigned long ul;
int H,W,i,j,k,nx,ny;
vector<string> S(51);
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
bool flag;
inline void solve(){
  IN2(H,W);
  INS(i,H,S);
  REP(i,W){
    REP(j,H){
      if(S[i][j]=='#'){
        flag=false;
        REP(k,4){
          nx=i+dx[k];
          ny=j+dy[k];
          if(nx>=0&&nx<W&&ny>=0&&ny<H&&S[nx][ny]=='#'){
            flag=true;
            break;
          }
        }
        if(!flag){
          OUT("No");
          return;
        }
      }
    }
  }
  OUT("Yes");
}

int main(int argc,char**argv){
  BEGIN;
  solve();
  END;
}


Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("filed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n:usize = read();
    let k:usize = read();
    let arr:Vec<usize> = (0..n).map(|_| read()).collect();
    let mut x = 1;
    let mut ans = 0;
    loop {
        x += k-1;
        ans += 1;
        if x >= n {
            break;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 2772
// Created by sz
#include <bits/stdc++.h>
using namespace std;

const int N = 1e5 + 5;
int n, q,k;
long long dp[N];

vector<pair<int, int> > g[N];


void dfs(int u, int pre, int d){
    
    for (auto i: g[u]){
        if(i.first == pre)continue;
        dp[i.first] = dp[u] + i.second;
        dfs(i.first, u, dp[i.first]);
    }
}


int main(){
#ifdef LOCAL
    freopen("./input.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    cin>>n;
    
    int u,v,c;
    for (int i = 0; i < n-1; i++){
        cin>>u>>v>>c;
        g[u].push_back({v,c});
        g[v].push_back({u, c});
    }
    
    cin>>q>>k;
    
    dfs(k, -1, 0);
    
    int x,y;
    for (int i = 0; i < q; i++){
        cin>>x>>y;
        cout<<dp[x]+dp[y]<<endl;
    }
    
    
    
    
    return 0;
}



Measured memory_bytes: 12800
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():
    s = S()
    ans = not(len(set(list(s)))==1)
    print("Yes" if ans else "No")
main()            


Measured memory_bytes: 74480