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

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vector<vector<bool>>> vvvb;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<vpll> vvpll;
typedef vector<double> vd;
typedef vector<vd> vdd;

#define FOR(i,x,y) for(ll i=(ll)x; i<(ll)y; ++i)
#define REP(i,y) FOR(i, 0, y)
#define RFOR(i,x,y) for(ll i=(ll)x; i>=(ll)y; --i)
#define RREP(i,x) RFOR(i, x, 0)
#define ALL(a) a.begin(), a.end()
#define pb push_back
#define debug_print(x...) cerr << "line " << __LINE__ << " : "; debug_print_in(x);

template <typename First>
void debug_print_in(First first){
  cerr << first << endl;
  return;
}

template <typename First, typename... Rest>
void debug_print_in(First first, Rest... rest){
  cerr << first << " ";
  debug_print_in(rest...);
  return;
}

void IN(void){
  return;
}

template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){
  cin >> first;
  IN(rest...);
  return;
}

template <typename First>
void OUT(First first){
  cout << first << endl;
  return;
}

template <typename First, typename... Rest>
void OUT(First first, Rest... rest){
  cout << first << " ";
  OUT(rest...);
  return;
}

template<class t, class u> void chmax(t&a,u b){if(a<b)a=b;};
template<class t, class u> void chmin(t&a,u b){if(a>b)a=b;};
int popcount(int t){return __builtin_popcount(t);} //GCC
int popcount(ll t){return __builtin_popcountll(t);} //GCC

template <typename T>
void vec_print(vector<T> VEC){
  REP(i, VEC.size()){
    cerr << VEC[i] << " ";
  }
  cerr << endl;
};

template <typename T>
void mat_print(vector<vector<T> > MAT){
  REP(i,MAT.size()){
    REP(j,MAT[i].size()){
      cerr << MAT[i][j] << " ";
    }
    cerr << endl;
  }
};

constexpr int INF = (1<<30);
constexpr ll INFLL = 1LL<<62;
constexpr long double EPS = 1e-12;
constexpr ll MOD = (ll)((1E+9)+7);

int main(){
  cin.tie(0); // cut the cin and cout (default, std::flush is performed after std::cin)
  ios::sync_with_stdio(false); // cut the iostream and stdio (DON'T endl; BUT "\n";)

  ll N;
  IN(N);
  OUT((10000-N)%1000);

  return 0;
}

Measured memory_bytes: 3644
#include <stdio.h>
int min(int time,int c[],int des[])
{
    for(int q=0;q<time;q++)
    {
        for(int r=0;r<10;r++)
        {
            for(int s=0;s<10;s++)
            {
                if(des[s]-des[r]>c[r*10+s])des[s]=des[r]+c[r*10+s];
            }
        }
    }
    return *des;
}

int aaa(int a,int c[])
{
    if(a==1)return 0;
    int des[10];
    for(int p=0;p<10;p++)
        des[p]=c[a*10+p];
    min(10,c,des);
    return des[1];
}


int main(void)
{
    int h,w;
    scanf("%d %d",&h,&w);
    int c[100]={};
    for(int t=0;t<100;t++)scanf("%d",&c[t]);
    int length[10];
    for(int u=0;u<10;u++)length[u]=aaa(u,c);
    int cap[h*w];
    long long int ans=0;
    int zzz=0;
    for(int z=0;z<h*w;z++)
    {
        scanf("%d",&cap[z]);
        if(cap[z]!=-1)
        {
            zzz=cap[z];
            ans+=length[zzz];
           }
    }
    printf("%lld",ans);
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#define fi first
#define se second
using namespace std;
short n,a[22],b[22],c[22],ans;
int main(){
    scanf("%hd",&n);
    for (short i=1;i<=n;++i) scanf("%hd",&a[i]);
    for (short i=1;i<=n;++i) scanf("%hd",&b[i]);
    for (short i=1;i<=n;++i) scanf("%hd",&c[i]);
    for (short i=1;i<=n;++i){
        if (a[i-1]+1==a[i]) ans+=c[a[i-1]];
        ans+=b[a[i]];
    }
    printf("%hd",ans);
}


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

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

    vector<int> B(N);
    for (int i=0; i<N; i++) B.at(i) = i+1;
    
    int counter = -1;

    for (int i=0; i<N; i++) {
        if (a.at(i)==counter+2) counter++;
    }

    if (a==B) cout << 0 << endl;
    else if (counter == -1) cout << counter << endl;
    else if (counter != -1) cout << N - (counter + 1) << endl;
}

Measured memory_bytes: 1792
if __name__ == '__main__':
    while True:
        [n, k] = [int(i) for i in input().split()]
        if n == 0 and k == 0:
            break
        a = []
        for i in range(n):
            a.append(int(input()))

        old = sum(a[0:k])
        ans = old

        for i in range(1, n-k+1):
            new = old - a[i-1] + a[i+k-1]
            ans = max(ans, new)
            old = new

        print(ans)



Measured memory_bytes: 9872
let () =
  let counting_sort a b k =
    let len = (Array.length a) -1 and
        c = Array.make (k+1) 0 in
    Array.iter (fun x -> c.(x) <- c.(x)+1) a;
    for i = 1 to k do
      c.(i) <- c.(i) + c.(i-1)
    done;
    for i = 0 to len do
      let j = len - i in
      b.(c.(a.(j))-1) <- a.(j);c.(a.(j)) <- c.(a.(j))-1
    done;b
  in
  let read x = Scanf.scanf " %d" (fun y -> y) in
  let n = read_int () in
  let a = Array.init n read in
  let res = counting_sort a (Array.make n 0) 10000 in
  Printf.printf "%d" res.(0);
  for i = 1 to n-1 do
    Printf.printf  " %d" res.(i)
  done;
  Printf.printf "\n"
;;

Measured memory_bytes: 36164
#include <stdio.h>

