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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()
#define endl "\n"
#define int ll

int D;
const int N=26;
vector<vector<int>>s;
vector<int>c;

ll score(vector<int>&t){
  ll score=0;
  ll ans=0;
  vector<int>last(N,-1);
  for(int i=0;i<D;i++){
    ans+=s[i][t[i]];
    last[t[i]]=i;
    for(int j=0;j<N;j++){
      if(last[j]==-1)ans-=c[j]*(i+1);
      else ans-=c[j]*(i-last[j]);
    }
    score+=max(ans+1000000,0ll);
  }
  return score;
}

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

  cin>>D;
  c.resize(N);
  for(int i=0;i<N;i++)cin>>c[i];
  s.resize(D,vector<int>(N));
  for(int i=0;i<D;i++)for(int j=0;j<N;j++)cin>>s[i][j];

  /*
  for(int i=0;i<24;i++){
    vector<int>t(D);
    std::mt19937 rand_src(i);
    for(int j=0;j<D;j++)t[j]=i;//rand_src()%N;
    ll s=score(t);
    if(MaxScore<s)ans=t,MaxScore=s;
  }
  */

  vector<int>t(D,0);
  for(int i=0;i<D;i++){
    vector<int>s(D);
    for(int j=0;j<D;j++)s[j]=t[j];
    ll S=0;
    for(int j=0;j<24;j++){
      s[i]=j;
      ll SS=score(s);
      if(S<SS){
        t[i]=j;
        S=SS;
      }
    }
  }

  for(auto it:t)cout<<it+1<<endl;
  //cout<<MaxScore<<endl;
  return 0;
}


Measured memory_bytes: 3760
#include <bits/stdc++.h>
#include<cmath>
#define N 100005
#define A 1000005
#define MOD 1000000007 // //100000000 998244353 //
#define inf 1000000000000000000
#define ll long long
//#define M_PI 3.141592653589793238463

using namespace std;

#define pii pair<ll, ll>
#define piii pair<ll, pii>
#define ft first
#define sd second
#define pb push_back
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repr(i, n) for(ll i = n-1; i >= 0; i--)
#define itr(it, x) for(auto it = x.begin(); it != x.end(); it++)
#define mem(a, b) memset(a, (ll)b, sizeof(a))
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define edge(v, x, y) v[x].pb(y); v[y].pb(x);
#define popcount __builtin_popcount
#define ANS(s) {cout << s << "\n"; return;}

//~~~~~~fancy print~~~~~~~//
#define printpii(a) cout << a.ft << " " << a.sd << endl;
#define printpiii(a) cout << a.ft << " " << a.sd.ft << " " << a.sd.sd << endl;
#define print(a, n) rep(i, n) cout << a[i] << " "; cout << endl;
#define printv(v) for(auto x: v)cout << x << " "; cout << endl;
#define printm(a, n, m) rep(i, n) { rep(j, m) cout << a[i][j] << "\t"; cout << endl;}

ll lx[4] = {0, 0, 1, -1};
ll ly[4] = {1, -1, 0, 0};
ll dx[8] = {0, 0, 1, -1, 1, -1, 1, -1};
ll dy[8] = {1, -1, 0, 0, 1, 1, -1, -1};
void fast(){ios_base::sync_with_stdio(false);cin.tie(0);cout << setprecision(12) << fixed;}
ll lcm(ll a, ll b) {return (a*b)/__gcd(a, b); }

void solve()
{
    ll x1 = 0, y1 = 0, x2, y2, n;
    cin >> x2 >> y2 >> n;
    rep(i, n)
    {
        ll x, y, a;
        cin >> x >> y >> a;
        if(a == 1){
            x1 = max(x1, x);
        }
        else if(a == 2) x2 = min(x2, x);
        else if(a == 3) y1 = max(y1, y);
        else y2 = min(y2, y);
    }
    if(x1 > x2 || y1 > y2) ANS(0);
    cout << (x2-x1) * (y2-y1);

}
int main(){
    /*#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif*/
    fast();
    ll t = 1; //cin >> t;
    while(t--){
        solve();
    }
    return 0;
}


Measured memory_bytes: 256
#include <float.h>
#include <inttypes.h>
#include <limits.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <math.h>
#ifdef __cplusplus
#include <bits/stdc++.h>
#endif

#define getchar getchar_unlocked
#define putchar putchar_unlocked
int32_t nextint(void){ char c=getchar_unlocked(); while(c!='-'&&(c<'0'||'9'<c)) c=getchar_unlocked(); bool s=false; if(c=='-'){s=true;c=getchar_unlocked();} uint32_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar_unlocked(); } return s?-x:x; }
int64_t nextlong(void){ char c=getchar_unlocked(); while(c!='-'&&(c<'0'||'9'<c)) c=getchar_unlocked(); int s=0; if(c=='-'){s=1;c=getchar_unlocked();} uint64_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar_unlocked(); } return s?-x:x; }
uint32_t nextstr(char *s){ char c=getchar_unlocked(); while(c==' '||c=='\n') c=getchar_unlocked(); uint32_t len=0; while(c!=' '&&c!='\n'){ *s++=c; len++; c=getchar_unlocked(); } *s='\0'; return len; }

int dif2(int a, int b){return a<b?b-a:a-b;}

int b[90001][2];
long c[90001];
int main(void){
	int h=nextint();
	int w=nextint();
	int d=nextint();
	for(int i=0; i<h; i++){
		for(int j=0; j<w; j++){
			int a=nextint();
			b[a][0]=i;
			b[a][1]=j;
		}
	}
	int l=h*w-d;
	for(int i=0; i<=l; i++){
		c[i+d] = c[i] + dif2(b[i][0], b[i+d][0]) + dif2(b[i][1], b[i+d][1]);
	}
	int q=nextint();
	while(q-->0){
		int l=nextint();
		int r=nextint();
		printf("%ld\n", c[r]-c[l]);
	}
}


