akhauriyash/Code-Regression huggingface dataset:
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#include <set>
#include <map>
#include <numeric>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;

int main(){
  ll n;
  cin >> n;
  ll ans;
  REP(i,n){
    ll a;
    cin >> a;
    ans += a;
  }
  ans -= n;
  cout << ans << endl;
  return 0;
}


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

int main() {
  int N;
  cin>>N;
  vector<int64_t> vec(N);
  for(int i=0;i<N;i++){
    cin>>vec.at(i);
  }
  int64_t sum=0;
  int64_t ksum=0;
  for(int i=1;i<N;i++){
    ksum+=vec.at(i);
    ksum=ksum%1000000007;
  }
  
  for(int i=0;i<N-1;i++){
    sum+=(vec.at(i)*ksum)%1000000007;
    sum=sum%1000000007;
    ksum-=vec.at(i+1);
    if (ksum < 0) ksum += 1000000007;
  }
  cout<<sum<<endl;  
  
}

Measured memory_bytes: 4852
#include <bits/stdc++.h>
long long a[10000007] = {0};
using namespace std;
int main(){
	int n;
	cin >> n; 
	for(int i = 1; i < 10000007; i++){
		for(int j = i; j < 10000007; j += i){
			a[j]++;
		}
	}
	long long ans = 0;
	for(int i = 1; i <= n; i++) ans += i * a[i];
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 81732
#include <bits/stdc++.h>
using namespace std;
using Int = int_fast64_t;

Int n, ans;
vector<Int> a;
set<Int> s;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> n;
	a.resize(n);
	for(Int i=0; i<n; ++i){
		Int t;
		cin >> t;
		a[t-1] = i;
	}
	for(Int i=n-1; i>=0; --i){
//		cout << i+1 << " " << a[i]+1 << " " << ans << "\n";
		auto j = s.insert(a[i]).first;
		if(j == s.begin()){
			if(j == prev(s.end())){
//				cout << "Case 0\n";
				continue;
			}
			auto k = next(j);
			if(k == prev(s.end())){
				ans += (n - *k) * (*j + 1) * (i + 1);
//				cout << "Case 1\n";
			}else{
				auto l = next(k);
				ans += (*l - *k) * (*j + 1) * (i + 1);
//				cout << "Case 2\n";
			}
		}else if(j == prev(s.end())){
			auto k = prev(j);
			if(k == s.begin()){
				ans += (*k + 1) * (n - *j) * (i + 1);
//				cout << "Case 3\n";
			}else{
				auto l = prev(k);
				ans += (*k - *l) * (n - *j) * (i + 1);
			}
		}else{
			auto k = next(j);
			auto p = prev(j);
			if(k == prev(s.end())){
				ans += (n - *k) * (*j - *p) * (i + 1);
				if(p == s.begin()){
					ans += (*k - *j) * (*p + 1) * (i + 1);
				}else{
					ans += (*k - *j) * (*p - *prev(p)) * (i + 1);
				}
			}else{
				ans += (*next(k) - *k) * (*j - *p) * (i + 1);
				if(p == s.begin()){
					ans += (*k - *j) * (*p + 1) * (i + 1);
				}else{
					ans += (*k - *j) * (*p - *prev(p)) * (i + 1);
				}
			}
		}
	}
	cout << ans << "\n";
}

Measured memory_bytes: 5760
#include <stdio.h>
#include <assert.h>
#include <fstream>
#include <iostream>
#include <algorithm>
#include <array>
#include <vector>
#include <queue>
#include <set>
#include <cmath>
//#include <unordered_map>
//#include <unordered_set>
//#include <boost/container/static_vector.hpp>
//#include <boost/unordered_set.hpp>
//#include <boost/unordered_map.hpp>
//#include <unistd.h>

const int MAX_N = 100050;
int N, M;
int X[MAX_N];

long long card_num[MAX_N], mod_num[MAX_N], mod_pair_num[MAX_N];

int main(int argc, char **argv) {
    std::cin >> N >> M;

    for (int i = 1; i <= N; i++) {
        std::cin >> X[i];
    }

    for (int i = 1; i <= N; i++) {
        card_num[X[i]]++;
    }

    for (int i = 1; i < MAX_N; i++) {
        mod_num[i%M] += card_num[i];
        mod_pair_num[i%M] += card_num[i] / 2;
    }

    long long ret = 0;
    for (int i = 0; i * 2 <= M; i++) {
        if (i == 0 || i * 2 == M) {
            ret += mod_num[i] / 2;
        } else {
            long long tmp = std::min(mod_num[i], mod_num[M-i]);
            ret += tmp;
            ret += std::min((mod_num[i] - tmp) / 2, mod_pair_num[i]);
            ret += std::min((mod_num[M-i] - tmp) / 2, mod_pair_num[M-i]);
        }
    }

    std::cout << ret << std::endl;

    return 0;
}



Measured memory_bytes: 2944
#include<cmath>
#include<cstdio>
#include<iostream>
using namespace std;
int main(){
	int T;
	long long int a,b;
	scanf("%d",&T);
	while(T--){
		scanf("%lld%lld",&a,&b);
		if(a>b) swap(a,b);
		if(a==b) printf("%lld\n",2*a-2);
		else if(a+1==b) printf("%lld\n",2*a-2);
		else{
			long long int c=sqrt(a*b);
			if(c*c==a*b) --c;
			if(c*(c+1)>=a*b) printf("%lld\n",2*c-2);
			else printf("%lld\n",2*c-1);
		}
	}
	return 0;
}

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

int main() {
    int a, b, c, t;
    cin >> a >> b >> c;
    if (a > b) {t = a; a = b; b = t;}
    if (b > c) {t = b; b = c; c = t;}
    if (a > b) {t = a; a = b; b = t;}
    cout << a << " " << b << " " << c << endl;
    return 0;
}

