akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#define NIL NULL
#define WHITE 0
#define GRAY 1
#define BLACK 2
#define INF 10000
int n,M[1000][1000];

int prim(){
    int d[100],pi[100],color[100];
    int sum=0,i,v,u=0,minv;
    for(i=0;i<n;i++){
        d[i]=INF;
        pi[i]=-1;
        color[i]=WHITE;
    }
    d[0]=0;
    while(1){
        minv=INF;
        u=-1;
        for(i=0;i<n;i++){
            if(minv>d[i]&&color[i]!=BLACK){
                u=i;
                minv=d[i];
            }
        }
        if(u==-1){
        break;
        }
        color[u]=BLACK;
        for(v=0;v<n;v++){
            if(color[v]!=BLACK&&M[u][v]!=INF){
                if(d[v]>M[u][v]){
                    pi[v]=u;
                    d[v]=M[u][v];
                    color[v]=GRAY;
                }
            }
        }
    }
    for(i=0;i<n;i++){
        if(pi[i]!=-1){
            sum+=M[i][pi[i]];
        }
    }
    return sum;
}

int main(){
    int i,j;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        for(j=0;j<n;j++){
            scanf("%d",&M[i][j]);
            if(M[i][j]==-1){
                M[i][j]=INF;
            }
        }
    }
    printf("%d\n",prim());
    return 0;
}



Measured memory_bytes: 2108
package main
 
import (
	"fmt"
)

func main() {
  var tl, ta, al, aa int
  fmt.Scan(&tl, &ta, &al, &aa)
  for tl > 0 && al > 0 {
    al -= ta
    tl -= aa
  }
  fmt.Println(map[bool]string{true: "No", false: "Yes"}[al > 0])
}


Measured memory_bytes: 1816
n,x = map(int, input().split())

donutspowderconsumption = [int(input()) for i in range(n)]
totalpowderconsumption = sum(donutspowderconsumption)
donutspowderconsumption.sort()

print( n + (x-totalpowderconsumption) // donutspowderconsumption[0])

Measured memory_bytes: 2940
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    int r = scanner.nextInt();
    int D = scanner.nextInt();
    long x = scanner.nextInt();
    for (int i = 0; i < 10; i++) {
      x = r * x - D;
      System.out.println(x);
    }
  }
}

Measured memory_bytes: 21332
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <string>

#define rep(i, a, b) for ( int i = (a); i < (b); i++ )
#define per(i, a, b) for ( int i = (b)-1; i >= (a); i--)
#define pb push_back
#define mp make_pair
#define bg begin()
#define en end()
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define sz(v) (int)(v).size()

using namespace std;

typedef long long ll;
typedef long double ld;

using P = pair<int, int>;

static const long long MOD = 1000000007;
static const long long LINF = (ll)(1e18+99);
static const int INF = 1e9+99;

int ans;

int main(void) {
    int x;
    cin >> x;

    int t = x / 200;


  
    cout << 10 - t << "\n";
    return 0;
}



Measured memory_bytes: 3620
import numpy as np
h, w = map(int, raw_input().split())
a = []
for i in range(h):
	tmp_a = list(raw_input())
	tmp_a = [1 if j == '#' else 0 for j in tmp_a]
	a.append(tmp_a)
a = np.array(a)
y0, x0 = a.shape
for i in range(x0 + y0):
	a = a[np.any(a == 1, axis=1)]
	a = a[:, np.any(a == 1, axis=0)]
	y, x = a.shape
	if (x0 == x) & (y0 == y):
		break
	else:
		x0, y0 = x, y
a = a.tolist()
for i in range(y):
	ans = ['#' if j == 1 else '.' for j in a[i][:]]
	print ''.join(ans)

Measured memory_bytes: 11484
#include <iostream>
#include <cmath>

using namespace std;

int main() {
    int n,t,a;
    cin>>n>>t>>a;

    int h[n],m=0;
    double p[n];
    for(int i=0;i<n;i++) {
        cin >> h[i];
        p[i] = abs(a-(t-h[i]*0.006));
        if (p[i]<p[m]) m=i;
    }
    cout << m+1;
    return 0;
}

Measured memory_bytes: 256
function main(input) {
  const N = parseInt(input.split(" ")[0] , 10);
  const M = parseInt(input.split(" ")[1] , 10);
  const C = parseInt(input.split(" ")[2] , 10);
  const arrB = input.split('\n')[1].split(' ').map((n) => parseInt(n, 10));
  var ans=0
  for(var i=0; i<N; i++){
    var tempArr = input.split('\n')[i+2].split(' ').map((n) => parseInt(n, 10));
    var temp=0;
    for(var j=0; j<M; j++){
      temp+=arrB[j]*tempArr[j]
    }
    temp+=C;
    if(temp>0)ans++
  }
  console.log(ans);
  
  
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7500
/*Q-4---ATCODER-BEGINNER-#ROUND_177
*/

#include <bits/stdc++.h>
#define M 1000000007
#define endl '\n'
#define ll long long
using namespace std;

ll find(vector<ll> adj_list[],ll nodes){
	bool visited[nodes+1];
	for(ll i=1;i<=nodes;i++)
		visited[i]=false;

	ll maxi=INT_MIN;
	for(ll i=1;i<=nodes;i++){
		if(visited[i]==false){
			ll cnt{0};

			queue<ll> q;
			q.push(i);
			visited[i]=true;

			while(!q.empty()){
				ll temp=q.front();
				cnt++;
				q.pop();

				ll siz=adj_list[temp].size();
				for(ll j=0;j<siz;j++){
					if(visited[adj_list[temp][j]]==false){
						q.push(adj_list[temp][j]);
						visited[adj_list[temp][j]]=true;
					}
				}

			}

			if(cnt>maxi)
				maxi=cnt;	
		}
	}

	return maxi;

}

int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
	ll nodes{0};
	ll edges{0};
	cin>>nodes>>edges;

	vector<ll> adj_list[nodes+1];

	while(edges--){
		ll u{0};
		ll v{0};
		cin>>u>>v;
		adj_list[u].push_back(v);
		adj_list[v].push_back(u);
	}

	cout<<find(adj_list,nodes)<<endl;

	return 0;
}

