akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <string>
#include <map>

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

typedef long long ll;

using namespace std;

int main() {
    string s;
    cin >> s;
    map<char, int> cnt;
    rep(i, 4) {
        auto itr = cnt.find(s[i]);
        if (itr != cnt.end()) cnt[s[i]]++;
        else cnt[s[i]] = 1;
    }

    for(auto itr = cnt.begin(); itr != cnt.end(); ++itr) {
        if (itr->second != 2) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define IINF 100000000
#define INF 300000000000000000
#define MOD 1000000007
#define mod 1000000007
#define INT_MAX_ 2147483647
#define REP(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define REPE(i, a, n) for (ll i = a; i <= (ll)(n); i++)
#define rep(i,n)for (ll i = 0; i < (ll)(n); i++)
#define Endl endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
#define me memset
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef pair<int,int>Pin;
typedef pair<ll,ll>Pll;
template<class T> using V=vector<T>;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
long long GCD(long long a, long long b) {return b?GCD(b,a%b):a;}
long long LCM(long long a, long long b) {return a/GCD(a,b)*b;}
int dx[4]={-1,0,1,0};
int dy[4]={0,-1,0,1};
int ddx[8]={-1,0,1,0,1,1,-1,-1};
int ddy[8]={0,-1,0,1,1,-1,1,-1};
ll cmp1(pair<ll,ll>a,pair<ll,ll> b){
        if(a.se!=b.se)
        return a.se<b.se;
        else
        return a.fi<b.fi;
}
//----------------------------------------------------------------------

//----------------------------------------------------------------------
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------  
    //ll begin_time=clock();
    //-------------------------------
    string s,t;cin>>s>>t;
    string c=t.substr(0,s.length());
    if(s==c){
        cout<<"Yes"<<Endl;
    }
    else cout<<"No"<<Endl;
    //-------------------------------  
    //ll end_time=clock();cout<<"time="<<end_time-begin_time<<"ms"<<endl;
    //-------------------------------
    return 0;
}
//----------------------------------------------------------------------





































Measured memory_bytes: 3640
#include "bits/stdc++.h"
using namespace std;

int main() {
    string s;
    cin >> s;
    if(s[0] != s[1] && s[1] != s[2] && s[2] != s[3]){
        cout << "Good" << endl;
    }else{
        cout << "Bad" << endl;
    }
}

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

#define rep(i,j,n) for(i=j;i<n;i++)
#define repi(i,j,n) for(i=j;i>n;i--)
#define inf 100001
#define M 1000000007
#define ll long long
#define vll vector<long long>
#define vi vector<int>
#define pll pair<long long,long long>
#define pii pair<int,int>
#define vpii vector<pair<int,int> >
#define vpll vector<pair<long long,long long> >
#define pb push_back
#define mp make_pair
#define F first
#define S second


ll power(ll a,ll m,ll mod){
	ll ans=1;
	while(m){
		if(m%2){
			ans*=a;
			ans%=(mod);
		}
		a=(a*a)%(mod);
		m>>=1;
	}
	return ans;
}


void init(long long* a,long long n,long long val){
	for(long long i=0;i<n;i++)
		a[i]=val;
}



int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);	
	ll t=1,i,j;
	ll n;
	cin>>n;
	ll a;
	ll c[62]={0},d;
	rep(i,0,n){
	    cin>>a;
	    /*for(j=1;j<=a;j=j<<1){
	        if(j&a)
	            c[(ll)log2(j)]++;
	    }*/
	    j=1;
	    while(a){
	        d=a%2;
	        if(d){
	            c[(ll)log2(j)]++;
	        }
	        j=j*2;
	        a/=2;
	    }
	}ll ans=0,k;
	rep(i,0,62){
	    k=c[i]*(n-c[i]);
	    k%=M;
	    ans+=((k*((ll)power(2,i,M)))%M);
	    ans%=M;
	}
	
	
	
	cout<<ans;
	return 0;
}

Measured memory_bytes: 384
#pragma comment(linker, "/stack:20000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
 
#include <stdio.h>
#include <bits/stdc++.h>
 
using namespace std;
 
#include <x86intrin.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template <typename T> using ordered_set = tree<T, null_type, std::less<T>, rb_tree_tag, tree_order_statistics_node_update>;
  
#define pb push_back
#define mp make_pair
#define in insert
#define f first
#define s second
#define ll long long
#define dd double
  
const int mod = 1e9 + 7;
const int N = 2e5 + 7;
const int inf = 2e9;
const ll INF = 1e18;

// int mmax[N], cnt[N], a[N];
int l[N], r[N];

int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	// freopen("*.in", "r", stdin);freopen("*.out", "w", stdout);
	int n, k, c;
	string s;
	cin >> n >> k >> c >> s;

	// for (int i = n - 1; i >= 0; i--) {
	// 	if (i + c + 1 > n) cnt[i] = (s[i] == 'o');
	// 	else cnt[i] = mmax[i + c + 1] + (s[i] == 'o');
	// 	mmax[i] = min(max(mmax[i + 1], cnt[i]), k);
	// }

	// for (int i = 0; i < n; i++) {
	// 	if (s[i] == 'x') continue;
	// 	a[mmax[i]]++;
	// 	if (mmax[i + 1] < mmax[i] && a[mmax[i]] == 1) {
	// 		cout << i + 1 << "\n";
	// 		i += c;
	// 	}
	// }
	int cnt = 0;
	for (int i = 0; i < n; i++) {
		if (s[i] == 'x') continue;
		l[cnt] = i;
		i += c;
		cnt++;
		if (cnt == k) break;
	}

	cnt = k - 1;
	for (int i = n - 1; i >= 0; i--) {
		if (s[i] == 'x') continue;
		r[cnt] = i;
		i -= c;
		cnt--;
		if (cnt == -1) break;
	}

	for (int i = 0; i < k; i++) {
		if (l[i] == r[i]) cout << l[i] + 1 << "\n";
	}
}

Measured memory_bytes: 3348
#include <stdio.h>

