akhauriyash/Code-Regression huggingface dataset:
/* Dsingh_24 */
 
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define	endl		'\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define ios	    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
 
#define N  100005

int main()
{
	ios
	ll n;
	cin>>n;
	cout<<(3*n*n);
	return 0;
}

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

int main(){
  int n,m,q;
  int left[200001];
  int right[200001];
  bool flag[200001];
  cin >> n >> m >> q;
  for(int i=0;i<n;i++){
    left[i] = (i + n - 1) % n;
    right[i] = (i + 1) % n;
  }
  for(int i=0;i<n;i++){
    flag[i] = true;
  }
  int now = 0;
  while(m--){
    int a;
    cin >> a;
    if(a % 2 == 0){
      while(a--){
	now = right[now];
      }
    }
    else {
      while(a--){
	now = left[now];
      }
    }
    flag[now] = false;
    left[right[now]] = left[now];
    right[left[now]] = right[now];
    now = right[now];
  }
  for(int i=0;i<q;i++){
    int w;
    cin >> w;
    if(flag[w] == true) cout << "1" << endl;
    else cout << "0" << endl;
  }
}

Measured memory_bytes: 2908
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <cstdio>

using namespace std;

const double EPS=1e-10;
bool EQ(double a,double b){
  return abs(a-b)<EPS;
}

double dp[511][111][111];
int H,N,P,M,K;
bool A[511];
bool B[511][111][111];
//double cnt;

double dfs(int i,int j,int k,double cnt){
  if(dp[i][j][k]>=-0.5)return dp[i][j][k];
  if(i==H+1){
    // kは使い切っていなくても到達確率には問題ない？
    if(j==P&&k==0)return 1;
    return 0;
  }
  double res=0;
  // この高さに線が存在
  if(A[i]!=0){
    // 左へ移動
    if(j!=0&&B[i][j-1][j])
      res=dfs(i+1,j-1,k,cnt);
    // 右へ移動
    else if(j+1!=N&&B[i][j][j+1])
      res=dfs(i+1,j+1,k,cnt);
    // 移動なし
    else res=dfs(i+1,j,k,cnt);
  }
  else{
    if(k>=1){
      if(j+1!=N&&j!=0){
	// to left
	res+=dfs(i+1,j-1,k-1,cnt-1)*(k/cnt)*(1.0/(N-1));
	// to right
	res+=dfs(i+1,j+1,k-1,cnt-1)*(k/cnt)*(1.0/(N-1));
	// no move without bar
	if(cnt-k!=0)
	  res+=dfs(i+1,j,k,cnt-1)*((1.0*cnt-k)/cnt);
	// no move with bar
	res+=dfs(i+1,j,k-1,cnt-1)*(k/cnt)*(1.0*(N-3)/(N-1));
      }
      else if(j!=0){
	// to left
	res+=dfs(i+1,j-1,k-1,cnt-1)*(k/cnt)*(1.0/(N-1));
	// no move without bar
	if(cnt-k!=0)
	  res+=(dfs(i+1,j,k,cnt-1))*(1.0*cnt-k)/cnt;
	// no move with bar
	res+=dfs(i+1,j,k-1,cnt-1)*(k/cnt)*(1.0*(N-2)/(N-1));
      }
      else if(j+1!=N){
	// to right
	res+=dfs(i+1,j+1,k-1,cnt-1)*(k/cnt)*(1.0/(N-1));
	// no move without bar
	if(cnt-k!=0)
	  res+=(dfs(i+1,j,k,cnt-1))*(1.0*cnt-k)/cnt;
	// no move with bar
	res+=dfs(i+1,j,k-1,cnt-1)*(k/cnt)*(1.0*(N-2)/(N-1));
      }
    }
    else{
      // no move
      res+=dfs(i+1,j,k,cnt);
    }
  }
  return dp[i][j][k]=res;
}

int main(){

  while(cin>>H>>N>>P>>M>>K&&(H|N|P|M|K)){
    P--; 
    double cnt=H;
    memset(A,0,sizeof(A));
    memset(B,0,sizeof(B));
    for(int i=0;i<511;i++)
      for(int j=0;j<111;j++)
	for(int k=0;k<111;k++)dp[i][j][k]=-1;
    int a,b;
    for(int i=0;i<M;i++){
      cnt--;
      cin>>a>>b;
      A[a]=true;
      b--;
      B[a][b][b+1]=true;
      B[a][b+1][b]=true;
    }
    double res=0;
    for(int i=0;i<N;i++){
      if(!EQ(res,dfs(1,i,K,cnt))&&res<dfs(1,i,K,cnt))
	res=dfs(1,i,K,cnt);
    }
    printf("%.10f\n",res);
  }
  

  return 0;
}

Measured memory_bytes: 54000
x = int(input())

if 400 <= x <= 599:
    print('8')
elif 600 <= x <= 799:
    print('7')
elif 800 <= x <= 999:
    print('6')
elif 1000 <= x <= 1199:
    print('5')
elif 1200 <= x <= 1399:
    print('4')
elif 1400 <= x <= 1599:
    print('3')
elif 1600 <= x <= 1799:
    print('2')
elif 1800 <= x <= 1999:
    print('1')


Measured memory_bytes: 9180
import java.util.*;
import java.io.*;
import static java.lang.Math.*;

public class Main {
    public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int n = sc.nextInt();
		int[] a = new int[n];
		for(int i = 0; i < n; i++){
		    a[i] = sc.nextInt();
		}
		
		// 計算
		int result = Integer.MAX_VALUE;
		for(int i = -100; i <= 100; i++){
		    int tmp = 0;
		    for(int j = 0; j < n; j++){
		        tmp += (a[j]-i)*(a[j]-i);
		    }
		    result = min(result, tmp);
		}
		
		// 出力
		System.out.println(result);
	}
	
	public static class Scanner {
		private BufferedReader br; private StringTokenizer tok;
		public Scanner(InputStream is) throws IOException { br = new BufferedReader(new InputStreamReader(is));}
		private void getLine() throws IOException { while(!hasNext()) tok = new StringTokenizer(br.readLine());}
		private boolean hasNext() { return tok != null && tok.hasMoreTokens();}
		public String next() throws IOException { getLine(); return tok.nextToken();}
		public int nextInt() throws IOException { return Integer.parseInt(next());}
		public long nextLong() throws IOException { return Long.parseLong(next());}
		public double nextDouble() throws IOException { return Double.parseDouble(next());}
	}
}



