akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define F first
#define S second
#define _READ freopen("input.txt", "r", stdin);
#define _FAST                         \
    ios_base::sync_with_stdio(false); \
    cin.tie(0);                       \
    cout.tie(0);
void solve()
{
    int n, k, r, s, p;
    cin >> n >> k >> r >> s >> p;
    string t;
    cin >> t;
    int ans = 0;
    vector<int> R(n), S(n), P(n);

    for (int i = 0; i <k; i++)
    {
        if (t[i] == 'r')
        {
            S[i] = 0;
            R[i] = 0;
            P[i] = p;
            //ans+=p+s;
        }
        if (t[i] == 'p')
        {
            S[i] = s;
            R[i] = 0;
            P[i] = 0;
            // ans+=r+s;
        }
        if (t[i] == 's')
        {
            S[i] = 0;
            R[i] = r;
            P[i] = 0;
            //ans+=p+r;
        }
        int pos = i;
        for (int j = i + k; j < n; j += k)
        {
            if (t[j] == 'r')
            {
                S[j] += max(R[j - k], P[j - k]);
                R[j] += max(P[j - k], S[j - k]);
                P[j] += max(S[j - k], R[j - k]) + p;
                //ans+=p+s;
            }
            if (t[j] == 's')
            {
                S[j] += max(R[j - k], P[j - k]);
                R[j] += max(P[j - k], S[j - k]) + r;
                P[j] += max(S[j - k], R[j - k]); //+p;
                //ans+=r+p;
            }
            if (t[j] == 'p')
            {
                S[j] += max(R[j - k], P[j - k]) + s;
                R[j] += max(P[j - k], S[j - k]);
                P[j] += max(S[j - k], R[j - k]); //+p;
                //ans+=r+s;
            }
            pos = j;
        }
        ans += max({R[pos], P[pos], S[pos]});
    }
    cout << ans;
}
int32_t main()
{

   // _READ
     _FAST
    int t;
    t = 1;
    while (t--)
        solve();

    return 0;
}

Measured memory_bytes: 2896
N,M,X = gets.split.map &:to_i
CA = N.times.map{ gets.split.map &:to_i }

c_min = nil
(2**N).times do |mask|
    cost = 0
    skill = [0]*M
    CA.each_with_index do |(c,*a), i|
        next if mask[i] == 0
        cost += c
        a.each_with_index do |s,j|
            skill[j] += s
        end
    end

    if (c_min.nil? || (cost<c_min)) && skill.min >= X then
        c_min = cost
    end
end

p c_min || -1

Measured memory_bytes: 14548
/*
Author : N_o_o_B
Created : December 02 2019 15:06:06 
*/
#include <bits/stdc++.h>
using namespace std;
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
*/
#define TRACE
#ifdef TRACE
#define trace(...) { cerr<<"[ "; __trace__(#__VA_ARGS__, __VA_ARGS__);}
#undef endl
template <typename Arg1,typename Arg2>
ostream& operator << (ostream& out, const pair<Arg1,Arg2> &x) {
    return out<<"("<<x.first<<","<<x.second<<")";
}
 
template <typename Arg1>
ostream& operator << (ostream& out, const vector<Arg1> &a) {
    out<<"[";for(const auto &x:a)out<<x<<",";return out<<"]";
}
 
template <typename Arg1>
ostream& operator << (ostream& out, const set<Arg1> &a) {
    out<<"[";for(const auto &x:a)out<<x<<",";return out<<"]";
}
 
template <typename Arg1,typename Arg2>
ostream& operator << (ostream& out, const map<Arg1,Arg2> &a) {
    out<<"[";for(const auto &x:a)out<<x<<",";return out<<"]";
}
 
template <typename Arg1>
void __trace__(const string name, Arg1&& arg1){
    cerr << name << " : " << arg1 << " ] " << endl;
}
 
template <typename Arg1, typename... Args>
void __trace__(const string names, Arg1&& arg1, Args&&... args){
    const string name = names.substr(0,names.find(','));
    cerr<<name<<" : "<<arg1<<" | ";
    __trace__(names.substr(1+(int)name.size()), args...);
}
#else
    #define trace(args...)
#endif
 
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pair<int,int>> vii;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<pair<ll,ll>> vll;
typedef vector<vl> vvl;
//typedef tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> oset;
#define fori(i,n) for(int i=0;i<n;i++)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define repd(i,a,b) for(int i=a;i>=b;i--)
#define ford(i,n)  for(int i=n-1;i>=0;i--)
#define trav(x,a) for(auto& x:a)
#define all(x) x.begin(),x.end()
#define pb push_back
#define endl '\n'
#define sz(a) (int)a.size()
#define fi first
#define se second
clock_t time_p=clock();
void time_taken()
{
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}
//const ll mod=998244353;
const ll mod=1e9+7;
const ll INF=1e18;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    cout.precision(12);cout << fixed;
    int n,l;
    cin >> n >> l;
    vector<string> a(n);
    fori(i,n) cin >> a[i];
    sort(all(a));
    fori(i,n) cout << a[i];
    cout << endl;




    time_taken();
    return 0;
}