Measured memory_bytes: 2980
import java.util.Scanner;

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

		while(true){
			n=stdIn.nextInt();
			if(n==0) break;
					
			int[] s=new int[n];
			for(int i=0;i<n;i++){
				s[i]=stdIn.nextInt();
			}
			int max = s[0];
			int min = s[0];
			int a=0;
			int b=0;
			for(int i=1;i<s.length;i++){
				if(s[i]>max){
					max = s[i];
					a=i;
				}
				if(s[i]<min){
					min = s[i];
					b=i;
				}
			}
			s[a]=0;
			s[b]=0;
			int all = 0;
			for(int i=0;i<s.length;i++){
				all += s[i];
			}
			int ave = all/(n-2);
			System.out.println(ave);
		}
	}

}

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

using namespace std;
#define INF 1000000007

#define LINF (1LL << 62)

typedef long long i64;
typedef pair<i64,i64> P;


int n, k, a,b,c;
string s;

int main(){
	cin >> n >> k >> a >> b >>c;
	cin >> s;
	
	i64 ans = 0;
	bool used[101010] = {0};
	for(int i = 0; i < n; i++){
		if(i < k){
			if(s[i] == 'r') ans += c;
			if(s[i] == 's') ans += a;
			if(s[i] == 'p') ans += b;
			used[i] = 1;
			continue;
		}
		if(s[i] == s[i-k] && used[i-k]) continue;
		if(s[i] == 'r') ans += c;
		if(s[i] == 's') ans += a;
		if(s[i] == 'p') ans += b;
		used[i] = 1;
	}
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 640
program main
	implicit none
    integer(16)::k,a,b
    integer(16)::ans
    
    read(*,*) k,a,b
    
    if (a+2>=b)then
    	ans=k+1
    else if (k<=a)then
    	ans=k+1
    else if (mod(a,2)==mod(k,2))then
    	ans=a+(k-a)*(b-a)/2_16 +1
    else
    	ans=a+((k-a+1_16)/2_16)*(b-a)
    end if
    
    write(*,*) ans
    
    stop
end program main

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long LL;
#define SORT(c) sort((c).begin(),(c).end())

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

using namespace std;
int main(void)
{
  int n,m;
  cin >> n >> m;
  queue<tuple<int,int,int> > e;
  vector<int> work,cost;
  work.assign(n,0);
  cost.assign(n,0);
  REP(i,m){
    int a,b,c;
    cin >> a >> b >> c;
    e.push(make_tuple(a,b,c));
    ++work[b];
  }
  while(!e.empty()){
    int a,b,c;
    tie(a,b,c)=e.front();
    e.pop();
    if(work[a]){
      e.push(make_tuple(a,b,c));
      continue;
    }
    cost[b]=max(cost[b],cost[a]+c);
    --work[b];
  }
  cout << cost[n-1] << endl;
  return 0;
}

Measured memory_bytes: 3172
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <stdio.h>

using namespace std;

void solve() {
    string s; cin >> s;
    int plus = 0;
    for(int i = 0; i < 3; i++){
        if(s.substr(i,1) == "o") plus++;
    }
    cout << 700 + plus*100 << endl;
}

int main() {
    solve();
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
ios_base::sync_with_stdio(false);
	cin.tie(NULL);
#ifndef ONLINE_JUDGE
	//freopen("input.txt","r",stdin);
#endif

	
		int n;
		cin>>n;
		vector<int> a(n);
		for(int i=0;i<n;i++)
		{
			cin>>a[i];
		}
		sort(a.begin(),a.end(),greater<int>());

		queue<int> q;
		q.push(a[0]);

		ll sum=0;

		for(int i=1;i<n;i++)
		{
			int temp=q.front();
			sum+=temp;
			q.pop();
			q.push(a[i]);
			q.push(a[i]);
		}

		cout<<sum<<endl;


	
	return 0;
}

Measured memory_bytes: 4768
n,m=map(int,input().split())
l = [0] * m
r = [0] * m
for i in range(m):
    l[i], r[i] = map(int, input().split())

L=max(l)
R=min(r)
if L>R:
    print(0)
else:
    print(R-L+1)

Measured memory_bytes: 10868
#include <algorithm>
#include <iostream>
#include <unordered_map>
#include <vector>
using namespace std;

int main() {
  int n, w;
  while ( cin >> n >> w ) {
    vector<pair<int, int>> values(n);
    vector<unordered_map<int, long long>> dp(n);
    
    for ( auto &i : values ) cin >> i.first >> i.second;

    dp[0][0] = 0;
    dp[0][values[0].first] = values[0].second;

    for ( int i = 1; i < n; ++i ) {
      for ( const auto& j : dp[i - 1] ) {
        int pos = j.first + values[i].first;
        if ( pos > w ) continue;
        if ( dp[i].count(pos) ) {
          dp[i][pos] = max(dp[i][pos], j.second + values[i].second);
        } else {
          dp[i][pos] = j.second + values[i].second;
        }
      }
      // cout << i << ": ";
      // for ( auto i : dp[i] ) cout << i.first << " " << i.second << ", "; cout << endl;

      for ( const auto& j : dp[i - 1] ) {
        if ( dp[i].count(j.first) ) {
          dp[i][j.first] = max(dp[i][j.first], j.second);
        } else {
          dp[i][j.first] = j.second;
        }
      }
      // cout << i << ": ";
      // for ( auto i : dp[i] ) cout << i.first << " " << i.second << ", "; cout << endl;
    }
    long long answer = 0;
    for ( auto i : dp[n - 1] ) answer = max(answer, i.second);
    cout << answer << endl;
  }
  return 0;
}

Measured memory_bytes: 328228
global cnt
cnt = 0

def merge(A, left, mid, right):
    L = A[left:mid] + [float("inf")]
    R = A[mid:right] + [float("inf")]

    i = 0
    j = 0
    global cnt
    for k in range(left, right):
        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1
            if L[i] != float("inf"):
                cnt += len(L)-1-i

def mergesort(A, left, right):
    rsl = []
    if left+1 < right:
        mid = int((left+right)/2)
        mergesort(A, left, mid)
        mergesort(A, mid, right)
        rsl = merge(A, left, mid, right)

    return rsl


n = int(input())
S = list(map(int, input().split()))

mergesort(S, 0, n)
print(cnt)



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

int main(){
  bool flg = 0; int N , x; cin >> N;
  for(int i = 1 ; i <= N ; ++i){cin >> x; flg ^= x & 1;}
  cout << (flg & 1 ? "NO" : "YES"); return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
#include <limits.h>	
#define inf (INT_MAX-1)
#define INF 9223372036854775807
#define sq(n) ((n)*(n))
#define rep(i,n) for(i=0;i<n;i++)
#define rev(i,n) for(i=n-1;i>=0;i--)
#define sort(a,n) qsort(a,n,sizeof(TYPE),cmp)
#define sort_r(a,n) qsort(a,n,sizeof(TYPE),cmp_r);
#define TYPE int
#define MEMSET(a) memset(a,0,sizeof(a))
const int mod=(int)1e09+7;

int in(void){
	int i;scanf("%d",&i);
	return i;
}
long long llin(void){
	long long i;scanf("%lld",&i);
	return i;
}
double din(void){
	double i;scanf("%lf",&i);
	return i;
}
void chin(char s[]){
	scanf("%s",s);
}
void print(int a){
	printf("%d\n",a);
}
void llprint(long long a){
	printf("%lld\n",a);
}
void dprint(double a){
	printf("%.10f\n",a);
}
void print2(int a,int b){
	printf("%d %d\n",a,b);
}
long long max(long long a,long long b){
	return a>b?a:b;
}
long long min(long long a,long long b){
	return a<b?a:b;
}
long long llabs(long long a){
	return a>0?a:-a;
}
double dmax(double a,double b){
	return a>b?a:b;
}
int cmp(const void *a,const void *b){
	return *(TYPE *)a-*(TYPE *)b;
}
int cmp_r(const void *a,const void *b){
	return *(TYPE *)b-*(TYPE *)a;
}

int main(void){
	int a=in(),b=in(),i;
	char s[30];
	chin(s);
	rep(i,a){
		if(!isdigit(s[i])){
			puts("No");
			return 0;
		}
	}
	if(s[i]!='-'){
		puts("No");
		return 0;
	}
	for(i++;i<a+b+1;i++){
		if(!isdigit(s[i])){
			puts("No");
			return 0;
		}
	}
	puts("Yes");
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <list>
#include <iomanip>
#include <vector>
#include <functional>
#include <algorithm>
#include <cstdio>
#include <random>
#include <ctime>
#include <cstdlib>
#include <unordered_map>
#include <string.h>
#include <iostream>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(begin, i, end) for (int i = begin; i < (int)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

int main()
{
    ll X;
    cin >> X;
    ll now = 100;
    ll ans = 0;
    while (1)
    {
        ans++;
        now = now + now * 0.01;
        if (now >= X)
        {
            break;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll INF = 1e18;
int main() {
    ll n;cin >> n;
    vector<ll>v;
    v.push_back(1);
    for(ll i=6;i<=n;i*=6){
        v.push_back(i);
    }
    for(ll i = 9; i <= n; i *= 9) {
        v.push_back(i);
    }
    vector<ll> cost(n+1,INF);
    cost[0]=0;
    for(ll i=0;i<n;i++){
        for(ll j=0;j<v.size();j++){
            if(i+v[j]<=n)(cost[i+v[j]]=min(cost[i]+1,cost[i+v[j]]));
        }
    }
    cout << cost[n] << endl;
    return 0;
}


Measured memory_bytes: 1024
//by shubham_bitsg

#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
//using namespace __gnu_pbds;
 
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector <string> vs;

//#define oset tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define forl(i,a,b) for (ll i = a; i < b; i++)
#define rfor(i,b,a) for (int i = b; i >= a; i--)
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define srt(x) sort(x.begin(), x.end())
#define sumup(x) accumulate(x.begin(), x.end(), 0)
#define PI 3.141592653589793238
#define MOD 1000000007

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n, m, k;
    ll c = 0;
    cin>>n>>m>>k;
    vector <int> a, b;
    ll t;
    vector <ll> sum1, sum2;
    sum1.push_back(0); sum2.push_back(0);
    forl(i,0,n) {
        cin>>t;
        sum1.push_back(sum1[i] + t);
        a.push_back(t);
    }
    forl(i,0,m) {
        cin>>t;
        sum2.push_back(sum2[i] + t);
        b.push_back(t);
    }
    t = 0;
    map <ll,ll> s2;
    forl(i,0,m+1) {
        s2[sum2[i]] = i;
    }
    forl(i,0,n+1) {
        ll rem = k - sum1[i];
        if(rem<0) break;
        //auto it = upper_bound(sum2.begin(), sum2.end(), rem);
        auto it = s2.upper_bound(rem); it--;
        ll tot = i + it->second;
        if(tot>c) c = tot;
    }
    cout<<c<<"\n";
}


Measured memory_bytes: 20708
import java.util.Scanner;

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

        String S = in.next();
        
        if(S.equals("ABC")){
            System.out.println("ARC");
        }else{
            System.out.println("ABC");
        }
    }
}

Measured memory_bytes: 35556
#include <bits/stdc++.h>
using namespace std;
using pp = pair<int, int>;

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

    int H, W;
    cin >> H >> W;
    int dot = 0;
    vector<vector<char>> field(H + 2, vector<char>(W + 2, '#'));
    for (int i = 1; i <= H; i++) {
        for (int j = 1; j <= W; j++) {
            cin >> field[i][j];
            dot += field[i][j] == '.';
        }
    }

    vector<vector<int>> score(H + 2, vector<int>(W + 2, -1));
    queue<pp> q;
    // x, yでとる
    q.push(make_pair(1, 1));
    score[1][1] = 1;
    int dx[] = {-1, 0, 1, 0};
    int dy[] = {0, 1, 0, -1};

    while (!q.empty()) {
        pp p = q.front();
        q.pop();

        if (p.second == H && p.first == W) break;
        for (int i = 0; i < 4; i++) {
            int nx = p.first + dx[i];
            int ny = p.second + dy[i];
            if (field[ny][nx] == '#') continue;
            if (score[ny][nx] != -1) continue;
            score[ny][nx] = score[p.second][p.first] + 1;
            q.push(make_pair(nx, ny));
        }
    }

    if (score[H][W] == -1) {
        cout << -1 << endl;
        return 0;
    }
    cout << dot - score[H][W] << endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#include <complex>
#include <unistd.h>
#include <cassert>
#include <cctype>
#include <random>
#include <time.h>
#define _USE_MATH_DEFINES
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;
typedef complex<double> xy_t;
typedef vector<ll> vll;
typedef vector< vector<ll> > matrix;
#define REP(i, x, y) for(ll i = (ll)x; i < (ll)y; i++)
#define DREP(i, x, y, d) for(ll i = (ll)x; i < (ll)y; i += (ll)d)
#define PER(i, x, y) for(ll i = (ll)x; i > (ll)y; i--)
#define DPER(i, x, y, d) for(ll i = (ll)x; i > (ll)y; i -= (ll)d)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;
int iinf = intmax / 8;
ll inf = llmax / 8;
double eps = 1e-12;

ll modadd(ll x, ll y) {
    return ((x + y) % mod + mod) % mod;
}

ll dp[3010][3010];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    string s;
    cin >> s;
    dp[0][0] = 1;
    REP(i, 0, N - 1) {
        if (s[i] == '<') {
            dp[i + 1][0] = 0;
            REP(j, 1, i + 2) {
                dp[i + 1][j] = modadd(dp[i][j - 1], dp[i + 1][j - 1]);
            }
        } else {
            dp[i + 1][i + 1] = 0;
            PER(j, i, -1) {
                dp[i + 1][j] = modadd(dp[i][j], dp[i + 1][j + 1]);
            }
        }
    }
    // REP(i, 0, N) {
    //     REP(j, 0, N + 1) {
    //         cout << dp[i][j] << " ";
    //     }
    //     cout << endl;
    // }
    ll ans = 0;
    REP(i, 0, N + 1) {
        ans = modadd(ans, dp[N - 1][i]);
    }
    cout << ans << endl;
}


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

int main(){
  int a,b,c,d;
  cin >> a >>b >> c >>d;
  if (abs(a - c) <= d) {
    puts("Yes");
    return 0;
  }
  if (abs(b - a) <= d && abs(b - c) <= d) {
    puts("Yes");
    return 0;
  }
  puts("No");
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
        int a,b,d,r;
        double f;
        scanf("%d %d",&a,&b);

        d=a/b;
        r=a%b;
        f=(double)a/b;

        printf("%d %d %f\n",d,r,f);
        return 0;
}


Measured memory_bytes: 2056
#include<iostream>
#include<algorithm>
#include <stdio.h>
#include <cmath>
#include <cstring>
#include<string>
#include<map>
using namespace std;
map<long long, long long>s;

int main()
{  long long sum=0;
   int n,i,l,t=0;
  char a[12];
  char fri,ends;
   cin>>n;
    cin>>a;
    l=strlen(a);
    fri=a[0];ends=a[l-1];
      n--;
     for(i=0;i<l;i++)
     {
         sum+=(a[i]-'a'+1)*pow(10,l-i);
     }
     s[sum]=1;

   while(n--)
  {
      sum=0;
       cin>>a;
       l=strlen(a);
        for(i=0;i<l;i++)
       {
         sum+=(a[i]-'a'+1)*pow(10,l-i);
       }
      if(s[sum]==1)
      {
           t=1;

      }
       if(a[0]==ends)
       {
            ends=a[l-1];
       }
      else
      {
          t=1;
      }
      s[sum]=1;
    }
    if(t==1)
        cout<<"No"<<endl;
    else
        cout<<"Yes"<<endl;
    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int X,Y;
  cin >> X >> Y;
  int count = 0;
  if (X == 1){
    count += 300000;
  }
  if (Y == 1){
    count += 300000;
  }
  if (X == 2){
    count += 200000;
  }
  if (Y == 2){
    count += 200000;
  }
  if (X == 3){
    count += 100000;
  }
  if (Y == 3){
    count += 100000;
  }
  if (X == 1 && Y == 1){
    count += 400000;
  }
  cout << count << endl;
}
    

Measured memory_bytes: 3616
// #define _CRT_SECURE_NO_WARNINGS
// #define _USE_MATH_DEFINES	// M_PI=3.1415...
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <locale>
#include <cctype>
#include <sstream>
#include <iomanip>	// 20桁出力 cout << setprecision(20) << double;
#include <queue>
#include <bitset>	// bitset<8> bs1(131uL); // 10000011 bs1[0]は1 01stringからビット集合生成可
#include <numeric>
#include <random>
#include <climits>  // A/Bを計算するときA==LLONG_MIN && B==-1のみ(1ull<<63)で代用
using namespace std;

typedef long long LL;
typedef pair<LL, LL> P;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<LL> VL;
typedef vector<VL> VVL;				// VVL v(100,VL(100,0));
typedef vector<pair<LL, LL> > VP;
typedef vector<string> VS;
typedef map<int, int> MAPII;
typedef multimap<int, char, greater<int> > MuMAPIC;
typedef multimap<int, string, greater<int> > MuMIS;
typedef pair<LL, pair<P, P> > PP;

#define INF 999999999999999997		// 少し加算したらオーバーフローする
#define MP make_pair
#define FAST_IO  cin.tie(0); ios::sync_with_stdio(false);
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORL(i,a,b) for(LL i=(a);i<(b);i++)
#define FOR_REV(i,a,b) for(int i=(a);i>=(b);i--)
#define foreach_it(type,it,c) for(type::iterator it=c.begin(),c_end=c.end();it!=c_end;++it)
#define FOR_ITR(d) for(auto itr=d.begin(),d_end=d.end();itr!=d_end;++itr)	// C++11
#define O(s) cout<<s<<endl;

#define DUMP_VVI(b) if(dbgF){FOR(i,0,b.size()){FOR(j,0,b[i].size())printf("%d ",b[i][j]);puts("");}}
#define D_OUT(str,value) if(dbgF){cout<<str<<" : "<<value<<endl;}

template<class T>T IN() { T d; cin >> d; return d; }

LL gcd(LL a, LL b) { return (b > 0) ? gcd(b, a % b) : a; } // 最大公約数（Greatest Common Divisor）
LL lcm(LL a, LL b) { return a / gcd(a, b) * b; } // 最小公倍数（Least Common Multiple）
bool uruu(LL Y) { return (((Y % 4 == 0 && Y % 100 != 0) || Y % 400 == 0) ? true : false); } // うるう年判定
string Replace(string S, string from, string to) { auto p = S.find(from); while (p != string::npos) { S.replace(p, from.size(), to); p = S.find(from, p + to.size()); }return S; }
// 桁和
LL Ketawa_s(string s) { LL a = 0; FOR(i, 0, s.length())a += s[i] - '0'; return a; }

//二項係数 nCk mod pを求める
const LL MAX = 510000, p = 998244353; LL fac[MAX], finv[MAX], inv[MAX];
/* 前処理 */void COM_init() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; FOR(i, 2, MAX) { fac[i] = fac[i - 1] * i % p; inv[i] = p - inv[p % i] * (p / i) % p; finv[i] = finv[i - 1] * inv[i] % p; } }
/* 主処理 */LL COM(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % p) % p; }

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

