akhauriyash/Code-Regression huggingface dataset:
/*betaでやろう*/
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <iterator>
#include <cstring>

using namespace std;

typedef pair<int, int> P;
typedef long long ll;
#define PB push_back
#define rep(i, a) for(ll i = 0; i < a; i++)
#define all(v) v.begin(),v.end()
#define FF first
#define SS second
#define mp make_pair
#define INT int_64
const ll INF = 1e17;
const ll NEGA=-INF; 

int a[502][502];
int f[502][502];
int main()
{ 
  int h,w;
  cin>>h>>w;
  rep(i,h) rep(j,w){
      cin>>a[i][j];
      if(a[i][j]%2) f[i][j]=1;
  }

int count=0;
int cha=-1,rel=0;
int j;
int pp=0;
 rep(i,h) {
    if(i%2==0) j=0;
     else j=w-1;
     while(j>=0&&j<w)
 {
     if(f[i][j]==1){
      if(cha==-1) cha=pp;
      else {
          count+=pp-cha;
          cha=-1;
      }
     }
  if(i%2==0) j++;
  else j--;
  pp++;
 }
 }
 cout<<count<<endl;
 int pox,poy;
 int inmu=0;
 rep(i,h) {
    if(i%2==0) j=0;
     else j=w-1;
     while(j>=0&&j<w)
 {
     if(rel==0){
         if(f[i][j]==1) {
             rel=1;
             pox=i+1,poy=j+1;
     } 
     }
     else{
       if(f[i][j]==1) rel=0;
       cout<<pox<<" "<<poy<<" "<<i+1<<" "<<j+1<<endl;
       pox=i+1,poy=j+1;
       inmu++;
     }
     
  if(i%2==0) j++;
  else j--;
  if(inmu>=count) break;
  }
    if(inmu>=count) break;
 }

}



Measured memory_bytes: 4096
use std::cmp::max;
use std::io::stdin;
fn main() {
    let (n, w_max) = read();
    let goods: Vec<(usize, usize)> = (0..n).map(|_| read()).collect();
    let mut dp: Vec<Vec<usize>> = vec![vec![0; w_max + 1]];
    for i in 1..n + 1 {
        let dpi = (0..w_max + 1)
            .map(|w| {
                if w >= goods[i - 1].1 {
                    max(dp[i - 1][w - goods[i - 1].1] + goods[i - 1].0, dp[i - 1][w])
                } else {
                    dp[i - 1][w]
                }
            })
            .collect();
        dp.push(dpi);
    }
    println!("{}", dp[n][w_max]);
}

fn read() -> (usize, usize) {
    let mut s = String::new();
    stdin().read_line(&mut s).unwrap();
    let mut s = s
        .trim()
        .split_whitespace()
        .map(|s| s.parse::<usize>().unwrap());
    (s.next().unwrap(), s.next().unwrap())
}


Measured memory_bytes: 13116
#include <iostream>
#include <math.h>
#include <string>
#include <algorithm>
using namespace std;
int kaijo(int n){
	int ans = 1;
	if (n != 0){
		for (int i = 0; i < n; i++){
			ans *= (n - i);
		}
	}
	else{
		ans = 1;
	}
	return ans;
}

int main(){
	int a, b;
	cin >> a;
	cin >> b;
	cout << (a - 1)*(b - 1) << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<iomanip>

using namespace std;

typedef long long ll;

typedef std::pair<int, int> ipair;
bool lessPair(const ipair& l, const ipair& r){return l.second < r.second;}
bool morePair(const ipair& l, const ipair& r){return l.second > r.second;}

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;
}

const ll MOD = 1e9 + 7;
// const long long INF = 1LL<<60;
void add(long long &a, long long b) { a += b; if (a >= MOD) a -= MOD; }
void sub(long long &a, long long b) { a -= b; if (a < 0) a += MOD; }
void mul(long long &a, long long b) { a *= b; a %= MOD; }
ll llmin(ll a, ll b) { if (a < b) return a; else return b; }
ll llmax(ll a, ll b) { if (a < b) return b; else return a; }
ll llabs(ll a) { if (a >= 0) return a; else return - a; }
ll llmodpow(ll a, ll n) {
   if (n == 0) return 1;
   ll tmp = llmodpow(a, n / 2);
   mul(tmp, tmp);
   if (n & 1) mul(tmp, a);
   return tmp;
}

int main() {
   int N, M;
   cin >> N >> M;
   map<int, int> log;
   vector<int> nlog;
   int a, b;
   for (int i = 0; i < M; i++) {
      cin >> a >> b;
      if (a == 1) log[b] = 1;
      if (b == N) nlog.push_back(a);
   }
   for (auto& n : nlog) {
      if (log[n] == 1) {
         cout << "POSSIBLE" << endl;
         return 0;
      }
   }
   cout << "IMPOSSIBLE" << endl;
   return 0;
}


Measured memory_bytes: 9976
use proconio::{fastout, input};
 
#[fastout]
fn main() {
  input! {
    n: usize,
    mut a: [i128;n],
  }
  a.sort();
  let ans: i128 = if a[0] == 0 {
    0
  }
  else {
    let mut prod: i128 = 1;
    for v in a {
      prod = prod * v;
      prod = if prod > 1_000_000_000_000_000_000 {
        prod = -1;
        break;
      }
      else {
        prod
      }
    }
    prod
  };
  println!("{}", ans);
}

Measured memory_bytes: 6144
//ABC154C.cpp

#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;

int main(){
	int N;
	vector<int> A;
	cin>>N;
	for(int i=0;i<N;i++){
		int a;
		cin>>a;
		A.push_back(a);
	}
	sort(A.begin(),A.end());
	bool judge=false;
	for(int i=1;i<N;i++){
		if(A[i-1]==A[i]){
			judge=true;
			break;
		}
	}
	if(judge){
		cout<<"NO"<<endl;
	}else{
		cout<<"YES"<<endl;
	}
}

Measured memory_bytes: 1400
#include <iostream>
#include <fstream>
#include <cmath>  
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <numeric>
#include <functional>
#include <string> 
#include <vector>
#include <bitset>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>

using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define REP(i,n) for(int i = 0; i < int(n); i++)
#define REREP(i,n) for(int i = int(n - 1); i >= 0; i--)
#define FOR(i, m, n) for(int i = int(m);i < int(n);i++)
#define REFOR(i, m, n) for(int i = int(n - 1);i >= int(m);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define fi first 
#define se second