Measured memory_bytes: 256
def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def s3(n):return [[input().split()] for _ in range(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]

n=n0()
a=n1()
b=n1()
c=n1()

a.sort()
b.sort()
c.sort()

from bisect import bisect_left,bisect_right
b2=[]
for i in b:
    b2.append(bisect_left(a,i))

import itertools
b3=list(itertools.accumulate(b2))
    
ans=0
for i in c:
    t=bisect_left(b,i)
    if t>0:
        ans+=b3[t-1]
    
print(ans)

Measured memory_bytes: 24692
import itertools
import math
import sys
import heapq
from collections import Counter
from collections import deque
from fractions import gcd
INF = 1 << 60
sys.setrecursionlimit(10 ** 6)

#ここから書き始める
n = int(input())
ans = 0
for i in range(1, n + 1, 2):
    cnt = 0
    d = 1
    while d <= i:
        if i % d == 0:
            cnt += 1
        d += 1
    if cnt == 8:
        ans += 1
print(ans)

Measured memory_bytes: 5288
import sys
import math

n = int(sys.stdin.readline().rstrip("\n"))
c = list(sys.stdin.readline().rstrip("\n"))
ans = 0
left, right = 0, n-1

while(left < right):
    while(c[left] == 'R'):
        left += 1
        if left >= n:
            break
    while(c[right] == 'W'):
        right -= 1
        if right < 0:
            break
    if (left < right):
        c[left], c[right] = c[right], c[left]
        ans += 1
    else:
        break

print(ans)

Measured memory_bytes: 10788
#include <stdio.h>

typedef struct {
  int P;
  int C; 
  int B;
}tree;

int main()
{
  int n,i,j,id,k,kodomo,irekae,depth;

  scanf("%d",&n);

  tree T[n];

  /*入力編*/

  for(i=0;i<n;i++)
    {
      T[i].P=-1;
    }
  
  for(i=0;i<n;i++)
    {
      scanf("%d%d",&id,&k);/*idとkの入力*/
      
      if(k!=0)/*子供がいる場合*/
	{
	  scanf("%d",&T[id].C);

	  kodomo=T[id].C;
      
	  for(j=0;j<k;j++)
	    {
	      if(j==k-1)T[kodomo].B=-1;/*最右の子は兄弟rootを-1にする。*/
	      else scanf("%d",&T[kodomo].B);/*子の兄弟の一人を代入（ひとりいれて次々連結していく）*/
	      
	      T[kodomo].P=id;/*親代入*/
	      
	      irekae=kodomo;
	      kodomo=T[irekae].B;/*kodomoを次の子供の番号に入れ替える*/
	    }
	}
      else
	{
	  T[id].C=-1;
	}

      
    }

  /*出力編*/

  for(i=0;i<n;i++)
    {

      printf("node %d: ",i);/*ノード番号出力*/
 
      printf("parent = %d, ",T[i].P);/*親出力*/
      
      depth=0;
      id=i;
      
      while(1)
	{
	  if(T[id].P==-1)break;
	  
	  depth++;
	  
	  irekae=id;
	  id=T[irekae].P;
	}

      printf("depth = %d, ",depth);/*深さ出力*/

      if(T[i].P==-1)
	{
	  printf("root, [");

	  if(T[i].C==-1)
	    {
	      printf("]\n");
	    }
	  else
	    {
	      id=T[i].C;
	      while(1)
		{
		  if(T[id].B==-1)
		    {
		      printf("%d]\n",id);
		      break;
		    }
		  else
		    {
		      printf("%d, ",id);
		      irekae=T[id].B;
		      id=irekae;
		    }
		}
	    }
	}
      else if(T[i].C==-1)
	{
	  printf("leaf, []\n");
	}
      else
	{
	  printf("internal node, [");
	  
	  id=T[i].C;
	  while(1)
	    {
	      if(T[id].B==-1)
		{
		  printf("%d]\n",id);
		  break;
		}
	      else
		{
		  printf("%d, ",id);
		  irekae=T[id].B;
		  id=irekae;
		}
	    }
	}
    }
  
  return 0;
}



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

using namespace std;

using ll = long long;
using ld = long double;

using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vvvl = vector<vvl>;
using vd = vector<double>;
using vvd = vector<vd>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vs = vector<string>;

const int INF = (1 << 30) - 1;
const ll INF64 = ((ll)1 << 62) - 1;
const double PI = 3.1415926535897932384626433832795;

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

int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
int lcm(int x, int y) { return x / gcd(x, y) * y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

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

	int a, b, c, d;
	cin >> a >> b >> c >> d;

	if (a + b > c + d) {
		cout << "Left" << endl;
	} else if (a + b < c + d) {
		cout << "Right" << endl;
	} else {
		cout << "Balanced" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
from collections import defaultdict, Counter
from bisect import bisect_right, bisect_left

N = int(input())
A = list(map(int, input().split()))
C = Counter(A)
ans = sum(A)
Q = int(input())
for i in range(Q):
    b, c = map(int, input().split())
    C[c] += C[b]
    ans -= b * C[b]
    ans += c * C[b]
    C[b] = 0
    print(ans)

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

int main() {
    string n;
    cin >> n;
    int r = 0;
    for (auto c : n) {
        r += c - '0';
        r %= 9;
    }
    if (r == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3736
/*@author hussein zayed ;
    ___  ___
   |\  \|\  \
   \ \  \_\  \
    \ \   ___ \USSEIN
     \ \  \\ \ \
      \ \__\\ \_\
       \|__| \|__|
****************************************
*/

#include <bits/stdc++.h>
using namespace std;
#define fr for(int i=0;i<n;++i)
#define fr1 for(int i=1;i<=n;++i)
#define cinA for(int i=0;i<n;++i){cin>>arr[i];}
#define cinA1 for(int i=1;i<=n;++i){cin>>arr[i];}
#define coutA for(int i=0;i<n;++i){cout<<arr[i]<<" ";}
#define ll long long
#define lnarray sizeof(arr)/sizeof(*arr)
#define vi vector<int>
#define vs vector<string>
void Fast()
{
    ios_base :: sync_with_stdio( 0 ) ;
    cin.tie( 0 ) ;
    cout.tie( 0 ) ;
}
inline int RD()
{
    int i ;
    cin>>i;
    return i;
}

inline float RF()
{
    float i ;
    cin>>i;
    return i;
}

inline double RDO()
{
    double i ;
    cin>>i;
    return i;
}

inline string RS()
{
    string i ;
    cin>>i;
    return i;
}

inline ll RLL()
{
    ll i ;
    cin>>i;
    return i;
}

int cm[200000];

ll sumSet(ll n)
{
    return (1ll*n*(n+1))/2;
}
string s;


bool isPrime(int n)
{
    if(n==1)
        return false;
    for(int i=2; i*i<=n; ++i)
    {
        if(n%i==0)
            return false;
    }
    return true;
}
int sumDigit(int n){
int sum =0;
  while (n != 0)
    {
        sum+= + n % 10;
        n = n / 10;
    }
    return sum;
}

ll power2(int n){
  ll ans=(1<<n);
  return ans;
}

ll sumpow2(ll n){
 ll sum=(n*(n+1)*(2*n-1))/6;
 return sum;
}

int main(){
    Fast();
//freopen("output.txt" , "w" , stdout);
//freopen("wall.in" , "r" , stdin);

  int n=RD(),m=RD();
  char a[n+2][n+2];
   char b[m+3][m+3];
  for(int i=0;i<n;i++){
   for(int j=0;j<n;j++){
   cin>>a[i][j];

   }
 }
 for(int i=0;i<m;i++){
   for(int j=0;j<m;j++){
 cin>>b[i][j];
 }

  }
 for(int i=0;i<n;i++){
   for(int j=0;j<n;j++){
 int cnt=0;

     for(int x=0;x<m;x++){
       for(int y=0;y<m;y++){

       if(b[x][y]==a[i+x][j+y]){
       cnt++;

       }
       }}
     if(cnt==(m*m)){
     cout<<"Yes";
     return 0;
     }

   }
}
cout<<"No";
 }




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using pii= pair<int, int>;
using Graph= vector<vector<pii>>;
const int TBC= -1;

void DFS(Graph &gph, int id, vector<int> *memo){
  for(auto e:gph.at(id)){
    int child,w;
    tie(child, w)= e;
    if(memo->at(child)==TBC){
      memo->at(child)= (memo->at(id)+ w) % 2;
      DFS(gph, child, memo);
    }
  }
  return;
}

int main(){
  int N;
  cin >> N;

  Graph G(N);
  int v1,v2,w;
  for(int i=0; i<N-1; i++){
    cin >> v1 >> v2 >> w;
    v1--; v2--; // 1-indexed -> 0-indexed
    G.at(v1).emplace_back(make_pair(v2, w%2));
    G.at(v2).emplace_back(make_pair(v1, w%2));
  }

  vector<int> memo(N, TBC);
  memo.at(0)= 0;
  DFS(G, 0, &memo);

  for(auto ans:memo){
    cout << ans << endl;
  }
}

Measured memory_bytes: 8960
#include <unordered_map>
#include <vector>
#include <queue>
#include <iostream>
using namespace std;
#define ll long long
int n,k;
int seg[600055];
int sz = 300005;
void upd(int i,int v){
    seg[i+=sz] = v;
    while(i>1){
        i/=2;
        seg[i] = max(seg[2*i],seg[2*i+1]);
    }
}
int query(int l,int r){
    l+=sz; r+=sz;
    int ret =0;
    while(l<r){
        if(l%2) ret = max(ret,seg[l++]);
        if(r%2) ret = max(ret,seg[--r]);
        l/=2; r/=2;
    }
    return ret;
}
int main(){
    cin >> n >> k;
    int a[n];
    for(int i=0;i<n;i++) cin >> a[i];
    for(int i=0;i<n;i++) a[i];
    for(int i=n-1;i>=0;i--){
        int l = max(0,a[i]-k);
        int r = min(a[i]+k,sz-1);
        int x = query(l,r+1)+1;
        upd(a[i],x);
        
    }
    cout << query(0,sz) << endl;
    
}


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

const int MAX = 5e5+3;
const ll mod = 1000000007;

ll fact[MAX], inv[MAX], finv[MAX];

ll nCk(ll n, ll k){
  if(n < k) return 0;
  if(n < 0 || k < 0) return 0;
  return fact[n] * finv[n-k] % mod * finv[k] % mod;
}

void pre_cal(){
  fact[0] = inv[1] = fact[1] = 1;
  finv[0] = finv[1] = 1;
  for(int i = 2; i <= 5e5; i++){
    fact[i] = fact[i-1] * i % mod;
    inv[i] = mod - (mod/i) * inv[mod%i] % mod;
    finv[i] = finv[i-1] * inv[i] % mod;
  }
}

int main(){
  pre_cal();
  ll n, k; cin >> n >> k;
  vector<ll> a(n);
  for(ll i = 0; i < n; i++) cin >> a[i];
  sort(a.begin(), a.end());
  ll mx = 0, mn = 0;
  for(ll i = k; i <= n; i++){
    mx += mod + nCk(i-1, k-1) * a[i-1] % mod;
    mx = (mx + mod) % mod;
  }
  for(ll i = 0; i <= n-k; i++){
    mn += nCk(n-i-1, k-1) * a[i] % mod;
    mn = (mn + mod) % mod;
  }
  cout << (mod + (mx - mn)%mod)%mod << endl;
}

Measured memory_bytes: 15632
import           Control.Monad

type Matrix = [[Char]]
type Pattern = [Bool]

patterns :: Int -> [Pattern]
patterns n = do
    start <- return []
    foldr (<=<)
        return
        (replicate n (\x -> map (:x) [True, False]))
     start

fill :: Matrix -> Pattern -> Matrix
fill [] _          = []
fill (x:xs) (y:ys)
  | y         = replicate (length x) 'R':(fill xs ys)
  | otherwise = x:(fill xs ys)

swap :: Matrix -> Matrix
swap ([]:_) = []
swap line   = foldr (\x acc -> head x : acc) [] line : (swap . map tail) line

main :: IO ()
main = do
    [h, w, k] <- map read . words <$> getLine
    matrix <-  lines . filter (/=',') <$> getContents
    let matrix' = return matrix
                >>= (\m -> map (fill m) (patterns h))
                >>= (\m -> map (fill $ swap m) (patterns w))
    print $ length . filter (==k) $ map (length . filter (=='#')) $ map concat matrix'


Measured memory_bytes: 4896
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define M 1000000007

void solve(){
	int n;
	cin >> n;
	for(int i=1; i<=n; i++){
		int count = 0;
		for(int j=1; j*j<=i; j++){
			for(int k=j; k*k<=i; k++){
				for(int l=k; l*l<=i; l++)
				{
					if(j*j+ k*k+l*l+j*l+j*k+k*l == i){
						if(j==k && k==l) count++;
						else if(j==k || k==l || j==l) count+=3;
						else count+=6;
					}
				}
			}
		}
		cout << count << "\n";
	}
}

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

	solve();
	return 0;	
}

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

int main ()
{
 	int a, b, c;
  cin >> a >> b >> c;
  if(a == b && b == c)
	cout << "No" << endl;
  else if(a == b && b != c)
	cout << "Yes" << endl;
  else if(a == c && b != c)
	cout << "Yes" << endl;
  else if(b == c && a != c)
	cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


Measured memory_bytes: 256
import java.util.*;
public class Main{
  public static void main (String args[]){
    Scanner sc = new Scanner(System.in);
    String steps = sc.next();
    String easy = "Yes";
    
    
    for ( int i = 0; i<steps.length(); i++){
      if (i%2 == 0){
        if(steps.substring(i,i+1).equals("L")){
          easy = "No";
          break;
        }
      } else {
          if(steps.substring(i,i+1).equals("R")){
          easy = "No";
          break;
          }
        }
    }
    
    System.out.println(easy);
    
  }
}


Measured memory_bytes: 22868
import java.io.*;
class Main
{
    public static void main(String args[])throws IOException
    {
	BufferedReader input=new BufferedReader(new InputStreamReader(System.in));
	
	String a;
	while(true)
	    {
		a=input.readLine();
		if(a.equals("0"))break;			
		int n=Integer.parseInt(a);
		String c=input.readLine();
		String b[]=c.split(" ");
		double d=0,sum=0;
		double e[]=new double[n];
		for(int j=0;j<n;j++)
		    {			
			e[j]=Double.parseDouble(b[j]);
			sum+=e[j];
		    }
		
			double m=sum/n;
			
			for(int i=0;i<n;i++)
			    {
				d+=(Math.pow((e[i]-m),2)/n);
			    } 
			
		System.out.println(Math.sqrt(d));
	    }
    }
}


			    

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

int main() {
    int N; cin >> N;
    vector<string> S(2 * N);
    rep(i, 0, N) {
        cin >> S[i];
        S[i + N] = S[i];
    }
    int ans = 0;
    rep(d, 0, N) {
        bool ok = true;
        rep(i, 0, N) rep(j, 0, N) {
            if(S[i + d][j] != S[j + d][i]) ok = false;
        }
        if(ok) ans += N;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 512
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <vector>
#include <set>
#include <cstdlib>
#include <random>
#include <map>
#include <string>
#include <algorithm>
#include <bitset>
#include <numeric>
#include <cassert>
#include <iomanip>
#include <cmath>

using namespace std;

typedef long long ll;
typedef long double ld;

const int M = (int)1e5 + 1;
const ld EPS = 1e-9;
const ll MOD = (ll)1e9 + 7;
const ll INF = (ll)1e9 + 10;
const ld PI = acosl(-1);
const int N = (int)1e6 + 2;

void solve() {
	int h, w, n;
	cin >> h >> w >> n;
	int k = max(h, w);
	cout << (n + k - 1) / k << endl;
}

int main() {
	//auto trash = freopen("a.in", "r", stdin);
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	solve();
}

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

int main() 
{
    int N;
    cin>>N;
    vector<int>A(N);
    for (int i = 0; i < N; i++)
    {
        int a;
        cin>>a;
        A[i]=a;
    }
    
    int cnt=0;
    for (int i = 0; i < N; i++)
    {
        if((i+1)%2!=1)
        {
            continue;
        }

        if(A[i]%2==1)
        {
            ++cnt;
        }
    }

    cout<<cnt<<endl;
    return 0;   
}

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

using namespace std;
string s;

bool check(int i){
    return (s[i] == 'A' || s[i] == 'C' || s[i] == 'G' || s[i] == 'T');
}

int main()
{
    cin >> s;
    int Ans = 0;
    for(int i = 0;i<s.size();i++){
        int c = 0;
        while(check(i))  i++ , c++;
        Ans = max(Ans , c);
    }
    cout << Ans;
    return 0;
}


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

#define MAXN 500

int h, w;

int arr[MAXN+10][MAXN+10];

int ans;
vector<pair<pair<int, int>, pair<int, int> > > todo;

int main()
{
    scanf("%d%d", &h, &w);

    int i, j;

    for(i=1; i<=h; i++) for(j=1; j<=w; j++) { scanf("%d", &arr[i][j]); arr[i][j]%=2; }


    for(i=1; i<=h; i++) for(j=1; j<w; j++) if(arr[i][j]) {todo.push_back(make_pair(make_pair(i, j), make_pair(i, j+1))); ans++; arr[i][j+1]=1-arr[i][j+1]; }
    for(i=1; i<h; i++) if(arr[i][w]) {todo.push_back(make_pair(make_pair(i, w), make_pair(i+1, w))); ans++; arr[i+1][w]=1-arr[i+1][w]; }

    printf("%d\n", ans);
    for(i=0; i<todo.size(); i++) printf("%d %d %d %d\n", todo[i].first.first, todo[i].first.second, todo[i].second.first, todo[i].second.second);
}


Measured memory_bytes: 5232
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <limits>
#include <queue>
#include <iomanip>
#include <set>
//#include <bits/stdc++.h>
template<typename T> bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<typename T> bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}
using namespace std;
#define ALL(X) X.begin(),X.end()
using ll = long long int;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
const int MOD=1000000007;
//const int MOD=998244353;
const int INTMAX=2147483647;
const ll LLMAX=9223372036854775807;


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    string T;
    cin>>T;
    
    for(ll i=0;i<T.size();i++){
        if(T[i]=='?')T[i]='D';
    }
    ll ans=0;
    for(ll i=0;i<T.size();i++){
        if(T[i]=='P'){
            if(i<T.size()-1&&T[i+1]=='D'){
                ans++;
            }
        }else ans++;
    }
    cout<<T<<endl;
    
    return 0;
}


Measured memory_bytes: 3736
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/

const ll mod = 1000000007;

ll modpow(ll x, ll n){
    if(n == 0) return 1;

    ll res = modpow(x, n/2);
    if(n%2 == 0) return res*res%mod;
    else return (((res*res)%mod)*x)%mod;
}

int main(){
    string s; cin >> s;
    int N = s.size();
    s = '0'+s;

    vector<ll> cum1(N+5, 0);
    for(int i=1; i<=N; i++){
        if(s[i] == '1') cum1[i] = cum1[i-1]+1;
        else cum1[i] = cum1[i-1];
    }

    ll ans = 0;
    for(int i=1; i<=N; i++){
        if(s[i] == '0') continue;

        ll tmp = 1;
        tmp = modpow(2, cum1[i-1]);
        tmp *= modpow(3, N-i);
        tmp %= mod;
        
        ans += tmp;
        ans %= mod;
    }

    ll tmp = 1;
    for(int i=1; i<=N; i++){
        if(s[i] == '0') tmp *= 1;
        else tmp *= 2;
        tmp %= mod;
    }

    ans += tmp;
    ans %= mod;
    
    cout << ans << endl;

}

Measured memory_bytes: 1276
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int maxn = 100005;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    string s;
    cin >> s;
    int n = s.size();
    if(s[n - 1] == '2' || s[n - 1] == '4' || s[n - 1] == '5' || s[n - 1] == '7' || s[n - 1] == '9')return cout << "hon", 0;
    if(s[n - 1] == '0' || s[n - 1] == '1' || s[n - 1] == '6' || s[n - 1] == '8')return cout << "pon", 0;
    if(s[n - 1] == '3')return cout << "bon", 0;
    return 0;
}


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

using namespace std;

#define cerr if(false)cerr
#define what(x) cerr<<#x<<" = "<<x<<endl
 
typedef long long ll;
typedef pair<ll, ll> ii;

const int maxN = 1e5 + 9, maxV = 1e6 + 9, MOD = 1e9 + 7, SQ = 322;

int main(){

	ios_base::sync_with_stdio(false); 
	cin.tie(0);
	cout.tie(0);

	string s;
	int n;
	cin >> n >> s;

	if(n >= s.size()){
		cout << s << endl;
	}else{
		cout << s.substr(0, n) << "..." << endl;
	}

	return 0;
}

Measured memory_bytes: 3652
n = int(input())

xy = [map(int, input().split()) for _ in range(n)]
x, y = [list(i) for i in zip(*xy)]

count = 0
for i in range(n):
  if x[i] == y[i]:
    count += 1
    if count == 3:
      print('Yes')
      exit()
  else:
    count = 0

print('No')

Measured memory_bytes: 9188
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int AS = 1 << 17;
ll dat[2 * AS];
const ll are = 1 << 30;
void modify(int p) {
	for (dat[p += AS] -= are; p > 1; p >>= 1) dat[p >> 1] = max(dat[p], dat[p ^ 1]);
}
void modify0(int p) {
	for (dat[p += AS] = 0; p > 1; p >>= 1) dat[p >> 1] = max(dat[p], dat[p ^ 1]);
}

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}
const int dm = 1 << 20;
char dn[dm], * di = dn;
inline void putint(int X) {
	int keta = 0;
	char C[10];
	while (X) {
		*(C + keta) = '0' + X % 10;
		X /= 10;
		keta++;
	}
	for (int i = keta - 1; i >= 0; i--)* di++ = (*(C + i));
	*di++ = ' ';
}

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


	int N = getint();
	int A[100000];
	rep(i, N) {
		A[i] = getint() - 1;
		dat[AS + A[i]]++;
	}
	rep(i, N) dat[AS + i] = (dat[AS + i] << 30) + i;
	for (int i = AS - 1; i > 0; i--) dat[i] = max(dat[i << 1], dat[i << 1 | 1]);

	if (N == 2) {
		printf("-1");
		return 0;
	}

	int dame = -1;
	int j = 0;
	const int m = (1 << 30) - 1;
	bool used[100000] = {};
	bool iranai = 0;
	rep(i, N - 3) {
		int kotae;
		if (!iranai && N - i - 1 == dat[1] >> 30) {
			kotae = dat[1] & m;
			iranai = 1;
		}
		else {
			int k = j;
			while (used[k] || k == dame) k++;
			kotae = k;
		}
		putint(kotae + 1);
		used[kotae] = 1;
		dame = A[kotae];
		while (used[j]) j++;
		if (!iranai) modify(dame);
		//modify0(kotae);

		//これを入れないと正しくなさそうだけど
		//嘘でも通るならいいかなって・・・
		//5
		//2 3 1 1 1
		//とか壊れてる
	}

	int kouho[3];
	int k = 0;
	for (int i = j; i < N; i++) {
		if (!used[i]) kouho[k++] = i;
	}
	while (1) {
		if (dame != kouho[0] && A[kouho[0]] != kouho[1] && A[kouho[1]] != kouho[2]) break;
		next_permutation(kouho, kouho + 3);
	}
	putint(kouho[0] + 1);
	putint(kouho[1] + 1);
	putint(kouho[2] + 1);

	fwrite(dn, 1, di - dn, stdout);

	Would you please return 0;
}

Measured memory_bytes: 3712
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#define ele int
using namespace std;
#define maxn 200010
const ele INF=1e9;
struct edge{
	ele v;
	edge *nxt;
}ep[maxn<<1],*ecnt;
ele n,r,d[maxn],f[maxn];
edge *h[maxn];
inline void addedge(ele u,ele v){
	edge *p=ecnt++;
	p->v=v; p->nxt=h[u];
	h[u]=p;
}
void dfs(ele p,ele i,ele B){
	vector<ele> lst;
	for (edge *j=h[i]; j; j=j->nxt)
		if (j->v!=p){
			dfs(i,j->v,B);
			lst.push_back(f[j->v]);
		}
	if (lst.size()%2==0) lst.push_back(0);
	sort(lst.begin(),lst.end());
	f[i]=INF;
	for (int r=0; r<lst.size(); ++r){
		ele u=0,v=lst.size()-1;
		bool flag=true;
		while (u<v){
			if (u==r) ++u;
			if (v==r) --v;
			if (u<v && lst[u]+lst[v]>B){ flag=false; break; }
			++u; --v;
		}
		if (flag){ f[i]=lst[r]+1; break; }
	}
}
inline bool test(ele B){
	dfs(-1,r,B);
	return f[r]<=B+1;
}
int main(){
	scanf("%d",&n);
	ecnt=ep; memset(h,0,sizeof(h)); memset(d,0,sizeof(d));
	for (int i=0; i<n-1; ++i){
		ele x,y;
		scanf("%d%d",&x,&y); --x,--y;
		addedge(x,y); addedge(y,x);
		++d[x]; ++d[y];
	}
	ele cnt=0;
	for (int i=0; i<n; ++i){
		if (d[i]==1) r=i;
		if (d[i]&1) ++cnt;
	}
	ele L=0,R=n-1;
	while (R-L>1){
		ele mid=(L+R)>>1;
		if (test(mid)) R=mid; else L=mid;
	}
	printf("%d %d\n",cnt/2,R);
	return 0;
}

Measured memory_bytes: 17664
#include<bits/stdc++.h>
using namespace std;
//#define num 1000000007
#define num 998244353
#define REP(i,a,n) for(ll i=a;i<n;i++)
#define inarr(i,a,n,A) for(ll i=a;i<n;i++) { cin>>A[i]; }
#define vll vector<long long>
#define pii pair <int,int>
#define pll pair<long long, long long>
#define vpii vector< pair <int,int>>
#define vpll vector< pair<long long, long long>>
//#define max(a,b) ((a>b)?a:b)
//#define min(a,b) ((a>b)?b:a)
#define max3(a,b,c) ((a>b)?(a>c)?a:c:(b>c)?b:c)
#define min3(a,b,c) ((a<b)?(a<c)?a:c:(b<c)?b:c)
#define avg(a,b) ((a)+(b))/2
#define pb push_back
#define pob pop_back
#define sf int flag=0     //Remember semicolon
// #define assmin(a,b) if(b<=a) { a=b; }
// #define assmax(a,b) if(b>=a) { a=b; }
#define f first
#define s second
#define fix(f,n) std::fixed<<std::setprecision(n)<<f
#define all(x) x.begin(), x.end()
#define M_PI 3.14159265358979323846
#define epsilon (double)(0.00000000001)
#define side 1e9
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
ll mod(ll a, ll b)
{
	if(a%b<0)
	{
		return a%b + b;
	}
	return a%b;
}
 
 
ll mod_exp(ll a, ll b, ll c)
{
	ll res=1;
	a=a%c;
	while(b>0)
	{
		if(b%2==1)
		{
			res=(res*a)%c;
		}
		b/=2;
		a=(a*a)%c;
	}
	return res;
}
ll mymod(ll a,ll b)
{
    return ((a%b)+b)%b;
}
bool prime[200001];
void SieveOfEratosthenes() 
{ 
    memset(prime, true, sizeof(prime)); 
    prime[1]=false;
    for (int p=2; p*p<=200000; p++) 
    { 
        if (prime[p] == true) 
        { 
            for (int i=p*p; i<=200000; i += p) 
                prime[i] = false; 
        } 
    } 
    return;
}
ll powe[200005];
void power()
{
    powe[0]=1;
    REP(i,1,200005)
    {
        powe[i]=mymod(2*powe[i-1],num);
    }
}
ll gcdExtended(ll,ll,ll *,ll *);
ll modInverse(ll a, ll m) 
{ 
    ll x, y; 
    ll g = gcdExtended(a, m, &x, &y); 
        ll res = (x%m + m) % m;
        return res;
} 
ll gcdExtended(ll a, ll b, ll *x, ll *y) 
{ 
    if (a == 0) 
    { 
        *x = 0, *y = 1; 
        return b; 
    } 
    ll x1, y1; 
    ll gcd = gcdExtended(b%a, a, &x1, &y1); 
    *x = y1 - (b/a) * x1; 
    *y = x1; 
    return gcd; 
}
struct node
{
	vll adj;
    ll indegree;
};
ll n,m,t;
bool inrange(ll a, ll b)
{
    return a>=0 && a<n && b>=0 && b<m;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll a,b,c;
    cin>>a>>b>>c;
    ll ans=LLONG_MAX;
    if(a&1 && b&1 && c&1)
    {   
        ans = min(ans, a*b);
        ans = min(ans, b*c);
        ans = min(ans, c*a);
    }
    else
    {
        ans = 0;
    }
    cout<<ans<<"\n";
    return 0;
}

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

using namespace std;
int gcd(int a, int b) {
	return b == 0 ? a : gcd(b, a % b);
}
int main() {
	int k; cin >> k;
	long long ans = 0;
	for (int i = 1; i <= k; i++) 
		for (int j = 1; j <= k; j++) 
			for (int h = 1; h <= k; h++) 
				ans += gcd(gcd(i, j), h);
	cout << ans << endl;
} 

Measured memory_bytes: 3624
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
using System.Numerics;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            Solve();
            //Out.Flush();
            Read();
        }
        static void Solve()
        {
            var N = Sarray()[0];
            var ans = 1L;
            for (var i = 1; i <= N; ++i)
                ans = ans * i % Mod;
            WriteLine(ans);
        }
        


        static long Mod = (long)1e9 + 7;
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static public (T1 a, T2 b) Slice<T1, T2>()
        {
            var t = ReadLine().Split();
            return (
            (T1)Convert.ChangeType(t[0], typeof(T1)),
            (T2)Convert.ChangeType(t[1], typeof(T2)));
        }
        static public (T a, T b) Slice2<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)));
        }
        static public (T a, T b, T c) Slice3<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)),
            (T)Convert.ChangeType(t[2], typeof(T)));
        }
    }
}

