akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main() {
  int K, S, count;
  cin >> K >> S;
  for (int i = 0; i < K + 1; i++) {
    for (int j = 0; j < K + 1; j++) {
      if (0 <= S - i - j && S - i - j <= K) {
          count++;
      }
    }
  }
  cout << count;
}

Measured memory_bytes: 256
#include<stdio.h>
 
int main(void)
{
    char x[1001];
    int sum[10000];
    int number;
    int i, j;
    int last = 0;
     
    for(i = 0; last != 1; i++)
    {
        scanf("%s", x);
        for(j = 0; x[j] != '\0'; j++)
        {
            if(j == 0)
            {
                sum[i] = (int)(x[j] - '0');
            }
            else
            {
                sum[i] += (int)(x[j] - '0');
            }
 
        }
        if(x[0] == '0' && x[1] == '\0')
        {
            last = 1;
            number = i;
        }
    }
     
    for(i = 0; i < number; i++)
    {
        printf("%d\n", sum[i]);
    }
    return 0;
}

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

int main(){
    bool result = true; //強い回文であればtrue
    string s;
    cin >> s;
    int len = s.length(); //文字列の長さ

    //回文かどうか確かめる
    for(int i=0; i<(len-1)/2; i++){
        if(s[i] != s[len-1-i]){
            result = false;
            break;
        }
    }

    for(int i=(len-1)/2; i<len; i++){
        if(s[i] != s[len-1-i]){
            result = false;
            break;
        }
    }

    //条件２つ目
    for(int i=0; i<(len-1)/2; i++){
        if(s[i] != s[(len-1)/2-1-i]){
            result = false;
            break;
        }
    }

    //条件３つ目
    for(int i=(len+3)/2-1; i<(len-1)/2; i++){
        if(s[i] != s[len-1-i]){
            result = false;
            break;
        }
    }

    string ans;

    if(result){
        ans = "Yes";
    }else{
        ans = "No";
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(300000)

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LMI(): return list(map(int, sys.stdin.readline().split()))
MOD = 10 ** 9 + 7
INF = float('inf')

from math import log
def log2(x): return log(x, 2)


class Doubling(object):

    def __init__(self, N, K, next0):
        """
        ダブリングのメモ構築 O(NlogK)
        :param N: 解の存在空間の大きさ
        :param K: K個先までのステップを考慮する
        :param next0: i番目の要素の1個先の番号を要素として持つリスト
                      次の要素が存在しない場合には-1を要素として保持する
        """
        next = [[0] * N for _ in range(int(log2(K)) + 1)]
        next[0] = next0
        for k in range(int(log2(K))):
            for i in range(N):
                if next[k][i] == -1:
                    # 2^k個次に要素が無い時、当然2^(k+1)個次にも要素はない
                    next[k + 1][i] = -1
                else:
                    # i番目の要素の2^(k+1)個次の要素 := next[k][i](i番目の要素の2^k個次の要素)の2^k個先
                    next[k + 1][i] = next[k][next[k][i]]
        self.next = next

    def query(self, p, K):
        """
        p番目の要素のK個次の要素を求める O(logK)
        """
        for i in reversed(range(int(log2(K)) + 1)):
            if p == -1:
                return p
            if (K >> i) & 1:
                p = self.next[i][p]
        return p


S = input()

times = 2 * 10 ** 5
n0 = [i + 1 if c == 'R' else i - 1 for i, c in enumerate(S)]
d = Doubling(len(S), times, n0)

ans = [0] * len(S)
for i in range(len(S)):
    ans[d.query(i, times)] += 1
print(' '.join(str(x) for x in ans))


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

int main() {
 int n;
  cin>>n;
  vector<string> s(n);
  for(int i=0;i<n;i++){
    cin>>s[i];
  }
  int m;
  cin>>m;
  vector<string> t(m);
  for(int i=0;i<m;i++){
    cin>>t[i];
  }
  int ans=0;
  for(int i=0;i<n;i++){
    int score=0;
    for(int j=0;j<n;j++){
      if(s[j]==s[i])score++;
    }
    for(int j=0;j<m;j++){
      if(t[j]==s[i])score--;
    }
    ans=max(ans,score);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cassert>
#include <climits>
#include <bitset>
#include <stack>
#include <queue>
#include <iomanip>
#include <limits>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string.h>
 
using namespace std;
typedef long long ll;
 
 
typedef pair<ll,ll> P;
long long int INF = 1e18;
double Pi = 3.141592653589;
const int mod = 1000000007;
// memset(a,0,sizeof(a)); →全部０にする
 
vector<ll> G[100005];
vector<P> tree[100010];
priority_queue <ll> pql;
priority_queue <P> pqp;
//big priority queue
priority_queue <ll,vector<ll>,greater<ll>> pqls;
priority_queue <P,vector<P>,greater<P>> pqps;
//small priority queue
//top pop

int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
 
#define p(x) cout<<x<<endl;
#define el cout<<endl;
#define pe(x) cout<<x<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define pu(x) cout<<x;
#define re(i,a,b) for(i=a;i<=b;i++);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
 
ll rui(ll abc,ll bed){
	//aのb乗を計算する
	if(bed==0){return 1;}
	else{
		ll ced = rui(abc,bed/2);
		ced *= ced;
		ced %= mod;
		if(bed%2==1){ced*=abc; ced%=mod;}
		return ced;
	}
} 
ll i,j,k,ii,jj;
ll n,m,sum,num;
ll ans;
ll a,b,d,e,f,g,h,w;
 
ll x[800005],y[800005],z[900005];
char s[500005];

int main(){
    cin>>n>>k;
	if(n%k)p(1);
	if(n%k==0)p(0);

	return 0;


}


Measured memory_bytes: 6528
#include <stdio.h>
int main(){
    int n,a,m,temp,graph[101][101];
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            graph[i][j]=0;
        }
    }
    for(int i=0;i<n;i++){
        scanf("%d%d",&a,&m);
        for(int j=0;j<m;j++){
            scanf("%d",&temp);
            graph[a][temp]++;
        }
    }
    for(int i=1;i<=n;i++){
        printf("%d",graph[i][1]);
        for(int j=2;j<=n;j++){
            printf(" %d",graph[i][j]);
        }
        printf("\n");
    }
}

Measured memory_bytes: 2720
readlines.each do |l|
  num = (1..10).to_a
  a,b,c = l.split.map(&:to_i)
  num.reject!{|i| [a,b,c].include?(i)}
  puts num.select{|i| a+b+i<=20 }.size/7.0 >= 0.5 ? "YES" : "NO"
end

Measured memory_bytes: 6112
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define PF push_front
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double
#define pii pair<int,int>
#define pll pair<LL,LL>
#define vi vector<int>
#define vl vector<LL>
#define vii vector<vi>
#define vll vector<vl>

const double pi = 3.14159265358979323846264;
const int mod=1000000007;

int func(string s){
    int n=s.length();
    FOR(i,0,n/2){
        if(s[i]!=s[n-1-i])return 0;
    }
    return 1;
}

int main(){
	string s,ss="",sss="";
    cin>>s;
    int n=s.length();
    FOR(i,0,(n-1)/2){
        ss+=s[i];
    }
    FOR(i,(n+1)/2,n){
        sss+=s[i];
    }
    cerr<<ss<<" "<<sss<<endl;
    int f=func(s)&func(ss)&func(sss);
    if(f){
        cout<<"Yes";
    }else{
        cout<<"No";
    }

}


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

using namespace std;

using ll = long long int;

int main() {

	array<ll, 5> unitN;
	ll N;

	cin >> N;
	ll minUnitN = 1e15;
	for (int i = 0; i < 5; i++) {
		cin >> unitN[i];
		if (unitN[i] < minUnitN) 
			minUnitN = unitN[i];
	}

	ll current = 0;
	array<ll, 6> cityN = {N, 0, 0, 0, 0, 0};

	// while (cityN.at(5) != N) {
	// 	for (int i = 4; i >= 0; --i) {
	// 		// from
	// 		ll rideN = (cityN[i] > unitN[i]) ? unitN[i] : cityN[i];
	// 		cityN[i] -= rideN;
	// 		// to
	// 		cityN[i + 1] += rideN;
	// 	}
	// 	current++;
	// }

	// cout << current;

	printf("%lld", 5 + (ll)ceil((double)N / minUnitN) - 1);

	return 0;
}



Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reg(i,a,b) for(int i=(a);i<=(b);i++)
#define irep(i,n) for(int i=((int)(n))-1;i>=0;i--)
#define ireg(i,a,b) for(int i=(b);i>=(a);i--)
typedef long long int lli;
typedef pair<int,int> mp;
#define fir first
#define sec second
#define IINF INT_MAX
#define LINF LLONG_MAX



int n,m;
int dist[10005];

vector<mp> vs[10005];
vector<int> esse[10005];

void dijkstra(){
	priority_queue<mp,vector<mp>,greater<mp> > que;
	que.push(mp(0,0));
	while(!que.empty()){
		mp pa = que.top();
		que.pop();
		int no = pa.sec,
			co = pa.fir;
		//printf("poped .. %d %d %d\n",no,co,dist[no]);
		if(dist[no]<=co)continue;
		dist[no] = co;
		rep(i,vs[no].size()){
			mp tp = vs[no][i];
			int to = tp.fir,
				tc = tp.sec + co;
			//printf("push .. %d %d\n",tc,to);
			if(dist[to]<=tc)continue;
			que.push(mp(tc,to));
		}
	}
}

int tocs[20005][4];

int main(void){
	while(1){
		scanf("%d%d",&n,&m);
		if(n==0)break;
		rep(i,n){
			vs[i].clear();
			esse[i].clear();
			dist[i] = IINF;
		}
		
		rep(i,m){
			int a,b,c,d;
			scanf("%d%d%d%d",&a,&b,&c,&d); a--; b--;
			vs[a].push_back(mp(b,c));
			vs[b].push_back(mp(a,c));
			
			tocs[i][0] = a; tocs[i][1] = b; tocs[i][2] = c; tocs[i][3] = d;
		}
		
		dijkstra();
		/*
		rep(i,n){
			printf("%2d  dist.. %d\n",i,dist[i]);
		}*/
		int ans = 0;
		rep(i,m){
			int nc = tocs[i][3],
				nl = tocs[i][2],
				a = tocs[i][0],
				b = tocs[i][1];
			//printf("nec .. %d %d\n",i,nc);
			bool b1 = (dist[a] + nl == dist[b]);
			bool b2 = (dist[b] + nl == dist[a]);
			if(b1 || b2){
				if(b1)esse[b].push_back(nc);
				if(b2)esse[a].push_back(nc);
			}
			//else ans += nc;
		}
		
		rep(i,n){
			if(esse[i].size()==0)continue;
			sort(esse[i].begin(),esse[i].end());
			/*
			rep(j,esse[i].size()){
				//printf("desd------------------\n");
				if(j+1==esse[i].size()){
					printf("isessense .. %d\n",esse[i][j]);
					continue;
				}
			}*/
			//printf("%2d  esse .. %d\n",i,esse[i][0]);
			ans += esse[i][0];
		}
		
		printf("%d\n",ans);
	}
				
		
	return 0;
}

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())

// {{{
template<typename T>
void printmatrix(vector<vector<T> > ar){
    for (int i = 0; i < (int)ar.size(); i++) {
        for (int j = 0; j < (int)ar[0].size(); j++) {
            cout << ar[i][j];
        }
        cout << endl;
    }
}

template<typename T>
void printvector(vector<T> vec){
    for (int i = 0; i < (int)vec.size(); i++) {
        cout << vec[i] << endl;
    }
}

template<typename T>
void unique(vector<T>& vec){
    sort(vec.begin(), vec.end());
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
}

template<typename T>
vector<T> cumsum(vector<T> vec){
    vector<T> newvec((T)vec.size());
    int tmp = 0;
    for (int i = 0; i < (int)vec.size(); i++) {
        tmp += vec[i];
        newvec[i] = tmp;
    }

    return newvec;
}

template<typename T>
T digitsum(T x){
    T y=0;
    while(x){
        y += x % 10;
        x /= 10;
    }

    return y;
}

// template<typename T>
// T gcd(T x, T y){
//     if (x == 0 || y == 0) {
//         return 0;
//     }
//
//     while (x != y){
//         if (x > y) {
//             x -= y;
//         }else{
//             y -= x;
//         }
//     }
//     return x;
// }

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

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

// }}}
/* vim:set foldmethod=marker: */

void solve(){
    int N, X;
    cin >> N >> X;
    
    vector<ll> x(N+1);
    for (int i = 0; i < N; i++) {
        cin >> x[i];
    }
    x[N] = X;
    sort(all(x));

    if (N == 1) {
        cout << abs(x[0] - x[1]) << endl;
        return;
    }

    vector<ll> v(N);
    for (int i = 0; i < N; i++) {
        v[i] = x[i+1] - x[i];
    }


    ll ans=v[0];
    for (int i = 0; i < N; i++) {
        ans = gcd(ans, v[i]);
    }

    cout << ans << endl;

    return;
}

int main(int argc, char const* argv[])
{
    solve();
    return 0;
}

// sortの仕方
// int a[N];
// array<int,N> ar;
// vector<int> v;
//
// sort(a, a+N); // 配列
// sort(ar.begin(), ar.end()); // array
// sort(v.begin(), v.end()); // vector 昇順
// sort(v.begin(), v.end(), greater<int>()); // 降順

// Template
// template <class T>
// T foomax(T x, T y){
//   if (x > y){
//     return x;
//   }else{
//     return y;
//   }
// }

// string を int に変換 stoi("1010")
// int を string に変換 to_string(1010)


// map の key, value を全て抜き出す。
// for (auto itr = mp.begin(); itr != mp.end(); itr++) {
//     cout << "key" << itr->first << " value" << itr->second << endl;
// }

// 文字列の検索
// string s="abc";
// if (s.find('d') == string::npos){
//     cout << "find" << endl;
// }else{
//     cout << "not find" << endl;
// }


Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>

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

using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repr(i,n) for(ll i=n;i>=0;i--)
#define P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define EPS (1e-10)
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}


