akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static MyUtil;

class MyUtil
{
    public static void Swap<T>(ref T a, ref T b)
    {
	var t = a;
	a = b;
	b = t;
    }

    public static int[] ReadIntArray()
    {
	return ReadLine().Split().Select(x => int.Parse(x)).ToArray();
    }

    public static long[] ReadLongArray()
    {
	return ReadLine().Split().Select(x => long.Parse(x)).ToArray();
    }
}

class Program
{
    public static void Main()
    {
	int a, b, k;
	var t = ReadIntArray();
	a = t[0]; b = t[1]; k = t[2];

	for (int i = Math.Min(a, b); i > 0; i--)
	{
	    if ((a%i) == 0 && (b%i) == 0){ k--; }
	    if (k == 0)
	    {
		WriteLine(i);
		return;
	    }
	}
    }
}


Measured memory_bytes: 13268
#include<bits/stdc++.h>
#define ull unsigned long long
#define ll long long
#define pb push_back
#define endl '\n'
#define line cout<<"----------------------"<<endl
#define mp make_pair
#define mod 1000000007
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL)
#define filein freopen("input.txt","r",stdin)
#define fileout freopen("output.txt","w",stdout)
using namespace std;
const ll  mx=200009;
vector<ll > v[mx];
ll  sub[mx];
pair<ll ,ll > call(ll  s, ll  par)
{
    ll  white=1,black=1;
    for(auto x: v[s])
    {
        if(x==par) continue;
        pair<ll ,ll > temp=call(x,s);
        white=white*(temp.first+temp.second);
        white%=mod;
        black=black*temp.first;
        black%=mod;
    }
    return {white,black};
}
int  main()
{

    ll  n;
    cin>>n;
    for(ll  i=0;i<n-1;i++)
    {
        ll  a,b;
        cin>>a>>b;
        v[a].pb(b);
        v[b].pb(a);
    }
    pair<ll ,ll > ans=call(1,-1);
    cout<<(ans.first+ans.second)%mod<<endl;
}


Measured memory_bytes: 14976
#include<bits/stdc++.h>
#define pi              acos(-1)
#define ll              long long
#define ld              long double
#define gcd             __gcd
#define bitscount       __builtin_popcount
#define ff              first
#define ss              second
#define MAXX            1e18
#define FastRead        ios_base::sync_with_stdio(false);cin.tie(NULL)
//__builtin_popcount()  -->  counts how many 1 s are in a binary represented integer
//accumulate() --> finds sum of an array of integers
using namespace std;
int main()
{
    ll n, i, j, k;
    cin>>n;
    vector<vector<ll> > v(n, vector<ll>(3)), dp(n, vector<ll>(3));
    for(i=0; i<n; i++){
        for(j=0; j<3; j++)
            cin>>v[i][j];
    }
    for(i=0; i<n; i++){
        if(i == 0){
            for(j=0; j<3; j++)
                dp[i][j] = v[i][j];
        }
        else{
            for(j=0; j<3; j++){
                dp[i][j] = -MAXX;
                for(k=0; k<3; k++){
                    if(k!=j)
                        dp[i][j] = max(dp[i][j], v[i][j] + dp[i-1][k]);
                }
            }
        }
    }
//    for(i=0; i<n; i++){
//        for(j=0; j<3; j++)
//            cout<<dp[i][j]<<" ";
//        cout<<endl;
//    }
    cout<<max({dp[n-1][0], dp[n-1][1], dp[n-1][2]});
}


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

#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define repr(i,n) for(int i=(n);i>=0;--i)
#define cinv(n,vec) V vec(n);for(auto&v:vec)cin>>v;
#define int long long
#define itn int
#define pb push_back
#define m_p make_pair
#define m_t meke_tuple
#define p_p(a,b) pb(m_p(a,b))
#define all(a) a.begin(),a.end()
#define SORT(a) sort(all(a))
#define RSORT(a) sort(all(a));reverse(all(a))
#define UNIQUE(a) a.erase(unique(all(a)),a.end())
#define SZ(a) (ll)(a.size())
#define ENDL cout<<endl
#define debg(a) cout<<#a<<" "<<a<<endl;
#define debgp(a) cout<<#a<<" "<<a.fi<<" : "<<a.se<<endl
#define call(a) for(auto i:a)cout<<i<<" ";cout<<endl
#define show(a) rep(ghf,SZ(a)){rep(kjh,SZ(a[ghf])){cout<<(a[ghf][kjh]<10?" ":"")<<a[ghf][kjh]<<" ";}ENDL;}
#define out(a) cout<<(a)<<endl
#define fi first
#define se second
#define Vec vector
#define P pair
#define VV(type,name,y,x,a) vector<vector<type>> name = vector<vector<type>>(y,vector<type>(x,a))
typedef long long ll;
typedef double D;
typedef long double LD;
typedef string str;
typedef vector<ll> V;
typedef pair<ll,ll> Pi;
typedef vector<Pi> VP;
const long long INF = 1LL<<60;
const long long MOD = 1e9+7;
void Yes(){cout<<"Yes"<<endl;}
void No(){cout<<"No"<<endl;}
void YN(bool b){cout<<(b?"Yes":"No")<<endl;}
template<class T>inline T gcd(T a,T b){if(b==0)return a; return(gcd(b,a%b));}
template<class T>inline T lcm(T a,T b){return a/gcd(a,b)*b;}
template<class T>inline bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int a,b;
  cin>>a>>b;
  if(a>12)out(b);
  else if(a>=6)out(b/2);
  else cout<<0<<endl;
  
  
  
  
  return 0;
}



Measured memory_bytes: 256
//package atcoder;
 
import java.util.*;
 
public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int A[] = new int [N-1];
		for(int i=0;i<N-1;i++) {
			A[i] = sc.nextInt();
		}
		Map<Integer,Integer> map = new HashMap<Integer,Integer>();
		for(int i=1;i<=N;i++) {
			map.put(i,0);
		}
		for(int j=0;j<N-1;j++) {
          int old = map.get(A[j])+1;
			map.put(A[j],old);
		}
		for(int i=1;i<=N;i++){
          System.out.println(map.get(i));
        }
    }
}