#define VI vector<int>
#define VVI vector<vector<int>>
#define VVVI vector<vector<vector<int>>>
#define VD vector<double>
#define VVD vector<vector<double>>
#define VVVD vector<vector<vector<double>>>
#define VL vector<ll>
#define VVL vector<vector<ll>>
#define VVVL vector<vector<vector<ll>>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define VVVB vector<vector<vector<bool>>>
#define VS vector<string>
#define VVS vector<vector<string>>
#define VVVS vector<vector<vector<string>>>

#define PII pair<int,int>
#define PDD pair<double,double>
#define PLL pair<ll,ll>
#define VPII vector<pair<int,int>>
#define VVPII vector<vector<pair<int,int>>>
#define VVVPII vector<vector<vector<pair<int,int>>>>
#define VPLL vector<pair<ll,ll>>
#define VVPLL vector<vector<pair<ll,ll>>>
#define VVVPLL vector<vector<vector<pair<ll,ll>>>>

const ll MOD = (ll)1e9 + 7;
const ll HINF = (ll)1e18;
const ll LINF = (ll)1e9;
const long double PI = 3.1415926535897932384626433;


void YN(bool flag) {
	cout << ((flag) ? "YES" : "NO") << endl;
}

void Yn(bool flag) {
	cout << ((flag) ? "Yes" : "No") << endl;
}

void yn(bool flag) {
	cout << ((flag) ? "yes" : "no") << endl;
}

int main() {
int H,W;
cin >> H >> W;
VVI a(H,VI(W));
REP(i,H)REP(j,W)cin>>a[i][j];
VI s,t,u,v;

REP(i,H){
int x,y;

if(i%2==0){

REP(j,W){
if(i==H-1&&j==W-1)break;
if(j!=W-1){
y=i;
x=j+1;
}
else{
y=i+1;
x=j;
}
if(a[i][j]%2==1){
a[i][j]--;
a[y][x]++;
s.push_back(i);
t.push_back(j);
u.push_back(y);
v.push_back(x);
}
  
}

}

else{

for(int j=W-1;j>=0;j--){
if(i==H-1&&j==0)break;
if(j!=0){
y=i;
x=j-1;
}
else{
y=i+1;
x=j;
}
if(a[i][j]%2==1){
a[i][j]--;
a[y][x]++;
s.push_back(i);
t.push_back(j);
u.push_back(y);
v.push_back(x);
}
  
 }

}
  
  
 }
cout<<s.size()<<endl;
REP(i,s.size()) cout <<s[i]+1<<" "<<t[i]+1<<" "<<u[i]+1<<" "<<v[i]+1<<endl;











	return 0;
}



Measured memory_bytes: 5224
using System;
using System.Collections.Generic;
using System.Linq;
class Program
 {
        static void Main(string[] args)
        {
        　　int N;
            N = int.Parse(Console.ReadLine()); //標準入力
            int[] A = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            int[] B = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            long count = 0;
            for(int i=0; i < N; i++)
            {
                int diffFirst = B[i] - A[i];
                if(diffFirst > 0)
                {
                    int diffSecond = A[i + 1] - diffFirst;
                    if(diffSecond > 0)
                    {
                        count += B[i];
                        A[i + 1] = diffSecond;
                    }
                    else{
                        count += A[i] + A[i + 1];
                        A[i + 1] = 0;
                    }
                }
                else
                {
                    count += B[i];
                }
                
            }
            Console.Write(count);
        }
 }

Measured memory_bytes: 36380
#include <iostream>

using namespace std;

int main(){
  int a,b,c,d,e,k;
  cin >> a;
  cin >> b;
  cin >> c;
  cin >> d;
  cin >> e;
  cin >> k;

  if(e-a>k){
    cout << ":(";
  }
  else if(e-b>k){
    cout << ":(";
  }
  else if(e-c>k){
    cout << ":(";
  }
  else if(e-d>k){
    cout << ":(";
  }
  else{
    cout << "Yay!";
  }
  cout <<"\n";
  return 0;
}


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

using namespace std;

bool rec(vector<int> &v, int level) {
    if(level == 5) return true;
    //ª
    if(level == 0) {
        for(int i = 0; i < v.size(); ++i) {
            if(v[i] >= 2) {
                v[i] -= 2;
                if(rec(v, level+1)) return true;
                v[i] += 2;
            }
        }
    }
    else {
        //q
        for(int i = 0; i < v.size()-2; ++i) {
            if(v[i] >= 1 && v[i+1] >= 1 && v[i+2] >= 1) {
                v[i]--; v[i+1]--; v[i+2]--;
                if(rec(v, level+1)) return true;
                v[i]++; v[i+1]++; v[i+2]++;
            }
        }
        //q
        for(int i = 0; i < v.size(); ++i) {
            if(v[i] >= 3) {
                v[i] -= 3;
                if(rec(v, level+1)) return true;
                v[i] += 3;
            }
        }
    }
    return false;
}

bool check(const vector<int> &v) {
    vector<int> tmp = v;
    return rec(tmp, 0);
}