int abs(int);
int min(int,int);
void output(int,int *);

int main(){
    int n;
    int h[100000];
    scanf("%d",&n);
    for(int i=0;i<n;i++) scanf("%d",&h[i]);

    int dp[100000]={};
    for(int i=0;i<n;i++) dp[i]=-1;
    for(int i=0;i<n;i++){
        if(i==0) {
            dp[0]=0;
            // output(n,dp);
            continue;
        }
        if(i==1){
            dp[i]=abs(h[i-1]-h[i]);
            // output(n,dp);
            continue;
        } 
            dp[i]=min(abs(h[i-2]-h[i])+dp[i-2],abs(h[i-1]-h[i])+dp[i-1]);
            // output(n,dp);
        
    }
    printf("%d\n",dp[n-1]);
}

int abs(int n){
    if(n>=0) return n;
    else return -n;
}
int min(int a,int b){
    if(a<=b) return a;
    if(b<a) return b;
    return 0;
}

void output(int n,int dp[]){
    for(int i=0;i<n;i++){
        printf("dp[%d]=%d\n",i,dp[i]);
    }
}

Measured memory_bytes: 896
#include <algorithm>
#include <string>
#include <map>
#include <iostream>

using namespace std;

/** Problem0029 : English Sentence **/
int main()
{
	map<string, int> sentences;
	string tmp, maxLength, a;
	maxLength="";
	int A=0;
	
	while (cin >> tmp) {
		if (tmp.length() > maxLength.length())
			maxLength = tmp;
		
		if (sentences.count(tmp) == 0) {
			sentences.insert(map<string,int>::value_type(tmp, 1));
		} else {
			sentences[tmp]++;
		}
		
		if (sentences[tmp] > A) {
			A = sentences[tmp];
			a = tmp;
		}
	}
	
	cout << a << " " << maxLength << endl;
	
	return 0;
}

Measured memory_bytes: 1196
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;

vector<long long> divisor(long long n) {
    vector<long long> ret;
    for (long long i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) ret.push_back(n / i);
        }
    }
    sort(ret.begin(), ret.end()); // 昇順に並べる
    return ret;
}

long long gcd(long long a, long long b){
    // 最大公約数
    // ユークリッドの互除法
    if(a < b){
        long long temp = a;
        a = b;
        b = temp;
    }
    long long r = a % b;
    while(r != 0){
        a = b;
        b = r;
        r = a % b;
    }
    return b;
}

bool isPrime(long long n){
    if(n < 2) return false;
    else if(n == 2) return true;
    else if(n % 2 == 0) return false;
    for(int i = 3; i <= sqrt(n) + 1; i += 2){
        if(n % i == 0) return false;
    }
    return true;
}

int main(){
    long long a, b;
    cin >> a >> b;
    vector<long long> divs = divisor(gcd(a, b));
    // for(auto x : divs) cout << x << " ";
    int ans = 0;
    for(int i = 0; i < (int)divs.size(); i++){
        if(isPrime(divs[i]) == true) ans++;
    }
    ans++; // 1 の分
    cout << ans;
    return 0;
}

Measured memory_bytes: 384
n=int(input())
a=list(map(int,input().split()))
dlt=0
push=0
a.sort()
k=0
while(1):
  i=a[k+push]
  if(i>n):
    dlt+=1
    push+=1
  else:
    j=a.count(i)
    push+=j
    if(j>i):dlt+=j-i
    elif(i>j):dlt+=j
  if(k+push>=n):break
print(dlt)


Measured memory_bytes: 14692
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int maxn = 15;
const int inf = 1e9 + 5;
int n, m, x;
int cena[maxn];
int mat[maxn][maxn];
int niz[maxn];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cin >> n >> m >> x;
    for(int i=0;i<n;i++){
        cin >> cena[i];
        for(int j=0;j<m;j++)cin >> mat[i][j];
    }
    int rez = inf;
    for(int mask=0;mask<(1<<n);mask++){
        for(int j=0;j<m;j++)niz[j] = 0;
        int zbir = 0;
        for(int i=0;i<n;i++){
            if(mask & (1 << i)){
                zbir += cena[i];
                for(int j=0;j<m;j++)niz[j] += mat[i][j];
            }
        }
        bool ok = 1;
        for(int j=0;j<m;j++){
            if(niz[j] < x)ok = 0;
        }
        if(ok)rez = min(rez, zbir);
    }
    cout << (rez == inf ? -1 : rez) << endl;
    return 0;
}


Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main() {
  ll n;
  cin>>n;
  ll a[n+1];
  for(int i = 1 ; i <= n ; i++) {
      cin >> a[i];
  }
  ll dp[n+1] = {0};
  dp[2] = abs(a[2]-a[1]);
  dp[1] = 0;
  for(int i = 3 ; i <= n ; i++){
      dp[i] = min(abs(a[i]-a[i-1])+dp[i-1],abs(a[i]-a[i-2])+dp[i-2]);
  }
  cout<<dp[n]<<endl;
}

Measured memory_bytes: 5204
#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(){
    ll N; cin >> N;
    vector<ll> A(N);
    for (ll i = 0; i < N; i++) {
        cin >> A[i];
    }
    vector<ll> C(N, -1);

    ll tmp;
    for (ll i = 0; i < N; i++) {
        tmp = lower_bound(ALL(C), A[i]) - C.begin();
        C[tmp-1] = A[i];
    }
    ll ans;
    tmp = lower_bound(ALL(C), 0) - C.begin();
    ans = N - tmp;
    printf("%lld\n", ans);

}


Measured memory_bytes: 4844
/// Thank you tanakh!!!
/// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

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

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

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

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

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

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