Measured memory_bytes: 73520
#include <bits/stdc++.h>
using namespace std;
#define dhoom ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);  
typedef long long ll;
typedef long double ld;
const ll inf = 1e18;
const int nax = 2e6 + 7;
const ll mod = 1e9 + 7;
//ll tree[4 * nax];
//9uS-22RSwk7gQqh
int main()
{
	int a , b , c;
	cin >> a >> b >> c;
	for(int i = 1 ; i <= 100000 ; i++){
		if(a*i%b == c%b)
			return cout << "YES" , 0;
	}
	cout << "NO" << endl;
	return 0;
} 




Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static int n = 0;
    public static int[] data = new int[100000];
    public static int q = 0;
    public static int[] targets = new int[50000];

    public static void main(String[] args) {
        Scanner num = new Scanner(System.in);
        n = num.nextInt();

        for(int i = 0; i < n; i++) {
            data[i] = num.nextInt();
        }

        q = num.nextInt();

        for(int i = 0; i < q; i++) {
            targets[i] = num.nextInt();
        }

        if(num != null) {
            num.close();
        }
        int result = 0;

        for(int i = 0; i < q; i++) {
            result += calc(0, n - 1, targets[i]);
        }

        System.out.println(result);
    }

    public static int calc(int left, int right, int target) {
        if(left > right) {
            return 0;
        }
        
        if(data[(left + right) / 2] == target) {
            return 1;
        } else if(data[(left + right) / 2] > target) {
            return calc(left, (left + right) / 2 - 1, target);
        } else {
            return calc((left + right) / 2 + 1, right, target);
        }
    }
}


Measured memory_bytes: 69760
using System;
using System.Linq;
class Test{
 
  public static void Main(){
    
    var KN =  Console.ReadLine().Split(' ').Select(n => int.Parse(n)).ToList();
    var nums = Console.ReadLine().Split(' ').Select(n => int.Parse(n)).ToList();
    long between = 0;
    for(int i =0; i<KN[1]; i++){
      if(i == nums.Count-1){
        if(KN[0] - nums[i] + nums[0] > between ){
          between = KN[0] - nums[i] + nums[0];
        }
      }else{
        if(nums[i+1]- nums[i] > between){
          between = nums[i+1]- nums[i];
        }
      }
    }
    
    Console.WriteLine(KN[0]-between);
  }
}

Measured memory_bytes: 34780
#include <iostream>
#include <math.h>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

typedef long long lint;

using namespace std;

int main(){
  int N,T;
  cin>>N>>T;
  int ans=9999;
  REP(i,N){
    int c,t;
    cin>>c>>t;
    if(t<=T)ans=min(ans,c);
  }
  if(ans!=9999)cout<<ans<<endl;
  else cout<<"TLE"<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb push_back
#define PI acos(-1)
#define mp make_pair
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define F first
#define sd(x) scanf("%d",&x)
#define sd2(x,y) scanf("%d%d",&x,&y)
#define sdl(x) scanf("%lld",&x)
#define sd2l(x,y) scanf("%lld%lld",&x,&y)
#define maxn 100010
#define S second
#define ll long long int
#define inf 1000002014
#define infl 1000000000000020000ll
#define mod 1000000007
#define clrs(x) memset(x,0,sizeof x)
#define sz(x) (int) x.size()
#define pi pair< int,int >
#define pii pair<pi,int>
#define pu push
#define ld long double
#define trace1(x)  cerr << #x << ": " << x << endl
#define trace2(x, y)  cerr << #x << ": " << x << " | " << #y << ": " << y << endl
using namespace std;
ll arr[maxn],brr[maxn];
int main(int argc, char const *argv[])
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int n;
    sd(n);
    ll ans = 0;
    for (int i = 1; i <= n; ++i)
    {
        sd2l(arr[i],brr[i]);
    }
    for (int i = n; i >= 1; --i)
    {
        arr[i]+=ans;
        if(arr[i]%brr[i]!=0)
        {
            ll dif = brr[i]-(arr[i]%brr[i]);
            ans+=dif;
        }
    }
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 1792
#include<iostream>//打表做法，危险动作，请勿效仿 
#include<cstdio>
#include<cstring>
using namespace std;
char s[1000005];
bool bo;
long long ji;
int main(){
	scanf("%s",&s);
	long long len=strlen(s);
	for(long long i=0;i<len-1;i++){
		if(s[i]!=s[i+1])bo=1;
	}
	if(bo==1){
		if(s[0]!=s[len-1])
			ji=len-2;
		else ji=len-3;
	}
	else ji=0;
	if(ji%2==1)cout<<"First";
	else cout<<"Second";
}

Measured memory_bytes: 384
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($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)*}
    };
}

#[allow(unused_macros)]
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)*}
    };

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

#[allow(unused_macros)]
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, bytes) => {
        read_value!($next, String).into_bytes()
    };

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

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

fn main() {
    input! {
        a: usize,
        b:usize,
        k:usize,
    }

    let mut count = 0;
    for i in (1..std::cmp::min(a, b) + 1).rev() {
        if a % i == 0 && b % i == 0 {
            count += 1;
            if count == k {
                println!("{}", i);
                break;
            }
        }
    }
}


Measured memory_bytes: 4352
import math
import time

a, b, x = map(int, input().split())

theta = 0
if x/a > a*b/2:
    h = (a*b - x/a) * 2 / a
    theta = math.atan2(h, a)
else:
    w = x/a * 2 / b
    theta = math.atan2(b, w)
    
print(theta/math.pi*180)


Measured memory_bytes: 3184
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#include <sstream>
#define IOS ios_base::sync_with_stdio(0); cin.tie(0);
#define mod 1000000007
#define eps 1e-6
#define ll long long
#define INF 0x3f3f3f3f
#define MEM(x,y) memset(x,y,sizeof(x))
#define pb push_back
#define mk make_pair
#define pi pair<int, int>
#define rep(i, a, b) for (int i = (a); i <= (b); ++i)
#define per(i,a,b) for(int i=a;i>=(b);--i)
using namespace std;
int dt[][2]= {{1,0},{-1,0},{0,1},{0,-1},{0,0}};
//typedef pair<int, int> P;
//priority_queue<int, vector<int>, greater<int> > q;
int main()
{
   //IOS;
   string s;
   cin >> s;
   int n=s.length();
   rep(i,0,n-1){
       if(s[i]=='7'){
           cout << "Yes";
           return 0;
       }
   }
   cout << "No";
}


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