Measured memory_bytes: 25400
N = int(input())
A = list(map(int, input().split()))
asset = 1000
stock = 0

for i in range(N):
    if i == N - 1:
        asset += stock * A[i]
        stock = 0
    else:
        if A[i] < A[i + 1]:
            r, v = divmod(asset, A[i])
            # print(r, v)
            stock += r
            asset = v
        else:
            asset += stock * A[i]
            stock = 0
print(asset)


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

int main(){
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    while(1){
        c = c - b;
        a = a - d;
        if (c <= 0){
            cout << "Yes" << endl;
            break;
        }else if ( a <= 0){
            cout << "No" << endl;
            break;
        }
    }
    return 0;
}

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

using LD = long double;
const LD PI = acos(-1);

int main() {
  LD m, t;
  cin >> m >> t;

  const LD am = 2.0 * PI * 60.0 / 2500000.0;
  const LD ak = 2.0 * PI / 2.0 / 60.0;
  const LD m0 = m * PI / 180.0;
  const LD Tm = 380000;
  const LD Tk = 1800 + 100;
  const LD R = 1800;

  const LD dt = 0.01;
  LD ans = 0;
  for(LD i = 0; i <= t; i += dt) {
    LD xm, ym, zm;
    xm = Tm * cos(m0 + am * i);
    ym = Tm * sin(m0 + am * i);
    zm = 0;
    LD xk, yk, zk;
    xk = xm - Tk * sin(ak * i);
    yk = ym;
    zk = zm + Tk * cos(ak * i);
    LD a = xk * xk + yk * yk + zk * zk;
    LD b = xk * xm + yk * ym + zk * zm;
    LD c = Tm * Tm - R * R;
    LD D = b * b - a * c;
    if(D > 0 && (b + sqrt(D)) / a < 1) ans += dt;
  }
  cout << setprecision(8) << fixed << ans << endl;
}

Measured memory_bytes: 3508
#include <stdio.h>

int main(void) {
	int numbers_num;
	int start,prev,now;
	int i;
	int isfirst;
	while(1) {
		scanf("%d",&numbers_num);
		if(numbers_num==0)break;
		scanf("%d",&start);
		prev=start;
		isfirst=1;
		for(i=1;i<numbers_num;i++) {
			scanf("%d",&now);
			if(prev+1!=now) {
				if(!isfirst)putchar(' ');
				printf("%d",start);
				if(start<prev)printf("-%d",prev);
				start=now;
				isfirst=0;
			}
			prev=now;
		}
		if(!isfirst)putchar(' ');
		printf("%d",start);
		if(start<prev)printf("-%d",prev);
		putchar('\n');
	}
	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
using namespace std;

// #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define ll long long int
#define ld long double
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>

vector <ll> v;
ll dp[105][100005][2];

ll fep(ll x, ll y, ll mod)
{ll res=1;while(y>0){if(y&1)res=(res*x)%mod;
    y=y>>1;x=(x*x)%mod;}return res%mod;}

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

	ll n,i,m=1000000007,j,k,x,y,a,b;
	string s;
	
	cin >> n >> k;
	v.pb(0);
	for(i=0;i<n;i++)
	{
		cin >> x;
		v.pb(x);
	}
	dp[0][0][0]=1;
	for(j=0;j<=k;j++)
		dp[0][j][1]=1;
	for(i=1;i<=n;i++)
	{
		for(j=0;j<=k;j++)
		{
			dp[i][j][0]=dp[i-1][j][1];
			if(j-v[i]-1>=0)
				dp[i][j][0]-=dp[i-1][j-v[i]-1][1];
			dp[i][j][1]=dp[i][j][0];
			if(j)
				dp[i][j][1]+=dp[i][j-1][1];
			dp[i][j][0]=(dp[i][j][0]+2*m)%m;
			dp[i][j][1]=(dp[i][j][1]+2*m)%m;
//			cout << dp[i][j][0] << " ";
		}
//		cout << endl;
	}
	cout << dp[n][k][0];

	return 0;
}


Measured memory_bytes: 160000
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        long x = sc.nextLong();
        long y = sc.nextLong();
        sc.close();
        boolean ebishu = true;
        for(int i = 1 ; i <= 3 && ebishu ; i++){
            if((x * i) % y != 0){
                System.out.println(i * x);
                ebishu = false;
            }
        }
        if(ebishu){
            System.out.println(-1);
        }
    }
}

Measured memory_bytes: 35236
#include<cstdio>
#include<cstring>
const int mod=1e9+7;
#define max(a,b) (a>b?a:b)
int matmod(long long v,long long k){
	long long ans=1ll;
	for(;k;k>>=1){
		if(k&1) ans=(ans*v)%mod;
		v=(v*v)%mod;
	}
	return (int) ans;
}
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*10+ch-'0';ch=getchar();}
    return x*f;
}
char num[5005];
int f[5005][5005],n;
int main(){
	n=read();
	scanf("%s",num);
	int len=strlen(num);
	int pu=1;
	for(int i=1;i<=len;i++) pu=(pu*2)%mod;
	pu=matmod(pu*1ll,mod-2);
	f[0][0]=1;
	for(int i=0;i<n;i++)
		for(int j=0;j<=i;j++){
			f[i+1][j+1]=(f[i+1][j+1]+2*f[i][j]%mod)%mod;
			f[i+1][max(j-1,0)]=(f[i+1][max(j-1,0)]+f[i][j])%mod;
		}
	long long ans=((long long) pu)*((long long) f[n][len])%mod;
	printf("%lld",ans);
	return 0;
}


Measured memory_bytes: 96384
#include <iostream>
#include <sstream>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cassert>
using namespace std;

typedef long long LL;
typedef unsigned long long ULL;

const double PI = 3.14159265358979323846264338327950;
const LL MOD = 1000000007;

#define PrintLn(X) cout << X << endl
#define Loop(n) for(int loop_ = n; loop_; --loop_)
#define Rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define For(i, a, b) for(int i = a; i < (int)(b); ++i)