fn main() {
    input!(a: usize, b: usize);
    let h = 100;
    let w = 100;
    let mut is_white = vec![vec![false; w]; h];

    let mut white = a - 1;
    let mut black = b - 1;

    for i in 0..h {
        for j in 0..w {
            if i <= h / 2 {
                if i % 2 == 1 && j % 2 == 0 {
                    is_white[i][j] = false;
                    if white > 0 {
                        is_white[i][j] = true;
                        white -= 1;
                    }
                } else {
                    is_white[i][j] = false;
                }
            } else {
                if i % 2 == 0 && j % 2 == 0 {
                    is_white[i][j] = true;
                    if black > 0 {
                        is_white[i][j] = false;
                        black -= 1;
                    }
                } else {
                    is_white[i][j] = true;
                }
            }
        }
    }

    println!("{} {}", h, w);

    for i in 0..h {
        for j in 0..w {
            print!("{}", if is_white[i][j] { '.' } else { '#' });
        }
        println!();
    }
}


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

int main(){
    int n;
    cin >> n;
    vector<int> a(100'000, 0);
    int x;
    for (int i = 0; i < n; i++) {
        cin >> x; x--;
        a[x]++;
    }
    int cnt = 0;
    int ans = 0;
    for (int i = 0; i < 100'000; i++){
        if (a[i] >= 3) a[i] = 2 - (a[i] % 2);
    }
    for (int i = 0; i < 100'000; i++){
        if (a[i] > 0) ans++;
        if (a[i] > 1) cnt++;
    }
    cout << ans - (cnt % 2) << endl;
}

Measured memory_bytes: 640
n=int(input())
a=list(map(int,input().split()))
b=a[:]

x=0#pmpm
y=0
sum1=0
sum2=0

for i in range(n):
  sum1+=a[i]
  sum2+=b[i]
  if(i%2==0):
    if(sum1<=0):
      x+=1-sum1
      a[i]+=1-sum1
      sum1+=1-sum1
    if(sum2>=0):
      y+=sum2+1
      b[i]-=sum2+1
      sum2-=sum2+1
  else:
    if(sum1>=0):
      x+=sum1+1
      a[i]-=1+sum1
      sum1-=1+sum1
    if(sum2<=0):
      y+=1-sum2
      b[i]+=1-sum2
      sum2+=1-sum2
print(min(x,y))

Measured memory_bytes: 14504
#include <bits/stdc++.h>
#define ll  long long int
using namespace std;
int main() {
    ll l,r;
    cin>>l>>r;
    r=min(r,l+2018);
    ll mini=2018;
    
    for(ll i=l;i<=r;i++){
        for(ll j=i+1;j<=r;j++){
            ll l1=i%2019,l2=j%2019;
            mini=min(mini,(l1*l2)%2019);
        }
    }
    cout<<mini<<"\n";

}



Measured memory_bytes: 3628
import sys
from collections import deque
import copy

from math import *
def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

def gcd(a, b):
    if a < b:
        z = a
        a = b
        b = z
    while b:
		a, b = b, a % b
    return a

def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N, K] = [int(input_raw[0]), int(input_raw[1])]

    input_raw = list(read_func().strip().split())
    A = set([])
    for i in range(len(input_raw)):
        A.add(int(input_raw[i]))
    A_list = list(A)
    possible_flag = False
    is_all_geometric = False

    if len(filter(lambda x:x >=K , A)) != 0:
        g = A_list[0]
        for i in range(1, len(A_list)):
            x = A_list[i]
            if x == K:
                possible_flag = True
                break
            g = gcd(g, A_list[i])

        if g == 1:
            possible_flag = True
        elif K % g == 0 :
            possible_flag = True

    if possible_flag == True:
        print "POSSIBLE"
    else:
        print "IMPOSSIBLE"


if __name__ == '__main__':
    main()

Measured memory_bytes: 19860
//   _/                _/                 _/_/_/   _/
//_/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
// _/     _/    _/   _/     _/    _/  _/_/_/     _/
//_/     _/    _/   _/     _/    _/  _/    _/   _/
// _/_/   _/_/       _/_/   _/_/      _/_/     _/
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=2e9;
const ll INF=9e18;
typedef pair<int,int> P;
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  int n,w,val[105]={},wei[105]={},dp[10005]={};
  cin >> n >> w;
  for(int i=0; i<n; i++) {
    cin >> val[i] >> wei[i];
  }
  for(int i=0; i<=w; i++) {
    for(int j=0; j<n; j++) {
      if(i-wei[j]>=0) {
        dp[i]=max(dp[i],dp[i-wei[j]]+val[j]);
      }
    }
  }
  cout << dp[w] << endl;
}


Measured memory_bytes: 3248
#include<stdio.h>

int main(){

    double w,h,x,y;
    scanf("%lf %lf %lf %lf",&w,&h,&x,&y);

    double S = w*h/2;
    int flag=0;
    if(x==w/2 && y==h/2){
        flag=1;
    }
    printf("%lf %d",S,flag);

    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <utility>
#include <numeric>
#include <functional>
#include <stdio.h>
#include <math.h>
#include <string>
#include <algorithm>
#include <deque>
#include <queue>
#include <map>

#define rep(i, m, n) for (int (i)(m); (i)<(n); ++(i))
#define repr(i, m, n) for (int (i)(m - 1); (i)>=(n); --(i))
#define repv(i, v) for (unsigned (i)(0); (i)<(v.size()); ++(i))
#define all(v) (v).begin(), (v).end()
#define sortv(v) sort(all(v))
#define sortgi(v) sort(all(v), greater<int>())
#define sortgd(v) sort(all(v), greater<double>())
#define sortgll(v) sort(all(v), greater<ll>())
#define debug(x) cerr << #x << ": " << x << '\n'

using namespace std;
using pii = pair<int, int>;
using pss = pair<string, string>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vd = vector<double>;
using vvd = vector<vd>;
using vs = vector<string>;
using ll = long long;
using pllll = pair<ll, ll>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvvb = vector<vvb>;
using pqi = priority_queue<int>;
using pqd = priority_queue<double>;
using pqll = priority_queue<ll>;
using pqvi = priority_queue<vi>;
using pqvll = priority_queue<vll>;

int main() {
	int n , m;
	cin >> n >> m;
	vector<pii> v;
	rep(i, 0, m) {
		int a, b;
		cin >> a >> b;
		int aa = min(a, b), bb = max(a, b);
		v.push_back(pii(aa, bb));
	}
	int sum = 0;
	while  (!v.empty()) {
		++sum;
		int loc = 0;
		repv(i, v) {
			loc = max(loc, v[i].first);
		}
		sort(all(v), [](const pii &l, const pii &r)
		{return l.second < r.second;});
		bool f = true;
		repr(i, v.size(), 0) {
			if (v[i].second <= loc) {
				v.erase(v.begin() + i + 1, v.end());
				f = false;
				break;
			}
		}
		if (f) {
			break;
		}
	}
	cout << sum << endl;
}


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

int main()
{
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	
	bool f=1;
	if(a!=1&&b!=1&&c!=1&&d!=1) f=0;
	else if(a!=9&&b!=9&&c!=9&&d!=9) f=0;
	else if(a!=7&&b!=7&&c!=7&&d!=7) f=0;
	else if(a!=4&&b!=4&&c!=4&&d!=4) f=0;
	
	cout<<((f)? "YES":"NO")<<endl;
	
	return 0;
}


Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        B solver = new B();
        solver.solve(1, in, out);
        out.close();
    }

    static class B {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            int n = Integer.parseInt(in.next());
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = Integer.parseInt(in.next()) - 1;
            }

            int ans = 0;
            for (int i = 0; i < n; i++) {
                if (a[a[i]] == i) ans++;
            }

            // 出力
            out.println(ans / 2);

        }

    }
}