Measured memory_bytes: 28092
import java.util.Scanner;

public class Main {

	public static void main(String[] args) 
	{
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		
		long[] a = new long[n];
		
		int dirright = -1;
		int dirleft = -1;
		for(int i = 0; i < n; i++)
		{
			a[i] = sc.nextLong();
			if(a[i] == 0)k--;
			
			if(a[i] > 0)
			{
				if(dirright == -1)dirright=i;
			}
			else if(a[i] < 0)
				dirleft = i;
		}
		if(k==0)
		{
			System.out.println(0);
			return;
		}
		
//		long[] costl = new long[k+1];
//		long[] costr = new long[k+1];
		long an = 99999999999999l;
		int curcan = 0;
		
		if(dirleft != -1)
		for(int i = dirleft; i >= 0 && curcan < k; i--)
		{ //assume we go here first... then go back
			curcan++;
			long curd = -a[i];
			if(curcan < k)
			{
				curd += -a[i];
				if(dirright != -1 && dirright + (k-curcan) - 1 < n)
				{
					curd += a[dirright + (k-curcan) - 1];
					an = Math.min(an, curd);
				}
			}
			else an = Math.min(an, curd);
		}
		curcan = 0;
		
		if(dirright != -1)
		for(int i = dirright; i < n && curcan < k; i++)
		{ //assume we go here first... then go back
			curcan++;
			long curd = a[i];
			if(curcan < k)
			{
				curd += a[i];
				if(dirleft != -1 && dirleft - (k-curcan) + 1 >= 0)
				{
					curd += -a[dirleft - (k-curcan) + 1];
					an = Math.min(an, curd);
				}
			}
			else an = Math.min(an, curd);
		}
		System.out.println(an);
	}

}