// -------------------------------------------------------------------------------

int main() {
	FAST_IO;
	bool dbgF = true; // for D_OUT(str, value)  ... cout<< str <<" : "<< value <<endl;

	LL A, B, C;
	cin >> A >> B >> C;

	LL maxV = B / A;
	O(min(maxV, C));

	return 0;
}

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

using namespace std;

#define SHOW_VECTOR(v) {std::cerr << #v << "\t:";for(const auto& xxx : v){std::cerr << xxx << " ";}std::cerr << "\n";}
#define SHOW_MAP(v){std::cerr << #v << endl; for(const auto& xxx: v){std::cerr << xxx.first << " " << xxx.second << "\n";}}

long long bfs(long long N, long long d, long long S) {
    vector<int> a = {3, 5, 7};
    long long ret = 0;
    if (d > N) return 0;
    if (d <= N && S == 7) ret++;
    for (int i = 0; i < 3; i++) ret += bfs(N, d * 10 + a[i], S | (1 << i));
    return ret;
}

int main() {

    long long N;
    cin >> N;

    auto ans = bfs(N, 0, 0);
    cout << ans << endl;

    return 0;
}


























































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

using namespace std;
using ll = long long;


int main(){
    ll x;
    cin >> x;
    cout << (x/500)*1000 + ((x-(x/500)*500)/5)*5 << endl;
}

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