Measured memory_bytes: 3096
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define INF 1000000000
int main(){
cin.tie(0);
ios::sync_with_stdio(false);

	int N;
	cin>>N;
	int co[9]={0};
	REP(i,N){
		int A;
		cin>>A;
		if(A<=399)co[0]++;
		else if(A<=799 && 400<=A)co[1]++;
		else if(A<=1199 && 800<=A)co[2]++;
		else if(A<=1599 && 1200<=A)co[3]++;
		else if(A<=1999 && 1600<=A)co[4]++;
		else if(A<=2399 && 2000<=A)co[5]++;
		else if(A<=2799 && 2400<=A)co[6]++;
		else if(A<=3199 && 2800<=A)co[7]++;
		else co[8]++;
	}
	int ans=0;
	REP(i,8){
		if(co[i]>0)
		ans++;
	}
	if(ans==0)
		cout<<1<<" "<<co[8]<<endl;
	else if(co[8]>0){
		cout<<ans<<" "<<ans+co[8]<<endl;
	}
	else
		cout<<ans<<" "<<ans<<endl;
		
	return 0;
}

Measured memory_bytes: 256
use std::io::Read;
use std::cmp::max;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

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

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let n: usize = iterator.next().unwrap().parse().unwrap();
    let mut a: Vec<isize> = (0..n).map(|_| iterator.next().unwrap().parse().unwrap()).collect();
    a.sort();

    if n % 2 == 0 {
        let mut b: Vec<isize> = vec![-1, 1];
        for _ in 0..((n - 2) / 2) {
            b.push(2);
            b.push(-2);
        }
        b.sort();

        let mut ans = 0;
        for i in 0..n {
            ans += a[i] * b[i];
        }
        return ans.to_string();
    }

    let mut b1: Vec<isize> = vec![-1, -1];
    let mut b2: Vec<isize> = vec![1, 1];
    for _ in 0..(n / 2) {
        b1.push(2);
        b2.push(-2);
    }
    for _ in 0..(n / 2 - 1) {
        b1.push(-2);
        b2.push(2);
    }
    b1.sort();
    b2.sort();

    let mut ans1 = 0;
    let mut ans2 = 0;
    for i in 0..n {
        ans1 += a[i] * b1[i];
        ans2 += a[i] * b2[i];
    }
    max(ans1, ans2).to_string()
}


Measured memory_bytes: 5840
#include <stdio.h>

int main(void)
{
	int i,n;
	int x=0;
	int max=0;
	char str[101];
	scanf("%d",&n);
	scanf("%s",str);
	for(i=0;i<n;i++){
		if(str[i]=='I'){
			x++;
		}
		else{
			x--;
		}
		if(max<x){
			max=x;
		}
	}
	printf("%d",max);
	
}

Measured memory_bytes: 128
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

	static Scanner scanner;

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

	    int N=gi();
	    long[] A=new long[N];
	    Map<Long,Boolean> m=new HashMap<Long, Boolean>();
	    for (int i=0; i<N;i++) {
	    	A[i]=gl();
	    	if(m.containsKey(A[i])) {
	    		m.put(A[i], !m.get(A[i]));
	    	} else {
	    		m.put(A[i], true);
	    	}
	    }
	    int c=0;
	    for (Boolean f: m.values()) {
	    	if(f)c++;
	    }
	    System.out.print(c);
//        if (f) {
//    	    System.out.print("Yes");
//        }else {
//        	System.out.print("No");
//        }
	}

	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}

	// doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	}
}

Measured memory_bytes: 66212
program test03_3
 implicit none
 integer first, last
 integer N
 integer,allocatable :: A(:)
 integer i,j
 integer :: kekka=0

 read *, N
 allocate(A(N))
 read *,A

 first=1
 last=N

 call quicksort1(A,first,last)

 do i=1,N-1
  if (A(i)==A(i+1)) kekka=1
 end do

 if (kekka==0) print '(A)', 'YES' 
 if (kekka==1) print '(A)', 'NO' 

contains
recursive subroutine quicksort1(a, first, last)
implicit none
integer::a(N)
integer,intent(in)::first,last

 double precision::x,t
 integer::i,j

 x = a((first+last)/2)
 i = first
 j = last

do 
  do while (a(i) < x)
   i=i+1
  end do
  do while (x < a(j))
   j=j-1
  end do

  if (i >= j) exit
    t = a(i)
    a(i) = a(j)
    a(j) = t
    i=i+1
    j=j-1
end do

 if (first < i-1) call quicksort1(a, first, i-1)
 if (j+1 < last)  call quicksort1(a, j+1, last)
end subroutine quicksort1

endprogram test03_3


Measured memory_bytes: 1536
#include <stdio.h>
int main(){
  int n,i,x;
  scanf("%d",&n);
  for(i=1;i<=n;i++){
    x=i;
    if(x%3==0){
      printf(" %d",x);
    }
    else{
      while(x){
      if(x%10==3){ 
    printf(" %d",i);
        break;
      }
      x=x/10;
      }
    }
  }
    printf("\n");
  return 0;
}


Measured memory_bytes: 2048
#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
#include<utility>
#include<map>
#include<set>
#include<string>

using namespace std;

#define ll long long