Measured memory_bytes: 60484
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define ll long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define pb push_back
#define eb emplace_back
template<class T>void chmax(T &a,T b){if(a<b)a=b;}
template<class T>void chmin(T &a,T b){if(a>b)a=b;}
constexpr int INF=1000000000000000000;
constexpr int mod=1000000007;
constexpr double eps=1e-8;
const double pi=acos(-1);
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int Random(int mi,int ma){
    random_device rnd;
    mt19937 mt(rnd());//32bit
    //[mi,ma]
    uniform_int_distribution<int>engine(mi,ma);
    return engine(mt);
}
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;
}
bool prime(int a){
    if(a==1)return false;
    for(int i=2;i*i<=a;i++){
        if(a%i==0)return false;
    }
    return true;
}
int modpow(int a,int b){
    if(b==0)return 1;
    if(b%2)return modpow(a,b-1)*a%mod;
    int memo=modpow(a,b/2);
    return memo*memo%mod;
}
vector<int>kaijo,invkaijo;
void init_fact(int n){
    kaijo.resize(n+1);
    invkaijo.resize(n+1);
    kaijo[0]=1;
    for(int i=1;i<=n;i++){
        kaijo[i]=kaijo[i-1]*i;
        kaijo[i]%=mod;
    }
    rep(i,n+1)invkaijo[i]=modpow(kaijo[i],mod-2);
}
int comb(int a,int b){
    if(a<b)return 0;
    if(a<0||b<0)return 0;
    return kaijo[a]*invkaijo[a-b]%mod*invkaijo[b]%mod;
}
int inv(int x){
    x=modpow(x,mod-2);
    return x;
}