int main(){
	int n, c, x;
	scanf("%d", &n);

	c = 0;
	for (int i=0; i<n;i++) {
		scanf("%d", &x);
		for (int j=2; j*j<=x; j++) {
			if ((x%j)==0) {
				goto skip;
			}
		}

		c++;
skip: 0;
	}

	printf("%d\n", c);
}




Measured memory_bytes: 2724
import java.util.Scanner;
import java.util.HashMap;

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

	int N = scan.nextInt();
	HashMap<Long, Integer> hash = new HashMap<Long, Integer>();

	long[] A_ = new long[N];
	for(int i = 0; i < N; i++){
	    A_[i] = scan.nextLong();
	}

	for(int i = 0; i < N; i++){
	    if(hash.containsKey(A_[i])){
		if(hash.get(A_[i]) == 1){
		    hash.put(A_[i], 0);
		}else{
		    hash.put(A_[i], 1);
		}
	    }else{
		hash.put(A_[i], 1);
	    }
	}
	
	int count = 0;
	for(int i = 0; i < N; i++){
	    if(hash.get(A_[i]) == 1){
		hash.put(A_[i], 0);
		count++;
	    }else{
	    }
	}

	System.out.println(count);
    }
}


Measured memory_bytes: 62792
#include<bits/stdc++.h>
using namespace std;
#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif
#define int long long

