akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std; 
using lint =                            long long int;
using plint =                           pair<lint, lint>;
#define vli                             vector<lint>
#define pb                              push_back
#define ALL(x)                          begin(x),end(x)
#define inf                             (1LL<63)-1
#define MOD 1000000007
#define SZ(x)                           ((lint)(x).size())
#define                                 FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define                                 IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define                                 REP(i, n) FOR(i,0,n)
#define                                 IREP(i, n) IFOR(i,0,n)
#define                                 f_ip   ios_base::sync_with_stdio(false); cin.tie(NULL);
#define                                 debug(x) cerr << #x << " " << (x) << endl
struct fast_ios                         { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
template<typename T>                    istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T>                    bool mmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T>                    bool mmin(T &m, const T q) { if (q < m) {m = q; return true;} else return false; }


/* -------
         |
    **   |
   -------      
   |
   ---------------------------------------------------------------------------------------------------------------------------------*/

void solve(){  
    lint A;
    cin>>A;
    lint B;
    cin>>B;
    lint K;
    cin>>K;
    if(K<=A){
        cout<< max(0LL,A-K)<<" "<<B<<endl;
    }else
    {
        cout<< 0 << " " << max(0LL,B-(K-A)) << endl;
    }
    
}

int main(){   
  
 solve();

 return 0;
}


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

using namespace std;
using ll = long long;
int arr[100005];
ll pre[100005];

int main() {
#ifndef ONLINE_JUDGE
    //freopen("input.txt", "r", stdin);
#endif

    int n, k;
    scanf("%d%d", &n, &k);
    int b = 0, res = 1;
    for(int i=1; i<=n; i++){
        int cur;
        scanf("%d", &cur);
        b += cur;

        res += b <= k;
    }
    printf("%d\n", res);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, q;
  cin >> n >> q;
  string s;
  cin >> s;
  vector<int> cnt(n+1, 0);
  for(int i = 0; i < n-1; i++)
    if(s[i] == 'A' && s[i+1] == 'C')
      cnt[i+2] = 1;
  for(int i = 1; i <= n; i++)
    cnt[i] += cnt[i-1];
  for(int i = 0; i < q; i++){
    int l, r;
    cin >> l >> r;
    cout << cnt[r] - cnt[l] << endl;
  }
  return 0;
}

Measured memory_bytes: 1488
from collections import defaultdict

def dfs(i, c):
    key = (i, c)
    if key in memo:
        return memo[key]
    if c == 75:
        return 1
    if i == m:
        return 0
    k, v = p[i]
    r = 0
    for j in range(v + 1):
        if c * (j + 1) <= 75:
            r += dfs(i + 1, c * (j + 1))
    memo[key] = r
    return r

n = int(input())
index = defaultdict(int)

for x in range(2, n + 1):
    y = 2
    while y ** 2 <= x:
        while x % y == 0:
            x //= y
            index[y] += 1
        y += 1
    if x > 1:
        index[x] += 1

*p, = index.items()
m = len(p)
memo = {}

print(dfs(0, 1))


Measured memory_bytes: 3572
#include<bits/stdc++.h>
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define repr(i,n) for(int i=n;i>=0;i--)
#define For(i,m,n) for(int i=m;i<n;i++)
#define Forr(i,m,n) for(int i=m;i>n;i--)
#define Sort(a) sort(a.begin(),a.end())
#define pb push_back
#define vl vector<ll>
#define vll vector<vector<ll>>
#define INF 999999999

int main(){
  int N,count=0,breakcount=0;
  cin>>N;
  rep(i,9){
    rep(j,9){
      if((i+1)*(j+1)==N){
        cout<<"Yes"<<endl;
        breakcount++;
      }else count++;
    }
    if(breakcount==1) break;
  }
  if(count==81) cout<<"No"<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int A[2000001],B[2000001],C[10001];

int main(){
  
  int n,i,k=0;
  
  scanf("%d",&n);
  
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
    if(k<A[i])k=A[i];
  }

  for(i=0;i<k+1;i++){
    C[i]==0;
  }

  for(i=0;i<n;i++){
    C[A[i]]++;
  }

  for(i=0;i<k+1;i++){
    C[i]=C[i]+C[i-1];
  }

  for(i=n-1;i>=0;i--){
    B[C[A[i]]]=A[i];
    C[A[i]]--;
  }

  for(i=1;i<=n;i++){
    printf("%d",B[i]);
    if(i!=n)printf(" ");
  }

  printf("\n");

  return 0;
}



Measured memory_bytes: 17380
/*
h s, d't skp th si tll i's sved
 * ABC141 E
 * ABC145 D
 * ABC147 F
*/
#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007
using namespace std;
int main()
{
int n;
cin>>n;
string s;
cin>>s;
int cnt=0;
int ans=0;
for(int i=0;i<n;i++)
{
if(s[i]=='R')
{
cnt++;
}
}
for(int i=0;i<cnt;i++)
{
if(s[i]=='W')
{
ans++;
}
}
cout<<ans<<endl;
}




/*
 * ||||


 */

Measured memory_bytes: 3744
import sys
input = sys.stdin.readline
import numpy as np

"""
ax + by + c という距離をたくさん作れる
全ての(a,b)に対して作るとしてよい（cを大きくすれば無視できるので）
悪さをしない範囲の最小のcを選ぶ
それで上手くいっているかを検証
"""

U = 100
A,B = map(int,input().split())
D = np.array([input().rstrip().split() for _ in range(A)], dtype=np.int64)

ax = np.arange(U+1)[:,None] * np.arange(1,A+1)[None,:] # (U+1, A)
by = np.arange(U+1)[:,None] * np.arange(1,B+1)[None,:] # (U+1, B)
axby = ax[:,:,None,None] + by[None,None,:,:] # (U+1,A,U+1,B)

c = (D[None,:,None,:] - axby).max(axis = 3).max(axis = 1) # (U+1,U+1)
c *= (c > 0)

D2 = (axby + c[:,None,:,None]).min(axis = 2).min(axis = 0) # (A,B)

if (D != D2).any():
    print('Impossible')
    exit()

# ax + by + c[a,b] という1次式が距離になるようなグラフを作成

graph = []
for a in range(U+1):
    for b in range(U+1):
        graph.append((1+a, (U+2) + b, c[a,b]))
for a in range(U):
    graph.append((a+1,a+2,'X'))
for b in range(U,0,-1):
    graph.append((U+2+b,U+1+b,'Y'))

start = 1
goal = U+2

print('Possible')
print(2*(U+1), len(graph))
for e in graph:
    print(*e)
print(start,goal)





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

int main() {
  string S;
  cin >> S;
  long long Q;
  cin >> Q;
  bool reverse_ = false;
  string before = "", after = "";
  for (int i = 0; i < Q; i++){
    long long T;
    cin >> T;
    if (T == 1){
      if (reverse_ == false) reverse_ = true;
      else reverse_ = false;
    }
    else {
      long long F;
      cin >> F;
      string C;
      cin >> C;
      if (reverse_ == false && F == 1) before += C;
      if (reverse_ == true && F == 1) after += C;
      if (reverse_ == false && F == 2) after += C;
      if (reverse_ == true && F == 2) before += C;
    }
  }
  reverse(before.begin(), before.end());
  S = before + S + after;
  if (reverse_ == true) reverse(S.begin(), S.end());
  cout << S << endl;
}

Measured memory_bytes: 4316
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s[3];
    cin>>s[0]>>s[1]>>s[2];
    int turn=0;
    int p[]={0,0,0};
    while(!(p[turn]==s[turn].size())){
        p[turn]++;
        turn=s[turn].at(p[turn]-1)-'a';
    }
    cout<<(char)('A'+turn);
}




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