int main(void)
{
	int a, b;
	cin >> a >> b;
	if(a > 0){
		PrintLn("Positive");
	}else if(a <= 0 && 0 <= b){
		PrintLn("Zero");
	}else{
		if((a - b) % 2){
			PrintLn("Positive");
		}else{
			PrintLn("Negative");
		}
	}
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextInt();
        long d = sc.nextInt();
        int ans = 0;
        for(int i = 0;i<n;i++){
            long x = sc.nextInt();
            long y = sc.nextInt();
            if((x*x+y*y)<=d*d){
                ans++;
            }
        }
        System.out.println(ans);
    }
    
}

Measured memory_bytes: 60068
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#define llong long long
#define INF (__INT32_MAX__ / 2)
#define EPS 10e-8
#define MAX_N 5000

using namespace std;
typedef pair<int, int> ipair;
llong modulo(llong left, llong right) { return (left % right + right) % right; }

int N;
string S;
int len[MAX_N + 20];
int main(int argc, char **argv) {
    cin >> N >> S;
    S += "#";
    N++;

    int res = 0;
    for(int i = 0; i < N; ++i)
        for(int j = i + 1; j < N; ++j) {

            if(S[i] == S[j])
                len[j - i]++;
            else {
                int l = len[j - i];
                l = min(l, j - i);
                res = max(res, l);

                len[j - i] = 0;
            }

        }
    
    cout << res << endl;
}

Measured memory_bytes: 384
#include <stdio.h>
int main(void){
  int a,b,c;
  
  scanf("%d %d %d",&a,&b,&c);
  
  if( (a==5&&b==5&&c==7) || (a==5&&b==7&&c==5) || (a==7&&b==5&&c==5) ){
      printf("YES");
  }else{
      printf("NO");
  }
  
  return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <assert.h>
#include <sys/time.h>
#include <fstream>
#include <iomanip>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define REP(i,n)  FOR(i,0,n)
#define each(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i)
#define EACH(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define deb(x) cerr << #x << " = " << (x) << " , ";
#define debl cerr << " (L" << __LINE__ << ")"<< endl;
#define sz(s) (int)((s).size())


#define clr(a) memset((a),0,sizeof(a))
#define nclr(a) memset((a),-1,sizeof(a))
#define pb push_back
#define INRANGE(x,s,e) ((s)<=(x) && (x)<(e))
#define MP(x,y) make_pair((x),(y))

double pi=3.14159265358979323846;

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;

template<typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& z){
	os << "[ ";
	REP(i,z.size())os << z[i] << ", " ;
	return ( os << "]" << endl);
}

template<typename T> std::ostream& operator<<(std::ostream& os, const set<T>& z){
	os << "set( ";
	EACH(p,z)os << (*p) << ", " ;
	return ( os << ")" << endl);
}

template<typename T,typename U> std::ostream& operator<<(std::ostream& os, const map<T,U>& z){
	os << "{ ";
	EACH(p,z)os << (p->first) << ": " << (p->second) << ", " ;
	return ( os << "}" << endl);
}

template<typename T,typename U> std::ostream& operator<<(std::ostream& os, const pair<T,U>& z){
	return ( os << "(" << z.first << ", " << z.second << ",)" );
}

double get_time(){
	struct timeval tv;
	gettimeofday(&tv, NULL);
	return tv.tv_sec + tv.tv_usec*1e-6;
}

typedef unsigned int uint32_t;
struct RND{
	uint32_t x;
	uint32_t y;
	uint32_t z;
	uint32_t w;
	RND(){
		x=123456789;
		y=362436069;
		z=521288629;
		w=88675123;
	}
	void init(int seed){
		x=123456789;
		y=362436069;
		z=521288629;
		w=seed+100;
		REP(i,10)get();
	}
	uint32_t get(){
		uint32_t t;
		t=x^(x<<11);
		x=y;y=z;z=w;
		w=(w^(w>>19))^(t^(t>>8));
		return w;
	}
};
RND rnd;

ll double_to_ll(double d){
	if(d>0)return d+0.5;
	return d-0.5;
}

void _main(istream &inp){
	string s;
	inp >> s;
	cout << string(s.begin(), s.begin()+4) <<" " << string(s.begin()+4, s.end()) << endl;

}