Measured memory_bytes: 17464
#include<stdio.h>
#include<string.h>
int main(){
char s[30],a[101010];
int ans=0,n,i,j,k,x,y,o,z=0,l,b;
scanf("%d\n",&n);
scanf("%s\n",s);
for(i=0;i<n;i++){
for(j=0;j<100010;j++){
a[j]='A';
}
scanf("%s\n",a);
x=strlen(s),y=strlen(a);
for(j=1;j<=y;j++){
	for(l=0;l<y;l++){
		b=l;
		for(k=0;k<x;k++){
			if(s[k]==a[b]){
			b=b+j;
			}
			else{
			break;
			}
		}
		if(k==x){
		z=1;
		break;
		}
	}
	if(z==1){
	ans++,z=0;
	break;
	}
}
}
printf("%d\n",ans);
return 0;
}


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

#define FOR(i,l,r) for(int i = (l);i < (r);i++)
#define ALL(x) (x).begin(),(x).end()
template<typename T> bool chmax(T& a,const T& b){return a < b ? (a = b,true) : false;}
template<typename T> bool chmin(T& a,const T& b){return b < a ? (a = b,true) : false;}
typedef long long ll;

int N;

int main()
{
	double x1,y1,x2,y2,x3,y3;
	scanf("%d",&N);
	FOR(i,0,N){
		scanf("%lf%lf%lf%lf%lf%lf",&x1,&y1,&x2,&y2,&x3,&y3);
		double a = pow(x1 - x2,2.0) + pow(y1 - y2,2.0);
		double b = pow(x2 - x3,2.0) + pow(y2 - y3,2.0);
		double c = pow(x3 - x1,2.0) + pow(y3 - y1,2.0);
		double s = a * (b + c - a) + b * (c + a - b) + c * (a + b - c);
		double x = (a * (b + c - a) * x3 + b * (c + a - b) * x1 + c * (a + b - c) * x2) / s;
		double y = (a * (b + c - a) * y3 + b * (c + a - b) * y1 + c * (a + b - c) * y2) / s;
		printf("%.3f %.3f %.3f\n",x,y,sqrt(pow(x - x1,2.0) + pow(y - y1,2.0)));
	}

	return 0;
}

Measured memory_bytes: 3224
use std::io::Read;
use std::str::SplitWhitespace;
use std::str::FromStr;
trait BinarySearch<T> {
    fn front_position(&self, x: T) -> usize;
    fn back_position(&self, x: T) -> usize;
    fn bs_position(v: &[T], x: T, is_back: bool) -> usize;
}

impl<T> BinarySearch<T> for Vec<T>
where
    T: Ord,
{
    fn front_position(&self, x: T) -> usize {
        Self::bs_position(self, x, true)
    }

    fn back_position(&self, x: T) -> usize {
        Self::bs_position(self, x, false)
    }

    fn bs_position(v: &[T], x: T, is_front: bool) -> usize {
        let len = v.len();
        if len == 1 {
            return if x < v[0] || (is_front && x == v[0]) {
                0
            } else {
                1
            };
        }
        let i = len / 2;
        if x < v[i] || (is_front && x == v[i]) {
            Self::bs_position(&v[..i], x, is_front)
        } else {
            Self::bs_position(&v[i..], x, is_front) + i
        }
    }
}

pub fn read_stdin() -> String {
    let mut s = String::new();
    ::std::io::stdin().read_to_string(&mut s).unwrap();
    s
}

pub trait Parse<T> {
    fn parse(&mut self) -> T;
}

impl<'a, T> Parse<T> for SplitWhitespace<'a>
where
    T: FromStr,
{
    fn parse(&mut self) -> T {
        let word = self.next().unwrap();
        word.parse().ok().unwrap()
    }
}

fn main() {
    let source = read_stdin();
    let mut iter = source.split_whitespace();
    let s_: String = iter.parse();
    let s = s_.chars().collect::<Vec<_>>();
    let t_: String = iter.parse();
    let t = t_.chars().collect::<Vec<_>>();

    let mut m = std::collections::HashMap::new();
    let alphabet = "abcdefghijklmnopqrstuvwxyz";
    for c in alphabet.chars() {
        m.insert(c, Vec::new());
    }

    let s_len = s.len();
    for (i, c) in s.into_iter().enumerate() {
        if let Some(v) = m.get_mut(&c) {
            v.push(i);
        }
    }

    let mut ans = 0;
    let mut curr = 0;
    for c in t {
        if let Some(v) = m.get(&c) {
            if v.is_empty() {
                println!("-1");
                return;
            }
            let mut pos = v.front_position(curr);
            if pos == v.len() {
                ans += s_len - curr;
                curr = 0;
                pos = v.front_position(curr);
            }
            ans += v[pos] + 1 - curr;
            curr = v[pos] + 1;
        }
    }

    println!("{}", ans);
}

Measured memory_bytes: 6396
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include <cstdint>
#include <utility>
#include <tuple>
#include <map>    
#include <queue> 
#include <set>  
#include <stack> 
#include <deque>  
#include <unordered_map> 
#include <unordered_set> 
#include <bitset>