using namespace std;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1LL<<60;

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

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

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

ll getsub(vector<ll> a){

  // 昇順の数列が入力される
  // 1始まりでないとだめ

  // check
  int n = a.size();

  rep(i, n-1){
    if(a[i+1]-a[i] > 1){
      return -1;
    }
  }

  ll ret = 0;
  ret += a[n-1];
  for(int i = n-1; i > 0; i--){
    if(a[i] == a[i-1]){
      ret += a[i];
    }
  }

  return ret;

}

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

  int N;
  cin >> N;
  vector<ll> A(N);
  rep(i, N) cin >> A[i];

  if(A[0] != 0){
    cout << -1 << endl;
    return 0;
  }

  ll ans = 0;
  vector<ll> tmp;
  tmp.push_back(A[1]);
  rep(i,1, N-1){
    if(A[i] <= A[i+1]){
      tmp.push_back(A[i+1]);
    }else{
      
      ll tans = getsub(tmp);
      if(tans == -1){
        cout << -1 << endl;
        return 0;
      }

      ans += tans;

      vector<ll> t;
      t.push_back(A[i+1]);
      tmp = t;

    }
  }

  ll tans = getsub(tmp);
  if(tans==-1){
    cout << -1 << endl;
    return 0;
  }

  ans += tans;

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 5104
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using static System.Console;