int main(){
	if(0){
		ifstream ifs("test.txt");
		_main(ifs);
	}
	else{
		_main(cin);
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n,m;
  cin >> n >> m;
  string s[n];
  for(int i=0; i<n; i++) cin >> s[i];
  int ans=n*m;
  for(int x=1; x<n; x++) {
    for(int y=x+1; y<n; y++) {
      int cnt=0;
      for(int i=0; i<n; i++) {
        for(int j=0; j<m; j++) {
          if(i<x&&s[i][j]!='W') cnt++;
          if(i>=x&&i<y&&s[i][j]!='B') cnt++;
          if(i>=y&&s[i][j]!='R') cnt++;
        }
      }
      ans=min(ans,cnt);
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1212
#include <stdio.h>

int main(void) {
	char S[256];
	scanf("%s", S);

	int nagasa;
	for (int i = 0; ; ++i) {
		if (S[i] == 0) {
			nagasa = i;
			break;
		}
	}
	char kekka[256];
	sprintf(kekka, "%c%d%c", S[0], nagasa - 2, S[nagasa - 1]);

	printf("%s\n", kekka);
}

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



int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout<<setprecision(30)<<fixed;
	
	int n;
	cin>>n;
	if(n>=30)
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
	return 0;
}





Measured memory_bytes: 3656
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;
 
int main() {
    int N, M, K; cin >> N >> M >> K;
    vector<int> D(M);
    for(int i=0; i<M; i++) cin >> D[i], D[i]--;

    vector<int> id(N, -1);
    for(int i=0; i<M; i++) id[ D[i] ] = i;
    
    vector< vector<int> > to(N, vector<int>(K));
    for(int i=0; i<N; i++) {
        for(int j=0; j<K; j++) {
            cin >> to[i][j]; to[i][j]--;
        }
    }

    vector<int> dp(1<<M, INF);
    dp[(1<<M)-1] = 0;
    queue< pair<int, int> > que;
    que.emplace((1<<M)-1, 0);

    while(que.size()) {
        int bit, cost; tie(bit, cost) = que.front(); que.pop();
        if(dp[bit] < cost) continue;
        for(int i=0; i<K; i++) {
            int nbit = 0;
            for(int x=0; x<M; x++) {
                if(!(bit >> x & 1)) continue;
                int p = to[ D[x] ][i];
                if(id[p] >= 0) nbit |= (1 << id[p]);
            }
            if(dp[nbit] > dp[bit] + 1) {
                dp[nbit] = dp[bit] + 1;
                que.emplace(nbit, dp[nbit]);
            }
        }
    }
    printf("%d\n", dp[0]);
    return 0;
}



Measured memory_bytes: 3572
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
//#include <algorithm>
#include <vector>

int main(int argc, char* argv[])
{
    long a[2], b[2];
    scanf("%ld %ld %ld %ld", &(a[0]), &(a[1]), &(b[0]), &(b[1]) );

    long vec[2] = {b[0]-a[0], b[1]-a[1]};
    long c[2] = {b[0]-vec[1], b[1]+vec[0]};
    long d[2] = {c[0]-vec[0], c[1]-vec[1]};

    printf("%d %d %d %d\n", c[0], c[1], d[0], d[1]);

    return 0;
}





Measured memory_bytes: 128
#include <stdio.h>
int main(){
 
  int a,b,i,d;
 
  while(1){
  scanf("%d %d",&a,&b);
if(a==0 && b==0)break;
 
  for(i=0;i<a;i++){

    for(d=0;d<b;d++)
{
    printf("#");
  } 
  printf("\n");
 
  
  }
  printf("\n");
  }
  
 
  return 0;
  }



Measured memory_bytes: 2048
#include<iostream>
using namespace std;
bool f(int a)
{
	while(a%3<1)a/=3;
	while(a%5<1)a/=5;
	return __builtin_popcount(a)==1;
}
main()
{
	int m,n;
	while(cin>>m,m)
	{
		cin>>n;int cnt=0;
		for(;m<=n;m++)cnt+=f(m);
		cout<<cnt<<endl;
	}
}



Measured memory_bytes: 3120
fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readIntList() = readLine()!!.split(" ").map(String::toInt)
fun readLongList() = readLine()!!.split(" ").map(String::toLong)
fun <T> Array<Array<T>>.print() {
    this.forEach {
        println(it.joinToString(" "))
    }
}

fun main() {
    val (a, b, c, k) = readIntList()
    println(
        when {
            a >= k -> k
            a + b >= k -> a
            else -> a - (k - a - b)
        }
    )
}

Measured memory_bytes: 36372
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
const double PI = 3.141592653589793238;
const double EPS = 1e-10;
typedef pair<int, int> P;
int main() {
	ll H, W, N;
	cin >> H >> W >> N;
	set<P> S;
	set<P> T;
	for (int i = 0; i < N; i++) {
		int x, y;
		cin >> y >> x;
		x--; y--;
		S.insert(P(x, y));
		for (int dx = -1; dx <= 1; dx++) {
			for (int dy = -1; dy <= 1; dy++) {
				int nx = x + dx;
				int ny = y + dy;
				if (1 > nx || nx >= W - 1 || 1 > ny || ny >= H - 1) continue;
				T.insert(P(nx, ny));
			}
		}
	}
	ll ans[10] = {};
	ll sum = 0;
	for (auto p : T) {
		int x = p.first, y = p.second;
		int cnt = 0;
		for (int dx = -1; dx <= 1; dx++) {
			for (int dy = -1; dy <= 1; dy++) {
				if (S.find(P(x + dx, y + dy)) != S.end()) cnt++;
			}
		}
		ans[cnt]++;
		sum++;
	}
	ans[0] = (H - 2)*(W - 2) - sum;
	for (int i = 0; i < 10; i++) {
		cout << ans[i] << endl;
	}
}


Measured memory_bytes: 47104
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<cmath>
#include<cstdio>
#include<tuple>
#include<bitset>
#include<map>

using namespace std;
//#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ALL(x) x.begin(),x.end()
using ll = long long;
using lint = long long;
typedef pair<int,int> P;
const lint inf=1e9+7;
const int MOD=1000000007;
struct Point{
    int x;
    int y;
    void build(int a,int b){
      x=a;y=b;
    }
    vector<Point> next;
    void get_next(int const& n){
      vector<int> dx={1,0,-1,0};
      vector<int> dy={0,1,0,-1};
      rep(i,4){
        int nx=x+dx[i];
        int ny=y+dy[i];
        if(nx>0&&nx<=n){
          if(ny>0&&ny<=n){
            Point buf;
            buf.build(nx,ny);
            next.push_back(buf);
          }
        }
      }
    }
};

signed main(){
  int n;cin>>n;
  vector<int> p(n*n);
  rep(i,n*n)cin>>p[i];
  vector<vector<int>> cost(n+5,vector<int>(n+5,inf));
  rep1(i,n){
    rep1(j,n){
      int bufy=min(i-1,n-i);
      int bufx=min(j-1,n-j);
      cost[i][j]=min(bufy,bufx);
    }
  }
  int res=0;
  vector<vector<int>> seki(n+5,vector<int>(n+5,1));
  vector<int> dx={1,0,-1,0};
  vector<int> dy={0,1,0,-1};
  for(int l=0;l<n*n;++l){
    int val=p[l];
    int x=(val-1)%n+1;
    int y=(val-1)/n+1;
    seki[y][x]=0;
    res+=cost[y][x];
    queue<P> que;
    que.push({x,y});
    while(!que.empty()){
      P buf=que.front();que.pop();
      rep(i,4){
        int nx=buf.first+dx[i];
        int ny=buf.second+dy[i];
        if(nx>0&&nx<=n&&ny>0&&ny<=n){
          if(cost[ny][nx]>cost[buf.second][buf.first]+seki[buf.second][buf.first]){
            cost[ny][nx]=cost[buf.second][buf.first]+seki[buf.second][buf.first];
            que.push({nx,ny});
          }
        }

      }
    }
  }
  cout<<res<<"\n";
  return 0;
}


Measured memory_bytes: 6112
#include<bits/stdc++.h>
using namespace std;
#define ll long long                                    // long long省略
#define pb push_back                                    // push_back省略
#define mp make_pair                                    // make_pair省略
#define fi first                                        // first省略
#define se second                                       // second省略
#define itn int                                         // int誤字保険
#define count cout                                      // cout誤字保険
#define vecotr vector                                   // vector誤字保険
#define ednl endl                                       // endl誤字保険
#define opt() cin.tie(0); ios::sync_with_stdio(false)   // 入出力速度改善

#define rep(i,l,r) for(ll i=(l);i<(r);i++)               // 範囲[l, r)で刻み1のfor文(順方向)
#define repp(i,l,r,k) for(ll i=(l);i<(r);i+=(k))         // 範囲[l, r)で刻みkのfor文(順方向)
#define rrep(i,l,r) for(ll i=(r-1);i>=(l);i--)           // 範囲[l, r)で刻み1のfor文(逆方向)
#define rrepp(i,l,r,k) for(ll i=(r-1);i>=(l);i-=(k))     // 範囲[l, r)で刻みkのfor文(逆方向)
#define all(x) (x).begin(), (x).end()                   // vectorのポインタ位置指定用
#define max(p,q)((p)>(q)?(p):(q))                       // max拡張
#define min(p,q)((p)<(q)?(p):(q))                       // min拡張
#define bit(n,m)(((n)>>(m))&1)                          // 変数nのm番目のbitを取り出す

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int dy[]={0, 1, 0, -1};                                 // 4方向近傍
int dx[]={1, 0, -1, 0};                                 // 4方向近傍

#define INF ((1LL<<62)-(1LL<<31))
//#define MOD 998244353
#define MOD 1000000007
#define invp(a,p) pom(a,p-2,p)

////////////////////////////////////////////////////////////////////////////////////////
int main(){
    string s;cin>>s;
    ll res = 0;
    char c = '0';
    rep(i,0,s.size()){
        if(c == s[i]){
            res++;
            c = '0';
            i += 1;
        }else{
          	if(i == s.size()-2 && s[i] == s[i+1]) continue;
            res++;
            c = s[i];
        }
    }
    cout << res << endl;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=5e18;

int main() {
  ll n;
  cin >> n;
  vec p(n);
  for(ll i=0;i<n;i++) cin >> p[i];
  ll cnt=0;
  for(ll i=0;i<n;i++) {
    if(p[i]==i+1) {
      cnt++;
      i++;
    }
  }
  cout << cnt << endl;
}

Measured memory_bytes: 1024
n = int(input())
s = input()
t = input()

a = []

for i in range(n+1):
    a.append(s+t[n-i:])

for i in range(len(a)):
    if s==a[i][:n] and t==a[i][len(a[i])-n:]:
        print(len(a[i]))
        exit()

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

int main() {
  int n;
  cin >> n;
  int p[51];
  int j[51];

  for (int i = 0; i < n; i++) {
    cin >> p[i];
    j[i] = p[i];
  }

  sort(p, p + n);
  int counter = 0;
  for (int i = 0; i < n; i++) {
    if (p[i] != j[i]) {
      counter++;
    }
  }

  if (counter <= 2) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }

  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <iostream>
#include <set>

// などの必要なインクルードファイルすべて（3章の各標準ライブラリの説明でそれぞれ書いています）
using namespace std;



int N,M,Q;

int a[50][4];

int A[10];

int t,c;

void tokuten(int k){

int i,j;

    
        if(k==N){
	
	  c=0;
	  
	    for(j = 0; j < Q; j++){
	      
	      if(  (A[a[j][1]-1] - A[a[j][0]-1]) == a[j][2] ){
	      
	        c=c+a[j][3];
	      
              }
	      
	    }
	
	  if((t<c)){ t = c; }          //最高点dしたら入れ替え
	  
	}else{
	
	     if(k==0){
	     
		for (i = 1; i < M+1; i++){
	         

			 A[k]=i;
			 
			 tokuten(k+1);

		}

	     }else{
	
		for (i = A[k-1]; i < M+1; i++){
		
			 A[k]=i;
			 
			 tokuten(k+1);
	        }
	       
	     }  

        }
}

int main(void){           


int i,j;

t=0;

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

for (i = 0; i < Q; i++){

	scanf("%d%d%d%d", &a[i][0] ,&a[i][1] ,&a[i][2] ,&a[i][3]);
	
}

for (i = 0; i < N; i++){

	A[i]=1;
}

tokuten(0);

printf("%d",t);

}

Measured memory_bytes: 3728
//        THIS IS MY NINJA WAY
#include<bits/stdc++.h>
#include<ctime>
#include<vector>
#include<algorithm>

#define str string
#define dbl double
#define ll long long
#define vl vector<ll> 
#define vs vector<str>
#define pll  pair<ll,ll> 
#define vll vector<pll>
#define sl set<ll>
#define pb push_back
#define mp make_pair
#define ub upper_bound
#define lb lower_bound
#define ff first
#define ss second
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL));
#define fr(i,a,b) for(long long i=a; i<b; i++)
#define nfr(i,a,b) for(long long i=a; i<=b; i++)
#define psl pair<str,ll>
#define pls pair<ll,str>
#define pss pair<str,str>
#define ALL(a) a.begin(),a.end()
#define stl stack<ll>
#define coml complex<ll>
#define INF 0x3f3f3f3f3f3f3f3f
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
const ll MOD = 1e9+7;


using namespace std;
int main()
{
	fast
	/*#ifndef ONLINE_JUDGE
		freopen("input.txt", "r" , stdin);
		freopen("output.txt", "w" , stdout);
	#endif*/
    
   ll n,k;
   cin>>n>>k;
   vl v(n);
   fr(i,0,n)cin>>v[i];
   vl dp(n,INF);
   dp[0]=0;
   dp[1]=abs(v[1]-v[0]);
   fr(i,2,n){
   		fr(j,1,k+1){
   			if(i>=j)
   			dp[i]=min(dp[i],dp[i-j]+abs(v[i]-v[i-j]));
   		}
   }
   cout<<dp[n-1];
   return 0;
}

Measured memory_bytes: 1792
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;


 class Dice {
	private int top;
	private int front;
	private int right;
	private int left;
	private int back;
	private int bottom;

	public Dice() {
		// TODO ?????????????????????????????????????????????????????????
	}

	public Dice(int top, int front, int right, int left, int back, int bottom) {
		this.top = top;
		this.front = front;
		this.right = right;
		this.left = left;
		this.back = back;
		this.bottom = bottom;
	}

	public void setDice(int top, int front, int right, int left, int back, int bottom) {
		this.top = top;
		this.front = front;
		this.right = right;
		this.left = left;
		this.back = back;
		this.bottom = bottom;
	}

	public void rollDice(String str){
		if(str.equals("N"))rollNorth();
		if(str.equals("S"))rollSouth();
		if(str.equals("E"))rollEast();
		if(str.equals("W"))rollWest();
	}

	public void rollNorth(){
		setDice(front,bottom,right,left,top,back);
	}

	public void rollSouth(){
		setDice(back,top,right,left,bottom,front);
	}

	public void rollEast(){
		setDice(left,front,top,bottom,back,right);
	}

	public void rollWest(){
		setDice(right,front,bottom,top,back,left);
	}

	public Map<String,Integer> getDice(){
		Map<String,Integer> dice = new HashMap<String,Integer>();
		dice.put("top", top);
		dice.put("front", front);
		dice.put("right", right);
		dice.put("left", left);
		dice.put("back", back);
		dice.put("bottom", bottom);
		return dice;
	}


	public int getTop() {
		return top;
	}


	public void setTop(int top) {
		this.top = top;
	}
	public int getBottom() {
		return bottom;
	}
	public void setBottom(int bottom) {
		this.bottom = bottom;
	}
	public int getFront() {
		return front;
	}
	public void setFront(int front) {
		this.front = front;
	}
	public int getBack() {
		return back;
	}
	public void setBack(int back) {
		this.back = back;
	}
	public int getRight() {
		return right;
	}
	public void setRight(int right) {
		this.right = right;
	}
	public int getLeft() {
		return left;
	}
	public void setLeft(int left) {
		this.left = left;
	}


}

public class Main {
	public static void main(String[] args){

	Scanner scan = new Scanner(System.in);
	Dice dice = new Dice(scan.nextInt(),scan.nextInt(),scan.nextInt(),scan.nextInt(),scan.nextInt(),scan.nextInt());

		String str = scan.next();
		for(int i=0;i<str.length();i++){
			dice.rollDice(String.valueOf(str.charAt(i)));
		}

		Map<String,Integer> dicenum =dice.getDice();
		
		System.out.println(dicenum.get("top"));
		

	}
}

Measured memory_bytes: 26240
#include <algorithm>
#include <iostream>
#include <stack>
#include <queue>
#include <cmath>
#include <string>
#include <iterator>
#include <map>
#include <set>
#include <iomanip>
#include <vector>
#include <cstdint>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Graph = vector<vector<int>>;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
#define rep(i, N) for(int i = 0; i < N; i++)
#define rep2(i, l, r) for (ll i = (ll)l; i < (ll)(r); i++)
#define INF 1000000000000000
#define MAX 200001

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
const ll MOD = 1000000007;

template <typename T > inline string toString(const T &a) {ostringstream oss; oss << a; return oss.str();};

int main(){
    ll A, B, K;
    cin >> A >> B >> K;
    rep(i,K){
        if(i % 2 == 0){
            if(A % 2 != 0) A--;
            B += A/2;
            A /= 2;
        }
        else{
            if(B % 2 != 0) B--;
            A += B/2;
            B /= 2;
        }
    }
    cout << A << ' ' << B << endl;
}

Measured memory_bytes: 3632
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = br.readLine();
		String[] jal = new String[3];
		jal = line.split(" ");
		if((jal[0].substring(jal[0].length()-1)).equals(jal[1].substring(0, 1)))
			if((jal[1].substring(jal[1].length()-1)).equals(jal[2].substring(0, 1)))
				{System.out.println("YES");}
			else
			{System.out.println("NO");}
		else
		{System.out.println("NO");}

	}
}