int main()
{
    int N = 0, Y = 0;
    cin >> N >> Y;
    for ( int i = 0; i < N+1; i++ )
    {
        for ( int j = 0; j < N+1-i; j++ )
        {
                if ( i*10000 + j*5000 + (N-i-j)*1000 == Y )
                {
                    cout << i << " " << j << " " << N-i-j << endl;
                    return 0;
                }
        }
    }
    cout << -1 << " " << -1 << " " << -1 << endl;
}


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



int main(){

    ios::sync_with_stdio(0) ;
    cin.tie(0) ;

    long long n, m ;
    cin >> n >> m ;
    long long s = 0;
    long long f = 1e9 ;

    for(long long i = 0; i < m; i++){

        long long l, r ;
        cin >> l >> r ;
        s = max(l, s) ;
        f = min(f, r) ;

    }
    if(f >= s){

        cout << f - s + 1 ;
        return 0 ;

    }
    cout << 0 ;
    return 0 ;

}


Measured memory_bytes: 256
<?php
/**
 * ABC126
 * B - YYMM or MMYY
 */

// $s = trim(fgets(STDIN));
// fscanf(STDIN, "%d %d", $a, $b);
// $n = array_map('intval', explode(' ', trim(fgets(STDIN))));

$s = trim(fgets(STDIN));

$s1 = substr($s, 0, 2);
$s2 = substr($s, 2, 4);

$s1_is_month = is_month($s1);
$s2_is_month = is_month($s2);

$result = solver($s1_is_month, $s2_is_month);

echo $result, PHP_EOL;

function is_month($s) {
    $months = ['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12'];
    return in_array($s, $months);
}

function solver($s1_is_month, $s2_is_month) {
    if ($s1_is_month and $s2_is_month) {
        return 'AMBIGUOUS';
    }
    if ($s1_is_month) {
        return 'MMYY';
    }
    if ($s2_is_month) {
        return 'YYMM';
    }
    return 'NA';
}


Measured memory_bytes: 4604
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
    int a,b,d,x=1;
    cin>>a>>b;
    d=b;
    while(d)
    {
        d=d/10;
        x*=10;
    }
    a=a*x+b;
    double c=sqrt(a*1.0);
    d=c;
    if(c*c==d*d)
    {
        cout<<"Yes"<<endl;
    }
    else cout<<"No"<<endl;
    return 0;
}


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

		// 文字列の入力
		String a = sc.next();
     	String b = sc.next();
      	String c = sc.next();
		// 出力
		System.out.println(a + " " + b + " " + c);
	}
}

Measured memory_bytes: 23252
#include <bits/stdc++.h>
#define N 1000005
#define ll long long int 	
#define MP make_pair
#define pb push_back
#define ppb pop_back
#define sp " "
#define endl "\n"
#define fi first
#define se second
#define ii pair<int,int>
#define lli pair<ll,ll>
#define fast cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(false)
#define fast2 freopen ("badhair.gir","r",stdin);freopen ("badhair.cik","w",stdout);
#define mod 1000000007
#define fs(x,y) for(ll i=1;i<=y;i++) cin>>x[i]
#define fo(i,x,y) for(ll i=x;i<=y;i++)
#define INF 1000000000005
using namespace std;

ll n,m,ar[N],sum,t;



int main()
{
	fast;
	cin>>n;
	int flag=0;

	fo(i,1,9)
	fo(j,1,9)
	{
		flag=max((ll)flag,(ll)(i*j==n));
	}

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



/*     cd onedrive\desktop\kod
cls

Sinav:21-22 aralik
Aciklama: Muhtemelen 25 aralik
*/

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n); i >= 0; i--)
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define ALL(obj) begin(obj), end(obj)
using namespace std;
using ll = long long;
using ull = unsigned long long;

const int INF = 2100100100;
const int MOD = 1e9 + 7;

// 多次元 vector 生成
template <class T> vector<T> make_vec(size_t a) { return vector<T>(a); }
template <class T, class... Ts> auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <class T> bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
int main() {
    // cin.tie(0);
    // ios::sync_with_stdio(false);

    int N, D;
    cin >> N >> D;
    int t = 2 * D + 1;
    cout << (N + t - 1) / t << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include<string>
#include<math.h>
#include<map>
#include<algorithm>
using namespace std;
int main()
{
	int N, d[51],ans=0;
	cin >> N ;
	for (int i = 0;i < N;i++)cin >> d[i];
	for (int i = 0;i < N;i++)
	{
		for (int j = i + 1;j < N;j++) 
		{
			 ans += d[i] * d[j];
		}
	}
	cout << ans;


}

Measured memory_bytes: 256
import java.util.*;

public class Main{

    private static int m;
    private static int n;;
    private static int max;
    private static int q;
    private static int[] a;
    private static int[] b;
    private static int[] c;
    private static int[] d;

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

        n = sc.nextInt();
        m = sc.nextInt();
        q = sc.nextInt();

        a = new int[q];
        b = new int[q];
        c = new int[q];
        d = new int[q];

        for(int i = 0; i < q; i++){
            a[i] = sc.nextInt() - 1;
            b[i] = sc.nextInt() - 1;
            c[i] = sc.nextInt();
            d[i] = sc.nextInt();
        }

        int[] A = new int[n];
        Arrays.fill(A, 1);
        max = 0;
        array(A, n - 1);

        System.out.println(max);

    }

    static void array(int[] A, int x){
        if(-1 == x){
            //System.out.println(Arrays.toString(A));
            int point = 0;
            for(int i = 0; i < q; i++){
                if(A[b[i]] - A[a[i]] == c[i]){
                    point += d[i];
                }
            }
            max = Math.max(max, point);
            //System.out.println(point);
            return;
        }


        if(x == n - 1){
            for(int i = 1; i <= m; i++){
                A[x] = i;
                array(A, x - 1);
            }

        }else{
            for(int i = A[x + 1]; i > 0; i--){
                A[x] = i;
                array(A, x - 1);
            }
        }

    }

}


Measured memory_bytes: 37784
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <list>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <utility>
#include <complex>
#include <functional>
#include <climits>

using namespace std;

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> v(m);
    for(int i=0; i<m; i++) {
        cin >> v[i];
    }
    sort(v.begin(), v.end());
    vector<int> r(m-1);
    for(int i=0; i<m-1; i++) {
        r[i] = v[i+1] - v[i];
    }
    sort(r.begin(), r.end());
    int sum = 0;
    for(int i=0; i<m-n; i++) {
        sum += r[i];
    }
    cout << sum << endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <cmath>