signed main(){

  int n,m; cin >> n >> m;
  priority_queue<int> q;
  for(int i = 0; i < n; i++){
    int a; cin >> a;
    q.push(a);
  }

  for(int i = 0; i < m; i++){
    int p = q.top(); q.pop();
    q.push(p/2);
  }

  int ans = 0;
  while(!q.empty()){
    int p = q.top(); q.pop();
    ans += p;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1400
#include<bits/stdc++.h>
using namespace std;
#define  ft  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define  ll  long long
#define  pi  pair<int,int>
#define  pb  push_back
#define  F   first
#define  S   second
const int N=2e5+2;
string s;
map<string,int>mp;
int main()
{
    ft
    int t,i,j,n,m,l,r;
    cin>>n;
    for(i=0;i<n;i++)
    {
        cin>>s;
        mp[s]++;
    }
    cin>>n;
    for(i=0;i<n;i++)
    {
        cin>>s;
        if(mp[s]>0)
        {
            mp[s]--;
        }
    }
    l=0;
    for(auto it=mp.begin(); it!=mp.end();it++)
    {
        l=max(l,it->second);
    }
    cout<<l<<"\n";
    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
#define ll long long
ll a[100];
int main(){
	int n;
	cin>>n;
	ll ans=0;
	for (int i=1;i<=n;i++){
		string s;
		cin>>s;
		if (s[0]=='M'){
			a[1]++;	
		}else if (s[0]=='A'){
			a[2]++;
		}else if (s[0]=='R'){
			a[3]++;
		}else if (s[0]=='C'){
			a[4]++;
		}else if (s[0]=='H'){
			a[5]++;
		}
	}
	
	for (int i=1;i<=5;i++){
		for (int j=i;j<=5;j++){
			for (int k=j;k<=5;k++){
				if	(i<j&&j<k){
					ans+=a[i]*a[j]*a[k];
				}
			}
		}
	}
	
	cout<<ans;	
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define r(i,n) for(int i=0;i<n;i++)
#define int long long
typedef pair<int,int>P;
typedef pair<int,P>P2;
#define F first
#define S second
 
typedef unsigned long long ull;

struct RollingHash{
  vector<ull> hash,p;
  ull MOD=1e9+7;
  ull B = 1777771;
  RollingHash(){}
  RollingHash(const string &s){
    int n=s.size();
    hash.assign(n+1,0);
    p.assign(n+1,1);
    for(int i=0;i<n;i++){
      hash[i+1]=(hash[i]*B+s[i])%MOD;
      p[i+1]=p[i]*B%MOD;
    }
  }
  //S[l, r)
  ull find(int l,int r){
    ull res=hash[r]+MOD-hash[l]*p[r-l]%MOD;
    return res>=MOD?res-MOD:res;
  }
};


 
signed main(){

  string s,t;
  cin>>s>>t;
  int B=t.size();
  while((int)s.size() <= 2000009) s=s+s;
  while((int)t.size() <= 1000009) t=t+t;
 
 
  RollingHash R(s);
  RollingHash T(t);
 
  int l=0,r=1000009/B+2;
 
  //cout<<t.substr(0,6)<<endl;
 
  while((r-l)>1){
    int mid=(r+l)/2;
    ull A = T.find(0,mid*B);
    int flag=0;
    r(i,s.size()-mid*B-1){
      if(R.find(i,i+mid*B) == A){
        flag=1;
        break;
      }
    }
    if(!flag) r=mid;
    else l=mid;
    //cout<<l<<' '<<B<<endl;
  }
 
  if(r==1000009/B+2)cout<<-1<<endl;
  else cout<<l<<endl;
 
}

Measured memory_bytes: 101792
A, B = map(int, input().split())
S = input()

parta = S[:A]
partb = S[A+1:]

if S[A] != '-':
  ans = "No"
elif parta.isdecimal() and partb.isdecimal():
  ans = "Yes"
else:
  ans = "No"
print(ans)

Measured memory_bytes: 38256
#include<bits/stdc++.h>
using namespace std;
inline int read(){
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+ch-'0';ch=getchar();}
	return x*f;
}
#define MN 100005
int n,d[MN];
struct edge{int to,nex;}e[MN*2];int hr[MN],cnt,fl[MN],fat[MN];
inline void ins(int f,int t){
	e[++cnt]=(edge){t,hr[f]};hr[f]=cnt;
}
inline void dfs1(int fa,int x){
	fl[x]=fl[fa]+1;fat[x]=fa;int res=0;
	for(int i=hr[x];i;i=e[i].nex) if(fa!=e[i].to) dfs1(x,e[i].to);
}
priority_queue<pair<int ,int> > que;
bool used[MN];
int main(){
	int a,b,i;
	n=read();
	for(i=1;i<n;i++) a=read(),b=read(),ins(a,b),ins(b,a),d[a]++,d[b]++;
	for(i=1;i<=n,d[i]==1;i++);dfs1(0,1);
	for(int i=1;i<=n;i++) que.push(make_pair(fl[i],i));
	while(!que.empty()){
		for(;!que.empty()&&used[que.top().second];que.pop());
		if(que.empty()) break;
		int top=que.top().second;
		int father=fat[top];que.pop();
		if(que.empty()){
			printf("First");return 0;
		}
		for(i=hr[father];i;i=e[i].nex) if(!used[e[i].to]&&e[i].to!=fat[father]&&e[i].to!=top){
			printf("First");return 0;
		}
		used[top]=1;used[father]=1;
	}
	printf("Second");
	return 0;
}

Measured memory_bytes: 4472
//https://atcoder.jp/contests/abc118/tasks/abc118_c
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
#ifdef BTK
#define DEBUG if(1)
#else
#define CIN_ONLY if(1)
struct cww {cww() {CIN_ONLY{ios::sync_with_stdio(false); cin.tie(0);}}}star;
#define DEBUG if(0)
#endif
#define ALL(v) (v).begin(),(v).end()
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l, T r){bool a = l>r; if (a)l = r; return a;}
template <typename T>inline bool chmax(T &l, T r){bool a = l<r; if (a)l = r; return a;}
template <typename T>istream& operator>>(istream &is, vector<T> &v){for (auto &it : v)is >> it;return is;}
class reverse_range {private:struct I {int x;int operator*() {return x-1;}bool operator!=(I& lhs) {return x>lhs.x;}void operator++() {--x;}};I i, n;public:reverse_range(int n) :i({ 0 }), n({ n }){}reverse_range(int i, int n) :i({ i }), n({ n }){}I& begin() {return n;}I& end() {return i;}};
class range {private: struct I { int x; int operator*() { return x; }bool operator!=(I& lhs) { return x<lhs.x; }void operator++() { ++x; } }; I i, n;public:range(int n) :i({ 0 }), n({ n }) {}range(int i, int n) :i({ i }), n({ n }) {}I& begin() { return i; }I& end() { return n; }reverse_range operator!(){return reverse_range(*i,*n);}};

int gcd(int a,int b){
    return b==0?a:gcd(b,a%b);
}

int main(){
    int N;
    cin>>N;
    int g=0;
    for(int i:range(N)){
        int a;
        cin>>a;
        g=gcd(g,a);
    }
    cout<<g<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define modulo 998244353
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 1000000000



int main(){
	
	int X;
	cin>>X;
	if(X==1)X++;
	for(int i=X;true;i++){
		bool f = true;
		for(int j=2;j*j<=i;j++){
			if(i%j==0){
				f=false;
				break;
			}
		}
		if(f){
			cout<<i<<endl;
			return 0;
		}
	}
	
    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
N = int(input())
S = list(input())

s = 0
e = N - 1

cnt = 0
while s <= e:
    if S[s] == 'W':
        while (S[e] != 'R'):
            if s >= e:
                print(cnt)
                exit()
            e -= 1
        S[s], S[e] = S[e], S[s]
        cnt += 1
    s += 1

print(cnt)

Measured memory_bytes: 73648
import java.util.*;

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

        int n = Integer.parseInt(sc.next());

        int[] a = new int[n - 1];
        for(int i = 0; i < n - 1; i++)
            a[i] = Integer.parseInt(sc.next());

        
        int[] ans = new int[n];
        for(int i = 0; i < n - 1; i++)
            ans[a[i] - 1]++;

        

        for(int i = 0; i < n; i++)
            System.out.println(ans[i]);
    }
}

Measured memory_bytes: 51340
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#define fo(a,b,c) for (a=b; a<=c; a++)
#define fd(a,b,c) for (a=b; a>=c; a--)
using namespace std;

long long a[101];
char st[101];
int tot,n,m,i,j,k,l;
char ch;
long long ans;

int main()
{
//	freopen("a.in","r",stdin);
	
	ch=getchar();
	while (ch>='a' && ch<='z')
	{
		st[++n]=ch;
		ch=getchar();
	}
	scanf("%d",&m);
	
	j=0;
	fo(i,1,n)
	{
		if (i==1 || st[i]!=st[i-1])
		j=1;
		else
		++j;
		
		if (i==n || st[i]!=st[i+1])
		a[++tot]=j;
	}
	
	if (st[1]!=st[n])
	{
		fo(i,1,tot)
		ans+=a[i]/2;
		ans*=m;
	}
	else
	{
		if (tot==1)
		ans=(long long)n*m/2;
		else
		{
			ans+=a[1]/2+a[tot]/2;
			fo(j,2,tot-1)
			ans+=(a[j]/2)*m;
			ans+=(a[1]+a[tot])/2*(m-1);
		}
	}
	
	printf("%lld\n",ans);
}

Measured memory_bytes: 256
/*..............IN THE NAME OF ALLAH.............*/
/**
*     => Md. Sajjat Hosen
*     => Department of Computer Science and Engineering
*     => Bangabandhu Sheikh Mujibur Rahman Science and Technology University
**/

/*..................! TRY ONCE MORE !..................*/

/*...Part - 01...*/

#include <bits/stdc++.h>
using namespace std ;

/*...Part - 02...*/

typedef long long               ll ;
typedef long double             ld ;
typedef unsigned long long      ull ;
typedef pair<int,int>           pii ;
typedef pair<ll,ll>             pll ;
typedef vector<int>             vi ;
typedef vector<ll>              vll ;
typedef vector<vector<int>>     vvi ;

int Int(){int x ; scanf("%d",&x) ; return x ;}
ll Long(){ll x ; scanf("%lld",&x) ; return x ;}
float Float(){float x ; scanf("%f",&x) ; return x ;}
double Double(){double x ; scanf("%lf",&x); return x;}

/*...Part - 03...*/
/*....Debugger....*/

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {cout << endl ;}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << ' ' ;
    err(++it, args...);
}

/*...Part - 04...*/
/*...Needed to change according to problem requirements...*/

const int N          = (int)2e5 + 5 ;
const int maxN       = (int)1e6 + 6 ;
const ll  Mod        = (ll)1e9 + 7 ;
const int inf        = (int)2e9 ;
const ll  Inf        = (ll)1e18 ;

/*..........................................................*/
/*...Part - 05...*/

#define     debug(x)    cerr << #x << " = " << x << '\n' ;
#define     rep(i,b,e)  for(__typeof(e) i = (b) ; i != (e + 1) - 2 * ((b) > (e))  ; i += 1 - 2 * ((b) > (e)))
#define     Int         Int()
#define     Long        Long()
#define     Float       Float()
#define     Double      Double()
#define     all(x)      x.begin() , x.end()
#define     sz(x)       (int)x.size()
#define     ff          first
#define     ss          second
#define     pb          push_back
#define     eb          emplace_back
#define     mem(a)      memset(a , 0 ,sizeof a)
#define     memn(a)     memset(a , -1 ,sizeof a)

/*...Part - 06...*/
/*...... ! Code start from here ! ......*/


inline void Yes(){printf("Yes\n");}
inline void No(){printf("No\n");}
inline void YES(){printf("YES\n");}
inline void NO(){printf("NO\n");}

int main(){
    //freopen("input.txt","r",stdin);
    int test = 1 , tc = 0 , flag = 0;
    char a[N];
    while(test--){
        scanf("%s", &a);
        int l = strlen(a);
        if(l % 2 == 1)
            No();
        else{
            for(int i = 0; i < l - 1; i += 2){
                if(a[i] == 'h' and a[i + 1] == 'i'){
                }
                else{
                    flag = 1;
                    break;
                }
            }
            if(flag == true) No();
            else Yes();
        }
    }
    return 0 ;
}

/*...Always look at the part - 04...*/
/*...............END................*/

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
void debug_out() { cerr << endl; }
template<class T> ostream& prnt(ostream& out, T v) { out << v.size() << '\n'; for(auto e : v) out << e << ' '; return out;}
template<class T> ostream& operator<<(ostream& out, vector <T> v) { return prnt(out, v); }
template<class T> ostream& operator<<(ostream& out, set <T> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, map <T1, T2> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, pair<T1, T2> p) { return out << '(' << p.st << ' ' << p.nd << ')'; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...);}
#define dbg(...) cerr << #__VA_ARGS__ << " ->", debug_out(__VA_ARGS__)
#define dbg_v(x, n) do{cerr<<#x"[]: ";for(int _=0;_<n;++_)cerr<<x[_]<<" ";cerr<<'\n';}while(0)
#define dbg_ok cerr<<"OK!\n"
#define ll long long
#define ld long double
#define ull unsigned long long
#define pii pair<int,int>
#define MOD 1000000007
#define zeros(x) x&(x-1)^x
#define fi first
#define se second
#define Nmax 500005
const long double PI = acos(-1);