const long long MOD = 1000000007;
const long long INF = 1LL << 60;


const int MAX_N = 100010;


signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int a, b; cin >> a >> b;
	cout << lcm(a, b) << endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
import java.util.Arrays;
 
public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int num1 = scan.nextInt();
        int num2 = scan.nextInt();
        int num3 = scan.nextInt();
        int tmp = num1;
        num1 = num2;
        num2 = tmp;
      
        tmp = num1;
        num1 = num3;
        num3 = tmp;
        System.out.println(num1 + " " + num2 + " " + num3);
        scan.close();
    }
}

Measured memory_bytes: 23252
#include<stdio.h>
int main(void)
{
	int n,i,w,a,s,d,x,j,z;
		scanf("%d",&n);
		for(i=0;i<n;i++){
			scanf("%d %d %d",&a,&s,&d);
			if(a>s&&d<a){
					if(a*a==d*d+s*s){
						printf("YES\n");
					}
					else{
						printf("NO\n");
					}	
			}	
			else if(a<d&&d>s){
					if(d*d==a*a+s*s){
						printf("YES\n");
					}
					else{
						printf("NO\n");
					}				
			}
			else if(a<s&&s>d){
					if(s*s==a*a+d*d){
						printf("YES\n");
					}
					else{
						printf("NO\n");
					}				
			}
			else if(a==s&&s==d&&d==a||a==s||s==d||d==a){
				printf("NO\n");
		}	
		
		}
	return 0;
}