Measured memory_bytes: 22484
#include <iostream>

using namespace std;

void insertionSort(int A[], int N){
	int key;
	
	for (int p = 0; p < N - 1; p++){
		cout << A[p] << " ";
	}
	cout << A[N - 1] << endl;

	for (int i = 1; i < N; i++){
		key = A[i];
		int j = i - 1;
		while (j >= 0 && A[j] > key){
			A[j + 1] = A[j];
			j--;
		}
		A[j + 1] = key;
		for (int p = 0; p < N - 1; p++){
			cout << A[p] << " ";
		}
		cout << A[N - 1] << endl;
	}
}

int main(){

	int N;
	int A[100];

	cin >> N;

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

	insertionSort(A, N);

	return 0;
}

Measured memory_bytes: 1160
import java.util.*;
class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		while(n-->0) {
			char[] num = in.next().toCharArray();
			Arrays.sort(num);
			String mx = "";
			String mn = "";
			for(int i = 0; i < num.length; i++) {
				mn+=num[i];
				mx+=num[num.length-i-1];
			}
			System.out.println(Integer.parseInt(mx)-Integer.parseInt(mn));
		}
	}
}

Measured memory_bytes: 12000
#include <iostream>
#include <vector>
#include <algorithm>

struct Weighted_Union_Find {
    std::vector<int> par;
    std::vector<int> rank;
    std::vector<long long> wdiff;
    //初期化
    void init( int n ) {
        par.resize( n );
        rank.resize( n );
        wdiff.resize( n );
        for ( int i = 0; i < n; ++i ) {
            par[ i ] = i;
            rank[ i ] = 0;
            wdiff[ i ] = 0;
        }
    }
    