namespace AtCoder_1
{
    class Program
    {
        static void Main(string[] args)
        {
            var s = CinAr();
            var SS = Cin();
            var b = SS[S2i(s[1]) - 1];
            string iss = b.ToString().ToLower();
            StringBuilder srr = new StringBuilder(SS);

            srr[S2i(s[1]) - 1] = iss[0];
            Cout(srr);
            Cin();
        }



        static readonly int MOD1E9 = 10000007;
        static bool isInt(double d) { return (int)d == d; }
        static string Cin() { return ReadLine(); }
        static string[] CinAr() { return ReadLine().Split(' '); }
        static int CinT() { return S2i(Cin()); }
        static int[] CinTAr() { return CinAr().Select((x, i) => { return S2i(x); }).ToArray(); }
        static long CinL() { return S2L(Cin()); }
        static long[] CinLAr() { return CinAr().Select((x, i) => { return S2L(x); }).ToArray(); }
        static double CinD() { return S2D(Cin()); }
        static double[] CinDAr() { return CinAr().Select((x, i) => { return S2D(x); }).ToArray(); }
        static int S2i(string s) { return int.Parse(s); }
        static long S2L(string s) { return long.Parse(s); }
        static double S2D(string s) { return double.Parse(s); }
        static void Cout(object s) { WriteLine(s); }
        static int[] yakusuu(int n)
        {
            if (n == 1) { return new int[] { 1 }; }
            HashSet<int> res = new HashSet<int>();
            for (int i = 1; i < Math.Ceiling(n / 2.0); i++)
            {
                if (n % i == 0)
                {
                    res.Add(i);
                    res.Add(n / i);
                }
            }
            return res.ToArray();
        }
        /// <summary>
        /// Debug時のみの使用を推奨
        /// </summary>
        /// <typeparam name="Type"></typeparam>
        /// <param name="types"></param>
        static void CoutAr<Type>(IEnumerable<Type> types)
        {
            string text = "";
            foreach (var i in types)
            {
                text += " " + i;
            }
            WriteLine(text.Substring(1));
        }