Measured memory_bytes: 1008
#include <bits/stdc++.h>
 
using namespace std;
using LL = long long int; 

template <class TH> void _dbg(const char *sdbg, TH h){cerr<<sdbg<<"="<<h<<"\n";}
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')
    cerr<<*sdbg++;
  cerr<<"="<<h<<","; 
  _dbg(sdbg+1, a...);
}

template<class T> ostream & operator<<(ostream & os, vector<T> V){
  os<<"[";
  for(auto vv: V) os << vv <<",";
  return os << "]";
}
template<class L, class R> ostream & operator <<(ostream & os, pair<L,R> P){
  return os <<"("<<P.st <<","<<P.nd <<")";
}

#ifdef DEBUG
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) (__VA_ARGS__)
#define cerr if(0)cout
#endif

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  swap(a, b);
  swap(a, c);
  cout << a << " " << b << " " << c << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <map>
#include <list>
#include <vector>
#include <string>
#include <stack>
#include <limits>
#include <cassert>
#include <fstream>
#include <cstring>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <cstdio>
#include <ciso646>
#include <set>
#include <array>

using namespace std;

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)

#define inf 0x3f3f3f3f
#define INF INT_MAX/3
#define PB push_back
#define MP make_pair
#define ALL(a) (a).begin(),(a).end()
#define SET(a,c) memset(a,c,sizeof a)
#define CLR(a) memset(a,0,sizeof a)
#define pii pair<int,int>
#define pcc pair<char,char>
#define pic pair<int,char>
#define pci pair<char,int>
#define VS vector<string>
#define VI vector<int>
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define MIN(a,b) (a>b?b:a)
#define MAX(a,b) (a>b?a:b)
#define pi 2*acos(0.0)
#define INFILE() freopen("in0.txt","r",stdin)
#define OUTFILE()freopen("out0.txt","w",stdout)
#define ll long long
#define ull unsigned long long
#define eps 1e-14
#define FST first
#define SEC second
#define SETUP cin.tie(0), ios::sync_with_stdio(false), cout << setprecision(15)

namespace {
	struct input_returnner {
		int N; input_returnner(int N_ = 0) :N(N_) {}
		template<typename T> operator vector<T>() const { vector<T> res(N); for (auto &a : res) cin >> a; return std::move(res); }
		template<typename T> operator T() const { T res; cin >> res; return res; }
		template<typename T> T operator - (T right) { return T(input_returnner()) - right; }
		template<typename T> T operator + (T right) { return T(input_returnner()) + right; }
		template<typename T> T operator * (T right) { return T(input_returnner()) * right; }
		template<typename T> T operator / (T right) { return T(input_returnner()) / right; }
		template<typename T> T operator << (T right) { return T(input_returnner()) << right; }
		template<typename T> T operator >> (T right) { return T(input_returnner()) >> right; }
	};
	template<typename T> input_returnner in() { return in<T>(); }
	input_returnner in() { return input_returnner(); }
	input_returnner in(int N) { return std::move(input_returnner(N)); }
}