Measured memory_bytes: 50352
#include <iostream>
using namespace std;
int main()
{
	int N,K;
	scanf("%d%d",&N,&K);
	double p = 0;
	for(int i = 1; i <= N; i++)
	{
		double pr = 1.0/N;
		int pt = i;
		while(pt < K)
		{
			pt *= 2.0;
			pr *= 0.5;
		}
		p += pr;
	}
	printf("%.12f\n", p);
	return 0;
}


Measured memory_bytes: 256
s=input()
n=len(s)
cha=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
if n<26:
    for i in range(26):
        if s.count(cha[i])==0:
            print(s+cha[i])
            exit()
else:
    for j in range(n-1,0,-1):
        if s[j]>s[j-1]:
            memo=j-1
            break
        if j==1:
            print(-1)
            exit()
    s2=s[:j]
    for i in range(26):
        if s2.count(cha[i])==0 and cha[i]>s[memo]:
            memo2=cha[i]
            break
    print(s[:j-1]+memo2)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
long long n,a[200010]={-1},ans;
inline int read()
{
	int num=0,flag=1;
	char c=getchar();
	for (;c<'0'||c>'9';c=getchar())
	if (c=='-') flag=-1;
	for (;c>='0'&&c<='9';c=getchar())
	num=(num<<3)+(num<<1)+c-48;
	return num*flag;
}
int main()
{
	n=read();
	for (int i=1;i<=n;++i)
	{
		a[i]=read();
		if (a[i]-a[i-1]>1)
		{
			printf("-1\n");
			return 0;
		}
	}
	for (int i=n;i>=1;--i)
	if (a[i+1]-a[i]!=1) ans+=a[i];
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 1792
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
#ifndef FAST_IO
 #define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);
#endif

#define FILE_IO freopen("input.txt","r",stdin)
#define int long long
#define f first
#define s second
#define endl '\n'
#define all(c) c.begin(),c.end()
#define debug(x) cerr << #x << " = " << x << endl;

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

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template <typename T>void print(T t){for(auto &it:t)cout<<it<<" ";}
inline int powerexp(int a,int b,int m = MOD){int res=1;while(b){if(b&1)res=res*a%m;a=a*a%m,b>>=1;}return res%m;}
inline int modinv(int a){return powerexp(a,MOD-2,MOD);}
inline int lcm(int a,int b){int g=__gcd(a,b);return a/g*b;}

//-------------------< start here >-------------------------// 
void solve(){
   int a, b, c;
   cin >> a >> b >> c;
   if (b - a == c - b) cout << "YES" << endl;
   else cout << "NO" << endl;
}
//-----------------------------
//comment from here for TOPCODER 
int32_t main(){
   IOS;
   solve();
   //find();
   #ifdef LOCAL_DEFINE
   cerr<<"time elapsed "<<(double)clock()/CLOCKS_PER_SEC<<endl;
   #endif
}


Measured memory_bytes: 256
n=int(input())
L=list(map(int,input().split()))
cnt=0
L.sort()
for i in range(n-2):
    for j in range(i+1,n-1):
        for k in range(j+1,n):
            if L[i]==L[j] or L[i]==L[k] or L[j]==L[k]:
                continue
            if L[i]+L[j]>L[k]:
                cnt+=1
print(cnt)

Measured memory_bytes: 9184
#include <iostream>
using namespace std;
int main()
{
  string N;
  cin >> N;
  string ans = "No";
  if (N[0] == N[1] && N[1] == N[2])
    ans = "Yes";
  if (N[1] == N[2] && N[2] == N[3])
    ans = "Yes";
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
arr = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
n = gets.to_i
puts arr[n-1]

Measured memory_bytes: 1788
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cfloat>
#include<climits>
#include<cmath>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;

using lint = long long;
using P = pair<int, int>;
using LLP = pair<long long, long long>;

#define REP(i, x, n) for(int i = (x), i##_len = (int)(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = (int)(n) ; i < i##_len ; ++i)
#define reps(i, n) for(int i = 1, i##_len = (int)(n) ; i <= i##_len ; ++i)
#define rrep(i, n) for(int i = (int)(n) - 1 ; i >= 0 ; --i)
#define rreps(i, n) for(int i = (int)(n) ; i > 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())
#define REVERSE(x) reverse((x).begin(), (x).end())
#define TWINS(x) cout << ((x) ? "Yay!" : ":(") << '\n'

constexpr int IINF = (1 << 30) - 1;
constexpr long long LLINF = 1LL << 61;
constexpr double EPS = 1e-10;

constexpr int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
constexpr int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};

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

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

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    int n;
    cin >> n;

    vector<int> a(n);
    vector<int> cnt(1000001, 0);
    rep(i, n){
        cin >> a[i];
        ++cnt[a[i]];
    }

    int ans = 0;

    rep(i, n){
        bool flg = true;
        for(int j = 1 ; j * j <= a[i] ; ++j){
            if(a[i] % j != 0){
                continue;
            }
            if(cnt[j] >= 1 + (j == a[i])){
                flg = false;
            }
            if(cnt[a[i] / j] >= 1 + (a[i] / j == a[i])){
                flg = false;
            }
        }
        ans += flg;
    }

    cout << ans << endl;

    cout << flush;

    return 0;
}

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