#include <iomanip>

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
template<class T>using vv = vector<vector<T>>;

#define in(v) v; cin >> v;
// #define rep(i,n) for(int i=0;i<(n);++i)
#define all(f,c,...) (([&](decltype((c)) cccc) { return (f)(begin(cccc), end(cccc), ## __VA_ARGS__); })(c))
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

#define rrep(i,n) for(int i=(n);i>=0;--i)
const int dx[4]={1,0,-1,0}, dy[4]={0,1,0,-1};
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}

// debug
template<class T>ostream& operator<<(ostream& os,const vector<T>& vec){os<<"{";for(int i=0;i<vec.size();++i)os<<(i?", ":"")<<vec[i];os<<"}";return os;}
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>& rhs){os<<"("<<rhs.first<<", "<<rhs.second<<")";return os;}

#ifdef LOCAL
void debug() {cerr << "\n";}
template<class First> void debug(const First& first) {cerr<<first<<"\n";}
template<class First, class... Rest> void debug(const First& first, const Rest&... rest) {cerr<<first<<",";debug(rest...);}
#else
#define debug(...) 42
#endif

int main() {
  ll in(n);


  // if (n > 1e5)
  //   return 0;

  // int ans2 = 0;
  // rep(i, 2, n+1) {
  //   int j = n;
  //   while (j % i == 0) j /= i;
  //   if (j % i == 1) {
  //     // debug(i);
  //     ++ans2;
  //   }
  // }

  ll ans = 1; // それ自身

  ll N = n;
  for (ll i = 2; i * i <= N; ++i) {
    if (N % i == 0) {
      ll M = n;
      while (M % i == 0) M /= i;
      if (M % i == 1)
        ++ans;
      if (n % (N / i) == 1)
        ++ans;
    }
  }
  if (N > 1 && N != n) {
    ll M = n;
    while (M % N == 0) M /= N;
    if (M % N == 1)
      ++ans;
  }


  N = n - 1;
  ll tmp = 1;
  for (ll i = 2; i * i <= N; ++i) {
    int count = 0;
    while (N % i == 0) {
      N /= i;
      ++count;
    }
    tmp *= count + 1;
  }
  if (N > 1)
    tmp *= 2;
  --tmp; // 1が含まれているぶん


  // if (ans2 != tmp + ans)
  //   debug("NG!!", ans2, tmp, ans);
  cout << tmp + ans << endl;

  return 0;
}


Measured memory_bytes: 256
from collections import Counter

S = input()
T = input()

lenS = len(Counter(S))
lenT = len(Counter(T))
flag = 0

if lenS == lenT:
    for i in range(lenS):
        if Counter(S).most_common()[i][1] == Counter(T).most_common()[i][1]:
            continue
        else:
            flag = 1
            break
else:
    flag = 1
    
if flag == 0:
    print('Yes')
else:
    print('No')

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

inline __int128 mod(__int128 a, __int128 m) {
    return (a % m + m) % m;
}

__int128 extGcd(__int128 a, __int128 b, __int128 &p, __int128 &q) {  
    if (b == 0) { p = 1; q = 0; return a; }  
    __int128 d = extGcd(b, a%b, q, p);  
    q -= a/b * p;  
    return d;  
}

pair<__int128, __int128> ChineseRem(__int128 b1, __int128 m1, __int128 b2, __int128 m2) {
  __int128 p, q;
  __int128 d = extGcd(m1, m2, p, q); // p is inv of m1/d (mod. m2/d)
  if ((b2 - b1) % d != 0) return make_pair(0, -1);
  __int128 m = m1 * (m2/d); // lcm of (m1, m2)
  __int128 tmp = (b2 - b1) / d * p % (m2/d);
  __int128 r = mod(b1 + m1 * tmp, m);
  return make_pair(r, m);
}

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
    return (ull)rng() % B;
}

ll solve(ll n){
	ll nn=2*n;
	vector<pair<ll,ll>> v;
	for(ll i=2;i*i<=nn;i++){
		if(nn%i==0){
			int cnt=0;
			while(nn%i==0){
				cnt++;
				nn/=i;
			}
			v.push_back({i,cnt});
		}
	}
	if(nn>1)v.push_back({nn,1});
	ll res=2*n-1;
	int m=v.size();
	vector<ll> vv(m);
	for(int i=0;i<m;i++){
		ll p=1;
		for(int j=0;j<v[i].second;j++){
			p*=v[i].first;
		}
		vv[i]=p;
	}
	for(int i=1;i<(1<<m)-1;i++){
		ll p=1,q=1;
		for(int j=0;j<m;j++){
			if((1<<j)&i)p*=vv[j];
			else q*=vv[j];
		}
		auto k=ChineseRem(0,p,q-1,q);
		res=min(res,(ll)k.first);
	}
	return res;
}

ll solve2(ll n){
	ll sum=0;
	for(ll i=1;i<=2*n;i++){
		sum+=i;
		if(sum%n==0)return i;
	}
	return 0;
}

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	ll n; cin >> n;
	// n=myrand(100000000);
	cout << solve(n) << endl;
	// cout << solve2(n) << endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
using namespace std;
using lint = long long;
using pi = pair<int, int>;
const int MAXN = 200005;
 

typedef long long ll;

int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  string s, ss;
  cin >>  s >> ss;
  ss = ss.substr(0, s.length());
  if(ss == s) cout <<"Yes";
  else cout <<"No";
  return 0;
}