void solve();
/// ---template---
signed main(void) {
	SETUP;
	solve();
	return 0;
}

struct Point {
	int x;
	int y;
	Point(int x_, int y_):x(x_),y(y_){}
	Point() {}
};

bool operator < (list<Point> left, list<Point> right) {
	return left.size() < right.size();
}

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

void solve() {
	int N = in();
	vector<int> a = in(N);
	ll cnt = 0;
	REP(i, N) {
		cnt += (a[a[i]-1] == i+1);
	}
	cout << cnt/2 << endl;
}

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

int main(){
  int n;
  cin >> n;
  map<int,int> m;
  bool ok=1;
  for(int i=0;i<n;i++){
    int x;
    cin >> x;
    if(m[x]!=0){
      ok=0;
    }
    m[x]++;
  }
  if(ok) cout << "YES" << endl;
  else cout << "NO" << endl;
}


Measured memory_bytes: 12832
#include<stdio.h>
#include<math.h>
int main()
{
	double x,h,s;
	while(1){
	scanf("%lf %lf",&x,&h);
	if(x==0&&h==0)
	break;
	s=2*x*sqrt(x*x+4*h*h)/2+x*x;
	printf("%lf\n",s);
	}
	return 0;
}


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

vector<int> dy = {-1, 1, 0,  0};
vector<int> dx = { 0, 0, 1, -1};

int h, w;
queue<pair<int, int>> todo; // y, x

// 次に動こうとしている点(nx, ny)に通路があるかの判定。訪れたかどうかは不問
bool movable(int ny, int nx, vector<string> & maze) {
    if (ny < 0 || ny >= h || nx < 0 || nx >= w)
        return false;

    if (maze.at(ny).at(nx) == '#')
        return false;

    return true;
}

int bfs(int sy, int sx, vector<string> & maze)
{
    /*
    -1: 見つけてない
    >= 0: 発見済み。(スタートからの距離)
    */
    vector<vector<int>> visited(h, vector<int>(w, -1));
    visited.at(sy).at(sx) = 0;
    todo.push(pair<int, int>(sy, sx));

    while(!todo.empty()) {
        int y = todo.front().first;
        int x = todo.front().second;
        int yu = y + dy.at(0);
        int xu = x + dx.at(0);
        int yd = y + dy.at(1);
        int xd = x + dx.at(1);
        int yr = y + dy.at(2);
        int xr = x + dx.at(2);
        int yl = y + dy.at(3);
        int xl = x + dx.at(3);

        todo.pop();
        if (movable(yu, xu, maze) && visited.at(yu).at(xu) == -1) {
            visited.at(yu).at(xu) = visited.at(y).at(x) + 1;
            todo.push(pair<int, int>(yu, xu));
        }
        if (movable(yd, xd, maze) && visited.at(yd).at(xd) == -1) {
            visited.at(yd).at(xd) = visited.at(y).at(x) + 1;
            todo.push(pair<int, int>(yd, xd));
        }
        if (movable(yr, xr, maze) && visited.at(yr).at(xr) == -1) {
            visited.at(yr).at(xr) = visited.at(y).at(x) + 1;
            todo.push(pair<int, int>(yr, xr));
        }
        if (movable(yl, xl, maze) && visited.at(yl).at(xl) == -1) {
            visited.at(yl).at(xl) = visited.at(y).at(x) + 1;
            todo.push(pair<int, int>(yl, xl));
        }
    }

    int maxDist = -1;
    for (vector<int> row : visited) {
        maxDist = max(*max_element(row.begin(), row.end()), maxDist);
    }
    return maxDist;
}