int main(){
  int n;cin>>n;
  int a,c=0;
  for(int i=0;i<n;i++){
    cin>>a;
    if(a&1) c++;
  }
  if(c&1){
    cout<<"NO"<<endl;
  }else{
    cout<<"YES"<<endl;
  }
}

Measured memory_bytes: 256
#include <cstdio>  
using namespace std;  
int main() { 	
	int a,b,c,d,e; 	
	scanf("%d", &a); 	
	b=a/100;
	c=(a%100)/10;
	d=a%10;
	e=b+c+d;
	printf("%d", e);

} 


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

#define dump(...) do{print_vars(cout<<"# "<<#__VA_ARGS__<<'=',__VA_ARGS__);cout<<endl;}while(0)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

using uint=unsigned;
using ll=long long;
using ull=unsigned long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using vd=vector<double>;
using vvd=vector<vd>;
using vs=vector<string>;

void print_vars(ostream&){}
template<typename Car,typename... Cdr>
void print_vars(ostream& os,const Car& car,const Cdr&... cdr){
	print_vars(os<<car<<(sizeof...(cdr)?",":""),cdr...);
}

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

template<int I,typename Tuple>
void print_tuple(ostream&,const Tuple&){}
template<int I,typename Car,typename... Cdr,typename Tuple>
void print_tuple(ostream& os,const Tuple& t){
	os<<get<I>(t)<<(sizeof...(Cdr)?",":"");
	print_tuple<I+1,Cdr...>(os,t);
}
template<typename... Args>
ostream& operator<<(ostream& os,const tuple<Args...>& t){
	print_tuple<0,Args...>(os<<'(',t);
	return os<<')';
}

template<typename Ch,typename Tr,typename C>
basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>& os,const C& c){
	os<<'[';
	for(auto i=begin(c);i!=end(c);++i)
		os<<(i==begin(c)?"":" ")<<*i;
	return os<<']';
}

constexpr int INF=1e9;
constexpr int MOD=1e9+7;
constexpr double EPS=1e-9;

int main()
{
	#ifndef _GLIBCXX_DEBUG
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	constexpr char endl='\n';
	#endif

	for(ll X,K;cin>>X>>K&&X|K;){
		vl rs(K+1);
		rep(i,K) cin>>rs[i+1];

		//dump(X);
		//dump(rs);

		vl as(K+1),bs(K+1),xs(K+1),ys(K+1);
		as[0]=xs[0]=0;
		bs[0]=ys[0]=X;

		rep(i,K){
			ll e=rs[i+1]-rs[i];
			if(i%2==0){  // 減る
				xs[i+1]=max(xs[i]-e,0LL);
				ys[i+1]=max(ys[i]-e,0LL);
				if(0<=xs[i]-e){
					as[i+1]=as[i];
				}
				else{
					ll tmp=e-xs[i];
					as[i+1]=min(as[i]+tmp,bs[i]);
				}
				bs[i+1]=bs[i];
			}
			else{  // 増える
				xs[i+1]=min(xs[i]+e,X);
				ys[i+1]=min(ys[i]+e,X);
				if(ys[i]+e<=X){
					bs[i+1]=bs[i];
				}
				else{
					ll tmp=ys[i]+e-X;
					bs[i+1]=max(bs[i]-tmp,as[i]);
				}
				as[i+1]=as[i];
			}
		}
		//rep(i,K+1) dump(rs[i],as[i],bs[i],xs[i],ys[i]);

		int Q; cin>>Q;
		rep(_,Q){
			ll t,c; cin>>t>>c;
			int i=upper_bound(all(rs),t)-begin(rs)-1;

			ll e=t-rs[i];
			//dump(t,c,i,e);
			ll res=-1;
			if(i%2==0){
				if(c<=as[i])
					res=max(xs[i]-e,0LL);
				else if(c<=bs[i])
					res=max(xs[i]+(c-as[i])-e,0LL);
				else
					res=max(ys[i]-e,0LL);
			}
			else{
				if(c<=as[i])
					res=min(xs[i]+e,X);
				else if(c<=bs[i])
					res=min(ys[i]-(bs[i]-c)+e,X);
				else
					res=min(ys[i]+e,X);
			}
			cout<<res<<endl;
		}
	}
}


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

#define ll long long
#define endl "\n"
#define fi first
#define se second

template<typename T>
void selfmax(T &a, T b){
    if(b>a) a=b;
}

int n;

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

    int n;
    cin>>n;
    vector<pair<int,int>> a(n);
    for (int i=0; i<n; ++i){
        cin>>a[i].first;
        a[i].second=i;
    }
    vector<vector<ll>> dp(n+1, vector<ll>(n+1, -1));
    dp[0][0]=0;
    sort(a.begin(), a.end(), greater<>());
    for (int i=0; i<n; ++i){
        int val = a[i].fi;
        for (int j=0; j<=i; ++j){
            ll leftDist = abs(a[i].se-j); 
            ll rightDist = abs(n-1-a[i].se-(i-j));
            ll leftScore = val*leftDist;
            ll rightScore = val*rightDist;
            selfmax(dp[i+1][j], dp[i][j] + rightScore);
            selfmax(dp[i+1][j+1], dp[i][j] + leftScore);
        }
    }
    ll ans = 0;
    for (int i=0; i<=n; ++i){
        selfmax(ans, dp[n][i]);
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 34620
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;



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

	vector<int> a(3);
	int ct;
	cin >> a[0] >> a[1] >> a[2];
	ct = 0;

	while (1) {
		sort(a.begin(), a.end());
		if (a[0] == a[2]) break;
		if ((a[0] < a[2]) && (a[1] < a[2])) {
			a[0]++; a[1]++;
			ct++;
		}
		else {
			a[0] += 2;
			ct++;
		}
	}
	cout << ct << "\n";

	return 0;
}