    //木の根を探す
    int find( int s ) {
        if ( par[ s ] == s ) {
            return s;
        }
        int r = find(par[ s ]);
        wdiff[s] += wdiff[par[s]];
        return par[s] = r;
    }
    
    long long weight(int x) {
        find(x); // 経路圧縮
        return wdiff[x];
    }

    long long diff(int x, int y) {
        return weight(y) - weight(x);
    }

    //結合
    bool unite( int x, int y, long long w ) {
        w += weight(x);
        w -= weight(y);
        x = find( x );
        y = find( y );
        if ( x == y ) {
            return false;
        }
        if ( rank[ x ] < rank[ y ] ) {
            std::swap(x, y);
            w = -w;
        }
        if ( rank[x] == rank[y] ) ++rank[x];
        par[y] = x;
        wdiff[y] = w;
        return true;
    }
    
    //二つの数の根が同じかどうか
    bool same( int x, int y ) {
        return find( x ) == find( y );
    }
    
    //サイズを返す
    unsigned int size() {
        return par.size();
    }
};

using namespace std;

int main(){
    int n, m;
    cin >> n >> m;
    Weighted_Union_Find wuf;
    wuf.init(n);
    while(m--){
        int l, r, d;
        cin >> l >> r >> d;
        if(!wuf.unite(l - 1, r - 1, d) && wuf.diff(l - 1, r - 1) != d){
            cout << "No\n";
            return 0;
        }
    }
    cout << "Yes\n";
}