using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define MIN(a,b) ((a)>(b)? (b): (a))
#define MAX(a,b) ((a)<(b)? (b): (a))

const long long INF = 1LL << 60;

typedef unsigned long long ll;

const long long MOD = 1000000000 + 7;

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

int main(){
    string s;
    cin >> s ;
    queue<string> que;
    que.push(s);
    while(!que.empty()){
        string ns = que.front();
        que.pop();
        string ts = ns.substr(0,5);
        if(ts == "dream" || ts == "erase"){
            ts = ns;
            ts.erase(0,5);
            if(ts.size() == 0)  {
                cout << "YES" << endl;
                return 0;
            }
            que.push(ts);
        }
        ts = ns.substr(0,6);
        if(ts == "eraser"){
            ts = ns;
            ts.erase(0,6);
            if(ts.size() == 0)  {
                cout << "YES" << endl;
                return 0;
            }
            que.push(ts);
        }
        ts = ns.substr(0,7);
        if(ts == "dreamer"){
            ts = ns;
            ts.erase(0,7);
            if(ts.size() == 0)  {
                cout << "YES" << endl;
                return 0;
            }
            que.push(ts);
        }
    }
    cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 820
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>

using namespace std;


int main(){
  int n,le,ri,mi,st,ed;
  string s;
  while(cin >> n && n){
    int L,D,M,okL,okD,okM;
    L=D=M=okL=okD=okM=0;
    st = 0;
    cin.ignore();
    for(int i=0;i<n;i++){
      getline(cin,s,'\n');
      st = s[0]=='0'?1:0;
      le = (atoi)(s.substr(st,st==0?2:1).c_str());
      st = s[3] == '0'?4:3;
      ri = (atoi)(s.substr(st,st==3?2:1).c_str());
      st = s[6]=='0'?7:6;
      mi = (atoi)(s.substr(st,st==6?2:1).c_str());
      //cout << le << " " << ri << " " << mi << endl; 
      int time = le*60+ri;
      if(660 <= time && time<=899){
	L++;
	if(ri <= mi){
	  if(mi-ri <= 8)okL++;
	}
	else{
	  if(60-ri+mi <= 8)okL++;
	}
      }
      else if(1080<=time &&time <=1259){
	D++;
	if(ri <= mi){
	  if(mi-ri <= 8)okD++;
	}
	else{
	  if(60-ri+mi <= 8)okD++;
	}

      }else if((1260<=time && time<=1439) || (0<=time && time<= 119) ){
	M++;
	if(ri <= mi){
	  if(mi-ri <= 8)okM++;
	}
	else{
	  if(60-ri+mi <= 8)okM++;
	}
      }
    }
   
    cout << "lunch ";
    L==0?cout <<"no guest"<<endl:cout <<(int)(((double)okL/(double)L)*100) << endl;
    cout << "dinner ";
    D==0?cout << "no guest"<<endl:cout << (int)(((double)okD/(double)D)*100) << endl;
    cout << "midnight ";
    M==0?cout <<"no guest" << endl:cout << (int)(((double)okM/(double)M)*100) << endl;

  }
  return 0;
}

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

int main(){
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  int ans = min({abs(a+b-c-d),abs(a-b+c-d),abs(a-b-c+d)});
  cout << ans << endl;
  return 0;
}



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

int main() {
  string s;
  cin >> s;
  char x;
  for(int i=0; i<s.size(); i++) {
    x = s[i];
    if(i % 2 == 0) {
      if(x == 'L'){
	cout << "No" << endl;
	return 0;
      }
    }
    if(i % 2 == 1) {
      if(x == 'R') {
	cout << "No" << endl;
	return 0;	
      }
    }
  }

  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 256
def insertationSort(A,n,g):
    global cnt
    for i in range(g,n):
        v=A[i]
        j=i-g
        while (j>=0 and A[j]>v):
            A[j+g]=A[j]
            j = j - g
            cnt += 1
        A[j+g] = v

def shellSort(A,n):
    global cnt
    cnt = 0
    g = []
    h = 1
    while h <= n:
        g.append(h)
        h = 3*h + 1
    g.reverse()
    m = len(g)
    print(m)
    print(' '.join(map(str,g)))
    for i in range(m):
        insertationSort(A,n,g[i])

N = int(input())
A = []
for i in range(N):
    A.append(int(input()))
shellSort(A,N)
print(cnt)
for e in A:
    print(e)



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

int main(void){
	int d, g;
	cin>>d>>g;
	int p[d+1], c[d+1];
	int tmp[d];
	for(int i=1; i<=d; i++){
		cin>>p[i]>>c[i];
		tmp[i-1] = i;
	}
	int ans = 1e9;
	do{
		int sum = 0, count = 0;
		for(int i=0; i<d; i++){
			int indx = tmp[i];
			int left = g-sum;
			if(p[indx]*100*indx + c[indx]<=left){
				sum+=p[indx]*100*indx + c[indx];
				count+=p[indx];
			}else{
				if(left > (p[indx]-1)*100*indx){
					sum+=p[indx]*100*indx + c[indx];
					count+=p[indx];
				}else{
					int val = ceil(left/(double)(100*indx));
					sum+=val*100*indx ;
					count+=val;
				}
			}
			if(sum>=g){
				break;
			}
		}
		ans = min(ans, count);
	}while(next_permutation(tmp, tmp+d));
	cout<<ans<<endl;
}

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

int n,k;
string st;

int main() {
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    cin >> n >> k;
    cin >> st;
    st[k-1]=tolower(st[k-1]);
    cout << st;
    return 0;
}


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

int main(){
    int N;
    int sum = 0;
    int x = INF;
    int s;
    cin >> N;
    for(int i=0; i<N; i++){
        cin >> s;
        sum += s;
        if(s%10 != 0 && s <= x){
            x = s;
        }
    }
    if(sum%10 != 0){
        cout << sum;
    }else{
        if(x != INF){
            cout << (sum-x);
        }else{
            cout << 0;
        }
    }
    return EXIT_SUCCESS;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//(a+b-1)/b

signed main(){
	int n; cin>>n;
	int ans=0;
	rep(i,1,n+1){
		int a; cin>>a;
		if(a%2==1 && i%2==1){
			ans++;
		}
	}
	cout<<ans<<endl;
	
	return 0;
}

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

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

    int sum = A + B + C;
    int maxv = max(A, max(B, C));

    if ((maxv * 3) % 2 == sum % 2) {
        cout << (maxv * 3 - sum) / 2 << endl;
    } else {
        cout << ((maxv + 1) * 3 - sum) / 2 << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define arep(i,x,n) for(int i=int(x);i<(int)(n);i++)
#define rep(i,n) for(long long i = 0;i < n;++i)
#define pi 3.141592653589793
#define eps 0.00000001
#define INF 1e9+7  
using ll = long long;
using P = pair<int, int>;
using lP = pair<ll, ll>;
using fP = pair<double, double>;

int dp[1005][10005];
int main() {
    int h, n;
    cin >> h >> n;
    vector<int>a(n), b(n);
    rep(i, n)cin >> a[i] >> b[i];
    rep(i, n)rep(j, 10005) {
        dp[i][j] = INF;
    }
    dp[0][0] = 0;
    rep(i, n)rep(j, 10005) {
        if (j < a[i]) {
            dp[i + 1][j] = dp[i][j];
        }
        else {
            dp[i + 1][j] = min(dp[i][j], dp[i + 1][j - a[i]] + b[i]);

        }

    }
    int ans = INF;
    arep(i, h, 10001) {
        //if (dp[n][i] == 0)continue;
        ans = min(ans, dp[n][i]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 39424
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		String[] targets = new String[]{"dream", "dreamer", "erase", "eraser"};
		StringBuilder sb = new StringBuilder(sc.next());
		while (sb.length() > 0) {
			boolean flag = true;
			for (String t : targets) {
				int idx = sb.lastIndexOf(t);
				if (idx != -1 && idx == sb.length() - t.length()) {
					sb.setLength(sb.length() - t.length());
					flag = false;
					break;
				}
			}
			if (flag) {
				System.out.println("NO");
				return;
			}
		}
		System.out.println("YES");
	}
}


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

int main()
{
    string s,s1="es",s2="s";
    cin>>s;
    int n=s.length();
    if(s[n-1]=='s')
    s.append(s1);
    if(s[n-1]!='s')
    s.append(s2);
    
    cout<<s;

    return 0;
}


Measured memory_bytes: 3632
#include<stdio.h>
#define MAX  100000
#define SENTINEL 2000000000

typedef struct {
    char suit;
    int value;
}Card;

Card L[MAX/2+2],R[MAX/2+2];

void merge(Card A[],int n,int left,int mid,int right){
    int i,j,k;
    int n1=mid-left;
    int n2=right-mid;
    for(i=0;i<n1;i++)L[i]=A[left+i];
    for(i=0;i<n2;i++)R[i]=A[mid+i];
    L[n1].value=R[n2].value=SENTINEL;
    i=j=0;
    for(k=left;k<right;k++){
        if(L[i].value<=R[j].value){
            A[k]=L[i++];
        }else {
            A[k]=R[j++];
        }
    }
}

void mergeSort(Card A[],int n,int left, int right){
    int mid;
    if(left+1<right){
        mid=(left+right)/2;
        mergeSort(A, n, left, mid);
        mergeSort(A, n, mid, right);
        merge(A, n, left, mid, right);
        
    }
}

int partition(Card A[],int n,int p,int r){
    int i,j;
    Card t,x;
    x=A[r];
    i=p-1;
    for(j=p;j<r;j++){
        if(A[j].value<=x.value){
            i++;
            t=A[i];
            A[i]=A[j];
            A[j]=t;
        }
    }
    t=A[i+1];
    A[i+1]=A[r];
    A[r]=t;
    return i+1;
}


void quickSort(Card A[],int n,int p,int r){
    int q;
    if(p<r){
        q=partition(A, n, p, r);
        quickSort(A, n, p, q-1);
        quickSort(A, n, q+1, r);
    }
}

int main(){
    int n,i,v;
    Card A[MAX],B[MAX];
    char S[10];
    int stable = 1;
    
    scanf("%d",&n);
    
    for(i=0;i<n;i++){
        scanf("%s %d",S,&v);
        A[i].suit=B[i].suit=S[0];
        A[i].value=B[i].value=v;
    }
    
    mergeSort(A, n, 0, n);
    quickSort(B, n, 0, n-1);
    
    for(i=0;i<n;i++){
        if(A[i].suit!=B[i].suit) stable=0;
        
    }
    if(stable==1) printf("Stable\n");
    else printf("Not stable\n");
    for(i=0;i<n;i++){
        printf("%c %d\n",B[i].suit,B[i].value);
    }
    
    return 0;
}



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

#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define RFOR(i,b,a) for(int i = (b) - 1; i >= (a); i--)
#define ITER(it, a) for(typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a, value) memset(a, value, sizeof(a))

#define SZ(a) (int) a.size()
#define ALL(a) a.begin(),a.end()
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double PI = acos(-1.0);
const LL INF = 1000 * 1000 *1000 + 7;
const LL LINF = INF * (LL)INF;

const int MAX = 2020;
const int MOD = 1000 * 1000 * 1000 + 7;

LL DP[MAX][MAX];
LL F[MAX * MAX];
LL IF[MAX * MAX];

LL bpow(LL a, LL b)
{
	LL res = 1;
	while(b)
	{
		if (b & 1) res = (res * a) % MOD;
		a = (a * a) % MOD;
		b /= 2;
	}
	return res;
}

LL inv(LL a)
{
	return bpow(a, MOD - 2);
}

LL C(LL a, LL b)
{
	LL res = F[a];
	res *= IF[b];
	res %= MOD;
	res *= IF[a-b];
	res %= MOD;
	return res;
}

void ADD(LL& x, LL val)
{
	x += val;
	if (x >= MOD) x -= MOD;
}

int main()
{
	//freopen("in.txt","r", stdin);
	//ios::sync_with_stdio(false); cin.tie(0);

	F[0] = 1;
	IF[0] = 1;
	FOR (i, 1, MAX * MAX)
	{
		F[i] = (F[i-1] * i) % MOD;
		IF[i] = inv(F[i]);
	}


	int n, k;
	scanf("%d%d", &n, &k);

	if (k == 1)
	{
		cout<<1<<endl;
		return 0;
	}

	DP[0][0] = 1;
	FOR (i, 0, n + 1)
	{
		RFOR (j, n+1, 0)
		{
			if (DP[i][j] == 0) continue;

			ADD(DP[i+1][j+1], DP[i][j]);

			if (j)
			{
				int used = i + (i - j) * (k - 1);

				int left = n * k - used - 1;


				LL cnt = C(left, k - 2);
				int cols = n - (i - j);
				cnt *= cols;
				cnt %= MOD;
				cnt *= DP[i][j];
				cnt %= MOD;

				ADD(DP[i][j-1], cnt);
			}
		}
	}

/*	FOR (i, 0, n+1)
	{
		FOR (j, 0, n+1)
		{
			cout<<DP[i][j]<<' ';
		}
		cout<<endl;
	}
	cout<<endl;*/

	LL res = DP[n][0];
	cout<<res<<endl;
}


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


public class ARC54
{	
    public static bool[,] edge;
    public static bool[] node;
    public static int cnt = 0;
    public static bool ok = false;
	public static void Main()
	{
        string[] str = Console.ReadLine().Split(' ');
        int N = int.Parse(str[0]);
        int M = int.Parse(str[1]);
        int ans = 0;

        edge = new bool[N,N];
        node = new bool[N];
        int a,b;
        for(int i = 0 ; i < M ; i++)
        {
            str = Console.ReadLine().Split(' ');
            a = int.Parse(str[0]) -1;
            b = int.Parse(str[1]) -1;
            edge[a,b] = true;
            edge[b,a] = true;
        }
        
        node[0] = true;
        DFS(0,node);
        
        
        Console.WriteLine(cnt);
    }
    
    public static void DFS(int index, bool[] node)
    {
        ok = true;
        for(int i = 0 ; i < node.Length ; i ++)
        {
            if(!node[i]) ok = false;
        }
        // Console.WriteLine("index = " + index + " ok = " + ok);
        if(ok) cnt++;

        for(int i = 0 ; i < edge.GetLength(0) ; i++)
        {
            if(edge[index,i]) 
            {
                if(!node[i]){
                    node[i] = true;
                    DFS(i, node);
                    node[i] = false;
                }
            }
        }
    }
}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(), x.end()
#define x first
#define y second
#define mp make_pair
#define mt make_tuple

const int N = 1.1e5;
const int L = 18;
const int K = 100;

struct edge {
	int to;
	int col;
	int dst;
	edge(int a, int b, int c) : to(a), col(b), dst(c) {}
};

int n;
int q;
vector<edge> g[N];
vector<int> freq;
pair<int, int> pref[K][N];
int root[N];
int tl[N];
int tr[N];
int up[L][N];
pair<int, int> *ptr;
int timer;
vector<tuple<int, int, int>> edges[N];

void prefdfs(int v, int p) {
	for (edge e : g[v]) {
		if (e.to == p) {
			continue;
		}
		ptr[e.to].x = ptr[v].x + (e.col == timer ? e.dst : 0);
		ptr[e.to].y = ptr[v].y + (e.col == timer ? 1 : 0);
		prefdfs(e.to, v);
	}
}

void subdfs(int v, int p) {
	up[0][v] = p;
	for (int i = 1; i < L; ++i) {
		up[i][v] = up[i - 1][up[i - 1][v]];
	}
	tl[v] = timer++;
	for (edge e : g[v]) {
		if (e.to == p) {
			continue;
		}
		root[e.to] = root[v] + e.dst;
		subdfs(e.to, v);
	}
	tr[v] = timer++;
}

bool anc(int v, int u) {
	return tl[v] <= tl[u] && tr[u] <= tr[v];
}

bool onpath(int e1, int e2, int v, int u) {
	if (!anc(e1, e2)) {
		swap(e1, e2);
	}
	assert(anc(e1, e2));
	return anc(e2, v) != anc(e2, u);
}

int lca(int v, int u) {
	for (int k = L - 1; k >= 0; --k) {
		if (!anc(up[k][v], u)) {
			v = up[k][v];
		}
	}
	if (!anc(v, u)) {
		v = up[0][v];
	}
	assert(anc(v, u));
	return v;
}

pair<int, int> query(int v, int u, int c) {
	int ind = (int)(lower_bound(all(freq), c) - freq.begin());
	if (ind == (int)freq.size() || freq[ind] != c) {
		int x = 0;
		int y = 0;
		for (tuple<int, int, int> e : edges[c]) {
			if (onpath(get<0>(e), get<1>(e), v, u)) {
				x += get<2>(e);
				y += 1;
			}
		}
		return {x, y};
	} else {
		int l = lca(v, u);
		pair<int, int> *arr = pref[ind];
		int x = arr[v].x + arr[u].x - 2 * arr[l].x;
		int y = arr[v].y + arr[u].y - 2 * arr[l].y;
		return {x, y};
	}
}

signed main() {
#ifdef LC
	assert(freopen("input.txt", "r", stdin));
#endif
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n >> q;
	for (int a, b, c, d, i = 0; i < n - 1; ++i) {
		cin >> a >> b >> c >> d;
		--a;
		--b;
		g[a].emplace_back(b, c, d);
		g[b].emplace_back(a, c, d);
		edges[c].emplace_back(a, b, d);
	}
	vector<pair<int, int>> srt;
	for (int i = 1; i < n; ++i) {
		srt.emplace_back(edges[i].size(), i);
	}
	sort(all(srt));
	reverse(all(srt));
	for (int i = 0; i < min(K, (int)srt.size()); ++i) {
		freq.push_back(srt[i].y);
	}
	sort(all(freq));
	srt.clear();
	for (int i = 0; i < (int)freq.size(); ++i) {
		ptr = pref[i];
		timer = freq[i];
		prefdfs(0, 0);
	}
	timer = 0;
	subdfs(0, 0);

	for (int x, y, v, u; q--; ) {
		cin >> x >> y >> v >> u;
		--v;
		--u;
		int l = lca(v, u);
		int dist = root[v] + root[u] - 2 * root[l];
		pair<int, int> upds = query(v, u, x);
		dist += upds.y * y - upds.x;
		cout << dist << "\n";
	}
	return 0;
}


Measured memory_bytes: 110772
#include<iostream>
#include<string>
#include<map>
#include<algorithm>
using namespace std;
long long int edge[800][800];
int main(){
  int n,m;
  while(cin >>n>>m,n||m){
    map<string,int> name;
    string S,P,G;
    int all = 1;
    for(int i=0; i<800; i++) for(int j=0; j<800; j++) edge[i][j] = 1000000000;
    cin >>S>>P>>G;
    for(int i=0; i<m; i++){
      string a_name,b_name;
      int x,y,a,b;
      cin >>a_name>>b_name>>x>>y;
      if(name[a_name] == 0) name[a_name] = all++;
      if(name[b_name] == 0) name[b_name] = all++;
      a = name[a_name];
      b = name[b_name];
      edge[a][b] = edge[b][a] = x/40+y;
    }
    for(int k=0; k<all; k++){
      for(int i=0; i<all; i++){
	for(int j=0; j<all; j++){
	  edge[i][j] = min(edge[i][j],edge[i][k]+edge[k][j]);
	}
      }
    }
    cout <<edge[name[S]][name[P]]+edge[name[P]][name[G]]<<endl;
  }
  return 0;
}

Measured memory_bytes: 6268
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0; i< (n); ++i)

using namespace std;
using ll = long long;
using v1 = vector<int>;
using v2 = vector<vector<int>>;

int main(){
	int n;
	cin >> n;
	v1 a(n);
	for(auto& x: a){
		cin >> x;
	}
	v1 b(n, 0);
	int i = 0;
	int s = 0;
	while(1){
		if(b.at(i) == 1){
			cout << -1 << endl;
			return 0;
		}
		if(i == 1){
			cout << s << endl;
			return 0;
		}
		b.at(i) = 1;
		i = a.at(i)-1;
		s++;
	}
}


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

int main()
{
    int x, y;
    while (true) {
        scanf("%d %d", &x, &y);
        if (x == 0 and y == 0) break;
        if (x > y) swap(x, y);
        printf("%d %d\n", x, y);
    }
}



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

int main() {
  int count[4] = {};
  int input;
  int odd = 0;
  for (int i = 0; i < 6; i++) {
    cin >> input;
    count[input - 1]++;
  }
  for (int i = 0; i < 4; i++) {
    if (count[i] % 2 == 1) {
      odd++;
    }
  }
  if (odd == 0 || odd == 2)
    cout << "YES";
  else
    cout << "NO";
  return 0;
}

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

using namespace std;

// repetition
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

// container util
#define all(x) (x).begin(), (x).end()

// debug
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x)                                         \
  cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
       << " " << __FILE__ << endl;

// typedef
typedef long long lint;
typedef unsigned long long ull;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

// constant
const int MOD = (int)1e9 + 7;
const int INF = (int)1e18;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

// conversion
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

//
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
//

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

  lint L, R;
  cin >> L >> R;

  if (2019 < R - L) {
    cout << 0 << endl;
    return 0;
  }

  lint ans = 2019;
  for (lint i = L; i < R; i++) {
    for (lint j = i + 1; j <= R; j++) {
      ans = min(ans, i * j % 2019);
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>

using namespace std;

int main()
{
    string s;
    int w, cnt(0);
    cin >> s >> w;
    for(int i = 0; i < s.length(); i++)
    {
        if(cnt == 0)
            cout << s[i];
        cnt++;
        if(cnt == w)
            cnt = 0;
    }
}


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;

int main() {
    int N, X, Y;
    cin >> N >> X >> Y;
    vector<int> ans(N, 0);
    rep(i, N - 1) {
        for (int j = i + 1; j < N; j++) {
            int d = min({j - i, abs(X - 1 - i) + 1 + abs(Y - 1 - j), abs(X - 1 - j) + 1 + abs(Y - 1 - i)});
            ans[d]++;
        }
    }
    for (int i = 1; i < N; i++) {
        cout << ans[i] << "\n";
    }
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main{
    public static void main(String[] arsg){
        Scanner sc = new Scanner(System.in);
        int D = sc.nextInt();
        String ans = "Christmas";
        if(D==24){
            ans += " Eve";
        }else if(D == 23){
            ans += " Eve Eve";
        }else if(D == 22){
            ans += " Eve Eve Eve";
        }
        System.out.print(ans);
    }
}

Measured memory_bytes: 21588
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

#include <fstream>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <unordered_map>
#include <bitset>
#include <numeric>
#include <unordered_set>
#include <bitset>
#include <limits>
#include <random>
#include <complex>
#include <numeric>
#include <cstdlib>
#include <random>
#include <bits/stdc++.h>


using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
//typedef vector<ll> vec;
//typedef vector<vec> mat;

const ll mod=1000000007ll;
const ll inf=1000000000000000ll;

const ll MAX_N=100;

ll n,a[MAX_N];

int main(){
  cin>>n;
  for(ll i=0;i<n;i++){
    cin>>a[i];
  }
  sort(a,a+n,greater<>());
  /*
  for(ll i=0;i<n;i++){
    cout<<a[i]<<" ";
  }
  cout<<endl;
  */
  ll alice=0,bob=0;
  for(ll i=0;i<n;i+=2)alice+=a[i];
  for(ll i=1;i<n;i+=2)bob+=a[i];
  cout<<(alice-bob)<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
using namespace std;
set<int>a;
int main()
{
    int n,choose,temp;
    cin >> n;
    while (n--)
    {
        cin >> choose;
        switch (choose)
        {
        case 0:
            cin >> temp;
            a.insert(temp);
            cout << a.size() << endl;
            break;
        case 1:
            cin >> temp;
            if (a.find(temp) == a.end())cout << 0 << endl;
            else cout << 1 << endl;
            break;
        case 2:
            cin >> temp;
            a.erase(temp);
            break;
        }
    }
    
}


Measured memory_bytes: 12376
def main():
    s = str(input())

    if not (1 <= len(s) and len(s) <= 10**5):
        return
    if s.islower() == False:
        return
        
    alph = 'abcdefghijklmnopqrstuvwxyz'

    for i in alph:
        if i not in s:
            print(i)
            return
    
    print('None')

if __name__ == "__main__":
    main()

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
int main()
{
   ll n;
   cin>>n;
   ll arr[n],i,count=1,maxi=1;
   for(i=0;i<n;i++)
   cin>>arr[i];
   for(i=1;i<n;i++)
   {
       if(arr[i]<=arr[i-1])
       count++;
       else
       {
           maxi=max(count,maxi);
           count=1;
       }  
   }
    maxi=max(count,maxi);
    cout<<maxi-1;
}



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

#define pb push_back
#define all(a) (a).begin(), (a).end()

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

int main() {
    ios::sync_with_stdio(false);cin.tie(nullptr);
    ll n, k; cin >> n >> k;
    n %= k;

    while (abs(n - k) < n) {
        n = abs(n - k);
    }

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

Measured memory_bytes: 256
card = [list(map(int, input().split())) for i in range(3)]
N = int(input())
bingo = [[0, 0, 0], [0, 0, 0], [0, 0, 0]]
ans = 'No'
for _ in range(N):
    x = int(input())
    for i in range(3):
        for j in range(3):
            if x == card[i][j]:
                bingo[i][j] = 1

for i in range(3):
    if bingo[i][0]+bingo[i][1]+bingo[i][2] == 3:
        ans = 'Yes'
for i in range(3):
    if bingo[0][i]+bingo[1][i]+bingo[2][i] == 3:
        ans = 'Yes'
if bingo[0][0]+bingo[1][1]+bingo[2][2] == 3:
    ans = 'Yes'
if bingo[2][0]+bingo[1][1]+bingo[0][2] == 3:
    ans = 'Yes'

print(ans)


Measured memory_bytes: 9168
#include <iostream>
using namespace std;
 
int main(){
    while(true){
        int n, r, p, c;
        cin >> n >> r;
        if ((not n) && (not r)) break;
        int card1[n], card2[n];
        for (int i = 0; i < n; ++i){
            card1[i] = n - i;
            card2[i] = n - i;
        }
        for (int i = 0; i < r; ++i){
            cin >> p >> c;
            for (int j = 0; j < n; ++j){
                if (i % 2){
                    if (j < c){
                        card1[j] = card2[p-1+j];
                    }else if(j < c + p - 1){
                        card1[j] = card2[j-c];
                    }else{
                        card1[j] = card2[j];
                    }
                }else{
                    if (j < c){
                        card2[j] = card1[p-1+j];
                    }else if(j < c + p - 1){
                        card2[j] = card1[j-c];
                    }else{
                        card2[j] = card1[j];
                    }
                }
            }
        }
        if (r%2) cout << card2[0] << endl;
        else cout << card1[0] << endl;
    }
    return 0;
}


Measured memory_bytes: 3052
use whiteread::parse_line;

fn main() {
    let n: usize = parse_line().unwrap();
    let mut a: Vec<u32> = Vec::new();

    for _ in 0..n {
        a.push(parse_line().unwrap());
    }

    let mut cp = a.clone();
    cp.sort();
    //let (max1, max2) = (cp.pop().unwrap(), cp.pop().unwrap());
    let (max1, max2) = (cp[n - 1], cp[n - 2]);

    for num in a {
        if num == max1 {
            println!("{}", max2);
        } else {
            println!("{}", max1);
        }
    }
}


Measured memory_bytes: 3968
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Rep(i, k, n) for (int i = k; i < (int)(n); i++)
#define RRep(i, k, n) for (int i = k; i > (int)(n); i--)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define ALL(a)  (a).begin(),(a).end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int MOD = 1000000007;
const double PI = acos(-1); //3.14~
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

bool compare_by_b(pair<string, int> a, pair<string, int> b)
{
    if (a.second != b.second)
    {
        return a.second < b.second;
    }
    else
    {
        return a.first < b.first;
    }
}

int main()
{
    int n; cin >> n;
    vector<pair<pair<string, int>, int>> a(n);
    rep(i, n)
    {
        string s; int b; cin >> s >> b;
        a[i] = make_pair(make_pair(s, -b), i + 1); // マイナスB
    }

    sort(ALL(a));

    rep(i, n)
    {
        cout << a[i].second << endl;
    }
}

Measured memory_bytes: 256
import math

primes = [2, 3, 5, 7]

def is_prime(n):
    n_sqrt = math.sqrt(n)
    if n_sqrt.is_integer():
        return False
    n_sqrt = int(n_sqrt+1)

    if n in primes:
        return True
    if any(n % i == 0 for i in primes):
        return False
    if n > 10 and any(n % i == 0 for i in range(2, n_sqrt)):
        return False
    return True

n = int(input().strip())
a = [int(input().strip()) for i in range(n)]

print(len(list(filter(is_prime, a))))



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

int main(){
    using namespace std;
    unsigned long Q;
    cin >> Q;
    constexpr auto M{205891132094649UL};
    const auto& calc = [](auto a, auto b, auto c, auto d){
        auto u{b}, p{M};
        while(p /= 3)if((a / p + (4 - a / p % 3) % 3) * p <= c)if(b / p % 3 == 1){
            u = b / (3 * p) * 3 * p + 2 * p;
            return c - a + min(u - b + max(u, d) - min(u, d), b + d - 2 * (b / (3 * p) * 3 * p + p - 1));
        }
        return c - a + d - b;
    };
    for(unsigned long _{0}, a, b, c, d; _ < Q; ++_){
        cin >> a >> b >> c >> d;
        if(--a > --c)swap(a, c), swap(b, d);
        if(--b > --d){
            b = M - b - 1;
            d = M - d - 1;
        }
        cout << max(calc(a, b, c, d), calc(b, a, d, c)) << endl;
    }
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <cstring>
#include <string.h>
#include <cmath>
#include <algorithm>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <climits>
 
using namespace std;
#define inf 0m3f3f3f3f
#define fast ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define pb push_back
#define sz(v) (int)v.size()
#define all(m) (m).begin(), (m).end()
#define rall(m) (m).rbegin(), (m).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
 
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef vector<ll> vi;
//const int mod=1e9+7;
const int N=1e5+7;
 
int main(){
    fast;
    int t=1;
    //cin>>t;
    while(t--){
        ll n,x,a[N],ans=0;
        cin>>n>>x;
        forn(i,n) cin>>a[i];
        
        if(a[0]>x) ans+=a[0]-x, a[0]=x;
        
        for1(i,n-1){
            if(a[i]+a[i-1]>x) ans+=a[i]+a[i-1]-x, a[i]=x-a[i-1];
            
        }
        cout<<ans<<endl;
        
    }
    return 0;
}

Measured memory_bytes: 1024
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<cctype>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>

using namespace std;
const int dx[] = {1,0,-1,0},dy[] = {0,1,0,-1};
#define INF 999999
#define rep(i,j) for(int i=0;i<(j);++i)
#define reps(i,j,k) for(int i=j;i<k;++i)
typedef long long ll;
typedef unsigned long long ull;
int stage[20][20];
int main(){
	int n;
	while(scanf("%d",&n),n){
		memset(stage,0,sizeof(stage));
		int x= n/2;
		int y = x+1;
		int cnt = 1;
		while(n*n >= cnt){
			if(x < 0){
				x = n-1;
			}
			else if(n <= x){
				x = 0;
			}
			else if(n <= y){
				y = 0;
			}
			else if(stage[y][x]){
				x--;
				y++;
			}
			else{
				stage[y][x] = cnt++;
				x++;
				y++;
			}
		}
		rep(i,n){
			rep(j,n){
				printf("%4d",stage[i][j]);
			}
			puts("");
		}
	}
	return 0;
}

Measured memory_bytes: 1204
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repit(it, li) for(auto it=li.begin(); it!=li.end(); it++)
using namespace std;
using ll = long long;
using P = pair<int,int>;

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

   cout<<t<<s<<endl;
   return 0;
}


Measured memory_bytes: 3576
void main() {
    int[] tmp = readln.split.to!(int[]);
    int n = tmp[0], t = tmp[1];
    int[] a = new int[n], b = new int[n];
    foreach (i; 0 .. n) {
        tmp = readln.split.to!(int[]);
        a[i] = tmp[0], b[i] = tmp[1];
    }
    zip(a, b).sort!((t1, t2) => t1[0] > t2[0]);
    int[][] dp = new int[][](n+1, t);
    foreach (i; 0 .. n) {
        dp[i+1][0] = b[i];
        foreach (j; 0 .. t) {
            dp[i+1][j] = max(dp[i+1][j], dp[i][j]);
            if (j + a[i] < t) {
                dp[i+1][j+a[i]] = max(dp[i+1][j+a[i]], dp[i][j]+b[i]);
            }
        }
    }
    dp[n].reduce!max.writeln;
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;

Measured memory_bytes: 38780
#include <algorithm>
#include <climits>
#include <complex>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#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 REVERSE(c) reverse(ALL(c))
#define UNIQ(c) unique(ALL(c))
#define FOR(i, a, b, c) for (int i = (int)(a); i < (int)(b); i += (int)(c))
#define REP(i, n) FOR(i, 0, n, 1)
#define RFOR(i, a, b, c) for (int i = (int)(a); i >= (int)(b); i -= (int)(c))
#define RREP(i, n) RFOR(i, n, 0, 1)

// functions
template <class T> T ceil(T a, T b) {
    return (a + b - 1) / b;
}
template <class T> T round(T a, T b) {
    return (a + b / 2) / b;
}
template <class T> T gcd(T a, T b) {
    return b ? gcd(b, a % b) : a;
}
template <class T> T lcm(T a, T 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() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, A[2][100];
    cin >> N;
    REP(i, 2) {
        REP(j, N) {
            cin >> A[i][j];
        }
    }
    int res = 0;
    REP(i, N) {
        int sum = 0;
        REP(j, N) {
            if (j < i) {
                sum += A[0][j];
            } else if (j > i) {
                sum += A[1][j];
            } else {
                sum += A[0][j] + A[1][j];
            }
        }
        amax(res, sum);
    }
    cout << res << endl;
    return 0;
}


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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;
int T[202020];
int A[202020];
ll mo=1000000007;
int L[202020];
int R[202020];
int L2[202020];
int R2[202020];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	FOR(i,N) cin>>T[i];
	FOR(i,N) cin>>A[i];
	L[0]=R[0]=T[0];
	for(i=1;i<N;i++) {
		if(T[i]>T[i-1]) L[i]=R[i]=T[i];
		else R[i]=T[i], L[i]=1;
	}
	L2[N-1]=R2[N-1]=A[N-1];
	for(i=N-2;i>=0;i--) {
		if(A[i]>A[i+1]) L2[i]=R2[i]=A[i];
		else R2[i]=A[i], L2[i]=1;
	}
	ll ret=1;
	FOR(i,N) {
		L2[i]=max(L[i],L2[i]);
		R2[i]=min(R[i],R2[i]);
		if(L2[i]>R2[i]) ret=0;
		else ret=ret*(R2[i]-L2[i]+1)%mo;
	}
	cout<<ret<<endl;
	
	
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}


Measured memory_bytes: 2688
#include <iostream>
#include <sstream>
#include <vector>
#include <list>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
using namespace std;
 
typedef long long LL;
typedef set <LL> SET;
 
const int size = 51;
const string YES = "YES";
const string NO = "NO";

int bek[size];
int vol[size];
int n;

SET visited[size];
 
bool dist( int now );
bool solve( int now );
 
bool dist( int now ) {
    if ( vol[now] == 0 ) return solve( now + 1 );

    LL state = 0;
    for ( LL i = now; i < n; ++ i ) {
        if ( vol[i] == bek[i] ) state |= 1LL << i;
    }
    
    if ( visited[now].count( state ) ) return false;
    visited[now].insert( state );
    if ( vol[now] == 0 ) return false;
    
    for ( int i = now + 1; i < n; ++ i ) {
        if ( vol[i] != 0 ) continue;
        if ( vol[now] < bek[i] ) continue;
        if ( i - 1 > now && bek[i - 1] == bek[i] && vol[i - 1] == 0 ) continue;
        vol[now] -= bek[i];
        vol[i] = bek[i];
        if ( dist( now ) ) return true;
        vol[i] = 0;
        vol[now] += bek[i];
    }
    return false;
}
 
bool solve( int now ) {
    if ( now == n ) return true;
    if ( vol[now] == 0 ) return false;
    if ( now + 1 < n && bek[now+1] == bek[now] && vol[now] == 0 ) return false;
    if ( solve( now + 1 ) ) return true;
    if ( dist( now ) ) return true;
    return false;
}
 
int main() {
    while ( cin >> n && n ) {
        for ( int i = 0; i < n; ++ i ) {
            cin >> bek[i];
            vol[i] = 0;
            visited[i].clear();
        }
        sort( bek, bek + n, greater<int>() );
        vol[0] = bek[0];
        cout << ( solve( 0 ) ? YES : NO ) << endl;
    }
    return 0;
}

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

int main(){
    vector<int>num(3);
    rep(i, 3)	cin >> num[i];
    sort(num.begin(), num.end());
    if(num[2] == num[1] + num[0]){
	cout << "Yes" << endl;
    }else{
	cout << "No" << endl;
    }
}


Measured memory_bytes: 256
N, T = map(int, input().split())

INF = 10**3 + 1

c_min = INF

for i in range(N):
    c, t = map(int, input().split())
    if t <= T and c_min > c:
        c_min = c

print("TLE" if c_min == INF else c_min)

Measured memory_bytes: 2940
#include <stdio.h>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
#include <algorithm>
#include <tuple>

using namespace std;
#define ll long long
#define pb push_back

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

  if(s.at(0)==s.at(1) && s.at(2)==s.at(3)){
      flag = true;
  }
  if(s.at(0)==s.at(2) && s.at(1)==s.at(3)){
      flag = true;
  }
  if(s.at(0)==s.at(3) && s.at(2)==s.at(1)){
      flag = true;
  }

  if(s.at(0)==s.at(3) && s.at(2)==s.at(1) && s.at(0) == s.at(1)){
      flag = false;
  }

if(flag){
  cout << "Yes" << endl;
}else{
  cout << "No" << endl;

}
  

}


Measured memory_bytes: 256
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>

using namespace std;

void func(int N,int K){
	int exist[101] = {0},need[101] = {0},tmp;

	for(int i = 1; i <= K; i++){
		scanf("%d",&exist[i]);
	}

	for(int i = 1; i <= N; i++){
		for(int p = 1; p <= K; p++){
			scanf("%d",&tmp);
			need[p] += tmp;
		}
	}

	bool FLG = true;

	for(int i = 1; i <= K; i++){
		if(exist[i] < need[i]){
			FLG = false;
			break;
		}
	}

	if(FLG)printf("Yes\n");
	else{
		printf("No\n");
	}

}

int main(){

	int N,K;

	while(true){
		scanf("%d %d",&N,&K);
		if(N == 0 && K == 0)break;

		func(N,K);
	}


	return 0;
}

Measured memory_bytes: 2672
#include<cstdio>
using namespace std;
#define N 500050
#define mod 998244353
int fr[N],ifr[N],n,m,as;
int pw(int a,int p){int as=1;while(p){if(p&1)as=1ll*as*a%mod;a=1ll*a*a%mod;p>>=1;}return as;}
int main()
{
	fr[0]=ifr[0]=1;for(int i=1;i<=5e5;i++)fr[i]=1ll*fr[i-1]*i%mod,ifr[i]=pw(fr[i],mod-2);
	scanf("%d%d",&n,&m);
	for(int i=0;i<=n&&i<=m;i++)as=(as+1ll*(i&1?mod-1:1)*fr[n]%mod*ifr[i]%mod*ifr[n-i]%mod*fr[m]%mod*ifr[m-i]%mod*pw(m+1,n-i)%mod*pw(n+1,m-i))%mod;
	printf("%d\n",as);
}//???

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

ll mod = 1e9+7;
ll esq, dir;
ll dp[65][5][5][5];

ll solve(int pos, int biggerMin, int smallerMax, int k){
    // cout << pos << " " << biggerMin << " " << smallerMax << endl;
    if(pos < 0) return 1;
    if(dp[pos][biggerMin][smallerMax][k] != -1) return dp[pos][biggerMin][smallerMax][k];
    int a = (dir >> pos)&1;
    int b = (esq >> pos)&1;
    // cout << a << " " << b << endl;
    ll res = 0;
    if( b == 0 || biggerMin) // placing (0,0) in both numbers
        res += solve(pos-1, biggerMin, smallerMax || (a == 1), k);
    if( (b == 0 || biggerMin) && (a == 1 || smallerMax) && k)
        res += solve(pos-1, biggerMin, smallerMax, k);
    if( a == 1 || smallerMax)
        res += solve(pos-1, biggerMin || (b == 0), smallerMax, 1);
    res %= mod;
    return dp[pos][biggerMin][smallerMax][k] = res;
}

int main(){
    memset(dp, -1, sizeof dp);
    cin >> esq >> dir;
    cout << solve(60, 0, 0, 0) << endl;
	return 0;
}


Measured memory_bytes: 256