Measured memory_bytes: 384
#include <limits.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <math.h>

#define P 1000000007

int comp(const void *a, const void *b){return *(int*)a-*(int*)b;}
int compw(const void *a, const void *b){return (*(int*)a>*(int*)b)-(*(int*)a<*(int*)b);}

uint32_t nextpint(void){
	uint_fast32_t x=0;
	while(1){
		uint_fast8_t c=getchar();
		if('0'<=c && c<='9'){
			x=x*10+c-'0';
		}else{
			break;
		}
	}
	return x;
}

#define nextInt nextpint

int main(void){
	int n = nextInt();
	int t = nextInt();
	int minC = 1001;
	for(int i=0; i<n; i++){
		int c = nextInt();
		int T = nextInt();
		if(T<=t && c<minC){
			minC = c;
		}
	}
	if(minC == 1001){
		puts("TLE");
	}else{
		printf("%d\n", minC);
	}
}


Measured memory_bytes: 128
#include<stdio.h>
int main(void){
    int a[200];
    int n,i,c,f;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    f=0;
    c=0;
    for(i=0;i<n;i++){
        if(a[i]&1){
            f=1;
        }
    }
    while(f==0){
        for(i=0;i<n;i++){
            a[i]=a[i]>>1;
            if(a[i]&1){
                f=1;
            }
        }
        c++;
    }
    printf("%d",c);
    return 0;
}

Measured memory_bytes: 1700
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define range(i, l, r) for(long long int (i) = (l); (i) < (r); (i)++)
#define reversed_range(i, l, r) for (long long int (i) = (r) - 1; (i) >= l; (i)--)
using namespace std;
template <typename T>
using vec = vector<T>;
using lint = long long;
using ulint = unsigned long long;
using pint = pair<int, int>;
using plint = pair<lint, lint>;

template <typename S, typename T>
ostream& operator <<(ostream& os, pair<S, T> p) {
    os << "(";
    os << p.first << ", " << p.second;
    return os << ")";
}

template <typename T>
ostream& operator <<(ostream& os, vec<T> v) {
    os << "[";
    if (v.size() == 0) return os << "]";
    for (int i = 0; i < v.size() - 1; i++) {
        os << v.at(i) << ", ";
    }
    return os << v.at(v.size() - 1) << "]";
}

template <typename T>
ostream& operator <<(ostream& os, set<T>& s) {
    os << "{";
    if (s.begin() == s.end()) return os << "}";
    auto it_first_item = s.begin();
    cout << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        cout << ", " << *it;
    }
    return cout << "}";
}

template <typename T>
ostream& operator <<(ostream& os, unordered_set<T>& s) {
    os << "{";
    if (s.begin() == s.end()) return os << "}";
    auto it_first_item = s.begin();
    cout << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        cout << ", " << *it;
    }
    return cout << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, map<K, V> m) {
    os << "{";
    if (m.begin() == m.end()) return os << "}";
    auto it_first_item = m.begin();
    cout << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        cout << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, unordered_map<K, V> m) {
    os << "{";
    if (m.begin() == m.end()) return os << "}";
    auto it_first_item = m.begin();
    cout << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        cout << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

lint pow(lint num, lint e, lint MOD) {
    lint res = 1;
    lint cur_num = num;
    while (e) {
        if (e & 1) {
            res *= cur_num;
            res %= MOD;
        }
        cur_num *= cur_num;
        cur_num %= MOD;
        e >>= 1;
    }
    return res;
}

int main() {
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    locale loc;
    string s1, s2, s3;
    cin >> s1 >> s2 >> s3;
    cout << toupper(s1.at(0), loc) << toupper(s2.at(0), loc) << toupper(s3.at(0), loc) << "\n";
}


Measured memory_bytes: 256
from sys import exit

w = input()
n = len(w)

cnt = [0]
c = w[0]
sw = sorted(w)
for i in range(n):
    if sw[i] == c:
        cnt[-1] += 1
    else:
        c = sw[i]
        cnt.append(1)
for i in range(len(cnt)):
    if cnt[i]%2 == 1:
        print("No")
        exit()
print("Yes")

Measured memory_bytes: 9064
N,A,B = list(map(int,input().split()))
diff = B - A
N2B = N - B
N2A = N - A
sumN = N2A + N2B 
sumAB = A + B 


if diff % 2 == 0:
    print(diff // 2)
else:
    if N2B < A - 1:
        tmp = (N - (A + N2B))//2 + N2B
        if (N - A - N2B)%2 == 1:
            tmp = tmp + 1
        if N2A < tmp:
            print(N2A,"a")
        else:
            print(tmp)
    else:
        tmp = ((B + 1 - A) - 1)//2 + A - 1
        if ((B + 1 - A) - 1)%2 == 1:
            tmp = tmp + 1
        if B-1 < tmp: 
            print(B - 1)
        else:
            print(tmp)

Measured memory_bytes: 3064
V,E,r = map(int,input().split())
g=[]
for i in range(E):
    s,t,d= map(int,input().split())
    g.append([s,t,d])
inf= 1001001001
dd= [inf]*V 

dd[r]=0
for i in range(V):
    update=0
    for s,t,d in g:
        if dd[t]> dd[s]+d:
            dd[t]= dd[s]+d
            update+=1
    if update==0:
        break
for i in dd:
    if i==inf:
        print("INF")
    else:
        print(i)


Measured memory_bytes: 102464
import java.util.Scanner;

class Main {
    public static void main(String args[]){
        Scanner scanner = new Scanner(System.in);
        int x = scanner.nextInt();
        int y = scanner.nextInt();
        int area = x * y;
        int perimeter = 2 * (x + y);
        System.out.println(area + " " + perimeter);
    }
}


Measured memory_bytes: 26136
main :: IO ()
main = do
    s <- getLine
    print $ solve s

solve :: String -> Int
solve cs = (\(_, s, t) -> s + t) $ foldr f (0, 0, 0) cs
  where
    f 'T' (d, s, t)             = (succ d,      s, succ t)
    f 'S' (d, s, t) | d == 0    = (     d, succ s,      t)
                    | otherwise = (pred d,      s, pred t)


Measured memory_bytes: 13692
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		Main res = new Main();
		StringBuilder result = new StringBuilder();
		while (true) {
			int m = sc.nextInt();
			int f = sc.nextInt();
			int r = sc.nextInt();
			if (m == -1 && f == -1 && r == -1)
				break;
			result.append(res.grading(m, f, r));
			result.append("\n");
		}
		System.out.print(result);
	}
	public char grading(int m, int f, int r) {
		if (m == -1 | f == -1)
			return 'F';
		int total = m + f;
		if (total >= 80)
			return 'A';
		if (/* 80 > */total >= 65)
			return 'B';
		if (/* 65 > */total >= 50)
			return 'C';
		if (/* 50 > */total >= 30) {
			if (r >= 50)
				return 'C';
			// r < 50:
			return 'D';
		}
		// total < 30:
		return 'F';
	}
}