signed main(){
    cin.tie(0);ios::sync_with_stdio(false);
    string s;
    cin>>s;
    if(s.back()=='s')s+="es";
    else s+="s";
    cout<<s<<endl;
    return 0;
}


Measured memory_bytes: 3664
import java.nio.file.FileSystemLoopException;
import java.text.DecimalFormat;
import java.util.*;

public class Main implements Runnable {

    private static int MOD = 1_000_000_007;

    public static void main(String[] args) {
        // Run with 32MB stack
        Thread thread = new Thread(null, new Main(), "", 32 * 1024 * 1024);
        thread.start();
    }

    @Override
    public void run() {
        final Scanner scanner = new Scanner(System.in);
        solve(scanner);
    }

    static class P {
        int x;
        int y;

        public P(int x, int y) {
            this.x = x;
            this.y = y;
        }

        @Override
        public boolean equals(Object o) {
            if (this == o) return true;
            if (o == null || getClass() != o.getClass()) return false;
            P p = (P) o;
            return x == p.x &&
                    y == p.y;
        }

        @Override
        public int hashCode() {
            return Objects.hash(x, y);
        }
    }

    static void solve(Scanner scanner) {
        int N = Integer.parseInt(scanner.next());
        int[] foo = {111, 222, 333, 444, 555, 666, 777, 888, 999};
        for(int n: foo) {
            if (N <= n) {
                System.out.println(n);
                return;
            }
        }
    }

}