int main() {
    cin >> h >> w;
    vector<string> maze(h);
    rep(i, h) cin >> maze.at(i);

    int ans = -1;
    rep(i, h)
    {
        rep (k, w) {
            if (maze.at(i).at(k) == '#')
                continue;

            ans = max(bfs(i, k, maze), ans);
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef pair<int, int> Pint;
typedef pair<int64_t, int64_t> Pll;


int main() {
    string S;
    cin >> S;
    for (int i = 0; i < S.size() - 1; i++){
        if (S.at(i + 1) != '9'){
            cout << S.at(0) - '0' + 9 * (S.size() - 1) - 1 << endl;
            return 0;
        }
    }
    cout << S.at(0) - '0' + 9 * (S.size() - 1) << endl;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF INT_MAX
#define ll  long long
#define ull unsigned long long
#define rep(i,n) for(ll i=0; i<n; ++i)
#define FOR(i, s, e) for(ll i=s; i<e; ++i)
#define MOD 1000000007
using namespace std;
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;}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll N; cin >> N;
  vector<ll> H(N);
  rep(i,N) cin >> H[i];
  ll ans = 0, tmp = 0;
  rep(i, N-1) {
    if(H[i] >= H[i+1]) {
      ++tmp;
    } else {
      if(tmp > ans) ans = tmp;
      tmp = 0;
    }
  }
  if(tmp > ans) ans = tmp;
  cout << ans << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s1;
    cin>>s1;
    string b=s1;
    reverse(s1.begin(),s1.end());
    for(int i=0;i<s1.size();++i)
    {
        if(s1[i]=='b') s1[i]='d';
        else if(s1[i]=='d') s1[i]='b';
        else if(s1[i]=='p') s1[i]='q';
        else if(s1[i]=='q') s1[i]='p';
    }
    if(s1==b) cout<<"Yes";
    else cout<<"No";
     cout<<endl;
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <string>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <stack>
#include <set>
#include <queue>
#include <algorithm>
#include <deque>
using namespace std;

#define INF 1e18
#define int long long

signed main() {
    int n; cin >> n;
    vector<int> p(n); for(int i = 0; i < n; i++) cin >> p[i];

    int ans = 0;
    for(int i = 1; i < n - 1; i++) {
        if(p[i - 1] < p[i] && p[i] < p[i + 1]) ans++;
        else if(p[i - 1] > p[i] && p[i] > p[i + 1]) ans++;
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
	"strings"
)

func main() {
	var s string
	fmt.Scan(&s)

	if len(s) == 0 {
		fmt.Println("NO")
		return
	}
	for len(s) > 0 {
		switch {
		case strings.HasSuffix(s, "dreamer"):
			s = s[:len(s)-7]
		case strings.HasSuffix(s, "dream"):
			s = s[:len(s)-5]
		case strings.HasSuffix(s, "eraser"):
			s = s[:len(s)-6]
		case strings.HasSuffix(s, "erase"):
			s = s[:len(s)-5]
		default:
			fmt.Println("NO")
			return
		}
	}

	fmt.Println("YES")
}

Measured memory_bytes: 1280
#include<iostream>
#include<fstream>
#include<sstream>
#include<cstdio>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<algorithm>
#include<cmath>
#include<string>
#include<cstring>
#include<cstdlib>
#include<climits>
#include<utility>
#include<cctype>
using namespace std;

#define ull unsigned long long
#define stt(it,order) sort(it.begin(),it.end(),order)
#define st(it) sort(it.begin(),it.end())
#define ll long long
#define rep(i,j) for(int i=0;i<j;++i)
#define loop(i,a,j) for(int i=a;i<j;++i)
#define mpi(it,table,T,E) for(map<T,E>::iterator it = table.begin();it!=table.end();++it)
#define PI 3.141592654
/*
ifstream fin("input.txt");
ofstream fout("output.txt");
#define cin fin
#define cout fout
*/


int main(){
   bool is_in[30];
   memset(is_in,0,sizeof(is_in));
   int n;
   while(scanf("%d",&n) != EOF)is_in[n-1] = true;
   rep(i,30){
      if(!is_in[i]){
         printf("%d\n",i+1);
      }
   }
   return 0;
}

Measured memory_bytes: 1188
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <numeric>
#include <iostream>

using namespace std;

#define FOR(i, a, b)   for(int i = (a); i < (b); ++i)
#define RFOR(i, a, b)  for(int i = (a); i > (b); --i)
#define rep(i, n)      for(int i = 0; i < (n); ++i)
#define all(c)         begin(c), end(c)
#define rall(c)        rbegin(c), rend(c)
#define SZ(a)          ((ll) a.size())

typedef long long ll;
typedef unsigned long long ull;

int main(){
	int H,W;
  scanf("%d %d",&H,&W);
	int c[10][10];
	int a[10] = {0};
	int tmp;
	rep(i,10){
		rep(j,10){
			scanf("%d",&c[i][j]);
		}
	}
	rep(i,H){
		rep(j,W){
			scanf("%d",&tmp);
			if(tmp>=0) a[tmp]++;
		}
	}
	rep(i,10){
		rep(j,10){
			rep(k,10){
				c[j][k] = min(c[j][k],c[j][i]+c[i][k]);
			}
		}
	}
	int sum=0;

	rep(i,10) sum = sum+a[i]*c[i][1];
	printf("%d",sum);

  return 0;
}


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

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  swap(a,b);
  swap(a,c);
  cout << a << " " << b << " " << c << endl;
}


Measured memory_bytes: 256
import java.util.*;
import java.math.*;
import java.lang.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		String s = sc.next();
		String[] strArray = s.split("");

		int winCount = 0;
		int k = strArray.length;

		for (int i = 0; i < k; i++) {
			String hoshi = strArray[i];

			if (hoshi.equals("o")) {
				winCount++;
			}
		}

		if ((15 - k) + winCount >= 8) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}

	}

}