using namespace std;

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

	vector<string> s(N);
	for (int i = 0; i < N; i++) {
		cin >> s.at(i);
		sort(s[i].begin(), s[i].end());
	}

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

	int64_t count = 0;
	int64_t ans = 0;

	for (int i = 0; i < N - 1; i++) {
		if (s.at(i + 1) == s.at(i)) {
			count++;
			ans += count;
		}
		else {
			count = 0;
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 7296
#include<iostream>
using namespace std;
#define MAX 100

int main()
{
	int a;
	int l0=2;
	int l1=1;
	int l2;
	long long int l;
	long long int k;
	long long int p;
	cin >> a;

	l2 = l0 + l1;
	l=l2;
	k = l1;
	
	if (a == 1)
	{
		cout << l1;
		
	}
	else if (a == 2)
	{
		cout << l2;
	}
	else if (a == 3)
	{
		cout << l + k;
	}
	
	else {
		l = l1;
			k = l2;
			l = k + l;
	
		for (int i = 4; i < a+1; i++)
		{
			p = l;
			l = l + k;
			k = p;
		}
		cout << l;
	}

	

	return 0;
}





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

int n,k,m;

int main() {
  cin >> n >> m;
  cout << (n==m ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
// 🐋💭
import Foundation

func readInts() -> [Int] {
    return readLine()!.split(separator: " ").map { Int($0)! }
}

func readInt() -> Int {
    return Int(readLine()!)!
}

func readDoubles () -> [Double] {
    return readLine()!.split(separator: " ").map { Double($0)! }
}

func readDouble() -> Double{
    return Double(readLine()!)!
}

func readLines() -> [String] {
    return readLine()!.map { String($0) }
}

///最大公約数を返す
func gcd(_ m:Int, _ n:Int) -> Int {
    if n == 0 {return m}
    return gcd(n, m % n)
}

///最大公約数を返す
func gcd(_ array: [Int]) -> Int {
    var value = array[0]
    if array.count > 1 {
        for i in 1..<array.count {
            value = gcd(value, array[i])
        }
    }
    return value
}

///最小公倍数を返す
func lcm(_ m:Int, _ n:Int) -> Int {
    return m * n / gcd(m, n)
}

///素数判定(試し割り)
func isPrime(_ x:Int) -> Bool {
    if x <= 1 || x % 2 == 0 { return false }
    if x == 2 { return true }
    for i in stride(from: 3, to: Int(ceil(sqrt(Double(x)))), by: 2){
        if x % i == 0 {
            return false
        }
    }
    return true
}

//https://program-life.com/669
///実行速度の計測
func exectionTime(action: () -> Void) {
    let startDate = Date()
    action()
    let endDate = Date()
    print(endDate.timeIntervalSince(startDate))
}

//https://riptutorial.com/ja/swift/example/14738/インデックスを知らずに配列から要素を削除する
extension Array where Element: Equatable {
    
    mutating func remove(_ element: Element) {
        _ = firstIndex(of: element).flatMap {
            self.remove(at: $0)
        }
    }
}

func binarySearch(rifgt:Int, key:Int, ary:[String]) -> Int{
    var left = 0
    var right = rifgt
    
    while abs(right - left) > 1 {
        let mid = left + (right - left) / 2
        
        if Int(ary[mid])! < key {
            left = mid
            
        } else {
            right = mid
        }
    }
    return left
}

func arrangement (prev:String, ary:[String], returnVal:[String]) -> [String] {
    var returnVal = returnVal
    if ary.count == 0 {
        returnVal.append(prev)
        return returnVal
    }
    
    for s in ary {
        let wprev = prev + s
        var wary = ary
        wary.remove(s)
        returnVal = arrangement(prev: wprev, ary: wary, returnVal: returnVal)
    }
    return returnVal
}
// https://algo-logic.info/divisor/
/// 約数の配列を返す
func divisor(_ n:Int) -> [Int] {
    var ret = [Int]()
    var i = 1
    while i * i <= n {
        if n % i == 0 {
            ret.append(i)
            if i * i != n {
                ret.append(n / i)
            }
        }
        i += 1
    }
    return ret.sorted()
}

func main() {
    let n = readInt()
    var aryA = [Int]()
    for _ in 0..<n {
        aryA.append(readInt())
    }
    //＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿ここまで入力
    aryA.sort()
    var left = 0
    var right = 1
    var ans = 0
    while right < n {
        while right < n && aryA[left] == aryA[right] {
            right += 1
        }
        if (right - left) % 2 == 1 {
            ans += 1
        }
        left = right
    }
    print(ans)
}
main()


Measured memory_bytes: 13924
#ライブラリインポート
from collections import defaultdict

#入力受け取り
def getlist():
	return list(map(int, input().split()))

con = 10 ** 9 + 7
#処理内容
def main():
	N = int(input())
	A = getlist()
	RGB = [0, 0, 0]
	ans = 1
	for i in range(N):
		cnt = 0
		jud = "No"
		for j in range(3):
			if A[i] == RGB[j]:
				cnt += 1
				if jud == "No":
					RGB[j] += 1
					jud = "Yes"
		ans = (ans * cnt) % con

	print(ans)

if __name__ == '__main__':
	main()

Measured memory_bytes: 52952
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;



int main(){
    int N; cin >> N;
    vector<int> L(N);
    rep(i,N) cin >> L[i];
    sort(L.begin(),L.end());
    int ans = 0;
    rep(i,N-2)repr(j,i+1,N-1){
        repr(k,j+1,N){
            if(L[k] < L[i]+L[j]) ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const long long INF = 1e7 + 1;
const long long MOD = 1000000007;
const long double PI = 3.1415926;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
typedef long long int ll;
typedef vector<ll> vi;
typedef vector < pair<ll, ll > > vp;
typedef vector <string> vs;
typedef vector <char> vc;
typedef list <ll> lst;

ll n, m, k, ans = 0, sum = 0, cnt = 0;
string s;
char c;

#define Endl endl

map<string, string> mp, mpg,mpa;

/*--------------------template--------------------*/


int main()
{
	cin >> s;
	if (s.size() < 4) {
		cout << "No" << endl;
		return 0;
	}
	if (s[0] == 'Y'&&s[1] == 'A'&&s[2] == 'K'&&s[3] == 'I') {
		cout << "Yes" << Endl;
	} else {
		cout << "No" << endl;
	}

}

Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}

int main(){
  int N;
  cin >>  N;
  int a[N];
  vector<int> num(100100,0);
  for(int i = 0; i < N; i++){
    cin >> a[i];
    num[a[i]] ++;
  }
  int cnt ,maxCnt = -1;
  for(int i = 1; i <= 100000; i++){
    maxCnt = max(maxCnt, num[i-1] + num[i] + num[i+1]);
  }
  cout << maxCnt << endl;
  return 0;
}


Measured memory_bytes: 1024
#include<cstdio>
#include<vector>
#include<queue>
int main(){
    int n;
    scanf("%d",&n);
    std::vector<std::vector<std::pair<int,int>>> g(n+1);
    for(int i=1;i<n;i++){
        int u,v,w;
        scanf("%d%d%d",&u,&v,&w);
        g[u].push_back({v,w%2});
        g[v].push_back({u,w%2});
    }
    std::vector<int> d(n+1,-1);
    std::queue<int> q;
    q.push(1);
    d[1]=0;
    while(!q.empty()){
        int u=q.front();
        q.pop();
        for(auto itr=g[u].begin();itr!=g[u].end();itr++){
            int v=(*itr).first, w=(*itr).second;
            if(d[v]<0){
                d[v]=d[u]+w;
                q.push(v);
            }
        }
    }
    for(int i=1;i<=n;i++){
        printf("%d\n",d[i]%2);
    }
    return 0;
}

Measured memory_bytes: 6784
import java.util.Scanner;

public class Main {
	public static void main(String []args){
		//????????£?????????????????????
		Scanner sc = new Scanner(System.in);
		//??£?¨?
		int count =0;
		//??°?????????
		while(true){
			//???????????§?????°??? ???
			int n = sc.nextInt();
			//????????° x
			int x = sc.nextInt();
			//?????¶??? n??¨x???????????¨???0?????´??? ??????
			if(n ==0&& x==0){
				break;
				}
			for(int i = 1; i <=n; i++){ //???????????°??? ????????????
				for(int j =i+1; j<=n; j++){ //2???????????°??? ????????????
					for(int k = j+1; k <=n; k++){ //3???????????°??? ????????????
						//????¨??????????????????????????????????
						if(x == (i + j + k)){
						//System.out.println(i + " " + j + " " + k);
						count++;
						}
					}
				}
			}
			System.out.println(count);
			//??????????????????
			count =0;
		}
	}
}

Measured memory_bytes: 26660
#include <stdio.h>

int main(void)
{
	int x, y, z;
	
	while (1) {
		scanf("%d %d", &x, &y);
		if (x == 0 && y ==0) break;
		if (x > y) {
			z = x;
			x = y;
			y = z;
		}
		printf("%d %d\n", x ,y);
	}
	
	return 0;
}

Measured memory_bytes: 600
n = int(input())
t, a = map(int, input().split())
hl = list(map(int, input().split()))

dt = 10**9
num = 0
for i in range(n):
    ti = t - hl[i] * 0.006
    if abs(a - ti) <= dt:
        dt = abs(a - ti)
        num = i

print(num + 1)


Measured memory_bytes: 3060
//49
#include<iostream>
#include<algorithm>

using namespace std;

int main(){
  for(int n;cin>>n,n;){
    int t[10000];
    for(int i=0;i<n;i++){
      cin>>t[i];
    }
    sort(t,t+n);
    long long w=0,s=0;
    for(int i=1;i<n;i++){
      w+=t[i-1];
      s+=w;
    }
    cout<<s<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <queue>
#include <complex>

using namespace std;

typedef complex<int> P;

int main() {
	int W, H;
	while ( cin >> W >> H, W || H ) {
		int m[20][20], sx, sy;
		for (int y = 0; y < H; ++y) {
			string str; cin >> str;
			for (int x = 0; x < W; ++x) {
				m[y][x] = str[x] == '#' ? 0 : 1;
				if (str[x] == '@') {
					sx = x, sy = y;
				}
			}
		}
		int ans = 0;
		queue<P> Q; Q.push( P(sx, sy) );
		while ( !Q.empty() ) {
			P p = Q.front(); Q.pop();
			int y = p.imag(), x = p.real();
			if (y < 0 || y >= H || x < 0 || x >= W) continue;
			if ( m[y][x] == 0 ) continue;
			m[y][x] = 0;
			++ans;
			
			Q.push( P(x+1, y) );
			Q.push( P(x-1, y) );
			Q.push( P(x, y-1) );
			Q.push( P(x, y+1) );
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 1232
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
#include<stdio.h>
#include<string.h>
#include <bitset>

using namespace std;
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(),(x).end()

// int DP[MEM_SIZE][MEM_SIZE] = {0};
// int GMEM[MEM_SIZE][MEM_SIZE] = {0};
template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return; std::cout << e <<" ";}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){std::cout<< e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class... Ts> void DEBUG(T d, Ts... e){if(DEBUG_OUT == false)return;DEBUG(d);DEBUG(e...);}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }



void solve(void)
{
  int N;
  cin>>N;
  string str;
  stack<char> st;
  for (int i = 0; i < N; i++)
  {
    char X;cin>>X;
    str += X;
    if(st.empty())
    {
      st.push(X);
    }
    else
    {
      if(X == '(')
      {
        st.push(X);
      }
      else
      {
        if(st.top() =='(')
        {
          st.pop();
        }
        else
        {
          st.push(X);
        }
        
      }
      
    }
  }
  string str1,str2;
  
  while(!st.empty())
  {
    char X = st.top();
    st.pop();
    if(X == '(')str1 += ')';
    else str2 += '(';
  }
  cout<<str2 + str + str1<<endl;
  return;
}




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

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();

  return 0;
}


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

using namespace std;

#define ll long long

int main(){

    string S;
    cin>>S;
    bool n=false,w=false,s=false,e=false;

    for(int i=0;i<S.size();i++){
        if(S[i]=='N')n=true;
        if(S[i]=='W')w=true;
        if(S[i]=='S')s=true;
        if(S[i]=='E')e=true;
    }
    if(n==s&&w==e)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(i) begin(i), end(i)

const int INF = 0x3fffffff;
const ll MINF = 0x7fffffffffff;
const ld DINF = numeric_limits<ld>::infinity();
const int MOD = 1000000007;
const int MODD = 998244353;
const ld EPS = 1e-9;
const ld PI = 3.1415926535897932;

ll gcd(ll a, ll b){ while(b){ ll c = b; b = a % b; a = c; } return a; }
ll lcm(ll a, ll b){ if(!a || !b) return 0; return a * b / gcd(a, b); }
ll pow_mod(ll n,ll k,ll m){ll r = 1;for(; k > 0;k >>= 1) {if (k & 1) r = (r * n) % m; n = (n * n) % m;}return r;}
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; }

// 入力
int N;
long long W, weight[110], value[110]; // 品物の個数は 100 個なので少し余裕持たせてサイズ 110 に

// DPテーブル
long long dp[110][100100] = {0};

int main() {
    cin >> N >> W;
    for (int i = 0; i < N; ++i) cin >> weight[i] >> value[i];

    // DPループ
    for (int i = 0; i < N; ++i) {
        for (int sum_w = 0; sum_w <= W; ++sum_w) {

            // i 番目の品物を選ぶ場合
            if (sum_w - weight[i] >= 0) {
                chmax(dp[i+1][sum_w], dp[i][sum_w - weight[i]] + value[i]);
            }

            // i 番目の品物を選ばない場合
            chmax(dp[i+1][sum_w], dp[i][sum_w]);
        }
    }

    // 最適値の出力
    cout << dp[N][W] << endl;
}

Measured memory_bytes: 79360
S = input()
if len(S) != 26:
  A = [0] * 26
  offset = ord('a')
  for s in S:
    A[ord(s)-offset] = 1
  print(S + chr(A.index(0)+offset))
elif S == 'zyxwvutsrqponmlkjihgfedcba':
  print(-1)
else:
  k = 25
  while S[k-1] > S[k]:
    k -= 1
  X = sorted(S[k-1:])
  print(S[:k-1] + X[X.index(S[k-1]) + 1])

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

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

    vector<vector<int>> val;
    val = vector<vector<int>>(4, vector<int>());
    ll w0, v0;  cin >> w0 >> v0;
    val[0].push_back(v0);
    for(int i=1; i<N; i++){
        int w, v;  cin >> w >> v;
        val[w-w0].push_back(v);
    }
    for(int i=0; i<4; i++){
        sort(val[i].begin(), val[i].end(), greater<int>());
        for(int j=1; j<val[i].size(); j++){
            val[i][j] += val[i][j-1];
        }
    }

    int ans = 0;
    for(ll a=0; a<=val[0].size(); a++) for(ll b=0; b<=val[1].size(); b++) for(ll c=0; c<=val[2].size(); c++) for(ll d=0; d<=val[3].size(); d++){
        if(w0*a + (w0+1)*b + (w0+2)*c + (w0+3)*d > W) continue;
        
        int tmpVal = 0;
        if(a>0) tmpVal += val[0][a-1];
        if(b>0) tmpVal += val[1][b-1];
        if(c>0) tmpVal += val[2][c-1];
        if(d>0) tmpVal += val[3][d-1];
        ans = max(ans, tmpVal);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    inf = 10**17
    #mod = 10**9 + 7

    h,n = map(int, input().split())
    ab = [list(map(int, input().split())) for _ in range(n)]
    dp = [inf] * (h+1)
    dp[0] = 0
    for i in range(h+1):
        for a,b in ab:
            if i+a > h:
                c = h
            else:
                c = i + a
            dp[c] = min(dp[c], dp[i]+b)

    print(dp[-1])

if __name__ == '__main__':
    main()


Measured memory_bytes: 42460
from collections import deque

s = input()
q = int(input())

d = deque(s)
inv = 0

for _ in range(q):
  Q = list(input().split())
  
  if Q[0]=='1':
    inv += 1
  elif Q[0]=='2':
    if Q[1]=='1':
      if inv%2==0:
        d.appendleft(Q[2])
      else:
        d.append(Q[2])
    elif Q[1]=='2':
      if inv%2==0:
        d.append(Q[2])
      else:
        d.appendleft(Q[2])

if inv%2==0:
  print(*d, sep='')
else:
  print(*deque(reversed(d)), sep='')

Measured memory_bytes: 12396
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
/*
    s.find_by_order(k) ---> returns iterator to the element at index(from 0) k
    s.order_of_key(val) ---> number of elements that are strictly smaller than the given value
*/
typedef long long int ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<long long int> vl;
typedef vector<vector<int>> vvi;
typedef vector<vector<long long int>> vvl;
typedef pair<int, int> pii;
typedef pair<long long int, long long int> pll;
typedef vector<pair<int, int>> vii;
typedef vector<pair<long long int, long long int>> vll;
#define fast() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define test() long long int tc; cin >> tc; cin.ignore(); while(tc--) 
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define MOD 1000000007
#define SMOD 998244353
#define pq priority_queue
#define all(x) x.begin(),x.end()
#define SP(x) setprecision(x)
#define sp " "
#define inp(a) ll a;cin>>a;cin.ignore()
#define inps(a,b) ll a,b;cin>>a>>b;cin.ignore()
#define out(a) cout<<SP(20)<<a<<'\n'
#define outs(a,b) cout<<SP(20)<<a<<" "<<b<<'\n'
#define ins insert
#define er erase
#define lb lower_bound
#define ub upper_bound
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
#define inpa(a,n) ll a[n]; for(int i=0; i<n; i++){cin>>a[i];}
#define inpv(a,n) vl a; for(int i=0; i<n; i++){inp(x);a.pb(x);}
#define outa(a,n) for(int i=0;i<n;i++){cout<<a[i]<<" ";}cout<<'\n';
#define outv(v) for(auto i:v){cout<<i<<" ";}cout<<'\n';
set<char> vow = {'a','e','i','o','u','A','E','I','O','U'};
ll xpow(ll n, ll m){if(m==0){return 1;}else{ll x = xpow(n, m/2);if(m&1){return x*x*n;}else{return x*x;}}}
ll xmod(ll a, ll m){return (((a%m)+m)%m);}
ll xmodpow(ll n, ll m, ll y){if(m==0){return 1;}else{ll x = xmodpow(n, m/2, y);if(m&1){return xmod((xmod((xmod(x,y)*xmod(x,y)),y)*xmod(n,y)),y);}else{return xmod((xmod(x,y)*xmod(x,y)),y);}}}
 
ll fact[2000005];
ll inv[2000005];

ll NCR(ll n, ll r){
    ll x = fact[n];
    x*=inv[r];
    x%=MOD;
    x*=inv[n-r];
    x%=MOD;
    return x;
}

int main() {
	fast();
 
    /*NA – JEONG – MO – SA – JI – MI – DA – CHAE – TZU*/
    
    fact[0] = 1;
    for(ll i=1; i<=2000001; i++){
        fact[i] = xmod(i*fact[i-1], MOD);
    }
    inv[2000001] = xmodpow(fact[2000001], MOD-2, MOD);
    for(ll i=2000000; i>=0; i--){
        inv[i] = xmod((i+1)*inv[i+1], MOD);
    }
    ll a, b, c, d;
    cin >> a >> c >> b >> d;
    ll ans = 0;
    for(ll i=a; i<=b; i++){
        ll y = NCR(i+d+1, d);
        ll yy = NCR(i+c, c-1);
        y = xmod(y-yy, MOD);
        ans += y;
        ans%=MOD;
    }
    cout << ans << endl;
}

Measured memory_bytes: 31488
import java.io.*;
import static java.lang.Math.*;

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

  private void run() {
    try(BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(System.out)) {

      final int n = atoi(in.readLine());
      int[] a = mapInt(in.readLine().split(" "));

      int ans = 64;
      for (int num : a) {
        int cnt = 0;
        while((num & 1) == 0) {
          num = num >> 1;
          cnt++;
        }
        ans = min(ans, cnt);
      }

      out.println(ans);
    }
    catch(IOException e) {
      System.err.println(e);
    }
  }

  int atoi(String s) { return Integer.parseInt(s); }
  long atol(String s) { return Long.parseLong(s); }
  int[] mapInt(String[] sa) {
    int[] ret = new int[sa.length];
    for (int i = 0; i < sa.length; i++) ret[i] = atoi(sa[i]);
    return ret;
  }
}

Measured memory_bytes: 21332
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int d, t, s;
    cin >> d >> t >> s;
    if (t * s >= d) cout << "Yes";
    else cout << "No";
}


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

int main() {

	int n, d, x;
	scanf("%d %d %d", &n, &d, &x);
	int ans = n;
	vector<int> v(n);
	for(int i = 0; i < n; i++) {
		scanf("%d", &v[i]);
	}
	for(int i = 0; i < n; i++) {
		int s = 1;
		while(s * v[i]  + 1 <= d) {
			s++;
			ans++;
		}
	}
	printf("%d\n", ans + x);
}

Measured memory_bytes: 256
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using System.Text;

public class Program
{

    public void Proc()
    {
        int[] inpt = Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray();


        int itemCount = inpt[0];
        int selectCount = inpt[1];


        int[] items = Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray();


        int ans = 0;
        for (int i = 0; i < items.Length; i+=selectCount-1) {
            if(i == items.Length-1) {
                break;
            }
            ans += 1;    
        }
        Console.WriteLine(ans);
    }




    public class Reader
    {
        static StringReader sr;
        public static bool IsDebug = false;
        public static string ReadLine()
        {
            if (IsDebug)
            {
                if (sr == null)
                {
                    sr = new StringReader(InputText.Trim());
                }
                return sr.ReadLine();
            }
            else
            {
                return Console.ReadLine();
            }
        }
        private static string InputText = @"


4 3
2 3 1 4



";
    }

    public static void Main(string[] args)
    {
#if DEBUG
        Reader.IsDebug = true;
#endif
        Program prg = new Program();
        prg.Proc();
    }
}


Measured memory_bytes: 18016
n = gets.chomp.to_i
a = gets.split.map(&:to_i)
s = a[0]
r = a[1..-1].reduce(:+)
min = (s-r).abs
1.upto(n-2) do |i|
  s += a[i]
  r -= a[i]
  diff = (s-r).abs
  min = diff if min > diff
end
puts min


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

int main(){
    string s;	cin >> s;
    if(s == "Sunny")	cout << "Cloudy" << endl;
    if(s == "Cloudy")	cout << "Rainy" << endl;
    if(s == "Rainy")	cout << "Sunny" << endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define int long long
int mod=1e9+7;

signed main(){
  int n,m;
  cin>>n>>m;
  vector<int> a(m);
  vector<int> b(m);
  vector<int> imos(n+1,0);
  for(int i=0;i<m;i++){
    cin>>a[i]>>b[i];
    imos[a[i]]++;
    imos[b[i]]--;
  }
  int x=0;
  bool f=true;
  for(int i=0;i<n+1;i++){
    x+=imos[i];
    if(x%2!=0)f=false;
  }
  if(f)cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
}


Measured memory_bytes: 2560
import numpy as np
#N,K = map(int,input().split())
N = int(input())
A,B,C = 0,0,0
for i in range(N):
  a,b,c = map(int,input().split())
  A,B,C = a+max(B,C),b+max(A,C),c+max(A,B)
print(max(A,B,C))

Measured memory_bytes: 12396
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)

ll gcd(ll a, ll b) {
    if (a % b == 0) return b;
    return gcd(b, a % b);
}

ll lcm(ll a, ll b) {
    return a / gcd(a, b) * b;
}

int main(){
    int n;
    cin >> n;
    vector<ll> t(n);
    rep(i, n) cin >> t[i];
    if (n == 1) {
        cout << t[0] << endl;
        return 0;
    }
    ll lcm_num;
    for (int i = 1; i < n; ++i) {
        if (i == 1) lcm_num = lcm(t[0], t[1]);
        else        lcm_num = lcm(lcm_num, t[i]);
    }
    cout << lcm_num << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <map>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <queue>
#include <list>
#include <numeric>

using namespace std;
typedef long long ll;

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

/*迷路
const int INF = 50;

typedef pair<int,int> P;
char field[52][52];
int d[51][51];
int r,c;
int sx,sy;
int gx,gy;

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

int bfs(){
    queue<P> que;
    for(int i=0;i<r;i++){
        for(int j=0;j<c;j++){
            d[i+1][j+1] = INF;
        }
    }
    que.push(P(sy,sx));
    d[sy][sx]=0;
while(que.size()){
    P p=que.front();
    que.pop();
    if(p.second==gx&&p.first==gy) break;
    for(int i=0;i<4;i++){
        int nx=p.second+dx[i];
        int ny=p.first+dy[i];

        if(1<=nx&&nx<=c&&1<=ny&&ny<=r&&field[ny][nx]!='#'&&d[ny][nx]==INF){
            que.push(P(ny,nx));
            d[ny][nx] = d[p.first][p.second] + 1;
        }
    }
}
return d[gy][gx];
}
*/

int main(){
  int n;
  cin>>n;
cout<<180*(n-2)<<endl;
return 0;
}


Measured memory_bytes: 256
import java.util.*;
class Main
{

    public static void main(String [] args)
    {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();

        int cost[] = new int[N];
        for(int i=0;i<N;i++)
        {
            cost[i] =sc.nextInt();
        }

        int dp[] =new int [N+1];

        dp[0]=0;
        dp[1]=Math.abs( cost[1]-cost[0]);

        for(int i=2;i< N;i++)
            dp[i] = Math.min(Math.abs(cost[i]-cost[i-1]) + dp[i-1] , Math.abs(cost[i]-cost[i-2]) + dp[i-2]);

       System.out.println( dp[N-1]);

    }


}


Measured memory_bytes: 49872
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef long double ld;
const double pi=acos(-1.0);
const ll mod=pow(10,9)+7;
const ll INF=pow(2,31)-1;
using str=string;
typedef pair<int,int> P;
typedef vector<int> vi;

ll gcd(ll a,ll b){
    ll v0=a,v1=b,v2=a%b;
    while(v2!=0){
        v0=v1;
        v1=v2;
        v2=v0%v1;
    }
    return v1;
}

ll lcm(ll a,ll b){
    return (a*b/gcd(a,b));
}

void printVec(std::vector<int> &vec) {
  std::cout << "";
  for (auto it = vec.begin(); it != vec.end(); ++it) {
    std::cout << *it << " ";
  }
  std::cout << std::endl;
}

int main(){
    int n; cin >>n;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    sort(a.begin(),a.end());
    a.erase(unique(a.begin(),a.end()),a.end());
    if(a.size()==n) cout <<"YES"<<endl;
    else cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <iostream>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <vector>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef double DB;

const int MaxN = 1e5;
int n, m;
int ind[MaxN + 5];

int main()
{
	scanf("%d%d", &n, &m);
	memset(ind, 0, sizeof(ind));
	for(int i = 1; i <= m; i++) {
		int u, v;
		scanf("%d%d", &u, &v);
		ind[u]++; ind[v]++;
	}
	bool flag = 1;
	for(int i = 1; i <= n; i++)
		if(ind[i] & 1) flag = 0;
	if(flag) printf("YES\n");
	else printf("NO\n");
}

Measured memory_bytes: 640
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::{Write, BufWriter};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, [ $t:tt ]) => {{
        let len = read_value!($next, usize);
        (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    }};

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused)]
macro_rules! debug {
    ($($format:tt)*) => (write!(std::io::stderr(), $($format)*).unwrap());
}
#[allow(unused)]
macro_rules! debugln {
    ($($format:tt)*) => (writeln!(std::io::stderr(), $($format)*).unwrap());
}

fn check(mut n: i64, k: i64) -> bool {
    while n % k == 0 {
        n /= k;
    }
    n % k == 1
}

fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (let _ = write!(out,$($format)*););
    }
    input! {
        n: i64,
    }
    if n == 2 {
        puts!("1\n");
        return;
    }
    const W: i64 = 1_000_010;
    let mut ans: i64 = 0;
    for k in 2..W {
        if k * k > n - 1 { break; }
        if (n - 1) % k == 0 {
            ans += 1;
            if k * k != n - 1 {
                ans += 1;
            }
        }
    }
    for k in 2..W {
        if k * k > n { break; }
        if n % k == 0 {
            if check(n, k) { ans += 1; }
            if n != k * k && check(n, n / k) { ans += 1; }
        }
    }
    // k, k - 1
    puts!("{}\n", ans + 2);
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


Measured memory_bytes: 8572
while 1:
 a={};b=1
 n=int(input())
 if n==0:break
 for _ in[0]*n:
  e,p,q=map(int,input().split())
  a.setdefault(e,0);a[e]+=p*q
 for e in a:
  if a[e]>=1e6:print(e);b=0
 if b:print('NA')


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

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

fn main(){
    let n: usize = read();
    let mut ans: u64 = 0;
    for _i in 0..n {
        let ai: u64 = read();
        ans += ai - 1;
    }
    println!("{}", ans);
}

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

inline int read()
{
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}

typedef long long ll;
ll mod=1000000007;

int main()
{
	int n=read(),p=0;
	ll ans=1;
	for(int i=1;i<=n;i++)
	{
		int x=read();
		if (x>=2*p+1) ans=ans*(++p)%mod;
		else ans=ans*(p+1)%mod;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
//解きなおし
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> iint;
typedef pair<ll,ll> llll;
#define ALL(x) (x).begin(),(x).end()
const ll zero = 0;
const ll INF = 3000000000000000000; //10^18
const int inINF = 1000000000; //10^9
const ll MOD = 1000000007; //10^9+7
const ll MOD2 = 998244353;

int main(){
    int H, W, K;
    cin >> H >> W >> K;
    vector<vector<char>> G(H, vector<char> (W));
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            cin >> G[i][j];
        }
    }
    int tmp;
    int ans = 0;
    vector<bool> tate(W), yoko(H);

    for (int i = 0; i < 1<<(H+W); i++) {
        tmp = 0;
        fill(ALL(tate), false);
        fill(ALL(yoko), false);
        for (int j= 0; j < H; j++) {
            if(i & 1<<j){
                yoko[j] = true;
            }
        }
        for (int j= 0; j < W; j++) {
            if(i & 1<<(H+j)){
                tate[j] = true;
            }
        }


        for (int j = 0; j < H; j++) {
            if(yoko[j] == true){
                continue;
            }
            for (int k = 0; k < W; k++) {
                if(tate[k] == true){
                    continue;
                }
                if(G[j][k] == '#'){
                    tmp++;
                }
            }
        }
        if(tmp == K){
            ans++;
        }

    }

    printf("%d\n", ans);
}

Measured memory_bytes: 3696
#include <bits/stdc++.h>
int N,M,C;
using namespace std;
int B[30];
int A[30][30];


int main() {
  ios::sync_with_stdio(false);
  cin >> N >> M >> C;
  for(int i = 1; i <= M; i++) {
    cin >> B[i];
  }
  for(int i = 1; i <= N; i++){
    for(int j = 1; j <= M; j++) {
      cin >> A[i][j];
    }
  }

  int s = 0;
  int t = 0;
  for(int i = 1; i <= N; i++){
    t = 0;
    for(int j = 1; j <= M; j++){
      t += A[i][j]*B[j];
    }
    if(t + C > 0) s++;
  }
  cout << s;

}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#define llong long long
#define INF (__INT32_MAX__ / 2)

using namespace std;
typedef pair<int, int> ipair;

int main(int argc, char **argv) {
    int A, B;
    cin >> A >> B;

    int res;
    if(A >= 13)
        res = B;
    else if(A >= 6)
        res = B / 2;
    else
        res = 0;
    cout << res << endl;
}

Measured memory_bytes: 256
#define r return
#define a (int u,int v,int x,int y,char m,int c)
i,j,n,f[6];w[8]={1,1,0,-1,-1,-1,0,1};h[8]={0,1,1,1,0,-1,-1,-1};char t[10][10],g[2]={'o','x'};l a{if(t[x][y]=='.'||t[x][y]=='0')r 0;if(t[x][y]==m)r c;r l(u,v,x+u,y+v,m,c+1);}s a{int k,d;d=0;if(t[x][y]!='.')r 0;for(k=0;k<8;k++)d+=l(w[k],h[k],x+w[k],y+h[k],m,0);r d;}p a{if(t[x][y]=='0'||t[x][y]=='.')r 0;if(t[x][y]==m)r 1;if(p(u,v,x+u,y+v,m,0)){t[x][y]=m;r 1;}else r 0;}o a{int k;t[x][y]=m;for(k=0;k<8;k++)p(w[k],h[k],x+w[k],y+h[k],m,0);r 0;}main(){for(i=0;i<10;)t[0][i]=t[9][i++]='0';for(i=1;i<9;t[i][0]=t[i++][9]='0')scanf("%s",&t[i][1]);for(n=f[1]=-1;f[n]=-1;n=(n+1)%2){for(i=n?8:1;n?i>-1:i<9;n?i--:i++)for(j=n?8:1;n?j>-1:j<9;n?j--:j++)f[n]<s(0,0,i,j,g[n],0)?f[2+n]=i,f[4+n]=j,f[n]=s(0,0,i,j,g[n],0):0;f[n]!=0?o(0,0,f[2+n],f[4+n],g[n],0):0;if(f[0]==0&&f[1]==0)break;}for(i=1;i<9;i++){for(j=1;j<9;j++)printf("%c",t[i][j]);puts("");}r 0;}

Measured memory_bytes: 524
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;
int main(){
    vector<int> in(5,0);
    int i;
    for(i = 0;i<5;i++){
        cin >> in[i];
    }
    int last,min=99;
    vector<int> amari(5,0);
    for(i=0;i<5;i++){
        amari[i] = in[i]%10;
        if(amari[i] == 0){
            continue;
        }
        else if(min>amari[i]){
            min = amari[i];
            last = i;
        }
    }
    int sum = 0;
    for(i=0;i<5;i++){
        if(i ==last){
            sum += in[i];
        }
        else{
            if(in[i]%10 ==0){
                sum += in[i];
            }
            else{
                sum += (in[i]/10+1)*10;
            }
        }
    }
    cout <<sum << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<numeric>
#include<math.h>
#include<algorithm>
#include<iomanip>
#include<bitset>
#include<list>
using namespace std;

int main() {

	int N, K;
	cin >> N >> K;

	if (N % K == 0) {
		cout << 0 << endl;
	}
	else {
		cout << 1 << endl;
	}

	return 0;
}


Measured memory_bytes: 256
x = int(input())


def is_prime(n):
    n_sqrt = n ** 0.5
    if n == 2:
        return True
    if n % 2 == 0:
        return False
    for num in range(3, int(n_sqrt), 2):
        if n == num:
            return True
        if n % num == 0:
            # 素数ではない
            return False
    return True


while not is_prime(x):
    x += 1

print(x)


Measured memory_bytes: 2940
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>

using namespace std;

int main(){
	int N,dam;
	vector<int> p;
	int cnt,pnt=0;
	scanf("%d",&N);
	for(int i=0;i<N;i++){
		scanf("%d",&dam);
		p.push_back(dam);
	}
	sort(p.begin(),p.end());
	for(int i=1;i<=p[N-1];i++){
		cnt=0;
		for(int j=0;j<N;j++){
			if(p[j]>=i)
			cnt++;
		}
		if(cnt>=i)
		pnt=i;
	}
	printf("%d\n",pnt);
}


Measured memory_bytes: 2780
s = input()
n = len(s)
ans = "No"
cnt = 0
if s[::1] == s[::-1]:
    cnt += 1
if s[:int((n-1)/2):1] == s[int((n-1)/2)-1::-1]:
    cnt += 1
if s[int((n+1)/2)::1] ==  s[:int((n-1)/2):-1]:
    cnt += 1
if cnt == 3:
    ans = "Yes"
print(ans)

Measured memory_bytes: 9004