Measured memory_bytes: 26380
import bisect, collections, copy, heapq, itertools, math, string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int, sys.stdin.readline().rstrip().split())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

S = S()
if S[2] == S[3] and S[4] == S[5]:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 74644
import sys

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

if not (str.isdecimal(s[:a])):
    print("No")
    sys.exit()
if not s[a] == '-':
    print("No")
    sys.exit()
if not (str.isdecimal(s[-b:])):
    print("No")
    sys.exit()
print("Yes")

Measured memory_bytes: 38256
#include <iostream>
#include <sstream>
#include <stdio.h>
//#define _USE_MATH_DEFINES
#include <math.h>
#include <set>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <limits>
#include <bitset>
#include <stack>
#include <queue>
#include <ctype.h>

typedef long long int lli;
#define rep(i,s,N) for(int i=s;i<N;i++)
#define MOD 1000000007
#define more(a,b) (((a)>(b))?(a):(b))
#define less(a,b) (((a)<(b))?(a):(b))

using namespace std;


int main(void)
{
	int N; cin >> N;
	vector<int> A(N); rep(i, 0, N)cin >> A[i];
	int ans = 0;
	rep(i, 0, N) {
		while (i + 1 < N && A[i] == A[i + 1])i++;

		if (i + 1 < N && A[i] < A[i + 1]) {
			while (i + 1 < N && A[i] <= A[i + 1])i++;
		}
		else if (i + 1 < N && A[i] > A[i + 1]) {
			while (i + 1 < N && A[i] >= A[i + 1])i++;
		}

		ans++;
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>

static const int INF = 1000000007;
using ll = long long;
using u32 = unsigned;
using namespace std;

template <typename T>
struct edge {
    int from, to;
    T cost;

    edge(int to, T cost) : from(-1), to(to), cost(cost) {}
    edge(int from, int to, T cost) : from(from), to(to), cost(cost) {}

    explicit operator int() const {return to;}
};

template <typename T>
vector<T> bellman_ford(int s, int V,vector<edge<T> > &G){
    const T INF = numeric_limits<T>::max();
    vector<T> d(V, INF);
    d[s] = 0;
    for (int i = 0; i < V - 1; ++i) {
        for (auto &&e : G) {
            if (d[e.from] == INF) continue;
            if(d[e.to] == INF) d[e.to] = d[e.from] + e.cost;
            else d[e.to] = max(d[e.to], d[e.from] + e.cost);
        }
    }
    vector<T> d2 = d;
    for (int i = 0; i < V - 1; ++i) {
        for (auto &&e : G) {
            if (d[e.from] == INF) continue;
            if(d[e.to] == INF) d[e.to] = d[e.from] + e.cost;
            else d[e.to] = max(d[e.to], d[e.from] + e.cost);
        }
    }
    if(d[V-1] != d2[V-1]) return vector<T> ();
    else return d;
}

int main() {
    int n, m;
    scanf("%d %d", &n, &m);
    vector<edge<ll>> g;
    for(int i = 0; i < m; i++) {
        ll a, b, c;
        scanf("%lld %lld %lld", &a, &b, &c);
        g.emplace_back(a-1, b-1, c);
    }
    auto dists = bellman_ford(0, n, g);
    if(dists.empty()) cout << "inf\n";
    else cout << dists[n-1] << "\n";
}


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

using namespace std;

typedef long long ll;


char a[2005][2005],b[2005][2005];
ll n,m;
ll ans;
int main(){
	cin >> n >> m;
	for(int i=0;i<n;i++){
		cin >> a[i];
	}
	for(int i=0;i<n;i++){
		cin >> b[i];
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			if(a[i][j] != b[i][j]){
				ans ++;
			}
		}
	}
	cout << ans << endl;
	return 0;
}


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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()

using namespace std;
using ll = long long;

const double PI = 3.14159265358979;

void solve()
{
  int n, k;
  cin >> n >> k;
  int ans = 1;
  for(int i = 0; i < n; ++i)
  {
    ans = min(ans * 2, ans + k);
  }
  cout << ans;
}

int main()
{
  fastio;
  solve();

  return 0;
}

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

int main() {
    int a, b, m;
    cin >> a >> b >> m;
    vector<int> H(a), W(b);

    int mh = 0, mw = 0, cnt = 0;
    vector<pair<int, int>> V;
    rep(i, m) {
        int h, w;
        cin >> h >> w;
        mh = max(mh, ++H.at(--h)), mw = max(mw, ++W.at(--w)),
        V.push_back({h, w});
    }

    for (auto v : V) {
        if (H.at(v.first) == mh && W.at(v.second) == mw) cnt++;
    }

    int ans = mh + mw;
    if (cnt == count(H.begin(), H.end(), mh) * count(W.begin(), W.end(), mw))
        ans--;
    cout << ans << endl;
    return 0;
}


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

#ifdef LOCAL_PC
	#define debug(args...) { cout.flush(); fflush(stdout); fprintf(stderr, args); }
#else
	#define debug(args...) ; /*  */
#endif
#define pb push_back
#define eb emplace_back
#define mk make_pair
#define fi first
#define se second
using ll = long long;
using pii = pair<int, int>;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class Ty> Ty rnd(Ty a, Ty b) { return uniform_int_distribution<Ty>(a, b)(rng); }

template<class num> inline void rd(num &x) {
	char c; while(isspace(c = getchar()));
	bool neg = false;
	if(!isdigit(c)) neg = (c == '-'), x = 0;
	else x = c - '0';
	while(isdigit(c = getchar()))
		x = (x << 3) + (x << 1) + c - '0';
	if (neg) x = -x;
} template <class T, class... Args> inline void rd(T& x, Args&... args) { rd(x); rd(args...); }

const int MAXN = 2e5 + 5, INF = 0x3f3f3f3f;

int main() {
	//ios::sync_with_stdio(false); cin.tie(NULL);
	 string s, t; cin >> s >> t;
	 t.pop_back();
	 if (s == t) cout << "Yes\n";
	 else cout << "No\n";
}

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

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

    int N, K;
    string S;
    cin >> N >> K >> S;
    
    string T;
    for (int i = 0; i < S.length(); ++i) {
        char s = S[i];
        if (i == K - 1) {
            T += (char) (s + 32);
        } else {
            T += s;
        }
    }

    cout << T << '\n';

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	int n; cin>>n;
  	vector<int> m(n);
  
  	for (int i=0;i<n;i++){
    	cin>>m.at(i);
    }
  	
  	bool a=true;
  	int count=0;
  	while(a){
  	for( int i=0;i<n;i++){
    	if(m.at(i)%2==0){
        	m.at(i)=m.at(i)/2;  
        }else{
        	a=false;
          	cout<<count<<endl;
          	return 0;
        }
    }
      count++;  	
    }
}


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