        public static long nCr(int n, int r)
        {
            // naive: return Factorial(n) / (Factorial(r) * Factorial(n - r));
            return nPr(n, r) / Factorial(r);
        }

        public static long nPr(int n, int r)
        {
            // naive: return Factorial(n) / Factorial(n - r);
            return FactorialDivision(n, n - r);
        }

        private static long FactorialDivision(int topFactorial, int divisorFactorial)
        {
            long result = 1;
            for (int i = topFactorial; i > divisorFactorial; i--)
                result *= i;
            return result;
        }

        private static long Factorial(int i)
        {
            if (i <= 1)
                return 1;
            return i * Factorial(i - 1);
        }
    }
}


Measured memory_bytes: 11092
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int N=53;
int x=1500;
string s,s1;
int main()
{
  cin>>s;
  for(int i=0;i+2<s.size();i++)
  {
    s1="";
    s1+=s[i],s1+=s[i+1],s1+=s[i+2];
    x=min(x,abs(stoi(s1)-753));
  }
  cout<<x<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define INF 1e9
typedef long long ll;
using namespace std;

int main() {
    int a,b,c,x; cin >> a >> b >> c >> x;
    int count = 0;
    for(int i = 0; i <= a; i++){
        for(int j = 0; j <= b; j++){
            for(int k = 0; k <= c; k++){
                if((500*i+100*j+50*k)==x){
                    count += 1;
                }
            }
        }
    }
    cout << count << endl;

    return 0;
}

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

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
  ll x;  // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod - a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const { return mint(*this) += a; }
  mint operator-(const mint a) const { return mint(*this) -= a; }
  mint operator*(const mint a) const { return mint(*this) *= a; }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod - 2); }
  mint& operator/=(const mint a) { return *this *= a.inv(); }
  mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream& is, mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }

int main() {
  ll n;
  cin >> n;
  vector<mint> a(n);
  rep(i, n) cin >> a[i];
  mint sum = 0, ans = 0;
  rep(i, n) sum += a[i];
  //   cout << "sum=" << sum << endl;
  ans = sum * sum;
  //   cout << "ans1=" << ans << endl;
  rep(i, n) ans -= a[i] * a[i];
  //   cout << "ans2=" << ans << endl;
  cout << ans / 2 << endl;
  return 0;
}

Measured memory_bytes: 4836
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	x, _ := strconv.Atoi(sc.Text())
	return x
}

func isWar(x, y []int, xLarge, yLarge int) bool {
	sort.Sort(sort.IntSlice(x))
	sort.Sort(sort.IntSlice(y))
	for z := xLarge + 1; z <= yLarge; z++ {
		if x[len(x)-1] < z && z <= y[0] {
			return false
		}
	}
	return true
}

func main() {
	sc.Split(bufio.ScanWords)
	var n, m, xLarge, yLarge int
	n = nextInt()
	m = nextInt()
	xLarge = nextInt()
	yLarge = nextInt()

	x := make([]int, n)
	y := make([]int, m)
	for i := range x {
		x[i] = nextInt()
	}

	for i := range y {
		y[i] = nextInt()
	}
	var war bool
	war = isWar(x, y, xLarge, yLarge)
	if !war {
		fmt.Println("No War")
		return
	}
	fmt.Println("War")
}


Measured memory_bytes: 640
import java.util.Scanner;
public class Main{
    public static boolean puttable(char board[][], int x, int y){
        for(int i = 1 ; i <= 7 ; i++){
            if(board[x][(y+i)%8] == 'Q')
                return false;
            else if(board[(x+i)%8][y] == 'Q')
                return false;
        }
	int n = Math.abs(x - y);
	for(int i = 0 ; i <= (7-n) ; i++){
		if(i == Math.min(x,y));
		else if(board[x-Math.min(x,y)+i][y-Math.min(x,y)+i] == 'Q')
			return false;
	}
	int n2 = 1;
	while(true){
		if(x-n2 < 0 || y+n2 > 7)
			break;
		else if(board[x-n2][y+n2] == 'Q')
			return false;
		n2++;
	}
	n2 = 1;
	while(true){
		if(x+n2 > 7 || y-n2 < 0)
			break;
		else if(board[x+n2][y-n2] == 'Q')
			return false;
		n2++;
	}
        return true;
    }
    public static boolean bfs(char board[][], int line){
        if(line == 8)
            return true;
        int count = 0;
        int x = 0;
        int y = 0;
        for(int i = 0 ; i < 8 ; i++){
            if(board[line][i] == 'Q'){
                x = line;
                y = i;
                count++;
            }
        }
        if(count >= 2)
            return false;
        else if(count == 1){
            if(puttable(board,x,y))
                return bfs(board,line+1);
            else
                return false;
        }
        else{
            for(int i = 0 ; i < 8 ; i++){
                if(puttable(board,line,i)){
                    board[line][i] = 'Q';
                    if(bfs(board,line+1))
                        return true;
                    else
                        board[line][i] = '.';
                }
            }
            return false;
        }
    }
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        char board[][] = new char[8][8];
        for(int i = 0 ; i < 8 ; i++){
            for(int j = 0 ; j < 8 ; j++)
                board[i][j] = '.';
        }
        int k = sc.nextInt();
        for(int i = 0 ; i < k ; i++){
            int x = sc.nextInt();
            int y = sc.nextInt();
            board[x][y] = 'Q';
        }
        if(bfs(board,0)){
            for(int i = 0 ; i < 8 ; i++){
                for(int j = 0 ; j < 8 ; j++)
                    System.out.print(board[i][j]);
                System.out.println();
            }
        }
    }
}


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