/*
         ,--"""",--.__,---[],-------._         
       ,"   __,'            \         \--""""""==;-
     ," _,-"  "/---.___     \       ___\   ,-'',"
    /,-'      / ;. ,.--'-.__\  _,-"" ,| `,'   /
   /``""""-._/,-|:\       []\,' ```-/:;-. `. /
             `  ;:::      ||       /:,;  `-.\
                =.,'__,---||-.____',.=
                =(:\_     ||__    ):)=
               ,"::::`----||::`--':::"._
             ,':::::::::::||::::::::::::'.
    .__     ;:::.-.:::::__||___:::::.-.:::\     __,
       """-;:::( O )::::>_|| _<::::( O )::::-"""
   =======;:::::`-`:::::::||':::::::`-`:::::\=======
    ,--"";:::_____________||______________::::""----.          , ,
         ; ::`._(    |    |||     |   )_,'::::\_,,,,,,,,,,____/,'_,
       ,;    :::`--._|____[]|_____|_.-'::::::::::::::::::::::::);_
      ;/ /      :::::::::,||,:::::::::::::::::::::::::::::::::::/
     /; ``''''----------/,'/,__,,,,,____:::::::::::::::::::::,"
     ;/                :);/|_;| ,--.. . ```-.:::::::::::::_,"
    /;                :::):__,'//""\\. ,--.. \:::,:::::_,"
   ;/              :::::/ . . . . . . //""\\. \::":__,"
   ;/          :::::::,' . . . . . . . . . . .:`::\
   ';      :::::::__,'. ,--.. . .,--. . . . . .:`::`
   ';   __,..--'''-. . //""\\. .//""\\ . ,--.. :`:::`
   ;    /  \\ .//""\\ . . . . . . . . . //""\\. :`::`
   ;   /       . . . . . . . . . . . . . . . . .:`::`
   ;   (          . . . . . . . . . . . . . . . ;:::`
   ,:  ;,            . . . . . . . . . . . . . ;':::`
   ,:  ;,             . . . . . . . . . . . . .;`:::
   ,:   ;,             . . . . . . . . . . . . ;`::;`
    ,:  ;             . . . . . . . . . . . . ;':::;`
     :   ;             . . . . . . . . . . . ,':::;
      :   '.          . . . . . . . .. . . .,':::;`
       :    `.       . . . . . . . . . . . ;::::;`
        '.    `-.   . . . . . . . . . . ,-'::::;
          `:_    ``--..___________..--'':::::;'`
             `._::,.:,.:,:_ctr_:,:,.::,.:_;'`
________________`"\/"\/\/'""""`\/"\/""\/"____________________________
 
*/

Measured memory_bytes: 3644
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <cstring>
#include <utility>
#include <vector>
#include <complex>
#include <valarray>
#include <fstream>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <random>

#define _overload(a, b, c, d, ...) d
#define _rep1(X, A, Y) for (int (X) = (A);(X) <= (Y);++(X))
#define _rep2(X, Y) for (int (X) = 0;(X) < (Y);++(X))
#define rep(...) _overload(__VA_ARGS__, _rep1, _rep2)(__VA_ARGS__)
#define rrep(X, Y) for (int (X) = Y-1;(X) >= 0;--(X))
#define all(X) (X).begin(),(X).end()
#define len(X) ((int)(X).size())
#define mod(n, m) (((n)%(m)+(m))%(m))
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;
const int INFINT = 1 << 30;                          // 1.07x10^ 9
const ll INFLL = 1LL << 60;                          // 1.15x10^18
const double EPS = 1e-10;
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

const int MAX_N = 10, MAX_Q = 50;
int N, M, Q;
int a[MAX_Q], b[MAX_Q], c[MAX_Q], d[MAX_Q];

int memo[MAX_N];

ll calc() {
    ll score = 0;
    for (int i = 0; i < Q; ++i) {
        if ((memo[b[i]] - memo[a[i]]) == c[i]) score += d[i];
    }
    return score;
}

void dfs(int n, int m, ll &ans) {
    if (n == N) {
        ans = max(ans, calc());
        return;
    }
    for (int j = m; j <= M; ++j) {
        memo[n] = j;
        dfs(n + 1, j, ans);
    }

}

int main() {

    cin >> N >> M >> Q;
    rep(i, Q) {
        cin >> a[i] >> b[i] >> c[i] >> d[i];
        --a[i]; --b[i];
    }

    ll ans = 0;
    dfs(0, 1, ans);

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3636
#include<iostream>
#include<map>
#include<vector>
#include<string>

using namespace std;
#define mp make_pair
int main(){
  int n;
  string a;
  long long b,c;
  map<string,long long> data;
  vector<string> id;
  while(true){
    id.clear();
    data.clear();
    cin>>n;
    if(!n)
      break;
    for(int i=0;i<n;i++){
      cin>>a>>b>>c;
      c*=b;
      if(data.find(a)==data.end()){
	data.insert(mp(a,c));
	id.push_back(a);
      }
      else{
	data[a]+=c;
      }
    }
    bool empty = true;
    for(int i=0;i<id.size();i++){
      if(data[id[i]]>=1000000){
	cout<<id[i]<<endl;
	empty = false;
      }
    }
    if (empty)
      cout<<"NA"<<endl;

  }
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A,B,N,x,y,n,ans;
  cin >> A >> B;
  
  for(N=A;N<=B;N++){
    x=N/10000;
    y=N%10000%1000%100%10;
  	if(x==y){
    	n=(N-x*10000-y)/10;
    	x=n/100;
    	y=n%100%10;
    	if(x==y){
        	ans++;
        }
    }
  }
  cout << ans << endl;
}

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

int selectionSort(int A[], int n);

int main(void)
{
    int n, i;
    cin >> n;
    int *A = new int[n];
    for (i = 0; i < n; i++)
    {
        cin >> A[i];
    }
    
    int count = selectionSort(A, n);
    
    for (i = 0; i < n - 1; i ++)
    {
        cout << A[i] << " " ;
    }
    cout << A[i] << endl << count << endl;
}
int selectionSort(int A[], int n)
{
    int i, j, min, count = 0;
    for (i = 0; i < n; i++)
    {
        min = i;
        for  (j = i; j < n; j++)
        {
            if (A[j] < A[min])
                min = j;
        }
        if (min != i)
        {
            swap(A[i], A[min]);
            count++;
        }
    }
    return count;
}


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

x = int(input())

if x<600:
    print(8)
elif x<800:
    print(7)
elif x<1000:
    print(6)
elif x<1200:
    print(5)
elif x<1400:
    print(4)
elif x<1600:
    print(3)
elif x<1800:
    print(2)
elif x<2000:
    print(1)

Measured memory_bytes: 9180
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
using namespace std;
#define pb                emplace_back
#define ppb               pop_back
#define pf                push_front
#define ppf               pop_front
#define all(x)            (x).begin(),(x).end()
#define uniq(v)           (v).erase(unique(all(v)),(v).end())
#define sz(x)             (ll)((x).size())
#define ff                first
#define ss                second
#define mem1(a)           memset(a,-1,sizeof(a))
#define mem0(a)           memset(a,0,sizeof(a))
#define ppc               __builtin_popcount
#define ppcll             __builtin_popcountll
#define isBitset(S,i)     ((S>>i)&1)
#define print(x) 		  for(auto it:x) cout<<it<<" "; cout<<"\n"; 
#define MOD 1000000007
ll gcd(ll a, ll b){
    while(true){
        if(a>b)
            swap(a,b);
        if (a == 0) 
            return b; 
        ll p = b % a  , q = a;
        a = p;
        b = q;
    }
}
 
ll powerMod(ll x,ll y){
    ll res = 1;
    x %= MOD;
    while(y > 0){
        if(y & 1)res = (res*x)%MOD;
        y = y >> 1;
        x = (x * x)%MOD;
    }
    return res%MOD;
}
 
string binary(ll s) {
    string res = "";
    while(s != 0) {
        res += (char)('0' + s % 2);
        s /= 2;
    }
    reverse(res.begin() , res.end());
    return res;
}
void solve()
{
	ll n;cin>>n;
	ll a[n];
	for(ll i=0;i<n;++i)
		cin>>a[i];
	ll ans=0;
	for(ll i=1;i<n;++i)
	{
		if(a[i]<a[i-1])
		{
			ans+=abs(a[i]-a[i-1]);
			a[i]=a[i-1];
		}
	}
	cout<<ans;
}
int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif    
        solve();
    return 0;
}