Measured memory_bytes: 24020
# パナソニックプログラミングコンテスト2020
# C - Sqrt Inequality
# https://atcoder.jp/contests/panasonic2020/tasks/panasonic2020_c
(A, B, C) = gets.split.map(&:to_i)

#if Math.sqrt(A*B).to_d < (C - A - B) / 2.to_d
#if Math.sqrt(A) + Math.sqrt(B) < Math.sqrt(C)
d = C-A-B
if d > 0 && 4*A*B < (d)**2
  puts 'Yes'
else
  puts 'No'
end


Measured memory_bytes: 1788
#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 (1ll << 60)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
using vl = vector<ll>;
using vvl = vector<vl>;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
using ll = long long;
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() {
    ll N;
    cin >> N;
    string S;
    cin >> S;
    char before = 'Z';
    ll res = 0;
    for(int i = 0; i < S.length(); i++) {
        if(S[i] != before) {
            before = S[i];
            res++;
        }
    }
    cout << res << endl;
}

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

int main(){
    ll n;
    cin>>n;

    ll res = 0;
    map<ll,int> mp;
    for(ll i = 2; i*i <= n; i++){
        if((n)%i == 0){
            ll t = n;
            while(t%i==0) t/=i;
            if(t%i == 1){
                mp[i] = 1;
                res++;
            } 
            ll tt = n/i;
            t = n;
            while(t%tt == 0) t/=tt;
            if(t%tt==1 && !mp[tt]){
                mp[tt] = 1;
                res++;
            }
        }
    }
    
    for(ll i = 2; i*i <= n-1; i++){
        if((n-1)%i == 0 && !mp[i]){
            mp[i] = 1;
            res++;
            ll tt = (n-1)/i;
            if(!mp[tt]){
                mp[tt] = 1;
                res++;
            }
        }
    }
    if(n == 2) cout<<1;
    else cout<<res+2;
}


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