using namespace std;

typedef long long ll;

const ll MOD = 1e9+7;

int n, m, k;
ll fac[900100];
ll inv[900100];
ll fnv[900100];
ll f[600100];
ll p[600100];

ll po(ll a, ll n) {
    if (!n) return 1;
    ll t = po(a,n/2);
    return t*t%MOD*(n%2?a:1)%MOD;
}

ll comb(ll n, ll r) {
    if (r<0||r>n) return 0;
    return fac[n]*fnv[r]%MOD*fnv[n-r]%MOD;
}

int main() {
    int i;
    scanf("%d%d%d",&n,&m,&k);
    fac[0] = 1; for (i=1;i<=n+m+k;i++) fac[i]=fac[i-1]*i%MOD;
    inv[1] = 1; for (i=2;i<=n+m+k;i++) inv[i]=inv[MOD%i]*(MOD-MOD/i)%MOD;
    fnv[0] = 1; for (i=1;i<=n+m+k;i++) fnv[i]=fnv[i-1]*inv[i]%MOD;
    f[m+k] = comb(m+k,m); for (i=m+k-1;i>=0;i--) f[i] = (MOD+1)/2*(f[i+1]+comb(i,i-m)+comb(i,k))%MOD;
    p[0] = 1; for (i=1;i<=m+k;i++) p[i]=p[i-1]*3%MOD;
    ll ans = 0;
    for (i=0;i<=m+k;i++) ans = ans+comb(n-1+i,n-1)*p[m+k-i]%MOD*f[i]%MOD;
    printf("%lld\n",ans%MOD);

    return 0;
}


Measured memory_bytes: 30720
#include <algorithm>
#include <array>
#include <assert.h>
#include <bitset>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstring>
#include <functional>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <istream>

#include <map>
#include <math.h>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

namespace asl
{
    
    template <typename numeric_type>
    class point
    {
    public:
        numeric_type x, y;

        point(numeric_type x = 0, numeric_type y = 0) : x(x), y(y) {}

    };

    template <typename numeric_type>
    std::istream &operator>>(std::istream &is, point<numeric_type> &p)
    {
        return is >> p.x >> p.y;
    }

    template <typename numeric_type>
    numeric_type cross(point<numeric_type> a, point<numeric_type> b)
    {
        return a.x * b.y - a.y * b.x;
    }

#include <stdint.h>

    template <typename T>
    std::istream &operator>>(std::istream &is, std::vector<T> &vec)
    {
        for (auto &value : vec)
            is >> value;
        return is;
    }

} 

#include <experimental/optional>

#define _NEXT(i) (((i) + 1) == n ? 0 : ((i) + 1))

namespace asl
{
    template <typename numeric_type>
    using polygon = std::vector<point<numeric_type>>;

    template <typename numeric_type>
    numeric_type area2(const polygon<numeric_type> &P)
    {
        numeric_type A = 0;
        for (int i = 0, n = P.size(); i < n; ++i)
            A += cross(P[i], P[(_NEXT(i))]);
        return A;
    }

} 

#include <random>

#define endl '\n'

using namespace std;
using namespace asl;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.precision(1);
    cout << fixed;

    int n;
    cin >> n;

    polygon<int> p(n);
    cin >> p;

    cout << 1. * area2(p) / 2 << endl;

    return 0;
}





Measured memory_bytes: 3300
/**akshaykumar99**/
 
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;
 
template<typename T> using id_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update> ;
template<typename T> using id_setp = tree<pair<T,T>,null_type,less<pair<T,T>>,rb_tree_tag,tree_order_statistics_node_update> ;

#define f(i,x,n) for(i=x;i<n;i++)
#define fr(i,x,n) for(i=x;i>=n;i--)
#define pu push_back           
#define pp pop_back
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define SP(x) fixed<<setprecision(x)
#define IOS() ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 
const long long MOD=1e9+7;
const long double PI = acos(-1);
const long long INF=INT_MAX;
const long long LINF=LLONG_MAX;
const long long N=1e5+1;
 
typedef long long ll;
typedef long double ld;

long long po(long long a, long long b, long long m) {
    a %= m;
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}