Measured memory_bytes: 5164
x,n = map(int,input().split())
arr = list(map(int,input().split()))
l = x
r = x
while (l in arr and r in arr):
    l-=1
    r+=1
la = abs(x-l)
ra = abs(x-r)
if (la == ra):
    if (l not in arr):
        print(l)
        exit(0)
    if (r not in arr):
        print(r)
        exit(0)
else:
    if (la < ra):
        print(l)
        exit(0)
    else:
        print(r)
        exit(0)


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

if M == 0:
    print(int((N * (N - 1)) / 2))
elif N == 0:
    print(int((M * (M - 1)) / 2))
    
else:
    print(int(((M * (M - 1)) + (N * (N - 1))) / 2))
    

Measured memory_bytes: 3060
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons;
import std.math, std.numeric;


void main() {
    int n; scan(n);
    auto a = readln.split.to!(int[]);
    auto b = readln.split.to!(int[]);

    auto bk = new int[][][](30, 2, 0);

    foreach (i ; 0 .. 30) {
        foreach (bj ; b) {
            int bl = bj & ((1<<i) - 1);
            bk[i][(bj >> i) & 1] ~= bl;
        }

        bk[i][0].sort();
        bk[i][1].sort();
    }

    debug {
        writeln(bk);
    }

    int ans;

    foreach (k ; 0 .. 30) {
        long cnt;

        foreach (ai ; a) {
            int al = ai & ((1<<k) - 1);
            if (ai & (1<<k)) {
                cnt += bk[k][0].assumeSorted.lowerBound(2^^k - al).length.to!int;
                cnt += bk[k][1].length.to!int - bk[k][1].assumeSorted.lowerBound(2^^k - al).length.to!int;
            }
            else {
                cnt += bk[k][1].assumeSorted.lowerBound(2^^k - al).length.to!int;
                cnt += bk[k][0].length.to!int - bk[k][0].assumeSorted.lowerBound(2^^k - al).length.to!int;
            }
        }

        debug {
            writefln("%d, %d", k, cnt);
        }

        if (cnt & 1) {
            ans ^= (1 << k);
        }
    }

    writeln(ans);
}








void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}


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

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

const ll mod =  1000000007;
const int inf = 1e9;
const long long INF = 1LL << 60;   // INFの値は1152921504606846976

ll pow(ll x,ll n){  // xのn乗 (mod m)
    ll res = 1;
    if(n > 0){
        res = pow(x,n / 2);
        if(n % 2 == 0){
            res = (res * res) % mod;
        }else{
            res = (((res * res) % mod) * x) % mod;
        }
    }
    return res;
}

int main()
{
    ll n,k;  cin >> n >> k;
    ll ans = 0;
    ll cnt[k+1];  
    rep(i,k+1) cnt[i] = 0;

    for(int i = k; i >= 1; i--){
        cnt[i] = pow(k/i,n);
        for(int j = 2 * i; j < k + 1; j += i){
            cnt[i] -= cnt[j];
        }
    }

    for(int i = k; i >= 1; i--){
        ans += ( i * cnt[i] );
        ans %= mod;
    }
    cout << (ans+mod)%mod << endl;
}

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

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

    ll x;
    cin >> x;

    cout << 2*x/11 + 1 - (x%11 == 0 || x%11 == 5 || x%11 == 6) << endl;
    return 0;
}

Measured memory_bytes: 256
use proconio::{fastout, input};
use std::cmp::max;

#[fastout]
fn main() {
    input! {
        n: usize,
        m: usize,
        k: isize,
        a: [isize; n],
        b: [isize; m]
    }

    let mut av: Vec<isize> = vec![0; n + 1];
    for i in 0..n {
        av[i + 1] = a[i] + av[i];
    }
    let mut bv: Vec<isize> = vec![0; m + 1];
    for i in 0..m {
        bv[i + 1] = b[i] + bv[i];
    }

    let mut ans = 0;
    let mut j = m;
    for i in 0..=n {
        if av[i] > k {
            break;
        }
        while av[i] + bv[j] > k {
            j -= 1;
        }
        ans = max(ans, i + j);
    }
    println!("{}", ans);
}


Measured memory_bytes: 12484
import sys
input = sys.stdin.readline

N = int(input())
H = list(map(int, input().rstrip().split()))

for i in range(N-1):
    if H[i] > H[i+1]:
        print('No')
        sys.exit() 
    H[i+1] = max(H[i], H[i+1]-1)
            
print('Yes')