int n, A[Nmax], B[Nmax];
ll ans1, ans2;
vector<pii> v;

int main(){
    ios::sync_with_stdio(false);
    cin >> n;
    for (int i=1;i<=n;i++){
        cin >> A[i] >> B[i];
        ans1 += A[i];
        ans2 += B[i];
        v.push_back({A[i],i});
        v.push_back({B[i],-i});
    }
    sort(v.begin(),v.end());
    
    int cnt = 0;
    ll s = 0;
    for (auto it : v){
        if (it.second < 0) B[-it.second] = cnt;
        else A[it.second] = cnt;  
        if (cnt < n) s += it.first;
        cnt++;
    }

    ll ans = min(ans1,ans2);


    for (int i=1;i<=n;i++){
        if (A[i] < n && B[i] < n){
            ans = min(ans, s);
        }
        else if (A[i] < n){
            if (A[i] == n-1) ans = min(ans, s - v[n-2].first + v[B[i]].first);
            else ans = min(ans, s - v[n-1].first + v[B[i]].first);
        }
        else if (B[i] < n){
            if (B[i] == n-1) ans = min(ans, s - v[n-2].first + v[A[i]].first);
            else ans = min(ans, s - v[n-1].first + v[A[i]].first); 
        }
        else{
            ans = min(ans, s - v[n-1].first - v[n-2].first + v[A[i]].first + v[B[i]].first);
        }
    }

    cout << ans << '\n';

    return 0;
}

Measured memory_bytes: 2932
#include<bits/stdc++.h>
using namespace std;
long long int num[200000+100],ara[200000+100];
int main()
{
	int n,i;
	cin>>n;
	int x;
	long long int sum=0,ans;
	for(i=0;i<n;i++){
		cin>>x;
		ara[i]=x;
		num[x]++;
	}
	for(i=1;i<=n;i++){
		sum+=(num[i]*(num[i]-1))/2;
	}
	for(i=0;i<n;i++){
		ans=sum-((num[ara[i]]*(num[ara[i]]-1))/2-((num[ara[i]]-1)*(num[ara[i]]-2))/2);
		cout<<ans<<endl;
	}
	return 0;
}

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

int main() { 
  for(;;) { 
    int n, l, r; 
    std::cin >> n >> l >> r; 
    if (n == 0 && l == 0 && r == 0) { break; } 
    std::vector<int> xs(n); 
    for(int i = 0; i < n; ++i) std::cin >> xs[i]; 
    int res = 0; 
    for(int y = l; y <= r; ++y) {
      bool flag = false;
      for(int i = 0; i < n; ++i) { 
        if (y % xs[i] == 0) { 
          if (i % 2 == 0) { 
            res += 1; 
          }
          flag = true;
          break;
        }
      }
      if (!flag) {
        if (n % 2 == 0) {
          res += 1;
        }
      }
    }    
    printf("%d\n", res); 
  } 
}
 



Measured memory_bytes: 3196
#include <bits/stdc++.h>
using namespace std;
#define inf 0x3f3f3f3f
#define ll long long
#define maxm 
#define mod 
#define maxn 
 