#define pb push_back
#define mp make_pair
#define loop1(x,s,e) for(int x=s;x!=e;x+=1-2*(s>e))
#define input_matrix(a,m,n) for(int i=0;i<m;i++)for(int j=0;j<n;j++)cin>>a[i][j];
#define input_array(a,n) for(int i=0;i<n;i++)cin>>a[i];
#define all(x) x.begin(),x.end()
#define newl "\n"
#define tests(t) int t; cin>>t; while(t--)
#define speed ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
//########################################################################



int main()
 {
	int n; cin>>n;
	vector<int>dp(3),c(3);
	for(int i=0;i<3;i++)cin>>dp[i];
	
	for(int i=1;i<n;++i)
	{
	    for(int j=0;j<3;++j){ cin>>c[j];}
	    vector<int> dp1(3,0);
	    for(int j=0;j<3;++j)
	    {
	        for(int k=0;k<3;++k)
	        {
	            if(j==k)continue;
	            dp1[j]=max(dp1[j],dp[k]+c[j]);
	        }
	    }
	    dp=dp1;
	}
    cout<<max({dp[0],dp[1],dp[2]});
	return 0;
}

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

const double PI = acos(-1);
const double EPS = 1e-15;
using ll = long long;
using ull = unsigned long long;
const int inf = 2e9;
const ll INF = 2e18;
const ll MOD = 1e9+7;
const ll MOD1 = 998244353;
//typedef pair<int,int> P;

#define REP(i,n) for (int i = 0; i < (n); i++)
#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second
//#define mp make_pair

class MaxFlow{
public:
  struct edge{int to, rev, cap;};

  const int INF = 2e9;
  static const int MAX_V = 100010;

  vector<edge> G[MAX_V];
  bool used[MAX_V] = {};
  void add_edge(int frm, int to, int cap) {
    G[frm].push_back((edge){to, G[to].size(), cap});
    G[to].push_back((edge){frm, G[frm].size() - 1, 0});
  }
  int dfs(int frm, int to, int flow) {
    if (frm == to) return flow;
    used[frm] = 1;
    for (int i = 0; i < G[frm].size(); i++) {
      edge &e = G[frm][i];
      if (!used[e.to] && e.cap > 0) {
        int d = dfs(e.to, to, min(flow, e.cap));
        if (d > 0) {
          e.cap -= d;
          G[e.to][e.rev].cap += d;
          return d;
        }
      }
    }
    return 0;
  }
  int maxflow(int s, int t) {
    int flow = 0;
    while (1) {
      memset(used, 0, sizeof(used));
      int f = dfs(s, t, INF);
      if (f == 0) return flow;
      flow += f;
    }
  }
};


vector<int> G[100010];
int n,m;
int n6, n4;
int p1, p2;
int cnt[100010];

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

  MaxFlow mf;

  cin >> n >> m;
  REP(i,m) {
    int a,b;
    cin >> a >> b;
    G[a].pb(b);
    G[b].pb(a);
    mf.add_edge(a,b,1);
    mf.add_edge(b,a,1);
    cnt[a]++;
    cnt[b]++;
  }

  REP(i,n) {
    if (cnt[i+1] & 1) {
      cout << "No" << endl;
      return 0;
    }
    if (cnt[i+1] >= 6) n6++;
    if (cnt[i+1] == 4) {
      n4++;
      p1 = p2;
      p2 = i+1;
    }
  }

  if (n6 != 0 || n4 >= 3) {
    cout << "Yes" << endl;
    return 0;
  }
  if (n4 != 2) {
    cout << "No" << endl;
    return 0;
  }

  if (mf.maxflow(p1,p2) == 2) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 16512
#include <iostream>
using namespace std;
#include <string>
#include <vector>
int main(){
int x;
  cin >> x;
  long long int a,b;
  for(int i = 0; i <= 1000; i++){
    for(int j = 0;j <= 2000; j++){
      a=i;b=j-1000;
      for(int k = 1; k < 5; k++){
        a*=i;b*=(j-1000); 
    }
    if(a-b==x){
      cout << i << " " << j-1000 << endl;
    return 0;
    }
    }
  }
}

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

#define mod 1000000007

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

using namespace std;
typedef long long ll;
const long long INF = 1LL << 60;
int N;
ll W, dp[110][100100], w[110], v[110];

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
 
int main(void){
	
	cin >> N >> W;
	
	rep(i, N)
		cin >> w[i] >> v[i];
		
	rep(i, 110)
		rep(j, 100100)
			dp[i][j] = INF;
			
	dp[0][0] = 0;
	
	rep(i, N){
		rep(sum_v, 100100){
			if(sum_v - v[i] >= 0)
				chmin(dp[i+1][sum_v], dp[i][sum_v - v[i]] + w[i]);
			chmin(dp[i+1][sum_v], dp[i][sum_v]);
		}
	}
	
	ll ans = 0;
	rep(sum_v, 100100)
		if(dp[N][sum_v] <= W)
			ans = sum_v;
		
	cout << ans;
	
	return 0;
}