Measured memory_bytes: 14252
#include <iostream>
#include <vector>
#include <iomanip>
using namespace std;

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

    int N;
    cin >> N;
    vector<double> prob(N);
    for (auto& x : prob) cin >> x;

    double dp[N+1][N+1];
    for (int i = 1; i <= N; i++) dp[0][i] = 0.0;
    for (int i = 0; i <= N; i++) {
        double r = 1;
        for (int j = 0; j < i; j++) {
            r *= (1 - prob[j]);
        }
        dp[i][0] = r;
    }

    for (int i = 1; i <= N; i++) {
        for (int j = 1; j <= i; j++) {
            dp[i][j] = prob[i - 1] * dp[i - 1][j - 1] 
                + (1 - prob[i - 1]) * dp[i - 1][j];  
        }
    }

    double res = 0.0;
    for (int i = N / 2 + 1; i <= N; i++) {
        res += dp[N][i];
    }

    cout << fixed << setprecision(9) << res << "\n";
}



Measured memory_bytes: 70272
#include<bits/stdc++.h>
using namespace std;
 
int main() {
  long long N,i;
  cin>>N;
  long long ans=0;
 
  long long a[N];
  for (i=0;i<N;i++)cin>>a[i];

  long long b[110]={0};
  for (i=0;i<N;i++)b[a[i]]++;
  
  for (i=0;i<110;i++){
    if(b[i])ans++;
  }
  //sort(a,a+N);
  //reverse(a,a+N);
  
  cout << ans << endl;
}

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


using namespace std;
using ll = long long;

int main(void)
{
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    ll n,sqn,ans=0;
    cin >> n;
    for(ll i=1;i*i<=n;++i) sqn=i;
    for(ll i=2;i<=sqn;++i)
    {
        if(n%i!=0) continue;
        ll t=n;
        while(t%i==0)
        {
            t/=i;
        }
        if(t%i==1) ++ans;
    }
    vector<ll> a;
    for(ll i=1;i*i<=n-1;++i)
    {
        if((n-1)%i==0)
        {
            a.push_back(i);
            if(i*i!=n-1) a.push_back((n-1)/i);
        }  
    }
    ans+=a.size();
    cout << ans <<endl;


    return 0;
}


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

using namespace std;
 
void insertionSort(int a[], int n) {
    for(int i=1; i<n;i++) {
        int v = a[i];
        int j = i - 1;
        while(j >= 0 && a[j] > v) {
            a[j + 1] = a[j];
            j--;
        }
        a[j+1] = v;
        
        cout << a[0];
        for(int i = 1; i < n; i++) {
            cout << " " << a[i];
        }
        cout << endl;
    }

}
int main() {
    int n;
    cin >> n;
    
    int x[n];
    for(int i = 0; i < n; i++) {
        cin >> x[i];
    }
    
    
    cout << x[0];
    for(int i = 1; i < n; i++) {
        cout << " " << x[i];
    }
    cout << endl;
    
    insertionSort(x, n);
   
}
    



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

constexpr int MOD = 1e9 + 7;

int main() {
    int N, M; cin >> N >> M;
    vector<bool> stairs(N+1, true);
    for (int i = 0; i < M; i++) {
        int a; cin >> a;
        stairs[a] = false;
    }
    vector<int> ans(N+1);
    ans[0] = 1;
    if (stairs[1]) ans[1] = 1;
    else ans[1] = 0;
    for (int i = 2; i <= N; i++) {
        if (stairs[i]) ans[i] = ans[i-1] + ans[i-2];
        else ans[i] = 0;
        ans[i] %= MOD;
    }
    cout << ans[N] << endl;
}

Measured memory_bytes: 640
#include <stdio.h>
#include <vector>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>
#include <bitset>
#include <map>
#include <set>
#include <tuple>
#include <string.h>
#include <math.h>
#include <random>
#include <functional>

using namespace std;

using ii = pair<int, int>;
using i64 = long long int;
using ii64 = pair<long long int, long long int>;

int main()
{
	//모든 수가 음수인 경우 - 제일 오른쪽이 제일 큰 값이게
	//나머지를 다 깎는다
	//하나라도 양수가 있는 경우 - 맨 왼쪽이 제일 작은 값이게?
	//항상 2n번 안쪽인가?
	//제일 작은거 - 큰 거 골라서.
	//제일 작은게 음수인 경우
	//제일 큰거나 제일 작은 거 하나를 골라서 N번 반복 계산하고
	//그걸 각 칸마다 매번 최댓값 갱신하며 더해주기

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

	vector<i64> arr(n);

	for (int i = 0; i < n; i++)
	{
		scanf("%lld", &arr[i]);
	}

	int minIdx = 0, maxIdx = 0;

	for (int i = 0; i < n; i++)
	{
		if (arr[i] < arr[minIdx])
			minIdx = i;

		if (arr[i] > arr[maxIdx])
			maxIdx = i;
	}

	vector<ii> res;

	if (arr[minIdx] > 0)
	{
		//전부 다 양수. 맨 왼쪽부터 젤 큰 값 갱신해나가며 더해주면 됨
		for (int i = 0; i < n; i++)
		{
			res.emplace_back(maxIdx, i);
			res.emplace_back(i, i);
			maxIdx = i;
		}
	}
	else if (arr[maxIdx] < 0)
	{
		//전부 다 음수. 맨 오른쪽부터 젤 작은 값 갱신해나가며 더해주면 됨
		for (int i = n - 1; i >= 0; i--)
		{
			res.emplace_back(minIdx, i);
			res.emplace_back(i, i);
			minIdx = i;
		}
	}
	else if (llabs(arr[minIdx]) < llabs(arr[maxIdx]))
	{
		for (int i = 0; i < n; i++)
		{
			res.emplace_back(maxIdx, i);
			res.emplace_back(i, i);
			maxIdx = i;
		}
	}
	else
	{
		for (int i = n - 1; i >= 0; i--)
		{
			res.emplace_back(minIdx, i);
			res.emplace_back(i, i);
			minIdx = i;
		}
	}

	printf("%d\n", res.size());

	for (auto& p : res)
		printf("%d %d\n", p.first + 1, p.second + 1);

	return 0;
}

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

long dp(int N, vector<int> &val){
    return 0;
}

long clever(int N, vector<int> &val){

    int minus_num=0;
    for(int i=0; i < N; i++){
        if(val.at(i) < 0){
            minus_num += 1;
            val.at(i) *= -1;
        }
    }
    if(minus_num%2==0){
        long res = accumulate(val.begin(), val.end(), 0L);
        return res;
    }else{
        long res = accumulate(val.begin(), val.end(), 0L);// - ;
        long dif = *min_element(val.begin(),val.end());
        return res-2*dif;
    }
}