int main()
{
	int a, b, c, d;
	
	scanf("%d%d%d%d", &a, &b, &c, &d);
	int x = max(a, c), y = min(b, d);
	if (x > y) {
		puts("0");
	} else {
		printf("%d\n", y - x);
	}
}

Measured memory_bytes: 256
/**
 *      AGC 14 A
 *      author  : kyomukyomupurin
 *      created : 2018-10-08 14:57:09
**/

#include <algorithm>
#include <array>
#include <cassert>
#include <climits>
#include <complex>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
#define int64 long long
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int A, B, C; cin >> A >> B >> C;

    int firstA = A; int firstB = B; int firstC = C;
    int cnt = 0;

    if (A % 2 == 1 || B % 2 == 1 || C % 2 == 1){
        cout << cnt << endl; return 0;
    }

    while (1){
        ++cnt;
        int tempA = A; int tempB = B; int tempC = C;
        A = (tempB + tempC) / 2; B = (tempA + tempC) / 2; C = (tempA + tempB) / 2;
        if (A % 2 == 1 || B % 2 == 1 || C % 2 == 1){
            cout << cnt << endl; return 0;
        }
        else if (A == firstA && B == firstB && C == firstC){
            cout << -1 << endl; return 0;
        }        
    }
    
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

class Main{
	public static void main(String args[]){
		Scanner s=new Scanner (System.in);
		while(true){
			String a=s.next();
			String b=s.next();
			if(a.length()==1)System.exit(0);
			int hit=0;
			for(int i=0;i<4;i++)if(a.charAt(i)==b.charAt(i))hit++;
			int blow=0;
			for(int i=0;i<4;i++)
				for(int j=0;j<4;j++)
					if(a.charAt(i)==b.charAt(j)&&i!=j)blow++;
			System.out.println(hit+" "+blow);
		}
	}
}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define EPS (1e-10)
#define equals(a, b) (fabs((a)-(b)) < EPS)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;

class BIT {
public:
  int N;
  vi arr;
  BIT(int n) {
    N = n;
    arr = vi(N+1,0);
  }
  int sum(int x) {
    int s = 0;
    for(int i = x+1;i > 0;i -=i&(-i)) {
      s += arr[i];
    }
    return s;
  }
  void add(int x,int k) {
    for(int i = x+1;i <= N;i +=i&(-i)) {
      arr[i] += k;
    }
  }
};
  