Measured memory_bytes: 21204
#include<stdio.h>
#include<string.h>
int ch[100];
int main()
{
	int n,m;
	scanf("%d%d",&n,&m);
	int a,b;
	while(m--)
	{
		scanf("%d%d",&a,&b);
		ch[a]++;
		ch[b]++;
	}
	for(int i=1;i<=n;i++)
	printf("%d\n",ch[i]);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

string s;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> s;
  if (s.size() == 2) {
    if (s[0] == s[1]) cout << "1 2" << endl;
    else cout << "-1 -1" << endl;
    return 0;
  }
  for (int i = 0; i + 3 <= s.size(); i++) {
    string t = s.substr(i, 3);
    if (t[0] == t[1] || t[1] == t[2] || t[2] == t[0]) {
      cout << i + 1 << " " << i + 3 << endl;
      return 0;
    }
  }  
  cout << "-1 -1" << endl;

  return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define SZ(x) ((int) (x).size())
using namespace std;

typedef long long i64;

int main() {
    #ifdef LOCAL_RUN
    freopen("task.in", "r", stdin);
    freopen("task.out", "w", stdout);
    //freopen("task.err", "w", stderr);
    #endif // ONLINE_JUDGE
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n, q;
    cin >> n >> q;

    vector<int64_t> qs;
    while (q-- > 0) {
        int64_t x;
        cin >> x;
        while (!qs.empty() && x <= qs.back()) {
            qs.pop_back();
        }
        qs.push_back(x);
    }
    int m = n + SZ(qs);
    vector<vector<pair<int, int64_t>>> graph(m);
    for (int i = 0; i < SZ(qs); ++i) {
        int64_t x = qs[i];
        int node = n + i;
        while (x != 0) {
            int pos = upper_bound(qs.begin(), qs.begin() + i, x) - qs.begin() - 1;
            if (pos == -1) {
                break;
            }
            int to = n + pos;
            graph[to].push_back(make_pair(node, x / qs[pos]));
            x %= qs[pos];
        }
        if (x >= n) {
            graph[n - 1].push_back(make_pair(node, x / n));
            x %= n;
        }
        if (x > 0) {
            graph[x - 1].push_back(make_pair(node, 1));
            x %= n;
        }
    }
    vector<int64_t> dp(m);
    dp[m - 1] = 1;
    for (int i = m - 2; i >= 0; --i) {
        dp[i] = 0;
        for (const auto& p: graph[i]) {
            dp[i] += dp[p.first] * p.second;
        }
    }
    for (int i = n - 2; i >= 0; --i) {
        dp[i] += dp[i + 1];
    }
    for (int i = 0; i < n; ++i) {
        cout << dp[i] << '\n';
    }
}

Measured memory_bytes: 23024
def resolve():
	do = True
	while do:
		s = int(input())
		if not s:
			break
		dp = [-1]*(s+1)
		for i in range(s+1):
			if i == 0 or i == 1:
				dp[i] = 1
				continue
			t = []
			for j in range(1, 4):
				if i - j >= 0:
					t.append(dp[i-j])
			dp[i] = sum(t)
		r = 1 if dp[-1] % (10*365) else 0
		print(dp[-1] // (10*365) + r)
resolve()


Measured memory_bytes: 5596
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
using vs = vector<string>;
using vll = vector<long long>;
using vpii = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvs = vector<vector<string>>;
using vvb = vector<vector<bool>>;
using vvll = vector<vector<long long>>;
using pii = pair<int, int>;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define reps(i,n) for(int i = 1; i <= (int)(n); 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 FOR(i,a,b) for(int i = (int)(a); i <= (int)(b); i++)
#define RFOR(i,a,b) for(int i = (int)(a); i >= (int)(b); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define call(x) (x).cbegin(), (x).cend()
#define MAX(x) *max_element(all(x))
#define MIN(x) *min_element(all(x))
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 (b<a) {a=b; return 1;} return 0;}
const int INF = INT_MAX;
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};

int main(){
    int N, K;
    cin >> N >> K;
    vector<long long> V(N);
    for (int i = 0; i < N; i++) cin >> V[i];
    
    long long res = 0;
    for (int p = 0; p <= min(N, K); p++) {
        for (int q = 0; p + q <= min(N, K); q++) {
            long long cur = 0;
            vector<long long> v;
            for (int i = 0; i < p; i++) {
                v.push_back(V[i]);
                cur += V[i];
            }
            for (int i = 0; i < q; i++) {
                v.push_back(V[N-1-i]);
                cur += V[N-1-i];
            }
            sort(v.begin(), v.end());
            for (int i = 0; i < min(p + q, K - p - q); i++) {
                if (v[i] < 0) {
                    cur -= v[i];
                }
            }
            res = max(res, cur);
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 256
import java.util.*;
import java.lang.*;
import java.io.*;


public class Main{
  public static void main(String[] args) throws IOException {
//     System.out.println("");
//     List<Integer> list = new ArrayList<Integer>();

    // Scanner scanner = new Scanner(System.in);
    BufferedReader bs = new BufferedReader(new InputStreamReader(System.in));
    // Integer N = Integer.valueOf(scanner.next());
    Integer N = Integer.valueOf(bs.readLine());
    List<String> S = new ArrayList<String>();
    List<Integer> P = new ArrayList<Integer>();
    List<Restaurant> restaurants = new ArrayList<Restaurant>();

    for(int i = 0; i < N; i++){
      String sp = bs.readLine();
      String[] splitedStr = sp.split(" ", 0);

      restaurants.add(new Restaurant(i + 1, Integer.valueOf(splitedStr[1]), splitedStr[0]));
      // S.add(splitedStr[0]); 
      // P.add(Integer.valueOf(splitedStr[1])); 
    }

    Collections.sort(restaurants, new MyComp());

    for(Restaurant rest : restaurants){
      System.out.println(rest.index);
    }
  }
}

class Restaurant {

  public Integer index;
  public Integer rank;
  public String cityName;

  Restaurant(int index, int rank, String cityName){

    this.rank = Integer.valueOf(rank);
    this.index = Integer.valueOf(index);
    this.cityName = cityName;
  }
  

}

class MyComp implements Comparator<Restaurant>{
  public int compare(Restaurant curr, Restaurant another){
    int cityResult = curr.cityName.compareTo(another.cityName);
    if (cityResult != 0) return cityResult;
    return Integer.compare(another.rank, curr.rank);
  }
}


Measured memory_bytes: 22868
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;

int main(){
    int a, b, c;
    cin >> a >> b >> c;
    double s = a * b * sin(c * M_PI / 180.0) / 2.0;
    double l = (double)a + (double)b + sqrt(a*a + b*b - 2.0*a*b*cos(c * M_PI / 180.0));
    double h = (double)b * sin(c * M_PI / 180.0);
    
    printf("%.5f %.5f %.5f\n", s, l, h);
    return 0;
}
    


Measured memory_bytes: 3432
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

const int INF = 1001001001;

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

  int v, e, r;
  cin >> v >> e >> r;

  vector<int> s(e, INF), t(e, INF), w(e, INF);
  for (int i = 0; i < e; i++) {
    cin >> s[i] >> t[i] >> w[i];
  }

  vector<vector<P>> adj(e);
  for (int i = 0; i < e; i++) {
    adj[s[i]].push_back(P(t[i], w[i]));
  }

  vector<int> d(v, INF);
  d[r] = 0;

  int cnt = 0;
  while (cnt < v) {
    bool updated = false;
    for (int i = 0; i < e; i++) {
      int from = i;
      for (int j = 0; j < adj[i].size(); j++) {
        int to = adj[i][j].first;
        int cost = adj[i][j].second;

        if (d[from] == INF) continue;

        if (d[from] + cost < d[to]) {
          d[to] = d[from] + cost;
          updated = true;
        }
      }
    }

    if (!updated) {
      break;
    }

    cnt++;
  }

  if (cnt == v) {
    cout << "NEGATIVE CYCLE" << endl;
  } else {
    for (int i = 0; i < v; i++) {
      if (d[i] < INF) {
        cout << d[i] << endl;
      } else {
        cout << "INF" << endl;
      }
    }
  }

  return 0;
}


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

#define ll long long 
#define sz(x) (int)x.size()

using namespace std;

int f(int x){
	int c=0;
	while(x)c+=x%10,x/=10;
	return c;
}

int main(){
	int n,a,b,ans=0;
	cin>>n>>a>>b;
	for(int i=1;i<=n;i++){
		if(f(i)>=a && f(i)<=b)ans+=i;
	}
	cout<<ans;
}





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


using namespace std;
#define ll  long long
#define ld  long double
#define endl '\n'
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const ll mod = 1e9 + 7;
const double PI = 3.141592653589793238463;
const int MAXN = 2e3 + 5;
bool isPrime[MAXN];

void sevie() {
    memset(isPrime, 1, sizeof(isPrime));
    isPrime[0] = isPrime[1] = 0;
    for (ll i = 2; i * i <= MAXN; i++) {
        if (isPrime[i]) {
            for (ll j = i * 2; j <= MAXN; j += i) {
                isPrime[j] = 0;

            }
        }
    }
}

ll fastPow(ll x, ll b) {
    if (b == 0)
        return 1;
    else if (!(b & 1)) {
        return fastPow(x * x, b / 2);
    } else
        return x * fastPow(x * x, (b - 1) / 2);
}

//__builtin_popcount ();
bool isPrim(int n) {
    if (n == 1 || n == 0)
        return false;
    for (int i = 2; i * i <= n; i++) {
        if (n % i == 0)
            return false;
    }
    return true;
}


int main() {
    FAST
    ll x, y, a, b, c;
    cin >> x >> y >> a >> b >> c;
    ll arra[a], arrb[b], arrc[c];
    for (int i = 0; i < a; i++)
        cin >> arra[i];
    for (int i = 0; i < b; i++)
        cin >> arrb[i];
    for (int i = 0; i < c; i++)
        cin >> arrc[i];
    sort(arra, arra + a, greater<ll>());
    sort(arrb, arrb + b, greater<ll>());
    sort(arrc, arrc + c, greater<ll>());
    ll sum = 0;
    ll cnt = 0;
    ll cc = 0;
    vector<ll> all;
    for(int i=0;i<x;i++)
        all.push_back(arra[i]);
    for(int i=0;i<y;i++)
        all.push_back(arrb[i]);
    sort(all.begin(),all.end());
    for(int i=0;i<all.size() && i<c;i++)
    {
        if(arrc[i]>all[i])
        {
            all[i]=arrc[i];
        }
        else
            break;
    }
  cout<<accumulate(all.begin(),all.end(),sum)<<endl;
    return 0;
}

Measured memory_bytes: 4852
/*
author: thanglong
*/
#include <bits/stdc++.h>
 
using namespace std;
 
#define fi first
#define se second
#define pb push_back
#define mp make_pair
 
typedef pair<int, int> ii;
 
const int N = 3e3 + 5;
 
int n, mod, f[N][N], c[N][N], pw[N * N], pw2[N], dp[N], ans;
 
void calc() {
    //f[i][j]:the number of ways to "put" i guys in j bowl
    for(int i = 0; i <= N - 5; i++)
        f[i][0] = 1;
    for(int i = 1; i <= N - 5; i++) {
        for(int j = 1; j <= i; j++)
            f[i][j] = ((1ll * (j + 1) * f[i - 1][j]) % mod + f[i - 1][j - 1]) % mod;
    }
    c[0][0] = 1;
    for(int i = 1; i <= N - 5; i++) {
        c[i][0] = 1;
        for(int j = 1; j <= i; j++)
            c[i][j] = (c[i - 1][j - 1] + c[i - 1][j]) % mod;
    }
    pw[0] = 1;
    for(int i = 1; i <= (N - 5) * (N - 5); i++)
        pw[i] = (1ll * pw[i - 1] * 2) % mod;
    pw2[0] = 2;
    for(int i = 1; i <= N - 5; i++)
        pw2[i] = (1ll * pw2[i - 1] * pw2[i - 1]) % mod;
    ans = pw2[n] - 1;
    for(int i = 1; i <= n; i++){
        for(int j = 0; j <= i; j++) {
            //cout << f[i][j] << " " << i << " " << j << "\n";
            int val = (1ll * f[i][j] * pw[(n - i) * j]) % mod;
            if(j == 0)
                dp[i] += (1ll * val * (pw2[n - i] - 1)) % mod;
            else
                dp[i] += (1ll * val * pw2[n - i]) % mod;
            dp[i] %= mod;
        }
        if(i % 2 == 0)
            ans = (ans + (1ll * dp[i] * c[n][i]) % mod) % mod;
        else
            ans = (ans - (1ll * dp[i] * c[n][i]) % mod) % mod;
        ans = (ans + mod) % mod;
    }
    cout << ans;
    exit(0);
}
 
int main() {
    cin.tie(0), ios::sync_with_stdio(0);
    cin >> n >> mod;
    calc();
}

Measured memory_bytes: 106112
#include<stdio.h>

int main()
{
  char s[1010];
  scanf("%s", s);
  int i=0;
  while(s[i]!='\0')
    i++;
  if(s[i-1]=='s')
    printf("%ses",s);
  else
    printf("%ss",s);
  return 0;
}

Measured memory_bytes: 1736
import std.stdio;
import std.algorithm;
import std.string;
import std.conv;
import std.math;

void main(){

    while(true){
	auto a = readln();
	if(stdin.eof()) break;
	auto s1 = split(a);
	real n = to!real(s1[0]) / to!real(s1[1]);
	long sum = 0;
	int s = to!int(s1[2]);
	n = n - to!int(n);
	for(int i=0;i<s;i++){
	    n *= 10;
	    sum += to!int(n)%10;
	    n = n - to!int(n);
	}
	writeln(sum);
    }
}

Measured memory_bytes: 2432
#include <iostream>

int main()
{
    int N;
    std::cin >> N;
    int* H = new int[N];

    for (int i = 0; i < N; ++i)
    {
        std::cin >> H[i];
    }
    int max = H[0];
    int cnt = 1;
    for (int i = 1; i < N; ++i)
    {
        if (max <= H[i])
        {
            max = H[i];
            cnt++;
        }
    }

    std::cout << cnt << std::endl;

    delete[] H;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
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; }

const ll INF=(1LL<<60);
const int mod=1000000007;

class UnionFind{
public:
    //親の番号を格納する。親だった場合はー（その集合のサイズ）
    vector<int> parents;

    //作る時はparentsを-1で初期化する
    //こうすることで全部ばらばらになる
    UnionFind(int n){
        parents = vector<int>(n, -1);
    }

    //Aがどのグループにいるか調べる
    int root(int A){
        if(parents[A]<0) return A;
        return parents[A] = root(parents[A]);
    }

    //自分のいるグループの大きさを調べる
    int size(int A){
        return -parents[root(A)];
    }

    //AとBをくっつける
    bool connect(int A, int B){
        //AとBを直接ではなく親同士をくっつける
        A=root(A);
        B=root(B);
        if(A==B){
            return false;
        }

        //大きい方（A)に小さい方（B)をくっつけたい
        if(size(A)<size(B)) swap(A, B);

        parents[A] += parents[B];
        parents[B] = A;

        return true;
    }
};

int main(){
    int N, M; cin >> N >> M;
    vector<int> A(M),B(M);
    for(int i=0; i<M; i++){
        cin >> A[i] >> B[i];
    }

    UnionFind uni(N);
    ll ans[M];
    ans[M-1] = (ll)N*(N-1)/2;

    for(int i=M-1; i>0; i--){
        ans[i-1] = ans[i];
        if(uni.root(A[i]-1) != uni.root(B[i]-1)){
            ans[i-1] -= (ll)uni.size(A[i]-1) * uni.size(B[i]-1);
            uni.connect(A[i]-1, B[i]-1);
        }
    }

    for(int i=0; i<M; i++){
        cout << ans[i] << endl;
    }

    
}

Measured memory_bytes: 3328
/*
***************************************************************************
 name  : ITP1_04_C.cpp
 title : Simple Calculator
 make  : 2018/08/15 tanabe
***************************************************************************
*/

// Library
#include <iostream> // standard input output object

main(void){
  int a,b;  // integers
  char op;  // operator
  bool con; // condition

  // initialized con = 0
  // continue con == 0
  for(con = 0;con == 0;){
    std::cin >> a >> op >> b; // input "a op b"

    switch(op){
      case '+': std::cout << a + b << std::endl; break; // output "a+b"
      case '-': std::cout << a - b << std::endl; break; // output "a-b"
      case '*': std::cout << a * b << std::endl; break; // output "a*b"
      case '/': std::cout << a / b << std::endl; break; // output "a/b"
      default : con++; break; // increment con
  }
}

}



Measured memory_bytes: 3112
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
int main(){
  string s;
  cin >> s;
  cout << s.substr(0,5) << " " << s.substr(6,7) << " " << s.substr(14,5) << endl;
}

Measured memory_bytes: 3576
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll ans;
int a[10005],b[10005];
int c[10005];
int d[10005];
bool v[10005];
vector<int> G[10005];
int N;
void bfs(int x){
	queue<int> que;
	que.push(x);
	while(que.size()){
		int t=que.front(); que.pop();
		for(int i=0;i<G[t].size();i++){
			int e=G[t][i];
			//cout<<e<<"  ";
			if(v[e]==false){
				que.push(e);
				v[e]=true;
				d[e]=c[N];
				N--;
				//cout<<e<<endl;
			}
		}
	}
}
int main(void){
	int n; cin>>n;
	for(int i=0;i<n-1;i++){
		cin>>a[i]>>b[i];
		G[a[i]-1].push_back(b[i]-1); G[b[i]-1].push_back(a[i]-1);
	}
	for(int i=0;i<n;i++){
		cin>>c[i];
		ans+=c[i];
	}
	sort(c,c+n);
	ans-=c[n-1];
	N=n-1;
	d[0]=c[N];
	N--;
	v[0]=true;
	bfs(0);
	cout<<ans<<endl;
	for(int i=0;i<n;i++){
		cout<<d[i];
		if(i!=n-1){
			cout<<" ";
		}
	}
	cout<<endl;
	
}


Measured memory_bytes: 1152
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		switch(s) {
		case "SUN":System.out.println(7);
		break;
		case "MON":System.out.println(6);
		break;
		case "TUE":System.out.println(5);
		break;
		case "WED":System.out.println(4);
		break;
		case "THU":System.out.println(3);
		break;
		case "FRI":System.out.println(2);
		break;
		case "SAT":System.out.println(1);
		break;
		}
	}
}

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

#define llong long long
#define inf 999999999
#define mp make_pair
#define pb push_back
typedef pair<int, int> P;
typedef struct data{
	int now;
	int cost;
}data;
int nh[4] = {1, 0, -1, 0};
int nw[4] = {0, 1, 0, -1};



int main(){
	int a = 0;
	char in;
	for(int i = 0; i < 3; i++){
		cin >> in;
		if((int)in - 48 == 1)a++;
	}
	cout << a << endl;
	return 0;
}

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

#define Fast ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)
#define FO freopen("in.txt", "r", stdin)
#define FC freopen("out.txt", "w", stdout)
#define aise cout<<"aise"<<endl
#define pb push_back
#define mp make_pair
#define ll long long
#define mset(v, a) memset(v, a, sizeof(v))
#define pll pair< ll, ll >
#define pdd pair< double, double >
#define ff first
#define ss second
#define pi acos(-1.0)
#define mxN 2097162
#define inf 1e9
#define MOD 1000000007

bool cmp(pair< string, ll > a, pair< string, ll > b)
{

    if(a.ff != b.ff) return a.ff < b.ff;
    else return a.ss > b.ss;
}

int main()
{

    vector< pair< string, ll > > v;
    map< pair< string, ll >, ll > m;
    ll n;
    cin >> n;
    for(ll i = 0; i < n; i++)
    {

        pair< string, ll > pp;
        cin >> pp.ff >> pp.ss;
        m[pp] = i+1;
        v.pb(pp);
    }
    sort(v.begin(), v.end(), cmp);
    for(ll i = 0; i < n; i++)
    {

        pair< string, ll > pp;
        pp = v[i];
        cout << m[pp] << endl;
    }
}


Measured memory_bytes: 256