int main()
{
    IOS();
  
    //reference geeks for geeks
    ll n,i,j,x=0,ans=0;
    cin>>n;
    ll a[n];
    f(i,0,n)
        cin>>a[i];
    f(i,0,64)  
    { 
        ll zc = 0, oc = 0;  
        ll sum = 0;  
        f(j,0,n)
        { 
            if(a[j] % 2 == 0) 
                zc++; 
            else
                oc++; 
            a[j]/=2; 
        } 
        sum = (oc*(zc*(po(2,i,MOD))%MOD)%MOD)%MOD;    
        ans+=(sum%MOD);
        ans%=MOD;  
    } 
    cout<<ans<<'\n';

    return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int main(){
  ll N,h,n,w; cin>>N;
  bool finish=false;
  for(int i=1; i<=3500; i++){
    for(int j=1; j<=3500; j++){
      if(4*i*j-N*(i+j)==0) continue;
      if(N*i*j%(4*i*j-N*(i+j))==0){
        w=N*i*j/(4*i*j-N*(i+j));
        if(w<=0) continue;
        h=i, n=j;
        finish=true;
        break;
      }
    }
    if(finish) break;
  }
  cout<<h<<" "<<n<<" "<<w<<endl;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
from collections import deque
from fractions import gcd
from functools import lru_cache


#############
# Constants #
#############

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

#############
# Functions #
#############

######INPUT######
def inputI(): return int(input().strip())
def inputS(): return input().strip()
def inputIL(): return list(map(int,input().split()))
def inputSL(): return list(map(str,input().split()))
def inputILs(n): return list(int(input()) for _ in range(n))
def inputSLs(n): return list(input().strip() for _ in range(n))
def inputILL(n): return [list(map(int, input().split())) for _ in range(n)]
def inputSLL(n): return [list(map(str, input().split())) for _ in range(n)]

#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])
    return arr

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#############
# Main Code #
#############

N= inputI()
l = inputSLs(N)

print(len(set(l)))

Measured memory_bytes: 104368
A, B, C, D = map(int, input().split())

# a > b
def m(a, b):
    if a < b:
        a, b = b, a

    if a % b == 0:
        return b
    return m(b, a % b)

def g(a, b):
    return a * b // m(a, b)

num_c = B // C - (A - 1) // C
num_d = B // D - (A - 1) // D
cd = g(D, C)
num_cd = B // cd - (A - 1) // cd

print(B - A + 1 - (num_c + num_d - num_cd))


Measured memory_bytes: 3064
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <queue>
#include <stack>
#include <list>
#include <functional>
#include <numeric>
#include <iostream>

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

int main() {

	int N, M, Q;
	static int L[212345], R[212345], p[112345], q[112345];

	scanf("%d%d%d", &N, &M, &Q);

	rep(i, M) scanf("%d%d", &L[i], &R[i]);
	rep(i, Q) scanf("%d%d", &p[i], &q[i]);

	map<pair<int, int>, int> LR;
	rep(i, M) LR[{ L[i], R[i] }]++;

	static int E[567][567];

	rep(i, 567) rep(j, 567) E[i][j] = 0;
	for (auto lr : LR) {
		E[lr.first.first][lr.first.second] = lr.second;
	}

	rep(i, N + 1) rep(j, N) {
		E[i][j + 1] = E[i][j + 1] + E[i][j];
	}

	rep(qi, Q) {
		int count = 0;
		for (int i = p[qi]; i <= q[qi]; ++i) {
			count += E[i][q[qi]];
		}
		printf("%d\n", count);
	}

	return 0;
}

Measured memory_bytes: 10752
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int num=sc.nextInt();
		for(int i=1;i<=num;i++){
			if(i%3==0){ //3の倍数を出力
				System.out.print(" "+i);
			}else{
				int x=i;
				while(true){
					if(x%10==3){ //3のつく数字を出力
						System.out.print(" "+i);
						break;
					}else if(x/10==0){ //10で割ったときの商が0の時終了
						break;
					}else{ //それ以外の時はxにx/10の値を入力
						x=x/10;
					}
				}
			}
		}
		System.out.println();
	}

}



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

struct UnionFind {
  vector<int> d; // 根なら負の値でサイズを持つ。子なら親のIDを持つ
  UnionFind(int n = 0) : d(n, -1) {}

  int find(int x) {
    if (d[x] < 0) return x;
    return d[x] = find(d[x]);
  }

  bool unite(int x, int y) {
    x = find(x); y = find(y);
    if (x == y) return false;
    if (d[x] > d[y]) swap(x, y);
    d[x] += d[y];
    d[y] = x;
    return true;
  }

  bool same(int x, int y) {
    return find(x) == find(y);
  }

  int size(int x) {
    return -d[find(x)];
  }
};

int main() {
  int n, m;
  cin >> n >> m;
  UnionFind uf(n);
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    --a; --b;
    uf.unite(a, b);
  }

  int ans = 0;
  rep(i, n) ans = max(ans, uf.size(i));
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3912
import itertools

N = int(input())

# 頭文字Mグループ、頭文字Aグループ、のように分割する
# どの3つのグループから1人選ぶかを考える

n_initial_MARCH = [0]*5
match_initial = ["M", "A", "R", "C", "H"]
for _ in range(N):
    s = input()
    for idx in range(5):
        if s[0] == match_initial[idx]:
            n_initial_MARCH[idx] += 1

taken_indices = list(itertools.combinations([idx for idx in range(5) if n_initial_MARCH[idx] > 0], 3))

ans = 0

for groups in taken_indices:
    ans += n_initial_MARCH[groups[0]] * n_initial_MARCH[groups[1]] * n_initial_MARCH[groups[2]]

print(ans)

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

using namespace std;

typedef long long int ll;
typedef long double ld;

#define rep(i,a,b) for(ll i=a;i<=b;++i)
#define rev(i,a,b) for(ll i=a;i>=b;i--)
#define pll pair<ll,ll>
#define vll vector<ll>
#define sll set<ll>
#define vpll vector<pll>
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define ln length()
#define M 1000000007
ll n,a,b,tot;

int main()
{
    ios::sync_with_stdio(false);cin.tie(0);
    cin>>n;
    ll sub = -1;ll ct=0;
    rep(i,1,n){
        cin>>a>>b;
        if(a>b){
            if(sub == -1) sub=b;
            else sub=min(sub,b);
        }
        if(a ==b ) ct++;
        tot+=a;
    }
    if(sub == -1) sub=0;
    if(ct == n) sub=tot;
    cout<<tot-sub<<'\n';
}



Measured memory_bytes: 256