int main() {
  int N;
  cin >> N;
  vi A(N);
  vi pos(N);
  rep(i,N) {
    cin >> A[i];
    A[i]--;
    pos[A[i]]=i;
  }
  BIT bit(N+3);
  bit.add(1,1);
  bit.add(N+2,1);
  auto incc = [&](int k) {
    bit.add(k+2,1);
  };
  auto isDiff = [&](int a,int b) {
    return bit.sum(a+1) != bit.sum(b+1);
  };
  ll ans = 0;
  rep(i,N) {
    int now = pos[i];
    int res = 0;
    int l,r;
    {
      int ng=-1,ok=now;
      while(ng+1<ok) {
        int m = (ng+ok)/2;
        if(isDiff(m,now)) {
          ng=m;
        } else {
          ok=m;
        }
      }
      l = now-ok;
    }
    {
      int ok=now,ng=N+1;
      while(ok+1<ng) {
        int m = (ok+ng)/2;
        if(isDiff(now,m)) {
          ng=m;
        } else {
          ok=m;
        }
      }
      r = ok-now-1;
    }
    incc(now);
    ans += ll(i+1)*(l+1)*(r+1);
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 2688
#include <bits/stdc++.h>
#include <variant>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/adaptor/indexed.hpp>
#define FOR(i,k,n)  for(int i = (k);i < (n);++i)
#define REP(i,n)    FOR(i,0,n)
#define ALL(x) begin(x),end(x)

using namespace std;
using namespace boost::adaptors;
using namespace std::string_literals;
using ll = int64_t;
using vecint = vector<int>;
using vecll = vector<ll>;
using boost::irange;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin>>n;
  vecint a(n);
  for(auto&&e:a)cin>>e;
  set<int> already;
  vector<bool> ng(1000001, false);
  REP(i,n) {
    if (already.count(a[i])) {
      ng[a[i]] = true;
      continue;
    }
    for(int j = 2*a[i]; j <= 1000000; j += a[i]) {
      ng[j] = true;
    }
    already.insert(a[i]);
  }
  int cnt = 0;
  REP(i,n) {
    if (!ng[a[i]]) ++cnt;
  }
  cout<<cnt<<endl;
  return 0;
}


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

void solve()
{
    char s[6];
    for(int i=1;i<=6;i++) cin>>s[i];
        if(s[3]==s[4] && s[5]==s[6])
            cout<<"Yes"<<endl;
        else cout<<"No"<<endl;

    return;
}
int main()
{
  //int t; cin>>t;
  //while(t--)
  {
      solve();
  }
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(ll i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
constexpr char ln = '\n';

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

#define bit(n,k) ((n>>k)&1) //*n no k bit me 1 or 0*/

struct mint {
    ll x; // typedef long long ll;
    mint(ll x=0):x((x%mod+mod)%mod){}
    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 { mint res(*this); return res+=a; }
    mint operator-(const mint a) const { mint res(*this); return res-=a; }
    mint operator*(const mint a) const { mint res(*this); return res*=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 { mint res(*this); return res/=a; }
};

int rc(int lim, int con, int b){
  if(lim==1){
    if(con==0 && b==1){
      return 0;
    } else {
      return 1;
    }
  } else {
    if(b==0){
      return con;
    } else {
      return 2-con;
    }
  }
}

int lc(int lim, int con, int b){
  if(lim==0){
    if(con==0 && b==0){
      return 0;
    } else {
      return 1;
    }
  } else {
    if(b==1){
      return con;
    } else {
      return 2-con;
    }
  }
}

int main(){
  ll L,R;
  cin >> L >> R;
  vector<vector<vector<vector<mint>>>> dp(61, vector<vector<vector<mint>>>(3, vector<vector<mint>>(3,vector<mint>(2,0))));
  dp[60][0][0][0] = 1;
  for(int i=59; i>=0; i--)rep(a,2)rep(b,2)rep(c,2){
    int bl = bit(L,i);
    int br = bit(R,i);
    // y,x 0,0
    dp[i][rc(br,a,0)][lc(bl,b,0)][c] += dp[i+1][a][b][c];
    // y,x 1,0
    if(c){
      dp[i][rc(br,a,1)][lc(bl,b,0)][c] += dp[i+1][a][b][c]; 
    }
    // y,x 1,1
    dp[i][rc(br,a,1)][lc(bl,b,1)][1] += dp[i+1][a][b][c];
  }

  mint ans = 0;
  rep(a,2)rep(b,2){
    ans += dp[0][a][b][1];
  }
  cout << ans.x << ln;
  return 0;
}

Measured memory_bytes: 3672
[h,w]=list(map(int,input().split()))
#print(h,w)
lst=[]
for i in range(h):
    lst.append(input())
#print(lst)

lst2=[]
for i in range(h*2):
    lst2.append(lst[i//2])
#print(lst2)
for i in lst2:
    print(i)

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

#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define pb push_back
#define mod 1000000007
#define INF 2000000000
typedef long long ll;
bool compare(pair<int, int> a, pair<int, int> b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}
// 入力



int main() {
    string S;
    cin >> S ;
    if(S =="Sunny"){
        cout << "Cloudy" << endl;
    }else if(S=="Cloudy"){
        cout << "Rainy" << endl;
    }else{
        cout << "Sunny" << endl;
    }
    
    
    return 0;
    

}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <ctime>
#include <cmath>
#include <string>
#include <stdlib.h>
#include <fstream>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <iterator>
#include <iomanip>
using namespace std;

const long long mod = 1e9 + 7;

int main(){
    string s;
    cin >> s;
    long long n = s.size();
    vector<vector<long long> > d(n + 1, vector<long long>(13, 0));
    d[0][0] = 1;
    for(int i = 0; i < n; ++i){
        if(s[i] == '?'){
            for(int j = 0; j < 13; ++j)
                for(int k = 0; k < 10; ++k){
                    d[i + 1][(j * 10 + k) % 13] += d[i][j];
                    d[i + 1][(j * 10 + k) % 13] %= mod;
                }
        }
        else{
            for(int j = 0; j < 13; ++j){
                int k = s[i] - '0';
                d[i + 1][(j * 10 + k) % 13] += d[i][j];
                d[i + 1][(j * 10 + k) % 13] %= mod;
            }
        }
    }
    cout << d[n][5] % mod;
}


Measured memory_bytes: 13568
import math
import copy
from copy import deepcopy
import sys
import fractions
import numpy as np
from functools import reduce
# import statistics
import heapq
sys.setrecursionlimit(3000)

# input = sys.stdin.readline
# sys.setrecursionlimit(10**6)

# ===FUNCTION===

def getInputInt():
    inputNum = int(input())
    return inputNum


def getInputListInt():
    outputData = []
    inputData = input().split()
    outputData = [int(n) for n in inputData]

    return outputData


def getSomeInputInt(n):
    outputDataList = []
    for i in range(n):
        inputData = int(input())
        outputDataList.append(inputData)

    return outputDataList


def getSomeInputListInt(n):
    inputDataList = []
    outputDataList = []
    for i in range(n):
        inputData = input().split()
        inputDataList = [int(n) for n in inputData]
        outputDataList.append(inputDataList)

    return outputDataList


# ===CODE===
# input_num = getInputListInt()
#
# h = input_num[0]
# w = input_num[1]
#
# data=[]
# for i in range(h):
#     tmp = str(input())
#     tmp_list = list(tmp)
#     data.append(tmp_list)
#
# def saikiU(cnt, i, j):
#     if i < 0 or i > h-1: return cnt
#     if j < 0 or j > w-1: return cnt
#     if data[i][j] == "#": return cnt
#
#     return saikiU(cnt+1, i-1, j)
#
#
# def saikiD(cnt, i, j):
#     if i < 0 or i > h - 1: return cnt
#     if j < 0 or j > w - 1: return cnt
#     if data[i][j] == "#": return cnt
#
#     return saikiD(cnt + 1, i + 1, j)
#
# def saikiL(cnt, i, j):
#     if i < 0 or i > h - 1: return cnt
#     if j < 0 or j > w - 1: return cnt
#     if data[i][j] == "#": return cnt
#
#     return saikiL(cnt + 1, i, j-1)
#
# def saikiR(cnt, i, j):
#     if i < 0 or i > h - 1: return cnt
#     if j < 0 or j > w - 1: return cnt
#     if data[i][j] == "#": return cnt
#
#     return saikiR(cnt + 1, i, j+1)
#
#
# yoko_sum = [[0 for i in range(w)] for j in range(h)] #二次元の静的確保
# tate_sum = [[0 for i in range(w)] for j in range(h)] #二次元の静的確保
#
# for i in range(h):
#     for j in range(w):

import numpy as np
import sys

H, W = list(map(int, sys.stdin.readline().split()))
S = np.array([list(sys.stdin.readline().rstrip()) for _ in range(H)]) == '.'
ups = np.zeros((H, W), dtype=int)
downs = np.zeros((H, W), dtype=int)
rights = np.zeros((H, W), dtype=int)
lefts = np.zeros((H, W), dtype=int)

for h in range(1, H):
    ups[h] = (ups[h - 1] + 1) * S[h - 1]
    downs[H - h - 1] = (downs[H - h] + 1) * S[H - h]
for w in range(1, W):
    lefts[:, w] = (lefts[:, w - 1] + 1) * S[:, w - 1]
    rights[:, W - w - 1] = (rights[:, W - w] + 1) * S[:, W - w]

print(((ups + downs + lefts + rights) * S).max() + 1)

Measured memory_bytes: 228268
import java.util.Scanner;

public class Main {

	static Scanner scanner;

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

        int a=gi();
        int b=gi();
        int c=gi();
        int d=gi();
       
        int k=0;
        while(a>0&&c>0) {
        	if(k%2==1) {
        		a-=d;
        	}else {
        		c-=b;
        	}
        	k++;
        }

        //System.out.println();
        if (a>0) {
        	System.out.println("Yes");
        }else {
        	System.out.println("No");
        }
	}


	public static long d(long n) {
		String a=String.valueOf(n);
		return (long)a.length();
	}

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

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

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

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

Measured memory_bytes: 35568
#include <iostream>
#include <complex>

using namespace std;

typedef complex<double> P;

double cross(P a, P b){
  return a.real() * b.imag() - a.imag() * b.real();
}

double dot(P a, P b){
  return a.real() * b.real() + a.imag() * b.imag();
}

int ccw(P a, P b, P c){
  b -= a; c -= a;
  if(cross(b, c) > 0) return 1;
  if(cross(b, c) < 0) return -1;
  if(dot(b, c) < 0) return 2;
  if(norm(b) < norm(c)) return -2;
  return 0;
}

int main()
{
  int i;
  int xp1,yp1,xp2,yp2,xp3,yp3,xk,yk,xs,ys;
  cin>>i;
  for(;i--;)
    {
      cin>>xp1>>yp1>>xp2>>yp2>>xp3>>yp3>>xk>>yk>>xs>>ys;
      P p1(xp1,yp1),p2(xp2,yp2),p3(xp3,yp3),k(xk,yk),s(xs,ys);

      if((ccw(p1,p2,k)==ccw(p2,p3,k)&& ccw(p2,p3,k)==ccw(p3,p1,k))
	 ^(ccw(p1,p2,s)==ccw(p2,p3,s)&& ccw(p2,p3,s)==ccw(p3,p1,s))
	 )
	cout<<"OK"<<endl;
      else
	cout<<"NG"<<endl;
    }
}

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

int main(void){

  int second,minute,hour,input;

  cin >> input;

  hour = input / 3600;
  input = input - hour * 3600;
  minute = input / 60;
  input = input - minute * 60;
  second = input;

  printf("%d:%d:%d\n",hour,minute,second);
  
  return 0;
}

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

int main() {
    init();

    int n; cin >> n;
    VI a(n); cin >> a;
    ll ans = 0;
    map<int, int> m;
    FOR(i, 0, n) {
        ans += m[i - a[i]];
        ++m[i + a[i]];
    }
    print(ans);
}

Measured memory_bytes: 21112
#include<stdio.h>
int main(void){
	int n, arr[100], i, j;
	
	scanf("%d\n", &n);
	for(i = 0; i < n; i++){
		scanf("%d", &arr[i]);
	}
	for(j = n-1; j >= 0; j--){
		if(j == 0){
			printf("%d\n", arr[j]);
			break;
		}
		printf("%d ", arr[j]);
	}
	return 0;
}



Measured memory_bytes: 2064
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <map>
#include <set>
#include <cassert>

#define rep(i,x) for(int i = 0; i < x; i++)
#define rrep(i,x) for(int i = 1; i <= x; i++)
#define srep(i,s,t) for (int i = s; i < t; ++i)
using ll = long long;
using namespace std;
const int INF = 1001001001;
const ll LINF = 1002003004005006007;

int main(){
    int k; cin >> k;
    queue<ll> q;
    rrep(i, 9) q.push(i);
    rep(i, k - 1){
        ll n = q.front();
        int btm = n % 10;
        for (int j = -1; j <= 1; ++j){
            int nbtm = btm + j;
            if (nbtm < 0 or nbtm > 9) continue;
            q.push(n * 10 + nbtm);
        }
        q.pop();
    }
    cout << q.front() << endl;
}


Measured memory_bytes: 1792
#include<stdio.h>
int main(void)
{
	int a,b,k;
	
	scanf("%d",&k);
	scanf("%d",&a);
	scanf("%d",&b);
	
	while(a<=b){
		if(a%k==0){
		printf("OK");
		return 0;
		}
		
		else
		a++;
	}
	
	printf("NG");
	

	return 0;
}


Measured memory_bytes: 1736
#include<iostream>
#include<fstream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>

using namespace std;
string st,st1;
int main()
{
	cin>>st>>st1;
	if(st[0]==st1[2]&&st[1]==st1[1]&&st[2]==st1[0])
	cout<<"YES";
	else
	cout<<"NO";
	cout<<endl;
	return 0;
}

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

typedef long long ll;

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

    int n, m;
    cin>>n>>m;

    const int mod = 1e9 + 7;

    vector<string> grid(n);
    for (int i=0;i<n;++i) cin>>grid[i];

    int dp[n][m];

    for (int i=0;i<n;++i){
        for (int j=0;j<m;++j){
            if (i==0 && j==0) {
                dp[0][0] = 1;
                continue;
            }
            dp[i][j] = 0;
            if (i-1>=0) {
                dp[i][j] += dp[i-1][j];
                dp[i][j] %= mod;
            }
            if (j-1>=0){
                dp[i][j] += dp[i][j-1];
                dp[i][j] %= mod;
            }

            if (grid[i][j] == '#') dp[i][j] = 0;
        }
    }

    cout<<dp[n-1][m-1]<<endl;

    return 0;
}

Measured memory_bytes: 5248
#include <iostream>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <functional>

using namespace std;
using ll = long long;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, pair<ll, ll>> PP;

const ll MOD = 1e9 + 7;
const ll INF = 1 << 30;
const ll INF2 = 9e18;
const double INF3 = 9e14;
const int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
const int tx[8] = { -1,0,1,-1,1,-1,0,1 }, ty[8] = { -1,-1,-1,0,0,1,1,1 };
#define ALL(x) (x).begin(),(x).end()
#define pb push_back
#define fr first
#define sc second

ll h, w, k, sh, sw, d[1000][1000], ans = INF;
char c[1000][1000];

void bfs(int x, int y) {
	queue<P>q;
	q.push(P(sh, sw));
	while (q.size()) {
		P p = q.front();q.pop();
		for (int i = 0;i < 4;i++) {
			ll nx = p.first + dx[i], ny = p.second + dy[i];
			if (0 <= nx&&nx < h && 0 <= ny&&ny < w&&c[nx][ny] != '#'&&d[nx][ny] == INF) {
				q.push(make_pair(nx, ny));
				d[nx][ny] = d[p.first][p.second] + 1;
			}
		}
	}
}

int main() {
	cin >> h >> w >> k;
	for (int i = 0;i < h;i++) {
		for (int j = 0;j < w;j++) {
			cin >> c[i][j];
			if (c[i][j] == 'S')sh = i, sw = j;
			d[i][j] = INF;
		}
	}
	d[sh][sw] = 0;
	bfs(sh, sw);
	for (int i = 0;i < h;i++) {
		for (int j = 0;j < w;j++) {
			if ((i == 0 || j == 0 || i == h - 1 || j == w - 1) && d[i][j] <= k) {
				cout << 1 << endl;
				return 0;
			}
			else if (d[i][j] <= k) {
				ans = min(ans, 1 + (j + k - 1) / k);
				ans = min(ans, 1 + (w - 1 - j + k - 1) / k);
				ans = min(ans, 1 + (i + k - 1) / k);
				ans = min(ans, 1 + (h - 1 - i + k - 1) / k);
			}
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 8320
#include <bits/stdc++.h>
#define ll long long

using namespace std;

int k;
int dist[100010];
queue<int> dial[2];

void update(int cvor, int vrednost, int ind)
{
    cvor=cvor%k;
    if(vrednost<dist[cvor])
        dist[cvor]=vrednost, dial[ind%2].push(cvor);
}

int dijkstra()
{
    int i=1;
    while(true)
    {
        while(dial[i%2].empty())
            i++;
        int tek=dial[i%2].front();
        dial[i%2].pop();
        if(tek==0)
            return dist[tek];
        update(tek+1, dist[tek]+1, i+1);
        update(tek*10, dist[tek], i);
    }
}

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

	cin>>k;
	for(int i=0;i<k;i++)
        dist[i]=1e7;
    dist[1]=1;
    dial[1].push(1);
    cout<<dijkstra();


	return 0;
}


Measured memory_bytes: 896
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using P = pair<int,int>;
// auto mod int
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, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

int main() {
  int h,w,k;
  cin >> h >> w >> k;
  --k;

  vector<mint> dp(w);
  dp[0] = 1;
  rep(hi,h){
    vector<mint> temp(w);
    rep(i,w){
      if(dp[i].x==0) continue;
      rep(x,1<<(w-1)){
        auto line = [&](int i){ return (x>>i)&1; };
        bool ok = [&]{
          rep(i,w-2) if(line(i) && line(i+1)) return false;
          return true;
        }();
        if(!ok) continue;

        if(i>0 && line(i-1)) temp[i-1] += dp[i];
        else if(line(i)) temp[i+1] += dp[i];
        else temp[i] += dp[i];
      }
    }
    swap(dp,temp);
  }
  cout << dp[k] << endl;
}

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

int main(){
  int a, b;
  cin >> a >> b;
  
  vector<int> ans(3);
  ans.at(0) = a+b;
  ans.at(1) = a-b;
  ans.at(2) = a*b;
  
  sort(ans.begin(), ans.end());
  
  cout << ans.at(2) << endl;
}

Measured memory_bytes: 3612
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using lpair = pair<ll, ll>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i=(m);i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i>=(n);i--)
#define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
void print() {}
template <class H,class... T>
void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}
ll dp[3010][3010] = {};
ll dp2[3010][3010] = {};

ll prev_w[3010][3010] = {};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N,T;
    cin >> N >> T;
    ll A[3010], B[3010];
    rep(i,0,N) cin >> A[i] >> B[i];
    dp[0][0] = 0;
    rep(i,0,N){
        rep(t,0,T+1){
            if(t - A[i] >= 0){
                if(dp[i+1][t] < dp[i][t - A[i]] + B[i]){
                    dp[i+1][t] = dp[i][t - A[i]] + B[i];
                }
            }
            if(dp[i+1][t] < dp[i][t]){
                dp[i+1][t] = dp[i][t];
            }
        }
    }
    ll ans1 = 0;
    rep(t,0,T+1) ans1 = max(ans1, dp[N][t]);

    rep(i,0,N){
        rep(t,0,T){
            if(t - A[i] >= 0){
                if(dp2[i+1][t] < dp2[i][t - A[i]] + B[i]){
                    dp2[i+1][t] = dp2[i][t - A[i]] + B[i];
                    prev_w[i+1][t] = t - A[i];
                }
            }
            if(dp2[i+1][t] < dp2[i][t]){
                dp2[i+1][t] = dp2[i][t];
                prev_w[i+1][t] = t;
            }
        }
    }
    ll ans2 = 0;
    rep(t,0,T) ans2 = max(ans2, dp2[N][t]);
    // print(dp[N][T]);
    // print(dp2[N][T-1]);

    // 復元
    ll cur_w = T-1;
    map<ll,ll> used;
    rrep(i,N-1,0){
        if(prev_w[i+1][cur_w] == cur_w - A[i]){
            used[i]++;
        }
        cur_w = prev_w[i+1][cur_w];
    }
    // print(ans2);
    // printa(used, used.size());
    ll max_val = 0;
    rep(i,0,N){
        if(used[i] == 0){
            max_val = max(max_val, B[i]);
        }
    }
    ll ans = max(ans1, ans2 + max_val);
    print(ans);




}

Measured memory_bytes: 212608
s=list(input())
s.reverse()
s=''.join(s)

i=0
while i<len(s):
    if s[i:i+5]=='esare' or  s[i:i+5]=='maerd':
        i+=5
    elif s[i:i+6]=='resare':
        i+=6
    elif s[i:i+7]=='remaerd':
        i+=7
    else:
        print('NO')
        exit()
print('YES')

Measured memory_bytes: 46960