Measured memory_bytes: 1920
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <cmath>
#define REP(i,n) for(int i=0;i<(n);++i)
using namespace std;
using ll = long long;
constexpr int INF = 1e9;
constexpr int MOD = 1e9 + 7;
template<class T> inline void chmax(T &a,T b){if(a<b)a=b;}
template<class T> inline void chmin(T &a,T b){if(a>b)a=b;}

int main(){
    cin.tie(0); ios_base::sync_with_stdio(false);
    string s,t;cin >> s >> t;
    sort(s.begin(),s.end());
    sort(t.rbegin(),t.rend());
    if(s<t) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
    int h, w;
    int i, j;

    while(1){
        scanf("%d %d", &h, &w);

        if (h == 0 && w == 0) break;

        for (i = 0; i < w; i++)
            printf("#");
        printf("\n");

        for (i = 0; i < h - 2; i++){
            printf("#");
            for (j = 0; j < w - 2; j++){
                printf(".");
            }
            printf("#\n");
        }

        for (i = 0; i < w; i++)
            printf("#");
        printf("\n\n");
    }

    return 0;
}

Measured memory_bytes: 588
#include<stdio.h>
#include<string.h>
 
 
int main(){
  char str;
  scanf("%s",&str);
  
  if(strcmp("SUN",&str) == 0)
    puts("7");
  else if(strcmp("MON",&str) == 0)
    puts("6");
  else if(strcmp("TUE",&str) == 0)
    puts("5");
  else if(strcmp("WED",&str) == 0)
    puts("4");
  else if(strcmp("THU",&str) == 0)
    puts("3");
  else if(strcmp("FRI",&str) == 0)
    puts("2");
  else if(strcmp("SAT",&str) == 0)
    puts("1");
  return 0;
}

Measured memory_bytes: 128
import numpy as np

a=np.array([[int(x) for x in input().split()]for y in range(3)],dtype=np.int64)
#print(a)
for i in range(3):
    for j in range(0,3):
        a[i][j]-=a[i][2]

#print(a)
for j in range(3):
    for i in range(1,3):
        if(a[i][j]!=a[0][j]):
            print("No")
            exit(0)
print("Yes")

Measured memory_bytes: 12424
from collections import deque
X,Y,A,B,C = map(int,input().split())
p = list(map(int,input().split()))
q = list(map(int,input().split()))
r = list(map(int,input().split()))
p.sort()
q.sort()
r.sort()
p = deque(p)
q = deque(q)
r = deque(r)
p.appendleft(0)
q.appendleft(0)
r.appendleft(0)


a = p.pop()
b = q.pop()
c = r.pop()
x = 0
y = 0
ans = 0
for i in range(X+Y):
    if x < X and y < Y:
        if a >= b and a >= c:
            ans += a
            x += 1
            a = p.pop()
        elif b >= c:
            ans += b
            y += 1
            b = q.pop()
        else:
            ans += c
            c = r.pop()
    elif x < X:
        if a >= c:
            ans += a
            x += 1
            a = p.pop()
        else:
            ans += c
            c = r.pop()
    else:
        if b >= c:
            ans += b
            y += 1
            b = q.pop()
        else:
            ans += c
            c = r.pop()

print(ans)


Measured memory_bytes: 23616
mod = 10**9 + 7

N = int(input())

# NG = {AGC,GAC,ACG,ATGC,AGGC,AGTC}
# (A,C,G,T) = (0,1,2,3)
# dp[i][j]: 長さiの条件を満たす文字列のうち、末尾がjとなるものの場合の数
# 初期条件:dp[1] = [1,1,1,1]
# 答え: dp[N][0] + dp[N][1] + dp[N][2] + dp[N][3]

dp = [[0]*4 for _ in range(N+1)]

# A,C,G,T それぞれ1通りずつ
dp[1] = [1]*4


for i in range(2,N+1):
    for j in range(4):
        # ひとまず長さi-1の文字列にjを足して良いとする　
        dp[i][j] += sum(dp[i-1])
        dp[i][j] %= mod
    # ダメなパターンを引いて補正する
    # 後ろ二文字が"AG","GA"の場合はCを付け足せない
    # ~AG, ~GA となる場合の数はそれぞれ dp[i-2][0]*1とdp[i-2][2]*1
    dp[i][1] -= dp[i-2][0] + dp[i-2][2]
     # 後ろ二文字が"AC"の場合はGを付け足せない
    # ~AC となる場合の数は dp[i-2][0] (- dp[i-3][2])
    dp[i][2] -= dp[i-2][0]
    if i >= 3:
        # 後ろ三文字が"ATG","AGG","AGT"となる場合はCを付け足せない
        # ~ATG, ~AGG, ~AGT となる場合の数は 合わせて dp[i-3][0]*3
        dp[i][1] -= dp[i-3][0]*3
        # ----------------------注意--------------------------
        # dp[i-2][0]は後ろから~ACとなる場合の数だから
        # これには~GACとなる場合の数も含まれている
        # しかし~GACというのは既に除外しているので
        # ~ACとなる場合の数は dp[i-2][0]-dp[i-3][2]
        # 余分に引いている分を+dp[i-3][2]することで補正
        dp[i][2] += dp[i-3][2]

ans = sum(dp[N]) % mod
print(ans)

Measured memory_bytes: 3064
//https://beta.atcoder.jp/contests/abc115/tasks/abc115_d
#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 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; }};