int main(){
    int N;
    cin >> N;
    std::vector<int> value(N);
    for(int i=0; i < N; i++){
        cin >> value.at(i);
    }
    long res;
    // res = dp(N, value);
    res = clever(N, value);

    cout << res << endl;
    return 0;
}


Measured memory_bytes: 640
n,m,x=map(int,input().split())
l=[list(map(int,input().split())) for _ in range(n)]
add=[]
for i in range(2**n):
    skill=[0]*(m+1)
    for j in range(n):
        if ((i>>j)&1):
            skill=list(map(sum,zip(skill,l[j])))
    if min(skill[1:])>=x:
        add.append(skill)
if add:
    add.sort()
    print(add[0][0])
else:
    print(-1)

Measured memory_bytes: 11584
#include <stdio.h>
#include <set>
#include <vector>
#include <algorithm>
using namespace std;

int use[10];
int a[10],b[10],ans1,ans2,per[10];
int now=0;int n;

int fin(int tmp){
    if (tmp==n){
        now++;
        //for (int i=0;i<n;++i) printf("%d",per[i]);printf("\n");
        int flag=1;
        for (int i=0;i<n;++i)
            if (a[i]!=per[i])
                flag=0;
        if (flag) ans1=now;
        flag=1;
        for (int i=0;i<n;++i)
            if (b[i]!=per[i])
                flag=0;
         if (flag) ans2=now;
        return 0;
    }
    for (int i=1;i<=n;++i){
        if (use[i]==0){
            use[i]=1;
            per[tmp]=i;
            fin(tmp+1);
            use[i]=0;
        }
    }
}


int main()
{
    int k,x;scanf("%d%d",&k,&x);
    if (k*500>=x) printf("Yes\n");else printf("No");


}


Measured memory_bytes: 128
#include<stdio.h>


int main(int argc, char const *argv[]){
	int n,i,o[27],j,p[27];
	char s[51];
	scanf("%d",&n);
	for(i=0;i<27;i++){
		o[i]=51;
	}
	for(i=0;i<n;i++){
		scanf("%s",s);
		for(j=0;j<27;j++){
			p[j]=0;
		}
		j=0;
		while(s[j]!='\0'){
			p[s[j]-'a']++;
			j++;
		}
		for(j=0;j<27;j++){
			o[j]=(p[j]<o[j])?p[j]:o[j];
		}
	}
	for(i=0;i<27;i++){
		for(j=0;j<o[i];j++){
			printf("%c",'a'+i);
		}
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
using namespace std;
#define MAXW (10000)

int main(){
    int N;
    int W;
    int Val[100],Weigh[100];
    cin>>N;
    cin>>W;
    for(int i=0;i<N;i++){
        cin>>Val[i]>>Weigh[i];
    }
    int res=0;
    int dp[MAXW+10]={};
    for(int i=0;i<N;i++){
        for(int w = W-Weigh[i];w>0;w--){
            if(dp[w]!=0){
                int a = max(dp[w+Weigh[i]],dp[w]+Val[i]);
                res=max(res,a);
                dp[w+Weigh[i]]=a;
            }
        }
        int a=max(dp[Weigh[i]],Val[i]);
        dp[Weigh[i]]=a;
        res=max(res,a);
    }
    /*
    cout<<"配列中身チェック"<<endl;
    for(int i=0;i<=W;i++){
        cout<<dp[i]<<' ';
    }
    cout<<endl;
    cout<<"こたえ"<<endl;
     */
    cout<<res<<endl;
    return 0;
}



Measured memory_bytes: 3132
N = int(raw_input())
ret = ()

for i in range(N):
  ret += (tuple([int(_) for _ in raw_input().split(" ")]),)

t = [[0]*N for _ in range(N)]
d = {}
for i in range(N):
  for j in range(i+1, N):    
    x = ret[i][0] - ret[j][0]
    y = ret[i][1] - ret[j][1]
    if not (x,y) in d:
      d[(x,y)] = []
    if not (-x, -y) in d:
      d[(-x, -y)] = []

    d[(x,y)] += [(i,j)]
    d[(-x,-y)] += [(j, i)]

d = [(len(d[_]), _, d[_]) for  _ in d]
if len(d) == 0:
  print 1
  exit()
d.sort(reverse=True)
d = d[0][2]
ans = [1] * N
current = d[0]
count = 0
while(len(d) > 0):
  count += 1
  current = d[0]
  ans[current[0]] = 0
  ans[current[1]] = 0
  d.remove(current)
  t = [current[0], current[1]]
  c1 = t[0]
  c2 = t[1]

  while(len(d) > 0):
    for i in d:
      if i[1] == c1:
        d.remove(i)
        c1 = i[0]
        ans[c1] = 0
        t = [c1] + t
        break
    else:
      break

  while(len(d) > 0):
    for i in d:
      if c2 == i[0]:
        d.remove(i)
        c2 = i[1]
        ans[c2] = 0
        t = t + [c2]
        break
    else:
      break
  
  #print t
print sum(ans) + count

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

struct UnionFind {
    vector<int> par;
    UnionFind(int N) : par(N) {
        for(int i = 0; i < N; i++) par[i] = i;
    }
    int root(int x) {
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }
    void unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return;
        par[rx] = ry;
    }

    bool same(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

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

  vector<int> p(N);
  for(int i=0;i<N;++i){
    cin>>p.at(i);
  }

  int x,y;
  UnionFind UF(N);
  for(int i=0;i<M;++i){
    cin>>x>>y;
    UF.unite(x-1,y-1);
  }

  int sum=0;
  for(int i=0;i<N;++i){
    if(UF.same(i,p.at(i)-1)){
    ++sum;
    }
  }

  cout<<sum<<endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef pair<int,int> P;
constexpr int INF = 1e9+1;

int main(){
  int n, q;
  string s;
  cin >> n >> s >> q;
  vector<int> K(q);
  rep(i,q) cin >> K[i];

  for (auto k : K) {
    ll a = 0, b = 0, c = 0;
    ll res = 0;
    for (int i = 0; i < n; i++) {
      if (k <= i) {
        if (s[i - k] == 'D') a--, c -= b;
        if (s[i - k] == 'M') b--;
      }
      if (s[i] == 'D') a++;
      if (s[i] == 'M') b++, c += a;
      if (s[i] == 'C') res += c;
    }
    cout << res << endl;
  }
  return 0;
} 

Measured memory_bytes: 1412