int main() {
    string line;
    while(cin >> line) {
        vector<int> cnt(9, 0);
        for(int i = 0; i < line.size(); ++i)
            cnt[line[i]-'1']++;
        vector<int> v;
        for(int i = 1; i <= 9; ++i) {
            if(cnt[i-1] == 4) continue;
            cnt[i-1]++;
            if(check(cnt)) v.push_back(i);
            cnt[i-1]--;
        }
        if(v.size() == 0) v.push_back(0);
        for(int i = 0; i < v.size(); ++i) {
            if(i > 0) cout << ' ';
            cout << v[i];
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <algorithm>
#include <fstream>
#include <string>
#include <math.h>
#include <cstdlib>
#include <istream>
#include <sstream>
#include <cctype>
using namespace std;
int main()
{
	int r;
	cin >> r;

	if(r<1200){
		cout << "ABC" << endl;
	}
	else if(r<2800){
		cout << "ARC" << endl;
	}
	else{
		cout << "AGC" << endl;
	}

}

Measured memory_bytes: 256
// --------------------<optimizations>--------------------
#pragma GCC optimize("O3")
//(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)
#pragma comment(linker, "/stack:200000000")
//(UNCOMMENT WHEN TRYING TO BRUTEFORCE WITH A LOT OF LOOPS)
#pragma GCC optimize("unroll-loops")
// -------------------</optimizations>--------------------
 
#include <bits/stdc++.h>
 
using namespace std;
 
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define f first
#define s second
#define sz(x) int(x.size())
#define endl '\n'
#define forn(i,n) for(int i=0;i<n;++i)
#define fore(i,l,r) for(int i=int(l);i<=int(r);++i)
#define rep(i,begin,end) for(__typeof(end) i=(begin);i!=(end);i++)
#define fill(a,value) memset(a,value,sizeof(a));
#define SIZE 26     
#define watch1(x) cout << (x) << endl
#define watch2(x,y) cout << (x) << " " << (y) << endl
#define watch3(x,y,z) cout << (x) << " " << (y) << " " << (z) << endl
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
 
typedef long long ll;
typedef long double ld; 
typedef pair<ll,ll> pii;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
 
const ll mod = 1e9 + 7;
const int inf = 1e9 + 5;
const int N = 1e5 + 5;
 
signed main(){
    fastio;
    string a,b,s,t;
    cin>>a>>b;
    int x=a[0]-'0';
    int y=b[0]-'0';
    while(y--) s+=a;
    while(x--) t+=b;
    if(s<=t) cout<<s;
    else cout<<t;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<queue>
using namespace std;
int w,h;
string map[40];
int vec[4][2]={{0,1},{0,-1},{-1,0},{1,0}};

struct pos{
	pos(int X,int Y){
		x=X,y=Y;
	}
	int x,y;
};

int move(int x,int y){
	int ans=0;
	map[x][y]='#';
	queue<pos> dfs;
	dfs.push(pos(x,y));
	while(!dfs.empty()){
		pos n=dfs.front();dfs.pop();
		x=n.x;
		y=n.y;
		////
		ans++;
		for(int i=0;i<4;i++){
			if((x+vec[i][0]>=0)&&(y+vec[i][1]>=0)&&(x+vec[i][0]<h)&&(y+vec[i][1]<w)){
				if(map[x+vec[i][0]][y+vec[i][1]]=='.'){
					map[x+vec[i][0]][y+vec[i][1]]='#';
					dfs.push(pos(x+vec[i][0],y+vec[i][1]));
				}
			}
		}
		/////
	}
	
	
	return ans;
}

int main(){
	while(cin>>w>>h,w){
		int fx,fy;
		for(int i=0;i<h;i++){
			cin>>map[i];
		}
		for(int i=0;i<h;i++){
			for(int j=0;j<w;j++){
				if(map[i][j]=='@'){
					fx=i;
					fy=j;
					break;
				}
			}
		}
		int ans=move(fx,fy);
		cout<<ans<<endl;
		
	}
}

Measured memory_bytes: 1228
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto&(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

vector<pair<char, ll>> RunLengthCompression(const string& s) {
  ll cur = 1;
  ll n = SZ(s);
  vector<pair<char, ll>> run;
  REP(i, n - 1) {
    if (s[i] == s[i + 1]) {
      cur++;
      continue;
    }
    run.push_back(make_pair(s[i], cur));
    cur = 1;
  }
  run.push_back(make_pair(s[n - 1], cur));
  return run;
}

int main() {
  ll n;
  cin >> n;
  string s;
  cin >> s;
  ll ans = SZ(RunLengthCompression(s));
  cout << ans << endl;
}

Measured memory_bytes: 2548
#include <stdio.h>

int grow[2000][2000];

int main(void){

    int i, j, k, h, w, prev, max_grow;
    char field[2000][2000];


    scanf("%d %d ", &h, &w);
    for(i = 0; i < h; i++){
        scanf("%s", field[i]); 
    }

    for(i = 0; i < h; i++){
        for(j = 0; j < w; j++){
            if(field[i][j] == '.'){
                prev = j;
                while(j < w && field[i][j] == '.'){
                    j++;
                }
                for(k = prev; k < j; k++){
                    grow[i][k] = j - prev;
                }
            }
        }
    }
    
    for(j = 0; j < w; j++){
        for(i = 0; i < h; i++){
            if(field[i][j] == '.'){
                prev = i;
                while(i < h && field[i][j] == '.'){
                    i++;
                }
                for(k = prev; k < i; k++){
                    grow[k][j] += (i - prev);
                }
            }
        }
    }
	
    for(i = 0; i < h; i++){
        for(j = 0; j < w; j++){
            if(max_grow < grow[i][j]){
                max_grow = grow[i][j];
            }
        }
    }
    
    printf("%d", max_grow - 1);

    return 0;
}

Measured memory_bytes: 19712
N,M = map(int,input().split())
S = input()
T = input()

def gcd(x, y):
    while y > 0:
        x, y = y, x%y
    return x
 
def lcm(x, y):
    return int(x/gcd(x, y)*y)

lenx = lcm(N,M)

s_list = list(S)
t_list = list(T)

baisuu_s = int(lenx/N)
baisuu_t = int(lenx/M)
def check():
    for i in range(0,lenx,baisuu_s):
        if i % baisuu_s==0 and i%baisuu_t == 0:
            if s_list[int(i/baisuu_s)] == t_list[int(i/baisuu_t)]:
                pass
            else:
                return False
    return True

if check():
    print(lenx)
else:
    print(-1)

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

int main()
{
    int A = 0;
    int B = 0;

    cin >> A >> B;

    if (A - 2 * B < 0)
    {
        cout << 0 << endl;
    }
    else
    {
        cout << A - 2 * B << endl;
    }
}


Measured memory_bytes: 256
# coding: utf-8
# Your code here!

box = input().rstrip().split()

#文字数が５だったらＦ+1、７だったらＳ+1で最終的にＦ＝２．Ｓ＝１なら正解
F = 0
S = 0

for i in range(len(box)):
    if int(box[i]) == 5:
        F = F + 1
    elif int(box[i]) == 7:
        S = S + 1
    
if (F == 2 and S == 1):
    print("YES")
else:
    print("NO")

Measured memory_bytes: 3060
package main

import "fmt"

func main() {
	var N, M, C int
	fmt.Scan(&N, &M, &C)
	ans := 0
	B := make([]int, M)
	A := make([]int, M)
	for i := range B {
		fmt.Scan(&B[i])
	}
	sum := 0
	for i := 0; i < N; i++ {
		sum = 0
		for x := 0; x < M; x++ {
			fmt.Scan(&A[x])
			sum = sum + A[x] * B[x]
		}
		if (sum + C) > 0 {
			ans++
		}
	}
	fmt.Println(ans)
}

Measured memory_bytes: 512
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
typedef long long ll;
using namespace std;

int main(){
    int n,m,ans=0;
    cin>>n>>m;
    vector<vector<int>> v(m+1);
    vector<int> vv(m+1);
    for(int i=1;i<=m;i++){
        int x,y;cin>>x;
        while(x--) {
            cin>>y;v[i].push_back(y);
        }
    }
    for(int i=1;i<=m;i++) cin>>vv[i];
    for(int i=0;i<(1<<n);i++){
        int t=i;bool b=1;
        vector<bool> tmp(n+1);
        for(int j=1;j<=n;j++) {
            tmp[j]=t&1;t>>=1;
        }
        for(int j=1;j<=m;j++){
            t=0;
            for(auto k:v[j]) t+=tmp[k];
            if((t&1)!=vv[j]) {b=0;break;}
        }
        if(b) ans++;
    }
    cout<<ans;
}

Measured memory_bytes: 384
#include<iostream>
#include<iomanip>
#include<functional>
#include<algorithm>
#include<cstring>
#include<string>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<vector>
#include<utility>
#include<bitset>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
using namespace std;
const int inf=2147483647,dx[]={-1,0,1,0},dy[]={0,-1,0,1};// 上 左 下 右
const int N=100005,M=1000005,mod=1000000007;
const long long llinf=9223372036854775807ll;
//int & long long
int n,m,d[2005][2005][4],ans;
char a[2005][2005];
int main(){
	ans=-999999;
	cin>>n>>m;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			cin>>a[i][j];
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
			if(a[i][j]=='.')
				d[i][j][0]=d[i][j-1][0]+1;
			else
				d[i][j][0]=0;
		for(int j=m;j>=1;j--)
			if(a[i][j]=='.')
				d[i][j][1]=d[i][j+1][1]+1;
			else
				d[i][j][1]=0;
	}
	for(int i=1;i<=m;i++)
	{
		for(int j=1;j<=n;j++)
			if(a[j][i]=='.')
				d[j][i][2]=d[j-1][i][2]+1;
			else
				d[j][i][2]=0;
		for(int j=n;j>=1;j--)
			if(a[j][i]=='.')
				d[j][i][3]=d[j+1][i][3]+1;
			else
				d[j][i][3]=0;
	}
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			ans=max(ans,d[i][j][0]+d[i][j][1]+d[i][j][2]+d[i][j][3]-3);
	cout<<ans;
	return 0;
}

Measured memory_bytes: 66816
while True:
    n=input()
    if n==0:break
    L=[map(int,list(raw_input())) for i in range(n)]
    Q=[[] for i in range(2*n-1)]
    for i in range(n):
        for j in range(n):
            Q[i+j].append((i,j))

    P=[[] for i in range(2*n-1)]
    for i in range(n):
        for j in range(n-1,-1,-1):
            P[(n-1)-i+j].append((i,j))

    maxInt=0
    for i in range(n):
        cnt=0
        for j in range(n):
            if L[i][j]==1:
                cnt+=1
            else:
                cnt=0
            maxInt=max(cnt,maxInt)
    for i in range(n):
        cnt=0
        for j in range(n):
            if L[j][i]==1:
                cnt+=1
            else:
                cnt=0
            maxInt=max(cnt,maxInt)
    for p in P:
        cnt=0
        for i,j in p:
            if L[i][j]==1:
                cnt+=1
            else:
                cnt=0
            maxInt=max(cnt,maxInt)
    for q in Q:
        cnt=0
        for i,j in q:
            if L[i][j]==1:
                cnt+=1
            else:
                cnt=0
            maxInt=max(cnt,maxInt)
    print maxInt

Measured memory_bytes: 15844
N, X, M = map(int, input().split())

existence = [False] * M
a = []
A = X
for i in range(N):
    if existence[A]:
        break
    existence[A] = True
    a.append(A)
    A = A * A % M

for i in range(len(a)):
    if a[i] == A:
        loop_start = i
        break
else:
    loop_start = len(a)

result = sum(a[:loop_start])
a = a[loop_start:]
N -= loop_start
if N != 0:
    loops = N // len(a)
    remainder = N % len(a)
    result += sum(a) * loops + sum(a[:remainder])
print(result)


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

using namespace std;

typedef long long ll;

const ll mod=1e9+7;
const ll maxn=2e5+5;


ll inv[maxn];
void getInv(){
	inv[1]=1;
	for(ll i=2;i<maxn;i++){
		inv[i]=(mod-mod/i)*inv[mod%i]%mod;
	}
}

ll qPow(ll a,ll b){
	ll ans=1;
	while(b){
		if(b&1) ans=(ans*a)%mod;
		a=(a*a)%mod;
		b>>=1;
	}
	return ans;
}

ll C(ll x,ll y){
	ll ans=1;
	for(int i=0;i<y;i++)
	{
		ans=(ans*(x-i)%mod*inv[i+1])%mod;
	}
	return ans;
}

int main(){
	getInv();
	ll n,k;
	scanf("%lld%lld",&n,&k);
	ll tmp=min(n-1,k);
	ll ans=0;ll kk=1;ll kk2=1;
	for(ll i=0;i<=tmp;i++){
		ans=(ans+kk*kk2%mod)%mod;
		kk=(kk*(n-i))%mod;
		kk=(kk*inv[i+1])%mod;
		kk2=(kk2*(n-i-1))%mod;
		kk2=(kk2*inv[i+1])%mod;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 1792
#include<stdio.h>
typedef struct{
  int no;
  double a;
}P;
  
int main(){
  int i,n,b,flg,j,k;
  double c,d;
  P temp[4001];
  while(1){
    flg=0;
    for(i=0;i<=4000;i++)temp[i].no=0,temp[i].a=0.0;
    scanf("%d",&n);
    if(n==0)break;

    for(i=0,j=0;i<n;i++,j++){
      scanf("%d %lf %lf",&b,&c,&d);
      c/=1000;
      d/=1000;
      for(k=0,flg=0;k<j;k++){
	if(b==temp[k].no){
	  temp[k].a+=c*d;
	  j--;
	  flg=1;
	}
      }
      if(flg==0){
	temp[j].no=b;
	temp[j].a=c*d;
      }
    }
    for(i=0;i<=j;i++){
      if(temp[i].a>=1.0){
	printf("%d\n",temp[i].no);
	flg=1;
      }
    }
    if(flg==0)printf("NA\n");
  }
  return 0;
}

Measured memory_bytes: 696
#include <stdio.h>

int main(int argc, const char * argv[]){
    int x, y;
    while (1) {
        scanf("%d %d", &x,&y);
        if (x == 0 && y == 0) break;
        for (int i = 0; i < x; i++) {
            for (int j = 0; j < y; j++) {
                if (i == 0 || i == x - 1 || j == 0 || j == y - 1) printf("#");
                else printf(".");
            }
            printf("\n");
        }
        printf("\n");
    }
}


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

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

  int ans = 0;
  for (int i = 1; i <= N; i += 2) {
    int count = 0;
    for (int j = 1; j <= i; ++j) {
      if (i % j == 0)
        ++count;
    }
    if (count == 8)
      ++ans;
  }
  cout << ans << "\n";

  return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <cstdio>
#include <stdlib.h>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
  int n,sum=0,m=1;
  cin>>n;
  for(int i=0;i<3;i++){
    if(n%10==1)sum+=9*m;
    else sum+=1*m;
    m*=10;
    n/=10;
  }
  cout<<sum<<endl;
  return 0;
}


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

ll dp[10000];
const ll INF = 1LL<<60;

int main(){
	ll n,m;
	cin >> n >> m;
	vector<int> value(m);
	vector<int> box(m);
	rep(i,m){
		cin >> value[i];
		int b;
		cin >> b;
		int temp = 0;
		rep(j,b){
			int c; cin >> c; c--;
			temp = temp | (1 << c);
		}
		box[i] = temp;
	}
	rep(i, 1<<n){
		dp[i] = INF;
	}
	dp[0] = 0;
	rep(bit, 1<<n){
		rep(i,m){
			dp[bit | box[i]] = min(dp[bit | box[i]], dp[bit] + value[i]);
		}
	}
	ll ans = dp[(1<<n) - 1];
	if(ans == INF){
		cout << -1 << endl;
	}else{
		cout << ans << endl;
	}
    return 0;
}



Measured memory_bytes: 256
#include<string>
using namespace std;
#include <stdio.h>
#include <limits.h>
#include "bits/stdc++.h"
#include <algorithm>
#include <iostream>
#include <cmath>
int x, y, z, p;
int main() {
	cin >> x;
	for (int i = 1; i < 40; i++) {
		z = std::pow(i, 2.0);
		if (z <= x) {
			y = z;
		}
	}
	for (int j = 1;j < 11;j++) {
		z=std::pow(j, 3.0);
		if (y < z&&z <= x) {
			y = z;
		}
	}
	for (int j = 1;j < 10;j++) {
		z = std::pow(j, 4.0);
		if (y < z&&z <= x) {
			y = z;
		}
	}
	for (int j = 1;j < 10;j++) {
		z = std::pow(j, 5.0);
		if (y < z&&z <= x) {
			y = z;
		}
	}
	for (int j = 1;j < 10;j++) {
		z = std::pow(j, 6.0);
		if (y < z&&z <= x) {
			y = z;
		}
	}
	for (int j = 1;j < 10;j++) {
		z = std::pow(j, 7.0);
		if (y < z&&z <= x) {
			y = z;
		}
	}
	for (int j = 1;j < 10;j++) {
		z = std::pow(j, 8.0);
		if (y < z&&z <= x) {
			y = z;
		}
	}
	for (int j = 1;j < 10;j++) {
		z = std::pow(j, 9.0);
		if (y < z&&z <= x) {
			y = z;
		}
	}
	for (int j = 1;j < 5;j++) {
		z = std::pow(j, 10.0);
		if (y < z&&z <= x) {
			y = z;
		}
	}
	cout << y;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <set>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>

typedef long long int lli;
#define rep(i,s,N) for(int i=s;i<N;i++)
using namespace std;


int main(void)
{
	string s, t; cin >> s >> t;
	vector<string> ans;
	int l = s.size() - t.size() + 1;
	for (int i = 0; i < max(0, l); i++) {
		string tmp = s;
		for (int j = 0; j < t.length(); j++) {
			if (i + j>s.size() - 1) break;
			if (tmp[i + j] == '?' || tmp[i + j] == t[j]) tmp[i + j] = t[j];
			else break;
			if (j == t.length() - 1) {
				for (int k = 0; k < tmp.length(); k++) {
					if (tmp[k] == '?') tmp[k] = 'a';
				}
				ans.push_back(tmp);
			}
		}
	}
	sort(ans.begin(), ans.end());
	cout << (ans.size() > 0 ? ans[0] : "UNRESTORABLE") << endl;

	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"

using namespace std;

using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using i8 = int8_t;
using i16 = int16_t;
using i32 = int32_t;
using i64 = int64_t;

constexpr char newl = '\n';
constexpr double eps = 1e-10;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--)
#define RF0(i,b) RFO(i,0,b)
#define fi first
#define se second
#define debug(x) cout << #x << ": " << x << '\n';
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()

template<typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
template<class T> void Print(vector<T> v) {
  F0R(i, v.size()) {
    cout << v[i] << ' ';
  }
  cout << newl;
}

#if 1

i64 gcd(i64 a, i64 b) { return b ? gcd(b, a % b) : a; }
i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }

template <typename U>
map<U, int> doPrimeFactorization(U n) {

  map<U, int> rs;
  U a = 1;

  while (!(n & 1)) {
    n >>= 1;
    rs[2]++;
  }

  for (U i = 3; i * i <= n; /*NOP*/) {
    auto q = n / i;
    auto r = n - i * q;
    if (r == 0) {
      rs[i]++;
      n = q;
    }
    else {
      i += 2;
    }
  }

  if (n > 1) {
    rs[n]++;
  }

  return move(rs);
}

// INSERT ABOVE HERE
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  i64 A, B;
  cin >> A >> B;
  auto pf = doPrimeFactorization(gcd(A, B));
  cout << (pf.size() + 1);
}
#endif


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
    	Scanner in = new Scanner(System.in);
    	int a = in.nextInt();
    	int b = in.nextInt();
    	int d = a / b;
    	int r = a % b;
    	double f = a / (double)b;
    	System.out.printf("%d %d %.5f",d,r,f);
	}
}

Measured memory_bytes: 17332
#include <bits/stdc++.h>
using namespace std;
#define TRACE(x) x
#define WATCH(x) TRACE( cout << #x" = " << x << endl)
#define PRINT(x) TRACE(printf(x))
#define WATCHR(a, b) TRACE( for(auto c = a; c != b;) cout << *(c++) << " "; cout << endl)
#define WATCHC(V) TRACE({cout << #V" = "; WATCHR(V.begin(), V.end());})
#define rep(i, a, b) for(int i = (a); (i) < (b); ++(i))
#define trav(a, x) for(auto& a : x)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) static_cast<int>(x.size())
#define mp make_pair
#define fi first
#define se second

using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;
using vll = vector<ll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

void buff() { ios::sync_with_stdio(false); cin.tie(nullptr); }

constexpr ll MOD = 1e9 + 7;

inline ll pow_mod(ll a, ll b, ll mod = MOD) {
    ll res = 1; a %= mod; assert(b >= 0);
    for(;b;b>>=1) {
        if(b & 1) res = (res * a) % mod;
        a = (a * a) % mod;
    }
    return res;
}

template<typename T> inline void remin(T& x, const T& y) { x = min(x, y); }
template<typename T> inline void remax(T& x, const T& y) { x = max(x, y); }

template<typename T> ostream& operator<<(ostream &os, const vector<T>& v) {
    os << "{"; string sep; for(const auto& x : v) os << sep << x, sep = ", "; return os << "}"; 
}

template<typename T, size_t size> ostream& operator<<(ostream& os, const array<T, size>& arr) {
    os << "{"; string sep; for(const auto& x : arr) os << sep << x, sep = ", "; return os << "}"; 
}

template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { 
    return os << '(' << p.first << ", " << p.second << ')'; 
}

int main() {
    buff();
    int n, m;
    cin >> n >> m;
    vector< set<int> > g(n);
    for(int i = 0; i < m; ++i) {
        int u, v;
        cin >> u >> v;
        --u; --v;
        g[u].insert(v);
        g[v].insert(u);
    }
    
    map<int, int> cc_size;
    vector<int> cc(n, -1); 
    int cur_cc = 0;

    function<void(int, int)> dfs = [&] (int root, int parent) {
        if(parent == -1) {
            cc[root] = cur_cc;
            cur_cc++;
        }
        else cc[root] = cc[parent];
        cc_size[cc[root]]++; 
        for(const auto& v : g[root]) {
            if(cc[v] == -1) {
                dfs(v, root);
            }
        } 
    };
    for(int i = 0; i < n; ++i) if(cc[i] == -1) dfs(i, -1);
    int ans = -1;
    for(const auto& par : cc_size) remax(ans, par.second);
    cout << ans << '\n';
    return 0;
}



Measured memory_bytes: 50928
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define print(n) cout << n << endl
#define in(v) int v; cin >> v
#define vint vector<int>
#define pb push_back
typedef long long int ll;

int main(){
  string s,t;
  cin>>s>>t;
  rep(i,s.size()){
    if(s.at(i)!=t.at(i)){
      print("No");
      return 0;
    }
  }
  print("Yes");
  return 0;
}

Measured memory_bytes: 3632
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <algorithm>

#include <bits/stdc++.h>
#include <cmath>
#include <limits>

using namespace std;
typedef long long LL;

LL GCD(LL x, LL y){
        LL r=0;

        if( x<y ) swap(x, y);
        r = x % y;
        while(r!=0){
                x = y;
                y = r;
                r = x % y;
        }
        return y;
}

long long dp[202][202] = {0};
LL dpGCD(LL x, LL y){
	if(dp[x][y] != 0) return dp[x][y];
	long long ret = GCD(x, y);
	dp[x][y] = ret;
	dp[y][x] = ret;
	return ret;
}

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

	long long K;
	cin >> K;

	long long ans = 0;
	for(int a=1; a<=K; a++){
		for(int b=1; b<=K; b++){
			for(int c=1; c<=K; c++){
				ans += dpGCD(dpGCD(a, b), c);
			}
		}
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 4108
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())


a, b = li()
print(max(0, a - 2*b))

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

using namespace std;

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

    int n, m;
    cin >> n >> m;
    int place[n + 1] = {}, parent[n + 1];
    vector<int> c[n + 1];
    pair<pair<int, int>, int> q[m];

    for (int i = 1; i <= n; i++)
        parent[i] = i, c[i].push_back(i);

    for (int i = 0; i < m; i++) {
        int l, r, d, lastR;
        cin >> l >> r >> d;

        q[i] = {{l, r}, d};

        if (parent[l] != parent[r]) {
            if (c[parent[l]].size() < c[parent[r]].size())
                swap(l, r), d *= -1;

            lastR = place[r];

            vector<int> tmp = c[parent[r]], empty;
            c[parent[r]].swap(empty);

            for (int x : tmp)
                place[x] = place[l] + d + (place[x] - lastR), c[parent[l]].push_back(x), parent[x] = parent[l];
        }
    }

    for (auto x : q) {
        int l = x.first.first, r = x.first.second, d = x.second;
        if (place[r] - place[l] != d)
            return cout << "No\n", 0;
    }

    cout << "Yes\n";

    return 0;
}


Measured memory_bytes: 10112
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>

using namespace std;


#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define INF 1<<30
#define mp make_pair
#define pb push_back
#define MAX 2*1000000000

typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pair<int, int> > vp;

typedef long long ll;

int main(){

	int n;
	cin >> n;
	vl a(n, 0);
	ll as=0;
	ll tas=0;
	rep(i, n){
		cin>>a[i];
		as += a[i];
	}
	ll mi = MAX;
	rep(i, n-1){
		tas += a[i];
		mi = min(mi, abs(tas - (as - tas)));
	}
	cout << mi << endl;

	return 0;
}


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


int main()
{
    int n;
    ll d;
    cin >> n >> d;
    int ans = 0;
    rep(i,n)
    {
        ll x, y;
        cin >> x >> y;
        if(x*x + y*y <= d*d) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3628
n=int(input())
A=[0]*(n+1)
a=round(n**0.5)+1
for x in range(1,a):
  for y in range(1,a):
    for z in range(1,a):
      b=x*x+y*y+z*z+x*y+y*z+z*x
      if b<n+1:
        A[b]+=1
for i in range(1,n+1):
  print(A[i])

Measured memory_bytes: 9448
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define rep(i,j,k) for(int i=j;i<k;i++)
#define BIG_NUM 1000000000
#define MOD 1000000007
#define EPS 0.000000001
int hako[110][110];
int flag[110][110];
int main(){
  rep(i,0,110)fill(hako[i],hako[i]+110,BIG_NUM);
  rep(i,0,110)fill(flag[i],flag[i]+110,-1);

  int n,m;
  cin >> n >> m;
  rep(i,0,m){
    int a,b,c;
    cin >> a >> b >> c;
    hako[a-1][b-1] = c;
    hako[b-1][a-1] = c;
    flag[a-1][b-1] = c;
    flag[b-1][a-1] = c;
  }
  rep(k,0,n){
    rep(i,0,n){
      rep(j,0,n){
        if(i==j){
          hako[i][i] = 0;
          continue;
        }
        if(hako[i][j] > hako[i][k] + hako[k][j]){
          hako[i][j] = hako[i][k]+hako[k][j];
        }
      }
    }
  }
  int res = m;
  rep(k,0,n){
    rep(i,0,n){
      rep(j,0,n){
        if(flag[k][j] == -1)continue;
        if(hako[i][j] == hako[i][k] + flag[k][j]){
          res--;
          flag[k][j] = -1;
          flag[j][k] = -1;
        }
      }
    }
  }
  cout << res << endl;

  return 0;
}


Measured memory_bytes: 384
#!/usr/bin/python3
n = int(input())
inf = 100 * 100000

M = [[inf for i in range(n)] for j in range(n)]

for i in range(n):
    L = list(map(int, input().split()))
    u = L[0]
    k = L[1]
    v = L[2::2]
    c = L[3::2]
    for j in range(k):
        M[u][v[j]] = c[j]

S = set()
V = set(range(n))
S.add(0)
d = [inf for i in range(n)]
d[0] = 0
count = 0
while len(V - S) != 0:
    T = V - S
    nd = [inf for i in range(n)]
    for s in S:
        for m, c in enumerate(M[s]):
            if d[s] + c < nd[m] and m in T:
                nd[m] = d[s] + c

    min_nd = min(nd)
    u = nd.index(min_nd)
    S.add(u)
    d[u] = min_nd


for i, v in enumerate(d):
    print(i, v)

Measured memory_bytes: 7900
//
// Writer:          Darsein
// Expected status: AC
// Complexity:      O(NlogN)
//

#include<iostream>
#include<vector>
#include<cassert>
#include<algorithm>
using namespace std;

inline void toComplement(vector<size_t> &p) {
  size_t n = p.size();
  for(size_t i=0;i<n;i++) p[i] = n - p[i] + 1;
}

inline vector<size_t> enumRuns(const vector<size_t> &p) {
  size_t n = p.size();
  vector<size_t> runs;
  for(size_t i=1;i<n-1;i++) {
    if( (p[i-1]<p[i]) xor (p[i]<p[i+1]) ) {
      runs.emplace_back(i);
    }
  }
  runs.emplace_back(n);
  return runs;
}

inline size_t LIS(const vector<size_t> &a) {
  size_t n = a.size();
  vector<size_t> dp(n, n+1);
  for(size_t i=0;i<n;i++) {
    *lower_bound(dp.begin(), dp.end(), a[i]) = a[i];
  }
  return distance(dp.begin(), lower_bound(dp.begin(), dp.end(), n+1));
}

inline vector< vector<size_t> > runDecompose(const vector<size_t> &p, vector<size_t> runs, int delta) {
  runs[0] += delta;
  vector< vector<size_t> > res;
  size_t cur = 0, idx = 0;
  while(idx < runs.size()) {
    vector<size_t> seq;
    while(cur < runs[idx]) seq.emplace_back(p[cur++]);
    if(idx%2==0) reverse(seq.begin(), seq.end());
    res.emplace_back(seq);
    idx++;
  }
  return res;
}

inline bool check(const vector< vector<size_t> > &qs, const vector< vector<size_t> > &ps, size_t n) {
  size_t run = ps.size();
  vector<size_t> pp(run, 0), qp(run, 0);

  size_t prv = n + 1;
  while(true) {
    int idx = -1;
    for(size_t i=0; i<run; i++) {
      if(pp[i] == ps[i].size()) continue;
      if( idx<0 or ps[idx][pp[idx]] < ps[i][pp[i]] ) idx = i;
    }
    if(idx < 0) break;
    pp[idx]++;

    while( qp[idx] < qs[idx].size() and qs[idx][qp[idx]] >= prv ) qp[idx]++;
    if( qp[idx] == qs[idx].size() ) return false;
    prv = qs[idx][qp[idx]];
  }

  return true;
}

inline bool solve(vector<size_t> &q, vector<size_t> &p) {
  size_t n = q.size();
  vector<size_t> q_runs = enumRuns(q);
  vector<size_t> p_runs = enumRuns(p);

  if( p_runs.size() > q_runs.size() ) return false;


  if( p_runs.size() == 1 ){
    if( p[0] > p[1] ){
      toComplement(q); toComplement(p);
    }
    return p.size() <= LIS(q);
  }
  
  if( q[0] > q[1] ){
    toComplement(q); toComplement(p);
  }

  if( p_runs.size() == 3 and p[0] > p[1] ) return false;

  if( p_runs.size() == 2 ) {
    if(p[0] < p[1]) {
      p_runs.back()--;
      p_runs.push_back(p.size());
    } else p_runs.insert(p_runs.begin(), 0);
  }
  
  for(int delta=0;delta<2;delta++) {
    vector< vector<size_t> > qs = runDecompose(q, q_runs, 0);
    vector< vector<size_t> > ps = runDecompose(p, p_runs, delta);
    if(check(qs, ps, n)) return true;
  }
  
  return false;
}

int main(){
  cin.tie(0); ios::sync_with_stdio(0);
  size_t n;
  cin >> n;
  vector<size_t> q(n);
  for(size_t i=0;i<n;i++) cin >> q[i];

  size_t m;
  cin >> m;
  vector<size_t> p(m);
  for(size_t i=0;i<m;i++) cin >> p[i];

  printf( (solve(q, p) ? "Yes\n" : "No\n") );
}



Measured memory_bytes: 6152
#include <stdio.h>
int main()
{
  int a,b,c,d,e;
  scanf("%d %d %d",&a,&b,&c);
  d=a;
  a=b;
  b=d;
  e=c;
  c=a;
  a=e;
  printf("%d %d %d",a,b,c);
  return 0;
}

Measured memory_bytes: 128
s=input()
rcnt,lcnt=0,0
jidai=0
rsatan=0
ans=[0 for _ in range(len(s))]
for i in range(len(s)):
    if jidai==0:
        if s[i]=="R":
            rcnt+=1
        elif s[i]=="L":
            rrem=i-1
            lrem=i
            lcnt+=1
            jidai=1
    elif jidai==1:
        if s[i]=="L":
            lcnt+=1
        elif s[i]=="R":
            jidai=0
            if (lcnt+rcnt)%2==0:
                ans[rrem],ans[lrem]=(lcnt+rcnt)//2,(lcnt+rcnt)//2
            else:
                if (rrem-rsatan)%2==0:
                    ans[rrem],ans[lrem]=(lcnt+rcnt)//2+1,(lcnt+rcnt)//2
                else:
                    ans[rrem],ans[lrem]=(lcnt+rcnt)//2,1+(lcnt+rcnt)//2

            rcnt,lcnt=1,0
            rsatan=i

if (lcnt+rcnt)%2==0:
    ans[rrem],ans[lrem]=(lcnt+rcnt)//2,(lcnt+rcnt)//2
else:
    if (rrem-rsatan)%2==0:
        ans[rrem],ans[lrem]=(lcnt+rcnt)//2+1,(lcnt+rcnt)//2
    else:
        ans[rrem],ans[lrem]=(lcnt+rcnt)//2,1+(lcnt+rcnt)//2

print(' '.join(map(str, ans)))

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

int arr[105];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    map <string, int> mp;
    string s[n];
    int mx = 0, cnt = 0;
    for (int i = 0; i < n; i++)
    {
        string str;
        cin >> str;
        s[i] = str;
        mp[str]++;
        if (mp[str] == 1)
        {
            cnt++;
        }
        if (mp[str] > mx)
        {
            mx = mp[str];
        }
    }
    sort (s, s+n);
    for (int i = 0; i < n-1; i++)
    {
        if (s[i] == s[i+1])
        {
            s[i] = "0";
        }
    }
    for (int i = 0; i < n; i++)
    {
        if (mp[s[i]] == mx)
        {
            cout << s[i] << endl;
        }
    }
    return 0;
}


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

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

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

ll A, B, Q;
ll S[100005];
ll T[100005];

ll solve(ll x)
{
    //! x以上の神社の最大index
    int s = A, us = -1;
    while (abs(us - s) > 1)
    {
        int mid = (s + us) / 2;
        if (S[mid] >= x)
            s = mid;
        else
            us = mid;
    }

    //! x以上の寺の最大index
    int t = B, ut = -1;
    while (abs(ut - t) > 1)
    {
        int mid = (t + ut) / 2;
        if (T[mid] >= x)
            t = mid;
        else
            ut = mid;
    }

    //cout << x << " " << S[s] << " " << T[t] << endl;

    ll min = INF;
    //! t,t-1,s,s-1を訪れる組み合わせで一番距離が短いもの
    for (int i = 0; i <= 1; ++i)
    {
        for (int j = 0; j <= 1; ++j)
        {
            //! 神社index
            int si = std::min(std::max(0, s - i), (int)A - 1);
            int ti = std::min(std::max(0, t - j), (int)B - 1);
            //! 寺→神社の順番
            ll sum0 = abs(S[si] - x) + abs(T[ti] - S[si]);
            ll sum1 = abs(T[ti] - x) + abs(S[si] - T[ti]);
            min = std::min(min, std::min(sum0, sum1));
        }
    }
    return min;
}

int main()
{
    cin >> A >> B >> Q;
    REP(i, A)
    {
        cin >> S[i];
    }
    S[A] = INF;
    REP(i, B)
    {
        cin >> T[i];
    }
    T[B] = INF;
    REP(i, Q)
    {
        ll x;
        cin >> x;
        cout << solve(x) << endl;
    }
    return 0;
}

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

int main() {
  string S;
  cin >> S;
  string ans = "";
  
  for(int i = 0; i < S.size(); i++){
    if(S.at(i) == '0'){
      ans += '0';
    }
    else if(S.at(i) == '1'){
      ans += '1';
    }
    else if(S.at(i) == 'B'){
      if(ans == ""){
        continue;
      }
      ans.pop_back();
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <math.h>

using namespace std;

int main() {
	vector<int> a(3), b(3);

	bool flag = true;
	int one = 0, two = 0, three = 0, four = 0;

	for (int i = 0; i < 3; i++) {
		
		cin >> a.at(i) >> b.at(i);
		if (a.at(i) == b.at(i)) {
			flag = false;
			break;
		}
		switch (a.at(i)){
		case 1: one++; if (one > 1) { flag = false; }; break;
		case 2: two++;  if (two > 2) { flag = false; }; break;
		case 3: three++; if (three > 2) { flag = false; }; break;
		case 4:four++; if (four > 2) { flag = false; }; break;
		}

		switch (b.at(i)) {
		case 1: one++; if (one > 1) { flag = false; }; break;
		case 2: two++;  if (two > 2) { flag = false; }; break;
		case 3: three++; if (three > 2) { flag = false; }; break;
		case 4:four++; if (four > 2) { flag = false; }; break;
		}
	}

	if (flag == true) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}

}

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

int N, M, Q;
int a[50];
int b[50];
int c[50];
int d[50];
int A[10];
int ans = -1;

void dfs(int dep, int i) {
    if (dep == N) {
        int score = 0;
        for (int i = 0; i < Q; i++) {
            if (A[b[i]] - A[a[i]] == c[i]) score += d[i];
        }
        ans = max(ans, score);
        return;
    }
    for (int j = i; j <= M; j++) {
        A[dep] = j;
        dfs(dep + 1, j);
    }
}

int main() {
    cin >> N >> M >> Q;
    for (int i = 0; i < Q; i++) {
        cin >> a[i] >> b[i] >> c[i] >> d[i];
        a[i]--;
        b[i]--;
    };
    dfs(0, 1);
    cout << ans << endl;
}

Measured memory_bytes: 3584
def factorization(n):
    ans = 0
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            tmp = set()
            while temp%i==0:
                cnt+=1
                temp //= i
                if not cnt in tmp:
                    tmp.add(cnt)
                    cnt = 0
                    ans += 1

    if temp!=1:
        ans += 1

    if ans==0 and temp!=1:
        ans += 1

    return ans

N = int(input())
print(factorization(N))

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

int main()
{
  int n;
  cin >> n;
  vector<int> a(n);
  int i;
  vector<long long> sum(n, 0);
  for(i = 0; i < n; i++)
  {
    cin >> a.at(i);
    sum.at(i) += a.at(i);
    if(i != n-1) sum.at(i+1) = sum.at(i);
  }
  sort(sum.begin(), sum.end());
  long long checknum = sum.at(0);
  long long count = 0;
  long long ans = 0;
  for(i = 0; i < n; i++)
  {
    if(checknum == sum.at(i))
    {
      count++;
    }
    else
    {
      if(checknum == 0)ans += count*(count+1)/2;
      else ans += count*(count-1)/2;
      checknum = sum.at(i);
      count = 1;
    }
  }
  if(checknum == 0)ans += count*(count+1)/2;
  else ans += count*(count-1)/2;
  cout << ans << endl;
}

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

int main(){
  int n;cin>>n;
  int a,b;cin>>a>>b;
  bool flag=false;
  for(int i=a;i<b+1;i++){
    if(i%n==0) flag = true;
  }
  if(flag) cout<<"OK"<<endl;
  else cout<<"NG"<<endl;
}
    


Measured memory_bytes: 3632
n,m = map(int,input().split())
li = []
for i in range(n):
    li.append(list(map(int,input().split())))
lia = sorted(li, key=lambda x:(x[0],x[1]))
asum = 0
for i in range(n):
    if m >= lia[i][1]:
        m -= lia[i][1]
        asum += lia[i][0]*lia[i][1]
    else:
        asum += lia[i][0]*m
        break
print(asum)

Measured memory_bytes: 35652