int N;
LL X;
LL sum[100];
LL niku[100];
int main(){
    cin>>N>>X;
    sum[0]=1;
    niku[0]=1;
    for(int i:range(1,60)){
        sum[i]=3+2*sum[i-1];
        niku[i]=1+2*niku[i-1];
    }
    LL ret=0;
    while(N>=0){
        if(X<=1){
            break;
        }
        else if(X<2+sum[N-1]){
            N--;
            X--;
        }
        else if(X<sum[N]){
            ret+=1+niku[N-1];
            X-=2+sum[N-1];
            N--;
        }
        else{
            ret+=niku[N];
            X=0;
            break;
        }
    }
    if(N==0&&X==1)ret++;
    cout<<ret<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
#define f0r(a, b) for (long long a = 0; a < (b); a++)
#define f1r(a, b, c) for (long long a = (b); a < (c); a++)
#define f0rd(a, b) for (long long a = (b); a >= 0; a--)
#define f1rd(a, b, c) for (long long a = (b); a >= (c); a--)
#define ms(arr, v) memset(arr, v, sizeof(arr))
#define pb push_back
#define mp make_pair
#define f first
#define s second
using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vpl = vector<pll>;
 
void fio() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); 
  cout.tie(0);
}
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const long double pi = 3.14159265358979323846;



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

  ll a[n]; f0r(i, n) cin >> a[i];

  ll cnt[100007] = {0};
  ll s = 0;
  f0r(i, n) {
    s += a[i];
    ++cnt[a[i]];
  }

  ll q; cin >> q;
  f0r(i, q) {
    ll x, y; cin >> x >> y;
    s += cnt[x] * (y - x);
    cnt[y] += cnt[x];
    cnt[x] = 0;
    cout << s << '\n';
  }
}
 
int main() {
  fio();
  
  int T = 1;
  // cin >> T;
  while (T--) solve();
} 

Measured memory_bytes: 5184
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
using namespace std;

int main()
{
    long long n;
    cin >> n;
    if (n == 1)
    {
        cout << 0 << endl;
        return 0;
    }
    long long num = n;
    map<long long, long long> dic;
    for(long long i = 2; i * i <= n; ++i)
    {
        long long r = num % i;
        while (r == 0)
        {
            ++dic[i];
            num = num / i;
            r = num % i;
        }
    }
    // 割り続けて1とならない場合,
    // numはまだ出ていない素数となる(あるいはnそのものは素数である)
    // したがって、これもカウントする
    if (num != 1)
    {
        ++dic[num]; // dic[num] = 1 でも OK だが、こちらの方が僅かに高速(?)
    }

    long long ans = 0;
    for (const auto& e : dic)
    {
        long long cnt = 0;
        long long ex = e.second;
        long long i = 1;
        while(ex > 0)
        {
            ex -= i;
            if (ex < 0) break;
            ++cnt;
            ++i;
        }
        ans += cnt;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define INF 1000000007
typedef long long ll;
struct Edge{ll u,v,cost;};
using Edges = vector<Edge>;

vector<ll> Bellman_ford(const Edges &edges,int V,int s){
    vector<ll> dist(V,INF);
    dist[s] = 0;
    for(int i = 0; i < V ; i++){
        for(auto e : edges){
            if(dist[e.u] == INF)continue;
            if(dist[e.v] > dist[e.u]+e.cost){
                dist[e.v] = dist[e.u]+e.cost;
                if(i == V-1)return vector<ll>();
            }
        }
    }
    return dist;
}

int main(){
    int V,E,s;cin >> V >> E >> s;
    Edges es(E);
    for(int i = 0; i < E ; i++){
        cin >> es[i].u >> es[i].v >> es[i].cost;
    }

    vector<ll> dist = Bellman_ford(es,V,s);
    if(dist.empty())cout << "NEGATIVE CYCLE" << endl;
    else{
        for(auto d : dist){
            if(d == INF)cout << "INF" << endl;
            else cout << d << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 3140
e=enumerate
(h,w),*a=[list(map(int,t.split()))for t in open(0)]
dp=[0]*w
c=12800
for i,a in e(zip(a,a[h:])):
  for j,(x,y)in e(zip(*a)):
    x=abs(x-y)
    t=0
    if j:
      t|=dp[j-1]<<x
      t|=dp[j-1]>>x
    if i:
      t|=dp[j]<<x
      t|=dp[j]>>x
    dp[j]=t if i+j else 2**c<<x
*a,=map(int,(bin(dp[w-1])[2:]).zfill(25601))
print(min([i for i,f in e(a[12800:])if f]+[i for i,f in e(a[12800::-1])if f]))

Measured memory_bytes: 4644
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define pb emplace_back
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define pi M_PI
#define PQ(T) priority_queue<T>
#define SPQ(T) priority_queue<T,vector<T>,greater<T>>
#define dame(a) {out(a);return 0;}
#define decimal cout<<fixed<<setprecision(15);
#define dupli(a) a.erase(unique(all(a)),a.end())
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef tuple<ll,ll,ll,ll> PPP;
typedef multiset<ll> S;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
using vvvvi=vector<vvvi>;
using vp=vector<P>;
using vvp=vector<vp>;
using vb=vector<bool>;
using vvb=vector<vb>;
const ll inf=1001001001001001001;
const ll INF=1001001001;
const ll mod=1000000007;
const double eps=1e-10;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())cout<<'('<<v[i].fi<<','<<v[i].se<<')';cout<<'\n';}
template<class T> void outvvp(T v){rep(i,v.size())outvp(v[i]);}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);}
template<class T> bool isin(T x,T l,T r){return (l)<=(x)&&(x)<=(r);}
template<class T> void yesno(T b){if(b)out("yes");else out("no");}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
template<class T> void YESNO(T b){if(b)out("YES");else out("NO");}
template<class T> void noyes(T b){if(b)out("no");else out("yes");}
template<class T> void NoYes(T b){if(b)out("No");else out("Yes");}
template<class T> void NOYES(T b){if(b)out("NO");else out("YES");}
void outs(ll a,ll b){if(a>=inf-100)out(b);else out(a);}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll modpow(ll a,ll b){ll res=1;a%=mod;while(b){if(b&1)res=res*a%mod;a=a*a%mod;b>>=1;}return res;}

int main(){
    ll a,v,b,w,t;cin>>a>>v>>b>>w>>t;
    if(v<=w)dame("NO");
    if((v-w)*t>=abs(a-b))out("YES");
    else out("NO");
}

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

int main(){
    ll l, r, ans = 2018;
    cin >> l >> r;

    if((r - l) >= 2019){
        cout << 0 << endl;
        return 0;
    }

    for(ll i = l; i < r; ++i){
        for(ll j = i + 1; j <= r; ++j){
            ans = min(ans, (i * j) % 2019);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256