int main(){
    ll n;
    ll t4, t2, t;
    cin >> n;
    vector<ll> a(n),b,c;
    for(int i = 0; i < n; i++) cin >> a[i];
    for(int i = 0; i < n; i++){
        if(a[i] % 4 == 0) t4++;
        else if(a[i] % 2 == 0) t2++;
        else t++; 
    }
    if(t2 > 0){
        if(t4 >= t){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
    }else{
        if(t4 >= t - 1){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
    } 
}


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

void print_top3(int *top3) {
	int i;
	for (i = 0; i < 3; i++) {
		printf("%d\n", top3[i]);
	}
}

int main() {
	char buf[256];
	int top3[3];
	int n, i, j, trade;
	
	// initialize
	memset(top3, 0, sizeof(int) * 3);
	
	for (j = 0; j < 10; j++) {
		fgets(buf, sizeof(buf), stdin);
		n = atoi(buf);
		
		if (n <= top3[2]) { continue; }
		
		top3[2] = n;
		for (i = 1; 0 <= i; i--) {
			if (top3[i] < top3[i + 1]) {
				trade = top3[i];
				top3[i] = top3[i + 1];
				top3[i + 1] = trade;
			}
		}
	}
	
	print_top3(top3);
	
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
inline ll read()
{
    ll x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9')
    {
        if(ch=='-')
            f=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9')
    {
        x=x*10+ch-'0';
        ch=getchar();
    }
    return x*f;
}
int n;
ll s[100005];
int main()
{
	cin>>n;
	for(int i=0;i<n;i++)
		scanf("%I64d",s+i);
	sort(s,s+n);
	ll ans,k=0;
	for(int i=n-1;i>0;i--)
	{
		if(s[i]==s[i-1])
		{
			if(k==0)
			{
				ans=s[i];
				i--;k++;
			}
            else
            {
				ans*=s[i];
				cout<<ans<<endl;
				return 0;
			}
		}
	}
	cout<<0<<endl;
	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=200010;
const ll mod=1e9+7;

  

int main(){
  string s,t; cin >> s >> t;
  int sz=s.size();
  s += s;
  if(s.find(t)!=std::string::npos){
    cout << "Yes" << endl;    
  } else {
    cout << "No" << endl;    
  }
 
  return 0;
}


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

#define all(x) (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define ll long long
#define ld long double
#define pb push_back
#define MOD 1000000007
#define LLMN LONG_LONG_MIN
#define LLMX LONG_LONG_MAX
#define LDMX LDBL_MAX
#define LDMN LDBL_MIN
#define MAX 1000000

ll mulmod(ll, ll);
ll fastpower(ll, ll);
void getprime(vector<ll>&);
void getfact(vector<ll>&, vector<ll>&);
ll ncr(ll, ll, vector<ll>&, vector<ll>&);

void solve()
{
    ll n, m, k, even = 0, odd =0;
    string s;
    cin>>n>>m;
    vector<ll>p(n);
    for(ll i=0;i<n;i++){
        cin>>p[i];
        p[i] /= 2;
        if(p[i]%2 == 0)
            even++;
        else
            odd++;
    }
    if(even > 0 && odd > 0)
        cout<<"0";
    else
    {
        ll lcm = p[0], res;
        for(ll i=1;i<n;i++)
        {
            lcm = (p[i] * lcm)/(__gcd(p[i], lcm));
            if(lcm > m)
            {
                cout<<"0";
                return;
            }
        }
        for(ll i=0;i<n;i++)
        {
            if(lcm / p[i] % 2 == 0)
            {
                cout<<"0";
                return;
            }
        }
        res = (m / lcm) - (m / (2*lcm));
        cout<<res;
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll t = 1;
    //cin>>t;
    while(t--)
    {
        solve();        
    }
    return 0;
}

ll mulmod(ll a, ll b)
{
    ll res = 0; 
    a = a % MOD;
    while(b > 0)
    {
        if (b % 2 == 1)
            res = (res + a) % MOD;
 
        a = (a * 2) % MOD; 
        b /= 2;
    } 
    return res % MOD; 
}

ll  fastpower(ll a, ll n)
{
    ll res = 1;
    while(n > 0)
    {
        if(n % 2 != 0)
        {
            res = (res * a) % MOD;
        }
        n /= 2;
        a = (a * a) % MOD;
    }
    return res;
}

void getprime(vector<bool>&prime)
{
    prime[0] = false;
    prime[1] = false;
    
    for(ll i = 2;i <= MAX; i++)
    {
        if(prime[i])
        {
            for(ll j = i*i; j <= MAX; j += i)
                prime[j] = false;
        }
    }
}

void getfact(vector<ll> &fact, vector<ll> &ifact)
{
    fact[0] = 1;
    ifact[0] = 1;
    
    for(ll i = 1; i <= MAX; i++)
    {
        fact[i] = (fact[i-1] * i)%MOD;
        ifact[i] = (ifact[i-1] * fastpower(i, MOD -2) )%MOD;
    }
}

ll ncr(ll n, ll r, vector<ll>&fact, vector<ll>&ifact)
{
    ll res;
    res = (((fact[n] * ifact[r]) % MOD) * ifact[n-r]) % MOD;
    return res;
}


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


int main(){
    string s;
    cin >> s;
    int cnt = 0;
    int lc = 0;
    for (auto c:s){
        if (c == 'A' || c == 'C' || c == 'G' || c == 'T'){
            cnt ++;
        }
        else{
            lc = max(lc, cnt);
            cnt = 0;
        }
    }
    lc = max(lc, cnt);
    cout << lc << endl;
    return 0;
}

Measured memory_bytes: 764
import java.util.*;

/* 46ツ閉ェツスツタツーツト */
public class Main {
	static class Team{
		int num , time;
		public Team(int n, int t1, int t2, int t3 , int t4 ) {
			num = n;
			time = t1 + t2 + t3 + t4;
		}
	}
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while ( !sc.hasNext("0") ) {
			LinkedList<Team> list = new LinkedList<Team>();
			int n = sc.nextInt();
			for ( int i = 0; i < n; i++ ) {
				int g = sc.nextInt();
				int t1 = sc.nextInt() * 60 + sc.nextInt();
				int t2 = sc.nextInt() * 60 + sc.nextInt();
				int t3 = sc.nextInt() * 60 + sc.nextInt();
				int t4 = sc.nextInt() * 60 + sc.nextInt();
				Team t = new Team(g,t1,t2,t3,t4);
				list.add(t);
			}
			Team win = list.get(0), swin = list.get(1) , boo = win , worst = win;
			for ( int i = 1; i < list.size(); i++ ) {
				if ( win.time > list.get(i).time ) {
					swin = win;
					win = list.get(i);
				} else if ( swin.time > list.get(i).time )
					swin = list.get(i);
				if ( worst.time < list.get(i).time ) {
					boo = worst;
					worst = list.get(i);
				} else if ( boo.time < list.get(i).time )
					boo = list.get(i);
			}
			System.out.println(win.num+"\n"+swin.num+"\n"+boo.num);
		}
	}
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define pb push_back
#define eb emplace_back
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
const ll INF = numeric_limits<ll>::max()/4;
const ll MOD = 1e9+7;
const int n_max = 1e5+10;

template<class T>
bool chmax(T &a, T b){if(a < b){a = b; return true;} return false;}
template<class T>
bool chmin(T &a, T b){if(a > b){a = b; return true;} return false;}
int main(){
    ll n; cin >> n;
    string s;cin >> s;
    vector<ll> west(n+1,0), east(n+1,0);
    rep(i,n){
        if(s[i] == 'W'){
            west[i+1] = west[i] + 1;
            east[i+1] = east[i];
        }
        else{
            west[i+1] = west[i];
            east[i+1] = east[i] + 1;
        }
    }
    ll ret = INF;
    rep(i,n){
        ll temp = west[i] - west[0] + east[n] - east[i+1];
        chmin(ret, temp);
    }
    cout << ret << endl;
}

Measured memory_bytes: 5380
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using ll = long long;
using namespace std;

int main() {
    int n;
    cin >> n;
    int a[n], a_array[n];

    // 最大値決定
    int first = 0;
    rep(i, n) {
        cin >> a[i];
        a_array[i] = a[i];
        first = max(a[i], first);
    }

    // 最大値を一つ0にする
    rep(i, n) {
        if(first == a[i]) {
            a[i] = 0;
            break;
        }
    }

    // 二番目を探す
    int second = 0;
    rep(i, n) { second = max(a[i], second); }

    rep(i, n) {
        if(a_array[i] != first) {
            cout << first << endl;
        } else {
            cout << second << endl;
        }
    }
}

Measured memory_bytes: 3200
from collections import deque
s = deque(list(input()))
q = int(input())

reverse_flag = 1

for i in range(q):
    query = input().split()
    if query[0] == "1":
        reverse_flag *= -1
    else:
        if query[1] == "1":
            if reverse_flag == 1:
                s.appendleft(query[2])
            else:
                s.append(query[2])
        else:
            if reverse_flag == 1:
                s.append(query[2])
            else:
                s.appendleft(query[2])


if reverse_flag == -1:
    s.reverse()

print("".join(s))


Measured memory_bytes: 74344
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
using VS = vector<string>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);--(i))
#define each(i, a) for(auto &i : a)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x) ((y) < 0 || h <= (y) || (x) < 0 || w <= (x))
#define line cout << "-----------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
#define stop system("pause")
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10;
constexpr ld pi = 3.1415926535897932;
template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; }return false; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T>inline istream& operator>>(istream& is, deque<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }

int main() {
    init();

    int n; cin >> n;
    map<int, int> m;
    eFOR(i, 2, n) {
        int a = i;
        for (int j = 2; j * j <= a; ++j) {
            while (a % j == 0) {
                a /= j;
                ++m[j];
            }
        }
        if (1 < a)++m[a];
    }

    ll ans = 1;
    each(i, m)(ans *= i.second + 1) %= mod;
    cout << ans << "\n";
}

Measured memory_bytes: 256
import java.io.*;

class Main{
    public static void main(String[] args) throws IOException{
        
        int x,y,i,j;
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        
        while(true){
            String[] str = br.readLine().split(" ");
            x = Integer.parseInt(str[0]);
            y = Integer.parseInt(str[1]);
            
            if(x == 0 && y ==0){
                break;
            }
            
            for(i = 0; i < x; i++){
                for(j = 0; j < y; j++){
                    if(i%2 == 0){
                        if(j%2 == 0){
                            System.out.printf("#");
                        }else{
                            System.out.printf(".");
                        }
                    }else{
                        if(j%2 == 0){
                            System.out.printf(".");
                        }else{
                            System.out.printf("#");
                        }
                    }
                }
                System.out.printf("\n");
            }
            System.out.printf("\n");
        }
    }
}

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

int main(){
  string S;
  cin >> S;
  int N = S.size() / 2;
  int count = 0;
  rep(i, N){
    if(S.at(i) != S.at(S.size() - i - 1)) count++;
  }
  
  cout << count << endl;
}

Measured memory_bytes: 384
import java.util.*;


public class Main {
	
	Scanner cin = new Scanner(System.in);
	
	public static void main(String[] args) {
		new Main().run(); 
	}
	
	public void run() {		
		
		/*input*/
		
		int n = cin.nextInt();
		
		/*start*/
		
		long res = (1 + n) * n / 2;
		
		/*finish*/
		System.out.println(res);
	}
}



Measured memory_bytes: 23636
#include <iostream>
#include <array>
#include <map>
#include <algorithm>
#include <cmath>
#include <vector>
#include <fstream>
#include <string>
#include <random>
#include <queue>
#include <iomanip>
#include <functional>
#include <climits>
#include <tuple>
#include <unordered_map>
#include <limits>
#include <functional>
#include <cassert>
#include <numeric>
#include <bitset>
#include <set>

#define FOR(x,n) for(int x = 0; x < n; x++)
#define INPUT(x) scanf("%d",&x)
#define PUT(x) printf("%d\n",x)
#define DPUT(x) printf("%.15lf\n",x)
#define GET(x,y) std::get<x>(y)
#define CHMAX(x,y) x = std::max(x,y)
#define CHMIN(x,y) x = std::min(x,y)
#define SP_END (i != n - 1 ? ' ' : '\n') ;

using namespace std;

using ll = long long int;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vll = std::vector<ll>;
using vpll = std::vector<pll>;
using vpii = std::vector<pii>;
using vi = std::vector<int>;
using vvi = std::vector<vi>;
using vvpii = std::vector<vpii>;
using vch = std::vector<char>;
using vvch = std::vector<vch>;
using tiii = std::tuple<int, int, int>;

const ll mod197 = 1000000007LL;
const ll INF = 10000000000LL;

const double PI11 = 3.14159265359;

const int dis[5] = { 0,1,0,-1,0 };

const int disD[4] = { 0,1,1,0 };
const int disLD[3] = { 0,1,0 };

const char disC[4] = { 'U','D','R','L' };
const char disY[4] = { -1,1,0,0 };
const char disX[4] = { 0,0,1,-1 };

//最大公約数
ll gcd(ll a, ll b) {
	if (a%b == 0)
		return b;
	return gcd(b, a%b);
}

int A[1000001] = {};

int main(void)
{
	int N, total = 0, pos = 0;
	cin >> N;

	for (int i = 0; i < N; i++) {
		cin >> A[i];
		total += abs(A[i] - pos);
		pos = A[i];
	}

	total += abs(pos - 0);

	pos = 0;

	for (int i = 0; i < N; i++) {
		cout << total + ( abs(A[i + 1] - pos) - (abs(A[i] - pos) + abs(A[i + 1] - A[i]))) << endl;
		//cerr << (abs(A[i + 1] - pos)) << " " << (abs(A[i] - pos) + abs(A[i + 1] - A[i])) << endl;
		pos = A[i];
	}


	return 0;
}


Measured memory_bytes: 1664
#define LOCAL
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rrep(i, n) for(int i=(n-1); i>=0; --i)
#define rep2(i, s, n) for(int i=s; i<(n); ++i)
#define ALL(v) (v).begin(), (v).end()
#define memr(dp, val) memset(dp, val, sizeof(dp))
using namespace std;
typedef long long ll;
static const int INTINF = (INT_MAX >> 1); // 10^9 + 10^7
static const ll LLINF = (LLONG_MAX >> 1);
static const int MAX = 100001;
static const ll MOD = 1000000007;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> inline bool int_ceil(T a, T b) { T res = a / b; if(a % b != 0) res++; return res; }
template<typename T>
using min_priority_queue = priority_queue<T, vector<T>, greater<T> >;
string to_string(string s) { return '"' + s + '"'; }
string to_string(bool b) { return b ? "true" : "false"; }
template <size_t N> string to_string(bitset<N> bs) {
  string res;
  for (size_t i = 0; i < N; ++i) res += '0' + bs[i];
  return res;
}
string to_string(vector<bool> v) {
  string res = "{";
  for (bool e : v) res += to_string(e) + ", ";
  return res += "}";
}
template <class T, class U> string to_string(pair<T, U> p);
template <class C> string to_string(C c) {
  string res = "{";
  for (auto e : c) res += to_string(e) + ", ";
  return res += "}";
}
template <class T, class U> string to_string(pair<T, U> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
void debug() { cerr << '\n'; }
template <class Head, class... Tail> void debug(Head head, Tail... tail) {
  cerr << '\t' << to_string(head), debug(tail...);
}
#ifdef LOCAL
#define print(...) cerr << "[" << #__VA_ARGS__ << "]:", debug(__VA_ARGS__)
#else
#define print(...)
#endif

int main(int argc, const char * argv[]) {
	std::cout << std::fixed << std::setprecision(15);

	int n, m, c;
	cin >> n >> m >> c;
	vector<int> b(m);
	rep(i, m){
		cin >> b[i];
	}
	int ans = 0;
	rep(i, n){
		int res = 0;
		rep(j, m){
			int a; cin >> a;
			res += a * b[j];
		}
		// print(res);
		if(res + c > 0) ans++;
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define debug(x) cerr << #x << " = " << x << "\n"
#define debugv(x) rep(i, x.size()) cerr << x[i] << (i == x.size() - 1 ? "\n" : " ")
using namespace std;
#define int long long
typedef long long ll;
typedef pair<int, int> pii;
const int INF = ((1LL << 30) + (1LL << 29));
const int MOD = 1000000007;

//=============================
int N;
vector<int> A;
vector<int> B;
//=============================
void input()
{
    cin>>N;
    A.resize(N);
    B.resize(N);
    rep(i,N){
        cin>>A[i];
        B[i]=A[i]-i-1;
    }

}
//=============================
void func() {}
//=============================
void solve()
{
    sort(B.begin(),B.end());

    int b = (N%2 ? B[N/2] : (B[N/2]+B[N/2-1])/2);
    int ans1=0;
    int ans2=0;
    int ans3=0;
    int c = B[(N-1)/2];
    int ans4 = 0;

    for(auto x : B){
        ans1 += abs(x-b);
        ans2 += abs(x-b+1);
        ans3 += abs(x-b-1);
        ans4 += abs(x-c);
    }
    cout<<min({ans1,ans2,ans3,ans4})<<endl;


}
//=============================
signed main()
{
    input();
    solve();
    return 0;
}

Measured memory_bytes: 3328
#include <stdio.h>

int main() {
  int n, i, j, v, A[1000];

  scanf("%d", &n);
  for(i = 0;i < n;i++)
    scanf("%d", &A[i]);

  for(i = 0;i < n;i++) {
    v = A[i];
    j = i - 1;

    while(j >= 0 && A[j] > v) {
      A[j + 1] = A[j];
      j--;
    }

    A[j + 1] = v;

    for(j = 0;j < n - 1;j++)
      printf("%d ", A[j]);

    printf("%d\n", A[j]);
  }

  return 0;
}



Measured memory_bytes: 2044
import copy
a,b=map(int,input().split())
s1=set()
s2=set()
for i in range(1,int(a**0.5)+1):
  if a%i==0:
    s1.add(i)
    s1.add(a//i)
for i in range(1,int(b**0.5)+1):
  if b%i==0:
    s2.add(i)
    s2.add(b//i)
s=s1&s2
l=sorted(list(s))
for i in range(1,len(l)):
  for j in range(i+1,len(l)):
    if l[j]%l[i]==0 and l[j] in s:
      s.remove(l[j])
print(len(s))

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

int main() {
  ll n, k;
  cin >> n >> k;
  n = n % k;
  while (true)
  {
    n = min(n, abs(n - k));
    if (n <= k / 2)  break;
  }
  cout << n;
  return 0;
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  string s,t;
  cin >> s >> t;
  long int cost = 0;
  for(int i=0;i<s.size();i++) {
    if(s[i]!=t[i]) {
      cost++;
    }
  }
  cout << cost << endl;
  return 0;
}

Measured memory_bytes: 3732
#include<iostream>
#include<algorithm>
#include <vector>
#include<cmath>
using namespace std;
int main() {
	int a;
	string S;
	cin >> a;
	cin >> S;
	if (a >= 3200) {
		cout << S << endl;
	}
	else {
		cout << "red" << endl;
	}

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main () {
  
  int n, m;
  cin >> n >> m;
  
  vector<pair<int , int>> war;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    war.push_back({a, b});
  }
  
  sort(war.begin(), war.end());
  
  int c = 1;
  int d = war[m-1].first;
  
  for (int i = m-2; i >= 0; i = i-1) {
    if (war[i].second <= d) {
      c = c + 1;
      d = war[i].first;
    }
  }
  
  cout << c << endl;
  
}

Measured memory_bytes: 1400
n = STDIN.gets.to_i
array = STDIN.gets.split.map(&:to_i)
counter = 0
flag = false
for i in 0..(n-1) do
  minj = i
  flag = false
  for j in i..(n-1) do
    if array[j] < array[minj]
      minj = j
      flag = true
    end
  end
  tmp = array[i]
  array[i] = array[minj]
  array[minj] = tmp
  if flag then
    counter += 1
  end
end

puts array.join(' ')
puts counter

Measured memory_bytes: 8660
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fi first
#define se second
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define endl '\n'
#define ld long double
typedef pair<ll,ll> pii;
const int maxn=5005;
const int mod=1e9+7;
ll f[maxn][maxn];
char s[maxn];
int main()
{
    #ifdef local
    freopen("in.txt","r",stdin);
    #endif // local
    IOS;
    f[0][0]=1;
    for(int i=1;i<=5000;i++)
    {
        for(int j=0;j<=5000;j++)
        {
            f[i][j]+=f[i-1][j+1]*2;
            if(!j) f[i][j]+=f[i-1][j];
            else f[i][j]+=f[i-1][j-1];
            f[i][j]%=mod;
        }
    }
    int n;
    cin>>n;
    cin>>s+1;
    int k=strlen(s+1);
    cout<<f[n][k]<<endl;
}


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

using namespace std;

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

    int n, a, b;
    cin >> n >> a >> b;
    int sub = abs(a - b);
    if (sub % 2) cout << "Borys" << endl;
    else cout << "Alice" << endl;
 
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int a,b,temp1=0,temp2=0; cin>>a>>b;
    temp2=a;
    bool ans=false;
    for(int i = 0; i<=a; i++){
        temp1=i;
        temp2=a-i;
        if((temp1*2+temp2*4)==b){
            ans=true;
        }
    }
    if(ans==true){
        cout << "Yes";
    }
    else{
        cout << "No";
    }
}

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

typedef long long ll;
const ll INF = 1LL << 60;
const int mod = 1000000007;

ll mod_pow(ll x, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }

    return res;
} 

ll choose(ll n, ll a) {
    ll x = 1;
    rep(i, a) {
        x *= (n - i);
        x %= mod;
    }
    rep(i, a) {
        x *= mod_pow(i + 1, mod - 2, mod);
        x %= mod;
    }

    return x;
}
int n, a, b;
int main() {
    cin >> n >> a >> b;

    ll ans = mod_pow(2, n, mod) - 1;
    // cout << ans << endl;
    // cout << choose(n, a) << endl;
    ans -= choose(n, a);
    ans -= choose(n, b);
    // cout << ans << endl;
    ans%=mod;
    // cout << ans << endl;
    ans+=mod;
    // cout << ans << endl;
    ans%=mod;
    cout << ans << endl;
}

Measured memory_bytes: 256
n, q = map(int, input().split())

neighbor = [[] for _ in range(n+1)]
for i in range(n-1):
    a, b = map(int, input().split())
    neighbor[a].append(b)

root_value = [0] * (n+1)
for i in range(q):
    p, x = map(int, input().split())
    root_value[p] += x

res = [0] * (n+1)
queue = [(1, root_value[1])]
while len(queue) > 0:
    pair = queue.pop()
    res[pair[0]] += pair[1]
    if neighbor[pair[0]] != []:
        for i in neighbor[pair[0]]:
            queue.append((i, pair[1] + root_value[i]))
    
for i in res[1:]:
    print(i, end=" ")

Measured memory_bytes: 95616
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, std.bitmanip;

immutable long MOD = 10^^9 + 7;

void main() {
    auto s = readln.split.map!(to!int);
    auto N = s[0];
    auto M = s[1];
    auto A = readln.split.map!(to!long).array;
    auto B = new long[](N+1);
    foreach (i; 0..N) B[i+1] = B[i] + A[i];

    long[long] cnt;
    foreach (i; 1..N+1) cnt[B[i] % M] += 1;
    long ans = 0;

    foreach (i; 0..N) {
        if ((B[i] % M) in cnt)
            ans += cnt[B[i] % M];
        cnt[B[i+1]%M] -= 1;
    }

    ans.writeln;
}


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

using namespace std;

int main() {
    int A, B, K;
    cin >> A >> B >> K;

    for (int i = 0; i < K; ++i) {
        if (A % 2 == 1) A--;
        A /= 2;
        B += A;
        swap(A, B);
    }
    if (K % 2 == 1) swap(A, B);
    cout << A << " " << B << endl;
    return 0;
}


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

#define pout(n)  printf ("%d\n", n)

#define rep(i,a,n) for (int i = a;i < n;i++)
#define per(i,n,a) for (int i = n-1;i >= a;i--)

typedef long long ll;
using namespace std;
 
int main (){
  int n;
  ll a = 1;
  cin >> n;

  rep(i,1,n+1){
    a = a*i%(1000000000+7);
  }
  printf("%lld\n",a);

  return 0;
}

Measured memory_bytes: 256
#include <queue>
#include <string>
#include <vector>
#include <iostream>
using namespace std;
struct edge {
	int to, cost;
};
struct state {
	int pos, cost, used;
};
bool operator<(const state& s1, const state& s2) {
	return s1.cost < s2.cost;
}
int X, Y, T, M, a[9], c; string s1, s2;
int main() {
	while (cin >> X >> Y >> T >> M, X) {
		for (int i = 0; i < X; i++) cin >> a[i];
		vector<string> v(X + Y + 2);
		v[0] = "H"; v[1] = "D";
		for (int i = 2; i < X + 2; i++) v[i] = "C" + to_string(i - 1);
		for (int i = X + 2; i < X + Y + 2; i++) v[i] = "L" + to_string(i - X - 1);
		vector<vector<edge> > G(X + Y + 2);
		for (int i = 0; i < M; i++) {
			cin >> s1 >> s2 >> c;
			int p1 = -1, p2 = -1;
			for (int j = 0; j < X + Y + 2; j++) {
				if (s1 == v[j]) p1 = j;
				if (s2 == v[j]) p2 = j;
			}
			G[p1].push_back(edge{ p2, c });
			G[p2].push_back(edge{ p1, c });
		}
		vector<vector<int> > dist(X + Y + 2, vector<int>(1 << X, 999999999)); dist[0][0] = 0;
		priority_queue<state> que; que.push(state{ 0, 0, 0 });
		while (!que.empty()) {
			state u = que.top(); que.pop();
			for (edge e : G[u.pos]) {
				int bit = u.used;
				if (2 <= e.to && e.to < X + 2) {
					if (bit & (1 << (e.to - 2))) continue;
					bit |= 1 << (e.to - 2);
				}
				int cost = dist[u.pos][u.used] + e.cost * T;
				if (dist[e.to][bit] > cost) {
					dist[e.to][bit] = cost;
					que.push(state{ e.to, -cost, bit });
				}
			}
		}
		int ret = 999999999;
		for (int i = 0; i < 1 << X; i++) {
			int res = dist[1][i];
			for (int j = 0; j < X; j++) {
				if (i & (1 << j)) res -= a[j];
			}
			ret = min(ret, res);
		}
		cout << ret << endl;
	}
	return 0;
}

Measured memory_bytes: 3336
N = int(input())
if N == 1:
  print(0)
else:
  d = {}
  n = N
  i = 2
  while i*i <= n:
    if n % i == 0:
      d[i] = 1
      n //= i
      while n % i == 0:
        n //= i
        d[i] += 1
    i += 1
  if n != 1:
    d[n] = 1
  ans = 0
  for i in d.values():
    ok = 1
    ng = 50
    while ng-ok > 1:
      mid = (ok+ng)//2
      if mid*(mid+1)//2 <= i:
        ok = mid
      else:
        ng = mid
    ans += ok
  print(ans)


Measured memory_bytes: 63124
#include <bits/stdc++.h>
#include <numeric>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rep1(i,n) for (int i = 1; i <= n; ++i)
template<typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;

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

  string s; cin >> s;
  int ss = s.size();

  ll ans = 0;
  int a = 0;

  rep(i, ss) {
    if(s[i] == 'A') ++a;
    else if(s[i] == 'B') {
      if(i + 1 < ss && s[i + 1] == 'C') {
        ans += a;
        ++i;
      } else {
        a = 0;
      }
    } else {
      a = 0;
    }
  }

  cout << ans << endl;
}


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

#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()
#define MOD 1000000007

typedef long long int ll;

const ll INF=(ll)1e19;
//const int INF=(1<<30);

int c[3][3];
int a[3];
int b[3];

int main(){
  REP(i,3)REP(j,3)cin >> c[i][j];

  a[0]=0;

  REP(i,3)b[i]=c[0][i]-a[0];
  FOR(i,1,3)a[i]=c[i][0]-b[0];

  bool ok=true;
  FOR(i,1,3)FOR(j,1,3){
    if(c[i][j] != a[i]+b[j]){
      ok=false;
      break;
    }
  }

  if(ok){
    cout << "Yes" << endl;
    exit(0);
  }

  cout << "No" << endl;

}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <stack>

using namespace std;
typedef long long ll;

int main(){
    string s;
    getline(cin, s);
    stack<ll> x;
    ll count = 0;
    for(char c : s){
        if(x.empty() || x.top() == c){
            x.push(c);
        }else{
            count += 2;
            x.pop();
        }
    }
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> l_l;
const int INF=1001001000;
const int mINF=-1001001000;
const ll LINF=1010010010010010000;
template<class T> inline bool chmin(T& a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template<class T> inline bool chmax(T& a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}

bool d[3][3][2005];

int main(){
    vector<string> s(3);
    for(int i=0;i<3;i++) cin >> s[i];
    sort(s.begin(),s.end());
    int ans=6010;
    do{
        for(int i=0;i<3;i++){
            for(int j=0;j<3;j++){
                if(i>=j) continue;
                for(int k=0;k<s[i].size();k++){
                    bool ok=true;
                    for(int ni=k;ni<s[i].size();ni++){
                        int nj=ni-k;
                        if(nj>=s[j].size()) continue;
                        if(s[i][ni]=='?'||s[j][nj]=='?') continue;
                        if(s[i][ni]!=s[j][nj]) ok=false;
                    }
                    d[i][j][k]=ok;
                }
            }
        }
        auto f = [&](int i, int j, int k) {
            if (k >= s[i].size()) return true;
            return d[i][j][k];
        };
        for(int i=0;i<2005;i++){
            for(int j=0;j<2005;j++){
                if(!f(0,1,i)) continue;
                if(!f(1,2,j)) continue;
                if(!f(0,2,i+j)) continue;
                int now=0;
                now=max(now,i+(int)s[1].size());
                now=max(now,i+j+(int)s[2].size());
                now=max(now,(int)s[0].size());
                ans=min(ans,now);
            }
        }
    } while(next_permutation(s.begin(),s.end()));
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 384
#include <stdio.h>
#include <string.h>

int a[7];
char str[6];
int n,m,i,j,k,p,sum,t;


void N() {
  t = a[1];
  a[1] = a[2];
  a[2] = a[6];
  a[6] = a[5];
  a[5] = t;
}

void S() {
  t = a[1];
  a[1] = a[5];
  a[5] = a[6];
  a[6] = a[2];
  a[2] = t;
}

void E() {
  t = a[1];
  a[1] = a[4];
  a[4] = a[6];
  a[6] = a[3];
  a[3] = t;
}

void W() {
  t = a[1];
  a[1] = a[3];
  a[3] = a[6];
  a[6] = a[4];
  a[4] = t;
}


void R() {
  N();
  W();
  S();
}

void L() {
  N();
  E();
  S(); 
}

void reset() {
  for(i=1;i<=6;i++) a[i] = i;
}


int main() {

  while(1) {

  scanf("%d",&n);

  if(n == 0) break;

  sum = 0;
  j = 0;
  reset();
  for(i=0;j<n;i++) {
    scanf("%s",str);

    if(str[0] == 'N') N();
    else if(str[0] == 'W') W();
    else if(str[0] == 'S') S();
    else if(str[0] == 'E') E();
    else if(str[0] == 'R') R();
    else if(str[0] == 'L') L();
    sum += a[1];
    //  printf("a[1] = %d\nstr = %c\n",a[1],str[0]);
    j++;
  }

  printf("%d\n",sum+1);
  }

  return 0;

  }

Measured memory_bytes: 604
//g++ -std=c++11 -Wall test.cpp -o test -lm -g -O2
#include <bits/stdc++.h>
using namespace std;
#define sws                           \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define endl '\n'
#define ff first
#define ss second
#define pb push_back
#define vi vector<int>
#define vb vector<bool>
#define vs vector<string>
#define qi queue<int>
#define si stack<int>
#define s string
#define ll long long;
int soma_digitos(int a)
{
    int soma = 0;
    while (a != 0)
    {
        soma += a % 10;
        a /= 10;
    }
    return soma;
}
int main()
{
    sws;
    int k;
    int bb[3];
    cin >> bb[0] >> bb[1] >> bb[2];
    cin >> k;
    while (k--)
    {
        int ind = max(bb[0], max(bb[1], bb[2]));
        int i;
        for (i = 0; i < 3; i++)
        {
            if (bb[i] == ind)
                break;
        }
        bb[i] *= 2;
    }
    int sum = 0;
    for (int i = 0; i < 3; i++)
    {
        sum += bb[i];
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
# coding:utf-8

import sys
# from collections import Counter, defaultdict

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def S(): return input()


s = S()
print(s if len(s) == 2 else s[::-1])


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

int main () {
    int N;
    string S;
    cin >> N >> S;
    int ans = 1;
    for (int i = 0; i < N-1; i++) {
        if (S[i] != S[i+1]) ans++;    
    }
    cout << ans << endl;
    return 0;
}

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

int n, ans;

int main()
{
	scanf("%d",&n);
	int C = 0;
	for(int i=1;i<=n;i++) {
		int T;
		scanf("%d",&T);
		if(i != T) {
			ans += (C+1)/2;
			C = 0;
		}
		else C++;
	}
	printf("%d\n",ans+(C+1)/2);
}


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

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> dp(3);
  int a,b,c;
  while(n--){
    cin >> a >> b >> c;
    a+= max(dp[1],dp[2]);
    b+= max(dp[0],dp[2]);
    c+= max(dp[0],dp[1]);
    dp[0]=a,dp[1]=b,dp[2]=c;
  }
  cout << max({dp[0],dp[1],dp[2]});
  return 0;
}


Measured memory_bytes: 256
import Control.Monad

main :: IO ()
main = do
    n  <- read <$> getLine
    dx <- (map read) . words <$> getLine
    a  <- (map read) <$> replicateM n getLine
    putStrLn $ show $ solve dx a


solve :: [Int] -> [Int] -> Int
solve (d:x:[]) a =
    foldr (\b c -> (d - 1) `div` b + 1 + c) x a

Measured memory_bytes: 892
#include <bits/stdc++.h>
using namespace std;
#define all(n) begin(n), end(n)
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
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;
}
template <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts)
{
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }

template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v)
{
    for (auto &e : t)
        fill_v(e, v);
}
int main()
{
    int N;
    cin>>N;
    vint a(N);
    int X=0;
    for (size_t i = 0; i < N; i++)
    {
        cin>>a[i];
        X = X xor a[i];
    }
    for (size_t i = 0; i < N; i++)
    {
        cout<<(a[i] xor X) << endl;
    }
    
    return 0;
}

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

int main() {
  int N, cnt;
  cnt = 0;
  cin >> N;
  while (N > cnt){
  	string color;
    cin >> color;
    cnt++;
    if (color == "Y"){
      cout << "Four" << endl;
      break;
    }
    else if (N == cnt){
      cout << "Three" << endl;
    }
  }
}

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

ll modinv(ll a,ll m){
   ll b=m,u=1,v=0;
   while(b){
      ll t=a/b;
      a-=t*b; 
      swap(a,b);
      u-=t*v; 
      swap(u,v);
   }
   u%=m;
   if(u<0) u+=m;
   return u;
}

ll gcd(ll x,ll y){
   if(y==0) return x;
   else return gcd(y,x%y);
}
ll lcm(ll x,ll y){
   return x/gcd(x,y)*y;
}



int main(){
   int n;
   cin>>n;
   ll ans=0;
   int i=0;
   do{
      i++;
      if(i%3==0 && i%5==0)  continue;
      else if(i%3==0) continue;
      else if(i%5==0) continue;
      else{
      ans+=i;
      
      }
   }while(i<n);
   cout<<ans;

   return 0;
}



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

#define pb push_back
#define mp make_pair
typedef long long int ll;

void solve()
{
	ll n;
	cin >> n;

	cout << ( 1000 - n % 1000) % 1000;

}



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

#ifndef ONLINE_JUDGE
	freopen("1input.txt", "r", stdin);
	freopen("1output.txt", "w", stdout);
#endif

	int t = 1;
	// cin >> t;

	while (t--)
	{
		solve();
		cout << "\n";
	}

	return 0;
}

Measured memory_bytes: 3620
#include<iostream>
#include<vector>
#include<cmath>
#include<string>
#include<algorithm>
#include<map>
#include<utility>
#include<cstdio>
#include<bits/stdc++.h>

using namespace std;
using ll = long long;
const long long INF = 1LL<<60;

typedef pair<ll,ll> Pair;

int main(){

ll A,B,C,D;

cin >> A >> B >> C >> D;

while(1){

    C -= B;

    if(C <= 0){
        cout << "Yes" << endl;
        break;
    }  

    A -= D;

    if(A <= 0){
        cout << "No" << endl;

        break;
    }

}

return 0;

}

Measured memory_bytes: 3592