Measured memory_bytes: 86272
//Zory-2019
#include<cmath>
#include<ctime>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<map>
#include<set>
#include<queue>
#include<deque>
#include<stack>
#include<bitset>
#include<vector>
#include<algorithm>
#include<iostream>
#include<deque>
// #include<unordered_map>
using namespace std;
int bin[40],lg[1<<21];
namespace mine
{
	typedef long long ll;
	#define double long double
	const int INF=0x3f3f3f3f;
	const ll LLINF=0x3f3f3f3f3f3f3f3fll;
	ll qread()
	{
		ll ans=0;char c=getchar();int f=1;
		while(c<'0' or c>'9') {if(c=='-') f=-1;c=getchar();}
		while('0'<=c and c<='9') ans=ans*10+c-'0',c=getchar();
		return ans*f;
	}
	void write(ll num)
	{
		if(num<0) {num=-num;putchar('-');}
		if(num>9) write(num/10);
		putchar('0'+num%10);
	}
	void writeln(int num){write(num);puts("");}
	#define FR first
	#define SE second
	#define MP make_pair
	#define pr pair<int,int>
	#define PB push_back
	#define vc vector
	inline void chmax(int &x,const int y) {x=x>y?x:y;}
	inline void chmin(int &x,const int y) {x=x<y?x:y;}
	const int MAX_N=2e5+10;
	const int MOD=1e9+7;
	void add(int &x,int y) {x+=y;if(x>=MOD) x-=MOD;if(x<0) x+=MOD;}

	int inv[MAX_N],fac[MAX_N],facinv[MAX_N];
	int C(int n,int m) {return (ll)fac[n]*facinv[m]%MOD*facinv[n-m]%MOD;}
	int f[5100][5100];
	#define F(i,j) (f[(i)+2100][(j)+2100])
	int a[MAX_N],b[MAX_N];
	void main()
	{
		inv[1]=1;for(int i=2;i<MAX_N;i++) inv[i]=ll(MOD-MOD/i)*inv[MOD%i]%MOD;
		fac[0]=1;for(int i=1;i<MAX_N;i++) fac[i]=(ll)fac[i-1]*i%MOD;
		facinv[0]=1;for(int i=1;i<MAX_N;i++) facinv[i]=(ll)facinv[i-1]*inv[i]%MOD;

		int n=qread(),ans=0;
		for(int i=1;i<=n;i++)
		{
			a[i]=qread(),b[i]=qread();
			add(ans,MOD-C(2*a[i]+2*b[i],2*a[i]) );
			F(-a[i],-b[i])++;
		}
		for(int i=-2000;i<=2000;i++) for(int j=-2000;j<=2000;j++) add(F(i+1,j),F(i,j)),add(F(i,j+1),F(i,j));
		for(int i=1;i<=n;i++) add(ans,F(a[i],b[i]));
		write((ll)ans*inv[2]%MOD);
	}
};
int main()
{
	srand(time(0));
	bin[0]=1;for(int i=1;i<=30;i++) bin[i]=bin[i-1]<<1;
	lg[1]=0;for(int i=2;i<(1<<21);i++) lg[i]=lg[i>>1]+1;
	mine::main();
}


Measured memory_bytes: 94976
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <math.h>

using namespace std;

typedef long long ll;

string beautify(string str) {
	string ret = "";
	for (int i = 0; i < str.size(); ++i) {
		char c = str[i];
		if ('a' <= c && c <= 'z') ret += c;
		else if ('A' <= c && c <= 'Z') ret += (char)(c-'A'+'a');
	}
	return ret;
}

class Dice {
private:
	int v[6];

public:
	int GetTop() {
		return v[0];
	}
	int GetFront() {
		return v[1];
	}
	int GetRight() {
		return v[2];
	}
	void Rotate(char op) {
		int newV[6];
		switch (op) {
		case 'N':
			newV[0] = v[1];
			newV[1] = v[5];
			newV[2] = v[2];
			newV[3] = v[3];
			newV[4] = v[0];
			newV[5] = v[4];
			break;

		case 'S':
			newV[0] = v[4];
			newV[1] = v[0];
			newV[2] = v[2];
			newV[3] = v[3];
			newV[4] = v[5];
			newV[5] = v[1];
			break;

		case 'E':
			newV[0] = v[3];
			newV[1] = v[1];
			newV[2] = v[0];
			newV[3] = v[5];
			newV[4] = v[4];
			newV[5] = v[2];
			break;

		case 'W':
			newV[0] = v[2];
			newV[1] = v[1];
			newV[2] = v[5];
			newV[3] = v[0];
			newV[4] = v[4];
			newV[5] = v[3];
			break;
		}
		for (int i = 0; i < 6; ++i) v[i] = newV[i];
	}
	void Spin(char op) {
		switch (op) {
		case 'R':
			Rotate('N');
			Rotate('E');
			Rotate('S');
			break;

		case 'L':
			Rotate('N');
			Rotate('W');
			Rotate('S');
			break;
		}
	}
	Dice(int v1, int v2, int v3, int v4, int v5, int v6) {
		v[0] = v1;
		v[1] = v2;
		v[2] = v3;
		v[3] = v4;
		v[4] = v5;
		v[5] = v6;
	}
};

int main() {
	int v[6];
	for (int i = 0; i < 6; ++i) cin >> v[i];
	Dice dice(v[0], v[1], v[2], v[3], v[4], v[5]);

	int n; cin >> n;
	for (int q = 0; q < n; ++q) {
		int t, f; cin >> t >> f;
		int v = -1;
		for (int k = 0; k < 4; ++k) {
			for (int i = 0; i < 4; ++i) {
				for (int j = 0; j < 4; ++j) {
					if (dice.GetTop() == t && dice.GetFront() == f) {
						v = dice.GetRight();
						break;
					}
					dice.Rotate('N');
				}
				if (v != -1) break;
				dice.Spin('R');
			}
			if (v != -1) break;
			dice.Rotate('E');
		}
		cout << v << endl;
	}
}


Measured memory_bytes: 3056
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll dp[3005][3005];
ll solve(int s,int e,vector<ll>&arr){
    
    if(s==e)return arr[s];
    if(dp[s][e]!=-1)return dp[s][e];
    return dp[s][e]=max(arr[e]-solve(s,e-1,arr),arr[s]-solve(s+1,e,arr));
    
}

int main(){
    int n;
    cin>>n;
    vector<ll> arr(n);
    for(ll &i : arr){
        cin>>i;
    }
    for(int i=0;i<=n;i++){
        for(int j=0;j<=n;j++){
            dp[i][j]=-1;
        }
    }
    cout<<solve(0,n-1,arr)<<endl;
}

Measured memory_bytes: 74340