int main(){
  string s;
  cin >> s;
  int out[100010];
  int num[26];
  for(int i=0;i<s.size();i++){
    out[i] = int(s[i]-97);
  }

  for(int k=0;k<s.size();k++){
    num[out[k]]++;
  }
  bool flag = false;
  
  for(int j=0;j<26;j++){
    if(num[j] == 0){
      cout << (char)(j+97) << endl;
      flag = true;
      break;
    }
  }
  if(flag == false) cout << "None" << endl;
}

Measured memory_bytes: 896
#include<stdio.h>
#include<iostream>
using namespace std;

int main(){


int N1,N2;
int G=0,x,y;
cin>>N1;
while(N1--){
cin>>N2;
int hm=0;
int dl=0;
int n[103]={};
for(int i=0;i<N2;i++)
{	cin>>n[i];if(i>0){
if(n[i-1]<n[i]&&n[i]-n[i-1]>hm)hm=n[i]-n[i-1];
if(n[i-1]>n[i]&&dl<n[i-1]-n[i])dl=n[i-1]-n[i];
}
//cout<<hm<<" "<<dl<<endl;
}

cout<<hm<<" "<<dl<<endl;
}
return 0;
}

Measured memory_bytes: 1160
def ascan; gets.split.map(&:to_i);end

n = gets.to_i
aa = ascan

@man = []

def ok?(aa)
    yes = true
    last = aa[0]
    aa[1..-1].each do |e|
        yes &= last <= e
        last = e
    end
    yes
end

def dfs(aa, offset = 0)
    #p aa
    return aa if aa.empty? || ok?(aa)
    
    ix = aa.index(aa.max_by{|a| a.abs})
    x = aa[ix]
    
    if x > 0
        if ix != 0
            a2 = dfs(aa[0...ix], offset)
            a2.size.times{|i| aa[i] = a2[i]}
            if aa[ix-1] > aa[ix]
                ix -= 1
            end
        end
        #p [aa,ix]
        
        i = ix
        while i < aa.size-1
            while aa[i+1] < aa[i]
                aa[i+1] += aa[i]
                @man << [i+offset, i+offset+1]
            end
            i += 1
        end
        ix = aa.index(aa.max_by{|a| a.abs})
        #p [aa,ix]
        dfs(aa[(ix+1)..-1], offset + ix + 1)
        
    elsif x < 0
        if ix != aa.size-1
            a2 = dfs(aa[(ix+1)..-1], offset + ix + 1)
            a2.size.times{|i| aa[-i-1] = a2[-i-1]}
            if aa[ix+1] < aa[ix]
                ix += 1
            end
        end
        #p [aa,ix]
        
        i = ix
        while 0 < i
            while aa[i-1] > aa[i]
                aa[i-1] += aa[i]
                @man << [i+offset, i+offset-1]
            end
            i -= 1
        end
        ix = aa.index(aa.max_by{|a| a.abs})
        #p [aa,ix]
        dfs(aa[0...ix], offset)
    end
    aa
end

1.times do
    #aa = (1..10).map{rand(-100..100)}; @man.clear
    
    _aa = aa.clone
    _aaa = aa.clone
    dfs(aa.clone)
    
    @man.each do |q|
        x,y = q
        _aa[y]+=_aa[x]
    end
    
    unless ok?(_aa)
        puts _aaa*" "
        p @man
        abort
    end
    abort unless ok?(_aa)
    
end
    

puts @man.size
puts @man.map{|x,y| "#{x+1} #{y+1}"}*"\n"



Measured memory_bytes: 1788